@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 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: _destyler_anatomy0.AnatomyInstance<"root" | "label" | "control" | "input" | "clearTrigger" | "item" | "itemPreview" | "itemInput" | "itemText" | "itemDeleteTrigger">;
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): _destyler_xstate0.Machine<MachineContext, MachineState, _destyler_xstate0.AnyEventObject>;
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 { type MachineApi as Api, type UserDefinedContext as Context, type ElementIds, type FocusOutsideEvent, type HighlightChangeDetails, type InputValueChangeDetails, type InteractOutsideEvent, type IntlTranslations, type ItemProps, type ItemState, type PointerDownOutsideEvent, type ValidateArgs, type ValidityChangeDetails, type ValueChangeDetails, anatomy, connect, itemProps, machine, props, splitItemProps, splitProps };
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$1) {
221
- if (state.context.highlightedTagId) event$1.preventDefault();
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$1) {
226
- event$1.preventDefault();
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$1) {
232
+ Enter(event) {
236
233
  if (isCombobox && isExpanded) return;
237
234
  send("ENTER");
238
- event$1.preventDefault();
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$1) {
255
+ getItemProps(props) {
259
256
  return normalize.element({
260
257
  ...parts.item.attrs,
261
258
  "dir": state.context.dir,
262
- "data-value": props$1.value,
259
+ "data-value": props.value,
263
260
  "data-disabled": dataAttr(disabled)
264
261
  });
265
262
  },
266
- getItemPreviewProps(props$1) {
267
- const itemState = getItemState(props$1);
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$1.value,
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$1) {
294
- const itemState = getItemState(props$1);
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$1) {
303
- const itemState = getItemState(props$1);
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$1.value),
304
+ "aria-label": translations.tagEdited(props.value),
308
305
  "aria-hidden": true,
309
306
  "disabled": disabled,
310
- "id": dom.getItemInputId(state.context, props$1),
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
- target: event.relatedTarget,
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$1) {
346
- const id = dom.getItemId(state.context, props$1);
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$1),
347
+ "id": dom.getItemDeleteTriggerId(state.context, props),
351
348
  "type": "button",
352
349
  "disabled": disabled,
353
- "aria-label": translations.deleteTagTriggerLabel(props$1.value),
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 (/* @__PURE__ */ new RegExp(`${del.source}$`)).test(str);
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$1) => ctx$1.value.length,
478
- valueAsString: (ctx$1) => JSON.stringify(ctx$1.value),
479
- trimmedInputValue: (ctx$1) => ctx$1.inputValue.trim(),
480
- isDisabled: (ctx$1) => !!ctx$1.disabled || ctx$1.fieldsetDisabled,
481
- isInteractive: (ctx$1) => !(ctx$1.readOnly || ctx$1.isDisabled),
482
- isAtMax: (ctx$1) => ctx$1.count === ctx$1.max,
483
- isOverflowing: (ctx$1) => ctx$1.count > ctx$1.max
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$1, evt) => evt.relatedTarget === dom.getInputEl(ctx$1),
690
- isAtMax: (ctx$1) => ctx$1.isAtMax,
691
- hasHighlightedTag: (ctx$1) => ctx$1.highlightedTagId !== null,
692
- isFirstTagHighlighted: (ctx$1) => {
693
- return dom.getItemId(ctx$1, {
694
- value: ctx$1.value[0],
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$1.highlightedTagId;
692
+ }) === ctx.highlightedTagId;
697
693
  },
698
- isEditedTagEmpty: (ctx$1) => ctx$1.editedTagValue.trim() === "",
699
- isLastTagHighlighted: (ctx$1) => {
700
- const lastIndex = ctx$1.value.length - 1;
701
- return dom.getItemId(ctx$1, {
702
- value: ctx$1.value[lastIndex],
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$1.highlightedTagId;
700
+ }) === ctx.highlightedTagId;
705
701
  },
706
- isInputValueEmpty: (ctx$1) => ctx$1.trimmedInputValue.length === 0,
707
- hasTags: (ctx$1) => ctx$1.value.length > 0,
708
- allowOverflow: (ctx$1) => !!ctx$1.allowOverflow,
709
- autoFocus: (ctx$1) => !!ctx$1.autoFocus,
710
- addOnBlur: (ctx$1) => ctx$1.blurBehavior === "add",
711
- clearOnBlur: (ctx$1) => ctx$1.blurBehavior === "clear",
712
- addOnPaste: (ctx$1) => !!ctx$1.addOnPaste,
713
- isTagEditable: (ctx$1) => !!ctx$1.editable,
714
- isInputCaretAtStart(ctx$1) {
715
- const input = dom.getInputEl(ctx$1);
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$1, _evt, { send }) {
726
- return trackInteractOutside(dom.getInputEl(ctx$1), {
721
+ trackInteractOutside(ctx, _evt, { send }) {
722
+ return trackInteractOutside(dom.getInputEl(ctx), {
727
723
  exclude(target) {
728
- return contains(dom.getRootEl(ctx$1), target);
724
+ return contains(dom.getRootEl(ctx), target);
729
725
  },
730
- onFocusOutside: ctx$1.onFocusOutside,
731
- onPointerDownOutside: ctx$1.onPointerDownOutside,
726
+ onFocusOutside: ctx.onFocusOutside,
727
+ onPointerDownOutside: ctx.onPointerDownOutside,
732
728
  onInteractOutside(event) {
733
- ctx$1.onInteractOutside?.(event);
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$1, _evt, { send, initialContext }) {
743
- return trackFormControl(dom.getHiddenInputEl(ctx$1), {
738
+ trackFormControlState(ctx, _evt, { send, initialContext }) {
739
+ return trackFormControl(dom.getHiddenInputEl(ctx), {
744
740
  onFieldsetDisabledChange(disabled) {
745
- ctx$1.fieldsetDisabled = disabled;
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$1) {
757
- if (!ctx$1.editedTagValue || ctx$1.idx == null || !ctx$1.editable) return;
758
- return autoResizeInput(dom.getTagInputEl(ctx$1, {
759
- value: ctx$1.editedTagValue,
760
- index: ctx$1.idx
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$1) {
764
- ctx$1.liveRegion = createLiveRegion({
760
+ trackLiveRegion(ctx) {
761
+ ctx.liveRegion = createLiveRegion({
765
762
  level: "assertive",
766
- document: dom.getDoc(ctx$1)
763
+ document: dom.getDoc(ctx)
767
764
  });
768
- return () => ctx$1.liveRegion?.destroy();
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$1) {
782
- dom.dispatchInputEvent(ctx$1);
778
+ dispatchChangeEvent(ctx) {
779
+ dom.dispatchInputEvent(ctx);
783
780
  },
784
- highlightNextTag(ctx$1) {
785
- if (ctx$1.highlightedTagId == null) return;
786
- const next = dom.getNextEl(ctx$1, ctx$1.highlightedTagId);
787
- set.highlightedId(ctx$1, next?.id ?? null);
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$1) {
786
+ highlightFirstTag(ctx) {
790
787
  raf(() => {
791
- const first = dom.getFirstEl(ctx$1);
792
- set.highlightedId(ctx$1, first?.id ?? null);
788
+ const first = dom.getFirstEl(ctx);
789
+ set.highlightedId(ctx, first?.id ?? null);
793
790
  });
794
791
  },
795
- highlightLastTag(ctx$1) {
796
- const last = dom.getLastEl(ctx$1);
797
- set.highlightedId(ctx$1, last?.id ?? null);
792
+ highlightLastTag(ctx) {
793
+ const last = dom.getLastEl(ctx);
794
+ set.highlightedId(ctx, last?.id ?? null);
798
795
  },
799
- highlightPrevTag(ctx$1) {
800
- if (ctx$1.highlightedTagId == null) return;
801
- const prev = dom.getPrevEl(ctx$1, ctx$1.highlightedTagId);
802
- set.highlightedId(ctx$1, prev?.id ?? null);
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$1, evt) {
805
- set.highlightedId(ctx$1, evt.id);
801
+ highlightTag(ctx, evt) {
802
+ set.highlightedId(ctx, evt.id);
806
803
  },
807
- highlightTagAtIndex(ctx$1) {
804
+ highlightTagAtIndex(ctx) {
808
805
  raf(() => {
809
- if (ctx$1.idx == null) return;
810
- const tagEl = dom.getTagElAtIndex(ctx$1, ctx$1.idx);
806
+ if (ctx.idx == null) return;
807
+ const tagEl = dom.getTagElAtIndex(ctx, ctx.idx);
811
808
  if (tagEl == null) return;
812
- set.highlightedId(ctx$1, tagEl.id);
813
- ctx$1.idx = void 0;
809
+ set.highlightedId(ctx, tagEl.id);
810
+ ctx.idx = void 0;
814
811
  });
815
812
  },
816
- deleteTag(ctx$1, evt) {
817
- const index = dom.getIndexOfId(ctx$1, evt.id);
818
- const value = ctx$1.value[index];
819
- ctx$1.log.prev = ctx$1.log.current;
820
- ctx$1.log.current = {
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$1, removeAt(ctx$1.value, index));
821
+ set.value(ctx, removeAt(ctx.value, index));
825
822
  },
826
- deleteHighlightedTag(ctx$1) {
827
- if (ctx$1.highlightedTagId == null) return;
828
- const index = dom.getIndexOfId(ctx$1, ctx$1.highlightedTagId);
829
- ctx$1.idx = index;
830
- const value = ctx$1.value[index];
831
- ctx$1.log.prev = ctx$1.log.current;
832
- ctx$1.log.current = {
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$1, removeAt(ctx$1.value, index));
833
+ set.value(ctx, removeAt(ctx.value, index));
837
834
  },
838
- setEditedId(ctx$1, evt) {
839
- ctx$1.editedTagId = evt.id ?? ctx$1.highlightedTagId;
840
- ctx$1.idx = dom.getIndexOfId(ctx$1, ctx$1.editedTagId);
835
+ setEditedId(ctx, evt) {
836
+ ctx.editedTagId = evt.id ?? ctx.highlightedTagId;
837
+ ctx.idx = dom.getIndexOfId(ctx, ctx.editedTagId);
841
838
  },
842
- clearEditedId(ctx$1) {
843
- ctx$1.editedTagId = null;
839
+ clearEditedId(ctx) {
840
+ ctx.editedTagId = null;
844
841
  },
845
- clearEditedTagValue(ctx$1) {
846
- ctx$1.editedTagValue = "";
842
+ clearEditedTagValue(ctx) {
843
+ ctx.editedTagValue = "";
847
844
  },
848
- setEditedTagValue(ctx$1, evt) {
849
- ctx$1.editedTagValue = evt.value;
845
+ setEditedTagValue(ctx, evt) {
846
+ ctx.editedTagValue = evt.value;
850
847
  },
851
- submitEditedTagValue(ctx$1) {
852
- if (!ctx$1.editedTagId) return;
853
- const index = dom.getIndexOfId(ctx$1, ctx$1.editedTagId);
854
- set.valueAtIndex(ctx$1, index, ctx$1.editedTagValue ?? "");
855
- ctx$1.log.prev = ctx$1.log.current;
856
- ctx$1.log.current = {
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$1.editedTagValue
855
+ value: ctx.editedTagValue
859
856
  };
860
857
  },
861
- setValueAtIndex(ctx$1, evt) {
858
+ setValueAtIndex(ctx, evt) {
862
859
  if (evt.value) {
863
- ctx$1.value[evt.index] = evt.value;
864
- ctx$1.log.prev = ctx$1.log.current;
865
- ctx$1.log.current = {
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$1) {
872
- if (!ctx$1.editedTagId) return;
873
- const index = dom.getIndexOfId(ctx$1, ctx$1.editedTagId);
874
- ctx$1.editedTagValue = ctx$1.value[index];
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$1) {
873
+ focusEditedTagInput(ctx) {
877
874
  raf(() => {
878
- dom.getEditInputEl(ctx$1)?.select();
875
+ dom.getEditInputEl(ctx)?.select();
879
876
  });
880
877
  },
881
- setInputValue(ctx$1, evt) {
882
- set.inputValue(ctx$1, evt.value);
878
+ setInputValue(ctx, evt) {
879
+ set.inputValue(ctx, evt.value);
883
880
  },
884
- clearHighlightedId(ctx$1) {
885
- ctx$1.highlightedTagId = null;
881
+ clearHighlightedId(ctx) {
882
+ ctx.highlightedTagId = null;
886
883
  },
887
- focusInput(ctx$1) {
884
+ focusInput(ctx) {
888
885
  raf(() => {
889
- dom.getInputEl(ctx$1)?.focus();
886
+ dom.getInputEl(ctx)?.focus();
890
887
  });
891
888
  },
892
- clearInputValue(ctx$1) {
889
+ clearInputValue(ctx) {
893
890
  raf(() => {
894
- set.inputValue(ctx$1, "");
891
+ set.inputValue(ctx, "");
895
892
  });
896
893
  },
897
- syncInputValue(ctx$1) {
898
- const inputEl = dom.getInputEl(ctx$1);
899
- dom.setValue(inputEl, ctx$1.inputValue);
894
+ syncInputValue(ctx) {
895
+ const inputEl = dom.getInputEl(ctx);
896
+ dom.setValue(inputEl, ctx.inputValue);
900
897
  },
901
- syncEditedTagInputValue(ctx$1, evt) {
902
- const id = ctx$1.editedTagId || ctx$1.highlightedTagId || evt.id;
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$1, `${id}:input`);
905
- dom.setValue(editTagInputEl, ctx$1.editedTagValue);
901
+ const editTagInputEl = dom.getById(ctx, `${id}:input`);
902
+ dom.setValue(editTagInputEl, ctx.editedTagValue);
906
903
  },
907
- addTag(ctx$1, evt) {
908
- const value = evt.value ?? ctx$1.trimmedInputValue;
909
- if (ctx$1.validate?.({
904
+ addTag(ctx, evt) {
905
+ const value = evt.value ?? ctx.trimmedInputValue;
906
+ if (ctx.validate?.({
910
907
  inputValue: value,
911
- value: Array.from(ctx$1.value)
908
+ value: Array.from(ctx.value)
912
909
  })) {
913
- const nextValue = uniq(ctx$1.value.concat(value));
914
- set.value(ctx$1, nextValue);
915
- ctx$1.log.prev = ctx$1.log.current;
916
- ctx$1.log.current = {
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$1.onValueInvalid?.({ reason: "invalidTag" });
917
+ } else ctx.onValueInvalid?.({ reason: "invalidTag" });
921
918
  },
922
- addTagFromPaste(ctx$1) {
919
+ addTagFromPaste(ctx) {
923
920
  raf(() => {
924
- const value = ctx$1.trimmedInputValue;
925
- if (ctx$1.validate?.({
921
+ const value = ctx.trimmedInputValue;
922
+ if (ctx.validate?.({
926
923
  inputValue: value,
927
- value: Array.from(ctx$1.value)
924
+ value: Array.from(ctx.value)
928
925
  })) {
929
- const trimmedValue = ctx$1.delimiter ? value.split(ctx$1.delimiter).map((v) => v.trim()) : [value];
930
- const nextValue = uniq(ctx$1.value.concat(...trimmedValue));
931
- set.value(ctx$1, nextValue);
932
- ctx$1.log.prev = ctx$1.log.current;
933
- ctx$1.log.current = {
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$1.onValueInvalid?.({ reason: "invalidTag" });
938
- set.inputValue(ctx$1, "");
934
+ } else ctx.onValueInvalid?.({ reason: "invalidTag" });
935
+ set.inputValue(ctx, "");
939
936
  });
940
937
  },
941
- clearTags(ctx$1) {
942
- set.value(ctx$1, []);
943
- ctx$1.log.prev = ctx$1.log.current;
944
- ctx$1.log.current = { type: "clear" };
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$1, evt) {
947
- set.value(ctx$1, evt.value);
943
+ setValue(ctx, evt) {
944
+ set.value(ctx, evt.value);
948
945
  },
949
- invokeOnInvalid(ctx$1) {
950
- if (ctx$1.isOverflowing) ctx$1.onValueInvalid?.({ reason: "rangeOverflow" });
946
+ invokeOnInvalid(ctx) {
947
+ if (ctx.isOverflowing) ctx.onValueInvalid?.({ reason: "rangeOverflow" });
951
948
  },
952
- clearLog(ctx$1) {
953
- ctx$1.log = {
949
+ clearLog(ctx) {
950
+ ctx.log = {
954
951
  prev: null,
955
952
  current: null
956
953
  };
957
954
  },
958
- logHighlightedTag(ctx$1) {
959
- if (ctx$1.highlightedTagId == null) return;
960
- const index = dom.getIndexOfId(ctx$1, ctx$1.highlightedTagId);
961
- ctx$1.log.prev = ctx$1.log.current;
962
- ctx$1.log.current = {
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$1.value[index]
961
+ value: ctx.value[index]
965
962
  };
966
963
  },
967
- announceLog(ctx$1) {
968
- if (!ctx$1.log.current || ctx$1.liveRegion == null) return;
969
- const region = ctx$1.liveRegion;
970
- const { current, prev } = ctx$1.log;
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$1.translations.tagAdded(current.value);
971
+ msg = ctx.translations.tagAdded(current.value);
975
972
  break;
976
973
  case "delete":
977
- msg = ctx$1.translations.tagDeleted(current.value);
974
+ msg = ctx.translations.tagDeleted(current.value);
978
975
  break;
979
976
  case "update":
980
- msg = ctx$1.translations.tagUpdated(current.value);
977
+ msg = ctx.translations.tagUpdated(current.value);
981
978
  break;
982
979
  case "paste":
983
- msg = ctx$1.translations.tagsPasted(current.values);
980
+ msg = ctx.translations.tagsPasted(current.values);
984
981
  break;
985
982
  case "select":
986
- msg = ctx$1.translations.tagSelected(current.value);
987
- if (prev?.type === "delete") msg = `${ctx$1.translations.tagDeleted(prev.value)}. ${msg}`;
988
- else if (prev?.type === "update") msg = `${ctx$1.translations.tagUpdated(prev.value)}. ${msg}`;
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.10",
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/auto-resize": "0.2.10",
26
- "@destyler/dom": "0.2.10",
27
- "@destyler/anatomy": "0.2.10",
28
- "@destyler/live-region": "0.2.10",
29
- "@destyler/types": "0.2.10",
30
- "@destyler/utils": "0.2.10",
31
- "@destyler/xstate": "0.2.10",
32
- "@destyler/interact-outside": "0.2.10"
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"