foldkit-richtext-dom 0.1.0 → 0.2.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/README.md +448 -166
- package/dist/decorations-Ar6URa7n.mjs +57 -0
- package/dist/decorations-Ar6URa7n.mjs.map +1 -0
- package/dist/editor-C76tfEyV.d.mts +1016 -0
- package/dist/editor-C76tfEyV.d.mts.map +1 -0
- package/dist/editor-bundle-dnjyuk1P.d.mts +8576 -0
- package/dist/editor-bundle-dnjyuk1P.d.mts.map +1 -0
- package/dist/editor-bundle.d.mts +2 -7535
- package/dist/editor-bundle.mjs +352 -81
- package/dist/editor-bundle.mjs.map +1 -1
- package/dist/editor.d.mts +2 -849
- package/dist/editor.mjs +176 -9
- package/dist/editor.mjs.map +1 -1
- package/dist/{events-BTw9SJ7r.d.mts → events-Dasls6a_.d.mts} +31 -5
- package/dist/events-Dasls6a_.d.mts.map +1 -0
- package/dist/events.d.mts +2 -2
- package/dist/events.mjs +84 -14
- package/dist/events.mjs.map +1 -1
- package/dist/host-1dtxuKIA.d.mts +86 -0
- package/dist/host-1dtxuKIA.d.mts.map +1 -0
- package/dist/host.d.mts +2 -25
- package/dist/host.mjs +78 -6
- package/dist/host.mjs.map +1 -1
- package/dist/html.d.mts +1 -1
- package/dist/html.d.mts.map +1 -1
- package/dist/html.mjs +150 -20
- package/dist/html.mjs.map +1 -1
- package/dist/index-DDV_JesZ.d.mts +57 -0
- package/dist/index-DDV_JesZ.d.mts.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +249 -99
- package/dist/index.mjs.map +1 -1
- package/dist/input.d.mts +936 -0
- package/dist/input.d.mts.map +1 -0
- package/dist/input.mjs +89 -0
- package/dist/input.mjs.map +1 -0
- package/dist/toolbar.d.mts +39 -0
- package/dist/toolbar.d.mts.map +1 -1
- package/dist/toolbar.mjs +325 -1
- package/dist/toolbar.mjs.map +1 -1
- package/dist/view.d.mts +14 -2
- package/dist/view.d.mts.map +1 -1
- package/dist/view.mjs +90 -19
- package/dist/view.mjs.map +1 -1
- package/package.json +26 -5
- package/dist/editor-bundle.d.mts.map +0 -1
- package/dist/editor.d.mts.map +0 -1
- package/dist/events-BTw9SJ7r.d.mts.map +0 -1
- package/dist/host.d.mts.map +0 -1
- package/dist/index-6QEOehXh.d.mts +0 -38
- package/dist/index-6QEOehXh.d.mts.map +0 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as RichText from "foldkit-richtext";
|
|
2
|
+
//#region src/decorations.ts
|
|
3
|
+
/**
|
|
4
|
+
* How decorations are drawn (§129), shared by the editor and the read-only view so one
|
|
5
|
+
* stylesheet serves both.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The decorations over each run (`RichText.decorationsIn`), plus an empty span, `{ from: 0,
|
|
9
|
+
* to: 0 }`, on an empty run a decoration starts or ends in. The core draws nothing over no
|
|
10
|
+
* text, but another person's caret on an empty line still has to show.
|
|
11
|
+
*/
|
|
12
|
+
const decorationSpans = (document, set) => {
|
|
13
|
+
const spans = RichText.decorationsIn(document, set);
|
|
14
|
+
if (set.length === 0) return spans;
|
|
15
|
+
const lengths = /* @__PURE__ */ new Map();
|
|
16
|
+
const visit = (blocks) => {
|
|
17
|
+
for (const block of blocks) {
|
|
18
|
+
for (const run of block.children) lengths.set(run.id, run.text.length);
|
|
19
|
+
if (block.type === "Node" && block.blocks !== void 0) visit(block.blocks);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
visit(document.children);
|
|
23
|
+
const withEmpty = new Map(spans);
|
|
24
|
+
for (const decoration of set) {
|
|
25
|
+
const { from, to } = decoration;
|
|
26
|
+
if (!lengths.has(from.node) || !lengths.has(to.node)) continue;
|
|
27
|
+
for (const node of from.node === to.node ? [from.node] : [from.node, to.node]) {
|
|
28
|
+
if (lengths.get(node) !== 0) continue;
|
|
29
|
+
withEmpty.set(node, [...withEmpty.get(node) ?? [], {
|
|
30
|
+
from: 0,
|
|
31
|
+
to: 0,
|
|
32
|
+
decoration
|
|
33
|
+
}]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return withEmpty;
|
|
37
|
+
};
|
|
38
|
+
/** `RichText.runPieces`, except that an empty run carries the empty spans on it. */
|
|
39
|
+
const piecesOf = (text, spans) => text.length === 0 ? [{
|
|
40
|
+
text,
|
|
41
|
+
decorations: spans.map((span) => span.decoration)
|
|
42
|
+
}] : RichText.runPieces(text, spans);
|
|
43
|
+
const FIELD = /^[a-z][a-z0-9-]*$/;
|
|
44
|
+
/**
|
|
45
|
+
* The attributes a decoration's element carries: `data-decoration` names its kind, and each
|
|
46
|
+
* string field of `data` named in lowercase letters, digits, and hyphens rides as
|
|
47
|
+
* `data-decoration-<name>`, for a stylesheet's `attr()`. Anything else in `data` is not drawn.
|
|
48
|
+
*/
|
|
49
|
+
const decorationAttributes = (decoration) => {
|
|
50
|
+
const data = decoration.data;
|
|
51
|
+
const fields = typeof data === "object" && data !== null && !Array.isArray(data) ? Object.entries(data).filter((field) => typeof field[1] === "string" && FIELD.test(field[0])) : [];
|
|
52
|
+
return [["data-decoration", decoration.kind], ...fields.map(([name, value]) => [`data-decoration-${name}`, value])];
|
|
53
|
+
};
|
|
54
|
+
//#endregion
|
|
55
|
+
export { decorationSpans as n, piecesOf as r, decorationAttributes as t };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=decorations-Ar6URa7n.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorations-Ar6URa7n.mjs","names":[],"sources":["../src/decorations.ts"],"sourcesContent":["/**\n * How decorations are drawn (§129), shared by the editor and the read-only view so one\n * stylesheet serves both.\n */\nimport * as RichText from 'foldkit-richtext'\n\nexport type Spans = ReadonlyMap<RichText.NodeId, ReadonlyArray<RichText.DecorationSpan>>\n\n/**\n * The decorations over each run (`RichText.decorationsIn`), plus an empty span, `{ from: 0,\n * to: 0 }`, on an empty run a decoration starts or ends in. The core draws nothing over no\n * text, but another person's caret on an empty line still has to show.\n */\nexport const decorationSpans = (\n document: RichText.Document,\n set: RichText.DecorationSet,\n): Spans => {\n const spans = RichText.decorationsIn(document, set)\n if (set.length === 0) return spans\n const lengths = new Map<RichText.NodeId, number>()\n const visit = (blocks: ReadonlyArray<RichText.Block>): void => {\n for (const block of blocks) {\n for (const run of block.children) lengths.set(run.id, run.text.length)\n if (block.type === 'Node' && block.blocks !== undefined) visit(block.blocks)\n }\n }\n visit(document.children)\n const withEmpty = new Map(spans)\n for (const decoration of set) {\n const { from, to } = decoration\n // Both ends must resolve, as `decorationsIn` requires.\n if (!lengths.has(from.node) || !lengths.has(to.node)) continue\n for (const node of from.node === to.node ? [from.node] : [from.node, to.node]) {\n if (lengths.get(node) !== 0) continue\n withEmpty.set(node, [...(withEmpty.get(node) ?? []), { from: 0, to: 0, decoration }])\n }\n }\n return withEmpty\n}\n\n/** `RichText.runPieces`, except that an empty run carries the empty spans on it. */\nexport const piecesOf = (\n text: string,\n spans: ReadonlyArray<RichText.DecorationSpan>,\n): ReadonlyArray<RichText.RunPiece> =>\n text.length === 0\n ? [{ text, decorations: spans.map(span => span.decoration) }]\n : RichText.runPieces(text, spans)\n\nconst FIELD = /^[a-z][a-z0-9-]*$/\n\n/**\n * The attributes a decoration's element carries: `data-decoration` names its kind, and each\n * string field of `data` named in lowercase letters, digits, and hyphens rides as\n * `data-decoration-<name>`, for a stylesheet's `attr()`. Anything else in `data` is not drawn.\n */\nexport const decorationAttributes = (\n decoration: RichText.Decoration,\n): ReadonlyArray<readonly [string, string]> => {\n const data: unknown = decoration.data\n const fields =\n typeof data === 'object' && data !== null && !Array.isArray(data)\n ? Object.entries(data).filter(\n (field): field is [string, string] =>\n typeof field[1] === 'string' && FIELD.test(field[0]),\n )\n : []\n return [\n ['data-decoration', decoration.kind],\n ...fields.map(([name, value]) => [`data-decoration-${name}`, value] as const),\n ]\n}\n"],"mappings":";;;;;;;;;;;AAaA,MAAa,mBACX,UACA,QACU;CACV,MA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