@guodun/antdv 1.7.6 → 1.7.8

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 (47) hide show
  1. package/dist/es/components/pro-contract-template-designer/src/ContractTemplateDesignerSidebar.vue.mjs +152 -146
  2. package/dist/es/components/pro-contract-template-designer/src/DesignerPage.vue.mjs +415 -295
  3. package/dist/es/components/pro-contract-template-designer/src/ProContractTemplateDesigner.vue.mjs +1040 -993
  4. package/dist/es/components/pro-contract-template-designer/src/composables/use-auto-pagination.mjs +141 -47
  5. package/dist/es/components/pro-contract-template-designer/src/composables/use-draft-cache-session.mjs +1 -1
  6. package/dist/es/components/pro-contract-template-designer/src/composables/use-page-authoring.mjs +22 -21
  7. package/dist/es/components/pro-contract-template-designer/src/composables/use-template-authoring.mjs +37 -36
  8. package/dist/es/components/pro-contract-template-designer/src/composables/use-template-designer.mjs +125 -75
  9. package/dist/es/components/pro-contract-template-designer/src/utils/authoring-search.mjs +34 -13
  10. package/dist/es/components/pro-contract-template-designer/src/utils/caret-viewport.mjs +41 -0
  11. package/dist/es/components/pro-contract-template-designer/src/utils/document-outline.mjs +24 -1
  12. package/dist/es/components/pro-contract-template-designer/src/utils/editor-snapshot-cache.mjs +15 -0
  13. package/dist/es/components/pro-contract-template-designer/style/index.css +1 -1
  14. package/dist/es/index.mjs +21 -21
  15. package/dist/es/node_modules/@tiptap/pm/dist/transform/index.mjs +1 -0
  16. package/dist/es/node_modules/prosemirror-transform/dist/index.mjs +161 -67
  17. package/dist/lib/components/pro-contract-template-designer/src/ContractTemplateDesignerSidebar.vue.cjs +1 -1
  18. package/dist/lib/components/pro-contract-template-designer/src/DesignerPage.vue.cjs +2 -2
  19. package/dist/lib/components/pro-contract-template-designer/src/ProContractTemplateDesigner.vue.cjs +1 -1
  20. package/dist/lib/components/pro-contract-template-designer/src/composables/use-auto-pagination.cjs +1 -1
  21. package/dist/lib/components/pro-contract-template-designer/src/composables/use-draft-cache-session.cjs +1 -1
  22. package/dist/lib/components/pro-contract-template-designer/src/composables/use-page-authoring.cjs +1 -1
  23. package/dist/lib/components/pro-contract-template-designer/src/composables/use-template-authoring.cjs +1 -1
  24. package/dist/lib/components/pro-contract-template-designer/src/composables/use-template-designer.cjs +4 -4
  25. package/dist/lib/components/pro-contract-template-designer/src/utils/authoring-search.cjs +1 -1
  26. package/dist/lib/components/pro-contract-template-designer/src/utils/caret-viewport.cjs +1 -0
  27. package/dist/lib/components/pro-contract-template-designer/src/utils/document-outline.cjs +1 -1
  28. package/dist/lib/components/pro-contract-template-designer/src/utils/editor-snapshot-cache.cjs +1 -0
  29. package/dist/lib/components/pro-contract-template-designer/style/index.css +1 -1
  30. package/dist/lib/index.cjs +1 -1
  31. package/dist/lib/node_modules/@tiptap/pm/dist/transform/index.cjs +1 -0
  32. package/dist/lib/node_modules/prosemirror-transform/dist/index.cjs +2 -2
  33. package/dist/theme/icon.css +1 -1
  34. package/dist/theme/index.css +1 -1
  35. package/dist/types/components/pro-contract-template-designer/src/ContractTemplateDesignerSidebar.vue.d.ts +1 -0
  36. package/dist/types/components/pro-contract-template-designer/src/DesignerPage.vue.d.ts +28 -0
  37. package/dist/types/components/pro-contract-template-designer/src/composables/use-auto-pagination.d.ts +25 -2
  38. package/dist/types/components/pro-contract-template-designer/src/composables/use-draft-cache-session.d.ts +1 -1
  39. package/dist/types/components/pro-contract-template-designer/src/composables/use-template-designer.d.ts +10 -1
  40. package/dist/types/components/pro-contract-template-designer/src/utils/authoring-search.d.ts +5 -0
  41. package/dist/types/components/pro-contract-template-designer/src/utils/caret-viewport.d.ts +18 -0
  42. package/dist/types/components/pro-contract-template-designer/src/utils/document-outline.d.ts +6 -0
  43. package/dist/types/components/pro-contract-template-designer/src/utils/editor-snapshot-cache.d.ts +16 -0
  44. package/package.json +3 -3
  45. package/dist/theme/dept-selector.css +0 -1
  46. package/dist/theme/pro-selector-group.css +0 -1
  47. package/dist/theme/role-selector.css +0 -1
@@ -1,21 +1,25 @@
1
1
  import { CONTRACT_TEXT_STYLE_PRESETS as e, DEFAULT_CONTRACT_FONT_FAMILY as t } from "./constants.mjs";
2
2
  import { CONTRACT_PAGE_BASE_PADDING as n, getPageDecorationSafePadding as r, hasEnabledPageFooter as i, hasEnabledPageHeader as a, normalizePageDecorations as o } from "./utils/page-decorations.mjs";
3
- import { DEFAULT_FIELD_STYLE as s, resolvePageSize as c, splitPageContentByMeasurements as ee } from "./composables/use-template-designer.mjs";
4
- import { usePageAuthoring as te } from "./composables/use-page-authoring.mjs";
5
- import { buildTemplateVariableAttrs as ne, insertTemplateVariableNode as re } from "./extensions/template-variable.mjs";
6
- import { normalizeContractImageDimension as l } from "./utils/content-image.mjs";
7
- import { createEditorExtensions as ie, runContractTemplateEditorCommand as u } from "./extensions/editor-extensions.mjs";
8
- import { resolveEditorContextMenuKind as d } from "./utils/context-variable.mjs";
9
- import { applyContractTemplateBlockStyle as ae } from "./utils/block-style.mjs";
10
- import oe from "./ContractTemplatePageDecorations.mjs";
11
- import { computed as f, createBlock as se, createCommentVNode as ce, createElementBlock as le, createElementVNode as p, createVNode as ue, defineComponent as m, nextTick as de, normalizeClass as h, normalizeStyle as g, onBeforeUnmount as fe, openBlock as _, ref as pe, toDisplayString as v, unref as y, watch as b, withModifiers as me } from "vue";
12
- import { Modal as he } from "ant-design-vue";
13
- import { EditorContent as ge, useEditor as _e } from "@tiptap/vue-3";
14
- import { generateHTML as ve } from "@tiptap/core";
15
- import { CellSelection as x, deleteColumn as ye, deleteRow as be, deleteTable as xe } from "@tiptap/pm/tables";
16
- import { NodeSelection as S } from "@tiptap/pm/state";
3
+ import { DEFAULT_FIELD_STYLE as s, resolvePageSize as c, splitPageContentByMeasurements as l } from "./composables/use-template-designer.mjs";
4
+ import { createEditorSnapshotCache as ee } from "./utils/editor-snapshot-cache.mjs";
5
+ import { Mapping as te, StepMap as ne } from "../../../node_modules/prosemirror-transform/dist/index.mjs";
6
+ import { usePageAuthoring as re } from "./composables/use-page-authoring.mjs";
7
+ import "../../../node_modules/@tiptap/pm/dist/transform/index.mjs";
8
+ import { buildTemplateVariableAttrs as ie, insertTemplateVariableNode as ae } from "./extensions/template-variable.mjs";
9
+ import { normalizeContractImageDimension as u } from "./utils/content-image.mjs";
10
+ import { createEditorExtensions as oe, runContractTemplateEditorCommand as d } from "./extensions/editor-extensions.mjs";
11
+ import { resolveEditorContextMenuKind as f } from "./utils/context-variable.mjs";
12
+ import { applyContractTemplateBlockStyle as se } from "./utils/block-style.mjs";
13
+ import ce from "./ContractTemplatePageDecorations.mjs";
14
+ import { scrollCaretIntoCanvas as le } from "./utils/caret-viewport.mjs";
15
+ import { computed as p, createBlock as ue, createCommentVNode as de, createElementBlock as fe, createElementVNode as m, createVNode as pe, defineComponent as h, nextTick as me, normalizeClass as he, normalizeStyle as g, onBeforeUnmount as ge, openBlock as _e, ref as ve, toDisplayString as _, toRaw as ye, unref as v, watch as y, withModifiers as be } from "vue";
16
+ import { Modal as xe } from "ant-design-vue";
17
+ import { EditorContent as Se, useEditor as Ce } from "@tiptap/vue-3";
18
+ import { generateHTML as we } from "@tiptap/core";
19
+ import { CellSelection as b, deleteColumn as Te, deleteRow as Ee, deleteTable as De } from "@tiptap/pm/tables";
20
+ import { NodeSelection as x, Selection as Oe } from "@tiptap/pm/state";
17
21
  //#region src/components/pro-contract-template-designer/src/DesignerPage.vue?vue&type=script&setup=true&lang.ts
18
- var Se = { class: "gd-contract-template-designer__page-title" }, C = "application/x-gd-contract-variable-move", Ce = 8, w = /* @__PURE__ */ m({
22
+ var ke = { class: "gd-contract-template-designer__page-title" }, S = "application/x-gd-contract-variable-move", Ae = 8, je = /* @__PURE__ */ h({
19
23
  name: "ProContractTemplateDesignerPage",
20
24
  __name: "DesignerPage",
21
25
  props: {
@@ -48,7 +52,11 @@ var Se = { class: "gd-contract-template-designer__page-title" }, C = "applicatio
48
52
  type: Boolean,
49
53
  default: !1
50
54
  },
51
- activeSearchMatch: { default: void 0 }
55
+ activeSearchMatch: { default: void 0 },
56
+ getScrollContainer: {
57
+ type: Function,
58
+ default: void 0
59
+ }
52
60
  },
53
61
  emits: [
54
62
  "page-update",
@@ -57,16 +65,24 @@ var Se = { class: "gd-contract-template-designer__page-title" }, C = "applicatio
57
65
  "variable-move-blocked",
58
66
  "editor-focus",
59
67
  "editor-ready",
68
+ "composition-end",
69
+ "page-layout-change",
60
70
  "editor-state-change",
61
71
  "editor-context-menu",
62
72
  "word-paste"
63
73
  ],
64
- setup(m, { expose: w, emit: we }) {
65
- let T = m, E = we, D = f(() => T.readonly || T.disabled), O = pe();
66
- function k(e) {
74
+ setup(h, { expose: je, emit: Me }) {
75
+ let C = h, w = Me, T = p(() => C.readonly || C.disabled), E = ve(), D = ee(), O = !1, k, A, j = !1, M = !1, Ne = !1, N = !1, P = 0, F, Pe = C.page.contentHtml, Fe = ye(C.page);
76
+ function I() {
77
+ return M && !j;
78
+ }
79
+ function L() {
80
+ return O || !!R.value?.view.composing;
81
+ }
82
+ function Ie(e) {
67
83
  let t = e.filter(Boolean).join("、");
68
84
  return typeof window > "u" ? !1 : new Promise((e) => {
69
- he.confirm({
85
+ xe.confirm({
70
86
  title: "粘贴内容包含不兼容字体",
71
87
  content: `检测到 ${t || "外部"} 字体。为保证 Mac 与 Windows 排版一致,将统一转换为合同标准字体(GD Contract Latin + 系统宋体)。是否继续粘贴?`,
72
88
  okText: "继续粘贴",
@@ -76,144 +92,166 @@ var Se = { class: "gd-contract-template-designer__page-title" }, C = "applicatio
76
92
  });
77
93
  });
78
94
  }
79
- let A = ie("请输入合同正文,或从 WPS / Word 粘贴合同内容", {
80
- processImageFile: T.processImageFile,
81
- confirmExternalFontPaste: k,
82
- getZoom: () => Math.max(.1, T.zoom || 1)
83
- }), j = _e({
84
- content: T.page.contentHtml,
85
- editable: !D.value,
86
- extensions: A,
95
+ let Le = oe("请输入合同正文,或从 WPS / Word 粘贴合同内容", {
96
+ processImageFile: C.processImageFile,
97
+ confirmExternalFontPaste: Ie,
98
+ getZoom: () => Math.max(.1, C.zoom || 1)
99
+ }), R = Ce({
100
+ content: C.page.contentHtml,
101
+ editable: !T.value,
102
+ extensions: Le,
87
103
  editorProps: {
88
104
  attributes: { class: "gd-contract-template-designer__editor-prose" },
89
105
  handleClick: (e, t, n) => {
90
106
  let r = (n.target instanceof HTMLElement ? n.target.closest("[data-template-variable]") : void 0)?.dataset.key;
91
107
  if (!r) return !1;
92
- let i = T.variables.find((e) => e.key === r);
93
- return i && E("variable-select", i.key), !1;
108
+ let i = C.variables.find((e) => e.key === r);
109
+ return i && w("variable-select", i.key), !1;
94
110
  },
95
111
  handleDOMEvents: {
112
+ compositionstart: () => (O = !0, k !== void 0 && clearTimeout(k), !1),
113
+ compositionend: () => (O = !1, k = setTimeout(() => {
114
+ if (k = void 0, !(j || L())) {
115
+ if (A !== void 0) {
116
+ let e = A;
117
+ A = void 0, dt(e);
118
+ }
119
+ w("page-update", K()), w("composition-end", C.page.id);
120
+ }
121
+ }, 0), !1),
96
122
  contextmenu: (e, t) => {
97
- if (D.value) return !1;
98
- let n = Be(e, t.target);
99
- if (n) return t.preventDefault(), R({
100
- pageId: T.page.id,
123
+ if (T.value) return !1;
124
+ let n = rt(e, t.target);
125
+ if (n) return t.preventDefault(), V({
126
+ pageId: C.page.id,
101
127
  clientX: t.clientX,
102
128
  clientY: t.clientY
103
129
  }, n), !0;
104
- let r = j.value?.state.selection, i = r instanceof x, a = t.target instanceof HTMLElement ? !!t.target.closest("td, th") : !1, o = d({
130
+ let r = R.value?.state.selection, i = r instanceof b, a = t.target instanceof HTMLElement ? !!t.target.closest("td, th") : !1, o = f({
105
131
  isCellSelection: i,
106
132
  selectionEmpty: !r || r.empty,
107
133
  inTable: a
108
134
  });
109
- return t.preventDefault(), o === "table" && (i || Le(t.clientX, t.clientY, t.target)) ? (V({
110
- pageId: T.page.id,
135
+ return t.preventDefault(), o === "table" && (i || Qe(t.clientX, t.clientY, t.target)) ? (it({
136
+ pageId: C.page.id,
111
137
  clientX: t.clientX,
112
138
  clientY: t.clientY
113
- }), !0) : (L({
114
- pageId: T.page.id,
139
+ }), !0) : (B({
140
+ pageId: C.page.id,
115
141
  clientX: t.clientX,
116
142
  clientY: t.clientY
117
143
  }), !0);
118
144
  },
119
- dragstart: (e, t) => D.value ? (t.preventDefault(), !0) : (t.target instanceof HTMLElement ? t.target : null)?.closest("[data-template-variable]") ? (t.dataTransfer?.setData(C, T.page.id), t.dataTransfer && (t.dataTransfer.effectAllowed = "move"), O.value?.classList.add("is-variable-dragging"), !1) : !1,
120
- dragend: () => (O.value?.classList.remove("is-variable-dragging"), !1),
145
+ dragstart: (e, t) => T.value ? (t.preventDefault(), !0) : (t.target instanceof HTMLElement ? t.target : null)?.closest("[data-template-variable]") ? (t.dataTransfer?.setData(S, C.page.id), t.dataTransfer && (t.dataTransfer.effectAllowed = "move"), E.value?.classList.add("is-variable-dragging"), !1) : !1,
146
+ dragend: () => (E.value?.classList.remove("is-variable-dragging"), !1),
121
147
  drop: (e, t) => {
122
- if (D.value) return t.preventDefault(), t.stopPropagation(), !0;
123
- let n = t.dataTransfer?.getData(C);
124
- return !n || n === T.page.id ? !1 : (t.preventDefault(), E("variable-move-blocked", T.page.id), !0);
148
+ if (T.value) return t.preventDefault(), t.stopPropagation(), !0;
149
+ let n = t.dataTransfer?.getData(S);
150
+ return !n || n === C.page.id ? !1 : (t.preventDefault(), w("variable-move-blocked", C.page.id), !0);
125
151
  }
126
152
  },
127
153
  handleKeyDown: (e, t) => {
128
- if (D.value || !Pe(t)) return !1;
129
- let n = j.value;
154
+ if (T.value || !Je(t)) return !1;
155
+ let n = R.value;
130
156
  if (!n) return !1;
131
157
  t.preventDefault();
132
- let r = n.state.selection, i = B();
158
+ let r = n.state.selection, i = U();
133
159
  if (i) {
134
160
  let e = n.view.coordsAtPos(r.from);
135
- return R({
136
- pageId: T.page.id,
161
+ return V({
162
+ pageId: C.page.id,
137
163
  clientX: e.left,
138
164
  clientY: e.bottom
139
165
  }, i), !0;
140
166
  }
141
- let a = r instanceof x;
142
- if (d({
167
+ let a = r instanceof b;
168
+ if (f({
143
169
  isCellSelection: a,
144
170
  selectionEmpty: r.empty,
145
171
  inTable: n.isActive("table")
146
172
  }) === "table") {
147
173
  if (!a) {
148
- let e = Ie();
149
- typeof e == "number" && n.view.dispatch(n.state.tr.setSelection(x.create(n.state.doc, e)));
174
+ let e = Ze();
175
+ typeof e == "number" && n.view.dispatch(n.state.tr.setSelection(b.create(n.state.doc, e)));
150
176
  }
151
177
  let e = n.view.coordsAtPos(n.state.selection.from);
152
- return V({
153
- pageId: T.page.id,
178
+ return it({
179
+ pageId: C.page.id,
154
180
  clientX: e.left,
155
181
  clientY: e.bottom
156
182
  }), !0;
157
183
  }
158
184
  let o = n.view.coordsAtPos(n.state.selection.from);
159
- return L({
160
- pageId: T.page.id,
185
+ return B({
186
+ pageId: C.page.id,
161
187
  clientX: o.left,
162
188
  clientY: o.bottom
163
189
  }), !0;
164
- }
190
+ },
191
+ handleScrollToSelection: (e) => le(e, () => C.getScrollContainer?.(), () => E.value)
192
+ },
193
+ onTransaction: ({ transaction: e, appendedTransactions: t }) => {
194
+ [e, ...t].some((e) => e.docChanged && !e.getMeta("preventUpdate")) && (Ne = !0), !M && [e, ...t].some((e) => e.selectionSet || e.storedMarksSet) && (N = !0), [e, ...t].some((e) => e.docChanged || e.selectionSet || e.storedMarksSet || e.getMeta("blur")) && (P += 1);
165
195
  },
166
196
  onUpdate: ({ editor: e }) => {
167
- E("page-update", {
168
- ...T.page,
169
- contentHtml: e.getHTML(),
170
- contentJson: e.getJSON()
197
+ w("page-update", {
198
+ ...C.page,
199
+ contentHtml: D.read(e).getHTML(),
200
+ contentJson: D.read(e).getJSON()
171
201
  }), W();
172
202
  },
173
203
  onFocus: () => {
174
- E("editor-focus", T.page.id), W();
204
+ w("editor-focus", C.page.id), W();
175
205
  },
176
206
  onBlur: W,
177
207
  onSelectionUpdate: W,
208
+ onMount: () => {
209
+ F = P;
210
+ },
178
211
  onCreate: ({ editor: e }) => {
179
- e.on("contract-word-paste", M), W(), E("editor-ready", T.page.id);
212
+ if (C.page.contentHtml !== Pe && C.page.contentHtml !== D.read(e).getHTML()) if (O || e.view.composing) A = C.page.contentHtml;
213
+ else {
214
+ let t = F === P ? P + 1 : void 0;
215
+ e.commands.setContent(C.page.contentHtml || "<p></p>", { emitUpdate: !1 }), F = t;
216
+ }
217
+ M = !0, e.on("contract-word-paste", He), W(), w("editor-ready", C.page.id);
180
218
  }
181
- }), { findText: Te, revealSearchMatch: Ee, replaceSearchMatches: De, focusHeading: Oe } = te({
182
- editor: () => j.value,
183
- readonly: () => D.value,
219
+ }), { findText: Re, revealSearchMatch: ze, replaceSearchMatches: Be, focusHeading: Ve } = re({
220
+ editor: () => R.value,
221
+ readonly: () => T.value,
184
222
  search: () => ({
185
- query: T.searchQuery,
186
- matchCase: T.searchMatchCase,
187
- activeMatch: T.activeSearchMatch
223
+ query: C.searchQuery,
224
+ matchCase: C.searchMatchCase,
225
+ activeMatch: C.activeSearchMatch
188
226
  })
189
227
  });
190
- function M(e) {
191
- E("word-paste", e);
228
+ function He(e) {
229
+ w("word-paste", e);
192
230
  }
193
- function ke(e) {
231
+ function Ue(e) {
194
232
  if (typeof e == "number" && Number.isFinite(e)) return e;
195
233
  let t = String(e || "").match(/(\d+(\.\d+)?)/);
196
234
  return t ? Number(t[1]) : void 0;
197
235
  }
198
- function Ae() {
199
- if (!j.value) return "";
200
- let { from: e, to: t } = j.value.state.selection;
201
- return j.value.state.doc.textBetween(e, t, "\n");
236
+ function We() {
237
+ if (!R.value) return "";
238
+ let { from: e, to: t } = R.value.state.selection;
239
+ return R.value.state.doc.textBetween(e, t, "\n");
202
240
  }
203
- function je() {
204
- let e = j.value, t = e?.state.selection;
241
+ function Ge() {
242
+ let e = R.value, t = e?.state.selection;
205
243
  if (!(!e || !t || t.empty)) try {
206
244
  let n = e.view.coordsAtPos(t.from), r = e.view.coordsAtPos(t.to, -1);
207
- if (Math.abs(r.top - n.top) > Ce) return;
245
+ if (Math.abs(r.top - n.top) > Ae) return;
208
246
  let i = Math.abs(r.left - n.left) / G.value;
209
247
  return Number.isFinite(i) && i > 0 ? i : void 0;
210
248
  } catch {
211
249
  return;
212
250
  }
213
251
  }
214
- function Me() {
215
- let e = j.value, t = e?.state.selection;
216
- if (!(!e || !t || t.empty) && !(t instanceof x || t instanceof S)) try {
252
+ function Ke() {
253
+ let e = R.value, t = e?.state.selection;
254
+ if (!(!e || !t || t.empty) && !(t instanceof b || t instanceof x)) try {
217
255
  let n = e.view.coordsAtPos(t.from), r = e.view.coordsAtPos(t.to, -1);
218
256
  return {
219
257
  top: Math.min(n.top, r.top),
@@ -225,8 +263,8 @@ var Se = { class: "gd-contract-template-designer__page-title" }, C = "applicatio
225
263
  return;
226
264
  }
227
265
  }
228
- function Ne() {
229
- let e = j.value;
266
+ function qe() {
267
+ let e = R.value;
230
268
  if (!e) return "";
231
269
  let t = e.state.selection.$from, n = t.pos;
232
270
  for (let e = t.depth; e > 0; --e) {
@@ -238,35 +276,35 @@ var Se = { class: "gd-contract-template-designer__page-title" }, C = "applicatio
238
276
  }
239
277
  return e.state.doc.textBetween(n, e.state.selection.from, "");
240
278
  }
241
- function Pe(e) {
279
+ function Je(e) {
242
280
  return e.key === "ContextMenu" || e.shiftKey && e.key === "F10";
243
281
  }
244
- function N(e) {
282
+ function Ye(e) {
245
283
  for (let t = e.depth; t > 0; --t) {
246
284
  let n = e.node(t).type.spec.tableRole;
247
285
  if (n === "cell" || n === "header_cell") return e.before(t);
248
286
  }
249
287
  }
250
- function Fe(e, t) {
251
- let n = j.value, r = n?.view.posAtCoords({
288
+ function Xe(e, t) {
289
+ let n = R.value, r = n?.view.posAtCoords({
252
290
  left: e,
253
291
  top: t
254
292
  })?.pos;
255
- if (!(!n || typeof r != "number")) return N(n.state.doc.resolve(r));
293
+ if (!(!n || typeof r != "number")) return Ye(n.state.doc.resolve(r));
256
294
  }
257
- function Ie() {
258
- let e = j.value;
259
- if (e) return N(e.state.selection.$from);
295
+ function Ze() {
296
+ let e = R.value;
297
+ if (e) return Ye(e.state.selection.$from);
260
298
  }
261
- function Le(e, t, n) {
262
- let r = j.value, i = n instanceof HTMLElement ? n : null;
299
+ function Qe(e, t, n) {
300
+ let r = R.value, i = n instanceof HTMLElement ? n : null;
263
301
  if (!r || !i?.closest("td,th")) return !1;
264
- if (r.state.selection instanceof x && i.closest("td.selectedCell,th.selectedCell")) return !0;
265
- let a = Fe(e, t);
266
- return typeof a == "number" ? (r.view.dispatch(r.state.tr.setSelection(x.create(r.state.doc, a))), !0) : !1;
302
+ if (r.state.selection instanceof b && i.closest("td.selectedCell,th.selectedCell")) return !0;
303
+ let a = Xe(e, t);
304
+ return typeof a == "number" ? (r.view.dispatch(r.state.tr.setSelection(b.create(r.state.doc, a))), !0) : !1;
267
305
  }
268
- function P() {
269
- let e = j.value, t = e?.isActive("table") ? e.can() : void 0, n = (e) => !!(t && e(t));
306
+ function $e() {
307
+ let e = R.value, t = e?.isActive("table") ? e.can() : void 0, n = (e) => !!(t && e(t));
270
308
  return {
271
309
  addRowBefore: n((e) => e.addRowBefore()),
272
310
  addRowAfter: n((e) => e.addRowAfter()),
@@ -284,97 +322,97 @@ var Se = { class: "gd-contract-template-designer__page-title" }, C = "applicatio
284
322
  deleteTable: n((e) => e.deleteTable())
285
323
  };
286
324
  }
287
- function Re() {
288
- let e = j.value, t = e?.state.selection;
289
- if (!e || !(t instanceof x)) return "left";
325
+ function et() {
326
+ let e = R.value, t = e?.state.selection;
327
+ if (!e || !(t instanceof b)) return "left";
290
328
  let n = /* @__PURE__ */ new Set();
291
329
  return t.forEachCell((e) => {
292
330
  let t = e.attrs.textAlign;
293
331
  n.add(t === "center" || t === "right" ? t : "left");
294
332
  }), n.size === 1 ? n.values().next().value ?? "left" : "mixed";
295
333
  }
296
- function F(e = j.value?.state.doc) {
334
+ function tt(e = R.value?.state.doc) {
297
335
  let t = 0;
298
336
  return e?.descendants((e) => {
299
337
  e.type.name === "templateVariable" && (t += 1);
300
338
  }), t;
301
339
  }
302
- function I(e) {
303
- let t = j.value;
340
+ function z(e) {
341
+ let t = R.value;
304
342
  if (!t) return 0;
305
- let n = F(t.state.doc), r = n, i = (e) => {
306
- r = F(e.doc);
343
+ let n = tt(t.state.doc), r = n, i = (e) => {
344
+ r = tt(e.doc);
307
345
  };
308
- return e === "delete-table-row" ? be(t.state, i) : e === "delete-table-column" ? ye(t.state, i) : xe(t.state, i), Math.max(0, n - r);
346
+ return e === "delete-table-row" ? Ee(t.state, i) : e === "delete-table-column" ? Te(t.state, i) : De(t.state, i), Math.max(0, n - r);
309
347
  }
310
- function L(e) {
311
- let t = j.value?.state.selection, n = !!(t && !t.empty);
312
- E("editor-context-menu", {
348
+ function B(e) {
349
+ let t = R.value?.state.selection, n = !!(t && !t.empty);
350
+ w("editor-context-menu", {
313
351
  type: "text",
314
352
  ...e,
315
353
  hasSelection: n,
316
- selectionWidth: n ? je() : void 0,
317
- leadingText: Ne()
354
+ selectionWidth: n ? Ge() : void 0,
355
+ leadingText: qe()
318
356
  });
319
357
  }
320
- function ze(e, t) {
321
- L({
322
- pageId: T.page.id,
358
+ function nt(e, t) {
359
+ B({
360
+ pageId: C.page.id,
323
361
  clientX: e,
324
362
  clientY: t
325
363
  });
326
364
  }
327
- function R(e, t) {
328
- E("editor-context-menu", {
365
+ function V(e, t) {
366
+ w("editor-context-menu", {
329
367
  type: "image",
330
368
  ...e,
331
369
  image: t
332
370
  });
333
371
  }
334
- function z(e, t) {
372
+ function H(e, t) {
335
373
  if (!(e.type.name !== "image" || typeof e.attrs.src != "string" || !e.attrs.src)) return {
336
374
  position: t,
337
375
  src: e.attrs.src,
338
376
  alt: typeof e.attrs.alt == "string" ? e.attrs.alt : void 0,
339
377
  title: typeof e.attrs.title == "string" ? e.attrs.title : void 0,
340
- width: l(e.attrs.width),
341
- height: l(e.attrs.height)
378
+ width: u(e.attrs.width),
379
+ height: u(e.attrs.height)
342
380
  };
343
381
  }
344
- function B() {
345
- let e = j.value?.state.selection;
346
- if (e instanceof S) return z(e.node, e.from);
382
+ function U() {
383
+ let e = R.value?.state.selection;
384
+ if (e instanceof x) return H(e.node, e.from);
347
385
  }
348
- function Be(e, t) {
386
+ function rt(e, t) {
349
387
  let n = t instanceof HTMLElement ? t.closest("[data-template-variable], img[src]") : null;
350
388
  if (n) try {
351
389
  let t = e.posAtDOM(n, 0), r = e.state.doc.nodeAt(t);
352
- return !r || r.type.name !== "templateVariable" && r.type.name !== "image" ? void 0 : (r.type.name === "templateVariable" && typeof r.attrs.key == "string" && E("variable-select", r.attrs.key), (!(e.state.selection instanceof S) || e.state.selection.from !== t) && e.dispatch(e.state.tr.setSelection(S.create(e.state.doc, t))), z(r, t));
390
+ return !r || r.type.name !== "templateVariable" && r.type.name !== "image" ? void 0 : (r.type.name === "templateVariable" && typeof r.attrs.key == "string" && w("variable-select", r.attrs.key), (!(e.state.selection instanceof x) || e.state.selection.from !== t) && e.dispatch(e.state.tr.setSelection(x.create(e.state.doc, t))), H(r, t));
353
391
  } catch {
354
392
  return;
355
393
  }
356
394
  }
357
- function V(e) {
358
- E("editor-context-menu", {
395
+ function it(e) {
396
+ w("editor-context-menu", {
359
397
  type: "table",
360
398
  ...e,
361
- capabilities: P(),
362
- activeAlignment: Re(),
399
+ capabilities: $e(),
400
+ activeAlignment: et(),
363
401
  affectedVariableCounts: {
364
- deleteRow: I("delete-table-row"),
365
- deleteColumn: I("delete-table-column"),
366
- deleteTable: I("delete-table")
402
+ deleteRow: z("delete-table-row"),
403
+ deleteColumn: z("delete-table-column"),
404
+ deleteTable: z("delete-table")
367
405
  }
368
406
  });
369
407
  }
370
- function Ve(e) {
408
+ function at(e) {
371
409
  return typeof e == "number" && Number.isInteger(e) && e >= 1 && e <= 6;
372
410
  }
373
- function H() {
374
- let e = j.value;
411
+ function ot() {
412
+ let e = R.value;
375
413
  if (!e) return [];
376
414
  let { doc: t, selection: n } = e.state, r = [], i = (e) => {
377
- e.type.name === "paragraph" ? r.push("paragraph") : e.type.name === "heading" && Ve(e.attrs.level) && r.push(e.attrs.level);
415
+ e.type.name === "paragraph" ? r.push("paragraph") : e.type.name === "heading" && at(e.attrs.level) && r.push(e.attrs.level);
378
416
  };
379
417
  if (n.empty) for (let e = n.$from.depth; e > 0; e--) {
380
418
  let t = n.$from.node(e);
@@ -386,18 +424,18 @@ var Se = { class: "gd-contract-template-designer__page-title" }, C = "applicatio
386
424
  else t.nodesBetween(n.from, n.to, (e) => (i(e), !0));
387
425
  return Array.from(new Set(r));
388
426
  }
389
- function He() {
390
- let e = H();
427
+ function st() {
428
+ let e = ot();
391
429
  return e.length === 1 && e[0] !== "paragraph" ? e[0] : void 0;
392
430
  }
393
- function Ue() {
394
- return H().length > 1;
431
+ function ct() {
432
+ return ot().length > 1;
395
433
  }
396
- function We() {
397
- return ["center", "right"].find((e) => j.value?.isActive("heading", { textAlign: e }) || j.value?.isActive("paragraph", { textAlign: e })) ?? "left";
434
+ function lt() {
435
+ return ["center", "right"].find((e) => R.value?.isActive("heading", { textAlign: e }) || R.value?.isActive("paragraph", { textAlign: e })) ?? "left";
398
436
  }
399
- function U() {
400
- let e = j.value, t = (t) => !!e?.isActive(t), n = e?.getAttributes("textStyle") ?? {};
437
+ function ut() {
438
+ let e = R.value, t = (t) => !!e?.isActive(t), n = e?.getAttributes("textStyle") ?? {};
401
439
  return {
402
440
  isFocused: !!e?.isFocused,
403
441
  canUndo: !!e?.can().undo(),
@@ -408,76 +446,87 @@ var Se = { class: "gd-contract-template-designer__page-title" }, C = "applicatio
408
446
  isBulletList: t("bulletList"),
409
447
  isOrderedList: t("orderedList"),
410
448
  isTableActive: t("table"),
411
- currentHeadingLevel: He(),
412
- hasMixedBlockFormats: Ue(),
413
- textAlign: We(),
449
+ currentHeadingLevel: st(),
450
+ hasMixedBlockFormats: ct(),
451
+ textAlign: lt(),
414
452
  fontFamily: typeof n.fontFamily == "string" ? n.fontFamily : void 0,
415
- fontSize: ke(n.fontSize),
453
+ fontSize: Ue(n.fontSize),
416
454
  textColor: typeof n.color == "string" ? n.color : void 0,
417
- selectionText: Ae(),
418
- selectedContentImage: B()
455
+ selectionText: We(),
456
+ selectedContentImage: U()
419
457
  };
420
458
  }
421
459
  function W() {
422
- E("editor-state-change", T.page.id, U());
460
+ w("editor-state-change", C.page.id, ut());
423
461
  }
424
- b(D, (e) => {
425
- j.value?.setEditable(!e), W();
426
- }), b(() => T.page.contentHtml, (e) => {
427
- !j.value || e === j.value.getHTML() || (j.value.commands.setContent(e || "<p></p>", { emitUpdate: !1 }), W());
462
+ y(T, (e) => {
463
+ R.value?.setEditable(!e), W();
464
+ }), y(() => C.page.contentHtml, (e) => {
465
+ dt(e);
428
466
  });
429
- let Ge = f(() => {
430
- let e = o(T.pageDecorations), t = T.pageIndex + 1, s = a(e, t) ? r(e.header) : n.top, c = i(e, t) ? r(e.footer) : n.bottom;
467
+ function dt(e) {
468
+ if (!R.value || e === $()) {
469
+ A = void 0;
470
+ return;
471
+ }
472
+ if (L()) {
473
+ A = e;
474
+ return;
475
+ }
476
+ R.value.commands.setContent(e || "<p></p>", { emitUpdate: !1 }), W();
477
+ }
478
+ let ft = p(() => {
479
+ let e = o(C.pageDecorations), t = C.pageIndex + 1, s = a(e, t) ? r(e.header) : n.top, c = i(e, t) ? r(e.footer) : n.bottom;
431
480
  return {
432
- width: `${T.pageSize.width}px`,
433
- height: `${T.pageSize.height}px`,
481
+ width: `${C.pageSize.width}px`,
482
+ height: `${C.pageSize.height}px`,
434
483
  paddingTop: `${s}px`,
435
484
  paddingBottom: `${c}px`,
436
- "--gd-contract-page-content-height": `${Math.max(120, T.pageSize.height - s - c)}px`
485
+ "--gd-contract-page-content-height": `${Math.max(120, C.pageSize.height - s - c)}px`
437
486
  };
438
- }), G = f(() => Math.max(.1, T.zoom || 1)), Ke = f(() => ({
439
- width: `${Math.ceil((T.pageSize.width + 10) * G.value)}px`,
440
- height: `${Math.ceil((T.pageSize.height + 40) * G.value)}px`
441
- })), qe = f(() => ({ "--gd-contract-page-zoom": String(G.value) })), Je = f(() => c(T.pageSize));
442
- function Ye(e) {
443
- if (T.readonly || T.disabled) {
487
+ }), G = p(() => Math.max(.1, C.zoom || 1)), pt = p(() => ({
488
+ width: `${Math.ceil((C.pageSize.width + 10) * G.value)}px`,
489
+ height: `${Math.ceil((C.pageSize.height + 40) * G.value)}px`
490
+ })), mt = p(() => ({ "--gd-contract-page-zoom": String(G.value) })), ht = p(() => c(C.pageSize));
491
+ function gt(e) {
492
+ if (C.readonly || C.disabled) {
444
493
  e.preventDefault(), e.stopPropagation();
445
494
  return;
446
495
  }
447
496
  let t = e.dataTransfer?.getData("application/x-gd-contract-variable");
448
497
  if (t) {
449
- e.preventDefault(), e.stopPropagation(), E("variable-drop", T.page.id, t, e.clientX, e.clientY);
498
+ e.preventDefault(), e.stopPropagation(), w("variable-drop", C.page.id, t, e.clientX, e.clientY);
450
499
  return;
451
500
  }
452
- let n = e.dataTransfer?.getData(C);
453
- n && n !== T.page.id && (e.preventDefault(), e.stopPropagation(), E("variable-move-blocked", T.page.id));
501
+ let n = e.dataTransfer?.getData(S);
502
+ n && n !== C.page.id && (e.preventDefault(), e.stopPropagation(), w("variable-move-blocked", C.page.id));
454
503
  }
455
- function Xe(e, t) {
456
- let n = j.value;
457
- return n ? (re(n, e, t ? n.view.posAtCoords(t)?.pos : void 0), $(), K()) : void 0;
504
+ function _t(e, t) {
505
+ let n = R.value;
506
+ return n ? (ae(n, e, t ? n.view.posAtCoords(t)?.pos : void 0), Z(), K()) : void 0;
458
507
  }
459
- function Ze(e, t) {
460
- let n = j.value;
461
- if (n) return u(n, {
508
+ function vt(e, t) {
509
+ let n = R.value;
510
+ if (n) return d(n, {
462
511
  type: "insert-content-image",
463
512
  image: e,
464
513
  position: t
465
514
  }), K();
466
515
  }
467
- function Qe(e) {
468
- let t = j.value, n = t?.state.selection;
469
- if (!t || !(n instanceof S) || n.node.type.name !== "image") return;
516
+ function yt(e) {
517
+ let t = R.value, n = t?.state.selection;
518
+ if (!t || !(n instanceof x) || n.node.type.name !== "image") return;
470
519
  let r = { ...n.node.attrs }, i = !1;
471
520
  if (["width", "height"].forEach((t) => {
472
521
  if (!Object.prototype.hasOwnProperty.call(e, t)) return;
473
- let n = e[t] === void 0 ? null : l(e[t]) ?? null;
522
+ let n = e[t] === void 0 ? null : u(e[t]) ?? null;
474
523
  r[t] !== n && (r[t] = n, i = !0);
475
524
  }), !i) return;
476
525
  let a = t.state.tr.setNodeMarkup(n.from, void 0, r);
477
- return a.setSelection(S.create(a.doc, n.from)), t.view.dispatch(a), K();
526
+ return a.setSelection(x.create(a.doc, n.from)), t.view.dispatch(a), K();
478
527
  }
479
- function $e() {
480
- let e = j.value?.state.selection;
528
+ function bt() {
529
+ let e = R.value?.state.selection;
481
530
  return e ? {
482
531
  from: e.from,
483
532
  to: e.to
@@ -485,10 +534,24 @@ var Se = { class: "gd-contract-template-designer__page-title" }, C = "applicatio
485
534
  }
486
535
  function K() {
487
536
  return {
488
- ...T.page,
489
- pageSize: Je.value,
490
- contentHtml: j.value?.getHTML() ?? T.page.contentHtml,
491
- contentJson: j.value?.getJSON() ?? T.page.contentJson
537
+ ...C.page,
538
+ pageSize: ht.value,
539
+ contentHtml: $(),
540
+ contentJson: Q() ?? C.page.contentJson
541
+ };
542
+ }
543
+ function xt(e) {
544
+ if (!I()) return {
545
+ contentHtml: e.contentHtml,
546
+ contentJson: e.contentJson
547
+ };
548
+ let t = $();
549
+ return !L() && e.contentHtml !== C.page.contentHtml && e.contentHtml !== t ? {
550
+ contentHtml: e.contentHtml,
551
+ contentJson: e.contentJson
552
+ } : {
553
+ contentHtml: t,
554
+ contentJson: Q()
492
555
  };
493
556
  }
494
557
  function q(e) {
@@ -497,24 +560,24 @@ var Se = { class: "gd-contract-template-designer__page-title" }, C = "applicatio
497
560
  content: e.length ? e : [{ type: "paragraph" }]
498
561
  };
499
562
  }
500
- function et(e) {
563
+ function St(e) {
501
564
  return e?.length ? e.length === 1 && e[0].type === "paragraph" && !e[0].content?.length : !0;
502
565
  }
503
- function tt(e) {
504
- return ve(q(e), A);
566
+ function Ct(e) {
567
+ return we(q(e), Le);
505
568
  }
506
- function nt() {
507
- if (T.pageDecorations) {
508
- let e = o(T.pageDecorations), t = T.pageIndex + 1, s = a(e, t) ? r(e.header) : n.top, c = i(e, t) ? r(e.footer) : n.bottom;
509
- return Math.max(120, T.pageSize.height - s - c);
569
+ function wt() {
570
+ if (C.pageDecorations) {
571
+ let e = o(C.pageDecorations), t = C.pageIndex + 1, s = a(e, t) ? r(e.header) : n.top, c = i(e, t) ? r(e.footer) : n.bottom;
572
+ return Math.max(120, C.pageSize.height - s - c);
510
573
  }
511
- let e = O.value;
512
- if (!e) return T.pageSize.height - 108;
574
+ let e = E.value;
575
+ if (!e) return C.pageSize.height - 108;
513
576
  let t = window.getComputedStyle(e), s = Number.parseFloat(t.paddingTop) || 0, c = Number.parseFloat(t.paddingBottom) || 0;
514
- return Math.max(120, T.pageSize.height - s - c);
577
+ return Math.max(120, C.pageSize.height - s - c);
515
578
  }
516
- function rt() {
517
- let e = O.value?.querySelector(".gd-contract-template-designer__editor-prose");
579
+ function Tt() {
580
+ let e = E.value?.querySelector(".gd-contract-template-designer__editor-prose");
518
581
  if (!e) return [];
519
582
  let t = e.getBoundingClientRect(), n = G.value;
520
583
  return Array.from(e.children).map((r) => {
@@ -536,26 +599,76 @@ var Se = { class: "gd-contract-template-designer__page-title" }, C = "applicatio
536
599
  });
537
600
  }
538
601
  function J() {
539
- return j.value ? ee(j.value.getJSON().content, rt(), nt()) : void 0;
602
+ if (!R.value) return;
603
+ let e = Tt(), t = wt();
604
+ if (e.some((e) => e.top + e.height > t + 1)) return l(Q()?.content, e, t);
540
605
  }
541
- function it() {
606
+ function Et() {
542
607
  return !!J();
543
608
  }
544
- function at() {
545
- if (!j.value) return;
609
+ function Dt() {
610
+ let e = R.value;
611
+ if (!e || !I() || L() || !e.view.hasFocus()) return !1;
612
+ let t = J();
613
+ if (!t) return !1;
614
+ let n = 0;
615
+ for (let r = 0; r < t.splitIndex; r++) n += e.state.doc.child(r).nodeSize;
616
+ if (t.currentContent.length > t.splitIndex) {
617
+ let r = e.state.doc.child(t.splitIndex), i = t.currentContent[t.splitIndex].content.length;
618
+ for (let e = 0; e < i; e++) n += r.child(e).nodeSize;
619
+ n += 1;
620
+ }
621
+ return e.state.selection.ranges.every((e) => e.$from.pos >= n);
622
+ }
623
+ function Ot(e) {
624
+ return (!e || ye(e) === Fe) && !Ne && !L() && !R.value?.view.hasFocus() && St(Q()?.content);
625
+ }
626
+ function kt() {
627
+ if (!R.value || !I() || L()) return;
546
628
  let e = J();
547
- if (e) return j.value.commands.setContent(q(e.currentContent), { emitUpdate: !1 }), {
629
+ if (!e) return;
630
+ let t = R.value, { doc: n, selection: r, storedMarks: i } = t.state, a = t.state.tr, o = 0;
631
+ for (let t = 0; t < e.splitIndex; t++) o += n.child(t).nodeSize;
632
+ let s = o, c = o;
633
+ if (e.currentContent.length > e.splitIndex) {
634
+ let t = n.child(e.splitIndex), r = e.currentContent[e.splitIndex].content.length;
635
+ for (let e = 0; e < r; e++) s += t.child(e).nodeSize;
636
+ c = s + 1, a.delete(c, o + t.nodeSize - 1), a.delete(s + 2, a.doc.content.size);
637
+ } else a.delete(o, n.content.size);
638
+ let l = t.view.hasFocus() && r.ranges.every((e) => e.$from.pos >= c) ? r.map(t.schema.nodeFromJSON(q(e.overflowContent)), new te([new ne([
639
+ 0,
640
+ s,
641
+ 0
642
+ ])])) : void 0;
643
+ a.setMeta("preventUpdate", !0).setMeta("addToHistory", !1).setStoredMarks(i);
644
+ let ee = P + 1;
645
+ t.view.dispatch(a);
646
+ let re = l && {
647
+ selection: l,
648
+ storedMarks: i,
649
+ isCurrent: () => !j && R.value === t && !t.isDestroyed && !T.value && !L() && t.view.hasFocus() && P === ee
650
+ };
651
+ return {
548
652
  page: K(),
549
653
  overflowContent: e.overflowContent,
550
- overflowHtml: tt(e.overflowContent)
654
+ overflowHtml: Ct(e.overflowContent),
655
+ selection: re
551
656
  };
552
657
  }
553
- function Y(e) {
554
- if (!j.value || !e.length) return;
555
- let t = j.value.getJSON().content, n = [...e, ...et(t) ? [] : t ?? []];
556
- return j.value.commands.setContent(q(n), { emitUpdate: !1 }), K();
658
+ function At(e) {
659
+ if (!R.value || !I() || L() || !e.length) return;
660
+ let t = R.value, n = t.schema.nodeFromJSON(q(e)).content, { doc: r, storedMarks: i } = t.state, a = t.state.tr;
661
+ St(Q()?.content) ? a.replaceWith(0, r.content.size, n) : a.insert(0, n), a.setMeta("preventUpdate", !0).setMeta("addToHistory", !1).setStoredMarks(i);
662
+ let o = P + 1;
663
+ return t.view.dispatch(a), F = N ? void 0 : o, N = !1, K();
557
664
  }
558
- function X(e, t) {
665
+ function jt(e, t) {
666
+ let n = R.value, r = F;
667
+ if (F = void 0, !n || !I() || T.value || L() || r !== P || !e.isCurrent() || $() !== t) return;
668
+ let i = Oe.fromJSON(n.state.doc, e.selection.toJSON()), a = P + 1;
669
+ n.view.dispatch(n.state.tr.setSelection(i).setStoredMarks(e.storedMarks?.map((e) => n.schema.markFromJSON(e.toJSON())) ?? null).setMeta("addToHistory", !1)), !(!e.isCurrent() || P !== a) && (n.view.focus(), n.view.hasFocus() && P === a && n.commands.scrollIntoView());
670
+ }
671
+ function Y(e, t) {
559
672
  let n = [];
560
673
  return e.descendants((e, r) => {
561
674
  e.type.name === "templateVariable" && e.attrs.key === t && n.push({
@@ -564,141 +677,148 @@ var Se = { class: "gd-contract-template-designer__page-title" }, C = "applicatio
564
677
  });
565
678
  }), n;
566
679
  }
567
- function ot(e, t = e.key) {
568
- if (!j.value) return;
569
- let n = ne(e), r = !1;
570
- return j.value.commands.command(({ tr: e, state: i, dispatch: a }) => (X(i.doc, t).forEach(({ node: t, pos: i }) => {
680
+ function Mt(e, t = e.key) {
681
+ if (!R.value) return;
682
+ let n = ie(e), r = !1;
683
+ return R.value.commands.command(({ tr: e, state: i, dispatch: a }) => (Y(i.doc, t).forEach(({ node: t, pos: i }) => {
571
684
  e.setNodeMarkup(i, void 0, {
572
685
  ...t.attrs,
573
686
  ...n
574
687
  }), r = !0;
575
- }), r && a?.(e), r)), $(), r ? K() : void 0;
688
+ }), r && a?.(e), r)), Z(), r ? K() : void 0;
576
689
  }
577
- function st(e) {
578
- if (!j.value) return;
690
+ function Nt(e) {
691
+ if (!R.value) return;
579
692
  let t = 0;
580
- return j.value.commands.command(({ tr: n, state: r, dispatch: i }) => {
581
- let a = X(r.doc, e).map(({ node: e, pos: t }) => ({
693
+ return R.value.commands.command(({ tr: n, state: r, dispatch: i }) => {
694
+ let a = Y(r.doc, e).map(({ node: e, pos: t }) => ({
582
695
  from: t,
583
696
  to: t + e.nodeSize
584
697
  })).sort((e, t) => t.from - e.from);
585
698
  return a.forEach((e) => n.delete(e.from, e.to)), t = a.length, t && i?.(n), t > 0;
586
699
  }), t ? K() : void 0;
587
700
  }
588
- function Z() {
589
- O.value?.querySelectorAll(".gd-contract-template-variable.is-active").forEach((e) => e.classList.remove("is-active"));
701
+ function Pt() {
702
+ E.value?.querySelectorAll(".gd-contract-template-variable.is-active").forEach((e) => e.classList.remove("is-active"));
590
703
  }
591
- function Q(e) {
592
- if (e) return Array.from(O.value?.querySelectorAll("[data-template-variable]") ?? []).find((t) => t.dataset.key === e);
704
+ function X(e) {
705
+ if (e) return Array.from(E.value?.querySelectorAll("[data-template-variable]") ?? []).find((t) => t.dataset.key === e);
593
706
  }
594
- function ct(e) {
595
- Z();
596
- let t = Q(e);
707
+ function Ft(e) {
708
+ Pt();
709
+ let t = X(e);
597
710
  return t ? (t.classList.add("is-active"), t.scrollIntoView({
598
711
  behavior: "smooth",
599
712
  block: "center",
600
713
  inline: "center"
601
- }), j.value?.commands.focus(), !0) : !1;
714
+ }), R.value?.commands.focus(), !0) : !1;
602
715
  }
603
- function $() {
604
- Z(), Q(T.selectedVariableKey)?.classList.add("is-active");
716
+ function Z() {
717
+ Pt(), X(C.selectedVariableKey)?.classList.add("is-active");
605
718
  }
606
- function lt(n) {
607
- let r = e.find((e) => e.key === n), i = j.value;
719
+ function It(n) {
720
+ let r = e.find((e) => e.key === n), i = R.value;
608
721
  if (!r || !i) return;
609
722
  let a = i.chain().focus().clearNodes();
610
723
  r.headingLevel ? a.setHeading({ level: r.headingLevel }) : a.setParagraph(), a.unsetAllMarks().unsetTextAlign().unsetFontSize().unsetFontFamily().unsetColor().setTextAlign(r.textAlign).setFontSize(`${r.fontSize}px`).setFontFamily(r.fontFamily || t).setColor(s.color || "#1f2937"), r.bold ? a.setBold() : a.unsetBold(), r.italic ? a.setItalic() : a.unsetItalic(), r.underline ? a.setUnderline() : a.unsetUnderline(), a.run();
611
724
  }
612
- b([() => T.selectedVariableKey, () => T.variables], () => {
613
- de($);
725
+ y([() => C.selectedVariableKey, () => C.variables], () => {
726
+ me(Z);
614
727
  }, {
615
728
  deep: !0,
616
729
  flush: "post"
617
730
  });
618
- function ut(e) {
619
- D.value || (e.type === "apply-block-style" ? j.value && ae(j.value, e.format) : e.type === "apply-text-style-preset" ? lt(e.preset) : u(j.value, e), W());
731
+ function Lt(e) {
732
+ T.value || (e.type === "apply-block-style" ? R.value && se(R.value, e.format) : e.type === "apply-text-style-preset" ? It(e.preset) : d(R.value, e), W());
620
733
  }
621
- function dt() {
622
- j.value?.commands.focus();
734
+ function Rt() {
735
+ R.value?.commands.focus();
623
736
  }
624
- function ft() {
625
- return j.value?.getJSON();
737
+ function Q() {
738
+ return R.value ? D.read(R.value).getJSON() : C.page.contentJson;
626
739
  }
627
- function pt() {
628
- return j.value?.getHTML() ?? T.page.contentHtml;
740
+ function $() {
741
+ return R.value ? D.read(R.value).getHTML() : C.page.contentHtml;
629
742
  }
630
- function mt(e) {
631
- let t = T.variables.find((t) => t.id === e || t.key === e), n = t ? Q(t.key) : void 0;
632
- $(), n?.scrollIntoView({
743
+ function zt(e) {
744
+ let t = C.variables.find((t) => t.id === e || t.key === e), n = t ? X(t.key) : void 0;
745
+ Z(), n?.scrollIntoView({
633
746
  behavior: "smooth",
634
747
  block: "center"
635
748
  });
636
749
  }
637
- function ht() {
638
- O.value?.scrollIntoView({
750
+ function Bt() {
751
+ E.value?.scrollIntoView({
639
752
  behavior: "smooth",
640
753
  block: "start",
641
754
  inline: "center"
642
755
  });
643
756
  }
644
- return fe(() => {
645
- j.value?.off("contract-word-paste", M), j.value?.destroy();
646
- }), w({
647
- findText: Te,
648
- revealSearchMatch: Ee,
649
- replaceSearchMatches: De,
650
- focusHeading: Oe,
651
- focus: dt,
652
- getHTML: pt,
653
- getJSON: ft,
654
- getEditorState: U,
655
- getTableCommandCapabilities: P,
656
- getAffectedVariableCount: I,
657
- insertVariable: Xe,
658
- insertContentImage: Ze,
659
- updateSelectedContentImage: Qe,
660
- getSelectionRange: $e,
661
- getSelectionViewportRect: Me,
662
- requestTextContextMenu: ze,
663
- hasOverflowContent: it,
664
- updateVariable: ot,
665
- removeVariable: st,
666
- splitOverflowContent: at,
667
- prependContent: Y,
668
- runCommand: ut,
669
- scrollIntoField: mt,
670
- scrollIntoVariable: ct,
671
- scrollIntoPage: ht
672
- }), (e, t) => (_(), le("section", {
757
+ return ge(() => {
758
+ j = !0, k !== void 0 && clearTimeout(k), R.value?.off("contract-word-paste", He), R.value?.destroy();
759
+ }), je({
760
+ findText: Re,
761
+ revealSearchMatch: ze,
762
+ replaceSearchMatches: Be,
763
+ focusHeading: Ve,
764
+ focus: Rt,
765
+ getHTML: $,
766
+ getJSON: Q,
767
+ getContentSnapshot: xt,
768
+ getEditorState: ut,
769
+ getTableCommandCapabilities: $e,
770
+ getAffectedVariableCount: z,
771
+ insertVariable: _t,
772
+ insertContentImage: vt,
773
+ updateSelectedContentImage: yt,
774
+ getSelectionRange: bt,
775
+ getSelectionViewportRect: Ke,
776
+ requestTextContextMenu: nt,
777
+ isReady: I,
778
+ isComposing: L,
779
+ hasOverflowContent: Et,
780
+ hasOverflowSelection: Dt,
781
+ isUntouchedPaginationBlank: Ot,
782
+ updateVariable: Mt,
783
+ removeVariable: Nt,
784
+ splitOverflowContent: kt,
785
+ prependContent: At,
786
+ restorePaginationSelection: jt,
787
+ runCommand: Lt,
788
+ scrollIntoField: zt,
789
+ scrollIntoVariable: Ft,
790
+ scrollIntoPage: Bt
791
+ }), (e, t) => (_e(), fe("section", {
673
792
  class: "gd-contract-template-designer__page-shell",
674
- style: g(Ke.value)
675
- }, [p("div", {
676
- class: h(["gd-contract-template-designer__page-zoom", { "is-active": m.active }]),
677
- style: g(qe.value)
678
- }, [p("header", Se, [p("span", null, v(m.page.title || `第 ${m.pageIndex + 1} 页`), 1), p("span", null, "第 " + v(m.pageIndex + 1) + " 页 · " + v(m.pageSize.label || "A4") + " · " + v(m.pageSize.width) + " × " + v(m.pageSize.height), 1)]), p("div", {
793
+ style: g(pt.value)
794
+ }, [m("div", {
795
+ class: he(["gd-contract-template-designer__page-zoom", { "is-active": h.active }]),
796
+ style: g(mt.value)
797
+ }, [m("header", ke, [m("span", null, _(h.page.title || `第 ${h.pageIndex + 1} 页`), 1), m("span", null, "第 " + _(h.pageIndex + 1) + " 页 · " + _(h.pageSize.label || "A4") + " · " + _(h.pageSize.width) + " × " + _(h.pageSize.height), 1)]), m("div", {
679
798
  ref_key: "pageElement",
680
- ref: O,
799
+ ref: E,
681
800
  class: "gd-contract-template-designer__page",
682
- style: g(Ge.value),
683
- onDragover: t[0] ||= me(() => {}, ["prevent"]),
684
- onDrop: Ye,
685
- onClick: t[1] ||= (e) => E("editor-focus", m.page.id)
686
- }, [ue(oe, {
687
- decorations: m.pageDecorations,
688
- "page-number": m.pageIndex + 1,
689
- "total-pages": m.totalPages,
690
- variables: m.variables
801
+ style: g(ft.value),
802
+ onLoadCapture: t[0] ||= (e) => w("page-layout-change", h.page.id),
803
+ onDragover: t[1] ||= be(() => {}, ["prevent"]),
804
+ onDrop: gt,
805
+ onClick: t[2] ||= (e) => w("editor-focus", h.page.id)
806
+ }, [pe(ce, {
807
+ decorations: h.pageDecorations,
808
+ "page-number": h.pageIndex + 1,
809
+ "total-pages": h.totalPages,
810
+ variables: h.variables
691
811
  }, null, 8, [
692
812
  "decorations",
693
813
  "page-number",
694
814
  "total-pages",
695
815
  "variables"
696
- ]), y(j) ? (_(), se(y(ge), {
816
+ ]), v(R) ? (_e(), ue(v(Se), {
697
817
  key: 0,
698
818
  class: "gd-contract-template-page__content",
699
- editor: y(j)
700
- }, null, 8, ["editor"])) : ce("", !0)], 36)], 6)], 4));
819
+ editor: v(R)
820
+ }, null, 8, ["editor"])) : de("", !0)], 36)], 6)], 4));
701
821
  }
702
822
  });
703
823
  //#endregion
704
- export { w as default };
824
+ export { je as default };