TypeScript/JavaScript client library for LiveTemplate - reactive HTML over the wire.
The LiveTemplate client enables reactive web applications by efficiently applying tree-based HTML updates from the server. It uses DOM morphing, intelligent static content caching, and WebSocket transport for real-time interactivity.
npm install @livetemplate/client
<script src="https://cdn.jsdelivr.net/npm/@livetemplate/client@0.1.0/dist/livetemplate-client.browser.js"></script>
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@livetemplate/client@0.1.0/dist/livetemplate-client.browser.js"></script>
</head>
<body>
<div id="app"></div>
<script>
const client = new LiveTemplateClient.LiveTemplateClient({
targetSelector: "#app",
wsUrl: "ws://localhost:8080/ws",
httpUrl: "http://localhost:8080"
});
client.connect();
</script>
</body>
</html>
import { LiveTemplateClient } from "@livetemplate/client";
const client = new LiveTemplateClient({
targetSelector: "#app",
wsUrl: "ws://localhost:8080/ws",
httpUrl: "http://localhost:8080"
});
client.connect();
interface LiveTemplateClientOptions {
// Required
targetSelector: string; // CSS selector for target element
wsUrl: string; // WebSocket URL
httpUrl: string; // HTTP URL for initial render
// Optional
debug?: boolean; // Enable debug logging (default: false)
reconnectInterval?: number; // Reconnect interval in ms (default: 3000)
maxReconnectAttempts?: number;// Max reconnect attempts (default: 10)
}
// Connect to server
client.connect(): void
// Disconnect from server
client.disconnect(): void
// Send event to server
client.sendEvent(event: string, data: any): void
// Set debug mode
client.setDebug(enabled: boolean): void
The client emits events you can listen to:
// Connection established
window.addEventListener("livetemplate:connected", (e) => {
console.log("Connected to server");
});
// Connection closed
window.addEventListener("livetemplate:disconnected", (e) => {
console.log("Disconnected from server");
});
// Update received
window.addEventListener("livetemplate:update", (e) => {
console.log("Received update:", e.detail);
});
The client supports six native HTML5 drag events as lvt-on:* bindings: dragstart, dragover, drop, dragend, dragenter, dragleave. On drop, the action message includes dragSourceKey (the dragged item's data-key) and dragTargetKey (the drop target's data-key).
dragSourceKey is only emitted when the drag originated in this app (carried via the custom application/x-lvt-key MIME). Cross-app drags produce no dragSourceKey, and the key is never written to text/plain so it cannot leak to external drop targets (URL bar, text editors, other apps).dragenter/dragleave use relatedTarget to suppress events when the pointer is just crossing into or out of a descendant of the same element. Handlers fire only on real boundary crossings.lvt-on:drop="", lvt-on:dragover="", etc.) runs the spec-mandated side-effects without sending a WS message — useful when only drop needs server handling.dragover fires at ~60 Hz. Add lvt-mod:throttle="100" (or higher) to any dragover handler bound to a real action, or use the marker pattern.effectAllowed and dropEffect are hardcoded to "move". Copy/link drag semantics are not yet configurable.This results in ~75% reduction in update payload sizes compared to full HTML updates.
# Clone repository
git clone https://github.com/livetemplate/client.git
cd client
# Install dependencies
npm install
# Run tests
npm test
# Build
npm run build
client/
├── livetemplate-client.ts # Main client
├── dom/ # DOM utilities
│ ├── directives.ts
│ ├── event-delegation.ts
│ ├── focus-manager.ts
│ ├── form-disabler.ts
│ ├── loading-indicator.ts
│ ├── modal-manager.ts
│ └── observer-manager.ts
├── state/ # State management
│ ├── form-lifecycle-manager.ts
│ └── tree-renderer.ts
├── transport/ # Network layer
│ └── websocket.ts
├── utils/ # Utilities
│ ├── logger.ts
│ ├── rate-limit.ts
│ └── testing.ts
└── tests/ # Test suite
# Run all tests
npm test
# Run specific test
npm test -- focus-manager
# Run with coverage
npm test -- --coverage
# Build TypeScript and browser bundle
npm run build
# Build browser bundle only
npm run build:browser
# Clean build artifacts
npm run clean
This client library follows the LiveTemplate core library's major.minor version. For example:
v0.1.5 → Client: v0.1.x (any patch version)v0.2.0 → Client: v0.2.0 (must match major.minor)Patch versions are independent and can be incremented for client-specific fixes.
See CONTRIBUTING.md for development guidelines.
MIT License - see LICENSE for details.