@destyler/dynamic 0.0.7-beta.9 → 0.2.0-beta.5
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.ts → index.d.mts} +1 -1
- package/dist/{index.js → index.mjs} +17 -26
- package/package.json +22 -13
|
@@ -6,7 +6,7 @@ import { AnyEventObject, XSend, XState } from "@destyler/xstate";
|
|
|
6
6
|
import { CommonProperties, DirectionProperty, NormalizeProps, PropTypes, RequiredBy } from "@destyler/types";
|
|
7
7
|
|
|
8
8
|
//#region src/anatomy.d.ts
|
|
9
|
-
declare const anatomy: _destyler_anatomy0.AnatomyInstance<"root" | "
|
|
9
|
+
declare const anatomy: _destyler_anatomy0.AnatomyInstance<"root" | "label" | "control" | "input" | "clearTrigger" | "item" | "itemPreview" | "itemInput" | "itemText" | "itemDeleteTrigger">;
|
|
10
10
|
//#endregion
|
|
11
11
|
//#region src/types.d.ts
|
|
12
12
|
interface ValueChangeDetails {
|
|
@@ -8,7 +8,7 @@ import { createMachine, guards } from "@destyler/xstate";
|
|
|
8
8
|
import { createProps } from "@destyler/types";
|
|
9
9
|
|
|
10
10
|
//#region src/anatomy.ts
|
|
11
|
-
const anatomy = createAnatomy("
|
|
11
|
+
const anatomy = createAnatomy("dynamic").parts("root", "label", "control", "input", "clearTrigger", "item", "itemPreview", "itemInput", "itemText", "itemDeleteTrigger");
|
|
12
12
|
const parts = anatomy.build();
|
|
13
13
|
|
|
14
14
|
//#endregion
|
|
@@ -39,8 +39,7 @@ const dom = createScope({
|
|
|
39
39
|
isInputFocused: (ctx) => dom.getDoc(ctx).activeElement === dom.getInputEl(ctx),
|
|
40
40
|
getHighlightedTagValue: (ctx) => {
|
|
41
41
|
if (!ctx.highlightedTagId) return null;
|
|
42
|
-
|
|
43
|
-
return tagEl?.dataset.value ?? null;
|
|
42
|
+
return dom.getById(ctx, ctx.highlightedTagId)?.dataset.value ?? null;
|
|
44
43
|
},
|
|
45
44
|
setHoverIntent: (el) => {
|
|
46
45
|
const tagEl = el.closest("[data-part=item-preview]");
|
|
@@ -210,7 +209,7 @@ function connect(state, send, normalize) {
|
|
|
210
209
|
const target = event.currentTarget;
|
|
211
210
|
const isCombobox = target.getAttribute("role") === "combobox";
|
|
212
211
|
const isExpanded = target.ariaExpanded === "true";
|
|
213
|
-
const
|
|
212
|
+
const exec = {
|
|
214
213
|
ArrowDown() {
|
|
215
214
|
send("ARROW_DOWN");
|
|
216
215
|
},
|
|
@@ -238,9 +237,7 @@ function connect(state, send, normalize) {
|
|
|
238
237
|
send("ENTER");
|
|
239
238
|
event$1.preventDefault();
|
|
240
239
|
}
|
|
241
|
-
};
|
|
242
|
-
const key = getEventKey(event, state.context);
|
|
243
|
-
const exec = keyMap[key];
|
|
240
|
+
}[getEventKey(event, state.context)];
|
|
244
241
|
if (exec) exec(event);
|
|
245
242
|
}
|
|
246
243
|
});
|
|
@@ -330,15 +327,14 @@ function connect(state, send, normalize) {
|
|
|
330
327
|
onKeyDown(event) {
|
|
331
328
|
if (event.defaultPrevented) return;
|
|
332
329
|
if (isComposingEvent(event)) return;
|
|
333
|
-
const
|
|
330
|
+
const exec = {
|
|
334
331
|
Enter() {
|
|
335
332
|
send("TAG_INPUT_ENTER");
|
|
336
333
|
},
|
|
337
334
|
Escape() {
|
|
338
335
|
send("TAG_INPUT_ESCAPE");
|
|
339
336
|
}
|
|
340
|
-
};
|
|
341
|
-
const exec = keyMap[event.key];
|
|
337
|
+
}[event.key];
|
|
342
338
|
if (exec) {
|
|
343
339
|
event.preventDefault();
|
|
344
340
|
exec(event);
|
|
@@ -441,7 +437,7 @@ const set = {
|
|
|
441
437
|
function machine(userContext) {
|
|
442
438
|
const ctx = compact(userContext);
|
|
443
439
|
return createMachine({
|
|
444
|
-
id: "
|
|
440
|
+
id: "dynamic",
|
|
445
441
|
initial: ctx.autoFocus ? "focused:input" : "idle",
|
|
446
442
|
context: {
|
|
447
443
|
inputValue: "",
|
|
@@ -694,20 +690,18 @@ function machine(userContext) {
|
|
|
694
690
|
isAtMax: (ctx$1) => ctx$1.isAtMax,
|
|
695
691
|
hasHighlightedTag: (ctx$1) => ctx$1.highlightedTagId !== null,
|
|
696
692
|
isFirstTagHighlighted: (ctx$1) => {
|
|
697
|
-
|
|
693
|
+
return dom.getItemId(ctx$1, {
|
|
698
694
|
value: ctx$1.value[0],
|
|
699
695
|
index: 0
|
|
700
|
-
});
|
|
701
|
-
return firstItemId === ctx$1.highlightedTagId;
|
|
696
|
+
}) === ctx$1.highlightedTagId;
|
|
702
697
|
},
|
|
703
698
|
isEditedTagEmpty: (ctx$1) => ctx$1.editedTagValue.trim() === "",
|
|
704
699
|
isLastTagHighlighted: (ctx$1) => {
|
|
705
700
|
const lastIndex = ctx$1.value.length - 1;
|
|
706
|
-
|
|
701
|
+
return dom.getItemId(ctx$1, {
|
|
707
702
|
value: ctx$1.value[lastIndex],
|
|
708
703
|
index: lastIndex
|
|
709
|
-
});
|
|
710
|
-
return lastItemId === ctx$1.highlightedTagId;
|
|
704
|
+
}) === ctx$1.highlightedTagId;
|
|
711
705
|
},
|
|
712
706
|
isInputValueEmpty: (ctx$1) => ctx$1.trimmedInputValue.length === 0,
|
|
713
707
|
hasTags: (ctx$1) => ctx$1.value.length > 0,
|
|
@@ -761,11 +755,10 @@ function machine(userContext) {
|
|
|
761
755
|
},
|
|
762
756
|
autoResize(ctx$1) {
|
|
763
757
|
if (!ctx$1.editedTagValue || ctx$1.idx == null || !ctx$1.editable) return;
|
|
764
|
-
|
|
758
|
+
return autoResizeInput(dom.getTagInputEl(ctx$1, {
|
|
765
759
|
value: ctx$1.editedTagValue,
|
|
766
760
|
index: ctx$1.idx
|
|
767
|
-
});
|
|
768
|
-
return autoResizeInput(input);
|
|
761
|
+
}));
|
|
769
762
|
},
|
|
770
763
|
trackLiveRegion(ctx$1) {
|
|
771
764
|
ctx$1.liveRegion = createLiveRegion({
|
|
@@ -913,11 +906,10 @@ function machine(userContext) {
|
|
|
913
906
|
},
|
|
914
907
|
addTag(ctx$1, evt) {
|
|
915
908
|
const value = evt.value ?? ctx$1.trimmedInputValue;
|
|
916
|
-
|
|
909
|
+
if (ctx$1.validate?.({
|
|
917
910
|
inputValue: value,
|
|
918
911
|
value: Array.from(ctx$1.value)
|
|
919
|
-
})
|
|
920
|
-
if (guard) {
|
|
912
|
+
})) {
|
|
921
913
|
const nextValue = uniq(ctx$1.value.concat(value));
|
|
922
914
|
set.value(ctx$1, nextValue);
|
|
923
915
|
ctx$1.log.prev = ctx$1.log.current;
|
|
@@ -930,11 +922,10 @@ function machine(userContext) {
|
|
|
930
922
|
addTagFromPaste(ctx$1) {
|
|
931
923
|
raf(() => {
|
|
932
924
|
const value = ctx$1.trimmedInputValue;
|
|
933
|
-
|
|
925
|
+
if (ctx$1.validate?.({
|
|
934
926
|
inputValue: value,
|
|
935
927
|
value: Array.from(ctx$1.value)
|
|
936
|
-
})
|
|
937
|
-
if (guard) {
|
|
928
|
+
})) {
|
|
938
929
|
const trimmedValue = ctx$1.delimiter ? value.split(ctx$1.delimiter).map((v) => v.trim()) : [value];
|
|
939
930
|
const nextValue = uniq(ctx$1.value.concat(...trimmedValue));
|
|
940
931
|
set.value(ctx$1, nextValue);
|
package/package.json
CHANGED
|
@@ -1,29 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@destyler/dynamic",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.2.0-beta.5",
|
|
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",
|
|
8
|
+
"homepage": "https://github.com/destyler/destyler",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/destyler/destyler.git",
|
|
12
|
+
"directory": "packages/components/dynamic"
|
|
13
|
+
},
|
|
8
14
|
"exports": {
|
|
9
|
-
".": "./dist/index.
|
|
15
|
+
".": "./dist/index.mjs"
|
|
10
16
|
},
|
|
11
|
-
"main": "dist/index.
|
|
12
|
-
"module": "dist/index.
|
|
13
|
-
"types": "dist/index.d.
|
|
17
|
+
"main": "dist/index.mjs",
|
|
18
|
+
"module": "dist/index.mjs",
|
|
19
|
+
"types": "dist/index.d.mts",
|
|
14
20
|
"files": [
|
|
15
21
|
"*.d.ts",
|
|
16
22
|
"dist"
|
|
17
23
|
],
|
|
18
24
|
"dependencies": {
|
|
19
|
-
"@destyler/
|
|
20
|
-
"@destyler/
|
|
21
|
-
"@destyler/
|
|
22
|
-
"@destyler/
|
|
23
|
-
"@destyler/
|
|
24
|
-
"@destyler/
|
|
25
|
-
"@destyler/
|
|
26
|
-
"@destyler/xstate": "0.0
|
|
25
|
+
"@destyler/auto-resize": "0.2.0-beta.5",
|
|
26
|
+
"@destyler/anatomy": "0.2.0-beta.5",
|
|
27
|
+
"@destyler/live-region": "0.2.0-beta.5",
|
|
28
|
+
"@destyler/interact-outside": "0.2.0-beta.5",
|
|
29
|
+
"@destyler/types": "0.2.0-beta.5",
|
|
30
|
+
"@destyler/dom": "0.2.0-beta.5",
|
|
31
|
+
"@destyler/utils": "0.2.0-beta.5",
|
|
32
|
+
"@destyler/xstate": "0.2.0-beta.5"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
27
36
|
},
|
|
28
37
|
"scripts": {
|
|
29
38
|
"clear": "rimraf ./dist",
|