@prosekit/web 0.8.0-beta.0 → 0.8.0-beta.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.
- package/dist/prosekit-web-autocomplete.d.ts +112 -90
- package/dist/prosekit-web-autocomplete.d.ts.map +1 -1
- package/dist/prosekit-web-autocomplete.js +292 -217
- package/dist/prosekit-web-autocomplete.js.map +1 -1
- package/dist/prosekit-web-block-handle.d.ts +95 -62
- package/dist/prosekit-web-block-handle.d.ts.map +1 -1
- package/dist/prosekit-web-block-handle.js +219 -114
- package/dist/prosekit-web-block-handle.js.map +1 -1
- package/dist/prosekit-web-drop-indicator.d.ts +13 -15
- package/dist/prosekit-web-drop-indicator.d.ts.map +1 -1
- package/dist/prosekit-web-drop-indicator.js +34 -30
- package/dist/prosekit-web-drop-indicator.js.map +1 -1
- package/dist/prosekit-web-inline-popover.d.ts +88 -54
- package/dist/prosekit-web-inline-popover.d.ts.map +1 -1
- package/dist/prosekit-web-inline-popover.js +129 -79
- package/dist/prosekit-web-inline-popover.js.map +1 -1
- package/dist/prosekit-web-menu.d.ts +13 -0
- package/dist/prosekit-web-menu.d.ts.map +1 -0
- package/dist/prosekit-web-menu.js +53 -0
- package/dist/prosekit-web-menu.js.map +1 -0
- package/dist/prosekit-web-popover.d.ts +7 -26
- package/dist/prosekit-web-popover.d.ts.map +1 -1
- package/dist/prosekit-web-popover.js +31 -29
- package/dist/prosekit-web-popover.js.map +1 -1
- package/dist/prosekit-web-resizable.d.ts +92 -51
- package/dist/prosekit-web-resizable.d.ts.map +1 -1
- package/dist/prosekit-web-resizable.js +139 -131
- package/dist/prosekit-web-resizable.js.map +1 -1
- package/dist/prosekit-web-table-handle.d.ts +166 -199
- package/dist/prosekit-web-table-handle.d.ts.map +1 -1
- package/dist/prosekit-web-table-handle.js +495 -496
- package/dist/prosekit-web-table-handle.js.map +1 -1
- package/dist/prosekit-web-tooltip.d.ts +7 -26
- package/dist/prosekit-web-tooltip.d.ts.map +1 -1
- package/dist/prosekit-web-tooltip.js +31 -29
- package/dist/prosekit-web-tooltip.js.map +1 -1
- package/dist/use-editor-extension.js +2 -2
- package/dist/use-editor-extension.js.map +1 -1
- package/dist/use-scrolling.js +17 -8
- package/dist/use-scrolling.js.map +1 -1
- package/package.json +28 -23
- package/src/components/autocomplete/autocomplete-empty.ts +45 -0
- package/src/components/autocomplete/autocomplete-item.ts +65 -0
- package/src/components/autocomplete/autocomplete-popup.ts +95 -0
- package/src/components/autocomplete/autocomplete-positioner.ts +98 -0
- package/src/components/autocomplete/autocomplete-root.ts +280 -0
- package/src/components/autocomplete/context.ts +16 -14
- package/src/components/autocomplete/index.ts +65 -0
- package/src/components/block-handle/block-handle-add.ts +71 -0
- package/src/components/block-handle/block-handle-draggable.ts +158 -0
- package/src/components/block-handle/block-handle-popup.ts +43 -0
- package/src/components/block-handle/block-handle-positioner.ts +89 -0
- package/src/components/block-handle/block-handle-root.ts +116 -0
- package/src/components/block-handle/context.ts +9 -18
- package/src/components/block-handle/hover-state.ts +16 -0
- package/src/components/block-handle/index.ts +59 -0
- package/src/components/block-handle/{block-handle-popover/pointer-move.ts → pointer-move.ts} +8 -7
- package/src/components/block-handle/{block-handle-draggable/set-drag-preview.ts → set-drag-preview.ts} +4 -4
- package/src/components/block-handle/use-hover-extension.ts +65 -0
- package/src/components/drop-indicator/drop-indicator.ts +128 -0
- package/src/components/drop-indicator/index.ts +18 -0
- package/src/components/inline-popover/index.ts +41 -0
- package/src/components/inline-popover/inline-popover-popup.ts +52 -0
- package/src/components/inline-popover/inline-popover-positioner.ts +98 -0
- package/src/components/inline-popover/inline-popover-root.ts +122 -0
- package/src/components/inline-popover/store.ts +6 -0
- package/src/components/menu/index.ts +92 -0
- package/src/components/popover/index.ts +53 -0
- package/src/components/resizable/{resizable-handle/calc-resize.ts → calc-resize.ts} +1 -1
- package/src/components/resizable/context.ts +3 -6
- package/src/components/resizable/index.ts +32 -0
- package/src/components/resizable/resizable-handle.ts +134 -0
- package/src/components/resizable/resizable-root.ts +184 -0
- package/src/components/table-handle/dnd.ts +16 -27
- package/src/components/table-handle/index.ts +125 -0
- package/src/components/table-handle/{table-handle-drag-preview/render-preview.ts → render-preview.ts} +5 -5
- package/src/components/table-handle/shared.ts +61 -0
- package/src/components/table-handle/store.ts +117 -0
- package/src/components/table-handle/table-handle-column-menu-root.ts +51 -0
- package/src/components/table-handle/table-handle-column-menu-trigger.ts +107 -0
- package/src/components/table-handle/table-handle-column-popup.ts +44 -0
- package/src/components/table-handle/table-handle-column-positioner.ts +67 -0
- package/src/components/table-handle/table-handle-drag-preview.ts +169 -0
- package/src/components/table-handle/table-handle-drop-indicator.ts +166 -0
- package/src/components/table-handle/table-handle-root.ts +103 -0
- package/src/components/table-handle/table-handle-row-menu-root.ts +51 -0
- package/src/components/table-handle/table-handle-row-menu-trigger.ts +107 -0
- package/src/components/table-handle/table-handle-row-popup.ts +42 -0
- package/src/components/table-handle/table-handle-row-positioner.ts +67 -0
- package/src/components/table-handle/use-drop.ts +74 -0
- package/src/components/table-handle/{hooks/use-empty-image.ts → use-empty-image.ts} +2 -3
- package/src/components/table-handle/utils.ts +0 -11
- package/src/components/tooltip/index.ts +52 -0
- package/src/hooks/use-editor-extension.ts +4 -4
- package/src/hooks/use-editor-focus-event.ts +4 -4
- package/src/hooks/use-editor-typing.ts +12 -16
- package/src/hooks/use-editor-update-event.ts +4 -4
- package/src/hooks/use-keymap.ts +4 -4
- package/src/hooks/use-scrolling.ts +11 -10
- package/src/hooks/use-selecting.ts +8 -15
- package/src/utils/event.ts +28 -0
- package/src/utils/lazy-signal.spec.ts +68 -0
- package/src/utils/lazy-signal.ts +17 -0
- package/src/utils/prefers-reduced-motion.ts +6 -0
- package/src/utils/prevent-default.ts +3 -0
- package/src/utils/use-html-element-at.ts +17 -0
- package/src/utils/use-no-focus.ts +7 -0
- package/dist/get-default-state.js +0 -11
- package/dist/get-default-state.js.map +0 -1
- package/src/components/autocomplete/autocomplete-empty/element.gen.ts +0 -18
- package/src/components/autocomplete/autocomplete-empty/setup.ts +0 -6
- package/src/components/autocomplete/autocomplete-empty/types.ts +0 -13
- package/src/components/autocomplete/autocomplete-item/element.gen.ts +0 -18
- package/src/components/autocomplete/autocomplete-item/setup.ts +0 -30
- package/src/components/autocomplete/autocomplete-item/types.ts +0 -25
- package/src/components/autocomplete/autocomplete-list/element.gen.ts +0 -18
- package/src/components/autocomplete/autocomplete-list/setup.ts +0 -125
- package/src/components/autocomplete/autocomplete-list/types.ts +0 -22
- package/src/components/autocomplete/autocomplete-popover/element.gen.ts +0 -18
- package/src/components/autocomplete/autocomplete-popover/setup.ts +0 -169
- package/src/components/autocomplete/autocomplete-popover/types.ts +0 -100
- package/src/components/autocomplete/index.gen.ts +0 -17
- package/src/components/block-handle/block-handle-add/element.gen.ts +0 -18
- package/src/components/block-handle/block-handle-add/setup.ts +0 -33
- package/src/components/block-handle/block-handle-add/types.ts +0 -23
- package/src/components/block-handle/block-handle-draggable/element.gen.ts +0 -18
- package/src/components/block-handle/block-handle-draggable/setup.ts +0 -113
- package/src/components/block-handle/block-handle-draggable/types.ts +0 -23
- package/src/components/block-handle/block-handle-popover/element.gen.ts +0 -18
- package/src/components/block-handle/block-handle-popover/setup.ts +0 -68
- package/src/components/block-handle/block-handle-popover/types.ts +0 -81
- package/src/components/block-handle/index.gen.ts +0 -13
- package/src/components/drop-indicator/drop-indicator/element.gen.ts +0 -18
- package/src/components/drop-indicator/drop-indicator/setup.ts +0 -75
- package/src/components/drop-indicator/drop-indicator/types.ts +0 -31
- package/src/components/drop-indicator/index.gen.ts +0 -5
- package/src/components/inline-popover/index.gen.ts +0 -5
- package/src/components/inline-popover/inline-popover/element.gen.ts +0 -18
- package/src/components/inline-popover/inline-popover/setup.ts +0 -111
- package/src/components/inline-popover/inline-popover/types.ts +0 -112
- package/src/components/popover/index.gen.ts +0 -13
- package/src/components/popover/popover-content/element.gen.ts +0 -18
- package/src/components/popover/popover-content/setup.ts +0 -1
- package/src/components/popover/popover-content/types.ts +0 -6
- package/src/components/popover/popover-root/element.gen.ts +0 -18
- package/src/components/popover/popover-root/setup.ts +0 -1
- package/src/components/popover/popover-root/types.ts +0 -6
- package/src/components/popover/popover-trigger/element.gen.ts +0 -18
- package/src/components/popover/popover-trigger/setup.ts +0 -1
- package/src/components/popover/popover-trigger/types.ts +0 -6
- package/src/components/resizable/index.gen.ts +0 -9
- package/src/components/resizable/resizable-handle/element.gen.ts +0 -18
- package/src/components/resizable/resizable-handle/setup.ts +0 -106
- package/src/components/resizable/resizable-handle/types.ts +0 -29
- package/src/components/resizable/resizable-root/element.gen.ts +0 -18
- package/src/components/resizable/resizable-root/setup.ts +0 -84
- package/src/components/resizable/resizable-root/types.ts +0 -59
- package/src/components/table-handle/context.ts +0 -43
- package/src/components/table-handle/hooks/use-drop.ts +0 -85
- package/src/components/table-handle/index.gen.ts +0 -37
- package/src/components/table-handle/table-handle-column-root/element.gen.ts +0 -18
- package/src/components/table-handle/table-handle-column-root/setup.ts +0 -60
- package/src/components/table-handle/table-handle-column-root/types.ts +0 -73
- package/src/components/table-handle/table-handle-column-trigger/element.gen.ts +0 -18
- package/src/components/table-handle/table-handle-column-trigger/setup.ts +0 -64
- package/src/components/table-handle/table-handle-column-trigger/types.ts +0 -20
- package/src/components/table-handle/table-handle-drag-preview/element.gen.ts +0 -18
- package/src/components/table-handle/table-handle-drag-preview/setup.ts +0 -57
- package/src/components/table-handle/table-handle-drag-preview/types.ts +0 -14
- package/src/components/table-handle/table-handle-drag-preview/updater.ts +0 -90
- package/src/components/table-handle/table-handle-drop-indicator/element.gen.ts +0 -18
- package/src/components/table-handle/table-handle-drop-indicator/setup.ts +0 -52
- package/src/components/table-handle/table-handle-drop-indicator/types.ts +0 -15
- package/src/components/table-handle/table-handle-drop-indicator/updater.ts +0 -96
- package/src/components/table-handle/table-handle-popover-content/element.gen.ts +0 -18
- package/src/components/table-handle/table-handle-popover-content/setup.ts +0 -83
- package/src/components/table-handle/table-handle-popover-content/types.ts +0 -32
- package/src/components/table-handle/table-handle-popover-item/element.gen.ts +0 -18
- package/src/components/table-handle/table-handle-popover-item/setup.ts +0 -17
- package/src/components/table-handle/table-handle-popover-item/types.ts +0 -16
- package/src/components/table-handle/table-handle-root/element.gen.ts +0 -18
- package/src/components/table-handle/table-handle-root/setup.ts +0 -86
- package/src/components/table-handle/table-handle-root/types.ts +0 -23
- package/src/components/table-handle/table-handle-row-root/element.gen.ts +0 -18
- package/src/components/table-handle/table-handle-row-root/setup.ts +0 -70
- package/src/components/table-handle/table-handle-row-root/types.ts +0 -68
- package/src/components/table-handle/table-handle-row-trigger/element.gen.ts +0 -18
- package/src/components/table-handle/table-handle-row-trigger/setup.ts +0 -63
- package/src/components/table-handle/table-handle-row-trigger/types.ts +0 -23
- package/src/components/tooltip/index.gen.ts +0 -13
- package/src/components/tooltip/tooltip-content/element.gen.ts +0 -18
- package/src/components/tooltip/tooltip-content/setup.ts +0 -1
- package/src/components/tooltip/tooltip-content/types.ts +0 -6
- package/src/components/tooltip/tooltip-root/element.gen.ts +0 -18
- package/src/components/tooltip/tooltip-root/setup.ts +0 -1
- package/src/components/tooltip/tooltip-root/types.ts +0 -6
- package/src/components/tooltip/tooltip-trigger/element.gen.ts +0 -18
- package/src/components/tooltip/tooltip-trigger/setup.ts +0 -1
- package/src/components/tooltip/tooltip-trigger/types.ts +0 -6
- package/src/hooks/use-first-rendering.ts +0 -15
- package/src/utils/get-default-state.spec.ts +0 -42
- package/src/utils/get-default-state.ts +0 -18
- /package/src/components/autocomplete/{autocomplete-popover/helpers.spec.ts → helpers.spec.ts} +0 -0
- /package/src/components/autocomplete/{autocomplete-popover/helpers.ts → helpers.ts} +0 -0
- /package/src/components/inline-popover/{inline-popover/virtual-selection-element.ts → virtual-selection-element.ts} +0 -0
- /package/src/components/resizable/{resizable-handle/calc-resize.spec.ts → calc-resize.spec.ts} +0 -0
- /package/src/components/table-handle/{table-handle-drop-indicator/calc-drag-over.ts → calc-drag-over.ts} +0 -0
|
@@ -1,96 +1,204 @@
|
|
|
1
|
-
import { t as getStateWithDefaults } from "./get-default-state.js";
|
|
2
1
|
import { t as useEditorExtension } from "./use-editor-extension.js";
|
|
3
2
|
import { t as getSafeEditorView } from "./get-safe-editor-view.js";
|
|
4
3
|
import { n as assignStyles, t as useScrolling } from "./use-scrolling.js";
|
|
5
|
-
import {
|
|
4
|
+
import { computed, createContext, createSignal, defineCustomElement, defineProps, onMount, registerCustomElement, useEffect, useEventListener } from "@aria-ui/core";
|
|
5
|
+
import { OverlayPositionerPropsDeclaration, createOverlayStore, setupOverlayPopup, setupOverlayPositioner } from "@aria-ui/elements/overlay";
|
|
6
6
|
import { defineDOMEventHandler, union } from "@prosekit/core";
|
|
7
|
-
import { useOverlayPositionerState } from "@aria-ui/overlay/elements";
|
|
8
|
-
import { usePresence } from "@aria-ui/presence";
|
|
9
7
|
import { getDocument, getId, isHTMLElement, once } from "@ocavue/utils";
|
|
10
|
-
import {
|
|
11
|
-
import { menuContentEvents, menuContentProps, menuRootEvents, menuRootProps, useMenuContent, useMenuItem, useMenuRoot, useMenuTrigger } from "@aria-ui/menu/elements";
|
|
8
|
+
import { MenuRootPropsDeclaration, setupMenuRoot, setupMenuTrigger } from "@aria-ui/elements/menu";
|
|
12
9
|
import { moveTableColumn, moveTableRow, selectTableColumn, selectTableRow } from "@prosekit/extensions/table";
|
|
13
10
|
import { computePosition, offset } from "@floating-ui/dom";
|
|
14
|
-
import { menuItemEvents, menuItemProps } from "@aria-ui/menu";
|
|
15
11
|
import { TableMap, cellAround } from "prosemirror-tables";
|
|
16
|
-
//#region src/components/table-handle/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
//#region src/components/table-handle/store.ts
|
|
13
|
+
function noop() {}
|
|
14
|
+
function returnTrue() {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
function returnFalse() {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
var DndStore = class {
|
|
21
|
+
constructor() {
|
|
22
|
+
this.dragging = createSignal(false);
|
|
23
|
+
this.direction = createSignal("row");
|
|
24
|
+
this.draggingIndex = createSignal(-1);
|
|
25
|
+
this.droppingIndex = createSignal(-1);
|
|
26
|
+
this.x = createSignal(-1);
|
|
27
|
+
this.y = createSignal(-1);
|
|
28
|
+
this.startX = createSignal(-1);
|
|
29
|
+
this.startY = createSignal(-1);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
21
32
|
/**
|
|
22
33
|
* @internal
|
|
23
34
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
function createTableHandleStore(getHoveringCellInfo, getCanShow) {
|
|
36
|
+
const isColumnMenuOpen = createSignal(false);
|
|
37
|
+
const isRowMenuOpen = createSignal(false);
|
|
38
|
+
const getHasMenuOpen = () => {
|
|
39
|
+
return isColumnMenuOpen.get() || isRowMenuOpen.get();
|
|
40
|
+
};
|
|
41
|
+
const setIsRowMenuOpen = (open) => {
|
|
42
|
+
isRowMenuOpen.set(open);
|
|
43
|
+
};
|
|
44
|
+
const setIsColumnMenuOpen = (open) => {
|
|
45
|
+
isColumnMenuOpen.set(open);
|
|
46
|
+
};
|
|
47
|
+
const referenceCellInfo = createSignal(void 0);
|
|
48
|
+
let prevHoveringCellInfo = void 0;
|
|
49
|
+
const getReferenceCell = computed(() => {
|
|
50
|
+
if (!getCanShow()) {
|
|
51
|
+
referenceCellInfo.set(void 0);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (getHasMenuOpen()) return prevHoveringCellInfo;
|
|
55
|
+
prevHoveringCellInfo = getHoveringCellInfo();
|
|
56
|
+
return prevHoveringCellInfo;
|
|
57
|
+
});
|
|
58
|
+
const getOpen = computed(() => {
|
|
59
|
+
return !!getReferenceCell();
|
|
60
|
+
});
|
|
61
|
+
const handleOpenChange = (event) => {
|
|
62
|
+
if (getHasMenuOpen()) event.preventDefault();
|
|
63
|
+
};
|
|
64
|
+
const columnOverlayStore = createOverlayStore(getOpen, noop, returnTrue, returnFalse, handleOpenChange);
|
|
65
|
+
const rowOverlayStore = createOverlayStore(getOpen, noop, returnTrue, returnFalse, handleOpenChange);
|
|
66
|
+
return {
|
|
67
|
+
dndStore: new DndStore(),
|
|
68
|
+
setIsRowMenuOpen,
|
|
69
|
+
setIsColumnMenuOpen,
|
|
70
|
+
columnOverlayStore,
|
|
71
|
+
rowOverlayStore,
|
|
72
|
+
getReferenceCell
|
|
73
|
+
};
|
|
74
|
+
}
|
|
34
75
|
/**
|
|
35
76
|
* @internal
|
|
36
77
|
*/
|
|
37
|
-
const
|
|
78
|
+
const tableHandleStoreContext = createContext("prosekit-table-handle-store");
|
|
38
79
|
//#endregion
|
|
39
|
-
//#region src/components/table-handle/table-handle-column-
|
|
80
|
+
//#region src/components/table-handle/table-handle-column-popup.ts
|
|
81
|
+
/** @internal */
|
|
82
|
+
const TableHandleColumnPopupPropsDeclaration = defineProps({});
|
|
83
|
+
/** @internal */
|
|
84
|
+
function setupTableHandleColumnPopup(host, _props) {
|
|
85
|
+
const getStore = tableHandleStoreContext.consume(host);
|
|
86
|
+
const getOverlayStore = () => getStore()?.columnOverlayStore;
|
|
87
|
+
setupOverlayPopup(host, getOverlayStore);
|
|
88
|
+
}
|
|
89
|
+
const TableHandleColumnPopupElementBase = defineCustomElement(setupTableHandleColumnPopup, TableHandleColumnPopupPropsDeclaration);
|
|
40
90
|
/**
|
|
41
|
-
* @
|
|
91
|
+
* @public
|
|
42
92
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
colFirstCellPos.get();
|
|
58
|
-
contentOpen.set(false);
|
|
59
|
-
});
|
|
60
|
-
useOverlayPositionerState(host, overlayState, { reference: referenceCell });
|
|
61
|
-
const presence = createComputed(() => !!referenceCell.get());
|
|
62
|
-
useAttribute(host, "data-state", () => presence.get() ? "open" : "closed");
|
|
63
|
-
usePresence(host, presence);
|
|
64
|
-
useMenuRoot(host, {
|
|
65
|
-
state: getStateWithDefaults({ open: contentOpen }, menuRootProps),
|
|
66
|
-
emit: () => void 0
|
|
93
|
+
var TableHandleColumnPopupElement = class extends TableHandleColumnPopupElementBase {};
|
|
94
|
+
/** @internal */
|
|
95
|
+
function registerTableHandleColumnPopupElement() {
|
|
96
|
+
registerCustomElement("prosekit-table-handle-column-popup", TableHandleColumnPopupElement);
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/utils/use-html-element-at.ts
|
|
100
|
+
function useHTMLElementAt(getEditor, getPos) {
|
|
101
|
+
return computed(() => {
|
|
102
|
+
const editor = getEditor();
|
|
103
|
+
const pos = getPos();
|
|
104
|
+
if (!editor || !pos) return;
|
|
105
|
+
const element = editor.view.nodeDOM(pos);
|
|
106
|
+
if (element && isHTMLElement(element)) return element;
|
|
67
107
|
});
|
|
68
108
|
}
|
|
69
109
|
//#endregion
|
|
70
|
-
//#region src/components/table-handle/
|
|
110
|
+
//#region src/components/table-handle/shared.ts
|
|
71
111
|
/** @internal */
|
|
72
|
-
const
|
|
73
|
-
...
|
|
74
|
-
editor: {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
112
|
+
const SharedTableHandlePositionerPropsDeclaration = defineProps({
|
|
113
|
+
...OverlayPositionerPropsDeclaration,
|
|
114
|
+
editor: {
|
|
115
|
+
default: null,
|
|
116
|
+
attribute: false,
|
|
117
|
+
type: "json"
|
|
118
|
+
},
|
|
119
|
+
hoist: {
|
|
120
|
+
default: false,
|
|
121
|
+
attribute: false,
|
|
122
|
+
type: "boolean"
|
|
123
|
+
},
|
|
124
|
+
flip: {
|
|
125
|
+
default: false,
|
|
126
|
+
attribute: false,
|
|
127
|
+
type: "json"
|
|
128
|
+
},
|
|
129
|
+
shift: {
|
|
130
|
+
default: false,
|
|
131
|
+
attribute: false,
|
|
132
|
+
type: "boolean"
|
|
133
|
+
},
|
|
134
|
+
hide: {
|
|
135
|
+
default: true,
|
|
136
|
+
attribute: false,
|
|
137
|
+
type: "boolean"
|
|
138
|
+
},
|
|
139
|
+
offset: {
|
|
140
|
+
default: 0,
|
|
141
|
+
attribute: false,
|
|
142
|
+
type: "json"
|
|
143
|
+
}
|
|
80
144
|
});
|
|
81
|
-
/** @internal */
|
|
82
|
-
const tableHandleColumnRootEvents = overlayPositionerEvents$1;
|
|
83
145
|
//#endregion
|
|
84
|
-
//#region src/components/table-handle/table-handle-column-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
146
|
+
//#region src/components/table-handle/table-handle-column-positioner.ts
|
|
147
|
+
/** @internal */
|
|
148
|
+
const TableHandleColumnPositionerPropsDeclaration = defineProps({
|
|
149
|
+
...SharedTableHandlePositionerPropsDeclaration,
|
|
150
|
+
placement: {
|
|
151
|
+
default: "top",
|
|
152
|
+
attribute: "placement",
|
|
153
|
+
type: "string"
|
|
154
|
+
}
|
|
89
155
|
});
|
|
90
|
-
|
|
91
|
-
|
|
156
|
+
/** @internal */
|
|
157
|
+
function setupTableHandleColumnPositioner(host, props) {
|
|
158
|
+
const getStore = tableHandleStoreContext.consume(host);
|
|
159
|
+
const getOverlayStore = () => getStore()?.columnOverlayStore;
|
|
160
|
+
setupOverlayPositioner(host, props, getOverlayStore);
|
|
161
|
+
const getEditor = props.editor.get;
|
|
162
|
+
const getReferenceCell = useHTMLElementAt(getEditor, computed(() => getStore()?.getReferenceCell()?.colFirstCellPos));
|
|
163
|
+
useEffect(host, () => {
|
|
164
|
+
getOverlayStore()?.setAnchorElement(getReferenceCell());
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
const TableHandleColumnPositionerElementBase = defineCustomElement(setupTableHandleColumnPositioner, TableHandleColumnPositionerPropsDeclaration);
|
|
168
|
+
/**
|
|
169
|
+
* @public
|
|
170
|
+
*/
|
|
171
|
+
var TableHandleColumnPositionerElement = class extends TableHandleColumnPositionerElementBase {};
|
|
172
|
+
/** @internal */
|
|
173
|
+
function registerTableHandleColumnPositionerElement() {
|
|
174
|
+
registerCustomElement("prosekit-table-handle-column-positioner", TableHandleColumnPositionerElement);
|
|
175
|
+
}
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/components/table-handle/table-handle-column-menu-root.ts
|
|
178
|
+
/** @internal */
|
|
179
|
+
const TableHandleColumnMenuRootPropsDeclaration = defineProps(MenuRootPropsDeclaration);
|
|
180
|
+
/** @internal */
|
|
181
|
+
function setupTableHandleColumnMenuRoot(host, props) {
|
|
182
|
+
setupMenuRoot(host, props);
|
|
183
|
+
const getStore = tableHandleStoreContext.consume(host);
|
|
184
|
+
useEffect(host, () => {
|
|
185
|
+
const open = props.open.get() || false;
|
|
186
|
+
const store = getStore?.();
|
|
187
|
+
if (!store) return;
|
|
188
|
+
store.setIsColumnMenuOpen(open);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
const TableHandleColumnMenuRootElementBase = defineCustomElement(setupTableHandleColumnMenuRoot, TableHandleColumnMenuRootPropsDeclaration);
|
|
192
|
+
/**
|
|
193
|
+
* @public
|
|
194
|
+
*/
|
|
195
|
+
var TableHandleColumnMenuRootElement = class extends TableHandleColumnMenuRootElementBase {};
|
|
196
|
+
/** @internal */
|
|
197
|
+
function registerTableHandleColumnMenuRootElement() {
|
|
198
|
+
registerCustomElement("prosekit-table-handle-column-menu-root", TableHandleColumnMenuRootElement);
|
|
199
|
+
}
|
|
92
200
|
//#endregion
|
|
93
|
-
//#region src/components/table-handle/
|
|
201
|
+
//#region src/components/table-handle/use-empty-image.ts
|
|
94
202
|
/**
|
|
95
203
|
* Returns a function that returns a 1x1 transparent image. This is used to
|
|
96
204
|
* prevent the browser from showing the default drag image. An earth icon in
|
|
@@ -114,21 +222,25 @@ function useEmptyImage(host) {
|
|
|
114
222
|
return () => image;
|
|
115
223
|
}
|
|
116
224
|
//#endregion
|
|
117
|
-
//#region src/components/table-handle/table-handle-column-trigger
|
|
118
|
-
/**
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
225
|
+
//#region src/components/table-handle/table-handle-column-menu-trigger.ts
|
|
226
|
+
/** @internal */
|
|
227
|
+
const TableHandleColumnMenuTriggerPropsDeclaration = defineProps({ editor: {
|
|
228
|
+
default: null,
|
|
229
|
+
attribute: false,
|
|
230
|
+
type: "json"
|
|
231
|
+
} });
|
|
232
|
+
/** @internal */
|
|
233
|
+
function setupTableHandleColumnMenuTrigger(host, props) {
|
|
234
|
+
const getEditor = props.editor.get;
|
|
235
|
+
const getStore = tableHandleStoreContext.consume(host);
|
|
236
|
+
setupMenuTrigger(host, { disabled: createSignal(false) });
|
|
125
237
|
useEventListener(host, "pointerdown", () => {
|
|
126
|
-
const editor =
|
|
127
|
-
const cellPos =
|
|
238
|
+
const editor = getEditor();
|
|
239
|
+
const cellPos = getStore()?.getReferenceCell()?.cellPos;
|
|
128
240
|
if (!editor || !cellPos) return;
|
|
129
241
|
editor.exec(selectTableColumn({ head: cellPos }));
|
|
130
242
|
});
|
|
131
|
-
|
|
243
|
+
onMount(host, () => {
|
|
132
244
|
host.draggable = true;
|
|
133
245
|
});
|
|
134
246
|
const getEmptyImage = useEmptyImage(host);
|
|
@@ -140,61 +252,49 @@ function useTableHandleColumnTrigger(host, { state }) {
|
|
|
140
252
|
if (emptyImage) dataTransfer.setDragImage(emptyImage, 0, 0);
|
|
141
253
|
dataTransfer.setData("application/x-prosekit-table-handle-drag", "");
|
|
142
254
|
}
|
|
143
|
-
const
|
|
144
|
-
|
|
255
|
+
const store = getStore();
|
|
256
|
+
if (!store) return;
|
|
257
|
+
const index = store.getReferenceCell()?.colIndex;
|
|
145
258
|
if (index == null || index < 0) {
|
|
146
259
|
console.warn("[prosekit] Invalid column index for drag operation:", index);
|
|
147
260
|
event.preventDefault();
|
|
148
261
|
return;
|
|
149
262
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
startY: event.clientY
|
|
157
|
-
});
|
|
263
|
+
const dndStore = store.dndStore;
|
|
264
|
+
dndStore.direction.set("col");
|
|
265
|
+
dndStore.dragging.set(true);
|
|
266
|
+
dndStore.draggingIndex.set(index);
|
|
267
|
+
dndStore.startX.set(event.clientX);
|
|
268
|
+
dndStore.startY.set(event.clientY);
|
|
158
269
|
});
|
|
159
270
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
setup: useTableHandleColumnTrigger
|
|
172
|
-
});
|
|
173
|
-
var TableHandleColumnTriggerElement = class extends TableHandleColumnTriggerElementBase {};
|
|
174
|
-
registerCustomElement("prosekit-table-handle-column-trigger", TableHandleColumnTriggerElement);
|
|
271
|
+
const TableHandleColumnMenuTriggerElementBase = defineCustomElement(setupTableHandleColumnMenuTrigger, TableHandleColumnMenuTriggerPropsDeclaration);
|
|
272
|
+
/**
|
|
273
|
+
* @public
|
|
274
|
+
*/
|
|
275
|
+
var TableHandleColumnMenuTriggerElement = class extends TableHandleColumnMenuTriggerElementBase {};
|
|
276
|
+
/**
|
|
277
|
+
* @internal
|
|
278
|
+
*/
|
|
279
|
+
function registerTableHandleColumnMenuTriggerElement() {
|
|
280
|
+
registerCustomElement("prosekit-table-handle-column-menu-trigger", TableHandleColumnMenuTriggerElement);
|
|
281
|
+
}
|
|
175
282
|
//#endregion
|
|
176
283
|
//#region src/components/table-handle/dnd.ts
|
|
177
|
-
function useInitDndPosition(host,
|
|
178
|
-
const
|
|
179
|
-
const rootContext = tableHandleRootContext.consume(host);
|
|
180
|
-
const draggingSignal = createComputed(() => {
|
|
181
|
-
return dndContext.get().dragging;
|
|
182
|
-
});
|
|
183
|
-
const directionSignal = createComputed(() => {
|
|
184
|
-
return dndContext.get().direction;
|
|
185
|
-
});
|
|
186
|
-
const draggingIndexSignal = createComputed(() => {
|
|
187
|
-
return dndContext.get().draggingIndex;
|
|
188
|
-
});
|
|
284
|
+
function useInitDndPosition(host, getEditor, onInit) {
|
|
285
|
+
const getStore = tableHandleStoreContext.consume(host);
|
|
189
286
|
useEffect(host, () => {
|
|
190
|
-
const view = getSafeEditorView(
|
|
287
|
+
const view = getSafeEditorView(getEditor());
|
|
191
288
|
if (!view) return;
|
|
192
|
-
const
|
|
193
|
-
|
|
289
|
+
const store = getStore();
|
|
290
|
+
if (!store) return;
|
|
291
|
+
const dndStore = store.dndStore;
|
|
292
|
+
const dragging = dndStore.dragging.get();
|
|
293
|
+
const direction = dndStore.direction.get();
|
|
194
294
|
host.dataset.direction = direction;
|
|
195
295
|
host.dataset.dragging = dragging.toString();
|
|
196
|
-
const draggingIndex =
|
|
197
|
-
const relatedDOMs = getDndRelatedDOMs(view,
|
|
296
|
+
const draggingIndex = dndStore.draggingIndex.get();
|
|
297
|
+
const relatedDOMs = getDndRelatedDOMs(view, store.getReferenceCell()?.cellPos, draggingIndex, direction);
|
|
198
298
|
if (!relatedDOMs) return;
|
|
199
299
|
const { table, cell } = relatedDOMs;
|
|
200
300
|
onInit({
|
|
@@ -349,7 +449,7 @@ function injectStyle(container, styleText) {
|
|
|
349
449
|
container.appendChild(style);
|
|
350
450
|
}
|
|
351
451
|
//#endregion
|
|
352
|
-
//#region src/components/table-handle/
|
|
452
|
+
//#region src/components/table-handle/render-preview.ts
|
|
353
453
|
function clearPreviewDOM(previewRoot) {
|
|
354
454
|
while (previewRoot.firstChild) previewRoot.removeChild(previewRoot.firstChild);
|
|
355
455
|
}
|
|
@@ -399,27 +499,59 @@ function unsetSize(element) {
|
|
|
399
499
|
});
|
|
400
500
|
}
|
|
401
501
|
//#endregion
|
|
402
|
-
//#region src/components/table-handle/table-handle-drag-preview
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
502
|
+
//#region src/components/table-handle/table-handle-drag-preview.ts
|
|
503
|
+
/** @internal */
|
|
504
|
+
const TableHandleDragPreviewPropsDeclaration = defineProps({ editor: {
|
|
505
|
+
default: null,
|
|
506
|
+
attribute: false,
|
|
507
|
+
type: "json"
|
|
508
|
+
} });
|
|
509
|
+
/**
|
|
510
|
+
* @internal
|
|
511
|
+
*/
|
|
512
|
+
function setupTableHandleDragPreview(host, props) {
|
|
513
|
+
const getEditor = props.editor.get;
|
|
514
|
+
useEffect(host, () => {
|
|
515
|
+
assignStyles(host, {
|
|
516
|
+
position: "absolute",
|
|
517
|
+
pointerEvents: "none"
|
|
518
|
+
});
|
|
408
519
|
});
|
|
409
|
-
|
|
410
|
-
|
|
520
|
+
useInitDndPosition(host, getEditor, onInitPreviewPosition);
|
|
521
|
+
useUpdatePreviewPosition(host, getEditor);
|
|
522
|
+
}
|
|
523
|
+
function onInitPreviewPosition({ host, direction, dragging, table, cell, draggingIndex }) {
|
|
524
|
+
assignStyles(host, { display: dragging ? "block" : "none" });
|
|
525
|
+
if (!dragging) {
|
|
526
|
+
clearPreviewDOM(host);
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
createPreviewDOM(table, host, draggingIndex, direction);
|
|
530
|
+
const tableRect = table.getBoundingClientRect();
|
|
531
|
+
const cellRect = cell.getBoundingClientRect();
|
|
532
|
+
if (direction === "col") assignStyles(host, {
|
|
533
|
+
width: `${cellRect.width}px`,
|
|
534
|
+
height: `${tableRect.height}px`
|
|
411
535
|
});
|
|
412
|
-
|
|
413
|
-
|
|
536
|
+
if (direction === "row") assignStyles(host, {
|
|
537
|
+
width: `${tableRect.width}px`,
|
|
538
|
+
height: `${cellRect.height}px`
|
|
414
539
|
});
|
|
540
|
+
}
|
|
541
|
+
function useUpdatePreviewPosition(host, getEditor) {
|
|
542
|
+
const getStore = tableHandleStoreContext.consume(host);
|
|
415
543
|
useEffect(host, () => {
|
|
416
|
-
const view = getSafeEditorView(
|
|
544
|
+
const view = getSafeEditorView(getEditor());
|
|
417
545
|
if (!view) return;
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
const
|
|
421
|
-
|
|
422
|
-
const
|
|
546
|
+
const store = getStore();
|
|
547
|
+
if (!store) return;
|
|
548
|
+
const dndStore = store.dndStore;
|
|
549
|
+
if (!dndStore.dragging.get()) return;
|
|
550
|
+
const draggingIndex = dndStore.draggingIndex.get();
|
|
551
|
+
const direction = dndStore.direction.get();
|
|
552
|
+
const x = dndStore.x.get();
|
|
553
|
+
const y = dndStore.y.get();
|
|
554
|
+
const relatedDOMs = getDndRelatedDOMs(view, store.getReferenceCell()?.cellPos, draggingIndex, direction);
|
|
423
555
|
if (!relatedDOMs) return;
|
|
424
556
|
const { cell } = relatedDOMs;
|
|
425
557
|
let cancelled = false;
|
|
@@ -457,55 +589,19 @@ function getVirtualElement(cell, x, y) {
|
|
|
457
589
|
}
|
|
458
590
|
};
|
|
459
591
|
}
|
|
460
|
-
|
|
461
|
-
|
|
592
|
+
const TableHandleDragPreviewElementBase = defineCustomElement(setupTableHandleDragPreview, TableHandleDragPreviewPropsDeclaration);
|
|
593
|
+
/**
|
|
594
|
+
* @public
|
|
595
|
+
*/
|
|
596
|
+
var TableHandleDragPreviewElement = class extends TableHandleDragPreviewElementBase {};
|
|
462
597
|
/**
|
|
463
598
|
* @internal
|
|
464
599
|
*/
|
|
465
|
-
function
|
|
466
|
-
|
|
467
|
-
useEffect(host, () => {
|
|
468
|
-
assignStyles(host, {
|
|
469
|
-
position: "absolute",
|
|
470
|
-
pointerEvents: "none"
|
|
471
|
-
});
|
|
472
|
-
});
|
|
473
|
-
useInitDndPosition(host, editor, onInitPreviewPosition);
|
|
474
|
-
useUpdatePreviewPosition(host, editor);
|
|
475
|
-
}
|
|
476
|
-
function onInitPreviewPosition({ host, direction, dragging, table, cell, draggingIndex }) {
|
|
477
|
-
assignStyles(host, { display: dragging ? "block" : "none" });
|
|
478
|
-
if (!dragging) {
|
|
479
|
-
clearPreviewDOM(host);
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
createPreviewDOM(table, host, draggingIndex, direction);
|
|
483
|
-
const tableRect = table.getBoundingClientRect();
|
|
484
|
-
const cellRect = cell.getBoundingClientRect();
|
|
485
|
-
if (direction === "col") assignStyles(host, {
|
|
486
|
-
width: `${cellRect.width}px`,
|
|
487
|
-
height: `${tableRect.height}px`
|
|
488
|
-
});
|
|
489
|
-
if (direction === "row") assignStyles(host, {
|
|
490
|
-
width: `${tableRect.width}px`,
|
|
491
|
-
height: `${cellRect.height}px`
|
|
492
|
-
});
|
|
600
|
+
function registerTableHandleDragPreviewElement() {
|
|
601
|
+
registerCustomElement("prosekit-table-handle-drag-preview", TableHandleDragPreviewElement);
|
|
493
602
|
}
|
|
494
603
|
//#endregion
|
|
495
|
-
//#region src/components/table-handle/
|
|
496
|
-
const tableHandleDragPreviewProps = { editor: { default: null } };
|
|
497
|
-
const tableHandleDragPreviewEvents = {};
|
|
498
|
-
//#endregion
|
|
499
|
-
//#region src/components/table-handle/table-handle-drag-preview/element.gen.ts
|
|
500
|
-
const TableHandleDragPreviewElementBase = defineCustomElement({
|
|
501
|
-
props: tableHandleDragPreviewProps,
|
|
502
|
-
events: tableHandleDragPreviewEvents,
|
|
503
|
-
setup: useTableHandleDragPreview
|
|
504
|
-
});
|
|
505
|
-
var TableHandleDragPreviewElement = class extends TableHandleDragPreviewElementBase {};
|
|
506
|
-
registerCustomElement("prosekit-table-handle-drag-preview", TableHandleDragPreviewElement);
|
|
507
|
-
//#endregion
|
|
508
|
-
//#region src/components/table-handle/table-handle-drop-indicator/calc-drag-over.ts
|
|
604
|
+
//#region src/components/table-handle/calc-drag-over.ts
|
|
509
605
|
function findDragOverElement(elements, pointer, axis) {
|
|
510
606
|
const startProp = axis === "x" ? "left" : "top";
|
|
511
607
|
const endProp = axis === "x" ? "right" : "bottom";
|
|
@@ -530,33 +626,54 @@ function getDragOverRow(table, pointerY) {
|
|
|
530
626
|
return findDragOverElement(Array.from(table.querySelectorAll("tr")), pointerY, "y");
|
|
531
627
|
}
|
|
532
628
|
//#endregion
|
|
533
|
-
//#region src/components/table-handle/table-handle-drop-indicator
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
629
|
+
//#region src/components/table-handle/table-handle-drop-indicator.ts
|
|
630
|
+
const HANDLE_WIDTH = 2;
|
|
631
|
+
/** @internal */
|
|
632
|
+
const TableHandleDropIndicatorPropsDeclaration = defineProps({ editor: {
|
|
633
|
+
default: null,
|
|
634
|
+
attribute: false,
|
|
635
|
+
type: "json"
|
|
636
|
+
} });
|
|
637
|
+
/**
|
|
638
|
+
* @internal
|
|
639
|
+
*/
|
|
640
|
+
function setupTableHandleDropIndicator(host, props) {
|
|
641
|
+
const getEditor = props.editor.get;
|
|
642
|
+
useEffect(host, () => {
|
|
643
|
+
assignStyles(host, {
|
|
644
|
+
pointerEvents: "none",
|
|
645
|
+
position: "absolute"
|
|
646
|
+
});
|
|
545
647
|
});
|
|
546
|
-
|
|
547
|
-
|
|
648
|
+
useInitDndPosition(host, getEditor, onInitIndicatorPosition);
|
|
649
|
+
useUpdateIndicatorPosition(host, getEditor, HANDLE_WIDTH);
|
|
650
|
+
}
|
|
651
|
+
function onInitIndicatorPosition({ host, direction, dragging, table }) {
|
|
652
|
+
assignStyles(host, { display: dragging ? "block" : "none" });
|
|
653
|
+
const tableRect = table.getBoundingClientRect();
|
|
654
|
+
if (direction === "col") assignStyles(host, {
|
|
655
|
+
width: `${HANDLE_WIDTH}px`,
|
|
656
|
+
height: `${tableRect.height}px`
|
|
548
657
|
});
|
|
549
|
-
|
|
550
|
-
|
|
658
|
+
if (direction === "row") assignStyles(host, {
|
|
659
|
+
width: `${tableRect.width}px`,
|
|
660
|
+
height: `${HANDLE_WIDTH}px`
|
|
551
661
|
});
|
|
662
|
+
}
|
|
663
|
+
function useUpdateIndicatorPosition(host, getEditor, handleWidth) {
|
|
664
|
+
const getStore = tableHandleStoreContext.consume(host);
|
|
552
665
|
useEffect(host, () => {
|
|
553
|
-
const view = getSafeEditorView(
|
|
666
|
+
const view = getSafeEditorView(getEditor());
|
|
554
667
|
if (!view) return;
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
const
|
|
558
|
-
|
|
559
|
-
const
|
|
668
|
+
const store = getStore();
|
|
669
|
+
if (!store) return;
|
|
670
|
+
const dndStore = store.dndStore;
|
|
671
|
+
if (!dndStore.dragging.get()) return;
|
|
672
|
+
const draggingIndex = dndStore.draggingIndex.get();
|
|
673
|
+
const direction = dndStore.direction.get();
|
|
674
|
+
const x = dndStore.x.get();
|
|
675
|
+
const y = dndStore.y.get();
|
|
676
|
+
const relatedDOMs = getDndRelatedDOMs(view, store.getReferenceCell()?.cellPos, draggingIndex, direction);
|
|
560
677
|
if (!relatedDOMs) return;
|
|
561
678
|
const { table } = relatedDOMs;
|
|
562
679
|
let cancelled = false;
|
|
@@ -564,17 +681,14 @@ function useUpdateIndicatorPosition(host, editor, handleWidth) {
|
|
|
564
681
|
cancelled = true;
|
|
565
682
|
};
|
|
566
683
|
if (direction === "col") {
|
|
567
|
-
const
|
|
684
|
+
const dir = dndStore.startX.get() > x ? "left" : "right";
|
|
568
685
|
const dragOverColumn = getDragOverColumn(table, x);
|
|
569
686
|
if (dragOverColumn) {
|
|
570
687
|
const [col, index] = dragOverColumn;
|
|
571
|
-
|
|
572
|
-
...dndContext.peek(),
|
|
573
|
-
droppingIndex: index
|
|
574
|
-
});
|
|
688
|
+
dndStore.droppingIndex.set(index);
|
|
575
689
|
computePosition(col, host, {
|
|
576
|
-
placement:
|
|
577
|
-
middleware: [offset(
|
|
690
|
+
placement: dir === "left" ? "left" : "right",
|
|
691
|
+
middleware: [offset(dir === "left" ? -1 * handleWidth : 0)]
|
|
578
692
|
}).then(({ x }) => {
|
|
579
693
|
if (cancelled) return;
|
|
580
694
|
assignStyles(host, { left: `${x}px` });
|
|
@@ -583,17 +697,14 @@ function useUpdateIndicatorPosition(host, editor, handleWidth) {
|
|
|
583
697
|
return cleanup;
|
|
584
698
|
}
|
|
585
699
|
if (direction === "row") {
|
|
586
|
-
const
|
|
700
|
+
const dir = dndStore.startY.get() > y ? "up" : "down";
|
|
587
701
|
const dragOverRow = getDragOverRow(table, y);
|
|
588
702
|
if (dragOverRow) {
|
|
589
703
|
const [row, index] = dragOverRow;
|
|
590
|
-
|
|
591
|
-
...dndContext.peek(),
|
|
592
|
-
droppingIndex: index
|
|
593
|
-
});
|
|
704
|
+
dndStore.droppingIndex.set(index);
|
|
594
705
|
computePosition(row, host, {
|
|
595
|
-
placement:
|
|
596
|
-
middleware: [offset(
|
|
706
|
+
placement: dir === "up" ? "top" : "bottom",
|
|
707
|
+
middleware: [offset(dir === "up" ? -1 * handleWidth : 0)]
|
|
597
708
|
}).then(({ y }) => {
|
|
598
709
|
if (cancelled) return;
|
|
599
710
|
assignStyles(host, { top: `${y}px` });
|
|
@@ -603,150 +714,27 @@ function useUpdateIndicatorPosition(host, editor, handleWidth) {
|
|
|
603
714
|
}
|
|
604
715
|
});
|
|
605
716
|
}
|
|
606
|
-
|
|
607
|
-
//#region src/components/table-handle/table-handle-drop-indicator/setup.ts
|
|
608
|
-
const HANDLE_WIDTH = 2;
|
|
717
|
+
const TableHandleDropIndicatorElementBase = defineCustomElement(setupTableHandleDropIndicator, TableHandleDropIndicatorPropsDeclaration);
|
|
609
718
|
/**
|
|
610
|
-
* @
|
|
719
|
+
* @public
|
|
611
720
|
*/
|
|
612
|
-
function useTableHandleDropIndicator(host, { state }) {
|
|
613
|
-
const { editor } = state;
|
|
614
|
-
useEffect(host, () => {
|
|
615
|
-
assignStyles(host, {
|
|
616
|
-
pointerEvents: "none",
|
|
617
|
-
position: "absolute"
|
|
618
|
-
});
|
|
619
|
-
});
|
|
620
|
-
useInitDndPosition(host, editor, onInitIndicatorPosition);
|
|
621
|
-
useUpdateIndicatorPosition(host, editor, HANDLE_WIDTH);
|
|
622
|
-
}
|
|
623
|
-
function onInitIndicatorPosition({ host, direction, dragging, table }) {
|
|
624
|
-
assignStyles(host, { display: dragging ? "block" : "none" });
|
|
625
|
-
const tableRect = table.getBoundingClientRect();
|
|
626
|
-
if (direction === "col") assignStyles(host, {
|
|
627
|
-
width: `${HANDLE_WIDTH}px`,
|
|
628
|
-
height: `${tableRect.height}px`
|
|
629
|
-
});
|
|
630
|
-
if (direction === "row") assignStyles(host, {
|
|
631
|
-
width: `${tableRect.width}px`,
|
|
632
|
-
height: `${HANDLE_WIDTH}px`
|
|
633
|
-
});
|
|
634
|
-
}
|
|
635
|
-
//#endregion
|
|
636
|
-
//#region src/components/table-handle/table-handle-drop-indicator/types.ts
|
|
637
|
-
const tableHandleDropIndicatorProps = { editor: { default: null } };
|
|
638
|
-
const tableHandleDropIndicatorEvents = {};
|
|
639
|
-
//#endregion
|
|
640
|
-
//#region src/components/table-handle/table-handle-drop-indicator/element.gen.ts
|
|
641
|
-
const TableHandleDropIndicatorElementBase = defineCustomElement({
|
|
642
|
-
props: tableHandleDropIndicatorProps,
|
|
643
|
-
events: tableHandleDropIndicatorEvents,
|
|
644
|
-
setup: useTableHandleDropIndicator
|
|
645
|
-
});
|
|
646
721
|
var TableHandleDropIndicatorElement = class extends TableHandleDropIndicatorElementBase {};
|
|
647
|
-
registerCustomElement("prosekit-table-handle-drop-indicator", TableHandleDropIndicatorElement);
|
|
648
|
-
//#endregion
|
|
649
|
-
//#region src/components/table-handle/table-handle-popover-content/setup.ts
|
|
650
722
|
/**
|
|
651
723
|
* @internal
|
|
652
724
|
*/
|
|
653
|
-
function
|
|
654
|
-
|
|
655
|
-
const keyDownTarget = useKeyDownTarget(host, createComputed(() => !!rootContext.get()));
|
|
656
|
-
useMenuContent(host, {
|
|
657
|
-
state: getStateWithDefaults({
|
|
658
|
-
placement: state.placement,
|
|
659
|
-
offset: state.offset,
|
|
660
|
-
eventTarget: createSignal(keyDownTarget)
|
|
661
|
-
}, menuContentProps),
|
|
662
|
-
emit
|
|
663
|
-
});
|
|
664
|
-
}
|
|
665
|
-
function useKeyDownTarget(element, open) {
|
|
666
|
-
const keydownHandlers = [];
|
|
667
|
-
useEffect(element, () => {
|
|
668
|
-
const handleKeydown = (event) => {
|
|
669
|
-
if (event.isComposing || event.defaultPrevented || !open.get()) return false;
|
|
670
|
-
keydownHandlers.forEach((handler) => handler(event));
|
|
671
|
-
};
|
|
672
|
-
document.addEventListener("keydown", handleKeydown);
|
|
673
|
-
return () => {
|
|
674
|
-
document.removeEventListener("keydown", handleKeydown);
|
|
675
|
-
};
|
|
676
|
-
});
|
|
677
|
-
return {
|
|
678
|
-
addEventListener: (type, listener) => {
|
|
679
|
-
if (type === "keydown") keydownHandlers.push(listener);
|
|
680
|
-
},
|
|
681
|
-
removeEventListener: (type, listener) => {
|
|
682
|
-
if (type === "keydown") {
|
|
683
|
-
const index = keydownHandlers.indexOf(listener);
|
|
684
|
-
if (index !== -1) keydownHandlers.splice(index, 1);
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
};
|
|
725
|
+
function registerTableHandleDropIndicatorElement() {
|
|
726
|
+
registerCustomElement("prosekit-table-handle-drop-indicator", TableHandleDropIndicatorElement);
|
|
688
727
|
}
|
|
689
728
|
//#endregion
|
|
690
|
-
//#region src/components/table-handle/table-handle-popover-content/types.ts
|
|
691
|
-
/** @internal */
|
|
692
|
-
const tableHandlePopoverContentProps = Object.freeze({
|
|
693
|
-
...menuContentProps,
|
|
694
|
-
placement: { default: "right-start" },
|
|
695
|
-
offset: { default: {
|
|
696
|
-
mainAxis: -4,
|
|
697
|
-
crossAxis: 4
|
|
698
|
-
} },
|
|
699
|
-
editor: { default: null }
|
|
700
|
-
});
|
|
701
|
-
/** @internal */
|
|
702
|
-
const tableHandlePopoverContentEvents = Object.freeze({ ...menuContentEvents });
|
|
703
|
-
//#endregion
|
|
704
|
-
//#region src/components/table-handle/table-handle-popover-content/element.gen.ts
|
|
705
|
-
const TableHandlePopoverContentElementBase = defineCustomElement({
|
|
706
|
-
props: tableHandlePopoverContentProps,
|
|
707
|
-
events: tableHandlePopoverContentEvents,
|
|
708
|
-
setup: useTableHandlePopoverContent
|
|
709
|
-
});
|
|
710
|
-
var TableHandlePopoverContentElement = class extends TableHandlePopoverContentElementBase {};
|
|
711
|
-
registerCustomElement("prosekit-table-handle-popover-content", TableHandlePopoverContentElement);
|
|
712
|
-
//#endregion
|
|
713
|
-
//#region src/components/table-handle/table-handle-popover-item/setup.ts
|
|
714
|
-
/**
|
|
715
|
-
* @internal
|
|
716
|
-
*/
|
|
717
|
-
function useTableHandlePopoverItem(element, { state, emit }) {
|
|
718
|
-
useMenuItem(element, {
|
|
719
|
-
state,
|
|
720
|
-
emit
|
|
721
|
-
});
|
|
722
|
-
}
|
|
723
|
-
//#endregion
|
|
724
|
-
//#region src/components/table-handle/table-handle-popover-item/types.ts
|
|
725
|
-
/** @internal */
|
|
726
|
-
const tableHandlePopoverItemProps = { ...menuItemProps };
|
|
727
|
-
/** @internal */
|
|
728
|
-
const tableHandlePopoverItemEvents = { ...menuItemEvents };
|
|
729
|
-
//#endregion
|
|
730
|
-
//#region src/components/table-handle/table-handle-popover-item/element.gen.ts
|
|
731
|
-
const TableHandlePopoverItemElementBase = defineCustomElement({
|
|
732
|
-
props: tableHandlePopoverItemProps,
|
|
733
|
-
events: tableHandlePopoverItemEvents,
|
|
734
|
-
setup: useTableHandlePopoverItem
|
|
735
|
-
});
|
|
736
|
-
var TableHandlePopoverItemElement = class extends TableHandlePopoverItemElementBase {};
|
|
737
|
-
registerCustomElement("prosekit-table-handle-popover-item", TableHandlePopoverItemElement);
|
|
738
|
-
//#endregion
|
|
739
729
|
//#region src/hooks/use-editor-typing.ts
|
|
740
|
-
function useEditorTyping(host,
|
|
730
|
+
function useEditorTyping(host, getEditor) {
|
|
741
731
|
const typing = createSignal(false);
|
|
742
|
-
|
|
732
|
+
useEditorExtension(host, getEditor, union(defineDOMEventHandler("keypress", () => {
|
|
743
733
|
typing.set(true);
|
|
744
|
-
}
|
|
745
|
-
const handlePointerMove = () => {
|
|
734
|
+
}), defineDOMEventHandler("pointermove", () => {
|
|
746
735
|
typing.set(false);
|
|
747
|
-
};
|
|
748
|
-
|
|
749
|
-
return typing;
|
|
736
|
+
})));
|
|
737
|
+
return typing.get;
|
|
750
738
|
}
|
|
751
739
|
//#endregion
|
|
752
740
|
//#region src/hooks/use-selecting.ts
|
|
@@ -754,12 +742,12 @@ function useEditorTyping(host, editor) {
|
|
|
754
742
|
* Detect if the user is selecting text inside the editor, in which case some
|
|
755
743
|
* components should be disabled or hidden.
|
|
756
744
|
*/
|
|
757
|
-
function useSelecting(host,
|
|
745
|
+
function useSelecting(host, getEditor, getEnabled) {
|
|
758
746
|
const selecting = createSignal(false);
|
|
759
747
|
const isPointerDown = createSignal(false);
|
|
760
748
|
useEffect(host, () => {
|
|
761
|
-
if (!
|
|
762
|
-
const view = getSafeEditorView(
|
|
749
|
+
if (!getEnabled()) return;
|
|
750
|
+
const view = getSafeEditorView(getEditor());
|
|
763
751
|
if (!view) return;
|
|
764
752
|
const { dom, root } = view;
|
|
765
753
|
if (!root) return;
|
|
@@ -782,22 +770,26 @@ function useSelecting(host, editor, enabled) {
|
|
|
782
770
|
root.removeEventListener("pointermove", handleMouseMove);
|
|
783
771
|
};
|
|
784
772
|
});
|
|
785
|
-
return selecting;
|
|
773
|
+
return selecting.get;
|
|
786
774
|
}
|
|
787
775
|
//#endregion
|
|
788
|
-
//#region src/components/table-handle/
|
|
789
|
-
function useDrop(host,
|
|
790
|
-
const
|
|
776
|
+
//#region src/components/table-handle/use-drop.ts
|
|
777
|
+
function useDrop(host, getEditor, store) {
|
|
778
|
+
const getDndStore = () => store.dndStore;
|
|
779
|
+
const getDragging = computed(() => getDndStore().dragging.get());
|
|
791
780
|
useEffect(host, () => {
|
|
792
|
-
const view = getSafeEditorView(
|
|
781
|
+
const view = getSafeEditorView(getEditor());
|
|
793
782
|
if (!view || !view.editable) return;
|
|
794
783
|
const ownerDocument = view.dom?.ownerDocument;
|
|
795
784
|
if (!ownerDocument) return;
|
|
796
785
|
const handleDrop = () => {
|
|
797
|
-
if (!
|
|
798
|
-
const
|
|
799
|
-
if (!
|
|
800
|
-
const
|
|
786
|
+
if (!getDragging()) return;
|
|
787
|
+
const editor = getEditor();
|
|
788
|
+
if (!editor) return;
|
|
789
|
+
const dndStore = getDndStore();
|
|
790
|
+
const droppingIndex = dndStore.droppingIndex.get();
|
|
791
|
+
const draggingIndex = dndStore.draggingIndex.get();
|
|
792
|
+
const direction = dndStore.direction.get();
|
|
801
793
|
if (draggingIndex < 0 || droppingIndex < 0) {
|
|
802
794
|
console.warn("[prosekit] Invalid drag indices:", {
|
|
803
795
|
draggingIndex,
|
|
@@ -806,14 +798,14 @@ function useDrop(host, editor, dndContext) {
|
|
|
806
798
|
return;
|
|
807
799
|
}
|
|
808
800
|
if (direction === "row") {
|
|
809
|
-
|
|
801
|
+
editor.exec(moveTableRow({
|
|
810
802
|
from: draggingIndex,
|
|
811
803
|
to: droppingIndex
|
|
812
804
|
}));
|
|
813
805
|
return;
|
|
814
806
|
}
|
|
815
807
|
if (direction === "col") {
|
|
816
|
-
|
|
808
|
+
editor.exec(moveTableColumn({
|
|
817
809
|
from: draggingIndex,
|
|
818
810
|
to: droppingIndex
|
|
819
811
|
}));
|
|
@@ -821,23 +813,16 @@ function useDrop(host, editor, dndContext) {
|
|
|
821
813
|
}
|
|
822
814
|
};
|
|
823
815
|
const handleDragOver = (event) => {
|
|
824
|
-
if (!
|
|
816
|
+
if (!getDragging()) return;
|
|
825
817
|
event.preventDefault();
|
|
826
|
-
const
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
x: event.clientX,
|
|
831
|
-
y: event.clientY
|
|
832
|
-
});
|
|
818
|
+
const dndStore = getDndStore();
|
|
819
|
+
dndStore.dragging.set(true);
|
|
820
|
+
dndStore.x.set(event.clientX);
|
|
821
|
+
dndStore.y.set(event.clientY);
|
|
833
822
|
};
|
|
834
823
|
const handleDragEnd = () => {
|
|
835
|
-
if (!
|
|
836
|
-
|
|
837
|
-
dndContext.set({
|
|
838
|
-
...prev,
|
|
839
|
-
dragging: false
|
|
840
|
-
});
|
|
824
|
+
if (!getDragging()) return;
|
|
825
|
+
getDndStore().dragging.set(false);
|
|
841
826
|
};
|
|
842
827
|
ownerDocument.addEventListener("dragover", handleDragOver);
|
|
843
828
|
ownerDocument.addEventListener("drop", handleDrop);
|
|
@@ -897,126 +882,145 @@ function getCellIndex(map, rowIndex, colIndex) {
|
|
|
897
882
|
return map.width * rowIndex + colIndex;
|
|
898
883
|
}
|
|
899
884
|
//#endregion
|
|
900
|
-
//#region src/components/table-handle/table-handle-root
|
|
885
|
+
//#region src/components/table-handle/table-handle-root.ts
|
|
886
|
+
/** @internal */
|
|
887
|
+
const TableHandleRootPropsDeclaration = defineProps({ editor: {
|
|
888
|
+
default: null,
|
|
889
|
+
attribute: false,
|
|
890
|
+
type: "json"
|
|
891
|
+
} });
|
|
901
892
|
/**
|
|
902
893
|
* @internal
|
|
903
894
|
*/
|
|
904
|
-
function
|
|
905
|
-
const
|
|
906
|
-
const
|
|
907
|
-
const
|
|
908
|
-
const
|
|
909
|
-
const
|
|
910
|
-
const
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
return !typing.get() && !selecting.get() && !scrolling.get();
|
|
914
|
-
});
|
|
915
|
-
useEffect(host, () => {
|
|
916
|
-
context.set(canShow.get() ? hoveringCell.get() : null);
|
|
917
|
-
});
|
|
918
|
-
tableHandleRootContext.provide(host, context);
|
|
919
|
-
tableHandleDndContext.provide(host, dndContext);
|
|
920
|
-
useDrop(host, editor, dndContext);
|
|
895
|
+
function setupTableHandleRoot(host, props) {
|
|
896
|
+
const getEditor = props.editor.get;
|
|
897
|
+
const getHoveringCellInfo = useHoveringCell(host, getEditor);
|
|
898
|
+
const getTyping = useEditorTyping(host, getEditor);
|
|
899
|
+
const getSelecting = useSelecting(host, getEditor, computed(() => !!getHoveringCellInfo()));
|
|
900
|
+
const getScrolling = useScrolling(host);
|
|
901
|
+
const store = createTableHandleStore(getHoveringCellInfo, computed(() => !getTyping() && !getSelecting() && !getScrolling()));
|
|
902
|
+
tableHandleStoreContext.provide(host, store);
|
|
903
|
+
useDrop(host, getEditor, store);
|
|
921
904
|
}
|
|
922
|
-
function useHoveringCell(host,
|
|
923
|
-
const hoveringCell = createSignal(
|
|
924
|
-
useEditorExtension(host,
|
|
925
|
-
if (
|
|
905
|
+
function useHoveringCell(host, getEditor) {
|
|
906
|
+
const hoveringCell = createSignal(void 0);
|
|
907
|
+
useEditorExtension(host, getEditor, defineCellHoverHandler((curr) => {
|
|
908
|
+
if (isHoveringCellInfoEqual(hoveringCell.get(), curr)) return;
|
|
909
|
+
hoveringCell.set(curr);
|
|
926
910
|
}));
|
|
927
|
-
return hoveringCell;
|
|
911
|
+
return hoveringCell.get;
|
|
928
912
|
}
|
|
929
913
|
function defineCellHoverHandler(handler) {
|
|
930
914
|
const pointerHandler = (view, event) => {
|
|
931
|
-
return handler(getHoveringCell(view, event)
|
|
915
|
+
return handler(getHoveringCell(view, event));
|
|
932
916
|
};
|
|
933
917
|
return defineDOMEventHandler("pointerover", pointerHandler);
|
|
934
918
|
}
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
/** @internal */
|
|
940
|
-
const tableHandleRootEvents = {};
|
|
941
|
-
//#endregion
|
|
942
|
-
//#region src/components/table-handle/table-handle-root/element.gen.ts
|
|
943
|
-
const TableHandleRootElementBase = defineCustomElement({
|
|
944
|
-
props: tableHandleRootProps,
|
|
945
|
-
events: tableHandleRootEvents,
|
|
946
|
-
setup: useTableHandleRoot
|
|
947
|
-
});
|
|
919
|
+
const TableHandleRootElementBase = defineCustomElement(setupTableHandleRoot, TableHandleRootPropsDeclaration);
|
|
920
|
+
/**
|
|
921
|
+
* @public
|
|
922
|
+
*/
|
|
948
923
|
var TableHandleRootElement = class extends TableHandleRootElementBase {};
|
|
949
|
-
registerCustomElement("prosekit-table-handle-root", TableHandleRootElement);
|
|
950
|
-
//#endregion
|
|
951
|
-
//#region src/components/table-handle/table-handle-row-root/setup.ts
|
|
952
924
|
/**
|
|
953
925
|
* @internal
|
|
954
926
|
*/
|
|
955
|
-
function
|
|
956
|
-
|
|
957
|
-
const rootContext = tableHandleRootContext.consume(host);
|
|
958
|
-
const rowFirstCellPos = createComputed(() => {
|
|
959
|
-
return rootContext.get()?.rowFirstCellPos;
|
|
960
|
-
});
|
|
961
|
-
const referenceCell = createComputed(() => {
|
|
962
|
-
const pos = rowFirstCellPos.get();
|
|
963
|
-
const view = getSafeEditorView(editor.get());
|
|
964
|
-
if (!pos || !view) return null;
|
|
965
|
-
return view.nodeDOM(pos);
|
|
966
|
-
});
|
|
967
|
-
const contentOpen = createSignal(false);
|
|
968
|
-
useEffect(host, () => {
|
|
969
|
-
rowFirstCellPos.get();
|
|
970
|
-
contentOpen.set(false);
|
|
971
|
-
});
|
|
972
|
-
useOverlayPositionerState(host, overlayState, { reference: referenceCell });
|
|
973
|
-
const presence = createComputed(() => !!referenceCell.get());
|
|
974
|
-
useAttribute(host, "data-state", () => presence.get() ? "open" : "closed");
|
|
975
|
-
usePresence(host, presence);
|
|
976
|
-
useMenuRoot(host, {
|
|
977
|
-
state: getStateWithDefaults({ open: contentOpen }, menuRootProps),
|
|
978
|
-
emit: defineEmit(host, menuRootEvents)
|
|
979
|
-
});
|
|
927
|
+
function registerTableHandleRootElement() {
|
|
928
|
+
registerCustomElement("prosekit-table-handle-root", TableHandleRootElement);
|
|
980
929
|
}
|
|
981
930
|
//#endregion
|
|
982
|
-
//#region src/components/table-handle/table-handle-row-
|
|
931
|
+
//#region src/components/table-handle/table-handle-row-popup.ts
|
|
983
932
|
/** @internal */
|
|
984
|
-
const
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
933
|
+
const TableHandleRowPopupPropsDeclaration = defineProps({});
|
|
934
|
+
/** @internal */
|
|
935
|
+
function setupTableHandleRowPopup(host, _props) {
|
|
936
|
+
const getStore = tableHandleStoreContext.consume(host);
|
|
937
|
+
const getOverlayStore = () => getStore()?.rowOverlayStore;
|
|
938
|
+
setupOverlayPopup(host, getOverlayStore);
|
|
939
|
+
}
|
|
940
|
+
const TableHandleRowPopupElementBase = defineCustomElement(setupTableHandleRowPopup, TableHandleRowPopupPropsDeclaration);
|
|
941
|
+
/**
|
|
942
|
+
* @public
|
|
943
|
+
*/
|
|
944
|
+
var TableHandleRowPopupElement = class extends TableHandleRowPopupElementBase {};
|
|
993
945
|
/** @internal */
|
|
994
|
-
|
|
946
|
+
function registerTableHandleRowPopupElement() {
|
|
947
|
+
registerCustomElement("prosekit-table-handle-row-popup", TableHandleRowPopupElement);
|
|
948
|
+
}
|
|
995
949
|
//#endregion
|
|
996
|
-
//#region src/components/table-handle/table-handle-row-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
950
|
+
//#region src/components/table-handle/table-handle-row-positioner.ts
|
|
951
|
+
/** @internal */
|
|
952
|
+
const TableHandleRowPositionerPropsDeclaration = defineProps({
|
|
953
|
+
...SharedTableHandlePositionerPropsDeclaration,
|
|
954
|
+
placement: {
|
|
955
|
+
default: "left",
|
|
956
|
+
attribute: "placement",
|
|
957
|
+
type: "string"
|
|
958
|
+
}
|
|
1001
959
|
});
|
|
1002
|
-
|
|
1003
|
-
|
|
960
|
+
/** @internal */
|
|
961
|
+
function setupTableHandleRowPositioner(host, props) {
|
|
962
|
+
const getStore = tableHandleStoreContext.consume(host);
|
|
963
|
+
const getOverlayStore = () => getStore()?.rowOverlayStore;
|
|
964
|
+
setupOverlayPositioner(host, props, getOverlayStore);
|
|
965
|
+
const getEditor = props.editor.get;
|
|
966
|
+
const getReferenceCell = useHTMLElementAt(getEditor, computed(() => getStore()?.getReferenceCell()?.rowFirstCellPos));
|
|
967
|
+
useEffect(host, () => {
|
|
968
|
+
getOverlayStore()?.setAnchorElement(getReferenceCell());
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
const TableHandleRowPositionerElementBase = defineCustomElement(setupTableHandleRowPositioner, TableHandleRowPositionerPropsDeclaration);
|
|
972
|
+
/**
|
|
973
|
+
* @public
|
|
974
|
+
*/
|
|
975
|
+
var TableHandleRowPositionerElement = class extends TableHandleRowPositionerElementBase {};
|
|
976
|
+
/** @internal */
|
|
977
|
+
function registerTableHandleRowPositionerElement() {
|
|
978
|
+
registerCustomElement("prosekit-table-handle-row-positioner", TableHandleRowPositionerElement);
|
|
979
|
+
}
|
|
1004
980
|
//#endregion
|
|
1005
|
-
//#region src/components/table-handle/table-handle-row-
|
|
981
|
+
//#region src/components/table-handle/table-handle-row-menu-root.ts
|
|
982
|
+
/** @internal */
|
|
983
|
+
const TableHandleRowMenuRootPropsDeclaration = defineProps(MenuRootPropsDeclaration);
|
|
984
|
+
/** @internal */
|
|
985
|
+
function setupTableHandleRowMenuRoot(host, props) {
|
|
986
|
+
setupMenuRoot(host, props);
|
|
987
|
+
const getStore = tableHandleStoreContext.consume(host);
|
|
988
|
+
useEffect(host, () => {
|
|
989
|
+
const open = props.open.get() || false;
|
|
990
|
+
const store = getStore?.();
|
|
991
|
+
if (!store) return;
|
|
992
|
+
store.setIsRowMenuOpen(open);
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
const TableHandleRowMenuRootElementBase = defineCustomElement(setupTableHandleRowMenuRoot, TableHandleRowMenuRootPropsDeclaration);
|
|
1006
996
|
/**
|
|
1007
|
-
* @
|
|
997
|
+
* @public
|
|
1008
998
|
*/
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
999
|
+
var TableHandleRowMenuRootElement = class extends TableHandleRowMenuRootElementBase {};
|
|
1000
|
+
/** @internal */
|
|
1001
|
+
function registerTableHandleRowMenuRootElement() {
|
|
1002
|
+
registerCustomElement("prosekit-table-handle-row-menu-root", TableHandleRowMenuRootElement);
|
|
1003
|
+
}
|
|
1004
|
+
//#endregion
|
|
1005
|
+
//#region src/components/table-handle/table-handle-row-menu-trigger.ts
|
|
1006
|
+
/** @internal */
|
|
1007
|
+
const TableHandleRowMenuTriggerPropsDeclaration = defineProps({ editor: {
|
|
1008
|
+
default: null,
|
|
1009
|
+
attribute: false,
|
|
1010
|
+
type: "json"
|
|
1011
|
+
} });
|
|
1012
|
+
/** @internal */
|
|
1013
|
+
function setupTableHandleRowMenuTrigger(host, props) {
|
|
1014
|
+
const getEditor = props.editor.get;
|
|
1015
|
+
const getStore = tableHandleStoreContext.consume(host);
|
|
1016
|
+
setupMenuTrigger(host, { disabled: createSignal(false) });
|
|
1013
1017
|
useEventListener(host, "pointerdown", () => {
|
|
1014
|
-
const editor =
|
|
1015
|
-
const cellPos =
|
|
1018
|
+
const editor = getEditor();
|
|
1019
|
+
const cellPos = getStore()?.getReferenceCell()?.cellPos;
|
|
1016
1020
|
if (!editor || !cellPos) return;
|
|
1017
1021
|
editor.exec(selectTableRow({ head: cellPos }));
|
|
1018
1022
|
});
|
|
1019
|
-
|
|
1023
|
+
onMount(host, () => {
|
|
1020
1024
|
host.draggable = true;
|
|
1021
1025
|
});
|
|
1022
1026
|
const getEmptyImage = useEmptyImage(host);
|
|
@@ -1027,39 +1031,34 @@ function useTableHandleRowTrigger(host, { state }) {
|
|
|
1027
1031
|
const emptyImage = getEmptyImage();
|
|
1028
1032
|
if (emptyImage) dataTransfer.setDragImage(emptyImage, 0, 0);
|
|
1029
1033
|
}
|
|
1030
|
-
const
|
|
1031
|
-
|
|
1034
|
+
const store = getStore();
|
|
1035
|
+
if (!store) return;
|
|
1036
|
+
const index = store.getReferenceCell()?.rowIndex;
|
|
1032
1037
|
if (index == null || index < 0) {
|
|
1033
1038
|
console.warn("[prosekit] Invalid row index for drag operation:", index);
|
|
1034
1039
|
event.preventDefault();
|
|
1035
1040
|
return;
|
|
1036
1041
|
}
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
startY: event.clientY
|
|
1044
|
-
});
|
|
1042
|
+
const dndStore = store.dndStore;
|
|
1043
|
+
dndStore.direction.set("row");
|
|
1044
|
+
dndStore.dragging.set(true);
|
|
1045
|
+
dndStore.draggingIndex.set(index);
|
|
1046
|
+
dndStore.startX.set(event.clientX);
|
|
1047
|
+
dndStore.startY.set(event.clientY);
|
|
1045
1048
|
});
|
|
1046
1049
|
}
|
|
1050
|
+
const TableHandleRowMenuTriggerElementBase = defineCustomElement(setupTableHandleRowMenuTrigger, TableHandleRowMenuTriggerPropsDeclaration);
|
|
1051
|
+
/**
|
|
1052
|
+
* @public
|
|
1053
|
+
*/
|
|
1054
|
+
var TableHandleRowMenuTriggerElement = class extends TableHandleRowMenuTriggerElementBase {};
|
|
1055
|
+
/**
|
|
1056
|
+
* @internal
|
|
1057
|
+
*/
|
|
1058
|
+
function registerTableHandleRowMenuTriggerElement() {
|
|
1059
|
+
registerCustomElement("prosekit-table-handle-row-menu-trigger", TableHandleRowMenuTriggerElement);
|
|
1060
|
+
}
|
|
1047
1061
|
//#endregion
|
|
1048
|
-
|
|
1049
|
-
/** @internal */
|
|
1050
|
-
const tableHandleRowTriggerProps = { editor: { default: null } };
|
|
1051
|
-
/** @internal */
|
|
1052
|
-
const tableHandleRowTriggerEvents = { select: {} };
|
|
1053
|
-
//#endregion
|
|
1054
|
-
//#region src/components/table-handle/table-handle-row-trigger/element.gen.ts
|
|
1055
|
-
const TableHandleRowTriggerElementBase = defineCustomElement({
|
|
1056
|
-
props: tableHandleRowTriggerProps,
|
|
1057
|
-
events: tableHandleRowTriggerEvents,
|
|
1058
|
-
setup: useTableHandleRowTrigger
|
|
1059
|
-
});
|
|
1060
|
-
var TableHandleRowTriggerElement = class extends TableHandleRowTriggerElementBase {};
|
|
1061
|
-
registerCustomElement("prosekit-table-handle-row-trigger", TableHandleRowTriggerElement);
|
|
1062
|
-
//#endregion
|
|
1063
|
-
export { TableHandleColumnRootElement, TableHandleColumnTriggerElement, TableHandleDragPreviewElement, TableHandleDropIndicatorElement, TableHandlePopoverContentElement, TableHandlePopoverItemElement, TableHandleRootElement, TableHandleRowRootElement, TableHandleRowTriggerElement, tableHandleColumnRootEvents, tableHandleColumnRootProps, tableHandleColumnTriggerEvents, tableHandleColumnTriggerProps, tableHandleDragPreviewEvents, tableHandleDragPreviewProps, tableHandleDropIndicatorEvents, tableHandleDropIndicatorProps, tableHandlePopoverContentEvents, tableHandlePopoverContentProps, tableHandlePopoverItemEvents, tableHandlePopoverItemProps, tableHandleRootEvents, tableHandleRootProps, tableHandleRowRootEvents, tableHandleRowRootProps, tableHandleRowTriggerEvents, tableHandleRowTriggerProps, useTableHandleColumnRoot, useTableHandleColumnTrigger, useTableHandleDragPreview, useTableHandleDropIndicator, useTableHandlePopoverContent, useTableHandlePopoverItem, useTableHandleRoot, useTableHandleRowRoot, useTableHandleRowTrigger };
|
|
1062
|
+
export { TableHandleColumnMenuRootElement, TableHandleColumnMenuRootPropsDeclaration, TableHandleColumnMenuTriggerElement, TableHandleColumnMenuTriggerPropsDeclaration, TableHandleColumnPopupElement, TableHandleColumnPopupPropsDeclaration, TableHandleColumnPositionerElement, TableHandleColumnPositionerPropsDeclaration, TableHandleDragPreviewElement, TableHandleDragPreviewPropsDeclaration, TableHandleDropIndicatorElement, TableHandleDropIndicatorPropsDeclaration, TableHandleRootElement, TableHandleRootPropsDeclaration, TableHandleRowMenuRootElement, TableHandleRowMenuRootPropsDeclaration, TableHandleRowMenuTriggerElement, TableHandleRowMenuTriggerPropsDeclaration, TableHandleRowPopupElement, TableHandleRowPopupPropsDeclaration, TableHandleRowPositionerElement, TableHandleRowPositionerPropsDeclaration, registerTableHandleColumnMenuRootElement, registerTableHandleColumnMenuTriggerElement, registerTableHandleColumnPopupElement, registerTableHandleColumnPositionerElement, registerTableHandleDragPreviewElement, registerTableHandleDropIndicatorElement, registerTableHandleRootElement, registerTableHandleRowMenuRootElement, registerTableHandleRowMenuTriggerElement, registerTableHandleRowPopupElement, registerTableHandleRowPositionerElement, setupTableHandleColumnMenuRoot, setupTableHandleColumnMenuTrigger, setupTableHandleColumnPopup, setupTableHandleColumnPositioner, setupTableHandleDragPreview, setupTableHandleDropIndicator, setupTableHandleRoot, setupTableHandleRowMenuRoot, setupTableHandleRowMenuTrigger, setupTableHandleRowPopup, setupTableHandleRowPositioner };
|
|
1064
1063
|
|
|
1065
1064
|
//# sourceMappingURL=prosekit-web-table-handle.js.map
|