@prosekit/web 0.7.2 → 0.7.3
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.
|
@@ -5,21 +5,21 @@ import { getDocument, getId } from "@ocavue/utils";
|
|
|
5
5
|
* Creates a deep clone of an Element, including all computed styles so that
|
|
6
6
|
* it looks almost exactly the same as the original element.
|
|
7
7
|
*/
|
|
8
|
-
function deepCloneElement(element) {
|
|
8
|
+
function deepCloneElement(element, important = false) {
|
|
9
9
|
const clonedElement = element.cloneNode(true);
|
|
10
|
-
const style = deepCopyStyles(element, clonedElement);
|
|
10
|
+
const style = deepCopyStyles(element, clonedElement, important);
|
|
11
11
|
return [clonedElement, style];
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Creates a clone of an Element, including all computed styles so that
|
|
15
15
|
* it looks similar enough to the original element.
|
|
16
16
|
*/
|
|
17
|
-
function cloneElement(element) {
|
|
17
|
+
function cloneElement(element, important = false) {
|
|
18
18
|
const clonedElement = element.cloneNode();
|
|
19
|
-
const style = copyStyles(element, clonedElement);
|
|
19
|
+
const style = copyStyles(element, clonedElement, important);
|
|
20
20
|
return [clonedElement, style];
|
|
21
21
|
}
|
|
22
|
-
function deepCopyStyles(source, target) {
|
|
22
|
+
function deepCopyStyles(source, target, important) {
|
|
23
23
|
const sources = [source];
|
|
24
24
|
const targets = [target];
|
|
25
25
|
const styles = [];
|
|
@@ -27,21 +27,21 @@ function deepCopyStyles(source, target) {
|
|
|
27
27
|
const source$1 = sources.pop();
|
|
28
28
|
const target$1 = targets.pop();
|
|
29
29
|
if (!source$1 || !target$1) break;
|
|
30
|
-
const style = copyStyles(source$1, target$1);
|
|
30
|
+
const style = copyStyles(source$1, target$1, important);
|
|
31
31
|
if (style) styles.push(style);
|
|
32
32
|
sources.push(...source$1.children);
|
|
33
33
|
targets.push(...target$1.children);
|
|
34
34
|
}
|
|
35
35
|
return styles.join("\n");
|
|
36
36
|
}
|
|
37
|
-
function copyStyles(source, target) {
|
|
37
|
+
function copyStyles(source, target, important) {
|
|
38
38
|
if (!source || !target) return "";
|
|
39
39
|
const view = source.ownerDocument?.defaultView;
|
|
40
40
|
if (!view) return "";
|
|
41
41
|
const sourceStyle = view.getComputedStyle(source);
|
|
42
42
|
const targetStyle = target.style;
|
|
43
43
|
if (!sourceStyle || !targetStyle) return "";
|
|
44
|
-
for (const key of sourceStyle) targetStyle.setProperty(key, sourceStyle.getPropertyValue(key), sourceStyle.getPropertyPriority(key));
|
|
44
|
+
for (const key of sourceStyle) targetStyle.setProperty(key, sourceStyle.getPropertyValue(key), important ? "important" : sourceStyle.getPropertyPriority(key) || "");
|
|
45
45
|
const styles = [];
|
|
46
46
|
for (const pseudoSelector of [":before", ":after"]) {
|
|
47
47
|
const sourcePseudoStyle = view.getComputedStyle(source, pseudoSelector);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEditorExtension } from "./use-editor-extension-Cc7ZG7uj.js";
|
|
2
2
|
import { getSafeEditorView } from "./get-safe-editor-view-DENm4avv.js";
|
|
3
3
|
import { assignStyles, useScrolling } from "./use-scrolling-BNfsQs3S.js";
|
|
4
|
-
import { deepCloneElement, injectStyle } from "./inject-style-
|
|
4
|
+
import { deepCloneElement, injectStyle } from "./inject-style-D5jj7cme.js";
|
|
5
5
|
import { createComputed, createContext, createSignal, defineCustomElement, registerCustomElement, useAttribute, useEffect, useEventListener } from "@aria-ui/core";
|
|
6
6
|
import { defineDOMEventHandler, insertDefaultBlock, union } from "@prosekit/core";
|
|
7
7
|
import { overlayPositionerEvents, overlayPositionerProps, useOverlayPositionerState } from "@aria-ui/overlay/elements";
|
|
@@ -56,6 +56,21 @@ const BlockHandleAddElementBase = defineCustomElement({
|
|
|
56
56
|
var BlockHandleAddElement = class extends BlockHandleAddElementBase {};
|
|
57
57
|
registerCustomElement("prosekit-block-handle-add", BlockHandleAddElement);
|
|
58
58
|
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/utils/get-box-element.ts
|
|
61
|
+
/**
|
|
62
|
+
* Returns the element that has a box.
|
|
63
|
+
*/
|
|
64
|
+
function getBoxElement(element) {
|
|
65
|
+
const window = element.ownerDocument.defaultView;
|
|
66
|
+
if (!window) return;
|
|
67
|
+
const style = window.getComputedStyle(element);
|
|
68
|
+
const display = style.display;
|
|
69
|
+
if (display === "contents" && element.childElementCount === 1) return element.firstElementChild;
|
|
70
|
+
else if (display === "none") return;
|
|
71
|
+
return element;
|
|
72
|
+
}
|
|
73
|
+
|
|
59
74
|
//#endregion
|
|
60
75
|
//#region src/utils/get-client-rect.ts
|
|
61
76
|
/**
|
|
@@ -120,8 +135,9 @@ function setDragPreview(event, element) {
|
|
|
120
135
|
const borderY = Math.max(outsideY, 0);
|
|
121
136
|
assignStyles(container, {
|
|
122
137
|
position: "fixed",
|
|
123
|
-
top: "
|
|
124
|
-
left: "
|
|
138
|
+
top: "-1000vh",
|
|
139
|
+
left: "-1000vw",
|
|
140
|
+
pointerEvents: "none",
|
|
125
141
|
zIndex: maxZIndex,
|
|
126
142
|
borderLeft: `${borderX}px solid transparent`,
|
|
127
143
|
borderTop: `${borderY}px solid transparent`,
|
|
@@ -129,11 +145,10 @@ function setDragPreview(event, element) {
|
|
|
129
145
|
width: `${width + borderX}px`,
|
|
130
146
|
height: `${height + borderY}px`
|
|
131
147
|
});
|
|
132
|
-
const [clonedElement, styleText] = deepCloneElement(element);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
});
|
|
148
|
+
const [clonedElement, styleText] = deepCloneElement(element, true);
|
|
149
|
+
clonedElement.style.setProperty("opacity", "0.5", "important");
|
|
150
|
+
clonedElement.style.setProperty("margin", "0", "important");
|
|
151
|
+
clonedElement.style.setProperty("outline-color", "transparent", "important");
|
|
137
152
|
document.body.appendChild(container);
|
|
138
153
|
container.appendChild(clonedElement);
|
|
139
154
|
injectStyle(container, styleText);
|
|
@@ -188,10 +203,12 @@ function createDraggingPreview(view, hoverState, event) {
|
|
|
188
203
|
const { pos } = hoverState;
|
|
189
204
|
const element = view.nodeDOM(pos);
|
|
190
205
|
if (!element || !isHTMLElement(element)) return;
|
|
206
|
+
const boxElement = getBoxElement(element);
|
|
207
|
+
if (!boxElement || !isHTMLElement(boxElement)) return;
|
|
191
208
|
event.dataTransfer.clearData();
|
|
192
|
-
event.dataTransfer.setData("text/html",
|
|
209
|
+
event.dataTransfer.setData("text/html", boxElement.outerHTML);
|
|
193
210
|
event.dataTransfer.effectAllowed = "copyMove";
|
|
194
|
-
setDragPreview(event,
|
|
211
|
+
setDragPreview(event, boxElement);
|
|
195
212
|
}
|
|
196
213
|
function setViewDragging(view, hoverState) {
|
|
197
214
|
const { node, pos } = hoverState;
|
|
@@ -2,7 +2,7 @@ import { getStateWithDefaults } from "./get-default-state-CIEy7xrl.js";
|
|
|
2
2
|
import { useEditorExtension } from "./use-editor-extension-Cc7ZG7uj.js";
|
|
3
3
|
import { getSafeEditorView } from "./get-safe-editor-view-DENm4avv.js";
|
|
4
4
|
import { assignStyles, useScrolling } from "./use-scrolling-BNfsQs3S.js";
|
|
5
|
-
import { cloneElement, deepCloneElement, injectStyle } from "./inject-style-
|
|
5
|
+
import { cloneElement, deepCloneElement, injectStyle } from "./inject-style-D5jj7cme.js";
|
|
6
6
|
import { createComputed, createContext, createSignal, defineCustomElement, defineEmit, registerCustomElement, useAttribute, useEffect, useEventListener } from "@aria-ui/core";
|
|
7
7
|
import { defineDOMEventHandler, union } from "@prosekit/core";
|
|
8
8
|
import { useOverlayPositionerState } from "@aria-ui/overlay/elements";
|
|
@@ -146,6 +146,7 @@ function useTableHandleColumnTrigger(host, { state }) {
|
|
|
146
146
|
dataTransfer.effectAllowed = "move";
|
|
147
147
|
const emptyImage = getEmptyImage();
|
|
148
148
|
if (emptyImage) dataTransfer.setDragImage(emptyImage, 0, 0);
|
|
149
|
+
dataTransfer.setData("application/x-prosekit-table-handle-drag", "");
|
|
149
150
|
}
|
|
150
151
|
const prev = dndContext.peek();
|
|
151
152
|
const index = context.peek()?.colIndex;
|
|
@@ -163,24 +164,6 @@ function useTableHandleColumnTrigger(host, { state }) {
|
|
|
163
164
|
startY: event.clientY
|
|
164
165
|
});
|
|
165
166
|
});
|
|
166
|
-
useEventListener(host, "drag", (event) => {
|
|
167
|
-
const prev = dndContext.peek();
|
|
168
|
-
if (event.clientX === 0 && event.clientY === 0) return;
|
|
169
|
-
dndContext.set({
|
|
170
|
-
...prev,
|
|
171
|
-
direction: "col",
|
|
172
|
-
dragging: true,
|
|
173
|
-
x: event.clientX,
|
|
174
|
-
y: event.clientY
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
useEventListener(host, "dragend", () => {
|
|
178
|
-
const prev = dndContext.peek();
|
|
179
|
-
dndContext.set({
|
|
180
|
-
...prev,
|
|
181
|
-
dragging: false
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
167
|
}
|
|
185
168
|
|
|
186
169
|
//#endregion
|
|
@@ -796,12 +779,12 @@ function useSelecting(host, editor, enabled) {
|
|
|
796
779
|
function useDrop(host, editor, dndContext) {
|
|
797
780
|
const dragging = createComputed(() => dndContext.get().dragging);
|
|
798
781
|
useEffect(host, () => {
|
|
799
|
-
|
|
800
|
-
const view = getSafeEditorView(editor.peek());
|
|
782
|
+
const view = getSafeEditorView(editor.get());
|
|
801
783
|
if (!view || !view.editable) return;
|
|
802
784
|
const ownerDocument = view.dom?.ownerDocument;
|
|
803
785
|
if (!ownerDocument) return;
|
|
804
786
|
const handleDrop = () => {
|
|
787
|
+
if (!dragging.peek()) return;
|
|
805
788
|
const editorValue = editor.peek();
|
|
806
789
|
if (!editorValue) return;
|
|
807
790
|
const { droppingIndex, draggingIndex, direction } = dndContext.peek();
|
|
@@ -828,13 +811,31 @@ function useDrop(host, editor, dndContext) {
|
|
|
828
811
|
}
|
|
829
812
|
};
|
|
830
813
|
const handleDragOver = (event) => {
|
|
814
|
+
if (!dragging.peek()) return;
|
|
831
815
|
event.preventDefault();
|
|
816
|
+
const prev = dndContext.peek();
|
|
817
|
+
dndContext.set({
|
|
818
|
+
...prev,
|
|
819
|
+
dragging: true,
|
|
820
|
+
x: event.clientX,
|
|
821
|
+
y: event.clientY
|
|
822
|
+
});
|
|
823
|
+
};
|
|
824
|
+
const handleDragEnd = () => {
|
|
825
|
+
if (!dragging.peek()) return;
|
|
826
|
+
const prev = dndContext.peek();
|
|
827
|
+
dndContext.set({
|
|
828
|
+
...prev,
|
|
829
|
+
dragging: false
|
|
830
|
+
});
|
|
832
831
|
};
|
|
833
832
|
ownerDocument.addEventListener("dragover", handleDragOver);
|
|
834
833
|
ownerDocument.addEventListener("drop", handleDrop);
|
|
834
|
+
ownerDocument.addEventListener("dragend", handleDragEnd);
|
|
835
835
|
return () => {
|
|
836
836
|
ownerDocument.removeEventListener("dragover", handleDragOver);
|
|
837
837
|
ownerDocument.removeEventListener("drop", handleDrop);
|
|
838
|
+
ownerDocument.removeEventListener("dragend", handleDragEnd);
|
|
838
839
|
};
|
|
839
840
|
});
|
|
840
841
|
}
|
|
@@ -1046,24 +1047,6 @@ function useTableHandleRowTrigger(host, { state }) {
|
|
|
1046
1047
|
startY: event.clientY
|
|
1047
1048
|
});
|
|
1048
1049
|
});
|
|
1049
|
-
useEventListener(host, "drag", (event) => {
|
|
1050
|
-
const prev = dndContext.peek();
|
|
1051
|
-
if (event.clientX === 0 && event.clientY === 0) return;
|
|
1052
|
-
dndContext.set({
|
|
1053
|
-
...prev,
|
|
1054
|
-
direction: "row",
|
|
1055
|
-
dragging: true,
|
|
1056
|
-
x: event.clientX,
|
|
1057
|
-
y: event.clientY
|
|
1058
|
-
});
|
|
1059
|
-
});
|
|
1060
|
-
useEventListener(host, "dragend", () => {
|
|
1061
|
-
const prev = dndContext.peek();
|
|
1062
|
-
dndContext.set({
|
|
1063
|
-
...prev,
|
|
1064
|
-
dragging: false
|
|
1065
|
-
});
|
|
1066
|
-
});
|
|
1067
1050
|
}
|
|
1068
1051
|
|
|
1069
1052
|
//#endregion
|
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.3",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "A collection of web components for ProseKit",
|
|
7
7
|
"author": {
|
|
@@ -80,15 +80,16 @@
|
|
|
80
80
|
"@zag-js/dom-query": "^1.21.1",
|
|
81
81
|
"prosemirror-tables": "^1.7.1",
|
|
82
82
|
"@prosekit/core": "^0.8.3",
|
|
83
|
-
"@prosekit/extensions": "^0.11.
|
|
83
|
+
"@prosekit/extensions": "^0.11.4",
|
|
84
84
|
"@prosekit/pm": "^0.1.11"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
-
"tsdown": "^0.13.
|
|
88
|
-
"
|
|
87
|
+
"tsdown": "^0.13.4",
|
|
88
|
+
"type-fest": "^4.41.0",
|
|
89
|
+
"typescript": "~5.9.2",
|
|
89
90
|
"vitest": "^3.2.4",
|
|
90
|
-
"@prosekit/config-
|
|
91
|
-
"@prosekit/config-
|
|
91
|
+
"@prosekit/config-tsdown": "0.0.0",
|
|
92
|
+
"@prosekit/config-vitest": "0.0.0"
|
|
92
93
|
},
|
|
93
94
|
"publishConfig": {
|
|
94
95
|
"dev": {}
|