@prosekit/web 0.1.1 → 0.1.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.
|
@@ -658,6 +658,8 @@ export declare function useEditorFocusChangeEvent(host: ConnectableElement, edit
|
|
|
658
658
|
*/
|
|
659
659
|
export declare function useEditorUpdateEvent(host: ConnectableElement, editor: ReadonlySignal<Editor | null>, handler: UpdateHandler): void;
|
|
660
660
|
|
|
661
|
+
export declare function useFirstRendering(host: ConnectableElement): ReadonlySignal<boolean>;
|
|
662
|
+
|
|
661
663
|
export declare function useInlinePopover(host: ConnectableElement, props?: Partial<InlinePopoverProps>): SignalState<Readonly<InlinePopoverProps>>;
|
|
662
664
|
|
|
663
665
|
export { usePopoverContent }
|
|
@@ -94,7 +94,6 @@ var defaultAutocompleteListProps = {
|
|
|
94
94
|
import {
|
|
95
95
|
assignProps,
|
|
96
96
|
createSignal,
|
|
97
|
-
mapSignals,
|
|
98
97
|
useEffect as useEffect2
|
|
99
98
|
} from "@aria-ui/core";
|
|
100
99
|
import { useListbox } from "@aria-ui/listbox";
|
|
@@ -104,24 +103,27 @@ import {
|
|
|
104
103
|
withPriority
|
|
105
104
|
} from "@prosekit/core";
|
|
106
105
|
function useAutocompleteList(element, props) {
|
|
107
|
-
const
|
|
106
|
+
const fullProps = assignProps(defaultAutocompleteListProps, props);
|
|
107
|
+
const editor = createSignal(fullProps.editor);
|
|
108
108
|
const open = openContext.consume(element);
|
|
109
109
|
const query = queryContext.consume(element);
|
|
110
110
|
const onSubmit = onSubmitContext.consume(element);
|
|
111
|
-
const onKeydownHandlerAdd = useKeyboardHandler(element, open,
|
|
111
|
+
const onKeydownHandlerAdd = useKeyboardHandler(element, open, editor);
|
|
112
|
+
const onValueChange = (value) => {
|
|
113
|
+
var _a;
|
|
114
|
+
if (value) {
|
|
115
|
+
(_a = onSubmit.peek()) == null ? void 0 : _a();
|
|
116
|
+
}
|
|
117
|
+
};
|
|
112
118
|
const {
|
|
113
119
|
query: listboxQuery,
|
|
114
120
|
value: listboxValue,
|
|
121
|
+
filter,
|
|
115
122
|
autoFocus
|
|
116
123
|
} = useListbox(element, {
|
|
117
124
|
onKeydownHandlerAdd,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
var _a;
|
|
121
|
-
if (value) {
|
|
122
|
-
(_a = onSubmit.value) == null ? void 0 : _a.call(onSubmit);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
+
onValueChange,
|
|
126
|
+
filter: fullProps.filter
|
|
125
127
|
});
|
|
126
128
|
useEffect2(element, () => {
|
|
127
129
|
listboxQuery.value = query.value;
|
|
@@ -129,6 +131,7 @@ function useAutocompleteList(element, props) {
|
|
|
129
131
|
useEffect2(element, () => {
|
|
130
132
|
if (!open.value) {
|
|
131
133
|
listboxValue.value = "";
|
|
134
|
+
query.value = "";
|
|
132
135
|
}
|
|
133
136
|
});
|
|
134
137
|
useEffect2(element, () => {
|
|
@@ -152,7 +155,7 @@ function useAutocompleteList(element, props) {
|
|
|
152
155
|
};
|
|
153
156
|
}
|
|
154
157
|
});
|
|
155
|
-
return
|
|
158
|
+
return { editor, filter };
|
|
156
159
|
}
|
|
157
160
|
function useKeyboardHandler(element, open, editor) {
|
|
158
161
|
const keydownHandler = createSignal(
|
|
@@ -225,9 +228,9 @@ var defaultAutocompletePopoverProps = Object.freeze({
|
|
|
225
228
|
import {
|
|
226
229
|
assignProps as assignProps2,
|
|
227
230
|
createComputed,
|
|
228
|
-
createSignal as
|
|
229
|
-
mapSignals
|
|
230
|
-
useEffect as
|
|
231
|
+
createSignal as createSignal3,
|
|
232
|
+
mapSignals,
|
|
233
|
+
useEffect as useEffect4
|
|
231
234
|
} from "@aria-ui/core";
|
|
232
235
|
import { useOverlayPositionerState } from "@aria-ui/overlay";
|
|
233
236
|
import { usePresence } from "@aria-ui/presence";
|
|
@@ -236,6 +239,21 @@ import {
|
|
|
236
239
|
defineAutocomplete
|
|
237
240
|
} from "@prosekit/extensions/autocomplete";
|
|
238
241
|
|
|
242
|
+
// src/hooks/use-first-rendering.ts
|
|
243
|
+
import {
|
|
244
|
+
createSignal as createSignal2,
|
|
245
|
+
useEffect as useEffect3
|
|
246
|
+
} from "@aria-ui/core";
|
|
247
|
+
function useFirstRendering(host) {
|
|
248
|
+
const firstRendering = createSignal2(true);
|
|
249
|
+
useEffect3(host, () => {
|
|
250
|
+
requestAnimationFrame(() => {
|
|
251
|
+
firstRendering.value = false;
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
return firstRendering;
|
|
255
|
+
}
|
|
256
|
+
|
|
239
257
|
// src/components/autocomplete/autocomplete-popover/helpers.ts
|
|
240
258
|
function defaultQueryBuilder(match) {
|
|
241
259
|
return match[0].toLowerCase().replace(/[!"#$%&'()*+,-./:;<=>?@[\\\]^_`{|}~]/g, "").replace(/\s\s+/g, " ").trim();
|
|
@@ -243,16 +261,16 @@ function defaultQueryBuilder(match) {
|
|
|
243
261
|
|
|
244
262
|
// src/components/autocomplete/autocomplete-popover/state.ts
|
|
245
263
|
function useAutocompletePopover(host, props) {
|
|
246
|
-
const state =
|
|
264
|
+
const state = mapSignals(assignProps2(defaultAutocompletePopoverProps, props));
|
|
247
265
|
useAutocompletePopoverState(host, state);
|
|
248
266
|
return state;
|
|
249
267
|
}
|
|
250
268
|
function useAutocompletePopoverState(host, state) {
|
|
251
269
|
const { editor, regex, ...overlayState } = state;
|
|
252
|
-
const reference =
|
|
253
|
-
const query =
|
|
254
|
-
const onDismiss =
|
|
255
|
-
const onSubmit =
|
|
270
|
+
const reference = createSignal3(null);
|
|
271
|
+
const query = createSignal3("");
|
|
272
|
+
const onDismiss = createSignal3(null);
|
|
273
|
+
const onSubmit = createSignal3(null);
|
|
256
274
|
const presence = createComputed(() => !!reference.value);
|
|
257
275
|
queryContext.provide(host, query);
|
|
258
276
|
onSubmitContext.provide(host, onSubmit);
|
|
@@ -269,21 +287,22 @@ function useAutocompletePopoverState(host, state) {
|
|
|
269
287
|
);
|
|
270
288
|
useOverlayPositionerState(host, overlayState, { reference });
|
|
271
289
|
usePresence(host, presence);
|
|
272
|
-
|
|
290
|
+
const firstRendering = useFirstRendering(host);
|
|
291
|
+
useEffect4(host, () => {
|
|
273
292
|
var _a;
|
|
274
293
|
const queryValue = query.value;
|
|
275
|
-
if (
|
|
294
|
+
if (!firstRendering.peek()) {
|
|
276
295
|
(_a = state.onQueryChange.peek()) == null ? void 0 : _a(queryValue);
|
|
277
296
|
}
|
|
278
297
|
});
|
|
279
|
-
|
|
298
|
+
useEffect4(host, () => {
|
|
280
299
|
var _a;
|
|
281
300
|
const presenceValue = presence.value;
|
|
282
301
|
(_a = state.onOpenChange.peek()) == null ? void 0 : _a(presenceValue);
|
|
283
302
|
});
|
|
284
303
|
}
|
|
285
304
|
function useAutocompleteExtension(host, editor, regex, reference, query, onDismiss, onSubmit) {
|
|
286
|
-
|
|
305
|
+
useEffect4(host, () => {
|
|
287
306
|
const editorValue = editor.value;
|
|
288
307
|
const regexValue = regex.value;
|
|
289
308
|
if (!editorValue || !regexValue) {
|
|
@@ -336,7 +355,7 @@ function createKeymapHandler(handler, enabled) {
|
|
|
336
355
|
};
|
|
337
356
|
}
|
|
338
357
|
function useEscapeKeydown(host, handler) {
|
|
339
|
-
|
|
358
|
+
useEffect4(host, () => {
|
|
340
359
|
const handleKeyDown = (event) => {
|
|
341
360
|
if (event.key !== "Escape") {
|
|
342
361
|
return;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosekit/web",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.3",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "ocavue",
|
|
@@ -74,15 +74,15 @@
|
|
|
74
74
|
"@aria-ui/tooltip": "^0.0.13",
|
|
75
75
|
"@floating-ui/dom": "^1.6.3",
|
|
76
76
|
"@prosekit/core": "^0.4.0",
|
|
77
|
-
"@prosekit/extensions": "^0.4.
|
|
77
|
+
"@prosekit/extensions": "^0.4.6",
|
|
78
78
|
"@prosekit/pm": "^0.1.2",
|
|
79
|
-
"@zag-js/dom-query": "^0.
|
|
79
|
+
"@zag-js/dom-query": "^0.48.0"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@prosekit/dev": "*",
|
|
83
83
|
"tsup": "^8.0.2",
|
|
84
84
|
"typescript": "^5.4.5",
|
|
85
|
-
"vitest": "^1.5.
|
|
85
|
+
"vitest": "^1.5.2"
|
|
86
86
|
},
|
|
87
87
|
"scripts": {
|
|
88
88
|
"build:tsup": "tsup",
|