myrole-docx-editor 0.1.2 → 0.1.4
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 +88 -8
- package/dist/chunks/sdk-DZeo_8qT.js +29664 -0
- package/dist/chunks/sdk-DZeo_8qT.js.map +1 -0
- package/dist/chunks/{vars-blockly-C-0oL-Mc.js → vars-blockly-EQQZFx30.js} +2 -2
- package/dist/chunks/{vars-blockly-C-0oL-Mc.js.map → vars-blockly-EQQZFx30.js.map} +1 -1
- package/dist/index.js +8 -7
- package/dist/react.js +44 -28
- package/dist/react.js.map +1 -1
- package/dist/types/packages/docx-editor/src/chrome.d.ts +11 -0
- package/dist/types/packages/docx-editor/src/commands.d.ts +8 -1
- package/dist/types/packages/docx-editor/src/drafts.d.ts +7 -0
- package/dist/types/packages/docx-editor/src/editor.d.ts +17 -3
- package/dist/types/packages/docx-editor/src/feedback.d.ts +73 -0
- package/dist/types/packages/docx-editor/src/index.d.ts +6 -1
- package/dist/types/packages/docx-editor/src/inspector-ui.d.ts +2 -2
- package/dist/types/packages/docx-editor/src/react.d.ts +2 -0
- package/dist/types/packages/docx-editor/src/ruler.d.ts +1 -0
- package/dist/types/packages/docx-editor/src/sdk.d.ts +39 -8
- package/dist/types/packages/docx-editor/src/ui/context-menu.d.ts +4 -0
- package/dist/types/packages/docx-editor/src/ui/panels.d.ts +13 -0
- package/dist/types/packages/docx-editor/src/ui/popover.d.ts +4 -0
- package/dist/types/packages/docx-editor/src/ui/shell.d.ts +17 -1
- package/dist/types/packages/docx-editor/src/variables.d.ts +7 -0
- package/dist/types/packages/docx-editor/src/vars-complete.d.ts +4 -1
- package/dist/types/packages/docx-editor/src/vars-library.d.ts +2 -2
- package/dist/types/packages/docx-editor/src/vars-panel.d.ts +4 -0
- package/dist/types/packages/docx-model/src/editor.d.ts +21 -1
- package/dist/types/packages/docx-model/src/layout.d.ts +9 -0
- package/dist/types/packages/docx-model/src/textbox.d.ts +2 -0
- package/dist/types/packages/docx-render/src/hyphenation.d.ts +9 -0
- package/dist/types/packages/docx-render/src/text.d.ts +7 -0
- package/dist/types/packages/docx-render/src/types.d.ts +3 -0
- package/package.json +3 -3
- package/dist/chunks/sdk-CxT1eC2o.js +0 -16294
- package/dist/chunks/sdk-CxT1eC2o.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
|
|
45
|
-
|
|
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,18 @@ 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` | `'
|
|
57
|
+
| `theme` | `'light'` | `'light'`, `'dark'`, `'system'` |
|
|
54
58
|
| `fontsUrl` | next to the bundle | the directory that holds `ttf/` — see Fonts |
|
|
55
|
-
| `onSave` | – |
|
|
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` |
|
|
67
|
+
| `panel` | `null` | `'navigation'`, `'properties'`, `'variables'` or `'inspector'` |
|
|
68
|
+
| `ui` | all enabled | `{ open: false, export: false, sidePanel: false }` disables file opening, UI exports and right-side panels; configured at mount |
|
|
60
69
|
| `values` | sample set | values for the generated-document preview |
|
|
61
70
|
| `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
71
|
| `comments` | `true` | Word's comments as marks on the text; click one for its balloon; « Commentaires » on the Affichage tab toggles them |
|
|
@@ -64,6 +73,12 @@ mount. `ref.current` is the same handle `createDocxEditor` returns.
|
|
|
64
73
|
|
|
65
74
|
## Handle
|
|
66
75
|
|
|
76
|
+
`ui.sidePanel: false` keeps left-side navigation/search available and disables
|
|
77
|
+
right-panel entry points in the toolbar, ribbon, context menu and badges.
|
|
78
|
+
`ui.export: false` requires `onSave` or `draftKey` for Ctrl/⌘S; the host's
|
|
79
|
+
`load`, `save` and `download` APIs remain available. These options configure
|
|
80
|
+
the interface and do not replace server-side permissions.
|
|
81
|
+
|
|
67
82
|
```ts
|
|
68
83
|
editor.load(src) editor.save(): Uint8Array editor.download('contrat.docx')
|
|
69
84
|
editor.editor // the low-level editor: commands, selection, format, undo…
|
|
@@ -73,6 +88,10 @@ editor.showPanel('variables') editor.fileName('contrat.docx') editor.pages()
|
|
|
73
88
|
editor.variables.tags() editor.variables.preview(true, values)
|
|
74
89
|
editor.comments() editor.showComments(false)
|
|
75
90
|
editor.on('change' | 'selection' | 'render' | 'save' | 'load' | 'zoom', fn)
|
|
91
|
+
await editor.saveNow() editor.isDirty() editor.saveState()
|
|
92
|
+
editor.fitZoom('width') // or 'page'; follows host resizing
|
|
93
|
+
editor.variables.setDisplay(false) // source text without variable/function badges
|
|
94
|
+
await editor.getDraft() await editor.restoreDraft() await editor.discardDraft()
|
|
76
95
|
editor.destroy()
|
|
77
96
|
```
|
|
78
97
|
|
|
@@ -81,11 +100,72 @@ adds a ribbon button, `registerDecorations` adds marks anchored to text,
|
|
|
81
100
|
`format` / `formatPara` / `setMargins` / `table` / `insertImage` edit the
|
|
82
101
|
model, `undo` / `redo` / `save` do what they say.
|
|
83
102
|
|
|
103
|
+
`formatPara({ styleId: 'Heading1' })` applies an existing paragraph style to
|
|
104
|
+
the selected paragraphs. It resets direct paragraph formatting and character
|
|
105
|
+
overrides covering more than half the paragraph, preserving local emphasis,
|
|
106
|
+
character styles and structural XML. `styleId: null` restores the document's
|
|
107
|
+
default style; `'Normal'` selects that named style. Unknown IDs are ignored.
|
|
108
|
+
|
|
109
|
+
## Display and context actions
|
|
110
|
+
|
|
111
|
+
**Document brut**, under **Affichage** and **Réglages**, shows the original
|
|
112
|
+
variable/JSONata code without modifying the DOCX. Set `badges: false` to open
|
|
113
|
+
that way. The Variables tab also controls variable and expression badges
|
|
114
|
+
separately. Generated **Aperçu** evaluates tags and remains a separate mode.
|
|
115
|
+
|
|
116
|
+
The compact ribbon, heading/page navigation and properties pane adapt to the
|
|
117
|
+
component width. Right-click targets text, images, fields or table cells while
|
|
118
|
+
preserving a containing selection. It offers formatting, plain-text copy/cut,
|
|
119
|
+
rich/plain paste, image sizing, table actions, properties and undo. Shift+F10,
|
|
120
|
+
arrow keys and Escape operate the same menu. Browser clipboard restrictions
|
|
121
|
+
fall back to the usual keyboard shortcuts. Read-only commands stay disabled.
|
|
122
|
+
|
|
123
|
+
`save()` serializes bytes; `saveNow()` waits for persistence, including edits
|
|
124
|
+
made during an upload. Failures retain the dirty state. Without `onSave` or
|
|
125
|
+
`draftKey`, saving downloads a copy and retains the unsaved status. A draft is
|
|
126
|
+
written before upload and removed after success. Recovery is explicit through
|
|
127
|
+
`restoreDraft()`; save before destroying if the host needs upload completion.
|
|
128
|
+
An unsaved document without persistence blocks `load()`; callers may explicitly
|
|
129
|
+
allow replacement using `load(source, { discardChanges: true })`.
|
|
130
|
+
|
|
131
|
+
## User feedback
|
|
132
|
+
|
|
133
|
+
Enable **Signaler un manque** with `feedback: true` to export a JSON report locally,
|
|
134
|
+
or provide a submission callback:
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
createDocxEditor(el, {
|
|
138
|
+
feedback: {
|
|
139
|
+
onSubmit: async report => {
|
|
140
|
+
const response = await fetch('/api/feedback', {
|
|
141
|
+
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
|
142
|
+
body: JSON.stringify(report),
|
|
143
|
+
})
|
|
144
|
+
if (!response.ok) throw new Error('Feedback submission failed')
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
})
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The form freezes the file name, visible canvas pages, selection and variable
|
|
151
|
+
badges when opened. Users describe their goal, missing feature and optional
|
|
152
|
+
workaround, and may remove the PNG screenshot. Context includes SDK/browser
|
|
153
|
+
versions, zoom, page/selection positions, display mode and the last 20 SDK
|
|
154
|
+
events. No DOCX bytes, selected text, preview values or global console logs are
|
|
155
|
+
collected; the screenshot can contain visible document text. Submission failures
|
|
156
|
+
keep the form available for retry and notify `onError`.
|
|
157
|
+
|
|
158
|
+
Feedback is opt-in. `editor.openFeedback()` opens the same form for custom chrome,
|
|
159
|
+
after loading a document. React accepts the same `feedback` option. Import
|
|
160
|
+
`FeedbackReport`, `FeedbackContext` and `FeedbackOptions` from the package for
|
|
161
|
+
typed integrations. The host owns authentication and storage; the SDK sends no
|
|
162
|
+
network request itself.
|
|
163
|
+
|
|
84
164
|
## Fonts
|
|
85
165
|
|
|
86
|
-
The engine measures with
|
|
166
|
+
The engine measures with 228 subset faces shipped under `fonts/ttf/`
|
|
87
167
|
(33 MB, loaded on demand). They are declared at runtime from
|
|
88
|
-
`fontsUrl`, which defaults to `fonts/`
|
|
168
|
+
`fontsUrl`, which defaults to the package’s `fonts/` directory. If your bundler
|
|
89
169
|
does not keep that directory next to the output, serve it yourself:
|
|
90
170
|
|
|
91
171
|
```ts
|