@bagelink/vue 0.0.570 → 0.0.577

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -5410,7 +5410,7 @@ const _sfc_main$O = /* @__PURE__ */ defineComponent({
5410
5410
  return (_ctx, _cache) => {
5411
5411
  return openBlock(), createElementBlock("span", {
5412
5412
  class: "bgl_icon-font",
5413
- style: normalizeStyle({ fontSize: `${_ctx.size}rem`, color: _ctx.color, "font-variation-settings": `'wght' ${_ctx.weight || 400}` })
5413
+ style: normalizeStyle({ "fontSize": `${_ctx.size}rem`, color: _ctx.color, "font-variation-settings": `'wght' ${_ctx.weight || 400}` })
5414
5414
  }, toDisplayString(_ctx.icon || _ctx.name), 5);
5415
5415
  };
5416
5416
  }
@@ -5419,8 +5419,8 @@ const _hoisted_1$J = { class: "full-nav" };
5419
5419
  const _hoisted_2$A = { class: "nav-scroll" };
5420
5420
  const _hoisted_3$n = { class: "nav-links-wrapper" };
5421
5421
  const _hoisted_4$f = { class: "tooltip" };
5422
- const _hoisted_5$d = { class: "bot-buttons-wrapper" };
5423
- const _hoisted_6$8 = { class: "tooltip" };
5422
+ const _hoisted_5$e = { class: "bot-buttons-wrapper" };
5423
+ const _hoisted_6$9 = { class: "tooltip" };
5424
5424
  const _sfc_main$N = /* @__PURE__ */ defineComponent({
5425
5425
  __name: "NavBar",
5426
5426
  props: {
@@ -5474,7 +5474,7 @@ const _sfc_main$N = /* @__PURE__ */ defineComponent({
5474
5474
  }), 128))
5475
5475
  ])
5476
5476
  ]),
5477
- createElementVNode("div", _hoisted_5$d, [
5477
+ createElementVNode("div", _hoisted_5$e, [
5478
5478
  (openBlock(true), createElementBlock(Fragment$1, null, renderList(_ctx.footerLinks, (link) => {
5479
5479
  return openBlock(), createBlock(resolveDynamicComponent(link.to ? "router-link" : "div"), {
5480
5480
  key: link.label,
@@ -5489,7 +5489,7 @@ const _sfc_main$N = /* @__PURE__ */ defineComponent({
5489
5489
  createVNode(unref(_sfc_main$O), {
5490
5490
  icon: link.icon
5491
5491
  }, null, 8, ["icon"]),
5492
- createElementVNode("div", _hoisted_6$8, toDisplayString(link.label), 1)
5492
+ createElementVNode("div", _hoisted_6$9, toDisplayString(link.label), 1)
5493
5493
  ]),
5494
5494
  _: 2
5495
5495
  }, 1032, ["to", "onClick"]);
@@ -6333,9 +6333,9 @@ const _hoisted_3$j = [
6333
6333
  _hoisted_2$t
6334
6334
  ];
6335
6335
  const _hoisted_4$d = { class: "infinite-wrapper" };
6336
- const _hoisted_5$c = { class: "row first-row" };
6337
- const _hoisted_6$7 = { key: 0 };
6338
- const _hoisted_7$2 = ["onClick"];
6336
+ const _hoisted_5$d = { class: "row first-row" };
6337
+ const _hoisted_6$8 = { key: 0 };
6338
+ const _hoisted_7$3 = ["onClick"];
6339
6339
  const _hoisted_8$1 = { class: "flex" };
6340
6340
  const _hoisted_9$1 = ["onClick"];
6341
6341
  const _hoisted_10$1 = { key: 0 };
@@ -6478,8 +6478,8 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
6478
6478
  }), [
6479
6479
  loading.value ? (openBlock(), createElementBlock("div", _hoisted_1$C, _hoisted_3$j)) : (openBlock(), createElementBlock("div", normalizeProps(mergeProps({ key: 1 }, unref(wrapperProps))), [
6480
6480
  createElementVNode("table", _hoisted_4$d, [
6481
- createElementVNode("thead", _hoisted_5$c, [
6482
- unref(isSelectable) ? (openBlock(), createElementBlock("th", _hoisted_6$7, [
6481
+ createElementVNode("thead", _hoisted_5$d, [
6482
+ unref(isSelectable) ? (openBlock(), createElementBlock("th", _hoisted_6$8, [
6483
6483
  createElementVNode("input", {
6484
6484
  ref_key: "allSelector",
6485
6485
  ref: allSelector,
@@ -6506,7 +6506,7 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
6506
6506
  }, null, 8, ["class"])
6507
6507
  ], 2)
6508
6508
  ])
6509
- ], 8, _hoisted_7$2);
6509
+ ], 8, _hoisted_7$3);
6510
6510
  }), 128))
6511
6511
  ]),
6512
6512
  createElementVNode("tbody", null, [
@@ -6600,8 +6600,8 @@ const _hoisted_2$s = {
6600
6600
  };
6601
6601
  const _hoisted_3$i = { class: "key" };
6602
6602
  const _hoisted_4$c = { key: 1 };
6603
- const _hoisted_5$b = { class: "key" };
6604
- const _hoisted_6$6 = { class: "vlue" };
6603
+ const _hoisted_5$c = { class: "key" };
6604
+ const _hoisted_6$7 = { class: "vlue" };
6605
6605
  const _sfc_main$C = /* @__PURE__ */ defineComponent({
6606
6606
  __name: "DataPreview",
6607
6607
  props: /* @__PURE__ */ mergeModels({
@@ -6651,8 +6651,8 @@ const _sfc_main$C = /* @__PURE__ */ defineComponent({
6651
6651
  key: id,
6652
6652
  class: "data-row"
6653
6653
  }, [
6654
- createElementVNode("div", _hoisted_5$b, toDisplayString(label), 1),
6655
- createElementVNode("div", _hoisted_6$6, toDisplayString(itemData.value[id ?? ""]), 1)
6654
+ createElementVNode("div", _hoisted_5$c, toDisplayString(label), 1),
6655
+ createElementVNode("div", _hoisted_6$7, toDisplayString(itemData.value[id ?? ""]), 1)
6656
6656
  ]);
6657
6657
  }), 128))
6658
6658
  ])) : createCommentVNode("", true),
@@ -25605,10 +25605,16 @@ const _sfc_main$m = /* @__PURE__ */ defineComponent({
25605
25605
  }
25606
25606
  });
25607
25607
  const JSONInput = /* @__PURE__ */ _export_sfc(_sfc_main$m, [["__scopeId", "data-v-1cbaeab2"]]);
25608
- const _hoisted_1$q = ["disabled"];
25609
- const _hoisted_2$k = { key: 1 };
25610
- const _hoisted_3$f = ["value"];
25611
- const _hoisted_4$b = ["onClick"];
25608
+ const _hoisted_1$q = { class: "flex gap-05" };
25609
+ const _hoisted_2$k = ["disabled"];
25610
+ const _hoisted_3$f = { key: 1 };
25611
+ const _hoisted_4$b = {
25612
+ key: 2,
25613
+ class: "ms-auto ps-05 me-05"
25614
+ };
25615
+ const _hoisted_5$b = ["value"];
25616
+ const _hoisted_6$6 = { class: "selectinput-options" };
25617
+ const _hoisted_7$2 = ["onClick"];
25612
25618
  const _sfc_main$l = /* @__PURE__ */ defineComponent({
25613
25619
  __name: "SelectInput",
25614
25620
  props: {
@@ -25623,7 +25629,8 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
25623
25629
  multiselect: { type: Boolean },
25624
25630
  icon: {},
25625
25631
  hideLabel: { type: Boolean },
25626
- defaultValue: {}
25632
+ defaultValue: {},
25633
+ clearable: { type: Boolean }
25627
25634
  },
25628
25635
  emits: ["update:modelValue"],
25629
25636
  setup(__props, { emit: __emit }) {
@@ -25631,6 +25638,7 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
25631
25638
  const emit2 = __emit;
25632
25639
  const searchInput = ref(null);
25633
25640
  let selectedItems = ref([]);
25641
+ const selectedItemCount = computed(() => selectedItems.value.length ?? 0);
25634
25642
  let search = ref("");
25635
25643
  const dropdown = ref(null);
25636
25644
  let open = ref(false);
@@ -25653,10 +25661,10 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
25653
25661
  }
25654
25662
  }
25655
25663
  const selectedLabel = computed(() => {
25656
- if (selectedItems.value.length === 0) return props2.placeholder || "Select";
25657
- if (selectedItems.value.length > 4) {
25664
+ if (selectedItemCount.value === 0) return props2.placeholder || "Select";
25665
+ if (selectedItemCount.value > 4) {
25658
25666
  const str = selectedItems.value.slice(0, 4).map((item) => getLabel(item)).join(", ");
25659
- return `${str}... +${selectedItems.value.length - 4}`;
25667
+ return `${str}... +${selectedItemCount.value - 4}`;
25660
25668
  }
25661
25669
  return selectedItems.value.map((item) => getLabel(item)).join(", ");
25662
25670
  });
@@ -25689,7 +25697,7 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
25689
25697
  current.push(option2);
25690
25698
  selectedItems.value = current;
25691
25699
  } else {
25692
- selectedItems.value.splice(0, selectedItems.value.length, option2);
25700
+ selectedItems.value.splice(0, selectedItemCount.value, option2);
25693
25701
  }
25694
25702
  if (!props2.multiselect) (_a2 = dropdown.value) == null ? void 0 : _a2.hide();
25695
25703
  emitUpdate();
@@ -25717,7 +25725,7 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
25717
25725
  } else {
25718
25726
  const isSame = compareArrays([newVal].flat(), selectedItems.value);
25719
25727
  if (!isSame) {
25720
- selectedItems.value.splice(0, selectedItems.value.length, ...[newVal].flat());
25728
+ selectedItems.value.splice(0, selectedItemCount.value, ...[newVal].flat());
25721
25729
  }
25722
25730
  }
25723
25731
  },
@@ -25751,13 +25759,13 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
25751
25759
  ref: dropdown,
25752
25760
  placement: "bottom-start",
25753
25761
  class: "bagel-input selectinput",
25754
- onClick: _cache[3] || (_cache[3] = withModifiers(() => {
25762
+ onClick: _cache[4] || (_cache[4] = withModifiers(() => {
25755
25763
  }, ["stop"])),
25756
- onHide: _cache[4] || (_cache[4] = ($event) => updateOpen(false))
25764
+ onHide: _cache[5] || (_cache[5] = ($event) => updateOpen(false))
25757
25765
  }, {
25758
25766
  popper: withCtx(() => [
25759
25767
  createVNode(unref(_sfc_main$B), {
25760
- class: "selectinput-options p-05",
25768
+ class: "p-05",
25761
25769
  style: normalizeStyle({ width: _ctx.fullWidth ? "100%" : "auto" })
25762
25770
  }, {
25763
25771
  default: withCtx(() => [
@@ -25766,62 +25774,72 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
25766
25774
  ref_key: "searchInput",
25767
25775
  ref: searchInput,
25768
25776
  modelValue: unref(search),
25769
- "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => isRef(search) ? search.value = $event : search = $event),
25777
+ "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => isRef(search) ? search.value = $event : search = $event),
25770
25778
  dense: "",
25771
25779
  placeholder: "Search",
25772
25780
  icon: "search"
25773
25781
  }, null, 8, ["modelValue"])) : createCommentVNode("", true),
25774
- (openBlock(true), createElementBlock(Fragment$1, null, renderList(filteredOptions.value, (option2, i2) => {
25775
- return openBlock(), createElementBlock("div", {
25776
- key: `${option2}${i2}`,
25777
- class: normalizeClass(["selectinput-option hover gap-1", { selected: isSelected(option2) }]),
25778
- onClick: ($event) => select2(option2)
25779
- }, [
25780
- isSelected(option2) ? (openBlock(), createBlock(unref(_sfc_main$O), {
25781
- key: 0,
25782
- icon: "check"
25783
- })) : createCommentVNode("", true),
25784
- !isSelected(option2) ? (openBlock(), createBlock(unref(_sfc_main$O), {
25785
- key: 1,
25786
- class: "opacity-3",
25787
- icon: "fiber_manual_record"
25788
- })) : createCommentVNode("", true),
25789
- createElementVNode("span", null, toDisplayString(getLabel(option2)), 1)
25790
- ], 10, _hoisted_4$b);
25791
- }), 128)),
25782
+ createElementVNode("div", _hoisted_6$6, [
25783
+ (openBlock(true), createElementBlock(Fragment$1, null, renderList(filteredOptions.value, (option2, i2) => {
25784
+ return openBlock(), createElementBlock("div", {
25785
+ key: `${option2}${i2}`,
25786
+ class: normalizeClass(["selectinput-option hover gap-1", { selected: isSelected(option2) }]),
25787
+ onClick: ($event) => select2(option2)
25788
+ }, [
25789
+ isSelected(option2) ? (openBlock(), createBlock(unref(_sfc_main$O), {
25790
+ key: 0,
25791
+ icon: "check"
25792
+ })) : createCommentVNode("", true),
25793
+ !isSelected(option2) ? (openBlock(), createBlock(unref(_sfc_main$O), {
25794
+ key: 1,
25795
+ class: "opacity-3",
25796
+ icon: "fiber_manual_record"
25797
+ })) : createCommentVNode("", true),
25798
+ createElementVNode("span", null, toDisplayString(getLabel(option2)), 1)
25799
+ ], 10, _hoisted_7$2);
25800
+ }), 128))
25801
+ ]),
25792
25802
  renderSlot(_ctx.$slots, "last", {}, void 0, true)
25793
25803
  ]),
25794
25804
  _: 3
25795
25805
  }, 8, ["style"])
25796
25806
  ]),
25797
25807
  default: withCtx(() => [
25798
- createElementVNode("label", null, [
25808
+ createElementVNode("label", _hoisted_1$q, [
25799
25809
  createTextVNode(toDisplayString(_ctx.label) + " ", 1),
25800
25810
  createElementVNode("button", {
25801
25811
  disabled: _ctx.disabled,
25802
25812
  type: "button",
25803
- class: normalizeClass(["selectinput-btn", { isEmpty: unref(selectedItems).length === 0 }]),
25813
+ class: normalizeClass(["selectinput-btn", { isEmpty: selectedItemCount.value === 0 }]),
25804
25814
  onKeydown: openOptions,
25805
- onClick: _cache[0] || (_cache[0] = ($event) => updateOpen(true))
25815
+ onClick: _cache[1] || (_cache[1] = ($event) => updateOpen(true))
25806
25816
  }, [
25807
25817
  _ctx.icon ? (openBlock(), createBlock(unref(_sfc_main$O), {
25808
25818
  key: 0,
25809
25819
  icon: _ctx.icon
25810
25820
  }, null, 8, ["icon"])) : createCommentVNode("", true),
25811
- !_ctx.hideLabel ? (openBlock(), createElementBlock("p", _hoisted_2$k, toDisplayString(selectedLabel.value), 1)) : createCommentVNode("", true),
25821
+ !_ctx.hideLabel ? (openBlock(), createElementBlock("p", _hoisted_3$f, toDisplayString(selectedLabel.value), 1)) : createCommentVNode("", true),
25822
+ _ctx.clearable && selectedItemCount.value > 0 ? (openBlock(), createElementBlock("div", _hoisted_4$b, [
25823
+ createVNode(unref(Btn), {
25824
+ thin: "",
25825
+ icon: "clear",
25826
+ class: "color-black bg-gray-light",
25827
+ onClick: _cache[0] || (_cache[0] = ($event) => isRef(selectedItems) ? selectedItems.value = [] : selectedItems = [])
25828
+ })
25829
+ ])) : createCommentVNode("", true),
25812
25830
  !_ctx.disabled ? (openBlock(), createBlock(unref(_sfc_main$O), mergeProps({
25813
- key: 2,
25831
+ key: 3,
25814
25832
  thin: ""
25815
25833
  }, { icon: unref(open) ? "unfold_less" : "unfold_more" }), null, 16)) : createCommentVNode("", true)
25816
- ], 42, _hoisted_1$q),
25834
+ ], 42, _hoisted_2$k),
25817
25835
  _ctx.required ? (openBlock(), createElementBlock("input", {
25818
25836
  key: 0,
25819
25837
  tabindex: "-1",
25820
25838
  style: { "width": "0", "height": "0", "position": "absolute", "opacity": "0", "z-index": "-1" },
25821
25839
  value: unref(selectedItems),
25822
25840
  required: "",
25823
- onInput: _cache[1] || (_cache[1] = ($event) => updateOpen(true))
25824
- }, null, 40, _hoisted_3$f)) : createCommentVNode("", true)
25841
+ onInput: _cache[2] || (_cache[2] = ($event) => updateOpen(true))
25842
+ }, null, 40, _hoisted_5$b)) : createCommentVNode("", true)
25825
25843
  ])
25826
25844
  ]),
25827
25845
  _: 3
@@ -25829,7 +25847,7 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
25829
25847
  };
25830
25848
  }
25831
25849
  });
25832
- const SelectInput = /* @__PURE__ */ _export_sfc(_sfc_main$l, [["__scopeId", "data-v-4e1d2142"]]);
25850
+ const SelectInput = /* @__PURE__ */ _export_sfc(_sfc_main$l, [["__scopeId", "data-v-6f297737"]]);
25833
25851
  /*!
25834
25852
  * vue-draggable-next v2.2.0
25835
25853
  * (c) 2023 Anish George
@@ -28816,7 +28834,7 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
28816
28834
  }
28817
28835
  });
28818
28836
  const RadioPillsInput = /* @__PURE__ */ _export_sfc(_sfc_main$f, [["__scopeId", "data-v-681173be"]]);
28819
- const _withScopeId$2 = (n2) => (pushScopeId("data-v-d8ba8e50"), n2 = n2(), popScopeId(), n2);
28837
+ const _withScopeId$2 = (n2) => (pushScopeId("data-v-853e75be"), n2 = n2(), popScopeId(), n2);
28820
28838
  const _hoisted_1$j = { class: "bagel-input" };
28821
28839
  const _hoisted_2$e = {
28822
28840
  key: 0,
@@ -28856,9 +28874,9 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
28856
28874
  emits: ["update:modelValue"],
28857
28875
  setup(__props, { emit: __emit }) {
28858
28876
  const props2 = __props;
28877
+ const emit2 = __emit;
28859
28878
  const bagel = useBagel();
28860
28879
  const bindKey2 = props2.bindkey || "id";
28861
- const emit2 = __emit;
28862
28880
  let file_bindkeys = ref(props2.modelValue || []);
28863
28881
  const storageFiles = ref([]);
28864
28882
  async function fetchFiles() {
@@ -29060,7 +29078,7 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
29060
29078
  };
29061
29079
  }
29062
29080
  });
29063
- const $el = /* @__PURE__ */ _export_sfc(_sfc_main$e, [["__scopeId", "data-v-d8ba8e50"]]);
29081
+ const $el = /* @__PURE__ */ _export_sfc(_sfc_main$e, [["__scopeId", "data-v-853e75be"]]);
29064
29082
  const _withScopeId$1 = (n2) => (pushScopeId("data-v-eceeebfb"), n2 = n2(), popScopeId(), n2);
29065
29083
  const _hoisted_1$i = ["title"];
29066
29084
  const _hoisted_2$d = /* @__PURE__ */ _withScopeId$1(() => /* @__PURE__ */ createElementVNode("span", { class: "slider round" }, null, -1));
@@ -29493,7 +29511,7 @@ class Fragment {
29493
29511
  /**
29494
29512
  Find the index and inner offset corresponding to a given relative
29495
29513
  position in this fragment. The result object will be reused
29496
- (overwritten) the next time the function is called. (Not public.)
29514
+ (overwritten) the next time the function is called. @internal
29497
29515
  */
29498
29516
  findIndex(pos, round2 = -1) {
29499
29517
  if (pos == 0)
@@ -29699,7 +29717,9 @@ let Mark$1 = class Mark2 {
29699
29717
  let type3 = schema.marks[json.type];
29700
29718
  if (!type3)
29701
29719
  throw new RangeError(`There is no mark type ${json.type} in this schema`);
29702
- return type3.create(json.attrs);
29720
+ let mark = type3.create(json.attrs);
29721
+ type3.checkAttrs(mark.attrs);
29722
+ return mark;
29703
29723
  }
29704
29724
  /**
29705
29725
  Test whether two sets of marks are identical.
@@ -30196,17 +30216,28 @@ class ResolvedPos {
30196
30216
  @internal
30197
30217
  */
30198
30218
  static resolveCached(doc2, pos) {
30199
- for (let i2 = 0; i2 < resolveCache.length; i2++) {
30200
- let cached2 = resolveCache[i2];
30201
- if (cached2.pos == pos && cached2.doc == doc2)
30202
- return cached2;
30219
+ let cache = resolveCache.get(doc2);
30220
+ if (cache) {
30221
+ for (let i2 = 0; i2 < cache.elts.length; i2++) {
30222
+ let elt = cache.elts[i2];
30223
+ if (elt.pos == pos)
30224
+ return elt;
30225
+ }
30226
+ } else {
30227
+ resolveCache.set(doc2, cache = new ResolveCache());
30203
30228
  }
30204
- let result2 = resolveCache[resolveCachePos] = ResolvedPos.resolve(doc2, pos);
30205
- resolveCachePos = (resolveCachePos + 1) % resolveCacheSize;
30229
+ let result2 = cache.elts[cache.i] = ResolvedPos.resolve(doc2, pos);
30230
+ cache.i = (cache.i + 1) % resolveCacheSize;
30206
30231
  return result2;
30207
30232
  }
30208
30233
  }
30209
- let resolveCache = [], resolveCachePos = 0, resolveCacheSize = 12;
30234
+ class ResolveCache {
30235
+ constructor() {
30236
+ this.elts = [];
30237
+ this.i = 0;
30238
+ }
30239
+ }
30240
+ const resolveCacheSize = 12, resolveCache = /* @__PURE__ */ new WeakMap();
30210
30241
  class NodeRange {
30211
30242
  /**
30212
30243
  Construct a node range. `$from` and `$to` should point into the
@@ -30592,13 +30623,17 @@ let Node$3 = class Node2 {
30592
30623
  }
30593
30624
  /**
30594
30625
  Check whether this node and its descendants conform to the
30595
- schema, and raise error when they do not.
30626
+ schema, and raise an exception when they do not.
30596
30627
  */
30597
30628
  check() {
30598
30629
  this.type.checkContent(this.content);
30630
+ this.type.checkAttrs(this.attrs);
30599
30631
  let copy2 = Mark$1.none;
30600
- for (let i2 = 0; i2 < this.marks.length; i2++)
30601
- copy2 = this.marks[i2].addToSet(copy2);
30632
+ for (let i2 = 0; i2 < this.marks.length; i2++) {
30633
+ let mark = this.marks[i2];
30634
+ mark.type.checkAttrs(mark.attrs);
30635
+ copy2 = mark.addToSet(copy2);
30636
+ }
30602
30637
  if (!Mark$1.sameSet(copy2, this.marks))
30603
30638
  throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((m2) => m2.type.name)}`);
30604
30639
  this.content.forEach((node) => node.check());
@@ -30624,7 +30659,7 @@ let Node$3 = class Node2 {
30624
30659
  static fromJSON(schema, json) {
30625
30660
  if (!json)
30626
30661
  throw new RangeError("Invalid input for Node.fromJSON");
30627
- let marks = null;
30662
+ let marks = void 0;
30628
30663
  if (json.marks) {
30629
30664
  if (!Array.isArray(json.marks))
30630
30665
  throw new RangeError("Invalid mark data for Node.fromJSON");
@@ -30636,7 +30671,9 @@ let Node$3 = class Node2 {
30636
30671
  return schema.text(json.text, marks);
30637
30672
  }
30638
30673
  let content = Fragment.fromJSON(schema, json.content);
30639
- return schema.nodeType(json.type).create(json.attrs, content, marks);
30674
+ let node = schema.nodeType(json.type).create(json.attrs, content, marks);
30675
+ node.type.checkAttrs(node.attrs);
30676
+ return node;
30640
30677
  }
30641
30678
  };
30642
30679
  Node$3.prototype.text = void 0;
@@ -31118,6 +31155,16 @@ function computeAttrs(attrs, value) {
31118
31155
  }
31119
31156
  return built;
31120
31157
  }
31158
+ function checkAttrs(attrs, values3, type3, name) {
31159
+ for (let name2 in values3)
31160
+ if (!(name2 in attrs))
31161
+ throw new RangeError(`Unsupported attribute ${name2} for ${type3} of type ${name2}`);
31162
+ for (let name2 in attrs) {
31163
+ let attr = attrs[name2];
31164
+ if (attr.validate)
31165
+ attr.validate(values3[name2]);
31166
+ }
31167
+ }
31121
31168
  function initAttrs(attrs) {
31122
31169
  let result2 = /* @__PURE__ */ Object.create(null);
31123
31170
  if (attrs)
@@ -31247,7 +31294,7 @@ let NodeType$1 = class NodeType2 {
31247
31294
  }
31248
31295
  /**
31249
31296
  Returns true if the given fragment is valid content for this node
31250
- type with the given attributes.
31297
+ type.
31251
31298
  */
31252
31299
  validContent(content) {
31253
31300
  let result2 = this.contentMatch.matchFragment(content);
@@ -31268,6 +31315,12 @@ let NodeType$1 = class NodeType2 {
31268
31315
  throw new RangeError(`Invalid content for node ${this.name}: ${content.toString().slice(0, 50)}`);
31269
31316
  }
31270
31317
  /**
31318
+ @internal
31319
+ */
31320
+ checkAttrs(attrs) {
31321
+ checkAttrs(this.attrs, attrs, "node", this.name);
31322
+ }
31323
+ /**
31271
31324
  Check whether the given mark type is allowed in this node.
31272
31325
  */
31273
31326
  allowsMarkType(markType) {
@@ -31317,10 +31370,19 @@ let NodeType$1 = class NodeType2 {
31317
31370
  return result2;
31318
31371
  }
31319
31372
  };
31373
+ function validateType(type3) {
31374
+ let types = type3.split("|");
31375
+ return (value) => {
31376
+ let name = value === null ? "null" : typeof value;
31377
+ if (types.indexOf(name) < 0)
31378
+ throw new RangeError(`Expected value of type ${types}, got ${name}`);
31379
+ };
31380
+ }
31320
31381
  class Attribute {
31321
31382
  constructor(options) {
31322
31383
  this.hasDefault = Object.prototype.hasOwnProperty.call(options, "default");
31323
31384
  this.default = options.default;
31385
+ this.validate = typeof options.validate == "string" ? validateType(options.validate) : options.validate;
31324
31386
  }
31325
31387
  get isRequired() {
31326
31388
  return !this.hasDefault;
@@ -31379,6 +31441,12 @@ class MarkType {
31379
31441
  return set2[i2];
31380
31442
  }
31381
31443
  /**
31444
+ @internal
31445
+ */
31446
+ checkAttrs(attrs) {
31447
+ checkAttrs(this.attrs, attrs, "mark", this.name);
31448
+ }
31449
+ /**
31382
31450
  Queries whether a given mark type is
31383
31451
  [excluded](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) by this one.
31384
31452
  */
@@ -31391,6 +31459,7 @@ class Schema {
31391
31459
  Construct a schema from a schema [specification](https://prosemirror.net/docs/ref/#model.SchemaSpec).
31392
31460
  */
31393
31461
  constructor(spec) {
31462
+ this.linebreakReplacement = null;
31394
31463
  this.cached = /* @__PURE__ */ Object.create(null);
31395
31464
  let instanceSpec = this.spec = {};
31396
31465
  for (let prop3 in spec)
@@ -31404,6 +31473,13 @@ class Schema {
31404
31473
  let type3 = this.nodes[prop3], contentExpr = type3.spec.content || "", markExpr = type3.spec.marks;
31405
31474
  type3.contentMatch = contentExprCache[contentExpr] || (contentExprCache[contentExpr] = ContentMatch.parse(contentExpr, this.nodes));
31406
31475
  type3.inlineContent = type3.contentMatch.inlineContent;
31476
+ if (type3.spec.linebreakReplacement) {
31477
+ if (this.linebreakReplacement)
31478
+ throw new RangeError("Multiple linebreak nodes defined");
31479
+ if (!type3.isInline || !type3.isLeaf)
31480
+ throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");
31481
+ this.linebreakReplacement = type3;
31482
+ }
31407
31483
  type3.markSet = markExpr == "_" ? null : markExpr ? gatherMarks(this, markExpr.split(" ")) : markExpr == "" || !type3.inlineContent ? [] : null;
31408
31484
  }
31409
31485
  for (let prop3 in this.marks) {
@@ -31488,6 +31564,12 @@ function gatherMarks(schema, marks) {
31488
31564
  }
31489
31565
  return found2;
31490
31566
  }
31567
+ function isTagRule(rule) {
31568
+ return rule.tag != null;
31569
+ }
31570
+ function isStyleRule(rule) {
31571
+ return rule.style != null;
31572
+ }
31491
31573
  class DOMParser {
31492
31574
  /**
31493
31575
  Create a parser that targets the given schema, using the given
@@ -31498,11 +31580,16 @@ class DOMParser {
31498
31580
  this.rules = rules;
31499
31581
  this.tags = [];
31500
31582
  this.styles = [];
31583
+ let matchedStyles = this.matchedStyles = [];
31501
31584
  rules.forEach((rule) => {
31502
- if (rule.tag)
31585
+ if (isTagRule(rule)) {
31503
31586
  this.tags.push(rule);
31504
- else if (rule.style)
31587
+ } else if (isStyleRule(rule)) {
31588
+ let prop3 = /[^=]*/.exec(rule.style)[0];
31589
+ if (matchedStyles.indexOf(prop3) < 0)
31590
+ matchedStyles.push(prop3);
31505
31591
  this.styles.push(rule);
31592
+ }
31506
31593
  });
31507
31594
  this.normalizeLists = !this.tags.some((r2) => {
31508
31595
  if (!/^(ul|ol)\b/.test(r2.tag) || !r2.node)
@@ -31762,10 +31849,10 @@ class ParseContext {
31762
31849
  this.addElement(dom);
31763
31850
  }
31764
31851
  withStyleRules(dom, f2) {
31765
- let style2 = dom.getAttribute("style");
31766
- if (!style2)
31852
+ let style2 = dom.style;
31853
+ if (!style2 || !style2.length)
31767
31854
  return f2();
31768
- let marks = this.readStyles(parseStyles(style2));
31855
+ let marks = this.readStyles(dom.style);
31769
31856
  if (!marks)
31770
31857
  return;
31771
31858
  let [addMarks, removeMarks] = marks, top2 = this.top;
@@ -31859,27 +31946,30 @@ class ParseContext {
31859
31946
  // had a rule with `ignore` set.
31860
31947
  readStyles(styles) {
31861
31948
  let add2 = Mark$1.none, remove2 = Mark$1.none;
31862
- for (let i2 = 0; i2 < styles.length; i2 += 2) {
31863
- for (let after = void 0; ; ) {
31864
- let rule = this.parser.matchStyle(styles[i2], styles[i2 + 1], this, after);
31865
- if (!rule)
31866
- break;
31867
- if (rule.ignore)
31868
- return null;
31869
- if (rule.clearMark) {
31870
- this.top.pendingMarks.concat(this.top.activeMarks).forEach((m2) => {
31871
- if (rule.clearMark(m2))
31872
- remove2 = m2.addToSet(remove2);
31873
- });
31874
- } else {
31875
- add2 = this.parser.schema.marks[rule.mark].create(rule.attrs).addToSet(add2);
31876
- }
31877
- if (rule.consuming === false)
31878
- after = rule;
31879
- else
31880
- break;
31949
+ if (styles.length)
31950
+ for (let i2 = 0; i2 < this.parser.matchedStyles.length; i2++) {
31951
+ let name = this.parser.matchedStyles[i2], value = styles.getPropertyValue(name);
31952
+ if (value)
31953
+ for (let after = void 0; ; ) {
31954
+ let rule = this.parser.matchStyle(name, value, this, after);
31955
+ if (!rule)
31956
+ break;
31957
+ if (rule.ignore)
31958
+ return null;
31959
+ if (rule.clearMark) {
31960
+ this.top.pendingMarks.concat(this.top.activeMarks).forEach((m2) => {
31961
+ if (rule.clearMark(m2))
31962
+ remove2 = m2.addToSet(remove2);
31963
+ });
31964
+ } else {
31965
+ add2 = this.parser.schema.marks[rule.mark].create(rule.attrs).addToSet(add2);
31966
+ }
31967
+ if (rule.consuming === false)
31968
+ after = rule;
31969
+ else
31970
+ break;
31971
+ }
31881
31972
  }
31882
- }
31883
31973
  return [add2, remove2];
31884
31974
  }
31885
31975
  // Look up a handler for the given node. If none are found, return
@@ -32148,12 +32238,6 @@ function normalizeList(dom) {
32148
32238
  function matches(dom, selector2) {
32149
32239
  return (dom.matches || dom.msMatchesSelector || dom.webkitMatchesSelector || dom.mozMatchesSelector).call(dom, selector2);
32150
32240
  }
32151
- function parseStyles(style2) {
32152
- let re2 = /\s*([\w-]+)\s*:\s*([^;]+)/g, m2, result2 = [];
32153
- while (m2 = re2.exec(style2))
32154
- result2.push(m2[1], m2[2].trim());
32155
- return result2;
32156
- }
32157
32241
  function copy$2(obj) {
32158
32242
  let copy2 = {};
32159
32243
  for (let prop3 in obj)
@@ -32244,7 +32328,7 @@ class DOMSerializer {
32244
32328
  @internal
32245
32329
  */
32246
32330
  serializeNodeInner(node, options) {
32247
- let { dom, contentDOM } = DOMSerializer.renderSpec(doc$1(options), this.nodes[node.type.name](node));
32331
+ let { dom, contentDOM } = renderSpec(doc$1(options), this.nodes[node.type.name](node), null, node.attrs);
32248
32332
  if (contentDOM) {
32249
32333
  if (node.isLeaf)
32250
32334
  throw new RangeError("Content hole not allowed in a leaf node spec");
@@ -32275,7 +32359,7 @@ class DOMSerializer {
32275
32359
  */
32276
32360
  serializeMark(mark, inline, options = {}) {
32277
32361
  let toDOM = this.marks[mark.type.name];
32278
- return toDOM && DOMSerializer.renderSpec(doc$1(options), toDOM(mark, inline));
32362
+ return toDOM && renderSpec(doc$1(options), toDOM(mark, inline), null, mark.attrs);
32279
32363
  }
32280
32364
  /**
32281
32365
  Render an [output spec](https://prosemirror.net/docs/ref/#model.DOMOutputSpec) to a DOM node. If
@@ -32283,48 +32367,7 @@ class DOMSerializer {
32283
32367
  node with the hole.
32284
32368
  */
32285
32369
  static renderSpec(doc2, structure, xmlNS = null) {
32286
- if (typeof structure == "string")
32287
- return { dom: doc2.createTextNode(structure) };
32288
- if (structure.nodeType != null)
32289
- return { dom: structure };
32290
- if (structure.dom && structure.dom.nodeType != null)
32291
- return structure;
32292
- let tagName = structure[0], space = tagName.indexOf(" ");
32293
- if (space > 0) {
32294
- xmlNS = tagName.slice(0, space);
32295
- tagName = tagName.slice(space + 1);
32296
- }
32297
- let contentDOM;
32298
- let dom = xmlNS ? doc2.createElementNS(xmlNS, tagName) : doc2.createElement(tagName);
32299
- let attrs = structure[1], start2 = 1;
32300
- if (attrs && typeof attrs == "object" && attrs.nodeType == null && !Array.isArray(attrs)) {
32301
- start2 = 2;
32302
- for (let name in attrs)
32303
- if (attrs[name] != null) {
32304
- let space2 = name.indexOf(" ");
32305
- if (space2 > 0)
32306
- dom.setAttributeNS(name.slice(0, space2), name.slice(space2 + 1), attrs[name]);
32307
- else
32308
- dom.setAttribute(name, attrs[name]);
32309
- }
32310
- }
32311
- for (let i2 = start2; i2 < structure.length; i2++) {
32312
- let child = structure[i2];
32313
- if (child === 0) {
32314
- if (i2 < structure.length - 1 || i2 > start2)
32315
- throw new RangeError("Content hole must be the only child of its parent node");
32316
- return { dom, contentDOM: dom };
32317
- } else {
32318
- let { dom: inner, contentDOM: innerContent } = DOMSerializer.renderSpec(doc2, child, xmlNS);
32319
- dom.appendChild(inner);
32320
- if (innerContent) {
32321
- if (contentDOM)
32322
- throw new RangeError("Multiple content holes");
32323
- contentDOM = innerContent;
32324
- }
32325
- }
32326
- }
32327
- return { dom, contentDOM };
32370
+ return renderSpec(doc2, structure, xmlNS);
32328
32371
  }
32329
32372
  /**
32330
32373
  Build a serializer using the [`toDOM`](https://prosemirror.net/docs/ref/#model.NodeSpec.toDOM)
@@ -32362,6 +32405,84 @@ function gatherToDOM(obj) {
32362
32405
  function doc$1(options) {
32363
32406
  return options.document || window.document;
32364
32407
  }
32408
+ const suspiciousAttributeCache = /* @__PURE__ */ new WeakMap();
32409
+ function suspiciousAttributes(attrs) {
32410
+ let value = suspiciousAttributeCache.get(attrs);
32411
+ if (value === void 0)
32412
+ suspiciousAttributeCache.set(attrs, value = suspiciousAttributesInner(attrs));
32413
+ return value;
32414
+ }
32415
+ function suspiciousAttributesInner(attrs) {
32416
+ let result2 = null;
32417
+ function scan(value) {
32418
+ if (value && typeof value == "object") {
32419
+ if (Array.isArray(value)) {
32420
+ if (typeof value[0] == "string") {
32421
+ if (!result2)
32422
+ result2 = [];
32423
+ result2.push(value);
32424
+ } else {
32425
+ for (let i2 = 0; i2 < value.length; i2++)
32426
+ scan(value[i2]);
32427
+ }
32428
+ } else {
32429
+ for (let prop3 in value)
32430
+ scan(value[prop3]);
32431
+ }
32432
+ }
32433
+ }
32434
+ scan(attrs);
32435
+ return result2;
32436
+ }
32437
+ function renderSpec(doc2, structure, xmlNS, blockArraysIn) {
32438
+ if (typeof structure == "string")
32439
+ return { dom: doc2.createTextNode(structure) };
32440
+ if (structure.nodeType != null)
32441
+ return { dom: structure };
32442
+ if (structure.dom && structure.dom.nodeType != null)
32443
+ return structure;
32444
+ let tagName = structure[0], suspicious;
32445
+ if (typeof tagName != "string")
32446
+ throw new RangeError("Invalid array passed to renderSpec");
32447
+ if (blockArraysIn && (suspicious = suspiciousAttributes(blockArraysIn)) && suspicious.indexOf(structure) > -1)
32448
+ throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");
32449
+ let space = tagName.indexOf(" ");
32450
+ if (space > 0) {
32451
+ xmlNS = tagName.slice(0, space);
32452
+ tagName = tagName.slice(space + 1);
32453
+ }
32454
+ let contentDOM;
32455
+ let dom = xmlNS ? doc2.createElementNS(xmlNS, tagName) : doc2.createElement(tagName);
32456
+ let attrs = structure[1], start2 = 1;
32457
+ if (attrs && typeof attrs == "object" && attrs.nodeType == null && !Array.isArray(attrs)) {
32458
+ start2 = 2;
32459
+ for (let name in attrs)
32460
+ if (attrs[name] != null) {
32461
+ let space2 = name.indexOf(" ");
32462
+ if (space2 > 0)
32463
+ dom.setAttributeNS(name.slice(0, space2), name.slice(space2 + 1), attrs[name]);
32464
+ else
32465
+ dom.setAttribute(name, attrs[name]);
32466
+ }
32467
+ }
32468
+ for (let i2 = start2; i2 < structure.length; i2++) {
32469
+ let child = structure[i2];
32470
+ if (child === 0) {
32471
+ if (i2 < structure.length - 1 || i2 > start2)
32472
+ throw new RangeError("Content hole must be the only child of its parent node");
32473
+ return { dom, contentDOM: dom };
32474
+ } else {
32475
+ let { dom: inner, contentDOM: innerContent } = renderSpec(doc2, child, xmlNS, blockArraysIn);
32476
+ dom.appendChild(inner);
32477
+ if (innerContent) {
32478
+ if (contentDOM)
32479
+ throw new RangeError("Multiple content holes");
32480
+ contentDOM = innerContent;
32481
+ }
32482
+ }
32483
+ }
32484
+ return { dom, contentDOM };
32485
+ }
32365
32486
  const lower16 = 65535;
32366
32487
  const factor16 = Math.pow(2, 16);
32367
32488
  function makeRecover(index2, offset2) {
@@ -33021,7 +33142,8 @@ class ReplaceAroundStep extends Step$1 {
33021
33142
  }
33022
33143
  map(mapping) {
33023
33144
  let from2 = mapping.mapResult(this.from, 1), to2 = mapping.mapResult(this.to, -1);
33024
- let gapFrom = mapping.map(this.gapFrom, -1), gapTo = mapping.map(this.gapTo, 1);
33145
+ let gapFrom = this.from == this.gapFrom ? from2.pos : mapping.map(this.gapFrom, -1);
33146
+ let gapTo = this.to == this.gapTo ? to2.pos : mapping.map(this.gapTo, 1);
33025
33147
  if (from2.deletedAcross && to2.deletedAcross || gapFrom < from2.pos || gapTo > to2.pos)
33026
33148
  return null;
33027
33149
  return new ReplaceAroundStep(from2.pos, to2.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
@@ -33134,7 +33256,7 @@ function removeMark(tr2, from2, to2, mark) {
33134
33256
  });
33135
33257
  matched.forEach((m2) => tr2.step(new RemoveMarkStep(m2.from, m2.to, m2.style)));
33136
33258
  }
33137
- function clearIncompatible(tr2, pos, parentType, match2 = parentType.contentMatch) {
33259
+ function clearIncompatible(tr2, pos, parentType, match2 = parentType.contentMatch, clearNewlines = true) {
33138
33260
  let node = tr2.doc.nodeAt(pos);
33139
33261
  let replSteps = [], cur = pos + 1;
33140
33262
  for (let i2 = 0; i2 < node.childCount; i2++) {
@@ -33147,7 +33269,7 @@ function clearIncompatible(tr2, pos, parentType, match2 = parentType.contentMatc
33147
33269
  for (let j2 = 0; j2 < child.marks.length; j2++)
33148
33270
  if (!parentType.allowsMarkType(child.marks[j2].type))
33149
33271
  tr2.step(new RemoveMarkStep(cur, end2, child.marks[j2]));
33150
- if (child.isText && !parentType.spec.code) {
33272
+ if (clearNewlines && child.isText && parentType.whitespace != "pre") {
33151
33273
  let m2, newline = /\r?\n|\r/g, slice4;
33152
33274
  while (m2 = newline.exec(child.text)) {
33153
33275
  if (!slice4)
@@ -33256,14 +33378,45 @@ function setBlockType$1(tr2, from2, to2, type3, attrs) {
33256
33378
  let mapFrom = tr2.steps.length;
33257
33379
  tr2.doc.nodesBetween(from2, to2, (node, pos) => {
33258
33380
  if (node.isTextblock && !node.hasMarkup(type3, attrs) && canChangeType(tr2.doc, tr2.mapping.slice(mapFrom).map(pos), type3)) {
33259
- tr2.clearIncompatible(tr2.mapping.slice(mapFrom).map(pos, 1), type3);
33381
+ let convertNewlines = null;
33382
+ if (type3.schema.linebreakReplacement) {
33383
+ let pre = type3.whitespace == "pre", supportLinebreak = !!type3.contentMatch.matchType(type3.schema.linebreakReplacement);
33384
+ if (pre && !supportLinebreak)
33385
+ convertNewlines = false;
33386
+ else if (!pre && supportLinebreak)
33387
+ convertNewlines = true;
33388
+ }
33389
+ if (convertNewlines === false)
33390
+ replaceLinebreaks(tr2, node, pos, mapFrom);
33391
+ clearIncompatible(tr2, tr2.mapping.slice(mapFrom).map(pos, 1), type3, void 0, convertNewlines === null);
33260
33392
  let mapping = tr2.mapping.slice(mapFrom);
33261
33393
  let startM = mapping.map(pos, 1), endM = mapping.map(pos + node.nodeSize, 1);
33262
33394
  tr2.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1, new Slice(Fragment.from(type3.create(attrs, null, node.marks)), 0, 0), 1, true));
33395
+ if (convertNewlines === true)
33396
+ replaceNewlines(tr2, node, pos, mapFrom);
33263
33397
  return false;
33264
33398
  }
33265
33399
  });
33266
33400
  }
33401
+ function replaceNewlines(tr2, node, pos, mapFrom) {
33402
+ node.forEach((child, offset2) => {
33403
+ if (child.isText) {
33404
+ let m2, newline = /\r?\n|\r/g;
33405
+ while (m2 = newline.exec(child.text)) {
33406
+ let start2 = tr2.mapping.slice(mapFrom).map(pos + 1 + offset2 + m2.index);
33407
+ tr2.replaceWith(start2, start2 + 1, node.type.schema.linebreakReplacement.create());
33408
+ }
33409
+ }
33410
+ });
33411
+ }
33412
+ function replaceLinebreaks(tr2, node, pos, mapFrom) {
33413
+ node.forEach((child, offset2) => {
33414
+ if (child.type == child.type.schema.linebreakReplacement) {
33415
+ let start2 = tr2.mapping.slice(mapFrom).map(pos + 1 + offset2);
33416
+ tr2.replaceWith(start2, start2 + 1, node.type.schema.text("\n"));
33417
+ }
33418
+ });
33419
+ }
33267
33420
  function canChangeType(doc2, pos, type3) {
33268
33421
  let $pos = doc2.resolve(pos), index2 = $pos.index();
33269
33422
  return $pos.parent.canReplaceWith(index2, index2 + 1, type3);
@@ -35029,6 +35182,9 @@ const textRange = function(node, from2, to2) {
35029
35182
  range2.setStart(node, from2 || 0);
35030
35183
  return range2;
35031
35184
  };
35185
+ const clearReusedRange = function() {
35186
+ reusedRange = null;
35187
+ };
35032
35188
  const isEquivalentPosition = function(node, off2, targetNode, targetOff) {
35033
35189
  return targetNode && (scanFor(node, off2, targetNode, targetOff, -1) || scanFor(node, off2, targetNode, targetOff, 1));
35034
35190
  };
@@ -35056,6 +35212,40 @@ function scanFor(node, off2, targetNode, targetOff, dir) {
35056
35212
  function nodeSize(node) {
35057
35213
  return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length;
35058
35214
  }
35215
+ function textNodeBefore$1(node, offset2) {
35216
+ for (; ; ) {
35217
+ if (node.nodeType == 3 && offset2)
35218
+ return node;
35219
+ if (node.nodeType == 1 && offset2 > 0) {
35220
+ if (node.contentEditable == "false")
35221
+ return null;
35222
+ node = node.childNodes[offset2 - 1];
35223
+ offset2 = nodeSize(node);
35224
+ } else if (node.parentNode && !hasBlockDesc(node)) {
35225
+ offset2 = domIndex(node);
35226
+ node = node.parentNode;
35227
+ } else {
35228
+ return null;
35229
+ }
35230
+ }
35231
+ }
35232
+ function textNodeAfter$1(node, offset2) {
35233
+ for (; ; ) {
35234
+ if (node.nodeType == 3 && offset2 < node.nodeValue.length)
35235
+ return node;
35236
+ if (node.nodeType == 1 && offset2 < node.childNodes.length) {
35237
+ if (node.contentEditable == "false")
35238
+ return null;
35239
+ node = node.childNodes[offset2];
35240
+ offset2 = 0;
35241
+ } else if (node.parentNode && !hasBlockDesc(node)) {
35242
+ offset2 = domIndex(node) + 1;
35243
+ node = node.parentNode;
35244
+ } else {
35245
+ return null;
35246
+ }
35247
+ }
35248
+ }
35059
35249
  function isOnEdge(node, offset2, parent) {
35060
35250
  for (let atStart = offset2 == 0, atEnd = offset2 == nodeSize(node); atStart || atEnd; ) {
35061
35251
  if (node == parent)
@@ -35127,6 +35317,14 @@ const android = /Android \d/.test(agent);
35127
35317
  const webkit = !!doc && "webkitFontSmoothing" in doc.documentElement.style;
35128
35318
  const webkit_version = webkit ? +(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent) || [0, 0])[1] : 0;
35129
35319
  function windowRect(doc2) {
35320
+ let vp = doc2.defaultView && doc2.defaultView.visualViewport;
35321
+ if (vp)
35322
+ return {
35323
+ left: 0,
35324
+ right: vp.width,
35325
+ top: 0,
35326
+ bottom: vp.height
35327
+ };
35130
35328
  return {
35131
35329
  left: 0,
35132
35330
  right: doc2.documentElement.clientWidth,
@@ -35328,14 +35526,14 @@ function posFromCaret(view, node, offset2, coords) {
35328
35526
  let desc = view.docView.nearestDesc(cur, true);
35329
35527
  if (!desc)
35330
35528
  return null;
35331
- if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent && !sawBlock || !desc.contentDOM)) {
35529
+ if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent || !desc.contentDOM)) {
35332
35530
  let rect = desc.dom.getBoundingClientRect();
35333
- if (desc.node.isBlock && desc.parent && !sawBlock) {
35334
- sawBlock = true;
35335
- if (rect.left > coords.left || rect.top > coords.top)
35531
+ if (desc.node.isBlock && desc.parent) {
35532
+ if (!sawBlock && rect.left > coords.left || rect.top > coords.top)
35336
35533
  outsideBlock = desc.posBefore;
35337
- else if (rect.right < coords.left || rect.bottom < coords.top)
35534
+ else if (!sawBlock && rect.right < coords.left || rect.bottom < coords.top)
35338
35535
  outsideBlock = desc.posAfter;
35536
+ sawBlock = true;
35339
35537
  }
35340
35538
  if (!desc.contentDOM && outsideBlock < 0 && !desc.node.isText) {
35341
35539
  let before = desc.node.isBlock ? coords.top < (rect.top + rect.bottom) / 2 : coords.left < (rect.left + rect.right) / 2;
@@ -35950,6 +36148,9 @@ class ViewDesc {
35950
36148
  get ignoreForCoords() {
35951
36149
  return false;
35952
36150
  }
36151
+ isText(text) {
36152
+ return false;
36153
+ }
35953
36154
  }
35954
36155
  class WidgetViewDesc extends ViewDesc {
35955
36156
  constructor(parent, widget, view, pos) {
@@ -36188,8 +36389,7 @@ class NodeViewDesc extends ViewDesc {
36188
36389
  let { from: from2, to: to2 } = view.state.selection;
36189
36390
  if (!(view.state.selection instanceof TextSelection) || from2 < pos || to2 > pos + this.node.content.size)
36190
36391
  return null;
36191
- let sel = view.domSelectionRange();
36192
- let textNode = nearbyTextNode(sel.focusNode, sel.focusOffset);
36392
+ let textNode = view.input.compositionNode;
36193
36393
  if (!textNode || !this.dom.contains(textNode.parentNode))
36194
36394
  return null;
36195
36395
  if (this.node.inlineContent) {
@@ -36255,10 +36455,11 @@ class NodeViewDesc extends ViewDesc {
36255
36455
  }
36256
36456
  // Remove selected node marking from this node.
36257
36457
  deselectNode() {
36258
- if (this.nodeDOM.nodeType == 1)
36458
+ if (this.nodeDOM.nodeType == 1) {
36259
36459
  this.nodeDOM.classList.remove("ProseMirror-selectednode");
36260
- if (this.contentDOM || !this.node.type.spec.draggable)
36261
- this.dom.removeAttribute("draggable");
36460
+ if (this.contentDOM || !this.node.type.spec.draggable)
36461
+ this.dom.removeAttribute("draggable");
36462
+ }
36262
36463
  }
36263
36464
  get domAtom() {
36264
36465
  return this.node.isAtom;
@@ -36324,6 +36525,9 @@ class TextViewDesc extends NodeViewDesc {
36324
36525
  get domAtom() {
36325
36526
  return false;
36326
36527
  }
36528
+ isText(text) {
36529
+ return this.node.text == text;
36530
+ }
36327
36531
  }
36328
36532
  class TrailingHackViewDesc extends ViewDesc {
36329
36533
  parseRule() {
@@ -36839,23 +37043,6 @@ function iosHacks(dom) {
36839
37043
  dom.style.cssText = oldCSS;
36840
37044
  }
36841
37045
  }
36842
- function nearbyTextNode(node, offset2) {
36843
- for (; ; ) {
36844
- if (node.nodeType == 3)
36845
- return node;
36846
- if (node.nodeType == 1 && offset2 > 0) {
36847
- if (node.childNodes.length > offset2 && node.childNodes[offset2].nodeType == 3)
36848
- return node.childNodes[offset2];
36849
- node = node.childNodes[offset2 - 1];
36850
- offset2 = nodeSize(node);
36851
- } else if (node.nodeType == 1 && offset2 < node.childNodes.length) {
36852
- node = node.childNodes[offset2];
36853
- offset2 = 0;
36854
- } else {
36855
- return null;
36856
- }
36857
- }
36858
- }
36859
37046
  function findTextInFragment(frag, text, from2, to2) {
36860
37047
  for (let i2 = 0, pos = 0; i2 < frag.childCount && pos <= to2; ) {
36861
37048
  let child = frag.child(i2++), childStart = pos;
@@ -37430,7 +37617,7 @@ function serializeForClipboard(view, slice4) {
37430
37617
  if (firstChild && firstChild.nodeType == 1)
37431
37618
  firstChild.setAttribute("data-pm-slice", `${openStart} ${openEnd}${wrappers ? ` -${wrappers}` : ""} ${JSON.stringify(context)}`);
37432
37619
  let text = view.someProp("clipboardTextSerializer", (f2) => f2(slice4, view)) || slice4.content.textBetween(0, slice4.content.size, "\n\n");
37433
- return { dom: wrap2, text };
37620
+ return { dom: wrap2, text, slice: slice4 };
37434
37621
  }
37435
37622
  function parseFromClipboard(view, text, html, plainText, $context) {
37436
37623
  let inCode = $context.parent.type.spec.code;
@@ -37650,6 +37837,7 @@ class InputState {
37650
37837
  this.lastTouch = 0;
37651
37838
  this.lastAndroidDelete = 0;
37652
37839
  this.composing = false;
37840
+ this.compositionNode = null;
37653
37841
  this.composingTimeout = -1;
37654
37842
  this.compositionNodes = [];
37655
37843
  this.compositionEndedAt = -2e8;
@@ -37899,7 +38087,7 @@ class MouseDown {
37899
38087
  }
37900
38088
  const target = flushed ? null : event.target;
37901
38089
  const targetDesc = target ? view.docView.nearestDesc(target, true) : null;
37902
- this.target = targetDesc ? targetDesc.dom : null;
38090
+ this.target = targetDesc && targetDesc.dom.nodeType == 1 ? targetDesc.dom : null;
37903
38091
  let { selection } = view.state;
37904
38092
  if (event.button == 0 && targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false || selection instanceof NodeSelection && selection.from <= targetPos && selection.to > targetPos)
37905
38093
  this.mightDrag = {
@@ -38031,6 +38219,7 @@ editHandlers.compositionend = (view, event) => {
38031
38219
  view.input.composing = false;
38032
38220
  view.input.compositionEndedAt = event.timeStamp;
38033
38221
  view.input.compositionPendingChanges = view.domObserver.pendingRecords().length ? view.input.compositionID : 0;
38222
+ view.input.compositionNode = null;
38034
38223
  if (view.input.compositionPendingChanges)
38035
38224
  Promise.resolve().then(() => view.domObserver.flush());
38036
38225
  view.input.compositionID++;
@@ -38050,6 +38239,26 @@ function clearComposition(view) {
38050
38239
  while (view.input.compositionNodes.length > 0)
38051
38240
  view.input.compositionNodes.pop().markParentsDirty();
38052
38241
  }
38242
+ function findCompositionNode(view) {
38243
+ let sel = view.domSelectionRange();
38244
+ if (!sel.focusNode)
38245
+ return null;
38246
+ let textBefore = textNodeBefore$1(sel.focusNode, sel.focusOffset);
38247
+ let textAfter = textNodeAfter$1(sel.focusNode, sel.focusOffset);
38248
+ if (textBefore && textAfter && textBefore != textAfter) {
38249
+ let descAfter = textAfter.pmViewDesc, lastChanged = view.domObserver.lastChangedTextNode;
38250
+ if (textBefore == lastChanged || textAfter == lastChanged)
38251
+ return lastChanged;
38252
+ if (!descAfter || !descAfter.isText(textAfter.nodeValue)) {
38253
+ return textAfter;
38254
+ } else if (view.input.compositionNode == textAfter) {
38255
+ let descBefore = textBefore.pmViewDesc;
38256
+ if (!(!descBefore || !descBefore.isText(textBefore.nodeValue)))
38257
+ return textAfter;
38258
+ }
38259
+ }
38260
+ return textBefore || textAfter;
38261
+ }
38053
38262
  function timestampFromCustomEvent() {
38054
38263
  let event = document.createEvent("Event");
38055
38264
  event.initEvent("event", true, true);
@@ -38184,7 +38393,8 @@ handlers.dragstart = (view, _event) => {
38184
38393
  if (desc && desc.node.type.spec.draggable && desc != view.docView)
38185
38394
  node = NodeSelection.create(view.state.doc, desc.posBefore);
38186
38395
  }
38187
- let slice4 = (node || view.state.selection).content(), { dom, text } = serializeForClipboard(view, slice4);
38396
+ let draggedSlice = (node || view.state.selection).content();
38397
+ let { dom, text, slice: slice4 } = serializeForClipboard(view, draggedSlice);
38188
38398
  event.dataTransfer.clearData();
38189
38399
  event.dataTransfer.setData(brokenClipboardAPI ? "Text" : "text/html", dom.innerHTML);
38190
38400
  event.dataTransfer.effectAllowed = "copyMove";
@@ -38604,9 +38814,6 @@ class DecorationSet {
38604
38814
  return this;
38605
38815
  return local.length || children2.length ? new DecorationSet(local, children2) : empty$1;
38606
38816
  }
38607
- /**
38608
- @internal
38609
- */
38610
38817
  forChild(offset2, node) {
38611
38818
  if (this == empty$1)
38612
38819
  return this;
@@ -38960,6 +39167,7 @@ class DOMObserver {
38960
39167
  this.currentSelection = new SelectionState();
38961
39168
  this.onCharData = null;
38962
39169
  this.suppressingSelectionUpdates = false;
39170
+ this.lastChangedTextNode = null;
38963
39171
  this.observer = window.MutationObserver && new window.MutationObserver((mutations) => {
38964
39172
  for (let i2 = 0; i2 < mutations.length; i2++)
38965
39173
  this.queue.push(mutations[i2]);
@@ -39085,14 +39293,21 @@ class DOMObserver {
39085
39293
  }
39086
39294
  }
39087
39295
  }
39088
- if (gecko && added.length > 1) {
39296
+ if (gecko && added.length) {
39089
39297
  let brs = added.filter((n2) => n2.nodeName == "BR");
39090
39298
  if (brs.length == 2) {
39091
- let a2 = brs[0], b2 = brs[1];
39299
+ let [a2, b2] = brs;
39092
39300
  if (a2.parentNode && a2.parentNode.parentNode == b2.parentNode)
39093
39301
  b2.remove();
39094
39302
  else
39095
39303
  a2.remove();
39304
+ } else {
39305
+ let { focusNode } = this.currentSelection;
39306
+ for (let br2 of brs) {
39307
+ let parent = br2.parentNode;
39308
+ if (parent && parent.nodeName == "LI" && (!focusNode || blockParent(view, focusNode) != parent))
39309
+ br2.remove();
39310
+ }
39096
39311
  }
39097
39312
  }
39098
39313
  let readSel = null;
@@ -39124,8 +39339,12 @@ class DOMObserver {
39124
39339
  if (!desc || desc.ignoreMutation(mut))
39125
39340
  return null;
39126
39341
  if (mut.type == "childList") {
39127
- for (let i2 = 0; i2 < mut.addedNodes.length; i2++)
39128
- added.push(mut.addedNodes[i2]);
39342
+ for (let i2 = 0; i2 < mut.addedNodes.length; i2++) {
39343
+ let node = mut.addedNodes[i2];
39344
+ added.push(node);
39345
+ if (node.nodeType == 3)
39346
+ this.lastChangedTextNode = node;
39347
+ }
39129
39348
  if (desc.contentDOM && desc.contentDOM != desc.dom && !desc.contentDOM.contains(mut.target))
39130
39349
  return { from: desc.posBefore, to: desc.posAfter };
39131
39350
  let prev = mut.previousSibling, next = mut.nextSibling;
@@ -39146,6 +39365,7 @@ class DOMObserver {
39146
39365
  } else if (mut.type == "attributes") {
39147
39366
  return { from: desc.posAtStart - desc.border, to: desc.posAtEnd + desc.border };
39148
39367
  } else {
39368
+ this.lastChangedTextNode = mut.target;
39149
39369
  return {
39150
39370
  from: desc.posAtStart,
39151
39371
  to: desc.posAtEnd,
@@ -39172,7 +39392,20 @@ function checkCSS(view) {
39172
39392
  cssCheckWarned = true;
39173
39393
  }
39174
39394
  }
39175
- function safariShadowSelectionRange(view) {
39395
+ function rangeToSelectionRange(view, range2) {
39396
+ let anchorNode = range2.startContainer, anchorOffset = range2.startOffset;
39397
+ let focusNode = range2.endContainer, focusOffset = range2.endOffset;
39398
+ let currentAnchor = view.domAtPos(view.state.selection.anchor);
39399
+ if (isEquivalentPosition(currentAnchor.node, currentAnchor.offset, focusNode, focusOffset))
39400
+ [anchorNode, anchorOffset, focusNode, focusOffset] = [focusNode, focusOffset, anchorNode, anchorOffset];
39401
+ return { anchorNode, anchorOffset, focusNode, focusOffset };
39402
+ }
39403
+ function safariShadowSelectionRange(view, selection) {
39404
+ if (selection.getComposedRanges) {
39405
+ let range2 = selection.getComposedRanges(view.root)[0];
39406
+ if (range2)
39407
+ return rangeToSelectionRange(view, range2);
39408
+ }
39176
39409
  let found2;
39177
39410
  function read2(event) {
39178
39411
  event.preventDefault();
@@ -39182,12 +39415,15 @@ function safariShadowSelectionRange(view) {
39182
39415
  view.dom.addEventListener("beforeinput", read2, true);
39183
39416
  document.execCommand("indent");
39184
39417
  view.dom.removeEventListener("beforeinput", read2, true);
39185
- let anchorNode = found2.startContainer, anchorOffset = found2.startOffset;
39186
- let focusNode = found2.endContainer, focusOffset = found2.endOffset;
39187
- let currentAnchor = view.domAtPos(view.state.selection.anchor);
39188
- if (isEquivalentPosition(currentAnchor.node, currentAnchor.offset, focusNode, focusOffset))
39189
- [anchorNode, anchorOffset, focusNode, focusOffset] = [focusNode, focusOffset, anchorNode, anchorOffset];
39190
- return { anchorNode, anchorOffset, focusNode, focusOffset };
39418
+ return found2 ? rangeToSelectionRange(view, found2) : null;
39419
+ }
39420
+ function blockParent(view, node) {
39421
+ for (let p2 = node.parentNode; p2 && p2 != view.dom; p2 = p2.parentNode) {
39422
+ let desc = view.docView.nearestDesc(p2, true);
39423
+ if (desc && desc.node.isBlock)
39424
+ return p2;
39425
+ }
39426
+ return null;
39191
39427
  }
39192
39428
  function parseBetween(view, from_, to_) {
39193
39429
  let { node: parent, fromOffset, toOffset, from: from2, to: to2 } = view.docView.parseRange(from_, to_);
@@ -39307,10 +39543,6 @@ function readDOMChange(view, from2, to2, typeOver, addedNodes) {
39307
39543
  return;
39308
39544
  }
39309
39545
  }
39310
- if (chrome && view.cursorWrapper && parse2.sel && parse2.sel.anchor == view.cursorWrapper.deco.from && parse2.sel.head == parse2.sel.anchor) {
39311
- let size2 = change.endB - change.start;
39312
- parse2.sel = { anchor: parse2.sel.anchor + size2, head: parse2.sel.anchor + size2 };
39313
- }
39314
39546
  view.input.domChangeCount++;
39315
39547
  if (view.state.selection.from < view.state.selection.to && change.start == change.endB && view.state.selection instanceof TextSelection) {
39316
39548
  if (change.start > view.state.selection.from && change.start <= view.state.selection.from + 2 && view.state.selection.from >= parse2.from) {
@@ -39334,7 +39566,7 @@ function readDOMChange(view, from2, to2, typeOver, addedNodes) {
39334
39566
  view.input.lastIOSEnter = 0;
39335
39567
  return;
39336
39568
  }
39337
- if (view.state.selection.anchor > change.start && looksLikeJoin(doc2, change.start, change.endA, $from, $to) && view.someProp("handleKeyDown", (f2) => f2(view, keyEvent(8, "Backspace")))) {
39569
+ if (view.state.selection.anchor > change.start && looksLikeBackspace(doc2, change.start, change.endA, $from, $to) && view.someProp("handleKeyDown", (f2) => f2(view, keyEvent(8, "Backspace")))) {
39338
39570
  if (android && chrome)
39339
39571
  view.domObserver.suppressSelectionUpdates();
39340
39572
  return;
@@ -39418,12 +39650,18 @@ function isMarkChange(cur, prev) {
39418
39650
  if (Fragment.from(updated).eq(cur))
39419
39651
  return { mark, type: type3 };
39420
39652
  }
39421
- function looksLikeJoin(old, start2, end2, $newStart, $newEnd) {
39422
- if (!$newStart.parent.isTextblock || // The content must have shrunk
39423
- end2 - start2 <= $newEnd.pos - $newStart.pos || // newEnd must point directly at or after the end of the block that newStart points into
39424
- skipClosingAndOpening($newStart, true, false) < $newEnd.pos)
39653
+ function looksLikeBackspace(old, start2, end2, $newStart, $newEnd) {
39654
+ if (
39655
+ // The content must have shrunk
39656
+ end2 - start2 <= $newEnd.pos - $newStart.pos || // newEnd must point directly at or after the end of the block that newStart points into
39657
+ skipClosingAndOpening($newStart, true, false) < $newEnd.pos
39658
+ )
39425
39659
  return false;
39426
39660
  let $start = old.resolve(start2);
39661
+ if (!$newStart.parent.isTextblock) {
39662
+ let after = $start.nodeAfter;
39663
+ return after != null && end2 == start2 + after.nodeSize;
39664
+ }
39427
39665
  if ($start.parentOffset < $start.parent.content.size || !$start.parent.isTextblock)
39428
39666
  return false;
39429
39667
  let $next = old.resolve(skipClosingAndOpening($start, true, true));
@@ -39612,8 +39850,10 @@ class EditorView {
39612
39850
  let forceSelUpdate = updateDoc && (ie$1 || chrome) && !this.composing && !prev.selection.empty && !state2.selection.empty && selectionContextChanged(prev.selection, state2.selection);
39613
39851
  if (updateDoc) {
39614
39852
  let chromeKludge = chrome ? this.trackWrites = this.domSelectionRange().focusNode : null;
39853
+ if (this.composing)
39854
+ this.input.compositionNode = findCompositionNode(this);
39615
39855
  if (redraw || !this.docView.update(state2.doc, outerDeco, innerDeco, this)) {
39616
- this.docView.updateOuterDeco([]);
39856
+ this.docView.updateOuterDeco(outerDeco);
39617
39857
  this.docView.destroy();
39618
39858
  this.docView = docViewDesc(state2.doc, outerDeco, innerDeco, this.dom, this);
39619
39859
  }
@@ -39872,6 +40112,7 @@ class EditorView {
39872
40112
  }
39873
40113
  this.docView.destroy();
39874
40114
  this.docView = null;
40115
+ clearReusedRange();
39875
40116
  }
39876
40117
  /**
39877
40118
  This is true when the view has been
@@ -39907,7 +40148,8 @@ class EditorView {
39907
40148
  @internal
39908
40149
  */
39909
40150
  domSelectionRange() {
39910
- return safari && this.root.nodeType === 11 && deepActiveElement(this.dom.ownerDocument) == this.dom ? safariShadowSelectionRange(this) : this.domSelection();
40151
+ let sel = this.domSelection();
40152
+ return safari && this.root.nodeType === 11 && deepActiveElement(this.dom.ownerDocument) == this.dom && safariShadowSelectionRange(this, sel) || sel;
39911
40153
  }
39912
40154
  /**
39913
40155
  @internal
@@ -40898,7 +41140,8 @@ function getAttributesFromExtensions(extensions) {
40898
41140
  const context = {
40899
41141
  name: extension.name,
40900
41142
  options: extension.options,
40901
- storage: extension.storage
41143
+ storage: extension.storage,
41144
+ extensions: nodeAndMarkExtensions
40902
41145
  };
40903
41146
  const addGlobalAttributes = getExtensionField(extension, "addGlobalAttributes", context);
40904
41147
  if (!addGlobalAttributes) {
@@ -41024,7 +41267,7 @@ function fromString(value) {
41024
41267
  return value;
41025
41268
  }
41026
41269
  function injectExtensionAttributesToParseRule(parseRule, extensionAttributes) {
41027
- if (parseRule.style) {
41270
+ if ("style" in parseRule) {
41028
41271
  return parseRule;
41029
41272
  }
41030
41273
  return {
@@ -41089,6 +41332,7 @@ function getSchemaByResolvedExtensions(extensions, editor) {
41089
41332
  selectable: callOrReturn(getExtensionField(extension, "selectable", context)),
41090
41333
  draggable: callOrReturn(getExtensionField(extension, "draggable", context)),
41091
41334
  code: callOrReturn(getExtensionField(extension, "code", context)),
41335
+ whitespace: callOrReturn(getExtensionField(extension, "whitespace", context)),
41092
41336
  defining: callOrReturn(getExtensionField(extension, "defining", context)),
41093
41337
  isolating: callOrReturn(getExtensionField(extension, "isolating", context)),
41094
41338
  attrs: Object.fromEntries(extensionAttributes.map((extensionAttribute) => {
@@ -41644,7 +41888,7 @@ class ExtensionManager {
41644
41888
  const plugins2 = [];
41645
41889
  const addKeyboardShortcuts = getExtensionField(extension, "addKeyboardShortcuts", context);
41646
41890
  let defaultBindings = {};
41647
- if (extension.type === "mark" && extension.config.exitable) {
41891
+ if (extension.type === "mark" && getExtensionField(extension, "exitable", context)) {
41648
41892
  defaultBindings.ArrowRight = () => Mark.handleExit({ editor, mark: extension });
41649
41893
  }
41650
41894
  if (addKeyboardShortcuts) {
@@ -41792,14 +42036,10 @@ function mergeDeep(target, source) {
41792
42036
  const output = { ...target };
41793
42037
  if (isPlainObject(target) && isPlainObject(source)) {
41794
42038
  Object.keys(source).forEach((key) => {
41795
- if (isPlainObject(source[key])) {
41796
- if (!(key in target)) {
41797
- Object.assign(output, { [key]: source[key] });
41798
- } else {
41799
- output[key] = mergeDeep(target[key], source[key]);
41800
- }
42039
+ if (isPlainObject(source[key]) && isPlainObject(target[key])) {
42040
+ output[key] = mergeDeep(target[key], source[key]);
41801
42041
  } else {
41802
- Object.assign(output, { [key]: source[key] });
42042
+ output[key] = source[key];
41803
42043
  }
41804
42044
  });
41805
42045
  }
@@ -41838,13 +42078,15 @@ class Extension {
41838
42078
  return new Extension(config);
41839
42079
  }
41840
42080
  configure(options = {}) {
41841
- const extension = this.extend();
42081
+ const extension = this.extend({
42082
+ ...this.config,
42083
+ addOptions() {
42084
+ var _a2;
42085
+ return mergeDeep(((_a2 = this.parent) === null || _a2 === void 0 ? void 0 : _a2.call(this)) || {}, options);
42086
+ }
42087
+ });
42088
+ extension.name = this.name;
41842
42089
  extension.parent = this.parent;
41843
- extension.options = mergeDeep(this.options, options);
41844
- extension.storage = callOrReturn(getExtensionField(extension, "addStorage", {
41845
- name: extension.name,
41846
- options: extension.options
41847
- }));
41848
42090
  return extension;
41849
42091
  }
41850
42092
  extend(extendedConfig = {}) {
@@ -41852,7 +42094,7 @@ class Extension {
41852
42094
  extension.parent = this;
41853
42095
  this.child = extension;
41854
42096
  extension.name = extendedConfig.name ? extendedConfig.name : extension.parent.name;
41855
- if (extendedConfig.defaultOptions) {
42097
+ if (extendedConfig.defaultOptions && Object.keys(extendedConfig.defaultOptions).length > 0) {
41856
42098
  console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`);
41857
42099
  }
41858
42100
  extension.options = callOrReturn(getExtensionField(extension, "addOptions", {
@@ -42236,13 +42478,47 @@ function createNodeFromContent(content, schema, options) {
42236
42478
  }
42237
42479
  return schema.nodeFromJSON(content);
42238
42480
  } catch (error) {
42481
+ if (options.errorOnInvalidContent) {
42482
+ throw new Error("[tiptap error]: Invalid JSON content", { cause: error });
42483
+ }
42239
42484
  console.warn("[tiptap warn]: Invalid content.", "Passed value:", content, "Error:", error);
42240
42485
  return createNodeFromContent("", schema, options);
42241
42486
  }
42242
42487
  }
42243
42488
  if (isTextContent) {
42244
- const parser = DOMParser.fromSchema(schema);
42245
- return options.slice ? parser.parseSlice(elementFromString(content), options.parseOptions).content : parser.parse(elementFromString(content), options.parseOptions);
42489
+ let schemaToUse = schema;
42490
+ let hasInvalidContent = false;
42491
+ let invalidContent = "";
42492
+ if (options.errorOnInvalidContent) {
42493
+ schemaToUse = new Schema({
42494
+ topNode: schema.spec.topNode,
42495
+ marks: schema.spec.marks,
42496
+ // Prosemirror's schemas are executed such that: the last to execute, matches last
42497
+ // This means that we can add a catch-all node at the end of the schema to catch any content that we don't know how to handle
42498
+ nodes: schema.spec.nodes.append({
42499
+ __tiptap__private__unknown__catch__all__node: {
42500
+ content: "inline*",
42501
+ group: "block",
42502
+ parseDOM: [
42503
+ {
42504
+ tag: "*",
42505
+ getAttrs: (e) => {
42506
+ hasInvalidContent = true;
42507
+ invalidContent = typeof e === "string" ? e : e.outerHTML;
42508
+ return null;
42509
+ }
42510
+ }
42511
+ ]
42512
+ }
42513
+ })
42514
+ });
42515
+ }
42516
+ const parser = DOMParser.fromSchema(schemaToUse);
42517
+ const response = options.slice ? parser.parseSlice(elementFromString(content), options.parseOptions).content : parser.parse(elementFromString(content), options.parseOptions);
42518
+ if (options.errorOnInvalidContent && hasInvalidContent) {
42519
+ throw new Error("[tiptap error]: Invalid HTML content", { cause: new Error(`Invalid element found: ${invalidContent}`) });
42520
+ }
42521
+ return response;
42246
42522
  }
42247
42523
  return createNodeFromContent("", schema, options);
42248
42524
  }
@@ -42265,9 +42541,10 @@ function selectionToInsertionEnd(tr2, startLen, bias) {
42265
42541
  tr2.setSelection(Selection$1.near(tr2.doc.resolve(end2), bias));
42266
42542
  }
42267
42543
  const isFragment = (nodeOrFragment) => {
42268
- return nodeOrFragment.toString().startsWith("<");
42544
+ return !("type" in nodeOrFragment);
42269
42545
  };
42270
42546
  const insertContentAt = (position, value, options) => ({ tr: tr2, dispatch, editor }) => {
42547
+ var _a2;
42271
42548
  if (dispatch) {
42272
42549
  options = {
42273
42550
  parseOptions: {},
@@ -42276,14 +42553,17 @@ const insertContentAt = (position, value, options) => ({ tr: tr2, dispatch, edit
42276
42553
  applyPasteRules: false,
42277
42554
  ...options
42278
42555
  };
42279
- const content = createNodeFromContent(value, editor.schema, {
42280
- parseOptions: {
42281
- preserveWhitespace: "full",
42282
- ...options.parseOptions
42283
- }
42284
- });
42285
- if (content.toString() === "<>") {
42286
- return true;
42556
+ let content;
42557
+ try {
42558
+ content = createNodeFromContent(value, editor.schema, {
42559
+ parseOptions: {
42560
+ preserveWhitespace: "full",
42561
+ ...options.parseOptions
42562
+ },
42563
+ errorOnInvalidContent: (_a2 = options.errorOnInvalidContent) !== null && _a2 !== void 0 ? _a2 : editor.options.enableContentCheck
42564
+ });
42565
+ } catch (e) {
42566
+ return false;
42287
42567
  }
42288
42568
  let { from: from2, to: to2 } = typeof position === "number" ? { from: position, to: position } : { from: position.from, to: position.to };
42289
42569
  let isOnlyTextContent = true;
@@ -42340,7 +42620,7 @@ const joinBackward = () => ({ state: state2, dispatch }) => {
42340
42620
  const joinForward = () => ({ state: state2, dispatch }) => {
42341
42621
  return joinForward$1(state2, dispatch);
42342
42622
  };
42343
- const joinItemBackward = () => ({ tr: tr2, state: state2, dispatch }) => {
42623
+ const joinItemBackward = () => ({ state: state2, dispatch, tr: tr2 }) => {
42344
42624
  try {
42345
42625
  const point2 = joinPoint(state2.doc, state2.selection.$from.pos, -1);
42346
42626
  if (point2 === null || point2 === void 0) {
@@ -42351,7 +42631,7 @@ const joinItemBackward = () => ({ tr: tr2, state: state2, dispatch }) => {
42351
42631
  dispatch(tr2);
42352
42632
  }
42353
42633
  return true;
42354
- } catch {
42634
+ } catch (e) {
42355
42635
  return false;
42356
42636
  }
42357
42637
  };
@@ -42569,16 +42849,32 @@ const selectTextblockEnd = () => ({ state: state2, dispatch }) => {
42569
42849
  const selectTextblockStart = () => ({ state: state2, dispatch }) => {
42570
42850
  return selectTextblockStart$1(state2, dispatch);
42571
42851
  };
42572
- function createDocument(content, schema, parseOptions = {}) {
42573
- return createNodeFromContent(content, schema, { slice: false, parseOptions });
42852
+ function createDocument(content, schema, parseOptions = {}, options = {}) {
42853
+ return createNodeFromContent(content, schema, {
42854
+ slice: false,
42855
+ parseOptions,
42856
+ errorOnInvalidContent: options.errorOnInvalidContent
42857
+ });
42574
42858
  }
42575
- const setContent$1 = (content, emitUpdate = false, parseOptions = {}) => ({ tr: tr2, editor, dispatch }) => {
42859
+ const setContent$1 = (content, emitUpdate = false, parseOptions = {}, options = {}) => ({ editor, tr: tr2, dispatch, commands: commands2 }) => {
42860
+ var _a2, _b;
42576
42861
  const { doc: doc2 } = tr2;
42577
- const document2 = createDocument(content, editor.schema, parseOptions);
42862
+ if (parseOptions.preserveWhitespace !== "full") {
42863
+ const document2 = createDocument(content, editor.schema, parseOptions, {
42864
+ errorOnInvalidContent: (_a2 = options.errorOnInvalidContent) !== null && _a2 !== void 0 ? _a2 : editor.options.enableContentCheck
42865
+ });
42866
+ if (dispatch) {
42867
+ tr2.replaceWith(0, doc2.content.size, document2).setMeta("preventUpdate", !emitUpdate);
42868
+ }
42869
+ return true;
42870
+ }
42578
42871
  if (dispatch) {
42579
- tr2.replaceWith(0, doc2.content.size, document2).setMeta("preventUpdate", !emitUpdate);
42872
+ tr2.setMeta("preventUpdate", !emitUpdate);
42580
42873
  }
42581
- return true;
42874
+ return commands2.insertContentAt({ from: 0, to: doc2.content.size }, content, {
42875
+ parseOptions,
42876
+ errorOnInvalidContent: (_b = options.errorOnInvalidContent) !== null && _b !== void 0 ? _b : editor.options.enableContentCheck
42877
+ });
42582
42878
  };
42583
42879
  function getMarkAttributes(state2, typeOrName) {
42584
42880
  const type3 = getMarkType(typeOrName, state2.schema);
@@ -42781,10 +43077,11 @@ function isList(name, extensions) {
42781
43077
  return group.split(" ").includes("list");
42782
43078
  }
42783
43079
  function isNodeEmpty(node) {
42784
- var _a2;
42785
- const defaultContent = (_a2 = node.type.createAndFill()) === null || _a2 === void 0 ? void 0 : _a2.toJSON();
42786
- const content = node.toJSON();
42787
- return JSON.stringify(defaultContent) === JSON.stringify(content);
43080
+ const defaultContent = node.type.createAndFill();
43081
+ if (!defaultContent) {
43082
+ return false;
43083
+ }
43084
+ return node.eq(defaultContent);
42788
43085
  }
42789
43086
  function isNodeSelection(value) {
42790
43087
  return value instanceof NodeSelection;
@@ -43299,14 +43596,14 @@ var commands = /* @__PURE__ */ Object.freeze({
43299
43596
  forEach,
43300
43597
  insertContent,
43301
43598
  insertContentAt,
43302
- joinUp,
43303
- joinDown,
43304
43599
  joinBackward,
43600
+ joinDown,
43305
43601
  joinForward,
43306
43602
  joinItemBackward,
43307
43603
  joinItemForward,
43308
43604
  joinTextblockBackward,
43309
43605
  joinTextblockForward,
43606
+ joinUp,
43310
43607
  keyboardShortcut,
43311
43608
  lift,
43312
43609
  liftEmptyBlock,
@@ -43503,13 +43800,16 @@ const Tabindex = Extension.create({
43503
43800
  new Plugin({
43504
43801
  key: new PluginKey("tabindex"),
43505
43802
  props: {
43506
- attributes: this.editor.isEditable ? { tabindex: "0" } : {}
43803
+ attributes: () => this.editor.isEditable ? { tabindex: "0" } : {}
43507
43804
  }
43508
43805
  })
43509
43806
  ];
43510
43807
  }
43511
43808
  });
43512
43809
  class NodePos {
43810
+ get name() {
43811
+ return this.node.type.name;
43812
+ }
43513
43813
  constructor(pos, editor, isBlock = false, node = null) {
43514
43814
  this.currentNode = null;
43515
43815
  this.actualDepth = null;
@@ -43518,9 +43818,6 @@ class NodePos {
43518
43818
  this.editor = editor;
43519
43819
  this.currentNode = node;
43520
43820
  }
43521
- get name() {
43522
- return this.node.type.name;
43523
- }
43524
43821
  get node() {
43525
43822
  return this.currentNode || this.resolvedPos.node();
43526
43823
  }
@@ -43784,6 +44081,7 @@ let Editor$1 = class Editor2 extends EventEmitter {
43784
44081
  enableInputRules: true,
43785
44082
  enablePasteRules: true,
43786
44083
  enableCoreExtensions: true,
44084
+ enableContentCheck: false,
43787
44085
  onBeforeCreate: () => null,
43788
44086
  onCreate: () => null,
43789
44087
  onUpdate: () => null,
@@ -43791,7 +44089,10 @@ let Editor$1 = class Editor2 extends EventEmitter {
43791
44089
  onTransaction: () => null,
43792
44090
  onFocus: () => null,
43793
44091
  onBlur: () => null,
43794
- onDestroy: () => null
44092
+ onDestroy: () => null,
44093
+ onContentError: ({ error }) => {
44094
+ throw error;
44095
+ }
43795
44096
  };
43796
44097
  this.isCapturingTransaction = false;
43797
44098
  this.capturedTransaction = null;
@@ -43801,6 +44102,7 @@ let Editor$1 = class Editor2 extends EventEmitter {
43801
44102
  this.createSchema();
43802
44103
  this.on("beforeCreate", this.options.onBeforeCreate);
43803
44104
  this.emit("beforeCreate", { editor: this });
44105
+ this.on("contentError", this.options.onContentError);
43804
44106
  this.createView();
43805
44107
  this.injectCSS();
43806
44108
  this.on("create", this.options.onCreate);
@@ -43954,7 +44256,23 @@ let Editor$1 = class Editor2 extends EventEmitter {
43954
44256
  * Creates a ProseMirror view.
43955
44257
  */
43956
44258
  createView() {
43957
- const doc2 = createDocument(this.options.content, this.schema, this.options.parseOptions);
44259
+ let doc2;
44260
+ try {
44261
+ doc2 = createDocument(this.options.content, this.schema, this.options.parseOptions, { errorOnInvalidContent: this.options.enableContentCheck });
44262
+ } catch (e) {
44263
+ if (!(e instanceof Error) || !["[tiptap error]: Invalid JSON content", "[tiptap error]: Invalid HTML content"].includes(e.message)) {
44264
+ throw e;
44265
+ }
44266
+ this.emit("contentError", {
44267
+ editor: this,
44268
+ error: e,
44269
+ disableCollaboration: () => {
44270
+ this.options.extensions = this.options.extensions.filter((extension) => extension.name !== "collaboration");
44271
+ this.createExtensionManager();
44272
+ }
44273
+ });
44274
+ doc2 = createDocument(this.options.content, this.schema, this.options.parseOptions, { errorOnInvalidContent: false });
44275
+ }
43958
44276
  const selection = resolveFocusPosition(doc2, this.options.autofocus);
43959
44277
  this.view = new EditorView(this.options.element, {
43960
44278
  ...this.options.editorProps,
@@ -44192,7 +44510,8 @@ function nodeInputRule(config) {
44192
44510
  tr2.insertText(lastChar, start2 + match2[0].length - 1);
44193
44511
  tr2.replaceWith(matchStart, end2, newNode);
44194
44512
  } else if (match2[0]) {
44195
- tr2.insert(start2 - 1, config.type.create(attributes)).delete(tr2.mapping.map(start2), tr2.mapping.map(end2));
44513
+ const insertionStart = config.type.isInline ? start2 : start2 - 1;
44514
+ tr2.insert(insertionStart, config.type.create(attributes)).delete(tr2.mapping.map(start2), tr2.mapping.map(end2));
44196
44515
  }
44197
44516
  tr2.scrollIntoView();
44198
44517
  }
@@ -44277,20 +44596,23 @@ class Mark {
44277
44596
  return new Mark(config);
44278
44597
  }
44279
44598
  configure(options = {}) {
44280
- const extension = this.extend();
44281
- extension.options = mergeDeep(this.options, options);
44282
- extension.storage = callOrReturn(getExtensionField(extension, "addStorage", {
44283
- name: extension.name,
44284
- options: extension.options
44285
- }));
44599
+ const extension = this.extend({
44600
+ ...this.config,
44601
+ addOptions() {
44602
+ var _a2;
44603
+ return mergeDeep(((_a2 = this.parent) === null || _a2 === void 0 ? void 0 : _a2.call(this)) || {}, options);
44604
+ }
44605
+ });
44606
+ extension.name = this.name;
44607
+ extension.parent = this.parent;
44286
44608
  return extension;
44287
44609
  }
44288
44610
  extend(extendedConfig = {}) {
44289
- const extension = new Mark({ ...this.config, ...extendedConfig });
44611
+ const extension = new Mark(extendedConfig);
44290
44612
  extension.parent = this;
44291
44613
  this.child = extension;
44292
44614
  extension.name = extendedConfig.name ? extendedConfig.name : extension.parent.name;
44293
- if (extendedConfig.defaultOptions) {
44615
+ if (extendedConfig.defaultOptions && Object.keys(extendedConfig.defaultOptions).length > 0) {
44294
44616
  console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`);
44295
44617
  }
44296
44618
  extension.options = callOrReturn(getExtensionField(extension, "addOptions", {
@@ -44356,20 +44678,23 @@ let Node$2 = class Node3 {
44356
44678
  return new Node3(config);
44357
44679
  }
44358
44680
  configure(options = {}) {
44359
- const extension = this.extend();
44360
- extension.options = mergeDeep(this.options, options);
44361
- extension.storage = callOrReturn(getExtensionField(extension, "addStorage", {
44362
- name: extension.name,
44363
- options: extension.options
44364
- }));
44681
+ const extension = this.extend({
44682
+ ...this.config,
44683
+ addOptions() {
44684
+ var _a2;
44685
+ return mergeDeep(((_a2 = this.parent) === null || _a2 === void 0 ? void 0 : _a2.call(this)) || {}, options);
44686
+ }
44687
+ });
44688
+ extension.name = this.name;
44689
+ extension.parent = this.parent;
44365
44690
  return extension;
44366
44691
  }
44367
44692
  extend(extendedConfig = {}) {
44368
- const extension = new Node3({ ...this.config, ...extendedConfig });
44693
+ const extension = new Node3(extendedConfig);
44369
44694
  extension.parent = this;
44370
44695
  this.child = extension;
44371
44696
  extension.name = extendedConfig.name ? extendedConfig.name : extension.parent.name;
44372
- if (extendedConfig.defaultOptions) {
44697
+ if (extendedConfig.defaultOptions && Object.keys(extendedConfig.defaultOptions).length > 0) {
44373
44698
  console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`);
44374
44699
  }
44375
44700
  extension.options = callOrReturn(getExtensionField(extension, "addOptions", {
@@ -44904,14 +45229,12 @@ const CodeBlock = Node$2.create({
44904
45229
  if (!text || !language) {
44905
45230
  return false;
44906
45231
  }
44907
- const { tr: tr2 } = view.state;
44908
- if (view.state.selection.from === view.state.doc.nodeSize - (1 + view.state.selection.$to.depth * 2)) {
44909
- tr2.insert(view.state.selection.from - 1, this.type.create({ language }));
44910
- } else {
44911
- tr2.replaceSelectionWith(this.type.create({ language }));
45232
+ const { tr: tr2, schema } = view.state;
45233
+ const textNode = schema.text(text.replace(/\r\n?/g, "\n"));
45234
+ tr2.replaceSelectionWith(this.type.create({ language }, textNode));
45235
+ if (tr2.selection.$from.parent.type !== this.type) {
45236
+ tr2.setSelection(TextSelection.near(tr2.doc.resolve(Math.max(0, tr2.selection.from - 2))));
44912
45237
  }
44913
- tr2.setSelection(TextSelection.near(tr2.doc.resolve(Math.max(0, tr2.selection.from - 2))));
44914
- tr2.insertText(text.replace(/\r\n?/g, "\n"));
44915
45238
  tr2.setMeta("paste", true);
44916
45239
  view.dispatch(tr2);
44917
45240
  return true;
@@ -45827,13 +46150,13 @@ function applyTransaction(history2, state2, tr2, options) {
45827
46150
  return history2;
45828
46151
  } else if (appended && appended.getMeta(historyKey)) {
45829
46152
  if (appended.getMeta(historyKey).redo)
45830
- return new HistoryState(history2.done.addTransform(tr2, void 0, options, mustPreserveItems(state2)), history2.undone, rangesFor(tr2.mapping.maps[tr2.steps.length - 1]), history2.prevTime, history2.prevComposition);
46153
+ return new HistoryState(history2.done.addTransform(tr2, void 0, options, mustPreserveItems(state2)), history2.undone, rangesFor(tr2.mapping.maps), history2.prevTime, history2.prevComposition);
45831
46154
  else
45832
46155
  return new HistoryState(history2.done, history2.undone.addTransform(tr2, void 0, options, mustPreserveItems(state2)), null, history2.prevTime, history2.prevComposition);
45833
46156
  } else if (tr2.getMeta("addToHistory") !== false && !(appended && appended.getMeta("addToHistory") === false)) {
45834
46157
  let composition = tr2.getMeta("composition");
45835
46158
  let newGroup = history2.prevTime == 0 || !appended && history2.prevComposition != composition && (history2.prevTime < (tr2.time || 0) - options.newGroupDelay || !isAdjacentTo(tr2, history2.prevRanges));
45836
- let prevRanges = appended ? mapRanges(history2.prevRanges, tr2.mapping) : rangesFor(tr2.mapping.maps[tr2.steps.length - 1]);
46159
+ let prevRanges = appended ? mapRanges(history2.prevRanges, tr2.mapping) : rangesFor(tr2.mapping.maps);
45837
46160
  return new HistoryState(history2.done.addTransform(tr2, newGroup ? state2.selection.getBookmark() : void 0, options, mustPreserveItems(state2)), Branch.empty, prevRanges, tr2.time, composition == null ? history2.prevComposition : composition);
45838
46161
  } else if (rebased = tr2.getMeta("rebased")) {
45839
46162
  return new HistoryState(history2.done.rebased(tr2, rebased), history2.undone.rebased(tr2, rebased), mapRanges(history2.prevRanges, tr2.mapping), history2.prevTime, history2.prevComposition);
@@ -45854,9 +46177,10 @@ function isAdjacentTo(transform, prevRanges) {
45854
46177
  });
45855
46178
  return adjacent;
45856
46179
  }
45857
- function rangesFor(map4) {
46180
+ function rangesFor(maps) {
45858
46181
  let result2 = [];
45859
- map4.forEach((_from, _to, from2, to2) => result2.push(from2, to2));
46182
+ for (let i2 = maps.length - 1; i2 >= 0 && result2.length == 0; i2--)
46183
+ maps[i2].forEach((_from, _to, from2, to2) => result2.push(from2, to2));
45860
46184
  return result2;
45861
46185
  }
45862
46186
  function mapRanges(ranges, mapping) {
@@ -45870,16 +46194,16 @@ function mapRanges(ranges, mapping) {
45870
46194
  }
45871
46195
  return result2;
45872
46196
  }
45873
- function histTransaction(history2, state2, dispatch, redo2) {
46197
+ function histTransaction(history2, state2, redo2) {
45874
46198
  let preserveItems = mustPreserveItems(state2);
45875
46199
  let histOptions = historyKey.get(state2).spec.config;
45876
46200
  let pop = (redo2 ? history2.undone : history2.done).popEvent(state2, preserveItems);
45877
46201
  if (!pop)
45878
- return;
46202
+ return null;
45879
46203
  let selection = pop.selection.resolve(pop.transform.doc);
45880
46204
  let added = (redo2 ? history2.done : history2.undone).addTransform(pop.transform, state2.selection.getBookmark(), histOptions, preserveItems);
45881
46205
  let newHist = new HistoryState(redo2 ? added : pop.remaining, redo2 ? pop.remaining : added, null, 0, -1);
45882
- dispatch(pop.transform.setSelection(selection).setMeta(historyKey, { redo: redo2, historyState: newHist }).scrollIntoView());
46206
+ return pop.transform.setSelection(selection).setMeta(historyKey, { redo: redo2, historyState: newHist });
45883
46207
  }
45884
46208
  let cachedPreserveItems = false, cachedPreserveItemsPlugins = null;
45885
46209
  function mustPreserveItems(state2) {
@@ -45927,22 +46251,21 @@ function history(config = {}) {
45927
46251
  }
45928
46252
  });
45929
46253
  }
45930
- const undo = (state2, dispatch) => {
45931
- let hist = historyKey.getState(state2);
45932
- if (!hist || hist.done.eventCount == 0)
45933
- return false;
45934
- if (dispatch)
45935
- histTransaction(hist, state2, dispatch, false);
45936
- return true;
45937
- };
45938
- const redo = (state2, dispatch) => {
45939
- let hist = historyKey.getState(state2);
45940
- if (!hist || hist.undone.eventCount == 0)
45941
- return false;
45942
- if (dispatch)
45943
- histTransaction(hist, state2, dispatch, true);
45944
- return true;
45945
- };
46254
+ function buildCommand(redo2, scroll) {
46255
+ return (state2, dispatch) => {
46256
+ let hist = historyKey.getState(state2);
46257
+ if (!hist || (redo2 ? hist.undone : hist.done).eventCount == 0)
46258
+ return false;
46259
+ if (dispatch) {
46260
+ let tr2 = histTransaction(hist, state2, redo2);
46261
+ if (tr2)
46262
+ dispatch(scroll ? tr2.scrollIntoView() : tr2);
46263
+ }
46264
+ return true;
46265
+ };
46266
+ }
46267
+ const undo = buildCommand(false, true);
46268
+ const redo = buildCommand(true, true);
45946
46269
  const History = Extension.create({
45947
46270
  name: "history",
45948
46271
  addOptions() {
@@ -45994,10 +46317,20 @@ const HorizontalRule = Node$2.create({
45994
46317
  addCommands() {
45995
46318
  return {
45996
46319
  setHorizontalRule: () => ({ chain, state: state2 }) => {
45997
- const { $to: $originTo } = state2.selection;
46320
+ const { selection } = state2;
46321
+ const { $from: $originFrom, $to: $originTo } = selection;
45998
46322
  const currentChain = chain();
45999
- if ($originTo.parentOffset === 0) {
46000
- currentChain.insertContentAt(Math.max($originTo.pos - 2, 0), { type: this.name });
46323
+ if ($originFrom.parentOffset === 0) {
46324
+ currentChain.insertContentAt({
46325
+ from: Math.max($originFrom.pos - 1, 0),
46326
+ to: $originTo.pos
46327
+ }, {
46328
+ type: this.name
46329
+ });
46330
+ } else if (isNodeSelection(selection)) {
46331
+ currentChain.insertContentAt($originTo.pos, {
46332
+ type: this.name
46333
+ });
46001
46334
  } else {
46002
46335
  currentChain.insertContent({ type: this.name });
46003
46336
  }
@@ -46383,11 +46716,11 @@ const StarterKit = Extension.create({
46383
46716
  addExtensions() {
46384
46717
  var _a2, _b, _c, _d, _e2, _f, _g, _h, _j, _k, _l2, _m, _o, _p, _q, _r2, _s, _t2;
46385
46718
  const extensions = [];
46386
- if (this.options.blockquote !== false) {
46387
- extensions.push(Blockquote.configure((_a2 = this.options) === null || _a2 === void 0 ? void 0 : _a2.blockquote));
46388
- }
46389
46719
  if (this.options.bold !== false) {
46390
- extensions.push(Bold.configure((_b = this.options) === null || _b === void 0 ? void 0 : _b.bold));
46720
+ extensions.push(Bold.configure((_a2 = this.options) === null || _a2 === void 0 ? void 0 : _a2.bold));
46721
+ }
46722
+ if (this.options.blockquote !== false) {
46723
+ extensions.push(Blockquote.configure((_b = this.options) === null || _b === void 0 ? void 0 : _b.blockquote));
46391
46724
  }
46392
46725
  if (this.options.bulletList !== false) {
46393
46726
  extensions.push(BulletList.configure((_c = this.options) === null || _c === void 0 ? void 0 : _c.bulletList));
@@ -49194,7 +49527,7 @@ class BubbleMenuView {
49194
49527
  }
49195
49528
  update(view, oldState) {
49196
49529
  const { state: state2 } = view;
49197
- const hasValidSelection = state2.selection.$from.pos !== state2.selection.$to.pos;
49530
+ const hasValidSelection = state2.selection.from !== state2.selection.to;
49198
49531
  if (this.updateDelay > 0 && hasValidSelection) {
49199
49532
  this.handleDebouncedUpdate(view, oldState);
49200
49533
  return;
@@ -52346,7 +52679,7 @@ const Table = Node$2.create({
52346
52679
  insertTable: ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr: tr2, dispatch, editor }) => {
52347
52680
  const node = createTable$1(editor.schema, rows, cols, withHeaderRow);
52348
52681
  if (dispatch) {
52349
- const offset2 = tr2.selection.anchor + 1;
52682
+ const offset2 = tr2.selection.from + 1;
52350
52683
  tr2.replaceSelectionWith(node).scrollIntoView().setSelection(TextSelection.near(tr2.doc.resolve(offset2)));
52351
52684
  }
52352
52685
  return true;