arethesis 0.1.5 → 0.2.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.
Files changed (78) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +3 -3
  3. package/dist/arethesis.js +84 -9
  4. package/dist/arethesis.js.map +1 -1
  5. package/dist/components.js +2340 -136
  6. package/dist/components.js.map +1 -1
  7. package/dist/core/arethesis.d.ts +1 -1
  8. package/dist/{arethesis-jPH9QdQE.js → fuzzy-Dnlbxdby.js} +731 -324
  9. package/dist/fuzzy-Dnlbxdby.js.map +1 -0
  10. package/dist/index.d.ts +8 -2
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/kit/cell-editor.d.ts +47 -0
  13. package/dist/kit/cell-editor.d.ts.map +1 -0
  14. package/dist/kit/chart.d.ts +55 -0
  15. package/dist/kit/chart.d.ts.map +1 -0
  16. package/dist/kit/command-palette.d.ts +52 -0
  17. package/dist/kit/command-palette.d.ts.map +1 -0
  18. package/dist/kit/data-table.d.ts +6 -1
  19. package/dist/kit/data-table.d.ts.map +1 -1
  20. package/dist/kit/index.d.ts +18 -1
  21. package/dist/kit/index.d.ts.map +1 -1
  22. package/dist/kit/markdown/highlight.d.ts +29 -0
  23. package/dist/kit/markdown/highlight.d.ts.map +1 -0
  24. package/dist/kit/markdown/render.d.ts +31 -0
  25. package/dist/kit/markdown/render.d.ts.map +1 -0
  26. package/dist/kit/markdown-editor.d.ts +52 -0
  27. package/dist/kit/markdown-editor.d.ts.map +1 -0
  28. package/dist/kit/sheet/formula.d.ts +106 -0
  29. package/dist/kit/sheet/formula.d.ts.map +1 -0
  30. package/dist/kit/sheet/model.d.ts +28 -0
  31. package/dist/kit/sheet/model.d.ts.map +1 -0
  32. package/dist/kit/sheet/sheet.d.ts +45 -0
  33. package/dist/kit/sheet/sheet.d.ts.map +1 -0
  34. package/dist/kit/theme-boot.generated.d.ts +2 -0
  35. package/dist/kit/theme-boot.generated.d.ts.map +1 -1
  36. package/dist/kit/theme.d.ts +5 -3
  37. package/dist/kit/theme.d.ts.map +1 -1
  38. package/dist/mixins/editable.d.ts.map +1 -1
  39. package/dist/mixins/grid-navigation.d.ts.map +1 -1
  40. package/dist/mixins/index.d.ts +2 -0
  41. package/dist/mixins/index.d.ts.map +1 -1
  42. package/dist/mixins/listbox.d.ts +19 -0
  43. package/dist/mixins/listbox.d.ts.map +1 -0
  44. package/dist/realtime/collab/anchors.d.ts +10 -0
  45. package/dist/realtime/collab/anchors.d.ts.map +1 -0
  46. package/dist/realtime/collab/collab-session.d.ts +46 -1
  47. package/dist/realtime/collab/collab-session.d.ts.map +1 -1
  48. package/dist/realtime/collab/cursor-overlay.d.ts +10 -0
  49. package/dist/realtime/collab/cursor-overlay.d.ts.map +1 -1
  50. package/dist/realtime/collab/textarea-adapter.d.ts +13 -0
  51. package/dist/realtime/collab/textarea-adapter.d.ts.map +1 -1
  52. package/dist/realtime/collab/undo-manager.d.ts +44 -0
  53. package/dist/realtime/collab/undo-manager.d.ts.map +1 -0
  54. package/dist/realtime/ot/client.d.ts +1 -1
  55. package/dist/realtime/ot/client.d.ts.map +1 -1
  56. package/dist/realtime/ot/server.d.ts +13 -1
  57. package/dist/realtime/ot/server.d.ts.map +1 -1
  58. package/dist/realtime/types.d.ts +29 -1
  59. package/dist/realtime/types.d.ts.map +1 -1
  60. package/dist/theme-polychrome-boot.js +17 -0
  61. package/dist/theme-polychrome.css +310 -0
  62. package/dist/theme.css +312 -1
  63. package/dist/tokens/base.tokens.json +18 -0
  64. package/dist/tokens/dark-high-contrast.tokens.json +11 -0
  65. package/dist/tokens/dark.tokens.json +81 -0
  66. package/dist/tokens/light-high-contrast.tokens.json +11 -0
  67. package/dist/tokens/light.tokens.json +81 -0
  68. package/dist/tokens/polychrome.base.tokens.json +45 -0
  69. package/dist/tokens/polychrome.dark-high-contrast.tokens.json +183 -0
  70. package/dist/tokens/polychrome.dark.tokens.json +321 -0
  71. package/dist/tokens/polychrome.light-high-contrast.tokens.json +115 -0
  72. package/dist/tokens/polychrome.light.tokens.json +418 -0
  73. package/dist/tokens/polychrome.resolver.json +78 -0
  74. package/dist/utils/fuzzy.d.ts +21 -0
  75. package/dist/utils/fuzzy.d.ts.map +1 -0
  76. package/dist/version.d.ts +1 -1
  77. package/package.json +3 -1
  78. package/dist/arethesis-jPH9QdQE.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Added
6
+
7
+ - **Polychrome theme** (`arethesis/components/theme-polychrome.css`): an optional palette in the pigments of painted Greek architecture: Egyptian blue, cinnabar, malachite and ochre on limestone, or terracotta and bone on black glaze in dark mode. It has light, dark and high-contrast variants, its own design tokens (`polychrome.resolver.json`), a boot script (`theme-polychrome-boot.js`) and `themeBootHtml({ palette: 'polychrome' })`.
8
+ - New tokens in both themes: `--ar-accent-2` (a secondary accent), `--ar-font-display` and `--ar-font-serif`.
9
+ - **`<a-markdown-editor>`**: a Markdown editor around a plain textarea, with syntax highlighting, line numbers, a toolbar, a live sanitized preview, find and replace, list editing, per-user undo and highlighted ranges. It works under `CollabSession`. `renderMarkdown`, `markdownOutline` and the highlighter are exported too.
10
+ - **Per-user undo** for collaborative editing (`{ undo: true }`, `UndoManager`): undo reverts only your own edits.
11
+ - **Comments on shared documents**: `session.annotate()` and friends. They stay attached to their text as people edit, and the server stores them.
12
+ - Remote collaborators' selections are drawn as well as their carets. `TextareaAdapter` fires `collab:apply` when it changes the value.
13
+
14
+ ### Fixed
15
+
16
+ - `editable` select editors no longer save (and close) on the first arrow key press on Windows and Linux.
17
+ - Fast typing to start editing a table cell no longer drops characters, and IME input works.
18
+
19
+ - **`<a-command-palette>`**: Ctrl/Cmd+K to search commands and data, with fuzzy matching (`fuzzyMatch`, `fuzzyFilter`), grouped sources (static, searched, or from the store with `storeSource`), recents, and a modal dialog that keeps focus.
20
+ - **`<a-sheet>`**: a spreadsheet with formulas, a dependency graph that recalculates only what changed and catches cycles, range selection, fill, clipboard compatible with other spreadsheet apps, per-user undo, and highlighted edits from collaborators. The engine (`SheetModel`, `parseFormula`, `shiftFormula`) is exported.
21
+ - **`<a-chart>`**: line, area, bar and stacked-bar SVG charts that stream, resize, and are readable by keyboard and screen reader (crosshair tooltip, arrow-key readout, legend toggles, data table). New `--ar-chart-1` … `--ar-chart-6` tokens in both palettes, checked for color-vision deficiency.
22
+ - **`listbox` mixin**: an accessible select-only combobox whose arrow keys never pick a value by accident.
23
+ - `openCellEditor()`: the spreadsheet-style cell editor behind `<a-data-table>`, for other grids.
24
+
25
+ ### Changed
26
+
27
+ - **Editing in `<a-data-table>` works like a spreadsheet.** A click edits the cell; moving with the keyboard only selects. Typing replaces the value, after which the arrow keys save and move. Tab saves and moves right, Enter saves (and can move down with `enterMoves: 'down'`), Escape reverts. The editor floats over the cell, so the table no longer shifts, and edits are announced to screen readers. Choice columns use the new `listbox` instead of a native select.
28
+ - The examples have a new look in the Polychrome theme, with self-hosted fonts (Cinzel and Gentium Book Plus, SIL OFL) and a new home page.
29
+ - Every example has a command palette ("Ask the Oracle", Ctrl/Cmd+K): go to any page, switch themes, find people, cards, sections, cells and poleis.
30
+ - New example: **The Agora**, a live threaded discussion ("Is virtue teachable?") with Socrates, Aristotle, Hypatia and others: top-level threads are a ListView with cursor pagination, infinite scroll and server-side sort; votes are optimistic with rollback; replies arrive over SSE; the feed follows the WAI-ARIA feed pattern. The examples' navigation labels are shorter, to fit eight pages.
31
+ - New example: **The Treasury of Athens**, a shared spreadsheet of the Delian League's tribute, with a live chart and Pericles as an optional auditor.
32
+ - The dashboard example streams a multi-series traffic chart and grouped bars, and its stat cards use `<a-chart>` sparklines.
33
+ - The collaborative editor example is now a Markdown studio, with an outline, comments, presence by section, and Socrates as an optional co-author.
34
+
3
35
  ## 0.1.5
4
36
 
5
37
  ### Fixed
package/README.md CHANGED
@@ -80,10 +80,10 @@ When the server sends `invalidate { type: "Person", id: 42 }` over SSE, every `<
80
80
  | **Binding** | `DataBinder`: 15 display types, two-way inputs, safe URL/HTML rendering, validation UI with an accessible error summary |
81
81
  | **Validation** | 16 built-in validators, async validators with cancellation, `{param}` messages, translations |
82
82
  | **Real-time** | `SSEManager`, `WebSocketManager`, `AzurePubSubManager` with shared reconnect/backoff, token refresh on reconnect, status events |
83
- | **Collaboration** | `TextOperation` OT, `OTClient`, a reference `CollabServer`, and `CollabSession` with presence and live cursors |
84
- | **Mixins** | `draggable`, `editable`, `grid-navigation`, `infinite-scroll`, `sortable`, `resizable`, `dropdown`, `tooltip`, `context-menu` |
83
+ | **Collaboration** | `TextOperation` OT, `OTClient`, a reference `CollabServer`, and `CollabSession` with presence, live cursors and selections, per-user undo, and comments anchored to their text |
84
+ | **Mixins** | `draggable`, `editable`, `grid-navigation`, `infinite-scroll`, `sortable`, `resizable`, `dropdown`, `listbox`, `tooltip`, `context-menu` |
85
85
  | **Plugins** | `date-utils`, `async-validators`, a dependency-free `rich-text` editor, and an API for your own |
86
- | **Component kit** | `<a-data-table>`, `<a-flex-view>`, `<a-list>`, `<a-form>` and a themeable stylesheet: light, dark and high contrast, without a flash on load |
86
+ | **Component kit** | `<a-data-table>` with spreadsheet-style editing, `<a-sheet>` (formulas, fill, clipboard), `<a-chart>` (streaming SVG charts), `<a-markdown-editor>`, `<a-command-palette>`, `<a-flex-view>`, `<a-list>`, `<a-form>`, and a themeable stylesheet: light, dark and high contrast, without a flash on load, plus the optional Polychrome palette |
87
87
  | **Design tokens** | The theme as [W3C design tokens](https://www.w3.org/community/reports/design-tokens/CG-FINAL-format-20251028/) (2025.10) with a resolver, published as `arethesis/tokens/*` |
88
88
 
89
89
  ## Documentation
package/dist/arethesis.js CHANGED
@@ -1,9 +1,10 @@
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-jPH9QdQE.js";
1
+ import { $ as e, A as t, B as n, Ct as r, D as i, E as a, Et as o, F as s, H as c, I as l, J as u, K as ee, L as te, M as ne, N as d, O as f, P as p, Q as m, R as h, S as g, St as _, T as v, Tt as y, U as b, V as x, X as S, Y as C, Z as w, _ as T, _t as E, a as D, at as O, b as k, bt as A, c as j, ct as M, d as N, dt as P, et as F, f as I, ft as L, g as R, gt as z, h as B, ht as V, i as H, it as U, j as W, k as G, l as K, lt as re, m as q, mt as J, n as Y, nt as X, o as ie, ot as ae, p as oe, pt as se, q as ce, r as le, rt as Z, s as ue, st as de, t as fe, tt as pe, u as me, ut as he, v as ge, vt as _e, w as ve, wt as ye, x as be, xt as xe, y as Q, yt as Se } from "./fuzzy-Dnlbxdby.js";
2
2
  // src/realtime/ot/server.ts
3
- var $ = class {
3
+ var Ce = 500, we = 4e3, $ = class {
4
4
  document;
5
5
  operations = [];
6
6
  opIds = [];
7
+ annotations = /* @__PURE__ */ new Map();
7
8
  constructor(e = "") {
8
9
  this.document = e;
9
10
  }
@@ -13,10 +14,61 @@ var $ = class {
13
14
  receive(e, t, n) {
14
15
  if (e < 0 || e > this.operations.length) throw Error(`Invalid revision ${e}`);
15
16
  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;
17
+ for (let t of this.operations.slice(e)) r = P.transform(r, t)[0];
18
+ this.document = r.apply(this.document), this.operations.push(r), this.opIds.push(n);
19
+ for (let [e, t] of this.annotations) this.annotations.set(e, Z(t, r));
20
+ return r;
18
21
  }
19
- }, he = class {
22
+ rebaseRange(e, t, n) {
23
+ let r = {
24
+ from: e,
25
+ to: t
26
+ };
27
+ for (let e of this.operations.slice(Math.max(0, Math.min(n, this.operations.length)))) r = Z(r, e);
28
+ let i = (e) => Math.max(0, Math.min(e, this.document.length));
29
+ return {
30
+ from: i(r.from),
31
+ to: i(Math.max(r.from, r.to))
32
+ };
33
+ }
34
+ annotate(e, t) {
35
+ let n = e.annotation;
36
+ if (!n || typeof n.id != "string" || !n.id || n.id.length > 100) return null;
37
+ let r = this.annotations.get(n.id);
38
+ if (e.action === "remove") return r ? (this.annotations.delete(n.id), r) : null;
39
+ let i = (e) => typeof e == "string" ? e.slice(0, we) : void 0, a = typeof e.revision == "number" ? e.revision : this.revision, o = r ? {
40
+ from: r.from,
41
+ to: r.to
42
+ } : null;
43
+ if (typeof n.from == "number" && typeof n.to == "number" && n.from <= n.to && (o = this.rebaseRange(n.from, n.to, a)), !o) return null;
44
+ if (e.action === "add") {
45
+ if (r || this.annotations.size >= Ce) return null;
46
+ let e = {
47
+ id: n.id,
48
+ ...o,
49
+ body: i(n.body) ?? "",
50
+ user: t ?? n.user,
51
+ resolved: !1,
52
+ createdAt: typeof n.createdAt == "number" ? n.createdAt : Date.now(),
53
+ replies: []
54
+ };
55
+ return this.annotations.set(n.id, e), e;
56
+ }
57
+ if (!r) return null;
58
+ let s = Array.isArray(n.replies) ? n.replies.slice(0, 200).map((e) => ({
59
+ body: i(e?.body) ?? "",
60
+ user: e?.user,
61
+ createdAt: typeof e?.createdAt == "number" ? e.createdAt : void 0
62
+ })) : r.replies, c = {
63
+ ...r,
64
+ ...o,
65
+ body: i(n.body) ?? r.body,
66
+ resolved: typeof n.resolved == "boolean" ? n.resolved : r.resolved,
67
+ replies: s
68
+ };
69
+ return this.annotations.set(n.id, c), c;
70
+ }
71
+ }, Te = class {
20
72
  send;
21
73
  loadDocument;
22
74
  docs = /* @__PURE__ */ new Map();
@@ -50,7 +102,7 @@ var $ = class {
50
102
  clientId: e,
51
103
  user: this.clients.get(e)?.user,
52
104
  selection: this.clients.get(e)?.selection
53
- }));
105
+ })), l = [...a.annotations.values()];
54
106
  this.send(e, {
55
107
  type: "collab:init",
56
108
  channel: t.channel,
@@ -60,7 +112,8 @@ var $ = class {
60
112
  clientId: e,
61
113
  peers: c,
62
114
  since: o,
63
- missed: s
115
+ missed: s,
116
+ annotations: l
64
117
  }
65
118
  }), this.broadcast(n, {
66
119
  type: "collab:presence",
@@ -76,7 +129,7 @@ var $ = class {
76
129
  if (!r.docs.has(n)) return;
77
130
  let { revision: i, op: a, opId: o } = t.payload, s;
78
131
  try {
79
- s = this.document(n).receive(i, Z.fromJSON(a), o);
132
+ s = this.document(n).receive(i, P.fromJSON(a), o);
80
133
  } catch (n) {
81
134
  this.send(e, {
82
135
  type: "collab:error",
@@ -122,6 +175,28 @@ var $ = class {
122
175
  }, e);
123
176
  return;
124
177
  }
178
+ case "collab:annotate": {
179
+ if (!r.docs.has(n)) return;
180
+ let i = t.payload, a = this.document(n), o = a.annotate(i, r.user);
181
+ if (!o) {
182
+ this.send(e, {
183
+ type: "collab:error",
184
+ channel: t.channel,
185
+ payload: { message: "Invalid annotation" }
186
+ });
187
+ return;
188
+ }
189
+ this.broadcast(n, {
190
+ type: "collab:annotate",
191
+ channel: t.channel,
192
+ payload: {
193
+ action: i.action,
194
+ annotation: o,
195
+ revision: a.revision
196
+ }
197
+ });
198
+ return;
199
+ }
125
200
  case "collab:leave":
126
201
  this.leave(e, n);
127
202
  return;
@@ -142,6 +217,6 @@ var $ = class {
142
217
  }
143
218
  }
144
219
  };
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, B as VERSION, v as ValidationEngine, ae as WebSocketManager, r as applyMixin, oe as asyncValidatorsPlugin, f as caretCoordinates, O as contextMenuMixin, E as dateUtilsPlugin, Y as deepEqual, U as deepMerge, de as defineComponent, W as defineEndpoint, ie as defineType, pe as draggableMixin, J as dropdownMixin, Q as editableMixin, a as formatDatePattern, p as formatRelative, re 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, C as richTextMixin, K 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 };
220
+ export { le as Arethesis, V as AuthManager, L as AzurePubSubManager, i as COMPONENT_METADATA, F as CollabManager, Te as CollabServer, pe as CollabSession, a as Component, ae as CursorOverlay, n as DataBinder, A as Emitter, z as HttpClient, E as HttpError, xe as ListViewRegistry, t as MixinRegistry, he as OTClient, $ as OTDocumentServer, _ as ObjectStore, Se as OptimisticUpdateManager, _e as PersistenceManager, ve as PluginManager, x as RelativeTimeTicker, J as SSEManager, te as TemplateLoader, P as TextOperation, re as TextareaAdapter, U as UndoManager, N as VERSION, C as ValidationEngine, se as WebSocketManager, W as applyMixin, K as asyncValidatorsPlugin, O as caretAfter, de as caretCoordinates, q as contextMenuMixin, me as dateUtilsPlugin, r as deepEqual, ye as deepMerge, f as defineComponent, H as defineEndpoint, D as defineType, g as draggableMixin, R as dropdownMixin, be as editableMixin, S as formatDatePattern, c as formatRelative, fe as fuzzyFilter, Y as fuzzyMatch, ie as getArethesis, G as getComponentMetadata, y as getPath, k as gridNavigationMixin, ee as htmlToText, Q as infiniteScrollMixin, ne as initMixins, oe as listboxMixin, X as mapRange, d as mixinRegistry, p as observeMixins, w as parseDate, M as rangeRects, I as registerBuiltInMixins, v as registerBuiltInPlugin, s as registerMixin, b as relativeTimes, l as removeMixin, T as resizableMixin, ue as richTextMixin, j as richTextPlugin, ce as sanitizeHtml, u as sanitizeUrl, o as setPath, ge as sortableMixin, h as templateLoader, m as toDateInputValue, e as toDateTimeInputValue, B as tooltipMixin, Z as transformRange };
146
221
 
147
222
  //# sourceMappingURL=arethesis.js.map
@@ -1 +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","richTextMixin","AuthManager","PluginManager","dateUtilsPlugin","PersistenceManager","contextMenuMixin","ListViewRegistry","OTClient","tooltipMixin","ObjectStore","infiniteScrollMixin","setPath","sortableMixin","getPath","getArethesis","SSEManager","registerMixin","mixinRegistry","VERSION","OptimisticUpdateManager","resizableMixin","deepMerge","defineEndpoint","AzurePubSubManager","richTextPlugin","HttpClient","dropdownMixin","deepEqual","toDateInputValue","defineType","WebSocketManager","asyncValidatorsPlugin","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,QAAQ,QAAQ,CAAC,CAA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AAS;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"}
1
+ {"version":3,"file":"arethesis.js","names":["toDateTimeInputValue","MixinRegistry","DataBinder","deepEqual","COMPONENT_METADATA","Component","setPath","registerMixin","formatRelative","removeMixin","sanitizeUrl","htmlToText","TemplateLoader","initMixins","mixinRegistry","defineComponent","observeMixins","toDateInputValue","templateLoader","draggableMixin","ObjectStore","registerBuiltInPlugin","getPath","relativeTimes","RelativeTimeTicker","formatDatePattern","ValidationEngine","parseDate","resizableMixin","HttpError","defineType","caretAfter","gridNavigationMixin","Emitter","richTextPlugin","rangeRects","VERSION","TextOperation","CollabManager","registerBuiltInMixins","AzurePubSubManager","dropdownMixin","HttpClient","tooltipMixin","AuthManager","defineEndpoint","UndoManager","applyMixin","getComponentMetadata","asyncValidatorsPlugin","TextareaAdapter","contextMenuMixin","SSEManager","fuzzyMatch","mapRange","getArethesis","CursorOverlay","listboxMixin","WebSocketManager","sanitizeHtml","Arethesis","transformRange","richTextMixin","caretCoordinates","fuzzyFilter","CollabSession","dateUtilsPlugin","OTClient","sortableMixin","PersistenceManager","PluginManager","deepMerge","editableMixin","ListViewRegistry","infiniteScrollMixin","OptimisticUpdateManager","MAX_ANNOTATIONS","MAX_ANNOTATION_TEXT","OTDocumentServer","document","revision","op","operation","concurrent","opId","id","a","range","clamp","n","input","payload","existing","text","v","created","user","replies","r","updated","CollabServer","send","loadDocument","doc","docId","c","except","message","client","clientId","join","since","missed","i","peers","annotations","applied","err","newRevision","annotation"],"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 { transformRange } from '../collab/anchors';\nimport type { AnnotatePayload, CollabAnnotation, CollabMessage, CollabUser, PresencePayload } from '../types';\n\nconst MAX_ANNOTATIONS = 500;\nconst MAX_ANNOTATION_TEXT = 4000;\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 /** Annotations (comments), kept anchored to their text as operations arrive. */\n readonly annotations = new Map<string, CollabAnnotation>();\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 for (const [id, a] of this.annotations) this.annotations.set(id, transformRange(a, op));\n return op;\n }\n\n /** Map a range made against `revision` to the current document. */\n rebaseRange(from: number, to: number, revision: number): { from: number; to: number } {\n let range = { from, to };\n for (const op of this.operations.slice(Math.max(0, Math.min(revision, this.operations.length)))) range = transformRange(range, op);\n const clamp = (n: number) => Math.max(0, Math.min(n, this.document.length));\n return { from: clamp(range.from), to: clamp(Math.max(range.from, range.to)) };\n }\n\n /**\n * Apply an annotation change made against `revision`. Returns the stored\n * annotation (positions at the current revision), or null if it was invalid.\n */\n annotate(payload: AnnotatePayload, user?: CollabUser): CollabAnnotation | null {\n const input = payload.annotation;\n if (!input || typeof input.id !== 'string' || !input.id || input.id.length > 100) return null;\n const existing = this.annotations.get(input.id);\n if (payload.action === 'remove') {\n if (!existing) return null;\n this.annotations.delete(input.id);\n return existing;\n }\n const text = (v: unknown) => (typeof v === 'string' ? v.slice(0, MAX_ANNOTATION_TEXT) : undefined);\n const revision = typeof payload.revision === 'number' ? payload.revision : this.revision;\n let range = existing ? { from: existing.from, to: existing.to } : null;\n if (typeof input.from === 'number' && typeof input.to === 'number' && input.from <= input.to) range = this.rebaseRange(input.from, input.to, revision);\n if (!range) return null;\n if (payload.action === 'add') {\n if (existing || this.annotations.size >= MAX_ANNOTATIONS) return null;\n const created: CollabAnnotation = { id: input.id, ...range, body: text(input.body) ?? '', user: user ?? input.user, resolved: false, createdAt: typeof input.createdAt === 'number' ? input.createdAt : Date.now(), replies: [] };\n this.annotations.set(input.id, created);\n return created;\n }\n if (!existing) return null;\n const replies = Array.isArray(input.replies)\n ? input.replies.slice(0, 200).map(r => ({ body: text(r?.body) ?? '', user: r?.user, createdAt: typeof r?.createdAt === 'number' ? r.createdAt : undefined }))\n : existing.replies;\n const updated: CollabAnnotation = { ...existing, ...range, body: text(input.body) ?? existing.body, resolved: typeof input.resolved === 'boolean' ? input.resolved : existing.resolved, replies };\n this.annotations.set(input.id, updated);\n return updated;\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 const annotations = [...doc.annotations.values()];\n this.send(clientId, { type: 'collab:init', channel: message.channel, payload: { content: doc.document, revision: doc.revision, clientId, peers, since, missed, annotations } });\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:annotate': {\n if (!client.docs.has(docId)) return;\n const payload = message.payload as AnnotatePayload;\n const doc = this.document(docId);\n const annotation = doc.annotate(payload, client.user);\n if (!annotation) {\n this.send(clientId, { type: 'collab:error', channel: message.channel, payload: { message: 'Invalid annotation' } });\n return;\n }\n // Everyone, including the sender, gets the stored version at the current revision.\n this.broadcast(docId, { type: 'collab:annotate', channel: message.channel, payload: { action: payload.action, annotation, revision: doc.revision } });\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":";;AAqBA,IAAM4E,KAAkB,KAClBC,KAAsB,KAEfC,IAAb,MAA8B;CAOT;CANnB,aAAuC,CAAC;CAExC,QAA4C,CAAC;CAE7C,8BAAuB,IAAI,IAA8B;CAE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