@docx-editor.dev/pro 2.31.0 → 2.32.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 +24 -0
- package/dist/chunk-3WTOHPAB.js +1 -0
- package/dist/chunk-AVZO5ZHZ.js +1 -0
- package/dist/chunk-GAGYRL3L.js +5 -0
- package/dist/chunk-HMSOWKXT.js +1 -0
- package/dist/chunk-I6HVINA4.cjs +1 -0
- package/dist/chunk-MHB6ID2P.cjs +1 -0
- package/dist/chunk-PMS3PGOE.cjs +1 -0
- package/dist/chunk-YOWEY5F3.cjs +5 -0
- package/dist/collaboration/hocuspocus.cjs +1 -1
- package/dist/collaboration/hocuspocus.d.cts +3 -3
- package/dist/collaboration/hocuspocus.d.ts +3 -3
- package/dist/collaboration/hocuspocus.js +1 -1
- package/dist/collaboration/index.cjs +2 -2
- package/dist/collaboration/index.d.cts +63 -7
- package/dist/collaboration/index.d.ts +63 -7
- package/dist/collaboration/index.js +2 -2
- package/dist/collaboration/webrtc.cjs +1 -1
- package/dist/collaboration/webrtc.d.cts +3 -3
- package/dist/collaboration/webrtc.d.ts +3 -3
- package/dist/collaboration/webrtc.js +1 -1
- package/dist/{document-session-_v9vqiSX.d.cts → document-session-B-MlORjE.d.cts} +105 -9
- package/dist/{document-session-Bxs4_GgX.d.ts → document-session-B-iH-YCU.d.ts} +105 -9
- package/dist/document-session-B35ZX2W4.js +1 -0
- package/dist/document-session-V3O7XBJY.cjs +1 -0
- package/dist/{document-session-options-DelOC7PX.d.ts → document-session-options-CdOH-TNn.d.ts} +1 -1
- package/dist/{document-session-options-CfKypp9c.d.cts → document-session-options-CxR0F5xT.d.cts} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/react/hocuspocus.d.cts +2 -2
- package/dist/react/hocuspocus.d.ts +2 -2
- package/dist/react/index.cjs +2 -2
- package/dist/react/index.d.cts +95 -12
- package/dist/react/index.d.ts +95 -12
- package/dist/react/index.js +2 -2
- package/dist/react/webrtc.d.cts +2 -2
- package/dist/react/webrtc.d.ts +2 -2
- package/dist/{types-BQ1vBt5Q.d.ts → types-DvGpDOcZ.d.cts} +9 -1
- package/dist/{types-BQ1vBt5Q.d.cts → types-DvGpDOcZ.d.ts} +9 -1
- package/dist/{types-6EmrEn4n.d.cts → types-bt2k1VO0.d.cts} +9 -1
- package/dist/{types-6EmrEn4n.d.ts → types-bt2k1VO0.d.ts} +9 -1
- package/dist/vue/hocuspocus.d.cts +2 -2
- package/dist/vue/hocuspocus.d.ts +2 -2
- package/dist/vue/index.cjs +2 -2
- package/dist/vue/index.d.cts +89 -13
- package/dist/vue/index.d.ts +89 -13
- package/dist/vue/index.js +2 -2
- package/dist/vue/webrtc.d.cts +2 -2
- package/dist/vue/webrtc.d.ts +2 -2
- package/docs/accept-reject-without-scrolling.md +95 -0
- package/docs/comment-on-found-text.md +72 -0
- package/docs/custom-review-cards.md +178 -0
- package/docs/highlight-ranges.md +48 -0
- package/docs/index.md +36 -0
- package/docs/propose-rewrite.md +247 -0
- package/docs/tracked-replacement.md +68 -0
- package/package.json +5 -4
- package/dist/chunk-32WEH2XH.cjs +0 -1
- package/dist/chunk-FD2KDBHX.cjs +0 -1
- package/dist/chunk-L567WP3J.js +0 -5
- package/dist/chunk-MJECUVHQ.cjs +0 -5
- package/dist/chunk-Q5JTCGJI.js +0 -1
- package/dist/chunk-SNQCYZLT.js +0 -1
- package/dist/chunk-UOAEJRVX.js +0 -1
- package/dist/chunk-ZSAAX6HV.cjs +0 -1
- package/dist/document-session-3VC43WNI.cjs +0 -1
- package/dist/document-session-J2YKWERI.js +0 -1
package/README.md
CHANGED
|
@@ -130,6 +130,30 @@ Every value reaching `fromDocx` came out of a `.docx`, so treat `attrs` and `tex
|
|
|
130
130
|
|
|
131
131
|
`insertCustomNode`, `updateCustomNode`, and `removeCustomNode` author them from code, and `customNodeXml` builds the same content control on a server with no editor and no DOM.
|
|
132
132
|
|
|
133
|
+
## Which API for which job
|
|
134
|
+
|
|
135
|
+
| Job | Use |
|
|
136
|
+
| --- | --- |
|
|
137
|
+
| Build a review UI in the browser | The React or Vue adapter hooks, plus the review hooks and `DocxEditorReview` from `@docx-editor.dev/pro/react` or `@docx-editor.dev/pro/vue`. |
|
|
138
|
+
| Edit in a headless, server, or agent pipeline | The editing API in `@docx-editor.dev/editor-api`, which follows the Office.js object model. |
|
|
139
|
+
|
|
140
|
+
| Task | Browser host (React or Vue) | Headless, server, or agent |
|
|
141
|
+
| --- | --- | --- |
|
|
142
|
+
| [Comment on found text](https://www.docx-editor.dev/docs/2.x/recipes/comment-on-found-text) | `editor.findMatches`, `editor.selectMatch`, then `useReview().comment` | `body.search`, then `Range.insertComment` |
|
|
143
|
+
| Reply to a thread | `useReview().reply(item, text)` | `Comment.reply(text)` |
|
|
144
|
+
| [Record a tracked replacement](https://www.docx-editor.dev/docs/2.x/recipes/tracked-replacement) | Suggesting mode, then `editor.exec({ type: 'replaceMatch', match, text })` | `document.changeTrackingMode = 'TrackMineOnly'`, then `Range.insertText(text, 'Replace')` |
|
|
145
|
+
| [Propose an AI rewrite as tracked changes](https://www.docx-editor.dev/docs/2.x/recipes/propose-rewrite) | The same code through `DocxEditor.createBrowser` from `@docx-editor.dev/editor-api/browser` | `prepareRewrite` from `@docx-editor.dev/editor-api/agent` |
|
|
146
|
+
| [Accept or reject a change](https://www.docx-editor.dev/docs/2.x/recipes/accept-reject-without-scrolling) | `useReview().accept(item)` or `useReview().reject(item)` | `Revision.accept()` or `Revision.reject()` |
|
|
147
|
+
| [Open or reveal a change without scrolling](https://www.docx-editor.dev/docs/2.x/recipes/accept-reject-without-scrolling) | `useReview().setActive(key, { reveal: false })` | Not applicable: no viewport |
|
|
148
|
+
| [Highlight ranges](https://www.docx-editor.dev/docs/2.x/recipes/highlight-ranges) | `useHighlights(name, source, options)` | Not applicable |
|
|
149
|
+
| [Custom review rail cards](https://www.docx-editor.dev/docs/2.x/recipes/custom-review-cards) | `DocxEditorReview` with `preset` set to `false`, `useReview().items`, `useStackedReviewPositions`, and `useReviewRailMetrics` | Not applicable |
|
|
150
|
+
| Comment-on-selection button | `DocxEditorReview.AddComment` as a direct child of `DocxEditorReview`, or `useEditorCommand('review.addComment')` | Not applicable |
|
|
151
|
+
| Page setup and paragraph dialogs from a custom toolbar | `DocxEditor.PageSetupDialog` or `DocxEditor.ParagraphDialog` with `open` and a close handler (`onClose` in React, `@close` in Vue); enable the button from `usePageSetup().isEnabled` or `useParagraphFormat().isEnabled` | `Section.pageSetup`, and `Paragraph` properties such as `alignment` |
|
|
152
|
+
|
|
153
|
+
The review hooks need `reviewModule()` from `@docx-editor.dev/pro` in the editor's modules, and an editor `author` for comments and tracked changes. The editing API takes its author from the `author` option of `DocxEditor.createServer`, imported from `@docx-editor.dev/editor-api`, or of `DocxEditor.createBrowser`, imported from `@docx-editor.dev/editor-api/browser`.
|
|
154
|
+
|
|
155
|
+
This package ships the task recipes in [`docs/index.md`](./docs/index.md). They are also on the site: [Task recipes](https://www.docx-editor.dev/docs/2.x/recipes).
|
|
156
|
+
|
|
133
157
|
## Licensing
|
|
134
158
|
|
|
135
159
|
This package uses the [EigenPal Pro License](https://github.com/eigenpal/docx-editor/blob/main/packages/pro/LICENSE.md). See [pricing](https://www.docx-editor.dev/pricing) for license and support options.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {e,b,p,a,f,j as j$1,i as i$1,g,k as k$1,l,m as m$1}from'./chunk-GAGYRL3L.js';import*as i from'yjs';var x="roomGeneration",M="docx-room-generation",G=4409,R=2,c=new Set,_=1024;async function D(n,e){let t=n.buffer instanceof ArrayBuffer?n:n.slice(),o=new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256",t)),r="";for(let a of o)r+=a.toString(16).padStart(2,"0");return `${e}:${r}`}function N(n){if(c.size>=_){let e=c.values().next().value;e!==void 0&&c.delete(e);}c.add(n);}function U(n){let e$1=n.getMap(e).get(x);return typeof e$1=="string"?e$1:""}async function j(n,e$1={}){let t=e$1.minimumGain??R,o=await D(n,t);if(c.has(o))return null;let r=new i.Doc;try{i.applyUpdate(r,n);let s=r.getMap(e).get("documentId");if(typeof s!="string")throw new b("not-initialized");let l=await I(p(r),s);return n.byteLength/Math.max(1,l.byteLength)>=t?l:(N(o),null)}finally{r.destroy();}}async function I(n,e,t){let o=new i.Doc,r=a(o),a$1=new f(o);try{let s=new j$1(o.getMap(i$1)),l$1=await g(a$1,k$1(n,t),s);if(!l$1.ok)throw new b(l$1.code);return o.transact(()=>{a$1.schema.meta.set("documentId",e),a$1.schema.meta.set(x,globalThis.crypto.randomUUID()),l(o);}),m$1(o),i.encodeStateAsUpdate(o)}finally{a$1.destroy(),r(),o.destroy();}}function J(n){let e$1=n.getMap(e).get("initialized")===true;return JSON.stringify({type:M,generation:e$1?U(n):null})}function V(n){return n.code===G||n.reason==="room-generation-changed"}var T=new Set([0,1,3,4,6]),k=5,w=Symbol("docx-room-generation-checked");function W(n){let e=P(n.update);if(!e)throw m();if(e.type===k){let t=Y(e.payload);if(t===void 0)return;if(t!==null&&t!==U(n.document))throw m();n.context[w]=true;return}if(T.has(e.type)&&n.context[w]!==true)throw m()}function m(){return Object.assign(new Error("room-generation-changed"),{code:G,reason:"room-generation-changed"})}function Y(n){if(n===null||n.length>512)return;let e;try{e=JSON.parse(n);}catch{return}if(typeof e!="object"||e===null)return;let t=e;if(t.type===M)return t.generation===null?null:typeof t.generation=="string"&&t.generation.length<=128?t.generation:void 0}function P(n){let e={at:0};if(C(n,e)===null)return null;let o=O(n,e);return o===null?null:{type:o,payload:o===k?C(n,e):null}}function O(n,e){let t=0,o=1;for(let r=0;r<8;r+=1){let a=n[e.at];if(a===void 0)return null;if(e.at+=1,t+=(a&127)*o,a<128)return t;o*=128;}return null}function C(n,e){let t=O(n,e);if(t===null||e.at+t>n.length)return null;let o=new TextDecoder().decode(n.subarray(e.at,e.at+t));return e.at+=t,o}export{U as a,j as b,I as c,J as d,V as e,W as f};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {a}from'./chunk-Q2VBO66F.js';import {contentControlsIn,contentControlPropertiesOf,contentControlTextOf,findNode,revisionItemsOf,collectReviewItems,paragraphOrderOfPart,locateSites,parseNoteScopeId,customNodePayloadsOf,customNodePayloadsByControl,segmentsOf}from'@docx-editor.dev/core/store';import {resolveReviewPane,REVISION_MARKUP_COLORS,observeContentControlPopup}from'@docx-editor.dev/core/editor';import {createT,en}from'@docx-editor.dev/i18n';import {reviewItemPositionRank}from'@docx-editor.dev/core/layout';var Ue=64,le=new Set(["__proto__","constructor","prototype"]);function E(e,t,n){let o=new URLSearchParams;for(let[s,d]of Object.entries(n))o.set(s,d);let r=o.toString(),a=r.length>0?`${e}:${t}?${r}`:`${e}:${t}`;return a.length>64?{ok:false,reason:"tag-overflow",length:a.length}:{ok:true,tag:a}}function P(e){if(e.length>64)return null;let t=e.indexOf(":");if(t<=0)return null;let n=e.slice(0,t),o=e.slice(t+1),r=o.indexOf("?"),a=r===-1?o:o.slice(0,r);if(a.length===0)return null;let s=Object.create(null);if(r!==-1)for(let[d,i]of new URLSearchParams(o.slice(r+1))){if(le.has(d))return null;s[d]=i;}return {prefix:n,name:a,attrs:s}}var Ke=262144;function A(e,t){if(t.length===0)return {ok:false,reason:"malformed",issues:["the node carries no payload"]};if(t.length>262144)return {ok:false,reason:"malformed",issues:[`the payload is ${String(t.length)} characters; the cap is ${String(262144)}`]};let n;try{n=JSON.parse(t);}catch(a){return {ok:false,reason:"malformed",issues:[a instanceof Error?a.message:"the payload is not JSON"]}}let o=H(n);if(!e)return {ok:true,value:o};let r=e["~standard"].validate(o);return ce(r)?{ok:false,reason:"async",issues:["the schema validates asynchronously, which the read path cannot await"]}:r.issues?{ok:false,reason:"invalid",issues:r.issues.map(ue)}:{ok:true,value:r.value}}function F(e){let t;try{t=JSON.stringify(e)??"";}catch(n){return {ok:false,reason:"malformed",issues:[n instanceof Error?n.message:"the value cannot be serialized"]}}return t.length===0?{ok:false,reason:"malformed",issues:["the value serializes to nothing"]}:t.length>262144?{ok:false,reason:"malformed",issues:[`the payload is ${String(t.length)} characters; the cap is ${String(262144)}`]}:{ok:true,value:t}}function ce(e){return typeof e.then=="function"}function ue(e){let t=(e.path??[]).map(n=>String(typeof n=="object"?n.key:n)).join(".");return t.length>0?`${t}: ${e.message}`:e.message}var me=new Set(["__proto__","constructor","prototype"]);function H(e){if(Array.isArray(e))return e.map(H);if(e===null||typeof e!="object")return e;let t=Object.create(null);for(let[n,o]of Object.entries(e))me.has(n)||(t[n]=H(o));return t}function B(e){let t=(e.path??[]).map(n=>{let o=typeof n=="object"?n.key:n;return typeof o=="number"?o:String(o)});return {message:e.message,path:t,pointer:t.join(".")}}function D(e,t){return {ok:false,code:"invalidArgs",reason:e,issues:t}}var G="docxEditor";function T(e){return e.payloadNamespace??`urn:docx-editor.dev:custom-node:${e.tagPrefix}`}function J(e,t,n){let o=0;for(let r of customNodePayloadsOf(e,t,n).keys()){let a=/^cx(\d{1,9})$/.exec(r);if(!a)continue;let s=Number(a[1]);s>o&&(o=s);}return `cx${String(o+1)}`}function X(e,t){let n=F(t);if(!n.ok)return {ok:false,reason:`the payload cannot be serialized: ${n.issues.join(", ")}`,issues:[]};if(!e.schema)return {ok:true,data:n.value,value:t};let r=e.schema["~standard"].validate(JSON.parse(n.value));if(pe(r))return {ok:false,reason:`${e.name}'s schema validates asynchronously, which a write cannot await`,issues:[]};if(r.issues){let s=r.issues.map(B);return {ok:false,reason:`the payload does not match ${e.name}'s schema: `+s.map(d=>(d.pointer?`${d.pointer}: `:"")+d.message).join(", "),issues:s}}let a=F(r.value);return a.ok?{ok:true,data:a.value,value:r.value}:{ok:false,reason:`the payload cannot be serialized: ${a.issues.join(", ")}`,issues:[]}}function pe(e){return typeof e.then=="function"}function Y(e){return typeof e=="object"&&e!==null&&typeof e.name=="string"&&typeof e.tagPrefix=="string"}var q=/^[A-Za-z0-9_.-]+$/,ge=/['"<>&]|[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/;function he(e){return e.length>0&&!ge.test(e)}function ot(e){if(!q.test(e.name??""))throw new Error(`defineCustomNode: invalid name ${JSON.stringify(e.name)}`);if(!q.test(e.tagPrefix??""))throw new Error(`defineCustomNode: invalid tagPrefix ${JSON.stringify(e.tagPrefix)}`);let t=e.schema;if(t!==void 0&&typeof t?.["~standard"]?.validate!="function")throw new Error(`defineCustomNode: ${JSON.stringify(e.name)} has a schema that does not implement Standard Schema`);if(e.payloadNamespace!==void 0&&!he(e.payloadNamespace))throw new Error(`defineCustomNode: ${JSON.stringify(e.name)} has a payloadNamespace that cannot be written into an XPath \u2014 no quotes, angle brackets, ampersands or control characters: ${JSON.stringify(e.payloadNamespace)}`);if(e.preserveOnExport!==void 0&&e.preserveOnExport!==true&&e.preserveOnExport!==false&&e.preserveOnExport!=="text")throw new Error(`defineCustomNode: ${JSON.stringify(e.name)} has an unknown preserveOnExport ${JSON.stringify(e.preserveOnExport)}`);return Object.freeze({...e,dataOf:o=>{if(!o||o.data===void 0||o.name!==void 0&&o.name!==e.name)return;if(!e.schema)return o.data;let r=e.schema["~standard"].validate(o.data);if(typeof r.then=="function")return;let a=r;return a.issues?void 0:a.value}})}function rt(e){a(e.licenseKey);let t=new Set;for(let n of e.nodes){let o=`${n.tagPrefix}:${n.name}`;if(t.has(o))throw new Error(`customNodesModule: two definitions claim ${JSON.stringify(o)}`);t.add(o);}return {id:"custom-nodes",customNodes:e.nodes,...e.onDiagnostic?{onCustomNodeDiagnostic:n=>{e.onDiagnostic?.(n);}}:{},customNodePayloadNamespaces:[...new Set(e.nodes.map(T))]}}function ve(e){for(let t of e.children)if(!(t.kind==="textValue"||t.localName!=="sdtPr")){for(let n of t.children)if(!(n.kind==="textValue"||n.localName!=="tag")){for(let o of n.attributes)if(o.localName==="val")return o.value}}}function Z(e){if(e.kind==="textValue")return e.value;let t="";for(let n of e.children)t+=Z(n);return t}function Q(e,t,n={}){if(t.length===0)return [];let o=new Map;for(let s of t){let d=`${s.tagPrefix}:${s.name}`;if(o.has(d))throw new Error(`recognizeCustomNodes: duplicate definition for ${JSON.stringify(d)}`);o.set(d,s);}let r=[],a=(s,d)=>{if(!(s.kind==="textValue"||d>64)){if(s.kind==="contentControl"){let i=ve(s),l=i!==void 0?P(i):null,f=l?o.get(`${l.prefix}:${l.name}`):void 0;if(l&&f&&i!==void 0){let g=Z(s),v=xe(f,s.id,n.payloads?.get(s.id),contentControlPropertiesOf(s).dataBinding!==void 0,n.onDiagnostic),k=f.fromDocx?f.fromDocx({attrs:l.attrs,text:g,...v.present?{data:v.value}:{}}):l.attrs;if(k!==null){r.push({name:f.name,attrs:k,text:g,nodeId:s.id,tag:i,...v.present?{data:v.value}:{}});return}}}for(let i of s.children)a(i,d+1);}};return a(e.root,0),r}function xe(e,t,n,o,r){if(!n)return o&&r?.({code:"payload-missing",name:e.name,nodeId:t,issues:["the control binds a store node this document does not hold"]}),{present:false};let a=A(e.schema,n.data);return a.ok?{present:true,value:a.value}:(r?.({code:"payload-invalid",name:e.name,nodeId:t,issues:a.issues}),{present:false})}function ee(e,t){let n=e.createElement("div");n.className="docx-revision-color-picker";let o=e.createElement("span");o.textContent=t.label,o.id=`${t.id}-label`;let r=e.createElement("button");r.type="button",r.className="docx-revision-color-trigger",r.setAttribute("aria-labelledby",`${o.id} ${t.id}-value`),r.setAttribute("aria-expanded","false"),r.setAttribute("aria-controls",`${t.id}-options`);let a=e.createElement("span");a.className="docx-revision-color-swatch",a.setAttribute("aria-hidden","true");let s=e.createElement("span");s.id=`${t.id}-value`,r.append(a,s);let d=e.createElement("div");d.id=`${t.id}-options`,d.className="docx-revision-color-options",d.hidden=true,d.setAttribute("role","group"),d.setAttribute("aria-labelledby",o.id);let i=new Map,l=c=>c==="auto"?"currentColor":c==="byAuthor"?"var(--doc-review-author-0)":c==="none"?"transparent":`var(--doc-revision-color-${c})`,f,g=()=>{f?.(),f=void 0,e.removeEventListener("pointerdown",v,true),d.hidden=true,r.setAttribute("aria-expanded","false");},v=c=>{n.contains(c.target)||g();};n.addEventListener("focusout",c=>{n.contains(c.relatedTarget)||g();});let k=e.createElement("div");k.className="docx-revision-color-special";let S=e.createElement("div");S.className="docx-toolbar__swatch-grid",d.append(k,S);for(let c of t.colors){let p=e.createElement("button");if(p.type="button",p.dataset.value=c,p.setAttribute("aria-label",t.translate(c)),p.title=t.translate(c),["auto","none","byAuthor"].includes(c)){p.className="docx-toolbar__swatch-clear";let m=e.createElement("span");m.className="docx-revision-color-swatch",m.style.backgroundColor=l(c),m.setAttribute("aria-hidden","true"),p.append(m,e.createTextNode(t.translate(c))),k.append(p);}else p.className="docx-toolbar__swatch",p.dataset.light="",p.style.backgroundColor=l(c),S.append(p);p.addEventListener("mousedown",m=>m.preventDefault()),p.addEventListener("click",()=>{t.change(c),g(),r.focus();}),i.set(c,p);}return r.addEventListener("click",()=>{let c=d.hidden;if(d.hidden=!c,r.setAttribute("aria-expanded",String(c)),!c){g();return}f=observeContentControlPopup(d,r),e.addEventListener("pointerdown",v,true),(Array.from(i.values()).find(p=>p.hasAttribute("data-selected"))??i.values().next().value)?.focus();}),d.addEventListener("keydown",c=>{c.key==="Escape"&&(c.preventDefault(),c.stopPropagation(),g(),r.focus());let p=Array.from(d.querySelectorAll("button")),m=p.indexOf(c.target),u=c.key==="Home"?0:c.key==="End"?p.length-1:["ArrowRight","ArrowDown"].includes(c.key)?(m+1)%p.length:["ArrowLeft","ArrowUp"].includes(c.key)?(m-1+p.length)%p.length:null;u!==null&&(c.preventDefault(),c.stopPropagation(),p[u]?.focus());}),n.append(o,r,d),{element:n,destroy:g,update(c,p){s.textContent=t.translate(c),a.style.backgroundColor=l(c),r.disabled=p;for(let[m,u]of i)u.setAttribute("aria-pressed",String(m===c)),u.toggleAttribute("data-selected",m===c),u.disabled=p;p&&g();}}}var M=["none","colorOnly","bold","italic","underline","doubleUnderline","strikethrough","doubleStrikethrough"],te=[...M,"hidden","caret","pound"],j=0;function ne(e){let t=e.container.ownerDocument,n=null,o=e.get(),r=null,a=new Map,s=new Map,d=createT(en),i=m=>e.translate?.(`revisionMarkup.${m}`)??d(`revisionMarkup.${m}`),l=(m,u)=>{let y=t.createElement(m);return u!==void 0&&(y.textContent=u),y},f=()=>{n?.close(),n?.remove(),n=null,a.clear();for(let m of s.values())m.destroy();s.clear(),r?.isConnected&&r.focus({preventScroll:true}),r=null;},g=()=>{for(let[m,u]of a){let[y,h]=m.split("."),x=o[y];u.tagName==="INPUT"?u.checked=x:u.value=x[h],u.disabled=(y==="movedFrom"||y==="movedTo")&&!o.trackMoves;}for(let[m,u]of s){let[y,h]=m.split("."),x=o[y];u.update(x[h],(y==="movedFrom"||y==="movedTo")&&!o.trackMoves);}},v=m=>{e.set(m);},k=e.subscribe(()=>{o=e.get(),g();}),S=(m,u,y,h,x)=>{if(y==="color"||y==="background"||u==="cells"){let R=i(u==="cells"?`${y}Cells`:`${u}${y==="background"?"Background":"Color"}`),N=ee(t,{id:`docx-revision-color-${j++}`,label:R,colors:h,translate:C=>i(`values.${C}`),change:C=>v({[u]:{[y]:C}})});return s.set(`${u}.${y}`,N),m.append(N.element),N.element}let O=l("label"),b=l("span",i(u));b.className="docx-revision-markup-field-label",O.append(b);let w=l("select");for(let R of h){let N=l("option",i(`values.${R}`));N.value=R,w.append(N);}return w.value=x,w.addEventListener("change",()=>v({[u]:{[y]:w.value}})),O.append(w),m.append(O),a.set(`${u}.${y}`,w),O},c=(m,u,y)=>{let h=l("div");h.className="docx-revision-markup-row";let x=l("span",i(u));if(x.className="docx-revision-markup-row-title",x.setAttribute("aria-hidden","true"),h.append(x),S(h,u,"mark",y,o[u].mark),S(h,u,"color",["byAuthor","auto",...REVISION_MARKUP_COLORS],o[u].color),m.append(h),u!=="changedLines"){let O=l("div");O.className="docx-revision-markup-background",S(O,u,"background",["none","byAuthor",...REVISION_MARKUP_COLORS],o[u].background),m.append(O);}},p=(m,u)=>{let y=l("label"),h=l("input");h.type="checkbox",h.checked=o[u],h.addEventListener("change",()=>v({[u]:h.checked}));let x=l("p",i(`${u}Note`));x.id=`docx-revision-markup-note-${j++}`,h.setAttribute("aria-describedby",x.id),y.append(h,t.createTextNode(i(u))),m.append(y,x),a.set(u,h);};return {open(){if(e.signal.aborted)return;if(n){n.focus();return}o=e.get(),r=t.activeElement,n=l("dialog"),n.className="docx-revision-markup-dialog",n.contentEditable="false",n.setAttribute("data-docx-marker","");for(let N of ["keydown","mousedown","beforeinput"])n.addEventListener(N,C=>C.stopPropagation());let m=l("h2",i("title"));m.id=`docx-revision-markup-title-${j++}`,n.setAttribute("aria-labelledby",m.id),n.append(m),n.addEventListener("cancel",N=>{N.preventDefault(),e.cancel();});let u=l("div");u.className="docx-revision-markup-body",n.append(u);let y=N=>{let C=l("fieldset");return C.className=`docx-revision-markup-${N}`,C.append(l("legend",i(N))),u.append(C),C},h=y("markup");c(h,"insertions",M),c(h,"deletions",te),c(h,"changedLines",["none","leftBorder","rightBorder","outsideBorder"]);let x=y("moves");p(x,"trackMoves"),c(x,"movedFrom",te),c(x,"movedTo",M);let O=y("tableCells");for(let N of ["inserted","deleted","merged","split"])S(O,"cells",N,["byAuthor","none",...REVISION_MARKUP_COLORS],o.cells[N]);let b=y("formatting");p(b,"trackFormatting"),c(b,"formatting",M);let w=l("div");w.className="docx-revision-markup-actions";let R=(N,C)=>{let V=l("button",i(N));V.type="button",V.addEventListener("click",C),w.append(V);};R("reset",()=>e.reset()),R("cancel",()=>e.cancel()),R("ok",()=>{e.apply();}),n.append(w),e.container.append(n),g(),n.showModal(),n.querySelector("select")?.focus({preventScroll:true});},destroy(){k(),f();}}}function re(e,t){let n=findNode(e,t);return !n||n.kind!=="paragraph"?[]:revisionItemsOf({id:e.id,name:e.name,contentType:e.contentType,root:n})}function Ie(e,t,n,o){if(t.length===0)return [];let r=Q(e,t,{...n===void 0?{}:{payloads:n},...o===void 0?{}:{onDiagnostic:o}});if(r.length===0)return [];let a=locateSites(e),s=[];for(let d of r){let i=t.find(g=>g.name===d.name&&d.tag.startsWith(`${g.tagPrefix}:`));if(!i)continue;let l=i.reviewCard?i.reviewCard({attrs:d.attrs,text:d.text,...d.data===void 0?{}:{data:d.data}}):null;if(i.reviewCard&&l===null)continue;let f=a.get(d.nodeId);s.push({kind:"custom",id:d.nodeId,name:d.name,tag:d.tag,attrs:d.attrs,text:d.text,...d.data===void 0?{}:{data:d.data},carded:i.reviewCard!==void 0&&l!==null,title:l?.title??"",...l?.detail!==void 0?{detail:l.detail}:{},...l?.icon!==void 0?{icon:l.icon}:{},range:f?{partName:e.name,start:{paragraphId:f.paragraphId,offset:f.start},end:{paragraphId:f.paragraphId,offset:f.end}}:null});}return s}function ae(e){let t=collectReviewItems(e),n=(e.customNodes??[]).filter(Y);if(n.length===0)return t;let o=[e.storyPart],r=new Set([e.storyPart.name]);for(let i of e.furnitureParts??[])r.has(i.name)||(r.add(i.name),o.push(i));let a=[],s=new Map;for(let i of o){a.push(...Ie(i,n,e.customNodePayloads,e.reportCustomNodeDiagnostic));let l=s.size;for(let[f,g]of paragraphOrderOfPart(i))s.has(f)||s.set(f,l+g);}return a.length===0?t:[...t,...a].sort((i,l)=>reviewItemPositionRank(i,s)-reviewItemPositionRank(l,s))}function Et(e={}){let t=e.pane===void 0?void 0:{...resolveReviewPane(e.pane)};return a(e.licenseKey),{id:"review",review:{createRevisionMarkupDialog:ne,displayModes:["all-markup","simple-markup","proposed","original"],collectReviewItems:ae,revisionItemsOfParagraph:re,...t?{pane:t}:{}}}}function de(e){return e.surface??null}function U(e,t){if(t==null)return null;let n=X(e,t);return n.ok?{ok:true,serialized:n.data,value:n.value}:{ok:false,reason:n.reason,issues:n.issues}}function W(e,t,n,o,r){let a=T(t),s=e.session.part().name;return {namespaceUri:a,rootLocalName:G,nodeId:r??J(e.session.currentPackage(),s,a),label:o,data:n}}function $(e){let t=e.detail?`${e.reason}: ${e.detail}`:e.reason;return {ok:false,code:Ae.has(e.reason)?"invalidArgs":"unsupported",reason:t}}var Ae=new Set(["payload-too-large","unaddressable-payload","store-not-authored","offset-out-of-range","invalid-range","invalid-property-value","splits-surrogate-pair"]);function K(e,t,n){let o,r;if(n!==void 0)try{o=e.text?.(n),r=e.tagAttrs?.(n);}catch(s){return {reason:`${e.name} could not describe this payload: ${s instanceof Error?s.message:String(s)}`}}let a=t.text??o;return a===void 0?{reason:e.text?`${e.name} derives its text from \`data\`, so pass one \u2014 or pass \`text\` directly`:`${e.name} declares no \`text\`, so \`text\` is required`}:t.attrs===void 0&&e.tagAttrs&&r===void 0?{reason:`${e.name} derives its tag attrs from \`data\`, so pass one \u2014 or pass \`attrs\` directly`}:{attrs:t.attrs??r??{},text:a}}function L(e){return e.getEditingMode()==="viewing"?{ok:false,code:"locked",reason:"the document is open for viewing"}:null}function se(e){let t=e.getActiveScope();if(t.kind==="headerFooter")return {kind:"headerFooter",rId:t.rId};if(t.kind==="note"){let n=parseNoteScopeId(t.id);if(n)return {kind:"notesPart",noteKind:n.noteKind}}return {kind:"body"}}function _(e,t){let n=de(e),o=t===void 0?"":t.slice(0,t.indexOf("#"));if(!n||o.length===0)return se(e);if(o===n.session.part().name)return {kind:"body"};for(let r of n.session.headerFooterResolutionBySection())for(let a of [r.headers,r.footers])for(let s of a.values())if(s.partName===o)return {kind:"headerFooter",rId:s.rId};for(let r of ["footnote","endnote"])if(n.session.partFor({kind:"notesPart",noteKind:r})?.name===o)return {kind:"notesPart",noteKind:r};return se(e)}function De(e){let t=e.author()?.trim();return e.editingMode()!=="suggest"||!t?null:{author:t,date:`${new Date().toISOString().slice(0,19)}Z`}}function $t(e,t,n={}){let o=de(e);if(!o)return {ok:false,code:"notFound",reason:"no document is mounted"};let r=U(t,n.data);if(r&&!r.ok)return D(r.reason,r.issues);let a=K(t,n,r?.value);if("reason"in a)return {ok:false,code:"invalidArgs",reason:a.reason};let s=E(t.tagPrefix,t.name,a.attrs);if(!s.ok)return {ok:false,code:"invalidArgs",reason:`the encoded tag is ${s.length} characters; Word caps w:tag at 64 \u2014 move what does not fit into the payload (\`data\`), or shorten the attrs`};let d=L(e);if(d)return d;o.flushPendingInput();let i=n.at??o.state().selection.head,l=n.lock===void 0?"contentLocked":n.lock,f=_(e,i.paragraphId),g=De(o),v=o.session.insertCustomNode({paragraphId:i.paragraphId,offset:i.offset,tag:s.tag,text:a.text,...n.alias===void 0?{}:{alias:n.alias},...l===false?{}:{lock:l},...r?{payload:W(o,t,r.serialized,a.text)}:{},...g?{revision:g}:{}},f);return v.ok?{ok:true,changed:true,...v.nodeId===void 0?{}:{nodeId:v.nodeId}}:$(v)}function ie(e){return e.surface??null}function Ve(e,t){let n=null,o=a=>a.id===t?true:a.kind==="textValue"?false:a.children.some(o),r=(a,s)=>{if(!(n||a.kind==="textValue"||s>64)){if(a.kind==="paragraph"){o(a)&&(n=a);return}for(let d of a.children)r(d,s+1);}};return r(e.root,0),n}function He(e,t){let n=new Set,o=i=>{if(n.add(i.id),i.kind!=="textValue")for(let l of i.children)o(l);},r=i=>{if(i.id===t)return i;if(i.kind==="textValue")return null;for(let l of i.children){let f=r(l);if(f)return f}return null},a=r(e);if(!a)return null;o(a);let s=Number.MAX_SAFE_INTEGER,d=-1;for(let i of segmentsOf(e))n.has(i.runId)&&(i.start<s&&(s=i.start),i.end>d&&(d=i.end));return d<0?null:{start:s,end:d}}function Ut(e,t){let n=ie(e);if(!n)return {ok:false,code:"notFound",reason:"no document is mounted"};let o=L(e);if(o)return o;n.flushPendingInput();let r=n.session.removeCustomNode(t,_(e,t));return r.ok?{ok:true,changed:true}:$(r)}function Wt(e,t,n,o={}){let r=ie(e);if(!r)return {ok:false,code:"notFound",reason:"no document is mounted"};let a=L(e);if(a)return a;r.flushPendingInput();let s=_(e,n),d=r.session.partFor(s)??r.session.part(),i=Ve(d,n),l=i?He(i,n):null,f=Fe(r,n,s);if(!i||!l||!f)return {ok:false,code:"notFound",reason:"no custom node with that id"};let g=`${t.tagPrefix}:${t.name}`;if(f.identity!==null&&f.identity!==g)return {ok:false,code:"invalidArgs",reason:`node ${n} is a ${f.identity}, not a ${g}`};let v=je(r,n,s),k=o.data===null?null:o.data===void 0?ze(v):U(t,o.data);if(k&&!k.ok)return D(k.reason,k.issues);let S=K(t,{attrs:o.attrs??(o.data===void 0?f.attrs:void 0),text:o.text??(k===null&&o.data===null?f.text:void 0)},k?.value);if("reason"in S)return {ok:false,code:"invalidArgs",reason:S.reason};let c=E(t.tagPrefix,t.name,S.attrs);if(!c.ok)return {ok:false,code:"invalidArgs",reason:`the encoded tag is ${c.length} characters; Word caps w:tag at 64 \u2014 move what does not fit into the payload (\`data\`), or shorten the attrs`};let p=o.alias??f.alias,m=o.lock??f.lock,u=r.session.insertCustomNode({replaceControlId:n,paragraphId:i.id,offset:l.start,tag:c.tag,text:S.text,...p===void 0?{}:{alias:p},...m===false||m===void 0?{}:{lock:m},...k?{payload:W(r,t,k.serialized,S.text,v?.nodeId)}:{}},s);return u.ok?{ok:true,changed:true,...u.nodeId===void 0?{}:{nodeId:u.nodeId}}:$(u)}function Fe(e,t,n){let o=e.session.partFor(n)??e.session.part(),r=contentControlsIn(o.root).find(i=>i.node.id===t);if(!r)return null;let a=contentControlPropertiesOf(r.node),s=a.tag===void 0?null:P(a.tag),d=a.lock;return {identity:s?`${s.prefix}:${s.name}`:null,attrs:s?.attrs??{},text:contentControlTextOf(r.node),alias:a.alias,lock:d==="sdtLocked"||d==="sdtContentLocked"||d==="contentLocked"?d:d==="unlocked"?false:void 0}}function ze(e){if(!e)return null;let t=A(void 0,e.data);return t.ok?{ok:true,serialized:e.data,value:t.value}:{ok:false,reason:`the stored payload is not readable: ${t.issues.join(", ")}`,issues:[]}}function je(e,t,n){let o=e.session.partFor(n)??e.session.part();return customNodePayloadsByControl(e.session.currentPackage(),o.name,e.session.part().name).get(t)}export{Ue as a,E as b,P as c,Ke as d,A as e,F as f,G as g,T as h,X as i,Y as j,q as k,ot as l,rt as m,Q as n,Et as o,$t as p,Ut as q,Wt as r};
|