foldkit-richtext 0.5.3 → 0.7.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/dist/clipboard.d.ts +224 -0
- package/dist/clipboard.d.ts.map +1 -0
- package/dist/clipboard.js +208 -0
- package/dist/clipboard.js.map +1 -0
- package/dist/code.d.ts +27 -0
- package/dist/code.d.ts.map +1 -0
- package/dist/code.js +45 -0
- package/dist/code.js.map +1 -0
- package/dist/command.d.ts +300 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +1438 -0
- package/dist/command.js.map +1 -0
- package/dist/decoration.d.ts +44 -0
- package/dist/decoration.d.ts.map +1 -0
- package/dist/decoration.js +96 -0
- package/dist/decoration.js.map +1 -0
- package/dist/document.d.ts +1045 -0
- package/dist/document.d.ts.map +1 -0
- package/dist/document.js +544 -0
- package/dist/document.js.map +1 -0
- package/dist/footnote.d.ts +35 -0
- package/dist/footnote.d.ts.map +1 -0
- package/dist/footnote.js +100 -0
- package/dist/footnote.js.map +1 -0
- package/dist/history.d.ts +470 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +81 -0
- package/dist/history.js.map +1 -0
- package/dist/html.d.ts +27 -0
- package/dist/html.d.ts.map +1 -0
- package/dist/html.js +99 -0
- package/dist/html.js.map +1 -0
- package/dist/indent.d.ts +16 -0
- package/dist/indent.d.ts.map +1 -0
- package/dist/indent.js +101 -0
- package/dist/indent.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +24 -0
- package/dist/input.d.ts +54 -0
- package/dist/input.d.ts.map +1 -0
- package/dist/input.js +37 -0
- package/dist/input.js.map +1 -0
- package/dist/kit.d.ts +179 -0
- package/dist/kit.d.ts.map +1 -0
- package/dist/kit.js +202 -0
- package/dist/kit.js.map +1 -0
- package/dist/marks.d.ts +79 -0
- package/dist/marks.d.ts.map +1 -0
- package/dist/marks.js +127 -0
- package/dist/marks.js.map +1 -0
- package/dist/media.d.ts +30 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +148 -0
- package/dist/media.js.map +1 -0
- package/dist/migration.d.ts +55 -0
- package/dist/migration.d.ts.map +1 -0
- package/dist/migration.js +124 -0
- package/dist/migration.js.map +1 -0
- package/dist/outline.d.ts +15 -0
- package/dist/outline.d.ts.map +1 -0
- package/dist/outline.js +39 -0
- package/dist/outline.js.map +1 -0
- package/dist/rendering.d.ts +96 -0
- package/dist/rendering.d.ts.map +1 -0
- package/dist/rendering.js +106 -0
- package/dist/rendering.js.map +1 -0
- package/dist/replicated.d.ts +340 -0
- package/dist/replicated.d.ts.map +1 -0
- package/dist/replicated.js +1727 -0
- package/dist/replicated.js.map +1 -0
- package/dist/search.d.ts +28 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +61 -0
- package/dist/search.js.map +1 -0
- package/dist/standard.d.ts +61 -0
- package/dist/standard.d.ts.map +1 -0
- package/dist/standard.js +231 -0
- package/dist/standard.js.map +1 -0
- package/dist/table.d.ts +38 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.js +160 -0
- package/dist/table.js.map +1 -0
- package/dist/transaction.d.ts +712 -0
- package/dist/transaction.d.ts.map +1 -0
- package/dist/transaction.js +993 -0
- package/dist/transaction.js.map +1 -0
- package/dist/transform.d.ts +48 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/transform.js +94 -0
- package/dist/transform.js.map +1 -0
- package/dist/url.d.ts +16 -0
- package/dist/url.d.ts.map +1 -0
- package/dist/url.js +32 -0
- package/dist/url.js.map +1 -0
- package/package.json +7 -7
- package/dist/index.d.mts +0 -3787
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -6688
- package/dist/index.mjs.map +0 -1
- package/dist/rolldown-runtime-D8jQpDG7.mjs +0 -12
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { Document, NodeId, Selection, Text } from "./document.js";
|
|
3
|
+
/** Where a footnote is referred to: the run showing its label carries this mark. */
|
|
4
|
+
export declare const FootnoteRef: import("./marks.js").MarkDef<Schema.Struct<{
|
|
5
|
+
readonly label: Schema.String;
|
|
6
|
+
}>>;
|
|
7
|
+
/** A footnote's note, under the label its references carry. */
|
|
8
|
+
export declare const FootnoteDefinition: import("./kit.js").NodeDefinitionOf<"FootnoteDefinition", Schema.Struct<{
|
|
9
|
+
readonly label: Schema.String;
|
|
10
|
+
}>, "blocks">;
|
|
11
|
+
/** One footnote: its label, its definition if there is one, and the runs that refer to it. */
|
|
12
|
+
export interface Footnote {
|
|
13
|
+
readonly label: string;
|
|
14
|
+
readonly definition: NodeId | undefined;
|
|
15
|
+
/** The runs carrying its reference, in document order. */
|
|
16
|
+
readonly references: ReadonlyArray<NodeId>;
|
|
17
|
+
/** The definition's text, one line per block. */
|
|
18
|
+
readonly text: string;
|
|
19
|
+
}
|
|
20
|
+
/** The label of the footnote a run refers to, if it carries a reference. */
|
|
21
|
+
export declare const referenceLabel: (run: Text) => string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Every footnote, in the order its first reference appears; a definition nothing refers to comes
|
|
24
|
+
* after them, in document order.
|
|
25
|
+
*/
|
|
26
|
+
export declare const footnotesOf: (document: Document) => ReadonlyArray<Footnote>;
|
|
27
|
+
/**
|
|
28
|
+
* The label of the footnote whose reference the selection starts in or right beside. A reference
|
|
29
|
+
* is a character or two, and its mark does not extend, so a click on one usually leaves the caret
|
|
30
|
+
* at its edge, in the run next to it; that caret counts as at the reference.
|
|
31
|
+
*/
|
|
32
|
+
export declare const footnoteAt: (document: Document, selection: Selection | null) => string | undefined;
|
|
33
|
+
/** The smallest whole number no footnote uses as its label, as text: the next note's label. */
|
|
34
|
+
export declare const nextFootnoteLabel: (document: Document) => string;
|
|
35
|
+
//# sourceMappingURL=footnote.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"footnote.d.ts","names":[],"sources":["../src/footnote.ts"],"mappings":";;;qBAyBa,kCAAW,QAAA,OAAA;;;;qBAGX,uCAAkB,uCAAA,OAAA;;;;iBAMd;WACN;WACA,YAAY;;WAEZ,YAAY,cAAc;;WAE1B;;;qBASE,iBAAc,KAAS;;;;;qBAiBvB,cAAW,UAAc,aAAW,cAAc;;;;;;qBAgClD,aAAU,UAAc,UAAQ,WAAa;;qBAkB7C,oBAAiB,UAAc"}
|
package/dist/footnote.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { blockContent, eachBlock, markName, rangeStart } from "./document.js";
|
|
3
|
+
import { mark, markProps } from "./marks.js";
|
|
4
|
+
import { node } from "./kit.js";
|
|
5
|
+
// src/footnote.ts
|
|
6
|
+
/**
|
|
7
|
+
* Footnotes: a reference in the text and a definition at the end of the document, tied by a
|
|
8
|
+
* label. The reference is a mark on the run that shows the label, so it moves, splits and undoes
|
|
9
|
+
* with the text; the definition is a block holding blocks, so its note is ordinary editable text.
|
|
10
|
+
* Nothing else ties them: a definition no reference names, or a reference with no definition, is
|
|
11
|
+
* what `footnotesOf` reports, not an invalid document.
|
|
12
|
+
*/
|
|
13
|
+
const Label = Schema.Struct({ label: Schema.String });
|
|
14
|
+
/** Where a footnote is referred to: the run showing its label carries this mark. */
|
|
15
|
+
const FootnoteRef = mark("FootnoteRef", {
|
|
16
|
+
Props: Label,
|
|
17
|
+
expand: "none"
|
|
18
|
+
});
|
|
19
|
+
/** A footnote's note, under the label its references carry. */
|
|
20
|
+
const FootnoteDefinition = node("FootnoteDefinition", {
|
|
21
|
+
Props: Label,
|
|
22
|
+
children: blockContent
|
|
23
|
+
});
|
|
24
|
+
const labelOf = (props) => {
|
|
25
|
+
if (typeof props !== "object" || props === null || !("label" in props)) return void 0;
|
|
26
|
+
return typeof props.label === "string" ? props.label : void 0;
|
|
27
|
+
};
|
|
28
|
+
/** The label of the footnote a run refers to, if it carries a reference. */
|
|
29
|
+
const referenceLabel = (run) => {
|
|
30
|
+
const reference = run.marks.find((each) => markName(each) === FootnoteRef.name);
|
|
31
|
+
return reference === void 0 ? void 0 : labelOf(markProps(reference));
|
|
32
|
+
};
|
|
33
|
+
const textOf = (blocks) => {
|
|
34
|
+
const lines = [];
|
|
35
|
+
eachBlock(blocks, (block) => {
|
|
36
|
+
if (block.children.length > 0) lines.push(block.children.map((run) => run.text).join(""));
|
|
37
|
+
});
|
|
38
|
+
return lines.join("\n");
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Every footnote, in the order its first reference appears; a definition nothing refers to comes
|
|
42
|
+
* after them, in document order.
|
|
43
|
+
*/
|
|
44
|
+
const footnotesOf = (document) => {
|
|
45
|
+
const references = /* @__PURE__ */ new Map();
|
|
46
|
+
const definitions = /* @__PURE__ */ new Map();
|
|
47
|
+
eachBlock(document.children, (block) => {
|
|
48
|
+
if (block.type === "Node" && block.kind === FootnoteDefinition.name) {
|
|
49
|
+
const label = labelOf(block.props);
|
|
50
|
+
if (label !== void 0 && !definitions.has(label)) definitions.set(label, {
|
|
51
|
+
node: block.id,
|
|
52
|
+
text: textOf(block.blocks ?? [])
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
for (const run of block.children) {
|
|
56
|
+
const label = referenceLabel(run);
|
|
57
|
+
if (label === void 0) continue;
|
|
58
|
+
const held = references.get(label);
|
|
59
|
+
if (held === void 0) references.set(label, [run.id]);
|
|
60
|
+
else held.push(run.id);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return [...references.keys(), ...[...definitions.keys()].filter((l) => !references.has(l))].map((label) => ({
|
|
64
|
+
label,
|
|
65
|
+
definition: definitions.get(label)?.node,
|
|
66
|
+
references: references.get(label) ?? [],
|
|
67
|
+
text: definitions.get(label)?.text ?? ""
|
|
68
|
+
}));
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* The label of the footnote whose reference the selection starts in or right beside. A reference
|
|
72
|
+
* is a character or two, and its mark does not extend, so a click on one usually leaves the caret
|
|
73
|
+
* at its edge, in the run next to it; that caret counts as at the reference.
|
|
74
|
+
*/
|
|
75
|
+
const footnoteAt = (document, selection) => {
|
|
76
|
+
if (selection?.type !== "Range") return void 0;
|
|
77
|
+
const start = rangeStart(document, selection);
|
|
78
|
+
if (start === void 0) return void 0;
|
|
79
|
+
let found;
|
|
80
|
+
eachBlock(document.children, (block) => {
|
|
81
|
+
const index = block.children.findIndex((each) => each.id === start.node);
|
|
82
|
+
if (index < 0) return;
|
|
83
|
+
const run = block.children[index];
|
|
84
|
+
let beside;
|
|
85
|
+
if (start.offset === 0) beside = block.children[index - 1];
|
|
86
|
+
else if (start.offset === run.text.length) beside = block.children[index + 1];
|
|
87
|
+
found = referenceLabel(run) ?? (beside === void 0 ? void 0 : referenceLabel(beside));
|
|
88
|
+
});
|
|
89
|
+
return found;
|
|
90
|
+
};
|
|
91
|
+
/** The smallest whole number no footnote uses as its label, as text: the next note's label. */
|
|
92
|
+
const nextFootnoteLabel = (document) => {
|
|
93
|
+
const used = new Set(footnotesOf(document).map((each) => each.label));
|
|
94
|
+
let n = 1;
|
|
95
|
+
while (used.has(String(n))) n++;
|
|
96
|
+
return String(n);
|
|
97
|
+
};
|
|
98
|
+
export { FootnoteDefinition, FootnoteRef, footnoteAt, footnotesOf, nextFootnoteLabel, referenceLabel };
|
|
99
|
+
|
|
100
|
+
//# sourceMappingURL=footnote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"footnote.js","names":[],"sources":["../src/footnote.ts"],"sourcesContent":["/**\n * Footnotes: a reference in the text and a definition at the end of the document, tied by a\n * label. The reference is a mark on the run that shows the label, so it moves, splits and undoes\n * with the text; the definition is a block holding blocks, so its note is ordinary editable text.\n * Nothing else ties them: a definition no reference names, or a reference with no definition, is\n * what `footnotesOf` reports, not an invalid document.\n */\nimport { Schema } from 'effect'\nimport {\n blockContent,\n eachBlock,\n markName,\n rangeStart,\n type Block,\n type Document,\n type NodeId,\n type Selection,\n type Text,\n} from './document.js'\nimport { node } from './kit.js'\nimport { mark, markProps } from './marks.js'\n\nconst Label = Schema.Struct({ label: Schema.String })\n\n/** Where a footnote is referred to: the run showing its label carries this mark. */\nexport const FootnoteRef = mark('FootnoteRef', { Props: Label, expand: 'none' })\n\n/** A footnote's note, under the label its references carry. */\nexport const FootnoteDefinition = node('FootnoteDefinition', {\n Props: Label,\n children: blockContent,\n})\n\n/** One footnote: its label, its definition if there is one, and the runs that refer to it. */\nexport interface Footnote {\n readonly label: string\n readonly definition: NodeId | undefined\n /** The runs carrying its reference, in document order. */\n readonly references: ReadonlyArray<NodeId>\n /** The definition's text, one line per block. */\n readonly text: string\n}\n\nconst labelOf = (props: unknown): string | undefined => {\n if (typeof props !== 'object' || props === null || !('label' in props)) return undefined\n return typeof props.label === 'string' ? props.label : undefined\n}\n\n/** The label of the footnote a run refers to, if it carries a reference. */\nexport const referenceLabel = (run: Text): string | undefined => {\n const reference = run.marks.find(each => markName(each) === FootnoteRef.name)\n return reference === undefined ? undefined : labelOf(markProps(reference))\n}\n\nconst textOf = (blocks: ReadonlyArray<Block>): string => {\n const lines: Array<string> = []\n eachBlock(blocks, block => {\n if (block.children.length > 0) lines.push(block.children.map(run => run.text).join(''))\n })\n return lines.join('\\n')\n}\n\n/**\n * Every footnote, in the order its first reference appears; a definition nothing refers to comes\n * after them, in document order.\n */\nexport const footnotesOf = (document: Document): ReadonlyArray<Footnote> => {\n const references = new Map<string, Array<NodeId>>()\n const definitions = new Map<string, { node: NodeId; text: string }>()\n eachBlock(document.children, block => {\n if (block.type === 'Node' && block.kind === FootnoteDefinition.name) {\n const label = labelOf(block.props)\n if (label !== undefined && !definitions.has(label)) {\n definitions.set(label, { node: block.id, text: textOf(block.blocks ?? []) })\n }\n }\n for (const run of block.children) {\n const label = referenceLabel(run)\n if (label === undefined) continue\n const held = references.get(label)\n if (held === undefined) references.set(label, [run.id])\n else held.push(run.id)\n }\n })\n const labels = [...references.keys(), ...[...definitions.keys()].filter(l => !references.has(l))]\n return labels.map(label => ({\n label,\n definition: definitions.get(label)?.node,\n references: references.get(label) ?? [],\n text: definitions.get(label)?.text ?? '',\n }))\n}\n\n/**\n * The label of the footnote whose reference the selection starts in or right beside. A reference\n * is a character or two, and its mark does not extend, so a click on one usually leaves the caret\n * at its edge, in the run next to it; that caret counts as at the reference.\n */\nexport const footnoteAt = (document: Document, selection: Selection | null): string | undefined => {\n if (selection?.type !== 'Range') return undefined\n const start = rangeStart(document, selection)\n if (start === undefined) return undefined\n let found: string | undefined\n eachBlock(document.children, block => {\n const index = block.children.findIndex(each => each.id === start.node)\n if (index < 0) return\n const run = block.children[index]!\n let beside: Text | undefined\n if (start.offset === 0) beside = block.children[index - 1]\n else if (start.offset === run.text.length) beside = block.children[index + 1]\n found = referenceLabel(run) ?? (beside === undefined ? undefined : referenceLabel(beside))\n })\n return found\n}\n\n/** The smallest whole number no footnote uses as its label, as text: the next note's label. */\nexport const nextFootnoteLabel = (document: Document): string => {\n const used = new Set(footnotesOf(document).map(each => each.label))\n let n = 1\n while (used.has(String(n))) n++\n return String(n)\n}\n"],"mappings":";;;;;;;;;;;;AAsBA,MAAM,QAAQ,OAAO,OAAO,EAAE,OAAO,OAAO,OAAO,CAAC;;AAGpD,MAAa,cAAc,KAAK,eAAe;CAAE,OAAO;CAAO,QAAQ;AAAO,CAAC;;AAG/E,MAAa,qBAAqB,KAAK,sBAAsB;CAC3D,OAAO;CACP,UAAU;AACZ,CAAC;AAYD,MAAM,WAAW,UAAuC;CACtD,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,EAAE,WAAW,QAAQ,OAAO,KAAA;CAC/E,OAAO,OAAO,MAAM,UAAU,WAAW,MAAM,QAAQ,KAAA;AACzD;;AAGA,MAAa,kBAAkB,QAAkC;CAC/D,MAAM,YAAY,IAAI,MAAM,MAAK,SAAQ,SAAS,IAAI,MAAM,YAAY,IAAI;CAC5E,OAAO,cAAc,KAAA,IAAY,KAAA,IAAY,QAAQ,UAAU,SAAS,CAAC;AAC3E;AAEA,MAAM,UAAU,WAA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