@superdoc-dev/cli 0.21.1 → 0.21.2

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 (2) hide show
  1. package/dist/index.js +836 -483
  2. package/package.json +9 -9
package/dist/index.js CHANGED
@@ -68358,7 +68358,7 @@ var init_remark_gfm_BUJjZJLy_es = __esm(() => {
68358
68358
  emptyOptions2 = {};
68359
68359
  });
68360
68360
 
68361
- // ../../packages/superdoc/dist/chunks/SuperConverter-SsIUcBUk.es.js
68361
+ // ../../packages/superdoc/dist/chunks/SuperConverter-8tQYSE1r.es.js
68362
68362
  function getExtensionConfigField(extension$1, field, context = { name: "" }) {
68363
68363
  const fieldValue = extension$1.config[field];
68364
68364
  if (typeof fieldValue === "function")
@@ -136974,7 +136974,7 @@ Docs: https://docs.superdoc.dev/getting-started/fonts`);
136974
136974
  return out;
136975
136975
  }
136976
136976
  return out;
136977
- }, groupedCache, SDT_NODE_NAMES, SDT_BLOCK_NAME = "structuredContentBlock", SDT_INLINE_NAME = "structuredContent", SDT_NODE_TYPES, VALID_CONTROL_TYPES, VALID_LOCK_MODES2, VALID_APPEARANCES, FIELD_LIKE_SDT_TYPES, liveDocumentCountsCache, BIBLIOGRAPHY_NAMESPACE_URI = "http://schemas.openxmlformats.org/officeDocument/2006/bibliography", CUSTOM_XML_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml", CUSTOM_XML_PROPS_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXmlProps", DEFAULT_SELECTED_STYLE = "/APA.XSL", DEFAULT_STYLE_NAME = "APA", DEFAULT_VERSION = "6", API_TO_OOXML_SOURCE_TYPE, OOXML_TO_API_SOURCE_TYPE, SIMPLE_FIELD_TO_XML_TAG, XML_TAG_TO_SIMPLE_FIELD, import_lib2, FONT_FAMILY_FALLBACKS, DEFAULT_GENERIC_FALLBACK = "sans-serif", DEFAULT_FONT_SIZE_PT = 10, CURRENT_APP_VERSION = "1.44.0", SUPERDOC_DOCUMENT_ORIGIN_PROPERTY = "SuperdocDocumentOrigin", STORED_DOCUMENT_ORIGINS, collectRunDefaultProperties = (runProps, { allowOverrideTypeface = true, allowOverrideSize = true, themeResolver, state }) => {
136977
+ }, groupedCache, SDT_NODE_NAMES, SDT_BLOCK_NAME = "structuredContentBlock", SDT_INLINE_NAME = "structuredContent", SDT_NODE_TYPES, VALID_CONTROL_TYPES, VALID_LOCK_MODES2, VALID_APPEARANCES, FIELD_LIKE_SDT_TYPES, liveDocumentCountsCache, BIBLIOGRAPHY_NAMESPACE_URI = "http://schemas.openxmlformats.org/officeDocument/2006/bibliography", CUSTOM_XML_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml", CUSTOM_XML_PROPS_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXmlProps", DEFAULT_SELECTED_STYLE = "/APA.XSL", DEFAULT_STYLE_NAME = "APA", DEFAULT_VERSION = "6", API_TO_OOXML_SOURCE_TYPE, OOXML_TO_API_SOURCE_TYPE, SIMPLE_FIELD_TO_XML_TAG, XML_TAG_TO_SIMPLE_FIELD, import_lib2, FONT_FAMILY_FALLBACKS, DEFAULT_GENERIC_FALLBACK = "sans-serif", DEFAULT_FONT_SIZE_PT = 10, CURRENT_APP_VERSION = "1.44.1", SUPERDOC_DOCUMENT_ORIGIN_PROPERTY = "SuperdocDocumentOrigin", STORED_DOCUMENT_ORIGINS, collectRunDefaultProperties = (runProps, { allowOverrideTypeface = true, allowOverrideSize = true, themeResolver, state }) => {
136978
136978
  if (!runProps?.elements?.length || !state)
136979
136979
  return;
136980
136980
  const fontsNode = runProps.elements.find((el) => el.name === "w:rFonts");
@@ -137008,7 +137008,7 @@ Docs: https://docs.superdoc.dev/getting-started/fonts`);
137008
137008
  state.kern = kernNode.attributes["w:val"];
137009
137009
  }
137010
137010
  }, SuperConverter;
137011
- var init_SuperConverter_SsIUcBUk_es = __esm(() => {
137011
+ var init_SuperConverter_8tQYSE1r_es = __esm(() => {
137012
137012
  init_rolldown_runtime_Bg48TavK_es();
137013
137013
  init_jszip_C49i9kUs_es();
137014
137014
  init_xml_js_CqGKpaft_es();
@@ -156672,12 +156672,7 @@ var init_SuperConverter_SsIUcBUk_es = __esm(() => {
156672
156672
  upperLetter: 360,
156673
156673
  lowerLetter: 360
156674
156674
  };
156675
- NUMBERING_ROOT_ATTRS = {
156676
- "xmlns:w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
156677
- "xmlns:w15": "http://schemas.microsoft.com/office/word/2012/wordml",
156678
- "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
156679
- "mc:Ignorable": "w15"
156680
- };
156675
+ NUMBERING_ROOT_ATTRS = { ...DEFAULT_DOCX_DEFS };
156681
156676
  numberingPartDescriptor = {
156682
156677
  id: NUMBERING_PART_ID,
156683
156678
  ensurePart() {
@@ -166024,7 +166019,7 @@ var init_SuperConverter_SsIUcBUk_es = __esm(() => {
166024
166019
  };
166025
166020
  });
166026
166021
 
166027
- // ../../packages/superdoc/dist/chunks/create-headless-toolbar-JMykgI82.es.js
166022
+ // ../../packages/superdoc/dist/chunks/create-headless-toolbar-J9k_n61d.es.js
166028
166023
  function parseSizeUnit(val = "0") {
166029
166024
  const length3 = val.toString() || "0";
166030
166025
  const value = Number.parseFloat(length3);
@@ -176845,9 +176840,9 @@ var CSS_DIMENSION_REGEX, DOM_SIZE_UNITS, MARK_KEYS, STEP_OP_CATALOG_UNFROZEN2, P
176845
176840
  }
176846
176841
  };
176847
176842
  };
176848
- var init_create_headless_toolbar_JMykgI82_es = __esm(() => {
176843
+ var init_create_headless_toolbar_J9k_n61d_es = __esm(() => {
176849
176844
  init_rolldown_runtime_Bg48TavK_es();
176850
- init_SuperConverter_SsIUcBUk_es();
176845
+ init_SuperConverter_8tQYSE1r_es();
176851
176846
  init_jszip_C49i9kUs_es();
176852
176847
  init_uuid_B2wVPhPi_es();
176853
176848
  init_constants_D9qj59G2_es();
@@ -226940,7 +226935,7 @@ var init_remark_gfm_DCND_V_3_es = __esm(() => {
226940
226935
  init_remark_gfm_BUJjZJLy_es();
226941
226936
  });
226942
226937
 
226943
- // ../../packages/superdoc/dist/chunks/src-CA6yipr-.es.js
226938
+ // ../../packages/superdoc/dist/chunks/src-K-HYiMBY.es.js
226944
226939
  function deleteProps(obj, propOrProps) {
226945
226940
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
226946
226941
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -227084,7 +227079,7 @@ function prosemirrorToYXmlFragment(doc$12, xmlFragment) {
227084
227079
  }
227085
227080
  function getSuperdocVersion() {
227086
227081
  try {
227087
- return "1.44.0";
227082
+ return "1.44.1";
227088
227083
  } catch {
227089
227084
  return "unknown";
227090
227085
  }
@@ -227761,6 +227756,390 @@ function createPartPublisher(editor, ydoc, options = {}) {
227761
227756
  destroy
227762
227757
  };
227763
227758
  }
227759
+ function getLocalName$12(name) {
227760
+ if (!name || typeof name !== "string")
227761
+ return "";
227762
+ const i3 = name.indexOf(":");
227763
+ return i3 >= 0 ? name.slice(i3 + 1) : name;
227764
+ }
227765
+ function findFirstElement(parent, localName$2) {
227766
+ if (!parent?.elements?.length)
227767
+ return null;
227768
+ return parent.elements.find((el) => el?.type === "element" && getLocalName$12(el.name) === localName$2) ?? null;
227769
+ }
227770
+ function findAllElements(parent, localName$2) {
227771
+ if (!parent?.elements?.length)
227772
+ return [];
227773
+ return parent.elements.filter((el) => el?.type === "element" && getLocalName$12(el.name) === localName$2);
227774
+ }
227775
+ function partNameFromIndex(index2) {
227776
+ return `customXml/item${index2}.xml`;
227777
+ }
227778
+ function propsPartNameFromIndex(index2) {
227779
+ return `customXml/itemProps${index2}.xml`;
227780
+ }
227781
+ function indexFromPartName(partName) {
227782
+ const m$1 = /^customXml\/item(\d+)\.xml$/i.exec(partName ?? "");
227783
+ return m$1 ? Number.parseInt(m$1[1], 10) : null;
227784
+ }
227785
+ function indexFromPropsPartName(propsPartName) {
227786
+ const m$1 = /^customXml\/itemProps(\d+)\.xml$/i.exec(propsPartName ?? "");
227787
+ return m$1 ? Number.parseInt(m$1[1], 10) : null;
227788
+ }
227789
+ function isCustomXmlStoragePartName(partName) {
227790
+ return indexFromPartName(partName) != null;
227791
+ }
227792
+ function listCustomXmlStoragePartNames(convertedXml) {
227793
+ if (!convertedXml || typeof convertedXml !== "object")
227794
+ return [];
227795
+ const indexes = [];
227796
+ for (const path2 of Object.keys(convertedXml)) {
227797
+ const idx = indexFromPartName(path2);
227798
+ if (idx != null)
227799
+ indexes.push(idx);
227800
+ }
227801
+ indexes.sort((a2, b$1) => a2 - b$1);
227802
+ return indexes.map(partNameFromIndex);
227803
+ }
227804
+ function findPropsPartFor(convertedXml, partName) {
227805
+ if (!convertedXml)
227806
+ return null;
227807
+ const idx = indexFromPartName(partName);
227808
+ if (idx == null)
227809
+ return null;
227810
+ const relsRoot = convertedXml[`customXml/_rels/item${idx}.xml.rels`]?.elements?.find((el) => getLocalName$12(el?.name) === "Relationships");
227811
+ if (relsRoot?.elements?.length)
227812
+ for (const rel of relsRoot.elements) {
227813
+ if (rel?.attributes?.Type !== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXmlProps")
227814
+ continue;
227815
+ const target = rel?.attributes?.Target;
227816
+ if (typeof target !== "string" || target.length === 0)
227817
+ continue;
227818
+ const candidate = resolveOpcTargetPath(target, "customXml");
227819
+ if (candidate && convertedXml[candidate])
227820
+ return candidate;
227821
+ }
227822
+ const indexCandidate = propsPartNameFromIndex(idx);
227823
+ return convertedXml[indexCandidate] ? indexCandidate : null;
227824
+ }
227825
+ function parsePropsPart(propsDoc) {
227826
+ const root3 = propsDoc?.elements?.find((el) => el?.type === "element" && getLocalName$12(el.name) === "datastoreItem");
227827
+ if (!root3)
227828
+ return null;
227829
+ const itemId = root3.attributes?.["ds:itemID"] ?? root3.attributes?.itemID ?? null;
227830
+ const schemaRefs = findAllElements(findFirstElement(root3, "schemaRefs"), "schemaRef").map((el) => el.attributes?.["ds:uri"] ?? el.attributes?.uri ?? null).filter((uri) => typeof uri === "string" && uri.length > 0);
227831
+ return {
227832
+ itemId: typeof itemId === "string" && itemId.length > 0 ? itemId : null,
227833
+ schemaRefs
227834
+ };
227835
+ }
227836
+ function parseStoragePartRootNamespace(storageDoc) {
227837
+ const root3 = storageDoc?.elements?.find((el) => el?.type === "element");
227838
+ if (!root3)
227839
+ return null;
227840
+ const xmlns2 = root3.attributes?.xmlns;
227841
+ if (typeof xmlns2 === "string" && xmlns2.length > 0)
227842
+ return xmlns2;
227843
+ const elementName = root3.name ?? "";
227844
+ const colonIdx = elementName.indexOf(":");
227845
+ if (colonIdx > 0) {
227846
+ const prefixedAttr = `xmlns:${elementName.slice(0, colonIdx)}`;
227847
+ const prefixedValue = root3.attributes?.[prefixedAttr];
227848
+ if (typeof prefixedValue === "string" && prefixedValue.length > 0)
227849
+ return prefixedValue;
227850
+ }
227851
+ return null;
227852
+ }
227853
+ function serializeXmlDoc(xmlDoc) {
227854
+ if (!xmlDoc)
227855
+ return "";
227856
+ return import_lib4.js2xml(xmlDoc, {
227857
+ compact: false,
227858
+ spaces: 0
227859
+ });
227860
+ }
227861
+ function readCustomXmlPart(convertedXml, target) {
227862
+ if (!target || !convertedXml)
227863
+ return null;
227864
+ let partName = null;
227865
+ let itemId = null;
227866
+ if (typeof target.partName === "string" && target.partName.length > 0) {
227867
+ if (!isCustomXmlStoragePartName(target.partName))
227868
+ return null;
227869
+ partName = target.partName;
227870
+ } else if (typeof target.id === "string" && target.id.length > 0) {
227871
+ itemId = target.id;
227872
+ for (const candidatePartName of listCustomXmlStoragePartNames(convertedXml)) {
227873
+ const propsName = findPropsPartFor(convertedXml, candidatePartName);
227874
+ if (!propsName)
227875
+ continue;
227876
+ if (parsePropsPart(convertedXml[propsName])?.itemId === itemId) {
227877
+ partName = candidatePartName;
227878
+ break;
227879
+ }
227880
+ }
227881
+ if (!partName)
227882
+ return null;
227883
+ } else
227884
+ return null;
227885
+ const storageDoc = convertedXml[partName];
227886
+ if (!storageDoc)
227887
+ return null;
227888
+ const propsPartName = findPropsPartFor(convertedXml, partName);
227889
+ const props = propsPartName ? parsePropsPart(convertedXml[propsPartName]) : null;
227890
+ return {
227891
+ id: props?.itemId ?? null,
227892
+ partName,
227893
+ propsPartName: propsPartName ?? null,
227894
+ rootNamespace: parseStoragePartRootNamespace(storageDoc),
227895
+ schemaRefs: props?.schemaRefs ?? [],
227896
+ content: serializeXmlDoc(storageDoc)
227897
+ };
227898
+ }
227899
+ function listCustomXmlParts(convertedXml) {
227900
+ return listCustomXmlStoragePartNames(convertedXml).map((partName) => {
227901
+ const propsPartName = findPropsPartFor(convertedXml, partName);
227902
+ const props = propsPartName ? parsePropsPart(convertedXml[propsPartName]) : null;
227903
+ return {
227904
+ id: props?.itemId ?? null,
227905
+ partName,
227906
+ propsPartName: propsPartName ?? null,
227907
+ rootNamespace: parseStoragePartRootNamespace(convertedXml[partName]),
227908
+ schemaRefs: props?.schemaRefs ?? []
227909
+ };
227910
+ });
227911
+ }
227912
+ function nextCustomXmlItemIndex(convertedXml, converter) {
227913
+ const used = /* @__PURE__ */ new Set;
227914
+ for (const path2 of Object.keys(convertedXml ?? {})) {
227915
+ const idx = indexFromPartName(path2) ?? indexFromPropsPartName(path2);
227916
+ if (idx != null)
227917
+ used.add(idx);
227918
+ }
227919
+ let candidate = 1;
227920
+ while (used.has(candidate))
227921
+ candidate += 1;
227922
+ return candidate;
227923
+ }
227924
+ function createXmlDocument2(rootElement$1, declaration) {
227925
+ const nextDeclaration = declaration ?? DEFAULT_XML_DECLARATION;
227926
+ return {
227927
+ declaration: {
227928
+ ...nextDeclaration,
227929
+ attributes: { ...nextDeclaration.attributes }
227930
+ },
227931
+ elements: [rootElement$1]
227932
+ };
227933
+ }
227934
+ function parseContentToRootElement(content3) {
227935
+ const parsed = import_lib4.xml2js(content3, { compact: false });
227936
+ const root3 = (parsed.elements ?? []).find((el) => el?.type === "element");
227937
+ if (!root3)
227938
+ throw new Error("Custom XML content is missing a root element.");
227939
+ return {
227940
+ root: root3,
227941
+ declaration: parsed.declaration ?? null
227942
+ };
227943
+ }
227944
+ function ensureDocumentRelationshipsRoot2(convertedXml) {
227945
+ if (!convertedXml["word/_rels/document.xml.rels"])
227946
+ convertedXml["word/_rels/document.xml.rels"] = createXmlDocument2({
227947
+ type: "element",
227948
+ name: "Relationships",
227949
+ attributes: { xmlns: "http://schemas.openxmlformats.org/package/2006/relationships" },
227950
+ elements: []
227951
+ });
227952
+ const relsData = convertedXml["word/_rels/document.xml.rels"];
227953
+ relsData.elements ??= [];
227954
+ let relsRoot = relsData.elements.find((el) => getLocalName$12(el?.name) === "Relationships");
227955
+ if (!relsRoot) {
227956
+ relsRoot = {
227957
+ type: "element",
227958
+ name: "Relationships",
227959
+ attributes: { xmlns: "http://schemas.openxmlformats.org/package/2006/relationships" },
227960
+ elements: []
227961
+ };
227962
+ relsData.elements.push(relsRoot);
227963
+ }
227964
+ relsRoot.elements ??= [];
227965
+ return relsRoot;
227966
+ }
227967
+ function getNextRelationshipId2(relsRoot) {
227968
+ const used = (relsRoot?.elements ?? []).map((rel) => {
227969
+ const id2 = rel?.attributes?.Id;
227970
+ const m$1 = typeof id2 === "string" ? /^rId(\d+)$/.exec(id2) : null;
227971
+ return m$1 ? Number.parseInt(m$1[1], 10) : NaN;
227972
+ }).filter((n) => Number.isFinite(n));
227973
+ return `rId${(used.length > 0 ? Math.max(...used) : 0) + 1}`;
227974
+ }
227975
+ function buildDocumentRelTarget(partName) {
227976
+ return partName.startsWith("customXml/") ? `../${partName}` : partName;
227977
+ }
227978
+ function buildItemPropsRoot(itemId, schemaRefs) {
227979
+ return [{
227980
+ type: "element",
227981
+ name: "ds:datastoreItem",
227982
+ attributes: {
227983
+ "ds:itemID": itemId,
227984
+ "xmlns:ds": CUSTOM_XML_DATASTORE_NAMESPACE
227985
+ },
227986
+ elements: schemaRefs === undefined ? [] : [{
227987
+ type: "element",
227988
+ name: "ds:schemaRefs",
227989
+ elements: schemaRefs.map((uri) => ({
227990
+ type: "element",
227991
+ name: "ds:schemaRef",
227992
+ attributes: { "ds:uri": uri }
227993
+ }))
227994
+ }]
227995
+ }][0];
227996
+ }
227997
+ function buildItemRelsRoot(propsPartFileName) {
227998
+ return {
227999
+ type: "element",
228000
+ name: "Relationships",
228001
+ attributes: { xmlns: "http://schemas.openxmlformats.org/package/2006/relationships" },
228002
+ elements: [{
228003
+ type: "element",
228004
+ name: "Relationship",
228005
+ attributes: {
228006
+ Id: "rId1",
228007
+ Type: CUSTOM_XML_PROPS_RELATIONSHIP_TYPE$1,
228008
+ Target: propsPartFileName
228009
+ }
228010
+ }]
228011
+ };
228012
+ }
228013
+ function resolveTargetPartName(convertedXml, target) {
228014
+ if (!target)
228015
+ return null;
228016
+ if (typeof target.partName === "string" && target.partName.length > 0) {
228017
+ if (!isCustomXmlStoragePartName(target.partName))
228018
+ return null;
228019
+ return convertedXml[target.partName] ? target.partName : null;
228020
+ }
228021
+ if (typeof target.id === "string" && target.id.length > 0)
228022
+ for (const partName of listCustomXmlStoragePartNames(convertedXml)) {
228023
+ const propsName = findPropsPartFor(convertedXml, partName);
228024
+ if (!propsName)
228025
+ continue;
228026
+ if (parsePropsPart(convertedXml[propsName])?.itemId === target.id)
228027
+ return partName;
228028
+ }
228029
+ return null;
228030
+ }
228031
+ function createCustomXmlPart(convertedXml, { content: content3, schemaRefs }, converter) {
228032
+ const { root: root3, declaration } = parseContentToRootElement(content3);
228033
+ const index2 = nextCustomXmlItemIndex(convertedXml, converter);
228034
+ const partName = partNameFromIndex(index2);
228035
+ const propsPartName = propsPartNameFromIndex(index2);
228036
+ const itemRelsPath = `customXml/_rels/item${index2}.xml.rels`;
228037
+ const itemId = `{${v4_default().toUpperCase()}}`;
228038
+ convertedXml[partName] = createXmlDocument2(root3, declaration);
228039
+ convertedXml[propsPartName] = createXmlDocument2(buildItemPropsRoot(itemId, schemaRefs));
228040
+ convertedXml[itemRelsPath] = createXmlDocument2(buildItemRelsRoot(`itemProps${index2}.xml`));
228041
+ const relsRoot = ensureDocumentRelationshipsRoot2(convertedXml);
228042
+ relsRoot.elements.push({
228043
+ type: "element",
228044
+ name: "Relationship",
228045
+ attributes: {
228046
+ Id: getNextRelationshipId2(relsRoot),
228047
+ Type: CUSTOM_XML_DATA_RELATIONSHIP_TYPE,
228048
+ Target: buildDocumentRelTarget(partName)
228049
+ }
228050
+ });
228051
+ if (converter?.removedCustomXmlPaths instanceof Set) {
228052
+ converter.removedCustomXmlPaths.delete(partName);
228053
+ converter.removedCustomXmlPaths.delete(propsPartName);
228054
+ converter.removedCustomXmlPaths.delete(itemRelsPath);
228055
+ }
228056
+ return {
228057
+ id: itemId,
228058
+ partName,
228059
+ propsPartName
228060
+ };
228061
+ }
228062
+ function patchCustomXmlPart(convertedXml, target, { content: content3, schemaRefs }, converter) {
228063
+ const partName = resolveTargetPartName(convertedXml, target);
228064
+ if (!partName)
228065
+ return null;
228066
+ if (content3 !== undefined) {
228067
+ const { root: root3, declaration } = parseContentToRootElement(content3);
228068
+ convertedXml[partName] = createXmlDocument2(root3, convertedXml[partName]?.declaration ?? declaration);
228069
+ }
228070
+ let resolvedId = null;
228071
+ if (schemaRefs !== undefined) {
228072
+ let propsPartName = findPropsPartFor(convertedXml, partName);
228073
+ if (propsPartName)
228074
+ resolvedId = parsePropsPart(convertedXml[propsPartName])?.itemId ?? null;
228075
+ if (!propsPartName) {
228076
+ const idx = indexFromPartName(partName);
228077
+ if (idx == null)
228078
+ return null;
228079
+ propsPartName = propsPartNameFromIndex(idx);
228080
+ const itemRelsPath = `customXml/_rels/item${idx}.xml.rels`;
228081
+ resolvedId = `{${v4_default().toUpperCase()}}`;
228082
+ convertedXml[itemRelsPath] = createXmlDocument2(buildItemRelsRoot(`itemProps${idx}.xml`));
228083
+ }
228084
+ if (!resolvedId)
228085
+ resolvedId = `{${v4_default().toUpperCase()}}`;
228086
+ const existingDecl = convertedXml[propsPartName]?.declaration;
228087
+ convertedXml[propsPartName] = createXmlDocument2(buildItemPropsRoot(resolvedId, schemaRefs), existingDecl);
228088
+ } else {
228089
+ const propsPartName = findPropsPartFor(convertedXml, partName);
228090
+ if (propsPartName)
228091
+ resolvedId = parsePropsPart(convertedXml[propsPartName])?.itemId ?? null;
228092
+ }
228093
+ if (converter)
228094
+ invalidateConverterCachesForPath(converter, partName);
228095
+ return resolvedId ? {
228096
+ partName,
228097
+ id: resolvedId
228098
+ } : { partName };
228099
+ }
228100
+ function removeCustomXmlPart(convertedXml, target, converter) {
228101
+ const partName = resolveTargetPartName(convertedXml, target);
228102
+ if (!partName)
228103
+ return false;
228104
+ const index2 = indexFromPartName(partName);
228105
+ const removedPaths = [
228106
+ partName,
228107
+ findPropsPartFor(convertedXml, partName),
228108
+ index2 == null ? null : `customXml/_rels/item${index2}.xml.rels`
228109
+ ].filter((path2) => typeof path2 === "string" && path2.length > 0);
228110
+ for (const path2 of removedPaths)
228111
+ delete convertedXml[path2];
228112
+ const relsRoot = convertedXml["word/_rels/document.xml.rels"]?.elements?.find((el) => getLocalName$12(el?.name) === "Relationships");
228113
+ if (relsRoot?.elements?.length)
228114
+ relsRoot.elements = relsRoot.elements.filter((rel) => {
228115
+ if (rel?.attributes?.Type !== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml")
228116
+ return true;
228117
+ return resolveOpcTargetPath(rel?.attributes?.Target, "word") !== partName;
228118
+ });
228119
+ if (converter) {
228120
+ if (!(converter.removedCustomXmlPaths instanceof Set))
228121
+ converter.removedCustomXmlPaths = /* @__PURE__ */ new Set;
228122
+ for (const path2 of removedPaths)
228123
+ converter.removedCustomXmlPaths.add(path2);
228124
+ invalidateConverterCachesForPath(converter, partName);
228125
+ }
228126
+ return true;
228127
+ }
228128
+ function invalidateConverterCachesForPath(converter, partName) {
228129
+ if (!converter || typeof partName !== "string")
228130
+ return;
228131
+ const biblio = converter.bibliographyPart;
228132
+ if (biblio && biblio.partPath === partName)
228133
+ converter.bibliographyPart = {
228134
+ sources: [],
228135
+ partPath: null,
228136
+ itemPropsPath: null,
228137
+ itemRelsPath: null,
228138
+ selectedStyle: null,
228139
+ styleName: null,
228140
+ version: null
228141
+ };
228142
+ }
227764
228143
  function isApplyingRemotePartChanges() {
227765
228144
  return isApplyingRemoteParts;
227766
228145
  }
@@ -227771,6 +228150,8 @@ function createPartConsumer(editor, ydoc) {
227771
228150
  if (transaction.local)
227772
228151
  return;
227773
228152
  const operations = [];
228153
+ const removedCustomXmlPaths = /* @__PURE__ */ new Set;
228154
+ const writtenCustomXmlPaths = /* @__PURE__ */ new Set;
227774
228155
  const relsData = decodeYjsToEnvelope(partsMap.get("word/_rels/document.xml.rels"))?.data ?? null;
227775
228156
  event.changes.keys.forEach((change, key2) => {
227776
228157
  if (EXCLUDED_PART_IDS.has(key2))
@@ -227779,6 +228160,8 @@ function createPartConsumer(editor, ydoc) {
227779
228160
  const sectionId = ensureHeaderFooterSectionId(partId, relsData, editor);
227780
228161
  try {
227781
228162
  if (change.action === "delete") {
228163
+ if (isCustomXmlTombstonePath(editor, key2))
228164
+ removedCustomXmlPaths.add(key2);
227782
228165
  if (hasPart(editor, partId))
227783
228166
  operations.push({
227784
228167
  editor,
@@ -227806,7 +228189,7 @@ function createPartConsumer(editor, ydoc) {
227806
228189
  operation: "mutate",
227807
228190
  source: SOURCE_COLLAB_REMOTE_PARTS,
227808
228191
  mutate: ({ part }) => {
227809
- replacePartData(part, envelope.data);
228192
+ replacePartData$1(part, envelope.data);
227810
228193
  }
227811
228194
  });
227812
228195
  else
@@ -227818,14 +228201,18 @@ function createPartConsumer(editor, ydoc) {
227818
228201
  source: SOURCE_COLLAB_REMOTE_PARTS,
227819
228202
  initial: envelope.data
227820
228203
  });
228204
+ if (isCustomXmlPartPath(key2))
228205
+ writtenCustomXmlPaths.add(key2);
227821
228206
  failedParts.delete(key2);
227822
228207
  } catch (err) {
227823
228208
  console.error(`[part-sync] Error processing remote part "${key2}":`, err);
227824
228209
  trackFailure(failedParts, key2, partsMap);
227825
228210
  }
227826
228211
  });
227827
- if (operations.length === 0)
228212
+ if (operations.length === 0) {
228213
+ applyCustomXmlTombstoneChanges(editor, removedCustomXmlPaths, writtenCustomXmlPaths);
227828
228214
  return;
228215
+ }
227829
228216
  isApplyingRemoteParts = true;
227830
228217
  try {
227831
228218
  mutateParts({
@@ -227833,6 +228220,7 @@ function createPartConsumer(editor, ydoc) {
227833
228220
  source: SOURCE_COLLAB_REMOTE_PARTS,
227834
228221
  operations
227835
228222
  });
228223
+ applyCustomXmlTombstoneChanges(editor, removedCustomXmlPaths, writtenCustomXmlPaths);
227836
228224
  } catch (err) {
227837
228225
  console.error("[part-sync] Failed to apply remote part changes:", err);
227838
228226
  } finally {
@@ -227845,7 +228233,7 @@ function createPartConsumer(editor, ydoc) {
227845
228233
  failedParts.clear();
227846
228234
  } };
227847
228235
  }
227848
- function replacePartData(target, source) {
228236
+ function replacePartData$1(target, source) {
227849
228237
  if (!target || typeof target !== "object" || !source || typeof source !== "object")
227850
228238
  return;
227851
228239
  const tgt = target;
@@ -227863,6 +228251,96 @@ function ensureHeaderFooterSectionId(partId, relsData, editor) {
227863
228251
  ensureHeaderFooterDescriptor(partId, sectionId);
227864
228252
  return sectionId;
227865
228253
  }
228254
+ function getCustomXmlTombstoneConverter(editor) {
228255
+ return editor.converter;
228256
+ }
228257
+ function isCustomXmlPartPath(path2) {
228258
+ return /^customxml\//i.test(path2);
228259
+ }
228260
+ function isCustomXmlTombstonePath(editor, path2) {
228261
+ return /^customXml\/item\d+\.xml$/i.test(path2) || /^customXml\/itemProps\d+\.xml$/i.test(path2) || /^customXml\/_rels\/item\d+\.xml\.rels$/i.test(path2) || isLinkedCustomXmlPropsPath(editor, path2);
228262
+ }
228263
+ function isLinkedCustomXmlPropsPath(editor, path2) {
228264
+ if (!isCustomXmlPartPath(path2) || !/\.xml$/i.test(path2))
228265
+ return false;
228266
+ const convertedXml = getCustomXmlTombstoneConverter(editor)?.convertedXml;
228267
+ if (!convertedXml)
228268
+ return false;
228269
+ for (const [relsPath, relsDoc] of Object.entries(convertedXml)) {
228270
+ if (!/^customXml\/_rels\/item\d+\.xml\.rels$/i.test(relsPath))
228271
+ continue;
228272
+ for (const target of getCustomXmlPropsTargets(relsDoc))
228273
+ if (target === path2)
228274
+ return true;
228275
+ }
228276
+ return false;
228277
+ }
228278
+ function getCustomXmlPropsTargets(relsDoc) {
228279
+ const relationshipsRoot = getElements(relsDoc).find((element3) => getLocalName2(getName(element3)) === "Relationships");
228280
+ if (!relationshipsRoot)
228281
+ return [];
228282
+ return getElements(relationshipsRoot).map((relationship) => {
228283
+ const attributes = getAttributes(relationship);
228284
+ if (attributes.Type !== CUSTOM_XML_PROPS_RELATIONSHIP_TYPE2)
228285
+ return null;
228286
+ return resolveCustomXmlRelationshipTarget(attributes.Target);
228287
+ }).filter((target) => typeof target === "string");
228288
+ }
228289
+ function getElements(value) {
228290
+ if (!value || typeof value !== "object")
228291
+ return [];
228292
+ const elements = value.elements;
228293
+ return Array.isArray(elements) ? elements : [];
228294
+ }
228295
+ function getName(value) {
228296
+ if (!value || typeof value !== "object")
228297
+ return "";
228298
+ const name = value.name;
228299
+ return typeof name === "string" ? name : "";
228300
+ }
228301
+ function getAttributes(value) {
228302
+ if (!value || typeof value !== "object")
228303
+ return {};
228304
+ const attributes = value.attributes;
228305
+ return attributes && typeof attributes === "object" && !Array.isArray(attributes) ? attributes : {};
228306
+ }
228307
+ function getLocalName2(name) {
228308
+ const separatorIndex = name.indexOf(":");
228309
+ return separatorIndex >= 0 ? name.slice(separatorIndex + 1) : name;
228310
+ }
228311
+ function resolveCustomXmlRelationshipTarget(target) {
228312
+ if (typeof target !== "string" || target.length === 0 || target.includes("://"))
228313
+ return null;
228314
+ if (target.startsWith("/"))
228315
+ return target.slice(1);
228316
+ const resolved = [];
228317
+ for (const segment of `customXml/${target}`.split("/"))
228318
+ if (segment === "..")
228319
+ resolved.pop();
228320
+ else if (segment !== "." && segment !== "")
228321
+ resolved.push(segment);
228322
+ return resolved.join("/");
228323
+ }
228324
+ function applyCustomXmlTombstoneChanges(editor, removedPaths, writtenPaths) {
228325
+ const converter = getCustomXmlTombstoneConverter(editor);
228326
+ if (!converter)
228327
+ return;
228328
+ for (const path2 of writtenPaths) {
228329
+ if (converter.removedCustomXmlPaths instanceof Set)
228330
+ converter.removedCustomXmlPaths.delete(path2);
228331
+ invalidateConverterCachesForPath(converter, path2);
228332
+ }
228333
+ if (removedPaths.size === 0)
228334
+ return;
228335
+ for (const path2 of removedPaths)
228336
+ recordCustomXmlTombstone(converter, path2);
228337
+ }
228338
+ function recordCustomXmlTombstone(converter, path2) {
228339
+ if (!(converter.removedCustomXmlPaths instanceof Set))
228340
+ converter.removedCustomXmlPaths = /* @__PURE__ */ new Set;
228341
+ converter.removedCustomXmlPaths.add(path2);
228342
+ invalidateConverterCachesForPath(converter, path2);
228343
+ }
227866
228344
  function trackFailure(failedParts, key2, partsMap) {
227867
228345
  const envelope = decodeYjsToEnvelope(partsMap.get(key2));
227868
228346
  if (envelope)
@@ -227979,7 +228457,7 @@ function updateMigrationStatus(metaMap, status, error3, ydoc) {
227979
228457
  };
227980
228458
  metaMap.set(META_PARTS_MIGRATION_KEY, updated);
227981
228459
  }
227982
- function getConverter$92(editor) {
228460
+ function getConverter$102(editor) {
227983
228461
  return editor.converter;
227984
228462
  }
227985
228463
  function bucketFor(type) {
@@ -228030,7 +228508,7 @@ function publishSessionManagedNoteIds(ydoc, registry2) {
228030
228508
  publishNoteTombstone(ydoc, "endnote", noteId);
228031
228509
  }
228032
228510
  function hydrateNoteTombstonesFromMeta(editor, ydoc) {
228033
- const converter = getConverter$92(editor);
228511
+ const converter = getConverter$102(editor);
228034
228512
  if (!converter)
228035
228513
  return;
228036
228514
  const metaMap = ydoc.getMap(META_MAP_KEY$1);
@@ -228056,7 +228534,7 @@ function registerNoteTombstoneSync(editor, ydoc) {
228056
228534
  };
228057
228535
  editor.on?.(NOTE_TOMBSTONE_EVENT, onTombstoned);
228058
228536
  const observer = (event) => {
228059
- const converter = getConverter$92(editor);
228537
+ const converter = getConverter$102(editor);
228060
228538
  if (!converter)
228061
228539
  return;
228062
228540
  let registry2 = null;
@@ -228212,9 +228690,12 @@ function hydrateFromPartsMap(editor, ydoc, partsMap) {
228212
228690
  const operations = [];
228213
228691
  const criticalFailures = [];
228214
228692
  const relsData = decodeYjsToEnvelope(partsMap.get("word/_rels/document.xml.rels"))?.data ?? null;
228693
+ const presentKeys = /* @__PURE__ */ new Set;
228694
+ const hydratedCustomXmlPaths = /* @__PURE__ */ new Set;
228215
228695
  for (const [key2, value] of partsMap.entries()) {
228216
228696
  if (EXCLUDED_PART_IDS.has(key2))
228217
228697
  continue;
228698
+ presentKeys.add(key2);
228218
228699
  const partId = key2;
228219
228700
  const sectionId = isHeaderFooterPartId(key2) ? resolveHeaderFooterRId(key2, relsData, editor) ?? key2 : undefined;
228220
228701
  try {
@@ -228239,6 +228720,8 @@ function hydrateFromPartsMap(editor, ydoc, partsMap) {
228239
228720
  source: SOURCE_COLLAB_REMOTE_PARTS,
228240
228721
  initial: envelope.data
228241
228722
  });
228723
+ if (isCustomXmlPartPath(key2))
228724
+ hydratedCustomXmlPaths.add(key2);
228242
228725
  } catch (err) {
228243
228726
  const errorMsg = err instanceof Error ? err.message : String(err);
228244
228727
  if (CRITICAL_PART_IDS.has(key2))
@@ -228254,17 +228737,21 @@ function hydrateFromPartsMap(editor, ydoc, partsMap) {
228254
228737
  failures: criticalFailures
228255
228738
  };
228256
228739
  }
228257
- if (operations.length === 0)
228740
+ const customXmlPathsToTombstone = pruneAbsentCustomXmlParts(editor, presentKeys, operations);
228741
+ if (operations.length === 0) {
228742
+ applyCustomXmlHydrationTombstoneChanges(editor, customXmlPathsToTombstone, hydratedCustomXmlPaths);
228258
228743
  return {
228259
228744
  ok: true,
228260
228745
  failures: []
228261
228746
  };
228747
+ }
228262
228748
  try {
228263
228749
  mutateParts({
228264
228750
  editor,
228265
228751
  source: SOURCE_COLLAB_REMOTE_PARTS,
228266
228752
  operations
228267
228753
  });
228754
+ applyCustomXmlHydrationTombstoneChanges(editor, customXmlPathsToTombstone, hydratedCustomXmlPaths);
228268
228755
  return {
228269
228756
  ok: true,
228270
228757
  failures: []
@@ -228278,6 +228765,48 @@ function hydrateFromPartsMap(editor, ydoc, partsMap) {
228278
228765
  };
228279
228766
  }
228280
228767
  }
228768
+ function pruneAbsentCustomXmlParts(editor, presentKeys, operations) {
228769
+ const pathsToTombstone = /* @__PURE__ */ new Set;
228770
+ if (presentKeys.size === 0)
228771
+ return pathsToTombstone;
228772
+ const converter = getCustomXmlTombstoneConverter(editor);
228773
+ const convertedXml = converter?.convertedXml;
228774
+ if (!converter || !convertedXml)
228775
+ return pathsToTombstone;
228776
+ for (const key2 of Object.keys(convertedXml)) {
228777
+ if (EXCLUDED_PART_IDS.has(key2))
228778
+ continue;
228779
+ if (presentKeys.has(key2))
228780
+ continue;
228781
+ if (!isCustomXmlTombstonePath(editor, key2))
228782
+ continue;
228783
+ pathsToTombstone.add(key2);
228784
+ if (hasPart(editor, key2))
228785
+ operations.push({
228786
+ editor,
228787
+ partId: key2,
228788
+ operation: "delete",
228789
+ source: SOURCE_COLLAB_REMOTE_PARTS
228790
+ });
228791
+ }
228792
+ return pathsToTombstone;
228793
+ }
228794
+ function applyCustomXmlHydrationTombstoneChanges(editor, pathsToTombstone, pathsToClear) {
228795
+ if (pathsToTombstone.size === 0 && pathsToClear.size === 0)
228796
+ return;
228797
+ const converter = getCustomXmlTombstoneConverter(editor);
228798
+ if (!converter)
228799
+ return;
228800
+ for (const path2 of pathsToClear) {
228801
+ if (!converter.convertedXml || !Object.prototype.hasOwnProperty.call(converter.convertedXml, path2))
228802
+ continue;
228803
+ if (converter.removedCustomXmlPaths instanceof Set)
228804
+ converter.removedCustomXmlPaths.delete(path2);
228805
+ invalidateConverterCachesForPath(converter, path2);
228806
+ }
228807
+ for (const path2 of pathsToTombstone)
228808
+ recordCustomXmlTombstone(converter, path2);
228809
+ }
228281
228810
  function createNoopHandle() {
228282
228811
  return {
228283
228812
  publisher: null,
@@ -228306,7 +228835,7 @@ function backfillCapability(metaMap, ydoc) {
228306
228835
  metaMap.set(META_PARTS_CAPABILITY_KEY, capability);
228307
228836
  }
228308
228837
  function createReplacer(data) {
228309
- return ({ part }) => replacePartData(part, data);
228838
+ return ({ part }) => replacePartData$1(part, data);
228310
228839
  }
228311
228840
  function normalizeYjsFragmentForSchema(fragment2) {
228312
228841
  if (!isTraversableYjsXml(fragment2))
@@ -229069,11 +229598,11 @@ function syncSplitParagraphRunProperties(attrs, runProperties) {
229069
229598
  paragraphProperties: nextParagraphProperties
229070
229599
  };
229071
229600
  }
229072
- function getConverter$82(editor) {
229601
+ function getConverter$92(editor) {
229073
229602
  return editor.converter;
229074
229603
  }
229075
229604
  function readTranslatedLinkedStyles(editor) {
229076
- return getConverter$82(editor)?.translatedLinkedStyles ?? null;
229605
+ return getConverter$92(editor)?.translatedLinkedStyles ?? null;
229077
229606
  }
229078
229607
  function findRangeById(doc$12, id2) {
229079
229608
  let from$1 = null, to = null;
@@ -233735,18 +234264,18 @@ function readStringAttr2(node3, key2) {
233735
234264
  function attrsEqual(left$1, right$1) {
233736
234265
  const keys$1 = new Set([...Object.keys(left$1), ...Object.keys(right$1)]);
233737
234266
  for (const key2 of keys$1)
233738
- if (!valuesEqual(left$1[key2], right$1[key2]))
234267
+ if (!valuesEqual$1(left$1[key2], right$1[key2]))
233739
234268
  return false;
233740
234269
  return true;
233741
234270
  }
233742
- function valuesEqual(left$1, right$1) {
234271
+ function valuesEqual$1(left$1, right$1) {
233743
234272
  if (Object.is(left$1, right$1))
233744
234273
  return true;
233745
234274
  if (!isRecord$3(left$1) || !isRecord$3(right$1))
233746
234275
  return false;
233747
234276
  const keys$1 = new Set([...Object.keys(left$1), ...Object.keys(right$1)]);
233748
234277
  for (const key2 of keys$1)
233749
- if (!valuesEqual(left$1[key2], right$1[key2]))
234278
+ if (!valuesEqual$1(left$1[key2], right$1[key2]))
233750
234279
  return false;
233751
234280
  return true;
233752
234281
  }
@@ -239166,7 +239695,7 @@ function syncStylesDiffToConvertedXml(converter, stylesDiff) {
239166
239695
  }
239167
239696
  return true;
239168
239697
  }
239169
- function cloneValue2(value) {
239698
+ function cloneValue$1(value) {
239170
239699
  if (value === null || typeof value !== "object")
239171
239700
  return value;
239172
239701
  return structuredClone(value);
@@ -239190,7 +239719,7 @@ function setByPath(target, path2, value) {
239190
239719
  return;
239191
239720
  const leaf = segments.pop();
239192
239721
  const parent = ensureParentObject(target, segments);
239193
- parent[leaf] = cloneValue2(value);
239722
+ parent[leaf] = cloneValue$1(value);
239194
239723
  }
239195
239724
  function pruneEmptyParents(root3, segments) {
239196
239725
  for (let idx = segments.length - 1;idx >= 0; idx -= 1) {
@@ -244417,7 +244946,7 @@ function makeTrackedChangeAnchorKey(ref$1) {
244417
244946
  function makeCommentAnchorKey(commentId) {
244418
244947
  return `${COMMENT_ANCHOR_KEY_PREFIX}${commentId}`;
244419
244948
  }
244420
- function getConverter$72(editor) {
244949
+ function getConverter$82(editor) {
244421
244950
  return editor.converter;
244422
244951
  }
244423
244952
  function toRevisionCapableNoteId(note) {
@@ -244434,7 +244963,7 @@ function enumerateRevisionCapableStories(editor) {
244434
244963
  kind: "story",
244435
244964
  storyType: "body"
244436
244965
  }];
244437
- const converter = getConverter$72(editor);
244966
+ const converter = getConverter$82(editor);
244438
244967
  if (!converter)
244439
244968
  return stories;
244440
244969
  if (converter.headers)
@@ -255954,10 +256483,10 @@ function registerBuiltInExecutors() {
255954
256483
  };
255955
256484
  } });
255956
256485
  }
255957
- function getConverter$62(editor) {
256486
+ function getConverter$72(editor) {
255958
256487
  return editor.converter;
255959
256488
  }
255960
- function getConverter$52(editor) {
256489
+ function getConverter$62(editor) {
255961
256490
  return editor.converter;
255962
256491
  }
255963
256492
  function createEmptyHeaderFooterJson() {
@@ -255970,7 +256499,7 @@ function createEmptyHeaderFooterJson() {
255970
256499
  };
255971
256500
  }
255972
256501
  function syncHeaderFooterCaches(editor, part) {
255973
- const converter = getConverter$52(editor);
256502
+ const converter = getConverter$62(editor);
255974
256503
  if (!converter)
255975
256504
  return;
255976
256505
  const relsRoot = getRelationshipsRoot(part);
@@ -256032,7 +256561,7 @@ function createTableWrapper(editor, input2, options) {
256032
256561
  });
256033
256562
  return adapterResult;
256034
256563
  }
256035
- function getConverter$42(editor) {
256564
+ function getConverter$52(editor) {
256036
256565
  return editor.converter;
256037
256566
  }
256038
256567
  function toSectionFailure2(code6, message) {
@@ -256100,7 +256629,7 @@ function buildSectionMarginsForAttrs2(sectPr) {
256100
256629
  };
256101
256630
  }
256102
256631
  function syncConverterBodySection2(editor, sectPr) {
256103
- const converter = getConverter$42(editor);
256632
+ const converter = getConverter$52(editor);
256104
256633
  if (!converter)
256105
256634
  return;
256106
256635
  converter.bodySectPr = cloneXmlElement(sectPr);
@@ -256220,7 +256749,7 @@ function createSectionBreakNode(editor, breakParagraphId, input2) {
256220
256749
  return paragraphNode;
256221
256750
  }
256222
256751
  function updateGlobalTitlePageFlag(editor) {
256223
- const converter = getConverter$42(editor);
256752
+ const converter = getConverter$52(editor);
256224
256753
  if (!converter)
256225
256754
  return;
256226
256755
  const anyTitlePage = resolveSectionProjections(editor).some((entry) => entry.domain.titlePage === true);
@@ -256304,7 +256833,7 @@ function sectionsSetTitlePageAdapter(editor, input2, options) {
256304
256833
  }
256305
256834
  function sectionsSetOddEvenHeadersFootersAdapter(editor, input2, options) {
256306
256835
  rejectTrackedMode("sections.setOddEvenHeadersFooters", options);
256307
- const converter = getConverter$42(editor);
256836
+ const converter = getConverter$52(editor);
256308
256837
  if (!converter)
256309
256838
  throw new DocumentApiAdapterError("CAPABILITY_UNAVAILABLE", "sections.setOddEvenHeadersFooters requires an active document converter.");
256310
256839
  return mutatePart({
@@ -256340,13 +256869,13 @@ function sectionsSetSectionDirectionAdapter(editor, input2, options) {
256340
256869
  }
256341
256870
  function sectionsSetHeaderFooterRefAdapter(editor, input2, options) {
256342
256871
  return sectionMutationBySectPr$1(editor, input2, options, "sections.setHeaderFooterRef", (sectPr, _projection, _sections, dryRun) => {
256343
- const converter = getConverter$42(editor) ?? null;
256872
+ const converter = getConverter$52(editor) ?? null;
256344
256873
  return setHeaderFooterRefMutation(sectPr, input2.kind, input2.variant, input2.refId, converter, "sections.setHeaderFooterRef", dryRun);
256345
256874
  });
256346
256875
  }
256347
256876
  function sectionsClearHeaderFooterRefAdapter(editor, input2, options) {
256348
256877
  return sectionMutationBySectPr$1(editor, input2, options, "sections.clearHeaderFooterRef", (sectPr, _projection, _sections, dryRun) => {
256349
- const converter = getConverter$42(editor) ?? null;
256878
+ const converter = getConverter$52(editor) ?? null;
256350
256879
  clearHeaderFooterRefMutation(sectPr, input2.kind, input2.variant, converter, dryRun);
256351
256880
  });
256352
256881
  }
@@ -260195,11 +260724,11 @@ function createContentControlsAdapter(editor) {
260195
260724
  create: (input2, options) => createWrapper(editor, input2, options)
260196
260725
  };
260197
260726
  }
260198
- function getConverter$32(editor) {
260727
+ function getConverter$42(editor) {
260199
260728
  return editor.converter;
260200
260729
  }
260201
260730
  function requireConverter$1(editor, operationName) {
260202
- const converter = getConverter$32(editor);
260731
+ const converter = getConverter$42(editor);
260203
260732
  if (!converter)
260204
260733
  throw new DocumentApiAdapterError("CAPABILITY_UNAVAILABLE", `${operationName} requires an active document converter.`);
260205
260734
  return converter;
@@ -260305,7 +260834,7 @@ function headerFootersResolveAdapter(editor, input2) {
260305
260834
  function headerFootersRefsSetAdapter(editor, input2, options) {
260306
260835
  const { section, headerFooterKind, variant } = input2.target;
260307
260836
  const result = sectionMutationBySectPr(editor, { target: section }, options, "headerFooters.refs.set", (sectPr, _projection, _sections, dryRun) => {
260308
- const converter = getConverter$32(editor) ?? null;
260837
+ const converter = getConverter$42(editor) ?? null;
260309
260838
  return setHeaderFooterRefMutation(sectPr, headerFooterKind, variant, input2.refId, converter, "headerFooters.refs.set", dryRun);
260310
260839
  });
260311
260840
  invalidateSlotRuntimesAfterRefChange(editor, result, options);
@@ -260314,7 +260843,7 @@ function headerFootersRefsSetAdapter(editor, input2, options) {
260314
260843
  function headerFootersRefsClearAdapter(editor, input2, options) {
260315
260844
  const { section, headerFooterKind, variant } = input2.target;
260316
260845
  const result = sectionMutationBySectPr(editor, { target: section }, options, "headerFooters.refs.clear", (sectPr, _projection, _sections, dryRun) => {
260317
- clearHeaderFooterRefMutation(sectPr, headerFooterKind, variant, getConverter$32(editor) ?? null, dryRun);
260846
+ clearHeaderFooterRefMutation(sectPr, headerFooterKind, variant, getConverter$42(editor) ?? null, dryRun);
260318
260847
  });
260319
260848
  invalidateSlotRuntimesAfterRefChange(editor, result, options);
260320
260849
  return result;
@@ -261135,389 +261664,136 @@ function executeOutOfBandMutation(editor, mutateFn, options) {
261135
261664
  }
261136
261665
  return result.payload;
261137
261666
  }
261138
- function getLocalName2(name) {
261139
- if (!name || typeof name !== "string")
261140
- return "";
261141
- const i3 = name.indexOf(":");
261142
- return i3 >= 0 ? name.slice(i3 + 1) : name;
261143
- }
261144
- function findFirstElement(parent, localName$2) {
261145
- if (!parent?.elements?.length)
261146
- return null;
261147
- return parent.elements.find((el) => el?.type === "element" && getLocalName2(el.name) === localName$2) ?? null;
261148
- }
261149
- function findAllElements(parent, localName$2) {
261150
- if (!parent?.elements?.length)
261151
- return [];
261152
- return parent.elements.filter((el) => el?.type === "element" && getLocalName2(el.name) === localName$2);
261153
- }
261154
- function partNameFromIndex(index2) {
261155
- return `customXml/item${index2}.xml`;
261156
- }
261157
- function propsPartNameFromIndex(index2) {
261158
- return `customXml/itemProps${index2}.xml`;
261667
+ function getConverter$32(editor) {
261668
+ const converter = editor.converter;
261669
+ if (!converter?.convertedXml)
261670
+ throw new Error("Custom XML part mutation requires editor.converter.convertedXml.");
261671
+ return converter;
261159
261672
  }
261160
- function indexFromPartName(partName) {
261161
- const m$1 = /^customXml\/item(\d+)\.xml$/i.exec(partName ?? "");
261162
- return m$1 ? Number.parseInt(m$1[1], 10) : null;
261673
+ function cloneValue2(value) {
261674
+ return structuredClone(value);
261163
261675
  }
261164
- function indexFromPropsPartName(propsPartName) {
261165
- const m$1 = /^customXml\/itemProps(\d+)\.xml$/i.exec(propsPartName ?? "");
261166
- return m$1 ? Number.parseInt(m$1[1], 10) : null;
261676
+ function hasOwn(record, key2) {
261677
+ return Object.prototype.hasOwnProperty.call(record, key2);
261167
261678
  }
261168
- function isCustomXmlStoragePartName(partName) {
261169
- return indexFromPartName(partName) != null;
261679
+ function valuesEqual(left$1, right$1) {
261680
+ return JSON.stringify(left$1) === JSON.stringify(right$1);
261170
261681
  }
261171
- function listCustomXmlStoragePartNames(convertedXml) {
261172
- if (!convertedXml || typeof convertedXml !== "object")
261173
- return [];
261174
- const indexes = [];
261175
- for (const path2 of Object.keys(convertedXml)) {
261176
- const idx = indexFromPartName(path2);
261177
- if (idx != null)
261178
- indexes.push(idx);
261179
- }
261180
- indexes.sort((a2, b$1) => a2 - b$1);
261181
- return indexes.map(partNameFromIndex);
261682
+ function toPartId(path2) {
261683
+ return path2;
261182
261684
  }
261183
- function findPropsPartFor(convertedXml, partName) {
261184
- if (!convertedXml)
261185
- return null;
261186
- const idx = indexFromPartName(partName);
261187
- if (idx == null)
261188
- return null;
261189
- const relsRoot = convertedXml[`customXml/_rels/item${idx}.xml.rels`]?.elements?.find((el) => getLocalName2(el?.name) === "Relationships");
261190
- if (relsRoot?.elements?.length)
261191
- for (const rel of relsRoot.elements) {
261192
- if (rel?.attributes?.Type !== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXmlProps")
261193
- continue;
261194
- const target = rel?.attributes?.Target;
261195
- if (typeof target !== "string" || target.length === 0)
261196
- continue;
261197
- const candidate = resolveOpcTargetPath(target, "customXml");
261198
- if (candidate && convertedXml[candidate])
261199
- return candidate;
261685
+ function replacePartData(target, source) {
261686
+ if (!target || typeof target !== "object" || !source || typeof source !== "object")
261687
+ throw new Error("Custom XML part mutation can only replace object-shaped XML parts.");
261688
+ const targetRecord = target;
261689
+ const sourceRecord = source;
261690
+ for (const key2 of Object.keys(targetRecord))
261691
+ if (!hasOwn(sourceRecord, key2))
261692
+ delete targetRecord[key2];
261693
+ for (const [key2, value] of Object.entries(sourceRecord))
261694
+ targetRecord[key2] = cloneValue2(value);
261695
+ }
261696
+ function createSandboxConverter(converter) {
261697
+ const sandbox = { convertedXml: cloneValue2(converter.convertedXml ?? {}) };
261698
+ if (converter.removedCustomXmlPaths instanceof Set)
261699
+ sandbox.removedCustomXmlPaths = new Set(converter.removedCustomXmlPaths);
261700
+ if (converter.bibliographyPart !== undefined)
261701
+ sandbox.bibliographyPart = cloneValue2(converter.bibliographyPart);
261702
+ return sandbox;
261703
+ }
261704
+ function createDeltaOperations(editor, source, before2, after2) {
261705
+ const paths = new Set([...Object.keys(before2), ...Object.keys(after2)]);
261706
+ const operations = [];
261707
+ for (const path2 of paths) {
261708
+ const existedBefore = hasOwn(before2, path2);
261709
+ const existsAfter = hasOwn(after2, path2);
261710
+ const partId = toPartId(path2);
261711
+ if (!existedBefore && existsAfter) {
261712
+ operations.push({
261713
+ editor,
261714
+ partId,
261715
+ operation: "create",
261716
+ source,
261717
+ initial: cloneValue2(after2[path2])
261718
+ });
261719
+ continue;
261200
261720
  }
261201
- const indexCandidate = propsPartNameFromIndex(idx);
261202
- return convertedXml[indexCandidate] ? indexCandidate : null;
261203
- }
261204
- function parsePropsPart(propsDoc) {
261205
- const root3 = propsDoc?.elements?.find((el) => el?.type === "element" && getLocalName2(el.name) === "datastoreItem");
261206
- if (!root3)
261207
- return null;
261208
- const itemId = root3.attributes?.["ds:itemID"] ?? root3.attributes?.itemID ?? null;
261209
- const schemaRefs = findAllElements(findFirstElement(root3, "schemaRefs"), "schemaRef").map((el) => el.attributes?.["ds:uri"] ?? el.attributes?.uri ?? null).filter((uri) => typeof uri === "string" && uri.length > 0);
261210
- return {
261211
- itemId: typeof itemId === "string" && itemId.length > 0 ? itemId : null,
261212
- schemaRefs
261213
- };
261214
- }
261215
- function parseStoragePartRootNamespace(storageDoc) {
261216
- const root3 = storageDoc?.elements?.find((el) => el?.type === "element");
261217
- if (!root3)
261218
- return null;
261219
- const xmlns2 = root3.attributes?.xmlns;
261220
- if (typeof xmlns2 === "string" && xmlns2.length > 0)
261221
- return xmlns2;
261222
- const elementName = root3.name ?? "";
261223
- const colonIdx = elementName.indexOf(":");
261224
- if (colonIdx > 0) {
261225
- const prefixedAttr = `xmlns:${elementName.slice(0, colonIdx)}`;
261226
- const prefixedValue = root3.attributes?.[prefixedAttr];
261227
- if (typeof prefixedValue === "string" && prefixedValue.length > 0)
261228
- return prefixedValue;
261229
- }
261230
- return null;
261231
- }
261232
- function serializeXmlDoc(xmlDoc) {
261233
- if (!xmlDoc)
261234
- return "";
261235
- return import_lib4.js2xml(xmlDoc, {
261236
- compact: false,
261237
- spaces: 0
261238
- });
261239
- }
261240
- function readCustomXmlPart(convertedXml, target) {
261241
- if (!target || !convertedXml)
261242
- return null;
261243
- let partName = null;
261244
- let itemId = null;
261245
- if (typeof target.partName === "string" && target.partName.length > 0) {
261246
- if (!isCustomXmlStoragePartName(target.partName))
261247
- return null;
261248
- partName = target.partName;
261249
- } else if (typeof target.id === "string" && target.id.length > 0) {
261250
- itemId = target.id;
261251
- for (const candidatePartName of listCustomXmlStoragePartNames(convertedXml)) {
261252
- const propsName = findPropsPartFor(convertedXml, candidatePartName);
261253
- if (!propsName)
261254
- continue;
261255
- if (parsePropsPart(convertedXml[propsName])?.itemId === itemId) {
261256
- partName = candidatePartName;
261257
- break;
261258
- }
261721
+ if (existedBefore && !existsAfter) {
261722
+ operations.push({
261723
+ editor,
261724
+ partId,
261725
+ operation: "delete",
261726
+ source
261727
+ });
261728
+ continue;
261729
+ }
261730
+ if (existedBefore && existsAfter && !valuesEqual(before2[path2], after2[path2])) {
261731
+ const nextPart = cloneValue2(after2[path2]);
261732
+ operations.push({
261733
+ editor,
261734
+ partId,
261735
+ operation: "mutate",
261736
+ source,
261737
+ mutate: ({ part }) => replacePartData(part, nextPart)
261738
+ });
261259
261739
  }
261260
- if (!partName)
261261
- return null;
261262
- } else
261263
- return null;
261264
- const storageDoc = convertedXml[partName];
261265
- if (!storageDoc)
261266
- return null;
261267
- const propsPartName = findPropsPartFor(convertedXml, partName);
261268
- const props = propsPartName ? parsePropsPart(convertedXml[propsPartName]) : null;
261269
- return {
261270
- id: props?.itemId ?? null,
261271
- partName,
261272
- propsPartName: propsPartName ?? null,
261273
- rootNamespace: parseStoragePartRootNamespace(storageDoc),
261274
- schemaRefs: props?.schemaRefs ?? [],
261275
- content: serializeXmlDoc(storageDoc)
261276
- };
261277
- }
261278
- function listCustomXmlParts(convertedXml) {
261279
- return listCustomXmlStoragePartNames(convertedXml).map((partName) => {
261280
- const propsPartName = findPropsPartFor(convertedXml, partName);
261281
- const props = propsPartName ? parsePropsPart(convertedXml[propsPartName]) : null;
261282
- return {
261283
- id: props?.itemId ?? null,
261284
- partName,
261285
- propsPartName: propsPartName ?? null,
261286
- rootNamespace: parseStoragePartRootNamespace(convertedXml[partName]),
261287
- schemaRefs: props?.schemaRefs ?? []
261288
- };
261289
- });
261290
- }
261291
- function nextCustomXmlItemIndex(convertedXml, converter) {
261292
- const used = /* @__PURE__ */ new Set;
261293
- for (const path2 of Object.keys(convertedXml ?? {})) {
261294
- const idx = indexFromPartName(path2) ?? indexFromPropsPartName(path2);
261295
- if (idx != null)
261296
- used.add(idx);
261297
- }
261298
- let candidate = 1;
261299
- while (used.has(candidate))
261300
- candidate += 1;
261301
- return candidate;
261302
- }
261303
- function createXmlDocument2(rootElement$1, declaration) {
261304
- const nextDeclaration = declaration ?? DEFAULT_XML_DECLARATION;
261305
- return {
261306
- declaration: {
261307
- ...nextDeclaration,
261308
- attributes: { ...nextDeclaration.attributes }
261309
- },
261310
- elements: [rootElement$1]
261311
- };
261312
- }
261313
- function parseContentToRootElement(content3) {
261314
- const parsed = import_lib4.xml2js(content3, { compact: false });
261315
- const root3 = (parsed.elements ?? []).find((el) => el?.type === "element");
261316
- if (!root3)
261317
- throw new Error("Custom XML content is missing a root element.");
261318
- return {
261319
- root: root3,
261320
- declaration: parsed.declaration ?? null
261321
- };
261322
- }
261323
- function ensureDocumentRelationshipsRoot2(convertedXml) {
261324
- if (!convertedXml["word/_rels/document.xml.rels"])
261325
- convertedXml["word/_rels/document.xml.rels"] = createXmlDocument2({
261326
- type: "element",
261327
- name: "Relationships",
261328
- attributes: { xmlns: "http://schemas.openxmlformats.org/package/2006/relationships" },
261329
- elements: []
261330
- });
261331
- const relsData = convertedXml["word/_rels/document.xml.rels"];
261332
- relsData.elements ??= [];
261333
- let relsRoot = relsData.elements.find((el) => getLocalName2(el?.name) === "Relationships");
261334
- if (!relsRoot) {
261335
- relsRoot = {
261336
- type: "element",
261337
- name: "Relationships",
261338
- attributes: { xmlns: "http://schemas.openxmlformats.org/package/2006/relationships" },
261339
- elements: []
261340
- };
261341
- relsData.elements.push(relsRoot);
261342
261740
  }
261343
- relsRoot.elements ??= [];
261344
- return relsRoot;
261345
- }
261346
- function getNextRelationshipId2(relsRoot) {
261347
- const used = (relsRoot?.elements ?? []).map((rel) => {
261348
- const id2 = rel?.attributes?.Id;
261349
- const m$1 = typeof id2 === "string" ? /^rId(\d+)$/.exec(id2) : null;
261350
- return m$1 ? Number.parseInt(m$1[1], 10) : NaN;
261351
- }).filter((n) => Number.isFinite(n));
261352
- return `rId${(used.length > 0 ? Math.max(...used) : 0) + 1}`;
261353
- }
261354
- function buildDocumentRelTarget(partName) {
261355
- return partName.startsWith("customXml/") ? `../${partName}` : partName;
261356
- }
261357
- function buildItemPropsRoot(itemId, schemaRefs) {
261358
- return [{
261359
- type: "element",
261360
- name: "ds:datastoreItem",
261361
- attributes: {
261362
- "ds:itemID": itemId,
261363
- "xmlns:ds": CUSTOM_XML_DATASTORE_NAMESPACE
261364
- },
261365
- elements: schemaRefs === undefined ? [] : [{
261366
- type: "element",
261367
- name: "ds:schemaRefs",
261368
- elements: schemaRefs.map((uri) => ({
261369
- type: "element",
261370
- name: "ds:schemaRef",
261371
- attributes: { "ds:uri": uri }
261372
- }))
261373
- }]
261374
- }][0];
261741
+ return operations;
261375
261742
  }
261376
- function buildItemRelsRoot(propsPartFileName) {
261743
+ function applyConverterState(editor, prepared) {
261744
+ const converter = getConverter$32(editor);
261745
+ const nextRemovedCustomXmlPaths = prepared.removedCustomXmlPaths ? new Set(prepared.removedCustomXmlPaths) : undefined;
261746
+ const nextBibliographyPart = prepared.hasBibliographyPart ? cloneValue2(prepared.bibliographyPart) : undefined;
261747
+ if (nextRemovedCustomXmlPaths)
261748
+ converter.removedCustomXmlPaths = nextRemovedCustomXmlPaths;
261749
+ if (prepared.hasBibliographyPart)
261750
+ converter.bibliographyPart = nextBibliographyPart;
261751
+ }
261752
+ function prepareCustomXmlPartMutation(editor, mutate, source = "customXml.parts") {
261753
+ const converter = getConverter$32(editor);
261754
+ const before2 = converter.convertedXml ?? {};
261755
+ const sandbox = createSandboxConverter(converter);
261756
+ const result = mutate(sandbox.convertedXml, sandbox);
261757
+ const operations = createDeltaOperations(editor, source, before2, sandbox.convertedXml);
261377
261758
  return {
261378
- type: "element",
261379
- name: "Relationships",
261380
- attributes: { xmlns: "http://schemas.openxmlformats.org/package/2006/relationships" },
261381
- elements: [{
261382
- type: "element",
261383
- name: "Relationship",
261384
- attributes: {
261385
- Id: "rId1",
261386
- Type: CUSTOM_XML_PROPS_RELATIONSHIP_TYPE2,
261387
- Target: propsPartFileName
261388
- }
261389
- }]
261759
+ result,
261760
+ operations,
261761
+ affectedParts: operations.map((operation) => operation.partId),
261762
+ removedCustomXmlPaths: sandbox.removedCustomXmlPaths,
261763
+ bibliographyPart: sandbox.bibliographyPart,
261764
+ hasBibliographyPart: Object.prototype.hasOwnProperty.call(sandbox, "bibliographyPart")
261390
261765
  };
261391
261766
  }
261392
- function resolveTargetPartName(convertedXml, target) {
261393
- if (!target)
261394
- return null;
261395
- if (typeof target.partName === "string" && target.partName.length > 0) {
261396
- if (!isCustomXmlStoragePartName(target.partName))
261397
- return null;
261398
- return convertedXml[target.partName] ? target.partName : null;
261767
+ function commitPreparedCustomXmlPartMutation(editor, prepared, options) {
261768
+ if (prepared.operations.length === 0) {
261769
+ checkRevision(editor, options.expectedRevision);
261770
+ applyConverterState(editor, prepared);
261771
+ return prepared.result;
261399
261772
  }
261400
- if (typeof target.id === "string" && target.id.length > 0)
261401
- for (const partName of listCustomXmlStoragePartNames(convertedXml)) {
261402
- const propsName = findPropsPartFor(convertedXml, partName);
261403
- if (!propsName)
261404
- continue;
261405
- if (parsePropsPart(convertedXml[propsName])?.itemId === target.id)
261406
- return partName;
261773
+ if (compoundMutation({
261774
+ editor,
261775
+ source: options.source,
261776
+ affectedParts: prepared.affectedParts,
261777
+ execute() {
261778
+ return mutateParts({
261779
+ editor,
261780
+ source: options.source,
261781
+ expectedRevision: options.expectedRevision,
261782
+ operations: prepared.operations.map((operation) => ({
261783
+ ...operation,
261784
+ source: options.source
261785
+ }))
261786
+ }).changed;
261407
261787
  }
261408
- return null;
261788
+ }).success)
261789
+ applyConverterState(editor, prepared);
261790
+ return prepared.result;
261409
261791
  }
261410
- function createCustomXmlPart(convertedXml, { content: content3, schemaRefs }, converter) {
261411
- const { root: root3, declaration } = parseContentToRootElement(content3);
261412
- const index2 = nextCustomXmlItemIndex(convertedXml, converter);
261413
- const partName = partNameFromIndex(index2);
261414
- const propsPartName = propsPartNameFromIndex(index2);
261415
- const itemRelsPath = `customXml/_rels/item${index2}.xml.rels`;
261416
- const itemId = `{${v4_default().toUpperCase()}}`;
261417
- convertedXml[partName] = createXmlDocument2(root3, declaration);
261418
- convertedXml[propsPartName] = createXmlDocument2(buildItemPropsRoot(itemId, schemaRefs));
261419
- convertedXml[itemRelsPath] = createXmlDocument2(buildItemRelsRoot(`itemProps${index2}.xml`));
261420
- const relsRoot = ensureDocumentRelationshipsRoot2(convertedXml);
261421
- relsRoot.elements.push({
261422
- type: "element",
261423
- name: "Relationship",
261424
- attributes: {
261425
- Id: getNextRelationshipId2(relsRoot),
261426
- Type: CUSTOM_XML_DATA_RELATIONSHIP_TYPE,
261427
- Target: buildDocumentRelTarget(partName)
261428
- }
261792
+ function mutateCustomXmlParts(editor, source, mutate, options) {
261793
+ return commitPreparedCustomXmlPartMutation(editor, prepareCustomXmlPartMutation(editor, mutate, source), {
261794
+ source,
261795
+ expectedRevision: options?.expectedRevision
261429
261796
  });
261430
- if (converter?.removedCustomXmlPaths instanceof Set) {
261431
- converter.removedCustomXmlPaths.delete(partName);
261432
- converter.removedCustomXmlPaths.delete(propsPartName);
261433
- converter.removedCustomXmlPaths.delete(itemRelsPath);
261434
- }
261435
- return {
261436
- id: itemId,
261437
- partName,
261438
- propsPartName
261439
- };
261440
- }
261441
- function patchCustomXmlPart(convertedXml, target, { content: content3, schemaRefs }, converter) {
261442
- const partName = resolveTargetPartName(convertedXml, target);
261443
- if (!partName)
261444
- return null;
261445
- if (content3 !== undefined) {
261446
- const { root: root3, declaration } = parseContentToRootElement(content3);
261447
- convertedXml[partName] = createXmlDocument2(root3, convertedXml[partName]?.declaration ?? declaration);
261448
- }
261449
- let resolvedId = null;
261450
- if (schemaRefs !== undefined) {
261451
- let propsPartName = findPropsPartFor(convertedXml, partName);
261452
- if (propsPartName)
261453
- resolvedId = parsePropsPart(convertedXml[propsPartName])?.itemId ?? null;
261454
- if (!propsPartName) {
261455
- const idx = indexFromPartName(partName);
261456
- if (idx == null)
261457
- return null;
261458
- propsPartName = propsPartNameFromIndex(idx);
261459
- const itemRelsPath = `customXml/_rels/item${idx}.xml.rels`;
261460
- resolvedId = `{${v4_default().toUpperCase()}}`;
261461
- convertedXml[itemRelsPath] = createXmlDocument2(buildItemRelsRoot(`itemProps${idx}.xml`));
261462
- }
261463
- if (!resolvedId)
261464
- resolvedId = `{${v4_default().toUpperCase()}}`;
261465
- const existingDecl = convertedXml[propsPartName]?.declaration;
261466
- convertedXml[propsPartName] = createXmlDocument2(buildItemPropsRoot(resolvedId, schemaRefs), existingDecl);
261467
- } else {
261468
- const propsPartName = findPropsPartFor(convertedXml, partName);
261469
- if (propsPartName)
261470
- resolvedId = parsePropsPart(convertedXml[propsPartName])?.itemId ?? null;
261471
- }
261472
- if (converter)
261473
- invalidateConverterCachesForPath(converter, partName);
261474
- return resolvedId ? {
261475
- partName,
261476
- id: resolvedId
261477
- } : { partName };
261478
- }
261479
- function removeCustomXmlPart(convertedXml, target, converter) {
261480
- const partName = resolveTargetPartName(convertedXml, target);
261481
- if (!partName)
261482
- return false;
261483
- const index2 = indexFromPartName(partName);
261484
- const removedPaths = [
261485
- partName,
261486
- findPropsPartFor(convertedXml, partName),
261487
- index2 == null ? null : `customXml/_rels/item${index2}.xml.rels`
261488
- ].filter((path2) => typeof path2 === "string" && path2.length > 0);
261489
- for (const path2 of removedPaths)
261490
- delete convertedXml[path2];
261491
- const relsRoot = convertedXml["word/_rels/document.xml.rels"]?.elements?.find((el) => getLocalName2(el?.name) === "Relationships");
261492
- if (relsRoot?.elements?.length)
261493
- relsRoot.elements = relsRoot.elements.filter((rel) => {
261494
- if (rel?.attributes?.Type !== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml")
261495
- return true;
261496
- return resolveOpcTargetPath(rel?.attributes?.Target, "word") !== partName;
261497
- });
261498
- if (converter) {
261499
- if (!(converter.removedCustomXmlPaths instanceof Set))
261500
- converter.removedCustomXmlPaths = /* @__PURE__ */ new Set;
261501
- for (const path2 of removedPaths)
261502
- converter.removedCustomXmlPaths.add(path2);
261503
- invalidateConverterCachesForPath(converter, partName);
261504
- }
261505
- return true;
261506
- }
261507
- function invalidateConverterCachesForPath(converter, partName) {
261508
- if (!converter || typeof partName !== "string")
261509
- return;
261510
- const biblio = converter.bibliographyPart;
261511
- if (biblio && biblio.partPath === partName)
261512
- converter.bibliographyPart = {
261513
- sources: [],
261514
- partPath: null,
261515
- itemPropsPath: null,
261516
- itemRelsPath: null,
261517
- selectedStyle: null,
261518
- styleName: null,
261519
- version: null
261520
- };
261521
261797
  }
261522
261798
  function getConverter$22(editor) {
261523
261799
  return editor.converter ?? null;
@@ -261635,20 +261911,20 @@ function customXmlPartsCreateWrapper(editor, input2, options) {
261635
261911
  }
261636
261912
  };
261637
261913
  }
261638
- const probe = safeValidate(() => createCustomXmlPart(getConvertedXml$1(editor), {
261914
+ const probe = safeValidate(() => prepareCustomXmlPartMutation(editor, (convertedXml, converter) => createCustomXmlPart(convertedXml, {
261639
261915
  content: input2.content,
261640
261916
  schemaRefs: input2.schemaRefs
261641
- }, getConverter$22(editor)));
261917
+ }, converter), "customXml.parts.create"));
261642
261918
  if (isWriteFailure(probe))
261643
261919
  return {
261644
261920
  changed: false,
261645
261921
  payload: probe
261646
261922
  };
261647
261923
  return {
261648
- changed: true,
261924
+ changed: false,
261649
261925
  payload: {
261650
261926
  ok: true,
261651
- payload: probe.payload
261927
+ payload: commitPreparedCustomXmlPartMutation(editor, probe.payload, { source: "customXml.parts.create" })
261652
261928
  }
261653
261929
  };
261654
261930
  }, {
@@ -261697,25 +261973,25 @@ function customXmlPartsPatchWrapper(editor, input2, options) {
261697
261973
  changed: false,
261698
261974
  payload: targetNotFound()
261699
261975
  };
261700
- const probe = safeValidate(() => patchCustomXmlPart(getConvertedXml$1(editor), input2.target, {
261976
+ const probe = safeValidate(() => prepareCustomXmlPartMutation(editor, (convertedXml, converter) => patchCustomXmlPart(convertedXml, input2.target, {
261701
261977
  content: input2.content,
261702
261978
  schemaRefs: input2.schemaRefs
261703
- }, getConverter$22(editor)));
261979
+ }, converter), "customXml.parts.patch"));
261704
261980
  if (isWriteFailure(probe))
261705
261981
  return {
261706
261982
  changed: false,
261707
261983
  payload: probe
261708
261984
  };
261709
- if (!probe.payload)
261985
+ if (!probe.payload.result)
261710
261986
  return {
261711
261987
  changed: false,
261712
261988
  payload: targetNotFound()
261713
261989
  };
261714
261990
  return {
261715
- changed: true,
261991
+ changed: false,
261716
261992
  payload: {
261717
261993
  ok: true,
261718
- payload: { id: probe.payload.id ?? null }
261994
+ payload: { id: commitPreparedCustomXmlPartMutation(editor, probe.payload, { source: "customXml.parts.patch" }).id ?? null }
261719
261995
  }
261720
261996
  };
261721
261997
  }, {
@@ -261746,13 +262022,15 @@ function customXmlPartsRemoveWrapper(editor, input2, options) {
261746
262022
  changed: false,
261747
262023
  payload: targetNotFound()
261748
262024
  };
261749
- if (!removeCustomXmlPart(getConvertedXml$1(editor), input2.target, getConverter$22(editor)))
262025
+ const probe = prepareCustomXmlPartMutation(editor, (convertedXml, converter) => removeCustomXmlPart(convertedXml, input2.target, converter), "customXml.parts.remove");
262026
+ if (!probe.result)
261750
262027
  return {
261751
262028
  changed: false,
261752
262029
  payload: targetNotFound()
261753
262030
  };
262031
+ commitPreparedCustomXmlPartMutation(editor, probe, { source: "customXml.parts.remove" });
261754
262032
  return {
261755
- changed: true,
262033
+ changed: false,
261756
262034
  payload: {
261757
262035
  ok: true,
261758
262036
  payload: true
@@ -261937,6 +262215,7 @@ function wrapRangeInAnchor(editor, target, id2) {
261937
262215
  const { absFrom, absTo } = resolveSelectionTarget(editor, target);
261938
262216
  if (absFrom >= absTo)
261939
262217
  throw new DocumentApiAdapterError("INVALID_TARGET", "metadata.attach requires a non-empty text range.");
262218
+ assertNoOverlappingMetadataAnchor(editor, absFrom, absTo);
261940
262219
  const nodeType = editor.schema.nodes[SDT_INLINE_NAME];
261941
262220
  if (!nodeType)
261942
262221
  throw new DocumentApiAdapterError("CAPABILITY_UNAVAILABLE", "Inline content-control node is not available.");
@@ -261953,7 +262232,8 @@ function wrapRangeInAnchor(editor, target, id2) {
261953
262232
  const selectedContent = parentRun.content.cut($from.parentOffset, $to.parentOffset);
261954
262233
  const leftContent = parentRun.content.cut(0, $from.parentOffset);
261955
262234
  const rightContent = parentRun.content.cut($to.parentOffset);
261956
- const sdtNode = nodeType.create(attrs, selectedContent);
262235
+ const sdtContent = runType.create(parentRun.attrs, selectedContent, parentRun.marks);
262236
+ const sdtNode = nodeType.create(attrs, sdtContent);
261957
262237
  const replacement = [];
261958
262238
  if (leftContent.size > 0)
261959
262239
  replacement.push(runType.create(parentRun.attrs, leftContent, parentRun.marks));
@@ -261974,8 +262254,13 @@ function unwrapAnchor(editor, id2) {
261974
262254
  const anchor = findAnchorsById(editor, id2)[0];
261975
262255
  if (!anchor)
261976
262256
  return false;
262257
+ const { selection } = editor.state;
261977
262258
  const { tr } = editor.state;
261978
- tr.replaceWith(anchor.pos, anchor.pos + anchor.node.nodeSize, anchor.node.content);
262259
+ const from$1 = anchor.pos;
262260
+ const to = from$1 + anchor.node.nodeSize;
262261
+ tr.replaceWith(from$1, to, anchor.node.content);
262262
+ if (selection.from < to && from$1 < selection.to)
262263
+ tr.setSelection(TextSelection.create(tr.doc, tr.mapping.map(from$1, -1)));
261979
262264
  dispatchTransaction2(editor, tr);
261980
262265
  clearIndexCache(editor);
261981
262266
  return true;
@@ -262011,6 +262296,30 @@ function rangesOverlap$1(aFrom, aTo, bFrom, bTo) {
262011
262296
  return aFrom <= bTo && bFrom <= aTo;
262012
262297
  return aFrom < bTo && bFrom < aTo;
262013
262298
  }
262299
+ function isMetadataAnchorNode(metadataIds, node3) {
262300
+ const tag = node3.attrs?.tag;
262301
+ if (typeof tag !== "string" || tag.length === 0)
262302
+ return false;
262303
+ if (node3.attrs?.alias === "Anchored metadata")
262304
+ return true;
262305
+ return metadataIds.has(tag) && node3.attrs?.appearance === "hidden";
262306
+ }
262307
+ function findOverlappingMetadataAnchor(editor, absFrom, absTo) {
262308
+ const convertedXml = getConvertedXml2(editor);
262309
+ const metadataIds = new Set(listMetadataParts(convertedXml).flatMap((part) => part.entries.map((entry) => entry.id)));
262310
+ return findAllSdtNodes(editor.state.doc).find((sdt) => {
262311
+ if (sdt.kind !== "inline")
262312
+ return false;
262313
+ if (!isMetadataAnchorNode(metadataIds, sdt.node))
262314
+ return false;
262315
+ return rangesOverlap$1(sdt.pos + 1, sdt.pos + sdt.node.nodeSize - 1, absFrom, absTo);
262316
+ });
262317
+ }
262318
+ function assertNoOverlappingMetadataAnchor(editor, absFrom, absTo) {
262319
+ if (!findOverlappingMetadataAnchor(editor, absFrom, absTo))
262320
+ return;
262321
+ throw new DocumentApiAdapterError("INVALID_TARGET", "metadata.attach does not support overlapping metadata anchors.");
262322
+ }
262014
262323
  function anchorOverlaps(editor, id2, within$1) {
262015
262324
  const anchor = findAnchorsById(editor, id2)[0];
262016
262325
  if (!anchor)
@@ -262021,50 +262330,58 @@ function anchorOverlaps(editor, id2, within$1) {
262021
262330
  function writeEntry(editor, namespace, id2, payload, dryRun) {
262022
262331
  const convertedXml = getConvertedXml2(editor);
262023
262332
  const converter = getConverter$12(editor);
262024
- const existing = findPartByNamespace(convertedXml, namespace);
262025
- const entries2 = existing?.entries.filter((entry) => entry.id !== id2) ?? [];
262026
262333
  const next2 = {
262027
262334
  id: id2,
262028
262335
  namespace,
262029
- partName: existing?.partName ?? predictPartName(convertedXml, converter),
262336
+ partName: findPartByNamespace(convertedXml, namespace)?.partName ?? predictPartName(convertedXml, converter),
262030
262337
  payload
262031
262338
  };
262032
- const xml2 = buildEnvelopeXml(namespace, [...entries2, next2]);
262033
- if (dryRun)
262339
+ if (dryRun) {
262340
+ buildEnvelopeXml(namespace, [next2]);
262034
262341
  return { partName: next2.partName };
262035
- if (existing) {
262036
- patchCustomXmlPart(convertedXml, { partName: existing.partName }, {
262037
- content: xml2,
262038
- schemaRefs: undefined
262039
- }, converter ?? undefined);
262040
- markConverterDirty(editor);
262041
- return { partName: existing.partName };
262042
262342
  }
262043
- const created = createCustomXmlPart(convertedXml, {
262044
- content: xml2,
262045
- schemaRefs: undefined
262046
- }, converter ?? undefined);
262047
- markConverterDirty(editor);
262048
- return { partName: created.partName };
262343
+ return { partName: mutateCustomXmlParts(editor, "metadata.writeEntry", (sandboxXml, sandboxConverter) => {
262344
+ const sandboxExisting = findPartByNamespace(sandboxXml, namespace);
262345
+ const sandboxEntries = sandboxExisting?.entries.filter((entry) => entry.id !== id2) ?? [];
262346
+ const sandboxNext = {
262347
+ id: id2,
262348
+ namespace,
262349
+ partName: sandboxExisting?.partName ?? predictPartName(sandboxXml, sandboxConverter),
262350
+ payload
262351
+ };
262352
+ const sandboxEnvelope = buildEnvelopeXml(namespace, [...sandboxEntries, sandboxNext]);
262353
+ if (sandboxExisting) {
262354
+ patchCustomXmlPart(sandboxXml, { partName: sandboxExisting.partName }, {
262355
+ content: sandboxEnvelope,
262356
+ schemaRefs: undefined
262357
+ }, sandboxConverter);
262358
+ return sandboxExisting.partName;
262359
+ }
262360
+ return createCustomXmlPart(sandboxXml, {
262361
+ content: sandboxEnvelope,
262362
+ schemaRefs: undefined
262363
+ }, sandboxConverter).partName;
262364
+ }) };
262049
262365
  }
262050
262366
  function removeEntry(editor, id2, dryRun) {
262051
- const convertedXml = getConvertedXml2(editor);
262052
- const converter = getConverter$12(editor);
262053
- const part = listMetadataParts(convertedXml).find((candidate) => candidate.entries.some((entry) => entry.id === id2));
262054
- if (!part)
262367
+ if (!listMetadataParts(getConvertedXml2(editor)).find((candidate) => candidate.entries.some((entry) => entry.id === id2)))
262055
262368
  return false;
262056
262369
  if (dryRun)
262057
262370
  return true;
262058
- const remaining = part.entries.filter((entry) => entry.id !== id2);
262059
- if (remaining.length === 0)
262060
- removeCustomXmlPart(convertedXml, { partName: part.partName }, converter ?? undefined);
262061
- else
262062
- patchCustomXmlPart(convertedXml, { partName: part.partName }, {
262063
- content: buildEnvelopeXml(part.namespace, remaining),
262064
- schemaRefs: undefined
262065
- }, converter ?? undefined);
262066
- markConverterDirty(editor);
262067
- return true;
262371
+ return mutateCustomXmlParts(editor, "metadata.removeEntry", (sandboxXml, sandboxConverter) => {
262372
+ const sandboxPart = listMetadataParts(sandboxXml).find((candidate) => candidate.entries.some((entry) => entry.id === id2));
262373
+ if (!sandboxPart)
262374
+ return false;
262375
+ const remaining = sandboxPart.entries.filter((entry) => entry.id !== id2);
262376
+ if (remaining.length === 0)
262377
+ removeCustomXmlPart(sandboxXml, { partName: sandboxPart.partName }, sandboxConverter);
262378
+ else
262379
+ patchCustomXmlPart(sandboxXml, { partName: sandboxPart.partName }, {
262380
+ content: buildEnvelopeXml(sandboxPart.namespace, remaining),
262381
+ schemaRefs: undefined
262382
+ }, sandboxConverter);
262383
+ return true;
262384
+ });
262068
262385
  }
262069
262386
  function toSummary(entry, editor) {
262070
262387
  return {
@@ -262122,8 +262439,9 @@ function metadataAttachWrapper(editor, input2, options) {
262122
262439
  rejectTrackedMode("metadata.attach", options);
262123
262440
  const id2 = input2.id ?? v4_default();
262124
262441
  const convertedXml = getConvertedXml2(editor);
262442
+ let resolvedTarget;
262125
262443
  try {
262126
- resolveSelectionTarget(editor, input2.target);
262444
+ resolvedTarget = resolveSelectionTarget(editor, input2.target);
262127
262445
  } catch (error3) {
262128
262446
  const message = error3 instanceof Error ? error3.message : String(error3);
262129
262447
  if (error3 instanceof DocumentApiAdapterError) {
@@ -262134,6 +262452,16 @@ function metadataAttachWrapper(editor, input2, options) {
262134
262452
  }
262135
262453
  if (hasPayloadEntry(convertedXml, id2) || hasAnchor(editor, id2))
262136
262454
  return failure("INVALID_INPUT", `Anchored metadata id "${id2}" already exists.`);
262455
+ try {
262456
+ assertNoOverlappingMetadataAnchor(editor, resolvedTarget.absFrom, resolvedTarget.absTo);
262457
+ } catch (error3) {
262458
+ const message = error3 instanceof Error ? error3.message : String(error3);
262459
+ if (error3 instanceof DocumentApiAdapterError) {
262460
+ if (error3.code === "TARGET_NOT_FOUND" || error3.code === "INVALID_TARGET")
262461
+ return failure(error3.code, message);
262462
+ }
262463
+ throw error3;
262464
+ }
262137
262465
  const preview = writeEntry(editor, input2.namespace, id2, input2.payload, true);
262138
262466
  if (options?.dryRun) {
262139
262467
  checkRevision(editor, options.expectedRevision);
@@ -262144,11 +262472,22 @@ function metadataAttachWrapper(editor, input2, options) {
262144
262472
  partName: preview.partName
262145
262473
  };
262146
262474
  }
262147
- if (executeDomainCommand(editor, () => {
262148
- wrapRangeInAnchor(editor, input2.target, id2);
262149
- writeEntry(editor, input2.namespace, id2, input2.payload, false);
262150
- return true;
262151
- }, { expectedRevision: options?.expectedRevision }).steps[0]?.effect !== "changed")
262475
+ let receipt2;
262476
+ try {
262477
+ receipt2 = executeDomainCommand(editor, () => {
262478
+ wrapRangeInAnchor(editor, input2.target, id2);
262479
+ writeEntry(editor, input2.namespace, id2, input2.payload, false);
262480
+ return true;
262481
+ }, { expectedRevision: options?.expectedRevision });
262482
+ } catch (error3) {
262483
+ const message = error3 instanceof Error ? error3.message : String(error3);
262484
+ if (error3 instanceof DocumentApiAdapterError) {
262485
+ if (error3.code === "TARGET_NOT_FOUND" || error3.code === "INVALID_TARGET")
262486
+ return failure(error3.code, message);
262487
+ }
262488
+ throw error3;
262489
+ }
262490
+ if (receipt2.steps[0]?.effect !== "changed")
262152
262491
  return failure("INVALID_TARGET", "metadata.attach did not change the document.");
262153
262492
  const entry = findEntry(getConvertedXml2(editor), id2);
262154
262493
  return {
@@ -262167,7 +262506,7 @@ function metadataUpdateWrapper(editor, input2, options) {
262167
262506
  if (!dryRun)
262168
262507
  writeEntry(editor, existing.namespace, input2.id, input2.payload, false);
262169
262508
  return {
262170
- changed: true,
262509
+ changed: false,
262171
262510
  payload: {
262172
262511
  success: true,
262173
262512
  id: input2.id
@@ -262193,8 +262532,9 @@ function metadataRemoveWrapper(editor, input2, options) {
262193
262532
  }
262194
262533
  if (!anchorExists)
262195
262534
  return executeOutOfBandMutation(editor, (dryRun) => {
262535
+ removeEntry(editor, input2.id, dryRun);
262196
262536
  return {
262197
- changed: removeEntry(editor, input2.id, dryRun),
262537
+ changed: false,
262198
262538
  payload: {
262199
262539
  success: true,
262200
262540
  id: input2.id
@@ -290451,7 +290791,7 @@ var Node$13 = class Node$14 {
290451
290791
  let $pos = doc$12.resolve(this.pos);
290452
290792
  return GapCursor.valid($pos) ? new GapCursor($pos) : Selection.near($pos);
290453
290793
  }
290454
- }, handleKeyDown2, Gapcursor, PARTS_MAP_KEY = "parts", META_MAP_KEY = "meta", META_PARTS_SCHEMA_VERSION_KEY = "partsSchemaVersion", META_PARTS_MIGRATION_KEY = "partsMigration", META_PARTS_LAST_HYDRATED_AT_KEY = "partsLastHydratedAt", META_PARTS_FALLBACK_MODE_KEY = "partsFallbackMode", META_PARTS_CAPABILITY_KEY = "partsCapability", SOURCE_COLLAB_REMOTE_PARTS = "collab:remote:parts", SOURCE_COLLAB_REMOTE_PREFIX = "collab:remote:", EXCLUDED_PART_IDS, CRITICAL_PART_IDS, isApplyingRemoteParts = false, META_MAP_KEY$1 = "meta", NOTE_TOMBSTONE_META_PREFIX = "noteTombstone:", SCHEMA_ATOM_NODE_NAMES, NORMALIZE_YJS_FRAGMENT_ORIGIN, headlessBindingStateByEditor, headlessCleanupRegisteredEditors, META_BODY_SECT_PR_KEY = "bodySectPr", BODY_SECT_PR_SYNC_META_KEY = "bodySectPrSync", collaborationCleanupByEditor, registerHeadlessBindingCleanup = (editor, cleanup) => {
290794
+ }, handleKeyDown2, Gapcursor, PARTS_MAP_KEY = "parts", META_MAP_KEY = "meta", META_PARTS_SCHEMA_VERSION_KEY = "partsSchemaVersion", META_PARTS_MIGRATION_KEY = "partsMigration", META_PARTS_LAST_HYDRATED_AT_KEY = "partsLastHydratedAt", META_PARTS_FALLBACK_MODE_KEY = "partsFallbackMode", META_PARTS_CAPABILITY_KEY = "partsCapability", SOURCE_COLLAB_REMOTE_PARTS = "collab:remote:parts", SOURCE_COLLAB_REMOTE_PREFIX = "collab:remote:", EXCLUDED_PART_IDS, CRITICAL_PART_IDS, import_lib4, CUSTOM_XML_DATA_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml", CUSTOM_XML_PROPS_RELATIONSHIP_TYPE$1 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXmlProps", CUSTOM_XML_DATASTORE_NAMESPACE = "http://schemas.openxmlformats.org/officeDocument/2006/customXml", CUSTOM_XML_PROPS_RELATIONSHIP_TYPE2 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXmlProps", isApplyingRemoteParts = false, META_MAP_KEY$1 = "meta", NOTE_TOMBSTONE_META_PREFIX = "noteTombstone:", SCHEMA_ATOM_NODE_NAMES, NORMALIZE_YJS_FRAGMENT_ORIGIN, headlessBindingStateByEditor, headlessCleanupRegisteredEditors, META_BODY_SECT_PR_KEY = "bodySectPr", BODY_SECT_PR_SYNC_META_KEY = "bodySectPrSync", collaborationCleanupByEditor, registerHeadlessBindingCleanup = (editor, cleanup) => {
290455
290795
  if (!cleanup || headlessCleanupRegisteredEditors.has(editor))
290456
290796
  return;
290457
290797
  headlessCleanupRegisteredEditors.add(editor);
@@ -306088,7 +306428,7 @@ var Node$13 = class Node$14 {
306088
306428
  domAvailabilityCache = false;
306089
306429
  return false;
306090
306430
  }
306091
- }, summaryVersion = "1.44.0", nodeKeys, markKeys, transformListsInCopiedContent = (html3) => {
306431
+ }, summaryVersion = "1.44.1", nodeKeys, markKeys, transformListsInCopiedContent = (html3) => {
306092
306432
  const container = document.createElement("div");
306093
306433
  container.innerHTML = html3;
306094
306434
  const result = [];
@@ -307274,7 +307614,7 @@ var Node$13 = class Node$14 {
307274
307614
  return () => {};
307275
307615
  const handle3 = setInterval(callback, intervalMs);
307276
307616
  return () => clearInterval(handle3);
307277
- }, HISTORY_UNSAFE_OPS, CANONICAL_COMMENT_IGNORED_KEYS, INITIAL_HASH, ROUND_CONSTANTS, V1_COVERAGE, V2_COVERAGE, SNAPSHOT_VERSION_V2 = "sd-diff-snapshot/v2", PAYLOAD_VERSION_V1 = "sd-diff-payload/v1", PAYLOAD_VERSION_V2 = "sd-diff-payload/v2", ENGINE_ID = "super-editor", STAGED_CONVERTER_KEYS, DiffServiceError, TC_LEVEL_MIN = 1, TC_LEVEL_MAX = 9, ALLOWED_WRAP_ATTRS, WRAP_TYPES_SUPPORTING_SIDE, WRAP_TYPES_SUPPORTING_DISTANCES, RELATIVE_HEIGHT_MIN = 0, RELATIVE_HEIGHT_MAX = 4294967295, FORBIDDEN_RAW_PATCH_NAMES, CONTROL_TYPE_SDT_PR_ELEMENTS, DEFAULT_CHECKBOX_SYMBOL_FONT2 = "MS Gothic", DEFAULT_CHECKBOX_CHECKED_HEX2 = "2612", DEFAULT_CHECKBOX_UNCHECKED_HEX2 = "2610", VARIANT_ORDER, KIND_ORDER, HEADER_RELATIONSHIP_TYPE3 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", FOOTER_RELATIONSHIP_TYPE3 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", DOCUMENT_RELS_PATH2 = "word/_rels/document.xml.rels", HEADER_FILE_PATTERN2, FOOTER_FILE_PATTERN2, BOOKMARK_SCAN_REVISION_PREFIX = "bookmark-scan:", import_lib4, CUSTOM_XML_DATA_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml", CUSTOM_XML_PROPS_RELATIONSHIP_TYPE2 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXmlProps", CUSTOM_XML_DATASTORE_NAMESPACE = "http://schemas.openxmlformats.org/officeDocument/2006/customXml", SETTINGS_PART, VALID_DISPLAYS, REFERENCE_BLOCK_PREFIX, CAPTION_STYLE_NAMES, CAPTION_PARAGRAPH_STYLE_ID = "Caption", CAPTION_FORMAT_TO_OOXML, DOCUMENT_STAT_FIELD_TYPES, TOA_LEADER_REVERSE_MAP, EDGE_NODE_TYPES, CONTENT_TYPES_PART_ID = "[Content_Types].xml", CONTENT_TYPES_NS = "http://schemas.openxmlformats.org/package/2006/content-types", contentTypesPartDescriptor, empty_exports, init_empty, CURRENT_APP_VERSION2 = "1.44.0", PIXELS_PER_INCH2 = 96, MAX_HEIGHT_BUFFER_PX = 50, MAX_WIDTH_BUFFER_PX = 20, TRACKED_REVIEW_MARK_NAMES2, isTrackedReviewMark = (mark2) => Boolean(mark2?.type?.name && TRACKED_REVIEW_MARK_NAMES2.has(mark2.type.name)), trackedReviewMarkKey = (mark2) => {
307617
+ }, HISTORY_UNSAFE_OPS, CANONICAL_COMMENT_IGNORED_KEYS, INITIAL_HASH, ROUND_CONSTANTS, V1_COVERAGE, V2_COVERAGE, SNAPSHOT_VERSION_V2 = "sd-diff-snapshot/v2", PAYLOAD_VERSION_V1 = "sd-diff-payload/v1", PAYLOAD_VERSION_V2 = "sd-diff-payload/v2", ENGINE_ID = "super-editor", STAGED_CONVERTER_KEYS, DiffServiceError, TC_LEVEL_MIN = 1, TC_LEVEL_MAX = 9, ALLOWED_WRAP_ATTRS, WRAP_TYPES_SUPPORTING_SIDE, WRAP_TYPES_SUPPORTING_DISTANCES, RELATIVE_HEIGHT_MIN = 0, RELATIVE_HEIGHT_MAX = 4294967295, FORBIDDEN_RAW_PATCH_NAMES, CONTROL_TYPE_SDT_PR_ELEMENTS, DEFAULT_CHECKBOX_SYMBOL_FONT2 = "MS Gothic", DEFAULT_CHECKBOX_CHECKED_HEX2 = "2612", DEFAULT_CHECKBOX_UNCHECKED_HEX2 = "2610", VARIANT_ORDER, KIND_ORDER, HEADER_RELATIONSHIP_TYPE3 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", FOOTER_RELATIONSHIP_TYPE3 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", DOCUMENT_RELS_PATH2 = "word/_rels/document.xml.rels", HEADER_FILE_PATTERN2, FOOTER_FILE_PATTERN2, BOOKMARK_SCAN_REVISION_PREFIX = "bookmark-scan:", SETTINGS_PART, VALID_DISPLAYS, REFERENCE_BLOCK_PREFIX, CAPTION_STYLE_NAMES, CAPTION_PARAGRAPH_STYLE_ID = "Caption", CAPTION_FORMAT_TO_OOXML, DOCUMENT_STAT_FIELD_TYPES, TOA_LEADER_REVERSE_MAP, EDGE_NODE_TYPES, CONTENT_TYPES_PART_ID = "[Content_Types].xml", CONTENT_TYPES_NS = "http://schemas.openxmlformats.org/package/2006/content-types", contentTypesPartDescriptor, empty_exports, init_empty, CURRENT_APP_VERSION2 = "1.44.1", PIXELS_PER_INCH2 = 96, MAX_HEIGHT_BUFFER_PX = 50, MAX_WIDTH_BUFFER_PX = 20, TRACKED_REVIEW_MARK_NAMES2, isTrackedReviewMark = (mark2) => Boolean(mark2?.type?.name && TRACKED_REVIEW_MARK_NAMES2.has(mark2.type.name)), trackedReviewMarkKey = (mark2) => {
307278
307618
  if (!isTrackedReviewMark(mark2))
307279
307619
  return null;
307280
307620
  const id2 = typeof mark2.attrs?.id === "string" ? mark2.attrs.id : "";
@@ -328161,13 +328501,13 @@ menclose::after {
328161
328501
  return;
328162
328502
  console.log(...args$1);
328163
328503
  }, HEADER_FOOTER_INIT_BUDGET_MS = 200, MAX_ZOOM_WARNING_THRESHOLD = 10, MAX_SELECTION_RECTS_PER_USER = 100, SEMANTIC_RESIZE_DEBOUNCE_MS = 120, MIN_SEMANTIC_CONTENT_WIDTH_PX = 1, GLOBAL_PERFORMANCE, PresentationEditor, ICONS, TEXTS, tableActionsOptions, TRACKED_MARK_NAMES;
328164
- var init_src_CA6yipr_es = __esm(() => {
328504
+ var init_src_K_HYiMBY_es = __esm(() => {
328165
328505
  init_rolldown_runtime_Bg48TavK_es();
328166
- init_SuperConverter_SsIUcBUk_es();
328506
+ init_SuperConverter_8tQYSE1r_es();
328167
328507
  init_jszip_C49i9kUs_es();
328168
328508
  init_xml_js_CqGKpaft_es();
328169
328509
  init_uuid_B2wVPhPi_es();
328170
- init_create_headless_toolbar_JMykgI82_es();
328510
+ init_create_headless_toolbar_J9k_n61d_es();
328171
328511
  init_constants_D9qj59G2_es();
328172
328512
  init_unified_BDuVPlMu_es();
328173
328513
  init_remark_gfm_BUJjZJLy_es();
@@ -335295,6 +335635,7 @@ ${err.toString()}`);
335295
335635
  "word/_rels/document.xml.rels",
335296
335636
  "[Content_Types].xml"
335297
335637
  ]);
335638
+ import_lib4 = /* @__PURE__ */ __toESM2(require_lib(), 1);
335298
335639
  SCHEMA_ATOM_NODE_NAMES = new Set(["crossReference", "citation"]);
335299
335640
  NORMALIZE_YJS_FRAGMENT_ORIGIN = Symbol.for("superdoc/yjs-fragment-normalize");
335300
335641
  new PluginKey("collaboration");
@@ -337315,6 +337656,7 @@ ${err.toString()}`);
337315
337656
  const editor = this.editor;
337316
337657
  const isHeadless$1 = editor.options.isHeadless;
337317
337658
  let shouldUpdate = true;
337659
+ let pendingSelectedNotification = null;
337318
337660
  const pluginSpec = {
337319
337661
  key: CommentsPluginKey,
337320
337662
  state: {
@@ -337340,11 +337682,23 @@ ${err.toString()}`);
337340
337682
  const previousActiveThreadId = pluginState.activeThreadId;
337341
337683
  const newActiveThreadId = meta2.activeThreadId;
337342
337684
  if (previousActiveThreadId !== newActiveThreadId) {
337685
+ const activeCommentId = newActiveThreadId ?? null;
337343
337686
  const update = {
337344
337687
  type: comments_module_events.SELECTED,
337345
- activeCommentId: newActiveThreadId ? newActiveThreadId : null
337688
+ activeCommentId
337346
337689
  };
337347
- setTimeout(() => editor.emit("commentsUpdate", update), 0);
337690
+ clearTimeout(pendingSelectedNotification);
337691
+ pendingSelectedNotification = setTimeout(() => {
337692
+ pendingSelectedNotification = null;
337693
+ if (editor.isDestroyed)
337694
+ return;
337695
+ const editorState = editor.state;
337696
+ if (!editorState)
337697
+ return;
337698
+ if ((CommentsPluginKey.getState(editorState)?.activeThreadId ?? null) !== activeCommentId)
337699
+ return;
337700
+ editor.emit("commentsUpdate", update);
337701
+ }, 0);
337348
337702
  }
337349
337703
  pluginState.activeThreadId = newActiveThreadId;
337350
337704
  return {
@@ -359558,7 +359912,7 @@ function print() { __p += __j.call(arguments, '') }
359558
359912
  stylesPartDescriptor = {
359559
359913
  id: STYLES_PART_ID,
359560
359914
  ensurePart(editor) {
359561
- const converter = getConverter$62(editor);
359915
+ const converter = getConverter$72(editor);
359562
359916
  if (converter?.convertedXml[STYLES_PART_ID])
359563
359917
  return converter.convertedXml[STYLES_PART_ID];
359564
359918
  return {
@@ -359573,7 +359927,7 @@ function print() { __p += __j.call(arguments, '') }
359573
359927
  },
359574
359928
  afterCommit(ctx$1) {
359575
359929
  if (ctx$1.source.startsWith("collab:remote:") || ctx$1.source === "templates.apply") {
359576
- const converter = getConverter$62(ctx$1.editor);
359930
+ const converter = getConverter$72(ctx$1.editor);
359577
359931
  if (converter)
359578
359932
  try {
359579
359933
  converter.translatedLinkedStyles = translateStyleDefinitions(converter.convertedXml);
@@ -359966,7 +360320,6 @@ function print() { __p += __j.call(arguments, '') }
359966
360320
  KIND_ORDER = ["header", "footer"];
359967
360321
  HEADER_FILE_PATTERN2 = /header(\d+)\.xml$/;
359968
360322
  FOOTER_FILE_PATTERN2 = /footer(\d+)\.xml$/;
359969
- import_lib4 = /* @__PURE__ */ __toESM2(require_lib(), 1);
359970
360323
  SETTINGS_PART = SETTINGS_PART_PATH;
359971
360324
  VALID_DISPLAYS = new Set([
359972
360325
  "content",
@@ -371474,11 +371827,11 @@ function print() { __p += __j.call(arguments, '') }
371474
371827
  ]);
371475
371828
  });
371476
371829
 
371477
- // ../../packages/superdoc/dist/chunks/create-super-doc-ui-DzAhRsHL.es.js
371830
+ // ../../packages/superdoc/dist/chunks/create-super-doc-ui-CtI0KsfE.es.js
371478
371831
  var DEFAULT_TEXT_ALIGN_OPTIONS, DEFAULT_LINE_HEIGHT_OPTIONS, DEFAULT_ZOOM_OPTIONS, DEFAULT_DOCUMENT_MODE_OPTIONS, DEFAULT_FONT_SIZE_OPTIONS, headlessToolbarConstants, MOD_ALIASES, ALT_ALIASES, CTRL_ALIASES, SHIFT_ALIASES, BUILTIN_CONTEXT_MENU_GROUPS, BUILTIN_GROUP_ORDER, RESERVED_PROXY_PROPERTY_NAMES, ALL_TOOLBAR_COMMAND_IDS, EMPTY_ACTIVE_IDS, FONT_SIZE_OPTIONS;
371479
- var init_create_super_doc_ui_DzAhRsHL_es = __esm(() => {
371480
- init_SuperConverter_SsIUcBUk_es();
371481
- init_create_headless_toolbar_JMykgI82_es();
371832
+ var init_create_super_doc_ui_CtI0KsfE_es = __esm(() => {
371833
+ init_SuperConverter_8tQYSE1r_es();
371834
+ init_create_headless_toolbar_J9k_n61d_es();
371482
371835
  DEFAULT_TEXT_ALIGN_OPTIONS = [
371483
371836
  {
371484
371837
  label: "Left",
@@ -371769,15 +372122,15 @@ var init_zipper_BxRAi0_5_es = __esm(() => {
371769
372122
 
371770
372123
  // ../../packages/superdoc/dist/super-editor.es.js
371771
372124
  var init_super_editor_es = __esm(() => {
371772
- init_src_CA6yipr_es();
371773
- init_SuperConverter_SsIUcBUk_es();
372125
+ init_src_K_HYiMBY_es();
372126
+ init_SuperConverter_8tQYSE1r_es();
371774
372127
  init_jszip_C49i9kUs_es();
371775
372128
  init_xml_js_CqGKpaft_es();
371776
- init_create_headless_toolbar_JMykgI82_es();
372129
+ init_create_headless_toolbar_J9k_n61d_es();
371777
372130
  init_constants_D9qj59G2_es();
371778
372131
  init_unified_BDuVPlMu_es();
371779
372132
  init_DocxZipper_BzS208BW_es();
371780
- init_create_super_doc_ui_DzAhRsHL_es();
372133
+ init_create_super_doc_ui_CtI0KsfE_es();
371781
372134
  init_ui_CGB3qmy3_es();
371782
372135
  init_eventemitter3_UwU_CLPU_es();
371783
372136
  init_errors_C_DoKMoN_es();