@prosekit/web 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,50 @@
1
+ //#region src/utils/assign-styles.ts
2
+ /**
3
+ * A type-safe version of `Object.assign` for `element.style`.
4
+ */
5
+ function assignStyles(element, styles) {
6
+ Object.assign(element.style, styles);
7
+ }
8
+
9
+ //#endregion
10
+ //#region src/utils/clone-element.ts
11
+ /**
12
+ * Creates a deep clone of an Element, including all computed styles so that
13
+ * it looks the same as the original element.
14
+ */
15
+ function deepCloneElement(element) {
16
+ const clonedElement = element.cloneNode(true);
17
+ deepCopyStyles(element, clonedElement);
18
+ return clonedElement;
19
+ }
20
+ /**
21
+ * Creates a clone of an Element, including all computed styles so that
22
+ * it looks similar enough to the original element.
23
+ */
24
+ function cloneElement(element) {
25
+ const clonedElement = element.cloneNode();
26
+ copyStyles(element, clonedElement);
27
+ return clonedElement;
28
+ }
29
+ function deepCopyStyles(source, target) {
30
+ const sources = [source];
31
+ const targets = [target];
32
+ while (sources.length > 0 && sources.length === targets.length) {
33
+ const source$1 = sources.pop();
34
+ const target$1 = targets.pop();
35
+ if (!source$1 || !target$1) return;
36
+ copyStyles(source$1, target$1);
37
+ sources.push(...source$1.children);
38
+ targets.push(...target$1.children);
39
+ }
40
+ }
41
+ function copyStyles(source, target) {
42
+ if (!source || !target) return;
43
+ const sourceStyle = source.ownerDocument?.defaultView?.getComputedStyle(source);
44
+ const targetStyle = target.style;
45
+ if (!sourceStyle || !targetStyle) return;
46
+ for (const key of sourceStyle) targetStyle.setProperty(key, sourceStyle.getPropertyValue(key), sourceStyle.getPropertyPriority(key));
47
+ }
48
+
49
+ //#endregion
50
+ export { assignStyles, cloneElement, deepCloneElement };
@@ -1,4 +1,5 @@
1
1
  import { useEditorExtension } from "./use-editor-extension-Cc7ZG7uj.js";
2
+ import { assignStyles, deepCloneElement } from "./clone-element-B55UD54E.js";
2
3
  import { createContext, createSignal, defineCustomElement, registerCustomElement, useAttribute, useEffect, useEventListener } from "@aria-ui/core";
3
4
  import { defineDOMEventHandler, insertDefaultBlock, union } from "@prosekit/core";
4
5
  import { overlayPositionerEvents, overlayPositionerProps, useOverlayPositionerState } from "@aria-ui/overlay/elements";
@@ -49,46 +50,10 @@ const BlockHandleAddElementBase = defineCustomElement({
49
50
  var BlockHandleAddElement = class extends BlockHandleAddElementBase {};
50
51
  registerCustomElement("prosekit-block-handle-add", BlockHandleAddElement);
51
52
 
52
- //#endregion
53
- //#region src/utils/asset-styles.ts
54
- function assignStyles(element, styles) {
55
- Object.assign(element.style, styles);
56
- }
57
-
58
53
  //#endregion
59
54
  //#region src/utils/max-z-index.ts
60
55
  const maxZIndex = "2147483647";
61
56
 
62
- //#endregion
63
- //#region src/components/block-handle/block-handle-draggable/deep-clone-element.ts
64
- /**
65
- * Creates a deep clone of an Element, including all computed styles so that
66
- * it looks the same as the original element.
67
- */
68
- function deepCloneElement(element) {
69
- const clonedElement = element.cloneNode(true);
70
- deepCopyStyles(element, clonedElement);
71
- return clonedElement;
72
- }
73
- function deepCopyStyles(source, target) {
74
- const sources = [source];
75
- const targets = [target];
76
- while (sources.length > 0 && sources.length === targets.length) {
77
- const source$1 = sources.pop();
78
- const target$1 = targets.pop();
79
- if (!source$1 || !target$1) return;
80
- copyStyles(source$1, target$1);
81
- sources.push(...source$1.children);
82
- targets.push(...target$1.children);
83
- }
84
- }
85
- function copyStyles(source, target) {
86
- const sourceStyle = source.ownerDocument?.defaultView?.getComputedStyle(source);
87
- const targetStyle = target.style;
88
- if (!sourceStyle || !targetStyle) return;
89
- for (const key of sourceStyle) targetStyle.setProperty(key, sourceStyle.getPropertyValue(key), sourceStyle.getPropertyPriority(key));
90
- }
91
-
92
57
  //#endregion
93
58
  //#region src/components/block-handle/block-handle-draggable/set-drag-preview.ts
94
59
  /**
@@ -1,5 +1,6 @@
1
1
  import { getSafeEditorView, getStateWithDefaults } from "./get-safe-editor-view-CqJWgxo1.js";
2
2
  import { useEditorExtension } from "./use-editor-extension-Cc7ZG7uj.js";
3
+ import { assignStyles, cloneElement, deepCloneElement } from "./clone-element-B55UD54E.js";
3
4
  import { createComputed, createContext, createSignal, defineCustomElement, defineEmit, registerCustomElement, useAttribute, useEffect, useEventListener } from "@aria-ui/core";
4
5
  import { defineDOMEventHandler, union } from "@prosekit/core";
5
6
  import { useOverlayPositionerState } from "@aria-ui/overlay/elements";
@@ -141,8 +142,8 @@ function useTableHandleColumnTrigger(host, { state }) {
141
142
  if (emptyImage) dataTransfer.setDragImage(emptyImage, 0, 0);
142
143
  }
143
144
  const prev = dndContext.peek();
144
- const index = context.peek()?.colIndex ?? -1;
145
- if (index < 0) {
145
+ const index = context.peek()?.colIndex;
146
+ if (index == null || index < 0) {
146
147
  console.warn("[prosekit] Invalid column index for drag operation:", index);
147
148
  event.preventDefault();
148
149
  return;
@@ -239,7 +240,7 @@ function useInitDndPosition(host, editor, onInit) {
239
240
  })]
240
241
  }).then(({ x, y }) => {
241
242
  if (cancelled) return;
242
- Object.assign(host.style, {
243
+ assignStyles(host, {
243
244
  left: `${x}px`,
244
245
  top: `${y}px`
245
246
  });
@@ -286,25 +287,45 @@ function clearPreviewDOM(previewRoot) {
286
287
  }
287
288
  function createPreviewDOM(table, previewRoot, index, direction) {
288
289
  clearPreviewDOM(previewRoot);
289
- const previewTable = document.createElement("table");
290
- const previewTableBody = document.createElement("tbody");
290
+ const previewTable = cloneElementWithoutSize(table);
291
+ const tableBody = table.querySelector("tbody");
292
+ const previewTableBody = tableBody ? cloneElementWithoutSize(tableBody) : table.ownerDocument.createElement("tbody");
293
+ unsetSize(previewTableBody);
294
+ unsetSize(previewTable);
291
295
  previewTable.appendChild(previewTableBody);
292
296
  previewRoot.appendChild(previewTable);
293
297
  const rows = table.querySelectorAll("tr");
294
298
  if (direction === "row") {
295
299
  const row = rows[index];
296
- const rowDOM = row.cloneNode(true);
297
- previewTableBody.appendChild(rowDOM);
300
+ const previewRow = deepCloneElement(row);
301
+ previewTableBody.appendChild(previewRow);
298
302
  } else rows.forEach((row) => {
299
- const rowDOM = row.cloneNode(false);
303
+ const previewRow = cloneElementWithoutSize(row);
304
+ unsetSize(previewRow);
300
305
  const cells = row.querySelectorAll("td");
301
- if (cells[index]) {
302
- const cellDOM = cells[index].cloneNode(true);
303
- rowDOM.appendChild(cellDOM);
304
- previewTableBody.appendChild(rowDOM);
306
+ const cell = cells[index];
307
+ if (cell) {
308
+ const previewCell = deepCloneElement(cell);
309
+ previewRow.appendChild(previewCell);
310
+ previewTableBody.appendChild(previewRow);
305
311
  }
306
312
  });
307
313
  }
314
+ function cloneElementWithoutSize(element) {
315
+ const clonedElement = cloneElement(element);
316
+ unsetSize(clonedElement);
317
+ return clonedElement;
318
+ }
319
+ function unsetSize(element) {
320
+ assignStyles(element, {
321
+ width: "unset",
322
+ height: "unset",
323
+ minWidth: "unset",
324
+ minHeight: "unset",
325
+ maxWidth: "unset",
326
+ maxHeight: "unset"
327
+ });
328
+ }
308
329
 
309
330
  //#endregion
310
331
  //#region src/components/table-handle/table-handle-drag-preview/updater.ts
@@ -337,11 +358,11 @@ function useUpdatePreviewPosition(host, editor) {
337
358
  computePosition(getVirtualElement(cell, x, y), host, { placement: direction === "row" ? "right" : "bottom" }).then(({ x: x$1, y: y$1 }) => {
338
359
  if (cancelled) return;
339
360
  if (direction === "row") {
340
- Object.assign(host.style, { top: `${y$1}px` });
361
+ assignStyles(host, { top: `${y$1}px` });
341
362
  return;
342
363
  }
343
364
  if (direction === "col") {
344
- Object.assign(host.style, { left: `${x$1}px` });
365
+ assignStyles(host, { left: `${x$1}px` });
345
366
  return;
346
367
  }
347
368
  });
@@ -377,8 +398,7 @@ function getVirtualElement(cell, x, y) {
377
398
  function useTableHandleDragPreview(host, { state }) {
378
399
  const { editor } = state;
379
400
  useEffect(host, () => {
380
- host.classList.add("ProseMirror");
381
- Object.assign(host.style, {
401
+ assignStyles(host, {
382
402
  position: "absolute",
383
403
  pointerEvents: "none"
384
404
  });
@@ -387,7 +407,7 @@ function useTableHandleDragPreview(host, { state }) {
387
407
  useUpdatePreviewPosition(host, editor);
388
408
  }
389
409
  function onInitPreviewPosition({ host, direction, dragging, table, cell, draggingIndex }) {
390
- Object.assign(host.style, { display: dragging ? "block" : "none" });
410
+ assignStyles(host, { display: dragging ? "block" : "none" });
391
411
  if (!dragging) {
392
412
  clearPreviewDOM(host);
393
413
  return;
@@ -395,11 +415,11 @@ function onInitPreviewPosition({ host, direction, dragging, table, cell, draggin
395
415
  createPreviewDOM(table, host, draggingIndex, direction);
396
416
  const tableRect = table.getBoundingClientRect();
397
417
  const cellRect = cell.getBoundingClientRect();
398
- if (direction === "col") Object.assign(host.style, {
418
+ if (direction === "col") assignStyles(host, {
399
419
  width: `${cellRect.width}px`,
400
420
  height: `${tableRect.height}px`
401
421
  });
402
- if (direction === "row") Object.assign(host.style, {
422
+ if (direction === "row") assignStyles(host, {
403
423
  width: `${tableRect.width}px`,
404
424
  height: `${cellRect.height}px`
405
425
  });
@@ -499,7 +519,7 @@ function useUpdateIndicatorPosition(host, editor, handleWidth) {
499
519
  middleware: [offset(direction$1 === "left" ? -1 * handleWidth : 0)]
500
520
  }).then(({ x: x$1 }) => {
501
521
  if (cancelled) return;
502
- Object.assign(host.style, { left: `${x$1}px` });
522
+ assignStyles(host, { left: `${x$1}px` });
503
523
  });
504
524
  }
505
525
  return cleanup;
@@ -518,7 +538,7 @@ function useUpdateIndicatorPosition(host, editor, handleWidth) {
518
538
  middleware: [offset(direction$1 === "up" ? -1 * handleWidth : 0)]
519
539
  }).then(({ y: y$1 }) => {
520
540
  if (cancelled) return;
521
- Object.assign(host.style, { top: `${y$1}px` });
541
+ assignStyles(host, { top: `${y$1}px` });
522
542
  });
523
543
  }
524
544
  return cleanup;
@@ -535,7 +555,7 @@ const HANDLE_WIDTH = 2;
535
555
  function useTableHandleDropIndicator(host, { state }) {
536
556
  const { editor } = state;
537
557
  useEffect(host, () => {
538
- Object.assign(host.style, {
558
+ assignStyles(host, {
539
559
  pointerEvents: "none",
540
560
  position: "absolute"
541
561
  });
@@ -544,13 +564,13 @@ function useTableHandleDropIndicator(host, { state }) {
544
564
  useUpdateIndicatorPosition(host, editor, HANDLE_WIDTH);
545
565
  }
546
566
  function onInitIndicatorPosition({ host, direction, dragging, table }) {
547
- Object.assign(host.style, { display: dragging ? "block" : "none" });
567
+ assignStyles(host, { display: dragging ? "block" : "none" });
548
568
  const tableRect = table.getBoundingClientRect();
549
- if (direction === "col") Object.assign(host.style, {
569
+ if (direction === "col") assignStyles(host, {
550
570
  width: `${HANDLE_WIDTH}px`,
551
571
  height: `${tableRect.height}px`
552
572
  });
553
- if (direction === "row") Object.assign(host.style, {
573
+ if (direction === "row") assignStyles(host, {
554
574
  width: `${tableRect.width}px`,
555
575
  height: `${HANDLE_WIDTH}px`
556
576
  });
@@ -946,8 +966,8 @@ function useTableHandleRowTrigger(host, { state }) {
946
966
  if (emptyImage) dataTransfer.setDragImage(emptyImage, 0, 0);
947
967
  }
948
968
  const prev = dndContext.peek();
949
- const index = context.peek()?.rowIndex ?? -1;
950
- if (index < 0) {
969
+ const index = context.peek()?.rowIndex;
970
+ if (index == null || index < 0) {
951
971
  console.warn("[prosekit] Invalid row index for drag operation:", index);
952
972
  event.preventDefault();
953
973
  return;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/web",
3
3
  "type": "module",
4
- "version": "0.6.0",
4
+ "version": "0.6.1",
5
5
  "private": false,
6
6
  "description": "A collection of web components for ProseKit",
7
7
  "author": {
@@ -74,16 +74,16 @@
74
74
  "@floating-ui/dom": "^1.7.2",
75
75
  "@ocavue/utils": "^0.5.0",
76
76
  "prosemirror-tables": "^1.7.1",
77
+ "@prosekit/core": "^0.8.3",
77
78
  "@prosekit/extensions": "^0.10.0",
78
- "@prosekit/pm": "^0.1.11",
79
- "@prosekit/core": "^0.8.3"
79
+ "@prosekit/pm": "^0.1.11"
80
80
  },
81
81
  "devDependencies": {
82
82
  "tsdown": "^0.12.9",
83
83
  "typescript": "~5.8.3",
84
84
  "vitest": "^3.2.4",
85
- "@prosekit/config-vitest": "0.0.0",
86
- "@prosekit/config-tsdown": "0.0.0"
85
+ "@prosekit/config-tsdown": "0.0.0",
86
+ "@prosekit/config-vitest": "0.0.0"
87
87
  },
88
88
  "publishConfig": {
89
89
  "dev": {}