myrole-docx-editor 0.1.1 → 0.1.3

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 (72) hide show
  1. package/README.md +81 -8
  2. package/dist/chunks/sdk-BKmEus_j.js +29652 -0
  3. package/dist/chunks/sdk-BKmEus_j.js.map +1 -0
  4. package/dist/chunks/{vars-blockly-D5Kxd1XI.js → vars-blockly-DMblR7c7.js} +2 -2
  5. package/dist/chunks/{vars-blockly-D5Kxd1XI.js.map → vars-blockly-DMblR7c7.js.map} +1 -1
  6. package/dist/index.js +23 -43
  7. package/dist/index.js.map +1 -1
  8. package/dist/react.js +44 -28
  9. package/dist/react.js.map +1 -1
  10. package/dist/types/packages/docx-editor/src/chrome.d.ts +11 -0
  11. package/dist/types/packages/docx-editor/src/commands.d.ts +8 -1
  12. package/dist/types/packages/docx-editor/src/drafts.d.ts +7 -0
  13. package/dist/types/packages/docx-editor/src/editor.d.ts +21 -3
  14. package/dist/types/packages/docx-editor/src/feedback.d.ts +73 -0
  15. package/dist/types/packages/docx-editor/src/fonts.d.ts +1 -1
  16. package/dist/types/packages/docx-editor/src/index.d.ts +5 -0
  17. package/dist/types/packages/docx-editor/src/inspector-ui.d.ts +2 -2
  18. package/dist/types/packages/docx-editor/src/react.d.ts +2 -0
  19. package/dist/types/packages/docx-editor/src/ruler.d.ts +1 -0
  20. package/dist/types/packages/docx-editor/src/sdk.d.ts +37 -8
  21. package/dist/types/packages/docx-editor/src/ui/context-menu.d.ts +4 -0
  22. package/dist/types/packages/docx-editor/src/ui/panels.d.ts +13 -0
  23. package/dist/types/packages/docx-editor/src/ui/popover.d.ts +4 -0
  24. package/dist/types/packages/docx-editor/src/ui/shell.d.ts +10 -1
  25. package/dist/types/packages/docx-editor/src/variables.d.ts +7 -0
  26. package/dist/types/packages/docx-editor/src/vars-complete.d.ts +4 -1
  27. package/dist/types/packages/docx-editor/src/vars-library.d.ts +2 -2
  28. package/dist/types/packages/docx-editor/src/vars-panel.d.ts +4 -0
  29. package/dist/types/packages/docx-model/src/editor.d.ts +46 -1
  30. package/dist/types/packages/docx-model/src/index.d.ts +1 -0
  31. package/dist/types/packages/docx-model/src/layout.d.ts +41 -0
  32. package/dist/types/packages/docx-model/src/tables.d.ts +16 -0
  33. package/dist/types/packages/docx-model/src/textbox.d.ts +27 -0
  34. package/dist/types/packages/docx-render/src/block-layout.d.ts +49 -0
  35. package/dist/types/packages/docx-render/src/body-context.d.ts +23 -0
  36. package/dist/types/packages/docx-render/src/body-flow.d.ts +28 -0
  37. package/dist/types/packages/docx-render/src/canvas-page.d.ts +18 -0
  38. package/dist/types/packages/docx-render/src/checkpoints.d.ts +22 -0
  39. package/dist/types/packages/docx-render/src/columns.d.ts +27 -0
  40. package/dist/types/packages/docx-render/src/document.d.ts +1 -1
  41. package/dist/types/packages/docx-render/src/floating.d.ts +25 -0
  42. package/dist/types/packages/docx-render/src/footnotes.d.ts +40 -0
  43. package/dist/types/packages/docx-render/src/hyphenation.d.ts +9 -0
  44. package/dist/types/packages/docx-render/src/images.d.ts +19 -0
  45. package/dist/types/packages/docx-render/src/index.d.ts +3 -2
  46. package/dist/types/packages/docx-render/src/metrics.d.ts +21 -1
  47. package/dist/types/packages/docx-render/src/page-flow.d.ts +68 -0
  48. package/dist/types/packages/docx-render/src/page-parts.d.ts +19 -0
  49. package/dist/types/packages/docx-render/src/pagination.d.ts +55 -0
  50. package/dist/types/packages/docx-render/src/paragraph.d.ts +13 -4
  51. package/dist/types/packages/docx-render/src/parts.d.ts +7 -3
  52. package/dist/types/packages/docx-render/src/render-api.d.ts +106 -0
  53. package/dist/types/packages/docx-render/src/render-output.d.ts +28 -0
  54. package/dist/types/packages/docx-render/src/renderer.d.ts +24 -247
  55. package/dist/types/packages/docx-render/src/section-layout.d.ts +62 -0
  56. package/dist/types/packages/docx-render/src/text-box.d.ts +10 -0
  57. package/dist/types/packages/docx-render/src/text.d.ts +38 -12
  58. package/dist/types/packages/docx-render/src/types.d.ts +86 -8
  59. package/dist/types/packages/docx-vars/src/target-canvas.d.ts +17 -0
  60. package/dist/types/packages/fonts/src/families.d.ts +1 -1
  61. package/fonts/ttf/daytona-400-italic.ttf +0 -0
  62. package/fonts/ttf/daytona-400-normal.ttf +0 -0
  63. package/fonts/ttf/daytona-700-italic.ttf +0 -0
  64. package/fonts/ttf/daytona-700-normal.ttf +0 -0
  65. package/fonts/ttf/hind-siliguri-400-normal.ttf +0 -0
  66. package/fonts/ttf/hind-siliguri-700-normal.ttf +0 -0
  67. package/fonts/ttf/hind-siliguri-light-400-normal.ttf +0 -0
  68. package/fonts/ttf/hind-siliguri-medium-400-normal.ttf +0 -0
  69. package/fonts/ttf/hind-siliguri-semibold-700-normal.ttf +0 -0
  70. package/package.json +3 -3
  71. package/dist/chunks/sdk-B9yNSxFT.js +0 -15066
  72. package/dist/chunks/sdk-B9yNSxFT.js.map +0 -1
package/README.md CHANGED
@@ -14,13 +14,16 @@ pnpm add myrole-docx-editor
14
14
  import { createDocxEditor } from 'myrole-docx-editor'
15
15
 
16
16
  const editor = createDocxEditor(document.getElementById('app'), {
17
+ badges: false, // original {{ … }} and JSONata text
18
+ theme: 'light',
17
19
  onSave: (bytes) => upload(bytes), // called after a quiet period, and on tab change
18
20
  })
19
21
  await editor.load(file) // File, Blob, ArrayBuffer, Uint8Array or URL
20
22
  ```
21
23
 
22
24
  The container needs a height (`height: 100vh`, or a flex parent). The SDK
23
- injects its own stylesheet; nothing else to import.
25
+ injects its own scoped stylesheet; nothing else to import. Multiple instances
26
+ can coexist inside the same application. Call `destroy()` when unmounting.
24
27
 
25
28
  ## React
26
29
 
@@ -41,8 +44,9 @@ function Page({ file }) {
41
44
  }
42
45
  ```
43
46
 
44
- `src` changes reload the document in place; the other props are read at
45
- mount. `ref.current` is the same handle `createDocxEditor` returns.
47
+ `src` changes reload the document in place. Theme, read-only state, zoom and
48
+ badge display also respond to prop changes. `ref.current` is the same handle
49
+ `createDocxEditor` returns. `<DocxViewer>` is its read-only companion.
46
50
 
47
51
  ## Options
48
52
 
@@ -50,13 +54,17 @@ mount. `ref.current` is the same handle `createDocxEditor` returns.
50
54
  |---|---|---|
51
55
  | `chrome` | `'full'` | `'full'` ribbon, rulers, panels · `'viewer'` read-only pages under a slim header · `'none'` pages only |
52
56
  | `readOnly` | `false` | the caret moves and the selection copies, nothing edits |
53
- | `theme` | `'system'` | `'light'`, `'dark'`, `'system'` |
57
+ | `theme` | `'light'` | `'light'`, `'dark'`, `'system'` |
54
58
  | `fontsUrl` | next to the bundle | the directory that holds `ttf/` — see Fonts |
55
- | `onSave` | – | autosave target; the `.docx` bytes |
59
+ | `onSave` | – | async persistence callback; resolving acknowledges saved bytes |
60
+ | `onError`, `onSaveState` | – | save failures and state changes |
61
+ | `draftKey` | – | opt-in IndexedDB recovery; unique per user/document |
62
+ | `saveDelay` | `2000` | autosave debounce in milliseconds |
63
+ | `badges` | `true` | `false` for raw document text, or `{ variables, expressions }` |
56
64
  | `onChange`, `onReady` | – | |
57
65
  | `zoom` | `1` | |
58
66
  | `rulers`, `statusBar` | `true` | |
59
- | `panel` | `null` | open on `'variables'` or `'inspector'` |
67
+ | `panel` | `null` | `'navigation'`, `'properties'`, `'variables'` or `'inspector'` |
60
68
  | `values` | sample set | values for the generated-document preview |
61
69
  | `library` | – | `{ fields: [{ path, label?, desc? }], snippets: [{ id, title, code, category?, desc? }], builtinSnippets? }` — offered in the Bibliothèque panel, the ribbon's Variable button and the autocompletion, before what the document already uses |
62
70
  | `comments` | `true` | Word's comments as marks on the text; click one for its balloon; « Commentaires » on the Affichage tab toggles them |
@@ -73,6 +81,10 @@ editor.showPanel('variables') editor.fileName('contrat.docx') editor.pages()
73
81
  editor.variables.tags() editor.variables.preview(true, values)
74
82
  editor.comments() editor.showComments(false)
75
83
  editor.on('change' | 'selection' | 'render' | 'save' | 'load' | 'zoom', fn)
84
+ await editor.saveNow() editor.isDirty() editor.saveState()
85
+ editor.fitZoom('width') // or 'page'; follows host resizing
86
+ editor.variables.setDisplay(false) // source text without variable/function badges
87
+ await editor.getDraft() await editor.restoreDraft() await editor.discardDraft()
76
88
  editor.destroy()
77
89
  ```
78
90
 
@@ -81,11 +93,72 @@ adds a ribbon button, `registerDecorations` adds marks anchored to text,
81
93
  `format` / `formatPara` / `setMargins` / `table` / `insertImage` edit the
82
94
  model, `undo` / `redo` / `save` do what they say.
83
95
 
96
+ `formatPara({ styleId: 'Heading1' })` applies an existing paragraph style to
97
+ the selected paragraphs. It resets direct paragraph formatting and character
98
+ overrides covering more than half the paragraph, preserving local emphasis,
99
+ character styles and structural XML. `styleId: null` restores the document's
100
+ default style; `'Normal'` selects that named style. Unknown IDs are ignored.
101
+
102
+ ## Display and context actions
103
+
104
+ **Document brut**, under **Affichage** and **Réglages**, shows the original
105
+ variable/JSONata code without modifying the DOCX. Set `badges: false` to open
106
+ that way. The Variables tab also controls variable and expression badges
107
+ separately. Generated **Aperçu** evaluates tags and remains a separate mode.
108
+
109
+ The compact ribbon, heading/page navigation and properties pane adapt to the
110
+ component width. Right-click targets text, images, fields or table cells while
111
+ preserving a containing selection. It offers formatting, plain-text copy/cut,
112
+ rich/plain paste, image sizing, table actions, properties and undo. Shift+F10,
113
+ arrow keys and Escape operate the same menu. Browser clipboard restrictions
114
+ fall back to the usual keyboard shortcuts. Read-only commands stay disabled.
115
+
116
+ `save()` serializes bytes; `saveNow()` waits for persistence, including edits
117
+ made during an upload. Failures retain the dirty state. Without `onSave` or
118
+ `draftKey`, saving downloads a copy and retains the unsaved status. A draft is
119
+ written before upload and removed after success. Recovery is explicit through
120
+ `restoreDraft()`; save before destroying if the host needs upload completion.
121
+ An unsaved document without persistence blocks `load()`; callers may explicitly
122
+ allow replacement using `load(source, { discardChanges: true })`.
123
+
124
+ ## User feedback
125
+
126
+ Enable **Signaler un manque** with `feedback: true` to export a JSON report locally,
127
+ or provide a submission callback:
128
+
129
+ ```ts
130
+ createDocxEditor(el, {
131
+ feedback: {
132
+ onSubmit: async report => {
133
+ const response = await fetch('/api/feedback', {
134
+ method: 'POST', headers: { 'Content-Type': 'application/json' },
135
+ body: JSON.stringify(report),
136
+ })
137
+ if (!response.ok) throw new Error('Feedback submission failed')
138
+ },
139
+ },
140
+ })
141
+ ```
142
+
143
+ The form freezes the file name, visible canvas pages, selection and variable
144
+ badges when opened. Users describe their goal, missing feature and optional
145
+ workaround, and may remove the PNG screenshot. Context includes SDK/browser
146
+ versions, zoom, page/selection positions, display mode and the last 20 SDK
147
+ events. No DOCX bytes, selected text, preview values or global console logs are
148
+ collected; the screenshot can contain visible document text. Submission failures
149
+ keep the form available for retry and notify `onError`.
150
+
151
+ Feedback is opt-in. `editor.openFeedback()` opens the same form for custom chrome,
152
+ after loading a document. React accepts the same `feedback` option. Import
153
+ `FeedbackReport`, `FeedbackContext` and `FeedbackOptions` from the package for
154
+ typed integrations. The host owns authentication and storage; the SDK sends no
155
+ network request itself.
156
+
84
157
  ## Fonts
85
158
 
86
- The engine measures with 219 subset faces shipped under `fonts/ttf/`
159
+ The engine measures with 228 subset faces shipped under `fonts/ttf/`
87
160
  (33 MB, loaded on demand). They are declared at runtime from
88
- `fontsUrl`, which defaults to `fonts/` next to the bundle. If your bundler
161
+ `fontsUrl`, which defaults to the package’s `fonts/` directory. If your bundler
89
162
  does not keep that directory next to the output, serve it yourself:
90
163
 
91
164
  ```ts