@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.
- package/LICENSE.THIRD-PARTY.md +74 -1
- package/dist/Calendar.svelte +28 -1
- package/dist/Calendar.svelte.d.ts +7 -0
- package/dist/Calendar.svelte.d.ts.map +1 -1
- package/dist/ContentSwitcher.svelte +6 -1
- package/dist/DiagramCard.svelte +282 -0
- package/dist/DiagramCard.svelte.d.ts +44 -0
- package/dist/DiagramCard.svelte.d.ts.map +1 -0
- package/dist/DiagramCardHeader.svelte +173 -0
- package/dist/DiagramCardHeader.svelte.d.ts +37 -0
- package/dist/DiagramCardHeader.svelte.d.ts.map +1 -0
- package/dist/DiagramZone.svelte +378 -0
- package/dist/DiagramZone.svelte.d.ts +45 -0
- package/dist/DiagramZone.svelte.d.ts.map +1 -0
- package/dist/DiagramZoneHeader.svelte +97 -0
- package/dist/DiagramZoneHeader.svelte.d.ts +40 -0
- package/dist/DiagramZoneHeader.svelte.d.ts.map +1 -0
- package/dist/MenuPopover.svelte +101 -12
- package/dist/MenuPopover.svelte.d.ts.map +1 -1
- package/dist/Pagination.svelte +5 -0
- package/dist/RadioGroup.svelte +4 -1
- package/dist/TimeRangePicker.svelte +19 -1
- package/dist/TimeRangePicker.svelte.d.ts.map +1 -1
- package/dist/diagram-icons/DiagramIcon.svelte +65 -0
- package/dist/diagram-icons/DiagramIcon.svelte.d.ts +11 -0
- package/dist/diagram-icons/DiagramIcon.svelte.d.ts.map +1 -0
- package/dist/diagram-icons/PROVENANCE.md +72 -0
- package/dist/diagram-icons/index.d.ts +6 -0
- package/dist/diagram-icons/index.d.ts.map +1 -0
- package/dist/diagram-icons/index.js +4 -0
- package/dist/diagram-icons/registry.d.ts +52 -0
- package/dist/diagram-icons/registry.d.ts.map +1 -0
- package/dist/diagram-icons/registry.js +79 -0
- package/dist/diagram-render/index.d.ts +17 -0
- package/dist/diagram-render/index.d.ts.map +1 -0
- package/dist/diagram-render/index.js +11 -0
- package/dist/diagram-render/renderCardSvg.d.ts +83 -0
- package/dist/diagram-render/renderCardSvg.d.ts.map +1 -0
- package/dist/diagram-render/renderCardSvg.js +149 -0
- package/dist/diagram-render/renderZoneSvg.d.ts +88 -0
- package/dist/diagram-render/renderZoneSvg.d.ts.map +1 -0
- package/dist/diagram-render/renderZoneSvg.js +184 -0
- package/dist/diagramCardModel.d.ts +582 -0
- package/dist/diagramCardModel.d.ts.map +1 -0
- package/dist/diagramCardModel.js +1133 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/presence-badge/LockPresenceBadge.svelte +490 -0
- package/dist/presence-badge/LockPresenceBadge.svelte.d.ts +18 -0
- package/dist/presence-badge/LockPresenceBadge.svelte.d.ts.map +1 -0
- package/dist/presence-badge/index.d.ts +6 -0
- package/dist/presence-badge/index.d.ts.map +1 -0
- package/dist/presence-badge/index.js +3 -0
- package/dist/rich-text-editor/ComposerEditor.svelte +485 -0
- package/dist/rich-text-editor/ComposerEditor.svelte.d.ts +16 -0
- package/dist/rich-text-editor/ComposerEditor.svelte.d.ts.map +1 -0
- package/dist/rich-text-editor/RichTextEditor.svelte +557 -0
- package/dist/rich-text-editor/RichTextEditor.svelte.d.ts +45 -0
- package/dist/rich-text-editor/RichTextEditor.svelte.d.ts.map +1 -0
- package/dist/rich-text-editor/RichTextEditorFixture.svelte.d.ts +8 -0
- package/dist/rich-text-editor/RichTextEditorFixture.svelte.d.ts.map +1 -0
- package/dist/rich-text-editor/RichTextEditorNestedFixture.svelte.d.ts +13 -0
- package/dist/rich-text-editor/RichTextEditorNestedFixture.svelte.d.ts.map +1 -0
- package/dist/rich-text-editor/index.d.ts +10 -0
- package/dist/rich-text-editor/index.d.ts.map +1 -0
- package/dist/rich-text-editor/index.js +4 -0
- package/dist/rich-text-editor/rich-text-editor.css +115 -0
- package/package.json +54 -7
|
@@ -0,0 +1,485 @@
|
|
|
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
|
+
ComposerCaptureResult,
|
|
7
|
+
ComposerEditorProps as ComposerContract,
|
|
8
|
+
ComposerKeyEvent,
|
|
9
|
+
RichTextDocument,
|
|
10
|
+
RichTextMessages,
|
|
11
|
+
RichTextReadiness,
|
|
12
|
+
} from "@sentropic/design-system-rich-text";
|
|
13
|
+
import {
|
|
14
|
+
RICH_TEXT_UNTRANSLATED_DATA_ATTRIBUTE,
|
|
15
|
+
composerDocumentFromText,
|
|
16
|
+
composerFullSeededDocumentForText,
|
|
17
|
+
composerFullSeededDocumentFromText,
|
|
18
|
+
composerFullSeededTextFromDocument,
|
|
19
|
+
composerTextFromDocument,
|
|
20
|
+
createCaptureUnavailableError,
|
|
21
|
+
formatUntranslatedMarker,
|
|
22
|
+
splitComposerText,
|
|
23
|
+
untranslatedDataValue,
|
|
24
|
+
} from "@sentropic/design-system-rich-text";
|
|
25
|
+
import type { RichTextMessageKey } from "@sentropic/design-system-rich-text";
|
|
26
|
+
|
|
27
|
+
/** Svelte props for the §6.2.1 string surface: the contract plus the
|
|
28
|
+
identity injection point and a class passthrough. The `profile` prop
|
|
29
|
+
selects the conversion path (R-FULL-PROFILE-1): `p0` (default) keeps
|
|
30
|
+
the chunk mapping; `full` parses through the full Markdown bridge. */
|
|
31
|
+
export interface ComposerEditorProps extends ComposerContract {
|
|
32
|
+
allocateId?: () => string;
|
|
33
|
+
class?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let {
|
|
37
|
+
value,
|
|
38
|
+
profile = "p0",
|
|
39
|
+
editable = true,
|
|
40
|
+
disabled = false,
|
|
41
|
+
messages,
|
|
42
|
+
placeholder,
|
|
43
|
+
allocateId,
|
|
44
|
+
class: className = "",
|
|
45
|
+
onChange,
|
|
46
|
+
onReadinessChange,
|
|
47
|
+
onKeyDown,
|
|
48
|
+
}: ComposerEditorProps = $props();
|
|
49
|
+
|
|
50
|
+
let root: HTMLDivElement | undefined;
|
|
51
|
+
let mountEl: HTMLDivElement | undefined;
|
|
52
|
+
let core = $state<CoreEditor | null>(null);
|
|
53
|
+
// In-flight full mount (review 3 blocking 1): `profile: "full"` builds
|
|
54
|
+
// asynchronously while P0 stays synchronous. `captureComposer()` awaits
|
|
55
|
+
// the pending mount and rejects only when unmounted during mount.
|
|
56
|
+
let pendingCore: Promise<CoreEditor | null> | null = null;
|
|
57
|
+
let lastSeenValue: string | undefined;
|
|
58
|
+
let localSequence = 0;
|
|
59
|
+
// Synthetic TrailingNode paragraph (review 3 blocking 3b): when the full
|
|
60
|
+
// mount ends with a non-paragraph block, Tiptap appends an empty trailing
|
|
61
|
+
// paragraph. Its id is recorded so the untouched composer re-emits the
|
|
62
|
+
// input byte-identically (R-COMP-2) instead of appending `"\n\n"`.
|
|
63
|
+
let trailingId: string | null = null;
|
|
64
|
+
|
|
65
|
+
/** Mount-local fallback allocator (non-Focus default): identities stay
|
|
66
|
+
internal to the composer and never reach the chat host. */
|
|
67
|
+
function freshId(): string {
|
|
68
|
+
if (allocateId !== undefined) return allocateId();
|
|
69
|
+
localSequence += 1;
|
|
70
|
+
return `composer:generated-${localSequence}`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Full-profile conversion seeds (review 1 item 10): untouched source
|
|
74
|
+
slice per block identity, retained across mount, edits and host
|
|
75
|
+
replacements so untouched slices re-emit byte-identically. Gesture
|
|
76
|
+
`affectedParagraphIds` mark the touched set; a host replacement
|
|
77
|
+
re-parses and resets both. P0 keeps the chunk mapping (no seeds). */
|
|
78
|
+
let fullSeeds: Map<string, string> = new Map();
|
|
79
|
+
let fullTouched: Set<string> = new Set();
|
|
80
|
+
|
|
81
|
+
/** Controlled string → document with positional identity reuse: the
|
|
82
|
+
chunk at an index the displayed document already holds keeps that
|
|
83
|
+
block's identity, so a host echo of the last emitted string decides
|
|
84
|
+
as §5.6 rule 1 (acknowledge, no conflict) instead of a spurious
|
|
85
|
+
session conflict. The synthetic TrailingNode paragraph elides while
|
|
86
|
+
it stays empty and untouched, so an untouched composer whose last
|
|
87
|
+
block is not a paragraph captures byte-identically (R-COMP-2). */
|
|
88
|
+
function textFromDocument(document: RichTextDocument): string {
|
|
89
|
+
if (profile !== "full") return composerTextFromDocument(document);
|
|
90
|
+
if (document.blocks.length > 0) {
|
|
91
|
+
const last = document.blocks[document.blocks.length - 1];
|
|
92
|
+
const lastId = last?.paragraphId;
|
|
93
|
+
// The synthetic TrailingNode paragraph has no seed (it was never in
|
|
94
|
+
// the parsed input) and stays untouched: elide it while empty so an
|
|
95
|
+
// untouched composer captures byte-identically (R-COMP-2). A genuine
|
|
96
|
+
// trailing empty block carries its seed and is kept.
|
|
97
|
+
const synthetic =
|
|
98
|
+
lastId !== undefined &&
|
|
99
|
+
((trailingId !== null && lastId === trailingId) || !fullSeeds.has(lastId)) &&
|
|
100
|
+
!fullTouched.has(lastId);
|
|
101
|
+
const empty =
|
|
102
|
+
last?.kind === "paragraph" &&
|
|
103
|
+
(last.segments === undefined || last.segments.length === 0) &&
|
|
104
|
+
(last.text === undefined || last.text === "");
|
|
105
|
+
if (synthetic && empty) {
|
|
106
|
+
return composerFullSeededTextFromDocument(
|
|
107
|
+
{ format: "ds.markdown.full@1", blocks: document.blocks.slice(0, -1) },
|
|
108
|
+
fullSeeds,
|
|
109
|
+
fullTouched,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return composerFullSeededTextFromDocument(document, fullSeeds, fullTouched);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function documentForText(text: string): RichTextDocument {
|
|
117
|
+
if (profile === "full") {
|
|
118
|
+
const previous = core?.getDocument()?.blocks ?? [];
|
|
119
|
+
const seeded = composerFullSeededDocumentForText(text, previous, freshId);
|
|
120
|
+
fullSeeds = seeded.seeds;
|
|
121
|
+
fullTouched = new Set();
|
|
122
|
+
return seeded.document;
|
|
123
|
+
}
|
|
124
|
+
const chunks = splitComposerText(text);
|
|
125
|
+
const previous = core?.getDocument()?.blocks ?? [];
|
|
126
|
+
return {
|
|
127
|
+
format: "focus.markdown.p0@1",
|
|
128
|
+
blocks: chunks.map((chunk, index) => {
|
|
129
|
+
const prior = previous[index];
|
|
130
|
+
return {
|
|
131
|
+
paragraphId:
|
|
132
|
+
prior !== undefined && prior.kind === "paragraph"
|
|
133
|
+
? prior.paragraphId
|
|
134
|
+
: freshId(),
|
|
135
|
+
kind: "paragraph" as const,
|
|
136
|
+
text: chunk,
|
|
137
|
+
};
|
|
138
|
+
}),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function mountDocumentForText(text: string): RichTextDocument {
|
|
143
|
+
if (profile === "full") {
|
|
144
|
+
const seeded = composerFullSeededDocumentFromText(text, freshId);
|
|
145
|
+
fullSeeds = seeded.seeds;
|
|
146
|
+
fullTouched = new Set();
|
|
147
|
+
return seeded.document;
|
|
148
|
+
}
|
|
149
|
+
return composerDocumentFromText(text, freshId);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Record the synthetic TrailingNode paragraph appended on mount or host
|
|
153
|
+
replacement: exactly one extra empty paragraph whose id the input did
|
|
154
|
+
not carry. Any other shape leaves `trailingId` null. */
|
|
155
|
+
function refreshTrailingId(
|
|
156
|
+
inputBlocks: RichTextDocument["blocks"],
|
|
157
|
+
displayedBlocks: RichTextDocument["blocks"],
|
|
158
|
+
): void {
|
|
159
|
+
if (profile !== "full") {
|
|
160
|
+
trailingId = null;
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (displayedBlocks.length !== inputBlocks.length + 1) {
|
|
164
|
+
trailingId = null;
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const inputIds = new Set(inputBlocks.map((block) => block.paragraphId));
|
|
168
|
+
const last = displayedBlocks[displayedBlocks.length - 1];
|
|
169
|
+
if (
|
|
170
|
+
last?.kind === "paragraph" &&
|
|
171
|
+
!inputIds.has(last.paragraphId) &&
|
|
172
|
+
(last.segments === undefined || last.segments.length === 0) &&
|
|
173
|
+
(last.text === undefined || last.text === "")
|
|
174
|
+
) {
|
|
175
|
+
trailingId = last.paragraphId;
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
trailingId = null;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function isActive(): boolean {
|
|
182
|
+
return editable && !disabled;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function provided(key: RichTextMessageKey): string | undefined {
|
|
186
|
+
const candidate: unknown = messages?.[key];
|
|
187
|
+
return typeof candidate === "string" ? candidate : undefined;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function resolveLabel(key: RichTextMessageKey): string {
|
|
191
|
+
return provided(key) ?? formatUntranslatedMarker(key);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function isMissing(key: RichTextMessageKey): boolean {
|
|
195
|
+
return provided(key) === undefined;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function markUntranslated(element: Element, key: RichTextMessageKey): void {
|
|
199
|
+
if (isMissing(key)) {
|
|
200
|
+
element.setAttribute(
|
|
201
|
+
RICH_TEXT_UNTRANSLATED_DATA_ATTRIBUTE,
|
|
202
|
+
untranslatedDataValue(key),
|
|
203
|
+
);
|
|
204
|
+
} else {
|
|
205
|
+
element.removeAttribute(RICH_TEXT_UNTRANSLATED_DATA_ATTRIBUTE);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function syncChrome(): void {
|
|
210
|
+
const view = core?.view;
|
|
211
|
+
if (!view || !root) return;
|
|
212
|
+
const dom = view.dom;
|
|
213
|
+
const editorLabel = resolveLabel("editorLabel");
|
|
214
|
+
dom.setAttribute("role", "textbox");
|
|
215
|
+
dom.setAttribute("aria-multiline", "true");
|
|
216
|
+
dom.setAttribute("aria-label", editorLabel);
|
|
217
|
+
markUntranslated(dom, "editorLabel");
|
|
218
|
+
dom.setAttribute("aria-disabled", disabled ? "true" : "false");
|
|
219
|
+
dom.setAttribute("tabindex", disabled ? "-1" : "0");
|
|
220
|
+
core?.setPlaceholder(
|
|
221
|
+
placeholder ?? resolveLabel("placeholder"),
|
|
222
|
+
placeholder !== undefined
|
|
223
|
+
? null
|
|
224
|
+
: isMissing("placeholder")
|
|
225
|
+
? untranslatedDataValue("placeholder")
|
|
226
|
+
: null,
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Deferred composer capture (R-COMP-2): the string and the
|
|
231
|
+
representability of the same captured revision. During an IME
|
|
232
|
+
composition it waits for the commit and resolves once; a capture
|
|
233
|
+
pending at unmount rejects exactly once with
|
|
234
|
+
`RichTextCaptureUnavailable` (IME-LOCK-1 clause 4). */
|
|
235
|
+
export function captureComposer(): Promise<ComposerCaptureResult> {
|
|
236
|
+
if (core) {
|
|
237
|
+
return core.captureDocument().then((captured) => ({
|
|
238
|
+
text: textFromDocument(captured.document),
|
|
239
|
+
representability: captured.representability,
|
|
240
|
+
}));
|
|
241
|
+
}
|
|
242
|
+
// Mount pending (review 3 blocking 1): await the in-flight full mount
|
|
243
|
+
// and capture from the settled instance. Reject only when unmounted
|
|
244
|
+
// or failed during mount.
|
|
245
|
+
if (pendingCore !== null) {
|
|
246
|
+
return pendingCore.then((instance) => {
|
|
247
|
+
if (instance !== null && core !== null) {
|
|
248
|
+
return core.captureDocument().then((captured) => ({
|
|
249
|
+
text: textFromDocument(captured.document),
|
|
250
|
+
representability: captured.representability,
|
|
251
|
+
}));
|
|
252
|
+
}
|
|
253
|
+
return Promise.reject(createCaptureUnavailableError());
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
return Promise.reject(createCaptureUnavailableError());
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export function readiness(): RichTextReadiness {
|
|
260
|
+
if (!core) return { composing: false, ready: false };
|
|
261
|
+
return core.readiness();
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function toComposerKeyEvent(native: KeyboardEvent): ComposerKeyEvent {
|
|
265
|
+
const active = core;
|
|
266
|
+
return {
|
|
267
|
+
key: native.key,
|
|
268
|
+
code: native.code,
|
|
269
|
+
shiftKey: native.shiftKey,
|
|
270
|
+
ctrlKey: native.ctrlKey,
|
|
271
|
+
metaKey: native.metaKey,
|
|
272
|
+
altKey: native.altKey,
|
|
273
|
+
isComposing: native.isComposing || (active?.readiness().composing ?? false),
|
|
274
|
+
preventDefault: () => native.preventDefault(),
|
|
275
|
+
stopPropagation: () => native.stopPropagation(),
|
|
276
|
+
get defaultPrevented() {
|
|
277
|
+
return native.defaultPrevented;
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Sending-adjacent keys (Enter, mention triggers, any key while the host
|
|
283
|
+
// subscribes) are forwarded with modifiers and composition facts, never
|
|
284
|
+
// consumed for sending by the DS (R-COMP-3). Capture phase on the root so
|
|
285
|
+
// a host-handled key reaches `preventDefault()` before ProseMirror's own
|
|
286
|
+
// target handler; ProseMirror skips default-prevented keys, so a handled
|
|
287
|
+
// Enter inserts no newline. Forwarded during composition as well, flagged
|
|
288
|
+
// `isComposing`; an inert surface forwards nothing.
|
|
289
|
+
function forwardKey(native: KeyboardEvent): void {
|
|
290
|
+
if (!onKeyDown || !core) return;
|
|
291
|
+
if (!isActive()) return;
|
|
292
|
+
if (!(native.target instanceof Node)) return;
|
|
293
|
+
if (!mountEl?.contains(native.target)) return;
|
|
294
|
+
const forwarded = toComposerKeyEvent(native);
|
|
295
|
+
const result = onKeyDown(forwarded);
|
|
296
|
+
if (result === true || forwarded.defaultPrevented) {
|
|
297
|
+
native.preventDefault();
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const stopAtBoundary = (event: Event): void => {
|
|
302
|
+
event.stopPropagation();
|
|
303
|
+
};
|
|
304
|
+
const stopTypes = ["click", "mousedown", "mouseup", "keydown", "keyup"];
|
|
305
|
+
|
|
306
|
+
onMount(() => {
|
|
307
|
+
const mountTarget = mountEl;
|
|
308
|
+
const host = root;
|
|
309
|
+
if (!mountTarget || !host) return;
|
|
310
|
+
const guardDisabledPointer = (event: Event): void => {
|
|
311
|
+
if (!disabled) return;
|
|
312
|
+
if (event.target instanceof Element && host.contains(event.target)) {
|
|
313
|
+
event.preventDefault();
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
const guardDisabledFocus = (event: Event): void => {
|
|
317
|
+
if (!disabled) return;
|
|
318
|
+
if (event.target instanceof HTMLElement && host.contains(event.target)) {
|
|
319
|
+
event.target.blur();
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
const mountText = value;
|
|
323
|
+
const mountDoc = mountDocumentForText(value);
|
|
324
|
+
lastSeenValue = value;
|
|
325
|
+
let cancelled = false;
|
|
326
|
+
const settle = (instance: CoreEditor): void => {
|
|
327
|
+
if (cancelled) {
|
|
328
|
+
instance.destroy();
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
core = instance;
|
|
332
|
+
host.addEventListener("keydown", forwardKey, true);
|
|
333
|
+
for (const type of stopTypes) {
|
|
334
|
+
host.addEventListener(type, stopAtBoundary);
|
|
335
|
+
}
|
|
336
|
+
host.addEventListener("mousedown", guardDisabledPointer);
|
|
337
|
+
host.addEventListener("focus", guardDisabledFocus, true);
|
|
338
|
+
// Reconcile prop updates that arrived while the full graph loaded
|
|
339
|
+
// (review 3 blocking 1): apply the latest host string and the current
|
|
340
|
+
// editability instead of leaving the mount snapshot stale.
|
|
341
|
+
instance.setEditable(editable);
|
|
342
|
+
instance.setDisabled(disabled);
|
|
343
|
+
const current = value;
|
|
344
|
+
if (current !== mountText) {
|
|
345
|
+
lastSeenValue = current;
|
|
346
|
+
untrack(() => {
|
|
347
|
+
const nextDoc = documentForText(current);
|
|
348
|
+
instance.applyExternalUpdate(nextDoc);
|
|
349
|
+
refreshTrailingId(nextDoc.blocks, instance.getDocument().blocks);
|
|
350
|
+
});
|
|
351
|
+
} else {
|
|
352
|
+
lastSeenValue = current;
|
|
353
|
+
refreshTrailingId(mountDoc.blocks, instance.getDocument().blocks);
|
|
354
|
+
}
|
|
355
|
+
syncChrome();
|
|
356
|
+
void tick().then(() => {
|
|
357
|
+
syncChrome();
|
|
358
|
+
});
|
|
359
|
+
};
|
|
360
|
+
// Single-prop opt-in (R-FULL-PROFILE-1): full construction loads the
|
|
361
|
+
// extension graph on demand and is asynchronous, P0 stays synchronous.
|
|
362
|
+
// The pending gap keeps `readiness()` not-ready while `core` is null;
|
|
363
|
+
// `captureComposer()` awaits the pending mount (rejecting only when
|
|
364
|
+
// unmounted or failed during mount).
|
|
365
|
+
const maybeCore = createRichTextEditor({
|
|
366
|
+
document: mountDoc,
|
|
367
|
+
profile,
|
|
368
|
+
messages: {
|
|
369
|
+
...messages,
|
|
370
|
+
placeholder: provided("placeholder") ?? formatUntranslatedMarker("placeholder"),
|
|
371
|
+
},
|
|
372
|
+
...(allocateId !== undefined ? { allocateId } : {}),
|
|
373
|
+
editable,
|
|
374
|
+
disabled,
|
|
375
|
+
element: mountTarget,
|
|
376
|
+
onChange: (event) => {
|
|
377
|
+
syncChrome();
|
|
378
|
+
// Host-owned string discipline: the emitted string is adopted for
|
|
379
|
+
// revision tracking (rule-1 echo, emits nothing), so the host's next
|
|
380
|
+
// distinct value — send-clear, edit cancel, external replacement —
|
|
381
|
+
// applies cleanly instead of raising a spurious session conflict.
|
|
382
|
+
// Capture never sets or clears this flag; only this adoption does.
|
|
383
|
+
// Full seeds: the gesture's affected identities lose their source
|
|
384
|
+
// slice (they serialize canonically from here on); untouched
|
|
385
|
+
// identities keep re-emitting their seed bytes.
|
|
386
|
+
const instance = core;
|
|
387
|
+
if (instance) {
|
|
388
|
+
instance.applyExternalUpdate(event.document);
|
|
389
|
+
}
|
|
390
|
+
if (profile === "full") {
|
|
391
|
+
for (const identity of event.gesture.affectedParagraphIds) {
|
|
392
|
+
fullTouched.add(identity);
|
|
393
|
+
fullSeeds.delete(identity);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
onChange?.(textFromDocument(event.document));
|
|
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
|
+
trailingId = null;
|
|
423
|
+
host.removeEventListener("keydown", forwardKey, true);
|
|
424
|
+
for (const type of stopTypes) {
|
|
425
|
+
host.removeEventListener(type, stopAtBoundary);
|
|
426
|
+
}
|
|
427
|
+
host.removeEventListener("mousedown", guardDisabledPointer);
|
|
428
|
+
host.removeEventListener("focus", guardDisabledFocus, true);
|
|
429
|
+
core?.destroy();
|
|
430
|
+
core = null;
|
|
431
|
+
};
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
// Controlled string (host-owned): an echo of the displayed text applies
|
|
435
|
+
// nothing; any distinct host value replaces the draft. A replacement
|
|
436
|
+
// arriving mid-composition is deferred by the core and re-evaluated once
|
|
437
|
+
// after the commit (IME-LOCK-1 clause 1). Never recreates the editor.
|
|
438
|
+
$effect(() => {
|
|
439
|
+
const snapshot = value;
|
|
440
|
+
const instance = core;
|
|
441
|
+
if (!instance) {
|
|
442
|
+
lastSeenValue = snapshot;
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
if (snapshot === lastSeenValue) {
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
lastSeenValue = snapshot;
|
|
449
|
+
untrack(() => {
|
|
450
|
+
if (textFromDocument(instance.getDocument()) === snapshot) {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
const nextDoc = documentForText(snapshot);
|
|
454
|
+
instance.applyExternalUpdate(nextDoc);
|
|
455
|
+
refreshTrailingId(nextDoc.blocks, instance.getDocument().blocks);
|
|
456
|
+
syncChrome();
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
$effect(() => {
|
|
461
|
+
core?.setEditable(editable);
|
|
462
|
+
core?.setDisabled(disabled);
|
|
463
|
+
if (
|
|
464
|
+
disabled &&
|
|
465
|
+
typeof globalThis.document !== "undefined" &&
|
|
466
|
+
root?.contains(globalThis.document.activeElement as Node | null)
|
|
467
|
+
) {
|
|
468
|
+
(globalThis.document.activeElement as HTMLElement).blur();
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
$effect(() => {
|
|
473
|
+
if (!core) return;
|
|
474
|
+
syncChrome();
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
const classes = (): string =>
|
|
478
|
+
["st-rich-text-editor", "st-composer-editor", className]
|
|
479
|
+
.filter((part) => part !== "")
|
|
480
|
+
.join(" ");
|
|
481
|
+
</script>
|
|
482
|
+
|
|
483
|
+
<div class={classes()} bind:this={root}>
|
|
484
|
+
<div class="st-rich-text-editor__surface" bind:this={mountEl}></div>
|
|
485
|
+
</div>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ComposerCaptureResult, ComposerEditorProps as ComposerContract, RichTextReadiness } from "@sentropic/design-system-rich-text";
|
|
2
|
+
/** Svelte props for the §6.2.1 string surface: the contract plus the
|
|
3
|
+
identity injection point and a class passthrough. The `profile` prop
|
|
4
|
+
selects the conversion path (R-FULL-PROFILE-1): `p0` (default) keeps
|
|
5
|
+
the chunk mapping; `full` parses through the full Markdown bridge. */
|
|
6
|
+
export interface ComposerEditorProps extends ComposerContract {
|
|
7
|
+
allocateId?: () => string;
|
|
8
|
+
class?: string;
|
|
9
|
+
}
|
|
10
|
+
declare const ComposerEditor: import("svelte").Component<ComposerEditorProps, {
|
|
11
|
+
captureComposer: () => Promise<ComposerCaptureResult>;
|
|
12
|
+
readiness: () => RichTextReadiness;
|
|
13
|
+
}, "">;
|
|
14
|
+
type ComposerEditor = ReturnType<typeof ComposerEditor>;
|
|
15
|
+
export default ComposerEditor;
|
|
16
|
+
//# sourceMappingURL=ComposerEditor.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComposerEditor.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/rich-text-editor/ComposerEditor.svelte.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACR,qBAAqB,EACrB,mBAAmB,IAAI,gBAAgB,EAIvC,iBAAiB,EAClB,MAAM,oCAAoC,CAAC;AAgB5C;;;yEAGyE;AACzE,MAAM,WAAW,mBAAoB,SAAQ,gBAAgB;IAC3D,UAAU,CAAC,EAAE,MAAM,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AA+cH,QAAA,MAAM,cAAc;2BA9PW,OAAO,CAAC,qBAAqB,CAAC;qBAwBpC,iBAAiB;MAsOkB,CAAC;AAC7D,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AACxD,eAAe,cAAc,CAAC"}
|