@bagelink/vue 0.0.568 → 0.0.575

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.cjs CHANGED
@@ -5412,7 +5412,7 @@ const _sfc_main$O = /* @__PURE__ */ vue.defineComponent({
5412
5412
  return (_ctx, _cache) => {
5413
5413
  return vue.openBlock(), vue.createElementBlock("span", {
5414
5414
  class: "bgl_icon-font",
5415
- style: vue.normalizeStyle({ fontSize: `${_ctx.size}rem`, color: _ctx.color, "font-variation-settings": `'wght' ${_ctx.weight || 400}` })
5415
+ style: vue.normalizeStyle({ "fontSize": `${_ctx.size}rem`, color: _ctx.color, "font-variation-settings": `'wght' ${_ctx.weight || 400}` })
5416
5416
  }, vue.toDisplayString(_ctx.icon || _ctx.name), 5);
5417
5417
  };
5418
5418
  }
@@ -5421,8 +5421,8 @@ const _hoisted_1$J = { class: "full-nav" };
5421
5421
  const _hoisted_2$A = { class: "nav-scroll" };
5422
5422
  const _hoisted_3$n = { class: "nav-links-wrapper" };
5423
5423
  const _hoisted_4$f = { class: "tooltip" };
5424
- const _hoisted_5$d = { class: "bot-buttons-wrapper" };
5425
- const _hoisted_6$8 = { class: "tooltip" };
5424
+ const _hoisted_5$e = { class: "bot-buttons-wrapper" };
5425
+ const _hoisted_6$9 = { class: "tooltip" };
5426
5426
  const _sfc_main$N = /* @__PURE__ */ vue.defineComponent({
5427
5427
  __name: "NavBar",
5428
5428
  props: {
@@ -5476,7 +5476,7 @@ const _sfc_main$N = /* @__PURE__ */ vue.defineComponent({
5476
5476
  }), 128))
5477
5477
  ])
5478
5478
  ]),
5479
- vue.createElementVNode("div", _hoisted_5$d, [
5479
+ vue.createElementVNode("div", _hoisted_5$e, [
5480
5480
  (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(_ctx.footerLinks, (link) => {
5481
5481
  return vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(link.to ? "router-link" : "div"), {
5482
5482
  key: link.label,
@@ -5491,7 +5491,7 @@ const _sfc_main$N = /* @__PURE__ */ vue.defineComponent({
5491
5491
  vue.createVNode(vue.unref(_sfc_main$O), {
5492
5492
  icon: link.icon
5493
5493
  }, null, 8, ["icon"]),
5494
- vue.createElementVNode("div", _hoisted_6$8, vue.toDisplayString(link.label), 1)
5494
+ vue.createElementVNode("div", _hoisted_6$9, vue.toDisplayString(link.label), 1)
5495
5495
  ]),
5496
5496
  _: 2
5497
5497
  }, 1032, ["to", "onClick"]);
@@ -6335,9 +6335,9 @@ const _hoisted_3$j = [
6335
6335
  _hoisted_2$t
6336
6336
  ];
6337
6337
  const _hoisted_4$d = { class: "infinite-wrapper" };
6338
- const _hoisted_5$c = { class: "row first-row" };
6339
- const _hoisted_6$7 = { key: 0 };
6340
- const _hoisted_7$2 = ["onClick"];
6338
+ const _hoisted_5$d = { class: "row first-row" };
6339
+ const _hoisted_6$8 = { key: 0 };
6340
+ const _hoisted_7$3 = ["onClick"];
6341
6341
  const _hoisted_8$1 = { class: "flex" };
6342
6342
  const _hoisted_9$1 = ["onClick"];
6343
6343
  const _hoisted_10$1 = { key: 0 };
@@ -6480,8 +6480,8 @@ const _sfc_main$F = /* @__PURE__ */ vue.defineComponent({
6480
6480
  }), [
6481
6481
  loading.value ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$C, _hoisted_3$j)) : (vue.openBlock(), vue.createElementBlock("div", vue.normalizeProps(vue.mergeProps({ key: 1 }, vue.unref(wrapperProps))), [
6482
6482
  vue.createElementVNode("table", _hoisted_4$d, [
6483
- vue.createElementVNode("thead", _hoisted_5$c, [
6484
- vue.unref(isSelectable) ? (vue.openBlock(), vue.createElementBlock("th", _hoisted_6$7, [
6483
+ vue.createElementVNode("thead", _hoisted_5$d, [
6484
+ vue.unref(isSelectable) ? (vue.openBlock(), vue.createElementBlock("th", _hoisted_6$8, [
6485
6485
  vue.createElementVNode("input", {
6486
6486
  ref_key: "allSelector",
6487
6487
  ref: allSelector,
@@ -6508,7 +6508,7 @@ const _sfc_main$F = /* @__PURE__ */ vue.defineComponent({
6508
6508
  }, null, 8, ["class"])
6509
6509
  ], 2)
6510
6510
  ])
6511
- ], 8, _hoisted_7$2);
6511
+ ], 8, _hoisted_7$3);
6512
6512
  }), 128))
6513
6513
  ]),
6514
6514
  vue.createElementVNode("tbody", null, [
@@ -6602,8 +6602,8 @@ const _hoisted_2$s = {
6602
6602
  };
6603
6603
  const _hoisted_3$i = { class: "key" };
6604
6604
  const _hoisted_4$c = { key: 1 };
6605
- const _hoisted_5$b = { class: "key" };
6606
- const _hoisted_6$6 = { class: "vlue" };
6605
+ const _hoisted_5$c = { class: "key" };
6606
+ const _hoisted_6$7 = { class: "vlue" };
6607
6607
  const _sfc_main$C = /* @__PURE__ */ vue.defineComponent({
6608
6608
  __name: "DataPreview",
6609
6609
  props: /* @__PURE__ */ vue.mergeModels({
@@ -6653,8 +6653,8 @@ const _sfc_main$C = /* @__PURE__ */ vue.defineComponent({
6653
6653
  key: id,
6654
6654
  class: "data-row"
6655
6655
  }, [
6656
- vue.createElementVNode("div", _hoisted_5$b, vue.toDisplayString(label), 1),
6657
- vue.createElementVNode("div", _hoisted_6$6, vue.toDisplayString(itemData.value[id ?? ""]), 1)
6656
+ vue.createElementVNode("div", _hoisted_5$c, vue.toDisplayString(label), 1),
6657
+ vue.createElementVNode("div", _hoisted_6$7, vue.toDisplayString(itemData.value[id ?? ""]), 1)
6658
6658
  ]);
6659
6659
  }), 128))
6660
6660
  ])) : vue.createCommentVNode("", true),
@@ -25607,10 +25607,16 @@ const _sfc_main$m = /* @__PURE__ */ vue.defineComponent({
25607
25607
  }
25608
25608
  });
25609
25609
  const JSONInput = /* @__PURE__ */ _export_sfc(_sfc_main$m, [["__scopeId", "data-v-1cbaeab2"]]);
25610
- const _hoisted_1$q = ["disabled"];
25611
- const _hoisted_2$k = { key: 1 };
25612
- const _hoisted_3$f = ["value"];
25613
- const _hoisted_4$b = ["onClick"];
25610
+ const _hoisted_1$q = { class: "flex gap-05" };
25611
+ const _hoisted_2$k = ["disabled"];
25612
+ const _hoisted_3$f = { key: 1 };
25613
+ const _hoisted_4$b = {
25614
+ key: 2,
25615
+ class: "ms-auto ps-05 me-05"
25616
+ };
25617
+ const _hoisted_5$b = ["value"];
25618
+ const _hoisted_6$6 = { class: "selectinput-options" };
25619
+ const _hoisted_7$2 = ["onClick"];
25614
25620
  const _sfc_main$l = /* @__PURE__ */ vue.defineComponent({
25615
25621
  __name: "SelectInput",
25616
25622
  props: {
@@ -25625,7 +25631,8 @@ const _sfc_main$l = /* @__PURE__ */ vue.defineComponent({
25625
25631
  multiselect: { type: Boolean },
25626
25632
  icon: {},
25627
25633
  hideLabel: { type: Boolean },
25628
- defaultValue: {}
25634
+ defaultValue: {},
25635
+ clearable: { type: Boolean }
25629
25636
  },
25630
25637
  emits: ["update:modelValue"],
25631
25638
  setup(__props, { emit: __emit }) {
@@ -25633,6 +25640,7 @@ const _sfc_main$l = /* @__PURE__ */ vue.defineComponent({
25633
25640
  const emit2 = __emit;
25634
25641
  const searchInput = vue.ref(null);
25635
25642
  let selectedItems = vue.ref([]);
25643
+ const selectedItemCount = vue.computed(() => selectedItems.value.length ?? 0);
25636
25644
  let search = vue.ref("");
25637
25645
  const dropdown = vue.ref(null);
25638
25646
  let open = vue.ref(false);
@@ -25655,10 +25663,10 @@ const _sfc_main$l = /* @__PURE__ */ vue.defineComponent({
25655
25663
  }
25656
25664
  }
25657
25665
  const selectedLabel = vue.computed(() => {
25658
- if (selectedItems.value.length === 0) return props2.placeholder || "Select";
25659
- if (selectedItems.value.length > 4) {
25666
+ if (selectedItemCount.value === 0) return props2.placeholder || "Select";
25667
+ if (selectedItemCount.value > 4) {
25660
25668
  const str = selectedItems.value.slice(0, 4).map((item) => getLabel(item)).join(", ");
25661
- return `${str}... +${selectedItems.value.length - 4}`;
25669
+ return `${str}... +${selectedItemCount.value - 4}`;
25662
25670
  }
25663
25671
  return selectedItems.value.map((item) => getLabel(item)).join(", ");
25664
25672
  });
@@ -25691,7 +25699,7 @@ const _sfc_main$l = /* @__PURE__ */ vue.defineComponent({
25691
25699
  current.push(option2);
25692
25700
  selectedItems.value = current;
25693
25701
  } else {
25694
- selectedItems.value.splice(0, selectedItems.value.length, option2);
25702
+ selectedItems.value.splice(0, selectedItemCount.value, option2);
25695
25703
  }
25696
25704
  if (!props2.multiselect) (_a2 = dropdown.value) == null ? void 0 : _a2.hide();
25697
25705
  emitUpdate();
@@ -25719,7 +25727,7 @@ const _sfc_main$l = /* @__PURE__ */ vue.defineComponent({
25719
25727
  } else {
25720
25728
  const isSame = compareArrays([newVal].flat(), selectedItems.value);
25721
25729
  if (!isSame) {
25722
- selectedItems.value.splice(0, selectedItems.value.length, ...[newVal].flat());
25730
+ selectedItems.value.splice(0, selectedItemCount.value, ...[newVal].flat());
25723
25731
  }
25724
25732
  }
25725
25733
  },
@@ -25753,13 +25761,13 @@ const _sfc_main$l = /* @__PURE__ */ vue.defineComponent({
25753
25761
  ref: dropdown,
25754
25762
  placement: "bottom-start",
25755
25763
  class: "bagel-input selectinput",
25756
- onClick: _cache[3] || (_cache[3] = vue.withModifiers(() => {
25764
+ onClick: _cache[4] || (_cache[4] = vue.withModifiers(() => {
25757
25765
  }, ["stop"])),
25758
- onHide: _cache[4] || (_cache[4] = ($event) => updateOpen(false))
25766
+ onHide: _cache[5] || (_cache[5] = ($event) => updateOpen(false))
25759
25767
  }, {
25760
25768
  popper: vue.withCtx(() => [
25761
25769
  vue.createVNode(vue.unref(_sfc_main$B), {
25762
- class: "selectinput-options p-05",
25770
+ class: "p-05",
25763
25771
  style: vue.normalizeStyle({ width: _ctx.fullWidth ? "100%" : "auto" })
25764
25772
  }, {
25765
25773
  default: vue.withCtx(() => [
@@ -25768,62 +25776,72 @@ const _sfc_main$l = /* @__PURE__ */ vue.defineComponent({
25768
25776
  ref_key: "searchInput",
25769
25777
  ref: searchInput,
25770
25778
  modelValue: vue.unref(search),
25771
- "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => vue.isRef(search) ? search.value = $event : search = $event),
25779
+ "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => vue.isRef(search) ? search.value = $event : search = $event),
25772
25780
  dense: "",
25773
25781
  placeholder: "Search",
25774
25782
  icon: "search"
25775
25783
  }, null, 8, ["modelValue"])) : vue.createCommentVNode("", true),
25776
- (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(filteredOptions.value, (option2, i2) => {
25777
- return vue.openBlock(), vue.createElementBlock("div", {
25778
- key: `${option2}${i2}`,
25779
- class: vue.normalizeClass(["selectinput-option hover gap-1", { selected: isSelected(option2) }]),
25780
- onClick: ($event) => select2(option2)
25781
- }, [
25782
- isSelected(option2) ? (vue.openBlock(), vue.createBlock(vue.unref(_sfc_main$O), {
25783
- key: 0,
25784
- icon: "check"
25785
- })) : vue.createCommentVNode("", true),
25786
- !isSelected(option2) ? (vue.openBlock(), vue.createBlock(vue.unref(_sfc_main$O), {
25787
- key: 1,
25788
- class: "opacity-3",
25789
- icon: "fiber_manual_record"
25790
- })) : vue.createCommentVNode("", true),
25791
- vue.createElementVNode("span", null, vue.toDisplayString(getLabel(option2)), 1)
25792
- ], 10, _hoisted_4$b);
25793
- }), 128)),
25784
+ vue.createElementVNode("div", _hoisted_6$6, [
25785
+ (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(filteredOptions.value, (option2, i2) => {
25786
+ return vue.openBlock(), vue.createElementBlock("div", {
25787
+ key: `${option2}${i2}`,
25788
+ class: vue.normalizeClass(["selectinput-option hover gap-1", { selected: isSelected(option2) }]),
25789
+ onClick: ($event) => select2(option2)
25790
+ }, [
25791
+ isSelected(option2) ? (vue.openBlock(), vue.createBlock(vue.unref(_sfc_main$O), {
25792
+ key: 0,
25793
+ icon: "check"
25794
+ })) : vue.createCommentVNode("", true),
25795
+ !isSelected(option2) ? (vue.openBlock(), vue.createBlock(vue.unref(_sfc_main$O), {
25796
+ key: 1,
25797
+ class: "opacity-3",
25798
+ icon: "fiber_manual_record"
25799
+ })) : vue.createCommentVNode("", true),
25800
+ vue.createElementVNode("span", null, vue.toDisplayString(getLabel(option2)), 1)
25801
+ ], 10, _hoisted_7$2);
25802
+ }), 128))
25803
+ ]),
25794
25804
  vue.renderSlot(_ctx.$slots, "last", {}, void 0, true)
25795
25805
  ]),
25796
25806
  _: 3
25797
25807
  }, 8, ["style"])
25798
25808
  ]),
25799
25809
  default: vue.withCtx(() => [
25800
- vue.createElementVNode("label", null, [
25810
+ vue.createElementVNode("label", _hoisted_1$q, [
25801
25811
  vue.createTextVNode(vue.toDisplayString(_ctx.label) + " ", 1),
25802
25812
  vue.createElementVNode("button", {
25803
25813
  disabled: _ctx.disabled,
25804
25814
  type: "button",
25805
- class: vue.normalizeClass(["selectinput-btn", { isEmpty: vue.unref(selectedItems).length === 0 }]),
25815
+ class: vue.normalizeClass(["selectinput-btn", { isEmpty: selectedItemCount.value === 0 }]),
25806
25816
  onKeydown: openOptions,
25807
- onClick: _cache[0] || (_cache[0] = ($event) => updateOpen(true))
25817
+ onClick: _cache[1] || (_cache[1] = ($event) => updateOpen(true))
25808
25818
  }, [
25809
25819
  _ctx.icon ? (vue.openBlock(), vue.createBlock(vue.unref(_sfc_main$O), {
25810
25820
  key: 0,
25811
25821
  icon: _ctx.icon
25812
25822
  }, null, 8, ["icon"])) : vue.createCommentVNode("", true),
25813
- !_ctx.hideLabel ? (vue.openBlock(), vue.createElementBlock("p", _hoisted_2$k, vue.toDisplayString(selectedLabel.value), 1)) : vue.createCommentVNode("", true),
25823
+ !_ctx.hideLabel ? (vue.openBlock(), vue.createElementBlock("p", _hoisted_3$f, vue.toDisplayString(selectedLabel.value), 1)) : vue.createCommentVNode("", true),
25824
+ _ctx.clearable ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_4$b, [
25825
+ vue.createVNode(vue.unref(Btn), {
25826
+ thin: "",
25827
+ icon: "clear",
25828
+ class: "color-black bg-gray-light",
25829
+ onClick: _cache[0] || (_cache[0] = ($event) => vue.isRef(selectedItems) ? selectedItems.value = [] : selectedItems = [])
25830
+ })
25831
+ ])) : vue.createCommentVNode("", true),
25814
25832
  !_ctx.disabled ? (vue.openBlock(), vue.createBlock(vue.unref(_sfc_main$O), vue.mergeProps({
25815
- key: 2,
25833
+ key: 3,
25816
25834
  thin: ""
25817
25835
  }, { icon: vue.unref(open) ? "unfold_less" : "unfold_more" }), null, 16)) : vue.createCommentVNode("", true)
25818
- ], 42, _hoisted_1$q),
25836
+ ], 42, _hoisted_2$k),
25819
25837
  _ctx.required ? (vue.openBlock(), vue.createElementBlock("input", {
25820
25838
  key: 0,
25821
25839
  tabindex: "-1",
25822
25840
  style: { "width": "0", "height": "0", "position": "absolute", "opacity": "0", "z-index": "-1" },
25823
25841
  value: vue.unref(selectedItems),
25824
25842
  required: "",
25825
- onInput: _cache[1] || (_cache[1] = ($event) => updateOpen(true))
25826
- }, null, 40, _hoisted_3$f)) : vue.createCommentVNode("", true)
25843
+ onInput: _cache[2] || (_cache[2] = ($event) => updateOpen(true))
25844
+ }, null, 40, _hoisted_5$b)) : vue.createCommentVNode("", true)
25827
25845
  ])
25828
25846
  ]),
25829
25847
  _: 3
@@ -25831,7 +25849,7 @@ const _sfc_main$l = /* @__PURE__ */ vue.defineComponent({
25831
25849
  };
25832
25850
  }
25833
25851
  });
25834
- const SelectInput = /* @__PURE__ */ _export_sfc(_sfc_main$l, [["__scopeId", "data-v-4e1d2142"]]);
25852
+ const SelectInput = /* @__PURE__ */ _export_sfc(_sfc_main$l, [["__scopeId", "data-v-c5344871"]]);
25835
25853
  /*!
25836
25854
  * vue-draggable-next v2.2.0
25837
25855
  * (c) 2023 Anish George
@@ -28818,7 +28836,7 @@ const _sfc_main$f = /* @__PURE__ */ vue.defineComponent({
28818
28836
  }
28819
28837
  });
28820
28838
  const RadioPillsInput = /* @__PURE__ */ _export_sfc(_sfc_main$f, [["__scopeId", "data-v-681173be"]]);
28821
- const _withScopeId$2 = (n2) => (vue.pushScopeId("data-v-1ce244aa"), n2 = n2(), vue.popScopeId(), n2);
28839
+ const _withScopeId$2 = (n2) => (vue.pushScopeId("data-v-853e75be"), n2 = n2(), vue.popScopeId(), n2);
28822
28840
  const _hoisted_1$j = { class: "bagel-input" };
28823
28841
  const _hoisted_2$e = {
28824
28842
  key: 0,
@@ -28850,20 +28868,25 @@ const _sfc_main$e = /* @__PURE__ */ vue.defineComponent({
28850
28868
  label: {},
28851
28869
  multiple: { type: Boolean },
28852
28870
  files: {},
28853
- deleteEndpoint: {},
28854
28871
  bindkey: {},
28855
28872
  modelValue: {},
28856
- width: {}
28873
+ width: {},
28874
+ topic: {}
28857
28875
  },
28858
28876
  emits: ["update:modelValue"],
28859
28877
  setup(__props, { emit: __emit }) {
28860
28878
  const props2 = __props;
28879
+ const emit2 = __emit;
28861
28880
  const bagel = useBagel();
28862
28881
  const bindKey2 = props2.bindkey || "id";
28863
- const emit2 = __emit;
28864
28882
  let file_bindkeys = vue.ref(props2.modelValue || []);
28865
28883
  const storageFiles = vue.ref([]);
28884
+ async function fetchFiles() {
28885
+ const files = await bagel.get(`/files?topic=${props2.topic}`);
28886
+ storageFiles.value.push(...files);
28887
+ }
28866
28888
  vue.onMounted(() => {
28889
+ if (props2.topic) fetchFiles();
28867
28890
  if (!props2.files && [file_bindkeys.value].flat().length) {
28868
28891
  const ids = [file_bindkeys.value].flat().filter(Boolean);
28869
28892
  if (!ids.length) return;
@@ -28915,9 +28938,7 @@ const _sfc_main$e = /* @__PURE__ */ vue.defineComponent({
28915
28938
  function removeFile(file) {
28916
28939
  const index2 = storageFiles.value.indexOf(file);
28917
28940
  storageFiles.value.splice(index2, 1);
28918
- if (props2.deleteEndpoint) {
28919
- void bagel.delete(`${props2.deleteEndpoint}/${file.id}`);
28920
- }
28941
+ void bagel.delete(`/static_files/${file.id}`);
28921
28942
  updateModelValue();
28922
28943
  }
28923
28944
  async function flushQueue() {
@@ -28925,7 +28946,8 @@ const _sfc_main$e = /* @__PURE__ */ vue.defineComponent({
28925
28946
  file.uploading = true;
28926
28947
  if (!props2.multiple) storageFiles.value.splice(0, 1);
28927
28948
  const serverFile = await bagel.uploadFile(file.file, {
28928
- onUploadProgress: (e) => file.progress = e.progress * 100 - 1
28949
+ onUploadProgress: (e) => file.progress = e.progress * 100 - 1,
28950
+ topic: props2.topic
28929
28951
  });
28930
28952
  storageFiles.value.push(serverFile);
28931
28953
  const i2 = fileQueue.value.indexOf(file);
@@ -29058,7 +29080,7 @@ const _sfc_main$e = /* @__PURE__ */ vue.defineComponent({
29058
29080
  };
29059
29081
  }
29060
29082
  });
29061
- const $el = /* @__PURE__ */ _export_sfc(_sfc_main$e, [["__scopeId", "data-v-1ce244aa"]]);
29083
+ const $el = /* @__PURE__ */ _export_sfc(_sfc_main$e, [["__scopeId", "data-v-853e75be"]]);
29062
29084
  const _withScopeId$1 = (n2) => (vue.pushScopeId("data-v-eceeebfb"), n2 = n2(), vue.popScopeId(), n2);
29063
29085
  const _hoisted_1$i = ["title"];
29064
29086
  const _hoisted_2$d = /* @__PURE__ */ _withScopeId$1(() => /* @__PURE__ */ vue.createElementVNode("span", { class: "slider round" }, null, -1));
@@ -29491,7 +29513,7 @@ class Fragment {
29491
29513
  /**
29492
29514
  Find the index and inner offset corresponding to a given relative
29493
29515
  position in this fragment. The result object will be reused
29494
- (overwritten) the next time the function is called. (Not public.)
29516
+ (overwritten) the next time the function is called. @internal
29495
29517
  */
29496
29518
  findIndex(pos, round2 = -1) {
29497
29519
  if (pos == 0)
@@ -29697,7 +29719,9 @@ let Mark$1 = class Mark2 {
29697
29719
  let type3 = schema.marks[json.type];
29698
29720
  if (!type3)
29699
29721
  throw new RangeError(`There is no mark type ${json.type} in this schema`);
29700
- return type3.create(json.attrs);
29722
+ let mark = type3.create(json.attrs);
29723
+ type3.checkAttrs(mark.attrs);
29724
+ return mark;
29701
29725
  }
29702
29726
  /**
29703
29727
  Test whether two sets of marks are identical.
@@ -30194,17 +30218,28 @@ class ResolvedPos {
30194
30218
  @internal
30195
30219
  */
30196
30220
  static resolveCached(doc2, pos) {
30197
- for (let i2 = 0; i2 < resolveCache.length; i2++) {
30198
- let cached2 = resolveCache[i2];
30199
- if (cached2.pos == pos && cached2.doc == doc2)
30200
- return cached2;
30221
+ let cache = resolveCache.get(doc2);
30222
+ if (cache) {
30223
+ for (let i2 = 0; i2 < cache.elts.length; i2++) {
30224
+ let elt = cache.elts[i2];
30225
+ if (elt.pos == pos)
30226
+ return elt;
30227
+ }
30228
+ } else {
30229
+ resolveCache.set(doc2, cache = new ResolveCache());
30201
30230
  }
30202
- let result2 = resolveCache[resolveCachePos] = ResolvedPos.resolve(doc2, pos);
30203
- resolveCachePos = (resolveCachePos + 1) % resolveCacheSize;
30231
+ let result2 = cache.elts[cache.i] = ResolvedPos.resolve(doc2, pos);
30232
+ cache.i = (cache.i + 1) % resolveCacheSize;
30204
30233
  return result2;
30205
30234
  }
30206
30235
  }
30207
- let resolveCache = [], resolveCachePos = 0, resolveCacheSize = 12;
30236
+ class ResolveCache {
30237
+ constructor() {
30238
+ this.elts = [];
30239
+ this.i = 0;
30240
+ }
30241
+ }
30242
+ const resolveCacheSize = 12, resolveCache = /* @__PURE__ */ new WeakMap();
30208
30243
  class NodeRange {
30209
30244
  /**
30210
30245
  Construct a node range. `$from` and `$to` should point into the
@@ -30590,13 +30625,17 @@ let Node$3 = class Node2 {
30590
30625
  }
30591
30626
  /**
30592
30627
  Check whether this node and its descendants conform to the
30593
- schema, and raise error when they do not.
30628
+ schema, and raise an exception when they do not.
30594
30629
  */
30595
30630
  check() {
30596
30631
  this.type.checkContent(this.content);
30632
+ this.type.checkAttrs(this.attrs);
30597
30633
  let copy2 = Mark$1.none;
30598
- for (let i2 = 0; i2 < this.marks.length; i2++)
30599
- copy2 = this.marks[i2].addToSet(copy2);
30634
+ for (let i2 = 0; i2 < this.marks.length; i2++) {
30635
+ let mark = this.marks[i2];
30636
+ mark.type.checkAttrs(mark.attrs);
30637
+ copy2 = mark.addToSet(copy2);
30638
+ }
30600
30639
  if (!Mark$1.sameSet(copy2, this.marks))
30601
30640
  throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((m2) => m2.type.name)}`);
30602
30641
  this.content.forEach((node) => node.check());
@@ -30622,7 +30661,7 @@ let Node$3 = class Node2 {
30622
30661
  static fromJSON(schema, json) {
30623
30662
  if (!json)
30624
30663
  throw new RangeError("Invalid input for Node.fromJSON");
30625
- let marks = null;
30664
+ let marks = void 0;
30626
30665
  if (json.marks) {
30627
30666
  if (!Array.isArray(json.marks))
30628
30667
  throw new RangeError("Invalid mark data for Node.fromJSON");
@@ -30634,7 +30673,9 @@ let Node$3 = class Node2 {
30634
30673
  return schema.text(json.text, marks);
30635
30674
  }
30636
30675
  let content = Fragment.fromJSON(schema, json.content);
30637
- return schema.nodeType(json.type).create(json.attrs, content, marks);
30676
+ let node = schema.nodeType(json.type).create(json.attrs, content, marks);
30677
+ node.type.checkAttrs(node.attrs);
30678
+ return node;
30638
30679
  }
30639
30680
  };
30640
30681
  Node$3.prototype.text = void 0;
@@ -31116,6 +31157,16 @@ function computeAttrs(attrs, value) {
31116
31157
  }
31117
31158
  return built;
31118
31159
  }
31160
+ function checkAttrs(attrs, values3, type3, name) {
31161
+ for (let name2 in values3)
31162
+ if (!(name2 in attrs))
31163
+ throw new RangeError(`Unsupported attribute ${name2} for ${type3} of type ${name2}`);
31164
+ for (let name2 in attrs) {
31165
+ let attr = attrs[name2];
31166
+ if (attr.validate)
31167
+ attr.validate(values3[name2]);
31168
+ }
31169
+ }
31119
31170
  function initAttrs(attrs) {
31120
31171
  let result2 = /* @__PURE__ */ Object.create(null);
31121
31172
  if (attrs)
@@ -31245,7 +31296,7 @@ let NodeType$1 = class NodeType2 {
31245
31296
  }
31246
31297
  /**
31247
31298
  Returns true if the given fragment is valid content for this node
31248
- type with the given attributes.
31299
+ type.
31249
31300
  */
31250
31301
  validContent(content) {
31251
31302
  let result2 = this.contentMatch.matchFragment(content);
@@ -31266,6 +31317,12 @@ let NodeType$1 = class NodeType2 {
31266
31317
  throw new RangeError(`Invalid content for node ${this.name}: ${content.toString().slice(0, 50)}`);
31267
31318
  }
31268
31319
  /**
31320
+ @internal
31321
+ */
31322
+ checkAttrs(attrs) {
31323
+ checkAttrs(this.attrs, attrs, "node", this.name);
31324
+ }
31325
+ /**
31269
31326
  Check whether the given mark type is allowed in this node.
31270
31327
  */
31271
31328
  allowsMarkType(markType) {
@@ -31315,10 +31372,19 @@ let NodeType$1 = class NodeType2 {
31315
31372
  return result2;
31316
31373
  }
31317
31374
  };
31375
+ function validateType(type3) {
31376
+ let types = type3.split("|");
31377
+ return (value) => {
31378
+ let name = value === null ? "null" : typeof value;
31379
+ if (types.indexOf(name) < 0)
31380
+ throw new RangeError(`Expected value of type ${types}, got ${name}`);
31381
+ };
31382
+ }
31318
31383
  class Attribute {
31319
31384
  constructor(options) {
31320
31385
  this.hasDefault = Object.prototype.hasOwnProperty.call(options, "default");
31321
31386
  this.default = options.default;
31387
+ this.validate = typeof options.validate == "string" ? validateType(options.validate) : options.validate;
31322
31388
  }
31323
31389
  get isRequired() {
31324
31390
  return !this.hasDefault;
@@ -31377,6 +31443,12 @@ class MarkType {
31377
31443
  return set2[i2];
31378
31444
  }
31379
31445
  /**
31446
+ @internal
31447
+ */
31448
+ checkAttrs(attrs) {
31449
+ checkAttrs(this.attrs, attrs, "mark", this.name);
31450
+ }
31451
+ /**
31380
31452
  Queries whether a given mark type is
31381
31453
  [excluded](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) by this one.
31382
31454
  */
@@ -31389,6 +31461,7 @@ class Schema {
31389
31461
  Construct a schema from a schema [specification](https://prosemirror.net/docs/ref/#model.SchemaSpec).
31390
31462
  */
31391
31463
  constructor(spec) {
31464
+ this.linebreakReplacement = null;
31392
31465
  this.cached = /* @__PURE__ */ Object.create(null);
31393
31466
  let instanceSpec = this.spec = {};
31394
31467
  for (let prop3 in spec)
@@ -31402,6 +31475,13 @@ class Schema {
31402
31475
  let type3 = this.nodes[prop3], contentExpr = type3.spec.content || "", markExpr = type3.spec.marks;
31403
31476
  type3.contentMatch = contentExprCache[contentExpr] || (contentExprCache[contentExpr] = ContentMatch.parse(contentExpr, this.nodes));
31404
31477
  type3.inlineContent = type3.contentMatch.inlineContent;
31478
+ if (type3.spec.linebreakReplacement) {
31479
+ if (this.linebreakReplacement)
31480
+ throw new RangeError("Multiple linebreak nodes defined");
31481
+ if (!type3.isInline || !type3.isLeaf)
31482
+ throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");
31483
+ this.linebreakReplacement = type3;
31484
+ }
31405
31485
  type3.markSet = markExpr == "_" ? null : markExpr ? gatherMarks(this, markExpr.split(" ")) : markExpr == "" || !type3.inlineContent ? [] : null;
31406
31486
  }
31407
31487
  for (let prop3 in this.marks) {
@@ -31486,6 +31566,12 @@ function gatherMarks(schema, marks) {
31486
31566
  }
31487
31567
  return found2;
31488
31568
  }
31569
+ function isTagRule(rule) {
31570
+ return rule.tag != null;
31571
+ }
31572
+ function isStyleRule(rule) {
31573
+ return rule.style != null;
31574
+ }
31489
31575
  class DOMParser {
31490
31576
  /**
31491
31577
  Create a parser that targets the given schema, using the given
@@ -31496,11 +31582,16 @@ class DOMParser {
31496
31582
  this.rules = rules;
31497
31583
  this.tags = [];
31498
31584
  this.styles = [];
31585
+ let matchedStyles = this.matchedStyles = [];
31499
31586
  rules.forEach((rule) => {
31500
- if (rule.tag)
31587
+ if (isTagRule(rule)) {
31501
31588
  this.tags.push(rule);
31502
- else if (rule.style)
31589
+ } else if (isStyleRule(rule)) {
31590
+ let prop3 = /[^=]*/.exec(rule.style)[0];
31591
+ if (matchedStyles.indexOf(prop3) < 0)
31592
+ matchedStyles.push(prop3);
31503
31593
  this.styles.push(rule);
31594
+ }
31504
31595
  });
31505
31596
  this.normalizeLists = !this.tags.some((r2) => {
31506
31597
  if (!/^(ul|ol)\b/.test(r2.tag) || !r2.node)
@@ -31760,10 +31851,10 @@ class ParseContext {
31760
31851
  this.addElement(dom);
31761
31852
  }
31762
31853
  withStyleRules(dom, f2) {
31763
- let style2 = dom.getAttribute("style");
31764
- if (!style2)
31854
+ let style2 = dom.style;
31855
+ if (!style2 || !style2.length)
31765
31856
  return f2();
31766
- let marks = this.readStyles(parseStyles(style2));
31857
+ let marks = this.readStyles(dom.style);
31767
31858
  if (!marks)
31768
31859
  return;
31769
31860
  let [addMarks, removeMarks] = marks, top2 = this.top;
@@ -31857,27 +31948,30 @@ class ParseContext {
31857
31948
  // had a rule with `ignore` set.
31858
31949
  readStyles(styles) {
31859
31950
  let add2 = Mark$1.none, remove2 = Mark$1.none;
31860
- for (let i2 = 0; i2 < styles.length; i2 += 2) {
31861
- for (let after = void 0; ; ) {
31862
- let rule = this.parser.matchStyle(styles[i2], styles[i2 + 1], this, after);
31863
- if (!rule)
31864
- break;
31865
- if (rule.ignore)
31866
- return null;
31867
- if (rule.clearMark) {
31868
- this.top.pendingMarks.concat(this.top.activeMarks).forEach((m2) => {
31869
- if (rule.clearMark(m2))
31870
- remove2 = m2.addToSet(remove2);
31871
- });
31872
- } else {
31873
- add2 = this.parser.schema.marks[rule.mark].create(rule.attrs).addToSet(add2);
31874
- }
31875
- if (rule.consuming === false)
31876
- after = rule;
31877
- else
31878
- break;
31951
+ if (styles.length)
31952
+ for (let i2 = 0; i2 < this.parser.matchedStyles.length; i2++) {
31953
+ let name = this.parser.matchedStyles[i2], value = styles.getPropertyValue(name);
31954
+ if (value)
31955
+ for (let after = void 0; ; ) {
31956
+ let rule = this.parser.matchStyle(name, value, this, after);
31957
+ if (!rule)
31958
+ break;
31959
+ if (rule.ignore)
31960
+ return null;
31961
+ if (rule.clearMark) {
31962
+ this.top.pendingMarks.concat(this.top.activeMarks).forEach((m2) => {
31963
+ if (rule.clearMark(m2))
31964
+ remove2 = m2.addToSet(remove2);
31965
+ });
31966
+ } else {
31967
+ add2 = this.parser.schema.marks[rule.mark].create(rule.attrs).addToSet(add2);
31968
+ }
31969
+ if (rule.consuming === false)
31970
+ after = rule;
31971
+ else
31972
+ break;
31973
+ }
31879
31974
  }
31880
- }
31881
31975
  return [add2, remove2];
31882
31976
  }
31883
31977
  // Look up a handler for the given node. If none are found, return
@@ -32146,12 +32240,6 @@ function normalizeList(dom) {
32146
32240
  function matches(dom, selector2) {
32147
32241
  return (dom.matches || dom.msMatchesSelector || dom.webkitMatchesSelector || dom.mozMatchesSelector).call(dom, selector2);
32148
32242
  }
32149
- function parseStyles(style2) {
32150
- let re2 = /\s*([\w-]+)\s*:\s*([^;]+)/g, m2, result2 = [];
32151
- while (m2 = re2.exec(style2))
32152
- result2.push(m2[1], m2[2].trim());
32153
- return result2;
32154
- }
32155
32243
  function copy$2(obj) {
32156
32244
  let copy2 = {};
32157
32245
  for (let prop3 in obj)
@@ -32242,7 +32330,7 @@ class DOMSerializer {
32242
32330
  @internal
32243
32331
  */
32244
32332
  serializeNodeInner(node, options) {
32245
- let { dom, contentDOM } = DOMSerializer.renderSpec(doc$1(options), this.nodes[node.type.name](node));
32333
+ let { dom, contentDOM } = renderSpec(doc$1(options), this.nodes[node.type.name](node), null, node.attrs);
32246
32334
  if (contentDOM) {
32247
32335
  if (node.isLeaf)
32248
32336
  throw new RangeError("Content hole not allowed in a leaf node spec");
@@ -32273,7 +32361,7 @@ class DOMSerializer {
32273
32361
  */
32274
32362
  serializeMark(mark, inline, options = {}) {
32275
32363
  let toDOM = this.marks[mark.type.name];
32276
- return toDOM && DOMSerializer.renderSpec(doc$1(options), toDOM(mark, inline));
32364
+ return toDOM && renderSpec(doc$1(options), toDOM(mark, inline), null, mark.attrs);
32277
32365
  }
32278
32366
  /**
32279
32367
  Render an [output spec](https://prosemirror.net/docs/ref/#model.DOMOutputSpec) to a DOM node. If
@@ -32281,48 +32369,7 @@ class DOMSerializer {
32281
32369
  node with the hole.
32282
32370
  */
32283
32371
  static renderSpec(doc2, structure, xmlNS = null) {
32284
- if (typeof structure == "string")
32285
- return { dom: doc2.createTextNode(structure) };
32286
- if (structure.nodeType != null)
32287
- return { dom: structure };
32288
- if (structure.dom && structure.dom.nodeType != null)
32289
- return structure;
32290
- let tagName = structure[0], space = tagName.indexOf(" ");
32291
- if (space > 0) {
32292
- xmlNS = tagName.slice(0, space);
32293
- tagName = tagName.slice(space + 1);
32294
- }
32295
- let contentDOM;
32296
- let dom = xmlNS ? doc2.createElementNS(xmlNS, tagName) : doc2.createElement(tagName);
32297
- let attrs = structure[1], start2 = 1;
32298
- if (attrs && typeof attrs == "object" && attrs.nodeType == null && !Array.isArray(attrs)) {
32299
- start2 = 2;
32300
- for (let name in attrs)
32301
- if (attrs[name] != null) {
32302
- let space2 = name.indexOf(" ");
32303
- if (space2 > 0)
32304
- dom.setAttributeNS(name.slice(0, space2), name.slice(space2 + 1), attrs[name]);
32305
- else
32306
- dom.setAttribute(name, attrs[name]);
32307
- }
32308
- }
32309
- for (let i2 = start2; i2 < structure.length; i2++) {
32310
- let child = structure[i2];
32311
- if (child === 0) {
32312
- if (i2 < structure.length - 1 || i2 > start2)
32313
- throw new RangeError("Content hole must be the only child of its parent node");
32314
- return { dom, contentDOM: dom };
32315
- } else {
32316
- let { dom: inner, contentDOM: innerContent } = DOMSerializer.renderSpec(doc2, child, xmlNS);
32317
- dom.appendChild(inner);
32318
- if (innerContent) {
32319
- if (contentDOM)
32320
- throw new RangeError("Multiple content holes");
32321
- contentDOM = innerContent;
32322
- }
32323
- }
32324
- }
32325
- return { dom, contentDOM };
32372
+ return renderSpec(doc2, structure, xmlNS);
32326
32373
  }
32327
32374
  /**
32328
32375
  Build a serializer using the [`toDOM`](https://prosemirror.net/docs/ref/#model.NodeSpec.toDOM)
@@ -32360,6 +32407,84 @@ function gatherToDOM(obj) {
32360
32407
  function doc$1(options) {
32361
32408
  return options.document || window.document;
32362
32409
  }
32410
+ const suspiciousAttributeCache = /* @__PURE__ */ new WeakMap();
32411
+ function suspiciousAttributes(attrs) {
32412
+ let value = suspiciousAttributeCache.get(attrs);
32413
+ if (value === void 0)
32414
+ suspiciousAttributeCache.set(attrs, value = suspiciousAttributesInner(attrs));
32415
+ return value;
32416
+ }
32417
+ function suspiciousAttributesInner(attrs) {
32418
+ let result2 = null;
32419
+ function scan(value) {
32420
+ if (value && typeof value == "object") {
32421
+ if (Array.isArray(value)) {
32422
+ if (typeof value[0] == "string") {
32423
+ if (!result2)
32424
+ result2 = [];
32425
+ result2.push(value);
32426
+ } else {
32427
+ for (let i2 = 0; i2 < value.length; i2++)
32428
+ scan(value[i2]);
32429
+ }
32430
+ } else {
32431
+ for (let prop3 in value)
32432
+ scan(value[prop3]);
32433
+ }
32434
+ }
32435
+ }
32436
+ scan(attrs);
32437
+ return result2;
32438
+ }
32439
+ function renderSpec(doc2, structure, xmlNS, blockArraysIn) {
32440
+ if (typeof structure == "string")
32441
+ return { dom: doc2.createTextNode(structure) };
32442
+ if (structure.nodeType != null)
32443
+ return { dom: structure };
32444
+ if (structure.dom && structure.dom.nodeType != null)
32445
+ return structure;
32446
+ let tagName = structure[0], suspicious;
32447
+ if (typeof tagName != "string")
32448
+ throw new RangeError("Invalid array passed to renderSpec");
32449
+ if (blockArraysIn && (suspicious = suspiciousAttributes(blockArraysIn)) && suspicious.indexOf(structure) > -1)
32450
+ throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");
32451
+ let space = tagName.indexOf(" ");
32452
+ if (space > 0) {
32453
+ xmlNS = tagName.slice(0, space);
32454
+ tagName = tagName.slice(space + 1);
32455
+ }
32456
+ let contentDOM;
32457
+ let dom = xmlNS ? doc2.createElementNS(xmlNS, tagName) : doc2.createElement(tagName);
32458
+ let attrs = structure[1], start2 = 1;
32459
+ if (attrs && typeof attrs == "object" && attrs.nodeType == null && !Array.isArray(attrs)) {
32460
+ start2 = 2;
32461
+ for (let name in attrs)
32462
+ if (attrs[name] != null) {
32463
+ let space2 = name.indexOf(" ");
32464
+ if (space2 > 0)
32465
+ dom.setAttributeNS(name.slice(0, space2), name.slice(space2 + 1), attrs[name]);
32466
+ else
32467
+ dom.setAttribute(name, attrs[name]);
32468
+ }
32469
+ }
32470
+ for (let i2 = start2; i2 < structure.length; i2++) {
32471
+ let child = structure[i2];
32472
+ if (child === 0) {
32473
+ if (i2 < structure.length - 1 || i2 > start2)
32474
+ throw new RangeError("Content hole must be the only child of its parent node");
32475
+ return { dom, contentDOM: dom };
32476
+ } else {
32477
+ let { dom: inner, contentDOM: innerContent } = renderSpec(doc2, child, xmlNS, blockArraysIn);
32478
+ dom.appendChild(inner);
32479
+ if (innerContent) {
32480
+ if (contentDOM)
32481
+ throw new RangeError("Multiple content holes");
32482
+ contentDOM = innerContent;
32483
+ }
32484
+ }
32485
+ }
32486
+ return { dom, contentDOM };
32487
+ }
32363
32488
  const lower16 = 65535;
32364
32489
  const factor16 = Math.pow(2, 16);
32365
32490
  function makeRecover(index2, offset2) {
@@ -33019,7 +33144,8 @@ class ReplaceAroundStep extends Step$1 {
33019
33144
  }
33020
33145
  map(mapping) {
33021
33146
  let from2 = mapping.mapResult(this.from, 1), to2 = mapping.mapResult(this.to, -1);
33022
- let gapFrom = mapping.map(this.gapFrom, -1), gapTo = mapping.map(this.gapTo, 1);
33147
+ let gapFrom = this.from == this.gapFrom ? from2.pos : mapping.map(this.gapFrom, -1);
33148
+ let gapTo = this.to == this.gapTo ? to2.pos : mapping.map(this.gapTo, 1);
33023
33149
  if (from2.deletedAcross && to2.deletedAcross || gapFrom < from2.pos || gapTo > to2.pos)
33024
33150
  return null;
33025
33151
  return new ReplaceAroundStep(from2.pos, to2.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
@@ -33132,7 +33258,7 @@ function removeMark(tr2, from2, to2, mark) {
33132
33258
  });
33133
33259
  matched.forEach((m2) => tr2.step(new RemoveMarkStep(m2.from, m2.to, m2.style)));
33134
33260
  }
33135
- function clearIncompatible(tr2, pos, parentType, match2 = parentType.contentMatch) {
33261
+ function clearIncompatible(tr2, pos, parentType, match2 = parentType.contentMatch, clearNewlines = true) {
33136
33262
  let node = tr2.doc.nodeAt(pos);
33137
33263
  let replSteps = [], cur = pos + 1;
33138
33264
  for (let i2 = 0; i2 < node.childCount; i2++) {
@@ -33145,7 +33271,7 @@ function clearIncompatible(tr2, pos, parentType, match2 = parentType.contentMatc
33145
33271
  for (let j2 = 0; j2 < child.marks.length; j2++)
33146
33272
  if (!parentType.allowsMarkType(child.marks[j2].type))
33147
33273
  tr2.step(new RemoveMarkStep(cur, end2, child.marks[j2]));
33148
- if (child.isText && !parentType.spec.code) {
33274
+ if (clearNewlines && child.isText && parentType.whitespace != "pre") {
33149
33275
  let m2, newline = /\r?\n|\r/g, slice4;
33150
33276
  while (m2 = newline.exec(child.text)) {
33151
33277
  if (!slice4)
@@ -33254,14 +33380,45 @@ function setBlockType$1(tr2, from2, to2, type3, attrs) {
33254
33380
  let mapFrom = tr2.steps.length;
33255
33381
  tr2.doc.nodesBetween(from2, to2, (node, pos) => {
33256
33382
  if (node.isTextblock && !node.hasMarkup(type3, attrs) && canChangeType(tr2.doc, tr2.mapping.slice(mapFrom).map(pos), type3)) {
33257
- tr2.clearIncompatible(tr2.mapping.slice(mapFrom).map(pos, 1), type3);
33383
+ let convertNewlines = null;
33384
+ if (type3.schema.linebreakReplacement) {
33385
+ let pre = type3.whitespace == "pre", supportLinebreak = !!type3.contentMatch.matchType(type3.schema.linebreakReplacement);
33386
+ if (pre && !supportLinebreak)
33387
+ convertNewlines = false;
33388
+ else if (!pre && supportLinebreak)
33389
+ convertNewlines = true;
33390
+ }
33391
+ if (convertNewlines === false)
33392
+ replaceLinebreaks(tr2, node, pos, mapFrom);
33393
+ clearIncompatible(tr2, tr2.mapping.slice(mapFrom).map(pos, 1), type3, void 0, convertNewlines === null);
33258
33394
  let mapping = tr2.mapping.slice(mapFrom);
33259
33395
  let startM = mapping.map(pos, 1), endM = mapping.map(pos + node.nodeSize, 1);
33260
33396
  tr2.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1, new Slice(Fragment.from(type3.create(attrs, null, node.marks)), 0, 0), 1, true));
33397
+ if (convertNewlines === true)
33398
+ replaceNewlines(tr2, node, pos, mapFrom);
33261
33399
  return false;
33262
33400
  }
33263
33401
  });
33264
33402
  }
33403
+ function replaceNewlines(tr2, node, pos, mapFrom) {
33404
+ node.forEach((child, offset2) => {
33405
+ if (child.isText) {
33406
+ let m2, newline = /\r?\n|\r/g;
33407
+ while (m2 = newline.exec(child.text)) {
33408
+ let start2 = tr2.mapping.slice(mapFrom).map(pos + 1 + offset2 + m2.index);
33409
+ tr2.replaceWith(start2, start2 + 1, node.type.schema.linebreakReplacement.create());
33410
+ }
33411
+ }
33412
+ });
33413
+ }
33414
+ function replaceLinebreaks(tr2, node, pos, mapFrom) {
33415
+ node.forEach((child, offset2) => {
33416
+ if (child.type == child.type.schema.linebreakReplacement) {
33417
+ let start2 = tr2.mapping.slice(mapFrom).map(pos + 1 + offset2);
33418
+ tr2.replaceWith(start2, start2 + 1, node.type.schema.text("\n"));
33419
+ }
33420
+ });
33421
+ }
33265
33422
  function canChangeType(doc2, pos, type3) {
33266
33423
  let $pos = doc2.resolve(pos), index2 = $pos.index();
33267
33424
  return $pos.parent.canReplaceWith(index2, index2 + 1, type3);
@@ -35027,6 +35184,9 @@ const textRange = function(node, from2, to2) {
35027
35184
  range2.setStart(node, from2 || 0);
35028
35185
  return range2;
35029
35186
  };
35187
+ const clearReusedRange = function() {
35188
+ reusedRange = null;
35189
+ };
35030
35190
  const isEquivalentPosition = function(node, off2, targetNode, targetOff) {
35031
35191
  return targetNode && (scanFor(node, off2, targetNode, targetOff, -1) || scanFor(node, off2, targetNode, targetOff, 1));
35032
35192
  };
@@ -35054,6 +35214,40 @@ function scanFor(node, off2, targetNode, targetOff, dir) {
35054
35214
  function nodeSize(node) {
35055
35215
  return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length;
35056
35216
  }
35217
+ function textNodeBefore$1(node, offset2) {
35218
+ for (; ; ) {
35219
+ if (node.nodeType == 3 && offset2)
35220
+ return node;
35221
+ if (node.nodeType == 1 && offset2 > 0) {
35222
+ if (node.contentEditable == "false")
35223
+ return null;
35224
+ node = node.childNodes[offset2 - 1];
35225
+ offset2 = nodeSize(node);
35226
+ } else if (node.parentNode && !hasBlockDesc(node)) {
35227
+ offset2 = domIndex(node);
35228
+ node = node.parentNode;
35229
+ } else {
35230
+ return null;
35231
+ }
35232
+ }
35233
+ }
35234
+ function textNodeAfter$1(node, offset2) {
35235
+ for (; ; ) {
35236
+ if (node.nodeType == 3 && offset2 < node.nodeValue.length)
35237
+ return node;
35238
+ if (node.nodeType == 1 && offset2 < node.childNodes.length) {
35239
+ if (node.contentEditable == "false")
35240
+ return null;
35241
+ node = node.childNodes[offset2];
35242
+ offset2 = 0;
35243
+ } else if (node.parentNode && !hasBlockDesc(node)) {
35244
+ offset2 = domIndex(node) + 1;
35245
+ node = node.parentNode;
35246
+ } else {
35247
+ return null;
35248
+ }
35249
+ }
35250
+ }
35057
35251
  function isOnEdge(node, offset2, parent) {
35058
35252
  for (let atStart = offset2 == 0, atEnd = offset2 == nodeSize(node); atStart || atEnd; ) {
35059
35253
  if (node == parent)
@@ -35125,6 +35319,14 @@ const android = /Android \d/.test(agent);
35125
35319
  const webkit = !!doc && "webkitFontSmoothing" in doc.documentElement.style;
35126
35320
  const webkit_version = webkit ? +(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent) || [0, 0])[1] : 0;
35127
35321
  function windowRect(doc2) {
35322
+ let vp = doc2.defaultView && doc2.defaultView.visualViewport;
35323
+ if (vp)
35324
+ return {
35325
+ left: 0,
35326
+ right: vp.width,
35327
+ top: 0,
35328
+ bottom: vp.height
35329
+ };
35128
35330
  return {
35129
35331
  left: 0,
35130
35332
  right: doc2.documentElement.clientWidth,
@@ -35326,14 +35528,14 @@ function posFromCaret(view, node, offset2, coords) {
35326
35528
  let desc = view.docView.nearestDesc(cur, true);
35327
35529
  if (!desc)
35328
35530
  return null;
35329
- if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent && !sawBlock || !desc.contentDOM)) {
35531
+ if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent || !desc.contentDOM)) {
35330
35532
  let rect = desc.dom.getBoundingClientRect();
35331
- if (desc.node.isBlock && desc.parent && !sawBlock) {
35332
- sawBlock = true;
35333
- if (rect.left > coords.left || rect.top > coords.top)
35533
+ if (desc.node.isBlock && desc.parent) {
35534
+ if (!sawBlock && rect.left > coords.left || rect.top > coords.top)
35334
35535
  outsideBlock = desc.posBefore;
35335
- else if (rect.right < coords.left || rect.bottom < coords.top)
35536
+ else if (!sawBlock && rect.right < coords.left || rect.bottom < coords.top)
35336
35537
  outsideBlock = desc.posAfter;
35538
+ sawBlock = true;
35337
35539
  }
35338
35540
  if (!desc.contentDOM && outsideBlock < 0 && !desc.node.isText) {
35339
35541
  let before = desc.node.isBlock ? coords.top < (rect.top + rect.bottom) / 2 : coords.left < (rect.left + rect.right) / 2;
@@ -35948,6 +36150,9 @@ class ViewDesc {
35948
36150
  get ignoreForCoords() {
35949
36151
  return false;
35950
36152
  }
36153
+ isText(text) {
36154
+ return false;
36155
+ }
35951
36156
  }
35952
36157
  class WidgetViewDesc extends ViewDesc {
35953
36158
  constructor(parent, widget, view, pos) {
@@ -36186,8 +36391,7 @@ class NodeViewDesc extends ViewDesc {
36186
36391
  let { from: from2, to: to2 } = view.state.selection;
36187
36392
  if (!(view.state.selection instanceof TextSelection) || from2 < pos || to2 > pos + this.node.content.size)
36188
36393
  return null;
36189
- let sel = view.domSelectionRange();
36190
- let textNode = nearbyTextNode(sel.focusNode, sel.focusOffset);
36394
+ let textNode = view.input.compositionNode;
36191
36395
  if (!textNode || !this.dom.contains(textNode.parentNode))
36192
36396
  return null;
36193
36397
  if (this.node.inlineContent) {
@@ -36253,10 +36457,11 @@ class NodeViewDesc extends ViewDesc {
36253
36457
  }
36254
36458
  // Remove selected node marking from this node.
36255
36459
  deselectNode() {
36256
- if (this.nodeDOM.nodeType == 1)
36460
+ if (this.nodeDOM.nodeType == 1) {
36257
36461
  this.nodeDOM.classList.remove("ProseMirror-selectednode");
36258
- if (this.contentDOM || !this.node.type.spec.draggable)
36259
- this.dom.removeAttribute("draggable");
36462
+ if (this.contentDOM || !this.node.type.spec.draggable)
36463
+ this.dom.removeAttribute("draggable");
36464
+ }
36260
36465
  }
36261
36466
  get domAtom() {
36262
36467
  return this.node.isAtom;
@@ -36322,6 +36527,9 @@ class TextViewDesc extends NodeViewDesc {
36322
36527
  get domAtom() {
36323
36528
  return false;
36324
36529
  }
36530
+ isText(text) {
36531
+ return this.node.text == text;
36532
+ }
36325
36533
  }
36326
36534
  class TrailingHackViewDesc extends ViewDesc {
36327
36535
  parseRule() {
@@ -36837,23 +37045,6 @@ function iosHacks(dom) {
36837
37045
  dom.style.cssText = oldCSS;
36838
37046
  }
36839
37047
  }
36840
- function nearbyTextNode(node, offset2) {
36841
- for (; ; ) {
36842
- if (node.nodeType == 3)
36843
- return node;
36844
- if (node.nodeType == 1 && offset2 > 0) {
36845
- if (node.childNodes.length > offset2 && node.childNodes[offset2].nodeType == 3)
36846
- return node.childNodes[offset2];
36847
- node = node.childNodes[offset2 - 1];
36848
- offset2 = nodeSize(node);
36849
- } else if (node.nodeType == 1 && offset2 < node.childNodes.length) {
36850
- node = node.childNodes[offset2];
36851
- offset2 = 0;
36852
- } else {
36853
- return null;
36854
- }
36855
- }
36856
- }
36857
37048
  function findTextInFragment(frag, text, from2, to2) {
36858
37049
  for (let i2 = 0, pos = 0; i2 < frag.childCount && pos <= to2; ) {
36859
37050
  let child = frag.child(i2++), childStart = pos;
@@ -37428,7 +37619,7 @@ function serializeForClipboard(view, slice4) {
37428
37619
  if (firstChild && firstChild.nodeType == 1)
37429
37620
  firstChild.setAttribute("data-pm-slice", `${openStart} ${openEnd}${wrappers ? ` -${wrappers}` : ""} ${JSON.stringify(context)}`);
37430
37621
  let text = view.someProp("clipboardTextSerializer", (f2) => f2(slice4, view)) || slice4.content.textBetween(0, slice4.content.size, "\n\n");
37431
- return { dom: wrap2, text };
37622
+ return { dom: wrap2, text, slice: slice4 };
37432
37623
  }
37433
37624
  function parseFromClipboard(view, text, html, plainText, $context) {
37434
37625
  let inCode = $context.parent.type.spec.code;
@@ -37648,6 +37839,7 @@ class InputState {
37648
37839
  this.lastTouch = 0;
37649
37840
  this.lastAndroidDelete = 0;
37650
37841
  this.composing = false;
37842
+ this.compositionNode = null;
37651
37843
  this.composingTimeout = -1;
37652
37844
  this.compositionNodes = [];
37653
37845
  this.compositionEndedAt = -2e8;
@@ -37897,7 +38089,7 @@ class MouseDown {
37897
38089
  }
37898
38090
  const target = flushed ? null : event.target;
37899
38091
  const targetDesc = target ? view.docView.nearestDesc(target, true) : null;
37900
- this.target = targetDesc ? targetDesc.dom : null;
38092
+ this.target = targetDesc && targetDesc.dom.nodeType == 1 ? targetDesc.dom : null;
37901
38093
  let { selection } = view.state;
37902
38094
  if (event.button == 0 && targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false || selection instanceof NodeSelection && selection.from <= targetPos && selection.to > targetPos)
37903
38095
  this.mightDrag = {
@@ -38029,6 +38221,7 @@ editHandlers.compositionend = (view, event) => {
38029
38221
  view.input.composing = false;
38030
38222
  view.input.compositionEndedAt = event.timeStamp;
38031
38223
  view.input.compositionPendingChanges = view.domObserver.pendingRecords().length ? view.input.compositionID : 0;
38224
+ view.input.compositionNode = null;
38032
38225
  if (view.input.compositionPendingChanges)
38033
38226
  Promise.resolve().then(() => view.domObserver.flush());
38034
38227
  view.input.compositionID++;
@@ -38048,6 +38241,26 @@ function clearComposition(view) {
38048
38241
  while (view.input.compositionNodes.length > 0)
38049
38242
  view.input.compositionNodes.pop().markParentsDirty();
38050
38243
  }
38244
+ function findCompositionNode(view) {
38245
+ let sel = view.domSelectionRange();
38246
+ if (!sel.focusNode)
38247
+ return null;
38248
+ let textBefore = textNodeBefore$1(sel.focusNode, sel.focusOffset);
38249
+ let textAfter = textNodeAfter$1(sel.focusNode, sel.focusOffset);
38250
+ if (textBefore && textAfter && textBefore != textAfter) {
38251
+ let descAfter = textAfter.pmViewDesc, lastChanged = view.domObserver.lastChangedTextNode;
38252
+ if (textBefore == lastChanged || textAfter == lastChanged)
38253
+ return lastChanged;
38254
+ if (!descAfter || !descAfter.isText(textAfter.nodeValue)) {
38255
+ return textAfter;
38256
+ } else if (view.input.compositionNode == textAfter) {
38257
+ let descBefore = textBefore.pmViewDesc;
38258
+ if (!(!descBefore || !descBefore.isText(textBefore.nodeValue)))
38259
+ return textAfter;
38260
+ }
38261
+ }
38262
+ return textBefore || textAfter;
38263
+ }
38051
38264
  function timestampFromCustomEvent() {
38052
38265
  let event = document.createEvent("Event");
38053
38266
  event.initEvent("event", true, true);
@@ -38182,7 +38395,8 @@ handlers.dragstart = (view, _event) => {
38182
38395
  if (desc && desc.node.type.spec.draggable && desc != view.docView)
38183
38396
  node = NodeSelection.create(view.state.doc, desc.posBefore);
38184
38397
  }
38185
- let slice4 = (node || view.state.selection).content(), { dom, text } = serializeForClipboard(view, slice4);
38398
+ let draggedSlice = (node || view.state.selection).content();
38399
+ let { dom, text, slice: slice4 } = serializeForClipboard(view, draggedSlice);
38186
38400
  event.dataTransfer.clearData();
38187
38401
  event.dataTransfer.setData(brokenClipboardAPI ? "Text" : "text/html", dom.innerHTML);
38188
38402
  event.dataTransfer.effectAllowed = "copyMove";
@@ -38602,9 +38816,6 @@ class DecorationSet {
38602
38816
  return this;
38603
38817
  return local.length || children2.length ? new DecorationSet(local, children2) : empty$1;
38604
38818
  }
38605
- /**
38606
- @internal
38607
- */
38608
38819
  forChild(offset2, node) {
38609
38820
  if (this == empty$1)
38610
38821
  return this;
@@ -38958,6 +39169,7 @@ class DOMObserver {
38958
39169
  this.currentSelection = new SelectionState();
38959
39170
  this.onCharData = null;
38960
39171
  this.suppressingSelectionUpdates = false;
39172
+ this.lastChangedTextNode = null;
38961
39173
  this.observer = window.MutationObserver && new window.MutationObserver((mutations) => {
38962
39174
  for (let i2 = 0; i2 < mutations.length; i2++)
38963
39175
  this.queue.push(mutations[i2]);
@@ -39083,14 +39295,21 @@ class DOMObserver {
39083
39295
  }
39084
39296
  }
39085
39297
  }
39086
- if (gecko && added.length > 1) {
39298
+ if (gecko && added.length) {
39087
39299
  let brs = added.filter((n2) => n2.nodeName == "BR");
39088
39300
  if (brs.length == 2) {
39089
- let a2 = brs[0], b2 = brs[1];
39301
+ let [a2, b2] = brs;
39090
39302
  if (a2.parentNode && a2.parentNode.parentNode == b2.parentNode)
39091
39303
  b2.remove();
39092
39304
  else
39093
39305
  a2.remove();
39306
+ } else {
39307
+ let { focusNode } = this.currentSelection;
39308
+ for (let br2 of brs) {
39309
+ let parent = br2.parentNode;
39310
+ if (parent && parent.nodeName == "LI" && (!focusNode || blockParent(view, focusNode) != parent))
39311
+ br2.remove();
39312
+ }
39094
39313
  }
39095
39314
  }
39096
39315
  let readSel = null;
@@ -39122,8 +39341,12 @@ class DOMObserver {
39122
39341
  if (!desc || desc.ignoreMutation(mut))
39123
39342
  return null;
39124
39343
  if (mut.type == "childList") {
39125
- for (let i2 = 0; i2 < mut.addedNodes.length; i2++)
39126
- added.push(mut.addedNodes[i2]);
39344
+ for (let i2 = 0; i2 < mut.addedNodes.length; i2++) {
39345
+ let node = mut.addedNodes[i2];
39346
+ added.push(node);
39347
+ if (node.nodeType == 3)
39348
+ this.lastChangedTextNode = node;
39349
+ }
39127
39350
  if (desc.contentDOM && desc.contentDOM != desc.dom && !desc.contentDOM.contains(mut.target))
39128
39351
  return { from: desc.posBefore, to: desc.posAfter };
39129
39352
  let prev = mut.previousSibling, next = mut.nextSibling;
@@ -39144,6 +39367,7 @@ class DOMObserver {
39144
39367
  } else if (mut.type == "attributes") {
39145
39368
  return { from: desc.posAtStart - desc.border, to: desc.posAtEnd + desc.border };
39146
39369
  } else {
39370
+ this.lastChangedTextNode = mut.target;
39147
39371
  return {
39148
39372
  from: desc.posAtStart,
39149
39373
  to: desc.posAtEnd,
@@ -39170,7 +39394,20 @@ function checkCSS(view) {
39170
39394
  cssCheckWarned = true;
39171
39395
  }
39172
39396
  }
39173
- function safariShadowSelectionRange(view) {
39397
+ function rangeToSelectionRange(view, range2) {
39398
+ let anchorNode = range2.startContainer, anchorOffset = range2.startOffset;
39399
+ let focusNode = range2.endContainer, focusOffset = range2.endOffset;
39400
+ let currentAnchor = view.domAtPos(view.state.selection.anchor);
39401
+ if (isEquivalentPosition(currentAnchor.node, currentAnchor.offset, focusNode, focusOffset))
39402
+ [anchorNode, anchorOffset, focusNode, focusOffset] = [focusNode, focusOffset, anchorNode, anchorOffset];
39403
+ return { anchorNode, anchorOffset, focusNode, focusOffset };
39404
+ }
39405
+ function safariShadowSelectionRange(view, selection) {
39406
+ if (selection.getComposedRanges) {
39407
+ let range2 = selection.getComposedRanges(view.root)[0];
39408
+ if (range2)
39409
+ return rangeToSelectionRange(view, range2);
39410
+ }
39174
39411
  let found2;
39175
39412
  function read2(event) {
39176
39413
  event.preventDefault();
@@ -39180,12 +39417,15 @@ function safariShadowSelectionRange(view) {
39180
39417
  view.dom.addEventListener("beforeinput", read2, true);
39181
39418
  document.execCommand("indent");
39182
39419
  view.dom.removeEventListener("beforeinput", read2, true);
39183
- let anchorNode = found2.startContainer, anchorOffset = found2.startOffset;
39184
- let focusNode = found2.endContainer, focusOffset = found2.endOffset;
39185
- let currentAnchor = view.domAtPos(view.state.selection.anchor);
39186
- if (isEquivalentPosition(currentAnchor.node, currentAnchor.offset, focusNode, focusOffset))
39187
- [anchorNode, anchorOffset, focusNode, focusOffset] = [focusNode, focusOffset, anchorNode, anchorOffset];
39188
- return { anchorNode, anchorOffset, focusNode, focusOffset };
39420
+ return found2 ? rangeToSelectionRange(view, found2) : null;
39421
+ }
39422
+ function blockParent(view, node) {
39423
+ for (let p2 = node.parentNode; p2 && p2 != view.dom; p2 = p2.parentNode) {
39424
+ let desc = view.docView.nearestDesc(p2, true);
39425
+ if (desc && desc.node.isBlock)
39426
+ return p2;
39427
+ }
39428
+ return null;
39189
39429
  }
39190
39430
  function parseBetween(view, from_, to_) {
39191
39431
  let { node: parent, fromOffset, toOffset, from: from2, to: to2 } = view.docView.parseRange(from_, to_);
@@ -39305,10 +39545,6 @@ function readDOMChange(view, from2, to2, typeOver, addedNodes) {
39305
39545
  return;
39306
39546
  }
39307
39547
  }
39308
- if (chrome && view.cursorWrapper && parse2.sel && parse2.sel.anchor == view.cursorWrapper.deco.from && parse2.sel.head == parse2.sel.anchor) {
39309
- let size2 = change.endB - change.start;
39310
- parse2.sel = { anchor: parse2.sel.anchor + size2, head: parse2.sel.anchor + size2 };
39311
- }
39312
39548
  view.input.domChangeCount++;
39313
39549
  if (view.state.selection.from < view.state.selection.to && change.start == change.endB && view.state.selection instanceof TextSelection) {
39314
39550
  if (change.start > view.state.selection.from && change.start <= view.state.selection.from + 2 && view.state.selection.from >= parse2.from) {
@@ -39332,7 +39568,7 @@ function readDOMChange(view, from2, to2, typeOver, addedNodes) {
39332
39568
  view.input.lastIOSEnter = 0;
39333
39569
  return;
39334
39570
  }
39335
- if (view.state.selection.anchor > change.start && looksLikeJoin(doc2, change.start, change.endA, $from, $to) && view.someProp("handleKeyDown", (f2) => f2(view, keyEvent(8, "Backspace")))) {
39571
+ if (view.state.selection.anchor > change.start && looksLikeBackspace(doc2, change.start, change.endA, $from, $to) && view.someProp("handleKeyDown", (f2) => f2(view, keyEvent(8, "Backspace")))) {
39336
39572
  if (android && chrome)
39337
39573
  view.domObserver.suppressSelectionUpdates();
39338
39574
  return;
@@ -39416,12 +39652,18 @@ function isMarkChange(cur, prev) {
39416
39652
  if (Fragment.from(updated).eq(cur))
39417
39653
  return { mark, type: type3 };
39418
39654
  }
39419
- function looksLikeJoin(old, start2, end2, $newStart, $newEnd) {
39420
- if (!$newStart.parent.isTextblock || // The content must have shrunk
39421
- end2 - start2 <= $newEnd.pos - $newStart.pos || // newEnd must point directly at or after the end of the block that newStart points into
39422
- skipClosingAndOpening($newStart, true, false) < $newEnd.pos)
39655
+ function looksLikeBackspace(old, start2, end2, $newStart, $newEnd) {
39656
+ if (
39657
+ // The content must have shrunk
39658
+ end2 - start2 <= $newEnd.pos - $newStart.pos || // newEnd must point directly at or after the end of the block that newStart points into
39659
+ skipClosingAndOpening($newStart, true, false) < $newEnd.pos
39660
+ )
39423
39661
  return false;
39424
39662
  let $start = old.resolve(start2);
39663
+ if (!$newStart.parent.isTextblock) {
39664
+ let after = $start.nodeAfter;
39665
+ return after != null && end2 == start2 + after.nodeSize;
39666
+ }
39425
39667
  if ($start.parentOffset < $start.parent.content.size || !$start.parent.isTextblock)
39426
39668
  return false;
39427
39669
  let $next = old.resolve(skipClosingAndOpening($start, true, true));
@@ -39610,8 +39852,10 @@ class EditorView {
39610
39852
  let forceSelUpdate = updateDoc && (ie$1 || chrome) && !this.composing && !prev.selection.empty && !state2.selection.empty && selectionContextChanged(prev.selection, state2.selection);
39611
39853
  if (updateDoc) {
39612
39854
  let chromeKludge = chrome ? this.trackWrites = this.domSelectionRange().focusNode : null;
39855
+ if (this.composing)
39856
+ this.input.compositionNode = findCompositionNode(this);
39613
39857
  if (redraw || !this.docView.update(state2.doc, outerDeco, innerDeco, this)) {
39614
- this.docView.updateOuterDeco([]);
39858
+ this.docView.updateOuterDeco(outerDeco);
39615
39859
  this.docView.destroy();
39616
39860
  this.docView = docViewDesc(state2.doc, outerDeco, innerDeco, this.dom, this);
39617
39861
  }
@@ -39870,6 +40114,7 @@ class EditorView {
39870
40114
  }
39871
40115
  this.docView.destroy();
39872
40116
  this.docView = null;
40117
+ clearReusedRange();
39873
40118
  }
39874
40119
  /**
39875
40120
  This is true when the view has been
@@ -39905,7 +40150,8 @@ class EditorView {
39905
40150
  @internal
39906
40151
  */
39907
40152
  domSelectionRange() {
39908
- return safari && this.root.nodeType === 11 && deepActiveElement(this.dom.ownerDocument) == this.dom ? safariShadowSelectionRange(this) : this.domSelection();
40153
+ let sel = this.domSelection();
40154
+ return safari && this.root.nodeType === 11 && deepActiveElement(this.dom.ownerDocument) == this.dom && safariShadowSelectionRange(this, sel) || sel;
39909
40155
  }
39910
40156
  /**
39911
40157
  @internal
@@ -40896,7 +41142,8 @@ function getAttributesFromExtensions(extensions) {
40896
41142
  const context = {
40897
41143
  name: extension.name,
40898
41144
  options: extension.options,
40899
- storage: extension.storage
41145
+ storage: extension.storage,
41146
+ extensions: nodeAndMarkExtensions
40900
41147
  };
40901
41148
  const addGlobalAttributes = getExtensionField(extension, "addGlobalAttributes", context);
40902
41149
  if (!addGlobalAttributes) {
@@ -41022,7 +41269,7 @@ function fromString(value) {
41022
41269
  return value;
41023
41270
  }
41024
41271
  function injectExtensionAttributesToParseRule(parseRule, extensionAttributes) {
41025
- if (parseRule.style) {
41272
+ if ("style" in parseRule) {
41026
41273
  return parseRule;
41027
41274
  }
41028
41275
  return {
@@ -41087,6 +41334,7 @@ function getSchemaByResolvedExtensions(extensions, editor) {
41087
41334
  selectable: callOrReturn(getExtensionField(extension, "selectable", context)),
41088
41335
  draggable: callOrReturn(getExtensionField(extension, "draggable", context)),
41089
41336
  code: callOrReturn(getExtensionField(extension, "code", context)),
41337
+ whitespace: callOrReturn(getExtensionField(extension, "whitespace", context)),
41090
41338
  defining: callOrReturn(getExtensionField(extension, "defining", context)),
41091
41339
  isolating: callOrReturn(getExtensionField(extension, "isolating", context)),
41092
41340
  attrs: Object.fromEntries(extensionAttributes.map((extensionAttribute) => {
@@ -41642,7 +41890,7 @@ class ExtensionManager {
41642
41890
  const plugins2 = [];
41643
41891
  const addKeyboardShortcuts = getExtensionField(extension, "addKeyboardShortcuts", context);
41644
41892
  let defaultBindings = {};
41645
- if (extension.type === "mark" && extension.config.exitable) {
41893
+ if (extension.type === "mark" && getExtensionField(extension, "exitable", context)) {
41646
41894
  defaultBindings.ArrowRight = () => Mark.handleExit({ editor, mark: extension });
41647
41895
  }
41648
41896
  if (addKeyboardShortcuts) {
@@ -41790,14 +42038,10 @@ function mergeDeep(target, source) {
41790
42038
  const output = { ...target };
41791
42039
  if (isPlainObject(target) && isPlainObject(source)) {
41792
42040
  Object.keys(source).forEach((key) => {
41793
- if (isPlainObject(source[key])) {
41794
- if (!(key in target)) {
41795
- Object.assign(output, { [key]: source[key] });
41796
- } else {
41797
- output[key] = mergeDeep(target[key], source[key]);
41798
- }
42041
+ if (isPlainObject(source[key]) && isPlainObject(target[key])) {
42042
+ output[key] = mergeDeep(target[key], source[key]);
41799
42043
  } else {
41800
- Object.assign(output, { [key]: source[key] });
42044
+ output[key] = source[key];
41801
42045
  }
41802
42046
  });
41803
42047
  }
@@ -41836,13 +42080,15 @@ class Extension {
41836
42080
  return new Extension(config);
41837
42081
  }
41838
42082
  configure(options = {}) {
41839
- const extension = this.extend();
42083
+ const extension = this.extend({
42084
+ ...this.config,
42085
+ addOptions() {
42086
+ var _a2;
42087
+ return mergeDeep(((_a2 = this.parent) === null || _a2 === void 0 ? void 0 : _a2.call(this)) || {}, options);
42088
+ }
42089
+ });
42090
+ extension.name = this.name;
41840
42091
  extension.parent = this.parent;
41841
- extension.options = mergeDeep(this.options, options);
41842
- extension.storage = callOrReturn(getExtensionField(extension, "addStorage", {
41843
- name: extension.name,
41844
- options: extension.options
41845
- }));
41846
42092
  return extension;
41847
42093
  }
41848
42094
  extend(extendedConfig = {}) {
@@ -41850,7 +42096,7 @@ class Extension {
41850
42096
  extension.parent = this;
41851
42097
  this.child = extension;
41852
42098
  extension.name = extendedConfig.name ? extendedConfig.name : extension.parent.name;
41853
- if (extendedConfig.defaultOptions) {
42099
+ if (extendedConfig.defaultOptions && Object.keys(extendedConfig.defaultOptions).length > 0) {
41854
42100
  console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`);
41855
42101
  }
41856
42102
  extension.options = callOrReturn(getExtensionField(extension, "addOptions", {
@@ -42234,13 +42480,47 @@ function createNodeFromContent(content, schema, options) {
42234
42480
  }
42235
42481
  return schema.nodeFromJSON(content);
42236
42482
  } catch (error) {
42483
+ if (options.errorOnInvalidContent) {
42484
+ throw new Error("[tiptap error]: Invalid JSON content", { cause: error });
42485
+ }
42237
42486
  console.warn("[tiptap warn]: Invalid content.", "Passed value:", content, "Error:", error);
42238
42487
  return createNodeFromContent("", schema, options);
42239
42488
  }
42240
42489
  }
42241
42490
  if (isTextContent) {
42242
- const parser = DOMParser.fromSchema(schema);
42243
- return options.slice ? parser.parseSlice(elementFromString(content), options.parseOptions).content : parser.parse(elementFromString(content), options.parseOptions);
42491
+ let schemaToUse = schema;
42492
+ let hasInvalidContent = false;
42493
+ let invalidContent = "";
42494
+ if (options.errorOnInvalidContent) {
42495
+ schemaToUse = new Schema({
42496
+ topNode: schema.spec.topNode,
42497
+ marks: schema.spec.marks,
42498
+ // Prosemirror's schemas are executed such that: the last to execute, matches last
42499
+ // 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
42500
+ nodes: schema.spec.nodes.append({
42501
+ __tiptap__private__unknown__catch__all__node: {
42502
+ content: "inline*",
42503
+ group: "block",
42504
+ parseDOM: [
42505
+ {
42506
+ tag: "*",
42507
+ getAttrs: (e) => {
42508
+ hasInvalidContent = true;
42509
+ invalidContent = typeof e === "string" ? e : e.outerHTML;
42510
+ return null;
42511
+ }
42512
+ }
42513
+ ]
42514
+ }
42515
+ })
42516
+ });
42517
+ }
42518
+ const parser = DOMParser.fromSchema(schemaToUse);
42519
+ const response = options.slice ? parser.parseSlice(elementFromString(content), options.parseOptions).content : parser.parse(elementFromString(content), options.parseOptions);
42520
+ if (options.errorOnInvalidContent && hasInvalidContent) {
42521
+ throw new Error("[tiptap error]: Invalid HTML content", { cause: new Error(`Invalid element found: ${invalidContent}`) });
42522
+ }
42523
+ return response;
42244
42524
  }
42245
42525
  return createNodeFromContent("", schema, options);
42246
42526
  }
@@ -42263,9 +42543,10 @@ function selectionToInsertionEnd(tr2, startLen, bias) {
42263
42543
  tr2.setSelection(Selection$1.near(tr2.doc.resolve(end2), bias));
42264
42544
  }
42265
42545
  const isFragment = (nodeOrFragment) => {
42266
- return nodeOrFragment.toString().startsWith("<");
42546
+ return !("type" in nodeOrFragment);
42267
42547
  };
42268
42548
  const insertContentAt = (position, value, options) => ({ tr: tr2, dispatch, editor }) => {
42549
+ var _a2;
42269
42550
  if (dispatch) {
42270
42551
  options = {
42271
42552
  parseOptions: {},
@@ -42274,14 +42555,17 @@ const insertContentAt = (position, value, options) => ({ tr: tr2, dispatch, edit
42274
42555
  applyPasteRules: false,
42275
42556
  ...options
42276
42557
  };
42277
- const content = createNodeFromContent(value, editor.schema, {
42278
- parseOptions: {
42279
- preserveWhitespace: "full",
42280
- ...options.parseOptions
42281
- }
42282
- });
42283
- if (content.toString() === "<>") {
42284
- return true;
42558
+ let content;
42559
+ try {
42560
+ content = createNodeFromContent(value, editor.schema, {
42561
+ parseOptions: {
42562
+ preserveWhitespace: "full",
42563
+ ...options.parseOptions
42564
+ },
42565
+ errorOnInvalidContent: (_a2 = options.errorOnInvalidContent) !== null && _a2 !== void 0 ? _a2 : editor.options.enableContentCheck
42566
+ });
42567
+ } catch (e) {
42568
+ return false;
42285
42569
  }
42286
42570
  let { from: from2, to: to2 } = typeof position === "number" ? { from: position, to: position } : { from: position.from, to: position.to };
42287
42571
  let isOnlyTextContent = true;
@@ -42338,7 +42622,7 @@ const joinBackward = () => ({ state: state2, dispatch }) => {
42338
42622
  const joinForward = () => ({ state: state2, dispatch }) => {
42339
42623
  return joinForward$1(state2, dispatch);
42340
42624
  };
42341
- const joinItemBackward = () => ({ tr: tr2, state: state2, dispatch }) => {
42625
+ const joinItemBackward = () => ({ state: state2, dispatch, tr: tr2 }) => {
42342
42626
  try {
42343
42627
  const point2 = joinPoint(state2.doc, state2.selection.$from.pos, -1);
42344
42628
  if (point2 === null || point2 === void 0) {
@@ -42349,7 +42633,7 @@ const joinItemBackward = () => ({ tr: tr2, state: state2, dispatch }) => {
42349
42633
  dispatch(tr2);
42350
42634
  }
42351
42635
  return true;
42352
- } catch {
42636
+ } catch (e) {
42353
42637
  return false;
42354
42638
  }
42355
42639
  };
@@ -42567,16 +42851,32 @@ const selectTextblockEnd = () => ({ state: state2, dispatch }) => {
42567
42851
  const selectTextblockStart = () => ({ state: state2, dispatch }) => {
42568
42852
  return selectTextblockStart$1(state2, dispatch);
42569
42853
  };
42570
- function createDocument(content, schema, parseOptions = {}) {
42571
- return createNodeFromContent(content, schema, { slice: false, parseOptions });
42854
+ function createDocument(content, schema, parseOptions = {}, options = {}) {
42855
+ return createNodeFromContent(content, schema, {
42856
+ slice: false,
42857
+ parseOptions,
42858
+ errorOnInvalidContent: options.errorOnInvalidContent
42859
+ });
42572
42860
  }
42573
- const setContent$1 = (content, emitUpdate = false, parseOptions = {}) => ({ tr: tr2, editor, dispatch }) => {
42861
+ const setContent$1 = (content, emitUpdate = false, parseOptions = {}, options = {}) => ({ editor, tr: tr2, dispatch, commands: commands2 }) => {
42862
+ var _a2, _b;
42574
42863
  const { doc: doc2 } = tr2;
42575
- const document2 = createDocument(content, editor.schema, parseOptions);
42864
+ if (parseOptions.preserveWhitespace !== "full") {
42865
+ const document2 = createDocument(content, editor.schema, parseOptions, {
42866
+ errorOnInvalidContent: (_a2 = options.errorOnInvalidContent) !== null && _a2 !== void 0 ? _a2 : editor.options.enableContentCheck
42867
+ });
42868
+ if (dispatch) {
42869
+ tr2.replaceWith(0, doc2.content.size, document2).setMeta("preventUpdate", !emitUpdate);
42870
+ }
42871
+ return true;
42872
+ }
42576
42873
  if (dispatch) {
42577
- tr2.replaceWith(0, doc2.content.size, document2).setMeta("preventUpdate", !emitUpdate);
42874
+ tr2.setMeta("preventUpdate", !emitUpdate);
42578
42875
  }
42579
- return true;
42876
+ return commands2.insertContentAt({ from: 0, to: doc2.content.size }, content, {
42877
+ parseOptions,
42878
+ errorOnInvalidContent: (_b = options.errorOnInvalidContent) !== null && _b !== void 0 ? _b : editor.options.enableContentCheck
42879
+ });
42580
42880
  };
42581
42881
  function getMarkAttributes(state2, typeOrName) {
42582
42882
  const type3 = getMarkType(typeOrName, state2.schema);
@@ -42779,10 +43079,11 @@ function isList(name, extensions) {
42779
43079
  return group.split(" ").includes("list");
42780
43080
  }
42781
43081
  function isNodeEmpty(node) {
42782
- var _a2;
42783
- const defaultContent = (_a2 = node.type.createAndFill()) === null || _a2 === void 0 ? void 0 : _a2.toJSON();
42784
- const content = node.toJSON();
42785
- return JSON.stringify(defaultContent) === JSON.stringify(content);
43082
+ const defaultContent = node.type.createAndFill();
43083
+ if (!defaultContent) {
43084
+ return false;
43085
+ }
43086
+ return node.eq(defaultContent);
42786
43087
  }
42787
43088
  function isNodeSelection(value) {
42788
43089
  return value instanceof NodeSelection;
@@ -43297,14 +43598,14 @@ var commands = /* @__PURE__ */ Object.freeze({
43297
43598
  forEach,
43298
43599
  insertContent,
43299
43600
  insertContentAt,
43300
- joinUp,
43301
- joinDown,
43302
43601
  joinBackward,
43602
+ joinDown,
43303
43603
  joinForward,
43304
43604
  joinItemBackward,
43305
43605
  joinItemForward,
43306
43606
  joinTextblockBackward,
43307
43607
  joinTextblockForward,
43608
+ joinUp,
43308
43609
  keyboardShortcut,
43309
43610
  lift,
43310
43611
  liftEmptyBlock,
@@ -43501,13 +43802,16 @@ const Tabindex = Extension.create({
43501
43802
  new Plugin({
43502
43803
  key: new PluginKey("tabindex"),
43503
43804
  props: {
43504
- attributes: this.editor.isEditable ? { tabindex: "0" } : {}
43805
+ attributes: () => this.editor.isEditable ? { tabindex: "0" } : {}
43505
43806
  }
43506
43807
  })
43507
43808
  ];
43508
43809
  }
43509
43810
  });
43510
43811
  class NodePos {
43812
+ get name() {
43813
+ return this.node.type.name;
43814
+ }
43511
43815
  constructor(pos, editor, isBlock = false, node = null) {
43512
43816
  this.currentNode = null;
43513
43817
  this.actualDepth = null;
@@ -43516,9 +43820,6 @@ class NodePos {
43516
43820
  this.editor = editor;
43517
43821
  this.currentNode = node;
43518
43822
  }
43519
- get name() {
43520
- return this.node.type.name;
43521
- }
43522
43823
  get node() {
43523
43824
  return this.currentNode || this.resolvedPos.node();
43524
43825
  }
@@ -43782,6 +44083,7 @@ let Editor$1 = class Editor2 extends EventEmitter {
43782
44083
  enableInputRules: true,
43783
44084
  enablePasteRules: true,
43784
44085
  enableCoreExtensions: true,
44086
+ enableContentCheck: false,
43785
44087
  onBeforeCreate: () => null,
43786
44088
  onCreate: () => null,
43787
44089
  onUpdate: () => null,
@@ -43789,7 +44091,10 @@ let Editor$1 = class Editor2 extends EventEmitter {
43789
44091
  onTransaction: () => null,
43790
44092
  onFocus: () => null,
43791
44093
  onBlur: () => null,
43792
- onDestroy: () => null
44094
+ onDestroy: () => null,
44095
+ onContentError: ({ error }) => {
44096
+ throw error;
44097
+ }
43793
44098
  };
43794
44099
  this.isCapturingTransaction = false;
43795
44100
  this.capturedTransaction = null;
@@ -43799,6 +44104,7 @@ let Editor$1 = class Editor2 extends EventEmitter {
43799
44104
  this.createSchema();
43800
44105
  this.on("beforeCreate", this.options.onBeforeCreate);
43801
44106
  this.emit("beforeCreate", { editor: this });
44107
+ this.on("contentError", this.options.onContentError);
43802
44108
  this.createView();
43803
44109
  this.injectCSS();
43804
44110
  this.on("create", this.options.onCreate);
@@ -43952,7 +44258,23 @@ let Editor$1 = class Editor2 extends EventEmitter {
43952
44258
  * Creates a ProseMirror view.
43953
44259
  */
43954
44260
  createView() {
43955
- const doc2 = createDocument(this.options.content, this.schema, this.options.parseOptions);
44261
+ let doc2;
44262
+ try {
44263
+ doc2 = createDocument(this.options.content, this.schema, this.options.parseOptions, { errorOnInvalidContent: this.options.enableContentCheck });
44264
+ } catch (e) {
44265
+ if (!(e instanceof Error) || !["[tiptap error]: Invalid JSON content", "[tiptap error]: Invalid HTML content"].includes(e.message)) {
44266
+ throw e;
44267
+ }
44268
+ this.emit("contentError", {
44269
+ editor: this,
44270
+ error: e,
44271
+ disableCollaboration: () => {
44272
+ this.options.extensions = this.options.extensions.filter((extension) => extension.name !== "collaboration");
44273
+ this.createExtensionManager();
44274
+ }
44275
+ });
44276
+ doc2 = createDocument(this.options.content, this.schema, this.options.parseOptions, { errorOnInvalidContent: false });
44277
+ }
43956
44278
  const selection = resolveFocusPosition(doc2, this.options.autofocus);
43957
44279
  this.view = new EditorView(this.options.element, {
43958
44280
  ...this.options.editorProps,
@@ -44190,7 +44512,8 @@ function nodeInputRule(config) {
44190
44512
  tr2.insertText(lastChar, start2 + match2[0].length - 1);
44191
44513
  tr2.replaceWith(matchStart, end2, newNode);
44192
44514
  } else if (match2[0]) {
44193
- tr2.insert(start2 - 1, config.type.create(attributes)).delete(tr2.mapping.map(start2), tr2.mapping.map(end2));
44515
+ const insertionStart = config.type.isInline ? start2 : start2 - 1;
44516
+ tr2.insert(insertionStart, config.type.create(attributes)).delete(tr2.mapping.map(start2), tr2.mapping.map(end2));
44194
44517
  }
44195
44518
  tr2.scrollIntoView();
44196
44519
  }
@@ -44275,20 +44598,23 @@ class Mark {
44275
44598
  return new Mark(config);
44276
44599
  }
44277
44600
  configure(options = {}) {
44278
- const extension = this.extend();
44279
- extension.options = mergeDeep(this.options, options);
44280
- extension.storage = callOrReturn(getExtensionField(extension, "addStorage", {
44281
- name: extension.name,
44282
- options: extension.options
44283
- }));
44601
+ const extension = this.extend({
44602
+ ...this.config,
44603
+ addOptions() {
44604
+ var _a2;
44605
+ return mergeDeep(((_a2 = this.parent) === null || _a2 === void 0 ? void 0 : _a2.call(this)) || {}, options);
44606
+ }
44607
+ });
44608
+ extension.name = this.name;
44609
+ extension.parent = this.parent;
44284
44610
  return extension;
44285
44611
  }
44286
44612
  extend(extendedConfig = {}) {
44287
- const extension = new Mark({ ...this.config, ...extendedConfig });
44613
+ const extension = new Mark(extendedConfig);
44288
44614
  extension.parent = this;
44289
44615
  this.child = extension;
44290
44616
  extension.name = extendedConfig.name ? extendedConfig.name : extension.parent.name;
44291
- if (extendedConfig.defaultOptions) {
44617
+ if (extendedConfig.defaultOptions && Object.keys(extendedConfig.defaultOptions).length > 0) {
44292
44618
  console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`);
44293
44619
  }
44294
44620
  extension.options = callOrReturn(getExtensionField(extension, "addOptions", {
@@ -44354,20 +44680,23 @@ let Node$2 = class Node3 {
44354
44680
  return new Node3(config);
44355
44681
  }
44356
44682
  configure(options = {}) {
44357
- const extension = this.extend();
44358
- extension.options = mergeDeep(this.options, options);
44359
- extension.storage = callOrReturn(getExtensionField(extension, "addStorage", {
44360
- name: extension.name,
44361
- options: extension.options
44362
- }));
44683
+ const extension = this.extend({
44684
+ ...this.config,
44685
+ addOptions() {
44686
+ var _a2;
44687
+ return mergeDeep(((_a2 = this.parent) === null || _a2 === void 0 ? void 0 : _a2.call(this)) || {}, options);
44688
+ }
44689
+ });
44690
+ extension.name = this.name;
44691
+ extension.parent = this.parent;
44363
44692
  return extension;
44364
44693
  }
44365
44694
  extend(extendedConfig = {}) {
44366
- const extension = new Node3({ ...this.config, ...extendedConfig });
44695
+ const extension = new Node3(extendedConfig);
44367
44696
  extension.parent = this;
44368
44697
  this.child = extension;
44369
44698
  extension.name = extendedConfig.name ? extendedConfig.name : extension.parent.name;
44370
- if (extendedConfig.defaultOptions) {
44699
+ if (extendedConfig.defaultOptions && Object.keys(extendedConfig.defaultOptions).length > 0) {
44371
44700
  console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`);
44372
44701
  }
44373
44702
  extension.options = callOrReturn(getExtensionField(extension, "addOptions", {
@@ -44902,14 +45231,12 @@ const CodeBlock = Node$2.create({
44902
45231
  if (!text || !language) {
44903
45232
  return false;
44904
45233
  }
44905
- const { tr: tr2 } = view.state;
44906
- if (view.state.selection.from === view.state.doc.nodeSize - (1 + view.state.selection.$to.depth * 2)) {
44907
- tr2.insert(view.state.selection.from - 1, this.type.create({ language }));
44908
- } else {
44909
- tr2.replaceSelectionWith(this.type.create({ language }));
45234
+ const { tr: tr2, schema } = view.state;
45235
+ const textNode = schema.text(text.replace(/\r\n?/g, "\n"));
45236
+ tr2.replaceSelectionWith(this.type.create({ language }, textNode));
45237
+ if (tr2.selection.$from.parent.type !== this.type) {
45238
+ tr2.setSelection(TextSelection.near(tr2.doc.resolve(Math.max(0, tr2.selection.from - 2))));
44910
45239
  }
44911
- tr2.setSelection(TextSelection.near(tr2.doc.resolve(Math.max(0, tr2.selection.from - 2))));
44912
- tr2.insertText(text.replace(/\r\n?/g, "\n"));
44913
45240
  tr2.setMeta("paste", true);
44914
45241
  view.dispatch(tr2);
44915
45242
  return true;
@@ -45825,13 +46152,13 @@ function applyTransaction(history2, state2, tr2, options) {
45825
46152
  return history2;
45826
46153
  } else if (appended && appended.getMeta(historyKey)) {
45827
46154
  if (appended.getMeta(historyKey).redo)
45828
- 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);
46155
+ return new HistoryState(history2.done.addTransform(tr2, void 0, options, mustPreserveItems(state2)), history2.undone, rangesFor(tr2.mapping.maps), history2.prevTime, history2.prevComposition);
45829
46156
  else
45830
46157
  return new HistoryState(history2.done, history2.undone.addTransform(tr2, void 0, options, mustPreserveItems(state2)), null, history2.prevTime, history2.prevComposition);
45831
46158
  } else if (tr2.getMeta("addToHistory") !== false && !(appended && appended.getMeta("addToHistory") === false)) {
45832
46159
  let composition = tr2.getMeta("composition");
45833
46160
  let newGroup = history2.prevTime == 0 || !appended && history2.prevComposition != composition && (history2.prevTime < (tr2.time || 0) - options.newGroupDelay || !isAdjacentTo(tr2, history2.prevRanges));
45834
- let prevRanges = appended ? mapRanges(history2.prevRanges, tr2.mapping) : rangesFor(tr2.mapping.maps[tr2.steps.length - 1]);
46161
+ let prevRanges = appended ? mapRanges(history2.prevRanges, tr2.mapping) : rangesFor(tr2.mapping.maps);
45835
46162
  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);
45836
46163
  } else if (rebased = tr2.getMeta("rebased")) {
45837
46164
  return new HistoryState(history2.done.rebased(tr2, rebased), history2.undone.rebased(tr2, rebased), mapRanges(history2.prevRanges, tr2.mapping), history2.prevTime, history2.prevComposition);
@@ -45852,9 +46179,10 @@ function isAdjacentTo(transform, prevRanges) {
45852
46179
  });
45853
46180
  return adjacent;
45854
46181
  }
45855
- function rangesFor(map4) {
46182
+ function rangesFor(maps) {
45856
46183
  let result2 = [];
45857
- map4.forEach((_from, _to, from2, to2) => result2.push(from2, to2));
46184
+ for (let i2 = maps.length - 1; i2 >= 0 && result2.length == 0; i2--)
46185
+ maps[i2].forEach((_from, _to, from2, to2) => result2.push(from2, to2));
45858
46186
  return result2;
45859
46187
  }
45860
46188
  function mapRanges(ranges, mapping) {
@@ -45868,16 +46196,16 @@ function mapRanges(ranges, mapping) {
45868
46196
  }
45869
46197
  return result2;
45870
46198
  }
45871
- function histTransaction(history2, state2, dispatch, redo2) {
46199
+ function histTransaction(history2, state2, redo2) {
45872
46200
  let preserveItems = mustPreserveItems(state2);
45873
46201
  let histOptions = historyKey.get(state2).spec.config;
45874
46202
  let pop = (redo2 ? history2.undone : history2.done).popEvent(state2, preserveItems);
45875
46203
  if (!pop)
45876
- return;
46204
+ return null;
45877
46205
  let selection = pop.selection.resolve(pop.transform.doc);
45878
46206
  let added = (redo2 ? history2.done : history2.undone).addTransform(pop.transform, state2.selection.getBookmark(), histOptions, preserveItems);
45879
46207
  let newHist = new HistoryState(redo2 ? added : pop.remaining, redo2 ? pop.remaining : added, null, 0, -1);
45880
- dispatch(pop.transform.setSelection(selection).setMeta(historyKey, { redo: redo2, historyState: newHist }).scrollIntoView());
46208
+ return pop.transform.setSelection(selection).setMeta(historyKey, { redo: redo2, historyState: newHist });
45881
46209
  }
45882
46210
  let cachedPreserveItems = false, cachedPreserveItemsPlugins = null;
45883
46211
  function mustPreserveItems(state2) {
@@ -45925,22 +46253,21 @@ function history(config = {}) {
45925
46253
  }
45926
46254
  });
45927
46255
  }
45928
- const undo = (state2, dispatch) => {
45929
- let hist = historyKey.getState(state2);
45930
- if (!hist || hist.done.eventCount == 0)
45931
- return false;
45932
- if (dispatch)
45933
- histTransaction(hist, state2, dispatch, false);
45934
- return true;
45935
- };
45936
- const redo = (state2, dispatch) => {
45937
- let hist = historyKey.getState(state2);
45938
- if (!hist || hist.undone.eventCount == 0)
45939
- return false;
45940
- if (dispatch)
45941
- histTransaction(hist, state2, dispatch, true);
45942
- return true;
45943
- };
46256
+ function buildCommand(redo2, scroll) {
46257
+ return (state2, dispatch) => {
46258
+ let hist = historyKey.getState(state2);
46259
+ if (!hist || (redo2 ? hist.undone : hist.done).eventCount == 0)
46260
+ return false;
46261
+ if (dispatch) {
46262
+ let tr2 = histTransaction(hist, state2, redo2);
46263
+ if (tr2)
46264
+ dispatch(scroll ? tr2.scrollIntoView() : tr2);
46265
+ }
46266
+ return true;
46267
+ };
46268
+ }
46269
+ const undo = buildCommand(false, true);
46270
+ const redo = buildCommand(true, true);
45944
46271
  const History = Extension.create({
45945
46272
  name: "history",
45946
46273
  addOptions() {
@@ -45992,10 +46319,20 @@ const HorizontalRule = Node$2.create({
45992
46319
  addCommands() {
45993
46320
  return {
45994
46321
  setHorizontalRule: () => ({ chain, state: state2 }) => {
45995
- const { $to: $originTo } = state2.selection;
46322
+ const { selection } = state2;
46323
+ const { $from: $originFrom, $to: $originTo } = selection;
45996
46324
  const currentChain = chain();
45997
- if ($originTo.parentOffset === 0) {
45998
- currentChain.insertContentAt(Math.max($originTo.pos - 2, 0), { type: this.name });
46325
+ if ($originFrom.parentOffset === 0) {
46326
+ currentChain.insertContentAt({
46327
+ from: Math.max($originFrom.pos - 1, 0),
46328
+ to: $originTo.pos
46329
+ }, {
46330
+ type: this.name
46331
+ });
46332
+ } else if (isNodeSelection(selection)) {
46333
+ currentChain.insertContentAt($originTo.pos, {
46334
+ type: this.name
46335
+ });
45999
46336
  } else {
46000
46337
  currentChain.insertContent({ type: this.name });
46001
46338
  }
@@ -46381,11 +46718,11 @@ const StarterKit = Extension.create({
46381
46718
  addExtensions() {
46382
46719
  var _a2, _b, _c, _d, _e2, _f, _g, _h, _j, _k, _l2, _m, _o, _p, _q, _r2, _s, _t2;
46383
46720
  const extensions = [];
46384
- if (this.options.blockquote !== false) {
46385
- extensions.push(Blockquote.configure((_a2 = this.options) === null || _a2 === void 0 ? void 0 : _a2.blockquote));
46386
- }
46387
46721
  if (this.options.bold !== false) {
46388
- extensions.push(Bold.configure((_b = this.options) === null || _b === void 0 ? void 0 : _b.bold));
46722
+ extensions.push(Bold.configure((_a2 = this.options) === null || _a2 === void 0 ? void 0 : _a2.bold));
46723
+ }
46724
+ if (this.options.blockquote !== false) {
46725
+ extensions.push(Blockquote.configure((_b = this.options) === null || _b === void 0 ? void 0 : _b.blockquote));
46389
46726
  }
46390
46727
  if (this.options.bulletList !== false) {
46391
46728
  extensions.push(BulletList.configure((_c = this.options) === null || _c === void 0 ? void 0 : _c.bulletList));
@@ -49192,7 +49529,7 @@ class BubbleMenuView {
49192
49529
  }
49193
49530
  update(view, oldState) {
49194
49531
  const { state: state2 } = view;
49195
- const hasValidSelection = state2.selection.$from.pos !== state2.selection.$to.pos;
49532
+ const hasValidSelection = state2.selection.from !== state2.selection.to;
49196
49533
  if (this.updateDelay > 0 && hasValidSelection) {
49197
49534
  this.handleDebouncedUpdate(view, oldState);
49198
49535
  return;
@@ -52344,7 +52681,7 @@ const Table = Node$2.create({
52344
52681
  insertTable: ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr: tr2, dispatch, editor }) => {
52345
52682
  const node = createTable$1(editor.schema, rows, cols, withHeaderRow);
52346
52683
  if (dispatch) {
52347
- const offset2 = tr2.selection.anchor + 1;
52684
+ const offset2 = tr2.selection.from + 1;
52348
52685
  tr2.replaceSelectionWith(node).scrollIntoView().setSelection(TextSelection.near(tr2.doc.resolve(offset2)));
52349
52686
  }
52350
52687
  return true;