@guodun/antdv 1.7.7 → 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 (23) hide show
  1. package/dist/es/components/pro-contract-template-designer/src/DesignerPage.vue.mjs +395 -325
  2. package/dist/es/components/pro-contract-template-designer/src/ProContractTemplateDesigner.vue.mjs +851 -829
  3. package/dist/es/components/pro-contract-template-designer/src/composables/use-auto-pagination.mjs +122 -63
  4. package/dist/es/components/pro-contract-template-designer/src/utils/caret-viewport.mjs +41 -0
  5. package/dist/es/components/pro-contract-template-designer/style/index.css +1 -1
  6. package/dist/es/node_modules/@tiptap/pm/dist/transform/index.mjs +1 -0
  7. package/dist/es/node_modules/prosemirror-transform/dist/index.mjs +161 -67
  8. package/dist/lib/components/pro-contract-template-designer/src/DesignerPage.vue.cjs +2 -2
  9. package/dist/lib/components/pro-contract-template-designer/src/ProContractTemplateDesigner.vue.cjs +1 -1
  10. package/dist/lib/components/pro-contract-template-designer/src/composables/use-auto-pagination.cjs +1 -1
  11. package/dist/lib/components/pro-contract-template-designer/src/utils/caret-viewport.cjs +1 -0
  12. package/dist/lib/components/pro-contract-template-designer/style/index.css +1 -1
  13. package/dist/lib/node_modules/@tiptap/pm/dist/transform/index.cjs +1 -0
  14. package/dist/lib/node_modules/prosemirror-transform/dist/index.cjs +2 -2
  15. package/dist/theme/icon.css +1 -1
  16. package/dist/theme/index.css +1 -1
  17. package/dist/types/components/pro-contract-template-designer/src/DesignerPage.vue.d.ts +14 -0
  18. package/dist/types/components/pro-contract-template-designer/src/composables/use-auto-pagination.d.ts +17 -0
  19. package/dist/types/components/pro-contract-template-designer/src/utils/caret-viewport.d.ts +18 -0
  20. package/package.json +1 -1
  21. package/dist/theme/dept-selector.css +0 -1
  22. package/dist/theme/pro-selector-group.css +0 -1
  23. package/dist/theme/role-selector.css +0 -1
@@ -0,0 +1 @@
1
+ import "../../../../prosemirror-transform/dist/index.mjs";
@@ -434,7 +434,7 @@ function D(e, t, n) {
434
434
  }
435
435
  return !1;
436
436
  }
437
- function O(e, t, n, r) {
437
+ function ee(e, t, n, r) {
438
438
  let i = [], a = [], o, s;
439
439
  e.doc.nodesBetween(t, n, (e, c, l) => {
440
440
  if (!e.isInline) return;
@@ -446,7 +446,7 @@ function O(e, t, n, r) {
446
446
  }
447
447
  }), i.forEach((t) => e.step(t)), a.forEach((t) => e.step(t));
448
448
  }
449
- function k(e, t, r, i) {
449
+ function te(e, t, r, i) {
450
450
  let a = [], o = 0;
451
451
  e.doc.nodesBetween(t, r, (e, s) => {
452
452
  if (!e.isInline) return;
@@ -474,7 +474,7 @@ function k(e, t, r, i) {
474
474
  }
475
475
  }), a.forEach((t) => e.step(new S(t.from, t.to, t.style)));
476
476
  }
477
- function A(t, n, r, a = r.contentMatch, o = !0) {
477
+ function O(t, n, r, a = r.contentMatch, o = !0) {
478
478
  let s = t.doc.nodeAt(n), c = [], l = n + 1;
479
479
  for (let n = 0; n < s.childCount; n++) {
480
480
  let u = s.child(n), d = l + u.nodeSize, f = a.matchType(u.type);
@@ -495,14 +495,53 @@ function A(t, n, r, a = r.contentMatch, o = !0) {
495
495
  }
496
496
  for (let e = c.length - 1; e >= 0; e--) t.step(c[e]);
497
497
  }
498
- function ee(t, n, r) {
498
+ function ne(e, t, n) {
499
+ return (t == 0 || e.canReplace(t, e.childCount)) && (n == e.childCount || e.canReplace(0, n));
500
+ }
501
+ function re(e) {
502
+ let t = e.parent.content.cutByIndex(e.startIndex, e.endIndex);
503
+ for (let n = e.depth, r = 0, i = 0;; --n) {
504
+ let a = e.$from.node(n), o = e.$from.index(n) + r, s = e.$to.indexAfter(n) - i;
505
+ if (n < e.depth && a.canReplace(o, s, t)) return n;
506
+ if (n == 0 || a.type.spec.isolating || !ne(a, o, s)) break;
507
+ o && (r = 1), s < a.childCount && (i = 1);
508
+ }
509
+ return null;
510
+ }
511
+ function ie(t, n, r) {
499
512
  let { $from: a, $to: o, depth: s } = n, c = a.before(s + 1), l = o.after(s + 1), u = c, d = l, f = e.empty, p = 0;
500
513
  for (let t = s, n = !1; t > r; t--) n || a.index(t) > 0 ? (n = !0, f = e.from(a.node(t).copy(f)), p++) : u--;
501
514
  let m = e.empty, h = 0;
502
515
  for (let t = s, n = !1; t > r; t--) n || o.after(t + 1) < o.end(t) ? (n = !0, m = e.from(o.node(t).copy(m)), h++) : d++;
503
516
  t.step(new E(u, d, c, l, new i(f.append(m), p, h), f.size - p, !0));
504
517
  }
505
- function j(t, n, r) {
518
+ function ae(e, t, n = null, r = e) {
519
+ let i = oe(e, t), a = i && se(r, t);
520
+ return a ? i.map(k).concat({
521
+ type: t,
522
+ attrs: n
523
+ }).concat(a.map(k)) : null;
524
+ }
525
+ function k(e) {
526
+ return {
527
+ type: e,
528
+ attrs: null
529
+ };
530
+ }
531
+ function oe(e, t) {
532
+ let { parent: n, startIndex: r, endIndex: i } = e, a = n.contentMatchAt(r).findWrapping(t);
533
+ if (!a) return null;
534
+ let o = a.length ? a[0] : t;
535
+ return n.canReplaceWith(r, i, o) ? a : null;
536
+ }
537
+ function se(e, t) {
538
+ let { parent: n, startIndex: r, endIndex: i } = e, a = n.child(r), o = t.contentMatch.findWrapping(a.type);
539
+ if (!o) return null;
540
+ let s = (o.length ? o[o.length - 1] : t).contentMatch;
541
+ for (let e = r; s && e < i; e++) s = s.matchType(n.child(e).type);
542
+ return !s || !s.validEnd ? null : o;
543
+ }
544
+ function A(t, n, r) {
506
545
  let a = e.empty;
507
546
  for (let t = r.length - 1; t >= 0; t--) {
508
547
  if (a.size) {
@@ -514,24 +553,24 @@ function j(t, n, r) {
514
553
  let o = n.start, s = n.end;
515
554
  t.step(new E(o, s, o, s, new i(a, 0, 0), r.length, !0));
516
555
  }
517
- function M(t, n, r, a, o) {
556
+ function j(t, n, r, a, o) {
518
557
  if (!a.isTextblock) throw RangeError("Type given to setBlockType should be a textblock");
519
558
  let s = t.steps.length;
520
559
  t.doc.nodesBetween(n, r, (n, r) => {
521
560
  let c = typeof o == "function" ? o(n) : o;
522
- if (n.isTextblock && !n.hasMarkup(a, c) && F(t.doc, t.mapping.slice(s).map(r), a)) {
561
+ if (n.isTextblock && !n.hasMarkup(a, c) && P(t.doc, t.mapping.slice(s).map(r), a)) {
523
562
  let o = null;
524
563
  if (a.schema.linebreakReplacement) {
525
564
  let e = a.whitespace == "pre", t = !!a.contentMatch.matchType(a.schema.linebreakReplacement);
526
565
  e && !t ? o = !1 : !e && t && (o = !0);
527
566
  }
528
- o === !1 && P(t, n, r, s), A(t, t.mapping.slice(s).map(r, 1), a, void 0, o === null);
567
+ o === !1 && N(t, n, r, s), O(t, t.mapping.slice(s).map(r, 1), a, void 0, o === null);
529
568
  let l = t.mapping.slice(s), u = l.map(r, 1), d = l.map(r + n.nodeSize, 1);
530
- return t.step(new E(u, d, u + 1, d - 1, new i(e.from(a.create(c, null, n.marks)), 0, 0), 1, !0)), o === !0 && N(t, n, r, s), !1;
569
+ return t.step(new E(u, d, u + 1, d - 1, new i(e.from(a.create(c, null, n.marks)), 0, 0), 1, !0)), o === !0 && M(t, n, r, s), !1;
531
570
  }
532
571
  });
533
572
  }
534
- function N(e, t, n, r) {
573
+ function M(e, t, n, r) {
535
574
  t.forEach((i, a) => {
536
575
  if (i.isText) {
537
576
  let o, s = /\r?\n|\r/g;
@@ -542,7 +581,7 @@ function N(e, t, n, r) {
542
581
  }
543
582
  });
544
583
  }
545
- function P(e, t, n, r) {
584
+ function N(e, t, n, r) {
546
585
  t.forEach((i, a) => {
547
586
  if (i.type == i.type.schema.linebreakReplacement) {
548
587
  let i = e.mapping.slice(r).map(n + 1 + a);
@@ -550,11 +589,11 @@ function P(e, t, n, r) {
550
589
  }
551
590
  });
552
591
  }
553
- function F(e, t, n) {
592
+ function P(e, t, n) {
554
593
  let r = e.resolve(t), i = r.index();
555
594
  return r.parent.canReplaceWith(i, i + 1, n);
556
595
  }
557
- function I(t, n, r, a, o) {
596
+ function F(t, n, r, a, o) {
558
597
  let s = t.doc.nodeAt(n);
559
598
  if (!s) throw RangeError("No node at given position");
560
599
  r ||= s.type;
@@ -563,7 +602,21 @@ function I(t, n, r, a, o) {
563
602
  if (!r.validContent(s.content)) throw RangeError("Invalid content for node type " + r.name);
564
603
  t.step(new E(n, n + s.nodeSize, n + 1, n + s.nodeSize - 1, new i(e.from(c), 0, 0), 1, !0));
565
604
  }
566
- function L(t, n, r = 1, a) {
605
+ function ce(e, t, n = 1, r) {
606
+ let i = e.resolve(t), a = i.depth - n, o = r && r[r.length - 1] || i.parent;
607
+ if (a < 0 || i.parent.type.spec.isolating || !i.parent.canReplace(i.index(), i.parent.childCount) || !o.type.validContent(i.parent.content.cutByIndex(i.index(), i.parent.childCount))) return !1;
608
+ for (let e = i.depth - 1, t = n - 2; e > a; e--, t--) {
609
+ let n = i.node(e), a = i.index(e);
610
+ if (n.type.spec.isolating) return !1;
611
+ let o = n.content.cutByIndex(a, n.childCount), s = r && r[t + 1];
612
+ s && (o = o.replaceChild(0, s.type.create(s.attrs)));
613
+ let c = r && r[t] || n;
614
+ if (!n.canReplace(a + 1, n.childCount) || !c.type.validContent(o)) return !1;
615
+ }
616
+ let s = i.indexAfter(a), c = r && r[0];
617
+ return i.node(a).canReplaceWith(s, s, c ? c.type : i.node(a + 1).type);
618
+ }
619
+ function le(t, n, r = 1, a) {
567
620
  let o = t.doc.resolve(n), s = e.empty, c = e.empty;
568
621
  for (let t = o.depth, n = o.depth - r, i = r - 1; t > n; t--, i--) {
569
622
  s = e.from(o.node(t).copy(s));
@@ -572,7 +625,32 @@ function L(t, n, r = 1, a) {
572
625
  }
573
626
  t.step(new T(n, n, new i(s.append(c), r, r), !0));
574
627
  }
575
- function te(e, t, n) {
628
+ function ue(e, t) {
629
+ let n = e.resolve(t), r = n.index();
630
+ return I(n.nodeBefore, n.nodeAfter) && n.parent.canReplace(r, r + 1);
631
+ }
632
+ function de(e, t) {
633
+ t.content.size || e.type.compatibleContent(t.type);
634
+ let n = e.contentMatchAt(e.childCount), { linebreakReplacement: r } = e.type.schema;
635
+ for (let i = 0; i < t.childCount; i++) {
636
+ let a = t.child(i), o = a.type == r ? e.type.schema.nodes.text : a.type;
637
+ if (n = n.matchType(o), !n || !e.type.allowsMarks(a.marks)) return !1;
638
+ }
639
+ return n.validEnd;
640
+ }
641
+ function I(e, t) {
642
+ return !!(e && t && !e.isLeaf && de(e, t));
643
+ }
644
+ function L(e, t, n = -1) {
645
+ let r = e.resolve(t);
646
+ for (let e = r.depth;; e--) {
647
+ let i, a, o = r.index(e);
648
+ if (e == r.depth ? (i = r.nodeBefore, a = r.nodeAfter) : n > 0 ? (i = r.node(e + 1), o++, a = r.node(e).maybeChild(o)) : (i = r.node(e).maybeChild(o - 1), a = r.node(e + 1)), i && !i.isTextblock && I(i, a) && r.node(e).canReplace(o, o + 1)) return t;
649
+ if (e == 0) break;
650
+ t = n < 0 ? r.before(e) : r.after(e);
651
+ }
652
+ }
653
+ function R(e, t, n) {
576
654
  let r = null, { linebreakReplacement: a } = e.doc.type.schema, o = e.doc.resolve(t - n), s = o.node().type;
577
655
  if (a && s.inlineContent) {
578
656
  let e = s.whitespace == "pre", t = !!s.contentMatch.matchType(a);
@@ -581,17 +659,17 @@ function te(e, t, n) {
581
659
  let c = e.steps.length;
582
660
  if (r === !1) {
583
661
  let r = e.doc.resolve(t + n);
584
- P(e, r.node(), r.before(), c);
662
+ N(e, r.node(), r.before(), c);
585
663
  }
586
- s.inlineContent && A(e, t + n - 1, s, o.node().contentMatchAt(o.index()), r == null);
664
+ s.inlineContent && O(e, t + n - 1, s, o.node().contentMatchAt(o.index()), r == null);
587
665
  let l = e.mapping.slice(c), u = l.map(t - n);
588
666
  if (e.step(new T(u, l.map(t + n, -1), i.empty, !0)), r === !0) {
589
667
  let t = e.doc.resolve(u);
590
- N(e, t.node(), t.before(), e.steps.length);
668
+ M(e, t.node(), t.before(), e.steps.length);
591
669
  }
592
670
  return e;
593
671
  }
594
- function ne(e, t, n) {
672
+ function z(e, t, n) {
595
673
  let r = e.resolve(t);
596
674
  if (r.parent.canReplaceWith(r.index(), r.index(), n)) return t;
597
675
  if (r.parentOffset == 0) for (let e = r.depth - 1; e >= 0; e--) {
@@ -606,15 +684,31 @@ function ne(e, t, n) {
606
684
  }
607
685
  return null;
608
686
  }
609
- function re(e, t, n = t, r = i.empty) {
687
+ function B(e, t, n) {
688
+ let r = e.resolve(t);
689
+ if (!n.content.size) return t;
690
+ let i = n.content;
691
+ for (let e = 0; e < n.openStart; e++) i = i.firstChild.content;
692
+ for (let e = 1; e <= (n.openStart == 0 && n.size ? 2 : 1); e++) for (let t = r.depth; t >= 0; t--) {
693
+ let n = t == r.depth ? 0 : r.pos <= (r.start(t + 1) + r.end(t + 1)) / 2 ? -1 : 1, a = r.index(t) + +(n > 0), o = r.node(t), s = !1;
694
+ if (e == 1) s = o.canReplace(a, a, i);
695
+ else {
696
+ let e = o.contentMatchAt(a).findWrapping(i.firstChild.type);
697
+ s = e && o.canReplaceWith(a, a, e[0]);
698
+ }
699
+ if (s) return n == 0 ? r.pos : n < 0 ? r.before(t + 1) : r.after(t + 1);
700
+ }
701
+ return null;
702
+ }
703
+ function V(e, t, n = t, r = i.empty) {
610
704
  if (t == n && !r.size) return null;
611
705
  let a = e.resolve(t), o = e.resolve(n);
612
- return R(a, o, r) ? new T(t, n, r) : new z(a, o, r).fit();
706
+ return H(a, o, r) ? new T(t, n, r) : new fe(a, o, r).fit();
613
707
  }
614
- function R(e, t, n) {
708
+ function H(e, t, n) {
615
709
  return !n.openStart && !n.openEnd && e.start() == t.start() && e.parent.canReplace(e.index(), t.index(), n.content);
616
710
  }
617
- var z = class {
711
+ var fe = class {
618
712
  constructor(t, n, r) {
619
713
  this.$from = t, this.$to = n, this.unplaced = r, this.frontier = [], this.placed = e.empty;
620
714
  for (let e = 0; e <= t.depth; e++) {
@@ -653,7 +747,7 @@ var z = class {
653
747
  }
654
748
  for (let n = 1; n <= 2; n++) for (let r = n == 1 ? t : this.unplaced.openStart; r >= 0; r--) {
655
749
  let t, i = null;
656
- r ? (i = H(this.unplaced.content, r - 1).firstChild, t = i.content) : t = this.unplaced.content;
750
+ r ? (i = G(this.unplaced.content, r - 1).firstChild, t = i.content) : t = this.unplaced.content;
657
751
  let a = t.firstChild;
658
752
  for (let t = this.depth; t >= 0; t--) {
659
753
  let { type: o, match: s } = this.frontier[t], c, l = null;
@@ -674,15 +768,15 @@ var z = class {
674
768
  }
675
769
  }
676
770
  openMore() {
677
- let { content: e, openStart: t, openEnd: n } = this.unplaced, r = H(e, t);
771
+ let { content: e, openStart: t, openEnd: n } = this.unplaced, r = G(e, t);
678
772
  return !r.childCount || r.firstChild.isLeaf ? !1 : (this.unplaced = new i(e, t + 1, Math.max(n, r.size + t >= e.size - n ? t + 1 : 0)), !0);
679
773
  }
680
774
  dropNode() {
681
- let { content: e, openStart: t, openEnd: n } = this.unplaced, r = H(e, t);
775
+ let { content: e, openStart: t, openEnd: n } = this.unplaced, r = G(e, t);
682
776
  if (r.childCount <= 1 && t > 0) {
683
777
  let a = e.size - t <= t + r.size;
684
- this.unplaced = new i(B(e, t - 1, 1), t - 1, a ? t - 1 : n);
685
- } else this.unplaced = new i(B(e, t, 1), t, n);
778
+ this.unplaced = new i(U(e, t - 1, 1), t - 1, a ? t - 1 : n);
779
+ } else this.unplaced = new i(U(e, t, 1), t, n);
686
780
  }
687
781
  placeNodes({ sliceDepth: t, frontierDepth: n, parent: r, inject: a, wrap: o }) {
688
782
  for (; this.depth > n;) this.closeFrontierNode();
@@ -696,10 +790,10 @@ var z = class {
696
790
  for (; u < c.childCount;) {
697
791
  let e = c.child(u), t = f.matchType(e.type);
698
792
  if (!t) break;
699
- u++, (u > 1 || l == 0 || e.content.size) && (f = t, d.push(U(e.mark(p.allowedMarks(e.marks)), u == 1 ? l : 0, u == c.childCount ? m : -1)));
793
+ u++, (u > 1 || l == 0 || e.content.size) && (f = t, d.push(K(e.mark(p.allowedMarks(e.marks)), u == 1 ? l : 0, u == c.childCount ? m : -1)));
700
794
  }
701
795
  let h = u == c.childCount;
702
- h || (m = -1), this.placed = V(this.placed, n, e.from(d)), this.frontier[n].match = f, h && m < 0 && r && r.type == this.frontier[this.depth].type && this.frontier.length > 1 && this.closeFrontierNode();
796
+ h || (m = -1), this.placed = W(this.placed, n, e.from(d)), this.frontier[n].match = f, h && m < 0 && r && r.type == this.frontier[this.depth].type && this.frontier.length > 1 && this.closeFrontierNode();
703
797
  for (let e = 0, t = c; e < m; e++) {
704
798
  let e = t.lastChild;
705
799
  this.frontier.push({
@@ -707,22 +801,22 @@ var z = class {
707
801
  match: e.contentMatchAt(e.childCount)
708
802
  }), t = e.content;
709
803
  }
710
- this.unplaced = h ? t == 0 ? i.empty : new i(B(s.content, t - 1, 1), t - 1, m < 0 ? s.openEnd : t - 1) : new i(B(s.content, t, u), s.openStart, s.openEnd);
804
+ this.unplaced = h ? t == 0 ? i.empty : new i(U(s.content, t - 1, 1), t - 1, m < 0 ? s.openEnd : t - 1) : new i(U(s.content, t, u), s.openStart, s.openEnd);
711
805
  }
712
806
  mustMoveInline() {
713
807
  if (!this.$to.parent.isTextblock) return -1;
714
808
  let e = this.frontier[this.depth], t;
715
- if (!e.type.isTextblock || !W(this.$to, this.$to.depth, e.type, e.match, !1) || this.$to.depth == this.depth && (t = this.findCloseLevel(this.$to)) && t.depth == this.depth) return -1;
809
+ if (!e.type.isTextblock || !q(this.$to, this.$to.depth, e.type, e.match, !1) || this.$to.depth == this.depth && (t = this.findCloseLevel(this.$to)) && t.depth == this.depth) return -1;
716
810
  let { depth: n } = this.$to, r = this.$to.after(n);
717
811
  for (; n > 1 && r == this.$to.end(--n);) ++r;
718
812
  return r;
719
813
  }
720
814
  findCloseLevel(e) {
721
815
  scan: for (let t = Math.min(this.depth, e.depth); t >= 0; t--) {
722
- let { match: n, type: r } = this.frontier[t], i = t < e.depth && e.end(t + 1) == e.pos + (e.depth - (t + 1)), a = W(e, t, r, n, i);
816
+ let { match: n, type: r } = this.frontier[t], i = t < e.depth && e.end(t + 1) == e.pos + (e.depth - (t + 1)), a = q(e, t, r, n, i);
723
817
  if (a) {
724
818
  for (let n = t - 1; n >= 0; n--) {
725
- let { match: t, type: r } = this.frontier[n], i = W(e, n, r, t, !0);
819
+ let { match: t, type: r } = this.frontier[n], i = q(e, n, r, t, !0);
726
820
  if (!i || i.childCount) continue scan;
727
821
  }
728
822
  return {
@@ -737,7 +831,7 @@ var z = class {
737
831
  let t = this.findCloseLevel(e);
738
832
  if (!t) return null;
739
833
  for (; this.depth > t.depth;) this.closeFrontierNode();
740
- t.fit.childCount && (this.placed = V(this.placed, t.depth, t.fit)), e = t.move;
834
+ t.fit.childCount && (this.placed = W(this.placed, t.depth, t.fit)), e = t.move;
741
835
  for (let n = t.depth + 1; n <= e.depth; n++) {
742
836
  let t = e.node(n), r = t.type.contentMatch.fillBefore(t.content, !0, e.index(n));
743
837
  this.openFrontierNode(t.type, t.attrs, r);
@@ -746,48 +840,48 @@ var z = class {
746
840
  }
747
841
  openFrontierNode(t, n = null, r) {
748
842
  let i = this.frontier[this.depth];
749
- i.match = i.match.matchType(t), this.placed = V(this.placed, this.depth, e.from(t.create(n, r))), this.frontier.push({
843
+ i.match = i.match.matchType(t), this.placed = W(this.placed, this.depth, e.from(t.create(n, r))), this.frontier.push({
750
844
  type: t,
751
845
  match: t.contentMatch
752
846
  });
753
847
  }
754
848
  closeFrontierNode() {
755
849
  let t = this.frontier.pop().match.fillBefore(e.empty, !0);
756
- t.childCount && (this.placed = V(this.placed, this.frontier.length, t));
850
+ t.childCount && (this.placed = W(this.placed, this.frontier.length, t));
757
851
  }
758
852
  };
759
- function B(e, t, n) {
760
- return t == 0 ? e.cutByIndex(n, e.childCount) : e.replaceChild(0, e.firstChild.copy(B(e.firstChild.content, t - 1, n)));
853
+ function U(e, t, n) {
854
+ return t == 0 ? e.cutByIndex(n, e.childCount) : e.replaceChild(0, e.firstChild.copy(U(e.firstChild.content, t - 1, n)));
761
855
  }
762
- function V(e, t, n) {
763
- return t == 0 ? e.append(n) : e.replaceChild(e.childCount - 1, e.lastChild.copy(V(e.lastChild.content, t - 1, n)));
856
+ function W(e, t, n) {
857
+ return t == 0 ? e.append(n) : e.replaceChild(e.childCount - 1, e.lastChild.copy(W(e.lastChild.content, t - 1, n)));
764
858
  }
765
- function H(e, t) {
859
+ function G(e, t) {
766
860
  for (let n = 0; n < t; n++) e = e.firstChild.content;
767
861
  return e;
768
862
  }
769
- function U(t, n, r) {
863
+ function K(t, n, r) {
770
864
  if (n <= 0) return t;
771
865
  let i = t.content;
772
- return n > 1 && (i = i.replaceChild(0, U(i.firstChild, n - 1, i.childCount == 1 ? r - 1 : 0))), n > 0 && (i = t.type.contentMatch.fillBefore(i).append(i), r <= 0 && (i = i.append(t.type.contentMatch.matchFragment(i).fillBefore(e.empty, !0)))), t.copy(i);
866
+ return n > 1 && (i = i.replaceChild(0, K(i.firstChild, n - 1, i.childCount == 1 ? r - 1 : 0))), n > 0 && (i = t.type.contentMatch.fillBefore(i).append(i), r <= 0 && (i = i.append(t.type.contentMatch.matchFragment(i).fillBefore(e.empty, !0)))), t.copy(i);
773
867
  }
774
- function W(e, t, n, r, i) {
868
+ function q(e, t, n, r, i) {
775
869
  let a = e.node(t), o = i ? e.indexAfter(t) : e.index(t);
776
870
  if (o == a.childCount && !n.compatibleContent(a.type)) return null;
777
871
  let s = r.fillBefore(a.content, !0, o);
778
- return s && !G(n, a.content, o) ? s : null;
872
+ return s && !pe(n, a.content, o) ? s : null;
779
873
  }
780
- function G(e, t, n) {
874
+ function pe(e, t, n) {
781
875
  for (let r = n; r < t.childCount; r++) if (!e.allowsMarks(t.child(r).marks)) return !0;
782
876
  return !1;
783
877
  }
784
- function K(e) {
878
+ function me(e) {
785
879
  return e.spec.defining || e.spec.definingForContent;
786
880
  }
787
- function q(e, t, n, r) {
881
+ function he(e, t, n, r) {
788
882
  if (!r.size) return e.deleteRange(t, n);
789
883
  let a = e.doc.resolve(t), o = e.doc.resolve(n);
790
- if (R(a, o, r)) return e.step(new T(t, n, r));
884
+ if (H(a, o, r)) return e.step(new T(t, n, r));
791
885
  let s = X(a, o);
792
886
  s[s.length - 1] == 0 && s.pop();
793
887
  let c = -(a.depth + 1);
@@ -804,7 +898,7 @@ function q(e, t, n, r) {
804
898
  e = n.content;
805
899
  }
806
900
  for (let e = d - 1; e >= 0; e--) {
807
- let t = u[e], n = K(t.type);
901
+ let t = u[e], n = me(t.type);
808
902
  if (n && !t.sameMarkup(a.node(Math.abs(c) - 1))) d = e;
809
903
  else if (n || !t.type.isTextblock) break;
810
904
  }
@@ -836,12 +930,12 @@ function J(t, n, r, i, a) {
836
930
  }
837
931
  function Y(t, n, r, a) {
838
932
  if (!a.isInline && n == r && t.doc.resolve(n).parent.content.size) {
839
- let e = ne(t.doc, n, a.type);
933
+ let e = z(t.doc, n, a.type);
840
934
  e != null && (n = r = e);
841
935
  }
842
936
  t.replaceRange(n, r, new i(e.from(a), 0, 0));
843
937
  }
844
- function ie(e, t, n) {
938
+ function ge(e, t, n) {
845
939
  let r = e.doc.resolve(t), i = e.doc.resolve(n);
846
940
  if (r.parent.isTextblock && i.parent.isTextblock && r.start() != i.start() && r.parentOffset == 0 && i.parentOffset == 0) {
847
941
  let a = r.sharedDepth(n), o = !1;
@@ -946,7 +1040,7 @@ $ = function e(t) {
946
1040
  let n = Error.call(this, t);
947
1041
  return n.__proto__ = e.prototype, n;
948
1042
  }, $.prototype = Object.create(Error.prototype), $.prototype.constructor = $, $.prototype.name = "TransformError";
949
- var ae = class {
1043
+ var _e = class {
950
1044
  constructor(e) {
951
1045
  this.doc = e, this.steps = [], this.docs = [], this.mapping = new g();
952
1046
  }
@@ -982,7 +1076,7 @@ var ae = class {
982
1076
  this.docs.push(this.doc), this.steps.push(e), this.mapping.appendMap(e.getMap()), this.doc = t;
983
1077
  }
984
1078
  replace(e, t = e, n = i.empty) {
985
- let r = re(this.doc, e, t, n);
1079
+ let r = V(this.doc, e, t, n);
986
1080
  return r && this.step(r), this;
987
1081
  }
988
1082
  replaceWith(t, n, r) {
@@ -995,28 +1089,28 @@ var ae = class {
995
1089
  return this.replaceWith(e, e, t);
996
1090
  }
997
1091
  replaceRange(e, t, n) {
998
- return q(this, e, t, n), this;
1092
+ return he(this, e, t, n), this;
999
1093
  }
1000
1094
  replaceRangeWith(e, t, n) {
1001
1095
  return Y(this, e, t, n), this;
1002
1096
  }
1003
1097
  deleteRange(e, t) {
1004
- return ie(this, e, t), this;
1098
+ return ge(this, e, t), this;
1005
1099
  }
1006
1100
  lift(e, t) {
1007
- return ee(this, e, t), this;
1101
+ return ie(this, e, t), this;
1008
1102
  }
1009
1103
  join(e, t = 1) {
1010
- return te(this, e, t), this;
1104
+ return R(this, e, t), this;
1011
1105
  }
1012
1106
  wrap(e, t) {
1013
- return j(this, e, t), this;
1107
+ return A(this, e, t), this;
1014
1108
  }
1015
1109
  setBlockType(e, t = e, n, r = null) {
1016
- return M(this, e, t, n, r), this;
1110
+ return j(this, e, t, n, r), this;
1017
1111
  }
1018
1112
  setNodeMarkup(e, t, n = null, r) {
1019
- return I(this, e, t, n, r), this;
1113
+ return F(this, e, t, n, r), this;
1020
1114
  }
1021
1115
  setNodeAttribute(e, t, n) {
1022
1116
  return this.step(new Z(e, t, n)), this;
@@ -1039,17 +1133,17 @@ var ae = class {
1039
1133
  return this;
1040
1134
  }
1041
1135
  split(e, t = 1, n) {
1042
- return L(this, e, t, n), this;
1136
+ return le(this, e, t, n), this;
1043
1137
  }
1044
1138
  addMark(e, t, n) {
1045
- return O(this, e, t, n), this;
1139
+ return ee(this, e, t, n), this;
1046
1140
  }
1047
1141
  removeMark(e, t, n) {
1048
- return k(this, e, t, n), this;
1142
+ return te(this, e, t, n), this;
1049
1143
  }
1050
1144
  clearIncompatible(e, t, n) {
1051
- return A(this, e, t, n), this;
1145
+ return O(this, e, t, n), this;
1052
1146
  }
1053
1147
  };
1054
1148
  //#endregion
1055
- export { g as Mapping, E as ReplaceAroundStep, T as ReplaceStep, ae as Transform };
1149
+ export { x as AddMarkStep, C as AddNodeMarkStep, Z as AttrStep, Q as DocAttrStep, m as MapResult, g as Mapping, S as RemoveMarkStep, w as RemoveNodeMarkStep, E as ReplaceAroundStep, T as ReplaceStep, v as Step, h as StepMap, y as StepResult, _e as Transform, $ as TransformError, ue as canJoin, ce as canSplit, B as dropPoint, ae as findWrapping, z as insertPoint, L as joinPoint, re as liftTarget, V as replaceStep };
@@ -1,2 +1,2 @@
1
- require(`../../../_virtual/_rolldown/runtime.cjs`);const e=require(`./constants.cjs`),t=require(`./utils/page-decorations.cjs`),n=require(`./composables/use-template-designer.cjs`),r=require(`./utils/editor-snapshot-cache.cjs`),i=require(`./composables/use-page-authoring.cjs`),a=require(`./extensions/template-variable.cjs`),o=require(`./utils/content-image.cjs`),s=require(`./extensions/editor-extensions.cjs`),c=require(`./utils/context-variable.cjs`),ee=require(`./utils/block-style.cjs`),te=require(`./ContractTemplatePageDecorations.cjs`);let l=require(`vue`),ne=require(`ant-design-vue`),u=require(`@tiptap/vue-3`),re=require(`@tiptap/core`),d=require(`@tiptap/pm/tables`),f=require(`@tiptap/pm/state`);var ie={class:`gd-contract-template-designer__page-title`},p=`application/x-gd-contract-variable-move`,ae=8,m=(0,l.defineComponent)({name:`ProContractTemplateDesignerPage`,__name:`DesignerPage`,props:{page:{},pageIndex:{},pageSize:{},pageDecorations:{default:void 0},totalPages:{default:1},variables:{},selectedVariableKey:{default:``},active:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},zoom:{default:1},processImageFile:{type:Function,default:void 0},searchQuery:{default:``},searchMatchCase:{type:Boolean,default:!1},activeSearchMatch:{default:void 0}},emits:[`page-update`,`variable-drop`,`variable-select`,`variable-move-blocked`,`editor-focus`,`editor-ready`,`composition-end`,`page-layout-change`,`editor-state-change`,`editor-context-menu`,`word-paste`],setup(m,{expose:oe,emit:se}){let h=m,g=se,_=(0,l.computed)(()=>h.readonly||h.disabled),v=(0,l.ref)(),y=r.createEditorSnapshotCache(),b=!1,x,S,C=!1,w=!1,ce=h.page.contentHtml;function T(){return w&&!C}function E(){return b||!!O.value?.view.composing}function le(e){let t=e.filter(Boolean).join(`、`);return typeof window>`u`?!1:new Promise(e=>{ne.Modal.confirm({title:`粘贴内容包含不兼容字体`,content:`检测到 ${t||`外部`} 字体。为保证 Mac 与 Windows 排版一致,将统一转换为合同标准字体(GD Contract Latin + 系统宋体)。是否继续粘贴?`,okText:`继续粘贴`,cancelText:`取消粘贴`,onOk:()=>e(!0),onCancel:()=>e(!1)})})}let D=s.createEditorExtensions(`请输入合同正文,或从 WPS / Word 粘贴合同内容`,{processImageFile:h.processImageFile,confirmExternalFontPaste:le,getZoom:()=>Math.max(.1,h.zoom||1)}),O=(0,u.useEditor)({content:h.page.contentHtml,editable:!_.value,extensions:D,editorProps:{attributes:{class:`gd-contract-template-designer__editor-prose`},handleClick:(e,t,n)=>{let r=(n.target instanceof HTMLElement?n.target.closest(`[data-template-variable]`):void 0)?.dataset.key;if(!r)return!1;let i=h.variables.find(e=>e.key===r);return i&&g(`variable-select`,i.key),!1},handleDOMEvents:{compositionstart:()=>(b=!0,x!==void 0&&clearTimeout(x),!1),compositionend:()=>(b=!1,x=setTimeout(()=>{if(x=void 0,!(C||E())){if(S!==void 0){let e=S;S=void 0,H(e)}g(`page-update`,W()),g(`composition-end`,h.page.id)}},0),!1),contextmenu:(e,t)=>{if(_.value)return!1;let n=Te(e,t.target);if(n)return t.preventDefault(),F({pageId:h.page.id,clientX:t.clientX,clientY:t.clientY},n),!0;let r=O.value?.state.selection,i=r instanceof d.CellSelection,a=t.target instanceof HTMLElement?!!t.target.closest(`td, th`):!1,o=c.resolveEditorContextMenuKind({isCellSelection:i,selectionEmpty:!r||r.empty,inTable:a});return t.preventDefault(),o===`table`&&(i||Se(t.clientX,t.clientY,t.target))?(R({pageId:h.page.id,clientX:t.clientX,clientY:t.clientY}),!0):(P({pageId:h.page.id,clientX:t.clientX,clientY:t.clientY}),!0)},dragstart:(e,t)=>_.value?(t.preventDefault(),!0):(t.target instanceof HTMLElement?t.target:null)?.closest(`[data-template-variable]`)?(t.dataTransfer?.setData(p,h.page.id),t.dataTransfer&&(t.dataTransfer.effectAllowed=`move`),v.value?.classList.add(`is-variable-dragging`),!1):!1,dragend:()=>(v.value?.classList.remove(`is-variable-dragging`),!1),drop:(e,t)=>{if(_.value)return t.preventDefault(),t.stopPropagation(),!0;let n=t.dataTransfer?.getData(p);return!n||n===h.page.id?!1:(t.preventDefault(),g(`variable-move-blocked`,h.page.id),!0)}},handleKeyDown:(e,t)=>{if(_.value||!ye(t))return!1;let n=O.value;if(!n)return!1;t.preventDefault();let r=n.state.selection,i=L();if(i){let e=n.view.coordsAtPos(r.from);return F({pageId:h.page.id,clientX:e.left,clientY:e.bottom},i),!0}let a=r instanceof d.CellSelection;if(c.resolveEditorContextMenuKind({isCellSelection:a,selectionEmpty:r.empty,inTable:n.isActive(`table`)})===`table`){if(!a){let e=xe();typeof e==`number`&&n.view.dispatch(n.state.tr.setSelection(d.CellSelection.create(n.state.doc,e)))}let e=n.view.coordsAtPos(n.state.selection.from);return R({pageId:h.page.id,clientX:e.left,clientY:e.bottom}),!0}let o=n.view.coordsAtPos(n.state.selection.from);return P({pageId:h.page.id,clientX:o.left,clientY:o.bottom}),!0}},onUpdate:({editor:e})=>{g(`page-update`,{...h.page,contentHtml:y.read(e).getHTML(),contentJson:y.read(e).getJSON()}),V()},onFocus:()=>{g(`editor-focus`,h.page.id),V()},onBlur:V,onSelectionUpdate:V,onCreate:({editor:e})=>{h.page.contentHtml!==ce&&h.page.contentHtml!==y.read(e).getHTML()&&(b||e.view.composing?S=h.page.contentHtml:e.commands.setContent(h.page.contentHtml||`<p></p>`,{emitUpdate:!1})),w=!0,e.on(`contract-word-paste`,k),V(),g(`editor-ready`,h.page.id)}}),{findText:ue,revealSearchMatch:de,replaceSearchMatches:fe,focusHeading:pe}=i.usePageAuthoring({editor:()=>O.value,readonly:()=>_.value,search:()=>({query:h.searchQuery,matchCase:h.searchMatchCase,activeMatch:h.activeSearchMatch})});function k(e){g(`word-paste`,e)}function me(e){if(typeof e==`number`&&Number.isFinite(e))return e;let t=String(e||``).match(/(\d+(\.\d+)?)/);return t?Number(t[1]):void 0}function he(){if(!O.value)return``;let{from:e,to:t}=O.value.state.selection;return O.value.state.doc.textBetween(e,t,`
2
- `)}function ge(){let e=O.value,t=e?.state.selection;if(!(!e||!t||t.empty))try{let n=e.view.coordsAtPos(t.from),r=e.view.coordsAtPos(t.to,-1);if(Math.abs(r.top-n.top)>ae)return;let i=Math.abs(r.left-n.left)/U.value;return Number.isFinite(i)&&i>0?i:void 0}catch{return}}function _e(){let e=O.value,t=e?.state.selection;if(!(!e||!t||t.empty)&&!(t instanceof d.CellSelection||t instanceof f.NodeSelection))try{let n=e.view.coordsAtPos(t.from),r=e.view.coordsAtPos(t.to,-1);return{top:Math.min(n.top,r.top),bottom:Math.max(n.bottom,r.bottom),left:Math.min(n.left,r.left),right:Math.max(n.left,r.right)}}catch{return}}function ve(){let e=O.value;if(!e)return``;let t=e.state.selection.$from,n=t.pos;for(let e=t.depth;e>0;--e){let r=t.node(e).type.name;if(r===`paragraph`||r===`heading`){n=t.start(e);break}}return e.state.doc.textBetween(n,e.state.selection.from,``)}function ye(e){return e.key===`ContextMenu`||e.shiftKey&&e.key===`F10`}function A(e){for(let t=e.depth;t>0;--t){let n=e.node(t).type.spec.tableRole;if(n===`cell`||n===`header_cell`)return e.before(t)}}function be(e,t){let n=O.value,r=n?.view.posAtCoords({left:e,top:t})?.pos;if(!(!n||typeof r!=`number`))return A(n.state.doc.resolve(r))}function xe(){let e=O.value;if(e)return A(e.state.selection.$from)}function Se(e,t,n){let r=O.value,i=n instanceof HTMLElement?n:null;if(!r||!i?.closest(`td,th`))return!1;if(r.state.selection instanceof d.CellSelection&&i.closest(`td.selectedCell,th.selectedCell`))return!0;let a=be(e,t);return typeof a==`number`?(r.view.dispatch(r.state.tr.setSelection(d.CellSelection.create(r.state.doc,a))),!0):!1}function j(){let e=O.value,t=e?.isActive(`table`)?e.can():void 0,n=e=>!!(t&&e(t));return{addRowBefore:n(e=>e.addRowBefore()),addRowAfter:n(e=>e.addRowAfter()),deleteRow:n(e=>e.deleteRow()),addColumnBefore:n(e=>e.addColumnBefore()),addColumnAfter:n(e=>e.addColumnAfter()),deleteColumn:n(e=>e.deleteColumn()),mergeCells:n(e=>e.mergeCells()),splitCell:n(e=>e.splitCell()),alignLeft:n(e=>e.setCellAttribute(`textAlign`,`left`)),alignCenter:n(e=>e.setCellAttribute(`textAlign`,`center`)),alignRight:n(e=>e.setCellAttribute(`textAlign`,`right`)),toggleHeaderRow:n(e=>e.toggleHeaderRow()),toggleHeaderColumn:n(e=>e.toggleHeaderColumn()),deleteTable:n(e=>e.deleteTable())}}function Ce(){let e=O.value,t=e?.state.selection;if(!e||!(t instanceof d.CellSelection))return`left`;let n=new Set;return t.forEachCell(e=>{let t=e.attrs.textAlign;n.add(t===`center`||t===`right`?t:`left`)}),n.size===1?n.values().next().value??`left`:`mixed`}function M(e=O.value?.state.doc){let t=0;return e?.descendants(e=>{e.type.name===`templateVariable`&&(t+=1)}),t}function N(e){let t=O.value;if(!t)return 0;let n=M(t.state.doc),r=n,i=e=>{r=M(e.doc)};return e===`delete-table-row`?(0,d.deleteRow)(t.state,i):e===`delete-table-column`?(0,d.deleteColumn)(t.state,i):(0,d.deleteTable)(t.state,i),Math.max(0,n-r)}function P(e){let t=O.value?.state.selection,n=!!(t&&!t.empty);g(`editor-context-menu`,{type:`text`,...e,hasSelection:n,selectionWidth:n?ge():void 0,leadingText:ve()})}function we(e,t){P({pageId:h.page.id,clientX:e,clientY:t})}function F(e,t){g(`editor-context-menu`,{type:`image`,...e,image:t})}function I(e,t){if(!(e.type.name!==`image`||typeof e.attrs.src!=`string`||!e.attrs.src))return{position:t,src:e.attrs.src,alt:typeof e.attrs.alt==`string`?e.attrs.alt:void 0,title:typeof e.attrs.title==`string`?e.attrs.title:void 0,width:o.normalizeContractImageDimension(e.attrs.width),height:o.normalizeContractImageDimension(e.attrs.height)}}function L(){let e=O.value?.state.selection;if(e instanceof f.NodeSelection)return I(e.node,e.from)}function Te(e,t){let n=t instanceof HTMLElement?t.closest(`[data-template-variable], img[src]`):null;if(n)try{let t=e.posAtDOM(n,0),r=e.state.doc.nodeAt(t);return!r||r.type.name!==`templateVariable`&&r.type.name!==`image`?void 0:(r.type.name===`templateVariable`&&typeof r.attrs.key==`string`&&g(`variable-select`,r.attrs.key),(!(e.state.selection instanceof f.NodeSelection)||e.state.selection.from!==t)&&e.dispatch(e.state.tr.setSelection(f.NodeSelection.create(e.state.doc,t))),I(r,t))}catch{return}}function R(e){g(`editor-context-menu`,{type:`table`,...e,capabilities:j(),activeAlignment:Ce(),affectedVariableCounts:{deleteRow:N(`delete-table-row`),deleteColumn:N(`delete-table-column`),deleteTable:N(`delete-table`)}})}function Ee(e){return typeof e==`number`&&Number.isInteger(e)&&e>=1&&e<=6}function z(){let e=O.value;if(!e)return[];let{doc:t,selection:n}=e.state,r=[],i=e=>{e.type.name===`paragraph`?r.push(`paragraph`):e.type.name===`heading`&&Ee(e.attrs.level)&&r.push(e.attrs.level)};if(n.empty)for(let e=n.$from.depth;e>0;e--){let t=n.$from.node(e);if(t.type.name===`paragraph`||t.type.name===`heading`){i(t);break}}else t.nodesBetween(n.from,n.to,e=>(i(e),!0));return Array.from(new Set(r))}function De(){let e=z();return e.length===1&&e[0]!==`paragraph`?e[0]:void 0}function Oe(){return z().length>1}function ke(){return[`center`,`right`].find(e=>O.value?.isActive(`heading`,{textAlign:e})||O.value?.isActive(`paragraph`,{textAlign:e}))??`left`}function B(){let e=O.value,t=t=>!!e?.isActive(t),n=e?.getAttributes(`textStyle`)??{};return{isFocused:!!e?.isFocused,canUndo:!!e?.can().undo(),canRedo:!!e?.can().redo(),isBold:t(`bold`),isItalic:t(`italic`),isUnderline:t(`underline`),isBulletList:t(`bulletList`),isOrderedList:t(`orderedList`),isTableActive:t(`table`),currentHeadingLevel:De(),hasMixedBlockFormats:Oe(),textAlign:ke(),fontFamily:typeof n.fontFamily==`string`?n.fontFamily:void 0,fontSize:me(n.fontSize),textColor:typeof n.color==`string`?n.color:void 0,selectionText:he(),selectedContentImage:L()}}function V(){g(`editor-state-change`,h.page.id,B())}(0,l.watch)(_,e=>{O.value?.setEditable(!e),V()}),(0,l.watch)(()=>h.page.contentHtml,e=>{H(e)});function H(e){if(!O.value||e===$()){S=void 0;return}if(E()){S=e;return}O.value.commands.setContent(e||`<p></p>`,{emitUpdate:!1}),V()}let Ae=(0,l.computed)(()=>{let e=t.normalizePageDecorations(h.pageDecorations),n=h.pageIndex+1,r=t.hasEnabledPageHeader(e,n)?t.getPageDecorationSafePadding(e.header):t.CONTRACT_PAGE_BASE_PADDING.top,i=t.hasEnabledPageFooter(e,n)?t.getPageDecorationSafePadding(e.footer):t.CONTRACT_PAGE_BASE_PADDING.bottom;return{width:`${h.pageSize.width}px`,height:`${h.pageSize.height}px`,paddingTop:`${r}px`,paddingBottom:`${i}px`,"--gd-contract-page-content-height":`${Math.max(120,h.pageSize.height-r-i)}px`}}),U=(0,l.computed)(()=>Math.max(.1,h.zoom||1)),je=(0,l.computed)(()=>({width:`${Math.ceil((h.pageSize.width+10)*U.value)}px`,height:`${Math.ceil((h.pageSize.height+40)*U.value)}px`})),Me=(0,l.computed)(()=>({"--gd-contract-page-zoom":String(U.value)})),Ne=(0,l.computed)(()=>n.resolvePageSize(h.pageSize));function Pe(e){if(h.readonly||h.disabled){e.preventDefault(),e.stopPropagation();return}let t=e.dataTransfer?.getData(`application/x-gd-contract-variable`);if(t){e.preventDefault(),e.stopPropagation(),g(`variable-drop`,h.page.id,t,e.clientX,e.clientY);return}let n=e.dataTransfer?.getData(p);n&&n!==h.page.id&&(e.preventDefault(),e.stopPropagation(),g(`variable-move-blocked`,h.page.id))}function Fe(e,t){let n=O.value;if(!n)return;let r=t?n.view.posAtCoords(t)?.pos:void 0;return a.insertTemplateVariableNode(n,e,r),Z(),W()}function Ie(e,t){let n=O.value;if(n)return s.runContractTemplateEditorCommand(n,{type:`insert-content-image`,image:e,position:t}),W()}function Le(e){let t=O.value,n=t?.state.selection;if(!t||!(n instanceof f.NodeSelection)||n.node.type.name!==`image`)return;let r={...n.node.attrs},i=!1;if([`width`,`height`].forEach(t=>{if(!Object.prototype.hasOwnProperty.call(e,t))return;let n=e[t]===void 0?null:o.normalizeContractImageDimension(e[t])??null;r[t]!==n&&(r[t]=n,i=!0)}),!i)return;let a=t.state.tr.setNodeMarkup(n.from,void 0,r);return a.setSelection(f.NodeSelection.create(a.doc,n.from)),t.view.dispatch(a),W()}function Re(){let e=O.value?.state.selection;return e?{from:e.from,to:e.to}:void 0}function W(){return{...h.page,pageSize:Ne.value,contentHtml:$(),contentJson:Q()??h.page.contentJson}}function ze(e){if(!T())return{contentHtml:e.contentHtml,contentJson:e.contentJson};let t=$();return!E()&&e.contentHtml!==h.page.contentHtml&&e.contentHtml!==t?{contentHtml:e.contentHtml,contentJson:e.contentJson}:{contentHtml:t,contentJson:Q()}}function G(e){return{type:`doc`,content:e.length?e:[{type:`paragraph`}]}}function Be(e){return e?.length?e.length===1&&e[0].type===`paragraph`&&!e[0].content?.length:!0}function Ve(e){return(0,re.generateHTML)(G(e),D)}function He(){if(h.pageDecorations){let e=t.normalizePageDecorations(h.pageDecorations),n=h.pageIndex+1,r=t.hasEnabledPageHeader(e,n)?t.getPageDecorationSafePadding(e.header):t.CONTRACT_PAGE_BASE_PADDING.top,i=t.hasEnabledPageFooter(e,n)?t.getPageDecorationSafePadding(e.footer):t.CONTRACT_PAGE_BASE_PADDING.bottom;return Math.max(120,h.pageSize.height-r-i)}let e=v.value;if(!e)return h.pageSize.height-108;let n=window.getComputedStyle(e),r=Number.parseFloat(n.paddingTop)||0,i=Number.parseFloat(n.paddingBottom)||0;return Math.max(120,h.pageSize.height-r-i)}function Ue(){let e=v.value?.querySelector(`.gd-contract-template-designer__editor-prose`);if(!e)return[];let t=e.getBoundingClientRect(),n=U.value;return Array.from(e.children).map(r=>{let i=r.getBoundingClientRect(),a=r instanceof HTMLTableElement?r:r.querySelector(`:scope > table`),o=a?Array.from(a.rows).map(e=>{let r=e.getBoundingClientRect();return{top:(r.top-t.top)/n,height:r.height/n}}):void 0;return{top:(i.top-t.top)/n,height:i.height/n,...o?.length?{tableRows:o,trailingTextBlockHeight:Number.parseFloat(window.getComputedStyle(e).lineHeight)||28}:{}}})}function K(){if(!O.value)return;let e=Ue(),t=He();if(e.some(e=>e.top+e.height>t+1))return n.splitPageContentByMeasurements(Q()?.content,e,t)}function We(){return!!K()}function Ge(){if(!O.value||!T()||E())return;let e=K();if(e)return O.value.commands.setContent(G(e.currentContent),{emitUpdate:!1}),{page:W(),overflowContent:e.overflowContent,overflowHtml:Ve(e.overflowContent)}}function Ke(e){if(!O.value||!T()||E()||!e.length)return;let t=Q()?.content,n=[...e,...Be(t)?[]:t??[]];return O.value.commands.setContent(G(n),{emitUpdate:!1}),W()}function q(e,t){let n=[];return e.descendants((e,r)=>{e.type.name===`templateVariable`&&e.attrs.key===t&&n.push({node:e,pos:r})}),n}function J(e,t=e.key){if(!O.value)return;let n=a.buildTemplateVariableAttrs(e),r=!1;return O.value.commands.command(({tr:e,state:i,dispatch:a})=>(q(i.doc,t).forEach(({node:t,pos:i})=>{e.setNodeMarkup(i,void 0,{...t.attrs,...n}),r=!0}),r&&a?.(e),r)),Z(),r?W():void 0}function qe(e){if(!O.value)return;let t=0;return O.value.commands.command(({tr:n,state:r,dispatch:i})=>{let a=q(r.doc,e).map(({node:e,pos:t})=>({from:t,to:t+e.nodeSize})).sort((e,t)=>t.from-e.from);return a.forEach(e=>n.delete(e.from,e.to)),t=a.length,t&&i?.(n),t>0}),t?W():void 0}function Y(){v.value?.querySelectorAll(`.gd-contract-template-variable.is-active`).forEach(e=>e.classList.remove(`is-active`))}function X(e){if(e)return Array.from(v.value?.querySelectorAll(`[data-template-variable]`)??[]).find(t=>t.dataset.key===e)}function Je(e){Y();let t=X(e);return t?(t.classList.add(`is-active`),t.scrollIntoView({behavior:`smooth`,block:`center`,inline:`center`}),O.value?.commands.focus(),!0):!1}function Z(){Y(),X(h.selectedVariableKey)?.classList.add(`is-active`)}function Ye(t){let r=e.CONTRACT_TEXT_STYLE_PRESETS.find(e=>e.key===t),i=O.value;if(!r||!i)return;let a=i.chain().focus().clearNodes();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||e.DEFAULT_CONTRACT_FONT_FAMILY).setColor(n.DEFAULT_FIELD_STYLE.color||`#1f2937`),r.bold?a.setBold():a.unsetBold(),r.italic?a.setItalic():a.unsetItalic(),r.underline?a.setUnderline():a.unsetUnderline(),a.run()}(0,l.watch)([()=>h.selectedVariableKey,()=>h.variables],()=>{(0,l.nextTick)(Z)},{deep:!0,flush:`post`});function Xe(e){_.value||(e.type===`apply-block-style`?O.value&&ee.applyContractTemplateBlockStyle(O.value,e.format):e.type===`apply-text-style-preset`?Ye(e.preset):s.runContractTemplateEditorCommand(O.value,e),V())}function Ze(){O.value?.commands.focus()}function Q(){return O.value?y.read(O.value).getJSON():h.page.contentJson}function $(){return O.value?y.read(O.value).getHTML():h.page.contentHtml}function Qe(e){let t=h.variables.find(t=>t.id===e||t.key===e),n=t?X(t.key):void 0;Z(),n?.scrollIntoView({behavior:`smooth`,block:`center`})}function $e(){v.value?.scrollIntoView({behavior:`smooth`,block:`start`,inline:`center`})}return(0,l.onBeforeUnmount)(()=>{C=!0,x!==void 0&&clearTimeout(x),O.value?.off(`contract-word-paste`,k),O.value?.destroy()}),oe({findText:ue,revealSearchMatch:de,replaceSearchMatches:fe,focusHeading:pe,focus:Ze,getHTML:$,getJSON:Q,getContentSnapshot:ze,getEditorState:B,getTableCommandCapabilities:j,getAffectedVariableCount:N,insertVariable:Fe,insertContentImage:Ie,updateSelectedContentImage:Le,getSelectionRange:Re,getSelectionViewportRect:_e,requestTextContextMenu:we,isReady:T,isComposing:E,hasOverflowContent:We,updateVariable:J,removeVariable:qe,splitOverflowContent:Ge,prependContent:Ke,runCommand:Xe,scrollIntoField:Qe,scrollIntoVariable:Je,scrollIntoPage:$e}),(e,t)=>((0,l.openBlock)(),(0,l.createElementBlock)(`section`,{class:`gd-contract-template-designer__page-shell`,style:(0,l.normalizeStyle)(je.value)},[(0,l.createElementVNode)(`div`,{class:(0,l.normalizeClass)([`gd-contract-template-designer__page-zoom`,{"is-active":m.active}]),style:(0,l.normalizeStyle)(Me.value)},[(0,l.createElementVNode)(`header`,ie,[(0,l.createElementVNode)(`span`,null,(0,l.toDisplayString)(m.page.title||`第 ${m.pageIndex+1} 页`),1),(0,l.createElementVNode)(`span`,null,`第 `+(0,l.toDisplayString)(m.pageIndex+1)+` 页 · `+(0,l.toDisplayString)(m.pageSize.label||`A4`)+` · `+(0,l.toDisplayString)(m.pageSize.width)+` × `+(0,l.toDisplayString)(m.pageSize.height),1)]),(0,l.createElementVNode)(`div`,{ref_key:`pageElement`,ref:v,class:`gd-contract-template-designer__page`,style:(0,l.normalizeStyle)(Ae.value),onLoadCapture:t[0]||=e=>g(`page-layout-change`,m.page.id),onDragover:t[1]||=(0,l.withModifiers)(()=>{},[`prevent`]),onDrop:Pe,onClick:t[2]||=e=>g(`editor-focus`,m.page.id)},[(0,l.createVNode)(te.default,{decorations:m.pageDecorations,"page-number":m.pageIndex+1,"total-pages":m.totalPages,variables:m.variables},null,8,[`decorations`,`page-number`,`total-pages`,`variables`]),(0,l.unref)(O)?((0,l.openBlock)(),(0,l.createBlock)((0,l.unref)(u.EditorContent),{key:0,class:`gd-contract-template-page__content`,editor:(0,l.unref)(O)},null,8,[`editor`])):(0,l.createCommentVNode)(``,!0)],36)],6)],4))}});exports.default=m;
1
+ require(`../../../_virtual/_rolldown/runtime.cjs`);const e=require(`./constants.cjs`),t=require(`./utils/page-decorations.cjs`),n=require(`./composables/use-template-designer.cjs`),r=require(`./utils/editor-snapshot-cache.cjs`),i=require(`../../../node_modules/prosemirror-transform/dist/index.cjs`),a=require(`./composables/use-page-authoring.cjs`);require(`../../../node_modules/@tiptap/pm/dist/transform/index.cjs`);const o=require(`./extensions/template-variable.cjs`),s=require(`./utils/content-image.cjs`),c=require(`./extensions/editor-extensions.cjs`),l=require(`./utils/context-variable.cjs`),u=require(`./utils/block-style.cjs`),ee=require(`./ContractTemplatePageDecorations.cjs`),d=require(`./utils/caret-viewport.cjs`);let f=require(`vue`),te=require(`ant-design-vue`),p=require(`@tiptap/vue-3`),ne=require(`@tiptap/core`),m=require(`@tiptap/pm/tables`),h=require(`@tiptap/pm/state`);var re={class:`gd-contract-template-designer__page-title`},g=`application/x-gd-contract-variable-move`,ie=8,_=(0,f.defineComponent)({name:`ProContractTemplateDesignerPage`,__name:`DesignerPage`,props:{page:{},pageIndex:{},pageSize:{},pageDecorations:{default:void 0},totalPages:{default:1},variables:{},selectedVariableKey:{default:``},active:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},zoom:{default:1},processImageFile:{type:Function,default:void 0},searchQuery:{default:``},searchMatchCase:{type:Boolean,default:!1},activeSearchMatch:{default:void 0},getScrollContainer:{type:Function,default:void 0}},emits:[`page-update`,`variable-drop`,`variable-select`,`variable-move-blocked`,`editor-focus`,`editor-ready`,`composition-end`,`page-layout-change`,`editor-state-change`,`editor-context-menu`,`word-paste`],setup(_,{expose:ae,emit:oe}){let v=_,y=oe,b=(0,f.computed)(()=>v.readonly||v.disabled),x=(0,f.ref)(),S=r.createEditorSnapshotCache(),C=!1,w,T,E=!1,D=!1,se=!1,O=!1,k=0,A,ce=v.page.contentHtml,le=(0,f.toRaw)(v.page);function j(){return D&&!E}function M(){return C||!!P.value?.view.composing}function ue(e){let t=e.filter(Boolean).join(`、`);return typeof window>`u`?!1:new Promise(e=>{te.Modal.confirm({title:`粘贴内容包含不兼容字体`,content:`检测到 ${t||`外部`} 字体。为保证 Mac 与 Windows 排版一致,将统一转换为合同标准字体(GD Contract Latin + 系统宋体)。是否继续粘贴?`,okText:`继续粘贴`,cancelText:`取消粘贴`,onOk:()=>e(!0),onCancel:()=>e(!1)})})}let N=c.createEditorExtensions(`请输入合同正文,或从 WPS / Word 粘贴合同内容`,{processImageFile:v.processImageFile,confirmExternalFontPaste:ue,getZoom:()=>Math.max(.1,v.zoom||1)}),P=(0,p.useEditor)({content:v.page.contentHtml,editable:!b.value,extensions:N,editorProps:{attributes:{class:`gd-contract-template-designer__editor-prose`},handleClick:(e,t,n)=>{let r=(n.target instanceof HTMLElement?n.target.closest(`[data-template-variable]`):void 0)?.dataset.key;if(!r)return!1;let i=v.variables.find(e=>e.key===r);return i&&y(`variable-select`,i.key),!1},handleDOMEvents:{compositionstart:()=>(C=!0,w!==void 0&&clearTimeout(w),!1),compositionend:()=>(C=!1,w=setTimeout(()=>{if(w=void 0,!(E||M())){if(T!==void 0){let e=T;T=void 0,W(e)}y(`page-update`,K()),y(`composition-end`,v.page.id)}},0),!1),contextmenu:(e,t)=>{if(b.value)return!1;let n=Ae(e,t.target);if(n)return t.preventDefault(),Oe({pageId:v.page.id,clientX:t.clientX,clientY:t.clientY},n),!0;let r=P.value?.state.selection,i=r instanceof m.CellSelection,a=t.target instanceof HTMLElement?!!t.target.closest(`td, th`):!1,o=l.resolveEditorContextMenuKind({isCellSelection:i,selectionEmpty:!r||r.empty,inTable:a});return t.preventDefault(),o===`table`&&(i||Ce(t.clientX,t.clientY,t.target))?(B({pageId:v.page.id,clientX:t.clientX,clientY:t.clientY}),!0):(R({pageId:v.page.id,clientX:t.clientX,clientY:t.clientY}),!0)},dragstart:(e,t)=>b.value?(t.preventDefault(),!0):(t.target instanceof HTMLElement?t.target:null)?.closest(`[data-template-variable]`)?(t.dataTransfer?.setData(g,v.page.id),t.dataTransfer&&(t.dataTransfer.effectAllowed=`move`),x.value?.classList.add(`is-variable-dragging`),!1):!1,dragend:()=>(x.value?.classList.remove(`is-variable-dragging`),!1),drop:(e,t)=>{if(b.value)return t.preventDefault(),t.stopPropagation(),!0;let n=t.dataTransfer?.getData(g);return!n||n===v.page.id?!1:(t.preventDefault(),y(`variable-move-blocked`,v.page.id),!0)}},handleKeyDown:(e,t)=>{if(b.value||!be(t))return!1;let n=P.value;if(!n)return!1;t.preventDefault();let r=n.state.selection,i=z();if(i){let e=n.view.coordsAtPos(r.from);return Oe({pageId:v.page.id,clientX:e.left,clientY:e.bottom},i),!0}let a=r instanceof m.CellSelection;if(l.resolveEditorContextMenuKind({isCellSelection:a,selectionEmpty:r.empty,inTable:n.isActive(`table`)})===`table`){if(!a){let e=Se();typeof e==`number`&&n.view.dispatch(n.state.tr.setSelection(m.CellSelection.create(n.state.doc,e)))}let e=n.view.coordsAtPos(n.state.selection.from);return B({pageId:v.page.id,clientX:e.left,clientY:e.bottom}),!0}let o=n.view.coordsAtPos(n.state.selection.from);return R({pageId:v.page.id,clientX:o.left,clientY:o.bottom}),!0},handleScrollToSelection:e=>d.scrollCaretIntoCanvas(e,()=>v.getScrollContainer?.(),()=>x.value)},onTransaction:({transaction:e,appendedTransactions:t})=>{[e,...t].some(e=>e.docChanged&&!e.getMeta(`preventUpdate`))&&(se=!0),!D&&[e,...t].some(e=>e.selectionSet||e.storedMarksSet)&&(O=!0),[e,...t].some(e=>e.docChanged||e.selectionSet||e.storedMarksSet||e.getMeta(`blur`))&&(k+=1)},onUpdate:({editor:e})=>{y(`page-update`,{...v.page,contentHtml:S.read(e).getHTML(),contentJson:S.read(e).getJSON()}),U()},onFocus:()=>{y(`editor-focus`,v.page.id),U()},onBlur:U,onSelectionUpdate:U,onMount:()=>{A=k},onCreate:({editor:e})=>{if(v.page.contentHtml!==ce&&v.page.contentHtml!==S.read(e).getHTML())if(C||e.view.composing)T=v.page.contentHtml;else{let t=A===k?k+1:void 0;e.commands.setContent(v.page.contentHtml||`<p></p>`,{emitUpdate:!1}),A=t}D=!0,e.on(`contract-word-paste`,F),U(),y(`editor-ready`,v.page.id)}}),{findText:de,revealSearchMatch:fe,replaceSearchMatches:pe,focusHeading:me}=a.usePageAuthoring({editor:()=>P.value,readonly:()=>b.value,search:()=>({query:v.searchQuery,matchCase:v.searchMatchCase,activeMatch:v.activeSearchMatch})});function F(e){y(`word-paste`,e)}function he(e){if(typeof e==`number`&&Number.isFinite(e))return e;let t=String(e||``).match(/(\d+(\.\d+)?)/);return t?Number(t[1]):void 0}function ge(){if(!P.value)return``;let{from:e,to:t}=P.value.state.selection;return P.value.state.doc.textBetween(e,t,`
2
+ `)}function _e(){let e=P.value,t=e?.state.selection;if(!(!e||!t||t.empty))try{let n=e.view.coordsAtPos(t.from),r=e.view.coordsAtPos(t.to,-1);if(Math.abs(r.top-n.top)>ie)return;let i=Math.abs(r.left-n.left)/G.value;return Number.isFinite(i)&&i>0?i:void 0}catch{return}}function ve(){let e=P.value,t=e?.state.selection;if(!(!e||!t||t.empty)&&!(t instanceof m.CellSelection||t instanceof h.NodeSelection))try{let n=e.view.coordsAtPos(t.from),r=e.view.coordsAtPos(t.to,-1);return{top:Math.min(n.top,r.top),bottom:Math.max(n.bottom,r.bottom),left:Math.min(n.left,r.left),right:Math.max(n.left,r.right)}}catch{return}}function ye(){let e=P.value;if(!e)return``;let t=e.state.selection.$from,n=t.pos;for(let e=t.depth;e>0;--e){let r=t.node(e).type.name;if(r===`paragraph`||r===`heading`){n=t.start(e);break}}return e.state.doc.textBetween(n,e.state.selection.from,``)}function be(e){return e.key===`ContextMenu`||e.shiftKey&&e.key===`F10`}function I(e){for(let t=e.depth;t>0;--t){let n=e.node(t).type.spec.tableRole;if(n===`cell`||n===`header_cell`)return e.before(t)}}function xe(e,t){let n=P.value,r=n?.view.posAtCoords({left:e,top:t})?.pos;if(!(!n||typeof r!=`number`))return I(n.state.doc.resolve(r))}function Se(){let e=P.value;if(e)return I(e.state.selection.$from)}function Ce(e,t,n){let r=P.value,i=n instanceof HTMLElement?n:null;if(!r||!i?.closest(`td,th`))return!1;if(r.state.selection instanceof m.CellSelection&&i.closest(`td.selectedCell,th.selectedCell`))return!0;let a=xe(e,t);return typeof a==`number`?(r.view.dispatch(r.state.tr.setSelection(m.CellSelection.create(r.state.doc,a))),!0):!1}function we(){let e=P.value,t=e?.isActive(`table`)?e.can():void 0,n=e=>!!(t&&e(t));return{addRowBefore:n(e=>e.addRowBefore()),addRowAfter:n(e=>e.addRowAfter()),deleteRow:n(e=>e.deleteRow()),addColumnBefore:n(e=>e.addColumnBefore()),addColumnAfter:n(e=>e.addColumnAfter()),deleteColumn:n(e=>e.deleteColumn()),mergeCells:n(e=>e.mergeCells()),splitCell:n(e=>e.splitCell()),alignLeft:n(e=>e.setCellAttribute(`textAlign`,`left`)),alignCenter:n(e=>e.setCellAttribute(`textAlign`,`center`)),alignRight:n(e=>e.setCellAttribute(`textAlign`,`right`)),toggleHeaderRow:n(e=>e.toggleHeaderRow()),toggleHeaderColumn:n(e=>e.toggleHeaderColumn()),deleteTable:n(e=>e.deleteTable())}}function Te(){let e=P.value,t=e?.state.selection;if(!e||!(t instanceof m.CellSelection))return`left`;let n=new Set;return t.forEachCell(e=>{let t=e.attrs.textAlign;n.add(t===`center`||t===`right`?t:`left`)}),n.size===1?n.values().next().value??`left`:`mixed`}function Ee(e=P.value?.state.doc){let t=0;return e?.descendants(e=>{e.type.name===`templateVariable`&&(t+=1)}),t}function L(e){let t=P.value;if(!t)return 0;let n=Ee(t.state.doc),r=n,i=e=>{r=Ee(e.doc)};return e===`delete-table-row`?(0,m.deleteRow)(t.state,i):e===`delete-table-column`?(0,m.deleteColumn)(t.state,i):(0,m.deleteTable)(t.state,i),Math.max(0,n-r)}function R(e){let t=P.value?.state.selection,n=!!(t&&!t.empty);y(`editor-context-menu`,{type:`text`,...e,hasSelection:n,selectionWidth:n?_e():void 0,leadingText:ye()})}function De(e,t){R({pageId:v.page.id,clientX:e,clientY:t})}function Oe(e,t){y(`editor-context-menu`,{type:`image`,...e,image:t})}function ke(e,t){if(!(e.type.name!==`image`||typeof e.attrs.src!=`string`||!e.attrs.src))return{position:t,src:e.attrs.src,alt:typeof e.attrs.alt==`string`?e.attrs.alt:void 0,title:typeof e.attrs.title==`string`?e.attrs.title:void 0,width:s.normalizeContractImageDimension(e.attrs.width),height:s.normalizeContractImageDimension(e.attrs.height)}}function z(){let e=P.value?.state.selection;if(e instanceof h.NodeSelection)return ke(e.node,e.from)}function Ae(e,t){let n=t instanceof HTMLElement?t.closest(`[data-template-variable], img[src]`):null;if(n)try{let t=e.posAtDOM(n,0),r=e.state.doc.nodeAt(t);return!r||r.type.name!==`templateVariable`&&r.type.name!==`image`?void 0:(r.type.name===`templateVariable`&&typeof r.attrs.key==`string`&&y(`variable-select`,r.attrs.key),(!(e.state.selection instanceof h.NodeSelection)||e.state.selection.from!==t)&&e.dispatch(e.state.tr.setSelection(h.NodeSelection.create(e.state.doc,t))),ke(r,t))}catch{return}}function B(e){y(`editor-context-menu`,{type:`table`,...e,capabilities:we(),activeAlignment:Te(),affectedVariableCounts:{deleteRow:L(`delete-table-row`),deleteColumn:L(`delete-table-column`),deleteTable:L(`delete-table`)}})}function je(e){return typeof e==`number`&&Number.isInteger(e)&&e>=1&&e<=6}function V(){let e=P.value;if(!e)return[];let{doc:t,selection:n}=e.state,r=[],i=e=>{e.type.name===`paragraph`?r.push(`paragraph`):e.type.name===`heading`&&je(e.attrs.level)&&r.push(e.attrs.level)};if(n.empty)for(let e=n.$from.depth;e>0;e--){let t=n.$from.node(e);if(t.type.name===`paragraph`||t.type.name===`heading`){i(t);break}}else t.nodesBetween(n.from,n.to,e=>(i(e),!0));return Array.from(new Set(r))}function Me(){let e=V();return e.length===1&&e[0]!==`paragraph`?e[0]:void 0}function Ne(){return V().length>1}function Pe(){return[`center`,`right`].find(e=>P.value?.isActive(`heading`,{textAlign:e})||P.value?.isActive(`paragraph`,{textAlign:e}))??`left`}function H(){let e=P.value,t=t=>!!e?.isActive(t),n=e?.getAttributes(`textStyle`)??{};return{isFocused:!!e?.isFocused,canUndo:!!e?.can().undo(),canRedo:!!e?.can().redo(),isBold:t(`bold`),isItalic:t(`italic`),isUnderline:t(`underline`),isBulletList:t(`bulletList`),isOrderedList:t(`orderedList`),isTableActive:t(`table`),currentHeadingLevel:Me(),hasMixedBlockFormats:Ne(),textAlign:Pe(),fontFamily:typeof n.fontFamily==`string`?n.fontFamily:void 0,fontSize:he(n.fontSize),textColor:typeof n.color==`string`?n.color:void 0,selectionText:ge(),selectedContentImage:z()}}function U(){y(`editor-state-change`,v.page.id,H())}(0,f.watch)(b,e=>{P.value?.setEditable(!e),U()}),(0,f.watch)(()=>v.page.contentHtml,e=>{W(e)});function W(e){if(!P.value||e===$()){T=void 0;return}if(M()){T=e;return}P.value.commands.setContent(e||`<p></p>`,{emitUpdate:!1}),U()}let Fe=(0,f.computed)(()=>{let e=t.normalizePageDecorations(v.pageDecorations),n=v.pageIndex+1,r=t.hasEnabledPageHeader(e,n)?t.getPageDecorationSafePadding(e.header):t.CONTRACT_PAGE_BASE_PADDING.top,i=t.hasEnabledPageFooter(e,n)?t.getPageDecorationSafePadding(e.footer):t.CONTRACT_PAGE_BASE_PADDING.bottom;return{width:`${v.pageSize.width}px`,height:`${v.pageSize.height}px`,paddingTop:`${r}px`,paddingBottom:`${i}px`,"--gd-contract-page-content-height":`${Math.max(120,v.pageSize.height-r-i)}px`}}),G=(0,f.computed)(()=>Math.max(.1,v.zoom||1)),Ie=(0,f.computed)(()=>({width:`${Math.ceil((v.pageSize.width+10)*G.value)}px`,height:`${Math.ceil((v.pageSize.height+40)*G.value)}px`})),Le=(0,f.computed)(()=>({"--gd-contract-page-zoom":String(G.value)})),Re=(0,f.computed)(()=>n.resolvePageSize(v.pageSize));function ze(e){if(v.readonly||v.disabled){e.preventDefault(),e.stopPropagation();return}let t=e.dataTransfer?.getData(`application/x-gd-contract-variable`);if(t){e.preventDefault(),e.stopPropagation(),y(`variable-drop`,v.page.id,t,e.clientX,e.clientY);return}let n=e.dataTransfer?.getData(g);n&&n!==v.page.id&&(e.preventDefault(),e.stopPropagation(),y(`variable-move-blocked`,v.page.id))}function Be(e,t){let n=P.value;if(!n)return;let r=t?n.view.posAtCoords(t)?.pos:void 0;return o.insertTemplateVariableNode(n,e,r),Z(),K()}function Ve(e,t){let n=P.value;if(n)return c.runContractTemplateEditorCommand(n,{type:`insert-content-image`,image:e,position:t}),K()}function He(e){let t=P.value,n=t?.state.selection;if(!t||!(n instanceof h.NodeSelection)||n.node.type.name!==`image`)return;let r={...n.node.attrs},i=!1;if([`width`,`height`].forEach(t=>{if(!Object.prototype.hasOwnProperty.call(e,t))return;let n=e[t]===void 0?null:s.normalizeContractImageDimension(e[t])??null;r[t]!==n&&(r[t]=n,i=!0)}),!i)return;let a=t.state.tr.setNodeMarkup(n.from,void 0,r);return a.setSelection(h.NodeSelection.create(a.doc,n.from)),t.view.dispatch(a),K()}function Ue(){let e=P.value?.state.selection;return e?{from:e.from,to:e.to}:void 0}function K(){return{...v.page,pageSize:Re.value,contentHtml:$(),contentJson:Q()??v.page.contentJson}}function We(e){if(!j())return{contentHtml:e.contentHtml,contentJson:e.contentJson};let t=$();return!M()&&e.contentHtml!==v.page.contentHtml&&e.contentHtml!==t?{contentHtml:e.contentHtml,contentJson:e.contentJson}:{contentHtml:t,contentJson:Q()}}function q(e){return{type:`doc`,content:e.length?e:[{type:`paragraph`}]}}function J(e){return e?.length?e.length===1&&e[0].type===`paragraph`&&!e[0].content?.length:!0}function Ge(e){return(0,ne.generateHTML)(q(e),N)}function Ke(){if(v.pageDecorations){let e=t.normalizePageDecorations(v.pageDecorations),n=v.pageIndex+1,r=t.hasEnabledPageHeader(e,n)?t.getPageDecorationSafePadding(e.header):t.CONTRACT_PAGE_BASE_PADDING.top,i=t.hasEnabledPageFooter(e,n)?t.getPageDecorationSafePadding(e.footer):t.CONTRACT_PAGE_BASE_PADDING.bottom;return Math.max(120,v.pageSize.height-r-i)}let e=x.value;if(!e)return v.pageSize.height-108;let n=window.getComputedStyle(e),r=Number.parseFloat(n.paddingTop)||0,i=Number.parseFloat(n.paddingBottom)||0;return Math.max(120,v.pageSize.height-r-i)}function qe(){let e=x.value?.querySelector(`.gd-contract-template-designer__editor-prose`);if(!e)return[];let t=e.getBoundingClientRect(),n=G.value;return Array.from(e.children).map(r=>{let i=r.getBoundingClientRect(),a=r instanceof HTMLTableElement?r:r.querySelector(`:scope > table`),o=a?Array.from(a.rows).map(e=>{let r=e.getBoundingClientRect();return{top:(r.top-t.top)/n,height:r.height/n}}):void 0;return{top:(i.top-t.top)/n,height:i.height/n,...o?.length?{tableRows:o,trailingTextBlockHeight:Number.parseFloat(window.getComputedStyle(e).lineHeight)||28}:{}}})}function Y(){if(!P.value)return;let e=qe(),t=Ke();if(e.some(e=>e.top+e.height>t+1))return n.splitPageContentByMeasurements(Q()?.content,e,t)}function Je(){return!!Y()}function Ye(){let e=P.value;if(!e||!j()||M()||!e.view.hasFocus())return!1;let t=Y();if(!t)return!1;let n=0;for(let r=0;r<t.splitIndex;r++)n+=e.state.doc.child(r).nodeSize;if(t.currentContent.length>t.splitIndex){let r=e.state.doc.child(t.splitIndex),i=t.currentContent[t.splitIndex].content.length;for(let e=0;e<i;e++)n+=r.child(e).nodeSize;n+=1}return e.state.selection.ranges.every(e=>e.$from.pos>=n)}function Xe(e){return(!e||(0,f.toRaw)(e)===le)&&!se&&!M()&&!P.value?.view.hasFocus()&&J(Q()?.content)}function Ze(){if(!P.value||!j()||M())return;let e=Y();if(!e)return;let t=P.value,{doc:n,selection:r,storedMarks:a}=t.state,o=t.state.tr,s=0;for(let t=0;t<e.splitIndex;t++)s+=n.child(t).nodeSize;let c=s,l=s;if(e.currentContent.length>e.splitIndex){let t=n.child(e.splitIndex),r=e.currentContent[e.splitIndex].content.length;for(let e=0;e<r;e++)c+=t.child(e).nodeSize;l=c+1,o.delete(l,s+t.nodeSize-1),o.delete(c+2,o.doc.content.size)}else o.delete(s,n.content.size);let u=t.view.hasFocus()&&r.ranges.every(e=>e.$from.pos>=l)?r.map(t.schema.nodeFromJSON(q(e.overflowContent)),new i.Mapping([new i.StepMap([0,c,0])])):void 0;o.setMeta(`preventUpdate`,!0).setMeta(`addToHistory`,!1).setStoredMarks(a);let ee=k+1;t.view.dispatch(o);let d=u&&{selection:u,storedMarks:a,isCurrent:()=>!E&&P.value===t&&!t.isDestroyed&&!b.value&&!M()&&t.view.hasFocus()&&k===ee};return{page:K(),overflowContent:e.overflowContent,overflowHtml:Ge(e.overflowContent),selection:d}}function Qe(e){if(!P.value||!j()||M()||!e.length)return;let t=P.value,n=t.schema.nodeFromJSON(q(e)).content,{doc:r,storedMarks:i}=t.state,a=t.state.tr;J(Q()?.content)?a.replaceWith(0,r.content.size,n):a.insert(0,n),a.setMeta(`preventUpdate`,!0).setMeta(`addToHistory`,!1).setStoredMarks(i);let o=k+1;return t.view.dispatch(a),A=O?void 0:o,O=!1,K()}function $e(e,t){let n=P.value,r=A;if(A=void 0,!n||!j()||b.value||M()||r!==k||!e.isCurrent()||$()!==t)return;let i=h.Selection.fromJSON(n.state.doc,e.selection.toJSON()),a=k+1;n.view.dispatch(n.state.tr.setSelection(i).setStoredMarks(e.storedMarks?.map(e=>n.schema.markFromJSON(e.toJSON()))??null).setMeta(`addToHistory`,!1)),!(!e.isCurrent()||k!==a)&&(n.view.focus(),n.view.hasFocus()&&k===a&&n.commands.scrollIntoView())}function et(e,t){let n=[];return e.descendants((e,r)=>{e.type.name===`templateVariable`&&e.attrs.key===t&&n.push({node:e,pos:r})}),n}function tt(e,t=e.key){if(!P.value)return;let n=o.buildTemplateVariableAttrs(e),r=!1;return P.value.commands.command(({tr:e,state:i,dispatch:a})=>(et(i.doc,t).forEach(({node:t,pos:i})=>{e.setNodeMarkup(i,void 0,{...t.attrs,...n}),r=!0}),r&&a?.(e),r)),Z(),r?K():void 0}function nt(e){if(!P.value)return;let t=0;return P.value.commands.command(({tr:n,state:r,dispatch:i})=>{let a=et(r.doc,e).map(({node:e,pos:t})=>({from:t,to:t+e.nodeSize})).sort((e,t)=>t.from-e.from);return a.forEach(e=>n.delete(e.from,e.to)),t=a.length,t&&i?.(n),t>0}),t?K():void 0}function rt(){x.value?.querySelectorAll(`.gd-contract-template-variable.is-active`).forEach(e=>e.classList.remove(`is-active`))}function X(e){if(e)return Array.from(x.value?.querySelectorAll(`[data-template-variable]`)??[]).find(t=>t.dataset.key===e)}function it(e){rt();let t=X(e);return t?(t.classList.add(`is-active`),t.scrollIntoView({behavior:`smooth`,block:`center`,inline:`center`}),P.value?.commands.focus(),!0):!1}function Z(){rt(),X(v.selectedVariableKey)?.classList.add(`is-active`)}function at(t){let r=e.CONTRACT_TEXT_STYLE_PRESETS.find(e=>e.key===t),i=P.value;if(!r||!i)return;let a=i.chain().focus().clearNodes();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||e.DEFAULT_CONTRACT_FONT_FAMILY).setColor(n.DEFAULT_FIELD_STYLE.color||`#1f2937`),r.bold?a.setBold():a.unsetBold(),r.italic?a.setItalic():a.unsetItalic(),r.underline?a.setUnderline():a.unsetUnderline(),a.run()}(0,f.watch)([()=>v.selectedVariableKey,()=>v.variables],()=>{(0,f.nextTick)(Z)},{deep:!0,flush:`post`});function ot(e){b.value||(e.type===`apply-block-style`?P.value&&u.applyContractTemplateBlockStyle(P.value,e.format):e.type===`apply-text-style-preset`?at(e.preset):c.runContractTemplateEditorCommand(P.value,e),U())}function st(){P.value?.commands.focus()}function Q(){return P.value?S.read(P.value).getJSON():v.page.contentJson}function $(){return P.value?S.read(P.value).getHTML():v.page.contentHtml}function ct(e){let t=v.variables.find(t=>t.id===e||t.key===e),n=t?X(t.key):void 0;Z(),n?.scrollIntoView({behavior:`smooth`,block:`center`})}function lt(){x.value?.scrollIntoView({behavior:`smooth`,block:`start`,inline:`center`})}return(0,f.onBeforeUnmount)(()=>{E=!0,w!==void 0&&clearTimeout(w),P.value?.off(`contract-word-paste`,F),P.value?.destroy()}),ae({findText:de,revealSearchMatch:fe,replaceSearchMatches:pe,focusHeading:me,focus:st,getHTML:$,getJSON:Q,getContentSnapshot:We,getEditorState:H,getTableCommandCapabilities:we,getAffectedVariableCount:L,insertVariable:Be,insertContentImage:Ve,updateSelectedContentImage:He,getSelectionRange:Ue,getSelectionViewportRect:ve,requestTextContextMenu:De,isReady:j,isComposing:M,hasOverflowContent:Je,hasOverflowSelection:Ye,isUntouchedPaginationBlank:Xe,updateVariable:tt,removeVariable:nt,splitOverflowContent:Ze,prependContent:Qe,restorePaginationSelection:$e,runCommand:ot,scrollIntoField:ct,scrollIntoVariable:it,scrollIntoPage:lt}),(e,t)=>((0,f.openBlock)(),(0,f.createElementBlock)(`section`,{class:`gd-contract-template-designer__page-shell`,style:(0,f.normalizeStyle)(Ie.value)},[(0,f.createElementVNode)(`div`,{class:(0,f.normalizeClass)([`gd-contract-template-designer__page-zoom`,{"is-active":_.active}]),style:(0,f.normalizeStyle)(Le.value)},[(0,f.createElementVNode)(`header`,re,[(0,f.createElementVNode)(`span`,null,(0,f.toDisplayString)(_.page.title||`第 ${_.pageIndex+1} 页`),1),(0,f.createElementVNode)(`span`,null,`第 `+(0,f.toDisplayString)(_.pageIndex+1)+` 页 · `+(0,f.toDisplayString)(_.pageSize.label||`A4`)+` · `+(0,f.toDisplayString)(_.pageSize.width)+` × `+(0,f.toDisplayString)(_.pageSize.height),1)]),(0,f.createElementVNode)(`div`,{ref_key:`pageElement`,ref:x,class:`gd-contract-template-designer__page`,style:(0,f.normalizeStyle)(Fe.value),onLoadCapture:t[0]||=e=>y(`page-layout-change`,_.page.id),onDragover:t[1]||=(0,f.withModifiers)(()=>{},[`prevent`]),onDrop:ze,onClick:t[2]||=e=>y(`editor-focus`,_.page.id)},[(0,f.createVNode)(ee.default,{decorations:_.pageDecorations,"page-number":_.pageIndex+1,"total-pages":_.totalPages,variables:_.variables},null,8,[`decorations`,`page-number`,`total-pages`,`variables`]),(0,f.unref)(P)?((0,f.openBlock)(),(0,f.createBlock)((0,f.unref)(p.EditorContent),{key:0,class:`gd-contract-template-page__content`,editor:(0,f.unref)(P)},null,8,[`editor`])):(0,f.createCommentVNode)(``,!0)],36)],6)],4))}});exports.default=_;