arethesis 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/LICENSE +21 -0
- package/README.md +121 -2
- package/dist/arethesis-z8eGA7mL.js +5177 -0
- package/dist/arethesis-z8eGA7mL.js.map +1 -0
- package/dist/arethesis.js +147 -0
- package/dist/arethesis.js.map +1 -0
- package/dist/binding/data-binder.d.ts +82 -0
- package/dist/binding/data-binder.d.ts.map +1 -0
- package/dist/binding/types.d.ts +119 -0
- package/dist/binding/types.d.ts.map +1 -0
- package/dist/binding/validation-engine.d.ts +22 -0
- package/dist/binding/validation-engine.d.ts.map +1 -0
- package/dist/components/component.d.ts +93 -0
- package/dist/components/component.d.ts.map +1 -0
- package/dist/components/decorators.d.ts +9 -0
- package/dist/components/decorators.d.ts.map +1 -0
- package/dist/components/runtime.d.ts +17 -0
- package/dist/components/runtime.d.ts.map +1 -0
- package/dist/components/template-loader.d.ts +37 -0
- package/dist/components/template-loader.d.ts.map +1 -0
- package/dist/components/types.d.ts +22 -0
- package/dist/components/types.d.ts.map +1 -0
- package/dist/components.js +568 -0
- package/dist/components.js.map +1 -0
- package/dist/core/arethesis.d.ts +96 -0
- package/dist/core/arethesis.d.ts.map +1 -0
- package/dist/core/types.d.ts +40 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/data/list-view-registry.d.ts +69 -0
- package/dist/data/list-view-registry.d.ts.map +1 -0
- package/dist/data/object-store.d.ts +88 -0
- package/dist/data/object-store.d.ts.map +1 -0
- package/dist/data/optimistic-updates.d.ts +59 -0
- package/dist/data/optimistic-updates.d.ts.map +1 -0
- package/dist/data/persistence-manager.d.ts +56 -0
- package/dist/data/persistence-manager.d.ts.map +1 -0
- package/dist/data/types.d.ts +145 -0
- package/dist/data/types.d.ts.map +1 -0
- package/dist/http/auth-manager.d.ts +60 -0
- package/dist/http/auth-manager.d.ts.map +1 -0
- package/dist/http/http-client.d.ts +77 -0
- package/dist/http/http-client.d.ts.map +1 -0
- package/dist/http/http-error.d.ts +35 -0
- package/dist/http/http-error.d.ts.map +1 -0
- package/dist/http/mapping.d.ts +21 -0
- package/dist/http/mapping.d.ts.map +1 -0
- package/dist/http/types.d.ts +237 -0
- package/dist/http/types.d.ts.map +1 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/kit/data-table.d.ts +57 -0
- package/dist/kit/data-table.d.ts.map +1 -0
- package/dist/kit/flex-view.d.ts +42 -0
- package/dist/kit/flex-view.d.ts.map +1 -0
- package/dist/kit/form.d.ts +13 -0
- package/dist/kit/form.d.ts.map +1 -0
- package/dist/kit/index.d.ts +18 -0
- package/dist/kit/index.d.ts.map +1 -0
- package/dist/kit/list.d.ts +10 -0
- package/dist/kit/list.d.ts.map +1 -0
- package/dist/mixins/context-menu.d.ts +3 -0
- package/dist/mixins/context-menu.d.ts.map +1 -0
- package/dist/mixins/draggable.d.ts +3 -0
- package/dist/mixins/draggable.d.ts.map +1 -0
- package/dist/mixins/dropdown.d.ts +3 -0
- package/dist/mixins/dropdown.d.ts.map +1 -0
- package/dist/mixins/editable.d.ts +3 -0
- package/dist/mixins/editable.d.ts.map +1 -0
- package/dist/mixins/grid-navigation.d.ts +3 -0
- package/dist/mixins/grid-navigation.d.ts.map +1 -0
- package/dist/mixins/index.d.ts +19 -0
- package/dist/mixins/index.d.ts.map +1 -0
- package/dist/mixins/infinite-scroll.d.ts +3 -0
- package/dist/mixins/infinite-scroll.d.ts.map +1 -0
- package/dist/mixins/registry.d.ts +41 -0
- package/dist/mixins/registry.d.ts.map +1 -0
- package/dist/mixins/resizable.d.ts +3 -0
- package/dist/mixins/resizable.d.ts.map +1 -0
- package/dist/mixins/sortable.d.ts +3 -0
- package/dist/mixins/sortable.d.ts.map +1 -0
- package/dist/mixins/tooltip.d.ts +3 -0
- package/dist/mixins/tooltip.d.ts.map +1 -0
- package/dist/mixins/types.d.ts +165 -0
- package/dist/mixins/types.d.ts.map +1 -0
- package/dist/mixins/utils.d.ts +22 -0
- package/dist/mixins/utils.d.ts.map +1 -0
- package/dist/plugins/async-validators.d.ts +9 -0
- package/dist/plugins/async-validators.d.ts.map +1 -0
- package/dist/plugins/builtins.d.ts +9 -0
- package/dist/plugins/builtins.d.ts.map +1 -0
- package/dist/plugins/date-utils.d.ts +16 -0
- package/dist/plugins/date-utils.d.ts.map +1 -0
- package/dist/plugins/plugin-manager.d.ts +29 -0
- package/dist/plugins/plugin-manager.d.ts.map +1 -0
- package/dist/plugins/rich-text.d.ts +15 -0
- package/dist/plugins/rich-text.d.ts.map +1 -0
- package/dist/plugins/types.d.ts +50 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/realtime/azure-pubsub-manager.d.ts +49 -0
- package/dist/realtime/azure-pubsub-manager.d.ts.map +1 -0
- package/dist/realtime/collab/collab-session.d.ts +75 -0
- package/dist/realtime/collab/collab-session.d.ts.map +1 -0
- package/dist/realtime/collab/cursor-overlay.d.ts +20 -0
- package/dist/realtime/collab/cursor-overlay.d.ts.map +1 -0
- package/dist/realtime/collab/textarea-adapter.d.ts +27 -0
- package/dist/realtime/collab/textarea-adapter.d.ts.map +1 -0
- package/dist/realtime/ot/client.d.ts +27 -0
- package/dist/realtime/ot/client.d.ts.map +1 -0
- package/dist/realtime/ot/server.d.ts +36 -0
- package/dist/realtime/ot/server.d.ts.map +1 -0
- package/dist/realtime/ot/text-operation.d.ts +55 -0
- package/dist/realtime/ot/text-operation.d.ts.map +1 -0
- package/dist/realtime/reconnect.d.ts +22 -0
- package/dist/realtime/reconnect.d.ts.map +1 -0
- package/dist/realtime/sse-manager.d.ts +37 -0
- package/dist/realtime/sse-manager.d.ts.map +1 -0
- package/dist/realtime/types.d.ts +122 -0
- package/dist/realtime/types.d.ts.map +1 -0
- package/dist/realtime/websocket-manager.d.ts +34 -0
- package/dist/realtime/websocket-manager.d.ts.map +1 -0
- package/dist/theme.css +516 -0
- package/dist/utils/backoff.d.ts +18 -0
- package/dist/utils/backoff.d.ts.map +1 -0
- package/dist/utils/dates.d.ts +22 -0
- package/dist/utils/dates.d.ts.map +1 -0
- package/dist/utils/dom.d.ts +16 -0
- package/dist/utils/dom.d.ts.map +1 -0
- package/dist/utils/emitter.d.ts +17 -0
- package/dist/utils/emitter.d.ts.map +1 -0
- package/dist/utils/path.d.ts +33 -0
- package/dist/utils/path.d.ts.map +1 -0
- package/dist/utils/sanitize.d.ts +20 -0
- package/dist/utils/sanitize.d.ts.map +1 -0
- package/dist/utils/url.d.ts +16 -0
- package/dist/utils/url.d.ts.map +1 -0
- package/package.json +95 -4
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { $ as e, A as t, C as n, D as r, E as i, G as a, H as o, I as s, J as c, K as ee, L as te, M as ne, N as l, O as u, P as d, Q as f, R as p, S as m, T as h, U as g, V as _, W as v, X as y, Y as b, Z as x, _ as S, a as C, at as w, b as T, c as E, ct as D, d as O, dt as k, et as A, f as j, ft as M, g as N, gt as P, h as F, ht as I, i as re, it as L, j as R, k as z, l as B, lt as V, m as H, mt as U, n as W, nt as G, o as K, ot as q, p as J, pt as Y, q as X, r as ie, rt as ae, s as oe, st as se, t as ce, tt as Z, u as le, ut as ue, v as Q, w as de, x as fe, y as pe, z as me } from "./arethesis-z8eGA7mL.js";
|
|
2
|
+
// src/realtime/ot/server.ts
|
|
3
|
+
var $ = class {
|
|
4
|
+
document;
|
|
5
|
+
operations = [];
|
|
6
|
+
opIds = [];
|
|
7
|
+
constructor(e = "") {
|
|
8
|
+
this.document = e;
|
|
9
|
+
}
|
|
10
|
+
get revision() {
|
|
11
|
+
return this.operations.length;
|
|
12
|
+
}
|
|
13
|
+
receive(e, t, n) {
|
|
14
|
+
if (e < 0 || e > this.operations.length) throw Error(`Invalid revision ${e}`);
|
|
15
|
+
let r = t;
|
|
16
|
+
for (let t of this.operations.slice(e)) r = Z.transform(r, t)[0];
|
|
17
|
+
return this.document = r.apply(this.document), this.operations.push(r), this.opIds.push(n), r;
|
|
18
|
+
}
|
|
19
|
+
}, he = class {
|
|
20
|
+
send;
|
|
21
|
+
loadDocument;
|
|
22
|
+
docs = /* @__PURE__ */ new Map();
|
|
23
|
+
clients = /* @__PURE__ */ new Map();
|
|
24
|
+
constructor(e, t = () => "") {
|
|
25
|
+
this.send = e, this.loadDocument = t;
|
|
26
|
+
}
|
|
27
|
+
document(e) {
|
|
28
|
+
let t = this.docs.get(e);
|
|
29
|
+
return t || (t = new $(this.loadDocument(e)), this.docs.set(e, t)), t;
|
|
30
|
+
}
|
|
31
|
+
membersOf(e) {
|
|
32
|
+
return Array.from(this.clients.entries()).filter(([, t]) => t.docs.has(e)).map(([e]) => e);
|
|
33
|
+
}
|
|
34
|
+
broadcast(e, t, n) {
|
|
35
|
+
for (let r of this.membersOf(e)) r !== n && this.send(r, t);
|
|
36
|
+
}
|
|
37
|
+
handle(e, t) {
|
|
38
|
+
let n = t.channel?.replace(/^doc:/, "") ?? "";
|
|
39
|
+
if (!n) return;
|
|
40
|
+
let r = this.clients.get(e);
|
|
41
|
+
switch (r || (r = { docs: /* @__PURE__ */ new Set() }, this.clients.set(e, r)), t.type) {
|
|
42
|
+
case "collab:join": {
|
|
43
|
+
r.docs.add(n);
|
|
44
|
+
let i = t.payload ?? {};
|
|
45
|
+
r.user = i.user;
|
|
46
|
+
let a = this.document(n), o = typeof i.revision == "number" && i.revision >= 0 && i.revision <= a.revision ? i.revision : null, s = o === null ? void 0 : a.operations.slice(o).map((e, t) => ({
|
|
47
|
+
op: e.toJSON(),
|
|
48
|
+
opId: a.opIds[o + t]
|
|
49
|
+
})), c = this.membersOf(n).filter((t) => t !== e).map((e) => ({
|
|
50
|
+
clientId: e,
|
|
51
|
+
user: this.clients.get(e)?.user,
|
|
52
|
+
selection: this.clients.get(e)?.selection
|
|
53
|
+
}));
|
|
54
|
+
this.send(e, {
|
|
55
|
+
type: "collab:init",
|
|
56
|
+
channel: t.channel,
|
|
57
|
+
payload: {
|
|
58
|
+
content: a.document,
|
|
59
|
+
revision: a.revision,
|
|
60
|
+
clientId: e,
|
|
61
|
+
peers: c,
|
|
62
|
+
since: o,
|
|
63
|
+
missed: s
|
|
64
|
+
}
|
|
65
|
+
}), this.broadcast(n, {
|
|
66
|
+
type: "collab:presence",
|
|
67
|
+
channel: t.channel,
|
|
68
|
+
payload: {
|
|
69
|
+
clientId: e,
|
|
70
|
+
user: r.user
|
|
71
|
+
}
|
|
72
|
+
}, e);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
case "collab:op": {
|
|
76
|
+
if (!r.docs.has(n)) return;
|
|
77
|
+
let { revision: i, op: a, opId: o } = t.payload, s;
|
|
78
|
+
try {
|
|
79
|
+
s = this.document(n).receive(i, Z.fromJSON(a), o);
|
|
80
|
+
} catch (n) {
|
|
81
|
+
this.send(e, {
|
|
82
|
+
type: "collab:error",
|
|
83
|
+
channel: t.channel,
|
|
84
|
+
payload: {
|
|
85
|
+
opId: o,
|
|
86
|
+
message: n.message
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
let c = this.document(n).revision;
|
|
92
|
+
this.send(e, {
|
|
93
|
+
type: "collab:ack",
|
|
94
|
+
channel: t.channel,
|
|
95
|
+
payload: {
|
|
96
|
+
revision: c,
|
|
97
|
+
opId: o
|
|
98
|
+
}
|
|
99
|
+
}), this.broadcast(n, {
|
|
100
|
+
type: "collab:op",
|
|
101
|
+
channel: t.channel,
|
|
102
|
+
payload: {
|
|
103
|
+
op: s.toJSON(),
|
|
104
|
+
revision: c,
|
|
105
|
+
clientId: e
|
|
106
|
+
}
|
|
107
|
+
}, e);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
case "collab:presence": {
|
|
111
|
+
if (!r.docs.has(n)) return;
|
|
112
|
+
let i = t.payload;
|
|
113
|
+
r.selection = i.selection, i.user && (r.user = i.user), this.broadcast(n, {
|
|
114
|
+
type: "collab:presence",
|
|
115
|
+
channel: t.channel,
|
|
116
|
+
payload: {
|
|
117
|
+
clientId: e,
|
|
118
|
+
user: r.user,
|
|
119
|
+
selection: i.selection,
|
|
120
|
+
revision: this.document(n).revision
|
|
121
|
+
}
|
|
122
|
+
}, e);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
case "collab:leave":
|
|
126
|
+
this.leave(e, n);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
leave(e, t) {
|
|
131
|
+
this.clients.get(e)?.docs.delete(t) && this.broadcast(t, {
|
|
132
|
+
type: "collab:leave",
|
|
133
|
+
channel: `doc:${t}`,
|
|
134
|
+
payload: { clientId: e }
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
disconnect(e) {
|
|
138
|
+
let t = this.clients.get(e);
|
|
139
|
+
if (t) {
|
|
140
|
+
for (let n of [...t.docs]) this.leave(e, n);
|
|
141
|
+
this.clients.delete(e);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
export { ce as Arethesis, w as AuthManager, G as AzurePubSubManager, n as COMPONENT_METADATA, b as CollabManager, he as CollabServer, y as CollabSession, m as Component, x as CursorOverlay, s as DataBinder, ue as Emitter, q as HttpClient, se as HttpError, k as ListViewRegistry, i as MixinRegistry, A as OTClient, $ as OTDocumentServer, M as ObjectStore, V as OptimisticUpdateManager, D as PersistenceManager, T as PluginManager, te as RelativeTimeTicker, L as SSEManager, l as TemplateLoader, Z as TextOperation, e as TextareaAdapter, W as VERSION, v as ValidationEngine, ae as WebSocketManager, r as applyMixin, E as asyncValidatorsPlugin, f as caretCoordinates, O as contextMenuMixin, B as dateUtilsPlugin, Y as deepEqual, U as deepMerge, de as defineComponent, ie as defineEndpoint, re as defineType, pe as draggableMixin, J as dropdownMixin, Q as editableMixin, a as formatDatePattern, p as formatRelative, C as getArethesis, h as getComponentMetadata, I as getPath, S as gridNavigationMixin, _ as htmlToText, N as infiniteScrollMixin, u as initMixins, z as mixinRegistry, t as observeMixins, ee as parseDate, le as registerBuiltInMixins, fe as registerBuiltInPlugin, R as registerMixin, me as relativeTimes, ne as removeMixin, H as resizableMixin, K as richTextMixin, oe as richTextPlugin, o as sanitizeHtml, g as sanitizeUrl, P as setPath, F as sortableMixin, d as templateLoader, X as toDateInputValue, c as toDateTimeInputValue, j as tooltipMixin };
|
|
146
|
+
|
|
147
|
+
//# sourceMappingURL=arethesis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arethesis.js","names":["TextareaAdapter","observeMixins","COMPONENT_METADATA","applyMixin","MixinRegistry","formatDatePattern","sanitizeHtml","DataBinder","toDateTimeInputValue","parseDate","RelativeTimeTicker","removeMixin","TemplateLoader","initMixins","templateLoader","caretCoordinates","formatRelative","Component","getComponentMetadata","sanitizeUrl","htmlToText","ValidationEngine","CollabSession","CollabManager","CursorOverlay","gridNavigationMixin","getArethesis","AuthManager","PluginManager","asyncValidatorsPlugin","PersistenceManager","contextMenuMixin","ListViewRegistry","OTClient","tooltipMixin","ObjectStore","infiniteScrollMixin","setPath","sortableMixin","getPath","defineType","SSEManager","registerMixin","mixinRegistry","dateUtilsPlugin","OptimisticUpdateManager","resizableMixin","deepMerge","VERSION","AzurePubSubManager","richTextMixin","HttpClient","dropdownMixin","deepEqual","toDateInputValue","defineEndpoint","WebSocketManager","richTextPlugin","HttpError","Arethesis","TextOperation","registerBuiltInMixins","Emitter","editableMixin","defineComponent","registerBuiltInPlugin","draggableMixin","relativeTimes","OTDocumentServer","document","revision","op","operation","concurrent","opId","CollabServer","send","loadDocument","doc","docId","c","id","except","message","client","clientId","join","since","missed","i","peers","applied","err","newRevision","payload"],"sources":["../src/realtime/ot/server.ts"],"sourcesContent":["/**\n * Reference OT server, usable in Node or in the browser (the examples run it\n * inside a mock backend).\n *\n * `OTDocumentServer` holds one document and its history. `CollabServer`\n * speaks the `collab:*` message protocol used by `CollabSession`, for any\n * number of documents and clients, over whatever transport you give it.\n *\n * ```ts\n * const server = new CollabServer((clientId, message) => sockets.get(clientId)?.send(JSON.stringify(message)));\n * socket.on('message', raw => server.handle(clientId, JSON.parse(raw)));\n * socket.on('close', () => server.disconnect(clientId));\n * ```\n *\n * @module realtime/ot/server\n */\n\nimport { TextOperation } from './text-operation';\nimport type { CollabMessage, CollabUser, PresencePayload } from '../types';\n\nexport class OTDocumentServer {\n readonly operations: TextOperation[] = [];\n /** Client op ids, parallel to `operations` (lets reconnecting clients spot their own ops). */\n readonly opIds: Array<string | undefined> = [];\n\n constructor(public document = '') {}\n\n get revision(): number {\n return this.operations.length;\n }\n\n /**\n * Accept an operation made against `revision`. Returns the transformed\n * operation that was applied (broadcast it to the other clients).\n */\n receive(revision: number, operation: TextOperation, opId?: string): TextOperation {\n if (revision < 0 || revision > this.operations.length) throw new Error(`Invalid revision ${revision}`);\n let op = operation;\n for (const concurrent of this.operations.slice(revision)) {\n op = TextOperation.transform(op, concurrent)[0];\n }\n this.document = op.apply(this.document);\n this.operations.push(op);\n this.opIds.push(opId);\n return op;\n }\n}\n\ninterface ClientInfo {\n docs: Set<string>;\n user?: CollabUser;\n selection?: PresencePayload['selection'];\n}\n\nexport class CollabServer {\n private docs = new Map<string, OTDocumentServer>();\n private clients = new Map<string, ClientInfo>();\n\n /**\n * @param send Deliver a message to one client.\n * @param loadDocument Initial content for a document opened for the first time.\n */\n constructor(\n private send: (clientId: string, message: CollabMessage) => void,\n private loadDocument: (docId: string) => string = () => ''\n ) {}\n\n /** Access (or create) a document. */\n document(docId: string): OTDocumentServer {\n let doc = this.docs.get(docId);\n if (!doc) {\n doc = new OTDocumentServer(this.loadDocument(docId));\n this.docs.set(docId, doc);\n }\n return doc;\n }\n\n private membersOf(docId: string): string[] {\n return Array.from(this.clients.entries()).filter(([, c]) => c.docs.has(docId)).map(([id]) => id);\n }\n\n private broadcast(docId: string, message: CollabMessage, except?: string): void {\n for (const id of this.membersOf(docId)) if (id !== except) this.send(id, message);\n }\n\n /** Handle one incoming message from a client. */\n handle(clientId: string, message: CollabMessage): void {\n const docId = message.channel?.replace(/^doc:/, '') ?? '';\n if (!docId) return;\n let client = this.clients.get(clientId);\n if (!client) {\n client = { docs: new Set() };\n this.clients.set(clientId, client);\n }\n\n switch (message.type) {\n case 'collab:join': {\n client.docs.add(docId);\n const join = (message.payload ?? {}) as { user?: CollabUser; revision?: number };\n client.user = join.user;\n const doc = this.document(docId);\n // A reconnecting client sends its revision and gets the ops it missed.\n const since = typeof join.revision === 'number' && join.revision >= 0 && join.revision <= doc.revision ? join.revision : null;\n const missed = since === null ? undefined : doc.operations.slice(since).map((op, i) => ({ op: op.toJSON(), opId: doc.opIds[since + i] }));\n const peers = this.membersOf(docId)\n .filter(id => id !== clientId)\n .map(id => ({ clientId: id, user: this.clients.get(id)?.user, selection: this.clients.get(id)?.selection }));\n this.send(clientId, { type: 'collab:init', channel: message.channel, payload: { content: doc.document, revision: doc.revision, clientId, peers, since, missed } });\n this.broadcast(docId, { type: 'collab:presence', channel: message.channel, payload: { clientId, user: client.user } }, clientId);\n return;\n }\n case 'collab:op': {\n if (!client.docs.has(docId)) return;\n const { revision, op, opId } = message.payload as { revision: number; op: unknown; opId?: string };\n let applied: TextOperation;\n try {\n applied = this.document(docId).receive(revision, TextOperation.fromJSON(op), opId);\n } catch (err) {\n this.send(clientId, { type: 'collab:error', channel: message.channel, payload: { opId, message: (err as Error).message } });\n return;\n }\n const newRevision = this.document(docId).revision;\n this.send(clientId, { type: 'collab:ack', channel: message.channel, payload: { revision: newRevision, opId } });\n this.broadcast(docId, { type: 'collab:op', channel: message.channel, payload: { op: applied.toJSON(), revision: newRevision, clientId } }, clientId);\n return;\n }\n case 'collab:presence': {\n if (!client.docs.has(docId)) return;\n const payload = message.payload as PresencePayload;\n client.selection = payload.selection;\n if (payload.user) client.user = payload.user;\n this.broadcast(docId, { type: 'collab:presence', channel: message.channel, payload: { clientId, user: client.user, selection: payload.selection, revision: this.document(docId).revision } }, clientId);\n return;\n }\n case 'collab:leave':\n this.leave(clientId, docId);\n return;\n }\n }\n\n private leave(clientId: string, docId: string): void {\n const client = this.clients.get(clientId);\n if (!client?.docs.delete(docId)) return;\n this.broadcast(docId, { type: 'collab:leave', channel: `doc:${docId}`, payload: { clientId } });\n }\n\n /** A client went away: leave every document. */\n disconnect(clientId: string): void {\n const client = this.clients.get(clientId);\n if (!client) return;\n for (const docId of [...client.docs]) this.leave(clientId, docId);\n this.clients.delete(clientId);\n }\n}\n"],"mappings":";;AAoBA,IAAaoE,IAAb,MAA8B;CAKT;CAJnB,aAAuC,CAAC;CAExC,QAA4C,CAAC;CAE7C,YAAY,IAAkB,IAAI;EAAf,KAAA,WAAAC;CAAgB;CAEnC,IAAI,WAAmB;EACrB,OAAO,KAAK,WAAW;CACzB;CAMA,QAAQ,GAAkB,GAA0B,GAA8B;EAChF,IAAIC,IAAW,KAAKA,IAAW,KAAK,WAAW,QAAQ,MAAU,MAAM,oBAAoBA,GAAU;EACrG,IAAIC,IAAKC;EACT,KAAK,IAAMC,KAAc,KAAK,WAAW,MAAMH,CAAQ,GACrD,IAAKV,EAAc,UAAUW,GAAIE,CAAU,CAAC,CAAC;EAK/C,OAHA,KAAK,WAAWF,EAAG,MAAM,KAAK,QAAQ,GACtC,KAAK,WAAW,KAAKA,CAAE,GACvB,KAAK,MAAM,KAAKG,CAAI,GACbH;CACT;AACF,GAQaI,KAAb,MAA0B;CASd;CACA;CATV,uBAAe,IAAI,IAA8B;CACjD,0BAAkB,IAAI,IAAwB;CAM9C,YACE,GACA,UAAwD,IACxD;EADQ,AADA,KAAA,OAAAC,GACA,KAAA,eAAAC;CACP;CAGH,SAAS,GAAiC;EACxC,IAAIC,IAAM,KAAK,KAAK,IAAIC,CAAK;EAK7B,OAJKD,MACH,IAAM,IAAIV,EAAiB,KAAK,aAAaW,CAAK,CAAC,GACnD,KAAK,KAAK,IAAIA,GAAOD,CAAG,IAEnBA;CACT;CAEA,UAAkB,GAAyB;EACzC,OAAO,MAAM,KAAK,KAAK,Q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ASf,CAAK,CAAC,CAAC;KAAS;IAAE,GAAGM,CAAQ;IACtM;GACF;GACA,KAAK;IACH,KAAK,MAAMA,GAAUN,CAAK;IAC1B;EACJ;CACF;CAEA,MAAc,GAAkB,GAAqB;EAEnD,AADe,KAAK,QAAQ,IAAIM,CAC3B,CAAA,EAAQ,KAAK,OAAON,CAAK,KAC9B,KAAK,UAAUA,GAAO;GAAE,MAAM;GAAgB,SAAS,OAAOA;GAAS,SAAS,EAAE,YAAS;EAAE,CAAC;CAChG;CAGA,WAAW,GAAwB;EACjC,IAAMK,IAAS,KAAK,QAAQ,IAAIC,CAAQ;EACxC,IAAKD,GACL;QAAK,IAAML,KAAS,CAAC,GAAGK,EAAO,IAAI,GAAG,KAAK,MAAMC,GAAUN,CAAK;GAChE,KAAK,QAAQ,OAAOM,CAAQ;EADoC;CAElE;AACF"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { BindConfig, FieldBindConfig, ValidationError, ValidationResult } from './types';
|
|
2
|
+
import { ValidationEngine } from './validation-engine';
|
|
3
|
+
/** A live binding returned by `DataBinder.bind()`. */
|
|
4
|
+
export interface BindingHandle {
|
|
5
|
+
/** Patch the DOM with new data (unchanged fields are skipped). */
|
|
6
|
+
update(data: unknown): void;
|
|
7
|
+
/** Validate every field with rules; shows errors and the summary. */
|
|
8
|
+
validate(): Promise<ValidationResult>;
|
|
9
|
+
/** Current values of the bound inputs. */
|
|
10
|
+
values(): Record<string, unknown>;
|
|
11
|
+
/** Remove listeners and timers. */
|
|
12
|
+
unbind(): void;
|
|
13
|
+
}
|
|
14
|
+
export declare class DataBinder {
|
|
15
|
+
readonly validationEngine: ValidationEngine;
|
|
16
|
+
private bindings;
|
|
17
|
+
private timers;
|
|
18
|
+
private validationRuns;
|
|
19
|
+
private touched;
|
|
20
|
+
constructor(validationEngine?: ValidationEngine);
|
|
21
|
+
/**
|
|
22
|
+
* Bind data to an element. Rebinding the same element replaces the previous
|
|
23
|
+
* binding (its listeners are removed first).
|
|
24
|
+
*/
|
|
25
|
+
bind(element: Element, data: unknown, config: BindConfig): BindingHandle;
|
|
26
|
+
/** The live handle for an element, if bound. */
|
|
27
|
+
getHandle(element: Element): BindingHandle | undefined;
|
|
28
|
+
/** Patch bound targets with new data; unchanged values are skipped. */
|
|
29
|
+
update(element: Element, data: unknown): void;
|
|
30
|
+
/** Remove listeners, timers and errors for an element. */
|
|
31
|
+
unbind(element: Element): void;
|
|
32
|
+
/** Write one value to one target. */
|
|
33
|
+
applyValue(target: Element, value: unknown, config: FieldBindConfig, data?: unknown): void;
|
|
34
|
+
private applyAttribute;
|
|
35
|
+
/** Format a value for display. */
|
|
36
|
+
format(value: unknown, config: FieldBindConfig, data?: unknown): string;
|
|
37
|
+
private applyToDisplay;
|
|
38
|
+
private inputTypeOf;
|
|
39
|
+
private applyToControl;
|
|
40
|
+
/** Read the current value of a bound target. */
|
|
41
|
+
readValue(target: Element, config: FieldBindConfig): unknown;
|
|
42
|
+
/** Current values of every bound input (by field key). */
|
|
43
|
+
values(element: Element): Record<string, unknown>;
|
|
44
|
+
private triggers;
|
|
45
|
+
private listen;
|
|
46
|
+
private scheduleValidation;
|
|
47
|
+
private validateTarget;
|
|
48
|
+
/** Validate every field that has rules. */
|
|
49
|
+
validate(element: Element): Promise<ValidationResult>;
|
|
50
|
+
private renderSummary;
|
|
51
|
+
/** Mark a field invalid and show the message next to it. */
|
|
52
|
+
showFieldError(element: Element, error: ValidationError): void;
|
|
53
|
+
/** Clear a field's error state. */
|
|
54
|
+
clearFieldError(element: Element): void;
|
|
55
|
+
private errorElementFor;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Keeps every rendered `relative` value current with one shared timer. The
|
|
59
|
+
* timer only runs while there is something to update, waits for the soonest
|
|
60
|
+
* label that can change, drops elements once they leave the document, and
|
|
61
|
+
* catches up as soon as a hidden tab becomes visible again.
|
|
62
|
+
*/
|
|
63
|
+
export declare class RelativeTimeTicker {
|
|
64
|
+
private targets;
|
|
65
|
+
private timer;
|
|
66
|
+
private listening;
|
|
67
|
+
private readonly onVisibility;
|
|
68
|
+
/** Number of elements being kept current. */
|
|
69
|
+
get size(): number;
|
|
70
|
+
watch(target: Element, date: Date, locale: string): void;
|
|
71
|
+
unwatch(target: Element): void;
|
|
72
|
+
/** Re-format every watched element now. */
|
|
73
|
+
tick(now?: number): void;
|
|
74
|
+
/** Stop the timer and forget every element. */
|
|
75
|
+
stop(): void;
|
|
76
|
+
private schedule;
|
|
77
|
+
}
|
|
78
|
+
/** The ticker shared by every DataBinder. */
|
|
79
|
+
export declare const relativeTimes: RelativeTimeTicker;
|
|
80
|
+
/** "3 minutes ago", "in 2 days". */
|
|
81
|
+
export declare function formatRelative(date: Date, locale?: string, now?: number): string;
|
|
82
|
+
//# sourceMappingURL=data-binder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-binder.d.ts","sourceRoot":"","sources":["../../src/binding/data-binder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,eAAe,EAGf,eAAe,EACf,gBAAgB,EAEjB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAkBvD,sDAAsD;AACtD,MAAM,WAAW,aAAa;IAC5B,kEAAkE;IAClE,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAC5B,qEAAqE;IACrE,QAAQ,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACtC,0CAA0C;IAC1C,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,mCAAmC;IACnC,MAAM,IAAI,IAAI,CAAC;CAChB;AAyBD,qBAAa,UAAU;IACrB,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAC5C,OAAO,CAAC,QAAQ,CAAwC;IACxD,OAAO,CAAC,MAAM,CAA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AC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,GAAG,IAAI;IAQ9D,mCAAmC;IACnC,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAgBvC,OAAO,CAAC,eAAe;CAqBxB;AAwBD;;;;;GAKG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,OAAO,CAAsD;IACrE,OAAO,CAAC,KAAK,CAA8C;IAC3D,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAE3B;IAEF,6CAA6C;IAC7C,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAKxD,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI;IAI9B,2CAA2C;IAC3C,IAAI,CAAC,GAAG,SAAa,GAAG,IAAI;IAe5B,+CAA+C;IAC/C,IAAI,IAAI,IAAI;IAQZ,OAAO,CAAC,QAAQ;CAUjB;AAED,6CAA6C;AAC7C,eAAO,MAAM,aAAa,oBAA2B,CAAC;AAEtD,oCAAoC;AACpC,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,SAAU,EAAE,GAAG,SAAa,GAAG,MAAM,CAOrF"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Binding and validation types.
|
|
3
|
+
*
|
|
4
|
+
* @module binding/types
|
|
5
|
+
*/
|
|
6
|
+
/** How a value is displayed in a non-input element. */
|
|
7
|
+
export type DisplayType = 'text' | 'html' | 'date' | 'datetime' | 'time' | 'relative' | 'currency' | 'number' | 'percent' | 'boolean' | 'image' | 'link' | 'tag' | 'badge' | 'tags';
|
|
8
|
+
/** How a value is edited in an input element. */
|
|
9
|
+
export type InputType = 'text' | 'textarea' | 'email' | 'url' | 'tel' | 'password' | 'number' | 'range' | 'color' | 'date' | 'datetime' | 'select' | 'multiselect' | 'checkbox' | 'toggle' | 'tags' | 'rich-text';
|
|
10
|
+
export interface FieldBindConfig {
|
|
11
|
+
/** Dotted path in the data. Defaults to the field's key in `fields`. */
|
|
12
|
+
field?: string;
|
|
13
|
+
/** Target elements. @default `[data-bind="<key>"]` */
|
|
14
|
+
selector?: string;
|
|
15
|
+
displayType?: DisplayType;
|
|
16
|
+
/** Set when the target is an input; inferred from the element otherwise. */
|
|
17
|
+
inputType?: InputType;
|
|
18
|
+
/**
|
|
19
|
+
* A formatter function, or a date pattern (`'MMM D'` style tokens: `YYYY MM DD HH mm ss`)
|
|
20
|
+
* for `date`/`datetime`/`time` display types.
|
|
21
|
+
*/
|
|
22
|
+
format?: string | ((value: unknown, data: unknown) => string);
|
|
23
|
+
/** Convert an input's raw value before it is written back. */
|
|
24
|
+
parse?: (raw: unknown) => unknown;
|
|
25
|
+
/** Write the formatted value to this attribute instead of the content. URLs are sanitized. */
|
|
26
|
+
attribute?: string;
|
|
27
|
+
/** Text shown when the value is empty. */
|
|
28
|
+
emptyText?: string;
|
|
29
|
+
/**
|
|
30
|
+
* For `relative`: keep the text current as time passes ("now" becomes
|
|
31
|
+
* "1 minute ago"). One shared timer serves every field. @default true
|
|
32
|
+
*/
|
|
33
|
+
live?: boolean;
|
|
34
|
+
/** Hide the target (via the `hidden` attribute) when this returns false. */
|
|
35
|
+
visible?: (value: unknown, data: unknown) => boolean;
|
|
36
|
+
/** `Intl` locale. @default the document language or 'en-US' */
|
|
37
|
+
locale?: string;
|
|
38
|
+
/** ISO currency code for `currency`. @default 'USD' */
|
|
39
|
+
currency?: string;
|
|
40
|
+
/** Extra `Intl` formatting options. */
|
|
41
|
+
intl?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions;
|
|
42
|
+
/** Labels for `boolean`. @default ['Yes', 'No'] */
|
|
43
|
+
booleanLabels?: [string, string];
|
|
44
|
+
/** For `html`: skip sanitizing. Only for content you fully trust. */
|
|
45
|
+
trusted?: boolean;
|
|
46
|
+
/** For `link`: text shown instead of the URL. */
|
|
47
|
+
linkText?: string;
|
|
48
|
+
/** For `link`: build the URL from the value, e.g. `v => 'mailto:' + v`. The result is sanitized. */
|
|
49
|
+
href?: (value: unknown, data: unknown) => string;
|
|
50
|
+
/** Write input changes back (see `BindConfig.onChange`). */
|
|
51
|
+
twoWay?: boolean;
|
|
52
|
+
validation?: FieldValidationConfig;
|
|
53
|
+
}
|
|
54
|
+
export type ValidationTrigger = 'blur' | 'input' | 'change' | 'submit';
|
|
55
|
+
export interface BindConfig {
|
|
56
|
+
fields: Record<string, FieldBindConfig>;
|
|
57
|
+
/** Collection bindings: `<template>` id rendered for each item. */
|
|
58
|
+
itemTemplate?: string;
|
|
59
|
+
/** Template rendered when the collection is empty. */
|
|
60
|
+
emptyTemplate?: string;
|
|
61
|
+
/** Template rendered while the first page loads. */
|
|
62
|
+
loadingTemplate?: string;
|
|
63
|
+
/** Template rendered when loading fails (supports `[data-error-message]` and `[data-retry]`). */
|
|
64
|
+
errorTemplate?: string;
|
|
65
|
+
/** Container for collection items. @default `[data-items]`, else the component itself */
|
|
66
|
+
itemsSelector?: string;
|
|
67
|
+
/** Load more items when the end of the collection scrolls into view. */
|
|
68
|
+
infiniteScroll?: boolean | {
|
|
69
|
+
threshold?: number;
|
|
70
|
+
root?: 'self' | 'viewport';
|
|
71
|
+
};
|
|
72
|
+
/** When to validate. @default ['blur', 'change'] (and on input once a field has shown an error) */
|
|
73
|
+
validateOn?: ValidationTrigger[];
|
|
74
|
+
/** Render a list of errors at `[data-error-summary]` (or a selector) when `validate()` fails. */
|
|
75
|
+
showErrorSummary?: boolean | string;
|
|
76
|
+
onValidationError?: (errors: ValidationError[]) => void;
|
|
77
|
+
/** Called for valid input changes on `twoWay` fields. */
|
|
78
|
+
onChange?: (field: string, value: unknown) => void;
|
|
79
|
+
}
|
|
80
|
+
export interface ValidationRule {
|
|
81
|
+
/** Validator name: built-in (`required`, `email`, `minLength`, ...) or registered. */
|
|
82
|
+
type: string;
|
|
83
|
+
/** Parameters, e.g. `{ min: 2 }`. Also available as `{min}` in messages. */
|
|
84
|
+
params?: Record<string, unknown>;
|
|
85
|
+
message?: string;
|
|
86
|
+
/** Only run this rule when the predicate is true. */
|
|
87
|
+
when?: (data: Record<string, unknown>) => boolean;
|
|
88
|
+
}
|
|
89
|
+
export interface ValidatorContext {
|
|
90
|
+
field: string;
|
|
91
|
+
rule: ValidationRule;
|
|
92
|
+
/** All current values of the form/object. */
|
|
93
|
+
data: Record<string, unknown>;
|
|
94
|
+
/** Aborted when a newer validation of the same field starts. */
|
|
95
|
+
signal?: AbortSignal;
|
|
96
|
+
}
|
|
97
|
+
/** `true`/`false`, an error message, or `{ valid, message }`. May be async. */
|
|
98
|
+
export type ValidatorResult = boolean | string | {
|
|
99
|
+
valid: boolean;
|
|
100
|
+
message?: string;
|
|
101
|
+
};
|
|
102
|
+
export type ValidatorFn = (value: unknown, params: Record<string, unknown>, context: ValidatorContext) => ValidatorResult | Promise<ValidatorResult>;
|
|
103
|
+
export interface FieldValidationConfig {
|
|
104
|
+
rules: ValidationRule[];
|
|
105
|
+
/** Debounce for input-triggered validation, in ms. @default 300 */
|
|
106
|
+
debounce?: number;
|
|
107
|
+
/** Human-readable name used as `{label}` in messages. */
|
|
108
|
+
label?: string;
|
|
109
|
+
}
|
|
110
|
+
export interface ValidationError {
|
|
111
|
+
field: string;
|
|
112
|
+
rule: string;
|
|
113
|
+
message: string;
|
|
114
|
+
}
|
|
115
|
+
export interface ValidationResult {
|
|
116
|
+
valid: boolean;
|
|
117
|
+
errors: ValidationError[];
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/binding/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,uDAAuD;AACvD,MAAM,MAAM,WAAW,GACnB,MAAM,GACN,MAAM,GACN,MAAM,GACN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CAAC;IACf,MAAM,EAAE,eAAe,EAAE,CAAC;CAC3B"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FieldValidationConfig, ValidationError, ValidationResult, ValidatorFn } from './types';
|
|
2
|
+
export declare class ValidationEngine {
|
|
3
|
+
private validators;
|
|
4
|
+
constructor();
|
|
5
|
+
private registerBuiltIns;
|
|
6
|
+
/** Register (or replace) a validator. */
|
|
7
|
+
registerValidator(name: string, fn: ValidatorFn, options?: {
|
|
8
|
+
message?: string;
|
|
9
|
+
}): void;
|
|
10
|
+
hasValidator(name: string): boolean;
|
|
11
|
+
/** Change a validator's default message (e.g. for translations). */
|
|
12
|
+
setMessage(name: string, message: string): void;
|
|
13
|
+
/** Run a field's rules in order; resolves to the first error or null. */
|
|
14
|
+
validateField(field: string, value: unknown, config: FieldValidationConfig, data?: Record<string, unknown>, signal?: AbortSignal): Promise<ValidationError | null>;
|
|
15
|
+
/** Synchronous variant; async validators are skipped with a warning. */
|
|
16
|
+
validateFieldSync(field: string, value: unknown, config: FieldValidationConfig, data?: Record<string, unknown>): ValidationError | null;
|
|
17
|
+
/** Validate several fields. Errors keep the order of `fields`. */
|
|
18
|
+
validateAll(data: Record<string, unknown>, fields: Record<string, FieldValidationConfig>): Promise<ValidationResult>;
|
|
19
|
+
private toError;
|
|
20
|
+
private interpolate;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=validation-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-engine.d.ts","sourceRoot":"","sources":["../../src/binding/validation-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EACf,gBAAgB,EAGhB,WAAW,EAEZ,MAAM,SAAS,CAAC;AAejB,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,UAAU,CAA0C;;IAM5D,OAAO,CAAC,gBAAgB;IAyDxB,yCAAyC;IACzC,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,WAAW,EAAE,OAAO,GAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,IAAI;IAI1F,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAInC,oEAAoE;IACpE,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAK/C,yEAAyE;IACnE,aAAa,CACjB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,qBAAqB,EAC7B,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EAClC,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAsBlC,wEAAwE;IACxE,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,eAAe,GAAG,IAAI;IAqB3I,kEAAkE;IAC5D,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAO1H,OAAO,CAAC,OAAO;IAef,OAAO,CAAC,WAAW;CAIpB"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { BindConfig } from '../binding/types';
|
|
2
|
+
import { ListView, ListViewConfig, ObjectRef, StoredObject } from '../data/types';
|
|
3
|
+
import { BindSource, ComponentMetadata, ComponentState, DataFetcher } from './types';
|
|
4
|
+
import { MixinInstance } from '../mixins/types';
|
|
5
|
+
export declare abstract class Component extends HTMLElement {
|
|
6
|
+
#private;
|
|
7
|
+
/** Default bind config for instances of this class. */
|
|
8
|
+
static bindConfig?: BindConfig;
|
|
9
|
+
/** Current state; mirrored to the `data-state` attribute for CSS. */
|
|
10
|
+
protected state: ComponentState;
|
|
11
|
+
protected error: Error | null;
|
|
12
|
+
protected mainTemplateId: string;
|
|
13
|
+
protected loadingTemplateId: string;
|
|
14
|
+
protected errorTemplateId: string;
|
|
15
|
+
/** Resolves once the template has rendered for the first time. */
|
|
16
|
+
readonly ready: Promise<void>;
|
|
17
|
+
connectedCallback(): Promise<void>;
|
|
18
|
+
disconnectedCallback(): void;
|
|
19
|
+
/** Abort signal for listeners that should be removed on disconnect. */
|
|
20
|
+
protected get signal(): AbortSignal;
|
|
21
|
+
/** `addEventListener` that is cleaned up automatically on disconnect. */
|
|
22
|
+
protected listen<K extends keyof HTMLElementEventMap>(target: EventTarget, type: K | string, handler: (event: HTMLElementEventMap[K]) => void, options?: AddEventListenerOptions): void;
|
|
23
|
+
/**
|
|
24
|
+
* Delegated event handler: `handler` runs when `type` fires on an element
|
|
25
|
+
* matching `selector` inside this component. The item id (from the closest
|
|
26
|
+
* `[data-id]`) is passed for collection items.
|
|
27
|
+
*/
|
|
28
|
+
protected delegate(type: string, selector: string, handler: (event: Event, target: Element, itemId: string | null) => void): void;
|
|
29
|
+
/** Apply a mixin to this component (or a child); destroyed on disconnect. */
|
|
30
|
+
protected useMixin(name: string, options?: Record<string, unknown>, element?: HTMLElement): MixinInstance | null;
|
|
31
|
+
/**
|
|
32
|
+
* Listen for a component event; returns an unsubscribe function. Component
|
|
33
|
+
* events are CustomEvents; pick names the DOM doesn't use (e.g. `row-select`
|
|
34
|
+
* rather than `select`), since native events bubble through components too.
|
|
35
|
+
*/
|
|
36
|
+
on<T = unknown>(event: string, handler: (detail: T, event: CustomEvent<T>) => void): () => void;
|
|
37
|
+
/** Dispatch a bubbling CustomEvent. */
|
|
38
|
+
emit<T = unknown>(event: string, detail?: T): boolean;
|
|
39
|
+
protected get metadata(): ComponentMetadata | undefined;
|
|
40
|
+
/** Whether the template file defines a template with this id. */
|
|
41
|
+
protected hasTemplate(templateId: string): Promise<boolean>;
|
|
42
|
+
/** Load a template fragment by id. */
|
|
43
|
+
protected loadTemplate(templateId: string): Promise<DocumentFragment | null>;
|
|
44
|
+
/**
|
|
45
|
+
* Replace this component's content with a template. Concurrent renders are
|
|
46
|
+
* safe: only the most recent call writes to the DOM.
|
|
47
|
+
*/
|
|
48
|
+
protected render(templateId: string): Promise<boolean>;
|
|
49
|
+
/** The bind config in effect: the argument to `bind()`, else `static bindConfig`. */
|
|
50
|
+
protected get bindConfig(): BindConfig | undefined;
|
|
51
|
+
/** What this component is bound to. */
|
|
52
|
+
get source(): BindSource | null;
|
|
53
|
+
/**
|
|
54
|
+
* Bind to one object (`{ type, id }`) or a ListView. Rebinding replaces the
|
|
55
|
+
* previous binding. Missing objects are fetched when their type has an `endpoint`.
|
|
56
|
+
*/
|
|
57
|
+
bind(source: BindSource, config?: BindConfig): void;
|
|
58
|
+
/** Bind to a ListView created from a config. */
|
|
59
|
+
bindList(config: ListViewConfig, bindConfig?: BindConfig): ListView;
|
|
60
|
+
/** Stop listening to the bound source. */
|
|
61
|
+
unbind(): void;
|
|
62
|
+
/** Refetch the bound object or reload the bound list. */
|
|
63
|
+
refetch(): Promise<void>;
|
|
64
|
+
/** Rendered element for a collection item. */
|
|
65
|
+
protected itemElement(id: string): Element | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Run `fetcher` with loading and error templates. On success the main
|
|
68
|
+
* template is restored and the current binding re-applied.
|
|
69
|
+
*/
|
|
70
|
+
protected fetchData<T>(fetcher: DataFetcher<T>): Promise<T | null>;
|
|
71
|
+
/** Render the error template with a friendly message and a retry button. */
|
|
72
|
+
protected showError(err: unknown): Promise<void>;
|
|
73
|
+
/** Retry after an error: refetch the bound source, then call `onRetry()`. */
|
|
74
|
+
retry(): Promise<void>;
|
|
75
|
+
/** Turn an error into a user-facing message. Override to customize. */
|
|
76
|
+
protected formatErrorMessage(error: Error): string;
|
|
77
|
+
/** After the first render, each time the element is connected. */
|
|
78
|
+
protected onConnected(): void;
|
|
79
|
+
/** After removal from the DOM. */
|
|
80
|
+
protected onDisconnected(): void;
|
|
81
|
+
/** After bound object data is rendered (initially and on every change). */
|
|
82
|
+
protected onBind(_obj: StoredObject): void;
|
|
83
|
+
/** After the binding is removed or the object deleted. */
|
|
84
|
+
protected onUnbind(): void;
|
|
85
|
+
/** After a collection item is created or updated. */
|
|
86
|
+
protected onItemRender(_element: Element, _obj: StoredObject): void;
|
|
87
|
+
/** After a bound ListView changes. */
|
|
88
|
+
protected onListChange(_view: ListView): void;
|
|
89
|
+
/** After the retry button is used. */
|
|
90
|
+
protected onRetry(): void;
|
|
91
|
+
}
|
|
92
|
+
export type { ObjectRef };
|
|
93
|
+
//# sourceMappingURL=component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../src/components/component.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,YAAY,EAAqB,MAAM,eAAe,CAAC;AAC1G,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC1F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAuBrD,8BAAsB,SAAU,SAAQ,WAAW;;IACjD,uDAAuD;IACvD,MAAM,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;IAE/B,qEAAqE;IACrE,SAAS,CAAC,KAAK,EAAE,cAAc,CAAU;IACzC,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAQ;IACrC,SAAS,CAAC,cAAc,SAAU;IAClC,SAAS,CAAC,iBAAiB,SAAa;IACxC,SAAS,CAAC,eAAe,SAAW;IAcpC,kEAAkE;IAClE,QAAQ,CAAC,KAAK,E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,0DAA0D;IAC1D,SAAS,CAAC,QAAQ,IAAI,IAAI;IAC1B,qDAAqD;IACrD,SAAS,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI;IACnE,sCAAsC;IACtC,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAC7C,sCAAsC;IACtC,SAAS,CAAC,OAAO,IAAI,IAAI;CAC1B;AAED,YAAY,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ComponentMetadata, DefineComponentOptions } from './types';
|
|
2
|
+
/** Symbol under which metadata is stored on the class. */
|
|
3
|
+
export declare const COMPONENT_METADATA: unique symbol;
|
|
4
|
+
type Ctor = CustomElementConstructor;
|
|
5
|
+
export declare function defineComponent(options: DefineComponentOptions): <T extends Ctor>(constructor: T, _context?: unknown) => T;
|
|
6
|
+
/** Metadata set by `defineComponent`, if any. */
|
|
7
|
+
export declare function getComponentMetadata(constructor: Ctor | (abstract new (...args: never[]) => unknown) | object): ComponentMetadata | undefined;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/components/decorators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAGzE,0DAA0D;AAC1D,eAAO,MAAM,kBAAkB,eAA4C,CAAC;AAE5E,KAAK,IAAI,GAAG,wBAAwB,CAAC;AAErC,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,IAI5C,CAAC,SAAS,IAAI,EAAE,aAAa,CAAC,EAAE,WAAW,OAAO,KAAG,CAAC,CAYxE;AAED,iDAAiD;AACjD,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,IAAI,GAAG,CAAC,QAAQ,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC,GAAG,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAE7I"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ObjectStore } from '../data/object-store';
|
|
2
|
+
import { ListViewRegistry } from '../data/list-view-registry';
|
|
3
|
+
import { DataBinder } from '../binding/data-binder';
|
|
4
|
+
import { HttpClient } from '../http/http-client';
|
|
5
|
+
export interface ComponentRuntime {
|
|
6
|
+
store: ObjectStore;
|
|
7
|
+
listViews: ListViewRegistry;
|
|
8
|
+
binder: DataBinder;
|
|
9
|
+
http: HttpClient;
|
|
10
|
+
}
|
|
11
|
+
/** @internal */
|
|
12
|
+
export declare function setRuntime(next: ComponentRuntime): void;
|
|
13
|
+
/** @internal */
|
|
14
|
+
export declare function getRuntime(): ComponentRuntime;
|
|
15
|
+
/** @internal */
|
|
16
|
+
export declare function hasRuntime(): boolean;
|
|
17
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/components/runtime.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,WAAW,CAAC;IACnB,SAAS,EAAE,gBAAgB,CAAC;IAC5B,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,EAAE,UAAU,CAAC;CAClB;AAID,gBAAgB;AAChB,wBAAgB,UAAU,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAEvD;AAED,gBAAgB;AAChB,wBAAgB,UAAU,IAAI,gBAAgB,CAG7C;AAED,gBAAgB;AAChB,wBAAgB,UAAU,IAAI,OAAO,CAEpC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TemplateLoader: fetch, parse and cache HTML templates.
|
|
3
|
+
*
|
|
4
|
+
* A template file (or inline HTML string) can hold several `<template id>`
|
|
5
|
+
* elements, e.g. `main`, `loading`, `error`, `item`, `empty`. Files are fetched
|
|
6
|
+
* once; concurrent loads share a request; every `load()` returns a fresh clone.
|
|
7
|
+
*
|
|
8
|
+
* @module components/template-loader
|
|
9
|
+
*/
|
|
10
|
+
export declare class TemplateLoader {
|
|
11
|
+
private files;
|
|
12
|
+
private pending;
|
|
13
|
+
private extracted;
|
|
14
|
+
private fetchImpl;
|
|
15
|
+
/** Use a custom fetch (for tests or mock backends). */
|
|
16
|
+
setFetch(fetchImpl: typeof fetch): void;
|
|
17
|
+
/** Register inline HTML under a key, so `load(key)` never hits the network. */
|
|
18
|
+
register(key: string, html: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* Load a file, or one `<template id>` from it. If the file has no `<template>`
|
|
21
|
+
* elements, asking for `'main'` returns the whole file.
|
|
22
|
+
*/
|
|
23
|
+
load(path: string, templateId?: string): Promise<DocumentFragment>;
|
|
24
|
+
/** Whether a file has a `<template>` with this id (after loading). */
|
|
25
|
+
has(path: string, templateId: string): Promise<boolean>;
|
|
26
|
+
private loadFile;
|
|
27
|
+
private fetchFile;
|
|
28
|
+
private extract;
|
|
29
|
+
/** Warm the cache. */
|
|
30
|
+
preload(paths: string[]): Promise<void>;
|
|
31
|
+
isCached(path: string): boolean;
|
|
32
|
+
/** Drop cached files (inline registrations included). */
|
|
33
|
+
clearCache(): void;
|
|
34
|
+
}
|
|
35
|
+
/** Shared loader used by every component. */
|
|
36
|
+
export declare const templateLoader: TemplateLoader;
|
|
37
|
+
//# sourceMappingURL=template-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-loader.d.ts","sourceRoot":"","sources":["../../src/components/template-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,qBAAa,cAAc;IACzB,OAAO,CAAC,KAAK,CAAuC;IACpD,OAAO,CAAC,OAAO,CAAgD;IAC/D,OAAO,CAAC,SAAS,CAAuC;IACxD,OAAO,CAAC,SAAS,CAA+D;IAEhF,uDAAuD;IACvD,QAAQ,CAAC,SAAS,EAAE,OAAO,KAAK,GAAG,IAAI;IAIvC,+EAA+E;IAC/E,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAKzC;;;OAGG;IACG,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAYxE,sEAAsE;IAChE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAK7D,OAAO,CAAC,QAAQ;YAqBF,SAAS;IAMvB,OAAO,CAAC,OAAO;IAOf,sBAAsB;IAChB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7C,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI/B,yDAAyD;IACzD,UAAU,IAAI,IAAI;CAInB;AAED,6CAA6C;AAC7C,eAAO,MAAM,cAAc,gBAAuB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ObjectRef, ListView, StoredObject } from '../data/types';
|
|
2
|
+
export type ComponentState = 'idle' | 'loading' | 'loaded' | 'empty' | 'error';
|
|
3
|
+
export interface DefineComponentOptions {
|
|
4
|
+
/** Custom element name (must contain a hyphen). */
|
|
5
|
+
tag: string;
|
|
6
|
+
/** URL of an HTML file with one or more `<template id="...">` elements. */
|
|
7
|
+
template?: string;
|
|
8
|
+
/** Inline HTML (same format as a template file). Takes precedence over `template`. */
|
|
9
|
+
html?: string;
|
|
10
|
+
/** Template id for the main state. @default 'main' */
|
|
11
|
+
templateId?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ComponentMetadata extends DefineComponentOptions {
|
|
14
|
+
/** Cache key used by the template loader. */
|
|
15
|
+
templateKey?: string;
|
|
16
|
+
}
|
|
17
|
+
/** What a component can bind to. */
|
|
18
|
+
export type BindSource = ObjectRef | ListView;
|
|
19
|
+
/** Async function that produces data, used with `fetchData()`. */
|
|
20
|
+
export type DataFetcher<T> = () => Promise<T>;
|
|
21
|
+
export type { StoredObject };
|
|
22
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/components/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAEvE,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC;AAE/E,MAAM,WAAW,sBAAsB;IACrC,mDAAmD;IACnD,GAAG,EAAE,MAAM,CAAC;IACZ,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sFAAsF;IACtF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,iBAAkB,SAAQ,sBAAsB;IAC/D,6CAA6C;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,oCAAoC;AACpC,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE9C,kEAAkE;AAClE,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC;AAE9C,YAAY,EAAE,YAAY,EAAE,CAAC"}
|