@quillmark/wasm 0.99.0 → 0.101.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 +108 -104
- package/README.md +54 -5
- package/backends/pdfform/wasm.d.ts +99 -17
- package/backends/pdfform/wasm_bg.js +138 -23
- package/backends/pdfform/wasm_bg.wasm +0 -0
- package/backends/pdfform/wasm_bg.wasm.d.ts +3 -1
- package/backends/typst/wasm.d.ts +99 -17
- package/backends/typst/wasm_bg.js +138 -23
- package/backends/typst/wasm_bg.wasm +0 -0
- package/backends/typst/wasm_bg.wasm.d.ts +3 -1
- package/core/wasm.d.ts +99 -17
- package/core/wasm_bg.js +138 -23
- 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 +36 -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);
|
|
@@ -207,11 +251,16 @@ export class Document {
|
|
|
207
251
|
}
|
|
208
252
|
}
|
|
209
253
|
/**
|
|
210
|
-
* **Apply** a committed content edit `bundle`
|
|
211
|
-
*
|
|
212
|
-
*
|
|
254
|
+
* **Apply** a committed content edit `bundle`
|
|
255
|
+
* (`{ delta?, islandOps?, lineOps?, markOps? }`) at `addr`, the editor
|
|
256
|
+
* splice: text delta first, then island ops, then line ops, then mark ops
|
|
257
|
+
* (mark ranges in final-text coordinates), each all-or-nothing. An absent
|
|
213
258
|
* `addr.field` targets the body, an absent `addr.card` the main card.
|
|
214
259
|
*
|
|
260
|
+
* The island channel keeps a table or image edit on the op path: it moves
|
|
261
|
+
* the island alone, so the anchors elsewhere in the field survive an edit
|
|
262
|
+
* `install` would clear.
|
|
263
|
+
*
|
|
215
264
|
* Throws on an out-of-range card, a field that is not richtext, a malformed
|
|
216
265
|
* bundle, or an op that applies out of bounds (the value is unchanged on a
|
|
217
266
|
* failed apply).
|
|
@@ -289,20 +338,6 @@ export class Document {
|
|
|
289
338
|
const ret = wasm.document_cardCount(this.__wbg_ptr);
|
|
290
339
|
return ret >>> 0;
|
|
291
340
|
}
|
|
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
341
|
/**
|
|
307
342
|
* @returns {Card[]}
|
|
308
343
|
*/
|
|
@@ -536,8 +571,7 @@ export class Document {
|
|
|
536
571
|
}
|
|
537
572
|
/**
|
|
538
573
|
* 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
|
|
574
|
+
* field, or the **body content** when `addr.field` is absent. A bare
|
|
541
575
|
* string is `Addr` shorthand for `{ field }`. Reads are total over the field
|
|
542
576
|
* axis: an absent field is `undefined`; only an out-of-range `addr.card`
|
|
543
577
|
* throws `edit::index_out_of_range`. Needs no schema, so it lives on
|
|
@@ -545,6 +579,16 @@ export class Document {
|
|
|
545
579
|
* the interpreted schema-plane [`reader.get`](Self::reader_get). For the
|
|
546
580
|
* markdown projection use [`getMarkdown`](Self::get_markdown) (body) or
|
|
547
581
|
* `reader.get` (a field's declared type).
|
|
582
|
+
*
|
|
583
|
+
* **A content field at rest has one stored form per codec**: a `richtext`
|
|
584
|
+
* field holds the canonical content object, a `plaintext` field its literal
|
|
585
|
+
* string. A document that came through the bound door (`quill.parse` /
|
|
586
|
+
* `quill.conform`) is at rest, so this read no longer depends on which lane
|
|
587
|
+
* built it. A document that came through the transport door
|
|
588
|
+
* (`Document.fromMarkdown`, a legacy stored row) may rest as authored until
|
|
589
|
+
* it is conformed, and this read reports what is there. For the corpus
|
|
590
|
+
* either way, use the schema-plane `reader.getContent`, which decodes
|
|
591
|
+
* through the codec the field's declared type names.
|
|
548
592
|
* @param {Addr | string} addr
|
|
549
593
|
* @returns {unknown}
|
|
550
594
|
*/
|
|
@@ -1254,6 +1298,10 @@ export class Document {
|
|
|
1254
1298
|
return ret === 0 ? undefined : Document.__wrap(ret);
|
|
1255
1299
|
}
|
|
1256
1300
|
/**
|
|
1301
|
+
* The non-fatal diagnostics of the load that produced this document: parse
|
|
1302
|
+
* warnings, plus the `conform::*` warnings when it came through
|
|
1303
|
+
* `quill.parse`. Session state, not document value: `equals` and the
|
|
1304
|
+
* storage DTO exclude it, and `fromJson` / `loadJson` clear it.
|
|
1257
1305
|
* @returns {Diagnostic[]}
|
|
1258
1306
|
*/
|
|
1259
1307
|
get warnings() {
|
|
@@ -1333,6 +1381,40 @@ export class Quill {
|
|
|
1333
1381
|
wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
|
|
1334
1382
|
}
|
|
1335
1383
|
}
|
|
1384
|
+
/**
|
|
1385
|
+
* Land `doc`'s declared content fields at their canonical rest **in
|
|
1386
|
+
* place**, returning the `conform::*` diagnostics for the values that would
|
|
1387
|
+
* not commit (an empty array when everything rested).
|
|
1388
|
+
*
|
|
1389
|
+
* The read-repair verb: a document that arrived through the transport door
|
|
1390
|
+
* (`fromMarkdown`, `fromJson`, a stored row) converges here, and is then
|
|
1391
|
+
* eligible for rewrite under its current schema tag. Idempotent, and a
|
|
1392
|
+
* no-op on an already-canonical document: an equal value is not rewritten,
|
|
1393
|
+
* so YAML comments and stored bytes survive.
|
|
1394
|
+
*
|
|
1395
|
+
* A `!must_fill` marker anywhere in a field's value skips that field (the
|
|
1396
|
+
* marker is the state), and a value the strict write refuses stays as
|
|
1397
|
+
* authored with a diagnostic. Throws when `doc` declares a different
|
|
1398
|
+
* `$quill`, before any mutation.
|
|
1399
|
+
* @param {Document} doc
|
|
1400
|
+
* @returns {Diagnostic[]}
|
|
1401
|
+
*/
|
|
1402
|
+
conform(doc) {
|
|
1403
|
+
try {
|
|
1404
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1405
|
+
_assertClass(doc, Document);
|
|
1406
|
+
wasm.quill_conform(retptr, this.__wbg_ptr, doc.__wbg_ptr);
|
|
1407
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1408
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1409
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1410
|
+
if (r2) {
|
|
1411
|
+
throw takeObject(r1);
|
|
1412
|
+
}
|
|
1413
|
+
return takeObject(r0);
|
|
1414
|
+
} finally {
|
|
1415
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1336
1418
|
/**
|
|
1337
1419
|
* Build a quill from a file tree. Pure: no backend, no engine; the
|
|
1338
1420
|
* declared backend is resolved later, at render time.
|
|
@@ -1381,6 +1463,39 @@ export class Quill {
|
|
|
1381
1463
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1382
1464
|
}
|
|
1383
1465
|
}
|
|
1466
|
+
/**
|
|
1467
|
+
* Parse `markdown` and conform it against this quill: the **primary
|
|
1468
|
+
* ingestion path**, and the bound twin of the schema-free
|
|
1469
|
+
* `Document.fromMarkdown`. The returned document rests at its canonical
|
|
1470
|
+
* form (a `richtext` field as a content object, a `plaintext` field as its
|
|
1471
|
+
* literal string), so `getStored` no longer answers "corpus or string?"
|
|
1472
|
+
* with "depends how this document was built".
|
|
1473
|
+
*
|
|
1474
|
+
* Parse warnings and the `conform::*` diagnostics both land on
|
|
1475
|
+
* `doc.warnings`. Throws on a parse failure, or when `markdown` declares a
|
|
1476
|
+
* `$quill` this quill does not answer to: nothing conforms under the wrong
|
|
1477
|
+
* schema. To open a document whose `$quill` is stale, use the transport
|
|
1478
|
+
* door (`Document.fromMarkdown`, `setQuillRef`, then `quill.conform`).
|
|
1479
|
+
* @param {string} markdown
|
|
1480
|
+
* @returns {Document}
|
|
1481
|
+
*/
|
|
1482
|
+
parse(markdown) {
|
|
1483
|
+
try {
|
|
1484
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1485
|
+
const ptr0 = passStringToWasm0(markdown, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1486
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1487
|
+
wasm.quill_parse(retptr, this.__wbg_ptr, ptr0, len0);
|
|
1488
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1489
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1490
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1491
|
+
if (r2) {
|
|
1492
|
+
throw takeObject(r1);
|
|
1493
|
+
}
|
|
1494
|
+
return Document.__wrap(r0);
|
|
1495
|
+
} finally {
|
|
1496
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1384
1499
|
/**
|
|
1385
1500
|
* The resolved-value view of `doc` against this quill's schema: for every
|
|
1386
1501
|
* 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
|
@@ -84,6 +84,7 @@ export type {
|
|
|
84
84
|
CardAddr,
|
|
85
85
|
Delta,
|
|
86
86
|
Assoc,
|
|
87
|
+
IslandOp,
|
|
87
88
|
LineOp,
|
|
88
89
|
MarkOp,
|
|
89
90
|
ChangeBundle,
|
|
@@ -674,12 +675,16 @@ export declare class DocumentWriter {
|
|
|
674
675
|
*/
|
|
675
676
|
setBody(markdown: string): void;
|
|
676
677
|
/**
|
|
677
|
-
* Revise the
|
|
678
|
+
* Revise the content main-card field `name` from authored text: typed *and*
|
|
678
679
|
* anchor-preserving. Surviving anchors rebase, then the diffed result is
|
|
679
680
|
* schema-conformed (`richtext(inline)` rejects a multi-block result). Throws
|
|
680
681
|
* `UnknownField` for a name the schema does not declare. Returns the `Delta`.
|
|
682
|
+
*
|
|
683
|
+
* The codec comes from the declared type: `richtext` diffs markdown, while
|
|
684
|
+
* `plaintext` diffs the literal text and never imports markdown, so a
|
|
685
|
+
* byte-identical revise of a value carrying escapes is a byte no-op.
|
|
681
686
|
*/
|
|
682
|
-
reviseField(name: string,
|
|
687
|
+
reviseField(name: string, text: string): Delta;
|
|
683
688
|
/**
|
|
684
689
|
* Build a composable card of `kind`, typed-commit `fields` onto it, set its
|
|
685
690
|
* body from optional markdown, and place it: the fused `makeCard` + typed
|
|
@@ -696,8 +701,8 @@ export declare class DocumentWriter {
|
|
|
696
701
|
* A {@link CardWriter} for the composable card at `index`. Index validity is
|
|
697
702
|
* checked lazily at commit time, so an out-of-range index does not throw here.
|
|
698
703
|
* The cursor is ephemeral: a `removeCard`/`addCard` between binding and writing
|
|
699
|
-
* silently retargets it;
|
|
700
|
-
*
|
|
704
|
+
* silently retargets it; re-resolve the index at write time when cards may
|
|
705
|
+
* move.
|
|
701
706
|
*/
|
|
702
707
|
card(index: number): CardWriter;
|
|
703
708
|
}
|
|
@@ -723,12 +728,12 @@ export declare class CardWriter {
|
|
|
723
728
|
/** Set this card's body from markdown (edit semantics), discarding the delta. */
|
|
724
729
|
setBody(markdown: string): void;
|
|
725
730
|
/**
|
|
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`.
|
|
731
|
+
* Revise the content field `name` on this card from authored text: typed *and*
|
|
732
|
+
* anchor-preserving; the card twin of {@link DocumentWriter.reviseField},
|
|
733
|
+
* codec included. Throws `UnknownField` for an undeclared name and
|
|
734
|
+
* `IndexOutOfRange` if the bound index is out of range. Returns the `Delta`.
|
|
730
735
|
*/
|
|
731
|
-
reviseField(name: string,
|
|
736
|
+
reviseField(name: string, text: string): Delta;
|
|
732
737
|
}
|
|
733
738
|
|
|
734
739
|
/**
|
|
@@ -745,6 +750,12 @@ export declare class CardWriter {
|
|
|
745
750
|
* decode throws `FieldRichtextDecode`. A field's markdown lives here, not on the
|
|
746
751
|
* body-only `Document.getMarkdown`. The body read stays quill-free (a body's type
|
|
747
752
|
* is a format fact) and never throws.
|
|
753
|
+
*
|
|
754
|
+
* `getContent` is the same read at the other end of the codec, returning the
|
|
755
|
+
* corpus rather than the projection. It binds the quill for the same reason
|
|
756
|
+
* `get` does: a `richtext` string is markdown and a `plaintext` string is
|
|
757
|
+
* literal text, so the same stored bytes decode two ways and only the declared
|
|
758
|
+
* type says which.
|
|
748
759
|
*/
|
|
749
760
|
export declare class DocumentReader {
|
|
750
761
|
constructor(quill: Quill, doc: Document);
|
|
@@ -759,6 +770,17 @@ export declare class DocumentReader {
|
|
|
759
770
|
* `IndexOutOfRange` for a bad `addr.card`.
|
|
760
771
|
*/
|
|
761
772
|
get(addr: Addr | string): unknown;
|
|
773
|
+
/**
|
|
774
|
+
* Read the content field at `addr` as its canonical `Content` corpus: the
|
|
775
|
+
* corpus twin of {@link get}, which projects. Decodes through the codec the
|
|
776
|
+
* declared type names (`richtext` as markdown, `plaintext` as literal text),
|
|
777
|
+
* so a committed field and a parsed one read back the same corpus and the
|
|
778
|
+
* storage form stops being the caller's business. An absent `addr.field`
|
|
779
|
+
* reads the body corpus. `undefined` for an absent field; throws
|
|
780
|
+
* `UnknownField`, `FieldNotContent` for a declared type that is not a content
|
|
781
|
+
* leaf, `FieldRichtextDecode` for an undecodable value, and `IndexOutOfRange`.
|
|
782
|
+
*/
|
|
783
|
+
getContent(addr: Addr | string): Content | undefined;
|
|
762
784
|
/** The main body's markdown: the quill-free body read. Equals `get({})`. */
|
|
763
785
|
getBody(): string;
|
|
764
786
|
/**
|
|
@@ -791,6 +813,11 @@ export declare class CardReader {
|
|
|
791
813
|
* `IndexOutOfRange` for a bad index.
|
|
792
814
|
*/
|
|
793
815
|
get(name: string): unknown;
|
|
816
|
+
/**
|
|
817
|
+
* Read the content field `name` on this card as its canonical `Content`
|
|
818
|
+
* corpus: the card twin of {@link DocumentReader.getContent}.
|
|
819
|
+
*/
|
|
820
|
+
getContent(name: string): Content | undefined;
|
|
794
821
|
/** This card's body markdown: the card twin of {@link DocumentReader.getBody}. */
|
|
795
822
|
getBody(): string;
|
|
796
823
|
}
|
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}
|