myrole-docx-editor 0.1.4 → 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 CHANGED
@@ -87,6 +87,8 @@ editor.setZoom(1.25) editor.setTheme('dark') editor.setRead
87
87
  editor.showPanel('variables') editor.fileName('contrat.docx') editor.pages()
88
88
  editor.variables.tags() editor.variables.preview(true, values)
89
89
  editor.comments() editor.showComments(false)
90
+ editor.addComment('Review', 'Author') // nonempty body selection → ID or null
91
+ editor.updateComment(id, 'Updated') editor.deleteComment(id)
90
92
  editor.on('change' | 'selection' | 'render' | 'save' | 'load' | 'zoom', fn)
91
93
  await editor.saveNow() editor.isDirty() editor.saveState()
92
94
  editor.fitZoom('width') // or 'page'; follows host resizing
@@ -106,6 +108,34 @@ overrides covering more than half the paragraph, preserving local emphasis,
106
108
  character styles and structural XML. `styleId: null` restores the document's
107
109
  default style; `'Normal'` selects that named style. Unknown IDs are ignored.
108
110
 
111
+ ```ts
112
+ const editing = editor.editor
113
+ if (!editing) throw new Error('Load a document first')
114
+ editing.selectRange({ para: 2, off: 0 }, { para: 2, off: 8 })
115
+ editing.setLink('https://example.org') // selected text; null removes the current link
116
+ const styleId = editing.defineStyle('My heading') // create and apply from the selection
117
+ if (styleId) editing.defineStyle('My heading', styleId) // update the same style
118
+ editing.setList(true) // numbered; false for bullets; null removes it
119
+ editing.setListLevel(1) // levels 0–8
120
+ editing.restartList(1) // body list, from the current item
121
+ editing.undo()
122
+ ```
123
+
124
+ These actions are also available in the ribbon and refuse edits in read-only
125
+ mode. Comments, styles, links and numbering definitions participate in undo/redo,
126
+ including their package relationships. Classic comments support creation on a
127
+ nonempty body range, editing and deletion, without threaded replies or resolution.
128
+ Documents with extended/threaded comment metadata remain readable; their comment
129
+ writes are refused to preserve the linked metadata.
130
+ Links support HTTP(S), mailto and `#bookmark`, within one paragraph and inline
131
+ container. Styles created here are paragraph styles. List restart currently
132
+ requires a body list with direct numbering properties.
133
+
134
+ Header/footer addresses use `{ para, off, part: 'word/header1.xml' }` (or the
135
+ actual part name). Enter, Backspace/Delete and range deletion stay in that part;
136
+ undo retains the story. Splitting inside a complex field, revision or content
137
+ control is refused without altering the document.
138
+
109
139
  ## Display and context actions
110
140
 
111
141
  **Document brut**, under **Affichage** and **Réglages**, shows the original
@@ -189,3 +219,32 @@ const { pages } = await renderDocx(url, hiddenDiv) // HTMLCanvasElement[]
189
219
 
190
220
  `pnpm build` writes `dist/` (ESM, one chunk per entry, types) and packs the
191
221
  fonts. CI publishes on a `v*` tag; see `.gitlab-ci.yml` at the repository root.
222
+
223
+ ## Exclusive editing
224
+
225
+ An optional `lock` adapter supplies `acquire(sessionId)`, `renew(sessionId)`,
226
+ `release(sessionId)` and `read(sessionId)`. Acquire and renew return
227
+ `{ acquired: true, ttlMs }` or `{ acquired: false, owner?: string }`. Read returns
228
+ fresh `Uint8Array` document bytes after acquisition. Configure one adapter per
229
+ document and remount the editor when the document identity changes.
230
+
231
+ ```tsx
232
+ <DocxEditor
233
+ src={initialDocument}
234
+ lock={documentLockAdapter}
235
+ onSave={(bytes, {lockId}) => saveWithVerifiedLock(bytes, lockId)}
236
+ onLockState={state => console.log(state.status)}
237
+ />
238
+ ```
239
+
240
+ The SDK stays read-only until ownership is confirmed, renews the lease, retries
241
+ occupied sessions and suspends editing on connection loss or expiration. The
242
+ server must reject every write without a valid lease; a `409` error thrown from
243
+ `onSave` also suspends editing. The banner identifies the blocking user, offers
244
+ retry and finishes the session with save-before-release. Unsaved changes survive
245
+ a lost lease in the open editor and can be downloaded for recovery.
246
+
247
+ `editor.lock` exposes `state()`, `acquire()` and `release()` (or is `null` when
248
+ locking is disabled). `destroy()` attempts final saving and release; the server
249
+ must expire abandoned sessions because browser shutdown is not reliable.
250
+ Read-only viewers acquire nothing. React exports `DOCX_LOCKING_VERSION = 1`.