@prosekit/web 0.1.0 → 0.1.2
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.
|
@@ -10,6 +10,7 @@ import { Editor } from '@prosekit/core';
|
|
|
10
10
|
import type { EditorView } from '@prosekit/pm/view';
|
|
11
11
|
import { Extension } from '@prosekit/core';
|
|
12
12
|
import { FocusChangeHandler } from '@prosekit/core';
|
|
13
|
+
import { ListboxProps } from '@aria-ui/listbox';
|
|
13
14
|
import { Options } from 'tsup';
|
|
14
15
|
import type { OverlayPositionerProps } from '@aria-ui/overlay';
|
|
15
16
|
import type { Placement } from '@floating-ui/dom';
|
|
@@ -84,7 +85,7 @@ declare interface AutocompleteListElement extends AutocompleteListProps {
|
|
|
84
85
|
export { AutocompleteListElement }
|
|
85
86
|
export { AutocompleteListElement as AutocompleteListElement_alias_1 }
|
|
86
87
|
|
|
87
|
-
declare interface AutocompleteListProps {
|
|
88
|
+
declare interface AutocompleteListProps extends Pick<ListboxProps, 'filter'> {
|
|
88
89
|
editor: Editor | null;
|
|
89
90
|
}
|
|
90
91
|
export { AutocompleteListProps }
|
|
@@ -108,11 +109,19 @@ declare interface AutocompletePopoverProps extends OverlayPositionerProps {
|
|
|
108
109
|
*/
|
|
109
110
|
editor: Editor | null;
|
|
110
111
|
/**
|
|
111
|
-
* The regular expression to match the text to autocomplete.
|
|
112
|
+
* The regular expression to match the query text to autocomplete.
|
|
112
113
|
*
|
|
113
114
|
* @default null
|
|
114
115
|
*/
|
|
115
116
|
regex: RegExp | null;
|
|
117
|
+
/**
|
|
118
|
+
* A callback that is called when the query changes.
|
|
119
|
+
*/
|
|
120
|
+
onQueryChange: ((query: string) => void) | null;
|
|
121
|
+
/**
|
|
122
|
+
* A callback that is called when the open state changes.
|
|
123
|
+
*/
|
|
124
|
+
onOpenChange: ((open: boolean) => void) | null;
|
|
116
125
|
/**
|
|
117
126
|
* The placement of the popover, relative to the text cursor.
|
|
118
127
|
*
|
|
@@ -239,6 +248,10 @@ export { defaultAutocompleteItemProps }
|
|
|
239
248
|
export { defaultAutocompleteItemProps as defaultAutocompleteItemProps_alias_1 }
|
|
240
249
|
|
|
241
250
|
declare const defaultAutocompleteListProps: {
|
|
251
|
+
filter: (options: {
|
|
252
|
+
query: string;
|
|
253
|
+
value: string;
|
|
254
|
+
}) => boolean;
|
|
242
255
|
editor: null;
|
|
243
256
|
};
|
|
244
257
|
export { defaultAutocompleteListProps }
|
|
@@ -247,6 +260,8 @@ export { defaultAutocompleteListProps as defaultAutocompleteListProps_alias_1 }
|
|
|
247
260
|
declare const defaultAutocompletePopoverProps: Readonly<{
|
|
248
261
|
editor: null;
|
|
249
262
|
regex: null;
|
|
263
|
+
onQueryChange: null;
|
|
264
|
+
onOpenChange: null;
|
|
250
265
|
placement: "bottom-start";
|
|
251
266
|
offset: 4;
|
|
252
267
|
inline: true;
|
|
@@ -83,7 +83,10 @@ defineCustomElement("prosekit-autocomplete-item", AutocompleteItemElement);
|
|
|
83
83
|
import { BaseElement as BaseElement3 } from "@aria-ui/core";
|
|
84
84
|
|
|
85
85
|
// src/components/autocomplete/autocomplete-list/props.ts
|
|
86
|
+
import { defaultListboxProps } from "@aria-ui/listbox";
|
|
87
|
+
var defaultFilter = defaultListboxProps.filter;
|
|
86
88
|
var defaultAutocompleteListProps = {
|
|
89
|
+
filter: defaultFilter,
|
|
87
90
|
editor: null
|
|
88
91
|
};
|
|
89
92
|
|
|
@@ -91,7 +94,6 @@ var defaultAutocompleteListProps = {
|
|
|
91
94
|
import {
|
|
92
95
|
assignProps,
|
|
93
96
|
createSignal,
|
|
94
|
-
mapSignals,
|
|
95
97
|
useEffect as useEffect2
|
|
96
98
|
} from "@aria-ui/core";
|
|
97
99
|
import { useListbox } from "@aria-ui/listbox";
|
|
@@ -101,24 +103,27 @@ import {
|
|
|
101
103
|
withPriority
|
|
102
104
|
} from "@prosekit/core";
|
|
103
105
|
function useAutocompleteList(element, props) {
|
|
104
|
-
const
|
|
106
|
+
const fullProps = assignProps(defaultAutocompleteListProps, props);
|
|
107
|
+
const editor = createSignal(fullProps.editor);
|
|
105
108
|
const open = openContext.consume(element);
|
|
106
109
|
const query = queryContext.consume(element);
|
|
107
110
|
const onSubmit = onSubmitContext.consume(element);
|
|
108
|
-
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
|
+
};
|
|
109
118
|
const {
|
|
110
119
|
query: listboxQuery,
|
|
111
120
|
value: listboxValue,
|
|
121
|
+
filter,
|
|
112
122
|
autoFocus
|
|
113
123
|
} = useListbox(element, {
|
|
114
124
|
onKeydownHandlerAdd,
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
var _a;
|
|
118
|
-
if (value) {
|
|
119
|
-
(_a = onSubmit.value) == null ? void 0 : _a.call(onSubmit);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
125
|
+
onValueChange,
|
|
126
|
+
filter: fullProps.filter
|
|
122
127
|
});
|
|
123
128
|
useEffect2(element, () => {
|
|
124
129
|
listboxQuery.value = query.value;
|
|
@@ -149,7 +154,7 @@ function useAutocompleteList(element, props) {
|
|
|
149
154
|
};
|
|
150
155
|
}
|
|
151
156
|
});
|
|
152
|
-
return
|
|
157
|
+
return { editor, filter };
|
|
153
158
|
}
|
|
154
159
|
function useKeyboardHandler(element, open, editor) {
|
|
155
160
|
const keydownHandler = createSignal(
|
|
@@ -207,6 +212,8 @@ var defaultAutocompletePopoverProps = Object.freeze({
|
|
|
207
212
|
...defaultOverlayPositionerProps,
|
|
208
213
|
editor: null,
|
|
209
214
|
regex: null,
|
|
215
|
+
onQueryChange: null,
|
|
216
|
+
onOpenChange: null,
|
|
210
217
|
placement: "bottom-start",
|
|
211
218
|
offset: 4,
|
|
212
219
|
inline: true,
|
|
@@ -221,7 +228,7 @@ import {
|
|
|
221
228
|
assignProps as assignProps2,
|
|
222
229
|
createComputed,
|
|
223
230
|
createSignal as createSignal2,
|
|
224
|
-
mapSignals
|
|
231
|
+
mapSignals,
|
|
225
232
|
useEffect as useEffect3
|
|
226
233
|
} from "@aria-ui/core";
|
|
227
234
|
import { useOverlayPositionerState } from "@aria-ui/overlay";
|
|
@@ -238,7 +245,7 @@ function defaultQueryBuilder(match) {
|
|
|
238
245
|
|
|
239
246
|
// src/components/autocomplete/autocomplete-popover/state.ts
|
|
240
247
|
function useAutocompletePopover(host, props) {
|
|
241
|
-
const state =
|
|
248
|
+
const state = mapSignals(assignProps2(defaultAutocompletePopoverProps, props));
|
|
242
249
|
useAutocompletePopoverState(host, state);
|
|
243
250
|
return state;
|
|
244
251
|
}
|
|
@@ -264,6 +271,18 @@ function useAutocompletePopoverState(host, state) {
|
|
|
264
271
|
);
|
|
265
272
|
useOverlayPositionerState(host, overlayState, { reference });
|
|
266
273
|
usePresence(host, presence);
|
|
274
|
+
useEffect3(host, () => {
|
|
275
|
+
var _a;
|
|
276
|
+
const queryValue = query.value;
|
|
277
|
+
if (presence.peek()) {
|
|
278
|
+
(_a = state.onQueryChange.peek()) == null ? void 0 : _a(queryValue);
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
useEffect3(host, () => {
|
|
282
|
+
var _a;
|
|
283
|
+
const presenceValue = presence.value;
|
|
284
|
+
(_a = state.onOpenChange.peek()) == null ? void 0 : _a(presenceValue);
|
|
285
|
+
});
|
|
267
286
|
}
|
|
268
287
|
function useAutocompleteExtension(host, editor, regex, reference, query, onDismiss, onSubmit) {
|
|
269
288
|
useEffect3(host, () => {
|
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.2",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "ocavue",
|
|
@@ -65,8 +65,9 @@
|
|
|
65
65
|
"dist"
|
|
66
66
|
],
|
|
67
67
|
"dependencies": {
|
|
68
|
+
"@aria-ui/collection": "^0.0.3",
|
|
68
69
|
"@aria-ui/core": "^0.0.12",
|
|
69
|
-
"@aria-ui/listbox": "^0.0.
|
|
70
|
+
"@aria-ui/listbox": "^0.0.11",
|
|
70
71
|
"@aria-ui/overlay": "^0.0.12",
|
|
71
72
|
"@aria-ui/popover": "^0.0.11",
|
|
72
73
|
"@aria-ui/presence": "^0.0.7",
|