@destyler/dynamic 0.0.1-beta.21
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/LICENSE +21 -0
- package/dist/component.cjs +20 -0
- package/dist/component.d.cts +4 -0
- package/dist/component.d.mts +4 -0
- package/dist/component.d.ts +4 -0
- package/dist/component.mjs +9 -0
- package/dist/index.cjs +533 -0
- package/dist/index.d.cts +502 -0
- package/dist/index.d.mts +502 -0
- package/dist/index.d.ts +502 -0
- package/dist/index.mjs +526 -0
- package/dist/resolver.cjs +20 -0
- package/dist/resolver.d.cts +6 -0
- package/dist/resolver.d.mts +6 -0
- package/dist/resolver.d.ts +6 -0
- package/dist/resolver.mjs +17 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-PRESENT Elone Hoo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const index = require('./index.cjs');
|
|
4
|
+
require('vue');
|
|
5
|
+
require('@destyler/primitive');
|
|
6
|
+
require('@destyler/composition');
|
|
7
|
+
require('@destyler/shared');
|
|
8
|
+
require('@vueuse/core');
|
|
9
|
+
require('@destyler/collection');
|
|
10
|
+
require('@destyler/visually-hidden/dist/component');
|
|
11
|
+
require('@destyler/directives');
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
exports.DestylerDynamicClear = index.DestylerDynamicClear;
|
|
16
|
+
exports.DestylerDynamicInput = index.DestylerDynamicInput;
|
|
17
|
+
exports.DestylerDynamicItem = index.DestylerDynamicItem;
|
|
18
|
+
exports.DestylerDynamicItemDelete = index.DestylerDynamicItemDelete;
|
|
19
|
+
exports.DestylerDynamicItemText = index.DestylerDynamicItemText;
|
|
20
|
+
exports.DestylerDynamicRoot = index.DestylerDynamicRoot;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { DestylerDynamicClear, DestylerDynamicClearProps, DestylerDynamicInput, DestylerDynamicInputProps, DestylerDynamicItem, DestylerDynamicItemDelete, DestylerDynamicItemDeleteProps, DestylerDynamicItemProops, DestylerDynamicItemText, DestylerDynamicItemTextProps, DestylerDynamicRoot, DestylerDynamicRootProps } from './index.cjs';
|
|
2
|
+
import 'vue';
|
|
3
|
+
import '@destyler/primitive';
|
|
4
|
+
import '@destyler/shared';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { DestylerDynamicClear, DestylerDynamicClearProps, DestylerDynamicInput, DestylerDynamicInputProps, DestylerDynamicItem, DestylerDynamicItemDelete, DestylerDynamicItemDeleteProps, DestylerDynamicItemProops, DestylerDynamicItemText, DestylerDynamicItemTextProps, DestylerDynamicRoot, DestylerDynamicRootProps } from './index.mjs';
|
|
2
|
+
import 'vue';
|
|
3
|
+
import '@destyler/primitive';
|
|
4
|
+
import '@destyler/shared';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { DestylerDynamicClear, DestylerDynamicClearProps, DestylerDynamicInput, DestylerDynamicInputProps, DestylerDynamicItem, DestylerDynamicItemDelete, DestylerDynamicItemDeleteProps, DestylerDynamicItemProops, DestylerDynamicItemText, DestylerDynamicItemTextProps, DestylerDynamicRoot, DestylerDynamicRootProps } from './index.js';
|
|
2
|
+
import 'vue';
|
|
3
|
+
import '@destyler/primitive';
|
|
4
|
+
import '@destyler/shared';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { DestylerDynamicClear, DestylerDynamicInput, DestylerDynamicItem, DestylerDynamicItemDelete, DestylerDynamicItemText, DestylerDynamicRoot } from './index.mjs';
|
|
2
|
+
import 'vue';
|
|
3
|
+
import '@destyler/primitive';
|
|
4
|
+
import '@destyler/composition';
|
|
5
|
+
import '@destyler/shared';
|
|
6
|
+
import '@vueuse/core';
|
|
7
|
+
import '@destyler/collection';
|
|
8
|
+
import '@destyler/visually-hidden/dist/component';
|
|
9
|
+
import '@destyler/directives';
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const vue = require('vue');
|
|
4
|
+
const primitive = require('@destyler/primitive');
|
|
5
|
+
const composition = require('@destyler/composition');
|
|
6
|
+
const shared = require('@destyler/shared');
|
|
7
|
+
const core = require('@vueuse/core');
|
|
8
|
+
const collection = require('@destyler/collection');
|
|
9
|
+
const component = require('@destyler/visually-hidden/dist/component');
|
|
10
|
+
const directives = require('@destyler/directives');
|
|
11
|
+
|
|
12
|
+
const destylerDynamicRootProps = {
|
|
13
|
+
as: {
|
|
14
|
+
type: [String, Object],
|
|
15
|
+
required: false,
|
|
16
|
+
default: "div"
|
|
17
|
+
},
|
|
18
|
+
asChild: {
|
|
19
|
+
type: Boolean,
|
|
20
|
+
required: false,
|
|
21
|
+
default: false
|
|
22
|
+
},
|
|
23
|
+
modelValue: {
|
|
24
|
+
type: Array,
|
|
25
|
+
required: false,
|
|
26
|
+
default: () => []
|
|
27
|
+
},
|
|
28
|
+
defaultValue: {
|
|
29
|
+
type: Array,
|
|
30
|
+
required: false
|
|
31
|
+
},
|
|
32
|
+
addOnPaste: {
|
|
33
|
+
type: Boolean,
|
|
34
|
+
required: false
|
|
35
|
+
},
|
|
36
|
+
duplicate: {
|
|
37
|
+
type: Boolean,
|
|
38
|
+
required: false
|
|
39
|
+
},
|
|
40
|
+
disabled: {
|
|
41
|
+
type: Boolean,
|
|
42
|
+
required: false
|
|
43
|
+
},
|
|
44
|
+
delimiter: {
|
|
45
|
+
type: String,
|
|
46
|
+
required: false,
|
|
47
|
+
default: ","
|
|
48
|
+
},
|
|
49
|
+
dir: {
|
|
50
|
+
type: String,
|
|
51
|
+
required: false
|
|
52
|
+
},
|
|
53
|
+
max: {
|
|
54
|
+
type: Number,
|
|
55
|
+
required: false,
|
|
56
|
+
default: 0
|
|
57
|
+
},
|
|
58
|
+
required: {
|
|
59
|
+
type: Boolean,
|
|
60
|
+
required: false
|
|
61
|
+
},
|
|
62
|
+
name: {
|
|
63
|
+
type: String,
|
|
64
|
+
required: false
|
|
65
|
+
},
|
|
66
|
+
id: {
|
|
67
|
+
type: String,
|
|
68
|
+
required: false
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const [injectDynamicRootContext, provideDynamicRootContext] = shared.createContext("DestylerDynamicRoot");
|
|
72
|
+
const DestylerDynamicRoot = vue.defineComponent({
|
|
73
|
+
name: "DestylerDynamicRoot",
|
|
74
|
+
props: destylerDynamicRootProps,
|
|
75
|
+
emits: ["update:modelValue", "invalid"],
|
|
76
|
+
setup(props, { emit }) {
|
|
77
|
+
const { addOnPaste, disabled, delimiter, max, id, dir: propDir } = vue.toRefs(props);
|
|
78
|
+
const dir = composition.useDirection(propDir);
|
|
79
|
+
const modelValue = composition.useVModel(props, "modelValue", emit, {
|
|
80
|
+
defaultValue: props.defaultValue,
|
|
81
|
+
passive: true,
|
|
82
|
+
deep: true
|
|
83
|
+
});
|
|
84
|
+
const { forwardRef, currentElement } = composition.useForwardExpose();
|
|
85
|
+
const { focused } = core.useFocusWithin(currentElement);
|
|
86
|
+
const isFormControl = composition.useFormControl(currentElement);
|
|
87
|
+
const { getItems } = collection.createCollection();
|
|
88
|
+
const selectedElement = vue.ref();
|
|
89
|
+
const isInvalidInput = vue.ref(false);
|
|
90
|
+
provideDynamicRootContext({
|
|
91
|
+
modelValue,
|
|
92
|
+
onAddValue: (payload) => {
|
|
93
|
+
if (modelValue.value.length >= max.value && !!max.value) {
|
|
94
|
+
emit("invalid", payload);
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
if (props.duplicate) {
|
|
98
|
+
modelValue.value.push(payload);
|
|
99
|
+
return true;
|
|
100
|
+
} else {
|
|
101
|
+
const exist = modelValue.value.includes(payload);
|
|
102
|
+
if (!exist) {
|
|
103
|
+
modelValue.value.push(payload);
|
|
104
|
+
return true;
|
|
105
|
+
} else {
|
|
106
|
+
isInvalidInput.value = true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
emit("invalid", payload);
|
|
110
|
+
return false;
|
|
111
|
+
},
|
|
112
|
+
onRemoveValue: (index) => {
|
|
113
|
+
if (index !== -1)
|
|
114
|
+
modelValue.value.splice(index, 1);
|
|
115
|
+
},
|
|
116
|
+
onInputKeydown: (event) => {
|
|
117
|
+
const target = event.target;
|
|
118
|
+
const collection = getItems().map((i) => i.ref).filter((i) => i.dataset.disabled !== "");
|
|
119
|
+
if (!collection.length)
|
|
120
|
+
return;
|
|
121
|
+
const lastTag = collection.at(-1);
|
|
122
|
+
switch (event.key) {
|
|
123
|
+
case "Delete":
|
|
124
|
+
case "Backspace": {
|
|
125
|
+
if (target.selectionStart !== 0 || target.selectionEnd !== 0)
|
|
126
|
+
break;
|
|
127
|
+
if (selectedElement.value) {
|
|
128
|
+
const index = collection.findIndex((i) => i === selectedElement.value);
|
|
129
|
+
modelValue.value.splice(index, 1);
|
|
130
|
+
selectedElement.value = selectedElement.value === lastTag ? collection.at(index - 1) : collection.at(index + 1);
|
|
131
|
+
event.preventDefault();
|
|
132
|
+
} else if (event.key === "Backspace") {
|
|
133
|
+
selectedElement.value = lastTag;
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
}
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
case "Home":
|
|
139
|
+
case "End":
|
|
140
|
+
case "ArrowRight":
|
|
141
|
+
case "ArrowLeft": {
|
|
142
|
+
const isArrowRight = event.key === "ArrowRight" && dir.value === "ltr" || event.key === "ArrowLeft" && dir.value === "rtl";
|
|
143
|
+
const isArrowLeft = !isArrowRight;
|
|
144
|
+
if (target.selectionStart !== 0 || target.selectionEnd !== 0)
|
|
145
|
+
break;
|
|
146
|
+
if (isArrowLeft && !selectedElement.value) {
|
|
147
|
+
selectedElement.value = lastTag;
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
} else if (isArrowRight && lastTag && selectedElement.value === lastTag) {
|
|
150
|
+
selectedElement.value = void 0;
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
} else if (selectedElement.value) {
|
|
153
|
+
const el = composition.useArrowNavigation(event, selectedElement.value, void 0, {
|
|
154
|
+
itemsArray: collection,
|
|
155
|
+
loop: false,
|
|
156
|
+
dir: dir.value
|
|
157
|
+
});
|
|
158
|
+
if (el)
|
|
159
|
+
selectedElement.value = el;
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
}
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
case "ArrowUp":
|
|
165
|
+
case "ArrowDown": {
|
|
166
|
+
if (selectedElement.value)
|
|
167
|
+
event.preventDefault();
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
default: {
|
|
171
|
+
selectedElement.value = void 0;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
selectedElement,
|
|
176
|
+
isInvalidInput,
|
|
177
|
+
addOnPaste,
|
|
178
|
+
dir,
|
|
179
|
+
disabled,
|
|
180
|
+
delimiter,
|
|
181
|
+
max,
|
|
182
|
+
id
|
|
183
|
+
});
|
|
184
|
+
return {
|
|
185
|
+
forwardRef,
|
|
186
|
+
dir,
|
|
187
|
+
isInvalidInput,
|
|
188
|
+
disabled,
|
|
189
|
+
focused,
|
|
190
|
+
modelValue,
|
|
191
|
+
isFormControl
|
|
192
|
+
};
|
|
193
|
+
},
|
|
194
|
+
render() {
|
|
195
|
+
return vue.h(collection.DestylerCollectionSlot, {}, {
|
|
196
|
+
default: () => {
|
|
197
|
+
return vue.h(primitive.DestylerPrimitive, {
|
|
198
|
+
"ref": (el) => this.forwardRef(el),
|
|
199
|
+
"dir": this.dir,
|
|
200
|
+
"as": this.$props.as,
|
|
201
|
+
"asChild": this.$props.asChild,
|
|
202
|
+
"data-invalid": this.isInvalidInput ? "" : void 0,
|
|
203
|
+
"data-disabled": this.disabled ? "" : void 0,
|
|
204
|
+
"data-focused": this.focused ? "" : void 0
|
|
205
|
+
}, {
|
|
206
|
+
default: () => {
|
|
207
|
+
return [
|
|
208
|
+
this.$slots.default?.({ modelValue: this.modelValue }),
|
|
209
|
+
this.isFormControl && this.$props.name ? vue.h(component.DestylerVisuallyhiddenInput, {
|
|
210
|
+
name: this.$props.name,
|
|
211
|
+
value: this.modelValue,
|
|
212
|
+
required: this.required,
|
|
213
|
+
disabled: this.disabled
|
|
214
|
+
}) : null
|
|
215
|
+
];
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
const destylerDynamicClearProps = {
|
|
224
|
+
as: {
|
|
225
|
+
type: [String, Object],
|
|
226
|
+
required: false,
|
|
227
|
+
default: "button"
|
|
228
|
+
},
|
|
229
|
+
asChild: {
|
|
230
|
+
type: Boolean,
|
|
231
|
+
required: false,
|
|
232
|
+
default: false
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
const DestylerDynamicClear = vue.defineComponent({
|
|
236
|
+
name: "DestylerDynamicClear",
|
|
237
|
+
props: destylerDynamicClearProps,
|
|
238
|
+
setup() {
|
|
239
|
+
composition.useForwardExpose();
|
|
240
|
+
const context = injectDynamicRootContext();
|
|
241
|
+
function handleCancel() {
|
|
242
|
+
if (context.disabled.value)
|
|
243
|
+
return;
|
|
244
|
+
context.modelValue.value = [];
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
context,
|
|
248
|
+
handleCancel
|
|
249
|
+
};
|
|
250
|
+
},
|
|
251
|
+
render() {
|
|
252
|
+
return vue.h(primitive.DestylerPrimitive, vue.mergeProps(this.$props, {
|
|
253
|
+
"type": this.$props.as === "button" ? "button" : void 0,
|
|
254
|
+
"data-disabled": this.context.disabled.value ? "" : void 0,
|
|
255
|
+
"onClick": () => {
|
|
256
|
+
this.handleCancel();
|
|
257
|
+
}
|
|
258
|
+
}), {
|
|
259
|
+
default: () => this.$slots.default?.()
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
const destylerDynamicInputProps = {
|
|
265
|
+
as: {
|
|
266
|
+
type: [String, Object],
|
|
267
|
+
required: false,
|
|
268
|
+
default: "input"
|
|
269
|
+
},
|
|
270
|
+
asChild: {
|
|
271
|
+
type: Boolean,
|
|
272
|
+
required: false,
|
|
273
|
+
default: false
|
|
274
|
+
},
|
|
275
|
+
placeholder: {
|
|
276
|
+
type: String,
|
|
277
|
+
required: false
|
|
278
|
+
},
|
|
279
|
+
autoFocus: {
|
|
280
|
+
type: Boolean,
|
|
281
|
+
required: false
|
|
282
|
+
},
|
|
283
|
+
maxLength: {
|
|
284
|
+
type: Number,
|
|
285
|
+
required: false
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
const DestylerDynamicInput = vue.defineComponent({
|
|
289
|
+
name: "DestylerDynamicInput",
|
|
290
|
+
props: destylerDynamicInputProps,
|
|
291
|
+
setup(props) {
|
|
292
|
+
const context = injectDynamicRootContext();
|
|
293
|
+
const { forwardRef, currentElement } = composition.useForwardExpose();
|
|
294
|
+
async function handleEnter(event) {
|
|
295
|
+
await vue.nextTick();
|
|
296
|
+
if (event.defaultPrevented)
|
|
297
|
+
return;
|
|
298
|
+
const target = event.target;
|
|
299
|
+
if (!target.value)
|
|
300
|
+
return;
|
|
301
|
+
const isAdded = context.onAddValue(target.value);
|
|
302
|
+
if (isAdded)
|
|
303
|
+
target.value = "";
|
|
304
|
+
event.preventDefault();
|
|
305
|
+
}
|
|
306
|
+
function handleInput(event) {
|
|
307
|
+
context.isInvalidInput.value = false;
|
|
308
|
+
const delimiter = context.delimiter.value;
|
|
309
|
+
if (delimiter === event.data) {
|
|
310
|
+
const target = event.target;
|
|
311
|
+
target.value = target.value.replaceAll(delimiter, "");
|
|
312
|
+
const isAdded = context.onAddValue(target.value);
|
|
313
|
+
if (isAdded)
|
|
314
|
+
target.value = "";
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
function handlePaste(event) {
|
|
318
|
+
if (context.addOnPaste.value) {
|
|
319
|
+
event.preventDefault();
|
|
320
|
+
const clipboardData = event.clipboardData;
|
|
321
|
+
if (!clipboardData)
|
|
322
|
+
return;
|
|
323
|
+
const value = clipboardData.getData("text");
|
|
324
|
+
if (context.delimiter.value) {
|
|
325
|
+
const splittedValue = value.split(context.delimiter.value);
|
|
326
|
+
splittedValue.forEach((v) => {
|
|
327
|
+
context.onAddValue(v);
|
|
328
|
+
});
|
|
329
|
+
} else {
|
|
330
|
+
context.onAddValue(value);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
vue.onMounted(() => {
|
|
335
|
+
const inputEl = currentElement.value.nodeName === "INPUT" ? currentElement.value : currentElement.value.querySelector("input");
|
|
336
|
+
if (!inputEl)
|
|
337
|
+
return;
|
|
338
|
+
setTimeout(() => {
|
|
339
|
+
if (props.autoFocus)
|
|
340
|
+
inputEl?.focus();
|
|
341
|
+
}, 1);
|
|
342
|
+
});
|
|
343
|
+
return {
|
|
344
|
+
forwardRef,
|
|
345
|
+
context,
|
|
346
|
+
handleInput,
|
|
347
|
+
handlePaste,
|
|
348
|
+
handleEnter
|
|
349
|
+
};
|
|
350
|
+
},
|
|
351
|
+
render() {
|
|
352
|
+
return vue.withDirectives(vue.h(primitive.DestylerPrimitive, {
|
|
353
|
+
"ref": (el) => this.forwardRef(el),
|
|
354
|
+
"type": "text",
|
|
355
|
+
"autocomplete": "off",
|
|
356
|
+
"autocorrect": "off",
|
|
357
|
+
"autocapitalize": "off",
|
|
358
|
+
"as": this.$props.as,
|
|
359
|
+
"asChild": this.$props.asChild,
|
|
360
|
+
"maxlength": this.$props.maxLength,
|
|
361
|
+
"placeholder": this.$props.placeholder,
|
|
362
|
+
"disabled": this.context.disabled.value,
|
|
363
|
+
"data-invalid": this.context.isInvalidInput.value ? "" : void 0,
|
|
364
|
+
"onInput": (event) => {
|
|
365
|
+
this.handleInput(event);
|
|
366
|
+
},
|
|
367
|
+
"onPaste": (event) => {
|
|
368
|
+
this.handlePaste(event);
|
|
369
|
+
},
|
|
370
|
+
"onKeydown": (event) => {
|
|
371
|
+
if (event.key === "Enter")
|
|
372
|
+
this.handleEnter(event);
|
|
373
|
+
else
|
|
374
|
+
this.context.onInputKeydown(event);
|
|
375
|
+
}
|
|
376
|
+
}, {
|
|
377
|
+
default: () => this.$slots.default?.()
|
|
378
|
+
}), [
|
|
379
|
+
[directives.BindOnceDirective, { id: this.context.id?.value }]
|
|
380
|
+
]);
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
const destylerDynamicItemProps = {
|
|
385
|
+
as: {
|
|
386
|
+
type: [String, Object],
|
|
387
|
+
required: false,
|
|
388
|
+
default: "div"
|
|
389
|
+
},
|
|
390
|
+
asChild: {
|
|
391
|
+
type: Boolean,
|
|
392
|
+
required: false,
|
|
393
|
+
default: false
|
|
394
|
+
},
|
|
395
|
+
value: {
|
|
396
|
+
type: String,
|
|
397
|
+
required: true
|
|
398
|
+
},
|
|
399
|
+
disabled: {
|
|
400
|
+
type: Boolean,
|
|
401
|
+
required: false
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
const [injectDynamicItemContext, provideDynamicItemContext] = shared.createContext("DestylerDynamicItem");
|
|
405
|
+
const DestylerDynamicItem = vue.defineComponent({
|
|
406
|
+
name: "DestylerDynamicItem",
|
|
407
|
+
props: destylerDynamicItemProps,
|
|
408
|
+
setup(props) {
|
|
409
|
+
const { value } = vue.toRefs(props);
|
|
410
|
+
const context = injectDynamicRootContext();
|
|
411
|
+
const { forwardRef, currentElement } = composition.useForwardExpose();
|
|
412
|
+
const isSelected = vue.computed(() => context.selectedElement.value === currentElement.value);
|
|
413
|
+
const textId = composition.useId();
|
|
414
|
+
const disabled = vue.computed(() => props.disabled || context.disabled.value);
|
|
415
|
+
provideDynamicItemContext({
|
|
416
|
+
value,
|
|
417
|
+
isSelected,
|
|
418
|
+
disabled,
|
|
419
|
+
textId
|
|
420
|
+
});
|
|
421
|
+
return {
|
|
422
|
+
forwardRef,
|
|
423
|
+
textId,
|
|
424
|
+
isSelected,
|
|
425
|
+
disabled
|
|
426
|
+
};
|
|
427
|
+
},
|
|
428
|
+
render() {
|
|
429
|
+
return vue.h(collection.DestylerCollectionItem, {}, {
|
|
430
|
+
default: () => {
|
|
431
|
+
return vue.h(primitive.DestylerPrimitive, {
|
|
432
|
+
"ref": (el) => this.forwardRef(el),
|
|
433
|
+
"as": this.$props.as,
|
|
434
|
+
"asChild": this.$props.asChild,
|
|
435
|
+
"aria-labelledby": this.textId,
|
|
436
|
+
"aria-current": this.isSelected,
|
|
437
|
+
"data-disabled": this.disabled ? "" : void 0,
|
|
438
|
+
"data-state": this.isSelected ? "active" : "inactive"
|
|
439
|
+
}, {
|
|
440
|
+
default: () => this.$slots.default?.()
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
const destylerDynamicItemDeleteProps = {
|
|
448
|
+
as: {
|
|
449
|
+
type: [String, Object],
|
|
450
|
+
required: false,
|
|
451
|
+
default: "button"
|
|
452
|
+
},
|
|
453
|
+
asChild: {
|
|
454
|
+
type: Boolean,
|
|
455
|
+
required: false,
|
|
456
|
+
default: false
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
const DestylerDynamicItemDelete = vue.defineComponent({
|
|
460
|
+
name: "DestylerDynamicItemDelete",
|
|
461
|
+
props: destylerDynamicItemDeleteProps,
|
|
462
|
+
setup() {
|
|
463
|
+
composition.useForwardExpose();
|
|
464
|
+
const context = injectDynamicRootContext();
|
|
465
|
+
const itemContext = injectDynamicItemContext();
|
|
466
|
+
const disabled = vue.computed(() => itemContext.disabled?.value || context.disabled.value);
|
|
467
|
+
function handleDelete() {
|
|
468
|
+
if (disabled.value)
|
|
469
|
+
return;
|
|
470
|
+
const index = context.modelValue.value.findIndex((i) => i === itemContext.value.value);
|
|
471
|
+
context.onRemoveValue(index);
|
|
472
|
+
}
|
|
473
|
+
return {
|
|
474
|
+
context,
|
|
475
|
+
itemContext,
|
|
476
|
+
disabled,
|
|
477
|
+
handleDelete
|
|
478
|
+
};
|
|
479
|
+
},
|
|
480
|
+
render() {
|
|
481
|
+
return vue.h(primitive.DestylerPrimitive, vue.mergeProps(this.$props, {
|
|
482
|
+
"tabindex": "-1",
|
|
483
|
+
"aria-labelledby": this.itemContext.textId,
|
|
484
|
+
"aria-current": this.itemContext.isSelected.value,
|
|
485
|
+
"data-state": this.itemContext.isSelected.value ? "active" : "inactive",
|
|
486
|
+
"data-disabled": this.disabled ? "" : void 0,
|
|
487
|
+
"type": this.$props.as === "button" ? "button" : void 0,
|
|
488
|
+
"onClick": () => {
|
|
489
|
+
this.handleDelete();
|
|
490
|
+
}
|
|
491
|
+
}), {
|
|
492
|
+
default: () => this.$slots.default?.()
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
const destylerDynamicItemTextProps = {
|
|
498
|
+
as: {
|
|
499
|
+
type: [String, Object],
|
|
500
|
+
required: false,
|
|
501
|
+
default: "span"
|
|
502
|
+
},
|
|
503
|
+
asChild: {
|
|
504
|
+
type: Boolean,
|
|
505
|
+
required: false,
|
|
506
|
+
default: false
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
const DestylerDynamicItemText = vue.defineComponent({
|
|
510
|
+
name: "DestylerDynamicItemText",
|
|
511
|
+
props: destylerDynamicItemTextProps,
|
|
512
|
+
setup() {
|
|
513
|
+
const itemContext = injectDynamicItemContext();
|
|
514
|
+
composition.useForwardExpose();
|
|
515
|
+
return {
|
|
516
|
+
itemContext
|
|
517
|
+
};
|
|
518
|
+
},
|
|
519
|
+
render() {
|
|
520
|
+
return vue.withDirectives(vue.h(primitive.DestylerPrimitive, this.$props, {
|
|
521
|
+
default: () => this.$slots.default ? this.$slots.default?.() : this.itemContext.value.value
|
|
522
|
+
}), [
|
|
523
|
+
[directives.BindOnceDirective, { id: this.itemContext.textId }]
|
|
524
|
+
]);
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
exports.DestylerDynamicClear = DestylerDynamicClear;
|
|
529
|
+
exports.DestylerDynamicInput = DestylerDynamicInput;
|
|
530
|
+
exports.DestylerDynamicItem = DestylerDynamicItem;
|
|
531
|
+
exports.DestylerDynamicItemDelete = DestylerDynamicItemDelete;
|
|
532
|
+
exports.DestylerDynamicItemText = DestylerDynamicItemText;
|
|
533
|
+
exports.DestylerDynamicRoot = DestylerDynamicRoot;
|