@hoci/core 0.5.9 → 0.7.0

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.cjs CHANGED
@@ -1,10 +1,416 @@
1
1
  'use strict';
2
2
 
3
- const vue = require('vue');
4
- const core = require('@vueuse/core');
5
3
  const shared = require('@hoci/shared');
4
+ const vue = require('vue');
6
5
  const tslx = require('tslx');
7
6
 
7
+ var _a;
8
+ const isClient = typeof window !== "undefined";
9
+ const isDef = (val) => typeof val !== "undefined";
10
+ const isFunction = (val) => typeof val === "function";
11
+ const isString = (val) => typeof val === "string";
12
+ const noop = () => {
13
+ };
14
+ isClient && ((_a = window == null ? void 0 : window.navigator) == null ? void 0 : _a.userAgent) && /iP(ad|hone|od)/.test(window.navigator.userAgent);
15
+
16
+ function resolveUnref(r) {
17
+ return typeof r === "function" ? r() : vue.unref(r);
18
+ }
19
+ function identity(arg) {
20
+ return arg;
21
+ }
22
+
23
+ function tryOnScopeDispose(fn) {
24
+ if (vue.getCurrentScope()) {
25
+ vue.onScopeDispose(fn);
26
+ return true;
27
+ }
28
+ return false;
29
+ }
30
+
31
+ function isDefined(v) {
32
+ return vue.unref(v) != null;
33
+ }
34
+
35
+ function syncRef(left, right, options = {}) {
36
+ var _a, _b;
37
+ const {
38
+ flush = "sync",
39
+ deep = false,
40
+ immediate = true,
41
+ direction = "both",
42
+ transform = {}
43
+ } = options;
44
+ let watchLeft;
45
+ let watchRight;
46
+ const transformLTR = (_a = transform.ltr) != null ? _a : (v) => v;
47
+ const transformRTL = (_b = transform.rtl) != null ? _b : (v) => v;
48
+ if (direction === "both" || direction === "ltr") {
49
+ watchLeft = vue.watch(left, (newValue) => right.value = transformLTR(newValue), { flush, deep, immediate });
50
+ }
51
+ if (direction === "both" || direction === "rtl") {
52
+ watchRight = vue.watch(right, (newValue) => left.value = transformRTL(newValue), { flush, deep, immediate });
53
+ }
54
+ return () => {
55
+ watchLeft == null ? void 0 : watchLeft();
56
+ watchRight == null ? void 0 : watchRight();
57
+ };
58
+ }
59
+
60
+ function tryOnMounted(fn, sync = true) {
61
+ if (vue.getCurrentInstance())
62
+ vue.onMounted(fn);
63
+ else if (sync)
64
+ fn();
65
+ else
66
+ vue.nextTick(fn);
67
+ }
68
+
69
+ function unrefElement(elRef) {
70
+ var _a;
71
+ const plain = resolveUnref(elRef);
72
+ return (_a = plain == null ? void 0 : plain.$el) != null ? _a : plain;
73
+ }
74
+
75
+ const defaultWindow = isClient ? window : void 0;
76
+
77
+ function useEventListener(...args) {
78
+ let target;
79
+ let events;
80
+ let listeners;
81
+ let options;
82
+ if (isString(args[0]) || Array.isArray(args[0])) {
83
+ [events, listeners, options] = args;
84
+ target = defaultWindow;
85
+ } else {
86
+ [target, events, listeners, options] = args;
87
+ }
88
+ if (!target)
89
+ return noop;
90
+ if (!Array.isArray(events))
91
+ events = [events];
92
+ if (!Array.isArray(listeners))
93
+ listeners = [listeners];
94
+ const cleanups = [];
95
+ const cleanup = () => {
96
+ cleanups.forEach((fn) => fn());
97
+ cleanups.length = 0;
98
+ };
99
+ const register = (el, event, listener) => {
100
+ el.addEventListener(event, listener, options);
101
+ return () => el.removeEventListener(event, listener, options);
102
+ };
103
+ const stopWatch = vue.watch(() => unrefElement(target), (el) => {
104
+ cleanup();
105
+ if (!el)
106
+ return;
107
+ cleanups.push(...events.flatMap((event) => {
108
+ return listeners.map((listener) => register(el, event, listener));
109
+ }));
110
+ }, { immediate: true, flush: "post" });
111
+ const stop = () => {
112
+ stopWatch();
113
+ cleanup();
114
+ };
115
+ tryOnScopeDispose(stop);
116
+ return stop;
117
+ }
118
+
119
+ function onClickOutside(target, handler, options = {}) {
120
+ const { window = defaultWindow, ignore = [], capture = true, detectIframe = false } = options;
121
+ if (!window)
122
+ return;
123
+ let shouldListen = true;
124
+ let fallback;
125
+ const shouldIgnore = (event) => {
126
+ return ignore.some((target2) => {
127
+ if (typeof target2 === "string") {
128
+ return Array.from(window.document.querySelectorAll(target2)).some((el) => el === event.target || event.composedPath().includes(el));
129
+ } else {
130
+ const el = unrefElement(target2);
131
+ return el && (event.target === el || event.composedPath().includes(el));
132
+ }
133
+ });
134
+ };
135
+ const listener = (event) => {
136
+ window.clearTimeout(fallback);
137
+ const el = unrefElement(target);
138
+ if (!el || el === event.target || event.composedPath().includes(el))
139
+ return;
140
+ if (event.detail === 0)
141
+ shouldListen = !shouldIgnore(event);
142
+ if (!shouldListen) {
143
+ shouldListen = true;
144
+ return;
145
+ }
146
+ handler(event);
147
+ };
148
+ const cleanup = [
149
+ useEventListener(window, "click", listener, { passive: true, capture }),
150
+ useEventListener(window, "pointerdown", (e) => {
151
+ const el = unrefElement(target);
152
+ if (el)
153
+ shouldListen = !e.composedPath().includes(el) && !shouldIgnore(e);
154
+ }, { passive: true }),
155
+ useEventListener(window, "pointerup", (e) => {
156
+ if (e.button === 0) {
157
+ const path = e.composedPath();
158
+ e.composedPath = () => path;
159
+ fallback = window.setTimeout(() => listener(e), 50);
160
+ }
161
+ }, { passive: true }),
162
+ detectIframe && useEventListener(window, "blur", (event) => {
163
+ var _a;
164
+ const el = unrefElement(target);
165
+ if (((_a = window.document.activeElement) == null ? void 0 : _a.tagName) === "IFRAME" && !(el == null ? void 0 : el.contains(window.document.activeElement)))
166
+ handler(event);
167
+ })
168
+ ].filter(Boolean);
169
+ const stop = () => cleanup.forEach((fn) => fn());
170
+ return stop;
171
+ }
172
+
173
+ function useSupported(callback, sync = false) {
174
+ const isSupported = vue.ref();
175
+ const update = () => isSupported.value = Boolean(callback());
176
+ update();
177
+ tryOnMounted(update, sync);
178
+ return isSupported;
179
+ }
180
+ function cloneFnJSON(source) {
181
+ return JSON.parse(JSON.stringify(source));
182
+ }
183
+
184
+ const _global = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
185
+ const globalKey = "__vueuse_ssr_handlers__";
186
+ _global[globalKey] = _global[globalKey] || {};
187
+
188
+ var __getOwnPropSymbols$f = Object.getOwnPropertySymbols;
189
+ var __hasOwnProp$f = Object.prototype.hasOwnProperty;
190
+ var __propIsEnum$f = Object.prototype.propertyIsEnumerable;
191
+ var __objRest$2 = (source, exclude) => {
192
+ var target = {};
193
+ for (var prop in source)
194
+ if (__hasOwnProp$f.call(source, prop) && exclude.indexOf(prop) < 0)
195
+ target[prop] = source[prop];
196
+ if (source != null && __getOwnPropSymbols$f)
197
+ for (var prop of __getOwnPropSymbols$f(source)) {
198
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$f.call(source, prop))
199
+ target[prop] = source[prop];
200
+ }
201
+ return target;
202
+ };
203
+ function useResizeObserver(target, callback, options = {}) {
204
+ const _a = options, { window = defaultWindow } = _a, observerOptions = __objRest$2(_a, ["window"]);
205
+ let observer;
206
+ const isSupported = useSupported(() => window && "ResizeObserver" in window);
207
+ const cleanup = () => {
208
+ if (observer) {
209
+ observer.disconnect();
210
+ observer = void 0;
211
+ }
212
+ };
213
+ const stopWatch = vue.watch(() => unrefElement(target), (el) => {
214
+ cleanup();
215
+ if (isSupported.value && window && el) {
216
+ observer = new ResizeObserver(callback);
217
+ observer.observe(el, observerOptions);
218
+ }
219
+ }, { immediate: true, flush: "post" });
220
+ const stop = () => {
221
+ cleanup();
222
+ stopWatch();
223
+ };
224
+ tryOnScopeDispose(stop);
225
+ return {
226
+ isSupported,
227
+ stop
228
+ };
229
+ }
230
+
231
+ function useElementBounding(target, options = {}) {
232
+ const {
233
+ reset = true,
234
+ windowResize = true,
235
+ windowScroll = true,
236
+ immediate = true
237
+ } = options;
238
+ const height = vue.ref(0);
239
+ const bottom = vue.ref(0);
240
+ const left = vue.ref(0);
241
+ const right = vue.ref(0);
242
+ const top = vue.ref(0);
243
+ const width = vue.ref(0);
244
+ const x = vue.ref(0);
245
+ const y = vue.ref(0);
246
+ function update() {
247
+ const el = unrefElement(target);
248
+ if (!el) {
249
+ if (reset) {
250
+ height.value = 0;
251
+ bottom.value = 0;
252
+ left.value = 0;
253
+ right.value = 0;
254
+ top.value = 0;
255
+ width.value = 0;
256
+ x.value = 0;
257
+ y.value = 0;
258
+ }
259
+ return;
260
+ }
261
+ const rect = el.getBoundingClientRect();
262
+ height.value = rect.height;
263
+ bottom.value = rect.bottom;
264
+ left.value = rect.left;
265
+ right.value = rect.right;
266
+ top.value = rect.top;
267
+ width.value = rect.width;
268
+ x.value = rect.x;
269
+ y.value = rect.y;
270
+ }
271
+ useResizeObserver(target, update);
272
+ vue.watch(() => unrefElement(target), (ele) => !ele && update());
273
+ if (windowScroll)
274
+ useEventListener("scroll", update, { capture: true, passive: true });
275
+ if (windowResize)
276
+ useEventListener("resize", update, { passive: true });
277
+ tryOnMounted(() => {
278
+ if (immediate)
279
+ update();
280
+ });
281
+ return {
282
+ height,
283
+ bottom,
284
+ left,
285
+ right,
286
+ top,
287
+ width,
288
+ x,
289
+ y,
290
+ update
291
+ };
292
+ }
293
+
294
+ function useElementVisibility(element, { window = defaultWindow, scrollTarget } = {}) {
295
+ const elementIsVisible = vue.ref(false);
296
+ const testBounding = () => {
297
+ if (!window)
298
+ return;
299
+ const document = window.document;
300
+ const el = unrefElement(element);
301
+ if (!el) {
302
+ elementIsVisible.value = false;
303
+ } else {
304
+ const rect = el.getBoundingClientRect();
305
+ elementIsVisible.value = rect.top <= (window.innerHeight || document.documentElement.clientHeight) && rect.left <= (window.innerWidth || document.documentElement.clientWidth) && rect.bottom >= 0 && rect.right >= 0;
306
+ }
307
+ };
308
+ vue.watch(() => unrefElement(element), () => testBounding(), { immediate: true, flush: "post" });
309
+ if (window) {
310
+ useEventListener(scrollTarget || window, "scroll", testBounding, {
311
+ capture: false,
312
+ passive: true
313
+ });
314
+ }
315
+ return elementIsVisible;
316
+ }
317
+
318
+ var SwipeDirection;
319
+ (function(SwipeDirection2) {
320
+ SwipeDirection2["UP"] = "UP";
321
+ SwipeDirection2["RIGHT"] = "RIGHT";
322
+ SwipeDirection2["DOWN"] = "DOWN";
323
+ SwipeDirection2["LEFT"] = "LEFT";
324
+ SwipeDirection2["NONE"] = "NONE";
325
+ })(SwipeDirection || (SwipeDirection = {}));
326
+
327
+ var __defProp = Object.defineProperty;
328
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
329
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
330
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
331
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
332
+ var __spreadValues = (a, b) => {
333
+ for (var prop in b || (b = {}))
334
+ if (__hasOwnProp.call(b, prop))
335
+ __defNormalProp(a, prop, b[prop]);
336
+ if (__getOwnPropSymbols)
337
+ for (var prop of __getOwnPropSymbols(b)) {
338
+ if (__propIsEnum.call(b, prop))
339
+ __defNormalProp(a, prop, b[prop]);
340
+ }
341
+ return a;
342
+ };
343
+ const _TransitionPresets = {
344
+ easeInSine: [0.12, 0, 0.39, 0],
345
+ easeOutSine: [0.61, 1, 0.88, 1],
346
+ easeInOutSine: [0.37, 0, 0.63, 1],
347
+ easeInQuad: [0.11, 0, 0.5, 0],
348
+ easeOutQuad: [0.5, 1, 0.89, 1],
349
+ easeInOutQuad: [0.45, 0, 0.55, 1],
350
+ easeInCubic: [0.32, 0, 0.67, 0],
351
+ easeOutCubic: [0.33, 1, 0.68, 1],
352
+ easeInOutCubic: [0.65, 0, 0.35, 1],
353
+ easeInQuart: [0.5, 0, 0.75, 0],
354
+ easeOutQuart: [0.25, 1, 0.5, 1],
355
+ easeInOutQuart: [0.76, 0, 0.24, 1],
356
+ easeInQuint: [0.64, 0, 0.78, 0],
357
+ easeOutQuint: [0.22, 1, 0.36, 1],
358
+ easeInOutQuint: [0.83, 0, 0.17, 1],
359
+ easeInExpo: [0.7, 0, 0.84, 0],
360
+ easeOutExpo: [0.16, 1, 0.3, 1],
361
+ easeInOutExpo: [0.87, 0, 0.13, 1],
362
+ easeInCirc: [0.55, 0, 1, 0.45],
363
+ easeOutCirc: [0, 0.55, 0.45, 1],
364
+ easeInOutCirc: [0.85, 0, 0.15, 1],
365
+ easeInBack: [0.36, 0, 0.66, -0.56],
366
+ easeOutBack: [0.34, 1.56, 0.64, 1],
367
+ easeInOutBack: [0.68, -0.6, 0.32, 1.6]
368
+ };
369
+ __spreadValues({
370
+ linear: identity
371
+ }, _TransitionPresets);
372
+
373
+ function useVModel(props, key, emit, options = {}) {
374
+ var _a, _b, _c;
375
+ const {
376
+ clone = false,
377
+ passive = false,
378
+ eventName,
379
+ deep = false,
380
+ defaultValue
381
+ } = options;
382
+ const vm = vue.getCurrentInstance();
383
+ const _emit = emit || (vm == null ? void 0 : vm.emit) || ((_a = vm == null ? void 0 : vm.$emit) == null ? void 0 : _a.bind(vm)) || ((_c = (_b = vm == null ? void 0 : vm.proxy) == null ? void 0 : _b.$emit) == null ? void 0 : _c.bind(vm == null ? void 0 : vm.proxy));
384
+ let event = eventName;
385
+ if (!key) {
386
+ {
387
+ key = "modelValue";
388
+ }
389
+ }
390
+ event = eventName || event || `update:${key.toString()}`;
391
+ const cloneFn = (val) => !clone ? val : isFunction(clone) ? clone(val) : cloneFnJSON(val);
392
+ const getValue = () => isDef(props[key]) ? cloneFn(props[key]) : defaultValue;
393
+ if (passive) {
394
+ const initialValue = getValue();
395
+ const proxy = vue.ref(initialValue);
396
+ vue.watch(() => props[key], (v) => proxy.value = cloneFn(v));
397
+ vue.watch(proxy, (v) => {
398
+ if (v !== props[key] || deep)
399
+ _emit(event, v);
400
+ }, { deep });
401
+ return proxy;
402
+ } else {
403
+ return vue.computed({
404
+ get() {
405
+ return getValue();
406
+ },
407
+ set(value) {
408
+ _emit(event, value);
409
+ }
410
+ });
411
+ }
412
+ }
413
+
8
414
  const affixProps = shared.defineHookProps(
9
415
  {
10
416
  fixedClass: {
@@ -54,8 +460,8 @@ function getTargetRect(target) {
54
460
  const useAffix = shared.defineHookComponent({
55
461
  props: affixProps,
56
462
  setup(props, { emit }) {
57
- const wrapperRef = vue.ref(null);
58
- const wrapperRect = shared.toReactive(core.useElementBounding(wrapperRef));
463
+ const wrapperRef = shared.elementRef();
464
+ const wrapperRect = shared.toReactive(useElementBounding(wrapperRef));
59
465
  const parentRef = vue.inject(AFFIX_TARGET_KEY, void 0);
60
466
  const targetRef = shared.useElement(props.target, parentRef);
61
467
  const isFixed = vue.ref(false);
@@ -64,7 +470,7 @@ const useAffix = shared.defineHookComponent({
64
470
  const className = vue.computed(() => {
65
471
  return isFixed.value ? props.fixedClass : "";
66
472
  });
67
- const wrapperVisible = core.useElementVisibility(wrapperRef);
473
+ const wrapperVisible = useElementVisibility(wrapperRef);
68
474
  const containerRef = vue.computed(() => {
69
475
  if (!wrapperVisible.value) {
70
476
  return null;
@@ -111,11 +517,11 @@ const useAffix = shared.defineHookComponent({
111
517
  ...newIsFixed ? newPlaceholderStyles : {}
112
518
  };
113
519
  });
114
- core.useEventListener(containerRef, "scroll", () => {
520
+ useEventListener(containerRef, "scroll", () => {
115
521
  emit("scroll");
116
522
  updatePosition();
117
523
  });
118
- core.useEventListener(containerRef, "resize", updatePosition);
524
+ useEventListener(containerRef, "resize", updatePosition);
119
525
  vue.watchPostEffect(updatePosition);
120
526
  return {
121
527
  className,
@@ -132,6 +538,150 @@ function provideAffixTarget(target) {
132
538
  vue.provide(AFFIX_TARGET_KEY, target);
133
539
  }
134
540
 
541
+ const configProviderProps = shared.defineHookProps({
542
+ icon: {
543
+ type: Object
544
+ },
545
+ activateEvent: {
546
+ type: String
547
+ }
548
+ });
549
+
550
+ const fileUploadProps = shared.defineHookProps({
551
+ modelValue: {
552
+ type: [File, Array],
553
+ default: () => []
554
+ },
555
+ multiple: {
556
+ type: Boolean,
557
+ default: false
558
+ }
559
+ });
560
+ const fileUploadEmits = shared.defineHookEmits([
561
+ "update:modelValue",
562
+ "change"
563
+ ]);
564
+ const useFileUpload = shared.defineHookComponent({
565
+ props: fileUploadProps,
566
+ emits: fileUploadEmits,
567
+ setup(props, { emit }) {
568
+ const fileInputRef = shared.elementRef();
569
+ const files = vue.ref([]);
570
+ vue.watch(props.modelValue, (value) => {
571
+ if (value instanceof File) {
572
+ files.value.push(value);
573
+ } else if (Array.isArray(value)) {
574
+ files.value.push(...value);
575
+ }
576
+ if (props.multiple) {
577
+ files.value.splice(1, files.value.length - 1);
578
+ }
579
+ }, {
580
+ immediate: true,
581
+ deep: true
582
+ });
583
+ const openFileInput = () => {
584
+ fileInputRef.value?.click();
585
+ };
586
+ useEventListener(fileInputRef, "change", (event) => {
587
+ const newFiles = event.target.files;
588
+ let value = [];
589
+ if (newFiles) {
590
+ if (props.multiple) {
591
+ value = Array.from(newFiles);
592
+ files.value.push(...value);
593
+ } else {
594
+ value = Array.from(newFiles)[0];
595
+ files.value = value ? [value] : [];
596
+ }
597
+ }
598
+ emit("update:modelValue", value);
599
+ emit("change", value);
600
+ });
601
+ return {
602
+ fileInputRef,
603
+ files,
604
+ openFileInput
605
+ };
606
+ }
607
+ });
608
+
609
+ const iconProps = shared.defineHookProps({
610
+ src: {
611
+ type: String,
612
+ required: true
613
+ },
614
+ size: {
615
+ type: [Number, String]
616
+ },
617
+ width: {
618
+ type: [Number, String]
619
+ },
620
+ height: {
621
+ type: [Number, String]
622
+ },
623
+ color: {
624
+ type: String,
625
+ default: "currentColor"
626
+ },
627
+ mask: {
628
+ type: [Boolean, String],
629
+ default: () => "auto"
630
+ }
631
+ });
632
+ const isSvg = (src) => src.endsWith(".svg") || src.startsWith("data:image/svg+xml");
633
+ const useIcon = shared.defineHookComponent({
634
+ props: iconProps,
635
+ setup(props, context) {
636
+ const sharedConfig = shared.useSharedConfig("icon");
637
+ const sizeStyle = vue.computed(() => {
638
+ const s = props.size ?? sharedConfig.size;
639
+ const unit = tslx.createUnitFormat(sharedConfig.sizeUnit ?? "px");
640
+ const size = s ? unit(s) : void 0;
641
+ const w = props.width ?? size;
642
+ const h = props.height ?? size;
643
+ const width = w ? unit(w) : void 0;
644
+ const height = h ? unit(h) : void 0;
645
+ return {
646
+ width,
647
+ height
648
+ };
649
+ });
650
+ const dynamicStyle = vue.computed(() => {
651
+ const mask = props.mask === "auto" ? isSvg(props.src) : props.mask;
652
+ if (!mask) {
653
+ return {
654
+ "background-image": "var(--icon-url)",
655
+ "background-size": "100% 100%"
656
+ };
657
+ }
658
+ return {
659
+ "mask": "var(--icon-url) no-repeat",
660
+ "mask-size": "100% 100%",
661
+ "-webkit-mask": "var(--icon-url) no-repeat",
662
+ "-webkit-mask-size": "100% 100%",
663
+ "background-color": props.color
664
+ };
665
+ });
666
+ const staticStyle = vue.computed(() => {
667
+ return {
668
+ "--icon-url": `url("${props.src}")`
669
+ };
670
+ });
671
+ const style = vue.computed(() => {
672
+ return {
673
+ ...staticStyle.value,
674
+ ...dynamicStyle.value,
675
+ ...sizeStyle.value,
676
+ ...context.attrs.style ?? {}
677
+ };
678
+ });
679
+ return {
680
+ style
681
+ };
682
+ }
683
+ });
684
+
135
685
  const selectionProps = shared.defineHookProps({
136
686
  modelValue: {
137
687
  type: shared.valuePropType,
@@ -166,7 +716,7 @@ const selectionProps = shared.defineHookProps({
166
716
  * 多选模式
167
717
  */
168
718
  multiple: {
169
- type: [Boolean, Number],
719
+ type: [Boolean, Number, Array],
170
720
  default: () => false
171
721
  },
172
722
  /**
@@ -207,7 +757,8 @@ function useSelectionContext() {
207
757
  itemClass: "",
208
758
  activateEvent: sharedConfig.activateEvent,
209
759
  label: null,
210
- multiple: false
760
+ multiple: false,
761
+ limit: [0, Number.POSITIVE_INFINITY]
211
762
  });
212
763
  }
213
764
  const useSelectionList = shared.defineHookComponent({
@@ -216,7 +767,7 @@ const useSelectionList = shared.defineHookComponent({
216
767
  setup(props, { emit, slots }) {
217
768
  const options = vue.reactive([]);
218
769
  function toArray(value) {
219
- if (!core.isDefined(value)) {
770
+ if (!isDefined(value)) {
220
771
  return [];
221
772
  }
222
773
  if (props.multiple && Array.isArray(value)) {
@@ -243,21 +794,31 @@ const useSelectionList = shared.defineHookComponent({
243
794
  emit("update:modelValue", val);
244
795
  }
245
796
  });
246
- core.syncRef(currentValue, modelValue, { immediate: true, deep: true });
797
+ syncRef(currentValue, modelValue, { immediate: true, deep: true });
247
798
  const emitChange = () => emit("change", currentValue.value);
248
799
  function isActive(value) {
249
800
  return actives.includes(value);
250
801
  }
802
+ const multipleActive = vue.computed(() => !!props.multiple);
803
+ const multipleLimit = vue.computed(() => {
804
+ if (Array.isArray(props.multiple)) {
805
+ if (props.multiple[1] === void 0) {
806
+ return [props.multiple[0], Number.POSITIVE_INFINITY];
807
+ }
808
+ return props.multiple;
809
+ }
810
+ return [0, Number.POSITIVE_INFINITY];
811
+ });
251
812
  function activate(value) {
813
+ const [min, max] = multipleLimit.value;
252
814
  if (isActive(value)) {
253
- if (props.multiple || props.clearable) {
815
+ if (multipleActive.value && actives.length > min || props.clearable) {
254
816
  actives.splice(actives.indexOf(value), 1);
255
817
  emitChange();
256
818
  }
257
819
  } else {
258
820
  if (props.multiple) {
259
- const limit = typeof props.multiple === "number" ? props.multiple : Number.POSITIVE_INFINITY;
260
- if (actives.length < limit) {
821
+ if (actives.length < max) {
261
822
  actives.push(value);
262
823
  emitChange();
263
824
  }
@@ -295,7 +856,8 @@ const useSelectionList = shared.defineHookComponent({
295
856
  disabledClass: vue.computed(() => tslx.cls(props.disabledClass)),
296
857
  itemClass: vue.computed(() => tslx.cls(props.itemClass)),
297
858
  label: vue.computed(() => props.label),
298
- multiple: vue.computed(() => props.multiple),
859
+ multiple: multipleActive,
860
+ limit: multipleLimit,
299
861
  clearable: vue.computed(() => props.clearable),
300
862
  defaultValue: vue.computed(() => props.defaultValue),
301
863
  activateEvent: vue.computed(() => props.activateEvent ?? sharedConfig.activateEvent),
@@ -395,7 +957,7 @@ const useSelectionItem = shared.defineHookComponent({
395
957
  },
396
958
  { immediate: true }
397
959
  );
398
- core.tryOnScopeDispose(remove);
960
+ tryOnScopeDispose(remove);
399
961
  }
400
962
  const isActive = vue.computed(() => context.isActive(props.value));
401
963
  const isDisabled = vue.computed(() => props.disabled);
@@ -421,157 +983,6 @@ const useSelectionItem = shared.defineHookComponent({
421
983
  }
422
984
  });
423
985
 
424
- const switchProps = shared.defineHookProps({
425
- modelValue: {
426
- type: Boolean,
427
- default: () => false
428
- },
429
- class: {
430
- type: shared.classPropType
431
- },
432
- activeClass: {
433
- type: shared.classPropType
434
- },
435
- unactiveClass: {
436
- type: shared.classPropType
437
- },
438
- activateEvent: {
439
- type: String
440
- },
441
- disabled: {
442
- type: Boolean,
443
- default: () => false
444
- },
445
- disabledClass: {
446
- type: shared.classPropType
447
- }
448
- });
449
- const switchEmits = shared.defineHookEmits(["update:modelValue", "change", "reject"]);
450
- const useSwitch = shared.defineHookComponent({
451
- props: switchProps,
452
- emits: switchEmits,
453
- setup(props, context) {
454
- const modelValue = core.useVModel(props, "modelValue", context.emit, {
455
- passive: true,
456
- defaultValue: false
457
- });
458
- const toggle = function(value) {
459
- if (props.disabled) {
460
- context.emit("reject", value);
461
- return;
462
- }
463
- const oldValue = modelValue.value;
464
- const newValue = typeof value === "boolean" ? value : !oldValue;
465
- if (newValue !== oldValue) {
466
- modelValue.value = newValue;
467
- context.emit("change", newValue);
468
- }
469
- };
470
- const isDisabled = vue.computed(() => props.disabled);
471
- const className = vue.computed(() => {
472
- return tslx.cls([
473
- props.class,
474
- modelValue.value ? props.activeClass : props.unactiveClass,
475
- isDisabled.value ? props.disabledClass : ""
476
- ]);
477
- });
478
- const sharedConfig = shared.useSharedConfig();
479
- const activateEvent = vue.computed(() => props.activateEvent ?? sharedConfig.activateEvent);
480
- return {
481
- toggle,
482
- modelValue,
483
- className,
484
- isDisabled,
485
- activateEvent
486
- };
487
- }
488
- });
489
-
490
- const iconProps = shared.defineHookProps({
491
- src: {
492
- type: String,
493
- required: true
494
- },
495
- size: {
496
- type: [Number, String]
497
- },
498
- width: {
499
- type: [Number, String]
500
- },
501
- height: {
502
- type: [Number, String]
503
- },
504
- color: {
505
- type: String,
506
- default: "currentColor"
507
- },
508
- mask: {
509
- type: [Boolean, String],
510
- default: () => "auto"
511
- }
512
- });
513
- const isSvg = (src) => src.endsWith(".svg") || src.startsWith("data:image/svg+xml");
514
- const useIcon = shared.defineHookComponent({
515
- props: iconProps,
516
- setup(props, context) {
517
- const sharedConfig = shared.useSharedConfig("icon");
518
- const sizeStyle = vue.computed(() => {
519
- const s = props.size ?? sharedConfig.size;
520
- const unit = tslx.createUnitFormat(sharedConfig.sizeUnit ?? "px");
521
- const size = s ? unit(s) : void 0;
522
- const w = props.width ?? size;
523
- const h = props.height ?? size;
524
- const width = w ? unit(w) : void 0;
525
- const height = h ? unit(h) : void 0;
526
- return {
527
- width,
528
- height
529
- };
530
- });
531
- const dynamicStyle = vue.computed(() => {
532
- const mask = props.mask === "auto" ? isSvg(props.src) : props.mask;
533
- if (!mask) {
534
- return {
535
- "background-image": "var(--icon-url)",
536
- "background-size": "100% 100%"
537
- };
538
- }
539
- return {
540
- "mask": "var(--icon-url) no-repeat",
541
- "mask-size": "100% 100%",
542
- "-webkit-mask": "var(--icon-url) no-repeat",
543
- "-webkit-mask-size": "100% 100%",
544
- "background-color": props.color
545
- };
546
- });
547
- const staticStyle = vue.computed(() => {
548
- return {
549
- "--icon-url": `url("${props.src}")`
550
- };
551
- });
552
- const style = vue.computed(() => {
553
- return {
554
- ...staticStyle.value,
555
- ...dynamicStyle.value,
556
- ...sizeStyle.value,
557
- ...context.attrs.style ?? {}
558
- };
559
- });
560
- return {
561
- style
562
- };
563
- }
564
- });
565
-
566
- const configProviderProps = shared.defineHookProps({
567
- icon: {
568
- type: Object
569
- },
570
- activateEvent: {
571
- type: String
572
- }
573
- });
574
-
575
986
  const popoverProps = shared.defineHookProps({
576
987
  popupClass: {
577
988
  type: String
@@ -610,11 +1021,11 @@ const usePopover = shared.defineHookComponent({
610
1021
  props: popoverProps,
611
1022
  emits: popoverEmits,
612
1023
  setup(props, context) {
613
- const visible = core.useVModel(props, "visible", context.emit, {
1024
+ const visible = useVModel(props, "visible", context.emit, {
614
1025
  passive: true
615
1026
  });
616
- const triggerRef = vue.ref();
617
- const popupRef = vue.ref();
1027
+ const triggerRef = shared.elementRef();
1028
+ const popupRef = shared.elementRef();
618
1029
  const validate = (event) => {
619
1030
  const events2 = Array.isArray(event) ? event : [event];
620
1031
  return !props.disabled && events2.includes(props.triggerEvent);
@@ -651,7 +1062,7 @@ const usePopover = shared.defineHookComponent({
651
1062
  e.stopPropagation();
652
1063
  toggle();
653
1064
  };
654
- core.onClickOutside(triggerRef, () => {
1065
+ onClickOutside(triggerRef, () => {
655
1066
  if (!validate(["click", "contextmenu", "touch", "dblclick", "mousedown"])) {
656
1067
  return;
657
1068
  }
@@ -805,10 +1216,78 @@ const usePopover = shared.defineHookComponent({
805
1216
  }
806
1217
  });
807
1218
 
1219
+ const switchProps = shared.defineHookProps({
1220
+ modelValue: {
1221
+ type: Boolean,
1222
+ default: () => false
1223
+ },
1224
+ class: {
1225
+ type: shared.classPropType
1226
+ },
1227
+ activeClass: {
1228
+ type: shared.classPropType
1229
+ },
1230
+ unactiveClass: {
1231
+ type: shared.classPropType
1232
+ },
1233
+ activateEvent: {
1234
+ type: String
1235
+ },
1236
+ disabled: {
1237
+ type: Boolean,
1238
+ default: () => false
1239
+ },
1240
+ disabledClass: {
1241
+ type: shared.classPropType
1242
+ }
1243
+ });
1244
+ const switchEmits = shared.defineHookEmits(["update:modelValue", "change", "reject"]);
1245
+ const useSwitch = shared.defineHookComponent({
1246
+ props: switchProps,
1247
+ emits: switchEmits,
1248
+ setup(props, context) {
1249
+ const modelValue = useVModel(props, "modelValue", context.emit, {
1250
+ passive: true,
1251
+ defaultValue: false
1252
+ });
1253
+ const toggle = function(value) {
1254
+ if (props.disabled) {
1255
+ context.emit("reject", value);
1256
+ return;
1257
+ }
1258
+ const oldValue = modelValue.value;
1259
+ const newValue = typeof value === "boolean" ? value : !oldValue;
1260
+ if (newValue !== oldValue) {
1261
+ modelValue.value = newValue;
1262
+ context.emit("change", newValue);
1263
+ }
1264
+ };
1265
+ const isDisabled = vue.computed(() => props.disabled);
1266
+ const className = vue.computed(() => {
1267
+ return tslx.cls([
1268
+ props.class,
1269
+ modelValue.value ? props.activeClass : props.unactiveClass,
1270
+ isDisabled.value ? props.disabledClass : ""
1271
+ ]);
1272
+ });
1273
+ const sharedConfig = shared.useSharedConfig();
1274
+ const activateEvent = vue.computed(() => props.activateEvent ?? sharedConfig.activateEvent);
1275
+ return {
1276
+ toggle,
1277
+ modelValue,
1278
+ className,
1279
+ isDisabled,
1280
+ activateEvent
1281
+ };
1282
+ }
1283
+ });
1284
+
808
1285
  exports.AFFIX_TARGET_KEY = AFFIX_TARGET_KEY;
809
1286
  exports.affixEmits = affixEmits;
810
1287
  exports.affixProps = affixProps;
811
1288
  exports.configProviderProps = configProviderProps;
1289
+ exports.fileUploadEmits = fileUploadEmits;
1290
+ exports.fileUploadProps = fileUploadProps;
812
1291
  exports.iconProps = iconProps;
813
1292
  exports.itemEmits = itemEmits;
814
1293
  exports.itemProps = itemProps;
@@ -820,12 +1299,20 @@ exports.selectionProps = selectionProps;
820
1299
  exports.switchEmits = switchEmits;
821
1300
  exports.switchProps = switchProps;
822
1301
  exports.useAffix = useAffix;
1302
+ exports.useFileUpload = useFileUpload;
823
1303
  exports.useIcon = useIcon;
824
1304
  exports.usePopover = usePopover;
825
1305
  exports.useSelectionContext = useSelectionContext;
826
1306
  exports.useSelectionItem = useSelectionItem;
827
1307
  exports.useSelectionList = useSelectionList;
828
1308
  exports.useSwitch = useSwitch;
1309
+ Object.prototype.hasOwnProperty.call(shared, '__proto__') &&
1310
+ !Object.prototype.hasOwnProperty.call(exports, '__proto__') &&
1311
+ Object.defineProperty(exports, '__proto__', {
1312
+ enumerable: true,
1313
+ value: shared['__proto__']
1314
+ });
1315
+
829
1316
  Object.keys(shared).forEach(function (k) {
830
1317
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = shared[k];
831
1318
  });