@folijs/view 0.5.0 → 1.0.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.
Files changed (82) hide show
  1. package/CHANGELOG.md +194 -0
  2. package/README.md +1 -1
  3. package/dist/clipboard.d.ts +1 -49
  4. package/dist/clipboard.d.ts.map +1 -1
  5. package/dist/clipboard.js +65 -13
  6. package/dist/clipboard.js.map +1 -1
  7. package/dist/extension.d.ts +90 -0
  8. package/dist/extension.d.ts.map +1 -0
  9. package/dist/extension.js +152 -0
  10. package/dist/extension.js.map +1 -0
  11. package/dist/index.d.ts +2 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/layout/flow.d.ts +1 -109
  15. package/dist/layout/flow.d.ts.map +1 -1
  16. package/dist/layout/flow.js +808 -103
  17. package/dist/layout/flow.js.map +1 -1
  18. package/dist/print.d.ts +6 -0
  19. package/dist/print.d.ts.map +1 -0
  20. package/dist/print.js +35 -0
  21. package/dist/print.js.map +1 -0
  22. package/dist/render.d.ts +1 -24
  23. package/dist/render.d.ts.map +1 -1
  24. package/dist/render.js +4 -1
  25. package/dist/render.js.map +1 -1
  26. package/dist/view.d.ts +244 -64
  27. package/dist/view.d.ts.map +1 -1
  28. package/dist/view.js +1945 -215
  29. package/dist/view.js.map +1 -1
  30. package/dist/word/blocks.d.ts +0 -146
  31. package/dist/word/blocks.d.ts.map +1 -1
  32. package/dist/word/blocks.js +294 -59
  33. package/dist/word/blocks.js.map +1 -1
  34. package/dist/word/columns.d.ts +2 -0
  35. package/dist/word/columns.d.ts.map +1 -0
  36. package/dist/word/columns.js +63 -0
  37. package/dist/word/columns.js.map +1 -0
  38. package/dist/word/controls.d.ts +2 -0
  39. package/dist/word/controls.d.ts.map +1 -0
  40. package/dist/word/controls.js +416 -0
  41. package/dist/word/controls.js.map +1 -0
  42. package/dist/word/edit.d.ts +1 -71
  43. package/dist/word/edit.d.ts.map +1 -1
  44. package/dist/word/edit.js +338 -29
  45. package/dist/word/edit.js.map +1 -1
  46. package/dist/word/matches.d.ts +2 -0
  47. package/dist/word/matches.d.ts.map +1 -0
  48. package/dist/word/matches.js +102 -0
  49. package/dist/word/matches.js.map +1 -0
  50. package/dist/word/notes.d.ts +2 -0
  51. package/dist/word/notes.d.ts.map +1 -0
  52. package/dist/word/notes.js +403 -0
  53. package/dist/word/notes.js.map +1 -0
  54. package/dist/word/pages.d.ts +30 -20
  55. package/dist/word/pages.d.ts.map +1 -1
  56. package/dist/word/pages.js +421 -229
  57. package/dist/word/pages.js.map +1 -1
  58. package/dist/word/regions.d.ts +2 -0
  59. package/dist/word/regions.d.ts.map +1 -0
  60. package/dist/word/regions.js +388 -0
  61. package/dist/word/regions.js.map +1 -0
  62. package/dist/word/table.d.ts +1 -78
  63. package/dist/word/table.d.ts.map +1 -1
  64. package/dist/word/table.js +13 -3
  65. package/dist/word/table.js.map +1 -1
  66. package/package.json +6 -3
  67. package/src/clipboard.ts +93 -20
  68. package/src/extension.ts +267 -0
  69. package/src/index.ts +10 -0
  70. package/src/layout/flow.ts +997 -116
  71. package/src/print.ts +55 -0
  72. package/src/render.ts +6 -1
  73. package/src/view.ts +2178 -245
  74. package/src/word/blocks.ts +339 -62
  75. package/src/word/columns.ts +81 -0
  76. package/src/word/controls.ts +457 -0
  77. package/src/word/edit.ts +381 -31
  78. package/src/word/matches.ts +104 -0
  79. package/src/word/notes.ts +464 -0
  80. package/src/word/pages.ts +518 -221
  81. package/src/word/regions.ts +488 -0
  82. package/src/word/table.ts +33 -8
@@ -1 +1 @@
1
- {"version":3,"file":"table.js","sourceRoot":"","sources":["../../src/word/table.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAiDzD,4DAA4D;AAC5D,MAAM,UAAU,OAAO,CAAC,GAAc,EAAE,QAAkB;IACxD,MAAM,KAAK,GAAW,EAAE,CAAC;IACzB,MAAM,KAAK,GAA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AC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@folijs/view",
3
- "version": "0.5.0",
3
+ "version": "1.0.0",
4
4
  "description": "Framework-agnostic DOM view for the Foli document engine: rendering, input, selection, layout.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -24,8 +24,11 @@
24
24
  "src",
25
25
  "!src/**/*.test.*"
26
26
  ],
27
- "dependencies": {
28
- "@folijs/core": "^0.5.0"
27
+ "peerDependencies": {
28
+ "@folijs/core": "1.0.0"
29
+ },
30
+ "devDependencies": {
31
+ "@folijs/core": "1.0.0"
29
32
  },
30
33
  "scripts": {
31
34
  "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
package/src/clipboard.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  type Alignment,
3
- copiedDefinitions,
4
3
  type DocJSON,
5
4
  Fragment,
6
5
  type InlineJSON,
@@ -8,10 +7,15 @@ import {
8
7
  type MarkJSON,
9
8
  type Node as ModelNode,
10
9
  type ParagraphJSON,
10
+ type ResourceJSON,
11
11
  type SimpleMarkName,
12
+ } from "@folijs/core";
13
+ import {
14
+ copiedDefinitions,
15
+ type FittedPaste,
12
16
  type WordContext,
13
17
  type WordEnvelope,
14
- } from "@folijs/core";
18
+ } from "@folijs/core/internal";
15
19
  import { PAGE_BREAK_ATTR } from "./render.js";
16
20
  import { opaqueParagraphsText, parseOpaque } from "./word/blocks.js";
17
21
  import { clipboardBlocks } from "./word/edit.js";
@@ -23,7 +27,39 @@ import { clipboardBlocks } from "./word/edit.js";
23
27
  */
24
28
  export const FOLI_MIME = "application/x-foli+json";
25
29
 
26
- /** One clipboard format's content, before validation. */
30
+ /**
31
+ * The attribute on the clipboard HTML's wrapper that holds the Foli JSON when the copy has custom
32
+ * nodes or marks (ADR-0008): some browsers (Firefox) give a paste only `text/html` and
33
+ * `text/plain`, and HTML alone cannot say what a custom type is.
34
+ */
35
+ const JSON_ATTR = "data-foli-clipboard";
36
+
37
+ /** Whether `content` holds a custom or foreign node or mark. */
38
+ function hasCustom(content: ModelNode): boolean {
39
+ let found = false;
40
+ content.descendants((node) => {
41
+ found ||=
42
+ !!node.type.spec.text ||
43
+ // Pictures too: an HTML-only paste (Firefox) would lose their images.
44
+ node.type.name === "picture" ||
45
+ node.marks.some((m) => m.type.name.includes(":") || m.type.name === "foreign");
46
+ return !found;
47
+ });
48
+ return found;
49
+ }
50
+
51
+ /** The Foli JSON of the clipboard (`FOLI_MIME`'s), as a format to try. */
52
+ function foliJSON(json: string): Found | null {
53
+ const value: unknown = JSON.parse(json);
54
+ if (typeof value !== "object" || value === null) return null;
55
+ const { open, content, word } = value as { open?: unknown; content?: unknown; word?: unknown };
56
+ return { content, open: open === true, word };
57
+ }
58
+
59
+ /**
60
+ * One clipboard format's content, before validation.
61
+ * @internal
62
+ */
27
63
  export interface Found {
28
64
  content: unknown;
29
65
  open: boolean;
@@ -33,11 +69,16 @@ export interface Found {
33
69
  word?: unknown;
34
70
  }
35
71
 
36
- /** Validated clipboard content. */
72
+ /**
73
+ * Validated clipboard content.
74
+ * @internal
75
+ */
37
76
  export interface Pasted {
38
77
  doc: ModelNode;
39
78
  /** The target's envelope with what the content needs (styles, lists...), when it changed. */
40
79
  envelope?: WordEnvelope;
80
+ /** New notes for the references in `doc`: added with it. */
81
+ notes?: FittedPaste["notes"];
41
82
  /**
42
83
  * True when no block boundary was copied (text from inside one block, plain text, inline
43
84
  * HTML): the content always joins the block it is pasted into, which keeps its type. Closed
@@ -46,6 +87,7 @@ export interface Pasted {
46
87
  open: boolean;
47
88
  }
48
89
 
90
+ /** @internal */
49
91
  export interface ClipboardContent {
50
92
  text: string;
51
93
  html: string;
@@ -56,13 +98,19 @@ export interface ClipboardContent {
56
98
  * Serializes `from..to` of `doc` for the clipboard. Hard breaks and block ends become "\n". The
57
99
  * HTML is the document as its Word renderer draws it (`word`: its context and the fonts' line
58
100
  * height ratios): resolved formatting as inline CSS, list numbers as Word's HTML has them.
101
+ * @internal
59
102
  */
60
103
  export function serializeRange(
61
104
  doc: ModelNode,
62
105
  from: number,
63
106
  to: number,
64
107
  ownerDocument: Document,
65
- word: { context: WordContext; ratio: (family: string) => number },
108
+ word: {
109
+ context: WordContext;
110
+ ratio: (family: string) => number;
111
+ /** A copied picture's image as another document can show it (the view's own source). */
112
+ portable?: (key: string, resource: ResourceJSON) => ResourceJSON;
113
+ },
66
114
  ): ClipboardContent {
67
115
  // A slice inside one textblock holds only inline content: wrap it back in its ancestors.
68
116
  const $from = doc.resolve(from);
@@ -87,14 +135,27 @@ export function serializeRange(
87
135
  // How other apps (and print) recognize a page break; the editor itself does not need it.
88
136
  for (const br of container.querySelectorAll(`br[${PAGE_BREAK_ATTR}]`))
89
137
  (br as HTMLElement).style.cssText = "page-break-before: always; break-before: page";
138
+ const definitions = copiedDefinitions(word.context, blocks);
139
+ const { portable } = word;
140
+ if (definitions.resources && portable)
141
+ definitions.resources = Object.fromEntries(
142
+ Object.entries(definitions.resources).map(([key, r]) => [key, portable(key, r)]),
143
+ );
144
+ const json = JSON.stringify({
145
+ open: $from.sharedDepth(to) > 0,
146
+ content: blocks.toJSON(),
147
+ word: definitions,
148
+ });
149
+ let html = container.innerHTML;
150
+ if (hasCustom(blocks)) {
151
+ // An attribute (escaped by the DOM) on the wrapper, read back by `docFromClipboard`.
152
+ container.setAttribute(JSON_ATTR, json);
153
+ html = container.outerHTML;
154
+ }
90
155
  return {
91
156
  text: doc.textBetween(from, to, "\n", (leaf) => leafText(leaf, ownerDocument)),
92
- html: container.innerHTML,
93
- json: JSON.stringify({
94
- open: $from.sharedDepth(to) > 0,
95
- content: blocks.toJSON(),
96
- word: copiedDefinitions(word.context, blocks),
97
- }),
157
+ html,
158
+ json,
98
159
  };
99
160
  }
100
161
 
@@ -105,6 +166,8 @@ export function serializeRange(
105
166
  function leafText(leaf: ModelNode, doc: Document): string {
106
167
  const name = leaf.type.name;
107
168
  if (name === "tab") return "\t";
169
+ const stands = leaf.type.spec.text;
170
+ if (stands) return leaf.isBlock ? `\n${stands(leaf.attrs)}` : stands(leaf.attrs);
108
171
  if (name === "opaqueInline" || name === "opaqueBlock") {
109
172
  const xml = parseOpaque(String(leaf.attrs.xml ?? ""), doc);
110
173
  const text = xml ? opaqueParagraphsText(xml) : "";
@@ -120,6 +183,7 @@ function leafText(leaf: ModelNode, doc: Document): string {
120
183
  * text. Every format is validated and fitted to the document by `parse` (`fitPaste`,
121
184
  * `fitPastedV2`); a format that fails falls through to the next. `marks` are given to plain text
122
185
  * (the marks typing would get at the insertion point).
186
+ * @internal
123
187
  */
124
188
  export function docFromClipboard(
125
189
  data: Pick<DataTransfer, "getData">,
@@ -130,16 +194,24 @@ export function docFromClipboard(
130
194
  const html = data.getData("text/html");
131
195
  const text = data.getData("text/plain");
132
196
  const candidates: (() => Found | null)[] = [
197
+ () => (json ? foliJSON(json) : null),
133
198
  () => {
134
- if (!json) return null;
135
- const value: unknown = JSON.parse(json);
136
- if (typeof value !== "object" || value === null) return null;
137
- const { open, content, word } = value as {
138
- open?: unknown;
139
- content?: unknown;
140
- word?: unknown;
141
- };
142
- return { content, open: open === true, word };
199
+ // Foli's HTML with custom content carries its JSON (parsed inert, never inserted).
200
+ if (!html.includes(JSON_ATTR)) return null;
201
+ const { body } = new DOMParser().parseFromString(html, "text/html");
202
+ // Only when the wrapper is all there is: a Foli copy inside other content (an email
203
+ // quoting it) is read as HTML, so the text around it is kept.
204
+ const alone = [...body.childNodes].every(
205
+ (n) =>
206
+ n.nodeType === 8 ||
207
+ (n.nodeType === 3 && !n.textContent?.trim()) ||
208
+ n === body.firstElementChild,
209
+ );
210
+ const carried =
211
+ alone && body.childElementCount === 1
212
+ ? body.firstElementChild?.getAttribute(JSON_ATTR)
213
+ : null;
214
+ return carried ? foliJSON(carried) : null;
143
215
  },
144
216
  () => {
145
217
  const read = html ? readHTML(html) : null;
@@ -283,6 +355,7 @@ const hex2 = (n: number) =>
283
355
  * A CSS color as the schema stores it (lowercase `#rrggbb`), or null: transparent, unknown
284
356
  * (system colors such as Word's `windowtext`) or empty. Hex (3 or 6 digits), `rgb()`/`rgba()`
285
357
  * and the basic named colors.
358
+ * @internal
286
359
  */
287
360
  export function parseColor(value: string): string | null {
288
361
  const color = value.trim().toLowerCase();
@@ -0,0 +1,267 @@
1
+ /**
2
+ * The view's side of extensions (ADR-0008, 12.4): node views draw custom nodes, mark views style
3
+ * runs of custom marks, decorations put classes and attributes on drawn ranges, and plugin views
4
+ * live as long as the `EditorView`. Core has no DOM: these hooks are on `ViewExtension`, which an
5
+ * app gives to `createEditor` as an ordinary extension; the view reads them from
6
+ * `editor.extensions`.
7
+ *
8
+ * Everything here is drawn with DOM calls, never parsed from HTML: attribute names are checked
9
+ * (no `on*` handlers, no `contenteditable`, none of the view's own `data-foli-*`), and URL
10
+ * attributes must be safe links (`isSafeHref`).
11
+ */
12
+ import {
13
+ type EditorState,
14
+ type Extension,
15
+ isSafeHref,
16
+ type Mark,
17
+ type Node as ModelNode,
18
+ } from "@folijs/core";
19
+ import type { EditorView } from "./view.js";
20
+
21
+ /**
22
+ * Attributes put on a drawn element: `class` is added to its classes, `style` to its style, any
23
+ * other name set (`aria-*`, `data-*`, `title`…).
24
+ */
25
+ export interface DecorationAttrs {
26
+ class?: string;
27
+ style?: string;
28
+ [name: string]: string | undefined;
29
+ }
30
+
31
+ /**
32
+ * Attributes on a range of the document as drawn, never content: the text and inline leaves
33
+ * from `from` to `to` (body positions of the state the decorations are for), or with `node` the
34
+ * node at `from`: a block (its element on every page it is on) or an inline leaf. A table, row
35
+ * or cell takes none.
36
+ */
37
+ export interface Decoration {
38
+ from: number;
39
+ to: number;
40
+ node?: boolean;
41
+ attrs: DecorationAttrs;
42
+ }
43
+
44
+ /**
45
+ * What a node view draws with: its document, and `h`, which makes elements safely. A node view may
46
+ * build its DOM by other means: what `render` returns is used as it is, unchecked (extension code
47
+ * is trusted, the node's attributes are not: never put them through HTML).
48
+ */
49
+ export interface NodeViewDOM {
50
+ readonly document: Document;
51
+ /**
52
+ * An element `tag` (from an allowlist of content elements: no `script`, `style`, `base`,
53
+ * `form`, frames…) with attributes `attrs` (checked as decorations' are) and children, strings
54
+ * as text nodes: data from the document never goes through HTML.
55
+ */
56
+ h(
57
+ tag: string,
58
+ attrs?: Readonly<Record<string, string>> | null,
59
+ ...children: readonly (Node | string)[]
60
+ ): HTMLElement;
61
+ }
62
+
63
+ /**
64
+ * How a custom node is drawn. Inline: in its line, which wraps around it as the browser sizes it.
65
+ * Block: on the pages, measured by the flow; one taller than the room left on a page splits
66
+ * between its root element's children (each part drawn again by `render`, clipped), unless
67
+ * `split` is false, which keeps it whole on one page.
68
+ */
69
+ export interface NodeView {
70
+ /**
71
+ * Called whenever the node is drawn again: a changed node, or a block split differently. Its
72
+ * DOM may change later (content loaded, a chart drawn): the view does not read it back.
73
+ */
74
+ render(node: ModelNode, dom: NodeViewDOM): Node;
75
+ split?: boolean;
76
+ /** Called with what `render` returned once the view no longer shows it (or is destroyed). */
77
+ destroy?(dom: Node): void;
78
+ }
79
+
80
+ /** How a run of a custom mark is drawn: attributes on the run's element. */
81
+ export type MarkView = (mark: Mark) => DecorationAttrs;
82
+
83
+ /** What a view extension keeps beside an `EditorView`: told of each update, destroyed with it. */
84
+ export interface PluginView {
85
+ /** After the view drew a new state; `previous` is the state before. */
86
+ update?(view: EditorView, previous: EditorState): void;
87
+ destroy?(): void;
88
+ }
89
+
90
+ /**
91
+ * An extension with view hooks (ADR-0008), given to `createEditor({ extensions })` (and React's
92
+ * `extensions` prop) like any extension.
93
+ */
94
+ export interface ViewExtension extends Extension {
95
+ /** By node type: one of the extension's (or another extension's) custom nodes. */
96
+ nodeViews?: Readonly<Record<string, NodeView>>;
97
+ /** By mark type. */
98
+ markViews?: Readonly<Record<string, MarkView>>;
99
+ /**
100
+ * The decorations for a state, asked on every update: keep it cheap (plugin state is a good
101
+ * place to keep them). Only blocks whose decorations changed are drawn again.
102
+ */
103
+ decorations?(state: EditorState): readonly Decoration[];
104
+ /** Called when a view of the editor is made (a story open on its page has a view too). */
105
+ view?(view: EditorView): PluginView;
106
+ }
107
+
108
+ /** The node and mark views of a view's extensions. @internal */
109
+ export interface Views {
110
+ nodes: ReadonlyMap<string, NodeView>;
111
+ marks: ReadonlyMap<string, MarkView>;
112
+ }
113
+
114
+ /** A node view's drawing, in its box, until the view drops it. @internal */
115
+ export interface Drawn {
116
+ view: NodeView;
117
+ root: Node;
118
+ box: Element;
119
+ }
120
+
121
+ /** @internal */
122
+ export function viewsOf(extensions: readonly ViewExtension[]): Views {
123
+ return {
124
+ nodes: new Map(extensions.flatMap((e) => Object.entries(e.nodeViews ?? {}))),
125
+ marks: new Map(extensions.flatMap((e) => Object.entries(e.markViews ?? {}))),
126
+ };
127
+ }
128
+
129
+ const NAME = /^[a-z_][\w.:-]*$/i;
130
+ const URL_ATTRS = new Set([
131
+ "href",
132
+ "src",
133
+ "xlink:href",
134
+ "action",
135
+ "formaction",
136
+ "poster",
137
+ "background",
138
+ ]);
139
+ /** Attributes holding several URLs: `srcset` (comma separated, each before its size), `ping`. */
140
+ const URL_LISTS: Record<string, (value: string) => string[]> = {
141
+ srcset: (value) => value.split(",").map((part) => part.trim().split(/\s+/)[0] ?? ""),
142
+ ping: (value) => value.split(/\s+/).filter(Boolean),
143
+ };
144
+ /** Style that fetches or runs something (escapes could spell it otherwise). */
145
+ const UNSAFE_STYLE = /url\s*\(|image-set|expression|@import|-moz-binding|behavior|\\/i;
146
+ /** Content elements a node view may make with `h` (no scripts, styles, forms, frames, `base`). */
147
+ const TAGS = new Set(
148
+ (
149
+ "a abbr address article aside audio b bdi bdo blockquote br button canvas caption cite code " +
150
+ "col colgroup data dd del details dfn div dl dt em figcaption figure footer h1 h2 h3 h4 h5 h6 " +
151
+ "header hgroup hr i img ins kbd label li mark meter ol p picture pre progress q rp rt ruby s " +
152
+ "samp section small source span strong sub summary sup table tbody td tfoot th thead time tr " +
153
+ "track u ul var video wbr"
154
+ ).split(" "),
155
+ );
156
+
157
+ /** Throws on an attribute a view must not set: handlers, editing, the view's own, unsafe URLs. */
158
+ function check(name: string, value: string): void {
159
+ const lower = name.toLowerCase();
160
+ if (
161
+ !NAME.test(name) ||
162
+ lower.startsWith("on") ||
163
+ lower === "contenteditable" ||
164
+ lower === "srcdoc" ||
165
+ lower.startsWith("data-foli-") ||
166
+ (URL_ATTRS.has(lower) && !isSafeHref(value)) ||
167
+ URL_LISTS[lower]?.(value).some((url) => !isSafeHref(url)) ||
168
+ (lower === "style" && UNSAFE_STYLE.test(value)) ||
169
+ (lower === "class" && /(^|\s)foli-/.test(value))
170
+ )
171
+ throw new TypeError(`Foli: attribute ${name} is not allowed on drawn content`);
172
+ }
173
+
174
+ /**
175
+ * Throws when `attrs` holds one an extension must not set (`check`).
176
+ * @internal
177
+ */
178
+ export function checkAttrs(attrs: DecorationAttrs): void {
179
+ for (const [name, value] of Object.entries(attrs)) if (value !== undefined) check(name, value);
180
+ }
181
+
182
+ /**
183
+ * Puts `attrs` on `element` (classes and style added, the rest set).
184
+ * @internal
185
+ */
186
+ export function applyAttrs(element: HTMLElement, attrs: DecorationAttrs): void {
187
+ checkAttrs(attrs);
188
+ for (const [name, value] of Object.entries(attrs)) {
189
+ if (value === undefined) continue;
190
+ if (name === "class") element.classList.add(...value.split(/\s+/).filter(Boolean));
191
+ else if (name === "style") {
192
+ const style = element.getAttribute("style")?.trim() ?? "";
193
+ element.setAttribute(
194
+ "style",
195
+ style && !style.endsWith(";") ? `${style};${value}` : style + value,
196
+ );
197
+ } else element.setAttribute(name, value);
198
+ }
199
+ }
200
+
201
+ /**
202
+ * Reports an extension's failure without stopping the editor.
203
+ * @internal
204
+ */
205
+ export function reportError(error: unknown): void {
206
+ console.error("Foli: an extension failed", error);
207
+ }
208
+
209
+ /** The DOM API node views draw with. @internal */
210
+ export function nodeViewDOM(document: Document): NodeViewDOM {
211
+ return {
212
+ document,
213
+ h(tag, attrs, ...children) {
214
+ if (!TAGS.has(tag.toLowerCase()))
215
+ throw new TypeError(`Foli: element ${tag} is not allowed in a node view`);
216
+ const element = document.createElement(tag);
217
+ if (attrs) applyAttrs(element, attrs);
218
+ element.append(...children);
219
+ return element;
220
+ },
221
+ };
222
+ }
223
+
224
+ /**
225
+ * The decorations of each block (`units`: the blocks drawn, in document order, with the position
226
+ * before each), relative to its content's start: a node decoration on the block itself is at -1.
227
+ * @internal
228
+ */
229
+ export function decorationsByBlock(
230
+ units: readonly { pos: number; node: ModelNode }[],
231
+ decorations: readonly Decoration[],
232
+ ): (readonly Decoration[] | undefined)[] {
233
+ const out: Decoration[][] = [];
234
+ const add = (i: number, d: Decoration) => {
235
+ const list = out[i] ?? [];
236
+ out[i] = list;
237
+ list.push(d);
238
+ };
239
+ for (const decoration of decorations) {
240
+ const { from, to } = decoration;
241
+ if (!(from <= to) || (!decoration.node && from === to)) continue;
242
+ // The first block ending after `from` (blocks do not overlap: their ends are sorted too).
243
+ let low = 0;
244
+ let high = units.length;
245
+ while (low < high) {
246
+ const mid = (low + high) >> 1;
247
+ const unit = units[mid] as { pos: number; node: ModelNode };
248
+ if (unit.pos + unit.node.nodeSize <= from) low = mid + 1;
249
+ else high = mid;
250
+ }
251
+ for (let i = low; i < units.length; i++) {
252
+ const { pos, node } = units[i] as { pos: number; node: ModelNode };
253
+ const start = pos + 1;
254
+ if (decoration.node) {
255
+ if (from >= pos && from < pos + node.nodeSize)
256
+ add(i, { ...decoration, from: from - start, to: to - start });
257
+ break;
258
+ }
259
+ if (pos >= to) break;
260
+ const end = pos + node.nodeSize - 1;
261
+ // A block leaf has no text to decorate.
262
+ if (!node.isLeaf && from < end && to > start)
263
+ add(i, { ...decoration, from: from - start, to: to - start });
264
+ }
265
+ }
266
+ return out;
267
+ }
package/src/index.ts CHANGED
@@ -1,4 +1,13 @@
1
1
  export { FOLI_MIME, htmlToDoc, textToDoc } from "./clipboard.js";
2
+ export type {
3
+ Decoration,
4
+ DecorationAttrs,
5
+ MarkView,
6
+ NodeView,
7
+ NodeViewDOM,
8
+ PluginView,
9
+ ViewExtension,
10
+ } from "./extension.js";
2
11
  export {
3
12
  EditorView,
4
13
  type EditorViewOptions,
@@ -9,6 +18,7 @@ export {
9
18
  export { EMU_PER_PX } from "./word/blocks.js";
10
19
  export {
11
20
  type DocumentPages,
21
+ type RenderDocumentOptions,
12
22
  type ReviewView,
13
23
  renderDocument,
14
24
  WORD_PAGE_CLASS,