@ni/spright-components 6.22.7 → 6.23.1

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.
@@ -18971,7 +18971,7 @@ Defines an interaction area clip-path that leaves out the severity text so it is
18971
18971
  };
18972
18972
  const electronicChipZoomed16X16 = {
18973
18973
  name: 'electronic_chip_zoomed_16_x_16',
18974
- data: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M13 14H7.333V9.333a2 2 0 0 1 2-2H14V13a1 1 0 0 1-1 1M12 2a.667.667 0 0 0-.667.667v2h1.334v-2A.667.667 0 0 0 12 2M8.444 2a.667.667 0 0 0-.666.667v2H9.11v-2A.667.667 0 0 0 8.444 2M2 8.444a.667.667 0 0 0 .667.667h2V7.778h-2A.667.667 0 0 0 2 8.444M2 12a.667.667 0 0 0 .667.667h2v-1.334h-2A.667.667 0 0 0 2 12m11.556-8.222v.889a.444.444 0 0 1-.445.444H10.89a.444.444 0 0 1-.445-.444v-.89H10v.89a.444.444 0 0 1-.444.444H7.333a.444.444 0 0 1-.444-.444v-.89H4.667a.89.89 0 0 0-.89.89v2.222h.89a.444.444 0 0 1 .444.444v2.223a.444.444 0 0 1-.444.444h-.89v.444h.89a.444.444 0 0 1 .444.445v2.222a.444.444 0 0 1-.444.445h-.89V14H6.89V8.222A1.333 1.333 0 0 1 8.222 6.89H14V3.778Z" class="cls-1"/></svg>`,
18974
+ data: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M8 7h6v7H7V8c0-.55.45-1 1-1m4-6v3h-2V1H8v3C5.79 4 4 5.79 4 8H1v2h3v2H1v2h5V8c0-1.1.9-2 2-2h6V1z" class="cls-1"/></svg>`,
18975
18975
  };
18976
18976
  const exclamationMark16X16 = {
18977
18977
  name: 'exclamation_mark_16_x_16',
@@ -18997,14 +18997,26 @@ Defines an interaction area clip-path that leaves out the severity text so it is
18997
18997
  name: 'file_arrow_curved_right_16_x_16',
18998
18998
  data: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="m7 2 3 3H7zM6 6V2H2v12h4.282l.03-.187A4.51 4.51 0 0 1 10 10.065V6zm8 5.5L11 9v2c-1.817-.091-3.412 1.137-3.701 2.97.576-.672 2.077-2.065 3.701-1.82V14z" class="cls-1"/></svg>`,
18999
18999
  };
19000
+ const fileClock16X16 = {
19001
+ name: 'file_clock_16_x_16',
19002
+ data: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M12 6H9V3zm-.01 2.19H12V7H8V3H4v10h4.41c-.1-.34-.17-.69-.17-1.06 0-2.07 1.68-3.75 3.75-3.75m3 3.75c0 1.66-1.34 3-3 3s-3-1.34-3-3 1.34-3 3-3 3 1.34 3 3m-1 2c.04-.26-.23-.54-.23-.54l-1.19-1.19q.06-.12.06-.27c0-.15-.02-.19-.06-.27.11-.11.73-.73.79-.81.06-.09.11-.32.11-.4-.11 0-.35.06-.42.13-.06.06-.68.69-.78.78a.644.644 0 0 0-.92.58c0 .35.28.64.64.64.1 0 .19-.02.28-.06.13.14.88.89 1.1 1.12.25.26.43.31.61.31Z" class="cls-1"/></svg>`,
19003
+ };
19000
19004
  const fileDrawer16X16 = {
19001
19005
  name: 'file_drawer_16_x_16',
19002
19006
  data: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M2 4v10h12V4Zm8 4H6V6h4Zm4-5H2V2h12Z" class="cls-1"/></svg>`,
19003
19007
  };
19008
+ const filePlus16X16 = {
19009
+ name: 'file_plus_16_x_16',
19010
+ data: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M12 6H9V3zm-1 3h1V7H8V3H4v10h5v-2h2zm2 3v-2h-1v2h-2v1h2v2h1v-2h2v-1z" class="cls-1"/></svg>`,
19011
+ };
19004
19012
  const fileSearch16X16 = {
19005
19013
  name: 'file_search_16_x_16',
19006
19014
  data: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M14 6v6h-3.333a3.7 3.7 0 0 0 .249-1.302A3.7 3.7 0 0 0 7.22 7 3.7 3.7 0 0 0 6 7.223V2h4v4Zm-3-4v3h3Zm-1.126 8.698a2.697 2.697 0 0 1-4.73 1.772L2.521 14l-.48-.823 2.613-1.523a2.698 2.698 0 1 1 5.22-.956m-.952 0a1.745 1.745 0 1 0-1.745 1.745 1.747 1.747 0 0 0 1.745-1.745" class="cls-1"/></svg>`,
19007
19015
  };
19016
+ const fileStar16X16 = {
19017
+ name: 'file_star_16_x_16',
19018
+ data: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M12 6H9V3zm-2.06 5.35-1.4-2.71 2.69 1.41.77-2.94V7H8V3H4v10h4.81l-2.62-.68 3.74-.97Zm5.23.97-1.82-.48.74-1.43-1.42.74-.48-1.83-.48 1.83-1.42-.75.74 1.43-1.86.48 1.86.49-.74 1.43 1.42-.74.48 1.83.48-1.83 1.42.75-.74-1.43 1.82-.48Z" class="cls-1"/></svg>`,
19019
+ };
19008
19020
  const filter16X16 = {
19009
19021
  name: 'filter_16_x_16',
19010
19022
  data: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M2 3.045v1.29h.787a2.069 2.069 0 1 0 2.907 2.903l1.32 2.173v4.522l1.973-1.846V9.411l3.878-5.076h1.134v-1.29Zm2.033 4.059a1.154 1.154 0 0 1 0-2.308c.023 0 .045.006.068.007l1.002 1.575a1.15 1.15 0 0 1-1.07.726" class="cls-1"/></svg>`,
@@ -19033,10 +19045,22 @@ Defines an interaction area clip-path that leaves out the severity text so it is
19033
19045
  name: 'folder_16_x_16',
19034
19046
  data: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M7 4V3H2v10h12V4Zm6 2H3V5h10Z" class="cls-1"/></svg>`,
19035
19047
  };
19048
+ const folderClock16X16 = {
19049
+ name: 'folder_clock_16_x_16',
19050
+ data: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M8.24 11.94c0-2.07 1.68-3.75 3.75-3.75.74 0 1.43.22 2.01.6V4.01H7v-1H2v10h6.41c-.1-.34-.17-.69-.17-1.06ZM3 5h10v1H3zm8.99 3.94c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3m.29 2.43.78-.78c.07-.07.31-.13.42-.13 0 .08-.05.31-.11.4-.06.08-.68.7-.79.81q.06.12.06.27c0 .15-.02.19-.06.27l1.19 1.19s.27.28.23.54c-.18 0-.36-.05-.61-.31-.23-.23-.97-.98-1.1-1.12a.644.644 0 0 1-.92-.58c0-.35.28-.64.64-.64.1 0 .2.02.28.06" class="cls-1"/></svg>`,
19051
+ };
19036
19052
  const folderOpen16X16 = {
19037
19053
  name: 'folder_open_16_x_16',
19038
19054
  data: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M7 3v1.002h6V6h-1V5H3v1H2V3ZM2 13h11l1-6H2Z" class="cls-1"/></svg>`,
19039
19055
  };
19056
+ const folderPlus16X16 = {
19057
+ name: 'folder_plus_16_x_16',
19058
+ data: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M9 11h2V9h3V4H7V3H2v10h7zM3 5h10v1H3zm12 8h-2v2h-1v-2h-2v-1h2v-2h1v2h2z" class="cls-1"/></svg>`,
19059
+ };
19060
+ const folderStar16X16 = {
19061
+ name: 'folder_star_16_x_16',
19062
+ data: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="m6.19 12.32 3.74-.97-1.4-2.71 2.69 1.41.54-2.05h.86l.54 2.05.84-.44V4H7V3H2v10h6.81zM3 5h10v1H3zm10.35 6.84 1.82.48-1.82.48.74 1.43-1.42-.75-.48 1.83-.48-1.83-1.42.74.74-1.43-1.86-.49 1.86-.48-.74-1.43 1.42.75.48-1.83.48 1.83 1.42-.74-.74 1.43Z" class="cls-1"/></svg>`,
19063
+ };
19040
19064
  const forklift16X16 = {
19041
19065
  name: 'forklift_16_x_16',
19042
19066
  data: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M13 11V4c0-.55-.45-1-1-1h-1v4.24l-1.53-3.3C9.24 3.37 8.69 3 8.08 3H4.01l1 1v3h-2v2.19c-.31.35-.5.81-.5 1.31 0 1.1.9 2 2 2 .5 0 .96-.19 1.31-.5h3.04c.39.32.88.52 1.42.52s1.04-.2 1.42-.52H15zm-8.5.25c-.41 0-.75-.34-.75-.75s.34-.75.75-.75.75.34.75.75-.34.75-.75.75m4.18-2.57L7 7H6V4h2.07c.21 0 .39.12.47.34l1.71 3.68c-.62 0-1.18.25-1.58.66Zm1.59 2.59c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1" class="cls-1"/></svg>`,
@@ -19281,6 +19305,10 @@ Defines an interaction area clip-path that leaves out the severity text so it is
19281
19305
  name: 'scanner_gun_16_x_16',
19282
19306
  data: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M11.48 4.99 12 3H6c-1.66-.02-2.97 1.24-2.99 2.89 0 .55.41 1.09.97 1.1H4v1l-.53 2.65c-.2.98.38 1.89 1.25 2.21a.85.85 0 0 1-.2.45c-.12.12-.28.18-.5.18h-2v.5h2c.36 0 .65-.11.86-.33s.29-.49.33-.69c.06 0 .12.02.19.02.93 0 .74-.66.92-1.58L8 7.98v-1h2.98l.25-1h-.5l.25-1h.5Zm-1.6.5h-2.9s0-.5.5-.5h2.5zm3.86-.76h-.93c-.14 0-.25-.11-.25-.25s.11-.25.25-.25h.93c.14 0 .25.11.25.25s-.11.25-.25.25m.02-2.15-.68.68c-.1.1-.26.1-.35 0-.1-.1-.1-.26 0-.35l.68-.68c.1-.1.26-.1.35 0 .1.1.1.26 0 .35m-1.14 4.38-.59-.59c-.1-.1-.1-.26 0-.35.1-.1.26-.1.35 0l.59.59c.1.1.1.26 0 .35-.1.1-.26.1-.35 0"/></svg>`,
19283
19307
  };
19308
+ const scissors16X16 = {
19309
+ name: 'scissors_16_x_16',
19310
+ data: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M10.35 8.62 15 12c-.54.54-1.17.7-1.89.42-.67-.25-2.95-1.36-4.84-2.29zM15 4l-9.25 6.73c.62.85.55 2.04-.21 2.8-.42.42-.98.63-1.53.63s-1.11-.21-1.53-.63-.63-.97-.63-1.53c0-1.35.99-2.07 2.14-2.24.75-.11 1.47-.33 1.82-.93a1.79 1.79 0 0 0 0-1.68c-.34-.6-1.07-.82-1.82-.93-1.15-.16-2.14-.88-2.14-2.24 0-.55.21-1.1.63-1.53.42-.42.98-.63 1.53-.63s1.11.21 1.53.63c.76.76.83 1.95.21 2.8l1.51 1.1c1.98-.98 5.05-2.49 5.85-2.79.72-.27 1.35-.12 1.89.42zM4.92 4c0-.24-.1-.48-.27-.65a.915.915 0 0 0-1.3 0 .915.915 0 0 0 0 1.3.915.915 0 0 0 1.3 0c.17-.17.27-.4.27-.65m0 8c0-.24-.1-.48-.27-.65a.915.915 0 0 0-1.3 0 .915.915 0 0 0 0 1.3.915.915 0 0 0 1.3 0c.17-.17.27-.4.27-.65M8 8c0-.28-.22-.5-.5-.5S7 7.72 7 8s.22.5.5.5.5-.22.5-.5" class="st0"/></svg>`,
19311
+ };
19284
19312
  const screenCheckLines16X16 = {
19285
19313
  name: 'screen_check_lines_16_x_16',
19286
19314
  data: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M3 3H2v8h5v1H5v1h6v-1H9v-1h5V3zm10 7H3V4h10z" class="cls-1"/><path d="M5.743 9 4 7.242l.766-.742.97 1.007L8.273 5 9 5.758zM10 6h2v1h-2zM8 8h4v1H8z" class="cls-1"/></svg>`,
@@ -19359,7 +19387,7 @@ Defines an interaction area clip-path that leaves out the severity text so it is
19359
19387
  };
19360
19388
  const systemlink16X16 = {
19361
19389
  name: 'systemlink_16_x_16',
19362
- data: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M7.249 2.55a1.06 1.06 0 0 1 1.498 0 1.06 1.06 0 0 1-.295 1.703v1.86a2.42 2.42 0 0 1 1.672 1.215l1.768-.573q.023-.176.106-.344a1.059 1.059 0 1 1 .176 1.208l-1.768.574a2.42 2.42 0 0 1-.638 1.964l1.093 1.504q.175-.033.36-.005a1.058 1.058 0 1 1-1.095.54l-1.093-1.503a2.43 2.43 0 0 1-2.066 0l-1.093 1.503q.085.155.117.34a1.058 1.058 0 1 1-.852-.875l1.093-1.504a2.42 2.42 0 0 1-.638-1.964l-1.768-.574a1.054 1.054 0 0 1-1.71-.247 1.059 1.059 0 1 1 1.992-.617l1.768.573q.161-.295.41-.547c.358-.358.8-.58 1.262-.668v-1.86a1.06 1.06 0 0 1-.294-1.704Zm2.072 9.704c-.42.148-.865.224-1.323.224s-.904-.076-1.324-.224l.566-.779q.37.094.758.094c.388 0 .512-.033.757-.094zM11.98 8.4l.002.097c0 .886-.288 1.727-.82 2.419l-.566-.778c.274-.43.434-.923.467-1.44l.914-.298Zm-7.046.298c.033.502.189.998.466 1.438l-.566.779A3.97 3.97 0 0 1 4.018 8.4zM6.86 5.644c-.377.15-.731.377-1.035.681q-.1.1-.19.209l-.915-.298q.202-.292.46-.554A3.96 3.96 0 0 1 6.86 4.68v.965Zm2.275-.964a3.96 3.96 0 0 1 2.14 1.556l-.915.298a3.075 3.075 0 0 0-1.224-.89z" class="cls-1"/></svg>`,
19390
+ data: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="m5.24 6.29-1.07-.35c.16-.23.34-.44.54-.65.55-.55 1.23-.95 1.96-1.17v1.13c-.44.18-.85.44-1.21.79-.08.08-.15.16-.22.24Zm5.51 0 1.07-.35c-.16-.23-.34-.45-.54-.65-.55-.55-1.23-.95-1.96-1.17v1.13c.44.18.85.44 1.21.79.08.08.15.16.22.24ZM8 12.16c-.3 0-.6-.04-.88-.11l-.66.91a4.7 4.7 0 0 0 3.08 0l-.66-.91c-.29.07-.58.11-.88.11m-3.03-1.67a3.5 3.5 0 0 1-.54-1.68l-1.07-.35c-.03 1.03.29 2.07.95 2.93l.66-.91Zm6.6-1.68c-.04.6-.23 1.18-.54 1.68l.66.91c.62-.81.96-1.79.96-2.82v-.11l-1.07.35Zm2.76-3.2c-.61-.31-1.35-.07-1.66.54-.07.13-.1.26-.12.4l-2.06.67c-.13-.23-.29-.45-.48-.64-.42-.42-.93-.68-1.47-.78V3.63c.42-.2.71-.62.71-1.11a1.23 1.23 0 1 0-2.46 0c0 .49.29.91.71 1.11 0 0-.01 0 0 0V5.8c-.54.1-1.05.36-1.47.78-.19.19-.35.41-.48.64l-2.06-.67a1.4 1.4 0 0 0-.12-.4c-.31-.61-1.05-.85-1.66-.54s-.85 1.05-.54 1.66a1.23 1.23 0 0 0 1.99.29l2.06.67c-.1.81.15 1.66.74 2.29l-1.28 1.75c-.13-.02-.28-.03-.42 0-.67.11-1.13.74-1.03 1.41.11.67.74 1.13 1.41 1.03.67-.11 1.13-.74 1.03-1.41-.02-.14-.07-.28-.14-.4l1.27-1.75c.76.36 1.65.36 2.41 0l1.27 1.75a1.226 1.226 0 0 0 .89 1.81c.67.11 1.31-.35 1.41-1.03.11-.67-.35-1.31-1.03-1.41q-.21-.03-.42 0l-1.28-1.75c.6-.64.85-1.48.74-2.29l2.06-.67c.1.1.21.19.33.25.61.31 1.35.07 1.66-.54s.07-1.35-.54-1.66Z" class="cls-1"/></svg>`,
19363
19391
  };
19364
19392
  const t16X16 = {
19365
19393
  name: 't_16_x_16',
@@ -25216,6 +25244,18 @@ so this becomes the fallback color for the slot */ ''}
25216
25244
  }
25217
25245
  registerIconSvg('icon-file-arrow-curved-right', IconFileArrowCurvedRight);
25218
25246
 
25247
+ // AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY
25248
+ // See generation source in nimble-components/build/generate-icons
25249
+ /**
25250
+ * The icon component for the 'fileClock' icon
25251
+ */
25252
+ class IconFileClock extends IconSvg {
25253
+ constructor() {
25254
+ super(fileClock16X16);
25255
+ }
25256
+ }
25257
+ registerIconSvg('icon-file-clock', IconFileClock);
25258
+
25219
25259
  // AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY
25220
25260
  // See generation source in nimble-components/build/generate-icons
25221
25261
  /**
@@ -25228,6 +25268,18 @@ so this becomes the fallback color for the slot */ ''}
25228
25268
  }
25229
25269
  registerIconSvg('icon-file-drawer', IconFileDrawer);
25230
25270
 
25271
+ // AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY
25272
+ // See generation source in nimble-components/build/generate-icons
25273
+ /**
25274
+ * The icon component for the 'filePlus' icon
25275
+ */
25276
+ class IconFilePlus extends IconSvg {
25277
+ constructor() {
25278
+ super(filePlus16X16);
25279
+ }
25280
+ }
25281
+ registerIconSvg('icon-file-plus', IconFilePlus);
25282
+
25231
25283
  // AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY
25232
25284
  // See generation source in nimble-components/build/generate-icons
25233
25285
  /**
@@ -25240,6 +25292,18 @@ so this becomes the fallback color for the slot */ ''}
25240
25292
  }
25241
25293
  registerIconSvg('icon-file-search', IconFileSearch);
25242
25294
 
25295
+ // AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY
25296
+ // See generation source in nimble-components/build/generate-icons
25297
+ /**
25298
+ * The icon component for the 'fileStar' icon
25299
+ */
25300
+ class IconFileStar extends IconSvg {
25301
+ constructor() {
25302
+ super(fileStar16X16);
25303
+ }
25304
+ }
25305
+ registerIconSvg('icon-file-star', IconFileStar);
25306
+
25243
25307
  // AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY
25244
25308
  // See generation source in nimble-components/build/generate-icons
25245
25309
  /**
@@ -25324,6 +25388,18 @@ so this becomes the fallback color for the slot */ ''}
25324
25388
  }
25325
25389
  registerIconSvg('icon-folder', IconFolder);
25326
25390
 
25391
+ // AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY
25392
+ // See generation source in nimble-components/build/generate-icons
25393
+ /**
25394
+ * The icon component for the 'folderClock' icon
25395
+ */
25396
+ class IconFolderClock extends IconSvg {
25397
+ constructor() {
25398
+ super(folderClock16X16);
25399
+ }
25400
+ }
25401
+ registerIconSvg('icon-folder-clock', IconFolderClock);
25402
+
25327
25403
  // AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY
25328
25404
  // See generation source in nimble-components/build/generate-icons
25329
25405
  /**
@@ -25336,6 +25412,30 @@ so this becomes the fallback color for the slot */ ''}
25336
25412
  }
25337
25413
  registerIconSvg('icon-folder-open', IconFolderOpen);
25338
25414
 
25415
+ // AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY
25416
+ // See generation source in nimble-components/build/generate-icons
25417
+ /**
25418
+ * The icon component for the 'folderPlus' icon
25419
+ */
25420
+ class IconFolderPlus extends IconSvg {
25421
+ constructor() {
25422
+ super(folderPlus16X16);
25423
+ }
25424
+ }
25425
+ registerIconSvg('icon-folder-plus', IconFolderPlus);
25426
+
25427
+ // AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY
25428
+ // See generation source in nimble-components/build/generate-icons
25429
+ /**
25430
+ * The icon component for the 'folderStar' icon
25431
+ */
25432
+ class IconFolderStar extends IconSvg {
25433
+ constructor() {
25434
+ super(folderStar16X16);
25435
+ }
25436
+ }
25437
+ registerIconSvg('icon-folder-star', IconFolderStar);
25438
+
25339
25439
  // AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY
25340
25440
  // See generation source in nimble-components/build/generate-icons
25341
25441
  /**
@@ -26062,6 +26162,18 @@ so this becomes the fallback color for the slot */ ''}
26062
26162
  }
26063
26163
  registerIconSvg('icon-scanner-gun', IconScannerGun);
26064
26164
 
26165
+ // AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY
26166
+ // See generation source in nimble-components/build/generate-icons
26167
+ /**
26168
+ * The icon component for the 'scissors' icon
26169
+ */
26170
+ class IconScissors extends IconSvg {
26171
+ constructor() {
26172
+ super(scissors16X16);
26173
+ }
26174
+ }
26175
+ registerIconSvg('icon-scissors', IconScissors);
26176
+
26065
26177
  // AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY
26066
26178
  // See generation source in nimble-components/build/generate-icons
26067
26179
  /**
@@ -29685,7 +29797,6 @@ so this becomes the fallback color for the slot */ ''}
29685
29797
  if (!type)
29686
29798
  throw new RangeError(`There is no mark type ${json.type} in this schema`);
29687
29799
  let mark = type.create(json.attrs);
29688
- type.checkAttrs(mark.attrs);
29689
29800
  return mark;
29690
29801
  }
29691
29802
  /**
@@ -30665,11 +30776,11 @@ so this becomes the fallback color for the slot */ ''}
30665
30776
  */
30666
30777
  check() {
30667
30778
  this.type.checkContent(this.content);
30668
- this.type.checkAttrs(this.attrs);
30779
+ checkAttrs(this.type.attrs, this.attrs, "node", this.type.name);
30669
30780
  let copy = Mark$1.none;
30670
30781
  for (let i = 0; i < this.marks.length; i++) {
30671
30782
  let mark = this.marks[i];
30672
- mark.type.checkAttrs(mark.attrs);
30783
+ checkAttrs(mark.type.attrs, mark.attrs, "mark", mark.type.name);
30673
30784
  copy = mark.addToSet(copy);
30674
30785
  }
30675
30786
  if (!Mark$1.sameSet(copy, this.marks))
@@ -30710,7 +30821,6 @@ so this becomes the fallback color for the slot */ ''}
30710
30821
  }
30711
30822
  let content = Fragment.fromJSON(schema, json.content);
30712
30823
  let node = schema.nodeType(json.type).create(json.attrs, content, marks);
30713
- node.type.checkAttrs(node.attrs);
30714
30824
  return node;
30715
30825
  }
30716
30826
  };
@@ -30760,6 +30870,15 @@ so this becomes the fallback color for the slot */ ''}
30760
30870
  str = marks[i].type.name + "(" + str + ")";
30761
30871
  return str;
30762
30872
  }
30873
+ function checkAttrs(attrs, values, type, name) {
30874
+ for (let attr in values)
30875
+ if (!(attr in attrs))
30876
+ throw new RangeError(`Unsupported attribute ${attr} for ${type} of type ${name}`);
30877
+ for (let attr in attrs) {
30878
+ if (attrs[attr].validate)
30879
+ attrs[attr].validate(values[attr]);
30880
+ }
30881
+ }
30763
30882
 
30764
30883
  /**
30765
30884
  Instances of this class represent a match state of a node type's
@@ -31214,27 +31333,21 @@ so this becomes the fallback color for the slot */ ''}
31214
31333
  function computeAttrs(attrs, value) {
31215
31334
  let built = Object.create(null);
31216
31335
  for (let name in attrs) {
31336
+ let attr = attrs[name];
31217
31337
  let given = value && value[name];
31218
31338
  if (given === undefined) {
31219
- let attr = attrs[name];
31220
31339
  if (attr.hasDefault)
31221
31340
  given = attr.default;
31222
31341
  else
31223
31342
  throw new RangeError("No value supplied for attribute " + name);
31224
31343
  }
31344
+ else if (attr.validate) {
31345
+ attr.validate(given);
31346
+ }
31225
31347
  built[name] = given;
31226
31348
  }
31227
31349
  return built;
31228
31350
  }
31229
- function checkAttrs(attrs, values, type, name) {
31230
- for (let attr in values)
31231
- if (!(attr in attrs))
31232
- throw new RangeError(`Unsupported attribute ${attr} for ${type} of type ${name}`);
31233
- for (let attr in attrs) {
31234
- if (attrs[attr].validate)
31235
- attrs[attr].validate(values[attr]);
31236
- }
31237
- }
31238
31351
  function initAttrs(typeName, attrs) {
31239
31352
  let result = Object.create(null);
31240
31353
  if (attrs)
@@ -31406,11 +31519,9 @@ so this becomes the fallback color for the slot */ ''}
31406
31519
  throw new RangeError(`Invalid content for node ${this.name}: ${content.toString().slice(0, 50)}`);
31407
31520
  }
31408
31521
  /**
31409
- @internal
31522
+ @internal no longer useful, but called by old prosemirror-view versions
31410
31523
  */
31411
- checkAttrs(attrs) {
31412
- checkAttrs(this.attrs, attrs, "node", this.name);
31413
- }
31524
+ checkAttrs(attrs) { }
31414
31525
  /**
31415
31526
  Check whether the given mark type is allowed in this node.
31416
31527
  */
@@ -31557,12 +31668,6 @@ so this becomes the fallback color for the slot */ ''}
31557
31668
  return set[i];
31558
31669
  }
31559
31670
  /**
31560
- @internal
31561
- */
31562
- checkAttrs(attrs) {
31563
- checkAttrs(this.attrs, attrs, "mark", this.name);
31564
- }
31565
- /**
31566
31671
  Queries whether a given mark type is
31567
31672
  [excluded](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) by this one.
31568
31673
  */
@@ -32753,9 +32858,12 @@ so this becomes the fallback color for the slot */ ''}
32753
32858
  if (simple)
32754
32859
  return result;
32755
32860
  let recover = pos == (assoc < 0 ? start : end) ? null : makeRecover(i / 3, pos - start);
32756
- let del = pos == start ? DEL_AFTER : pos == end ? DEL_BEFORE : DEL_ACROSS;
32757
- if (assoc < 0 ? pos != start : pos != end)
32758
- del |= DEL_SIDE;
32861
+ let del = 0;
32862
+ if (oldSize) {
32863
+ del |= pos == start ? DEL_AFTER : pos == end ? DEL_BEFORE : DEL_ACROSS;
32864
+ if (assoc < 0 ? pos != start : pos != end)
32865
+ del |= DEL_SIDE;
32866
+ }
32759
32867
  return new MapResult(result, del, recover);
32760
32868
  }
32761
32869
  diff += newSize - oldSize;
@@ -36693,15 +36801,15 @@ so this becomes the fallback color for the slot */ ''}
36693
36801
  return true;
36694
36802
  if (off == (dir < 0 ? 0 : nodeSize(node))) {
36695
36803
  let parent = node.parentNode;
36696
- if (!parent || parent.nodeType != 1 || hasBlockDesc(node) || atomElements.test(node.nodeName) ||
36804
+ if (!parent || !isElt(parent) || hasBlockDesc(node) || atomElements.test(node.nodeName) ||
36697
36805
  node.contentEditable == "false")
36698
36806
  return false;
36699
36807
  off = domIndex(node) + (dir < 0 ? 0 : 1);
36700
36808
  node = parent;
36701
36809
  }
36702
- else if (node.nodeType == 1) {
36810
+ else if (isElt(node)) {
36703
36811
  let child = node.childNodes[off + (dir < 0 ? -1 : 0)];
36704
- if (child.nodeType == 1 && child.contentEditable == "false") {
36812
+ if (isElt(child) && child.contentEditable == "false") {
36705
36813
  if ((_a = child.pmViewDesc) === null || _a === void 0 ? void 0 : _a.ignoreForSelection)
36706
36814
  off += dir;
36707
36815
  else
@@ -36720,11 +36828,16 @@ so this becomes the fallback color for the slot */ ''}
36720
36828
  function nodeSize(node) {
36721
36829
  return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length;
36722
36830
  }
36831
+ function isElt(node) { return node.nodeType == 1; }
36832
+ function isText(node) { return node.nodeType == 3; }
36833
+ function contains(parent, child) {
36834
+ return child ? parent.contains(isElt(child) ? child : child.parentNode) : false;
36835
+ }
36723
36836
  function textNodeBefore$1(node, offset) {
36724
36837
  for (;;) {
36725
- if (node.nodeType == 3 && offset)
36838
+ if (isText(node) && offset)
36726
36839
  return node;
36727
- if (node.nodeType == 1 && offset > 0) {
36840
+ if (isElt(node) && offset > 0) {
36728
36841
  if (node.contentEditable == "false")
36729
36842
  return null;
36730
36843
  node = node.childNodes[offset - 1];
@@ -36741,9 +36854,9 @@ so this becomes the fallback color for the slot */ ''}
36741
36854
  }
36742
36855
  function textNodeAfter$1(node, offset) {
36743
36856
  for (;;) {
36744
- if (node.nodeType == 3 && offset < node.nodeValue.length)
36857
+ if (isText(node) && offset < node.nodeValue.length)
36745
36858
  return node;
36746
- if (node.nodeType == 1 && offset < node.childNodes.length) {
36859
+ if (isElt(node) && offset < node.childNodes.length) {
36747
36860
  if (node.contentEditable == "false")
36748
36861
  return null;
36749
36862
  node = node.childNodes[offset];
@@ -36867,13 +36980,12 @@ so this becomes the fallback color for the slot */ ''}
36867
36980
  for (let parent = startDOM || view.dom;;) {
36868
36981
  if (!parent)
36869
36982
  break;
36870
- if (parent.nodeType != 1) {
36983
+ if (!isElt(parent)) {
36871
36984
  parent = parentNode(parent);
36872
36985
  continue;
36873
36986
  }
36874
- let elt = parent;
36875
- let atTop = elt == doc.body;
36876
- let bounding = atTop ? windowRect(doc) : clientRect(elt);
36987
+ let atTop = parent == doc.body;
36988
+ let bounding = atTop ? windowRect(doc) : clientRect(parent);
36877
36989
  let moveX = 0, moveY = 0;
36878
36990
  if (rect.top < bounding.top + getSide$1(scrollThreshold, "top"))
36879
36991
  moveY = -(bounding.top - rect.top + getSide$1(scrollMargin, "top"));
@@ -36890,12 +37002,12 @@ so this becomes the fallback color for the slot */ ''}
36890
37002
  doc.defaultView.scrollBy(moveX, moveY);
36891
37003
  }
36892
37004
  else {
36893
- let startX = elt.scrollLeft, startY = elt.scrollTop;
37005
+ let startX = parent.scrollLeft, startY = parent.scrollTop;
36894
37006
  if (moveY)
36895
- elt.scrollTop += moveY;
37007
+ parent.scrollTop += moveY;
36896
37008
  if (moveX)
36897
- elt.scrollLeft += moveX;
36898
- let dX = elt.scrollLeft - startX, dY = elt.scrollTop - startY;
37009
+ parent.scrollLeft += moveX;
37010
+ let dX = parent.scrollLeft - startX, dY = parent.scrollTop - startY;
36899
37011
  rect = { left: rect.left - dX, top: rect.top - dY, right: rect.right - dX, bottom: rect.bottom - dY };
36900
37012
  }
36901
37013
  }
@@ -36970,14 +37082,15 @@ so this becomes the fallback color for the slot */ ''}
36970
37082
  }
36971
37083
  }
36972
37084
  function findOffsetInNode(node, coords) {
36973
- let closest, dxClosest = 2e8, coordsClosest, offset = 0;
37085
+ let closest;
37086
+ let dxClosest = 2e8, coordsClosest, offset = 0;
36974
37087
  let rowBot = coords.top, rowTop = coords.top;
36975
37088
  let firstBelow, coordsBelow;
36976
37089
  for (let child = node.firstChild, childIndex = 0; child; child = child.nextSibling, childIndex++) {
36977
37090
  let rects;
36978
- if (child.nodeType == 1)
37091
+ if (isElt(child))
36979
37092
  rects = child.getClientRects();
36980
- else if (child.nodeType == 3)
37093
+ else if (isText(child))
36981
37094
  rects = textRange(child).getClientRects();
36982
37095
  else
36983
37096
  continue;
@@ -36991,11 +37104,11 @@ so this becomes the fallback color for the slot */ ''}
36991
37104
  if (dx < dxClosest) {
36992
37105
  closest = child;
36993
37106
  dxClosest = dx;
36994
- coordsClosest = dx && closest.nodeType == 3 ? {
37107
+ coordsClosest = dx && isText(closest) ? {
36995
37108
  left: rect.right < coords.left ? rect.right : rect.left,
36996
37109
  top: coords.top
36997
37110
  } : coords;
36998
- if (child.nodeType == 1 && dx)
37111
+ if (isElt(child) && dx)
36999
37112
  offset = childIndex + (coords.left >= (rect.left + rect.right) / 2 ? 1 : 0);
37000
37113
  continue;
37001
37114
  }
@@ -37014,9 +37127,9 @@ so this becomes the fallback color for the slot */ ''}
37014
37127
  coordsClosest = coordsBelow;
37015
37128
  dxClosest = 0;
37016
37129
  }
37017
- if (closest && closest.nodeType == 3)
37130
+ if (closest && isText(closest))
37018
37131
  return findOffsetInText(closest, coordsClosest);
37019
- if (!closest || (dxClosest && closest.nodeType == 1))
37132
+ if (!closest || dxClosest)
37020
37133
  return { node, offset };
37021
37134
  return findOffsetInNode(closest, coordsClosest);
37022
37135
  }
@@ -37049,7 +37162,7 @@ so this becomes the fallback color for the slot */ ''}
37049
37162
  }
37050
37163
  function posFromElement(view, elt, coords) {
37051
37164
  let { node, offset } = findOffsetInNode(elt, coords), bias = -1;
37052
- if (node.nodeType == 1 && !node.firstChild) {
37165
+ if (isElt(node) && !node.firstChild) {
37053
37166
  let rect = node.getBoundingClientRect();
37054
37167
  bias = rect.left != rect.right && coords.left > (rect.left + rect.right) / 2 ? 1 : -1;
37055
37168
  }
@@ -37069,7 +37182,7 @@ so this becomes the fallback color for the slot */ ''}
37069
37182
  let desc = view.docView.nearestDesc(cur, true), rect;
37070
37183
  if (!desc)
37071
37184
  return null;
37072
- if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent || !desc.contentDOM) &&
37185
+ if (isElt(desc.dom) && (desc.node.isBlock && desc.parent || !desc.contentDOM) &&
37073
37186
  // Ignore elements with zero-size bounding rectangles
37074
37187
  ((rect = desc.dom.getBoundingClientRect()).width || rect.height)) {
37075
37188
  if (desc.node.isBlock && desc.parent && !/^T(R|BODY|HEAD|FOOT)$/.test(desc.dom.nodeName)) {
@@ -37096,7 +37209,7 @@ so this becomes the fallback color for the slot */ ''}
37096
37209
  if (len && box.top < box.bottom) {
37097
37210
  for (let startI = Math.max(0, Math.min(len - 1, Math.floor(len * (coords.top - box.top) / (box.bottom - box.top)) - 2)), i = startI;;) {
37098
37211
  let child = element.childNodes[i];
37099
- if (child.nodeType == 1) {
37212
+ if (isElt(child)) {
37100
37213
  let rects = child.getClientRects();
37101
37214
  for (let j = 0; j < rects.length; j++) {
37102
37215
  let rect = rects[j];
@@ -37119,7 +37232,7 @@ so this becomes the fallback color for the slot */ ''}
37119
37232
  let elt = (view.root.elementFromPoint ? view.root : doc)
37120
37233
  .elementFromPoint(coords.left, coords.top);
37121
37234
  let pos;
37122
- if (!elt || !view.dom.contains(elt.nodeType != 1 ? elt.parentNode : elt)) {
37235
+ if (!elt || !view.dom.contains(elt)) {
37123
37236
  let box = view.dom.getBoundingClientRect();
37124
37237
  if (!inRect(coords, box))
37125
37238
  return null;
@@ -37135,7 +37248,7 @@ so this becomes the fallback color for the slot */ ''}
37135
37248
  }
37136
37249
  elt = targetKludge(elt, coords);
37137
37250
  if (node) {
37138
- if (gecko && node.nodeType == 1) {
37251
+ if (gecko && isElt(node)) {
37139
37252
  // Firefox will sometimes return offsets into <input> nodes, which
37140
37253
  // have no actual children, from caretPositionFromPoint (#953)
37141
37254
  offset = Math.min(offset, node.childNodes.length);
@@ -37150,18 +37263,18 @@ so this becomes the fallback color for the slot */ ''}
37150
37263
  }
37151
37264
  let prev;
37152
37265
  // When clicking above the right side of an uneditable node, Chrome will report a cursor position after that node.
37153
- if (webkit && offset && node.nodeType == 1 && (prev = node.childNodes[offset - 1]).nodeType == 1 &&
37266
+ if (webkit && offset && isElt(node) && isElt(prev = node.childNodes[offset - 1]) &&
37154
37267
  prev.contentEditable == "false" && prev.getBoundingClientRect().top >= coords.top)
37155
37268
  offset--;
37156
37269
  // Suspiciously specific kludge to work around caret*FromPoint
37157
37270
  // never returning a position at the end of the document
37158
- if (node == view.dom && offset == node.childNodes.length - 1 && node.lastChild.nodeType == 1 &&
37271
+ if (node == view.dom && offset == node.childNodes.length - 1 && isElt(node.lastChild) &&
37159
37272
  coords.top > node.lastChild.getBoundingClientRect().bottom)
37160
37273
  pos = view.state.doc.content.size;
37161
37274
  // Ignore positions directly after a BR, since caret*FromPoint
37162
37275
  // 'round up' positions that would be more accurately placed
37163
37276
  // before the BR node.
37164
- else if (offset == 0 || node.nodeType != 1 || node.childNodes[offset - 1].nodeName != "BR")
37277
+ else if (offset == 0 || !isElt(node) || node.childNodes[offset - 1].nodeName != "BR")
37165
37278
  pos = posFromCaret(view, node, offset, coords);
37166
37279
  }
37167
37280
  if (pos == null)
@@ -37187,7 +37300,7 @@ so this becomes the fallback color for the slot */ ''}
37187
37300
  function coordsAtPos(view, pos, side) {
37188
37301
  let { node, offset, atom } = view.docView.domFromPos(pos, side < 0 ? -1 : 1);
37189
37302
  let supportEmptyRange = webkit || gecko;
37190
- if (node.nodeType == 3) {
37303
+ if (isText(node)) {
37191
37304
  // These browsers support querying empty text ranges. Prefer that in
37192
37305
  // bidi context or when at the end of a node.
37193
37306
  if (supportEmptyRange && (BIDI.test(node.nodeValue) || (side < 0 ? !offset : offset == node.nodeValue.length))) {
@@ -37229,12 +37342,12 @@ so this becomes the fallback color for the slot */ ''}
37229
37342
  if (!$dom.parent.inlineContent) {
37230
37343
  if (atom == null && offset && (side < 0 || offset == nodeSize(node))) {
37231
37344
  let before = node.childNodes[offset - 1];
37232
- if (before.nodeType == 1)
37345
+ if (isElt(before))
37233
37346
  return flattenH(before.getBoundingClientRect(), false);
37234
37347
  }
37235
37348
  if (atom == null && offset < nodeSize(node)) {
37236
37349
  let after = node.childNodes[offset];
37237
- if (after.nodeType == 1)
37350
+ if (isElt(after))
37238
37351
  return flattenH(after.getBoundingClientRect(), true);
37239
37352
  }
37240
37353
  return flattenH(node.getBoundingClientRect(), side >= 0);
@@ -37242,10 +37355,10 @@ so this becomes the fallback color for the slot */ ''}
37242
37355
  // Inline, not in text node (this is not Bidi-safe)
37243
37356
  if (atom == null && offset && (side < 0 || offset == nodeSize(node))) {
37244
37357
  let before = node.childNodes[offset - 1];
37245
- let target = before.nodeType == 3 ? textRange(before, nodeSize(before) - (supportEmptyRange ? 0 : 1))
37358
+ let target = isText(before) ? textRange(before, nodeSize(before) - (supportEmptyRange ? 0 : 1))
37246
37359
  // BR nodes tend to only return the rectangle before them.
37247
37360
  // Only use them if they are the last element in their parent
37248
- : before.nodeType == 1 && (before.nodeName != "BR" || !before.nextSibling) ? before : null;
37361
+ : isElt(before) && (before.nodeName != "BR" || !before.nextSibling) ? before : null;
37249
37362
  if (target)
37250
37363
  return flattenV(singleRect(target, 1), false);
37251
37364
  }
@@ -37253,13 +37366,13 @@ so this becomes the fallback color for the slot */ ''}
37253
37366
  let after = node.childNodes[offset];
37254
37367
  while (after.pmViewDesc && after.pmViewDesc.ignoreForCoords)
37255
37368
  after = after.nextSibling;
37256
- let target = !after ? null : after.nodeType == 3 ? textRange(after, 0, (supportEmptyRange ? 0 : 1))
37257
- : after.nodeType == 1 ? after : null;
37369
+ let target = !after ? null : isText(after) ? textRange(after, 0, (supportEmptyRange ? 0 : 1))
37370
+ : isElt(after) ? after : null;
37258
37371
  if (target)
37259
37372
  return flattenV(singleRect(target, -1), true);
37260
37373
  }
37261
37374
  // All else failed, just try to get a rectangle for the target node
37262
- return flattenV(singleRect(node.nodeType == 3 ? textRange(node) : node, -side), side >= 0);
37375
+ return flattenV(singleRect(isText(node) ? textRange(node) : node, -side), side >= 0);
37263
37376
  }
37264
37377
  function flattenV(rect, left) {
37265
37378
  if (rect.width == 0)
@@ -37309,9 +37422,9 @@ so this becomes the fallback color for the slot */ ''}
37309
37422
  let coords = coordsAtPos(view, $pos.pos, 1);
37310
37423
  for (let child = dom.firstChild; child; child = child.nextSibling) {
37311
37424
  let boxes;
37312
- if (child.nodeType == 1)
37425
+ if (isElt(child))
37313
37426
  boxes = child.getClientRects();
37314
- else if (child.nodeType == 3)
37427
+ else if (isText(child))
37315
37428
  boxes = textRange(child, 0, child.nodeValue.length).getClientRects();
37316
37429
  else
37317
37430
  continue;
@@ -37351,8 +37464,7 @@ so this becomes the fallback color for the slot */ ''}
37351
37464
  sel.modify("move", dir, "character");
37352
37465
  let parentDOM = $head.depth ? view.docView.domAfterPos($head.before()) : view.dom;
37353
37466
  let { focusNode: newNode, focusOffset: newOff } = view.domSelectionRange();
37354
- let result = newNode && !parentDOM.contains(newNode.nodeType == 1 ? newNode : newNode.parentNode) ||
37355
- (oldNode == newNode && oldOff == newOff);
37467
+ let result = newNode && !contains(parentDOM, newNode) || (oldNode == newNode && oldOff == newOff);
37356
37468
  // Restore the previous selection
37357
37469
  try {
37358
37470
  sel.collapse(anchorNode, anchorOffset);
@@ -37460,7 +37572,7 @@ so this becomes the fallback color for the slot */ ''}
37460
37572
  localPosFromDOM(dom, offset, bias) {
37461
37573
  // If the DOM position is in the content, use the child desc after
37462
37574
  // it to figure out a position.
37463
- if (this.contentDOM && this.contentDOM.contains(dom.nodeType == 1 ? dom : dom.parentNode)) {
37575
+ if (this.contentDOM && contains(this.contentDOM, dom)) {
37464
37576
  if (bias < 0) {
37465
37577
  let domBefore, desc;
37466
37578
  if (dom == this.contentDOM) {
@@ -37498,7 +37610,7 @@ so this becomes the fallback color for the slot */ ''}
37498
37610
  atEnd = offset > domIndex(this.contentDOM);
37499
37611
  }
37500
37612
  else if (this.contentDOM && this.contentDOM != this.dom && this.dom.contains(this.contentDOM)) {
37501
- atEnd = dom.compareDocumentPosition(this.contentDOM) & 2;
37613
+ atEnd = !!(dom.compareDocumentPosition(this.contentDOM) & 4);
37502
37614
  }
37503
37615
  else if (this.dom.firstChild) {
37504
37616
  if (offset == 0)
@@ -37528,7 +37640,7 @@ so this becomes the fallback color for the slot */ ''}
37528
37640
  if (desc && (!onlyNodes || desc.node)) {
37529
37641
  // If dom is outside of this desc's nodeDOM, don't count it.
37530
37642
  if (first && (nodeDOM = desc.nodeDOM) &&
37531
- !(nodeDOM.nodeType == 1 ? nodeDOM.contains(dom.nodeType == 1 ? dom : dom.parentNode) : nodeDOM == dom))
37643
+ !(isElt(nodeDOM) ? contains(nodeDOM, dom) : nodeDOM == dom))
37532
37644
  first = false;
37533
37645
  else
37534
37646
  return desc;
@@ -37578,7 +37690,7 @@ so this becomes the fallback color for the slot */ ''}
37578
37690
  let i = 0, offset = 0;
37579
37691
  for (let curPos = 0; i < this.children.length; i++) {
37580
37692
  let child = this.children[i], end = curPos + child.size;
37581
- if (end > pos || child instanceof TrailingHackViewDesc) {
37693
+ if (end > pos) {
37582
37694
  offset = pos - curPos;
37583
37695
  break;
37584
37696
  }
@@ -37588,7 +37700,11 @@ so this becomes the fallback color for the slot */ ''}
37588
37700
  if (offset)
37589
37701
  return this.children[i].domFromPos(offset - this.children[i].border, side);
37590
37702
  // Go back if there were any zero-length widgets with side >= 0 before this point
37591
- for (let prev; i && !(prev = this.children[i - 1]).size && prev instanceof WidgetViewDesc && prev.side >= 0; i--) { }
37703
+ for (; i > 0; i--) {
37704
+ let prev = this.children[i - 1];
37705
+ if (prev.size || !(prev instanceof BufferHackViewDesc || prev instanceof WidgetViewDesc && prev.side >= 0))
37706
+ break;
37707
+ }
37592
37708
  // Scan towards the first useable node
37593
37709
  if (side <= 0) {
37594
37710
  let prev, enter = true;
@@ -37665,7 +37781,7 @@ so this becomes the fallback color for the slot */ ''}
37665
37781
  }
37666
37782
  domAfterPos(pos) {
37667
37783
  let { node, offset } = this.domFromPos(pos, 0);
37668
- if (node.nodeType != 1 || offset == node.childNodes.length)
37784
+ if (!isElt(node) || offset == node.childNodes.length)
37669
37785
  throw new RangeError("No node after pos " + pos);
37670
37786
  return node.childNodes[offset];
37671
37787
  }
@@ -37694,7 +37810,7 @@ so this becomes the fallback color for the slot */ ''}
37694
37810
  // reported position in such situations (#1092).
37695
37811
  if ((gecko || safari) && anchor == head) {
37696
37812
  let { node, offset } = anchorDOM;
37697
- if (node.nodeType == 3) {
37813
+ if (isText(node)) {
37698
37814
  brKludge = !!(offset && node.nodeValue[offset - 1] == "\n");
37699
37815
  // Issue #1128
37700
37816
  if (brKludge && offset == node.nodeValue.length) {
@@ -37717,7 +37833,7 @@ so this becomes the fallback color for the slot */ ''}
37717
37833
  }
37718
37834
  // Firefox can act strangely when the selection is in front of an
37719
37835
  // uneditable node. See #1163 and https://bugzilla.mozilla.org/show_bug.cgi?id=1709536
37720
- if (gecko && selRange.focusNode && selRange.focusNode != headDOM.node && selRange.focusNode.nodeType == 1) {
37836
+ if (gecko && selRange.focusNode && selRange.focusNode != headDOM.node && isElt(selRange.focusNode)) {
37721
37837
  let after = selRange.focusNode.childNodes[selRange.focusOffset];
37722
37838
  if (after && after.contentEditable == "false")
37723
37839
  force = true;
@@ -37816,14 +37932,12 @@ so this becomes the fallback color for the slot */ ''}
37816
37932
  return self.parent.posBeforeChild(self);
37817
37933
  });
37818
37934
  if (!widget.type.spec.raw) {
37819
- if (dom.nodeType != 1) {
37820
- let wrap = document.createElement("span");
37821
- wrap.appendChild(dom);
37822
- dom = wrap;
37823
- }
37824
- if (!dom.hasAttribute("contenteditable"))
37825
- dom.contentEditable = "false";
37826
- dom.classList.add("ProseMirror-widget");
37935
+ let elt = isElt(dom) ? dom : document.createElement("span");
37936
+ if (elt != dom)
37937
+ elt.appendChild(dom);
37938
+ if (!elt.hasAttribute("contenteditable"))
37939
+ elt.contentEditable = "false";
37940
+ elt.classList.add("ProseMirror-widget");
37827
37941
  }
37828
37942
  super(parent, [], dom, null);
37829
37943
  this.widget = widget;
@@ -37959,7 +38073,7 @@ so this becomes the fallback color for the slot */ ''}
37959
38073
  if (node.isText) {
37960
38074
  if (!dom)
37961
38075
  dom = document.createTextNode(node.text);
37962
- else if (dom.nodeType != 3)
38076
+ else if (!isText(dom))
37963
38077
  throw new RangeError("Text must be rendered as a DOM text node");
37964
38078
  }
37965
38079
  else if (!dom) {
@@ -38011,7 +38125,7 @@ so this becomes the fallback color for the slot */ ''}
38011
38125
  }
38012
38126
  if (!rule.contentElement) {
38013
38127
  let found = addedNodes &&
38014
- addedNodes.find(n => n.nodeType == 1 && addedNodes.indexOf(n.parentNode) < 0 && this.dom.contains(n));
38128
+ addedNodes.find(n => isElt(n) && addedNodes.indexOf(n.parentNode) < 0 && this.dom.contains(n));
38015
38129
  if (found)
38016
38130
  rule.contentElement = found;
38017
38131
  else
@@ -38036,6 +38150,7 @@ so this becomes the fallback color for the slot */ ''}
38036
38150
  let localComposition = composition && composition.pos > -1 ? composition : null;
38037
38151
  let compositionInChild = composition && composition.pos < 0;
38038
38152
  let updater = new ViewTreeUpdater(this, localComposition && localComposition.node, view);
38153
+ let addBuffers = this.node.inlineContent, atBufferPos = addBuffers && this.node.isBlock;
38039
38154
  iterDeco(this.node, this.innerDeco, (widget, i, insideNode) => {
38040
38155
  if (widget.spec.marks)
38041
38156
  updater.syncToMarks(widget.spec.marks, inline, view, i);
@@ -38047,6 +38162,8 @@ so this becomes the fallback color for the slot */ ''}
38047
38162
  }, (child, outerDeco, innerDeco, i) => {
38048
38163
  // Make sure the wrapping mark descs match the node's marks.
38049
38164
  updater.syncToMarks(child.marks, inline, view, i);
38165
+ if (atBufferPos && child.isAtom && !child.isText)
38166
+ updater.addHackNode("IMG", updater.top);
38050
38167
  // Try several strategies for drawing this node
38051
38168
  let compIndex;
38052
38169
  if (updater.findNodeMatch(child, outerDeco, innerDeco, i)) ;
@@ -38060,6 +38177,8 @@ so this becomes the fallback color for the slot */ ''}
38060
38177
  updater.addNode(child, outerDeco, innerDeco, view, off);
38061
38178
  }
38062
38179
  off += child.nodeSize;
38180
+ if (addBuffers)
38181
+ atBufferPos = child.isAtom && !child.isText;
38063
38182
  });
38064
38183
  // Drop all remaining descs after the current position.
38065
38184
  updater.syncToMarks([], inline, view, 0);
@@ -38138,7 +38257,7 @@ so this becomes the fallback color for the slot */ ''}
38138
38257
  updateOuterDeco(outerDeco) {
38139
38258
  if (sameOuterDeco(outerDeco, this.outerDeco))
38140
38259
  return;
38141
- let needsWrap = this.nodeDOM.nodeType != 1;
38260
+ let needsWrap = !isElt(this.nodeDOM);
38142
38261
  let oldDOM = this.dom;
38143
38262
  this.dom = patchOuterDeco(this.dom, this.nodeDOM, computeOuterDeco(this.outerDeco, this.node, needsWrap), computeOuterDeco(outerDeco, this.node, needsWrap));
38144
38263
  if (this.dom != oldDOM) {
@@ -38149,7 +38268,7 @@ so this becomes the fallback color for the slot */ ''}
38149
38268
  }
38150
38269
  // Mark this node as being the selected node.
38151
38270
  selectNode() {
38152
- if (this.nodeDOM.nodeType == 1) {
38271
+ if (isElt(this.nodeDOM)) {
38153
38272
  this.nodeDOM.classList.add("ProseMirror-selectednode");
38154
38273
  if (this.contentDOM || !this.node.type.spec.draggable)
38155
38274
  this.nodeDOM.draggable = true;
@@ -38157,7 +38276,7 @@ so this becomes the fallback color for the slot */ ''}
38157
38276
  }
38158
38277
  // Remove selected node marking from this node.
38159
38278
  deselectNode() {
38160
- if (this.nodeDOM.nodeType == 1) {
38279
+ if (isElt(this.nodeDOM)) {
38161
38280
  this.nodeDOM.classList.remove("ProseMirror-selectednode");
38162
38281
  if (this.contentDOM || !this.node.type.spec.draggable)
38163
38282
  this.nodeDOM.removeAttribute("draggable");
@@ -38228,9 +38347,9 @@ so this becomes the fallback color for the slot */ ''}
38228
38347
  get domAtom() { return false; }
38229
38348
  isText(text) { return this.node.text == text; }
38230
38349
  }
38231
- // A dummy desc used to tag trailing BR or IMG nodes created to work
38350
+ // A dummy desc used to tag extra BR or IMG nodes created to work
38232
38351
  // around contentEditable terribleness.
38233
- class TrailingHackViewDesc extends ViewDesc {
38352
+ class BufferHackViewDesc extends ViewDesc {
38234
38353
  parseRule() { return { ignore: true }; }
38235
38354
  matchesHack(nodeName) { return this.dirty == NOT_DIRTY && this.dom.nodeName == nodeName; }
38236
38355
  get domAtom() { return true; }
@@ -38403,7 +38522,7 @@ so this becomes the fallback color for the slot */ ''}
38403
38522
  }
38404
38523
  }
38405
38524
  function applyOuterDeco(dom, deco, node) {
38406
- return patchOuterDeco(dom, dom, noDeco, computeOuterDeco(deco, node, dom.nodeType != 1));
38525
+ return patchOuterDeco(dom, dom, noDeco, computeOuterDeco(deco, node, !isElt(dom)));
38407
38526
  }
38408
38527
  function sameOuterDeco(a, b) {
38409
38528
  if (a.length != b.length)
@@ -38666,7 +38785,7 @@ so this becomes the fallback color for the slot */ ''}
38666
38785
  }
38667
38786
  if (nodeName == "BR")
38668
38787
  dom.className = "ProseMirror-trailingBreak";
38669
- let hack = new TrailingHackViewDesc(this.top, [], dom, null);
38788
+ let hack = new BufferHackViewDesc(this.top, [], dom, null);
38670
38789
  if (parent != this.top)
38671
38790
  parent.children.push(hack);
38672
38791
  else
@@ -38675,7 +38794,7 @@ so this becomes the fallback color for the slot */ ''}
38675
38794
  }
38676
38795
  }
38677
38796
  isLocked(node) {
38678
- return this.lock && (node == this.lock || node.nodeType == 1 && node.contains(this.lock.parentNode));
38797
+ return this.lock && (node == this.lock || isElt(node) && node.contains(this.lock.parentNode));
38679
38798
  }
38680
38799
  }
38681
38800
  // Iterate from the end of the fragment and array of descs to find
@@ -38877,12 +38996,27 @@ so this becomes the fallback color for the slot */ ''}
38877
38996
  anchor = head;
38878
38997
  while (nearestDesc && !nearestDesc.node)
38879
38998
  nearestDesc = nearestDesc.parent;
38880
- let nearestDescNode = nearestDesc.node;
38881
- if (nearestDesc && nearestDescNode.isAtom && NodeSelection.isSelectable(nearestDescNode) && nearestDesc.parent
38882
- && !(nearestDescNode.isInline && isOnEdge(domSel.focusNode, domSel.focusOffset, nearestDesc.dom))) {
38999
+ if (nearestDesc && nearestDesc.node.isAtom && NodeSelection.isSelectable(nearestDesc.node) &&
39000
+ nearestDesc.parent &&
39001
+ !(nearestDesc.node.isInline && isOnEdge(domSel.focusNode, domSel.focusOffset, nearestDesc.dom))) {
38883
39002
  let pos = nearestDesc.posBefore;
38884
39003
  selection = new NodeSelection(head == pos ? $head : doc.resolve(pos));
38885
39004
  }
39005
+ else if (gecko && origin == "key" && head > view.state.selection.to &&
39006
+ isElt(domSel.focusNode) && domSel.focusOffset == domSel.focusNode.childNodes.length &&
39007
+ nearestDesc && nearestDesc.posAtStart > view.state.selection.to) {
39008
+ // Firefox will jump across scrollable wrapper nodes on keyboard
39009
+ // cursor motion (#1594). This tries to detect this situation
39010
+ // and work around it.
39011
+ for (let scan = domSel.focusNode;; scan = scan.parentNode) {
39012
+ if (getComputedStyle(scan).overflow != "visible") {
39013
+ selection = Selection$2.findFrom(doc.resolve(nearestDesc.posAtStart), 1);
39014
+ break;
39015
+ }
39016
+ if (scan == nearestDesc.dom || scan.nextSibling || !scan.parentNode || !isElt(scan.parentNode))
39017
+ break;
39018
+ }
39019
+ }
38886
39020
  }
38887
39021
  else {
38888
39022
  if (domSel instanceof view.dom.ownerDocument.defaultView.Selection && domSel.rangeCount > 1) {
@@ -39068,8 +39202,7 @@ so this becomes the fallback color for the slot */ ''}
39068
39202
  // Firefox will raise 'permission denied' errors when accessing
39069
39203
  // properties of `sel.anchorNode` when it's in a generated CSS
39070
39204
  // element.
39071
- return view.dom.contains(sel.anchorNode.nodeType == 3 ? sel.anchorNode.parentNode : sel.anchorNode) &&
39072
- (view.editable || view.dom.contains(sel.focusNode.nodeType == 3 ? sel.focusNode.parentNode : sel.focusNode));
39205
+ return contains(view.dom, sel.anchorNode) && (view.editable || contains(view.dom, sel.focusNode));
39073
39206
  }
39074
39207
  catch (_) {
39075
39208
  return false;
@@ -39120,15 +39253,14 @@ so this becomes the fallback color for the slot */ ''}
39120
39253
  if (NodeSelection.isSelectable(node)) {
39121
39254
  return apply(view, new NodeSelection(dir < 0 ? view.state.doc.resolve($head.pos - node.nodeSize) : $head));
39122
39255
  }
39123
- else if (webkit) {
39256
+ else {
39124
39257
  // Chrome and Safari will introduce extra pointless cursor
39125
- // positions around inline uneditable nodes, so we have to
39126
- // take over and move the cursor past them (#937)
39258
+ // positions around inline uneditable nodes (#937), and
39259
+ // Firefox will sometimes just plain refuse to move across
39260
+ // them (#1592), so in this situation we move the cursor
39261
+ // ourselves.
39127
39262
  return apply(view, new TextSelection(view.state.doc.resolve(dir < 0 ? nodePos : nodePos + node.nodeSize)));
39128
39263
  }
39129
- else {
39130
- return false;
39131
- }
39132
39264
  }
39133
39265
  }
39134
39266
  else if (sel instanceof NodeSelection && sel.node.isInline) {
@@ -39141,12 +39273,10 @@ so this becomes the fallback color for the slot */ ''}
39141
39273
  return false;
39142
39274
  }
39143
39275
  }
39144
- function nodeLen(node) {
39145
- return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length;
39146
- }
39147
39276
  function isIgnorable(dom, dir) {
39148
39277
  let desc = dom.pmViewDesc;
39149
- return desc && desc.size == 0 && (dir < 0 || dom.nextSibling || dom.nodeName != "BR");
39278
+ return desc ? desc.size == 0 && (dir < 0 || dom.nextSibling || dom.nodeName != "BR")
39279
+ : isElt(dom) && dom.contentEditable == "false";
39150
39280
  }
39151
39281
  function skipIgnoredNodes(view, dir) {
39152
39282
  return dir < 0 ? skipIgnoredNodesBefore(view) : skipIgnoredNodesAfter(view);
@@ -39162,25 +39292,23 @@ so this becomes the fallback color for the slot */ ''}
39162
39292
  // Gecko will do odd things when the selection is directly in front
39163
39293
  // of a non-editable node, so in that case, move it into the next
39164
39294
  // node if possible. Issue prosemirror/prosemirror#832.
39165
- if (gecko && node.nodeType == 1 && offset < nodeLen(node) && isIgnorable(node.childNodes[offset], -1))
39295
+ if (gecko && isElt(node) && offset < nodeSize(node) && isIgnorable(node.childNodes[offset], -1))
39166
39296
  force = true;
39167
39297
  for (;;) {
39168
39298
  if (offset > 0) {
39169
- if (node.nodeType != 1) {
39299
+ if (!isElt(node))
39170
39300
  break;
39301
+ let before = node.childNodes[offset - 1];
39302
+ if (isIgnorable(before, -1)) {
39303
+ moveNode = node;
39304
+ moveOffset = --offset;
39305
+ }
39306
+ else if (isText(before)) {
39307
+ node = before;
39308
+ offset = node.nodeValue.length;
39171
39309
  }
39172
39310
  else {
39173
- let before = node.childNodes[offset - 1];
39174
- if (isIgnorable(before, -1)) {
39175
- moveNode = node;
39176
- moveOffset = --offset;
39177
- }
39178
- else if (before.nodeType == 3) {
39179
- node = before;
39180
- offset = node.nodeValue.length;
39181
- }
39182
- else
39183
- break;
39311
+ break;
39184
39312
  }
39185
39313
  }
39186
39314
  else if (isBlockNode(node)) {
@@ -39201,7 +39329,7 @@ so this becomes the fallback color for the slot */ ''}
39201
39329
  }
39202
39330
  else {
39203
39331
  node = prev;
39204
- offset = nodeLen(node);
39332
+ offset = nodeSize(node);
39205
39333
  }
39206
39334
  }
39207
39335
  }
@@ -39217,19 +39345,20 @@ so this becomes the fallback color for the slot */ ''}
39217
39345
  let node = sel.focusNode, offset = sel.focusOffset;
39218
39346
  if (!node)
39219
39347
  return;
39220
- let len = nodeLen(node);
39348
+ let len = nodeSize(node);
39221
39349
  let moveNode, moveOffset;
39222
39350
  for (;;) {
39223
39351
  if (offset < len) {
39224
- if (node.nodeType != 1)
39352
+ if (!isElt(node))
39225
39353
  break;
39226
39354
  let after = node.childNodes[offset];
39227
39355
  if (isIgnorable(after, 1)) {
39228
39356
  moveNode = node;
39229
39357
  moveOffset = ++offset;
39230
39358
  }
39231
- else
39359
+ else {
39232
39360
  break;
39361
+ }
39233
39362
  }
39234
39363
  else if (isBlockNode(node)) {
39235
39364
  break;
@@ -39250,7 +39379,7 @@ so this becomes the fallback color for the slot */ ''}
39250
39379
  else {
39251
39380
  node = next;
39252
39381
  offset = 0;
39253
- len = nodeLen(node);
39382
+ len = nodeSize(node);
39254
39383
  }
39255
39384
  }
39256
39385
  }
@@ -39268,9 +39397,9 @@ so this becomes the fallback color for the slot */ ''}
39268
39397
  }
39269
39398
  while (node && offset < node.childNodes.length) {
39270
39399
  let next = node.childNodes[offset];
39271
- if (next.nodeType == 3)
39400
+ if (isText(next))
39272
39401
  return next;
39273
- if (next.nodeType == 1 && next.contentEditable == "false")
39402
+ if (isElt(next) && next.contentEditable == "false")
39274
39403
  break;
39275
39404
  node = next;
39276
39405
  offset = 0;
@@ -39283,16 +39412,16 @@ so this becomes the fallback color for the slot */ ''}
39283
39412
  }
39284
39413
  while (node && offset) {
39285
39414
  let next = node.childNodes[offset - 1];
39286
- if (next.nodeType == 3)
39415
+ if (isText(next))
39287
39416
  return next;
39288
- if (next.nodeType == 1 && next.contentEditable == "false")
39417
+ if (isElt(next) && next.contentEditable == "false")
39289
39418
  break;
39290
39419
  node = next;
39291
39420
  offset = node.childNodes.length;
39292
39421
  }
39293
39422
  }
39294
39423
  function setSelFocus(view, node, offset) {
39295
- if (node.nodeType != 3) {
39424
+ if (!isText(node)) {
39296
39425
  let before, after;
39297
39426
  if (after = textNodeAfter(node, offset)) {
39298
39427
  node = after;
@@ -39402,8 +39531,8 @@ so this becomes the fallback color for the slot */ ''}
39402
39531
  if (!safari || view.state.selection.$head.parentOffset > 0)
39403
39532
  return false;
39404
39533
  let { focusNode, focusOffset } = view.domSelectionRange();
39405
- if (focusNode && focusNode.nodeType == 1 && focusOffset == 0 &&
39406
- focusNode.firstChild && focusNode.firstChild.contentEditable == "false") {
39534
+ if (focusNode && isElt(focusNode) && focusOffset == 0 &&
39535
+ focusNode.firstChild && isElt(focusNode.firstChild) && focusNode.firstChild.contentEditable == "false") {
39407
39536
  let child = focusNode.firstChild;
39408
39537
  switchEditable(view, child, "true");
39409
39538
  setTimeout(() => switchEditable(view, child, "false"), 20);
@@ -39474,7 +39603,7 @@ so this becomes the fallback color for the slot */ ''}
39474
39603
  let doc = detachedDoc(), wrap = doc.createElement("div");
39475
39604
  wrap.appendChild(serializer.serializeFragment(content, { document: doc }));
39476
39605
  let firstChild = wrap.firstChild, needsWrap, wrappers = 0;
39477
- while (firstChild && firstChild.nodeType == 1 && (needsWrap = wrapMap[firstChild.nodeName.toLowerCase()])) {
39606
+ while (firstChild && isElt(firstChild) && (needsWrap = wrapMap[firstChild.nodeName.toLowerCase()])) {
39478
39607
  for (let i = needsWrap.length - 1; i >= 0; i--) {
39479
39608
  let wrapper = doc.createElement(needsWrap[i]);
39480
39609
  while (wrap.firstChild)
@@ -39484,7 +39613,7 @@ so this becomes the fallback color for the slot */ ''}
39484
39613
  }
39485
39614
  firstChild = wrap.firstChild;
39486
39615
  }
39487
- if (firstChild && firstChild.nodeType == 1)
39616
+ if (firstChild && isElt(firstChild))
39488
39617
  firstChild.setAttribute("data-pm-slice", `${openStart} ${openEnd}${wrappers ? ` -${wrappers}` : ""} ${JSON.stringify(context)}`);
39489
39618
  let text = view.someProp("clipboardTextSerializer", f => f(slice, view)) ||
39490
39619
  slice.content.textBetween(0, slice.content.size, "\n\n");
@@ -39530,7 +39659,7 @@ so this becomes the fallback color for the slot */ ''}
39530
39659
  if (sliceData && sliceData[3])
39531
39660
  for (let i = +sliceData[3]; i > 0; i--) {
39532
39661
  let child = dom.firstChild;
39533
- while (child && child.nodeType != 1)
39662
+ while (child && !isElt(child))
39534
39663
  child = child.nextSibling;
39535
39664
  if (!child)
39536
39665
  break;
@@ -39735,12 +39864,11 @@ so this becomes the fallback color for the slot */ ''}
39735
39864
  if (!type || type.hasRequiredAttrs())
39736
39865
  break;
39737
39866
  try {
39738
- type.checkAttrs(array[i + 1]);
39867
+ content = Fragment.from(type.create(array[i + 1], content));
39739
39868
  }
39740
39869
  catch (e) {
39741
39870
  break;
39742
39871
  }
39743
- content = Fragment.from(type.create(array[i + 1], content));
39744
39872
  openStart++;
39745
39873
  openEnd++;
39746
39874
  }
@@ -40072,7 +40200,7 @@ so this becomes the fallback color for the slot */ ''}
40072
40200
  }
40073
40201
  const target = flushed ? null : event.target;
40074
40202
  const targetDesc = target ? view.docView.nearestDesc(target, true) : null;
40075
- this.target = targetDesc && targetDesc.nodeDOM.nodeType == 1 ? targetDesc.nodeDOM : null;
40203
+ this.target = targetDesc && isElt(targetDesc.nodeDOM) ? targetDesc.nodeDOM : null;
40076
40204
  let { selection } = view.state;
40077
40205
  if (event.button == 0 &&
40078
40206
  (targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false ||
@@ -40220,7 +40348,7 @@ so this becomes the fallback color for the slot */ ''}
40220
40348
  if (!view.composing) {
40221
40349
  view.domObserver.flush();
40222
40350
  let { state } = view, $pos = state.selection.$to;
40223
- if (state.selection instanceof TextSelection &&
40351
+ if (state.selection instanceof TextSelection && state.selection.empty &&
40224
40352
  (state.storedMarks ||
40225
40353
  (!$pos.textOffset && $pos.parentOffset && $pos.nodeBefore.marks.some(m => m.type.spec.inclusive === false)) ||
40226
40354
  chrome && windows$1 && selectionBeforeUneditable(view))) { // Issue #1500
@@ -40236,11 +40364,11 @@ so this becomes the fallback color for the slot */ ''}
40236
40364
  // inside if necessary.
40237
40365
  if (gecko && state.selection.empty && $pos.parentOffset && !$pos.textOffset && $pos.nodeBefore.marks.length) {
40238
40366
  let sel = view.domSelectionRange();
40239
- for (let node = sel.focusNode, offset = sel.focusOffset; node && node.nodeType == 1 && offset != 0;) {
40367
+ for (let node = sel.focusNode, offset = sel.focusOffset; node && isElt(node) && offset != 0;) {
40240
40368
  let before = offset < 0 ? node.lastChild : node.childNodes[offset - 1];
40241
40369
  if (!before)
40242
40370
  break;
40243
- if (before.nodeType == 3) {
40371
+ if (isText(before)) {
40244
40372
  let sel = view.domSelection();
40245
40373
  if (sel)
40246
40374
  sel.collapse(before, before.nodeValue.length);
@@ -40259,10 +40387,10 @@ so this becomes the fallback color for the slot */ ''}
40259
40387
  };
40260
40388
  function selectionBeforeUneditable(view) {
40261
40389
  let { focusNode, focusOffset } = view.domSelectionRange();
40262
- if (!focusNode || focusNode.nodeType != 1 || focusOffset >= focusNode.childNodes.length)
40390
+ if (!focusNode || !isElt(focusNode) || focusOffset >= focusNode.childNodes.length)
40263
40391
  return false;
40264
40392
  let next = focusNode.childNodes[focusOffset];
40265
- return next.nodeType == 1 && next.contentEditable == "false";
40393
+ return isElt(next) && next.contentEditable == "false";
40266
40394
  }
40267
40395
  editHandlers.compositionend = (view, event) => {
40268
40396
  if (view.composing) {
@@ -40464,7 +40592,7 @@ so this becomes the fallback color for the slot */ ''}
40464
40592
  else if (mouseDown && mouseDown.mightDrag) {
40465
40593
  node = NodeSelection.create(view.state.doc, mouseDown.mightDrag.pos);
40466
40594
  }
40467
- else if (event.target && event.target.nodeType == 1) {
40595
+ else if (event.target && isElt(event.target)) {
40468
40596
  let desc = view.docView.nearestDesc(event.target, true);
40469
40597
  if (desc && desc.node.type.spec.draggable && desc != view.docView)
40470
40598
  node = NodeSelection.create(view.state.doc, desc.posBefore);
@@ -41435,7 +41563,7 @@ so this becomes the fallback color for the slot */ ''}
41435
41563
  let desc = container && this.view.docView.nearestDesc(container);
41436
41564
  if (desc && desc.ignoreMutation({
41437
41565
  type: "selection",
41438
- target: container.nodeType == 3 ? container.parentNode : container
41566
+ target: isText(container) ? container.parentNode : container
41439
41567
  })) {
41440
41568
  this.setCurSelection();
41441
41569
  return true;
@@ -41477,7 +41605,7 @@ so this becomes the fallback color for the slot */ ''}
41477
41605
  for (let node of added)
41478
41606
  if (node.nodeName == "BR" && node.parentNode) {
41479
41607
  let after = node.nextSibling;
41480
- while (after && after.nodeType == 1) {
41608
+ while (after && isElt(after)) {
41481
41609
  if (after.contentEditable == "false") {
41482
41610
  node.parentNode.removeChild(node);
41483
41611
  break;
@@ -41550,7 +41678,7 @@ so this becomes the fallback color for the slot */ ''}
41550
41678
  for (let i = 0; i < mut.addedNodes.length; i++) {
41551
41679
  let node = mut.addedNodes[i];
41552
41680
  added.push(node);
41553
- if (node.nodeType == 3)
41681
+ if (isText(node))
41554
41682
  this.lastChangedTextNode = node;
41555
41683
  }
41556
41684
  if (desc.contentDOM && desc.contentDOM != desc.dom && !desc.contentDOM.contains(mut.target))
@@ -41665,8 +41793,7 @@ so this becomes the fallback color for the slot */ ''}
41665
41793
  let parent = nextCell;
41666
41794
  for (;;) {
41667
41795
  let first = parent.firstChild;
41668
- if (!first || first.nodeType != 1 || first.contentEditable == "false" ||
41669
- /^(BR|IMG)$/.test(first.nodeName))
41796
+ if (!first || !isElt(first) || first.contentEditable == "false" || /^(BR|IMG)$/.test(first.nodeName))
41670
41797
  break;
41671
41798
  parent = first;
41672
41799
  }
@@ -41691,7 +41818,7 @@ so this becomes the fallback color for the slot */ ''}
41691
41818
  let domSel = view.domSelectionRange();
41692
41819
  let find;
41693
41820
  let anchor = domSel.anchorNode;
41694
- if (anchor && view.dom.contains(anchor.nodeType == 1 ? anchor : anchor.parentNode)) {
41821
+ if (anchor && contains(view.dom, anchor)) {
41695
41822
  find = [{ node: anchor, offset: domSel.anchorOffset }];
41696
41823
  if (!selectionCollapsed(domSel))
41697
41824
  find.push({ node: domSel.focusNode, offset: domSel.focusOffset });
@@ -41799,7 +41926,7 @@ so this becomes the fallback color for the slot */ ''}
41799
41926
  if (change)
41800
41927
  view.input.domChangeCount++;
41801
41928
  if ((ios && view.input.lastIOSEnter > Date.now() - 225 || android) &&
41802
- addedNodes.some(n => n.nodeType == 1 && !isInline.test(n.nodeName)) &&
41929
+ addedNodes.some(n => isElt(n) && !isInline.test(n.nodeName)) &&
41803
41930
  (!change || change.endA >= change.endB) &&
41804
41931
  view.someProp("handleKeyDown", f => f(view, keyEvent(13, "Enter")))) {
41805
41932
  view.input.lastIOSEnter = 0;
@@ -41857,9 +41984,7 @@ so this becomes the fallback color for the slot */ ''}
41857
41984
  // as being an iOS enter press), just dispatch an Enter key instead.
41858
41985
  if (((ios && view.input.lastIOSEnter > Date.now() - 225 &&
41859
41986
  (!inlineChange || addedNodes.some(n => n.nodeName == "DIV" || n.nodeName == "P"))) ||
41860
- (!inlineChange && $from.pos < parse.doc.content.size &&
41861
- (!$from.sameParent($to) || !$from.parent.inlineContent) &&
41862
- $from.pos < $to.pos && !/\S/.test(parse.doc.textBetween($from.pos, $to.pos, "", "")))) &&
41987
+ (!inlineChange && looksLikeEnter(parse.doc, $from.pos, $to.pos))) &&
41863
41988
  view.someProp("handleKeyDown", f => f(view, keyEvent(13, "Enter")))) {
41864
41989
  view.input.lastIOSEnter = 0;
41865
41990
  return;
@@ -42010,6 +42135,16 @@ so this becomes the fallback color for the slot */ ''}
42010
42135
  // The fragments after the join point must match
42011
42136
  return $newStart.parent.content.cut($newStart.parentOffset).eq($next.parent.content);
42012
42137
  }
42138
+ function looksLikeEnter(content, from, to) {
42139
+ let newTextlines = 0, newLeaves = 0;
42140
+ content.nodesBetween(from, to, (node, pos) => {
42141
+ if (node.isTextblock && pos >= from && pos < to)
42142
+ newTextlines++;
42143
+ else if (node.isText ? /\S/.test(node.text.slice(Math.max(0, from - pos), Math.min(node.nodeSize, to - pos))) : node.isLeaf)
42144
+ newLeaves++;
42145
+ });
42146
+ return newLeaves == 0 && newTextlines == 1;
42147
+ }
42013
42148
  function skipClosingAndOpening($pos, fromEnd, mayOpen) {
42014
42149
  let depth = $pos.depth, end = fromEnd ? $pos.end() : $pos.pos;
42015
42150
  while (depth > 0 && (fromEnd || $pos.indexAfter(depth) == $pos.node(depth).childCount)) {
@@ -42270,11 +42405,11 @@ so this becomes the fallback color for the slot */ ''}
42270
42405
  */
42271
42406
  scrollToSelection() {
42272
42407
  let startDOM = this.domSelectionRange().focusNode;
42273
- if (!startDOM || !this.dom.contains(startDOM.nodeType == 1 ? startDOM : startDOM.parentNode)) ;
42408
+ if (!startDOM || !contains(this.dom, startDOM)) ;
42274
42409
  else if (this.someProp("handleScrollToSelection", f => f(this))) ;
42275
42410
  else if (this.state.selection instanceof NodeSelection) {
42276
42411
  let target = this.docView.domAfterPos(this.state.selection.from);
42277
- if (target.nodeType == 1)
42412
+ if (isElt(target))
42278
42413
  scrollRectIntoView(this, target.getBoundingClientRect(), startDOM);
42279
42414
  }
42280
42415
  else {
@@ -42539,7 +42674,7 @@ so this becomes the fallback color for the slot */ ''}
42539
42674
  @internal
42540
42675
  */
42541
42676
  domSelectionRange() {
42542
- let sel = this.domSelection();
42677
+ let sel = this.dom.isConnected !== false && this.domSelection();
42543
42678
  if (!sel)
42544
42679
  return { focusNode: null, focusOffset: 0, anchorNode: null, anchorOffset: 0 };
42545
42680
  return safari && this.root.nodeType === 11 &&
@@ -42870,336 +43005,967 @@ so this becomes the fallback color for the slot */ ''}
42870
43005
  };
42871
43006
  }
42872
43007
 
42873
- //#region src/helpers/createChainableState.ts
42874
- /**
42875
- * Takes a Transaction & Editor State and turns it into a chainable state object
42876
- * @param config The transaction and state to create the chainable state from
42877
- * @returns A chainable Editor state object
42878
- */
42879
- function createChainableState(config) {
42880
- const { state, transaction } = config;
42881
- let { selection } = transaction;
42882
- let { doc } = transaction;
42883
- let { storedMarks } = transaction;
42884
- return {
42885
- ...state,
42886
- apply: state.apply.bind(state),
42887
- applyTransaction: state.applyTransaction.bind(state),
42888
- plugins: state.plugins,
42889
- schema: state.schema,
42890
- reconfigure: state.reconfigure.bind(state),
42891
- toJSON: state.toJSON.bind(state),
42892
- get storedMarks() {
42893
- return storedMarks;
42894
- },
42895
- get selection() {
42896
- return selection;
42897
- },
42898
- get doc() {
42899
- return doc;
42900
- },
42901
- get tr() {
42902
- selection = transaction.selection;
42903
- doc = transaction.doc;
42904
- storedMarks = transaction.storedMarks;
42905
- return transaction;
42906
- }
42907
- };
42908
- }
42909
- //#endregion
42910
- //#region src/CommandManager.ts
42911
- var CommandManager = class CommandManager {
42912
- constructor(props) {
42913
- this.editor = props.editor;
42914
- this.rawCommands = this.editor.extensionManager.commands;
42915
- this.customState = props.state;
42916
- }
42917
- get hasCustomState() {
42918
- return !!this.customState;
42919
- }
42920
- get state() {
42921
- return this.customState || this.editor.state;
42922
- }
42923
- get commands() {
42924
- const { rawCommands, editor, state } = this;
42925
- const { view } = editor;
42926
- const { tr } = state;
42927
- const props = this.buildProps(tr);
42928
- return Object.fromEntries(Object.entries(rawCommands).map(([name, command]) => {
42929
- const method = (...args) => {
42930
- const callback = command(...args)(props);
42931
- if (!tr.getMeta("preventDispatch") && !this.hasCustomState) view.dispatch(tr);
42932
- return callback;
42933
- };
42934
- return [name, method];
42935
- }));
42936
- }
42937
- get chain() {
42938
- return () => this.createChain();
42939
- }
42940
- get can() {
42941
- return () => this.createCan();
42942
- }
42943
- createChain(startTr, shouldDispatch = true) {
42944
- const { rawCommands, editor, state } = this;
42945
- const { view } = editor;
42946
- const callbacks = [];
42947
- const hasStartTransaction = !!startTr;
42948
- const tr = startTr || state.tr;
42949
- const run = () => {
42950
- if (!hasStartTransaction && shouldDispatch && !tr.getMeta("preventDispatch") && !this.hasCustomState) view.dispatch(tr);
42951
- return callbacks.every((callback) => callback === true);
42952
- };
42953
- const chain = {
42954
- ...Object.fromEntries(Object.entries(rawCommands).map(([name, command]) => {
42955
- const chainedCommand = (...args) => {
42956
- const props = this.buildProps(tr, shouldDispatch);
42957
- const callback = command(...args)(props);
42958
- callbacks.push(callback);
42959
- return chain;
42960
- };
42961
- return [name, chainedCommand];
42962
- })),
42963
- run
42964
- };
42965
- return chain;
42966
- }
42967
- /**
42968
- * Creates a chain that safely returns `false` when run.
42969
- * @returns A non-dispatching command chain.
42970
- * @example
42971
- * const chain = CommandManager.createFakeChain()
42972
- * chain.focus().run() // false
42973
- */
42974
- static createFakeChain() {
42975
- const chain = new Proxy({}, { get: (_target, property) => {
42976
- if (property === "then") return;
42977
- if (property === "run") return () => false;
42978
- return () => chain;
42979
- } });
42980
- return chain;
42981
- }
42982
- createCan(startTr) {
42983
- const { rawCommands, state } = this;
42984
- const dispatch = false;
42985
- const tr = startTr || state.tr;
42986
- const props = this.buildProps(tr, dispatch);
42987
- return {
42988
- ...Object.fromEntries(Object.entries(rawCommands).map(([name, command]) => {
42989
- return [name, (...args) => command(...args)({
42990
- ...props,
42991
- dispatch: void 0
42992
- })];
42993
- })),
42994
- chain: () => this.createChain(tr, dispatch)
42995
- };
42996
- }
42997
- /**
42998
- * Creates capability checks that safely return `false`.
42999
- * @returns A non-dispatching capability checker.
43000
- * @example
43001
- * const can = CommandManager.createFallbackCan()
43002
- * can.focus() // false
43003
- */
43004
- static createFallbackCan() {
43005
- const chain = CommandManager.createFakeChain();
43006
- return new Proxy({ chain: () => chain }, { get: (target, property) => {
43007
- if (property === "then") return;
43008
- if (property === "chain") return target.chain;
43009
- return () => false;
43010
- } });
43011
- }
43012
- buildProps(tr, shouldDispatch = true) {
43013
- const { rawCommands, editor, state } = this;
43014
- const { view } = editor;
43015
- const props = {
43016
- tr,
43017
- editor,
43018
- view,
43019
- state: createChainableState({
43020
- state,
43021
- transaction: tr
43022
- }),
43023
- dispatch: shouldDispatch ? () => void 0 : void 0,
43024
- chain: () => this.createChain(tr, shouldDispatch),
43025
- can: () => this.createCan(tr),
43026
- get commands() {
43027
- return Object.fromEntries(Object.entries(rawCommands).map(([name, command]) => {
43028
- return [name, (...args) => command(...args)(props)];
43029
- }));
43030
- }
43031
- };
43032
- return props;
43033
- }
43034
- };
43035
- //#endregion
43036
- //#region src/commands/blur.ts
43037
- const blur = () => ({ editor, view }) => {
43038
- requestAnimationFrame(() => {
43039
- if (!editor.isDestroyed) {
43040
- var _window;
43041
- view.dom.blur();
43042
- (_window = window) === null || _window === void 0 || (_window = _window.getSelection()) === null || _window === void 0 || _window.removeAllRanges();
43043
- }
43044
- });
43045
- return true;
43046
- };
43047
- //#endregion
43048
- //#region src/commands/clearContent.ts
43049
- const clearContent = (emitUpdate = true) => ({ commands }) => {
43050
- return commands.setContent("", { emitUpdate });
43051
- };
43052
- //#endregion
43053
- //#region src/commands/clearNodes.ts
43054
- const clearNodes = () => ({ state, tr, dispatch }) => {
43055
- const { selection } = tr;
43056
- const { ranges } = selection;
43057
- if (!dispatch) return true;
43058
- ranges.forEach(({ $from, $to }) => {
43059
- state.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
43060
- if (node.type.isText) return;
43061
- const { doc, mapping } = tr;
43062
- const $mappedFrom = doc.resolve(mapping.map(pos));
43063
- const $mappedTo = doc.resolve(mapping.map(pos + node.nodeSize));
43064
- const nodeRange = $mappedFrom.blockRange($mappedTo);
43065
- if (!nodeRange) return;
43066
- const targetLiftDepth = liftTarget(nodeRange);
43067
- if (node.type.isTextblock) {
43068
- const { defaultType } = $mappedFrom.parent.contentMatchAt($mappedFrom.index());
43069
- tr.setNodeMarkup(nodeRange.start, defaultType);
43070
- }
43071
- if (targetLiftDepth || targetLiftDepth === 0) tr.lift(nodeRange, targetLiftDepth);
43072
- });
43073
- });
43074
- return true;
43075
- };
43076
- //#endregion
43077
- //#region src/commands/command.ts
43078
- const command = (fn) => (props) => {
43079
- return fn(props);
43080
- };
43081
- //#endregion
43082
- //#region src/commands/createParagraphNear.ts
43083
- const createParagraphNear$1 = () => ({ state, dispatch }) => {
43084
- return createParagraphNear(state, dispatch);
43085
- };
43086
- //#endregion
43087
- //#region src/commands/cut.ts
43088
- const cut = (originRange, targetPos) => ({ editor, tr }) => {
43089
- const { state } = editor;
43090
- const contentSlice = state.doc.slice(originRange.from, originRange.to);
43091
- tr.deleteRange(originRange.from, originRange.to);
43092
- const newPos = tr.mapping.map(targetPos);
43093
- tr.insert(newPos, contentSlice.content);
43094
- tr.setSelection(new TextSelection(tr.doc.resolve(Math.max(newPos - 1, 0))));
43095
- return true;
43008
+ var GOOD_LEAF_SIZE = 200;
43009
+
43010
+ // :: class<T> A rope sequence is a persistent sequence data structure
43011
+ // that supports appending, prepending, and slicing without doing a
43012
+ // full copy. It is represented as a mostly-balanced tree.
43013
+ var RopeSequence = function RopeSequence () {};
43014
+
43015
+ RopeSequence.prototype.append = function append (other) {
43016
+ if (!other.length) { return this }
43017
+ other = RopeSequence.from(other);
43018
+
43019
+ return (!this.length && other) ||
43020
+ (other.length < GOOD_LEAF_SIZE && this.leafAppend(other)) ||
43021
+ (this.length < GOOD_LEAF_SIZE && other.leafPrepend(this)) ||
43022
+ this.appendInner(other)
43096
43023
  };
43097
- //#endregion
43098
- //#region src/commands/deleteCurrentNode.ts
43099
- const deleteCurrentNode = () => ({ tr, dispatch }) => {
43100
- const { selection } = tr;
43101
- const currentNode = selection.$anchor.node();
43102
- if (currentNode.content.size > 0) return false;
43103
- const $pos = tr.selection.$anchor;
43104
- for (let depth = $pos.depth; depth > 0; depth -= 1) if ($pos.node(depth).type === currentNode.type) {
43105
- if (dispatch) {
43106
- const from = $pos.before(depth);
43107
- const to = $pos.after(depth);
43108
- tr.delete(from, to).scrollIntoView();
43109
- }
43110
- return true;
43111
- }
43112
- return false;
43024
+
43025
+ // :: (union<[T], RopeSequence<T>>) → RopeSequence<T>
43026
+ // Prepend an array or other rope to this one, returning a new rope.
43027
+ RopeSequence.prototype.prepend = function prepend (other) {
43028
+ if (!other.length) { return this }
43029
+ return RopeSequence.from(other).append(this)
43113
43030
  };
43114
- //#endregion
43115
- //#region src/helpers/getNodeType.ts
43116
- function getNodeType(nameOrType, schema) {
43117
- if (typeof nameOrType === "string") {
43118
- if (!schema.nodes[nameOrType]) throw Error(`There is no node type named '${nameOrType}'. Maybe you forgot to add the extension?`);
43119
- return schema.nodes[nameOrType];
43120
- }
43121
- return nameOrType;
43122
- }
43123
- //#endregion
43124
- //#region src/commands/deleteNode.ts
43125
- const deleteNode = (typeOrName) => ({ tr, state, dispatch }) => {
43126
- const type = getNodeType(typeOrName, state.schema);
43127
- const $pos = tr.selection.$anchor;
43128
- for (let depth = $pos.depth; depth > 0; depth -= 1) if ($pos.node(depth).type === type) {
43129
- if (dispatch) {
43130
- const from = $pos.before(depth);
43131
- const to = $pos.after(depth);
43132
- tr.delete(from, to).scrollIntoView();
43133
- }
43134
- return true;
43135
- }
43136
- return false;
43031
+
43032
+ RopeSequence.prototype.appendInner = function appendInner (other) {
43033
+ return new Append(this, other)
43137
43034
  };
43138
- //#endregion
43139
- //#region src/commands/deleteRange.ts
43140
- const deleteRange = (range) => ({ tr, dispatch }) => {
43141
- const { from, to } = range;
43142
- if (dispatch) tr.delete(from, to);
43143
- return true;
43035
+
43036
+ // :: (?number, ?number) → RopeSequence<T>
43037
+ // Create a rope repesenting a sub-sequence of this rope.
43038
+ RopeSequence.prototype.slice = function slice (from, to) {
43039
+ if ( from === void 0 ) from = 0;
43040
+ if ( to === void 0 ) to = this.length;
43041
+
43042
+ if (from >= to) { return RopeSequence.empty }
43043
+ return this.sliceInner(Math.max(0, from), Math.min(this.length, to))
43144
43044
  };
43145
- //#endregion
43146
- //#region src/commands/deleteSelection.ts
43147
- /**
43148
- * Check if a node has text content based on its content specification.
43149
- * Returns true if the node's content spec matches text* or text+ patterns.
43150
- */
43151
- const hasTextContent = (nodeSpec) => {
43152
- if (!nodeSpec.content) return false;
43153
- return /^text(\*|\+)/.test(nodeSpec.content);
43045
+
43046
+ // :: (number) → T
43047
+ // Retrieve the element at the given position from this rope.
43048
+ RopeSequence.prototype.get = function get (i) {
43049
+ if (i < 0 || i >= this.length) { return undefined }
43050
+ return this.getInner(i)
43154
43051
  };
43155
- /**
43156
- * Expand selection position for a specific side (left or right) to handle inline text nodes.
43157
- * This function checks if the position is within an inline node with text content and
43158
- * expands it to include the entire node boundaries for proper deletion.
43159
- * @param $pos - The resolved position to expand
43160
- * @param schema - The ProseMirror schema
43161
- * @param side - Which side to expand ('left' or 'right')
43162
- * @returns The expanded position for deletion
43163
- */
43164
- const expandSelectionForSide = ($pos, schema, side) => {
43165
- if (!$pos.parent.isInline) return $pos.pos;
43166
- if (side === "left" && $pos.pos > $pos.start() || side === "right" && $pos.pos < $pos.end()) return $pos.pos;
43167
- const parentContent = schema.nodes[$pos.parent.type.name].spec;
43168
- if (!hasTextContent(parentContent)) return $pos.pos;
43169
- return side === "left" ? $pos.start() - 1 : $pos.end() + 1;
43052
+
43053
+ // :: ((element: T, index: number) → ?bool, ?number, ?number)
43054
+ // Call the given function for each element between the given
43055
+ // indices. This tends to be more efficient than looping over the
43056
+ // indices and calling `get`, because it doesn't have to descend the
43057
+ // tree for every element.
43058
+ RopeSequence.prototype.forEach = function forEach (f, from, to) {
43059
+ if ( from === void 0 ) from = 0;
43060
+ if ( to === void 0 ) to = this.length;
43061
+
43062
+ if (from <= to)
43063
+ { this.forEachInner(f, from, to, 0); }
43064
+ else
43065
+ { this.forEachInvertedInner(f, from, to, 0); }
43170
43066
  };
43171
- /**
43172
- * Expand selection range to properly handle deletion of inline text nodes.
43173
- * Inline text nodes don't collapse correctly when text inside is deleted,
43174
- * so we need to expand the selection to include the entire node.
43175
- * See: https://code.haverbeke.berlin/prosemirror/prosemirror/issues/1365
43176
- */
43177
- const expandSelectionForInlineText = ($from, $to, schema) => {
43178
- return {
43179
- from: expandSelectionForSide($from, schema, "left"),
43180
- to: expandSelectionForSide($to, schema, "right")
43181
- };
43067
+
43068
+ // :: ((element: T, index: number) → U, ?number, ?number) → [U]
43069
+ // Map the given functions over the elements of the rope, producing
43070
+ // a flat array.
43071
+ RopeSequence.prototype.map = function map (f, from, to) {
43072
+ if ( from === void 0 ) from = 0;
43073
+ if ( to === void 0 ) to = this.length;
43074
+
43075
+ var result = [];
43076
+ this.forEach(function (elt, i) { return result.push(f(elt, i)); }, from, to);
43077
+ return result
43182
43078
  };
43183
- const deleteSelection = () => ({ state, dispatch }) => {
43184
- if (state.selection.empty) return false;
43185
- if (dispatch) {
43186
- const tr = state.tr;
43187
- const { ranges } = state.selection;
43188
- const mapFrom = tr.steps.length;
43189
- ranges.forEach((range) => {
43190
- const mapping = tr.mapping.slice(mapFrom);
43191
- const $from = tr.doc.resolve(mapping.map(range.$from.pos));
43192
- const $to = tr.doc.resolve(mapping.map(range.$to.pos));
43193
- const { from, to } = expandSelectionForInlineText($from, $to, state.schema);
43194
- tr.deleteRange(from, to);
43195
- });
43196
- if (!tr.selection.empty) tr.setSelection(TextSelection.near(tr.doc.resolve(tr.selection.from)));
43197
- tr.scrollIntoView();
43198
- dispatch(tr);
43199
- }
43200
- return true;
43079
+
43080
+ // :: (?union<[T], RopeSequence<T>>) → RopeSequence<T>
43081
+ // Create a rope representing the given array, or return the rope
43082
+ // itself if a rope was given.
43083
+ RopeSequence.from = function from (values) {
43084
+ if (values instanceof RopeSequence) { return values }
43085
+ return values && values.length ? new Leaf(values) : RopeSequence.empty
43201
43086
  };
43202
- //#endregion
43087
+
43088
+ var Leaf = /*@__PURE__*/(function (RopeSequence) {
43089
+ function Leaf(values) {
43090
+ RopeSequence.call(this);
43091
+ this.values = values;
43092
+ }
43093
+
43094
+ if ( RopeSequence ) Leaf.__proto__ = RopeSequence;
43095
+ Leaf.prototype = Object.create( RopeSequence && RopeSequence.prototype );
43096
+ Leaf.prototype.constructor = Leaf;
43097
+
43098
+ var prototypeAccessors = { length: { configurable: true },depth: { configurable: true } };
43099
+
43100
+ Leaf.prototype.flatten = function flatten () {
43101
+ return this.values
43102
+ };
43103
+
43104
+ Leaf.prototype.sliceInner = function sliceInner (from, to) {
43105
+ if (from == 0 && to == this.length) { return this }
43106
+ return new Leaf(this.values.slice(from, to))
43107
+ };
43108
+
43109
+ Leaf.prototype.getInner = function getInner (i) {
43110
+ return this.values[i]
43111
+ };
43112
+
43113
+ Leaf.prototype.forEachInner = function forEachInner (f, from, to, start) {
43114
+ for (var i = from; i < to; i++)
43115
+ { if (f(this.values[i], start + i) === false) { return false } }
43116
+ };
43117
+
43118
+ Leaf.prototype.forEachInvertedInner = function forEachInvertedInner (f, from, to, start) {
43119
+ for (var i = from - 1; i >= to; i--)
43120
+ { if (f(this.values[i], start + i) === false) { return false } }
43121
+ };
43122
+
43123
+ Leaf.prototype.leafAppend = function leafAppend (other) {
43124
+ if (this.length + other.length <= GOOD_LEAF_SIZE)
43125
+ { return new Leaf(this.values.concat(other.flatten())) }
43126
+ };
43127
+
43128
+ Leaf.prototype.leafPrepend = function leafPrepend (other) {
43129
+ if (this.length + other.length <= GOOD_LEAF_SIZE)
43130
+ { return new Leaf(other.flatten().concat(this.values)) }
43131
+ };
43132
+
43133
+ prototypeAccessors.length.get = function () { return this.values.length };
43134
+
43135
+ prototypeAccessors.depth.get = function () { return 0 };
43136
+
43137
+ Object.defineProperties( Leaf.prototype, prototypeAccessors );
43138
+
43139
+ return Leaf;
43140
+ }(RopeSequence));
43141
+
43142
+ // :: RopeSequence
43143
+ // The empty rope sequence.
43144
+ RopeSequence.empty = new Leaf([]);
43145
+
43146
+ var Append = /*@__PURE__*/(function (RopeSequence) {
43147
+ function Append(left, right) {
43148
+ RopeSequence.call(this);
43149
+ this.left = left;
43150
+ this.right = right;
43151
+ this.length = left.length + right.length;
43152
+ this.depth = Math.max(left.depth, right.depth) + 1;
43153
+ }
43154
+
43155
+ if ( RopeSequence ) Append.__proto__ = RopeSequence;
43156
+ Append.prototype = Object.create( RopeSequence && RopeSequence.prototype );
43157
+ Append.prototype.constructor = Append;
43158
+
43159
+ Append.prototype.flatten = function flatten () {
43160
+ return this.left.flatten().concat(this.right.flatten())
43161
+ };
43162
+
43163
+ Append.prototype.getInner = function getInner (i) {
43164
+ return i < this.left.length ? this.left.get(i) : this.right.get(i - this.left.length)
43165
+ };
43166
+
43167
+ Append.prototype.forEachInner = function forEachInner (f, from, to, start) {
43168
+ var leftLen = this.left.length;
43169
+ if (from < leftLen &&
43170
+ this.left.forEachInner(f, from, Math.min(to, leftLen), start) === false)
43171
+ { return false }
43172
+ if (to > leftLen &&
43173
+ this.right.forEachInner(f, Math.max(from - leftLen, 0), Math.min(this.length, to) - leftLen, start + leftLen) === false)
43174
+ { return false }
43175
+ };
43176
+
43177
+ Append.prototype.forEachInvertedInner = function forEachInvertedInner (f, from, to, start) {
43178
+ var leftLen = this.left.length;
43179
+ if (from > leftLen &&
43180
+ this.right.forEachInvertedInner(f, from - leftLen, Math.max(to, leftLen) - leftLen, start + leftLen) === false)
43181
+ { return false }
43182
+ if (to < leftLen &&
43183
+ this.left.forEachInvertedInner(f, Math.min(from, leftLen), to, start) === false)
43184
+ { return false }
43185
+ };
43186
+
43187
+ Append.prototype.sliceInner = function sliceInner (from, to) {
43188
+ if (from == 0 && to == this.length) { return this }
43189
+ var leftLen = this.left.length;
43190
+ if (to <= leftLen) { return this.left.slice(from, to) }
43191
+ if (from >= leftLen) { return this.right.slice(from - leftLen, to - leftLen) }
43192
+ return this.left.slice(from, leftLen).append(this.right.slice(0, to - leftLen))
43193
+ };
43194
+
43195
+ Append.prototype.leafAppend = function leafAppend (other) {
43196
+ var inner = this.right.leafAppend(other);
43197
+ if (inner) { return new Append(this.left, inner) }
43198
+ };
43199
+
43200
+ Append.prototype.leafPrepend = function leafPrepend (other) {
43201
+ var inner = this.left.leafPrepend(other);
43202
+ if (inner) { return new Append(inner, this.right) }
43203
+ };
43204
+
43205
+ Append.prototype.appendInner = function appendInner (other) {
43206
+ if (this.left.depth >= Math.max(this.right.depth, other.depth) + 1)
43207
+ { return new Append(this.left, new Append(this.right, other)) }
43208
+ return new Append(this, other)
43209
+ };
43210
+
43211
+ return Append;
43212
+ }(RopeSequence));
43213
+
43214
+ // ProseMirror's history isn't simply a way to roll back to a previous
43215
+ // state, because ProseMirror supports applying changes without adding
43216
+ // them to the history (for example during collaboration).
43217
+ //
43218
+ // To this end, each 'Branch' (one for the undo history and one for
43219
+ // the redo history) keeps an array of 'Items', which can optionally
43220
+ // hold a step (an actual undoable change), and always hold a position
43221
+ // map (which is needed to move changes below them to apply to the
43222
+ // current document).
43223
+ //
43224
+ // An item that has both a step and a selection bookmark is the start
43225
+ // of an 'event' — a group of changes that will be undone or redone at
43226
+ // once. (It stores only the bookmark, since that way we don't have to
43227
+ // provide a document until the selection is actually applied, which
43228
+ // is useful when compressing.)
43229
+ // Used to schedule history compression
43230
+ const max_empty_items = 500;
43231
+ class Branch {
43232
+ constructor(items, eventCount) {
43233
+ this.items = items;
43234
+ this.eventCount = eventCount;
43235
+ }
43236
+ // Pop the latest event off the branch's history and apply it
43237
+ // to a document transform.
43238
+ popEvent(state, preserveItems) {
43239
+ if (this.eventCount == 0)
43240
+ return null;
43241
+ let end = this.items.length;
43242
+ for (;; end--) {
43243
+ let next = this.items.get(end - 1);
43244
+ if (next.selection) {
43245
+ --end;
43246
+ break;
43247
+ }
43248
+ }
43249
+ let remap, mapFrom;
43250
+ if (preserveItems) {
43251
+ remap = this.remapping(end, this.items.length);
43252
+ mapFrom = remap.maps.length;
43253
+ }
43254
+ let transform = state.tr;
43255
+ let selection, remaining;
43256
+ let addAfter = [], addBefore = [];
43257
+ this.items.forEach((item, i) => {
43258
+ if (!item.step) {
43259
+ if (!remap) {
43260
+ remap = this.remapping(end, i + 1);
43261
+ mapFrom = remap.maps.length;
43262
+ }
43263
+ mapFrom--;
43264
+ addBefore.push(item);
43265
+ return;
43266
+ }
43267
+ if (remap) {
43268
+ addBefore.push(new Item(item.map));
43269
+ let step = item.step.map(remap.slice(mapFrom)), map;
43270
+ if (step && transform.maybeStep(step).doc) {
43271
+ map = transform.mapping.maps[transform.mapping.maps.length - 1];
43272
+ addAfter.push(new Item(map, undefined, undefined, addAfter.length + addBefore.length));
43273
+ }
43274
+ mapFrom--;
43275
+ if (map)
43276
+ remap.appendMap(map, mapFrom);
43277
+ }
43278
+ else {
43279
+ transform.maybeStep(item.step);
43280
+ }
43281
+ if (item.selection) {
43282
+ selection = remap ? item.selection.map(remap.slice(mapFrom)) : item.selection;
43283
+ remaining = new Branch(this.items.slice(0, end).append(addBefore.reverse().concat(addAfter)), this.eventCount - 1);
43284
+ return false;
43285
+ }
43286
+ }, this.items.length, 0);
43287
+ return { remaining: remaining, transform, selection: selection };
43288
+ }
43289
+ // Create a new branch with the given transform added.
43290
+ addTransform(transform, selection, histOptions, preserveItems) {
43291
+ let newItems = [], eventCount = this.eventCount;
43292
+ let oldItems = this.items, lastItem = !preserveItems && oldItems.length ? oldItems.get(oldItems.length - 1) : null;
43293
+ for (let i = 0; i < transform.steps.length; i++) {
43294
+ let step = transform.steps[i].invert(transform.docs[i]);
43295
+ let item = new Item(transform.mapping.maps[i], step, selection), merged;
43296
+ if (merged = lastItem && lastItem.merge(item)) {
43297
+ item = merged;
43298
+ if (i)
43299
+ newItems.pop();
43300
+ else
43301
+ oldItems = oldItems.slice(0, oldItems.length - 1);
43302
+ }
43303
+ newItems.push(item);
43304
+ if (selection) {
43305
+ eventCount++;
43306
+ selection = undefined;
43307
+ }
43308
+ if (!preserveItems)
43309
+ lastItem = item;
43310
+ }
43311
+ let overflow = eventCount - histOptions.depth;
43312
+ if (overflow > DEPTH_OVERFLOW) {
43313
+ oldItems = cutOffEvents(oldItems, overflow);
43314
+ eventCount -= overflow;
43315
+ }
43316
+ return new Branch(oldItems.append(newItems), eventCount);
43317
+ }
43318
+ remapping(from, to) {
43319
+ let maps = new Mapping;
43320
+ this.items.forEach((item, i) => {
43321
+ let mirrorPos = item.mirrorOffset != null && i - item.mirrorOffset >= from
43322
+ ? maps.maps.length - item.mirrorOffset : undefined;
43323
+ maps.appendMap(item.map, mirrorPos);
43324
+ }, from, to);
43325
+ return maps;
43326
+ }
43327
+ addMaps(array) {
43328
+ if (this.eventCount == 0)
43329
+ return this;
43330
+ return new Branch(this.items.append(array.map(map => new Item(map))), this.eventCount);
43331
+ }
43332
+ // When the collab module receives remote changes, the history has
43333
+ // to know about those, so that it can adjust the steps that were
43334
+ // rebased on top of the remote changes, and include the position
43335
+ // maps for the remote changes in its array of items.
43336
+ rebased(rebasedTransform, rebasedCount) {
43337
+ if (!this.eventCount)
43338
+ return this;
43339
+ rebasedCount = Math.min(this.items.length, rebasedCount);
43340
+ let rebasedItems = [], start = this.items.length - rebasedCount;
43341
+ let mapping = rebasedTransform.mapping;
43342
+ let newUntil = rebasedTransform.steps.length;
43343
+ let eventCount = this.eventCount;
43344
+ this.items.forEach(item => { if (item.selection)
43345
+ eventCount--; }, start);
43346
+ let iRebased = rebasedCount;
43347
+ this.items.forEach(item => {
43348
+ let pos = mapping.getMirror(--iRebased);
43349
+ if (pos == null)
43350
+ return;
43351
+ newUntil = Math.min(newUntil, pos);
43352
+ let map = mapping.maps[pos];
43353
+ if (item.step) {
43354
+ let step = rebasedTransform.steps[pos].invert(rebasedTransform.docs[pos]);
43355
+ let selection = item.selection && item.selection.map(mapping.slice(iRebased + 1, pos));
43356
+ if (selection)
43357
+ eventCount++;
43358
+ rebasedItems.push(new Item(map, step, selection));
43359
+ }
43360
+ else {
43361
+ rebasedItems.push(new Item(map));
43362
+ }
43363
+ }, start);
43364
+ let newMaps = [];
43365
+ for (let i = rebasedCount; i < newUntil; i++)
43366
+ newMaps.push(new Item(mapping.maps[i]));
43367
+ let items = this.items.slice(0, start).append(newMaps).append(rebasedItems);
43368
+ let branch = new Branch(items, eventCount);
43369
+ if (branch.emptyItemCount() > max_empty_items)
43370
+ branch = branch.compress(this.items.length - rebasedItems.length);
43371
+ return branch;
43372
+ }
43373
+ emptyItemCount() {
43374
+ let count = 0;
43375
+ this.items.forEach(item => { if (!item.step)
43376
+ count++; });
43377
+ return count;
43378
+ }
43379
+ // Compressing a branch means rewriting it to push the air (map-only
43380
+ // items) out. During collaboration, these naturally accumulate
43381
+ // because each remote change adds one. The `upto` argument is used
43382
+ // to ensure that only the items below a given level are compressed,
43383
+ // because `rebased` relies on a clean, untouched set of items in
43384
+ // order to associate old items with rebased steps.
43385
+ compress(upto = this.items.length) {
43386
+ let remap = this.remapping(0, upto), mapFrom = remap.maps.length;
43387
+ let items = [], events = 0;
43388
+ this.items.forEach((item, i) => {
43389
+ if (i >= upto) {
43390
+ items.push(item);
43391
+ if (item.selection)
43392
+ events++;
43393
+ }
43394
+ else if (item.step) {
43395
+ let step = item.step.map(remap.slice(mapFrom)), map = step && step.getMap();
43396
+ mapFrom--;
43397
+ if (map)
43398
+ remap.appendMap(map, mapFrom);
43399
+ if (step) {
43400
+ let selection = item.selection && item.selection.map(remap.slice(mapFrom));
43401
+ if (selection)
43402
+ events++;
43403
+ let newItem = new Item(map.invert(), step, selection), merged, last = items.length - 1;
43404
+ if (merged = items.length && items[last].merge(newItem))
43405
+ items[last] = merged;
43406
+ else
43407
+ items.push(newItem);
43408
+ }
43409
+ }
43410
+ else if (item.map) {
43411
+ mapFrom--;
43412
+ }
43413
+ }, this.items.length, 0);
43414
+ return new Branch(RopeSequence.from(items.reverse()), events);
43415
+ }
43416
+ }
43417
+ Branch.empty = new Branch(RopeSequence.empty, 0);
43418
+ function cutOffEvents(items, n) {
43419
+ let cutPoint;
43420
+ items.forEach((item, i) => {
43421
+ if (item.selection && (n-- == 0)) {
43422
+ cutPoint = i;
43423
+ return false;
43424
+ }
43425
+ });
43426
+ return items.slice(cutPoint);
43427
+ }
43428
+ class Item {
43429
+ constructor(
43430
+ // The (forward) step map for this item.
43431
+ map,
43432
+ // The inverted step
43433
+ step,
43434
+ // If this is non-null, this item is the start of a group, and
43435
+ // this selection is the starting selection for the group (the one
43436
+ // that was active before the first step was applied)
43437
+ selection,
43438
+ // If this item is the inverse of a previous mapping on the stack,
43439
+ // this points at the inverse's offset
43440
+ mirrorOffset) {
43441
+ this.map = map;
43442
+ this.step = step;
43443
+ this.selection = selection;
43444
+ this.mirrorOffset = mirrorOffset;
43445
+ }
43446
+ merge(other) {
43447
+ if (this.step && other.step && !other.selection) {
43448
+ let step = other.step.merge(this.step);
43449
+ if (step)
43450
+ return new Item(step.getMap().invert(), step, this.selection);
43451
+ }
43452
+ }
43453
+ }
43454
+ // The value of the state field that tracks undo/redo history for that
43455
+ // state. Will be stored in the plugin state when the history plugin
43456
+ // is active.
43457
+ class HistoryState {
43458
+ constructor(done, undone, prevRanges, prevTime, prevComposition) {
43459
+ this.done = done;
43460
+ this.undone = undone;
43461
+ this.prevRanges = prevRanges;
43462
+ this.prevTime = prevTime;
43463
+ this.prevComposition = prevComposition;
43464
+ }
43465
+ }
43466
+ const DEPTH_OVERFLOW = 20;
43467
+ // Record a transformation in undo history.
43468
+ function applyTransaction(history, state, tr, options) {
43469
+ let historyTr = tr.getMeta(historyKey), rebased;
43470
+ if (historyTr)
43471
+ return historyTr.historyState;
43472
+ if (tr.getMeta(closeHistoryKey))
43473
+ history = new HistoryState(history.done, history.undone, null, 0, -1);
43474
+ let appended = tr.getMeta("appendedTransaction");
43475
+ if (tr.steps.length == 0) {
43476
+ return history;
43477
+ }
43478
+ else if (appended && appended.getMeta(historyKey)) {
43479
+ if (appended.getMeta(historyKey).redo)
43480
+ return new HistoryState(history.done.addTransform(tr, undefined, options, mustPreserveItems(state)), history.undone, rangesFor(tr.mapping.maps), history.prevTime, history.prevComposition);
43481
+ else
43482
+ return new HistoryState(history.done, history.undone.addTransform(tr, undefined, options, mustPreserveItems(state)), null, history.prevTime, history.prevComposition);
43483
+ }
43484
+ else if (tr.getMeta("addToHistory") !== false && !(appended && appended.getMeta("addToHistory") === false)) {
43485
+ // Group transforms that occur in quick succession into one event.
43486
+ let composition = tr.getMeta("composition");
43487
+ let newGroup = history.prevTime == 0 ||
43488
+ (!appended && history.prevComposition != composition &&
43489
+ (history.prevTime < (tr.time || 0) - options.newGroupDelay || !isAdjacentTo(tr, history.prevRanges)));
43490
+ let prevRanges = appended ? mapRanges(history.prevRanges, tr.mapping) : rangesFor(tr.mapping.maps);
43491
+ return new HistoryState(history.done.addTransform(tr, newGroup ? state.selection.getBookmark() : undefined, options, mustPreserveItems(state)), Branch.empty, prevRanges, tr.time, composition == null ? history.prevComposition : composition);
43492
+ }
43493
+ else if (rebased = tr.getMeta("rebased")) {
43494
+ // Used by the collab module to tell the history that some of its
43495
+ // content has been rebased.
43496
+ return new HistoryState(history.done.rebased(tr, rebased), history.undone.rebased(tr, rebased), mapRanges(history.prevRanges, tr.mapping), history.prevTime, history.prevComposition);
43497
+ }
43498
+ else {
43499
+ return new HistoryState(history.done.addMaps(tr.mapping.maps), history.undone.addMaps(tr.mapping.maps), mapRanges(history.prevRanges, tr.mapping), history.prevTime, history.prevComposition);
43500
+ }
43501
+ }
43502
+ function isAdjacentTo(transform, prevRanges) {
43503
+ if (!prevRanges)
43504
+ return false;
43505
+ if (!transform.docChanged)
43506
+ return true;
43507
+ let adjacent = false;
43508
+ transform.mapping.maps[0].forEach((start, end) => {
43509
+ for (let i = 0; i < prevRanges.length; i += 2)
43510
+ if (start <= prevRanges[i + 1] && end >= prevRanges[i])
43511
+ adjacent = true;
43512
+ });
43513
+ return adjacent;
43514
+ }
43515
+ function rangesFor(maps) {
43516
+ let result = [];
43517
+ for (let i = maps.length - 1; i >= 0 && result.length == 0; i--)
43518
+ maps[i].forEach((_from, _to, from, to) => result.push(from, to));
43519
+ return result;
43520
+ }
43521
+ function mapRanges(ranges, mapping) {
43522
+ if (!ranges)
43523
+ return null;
43524
+ let result = [];
43525
+ for (let i = 0; i < ranges.length; i += 2) {
43526
+ let from = mapping.map(ranges[i], 1), to = mapping.map(ranges[i + 1], -1);
43527
+ if (from <= to)
43528
+ result.push(from, to);
43529
+ }
43530
+ return result;
43531
+ }
43532
+ // Apply the latest event from one branch to the document and shift the event
43533
+ // onto the other branch.
43534
+ function histTransaction(history, state, redo) {
43535
+ let preserveItems = mustPreserveItems(state);
43536
+ let histOptions = historyKey.get(state).spec.config;
43537
+ let pop = (redo ? history.undone : history.done).popEvent(state, preserveItems);
43538
+ if (!pop)
43539
+ return null;
43540
+ let selection = pop.selection.resolve(pop.transform.doc);
43541
+ let added = (redo ? history.done : history.undone).addTransform(pop.transform, state.selection.getBookmark(), histOptions, preserveItems);
43542
+ let newHist = new HistoryState(redo ? added : pop.remaining, redo ? pop.remaining : added, null, 0, -1);
43543
+ return pop.transform.setSelection(selection).setMeta(historyKey, { redo, historyState: newHist });
43544
+ }
43545
+ let cachedPreserveItems = false, cachedPreserveItemsPlugins = null;
43546
+ // Check whether any plugin in the given state has a
43547
+ // `historyPreserveItems` property in its spec, in which case we must
43548
+ // preserve steps exactly as they came in, so that they can be
43549
+ // rebased.
43550
+ function mustPreserveItems(state) {
43551
+ let plugins = state.plugins;
43552
+ if (cachedPreserveItemsPlugins != plugins) {
43553
+ cachedPreserveItems = false;
43554
+ cachedPreserveItemsPlugins = plugins;
43555
+ for (let i = 0; i < plugins.length; i++)
43556
+ if (plugins[i].spec.historyPreserveItems) {
43557
+ cachedPreserveItems = true;
43558
+ break;
43559
+ }
43560
+ }
43561
+ return cachedPreserveItems;
43562
+ }
43563
+ /**
43564
+ Set a flag on the given transaction that will prevent further steps
43565
+ from being appended to an existing history event (so that they
43566
+ require a separate undo command to undo).
43567
+ */
43568
+ function closeHistory(tr) {
43569
+ return tr.setMeta(closeHistoryKey, true);
43570
+ }
43571
+ const historyKey = new PluginKey("history");
43572
+ const closeHistoryKey = new PluginKey("closeHistory");
43573
+ /**
43574
+ Returns a plugin that enables the undo history for an editor. The
43575
+ plugin will track undo and redo stacks, which can be used with the
43576
+ [`undo`](https://prosemirror.net/docs/ref/#history.undo) and [`redo`](https://prosemirror.net/docs/ref/#history.redo) commands.
43577
+
43578
+ You can set an `"addToHistory"` [metadata
43579
+ property](https://prosemirror.net/docs/ref/#state.Transaction.setMeta) of `false` on a transaction
43580
+ to prevent it from being rolled back by undo.
43581
+ */
43582
+ function history(config = {}) {
43583
+ config = { depth: config.depth || 100,
43584
+ newGroupDelay: config.newGroupDelay || 500 };
43585
+ return new Plugin({
43586
+ key: historyKey,
43587
+ state: {
43588
+ init() {
43589
+ return new HistoryState(Branch.empty, Branch.empty, null, 0, -1);
43590
+ },
43591
+ apply(tr, hist, state) {
43592
+ return applyTransaction(hist, state, tr, config);
43593
+ }
43594
+ },
43595
+ config,
43596
+ props: {
43597
+ handleDOMEvents: {
43598
+ beforeinput(view, e) {
43599
+ let inputType = e.inputType;
43600
+ let command = inputType == "historyUndo" ? undo : inputType == "historyRedo" ? redo : null;
43601
+ if (!command || !view.editable)
43602
+ return false;
43603
+ e.preventDefault();
43604
+ return command(view.state, view.dispatch);
43605
+ }
43606
+ }
43607
+ }
43608
+ });
43609
+ }
43610
+ function buildCommand(redo, scroll) {
43611
+ return (state, dispatch) => {
43612
+ let hist = historyKey.getState(state);
43613
+ if (!hist || (redo ? hist.undone : hist.done).eventCount == 0)
43614
+ return false;
43615
+ if (dispatch) {
43616
+ let tr = histTransaction(hist, state, redo);
43617
+ if (tr)
43618
+ dispatch(scroll ? tr.scrollIntoView() : tr);
43619
+ }
43620
+ return true;
43621
+ };
43622
+ }
43623
+ /**
43624
+ A command function that undoes the last change, if any.
43625
+ */
43626
+ const undo = buildCommand(false, true);
43627
+ /**
43628
+ A command function that redoes the last undone change, if any.
43629
+ */
43630
+ const redo = buildCommand(true, true);
43631
+ /**
43632
+ Returns true if the given transaction was generated by the history
43633
+ plugin.
43634
+ */
43635
+ function isHistoryTransaction(tr) {
43636
+ return tr.getMeta(historyKey) != null;
43637
+ }
43638
+
43639
+ //#region src/helpers/createChainableState.ts
43640
+ /**
43641
+ * Takes a Transaction & Editor State and turns it into a chainable state object
43642
+ * @param config The transaction and state to create the chainable state from
43643
+ * @returns A chainable Editor state object
43644
+ */
43645
+ function createChainableState(config) {
43646
+ const { state, transaction } = config;
43647
+ let { selection } = transaction;
43648
+ let { doc } = transaction;
43649
+ let { storedMarks } = transaction;
43650
+ return {
43651
+ ...state,
43652
+ apply: state.apply.bind(state),
43653
+ applyTransaction: state.applyTransaction.bind(state),
43654
+ plugins: state.plugins,
43655
+ schema: state.schema,
43656
+ reconfigure: state.reconfigure.bind(state),
43657
+ toJSON: state.toJSON.bind(state),
43658
+ get storedMarks() {
43659
+ return storedMarks;
43660
+ },
43661
+ get selection() {
43662
+ return selection;
43663
+ },
43664
+ get doc() {
43665
+ return doc;
43666
+ },
43667
+ get tr() {
43668
+ selection = transaction.selection;
43669
+ doc = transaction.doc;
43670
+ storedMarks = transaction.storedMarks;
43671
+ return transaction;
43672
+ }
43673
+ };
43674
+ }
43675
+ //#endregion
43676
+ //#region src/CommandManager.ts
43677
+ var CommandManager = class CommandManager {
43678
+ constructor(props) {
43679
+ this.editor = props.editor;
43680
+ this.rawCommands = this.editor.extensionManager.commands;
43681
+ this.customState = props.state;
43682
+ }
43683
+ get hasCustomState() {
43684
+ return !!this.customState;
43685
+ }
43686
+ get state() {
43687
+ return this.customState || this.editor.state;
43688
+ }
43689
+ get commands() {
43690
+ const { rawCommands, editor, state } = this;
43691
+ const { view } = editor;
43692
+ const { tr } = state;
43693
+ const props = this.buildProps(tr);
43694
+ return Object.fromEntries(Object.entries(rawCommands).map(([name, command]) => {
43695
+ const method = (...args) => {
43696
+ const callback = command(...args)(props);
43697
+ if (!tr.getMeta("preventDispatch") && !this.hasCustomState) view.dispatch(tr);
43698
+ return callback;
43699
+ };
43700
+ return [name, method];
43701
+ }));
43702
+ }
43703
+ get chain() {
43704
+ return () => this.createChain();
43705
+ }
43706
+ get can() {
43707
+ return () => this.createCan();
43708
+ }
43709
+ createChain(startTr, shouldDispatch = true) {
43710
+ const { rawCommands, editor, state } = this;
43711
+ const { view } = editor;
43712
+ const callbacks = [];
43713
+ const hasStartTransaction = !!startTr;
43714
+ const tr = startTr || state.tr;
43715
+ const run = () => {
43716
+ if (!hasStartTransaction && shouldDispatch && !tr.getMeta("preventDispatch") && !this.hasCustomState) view.dispatch(tr);
43717
+ return callbacks.every((callback) => callback === true);
43718
+ };
43719
+ const chain = {
43720
+ ...Object.fromEntries(Object.entries(rawCommands).map(([name, command]) => {
43721
+ const chainedCommand = (...args) => {
43722
+ const props = this.buildProps(tr, shouldDispatch);
43723
+ const callback = command(...args)(props);
43724
+ callbacks.push(callback);
43725
+ return chain;
43726
+ };
43727
+ return [name, chainedCommand];
43728
+ })),
43729
+ run
43730
+ };
43731
+ return chain;
43732
+ }
43733
+ /**
43734
+ * Creates a chain that safely returns `false` when run.
43735
+ * @returns A non-dispatching command chain.
43736
+ * @example
43737
+ * const chain = CommandManager.createFakeChain()
43738
+ * chain.focus().run() // false
43739
+ */
43740
+ static createFakeChain() {
43741
+ const chain = new Proxy({}, { get: (_target, property) => {
43742
+ if (property === "then") return;
43743
+ if (property === "run") return () => false;
43744
+ return () => chain;
43745
+ } });
43746
+ return chain;
43747
+ }
43748
+ createCan(startTr) {
43749
+ const { rawCommands, state } = this;
43750
+ const dispatch = false;
43751
+ const tr = startTr || state.tr;
43752
+ const props = this.buildProps(tr, dispatch);
43753
+ return {
43754
+ ...Object.fromEntries(Object.entries(rawCommands).map(([name, command]) => {
43755
+ return [name, (...args) => command(...args)({
43756
+ ...props,
43757
+ dispatch: void 0
43758
+ })];
43759
+ })),
43760
+ chain: () => this.createChain(tr, dispatch)
43761
+ };
43762
+ }
43763
+ /**
43764
+ * Creates capability checks that safely return `false`.
43765
+ * @returns A non-dispatching capability checker.
43766
+ * @example
43767
+ * const can = CommandManager.createFallbackCan()
43768
+ * can.focus() // false
43769
+ */
43770
+ static createFallbackCan() {
43771
+ const chain = CommandManager.createFakeChain();
43772
+ return new Proxy({ chain: () => chain }, { get: (target, property) => {
43773
+ if (property === "then") return;
43774
+ if (property === "chain") return target.chain;
43775
+ return () => false;
43776
+ } });
43777
+ }
43778
+ buildProps(tr, shouldDispatch = true) {
43779
+ const { rawCommands, editor, state } = this;
43780
+ const { view } = editor;
43781
+ const props = {
43782
+ tr,
43783
+ editor,
43784
+ view,
43785
+ state: createChainableState({
43786
+ state,
43787
+ transaction: tr
43788
+ }),
43789
+ dispatch: shouldDispatch ? () => void 0 : void 0,
43790
+ chain: () => this.createChain(tr, shouldDispatch),
43791
+ can: () => this.createCan(tr),
43792
+ get commands() {
43793
+ return Object.fromEntries(Object.entries(rawCommands).map(([name, command]) => {
43794
+ return [name, (...args) => command(...args)(props)];
43795
+ }));
43796
+ }
43797
+ };
43798
+ return props;
43799
+ }
43800
+ };
43801
+ //#endregion
43802
+ //#region src/commands/blur.ts
43803
+ const blur = () => ({ editor, view }) => {
43804
+ requestAnimationFrame(() => {
43805
+ if (!editor.isDestroyed) {
43806
+ var _window;
43807
+ view.dom.blur();
43808
+ (_window = window) === null || _window === void 0 || (_window = _window.getSelection()) === null || _window === void 0 || _window.removeAllRanges();
43809
+ }
43810
+ });
43811
+ return true;
43812
+ };
43813
+ //#endregion
43814
+ //#region src/commands/clearContent.ts
43815
+ const clearContent = (emitUpdate = true) => ({ commands }) => {
43816
+ return commands.setContent("", { emitUpdate });
43817
+ };
43818
+ //#endregion
43819
+ //#region src/commands/clearNodes.ts
43820
+ const clearNodes = () => ({ state, tr, dispatch }) => {
43821
+ const { selection } = tr;
43822
+ const { ranges } = selection;
43823
+ if (!dispatch) return true;
43824
+ ranges.forEach(({ $from, $to }) => {
43825
+ state.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
43826
+ if (node.type.isText) return;
43827
+ const { doc, mapping } = tr;
43828
+ const $mappedFrom = doc.resolve(mapping.map(pos));
43829
+ const $mappedTo = doc.resolve(mapping.map(pos + node.nodeSize));
43830
+ const nodeRange = $mappedFrom.blockRange($mappedTo);
43831
+ if (!nodeRange) return;
43832
+ const targetLiftDepth = liftTarget(nodeRange);
43833
+ if (node.type.isTextblock) {
43834
+ const { defaultType } = $mappedFrom.parent.contentMatchAt($mappedFrom.index());
43835
+ tr.setNodeMarkup(nodeRange.start, defaultType);
43836
+ }
43837
+ if (targetLiftDepth || targetLiftDepth === 0) tr.lift(nodeRange, targetLiftDepth);
43838
+ });
43839
+ });
43840
+ return true;
43841
+ };
43842
+ //#endregion
43843
+ //#region src/commands/command.ts
43844
+ const command = (fn) => (props) => {
43845
+ return fn(props);
43846
+ };
43847
+ //#endregion
43848
+ //#region src/commands/createParagraphNear.ts
43849
+ const createParagraphNear$1 = () => ({ state, dispatch }) => {
43850
+ return createParagraphNear(state, dispatch);
43851
+ };
43852
+ //#endregion
43853
+ //#region src/commands/cut.ts
43854
+ const cut = (originRange, targetPos) => ({ editor, tr }) => {
43855
+ const { state } = editor;
43856
+ const contentSlice = state.doc.slice(originRange.from, originRange.to);
43857
+ tr.deleteRange(originRange.from, originRange.to);
43858
+ const newPos = tr.mapping.map(targetPos);
43859
+ tr.insert(newPos, contentSlice.content);
43860
+ tr.setSelection(new TextSelection(tr.doc.resolve(Math.max(newPos - 1, 0))));
43861
+ return true;
43862
+ };
43863
+ //#endregion
43864
+ //#region src/commands/deleteCurrentNode.ts
43865
+ const deleteCurrentNode = () => ({ tr, dispatch }) => {
43866
+ const { selection } = tr;
43867
+ const currentNode = selection.$anchor.node();
43868
+ if (currentNode.content.size > 0) return false;
43869
+ const $pos = tr.selection.$anchor;
43870
+ for (let depth = $pos.depth; depth > 0; depth -= 1) if ($pos.node(depth).type === currentNode.type) {
43871
+ if (dispatch) {
43872
+ const from = $pos.before(depth);
43873
+ const to = $pos.after(depth);
43874
+ tr.delete(from, to).scrollIntoView();
43875
+ }
43876
+ return true;
43877
+ }
43878
+ return false;
43879
+ };
43880
+ //#endregion
43881
+ //#region src/helpers/getNodeType.ts
43882
+ function getNodeType(nameOrType, schema) {
43883
+ if (typeof nameOrType === "string") {
43884
+ if (!schema.nodes[nameOrType]) throw Error(`There is no node type named '${nameOrType}'. Maybe you forgot to add the extension?`);
43885
+ return schema.nodes[nameOrType];
43886
+ }
43887
+ return nameOrType;
43888
+ }
43889
+ //#endregion
43890
+ //#region src/commands/deleteNode.ts
43891
+ const deleteNode = (typeOrName) => ({ tr, state, dispatch }) => {
43892
+ const type = getNodeType(typeOrName, state.schema);
43893
+ const $pos = tr.selection.$anchor;
43894
+ for (let depth = $pos.depth; depth > 0; depth -= 1) if ($pos.node(depth).type === type) {
43895
+ if (dispatch) {
43896
+ const from = $pos.before(depth);
43897
+ const to = $pos.after(depth);
43898
+ tr.delete(from, to).scrollIntoView();
43899
+ }
43900
+ return true;
43901
+ }
43902
+ return false;
43903
+ };
43904
+ //#endregion
43905
+ //#region src/commands/deleteRange.ts
43906
+ const deleteRange = (range) => ({ tr, dispatch }) => {
43907
+ const { from, to } = range;
43908
+ if (dispatch) tr.delete(from, to);
43909
+ return true;
43910
+ };
43911
+ //#endregion
43912
+ //#region src/commands/deleteSelection.ts
43913
+ /**
43914
+ * Check if a node has text content based on its content specification.
43915
+ * Returns true if the node's content spec matches text* or text+ patterns.
43916
+ */
43917
+ const hasTextContent = (nodeSpec) => {
43918
+ if (!nodeSpec.content) return false;
43919
+ return /^text(\*|\+)/.test(nodeSpec.content);
43920
+ };
43921
+ /**
43922
+ * Expand selection position for a specific side (left or right) to handle inline text nodes.
43923
+ * This function checks if the position is within an inline node with text content and
43924
+ * expands it to include the entire node boundaries for proper deletion.
43925
+ * @param $pos - The resolved position to expand
43926
+ * @param schema - The ProseMirror schema
43927
+ * @param side - Which side to expand ('left' or 'right')
43928
+ * @returns The expanded position for deletion
43929
+ */
43930
+ const expandSelectionForSide = ($pos, schema, side) => {
43931
+ if (!$pos.parent.isInline) return $pos.pos;
43932
+ if (side === "left" && $pos.pos > $pos.start() || side === "right" && $pos.pos < $pos.end()) return $pos.pos;
43933
+ const parentContent = schema.nodes[$pos.parent.type.name].spec;
43934
+ if (!hasTextContent(parentContent)) return $pos.pos;
43935
+ return side === "left" ? $pos.start() - 1 : $pos.end() + 1;
43936
+ };
43937
+ /**
43938
+ * Expand selection range to properly handle deletion of inline text nodes.
43939
+ * Inline text nodes don't collapse correctly when text inside is deleted,
43940
+ * so we need to expand the selection to include the entire node.
43941
+ * See: https://code.haverbeke.berlin/prosemirror/prosemirror/issues/1365
43942
+ */
43943
+ const expandSelectionForInlineText = ($from, $to, schema) => {
43944
+ return {
43945
+ from: expandSelectionForSide($from, schema, "left"),
43946
+ to: expandSelectionForSide($to, schema, "right")
43947
+ };
43948
+ };
43949
+ const deleteSelection = () => ({ state, dispatch }) => {
43950
+ if (state.selection.empty) return false;
43951
+ if (dispatch) {
43952
+ const tr = state.tr;
43953
+ const { ranges } = state.selection;
43954
+ const mapFrom = tr.steps.length;
43955
+ ranges.forEach((range) => {
43956
+ const mapping = tr.mapping.slice(mapFrom);
43957
+ const $from = tr.doc.resolve(mapping.map(range.$from.pos));
43958
+ const $to = tr.doc.resolve(mapping.map(range.$to.pos));
43959
+ const { from, to } = expandSelectionForInlineText($from, $to, state.schema);
43960
+ tr.deleteRange(from, to);
43961
+ });
43962
+ if (!tr.selection.empty) tr.setSelection(TextSelection.near(tr.doc.resolve(tr.selection.from)));
43963
+ tr.scrollIntoView();
43964
+ dispatch(tr);
43965
+ }
43966
+ return true;
43967
+ };
43968
+ //#endregion
43203
43969
  //#region src/commands/enter.ts
43204
43970
  const enter = () => ({ commands }) => {
43205
43971
  return commands.keyboardShortcut("Enter");
@@ -43672,11 +44438,21 @@ so this becomes the fallback color for the slot */ ''}
43672
44438
  return joinForward(state, dispatch);
43673
44439
  };
43674
44440
  //#endregion
44441
+ //#region src/commands/canJoinItemsAt.ts
44442
+ const canJoinItemsAt = (doc, pos) => {
44443
+ const $pos = doc.resolve(pos);
44444
+ const before = $pos.nodeBefore;
44445
+ const after = $pos.nodeAfter;
44446
+ if (!before || !after) return false;
44447
+ return !before.type.spec.isolating && !after.type.spec.isolating;
44448
+ };
44449
+ //#endregion
43675
44450
  //#region src/commands/joinItemBackward.ts
43676
44451
  const joinItemBackward = () => ({ state, dispatch, tr }) => {
43677
44452
  try {
43678
44453
  const point = joinPoint(state.doc, state.selection.$from.pos, -1);
43679
44454
  if (point === null || point === void 0) return false;
44455
+ if (!canJoinItemsAt(state.doc, point)) return false;
43680
44456
  tr.join(point, 2);
43681
44457
  if (dispatch) dispatch(tr);
43682
44458
  return true;
@@ -43690,6 +44466,7 @@ so this becomes the fallback color for the slot */ ''}
43690
44466
  try {
43691
44467
  const point = joinPoint(state.doc, state.selection.$from.pos, 1);
43692
44468
  if (point === null || point === void 0) return false;
44469
+ if (!canJoinItemsAt(state.doc, point)) return false;
43693
44470
  tr.join(point, 2);
43694
44471
  if (dispatch) dispatch(tr);
43695
44472
  return true;
@@ -45096,8 +45873,14 @@ so this becomes the fallback color for the slot */ ''}
45096
45873
  type: deflt,
45097
45874
  attrs: newAttributes
45098
45875
  }] : void 0;
45099
- let can = canSplit(tr.doc, tr.mapping.map($from.pos), 1, types);
45100
- if (!types && !can && canSplit(tr.doc, tr.mapping.map($from.pos), 1, deflt ? [{ type: deflt }] : void 0)) {
45876
+ const deletedTr = selection instanceof TextSelection && !selection.empty ? EditorState.create({
45877
+ doc: tr.doc,
45878
+ selection
45879
+ }).tr.deleteSelection() : null;
45880
+ const splitDoc = deletedTr ? deletedTr.doc : tr.doc;
45881
+ const splitPos = deletedTr ? deletedTr.mapping.map($from.pos) : $from.pos;
45882
+ let can = canSplit(splitDoc, splitPos, 1, types);
45883
+ if (!types && !can && canSplit(splitDoc, splitPos, 1, deflt ? [{ type: deflt }] : void 0)) {
45101
45884
  can = true;
45102
45885
  types = deflt ? [{
45103
45886
  type: deflt,
@@ -45106,12 +45889,13 @@ so this becomes the fallback color for the slot */ ''}
45106
45889
  }
45107
45890
  if (dispatch) {
45108
45891
  if (can) {
45892
+ const mapFrom = tr.steps.length;
45109
45893
  if (selection instanceof TextSelection) tr.deleteSelection();
45110
- tr.split(tr.mapping.map($from.pos), 1, types);
45894
+ tr.split(tr.mapping.slice(mapFrom).map($from.pos), 1, types);
45111
45895
  if (deflt && !atEnd && !$from.parentOffset && $from.parent.type !== deflt) {
45112
- const first = tr.mapping.map($from.before());
45896
+ const first = tr.mapping.slice(mapFrom).map($from.before());
45113
45897
  const $first = tr.doc.resolve(first);
45114
- if ($from.node(-1).canReplaceWith($first.index(), $first.index() + 1, deflt)) tr.setNodeMarkup(tr.mapping.map($from.before()), deflt);
45898
+ if ($from.node(-1).canReplaceWith($first.index(), $first.index() + 1, deflt)) tr.setNodeMarkup(tr.mapping.slice(mapFrom).map($from.before()), deflt);
45115
45899
  }
45116
45900
  }
45117
45901
  if (keepMarks) ensureMarks(state, editor.extensionManager.splittableMarks);
@@ -45164,16 +45948,19 @@ so this becomes the fallback color for the slot */ ''}
45164
45948
  ...getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs),
45165
45949
  ...overrideAttrs
45166
45950
  };
45951
+ const splitsAtStartOfItem = $from.parentOffset === 0 && $from.index(-1) === 0;
45952
+ const itemStart = $from.before(-1);
45167
45953
  tr.delete($from.pos, $to.pos);
45954
+ const trailingTypeAttributes = splitsAtStartOfItem ? grandParent.attrs : newTypeAttributes;
45168
45955
  const types = nextType ? [{
45169
45956
  type,
45170
- attrs: newTypeAttributes
45957
+ attrs: trailingTypeAttributes
45171
45958
  }, {
45172
45959
  type: nextType,
45173
45960
  attrs: newNextTypeAttributes
45174
45961
  }] : [{
45175
45962
  type,
45176
- attrs: newTypeAttributes
45963
+ attrs: trailingTypeAttributes
45177
45964
  }];
45178
45965
  if (!canSplit(tr.doc, $from.pos, 2)) return false;
45179
45966
  if (dispatch) {
@@ -45181,6 +45968,7 @@ so this becomes the fallback color for the slot */ ''}
45181
45968
  const { splittableMarks } = editor.extensionManager;
45182
45969
  const marks = storedMarks || selection.$to.parentOffset && selection.$from.marks();
45183
45970
  tr.split($from.pos, 2, types).scrollIntoView();
45971
+ if (splitsAtStartOfItem) tr.setNodeMarkup(itemStart, void 0, newTypeAttributes);
45184
45972
  if (!marks || !dispatch) return true;
45185
45973
  const filteredMarks = marks.filter((mark) => splittableMarks.includes(mark.type.name));
45186
45974
  tr.ensureMarks(filteredMarks);
@@ -46713,55 +47501,106 @@ so this becomes the fallback color for the slot */ ''}
46713
47501
  }
46714
47502
  return result;
46715
47503
  };
47504
+ /**
47505
+ * Prepares the typed text so the rule handler can inspect the resulting document.
47506
+ */
47507
+ function createRuleTransaction(config) {
47508
+ const { editor, from, to, text, insertText } = config;
47509
+ if (!insertText) return {
47510
+ inputTransaction: null,
47511
+ tr: editor.view.state.tr
47512
+ };
47513
+ const inputTransaction = editor.view.state.tr.insertText(text, from, to);
47514
+ return {
47515
+ inputTransaction,
47516
+ tr: EditorState.create({
47517
+ doc: inputTransaction.doc,
47518
+ selection: inputTransaction.selection,
47519
+ storedMarks: inputTransaction.storedMarks
47520
+ }).tr
47521
+ };
47522
+ }
47523
+ /**
47524
+ * Runs a matching rule and dispatches the typed text before its conversion.
47525
+ */
47526
+ function applyRule(config) {
47527
+ const { editor, from, to, text, rule, match, plugin, insertText } = config;
47528
+ const { view } = editor;
47529
+ const { inputTransaction, tr } = createRuleTransaction({
47530
+ editor,
47531
+ from,
47532
+ to,
47533
+ text,
47534
+ insertText
47535
+ });
47536
+ const inputEnd = inputTransaction ? from + text.length : to;
47537
+ const state = createChainableState({
47538
+ state: view.state,
47539
+ transaction: tr
47540
+ });
47541
+ const range = {
47542
+ from: from - (match[0].length - text.length),
47543
+ to: inputEnd
47544
+ };
47545
+ const { commands, chain, can } = new CommandManager({
47546
+ editor,
47547
+ state
47548
+ });
47549
+ if (rule.handler({
47550
+ state,
47551
+ range,
47552
+ match,
47553
+ commands,
47554
+ chain,
47555
+ can
47556
+ }) === null || !tr.steps.length) return false;
47557
+ if (inputTransaction) {
47558
+ view.dispatch(inputTransaction);
47559
+ if (!view.state.doc.eq(inputTransaction.doc)) return true;
47560
+ }
47561
+ closeHistory(tr);
47562
+ tr.setMeta("inputRule", true);
47563
+ if (rule.undoable) tr.setMeta(plugin, {
47564
+ transform: tr,
47565
+ from,
47566
+ to: inputEnd,
47567
+ text
47568
+ });
47569
+ view.dispatch(tr);
47570
+ return true;
47571
+ }
47572
+ /**
47573
+ * Checks that the part of a match already in the document has matching positions.
47574
+ */
47575
+ function matchesDocument($from, match, text) {
47576
+ const matchedDocLength = match[0].length - text.length;
47577
+ if (matchedDocLength <= 0) return true;
47578
+ const matchStartOffset = $from.parentOffset - matchedDocLength;
47579
+ return matchStartOffset >= 0 && $from.parent.textBetween(matchStartOffset, $from.parentOffset) === match[0].slice(0, matchedDocLength);
47580
+ }
46716
47581
  function run$1$1(config) {
46717
47582
  var _ref;
46718
- const { editor, from, to, text, rules, plugin } = config;
47583
+ const { editor, from, to, text, rules, plugin, insertText } = config;
46719
47584
  const { view } = editor;
46720
47585
  if (view.composing) return false;
46721
47586
  const $from = view.state.doc.resolve(from);
46722
47587
  if ($from.parent.type.spec.code || !!((_ref = $from.nodeBefore || $from.nodeAfter) === null || _ref === void 0 ? void 0 : _ref.marks.find((mark) => mark.type.spec.code))) return false;
46723
- let matched = false;
46724
47588
  const textBefore = getTextContentFromNodes($from) + text;
46725
- rules.forEach((rule) => {
46726
- if (matched) return;
47589
+ for (const rule of rules) {
46727
47590
  const match = inputRuleMatcherHandler(textBefore, rule.find);
46728
- if (!match) return;
46729
- const matchedDocLength = match[0].length - text.length;
46730
- if (matchedDocLength > 0) {
46731
- const matchStartOffset = $from.parentOffset - matchedDocLength;
46732
- if (matchStartOffset < 0 || $from.parent.textBetween(matchStartOffset, $from.parentOffset) !== match[0].slice(0, matchedDocLength)) return;
46733
- }
46734
- const tr = view.state.tr;
46735
- const state = createChainableState({
46736
- state: view.state,
46737
- transaction: tr
46738
- });
46739
- const range = {
46740
- from: from - (match[0].length - text.length),
46741
- to
46742
- };
46743
- const { commands, chain, can } = new CommandManager({
47591
+ if (!match || !matchesDocument($from, match, text)) continue;
47592
+ if (applyRule({
46744
47593
  editor,
46745
- state
46746
- });
46747
- if (rule.handler({
46748
- state,
46749
- range,
46750
- match,
46751
- commands,
46752
- chain,
46753
- can
46754
- }) === null || !tr.steps.length) return;
46755
- if (rule.undoable) tr.setMeta(plugin, {
46756
- transform: tr,
46757
47594
  from,
46758
47595
  to,
46759
- text
46760
- });
46761
- view.dispatch(tr);
46762
- matched = true;
46763
- });
46764
- return matched;
47596
+ text,
47597
+ rule,
47598
+ match,
47599
+ plugin,
47600
+ insertText
47601
+ })) return true;
47602
+ }
47603
+ return false;
46765
47604
  }
46766
47605
  /**
46767
47606
  * Create an input rules plugin. When enabled, it will cause text
@@ -46805,7 +47644,8 @@ so this becomes the fallback color for the slot */ ''}
46805
47644
  to,
46806
47645
  text,
46807
47646
  rules,
46808
- plugin
47647
+ plugin,
47648
+ insertText: true
46809
47649
  });
46810
47650
  },
46811
47651
  handleDOMEvents: { compositionend: (view) => {
@@ -47041,6 +47881,9 @@ so this becomes the fallback color for the slot */ ''}
47041
47881
  pasteEvent = typeof ClipboardEvent !== "undefined" ? new ClipboardEvent("paste") : null;
47042
47882
  return tr;
47043
47883
  };
47884
+ editor.on("destroy", () => {
47885
+ if (tiptapDragFromOtherEditor === editor) tiptapDragFromOtherEditor = null;
47886
+ });
47044
47887
  return rules.map((rule) => {
47045
47888
  return new Plugin({
47046
47889
  view(view) {
@@ -47066,6 +47909,7 @@ so this becomes the fallback color for the slot */ ''}
47066
47909
  if (!isDroppedFromProseMirror) {
47067
47910
  const dragFromOtherEditor = tiptapDragFromOtherEditor;
47068
47911
  if (dragFromOtherEditor === null || dragFromOtherEditor === void 0 ? void 0 : dragFromOtherEditor.isEditable) setTimeout(() => {
47912
+ if (dragFromOtherEditor.isDestroyed) return;
47069
47913
  const selection = dragFromOtherEditor.state.selection;
47070
47914
  if (selection) dragFromOtherEditor.commands.deleteRange({
47071
47915
  from: selection.from,
@@ -48235,7 +49079,10 @@ img.ProseMirror-separator {
48235
49079
  ...options
48236
49080
  };
48237
49081
  if (!this.editorView || !this.state || this.isDestroyed) return;
48238
- if (this.options.editorProps) this.view.setProps(this.options.editorProps);
49082
+ if (this.options.editorProps) this.view.setProps({
49083
+ ...this.options.editorProps,
49084
+ attributes: this.getEditorViewAttributes()
49085
+ });
48239
49086
  this.view.updateState(this.state);
48240
49087
  }
48241
49088
  /**
@@ -48391,6 +49238,23 @@ img.ProseMirror-separator {
48391
49238
  return doc;
48392
49239
  }
48393
49240
  /**
49241
+ * Returns the attributes for the editor element.
49242
+ * Merges the default `role="textbox"` with the attributes from `editorProps`,
49243
+ * so the role is kept no matter when the props are applied.
49244
+ */
49245
+ getEditorViewAttributes() {
49246
+ var _this$options$editorP;
49247
+ const attributes = (_this$options$editorP = this.options.editorProps) === null || _this$options$editorP === void 0 ? void 0 : _this$options$editorP.attributes;
49248
+ if (isFunction$3(attributes)) return (state) => ({
49249
+ role: "textbox",
49250
+ ...attributes(state)
49251
+ });
49252
+ return {
49253
+ role: "textbox",
49254
+ ...attributes
49255
+ };
49256
+ }
49257
+ /**
48394
49258
  * Creates a ProseMirror view.
48395
49259
  */
48396
49260
  createView(element) {
@@ -48401,10 +49265,7 @@ img.ProseMirror-separator {
48401
49265
  const transformPastedHTML = this.extensionManager.transformPastedHTML(baseTransformPastedHTML);
48402
49266
  this.editorView = new EditorView(element, {
48403
49267
  ...editorProps,
48404
- attributes: {
48405
- role: "textbox",
48406
- ...editorProps === null || editorProps === void 0 ? void 0 : editorProps.attributes
48407
- },
49268
+ attributes: this.getEditorViewAttributes(),
48408
49269
  dispatchTransaction: dispatch,
48409
49270
  transformPastedHTML,
48410
49271
  state: this.editorState,
@@ -58107,7 +58968,7 @@ img.ProseMirror-separator {
58107
58968
  toDOM() { return ["div", ["hr"]]; }
58108
58969
  },
58109
58970
  heading: {
58110
- attrs: { level: { default: 1 } },
58971
+ attrs: { level: { default: 1, validate: "number" } },
58111
58972
  content: "(text | image)*",
58112
58973
  group: "block",
58113
58974
  defining: true,
@@ -58117,7 +58978,7 @@ img.ProseMirror-separator {
58117
58978
  { tag: "h4", attrs: { level: 4 } },
58118
58979
  { tag: "h5", attrs: { level: 5 } },
58119
58980
  { tag: "h6", attrs: { level: 6 } }],
58120
- toDOM(node) { return ["h" + node.attrs.level, 0]; }
58981
+ toDOM(node) { return ["h" + +node.attrs.level, 0]; }
58121
58982
  },
58122
58983
  code_block: {
58123
58984
  content: "text*",
@@ -61614,8 +62475,27 @@ img.ProseMirror-separator {
61614
62475
  const UNICODE_WHITESPACE_PATTERN = "[\0- \xA0 ᠎ -\u2029  ]";
61615
62476
  const UNICODE_WHITESPACE_REGEX = new RegExp(UNICODE_WHITESPACE_PATTERN);
61616
62477
  const UNICODE_WHITESPACE_REGEX_END = new RegExp(`${UNICODE_WHITESPACE_PATTERN}$`);
62478
+ const UNICODE_WHITESPACE_REGEX_TRAILING = new RegExp(`${UNICODE_WHITESPACE_PATTERN}+$`);
61617
62479
  const UNICODE_WHITESPACE_REGEX_GLOBAL = new RegExp(UNICODE_WHITESPACE_PATTERN, "g");
61618
62480
  //#endregion
62481
+ //#region src/helpers/unlinkTrailingWhitespace.ts
62482
+ function unlinkTrailingWhitespace(tr, range, type) {
62483
+ var _rangeEnd$nodeBefore, _insertedText$match;
62484
+ const rangeEnd = tr.doc.resolve(range.to);
62485
+ if (!((_rangeEnd$nodeBefore = rangeEnd.nodeBefore) === null || _rangeEnd$nodeBefore === void 0 ? void 0 : _rangeEnd$nodeBefore.isText)) return;
62486
+ const trailingWhitespace = (_insertedText$match = tr.doc.textBetween(range.from, range.to, "", "").match(UNICODE_WHITESPACE_REGEX_TRAILING)) === null || _insertedText$match === void 0 ? void 0 : _insertedText$match[0];
62487
+ if (!trailingWhitespace) return;
62488
+ const whitespaceFrom = range.to - trailingWhitespace.length;
62489
+ const linkMarks = getMarksBetween(whitespaceFrom, range.to, tr.doc).filter((item) => item.mark.type === type);
62490
+ if (!linkMarks.length) return;
62491
+ const { nodeAfter } = rangeEnd;
62492
+ if (!!nodeAfter && linkMarks.some((item) => item.mark.isInSet(nodeAfter.marks))) return;
62493
+ const storedMarks = tr.storedMarks;
62494
+ tr.removeMark(whitespaceFrom, range.to, type);
62495
+ tr.setStoredMarks(storedMarks);
62496
+ if (tr.selection.empty && tr.selection.from === range.to) tr.removeStoredMark(type);
62497
+ }
62498
+ //#endregion
61619
62499
  //#region src/helpers/autolink.ts
61620
62500
  /**
61621
62501
  * Check if the provided tokens form a valid link structure, which can either be a single link token
@@ -61656,6 +62536,21 @@ img.ProseMirror-separator {
61656
62536
  if (!docChanges || preventAutolink) return;
61657
62537
  const { tr } = newState;
61658
62538
  const transform = combineTransactionSteps(oldState.doc, [...transactions]);
62539
+ if (!transactions.some(isHistoryTransaction)) {
62540
+ const insertedRanges = [];
62541
+ transform.steps.forEach((step, index) => {
62542
+ if (!(step instanceof ReplaceStep) || !step.slice.size) return;
62543
+ const mapping = transform.mapping.slice(index + 1);
62544
+ const from = mapping.map(step.from, 1);
62545
+ const to = mapping.map(step.from + step.slice.size, -1);
62546
+ if (from < to) insertedRanges.push({
62547
+ from,
62548
+ to
62549
+ });
62550
+ });
62551
+ insertedRanges.sort((left, right) => right.to - left.to);
62552
+ insertedRanges.forEach((range) => unlinkTrailingWhitespace(tr, range, options.type));
62553
+ }
61659
62554
  getChangedRanges(transform).forEach(({ newRange }) => {
61660
62555
  const nodesInChangedRanges = findChildrenInRange(newState.doc, newRange, (node) => node.isTextblock);
61661
62556
  let textBlock;
@@ -63042,6 +63937,54 @@ img.ProseMirror-separator {
63042
63937
  });
63043
63938
  }
63044
63939
  //#endregion
63940
+ //#region src/ordered-list/collectOrderedListItemsFromSource.ts
63941
+ const ORDERED_LIST_SCAN_WINDOW = 64;
63942
+ function takeLines(source, max) {
63943
+ const lines = [];
63944
+ let start = 0;
63945
+ while (lines.length < max) {
63946
+ const lineEnd = source.indexOf("\n", start);
63947
+ if (lineEnd === -1) {
63948
+ lines.push(source.slice(start));
63949
+ return lines;
63950
+ }
63951
+ lines.push(source.slice(start, lineEnd));
63952
+ start = lineEnd + 1;
63953
+ }
63954
+ return lines;
63955
+ }
63956
+ /**
63957
+ * Collect ordered list items from the start of `source`, reading only the lines the list needs.
63958
+ *
63959
+ * @param source Markdown beginning at a block boundary.
63960
+ * @returns The items, how many lines they consumed, and the lines that were read.
63961
+ * @example
63962
+ * collectOrderedListItemsFromSource('1. one\n2. two\n\nAfter')
63963
+ * // → [[item, item], 3, ['1. one', '2. two', '', 'After']]
63964
+ */
63965
+ function collectOrderedListItemsFromSource(source) {
63966
+ const firstLineEnd = source.indexOf("\n");
63967
+ const firstLine = firstLineEnd === -1 ? source : source.slice(0, firstLineEnd);
63968
+ if (!ORDERED_LIST_ITEM_REGEX.test(firstLine)) return [
63969
+ [],
63970
+ 0,
63971
+ []
63972
+ ];
63973
+ let windowSize = ORDERED_LIST_SCAN_WINDOW;
63974
+ let lines = takeLines(source, windowSize);
63975
+ let collected = collectOrderedListItems(lines);
63976
+ while (collected[1] === lines.length && lines.length === windowSize) {
63977
+ windowSize *= 2;
63978
+ lines = takeLines(source, windowSize);
63979
+ collected = collectOrderedListItems(lines);
63980
+ }
63981
+ return [
63982
+ collected[0],
63983
+ collected[1],
63984
+ lines
63985
+ ];
63986
+ }
63987
+ //#endregion
63045
63988
  //#region src/ordered-list/ordered-list.ts
63046
63989
  const ListItemName = "listItem";
63047
63990
  const TextStyleName = "textStyle";
@@ -63160,8 +64103,7 @@ img.ProseMirror-separator {
63160
64103
  start: () => -1,
63161
64104
  tokenize: (src, _tokens, lexer) => {
63162
64105
  var _listItems$, _listItems$2;
63163
- const lines = src.split("\n");
63164
- const [listItems, consumed] = collectOrderedListItems(lines);
64106
+ const [listItems, consumed, lines] = collectOrderedListItemsFromSource(src);
63165
64107
  if (listItems.length === 0) return;
63166
64108
  const items = buildNestedStructure(listItems, listItems[0].indent, lexer);
63167
64109
  if (items.length === 0) return;
@@ -65932,1028 +66874,414 @@ img.ProseMirror-separator {
65932
66874
  //#region src/text.ts
65933
66875
  /**
65934
66876
  * This extension allows you to create text nodes.
65935
- * @see https://www.tiptap.dev/api/nodes/text
65936
- */
65937
- const Text = Node$1.create({
65938
- name: "text",
65939
- group: "inline",
65940
- parseMarkdown: (token) => {
65941
- return {
65942
- type: "text",
65943
- text: token.text || ""
65944
- };
65945
- },
65946
- renderMarkdown: (node) => node.text || ""
65947
- });
65948
- //#endregion
65949
- //#region src/index.ts
65950
- var src_default = Text;
65951
-
65952
- /**
65953
- Create a plugin that, when added to a ProseMirror instance,
65954
- causes a decoration to show up at the drop position when something
65955
- is dragged over the editor.
65956
-
65957
- Nodes may add a `disableDropCursor` property to their spec to
65958
- control the showing of a drop cursor inside them. This may be a
65959
- boolean or a function, which will be called with a view and a
65960
- position, and should return a boolean.
65961
- */
65962
- function dropCursor(options = {}) {
65963
- return new Plugin({
65964
- view(editorView) { return new DropCursorView(editorView, options); }
65965
- });
65966
- }
65967
- class DropCursorView {
65968
- constructor(editorView, options) {
65969
- var _a;
65970
- this.editorView = editorView;
65971
- this.cursorPos = null;
65972
- this.element = null;
65973
- this.timeout = -1;
65974
- this.lastDragEvent = null;
65975
- this.width = (_a = options.width) !== null && _a !== void 0 ? _a : 1;
65976
- this.color = options.color === false ? undefined : (options.color || "black");
65977
- this.class = options.class;
65978
- this.handlers = ["dragover", "dragend", "drop", "dragleave"].map(name => {
65979
- let handler = (e) => { this[name](e); };
65980
- editorView.dom.addEventListener(name, handler);
65981
- return { name, handler };
65982
- });
65983
- }
65984
- destroy() {
65985
- this.handlers.forEach(({ name, handler }) => this.editorView.dom.removeEventListener(name, handler));
65986
- }
65987
- update(editorView, prevState) {
65988
- if (this.cursorPos != null && prevState.doc != editorView.state.doc) {
65989
- // if we currently have an on-going drag event
65990
- // we need to update the cursor position again and update the overlay
65991
- if (this.lastDragEvent) {
65992
- let target = this.computeTarget(this.lastDragEvent);
65993
- if (target == this.cursorPos)
65994
- this.updateOverlay();
65995
- else
65996
- this.setCursor(target);
65997
- }
65998
- else {
65999
- this.updateOverlay();
66000
- }
66001
- }
66002
- }
66003
- setCursor(pos) {
66004
- if (pos == this.cursorPos)
66005
- return;
66006
- this.cursorPos = pos;
66007
- if (pos == null) {
66008
- this.element.parentNode.removeChild(this.element);
66009
- this.element = null;
66010
- }
66011
- else {
66012
- this.updateOverlay();
66013
- }
66014
- }
66015
- updateOverlay() {
66016
- let $pos = this.editorView.state.doc.resolve(this.cursorPos);
66017
- let isBlock = !$pos.parent.inlineContent, rect;
66018
- let editorDOM = this.editorView.dom, editorRect = editorDOM.getBoundingClientRect();
66019
- let scaleX = editorRect.width / editorDOM.offsetWidth, scaleY = editorRect.height / editorDOM.offsetHeight;
66020
- if (isBlock) {
66021
- let before = $pos.nodeBefore, after = $pos.nodeAfter;
66022
- if (before || after) {
66023
- let node = this.editorView.nodeDOM(this.cursorPos - (before ? before.nodeSize : 0));
66024
- if (node) {
66025
- let nodeRect = node.getBoundingClientRect();
66026
- let top = before ? nodeRect.bottom : nodeRect.top;
66027
- if (before && after)
66028
- top = (top + this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top) / 2;
66029
- let halfWidth = (this.width / 2) * scaleY;
66030
- rect = { left: nodeRect.left, right: nodeRect.right, top: top - halfWidth, bottom: top + halfWidth };
66031
- }
66032
- }
66033
- }
66034
- if (!rect) {
66035
- let coords = this.editorView.coordsAtPos(this.cursorPos);
66036
- let halfWidth = (this.width / 2) * scaleX;
66037
- rect = { left: coords.left - halfWidth, right: coords.left + halfWidth, top: coords.top, bottom: coords.bottom };
66038
- }
66039
- let parent = this.editorView.dom.offsetParent;
66040
- if (!this.element) {
66041
- this.element = parent.appendChild(document.createElement("div"));
66042
- if (this.class)
66043
- this.element.className = this.class;
66044
- this.element.style.cssText = "position: absolute; z-index: 50; pointer-events: none;";
66045
- if (this.color) {
66046
- this.element.style.backgroundColor = this.color;
66047
- }
66048
- }
66049
- this.element.classList.toggle("prosemirror-dropcursor-block", isBlock);
66050
- this.element.classList.toggle("prosemirror-dropcursor-inline", !isBlock);
66051
- let parentLeft, parentTop;
66052
- if (!parent || parent == document.body && getComputedStyle(parent).position == "static") {
66053
- parentLeft = -pageXOffset;
66054
- parentTop = -pageYOffset;
66055
- }
66056
- else {
66057
- let rect = parent.getBoundingClientRect();
66058
- let parentScaleX = rect.width / parent.offsetWidth, parentScaleY = rect.height / parent.offsetHeight;
66059
- parentLeft = rect.left - parent.scrollLeft * parentScaleX;
66060
- parentTop = rect.top - parent.scrollTop * parentScaleY;
66061
- }
66062
- this.element.style.left = (rect.left - parentLeft) / scaleX + "px";
66063
- this.element.style.top = (rect.top - parentTop) / scaleY + "px";
66064
- this.element.style.width = (rect.right - rect.left) / scaleX + "px";
66065
- this.element.style.height = (rect.bottom - rect.top) / scaleY + "px";
66066
- }
66067
- scheduleRemoval(timeout) {
66068
- clearTimeout(this.timeout);
66069
- this.timeout = setTimeout(() => this.setCursor(null), timeout);
66070
- }
66071
- computeTarget(event) {
66072
- let pos = this.editorView.posAtCoords({ left: event.clientX, top: event.clientY });
66073
- let node = pos && pos.inside >= 0 && this.editorView.state.doc.nodeAt(pos.inside);
66074
- let disableDropCursor = node && node.type.spec.disableDropCursor;
66075
- let disabled = typeof disableDropCursor == "function"
66076
- ? disableDropCursor(this.editorView, pos, event)
66077
- : disableDropCursor;
66078
- if (!pos || disabled)
66079
- return null;
66080
- let target = pos.pos;
66081
- if (this.editorView.dragging && this.editorView.dragging.slice) {
66082
- let point = dropPoint(this.editorView.state.doc, target, this.editorView.dragging.slice);
66083
- if (point != null)
66084
- target = point;
66085
- }
66086
- return target;
66087
- }
66088
- dragover(event) {
66089
- if (!this.editorView.editable)
66090
- return;
66091
- this.lastDragEvent = event;
66092
- let target = this.computeTarget(event);
66093
- if (target != null) {
66094
- this.setCursor(target);
66095
- this.scheduleRemoval(5000);
66096
- }
66097
- }
66098
- dragend() {
66099
- this.scheduleRemoval(20);
66100
- }
66101
- drop() {
66102
- this.scheduleRemoval(20);
66103
- }
66104
- dragleave(event) {
66105
- if (!this.editorView.dom.contains(event.relatedTarget))
66106
- this.setCursor(null);
66107
- }
66108
- }
66109
-
66110
- /**
66111
- Gap cursor selections are represented using this class. Its
66112
- `$anchor` and `$head` properties both point at the cursor position.
66113
- */
66114
- class GapCursor extends Selection$2 {
66115
- /**
66116
- Create a gap cursor.
66117
- */
66118
- constructor($pos) {
66119
- super($pos, $pos);
66120
- }
66121
- map(doc, mapping) {
66122
- let $pos = doc.resolve(mapping.map(this.head));
66123
- return GapCursor.valid($pos) ? new GapCursor($pos) : Selection$2.near($pos);
66124
- }
66125
- content() { return Slice.empty; }
66126
- eq(other) {
66127
- return other instanceof GapCursor && other.head == this.head;
66128
- }
66129
- toJSON() {
66130
- return { type: "gapcursor", pos: this.head };
66131
- }
66132
- /**
66133
- @internal
66134
- */
66135
- static fromJSON(doc, json) {
66136
- if (typeof json.pos != "number")
66137
- throw new RangeError("Invalid input for GapCursor.fromJSON");
66138
- return new GapCursor(doc.resolve(json.pos));
66139
- }
66140
- /**
66141
- @internal
66142
- */
66143
- getBookmark() { return new GapBookmark(this.anchor); }
66144
- /**
66145
- @internal
66146
- */
66147
- static valid($pos) {
66148
- let parent = $pos.parent;
66149
- if (parent.inlineContent || !closedBefore($pos) || !closedAfter($pos))
66150
- return false;
66151
- let override = parent.type.spec.allowGapCursor;
66152
- if (override != null)
66153
- return override;
66154
- let deflt = parent.contentMatchAt($pos.index()).defaultType;
66155
- return deflt && deflt.isTextblock;
66156
- }
66157
- /**
66158
- @internal
66159
- */
66160
- static findGapCursorFrom($pos, dir, mustMove = false) {
66161
- search: for (;;) {
66162
- if (!mustMove && GapCursor.valid($pos))
66163
- return $pos;
66164
- let pos = $pos.pos, next = null;
66165
- // Scan up from this position
66166
- for (let d = $pos.depth;; d--) {
66167
- let parent = $pos.node(d);
66168
- if (dir > 0 ? $pos.indexAfter(d) < parent.childCount : $pos.index(d) > 0) {
66169
- next = parent.child(dir > 0 ? $pos.indexAfter(d) : $pos.index(d) - 1);
66170
- break;
66171
- }
66172
- else if (d == 0) {
66173
- return null;
66174
- }
66175
- pos += dir;
66176
- let $cur = $pos.doc.resolve(pos);
66177
- if (GapCursor.valid($cur))
66178
- return $cur;
66179
- }
66180
- // And then down into the next node
66181
- for (;;) {
66182
- let inside = dir > 0 ? next.firstChild : next.lastChild;
66183
- if (!inside) {
66184
- if (next.isAtom && !next.isText && !NodeSelection.isSelectable(next)) {
66185
- $pos = $pos.doc.resolve(pos + next.nodeSize * dir);
66186
- mustMove = false;
66187
- continue search;
66188
- }
66189
- break;
66190
- }
66191
- next = inside;
66192
- pos += dir;
66193
- let $cur = $pos.doc.resolve(pos);
66194
- if (GapCursor.valid($cur))
66195
- return $cur;
66196
- }
66197
- return null;
66198
- }
66199
- }
66200
- }
66201
- GapCursor.prototype.visible = false;
66202
- GapCursor.findFrom = GapCursor.findGapCursorFrom;
66203
- Selection$2.jsonID("gapcursor", GapCursor);
66204
- class GapBookmark {
66205
- constructor(pos) {
66206
- this.pos = pos;
66207
- }
66208
- map(mapping) {
66209
- return new GapBookmark(mapping.map(this.pos));
66210
- }
66211
- resolve(doc) {
66212
- let $pos = doc.resolve(this.pos);
66213
- return GapCursor.valid($pos) ? new GapCursor($pos) : Selection$2.near($pos);
66214
- }
66215
- }
66216
- function needsGap(type) {
66217
- return type.isAtom || type.spec.isolating || type.spec.createGapCursor;
66218
- }
66219
- function closedBefore($pos) {
66220
- for (let d = $pos.depth; d >= 0; d--) {
66221
- let index = $pos.index(d), parent = $pos.node(d);
66222
- // At the start of this parent, look at next one
66223
- if (index == 0) {
66224
- if (parent.type.spec.isolating)
66225
- return true;
66226
- continue;
66227
- }
66228
- // See if the node before (or its first ancestor) is closed
66229
- for (let before = parent.child(index - 1);; before = before.lastChild) {
66230
- if ((before.childCount == 0 && !before.inlineContent) || needsGap(before.type))
66231
- return true;
66232
- if (before.inlineContent)
66233
- return false;
66234
- }
66235
- }
66236
- // Hit start of document
66237
- return true;
66238
- }
66239
- function closedAfter($pos) {
66240
- for (let d = $pos.depth; d >= 0; d--) {
66241
- let index = $pos.indexAfter(d), parent = $pos.node(d);
66242
- if (index == parent.childCount) {
66243
- if (parent.type.spec.isolating)
66244
- return true;
66245
- continue;
66246
- }
66247
- for (let after = parent.child(index);; after = after.firstChild) {
66248
- if ((after.childCount == 0 && !after.inlineContent) || needsGap(after.type))
66249
- return true;
66250
- if (after.inlineContent)
66251
- return false;
66252
- }
66253
- }
66254
- return true;
66255
- }
66877
+ * @see https://www.tiptap.dev/api/nodes/text
66878
+ */
66879
+ const Text = Node$1.create({
66880
+ name: "text",
66881
+ group: "inline",
66882
+ parseMarkdown: (token) => {
66883
+ return {
66884
+ type: "text",
66885
+ text: token.text || ""
66886
+ };
66887
+ },
66888
+ renderMarkdown: (node) => node.text || ""
66889
+ });
66890
+ //#endregion
66891
+ //#region src/index.ts
66892
+ var src_default = Text;
66256
66893
 
66257
66894
  /**
66258
- Create a gap cursor plugin. When enabled, this will capture clicks
66259
- near and arrow-key-motion past places that don't have a normally
66260
- selectable position nearby, and create a gap cursor selection for
66261
- them. The cursor is drawn as an element with class
66262
- `ProseMirror-gapcursor`. You can either include
66263
- `style/gapcursor.css` from the package's directory or add your own
66264
- styles to make it visible.
66895
+ Create a plugin that, when added to a ProseMirror instance,
66896
+ causes a decoration to show up at the drop position when something
66897
+ is dragged over the editor.
66898
+
66899
+ Nodes may add a `disableDropCursor` property to their spec to
66900
+ control the showing of a drop cursor inside them. This may be a
66901
+ boolean or a function, which will be called with a view and a
66902
+ position, and should return a boolean.
66265
66903
  */
66266
- function gapCursor() {
66904
+ function dropCursor(options = {}) {
66267
66905
  return new Plugin({
66268
- props: {
66269
- decorations: drawGapCursor,
66270
- createSelectionBetween(_view, $anchor, $head) {
66271
- return $anchor.pos == $head.pos && GapCursor.valid($head) ? new GapCursor($head) : null;
66272
- },
66273
- handleClick,
66274
- handleKeyDown,
66275
- handleDOMEvents: { beforeinput: beforeinput }
66276
- }
66906
+ view(editorView) { return new DropCursorView(editorView, options); }
66277
66907
  });
66278
66908
  }
66279
- const handleKeyDown = keydownHandler({
66280
- "ArrowLeft": arrow("horiz", -1),
66281
- "ArrowRight": arrow("horiz", 1),
66282
- "ArrowUp": arrow("vert", -1),
66283
- "ArrowDown": arrow("vert", 1)
66284
- });
66285
- function arrow(axis, dir) {
66286
- const dirStr = axis == "vert" ? (dir > 0 ? "down" : "up") : (dir > 0 ? "right" : "left");
66287
- return function (state, dispatch, view) {
66288
- let sel = state.selection;
66289
- let $start = dir > 0 ? sel.$to : sel.$from, mustMove = sel.empty;
66290
- if (sel instanceof TextSelection) {
66291
- if (!view.endOfTextblock(dirStr) || $start.depth == 0)
66292
- return false;
66293
- mustMove = false;
66294
- $start = state.doc.resolve(dir > 0 ? $start.after() : $start.before());
66295
- }
66296
- let $found = GapCursor.findGapCursorFrom($start, dir, mustMove);
66297
- if (!$found)
66298
- return false;
66299
- if (dispatch)
66300
- dispatch(state.tr.setSelection(new GapCursor($found)));
66301
- return true;
66302
- };
66303
- }
66304
- function handleClick(view, pos, event) {
66305
- if (!view || !view.editable)
66306
- return false;
66307
- let $pos = view.state.doc.resolve(pos);
66308
- if (!GapCursor.valid($pos))
66309
- return false;
66310
- let clickPos = view.posAtCoords({ left: event.clientX, top: event.clientY });
66311
- if (clickPos && clickPos.inside > -1 && NodeSelection.isSelectable(view.state.doc.nodeAt(clickPos.inside)))
66312
- return false;
66313
- view.dispatch(view.state.tr.setSelection(new GapCursor($pos)));
66314
- return true;
66315
- }
66316
- // This is a hack that, when a composition starts while a gap cursor
66317
- // is active, quickly creates an inline context for the composition to
66318
- // happen in, to avoid it being aborted by the DOM selection being
66319
- // moved into a valid position.
66320
- function beforeinput(view, event) {
66321
- if (event.inputType != "insertCompositionText" || !(view.state.selection instanceof GapCursor))
66322
- return false;
66323
- let { $from } = view.state.selection;
66324
- let insert = $from.parent.contentMatchAt($from.index()).findWrapping(view.state.schema.nodes.text);
66325
- if (!insert)
66326
- return false;
66327
- let frag = Fragment.empty;
66328
- for (let i = insert.length - 1; i >= 0; i--)
66329
- frag = Fragment.from(insert[i].createAndFill(null, frag));
66330
- let tr = view.state.tr.replace($from.pos, $from.pos, new Slice(frag, 0, 0));
66331
- tr.setSelection(TextSelection.near(tr.doc.resolve($from.pos + 1)));
66332
- view.dispatch(tr);
66333
- return false;
66334
- }
66335
- function drawGapCursor(state) {
66336
- if (!(state.selection instanceof GapCursor))
66337
- return null;
66338
- let node = document.createElement("div");
66339
- node.className = "ProseMirror-gapcursor";
66340
- return DecorationSet.create(state.doc, [Decoration.widget(state.selection.head, node, { key: "gapcursor" })]);
66341
- }
66342
-
66343
- var GOOD_LEAF_SIZE = 200;
66344
-
66345
- // :: class<T> A rope sequence is a persistent sequence data structure
66346
- // that supports appending, prepending, and slicing without doing a
66347
- // full copy. It is represented as a mostly-balanced tree.
66348
- var RopeSequence = function RopeSequence () {};
66349
-
66350
- RopeSequence.prototype.append = function append (other) {
66351
- if (!other.length) { return this }
66352
- other = RopeSequence.from(other);
66353
-
66354
- return (!this.length && other) ||
66355
- (other.length < GOOD_LEAF_SIZE && this.leafAppend(other)) ||
66356
- (this.length < GOOD_LEAF_SIZE && other.leafPrepend(this)) ||
66357
- this.appendInner(other)
66358
- };
66359
-
66360
- // :: (union<[T], RopeSequence<T>>) → RopeSequence<T>
66361
- // Prepend an array or other rope to this one, returning a new rope.
66362
- RopeSequence.prototype.prepend = function prepend (other) {
66363
- if (!other.length) { return this }
66364
- return RopeSequence.from(other).append(this)
66365
- };
66366
-
66367
- RopeSequence.prototype.appendInner = function appendInner (other) {
66368
- return new Append(this, other)
66369
- };
66370
-
66371
- // :: (?number, ?number) → RopeSequence<T>
66372
- // Create a rope repesenting a sub-sequence of this rope.
66373
- RopeSequence.prototype.slice = function slice (from, to) {
66374
- if ( from === void 0 ) from = 0;
66375
- if ( to === void 0 ) to = this.length;
66376
-
66377
- if (from >= to) { return RopeSequence.empty }
66378
- return this.sliceInner(Math.max(0, from), Math.min(this.length, to))
66379
- };
66380
-
66381
- // :: (number) → T
66382
- // Retrieve the element at the given position from this rope.
66383
- RopeSequence.prototype.get = function get (i) {
66384
- if (i < 0 || i >= this.length) { return undefined }
66385
- return this.getInner(i)
66386
- };
66387
-
66388
- // :: ((element: T, index: number) → ?bool, ?number, ?number)
66389
- // Call the given function for each element between the given
66390
- // indices. This tends to be more efficient than looping over the
66391
- // indices and calling `get`, because it doesn't have to descend the
66392
- // tree for every element.
66393
- RopeSequence.prototype.forEach = function forEach (f, from, to) {
66394
- if ( from === void 0 ) from = 0;
66395
- if ( to === void 0 ) to = this.length;
66396
-
66397
- if (from <= to)
66398
- { this.forEachInner(f, from, to, 0); }
66399
- else
66400
- { this.forEachInvertedInner(f, from, to, 0); }
66401
- };
66402
-
66403
- // :: ((element: T, index: number) → U, ?number, ?number) → [U]
66404
- // Map the given functions over the elements of the rope, producing
66405
- // a flat array.
66406
- RopeSequence.prototype.map = function map (f, from, to) {
66407
- if ( from === void 0 ) from = 0;
66408
- if ( to === void 0 ) to = this.length;
66409
-
66410
- var result = [];
66411
- this.forEach(function (elt, i) { return result.push(f(elt, i)); }, from, to);
66412
- return result
66413
- };
66414
-
66415
- // :: (?union<[T], RopeSequence<T>>) → RopeSequence<T>
66416
- // Create a rope representing the given array, or return the rope
66417
- // itself if a rope was given.
66418
- RopeSequence.from = function from (values) {
66419
- if (values instanceof RopeSequence) { return values }
66420
- return values && values.length ? new Leaf(values) : RopeSequence.empty
66421
- };
66422
-
66423
- var Leaf = /*@__PURE__*/(function (RopeSequence) {
66424
- function Leaf(values) {
66425
- RopeSequence.call(this);
66426
- this.values = values;
66427
- }
66428
-
66429
- if ( RopeSequence ) Leaf.__proto__ = RopeSequence;
66430
- Leaf.prototype = Object.create( RopeSequence && RopeSequence.prototype );
66431
- Leaf.prototype.constructor = Leaf;
66432
-
66433
- var prototypeAccessors = { length: { configurable: true },depth: { configurable: true } };
66434
-
66435
- Leaf.prototype.flatten = function flatten () {
66436
- return this.values
66437
- };
66438
-
66439
- Leaf.prototype.sliceInner = function sliceInner (from, to) {
66440
- if (from == 0 && to == this.length) { return this }
66441
- return new Leaf(this.values.slice(from, to))
66442
- };
66443
-
66444
- Leaf.prototype.getInner = function getInner (i) {
66445
- return this.values[i]
66446
- };
66447
-
66448
- Leaf.prototype.forEachInner = function forEachInner (f, from, to, start) {
66449
- for (var i = from; i < to; i++)
66450
- { if (f(this.values[i], start + i) === false) { return false } }
66451
- };
66452
-
66453
- Leaf.prototype.forEachInvertedInner = function forEachInvertedInner (f, from, to, start) {
66454
- for (var i = from - 1; i >= to; i--)
66455
- { if (f(this.values[i], start + i) === false) { return false } }
66456
- };
66457
-
66458
- Leaf.prototype.leafAppend = function leafAppend (other) {
66459
- if (this.length + other.length <= GOOD_LEAF_SIZE)
66460
- { return new Leaf(this.values.concat(other.flatten())) }
66461
- };
66462
-
66463
- Leaf.prototype.leafPrepend = function leafPrepend (other) {
66464
- if (this.length + other.length <= GOOD_LEAF_SIZE)
66465
- { return new Leaf(other.flatten().concat(this.values)) }
66466
- };
66467
-
66468
- prototypeAccessors.length.get = function () { return this.values.length };
66469
-
66470
- prototypeAccessors.depth.get = function () { return 0 };
66471
-
66472
- Object.defineProperties( Leaf.prototype, prototypeAccessors );
66473
-
66474
- return Leaf;
66475
- }(RopeSequence));
66476
-
66477
- // :: RopeSequence
66478
- // The empty rope sequence.
66479
- RopeSequence.empty = new Leaf([]);
66480
-
66481
- var Append = /*@__PURE__*/(function (RopeSequence) {
66482
- function Append(left, right) {
66483
- RopeSequence.call(this);
66484
- this.left = left;
66485
- this.right = right;
66486
- this.length = left.length + right.length;
66487
- this.depth = Math.max(left.depth, right.depth) + 1;
66488
- }
66489
-
66490
- if ( RopeSequence ) Append.__proto__ = RopeSequence;
66491
- Append.prototype = Object.create( RopeSequence && RopeSequence.prototype );
66492
- Append.prototype.constructor = Append;
66493
-
66494
- Append.prototype.flatten = function flatten () {
66495
- return this.left.flatten().concat(this.right.flatten())
66496
- };
66497
-
66498
- Append.prototype.getInner = function getInner (i) {
66499
- return i < this.left.length ? this.left.get(i) : this.right.get(i - this.left.length)
66500
- };
66501
-
66502
- Append.prototype.forEachInner = function forEachInner (f, from, to, start) {
66503
- var leftLen = this.left.length;
66504
- if (from < leftLen &&
66505
- this.left.forEachInner(f, from, Math.min(to, leftLen), start) === false)
66506
- { return false }
66507
- if (to > leftLen &&
66508
- this.right.forEachInner(f, Math.max(from - leftLen, 0), Math.min(this.length, to) - leftLen, start + leftLen) === false)
66509
- { return false }
66510
- };
66511
-
66512
- Append.prototype.forEachInvertedInner = function forEachInvertedInner (f, from, to, start) {
66513
- var leftLen = this.left.length;
66514
- if (from > leftLen &&
66515
- this.right.forEachInvertedInner(f, from - leftLen, Math.max(to, leftLen) - leftLen, start + leftLen) === false)
66516
- { return false }
66517
- if (to < leftLen &&
66518
- this.left.forEachInvertedInner(f, Math.min(from, leftLen), to, start) === false)
66519
- { return false }
66520
- };
66521
-
66522
- Append.prototype.sliceInner = function sliceInner (from, to) {
66523
- if (from == 0 && to == this.length) { return this }
66524
- var leftLen = this.left.length;
66525
- if (to <= leftLen) { return this.left.slice(from, to) }
66526
- if (from >= leftLen) { return this.right.slice(from - leftLen, to - leftLen) }
66527
- return this.left.slice(from, leftLen).append(this.right.slice(0, to - leftLen))
66528
- };
66529
-
66530
- Append.prototype.leafAppend = function leafAppend (other) {
66531
- var inner = this.right.leafAppend(other);
66532
- if (inner) { return new Append(this.left, inner) }
66533
- };
66534
-
66535
- Append.prototype.leafPrepend = function leafPrepend (other) {
66536
- var inner = this.left.leafPrepend(other);
66537
- if (inner) { return new Append(inner, this.right) }
66538
- };
66539
-
66540
- Append.prototype.appendInner = function appendInner (other) {
66541
- if (this.left.depth >= Math.max(this.right.depth, other.depth) + 1)
66542
- { return new Append(this.left, new Append(this.right, other)) }
66543
- return new Append(this, other)
66544
- };
66545
-
66546
- return Append;
66547
- }(RopeSequence));
66548
-
66549
- // ProseMirror's history isn't simply a way to roll back to a previous
66550
- // state, because ProseMirror supports applying changes without adding
66551
- // them to the history (for example during collaboration).
66552
- //
66553
- // To this end, each 'Branch' (one for the undo history and one for
66554
- // the redo history) keeps an array of 'Items', which can optionally
66555
- // hold a step (an actual undoable change), and always hold a position
66556
- // map (which is needed to move changes below them to apply to the
66557
- // current document).
66558
- //
66559
- // An item that has both a step and a selection bookmark is the start
66560
- // of an 'event' — a group of changes that will be undone or redone at
66561
- // once. (It stores only the bookmark, since that way we don't have to
66562
- // provide a document until the selection is actually applied, which
66563
- // is useful when compressing.)
66564
- // Used to schedule history compression
66565
- const max_empty_items = 500;
66566
- class Branch {
66567
- constructor(items, eventCount) {
66568
- this.items = items;
66569
- this.eventCount = eventCount;
66570
- }
66571
- // Pop the latest event off the branch's history and apply it
66572
- // to a document transform.
66573
- popEvent(state, preserveItems) {
66574
- if (this.eventCount == 0)
66575
- return null;
66576
- let end = this.items.length;
66577
- for (;; end--) {
66578
- let next = this.items.get(end - 1);
66579
- if (next.selection) {
66580
- --end;
66581
- break;
66582
- }
66583
- }
66584
- let remap, mapFrom;
66585
- if (preserveItems) {
66586
- remap = this.remapping(end, this.items.length);
66587
- mapFrom = remap.maps.length;
66588
- }
66589
- let transform = state.tr;
66590
- let selection, remaining;
66591
- let addAfter = [], addBefore = [];
66592
- this.items.forEach((item, i) => {
66593
- if (!item.step) {
66594
- if (!remap) {
66595
- remap = this.remapping(end, i + 1);
66596
- mapFrom = remap.maps.length;
66597
- }
66598
- mapFrom--;
66599
- addBefore.push(item);
66600
- return;
66601
- }
66602
- if (remap) {
66603
- addBefore.push(new Item(item.map));
66604
- let step = item.step.map(remap.slice(mapFrom)), map;
66605
- if (step && transform.maybeStep(step).doc) {
66606
- map = transform.mapping.maps[transform.mapping.maps.length - 1];
66607
- addAfter.push(new Item(map, undefined, undefined, addAfter.length + addBefore.length));
66608
- }
66609
- mapFrom--;
66610
- if (map)
66611
- remap.appendMap(map, mapFrom);
66612
- }
66613
- else {
66614
- transform.maybeStep(item.step);
66615
- }
66616
- if (item.selection) {
66617
- selection = remap ? item.selection.map(remap.slice(mapFrom)) : item.selection;
66618
- remaining = new Branch(this.items.slice(0, end).append(addBefore.reverse().concat(addAfter)), this.eventCount - 1);
66619
- return false;
66620
- }
66621
- }, this.items.length, 0);
66622
- return { remaining: remaining, transform, selection: selection };
66623
- }
66624
- // Create a new branch with the given transform added.
66625
- addTransform(transform, selection, histOptions, preserveItems) {
66626
- let newItems = [], eventCount = this.eventCount;
66627
- let oldItems = this.items, lastItem = !preserveItems && oldItems.length ? oldItems.get(oldItems.length - 1) : null;
66628
- for (let i = 0; i < transform.steps.length; i++) {
66629
- let step = transform.steps[i].invert(transform.docs[i]);
66630
- let item = new Item(transform.mapping.maps[i], step, selection), merged;
66631
- if (merged = lastItem && lastItem.merge(item)) {
66632
- item = merged;
66633
- if (i)
66634
- newItems.pop();
66635
- else
66636
- oldItems = oldItems.slice(0, oldItems.length - 1);
66637
- }
66638
- newItems.push(item);
66639
- if (selection) {
66640
- eventCount++;
66641
- selection = undefined;
66642
- }
66643
- if (!preserveItems)
66644
- lastItem = item;
66645
- }
66646
- let overflow = eventCount - histOptions.depth;
66647
- if (overflow > DEPTH_OVERFLOW) {
66648
- oldItems = cutOffEvents(oldItems, overflow);
66649
- eventCount -= overflow;
66650
- }
66651
- return new Branch(oldItems.append(newItems), eventCount);
66652
- }
66653
- remapping(from, to) {
66654
- let maps = new Mapping;
66655
- this.items.forEach((item, i) => {
66656
- let mirrorPos = item.mirrorOffset != null && i - item.mirrorOffset >= from
66657
- ? maps.maps.length - item.mirrorOffset : undefined;
66658
- maps.appendMap(item.map, mirrorPos);
66659
- }, from, to);
66660
- return maps;
66661
- }
66662
- addMaps(array) {
66663
- if (this.eventCount == 0)
66664
- return this;
66665
- return new Branch(this.items.append(array.map(map => new Item(map))), this.eventCount);
66666
- }
66667
- // When the collab module receives remote changes, the history has
66668
- // to know about those, so that it can adjust the steps that were
66669
- // rebased on top of the remote changes, and include the position
66670
- // maps for the remote changes in its array of items.
66671
- rebased(rebasedTransform, rebasedCount) {
66672
- if (!this.eventCount)
66673
- return this;
66674
- let rebasedItems = [], start = Math.max(0, this.items.length - rebasedCount);
66675
- let mapping = rebasedTransform.mapping;
66676
- let newUntil = rebasedTransform.steps.length;
66677
- let eventCount = this.eventCount;
66678
- this.items.forEach(item => { if (item.selection)
66679
- eventCount--; }, start);
66680
- let iRebased = rebasedCount;
66681
- this.items.forEach(item => {
66682
- let pos = mapping.getMirror(--iRebased);
66683
- if (pos == null)
66684
- return;
66685
- newUntil = Math.min(newUntil, pos);
66686
- let map = mapping.maps[pos];
66687
- if (item.step) {
66688
- let step = rebasedTransform.steps[pos].invert(rebasedTransform.docs[pos]);
66689
- let selection = item.selection && item.selection.map(mapping.slice(iRebased + 1, pos));
66690
- if (selection)
66691
- eventCount++;
66692
- rebasedItems.push(new Item(map, step, selection));
66693
- }
66694
- else {
66695
- rebasedItems.push(new Item(map));
66696
- }
66697
- }, start);
66698
- let newMaps = [];
66699
- for (let i = rebasedCount; i < newUntil; i++)
66700
- newMaps.push(new Item(mapping.maps[i]));
66701
- let items = this.items.slice(0, start).append(newMaps).append(rebasedItems);
66702
- let branch = new Branch(items, eventCount);
66703
- if (branch.emptyItemCount() > max_empty_items)
66704
- branch = branch.compress(this.items.length - rebasedItems.length);
66705
- return branch;
66909
+ class DropCursorView {
66910
+ constructor(editorView, options) {
66911
+ var _a;
66912
+ this.editorView = editorView;
66913
+ this.cursorPos = null;
66914
+ this.element = null;
66915
+ this.timeout = -1;
66916
+ this.lastDragEvent = null;
66917
+ this.width = (_a = options.width) !== null && _a !== void 0 ? _a : 1;
66918
+ this.color = options.color === false ? undefined : (options.color || "black");
66919
+ this.class = options.class;
66920
+ this.handlers = ["dragover", "dragend", "drop", "dragleave"].map(name => {
66921
+ let handler = (e) => { this[name](e); };
66922
+ editorView.dom.addEventListener(name, handler);
66923
+ return { name, handler };
66924
+ });
66706
66925
  }
66707
- emptyItemCount() {
66708
- let count = 0;
66709
- this.items.forEach(item => { if (!item.step)
66710
- count++; });
66711
- return count;
66926
+ destroy() {
66927
+ this.setCursor(null);
66928
+ this.handlers.forEach(({ name, handler }) => this.editorView.dom.removeEventListener(name, handler));
66712
66929
  }
66713
- // Compressing a branch means rewriting it to push the air (map-only
66714
- // items) out. During collaboration, these naturally accumulate
66715
- // because each remote change adds one. The `upto` argument is used
66716
- // to ensure that only the items below a given level are compressed,
66717
- // because `rebased` relies on a clean, untouched set of items in
66718
- // order to associate old items with rebased steps.
66719
- compress(upto = this.items.length) {
66720
- let remap = this.remapping(0, upto), mapFrom = remap.maps.length;
66721
- let items = [], events = 0;
66722
- this.items.forEach((item, i) => {
66723
- if (i >= upto) {
66724
- items.push(item);
66725
- if (item.selection)
66726
- events++;
66930
+ update(editorView, prevState) {
66931
+ if (this.cursorPos != null && prevState.doc != editorView.state.doc) {
66932
+ // if we currently have an on-going drag event
66933
+ // we need to update the cursor position again and update the overlay
66934
+ if (this.lastDragEvent) {
66935
+ let target = this.computeTarget(this.lastDragEvent);
66936
+ if (target == this.cursorPos)
66937
+ this.updateOverlay();
66938
+ else
66939
+ this.setCursor(target);
66727
66940
  }
66728
- else if (item.step) {
66729
- let step = item.step.map(remap.slice(mapFrom)), map = step && step.getMap();
66730
- mapFrom--;
66731
- if (map)
66732
- remap.appendMap(map, mapFrom);
66733
- if (step) {
66734
- let selection = item.selection && item.selection.map(remap.slice(mapFrom));
66735
- if (selection)
66736
- events++;
66737
- let newItem = new Item(map.invert(), step, selection), merged, last = items.length - 1;
66738
- if (merged = items.length && items[last].merge(newItem))
66739
- items[last] = merged;
66740
- else
66741
- items.push(newItem);
66941
+ else {
66942
+ this.updateOverlay();
66943
+ }
66944
+ }
66945
+ }
66946
+ setCursor(pos) {
66947
+ if (pos == this.cursorPos)
66948
+ return;
66949
+ this.cursorPos = pos;
66950
+ if (pos == null) {
66951
+ this.element.parentNode.removeChild(this.element);
66952
+ this.element = null;
66953
+ }
66954
+ else {
66955
+ this.updateOverlay();
66956
+ }
66957
+ }
66958
+ updateOverlay() {
66959
+ let $pos = this.editorView.state.doc.resolve(this.cursorPos);
66960
+ let isBlock = !$pos.parent.inlineContent, rect;
66961
+ let editorDOM = this.editorView.dom, editorRect = editorDOM.getBoundingClientRect();
66962
+ let scaleX = editorRect.width / editorDOM.offsetWidth, scaleY = editorRect.height / editorDOM.offsetHeight;
66963
+ if (isBlock) {
66964
+ let before = $pos.nodeBefore, after = $pos.nodeAfter;
66965
+ if (before || after) {
66966
+ let node = this.editorView.nodeDOM(this.cursorPos - (before ? before.nodeSize : 0));
66967
+ if (node) {
66968
+ let nodeRect = node.getBoundingClientRect();
66969
+ let top = before ? nodeRect.bottom : nodeRect.top;
66970
+ if (before && after)
66971
+ top = (top + this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top) / 2;
66972
+ let halfWidth = (this.width / 2) * scaleY;
66973
+ rect = { left: nodeRect.left, right: nodeRect.right, top: top - halfWidth, bottom: top + halfWidth };
66742
66974
  }
66743
66975
  }
66744
- else if (item.map) {
66745
- mapFrom--;
66976
+ }
66977
+ if (!rect) {
66978
+ let coords = this.editorView.coordsAtPos(this.cursorPos);
66979
+ let halfWidth = (this.width / 2) * scaleX;
66980
+ rect = { left: coords.left - halfWidth, right: coords.left + halfWidth, top: coords.top, bottom: coords.bottom };
66981
+ }
66982
+ let parent = this.editorView.dom.offsetParent;
66983
+ if (!this.element) {
66984
+ this.element = parent.appendChild(document.createElement("div"));
66985
+ if (this.class)
66986
+ this.element.className = this.class;
66987
+ this.element.style.cssText = "position: absolute; z-index: 50; pointer-events: none;";
66988
+ if (this.color) {
66989
+ this.element.style.backgroundColor = this.color;
66746
66990
  }
66747
- }, this.items.length, 0);
66748
- return new Branch(RopeSequence.from(items.reverse()), events);
66991
+ }
66992
+ this.element.classList.toggle("prosemirror-dropcursor-block", isBlock);
66993
+ this.element.classList.toggle("prosemirror-dropcursor-inline", !isBlock);
66994
+ let parentLeft, parentTop;
66995
+ if (!parent || parent == document.body && getComputedStyle(parent).position == "static") {
66996
+ parentLeft = -pageXOffset;
66997
+ parentTop = -pageYOffset;
66998
+ }
66999
+ else {
67000
+ let rect = parent.getBoundingClientRect();
67001
+ let parentScaleX = rect.width / parent.offsetWidth, parentScaleY = rect.height / parent.offsetHeight;
67002
+ parentLeft = rect.left - parent.scrollLeft * parentScaleX;
67003
+ parentTop = rect.top - parent.scrollTop * parentScaleY;
67004
+ }
67005
+ this.element.style.left = (rect.left - parentLeft) / scaleX + "px";
67006
+ this.element.style.top = (rect.top - parentTop) / scaleY + "px";
67007
+ this.element.style.width = (rect.right - rect.left) / scaleX + "px";
67008
+ this.element.style.height = (rect.bottom - rect.top) / scaleY + "px";
66749
67009
  }
66750
- }
66751
- Branch.empty = new Branch(RopeSequence.empty, 0);
66752
- function cutOffEvents(items, n) {
66753
- let cutPoint;
66754
- items.forEach((item, i) => {
66755
- if (item.selection && (n-- == 0)) {
66756
- cutPoint = i;
66757
- return false;
67010
+ scheduleRemoval(timeout) {
67011
+ clearTimeout(this.timeout);
67012
+ this.timeout = setTimeout(() => this.setCursor(null), timeout);
67013
+ }
67014
+ computeTarget(event) {
67015
+ let pos = this.editorView.posAtCoords({ left: event.clientX, top: event.clientY });
67016
+ let node = pos && pos.inside >= 0 && this.editorView.state.doc.nodeAt(pos.inside);
67017
+ let disableDropCursor = node && node.type.spec.disableDropCursor;
67018
+ let disabled = typeof disableDropCursor == "function"
67019
+ ? disableDropCursor(this.editorView, pos, event)
67020
+ : disableDropCursor;
67021
+ if (!pos || disabled)
67022
+ return null;
67023
+ let target = pos.pos;
67024
+ if (this.editorView.dragging && this.editorView.dragging.slice) {
67025
+ let point = dropPoint(this.editorView.state.doc, target, this.editorView.dragging.slice);
67026
+ if (point != null)
67027
+ target = point;
66758
67028
  }
66759
- });
66760
- return items.slice(cutPoint);
66761
- }
66762
- class Item {
66763
- constructor(
66764
- // The (forward) step map for this item.
66765
- map,
66766
- // The inverted step
66767
- step,
66768
- // If this is non-null, this item is the start of a group, and
66769
- // this selection is the starting selection for the group (the one
66770
- // that was active before the first step was applied)
66771
- selection,
66772
- // If this item is the inverse of a previous mapping on the stack,
66773
- // this points at the inverse's offset
66774
- mirrorOffset) {
66775
- this.map = map;
66776
- this.step = step;
66777
- this.selection = selection;
66778
- this.mirrorOffset = mirrorOffset;
67029
+ return target;
66779
67030
  }
66780
- merge(other) {
66781
- if (this.step && other.step && !other.selection) {
66782
- let step = other.step.merge(this.step);
66783
- if (step)
66784
- return new Item(step.getMap().invert(), step, this.selection);
67031
+ dragover(event) {
67032
+ if (!this.editorView.editable)
67033
+ return;
67034
+ this.lastDragEvent = event;
67035
+ let target = this.computeTarget(event);
67036
+ if (target != null) {
67037
+ this.setCursor(target);
67038
+ this.scheduleRemoval(5000);
66785
67039
  }
66786
67040
  }
66787
- }
66788
- // The value of the state field that tracks undo/redo history for that
66789
- // state. Will be stored in the plugin state when the history plugin
66790
- // is active.
66791
- class HistoryState {
66792
- constructor(done, undone, prevRanges, prevTime, prevComposition) {
66793
- this.done = done;
66794
- this.undone = undone;
66795
- this.prevRanges = prevRanges;
66796
- this.prevTime = prevTime;
66797
- this.prevComposition = prevComposition;
67041
+ dragend() {
67042
+ this.scheduleRemoval(20);
67043
+ }
67044
+ drop() {
67045
+ this.scheduleRemoval(20);
67046
+ }
67047
+ dragleave(event) {
67048
+ if (!this.editorView.dom.contains(event.relatedTarget))
67049
+ this.setCursor(null);
66798
67050
  }
66799
67051
  }
66800
- const DEPTH_OVERFLOW = 20;
66801
- // Record a transformation in undo history.
66802
- function applyTransaction(history, state, tr, options) {
66803
- let historyTr = tr.getMeta(historyKey), rebased;
66804
- if (historyTr)
66805
- return historyTr.historyState;
66806
- if (tr.getMeta(closeHistoryKey))
66807
- history = new HistoryState(history.done, history.undone, null, 0, -1);
66808
- let appended = tr.getMeta("appendedTransaction");
66809
- if (tr.steps.length == 0) {
66810
- return history;
67052
+
67053
+ /**
67054
+ Gap cursor selections are represented using this class. Its
67055
+ `$anchor` and `$head` properties both point at the cursor position.
67056
+ */
67057
+ class GapCursor extends Selection$2 {
67058
+ /**
67059
+ Create a gap cursor.
67060
+ */
67061
+ constructor($pos) {
67062
+ super($pos, $pos);
66811
67063
  }
66812
- else if (appended && appended.getMeta(historyKey)) {
66813
- if (appended.getMeta(historyKey).redo)
66814
- return new HistoryState(history.done.addTransform(tr, undefined, options, mustPreserveItems(state)), history.undone, rangesFor(tr.mapping.maps), history.prevTime, history.prevComposition);
66815
- else
66816
- return new HistoryState(history.done, history.undone.addTransform(tr, undefined, options, mustPreserveItems(state)), null, history.prevTime, history.prevComposition);
67064
+ map(doc, mapping) {
67065
+ let $pos = doc.resolve(mapping.map(this.head));
67066
+ return GapCursor.valid($pos) ? new GapCursor($pos) : Selection$2.near($pos);
66817
67067
  }
66818
- else if (tr.getMeta("addToHistory") !== false && !(appended && appended.getMeta("addToHistory") === false)) {
66819
- // Group transforms that occur in quick succession into one event.
66820
- let composition = tr.getMeta("composition");
66821
- let newGroup = history.prevTime == 0 ||
66822
- (!appended && history.prevComposition != composition &&
66823
- (history.prevTime < (tr.time || 0) - options.newGroupDelay || !isAdjacentTo(tr, history.prevRanges)));
66824
- let prevRanges = appended ? mapRanges(history.prevRanges, tr.mapping) : rangesFor(tr.mapping.maps);
66825
- return new HistoryState(history.done.addTransform(tr, newGroup ? state.selection.getBookmark() : undefined, options, mustPreserveItems(state)), Branch.empty, prevRanges, tr.time, composition == null ? history.prevComposition : composition);
67068
+ content() { return Slice.empty; }
67069
+ eq(other) {
67070
+ return other instanceof GapCursor && other.head == this.head;
66826
67071
  }
66827
- else if (rebased = tr.getMeta("rebased")) {
66828
- // Used by the collab module to tell the history that some of its
66829
- // content has been rebased.
66830
- return new HistoryState(history.done.rebased(tr, rebased), history.undone.rebased(tr, rebased), mapRanges(history.prevRanges, tr.mapping), history.prevTime, history.prevComposition);
67072
+ toJSON() {
67073
+ return { type: "gapcursor", pos: this.head };
66831
67074
  }
66832
- else {
66833
- return new HistoryState(history.done.addMaps(tr.mapping.maps), history.undone.addMaps(tr.mapping.maps), mapRanges(history.prevRanges, tr.mapping), history.prevTime, history.prevComposition);
67075
+ /**
67076
+ @internal
67077
+ */
67078
+ static fromJSON(doc, json) {
67079
+ if (typeof json.pos != "number")
67080
+ throw new RangeError("Invalid input for GapCursor.fromJSON");
67081
+ return new GapCursor(doc.resolve(json.pos));
67082
+ }
67083
+ /**
67084
+ @internal
67085
+ */
67086
+ getBookmark() { return new GapBookmark(this.anchor); }
67087
+ /**
67088
+ @internal
67089
+ */
67090
+ static valid($pos) {
67091
+ let parent = $pos.parent;
67092
+ if (parent.inlineContent || !closedBefore($pos) || !closedAfter($pos))
67093
+ return false;
67094
+ let override = parent.type.spec.allowGapCursor;
67095
+ if (override != null)
67096
+ return override;
67097
+ let deflt = parent.contentMatchAt($pos.index()).defaultType;
67098
+ return deflt && deflt.isTextblock;
67099
+ }
67100
+ /**
67101
+ @internal
67102
+ */
67103
+ static findGapCursorFrom($pos, dir, mustMove = false) {
67104
+ search: for (;;) {
67105
+ if (!mustMove && GapCursor.valid($pos))
67106
+ return $pos;
67107
+ let pos = $pos.pos, next = null;
67108
+ // Scan up from this position
67109
+ for (let d = $pos.depth;; d--) {
67110
+ let parent = $pos.node(d);
67111
+ if (dir > 0 ? $pos.indexAfter(d) < parent.childCount : $pos.index(d) > 0) {
67112
+ next = parent.child(dir > 0 ? $pos.indexAfter(d) : $pos.index(d) - 1);
67113
+ break;
67114
+ }
67115
+ else if (d == 0) {
67116
+ return null;
67117
+ }
67118
+ pos += dir;
67119
+ let $cur = $pos.doc.resolve(pos);
67120
+ if (GapCursor.valid($cur))
67121
+ return $cur;
67122
+ }
67123
+ // And then down into the next node
67124
+ for (;;) {
67125
+ let inside = dir > 0 ? next.firstChild : next.lastChild;
67126
+ if (!inside) {
67127
+ if (next.isAtom && !next.isText && !NodeSelection.isSelectable(next)) {
67128
+ $pos = $pos.doc.resolve(pos + next.nodeSize * dir);
67129
+ mustMove = false;
67130
+ continue search;
67131
+ }
67132
+ break;
67133
+ }
67134
+ next = inside;
67135
+ pos += dir;
67136
+ let $cur = $pos.doc.resolve(pos);
67137
+ if (GapCursor.valid($cur))
67138
+ return $cur;
67139
+ }
67140
+ return null;
67141
+ }
66834
67142
  }
66835
67143
  }
66836
- function isAdjacentTo(transform, prevRanges) {
66837
- if (!prevRanges)
66838
- return false;
66839
- if (!transform.docChanged)
66840
- return true;
66841
- let adjacent = false;
66842
- transform.mapping.maps[0].forEach((start, end) => {
66843
- for (let i = 0; i < prevRanges.length; i += 2)
66844
- if (start <= prevRanges[i + 1] && end >= prevRanges[i])
66845
- adjacent = true;
66846
- });
66847
- return adjacent;
67144
+ GapCursor.prototype.visible = false;
67145
+ GapCursor.findFrom = GapCursor.findGapCursorFrom;
67146
+ Selection$2.jsonID("gapcursor", GapCursor);
67147
+ class GapBookmark {
67148
+ constructor(pos) {
67149
+ this.pos = pos;
67150
+ }
67151
+ map(mapping) {
67152
+ return new GapBookmark(mapping.map(this.pos));
67153
+ }
67154
+ resolve(doc) {
67155
+ let $pos = doc.resolve(this.pos);
67156
+ return GapCursor.valid($pos) ? new GapCursor($pos) : Selection$2.near($pos);
67157
+ }
66848
67158
  }
66849
- function rangesFor(maps) {
66850
- let result = [];
66851
- for (let i = maps.length - 1; i >= 0 && result.length == 0; i--)
66852
- maps[i].forEach((_from, _to, from, to) => result.push(from, to));
66853
- return result;
67159
+ function needsGap(type) {
67160
+ return type.isAtom || type.spec.isolating || type.spec.createGapCursor;
66854
67161
  }
66855
- function mapRanges(ranges, mapping) {
66856
- if (!ranges)
66857
- return null;
66858
- let result = [];
66859
- for (let i = 0; i < ranges.length; i += 2) {
66860
- let from = mapping.map(ranges[i], 1), to = mapping.map(ranges[i + 1], -1);
66861
- if (from <= to)
66862
- result.push(from, to);
67162
+ function closedBefore($pos) {
67163
+ for (let d = $pos.depth; d >= 0; d--) {
67164
+ let index = $pos.index(d), parent = $pos.node(d);
67165
+ // At the start of this parent, look at next one
67166
+ if (index == 0) {
67167
+ if (parent.type.spec.isolating)
67168
+ return true;
67169
+ continue;
67170
+ }
67171
+ // See if the node before (or its first ancestor) is closed
67172
+ for (let before = parent.child(index - 1);; before = before.lastChild) {
67173
+ if ((before.childCount == 0 && !before.inlineContent) || needsGap(before.type))
67174
+ return true;
67175
+ if (before.inlineContent)
67176
+ return false;
67177
+ }
66863
67178
  }
66864
- return result;
66865
- }
66866
- // Apply the latest event from one branch to the document and shift the event
66867
- // onto the other branch.
66868
- function histTransaction(history, state, redo) {
66869
- let preserveItems = mustPreserveItems(state);
66870
- let histOptions = historyKey.get(state).spec.config;
66871
- let pop = (redo ? history.undone : history.done).popEvent(state, preserveItems);
66872
- if (!pop)
66873
- return null;
66874
- let selection = pop.selection.resolve(pop.transform.doc);
66875
- let added = (redo ? history.done : history.undone).addTransform(pop.transform, state.selection.getBookmark(), histOptions, preserveItems);
66876
- let newHist = new HistoryState(redo ? added : pop.remaining, redo ? pop.remaining : added, null, 0, -1);
66877
- return pop.transform.setSelection(selection).setMeta(historyKey, { redo, historyState: newHist });
67179
+ // Hit start of document
67180
+ return true;
66878
67181
  }
66879
- let cachedPreserveItems = false, cachedPreserveItemsPlugins = null;
66880
- // Check whether any plugin in the given state has a
66881
- // `historyPreserveItems` property in its spec, in which case we must
66882
- // preserve steps exactly as they came in, so that they can be
66883
- // rebased.
66884
- function mustPreserveItems(state) {
66885
- let plugins = state.plugins;
66886
- if (cachedPreserveItemsPlugins != plugins) {
66887
- cachedPreserveItems = false;
66888
- cachedPreserveItemsPlugins = plugins;
66889
- for (let i = 0; i < plugins.length; i++)
66890
- if (plugins[i].spec.historyPreserveItems) {
66891
- cachedPreserveItems = true;
66892
- break;
66893
- }
67182
+ function closedAfter($pos) {
67183
+ for (let d = $pos.depth; d >= 0; d--) {
67184
+ let index = $pos.indexAfter(d), parent = $pos.node(d);
67185
+ if (index == parent.childCount) {
67186
+ if (parent.type.spec.isolating)
67187
+ return true;
67188
+ continue;
67189
+ }
67190
+ for (let after = parent.child(index);; after = after.firstChild) {
67191
+ if ((after.childCount == 0 && !after.inlineContent) || needsGap(after.type))
67192
+ return true;
67193
+ if (after.inlineContent)
67194
+ return false;
67195
+ }
66894
67196
  }
66895
- return cachedPreserveItems;
67197
+ return true;
66896
67198
  }
66897
- const historyKey = new PluginKey("history");
66898
- const closeHistoryKey = new PluginKey("closeHistory");
66899
- /**
66900
- Returns a plugin that enables the undo history for an editor. The
66901
- plugin will track undo and redo stacks, which can be used with the
66902
- [`undo`](https://prosemirror.net/docs/ref/#history.undo) and [`redo`](https://prosemirror.net/docs/ref/#history.redo) commands.
66903
67199
 
66904
- You can set an `"addToHistory"` [metadata
66905
- property](https://prosemirror.net/docs/ref/#state.Transaction.setMeta) of `false` on a transaction
66906
- to prevent it from being rolled back by undo.
67200
+ /**
67201
+ Create a gap cursor plugin. When enabled, this will capture clicks
67202
+ near and arrow-key-motion past places that don't have a normally
67203
+ selectable position nearby, and create a gap cursor selection for
67204
+ them. The cursor is drawn as an element with class
67205
+ `ProseMirror-gapcursor`. You can either include
67206
+ `style/gapcursor.css` from the package's directory or add your own
67207
+ styles to make it visible.
66907
67208
  */
66908
- function history(config = {}) {
66909
- config = { depth: config.depth || 100,
66910
- newGroupDelay: config.newGroupDelay || 500 };
67209
+ function gapCursor() {
66911
67210
  return new Plugin({
66912
- key: historyKey,
66913
- state: {
66914
- init() {
66915
- return new HistoryState(Branch.empty, Branch.empty, null, 0, -1);
66916
- },
66917
- apply(tr, hist, state) {
66918
- return applyTransaction(hist, state, tr, config);
66919
- }
66920
- },
66921
- config,
66922
67211
  props: {
66923
- handleDOMEvents: {
66924
- beforeinput(view, e) {
66925
- let inputType = e.inputType;
66926
- let command = inputType == "historyUndo" ? undo : inputType == "historyRedo" ? redo : null;
66927
- if (!command || !view.editable)
66928
- return false;
66929
- e.preventDefault();
66930
- return command(view.state, view.dispatch);
66931
- }
66932
- }
67212
+ decorations: drawGapCursor,
67213
+ createSelectionBetween(_view, $anchor, $head) {
67214
+ return $anchor.pos == $head.pos && GapCursor.valid($head) ? new GapCursor($head) : null;
67215
+ },
67216
+ handleClick,
67217
+ handleKeyDown,
67218
+ handleDOMEvents: { beforeinput: beforeinput }
66933
67219
  }
66934
67220
  });
66935
67221
  }
66936
- function buildCommand(redo, scroll) {
66937
- return (state, dispatch) => {
66938
- let hist = historyKey.getState(state);
66939
- if (!hist || (redo ? hist.undone : hist.done).eventCount == 0)
66940
- return false;
66941
- if (dispatch) {
66942
- let tr = histTransaction(hist, state, redo);
66943
- if (tr)
66944
- dispatch(scroll ? tr.scrollIntoView() : tr);
67222
+ const handleKeyDown = keydownHandler({
67223
+ "ArrowLeft": arrow("horiz", -1),
67224
+ "ArrowRight": arrow("horiz", 1),
67225
+ "ArrowUp": arrow("vert", -1),
67226
+ "ArrowDown": arrow("vert", 1)
67227
+ });
67228
+ function arrow(axis, dir) {
67229
+ const dirStr = axis == "vert" ? (dir > 0 ? "down" : "up") : (dir > 0 ? "right" : "left");
67230
+ return function (state, dispatch, view) {
67231
+ let sel = state.selection;
67232
+ let $start = dir > 0 ? sel.$to : sel.$from, mustMove = sel.empty;
67233
+ if (sel instanceof TextSelection) {
67234
+ if (!view.endOfTextblock(dirStr) || $start.depth == 0)
67235
+ return false;
67236
+ mustMove = false;
67237
+ $start = state.doc.resolve(dir > 0 ? $start.after() : $start.before());
66945
67238
  }
67239
+ let $found = GapCursor.findGapCursorFrom($start, dir, mustMove);
67240
+ if (!$found)
67241
+ return false;
67242
+ if (dispatch)
67243
+ dispatch(state.tr.setSelection(new GapCursor($found)));
66946
67244
  return true;
66947
67245
  };
66948
67246
  }
66949
- /**
66950
- A command function that undoes the last change, if any.
66951
- */
66952
- const undo = buildCommand(false, true);
66953
- /**
66954
- A command function that redoes the last undone change, if any.
66955
- */
66956
- const redo = buildCommand(true, true);
67247
+ function handleClick(view, pos, event) {
67248
+ if (!view || !view.editable)
67249
+ return false;
67250
+ let $pos = view.state.doc.resolve(pos);
67251
+ if (!GapCursor.valid($pos))
67252
+ return false;
67253
+ let clickPos = view.posAtCoords({ left: event.clientX, top: event.clientY });
67254
+ if (clickPos && clickPos.inside > -1 && NodeSelection.isSelectable(view.state.doc.nodeAt(clickPos.inside)))
67255
+ return false;
67256
+ view.dispatch(view.state.tr.setSelection(new GapCursor($pos)));
67257
+ return true;
67258
+ }
67259
+ // This is a hack that, when a composition starts while a gap cursor
67260
+ // is active, quickly creates an inline context for the composition to
67261
+ // happen in, to avoid it being aborted by the DOM selection being
67262
+ // moved into a valid position.
67263
+ function beforeinput(view, event) {
67264
+ if (event.inputType != "insertCompositionText" || !(view.state.selection instanceof GapCursor))
67265
+ return false;
67266
+ let { $from } = view.state.selection;
67267
+ let insert = $from.parent.contentMatchAt($from.index()).findWrapping(view.state.schema.nodes.text);
67268
+ if (!insert)
67269
+ return false;
67270
+ let frag = Fragment.empty;
67271
+ for (let i = insert.length - 1; i >= 0; i--)
67272
+ frag = Fragment.from(insert[i].createAndFill(null, frag));
67273
+ let tr = view.state.tr.replace($from.pos, $from.pos, new Slice(frag, 0, 0));
67274
+ tr.setSelection(TextSelection.near(tr.doc.resolve($from.pos + 1)));
67275
+ view.dispatch(tr);
67276
+ return false;
67277
+ }
67278
+ function drawGapCursor(state) {
67279
+ if (!(state.selection instanceof GapCursor))
67280
+ return null;
67281
+ let node = document.createElement("div");
67282
+ node.className = "ProseMirror-gapcursor";
67283
+ return DecorationSet.create(state.doc, [Decoration.widget(state.selection.head, node, { key: "gapcursor" })]);
67284
+ }
66957
67285
 
66958
67286
  //#region src/character-count/character-count.ts
66959
67287
  /**
@@ -97548,12 +97876,12 @@ focus outline in that case.
97548
97876
  toDOMStream(options) {
97549
97877
  return streamAdapters.toDOMStream((this._closedPromiseResolve || this._error)
97550
97878
  ? this
97551
- : this._values, options);
97879
+ : this._values);
97552
97880
  }
97553
97881
  toNodeStream(options) {
97554
97882
  return streamAdapters.toNodeStream((this._closedPromiseResolve || this._error)
97555
97883
  ? this
97556
- : this._values, options);
97884
+ : this._values);
97557
97885
  }
97558
97886
  throw(_) {
97559
97887
  return __awaiter(this, void 0, void 0, function* () { yield this.abort(_); return ITERATOR_DONE; });
@@ -99944,7 +100272,7 @@ focus outline in that case.
99944
100272
  toNodeStream() {
99945
100273
  return streamAdapters.toNodeStream((this.isSync()
99946
100274
  ? { [Symbol.iterator]: () => this }
99947
- : { [Symbol.asyncIterator]: () => this }), { objectMode: true });
100275
+ : { [Symbol.asyncIterator]: () => this }));
99948
100276
  }
99949
100277
  /** @nocollapse */
99950
100278
  // @ts-ignore