oasis-editor 0.0.161 → 0.0.163

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.
@@ -1,3 +1,9 @@
1
+ declare module "./primitives.js" {
2
+ interface EditorRevision {
3
+ /** Word tracked-move semantics layered over delete/insert revisions. */
4
+ move?: "from" | "to";
5
+ }
6
+ }
1
7
  declare module "./nodes.js" {
2
8
  interface EditorRunBase {
3
9
  /** Enclosing inline `w:sdt` content controls, outermost first. */
@@ -0,0 +1,11 @@
1
+ import { EditorRevision } from '../../../core/model.js';
2
+
3
+ /**
4
+ * Word stores visible text from deletion-like revisions in `w:delText` and
5
+ * deleted field instructions in `w:delInstrText`. Canonical run generation uses
6
+ * the ordinary tags, so normalize only direct run children here. If a source
7
+ * overlay retained stale deleted-text children after an edit, the generated
8
+ * ordinary child is authoritative and the stale counterpart is removed first.
9
+ */
10
+ export declare function serializeDeletionRunContent(xml: string): string;
11
+ export declare function serializeRunRevisionWrapper(innerXml: string, revision: EditorRevision): string;
@@ -1,5 +1,5 @@
1
1
  import { Element as XmlElement } from '@xmldom/xmldom';
2
- import { EditorBlockNode, EditorTextStyle, EditorImageRunData, EditorTextBoxData, EditorMathExpression, EditorSdtBlockWrapper } from '../../../core/model.js';
2
+ import { EditorBlockNode, EditorTextStyle, EditorImageRunData, EditorTextBoxData, EditorMathExpression, EditorRevision, EditorSdtBlockWrapper } from '../../../core/model.js';
3
3
 
4
4
  export type ParseNestedBlocks = (container: XmlElement) => Promise<EditorBlockNode[]>;
5
5
  /**
@@ -28,6 +28,8 @@ export interface ImportedRun {
28
28
  image?: EditorImageRunData;
29
29
  textBox?: EditorTextBoxData;
30
30
  styles?: EditorTextStyle;
31
+ /** Tracked insertion/deletion, optionally paired as a Word move. */
32
+ revision?: EditorRevision;
31
33
  /** Enclosing inline `w:sdt` wrappers, outermost first. */
32
34
  sdtWrappers?: EditorSdtBlockWrapper[];
33
35
  field?: {
@@ -39,7 +41,7 @@ export interface ImportedRun {
39
41
  fieldLock?: boolean;
40
42
  dirty?: boolean;
41
43
  };
42
- /** Preserved `w:instrText`. Zero-length marker. */
44
+ /** Preserved `w:instrText` / `w:delInstrText`. Zero-length marker. */
43
45
  fieldInstruction?: string;
44
46
  footnoteReference?: {
45
47
  docxId: string;
@@ -2863,7 +2863,7 @@ function OasisEditorAppLazy(props = {}) {
2863
2863
  onCleanup(() => {
2864
2864
  cancelled = true;
2865
2865
  });
2866
- import("./OasisEditorApp-CZ4smGNO.js").then((m) => {
2866
+ import("./OasisEditorApp-DrmbnMAA.js").then((m) => {
2867
2867
  cancelled = true;
2868
2868
  setProgress(1);
2869
2869
  setTimeout(() => setApp(() => m.OasisEditorApp), 180);
@@ -39752,6 +39752,31 @@ function parseCommentMarker(element) {
39752
39752
  docxId
39753
39753
  };
39754
39754
  }
39755
+ function fallbackRevisionId(element) {
39756
+ const xml = new XMLSerializer().serializeToString(element);
39757
+ let hash = 2166136261;
39758
+ for (let index = 0; index < xml.length; index += 1) {
39759
+ hash ^= xml.charCodeAt(index);
39760
+ hash = Math.imul(hash, 16777619);
39761
+ }
39762
+ return `revision:${hash >>> 0}`;
39763
+ }
39764
+ function parseRevisionContainer(element) {
39765
+ const kind = element.localName;
39766
+ if (kind !== "ins" && kind !== "del" && kind !== "moveFrom" && kind !== "moveTo") {
39767
+ return void 0;
39768
+ }
39769
+ const rawDate = getAttributeValue(element, "date");
39770
+ const parsedDate = rawDate ? Date.parse(rawDate) : Number.NaN;
39771
+ const isDeletion = kind === "del" || kind === "moveFrom";
39772
+ return {
39773
+ id: getAttributeValue(element, "id") ?? fallbackRevisionId(element),
39774
+ type: isDeletion ? "delete" : "insert",
39775
+ author: getAttributeValue(element, "author") ?? "Unknown",
39776
+ date: Number.isFinite(parsedDate) ? parsedDate : 0,
39777
+ ...kind === "moveFrom" ? { move: "from" } : kind === "moveTo" ? { move: "to" } : {}
39778
+ };
39779
+ }
39755
39780
  async function parseRunElement(runElement, zip, relsMap, assets, parseNestedBlocks) {
39756
39781
  const textParts = [];
39757
39782
  let image;
@@ -39772,7 +39797,7 @@ async function parseRunElement(runElement, zip, relsMap, assets, parseNestedBloc
39772
39797
  }
39773
39798
  const element = node;
39774
39799
  if (element.namespaceURI === WORD_NS$3) {
39775
- if (element.localName === "t") {
39800
+ if (element.localName === "t" || element.localName === "delText") {
39776
39801
  pushText(element.textContent ?? "");
39777
39802
  } else if (element.localName === "tab") {
39778
39803
  pushText(" ");
@@ -39959,6 +39984,26 @@ async function parseRunsContainer(container, numberingMaps, zip, relsMap, assets
39959
39984
  runs.push({ text: "", comment: marker });
39960
39985
  continue;
39961
39986
  }
39987
+ const revision = parseRevisionContainer(element);
39988
+ if (revision) {
39989
+ const nestedRuns = await parseRunsContainer(
39990
+ element,
39991
+ numberingMaps,
39992
+ zip,
39993
+ relsMap,
39994
+ assets,
39995
+ theme,
39996
+ inheritedLink,
39997
+ parseNestedBlocks
39998
+ );
39999
+ for (const nestedRun of nestedRuns) {
40000
+ runs.push({
40001
+ ...nestedRun,
40002
+ revision: nestedRun.revision ?? revision
40003
+ });
40004
+ }
40005
+ continue;
40006
+ }
39962
40007
  if (element.localName === "sdt") {
39963
40008
  const sdtContent = getFirstChildByTagNameNS(element, WORD_NS$3, "sdtContent");
39964
40009
  if (!sdtContent) {
@@ -39994,7 +40039,7 @@ async function parseRunsContainer(container, numberingMaps, zip, relsMap, assets
39994
40039
  getFirstChildByTagNameNS(element, WORD_NS$3, "rPr"),
39995
40040
  theme
39996
40041
  );
39997
- const hasFieldControl = getChildrenByTagNameNS(element, WORD_NS$3, "fldChar").length > 0 || getChildrenByTagNameNS(element, WORD_NS$3, "instrText").length > 0;
40042
+ const hasFieldControl = getChildrenByTagNameNS(element, WORD_NS$3, "fldChar").length > 0 || getChildrenByTagNameNS(element, WORD_NS$3, "instrText").length > 0 || getChildrenByTagNameNS(element, WORD_NS$3, "delInstrText").length > 0;
39998
40043
  if (hasFieldControl) {
39999
40044
  for (let child2 = 0; child2 < element.childNodes.length; child2 += 1) {
40000
40045
  const childNode = element.childNodes[child2];
@@ -40007,7 +40052,7 @@ async function parseRunsContainer(container, numberingMaps, zip, relsMap, assets
40007
40052
  }
40008
40053
  if (childElement.localName === "fldChar") {
40009
40054
  onFldChar(childElement, runStyles);
40010
- } else if (childElement.localName === "instrText") {
40055
+ } else if (childElement.localName === "instrText" || childElement.localName === "delInstrText") {
40011
40056
  onInstrText(childElement, runStyles);
40012
40057
  }
40013
40058
  }
@@ -40537,6 +40582,9 @@ function importedRunToEditorRun(run) {
40537
40582
  if (run.styles) {
40538
40583
  base.styles = { ...run.styles };
40539
40584
  }
40585
+ if (run.revision) {
40586
+ base.revision = { ...run.revision };
40587
+ }
40540
40588
  if ((_a2 = run.sdtWrappers) == null ? void 0 : _a2.length) {
40541
40589
  base.sdtWrappers = [...run.sdtWrappers];
40542
40590
  }
@@ -43256,7 +43304,7 @@ function wrapTableStructuralSdts(table, tableElement) {
43256
43304
  }))
43257
43305
  );
43258
43306
  }
43259
- function elementChildren(node) {
43307
+ function elementChildren$1(node) {
43260
43308
  const children2 = [];
43261
43309
  for (let index = 0; index < node.childNodes.length; index += 1) {
43262
43310
  const child2 = node.childNodes[index];
@@ -43308,8 +43356,8 @@ function matchingChildByOccurrence(sourceChildren, sourceIndex, generatedChildre
43308
43356
  }
43309
43357
  function mergeNestedExtensionMarkup(source, generated) {
43310
43358
  copyExtensionAttributes(source, generated);
43311
- const sourceChildren = elementChildren(source);
43312
- const generatedChildren = elementChildren(generated);
43359
+ const sourceChildren = elementChildren$1(source);
43360
+ const generatedChildren = elementChildren$1(generated);
43313
43361
  sourceChildren.forEach((sourceChild, sourceIndex) => {
43314
43362
  const generatedChild = matchingChildByOccurrence(
43315
43363
  sourceChildren,
@@ -45142,6 +45190,106 @@ function mergeRunOoxmlSourceIntoGeneratedXml(run, generatedXml) {
45142
45190
  mergeSourceRunChildren(sourceRun, generatedRun);
45143
45191
  return new XMLSerializer().serializeToString(generatedRun);
45144
45192
  }
45193
+ const WRAPPER_XMLNS = `xmlns:oasis="urn:oasis:docx" xmlns:w="${WORD_NS$1}" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"`;
45194
+ function elementChildren(element) {
45195
+ const result = [];
45196
+ for (let index = 0; index < element.childNodes.length; index += 1) {
45197
+ const child2 = element.childNodes[index];
45198
+ if ((child2 == null ? void 0 : child2.nodeType) === child2.ELEMENT_NODE) {
45199
+ result.push(child2);
45200
+ }
45201
+ }
45202
+ return result;
45203
+ }
45204
+ function parseSingleRun(xml) {
45205
+ const wrapper = new DOMParser$1().parseFromString(
45206
+ `<oasis:root ${WRAPPER_XMLNS}>${xml}</oasis:root>`,
45207
+ "application/xml"
45208
+ ).documentElement;
45209
+ if (!wrapper) return void 0;
45210
+ const children2 = elementChildren(wrapper);
45211
+ if (children2.length !== 1) return void 0;
45212
+ const run = children2[0];
45213
+ return run.namespaceURI === WORD_NS$1 && run.localName === "r" ? run : void 0;
45214
+ }
45215
+ function replaceWordChildName(parent, source, targetLocalName) {
45216
+ const ownerDocument = parent.ownerDocument;
45217
+ if (!ownerDocument) return;
45218
+ const replacement = ownerDocument.createElementNS(
45219
+ WORD_NS$1,
45220
+ `w:${targetLocalName}`
45221
+ );
45222
+ for (let index = 0; index < source.attributes.length; index += 1) {
45223
+ const attribute = source.attributes.item(index);
45224
+ if (!attribute) continue;
45225
+ if (attribute.namespaceURI) {
45226
+ replacement.setAttributeNS(
45227
+ attribute.namespaceURI,
45228
+ attribute.name,
45229
+ attribute.value
45230
+ );
45231
+ } else {
45232
+ replacement.setAttribute(attribute.name, attribute.value);
45233
+ }
45234
+ }
45235
+ while (source.firstChild) {
45236
+ replacement.appendChild(source.firstChild);
45237
+ }
45238
+ parent.replaceChild(replacement, source);
45239
+ }
45240
+ function serializeDeletionRunContent(xml) {
45241
+ const run = parseSingleRun(xml);
45242
+ if (!run) return xml;
45243
+ const children2 = elementChildren(run);
45244
+ const generatedText = children2.filter(
45245
+ (child2) => child2.namespaceURI === WORD_NS$1 && child2.localName === "t"
45246
+ );
45247
+ if (generatedText.length > 0) {
45248
+ for (const child2 of children2) {
45249
+ if (child2.namespaceURI === WORD_NS$1 && child2.localName === "delText") {
45250
+ run.removeChild(child2);
45251
+ }
45252
+ }
45253
+ for (const child2 of generatedText) {
45254
+ replaceWordChildName(run, child2, "delText");
45255
+ }
45256
+ }
45257
+ const refreshed = elementChildren(run);
45258
+ const generatedInstructions = refreshed.filter(
45259
+ (child2) => child2.namespaceURI === WORD_NS$1 && child2.localName === "instrText"
45260
+ );
45261
+ if (generatedInstructions.length > 0) {
45262
+ for (const child2 of refreshed) {
45263
+ if (child2.namespaceURI === WORD_NS$1 && child2.localName === "delInstrText") {
45264
+ run.removeChild(child2);
45265
+ }
45266
+ }
45267
+ for (const child2 of generatedInstructions) {
45268
+ replaceWordChildName(run, child2, "delInstrText");
45269
+ }
45270
+ }
45271
+ return new XMLSerializer().serializeToString(run);
45272
+ }
45273
+ function revisionNumericId(id) {
45274
+ if (/^\d+$/.test(id)) return id;
45275
+ return String(
45276
+ Array.from(id).reduce(
45277
+ (hash, character) => hash * 31 + character.charCodeAt(0) >>> 0,
45278
+ 0
45279
+ )
45280
+ );
45281
+ }
45282
+ function revisionElementName(revision) {
45283
+ if (revision.move === "from") return "moveFrom";
45284
+ if (revision.move === "to") return "moveTo";
45285
+ return revision.type === "delete" ? "del" : "ins";
45286
+ }
45287
+ function serializeRunRevisionWrapper(innerXml, revision) {
45288
+ const date = Number.isFinite(revision.date) ? new Date(revision.date).toISOString() : (/* @__PURE__ */ new Date(0)).toISOString();
45289
+ const attributes = `w:id="${revisionNumericId(revision.id)}" w:author="${escapeXml(revision.author)}" w:date="${date}"`;
45290
+ const element = revisionElementName(revision);
45291
+ return `<w:${element} ${attributes}>${innerXml}</w:${element}>`;
45292
+ }
45145
45293
  function serializeRun(run, context2, paragraphStyleId, styles, serializeBlocksXml2) {
45146
45294
  if (run.__isFootnoteRefMarker) {
45147
45295
  return serializeFootnoteRefMarker();
@@ -45191,19 +45339,20 @@ function serializeRun(run, context2, paragraphStyleId, styles, serializeBlocksXm
45191
45339
  return mergeRunOoxmlSourceIntoGeneratedXml(run, generatedXml);
45192
45340
  }
45193
45341
  function serializeRunWithRelationships(run, context2, paragraphStyleId, styles, serializeBlocksXml2) {
45194
- var _a2;
45195
- const runXml = serializeRun(
45342
+ var _a2, _b2;
45343
+ let runXml = serializeRun(
45196
45344
  run,
45197
45345
  context2,
45198
45346
  paragraphStyleId,
45199
45347
  styles,
45200
45348
  serializeBlocksXml2
45201
45349
  );
45202
- const href = (_a2 = run.styles) == null ? void 0 : _a2.link;
45203
- if (!href) {
45204
- return runXml;
45350
+ if (((_a2 = run.revision) == null ? void 0 : _a2.type) === "delete") {
45351
+ runXml = serializeDeletionRunContent(runXml);
45205
45352
  }
45206
- return wrapRunWithHyperlink(runXml, href, context2);
45353
+ const href = (_b2 = run.styles) == null ? void 0 : _b2.link;
45354
+ const linkedXml = href ? wrapRunWithHyperlink(runXml, href, context2) : runXml;
45355
+ return run.revision ? serializeRunRevisionWrapper(linkedXml, run.revision) : linkedXml;
45207
45356
  }
45208
45357
  function serializeRunsWithInlineSdts(runs, serializeRun2) {
45209
45358
  var _a2, _b2, _c;
@@ -47568,7 +47717,7 @@ async function importDocxInWorker(buffer, options = {}) {
47568
47717
  const worker = new Worker(
47569
47718
  new URL(
47570
47719
  /* @vite-ignore */
47571
- "" + new URL("assets/importDocxWorker-CyAWuOO6.js", import.meta.url).href,
47720
+ "" + new URL("assets/importDocxWorker-Dc9RJPVl.js", import.meta.url).href,
47572
47721
  import.meta.url
47573
47722
  ),
47574
47723
  {
@@ -1,4 +1,4 @@
1
- import { dK, ah, aw, aM, aG, dL, dM, dN, aA, dO, ai, dP, dt, aN, dQ, dR, aL, aD, dS, dT, dU, ag, dV, dr, aP, dW, dX, dY, dZ, d_, dF, d$, e0, e1, aU, aT, e2, aE, e3, e4, e5, e6, e7, e8, aI, aF, e9, b3, aO, b2, aV, az, aK, dE, ea, dL as dL2, dS as dS2, dV as dV2, e2 as e22, e3 as e32, e8 as e82, eb, ec, dv, dq, ed, ee, ef, eg, eh, ei, ej, ds, ek, el, em, du, en } from "./index-BXPaFnv7.js";
1
+ import { dK, ah, aw, aM, aG, dL, dM, dN, aA, dO, ai, dP, dt, aN, dQ, dR, aL, aD, dS, dT, dU, ag, dV, dr, aP, dW, dX, dY, dZ, d_, dF, d$, e0, e1, aU, aT, e2, aE, e3, e4, e5, e6, e7, e8, aI, aF, e9, b3, aO, b2, aV, az, aK, dE, ea, dL as dL2, dS as dS2, dV as dV2, e2 as e22, e3 as e32, e8 as e82, eb, ec, dv, dq, ed, ee, ef, eg, eh, ei, ej, ds, ek, el, em, du, en } from "./index-ByH2Moxz.js";
2
2
  export {
3
3
  dK as ActionRow,
4
4
  ah as BalloonShell,