@prosekit/web 0.5.7 → 0.5.8
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/get-default-state-CIEy7xrl.js +11 -0
- package/dist/prosekit-web-autocomplete.d.ts +135 -20
- package/dist/prosekit-web-autocomplete.js +240 -349
- package/dist/prosekit-web-block-handle.d.ts +88 -15
- package/dist/prosekit-web-block-handle.js +422 -394
- package/dist/prosekit-web-inline-popover.d.ts +81 -5
- package/dist/prosekit-web-inline-popover.js +114 -155
- package/dist/prosekit-web-popover.d.ts +34 -15
- package/dist/prosekit-web-popover.js +31 -70
- package/dist/prosekit-web-resizable.d.ts +52 -10
- package/dist/prosekit-web-resizable.js +210 -238
- package/dist/prosekit-web-table-handle.d.ts +165 -35
- package/dist/prosekit-web-table-handle.js +364 -491
- package/dist/prosekit-web-tooltip.d.ts +34 -15
- package/dist/prosekit-web-tooltip.js +31 -70
- package/dist/prosekit-web.d.ts +1 -1
- package/dist/use-editor-extension-Cc7ZG7uj.js +11 -0
- package/package.json +29 -14
- package/dist/_tsup-dts-rollup.d.ts +0 -1100
- package/dist/chunk-WTW6FOH3.js +0 -13
- package/dist/chunk-ZGQ225UP.js +0 -17
|
@@ -1,270 +1,242 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import { createContext, createSignal, defineCustomElement, registerCustomElement, useAttribute, useEffect } from "@aria-ui/core";
|
|
2
|
+
import { getWindow } from "@ocavue/utils";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
//#region src/components/resizable/context.ts
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
const onResizeContext = createContext("prosekit/resizable/onResize", null);
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
const onResizeStartContext = createContext("prosekit/resizable/onResizeStart", null);
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
const onResizeEndContext = createContext("prosekit/resizable/onResizeEnd", null);
|
|
10
17
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var onResizeContext = createContext(
|
|
14
|
-
"prosekit/resizable/onResize",
|
|
15
|
-
null
|
|
16
|
-
);
|
|
17
|
-
var onResizeStartContext = createContext(
|
|
18
|
-
"prosekit/resizable/onResizeStart",
|
|
19
|
-
null
|
|
20
|
-
);
|
|
21
|
-
var onResizeEndContext = createContext(
|
|
22
|
-
"prosekit/resizable/onResizeEnd",
|
|
23
|
-
null
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
// src/utils/is-finite-positive-number.ts
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/utils/is-finite-positive-number.ts
|
|
27
20
|
function isFinitePositiveNumber(value) {
|
|
28
|
-
|
|
21
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
29
22
|
}
|
|
30
23
|
|
|
31
|
-
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/components/resizable/resizable-handle/calc-resize.ts
|
|
32
26
|
function calcResize(position, w, h, dx, dy, aspectRatio) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
case "right":
|
|
47
|
-
return calcRightResize(w, h, dx, dy, aspectRatio);
|
|
48
|
-
case "bottom":
|
|
49
|
-
return calcBottomResize(w, h, dx, dy, aspectRatio);
|
|
50
|
-
case "left":
|
|
51
|
-
return calcLeftResize(w, h, dx, dy, aspectRatio);
|
|
52
|
-
default:
|
|
53
|
-
throw new RangeError(`Invalid position: ${position}`);
|
|
54
|
-
}
|
|
27
|
+
aspectRatio = aspectRatio ? aspectRatio : w / h;
|
|
28
|
+
aspectRatio = isFinitePositiveNumber(aspectRatio) ? aspectRatio : 1;
|
|
29
|
+
switch (position) {
|
|
30
|
+
case "bottom-right": return calcBottomRightResize(w, h, dx, dy, aspectRatio);
|
|
31
|
+
case "bottom-left": return calcBottomLeftResize(w, h, dx, dy, aspectRatio);
|
|
32
|
+
case "top-right": return calcTopRightResize(w, h, dx, dy, aspectRatio);
|
|
33
|
+
case "top-left": return calcTopLeftResize(w, h, dx, dy, aspectRatio);
|
|
34
|
+
case "top": return calcTopResize(w, h, dx, dy, aspectRatio);
|
|
35
|
+
case "right": return calcRightResize(w, h, dx, dy, aspectRatio);
|
|
36
|
+
case "bottom": return calcBottomResize(w, h, dx, dy, aspectRatio);
|
|
37
|
+
case "left": return calcLeftResize(w, h, dx, dy, aspectRatio);
|
|
38
|
+
default: throw new RangeError(`Invalid position: ${position}`);
|
|
39
|
+
}
|
|
55
40
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
41
|
+
const calcBottomRightResize = (w, h, dx, dy, r) => {
|
|
42
|
+
w += dx;
|
|
43
|
+
h += dy;
|
|
44
|
+
const sum = w + h;
|
|
45
|
+
h = sum / (r + 1);
|
|
46
|
+
w = sum - h;
|
|
47
|
+
return [w, h];
|
|
63
48
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
49
|
+
const calcBottomLeftResize = (w, h, dx, dy, r) => {
|
|
50
|
+
w -= dx;
|
|
51
|
+
h += dy;
|
|
52
|
+
const sum = w + h;
|
|
53
|
+
h = sum / (r + 1);
|
|
54
|
+
w = sum - h;
|
|
55
|
+
return [w, h];
|
|
71
56
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
57
|
+
const calcTopRightResize = (w, h, dx, dy, r) => {
|
|
58
|
+
w += dx;
|
|
59
|
+
h -= dy;
|
|
60
|
+
const sum = w + h;
|
|
61
|
+
h = sum / (r + 1);
|
|
62
|
+
w = sum - h;
|
|
63
|
+
return [w, h];
|
|
79
64
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
65
|
+
const calcTopLeftResize = (w, h, dx, dy, r) => {
|
|
66
|
+
w -= dx;
|
|
67
|
+
h -= dy;
|
|
68
|
+
const sum = w + h;
|
|
69
|
+
h = sum / (r + 1);
|
|
70
|
+
w = sum - h;
|
|
71
|
+
return [w, h];
|
|
87
72
|
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
73
|
+
const calcTopResize = (w, h, dx, dy, r) => {
|
|
74
|
+
h -= dy;
|
|
75
|
+
w = h * r;
|
|
76
|
+
return [w, h];
|
|
92
77
|
};
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
78
|
+
const calcRightResize = (w, h, dx, dy, r) => {
|
|
79
|
+
w += dx;
|
|
80
|
+
h = w / r;
|
|
81
|
+
return [w, h];
|
|
97
82
|
};
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
83
|
+
const calcBottomResize = (w, h, dx, dy, r) => {
|
|
84
|
+
h += dy;
|
|
85
|
+
w = h * r;
|
|
86
|
+
return [w, h];
|
|
102
87
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
88
|
+
const calcLeftResize = (w, h, dx, dy, r) => {
|
|
89
|
+
w -= dx;
|
|
90
|
+
h = w / r;
|
|
91
|
+
return [w, h];
|
|
107
92
|
};
|
|
108
93
|
|
|
109
|
-
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/components/resizable/resizable-handle/setup.ts
|
|
110
96
|
function useResizableHandle(host, { state }) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
97
|
+
const onResize = onResizeContext.consume(host);
|
|
98
|
+
const onResizeStart = onResizeStartContext.consume(host);
|
|
99
|
+
const onResizeEnd = onResizeEndContext.consume(host);
|
|
100
|
+
useResizableHandleState(host, state, {
|
|
101
|
+
onResize,
|
|
102
|
+
onResizeStart,
|
|
103
|
+
onResizeEnd
|
|
104
|
+
});
|
|
115
105
|
}
|
|
116
106
|
function useResizableHandleState(host, state, context) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
useEffect(host, () => {
|
|
160
|
-
if (!pointerPressing.get()) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
const win = getWindow(host);
|
|
164
|
-
win.addEventListener("pointermove", handlePointerMove);
|
|
165
|
-
win.addEventListener("pointerup", handlePointerUp);
|
|
166
|
-
return () => {
|
|
167
|
-
win.removeEventListener("pointermove", handlePointerMove);
|
|
168
|
-
win.removeEventListener("pointerup", handlePointerUp);
|
|
169
|
-
};
|
|
170
|
-
});
|
|
107
|
+
let startX = 0;
|
|
108
|
+
let startY = 0;
|
|
109
|
+
let width = 0;
|
|
110
|
+
let height = 0;
|
|
111
|
+
let aspectRatio = 1;
|
|
112
|
+
const pointerPressing = createSignal(false);
|
|
113
|
+
const handlePointerDown = (event) => {
|
|
114
|
+
event.preventDefault();
|
|
115
|
+
pointerPressing.set(true);
|
|
116
|
+
startX = event.x;
|
|
117
|
+
startY = event.y;
|
|
118
|
+
const size = context.onResizeStart.get()?.();
|
|
119
|
+
if (size) [width, height, aspectRatio] = size;
|
|
120
|
+
};
|
|
121
|
+
const handlePointerMove = (event) => {
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
const dx = event.x - startX;
|
|
124
|
+
const dy = event.y - startY;
|
|
125
|
+
const [w, h] = calcResize(state.position.peek(), width, height, dx, dy, aspectRatio);
|
|
126
|
+
context.onResize.get()?.(w, h);
|
|
127
|
+
};
|
|
128
|
+
const handlePointerUp = (event) => {
|
|
129
|
+
event.preventDefault();
|
|
130
|
+
pointerPressing.set(false);
|
|
131
|
+
context.onResizeEnd.get()?.();
|
|
132
|
+
};
|
|
133
|
+
useEffect(host, () => {
|
|
134
|
+
host.addEventListener("pointerdown", handlePointerDown);
|
|
135
|
+
return () => {
|
|
136
|
+
host.removeEventListener("pointerdown", handlePointerDown);
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
useEffect(host, () => {
|
|
140
|
+
if (!pointerPressing.get()) return;
|
|
141
|
+
const win = getWindow(host);
|
|
142
|
+
win.addEventListener("pointermove", handlePointerMove);
|
|
143
|
+
win.addEventListener("pointerup", handlePointerUp);
|
|
144
|
+
return () => {
|
|
145
|
+
win.removeEventListener("pointermove", handlePointerMove);
|
|
146
|
+
win.removeEventListener("pointerup", handlePointerUp);
|
|
147
|
+
};
|
|
148
|
+
});
|
|
171
149
|
}
|
|
172
150
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
};
|
|
177
|
-
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/components/resizable/resizable-handle/types.ts
|
|
153
|
+
/** @internal */
|
|
154
|
+
const resizableHandleProps = { position: { default: "bottom-right" } };
|
|
155
|
+
/** @internal */
|
|
156
|
+
const resizableHandleEvents = {};
|
|
178
157
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
};
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/components/resizable/resizable-handle/element.gen.ts
|
|
160
|
+
const ResizableHandleElementBase = defineCustomElement({
|
|
161
|
+
props: resizableHandleProps,
|
|
162
|
+
events: resizableHandleEvents,
|
|
163
|
+
setup: useResizableHandle
|
|
164
|
+
});
|
|
165
|
+
var ResizableHandleElement = class extends ResizableHandleElementBase {};
|
|
186
166
|
registerCustomElement("prosekit-resizable-handle", ResizableHandleElement);
|
|
187
167
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
// src/components/resizable/resizable-root/setup.ts
|
|
192
|
-
import {
|
|
193
|
-
createSignal as createSignal2,
|
|
194
|
-
useAttribute,
|
|
195
|
-
useEffect as useEffect2
|
|
196
|
-
} from "@aria-ui/core";
|
|
168
|
+
//#endregion
|
|
169
|
+
//#region src/components/resizable/resizable-root/setup.ts
|
|
197
170
|
function useResizableRoot(host, { state, emit }) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
171
|
+
const resizing = createSignal(false);
|
|
172
|
+
const onResizeStart = () => {
|
|
173
|
+
const { width, height } = host.getBoundingClientRect();
|
|
174
|
+
let aspectRatio = state.aspectRatio.peek() ?? width / height;
|
|
175
|
+
if (!isFinitePositiveNumber(aspectRatio)) aspectRatio = 0;
|
|
176
|
+
emit("resizeStart", {
|
|
177
|
+
width,
|
|
178
|
+
height
|
|
179
|
+
});
|
|
180
|
+
resizing.set(true);
|
|
181
|
+
return [
|
|
182
|
+
width,
|
|
183
|
+
height,
|
|
184
|
+
aspectRatio
|
|
185
|
+
];
|
|
186
|
+
};
|
|
187
|
+
const onResize = (width, height) => {
|
|
188
|
+
state.width.set(width);
|
|
189
|
+
state.height.set(height);
|
|
190
|
+
};
|
|
191
|
+
const onResizeEnd = () => {
|
|
192
|
+
const { width, height } = host.getBoundingClientRect();
|
|
193
|
+
emit("resizeEnd", {
|
|
194
|
+
width,
|
|
195
|
+
height
|
|
196
|
+
});
|
|
197
|
+
resizing.set(false);
|
|
198
|
+
};
|
|
199
|
+
onResizeStartContext.provide(host, createSignal(onResizeStart));
|
|
200
|
+
onResizeContext.provide(host, createSignal(onResize));
|
|
201
|
+
onResizeEndContext.provide(host, createSignal(onResizeEnd));
|
|
202
|
+
useEffect(host, () => {
|
|
203
|
+
updateResizableRootStyles(host, Math.max(state.width.get() || 0, 1), Math.max(state.height.get() || 0, 1), state.aspectRatio.get());
|
|
204
|
+
});
|
|
205
|
+
useAttribute(host, "data-resizing", () => resizing.get() ? "" : void 0);
|
|
230
206
|
}
|
|
231
207
|
function updateResizableRootStyles(host, width, height, aspectRatio) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
host.style.width = "min-content";
|
|
240
|
-
}
|
|
241
|
-
}
|
|
208
|
+
host.style.width = isFinitePositiveNumber(width) ? `${width}px` : "";
|
|
209
|
+
host.style.height = isFinitePositiveNumber(height) ? `${height}px` : "";
|
|
210
|
+
if (isFinitePositiveNumber(aspectRatio)) {
|
|
211
|
+
host.style.aspectRatio = `${aspectRatio}`;
|
|
212
|
+
if (width && width > 0 && aspectRatio >= 1) host.style.height = "auto";
|
|
213
|
+
else if (height && height > 0 && aspectRatio <= 1) host.style.width = "min-content";
|
|
214
|
+
}
|
|
242
215
|
}
|
|
243
216
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
217
|
+
//#endregion
|
|
218
|
+
//#region src/components/resizable/resizable-root/types.ts
|
|
219
|
+
/** @internal */
|
|
220
|
+
const resizableRootProps = {
|
|
221
|
+
width: { default: null },
|
|
222
|
+
height: { default: null },
|
|
223
|
+
aspectRatio: { default: null }
|
|
249
224
|
};
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
225
|
+
/** @internal */
|
|
226
|
+
const resizableRootEvents = {
|
|
227
|
+
resizeStart: {},
|
|
228
|
+
resizeEnd: {}
|
|
253
229
|
};
|
|
254
230
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
resizableHandleProps,
|
|
268
|
-
resizableRootEvents,
|
|
269
|
-
resizableRootProps
|
|
270
|
-
};
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region src/components/resizable/resizable-root/element.gen.ts
|
|
233
|
+
const ResizableRootElementBase = defineCustomElement({
|
|
234
|
+
props: resizableRootProps,
|
|
235
|
+
events: resizableRootEvents,
|
|
236
|
+
setup: useResizableRoot
|
|
237
|
+
});
|
|
238
|
+
var ResizableRootElement = class extends ResizableRootElementBase {};
|
|
239
|
+
registerCustomElement("prosekit-resizable-root", ResizableRootElement);
|
|
240
|
+
|
|
241
|
+
//#endregion
|
|
242
|
+
export { ResizableHandleElement, ResizableRootElement, resizableHandleEvents, resizableHandleProps, resizableRootEvents, resizableRootProps };
|