@quillmark/wasm 0.99.0 → 0.100.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +89 -104
- package/README.md +54 -5
- package/backends/pdfform/wasm.d.ts +60 -12
- package/backends/pdfform/wasm_bg.js +130 -20
- package/backends/pdfform/wasm_bg.wasm +0 -0
- package/backends/pdfform/wasm_bg.wasm.d.ts +3 -1
- package/backends/typst/wasm.d.ts +60 -12
- package/backends/typst/wasm_bg.js +130 -20
- package/backends/typst/wasm_bg.wasm +0 -0
- package/backends/typst/wasm_bg.wasm.d.ts +3 -1
- package/core/wasm.d.ts +60 -12
- package/core/wasm_bg.js +130 -20
- package/core/wasm_bg.wasm +0 -0
- package/core/wasm_bg.wasm.d.ts +3 -1
- package/package.json +1 -1
- package/runtime/runtime.d.ts +35 -9
- package/runtime/runtime.js +43 -14
package/core/wasm_bg.js
CHANGED
|
@@ -169,7 +169,48 @@ export class Document {
|
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
/**
|
|
172
|
-
*
|
|
172
|
+
* Interpreted **corpus** read at `addr`: the stable ABI under the runtime
|
|
173
|
+
* `reader.getContent` / `reader.card(i).getContent`. The corpus twin of
|
|
174
|
+
* [`reader.get`](Self::reader_get), which projects; this decodes the stored
|
|
175
|
+
* value through the codec the field's declared type names (`richtext` as
|
|
176
|
+
* markdown, `plaintext` as literal text) and returns the canonical `Content`.
|
|
177
|
+
*
|
|
178
|
+
* Total over the storage form: a committed field holds a content object and
|
|
179
|
+
* a parsed one holds the authored string, and both read back as a corpus
|
|
180
|
+
* here, so a consumer mounting a corpus editor stops branching on how the
|
|
181
|
+
* document was built.
|
|
182
|
+
*
|
|
183
|
+
* A bare string is `Addr` shorthand for `{ field }`; `{ card, field }`
|
|
184
|
+
* targets a composable card. Returns `undefined` for an **absent** field. An
|
|
185
|
+
* absent `addr.field` reads the **body** corpus, quill-free, mirroring
|
|
186
|
+
* [`getStored`](Self::get_stored). Throws `edit::unknown_field` for a name
|
|
187
|
+
* the schema does not declare, `edit::field_not_content` for a declared type
|
|
188
|
+
* that is not a content leaf (`array<richtext>` carries content and still has
|
|
189
|
+
* no one corpus), `edit::field_richtext_decode` for a stored value
|
|
190
|
+
* that decodes under neither encoding, and `edit::index_out_of_range` for a
|
|
191
|
+
* bad `addr.card`.
|
|
192
|
+
* @param {Quill} quill
|
|
193
|
+
* @param {Addr | string} addr
|
|
194
|
+
* @returns {Content | undefined}
|
|
195
|
+
*/
|
|
196
|
+
_readerGetContent(quill, addr) {
|
|
197
|
+
try {
|
|
198
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
199
|
+
_assertClass(quill, Quill);
|
|
200
|
+
wasm.document__readerGetContent(retptr, this.__wbg_ptr, quill.__wbg_ptr, addHeapObject(addr));
|
|
201
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
202
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
203
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
204
|
+
if (r2) {
|
|
205
|
+
throw takeObject(r1);
|
|
206
|
+
}
|
|
207
|
+
return takeObject(r0);
|
|
208
|
+
} finally {
|
|
209
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Revise the content field at `addr` from authored text, typed *and*
|
|
173
214
|
* anchor-preserving: the ABI under `writer.reviseField`. Resolves the
|
|
174
215
|
* field's schema from `quill` (main card, or the addressed card's `$kind`)
|
|
175
216
|
* and defers to [`TypedWriter::revise_field`](quillmark_core::TypedWriter::revise_field):
|
|
@@ -178,6 +219,9 @@ export class Document {
|
|
|
178
219
|
* multi-block result with `edit::field_richtext_not_inline`. Returns the
|
|
179
220
|
* text `Delta`.
|
|
180
221
|
*
|
|
222
|
+
* The codec is the declared type's: `richtext` diffs markdown, `plaintext`
|
|
223
|
+
* the literal text.
|
|
224
|
+
*
|
|
181
225
|
* `addr` must name a field (a bare string is `{ field }`); a body address
|
|
182
226
|
* throws (a body carries no field schema: use [`revise`](Self::revise)). A
|
|
183
227
|
* name the schema does not declare throws `edit::unknown_field`. Throws
|
|
@@ -185,14 +229,14 @@ export class Document {
|
|
|
185
229
|
* `writer.reviseField` in the runtime layer.
|
|
186
230
|
* @param {Quill} quill
|
|
187
231
|
* @param {Addr | string} addr
|
|
188
|
-
* @param {string}
|
|
232
|
+
* @param {string} text
|
|
189
233
|
* @returns {Delta}
|
|
190
234
|
*/
|
|
191
|
-
_reviseField(quill, addr,
|
|
235
|
+
_reviseField(quill, addr, text) {
|
|
192
236
|
try {
|
|
193
237
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
194
238
|
_assertClass(quill, Quill);
|
|
195
|
-
const ptr0 = passStringToWasm0(
|
|
239
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
196
240
|
const len0 = WASM_VECTOR_LEN;
|
|
197
241
|
wasm.document__reviseField(retptr, this.__wbg_ptr, quill.__wbg_ptr, addHeapObject(addr), ptr0, len0);
|
|
198
242
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
@@ -289,20 +333,6 @@ export class Document {
|
|
|
289
333
|
const ret = wasm.document_cardCount(this.__wbg_ptr);
|
|
290
334
|
return ret >>> 0;
|
|
291
335
|
}
|
|
292
|
-
/**
|
|
293
|
-
* The index of the composable card whose `$id` equals `id`, or
|
|
294
|
-
* `undefined` when none carries it. Resolves the durable card handle
|
|
295
|
-
* without a hand-rolled scan over [`cards`](Self::cards); `$id` is
|
|
296
|
-
* unique per document, so at most one card matches.
|
|
297
|
-
* @param {string} id
|
|
298
|
-
* @returns {number | undefined}
|
|
299
|
-
*/
|
|
300
|
-
cardIndexById(id) {
|
|
301
|
-
const ptr0 = passStringToWasm0(id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
302
|
-
const len0 = WASM_VECTOR_LEN;
|
|
303
|
-
const ret = wasm.document_cardIndexById(this.__wbg_ptr, ptr0, len0);
|
|
304
|
-
return takeObject(ret);
|
|
305
|
-
}
|
|
306
336
|
/**
|
|
307
337
|
* @returns {Card[]}
|
|
308
338
|
*/
|
|
@@ -536,8 +566,7 @@ export class Document {
|
|
|
536
566
|
}
|
|
537
567
|
/**
|
|
538
568
|
* Read the **verbatim stored value** at `addr`: the raw payload value of a
|
|
539
|
-
* field
|
|
540
|
-
* otherwise), or the **body content** when `addr.field` is absent. A bare
|
|
569
|
+
* field, or the **body content** when `addr.field` is absent. A bare
|
|
541
570
|
* string is `Addr` shorthand for `{ field }`. Reads are total over the field
|
|
542
571
|
* axis: an absent field is `undefined`; only an out-of-range `addr.card`
|
|
543
572
|
* throws `edit::index_out_of_range`. Needs no schema, so it lives on
|
|
@@ -545,6 +574,16 @@ export class Document {
|
|
|
545
574
|
* the interpreted schema-plane [`reader.get`](Self::reader_get). For the
|
|
546
575
|
* markdown projection use [`getMarkdown`](Self::get_markdown) (body) or
|
|
547
576
|
* `reader.get` (a field's declared type).
|
|
577
|
+
*
|
|
578
|
+
* **A content field at rest has one stored form per codec**: a `richtext`
|
|
579
|
+
* field holds the canonical content object, a `plaintext` field its literal
|
|
580
|
+
* string. A document that came through the bound door (`quill.parse` /
|
|
581
|
+
* `quill.conform`) is at rest, so this read no longer depends on which lane
|
|
582
|
+
* built it. A document that came through the transport door
|
|
583
|
+
* (`Document.fromMarkdown`, a legacy stored row) may rest as authored until
|
|
584
|
+
* it is conformed, and this read reports what is there. For the corpus
|
|
585
|
+
* either way, use the schema-plane `reader.getContent`, which decodes
|
|
586
|
+
* through the codec the field's declared type names.
|
|
548
587
|
* @param {Addr | string} addr
|
|
549
588
|
* @returns {unknown}
|
|
550
589
|
*/
|
|
@@ -1254,6 +1293,10 @@ export class Document {
|
|
|
1254
1293
|
return ret === 0 ? undefined : Document.__wrap(ret);
|
|
1255
1294
|
}
|
|
1256
1295
|
/**
|
|
1296
|
+
* The non-fatal diagnostics of the load that produced this document: parse
|
|
1297
|
+
* warnings, plus the `conform::*` warnings when it came through
|
|
1298
|
+
* `quill.parse`. Session state, not document value: `equals` and the
|
|
1299
|
+
* storage DTO exclude it, and `fromJson` / `loadJson` clear it.
|
|
1257
1300
|
* @returns {Diagnostic[]}
|
|
1258
1301
|
*/
|
|
1259
1302
|
get warnings() {
|
|
@@ -1333,6 +1376,40 @@ export class Quill {
|
|
|
1333
1376
|
wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
|
|
1334
1377
|
}
|
|
1335
1378
|
}
|
|
1379
|
+
/**
|
|
1380
|
+
* Land `doc`'s declared content fields at their canonical rest **in
|
|
1381
|
+
* place**, returning the `conform::*` diagnostics for the values that would
|
|
1382
|
+
* not commit (an empty array when everything rested).
|
|
1383
|
+
*
|
|
1384
|
+
* The read-repair verb: a document that arrived through the transport door
|
|
1385
|
+
* (`fromMarkdown`, `fromJson`, a stored row) converges here, and is then
|
|
1386
|
+
* eligible for rewrite under its current schema tag. Idempotent, and a
|
|
1387
|
+
* no-op on an already-canonical document: an equal value is not rewritten,
|
|
1388
|
+
* so YAML comments and stored bytes survive.
|
|
1389
|
+
*
|
|
1390
|
+
* A `!must_fill` marker anywhere in a field's value skips that field (the
|
|
1391
|
+
* marker is the state), and a value the strict write refuses stays as
|
|
1392
|
+
* authored with a diagnostic. Throws when `doc` declares a different
|
|
1393
|
+
* `$quill`, before any mutation.
|
|
1394
|
+
* @param {Document} doc
|
|
1395
|
+
* @returns {Diagnostic[]}
|
|
1396
|
+
*/
|
|
1397
|
+
conform(doc) {
|
|
1398
|
+
try {
|
|
1399
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1400
|
+
_assertClass(doc, Document);
|
|
1401
|
+
wasm.quill_conform(retptr, this.__wbg_ptr, doc.__wbg_ptr);
|
|
1402
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1403
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1404
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1405
|
+
if (r2) {
|
|
1406
|
+
throw takeObject(r1);
|
|
1407
|
+
}
|
|
1408
|
+
return takeObject(r0);
|
|
1409
|
+
} finally {
|
|
1410
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1336
1413
|
/**
|
|
1337
1414
|
* Build a quill from a file tree. Pure: no backend, no engine; the
|
|
1338
1415
|
* declared backend is resolved later, at render time.
|
|
@@ -1381,6 +1458,39 @@ export class Quill {
|
|
|
1381
1458
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1382
1459
|
}
|
|
1383
1460
|
}
|
|
1461
|
+
/**
|
|
1462
|
+
* Parse `markdown` and conform it against this quill: the **primary
|
|
1463
|
+
* ingestion path**, and the bound twin of the schema-free
|
|
1464
|
+
* `Document.fromMarkdown`. The returned document rests at its canonical
|
|
1465
|
+
* form (a `richtext` field as a content object, a `plaintext` field as its
|
|
1466
|
+
* literal string), so `getStored` no longer answers "corpus or string?"
|
|
1467
|
+
* with "depends how this document was built".
|
|
1468
|
+
*
|
|
1469
|
+
* Parse warnings and the `conform::*` diagnostics both land on
|
|
1470
|
+
* `doc.warnings`. Throws on a parse failure, or when `markdown` declares a
|
|
1471
|
+
* `$quill` this quill does not answer to: nothing conforms under the wrong
|
|
1472
|
+
* schema. To open a document whose `$quill` is stale, use the transport
|
|
1473
|
+
* door (`Document.fromMarkdown`, `setQuillRef`, then `quill.conform`).
|
|
1474
|
+
* @param {string} markdown
|
|
1475
|
+
* @returns {Document}
|
|
1476
|
+
*/
|
|
1477
|
+
parse(markdown) {
|
|
1478
|
+
try {
|
|
1479
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1480
|
+
const ptr0 = passStringToWasm0(markdown, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1481
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1482
|
+
wasm.quill_parse(retptr, this.__wbg_ptr, ptr0, len0);
|
|
1483
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1484
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1485
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1486
|
+
if (r2) {
|
|
1487
|
+
throw takeObject(r1);
|
|
1488
|
+
}
|
|
1489
|
+
return Document.__wrap(r0);
|
|
1490
|
+
} finally {
|
|
1491
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1384
1494
|
/**
|
|
1385
1495
|
* The resolved-value view of `doc` against this quill's schema: for every
|
|
1386
1496
|
* declared field the value the render projection would use and the
|
package/core/wasm_bg.wasm
CHANGED
|
Binary file
|
package/core/wasm_bg.wasm.d.ts
CHANGED
|
@@ -7,12 +7,12 @@ export const document__addCard: (a: number, b: number, c: number, d: number, e:
|
|
|
7
7
|
export const document__commitField: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
8
8
|
export const document__commitFields: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
9
9
|
export const document__readerGet: (a: number, b: number, c: number, d: number) => void;
|
|
10
|
+
export const document__readerGetContent: (a: number, b: number, c: number, d: number) => void;
|
|
10
11
|
export const document__reviseField: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
11
12
|
export const document_applyChange: (a: number, b: number, c: number, d: number) => void;
|
|
12
13
|
export const document_blueprintInstruction: (a: number, b: number, c: number) => void;
|
|
13
14
|
export const document_card: (a: number, b: number, c: number) => void;
|
|
14
15
|
export const document_cardCount: (a: number) => number;
|
|
15
|
-
export const document_cardIndexById: (a: number, b: number, c: number) => number;
|
|
16
16
|
export const document_cards: (a: number, b: number) => void;
|
|
17
17
|
export const document_clone: (a: number) => number;
|
|
18
18
|
export const document_currentSchemaVersion: (a: number) => void;
|
|
@@ -63,8 +63,10 @@ export const mapPos: (a: number, b: number, c: number, d: number) => void;
|
|
|
63
63
|
export const parseDocPath: (a: number, b: number, c: number) => void;
|
|
64
64
|
export const quill_backendId: (a: number, b: number) => void;
|
|
65
65
|
export const quill_blueprint: (a: number, b: number) => void;
|
|
66
|
+
export const quill_conform: (a: number, b: number, c: number) => void;
|
|
66
67
|
export const quill_fromTree: (a: number, b: number) => void;
|
|
67
68
|
export const quill_metadata: (a: number, b: number) => void;
|
|
69
|
+
export const quill_parse: (a: number, b: number, c: number, d: number) => void;
|
|
68
70
|
export const quill_resolve: (a: number, b: number, c: number) => void;
|
|
69
71
|
export const quill_schema: (a: number, b: number) => void;
|
|
70
72
|
export const quill_seedCard: (a: number, b: number, c: number, d: number, e: number) => void;
|
package/package.json
CHANGED
package/runtime/runtime.d.ts
CHANGED
|
@@ -674,12 +674,16 @@ export declare class DocumentWriter {
|
|
|
674
674
|
*/
|
|
675
675
|
setBody(markdown: string): void;
|
|
676
676
|
/**
|
|
677
|
-
* Revise the
|
|
677
|
+
* Revise the content main-card field `name` from authored text: typed *and*
|
|
678
678
|
* anchor-preserving. Surviving anchors rebase, then the diffed result is
|
|
679
679
|
* schema-conformed (`richtext(inline)` rejects a multi-block result). Throws
|
|
680
680
|
* `UnknownField` for a name the schema does not declare. Returns the `Delta`.
|
|
681
|
+
*
|
|
682
|
+
* The codec comes from the declared type: `richtext` diffs markdown, while
|
|
683
|
+
* `plaintext` diffs the literal text and never imports markdown, so a
|
|
684
|
+
* byte-identical revise of a value carrying escapes is a byte no-op.
|
|
681
685
|
*/
|
|
682
|
-
reviseField(name: string,
|
|
686
|
+
reviseField(name: string, text: string): Delta;
|
|
683
687
|
/**
|
|
684
688
|
* Build a composable card of `kind`, typed-commit `fields` onto it, set its
|
|
685
689
|
* body from optional markdown, and place it: the fused `makeCard` + typed
|
|
@@ -696,8 +700,8 @@ export declare class DocumentWriter {
|
|
|
696
700
|
* A {@link CardWriter} for the composable card at `index`. Index validity is
|
|
697
701
|
* checked lazily at commit time, so an out-of-range index does not throw here.
|
|
698
702
|
* The cursor is ephemeral: a `removeCard`/`addCard` between binding and writing
|
|
699
|
-
* silently retargets it;
|
|
700
|
-
*
|
|
703
|
+
* silently retargets it; re-resolve the index at write time when cards may
|
|
704
|
+
* move.
|
|
701
705
|
*/
|
|
702
706
|
card(index: number): CardWriter;
|
|
703
707
|
}
|
|
@@ -723,12 +727,12 @@ export declare class CardWriter {
|
|
|
723
727
|
/** Set this card's body from markdown (edit semantics), discarding the delta. */
|
|
724
728
|
setBody(markdown: string): void;
|
|
725
729
|
/**
|
|
726
|
-
* Revise the
|
|
727
|
-
* anchor-preserving; the card twin of {@link DocumentWriter.reviseField}
|
|
728
|
-
* Throws `UnknownField` for an undeclared name and
|
|
729
|
-
* bound index is out of range. Returns the `Delta`.
|
|
730
|
+
* Revise the content field `name` on this card from authored text: typed *and*
|
|
731
|
+
* anchor-preserving; the card twin of {@link DocumentWriter.reviseField},
|
|
732
|
+
* codec included. Throws `UnknownField` for an undeclared name and
|
|
733
|
+
* `IndexOutOfRange` if the bound index is out of range. Returns the `Delta`.
|
|
730
734
|
*/
|
|
731
|
-
reviseField(name: string,
|
|
735
|
+
reviseField(name: string, text: string): Delta;
|
|
732
736
|
}
|
|
733
737
|
|
|
734
738
|
/**
|
|
@@ -745,6 +749,12 @@ export declare class CardWriter {
|
|
|
745
749
|
* decode throws `FieldRichtextDecode`. A field's markdown lives here, not on the
|
|
746
750
|
* body-only `Document.getMarkdown`. The body read stays quill-free (a body's type
|
|
747
751
|
* is a format fact) and never throws.
|
|
752
|
+
*
|
|
753
|
+
* `getContent` is the same read at the other end of the codec, returning the
|
|
754
|
+
* corpus rather than the projection. It binds the quill for the same reason
|
|
755
|
+
* `get` does: a `richtext` string is markdown and a `plaintext` string is
|
|
756
|
+
* literal text, so the same stored bytes decode two ways and only the declared
|
|
757
|
+
* type says which.
|
|
748
758
|
*/
|
|
749
759
|
export declare class DocumentReader {
|
|
750
760
|
constructor(quill: Quill, doc: Document);
|
|
@@ -759,6 +769,17 @@ export declare class DocumentReader {
|
|
|
759
769
|
* `IndexOutOfRange` for a bad `addr.card`.
|
|
760
770
|
*/
|
|
761
771
|
get(addr: Addr | string): unknown;
|
|
772
|
+
/**
|
|
773
|
+
* Read the content field at `addr` as its canonical `Content` corpus: the
|
|
774
|
+
* corpus twin of {@link get}, which projects. Decodes through the codec the
|
|
775
|
+
* declared type names (`richtext` as markdown, `plaintext` as literal text),
|
|
776
|
+
* so a committed field and a parsed one read back the same corpus and the
|
|
777
|
+
* storage form stops being the caller's business. An absent `addr.field`
|
|
778
|
+
* reads the body corpus. `undefined` for an absent field; throws
|
|
779
|
+
* `UnknownField`, `FieldNotContent` for a declared type that is not a content
|
|
780
|
+
* leaf, `FieldRichtextDecode` for an undecodable value, and `IndexOutOfRange`.
|
|
781
|
+
*/
|
|
782
|
+
getContent(addr: Addr | string): Content | undefined;
|
|
762
783
|
/** The main body's markdown: the quill-free body read. Equals `get({})`. */
|
|
763
784
|
getBody(): string;
|
|
764
785
|
/**
|
|
@@ -791,6 +812,11 @@ export declare class CardReader {
|
|
|
791
812
|
* `IndexOutOfRange` for a bad index.
|
|
792
813
|
*/
|
|
793
814
|
get(name: string): unknown;
|
|
815
|
+
/**
|
|
816
|
+
* Read the content field `name` on this card as its canonical `Content`
|
|
817
|
+
* corpus: the card twin of {@link DocumentReader.getContent}.
|
|
818
|
+
*/
|
|
819
|
+
getContent(name: string): Content | undefined;
|
|
794
820
|
/** This card's body markdown: the card twin of {@link DocumentReader.getBody}. */
|
|
795
821
|
getBody(): string;
|
|
796
822
|
}
|
package/runtime/runtime.js
CHANGED
|
@@ -244,7 +244,7 @@ patchHandleChecked(Document.prototype, 'equals', (original) =>
|
|
|
244
244
|
return original.call(this, other);
|
|
245
245
|
}
|
|
246
246
|
);
|
|
247
|
-
for (const name of /** @type {const} */ (['validate', 'resolve'])) {
|
|
247
|
+
for (const name of /** @type {const} */ (['validate', 'resolve', 'conform'])) {
|
|
248
248
|
// Named once per patch, not per call: `validate` runs per keystroke.
|
|
249
249
|
const method = `Quill.${name}`;
|
|
250
250
|
patchHandleChecked(Quill.prototype, name, (original) =>
|
|
@@ -917,17 +917,21 @@ export class DocumentWriter {
|
|
|
917
917
|
this.#doc.revise({}, markdown);
|
|
918
918
|
}
|
|
919
919
|
/**
|
|
920
|
-
* Revise the
|
|
920
|
+
* Revise the content main-card field `name` from authored text: typed *and*
|
|
921
921
|
* anchor-preserving. Surviving anchors rebase, then the diffed result is
|
|
922
922
|
* schema-conformed (`richtext(inline)` rejects a multi-block result). Throws
|
|
923
923
|
* `UnknownField` for a name the schema does not declare. Returns the text
|
|
924
924
|
* {@link Delta}.
|
|
925
|
+
*
|
|
926
|
+
* The codec comes from the declared type: `richtext` diffs markdown, while
|
|
927
|
+
* `plaintext` diffs the literal text and never imports markdown, so a
|
|
928
|
+
* byte-identical revise of a value carrying escapes is a byte no-op.
|
|
925
929
|
* @param {string} name
|
|
926
|
-
* @param {string}
|
|
930
|
+
* @param {string} text
|
|
927
931
|
* @returns {import('../core/wasm.js').Delta}
|
|
928
932
|
*/
|
|
929
|
-
reviseField(name,
|
|
930
|
-
return this.#doc._reviseField(this.#quill, name,
|
|
933
|
+
reviseField(name, text) {
|
|
934
|
+
return this.#doc._reviseField(this.#quill, name, text);
|
|
931
935
|
}
|
|
932
936
|
/**
|
|
933
937
|
* Build a composable card of `kind`, typed-commit `fields` onto it, set its
|
|
@@ -964,8 +968,7 @@ export class DocumentWriter {
|
|
|
964
968
|
*
|
|
965
969
|
* The cursor is ephemeral: bind, write, discard. It holds `index`, not the
|
|
966
970
|
* card: a `removeCard`/`addCard` between binding and writing silently
|
|
967
|
-
* retargets it.
|
|
968
|
-
* at write time.
|
|
971
|
+
* retargets it. Re-resolve the index at write time when cards may move.
|
|
969
972
|
* @param {number} index
|
|
970
973
|
* @returns {CardWriter}
|
|
971
974
|
*/
|
|
@@ -1039,16 +1042,17 @@ export class CardWriter {
|
|
|
1039
1042
|
this.#doc.revise({ card: this.#index }, markdown);
|
|
1040
1043
|
}
|
|
1041
1044
|
/**
|
|
1042
|
-
* Revise the
|
|
1043
|
-
* anchor-preserving; the card twin of {@link DocumentWriter.reviseField}
|
|
1044
|
-
* Throws `UnknownField` for an undeclared name and
|
|
1045
|
-
* bound index is out of range. Returns the text
|
|
1045
|
+
* Revise the content field `name` on this card from authored text: typed *and*
|
|
1046
|
+
* anchor-preserving; the card twin of {@link DocumentWriter.reviseField},
|
|
1047
|
+
* codec included. Throws `UnknownField` for an undeclared name and
|
|
1048
|
+
* `IndexOutOfRange` if the bound index is out of range. Returns the text
|
|
1049
|
+
* {@link Delta}.
|
|
1046
1050
|
* @param {string} name
|
|
1047
|
-
* @param {string}
|
|
1051
|
+
* @param {string} text
|
|
1048
1052
|
* @returns {import('../core/wasm.js').Delta}
|
|
1049
1053
|
*/
|
|
1050
|
-
reviseField(name,
|
|
1051
|
-
return this.#doc._reviseField(this.#quill, { card: this.#index, field: name },
|
|
1054
|
+
reviseField(name, text) {
|
|
1055
|
+
return this.#doc._reviseField(this.#quill, { card: this.#index, field: name }, text);
|
|
1052
1056
|
}
|
|
1053
1057
|
}
|
|
1054
1058
|
|
|
@@ -1119,6 +1123,22 @@ export class DocumentReader {
|
|
|
1119
1123
|
get(addr) {
|
|
1120
1124
|
return this.#doc._readerGet(this.#quill, addr);
|
|
1121
1125
|
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Read the content field at `addr` as its canonical `Content` corpus: the
|
|
1128
|
+
* corpus twin of {@link get}, which projects. Decodes through the codec the
|
|
1129
|
+
* declared type names (`richtext` as markdown, `plaintext` as literal text),
|
|
1130
|
+
* so a field the writer committed as a corpus and one a markdown parse left
|
|
1131
|
+
* as an authored string read back the same; no branching on how the
|
|
1132
|
+
* document was built. An absent `addr.field` reads the body corpus.
|
|
1133
|
+
* `undefined` for an absent field; throws `UnknownField`, `FieldNotContent`
|
|
1134
|
+
* for a type that is not a content leaf, `FieldRichtextDecode` for an undecodable
|
|
1135
|
+
* value, and `IndexOutOfRange` for a bad `addr.card`.
|
|
1136
|
+
* @param {import('../core/wasm.js').Addr | string} addr
|
|
1137
|
+
* @returns {import('../core/wasm.js').Content | undefined}
|
|
1138
|
+
*/
|
|
1139
|
+
getContent(addr) {
|
|
1140
|
+
return this.#doc._readerGetContent(this.#quill, addr);
|
|
1141
|
+
}
|
|
1122
1142
|
/**
|
|
1123
1143
|
* The main body's markdown: the quill-free body read (a body's type is a
|
|
1124
1144
|
* format fact, not a schema fact). Equivalent to `get({})`.
|
|
@@ -1184,6 +1204,15 @@ export class CardReader {
|
|
|
1184
1204
|
get(name) {
|
|
1185
1205
|
return this.#doc._readerGet(this.#quill, { card: this.#index, field: name });
|
|
1186
1206
|
}
|
|
1207
|
+
/**
|
|
1208
|
+
* Read the content field `name` on this card as its canonical `Content`
|
|
1209
|
+
* corpus: the card twin of {@link DocumentReader.getContent}.
|
|
1210
|
+
* @param {string} name
|
|
1211
|
+
* @returns {import('../core/wasm.js').Content | undefined}
|
|
1212
|
+
*/
|
|
1213
|
+
getContent(name) {
|
|
1214
|
+
return this.#doc._readerGetContent(this.#quill, { card: this.#index, field: name });
|
|
1215
|
+
}
|
|
1187
1216
|
/**
|
|
1188
1217
|
* This card's body markdown: the card twin of {@link DocumentReader.getBody}.
|
|
1189
1218
|
* @returns {string}
|