docxodus 9.2.0 → 9.3.0

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.
@@ -1,3 +1,118 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ try {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ } catch (e) {
11
+ throw mod = 0, e;
12
+ }
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+
31
+ // node_modules/bind-event-listener/dist/bind.js
32
+ var require_bind = __commonJS({
33
+ "node_modules/bind-event-listener/dist/bind.js"(exports) {
34
+ "use strict";
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.bind = void 0;
37
+ function bind3(target, _a) {
38
+ var type = _a.type, listener = _a.listener, options = _a.options;
39
+ target.addEventListener(type, listener, options);
40
+ return function unbind() {
41
+ target.removeEventListener(type, listener, options);
42
+ };
43
+ }
44
+ exports.bind = bind3;
45
+ }
46
+ });
47
+
48
+ // node_modules/bind-event-listener/dist/bind-all.js
49
+ var require_bind_all = __commonJS({
50
+ "node_modules/bind-event-listener/dist/bind-all.js"(exports) {
51
+ "use strict";
52
+ var __assign = exports && exports.__assign || function() {
53
+ __assign = Object.assign || function(t) {
54
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
55
+ s = arguments[i];
56
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
57
+ t[p] = s[p];
58
+ }
59
+ return t;
60
+ };
61
+ return __assign.apply(this, arguments);
62
+ };
63
+ Object.defineProperty(exports, "__esModule", { value: true });
64
+ exports.bindAll = void 0;
65
+ var bind_1 = require_bind();
66
+ function toOptions(value) {
67
+ if (typeof value === "undefined") {
68
+ return void 0;
69
+ }
70
+ if (typeof value === "boolean") {
71
+ return {
72
+ capture: value
73
+ };
74
+ }
75
+ return value;
76
+ }
77
+ function getBinding(original, sharedOptions) {
78
+ if (sharedOptions == null) {
79
+ return original;
80
+ }
81
+ var binding = __assign(__assign({}, original), { options: __assign(__assign({}, toOptions(sharedOptions)), toOptions(original.options)) });
82
+ return binding;
83
+ }
84
+ function bindAll4(target, bindings, sharedOptions) {
85
+ var unbinds = bindings.map(function(original) {
86
+ var binding = getBinding(original, sharedOptions);
87
+ return (0, bind_1.bind)(target, binding);
88
+ });
89
+ return function unbindAll() {
90
+ unbinds.forEach(function(unbind) {
91
+ return unbind();
92
+ });
93
+ };
94
+ }
95
+ exports.bindAll = bindAll4;
96
+ }
97
+ });
98
+
99
+ // node_modules/bind-event-listener/dist/index.js
100
+ var require_dist = __commonJS({
101
+ "node_modules/bind-event-listener/dist/index.js"(exports) {
102
+ "use strict";
103
+ Object.defineProperty(exports, "__esModule", { value: true });
104
+ exports.bindAll = exports.bind = void 0;
105
+ var bind_1 = require_bind();
106
+ Object.defineProperty(exports, "bind", { enumerable: true, get: function() {
107
+ return bind_1.bind;
108
+ } });
109
+ var bind_all_1 = require_bind_all();
110
+ Object.defineProperty(exports, "bindAll", { enumerable: true, get: function() {
111
+ return bind_all_1.bindAll;
112
+ } });
113
+ }
114
+ });
115
+
1
116
  // src/types.ts
2
117
  var ProjectionScopes = /* @__PURE__ */ ((ProjectionScopes2) => {
3
118
  ProjectionScopes2[ProjectionScopes2["Body"] = 1] = "Body";
@@ -310,6 +425,12 @@ var DocxSession = class {
310
425
  deleteBlock(anchorId) {
311
426
  return JSON.parse(this.wasm.DeleteBlock(this.handle, anchorId));
312
427
  }
428
+ /** Reorder one top-level paragraph/heading/list/table block relative to another. */
429
+ moveBlock(sourceAnchorId, targetAnchorId, position) {
430
+ return JSON.parse(
431
+ this.wasm.MoveBlock(this.handle, sourceAnchorId, targetAnchorId, position)
432
+ );
433
+ }
313
434
  /**
314
435
  * Delete every top-level block-level sibling between `fromAnchorId` (inclusive)
315
436
  * and `toAnchorIdExclusive` (exclusive). Both anchors must share a direct
@@ -1286,9 +1407,9 @@ var PaginationEngine = class {
1286
1407
  for (const section of Array.from(sections)) {
1287
1408
  const index = parseInt(section.dataset.sectionIndex || "0", 10);
1288
1409
  const rawStart = section.dataset.pageNumStart;
1289
- const start = rawStart === void 0 ? void 0 : parseInt(rawStart, 10);
1410
+ const start2 = rawStart === void 0 ? void 0 : parseInt(rawStart, 10);
1290
1411
  map.set(index, {
1291
- start: start !== void 0 && Number.isFinite(start) ? start : void 0,
1412
+ start: start2 !== void 0 && Number.isFinite(start2) ? start2 : void 0,
1292
1413
  format: section.dataset.pageNumFmt
1293
1414
  });
1294
1415
  }
@@ -1513,16 +1634,16 @@ var PaginationEngine = class {
1513
1634
  return null;
1514
1635
  }
1515
1636
  const groups = [];
1516
- let start = 0;
1517
- while (start < rows.length) {
1518
- let end = start;
1637
+ let start2 = 0;
1638
+ while (start2 < rows.length) {
1639
+ let end = start2;
1519
1640
  while (end < rows.length) {
1520
1641
  const candidate = this.createSimpleTableFragment(
1521
1642
  wrapper,
1522
1643
  table,
1523
1644
  body,
1524
- rows.slice(start, end + 1),
1525
- start === 0
1645
+ rows.slice(start2, end + 1),
1646
+ start2 === 0
1526
1647
  );
1527
1648
  const measured = this.measureElement(candidate, dims);
1528
1649
  if (measured.heightPt > maximumFragmentHeight) {
@@ -1530,11 +1651,11 @@ var PaginationEngine = class {
1530
1651
  }
1531
1652
  end++;
1532
1653
  }
1533
- if (end === start) {
1654
+ if (end === start2) {
1534
1655
  return null;
1535
1656
  }
1536
- groups.push(rows.slice(start, end));
1537
- start = end;
1657
+ groups.push(rows.slice(start2, end));
1658
+ start2 = end;
1538
1659
  }
1539
1660
  if (groups.length < 2) {
1540
1661
  return null;
@@ -2849,9 +2970,9 @@ var HeaderFooterRegion = class {
2849
2970
  const commitStart = () => {
2850
2971
  const raw = pageStart.value.trim();
2851
2972
  if (raw === "") return;
2852
- const start = Number(raw);
2853
- if (!Number.isInteger(start) || start < 0) return;
2854
- this.setPageNumbering({ start });
2973
+ const start2 = Number(raw);
2974
+ if (!Number.isInteger(start2) || start2 < 0) return;
2975
+ this.setPageNumbering({ start: start2 });
2855
2976
  };
2856
2977
  pageStart.addEventListener("blur", commitStart);
2857
2978
  pageStart.addEventListener("keydown", (e) => {
@@ -2902,8 +3023,8 @@ var HeaderFooterRegion = class {
2902
3023
  if (pageFmt) pageFmt.value = this.sectionInfo?.pageNumberFormat ?? "";
2903
3024
  const pageStart = band.querySelector("[data-hf-pagestart]");
2904
3025
  if (pageStart && document.activeElement !== pageStart) {
2905
- const start = this.sectionInfo?.pageNumberStart;
2906
- pageStart.value = start === void 0 ? "" : String(start);
3026
+ const start2 = this.sectionInfo?.pageNumberStart;
3027
+ pageStart.value = start2 === void 0 ? "" : String(start2);
2907
3028
  }
2908
3029
  const inherited = this.refFor(which, kind)?.inherited === true;
2909
3030
  band.toggleAttribute("data-hf-inherited", inherited);
@@ -2933,83 +3054,2484 @@ var HeaderFooterRegion = class {
2933
3054
  this.adoptBlock(el, anchorId);
2934
3055
  this.callbacks.wireBlock(el);
2935
3056
  }
2936
- }
2937
- /**
2938
- * Mark a story paragraph as belonging to this region. The full anchor id is stamped alongside
2939
- * `data-anchor` (which carries only the bare unid, matching the body's convention) so band
2940
- * chrome can address the block without going through the editor's unid map. Called on first
2941
- * render AND after an incremental swap, which replaces the DOM node.
2942
- */
2943
- adoptBlock(el, anchorId) {
2944
- const body = this.blockRootOf(el);
2945
- if (!body) return;
2946
- el.setAttribute("data-hf-anchor", anchorId);
2947
- if (el.dataset.hfAdopted === "true") return;
2948
- el.dataset.hfAdopted = "true";
2949
- el.addEventListener("focus", () => {
2950
- body.querySelectorAll("[data-hf-focused]").forEach((sib) => sib.removeAttribute("data-hf-focused"));
2951
- el.setAttribute("data-hf-focused", "true");
3057
+ }
3058
+ /**
3059
+ * Mark a story paragraph as belonging to this region. The full anchor id is stamped alongside
3060
+ * `data-anchor` (which carries only the bare unid, matching the body's convention) so band
3061
+ * chrome can address the block without going through the editor's unid map. Called on first
3062
+ * render AND after an incremental swap, which replaces the DOM node.
3063
+ */
3064
+ adoptBlock(el, anchorId) {
3065
+ const body = this.blockRootOf(el);
3066
+ if (!body) return;
3067
+ el.setAttribute("data-hf-anchor", anchorId);
3068
+ if (el.dataset.hfAdopted === "true") return;
3069
+ el.dataset.hfAdopted = "true";
3070
+ el.addEventListener("focus", () => {
3071
+ body.querySelectorAll("[data-hf-focused]").forEach((sib) => sib.removeAttribute("data-hf-focused"));
3072
+ el.setAttribute("data-hf-focused", "true");
3073
+ });
3074
+ }
3075
+ renderStoryBlock(anchorId) {
3076
+ const html = this.bridge.RenderBlockHtml(
3077
+ this.handle,
3078
+ anchorId,
3079
+ this.options.cssPrefix,
3080
+ this.options.fabricateClasses
3081
+ );
3082
+ if (html.charCodeAt(0) === 123) return null;
3083
+ return new DOMParser().parseFromString(html, "text/html").body.firstElementChild;
3084
+ }
3085
+ placeholder(which, kind) {
3086
+ const el = document.createElement("div");
3087
+ el.className = "docx-hf-placeholder";
3088
+ el.setAttribute("data-hf-placeholder", "");
3089
+ const label = KIND_LABELS.find((k) => k.value === kind)?.label ?? kind;
3090
+ el.textContent = `No ${label.toLowerCase()} ${which} \u2014 pick a kind to create one.`;
3091
+ return el;
3092
+ }
3093
+ /**
3094
+ * Surface the caveat that comes with the selected kind. Turning on first/even means those pages
3095
+ * stop using the Default stories entirely, which bites hardest on the OTHER band: enabling an
3096
+ * even header with no even footer leaves even pages footer-less, and enabling a first-page
3097
+ * header with an empty first-page footer leaves page 1 footer-less. The note is shown whenever
3098
+ * first/even is selected (the behavior change is real either way); the fix button appears only
3099
+ * when the counterpart story is missing entirely, which is what a user almost always wants next.
3100
+ */
3101
+ renderKindWarning(which) {
3102
+ const band = this.bandFor(which);
3103
+ const warning = band.querySelector("[data-hf-warning]");
3104
+ if (!warning) return;
3105
+ const kind = this.kinds[which];
3106
+ if (kind === "default") {
3107
+ warning.hidden = true;
3108
+ warning.textContent = "";
3109
+ return;
3110
+ }
3111
+ const other = which === "header" ? "footer" : "header";
3112
+ warning.hidden = false;
3113
+ warning.textContent = `${kind === "even" ? EVEN_WARNING : FIRST_WARNING} `;
3114
+ if (this.partUriFor(other, kind)) return;
3115
+ const fix = document.createElement("button");
3116
+ fix.type = "button";
3117
+ fix.setAttribute("data-hf-fix-counterpart", "");
3118
+ fix.textContent = `Also create a ${kind === "even" ? "matching even" : "first-page"} ${other}`;
3119
+ fix.addEventListener("click", () => {
3120
+ this.setKind(other, kind);
3121
+ this.renderKindWarning(which);
3122
+ });
3123
+ warning.appendChild(fix);
3124
+ }
3125
+ };
3126
+ function parseResult(json) {
3127
+ try {
3128
+ return JSON.parse(json);
3129
+ } catch {
3130
+ return { success: false };
3131
+ }
3132
+ }
3133
+
3134
+ // node_modules/@babel/runtime/helpers/esm/arrayWithHoles.js
3135
+ function _arrayWithHoles(r) {
3136
+ if (Array.isArray(r)) return r;
3137
+ }
3138
+
3139
+ // node_modules/@babel/runtime/helpers/esm/iterableToArrayLimit.js
3140
+ function _iterableToArrayLimit(r, l) {
3141
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
3142
+ if (null != t) {
3143
+ var e, n, i, u, a = [], f = true, o = false;
3144
+ try {
3145
+ if (i = (t = t.call(r)).next, 0 === l) {
3146
+ if (Object(t) !== t) return;
3147
+ f = false;
3148
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = true) ;
3149
+ } catch (r2) {
3150
+ o = true, n = r2;
3151
+ } finally {
3152
+ try {
3153
+ if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
3154
+ } finally {
3155
+ if (o) throw n;
3156
+ }
3157
+ }
3158
+ return a;
3159
+ }
3160
+ }
3161
+
3162
+ // node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js
3163
+ function _arrayLikeToArray(r, a) {
3164
+ (null == a || a > r.length) && (a = r.length);
3165
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
3166
+ return n;
3167
+ }
3168
+
3169
+ // node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js
3170
+ function _unsupportedIterableToArray(r, a) {
3171
+ if (r) {
3172
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
3173
+ var t = {}.toString.call(r).slice(8, -1);
3174
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
3175
+ }
3176
+ }
3177
+
3178
+ // node_modules/@babel/runtime/helpers/esm/nonIterableRest.js
3179
+ function _nonIterableRest() {
3180
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
3181
+ }
3182
+
3183
+ // node_modules/@babel/runtime/helpers/esm/slicedToArray.js
3184
+ function _slicedToArray(r, e) {
3185
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
3186
+ }
3187
+
3188
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/adapter/element-adapter.js
3189
+ var import_bind_event_listener4 = __toESM(require_dist());
3190
+
3191
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/honey-pot-fix/honey-pot-data-attribute.js
3192
+ var honeyPotDataAttribute = "data-pdnd-honey-pot";
3193
+
3194
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/honey-pot-fix/is-honey-pot-element.js
3195
+ function isHoneyPotElement(target) {
3196
+ return target instanceof Element && target.hasAttribute(honeyPotDataAttribute);
3197
+ }
3198
+
3199
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/honey-pot-fix/get-element-from-point-without-honey-pot.js
3200
+ function getElementFromPointWithoutHoneypot(client) {
3201
+ var _document$elementsFro = document.elementsFromPoint(client.x, client.y), _document$elementsFro2 = _slicedToArray(_document$elementsFro, 2), top2 = _document$elementsFro2[0], second = _document$elementsFro2[1];
3202
+ if (!top2) {
3203
+ return null;
3204
+ }
3205
+ if (isHoneyPotElement(top2)) {
3206
+ return second !== null && second !== void 0 ? second : null;
3207
+ }
3208
+ return top2;
3209
+ }
3210
+
3211
+ // node_modules/@babel/runtime/helpers/esm/typeof.js
3212
+ function _typeof(o) {
3213
+ "@babel/helpers - typeof";
3214
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
3215
+ return typeof o2;
3216
+ } : function(o2) {
3217
+ return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
3218
+ }, _typeof(o);
3219
+ }
3220
+
3221
+ // node_modules/@babel/runtime/helpers/esm/toPrimitive.js
3222
+ function toPrimitive(t, r) {
3223
+ if ("object" != _typeof(t) || !t) return t;
3224
+ var e = t[Symbol.toPrimitive];
3225
+ if (void 0 !== e) {
3226
+ var i = e.call(t, r || "default");
3227
+ if ("object" != _typeof(i)) return i;
3228
+ throw new TypeError("@@toPrimitive must return a primitive value.");
3229
+ }
3230
+ return ("string" === r ? String : Number)(t);
3231
+ }
3232
+
3233
+ // node_modules/@babel/runtime/helpers/esm/toPropertyKey.js
3234
+ function toPropertyKey(t) {
3235
+ var i = toPrimitive(t, "string");
3236
+ return "symbol" == _typeof(i) ? i : i + "";
3237
+ }
3238
+
3239
+ // node_modules/@babel/runtime/helpers/esm/defineProperty.js
3240
+ function _defineProperty(e, r, t) {
3241
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
3242
+ value: t,
3243
+ enumerable: true,
3244
+ configurable: true,
3245
+ writable: true
3246
+ }) : e[r] = t, e;
3247
+ }
3248
+
3249
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/honey-pot-fix/make-honey-pot-fix.js
3250
+ var import_bind_event_listener = __toESM(require_dist());
3251
+
3252
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/util/max-z-index.js
3253
+ var maxZIndex = 2147483647;
3254
+
3255
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/util/popover-reset-styles.js
3256
+ var popoverResetUserAgentStyles = {
3257
+ inset: "unset",
3258
+ border: "none",
3259
+ padding: 0,
3260
+ margin: 0,
3261
+ overflow: "visible",
3262
+ color: "inherit",
3263
+ background: "transparent",
3264
+ width: "auto",
3265
+ height: "auto"
3266
+ };
3267
+
3268
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/public-utils/once.js
3269
+ function once(fn) {
3270
+ var cache = null;
3271
+ return function wrapped() {
3272
+ if (!cache) {
3273
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
3274
+ args[_key] = arguments[_key];
3275
+ }
3276
+ var result = fn.apply(this, args);
3277
+ cache = {
3278
+ result
3279
+ };
3280
+ }
3281
+ return cache.result;
3282
+ };
3283
+ }
3284
+
3285
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/util/supports-popover.js
3286
+ var supportsPopover = once(function supportsPopover2() {
3287
+ return typeof HTMLElement !== "undefined" && typeof HTMLElement.prototype.showPopover === "function";
3288
+ });
3289
+
3290
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/honey-pot-fix/make-honey-pot-fix.js
3291
+ function ownKeys(e, r) {
3292
+ var t = Object.keys(e);
3293
+ if (Object.getOwnPropertySymbols) {
3294
+ var o = Object.getOwnPropertySymbols(e);
3295
+ r && (o = o.filter(function(r2) {
3296
+ return Object.getOwnPropertyDescriptor(e, r2).enumerable;
3297
+ })), t.push.apply(t, o);
3298
+ }
3299
+ return t;
3300
+ }
3301
+ function _objectSpread(e) {
3302
+ for (var r = 1; r < arguments.length; r++) {
3303
+ var t = null != arguments[r] ? arguments[r] : {};
3304
+ r % 2 ? ownKeys(Object(t), true).forEach(function(r2) {
3305
+ _defineProperty(e, r2, t[r2]);
3306
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r2) {
3307
+ Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
3308
+ });
3309
+ }
3310
+ return e;
3311
+ }
3312
+ var honeyPotSize = 2;
3313
+ var halfHoneyPotSize = honeyPotSize / 2;
3314
+ function floorToClosestPixel(point) {
3315
+ return {
3316
+ x: Math.floor(point.x),
3317
+ y: Math.floor(point.y)
3318
+ };
3319
+ }
3320
+ function pullBackByHalfHoneyPotSize(point) {
3321
+ return {
3322
+ x: point.x - halfHoneyPotSize,
3323
+ y: point.y - halfHoneyPotSize
3324
+ };
3325
+ }
3326
+ function preventGoingBackwardsOffScreen(point) {
3327
+ return {
3328
+ x: Math.max(point.x, 0),
3329
+ y: Math.max(point.y, 0)
3330
+ };
3331
+ }
3332
+ function preventGoingForwardsOffScreen(point) {
3333
+ return {
3334
+ x: Math.min(point.x, window.innerWidth - honeyPotSize),
3335
+ y: Math.min(point.y, window.innerHeight - honeyPotSize)
3336
+ };
3337
+ }
3338
+ function getHoneyPotRectFor(_ref) {
3339
+ var client = _ref.client;
3340
+ var point = preventGoingForwardsOffScreen(preventGoingBackwardsOffScreen(pullBackByHalfHoneyPotSize(floorToClosestPixel(client))));
3341
+ return DOMRect.fromRect({
3342
+ x: point.x,
3343
+ y: point.y,
3344
+ width: honeyPotSize,
3345
+ height: honeyPotSize
3346
+ });
3347
+ }
3348
+ function getRectStyles(_ref2) {
3349
+ var clientRect = _ref2.clientRect;
3350
+ return {
3351
+ left: "".concat(clientRect.left, "px"),
3352
+ top: "".concat(clientRect.top, "px"),
3353
+ width: "".concat(clientRect.width, "px"),
3354
+ height: "".concat(clientRect.height, "px")
3355
+ };
3356
+ }
3357
+ function isWithin(_ref3) {
3358
+ var client = _ref3.client, clientRect = _ref3.clientRect;
3359
+ return (
3360
+ // is within horizontal bounds
3361
+ client.x >= clientRect.x && client.x <= clientRect.x + clientRect.width && // is within vertical bounds
3362
+ client.y >= clientRect.y && client.y <= clientRect.y + clientRect.height
3363
+ );
3364
+ }
3365
+ function mountHoneyPot(_ref4) {
3366
+ var initial = _ref4.initial;
3367
+ var element = document.createElement("div");
3368
+ element.setAttribute(honeyPotDataAttribute, "true");
3369
+ if (supportsPopover()) {
3370
+ element.setAttribute("popover", "manual");
3371
+ }
3372
+ var clientRect = getHoneyPotRectFor({
3373
+ client: initial
3374
+ });
3375
+ Object.assign(element.style, _objectSpread(_objectSpread({
3376
+ position: "fixed"
3377
+ }, supportsPopover() ? (
3378
+ // needs to come first as it has 'inset: unset' which
3379
+ // needs to be overridden by our top / left values
3380
+ popoverResetUserAgentStyles
3381
+ ) : {
3382
+ // Fallback: using maximum possible z-index so that this element
3383
+ // will always be on top of other positioned content.
3384
+ zIndex: maxZIndex
3385
+ }), {}, {
3386
+ // Setting a background color explicitly to avoid any inherited styles.
3387
+ // Looks like this could be `opacity: 0`, but worried that _might_
3388
+ // cause the element to be ignored on some platforms.
3389
+ // When debugging, set backgroundColor to something like "red".
3390
+ backgroundColor: "transparent",
3391
+ // Being explicit to avoid inheriting styles
3392
+ padding: 0,
3393
+ margin: 0,
3394
+ boxSizing: "border-box",
3395
+ // We want this element to absorb pointer events,
3396
+ // it's kind of the whole point 😉
3397
+ pointerEvents: "auto"
3398
+ }, getRectStyles({
3399
+ clientRect
3400
+ })));
3401
+ document.body.appendChild(element);
3402
+ if (supportsPopover()) {
3403
+ element.showPopover();
3404
+ }
3405
+ var unbindPointerMove = (0, import_bind_event_listener.bind)(window, {
3406
+ type: "pointermove",
3407
+ listener: function listener(event) {
3408
+ var client = {
3409
+ x: event.clientX,
3410
+ y: event.clientY
3411
+ };
3412
+ clientRect = getHoneyPotRectFor({
3413
+ client
3414
+ });
3415
+ Object.assign(element.style, getRectStyles({
3416
+ clientRect
3417
+ }));
3418
+ },
3419
+ // using capture so we are less likely to be impacted by event stopping
3420
+ options: {
3421
+ capture: true
3422
+ }
3423
+ });
3424
+ return function finish(_ref5) {
3425
+ var current = _ref5.current;
3426
+ unbindPointerMove();
3427
+ if (isWithin({
3428
+ client: current,
3429
+ clientRect
3430
+ })) {
3431
+ element.remove();
3432
+ return;
3433
+ }
3434
+ function cleanup() {
3435
+ unbindPostDragEvents();
3436
+ element.remove();
3437
+ }
3438
+ var unbindPostDragEvents = (0, import_bind_event_listener.bindAll)(window, [
3439
+ {
3440
+ type: "pointerdown",
3441
+ listener: cleanup
3442
+ },
3443
+ {
3444
+ type: "pointermove",
3445
+ listener: cleanup
3446
+ },
3447
+ {
3448
+ type: "focusin",
3449
+ listener: cleanup
3450
+ },
3451
+ {
3452
+ type: "focusout",
3453
+ listener: cleanup
3454
+ },
3455
+ // a 'pointerdown' should happen before 'dragstart', but just being super safe
3456
+ {
3457
+ type: "dragstart",
3458
+ listener: cleanup
3459
+ },
3460
+ // if the user has dragged something out of the window
3461
+ // and then is dragging something back into the window
3462
+ // the first events we will see are "dragenter" (and then "dragover").
3463
+ // So if we see any of these we need to clear the post drag fix.
3464
+ {
3465
+ type: "dragenter",
3466
+ listener: cleanup
3467
+ },
3468
+ {
3469
+ type: "dragover",
3470
+ listener: cleanup
3471
+ }
3472
+ // Not adding a "wheel" event listener, as "wheel" by itself does not
3473
+ // resolve the bug.
3474
+ ], {
3475
+ // Using `capture` so less likely to be impacted by other code stopping events
3476
+ capture: true
3477
+ });
3478
+ };
3479
+ }
3480
+ function makeHoneyPotFix() {
3481
+ var latestPointerMove = null;
3482
+ function bindEvents() {
3483
+ latestPointerMove = null;
3484
+ return (0, import_bind_event_listener.bind)(window, {
3485
+ type: "pointermove",
3486
+ listener: function listener(event) {
3487
+ latestPointerMove = {
3488
+ x: event.clientX,
3489
+ y: event.clientY
3490
+ };
3491
+ },
3492
+ // listening for pointer move in capture phase
3493
+ // so we are less likely to be impacted by events being stopped.
3494
+ options: {
3495
+ capture: true
3496
+ }
3497
+ });
3498
+ }
3499
+ function getOnPostDispatch() {
3500
+ var finish = null;
3501
+ return function onPostEvent(_ref6) {
3502
+ var eventName = _ref6.eventName, payload = _ref6.payload;
3503
+ if (eventName === "onDragStart") {
3504
+ var input = payload.location.initial.input;
3505
+ var initial = latestPointerMove !== null && latestPointerMove !== void 0 ? latestPointerMove : {
3506
+ x: input.clientX,
3507
+ y: input.clientY
3508
+ };
3509
+ finish = mountHoneyPot({
3510
+ initial
3511
+ });
3512
+ }
3513
+ if (eventName === "onDrop") {
3514
+ var _finish;
3515
+ var _input = payload.location.current.input;
3516
+ (_finish = finish) === null || _finish === void 0 || _finish({
3517
+ current: {
3518
+ x: _input.clientX,
3519
+ y: _input.clientY
3520
+ }
3521
+ });
3522
+ finish = null;
3523
+ latestPointerMove = null;
3524
+ }
3525
+ };
3526
+ }
3527
+ return {
3528
+ bindEvents,
3529
+ getOnPostDispatch
3530
+ };
3531
+ }
3532
+
3533
+ // node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js
3534
+ function _arrayWithoutHoles(r) {
3535
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
3536
+ }
3537
+
3538
+ // node_modules/@babel/runtime/helpers/esm/iterableToArray.js
3539
+ function _iterableToArray(r) {
3540
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
3541
+ }
3542
+
3543
+ // node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js
3544
+ function _nonIterableSpread() {
3545
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
3546
+ }
3547
+
3548
+ // node_modules/@babel/runtime/helpers/esm/toConsumableArray.js
3549
+ function _toConsumableArray(r) {
3550
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
3551
+ }
3552
+
3553
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/ledger/lifecycle-manager.js
3554
+ var import_bind_event_listener3 = __toESM(require_dist());
3555
+
3556
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/util/is-firefox.js
3557
+ var isFirefox = once(function isFirefox2() {
3558
+ if (false) {
3559
+ return false;
3560
+ }
3561
+ return navigator.userAgent.includes("Firefox");
3562
+ });
3563
+
3564
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/util/is-safari.js
3565
+ var isSafari = once(function isSafari2() {
3566
+ if (false) {
3567
+ return false;
3568
+ }
3569
+ var _navigator = navigator, userAgent = _navigator.userAgent;
3570
+ return userAgent.includes("AppleWebKit") && !userAgent.includes("Chrome");
3571
+ });
3572
+
3573
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/util/changing-window/count-events-for-safari.js
3574
+ var import_bind_event_listener2 = __toESM(require_dist());
3575
+ var symbols = {
3576
+ isLeavingWindow: /* @__PURE__ */ Symbol("leaving"),
3577
+ isEnteringWindow: /* @__PURE__ */ Symbol("entering")
3578
+ };
3579
+ function isLeavingWindowInSafari(_ref2) {
3580
+ var dragLeave = _ref2.dragLeave;
3581
+ if (!isSafari()) {
3582
+ return false;
3583
+ }
3584
+ return dragLeave.hasOwnProperty(symbols.isLeavingWindow);
3585
+ }
3586
+ (function fixSafari() {
3587
+ if (typeof window === "undefined") {
3588
+ return;
3589
+ }
3590
+ if (false) {
3591
+ return;
3592
+ }
3593
+ if (!isSafari()) {
3594
+ return;
3595
+ }
3596
+ function getInitialState() {
3597
+ return {
3598
+ enterCount: 0,
3599
+ isOverWindow: false
3600
+ };
3601
+ }
3602
+ var state = getInitialState();
3603
+ function resetState() {
3604
+ state = getInitialState();
3605
+ }
3606
+ (0, import_bind_event_listener2.bindAll)(
3607
+ window,
3608
+ [{
3609
+ type: "dragstart",
3610
+ listener: function listener() {
3611
+ state.enterCount = 0;
3612
+ state.isOverWindow = true;
3613
+ }
3614
+ }, {
3615
+ type: "drop",
3616
+ listener: resetState
3617
+ }, {
3618
+ type: "dragend",
3619
+ listener: resetState
3620
+ }, {
3621
+ type: "dragenter",
3622
+ listener: function listener(event) {
3623
+ if (!state.isOverWindow && state.enterCount === 0) {
3624
+ event[symbols.isEnteringWindow] = true;
3625
+ }
3626
+ state.isOverWindow = true;
3627
+ state.enterCount++;
3628
+ }
3629
+ }, {
3630
+ type: "dragleave",
3631
+ listener: function listener(event) {
3632
+ state.enterCount--;
3633
+ if (state.isOverWindow && state.enterCount === 0) {
3634
+ event[symbols.isLeavingWindow] = true;
3635
+ state.isOverWindow = false;
3636
+ }
3637
+ }
3638
+ }],
3639
+ // using `capture: true` so that adding event listeners
3640
+ // in bubble phase will have the correct symbols
3641
+ {
3642
+ capture: true
3643
+ }
3644
+ );
3645
+ })();
3646
+
3647
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/util/changing-window/is-from-another-window.js
3648
+ function isNodeLike(target) {
3649
+ return "nodeName" in target;
3650
+ }
3651
+ function isFromAnotherWindow(eventTarget) {
3652
+ return isNodeLike(eventTarget) && eventTarget.ownerDocument !== document;
3653
+ }
3654
+
3655
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/util/changing-window/is-leaving-window.js
3656
+ function isLeavingWindow(_ref) {
3657
+ var dragLeave = _ref.dragLeave;
3658
+ var type = dragLeave.type, relatedTarget = dragLeave.relatedTarget;
3659
+ if (type !== "dragleave") {
3660
+ return false;
3661
+ }
3662
+ if (isSafari()) {
3663
+ return isLeavingWindowInSafari({
3664
+ dragLeave
3665
+ });
3666
+ }
3667
+ if (relatedTarget == null) {
3668
+ return true;
3669
+ }
3670
+ if (isFirefox()) {
3671
+ return isFromAnotherWindow(relatedTarget);
3672
+ }
3673
+ return relatedTarget instanceof HTMLIFrameElement;
3674
+ }
3675
+
3676
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/util/detect-broken-drag.js
3677
+ function getBindingsForBrokenDrags(_ref) {
3678
+ var onDragEnd = _ref.onDragEnd;
3679
+ return [
3680
+ // ## Detecting drag ending for removed draggables
3681
+ //
3682
+ // If a draggable element is removed during a drag and the user drops:
3683
+ // 1. if over a valid drop target: we get a "drop" event to know the drag is finished
3684
+ // 2. if not over a valid drop target (or cancelled): we get nothing
3685
+ // The "dragend" event will not fire on the source draggable if it has been
3686
+ // removed from the DOM.
3687
+ // So we need to figure out if a drag operation has finished by looking at other events
3688
+ // We can do this by looking at other events
3689
+ // ### First detection: "pointermove" events
3690
+ // 1. "pointermove" events cannot fire during a drag and drop operation
3691
+ // according to the spec. So if we get a "pointermove" it means that
3692
+ // the drag and drop operations has finished. So if we get a "pointermove"
3693
+ // we know that the drag is over
3694
+ // 2. 🦊😤 Drag and drop operations are _supposed_ to suppress
3695
+ // other pointer events. However, firefox will allow a few
3696
+ // pointer event to get through after a drag starts.
3697
+ // The most I've seen is 3
3698
+ {
3699
+ type: "pointermove",
3700
+ listener: /* @__PURE__ */ (function() {
3701
+ var callCount = 0;
3702
+ return function listener() {
3703
+ if (callCount < 20) {
3704
+ callCount++;
3705
+ return;
3706
+ }
3707
+ onDragEnd();
3708
+ };
3709
+ })()
3710
+ },
3711
+ // ### Second detection: "pointerdown" events
3712
+ // If we receive this event then we know that a drag operation has finished
3713
+ // and potentially another one is about to start.
3714
+ // Note: `pointerdown` fires on all browsers / platforms before "dragstart"
3715
+ {
3716
+ type: "pointerdown",
3717
+ listener: onDragEnd
3718
+ }
3719
+ ];
3720
+ }
3721
+
3722
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/util/get-input.js
3723
+ function getInput(event) {
3724
+ return {
3725
+ altKey: event.altKey,
3726
+ button: event.button,
3727
+ buttons: event.buttons,
3728
+ ctrlKey: event.ctrlKey,
3729
+ metaKey: event.metaKey,
3730
+ shiftKey: event.shiftKey,
3731
+ clientX: event.clientX,
3732
+ clientY: event.clientY,
3733
+ pageX: event.pageX,
3734
+ pageY: event.pageY
3735
+ };
3736
+ }
3737
+
3738
+ // node_modules/raf-schd/dist/raf-schd.esm.js
3739
+ var rafSchd = function rafSchd2(fn) {
3740
+ var lastArgs = [];
3741
+ var frameId = null;
3742
+ var wrapperFn = function wrapperFn2() {
3743
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
3744
+ args[_key] = arguments[_key];
3745
+ }
3746
+ lastArgs = args;
3747
+ if (frameId) {
3748
+ return;
3749
+ }
3750
+ frameId = requestAnimationFrame(function() {
3751
+ frameId = null;
3752
+ fn.apply(void 0, lastArgs);
3753
+ });
3754
+ };
3755
+ wrapperFn.cancel = function() {
3756
+ if (!frameId) {
3757
+ return;
3758
+ }
3759
+ cancelAnimationFrame(frameId);
3760
+ frameId = null;
3761
+ };
3762
+ return wrapperFn;
3763
+ };
3764
+ var raf_schd_esm_default = rafSchd;
3765
+
3766
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/ledger/dispatch-consumer-event.js
3767
+ var scheduleOnDrag = raf_schd_esm_default(function(fn) {
3768
+ return fn();
3769
+ });
3770
+ var dragStart = /* @__PURE__ */ (function() {
3771
+ var scheduled = null;
3772
+ function schedule(fn) {
3773
+ var frameId = requestAnimationFrame(function() {
3774
+ scheduled = null;
3775
+ fn();
3776
+ });
3777
+ scheduled = {
3778
+ frameId,
3779
+ fn
3780
+ };
3781
+ }
3782
+ function flush() {
3783
+ if (scheduled) {
3784
+ cancelAnimationFrame(scheduled.frameId);
3785
+ scheduled.fn();
3786
+ scheduled = null;
3787
+ }
3788
+ }
3789
+ return {
3790
+ schedule,
3791
+ flush
3792
+ };
3793
+ })();
3794
+ function makeDispatch(_ref) {
3795
+ var source = _ref.source, initial = _ref.initial, dispatchEvent = _ref.dispatchEvent;
3796
+ var previous = {
3797
+ dropTargets: []
3798
+ };
3799
+ function safeDispatch(args) {
3800
+ dispatchEvent(args);
3801
+ previous = {
3802
+ dropTargets: args.payload.location.current.dropTargets
3803
+ };
3804
+ }
3805
+ var dispatch = {
3806
+ start: function start2(_ref2) {
3807
+ var nativeSetDragImage = _ref2.nativeSetDragImage;
3808
+ var location2 = {
3809
+ current: initial,
3810
+ previous,
3811
+ initial
3812
+ };
3813
+ safeDispatch({
3814
+ eventName: "onGenerateDragPreview",
3815
+ payload: {
3816
+ source,
3817
+ location: location2,
3818
+ nativeSetDragImage
3819
+ }
3820
+ });
3821
+ dragStart.schedule(function() {
3822
+ safeDispatch({
3823
+ eventName: "onDragStart",
3824
+ payload: {
3825
+ source,
3826
+ location: location2
3827
+ }
3828
+ });
3829
+ });
3830
+ },
3831
+ dragUpdate: function dragUpdate(_ref3) {
3832
+ var current = _ref3.current;
3833
+ dragStart.flush();
3834
+ scheduleOnDrag.cancel();
3835
+ safeDispatch({
3836
+ eventName: "onDropTargetChange",
3837
+ payload: {
3838
+ source,
3839
+ location: {
3840
+ initial,
3841
+ previous,
3842
+ current
3843
+ }
3844
+ }
3845
+ });
3846
+ },
3847
+ drag: function drag(_ref4) {
3848
+ var current = _ref4.current;
3849
+ scheduleOnDrag(function() {
3850
+ dragStart.flush();
3851
+ var location2 = {
3852
+ initial,
3853
+ previous,
3854
+ current
3855
+ };
3856
+ safeDispatch({
3857
+ eventName: "onDrag",
3858
+ payload: {
3859
+ source,
3860
+ location: location2
3861
+ }
3862
+ });
3863
+ });
3864
+ },
3865
+ drop: function drop(_ref5) {
3866
+ var current = _ref5.current, updatedSourcePayload = _ref5.updatedSourcePayload;
3867
+ dragStart.flush();
3868
+ scheduleOnDrag.cancel();
3869
+ safeDispatch({
3870
+ eventName: "onDrop",
3871
+ payload: {
3872
+ source: updatedSourcePayload !== null && updatedSourcePayload !== void 0 ? updatedSourcePayload : source,
3873
+ location: {
3874
+ current,
3875
+ previous,
3876
+ initial
3877
+ }
3878
+ }
3879
+ });
3880
+ }
3881
+ };
3882
+ return dispatch;
3883
+ }
3884
+
3885
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/ledger/lifecycle-manager.js
3886
+ var globalState = {
3887
+ isActive: false
3888
+ };
3889
+ function canStart() {
3890
+ return !globalState.isActive;
3891
+ }
3892
+ function getNativeSetDragImage(event) {
3893
+ if (event.dataTransfer) {
3894
+ return event.dataTransfer.setDragImage.bind(event.dataTransfer);
3895
+ }
3896
+ return null;
3897
+ }
3898
+ function hasHierarchyChanged(_ref) {
3899
+ var current = _ref.current, next = _ref.next;
3900
+ if (current.length !== next.length) {
3901
+ return true;
3902
+ }
3903
+ for (var i = 0; i < current.length; i++) {
3904
+ if (current[i].element !== next[i].element) {
3905
+ return true;
3906
+ }
3907
+ }
3908
+ return false;
3909
+ }
3910
+ function start(_ref2) {
3911
+ var event = _ref2.event, dragType = _ref2.dragType, getDropTargetsOver = _ref2.getDropTargetsOver, dispatchEvent = _ref2.dispatchEvent;
3912
+ if (!canStart()) {
3913
+ return;
3914
+ }
3915
+ var initial = getStartLocation({
3916
+ event,
3917
+ dragType,
3918
+ getDropTargetsOver
3919
+ });
3920
+ globalState.isActive = true;
3921
+ var state = {
3922
+ current: initial
3923
+ };
3924
+ setDropEffectOnEvent({
3925
+ event,
3926
+ current: initial.dropTargets
3927
+ });
3928
+ var dispatch = makeDispatch({
3929
+ source: dragType.payload,
3930
+ dispatchEvent,
3931
+ initial
3932
+ });
3933
+ function updateState(next) {
3934
+ var hasChanged = hasHierarchyChanged({
3935
+ current: state.current.dropTargets,
3936
+ next: next.dropTargets
3937
+ });
3938
+ state.current = next;
3939
+ if (hasChanged) {
3940
+ dispatch.dragUpdate({
3941
+ current: state.current
3942
+ });
3943
+ }
3944
+ }
3945
+ function onUpdateEvent(event2) {
3946
+ var input = getInput(event2);
3947
+ var target = isHoneyPotElement(event2.target) ? getElementFromPointWithoutHoneypot({
3948
+ x: input.clientX,
3949
+ y: input.clientY
3950
+ }) : event2.target;
3951
+ var nextDropTargets = getDropTargetsOver({
3952
+ target,
3953
+ input,
3954
+ source: dragType.payload,
3955
+ current: state.current.dropTargets
3956
+ });
3957
+ if (nextDropTargets.length) {
3958
+ event2.preventDefault();
3959
+ setDropEffectOnEvent({
3960
+ event: event2,
3961
+ current: nextDropTargets
3962
+ });
3963
+ }
3964
+ updateState({
3965
+ dropTargets: nextDropTargets,
3966
+ input
3967
+ });
3968
+ }
3969
+ function cancel() {
3970
+ if (state.current.dropTargets.length) {
3971
+ updateState({
3972
+ dropTargets: [],
3973
+ input: state.current.input
3974
+ });
3975
+ }
3976
+ dispatch.drop({
3977
+ current: state.current,
3978
+ updatedSourcePayload: null
3979
+ });
3980
+ finish();
3981
+ }
3982
+ function finish() {
3983
+ globalState.isActive = false;
3984
+ unbindEvents();
3985
+ }
3986
+ var unbindEvents = (0, import_bind_event_listener3.bindAll)(
3987
+ window,
3988
+ [{
3989
+ // 👋 Note: we are repurposing the `dragover` event as our `drag` event
3990
+ // this is because firefox does not publish pointer coordinates during
3991
+ // a `drag` event, but does for every other type of drag event
3992
+ // `dragover` fires on all elements that are being dragged over
3993
+ // Because we are binding to `window` - our `dragover` is effectively the same as a `drag`
3994
+ // 🦊😤
3995
+ type: "dragover",
3996
+ listener: function listener(event2) {
3997
+ onUpdateEvent(event2);
3998
+ dispatch.drag({
3999
+ current: state.current
4000
+ });
4001
+ }
4002
+ }, {
4003
+ type: "dragenter",
4004
+ listener: onUpdateEvent
4005
+ }, {
4006
+ type: "dragleave",
4007
+ listener: function listener(event2) {
4008
+ if (!isLeavingWindow({
4009
+ dragLeave: event2
4010
+ })) {
4011
+ return;
4012
+ }
4013
+ updateState({
4014
+ input: state.current.input,
4015
+ dropTargets: []
4016
+ });
4017
+ if (dragType.startedFrom === "external") {
4018
+ cancel();
4019
+ }
4020
+ }
4021
+ }, {
4022
+ // A "drop" can only happen if the browser allowed the drop
4023
+ type: "drop",
4024
+ listener: function listener(event2) {
4025
+ state.current = {
4026
+ dropTargets: state.current.dropTargets,
4027
+ input: getInput(event2)
4028
+ };
4029
+ if (!state.current.dropTargets.length) {
4030
+ cancel();
4031
+ return;
4032
+ }
4033
+ event2.preventDefault();
4034
+ setDropEffectOnEvent({
4035
+ event: event2,
4036
+ current: state.current.dropTargets
4037
+ });
4038
+ dispatch.drop({
4039
+ current: state.current,
4040
+ // When dropping something native, we need to extract the latest
4041
+ // `.items` from the "drop" event as it is now accessible
4042
+ updatedSourcePayload: dragType.type === "external" ? dragType.getDropPayload(event2) : null
4043
+ });
4044
+ finish();
4045
+ }
4046
+ }, {
4047
+ // "dragend" fires when on the drag source (eg a draggable element)
4048
+ // when the drag is finished.
4049
+ // "dragend" will fire after "drop" (if there was a successful drop)
4050
+ // "dragend" does not fire if the draggable source has been removed during the drag
4051
+ // or for external drag sources (eg files)
4052
+ // This "dragend" listener will not fire if there was a successful drop
4053
+ // as we will have already removed the event listener
4054
+ type: "dragend",
4055
+ listener: function listener(event2) {
4056
+ state.current = {
4057
+ dropTargets: state.current.dropTargets,
4058
+ input: getInput(event2)
4059
+ };
4060
+ cancel();
4061
+ }
4062
+ }].concat(_toConsumableArray(getBindingsForBrokenDrags({
4063
+ onDragEnd: cancel
4064
+ }))),
4065
+ // Once we have started a managed drag operation it is important that we see / own all drag events
4066
+ // We got one adoption bug pop up where some code was stopping (`event.stopPropagation()`)
4067
+ // all "drop" events in the bubble phase on the `document.body`.
4068
+ // This meant that we never saw the "drop" event.
4069
+ {
4070
+ capture: true
4071
+ }
4072
+ );
4073
+ dispatch.start({
4074
+ nativeSetDragImage: getNativeSetDragImage(event)
4075
+ });
4076
+ }
4077
+ function setDropEffectOnEvent(_ref3) {
4078
+ var _current$;
4079
+ var event = _ref3.event, current = _ref3.current;
4080
+ var innerMost = (_current$ = current[0]) === null || _current$ === void 0 ? void 0 : _current$.dropEffect;
4081
+ if (innerMost != null && event.dataTransfer) {
4082
+ event.dataTransfer.dropEffect = innerMost;
4083
+ }
4084
+ }
4085
+ function getStartLocation(_ref4) {
4086
+ var event = _ref4.event, dragType = _ref4.dragType, getDropTargetsOver = _ref4.getDropTargetsOver;
4087
+ var input = getInput(event);
4088
+ if (dragType.startedFrom === "external") {
4089
+ return {
4090
+ input,
4091
+ dropTargets: []
4092
+ };
4093
+ }
4094
+ var dropTargets = getDropTargetsOver({
4095
+ input,
4096
+ source: dragType.payload,
4097
+ target: event.target,
4098
+ current: []
4099
+ });
4100
+ return {
4101
+ input,
4102
+ dropTargets
4103
+ };
4104
+ }
4105
+ var lifecycle = {
4106
+ canStart,
4107
+ start
4108
+ };
4109
+
4110
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/ledger/usage-ledger.js
4111
+ var ledger = /* @__PURE__ */ new Map();
4112
+ function registerUsage(_ref) {
4113
+ var typeKey = _ref.typeKey, mount2 = _ref.mount;
4114
+ var entry = ledger.get(typeKey);
4115
+ if (entry) {
4116
+ entry.usageCount++;
4117
+ return entry;
4118
+ }
4119
+ var initial = {
4120
+ typeKey,
4121
+ unmount: mount2(),
4122
+ usageCount: 1
4123
+ };
4124
+ ledger.set(typeKey, initial);
4125
+ return initial;
4126
+ }
4127
+ function register(args) {
4128
+ var entry = registerUsage(args);
4129
+ return function unregister() {
4130
+ entry.usageCount--;
4131
+ if (entry.usageCount > 0) {
4132
+ return;
4133
+ }
4134
+ entry.unmount();
4135
+ ledger.delete(args.typeKey);
4136
+ };
4137
+ }
4138
+
4139
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/public-utils/combine.js
4140
+ function combine() {
4141
+ for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {
4142
+ fns[_key] = arguments[_key];
4143
+ }
4144
+ return function cleanup() {
4145
+ fns.forEach(function(fn) {
4146
+ return fn();
4147
+ });
4148
+ };
4149
+ }
4150
+
4151
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/util/add-attribute.js
4152
+ function addAttribute(element, _ref) {
4153
+ var attribute = _ref.attribute, value = _ref.value;
4154
+ element.setAttribute(attribute, value);
4155
+ return function() {
4156
+ return element.removeAttribute(attribute);
4157
+ };
4158
+ }
4159
+
4160
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/make-adapter/make-drop-target.js
4161
+ function ownKeys2(e, r) {
4162
+ var t = Object.keys(e);
4163
+ if (Object.getOwnPropertySymbols) {
4164
+ var o = Object.getOwnPropertySymbols(e);
4165
+ r && (o = o.filter(function(r2) {
4166
+ return Object.getOwnPropertyDescriptor(e, r2).enumerable;
4167
+ })), t.push.apply(t, o);
4168
+ }
4169
+ return t;
4170
+ }
4171
+ function _objectSpread2(e) {
4172
+ for (var r = 1; r < arguments.length; r++) {
4173
+ var t = null != arguments[r] ? arguments[r] : {};
4174
+ r % 2 ? ownKeys2(Object(t), true).forEach(function(r2) {
4175
+ _defineProperty(e, r2, t[r2]);
4176
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys2(Object(t)).forEach(function(r2) {
4177
+ Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
4178
+ });
4179
+ }
4180
+ return e;
4181
+ }
4182
+ function _createForOfIteratorHelper(r, e) {
4183
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
4184
+ if (!t) {
4185
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray2(r)) || e && r && "number" == typeof r.length) {
4186
+ t && (r = t);
4187
+ var _n = 0, F = function F2() {
4188
+ };
4189
+ return { s: F, n: function n() {
4190
+ return _n >= r.length ? { done: true } : { done: false, value: r[_n++] };
4191
+ }, e: function e2(r2) {
4192
+ throw r2;
4193
+ }, f: F };
4194
+ }
4195
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
4196
+ }
4197
+ var o, a = true, u = false;
4198
+ return { s: function s() {
4199
+ t = t.call(r);
4200
+ }, n: function n() {
4201
+ var r2 = t.next();
4202
+ return a = r2.done, r2;
4203
+ }, e: function e2(r2) {
4204
+ u = true, o = r2;
4205
+ }, f: function f() {
4206
+ try {
4207
+ a || null == t.return || t.return();
4208
+ } finally {
4209
+ if (u) throw o;
4210
+ }
4211
+ } };
4212
+ }
4213
+ function _unsupportedIterableToArray2(r, a) {
4214
+ if (r) {
4215
+ if ("string" == typeof r) return _arrayLikeToArray2(r, a);
4216
+ var t = {}.toString.call(r).slice(8, -1);
4217
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray2(r, a) : void 0;
4218
+ }
4219
+ }
4220
+ function _arrayLikeToArray2(r, a) {
4221
+ (null == a || a > r.length) && (a = r.length);
4222
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
4223
+ return n;
4224
+ }
4225
+ function copyReverse(array) {
4226
+ return array.slice(0).reverse();
4227
+ }
4228
+ function makeDropTarget(_ref) {
4229
+ var typeKey = _ref.typeKey, defaultDropEffect = _ref.defaultDropEffect;
4230
+ var registry = /* @__PURE__ */ new WeakMap();
4231
+ var dropTargetDataAtt = "data-drop-target-for-".concat(typeKey);
4232
+ var dropTargetSelector = "[".concat(dropTargetDataAtt, "]");
4233
+ function addToRegistry2(args) {
4234
+ registry.set(args.element, args);
4235
+ return function() {
4236
+ return registry.delete(args.element);
4237
+ };
4238
+ }
4239
+ function dropTargetForConsumers(args) {
4240
+ if (true) {
4241
+ var existing = registry.get(args.element);
4242
+ if (existing) {
4243
+ console.warn("You have already registered a [".concat(typeKey, "] dropTarget on the same element"), {
4244
+ existing,
4245
+ proposed: args
4246
+ });
4247
+ }
4248
+ if (args.element instanceof HTMLIFrameElement) {
4249
+ console.warn("\n We recommend not registering <iframe> elements as drop targets\n as it can result in some strange browser event ordering.\n ".replace(/\s{2,}/g, " ").trim());
4250
+ }
4251
+ }
4252
+ var cleanup = combine(addAttribute(args.element, {
4253
+ attribute: dropTargetDataAtt,
4254
+ value: "true"
4255
+ }), addToRegistry2(args));
4256
+ return once(cleanup);
4257
+ }
4258
+ function getActualDropTargets(_ref2) {
4259
+ var _args$getData, _args$getData2, _args$getDropEffect, _args$getDropEffect2;
4260
+ var source = _ref2.source, target = _ref2.target, input = _ref2.input, _ref2$result = _ref2.result, result = _ref2$result === void 0 ? [] : _ref2$result;
4261
+ if (target == null) {
4262
+ return result;
4263
+ }
4264
+ if (!(target instanceof Element)) {
4265
+ if (target instanceof Node) {
4266
+ return getActualDropTargets({
4267
+ source,
4268
+ target: target.parentElement,
4269
+ input,
4270
+ result
4271
+ });
4272
+ }
4273
+ return result;
4274
+ }
4275
+ var closest = target.closest(dropTargetSelector);
4276
+ if (closest == null) {
4277
+ return result;
4278
+ }
4279
+ var args = registry.get(closest);
4280
+ if (args == null) {
4281
+ return result;
4282
+ }
4283
+ var feedback = {
4284
+ input,
4285
+ source,
4286
+ element: args.element
4287
+ };
4288
+ if (args.canDrop && !args.canDrop(feedback)) {
4289
+ return getActualDropTargets({
4290
+ source,
4291
+ target: args.element.parentElement,
4292
+ input,
4293
+ result
4294
+ });
4295
+ }
4296
+ var data = (_args$getData = (_args$getData2 = args.getData) === null || _args$getData2 === void 0 ? void 0 : _args$getData2.call(args, feedback)) !== null && _args$getData !== void 0 ? _args$getData : {};
4297
+ var dropEffect = (_args$getDropEffect = (_args$getDropEffect2 = args.getDropEffect) === null || _args$getDropEffect2 === void 0 ? void 0 : _args$getDropEffect2.call(args, feedback)) !== null && _args$getDropEffect !== void 0 ? _args$getDropEffect : defaultDropEffect;
4298
+ var record = {
4299
+ data,
4300
+ element: args.element,
4301
+ dropEffect,
4302
+ // we are collecting _actual_ drop targets, so these are
4303
+ // being applied _not_ due to stickiness
4304
+ isActiveDueToStickiness: false
4305
+ };
4306
+ return getActualDropTargets({
4307
+ source,
4308
+ target: args.element.parentElement,
4309
+ input,
4310
+ // Using bubble ordering. Same ordering as `event.getPath()`
4311
+ result: [].concat(_toConsumableArray(result), [record])
4312
+ });
4313
+ }
4314
+ function notifyCurrent(_ref3) {
4315
+ var eventName = _ref3.eventName, payload = _ref3.payload;
4316
+ var _iterator = _createForOfIteratorHelper(payload.location.current.dropTargets), _step;
4317
+ try {
4318
+ for (_iterator.s(); !(_step = _iterator.n()).done; ) {
4319
+ var _entry$eventName;
4320
+ var record = _step.value;
4321
+ var entry = registry.get(record.element);
4322
+ var args = _objectSpread2(_objectSpread2({}, payload), {}, {
4323
+ self: record
4324
+ });
4325
+ entry === null || entry === void 0 || (_entry$eventName = entry[eventName]) === null || _entry$eventName === void 0 || _entry$eventName.call(
4326
+ entry,
4327
+ // I cannot seem to get the types right here.
4328
+ // TS doesn't seem to like that one event can need `nativeSetDragImage`
4329
+ // @ts-expect-error
4330
+ args
4331
+ );
4332
+ }
4333
+ } catch (err) {
4334
+ _iterator.e(err);
4335
+ } finally {
4336
+ _iterator.f();
4337
+ }
4338
+ }
4339
+ var actions = {
4340
+ onGenerateDragPreview: notifyCurrent,
4341
+ onDrag: notifyCurrent,
4342
+ onDragStart: notifyCurrent,
4343
+ onDrop: notifyCurrent,
4344
+ onDropTargetChange: function onDropTargetChange(_ref4) {
4345
+ var payload = _ref4.payload;
4346
+ var isCurrent = new Set(payload.location.current.dropTargets.map(function(record2) {
4347
+ return record2.element;
4348
+ }));
4349
+ var visited = /* @__PURE__ */ new Set();
4350
+ var _iterator2 = _createForOfIteratorHelper(payload.location.previous.dropTargets), _step2;
4351
+ try {
4352
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done; ) {
4353
+ var _entry$onDropTargetCh;
4354
+ var record = _step2.value;
4355
+ visited.add(record.element);
4356
+ var entry = registry.get(record.element);
4357
+ var isOver = isCurrent.has(record.element);
4358
+ var args = _objectSpread2(_objectSpread2({}, payload), {}, {
4359
+ self: record
4360
+ });
4361
+ entry === null || entry === void 0 || (_entry$onDropTargetCh = entry.onDropTargetChange) === null || _entry$onDropTargetCh === void 0 || _entry$onDropTargetCh.call(entry, args);
4362
+ if (!isOver) {
4363
+ var _entry$onDragLeave;
4364
+ entry === null || entry === void 0 || (_entry$onDragLeave = entry.onDragLeave) === null || _entry$onDragLeave === void 0 || _entry$onDragLeave.call(entry, args);
4365
+ }
4366
+ }
4367
+ } catch (err) {
4368
+ _iterator2.e(err);
4369
+ } finally {
4370
+ _iterator2.f();
4371
+ }
4372
+ var _iterator3 = _createForOfIteratorHelper(payload.location.current.dropTargets), _step3;
4373
+ try {
4374
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done; ) {
4375
+ var _entry$onDropTargetCh2, _entry$onDragEnter;
4376
+ var _record = _step3.value;
4377
+ if (visited.has(_record.element)) {
4378
+ continue;
4379
+ }
4380
+ var _args = _objectSpread2(_objectSpread2({}, payload), {}, {
4381
+ self: _record
4382
+ });
4383
+ var _entry = registry.get(_record.element);
4384
+ _entry === null || _entry === void 0 || (_entry$onDropTargetCh2 = _entry.onDropTargetChange) === null || _entry$onDropTargetCh2 === void 0 || _entry$onDropTargetCh2.call(_entry, _args);
4385
+ _entry === null || _entry === void 0 || (_entry$onDragEnter = _entry.onDragEnter) === null || _entry$onDragEnter === void 0 || _entry$onDragEnter.call(_entry, _args);
4386
+ }
4387
+ } catch (err) {
4388
+ _iterator3.e(err);
4389
+ } finally {
4390
+ _iterator3.f();
4391
+ }
4392
+ }
4393
+ };
4394
+ function dispatchEvent(args) {
4395
+ actions[args.eventName](args);
4396
+ }
4397
+ function getIsOver(_ref5) {
4398
+ var source = _ref5.source, target = _ref5.target, input = _ref5.input, current = _ref5.current;
4399
+ var actual = getActualDropTargets({
4400
+ source,
4401
+ target,
4402
+ input
4403
+ });
4404
+ if (actual.length >= current.length) {
4405
+ return actual;
4406
+ }
4407
+ var lastCaptureOrdered = copyReverse(current);
4408
+ var actualCaptureOrdered = copyReverse(actual);
4409
+ var resultCaptureOrdered = [];
4410
+ for (var index = 0; index < lastCaptureOrdered.length; index++) {
4411
+ var _argsForLast$getIsSti;
4412
+ var last = lastCaptureOrdered[index];
4413
+ var fresh = actualCaptureOrdered[index];
4414
+ if (fresh != null) {
4415
+ resultCaptureOrdered.push(fresh);
4416
+ continue;
4417
+ }
4418
+ var parent = resultCaptureOrdered[index - 1];
4419
+ var lastParent = lastCaptureOrdered[index - 1];
4420
+ if ((parent === null || parent === void 0 ? void 0 : parent.element) !== (lastParent === null || lastParent === void 0 ? void 0 : lastParent.element)) {
4421
+ break;
4422
+ }
4423
+ var argsForLast = registry.get(last.element);
4424
+ if (!argsForLast) {
4425
+ break;
4426
+ }
4427
+ var feedback = {
4428
+ input,
4429
+ source,
4430
+ element: argsForLast.element
4431
+ };
4432
+ if (argsForLast.canDrop && !argsForLast.canDrop(feedback)) {
4433
+ break;
4434
+ }
4435
+ if (!((_argsForLast$getIsSti = argsForLast.getIsSticky) !== null && _argsForLast$getIsSti !== void 0 && _argsForLast$getIsSti.call(argsForLast, feedback))) {
4436
+ break;
4437
+ }
4438
+ resultCaptureOrdered.push(_objectSpread2(_objectSpread2({}, last), {}, {
4439
+ // making it clear to consumers this drop target is active due to stickiness
4440
+ isActiveDueToStickiness: true
4441
+ }));
4442
+ }
4443
+ return copyReverse(resultCaptureOrdered);
4444
+ }
4445
+ return {
4446
+ dropTargetForConsumers,
4447
+ getIsOver,
4448
+ dispatchEvent
4449
+ };
4450
+ }
4451
+
4452
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/make-adapter/make-monitor.js
4453
+ function _createForOfIteratorHelper2(r, e) {
4454
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
4455
+ if (!t) {
4456
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray3(r)) || e && r && "number" == typeof r.length) {
4457
+ t && (r = t);
4458
+ var _n = 0, F = function F2() {
4459
+ };
4460
+ return { s: F, n: function n() {
4461
+ return _n >= r.length ? { done: true } : { done: false, value: r[_n++] };
4462
+ }, e: function e2(r2) {
4463
+ throw r2;
4464
+ }, f: F };
4465
+ }
4466
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
4467
+ }
4468
+ var o, a = true, u = false;
4469
+ return { s: function s() {
4470
+ t = t.call(r);
4471
+ }, n: function n() {
4472
+ var r2 = t.next();
4473
+ return a = r2.done, r2;
4474
+ }, e: function e2(r2) {
4475
+ u = true, o = r2;
4476
+ }, f: function f() {
4477
+ try {
4478
+ a || null == t.return || t.return();
4479
+ } finally {
4480
+ if (u) throw o;
4481
+ }
4482
+ } };
4483
+ }
4484
+ function _unsupportedIterableToArray3(r, a) {
4485
+ if (r) {
4486
+ if ("string" == typeof r) return _arrayLikeToArray3(r, a);
4487
+ var t = {}.toString.call(r).slice(8, -1);
4488
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray3(r, a) : void 0;
4489
+ }
4490
+ }
4491
+ function _arrayLikeToArray3(r, a) {
4492
+ (null == a || a > r.length) && (a = r.length);
4493
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
4494
+ return n;
4495
+ }
4496
+ function ownKeys3(e, r) {
4497
+ var t = Object.keys(e);
4498
+ if (Object.getOwnPropertySymbols) {
4499
+ var o = Object.getOwnPropertySymbols(e);
4500
+ r && (o = o.filter(function(r2) {
4501
+ return Object.getOwnPropertyDescriptor(e, r2).enumerable;
4502
+ })), t.push.apply(t, o);
4503
+ }
4504
+ return t;
4505
+ }
4506
+ function _objectSpread3(e) {
4507
+ for (var r = 1; r < arguments.length; r++) {
4508
+ var t = null != arguments[r] ? arguments[r] : {};
4509
+ r % 2 ? ownKeys3(Object(t), true).forEach(function(r2) {
4510
+ _defineProperty(e, r2, t[r2]);
4511
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys3(Object(t)).forEach(function(r2) {
4512
+ Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
4513
+ });
4514
+ }
4515
+ return e;
4516
+ }
4517
+ function makeMonitor() {
4518
+ var registry = /* @__PURE__ */ new Set();
4519
+ var dragging = null;
4520
+ function tryAddToActive(monitor) {
4521
+ if (!dragging) {
4522
+ return;
4523
+ }
4524
+ if (!monitor.canMonitor || monitor.canMonitor(dragging.canMonitorArgs)) {
4525
+ dragging.active.add(monitor);
4526
+ }
4527
+ }
4528
+ function monitorForConsumers(args) {
4529
+ var entry = _objectSpread3({}, args);
4530
+ registry.add(entry);
4531
+ tryAddToActive(entry);
4532
+ function cleanup() {
4533
+ registry.delete(entry);
4534
+ if (dragging) {
4535
+ dragging.active.delete(entry);
4536
+ }
4537
+ }
4538
+ return once(cleanup);
4539
+ }
4540
+ function dispatchEvent(_ref) {
4541
+ var eventName = _ref.eventName, payload = _ref.payload;
4542
+ if (eventName === "onGenerateDragPreview") {
4543
+ dragging = {
4544
+ canMonitorArgs: {
4545
+ initial: payload.location.initial,
4546
+ source: payload.source
4547
+ },
4548
+ active: /* @__PURE__ */ new Set()
4549
+ };
4550
+ var _iterator = _createForOfIteratorHelper2(registry), _step;
4551
+ try {
4552
+ for (_iterator.s(); !(_step = _iterator.n()).done; ) {
4553
+ var monitor = _step.value;
4554
+ tryAddToActive(monitor);
4555
+ }
4556
+ } catch (err) {
4557
+ _iterator.e(err);
4558
+ } finally {
4559
+ _iterator.f();
4560
+ }
4561
+ }
4562
+ if (!dragging) {
4563
+ return;
4564
+ }
4565
+ var active = Array.from(dragging.active);
4566
+ for (var _i = 0, _active = active; _i < _active.length; _i++) {
4567
+ var _monitor = _active[_i];
4568
+ if (dragging.active.has(_monitor)) {
4569
+ var _monitor$eventName;
4570
+ (_monitor$eventName = _monitor[eventName]) === null || _monitor$eventName === void 0 || _monitor$eventName.call(_monitor, payload);
4571
+ }
4572
+ }
4573
+ if (eventName === "onDrop") {
4574
+ dragging.active.clear();
4575
+ dragging = null;
4576
+ }
4577
+ }
4578
+ return {
4579
+ dispatchEvent,
4580
+ monitorForConsumers
4581
+ };
4582
+ }
4583
+
4584
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/make-adapter/make-adapter.js
4585
+ function makeAdapter(_ref) {
4586
+ var typeKey = _ref.typeKey, mount2 = _ref.mount, dispatchEventToSource2 = _ref.dispatchEventToSource, onPostDispatch = _ref.onPostDispatch, defaultDropEffect = _ref.defaultDropEffect;
4587
+ var monitorAPI = makeMonitor();
4588
+ var dropTargetAPI = makeDropTarget({
4589
+ typeKey,
4590
+ defaultDropEffect
4591
+ });
4592
+ function dispatchEvent(args) {
4593
+ dispatchEventToSource2 === null || dispatchEventToSource2 === void 0 || dispatchEventToSource2(args);
4594
+ dropTargetAPI.dispatchEvent(args);
4595
+ monitorAPI.dispatchEvent(args);
4596
+ onPostDispatch === null || onPostDispatch === void 0 || onPostDispatch(args);
4597
+ }
4598
+ function start2(_ref2) {
4599
+ var event = _ref2.event, dragType = _ref2.dragType;
4600
+ lifecycle.start({
4601
+ event,
4602
+ dragType,
4603
+ getDropTargetsOver: dropTargetAPI.getIsOver,
4604
+ dispatchEvent
4605
+ });
4606
+ }
4607
+ function registerUsage2() {
4608
+ function mountAdapter() {
4609
+ var api2 = {
4610
+ canStart: lifecycle.canStart,
4611
+ start: start2
4612
+ };
4613
+ return mount2(api2);
4614
+ }
4615
+ return register({
4616
+ typeKey,
4617
+ mount: mountAdapter
4618
+ });
4619
+ }
4620
+ return {
4621
+ registerUsage: registerUsage2,
4622
+ dropTarget: dropTargetAPI.dropTargetForConsumers,
4623
+ monitor: monitorAPI.monitorForConsumers
4624
+ };
4625
+ }
4626
+
4627
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/util/android.js
4628
+ var isAndroid = once(function isAndroid2() {
4629
+ return navigator.userAgent.toLocaleLowerCase().includes("android");
4630
+ });
4631
+ var androidFallbackText = "pdnd:android-fallback";
4632
+
4633
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/util/media-types/text-media-type.js
4634
+ var textMediaType = "text/plain";
4635
+
4636
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/util/media-types/url-media-type.js
4637
+ var URLMediaType = "text/uri-list";
4638
+
4639
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/adapter/element-adapter-native-data-key.js
4640
+ var elementAdapterNativeDataKey = "application/vnd.pdnd";
4641
+
4642
+ // node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/adapter/element-adapter.js
4643
+ var draggableRegistry = /* @__PURE__ */ new WeakMap();
4644
+ function addToRegistry(args) {
4645
+ draggableRegistry.set(args.element, args);
4646
+ return function cleanup() {
4647
+ draggableRegistry.delete(args.element);
4648
+ };
4649
+ }
4650
+ var honeyPotFix = makeHoneyPotFix();
4651
+ var adapter = makeAdapter({
4652
+ typeKey: "element",
4653
+ defaultDropEffect: "move",
4654
+ mount: function mount(api2) {
4655
+ return combine(honeyPotFix.bindEvents(), (0, import_bind_event_listener4.bind)(document, {
4656
+ type: "dragstart",
4657
+ listener: function listener(event) {
4658
+ var _entry$dragHandle, _entry$getInitialData, _entry$getInitialData2, _entry$dragHandle2, _entry$getInitialData3, _entry$getInitialData4;
4659
+ if (!api2.canStart(event)) {
4660
+ return;
4661
+ }
4662
+ if (event.defaultPrevented) {
4663
+ return;
4664
+ }
4665
+ if (!event.dataTransfer) {
4666
+ if (true) {
4667
+ console.warn("\n It appears as though you have are not testing DragEvents correctly.\n\n - If you are unit testing, ensure you have polyfilled DragEvent.\n - If you are browser testing, ensure you are dispatching drag events correctly.\n\n Please see our testing guides for more information:\n https://atlassian.design/components/pragmatic-drag-and-drop/core-package/testing\n ".replace(/ {2}/g, ""));
4668
+ }
4669
+ return;
4670
+ }
4671
+ var target = event.target;
4672
+ if (!(target instanceof HTMLElement)) {
4673
+ return;
4674
+ }
4675
+ var entry = draggableRegistry.get(target);
4676
+ if (!entry) {
4677
+ return;
4678
+ }
4679
+ var input = getInput(event);
4680
+ var feedback = {
4681
+ element: entry.element,
4682
+ dragHandle: (_entry$dragHandle = entry.dragHandle) !== null && _entry$dragHandle !== void 0 ? _entry$dragHandle : null,
4683
+ input
4684
+ };
4685
+ if (entry.canDrag && !entry.canDrag(feedback)) {
4686
+ event.preventDefault();
4687
+ return;
4688
+ }
4689
+ if (entry.dragHandle) {
4690
+ var over = getElementFromPointWithoutHoneypot({
4691
+ x: input.clientX,
4692
+ y: input.clientY
4693
+ });
4694
+ if (!entry.dragHandle.contains(over)) {
4695
+ event.preventDefault();
4696
+ return;
4697
+ }
4698
+ }
4699
+ var nativeData = (_entry$getInitialData = (_entry$getInitialData2 = entry.getInitialDataForExternal) === null || _entry$getInitialData2 === void 0 ? void 0 : _entry$getInitialData2.call(entry, feedback)) !== null && _entry$getInitialData !== void 0 ? _entry$getInitialData : null;
4700
+ if (nativeData) {
4701
+ for (var _i = 0, _Object$entries = Object.entries(nativeData); _i < _Object$entries.length; _i++) {
4702
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), key = _Object$entries$_i[0], data = _Object$entries$_i[1];
4703
+ event.dataTransfer.setData(key, data !== null && data !== void 0 ? data : "");
4704
+ }
4705
+ }
4706
+ if (isAndroid() && !event.dataTransfer.types.includes(textMediaType) && !event.dataTransfer.types.includes(URLMediaType)) {
4707
+ event.dataTransfer.setData(textMediaType, androidFallbackText);
4708
+ }
4709
+ event.dataTransfer.setData(elementAdapterNativeDataKey, "");
4710
+ var payload = {
4711
+ element: entry.element,
4712
+ dragHandle: (_entry$dragHandle2 = entry.dragHandle) !== null && _entry$dragHandle2 !== void 0 ? _entry$dragHandle2 : null,
4713
+ data: (_entry$getInitialData3 = (_entry$getInitialData4 = entry.getInitialData) === null || _entry$getInitialData4 === void 0 ? void 0 : _entry$getInitialData4.call(entry, feedback)) !== null && _entry$getInitialData3 !== void 0 ? _entry$getInitialData3 : {}
4714
+ };
4715
+ var dragType = {
4716
+ type: "element",
4717
+ payload,
4718
+ startedFrom: "internal"
4719
+ };
4720
+ api2.start({
4721
+ event,
4722
+ dragType
4723
+ });
4724
+ }
4725
+ }));
4726
+ },
4727
+ dispatchEventToSource: function dispatchEventToSource(_ref) {
4728
+ var _draggableRegistry$ge, _draggableRegistry$ge2;
4729
+ var eventName = _ref.eventName, payload = _ref.payload;
4730
+ (_draggableRegistry$ge = draggableRegistry.get(payload.source.element)) === null || _draggableRegistry$ge === void 0 || (_draggableRegistry$ge2 = _draggableRegistry$ge[eventName]) === null || _draggableRegistry$ge2 === void 0 || _draggableRegistry$ge2.call(
4731
+ _draggableRegistry$ge,
4732
+ // I cannot seem to get the types right here.
4733
+ // TS doesn't seem to like that one event can need `nativeSetDragImage`
4734
+ // @ts-expect-error
4735
+ payload
4736
+ );
4737
+ },
4738
+ onPostDispatch: honeyPotFix.getOnPostDispatch()
4739
+ });
4740
+ var dropTargetForElements = adapter.dropTarget;
4741
+ var monitorForElements = adapter.monitor;
4742
+ function draggable(args) {
4743
+ if (true) {
4744
+ if (args.dragHandle && !args.element.contains(args.dragHandle)) {
4745
+ console.warn("Drag handle element must be contained in draggable element", {
4746
+ element: args.element,
4747
+ dragHandle: args.dragHandle
4748
+ });
4749
+ }
4750
+ }
4751
+ if (true) {
4752
+ var existing = draggableRegistry.get(args.element);
4753
+ if (existing) {
4754
+ console.warn("You have already registered a `draggable` on the same element", {
4755
+ existing,
4756
+ proposed: args
4757
+ });
4758
+ }
4759
+ }
4760
+ var cleanup = combine(
4761
+ // making the draggable register the adapter rather than drop targets
4762
+ // this is because you *must* have a draggable element to start a drag
4763
+ // but you _might_ not have any drop targets immediately
4764
+ // (You might create drop targets async)
4765
+ adapter.registerUsage(),
4766
+ addToRegistry(args),
4767
+ addAttribute(args.element, {
4768
+ attribute: "draggable",
4769
+ value: "true"
4770
+ })
4771
+ );
4772
+ return once(cleanup);
4773
+ }
4774
+
4775
+ // node_modules/@atlaskit/pragmatic-drag-and-drop-auto-scroll/dist/esm/shared/engagement-history.js
4776
+ var ledger2 = /* @__PURE__ */ new Map();
4777
+ var requested = /* @__PURE__ */ new Set();
4778
+ function markAndGetEngagement(element) {
4779
+ markEngagement(element);
4780
+ var entry = ledger2.get(element);
4781
+ if (entry) {
4782
+ return entry;
4783
+ }
4784
+ var fresh = {
4785
+ timeOfEngagementStart: Date.now()
4786
+ };
4787
+ ledger2.set(element, fresh);
4788
+ return fresh;
4789
+ }
4790
+ function markEngagement(element) {
4791
+ requested.add(element);
4792
+ }
4793
+ function clearUnusedEngagements(fn) {
4794
+ requested.clear();
4795
+ fn();
4796
+ ledger2.forEach(function(_, element) {
4797
+ if (!requested.has(element)) {
4798
+ ledger2.delete(element);
4799
+ }
4800
+ });
4801
+ requested.clear();
4802
+ }
4803
+ function clearEngagementHistory() {
4804
+ ledger2.clear();
4805
+ }
4806
+
4807
+ // node_modules/@atlaskit/pragmatic-drag-and-drop-auto-scroll/dist/esm/shared/scheduler.js
4808
+ var schedulers = /* @__PURE__ */ new Map();
4809
+ function getScheduler(monitor) {
4810
+ var scheduler = schedulers.get(monitor);
4811
+ if (scheduler) {
4812
+ return scheduler;
4813
+ }
4814
+ var created = makeScheduler(monitor);
4815
+ schedulers.set(monitor, created);
4816
+ return created;
4817
+ }
4818
+ function makeScheduler(monitor) {
4819
+ var state = {
4820
+ type: "idle"
4821
+ };
4822
+ var callbacks = [];
4823
+ function loop(timeLastFrameFinished) {
4824
+ if (state.type !== "running") {
4825
+ return;
4826
+ }
4827
+ var timeSinceLastFrame = timeLastFrameFinished - state.timeLastFrameFinished;
4828
+ var _state = state, latestArgs = _state.latestArgs;
4829
+ var underUsersPointer = getElementFromPointWithoutHoneypot({
4830
+ x: latestArgs.location.current.input.clientX,
4831
+ y: latestArgs.location.current.input.clientY
4832
+ });
4833
+ clearUnusedEngagements(function() {
4834
+ callbacks.forEach(function(onFrame) {
4835
+ return onFrame({
4836
+ underUsersPointer,
4837
+ latestArgs,
4838
+ timeSinceLastFrame
4839
+ });
4840
+ });
4841
+ });
4842
+ state.timeLastFrameFinished = timeLastFrameFinished;
4843
+ state.frameId = requestAnimationFrame(loop);
4844
+ }
4845
+ function reset() {
4846
+ if (state.type === "idle") {
4847
+ return;
4848
+ }
4849
+ cancelAnimationFrame(state.frameId);
4850
+ clearEngagementHistory();
4851
+ state = {
4852
+ type: "idle"
4853
+ };
4854
+ }
4855
+ function start2(args) {
4856
+ if (state.type !== "idle") {
4857
+ return;
4858
+ }
4859
+ state = {
4860
+ // Waiting a frame so we can accurately determine `timeSinceLastFrame`.
4861
+ type: "initializing",
4862
+ latestArgs: args,
4863
+ frameId: requestAnimationFrame(function(timeLastFrameFinished) {
4864
+ if (state.type !== "initializing") {
4865
+ return;
4866
+ }
4867
+ state = {
4868
+ type: "running",
4869
+ timeLastFrameFinished,
4870
+ latestArgs: state.latestArgs,
4871
+ frameId: requestAnimationFrame(loop)
4872
+ };
4873
+ })
4874
+ };
4875
+ }
4876
+ function update(args) {
4877
+ if (state.type === "idle") {
4878
+ start2(args);
4879
+ return;
4880
+ }
4881
+ state.latestArgs = args;
4882
+ }
4883
+ monitor({
4884
+ onDragStart: start2,
4885
+ onDropTargetChange: update,
4886
+ onDrag: update,
4887
+ onDrop: reset
4888
+ });
4889
+ var api2 = {
4890
+ onFrame: function onFrame(fn) {
4891
+ callbacks.push(fn);
4892
+ }
4893
+ };
4894
+ return api2;
4895
+ }
4896
+
4897
+ // node_modules/@atlaskit/pragmatic-drag-and-drop-auto-scroll/dist/esm/over-element/data-attributes.js
4898
+ var dataAttribute = "data-auto-scrollable";
4899
+ var selector = "[".concat(dataAttribute, '="true"]');
4900
+ function addScrollableAttribute(element) {
4901
+ element.setAttribute(dataAttribute, "true");
4902
+ return function() {
4903
+ return element.removeAttribute(dataAttribute);
4904
+ };
4905
+ }
4906
+
4907
+ // node_modules/@atlaskit/pragmatic-drag-and-drop-auto-scroll/dist/esm/shared/configuration.js
4908
+ function ownKeys4(e, r) {
4909
+ var t = Object.keys(e);
4910
+ if (Object.getOwnPropertySymbols) {
4911
+ var o = Object.getOwnPropertySymbols(e);
4912
+ r && (o = o.filter(function(r2) {
4913
+ return Object.getOwnPropertyDescriptor(e, r2).enumerable;
4914
+ })), t.push.apply(t, o);
4915
+ }
4916
+ return t;
4917
+ }
4918
+ function _objectSpread4(e) {
4919
+ for (var r = 1; r < arguments.length; r++) {
4920
+ var t = null != arguments[r] ? arguments[r] : {};
4921
+ r % 2 ? ownKeys4(Object(t), true).forEach(function(r2) {
4922
+ _defineProperty(e, r2, t[r2]);
4923
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys4(Object(t)).forEach(function(r2) {
4924
+ Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
4925
+ });
4926
+ }
4927
+ return e;
4928
+ }
4929
+ var baseConfig = {
4930
+ startHitboxAtPercentageRemainingOfElement: {
4931
+ top: 0.25,
4932
+ right: 0.25,
4933
+ bottom: 0.25,
4934
+ left: 0.25
4935
+ },
4936
+ maxScrollAtPercentageRemainingOfHitbox: {
4937
+ top: 0.5,
4938
+ right: 0.5,
4939
+ bottom: 0.5,
4940
+ left: 0.5
4941
+ },
4942
+ timeDampeningDurationMs: 400,
4943
+ // Too big and it's too easy to trigger auto scrolling
4944
+ // Too small and it's too hard 😅
4945
+ maxMainAxisHitboxSize: 180
4946
+ };
4947
+ var maxPixelScrollPerSecond = {
4948
+ // What the value would be if we were scrolling at 15px per frame at 60fps.
4949
+ // This is the default as it works well for most experiences.
4950
+ // In certain scenarios though it can feel a bit slow.
4951
+ standard: 15 * 60,
4952
+ // What the value would be if we were scrolling at 25px per frame at 60fps.
4953
+ // This is not the default as it feels too fast for a lot of experiences.
4954
+ fast: 25 * 60
4955
+ };
4956
+ function getInternalConfig(provided) {
4957
+ var _provided$maxScrollSp;
4958
+ return _objectSpread4(_objectSpread4({}, baseConfig), {}, {
4959
+ // only allowing limited control over the config at this stage
4960
+ maxPixelScrollPerSecond: maxPixelScrollPerSecond[(_provided$maxScrollSp = provided === null || provided === void 0 ? void 0 : provided.maxScrollSpeed) !== null && _provided$maxScrollSp !== void 0 ? _provided$maxScrollSp : "standard"]
4961
+ });
4962
+ }
4963
+
4964
+ // node_modules/@atlaskit/pragmatic-drag-and-drop-auto-scroll/dist/esm/shared/can-scroll-on-edge.js
4965
+ var canScrollOnEdge = {
4966
+ // Notes:
4967
+ //
4968
+ // 🌏 Chrome 115.0: uses fractional units for `scrollLeft` and `scrollTop`
4969
+ // (and fractional units don't reach true integer maximum when zoomed in / out)
4970
+ // 🍎 Safari 16.5.2: no fractional units
4971
+ // 🦊 Firefox 115.0: no fractional units
4972
+ // we have some scroll we can move backwards into
4973
+ top: function top(element) {
4974
+ return element.scrollTop > 0;
4975
+ },
4976
+ // We have some scroll we can move forward into
4977
+ right: function right(element) {
4978
+ return Math.ceil(element.scrollLeft) + element.clientWidth < element.scrollWidth;
4979
+ },
4980
+ // We have some scroll we can move forwards into
4981
+ bottom: function bottom(element) {
4982
+ return Math.ceil(element.scrollTop) + element.clientHeight < element.scrollHeight;
4983
+ },
4984
+ // we have some scroll we can move back into.
4985
+ left: function left(element) {
4986
+ return element.scrollLeft > 0;
4987
+ }
4988
+ };
4989
+
4990
+ // node_modules/@atlaskit/pragmatic-drag-and-drop-auto-scroll/dist/esm/shared/edges.js
4991
+ var edges = ["top", "right", "bottom", "left"];
4992
+ var edgeAxisLookup = {
4993
+ top: "vertical",
4994
+ right: "horizontal",
4995
+ bottom: "vertical",
4996
+ left: "horizontal"
4997
+ };
4998
+
4999
+ // node_modules/@atlaskit/pragmatic-drag-and-drop-auto-scroll/dist/esm/shared/axis.js
5000
+ var vertical = {
5001
+ start: "top",
5002
+ end: "bottom",
5003
+ point: "y",
5004
+ size: "height"
5005
+ };
5006
+ var horizontal = {
5007
+ start: "left",
5008
+ end: "right",
5009
+ point: "x",
5010
+ size: "width"
5011
+ };
5012
+ var axisLookup = {
5013
+ vertical: {
5014
+ mainAxis: vertical,
5015
+ crossAxis: horizontal
5016
+ },
5017
+ horizontal: {
5018
+ mainAxis: horizontal,
5019
+ crossAxis: vertical
5020
+ }
5021
+ };
5022
+
5023
+ // node_modules/@atlaskit/pragmatic-drag-and-drop-auto-scroll/dist/esm/shared/side.js
5024
+ var mainAxisSideLookup = {
5025
+ top: "start",
5026
+ right: "end",
5027
+ bottom: "end",
5028
+ left: "start"
5029
+ };
5030
+
5031
+ // node_modules/@atlaskit/pragmatic-drag-and-drop-auto-scroll/dist/esm/shared/get-over-element-hitbox.js
5032
+ function makeGetHitbox(_ref) {
5033
+ var edge = _ref.edge, axis = _ref.axis;
5034
+ return function hitbox(_ref2) {
5035
+ var clientRect = _ref2.clientRect, config = _ref2.config;
5036
+ var _axisLookup$axis = axisLookup[axis], mainAxis = _axisLookup$axis.mainAxis, crossAxis = _axisLookup$axis.crossAxis;
5037
+ var side = mainAxisSideLookup[edge];
5038
+ var mainAxisHitboxSize = Math.min(
5039
+ // scale the size of the hitbox down for smaller elements
5040
+ config.startHitboxAtPercentageRemainingOfElement[edge] * clientRect[mainAxis.size],
5041
+ // Don't let the hitbox grow too big for big elements
5042
+ config.maxMainAxisHitboxSize
5043
+ );
5044
+ return DOMRect.fromRect(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, mainAxis.point, side === "start" ? (
5045
+ // begin from the start edge and grow inwards
5046
+ clientRect[mainAxis.point]
5047
+ ) : (
5048
+ // begin from inside the end edge and grow towards the end edge
5049
+ clientRect[mainAxis.point] + clientRect[mainAxis.size] - mainAxisHitboxSize
5050
+ )), crossAxis.point, clientRect[crossAxis.point]), mainAxis.size, mainAxisHitboxSize), crossAxis.size, clientRect[crossAxis.size]));
5051
+ };
5052
+ }
5053
+ var getOverElementHitbox = {
5054
+ top: makeGetHitbox({
5055
+ axis: "vertical",
5056
+ edge: "top"
5057
+ }),
5058
+ right: makeGetHitbox({
5059
+ axis: "horizontal",
5060
+ edge: "right"
5061
+ }),
5062
+ bottom: makeGetHitbox({
5063
+ axis: "vertical",
5064
+ edge: "bottom"
5065
+ }),
5066
+ left: makeGetHitbox({
5067
+ axis: "horizontal",
5068
+ edge: "left"
5069
+ })
5070
+ };
5071
+
5072
+ // node_modules/@atlaskit/pragmatic-drag-and-drop-auto-scroll/dist/esm/shared/get-percentage-in-range.js
5073
+ function getPercentageInRange(_ref) {
5074
+ var startOfRange = _ref.startOfRange, endOfRange = _ref.endOfRange, value = _ref.value;
5075
+ var isValid = startOfRange < endOfRange;
5076
+ if (!isValid) {
5077
+ return 0;
5078
+ }
5079
+ if (value < startOfRange) {
5080
+ return 0;
5081
+ }
5082
+ if (value > endOfRange) {
5083
+ return 1;
5084
+ }
5085
+ var range = endOfRange - startOfRange;
5086
+ return (value - startOfRange) / range;
5087
+ }
5088
+
5089
+ // node_modules/@atlaskit/pragmatic-drag-and-drop-auto-scroll/dist/esm/shared/get-scroll-change.js
5090
+ function getMaxScrollChange(_ref) {
5091
+ var timeSinceLastFrame = _ref.timeSinceLastFrame, config = _ref.config;
5092
+ var targetScrollPerMs = config.maxPixelScrollPerSecond / 1e3;
5093
+ var proposed = Math.ceil(targetScrollPerMs * timeSinceLastFrame);
5094
+ var maximum = config.maxPixelScrollPerSecond / 60;
5095
+ return Math.min(proposed, maximum);
5096
+ }
5097
+ function getDistanceDampening(_ref2) {
5098
+ var client = _ref2.client, axis = _ref2.axis, edge = _ref2.edge, hitbox = _ref2.hitbox, config = _ref2.config;
5099
+ var mainAxis = axisLookup[axis].mainAxis;
5100
+ var side = mainAxisSideLookup[edge];
5101
+ var maxSpeedBuffer = hitbox[mainAxis.size] * config.maxScrollAtPercentageRemainingOfHitbox[edge];
5102
+ if (side === "end") {
5103
+ return getPercentageInRange({
5104
+ startOfRange: hitbox[mainAxis.start],
5105
+ endOfRange: hitbox[mainAxis.end] - maxSpeedBuffer,
5106
+ value: client[mainAxis.point]
5107
+ });
5108
+ }
5109
+ var raw = getPercentageInRange({
5110
+ startOfRange: hitbox[mainAxis.start] + maxSpeedBuffer,
5111
+ endOfRange: hitbox[mainAxis.end],
5112
+ value: client[mainAxis.point]
5113
+ });
5114
+ return 1 - raw;
5115
+ }
5116
+ function getScrollChange(_ref3) {
5117
+ var client = _ref3.client, timeSinceLastFrame = _ref3.timeSinceLastFrame, engagement = _ref3.engagement, axis = _ref3.axis, hitbox = _ref3.hitbox, edge = _ref3.edge, isDistanceDampeningEnabled = _ref3.isDistanceDampeningEnabled, config = _ref3.config;
5118
+ var maxScroll = getMaxScrollChange({
5119
+ timeSinceLastFrame,
5120
+ config
5121
+ });
5122
+ var percentageDistanceDampening = isDistanceDampeningEnabled ? getDistanceDampening({
5123
+ client,
5124
+ edge,
5125
+ hitbox,
5126
+ axis,
5127
+ config
5128
+ }) : 1;
5129
+ var percentageThroughTimeDampening = getPercentageInRange({
5130
+ startOfRange: engagement.timeOfEngagementStart,
5131
+ endOfRange: engagement.timeOfEngagementStart + config.timeDampeningDurationMs,
5132
+ value: Date.now()
5133
+ });
5134
+ var percentageOfMaxScroll = percentageDistanceDampening * percentageThroughTimeDampening;
5135
+ var scroll = Math.max(maxScroll * percentageOfMaxScroll, 1);
5136
+ var side = mainAxisSideLookup[edge];
5137
+ return side === "end" ? scroll : -1 * scroll;
5138
+ }
5139
+
5140
+ // node_modules/@atlaskit/pragmatic-drag-and-drop-auto-scroll/dist/esm/shared/is-axis-allowed.js
5141
+ function isAxisAllowed(axis, allowedAxis) {
5142
+ return allowedAxis === "all" || axis === allowedAxis;
5143
+ }
5144
+
5145
+ // node_modules/@atlaskit/pragmatic-drag-and-drop-auto-scroll/dist/esm/shared/is-within.js
5146
+ function isWithin2(_ref) {
5147
+ var client = _ref.client, clientRect = _ref.clientRect;
5148
+ return (
5149
+ // is within horizontal bounds
5150
+ client.x >= clientRect.x && client.x <= clientRect.x + clientRect.width && // is within vertical bounds
5151
+ client.y >= clientRect.y && client.y <= clientRect.y + clientRect.height
5152
+ );
5153
+ }
5154
+
5155
+ // node_modules/@atlaskit/pragmatic-drag-and-drop-auto-scroll/dist/esm/over-element/get-scroll-by.js
5156
+ function getRectDefault(element) {
5157
+ return element.getBoundingClientRect();
5158
+ }
5159
+ function getScrollBy(_ref) {
5160
+ var element = _ref.element, input = _ref.input, timeSinceLastFrame = _ref.timeSinceLastFrame, engagement = _ref.engagement, config = _ref.config, allowedAxis = _ref.allowedAxis, _ref$getRect = _ref.getRect, getRect = _ref$getRect === void 0 ? getRectDefault : _ref$getRect;
5161
+ var client = {
5162
+ x: input.clientX,
5163
+ y: input.clientY
5164
+ };
5165
+ var clientRect = getRect(element);
5166
+ var scrollableEdges = edges.reduce(function(map, edge) {
5167
+ var hitbox = getOverElementHitbox[edge]({
5168
+ clientRect,
5169
+ config
5170
+ });
5171
+ var axis = edgeAxisLookup[edge];
5172
+ if (!isAxisAllowed(axis, allowedAxis)) {
5173
+ return map;
5174
+ }
5175
+ if (!isWithin2({
5176
+ client,
5177
+ clientRect: hitbox
5178
+ })) {
5179
+ return map;
5180
+ }
5181
+ if (!canScrollOnEdge[edge](element)) {
5182
+ return map;
5183
+ }
5184
+ map.set(edge, {
5185
+ edge,
5186
+ hitbox
5187
+ });
5188
+ return map;
5189
+ }, /* @__PURE__ */ new Map());
5190
+ var left2 = (function() {
5191
+ var axis = "horizontal";
5192
+ var leftEdge = scrollableEdges.get("left");
5193
+ if (leftEdge) {
5194
+ return getScrollChange({
5195
+ client,
5196
+ edge: leftEdge.edge,
5197
+ hitbox: leftEdge.hitbox,
5198
+ axis,
5199
+ timeSinceLastFrame,
5200
+ engagement,
5201
+ isDistanceDampeningEnabled: true,
5202
+ config
5203
+ });
5204
+ }
5205
+ var rightEdge = scrollableEdges.get("right");
5206
+ if (rightEdge) {
5207
+ return getScrollChange({
5208
+ client,
5209
+ edge: rightEdge.edge,
5210
+ hitbox: rightEdge.hitbox,
5211
+ axis,
5212
+ timeSinceLastFrame,
5213
+ engagement,
5214
+ isDistanceDampeningEnabled: true,
5215
+ config
5216
+ });
5217
+ }
5218
+ return 0;
5219
+ })();
5220
+ var top2 = (function() {
5221
+ var axis = "vertical";
5222
+ var bottomEdge = scrollableEdges.get("bottom");
5223
+ if (bottomEdge) {
5224
+ return getScrollChange({
5225
+ client,
5226
+ edge: bottomEdge.edge,
5227
+ hitbox: bottomEdge.hitbox,
5228
+ axis,
5229
+ timeSinceLastFrame,
5230
+ engagement,
5231
+ isDistanceDampeningEnabled: true,
5232
+ config
5233
+ });
5234
+ }
5235
+ var topEdge = scrollableEdges.get("top");
5236
+ if (topEdge) {
5237
+ return getScrollChange({
5238
+ client,
5239
+ edge: topEdge.edge,
5240
+ hitbox: topEdge.hitbox,
5241
+ axis,
5242
+ timeSinceLastFrame,
5243
+ engagement,
5244
+ isDistanceDampeningEnabled: true,
5245
+ config
5246
+ });
5247
+ }
5248
+ return 0;
5249
+ })();
5250
+ return {
5251
+ left: left2,
5252
+ top: top2
5253
+ };
5254
+ }
5255
+
5256
+ // node_modules/@atlaskit/pragmatic-drag-and-drop-auto-scroll/dist/esm/over-element/try-scroll.js
5257
+ function _createForOfIteratorHelper3(r, e) {
5258
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
5259
+ if (!t) {
5260
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray4(r)) || e && r && "number" == typeof r.length) {
5261
+ t && (r = t);
5262
+ var _n = 0, F = function F2() {
5263
+ };
5264
+ return { s: F, n: function n() {
5265
+ return _n >= r.length ? { done: true } : { done: false, value: r[_n++] };
5266
+ }, e: function e2(r2) {
5267
+ throw r2;
5268
+ }, f: F };
5269
+ }
5270
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
5271
+ }
5272
+ var o, a = true, u = false;
5273
+ return { s: function s() {
5274
+ t = t.call(r);
5275
+ }, n: function n() {
5276
+ var r2 = t.next();
5277
+ return a = r2.done, r2;
5278
+ }, e: function e2(r2) {
5279
+ u = true, o = r2;
5280
+ }, f: function f() {
5281
+ try {
5282
+ a || null == t.return || t.return();
5283
+ } finally {
5284
+ if (u) throw o;
5285
+ }
5286
+ } };
5287
+ }
5288
+ function _unsupportedIterableToArray4(r, a) {
5289
+ if (r) {
5290
+ if ("string" == typeof r) return _arrayLikeToArray4(r, a);
5291
+ var t = {}.toString.call(r).slice(8, -1);
5292
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray4(r, a) : void 0;
5293
+ }
5294
+ }
5295
+ function _arrayLikeToArray4(r, a) {
5296
+ (null == a || a > r.length) && (a = r.length);
5297
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
5298
+ return n;
5299
+ }
5300
+ function isScrollingAvailable(value) {
5301
+ return Boolean(value.top || value.left);
5302
+ }
5303
+ function tryScrollElements(_ref) {
5304
+ var _container$getConfigu, _container$getAllowed, _container$getAllowed2;
5305
+ var target = _ref.target, input = _ref.input, source = _ref.source, findEntry = _ref.findEntry, timeSinceLastFrame = _ref.timeSinceLastFrame, _ref$available = _ref.available, available = _ref$available === void 0 ? {
5306
+ top: true,
5307
+ left: true
5308
+ } : _ref$available;
5309
+ if (!isScrollingAvailable(available)) {
5310
+ return available;
5311
+ }
5312
+ if (!target) {
5313
+ return available;
5314
+ }
5315
+ var element = target.closest(selector);
5316
+ if (!element) {
5317
+ return available;
5318
+ }
5319
+ var container = findEntry(element);
5320
+ if (!container) {
5321
+ return available;
5322
+ }
5323
+ function continueSearchUp() {
5324
+ var _element$parentElemen;
5325
+ return tryScrollElements({
5326
+ target: (_element$parentElemen = element === null || element === void 0 ? void 0 : element.parentElement) !== null && _element$parentElemen !== void 0 ? _element$parentElemen : null,
5327
+ findEntry,
5328
+ source,
5329
+ timeSinceLastFrame,
5330
+ input,
5331
+ available
2952
5332
  });
2953
5333
  }
2954
- renderStoryBlock(anchorId) {
2955
- const html = this.bridge.RenderBlockHtml(
2956
- this.handle,
2957
- anchorId,
2958
- this.options.cssPrefix,
2959
- this.options.fabricateClasses
2960
- );
2961
- if (html.charCodeAt(0) === 123) return null;
2962
- return new DOMParser().parseFromString(html, "text/html").body.firstElementChild;
5334
+ var feedback = {
5335
+ input,
5336
+ source,
5337
+ element
5338
+ };
5339
+ if (container.canScroll && !container.canScroll(feedback)) {
5340
+ return continueSearchUp();
5341
+ }
5342
+ var engagement = markAndGetEngagement(element);
5343
+ var config = getInternalConfig((_container$getConfigu = container.getConfiguration) === null || _container$getConfigu === void 0 ? void 0 : _container$getConfigu.call(container, feedback));
5344
+ var allowedAxis = (_container$getAllowed = (_container$getAllowed2 = container.getAllowedAxis) === null || _container$getAllowed2 === void 0 ? void 0 : _container$getAllowed2.call(container, feedback)) !== null && _container$getAllowed !== void 0 ? _container$getAllowed : "all";
5345
+ var scrollBy = getScrollBy({
5346
+ element,
5347
+ engagement,
5348
+ input,
5349
+ timeSinceLastFrame,
5350
+ allowedAxis,
5351
+ config
5352
+ });
5353
+ var scroll = {
5354
+ top: 0,
5355
+ left: 0
5356
+ };
5357
+ if (available.top && scrollBy.top !== 0) {
5358
+ scroll.top = scrollBy.top;
5359
+ available.top = false;
5360
+ }
5361
+ if (available.left && scrollBy.left !== 0) {
5362
+ scroll.left = scrollBy.left;
5363
+ available.left = false;
5364
+ }
5365
+ if (scroll.top !== 0 || scroll.left !== 0) {
5366
+ element.scrollBy(scroll);
5367
+ }
5368
+ return continueSearchUp();
5369
+ }
5370
+ function tryScrollWindow(_ref2) {
5371
+ var input = _ref2.input, timeSinceLastFrame = _ref2.timeSinceLastFrame, available = _ref2.available, source = _ref2.source, entries = _ref2.entries;
5372
+ var element = document.documentElement;
5373
+ var feedback = {
5374
+ input,
5375
+ source,
5376
+ element
5377
+ };
5378
+ var _iterator = _createForOfIteratorHelper3(entries), _step;
5379
+ try {
5380
+ for (_iterator.s(); !(_step = _iterator.n()).done; ) {
5381
+ var _entry$getConfigurati, _entry$getAllowedAxis, _entry$getAllowedAxis2;
5382
+ var entry = _step.value;
5383
+ if (entry.canScroll && !entry.canScroll(feedback)) {
5384
+ continue;
5385
+ }
5386
+ var engagement = markAndGetEngagement(element);
5387
+ var config = getInternalConfig((_entry$getConfigurati = entry.getConfiguration) === null || _entry$getConfigurati === void 0 ? void 0 : _entry$getConfigurati.call(entry, feedback));
5388
+ var allowedAxis = (_entry$getAllowedAxis = (_entry$getAllowedAxis2 = entry.getAllowedAxis) === null || _entry$getAllowedAxis2 === void 0 ? void 0 : _entry$getAllowedAxis2.call(entry, feedback)) !== null && _entry$getAllowedAxis !== void 0 ? _entry$getAllowedAxis : "all";
5389
+ var scrollBy = getScrollBy({
5390
+ element,
5391
+ engagement,
5392
+ input,
5393
+ config,
5394
+ allowedAxis,
5395
+ getRect: function getRect(element2) {
5396
+ return DOMRect.fromRect({
5397
+ y: 0,
5398
+ x: 0,
5399
+ width: element2.clientWidth,
5400
+ height: element2.clientHeight
5401
+ });
5402
+ },
5403
+ timeSinceLastFrame
5404
+ });
5405
+ var scroll = {
5406
+ top: available.top ? scrollBy.top : 0,
5407
+ left: available.left ? scrollBy.left : 0
5408
+ };
5409
+ if (scroll.top !== 0 || scroll.left !== 0) {
5410
+ element.scrollBy(scroll);
5411
+ }
5412
+ break;
5413
+ }
5414
+ } catch (err) {
5415
+ _iterator.e(err);
5416
+ } finally {
5417
+ _iterator.f();
2963
5418
  }
2964
- placeholder(which, kind) {
2965
- const el = document.createElement("div");
2966
- el.className = "docx-hf-placeholder";
2967
- el.setAttribute("data-hf-placeholder", "");
2968
- const label = KIND_LABELS.find((k) => k.value === kind)?.label ?? kind;
2969
- el.textContent = `No ${label.toLowerCase()} ${which} \u2014 pick a kind to create one.`;
2970
- return el;
5419
+ }
5420
+ function tryScroll(_ref3) {
5421
+ var input = _ref3.input, findEntry = _ref3.findEntry, timeSinceLastFrame = _ref3.timeSinceLastFrame, source = _ref3.source, getWindowScrollEntries = _ref3.getWindowScrollEntries, underUsersPointer = _ref3.underUsersPointer;
5422
+ var remainder = tryScrollElements({
5423
+ target: underUsersPointer,
5424
+ timeSinceLastFrame,
5425
+ input,
5426
+ source,
5427
+ findEntry
5428
+ });
5429
+ if (!isScrollingAvailable(remainder)) {
5430
+ return;
2971
5431
  }
2972
- /**
2973
- * Surface the caveat that comes with the selected kind. Turning on first/even means those pages
2974
- * stop using the Default stories entirely, which bites hardest on the OTHER band: enabling an
2975
- * even header with no even footer leaves even pages footer-less, and enabling a first-page
2976
- * header with an empty first-page footer leaves page 1 footer-less. The note is shown whenever
2977
- * first/even is selected (the behavior change is real either way); the fix button appears only
2978
- * when the counterpart story is missing entirely, which is what a user almost always wants next.
2979
- */
2980
- renderKindWarning(which) {
2981
- const band = this.bandFor(which);
2982
- const warning = band.querySelector("[data-hf-warning]");
2983
- if (!warning) return;
2984
- const kind = this.kinds[which];
2985
- if (kind === "default") {
2986
- warning.hidden = true;
2987
- warning.textContent = "";
2988
- return;
2989
- }
2990
- const other = which === "header" ? "footer" : "header";
2991
- warning.hidden = false;
2992
- warning.textContent = `${kind === "even" ? EVEN_WARNING : FIRST_WARNING} `;
2993
- if (this.partUriFor(other, kind)) return;
2994
- const fix = document.createElement("button");
2995
- fix.type = "button";
2996
- fix.setAttribute("data-hf-fix-counterpart", "");
2997
- fix.textContent = `Also create a ${kind === "even" ? "matching even" : "first-page"} ${other}`;
2998
- fix.addEventListener("click", () => {
2999
- this.setKind(other, kind);
3000
- this.renderKindWarning(which);
5432
+ tryScrollWindow({
5433
+ input,
5434
+ source,
5435
+ entries: getWindowScrollEntries(),
5436
+ timeSinceLastFrame,
5437
+ available: remainder
5438
+ });
5439
+ }
5440
+
5441
+ // node_modules/@atlaskit/pragmatic-drag-and-drop-auto-scroll/dist/esm/over-element/make-api.js
5442
+ function ownKeys5(e, r) {
5443
+ var t = Object.keys(e);
5444
+ if (Object.getOwnPropertySymbols) {
5445
+ var o = Object.getOwnPropertySymbols(e);
5446
+ r && (o = o.filter(function(r2) {
5447
+ return Object.getOwnPropertyDescriptor(e, r2).enumerable;
5448
+ })), t.push.apply(t, o);
5449
+ }
5450
+ return t;
5451
+ }
5452
+ function _objectSpread5(e) {
5453
+ for (var r = 1; r < arguments.length; r++) {
5454
+ var t = null != arguments[r] ? arguments[r] : {};
5455
+ r % 2 ? ownKeys5(Object(t), true).forEach(function(r2) {
5456
+ _defineProperty(e, r2, t[r2]);
5457
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys5(Object(t)).forEach(function(r2) {
5458
+ Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
3001
5459
  });
3002
- warning.appendChild(fix);
3003
5460
  }
3004
- };
3005
- function parseResult(json) {
3006
- try {
3007
- return JSON.parse(json);
3008
- } catch {
3009
- return { success: false };
5461
+ return e;
5462
+ }
5463
+ function makeApi(_ref) {
5464
+ var monitor = _ref.monitor;
5465
+ var elementRegistry = /* @__PURE__ */ new Map();
5466
+ var windowRegistry = /* @__PURE__ */ new Set();
5467
+ function autoScroll(args) {
5468
+ if (true) {
5469
+ var _window$getComputedSt = window.getComputedStyle(args.element), overflowX = _window$getComputedSt.overflowX, overflowY = _window$getComputedSt.overflowY;
5470
+ var isScrollable = overflowX === "auto" || overflowX === "scroll" || overflowY === "auto" || overflowY === "scroll";
5471
+ if (!isScrollable) {
5472
+ console.warn("Auto scrolling has been attached to an element that appears not to be scrollable", {
5473
+ element: args.element,
5474
+ overflowX,
5475
+ overflowY
5476
+ });
5477
+ }
5478
+ }
5479
+ if (true) {
5480
+ var existing = elementRegistry.get(args.element);
5481
+ if (existing) {
5482
+ console.warn("You have already registered autoScrolling on the same element", {
5483
+ existing,
5484
+ proposed: args
5485
+ });
5486
+ }
5487
+ }
5488
+ elementRegistry.set(args.element, args);
5489
+ var cleanup = combine(addScrollableAttribute(args.element), function() {
5490
+ return elementRegistry.delete(args.element);
5491
+ });
5492
+ return once(cleanup);
5493
+ }
5494
+ function autoScrollWindow() {
5495
+ var args = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
5496
+ var unique = _objectSpread5({}, args);
5497
+ windowRegistry.add(unique);
5498
+ function cleanup() {
5499
+ windowRegistry.delete(unique);
5500
+ }
5501
+ return once(cleanup);
5502
+ }
5503
+ function findEntry(element) {
5504
+ var _elementRegistry$get;
5505
+ return (_elementRegistry$get = elementRegistry.get(element)) !== null && _elementRegistry$get !== void 0 ? _elementRegistry$get : null;
5506
+ }
5507
+ function getWindowScrollEntries() {
5508
+ return Array.from(windowRegistry);
5509
+ }
5510
+ function onFrame(_ref2) {
5511
+ var latestArgs = _ref2.latestArgs, underUsersPointer = _ref2.underUsersPointer, timeSinceLastFrame = _ref2.timeSinceLastFrame;
5512
+ tryScroll({
5513
+ input: latestArgs.location.current.input,
5514
+ source: latestArgs.source,
5515
+ findEntry,
5516
+ underUsersPointer,
5517
+ timeSinceLastFrame,
5518
+ getWindowScrollEntries
5519
+ });
3010
5520
  }
5521
+ getScheduler(monitor).onFrame(onFrame);
5522
+ return {
5523
+ autoScroll,
5524
+ autoScrollWindow
5525
+ };
3011
5526
  }
3012
5527
 
5528
+ // node_modules/@atlaskit/pragmatic-drag-and-drop-auto-scroll/dist/esm/entry-point/element.js
5529
+ var api = makeApi({
5530
+ monitor: monitorForElements
5531
+ });
5532
+ var autoScrollForElements = api.autoScroll;
5533
+ var autoScrollWindowForElements = api.autoScrollWindow;
5534
+
3013
5535
  // src/editor-reconcile.ts
3014
5536
  function tokenOf(unit) {
3015
5537
  return unidOf(unit.id) + (unit.sig ? "|" + unit.sig : "");
@@ -3049,15 +5571,32 @@ function diffUnits(oldUnids, newUnits) {
3049
5571
  const bar = token.indexOf("|");
3050
5572
  return bar < 0 ? token : token.slice(0, bar);
3051
5573
  };
3052
- const substituted = [];
5574
+ const moved = [];
3053
5575
  const usedRemoved = /* @__PURE__ */ new Set();
5576
+ const usedAdded = /* @__PURE__ */ new Set();
5577
+ const removedByToken = /* @__PURE__ */ new Map();
5578
+ for (const oi of removed) {
5579
+ (removedByToken.get(oldUnids[oi]) ?? removedByToken.set(oldUnids[oi], []).get(oldUnids[oi])).push(oi);
5580
+ }
5581
+ for (const nj of added) {
5582
+ const candidates = removedByToken.get(newUnids[nj]);
5583
+ const oi = candidates?.find((i2) => !usedRemoved.has(i2));
5584
+ if (oi !== void 0) {
5585
+ moved.push({ oldIndex: oi, newIndex: nj });
5586
+ usedRemoved.add(oi);
5587
+ usedAdded.add(nj);
5588
+ }
5589
+ }
5590
+ const substituted = [];
3054
5591
  const removedByUnid = /* @__PURE__ */ new Map();
3055
5592
  for (const oi of removed) {
5593
+ if (usedRemoved.has(oi)) continue;
3056
5594
  const u = bareUnid(oldUnids[oi]);
3057
5595
  (removedByUnid.get(u) ?? removedByUnid.set(u, []).get(u)).push(oi);
3058
5596
  }
3059
5597
  const unmatchedAdded = [];
3060
5598
  for (const nj of added) {
5599
+ if (usedAdded.has(nj)) continue;
3061
5600
  const candidates = removedByUnid.get(bareUnid(newUnids[nj]));
3062
5601
  const oi = candidates?.find((i2) => !usedRemoved.has(i2));
3063
5602
  if (oi !== void 0) {
@@ -3088,7 +5627,7 @@ function diffUnits(oldUnids, newUnits) {
3088
5627
  }
3089
5628
  }
3090
5629
  }
3091
- return { keep, removed, added, substituted };
5630
+ return { keep, removed, added, substituted, moved };
3092
5631
  }
3093
5632
  function needsRemount(diff, newUnits, oldKinds, threshold = 40) {
3094
5633
  if (diff.added.length + diff.removed.length > threshold) return true;
@@ -3105,6 +5644,46 @@ function needsRemount(diff, newUnits, oldKinds, threshold = 40) {
3105
5644
 
3106
5645
  // src/editor.ts
3107
5646
  var EDITABLE_TAGS = /* @__PURE__ */ new Set(["P", "H1", "H2", "H3", "H4", "H5", "H6"]);
5647
+ var BLOCK_DRAG_TYPE = "docxodus-block";
5648
+ var blockDragStyledDocuments = /* @__PURE__ */ new WeakSet();
5649
+ function ensureBlockDragStyles(doc) {
5650
+ if (blockDragStyledDocuments.has(doc)) return;
5651
+ blockDragStyledDocuments.add(doc);
5652
+ const style = doc.createElement("style");
5653
+ style.dataset.docxodusBlockDrag = "true";
5654
+ style.textContent = `
5655
+ .docx-block-handle {
5656
+ position: fixed; z-index: 2147483000; display: none; width: 26px; height: 28px;
5657
+ align-items: center; justify-content: center; padding: 0; border: 1px solid #d0d5dd;
5658
+ border-radius: 6px; background: #fff; color: #667085; box-shadow: 0 1px 3px rgba(16,24,40,.12);
5659
+ cursor: grab; font: 700 17px/1 system-ui, sans-serif; user-select: none; touch-action: none;
5660
+ }
5661
+ .docx-block-handle:hover, .docx-block-handle:focus-visible { color: #344054; border-color: #98a2b3; outline: none; }
5662
+ .docx-block-handle[aria-pressed="true"] { color: #175cd3; border-color: #84adff; background: #eff8ff; }
5663
+ .docx-block-handle.docx-block-dragging { cursor: grabbing; opacity: .78; }
5664
+ .docx-block-drop-indicator {
5665
+ position: fixed; z-index: 2147482999; display: none; height: 3px; pointer-events: none;
5666
+ border-radius: 999px; background: #2e90fa; box-shadow: 0 0 0 1px rgba(255,255,255,.85);
5667
+ }
5668
+ .docx-block-move-menu {
5669
+ position: fixed; z-index: 2147483001; display: none; min-width: 150px; padding: 5px;
5670
+ border: 1px solid #d0d5dd; border-radius: 8px; background: #fff;
5671
+ box-shadow: 0 8px 24px rgba(16,24,40,.18); font: 13px/1.35 system-ui, sans-serif;
5672
+ }
5673
+ .docx-block-move-menu button { display: block; width: 100%; padding: 7px 9px; border: 0; border-radius: 5px; background: transparent; color: #344054; text-align: left; }
5674
+ .docx-block-move-menu button:hover, .docx-block-move-menu button:focus-visible { background: #f2f4f7; outline: none; }
5675
+ .docx-block-move-menu button:disabled { color: #98a2b3; background: transparent; }
5676
+ .docx-block-move-flash { animation: docx-block-move-flash 800ms ease-out; }
5677
+ @keyframes docx-block-move-flash { from { box-shadow: 0 0 0 3px rgba(46,144,250,.55); } to { box-shadow: none; } }
5678
+ .docx-block-live-region { position: fixed; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
5679
+ `;
5680
+ (doc.head ?? doc.documentElement).appendChild(style);
5681
+ }
5682
+ function trackedChangeWireName(mode) {
5683
+ if (mode === 1 /* RenderInline */) return "render_inline";
5684
+ if (mode === 2 /* StripDeletions */) return "strip_deletions";
5685
+ return "accept";
5686
+ }
3108
5687
  function fontWeightIsBold(w) {
3109
5688
  if (w === "bold" || w === "bolder") return true;
3110
5689
  const n = parseInt(w, 10);
@@ -3252,9 +5831,9 @@ function trimBounds(block) {
3252
5831
  }
3253
5832
  function trimmedSpan(block, span) {
3254
5833
  const { leading, trimmedLen } = trimBounds(block);
3255
- const start = Math.max(0, Math.min(span.start - Math.min(span.start, leading), trimmedLen));
3256
- const end = Math.max(start, Math.min(span.start + span.length - leading, trimmedLen));
3257
- return { start, length: end - start };
5834
+ const start2 = Math.max(0, Math.min(span.start - Math.min(span.start, leading), trimmedLen));
5835
+ const end = Math.max(start2, Math.min(span.start + span.length - leading, trimmedLen));
5836
+ return { start: start2, length: end - start2 };
3258
5837
  }
3259
5838
  function contentPositionIn(el, offset) {
3260
5839
  let remaining = offset;
@@ -3297,9 +5876,9 @@ function setSelectionBetween(anchor, focus) {
3297
5876
  probe.collapse(true);
3298
5877
  const focusIsBefore = probe.comparePoint(focus.node, focus.offset) < 0;
3299
5878
  const range = document.createRange();
3300
- const start = focusIsBefore ? focus : anchor;
5879
+ const start2 = focusIsBefore ? focus : anchor;
3301
5880
  const end = focusIsBefore ? anchor : focus;
3302
- range.setStart(start.node, start.offset);
5881
+ range.setStart(start2.node, start2.offset);
3303
5882
  range.setEnd(end.node, end.offset);
3304
5883
  sel.removeAllRanges();
3305
5884
  sel.addRange(range);
@@ -3347,17 +5926,17 @@ function selectionSpanIn(block) {
3347
5926
  const range = sel.getRangeAt(0);
3348
5927
  if (range.collapsed) return null;
3349
5928
  if (!block.contains(range.startContainer) || !block.contains(range.endContainer)) return null;
3350
- const start = contentOffsetOf(block, range.startContainer, range.startOffset);
5929
+ const start2 = contentOffsetOf(block, range.startContainer, range.startOffset);
3351
5930
  const end = contentOffsetOf(block, range.endContainer, range.endOffset);
3352
- const span = trimmedSpan(block, { start: Math.min(start, end), length: Math.abs(end - start) });
5931
+ const span = trimmedSpan(block, { start: Math.min(start2, end), length: Math.abs(end - start2) });
3353
5932
  return span.length > 0 ? span : null;
3354
5933
  }
3355
- function selectRange(el, start, length) {
5934
+ function selectRange(el, start2, length) {
3356
5935
  const sel = typeof window !== "undefined" ? window.getSelection() : null;
3357
5936
  if (!sel || !el.isConnected) return;
3358
5937
  el.focus();
3359
5938
  const range = document.createRange();
3360
- const end = start + length;
5939
+ const end = start2 + length;
3361
5940
  let pos = 0;
3362
5941
  let startSet = false;
3363
5942
  const walk = (node) => {
@@ -3366,8 +5945,8 @@ function selectRange(el, start, length) {
3366
5945
  if (isInMarker(child)) continue;
3367
5946
  const raw = child.textContent ?? "";
3368
5947
  const len = stripBidi(raw).length;
3369
- if (!startSet && pos + len >= start) {
3370
- range.setStart(child, domOffsetForContentOffset(raw, start - pos));
5948
+ if (!startSet && pos + len >= start2) {
5949
+ range.setStart(child, domOffsetForContentOffset(raw, start2 - pos));
3371
5950
  startSet = true;
3372
5951
  }
3373
5952
  if (startSet && pos + len >= end) {
@@ -3418,7 +5997,7 @@ function selectionHasFormat(key, fallback) {
3418
5997
  return false;
3419
5998
  }
3420
5999
  }
3421
- function completeArgs(bytes, cssPrefix, fabricate, paginated, scale) {
6000
+ function completeArgs(bytes, cssPrefix, fabricate, paginated, scale, renderTrackedChanges) {
3422
6001
  return [
3423
6002
  bytes,
3424
6003
  "Document",
@@ -3442,7 +6021,7 @@ function completeArgs(bytes, cssPrefix, fabricate, paginated, scale) {
3442
6021
  true,
3443
6022
  /* renderHeadersAndFooters */
3444
6023
  paginated,
3445
- false,
6024
+ renderTrackedChanges,
3446
6025
  true,
3447
6026
  true,
3448
6027
  false,
@@ -3465,6 +6044,21 @@ var DocxEditor = class _DocxEditor {
3465
6044
  * structural edit (split/merge/format) is lost. While this flag is set, commitBlock no-ops.
3466
6045
  */
3467
6046
  this.replacing = false;
6047
+ /** Editor-owned block-move chrome. It is deliberately outside the rendered unit tree. */
6048
+ this.blockDragHandle = null;
6049
+ this.blockDropIndicator = null;
6050
+ this.blockMoveMenu = null;
6051
+ this.blockMoveLive = null;
6052
+ this.blockDragSource = null;
6053
+ this.blockDragCleanup = [];
6054
+ this.blockDragTargetCleanup = [];
6055
+ this.blockDragging = false;
6056
+ this.blockDragPointerDown = false;
6057
+ /** Anchors the current drag source may legally move next to, per the engine's own rules.
6058
+ * Null when the bridge predates ValidMoveTargets — then every block is offered, as before. */
6059
+ this.blockMoveTargets = null;
6060
+ /** Why the last move was refused, verbatim from the engine — diagnostics, not announcement copy. */
6061
+ this.lastMoveError = null;
3468
6062
  /**
3469
6063
  * The last real (non-collapsed) text selection inside an editable block. A toolbar control that
3470
6064
  * must take focus to be used — the font-size combobox — blurs the block and collapses the live
@@ -3621,8 +6215,8 @@ var DocxEditor = class _DocxEditor {
3621
6215
  * body edit root by design — also register. The fence still rejects other editors on the page. */
3622
6216
  editableBlockOf(node) {
3623
6217
  if (!node) return null;
3624
- const start = node.nodeType === 1 ? node : node.parentElement;
3625
- const block = start?.closest('[data-anchor][contenteditable="true"]') ?? null;
6218
+ const start2 = node.nodeType === 1 ? node : node.parentElement;
6219
+ const block = start2?.closest('[data-anchor][contenteditable="true"]') ?? null;
3626
6220
  return block && this.container.contains(block) ? block : null;
3627
6221
  }
3628
6222
  /**
@@ -3663,18 +6257,34 @@ var DocxEditor = class _DocxEditor {
3663
6257
  paginated: options.paginated ?? false,
3664
6258
  scale: options.scale ?? 1,
3665
6259
  headerFooter: options.headerFooter ?? false,
3666
- onEdit: options.onEdit
6260
+ blockDrag: options.blockDrag ?? false,
6261
+ trackedChanges: options.trackedChanges ?? 0 /* Accept */,
6262
+ revisionAuthor: options.revisionAuthor ?? "docxodus",
6263
+ onEdit: options.onEdit,
6264
+ onMove: options.onMove
3667
6265
  };
3668
- const handle = exports.DocxSessionBridge.OpenSession(bytes, '{"emitMarkdownPatch":false}');
6266
+ const handle = exports.DocxSessionBridge.OpenSession(bytes, JSON.stringify({
6267
+ emitMarkdownPatch: false,
6268
+ trackedChanges: trackedChangeWireName(opts.trackedChanges),
6269
+ revisionAuthor: opts.revisionAuthor
6270
+ }));
3669
6271
  const editor = new _DocxEditor(container, exports, handle, opts);
3670
6272
  editor.refreshAnchorMap();
3671
6273
  if (opts.headerFooter) editor.createRegion();
3672
6274
  const fullHtml = exports.DocumentConverter.ConvertDocxToHtmlComplete(
3673
- ...completeArgs(bytes, opts.cssPrefix, opts.fabricateClasses, opts.paginated, opts.scale)
6275
+ ...completeArgs(
6276
+ bytes,
6277
+ opts.cssPrefix,
6278
+ opts.fabricateClasses,
6279
+ opts.paginated,
6280
+ opts.scale,
6281
+ opts.trackedChanges === 1 /* RenderInline */
6282
+ )
3674
6283
  );
3675
6284
  if (opts.paginated) editor.mountPaginated(fullHtml);
3676
6285
  else editor.mountHtml(fullHtml);
3677
6286
  editor.syncRegionToBody();
6287
+ editor.setupBlockDrag();
3678
6288
  return editor;
3679
6289
  }
3680
6290
  /**
@@ -3701,6 +6311,7 @@ var DocxEditor = class _DocxEditor {
3701
6311
  document.removeEventListener("mouseup", this.onMouseUp, true);
3702
6312
  }
3703
6313
  this.clearDragSelection();
6314
+ this.teardownBlockDrag();
3704
6315
  this.exports.DocxSessionBridge.CloseSession(this.handle);
3705
6316
  }
3706
6317
  /**
@@ -3728,6 +6339,416 @@ var DocxEditor = class _DocxEditor {
3728
6339
  get sessionHandle() {
3729
6340
  return this.handle;
3730
6341
  }
6342
+ /** Move one top-level body block relative to another and repaint from the live session. */
6343
+ moveBlock(sourceAnchorId, targetAnchorId, position) {
6344
+ this.assertOpen();
6345
+ const bridge = this.exports.DocxSessionBridge;
6346
+ if (typeof bridge.MoveBlock !== "function") return false;
6347
+ const res = this.parseEdit(
6348
+ bridge.MoveBlock(this.handle, sourceAnchorId, targetAnchorId, position)
6349
+ );
6350
+ if (!res.success) {
6351
+ this.lastMoveError = res.error?.message ?? null;
6352
+ this.announceBlockMove("This block cannot be moved there.");
6353
+ return false;
6354
+ }
6355
+ if ((res.created?.length ?? 0) === 0 && (res.modified?.length ?? 0) === 0 && (res.removed?.length ?? 0) === 0) {
6356
+ this.announceBlockMove("The block is already in that position.");
6357
+ return true;
6358
+ }
6359
+ const destination = res.created?.[0] ?? res.modified?.[0];
6360
+ if (this.renderTrackedChanges) this.remount();
6361
+ else this.reconcile();
6362
+ const moved = destination ? this.bodyUnitNodes().find((el) => el.getAttribute("data-anchor") === destination.unid) : null;
6363
+ if (moved) {
6364
+ moved.classList.add("docx-block-move-flash");
6365
+ moved.addEventListener("animationend", () => moved.classList.remove("docx-block-move-flash"), {
6366
+ once: true
6367
+ });
6368
+ const focusTarget = EDITABLE_TAGS.has(moved.tagName) ? moved : moved.querySelector('[data-anchor][contenteditable="true"]');
6369
+ if (focusTarget) {
6370
+ this.activeBlock = focusTarget;
6371
+ focusTarget.focus({ preventScroll: true });
6372
+ }
6373
+ }
6374
+ this.options.onMove?.({
6375
+ sourceAnchorId,
6376
+ destinationAnchorId: destination?.id ?? sourceAnchorId
6377
+ });
6378
+ this.announceBlockMove("Block moved.");
6379
+ return true;
6380
+ }
6381
+ /** Resolve any rendered descendant to its top-level body move unit (tables stay whole). */
6382
+ blockUnitOf(target) {
6383
+ const node = target instanceof Node ? target : null;
6384
+ const el = node?.nodeType === Node.ELEMENT_NODE ? node : node?.parentElement;
6385
+ if (!el || !this.editRoot.contains(el)) return null;
6386
+ return this.bodyUnitNodes().find((unit) => unit === el || unit.contains(el)) ?? null;
6387
+ }
6388
+ isMovableBlockUnit(unit) {
6389
+ if (!unit || !this.anchorIdOf(unit)) return false;
6390
+ if (unit.matches("[class$='row-del'], [class*='row-del ']") || unit.querySelector("tr[class$='row-del'], tr[class*='row-del '], del[class$='move-from'], del[class*='move-from ']")) return false;
6391
+ return unit.tagName === "TABLE" || EDITABLE_TAGS.has(unit.tagName);
6392
+ }
6393
+ currentBlockDragSource() {
6394
+ if (this.isMovableBlockUnit(this.blockDragSource) && this.blockDragSource.isConnected)
6395
+ return this.blockDragSource;
6396
+ const fromActive = this.blockUnitOf(this.activeBlock);
6397
+ if (this.isMovableBlockUnit(fromActive)) {
6398
+ this.blockDragSource = fromActive;
6399
+ return fromActive;
6400
+ }
6401
+ return null;
6402
+ }
6403
+ showBlockHandle(unit) {
6404
+ const handle = this.blockDragHandle;
6405
+ if (!handle || !this.isMovableBlockUnit(unit)) return;
6406
+ const changed = unit !== this.blockDragSource;
6407
+ this.blockDragSource = unit;
6408
+ if (changed) this.refreshBlockMoveTargets(unit);
6409
+ if (this.blockMoveTargets?.size === 0) {
6410
+ handle.style.display = "none";
6411
+ return;
6412
+ }
6413
+ const rect = unit.getBoundingClientRect();
6414
+ handle.style.display = "flex";
6415
+ handle.style.left = `${Math.max(4, rect.left - 32)}px`;
6416
+ handle.style.top = `${Math.max(4, rect.top + (unit.tagName === "TABLE" ? 6 : Math.max(0, (rect.height - 28) / 2)))}px`;
6417
+ const preview = (unit.textContent ?? "").trim().replace(/\s+/g, " ").slice(0, 48);
6418
+ handle.setAttribute("aria-label", preview ? `Move block: ${preview}` : "Move block");
6419
+ if (changed) this.refreshBlockDropTargets();
6420
+ }
6421
+ hideBlockHandle() {
6422
+ if (this.blockDragging || this.blockMoveMenu?.style.display === "block") return;
6423
+ if (this.blockDragHandle) this.blockDragHandle.style.display = "none";
6424
+ }
6425
+ positionBlockHandle() {
6426
+ const source = this.currentBlockDragSource();
6427
+ if (source && this.blockDragHandle?.style.display !== "none") this.showBlockHandle(source);
6428
+ }
6429
+ showDropIndicator(target, position) {
6430
+ const indicator = this.blockDropIndicator;
6431
+ if (!indicator) return;
6432
+ const rect = this.unitWrapperOf(target).getBoundingClientRect();
6433
+ indicator.style.display = "block";
6434
+ indicator.style.left = `${rect.left}px`;
6435
+ indicator.style.top = `${position === "before" ? rect.top - 1 : rect.bottom - 1}px`;
6436
+ indicator.style.width = `${Math.max(24, rect.width)}px`;
6437
+ }
6438
+ hideDropIndicator() {
6439
+ if (this.blockDropIndicator) this.blockDropIndicator.style.display = "none";
6440
+ }
6441
+ announceBlockMove(message) {
6442
+ const live = this.blockMoveLive;
6443
+ if (!live) return;
6444
+ live.textContent = "";
6445
+ this.container.ownerDocument.defaultView?.setTimeout(() => {
6446
+ live.textContent = message;
6447
+ }, 0);
6448
+ }
6449
+ /**
6450
+ * Ask the engine which anchors the current source may move next to. One call per drag source,
6451
+ * so the UI offers only drops MoveBlock will accept — a document with section breaks is
6452
+ * partitioned into regions, and drawing an indicator across one only to fail the drop was the
6453
+ * behaviour this replaces. Null (no bridge support) keeps the previous offer-everything path.
6454
+ */
6455
+ refreshBlockMoveTargets(source) {
6456
+ const bridge = this.exports.DocxSessionBridge;
6457
+ const sourceId = source ? this.anchorIdOf(source) : null;
6458
+ if (!sourceId || typeof bridge.ValidMoveTargets !== "function") {
6459
+ this.blockMoveTargets = null;
6460
+ return;
6461
+ }
6462
+ try {
6463
+ const targets = JSON.parse(bridge.ValidMoveTargets(this.handle, sourceId));
6464
+ this.blockMoveTargets = new Map(
6465
+ targets.map((t) => [t.anchorId, { before: t.before, after: t.after }])
6466
+ );
6467
+ } catch {
6468
+ this.blockMoveTargets = null;
6469
+ }
6470
+ }
6471
+ /**
6472
+ * Whether `unit` is a legal destination for the current drag source — for a SPECIFIC side when
6473
+ * one is given. A cross-block range or a section break between the blocks can make one side
6474
+ * legal and the other not, so "this target is reachable" is not enough to pick a position.
6475
+ */
6476
+ isValidMoveTarget(unit, position) {
6477
+ if (!this.blockMoveTargets) return true;
6478
+ const id = this.anchorIdOf(unit);
6479
+ const sides = id ? this.blockMoveTargets.get(id) : void 0;
6480
+ if (!sides) return false;
6481
+ return position ? sides[position] : sides.before || sides.after;
6482
+ }
6483
+ /**
6484
+ * The side of `unit` a drop at `clientY` should land on: the half the pointer is in, snapped to
6485
+ * the other side when only that one is legal. Snapping rather than refusing keeps a reachable
6486
+ * target usable — the illegal side is usually illegal only because a section break or a
6487
+ * cross-block range sits between the two blocks on that side.
6488
+ */
6489
+ dropPositionFor(unit, clientY) {
6490
+ const rect = unit.getBoundingClientRect();
6491
+ const preferred = clientY < rect.top + rect.height / 2 ? "before" : "after";
6492
+ if (this.isValidMoveTarget(unit, preferred)) return preferred;
6493
+ const other = preferred === "before" ? "after" : "before";
6494
+ return this.isValidMoveTarget(unit, other) ? other : preferred;
6495
+ }
6496
+ refreshBlockDropTargets() {
6497
+ for (const cleanup of this.blockDragTargetCleanup.splice(0)) cleanup();
6498
+ if (!this.blockDragHandle || this.options.paginated) return;
6499
+ for (const unit of this.bodyUnitNodes().filter((el) => this.isMovableBlockUnit(el))) {
6500
+ this.blockDragTargetCleanup.push(dropTargetForElements({
6501
+ element: unit,
6502
+ // A target the engine would refuse is not a drop target at all, so Pragmatic never
6503
+ // fires onDragEnter for it and no indicator is drawn over it.
6504
+ canDrop: ({ source }) => source.data.type === BLOCK_DRAG_TYPE && source.data.sourceAnchorId !== this.anchorIdOf(unit) && this.isValidMoveTarget(unit),
6505
+ getData: ({ input }) => ({
6506
+ type: BLOCK_DRAG_TYPE,
6507
+ targetAnchorId: this.anchorIdOf(unit),
6508
+ position: this.dropPositionFor(unit, input.clientY),
6509
+ targetElement: unit
6510
+ }),
6511
+ onDragEnter: ({ self }) => {
6512
+ const pos = self.data.position === "after" ? "after" : "before";
6513
+ this.showDropIndicator(unit, pos);
6514
+ },
6515
+ onDrag: ({ self }) => {
6516
+ const pos = self.data.position === "after" ? "after" : "before";
6517
+ this.showDropIndicator(unit, pos);
6518
+ },
6519
+ onDragLeave: () => this.hideDropIndicator()
6520
+ }));
6521
+ }
6522
+ }
6523
+ closeBlockMoveMenu(restoreFocus = false) {
6524
+ if (!this.blockMoveMenu || !this.blockDragHandle) return;
6525
+ this.blockMoveMenu.style.display = "none";
6526
+ this.blockDragHandle.setAttribute("aria-expanded", "false");
6527
+ this.blockDragHandle.setAttribute("aria-pressed", "false");
6528
+ if (restoreFocus) this.blockDragHandle.focus({ preventScroll: true });
6529
+ }
6530
+ openBlockMoveMenu() {
6531
+ const menu = this.blockMoveMenu;
6532
+ const handle = this.blockDragHandle;
6533
+ const source = this.currentBlockDragSource();
6534
+ if (!menu || !handle || !source) return;
6535
+ this.refreshBlockMoveTargets(source);
6536
+ menu.querySelectorAll("button[data-move]").forEach((button) => {
6537
+ button.disabled = !this.blockMoveDestination(source, button.dataset.move ?? "");
6538
+ });
6539
+ const rect = handle.getBoundingClientRect();
6540
+ menu.style.display = "block";
6541
+ menu.style.left = `${Math.max(4, rect.right + 6)}px`;
6542
+ menu.style.top = `${Math.max(4, rect.top)}px`;
6543
+ handle.setAttribute("aria-expanded", "true");
6544
+ handle.setAttribute("aria-pressed", "true");
6545
+ menu.querySelector("button:not(:disabled)")?.focus({ preventScroll: true });
6546
+ }
6547
+ /**
6548
+ * Resolve a move-menu action to the block it should land against, considering only destinations
6549
+ * the engine accepts. "Top"/"bottom" therefore mean the ends of the source's own movable region
6550
+ * — on a document with section breaks that is the section, not the document, which is what makes
6551
+ * the commands work at all there instead of always failing.
6552
+ */
6553
+ blockMoveDestination(source, action) {
6554
+ const units = this.bodyUnitNodes().filter((el) => this.isMovableBlockUnit(el));
6555
+ const index = units.indexOf(source);
6556
+ if (index < 0) return null;
6557
+ const position = action === "up" || action === "top" ? "before" : "after";
6558
+ const candidates = units.filter((el) => el !== source && this.isValidMoveTarget(el, position)).filter((el) => position === "before" ? units.indexOf(el) < index : units.indexOf(el) > index);
6559
+ if (candidates.length === 0) return null;
6560
+ if (action === "up") return { target: candidates[candidates.length - 1], position };
6561
+ if (action === "down") return { target: candidates[0], position };
6562
+ if (action === "top") return { target: candidates[0], position };
6563
+ if (action === "bottom") return { target: candidates[candidates.length - 1], position };
6564
+ return null;
6565
+ }
6566
+ runBlockMoveMenuAction(action) {
6567
+ const source = this.currentBlockDragSource();
6568
+ if (!source) return;
6569
+ const destination = this.blockMoveDestination(source, action);
6570
+ this.closeBlockMoveMenu();
6571
+ if (!destination) return;
6572
+ const sourceId = this.anchorIdOf(source);
6573
+ const targetId = this.anchorIdOf(destination.target);
6574
+ if (sourceId && targetId) this.moveBlock(sourceId, targetId, destination.position);
6575
+ }
6576
+ /** The nearest ancestor that actually scrolls the document flow, for drag autoscroll. */
6577
+ scrollContainer() {
6578
+ const view = this.container.ownerDocument.defaultView;
6579
+ for (let el = this.editRoot; el; el = el.parentElement) {
6580
+ const overflowY = view?.getComputedStyle(el).overflowY ?? "visible";
6581
+ if ((overflowY === "auto" || overflowY === "scroll") && el.scrollHeight > el.clientHeight)
6582
+ return el;
6583
+ }
6584
+ return null;
6585
+ }
6586
+ /** Mount one floating handle; PDD owns pointer dragging while the menu owns keyboard moves. */
6587
+ setupBlockDrag() {
6588
+ if (!this.options.blockDrag || this.options.paginated || this.closed || this.blockDragHandle)
6589
+ return;
6590
+ const doc = this.container.ownerDocument;
6591
+ ensureBlockDragStyles(doc);
6592
+ const handle = doc.createElement("div");
6593
+ handle.className = "docx-block-handle";
6594
+ handle.textContent = "\u283F";
6595
+ handle.tabIndex = 0;
6596
+ handle.setAttribute("role", "button");
6597
+ handle.setAttribute("contenteditable", "false");
6598
+ handle.setAttribute("aria-haspopup", "menu");
6599
+ handle.setAttribute("aria-expanded", "false");
6600
+ handle.setAttribute("aria-pressed", "false");
6601
+ const indicator = doc.createElement("div");
6602
+ indicator.className = "docx-block-drop-indicator";
6603
+ const menu = doc.createElement("div");
6604
+ menu.className = "docx-block-move-menu";
6605
+ menu.setAttribute("role", "menu");
6606
+ menu.innerHTML = `
6607
+ <button type="button" role="menuitem" data-move="up">Move up</button>
6608
+ <button type="button" role="menuitem" data-move="down">Move down</button>
6609
+ <button type="button" role="menuitem" data-move="top">Move to top</button>
6610
+ <button type="button" role="menuitem" data-move="bottom">Move to bottom</button>`;
6611
+ const live = doc.createElement("div");
6612
+ live.className = "docx-block-live-region";
6613
+ live.setAttribute("role", "status");
6614
+ live.setAttribute("aria-live", "polite");
6615
+ this.container.append(handle, indicator, menu, live);
6616
+ this.blockDragHandle = handle;
6617
+ this.blockDropIndicator = indicator;
6618
+ this.blockMoveMenu = menu;
6619
+ this.blockMoveLive = live;
6620
+ const onPointerMove = (event) => {
6621
+ if (this.blockDragging || this.blockDragPointerDown) return;
6622
+ const unit = this.blockUnitOf(event.target);
6623
+ if (this.isMovableBlockUnit(unit)) this.showBlockHandle(unit);
6624
+ };
6625
+ const onFocusIn = (event) => {
6626
+ const unit = this.blockUnitOf(event.target);
6627
+ if (this.isMovableBlockUnit(unit)) this.showBlockHandle(unit);
6628
+ };
6629
+ const onPointerLeave = (event) => {
6630
+ const next = event.relatedTarget instanceof Node ? event.relatedTarget : null;
6631
+ if (next && (handle.contains(next) || menu.contains(next))) return;
6632
+ this.hideBlockHandle();
6633
+ };
6634
+ const onViewportChange = () => this.positionBlockHandle();
6635
+ this.container.addEventListener("pointermove", onPointerMove);
6636
+ this.container.addEventListener("focusin", onFocusIn);
6637
+ this.container.addEventListener("pointerleave", onPointerLeave);
6638
+ doc.addEventListener("scroll", onViewportChange, true);
6639
+ doc.defaultView?.addEventListener("resize", onViewportChange);
6640
+ this.blockDragCleanup.push(
6641
+ () => this.container.removeEventListener("pointermove", onPointerMove),
6642
+ () => this.container.removeEventListener("focusin", onFocusIn),
6643
+ () => this.container.removeEventListener("pointerleave", onPointerLeave),
6644
+ () => doc.removeEventListener("scroll", onViewportChange, true),
6645
+ () => doc.defaultView?.removeEventListener("resize", onViewportChange)
6646
+ );
6647
+ const onHandleClick = () => {
6648
+ if (menu.style.display === "block") this.closeBlockMoveMenu();
6649
+ else this.openBlockMoveMenu();
6650
+ };
6651
+ const onHandlePointerDown = () => {
6652
+ this.blockDragPointerDown = true;
6653
+ };
6654
+ const onPointerUp = () => {
6655
+ this.blockDragPointerDown = false;
6656
+ };
6657
+ const onHandleKeydown = (event) => {
6658
+ if (event.key !== "Enter" && event.key !== " ") return;
6659
+ event.preventDefault();
6660
+ onHandleClick();
6661
+ };
6662
+ const onMenuClick = (event) => {
6663
+ const button = event.target?.closest("button[data-move]");
6664
+ if (button && !button.disabled) this.runBlockMoveMenuAction(button.dataset.move ?? "");
6665
+ };
6666
+ const onMenuKeydown = (event) => {
6667
+ if (event.key === "Escape") {
6668
+ event.preventDefault();
6669
+ this.closeBlockMoveMenu(true);
6670
+ }
6671
+ };
6672
+ handle.addEventListener("click", onHandleClick);
6673
+ handle.addEventListener("pointerdown", onHandlePointerDown);
6674
+ handle.addEventListener("keydown", onHandleKeydown);
6675
+ menu.addEventListener("click", onMenuClick);
6676
+ menu.addEventListener("keydown", onMenuKeydown);
6677
+ doc.addEventListener("pointerup", onPointerUp, true);
6678
+ doc.addEventListener("pointercancel", onPointerUp, true);
6679
+ this.blockDragCleanup.push(
6680
+ () => handle.removeEventListener("click", onHandleClick),
6681
+ () => handle.removeEventListener("pointerdown", onHandlePointerDown),
6682
+ () => handle.removeEventListener("keydown", onHandleKeydown),
6683
+ () => menu.removeEventListener("click", onMenuClick),
6684
+ () => menu.removeEventListener("keydown", onMenuKeydown),
6685
+ () => doc.removeEventListener("pointerup", onPointerUp, true),
6686
+ () => doc.removeEventListener("pointercancel", onPointerUp, true)
6687
+ );
6688
+ this.blockDragCleanup.push(draggable({
6689
+ element: handle,
6690
+ canDrag: () => !!this.currentBlockDragSource(),
6691
+ getInitialData: () => {
6692
+ const source = this.currentBlockDragSource();
6693
+ return { type: BLOCK_DRAG_TYPE, sourceAnchorId: source ? this.anchorIdOf(source) : void 0 };
6694
+ },
6695
+ onDragStart: () => {
6696
+ this.blockDragging = true;
6697
+ handle.classList.add("docx-block-dragging");
6698
+ this.closeBlockMoveMenu();
6699
+ this.refreshBlockMoveTargets(this.currentBlockDragSource());
6700
+ this.refreshBlockDropTargets();
6701
+ },
6702
+ onDrop: () => {
6703
+ this.blockDragging = false;
6704
+ this.blockDragPointerDown = false;
6705
+ handle.classList.remove("docx-block-dragging");
6706
+ this.hideDropIndicator();
6707
+ }
6708
+ }));
6709
+ this.blockDragCleanup.push(monitorForElements({
6710
+ canMonitor: ({ source }) => source.data.type === BLOCK_DRAG_TYPE,
6711
+ onDrop: ({ source, location: location2 }) => {
6712
+ this.hideDropIndicator();
6713
+ const drop = location2.current.dropTargets[0]?.data;
6714
+ const sourceId = source.data.sourceAnchorId;
6715
+ const targetId = drop?.targetAnchorId;
6716
+ const position = drop?.position === "after" ? "after" : "before";
6717
+ if (typeof sourceId === "string" && typeof targetId === "string")
6718
+ this.moveBlock(sourceId, targetId, position);
6719
+ else
6720
+ this.announceBlockMove("Move cancelled \u2014 the block was not dropped on a valid position.");
6721
+ }
6722
+ }));
6723
+ const scroller = this.scrollContainer();
6724
+ if (scroller) {
6725
+ this.blockDragCleanup.push(autoScrollForElements({
6726
+ element: scroller,
6727
+ canScroll: ({ source }) => source.data.type === BLOCK_DRAG_TYPE,
6728
+ getAllowedAxis: () => "vertical"
6729
+ }));
6730
+ }
6731
+ this.blockDragCleanup.push(autoScrollWindowForElements({
6732
+ canScroll: ({ source }) => source.data.type === BLOCK_DRAG_TYPE,
6733
+ getAllowedAxis: () => "vertical"
6734
+ }));
6735
+ this.refreshBlockDropTargets();
6736
+ }
6737
+ teardownBlockDrag() {
6738
+ for (const cleanup of this.blockDragTargetCleanup.splice(0)) cleanup();
6739
+ for (const cleanup of this.blockDragCleanup.splice(0)) cleanup();
6740
+ this.blockDragHandle?.remove();
6741
+ this.blockDropIndicator?.remove();
6742
+ this.blockMoveMenu?.remove();
6743
+ this.blockMoveLive?.remove();
6744
+ this.blockDragHandle = null;
6745
+ this.blockDropIndicator = null;
6746
+ this.blockMoveMenu = null;
6747
+ this.blockMoveLive = null;
6748
+ this.blockDragSource = null;
6749
+ this.blockDragging = false;
6750
+ this.blockDragPointerDown = false;
6751
+ }
3731
6752
  // ─── internals ───────────────────────────────────────────────────────
3732
6753
  assertOpen() {
3733
6754
  if (this.closed) throw new Error("DocxEditor is closed");
@@ -3849,6 +6870,10 @@ var DocxEditor = class _DocxEditor {
3849
6870
  }
3850
6871
  wireBlock(el) {
3851
6872
  if (!EDITABLE_TAGS.has(el.tagName)) return;
6873
+ if (el.closest("tr[class$='row-del'], tr[class*='row-del ']") || el.querySelector(":scope > del[class$='move-from'], :scope > del[class*='move-from ']")) {
6874
+ el.setAttribute("contenteditable", "false");
6875
+ return;
6876
+ }
3852
6877
  const unid = el.getAttribute("data-anchor");
3853
6878
  if (!unid || !this.anchorIdOf(el)) return;
3854
6879
  el.setAttribute("contenteditable", "true");
@@ -3910,12 +6935,7 @@ var DocxEditor = class _DocxEditor {
3910
6935
  this.options.onEdit?.({ anchorId: newAnchor, unid: newUnid });
3911
6936
  return;
3912
6937
  }
3913
- const html = this.exports.DocxSessionBridge.RenderBlockHtml(
3914
- this.handle,
3915
- newAnchor,
3916
- this.options.cssPrefix,
3917
- this.options.fabricateClasses
3918
- );
6938
+ const html = this.renderBlockHtml(newAnchor);
3919
6939
  if (html.charCodeAt(0) !== 123) {
3920
6940
  const fresh = new DOMParser().parseFromString(html, "text/html").body.firstElementChild;
3921
6941
  const inBand = this.isBandBlock(el);
@@ -3956,9 +6976,10 @@ var DocxEditor = class _DocxEditor {
3956
6976
  }
3957
6977
  }
3958
6978
  const inTableCell = !!el.closest("table");
3959
- if (ev.key === "Tab") {
6979
+ if (ev.key === "Tab" && !ev.ctrlKey && !ev.metaKey && !ev.altKey && !ev.isComposing) {
3960
6980
  if (inTableCell) {
3961
6981
  ev.preventDefault();
6982
+ this.navigateTableCell(el, ev.shiftKey);
3962
6983
  return;
3963
6984
  }
3964
6985
  if (isListBlock(el)) {
@@ -3987,6 +7008,42 @@ var DocxEditor = class _DocxEditor {
3987
7008
  }
3988
7009
  }
3989
7010
  }
7011
+ /** Editable cells in visual document order, excluding cells from any nested table. */
7012
+ tableCellsFor(el) {
7013
+ const cell = el.closest("td, th");
7014
+ const table = cell?.closest("table");
7015
+ if (!cell || !table) return null;
7016
+ const cells = Array.from(table.querySelectorAll("td, th")).filter((candidate) => candidate.closest("table") === table);
7017
+ const index = cells.indexOf(cell);
7018
+ return index >= 0 ? { cells, index } : null;
7019
+ }
7020
+ /** First addressable paragraph in a cell, fenced against nested-table descendants. */
7021
+ editableInCell(cell) {
7022
+ return Array.from(
7023
+ cell.querySelectorAll('[data-anchor][contenteditable="true"]')
7024
+ ).find((block) => block.closest("td, th") === cell) ?? null;
7025
+ }
7026
+ /** Word-style cell navigation: Shift+Tab goes back, Tab goes forward, and Tab at the
7027
+ * final cell appends a row before entering its first cell. The first cell is a hard
7028
+ * boundary for Shift+Tab so focus never leaks out of the editor table. */
7029
+ navigateTableCell(el, backwards) {
7030
+ const state = this.tableCellsFor(el);
7031
+ if (!state) return;
7032
+ const adjacent = state.cells[state.index + (backwards ? -1 : 1)];
7033
+ if (adjacent) {
7034
+ const target2 = this.editableInCell(adjacent);
7035
+ if (target2) placeCaretAtOffset(target2, 0);
7036
+ return;
7037
+ }
7038
+ if (backwards) return;
7039
+ this.activeBlock = el;
7040
+ this.insertTableRow("below");
7041
+ const fresh = this.activeBlock ? this.tableCellsFor(this.activeBlock) : null;
7042
+ if (!fresh) return;
7043
+ const target = fresh.cells[fresh.index + 1];
7044
+ const block = target ? this.editableInCell(target) : null;
7045
+ if (block) placeCaretAtOffset(block, 0);
7046
+ }
3990
7047
  /** Shift+Enter: insert an intra-paragraph line break at the caret. Delegates to the
3991
7048
  * native `insertLineBreak` command, which inserts a <br> AND positions the caret
3992
7049
  * after it correctly (handling the browser's bogus trailing-<br> rule) so typing
@@ -4096,21 +7153,21 @@ var DocxEditor = class _DocxEditor {
4096
7153
  while (p < minLen && old[p] === next[p]) p++;
4097
7154
  let s = 0;
4098
7155
  while (s < minLen - p && old[old.length - 1 - s] === next[next.length - 1 - s]) s++;
4099
- let start = p;
7156
+ let start2 = p;
4100
7157
  let len = old.length - p - s;
4101
7158
  let middle = next.slice(p, next.length - s);
4102
7159
  if (len === 0) {
4103
- if (start > 0) {
4104
- start -= 1;
7160
+ if (start2 > 0) {
7161
+ start2 -= 1;
4105
7162
  len = 1;
4106
- middle = old[start] + middle;
7163
+ middle = old[start2] + middle;
4107
7164
  } else {
4108
7165
  len = 1;
4109
7166
  middle = middle + old[0];
4110
7167
  }
4111
7168
  }
4112
7169
  return this.parseEdit(
4113
- this.exports.DocxSessionBridge.ReplaceTextAtSpan(this.handle, fullId, start, len, middle)
7170
+ this.exports.DocxSessionBridge.ReplaceTextAtSpan(this.handle, fullId, start2, len, middle)
4114
7171
  );
4115
7172
  }
4116
7173
  /** Flush a block's current (uncommitted) text to the session; returns the live full id. */
@@ -4122,14 +7179,34 @@ var DocxEditor = class _DocxEditor {
4122
7179
  }
4123
7180
  /** Render a block by anchor and parse it into a detached element (null on error). */
4124
7181
  renderInto(anchorId) {
4125
- const html = this.exports.DocxSessionBridge.RenderBlockHtml(
7182
+ const html = this.renderBlockHtml(anchorId);
7183
+ if (html.charCodeAt(0) === 123) return null;
7184
+ return new DOMParser().parseFromString(html, "text/html").body.firstElementChild;
7185
+ }
7186
+ get renderTrackedChanges() {
7187
+ return this.options.trackedChanges === 1 /* RenderInline */;
7188
+ }
7189
+ renderBlockHtml(anchorId) {
7190
+ const bridge = this.exports.DocxSessionBridge;
7191
+ if (typeof bridge.RenderBlockHtmlForReview === "function") {
7192
+ return bridge.RenderBlockHtmlForReview(
7193
+ this.handle,
7194
+ anchorId,
7195
+ this.options.cssPrefix,
7196
+ this.options.fabricateClasses,
7197
+ this.renderTrackedChanges
7198
+ );
7199
+ }
7200
+ return bridge.RenderBlockHtml(
4126
7201
  this.handle,
4127
7202
  anchorId,
4128
7203
  this.options.cssPrefix,
4129
7204
  this.options.fabricateClasses
4130
7205
  );
4131
- if (html.charCodeAt(0) === 123) return null;
4132
- return new DOMParser().parseFromString(html, "text/html").body.firstElementChild;
7206
+ }
7207
+ renderPlanJson() {
7208
+ const bridge = this.exports.DocxSessionBridge;
7209
+ return typeof bridge.ListRenderedBlocks === "function" ? bridge.ListRenderedBlocks(this.handle, this.renderTrackedChanges) : bridge.ListBlocks(this.handle);
4133
7210
  }
4134
7211
  /** Render two blocks in ONE batched bridge call when the bundle carries RenderBlocksHtml —
4135
7212
  * the per-render shell/converter setup is paid once instead of twice, which matters on the
@@ -4140,14 +7217,20 @@ var DocxEditor = class _DocxEditor {
4140
7217
  const bridge = this.exports.DocxSessionBridge;
4141
7218
  if (typeof bridge.RenderBlocksHtml === "function") {
4142
7219
  try {
4143
- const map = JSON.parse(
4144
- bridge.RenderBlocksHtml(
4145
- this.handle,
4146
- JSON.stringify([a, b]),
4147
- this.options.cssPrefix,
4148
- this.options.fabricateClasses
4149
- )
7220
+ const idsJson = JSON.stringify([a, b]);
7221
+ const json = typeof bridge.RenderBlocksHtmlForReview === "function" ? bridge.RenderBlocksHtmlForReview(
7222
+ this.handle,
7223
+ idsJson,
7224
+ this.options.cssPrefix,
7225
+ this.options.fabricateClasses,
7226
+ this.renderTrackedChanges
7227
+ ) : bridge.RenderBlocksHtml(
7228
+ this.handle,
7229
+ idsJson,
7230
+ this.options.cssPrefix,
7231
+ this.options.fabricateClasses
4150
7232
  );
7233
+ const map = JSON.parse(json);
4151
7234
  if (!map.error) {
4152
7235
  const parse = (h) => h ? new DOMParser().parseFromString(h, "text/html").body.firstElementChild : null;
4153
7236
  const fa = parse(map[a]);
@@ -4190,9 +7273,9 @@ var DocxEditor = class _DocxEditor {
4190
7273
  const first = all.find((block) => block.getAttribute("data-anchor") === bookmark.startUnid);
4191
7274
  const last = all.find((block) => block.getAttribute("data-anchor") === bookmark.endUnid);
4192
7275
  if (!first || !last || first === last || all.indexOf(first) > all.indexOf(last)) return false;
4193
- const start = contentPositionIn(first, bookmark.startOffset);
7276
+ const start2 = contentPositionIn(first, bookmark.startOffset);
4194
7277
  const end = contentPositionIn(last, bookmark.endOffset);
4195
- return setSelectionBetween(start, end);
7278
+ return setSelectionBetween(start2, end);
4196
7279
  }
4197
7280
  /** Editable blocks the current selection covers, in document order. Uses Range.comparePoint
4198
7281
  * (robust to a selection boundary that normalized onto a wrapper element rather than a block
@@ -4235,8 +7318,8 @@ var DocxEditor = class _DocxEditor {
4235
7318
  if (hasStart && hasEnd) return selectionSpanIn(block);
4236
7319
  const contentLen = blockContentText(block).length;
4237
7320
  if (hasStart) {
4238
- const start = contentOffsetOf(block, range.startContainer, range.startOffset);
4239
- return trimmedSpan(block, { start, length: Math.max(0, contentLen - start) });
7321
+ const start2 = contentOffsetOf(block, range.startContainer, range.startOffset);
7322
+ return trimmedSpan(block, { start: start2, length: Math.max(0, contentLen - start2) });
4240
7323
  }
4241
7324
  if (hasEnd) {
4242
7325
  const end = contentOffsetOf(block, range.endContainer, range.endOffset);
@@ -4831,6 +7914,17 @@ var DocxEditor = class _DocxEditor {
4831
7914
  */
4832
7915
  renderFullHtml() {
4833
7916
  const bridge = this.exports.DocxSessionBridge;
7917
+ if (typeof bridge.RenderHtmlForReview === "function") {
7918
+ const html = bridge.RenderHtmlForReview(
7919
+ this.handle,
7920
+ this.options.cssPrefix,
7921
+ this.options.fabricateClasses,
7922
+ this.options.paginated,
7923
+ this.options.scale,
7924
+ this.renderTrackedChanges
7925
+ );
7926
+ if (html.charCodeAt(0) !== 123) return html;
7927
+ }
4834
7928
  if (typeof bridge.RenderHtml === "function") {
4835
7929
  const html = bridge.RenderHtml(
4836
7930
  this.handle,
@@ -4843,7 +7937,14 @@ var DocxEditor = class _DocxEditor {
4843
7937
  }
4844
7938
  const bytes = typeof bridge.SaveWithAnchorIds === "function" ? bridge.SaveWithAnchorIds(this.handle) : bridge.Save(this.handle);
4845
7939
  return this.exports.DocumentConverter.ConvertDocxToHtmlComplete(
4846
- ...completeArgs(bytes, this.options.cssPrefix, this.options.fabricateClasses, this.options.paginated, this.options.scale)
7940
+ ...completeArgs(
7941
+ bytes,
7942
+ this.options.cssPrefix,
7943
+ this.options.fabricateClasses,
7944
+ this.options.paginated,
7945
+ this.options.scale,
7946
+ this.renderTrackedChanges
7947
+ )
4847
7948
  );
4848
7949
  }
4849
7950
  /** Editable BODY blocks in document order (band blocks are enumerated by `ownerRoot`). */
@@ -4937,7 +8038,7 @@ var DocxEditor = class _DocxEditor {
4937
8038
  reconcileCore() {
4938
8039
  const bridge = this.exports.DocxSessionBridge;
4939
8040
  this.refreshAnchorMap();
4940
- const plan = JSON.parse(bridge.ListBlocks(this.handle));
8041
+ const plan = JSON.parse(this.renderPlanJson());
4941
8042
  if (plan.error) return this.bail(`plan error: ${plan.error}`);
4942
8043
  const oldNodes = this.bodyUnitNodes();
4943
8044
  const oldTokens = oldNodes.map(_DocxEditor.domTokenOf);
@@ -4947,19 +8048,26 @@ var DocxEditor = class _DocxEditor {
4947
8048
  const fnState = this.notesDiff("footnotes", plan.footnotes);
4948
8049
  const enState = this.notesDiff("endnotes", plan.endnotes);
4949
8050
  if (fnState === null || enState === null) return this.bail("notes container unstampable/missing");
4950
- const addedBodyIds = bodyDiff.added.map((j) => plan.body[j].id);
8051
+ const movedBodyNew = new Set(bodyDiff.moved.map((m) => m.newIndex));
8052
+ const addedBodyIds = bodyDiff.added.filter((j) => !movedBodyNew.has(j)).map((j) => plan.body[j].id);
4951
8053
  const addedNoteIds = fnState.diff.added.map((j) => plan.footnotes[j].id).concat(enState.diff.added.map((j) => plan.endnotes[j].id));
4952
8054
  const allIds = addedBodyIds.concat(addedNoteIds);
4953
8055
  let rendered = {};
4954
8056
  if (allIds.length > 0) {
4955
- rendered = JSON.parse(
4956
- bridge.RenderBlocksHtml(
4957
- this.handle,
4958
- JSON.stringify(allIds),
4959
- this.options.cssPrefix,
4960
- this.options.fabricateClasses
4961
- )
8057
+ const idsJson = JSON.stringify(allIds);
8058
+ const renderedJson = typeof bridge.RenderBlocksHtmlForReview === "function" ? bridge.RenderBlocksHtmlForReview(
8059
+ this.handle,
8060
+ idsJson,
8061
+ this.options.cssPrefix,
8062
+ this.options.fabricateClasses,
8063
+ this.renderTrackedChanges
8064
+ ) : bridge.RenderBlocksHtml(
8065
+ this.handle,
8066
+ idsJson,
8067
+ this.options.cssPrefix,
8068
+ this.options.fabricateClasses
4962
8069
  );
8070
+ rendered = JSON.parse(renderedJson);
4963
8071
  if (rendered.error) return this.bail(`render error: ${rendered.error}`);
4964
8072
  for (const id of allIds) if (!rendered[id]) return this.bail(`unrenderable: ${id}`);
4965
8073
  }
@@ -4969,7 +8077,7 @@ var DocxEditor = class _DocxEditor {
4969
8077
  return el;
4970
8078
  };
4971
8079
  const freshBody = /* @__PURE__ */ new Map();
4972
- for (const j of bodyDiff.added) {
8080
+ for (const j of bodyDiff.added.filter((j2) => !movedBodyNew.has(j2))) {
4973
8081
  const el = parse(rendered[plan.body[j].id]);
4974
8082
  if (!el) return this.bail(`unparseable render: ${plan.body[j].id}`);
4975
8083
  freshBody.set(j, el);
@@ -5019,13 +8127,6 @@ var DocxEditor = class _DocxEditor {
5019
8127
  * bail-reason string (parent ambiguity, order violation, wrapper semantics) — the
5020
8128
  * session is already correct, so bailing just means a full repaint. */
5021
8129
  applyBodyDiff(oldNodes, units, diff, fresh) {
5022
- let lastOld = -1;
5023
- for (let j = 0; j < units.length; j++) {
5024
- const oi = diff.keep.get(j);
5025
- if (oi === void 0) continue;
5026
- if (oi < lastOld) return "kept order violation";
5027
- lastOld = oi;
5028
- }
5029
8130
  const subOldByNew = new Map(diff.substituted.map((s) => [s.newIndex, s.oldIndex]));
5030
8131
  for (const [nj, oi] of subOldByNew) {
5031
8132
  const freshRoot = fresh.get(nj);
@@ -5041,13 +8142,18 @@ var DocxEditor = class _DocxEditor {
5041
8142
  }
5042
8143
  this.wireUnit(freshRoot, units[nj]);
5043
8144
  }
5044
- const pureAdded = diff.added.filter((j) => !subOldByNew.has(j));
8145
+ const movedOldByNew = new Map(diff.moved.map((m) => [m.newIndex, m.oldIndex]));
8146
+ const movedNew = new Set(diff.moved.map((m) => m.newIndex));
8147
+ const movedOld = new Set(diff.moved.map((m) => m.oldIndex));
8148
+ const pureAdded = diff.added.filter((j) => !subOldByNew.has(j) && !movedNew.has(j));
5045
8149
  const pureRemoved = diff.removed.filter(
5046
- (i) => !diff.substituted.some((s) => s.oldIndex === i)
8150
+ (i) => !diff.substituted.some((s) => s.oldIndex === i) && !movedOld.has(i)
5047
8151
  );
5048
8152
  const nodeAt = (j) => {
5049
8153
  const oi = diff.keep.get(j);
5050
8154
  if (oi !== void 0) return oldNodes[oi];
8155
+ const movedOi = movedOldByNew.get(j);
8156
+ if (movedOi !== void 0) return oldNodes[movedOi];
5051
8157
  if (subOldByNew.has(j)) return fresh.get(j);
5052
8158
  const f = fresh.get(j);
5053
8159
  return f && f.isConnected ? f : null;
@@ -5057,11 +8163,7 @@ var DocxEditor = class _DocxEditor {
5057
8163
  let prev = null;
5058
8164
  for (let k = j - 1; k >= 0 && !prev; k--) prev = nodeAt(k);
5059
8165
  let next = null;
5060
- for (let k = j + 1; k < units.length && !next; k++) {
5061
- const oi = diff.keep.get(k);
5062
- if (oi !== void 0) next = oldNodes[oi];
5063
- else if (subOldByNew.has(k)) next = fresh.get(k);
5064
- }
8166
+ for (let k = j + 1; k < units.length && !next; k++) next = nodeAt(k);
5065
8167
  const prevW = prev ? this.unitWrapperOf(prev) : null;
5066
8168
  const nextW = next ? this.unitWrapperOf(next) : null;
5067
8169
  if (prevW && nextW && prevW.parentElement !== nextW.parentElement)
@@ -5072,8 +8174,29 @@ var DocxEditor = class _DocxEditor {
5072
8174
  this.wireUnit(el, units[j]);
5073
8175
  }
5074
8176
  for (const i of pureRemoved) {
5075
- const wrapper = this.unitWrapperOf(oldNodes[i]);
5076
- wrapper.remove();
8177
+ this.unitWrapperOf(oldNodes[i]).remove();
8178
+ }
8179
+ for (const { newIndex } of [...diff.moved].sort((a, b) => a.newIndex - b.newIndex)) {
8180
+ const moving = nodeAt(newIndex);
8181
+ if (!moving?.isConnected) return "move source is not connected";
8182
+ const movingW = this.unitWrapperOf(moving);
8183
+ let prevW = null;
8184
+ for (let k = newIndex - 1; k >= 0 && !prevW; k--) {
8185
+ const n = nodeAt(k);
8186
+ if (n?.isConnected) prevW = this.unitWrapperOf(n);
8187
+ }
8188
+ let nextW = null;
8189
+ for (let k = newIndex + 1; k < units.length && !nextW; k++) {
8190
+ const n = nodeAt(k);
8191
+ if (n?.isConnected) nextW = this.unitWrapperOf(n);
8192
+ }
8193
+ if (prevW && prevW !== movingW && prevW.parentElement === movingW.parentElement) {
8194
+ prevW.after(movingW);
8195
+ } else if (nextW && nextW !== movingW && nextW.parentElement === movingW.parentElement) {
8196
+ nextW.before(movingW);
8197
+ } else {
8198
+ return "move neighbors in different parents";
8199
+ }
5077
8200
  }
5078
8201
  return true;
5079
8202
  }
@@ -5197,7 +8320,7 @@ var DocxEditor = class _DocxEditor {
5197
8320
  const bridge = this.exports.DocxSessionBridge;
5198
8321
  if (typeof bridge.ListBlocks !== "function") return;
5199
8322
  try {
5200
- const plan = JSON.parse(bridge.ListBlocks(this.handle));
8323
+ const plan = JSON.parse(this.renderPlanJson());
5201
8324
  if (plan.error) return;
5202
8325
  const nodes = this.bodyUnitNodes();
5203
8326
  if (nodes.length === plan.body.length) {
@@ -5226,6 +8349,7 @@ var DocxEditor = class _DocxEditor {
5226
8349
  * block's content-hashed unid changes across the save/reproject a remount performs.
5227
8350
  */
5228
8351
  remount(focusIndex = -1, caretAtEnd = false) {
8352
+ this.teardownBlockDrag();
5229
8353
  this.refreshAnchorMap();
5230
8354
  const fullHtml = this.renderFullHtml();
5231
8355
  this.activeBlock = null;
@@ -5240,6 +8364,7 @@ var DocxEditor = class _DocxEditor {
5240
8364
  }
5241
8365
  }
5242
8366
  this.syncRegionToBody(this.activeBlock ?? void 0);
8367
+ this.setupBlockDrag();
5243
8368
  }
5244
8369
  };
5245
8370
 
@@ -6448,8 +9573,12 @@ var RibbonSurface = class {
6448
9573
  editable: this.options.editable,
6449
9574
  scale: this.options.scale,
6450
9575
  onEdit: this.options.onEdit,
9576
+ onMove: this.options.onMove,
6451
9577
  paginated,
6452
- headerFooter: this.headerFooter
9578
+ headerFooter: this.headerFooter,
9579
+ blockDrag: this.options.blockDrag ?? true,
9580
+ trackedChanges: this.options.trackedChanges,
9581
+ revisionAuthor: this.options.revisionAuthor
6453
9582
  });
6454
9583
  this.require("save").disabled = false;
6455
9584
  this.require("ribbon").setAttribute("aria-disabled", "false");
@@ -6537,8 +9666,8 @@ var RibbonSurface = class {
6537
9666
  this.keepSelection(tab);
6538
9667
  tab.addEventListener("click", () => this.selectTab(tab.dataset.tab ?? "home"));
6539
9668
  }
6540
- const delegate = (selector, label, fn) => {
6541
- for (const el of Array.from(ribbon.querySelectorAll(selector))) {
9669
+ const delegate = (selector2, label, fn) => {
9670
+ for (const el of Array.from(ribbon.querySelectorAll(selector2))) {
6542
9671
  this.keepSelection(el);
6543
9672
  el.addEventListener("click", () => this.run(label(el), () => fn(el)));
6544
9673
  }
@@ -7253,10 +10382,10 @@ async function getRevisions(document2, options) {
7253
10382
  function docxDiffSettingsJson(settings) {
7254
10383
  return settings ? JSON.stringify(settings) : "";
7255
10384
  }
7256
- async function docxDiffCompare(left, right, settings) {
10385
+ async function docxDiffCompare(left2, right2, settings) {
7257
10386
  const exports = ensureInitialized();
7258
- const leftBytes = await toBytes(left);
7259
- const rightBytes = await toBytes(right);
10387
+ const leftBytes = await toBytes(left2);
10388
+ const rightBytes = await toBytes(right2);
7260
10389
  await yieldToMain();
7261
10390
  const result = exports.DocxDiffBridge.Compare(
7262
10391
  leftBytes,
@@ -7268,10 +10397,10 @@ async function docxDiffCompare(left, right, settings) {
7268
10397
  }
7269
10398
  return result;
7270
10399
  }
7271
- async function docxDiffGetRevisions(left, right, settings) {
10400
+ async function docxDiffGetRevisions(left2, right2, settings) {
7272
10401
  const exports = ensureInitialized();
7273
- const leftBytes = await toBytes(left);
7274
- const rightBytes = await toBytes(right);
10402
+ const leftBytes = await toBytes(left2);
10403
+ const rightBytes = await toBytes(right2);
7275
10404
  await yieldToMain();
7276
10405
  const result = exports.DocxDiffBridge.GetRevisionsJson(
7277
10406
  leftBytes,
@@ -7299,10 +10428,10 @@ async function docxDiffGetRevisions(left, right, settings) {
7299
10428
  rightAnchor: r.rightAnchor ?? r.RightAnchor ?? void 0
7300
10429
  }));
7301
10430
  }
7302
- async function docxDiffGetEditScript(left, right, settings) {
10431
+ async function docxDiffGetEditScript(left2, right2, settings) {
7303
10432
  const exports = ensureInitialized();
7304
- const leftBytes = await toBytes(left);
7305
- const rightBytes = await toBytes(right);
10433
+ const leftBytes = await toBytes(left2);
10434
+ const rightBytes = await toBytes(right2);
7306
10435
  await yieldToMain();
7307
10436
  const result = exports.DocxDiffBridge.GetEditScriptJson(
7308
10437
  leftBytes,
@@ -7930,8 +11059,8 @@ function createAnnotationFromSearch(id, labelId, documentText, searchText, occur
7930
11059
  if (occurrence > offsets.length) {
7931
11060
  return null;
7932
11061
  }
7933
- const { start, end } = offsets[occurrence - 1];
7934
- return createAnnotation(id, labelId, documentText, start, end);
11062
+ const { start: start2, end } = offsets[occurrence - 1];
11063
+ return createAnnotation(id, labelId, documentText, start2, end);
7935
11064
  }
7936
11065
  function findTextOccurrences(documentText, searchText, maxResults = 100) {
7937
11066
  if (!searchText) return [];
@@ -8173,7 +11302,7 @@ function createScopedMount(container) {
8173
11302
  }
8174
11303
  function splitSelectorList(selectorText) {
8175
11304
  const selectors = [];
8176
- let start = 0;
11305
+ let start2 = 0;
8177
11306
  let parentheses = 0;
8178
11307
  let brackets = 0;
8179
11308
  let quote = "";
@@ -8201,15 +11330,15 @@ function splitSelectorList(selectorText) {
8201
11330
  else if (ch === "[") brackets++;
8202
11331
  else if (ch === "]") brackets--;
8203
11332
  else if (ch === "," && parentheses === 0 && brackets === 0) {
8204
- selectors.push(selectorText.slice(start, i).trim());
8205
- start = i + 1;
11333
+ selectors.push(selectorText.slice(start2, i).trim());
11334
+ start2 = i + 1;
8206
11335
  }
8207
11336
  }
8208
- selectors.push(selectorText.slice(start).trim());
11337
+ selectors.push(selectorText.slice(start2).trim());
8209
11338
  return selectors.filter(Boolean);
8210
11339
  }
8211
- function scopeSelector(selector, rootSelector) {
8212
- let remaining = selector.trim();
11340
+ function scopeSelector(selector2, rootSelector) {
11341
+ let remaining = selector2.trim();
8213
11342
  let consumedRoot = false;
8214
11343
  let separated = false;
8215
11344
  for (; ; ) {
@@ -8240,7 +11369,7 @@ function scopeCssRules(container, rootSelector) {
8240
11369
  }
8241
11370
  if (rule.type === CSSRule.STYLE_RULE) {
8242
11371
  const styleRule = rule;
8243
- styleRule.selectorText = splitSelectorList(styleRule.selectorText).map((selector) => scopeSelector(selector, rootSelector)).join(", ");
11372
+ styleRule.selectorText = splitSelectorList(styleRule.selectorText).map((selector2) => scopeSelector(selector2, rootSelector)).join(", ");
8244
11373
  continue;
8245
11374
  }
8246
11375
  const grouping = rule;
@@ -8280,6 +11409,10 @@ function createScopedEditorExports(exports, rootSelector) {
8280
11409
  if (renderHtml) {
8281
11410
  bridge.RenderHtml = (...args) => scopeDocumentStyles(renderHtml(...args), rootSelector);
8282
11411
  }
11412
+ const renderHtmlForReview = bridge.RenderHtmlForReview;
11413
+ if (renderHtmlForReview) {
11414
+ bridge.RenderHtmlForReview = (...args) => scopeDocumentStyles(renderHtmlForReview(...args), rootSelector);
11415
+ }
8283
11416
  return {
8284
11417
  DocxSessionBridge: bridge,
8285
11418
  DocumentConverter: {
@@ -8308,7 +11441,7 @@ async function createViewer(container, source, options = {}) {
8308
11441
  const el = resolveContainer2(container);
8309
11442
  const { wasmBasePath: wasmBasePath2, ...conversion } = options;
8310
11443
  await ensureWasm(wasmBasePath2);
8311
- const mount = createScopedMount(el);
11444
+ const mount2 = createScopedMount(el);
8312
11445
  let lastHtml = "";
8313
11446
  const render = async (src, opts) => {
8314
11447
  const bytes = await toDocumentBytes(src);
@@ -8321,13 +11454,13 @@ async function createViewer(container, source, options = {}) {
8321
11454
  parsed.querySelectorAll("style").forEach((sourceStyle) => {
8322
11455
  const style = document.createElement("style");
8323
11456
  style.textContent = sourceStyle.textContent;
8324
- scopeStyleElement(style, mount.selector);
11457
+ scopeStyleElement(style, mount2.selector);
8325
11458
  fragment.appendChild(style);
8326
11459
  });
8327
11460
  const body = document.createElement("template");
8328
11461
  body.innerHTML = parsed.body.innerHTML;
8329
11462
  fragment.appendChild(body.content);
8330
- mount.root.replaceChildren(fragment);
11463
+ mount2.root.replaceChildren(fragment);
8331
11464
  };
8332
11465
  await render(source, conversion);
8333
11466
  return {
@@ -8345,13 +11478,13 @@ async function createEditor(container, source, options = {}) {
8345
11478
  const el = resolveContainer2(container);
8346
11479
  const { wasmBasePath: wasmBasePath2, ...editorOptions } = options;
8347
11480
  await ensureWasm(wasmBasePath2);
8348
- const mount = createScopedMount(el);
11481
+ const mount2 = createScopedMount(el);
8349
11482
  const exports = createScopedEditorExports(
8350
11483
  getWasmExports(),
8351
- mount.selector
11484
+ mount2.selector
8352
11485
  );
8353
11486
  try {
8354
- return source == null ? DocxEditor.openBlank(mount.root, exports, editorOptions) : DocxEditor.open(mount.root, await toDocumentBytes(source), exports, editorOptions);
11487
+ return source == null ? DocxEditor.openBlank(mount2.root, exports, editorOptions) : DocxEditor.open(mount2.root, await toDocumentBytes(source), exports, editorOptions);
8355
11488
  } catch (error) {
8356
11489
  el.replaceChildren();
8357
11490
  throw error;
@@ -8369,10 +11502,10 @@ function nameFromSource(source) {
8369
11502
  async function createRibbonEditor(container, source, options = {}) {
8370
11503
  const el = resolveContainer2(container);
8371
11504
  const { wasmBasePath: wasmBasePath2, ...ribbonOptions } = options;
8372
- const mount = createScopedMount(el);
8373
- mount.root.style.height = "100%";
8374
- mount.root.style.minHeight = "0";
8375
- const ribbon = mountRibbon(mount.root, {
11505
+ const mount2 = createScopedMount(el);
11506
+ mount2.root.style.height = "100%";
11507
+ mount2.root.style.minHeight = "0";
11508
+ const ribbon = mountRibbon(mount2.root, {
8376
11509
  documentName: ribbonOptions.documentName ?? nameFromSource(source),
8377
11510
  ...ribbonOptions,
8378
11511
  // Exports arrive after the runtime boots; the loader covers that gap.
@@ -8384,7 +11517,7 @@ async function createRibbonEditor(container, source, options = {}) {
8384
11517
  ribbon.setExports(
8385
11518
  createScopedEditorExports(
8386
11519
  getWasmExports(),
8387
- `${mount.selector} [data-dxr-surface]`
11520
+ `${mount2.selector} [data-dxr-surface]`
8388
11521
  )
8389
11522
  );
8390
11523
  ribbon.loader.stage(1);