@bendyline/squisq-editor-react 2.13.16 → 2.13.18
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/THIRD_PARTY_LICENSES.txt +2411 -0
- package/dist/{chunk-LDU3AWER.js → chunk-6GHLTJNG.js} +2 -2
- package/dist/{chunk-4MBH7MMU.js → chunk-F6URHAW6.js} +1 -1
- package/dist/{chunk-UQUYPT5P.js → chunk-MMK26QF7.js} +126 -10
- package/dist/{chunk-ZLKINE4Y.js → chunk-SSEE55FT.js} +2 -7
- package/dist/{chunk-54MN2HG7.js → chunk-XUEYPMBH.js} +2307 -2081
- package/dist/document-parse-worker/index.js +84 -0
- package/dist/index.d.ts +15 -2
- package/dist/index.js +7 -5
- package/dist/json-editor/index.js +3 -3
- package/dist/review/index.js +2 -2
- package/dist/shell/index.js +4 -4
- package/dist/styles/index.css +115 -47
- package/package.json +8 -8
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
AlignedTableHeader,
|
|
4
4
|
MarkdownEscape,
|
|
5
5
|
PlainTextClipboard
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-F6URHAW6.js";
|
|
7
7
|
import {
|
|
8
8
|
markdownToTiptap,
|
|
9
9
|
tiptapToMarkdown
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-SSEE55FT.js";
|
|
11
11
|
|
|
12
12
|
// src/jsonEditor/JsonEditorContext.tsx
|
|
13
13
|
import { createContext, useContext, useEffect, useMemo } from "react";
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
markdownToTiptap,
|
|
7
7
|
tiptapToMarkdown
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-SSEE55FT.js";
|
|
9
9
|
|
|
10
10
|
// src/InsertMenuItems.tsx
|
|
11
11
|
import { createContext, useContext, useEffect, useMemo, useRef } from "react";
|
|
@@ -482,6 +482,96 @@ function useBlockNavigator(source, setSource, opts) {
|
|
|
482
482
|
};
|
|
483
483
|
}
|
|
484
484
|
|
|
485
|
+
// src/markdownParseProtocol.ts
|
|
486
|
+
import { parseMarkdown as parseMarkdown3 } from "@bendyline/squisq/markdown";
|
|
487
|
+
function isMarkdownParseResult(value) {
|
|
488
|
+
if (!value || typeof value !== "object") return false;
|
|
489
|
+
const result = value;
|
|
490
|
+
if (Object.keys(result).length !== 3 || !Number.isSafeInteger(result.id) || typeof result.id !== "number" || result.id < 1)
|
|
491
|
+
return false;
|
|
492
|
+
if (result.markdown === null) return typeof result.error === "string";
|
|
493
|
+
if (result.error !== null || !result.markdown || typeof result.markdown !== "object")
|
|
494
|
+
return false;
|
|
495
|
+
const markdown = result.markdown;
|
|
496
|
+
return markdown.type === "document" && Array.isArray(markdown.children);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// src/backgroundMarkdownParser.ts
|
|
500
|
+
var BackgroundMarkdownParser = class {
|
|
501
|
+
constructor(createWorker = () => new Worker(new URL("./document-parse-worker/index.js", import.meta.url), {
|
|
502
|
+
type: "module",
|
|
503
|
+
name: "squisq-markdown-parser"
|
|
504
|
+
})) {
|
|
505
|
+
this.createWorker = createWorker;
|
|
506
|
+
this.worker = null;
|
|
507
|
+
this.active = null;
|
|
508
|
+
this.pending = null;
|
|
509
|
+
this.serial = 0;
|
|
510
|
+
this.failed = false;
|
|
511
|
+
this.disposed = false;
|
|
512
|
+
}
|
|
513
|
+
parse(source, done) {
|
|
514
|
+
if (this.disposed) return;
|
|
515
|
+
this.pending = { id: ++this.serial, source, done };
|
|
516
|
+
this.drain();
|
|
517
|
+
}
|
|
518
|
+
cancel() {
|
|
519
|
+
this.serial++;
|
|
520
|
+
this.pending = null;
|
|
521
|
+
}
|
|
522
|
+
dispose() {
|
|
523
|
+
this.disposed = true;
|
|
524
|
+
this.cancel();
|
|
525
|
+
this.stopWorker();
|
|
526
|
+
}
|
|
527
|
+
stopWorker() {
|
|
528
|
+
clearTimeout(this.timeout);
|
|
529
|
+
this.worker?.terminate();
|
|
530
|
+
this.worker = null;
|
|
531
|
+
this.active = null;
|
|
532
|
+
}
|
|
533
|
+
fail() {
|
|
534
|
+
const latest = this.pending ?? this.active;
|
|
535
|
+
this.failed = true;
|
|
536
|
+
this.pending = null;
|
|
537
|
+
this.stopWorker();
|
|
538
|
+
if (!this.disposed && latest?.id === this.serial) latest.done(null);
|
|
539
|
+
}
|
|
540
|
+
drain() {
|
|
541
|
+
if (this.disposed || this.active || !this.pending) return;
|
|
542
|
+
const job = this.pending;
|
|
543
|
+
this.pending = null;
|
|
544
|
+
if (this.failed) {
|
|
545
|
+
job.done(null);
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
this.active = job;
|
|
549
|
+
try {
|
|
550
|
+
if (!this.worker) {
|
|
551
|
+
this.worker = this.createWorker();
|
|
552
|
+
this.worker.onmessage = ({ data }) => {
|
|
553
|
+
if (this.disposed || !this.active) return;
|
|
554
|
+
if (!isMarkdownParseResult(data) || data.id !== this.active.id) {
|
|
555
|
+
this.fail();
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
const completed = this.active;
|
|
559
|
+
clearTimeout(this.timeout);
|
|
560
|
+
this.active = null;
|
|
561
|
+
if (completed.id === this.serial) completed.done(data);
|
|
562
|
+
this.drain();
|
|
563
|
+
};
|
|
564
|
+
this.worker.onerror = () => this.fail();
|
|
565
|
+
this.worker.onmessageerror = () => this.fail();
|
|
566
|
+
}
|
|
567
|
+
this.timeout = setTimeout(() => this.fail(), 3e4);
|
|
568
|
+
this.worker.postMessage({ id: job.id, source: job.source });
|
|
569
|
+
} catch {
|
|
570
|
+
this.fail();
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
|
|
485
575
|
// src/EditorContext.tsx
|
|
486
576
|
import {
|
|
487
577
|
createContext as createContext3,
|
|
@@ -493,7 +583,7 @@ import {
|
|
|
493
583
|
useEffect as useEffect3
|
|
494
584
|
} from "react";
|
|
495
585
|
import {
|
|
496
|
-
parseMarkdown as
|
|
586
|
+
parseMarkdown as parseMarkdown4,
|
|
497
587
|
stringifyMarkdown,
|
|
498
588
|
resolveWikiLinks
|
|
499
589
|
} from "@bendyline/squisq/markdown";
|
|
@@ -1871,10 +1961,17 @@ function EditorProvider({
|
|
|
1871
1961
|
}, [initialColorScheme]);
|
|
1872
1962
|
const parseTimeoutRef = useRef3(null);
|
|
1873
1963
|
const skipInitialDebouncedParseRef = useRef3(Boolean(initialMarkdown));
|
|
1874
|
-
const
|
|
1964
|
+
const backgroundParserRef = useRef3(null);
|
|
1965
|
+
useEffect3(
|
|
1966
|
+
() => () => {
|
|
1967
|
+
backgroundParserRef.current?.dispose();
|
|
1968
|
+
backgroundParserRef.current = null;
|
|
1969
|
+
},
|
|
1970
|
+
[]
|
|
1971
|
+
);
|
|
1972
|
+
const doParse = useCallback3((source, background = false) => {
|
|
1875
1973
|
setIsParsing(true);
|
|
1876
|
-
|
|
1877
|
-
const parsed = parseMarkdown3(source);
|
|
1974
|
+
const applyParsed = (parsed) => {
|
|
1878
1975
|
setMarkdownDocState(parsed);
|
|
1879
1976
|
setParseError(null);
|
|
1880
1977
|
try {
|
|
@@ -1887,12 +1984,30 @@ function EditorProvider({
|
|
|
1887
1984
|
setDoc(null);
|
|
1888
1985
|
console.warn("Doc generation failed:", docErr instanceof Error ? docErr.message : docErr);
|
|
1889
1986
|
}
|
|
1890
|
-
|
|
1891
|
-
|
|
1987
|
+
setIsParsing(false);
|
|
1988
|
+
};
|
|
1989
|
+
const applyError = (error) => {
|
|
1990
|
+
setParseError(error);
|
|
1892
1991
|
setMarkdownDocState(null);
|
|
1893
1992
|
setDoc(null);
|
|
1894
|
-
} finally {
|
|
1895
1993
|
setIsParsing(false);
|
|
1994
|
+
};
|
|
1995
|
+
const synchronous = () => {
|
|
1996
|
+
try {
|
|
1997
|
+
applyParsed(parseMarkdown4(source));
|
|
1998
|
+
} catch (error) {
|
|
1999
|
+
applyError(error instanceof Error ? error.message : "Parse error");
|
|
2000
|
+
}
|
|
2001
|
+
};
|
|
2002
|
+
if (background && source.length >= 32768 && typeof Worker !== "undefined") {
|
|
2003
|
+
backgroundParserRef.current ?? (backgroundParserRef.current = new BackgroundMarkdownParser());
|
|
2004
|
+
backgroundParserRef.current.parse(source, (result) => {
|
|
2005
|
+
if (result === null) synchronous();
|
|
2006
|
+
else if (result.markdown) applyParsed(result.markdown);
|
|
2007
|
+
else applyError(result.error);
|
|
2008
|
+
});
|
|
2009
|
+
} else {
|
|
2010
|
+
synchronous();
|
|
1896
2011
|
}
|
|
1897
2012
|
}, []);
|
|
1898
2013
|
const [wikiProjection, setWikiProjection] = useState3(null);
|
|
@@ -1933,14 +2048,15 @@ function EditorProvider({
|
|
|
1933
2048
|
}
|
|
1934
2049
|
setIsParsing(true);
|
|
1935
2050
|
parseTimeoutRef.current = setTimeout(() => {
|
|
1936
|
-
doParse(markdownSource);
|
|
2051
|
+
doParse(markdownSource, true);
|
|
1937
2052
|
}, 150);
|
|
1938
2053
|
return () => {
|
|
1939
2054
|
if (parseTimeoutRef.current) {
|
|
1940
2055
|
clearTimeout(parseTimeoutRef.current);
|
|
1941
2056
|
}
|
|
2057
|
+
backgroundParserRef.current?.cancel();
|
|
1942
2058
|
};
|
|
1943
|
-
}, [markdownSource, doParse, editorMode]);
|
|
2059
|
+
}, [markdownSource, doParse, editorMode, articleId, fileName]);
|
|
1944
2060
|
useEffect3(() => {
|
|
1945
2061
|
if (editorMode !== "markdown") return;
|
|
1946
2062
|
if (initialMarkdown) {
|
|
@@ -704,14 +704,12 @@ function tiptapToMarkdown(html) {
|
|
|
704
704
|
const cellRegex = /<(th|td)([^>]*)>(.*?)<\/\1>/gs;
|
|
705
705
|
let cellExec;
|
|
706
706
|
while ((cellExec = cellRegex.exec(rowHtml)) !== null) {
|
|
707
|
-
const tag = cellExec[1];
|
|
708
707
|
const attrs = cellExec[2];
|
|
709
708
|
const content = htmlToTableCell(cellExec[3]);
|
|
710
709
|
const alignExec = attrs.match(/text-align:\s*(left|center|right)/);
|
|
711
710
|
cells.push({
|
|
712
711
|
content,
|
|
713
|
-
align: alignExec ? alignExec[1] : null
|
|
714
|
-
isHeader: tag === "th"
|
|
712
|
+
align: alignExec ? alignExec[1] : null
|
|
715
713
|
});
|
|
716
714
|
}
|
|
717
715
|
if (cells.length > 0) {
|
|
@@ -719,10 +717,7 @@ function tiptapToMarkdown(html) {
|
|
|
719
717
|
}
|
|
720
718
|
}
|
|
721
719
|
if (rows.length > 0) {
|
|
722
|
-
const
|
|
723
|
-
const hIdx = headerIdx >= 0 ? headerIdx : 0;
|
|
724
|
-
const headerRow = rows[hIdx];
|
|
725
|
-
const dataRows = rows.filter((_, i) => i !== hIdx);
|
|
720
|
+
const [headerRow, ...dataRows] = rows;
|
|
726
721
|
const aligns = headerRow.map((c) => c.align);
|
|
727
722
|
lines.push("| " + headerRow.map((c) => c.content || " ").join(" | ") + " |");
|
|
728
723
|
lines.push(
|