defuss-markdown 1.0.1 → 1.0.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.
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +64 -19
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ interface MarkdownAstNode {
|
|
|
11
11
|
children?: MarkdownAstNode[];
|
|
12
12
|
value?: string;
|
|
13
13
|
depth?: number;
|
|
14
|
-
ordered?: boolean;
|
|
14
|
+
ordered?: boolean | null;
|
|
15
15
|
start?: number;
|
|
16
16
|
spread?: boolean;
|
|
17
17
|
checked?: boolean | null;
|
|
@@ -30,8 +30,7 @@ interface MarkdownAstNode {
|
|
|
30
30
|
name?: string;
|
|
31
31
|
value?: string;
|
|
32
32
|
}>;
|
|
33
|
-
data?:
|
|
34
|
-
[key: string]: unknown;
|
|
33
|
+
data?: unknown;
|
|
35
34
|
}
|
|
36
35
|
interface ParserLike {
|
|
37
36
|
append?: (chunk: string) => unknown;
|
|
@@ -39,7 +38,6 @@ interface ParserLike {
|
|
|
39
38
|
render?: (content: string) => unknown;
|
|
40
39
|
reset?: () => void;
|
|
41
40
|
blocks?: MarkdownBlockLike[];
|
|
42
|
-
completedBlocks?: MarkdownBlockLike[];
|
|
43
41
|
pendingBlocks?: MarkdownBlockLike[];
|
|
44
42
|
pendingBlock?: MarkdownBlockLike | null;
|
|
45
43
|
getBlocks?: () => MarkdownBlockLike[];
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sources":["../../src/index.ts"],"mappings":";;KAEY,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;UAE1D,iBAAiB;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sources":["../../src/index.ts"],"mappings":";;KAEY,eAAe,GAAG,MAAM,GAAG,MAA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AC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,KAAK,UAAU,CAAC;IAC1E,cAAc,EAAE,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,SAAS,EAAE,OAAO,EAAE,aAAa,KAAK,UAAU,EAAE,CAAC;CAClG;iBAeqB,kBAAkB,CACvC,MAAM,EAAE,OAAO,GAAG,GAAG,EACrB,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,EAC/E,OAAO,GAAE,yBAA8B,GACrC,OAAO,CAAC,IAAI,CAAC,CAsBf;;;;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ const FALL_THROUGH = Symbol("defuss-markdown:fallback-renderer");
|
|
|
2
2
|
const DEFAULT_PARSER_OPTIONS = Object.freeze({
|
|
3
3
|
gfm: true,
|
|
4
4
|
math: true,
|
|
5
|
+
table: true,
|
|
5
6
|
htmlTree: true,
|
|
6
7
|
containers: true
|
|
7
8
|
});
|
|
@@ -32,21 +33,14 @@ async function getParser(options) {
|
|
|
32
33
|
if (options.createParser) {
|
|
33
34
|
return await options.createParser();
|
|
34
35
|
}
|
|
35
|
-
const incremark = await
|
|
36
|
+
const incremark = await import('@incremark/core');
|
|
36
37
|
const parserOptions = { ...DEFAULT_PARSER_OPTIONS, ...options.parserOptions ?? {} };
|
|
37
|
-
if (typeof incremark
|
|
38
|
+
if (typeof incremark.createIncremarkParser === "function") {
|
|
38
39
|
return incremark.createIncremarkParser(parserOptions);
|
|
39
40
|
}
|
|
40
|
-
if (typeof incremark
|
|
41
|
+
if (typeof incremark.IncremarkParser === "function") {
|
|
41
42
|
return new incremark.IncremarkParser(parserOptions);
|
|
42
43
|
}
|
|
43
|
-
if (typeof incremark?.default === "function") {
|
|
44
|
-
try {
|
|
45
|
-
return new incremark.default(parserOptions);
|
|
46
|
-
} catch {
|
|
47
|
-
return incremark.default(parserOptions);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
44
|
throw new Error(
|
|
51
45
|
"Could not construct an Incremark parser. Provide options.parser or options.createParser, or install @incremark/core with either createIncremarkParser() or IncremarkParser exported."
|
|
52
46
|
);
|
|
@@ -81,7 +75,7 @@ async function renderIntoElement(target, jsx, options) {
|
|
|
81
75
|
await options.render(jsx, target);
|
|
82
76
|
return;
|
|
83
77
|
}
|
|
84
|
-
const defuss = await
|
|
78
|
+
const defuss = await import('defuss');
|
|
85
79
|
const render = defuss?.render ?? defuss?.default?.render ?? defuss?.default ?? null;
|
|
86
80
|
if (typeof render !== "function") {
|
|
87
81
|
throw new Error(
|
|
@@ -242,13 +236,13 @@ function renderUnknownNode(node, context) {
|
|
|
242
236
|
function renderTable(node, context) {
|
|
243
237
|
const rows = Array.isArray(node.children) ? node.children : [];
|
|
244
238
|
if (rows.length === 0) {
|
|
245
|
-
return h("table", {});
|
|
239
|
+
return h("table", { class: "table" });
|
|
246
240
|
}
|
|
247
241
|
const [headerRow, ...bodyRows] = rows;
|
|
248
242
|
const alignments = Array.isArray(node.align) ? node.align : [];
|
|
249
243
|
return h(
|
|
250
244
|
"table",
|
|
251
|
-
{},
|
|
245
|
+
{ class: "table" },
|
|
252
246
|
h(
|
|
253
247
|
"thead",
|
|
254
248
|
{},
|
|
@@ -315,45 +309,99 @@ function createBlockState() {
|
|
|
315
309
|
};
|
|
316
310
|
}
|
|
317
311
|
function hydrateStateFromParserOrUpdate(parser, update, state) {
|
|
312
|
+
const updateKeys = update && typeof update === "object" ? Object.keys(update) : [];
|
|
313
|
+
console.log("[defuss-markdown] hydrateState: updateKeys =", updateKeys, "isIncremental =", isIncrementalUpdate(update));
|
|
314
|
+
if (isIncrementalUpdate(update)) {
|
|
315
|
+
const value = update;
|
|
316
|
+
const completed = pickBlockArray(value.completed);
|
|
317
|
+
const updated = pickBlockArray(value.updated);
|
|
318
|
+
const pending = pickBlockArray(value.pending);
|
|
319
|
+
const removed = pickBlockArray(value.removed);
|
|
320
|
+
console.log("[defuss-markdown] Incremark INCREMENTAL path:", {
|
|
321
|
+
completed: completed.map((b) => `${b.id}(${b.status})`),
|
|
322
|
+
updated: updated.map((b) => `${b.id}(${b.status})`),
|
|
323
|
+
pending: pending.map((b) => `${b.id}(${b.status})`),
|
|
324
|
+
removed: removed.map((b) => b.id)
|
|
325
|
+
});
|
|
326
|
+
applyIncrementalCollections(state, update);
|
|
327
|
+
const parserCompleted = pickBlockArray(parser.getCompletedBlocks?.());
|
|
328
|
+
if (parserCompleted.length > 0) {
|
|
329
|
+
for (const block of parserCompleted) {
|
|
330
|
+
upsertBlock(state, block);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
const parserPending = pickBlockArray(parser.pendingBlocks ?? parser.pendingBlock);
|
|
334
|
+
for (const block of parserPending) {
|
|
335
|
+
upsertBlock(state, block);
|
|
336
|
+
}
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
318
339
|
const directSnapshot = extractSnapshotBlocksFromUpdate(update);
|
|
319
340
|
if (directSnapshot) {
|
|
341
|
+
console.log("[defuss-markdown] DIRECT SNAPSHOT path, blocks =", directSnapshot.map((b) => b.id));
|
|
320
342
|
replaceState(state, directSnapshot);
|
|
321
343
|
return;
|
|
322
344
|
}
|
|
323
345
|
const parserSnapshot = extractBlocksFromParser(parser);
|
|
324
346
|
if (parserSnapshot) {
|
|
347
|
+
console.log("[defuss-markdown] PARSER SNAPSHOT path, blocks =", parserSnapshot.map((b) => b.id));
|
|
325
348
|
replaceState(state, parserSnapshot);
|
|
326
349
|
return;
|
|
327
350
|
}
|
|
351
|
+
console.log("[defuss-markdown] FALLBACK to applyIncrementalCollections");
|
|
328
352
|
applyIncrementalCollections(state, update);
|
|
329
353
|
}
|
|
354
|
+
function isIncrementalUpdate(update) {
|
|
355
|
+
if (!update || typeof update !== "object") {
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
const value = update;
|
|
359
|
+
return Array.isArray(value.completed) || Array.isArray(value.updated) || Array.isArray(value.pending);
|
|
360
|
+
}
|
|
330
361
|
function extractSnapshotBlocksFromUpdate(update) {
|
|
331
362
|
if (!update || typeof update !== "object") {
|
|
332
363
|
return null;
|
|
333
364
|
}
|
|
334
365
|
const value = update;
|
|
335
366
|
const direct = pickBlockArray(value.blocks);
|
|
336
|
-
|
|
367
|
+
const pending = pickBlockArray(value.pendingBlocks ?? value.pendingBlock);
|
|
368
|
+
if (direct.length > 0) {
|
|
369
|
+
if (pending.length > 0) {
|
|
370
|
+
return mergeCompletedAndPending(direct, pending);
|
|
371
|
+
}
|
|
372
|
+
return direct;
|
|
373
|
+
}
|
|
374
|
+
if (pending.length > 0) {
|
|
375
|
+
return pending;
|
|
376
|
+
}
|
|
377
|
+
return null;
|
|
337
378
|
}
|
|
338
379
|
function extractBlocksFromParser(parser) {
|
|
380
|
+
const pending = pickBlockArray(parser.pendingBlocks ?? parser.pendingBlock);
|
|
339
381
|
const methodBlocks = pickBlockArray(parser.getBlocks?.());
|
|
340
382
|
if (methodBlocks.length > 0) {
|
|
383
|
+
if (pending.length > 0) {
|
|
384
|
+
return mergeCompletedAndPending(methodBlocks, pending);
|
|
385
|
+
}
|
|
341
386
|
return methodBlocks;
|
|
342
387
|
}
|
|
343
388
|
const methodMerged = mergeCompletedAndPending(
|
|
344
389
|
pickBlockArray(parser.getCompletedBlocks?.()),
|
|
345
|
-
|
|
390
|
+
pending
|
|
346
391
|
);
|
|
347
392
|
if (methodMerged.length > 0) {
|
|
348
393
|
return methodMerged;
|
|
349
394
|
}
|
|
350
395
|
const propBlocks = pickBlockArray(parser.blocks);
|
|
351
396
|
if (propBlocks.length > 0) {
|
|
397
|
+
if (pending.length > 0) {
|
|
398
|
+
return mergeCompletedAndPending(propBlocks, pending);
|
|
399
|
+
}
|
|
352
400
|
return propBlocks;
|
|
353
401
|
}
|
|
354
402
|
const propMerged = mergeCompletedAndPending(
|
|
355
403
|
pickBlockArray(parser.completedBlocks),
|
|
356
|
-
|
|
404
|
+
pending
|
|
357
405
|
);
|
|
358
406
|
return propMerged.length > 0 ? propMerged : null;
|
|
359
407
|
}
|
|
@@ -472,8 +520,5 @@ async function* toAsyncIterable(input) {
|
|
|
472
520
|
yield result.value;
|
|
473
521
|
}
|
|
474
522
|
}
|
|
475
|
-
async function dynamicModuleImport(specifier) {
|
|
476
|
-
return Function("specifier", "return import(specifier)")(specifier);
|
|
477
|
-
}
|
|
478
523
|
|
|
479
524
|
export { FALL_THROUGH, updateWithMarkdown };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "defuss-markdown",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Incremental Markdown -> Defuss JSX bridge built on Incremark core.",
|
|
6
6
|
"keywords": [
|
|
@@ -56,4 +56,4 @@
|
|
|
56
56
|
"typescript": "^6.0.2",
|
|
57
57
|
"vitest": "^4.1.2"
|
|
58
58
|
}
|
|
59
|
-
}
|
|
59
|
+
}
|