@quillmark/svelte 0.4.2 → 0.4.3
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.
|
@@ -65,7 +65,8 @@
|
|
|
65
65
|
// rest per codec"), and the read that decodes a resting value to `Content` addresses
|
|
66
66
|
// a field, never an element (`getContent`; borb-sh/quillmark#1243), so a string is
|
|
67
67
|
// what the row is handed and a string is what it commits. The prose element stays
|
|
68
|
-
// the `richtext` arm
|
|
68
|
+
// the `richtext` arm: `Content` after a bound load or a commit, the authored
|
|
69
|
+
// string through the transport door, lowered in the row for the same reason.
|
|
69
70
|
//
|
|
70
71
|
// An array declaring no `items` has text elements.
|
|
71
72
|
const control = $derived(items && items.type !== 'plaintext' ? controlKind(items) : 'text');
|
|
@@ -197,10 +198,15 @@
|
|
|
197
198
|
}
|
|
198
199
|
/** Whether element `k` reads empty to the user. A text element's committed value
|
|
199
200
|
* lags the input: a cleared field commits at `change`, not per keystroke
|
|
200
|
-
* ({@link TextField}); so the input's own value is the truth
|
|
201
|
-
* commits every edit, so the committed `Content` is
|
|
201
|
+
* ({@link TextField}); so the input's own value is the truth. A prose element
|
|
202
|
+
* commits every edit, so the committed `Content` is; an authored string, the
|
|
203
|
+
* transport-door rest, is empty when it has no characters. */
|
|
202
204
|
function elementEmpty(k: number, target: EventTarget | null): boolean {
|
|
203
|
-
if (control === 'prose')
|
|
205
|
+
if (control === 'prose') {
|
|
206
|
+
const el = arr[k];
|
|
207
|
+
if (typeof el === 'string') return el.length === 0;
|
|
208
|
+
return !(el as Content | undefined)?.text;
|
|
209
|
+
}
|
|
204
210
|
return target instanceof HTMLInputElement && !target.value;
|
|
205
211
|
}
|
|
206
212
|
/**
|
|
@@ -258,7 +264,7 @@
|
|
|
258
264
|
{#if control === 'prose'}
|
|
259
265
|
<ProseArrayElement
|
|
260
266
|
bind:this={els[id]}
|
|
261
|
-
value={(arr[k] ?? emptyElement()) as Content}
|
|
267
|
+
value={(arr[k] ?? emptyElement()) as Content | string}
|
|
262
268
|
label={label != null ? `${label} ${k + 1}` : undefined}
|
|
263
269
|
onChange={(rt) => commitElement(k, rt)}
|
|
264
270
|
onKey={(e) => onElementKey(e, k)}
|
|
@@ -8,17 +8,25 @@
|
|
|
8
8
|
by value (`writer.set(field, arrayWithElementReplaced)`). Anchors within an
|
|
9
9
|
element are dropped on that value write: acceptable for inline refs. Mounts
|
|
10
10
|
once per stable element id (no reset on the parent's re-derive).
|
|
11
|
+
|
|
12
|
+
A transport-door document rests each element as the authored string. A scalar
|
|
13
|
+
leaf reads that through `getContent`; `getContent` names a field, never an
|
|
14
|
+
element, so this row calls the boundary's `importMarkdown` itself. That is
|
|
15
|
+
the richtext codec, which is this row's `items` type; `decode` is the PM
|
|
16
|
+
mapping and assumes `Content`. A string here is the missing element read,
|
|
17
|
+
not a codec failure.
|
|
11
18
|
-->
|
|
12
19
|
<script lang="ts">
|
|
13
20
|
import { onMount } from 'svelte';
|
|
14
21
|
import { EditorState } from 'prosemirror-state';
|
|
15
22
|
import { EditorView } from 'prosemirror-view';
|
|
16
23
|
import { decode, pmToContent, inlineSchema, proseLeafPlugins } from '../core/codec/index.js';
|
|
24
|
+
import { core } from '../core/lifecycle.js';
|
|
17
25
|
import './controls.css';
|
|
18
26
|
import type { Content } from '@quillmark/wasm';
|
|
19
27
|
|
|
20
28
|
interface Props {
|
|
21
|
-
value: Content;
|
|
29
|
+
value: Content | string;
|
|
22
30
|
/** Accessible name for the editable region (the array has no per-element label). */
|
|
23
31
|
label?: string;
|
|
24
32
|
onChange: (rt: Content) => void;
|
|
@@ -44,7 +52,8 @@
|
|
|
44
52
|
// plugin stack a `createField` leaf mounts (shared `proseLeafPlugins`), minus
|
|
45
53
|
// the anchor-position plugin (element anchors are dropped on the array's value
|
|
46
54
|
// write, per the header). Its own `dispatchTransaction` hands `Content` up.
|
|
47
|
-
const
|
|
55
|
+
const rt = typeof value === 'string' ? core().importMarkdown(value) : value;
|
|
56
|
+
const pmDoc = decode(rt, inlineSchema);
|
|
48
57
|
const state = EditorState.create({
|
|
49
58
|
doc: pmDoc,
|
|
50
59
|
plugins: proseLeafPlugins(inlineSchema, { inline: true })
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import './controls.css';
|
|
2
2
|
import type { Content } from '@quillmark/wasm';
|
|
3
3
|
interface Props {
|
|
4
|
-
value: Content;
|
|
4
|
+
value: Content | string;
|
|
5
5
|
/** Accessible name for the editable region (the array has no per-element label). */
|
|
6
6
|
label?: string;
|
|
7
7
|
onChange: (rt: Content) => void;
|