@destyler/dynamic 0.2.10 → 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 +8 -11
- package/dist/index.mjs +199 -206
- package/package.json +9 -9
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import * as _destyler_anatomy0 from "@destyler/anatomy";
|
|
2
1
|
import { FocusOutsideEvent, InteractOutsideEvent, InteractOutsideHandlers, PointerDownOutsideEvent } from "@destyler/interact-outside";
|
|
3
2
|
import { LiveRegion } from "@destyler/live-region";
|
|
4
|
-
import * as _destyler_xstate0 from "@destyler/xstate";
|
|
5
3
|
import { AnyEventObject, XSend, XState } from "@destyler/xstate";
|
|
6
4
|
import { CommonProperties, DirectionProperty, NormalizeProps, PropTypes, RequiredBy } from "@destyler/types";
|
|
7
|
-
|
|
8
5
|
//#region src/anatomy.d.ts
|
|
9
|
-
declare const anatomy:
|
|
6
|
+
export declare const anatomy: import("@destyler/anatomy").AnatomyInstance<"root" | "label" | "control" | "input" | "clearTrigger" | "item" | "itemPreview" | "itemInput" | "itemText" | "itemDeleteTrigger">;
|
|
10
7
|
//#endregion
|
|
11
8
|
//#region src/types.d.ts
|
|
12
9
|
interface ValueChangeDetails {
|
|
@@ -345,15 +342,15 @@ interface MachineApi<T extends PropTypes = PropTypes> {
|
|
|
345
342
|
}
|
|
346
343
|
//#endregion
|
|
347
344
|
//#region src/connect.d.ts
|
|
348
|
-
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
|
|
345
|
+
export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
|
|
349
346
|
//#endregion
|
|
350
347
|
//#region src/machine.d.ts
|
|
351
|
-
declare function machine(userContext: UserDefinedContext):
|
|
348
|
+
export declare function machine(userContext: UserDefinedContext): import("@destyler/xstate").Machine<MachineContext, MachineState, import("@destyler/xstate").AnyEventObject>;
|
|
352
349
|
//#endregion
|
|
353
350
|
//#region src/props.d.ts
|
|
354
|
-
declare const props: ("id" | "ids" | "translations" | "maxLength" | "delimiter" | "autoFocus" | "disabled" | "readOnly" | "invalid" | "required" | "editable" | "inputValue" | "value" | "onValueChange" | "onInputValueChange" | "onHighlightChange" | "onValueInvalid" | "validate" | "blurBehavior" | "addOnPaste" | "max" | "allowOverflow" | "name" | "form" | "dir" | "getRootNode" | "onPointerDownOutside" | "onFocusOutside" | "onInteractOutside")[];
|
|
355
|
-
declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "id" | "ids" | "translations" | "maxLength" | "delimiter" | "autoFocus" | "disabled" | "readOnly" | "invalid" | "required" | "editable" | "inputValue" | "value" | "onValueChange" | "onInputValueChange" | "onHighlightChange" | "onValueInvalid" | "validate" | "blurBehavior" | "addOnPaste" | "max" | "allowOverflow" | "name" | "form" | "dir" | "getRootNode" | "onPointerDownOutside" | "onFocusOutside" | "onInteractOutside">];
|
|
356
|
-
declare const itemProps: (keyof ItemProps)[];
|
|
357
|
-
declare const splitItemProps: <Props extends ItemProps>(props: Props) => [ItemProps, Omit<Props, keyof ItemProps>];
|
|
351
|
+
export declare const props: ("id" | "ids" | "translations" | "maxLength" | "delimiter" | "autoFocus" | "disabled" | "readOnly" | "invalid" | "required" | "editable" | "inputValue" | "value" | "onValueChange" | "onInputValueChange" | "onHighlightChange" | "onValueInvalid" | "validate" | "blurBehavior" | "addOnPaste" | "max" | "allowOverflow" | "name" | "form" | "dir" | "getRootNode" | "onPointerDownOutside" | "onFocusOutside" | "onInteractOutside")[];
|
|
352
|
+
export declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "id" | "ids" | "translations" | "maxLength" | "delimiter" | "autoFocus" | "disabled" | "readOnly" | "invalid" | "required" | "editable" | "inputValue" | "value" | "onValueChange" | "onInputValueChange" | "onHighlightChange" | "onValueInvalid" | "validate" | "blurBehavior" | "addOnPaste" | "max" | "allowOverflow" | "name" | "form" | "dir" | "getRootNode" | "onPointerDownOutside" | "onFocusOutside" | "onInteractOutside">];
|
|
353
|
+
export declare const itemProps: (keyof ItemProps)[];
|
|
354
|
+
export declare const splitItemProps: <Props extends ItemProps>(props: Props) => [ItemProps, Omit<Props, keyof ItemProps>];
|
|
358
355
|
//#endregion
|
|
359
|
-
export {
|
|
356
|
+
export type { MachineApi as Api, UserDefinedContext as Context, ElementIds, FocusOutsideEvent, HighlightChangeDetails, InputValueChangeDetails, InteractOutsideEvent, IntlTranslations, ItemProps, ItemState, PointerDownOutsideEvent, ValidateArgs, ValidityChangeDetails, ValueChangeDetails };
|
package/dist/index.mjs
CHANGED
|
@@ -6,11 +6,9 @@ import { createLiveRegion } from "@destyler/live-region";
|
|
|
6
6
|
import { compact, createSplitProps, isEqual, removeAt, uniq } from "@destyler/utils";
|
|
7
7
|
import { createMachine, guards } from "@destyler/xstate";
|
|
8
8
|
import { createProps } from "@destyler/types";
|
|
9
|
-
|
|
10
9
|
//#region src/anatomy.ts
|
|
11
10
|
const anatomy = createAnatomy("dynamic").parts("root", "label", "control", "input", "clearTrigger", "item", "itemPreview", "itemInput", "itemText", "itemDeleteTrigger");
|
|
12
11
|
const parts = anatomy.build();
|
|
13
|
-
|
|
14
12
|
//#endregion
|
|
15
13
|
//#region src/dom.ts
|
|
16
14
|
const dom = createScope({
|
|
@@ -57,7 +55,6 @@ const dom = createScope({
|
|
|
57
55
|
dispatchInputValueEvent(inputEl, { value: ctx.valueAsString });
|
|
58
56
|
}
|
|
59
57
|
});
|
|
60
|
-
|
|
61
58
|
//#endregion
|
|
62
59
|
//#region src/connect.ts
|
|
63
60
|
function connect(state, send, normalize) {
|
|
@@ -217,13 +214,13 @@ function connect(state, send, normalize) {
|
|
|
217
214
|
if (isCombobox && isExpanded) return;
|
|
218
215
|
send("ARROW_LEFT");
|
|
219
216
|
},
|
|
220
|
-
ArrowRight(event
|
|
221
|
-
if (state.context.highlightedTagId) event
|
|
217
|
+
ArrowRight(event) {
|
|
218
|
+
if (state.context.highlightedTagId) event.preventDefault();
|
|
222
219
|
if (isCombobox && isExpanded) return;
|
|
223
220
|
send("ARROW_RIGHT");
|
|
224
221
|
},
|
|
225
|
-
Escape(event
|
|
226
|
-
event
|
|
222
|
+
Escape(event) {
|
|
223
|
+
event.preventDefault();
|
|
227
224
|
send("ESCAPE");
|
|
228
225
|
},
|
|
229
226
|
Backspace() {
|
|
@@ -232,10 +229,10 @@ function connect(state, send, normalize) {
|
|
|
232
229
|
Delete() {
|
|
233
230
|
send("DELETE");
|
|
234
231
|
},
|
|
235
|
-
Enter(event
|
|
232
|
+
Enter(event) {
|
|
236
233
|
if (isCombobox && isExpanded) return;
|
|
237
234
|
send("ENTER");
|
|
238
|
-
event
|
|
235
|
+
event.preventDefault();
|
|
239
236
|
}
|
|
240
237
|
}[getEventKey(event, state.context)];
|
|
241
238
|
if (exec) exec(event);
|
|
@@ -255,22 +252,22 @@ function connect(state, send, normalize) {
|
|
|
255
252
|
defaultValue: state.context.valueAsString
|
|
256
253
|
});
|
|
257
254
|
},
|
|
258
|
-
getItemProps(props
|
|
255
|
+
getItemProps(props) {
|
|
259
256
|
return normalize.element({
|
|
260
257
|
...parts.item.attrs,
|
|
261
258
|
"dir": state.context.dir,
|
|
262
|
-
"data-value": props
|
|
259
|
+
"data-value": props.value,
|
|
263
260
|
"data-disabled": dataAttr(disabled)
|
|
264
261
|
});
|
|
265
262
|
},
|
|
266
|
-
getItemPreviewProps(props
|
|
267
|
-
const itemState = getItemState(props
|
|
263
|
+
getItemPreviewProps(props) {
|
|
264
|
+
const itemState = getItemState(props);
|
|
268
265
|
return normalize.element({
|
|
269
266
|
...parts.itemPreview.attrs,
|
|
270
267
|
"id": itemState.id,
|
|
271
268
|
"dir": state.context.dir,
|
|
272
269
|
"hidden": itemState.editing,
|
|
273
|
-
"data-value": props
|
|
270
|
+
"data-value": props.value,
|
|
274
271
|
"data-disabled": dataAttr(disabled),
|
|
275
272
|
"data-highlighted": dataAttr(itemState.highlighted),
|
|
276
273
|
onPointerDown(event) {
|
|
@@ -290,8 +287,8 @@ function connect(state, send, normalize) {
|
|
|
290
287
|
}
|
|
291
288
|
});
|
|
292
289
|
},
|
|
293
|
-
getItemTextProps(props
|
|
294
|
-
const itemState = getItemState(props
|
|
290
|
+
getItemTextProps(props) {
|
|
291
|
+
const itemState = getItemState(props);
|
|
295
292
|
return normalize.element({
|
|
296
293
|
...parts.itemText.attrs,
|
|
297
294
|
"dir": state.context.dir,
|
|
@@ -299,15 +296,15 @@ function connect(state, send, normalize) {
|
|
|
299
296
|
"data-highlighted": dataAttr(itemState.highlighted)
|
|
300
297
|
});
|
|
301
298
|
},
|
|
302
|
-
getItemInputProps(props
|
|
303
|
-
const itemState = getItemState(props
|
|
299
|
+
getItemInputProps(props) {
|
|
300
|
+
const itemState = getItemState(props);
|
|
304
301
|
return normalize.input({
|
|
305
302
|
...parts.itemInput.attrs,
|
|
306
303
|
"dir": state.context.dir,
|
|
307
|
-
"aria-label": translations.tagEdited(props
|
|
304
|
+
"aria-label": translations.tagEdited(props.value),
|
|
308
305
|
"aria-hidden": true,
|
|
309
306
|
"disabled": disabled,
|
|
310
|
-
"id": dom.getItemInputId(state.context, props
|
|
307
|
+
"id": dom.getItemInputId(state.context, props),
|
|
311
308
|
"tabIndex": -1,
|
|
312
309
|
"hidden": !itemState.editing,
|
|
313
310
|
"defaultValue": itemState.editing ? state.context.editedTagValue : "",
|
|
@@ -320,7 +317,7 @@ function connect(state, send, normalize) {
|
|
|
320
317
|
onBlur(event) {
|
|
321
318
|
send({
|
|
322
319
|
type: "TAG_INPUT_BLUR",
|
|
323
|
-
|
|
320
|
+
relatedTarget: event.relatedTarget,
|
|
324
321
|
id: itemState.id
|
|
325
322
|
});
|
|
326
323
|
},
|
|
@@ -342,15 +339,15 @@ function connect(state, send, normalize) {
|
|
|
342
339
|
}
|
|
343
340
|
});
|
|
344
341
|
},
|
|
345
|
-
getItemDeleteTriggerProps(props
|
|
346
|
-
const id = dom.getItemId(state.context, props
|
|
342
|
+
getItemDeleteTriggerProps(props) {
|
|
343
|
+
const id = dom.getItemId(state.context, props);
|
|
347
344
|
return normalize.button({
|
|
348
345
|
...parts.itemDeleteTrigger.attrs,
|
|
349
346
|
"dir": state.context.dir,
|
|
350
|
-
"id": dom.getItemDeleteTriggerId(state.context, props
|
|
347
|
+
"id": dom.getItemDeleteTriggerId(state.context, props),
|
|
351
348
|
"type": "button",
|
|
352
349
|
"disabled": disabled,
|
|
353
|
-
"aria-label": translations.deleteTagTriggerLabel(props
|
|
350
|
+
"aria-label": translations.deleteTagTriggerLabel(props.value),
|
|
354
351
|
"tabIndex": -1,
|
|
355
352
|
onPointerDown(event) {
|
|
356
353
|
if (!interactive) event.preventDefault();
|
|
@@ -393,9 +390,8 @@ function connect(state, send, normalize) {
|
|
|
393
390
|
function endsWith(str, del) {
|
|
394
391
|
if (!del) return false;
|
|
395
392
|
if (typeof del === "string") return str.endsWith(del);
|
|
396
|
-
return
|
|
393
|
+
return new RegExp(`${del.source}$`).test(str);
|
|
397
394
|
}
|
|
398
|
-
|
|
399
395
|
//#endregion
|
|
400
396
|
//#region src/machine.ts
|
|
401
397
|
const { and, not, or } = guards;
|
|
@@ -474,13 +470,13 @@ function machine(userContext) {
|
|
|
474
470
|
}
|
|
475
471
|
},
|
|
476
472
|
computed: {
|
|
477
|
-
count: (ctx
|
|
478
|
-
valueAsString: (ctx
|
|
479
|
-
trimmedInputValue: (ctx
|
|
480
|
-
isDisabled: (ctx
|
|
481
|
-
isInteractive: (ctx
|
|
482
|
-
isAtMax: (ctx
|
|
483
|
-
isOverflowing: (ctx
|
|
473
|
+
count: (ctx) => ctx.value.length,
|
|
474
|
+
valueAsString: (ctx) => JSON.stringify(ctx.value),
|
|
475
|
+
trimmedInputValue: (ctx) => ctx.inputValue.trim(),
|
|
476
|
+
isDisabled: (ctx) => !!ctx.disabled || ctx.fieldsetDisabled,
|
|
477
|
+
isInteractive: (ctx) => !(ctx.readOnly || ctx.isDisabled),
|
|
478
|
+
isAtMax: (ctx) => ctx.count === ctx.max,
|
|
479
|
+
isOverflowing: (ctx) => ctx.count > ctx.max
|
|
484
480
|
},
|
|
485
481
|
watch: {
|
|
486
482
|
highlightedTagId: "logHighlightedTag",
|
|
@@ -686,33 +682,33 @@ function machine(userContext) {
|
|
|
686
682
|
}
|
|
687
683
|
}, {
|
|
688
684
|
guards: {
|
|
689
|
-
isInputRelatedTarget: (ctx
|
|
690
|
-
isAtMax: (ctx
|
|
691
|
-
hasHighlightedTag: (ctx
|
|
692
|
-
isFirstTagHighlighted: (ctx
|
|
693
|
-
return dom.getItemId(ctx
|
|
694
|
-
value: ctx
|
|
685
|
+
isInputRelatedTarget: (ctx, evt) => evt.relatedTarget != null && evt.relatedTarget === dom.getInputEl(ctx),
|
|
686
|
+
isAtMax: (ctx) => ctx.isAtMax,
|
|
687
|
+
hasHighlightedTag: (ctx) => ctx.highlightedTagId !== null,
|
|
688
|
+
isFirstTagHighlighted: (ctx) => {
|
|
689
|
+
return dom.getItemId(ctx, {
|
|
690
|
+
value: ctx.value[0],
|
|
695
691
|
index: 0
|
|
696
|
-
}) === ctx
|
|
692
|
+
}) === ctx.highlightedTagId;
|
|
697
693
|
},
|
|
698
|
-
isEditedTagEmpty: (ctx
|
|
699
|
-
isLastTagHighlighted: (ctx
|
|
700
|
-
const lastIndex = ctx
|
|
701
|
-
return dom.getItemId(ctx
|
|
702
|
-
value: ctx
|
|
694
|
+
isEditedTagEmpty: (ctx) => ctx.editedTagValue.trim() === "",
|
|
695
|
+
isLastTagHighlighted: (ctx) => {
|
|
696
|
+
const lastIndex = ctx.value.length - 1;
|
|
697
|
+
return dom.getItemId(ctx, {
|
|
698
|
+
value: ctx.value[lastIndex],
|
|
703
699
|
index: lastIndex
|
|
704
|
-
}) === ctx
|
|
700
|
+
}) === ctx.highlightedTagId;
|
|
705
701
|
},
|
|
706
|
-
isInputValueEmpty: (ctx
|
|
707
|
-
hasTags: (ctx
|
|
708
|
-
allowOverflow: (ctx
|
|
709
|
-
autoFocus: (ctx
|
|
710
|
-
addOnBlur: (ctx
|
|
711
|
-
clearOnBlur: (ctx
|
|
712
|
-
addOnPaste: (ctx
|
|
713
|
-
isTagEditable: (ctx
|
|
714
|
-
isInputCaretAtStart(ctx
|
|
715
|
-
const input = dom.getInputEl(ctx
|
|
702
|
+
isInputValueEmpty: (ctx) => ctx.trimmedInputValue.length === 0,
|
|
703
|
+
hasTags: (ctx) => ctx.value.length > 0,
|
|
704
|
+
allowOverflow: (ctx) => !!ctx.allowOverflow,
|
|
705
|
+
autoFocus: (ctx) => !!ctx.autoFocus,
|
|
706
|
+
addOnBlur: (ctx) => ctx.blurBehavior === "add",
|
|
707
|
+
clearOnBlur: (ctx) => ctx.blurBehavior === "clear",
|
|
708
|
+
addOnPaste: (ctx) => !!ctx.addOnPaste,
|
|
709
|
+
isTagEditable: (ctx) => !!ctx.editable,
|
|
710
|
+
isInputCaretAtStart(ctx) {
|
|
711
|
+
const input = dom.getInputEl(ctx);
|
|
716
712
|
if (!input) return false;
|
|
717
713
|
try {
|
|
718
714
|
return input.selectionStart === 0 && input.selectionEnd === 0;
|
|
@@ -722,15 +718,15 @@ function machine(userContext) {
|
|
|
722
718
|
}
|
|
723
719
|
},
|
|
724
720
|
activities: {
|
|
725
|
-
trackInteractOutside(ctx
|
|
726
|
-
return trackInteractOutside(dom.getInputEl(ctx
|
|
721
|
+
trackInteractOutside(ctx, _evt, { send }) {
|
|
722
|
+
return trackInteractOutside(dom.getInputEl(ctx), {
|
|
727
723
|
exclude(target) {
|
|
728
|
-
return contains(dom.getRootEl(ctx
|
|
724
|
+
return contains(dom.getRootEl(ctx), target);
|
|
729
725
|
},
|
|
730
|
-
onFocusOutside: ctx
|
|
731
|
-
onPointerDownOutside: ctx
|
|
726
|
+
onFocusOutside: ctx.onFocusOutside,
|
|
727
|
+
onPointerDownOutside: ctx.onPointerDownOutside,
|
|
732
728
|
onInteractOutside(event) {
|
|
733
|
-
ctx
|
|
729
|
+
ctx.onInteractOutside?.(event);
|
|
734
730
|
if (event.defaultPrevented) return;
|
|
735
731
|
send({
|
|
736
732
|
type: "BLUR",
|
|
@@ -739,10 +735,10 @@ function machine(userContext) {
|
|
|
739
735
|
}
|
|
740
736
|
});
|
|
741
737
|
},
|
|
742
|
-
trackFormControlState(ctx
|
|
743
|
-
return trackFormControl(dom.getHiddenInputEl(ctx
|
|
738
|
+
trackFormControlState(ctx, _evt, { send, initialContext }) {
|
|
739
|
+
return trackFormControl(dom.getHiddenInputEl(ctx), {
|
|
744
740
|
onFieldsetDisabledChange(disabled) {
|
|
745
|
-
ctx
|
|
741
|
+
ctx.fieldsetDisabled = disabled;
|
|
746
742
|
},
|
|
747
743
|
onFormReset() {
|
|
748
744
|
send({
|
|
@@ -753,19 +749,20 @@ function machine(userContext) {
|
|
|
753
749
|
}
|
|
754
750
|
});
|
|
755
751
|
},
|
|
756
|
-
autoResize(ctx
|
|
757
|
-
if (!ctx
|
|
758
|
-
|
|
759
|
-
value: ctx
|
|
760
|
-
index: ctx
|
|
761
|
-
})
|
|
752
|
+
autoResize(ctx) {
|
|
753
|
+
if (!ctx.editedTagValue || ctx.idx == null || !ctx.editable) return;
|
|
754
|
+
const input = dom.getTagInputEl(ctx, {
|
|
755
|
+
value: ctx.editedTagValue,
|
|
756
|
+
index: ctx.idx
|
|
757
|
+
});
|
|
758
|
+
return autoResizeInput(input);
|
|
762
759
|
},
|
|
763
|
-
trackLiveRegion(ctx
|
|
764
|
-
ctx
|
|
760
|
+
trackLiveRegion(ctx) {
|
|
761
|
+
ctx.liveRegion = createLiveRegion({
|
|
765
762
|
level: "assertive",
|
|
766
|
-
document: dom.getDoc(ctx
|
|
763
|
+
document: dom.getDoc(ctx)
|
|
767
764
|
});
|
|
768
|
-
return () => ctx
|
|
765
|
+
return () => ctx.liveRegion?.destroy();
|
|
769
766
|
}
|
|
770
767
|
},
|
|
771
768
|
actions: {
|
|
@@ -778,223 +775,220 @@ function machine(userContext) {
|
|
|
778
775
|
id: evt.id
|
|
779
776
|
});
|
|
780
777
|
},
|
|
781
|
-
dispatchChangeEvent(ctx
|
|
782
|
-
dom.dispatchInputEvent(ctx
|
|
778
|
+
dispatchChangeEvent(ctx) {
|
|
779
|
+
dom.dispatchInputEvent(ctx);
|
|
783
780
|
},
|
|
784
|
-
highlightNextTag(ctx
|
|
785
|
-
if (ctx
|
|
786
|
-
const next = dom.getNextEl(ctx
|
|
787
|
-
set.highlightedId(ctx
|
|
781
|
+
highlightNextTag(ctx) {
|
|
782
|
+
if (ctx.highlightedTagId == null) return;
|
|
783
|
+
const next = dom.getNextEl(ctx, ctx.highlightedTagId);
|
|
784
|
+
set.highlightedId(ctx, next?.id ?? null);
|
|
788
785
|
},
|
|
789
|
-
highlightFirstTag(ctx
|
|
786
|
+
highlightFirstTag(ctx) {
|
|
790
787
|
raf(() => {
|
|
791
|
-
const first = dom.getFirstEl(ctx
|
|
792
|
-
set.highlightedId(ctx
|
|
788
|
+
const first = dom.getFirstEl(ctx);
|
|
789
|
+
set.highlightedId(ctx, first?.id ?? null);
|
|
793
790
|
});
|
|
794
791
|
},
|
|
795
|
-
highlightLastTag(ctx
|
|
796
|
-
const last = dom.getLastEl(ctx
|
|
797
|
-
set.highlightedId(ctx
|
|
792
|
+
highlightLastTag(ctx) {
|
|
793
|
+
const last = dom.getLastEl(ctx);
|
|
794
|
+
set.highlightedId(ctx, last?.id ?? null);
|
|
798
795
|
},
|
|
799
|
-
highlightPrevTag(ctx
|
|
800
|
-
if (ctx
|
|
801
|
-
const prev = dom.getPrevEl(ctx
|
|
802
|
-
set.highlightedId(ctx
|
|
796
|
+
highlightPrevTag(ctx) {
|
|
797
|
+
if (ctx.highlightedTagId == null) return;
|
|
798
|
+
const prev = dom.getPrevEl(ctx, ctx.highlightedTagId);
|
|
799
|
+
set.highlightedId(ctx, prev?.id ?? null);
|
|
803
800
|
},
|
|
804
|
-
highlightTag(ctx
|
|
805
|
-
set.highlightedId(ctx
|
|
801
|
+
highlightTag(ctx, evt) {
|
|
802
|
+
set.highlightedId(ctx, evt.id);
|
|
806
803
|
},
|
|
807
|
-
highlightTagAtIndex(ctx
|
|
804
|
+
highlightTagAtIndex(ctx) {
|
|
808
805
|
raf(() => {
|
|
809
|
-
if (ctx
|
|
810
|
-
const tagEl = dom.getTagElAtIndex(ctx
|
|
806
|
+
if (ctx.idx == null) return;
|
|
807
|
+
const tagEl = dom.getTagElAtIndex(ctx, ctx.idx);
|
|
811
808
|
if (tagEl == null) return;
|
|
812
|
-
set.highlightedId(ctx
|
|
813
|
-
ctx
|
|
809
|
+
set.highlightedId(ctx, tagEl.id);
|
|
810
|
+
ctx.idx = void 0;
|
|
814
811
|
});
|
|
815
812
|
},
|
|
816
|
-
deleteTag(ctx
|
|
817
|
-
const index = dom.getIndexOfId(ctx
|
|
818
|
-
const value = ctx
|
|
819
|
-
ctx
|
|
820
|
-
ctx
|
|
813
|
+
deleteTag(ctx, evt) {
|
|
814
|
+
const index = dom.getIndexOfId(ctx, evt.id);
|
|
815
|
+
const value = ctx.value[index];
|
|
816
|
+
ctx.log.prev = ctx.log.current;
|
|
817
|
+
ctx.log.current = {
|
|
821
818
|
type: "delete",
|
|
822
819
|
value
|
|
823
820
|
};
|
|
824
|
-
set.value(ctx
|
|
821
|
+
set.value(ctx, removeAt(ctx.value, index));
|
|
825
822
|
},
|
|
826
|
-
deleteHighlightedTag(ctx
|
|
827
|
-
if (ctx
|
|
828
|
-
const index = dom.getIndexOfId(ctx
|
|
829
|
-
ctx
|
|
830
|
-
const value = ctx
|
|
831
|
-
ctx
|
|
832
|
-
ctx
|
|
823
|
+
deleteHighlightedTag(ctx) {
|
|
824
|
+
if (ctx.highlightedTagId == null) return;
|
|
825
|
+
const index = dom.getIndexOfId(ctx, ctx.highlightedTagId);
|
|
826
|
+
ctx.idx = index;
|
|
827
|
+
const value = ctx.value[index];
|
|
828
|
+
ctx.log.prev = ctx.log.current;
|
|
829
|
+
ctx.log.current = {
|
|
833
830
|
type: "delete",
|
|
834
831
|
value
|
|
835
832
|
};
|
|
836
|
-
set.value(ctx
|
|
833
|
+
set.value(ctx, removeAt(ctx.value, index));
|
|
837
834
|
},
|
|
838
|
-
setEditedId(ctx
|
|
839
|
-
ctx
|
|
840
|
-
ctx
|
|
835
|
+
setEditedId(ctx, evt) {
|
|
836
|
+
ctx.editedTagId = evt.id ?? ctx.highlightedTagId;
|
|
837
|
+
ctx.idx = dom.getIndexOfId(ctx, ctx.editedTagId);
|
|
841
838
|
},
|
|
842
|
-
clearEditedId(ctx
|
|
843
|
-
ctx
|
|
839
|
+
clearEditedId(ctx) {
|
|
840
|
+
ctx.editedTagId = null;
|
|
844
841
|
},
|
|
845
|
-
clearEditedTagValue(ctx
|
|
846
|
-
ctx
|
|
842
|
+
clearEditedTagValue(ctx) {
|
|
843
|
+
ctx.editedTagValue = "";
|
|
847
844
|
},
|
|
848
|
-
setEditedTagValue(ctx
|
|
849
|
-
ctx
|
|
845
|
+
setEditedTagValue(ctx, evt) {
|
|
846
|
+
ctx.editedTagValue = evt.value;
|
|
850
847
|
},
|
|
851
|
-
submitEditedTagValue(ctx
|
|
852
|
-
if (!ctx
|
|
853
|
-
const index = dom.getIndexOfId(ctx
|
|
854
|
-
set.valueAtIndex(ctx
|
|
855
|
-
ctx
|
|
856
|
-
ctx
|
|
848
|
+
submitEditedTagValue(ctx) {
|
|
849
|
+
if (!ctx.editedTagId) return;
|
|
850
|
+
const index = dom.getIndexOfId(ctx, ctx.editedTagId);
|
|
851
|
+
set.valueAtIndex(ctx, index, ctx.editedTagValue ?? "");
|
|
852
|
+
ctx.log.prev = ctx.log.current;
|
|
853
|
+
ctx.log.current = {
|
|
857
854
|
type: "update",
|
|
858
|
-
value: ctx
|
|
855
|
+
value: ctx.editedTagValue
|
|
859
856
|
};
|
|
860
857
|
},
|
|
861
|
-
setValueAtIndex(ctx
|
|
858
|
+
setValueAtIndex(ctx, evt) {
|
|
862
859
|
if (evt.value) {
|
|
863
|
-
ctx
|
|
864
|
-
ctx
|
|
865
|
-
ctx
|
|
860
|
+
set.valueAtIndex(ctx, evt.index, evt.value);
|
|
861
|
+
ctx.log.prev = ctx.log.current;
|
|
862
|
+
ctx.log.current = {
|
|
866
863
|
type: "update",
|
|
867
864
|
value: evt.value
|
|
868
865
|
};
|
|
869
866
|
} else throw new Error("You need to provide a value for the tag");
|
|
870
867
|
},
|
|
871
|
-
initializeEditedTagValue(ctx
|
|
872
|
-
if (!ctx
|
|
873
|
-
const index = dom.getIndexOfId(ctx
|
|
874
|
-
ctx
|
|
868
|
+
initializeEditedTagValue(ctx) {
|
|
869
|
+
if (!ctx.editedTagId) return;
|
|
870
|
+
const index = dom.getIndexOfId(ctx, ctx.editedTagId);
|
|
871
|
+
ctx.editedTagValue = ctx.value[index];
|
|
875
872
|
},
|
|
876
|
-
focusEditedTagInput(ctx
|
|
873
|
+
focusEditedTagInput(ctx) {
|
|
877
874
|
raf(() => {
|
|
878
|
-
dom.getEditInputEl(ctx
|
|
875
|
+
dom.getEditInputEl(ctx)?.select();
|
|
879
876
|
});
|
|
880
877
|
},
|
|
881
|
-
setInputValue(ctx
|
|
882
|
-
set.inputValue(ctx
|
|
878
|
+
setInputValue(ctx, evt) {
|
|
879
|
+
set.inputValue(ctx, evt.value);
|
|
883
880
|
},
|
|
884
|
-
clearHighlightedId(ctx
|
|
885
|
-
ctx
|
|
881
|
+
clearHighlightedId(ctx) {
|
|
882
|
+
ctx.highlightedTagId = null;
|
|
886
883
|
},
|
|
887
|
-
focusInput(ctx
|
|
884
|
+
focusInput(ctx) {
|
|
888
885
|
raf(() => {
|
|
889
|
-
dom.getInputEl(ctx
|
|
886
|
+
dom.getInputEl(ctx)?.focus();
|
|
890
887
|
});
|
|
891
888
|
},
|
|
892
|
-
clearInputValue(ctx
|
|
889
|
+
clearInputValue(ctx) {
|
|
893
890
|
raf(() => {
|
|
894
|
-
set.inputValue(ctx
|
|
891
|
+
set.inputValue(ctx, "");
|
|
895
892
|
});
|
|
896
893
|
},
|
|
897
|
-
syncInputValue(ctx
|
|
898
|
-
const inputEl = dom.getInputEl(ctx
|
|
899
|
-
dom.setValue(inputEl, ctx
|
|
894
|
+
syncInputValue(ctx) {
|
|
895
|
+
const inputEl = dom.getInputEl(ctx);
|
|
896
|
+
dom.setValue(inputEl, ctx.inputValue);
|
|
900
897
|
},
|
|
901
|
-
syncEditedTagInputValue(ctx
|
|
902
|
-
const id = ctx
|
|
898
|
+
syncEditedTagInputValue(ctx, evt) {
|
|
899
|
+
const id = ctx.editedTagId || ctx.highlightedTagId || evt.id;
|
|
903
900
|
if (id == null) return;
|
|
904
|
-
const editTagInputEl = dom.getById(ctx
|
|
905
|
-
dom.setValue(editTagInputEl, ctx
|
|
901
|
+
const editTagInputEl = dom.getById(ctx, `${id}:input`);
|
|
902
|
+
dom.setValue(editTagInputEl, ctx.editedTagValue);
|
|
906
903
|
},
|
|
907
|
-
addTag(ctx
|
|
908
|
-
const value = evt.value ?? ctx
|
|
909
|
-
if (ctx
|
|
904
|
+
addTag(ctx, evt) {
|
|
905
|
+
const value = evt.value ?? ctx.trimmedInputValue;
|
|
906
|
+
if (ctx.validate?.({
|
|
910
907
|
inputValue: value,
|
|
911
|
-
value: Array.from(ctx
|
|
908
|
+
value: Array.from(ctx.value)
|
|
912
909
|
})) {
|
|
913
|
-
const nextValue = uniq(ctx
|
|
914
|
-
set.value(ctx
|
|
915
|
-
ctx
|
|
916
|
-
ctx
|
|
910
|
+
const nextValue = uniq(ctx.value.concat(value));
|
|
911
|
+
set.value(ctx, nextValue);
|
|
912
|
+
ctx.log.prev = ctx.log.current;
|
|
913
|
+
ctx.log.current = {
|
|
917
914
|
type: "add",
|
|
918
915
|
value
|
|
919
916
|
};
|
|
920
|
-
} else ctx
|
|
917
|
+
} else ctx.onValueInvalid?.({ reason: "invalidTag" });
|
|
921
918
|
},
|
|
922
|
-
addTagFromPaste(ctx
|
|
919
|
+
addTagFromPaste(ctx) {
|
|
923
920
|
raf(() => {
|
|
924
|
-
const value = ctx
|
|
925
|
-
if (ctx
|
|
921
|
+
const value = ctx.trimmedInputValue;
|
|
922
|
+
if (ctx.validate?.({
|
|
926
923
|
inputValue: value,
|
|
927
|
-
value: Array.from(ctx
|
|
924
|
+
value: Array.from(ctx.value)
|
|
928
925
|
})) {
|
|
929
|
-
const trimmedValue = ctx
|
|
930
|
-
const nextValue = uniq(ctx
|
|
931
|
-
set.value(ctx
|
|
932
|
-
ctx
|
|
933
|
-
ctx
|
|
926
|
+
const trimmedValue = ctx.delimiter ? value.split(ctx.delimiter).map((v) => v.trim()) : [value];
|
|
927
|
+
const nextValue = uniq(ctx.value.concat(...trimmedValue));
|
|
928
|
+
set.value(ctx, nextValue);
|
|
929
|
+
ctx.log.prev = ctx.log.current;
|
|
930
|
+
ctx.log.current = {
|
|
934
931
|
type: "paste",
|
|
935
932
|
values: trimmedValue
|
|
936
933
|
};
|
|
937
|
-
} else ctx
|
|
938
|
-
set.inputValue(ctx
|
|
934
|
+
} else ctx.onValueInvalid?.({ reason: "invalidTag" });
|
|
935
|
+
set.inputValue(ctx, "");
|
|
939
936
|
});
|
|
940
937
|
},
|
|
941
|
-
clearTags(ctx
|
|
942
|
-
set.value(ctx
|
|
943
|
-
ctx
|
|
944
|
-
ctx
|
|
938
|
+
clearTags(ctx) {
|
|
939
|
+
set.value(ctx, []);
|
|
940
|
+
ctx.log.prev = ctx.log.current;
|
|
941
|
+
ctx.log.current = { type: "clear" };
|
|
945
942
|
},
|
|
946
|
-
setValue(ctx
|
|
947
|
-
set.value(ctx
|
|
943
|
+
setValue(ctx, evt) {
|
|
944
|
+
set.value(ctx, evt.value);
|
|
948
945
|
},
|
|
949
|
-
invokeOnInvalid(ctx
|
|
950
|
-
if (ctx
|
|
946
|
+
invokeOnInvalid(ctx) {
|
|
947
|
+
if (ctx.isOverflowing) ctx.onValueInvalid?.({ reason: "rangeOverflow" });
|
|
951
948
|
},
|
|
952
|
-
clearLog(ctx
|
|
953
|
-
ctx
|
|
949
|
+
clearLog(ctx) {
|
|
950
|
+
ctx.log = {
|
|
954
951
|
prev: null,
|
|
955
952
|
current: null
|
|
956
953
|
};
|
|
957
954
|
},
|
|
958
|
-
logHighlightedTag(ctx
|
|
959
|
-
if (ctx
|
|
960
|
-
const index = dom.getIndexOfId(ctx
|
|
961
|
-
ctx
|
|
962
|
-
ctx
|
|
955
|
+
logHighlightedTag(ctx) {
|
|
956
|
+
if (ctx.highlightedTagId == null) return;
|
|
957
|
+
const index = dom.getIndexOfId(ctx, ctx.highlightedTagId);
|
|
958
|
+
ctx.log.prev = ctx.log.current;
|
|
959
|
+
ctx.log.current = {
|
|
963
960
|
type: "select",
|
|
964
|
-
value: ctx
|
|
961
|
+
value: ctx.value[index]
|
|
965
962
|
};
|
|
966
963
|
},
|
|
967
|
-
announceLog(ctx
|
|
968
|
-
if (!ctx
|
|
969
|
-
const region = ctx
|
|
970
|
-
const { current, prev } = ctx
|
|
964
|
+
announceLog(ctx) {
|
|
965
|
+
if (!ctx.log.current || ctx.liveRegion == null) return;
|
|
966
|
+
const region = ctx.liveRegion;
|
|
967
|
+
const { current, prev } = ctx.log;
|
|
971
968
|
let msg;
|
|
972
969
|
switch (current.type) {
|
|
973
970
|
case "add":
|
|
974
|
-
msg = ctx
|
|
971
|
+
msg = ctx.translations.tagAdded(current.value);
|
|
975
972
|
break;
|
|
976
973
|
case "delete":
|
|
977
|
-
msg = ctx
|
|
974
|
+
msg = ctx.translations.tagDeleted(current.value);
|
|
978
975
|
break;
|
|
979
976
|
case "update":
|
|
980
|
-
msg = ctx
|
|
977
|
+
msg = ctx.translations.tagUpdated(current.value);
|
|
981
978
|
break;
|
|
982
979
|
case "paste":
|
|
983
|
-
msg = ctx
|
|
980
|
+
msg = ctx.translations.tagsPasted(current.values);
|
|
984
981
|
break;
|
|
985
982
|
case "select":
|
|
986
|
-
msg = ctx
|
|
987
|
-
if (prev?.type === "delete") msg = `${ctx
|
|
988
|
-
else if (prev?.type === "update") msg = `${ctx
|
|
989
|
-
break;
|
|
990
|
-
default: break;
|
|
983
|
+
msg = ctx.translations.tagSelected(current.value);
|
|
984
|
+
if (prev?.type === "delete") msg = `${ctx.translations.tagDeleted(prev.value)}. ${msg}`;
|
|
985
|
+
else if (prev?.type === "update") msg = `${ctx.translations.tagUpdated(prev.value)}. ${msg}`;
|
|
991
986
|
}
|
|
992
987
|
if (msg) region.announce(msg);
|
|
993
988
|
}
|
|
994
989
|
}
|
|
995
990
|
});
|
|
996
991
|
}
|
|
997
|
-
|
|
998
992
|
//#endregion
|
|
999
993
|
//#region src/props.ts
|
|
1000
994
|
const props = createProps()([
|
|
@@ -1035,6 +1029,5 @@ const itemProps = createProps()([
|
|
|
1035
1029
|
"value"
|
|
1036
1030
|
]);
|
|
1037
1031
|
const splitItemProps = createSplitProps(itemProps);
|
|
1038
|
-
|
|
1039
1032
|
//#endregion
|
|
1040
|
-
export { anatomy, connect, itemProps, machine, props, splitItemProps, splitProps };
|
|
1033
|
+
export { anatomy, connect, itemProps, machine, props, splitItemProps, splitProps };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@destyler/dynamic",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.12",
|
|
5
5
|
"description": "inputs render tags inside an input, followed by an actual text input.",
|
|
6
6
|
"author": "Elone Hoo <elonehoo@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@destyler/
|
|
26
|
-
"@destyler/
|
|
27
|
-
"@destyler/
|
|
28
|
-
"@destyler/
|
|
29
|
-
"@destyler/
|
|
30
|
-
"@destyler/
|
|
31
|
-
"@destyler/
|
|
32
|
-
"@destyler/
|
|
25
|
+
"@destyler/anatomy": "0.2.12",
|
|
26
|
+
"@destyler/auto-resize": "0.2.12",
|
|
27
|
+
"@destyler/dom": "0.2.12",
|
|
28
|
+
"@destyler/interact-outside": "0.2.12",
|
|
29
|
+
"@destyler/live-region": "0.2.12",
|
|
30
|
+
"@destyler/types": "0.2.12",
|
|
31
|
+
"@destyler/utils": "0.2.12",
|
|
32
|
+
"@destyler/xstate": "0.2.12"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|