@burger-editor/local 4.0.0-alpha.43 → 4.0.0-alpha.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.js CHANGED
@@ -1133,7 +1133,7 @@ var hasRequiredDayjs_min$1;
1133
1133
  function requireDayjs_min$1 () {
1134
1134
  if (hasRequiredDayjs_min$1) return dayjs_min$3.exports;
1135
1135
  hasRequiredDayjs_min$1 = 1;
1136
- (function (module, exports) {
1136
+ (function (module, exports$1) {
1137
1137
  !function(t,e){module.exports=e();}(dayjs_min$2,(function(){var t=1e3,e=6e4,n=36e5,r="millisecond",i="second",s="minute",u="hour",a="day",o="week",c="month",f="quarter",h="year",d="date",l="Invalid Date",$=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,y=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,M={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(t){var e=["th","st","nd","rd"],n=t%100;return "["+t+(e[(n-20)%10]||e[n]||e[0])+"]"}},m=function(t,e,n){var r=String(t);return !r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},v={s:m,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return (e<=0?"+":"-")+m(r,2,"0")+":"+m(i,2,"0")},m:function t(e,n){if(e.date()<n.date())return -t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),i=e.clone().add(r,c),s=n-i<0,u=e.clone().add(r+(s?-1:1),c);return +(-(r+(n-i)/(s?i-u:u-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return {M:c,y:h,w:o,d:a,D:d,h:u,m:s,s:i,ms:r,Q:f}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},g="en",D={};D[g]=M;var p="$isDayjsObject",S=function(t){return t instanceof _||!(!t||!t[p])},w=function t(e,n,r){var i;if(!e)return g;if("string"==typeof e){var s=e.toLowerCase();D[s]&&(i=s),n&&(D[s]=n,i=s);var u=e.split("-");if(!i&&u.length>1)return t(u[0])}else {var a=e.name;D[a]=e,i=a;}return !r&&i&&(g=i),i||!r&&g},O=function(t,e){if(S(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new _(n)},b=v;b.l=w,b.i=S,b.w=function(t,e){return O(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var _=function(){function M(t){this.$L=w(t.locale,null,true),this.parse(t),this.$x=this.$x||t.x||{},this[p]=true;}var m=M.prototype;return m.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(b.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match($);if(r){var i=r[2]-1||0,s=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)}}return new Date(e)}(t),this.init();},m.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds();},m.$utils=function(){return b},m.isValid=function(){return !(this.$d.toString()===l)},m.isSame=function(t,e){var n=O(t);return this.startOf(e)<=n&&n<=this.endOf(e)},m.isAfter=function(t,e){return O(t)<this.startOf(e)},m.isBefore=function(t,e){return this.endOf(e)<O(t)},m.$g=function(t,e,n){return b.u(t)?this[e]:this.set(n,t)},m.unix=function(){return Math.floor(this.valueOf()/1e3)},m.valueOf=function(){return this.$d.getTime()},m.startOf=function(t,e){var n=this,r=!!b.u(e)||e,f=b.p(t),l=function(t,e){var i=b.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return r?i:i.endOf(a)},$=function(t,e){return b.w(n.toDate()[t].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},y=this.$W,M=this.$M,m=this.$D,v="set"+(this.$u?"UTC":"");switch(f){case h:return r?l(1,0):l(31,11);case c:return r?l(1,M):l(0,M+1);case o:var g=this.$locale().weekStart||0,D=(y<g?y+7:y)-g;return l(r?m-D:m+(6-D),M);case a:case d:return $(v+"Hours",0);case u:return $(v+"Minutes",1);case s:return $(v+"Seconds",2);case i:return $(v+"Milliseconds",3);default:return this.clone()}},m.endOf=function(t){return this.startOf(t,false)},m.$set=function(t,e){var n,o=b.p(t),f="set"+(this.$u?"UTC":""),l=(n={},n[a]=f+"Date",n[d]=f+"Date",n[c]=f+"Month",n[h]=f+"FullYear",n[u]=f+"Hours",n[s]=f+"Minutes",n[i]=f+"Seconds",n[r]=f+"Milliseconds",n)[o],$=o===a?this.$D+(e-this.$W):e;if(o===c||o===h){var y=this.clone().set(d,1);y.$d[l]($),y.init(),this.$d=y.set(d,Math.min(this.$D,y.daysInMonth())).$d;}else l&&this.$d[l]($);return this.init(),this},m.set=function(t,e){return this.clone().$set(t,e)},m.get=function(t){return this[b.p(t)]()},m.add=function(r,f){var d,l=this;r=Number(r);var $=b.p(f),y=function(t){var e=O(l);return b.w(e.date(e.date()+Math.round(t*r)),l)};if($===c)return this.set(c,this.$M+r);if($===h)return this.set(h,this.$y+r);if($===a)return y(1);if($===o)return y(7);var M=(d={},d[s]=e,d[u]=n,d[i]=t,d)[$]||1,m=this.$d.getTime()+r*M;return b.w(m,this)},m.subtract=function(t,e){return this.add(-1*t,e)},m.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||l;var r=t||"YYYY-MM-DDTHH:mm:ssZ",i=b.z(this),s=this.$H,u=this.$m,a=this.$M,o=n.weekdays,c=n.months,f=n.meridiem,h=function(t,n,i,s){return t&&(t[n]||t(e,r))||i[n].slice(0,s)},d=function(t){return b.s(s%12||12,t,"0")},$=f||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace(y,(function(t,r){return r||function(t){switch(t){case "YY":return String(e.$y).slice(-2);case "YYYY":return b.s(e.$y,4,"0");case "M":return a+1;case "MM":return b.s(a+1,2,"0");case "MMM":return h(n.monthsShort,a,c,3);case "MMMM":return h(c,a);case "D":return e.$D;case "DD":return b.s(e.$D,2,"0");case "d":return String(e.$W);case "dd":return h(n.weekdaysMin,e.$W,o,2);case "ddd":return h(n.weekdaysShort,e.$W,o,3);case "dddd":return o[e.$W];case "H":return String(s);case "HH":return b.s(s,2,"0");case "h":return d(1);case "hh":return d(2);case "a":return $(s,u,true);case "A":return $(s,u,false);case "m":return String(u);case "mm":return b.s(u,2,"0");case "s":return String(e.$s);case "ss":return b.s(e.$s,2,"0");case "SSS":return b.s(e.$ms,3,"0");case "Z":return i}return null}(t)||i.replace(":","")}))},m.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},m.diff=function(r,d,l){var $,y=this,M=b.p(d),m=O(r),v=(m.utcOffset()-this.utcOffset())*e,g=this-m,D=function(){return b.m(y,m)};switch(M){case h:$=D()/12;break;case c:$=D();break;case f:$=D()/3;break;case o:$=(g-v)/6048e5;break;case a:$=(g-v)/864e5;break;case u:$=g/n;break;case s:$=g/e;break;case i:$=g/t;break;default:$=g;}return l?$:b.a($)},m.daysInMonth=function(){return this.endOf(c).$D},m.$locale=function(){return D[this.$L]},m.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=w(t,e,true);return r&&(n.$L=r),n},m.clone=function(){return b.w(this.$d,this)},m.toDate=function(){return new Date(this.valueOf())},m.toJSON=function(){return this.isValid()?this.toISOString():null},m.toISOString=function(){return this.$d.toISOString()},m.toString=function(){return this.$d.toUTCString()},M}(),k=_.prototype;return O.prototype=k,[["$ms",r],["$s",i],["$m",s],["$H",u],["$W",a],["$M",c],["$y",h],["$D",d]].forEach((function(t){k[t[1]]=function(e){return this.$g(e,t[0],t[1])};})),O.extend=function(t,e){return t.$i||(t(e,_,O),t.$i=true),O},O.locale=w,O.isDayjs=S,O.unix=function(t){return O(1e3*t)},O.en=D[g],O.Ls=D,O.p={},O}));
1138
1138
  } (dayjs_min$3));
1139
1139
  return dayjs_min$3.exports;
@@ -1291,10 +1291,10 @@ var editor$b = "<div>\n\t<fieldset>\n\t\t<legend>リンク</legend>\n\t\t<label>
1291
1291
 
1292
1292
  var style$b = "/* No Styling */\n";
1293
1293
 
1294
- var template$b = "<a href=\"\" data-kind=\"link\" data-before-icon=\"none\" data-after-icon=\"none\" data-bge=\"link:href, target:target, kind:data-kind, before-icon:data-before-icon, after-icon:data-after-icon\">\n\t<div>\n\t\t<span data-bge=\"text\">ボタン</span>\n\t\t<span data-bge=\"subtext\">サブテキスト</span>\n\t</div>\n</a>\n";
1294
+ var template$b = "<a href=\"\" data-kind=\"primary\" data-before-icon=\"none\" data-after-icon=\"none\" data-bge=\"link:href, target:target, kind:data-kind, before-icon:data-before-icon, after-icon:data-after-icon\">\n\t<div>\n\t\t<span data-bge=\"text\">ボタン</span>\n\t\t<span data-bge=\"subtext\">サブテキスト</span>\n\t</div>\n</a>\n";
1295
1295
 
1296
1296
  var button = createItem$1({
1297
- version: "4.0.0-alpha.42",
1297
+ version: "4.0.0-alpha.44",
1298
1298
  name: "button",
1299
1299
  template: template$b,
1300
1300
  style: style$b,
@@ -1350,7 +1350,7 @@ var style$a = "/* No Styling */\n";
1350
1350
  var template$a = "<details data-bge=\"open:open\">\n\t<summary data-bge=\"summary\">折りたたみコンテンツ</summary>\n\t<div data-bge=\"content\"><p>内容を入力してください</p></div>\n</details>\n";
1351
1351
 
1352
1352
  var details = createItem$1({
1353
- version: "4.0.0-alpha.42",
1353
+ version: "4.0.0-alpha.44",
1354
1354
  name: "details",
1355
1355
  template: template$a,
1356
1356
  style: style$a,
@@ -1364,7 +1364,7 @@ var style$9 = "[data-bgi='download-file'] {\n\t[data-bge*='size'] {\n\t\t&::befo
1364
1364
  var template$9 = "<a href=\"./files/bgeditor/bg-sample.pdf\" target=\"_blank\" data-bge=\"path:href, download:download\">\n\t<div>\n\t\t<span data-bge=\"name\">サンプルダウンロードファイル</span>\n\t\t<span data-bge=\"formated-size, size:data-size\" data-size=\"138158\">134.92kB</span>\n\t</div>\n</a>\n";
1365
1365
 
1366
1366
  var downloadFile = createItem$1({
1367
- version: "4.0.0-alpha.42",
1367
+ version: "4.0.0-alpha.44",
1368
1368
  name: "download-file",
1369
1369
  template: template$9,
1370
1370
  style: style$9,
@@ -1403,7 +1403,7 @@ var style$8 = "[data-bgi='google-maps'] {\n\tdiv {\n\t\tinline-size: 100%;\n\t\t
1403
1403
  var template$8 = "<div data-lat=\"35.681382\" data-lng=\"139.766084\" data-zoom=\"16\" data-bge=\"lat:data-lat, lng:data-lng, zoom:data-zoom\">\n\t<img data-bge=\"img:src\" src=\"https://maps.google.com/maps/api/staticmap?center=35.681382,139.766084&amp;zoom=16&amp;size=640x400&amp;markers=color:red|color:red|35.681382,139.766084&amp;scale=2&amp;key=%googleMapsApiKey%\" width=\"8\" height=\"5\" alt=\"Google Maps\" />\n</div>\n<a href=\"https://maps.apple.com/?q=35.681382,139.766084\" data-bge=\"url:href\" target=\"_blank\"><span>アプリで開く</span></a>\n";
1404
1404
 
1405
1405
  var googleMaps = createItem$1({
1406
- version: "4.0.0-alpha.42",
1406
+ version: "4.0.0-alpha.44",
1407
1407
  name: "google-maps",
1408
1408
  template: template$8,
1409
1409
  style: style$8,
@@ -1538,7 +1538,7 @@ var style$7 = "[data-bgi='hr'] {\n\t--inline-size: 100%;\n\t--border-color: #000
1538
1538
  var template$7 = "<div data-bgi-hr-kind=\"primary\" data-bge=\"kind:data-bgi-hr-kind\">\n\t<hr />\n</div>\n";
1539
1539
 
1540
1540
  var hr = createItem$1({
1541
- version: "4.0.0-alpha.42",
1541
+ version: "4.0.0-alpha.44",
1542
1542
  name: "hr",
1543
1543
  template: template$7,
1544
1544
  style: style$7,
@@ -1628,7 +1628,7 @@ function createWidthState() {
1628
1628
 
1629
1629
  const ORIGIN = "__org";
1630
1630
  var image = createItem$1({
1631
- version: "4.0.0-alpha.42",
1631
+ version: "4.0.0-alpha.44",
1632
1632
  name: "image",
1633
1633
  template: template$6,
1634
1634
  style: style$6,
@@ -1826,7 +1826,7 @@ var style$5 = "[data-bgi='import'] {\n\tbge-import {\n\t\t&::before {\n\t\t\tfon
1826
1826
  var template$5 = "<bge-import data-bge=\":src\" src=\"\"></bge-import>\n";
1827
1827
 
1828
1828
  var importItem = createItem$1({
1829
- version: "4.0.0-alpha.42",
1829
+ version: "4.0.0-alpha.44",
1830
1830
  name: "import",
1831
1831
  template: template$5,
1832
1832
  style: style$5,
@@ -1840,7 +1840,7 @@ var style$4 = "/* No Styling */\n";
1840
1840
  var template$4 = "<div data-bge=\":scrollable\" data-bge-scrollable=\"false\">\n\t<table>\n\t\t<caption data-bge=\"caption\">\n\t\t\tキャプションを入力してください\n\t\t</caption>\n\t\t<tbody data-bge-list>\n\t\t\t<tr>\n\t\t\t\t<th data-bge=\"th\">表組の見出し</th>\n\t\t\t\t<td data-bge=\"td\">表組の内容を入力してください</td>\n\t\t\t</tr>\n\t\t</tbody>\n\t</table>\n</div>\n";
1841
1841
 
1842
1842
  var table = createItem$1({
1843
- version: "4.0.0-alpha.42",
1843
+ version: "4.0.0-alpha.44",
1844
1844
  name: "table",
1845
1845
  template: template$4,
1846
1846
  style: style$4,
@@ -1868,7 +1868,7 @@ var style$3 = "/* No Styling */\n";
1868
1868
  var template$3 = "<h2 data-bge=\"title-h2\">見出しを入力してください</h2>\n";
1869
1869
 
1870
1870
  var titleH2 = createItem$1({
1871
- version: "4.0.0-alpha.42",
1871
+ version: "4.0.0-alpha.44",
1872
1872
  name: "title-h2",
1873
1873
  template: template$3,
1874
1874
  style: style$3,
@@ -1882,7 +1882,7 @@ var style$2 = "/* No Styling */\n";
1882
1882
  var template$2 = "<h3 data-bge=\"title-h3\">見出しを入力してください</h3>\n";
1883
1883
 
1884
1884
  var titleH3 = createItem$1({
1885
- version: "4.0.0-alpha.42",
1885
+ version: "4.0.0-alpha.44",
1886
1886
  name: "title-h3",
1887
1887
  template: template$2,
1888
1888
  style: style$2,
@@ -1896,7 +1896,7 @@ var style$1 = "/* No Styling */\n";
1896
1896
  var template$1 = "<div data-bge=\"wysiwyg\"><p>本文を入力してください</p></div>\n";
1897
1897
 
1898
1898
  var wysiwyg = createItem$1({
1899
- version: "4.0.0-alpha.42",
1899
+ version: "4.0.0-alpha.44",
1900
1900
  name: "wysiwyg",
1901
1901
  template: template$1,
1902
1902
  style: style$1,
@@ -1911,7 +1911,7 @@ var template = "<div data-id=\"3KtWfp0UopM\" data-title=\"YouTube動画\" data-w
1911
1911
 
1912
1912
  const FALLBACK_TITLE = "YouTube\u52D5\u753B";
1913
1913
  var youtube = createItem$1({
1914
- version: "4.0.0-alpha.42",
1914
+ version: "4.0.0-alpha.44",
1915
1915
  name: "youtube",
1916
1916
  template,
1917
1917
  style: style$c,
@@ -3444,7 +3444,7 @@ var hasRequiredDayjs_min;
3444
3444
  function requireDayjs_min() {
3445
3445
  if (hasRequiredDayjs_min) return dayjs_min$1.exports;
3446
3446
  hasRequiredDayjs_min = 1;
3447
- (function(module, exports) {
3447
+ (function(module, exports$1) {
3448
3448
  !(function(t, e) {
3449
3449
  module.exports = e();
3450
3450
  })(dayjs_min, (function() {
@@ -5404,11 +5404,11 @@ function isBurgerBlockElement(el) {
5404
5404
  "[data-bge-name][data-bge-container]:has(>[data-bge-container-frame]>[data-bge-group]>[data-bge-item])"
5405
5405
  ].join(","));
5406
5406
  }
5407
- function appendStylesheetTo(doc2, url) {
5407
+ function appendStylesheetTo(doc2, url, id) {
5408
5408
  const link2 = doc2.createElement("link");
5409
5409
  link2.rel = "stylesheet";
5410
5410
  link2.crossOrigin = "anonymous";
5411
- link2.href = url;
5411
+ link2.href = `${url}#${id}`;
5412
5412
  doc2.head.append(link2);
5413
5413
  }
5414
5414
  function createStylesheet(cssContents, layer) {
@@ -5460,7 +5460,7 @@ class EditorUI {
5460
5460
  this.#el.dataset.bgeComponent = name;
5461
5461
  if (options?.stylesheet) {
5462
5462
  const url = createStylesheet(options.stylesheet, CSS_LAYER.ui);
5463
- appendStylesheetTo(this.el.ownerDocument, url);
5463
+ appendStylesheetTo(this.el.ownerDocument, url, `${name}-${CSS_LAYER.ui}`);
5464
5464
  }
5465
5465
  }
5466
5466
  hide() {
@@ -5746,12 +5746,52 @@ async function createStylesheetFromUrl(url, layer) {
5746
5746
  const css = layer ? `@layer ${layer} {${cssContents}}` : cssContents;
5747
5747
  const blob = new Blob([css], { type: "text/css" });
5748
5748
  const blobUrl = URL.createObjectURL(blob);
5749
- return blobUrl;
5749
+ return {
5750
+ blob: blobUrl,
5751
+ originalUrl: url
5752
+ };
5753
+ }
5754
+ function comparePriority(a, b2) {
5755
+ if (a.length === 0 && b2.length === 0) {
5756
+ return 0;
5757
+ }
5758
+ if (a.length === 0) {
5759
+ return 1;
5760
+ }
5761
+ if (b2.length === 0) {
5762
+ return -1;
5763
+ }
5764
+ const minLength = Math.min(a.length, b2.length);
5765
+ for (let i = 0; i < minLength - 1; i++) {
5766
+ if (a[i] > b2[i]) {
5767
+ return -1;
5768
+ }
5769
+ if (a[i] < b2[i]) {
5770
+ return 1;
5771
+ }
5772
+ }
5773
+ if (minLength > 0) {
5774
+ const aLast = a[minLength - 1];
5775
+ const bLast = b2[minLength - 1];
5776
+ if (minLength >= 3 && aLast >= 0 && aLast <= 1 && bLast >= 0 && bLast <= 1) {
5777
+ if (a.length !== b2.length) {
5778
+ return 0;
5779
+ }
5780
+ return 0;
5781
+ }
5782
+ if (aLast > bLast) {
5783
+ return -1;
5784
+ }
5785
+ if (aLast < bLast) {
5786
+ return 1;
5787
+ }
5788
+ }
5789
+ return 0;
5750
5790
  }
5751
5791
  function getCustomProperties(scope, containerType) {
5752
5792
  const categories = /* @__PURE__ */ new Map();
5753
5793
  const defaultValues = /* @__PURE__ */ new Map();
5754
- searchCustomProperty(scope, (cssProperty, value) => {
5794
+ searchCustomProperty(scope, (cssProperty, value, layers) => {
5755
5795
  if (!cssProperty.startsWith(BLOCK_OPTION_CSS_CUSTOM_PROPERTY_PREFIX)) {
5756
5796
  return;
5757
5797
  }
@@ -5768,9 +5808,21 @@ function getCustomProperties(scope, containerType) {
5768
5808
  properties: /* @__PURE__ */ new Map()
5769
5809
  };
5770
5810
  if (key) {
5771
- currentMap.properties.set(key, { value, isDefault: false });
5811
+ const newProperty = {
5812
+ value,
5813
+ isDefault: false,
5814
+ priority: layers.map((layer) => layer.priority)
5815
+ };
5816
+ const currentProperty = currentMap.properties.get(key);
5817
+ currentMap.properties.set(key, currentProperty ? compareCustomPropertyByLayerPriority(currentProperty, newProperty) : newProperty);
5772
5818
  } else {
5773
- defaultValues.set(propName, value);
5819
+ const newDefaultValue = {
5820
+ value,
5821
+ isDefault: true,
5822
+ priority: layers.map((layer) => layer.priority)
5823
+ };
5824
+ const currentDefaultValue = defaultValues.get(propName);
5825
+ defaultValues.set(propName, currentDefaultValue ? compareCustomPropertyByLayerPriority(currentDefaultValue, newDefaultValue) : newDefaultValue);
5774
5826
  }
5775
5827
  categories.set(propName, currentMap);
5776
5828
  });
@@ -5781,13 +5833,13 @@ function getCustomProperties(scope, containerType) {
5781
5833
  }
5782
5834
  }
5783
5835
  }
5784
- for (const [category, value] of defaultValues.entries()) {
5836
+ for (const [category, property] of defaultValues.entries()) {
5785
5837
  const currentMap = categories.get(category);
5786
5838
  if (!currentMap) {
5787
5839
  continue;
5788
5840
  }
5789
5841
  for (const [key, customProperty] of currentMap.properties.entries()) {
5790
- if (value === `var(${BLOCK_OPTION_CSS_CUSTOM_PROPERTY_PREFIX}${category}--${key})`) {
5842
+ if (property.value === `var(${BLOCK_OPTION_CSS_CUSTOM_PROPERTY_PREFIX}${category}--${key})`) {
5791
5843
  customProperty.isDefault = true;
5792
5844
  }
5793
5845
  }
@@ -5811,7 +5863,7 @@ function getCustomProperty(scope, property) {
5811
5863
  });
5812
5864
  return result;
5813
5865
  }
5814
- function getStyleRules(rules, scope) {
5866
+ function getStyleRules(rules, layers, scope) {
5815
5867
  const CSSStyleRule = scope.defaultView?.CSSStyleRule;
5816
5868
  if (CSSStyleRule === void 0) {
5817
5869
  throw new Error("CSSStyleRule is not available");
@@ -5820,15 +5872,32 @@ function getStyleRules(rules, scope) {
5820
5872
  if (CSSLayerBlockRule === void 0) {
5821
5873
  throw new Error("CSSLayerBlockRule is not available");
5822
5874
  }
5875
+ const CSSLayerStatementRule = scope.defaultView?.CSSLayerStatementRule;
5876
+ if (CSSLayerStatementRule === void 0) {
5877
+ throw new Error("CSSLayerStatementRule is not available");
5878
+ }
5879
+ const layerPriorities = [...rules].filter((rule) => rule instanceof CSSLayerStatementRule);
5823
5880
  const styleRules = [];
5824
5881
  for (const rule of rules) {
5825
- if (rule instanceof CSSStyleRule && rule.selectorText) {
5826
- styleRules.push(...getStyleRules(rule.cssRules, scope), rule);
5827
- continue;
5882
+ if (rule instanceof CSSStyleRule) {
5883
+ styleRules.push({
5884
+ rule,
5885
+ _cssText: rule.cssText,
5886
+ layers
5887
+ }, ...getStyleRules(rule.cssRules, layers, scope));
5828
5888
  }
5829
5889
  if (rule instanceof CSSLayerBlockRule) {
5830
- styleRules.push(...getStyleRules(rule.cssRules, scope));
5831
- continue;
5890
+ const layerName = rule.name;
5891
+ const foundPriorityLayerList = layerPriorities.find((priority2) => priority2.nameList.includes(layerName));
5892
+ const priority = foundPriorityLayerList?.nameList.toReversed().indexOf(layerName) ?? 0;
5893
+ styleRules.push(...getStyleRules(rule.cssRules, [
5894
+ ...layers,
5895
+ {
5896
+ priorityList: foundPriorityLayerList?.nameList ?? [],
5897
+ layerName,
5898
+ priority: 1 + priority
5899
+ }
5900
+ ], scope));
5832
5901
  }
5833
5902
  }
5834
5903
  return styleRules;
@@ -5836,16 +5905,16 @@ function getStyleRules(rules, scope) {
5836
5905
  function searchCustomProperty(scope, found2) {
5837
5906
  for (const styleSheet of scope.styleSheets) {
5838
5907
  try {
5839
- const styleRules = getStyleRules(styleSheet.cssRules, scope);
5908
+ const styleRules = getStyleRules(styleSheet.cssRules, [], scope);
5840
5909
  for (const cssRule of styleRules) {
5841
- const selector = cssRule.selectorText.trim().replace(/^&/, "").trim();
5910
+ const selector = cssRule.rule.selectorText.trim().replace(/^&/, "").trim();
5842
5911
  if (selector === BLOCK_OPTION_SCOPE_SELECTOR) {
5843
- for (const cssProperty of cssRule.style) {
5912
+ for (const cssProperty of cssRule.rule.style) {
5844
5913
  if (!cssProperty.startsWith("--")) {
5845
5914
  continue;
5846
5915
  }
5847
- const value = cssRule.style.getPropertyValue(cssProperty);
5848
- found2(cssProperty, value);
5916
+ const value = cssRule.rule.style.getPropertyValue(cssProperty);
5917
+ found2(cssProperty, value, cssRule.layers);
5849
5918
  }
5850
5919
  }
5851
5920
  }
@@ -5857,6 +5926,19 @@ function searchCustomProperty(scope, found2) {
5857
5926
  }
5858
5927
  }
5859
5928
  }
5929
+ function compareCustomPropertyByLayerPriority(a, b2) {
5930
+ const result = comparePriority(a.priority, b2.priority);
5931
+ if (result === 0) {
5932
+ return b2;
5933
+ }
5934
+ if (result === -1) {
5935
+ return b2;
5936
+ }
5937
+ if (result === 1) {
5938
+ return a;
5939
+ }
5940
+ return b2;
5941
+ }
5860
5942
  const getCSSPropertyAsNumberCache = /* @__PURE__ */ new Map();
5861
5943
  function getCSSPropertyAsNumber(el, property) {
5862
5944
  const value = window.getComputedStyle(el).getPropertyValue(property);
@@ -6079,8 +6161,8 @@ class EditableArea extends EditorUI {
6079
6161
  }
6080
6162
  this.#frameElement.contentWindow.document.open();
6081
6163
  this.#frameElement.contentWindow.document.close();
6082
- for (const cssPath of stylesheets) {
6083
- appendStylesheetTo(this.#frameElement.contentWindow.document, cssPath);
6164
+ for (const { path, id } of stylesheets) {
6165
+ appendStylesheetTo(this.#frameElement.contentWindow.document, path, id);
6084
6166
  }
6085
6167
  this.#frameElement.contentWindow.document.body.setAttribute("style", "margin: 0; border: 0;");
6086
6168
  this.#containerElement = this.#frameElement.contentWindow.document.createElement("div");
@@ -6834,11 +6916,11 @@ class BurgerEditorEngine {
6834
6916
  }
6835
6917
  async #createItemElement(itemData) {
6836
6918
  if (typeof itemData !== "string" && "localName" in itemData) {
6837
- Item$1.rebind(itemData, this.items, this.itemEditorDialog);
6838
- return itemData;
6919
+ const item2 = Item$1.rebind(itemData, this.items, this.itemEditorDialog);
6920
+ return item2.el;
6839
6921
  }
6840
6922
  const name = typeof itemData === "string" ? itemData : itemData.name;
6841
- const item = await Item$1.create(name, this.items, this.itemEditorDialog);
6923
+ const item = await Item$1.create(name, this.items, this.itemEditorDialog, typeof itemData === "string" ? void 0 : itemData.data);
6842
6924
  return item.el;
6843
6925
  }
6844
6926
  #isUIName(name) {
@@ -6878,7 +6960,20 @@ class BurgerEditorEngine {
6878
6960
  const componentStylesheets = await Promise.all(options.config.stylesheets.map(async (stylesheet) => {
6879
6961
  return createStylesheetFromUrl(stylesheet.path, stylesheet.layer ?? CSS_LAYER.components);
6880
6962
  }));
6881
- const stylesheets = [layers, baseStylesheet, ...componentStylesheets];
6963
+ const stylesheets = [
6964
+ {
6965
+ path: layers,
6966
+ id: "layers"
6967
+ },
6968
+ {
6969
+ path: baseStylesheet,
6970
+ id: "base-stylesheet"
6971
+ },
6972
+ ...componentStylesheets.map(({ blob, originalUrl }) => ({
6973
+ path: blob,
6974
+ id: originalUrl
6975
+ }))
6976
+ ];
6882
6977
  const mainInitialContent = typeof options.initialContents === "string" ? options.initialContents : options.initialContents.main;
6883
6978
  engine.#main = //
6884
6979
  await EditableArea.new("main", mainInitialContent, engine, options.blockMenu, stylesheets, options.config.classList);
@@ -7633,9 +7728,11 @@ function removeRange(content, from2, to) {
7633
7728
  function insertInto(content, dist, insert, parent) {
7634
7729
  let { index: index2, offset } = content.findIndex(dist), child2 = content.maybeChild(index2);
7635
7730
  if (offset == dist || child2.isText) {
7731
+ if (parent && !parent.canReplace(index2, index2, insert))
7732
+ return null;
7636
7733
  return content.cut(0, dist).append(insert).append(content.cut(dist));
7637
7734
  }
7638
- let inner = insertInto(child2.content, dist - offset - 1, insert);
7735
+ let inner = insertInto(child2.content, dist - offset - 1, insert, child2);
7639
7736
  return inner && content.replaceChild(index2, child2.copy(inner));
7640
7737
  }
7641
7738
  function replace($from, $to, slice2) {
@@ -9613,6 +9710,7 @@ class ParseContext {
9613
9710
  addTextNode(dom, marks) {
9614
9711
  let value = dom.nodeValue;
9615
9712
  let top = this.top, preserveWS = top.options & OPT_PRESERVE_WS_FULL ? "full" : this.localPreserveWS || (top.options & OPT_PRESERVE_WS) > 0;
9713
+ let { schema } = this.parser;
9616
9714
  if (preserveWS === "full" || top.inlineContext(dom) || /[^ \t\r\n\u000c]/.test(value)) {
9617
9715
  if (!preserveWS) {
9618
9716
  value = value.replace(/[ \t\r\n\u000c]+/g, " ");
@@ -9622,13 +9720,22 @@ class ParseContext {
9622
9720
  if (!nodeBefore || domNodeBefore && domNodeBefore.nodeName == "BR" || nodeBefore.isText && /[ \t\r\n\u000c]$/.test(nodeBefore.text))
9623
9721
  value = value.slice(1);
9624
9722
  }
9625
- } else if (preserveWS !== "full") {
9626
- value = value.replace(/\r?\n|\r/g, " ");
9627
- } else {
9723
+ } else if (preserveWS === "full") {
9628
9724
  value = value.replace(/\r\n?/g, "\n");
9725
+ } else if (schema.linebreakReplacement && /[\r\n]/.test(value) && this.top.findWrapping(schema.linebreakReplacement.create())) {
9726
+ let lines = value.split(/\r?\n|\r/);
9727
+ for (let i = 0; i < lines.length; i++) {
9728
+ if (i)
9729
+ this.insertNode(schema.linebreakReplacement.create(), marks, true);
9730
+ if (lines[i])
9731
+ this.insertNode(schema.text(lines[i]), marks, !/\S/.test(lines[i]));
9732
+ }
9733
+ value = "";
9734
+ } else {
9735
+ value = value.replace(/\r?\n|\r/g, " ");
9629
9736
  }
9630
9737
  if (value)
9631
- this.insertNode(this.parser.schema.text(value), marks, !/\S/.test(value));
9738
+ this.insertNode(schema.text(value), marks, !/\S/.test(value));
9632
9739
  this.findInText(dom);
9633
9740
  } else {
9634
9741
  this.findInside(dom);
@@ -11027,13 +11134,17 @@ function canCut(node, start, end) {
11027
11134
  function liftTarget(range) {
11028
11135
  let parent = range.parent;
11029
11136
  let content = parent.content.cutByIndex(range.startIndex, range.endIndex);
11030
- for (let depth = range.depth; ; --depth) {
11137
+ for (let depth = range.depth, contentBefore = 0, contentAfter = 0; ; --depth) {
11031
11138
  let node = range.$from.node(depth);
11032
- let index2 = range.$from.index(depth), endIndex = range.$to.indexAfter(depth);
11139
+ let index2 = range.$from.index(depth) + contentBefore, endIndex = range.$to.indexAfter(depth) - contentAfter;
11033
11140
  if (depth < range.depth && node.canReplace(index2, endIndex, content))
11034
11141
  return depth;
11035
11142
  if (depth == 0 || node.type.spec.isolating || !canCut(node, index2, endIndex))
11036
11143
  break;
11144
+ if (index2)
11145
+ contentBefore = 1;
11146
+ if (endIndex < node.childCount)
11147
+ contentAfter = 1;
11037
11148
  }
11038
11149
  return null;
11039
11150
  }
@@ -11576,7 +11687,7 @@ function replaceRange(tr2, from2, to, slice2) {
11576
11687
  let $from = tr2.doc.resolve(from2), $to = tr2.doc.resolve(to);
11577
11688
  if (fitsTrivially($from, $to, slice2))
11578
11689
  return tr2.step(new ReplaceStep(from2, to, slice2));
11579
- let targetDepths = coveredDepths($from, tr2.doc.resolve(to));
11690
+ let targetDepths = coveredDepths($from, $to);
11580
11691
  if (targetDepths[targetDepths.length - 1] == 0)
11581
11692
  targetDepths.pop();
11582
11693
  let preferredTarget = -($from.depth + 1);
@@ -12596,7 +12707,6 @@ class Transaction extends Transform {
12596
12707
  } else {
12597
12708
  if (to == null)
12598
12709
  to = from2;
12599
- to = to == null ? from2 : to;
12600
12710
  if (!text2)
12601
12711
  return this.deleteRange(from2, to);
12602
12712
  let marks = this.storedMarks;
@@ -12605,7 +12715,7 @@ class Transaction extends Transform {
12605
12715
  marks = to == from2 ? $from.marks() : $from.marksAcross(this.doc.resolve(to));
12606
12716
  }
12607
12717
  this.replaceRangeWith(from2, to, schema.text(text2, marks));
12608
- if (!this.selection.empty)
12718
+ if (!this.selection.empty && this.selection.to == from2 + text2.length)
12609
12719
  this.setSelection(Selection.near(this.selection.$to));
12610
12720
  return this;
12611
12721
  }
@@ -12797,7 +12907,7 @@ class EditorState {
12797
12907
  return newInstance;
12798
12908
  }
12799
12909
  /**
12800
- Start a [transaction](https://prosemirror.net/docs/ref/#state.Transaction) from this state.
12910
+ Accessor that constructs and returns a new [transaction](https://prosemirror.net/docs/ref/#state.Transaction) from this state.
12801
12911
  */
12802
12912
  get tr() {
12803
12913
  return new Transaction(this);
@@ -13901,17 +14011,20 @@ function findOffsetInNode(node, coords) {
13901
14011
  }
13902
14012
  function findOffsetInText(node, coords) {
13903
14013
  let len = node.nodeValue.length;
13904
- let range = document.createRange();
14014
+ let range = document.createRange(), result;
13905
14015
  for (let i = 0; i < len; i++) {
13906
14016
  range.setEnd(node, i + 1);
13907
14017
  range.setStart(node, i);
13908
14018
  let rect = singleRect(range, 1);
13909
14019
  if (rect.top == rect.bottom)
13910
14020
  continue;
13911
- if (inRect(coords, rect))
13912
- return { node, offset: i + (coords.left >= (rect.left + rect.right) / 2 ? 1 : 0) };
14021
+ if (inRect(coords, rect)) {
14022
+ result = { node, offset: i + (coords.left >= (rect.left + rect.right) / 2 ? 1 : 0) };
14023
+ break;
14024
+ }
13913
14025
  }
13914
- return { node, offset: 0 };
14026
+ range.detach();
14027
+ return result || { node, offset: 0 };
13915
14028
  }
13916
14029
  function inRect(coords, rect) {
13917
14030
  return coords.left >= rect.left - 1 && coords.left <= rect.right + 1 && coords.top >= rect.top - 1 && coords.top <= rect.bottom + 1;
@@ -14506,7 +14619,7 @@ class ViewDesc {
14506
14619
  if (!(force || brKludge && safari) && isEquivalentPosition(anchorDOM.node, anchorDOM.offset, selRange.anchorNode, selRange.anchorOffset) && isEquivalentPosition(headDOM.node, headDOM.offset, selRange.focusNode, selRange.focusOffset))
14507
14620
  return;
14508
14621
  let domSelExtended = false;
14509
- if ((domSel.extend || anchor == head) && !brKludge) {
14622
+ if ((domSel.extend || anchor == head) && !(brKludge && gecko)) {
14510
14623
  domSel.collapse(anchorDOM.node, anchorDOM.offset);
14511
14624
  try {
14512
14625
  if (anchor != head)
@@ -14886,17 +14999,18 @@ class NodeViewDesc extends ViewDesc {
14886
14999
  }
14887
15000
  // Mark this node as being the selected node.
14888
15001
  selectNode() {
14889
- if (this.nodeDOM.nodeType == 1)
15002
+ if (this.nodeDOM.nodeType == 1) {
14890
15003
  this.nodeDOM.classList.add("ProseMirror-selectednode");
14891
- if (this.contentDOM || !this.node.type.spec.draggable)
14892
- this.dom.draggable = true;
15004
+ if (this.contentDOM || !this.node.type.spec.draggable)
15005
+ this.nodeDOM.draggable = true;
15006
+ }
14893
15007
  }
14894
15008
  // Remove selected node marking from this node.
14895
15009
  deselectNode() {
14896
15010
  if (this.nodeDOM.nodeType == 1) {
14897
15011
  this.nodeDOM.classList.remove("ProseMirror-selectednode");
14898
15012
  if (this.contentDOM || !this.node.type.spec.draggable)
14899
- this.dom.removeAttribute("draggable");
15013
+ this.nodeDOM.removeAttribute("draggable");
14900
15014
  }
14901
15015
  }
14902
15016
  get domAtom() {
@@ -15660,17 +15774,14 @@ function removeClassOnSelectionChange(view) {
15660
15774
  });
15661
15775
  }
15662
15776
  function selectCursorWrapper(view) {
15663
- let domSel = view.domSelection(), range = document.createRange();
15777
+ let domSel = view.domSelection();
15664
15778
  if (!domSel)
15665
15779
  return;
15666
15780
  let node = view.cursorWrapper.dom, img = node.nodeName == "IMG";
15667
15781
  if (img)
15668
- range.setStart(node.parentNode, domIndex(node) + 1);
15782
+ domSel.collapse(node.parentNode, domIndex(node) + 1);
15669
15783
  else
15670
- range.setStart(node, 0);
15671
- range.collapse(true);
15672
- domSel.removeAllRanges();
15673
- domSel.addRange(range);
15784
+ domSel.collapse(node, 0);
15674
15785
  if (!img && !view.state.selection.visible && ie$1 && ie_version <= 11) {
15675
15786
  node.disabled = true;
15676
15787
  node.disabled = false;
@@ -16080,13 +16191,18 @@ function parseFromClipboard(view, text2, html2, plainText, $context) {
16080
16191
  let dom, slice2;
16081
16192
  if (!html2 && !text2)
16082
16193
  return null;
16083
- let asText = text2 && (plainText || inCode || !html2);
16194
+ let asText = !!text2 && (plainText || inCode || !html2);
16084
16195
  if (asText) {
16085
16196
  view.someProp("transformPastedText", (f) => {
16086
16197
  text2 = f(text2, inCode || plainText, view);
16087
16198
  });
16088
- if (inCode)
16089
- return text2 ? new Slice(Fragment.from(view.state.schema.text(text2.replace(/\r\n?/g, "\n"))), 0, 0) : Slice.empty;
16199
+ if (inCode) {
16200
+ slice2 = new Slice(Fragment.from(view.state.schema.text(text2.replace(/\r\n?/g, "\n"))), 0, 0);
16201
+ view.someProp("transformPasted", (f) => {
16202
+ slice2 = f(slice2, view, true);
16203
+ });
16204
+ return slice2;
16205
+ }
16090
16206
  let parsed = view.someProp("clipboardTextParser", (f) => f(text2, $context, plainText, view));
16091
16207
  if (parsed) {
16092
16208
  slice2 = parsed;
@@ -16145,7 +16261,7 @@ function parseFromClipboard(view, text2, html2, plainText, $context) {
16145
16261
  }
16146
16262
  }
16147
16263
  view.someProp("transformPasted", (f) => {
16148
- slice2 = f(slice2, view);
16264
+ slice2 = f(slice2, view, asText);
16149
16265
  });
16150
16266
  return slice2;
16151
16267
  }
@@ -16554,7 +16670,7 @@ class MouseDown {
16554
16670
  }
16555
16671
  const target = flushed ? null : event2.target;
16556
16672
  const targetDesc = target ? view.docView.nearestDesc(target, true) : null;
16557
- this.target = targetDesc && targetDesc.dom.nodeType == 1 ? targetDesc.dom : null;
16673
+ this.target = targetDesc && targetDesc.nodeDOM.nodeType == 1 ? targetDesc.nodeDOM : null;
16558
16674
  let { selection } = view.state;
16559
16675
  if (event2.button == 0 && targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false || selection instanceof NodeSelection && selection.from <= targetPos && selection.to > targetPos)
16560
16676
  this.mightDrag = {
@@ -16655,7 +16771,7 @@ editHandlers.compositionstart = editHandlers.compositionupdate = (view) => {
16655
16771
  if (!view.composing) {
16656
16772
  view.domObserver.flush();
16657
16773
  let { state: state2 } = view, $pos = state2.selection.$to;
16658
- if (state2.selection instanceof TextSelection && (state2.storedMarks || !$pos.textOffset && $pos.parentOffset && $pos.nodeBefore.marks.some((m2) => m2.type.spec.inclusive === false))) {
16774
+ if (state2.selection instanceof TextSelection && (state2.storedMarks || !$pos.textOffset && $pos.parentOffset && $pos.nodeBefore.marks.some((m2) => m2.type.spec.inclusive === false) || chrome && windows$1 && selectionBeforeUneditable(view))) {
16659
16775
  view.markCursor = view.state.storedMarks || $pos.marks();
16660
16776
  endComposition(view, true);
16661
16777
  view.markCursor = null;
@@ -16683,6 +16799,13 @@ editHandlers.compositionstart = editHandlers.compositionupdate = (view) => {
16683
16799
  }
16684
16800
  scheduleComposeEnd(view, timeoutComposition);
16685
16801
  };
16802
+ function selectionBeforeUneditable(view) {
16803
+ let { focusNode, focusOffset } = view.domSelectionRange();
16804
+ if (!focusNode || focusNode.nodeType != 1 || focusOffset >= focusNode.childNodes.length)
16805
+ return false;
16806
+ let next = focusNode.childNodes[focusOffset];
16807
+ return next.nodeType == 1 && next.contentEditable == "false";
16808
+ }
16686
16809
  editHandlers.compositionend = (view, event2) => {
16687
16810
  if (view.composing) {
16688
16811
  view.input.composing = false;
@@ -16886,10 +17009,14 @@ handlers.dragend = (view) => {
16886
17009
  }, 50);
16887
17010
  };
16888
17011
  editHandlers.dragover = editHandlers.dragenter = (_2, e) => e.preventDefault();
16889
- editHandlers.drop = (view, _event) => {
16890
- let event2 = _event;
16891
- let dragging = view.dragging;
16892
- view.dragging = null;
17012
+ editHandlers.drop = (view, event2) => {
17013
+ try {
17014
+ handleDrop(view, event2, view.dragging);
17015
+ } finally {
17016
+ view.dragging = null;
17017
+ }
17018
+ };
17019
+ function handleDrop(view, event2, dragging) {
16893
17020
  if (!event2.dataTransfer)
16894
17021
  return;
16895
17022
  let eventPos = view.posAtCoords(eventCoords(event2));
@@ -16899,7 +17026,7 @@ editHandlers.drop = (view, _event) => {
16899
17026
  let slice2 = dragging && dragging.slice;
16900
17027
  if (slice2) {
16901
17028
  view.someProp("transformPasted", (f) => {
16902
- slice2 = f(slice2, view);
17029
+ slice2 = f(slice2, view, false);
16903
17030
  });
16904
17031
  } else {
16905
17032
  slice2 = parseFromClipboard(view, getText$1(event2.dataTransfer), brokenClipboardAPI ? null : event2.dataTransfer.getData("text/html"), false, $mouse);
@@ -16942,7 +17069,7 @@ editHandlers.drop = (view, _event) => {
16942
17069
  }
16943
17070
  view.focus();
16944
17071
  view.dispatch(tr2.setMeta("uiEvent", "drop"));
16945
- };
17072
+ }
16946
17073
  handlers.focus = (view) => {
16947
17074
  view.input.lastFocus = Date.now();
16948
17075
  if (!view.focused) {
@@ -17792,6 +17919,13 @@ class DOMObserver {
17792
17919
  br.remove();
17793
17920
  }
17794
17921
  }
17922
+ } else if ((chrome || safari) && added.some((n) => n.nodeName == "BR") && (view.input.lastKeyCode == 8 || view.input.lastKeyCode == 46)) {
17923
+ for (let node of added)
17924
+ if (node.nodeName == "BR" && node.parentNode) {
17925
+ let after = node.nextSibling;
17926
+ if (after && after.nodeType == 1 && after.contentEditable == "false")
17927
+ node.parentNode.removeChild(node);
17928
+ }
17795
17929
  }
17796
17930
  let readSel = null;
17797
17931
  if (from2 < 0 && newSel && view.input.lastFocus > Date.now() - 200 && Math.max(view.input.lastTouch, view.input.lastClick.time) < Date.now() - 300 && selectionCollapsed(sel) && (readSel = selectionFromDOM(view)) && readSel.eq(Selection.near(view.state.doc.resolve(0), 1))) {
@@ -18045,8 +18179,7 @@ function readDOMChange(view, from2, to, typeOver, addedNodes) {
18045
18179
  let $to = parse2.doc.resolveNoCache(change.endB - parse2.from);
18046
18180
  let $fromA = doc2.resolve(change.start);
18047
18181
  let inlineChange = $from.sameParent($to) && $from.parent.inlineContent && $fromA.end() >= change.endA;
18048
- let nextSel;
18049
- if ((ios && view.input.lastIOSEnter > Date.now() - 225 && (!inlineChange || addedNodes.some((n) => n.nodeName == "DIV" || n.nodeName == "P")) || !inlineChange && $from.pos < parse2.doc.content.size && (!$from.sameParent($to) || !$from.parent.inlineContent) && !/\S/.test(parse2.doc.textBetween($from.pos, $to.pos, "", "")) && (nextSel = Selection.findFrom(parse2.doc.resolve($from.pos + 1), 1, true)) && nextSel.head > $from.pos) && view.someProp("handleKeyDown", (f) => f(view, keyEvent(13, "Enter")))) {
18182
+ if ((ios && view.input.lastIOSEnter > Date.now() - 225 && (!inlineChange || addedNodes.some((n) => n.nodeName == "DIV" || n.nodeName == "P")) || !inlineChange && $from.pos < parse2.doc.content.size && (!$from.sameParent($to) || !$from.parent.inlineContent) && $from.pos < $to.pos && !/\S/.test(parse2.doc.textBetween($from.pos, $to.pos, "", ""))) && view.someProp("handleKeyDown", (f) => f(view, keyEvent(13, "Enter")))) {
18050
18183
  view.input.lastIOSEnter = 0;
18051
18184
  return;
18052
18185
  }
@@ -18105,6 +18238,8 @@ function readDOMChange(view, from2, to, typeOver, addedNodes) {
18105
18238
  let deflt = () => mkTr(view.state.tr.insertText(text2, chFrom, chTo));
18106
18239
  if (!view.someProp("handleTextInput", (f) => f(view, chFrom, chTo, text2, deflt)))
18107
18240
  view.dispatch(deflt());
18241
+ } else {
18242
+ view.dispatch(mkTr());
18108
18243
  }
18109
18244
  } else {
18110
18245
  view.dispatch(mkTr());
@@ -28382,6 +28517,9 @@ class GapBookmark {
28382
28517
  return GapCursor.valid($pos) ? new GapCursor($pos) : Selection.near($pos);
28383
28518
  }
28384
28519
  }
28520
+ function needsGap(type) {
28521
+ return type.isAtom || type.spec.isolating || type.spec.createGapCursor;
28522
+ }
28385
28523
  function closedBefore($pos) {
28386
28524
  for (let d2 = $pos.depth; d2 >= 0; d2--) {
28387
28525
  let index2 = $pos.index(d2), parent = $pos.node(d2);
@@ -28391,7 +28529,7 @@ function closedBefore($pos) {
28391
28529
  continue;
28392
28530
  }
28393
28531
  for (let before = parent.child(index2 - 1); ; before = before.lastChild) {
28394
- if (before.childCount == 0 && !before.inlineContent || before.isAtom || before.type.spec.isolating)
28532
+ if (before.childCount == 0 && !before.inlineContent || needsGap(before.type))
28395
28533
  return true;
28396
28534
  if (before.inlineContent)
28397
28535
  return false;
@@ -28408,7 +28546,7 @@ function closedAfter($pos) {
28408
28546
  continue;
28409
28547
  }
28410
28548
  for (let after = parent.child(index2); ; after = after.firstChild) {
28411
- if (after.childCount == 0 && !after.inlineContent || after.isAtom || after.type.spec.isolating)
28549
+ if (after.childCount == 0 && !after.inlineContent || needsGap(after.type))
28412
28550
  return true;
28413
28551
  if (after.inlineContent)
28414
28552
  return false;
@@ -28992,7 +29130,7 @@ function history(config = {}) {
28992
29130
  beforeinput(view, e) {
28993
29131
  let inputType = e.inputType;
28994
29132
  let command2 = inputType == "historyUndo" ? undo : inputType == "historyRedo" ? redo : null;
28995
- if (!command2)
29133
+ if (!command2 || !view.editable)
28996
29134
  return false;
28997
29135
  e.preventDefault();
28998
29136
  return command2(view.state, view.dispatch);
@@ -29586,8 +29724,8 @@ var Image$2 = Node3.create({
29586
29724
  ];
29587
29725
  }
29588
29726
  });
29589
- var readFromCache;
29590
- var addToCache;
29727
+ let readFromCache;
29728
+ let addToCache;
29591
29729
  if (typeof WeakMap != "undefined") {
29592
29730
  let cache2 = /* @__PURE__ */ new WeakMap();
29593
29731
  readFromCache = (key) => cache2.get(key);
@@ -29600,8 +29738,7 @@ if (typeof WeakMap != "undefined") {
29600
29738
  const cacheSize = 10;
29601
29739
  let cachePos = 0;
29602
29740
  readFromCache = (key) => {
29603
- for (let i = 0; i < cache2.length; i += 2)
29604
- if (cache2[i] == key) return cache2[i + 1];
29741
+ for (let i = 0; i < cache2.length; i += 2) if (cache2[i] == key) return cache2[i + 1];
29605
29742
  };
29606
29743
  addToCache = (key, value) => {
29607
29744
  if (cachePos == cacheSize) cachePos = 0;
@@ -29616,7 +29753,6 @@ var TableMap = class {
29616
29753
  this.map = map2;
29617
29754
  this.problems = problems;
29618
29755
  }
29619
- // Find the dimensions of the cell at the given position.
29620
29756
  findCell(pos) {
29621
29757
  for (let i = 0; i < this.map.length; i++) {
29622
29758
  const curPos = this.map[i];
@@ -29625,27 +29761,21 @@ var TableMap = class {
29625
29761
  const top = i / this.width | 0;
29626
29762
  let right = left + 1;
29627
29763
  let bottom = top + 1;
29628
- for (let j2 = 1; right < this.width && this.map[i + j2] == curPos; j2++) {
29629
- right++;
29630
- }
29631
- for (let j2 = 1; bottom < this.height && this.map[i + this.width * j2] == curPos; j2++) {
29632
- bottom++;
29633
- }
29634
- return { left, top, right, bottom };
29764
+ for (let j2 = 1; right < this.width && this.map[i + j2] == curPos; j2++) right++;
29765
+ for (let j2 = 1; bottom < this.height && this.map[i + this.width * j2] == curPos; j2++) bottom++;
29766
+ return {
29767
+ left,
29768
+ top,
29769
+ right,
29770
+ bottom
29771
+ };
29635
29772
  }
29636
29773
  throw new RangeError(`No cell with offset ${pos} found`);
29637
29774
  }
29638
- // Find the left side of the cell at the given position.
29639
29775
  colCount(pos) {
29640
- for (let i = 0; i < this.map.length; i++) {
29641
- if (this.map[i] == pos) {
29642
- return i % this.width;
29643
- }
29644
- }
29776
+ for (let i = 0; i < this.map.length; i++) if (this.map[i] == pos) return i % this.width;
29645
29777
  throw new RangeError(`No cell with offset ${pos} found`);
29646
29778
  }
29647
- // Find the next cell in the given direction, starting from the cell
29648
- // at `pos`, if any.
29649
29779
  nextCell(pos, axis, dir) {
29650
29780
  const { left, right, top, bottom } = this.findCell(pos);
29651
29781
  if (axis == "horiz") {
@@ -29656,20 +29786,9 @@ var TableMap = class {
29656
29786
  return this.map[left + this.width * (dir < 0 ? top - 1 : bottom)];
29657
29787
  }
29658
29788
  }
29659
- // Get the rectangle spanning the two given cells.
29660
29789
  rectBetween(a, b2) {
29661
- const {
29662
- left: leftA,
29663
- right: rightA,
29664
- top: topA,
29665
- bottom: bottomA
29666
- } = this.findCell(a);
29667
- const {
29668
- left: leftB,
29669
- right: rightB,
29670
- top: topB,
29671
- bottom: bottomB
29672
- } = this.findCell(b2);
29790
+ const { left: leftA, right: rightA, top: topA, bottom: bottomA } = this.findCell(a);
29791
+ const { left: leftB, right: rightB, top: topB, bottom: bottomB } = this.findCell(b2);
29673
29792
  return {
29674
29793
  left: Math.min(leftA, leftB),
29675
29794
  top: Math.min(topA, topB),
@@ -29677,27 +29796,19 @@ var TableMap = class {
29677
29796
  bottom: Math.max(bottomA, bottomB)
29678
29797
  };
29679
29798
  }
29680
- // Return the position of all cells that have the top left corner in
29681
- // the given rectangle.
29682
29799
  cellsInRect(rect) {
29683
29800
  const result = [];
29684
29801
  const seen = {};
29685
- for (let row = rect.top; row < rect.bottom; row++) {
29686
- for (let col = rect.left; col < rect.right; col++) {
29687
- const index2 = row * this.width + col;
29688
- const pos = this.map[index2];
29689
- if (seen[pos]) continue;
29690
- seen[pos] = true;
29691
- if (col == rect.left && col && this.map[index2 - 1] == pos || row == rect.top && row && this.map[index2 - this.width] == pos) {
29692
- continue;
29693
- }
29694
- result.push(pos);
29695
- }
29802
+ for (let row = rect.top; row < rect.bottom; row++) for (let col = rect.left; col < rect.right; col++) {
29803
+ const index2 = row * this.width + col;
29804
+ const pos = this.map[index2];
29805
+ if (seen[pos]) continue;
29806
+ seen[pos] = true;
29807
+ if (col == rect.left && col && this.map[index2 - 1] == pos || row == rect.top && row && this.map[index2 - this.width] == pos) continue;
29808
+ result.push(pos);
29696
29809
  }
29697
29810
  return result;
29698
29811
  }
29699
- // Return the position at which the cell at the given row and column
29700
- // starts, or would start, if a cell started there.
29701
29812
  positionAt(row, col, table) {
29702
29813
  for (let i = 0, rowStart = 0; ; i++) {
29703
29814
  const rowEnd = rowStart + table.child(i).nodeSize;
@@ -29710,14 +29821,12 @@ var TableMap = class {
29710
29821
  rowStart = rowEnd;
29711
29822
  }
29712
29823
  }
29713
- // Find the table map for the given table node.
29714
29824
  static get(table) {
29715
29825
  return readFromCache(table) || addToCache(table, computeMap(table));
29716
29826
  }
29717
29827
  };
29718
29828
  function computeMap(table) {
29719
- if (table.type.spec.tableRole != "table")
29720
- throw new RangeError("Not a table node: " + table.type.name);
29829
+ if (table.type.spec.tableRole != "table") throw new RangeError("Not a table node: " + table.type.name);
29721
29830
  const width = findWidth(table), height = table.childCount;
29722
29831
  const map2 = [];
29723
29832
  let mapPos = 0;
@@ -29744,22 +29853,19 @@ function computeMap(table) {
29744
29853
  const start = mapPos + h2 * width;
29745
29854
  for (let w2 = 0; w2 < colspan; w2++) {
29746
29855
  if (map2[start + w2] == 0) map2[start + w2] = pos;
29747
- else
29748
- (problems || (problems = [])).push({
29749
- type: "collision",
29750
- row,
29751
- pos,
29752
- n: colspan - w2
29753
- });
29856
+ else (problems || (problems = [])).push({
29857
+ type: "collision",
29858
+ row,
29859
+ pos,
29860
+ n: colspan - w2
29861
+ });
29754
29862
  const colW = colwidth && colwidth[w2];
29755
29863
  if (colW) {
29756
29864
  const widthIndex = (start + w2) % width * 2, prev = colWidths[widthIndex];
29757
29865
  if (prev == null || prev != colW && colWidths[widthIndex + 1] == 1) {
29758
29866
  colWidths[widthIndex] = colW;
29759
29867
  colWidths[widthIndex + 1] = 1;
29760
- } else if (prev == colW) {
29761
- colWidths[widthIndex + 1]++;
29762
- }
29868
+ } else if (prev == colW) colWidths[widthIndex + 1]++;
29763
29869
  }
29764
29870
  }
29765
29871
  }
@@ -29769,16 +29875,17 @@ function computeMap(table) {
29769
29875
  const expectedPos = (row + 1) * width;
29770
29876
  let missing = 0;
29771
29877
  while (mapPos < expectedPos) if (map2[mapPos++] == 0) missing++;
29772
- if (missing)
29773
- (problems || (problems = [])).push({ type: "missing", row, n: missing });
29878
+ if (missing) (problems || (problems = [])).push({
29879
+ type: "missing",
29880
+ row,
29881
+ n: missing
29882
+ });
29774
29883
  pos++;
29775
29884
  }
29776
- if (width === 0 || height === 0)
29777
- (problems || (problems = [])).push({ type: "zero_sized" });
29885
+ if (width === 0 || height === 0) (problems || (problems = [])).push({ type: "zero_sized" });
29778
29886
  const tableMap = new TableMap(width, height, map2, problems);
29779
29887
  let badWidths = false;
29780
- for (let i = 0; !badWidths && i < colWidths.length; i += 2)
29781
- if (colWidths[i] != null && colWidths[i + 1] < height) badWidths = true;
29888
+ for (let i = 0; !badWidths && i < colWidths.length; i += 2) if (colWidths[i] != null && colWidths[i + 1] < height) badWidths = true;
29782
29889
  if (badWidths) findBadColWidths(tableMap, colWidths, table);
29783
29890
  return tableMap;
29784
29891
  }
@@ -29788,14 +29895,13 @@ function findWidth(table) {
29788
29895
  for (let row = 0; row < table.childCount; row++) {
29789
29896
  const rowNode = table.child(row);
29790
29897
  let rowWidth = 0;
29791
- if (hasRowSpan)
29792
- for (let j2 = 0; j2 < row; j2++) {
29793
- const prevRow = table.child(j2);
29794
- for (let i = 0; i < prevRow.childCount; i++) {
29795
- const cell = prevRow.child(i);
29796
- if (j2 + cell.attrs.rowspan > row) rowWidth += cell.attrs.colspan;
29797
- }
29898
+ if (hasRowSpan) for (let j2 = 0; j2 < row; j2++) {
29899
+ const prevRow = table.child(j2);
29900
+ for (let i = 0; i < prevRow.childCount; i++) {
29901
+ const cell = prevRow.child(i);
29902
+ if (j2 + cell.attrs.rowspan > row) rowWidth += cell.attrs.colspan;
29798
29903
  }
29904
+ }
29799
29905
  for (let i = 0; i < rowNode.childCount; i++) {
29800
29906
  const cell = rowNode.child(i);
29801
29907
  rowWidth += cell.attrs.colspan;
@@ -29814,23 +29920,18 @@ function findBadColWidths(map2, colWidths, table) {
29814
29920
  if (seen[pos]) continue;
29815
29921
  seen[pos] = true;
29816
29922
  const node = table.nodeAt(pos);
29817
- if (!node) {
29818
- throw new RangeError(`No cell with offset ${pos} found`);
29819
- }
29923
+ if (!node) throw new RangeError(`No cell with offset ${pos} found`);
29820
29924
  let updated = null;
29821
29925
  const attrs = node.attrs;
29822
29926
  for (let j2 = 0; j2 < attrs.colspan; j2++) {
29823
- const col = (i + j2) % map2.width;
29824
- const colWidth = colWidths[col * 2];
29825
- if (colWidth != null && (!attrs.colwidth || attrs.colwidth[j2] != colWidth))
29826
- (updated || (updated = freshColWidth(attrs)))[j2] = colWidth;
29827
- }
29828
- if (updated)
29829
- map2.problems.unshift({
29830
- type: "colwidth mismatch",
29831
- pos,
29832
- colwidth: updated
29833
- });
29927
+ const colWidth = colWidths[(i + j2) % map2.width * 2];
29928
+ if (colWidth != null && (!attrs.colwidth || attrs.colwidth[j2] != colWidth)) (updated || (updated = freshColWidth(attrs)))[j2] = colWidth;
29929
+ }
29930
+ if (updated) map2.problems.unshift({
29931
+ type: "colwidth mismatch",
29932
+ pos,
29933
+ colwidth: updated
29934
+ });
29834
29935
  }
29835
29936
  }
29836
29937
  function freshColWidth(attrs) {
@@ -29850,11 +29951,9 @@ function tableNodeTypes(schema) {
29850
29951
  }
29851
29952
  return result;
29852
29953
  }
29853
- var tableEditingKey = new PluginKey("selectingCells");
29954
+ const tableEditingKey = new PluginKey("selectingCells");
29854
29955
  function cellAround($pos) {
29855
- for (let d2 = $pos.depth - 1; d2 > 0; d2--)
29856
- if ($pos.node(d2).type.spec.tableRole == "row")
29857
- return $pos.node(0).resolve($pos.before(d2 + 1));
29956
+ for (let d2 = $pos.depth - 1; d2 > 0; d2--) if ($pos.node(d2).type.spec.tableRole == "row") return $pos.node(0).resolve($pos.before(d2 + 1));
29858
29957
  return null;
29859
29958
  }
29860
29959
  function cellWrapping($pos) {
@@ -29866,21 +29965,15 @@ function cellWrapping($pos) {
29866
29965
  }
29867
29966
  function isInTable(state2) {
29868
29967
  const $head = state2.selection.$head;
29869
- for (let d2 = $head.depth; d2 > 0; d2--)
29870
- if ($head.node(d2).type.spec.tableRole == "row") return true;
29968
+ for (let d2 = $head.depth; d2 > 0; d2--) if ($head.node(d2).type.spec.tableRole == "row") return true;
29871
29969
  return false;
29872
29970
  }
29873
29971
  function selectionCell(state2) {
29874
29972
  const sel = state2.selection;
29875
- if ("$anchorCell" in sel && sel.$anchorCell) {
29876
- return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;
29877
- } else if ("node" in sel && sel.node && sel.node.type.spec.tableRole == "cell") {
29878
- return sel.$anchor;
29879
- }
29973
+ if ("$anchorCell" in sel && sel.$anchorCell) return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;
29974
+ else if ("node" in sel && sel.node && sel.node.type.spec.tableRole == "cell") return sel.$anchor;
29880
29975
  const $cell = cellAround(sel.$head) || cellNear(sel.$head);
29881
- if ($cell) {
29882
- return $cell;
29883
- }
29976
+ if ($cell) return $cell;
29884
29977
  throw new RangeError(`No cell found around position ${sel.head}`);
29885
29978
  }
29886
29979
  function cellNear($pos) {
@@ -29890,8 +29983,7 @@ function cellNear($pos) {
29890
29983
  }
29891
29984
  for (let before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) {
29892
29985
  const role = before.type.spec.tableRole;
29893
- if (role == "cell" || role == "header_cell")
29894
- return $pos.doc.resolve(pos - before.nodeSize);
29986
+ if (role == "cell" || role == "header_cell") return $pos.doc.resolve(pos - before.nodeSize);
29895
29987
  }
29896
29988
  }
29897
29989
  function pointsAtCell($pos) {
@@ -29911,7 +30003,10 @@ function nextCell($pos, axis, dir) {
29911
30003
  return moved == null ? null : $pos.node(0).resolve(tableStart + moved);
29912
30004
  }
29913
30005
  function removeColSpan(attrs, pos, n = 1) {
29914
- const result = { ...attrs, colspan: attrs.colspan - n };
30006
+ const result = {
30007
+ ...attrs,
30008
+ colspan: attrs.colspan - n
30009
+ };
29915
30010
  if (result.colwidth) {
29916
30011
  result.colwidth = result.colwidth.slice();
29917
30012
  result.colwidth.splice(pos, n);
@@ -29920,7 +30015,10 @@ function removeColSpan(attrs, pos, n = 1) {
29920
30015
  return result;
29921
30016
  }
29922
30017
  function addColSpan(attrs, pos, n = 1) {
29923
- const result = { ...attrs, colspan: attrs.colspan + n };
30018
+ const result = {
30019
+ ...attrs,
30020
+ colspan: attrs.colspan + n
30021
+ };
29924
30022
  if (result.colwidth) {
29925
30023
  result.colwidth = result.colwidth.slice();
29926
30024
  for (let i = 0; i < n; i++) result.colwidth.splice(pos, 0, 0);
@@ -29929,37 +30027,23 @@ function addColSpan(attrs, pos, n = 1) {
29929
30027
  }
29930
30028
  function columnIsHeader(map2, table, col) {
29931
30029
  const headerCell = tableNodeTypes(table.type.schema).header_cell;
29932
- for (let row = 0; row < map2.height; row++)
29933
- if (table.nodeAt(map2.map[col + row * map2.width]).type != headerCell)
29934
- return false;
30030
+ for (let row = 0; row < map2.height; row++) if (table.nodeAt(map2.map[col + row * map2.width]).type != headerCell) return false;
29935
30031
  return true;
29936
30032
  }
29937
- var CellSelection = class _CellSelection extends Selection {
29938
- // A table selection is identified by its anchor and head cells. The
29939
- // positions given to this constructor should point _before_ two
29940
- // cells in the same table. They may be the same, to select a single
29941
- // cell.
30033
+ var CellSelection = class CellSelection2 extends Selection {
29942
30034
  constructor($anchorCell, $headCell = $anchorCell) {
29943
30035
  const table = $anchorCell.node(-1);
29944
30036
  const map2 = TableMap.get(table);
29945
30037
  const tableStart = $anchorCell.start(-1);
29946
- const rect = map2.rectBetween(
29947
- $anchorCell.pos - tableStart,
29948
- $headCell.pos - tableStart
29949
- );
30038
+ const rect = map2.rectBetween($anchorCell.pos - tableStart, $headCell.pos - tableStart);
29950
30039
  const doc2 = $anchorCell.node(0);
29951
30040
  const cells = map2.cellsInRect(rect).filter((p) => p != $headCell.pos - tableStart);
29952
30041
  cells.unshift($headCell.pos - tableStart);
29953
30042
  const ranges = cells.map((pos) => {
29954
30043
  const cell = table.nodeAt(pos);
29955
- if (!cell) {
29956
- throw RangeError(`No cell with offset ${pos} found`);
29957
- }
30044
+ if (!cell) throw new RangeError(`No cell with offset ${pos} found`);
29958
30045
  const from2 = tableStart + pos + 1;
29959
- return new SelectionRange(
29960
- doc2.resolve(from2),
29961
- doc2.resolve(from2 + cell.content.size)
29962
- );
30046
+ return new SelectionRange(doc2.resolve(from2), doc2.resolve(from2 + cell.content.size));
29963
30047
  });
29964
30048
  super(ranges[0].$from, ranges[0].$to, ranges);
29965
30049
  this.$anchorCell = $anchorCell;
@@ -29970,24 +30054,17 @@ var CellSelection = class _CellSelection extends Selection {
29970
30054
  const $headCell = doc2.resolve(mapping.map(this.$headCell.pos));
29971
30055
  if (pointsAtCell($anchorCell) && pointsAtCell($headCell) && inSameTable($anchorCell, $headCell)) {
29972
30056
  const tableChanged = this.$anchorCell.node(-1) != $anchorCell.node(-1);
29973
- if (tableChanged && this.isRowSelection())
29974
- return _CellSelection.rowSelection($anchorCell, $headCell);
29975
- else if (tableChanged && this.isColSelection())
29976
- return _CellSelection.colSelection($anchorCell, $headCell);
29977
- else return new _CellSelection($anchorCell, $headCell);
30057
+ if (tableChanged && this.isRowSelection()) return CellSelection2.rowSelection($anchorCell, $headCell);
30058
+ else if (tableChanged && this.isColSelection()) return CellSelection2.colSelection($anchorCell, $headCell);
30059
+ else return new CellSelection2($anchorCell, $headCell);
29978
30060
  }
29979
30061
  return TextSelection.between($anchorCell, $headCell);
29980
30062
  }
29981
- // Returns a rectangular slice of table rows containing the selected
29982
- // cells.
29983
30063
  content() {
29984
30064
  const table = this.$anchorCell.node(-1);
29985
30065
  const map2 = TableMap.get(table);
29986
30066
  const tableStart = this.$anchorCell.start(-1);
29987
- const rect = map2.rectBetween(
29988
- this.$anchorCell.pos - tableStart,
29989
- this.$headCell.pos - tableStart
29990
- );
30067
+ const rect = map2.rectBetween(this.$anchorCell.pos - tableStart, this.$headCell.pos - tableStart);
29991
30068
  const seen = {};
29992
30069
  const rows = [];
29993
30070
  for (let row = rect.top; row < rect.bottom; row++) {
@@ -29998,44 +30075,25 @@ var CellSelection = class _CellSelection extends Selection {
29998
30075
  seen[pos] = true;
29999
30076
  const cellRect = map2.findCell(pos);
30000
30077
  let cell = table.nodeAt(pos);
30001
- if (!cell) {
30002
- throw RangeError(`No cell with offset ${pos} found`);
30003
- }
30078
+ if (!cell) throw new RangeError(`No cell with offset ${pos} found`);
30004
30079
  const extraLeft = rect.left - cellRect.left;
30005
30080
  const extraRight = cellRect.right - rect.right;
30006
30081
  if (extraLeft > 0 || extraRight > 0) {
30007
30082
  let attrs = cell.attrs;
30008
- if (extraLeft > 0) {
30009
- attrs = removeColSpan(attrs, 0, extraLeft);
30010
- }
30011
- if (extraRight > 0) {
30012
- attrs = removeColSpan(
30013
- attrs,
30014
- attrs.colspan - extraRight,
30015
- extraRight
30016
- );
30017
- }
30083
+ if (extraLeft > 0) attrs = removeColSpan(attrs, 0, extraLeft);
30084
+ if (extraRight > 0) attrs = removeColSpan(attrs, attrs.colspan - extraRight, extraRight);
30018
30085
  if (cellRect.left < rect.left) {
30019
30086
  cell = cell.type.createAndFill(attrs);
30020
- if (!cell) {
30021
- throw RangeError(
30022
- `Could not create cell with attrs ${JSON.stringify(attrs)}`
30023
- );
30024
- }
30025
- } else {
30026
- cell = cell.type.create(attrs, cell.content);
30027
- }
30087
+ if (!cell) throw new RangeError(`Could not create cell with attrs ${JSON.stringify(attrs)}`);
30088
+ } else cell = cell.type.create(attrs, cell.content);
30028
30089
  }
30029
30090
  if (cellRect.top < rect.top || cellRect.bottom > rect.bottom) {
30030
30091
  const attrs = {
30031
30092
  ...cell.attrs,
30032
30093
  rowspan: Math.min(cellRect.bottom, rect.bottom) - Math.max(cellRect.top, rect.top)
30033
30094
  };
30034
- if (cellRect.top < rect.top) {
30035
- cell = cell.type.createAndFill(attrs);
30036
- } else {
30037
- cell = cell.type.create(attrs, cell.content);
30038
- }
30095
+ if (cellRect.top < rect.top) cell = cell.type.createAndFill(attrs);
30096
+ else cell = cell.type.create(attrs, cell.content);
30039
30097
  }
30040
30098
  rowContent.push(cell);
30041
30099
  }
@@ -30048,16 +30106,9 @@ var CellSelection = class _CellSelection extends Selection {
30048
30106
  const mapFrom = tr2.steps.length, ranges = this.ranges;
30049
30107
  for (let i = 0; i < ranges.length; i++) {
30050
30108
  const { $from, $to } = ranges[i], mapping = tr2.mapping.slice(mapFrom);
30051
- tr2.replace(
30052
- mapping.map($from.pos),
30053
- mapping.map($to.pos),
30054
- i ? Slice.empty : content
30055
- );
30109
+ tr2.replace(mapping.map($from.pos), mapping.map($to.pos), i ? Slice.empty : content);
30056
30110
  }
30057
- const sel = Selection.findFrom(
30058
- tr2.doc.resolve(tr2.mapping.slice(mapFrom).map(this.to)),
30059
- -1
30060
- );
30111
+ const sel = Selection.findFrom(tr2.doc.resolve(tr2.mapping.slice(mapFrom).map(this.to)), -1);
30061
30112
  if (sel) tr2.setSelection(sel);
30062
30113
  }
30063
30114
  replaceWith(tr2, node) {
@@ -30067,18 +30118,9 @@ var CellSelection = class _CellSelection extends Selection {
30067
30118
  const table = this.$anchorCell.node(-1);
30068
30119
  const map2 = TableMap.get(table);
30069
30120
  const tableStart = this.$anchorCell.start(-1);
30070
- const cells = map2.cellsInRect(
30071
- map2.rectBetween(
30072
- this.$anchorCell.pos - tableStart,
30073
- this.$headCell.pos - tableStart
30074
- )
30075
- );
30076
- for (let i = 0; i < cells.length; i++) {
30077
- f(table.nodeAt(cells[i]), tableStart + cells[i]);
30078
- }
30121
+ const cells = map2.cellsInRect(map2.rectBetween(this.$anchorCell.pos - tableStart, this.$headCell.pos - tableStart));
30122
+ for (let i = 0; i < cells.length; i++) f(table.nodeAt(cells[i]), tableStart + cells[i]);
30079
30123
  }
30080
- // True if this selection goes all the way from the top to the
30081
- // bottom of the table.
30082
30124
  isColSelection() {
30083
30125
  const anchorTop = this.$anchorCell.index(-1);
30084
30126
  const headTop = this.$headCell.index(-1);
@@ -30087,8 +30129,6 @@ var CellSelection = class _CellSelection extends Selection {
30087
30129
  const headBottom = headTop + this.$headCell.nodeAfter.attrs.rowspan;
30088
30130
  return Math.max(anchorBottom, headBottom) == this.$headCell.node(-1).childCount;
30089
30131
  }
30090
- // Returns the smallest column selection that covers the given anchor
30091
- // and head cell.
30092
30132
  static colSelection($anchorCell, $headCell = $anchorCell) {
30093
30133
  const table = $anchorCell.node(-1);
30094
30134
  const map2 = TableMap.get(table);
@@ -30097,24 +30137,14 @@ var CellSelection = class _CellSelection extends Selection {
30097
30137
  const headRect = map2.findCell($headCell.pos - tableStart);
30098
30138
  const doc2 = $anchorCell.node(0);
30099
30139
  if (anchorRect.top <= headRect.top) {
30100
- if (anchorRect.top > 0)
30101
- $anchorCell = doc2.resolve(tableStart + map2.map[anchorRect.left]);
30102
- if (headRect.bottom < map2.height)
30103
- $headCell = doc2.resolve(
30104
- tableStart + map2.map[map2.width * (map2.height - 1) + headRect.right - 1]
30105
- );
30140
+ if (anchorRect.top > 0) $anchorCell = doc2.resolve(tableStart + map2.map[anchorRect.left]);
30141
+ if (headRect.bottom < map2.height) $headCell = doc2.resolve(tableStart + map2.map[map2.width * (map2.height - 1) + headRect.right - 1]);
30106
30142
  } else {
30107
- if (headRect.top > 0)
30108
- $headCell = doc2.resolve(tableStart + map2.map[headRect.left]);
30109
- if (anchorRect.bottom < map2.height)
30110
- $anchorCell = doc2.resolve(
30111
- tableStart + map2.map[map2.width * (map2.height - 1) + anchorRect.right - 1]
30112
- );
30143
+ if (headRect.top > 0) $headCell = doc2.resolve(tableStart + map2.map[headRect.left]);
30144
+ if (anchorRect.bottom < map2.height) $anchorCell = doc2.resolve(tableStart + map2.map[map2.width * (map2.height - 1) + anchorRect.right - 1]);
30113
30145
  }
30114
- return new _CellSelection($anchorCell, $headCell);
30146
+ return new CellSelection2($anchorCell, $headCell);
30115
30147
  }
30116
- // True if this selection goes all the way from the left to the
30117
- // right of the table.
30118
30148
  isRowSelection() {
30119
30149
  const table = this.$anchorCell.node(-1);
30120
30150
  const map2 = TableMap.get(table);
@@ -30127,10 +30157,8 @@ var CellSelection = class _CellSelection extends Selection {
30127
30157
  return Math.max(anchorRight, headRight) == map2.width;
30128
30158
  }
30129
30159
  eq(other) {
30130
- return other instanceof _CellSelection && other.$anchorCell.pos == this.$anchorCell.pos && other.$headCell.pos == this.$headCell.pos;
30160
+ return other instanceof CellSelection2 && other.$anchorCell.pos == this.$anchorCell.pos && other.$headCell.pos == this.$headCell.pos;
30131
30161
  }
30132
- // Returns the smallest row selection that covers the given anchor
30133
- // and head cell.
30134
30162
  static rowSelection($anchorCell, $headCell = $anchorCell) {
30135
30163
  const table = $anchorCell.node(-1);
30136
30164
  const map2 = TableMap.get(table);
@@ -30139,23 +30167,13 @@ var CellSelection = class _CellSelection extends Selection {
30139
30167
  const headRect = map2.findCell($headCell.pos - tableStart);
30140
30168
  const doc2 = $anchorCell.node(0);
30141
30169
  if (anchorRect.left <= headRect.left) {
30142
- if (anchorRect.left > 0)
30143
- $anchorCell = doc2.resolve(
30144
- tableStart + map2.map[anchorRect.top * map2.width]
30145
- );
30146
- if (headRect.right < map2.width)
30147
- $headCell = doc2.resolve(
30148
- tableStart + map2.map[map2.width * (headRect.top + 1) - 1]
30149
- );
30170
+ if (anchorRect.left > 0) $anchorCell = doc2.resolve(tableStart + map2.map[anchorRect.top * map2.width]);
30171
+ if (headRect.right < map2.width) $headCell = doc2.resolve(tableStart + map2.map[map2.width * (headRect.top + 1) - 1]);
30150
30172
  } else {
30151
- if (headRect.left > 0)
30152
- $headCell = doc2.resolve(tableStart + map2.map[headRect.top * map2.width]);
30153
- if (anchorRect.right < map2.width)
30154
- $anchorCell = doc2.resolve(
30155
- tableStart + map2.map[map2.width * (anchorRect.top + 1) - 1]
30156
- );
30173
+ if (headRect.left > 0) $headCell = doc2.resolve(tableStart + map2.map[headRect.top * map2.width]);
30174
+ if (anchorRect.right < map2.width) $anchorCell = doc2.resolve(tableStart + map2.map[map2.width * (anchorRect.top + 1) - 1]);
30157
30175
  }
30158
- return new _CellSelection($anchorCell, $headCell);
30176
+ return new CellSelection2($anchorCell, $headCell);
30159
30177
  }
30160
30178
  toJSON() {
30161
30179
  return {
@@ -30165,10 +30183,10 @@ var CellSelection = class _CellSelection extends Selection {
30165
30183
  };
30166
30184
  }
30167
30185
  static fromJSON(doc2, json) {
30168
- return new _CellSelection(doc2.resolve(json.anchor), doc2.resolve(json.head));
30186
+ return new CellSelection2(doc2.resolve(json.anchor), doc2.resolve(json.head));
30169
30187
  }
30170
30188
  static create(doc2, anchorCell, headCell = anchorCell) {
30171
- return new _CellSelection(doc2.resolve(anchorCell), doc2.resolve(headCell));
30189
+ return new CellSelection2(doc2.resolve(anchorCell), doc2.resolve(headCell));
30172
30190
  }
30173
30191
  getBookmark() {
30174
30192
  return new CellBookmark(this.$anchorCell.pos, this.$headCell.pos);
@@ -30176,18 +30194,17 @@ var CellSelection = class _CellSelection extends Selection {
30176
30194
  };
30177
30195
  CellSelection.prototype.visible = false;
30178
30196
  Selection.jsonID("cell", CellSelection);
30179
- var CellBookmark = class _CellBookmark {
30197
+ var CellBookmark = class CellBookmark2 {
30180
30198
  constructor(anchor, head) {
30181
30199
  this.anchor = anchor;
30182
30200
  this.head = head;
30183
30201
  }
30184
30202
  map(mapping) {
30185
- return new _CellBookmark(mapping.map(this.anchor), mapping.map(this.head));
30203
+ return new CellBookmark2(mapping.map(this.anchor), mapping.map(this.head));
30186
30204
  }
30187
30205
  resolve(doc2) {
30188
30206
  const $anchorCell = doc2.resolve(this.anchor), $headCell = doc2.resolve(this.head);
30189
- if ($anchorCell.parent.type.spec.tableRole == "row" && $headCell.parent.type.spec.tableRole == "row" && $anchorCell.index() < $anchorCell.parent.childCount && $headCell.index() < $headCell.parent.childCount && inSameTable($anchorCell, $headCell))
30190
- return new CellSelection($anchorCell, $headCell);
30207
+ if ($anchorCell.parent.type.spec.tableRole == "row" && $headCell.parent.type.spec.tableRole == "row" && $anchorCell.index() < $anchorCell.parent.childCount && $headCell.index() < $headCell.parent.childCount && inSameTable($anchorCell, $headCell)) return new CellSelection($anchorCell, $headCell);
30191
30208
  else return Selection.near($headCell, 1);
30192
30209
  }
30193
30210
  };
@@ -30195,9 +30212,7 @@ function drawCellSelection(state2) {
30195
30212
  if (!(state2.selection instanceof CellSelection)) return null;
30196
30213
  const cells = [];
30197
30214
  state2.selection.forEachCell((node, pos) => {
30198
- cells.push(
30199
- Decoration.node(pos, pos + node.nodeSize, { class: "selectedCell" })
30200
- );
30215
+ cells.push(Decoration.node(pos, pos + node.nodeSize, { class: "selectedCell" }));
30201
30216
  });
30202
30217
  return DecorationSet.create(state2.doc, cells);
30203
30218
  }
@@ -30206,10 +30221,8 @@ function isCellBoundarySelection({ $from, $to }) {
30206
30221
  let afterFrom = $from.pos;
30207
30222
  let beforeTo = $to.pos;
30208
30223
  let depth = $from.depth;
30209
- for (; depth >= 0; depth--, afterFrom++)
30210
- if ($from.after(depth + 1) < $from.end(depth)) break;
30211
- for (let d2 = $to.depth; d2 >= 0; d2--, beforeTo--)
30212
- if ($to.before(d2 + 1) > $to.start(d2)) break;
30224
+ for (; depth >= 0; depth--, afterFrom++) if ($from.after(depth + 1) < $from.end(depth)) break;
30225
+ for (let d2 = $to.depth; d2 >= 0; d2--, beforeTo--) if ($to.before(d2 + 1) > $to.start(d2)) break;
30213
30226
  return afterFrom == beforeTo && /row|table/.test($from.node(depth).type.spec.tableRole);
30214
30227
  }
30215
30228
  function isTextSelectionAcrossCells({ $from, $to }) {
@@ -30237,9 +30250,8 @@ function normalizeSelection(state2, tr2, allowTableNodeSelection) {
30237
30250
  let normalize2;
30238
30251
  let role;
30239
30252
  if (sel instanceof NodeSelection && (role = sel.node.type.spec.tableRole)) {
30240
- if (role == "cell" || role == "header_cell") {
30241
- normalize2 = CellSelection.create(doc2, sel.from);
30242
- } else if (role == "row") {
30253
+ if (role == "cell" || role == "header_cell") normalize2 = CellSelection.create(doc2, sel.from);
30254
+ else if (role == "row") {
30243
30255
  const $cell = doc2.resolve(sel.from + 1);
30244
30256
  normalize2 = CellSelection.rowSelection($cell, $cell);
30245
30257
  } else if (!allowTableNodeSelection) {
@@ -30248,29 +30260,23 @@ function normalizeSelection(state2, tr2, allowTableNodeSelection) {
30248
30260
  const lastCell = start + map2.map[map2.width * map2.height - 1];
30249
30261
  normalize2 = CellSelection.create(doc2, start + 1, lastCell);
30250
30262
  }
30251
- } else if (sel instanceof TextSelection && isCellBoundarySelection(sel)) {
30252
- normalize2 = TextSelection.create(doc2, sel.from);
30253
- } else if (sel instanceof TextSelection && isTextSelectionAcrossCells(sel)) {
30254
- normalize2 = TextSelection.create(doc2, sel.$from.start(), sel.$from.end());
30255
- }
30263
+ } else if (sel instanceof TextSelection && isCellBoundarySelection(sel)) normalize2 = TextSelection.create(doc2, sel.from);
30264
+ else if (sel instanceof TextSelection && isTextSelectionAcrossCells(sel)) normalize2 = TextSelection.create(doc2, sel.$from.start(), sel.$from.end());
30256
30265
  if (normalize2) (tr2 || (tr2 = state2.tr)).setSelection(normalize2);
30257
30266
  return tr2;
30258
30267
  }
30259
- var fixTablesKey = new PluginKey("fix-tables");
30268
+ const fixTablesKey = new PluginKey("fix-tables");
30260
30269
  function changedDescendants(old, cur, offset, f) {
30261
30270
  const oldSize = old.childCount, curSize = cur.childCount;
30262
30271
  outer: for (let i = 0, j2 = 0; i < curSize; i++) {
30263
30272
  const child2 = cur.child(i);
30264
- for (let scan = j2, e = Math.min(oldSize, i + 3); scan < e; scan++) {
30265
- if (old.child(scan) == child2) {
30266
- j2 = scan + 1;
30267
- offset += child2.nodeSize;
30268
- continue outer;
30269
- }
30273
+ for (let scan = j2, e = Math.min(oldSize, i + 3); scan < e; scan++) if (old.child(scan) == child2) {
30274
+ j2 = scan + 1;
30275
+ offset += child2.nodeSize;
30276
+ continue outer;
30270
30277
  }
30271
30278
  f(child2, offset);
30272
- if (j2 < oldSize && old.child(j2).sameMarkup(child2))
30273
- changedDescendants(old.child(j2), child2, offset + 1, f);
30279
+ if (j2 < oldSize && old.child(j2).sameMarkup(child2)) changedDescendants(old.child(j2), child2, offset + 1, f);
30274
30280
  else child2.nodesBetween(0, child2.content.size, f, offset + 1);
30275
30281
  offset += child2.nodeSize;
30276
30282
  }
@@ -30278,12 +30284,10 @@ function changedDescendants(old, cur, offset, f) {
30278
30284
  function fixTables(state2, oldState) {
30279
30285
  let tr2;
30280
30286
  const check = (node, pos) => {
30281
- if (node.type.spec.tableRole == "table")
30282
- tr2 = fixTable(state2, node, pos, tr2);
30287
+ if (node.type.spec.tableRole == "table") tr2 = fixTable(state2, node, pos, tr2);
30283
30288
  };
30284
30289
  if (!oldState) state2.doc.descendants(check);
30285
- else if (oldState.doc != state2.doc)
30286
- changedDescendants(oldState.doc, state2.doc, 0, check);
30290
+ else if (oldState.doc != state2.doc) changedDescendants(oldState.doc, state2.doc, 0, check);
30287
30291
  return tr2;
30288
30292
  }
30289
30293
  function fixTable(state2, table, tablePos, tr2) {
@@ -30299,14 +30303,9 @@ function fixTable(state2, table, tablePos, tr2) {
30299
30303
  if (!cell) continue;
30300
30304
  const attrs = cell.attrs;
30301
30305
  for (let j2 = 0; j2 < attrs.rowspan; j2++) mustAdd[prob.row + j2] += prob.n;
30302
- tr2.setNodeMarkup(
30303
- tr2.mapping.map(tablePos + 1 + prob.pos),
30304
- null,
30305
- removeColSpan(attrs, attrs.colspan - prob.n, prob.n)
30306
- );
30307
- } else if (prob.type == "missing") {
30308
- mustAdd[prob.row] += prob.n;
30309
- } else if (prob.type == "overlong_rowspan") {
30306
+ tr2.setNodeMarkup(tr2.mapping.map(tablePos + 1 + prob.pos), null, removeColSpan(attrs, attrs.colspan - prob.n, prob.n));
30307
+ } else if (prob.type == "missing") mustAdd[prob.row] += prob.n;
30308
+ else if (prob.type == "overlong_rowspan") {
30310
30309
  const cell = table.nodeAt(prob.pos);
30311
30310
  if (!cell) continue;
30312
30311
  tr2.setNodeMarkup(tr2.mapping.map(tablePos + 1 + prob.pos), null, {
@@ -30326,20 +30325,17 @@ function fixTable(state2, table, tablePos, tr2) {
30326
30325
  }
30327
30326
  }
30328
30327
  let first2, last;
30329
- for (let i = 0; i < mustAdd.length; i++)
30330
- if (mustAdd[i]) {
30331
- if (first2 == null) first2 = i;
30332
- last = i;
30333
- }
30328
+ for (let i = 0; i < mustAdd.length; i++) if (mustAdd[i]) {
30329
+ if (first2 == null) first2 = i;
30330
+ last = i;
30331
+ }
30334
30332
  for (let i = 0, pos = tablePos + 1; i < map2.height; i++) {
30335
30333
  const row = table.child(i);
30336
30334
  const end = pos + row.nodeSize;
30337
30335
  const add = mustAdd[i];
30338
30336
  if (add > 0) {
30339
30337
  let role = "cell";
30340
- if (row.firstChild) {
30341
- role = row.firstChild.type.spec.tableRole;
30342
- }
30338
+ if (row.firstChild) role = row.firstChild.type.spec.tableRole;
30343
30339
  const nodes = [];
30344
30340
  for (let j2 = 0; j2 < add; j2++) {
30345
30341
  const node = tableNodeTypes(state2.schema)[role].createAndFill();
@@ -30358,27 +30354,22 @@ function selectedRect(state2) {
30358
30354
  const table = $pos.node(-1);
30359
30355
  const tableStart = $pos.start(-1);
30360
30356
  const map2 = TableMap.get(table);
30361
- const rect = sel instanceof CellSelection ? map2.rectBetween(
30362
- sel.$anchorCell.pos - tableStart,
30363
- sel.$headCell.pos - tableStart
30364
- ) : map2.findCell($pos.pos - tableStart);
30365
- return { ...rect, tableStart, map: map2, table };
30357
+ return {
30358
+ ...sel instanceof CellSelection ? map2.rectBetween(sel.$anchorCell.pos - tableStart, sel.$headCell.pos - tableStart) : map2.findCell($pos.pos - tableStart),
30359
+ tableStart,
30360
+ map: map2,
30361
+ table
30362
+ };
30366
30363
  }
30367
30364
  function addColumn(tr2, { map: map2, tableStart, table }, col) {
30368
30365
  let refColumn = col > 0 ? -1 : 0;
30369
- if (columnIsHeader(map2, table, col + refColumn)) {
30370
- refColumn = col == 0 || col == map2.width ? null : 0;
30371
- }
30366
+ if (columnIsHeader(map2, table, col + refColumn)) refColumn = col == 0 || col == map2.width ? null : 0;
30372
30367
  for (let row = 0; row < map2.height; row++) {
30373
30368
  const index2 = row * map2.width + col;
30374
30369
  if (col > 0 && col < map2.width && map2.map[index2 - 1] == map2.map[index2]) {
30375
30370
  const pos = map2.map[index2];
30376
30371
  const cell = table.nodeAt(pos);
30377
- tr2.setNodeMarkup(
30378
- tr2.mapping.map(tableStart + pos),
30379
- null,
30380
- addColSpan(cell.attrs, col - map2.colCount(pos))
30381
- );
30372
+ tr2.setNodeMarkup(tr2.mapping.map(tableStart + pos), null, addColSpan(cell.attrs, col - map2.colCount(pos)));
30382
30373
  row += cell.attrs.rowspan - 1;
30383
30374
  } else {
30384
30375
  const type = refColumn == null ? tableNodeTypes(table.type.schema).cell : table.nodeAt(map2.map[index2 + refColumn]).type;
@@ -30411,13 +30402,8 @@ function removeColumn(tr2, { map: map2, table, tableStart }, col) {
30411
30402
  const pos = map2.map[index2];
30412
30403
  const cell = table.nodeAt(pos);
30413
30404
  const attrs = cell.attrs;
30414
- if (col > 0 && map2.map[index2 - 1] == pos || col < map2.width - 1 && map2.map[index2 + 1] == pos) {
30415
- tr2.setNodeMarkup(
30416
- tr2.mapping.slice(mapStart).map(tableStart + pos),
30417
- null,
30418
- removeColSpan(attrs, col - map2.colCount(pos))
30419
- );
30420
- } else {
30405
+ if (col > 0 && map2.map[index2 - 1] == pos || col < map2.width - 1 && map2.map[index2 + 1] == pos) tr2.setNodeMarkup(tr2.mapping.slice(mapStart).map(tableStart + pos), null, removeColSpan(attrs, col - map2.colCount(pos)));
30406
+ else {
30421
30407
  const start = tr2.mapping.slice(mapStart).map(tableStart + pos);
30422
30408
  tr2.delete(start, start + cell.nodeSize);
30423
30409
  }
@@ -30434,9 +30420,7 @@ function deleteColumn(state2, dispatch) {
30434
30420
  removeColumn(tr2, rect, i);
30435
30421
  if (i == rect.left) break;
30436
30422
  const table = rect.tableStart ? tr2.doc.nodeAt(rect.tableStart - 1) : tr2.doc;
30437
- if (!table) {
30438
- throw RangeError("No table found");
30439
- }
30423
+ if (!table) throw new RangeError("No table found");
30440
30424
  rect.table = table;
30441
30425
  rect.map = TableMap.get(table);
30442
30426
  }
@@ -30445,35 +30429,30 @@ function deleteColumn(state2, dispatch) {
30445
30429
  return true;
30446
30430
  }
30447
30431
  function rowIsHeader(map2, table, row) {
30448
- var _a2;
30432
+ var _table$nodeAt;
30449
30433
  const headerCell = tableNodeTypes(table.type.schema).header_cell;
30450
- for (let col = 0; col < map2.width; col++)
30451
- if (((_a2 = table.nodeAt(map2.map[col + row * map2.width])) == null ? void 0 : _a2.type) != headerCell)
30452
- return false;
30434
+ for (let col = 0; col < map2.width; col++) if (((_table$nodeAt = table.nodeAt(map2.map[col + row * map2.width])) === null || _table$nodeAt === void 0 ? void 0 : _table$nodeAt.type) != headerCell) return false;
30453
30435
  return true;
30454
30436
  }
30455
30437
  function addRow(tr2, { map: map2, tableStart, table }, row) {
30456
- var _a2;
30457
30438
  let rowPos = tableStart;
30458
30439
  for (let i = 0; i < row; i++) rowPos += table.child(i).nodeSize;
30459
30440
  const cells = [];
30460
30441
  let refRow = row > 0 ? -1 : 0;
30461
- if (rowIsHeader(map2, table, row + refRow))
30462
- refRow = row == 0 || row == map2.height ? null : 0;
30463
- for (let col = 0, index2 = map2.width * row; col < map2.width; col++, index2++) {
30464
- if (row > 0 && row < map2.height && map2.map[index2] == map2.map[index2 - map2.width]) {
30465
- const pos = map2.map[index2];
30466
- const attrs = table.nodeAt(pos).attrs;
30467
- tr2.setNodeMarkup(tableStart + pos, null, {
30468
- ...attrs,
30469
- rowspan: attrs.rowspan + 1
30470
- });
30471
- col += attrs.colspan - 1;
30472
- } else {
30473
- const type = refRow == null ? tableNodeTypes(table.type.schema).cell : (_a2 = table.nodeAt(map2.map[index2 + refRow * map2.width])) == null ? void 0 : _a2.type;
30474
- const node = type == null ? void 0 : type.createAndFill();
30475
- if (node) cells.push(node);
30476
- }
30442
+ if (rowIsHeader(map2, table, row + refRow)) refRow = row == 0 || row == map2.height ? null : 0;
30443
+ for (let col = 0, index2 = map2.width * row; col < map2.width; col++, index2++) if (row > 0 && row < map2.height && map2.map[index2] == map2.map[index2 - map2.width]) {
30444
+ const pos = map2.map[index2];
30445
+ const attrs = table.nodeAt(pos).attrs;
30446
+ tr2.setNodeMarkup(tableStart + pos, null, {
30447
+ ...attrs,
30448
+ rowspan: attrs.rowspan + 1
30449
+ });
30450
+ col += attrs.colspan - 1;
30451
+ } else {
30452
+ var _table$nodeAt2;
30453
+ const type = refRow == null ? tableNodeTypes(table.type.schema).cell : (_table$nodeAt2 = table.nodeAt(map2.map[index2 + refRow * map2.width])) === null || _table$nodeAt2 === void 0 ? void 0 : _table$nodeAt2.type;
30454
+ const node = type === null || type === void 0 ? void 0 : type.createAndFill();
30455
+ if (node) cells.push(node);
30477
30456
  }
30478
30457
  tr2.insert(rowPos, tableNodeTypes(table.type.schema).row.create(null, cells));
30479
30458
  return tr2;
@@ -30515,10 +30494,10 @@ function removeRow(tr2, { map: map2, table, tableStart }, row) {
30515
30494
  } else if (row < map2.height && pos == map2.map[index2 + map2.width]) {
30516
30495
  const cell = table.nodeAt(pos);
30517
30496
  const attrs = cell.attrs;
30518
- const copy2 = cell.type.create(
30519
- { ...attrs, rowspan: cell.attrs.rowspan - 1 },
30520
- cell.content
30521
- );
30497
+ const copy2 = cell.type.create({
30498
+ ...attrs,
30499
+ rowspan: cell.attrs.rowspan - 1
30500
+ }, cell.content);
30522
30501
  const newPos = map2.positionAt(row + 1, col, table);
30523
30502
  tr2.insert(tr2.mapping.slice(mapFrom).map(tableStart + newPos), copy2);
30524
30503
  col += attrs.colspan - 1;
@@ -30534,9 +30513,7 @@ function deleteRow(state2, dispatch) {
30534
30513
  removeRow(tr2, rect, i);
30535
30514
  if (i == rect.top) break;
30536
30515
  const table = rect.tableStart ? tr2.doc.nodeAt(rect.tableStart - 1) : tr2.doc;
30537
- if (!table) {
30538
- throw RangeError("No table found");
30539
- }
30516
+ if (!table) throw new RangeError("No table found");
30540
30517
  rect.table = table;
30541
30518
  rect.map = TableMap.get(rect.table);
30542
30519
  }
@@ -30552,14 +30529,12 @@ function cellsOverlapRectangle({ width, height, map: map2 }, rect) {
30552
30529
  let indexTop = rect.top * width + rect.left, indexLeft = indexTop;
30553
30530
  let indexBottom = (rect.bottom - 1) * width + rect.left, indexRight = indexTop + (rect.right - rect.left - 1);
30554
30531
  for (let i = rect.top; i < rect.bottom; i++) {
30555
- if (rect.left > 0 && map2[indexLeft] == map2[indexLeft - 1] || rect.right < width && map2[indexRight] == map2[indexRight + 1])
30556
- return true;
30532
+ if (rect.left > 0 && map2[indexLeft] == map2[indexLeft - 1] || rect.right < width && map2[indexRight] == map2[indexRight + 1]) return true;
30557
30533
  indexLeft += width;
30558
30534
  indexRight += width;
30559
30535
  }
30560
30536
  for (let i = rect.left; i < rect.right; i++) {
30561
- if (rect.top > 0 && map2[indexTop] == map2[indexTop - width] || rect.bottom < height && map2[indexBottom] == map2[indexBottom + width])
30562
- return true;
30537
+ if (rect.top > 0 && map2[indexTop] == map2[indexTop - width] || rect.bottom < height && map2[indexBottom] == map2[indexBottom + width]) return true;
30563
30538
  indexTop++;
30564
30539
  indexBottom++;
30565
30540
  }
@@ -30567,8 +30542,7 @@ function cellsOverlapRectangle({ width, height, map: map2 }, rect) {
30567
30542
  }
30568
30543
  function mergeCells(state2, dispatch) {
30569
30544
  const sel = state2.selection;
30570
- if (!(sel instanceof CellSelection) || sel.$anchorCell.pos == sel.$headCell.pos)
30571
- return false;
30545
+ if (!(sel instanceof CellSelection) || sel.$anchorCell.pos == sel.$headCell.pos) return false;
30572
30546
  const rect = selectedRect(state2), { map: map2 } = rect;
30573
30547
  if (cellsOverlapRectangle(map2, rect)) return false;
30574
30548
  if (dispatch) {
@@ -30577,41 +30551,31 @@ function mergeCells(state2, dispatch) {
30577
30551
  let content = Fragment.empty;
30578
30552
  let mergedPos;
30579
30553
  let mergedCell;
30580
- for (let row = rect.top; row < rect.bottom; row++) {
30581
- for (let col = rect.left; col < rect.right; col++) {
30582
- const cellPos = map2.map[row * map2.width + col];
30583
- const cell = rect.table.nodeAt(cellPos);
30584
- if (seen[cellPos] || !cell) continue;
30585
- seen[cellPos] = true;
30586
- if (mergedPos == null) {
30587
- mergedPos = cellPos;
30588
- mergedCell = cell;
30589
- } else {
30590
- if (!isEmpty(cell)) content = content.append(cell.content);
30591
- const mapped = tr2.mapping.map(cellPos + rect.tableStart);
30592
- tr2.delete(mapped, mapped + cell.nodeSize);
30593
- }
30554
+ for (let row = rect.top; row < rect.bottom; row++) for (let col = rect.left; col < rect.right; col++) {
30555
+ const cellPos = map2.map[row * map2.width + col];
30556
+ const cell = rect.table.nodeAt(cellPos);
30557
+ if (seen[cellPos] || !cell) continue;
30558
+ seen[cellPos] = true;
30559
+ if (mergedPos == null) {
30560
+ mergedPos = cellPos;
30561
+ mergedCell = cell;
30562
+ } else {
30563
+ if (!isEmpty(cell)) content = content.append(cell.content);
30564
+ const mapped = tr2.mapping.map(cellPos + rect.tableStart);
30565
+ tr2.delete(mapped, mapped + cell.nodeSize);
30594
30566
  }
30595
30567
  }
30596
- if (mergedPos == null || mergedCell == null) {
30597
- return true;
30598
- }
30568
+ if (mergedPos == null || mergedCell == null) return true;
30599
30569
  tr2.setNodeMarkup(mergedPos + rect.tableStart, null, {
30600
- ...addColSpan(
30601
- mergedCell.attrs,
30602
- mergedCell.attrs.colspan,
30603
- rect.right - rect.left - mergedCell.attrs.colspan
30604
- ),
30570
+ ...addColSpan(mergedCell.attrs, mergedCell.attrs.colspan, rect.right - rect.left - mergedCell.attrs.colspan),
30605
30571
  rowspan: rect.bottom - rect.top
30606
30572
  });
30607
- if (content.size) {
30573
+ if (content.size > 0) {
30608
30574
  const end = mergedPos + 1 + mergedCell.content.size;
30609
30575
  const start = isEmpty(mergedCell) ? mergedPos + 1 : end;
30610
30576
  tr2.replaceWith(start + rect.tableStart, end + rect.tableStart, content);
30611
30577
  }
30612
- tr2.setSelection(
30613
- new CellSelection(tr2.doc.resolve(mergedPos + rect.tableStart))
30614
- );
30578
+ tr2.setSelection(new CellSelection(tr2.doc.resolve(mergedPos + rect.tableStart)));
30615
30579
  dispatch(tr2);
30616
30580
  }
30617
30581
  return true;
@@ -30624,63 +30588,57 @@ function splitCell(state2, dispatch) {
30624
30588
  }
30625
30589
  function splitCellWithType(getCellType) {
30626
30590
  return (state2, dispatch) => {
30627
- var _a2;
30628
30591
  const sel = state2.selection;
30629
30592
  let cellNode;
30630
30593
  let cellPos;
30631
30594
  if (!(sel instanceof CellSelection)) {
30595
+ var _cellAround;
30632
30596
  cellNode = cellWrapping(sel.$from);
30633
30597
  if (!cellNode) return false;
30634
- cellPos = (_a2 = cellAround(sel.$from)) == null ? void 0 : _a2.pos;
30598
+ cellPos = (_cellAround = cellAround(sel.$from)) === null || _cellAround === void 0 ? void 0 : _cellAround.pos;
30635
30599
  } else {
30636
30600
  if (sel.$anchorCell.pos != sel.$headCell.pos) return false;
30637
30601
  cellNode = sel.$anchorCell.nodeAfter;
30638
30602
  cellPos = sel.$anchorCell.pos;
30639
30603
  }
30640
- if (cellNode == null || cellPos == null) {
30641
- return false;
30642
- }
30643
- if (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) {
30644
- return false;
30645
- }
30604
+ if (cellNode == null || cellPos == null) return false;
30605
+ if (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) return false;
30646
30606
  if (dispatch) {
30647
30607
  let baseAttrs = cellNode.attrs;
30648
30608
  const attrs = [];
30649
30609
  const colwidth = baseAttrs.colwidth;
30650
- if (baseAttrs.rowspan > 1) baseAttrs = { ...baseAttrs, rowspan: 1 };
30651
- if (baseAttrs.colspan > 1) baseAttrs = { ...baseAttrs, colspan: 1 };
30610
+ if (baseAttrs.rowspan > 1) baseAttrs = {
30611
+ ...baseAttrs,
30612
+ rowspan: 1
30613
+ };
30614
+ if (baseAttrs.colspan > 1) baseAttrs = {
30615
+ ...baseAttrs,
30616
+ colspan: 1
30617
+ };
30652
30618
  const rect = selectedRect(state2), tr2 = state2.tr;
30653
- for (let i = 0; i < rect.right - rect.left; i++)
30654
- attrs.push(
30655
- colwidth ? {
30656
- ...baseAttrs,
30657
- colwidth: colwidth && colwidth[i] ? [colwidth[i]] : null
30658
- } : baseAttrs
30659
- );
30619
+ for (let i = 0; i < rect.right - rect.left; i++) attrs.push(colwidth ? {
30620
+ ...baseAttrs,
30621
+ colwidth: colwidth && colwidth[i] ? [colwidth[i]] : null
30622
+ } : baseAttrs);
30660
30623
  let lastCell;
30661
30624
  for (let row = rect.top; row < rect.bottom; row++) {
30662
30625
  let pos = rect.map.positionAt(row, rect.left, rect.table);
30663
30626
  if (row == rect.top) pos += cellNode.nodeSize;
30664
30627
  for (let col = rect.left, i = 0; col < rect.right; col++, i++) {
30665
30628
  if (col == rect.left && row == rect.top) continue;
30666
- tr2.insert(
30667
- lastCell = tr2.mapping.map(pos + rect.tableStart, 1),
30668
- getCellType({ node: cellNode, row, col }).createAndFill(attrs[i])
30669
- );
30670
- }
30671
- }
30672
- tr2.setNodeMarkup(
30673
- cellPos,
30674
- getCellType({ node: cellNode, row: rect.top, col: rect.left }),
30675
- attrs[0]
30676
- );
30677
- if (sel instanceof CellSelection)
30678
- tr2.setSelection(
30679
- new CellSelection(
30680
- tr2.doc.resolve(sel.$anchorCell.pos),
30681
- lastCell ? tr2.doc.resolve(lastCell) : void 0
30682
- )
30683
- );
30629
+ tr2.insert(lastCell = tr2.mapping.map(pos + rect.tableStart, 1), getCellType({
30630
+ node: cellNode,
30631
+ row,
30632
+ col
30633
+ }).createAndFill(attrs[i]));
30634
+ }
30635
+ }
30636
+ tr2.setNodeMarkup(cellPos, getCellType({
30637
+ node: cellNode,
30638
+ row: rect.top,
30639
+ col: rect.left
30640
+ }), attrs[0]);
30641
+ if (sel instanceof CellSelection) tr2.setSelection(new CellSelection(tr2.doc.resolve(sel.$anchorCell.pos), lastCell ? tr2.doc.resolve(lastCell) : void 0));
30684
30642
  dispatch(tr2);
30685
30643
  }
30686
30644
  return true;
@@ -30693,19 +30651,16 @@ function setCellAttr(name, value) {
30693
30651
  if ($cell.nodeAfter.attrs[name] === value) return false;
30694
30652
  if (dispatch) {
30695
30653
  const tr2 = state2.tr;
30696
- if (state2.selection instanceof CellSelection)
30697
- state2.selection.forEachCell((node, pos) => {
30698
- if (node.attrs[name] !== value)
30699
- tr2.setNodeMarkup(pos, null, {
30700
- ...node.attrs,
30701
- [name]: value
30702
- });
30703
- });
30704
- else
30705
- tr2.setNodeMarkup($cell.pos, null, {
30706
- ...$cell.nodeAfter.attrs,
30654
+ if (state2.selection instanceof CellSelection) state2.selection.forEachCell((node, pos) => {
30655
+ if (node.attrs[name] !== value) tr2.setNodeMarkup(pos, null, {
30656
+ ...node.attrs,
30707
30657
  [name]: value
30708
30658
  });
30659
+ });
30660
+ else tr2.setNodeMarkup($cell.pos, null, {
30661
+ ...$cell.nodeAfter.attrs,
30662
+ [name]: value
30663
+ });
30709
30664
  dispatch(tr2);
30710
30665
  }
30711
30666
  return true;
@@ -30717,34 +30672,20 @@ function deprecated_toggleHeader(type) {
30717
30672
  if (dispatch) {
30718
30673
  const types = tableNodeTypes(state2.schema);
30719
30674
  const rect = selectedRect(state2), tr2 = state2.tr;
30720
- const cells = rect.map.cellsInRect(
30721
- type == "column" ? {
30722
- left: rect.left,
30723
- top: 0,
30724
- right: rect.right,
30725
- bottom: rect.map.height
30726
- } : type == "row" ? {
30727
- left: 0,
30728
- top: rect.top,
30729
- right: rect.map.width,
30730
- bottom: rect.bottom
30731
- } : rect
30732
- );
30675
+ const cells = rect.map.cellsInRect(type == "column" ? {
30676
+ left: rect.left,
30677
+ top: 0,
30678
+ right: rect.right,
30679
+ bottom: rect.map.height
30680
+ } : type == "row" ? {
30681
+ left: 0,
30682
+ top: rect.top,
30683
+ right: rect.map.width,
30684
+ bottom: rect.bottom
30685
+ } : rect);
30733
30686
  const nodes = cells.map((pos) => rect.table.nodeAt(pos));
30734
- for (let i = 0; i < cells.length; i++)
30735
- if (nodes[i].type == types.header_cell)
30736
- tr2.setNodeMarkup(
30737
- rect.tableStart + cells[i],
30738
- types.cell,
30739
- nodes[i].attrs
30740
- );
30741
- if (tr2.steps.length == 0)
30742
- for (let i = 0; i < cells.length; i++)
30743
- tr2.setNodeMarkup(
30744
- rect.tableStart + cells[i],
30745
- types.header_cell,
30746
- nodes[i].attrs
30747
- );
30687
+ for (let i = 0; i < cells.length; i++) if (nodes[i].type == types.header_cell) tr2.setNodeMarkup(rect.tableStart + cells[i], types.cell, nodes[i].attrs);
30688
+ if (tr2.steps.length === 0) for (let i = 0; i < cells.length; i++) tr2.setNodeMarkup(rect.tableStart + cells[i], types.header_cell, nodes[i].attrs);
30748
30689
  dispatch(tr2);
30749
30690
  }
30750
30691
  return true;
@@ -30759,9 +30700,7 @@ function isHeaderEnabledByType(type, rect, types) {
30759
30700
  });
30760
30701
  for (let i = 0; i < cellPositions.length; i++) {
30761
30702
  const cell = rect.table.nodeAt(cellPositions[i]);
30762
- if (cell && cell.type !== types.header_cell) {
30763
- return false;
30764
- }
30703
+ if (cell && cell.type !== types.header_cell) return false;
30765
30704
  }
30766
30705
  return true;
30767
30706
  }
@@ -30774,13 +30713,8 @@ function toggleHeader(type, options) {
30774
30713
  const types = tableNodeTypes(state2.schema);
30775
30714
  const rect = selectedRect(state2), tr2 = state2.tr;
30776
30715
  const isHeaderRowEnabled = isHeaderEnabledByType("row", rect, types);
30777
- const isHeaderColumnEnabled = isHeaderEnabledByType(
30778
- "column",
30779
- rect,
30780
- types
30781
- );
30782
- const isHeaderEnabled = type === "column" ? isHeaderRowEnabled : type === "row" ? isHeaderColumnEnabled : false;
30783
- const selectionStartsAt = isHeaderEnabled ? 1 : 0;
30716
+ const isHeaderColumnEnabled = isHeaderEnabledByType("column", rect, types);
30717
+ const selectionStartsAt = (type === "column" ? isHeaderRowEnabled : type === "row" ? isHeaderColumnEnabled : false) ? 1 : 0;
30784
30718
  const cellsRect = type == "column" ? {
30785
30719
  left: 0,
30786
30720
  top: selectionStartsAt,
@@ -30796,24 +30730,16 @@ function toggleHeader(type, options) {
30796
30730
  rect.map.cellsInRect(cellsRect).forEach((relativeCellPos) => {
30797
30731
  const cellPos = relativeCellPos + rect.tableStart;
30798
30732
  const cell = tr2.doc.nodeAt(cellPos);
30799
- if (cell) {
30800
- tr2.setNodeMarkup(cellPos, newType, cell.attrs);
30801
- }
30733
+ if (cell) tr2.setNodeMarkup(cellPos, newType, cell.attrs);
30802
30734
  });
30803
30735
  dispatch(tr2);
30804
30736
  }
30805
30737
  return true;
30806
30738
  };
30807
30739
  }
30808
- toggleHeader("row", {
30809
- useDeprecatedLogic: true
30810
- });
30811
- toggleHeader("column", {
30812
- useDeprecatedLogic: true
30813
- });
30814
- var toggleHeaderCell = toggleHeader("cell", {
30815
- useDeprecatedLogic: true
30816
- });
30740
+ toggleHeader("row", { useDeprecatedLogic: true });
30741
+ toggleHeader("column", { useDeprecatedLogic: true });
30742
+ const toggleHeaderCell = toggleHeader("cell", { useDeprecatedLogic: true });
30817
30743
  function findNextCell($cell, dir) {
30818
30744
  if (dir < 0) {
30819
30745
  const before = $cell.nodeBefore;
@@ -30821,15 +30747,11 @@ function findNextCell($cell, dir) {
30821
30747
  for (let row = $cell.index(-1) - 1, rowEnd = $cell.before(); row >= 0; row--) {
30822
30748
  const rowNode = $cell.node(-1).child(row);
30823
30749
  const lastChild = rowNode.lastChild;
30824
- if (lastChild) {
30825
- return rowEnd - 1 - lastChild.nodeSize;
30826
- }
30750
+ if (lastChild) return rowEnd - 1 - lastChild.nodeSize;
30827
30751
  rowEnd -= rowNode.nodeSize;
30828
30752
  }
30829
30753
  } else {
30830
- if ($cell.index() < $cell.parent.childCount - 1) {
30831
- return $cell.pos + $cell.nodeAfter.nodeSize;
30832
- }
30754
+ if ($cell.index() < $cell.parent.childCount - 1) return $cell.pos + $cell.nodeAfter.nodeSize;
30833
30755
  const table = $cell.node(-1);
30834
30756
  for (let row = $cell.indexAfter(-1), rowStart = $cell.after(); row < table.childCount; row++) {
30835
30757
  const rowNode = table.child(row);
@@ -30846,24 +30768,16 @@ function goToNextCell(direction) {
30846
30768
  if (cell == null) return false;
30847
30769
  if (dispatch) {
30848
30770
  const $cell = state2.doc.resolve(cell);
30849
- dispatch(
30850
- state2.tr.setSelection(TextSelection.between($cell, moveCellForward($cell))).scrollIntoView()
30851
- );
30771
+ dispatch(state2.tr.setSelection(TextSelection.between($cell, moveCellForward($cell))).scrollIntoView());
30852
30772
  }
30853
30773
  return true;
30854
30774
  };
30855
30775
  }
30856
30776
  function deleteTable(state2, dispatch) {
30857
30777
  const $pos = state2.selection.$anchor;
30858
- for (let d2 = $pos.depth; d2 > 0; d2--) {
30859
- const node = $pos.node(d2);
30860
- if (node.type.spec.tableRole == "table") {
30861
- if (dispatch)
30862
- dispatch(
30863
- state2.tr.delete($pos.before(d2), $pos.after(d2)).scrollIntoView()
30864
- );
30865
- return true;
30866
- }
30778
+ for (let d2 = $pos.depth; d2 > 0; d2--) if ($pos.node(d2).type.spec.tableRole == "table") {
30779
+ if (dispatch) dispatch(state2.tr.delete($pos.before(d2), $pos.after(d2)).scrollIntoView());
30780
+ return true;
30867
30781
  }
30868
30782
  return false;
30869
30783
  }
@@ -30874,19 +30788,14 @@ function deleteCellSelection(state2, dispatch) {
30874
30788
  const tr2 = state2.tr;
30875
30789
  const baseContent = tableNodeTypes(state2.schema).cell.createAndFill().content;
30876
30790
  sel.forEachCell((cell, pos) => {
30877
- if (!cell.content.eq(baseContent))
30878
- tr2.replace(
30879
- tr2.mapping.map(pos + 1),
30880
- tr2.mapping.map(pos + cell.nodeSize - 1),
30881
- new Slice(baseContent, 0, 0)
30882
- );
30791
+ if (!cell.content.eq(baseContent)) tr2.replace(tr2.mapping.map(pos + 1), tr2.mapping.map(pos + cell.nodeSize - 1), new Slice(baseContent, 0, 0));
30883
30792
  });
30884
30793
  if (tr2.docChanged) dispatch(tr2);
30885
30794
  }
30886
30795
  return true;
30887
30796
  }
30888
30797
  function pastedCells(slice2) {
30889
- if (!slice2.size) return null;
30798
+ if (slice2.size === 0) return null;
30890
30799
  let { content, openStart, openEnd } = slice2;
30891
30800
  while (content.childCount == 1 && (openStart > 0 && openEnd > 0 || content.child(0).type.spec.tableRole == "table")) {
30892
30801
  openStart--;
@@ -30896,28 +30805,15 @@ function pastedCells(slice2) {
30896
30805
  const first2 = content.child(0);
30897
30806
  const role = first2.type.spec.tableRole;
30898
30807
  const schema = first2.type.schema, rows = [];
30899
- if (role == "row") {
30900
- for (let i = 0; i < content.childCount; i++) {
30901
- let cells = content.child(i).content;
30902
- const left = i ? 0 : Math.max(0, openStart - 1);
30903
- const right = i < content.childCount - 1 ? 0 : Math.max(0, openEnd - 1);
30904
- if (left || right)
30905
- cells = fitSlice(
30906
- tableNodeTypes(schema).row,
30907
- new Slice(cells, left, right)
30908
- ).content;
30909
- rows.push(cells);
30910
- }
30911
- } else if (role == "cell" || role == "header_cell") {
30912
- rows.push(
30913
- openStart || openEnd ? fitSlice(
30914
- tableNodeTypes(schema).row,
30915
- new Slice(content, openStart, openEnd)
30916
- ).content : content
30917
- );
30918
- } else {
30919
- return null;
30808
+ if (role == "row") for (let i = 0; i < content.childCount; i++) {
30809
+ let cells = content.child(i).content;
30810
+ const left = i ? 0 : Math.max(0, openStart - 1);
30811
+ const right = i < content.childCount - 1 ? 0 : Math.max(0, openEnd - 1);
30812
+ if (left || right) cells = fitSlice(tableNodeTypes(schema).row, new Slice(cells, left, right)).content;
30813
+ rows.push(cells);
30920
30814
  }
30815
+ else if (role == "cell" || role == "header_cell") rows.push(openStart || openEnd ? fitSlice(tableNodeTypes(schema).row, new Slice(content, openStart, openEnd)).content : content);
30816
+ else return null;
30921
30817
  return ensureRectangular(schema, rows);
30922
30818
  }
30923
30819
  function ensureRectangular(schema, rows) {
@@ -30926,8 +30822,7 @@ function ensureRectangular(schema, rows) {
30926
30822
  const row = rows[i];
30927
30823
  for (let j2 = row.childCount - 1; j2 >= 0; j2--) {
30928
30824
  const { rowspan, colspan } = row.child(j2).attrs;
30929
- for (let r2 = i; r2 < i + rowspan; r2++)
30930
- widths[r2] = (widths[r2] || 0) + colspan;
30825
+ for (let r2 = i; r2 < i + rowspan; r2++) widths[r2] = (widths[r2] || 0) + colspan;
30931
30826
  }
30932
30827
  }
30933
30828
  let width = 0;
@@ -30937,18 +30832,19 @@ function ensureRectangular(schema, rows) {
30937
30832
  if (widths[r2] < width) {
30938
30833
  const empty2 = tableNodeTypes(schema).cell.createAndFill();
30939
30834
  const cells = [];
30940
- for (let i = widths[r2]; i < width; i++) {
30941
- cells.push(empty2);
30942
- }
30835
+ for (let i = widths[r2]; i < width; i++) cells.push(empty2);
30943
30836
  rows[r2] = rows[r2].append(Fragment.from(cells));
30944
30837
  }
30945
30838
  }
30946
- return { height: rows.length, width, rows };
30839
+ return {
30840
+ height: rows.length,
30841
+ width,
30842
+ rows
30843
+ };
30947
30844
  }
30948
30845
  function fitSlice(nodeType, slice2) {
30949
30846
  const node = nodeType.createAndFill();
30950
- const tr2 = new Transform(node).replace(0, node.content.size, slice2);
30951
- return tr2.doc;
30847
+ return new Transform(node).replace(0, node.content.size, slice2).doc;
30952
30848
  }
30953
30849
  function clipCells({ width, height, rows }, newWidth, newHeight) {
30954
30850
  if (width != newWidth) {
@@ -30958,19 +30854,10 @@ function clipCells({ width, height, rows }, newWidth, newHeight) {
30958
30854
  const frag = rows[row], cells = [];
30959
30855
  for (let col = added[row] || 0, i = 0; col < newWidth; i++) {
30960
30856
  let cell = frag.child(i % frag.childCount);
30961
- if (col + cell.attrs.colspan > newWidth)
30962
- cell = cell.type.createChecked(
30963
- removeColSpan(
30964
- cell.attrs,
30965
- cell.attrs.colspan,
30966
- col + cell.attrs.colspan - newWidth
30967
- ),
30968
- cell.content
30969
- );
30857
+ if (col + cell.attrs.colspan > newWidth) cell = cell.type.createChecked(removeColSpan(cell.attrs, cell.attrs.colspan, col + cell.attrs.colspan - newWidth), cell.content);
30970
30858
  cells.push(cell);
30971
30859
  col += cell.attrs.colspan;
30972
- for (let j2 = 1; j2 < cell.attrs.rowspan; j2++)
30973
- added[row + j2] = (added[row + j2] || 0) + cell.attrs.colspan;
30860
+ for (let j2 = 1; j2 < cell.attrs.rowspan; j2++) added[row + j2] = (added[row + j2] || 0) + cell.attrs.colspan;
30974
30861
  }
30975
30862
  newRows.push(Fragment.from(cells));
30976
30863
  }
@@ -30983,14 +30870,10 @@ function clipCells({ width, height, rows }, newWidth, newHeight) {
30983
30870
  const cells = [], source2 = rows[i % height];
30984
30871
  for (let j2 = 0; j2 < source2.childCount; j2++) {
30985
30872
  let cell = source2.child(j2);
30986
- if (row + cell.attrs.rowspan > newHeight)
30987
- cell = cell.type.create(
30988
- {
30989
- ...cell.attrs,
30990
- rowspan: Math.max(1, newHeight - cell.attrs.rowspan)
30991
- },
30992
- cell.content
30993
- );
30873
+ if (row + cell.attrs.rowspan > newHeight) cell = cell.type.create({
30874
+ ...cell.attrs,
30875
+ rowspan: Math.max(1, newHeight - cell.attrs.rowspan)
30876
+ }, cell.content);
30994
30877
  cells.push(cell);
30995
30878
  }
30996
30879
  newRows.push(Fragment.from(cells));
@@ -30998,33 +30881,32 @@ function clipCells({ width, height, rows }, newWidth, newHeight) {
30998
30881
  rows = newRows;
30999
30882
  height = newHeight;
31000
30883
  }
31001
- return { width, height, rows };
30884
+ return {
30885
+ width,
30886
+ height,
30887
+ rows
30888
+ };
31002
30889
  }
31003
30890
  function growTable(tr2, map2, table, start, width, height, mapFrom) {
31004
30891
  const schema = tr2.doc.type.schema;
31005
30892
  const types = tableNodeTypes(schema);
31006
30893
  let empty2;
31007
30894
  let emptyHead;
31008
- if (width > map2.width) {
31009
- for (let row = 0, rowEnd = 0; row < map2.height; row++) {
31010
- const rowNode = table.child(row);
31011
- rowEnd += rowNode.nodeSize;
31012
- const cells = [];
31013
- let add;
31014
- if (rowNode.lastChild == null || rowNode.lastChild.type == types.cell)
31015
- add = empty2 || (empty2 = types.cell.createAndFill());
31016
- else add = emptyHead || (emptyHead = types.header_cell.createAndFill());
31017
- for (let i = map2.width; i < width; i++) cells.push(add);
31018
- tr2.insert(tr2.mapping.slice(mapFrom).map(rowEnd - 1 + start), cells);
31019
- }
30895
+ if (width > map2.width) for (let row = 0, rowEnd = 0; row < map2.height; row++) {
30896
+ const rowNode = table.child(row);
30897
+ rowEnd += rowNode.nodeSize;
30898
+ const cells = [];
30899
+ let add;
30900
+ if (rowNode.lastChild == null || rowNode.lastChild.type == types.cell) add = empty2 || (empty2 = types.cell.createAndFill());
30901
+ else add = emptyHead || (emptyHead = types.header_cell.createAndFill());
30902
+ for (let i = map2.width; i < width; i++) cells.push(add);
30903
+ tr2.insert(tr2.mapping.slice(mapFrom).map(rowEnd - 1 + start), cells);
31020
30904
  }
31021
30905
  if (height > map2.height) {
31022
30906
  const cells = [];
31023
- for (let i = 0, start2 = (map2.height - 1) * map2.width; i < Math.max(map2.width, width); i++) {
31024
- const header = i >= map2.width ? false : table.nodeAt(map2.map[start2 + i]).type == types.header_cell;
31025
- cells.push(
31026
- header ? emptyHead || (emptyHead = types.header_cell.createAndFill()) : empty2 || (empty2 = types.cell.createAndFill())
31027
- );
30907
+ for (let i = 0, start$1 = (map2.height - 1) * map2.width; i < Math.max(map2.width, width); i++) {
30908
+ const header = i >= map2.width ? false : table.nodeAt(map2.map[start$1 + i]).type == types.header_cell;
30909
+ cells.push(header ? emptyHead || (emptyHead = types.header_cell.createAndFill()) : empty2 || (empty2 = types.cell.createAndFill()));
31028
30910
  }
31029
30911
  const emptyRow = types.row.create(null, Fragment.from(cells)), rows = [];
31030
30912
  for (let i = map2.height; i < height; i++) rows.push(emptyRow);
@@ -31045,13 +30927,10 @@ function isolateHorizontal(tr2, map2, table, start, left, right, top, mapFrom) {
31045
30927
  ...cell.attrs,
31046
30928
  rowspan: top - cellTop
31047
30929
  });
31048
- tr2.insert(
31049
- tr2.mapping.slice(mapFrom).map(map2.positionAt(top, cellLeft, table)),
31050
- cell.type.createAndFill({
31051
- ...cell.attrs,
31052
- rowspan: cellTop + cell.attrs.rowspan - top
31053
- })
31054
- );
30930
+ tr2.insert(tr2.mapping.slice(mapFrom).map(map2.positionAt(top, cellLeft, table)), cell.type.createAndFill({
30931
+ ...cell.attrs,
30932
+ rowspan: cellTop + cell.attrs.rowspan - top
30933
+ }));
31055
30934
  col += cell.attrs.colspan - 1;
31056
30935
  }
31057
30936
  }
@@ -31067,21 +30946,8 @@ function isolateVertical(tr2, map2, table, start, top, bottom, left, mapFrom) {
31067
30946
  const cell = table.nodeAt(pos);
31068
30947
  const cellLeft = map2.colCount(pos);
31069
30948
  const updatePos = tr2.mapping.slice(mapFrom).map(pos + start);
31070
- tr2.setNodeMarkup(
31071
- updatePos,
31072
- null,
31073
- removeColSpan(
31074
- cell.attrs,
31075
- left - cellLeft,
31076
- cell.attrs.colspan - (left - cellLeft)
31077
- )
31078
- );
31079
- tr2.insert(
31080
- updatePos + cell.nodeSize,
31081
- cell.type.createAndFill(
31082
- removeColSpan(cell.attrs, 0, left - cellLeft)
31083
- )
31084
- );
30949
+ tr2.setNodeMarkup(updatePos, null, removeColSpan(cell.attrs, left - cellLeft, cell.attrs.colspan - (left - cellLeft)));
30950
+ tr2.insert(updatePos + cell.nodeSize, cell.type.createAndFill(removeColSpan(cell.attrs, 0, left - cellLeft)));
31085
30951
  row += cell.attrs.rowspan - 1;
31086
30952
  }
31087
30953
  }
@@ -31089,9 +30955,7 @@ function isolateVertical(tr2, map2, table, start, top, bottom, left, mapFrom) {
31089
30955
  }
31090
30956
  function insertCells(state2, dispatch, tableStart, rect, cells) {
31091
30957
  let table = tableStart ? state2.doc.nodeAt(tableStart - 1) : state2.doc;
31092
- if (!table) {
31093
- throw new Error("No table found");
31094
- }
30958
+ if (!table) throw new Error("No table found");
31095
30959
  let map2 = TableMap.get(table);
31096
30960
  const { top, left } = rect;
31097
30961
  const right = left + cells.width, bottom = top + cells.height;
@@ -31099,39 +30963,24 @@ function insertCells(state2, dispatch, tableStart, rect, cells) {
31099
30963
  let mapFrom = 0;
31100
30964
  function recomp() {
31101
30965
  table = tableStart ? tr2.doc.nodeAt(tableStart - 1) : tr2.doc;
31102
- if (!table) {
31103
- throw new Error("No table found");
31104
- }
30966
+ if (!table) throw new Error("No table found");
31105
30967
  map2 = TableMap.get(table);
31106
30968
  mapFrom = tr2.mapping.maps.length;
31107
30969
  }
31108
30970
  if (growTable(tr2, map2, table, tableStart, right, bottom, mapFrom)) recomp();
31109
- if (isolateHorizontal(tr2, map2, table, tableStart, left, right, top, mapFrom))
31110
- recomp();
31111
- if (isolateHorizontal(tr2, map2, table, tableStart, left, right, bottom, mapFrom))
31112
- recomp();
31113
- if (isolateVertical(tr2, map2, table, tableStart, top, bottom, left, mapFrom))
31114
- recomp();
31115
- if (isolateVertical(tr2, map2, table, tableStart, top, bottom, right, mapFrom))
31116
- recomp();
30971
+ if (isolateHorizontal(tr2, map2, table, tableStart, left, right, top, mapFrom)) recomp();
30972
+ if (isolateHorizontal(tr2, map2, table, tableStart, left, right, bottom, mapFrom)) recomp();
30973
+ if (isolateVertical(tr2, map2, table, tableStart, top, bottom, left, mapFrom)) recomp();
30974
+ if (isolateVertical(tr2, map2, table, tableStart, top, bottom, right, mapFrom)) recomp();
31117
30975
  for (let row = top; row < bottom; row++) {
31118
30976
  const from2 = map2.positionAt(row, left, table), to = map2.positionAt(row, right, table);
31119
- tr2.replace(
31120
- tr2.mapping.slice(mapFrom).map(from2 + tableStart),
31121
- tr2.mapping.slice(mapFrom).map(to + tableStart),
31122
- new Slice(cells.rows[row - top], 0, 0)
31123
- );
30977
+ tr2.replace(tr2.mapping.slice(mapFrom).map(from2 + tableStart), tr2.mapping.slice(mapFrom).map(to + tableStart), new Slice(cells.rows[row - top], 0, 0));
31124
30978
  }
31125
30979
  recomp();
31126
- tr2.setSelection(
31127
- new CellSelection(
31128
- tr2.doc.resolve(tableStart + map2.positionAt(top, left, table)),
31129
- tr2.doc.resolve(tableStart + map2.positionAt(bottom - 1, right - 1, table))
31130
- )
31131
- );
30980
+ tr2.setSelection(new CellSelection(tr2.doc.resolve(tableStart + map2.positionAt(top, left, table)), tr2.doc.resolve(tableStart + map2.positionAt(bottom - 1, right - 1, table))));
31132
30981
  dispatch(tr2);
31133
30982
  }
31134
- var handleKeyDown = keydownHandler({
30983
+ const handleKeyDown = keydownHandler({
31135
30984
  ArrowLeft: arrow("horiz", -1),
31136
30985
  ArrowRight: arrow("horiz", 1),
31137
30986
  ArrowUp: arrow("vert", -1),
@@ -31154,29 +31003,17 @@ function arrow(axis, dir) {
31154
31003
  return (state2, dispatch, view) => {
31155
31004
  if (!view) return false;
31156
31005
  const sel = state2.selection;
31157
- if (sel instanceof CellSelection) {
31158
- return maybeSetSelection(
31159
- state2,
31160
- dispatch,
31161
- Selection.near(sel.$headCell, dir)
31162
- );
31163
- }
31006
+ if (sel instanceof CellSelection) return maybeSetSelection(state2, dispatch, Selection.near(sel.$headCell, dir));
31164
31007
  if (axis != "horiz" && !sel.empty) return false;
31165
31008
  const end = atEndOfCell(view, axis, dir);
31166
31009
  if (end == null) return false;
31167
- if (axis == "horiz") {
31168
- return maybeSetSelection(
31169
- state2,
31170
- dispatch,
31171
- Selection.near(state2.doc.resolve(sel.head + dir), dir)
31172
- );
31173
- } else {
31010
+ if (axis == "horiz") return maybeSetSelection(state2, dispatch, Selection.near(state2.doc.resolve(sel.head + dir), dir));
31011
+ else {
31174
31012
  const $cell = state2.doc.resolve(end);
31175
31013
  const $next = nextCell($cell, axis, dir);
31176
31014
  let newSel;
31177
31015
  if ($next) newSel = Selection.near($next, 1);
31178
- else if (dir < 0)
31179
- newSel = Selection.near(state2.doc.resolve($cell.before(-1)), -1);
31016
+ else if (dir < 0) newSel = Selection.near(state2.doc.resolve($cell.before(-1)), -1);
31180
31017
  else newSel = Selection.near(state2.doc.resolve($cell.after(-1)), 1);
31181
31018
  return maybeSetSelection(state2, dispatch, newSel);
31182
31019
  }
@@ -31187,20 +31024,15 @@ function shiftArrow(axis, dir) {
31187
31024
  if (!view) return false;
31188
31025
  const sel = state2.selection;
31189
31026
  let cellSel;
31190
- if (sel instanceof CellSelection) {
31191
- cellSel = sel;
31192
- } else {
31027
+ if (sel instanceof CellSelection) cellSel = sel;
31028
+ else {
31193
31029
  const end = atEndOfCell(view, axis, dir);
31194
31030
  if (end == null) return false;
31195
31031
  cellSel = new CellSelection(state2.doc.resolve(end));
31196
31032
  }
31197
31033
  const $head = nextCell(cellSel.$headCell, axis, dir);
31198
31034
  if (!$head) return false;
31199
- return maybeSetSelection(
31200
- state2,
31201
- dispatch,
31202
- new CellSelection(cellSel.$anchorCell, $head)
31203
- );
31035
+ return maybeSetSelection(state2, dispatch, new CellSelection(cellSel.$anchorCell, $head));
31204
31036
  };
31205
31037
  }
31206
31038
  function handleTripleClick(view, pos) {
@@ -31214,65 +31046,46 @@ function handlePaste(view, _2, slice2) {
31214
31046
  let cells = pastedCells(slice2);
31215
31047
  const sel = view.state.selection;
31216
31048
  if (sel instanceof CellSelection) {
31217
- if (!cells)
31218
- cells = {
31219
- width: 1,
31220
- height: 1,
31221
- rows: [
31222
- Fragment.from(
31223
- fitSlice(tableNodeTypes(view.state.schema).cell, slice2)
31224
- )
31225
- ]
31226
- };
31049
+ if (!cells) cells = {
31050
+ width: 1,
31051
+ height: 1,
31052
+ rows: [Fragment.from(fitSlice(tableNodeTypes(view.state.schema).cell, slice2))]
31053
+ };
31227
31054
  const table = sel.$anchorCell.node(-1);
31228
31055
  const start = sel.$anchorCell.start(-1);
31229
- const rect = TableMap.get(table).rectBetween(
31230
- sel.$anchorCell.pos - start,
31231
- sel.$headCell.pos - start
31232
- );
31056
+ const rect = TableMap.get(table).rectBetween(sel.$anchorCell.pos - start, sel.$headCell.pos - start);
31233
31057
  cells = clipCells(cells, rect.right - rect.left, rect.bottom - rect.top);
31234
31058
  insertCells(view.state, view.dispatch, start, rect, cells);
31235
31059
  return true;
31236
31060
  } else if (cells) {
31237
31061
  const $cell = selectionCell(view.state);
31238
31062
  const start = $cell.start(-1);
31239
- insertCells(
31240
- view.state,
31241
- view.dispatch,
31242
- start,
31243
- TableMap.get($cell.node(-1)).findCell($cell.pos - start),
31244
- cells
31245
- );
31063
+ insertCells(view.state, view.dispatch, start, TableMap.get($cell.node(-1)).findCell($cell.pos - start), cells);
31246
31064
  return true;
31247
- } else {
31248
- return false;
31249
- }
31065
+ } else return false;
31250
31066
  }
31251
- function handleMouseDown(view, startEvent) {
31252
- var _a2;
31067
+ function handleMouseDown$1(view, startEvent) {
31068
+ var _cellUnderMouse;
31069
+ if (startEvent.button != 0) return;
31253
31070
  if (startEvent.ctrlKey || startEvent.metaKey) return;
31254
31071
  const startDOMCell = domInCell(view, startEvent.target);
31255
31072
  let $anchor;
31256
31073
  if (startEvent.shiftKey && view.state.selection instanceof CellSelection) {
31257
31074
  setCellSelection(view.state.selection.$anchorCell, startEvent);
31258
31075
  startEvent.preventDefault();
31259
- } else if (startEvent.shiftKey && startDOMCell && ($anchor = cellAround(view.state.selection.$anchor)) != null && ((_a2 = cellUnderMouse(view, startEvent)) == null ? void 0 : _a2.pos) != $anchor.pos) {
31076
+ } else if (startEvent.shiftKey && startDOMCell && ($anchor = cellAround(view.state.selection.$anchor)) != null && ((_cellUnderMouse = cellUnderMouse(view, startEvent)) === null || _cellUnderMouse === void 0 ? void 0 : _cellUnderMouse.pos) != $anchor.pos) {
31260
31077
  setCellSelection($anchor, startEvent);
31261
31078
  startEvent.preventDefault();
31262
- } else if (!startDOMCell) {
31263
- return;
31264
- }
31265
- function setCellSelection($anchor2, event2) {
31079
+ } else if (!startDOMCell) return;
31080
+ function setCellSelection($anchor$1, event2) {
31266
31081
  let $head = cellUnderMouse(view, event2);
31267
31082
  const starting = tableEditingKey.getState(view.state) == null;
31268
- if (!$head || !inSameTable($anchor2, $head)) {
31269
- if (starting) $head = $anchor2;
31270
- else return;
31271
- }
31272
- const selection = new CellSelection($anchor2, $head);
31083
+ if (!$head || !inSameTable($anchor$1, $head)) if (starting) $head = $anchor$1;
31084
+ else return;
31085
+ const selection = new CellSelection($anchor$1, $head);
31273
31086
  if (starting || !view.state.selection.eq(selection)) {
31274
31087
  const tr2 = view.state.tr.setSelection(selection);
31275
- if (starting) tr2.setMeta(tableEditingKey, $anchor2.pos);
31088
+ if (starting) tr2.setMeta(tableEditingKey, $anchor$1.pos);
31276
31089
  view.dispatch(tr2);
31277
31090
  }
31278
31091
  }
@@ -31280,20 +31093,18 @@ function handleMouseDown(view, startEvent) {
31280
31093
  view.root.removeEventListener("mouseup", stop);
31281
31094
  view.root.removeEventListener("dragstart", stop);
31282
31095
  view.root.removeEventListener("mousemove", move2);
31283
- if (tableEditingKey.getState(view.state) != null)
31284
- view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));
31096
+ if (tableEditingKey.getState(view.state) != null) view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));
31285
31097
  }
31286
31098
  function move2(_event) {
31287
31099
  const event2 = _event;
31288
31100
  const anchor = tableEditingKey.getState(view.state);
31289
- let $anchor2;
31290
- if (anchor != null) {
31291
- $anchor2 = view.state.doc.resolve(anchor);
31292
- } else if (domInCell(view, event2.target) != startDOMCell) {
31293
- $anchor2 = cellUnderMouse(view, startEvent);
31294
- if (!$anchor2) return stop();
31101
+ let $anchor$1;
31102
+ if (anchor != null) $anchor$1 = view.state.doc.resolve(anchor);
31103
+ else if (domInCell(view, event2.target) != startDOMCell) {
31104
+ $anchor$1 = cellUnderMouse(view, startEvent);
31105
+ if (!$anchor$1) return stop();
31295
31106
  }
31296
- if ($anchor2) setCellSelection($anchor2, event2);
31107
+ if ($anchor$1) setCellSelection($anchor$1, event2);
31297
31108
  }
31298
31109
  view.root.addEventListener("mouseup", stop);
31299
31110
  view.root.addEventListener("dragstart", stop);
@@ -31303,8 +31114,8 @@ function atEndOfCell(view, axis, dir) {
31303
31114
  if (!(view.state.selection instanceof TextSelection)) return null;
31304
31115
  const { $head } = view.state.selection;
31305
31116
  for (let d2 = $head.depth - 1; d2 >= 0; d2--) {
31306
- const parent = $head.node(d2), index2 = dir < 0 ? $head.index(d2) : $head.indexAfter(d2);
31307
- if (index2 != (dir < 0 ? 0 : parent.childCount)) return null;
31117
+ const parent = $head.node(d2);
31118
+ if ((dir < 0 ? $head.index(d2) : $head.indexAfter(d2)) != (dir < 0 ? 0 : parent.childCount)) return null;
31308
31119
  if (parent.type.spec.tableRole == "cell" || parent.type.spec.tableRole == "header_cell") {
31309
31120
  const cellPos = $head.before(d2);
31310
31121
  const dirStr = axis == "vert" ? dir > 0 ? "down" : "up" : dir > 0 ? "right" : "left";
@@ -31314,11 +31125,7 @@ function atEndOfCell(view, axis, dir) {
31314
31125
  return null;
31315
31126
  }
31316
31127
  function domInCell(view, dom) {
31317
- for (; dom && dom != view.dom; dom = dom.parentNode) {
31318
- if (dom.nodeName == "TD" || dom.nodeName == "TH") {
31319
- return dom;
31320
- }
31321
- }
31128
+ for (; dom && dom != view.dom; dom = dom.parentNode) if (dom.nodeName == "TD" || dom.nodeName == "TH") return dom;
31322
31129
  return null;
31323
31130
  }
31324
31131
  function cellUnderMouse(view, event2) {
@@ -31327,7 +31134,8 @@ function cellUnderMouse(view, event2) {
31327
31134
  top: event2.clientY
31328
31135
  });
31329
31136
  if (!mousePos) return null;
31330
- return mousePos ? cellAround(view.state.doc.resolve(mousePos.pos)) : null;
31137
+ let { inside, pos } = mousePos;
31138
+ return inside >= 0 && cellAround(view.state.doc.resolve(inside)) || cellAround(view.state.doc.resolve(pos));
31331
31139
  }
31332
31140
  var TableView$1 = class TableView {
31333
31141
  constructor(node, defaultCellMinWidth) {
@@ -31336,10 +31144,7 @@ var TableView$1 = class TableView {
31336
31144
  this.dom = document.createElement("div");
31337
31145
  this.dom.className = "tableWrapper";
31338
31146
  this.table = this.dom.appendChild(document.createElement("table"));
31339
- this.table.style.setProperty(
31340
- "--default-cell-min-width",
31341
- `${defaultCellMinWidth}px`
31342
- );
31147
+ this.table.style.setProperty("--default-cell-min-width", `${defaultCellMinWidth}px`);
31343
31148
  this.colgroup = this.table.appendChild(document.createElement("colgroup"));
31344
31149
  updateColumnsOnResize(node, this.colgroup, this.table, defaultCellMinWidth);
31345
31150
  this.contentDOM = this.table.appendChild(document.createElement("tbody"));
@@ -31347,12 +31152,7 @@ var TableView$1 = class TableView {
31347
31152
  update(node) {
31348
31153
  if (node.type != this.node.type) return false;
31349
31154
  this.node = node;
31350
- updateColumnsOnResize(
31351
- node,
31352
- this.colgroup,
31353
- this.table,
31354
- this.defaultCellMinWidth
31355
- );
31155
+ updateColumnsOnResize(node, this.colgroup, this.table, this.defaultCellMinWidth);
31356
31156
  return true;
31357
31157
  }
31358
31158
  ignoreMutation(record) {
@@ -31360,7 +31160,6 @@ var TableView$1 = class TableView {
31360
31160
  }
31361
31161
  };
31362
31162
  function updateColumnsOnResize(node, colgroup, table, defaultCellMinWidth, overrideCol, overrideValue) {
31363
- var _a2;
31364
31163
  let totalWidth = 0;
31365
31164
  let fixedWidth = true;
31366
31165
  let nextDOM = colgroup.firstChild;
@@ -31374,20 +31173,19 @@ function updateColumnsOnResize(node, colgroup, table, defaultCellMinWidth, overr
31374
31173
  totalWidth += hasWidth || defaultCellMinWidth;
31375
31174
  if (!hasWidth) fixedWidth = false;
31376
31175
  if (!nextDOM) {
31377
- const col2 = document.createElement("col");
31378
- col2.style.width = cssWidth;
31379
- colgroup.appendChild(col2);
31176
+ const col$1 = document.createElement("col");
31177
+ col$1.style.width = cssWidth;
31178
+ colgroup.appendChild(col$1);
31380
31179
  } else {
31381
- if (nextDOM.style.width != cssWidth) {
31382
- nextDOM.style.width = cssWidth;
31383
- }
31180
+ if (nextDOM.style.width != cssWidth) nextDOM.style.width = cssWidth;
31384
31181
  nextDOM = nextDOM.nextSibling;
31385
31182
  }
31386
31183
  }
31387
31184
  }
31388
31185
  while (nextDOM) {
31186
+ var _nextDOM$parentNode;
31389
31187
  const after = nextDOM.nextSibling;
31390
- (_a2 = nextDOM.parentNode) == null ? void 0 : _a2.removeChild(nextDOM);
31188
+ (_nextDOM$parentNode = nextDOM.parentNode) === null || _nextDOM$parentNode === void 0 || _nextDOM$parentNode.removeChild(nextDOM);
31391
31189
  nextDOM = after;
31392
31190
  }
31393
31191
  if (fixedWidth) {
@@ -31398,28 +31196,18 @@ function updateColumnsOnResize(node, colgroup, table, defaultCellMinWidth, overr
31398
31196
  table.style.minWidth = totalWidth + "px";
31399
31197
  }
31400
31198
  }
31401
- var columnResizingPluginKey = new PluginKey(
31402
- "tableColumnResizing"
31403
- );
31404
- function columnResizing({
31405
- handleWidth = 5,
31406
- cellMinWidth = 25,
31407
- defaultCellMinWidth = 100,
31408
- View = TableView$1,
31409
- lastColumnResizable = true
31410
- } = {}) {
31199
+ const columnResizingPluginKey = new PluginKey("tableColumnResizing");
31200
+ function columnResizing({ handleWidth = 5, cellMinWidth = 25, defaultCellMinWidth = 100, View = TableView$1, lastColumnResizable = true } = {}) {
31411
31201
  const plugin = new Plugin({
31412
31202
  key: columnResizingPluginKey,
31413
31203
  state: {
31414
31204
  init(_2, state2) {
31415
- var _a2, _b;
31416
- const nodeViews = (_b = (_a2 = plugin.spec) == null ? void 0 : _a2.props) == null ? void 0 : _b.nodeViews;
31205
+ var _plugin$spec;
31206
+ const nodeViews = (_plugin$spec = plugin.spec) === null || _plugin$spec === void 0 || (_plugin$spec = _plugin$spec.props) === null || _plugin$spec === void 0 ? void 0 : _plugin$spec.nodeViews;
31417
31207
  const tableName = tableNodeTypes(state2.schema).table.name;
31418
- if (View && nodeViews) {
31419
- nodeViews[tableName] = (node, view) => {
31420
- return new View(node, defaultCellMinWidth, view);
31421
- };
31422
- }
31208
+ if (View && nodeViews) nodeViews[tableName] = (node, view) => {
31209
+ return new View(node, defaultCellMinWidth, view);
31210
+ };
31423
31211
  return new ResizeState(-1, false);
31424
31212
  },
31425
31213
  apply(tr2, prev) {
@@ -31439,21 +31227,19 @@ function columnResizing({
31439
31227
  handleMouseLeave(view);
31440
31228
  },
31441
31229
  mousedown: (view, event2) => {
31442
- handleMouseDown2(view, event2, cellMinWidth, defaultCellMinWidth);
31230
+ handleMouseDown(view, event2, cellMinWidth, defaultCellMinWidth);
31443
31231
  }
31444
31232
  },
31445
31233
  decorations: (state2) => {
31446
31234
  const pluginState = columnResizingPluginKey.getState(state2);
31447
- if (pluginState && pluginState.activeHandle > -1) {
31448
- return handleDecorations(state2, pluginState.activeHandle);
31449
- }
31235
+ if (pluginState && pluginState.activeHandle > -1) return handleDecorations(state2, pluginState.activeHandle);
31450
31236
  },
31451
31237
  nodeViews: {}
31452
31238
  }
31453
31239
  });
31454
31240
  return plugin;
31455
31241
  }
31456
- var ResizeState = class _ResizeState {
31242
+ var ResizeState = class ResizeState2 {
31457
31243
  constructor(activeHandle, dragging) {
31458
31244
  this.activeHandle = activeHandle;
31459
31245
  this.dragging = dragging;
@@ -31461,16 +31247,12 @@ var ResizeState = class _ResizeState {
31461
31247
  apply(tr2) {
31462
31248
  const state2 = this;
31463
31249
  const action = tr2.getMeta(columnResizingPluginKey);
31464
- if (action && action.setHandle != null)
31465
- return new _ResizeState(action.setHandle, false);
31466
- if (action && action.setDragging !== void 0)
31467
- return new _ResizeState(state2.activeHandle, action.setDragging);
31250
+ if (action && action.setHandle != null) return new ResizeState2(action.setHandle, false);
31251
+ if (action && action.setDragging !== void 0) return new ResizeState2(state2.activeHandle, action.setDragging);
31468
31252
  if (state2.activeHandle > -1 && tr2.docChanged) {
31469
31253
  let handle = tr2.mapping.map(state2.activeHandle, -1);
31470
- if (!pointsAtCell(tr2.doc.resolve(handle))) {
31471
- handle = -1;
31472
- }
31473
- return new _ResizeState(handle, state2.dragging);
31254
+ if (!pointsAtCell(tr2.doc.resolve(handle))) handle = -1;
31255
+ return new ResizeState2(handle, state2.dragging);
31474
31256
  }
31475
31257
  return state2;
31476
31258
  }
@@ -31484,10 +31266,8 @@ function handleMouseMove(view, event2, handleWidth, lastColumnResizable) {
31484
31266
  let cell = -1;
31485
31267
  if (target) {
31486
31268
  const { left, right } = target.getBoundingClientRect();
31487
- if (event2.clientX - left <= handleWidth)
31488
- cell = edgeCell(view, event2, "left", handleWidth);
31489
- else if (right - event2.clientX <= handleWidth)
31490
- cell = edgeCell(view, event2, "right", handleWidth);
31269
+ if (event2.clientX - left <= handleWidth) cell = edgeCell(view, event2, "left", handleWidth);
31270
+ else if (right - event2.clientX <= handleWidth) cell = edgeCell(view, event2, "right", handleWidth);
31491
31271
  }
31492
31272
  if (cell != pluginState.activeHandle) {
31493
31273
  if (!lastColumnResizable && cell !== -1) {
@@ -31495,10 +31275,7 @@ function handleMouseMove(view, event2, handleWidth, lastColumnResizable) {
31495
31275
  const table = $cell.node(-1);
31496
31276
  const map2 = TableMap.get(table);
31497
31277
  const tableStart = $cell.start(-1);
31498
- const col = map2.colCount($cell.pos - tableStart) + $cell.nodeAfter.attrs.colspan - 1;
31499
- if (col == map2.width - 1) {
31500
- return;
31501
- }
31278
+ if (map2.colCount($cell.pos - tableStart) + $cell.nodeAfter.attrs.colspan - 1 == map2.width - 1) return;
31502
31279
  }
31503
31280
  updateHandle(view, cell);
31504
31281
  }
@@ -31507,58 +31284,39 @@ function handleMouseMove(view, event2, handleWidth, lastColumnResizable) {
31507
31284
  function handleMouseLeave(view) {
31508
31285
  if (!view.editable) return;
31509
31286
  const pluginState = columnResizingPluginKey.getState(view.state);
31510
- if (pluginState && pluginState.activeHandle > -1 && !pluginState.dragging)
31511
- updateHandle(view, -1);
31287
+ if (pluginState && pluginState.activeHandle > -1 && !pluginState.dragging) updateHandle(view, -1);
31512
31288
  }
31513
- function handleMouseDown2(view, event2, cellMinWidth, defaultCellMinWidth) {
31514
- var _a2;
31289
+ function handleMouseDown(view, event2, cellMinWidth, defaultCellMinWidth) {
31290
+ var _view$dom$ownerDocume;
31515
31291
  if (!view.editable) return false;
31516
- const win = (_a2 = view.dom.ownerDocument.defaultView) != null ? _a2 : window;
31292
+ const win = (_view$dom$ownerDocume = view.dom.ownerDocument.defaultView) !== null && _view$dom$ownerDocume !== void 0 ? _view$dom$ownerDocume : window;
31517
31293
  const pluginState = columnResizingPluginKey.getState(view.state);
31518
- if (!pluginState || pluginState.activeHandle == -1 || pluginState.dragging)
31519
- return false;
31294
+ if (!pluginState || pluginState.activeHandle == -1 || pluginState.dragging) return false;
31520
31295
  const cell = view.state.doc.nodeAt(pluginState.activeHandle);
31521
31296
  const width = currentColWidth(view, pluginState.activeHandle, cell.attrs);
31522
- view.dispatch(
31523
- view.state.tr.setMeta(columnResizingPluginKey, {
31524
- setDragging: { startX: event2.clientX, startWidth: width }
31525
- })
31526
- );
31527
- function finish(event22) {
31297
+ view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setDragging: {
31298
+ startX: event2.clientX,
31299
+ startWidth: width
31300
+ } }));
31301
+ function finish(event$1) {
31528
31302
  win.removeEventListener("mouseup", finish);
31529
31303
  win.removeEventListener("mousemove", move2);
31530
- const pluginState2 = columnResizingPluginKey.getState(view.state);
31531
- if (pluginState2 == null ? void 0 : pluginState2.dragging) {
31532
- updateColumnWidth(
31533
- view,
31534
- pluginState2.activeHandle,
31535
- draggedWidth(pluginState2.dragging, event22, cellMinWidth)
31536
- );
31537
- view.dispatch(
31538
- view.state.tr.setMeta(columnResizingPluginKey, { setDragging: null })
31539
- );
31304
+ const pluginState$1 = columnResizingPluginKey.getState(view.state);
31305
+ if (pluginState$1 === null || pluginState$1 === void 0 ? void 0 : pluginState$1.dragging) {
31306
+ updateColumnWidth(view, pluginState$1.activeHandle, draggedWidth(pluginState$1.dragging, event$1, cellMinWidth));
31307
+ view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setDragging: null }));
31540
31308
  }
31541
31309
  }
31542
- function move2(event22) {
31543
- if (!event22.which) return finish(event22);
31544
- const pluginState2 = columnResizingPluginKey.getState(view.state);
31545
- if (!pluginState2) return;
31546
- if (pluginState2.dragging) {
31547
- const dragged = draggedWidth(pluginState2.dragging, event22, cellMinWidth);
31548
- displayColumnWidth(
31549
- view,
31550
- pluginState2.activeHandle,
31551
- dragged,
31552
- defaultCellMinWidth
31553
- );
31310
+ function move2(event$1) {
31311
+ if (!event$1.which) return finish(event$1);
31312
+ const pluginState$1 = columnResizingPluginKey.getState(view.state);
31313
+ if (!pluginState$1) return;
31314
+ if (pluginState$1.dragging) {
31315
+ const dragged = draggedWidth(pluginState$1.dragging, event$1, cellMinWidth);
31316
+ displayColumnWidth(view, pluginState$1.activeHandle, dragged, defaultCellMinWidth);
31554
31317
  }
31555
31318
  }
31556
- displayColumnWidth(
31557
- view,
31558
- pluginState.activeHandle,
31559
- width,
31560
- defaultCellMinWidth
31561
- );
31319
+ displayColumnWidth(view, pluginState.activeHandle, width, defaultCellMinWidth);
31562
31320
  win.addEventListener("mouseup", finish);
31563
31321
  win.addEventListener("mousemove", move2);
31564
31322
  event2.preventDefault();
@@ -31568,20 +31326,17 @@ function currentColWidth(view, cellPos, { colspan, colwidth }) {
31568
31326
  const width = colwidth && colwidth[colwidth.length - 1];
31569
31327
  if (width) return width;
31570
31328
  const dom = view.domAtPos(cellPos);
31571
- const node = dom.node.childNodes[dom.offset];
31572
- let domWidth = node.offsetWidth, parts = colspan;
31329
+ let domWidth = dom.node.childNodes[dom.offset].offsetWidth, parts = colspan;
31573
31330
  if (colwidth) {
31574
- for (let i = 0; i < colspan; i++)
31575
- if (colwidth[i]) {
31576
- domWidth -= colwidth[i];
31577
- parts--;
31578
- }
31331
+ for (let i = 0; i < colspan; i++) if (colwidth[i]) {
31332
+ domWidth -= colwidth[i];
31333
+ parts--;
31334
+ }
31579
31335
  }
31580
31336
  return domWidth / parts;
31581
31337
  }
31582
31338
  function domCellAround(target) {
31583
- while (target && target.nodeName != "TD" && target.nodeName != "TH")
31584
- target = target.classList && target.classList.contains("ProseMirror") ? null : target.parentNode;
31339
+ while (target && target.nodeName != "TD" && target.nodeName != "TH") target = target.classList && target.classList.contains("ProseMirror") ? null : target.parentNode;
31585
31340
  return target;
31586
31341
  }
31587
31342
  function edgeCell(view, event2, side, handleWidth) {
@@ -31604,9 +31359,7 @@ function draggedWidth(dragging, event2, resizeMinWidth) {
31604
31359
  return Math.max(resizeMinWidth, dragging.startWidth + offset);
31605
31360
  }
31606
31361
  function updateHandle(view, value) {
31607
- view.dispatch(
31608
- view.state.tr.setMeta(columnResizingPluginKey, { setHandle: value })
31609
- );
31362
+ view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setHandle: value }));
31610
31363
  }
31611
31364
  function updateColumnWidth(view, cell, width) {
31612
31365
  const $cell = view.state.doc.resolve(cell);
@@ -31622,7 +31375,10 @@ function updateColumnWidth(view, cell, width) {
31622
31375
  if (attrs.colwidth && attrs.colwidth[index2] == width) continue;
31623
31376
  const colwidth = attrs.colwidth ? attrs.colwidth.slice() : zeroes(attrs.colspan);
31624
31377
  colwidth[index2] = width;
31625
- tr2.setNodeMarkup(start + pos, null, { ...attrs, colwidth });
31378
+ tr2.setNodeMarkup(start + pos, null, {
31379
+ ...attrs,
31380
+ colwidth
31381
+ });
31626
31382
  }
31627
31383
  if (tr2.docChanged) view.dispatch(tr2);
31628
31384
  }
@@ -31631,64 +31387,38 @@ function displayColumnWidth(view, cell, width, defaultCellMinWidth) {
31631
31387
  const table = $cell.node(-1), start = $cell.start(-1);
31632
31388
  const col = TableMap.get(table).colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1;
31633
31389
  let dom = view.domAtPos($cell.start(-1)).node;
31634
- while (dom && dom.nodeName != "TABLE") {
31635
- dom = dom.parentNode;
31636
- }
31390
+ while (dom && dom.nodeName != "TABLE") dom = dom.parentNode;
31637
31391
  if (!dom) return;
31638
- updateColumnsOnResize(
31639
- table,
31640
- dom.firstChild,
31641
- dom,
31642
- defaultCellMinWidth,
31643
- col,
31644
- width
31645
- );
31392
+ updateColumnsOnResize(table, dom.firstChild, dom, defaultCellMinWidth, col, width);
31646
31393
  }
31647
31394
  function zeroes(n) {
31648
31395
  return Array(n).fill(0);
31649
31396
  }
31650
31397
  function handleDecorations(state2, cell) {
31651
- var _a2;
31652
31398
  const decorations = [];
31653
31399
  const $cell = state2.doc.resolve(cell);
31654
31400
  const table = $cell.node(-1);
31655
- if (!table) {
31656
- return DecorationSet.empty;
31657
- }
31401
+ if (!table) return DecorationSet.empty;
31658
31402
  const map2 = TableMap.get(table);
31659
31403
  const start = $cell.start(-1);
31660
31404
  const col = map2.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1;
31661
31405
  for (let row = 0; row < map2.height; row++) {
31662
31406
  const index2 = col + row * map2.width;
31663
31407
  if ((col == map2.width - 1 || map2.map[index2] != map2.map[index2 + 1]) && (row == 0 || map2.map[index2] != map2.map[index2 - map2.width])) {
31408
+ var _columnResizingPlugin;
31664
31409
  const cellPos = map2.map[index2];
31665
31410
  const pos = start + cellPos + table.nodeAt(cellPos).nodeSize - 1;
31666
31411
  const dom = document.createElement("div");
31667
31412
  dom.className = "column-resize-handle";
31668
- if ((_a2 = columnResizingPluginKey.getState(state2)) == null ? void 0 : _a2.dragging) {
31669
- decorations.push(
31670
- Decoration.node(
31671
- start + cellPos,
31672
- start + cellPos + table.nodeAt(cellPos).nodeSize,
31673
- {
31674
- class: "column-resize-dragging"
31675
- }
31676
- )
31677
- );
31678
- }
31413
+ if ((_columnResizingPlugin = columnResizingPluginKey.getState(state2)) === null || _columnResizingPlugin === void 0 ? void 0 : _columnResizingPlugin.dragging) decorations.push(Decoration.node(start + cellPos, start + cellPos + table.nodeAt(cellPos).nodeSize, { class: "column-resize-dragging" }));
31679
31414
  decorations.push(Decoration.widget(pos, dom));
31680
31415
  }
31681
31416
  }
31682
31417
  return DecorationSet.create(state2.doc, decorations);
31683
31418
  }
31684
- function tableEditing({
31685
- allowTableNodeSelection = false
31686
- } = {}) {
31419
+ function tableEditing({ allowTableNodeSelection = false } = {}) {
31687
31420
  return new Plugin({
31688
31421
  key: tableEditingKey,
31689
- // This piece of state is used to remember when a mouse-drag
31690
- // cell-selection is happening, so that it can continue even as
31691
- // transactions (which might move its anchor cell) come in.
31692
31422
  state: {
31693
31423
  init() {
31694
31424
  return null;
@@ -31703,9 +31433,7 @@ function tableEditing({
31703
31433
  },
31704
31434
  props: {
31705
31435
  decorations: drawCellSelection,
31706
- handleDOMEvents: {
31707
- mousedown: handleMouseDown
31708
- },
31436
+ handleDOMEvents: { mousedown: handleMouseDown$1 },
31709
31437
  createSelectionBetween(view) {
31710
31438
  return tableEditingKey.getState(view.state) != null ? view.state.selection : null;
31711
31439
  },
@@ -31714,11 +31442,7 @@ function tableEditing({
31714
31442
  handlePaste
31715
31443
  },
31716
31444
  appendTransaction(_2, oldState, state2) {
31717
- return normalizeSelection(
31718
- state2,
31719
- fixTables(state2, oldState),
31720
- allowTableNodeSelection
31721
- );
31445
+ return normalizeSelection(state2, fixTables(state2, oldState), allowTableNodeSelection);
31722
31446
  }
31723
31447
  });
31724
31448
  }