myrole-docx-editor 0.1.5 → 0.3.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 (30) hide show
  1. package/README.md +30 -0
  2. package/dist/chunks/{sdk-BVyUd7P0.js → sdk-CU9i-NwD.js} +9202 -8422
  3. package/dist/chunks/sdk-CU9i-NwD.js.map +1 -0
  4. package/dist/chunks/{vars-blockly-CBeNXS0X.js → vars-blockly-CBim6Ow0.js} +2 -2
  5. package/dist/chunks/{vars-blockly-CBeNXS0X.js.map → vars-blockly-CBim6Ow0.js.map} +1 -1
  6. package/dist/index.js +2 -2
  7. package/dist/react.js +1 -1
  8. package/dist/types/packages/docx-editor/src/authoring-ui.d.ts +3 -0
  9. package/dist/types/packages/docx-editor/src/commands.d.ts +1 -1
  10. package/dist/types/packages/docx-editor/src/comment-ui.d.ts +4 -0
  11. package/dist/types/packages/docx-editor/src/comments.d.ts +2 -24
  12. package/dist/types/packages/docx-editor/src/editor.d.ts +22 -3
  13. package/dist/types/packages/docx-editor/src/html.d.ts +3 -2
  14. package/dist/types/packages/docx-editor/src/sdk.d.ts +5 -0
  15. package/dist/types/packages/docx-editor/src/vars-complete.d.ts +3 -3
  16. package/dist/types/packages/docx-editor/src/vars-library.d.ts +14 -0
  17. package/dist/types/packages/docx-editor/src/vars-panel.d.ts +2 -0
  18. package/dist/types/packages/docx-model/src/authoring.d.ts +10 -0
  19. package/dist/types/packages/docx-model/src/comments.d.ts +30 -0
  20. package/dist/types/packages/docx-model/src/editor.d.ts +3 -1
  21. package/dist/types/packages/docx-model/src/index.d.ts +2 -0
  22. package/dist/types/packages/docx-model/src/insert.d.ts +8 -1
  23. package/dist/types/packages/docx-model/src/paste.d.ts +6 -0
  24. package/dist/types/packages/docx-model/src/spans.d.ts +2 -0
  25. package/dist/types/packages/docx-render/src/index.d.ts +1 -1
  26. package/dist/types/packages/docx-render/src/render-api.d.ts +2 -1
  27. package/dist/types/packages/docx-render/src/types.d.ts +16 -0
  28. package/dist/types/packages/docx-tags/src/grammar.d.ts +1 -0
  29. package/package.json +4 -3
  30. package/dist/chunks/sdk-BVyUd7P0.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import * as s from "blockly";
2
- import { k as p, T as u, m, n as f, o as g, q as h } from "./sdk-BVyUd7P0.js";
2
+ import { k as p, T as u, m, n as f, o as g, q as h } from "./sdk-CU9i-NwD.js";
3
3
  let r = !1;
4
4
  function b(o, n, i) {
5
5
  r || (p(), r = !0), o.replaceChildren();
@@ -39,4 +39,4 @@ function b(o, n, i) {
39
39
  export {
40
40
  b as mountBlockly
41
41
  };
42
- //# sourceMappingURL=vars-blockly-CBeNXS0X.js.map
42
+ //# sourceMappingURL=vars-blockly-CBim6Ow0.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"vars-blockly-CBeNXS0X.js","sources":["../../src/vars-blockly.ts"],"sourcesContent":["import * as Blockly from 'blockly'\nimport {\n decorate, defineBlocks, fieldLibrary, setFields, THEME, TOOLBOX,\n type BlockJson,\n} from '@myrole/docx-vars'\nimport type { Tag } from '@myrole/docx-tags'\n\n/**\n * Le mode Blockly, chargé à la demande.\n *\n * Le canvas ne se replie pas — c'est ce qui a fait choisir le rendu DOM par\n * défaut — mais il sait ce que le DOM ne fait pas encore aussi bien :\n * restructurer librement une expression au glisser-déposer, avec sa poubelle,\n * son annulation et ses connexions typées.\n *\n * Il vit dans son propre module pour ne peser que si on l'ouvre : un\n * mégaoctet et demi qu'un utilisateur qui ne bascule jamais ne télécharge pas.\n */\n\nlet defined = false\n\nexport interface BlocklyView {\n load(tree: BlockJson): void\n read(): BlockJson | null\n resize(): void\n dispose(): void\n}\n\nexport function mountBlockly(\n holder: HTMLElement, onChange: () => void, tags: () => Tag[],\n): BlocklyView {\n if (!defined) { defineBlocks(); defined = true }\n holder.replaceChildren()\n const host = document.createElement('div')\n host.className = 'vp-canvas-host'\n holder.append(host)\n\n const ws = Blockly.inject(host, {\n // La boîte à outils : sans elle, on peut lire une expression et la\n // rebrancher, mais pas y AJOUTER quoi que ce soit — c'est la moitié de ce\n // qu'on vient chercher dans un canvas de blocs.\n toolbox: TOOLBOX,\n theme: THEME,\n renderer: 'geras',\n trashcan: true,\n sounds: false,\n grid: { spacing: 20, length: 1, colour: '#e8e9ed', snap: false },\n zoom: { controls: true, wheel: true, startScale: 0.95, minScale: 0.3, maxScale: 2 },\n move: { scrollbars: true, drag: true, wheel: true },\n })\n ws.addChangeListener((e) => { if (!e.isUiEvent) onChange() })\n\n return {\n load(tree) {\n // `setFields` alimente le sélecteur du bloc « champ » : sans lui, un clic\n // sur un champ n'ouvre rien.\n const groups = fieldLibrary(tags())\n setFields(groups.flatMap((g) => g.fields.map((f) => ({ path: f.path, label: f.label }))))\n Blockly.serialization.workspaces.load({ blocks: { languageVersion: 0, blocks: [tree] } }, ws)\n decorate(ws)\n Blockly.svgResize(ws)\n },\n read() {\n const state = Blockly.serialization.workspaces.save(ws) as {\n blocks?: { blocks?: BlockJson[] }\n }\n return state?.blocks?.blocks?.[0] ?? null\n },\n resize() { Blockly.svgResize(ws) },\n dispose() { ws.dispose() },\n }\n}\n"],"names":["defined","mountBlockly","holder","onChange","tags","defineBlocks","host","ws","Blockly","TOOLBOX","THEME","e","tree","groups","fieldLibrary","setFields","g","f","decorate"],"mappings":";;AAmBA,IAAIA,IAAU;AASP,SAASC,EACdC,GAAqBC,GAAsBC,GAC9B;AACb,EAAKJ,MAAWK,EAAA,GAAgBL,IAAU,KAC1CE,EAAO,gBAAA;AACP,QAAMI,IAAO,SAAS,cAAc,KAAK;AACzC,EAAAA,EAAK,YAAY,kBACjBJ,EAAO,OAAOI,CAAI;AAElB,QAAMC,IAAKC,EAAQ,OAAOF,GAAM;AAAA;AAAA;AAAA;AAAA,IAI9B,SAASG;AAAA,IACT,OAAOC;AAAA,IACP,UAAU;AAAA,IACV,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,MAAM,EAAE,SAAS,IAAI,QAAQ,GAAG,QAAQ,WAAW,MAAM,GAAA;AAAA,IACzD,MAAM,EAAE,UAAU,IAAM,OAAO,IAAM,YAAY,MAAM,UAAU,KAAK,UAAU,EAAA;AAAA,IAChF,MAAM,EAAE,YAAY,IAAM,MAAM,IAAM,OAAO,GAAA;AAAA,EAAK,CACnD;AACD,SAAAH,EAAG,kBAAkB,CAACI,MAAM;AAAE,IAAKA,EAAE,aAAWR,EAAA;AAAA,EAAW,CAAC,GAErD;AAAA,IACL,KAAKS,GAAM;AAGT,YAAMC,IAASC,EAAaV,GAAM;AAClC,MAAAW,EAAUF,EAAO,QAAQ,CAACG,MAAMA,EAAE,OAAO,IAAI,CAACC,OAAO,EAAE,MAAMA,EAAE,MAAM,OAAOA,EAAE,MAAA,EAAQ,CAAC,CAAC,GACxFT,EAAQ,cAAc,WAAW,KAAK,EAAE,QAAQ,EAAE,iBAAiB,GAAG,QAAQ,CAACI,CAAI,EAAA,EAAE,GAAKL,CAAE,GAC5FW,EAASX,CAAE,GACXC,EAAQ,UAAUD,CAAE;AAAA,IACtB;AAAA,IACA,OAAO;AAIL,aAHcC,EAAQ,cAAc,WAAW,KAAKD,CAAE,GAGxC,QAAQ,SAAS,CAAC,KAAK;AAAA,IACvC;AAAA,IACA,SAAS;AAAE,MAAAC,EAAQ,UAAUD,CAAE;AAAA,IAAE;AAAA,IACjC,UAAU;AAAE,MAAAA,EAAG,QAAA;AAAA,IAAU;AAAA,EAAA;AAE7B;"}
1
+ {"version":3,"file":"vars-blockly-CBim6Ow0.js","sources":["../../src/vars-blockly.ts"],"sourcesContent":["import * as Blockly from 'blockly'\nimport {\n decorate, defineBlocks, fieldLibrary, setFields, THEME, TOOLBOX,\n type BlockJson,\n} from '@myrole/docx-vars'\nimport type { Tag } from '@myrole/docx-tags'\n\n/**\n * Le mode Blockly, chargé à la demande.\n *\n * Le canvas ne se replie pas — c'est ce qui a fait choisir le rendu DOM par\n * défaut — mais il sait ce que le DOM ne fait pas encore aussi bien :\n * restructurer librement une expression au glisser-déposer, avec sa poubelle,\n * son annulation et ses connexions typées.\n *\n * Il vit dans son propre module pour ne peser que si on l'ouvre : un\n * mégaoctet et demi qu'un utilisateur qui ne bascule jamais ne télécharge pas.\n */\n\nlet defined = false\n\nexport interface BlocklyView {\n load(tree: BlockJson): void\n read(): BlockJson | null\n resize(): void\n dispose(): void\n}\n\nexport function mountBlockly(\n holder: HTMLElement, onChange: () => void, tags: () => Tag[],\n): BlocklyView {\n if (!defined) { defineBlocks(); defined = true }\n holder.replaceChildren()\n const host = document.createElement('div')\n host.className = 'vp-canvas-host'\n holder.append(host)\n\n const ws = Blockly.inject(host, {\n // La boîte à outils : sans elle, on peut lire une expression et la\n // rebrancher, mais pas y AJOUTER quoi que ce soit — c'est la moitié de ce\n // qu'on vient chercher dans un canvas de blocs.\n toolbox: TOOLBOX,\n theme: THEME,\n renderer: 'geras',\n trashcan: true,\n sounds: false,\n grid: { spacing: 20, length: 1, colour: '#e8e9ed', snap: false },\n zoom: { controls: true, wheel: true, startScale: 0.95, minScale: 0.3, maxScale: 2 },\n move: { scrollbars: true, drag: true, wheel: true },\n })\n ws.addChangeListener((e) => { if (!e.isUiEvent) onChange() })\n\n return {\n load(tree) {\n // `setFields` alimente le sélecteur du bloc « champ » : sans lui, un clic\n // sur un champ n'ouvre rien.\n const groups = fieldLibrary(tags())\n setFields(groups.flatMap((g) => g.fields.map((f) => ({ path: f.path, label: f.label }))))\n Blockly.serialization.workspaces.load({ blocks: { languageVersion: 0, blocks: [tree] } }, ws)\n decorate(ws)\n Blockly.svgResize(ws)\n },\n read() {\n const state = Blockly.serialization.workspaces.save(ws) as {\n blocks?: { blocks?: BlockJson[] }\n }\n return state?.blocks?.blocks?.[0] ?? null\n },\n resize() { Blockly.svgResize(ws) },\n dispose() { ws.dispose() },\n }\n}\n"],"names":["defined","mountBlockly","holder","onChange","tags","defineBlocks","host","ws","Blockly","TOOLBOX","THEME","e","tree","groups","fieldLibrary","setFields","g","f","decorate"],"mappings":";;AAmBA,IAAIA,IAAU;AASP,SAASC,EACdC,GAAqBC,GAAsBC,GAC9B;AACb,EAAKJ,MAAWK,EAAA,GAAgBL,IAAU,KAC1CE,EAAO,gBAAA;AACP,QAAMI,IAAO,SAAS,cAAc,KAAK;AACzC,EAAAA,EAAK,YAAY,kBACjBJ,EAAO,OAAOI,CAAI;AAElB,QAAMC,IAAKC,EAAQ,OAAOF,GAAM;AAAA;AAAA;AAAA;AAAA,IAI9B,SAASG;AAAA,IACT,OAAOC;AAAA,IACP,UAAU;AAAA,IACV,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,MAAM,EAAE,SAAS,IAAI,QAAQ,GAAG,QAAQ,WAAW,MAAM,GAAA;AAAA,IACzD,MAAM,EAAE,UAAU,IAAM,OAAO,IAAM,YAAY,MAAM,UAAU,KAAK,UAAU,EAAA;AAAA,IAChF,MAAM,EAAE,YAAY,IAAM,MAAM,IAAM,OAAO,GAAA;AAAA,EAAK,CACnD;AACD,SAAAH,EAAG,kBAAkB,CAACI,MAAM;AAAE,IAAKA,EAAE,aAAWR,EAAA;AAAA,EAAW,CAAC,GAErD;AAAA,IACL,KAAKS,GAAM;AAGT,YAAMC,IAASC,EAAaV,GAAM;AAClC,MAAAW,EAAUF,EAAO,QAAQ,CAACG,MAAMA,EAAE,OAAO,IAAI,CAACC,OAAO,EAAE,MAAMA,EAAE,MAAM,OAAOA,EAAE,MAAA,EAAQ,CAAC,CAAC,GACxFT,EAAQ,cAAc,WAAW,KAAK,EAAE,QAAQ,EAAE,iBAAiB,GAAG,QAAQ,CAACI,CAAI,EAAA,EAAE,GAAKL,CAAE,GAC5FW,EAASX,CAAE,GACXC,EAAQ,UAAUD,CAAE;AAAA,IACtB;AAAA,IACA,OAAO;AAIL,aAHcC,EAAQ,cAAc,WAAW,KAAKD,CAAE,GAGxC,QAAQ,SAAS,CAAC,KAAK;AAAA,IACvC;AAAA,IACA,SAAS;AAAE,MAAAC,EAAQ,UAAUD,CAAE;AAAA,IAAE;AAAA,IACjC,UAAU;AAAE,MAAAA,EAAG,QAAA;AAAA,IAAU;AAAA,EAAA;AAE7B;"}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { i as f, r as m, e as w, f as p, p as u, l as y, a as g, b as h, c as x } from "./chunks/sdk-BVyUd7P0.js";
2
- import { d as R, g as b, h as U, j, s as A } from "./chunks/sdk-BVyUd7P0.js";
1
+ import { i as f, r as m, e as w, f as p, p as u, l as y, a as g, b as h, c as x } from "./chunks/sdk-CU9i-NwD.js";
2
+ import { d as R, g as b, h as U, j, s as A } from "./chunks/sdk-CU9i-NwD.js";
3
3
  async function P(a, o, r = {}) {
4
4
  const i = performance.now(), [c] = await Promise.all([
5
5
  typeof a == "string" ? fetch(a).then((e) => e.ok ? e.arrayBuffer() : Promise.reject(new Error(`${e.status} ${a}`))) : Promise.resolve(a),
package/dist/react.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx as h } from "react/jsx-runtime";
2
2
  import { forwardRef as v, useRef as o, useEffect as a } from "react";
3
- import { d as y } from "./chunks/sdk-BVyUd7P0.js";
3
+ import { d as y } from "./chunks/sdk-CU9i-NwD.js";
4
4
  const s = v(function({ src: u, className: b, style: S, onReady: g, ...e }, f) {
5
5
  const l = o(null), c = o(null), n = o(e);
6
6
  n.current = e;
@@ -0,0 +1,3 @@
1
+ import type { Editor } from './editor';
2
+ export declare function editLink(editor: Editor): void;
3
+ export declare function editStyle(editor: Editor, update?: boolean): void;
@@ -11,7 +11,7 @@ import type { Command } from './editor';
11
11
  */
12
12
  export declare const FONTS: string[];
13
13
  export declare const SIZES: number[];
14
- /** Quatre traits, décalés selon l'alignement — l'icône de Word, en SVG. */
14
+ /** Alignment uses the same optical grid as the other ribbon actions. */
15
15
  export declare function alignIcon(align: string): SVGElement;
16
16
  /**
17
17
  * Insere une variable au curseur, choisie dans la bibliotheque du document.
@@ -0,0 +1,4 @@
1
+ import type { Comment } from './comments';
2
+ import type { Editor } from './editor';
3
+ /** Comments use the same scoped popover and command path as the ribbon. */
4
+ export declare function editComment(editor: Editor, existing?: Comment, author?: string): void;
@@ -1,24 +1,2 @@
1
- /**
2
- * Word's comments, and where they sit in the text.
3
- *
4
- * `word/comments.xml` holds the comments; the body marks each range with
5
- * `w:commentRangeStart` / `w:commentRangeEnd` between the runs. The offsets
6
- * are counted the way `paragraphText` counts — `w:t` text, a tab, a break —
7
- * so a comment's range is addressable by the editor like any selection.
8
- */
9
- import { type DocxDocument } from '../../docx-model/src/index';
10
- export interface Comment {
11
- id: string;
12
- author: string;
13
- date?: string;
14
- text: string;
15
- }
16
- export interface CommentRange extends Comment {
17
- para: number;
18
- from: number;
19
- to: number;
20
- }
21
- /** The comments, in the order comments.xml declares them. */
22
- export declare function commentsOf(doc: DocxDocument): Comment[];
23
- /** Each comment with its range in the body — a comment whose range is not in the flow is left out. */
24
- export declare function commentRanges(doc: DocxDocument): CommentRange[];
1
+ export { commentsOf, commentRanges } from '../../docx-model/src/index';
2
+ export type { Comment, CommentRange } from '../../docx-model/src/index';
@@ -1,5 +1,5 @@
1
1
  import { type CellPatch, type MarginPatch, type DocViews, type DocxDocument, type DocPos, type EditContext, type PageSetup, type PageSetupPatch, type ParaPatch, type RunPatch } from '../../docx-model/src/index';
2
- import { type ImageRect, type LineTrace, type MarkRect, type ResumeState, type SelRect, type TableRect } from '../../docx-render/src/index';
2
+ import { type ImageRect, type LineTrace, type MarkRect, type ResumeState, type SelRect, type TableRect, type CellRect } from '../../docx-render/src/index';
3
3
  export interface EditorHooks {
4
4
  /** appelé après chaque composition, avec ce qu'il faut pour la barre d'outils */
5
5
  onContext?(ctx: EditContext | null, hasSelection: boolean): void;
@@ -19,6 +19,7 @@ export interface ComposeOut {
19
19
  * peindre : c'est l'hôte qui vient poser dedans. Voir extensions.md.
20
20
  */
21
21
  mark(r: MarkRect): void;
22
+ cell(r: CellRect): void;
22
23
  }
23
24
  /** Ce que l'hôte fournit : comment composer le document, et où. */
24
25
  export interface EditorSetup {
@@ -117,6 +118,15 @@ export declare function createEditor(setup: EditorSetup): {
117
118
  width: number;
118
119
  height: number;
119
120
  }[];
121
+ cellRects: () => {
122
+ para: number;
123
+ page: number;
124
+ x: number;
125
+ y: number;
126
+ width: number;
127
+ height: number;
128
+ }[];
129
+ selectedCells: () => number[];
120
130
  /** Objet sélectionné — une image ou un tableau pris comme un tout, ou `null`. */
121
131
  selectedObject: () => {
122
132
  kind: "image";
@@ -169,12 +179,21 @@ export declare function createEditor(setup: EditorSetup): {
169
179
  from: number;
170
180
  to: number;
171
181
  } | null;
182
+ addComment(text: string, author?: string): string | null;
183
+ updateComment: (id: string, text: string) => boolean;
184
+ deleteComment: (id: string) => boolean;
185
+ defineStyle(name: string, id?: string): string | null;
186
+ link: () => string | null;
187
+ setLink(target: string | null): boolean;
188
+ setListLevel(level: number): void;
189
+ restartList(start?: number): boolean;
172
190
  setList(ordered: boolean | null): void;
191
+ clearTableBorders(): boolean;
173
192
  formatCell(patch: CellPatch): boolean;
174
193
  mergeNextCell(): boolean;
175
194
  replaceAll(query: string, replacement: string, matchCase?: boolean): number;
176
195
  /** Insère du texte au curseur, ou remplace la sélection. */
177
- insert: (text: string) => void;
196
+ insert: (text: string, patch?: RunPatch) => void;
178
197
  deleteSelection: () => void;
179
198
  deleteObject: () => void;
180
199
  splitAtCaret: () => void;
@@ -262,7 +281,7 @@ export type Editor = ReturnType<typeof createEditor>;
262
281
  * déplacement du curseur, `render` après chaque composition, `context` avec
263
282
  * l'état complet sous le curseur, `commands` quand le registre bouge.
264
283
  */
265
- export type EditorEvent = 'change' | 'selection' | 'render' | 'context' | 'commands' | 'load' | 'save' | 'command';
284
+ export type EditorEvent = 'change' | 'selection' | 'render' | 'context' | 'commands' | 'styles' | 'load' | 'save' | 'command';
266
285
  /**
267
286
  * Une commande ajoutée par l'hôte ou par une extension.
268
287
  *
@@ -1,4 +1,4 @@
1
- import type { PastedBlock } from '../../docx-model/src/index';
1
+ import type { PastedBlock, PastedRun, RunPatch } from '../../docx-model/src/index';
2
2
  /** Décode une URI `data:` en octets, ou rend `null` si ce n'en est pas une. */
3
3
  export declare function dataUri(src: string): {
4
4
  data: Uint8Array;
@@ -10,4 +10,5 @@ export declare function dataUri(src: string): {
10
10
  * Les espaces sont normalisées comme le ferait un navigateur — le HTML de Word
11
11
  * est plein de retours à la ligne et d'indentation qui ne sont pas du texte.
12
12
  */
13
- export declare function htmlToBlocks(html: string): PastedBlock[];
13
+ export declare function htmlToBlocks(html: string, baseStyle?: RunPatch): PastedBlock[];
14
+ export declare function runsToHtml(paragraphs: PastedRun[][]): string;
@@ -64,6 +64,8 @@ export interface DocxEditorOptions {
64
64
  panel?: Panel | null;
65
65
  /** the fields and snippets the application offers, beyond what the document already uses */
66
66
  library?: LibraryExtras;
67
+ /** Optional host loader, called once per editor; the host owns the route and authentication. */
68
+ loadLibrary?: () => Promise<unknown>;
67
69
  /** show Word's comments as marks on the text (default true) */
68
70
  comments?: boolean;
69
71
  /** Opt-in feedback button: true exports JSON; onSubmit routes the report to the host. */
@@ -105,6 +107,9 @@ export interface DocxEditorHandle {
105
107
  openFeedback(): void;
106
108
  /** Word's comments of the open document, with their ranges */
107
109
  comments(): CommentRange[];
110
+ addComment(text: string, author?: string): string | null;
111
+ updateComment(id: string, text: string): boolean;
112
+ deleteComment(id: string): boolean;
108
113
  showComments(on: boolean): void;
109
114
  variables: {
110
115
  tags(): Tag[];
@@ -8,8 +8,7 @@ import type { Tag } from '../../docx-tags/src/index';
8
8
  *
9
9
  * - **dans un tag ouvert** (`{{` ou `{%` sans fermeture avant le curseur) :
10
10
  * champs et fonctions, c'est-à-dire ce qui a le droit d'y figurer ;
11
- * - **après un `/` en début de mot** : les extraits, comme partout ailleurs
12
- * depuis que Notion en a fait une convention.
11
+ * - **après un `/` en début de mot** : champs, fonctions et extraits.
13
12
  *
14
13
  * Le clavier passe AVANT l'éditeur : la capture est posée sur le champ de
15
14
  * frappe, et les flèches, Entrée, Tab et Échap ne redescendent pas jusqu'à lui
@@ -30,7 +29,7 @@ export interface CompleteHost {
30
29
  off: number;
31
30
  } | null;
32
31
  /** Remplace une plage du paragraphe courant par ce texte. */
33
- replace(para: number, from: number, to: number, text: string): void;
32
+ replace(para: number, from: number, to: number, text: string, caretOffset?: number): void;
34
33
  /** Where to hang the list; by default under the page's caret. */
35
34
  anchor?(): DOMRect | undefined;
36
35
  }
@@ -51,6 +50,7 @@ interface Context {
51
50
  kinds: LibEntry['kind'][];
52
51
  /** ce qu'on insère : le code entier, ou seulement l'expression */
53
52
  as: 'code' | 'expr';
53
+ padded?: boolean;
54
54
  }
55
55
  /**
56
56
  * Lit le contexte de frappe autour du curseur.
@@ -23,13 +23,23 @@ export interface LibEntry {
23
23
  /** Ce qu'on met dans une expression, sans les accolades. */
24
24
  expr: string;
25
25
  desc?: string;
26
+ /** Example rendered value, such as RODET; informational metadata, separate from inserted code. */
27
+ output?: string;
28
+ tags?: string[];
29
+ deprecated?: boolean;
26
30
  }
27
31
  /** A field the host declares — what the matrix MAY use, beyond what it already does. */
28
32
  export interface LibraryField {
29
33
  /** `salarie.nom` */
30
34
  path: string;
35
+ /** Exact insertion text supplied by the variable catalog. */
36
+ copy?: string;
37
+ tags?: string[];
38
+ deprecated?: boolean;
31
39
  label?: string;
32
40
  desc?: string;
41
+ /** Example rendered value, such as RODET; informational metadata, separate from inserted code. */
42
+ output?: string;
33
43
  }
34
44
  /** A snippet the host declares — a whole block, ready to paste. */
35
45
  export interface LibrarySnippet {
@@ -38,6 +48,8 @@ export interface LibrarySnippet {
38
48
  code: string;
39
49
  category?: string;
40
50
  desc?: string;
51
+ /** Example rendered value, such as RODET; informational metadata, separate from inserted code. */
52
+ output?: string;
41
53
  }
42
54
  export interface LibraryExtras {
43
55
  fields?: LibraryField[];
@@ -45,6 +57,8 @@ export interface LibraryExtras {
45
57
  /** keep the built-in snippets next to the host's (default true) */
46
58
  builtinSnippets?: boolean;
47
59
  }
60
+ /** Validate host-loaded JSON before replacing any existing catalog entries. */
61
+ export declare function parseLibrary(data: unknown): LibraryExtras;
48
62
  /** Each editor supplies its own library. */
49
63
  export declare function libraryEntries(tags: Tag[], extras?: LibraryExtras): LibEntry[];
50
64
  /** Filtre sans accent ni casse — on cherche « majore », on trouve « Majoré ». */
@@ -35,6 +35,8 @@ export interface VarsPanel {
35
35
  show(tag: Tag | null): void;
36
36
  /** Ouvre la bibliothèque, sans tag. */
37
37
  library(): void;
38
+ /** Refresh catalog data without opening the panel or replacing the tag being edited. */
39
+ refreshLibrary(): void;
38
40
  current(): Tag | null;
39
41
  open(): boolean;
40
42
  destroy(): void;
@@ -0,0 +1,10 @@
1
+ import { type DocxDocument } from './index';
2
+ import { type DocPos } from './editor';
3
+ /** Create a paragraph style from the selection, or update an existing style to match it. */
4
+ export declare function defineParagraphStyle(doc: DocxDocument, at: DocPos, name: string, id?: string): string | null;
5
+ /** Read a link at the caret using the same inline address as its writer. */
6
+ export declare function hyperlinkTarget(doc: DocxDocument, at: DocPos): string | null;
7
+ /** Set or remove a hyperlink in one inline container without flattening its content. */
8
+ export declare function setHyperlink(doc: DocxDocument, a: DocPos, b: DocPos, target: string | null): boolean;
9
+ /** Restart from this paragraph, keeping the following contiguous items in the same new list. */
10
+ export declare function restartList(doc: DocxDocument, at: DocPos, start?: number): number | null;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Word's comments, and where they sit in the text.
3
+ *
4
+ * `word/comments.xml` holds the comments; the body marks each range with
5
+ * `w:commentRangeStart` / `w:commentRangeEnd` between the runs. The offsets
6
+ * are counted the way `paragraphText` counts — `w:t` text, a tab, a break —
7
+ * so a comment's range is addressable by the editor like any selection.
8
+ */
9
+ import { type DocxDocument } from './index';
10
+ import { type DocPos } from './editor';
11
+ export interface Comment {
12
+ id: string;
13
+ author: string;
14
+ date?: string;
15
+ text: string;
16
+ }
17
+ export interface CommentRange extends Comment {
18
+ para: number;
19
+ from: number;
20
+ to: number;
21
+ }
22
+ /** The comments, in the order comments.xml declares them. */
23
+ export declare function commentsOf(doc: DocxDocument): Comment[];
24
+ /** Each comment with its range in the body — a comment whose range is not in the flow is left out. */
25
+ export declare function commentRanges(doc: DocxDocument): CommentRange[];
26
+ /** Add a classic Word comment to a nonempty body selection, keeping existing parts intact. */
27
+ export declare function addComment(doc: DocxDocument, a: DocPos, b: DocPos, text: string, author?: string): string | null;
28
+ export declare function updateComment(doc: DocxDocument, id: string, text: string): boolean;
29
+ /** Remove this comment's definition and anchors; unrelated annotations remain intact. */
30
+ export declare function deleteComment(doc: DocxDocument, id: string): boolean;
@@ -53,7 +53,7 @@ export declare function splitParagraph(doc: DocxDocument, pos: DocPos): DocPos |
53
53
  *
54
54
  * Renvoie la position de la soudure, là où le curseur doit rester.
55
55
  */
56
- export declare function joinParagraph(doc: DocxDocument, para: number): DocPos | null;
56
+ export declare function joinParagraph(doc: DocxDocument, para: number, part?: string): DocPos | null;
57
57
  /**
58
58
  * Insère un tableau vide au caret en coupant le paragraphe en deux.
59
59
  *
@@ -294,6 +294,8 @@ export interface CellPatch {
294
294
  borderPt?: number;
295
295
  borderColor?: string;
296
296
  }
297
+ /** Explicit nil borders suppress style inheritance; nested tables keep their own grid. */
298
+ export declare function clearTableBorders(doc: DocxDocument, para: number): boolean;
297
299
  export declare function formatCell(doc: DocxDocument, para: number, patch: CellPatch): boolean;
298
300
  /** Merge with the next cell without dropping its paragraphs. Vertical merges are protected. */
299
301
  export declare function mergeNextCell(doc: DocxDocument, para: number): boolean;
@@ -112,3 +112,5 @@ export * from './insert';
112
112
  export * from './paste';
113
113
  export * from './fonts';
114
114
  export * from './textbox';
115
+ export * from './comments';
116
+ export * from './authoring';
@@ -1,5 +1,12 @@
1
- import { type DocxDocument } from './index';
1
+ import { type DocxDocument, type XmlNode } from './index';
2
2
  import { type DocPos, type RunPatch } from './editor';
3
+ /** Prochain identifiant de relation libre pour une part. */
4
+ export declare function nextRelId(rels: XmlNode[]): string;
5
+ /** Le tableau des relations d'une part, créé s'il n'existe pas. */
6
+ export declare function relsOf(doc: DocxDocument, part: string): {
7
+ path: string;
8
+ list: XmlNode[];
9
+ };
3
10
  export interface InsertedImage {
4
11
  /** où le curseur se retrouve, après l'image */
5
12
  pos: DocPos;
@@ -30,6 +30,12 @@ export type PastedBlock = {
30
30
  widthPt: number;
31
31
  heightPt: number;
32
32
  };
33
+ /** Déclare une part dans `[Content_Types].xml` par son chemin. */
34
+ export declare function ensureOverride(doc: DocxDocument, part: string, mime: string): void;
35
+ /** Relation du document vers une part interne, créée si elle manque. */
36
+ export declare function ensureRel(doc: DocxDocument, type: string, target: string): void;
37
+ /** Add a missing level to this list instance without changing other lists' abstract definitions. */
38
+ export declare function ensureListLevel(doc: DocxDocument, numId: number, level: number): boolean;
33
39
  /**
34
40
  * Un `w:numId` bon pour une liste collée — trouvé, ou créé.
35
41
  *
@@ -49,6 +49,8 @@ export interface RunSpan {
49
49
  start: number;
50
50
  end: number;
51
51
  }
52
+ /** Keep zero-width markup and objects between text runs when replacing their text. */
53
+ export declare function interveningMarkup(first: RunSpan, last: RunSpan): XmlNode[];
52
54
  /**
53
55
  * Découpe un paragraphe en runs adressables, dans l'ordre de lecture.
54
56
  *
@@ -2,7 +2,7 @@ export { render } from './renderer';
2
2
  export { PT_PX } from './types';
3
3
  export { decodeImage, preloadImages } from './images';
4
4
  export type { RenderInput, RenderOptions, ResumeState } from './render-api';
5
- export type { BreakTrace, ImageMap, ImageRect, LineTrace, MarkRect, PlacedTextBox, RowTrace, RuleTrace, SectionParts, TableRect, } from './types';
5
+ export type { BreakTrace, ImageMap, ImageRect, LineTrace, MarkRect, PlacedTextBox, RowTrace, RuleTrace, SectionParts, TableRect, CellRect, } from './types';
6
6
  export { caretAt, editableLines, hitTest, ordered, paraRange, samePos, selectionRects, verticalStep, } from './hit';
7
7
  export type { CaretRect, DocPos, HitMode, SelRect } from './hit';
8
8
  export { buildRenderInput, footnoteContent, partParagraphs, styleParagraphs } from './document';
@@ -1,6 +1,6 @@
1
1
  import type { BodyBlock, ListInfo, PageSetup, StyledParagraph, TableInfo } from '../../docx-model/src/index';
2
2
  import type { SideWrap } from './floating';
3
- import type { BreakTrace, Footnotes, ImageMap, ImageRect, LineTrace, MarkRect, PlacedTextBox, RowTrace, RuleTrace, SectionParts, TableRect } from './types';
3
+ import type { BreakTrace, Footnotes, ImageMap, ImageRect, LineTrace, MarkRect, PlacedTextBox, RowTrace, RuleTrace, SectionParts, TableRect, CellRect } from './types';
4
4
  /**
5
5
  * Public input of the document compositor.
6
6
  *
@@ -39,6 +39,7 @@ export interface RenderOptions {
39
39
  onLine?(line: LineTrace): void;
40
40
  onImage?(rect: ImageRect): void;
41
41
  onTable?(rect: TableRect): void;
42
+ onCell?(rect: CellRect): void;
42
43
  /** Include empty lines in traces (needed by the editor, not the bench). */
43
44
  traceEmpty?: boolean;
44
45
  onRule?(rule: RuleTrace): void;
@@ -136,6 +136,7 @@ export interface DrawCtx {
136
136
  onLine?(line: LineTrace): void;
137
137
  /** publie le rectangle de chaque image dessinée — la souris n'a que ça */
138
138
  onImage?(rect: ImageRect): void;
139
+ onCell?(rect: CellRect): void;
139
140
  /** Internal content tracking, independent of public traces and bitmap decoding.
140
141
  * Wire only into real body/cell paint contexts, never speculative probes. */
141
142
  onContent?(page: number): void;
@@ -353,6 +354,12 @@ export interface Footnotes {
353
354
  }>;
354
355
  }
355
356
  export interface LineTrace {
357
+ /** Editing bounds include whitespace omitted from the ink trace. */
358
+ caretRange?: {
359
+ from: number;
360
+ to: number;
361
+ endX: number;
362
+ };
356
363
  /**
357
364
  * Index du BLOC dont vient cette ligne.
358
365
  *
@@ -479,6 +486,15 @@ export interface TableRect {
479
486
  width: number;
480
487
  height: number;
481
488
  }
489
+ /** A cell fragment on one page, addressed by its first body paragraph. */
490
+ export interface CellRect {
491
+ para: number;
492
+ page: number;
493
+ x: number;
494
+ y: number;
495
+ width: number;
496
+ height: number;
497
+ }
482
498
  /** Rectangle dessiné pour un run marqué, en px CSS relatifs à sa page. */
483
499
  export interface MarkRect {
484
500
  mark: string;
@@ -18,6 +18,7 @@ export declare const DIRECTIVES: {
18
18
  readonly 'inline-section': "open";
19
19
  readonly 'style-section': "open";
20
20
  readonly 'else-section': "middle";
21
+ readonly 'else-if-section': "middle";
21
22
  readonly 'end-section': "close";
22
23
  readonly 'table-start': "open";
23
24
  readonly 'table-end': "close";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "myrole-docx-editor",
3
- "version": "0.1.5",
3
+ "version": "0.3.0",
4
4
  "description": "Word-faithful .docx editor and renderer on canvas — the MyRole engine as an embeddable SDK, with a React component.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -48,8 +48,8 @@
48
48
  "@myrole/docx-model": "0.0.0",
49
49
  "@myrole/docx-render": "0.0.0",
50
50
  "@myrole/docx-tags": "0.0.0",
51
- "@myrole/fonts": "0.1.0",
52
- "@myrole/docx-vars": "0.0.0"
51
+ "@myrole/docx-vars": "0.0.0",
52
+ "@myrole/fonts": "0.1.0"
53
53
  },
54
54
  "publishConfig": {
55
55
  "access": "public"
@@ -57,6 +57,7 @@
57
57
  "scripts": {
58
58
  "fonts": "node scripts/pack-fonts.mjs",
59
59
  "build": "node scripts/pack-fonts.mjs && vite build && node scripts/types.mjs",
60
+ "watch": "vite build --watch",
60
61
  "check": "node scripts/pack-fonts.mjs && tsc -p tsconfig.json && tsx scripts/locking.test.ts",
61
62
  "types": "node scripts/types.mjs"
62
63
  },