@sentropic/design-system-svelte 0.35.1 → 0.37.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 (69) hide show
  1. package/LICENSE.THIRD-PARTY.md +74 -1
  2. package/dist/Calendar.svelte +28 -1
  3. package/dist/Calendar.svelte.d.ts +7 -0
  4. package/dist/Calendar.svelte.d.ts.map +1 -1
  5. package/dist/ContentSwitcher.svelte +6 -1
  6. package/dist/DiagramCard.svelte +282 -0
  7. package/dist/DiagramCard.svelte.d.ts +44 -0
  8. package/dist/DiagramCard.svelte.d.ts.map +1 -0
  9. package/dist/DiagramCardHeader.svelte +173 -0
  10. package/dist/DiagramCardHeader.svelte.d.ts +37 -0
  11. package/dist/DiagramCardHeader.svelte.d.ts.map +1 -0
  12. package/dist/DiagramZone.svelte +378 -0
  13. package/dist/DiagramZone.svelte.d.ts +45 -0
  14. package/dist/DiagramZone.svelte.d.ts.map +1 -0
  15. package/dist/DiagramZoneHeader.svelte +97 -0
  16. package/dist/DiagramZoneHeader.svelte.d.ts +40 -0
  17. package/dist/DiagramZoneHeader.svelte.d.ts.map +1 -0
  18. package/dist/MenuPopover.svelte +101 -12
  19. package/dist/MenuPopover.svelte.d.ts.map +1 -1
  20. package/dist/Pagination.svelte +5 -0
  21. package/dist/RadioGroup.svelte +4 -1
  22. package/dist/TimeRangePicker.svelte +19 -1
  23. package/dist/TimeRangePicker.svelte.d.ts.map +1 -1
  24. package/dist/diagram-icons/DiagramIcon.svelte +65 -0
  25. package/dist/diagram-icons/DiagramIcon.svelte.d.ts +11 -0
  26. package/dist/diagram-icons/DiagramIcon.svelte.d.ts.map +1 -0
  27. package/dist/diagram-icons/PROVENANCE.md +72 -0
  28. package/dist/diagram-icons/index.d.ts +6 -0
  29. package/dist/diagram-icons/index.d.ts.map +1 -0
  30. package/dist/diagram-icons/index.js +4 -0
  31. package/dist/diagram-icons/registry.d.ts +52 -0
  32. package/dist/diagram-icons/registry.d.ts.map +1 -0
  33. package/dist/diagram-icons/registry.js +79 -0
  34. package/dist/diagram-render/index.d.ts +17 -0
  35. package/dist/diagram-render/index.d.ts.map +1 -0
  36. package/dist/diagram-render/index.js +11 -0
  37. package/dist/diagram-render/renderCardSvg.d.ts +83 -0
  38. package/dist/diagram-render/renderCardSvg.d.ts.map +1 -0
  39. package/dist/diagram-render/renderCardSvg.js +149 -0
  40. package/dist/diagram-render/renderZoneSvg.d.ts +88 -0
  41. package/dist/diagram-render/renderZoneSvg.d.ts.map +1 -0
  42. package/dist/diagram-render/renderZoneSvg.js +184 -0
  43. package/dist/diagramCardModel.d.ts +582 -0
  44. package/dist/diagramCardModel.d.ts.map +1 -0
  45. package/dist/diagramCardModel.js +1133 -0
  46. package/dist/index.d.ts +5 -0
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +2 -0
  49. package/dist/presence-badge/LockPresenceBadge.svelte +490 -0
  50. package/dist/presence-badge/LockPresenceBadge.svelte.d.ts +18 -0
  51. package/dist/presence-badge/LockPresenceBadge.svelte.d.ts.map +1 -0
  52. package/dist/presence-badge/index.d.ts +6 -0
  53. package/dist/presence-badge/index.d.ts.map +1 -0
  54. package/dist/presence-badge/index.js +3 -0
  55. package/dist/rich-text-editor/ComposerEditor.svelte +485 -0
  56. package/dist/rich-text-editor/ComposerEditor.svelte.d.ts +16 -0
  57. package/dist/rich-text-editor/ComposerEditor.svelte.d.ts.map +1 -0
  58. package/dist/rich-text-editor/RichTextEditor.svelte +557 -0
  59. package/dist/rich-text-editor/RichTextEditor.svelte.d.ts +45 -0
  60. package/dist/rich-text-editor/RichTextEditor.svelte.d.ts.map +1 -0
  61. package/dist/rich-text-editor/RichTextEditorFixture.svelte.d.ts +8 -0
  62. package/dist/rich-text-editor/RichTextEditorFixture.svelte.d.ts.map +1 -0
  63. package/dist/rich-text-editor/RichTextEditorNestedFixture.svelte.d.ts +13 -0
  64. package/dist/rich-text-editor/RichTextEditorNestedFixture.svelte.d.ts.map +1 -0
  65. package/dist/rich-text-editor/index.d.ts +10 -0
  66. package/dist/rich-text-editor/index.d.ts.map +1 -0
  67. package/dist/rich-text-editor/index.js +4 -0
  68. package/dist/rich-text-editor/rich-text-editor.css +115 -0
  69. package/package.json +54 -7
@@ -0,0 +1,557 @@
1
+ <script lang="ts">
2
+ import { onMount, tick, untrack } from "svelte";
3
+ import { createRichTextEditor } from "@sentropic/design-system-rich-text/editor";
4
+ import type { RichTextEditor as CoreEditor } from "@sentropic/design-system-rich-text/editor";
5
+ import type {
6
+ CollaborationActor,
7
+ CollaborationCapabilities,
8
+ CollaborationProvider,
9
+ FieldBindingIdentity,
10
+ LockSnapshot,
11
+ PresenceSnapshot,
12
+ RichTextCaptureResult,
13
+ RichTextChangeEvent,
14
+ RichTextDocument,
15
+ RichTextEditorHandle,
16
+ RichTextExternalConflictEvent,
17
+ RichTextMessages,
18
+ RichTextReadiness,
19
+ RichTextUnsupportedPasteEvent,
20
+ } from "@sentropic/design-system-rich-text";
21
+ import {
22
+ RICH_TEXT_UNTRANSLATED_DATA_ATTRIBUTE,
23
+ computeEffectiveEditable,
24
+ createCaptureUnavailableError,
25
+ formatCollabUntranslatedMarker,
26
+ formatUntranslatedMarker,
27
+ collabUntranslatedDataValue,
28
+ untranslatedDataValue,
29
+ } from "@sentropic/design-system-rich-text";
30
+ import type {
31
+ CollabMessageKey,
32
+ RichTextMessageKey,
33
+ } from "@sentropic/design-system-rich-text";
34
+
35
+ export interface RichTextEditorProps {
36
+ value: RichTextDocument;
37
+ /** Content profile (R-FULL-PROFILE-1): `p0` (default) or the CL-2F
38
+ `full` profile. `full` requires `value.format` to be
39
+ `ds.markdown.full@1`; a mismatch refuses the mount. */
40
+ profile?: "p0" | "full";
41
+ editable?: boolean;
42
+ disabled?: boolean;
43
+ messages: RichTextMessages;
44
+ allocateId?: () => string;
45
+ class?: string;
46
+ onChange?: (event: RichTextChangeEvent) => void;
47
+ onExternalConflict?: (event: RichTextExternalConflictEvent) => void;
48
+ onUnsupportedPaste?: (event: RichTextUnsupportedPasteEvent) => void;
49
+ onReadinessChange?: (event: RichTextReadiness) => void;
50
+ // ── CL-2 live extension (spec §6.2; the binding source arrives with the
51
+ // CL-3 Yjs binding, which resolves sessions against `binding`) ──
52
+ /** Injected collaboration provider. Accepted beside the editor; no
53
+ provider call happens in CL-2. Absent ⇒ controlled mode. */
54
+ provider?: CollaborationProvider | null;
55
+ /** Full binding identity of the live field, if any. Present ⇒ live
56
+ (L2) surface: admission decides, the L0 lock snapshot below stays
57
+ information only and never drives `editable` (R-API-2). */
58
+ binding?: FieldBindingIdentity | null;
59
+ /** The local actor for this binding. */
60
+ actor?: CollaborationActor | null;
61
+ /** L0 lock snapshot. Drives inertness only on controlled surfaces
62
+ (holder held by another actor ⇒ read-only); information only when
63
+ `binding` is present. An expired lock is passed as `null`. */
64
+ lock?: LockSnapshot | null;
65
+ /** Co-viewer presence snapshot (host-authoritative). */
66
+ presence?: PresenceSnapshot | null;
67
+ /** Badge derivation facts (B2 §5.1). */
68
+ capabilities?: CollaborationCapabilities | null;
69
+ onPresenceChange?: (snapshot: PresenceSnapshot) => void;
70
+ onLockChange?: (snapshot: LockSnapshot) => void;
71
+ /** Request-unlock action for the composition seam (§6.4). */
72
+ onRequestUnlock?: () => void;
73
+ }
74
+
75
+ let {
76
+ value,
77
+ profile = "p0",
78
+ editable = true,
79
+ disabled = false,
80
+ messages,
81
+ allocateId,
82
+ class: className = "",
83
+ onChange,
84
+ onExternalConflict,
85
+ onUnsupportedPaste,
86
+ onReadinessChange,
87
+ provider = null,
88
+ binding = null,
89
+ actor = null,
90
+ lock = null,
91
+ presence = null,
92
+ capabilities = null,
93
+ onPresenceChange,
94
+ onLockChange,
95
+ onRequestUnlock,
96
+ }: RichTextEditorProps = $props();
97
+
98
+ let root: HTMLDivElement | undefined;
99
+ let mountEl: HTMLDivElement | undefined;
100
+ let core = $state<CoreEditor | null>(null);
101
+ // In-flight full mount (review 3 blocking 1): `createRichTextEditor`
102
+ // stays synchronous for P0 and asynchronous for `profile: "full"`. While
103
+ // pending, prop updates are recorded by the value/editable effects and
104
+ // `captureDocument()` awaits the mount instead of rejecting.
105
+ let pendingCore: Promise<CoreEditor | null> | null = null;
106
+ // Last `value` handed to the §5.6 decision, as a reference plus a snapshot
107
+ // of the significant document fields. A host that re-passes the identical
108
+ // reference (coarse prop update, unrelated re-render) supplies no new
109
+ // value, so re-evaluating it must not replay the decision: replaying the
110
+ // unchanged value would falsely acknowledge a silent draft or raise a
111
+ // spurious conflict. A host `$state` mutation of a nested field
112
+ // (`value.blocks[0].text`) without replacing the reference still changes
113
+ // the snapshot, so it reaches the decision (or the conflict path).
114
+ let lastSeenValue: RichTextDocument | undefined;
115
+ let lastSeenFingerprint: string | undefined;
116
+
117
+ /** Significant document fields for the §5.6 decision (equality of §5.6,
118
+ emission granularity of §5.3): `format` plus, per block in order,
119
+ `paragraphId`, `kind`, P0 text/raw/kind fields and the full
120
+ metadata/segments shapes. Read reactively (outside `untrack`) so
121
+ nested host mutations subscribe. */
122
+ function fingerprintOf(document: RichTextDocument): string {
123
+ const parts: string[] = [document.format, String(document.blocks.length)];
124
+ for (const block of document.blocks) {
125
+ parts.push(
126
+ block.paragraphId,
127
+ block.kind,
128
+ block.text ?? "",
129
+ block.raw ?? "",
130
+ block.preservedKind ?? "",
131
+ JSON.stringify(block.metadata ?? null),
132
+ JSON.stringify(block.segments ?? null),
133
+ JSON.stringify(block.hrMetadata ?? null),
134
+ );
135
+ }
136
+ parts.push(JSON.stringify(document.retainedRunMetadata ?? null));
137
+ return JSON.stringify(parts);
138
+ }
139
+
140
+ function provided(key: RichTextMessageKey): string | undefined {
141
+ const candidate: unknown = messages?.[key];
142
+ return typeof candidate === "string" ? candidate : undefined;
143
+ }
144
+
145
+ function resolveLabel(key: RichTextMessageKey): string {
146
+ return provided(key) ?? formatUntranslatedMarker(key);
147
+ }
148
+
149
+ function isMissing(key: RichTextMessageKey): boolean {
150
+ return provided(key) === undefined;
151
+ }
152
+
153
+ function markUntranslated(element: Element, key: RichTextMessageKey): void {
154
+ if (isMissing(key)) {
155
+ element.setAttribute(
156
+ RICH_TEXT_UNTRANSLATED_DATA_ATTRIBUTE,
157
+ untranslatedDataValue(key),
158
+ );
159
+ } else {
160
+ element.removeAttribute(RICH_TEXT_UNTRANSLATED_DATA_ATTRIBUTE);
161
+ }
162
+ }
163
+
164
+ /** Apply the injected catalogue to the live DOM: the editable root keeps
165
+ its accessible name, the actual placeholder paragraphs carry the
166
+ placeholder text and its missing-key marker, and every preserved
167
+ region keeps its label. Reads `messages`, `editable` and `disabled`
168
+ only — never `value`. Never remounts. */
169
+ function syncChrome(): void {
170
+ const view = core?.view;
171
+ if (!view || !root) return;
172
+ const dom = view.dom;
173
+ const editorLabel = resolveLabel("editorLabel");
174
+ dom.setAttribute("role", "textbox");
175
+ dom.setAttribute("aria-multiline", "true");
176
+ dom.setAttribute("aria-label", editorLabel);
177
+ markUntranslated(dom, "editorLabel");
178
+ // Distinct read-only and disabled semantics (§5.4): disabled is
179
+ // exposed, removed from the tab order and non-selectable (see the
180
+ // stylesheet); read-only stays focusable with its caret.
181
+ dom.setAttribute("aria-disabled", disabled ? "true" : "false");
182
+ dom.setAttribute("tabindex", disabled ? "-1" : "0");
183
+ // Reactive placeholder (§5.7): the live decoration text follows the
184
+ // catalogue through the core (`setPlaceholder` refreshes the
185
+ // decorations with no document transaction), so a locale switch
186
+ // re-renders with no change event. Both the text and the missing-key
187
+ // marker are decoration-backed: manually set DOM attributes would not
188
+ // survive the ProseMirror re-renders that replace the paragraph element.
189
+ core?.setPlaceholder(
190
+ resolveLabel("placeholder"),
191
+ isMissing("placeholder")
192
+ ? untranslatedDataValue("placeholder")
193
+ : null,
194
+ );
195
+ const preservedTemplate = resolveLabel("preservedBlockLabel");
196
+ const preservedMissing = isMissing("preservedBlockLabel");
197
+ const regions = root.querySelectorAll("[data-preserved-block]");
198
+ for (const region of regions) {
199
+ const kind = region.getAttribute("data-preserved-block") ?? "";
200
+ const text = preservedTemplate.includes("{kind}")
201
+ ? preservedTemplate.replace("{kind}", kind)
202
+ : preservedTemplate;
203
+ region.setAttribute("aria-label", text);
204
+ if (preservedMissing) {
205
+ region.setAttribute(
206
+ RICH_TEXT_UNTRANSLATED_DATA_ATTRIBUTE,
207
+ untranslatedDataValue("preservedBlockLabel"),
208
+ );
209
+ } else {
210
+ region.removeAttribute(RICH_TEXT_UNTRANSLATED_DATA_ATTRIBUTE);
211
+ }
212
+ }
213
+ }
214
+
215
+ /** R-API-2 effective editing fact (spec §6.2): exactly one host-computed
216
+ fact per surface mode. A live `binding` keeps admitted editors editable
217
+ under a locked-by-other L0 snapshot; without a binding the same
218
+ snapshot makes the surface read-only. `disabled` wins everywhere. */
219
+ const effectiveEditable = $derived(
220
+ computeEffectiveEditable({
221
+ binding,
222
+ editable,
223
+ lock,
224
+ actorId: actor?.actorId ?? null,
225
+ disabled,
226
+ }),
227
+ );
228
+
229
+ /** Whether the L0 snapshot names an active hold (spec §6.4: an expired
230
+ lock arrives as `null`, so any named holder counts as active here). */
231
+ const lockActive = $derived(lock?.holder != null);
232
+
233
+ /** The live composition seam renders beside the editor while CL-1B owns
234
+ the full badge: lock/presence facts as injected text, never driving
235
+ `editable` (R-API-2 display half). */
236
+ const showLive = $derived(
237
+ binding !== null || lock !== null || presence !== null,
238
+ );
239
+
240
+ function collabProvided(key: CollabMessageKey): string | undefined {
241
+ const candidate: unknown = messages?.[key];
242
+ return typeof candidate === "string" ? candidate : undefined;
243
+ }
244
+
245
+ function resolveCollabLabel(key: CollabMessageKey): string {
246
+ return collabProvided(key) ?? formatCollabUntranslatedMarker(key);
247
+ }
248
+
249
+ function isCollabMissing(key: CollabMessageKey): boolean {
250
+ return collabProvided(key) === undefined;
251
+ }
252
+
253
+ function presenceText(): string {
254
+ const template = resolveCollabLabel("presenceLabel");
255
+ const count = String(presence?.total ?? 0);
256
+ return template.includes("{count}")
257
+ ? template.replace("{count}", count)
258
+ : template;
259
+ }
260
+
261
+ function lockText(): string {
262
+ const holder = lock?.holder ?? null;
263
+ if (holder === null) return resolveCollabLabel("noLockLabel");
264
+ const template = resolveCollabLabel("lockLabel");
265
+ return template.includes("{holder}")
266
+ ? template.replace("{holder}", holder.displayLabel)
267
+ : template;
268
+ }
269
+
270
+ /** Request-unlock is available only to a capable actor on an actively held
271
+ lock while the surface itself stays editable (spec §6.4: read-only mode
272
+ still shows the badge with request-unlock disabled). */
273
+ const unlockEnabled = $derived(
274
+ lockActive &&
275
+ effectiveEditable &&
276
+ (capabilities?.canRequestUnlock ?? false),
277
+ );
278
+
279
+ export function captureDocument(): Promise<RichTextCaptureResult> {
280
+ if (core) return core.captureDocument();
281
+ // Mount pending (review 3 blocking 1): await the in-flight full mount
282
+ // and capture from the settled instance. Reject with the
283
+ // capture-unavailable error only when unmounted or failed during mount.
284
+ if (pendingCore !== null) {
285
+ return pendingCore.then((instance) => {
286
+ if (instance !== null && core !== null) return core.captureDocument();
287
+ return Promise.reject(createCaptureUnavailableError());
288
+ });
289
+ }
290
+ return Promise.reject(createCaptureUnavailableError());
291
+ }
292
+
293
+ export function readiness(): RichTextReadiness {
294
+ if (!core) return { composing: false, ready: false };
295
+ return core.readiness();
296
+ }
297
+
298
+ const stopAtBoundary = (event: Event): void => {
299
+ event.stopPropagation();
300
+ };
301
+ const stopTypes = ["click", "mousedown", "mouseup", "keydown", "keyup"];
302
+
303
+ onMount(() => {
304
+ const mountTarget = mountEl;
305
+ const host = root;
306
+ if (!mountTarget || !host) return;
307
+ // Disabled focus guard (§5.4: a disabled editor is not focusable).
308
+ // `tabindex="-1"` removes sequential keyboard focus only: a pointer
309
+ // click still moves focus through the mousedown default, and a
310
+ // programmatic `focus()` still lands. While disabled, the mousedown
311
+ // default is prevented and any focus landing inside is blurred back.
312
+ const guardDisabledPointer = (event: Event): void => {
313
+ if (!disabled) return;
314
+ if (event.target instanceof Element && host.contains(event.target)) {
315
+ event.preventDefault();
316
+ }
317
+ };
318
+ const guardDisabledFocus = (event: Event): void => {
319
+ if (!disabled) return;
320
+ if (event.target instanceof HTMLElement && host.contains(event.target)) {
321
+ event.target.blur();
322
+ }
323
+ };
324
+ // Stable forwarders: the core captures its callbacks once, while the
325
+ // props they read stay live, so a parent re-render never needs a remount.
326
+ // The mount document initialises the core and the acknowledgement
327
+ // reference, so it is recorded as seen without a §5.6 evaluation.
328
+ // The mount snapshot below reconciles any prop flip that arrives while
329
+ // the full graph loads (review 3 blocking 1).
330
+ const mountValue = value;
331
+ const mountFingerprint = fingerprintOf(value);
332
+ lastSeenValue = value;
333
+ lastSeenFingerprint = mountFingerprint;
334
+ let cancelled = false;
335
+ const settle = (instance: CoreEditor): void => {
336
+ if (cancelled) {
337
+ instance.destroy();
338
+ return;
339
+ }
340
+ core = instance;
341
+ for (const type of stopTypes) {
342
+ host.addEventListener(type, stopAtBoundary);
343
+ }
344
+ host.addEventListener("mousedown", guardDisabledPointer);
345
+ // `focus` does not bubble: capture from the host so a programmatic
346
+ // `focus()` on the editable element is still observed.
347
+ host.addEventListener("focus", guardDisabledFocus, true);
348
+ // Reconcile prop updates that arrived while the full graph loaded:
349
+ // the value effect recorded the latest host value while `core` was
350
+ // null, so apply it now instead of leaving the mount value stale;
351
+ // effective editability follows the current props, not the mount.
352
+ instance.setEditable(effectiveEditable);
353
+ instance.setDisabled(disabled);
354
+ const current = value;
355
+ const currentFingerprint = fingerprintOf(current);
356
+ if (current !== mountValue || currentFingerprint !== mountFingerprint) {
357
+ lastSeenValue = current;
358
+ lastSeenFingerprint = currentFingerprint;
359
+ untrack(() => {
360
+ instance.applyExternalUpdate(current);
361
+ });
362
+ }
363
+ syncChrome();
364
+ // Placeholder decorations land after the ProseMirror observer flush,
365
+ // past the synchronous mount sync: re-sync once settled so the
366
+ // displaying paragraph carries the marker with no transaction.
367
+ void tick().then(() => {
368
+ syncChrome();
369
+ });
370
+ };
371
+ // Single-prop opt-in (R-FULL-PROFILE-1): full construction loads the
372
+ // extension graph on demand and is asynchronous, P0 stays synchronous.
373
+ // The pending gap keeps `readiness()` not-ready while `core` is null;
374
+ // `captureDocument()` awaits the pending mount (rejecting only when
375
+ // unmounted or failed during mount).
376
+ const maybeCore = createRichTextEditor({
377
+ document: value,
378
+ profile,
379
+ messages: {
380
+ ...messages,
381
+ placeholder: provided("placeholder") ?? formatUntranslatedMarker("placeholder"),
382
+ },
383
+ ...(allocateId !== undefined ? { allocateId } : {}),
384
+ editable: effectiveEditable,
385
+ disabled,
386
+ collaborationBinding: binding,
387
+ element: mountTarget,
388
+ onChange: (event) => {
389
+ syncChrome();
390
+ onChange?.(event);
391
+ },
392
+ onExternalConflict: (event) => {
393
+ onExternalConflict?.(event);
394
+ },
395
+ onUnsupportedPaste: (event) => {
396
+ onUnsupportedPaste?.(event);
397
+ },
398
+ onReadinessChange: (event) => {
399
+ onReadinessChange?.(event);
400
+ },
401
+ }) as CoreEditor | Promise<CoreEditor>;
402
+ if (maybeCore instanceof Promise) {
403
+ pendingCore = maybeCore.then(
404
+ (instance) => {
405
+ settle(instance);
406
+ return cancelled ? null : instance;
407
+ },
408
+ () => {
409
+ // A failed full-graph load leaves the surface unmounted; the host
410
+ // observes it through the pending readiness path (never a throw
411
+ // out of the mount effect).
412
+ return null;
413
+ },
414
+ );
415
+ } else {
416
+ pendingCore = null;
417
+ settle(maybeCore);
418
+ }
419
+ return () => {
420
+ cancelled = true;
421
+ pendingCore = null;
422
+ for (const type of stopTypes) {
423
+ host.removeEventListener(type, stopAtBoundary);
424
+ }
425
+ host.removeEventListener("mousedown", guardDisabledPointer);
426
+ host.removeEventListener("focus", guardDisabledFocus, true);
427
+ core?.destroy();
428
+ core = null;
429
+ };
430
+ });
431
+
432
+ // Controlled value (§5.6): this effect tracks `value` by reference plus a
433
+ // snapshot of its significant document fields, read reactively above the
434
+ // `untrack` boundary. The update is applied inside `untrack` and chrome is
435
+ // re-synced there too, so a locale switch (messages change, value
436
+ // untouched) never replays the unchanged value through the §5.6 decision
437
+ // — replaying would falsely acknowledge a silent draft or raise a
438
+ // spurious conflict — while a nested host `$state` mutation of
439
+ // `value.blocks[i]` with the reference kept still reaches the decision.
440
+ // Never recreates the editor.
441
+ $effect(() => {
442
+ const snapshot = value;
443
+ const fingerprint = fingerprintOf(snapshot);
444
+ const instance = core;
445
+ if (!instance) {
446
+ lastSeenValue = snapshot;
447
+ lastSeenFingerprint = fingerprint;
448
+ return;
449
+ }
450
+ // Same reference and same significant fields: no new value, no §5.6
451
+ // replay. The chrome effect below still tracks messages, editable
452
+ // and disabled, so labels keep re-rendering on a locale switch.
453
+ if (snapshot === lastSeenValue && fingerprint === lastSeenFingerprint) {
454
+ return;
455
+ }
456
+ lastSeenValue = snapshot;
457
+ lastSeenFingerprint = fingerprint;
458
+ untrack(() => {
459
+ instance.applyExternalUpdate(snapshot);
460
+ syncChrome();
461
+ });
462
+ });
463
+
464
+ $effect(() => {
465
+ core?.setEditable(effectiveEditable);
466
+ core?.setDisabled(disabled);
467
+ // Entering the disabled state releases focus: a caret left inside the
468
+ // editor when the host disables it must not stay there (§5.4).
469
+ if (
470
+ disabled &&
471
+ typeof globalThis.document !== "undefined" &&
472
+ root?.contains(globalThis.document.activeElement as Node | null)
473
+ ) {
474
+ (globalThis.document.activeElement as HTMLElement).blur();
475
+ }
476
+ });
477
+
478
+ // Locale and state chrome: re-render labels in place, no remount, no
479
+ // change event. Tracks `messages`, `editable` and `disabled` only —
480
+ // never `value`.
481
+ $effect(() => {
482
+ if (!core) return;
483
+ syncChrome();
484
+ });
485
+
486
+ // Snapshot subscriptions (CL-2 seam): the host owns the snapshots; the
487
+ // component notifies on every new snapshot reference, including the
488
+ // initial one. No provider call happens here; live subscription arrives
489
+ // with the CL-3 binding.
490
+ let lastNotifiedLock: LockSnapshot | null = null;
491
+ let lastNotifiedPresence: PresenceSnapshot | null = null;
492
+ $effect(() => {
493
+ const snapshot = lock;
494
+ if (snapshot !== lastNotifiedLock) {
495
+ lastNotifiedLock = snapshot;
496
+ if (snapshot !== null) {
497
+ const callback = onLockChange;
498
+ if (callback) untrack(() => callback(snapshot));
499
+ }
500
+ }
501
+ });
502
+ $effect(() => {
503
+ const snapshot = presence;
504
+ if (snapshot !== lastNotifiedPresence) {
505
+ lastNotifiedPresence = snapshot;
506
+ if (snapshot !== null) {
507
+ const callback = onPresenceChange;
508
+ if (callback) untrack(() => callback(snapshot));
509
+ }
510
+ }
511
+ });
512
+
513
+ const classes = (): string =>
514
+ ["st-rich-text-editor", className].filter((part) => part !== "").join(" ");
515
+
516
+ const statusText = (): string => resolveLabel("externalConflictLabel");
517
+
518
+ const statusUntranslated = (): string | null =>
519
+ isMissing("externalConflictLabel")
520
+ ? untranslatedDataValue("externalConflictLabel")
521
+ : null;
522
+ </script>
523
+
524
+ <div class={classes()} bind:this={root}>
525
+ <div class="st-rich-text-editor__surface" bind:this={mountEl}></div>
526
+ {#if showLive}
527
+ <div class="st-rich-text-editor__live" data-testid="live-seam">
528
+ <span
529
+ class="st-rich-text-editor__presence"
530
+ data-untranslated={isCollabMissing("presenceLabel")
531
+ ? collabUntranslatedDataValue("presenceLabel")
532
+ : null}
533
+ >{presenceText()}</span>
534
+ <span
535
+ class="st-rich-text-editor__lock"
536
+ data-untranslated={isCollabMissing(lock?.holder == null ? "noLockLabel" : "lockLabel")
537
+ ? collabUntranslatedDataValue(lock?.holder == null ? "noLockLabel" : "lockLabel")
538
+ : null}
539
+ >{lockText()}</span>
540
+ {#if capabilities?.canRequestUnlock}
541
+ <button
542
+ type="button"
543
+ class="st-rich-text-editor__unlock"
544
+ data-untranslated={isCollabMissing("unlockRequestLabel")
545
+ ? collabUntranslatedDataValue("unlockRequestLabel")
546
+ : null}
547
+ disabled={!unlockEnabled}
548
+ onclick={() => onRequestUnlock?.()}
549
+ >{resolveCollabLabel("unlockRequestLabel")}</button>
550
+ {/if}
551
+ </div>
552
+ {/if}
553
+ <div
554
+ class="st-rich-text-editor__status"
555
+ data-untranslated={statusUntranslated()}
556
+ >{statusText()}</div>
557
+ </div>
@@ -0,0 +1,45 @@
1
+ import type { CollaborationActor, CollaborationCapabilities, CollaborationProvider, FieldBindingIdentity, LockSnapshot, PresenceSnapshot, RichTextCaptureResult, RichTextChangeEvent, RichTextDocument, RichTextExternalConflictEvent, RichTextMessages, RichTextReadiness, RichTextUnsupportedPasteEvent } from "@sentropic/design-system-rich-text";
2
+ export interface RichTextEditorProps {
3
+ value: RichTextDocument;
4
+ /** Content profile (R-FULL-PROFILE-1): `p0` (default) or the CL-2F
5
+ `full` profile. `full` requires `value.format` to be
6
+ `ds.markdown.full@1`; a mismatch refuses the mount. */
7
+ profile?: "p0" | "full";
8
+ editable?: boolean;
9
+ disabled?: boolean;
10
+ messages: RichTextMessages;
11
+ allocateId?: () => string;
12
+ class?: string;
13
+ onChange?: (event: RichTextChangeEvent) => void;
14
+ onExternalConflict?: (event: RichTextExternalConflictEvent) => void;
15
+ onUnsupportedPaste?: (event: RichTextUnsupportedPasteEvent) => void;
16
+ onReadinessChange?: (event: RichTextReadiness) => void;
17
+ /** Injected collaboration provider. Accepted beside the editor; no
18
+ provider call happens in CL-2. Absent ⇒ controlled mode. */
19
+ provider?: CollaborationProvider | null;
20
+ /** Full binding identity of the live field, if any. Present ⇒ live
21
+ (L2) surface: admission decides, the L0 lock snapshot below stays
22
+ information only and never drives `editable` (R-API-2). */
23
+ binding?: FieldBindingIdentity | null;
24
+ /** The local actor for this binding. */
25
+ actor?: CollaborationActor | null;
26
+ /** L0 lock snapshot. Drives inertness only on controlled surfaces
27
+ (holder held by another actor ⇒ read-only); information only when
28
+ `binding` is present. An expired lock is passed as `null`. */
29
+ lock?: LockSnapshot | null;
30
+ /** Co-viewer presence snapshot (host-authoritative). */
31
+ presence?: PresenceSnapshot | null;
32
+ /** Badge derivation facts (B2 §5.1). */
33
+ capabilities?: CollaborationCapabilities | null;
34
+ onPresenceChange?: (snapshot: PresenceSnapshot) => void;
35
+ onLockChange?: (snapshot: LockSnapshot) => void;
36
+ /** Request-unlock action for the composition seam (§6.4). */
37
+ onRequestUnlock?: () => void;
38
+ }
39
+ declare const RichTextEditor: import("svelte").Component<RichTextEditorProps, {
40
+ captureDocument: () => Promise<RichTextCaptureResult>;
41
+ readiness: () => RichTextReadiness;
42
+ }, "">;
43
+ type RichTextEditor = ReturnType<typeof RichTextEditor>;
44
+ export default RichTextEditor;
45
+ //# sourceMappingURL=RichTextEditor.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RichTextEditor.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/rich-text-editor/RichTextEditor.svelte.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACR,kBAAkB,EAClB,yBAAyB,EACzB,qBAAqB,EACrB,oBAAoB,EACpB,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,EAEhB,6BAA6B,EAC7B,gBAAgB,EAChB,iBAAiB,EACjB,6BAA6B,EAC9B,MAAM,oCAAoC,CAAC;AAgB5C,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,gBAAgB,CAAC;IACxB;;8DAE0D;IAC1D,OAAO,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAChD,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,6BAA6B,KAAK,IAAI,CAAC;IACpE,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,6BAA6B,KAAK,IAAI,CAAC;IACpE,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAGvD;mEAC+D;IAC/D,QAAQ,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAAC;IACxC;;kEAE8D;IAC9D,OAAO,CAAC,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACtC,wCAAwC;IACxC,KAAK,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAClC;;qEAEiE;IACjE,IAAI,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IAC3B,wDAAwD;IACxD,QAAQ,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACnC,wCAAwC;IACxC,YAAY,CAAC,EAAE,yBAAyB,GAAG,IAAI,CAAC;IAChD,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,gBAAgB,KAAK,IAAI,CAAC;IACxD,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,YAAY,KAAK,IAAI,CAAC;IAChD,6DAA6D;IAC7D,eAAe,CAAC,EAAE,MAAM,IAAI,CAAC;CAC9B;AAieH,QAAA,MAAM,cAAc;2BA3QW,OAAO,CAAC,qBAAqB,CAAC;qBAcpC,iBAAiB;MA6PkB,CAAC;AAC7D,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AACxD,eAAe,cAAc,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { RichTextEditorProps } from "./RichTextEditor.svelte";
2
+ type FixtureProps = RichTextEditorProps & {
3
+ onCardSelect: () => void;
4
+ };
5
+ declare const RichTextEditorFixture: import("svelte").Component<FixtureProps, {}, "">;
6
+ type RichTextEditorFixture = ReturnType<typeof RichTextEditorFixture>;
7
+ export default RichTextEditorFixture;
8
+ //# sourceMappingURL=RichTextEditorFixture.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RichTextEditorFixture.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/rich-text-editor/RichTextEditorFixture.svelte.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAGjE,KAAK,YAAY,GAAG,mBAAmB,GAAG;IACxC,YAAY,EAAE,MAAM,IAAI,CAAC;CAC1B,CAAC;AAiBJ,QAAA,MAAM,qBAAqB,kDAAwC,CAAC;AACpE,KAAK,qBAAqB,GAAG,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACtE,eAAe,qBAAqB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { RichTextDocument } from "@sentropic/design-system-rich-text";
2
+ import type { RichTextEditorProps } from "./RichTextEditor.svelte";
3
+ type FixtureProps = Omit<RichTextEditorProps, "value" | "messages"> & {
4
+ initial: RichTextDocument;
5
+ messages: RichTextEditorProps["messages"];
6
+ };
7
+ declare const RichTextEditorNestedFixture: import("svelte").Component<FixtureProps, {
8
+ updateNestedText: (text: string) => void;
9
+ currentValue: () => RichTextDocument;
10
+ }, "">;
11
+ type RichTextEditorNestedFixture = ReturnType<typeof RichTextEditorNestedFixture>;
12
+ export default RichTextEditorNestedFixture;
13
+ //# sourceMappingURL=RichTextEditorNestedFixture.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RichTextEditorNestedFixture.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/rich-text-editor/RichTextEditorNestedFixture.svelte.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAGjE,KAAK,YAAY,GAAG,IAAI,CAAC,mBAAmB,EAAE,OAAO,GAAG,UAAU,CAAC,GAAG;IACpE,OAAO,EAAE,gBAAgB,CAAC;IAC1B,QAAQ,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC;CAC3C,CAAC;AA4BJ,QAAA,MAAM,2BAA2B;6BAjBE,MAAM,KAAG,IAAI;wBAOpB,gBAAgB;MAU6B,CAAC;AAC1E,KAAK,2BAA2B,GAAG,UAAU,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAClF,eAAe,2BAA2B,CAAC"}
@@ -0,0 +1,10 @@
1
+ import ComposerEditor from "./ComposerEditor.svelte";
2
+ import type { ComposerEditorProps } from "./ComposerEditor.svelte";
3
+ import RichTextEditor from "./RichTextEditor.svelte";
4
+ import type { RichTextEditorProps } from "./RichTextEditor.svelte";
5
+ import type { RichTextEditorHandle } from "@sentropic/design-system-rich-text";
6
+ import type { ComposerEditorHandle } from "@sentropic/design-system-rich-text";
7
+ export default RichTextEditor;
8
+ export { RichTextEditor, ComposerEditor };
9
+ export type { RichTextEditorProps, RichTextEditorHandle, ComposerEditorProps, ComposerEditorHandle, };
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/rich-text-editor/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,cAAc,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC/E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE/E,eAAe,cAAc,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,CAAC;AAC1C,YAAY,EACV,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,GACrB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import ComposerEditor from "./ComposerEditor.svelte";
2
+ import RichTextEditor from "./RichTextEditor.svelte";
3
+ export default RichTextEditor;
4
+ export { RichTextEditor, ComposerEditor };