@prosekit/web 0.6.0 → 0.7.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.
- package/dist/assign-styles-3yY6F1UX.js +10 -0
- package/dist/clone-element-i6RFnyj4.js +41 -0
- package/dist/prosekit-web-autocomplete.d.ts +1 -1
- package/dist/prosekit-web-block-handle.d.ts +1 -1
- package/dist/prosekit-web-block-handle.js +16 -48
- package/dist/prosekit-web-drop-indicator.d.ts +38 -0
- package/dist/prosekit-web-drop-indicator.js +75 -0
- package/dist/prosekit-web-inline-popover.d.ts +1 -1
- package/dist/prosekit-web-popover.d.ts +1 -1
- package/dist/prosekit-web-resizable.d.ts +1 -1
- package/dist/prosekit-web-table-handle.d.ts +17 -3
- package/dist/prosekit-web-table-handle.js +52 -29
- package/dist/prosekit-web-tooltip.d.ts +1 -1
- package/package.json +17 -9
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region src/utils/clone-element.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a deep clone of an Element, including all computed styles so that
|
|
4
|
+
* it looks the same as the original element.
|
|
5
|
+
*/
|
|
6
|
+
function deepCloneElement(element) {
|
|
7
|
+
const clonedElement = element.cloneNode(true);
|
|
8
|
+
deepCopyStyles(element, clonedElement);
|
|
9
|
+
return clonedElement;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a clone of an Element, including all computed styles so that
|
|
13
|
+
* it looks similar enough to the original element.
|
|
14
|
+
*/
|
|
15
|
+
function cloneElement(element) {
|
|
16
|
+
const clonedElement = element.cloneNode();
|
|
17
|
+
copyStyles(element, clonedElement);
|
|
18
|
+
return clonedElement;
|
|
19
|
+
}
|
|
20
|
+
function deepCopyStyles(source, target) {
|
|
21
|
+
const sources = [source];
|
|
22
|
+
const targets = [target];
|
|
23
|
+
while (sources.length > 0 && sources.length === targets.length) {
|
|
24
|
+
const source$1 = sources.pop();
|
|
25
|
+
const target$1 = targets.pop();
|
|
26
|
+
if (!source$1 || !target$1) return;
|
|
27
|
+
copyStyles(source$1, target$1);
|
|
28
|
+
sources.push(...source$1.children);
|
|
29
|
+
targets.push(...target$1.children);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function copyStyles(source, target) {
|
|
33
|
+
if (!source || !target) return;
|
|
34
|
+
const sourceStyle = source.ownerDocument?.defaultView?.getComputedStyle(source);
|
|
35
|
+
const targetStyle = target.style;
|
|
36
|
+
if (!sourceStyle || !targetStyle) return;
|
|
37
|
+
for (const key of sourceStyle) targetStyle.setProperty(key, sourceStyle.getPropertyValue(key), sourceStyle.getPropertyPriority(key));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { cloneElement, deepCloneElement };
|
|
@@ -157,4 +157,4 @@ declare function useAutocompletePopover(host: ConnectableElement, {
|
|
|
157
157
|
emit
|
|
158
158
|
}: SetupOptions<AutocompletePopoverProps, AutocompletePopoverEvents>): void;
|
|
159
159
|
//#endregion
|
|
160
|
-
export { AutocompleteEmptyElement, AutocompleteEmptyEvents, AutocompleteEmptyProps, AutocompleteItemElement, AutocompleteItemEvents, AutocompleteItemProps, AutocompleteListElement, AutocompleteListEvents, AutocompleteListProps, AutocompletePopoverElement, AutocompletePopoverEvents, AutocompletePopoverProps, autocompleteEmptyEvents, autocompleteEmptyProps, autocompleteItemEvents, autocompleteItemProps, autocompleteListEvents, autocompleteListProps, autocompletePopoverEvents, autocompletePopoverProps, useAutocompleteEmpty, useAutocompleteItem, useAutocompleteList, useAutocompletePopover };
|
|
160
|
+
export { AutocompleteEmptyElement, type AutocompleteEmptyEvents, type AutocompleteEmptyProps, AutocompleteItemElement, type AutocompleteItemEvents, type AutocompleteItemProps, AutocompleteListElement, type AutocompleteListEvents, type AutocompleteListProps, AutocompletePopoverElement, type AutocompletePopoverEvents, type AutocompletePopoverProps, autocompleteEmptyEvents, autocompleteEmptyProps, autocompleteItemEvents, autocompleteItemProps, autocompleteListEvents, autocompleteListProps, autocompletePopoverEvents, autocompletePopoverProps, useAutocompleteEmpty, useAutocompleteItem, useAutocompleteList, useAutocompletePopover };
|
|
@@ -116,4 +116,4 @@ declare function useBlockHandlePopover(host: ConnectableElement, {
|
|
|
116
116
|
emit
|
|
117
117
|
}: SetupOptions<BlockHandlePopoverProps, BlockHandlePopoverEvents>): void;
|
|
118
118
|
//#endregion
|
|
119
|
-
export { BlockHandleAddElement, BlockHandleAddEvents, BlockHandleAddProps, BlockHandleDraggableElement, BlockHandleDraggableEvents, BlockHandleDraggableProps, BlockHandlePopoverElement, BlockHandlePopoverEvents, BlockHandlePopoverProps, blockHandleAddEvents, blockHandleAddProps, blockHandleDraggableEvents, blockHandleDraggableProps, blockHandlePopoverEvents, blockHandlePopoverProps, useBlockHandleAdd, useBlockHandleDraggable, useBlockHandlePopover };
|
|
119
|
+
export { BlockHandleAddElement, type BlockHandleAddEvents, type BlockHandleAddProps, BlockHandleDraggableElement, type BlockHandleDraggableEvents, type BlockHandleDraggableProps, BlockHandlePopoverElement, type BlockHandlePopoverEvents, type BlockHandlePopoverProps, blockHandleAddEvents, blockHandleAddProps, blockHandleDraggableEvents, blockHandleDraggableProps, blockHandlePopoverEvents, blockHandlePopoverProps, useBlockHandleAdd, useBlockHandleDraggable, useBlockHandlePopover };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { useEditorExtension } from "./use-editor-extension-Cc7ZG7uj.js";
|
|
2
|
-
import {
|
|
2
|
+
import { assignStyles } from "./assign-styles-3yY6F1UX.js";
|
|
3
|
+
import { deepCloneElement } from "./clone-element-i6RFnyj4.js";
|
|
4
|
+
import { createComputed, createContext, createSignal, defineCustomElement, registerCustomElement, useAttribute, useEffect, useEventListener } from "@aria-ui/core";
|
|
3
5
|
import { defineDOMEventHandler, insertDefaultBlock, union } from "@prosekit/core";
|
|
4
6
|
import { overlayPositionerEvents, overlayPositionerProps, useOverlayPositionerState } from "@aria-ui/overlay/elements";
|
|
5
7
|
import { usePresence } from "@aria-ui/presence";
|
|
@@ -12,6 +14,10 @@ import { NodeSelection } from "@prosekit/pm/state";
|
|
|
12
14
|
* @internal
|
|
13
15
|
*/
|
|
14
16
|
const blockPopoverContext = createContext("prosekit-block-popover-context", null);
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
const draggingContext = createContext("prosekit-block-handle-dragging-context", false);
|
|
15
21
|
|
|
16
22
|
//#endregion
|
|
17
23
|
//#region src/components/block-handle/block-handle-add/setup.ts
|
|
@@ -49,46 +55,10 @@ const BlockHandleAddElementBase = defineCustomElement({
|
|
|
49
55
|
var BlockHandleAddElement = class extends BlockHandleAddElementBase {};
|
|
50
56
|
registerCustomElement("prosekit-block-handle-add", BlockHandleAddElement);
|
|
51
57
|
|
|
52
|
-
//#endregion
|
|
53
|
-
//#region src/utils/asset-styles.ts
|
|
54
|
-
function assignStyles(element, styles) {
|
|
55
|
-
Object.assign(element.style, styles);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
58
|
//#endregion
|
|
59
59
|
//#region src/utils/max-z-index.ts
|
|
60
60
|
const maxZIndex = "2147483647";
|
|
61
61
|
|
|
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
62
|
//#endregion
|
|
93
63
|
//#region src/components/block-handle/block-handle-draggable/set-drag-preview.ts
|
|
94
64
|
/**
|
|
@@ -186,7 +156,7 @@ function useDataDraggingAttribute(host) {
|
|
|
186
156
|
useAttribute(host, "data-dragging", () => dragging.get() ? "" : void 0);
|
|
187
157
|
}
|
|
188
158
|
function useDragging(host) {
|
|
189
|
-
const dragging =
|
|
159
|
+
const dragging = draggingContext.consume(host);
|
|
190
160
|
useEventListener(host, "dragstart", () => {
|
|
191
161
|
dragging.set(true);
|
|
192
162
|
});
|
|
@@ -223,7 +193,7 @@ function getClientRect(element) {
|
|
|
223
193
|
if (rect.width === 0 && rect.height === 0 && rect.x === 0 && rect.y === 0) {
|
|
224
194
|
if (element.getClientRects().length === 0) {
|
|
225
195
|
const children = Array.from(element.children);
|
|
226
|
-
const rects = children.map((child) => getClientRect(child))
|
|
196
|
+
const rects = children.map((child) => getClientRect(child));
|
|
227
197
|
if (rects.length === 0) return rect;
|
|
228
198
|
if (rects.length === 1) return rects[0];
|
|
229
199
|
return {
|
|
@@ -271,7 +241,7 @@ function defineElementHoverHandler(handler) {
|
|
|
271
241
|
};
|
|
272
242
|
const handlePointerEvent = (view, event) => {
|
|
273
243
|
const { x, y } = event;
|
|
274
|
-
const block =
|
|
244
|
+
const block = findBlockByCoords(view, x, y);
|
|
275
245
|
if (!block) {
|
|
276
246
|
handler(null, null);
|
|
277
247
|
return;
|
|
@@ -292,9 +262,8 @@ function defineElementHoverHandler(handler) {
|
|
|
292
262
|
};
|
|
293
263
|
return union(defineDOMEventHandler("pointermove", throttle(handlePointerEvent, 200)), defineDOMEventHandler("pointerout", handlePointerEvent), defineDOMEventHandler("keypress", () => handler(null, null)));
|
|
294
264
|
}
|
|
295
|
-
function
|
|
296
|
-
const
|
|
297
|
-
const rect = getClientRect(dom);
|
|
265
|
+
function findBlockByCoords(view, x, y) {
|
|
266
|
+
const rect = getClientRect(view.dom);
|
|
298
267
|
if (!isWithinRect(rect, x, y)) return;
|
|
299
268
|
let parent = view.state.doc;
|
|
300
269
|
let pos = -1;
|
|
@@ -316,7 +285,7 @@ function findBlockByCoordinate(view, x, y) {
|
|
|
316
285
|
const childDOM = view.nodeDOM(positions[i]);
|
|
317
286
|
const childRect = getNodeRect(childDOM);
|
|
318
287
|
if (!childRect) {
|
|
319
|
-
console.warn(
|
|
288
|
+
console.warn(`[prosekit] Unable to get rect at position: ${positions[i]}`);
|
|
320
289
|
return;
|
|
321
290
|
}
|
|
322
291
|
if (childRect.top > y) hi = i - 1;
|
|
@@ -438,10 +407,9 @@ function useBlockHandlePopover(host, { state, emit }) {
|
|
|
438
407
|
useOverlayPositionerState(host, overlayState, { reference });
|
|
439
408
|
const context = createSignal(null);
|
|
440
409
|
blockPopoverContext.provide(host, context);
|
|
441
|
-
const
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
});
|
|
410
|
+
const dragging = createSignal(false);
|
|
411
|
+
draggingContext.provide(host, dragging);
|
|
412
|
+
const open = createComputed(() => !!context.get());
|
|
445
413
|
useHoverExtension(host, editor, (referenceValue, hoverState) => {
|
|
446
414
|
reference.set(referenceValue);
|
|
447
415
|
context.set(hoverState);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { BaseElementConstructor, ConnectableElement, EventDeclarations, PropDeclarations, SetupOptions } from "@aria-ui/core";
|
|
2
|
+
import { Editor } from "@prosekit/core";
|
|
3
|
+
|
|
4
|
+
//#region src/components/drop-indicator/drop-indicator/types.d.ts
|
|
5
|
+
interface DropIndicatorProps {
|
|
6
|
+
/**
|
|
7
|
+
* The ProseKit editor instance.
|
|
8
|
+
*
|
|
9
|
+
* @default null
|
|
10
|
+
* @hidden
|
|
11
|
+
*/
|
|
12
|
+
editor: Editor | null;
|
|
13
|
+
/**
|
|
14
|
+
* The line width in pixels.
|
|
15
|
+
*
|
|
16
|
+
* @default 2
|
|
17
|
+
*/
|
|
18
|
+
width: number;
|
|
19
|
+
}
|
|
20
|
+
/** @internal */
|
|
21
|
+
declare const dropIndicatorProps: PropDeclarations<DropIndicatorProps>;
|
|
22
|
+
interface DropIndicatorEvents {}
|
|
23
|
+
/** @internal */
|
|
24
|
+
declare const dropIndicatorEvents: EventDeclarations<DropIndicatorEvents>;
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/components/drop-indicator/drop-indicator/element.gen.d.ts
|
|
27
|
+
declare const DropIndicatorElementBase: BaseElementConstructor<DropIndicatorProps>;
|
|
28
|
+
declare class DropIndicatorElement extends DropIndicatorElementBase {}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/components/drop-indicator/drop-indicator/setup.d.ts
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
declare function useDropIndicator(host: ConnectableElement, {
|
|
35
|
+
state
|
|
36
|
+
}: SetupOptions<DropIndicatorProps, DropIndicatorEvents>): void;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { DropIndicatorElement, type DropIndicatorEvents, type DropIndicatorProps, dropIndicatorEvents, dropIndicatorProps, useDropIndicator };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { useEditorExtension } from "./use-editor-extension-Cc7ZG7uj.js";
|
|
2
|
+
import { assignStyles } from "./assign-styles-3yY6F1UX.js";
|
|
3
|
+
import { createComputed, createSignal, defineCustomElement, registerCustomElement, useEffect } from "@aria-ui/core";
|
|
4
|
+
import { usePresence } from "@aria-ui/presence";
|
|
5
|
+
import { defineDropIndicator } from "@prosekit/extensions/drop-indicator";
|
|
6
|
+
|
|
7
|
+
//#region src/components/drop-indicator/drop-indicator/setup.ts
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
function useDropIndicator(host, { state }) {
|
|
12
|
+
const context = createSignal(null);
|
|
13
|
+
const extension = defineDropIndicator({
|
|
14
|
+
onShow: (options) => context.set(options),
|
|
15
|
+
onHide: () => context.set(null)
|
|
16
|
+
});
|
|
17
|
+
useEditorExtension(host, state.editor, extension);
|
|
18
|
+
const line = createComputed(() => context.get()?.line);
|
|
19
|
+
const presence = createComputed(() => !!line.get());
|
|
20
|
+
usePresence(host, presence);
|
|
21
|
+
useEffect(host, () => {
|
|
22
|
+
const lineValue = line.get();
|
|
23
|
+
const lineWidth = state.width.get();
|
|
24
|
+
if (!lineValue) return;
|
|
25
|
+
const { p1: { x: x1, y: y1 }, p2: { x: x2, y: y2 } } = lineValue;
|
|
26
|
+
const horizontal = y1 === y2;
|
|
27
|
+
let width;
|
|
28
|
+
let height;
|
|
29
|
+
let top = y1;
|
|
30
|
+
let left = x1;
|
|
31
|
+
if (horizontal) {
|
|
32
|
+
width = x2 - x1;
|
|
33
|
+
height = lineWidth;
|
|
34
|
+
top -= lineWidth / 2;
|
|
35
|
+
} else {
|
|
36
|
+
width = lineWidth;
|
|
37
|
+
height = y2 - y1;
|
|
38
|
+
left -= lineWidth / 2;
|
|
39
|
+
}
|
|
40
|
+
top = Math.round(top);
|
|
41
|
+
left = Math.round(left);
|
|
42
|
+
assignStyles(host, {
|
|
43
|
+
position: "fixed",
|
|
44
|
+
pointerEvents: "none",
|
|
45
|
+
width: `${width}px`,
|
|
46
|
+
height: `${height}px`,
|
|
47
|
+
transform: `translate(${left}px, ${top}px)`,
|
|
48
|
+
left: "0px",
|
|
49
|
+
top: "0px"
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/components/drop-indicator/drop-indicator/types.ts
|
|
56
|
+
/** @internal */
|
|
57
|
+
const dropIndicatorProps = Object.freeze({
|
|
58
|
+
editor: { default: null },
|
|
59
|
+
width: { default: 2 }
|
|
60
|
+
});
|
|
61
|
+
/** @internal */
|
|
62
|
+
const dropIndicatorEvents = {};
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/components/drop-indicator/drop-indicator/element.gen.ts
|
|
66
|
+
const DropIndicatorElementBase = defineCustomElement({
|
|
67
|
+
props: dropIndicatorProps,
|
|
68
|
+
events: dropIndicatorEvents,
|
|
69
|
+
setup: useDropIndicator
|
|
70
|
+
});
|
|
71
|
+
var DropIndicatorElement = class extends DropIndicatorElementBase {};
|
|
72
|
+
registerCustomElement("prosekit-drop-indicator", DropIndicatorElement);
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
export { DropIndicatorElement, dropIndicatorEvents, dropIndicatorProps, useDropIndicator };
|
|
@@ -87,4 +87,4 @@ declare function useInlinePopover(host: ConnectableElement, {
|
|
|
87
87
|
emit
|
|
88
88
|
}: SetupOptions<InlinePopoverProps, InlinePopoverEvents>): void;
|
|
89
89
|
//#endregion
|
|
90
|
-
export { InlinePopoverElement, InlinePopoverEvents, InlinePopoverProps, inlinePopoverEvents, inlinePopoverProps, useInlinePopover };
|
|
90
|
+
export { InlinePopoverElement, type InlinePopoverEvents, type InlinePopoverProps, inlinePopoverEvents, inlinePopoverProps, useInlinePopover };
|
|
@@ -25,4 +25,4 @@ interface PopoverTriggerEvents extends PopoverTriggerEvents$1 {}
|
|
|
25
25
|
declare const PopoverTriggerElementBase: BaseElementConstructor<PopoverTriggerProps>;
|
|
26
26
|
declare class PopoverTriggerElement extends PopoverTriggerElementBase {}
|
|
27
27
|
//#endregion
|
|
28
|
-
export { PopoverContentElement, PopoverContentEvents, PopoverContentProps, PopoverRootElement, PopoverRootEvents, PopoverRootProps, PopoverTriggerElement, PopoverTriggerEvents, PopoverTriggerProps, popoverContentEvents, popoverContentProps, popoverRootEvents, popoverRootProps, popoverTriggerEvents, popoverTriggerProps, usePopoverContent, usePopoverRoot, usePopoverTrigger };
|
|
28
|
+
export { PopoverContentElement, type PopoverContentEvents, type PopoverContentProps, PopoverRootElement, type PopoverRootEvents, type PopoverRootProps, PopoverTriggerElement, type PopoverTriggerEvents, type PopoverTriggerProps, popoverContentEvents, popoverContentProps, popoverRootEvents, popoverRootProps, popoverTriggerEvents, popoverTriggerProps, usePopoverContent, usePopoverRoot, usePopoverTrigger };
|
|
@@ -64,4 +64,4 @@ declare function useResizableRoot(host: ConnectableElement, {
|
|
|
64
64
|
emit
|
|
65
65
|
}: SetupOptions<ResizableRootProps, ResizableRootEvents>): void;
|
|
66
66
|
//#endregion
|
|
67
|
-
export { ResizableHandleElement, ResizableHandleEvents, ResizableHandleProps, ResizableRootElement, ResizableRootEvents, ResizableRootProps, resizableHandleEvents, resizableHandleProps, resizableRootEvents, resizableRootProps, useResizableHandle, useResizableRoot };
|
|
67
|
+
export { ResizableHandleElement, type ResizableHandleEvents, type ResizableHandleProps, ResizableRootElement, type ResizableRootEvents, type ResizableRootProps, resizableHandleEvents, resizableHandleProps, resizableRootEvents, resizableRootProps, useResizableHandle, useResizableRoot };
|
|
@@ -7,7 +7,7 @@ import { Placement } from "@floating-ui/dom";
|
|
|
7
7
|
import { MenuItemEvents, MenuItemProps } from "@aria-ui/menu";
|
|
8
8
|
|
|
9
9
|
//#region src/components/table-handle/table-handle-column-root/types.d.ts
|
|
10
|
-
interface TableHandleColumnRootProps extends Omit<OverlayPositionerProps, "placement"> {
|
|
10
|
+
interface TableHandleColumnRootProps extends Omit<OverlayPositionerProps, "placement" | "hoist"> {
|
|
11
11
|
/**
|
|
12
12
|
* The ProseKit editor instance.
|
|
13
13
|
*
|
|
@@ -21,6 +21,13 @@ interface TableHandleColumnRootProps extends Omit<OverlayPositionerProps, "place
|
|
|
21
21
|
* @default "top"
|
|
22
22
|
*/
|
|
23
23
|
placement: Placement;
|
|
24
|
+
/**
|
|
25
|
+
* Whether to use the browser [Popover API](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API)
|
|
26
|
+
* to place the floating element on top of other page content.
|
|
27
|
+
*
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
hoist: boolean;
|
|
24
31
|
}
|
|
25
32
|
/** @internal */
|
|
26
33
|
declare const tableHandleColumnRootProps: PropDeclarations<TableHandleColumnRootProps>;
|
|
@@ -195,7 +202,7 @@ declare function useTableHandleRoot(host: ConnectableElement, {
|
|
|
195
202
|
}): void;
|
|
196
203
|
//#endregion
|
|
197
204
|
//#region src/components/table-handle/table-handle-row-root/types.d.ts
|
|
198
|
-
interface TableHandleRowRootProps extends Omit<OverlayPositionerProps, "placement"> {
|
|
205
|
+
interface TableHandleRowRootProps extends Omit<OverlayPositionerProps, "placement" | "hoist"> {
|
|
199
206
|
/**
|
|
200
207
|
* The ProseKit editor instance.
|
|
201
208
|
*
|
|
@@ -209,6 +216,13 @@ interface TableHandleRowRootProps extends Omit<OverlayPositionerProps, "placemen
|
|
|
209
216
|
* @default "left"
|
|
210
217
|
*/
|
|
211
218
|
placement: Placement;
|
|
219
|
+
/**
|
|
220
|
+
* Whether to use the browser [Popover API](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API)
|
|
221
|
+
* to place the floating element on top of other page content.
|
|
222
|
+
*
|
|
223
|
+
* @default false
|
|
224
|
+
*/
|
|
225
|
+
hoist: boolean;
|
|
212
226
|
}
|
|
213
227
|
/** @internal */
|
|
214
228
|
declare const tableHandleRowRootProps: PropDeclarations<TableHandleRowRootProps>;
|
|
@@ -254,4 +268,4 @@ declare function useTableHandleRowTrigger(host: ConnectableElement, {
|
|
|
254
268
|
state
|
|
255
269
|
}: SetupOptions<TableHandleRowTriggerProps, TableHandleRowTriggerEvents>): void;
|
|
256
270
|
//#endregion
|
|
257
|
-
export { TableHandleColumnRootElement, TableHandleColumnRootEvents, TableHandleColumnRootProps, TableHandleColumnTriggerElement, TableHandleColumnTriggerEvents, TableHandleColumnTriggerProps, TableHandleDragPreviewElement, TableHandleDragPreviewEvents, TableHandleDragPreviewProps, TableHandleDropIndicatorElement, TableHandleDropIndicatorEvents, TableHandleDropIndicatorProps, TableHandlePopoverContentElement, TableHandlePopoverContentEvents, TableHandlePopoverContentProps, TableHandlePopoverItemElement, TableHandlePopoverItemEvents, TableHandlePopoverItemProps, TableHandleRootElement, TableHandleRootEvents, TableHandleRootProps, TableHandleRowRootElement, TableHandleRowRootEvents, TableHandleRowRootProps, TableHandleRowTriggerElement, TableHandleRowTriggerEvents, TableHandleRowTriggerProps, 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 };
|
|
271
|
+
export { TableHandleColumnRootElement, type TableHandleColumnRootEvents, type TableHandleColumnRootProps, TableHandleColumnTriggerElement, type TableHandleColumnTriggerEvents, type TableHandleColumnTriggerProps, TableHandleDragPreviewElement, type TableHandleDragPreviewEvents, type TableHandleDragPreviewProps, TableHandleDropIndicatorElement, type TableHandleDropIndicatorEvents, type TableHandleDropIndicatorProps, TableHandlePopoverContentElement, type TableHandlePopoverContentEvents, type TableHandlePopoverContentProps, TableHandlePopoverItemElement, type TableHandlePopoverItemEvents, type TableHandlePopoverItemProps, TableHandleRootElement, type TableHandleRootEvents, type TableHandleRootProps, TableHandleRowRootElement, type TableHandleRowRootEvents, type TableHandleRowRootProps, TableHandleRowTriggerElement, type TableHandleRowTriggerEvents, type TableHandleRowTriggerProps, 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 };
|
|
@@ -1,5 +1,7 @@
|
|
|
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 } from "./assign-styles-3yY6F1UX.js";
|
|
4
|
+
import { cloneElement, deepCloneElement } from "./clone-element-i6RFnyj4.js";
|
|
3
5
|
import { createComputed, createContext, createSignal, defineCustomElement, defineEmit, registerCustomElement, useAttribute, useEffect, useEventListener } from "@aria-ui/core";
|
|
4
6
|
import { defineDOMEventHandler, union } from "@prosekit/core";
|
|
5
7
|
import { useOverlayPositionerState } from "@aria-ui/overlay/elements";
|
|
@@ -74,7 +76,8 @@ function useTableHandleColumnRoot(host, { state }) {
|
|
|
74
76
|
const tableHandleColumnRootProps = Object.freeze({
|
|
75
77
|
...overlayPositionerProps$1,
|
|
76
78
|
editor: { default: null },
|
|
77
|
-
placement: { default: "top" }
|
|
79
|
+
placement: { default: "top" },
|
|
80
|
+
hoist: { default: false }
|
|
78
81
|
});
|
|
79
82
|
/** @internal */
|
|
80
83
|
const tableHandleColumnRootEvents = overlayPositionerEvents$1;
|
|
@@ -141,8 +144,8 @@ function useTableHandleColumnTrigger(host, { state }) {
|
|
|
141
144
|
if (emptyImage) dataTransfer.setDragImage(emptyImage, 0, 0);
|
|
142
145
|
}
|
|
143
146
|
const prev = dndContext.peek();
|
|
144
|
-
const index = context.peek()?.colIndex
|
|
145
|
-
if (index < 0) {
|
|
147
|
+
const index = context.peek()?.colIndex;
|
|
148
|
+
if (index == null || index < 0) {
|
|
146
149
|
console.warn("[prosekit] Invalid column index for drag operation:", index);
|
|
147
150
|
event.preventDefault();
|
|
148
151
|
return;
|
|
@@ -239,7 +242,7 @@ function useInitDndPosition(host, editor, onInit) {
|
|
|
239
242
|
})]
|
|
240
243
|
}).then(({ x, y }) => {
|
|
241
244
|
if (cancelled) return;
|
|
242
|
-
|
|
245
|
+
assignStyles(host, {
|
|
243
246
|
left: `${x}px`,
|
|
244
247
|
top: `${y}px`
|
|
245
248
|
});
|
|
@@ -286,25 +289,45 @@ function clearPreviewDOM(previewRoot) {
|
|
|
286
289
|
}
|
|
287
290
|
function createPreviewDOM(table, previewRoot, index, direction) {
|
|
288
291
|
clearPreviewDOM(previewRoot);
|
|
289
|
-
const previewTable =
|
|
290
|
-
const
|
|
292
|
+
const previewTable = cloneElementWithoutSize(table);
|
|
293
|
+
const tableBody = table.querySelector("tbody");
|
|
294
|
+
const previewTableBody = tableBody ? cloneElementWithoutSize(tableBody) : table.ownerDocument.createElement("tbody");
|
|
295
|
+
unsetSize(previewTableBody);
|
|
296
|
+
unsetSize(previewTable);
|
|
291
297
|
previewTable.appendChild(previewTableBody);
|
|
292
298
|
previewRoot.appendChild(previewTable);
|
|
293
299
|
const rows = table.querySelectorAll("tr");
|
|
294
300
|
if (direction === "row") {
|
|
295
301
|
const row = rows[index];
|
|
296
|
-
const
|
|
297
|
-
previewTableBody.appendChild(
|
|
302
|
+
const previewRow = deepCloneElement(row);
|
|
303
|
+
previewTableBody.appendChild(previewRow);
|
|
298
304
|
} else rows.forEach((row) => {
|
|
299
|
-
const
|
|
305
|
+
const previewRow = cloneElementWithoutSize(row);
|
|
306
|
+
unsetSize(previewRow);
|
|
300
307
|
const cells = row.querySelectorAll("td");
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
308
|
+
const cell = cells[index];
|
|
309
|
+
if (cell) {
|
|
310
|
+
const previewCell = deepCloneElement(cell);
|
|
311
|
+
previewRow.appendChild(previewCell);
|
|
312
|
+
previewTableBody.appendChild(previewRow);
|
|
305
313
|
}
|
|
306
314
|
});
|
|
307
315
|
}
|
|
316
|
+
function cloneElementWithoutSize(element) {
|
|
317
|
+
const clonedElement = cloneElement(element);
|
|
318
|
+
unsetSize(clonedElement);
|
|
319
|
+
return clonedElement;
|
|
320
|
+
}
|
|
321
|
+
function unsetSize(element) {
|
|
322
|
+
assignStyles(element, {
|
|
323
|
+
width: "unset",
|
|
324
|
+
height: "unset",
|
|
325
|
+
minWidth: "unset",
|
|
326
|
+
minHeight: "unset",
|
|
327
|
+
maxWidth: "unset",
|
|
328
|
+
maxHeight: "unset"
|
|
329
|
+
});
|
|
330
|
+
}
|
|
308
331
|
|
|
309
332
|
//#endregion
|
|
310
333
|
//#region src/components/table-handle/table-handle-drag-preview/updater.ts
|
|
@@ -337,11 +360,11 @@ function useUpdatePreviewPosition(host, editor) {
|
|
|
337
360
|
computePosition(getVirtualElement(cell, x, y), host, { placement: direction === "row" ? "right" : "bottom" }).then(({ x: x$1, y: y$1 }) => {
|
|
338
361
|
if (cancelled) return;
|
|
339
362
|
if (direction === "row") {
|
|
340
|
-
|
|
363
|
+
assignStyles(host, { top: `${y$1}px` });
|
|
341
364
|
return;
|
|
342
365
|
}
|
|
343
366
|
if (direction === "col") {
|
|
344
|
-
|
|
367
|
+
assignStyles(host, { left: `${x$1}px` });
|
|
345
368
|
return;
|
|
346
369
|
}
|
|
347
370
|
});
|
|
@@ -377,8 +400,7 @@ function getVirtualElement(cell, x, y) {
|
|
|
377
400
|
function useTableHandleDragPreview(host, { state }) {
|
|
378
401
|
const { editor } = state;
|
|
379
402
|
useEffect(host, () => {
|
|
380
|
-
host
|
|
381
|
-
Object.assign(host.style, {
|
|
403
|
+
assignStyles(host, {
|
|
382
404
|
position: "absolute",
|
|
383
405
|
pointerEvents: "none"
|
|
384
406
|
});
|
|
@@ -387,7 +409,7 @@ function useTableHandleDragPreview(host, { state }) {
|
|
|
387
409
|
useUpdatePreviewPosition(host, editor);
|
|
388
410
|
}
|
|
389
411
|
function onInitPreviewPosition({ host, direction, dragging, table, cell, draggingIndex }) {
|
|
390
|
-
|
|
412
|
+
assignStyles(host, { display: dragging ? "block" : "none" });
|
|
391
413
|
if (!dragging) {
|
|
392
414
|
clearPreviewDOM(host);
|
|
393
415
|
return;
|
|
@@ -395,11 +417,11 @@ function onInitPreviewPosition({ host, direction, dragging, table, cell, draggin
|
|
|
395
417
|
createPreviewDOM(table, host, draggingIndex, direction);
|
|
396
418
|
const tableRect = table.getBoundingClientRect();
|
|
397
419
|
const cellRect = cell.getBoundingClientRect();
|
|
398
|
-
if (direction === "col")
|
|
420
|
+
if (direction === "col") assignStyles(host, {
|
|
399
421
|
width: `${cellRect.width}px`,
|
|
400
422
|
height: `${tableRect.height}px`
|
|
401
423
|
});
|
|
402
|
-
if (direction === "row")
|
|
424
|
+
if (direction === "row") assignStyles(host, {
|
|
403
425
|
width: `${tableRect.width}px`,
|
|
404
426
|
height: `${cellRect.height}px`
|
|
405
427
|
});
|
|
@@ -499,7 +521,7 @@ function useUpdateIndicatorPosition(host, editor, handleWidth) {
|
|
|
499
521
|
middleware: [offset(direction$1 === "left" ? -1 * handleWidth : 0)]
|
|
500
522
|
}).then(({ x: x$1 }) => {
|
|
501
523
|
if (cancelled) return;
|
|
502
|
-
|
|
524
|
+
assignStyles(host, { left: `${x$1}px` });
|
|
503
525
|
});
|
|
504
526
|
}
|
|
505
527
|
return cleanup;
|
|
@@ -518,7 +540,7 @@ function useUpdateIndicatorPosition(host, editor, handleWidth) {
|
|
|
518
540
|
middleware: [offset(direction$1 === "up" ? -1 * handleWidth : 0)]
|
|
519
541
|
}).then(({ y: y$1 }) => {
|
|
520
542
|
if (cancelled) return;
|
|
521
|
-
|
|
543
|
+
assignStyles(host, { top: `${y$1}px` });
|
|
522
544
|
});
|
|
523
545
|
}
|
|
524
546
|
return cleanup;
|
|
@@ -535,7 +557,7 @@ const HANDLE_WIDTH = 2;
|
|
|
535
557
|
function useTableHandleDropIndicator(host, { state }) {
|
|
536
558
|
const { editor } = state;
|
|
537
559
|
useEffect(host, () => {
|
|
538
|
-
|
|
560
|
+
assignStyles(host, {
|
|
539
561
|
pointerEvents: "none",
|
|
540
562
|
position: "absolute"
|
|
541
563
|
});
|
|
@@ -544,13 +566,13 @@ function useTableHandleDropIndicator(host, { state }) {
|
|
|
544
566
|
useUpdateIndicatorPosition(host, editor, HANDLE_WIDTH);
|
|
545
567
|
}
|
|
546
568
|
function onInitIndicatorPosition({ host, direction, dragging, table }) {
|
|
547
|
-
|
|
569
|
+
assignStyles(host, { display: dragging ? "block" : "none" });
|
|
548
570
|
const tableRect = table.getBoundingClientRect();
|
|
549
|
-
if (direction === "col")
|
|
571
|
+
if (direction === "col") assignStyles(host, {
|
|
550
572
|
width: `${HANDLE_WIDTH}px`,
|
|
551
573
|
height: `${tableRect.height}px`
|
|
552
574
|
});
|
|
553
|
-
if (direction === "row")
|
|
575
|
+
if (direction === "row") assignStyles(host, {
|
|
554
576
|
width: `${tableRect.width}px`,
|
|
555
577
|
height: `${HANDLE_WIDTH}px`
|
|
556
578
|
});
|
|
@@ -904,7 +926,8 @@ function useTableHandleRowRoot(host, { state }) {
|
|
|
904
926
|
const tableHandleRowRootProps = {
|
|
905
927
|
...overlayPositionerProps$1,
|
|
906
928
|
editor: { default: null },
|
|
907
|
-
placement: { default: "left" }
|
|
929
|
+
placement: { default: "left" },
|
|
930
|
+
hoist: { default: false }
|
|
908
931
|
};
|
|
909
932
|
/** @internal */
|
|
910
933
|
const tableHandleRowRootEvents = {};
|
|
@@ -946,8 +969,8 @@ function useTableHandleRowTrigger(host, { state }) {
|
|
|
946
969
|
if (emptyImage) dataTransfer.setDragImage(emptyImage, 0, 0);
|
|
947
970
|
}
|
|
948
971
|
const prev = dndContext.peek();
|
|
949
|
-
const index = context.peek()?.rowIndex
|
|
950
|
-
if (index < 0) {
|
|
972
|
+
const index = context.peek()?.rowIndex;
|
|
973
|
+
if (index == null || index < 0) {
|
|
951
974
|
console.warn("[prosekit] Invalid row index for drag operation:", index);
|
|
952
975
|
event.preventDefault();
|
|
953
976
|
return;
|
|
@@ -25,4 +25,4 @@ interface TooltipTriggerEvents extends TooltipTriggerEvents$1 {}
|
|
|
25
25
|
declare const TooltipTriggerElementBase: BaseElementConstructor<TooltipTriggerProps>;
|
|
26
26
|
declare class TooltipTriggerElement extends TooltipTriggerElementBase {}
|
|
27
27
|
//#endregion
|
|
28
|
-
export { TooltipContentElement, TooltipContentEvents, TooltipContentProps, TooltipRootElement, TooltipRootEvents, TooltipRootProps, TooltipTriggerElement, TooltipTriggerEvents, TooltipTriggerProps, tooltipContentEvents, tooltipContentProps, tooltipRootEvents, tooltipRootProps, tooltipTriggerEvents, tooltipTriggerProps, useTooltipContent, useTooltipRoot, useTooltipTrigger };
|
|
28
|
+
export { TooltipContentElement, type TooltipContentEvents, type TooltipContentProps, TooltipRootElement, type TooltipRootEvents, type TooltipRootProps, TooltipTriggerElement, type TooltipTriggerEvents, type TooltipTriggerProps, tooltipContentEvents, tooltipContentProps, tooltipRootEvents, tooltipRootProps, tooltipTriggerEvents, tooltipTriggerProps, useTooltipContent, useTooltipRoot, useTooltipTrigger };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosekit/web",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "A collection of web components for ProseKit",
|
|
7
7
|
"author": {
|
|
@@ -38,6 +38,10 @@
|
|
|
38
38
|
"types": "./dist/prosekit-web-block-handle.d.ts",
|
|
39
39
|
"default": "./dist/prosekit-web-block-handle.js"
|
|
40
40
|
},
|
|
41
|
+
"./drop-indicator": {
|
|
42
|
+
"types": "./dist/prosekit-web-drop-indicator.d.ts",
|
|
43
|
+
"default": "./dist/prosekit-web-drop-indicator.js"
|
|
44
|
+
},
|
|
41
45
|
"./inline-popover": {
|
|
42
46
|
"types": "./dist/prosekit-web-inline-popover.d.ts",
|
|
43
47
|
"default": "./dist/prosekit-web-inline-popover.js"
|
|
@@ -71,19 +75,19 @@
|
|
|
71
75
|
"@aria-ui/popover": "^0.0.27",
|
|
72
76
|
"@aria-ui/presence": "^0.0.19",
|
|
73
77
|
"@aria-ui/tooltip": "^0.0.29",
|
|
74
|
-
"@floating-ui/dom": "^1.7.
|
|
75
|
-
"@ocavue/utils": "^0.
|
|
78
|
+
"@floating-ui/dom": "^1.7.3",
|
|
79
|
+
"@ocavue/utils": "^0.6.0",
|
|
76
80
|
"prosemirror-tables": "^1.7.1",
|
|
77
|
-
"@prosekit/
|
|
81
|
+
"@prosekit/core": "^0.8.3",
|
|
78
82
|
"@prosekit/pm": "^0.1.11",
|
|
79
|
-
"@prosekit/
|
|
83
|
+
"@prosekit/extensions": "^0.11.0"
|
|
80
84
|
},
|
|
81
85
|
"devDependencies": {
|
|
82
|
-
"tsdown": "^0.
|
|
86
|
+
"tsdown": "^0.13.1",
|
|
83
87
|
"typescript": "~5.8.3",
|
|
84
88
|
"vitest": "^3.2.4",
|
|
85
|
-
"@prosekit/config-
|
|
86
|
-
"@prosekit/config-
|
|
89
|
+
"@prosekit/config-tsdown": "0.0.0",
|
|
90
|
+
"@prosekit/config-vitest": "0.0.0"
|
|
87
91
|
},
|
|
88
92
|
"publishConfig": {
|
|
89
93
|
"dev": {}
|
|
@@ -97,7 +101,8 @@
|
|
|
97
101
|
"prosekit-web-popover": "./src/components/popover/index.gen.ts",
|
|
98
102
|
"prosekit-web-resizable": "./src/components/resizable/index.gen.ts",
|
|
99
103
|
"prosekit-web-table-handle": "./src/components/table-handle/index.gen.ts",
|
|
100
|
-
"prosekit-web-tooltip": "./src/components/tooltip/index.gen.ts"
|
|
104
|
+
"prosekit-web-tooltip": "./src/components/tooltip/index.gen.ts",
|
|
105
|
+
"prosekit-web-drop-indicator": "./src/components/drop-indicator/index.gen.ts"
|
|
101
106
|
}
|
|
102
107
|
},
|
|
103
108
|
"scripts": {
|
|
@@ -116,6 +121,9 @@
|
|
|
116
121
|
"block-handle": [
|
|
117
122
|
"./dist/prosekit-web-block-handle.d.ts"
|
|
118
123
|
],
|
|
124
|
+
"drop-indicator": [
|
|
125
|
+
"./dist/prosekit-web-drop-indicator.d.ts"
|
|
126
|
+
],
|
|
119
127
|
"inline-popover": [
|
|
120
128
|
"./dist/prosekit-web-inline-popover.d.ts"
|
|
121
129
|
],
|