@prosekit/web 0.7.0 → 0.7.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/{clone-element-i6RFnyj4.js → clone-element-CwLKm7c_.js} +1 -1
- package/dist/{get-safe-editor-view-CqJWgxo1.js → get-default-state-CIEy7xrl.js} +1 -11
- package/dist/get-safe-editor-view-DENm4avv.js +11 -0
- package/dist/prosekit-web-autocomplete.js +2 -1
- package/dist/prosekit-web-block-handle.d.ts +16 -1
- package/dist/prosekit-web-block-handle.js +84 -66
- package/dist/prosekit-web-drop-indicator.js +5 -2
- package/dist/prosekit-web-table-handle.d.ts +32 -2
- package/dist/prosekit-web-table-handle.js +54 -36
- package/dist/use-scrolling-BNfsQs3S.js +35 -0
- package/package.json +9 -8
- package/dist/assign-styles-3yY6F1UX.js +0 -10
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region src/utils/clone-element.ts
|
|
2
2
|
/**
|
|
3
3
|
* Creates a deep clone of an Element, including all computed styles so that
|
|
4
|
-
* it looks the same as the original element.
|
|
4
|
+
* it looks almost exactly the same as the original element.
|
|
5
5
|
*/
|
|
6
6
|
function deepCloneElement(element) {
|
|
7
7
|
const clonedElement = element.cloneNode(true);
|
|
@@ -8,14 +8,4 @@ function getStateWithDefaults(state, props) {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
//#endregion
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @internal
|
|
14
|
-
*/
|
|
15
|
-
function getSafeEditorView(editor) {
|
|
16
|
-
if (!editor || !editor.mounted) return;
|
|
17
|
-
return editor.view;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
//#endregion
|
|
21
|
-
export { getSafeEditorView, getStateWithDefaults };
|
|
11
|
+
export { getStateWithDefaults };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getStateWithDefaults } from "./get-default-state-CIEy7xrl.js";
|
|
2
2
|
import { useEditorExtension } from "./use-editor-extension-Cc7ZG7uj.js";
|
|
3
|
+
import { getSafeEditorView } from "./get-safe-editor-view-DENm4avv.js";
|
|
3
4
|
import { createComputed, createContext, createSignal, defineCustomElement, registerCustomElement, useAnimationFrame, useAttribute, useEffect, useEventListener } from "@aria-ui/core";
|
|
4
5
|
import { listboxProps, useListbox, useListboxEmpty, useListboxItem } from "@aria-ui/listbox/elements";
|
|
5
6
|
import { listboxEvents, listboxItemEvents, listboxProps as listboxProps$1 } from "@aria-ui/listbox";
|
|
@@ -67,7 +67,7 @@ declare function useBlockHandleDraggable(host: ConnectableElement, {
|
|
|
67
67
|
}): void;
|
|
68
68
|
//#endregion
|
|
69
69
|
//#region src/components/block-handle/block-handle-popover/types.d.ts
|
|
70
|
-
interface BlockHandlePopoverProps extends Omit<OverlayPositionerProps, "placement" | "hoist"> {
|
|
70
|
+
interface BlockHandlePopoverProps extends Omit<OverlayPositionerProps, "placement" | "hoist" | "flip" | "shift" | "hide"> {
|
|
71
71
|
/**
|
|
72
72
|
* The ProseKit editor instance.
|
|
73
73
|
*
|
|
@@ -88,6 +88,21 @@ interface BlockHandlePopoverProps extends Omit<OverlayPositionerProps, "placemen
|
|
|
88
88
|
* @default false
|
|
89
89
|
*/
|
|
90
90
|
hoist: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* @default false
|
|
93
|
+
* @hidden
|
|
94
|
+
*/
|
|
95
|
+
flip: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* @default false
|
|
98
|
+
* @hidden
|
|
99
|
+
*/
|
|
100
|
+
shift: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* @default true
|
|
103
|
+
* @hidden
|
|
104
|
+
*/
|
|
105
|
+
hide: boolean;
|
|
91
106
|
}
|
|
92
107
|
/** @internal */
|
|
93
108
|
declare const blockHandlePopoverProps: PropDeclarations<BlockHandlePopoverProps>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useEditorExtension } from "./use-editor-extension-Cc7ZG7uj.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { getSafeEditorView } from "./get-safe-editor-view-DENm4avv.js";
|
|
3
|
+
import { assignStyles, useScrolling } from "./use-scrolling-BNfsQs3S.js";
|
|
4
|
+
import { deepCloneElement } from "./clone-element-CwLKm7c_.js";
|
|
4
5
|
import { createComputed, createContext, createSignal, defineCustomElement, registerCustomElement, useAttribute, useEffect, useEventListener } from "@aria-ui/core";
|
|
5
6
|
import { defineDOMEventHandler, insertDefaultBlock, union } from "@prosekit/core";
|
|
6
7
|
import { overlayPositionerEvents, overlayPositionerProps, useOverlayPositionerState } from "@aria-ui/overlay/elements";
|
|
@@ -55,6 +56,38 @@ const BlockHandleAddElementBase = defineCustomElement({
|
|
|
55
56
|
var BlockHandleAddElement = class extends BlockHandleAddElementBase {};
|
|
56
57
|
registerCustomElement("prosekit-block-handle-add", BlockHandleAddElement);
|
|
57
58
|
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/utils/get-client-rect.ts
|
|
61
|
+
/**
|
|
62
|
+
* Similar to `element.getBoundingClientRect`, but handles `display: contents` elements.
|
|
63
|
+
*/
|
|
64
|
+
function getClientRect(element) {
|
|
65
|
+
const rect = element.getBoundingClientRect();
|
|
66
|
+
if (rect.width === 0 && rect.height === 0 && rect.x === 0 && rect.y === 0) {
|
|
67
|
+
if (element.getClientRects().length === 0) {
|
|
68
|
+
const children = Array.from(element.children);
|
|
69
|
+
const rects = children.map((child) => getClientRect(child));
|
|
70
|
+
if (rects.length === 0) return rect;
|
|
71
|
+
if (rects.length === 1) return rects[0];
|
|
72
|
+
let { top, bottom, left, right } = rects[0];
|
|
73
|
+
for (let i = 1; i < rects.length; i++) {
|
|
74
|
+
const r = rects[i];
|
|
75
|
+
if (r.top < top) top = r.top;
|
|
76
|
+
if (r.bottom > bottom) bottom = r.bottom;
|
|
77
|
+
if (r.left < left) left = r.left;
|
|
78
|
+
if (r.right > right) right = r.right;
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
top,
|
|
82
|
+
bottom,
|
|
83
|
+
left,
|
|
84
|
+
right
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return rect;
|
|
89
|
+
}
|
|
90
|
+
|
|
58
91
|
//#endregion
|
|
59
92
|
//#region src/utils/max-z-index.ts
|
|
60
93
|
const maxZIndex = "2147483647";
|
|
@@ -73,8 +106,11 @@ const maxZIndex = "2147483647";
|
|
|
73
106
|
* - Removes the container from the document body after the next frame.
|
|
74
107
|
*/
|
|
75
108
|
function setDragPreview(event, element) {
|
|
76
|
-
const
|
|
77
|
-
const
|
|
109
|
+
const { top, bottom, left, right } = getClientRect(element);
|
|
110
|
+
const width = right - left;
|
|
111
|
+
const height = bottom - top;
|
|
112
|
+
const elementX = left;
|
|
113
|
+
const elementY = top;
|
|
78
114
|
const { clientX, clientY } = event;
|
|
79
115
|
const document = element.ownerDocument;
|
|
80
116
|
const container = document.createElement("div");
|
|
@@ -95,8 +131,8 @@ function setDragPreview(event, element) {
|
|
|
95
131
|
});
|
|
96
132
|
const clonedElement = deepCloneElement(element);
|
|
97
133
|
assignStyles(clonedElement, {
|
|
98
|
-
|
|
99
|
-
|
|
134
|
+
opacity: "0.5",
|
|
135
|
+
margin: "0"
|
|
100
136
|
});
|
|
101
137
|
document.body.appendChild(container);
|
|
102
138
|
container.appendChild(clonedElement);
|
|
@@ -113,12 +149,27 @@ function setDragPreview(event, element) {
|
|
|
113
149
|
*/
|
|
114
150
|
function useBlockHandleDraggable(host, { state }) {
|
|
115
151
|
const context = blockPopoverContext.consume(host);
|
|
152
|
+
const dragging = draggingContext.consume(host);
|
|
116
153
|
useEffect(host, () => {
|
|
117
154
|
host.draggable = true;
|
|
118
155
|
});
|
|
119
156
|
usePointerDownHandler(host, context, state.editor);
|
|
120
|
-
|
|
121
|
-
|
|
157
|
+
useEventListener(host, "dragstart", (event) => {
|
|
158
|
+
dragging.set(true);
|
|
159
|
+
const view = getSafeEditorView(state.editor.get());
|
|
160
|
+
const hoverState = context.get();
|
|
161
|
+
if (view && hoverState) {
|
|
162
|
+
view.dom.classList.add("prosekit-dragging");
|
|
163
|
+
createDraggingPreview(view, hoverState, event);
|
|
164
|
+
setViewDragging(view, hoverState);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
useEventListener(host, "dragend", () => {
|
|
168
|
+
dragging.set(false);
|
|
169
|
+
const view = getSafeEditorView(state.editor.get());
|
|
170
|
+
if (view) view.dom.classList.remove("prosekit-dragging");
|
|
171
|
+
});
|
|
172
|
+
useAttribute(host, "data-dragging", () => dragging.get() ? "" : void 0);
|
|
122
173
|
}
|
|
123
174
|
function usePointerDownHandler(host, context, editor) {
|
|
124
175
|
useEventListener(host, "pointerdown", () => {
|
|
@@ -131,39 +182,24 @@ function usePointerDownHandler(host, context, editor) {
|
|
|
131
182
|
});
|
|
132
183
|
});
|
|
133
184
|
}
|
|
134
|
-
function
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
event.dataTransfer.setData("text/html", element.outerHTML);
|
|
144
|
-
event.dataTransfer.effectAllowed = "copyMove";
|
|
145
|
-
setDragPreview(event, element);
|
|
146
|
-
const dragging = {
|
|
147
|
-
slice: new Slice(Fragment.from(node), 0, 0),
|
|
148
|
-
move: true,
|
|
149
|
-
node: NodeSelection.create(view.state.doc, pos)
|
|
150
|
-
};
|
|
151
|
-
view.dragging = dragging;
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
function useDataDraggingAttribute(host) {
|
|
155
|
-
const dragging = useDragging(host);
|
|
156
|
-
useAttribute(host, "data-dragging", () => dragging.get() ? "" : void 0);
|
|
185
|
+
function createDraggingPreview(view, hoverState, event) {
|
|
186
|
+
if (!event.dataTransfer) return;
|
|
187
|
+
const { pos } = hoverState;
|
|
188
|
+
const element = view.nodeDOM(pos);
|
|
189
|
+
if (!element || !isHTMLElement(element)) return;
|
|
190
|
+
event.dataTransfer.clearData();
|
|
191
|
+
event.dataTransfer.setData("text/html", element.outerHTML);
|
|
192
|
+
event.dataTransfer.effectAllowed = "copyMove";
|
|
193
|
+
setDragPreview(event, element);
|
|
157
194
|
}
|
|
158
|
-
function
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
return dragging;
|
|
195
|
+
function setViewDragging(view, hoverState) {
|
|
196
|
+
const { node, pos } = hoverState;
|
|
197
|
+
const dragging = {
|
|
198
|
+
slice: new Slice(Fragment.from(node), 0, 0),
|
|
199
|
+
move: true,
|
|
200
|
+
node: NodeSelection.create(view.state.doc, pos)
|
|
201
|
+
};
|
|
202
|
+
view.dragging = dragging;
|
|
167
203
|
}
|
|
168
204
|
|
|
169
205
|
//#endregion
|
|
@@ -183,30 +219,6 @@ const BlockHandleDraggableElementBase = defineCustomElement({
|
|
|
183
219
|
var BlockHandleDraggableElement = class extends BlockHandleDraggableElementBase {};
|
|
184
220
|
registerCustomElement("prosekit-block-handle-draggable", BlockHandleDraggableElement);
|
|
185
221
|
|
|
186
|
-
//#endregion
|
|
187
|
-
//#region src/utils/get-client-rect.ts
|
|
188
|
-
/**
|
|
189
|
-
* Similar to `element.getBoundingClientRect`, but handles `display: contents` elements.
|
|
190
|
-
*/
|
|
191
|
-
function getClientRect(element) {
|
|
192
|
-
const rect = element.getBoundingClientRect();
|
|
193
|
-
if (rect.width === 0 && rect.height === 0 && rect.x === 0 && rect.y === 0) {
|
|
194
|
-
if (element.getClientRects().length === 0) {
|
|
195
|
-
const children = Array.from(element.children);
|
|
196
|
-
const rects = children.map((child) => getClientRect(child));
|
|
197
|
-
if (rects.length === 0) return rect;
|
|
198
|
-
if (rects.length === 1) return rects[0];
|
|
199
|
-
return {
|
|
200
|
-
top: Math.min(...rects.map((rect$1) => rect$1.top)),
|
|
201
|
-
right: Math.max(...rects.map((rect$1) => rect$1.right)),
|
|
202
|
-
bottom: Math.max(...rects.map((rect$1) => rect$1.bottom)),
|
|
203
|
-
left: Math.min(...rects.map((rect$1) => rect$1.left))
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
return rect;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
222
|
//#endregion
|
|
211
223
|
//#region src/utils/throttle.ts
|
|
212
224
|
/**
|
|
@@ -409,7 +421,10 @@ function useBlockHandlePopover(host, { state, emit }) {
|
|
|
409
421
|
blockPopoverContext.provide(host, context);
|
|
410
422
|
const dragging = createSignal(false);
|
|
411
423
|
draggingContext.provide(host, dragging);
|
|
412
|
-
const
|
|
424
|
+
const scrolling = useScrolling(host);
|
|
425
|
+
const open = createComputed(() => {
|
|
426
|
+
return !!context.get() && !scrolling.get();
|
|
427
|
+
});
|
|
413
428
|
useHoverExtension(host, editor, (referenceValue, hoverState) => {
|
|
414
429
|
reference.set(referenceValue);
|
|
415
430
|
context.set(hoverState);
|
|
@@ -444,7 +459,10 @@ const blockHandlePopoverProps = {
|
|
|
444
459
|
...overlayPositionerProps,
|
|
445
460
|
editor: { default: null },
|
|
446
461
|
placement: { default: "left" },
|
|
447
|
-
hoist: { default: false }
|
|
462
|
+
hoist: { default: false },
|
|
463
|
+
flip: { default: false },
|
|
464
|
+
shift: { default: false },
|
|
465
|
+
hide: { default: true }
|
|
448
466
|
};
|
|
449
467
|
/** @internal */
|
|
450
468
|
const blockHandlePopoverEvents = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEditorExtension } from "./use-editor-extension-Cc7ZG7uj.js";
|
|
2
|
-
import { assignStyles } from "./
|
|
2
|
+
import { assignStyles, useScrolling } from "./use-scrolling-BNfsQs3S.js";
|
|
3
3
|
import { createComputed, createSignal, defineCustomElement, registerCustomElement, useEffect } from "@aria-ui/core";
|
|
4
4
|
import { usePresence } from "@aria-ui/presence";
|
|
5
5
|
import { defineDropIndicator } from "@prosekit/extensions/drop-indicator";
|
|
@@ -16,7 +16,10 @@ function useDropIndicator(host, { state }) {
|
|
|
16
16
|
});
|
|
17
17
|
useEditorExtension(host, state.editor, extension);
|
|
18
18
|
const line = createComputed(() => context.get()?.line);
|
|
19
|
-
const
|
|
19
|
+
const scrolling = useScrolling(host);
|
|
20
|
+
const presence = createComputed(() => {
|
|
21
|
+
return !!context.get() && !scrolling.get();
|
|
22
|
+
});
|
|
20
23
|
usePresence(host, presence);
|
|
21
24
|
useEffect(host, () => {
|
|
22
25
|
const lineValue = line.get();
|
|
@@ -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" | "hoist"> {
|
|
10
|
+
interface TableHandleColumnRootProps extends Omit<OverlayPositionerProps, "placement" | "hoist" | "flip" | "shift" | "hide"> {
|
|
11
11
|
/**
|
|
12
12
|
* The ProseKit editor instance.
|
|
13
13
|
*
|
|
@@ -28,6 +28,21 @@ interface TableHandleColumnRootProps extends Omit<OverlayPositionerProps, "place
|
|
|
28
28
|
* @default false
|
|
29
29
|
*/
|
|
30
30
|
hoist: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* @default false
|
|
33
|
+
* @hidden
|
|
34
|
+
*/
|
|
35
|
+
flip: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* @default false
|
|
38
|
+
* @hidden
|
|
39
|
+
*/
|
|
40
|
+
shift: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* @default true
|
|
43
|
+
* @hidden
|
|
44
|
+
*/
|
|
45
|
+
hide: boolean;
|
|
31
46
|
}
|
|
32
47
|
/** @internal */
|
|
33
48
|
declare const tableHandleColumnRootProps: PropDeclarations<TableHandleColumnRootProps>;
|
|
@@ -202,7 +217,7 @@ declare function useTableHandleRoot(host: ConnectableElement, {
|
|
|
202
217
|
}): void;
|
|
203
218
|
//#endregion
|
|
204
219
|
//#region src/components/table-handle/table-handle-row-root/types.d.ts
|
|
205
|
-
interface TableHandleRowRootProps extends Omit<OverlayPositionerProps, "placement" | "hoist"> {
|
|
220
|
+
interface TableHandleRowRootProps extends Omit<OverlayPositionerProps, "placement" | "hoist" | "flip" | "shift" | "hide"> {
|
|
206
221
|
/**
|
|
207
222
|
* The ProseKit editor instance.
|
|
208
223
|
*
|
|
@@ -223,6 +238,21 @@ interface TableHandleRowRootProps extends Omit<OverlayPositionerProps, "placemen
|
|
|
223
238
|
* @default false
|
|
224
239
|
*/
|
|
225
240
|
hoist: boolean;
|
|
241
|
+
/**
|
|
242
|
+
* @default false
|
|
243
|
+
* @hidden
|
|
244
|
+
*/
|
|
245
|
+
flip: boolean;
|
|
246
|
+
/**
|
|
247
|
+
* @default false
|
|
248
|
+
* @hidden
|
|
249
|
+
*/
|
|
250
|
+
shift: boolean;
|
|
251
|
+
/**
|
|
252
|
+
* @default true
|
|
253
|
+
* @hidden
|
|
254
|
+
*/
|
|
255
|
+
hide: boolean;
|
|
226
256
|
}
|
|
227
257
|
/** @internal */
|
|
228
258
|
declare const tableHandleRowRootProps: PropDeclarations<TableHandleRowRootProps>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getStateWithDefaults } from "./get-default-state-CIEy7xrl.js";
|
|
2
2
|
import { useEditorExtension } from "./use-editor-extension-Cc7ZG7uj.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { getSafeEditorView } from "./get-safe-editor-view-DENm4avv.js";
|
|
4
|
+
import { assignStyles, useScrolling } from "./use-scrolling-BNfsQs3S.js";
|
|
5
|
+
import { cloneElement, deepCloneElement } from "./clone-element-CwLKm7c_.js";
|
|
5
6
|
import { createComputed, createContext, createSignal, defineCustomElement, defineEmit, registerCustomElement, useAttribute, useEffect, useEventListener } from "@aria-ui/core";
|
|
6
7
|
import { defineDOMEventHandler, union } from "@prosekit/core";
|
|
7
8
|
import { useOverlayPositionerState } from "@aria-ui/overlay/elements";
|
|
@@ -77,7 +78,10 @@ const tableHandleColumnRootProps = Object.freeze({
|
|
|
77
78
|
...overlayPositionerProps$1,
|
|
78
79
|
editor: { default: null },
|
|
79
80
|
placement: { default: "top" },
|
|
80
|
-
hoist: { default: false }
|
|
81
|
+
hoist: { default: false },
|
|
82
|
+
flip: { default: false },
|
|
83
|
+
shift: { default: false },
|
|
84
|
+
hide: { default: true }
|
|
81
85
|
});
|
|
82
86
|
/** @internal */
|
|
83
87
|
const tableHandleColumnRootEvents = overlayPositionerEvents$1;
|
|
@@ -706,6 +710,43 @@ function useEditorTyping(host, editor) {
|
|
|
706
710
|
return typing;
|
|
707
711
|
}
|
|
708
712
|
|
|
713
|
+
//#endregion
|
|
714
|
+
//#region src/hooks/use-selecting.ts
|
|
715
|
+
/**
|
|
716
|
+
* Detect if the user is selecting text inside the editor, in which case some
|
|
717
|
+
* components should be disabled or hidden.
|
|
718
|
+
*/
|
|
719
|
+
function useSelecting(host, editor, enabled) {
|
|
720
|
+
const selecting = createSignal(false);
|
|
721
|
+
const isPointerDown = createSignal(false);
|
|
722
|
+
useEffect(host, () => {
|
|
723
|
+
if (!enabled.get()) return;
|
|
724
|
+
const view = getSafeEditorView(editor.peek());
|
|
725
|
+
if (!view) return;
|
|
726
|
+
const { dom, root } = view;
|
|
727
|
+
if (!root) return;
|
|
728
|
+
const handlePointerDown = () => {
|
|
729
|
+
selecting.set(true);
|
|
730
|
+
isPointerDown.set(true);
|
|
731
|
+
};
|
|
732
|
+
const handlePointerUp = () => {
|
|
733
|
+
isPointerDown.set(false);
|
|
734
|
+
};
|
|
735
|
+
const handleMouseMove = () => {
|
|
736
|
+
if (!isPointerDown.get()) selecting.set(false);
|
|
737
|
+
};
|
|
738
|
+
dom.addEventListener("pointerdown", handlePointerDown);
|
|
739
|
+
root.addEventListener("pointerup", handlePointerUp);
|
|
740
|
+
root.addEventListener("pointermove", handleMouseMove);
|
|
741
|
+
return () => {
|
|
742
|
+
dom.removeEventListener("pointerdown", handlePointerDown);
|
|
743
|
+
root.removeEventListener("pointerup", handlePointerUp);
|
|
744
|
+
root.removeEventListener("pointermove", handleMouseMove);
|
|
745
|
+
};
|
|
746
|
+
});
|
|
747
|
+
return selecting;
|
|
748
|
+
}
|
|
749
|
+
|
|
709
750
|
//#endregion
|
|
710
751
|
//#region src/components/table-handle/hooks/use-drop.ts
|
|
711
752
|
function useDrop(host, editor, dndContext) {
|
|
@@ -816,11 +857,12 @@ function useTableHandleRoot(host, { state }) {
|
|
|
816
857
|
const typing = useEditorTyping(host, editor);
|
|
817
858
|
const isInTable = createComputed(() => !!hoveringCell.get());
|
|
818
859
|
const selecting = useSelecting(host, editor, isInTable);
|
|
860
|
+
const scrolling = useScrolling(host);
|
|
861
|
+
const canShow = createComputed(() => {
|
|
862
|
+
return !typing.get() && !selecting.get() && !scrolling.get();
|
|
863
|
+
});
|
|
819
864
|
useEffect(host, () => {
|
|
820
|
-
|
|
821
|
-
const selectingValue = selecting.get();
|
|
822
|
-
const hoveringCellValue = hoveringCell.get();
|
|
823
|
-
context.set(typingValue || selectingValue ? null : hoveringCellValue);
|
|
865
|
+
context.set(canShow.get() ? hoveringCell.get() : null);
|
|
824
866
|
});
|
|
825
867
|
tableHandleRootContext.provide(host, context);
|
|
826
868
|
tableHandleDndContext.provide(host, dndContext);
|
|
@@ -842,33 +884,6 @@ function defineCellHoverHandler(handler) {
|
|
|
842
884
|
};
|
|
843
885
|
return defineDOMEventHandler("pointerover", pointerHandler);
|
|
844
886
|
}
|
|
845
|
-
/**
|
|
846
|
-
* Detect if the user is selecting text by dragging.
|
|
847
|
-
*/
|
|
848
|
-
function useSelecting(host, editor, isInTable) {
|
|
849
|
-
const selecting = createSignal(false);
|
|
850
|
-
useEffect(host, () => {
|
|
851
|
-
if (!isInTable.get()) return;
|
|
852
|
-
const view = getSafeEditorView(editor.peek());
|
|
853
|
-
const root = view?.root;
|
|
854
|
-
if (!root) return;
|
|
855
|
-
const pointerDownHandler = (event) => {
|
|
856
|
-
const target = event.target;
|
|
857
|
-
if (!target || host.contains(event.target)) return;
|
|
858
|
-
selecting.set(true);
|
|
859
|
-
};
|
|
860
|
-
const pointerUpHandler = () => {
|
|
861
|
-
selecting.set(false);
|
|
862
|
-
};
|
|
863
|
-
root.addEventListener("pointerdown", pointerDownHandler);
|
|
864
|
-
root.addEventListener("pointerup", pointerUpHandler);
|
|
865
|
-
return () => {
|
|
866
|
-
root.removeEventListener("pointerdown", pointerDownHandler);
|
|
867
|
-
root.removeEventListener("pointerup", pointerUpHandler);
|
|
868
|
-
};
|
|
869
|
-
});
|
|
870
|
-
return selecting;
|
|
871
|
-
}
|
|
872
887
|
|
|
873
888
|
//#endregion
|
|
874
889
|
//#region src/components/table-handle/table-handle-root/types.ts
|
|
@@ -927,7 +942,10 @@ const tableHandleRowRootProps = {
|
|
|
927
942
|
...overlayPositionerProps$1,
|
|
928
943
|
editor: { default: null },
|
|
929
944
|
placement: { default: "left" },
|
|
930
|
-
hoist: { default: false }
|
|
945
|
+
hoist: { default: false },
|
|
946
|
+
flip: { default: false },
|
|
947
|
+
shift: { default: false },
|
|
948
|
+
hide: { default: true }
|
|
931
949
|
};
|
|
932
950
|
/** @internal */
|
|
933
951
|
const tableHandleRowRootEvents = {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createSignal, useEffect } from "@aria-ui/core";
|
|
2
|
+
import { getNearestOverflowAncestor } from "@zag-js/dom-query";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/assign-styles.ts
|
|
5
|
+
/**
|
|
6
|
+
* A type-safe version of `Object.assign` for `element.style`.
|
|
7
|
+
*/
|
|
8
|
+
function assignStyles(element, styles) {
|
|
9
|
+
Object.assign(element.style, styles);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/hooks/use-scrolling.ts
|
|
14
|
+
function useScrolling(host) {
|
|
15
|
+
const scrolling = createSignal(false);
|
|
16
|
+
useEffect(host, () => {
|
|
17
|
+
const scrollableParent = getNearestOverflowAncestor(host);
|
|
18
|
+
const handleScroll = () => {
|
|
19
|
+
scrolling.set(true);
|
|
20
|
+
};
|
|
21
|
+
const handleMouseMove = () => {
|
|
22
|
+
scrolling.set(false);
|
|
23
|
+
};
|
|
24
|
+
scrollableParent.addEventListener("scroll", handleScroll, { passive: true });
|
|
25
|
+
window.addEventListener("mousemove", handleMouseMove, { passive: true });
|
|
26
|
+
return () => {
|
|
27
|
+
scrollableParent.removeEventListener("scroll", handleScroll);
|
|
28
|
+
window.removeEventListener("mousemove", handleMouseMove);
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
return scrolling;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { assignStyles, useScrolling };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosekit/web",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "A collection of web components for ProseKit",
|
|
7
7
|
"author": {
|
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
},
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"funding": "https://github.com/sponsors/ocavue",
|
|
13
|
-
"homepage": "https://github.com/
|
|
13
|
+
"homepage": "https://github.com/prosekit/prosekit#readme",
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/
|
|
16
|
+
"url": "git+https://github.com/prosekit/prosekit.git",
|
|
17
17
|
"directory": "packages/web"
|
|
18
18
|
},
|
|
19
19
|
"bugs": {
|
|
20
|
-
"url": "https://github.com/
|
|
20
|
+
"url": "https://github.com/prosekit/prosekit/issues"
|
|
21
21
|
},
|
|
22
22
|
"keywords": [
|
|
23
23
|
"ProseMirror"
|
|
@@ -77,10 +77,11 @@
|
|
|
77
77
|
"@aria-ui/tooltip": "^0.0.29",
|
|
78
78
|
"@floating-ui/dom": "^1.7.3",
|
|
79
79
|
"@ocavue/utils": "^0.6.0",
|
|
80
|
+
"@zag-js/dom-query": "^1.21.1",
|
|
80
81
|
"prosemirror-tables": "^1.7.1",
|
|
81
82
|
"@prosekit/core": "^0.8.3",
|
|
82
|
-
"@prosekit/
|
|
83
|
-
"@prosekit/
|
|
83
|
+
"@prosekit/extensions": "^0.11.1",
|
|
84
|
+
"@prosekit/pm": "^0.1.11"
|
|
84
85
|
},
|
|
85
86
|
"devDependencies": {
|
|
86
87
|
"tsdown": "^0.13.1",
|
|
@@ -97,12 +98,12 @@
|
|
|
97
98
|
"prosekit-web": "./src/index.ts",
|
|
98
99
|
"prosekit-web-autocomplete": "./src/components/autocomplete/index.gen.ts",
|
|
99
100
|
"prosekit-web-block-handle": "./src/components/block-handle/index.gen.ts",
|
|
101
|
+
"prosekit-web-drop-indicator": "./src/components/drop-indicator/index.gen.ts",
|
|
100
102
|
"prosekit-web-inline-popover": "./src/components/inline-popover/index.gen.ts",
|
|
101
103
|
"prosekit-web-popover": "./src/components/popover/index.gen.ts",
|
|
102
104
|
"prosekit-web-resizable": "./src/components/resizable/index.gen.ts",
|
|
103
105
|
"prosekit-web-table-handle": "./src/components/table-handle/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"
|
|
106
|
+
"prosekit-web-tooltip": "./src/components/tooltip/index.gen.ts"
|
|
106
107
|
}
|
|
107
108
|
},
|
|
108
109
|
"scripts": {
|