@destyler/combobox 0.2.11 → 0.2.12
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/index.d.mts +6 -9
- package/dist/index.mjs +180 -184
- package/package.json +10 -10
package/dist/index.d.mts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import * as _destyler_anatomy0 from "@destyler/anatomy";
|
|
2
1
|
import { CollectionItem, CollectionItem as CollectionItem$1, CollectionOptions, CollectionOptions as CollectionOptions$1, ListCollection } from "@destyler/collection";
|
|
3
|
-
import * as _destyler_xstate0 from "@destyler/xstate";
|
|
4
2
|
import { AnyEventObject, Machine, XSend, XState } from "@destyler/xstate";
|
|
5
3
|
import { Placement, PositioningOptions } from "@destyler/popper";
|
|
6
4
|
import { FocusOutsideEvent, InteractOutsideEvent, InteractOutsideHandlers, PointerDownOutsideEvent } from "@destyler/dismissable";
|
|
7
5
|
import { CommonProperties, DirectionProperty, NormalizeProps, PropTypes, RequiredBy } from "@destyler/types";
|
|
8
|
-
|
|
9
6
|
//#region src/anatomy.d.ts
|
|
10
|
-
declare const anatomy:
|
|
7
|
+
export declare const anatomy: import("@destyler/anatomy").AnatomyInstance<"root" | "label" | "control" | "input" | "content" | "trigger" | "clearTrigger" | "item" | "positioner" | "itemGroup" | "itemGroupLabel" | "itemIndicator" | "itemText" | "list">;
|
|
11
8
|
//#endregion
|
|
12
9
|
//#region src/collection.d.ts
|
|
13
|
-
declare function collection<T extends CollectionItem$1>(options: CollectionOptions$1<T>): ListCollection<T>;
|
|
14
|
-
declare namespace collection {
|
|
10
|
+
export declare function collection<T extends CollectionItem$1>(options: CollectionOptions$1<T>): ListCollection<T>;
|
|
11
|
+
export declare namespace collection {
|
|
15
12
|
var empty: () => ListCollection<CollectionItem$1>;
|
|
16
13
|
}
|
|
17
14
|
//#endregion
|
|
@@ -431,9 +428,9 @@ interface MachineApi<T extends PropTypes = PropTypes, V extends CollectionItem =
|
|
|
431
428
|
}
|
|
432
429
|
//#endregion
|
|
433
430
|
//#region src/connect.d.ts
|
|
434
|
-
declare function connect<T extends PropTypes, V extends CollectionItem>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T, V>;
|
|
431
|
+
export declare function connect<T extends PropTypes, V extends CollectionItem>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T, V>;
|
|
435
432
|
//#endregion
|
|
436
433
|
//#region src/machine.d.ts
|
|
437
|
-
declare function machine<T extends CollectionItem>(userContext: UserDefinedContext<T>):
|
|
434
|
+
export declare function machine<T extends CollectionItem>(userContext: UserDefinedContext<T>): import("@destyler/xstate").Machine<MachineContext, MachineState, import("@destyler/xstate").AnyEventObject>;
|
|
438
435
|
//#endregion
|
|
439
|
-
export {
|
|
436
|
+
export type { MachineApi as Api, CollectionItem, CollectionOptions, UserDefinedContext as Context, ElementIds, FocusOutsideEvent, HighlightChangeDetails, InputValueChangeDetails, InteractOutsideEvent, IntlTranslations, ItemGroupLabelProps, ItemGroupProps, ItemProps, ItemState, NavigateDetails, OpenChangeDetails, Placement, PointerDownOutsideEvent, PositioningOptions, ScrollToIndexDetails, Service, TriggerProps, ValueChangeDetails };
|
package/dist/index.mjs
CHANGED
|
@@ -6,11 +6,9 @@ import { getPlacement, getPlacementStyles } from "@destyler/popper";
|
|
|
6
6
|
import { ariaHidden } from "@destyler/aria-hidden";
|
|
7
7
|
import { trackDismissableElement } from "@destyler/dismissable";
|
|
8
8
|
import { addOrRemove, compact, isArray, isBoolean, isControlled, isEqual, isPropUserProvided, match, resolveControllableOpen, resolveControllableProp, withControllableProvided } from "@destyler/utils";
|
|
9
|
-
|
|
10
9
|
//#region src/anatomy.ts
|
|
11
10
|
const anatomy = createAnatomy("combobox").parts("root", "clearTrigger", "content", "control", "input", "item", "itemGroup", "itemGroupLabel", "itemIndicator", "itemText", "label", "list", "positioner", "trigger");
|
|
12
11
|
const parts = anatomy.build();
|
|
13
|
-
|
|
14
12
|
//#endregion
|
|
15
13
|
//#region src/collection.ts
|
|
16
14
|
function collection(options) {
|
|
@@ -19,7 +17,6 @@ function collection(options) {
|
|
|
19
17
|
collection.empty = () => {
|
|
20
18
|
return ref(new ListCollection({ items: [] }));
|
|
21
19
|
};
|
|
22
|
-
|
|
23
20
|
//#endregion
|
|
24
21
|
//#region src/dom.ts
|
|
25
22
|
const dom = createScope({
|
|
@@ -43,7 +40,7 @@ const dom = createScope({
|
|
|
43
40
|
getHighlightedItemEl: (ctx) => {
|
|
44
41
|
const value = ctx.highlightedValue;
|
|
45
42
|
if (value == null) return;
|
|
46
|
-
const selector = `[role=option][data-value="${CSS.escape(value)}"`;
|
|
43
|
+
const selector = `[role=option][data-value="${CSS.escape(value)}"]`;
|
|
47
44
|
return query(dom.getContentEl(ctx), selector);
|
|
48
45
|
},
|
|
49
46
|
focusInputEl: (ctx) => {
|
|
@@ -57,12 +54,11 @@ const dom = createScope({
|
|
|
57
54
|
triggerEl?.focus({ preventScroll: true });
|
|
58
55
|
}
|
|
59
56
|
});
|
|
60
|
-
|
|
61
57
|
//#endregion
|
|
62
58
|
//#region src/connect.ts
|
|
63
59
|
function connect(state, send, normalize) {
|
|
64
60
|
const translations = state.context.translations;
|
|
65
|
-
const collection
|
|
61
|
+
const collection = state.context.collection;
|
|
66
62
|
const disabled = state.context.disabled;
|
|
67
63
|
const interactive = state.context.isInteractive;
|
|
68
64
|
const invalid = state.context.invalid;
|
|
@@ -76,11 +72,11 @@ function connect(state, send, normalize) {
|
|
|
76
72
|
placement: state.context.currentPlacement
|
|
77
73
|
});
|
|
78
74
|
function getItemState(props) {
|
|
79
|
-
const
|
|
80
|
-
const value = collection
|
|
75
|
+
const itemDisabled = collection.getItemDisabled(props.item);
|
|
76
|
+
const value = collection.getItemValue(props.item);
|
|
81
77
|
return {
|
|
82
78
|
value,
|
|
83
|
-
disabled: Boolean(disabled
|
|
79
|
+
disabled: Boolean(disabled || itemDisabled),
|
|
84
80
|
highlighted: highlightedValue === value,
|
|
85
81
|
selected: state.context.value.includes(value)
|
|
86
82
|
};
|
|
@@ -107,10 +103,10 @@ function connect(state, send, normalize) {
|
|
|
107
103
|
options
|
|
108
104
|
});
|
|
109
105
|
},
|
|
110
|
-
setCollection(collection
|
|
106
|
+
setCollection(collection) {
|
|
111
107
|
send({
|
|
112
108
|
type: "COLLECTION.SET",
|
|
113
|
-
value: collection
|
|
109
|
+
value: collection
|
|
114
110
|
});
|
|
115
111
|
},
|
|
116
112
|
setHighlightValue(value) {
|
|
@@ -250,13 +246,13 @@ function connect(state, send, normalize) {
|
|
|
250
246
|
const isModifierKey = event.ctrlKey || event.metaKey || event.shiftKey;
|
|
251
247
|
const keypress = true;
|
|
252
248
|
const exec = {
|
|
253
|
-
ArrowDown(event
|
|
249
|
+
ArrowDown(event) {
|
|
254
250
|
if (!openOnKeyPress && !open) return;
|
|
255
251
|
send({
|
|
256
|
-
type: event
|
|
252
|
+
type: event.altKey ? "OPEN" : "INPUT.ARROW_DOWN",
|
|
257
253
|
keypress
|
|
258
254
|
});
|
|
259
|
-
event
|
|
255
|
+
event.preventDefault();
|
|
260
256
|
},
|
|
261
257
|
ArrowUp() {
|
|
262
258
|
if (!openOnKeyPress && !open) return;
|
|
@@ -266,28 +262,28 @@ function connect(state, send, normalize) {
|
|
|
266
262
|
});
|
|
267
263
|
event.preventDefault();
|
|
268
264
|
},
|
|
269
|
-
Home(event
|
|
265
|
+
Home(event) {
|
|
270
266
|
if (isModifierKey) return;
|
|
271
267
|
send({
|
|
272
268
|
type: "INPUT.HOME",
|
|
273
269
|
keypress
|
|
274
270
|
});
|
|
275
|
-
if (open) event
|
|
271
|
+
if (open) event.preventDefault();
|
|
276
272
|
},
|
|
277
|
-
End(event
|
|
273
|
+
End(event) {
|
|
278
274
|
if (isModifierKey) return;
|
|
279
275
|
send({
|
|
280
276
|
type: "INPUT.END",
|
|
281
277
|
keypress
|
|
282
278
|
});
|
|
283
|
-
if (open) event
|
|
279
|
+
if (open) event.preventDefault();
|
|
284
280
|
},
|
|
285
|
-
Enter(event
|
|
281
|
+
Enter(event) {
|
|
286
282
|
send({
|
|
287
283
|
type: "INPUT.ENTER",
|
|
288
284
|
keypress
|
|
289
285
|
});
|
|
290
|
-
if (open) event
|
|
286
|
+
if (open) event.preventDefault();
|
|
291
287
|
const itemEl = dom.getHighlightedItemEl(state.context);
|
|
292
288
|
if (isAnchorElement(itemEl)) state.context.navigate({
|
|
293
289
|
value: state.context.highlightedValue,
|
|
@@ -435,6 +431,7 @@ function connect(state, send, normalize) {
|
|
|
435
431
|
"data-disabled": dataAttr(itemState.disabled),
|
|
436
432
|
"data-value": itemState.value,
|
|
437
433
|
onPointerMove() {
|
|
434
|
+
if (!interactive) return;
|
|
438
435
|
if (itemState.disabled) return;
|
|
439
436
|
if (itemState.highlighted) return;
|
|
440
437
|
send({
|
|
@@ -443,6 +440,7 @@ function connect(state, send, normalize) {
|
|
|
443
440
|
});
|
|
444
441
|
},
|
|
445
442
|
onPointerLeave() {
|
|
443
|
+
if (!interactive) return;
|
|
446
444
|
if (props.persistFocus) return;
|
|
447
445
|
if (itemState.disabled) return;
|
|
448
446
|
if (!state.previousEvent.type.includes("POINTER")) return;
|
|
@@ -452,6 +450,7 @@ function connect(state, send, normalize) {
|
|
|
452
450
|
});
|
|
453
451
|
},
|
|
454
452
|
onClick(event) {
|
|
453
|
+
if (event.defaultPrevented || !interactive) return;
|
|
455
454
|
if (isDownloadingEvent(event)) return;
|
|
456
455
|
if (isOpeningInNewTab(event)) return;
|
|
457
456
|
if (isContextMenuEvent(event)) return;
|
|
@@ -504,7 +503,6 @@ function connect(state, send, normalize) {
|
|
|
504
503
|
}
|
|
505
504
|
};
|
|
506
505
|
}
|
|
507
|
-
|
|
508
506
|
//#endregion
|
|
509
507
|
//#region src/machine.ts
|
|
510
508
|
const { and, not } = guards;
|
|
@@ -652,11 +650,11 @@ function machine(userContext) {
|
|
|
652
650
|
},
|
|
653
651
|
created: ["syncInitialValues", "syncSelectionBehavior"],
|
|
654
652
|
computed: {
|
|
655
|
-
isInputValueEmpty: (ctx
|
|
656
|
-
isInteractive: (ctx
|
|
657
|
-
autoComplete: (ctx
|
|
658
|
-
autoHighlight: (ctx
|
|
659
|
-
hasSelectedItems: (ctx
|
|
653
|
+
isInputValueEmpty: (ctx) => ctx.inputValue.length === 0,
|
|
654
|
+
isInteractive: (ctx) => !(ctx.readOnly || ctx.disabled),
|
|
655
|
+
autoComplete: (ctx) => ctx.inputBehavior === "autocomplete",
|
|
656
|
+
autoHighlight: (ctx) => ctx.inputBehavior === "autohighlight",
|
|
657
|
+
hasSelectedItems: (ctx) => ctx.value.length > 0
|
|
660
658
|
},
|
|
661
659
|
watch: {
|
|
662
660
|
value: ["syncSelectedItems"],
|
|
@@ -798,8 +796,7 @@ function machine(userContext) {
|
|
|
798
796
|
],
|
|
799
797
|
"INPUT.ARROW_UP": [
|
|
800
798
|
{
|
|
801
|
-
guard: "autoComplete",
|
|
802
|
-
target: "interacting",
|
|
799
|
+
guard: and("isOpenControlled", "autoComplete"),
|
|
803
800
|
actions: "invokeOnOpen"
|
|
804
801
|
},
|
|
805
802
|
{
|
|
@@ -808,7 +805,7 @@ function machine(userContext) {
|
|
|
808
805
|
actions: "invokeOnOpen"
|
|
809
806
|
},
|
|
810
807
|
{
|
|
811
|
-
|
|
808
|
+
guard: "isOpenControlled",
|
|
812
809
|
actions: ["highlightLastOrSelectedItem", "invokeOnOpen"]
|
|
813
810
|
},
|
|
814
811
|
{
|
|
@@ -1120,37 +1117,37 @@ function machine(userContext) {
|
|
|
1120
1117
|
}
|
|
1121
1118
|
}, {
|
|
1122
1119
|
guards: {
|
|
1123
|
-
isInputValueEmpty: (ctx
|
|
1124
|
-
autoComplete: (ctx
|
|
1125
|
-
autoHighlight: (ctx
|
|
1126
|
-
isFirstItemHighlighted: (ctx
|
|
1127
|
-
isLastItemHighlighted: (ctx
|
|
1128
|
-
isCustomValue: (ctx
|
|
1129
|
-
allowCustomValue: (ctx
|
|
1130
|
-
hasHighlightedItem: (ctx
|
|
1131
|
-
closeOnSelect: (ctx
|
|
1132
|
-
isOpenControlled: (ctx
|
|
1133
|
-
openOnChange: (ctx
|
|
1134
|
-
if (isBoolean(ctx
|
|
1135
|
-
return !!ctx
|
|
1120
|
+
isInputValueEmpty: (ctx) => ctx.isInputValueEmpty,
|
|
1121
|
+
autoComplete: (ctx) => ctx.autoComplete && !ctx.multiple,
|
|
1122
|
+
autoHighlight: (ctx) => ctx.autoHighlight,
|
|
1123
|
+
isFirstItemHighlighted: (ctx) => ctx.collection.firstValue === ctx.highlightedValue,
|
|
1124
|
+
isLastItemHighlighted: (ctx) => ctx.collection.lastValue === ctx.highlightedValue,
|
|
1125
|
+
isCustomValue: (ctx) => ctx.inputValue !== ctx.valueAsString,
|
|
1126
|
+
allowCustomValue: (ctx) => !!ctx.allowCustomValue,
|
|
1127
|
+
hasHighlightedItem: (ctx) => ctx.highlightedValue != null,
|
|
1128
|
+
closeOnSelect: (ctx) => !!ctx.closeOnSelect,
|
|
1129
|
+
isOpenControlled: (ctx) => isControlled(ctx, "open"),
|
|
1130
|
+
openOnChange: (ctx, evt) => {
|
|
1131
|
+
if (isBoolean(ctx.openOnChange)) return ctx.openOnChange;
|
|
1132
|
+
return !!ctx.openOnChange?.({ inputValue: evt.value });
|
|
1136
1133
|
},
|
|
1137
1134
|
restoreFocus: (_ctx, evt) => evt.restoreFocus == null ? true : !!evt.restoreFocus,
|
|
1138
1135
|
isChangeEvent: (_ctx, evt) => evt.previousEvent?.type === "INPUT.CHANGE"
|
|
1139
1136
|
},
|
|
1140
1137
|
activities: {
|
|
1141
|
-
trackDismissableLayer(ctx
|
|
1142
|
-
if (ctx
|
|
1143
|
-
const contentEl = () => dom.getContentEl(ctx
|
|
1138
|
+
trackDismissableLayer(ctx, _evt, { send }) {
|
|
1139
|
+
if (ctx.disableLayer) return;
|
|
1140
|
+
const contentEl = () => dom.getContentEl(ctx);
|
|
1144
1141
|
return trackDismissableElement(contentEl, {
|
|
1145
1142
|
defer: true,
|
|
1146
1143
|
exclude: () => [
|
|
1147
|
-
dom.getInputEl(ctx
|
|
1148
|
-
dom.getTriggerEl(ctx
|
|
1149
|
-
dom.getClearTriggerEl(ctx
|
|
1144
|
+
dom.getInputEl(ctx),
|
|
1145
|
+
dom.getTriggerEl(ctx),
|
|
1146
|
+
dom.getClearTriggerEl(ctx)
|
|
1150
1147
|
],
|
|
1151
|
-
onFocusOutside: ctx
|
|
1152
|
-
onPointerDownOutside: ctx
|
|
1153
|
-
onInteractOutside: ctx
|
|
1148
|
+
onFocusOutside: ctx.onFocusOutside,
|
|
1149
|
+
onPointerDownOutside: ctx.onPointerDownOutside,
|
|
1150
|
+
onInteractOutside: ctx.onInteractOutside,
|
|
1154
1151
|
onEscapeKeyDown(event) {
|
|
1155
1152
|
event.preventDefault();
|
|
1156
1153
|
event.stopPropagation();
|
|
@@ -1164,57 +1161,57 @@ function machine(userContext) {
|
|
|
1164
1161
|
}
|
|
1165
1162
|
});
|
|
1166
1163
|
},
|
|
1167
|
-
hideOtherElements(ctx
|
|
1164
|
+
hideOtherElements(ctx) {
|
|
1168
1165
|
return ariaHidden([
|
|
1169
|
-
dom.getInputEl(ctx
|
|
1170
|
-
dom.getContentEl(ctx
|
|
1171
|
-
dom.getTriggerEl(ctx
|
|
1172
|
-
dom.getClearTriggerEl(ctx
|
|
1166
|
+
dom.getInputEl(ctx),
|
|
1167
|
+
dom.getContentEl(ctx),
|
|
1168
|
+
dom.getTriggerEl(ctx),
|
|
1169
|
+
dom.getClearTriggerEl(ctx)
|
|
1173
1170
|
]);
|
|
1174
1171
|
},
|
|
1175
|
-
computePlacement(ctx
|
|
1176
|
-
const controlEl = () => dom.getControlEl(ctx
|
|
1177
|
-
const positionerEl = () => dom.getPositionerEl(ctx
|
|
1178
|
-
ctx
|
|
1172
|
+
computePlacement(ctx) {
|
|
1173
|
+
const controlEl = () => dom.getControlEl(ctx);
|
|
1174
|
+
const positionerEl = () => dom.getPositionerEl(ctx);
|
|
1175
|
+
ctx.currentPlacement = ctx.positioning.placement;
|
|
1179
1176
|
return getPlacement(controlEl, positionerEl, {
|
|
1180
|
-
...ctx
|
|
1177
|
+
...ctx.positioning,
|
|
1181
1178
|
defer: true,
|
|
1182
1179
|
onComplete(data) {
|
|
1183
|
-
ctx
|
|
1180
|
+
ctx.currentPlacement = data.placement;
|
|
1184
1181
|
}
|
|
1185
1182
|
});
|
|
1186
1183
|
},
|
|
1187
|
-
trackChildNodes(ctx
|
|
1188
|
-
if (!ctx
|
|
1184
|
+
trackChildNodes(ctx, _evt, { send }) {
|
|
1185
|
+
if (!ctx.autoHighlight) return;
|
|
1189
1186
|
const exec = () => send("CHILDREN_CHANGE");
|
|
1190
|
-
const contentEl = () => dom.getContentEl(ctx
|
|
1187
|
+
const contentEl = () => dom.getContentEl(ctx);
|
|
1191
1188
|
return observeChildren(contentEl, {
|
|
1192
1189
|
callback: exec,
|
|
1193
1190
|
defer: true
|
|
1194
1191
|
});
|
|
1195
1192
|
},
|
|
1196
|
-
scrollToHighlightedItem(ctx
|
|
1197
|
-
const inputEl = dom.getInputEl(ctx
|
|
1193
|
+
scrollToHighlightedItem(ctx, _evt, { getState }) {
|
|
1194
|
+
const inputEl = dom.getInputEl(ctx);
|
|
1198
1195
|
const cleanups = [];
|
|
1199
1196
|
const exec = (immediate) => {
|
|
1200
|
-
if (getState().event.type.includes("POINTER") || !ctx
|
|
1201
|
-
const itemEl = dom.getHighlightedItemEl(ctx
|
|
1202
|
-
const contentEl = dom.getContentEl(ctx
|
|
1203
|
-
if (ctx
|
|
1204
|
-
const highlightedIndex = ctx
|
|
1205
|
-
ctx
|
|
1197
|
+
if (getState().event.type.includes("POINTER") || !ctx.highlightedValue) return;
|
|
1198
|
+
const itemEl = dom.getHighlightedItemEl(ctx);
|
|
1199
|
+
const contentEl = dom.getContentEl(ctx);
|
|
1200
|
+
if (ctx.scrollToIndexFn) {
|
|
1201
|
+
const highlightedIndex = ctx.collection.indexOf(ctx.highlightedValue);
|
|
1202
|
+
ctx.scrollToIndexFn({
|
|
1206
1203
|
index: highlightedIndex,
|
|
1207
1204
|
immediate
|
|
1208
1205
|
});
|
|
1209
1206
|
return;
|
|
1210
1207
|
}
|
|
1211
|
-
const rafCleanup
|
|
1208
|
+
const rafCleanup = raf(() => {
|
|
1212
1209
|
scrollIntoView(itemEl, {
|
|
1213
1210
|
rootEl: contentEl,
|
|
1214
1211
|
block: "nearest"
|
|
1215
1212
|
});
|
|
1216
1213
|
});
|
|
1217
|
-
cleanups.push(rafCleanup
|
|
1214
|
+
cleanups.push(rafCleanup);
|
|
1218
1215
|
};
|
|
1219
1216
|
const rafCleanup = raf(() => exec(true));
|
|
1220
1217
|
cleanups.push(rafCleanup);
|
|
@@ -1229,56 +1226,56 @@ function machine(userContext) {
|
|
|
1229
1226
|
}
|
|
1230
1227
|
},
|
|
1231
1228
|
actions: {
|
|
1232
|
-
reposition(ctx
|
|
1233
|
-
const controlEl = () => dom.getControlEl(ctx
|
|
1234
|
-
const positionerEl = () => dom.getPositionerEl(ctx
|
|
1229
|
+
reposition(ctx, evt) {
|
|
1230
|
+
const controlEl = () => dom.getControlEl(ctx);
|
|
1231
|
+
const positionerEl = () => dom.getPositionerEl(ctx);
|
|
1235
1232
|
getPlacement(controlEl, positionerEl, {
|
|
1236
|
-
...ctx
|
|
1233
|
+
...ctx.positioning,
|
|
1237
1234
|
...evt.options,
|
|
1238
1235
|
defer: true,
|
|
1239
1236
|
listeners: false,
|
|
1240
1237
|
onComplete(data) {
|
|
1241
|
-
ctx
|
|
1238
|
+
ctx.currentPlacement = data.placement;
|
|
1242
1239
|
}
|
|
1243
1240
|
});
|
|
1244
1241
|
},
|
|
1245
|
-
setHighlightedItem(ctx
|
|
1242
|
+
setHighlightedItem(ctx, evt) {
|
|
1246
1243
|
if (evt.value == null) return;
|
|
1247
|
-
set.highlightedValue(ctx
|
|
1244
|
+
set.highlightedValue(ctx, evt.value);
|
|
1248
1245
|
},
|
|
1249
|
-
clearHighlightedItem(ctx
|
|
1250
|
-
set.highlightedValue(ctx
|
|
1246
|
+
clearHighlightedItem(ctx) {
|
|
1247
|
+
set.highlightedValue(ctx, null, true);
|
|
1251
1248
|
},
|
|
1252
|
-
selectHighlightedItem(ctx
|
|
1253
|
-
set.value(ctx
|
|
1254
|
-
set.inputValue(ctx
|
|
1249
|
+
selectHighlightedItem(ctx) {
|
|
1250
|
+
set.value(ctx, ctx.highlightedValue);
|
|
1251
|
+
set.inputValue(ctx, getInputValue(ctx));
|
|
1255
1252
|
},
|
|
1256
|
-
selectItem(ctx
|
|
1253
|
+
selectItem(ctx, evt) {
|
|
1257
1254
|
if (evt.value == null) return;
|
|
1258
|
-
set.value(ctx
|
|
1259
|
-
set.inputValue(ctx
|
|
1255
|
+
set.value(ctx, evt.value);
|
|
1256
|
+
set.inputValue(ctx, getInputValue(ctx));
|
|
1260
1257
|
},
|
|
1261
|
-
clearItem(ctx
|
|
1258
|
+
clearItem(ctx, evt) {
|
|
1262
1259
|
if (evt.value == null) return;
|
|
1263
|
-
const value = ctx
|
|
1264
|
-
set.value(ctx
|
|
1265
|
-
set.inputValue(ctx
|
|
1260
|
+
const value = ctx.value.filter((v) => v !== evt.value);
|
|
1261
|
+
set.value(ctx, value);
|
|
1262
|
+
set.inputValue(ctx, getInputValue(ctx));
|
|
1266
1263
|
},
|
|
1267
|
-
setInitialFocus(ctx
|
|
1264
|
+
setInitialFocus(ctx) {
|
|
1268
1265
|
raf(() => {
|
|
1269
|
-
dom.focusInputEl(ctx
|
|
1266
|
+
dom.focusInputEl(ctx);
|
|
1270
1267
|
});
|
|
1271
1268
|
},
|
|
1272
|
-
setFinalFocus(ctx
|
|
1269
|
+
setFinalFocus(ctx) {
|
|
1273
1270
|
raf(() => {
|
|
1274
|
-
if (dom.getTriggerEl(ctx
|
|
1275
|
-
else dom.focusTriggerEl(ctx
|
|
1271
|
+
if (dom.getTriggerEl(ctx)?.dataset.focusable == null) dom.focusInputEl(ctx);
|
|
1272
|
+
else dom.focusTriggerEl(ctx);
|
|
1276
1273
|
});
|
|
1277
1274
|
},
|
|
1278
|
-
syncInputValue(ctx
|
|
1279
|
-
const inputEl = dom.getInputEl(ctx
|
|
1275
|
+
syncInputValue(ctx) {
|
|
1276
|
+
const inputEl = dom.getInputEl(ctx);
|
|
1280
1277
|
if (!inputEl) return;
|
|
1281
|
-
inputEl.value = ctx
|
|
1278
|
+
inputEl.value = ctx.inputValue;
|
|
1282
1279
|
queueMicrotask(() => {
|
|
1283
1280
|
const { selectionStart, selectionEnd } = inputEl;
|
|
1284
1281
|
if (Math.abs((selectionEnd ?? 0) - (selectionStart ?? 0)) !== 0) return;
|
|
@@ -1286,146 +1283,145 @@ function machine(userContext) {
|
|
|
1286
1283
|
inputEl.setSelectionRange(inputEl.value.length, inputEl.value.length);
|
|
1287
1284
|
});
|
|
1288
1285
|
},
|
|
1289
|
-
setInputValue(ctx
|
|
1290
|
-
set.inputValue(ctx
|
|
1286
|
+
setInputValue(ctx, evt) {
|
|
1287
|
+
set.inputValue(ctx, evt.value);
|
|
1291
1288
|
},
|
|
1292
|
-
clearInputValue(ctx
|
|
1293
|
-
set.inputValue(ctx
|
|
1289
|
+
clearInputValue(ctx) {
|
|
1290
|
+
set.inputValue(ctx, "");
|
|
1294
1291
|
},
|
|
1295
|
-
revertInputValue(ctx
|
|
1296
|
-
const inputValue = match(ctx
|
|
1297
|
-
replace: ctx
|
|
1298
|
-
preserve: ctx
|
|
1292
|
+
revertInputValue(ctx) {
|
|
1293
|
+
const inputValue = match(ctx.selectionBehavior, {
|
|
1294
|
+
replace: ctx.hasSelectedItems ? ctx.valueAsString : "",
|
|
1295
|
+
preserve: ctx.inputValue,
|
|
1299
1296
|
clear: ""
|
|
1300
1297
|
});
|
|
1301
|
-
set.inputValue(ctx
|
|
1298
|
+
set.inputValue(ctx, inputValue);
|
|
1302
1299
|
},
|
|
1303
|
-
syncInitialValues(ctx
|
|
1304
|
-
const selectedItems = ctx
|
|
1305
|
-
const valueAsString = ctx
|
|
1306
|
-
ctx
|
|
1307
|
-
ctx
|
|
1308
|
-
ctx
|
|
1309
|
-
if (ctx
|
|
1310
|
-
ctx
|
|
1311
|
-
preserve: ctx
|
|
1300
|
+
syncInitialValues(ctx) {
|
|
1301
|
+
const selectedItems = ctx.collection.findMany(ctx.value);
|
|
1302
|
+
const valueAsString = ctx.collection.stringifyMany(ctx.value);
|
|
1303
|
+
ctx.highlightedItem = ctx.collection.find(ctx.highlightedValue);
|
|
1304
|
+
ctx.selectedItems = selectedItems;
|
|
1305
|
+
ctx.valueAsString = valueAsString;
|
|
1306
|
+
if (isControlled(ctx, "inputValue") || ctx.inputValue.trim() || ctx.multiple) return;
|
|
1307
|
+
ctx.inputValue = match(ctx.selectionBehavior, {
|
|
1308
|
+
preserve: ctx.inputValue || valueAsString,
|
|
1312
1309
|
replace: valueAsString,
|
|
1313
1310
|
clear: ""
|
|
1314
1311
|
});
|
|
1315
1312
|
},
|
|
1316
|
-
syncSelectionBehavior(ctx
|
|
1317
|
-
if (ctx
|
|
1313
|
+
syncSelectionBehavior(ctx) {
|
|
1314
|
+
if (ctx.multiple) ctx.selectionBehavior = "clear";
|
|
1318
1315
|
},
|
|
1319
|
-
setSelectedItems(ctx
|
|
1316
|
+
setSelectedItems(ctx, evt) {
|
|
1320
1317
|
if (!isArray(evt.value)) return;
|
|
1321
|
-
set.value(ctx
|
|
1322
|
-
set.inputValue(ctx
|
|
1318
|
+
set.value(ctx, evt.value);
|
|
1319
|
+
set.inputValue(ctx, getInputValue(ctx));
|
|
1323
1320
|
},
|
|
1324
|
-
clearSelectedItems(ctx
|
|
1325
|
-
set.value(ctx
|
|
1326
|
-
set.inputValue(ctx
|
|
1321
|
+
clearSelectedItems(ctx) {
|
|
1322
|
+
set.value(ctx, []);
|
|
1323
|
+
set.inputValue(ctx, getInputValue(ctx));
|
|
1327
1324
|
},
|
|
1328
|
-
scrollContentToTop(ctx
|
|
1329
|
-
if (ctx
|
|
1325
|
+
scrollContentToTop(ctx) {
|
|
1326
|
+
if (ctx.scrollToIndexFn) ctx.scrollToIndexFn({
|
|
1330
1327
|
index: 0,
|
|
1331
1328
|
immediate: true
|
|
1332
1329
|
});
|
|
1333
1330
|
else {
|
|
1334
|
-
const contentEl = dom.getContentEl(ctx
|
|
1331
|
+
const contentEl = dom.getContentEl(ctx);
|
|
1335
1332
|
if (!contentEl) return;
|
|
1336
1333
|
contentEl.scrollTop = 0;
|
|
1337
1334
|
}
|
|
1338
1335
|
},
|
|
1339
|
-
invokeOnOpen(ctx
|
|
1340
|
-
ctx
|
|
1336
|
+
invokeOnOpen(ctx) {
|
|
1337
|
+
ctx.onOpenChange?.({ open: true });
|
|
1341
1338
|
},
|
|
1342
|
-
invokeOnClose(ctx
|
|
1343
|
-
ctx
|
|
1339
|
+
invokeOnClose(ctx) {
|
|
1340
|
+
ctx.onOpenChange?.({ open: false });
|
|
1344
1341
|
},
|
|
1345
|
-
highlightFirstItem(ctx
|
|
1342
|
+
highlightFirstItem(ctx) {
|
|
1346
1343
|
raf(() => {
|
|
1347
|
-
const value = ctx
|
|
1348
|
-
set.highlightedValue(ctx
|
|
1344
|
+
const value = ctx.collection.firstValue;
|
|
1345
|
+
set.highlightedValue(ctx, value, true);
|
|
1349
1346
|
});
|
|
1350
1347
|
},
|
|
1351
|
-
highlightFirstItemIfNeeded(ctx
|
|
1352
|
-
if (!ctx
|
|
1348
|
+
highlightFirstItemIfNeeded(ctx) {
|
|
1349
|
+
if (!ctx.autoHighlight) return;
|
|
1353
1350
|
raf(() => {
|
|
1354
|
-
const value = ctx
|
|
1355
|
-
set.highlightedValue(ctx
|
|
1351
|
+
const value = ctx.collection.firstValue;
|
|
1352
|
+
set.highlightedValue(ctx, value);
|
|
1356
1353
|
});
|
|
1357
1354
|
},
|
|
1358
|
-
highlightLastItem(ctx
|
|
1355
|
+
highlightLastItem(ctx) {
|
|
1359
1356
|
raf(() => {
|
|
1360
|
-
const value = ctx
|
|
1361
|
-
set.highlightedValue(ctx
|
|
1357
|
+
const value = ctx.collection.lastValue;
|
|
1358
|
+
set.highlightedValue(ctx, value);
|
|
1362
1359
|
});
|
|
1363
1360
|
},
|
|
1364
|
-
highlightNextItem(ctx
|
|
1361
|
+
highlightNextItem(ctx) {
|
|
1365
1362
|
let value = null;
|
|
1366
|
-
if (ctx
|
|
1367
|
-
value = ctx
|
|
1368
|
-
if (!value && ctx
|
|
1369
|
-
} else value = ctx
|
|
1370
|
-
set.highlightedValue(ctx
|
|
1363
|
+
if (ctx.highlightedValue) {
|
|
1364
|
+
value = ctx.collection.getNextValue(ctx.highlightedValue);
|
|
1365
|
+
if (!value && ctx.loopFocus) value = ctx.collection.firstValue;
|
|
1366
|
+
} else value = ctx.collection.firstValue;
|
|
1367
|
+
set.highlightedValue(ctx, value);
|
|
1371
1368
|
},
|
|
1372
|
-
highlightPrevItem(ctx
|
|
1369
|
+
highlightPrevItem(ctx) {
|
|
1373
1370
|
let value = null;
|
|
1374
|
-
if (ctx
|
|
1375
|
-
value = ctx
|
|
1376
|
-
if (!value && ctx
|
|
1377
|
-
} else value = ctx
|
|
1378
|
-
set.highlightedValue(ctx
|
|
1371
|
+
if (ctx.highlightedValue) {
|
|
1372
|
+
value = ctx.collection.getPreviousValue(ctx.highlightedValue);
|
|
1373
|
+
if (!value && ctx.loopFocus) value = ctx.collection.lastValue;
|
|
1374
|
+
} else value = ctx.collection.lastValue;
|
|
1375
|
+
set.highlightedValue(ctx, value);
|
|
1379
1376
|
},
|
|
1380
|
-
highlightFirstSelectedItem(ctx
|
|
1377
|
+
highlightFirstSelectedItem(ctx) {
|
|
1381
1378
|
raf(() => {
|
|
1382
|
-
const [value] = ctx
|
|
1383
|
-
set.highlightedValue(ctx
|
|
1379
|
+
const [value] = ctx.collection.sort(ctx.value);
|
|
1380
|
+
set.highlightedValue(ctx, value);
|
|
1384
1381
|
});
|
|
1385
1382
|
},
|
|
1386
|
-
highlightFirstOrSelectedItem(ctx
|
|
1383
|
+
highlightFirstOrSelectedItem(ctx) {
|
|
1387
1384
|
raf(() => {
|
|
1388
1385
|
let value = null;
|
|
1389
|
-
if (ctx
|
|
1390
|
-
else value = ctx
|
|
1391
|
-
set.highlightedValue(ctx
|
|
1386
|
+
if (ctx.hasSelectedItems) value = ctx.collection.sort(ctx.value)[0];
|
|
1387
|
+
else value = ctx.collection.firstValue;
|
|
1388
|
+
set.highlightedValue(ctx, value);
|
|
1392
1389
|
});
|
|
1393
1390
|
},
|
|
1394
|
-
highlightLastOrSelectedItem(ctx
|
|
1391
|
+
highlightLastOrSelectedItem(ctx) {
|
|
1395
1392
|
raf(() => {
|
|
1396
1393
|
let value = null;
|
|
1397
|
-
if (ctx
|
|
1398
|
-
else value = ctx
|
|
1399
|
-
set.highlightedValue(ctx
|
|
1394
|
+
if (ctx.hasSelectedItems) value = ctx.collection.sort(ctx.value)[0];
|
|
1395
|
+
else value = ctx.collection.lastValue;
|
|
1396
|
+
set.highlightedValue(ctx, value);
|
|
1400
1397
|
});
|
|
1401
1398
|
},
|
|
1402
|
-
autofillInputValue(ctx
|
|
1403
|
-
const inputEl = dom.getInputEl(ctx
|
|
1404
|
-
if (!ctx
|
|
1405
|
-
const valueText = ctx
|
|
1399
|
+
autofillInputValue(ctx, evt) {
|
|
1400
|
+
const inputEl = dom.getInputEl(ctx);
|
|
1401
|
+
if (!ctx.autoComplete || !inputEl || !evt.keypress) return;
|
|
1402
|
+
const valueText = ctx.collection.stringify(ctx.highlightedValue);
|
|
1406
1403
|
raf(() => {
|
|
1407
|
-
inputEl.value = valueText || ctx
|
|
1404
|
+
inputEl.value = valueText || ctx.inputValue;
|
|
1408
1405
|
});
|
|
1409
1406
|
},
|
|
1410
|
-
setCollection(ctx
|
|
1411
|
-
ctx
|
|
1407
|
+
setCollection(ctx, evt) {
|
|
1408
|
+
ctx.collection = evt.value;
|
|
1412
1409
|
},
|
|
1413
|
-
syncSelectedItems(ctx
|
|
1414
|
-
sync.valueChange(ctx
|
|
1415
|
-
set.inputValue(ctx
|
|
1410
|
+
syncSelectedItems(ctx) {
|
|
1411
|
+
sync.valueChange(ctx);
|
|
1412
|
+
set.inputValue(ctx, getInputValue(ctx));
|
|
1416
1413
|
},
|
|
1417
|
-
syncHighlightedItem(ctx
|
|
1418
|
-
sync.highlightChange(ctx
|
|
1414
|
+
syncHighlightedItem(ctx) {
|
|
1415
|
+
sync.highlightChange(ctx);
|
|
1419
1416
|
},
|
|
1420
|
-
toggleVisibility(ctx
|
|
1417
|
+
toggleVisibility(ctx, evt, { send }) {
|
|
1421
1418
|
send({
|
|
1422
|
-
type: ctx
|
|
1419
|
+
type: ctx.open ? "CONTROLLED.OPEN" : "CONTROLLED.CLOSE",
|
|
1423
1420
|
previousEvent: evt
|
|
1424
1421
|
});
|
|
1425
1422
|
}
|
|
1426
1423
|
}
|
|
1427
1424
|
});
|
|
1428
1425
|
}
|
|
1429
|
-
|
|
1430
1426
|
//#endregion
|
|
1431
|
-
export { anatomy, collection, connect, machine };
|
|
1427
|
+
export { anatomy, collection, connect, machine };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@destyler/combobox",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.12",
|
|
5
5
|
"description": "autocomplete input and command palette with a list of suggestions.",
|
|
6
6
|
"author": "Elone Hoo <elonehoo@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@destyler/
|
|
26
|
-
"@destyler/
|
|
27
|
-
"@destyler/collection": "0.2.
|
|
28
|
-
"@destyler/
|
|
29
|
-
"@destyler/
|
|
30
|
-
"@destyler/popper": "0.2.
|
|
31
|
-
"@destyler/
|
|
32
|
-
"@destyler/
|
|
33
|
-
"@destyler/
|
|
25
|
+
"@destyler/anatomy": "0.2.12",
|
|
26
|
+
"@destyler/aria-hidden": "0.2.12",
|
|
27
|
+
"@destyler/collection": "0.2.12",
|
|
28
|
+
"@destyler/dismissable": "0.2.12",
|
|
29
|
+
"@destyler/dom": "0.2.12",
|
|
30
|
+
"@destyler/popper": "0.2.12",
|
|
31
|
+
"@destyler/types": "0.2.12",
|
|
32
|
+
"@destyler/utils": "0.2.12",
|
|
33
|
+
"@destyler/xstate": "0.2.12"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|