@varlet/ui 3.0.7 → 3.1.0-alpha.1709537939980

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.
Files changed (70) hide show
  1. package/es/action-sheet/ActionItem.mjs +79 -0
  2. package/es/action-sheet/ActionItemSfc.css +0 -0
  3. package/es/action-sheet/ActionSheet.mjs +29 -56
  4. package/es/action-sheet/actionSheet.css +1 -1
  5. package/es/action-sheet/props.mjs +3 -1
  6. package/es/action-sheet/style/index.mjs +1 -0
  7. package/es/button/Button.mjs +6 -6
  8. package/es/checkbox/Checkbox.mjs +83 -50
  9. package/es/checkbox/checkbox.css +1 -1
  10. package/es/context/stack.mjs +46 -0
  11. package/es/dialog/Dialog.mjs +12 -2
  12. package/es/dialog/props.mjs +4 -1
  13. package/es/field-decorator/FieldDecorator.mjs +10 -7
  14. package/es/field-decorator/props.mjs +1 -1
  15. package/es/hover-overlay/HoverOverlay.mjs +4 -2
  16. package/es/image-preview/ImagePreview.mjs +12 -16
  17. package/es/image-preview/props.mjs +4 -1
  18. package/es/index.bundle.mjs +1 -1
  19. package/es/index.mjs +1 -1
  20. package/es/input/Input.mjs +8 -8
  21. package/es/link/Link.mjs +10 -4
  22. package/es/link/link.css +1 -1
  23. package/es/menu/menu.css +1 -1
  24. package/es/menu/props.mjs +6 -1
  25. package/es/menu/usePopover.mjs +12 -2
  26. package/es/menu-option/MenuOption.mjs +72 -43
  27. package/es/menu-option/menuOption.css +1 -1
  28. package/es/menu-select/MenuSelect.mjs +28 -3
  29. package/es/option/Option.mjs +77 -48
  30. package/es/option/option.css +1 -1
  31. package/es/overlay/Overlay.mjs +19 -2
  32. package/es/overlay/props.mjs +7 -1
  33. package/es/paper/paper.css +1 -1
  34. package/es/picker/Picker.mjs +2 -0
  35. package/es/picker/props.mjs +4 -1
  36. package/es/popup/Popup.mjs +18 -2
  37. package/es/popup/props.mjs +7 -1
  38. package/es/radio/Radio.mjs +84 -42
  39. package/es/radio/radio.css +1 -1
  40. package/es/radio-group/RadioGroup.mjs +43 -1
  41. package/es/select/Select.mjs +279 -213
  42. package/es/select/select.css +1 -1
  43. package/es/style.css +1 -1
  44. package/es/switch/Switch.mjs +82 -52
  45. package/es/switch/switch.css +1 -1
  46. package/es/tab/tab.css +1 -1
  47. package/es/themes/dark/link.mjs +2 -1
  48. package/es/themes/dark/paper.mjs +2 -1
  49. package/es/themes/dark/tab.mjs +3 -1
  50. package/es/themes/md3-dark/link.mjs +2 -1
  51. package/es/themes/md3-dark/paper.mjs +2 -1
  52. package/es/themes/md3-dark/tab.mjs +3 -1
  53. package/es/themes/md3-light/link.mjs +2 -1
  54. package/es/themes/md3-light/paper.mjs +2 -1
  55. package/es/themes/md3-light/tab.mjs +3 -1
  56. package/es/tooltip/props.mjs +6 -1
  57. package/es/uploader/Uploader.mjs +70 -44
  58. package/es/uploader/uploader.css +1 -1
  59. package/es/utils/elements.mjs +32 -0
  60. package/es/varlet.esm.js +8014 -7704
  61. package/highlight/web-types.en-US.json +15 -2
  62. package/lib/style.css +1 -1
  63. package/lib/varlet.cjs.js +1753 -1224
  64. package/package.json +7 -7
  65. package/types/actionSheet.d.ts +4 -0
  66. package/types/input.d.ts +5 -1
  67. package/types/select.d.ts +6 -1
  68. package/types/styleVars.d.ts +100 -92
  69. package/umd/varlet.js +6 -6
  70. package/highlight/web-types.zh-CN.json +0 -8045
@@ -2,16 +2,18 @@ import VarFormDetails from "../form-details/index.mjs";
2
2
  import Ripple from "../ripple/index.mjs";
3
3
  import Hover from "../hover/index.mjs";
4
4
  import VarHoverOverlay, { useHoverOverlay } from "../hover-overlay/index.mjs";
5
- import { defineComponent, computed, nextTick } from "vue";
5
+ import { defineComponent, computed, nextTick, ref } from "vue";
6
6
  import { useValidation, createNamespace } from "../utils/components.mjs";
7
7
  import { multiplySizeUnit } from "../utils/elements.mjs";
8
8
  import { useForm } from "../form/provide.mjs";
9
9
  import { props } from "./props.mjs";
10
- import { call } from "@varlet/shared";
10
+ import { call, preventDefault } from "@varlet/shared";
11
+ import { useEventListener } from "@varlet/use";
11
12
  const { name, n, classes } = createNamespace("switch");
12
13
  import { normalizeClass as _normalizeClass, normalizeStyle as _normalizeStyle, createElementVNode as _createElementVNode, openBlock as _openBlock, createElementBlock as _createElementBlock, createCommentVNode as _createCommentVNode, resolveComponent as _resolveComponent, createVNode as _createVNode, resolveDirective as _resolveDirective, withDirectives as _withDirectives, pushScopeId as _pushScopeId, popScopeId as _popScopeId } from "vue";
13
14
  const _withScopeId = (n2) => (_pushScopeId(""), n2 = n2(), _popScopeId(), n2);
14
- const _hoisted_1 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ _createElementVNode(
15
+ const _hoisted_1 = ["tabindex"];
16
+ const _hoisted_2 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ _createElementVNode(
15
17
  "svg",
16
18
  { viewBox: "25 25 50 50" },
17
19
  [
@@ -25,8 +27,8 @@ const _hoisted_1 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ _createEle
25
27
  -1
26
28
  /* HOISTED */
27
29
  ));
28
- const _hoisted_2 = [
29
- _hoisted_1
30
+ const _hoisted_3 = [
31
+ _hoisted_2
30
32
  ];
31
33
  function __render__(_ctx, _cache) {
32
34
  const _component_var_hover_overlay = _resolveComponent("var-hover-overlay");
@@ -42,9 +44,10 @@ function __render__(_ctx, _cache) {
42
44
  _createElementVNode(
43
45
  "div",
44
46
  {
47
+ ref: "switchRef",
45
48
  class: _normalizeClass(_ctx.classes(_ctx.n("block"), [_ctx.disabled || _ctx.formDisabled, _ctx.n("--disabled")])),
46
- onClick: _cache[0] || (_cache[0] = (...args) => _ctx.switchActive && _ctx.switchActive(...args)),
47
- style: _normalizeStyle(_ctx.styleComputed.switch)
49
+ style: _normalizeStyle(_ctx.styleComputed.switch),
50
+ onClick: _cache[2] || (_cache[2] = (...args) => _ctx.switchActive && _ctx.switchActive(...args))
48
51
  },
49
52
  [
50
53
  _createElementVNode(
@@ -59,52 +62,52 @@ function __render__(_ctx, _cache) {
59
62
  6
60
63
  /* CLASS, STYLE */
61
64
  ),
62
- _withDirectives((_openBlock(), _createElementBlock(
63
- "div",
64
- {
65
- class: _normalizeClass(_ctx.classes(_ctx.n("ripple"), [_ctx.modelValue === _ctx.activeValue, _ctx.n("ripple--active")])),
66
- style: _normalizeStyle(_ctx.styleComputed.ripple)
67
- },
68
- [
69
- _createElementVNode(
70
- "div",
71
- {
72
- style: _normalizeStyle(_ctx.styleComputed.handle),
73
- class: _normalizeClass(
74
- _ctx.classes(
75
- _ctx.n("handle"),
76
- _ctx.n("$-elevation--2"),
77
- [_ctx.modelValue === _ctx.activeValue, _ctx.n("handle--active")],
78
- [_ctx.errorMessage, _ctx.n("handle--error")]
79
- )
65
+ _withDirectives((_openBlock(), _createElementBlock("div", {
66
+ class: _normalizeClass(_ctx.classes(_ctx.n("ripple"), [_ctx.modelValue === _ctx.activeValue, _ctx.n("ripple--active")])),
67
+ style: _normalizeStyle(_ctx.styleComputed.ripple),
68
+ tabindex: _ctx.disabled || _ctx.formDisabled ? void 0 : "0",
69
+ onFocus: _cache[0] || (_cache[0] = ($event) => _ctx.isFocusing = true),
70
+ onBlur: _cache[1] || (_cache[1] = ($event) => _ctx.isFocusing = false)
71
+ }, [
72
+ _createElementVNode(
73
+ "div",
74
+ {
75
+ style: _normalizeStyle(_ctx.styleComputed.handle),
76
+ class: _normalizeClass(
77
+ _ctx.classes(
78
+ _ctx.n("handle"),
79
+ _ctx.n("$-elevation--2"),
80
+ [_ctx.modelValue === _ctx.activeValue, _ctx.n("handle--active")],
81
+ [_ctx.errorMessage, _ctx.n("handle--error")]
80
82
  )
81
- },
82
- [
83
- _ctx.loading ? (_openBlock(), _createElementBlock(
84
- "span",
85
- {
86
- key: 0,
87
- class: _normalizeClass(_ctx.n("loading")),
88
- style: _normalizeStyle({
89
- width: _ctx.radius,
90
- height: _ctx.radius
91
- })
92
- },
93
- [..._hoisted_2],
94
- 6
95
- /* CLASS, STYLE */
96
- )) : _createCommentVNode("v-if", true)
97
- ],
98
- 6
99
- /* CLASS, STYLE */
100
- ),
101
- _createVNode(_component_var_hover_overlay, { hovering: _ctx.hovering }, null, 8, ["hovering"])
102
- ],
103
- 6
104
- /* CLASS, STYLE */
105
- )), [
83
+ )
84
+ },
85
+ [
86
+ _ctx.loading ? (_openBlock(), _createElementBlock(
87
+ "span",
88
+ {
89
+ key: 0,
90
+ class: _normalizeClass(_ctx.n("loading")),
91
+ style: _normalizeStyle({
92
+ width: _ctx.radius,
93
+ height: _ctx.radius
94
+ })
95
+ },
96
+ [..._hoisted_3],
97
+ 6
98
+ /* CLASS, STYLE */
99
+ )) : _createCommentVNode("v-if", true)
100
+ ],
101
+ 6
102
+ /* CLASS, STYLE */
103
+ ),
104
+ _createVNode(_component_var_hover_overlay, {
105
+ hovering: _ctx.hovering && !_ctx.disabled && !_ctx.formDisabled,
106
+ focusing: _ctx.isFocusing && !_ctx.disabled && !_ctx.formDisabled
107
+ }, null, 8, ["hovering", "focusing"])
108
+ ], 46, _hoisted_1)), [
106
109
  [_directive_ripple, {
107
- disabled: !_ctx.ripple || _ctx.disabled || _ctx.loading || _ctx.formDisabled
110
+ disabled: !_ctx.ripple || _ctx.disabled || _ctx.loading || _ctx.formDisabled || _ctx.readonly || _ctx.formReadonly
108
111
  }]
109
112
  ])
110
113
  ],
@@ -128,6 +131,8 @@ const __sfc__ = defineComponent({
128
131
  directives: { Ripple, Hover },
129
132
  props,
130
133
  setup(props2) {
134
+ const switchRef = ref(null);
135
+ const isFocusing = ref(false);
131
136
  const { bindForm, form } = useForm();
132
137
  const { errorMessage, validateWithTrigger: vt, validate: v, resetValidation } = useValidation();
133
138
  const { hovering, handleHovering } = useHoverOverlay();
@@ -166,6 +171,26 @@ const __sfc__ = defineComponent({
166
171
  resetValidation
167
172
  };
168
173
  call(bindForm, switchProvider);
174
+ useEventListener(() => window, "keydown", handleKeydown);
175
+ useEventListener(() => window, "keyup", handleKeyup);
176
+ function handleKeydown(event) {
177
+ if (!isFocusing.value) {
178
+ return;
179
+ }
180
+ if (event.key === " " || event.key === "Enter") {
181
+ preventDefault(event);
182
+ }
183
+ if (event.key === "Enter") {
184
+ switchRef.value.click();
185
+ }
186
+ }
187
+ function handleKeyup(event) {
188
+ if (!isFocusing.value || event.key !== " ") {
189
+ return;
190
+ }
191
+ preventDefault(event);
192
+ switchRef.value.click();
193
+ }
169
194
  function validate() {
170
195
  return v(props2.rules, props2.modelValue);
171
196
  }
@@ -189,8 +214,11 @@ const __sfc__ = defineComponent({
189
214
  "onUpdate:modelValue": updateModelValue,
190
215
  onBeforeChange
191
216
  } = props2;
217
+ if (disabled || (form == null ? void 0 : form.disabled.value)) {
218
+ return;
219
+ }
192
220
  call(onClick, event);
193
- if (disabled || loading || readonly || (form == null ? void 0 : form.disabled.value) || (form == null ? void 0 : form.readonly.value)) {
221
+ if (loading || readonly || (form == null ? void 0 : form.readonly.value)) {
194
222
  return;
195
223
  }
196
224
  const newValue = modelValue === activeValue ? inactiveValue : activeValue;
@@ -216,7 +244,9 @@ const __sfc__ = defineComponent({
216
244
  resetValidation();
217
245
  }
218
246
  return {
247
+ switchRef,
219
248
  hovering,
249
+ isFocusing,
220
250
  radius,
221
251
  styleComputed,
222
252
  errorMessage,
@@ -1 +1 @@
1
- :root { --switch-track-background: #fff; --switch-track-active-background: var(--color-primary); --switch-track-error-background: var(--color-danger); --switch-ripple-color: var(--color-primary); --switch-handle-background: #fff; --switch-handle-color: #fff; --switch-handle-active-background: var(--color-primary); --switch-handle-error-background: var(--color-danger); --switch-disabled-opacity: var(--opacity-disabled);}.var-switch { display: inline-block;}.var-switch__block { position: relative; display: flex; cursor: pointer; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); align-items: center; justify-content: center; height: 24px; width: 40px; transition: filter 0.25s;}.var-switch--disabled { filter: opacity(var(--switch-disabled-opacity)); cursor: not-allowed;}.var-switch__track { background-color: var(--switch-track-background); transition: background-color 0.25s; filter: opacity(var(--switch-disabled-opacity)); height: 14.4px; width: 38px; border-radius: calc(20px * 2 / 3);}.var-switch__track--active { background-color: var(--switch-track-active-background);}.var-switch__track--error { background-color: var(--switch-track-error-background) !important;}.var-switch__ripple { position: absolute; display: flex; align-items: center; justify-content: center; color: var(--switch-ripple-color); border-radius: 50%; overflow: hidden; transition: 0.3s var(--cubic-bezier); width: 40px; height: 40px; left: -10px;}.var-switch__ripple--active { left: 10px;}.var-switch__handle { border-radius: 50%; background-color: var(--switch-handle-background); display: flex; align-items: center; justify-content: center; color: var(--switch-handle-color); transition: background-color 0.25s; width: 20px; height: 20px;}.var-switch__handle--active { background-color: var(--switch-handle-active-background);}.var-switch__handle--error { background-color: var(--switch-handle-error-background) !important;}.var-switch__loading { display: inline-block; width: 16px; height: 16px; animation: circle 1.8s linear infinite;}.var-switch__loading svg { display: block; width: 100%; height: 100%;}.var-switch__loading svg circle { animation: circular 1.5s ease-in-out infinite; stroke: currentColor; stroke-width: 3; stroke-linecap: round;}@keyframes circle { from { transform: rotate(0deg); } to { transform: rotate(360deg); }}@keyframes circular { 0% { stroke-dasharray: 1, 200; stroke-dashoffset: 0; } 50% { stroke-dasharray: 90, 150; stroke-dashoffset: -40; } 100% { stroke-dasharray: 90, 150; stroke-dashoffset: -120; }}
1
+ :root { --switch-track-background: #fff; --switch-track-active-background: var(--color-primary); --switch-track-error-background: var(--color-danger); --switch-ripple-color: var(--color-primary); --switch-handle-background: #fff; --switch-handle-color: #fff; --switch-handle-active-background: var(--color-primary); --switch-handle-error-background: var(--color-danger); --switch-disabled-opacity: var(--opacity-disabled);}.var-switch { display: inline-block;}.var-switch__block { position: relative; display: flex; cursor: pointer; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); align-items: center; justify-content: center; height: 24px; width: 40px; transition: filter 0.25s;}.var-switch--disabled { filter: opacity(var(--switch-disabled-opacity)); cursor: not-allowed;}.var-switch__track { background-color: var(--switch-track-background); transition: background-color 0.25s; filter: opacity(var(--switch-disabled-opacity)); height: 14.4px; width: 38px; border-radius: calc(20px * 2 / 3);}.var-switch__track--active { background-color: var(--switch-track-active-background);}.var-switch__track--error { background-color: var(--switch-track-error-background) !important;}.var-switch__ripple { position: absolute; display: flex; align-items: center; justify-content: center; color: var(--switch-ripple-color); border-radius: 50%; overflow: hidden; outline: none; transition: 0.3s var(--cubic-bezier); width: 40px; height: 40px; left: -10px;}.var-switch__ripple--active { left: 10px;}.var-switch__handle { border-radius: 50%; background-color: var(--switch-handle-background); display: flex; align-items: center; justify-content: center; color: var(--switch-handle-color); transition: background-color 0.25s; width: 20px; height: 20px;}.var-switch__handle--active { background-color: var(--switch-handle-active-background);}.var-switch__handle--error { background-color: var(--switch-handle-error-background) !important;}.var-switch__loading { display: inline-block; width: 16px; height: 16px; animation: circle 1.8s linear infinite;}.var-switch__loading svg { display: block; width: 100%; height: 100%;}.var-switch__loading svg circle { animation: circular 1.5s ease-in-out infinite; stroke: currentColor; stroke-width: 3; stroke-linecap: round;}@keyframes circle { from { transform: rotate(0deg); } to { transform: rotate(360deg); }}@keyframes circular { 0% { stroke-dasharray: 1, 200; stroke-dashoffset: 0; } 50% { stroke-dasharray: 90, 150; stroke-dashoffset: -40; } 100% { stroke-dasharray: 90, 150; stroke-dashoffset: -120; }}
package/es/tab/tab.css CHANGED
@@ -1 +1 @@
1
- :root { --tab-padding: 12px; --tab-active-color: var(--color-primary); --tab-inactive-color: #646566; --tab-disabled-color: var(--color-text-disabled); --tab-font-size: var(--font-size-md); --tab-font-weight: 400;}.var-tab { display: flex; justify-content: center; align-items: center; flex: 1 0 auto; padding: 0 var(--tab-padding); font-size: var(--tab-font-size); font-weight: var(--tab-font-weight); cursor: pointer; user-select: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);}.var-tab--active { color: var(--tab-active-color);}.var-tab--inactive { color: var(--tab-inactive-color);}.var-tab--disabled { color: var(--tab-disabled-color); cursor: not-allowed;}.var-tab--horizontal { flex-direction: row;}.var-tab--vertical { flex-direction: column;}
1
+ :root { --tab-padding: 12px; --tab-active-color: var(--color-primary); --tab-inactive-color: #646566; --tab-disabled-color: var(--color-text-disabled); --tab-font-size: var(--font-size-md); --tab-font-weight: 400; --tab-active-font-size: var(--font-size-md); --tab-active-font-weight: 400;}.var-tab { display: flex; justify-content: center; align-items: center; flex: 1 0 auto; padding: 0 var(--tab-padding); font-size: var(--tab-font-size); font-weight: var(--tab-font-weight); cursor: pointer; user-select: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);}.var-tab--active { color: var(--tab-active-color); font-size: var(--tab-active-font-size); font-weight: var(--tab-active-font-weight);}.var-tab--inactive { color: var(--tab-inactive-color);}.var-tab--disabled { color: var(--tab-disabled-color); cursor: not-allowed;}.var-tab--horizontal { flex-direction: row;}.var-tab--vertical { flex-direction: column;}
@@ -6,7 +6,8 @@ var stdin_default = {
6
6
  "--link-warning-color": "var(--color-warning)",
7
7
  "--link-info-color": "var(--color-info)",
8
8
  "--link-disabled-color": "var(--color-text-disabled)",
9
- "--link-font-size": "var(--font-size-md)"
9
+ "--link-font-size": "var(--font-size-md)",
10
+ "--link-focus-opacity": "0.8"
10
11
  };
11
12
  export {
12
13
  stdin_default as default
@@ -1,5 +1,6 @@
1
1
  var stdin_default = {
2
- "--paper-background": "var(--color-surface-container-highest)"
2
+ "--paper-background": "var(--color-surface-container-highest)",
3
+ "--paper-border-radius": "4px"
3
4
  };
4
5
  export {
5
6
  stdin_default as default
@@ -4,7 +4,9 @@ var stdin_default = {
4
4
  "--tab-active-color": "var(--color-primary)",
5
5
  "--tab-disabled-color": "var(--color-text-disabled)",
6
6
  "--tab-font-size": "var(--font-size-md)",
7
- "--tab-font-weight": "400"
7
+ "--tab-font-weight": "400",
8
+ "--tab-active-font-size": "var(--font-size-md)",
9
+ "--tab-active-font-weight": "400"
8
10
  };
9
11
  export {
10
12
  stdin_default as default
@@ -6,7 +6,8 @@ var stdin_default = {
6
6
  "--link-warning-color": "var(--color-warning)",
7
7
  "--link-info-color": "var(--color-info)",
8
8
  "--link-disabled-color": "var(--color-text-disabled)",
9
- "--link-font-size": "var(--font-size-md)"
9
+ "--link-font-size": "var(--font-size-md)",
10
+ "--link-focus-opacity": "0.8"
10
11
  };
11
12
  export {
12
13
  stdin_default as default
@@ -1,5 +1,6 @@
1
1
  var stdin_default = {
2
- "--paper-background": "var(--color-surface-container-high)"
2
+ "--paper-background": "var(--color-surface-container-highest)",
3
+ "--paper-border-radius": "12px"
3
4
  };
4
5
  export {
5
6
  stdin_default as default
@@ -4,7 +4,9 @@ var stdin_default = {
4
4
  "--tab-active-color": "var(--color-primary)",
5
5
  "--tab-disabled-color": "var(--color-text-disabled)",
6
6
  "--tab-font-size": "var(--font-size-md)",
7
- "--tab-font-weight": "400"
7
+ "--tab-font-weight": "400",
8
+ "--tab-active-font-size": "var(--font-size-md)",
9
+ "--tab-active-font-weight": "400"
8
10
  };
9
11
  export {
10
12
  stdin_default as default
@@ -6,7 +6,8 @@ var stdin_default = {
6
6
  "--link-warning-color": "var(--color-warning)",
7
7
  "--link-info-color": "var(--color-info)",
8
8
  "--link-disabled-color": "var(--color-text-disabled)",
9
- "--link-font-size": "var(--font-size-md)"
9
+ "--link-font-size": "var(--font-size-md)",
10
+ "--link-focus-opacity": "0.8"
10
11
  };
11
12
  export {
12
13
  stdin_default as default
@@ -1,5 +1,6 @@
1
1
  var stdin_default = {
2
- "--paper-background": "var(--color-surface-container-low)"
2
+ "--paper-background": "var(--color-surface-container-low)",
3
+ "--paper-border-radius": "12px"
3
4
  };
4
5
  export {
5
6
  stdin_default as default
@@ -4,7 +4,9 @@ var stdin_default = {
4
4
  "--tab-active-color": "var(--color-primary)",
5
5
  "--tab-disabled-color": "var(--color-text-disabled)",
6
6
  "--tab-font-size": "var(--font-size-md)",
7
- "--tab-font-weight": "400"
7
+ "--tab-font-weight": "400",
8
+ "--tab-active-font-size": "var(--font-size-md)",
9
+ "--tab-active-font-weight": "400"
8
10
  };
9
11
  export {
10
12
  stdin_default as default
@@ -40,7 +40,12 @@ const props = {
40
40
  onClose: defineListenerProp(),
41
41
  onClosed: defineListenerProp(),
42
42
  onClickOutside: defineListenerProp(),
43
- "onUpdate:show": defineListenerProp()
43
+ "onUpdate:show": defineListenerProp(),
44
+ // internal for esc
45
+ closeOnKeyEscape: {
46
+ type: Boolean,
47
+ default: true
48
+ }
44
49
  };
45
50
  export {
46
51
  props
@@ -32,6 +32,7 @@ import { isHTMLSupportImage, isHTMLSupportVideo } from "../utils/shared.mjs";
32
32
  import { useValidation, createNamespace, formatElevation } from "../utils/components.mjs";
33
33
  import { useForm } from "../form/provide.mjs";
34
34
  import { toSizeUnit } from "../utils/elements.mjs";
35
+ import { useEventListener } from "@varlet/use";
35
36
  const { name, n, classes } = createNamespace("uploader");
36
37
  let fid = 0;
37
38
  import { renderList as _renderList, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock, toDisplayString as _toDisplayString, normalizeClass as _normalizeClass, createElementVNode as _createElementVNode, resolveComponent as _resolveComponent, createVNode as _createVNode, withModifiers as _withModifiers, createCommentVNode as _createCommentVNode, normalizeStyle as _normalizeStyle, resolveDirective as _resolveDirective, withDirectives as _withDirectives, renderSlot as _renderSlot, withCtx as _withCtx, createSlots as _createSlots, pushScopeId as _pushScopeId, popScopeId as _popScopeId } from "vue";
@@ -39,8 +40,9 @@ const _withScopeId = (n2) => (_pushScopeId(""), n2 = n2(), _popScopeId(), n2);
39
40
  const _hoisted_1 = ["onClick"];
40
41
  const _hoisted_2 = ["onClick"];
41
42
  const _hoisted_3 = ["src", "alt"];
42
- const _hoisted_4 = ["multiple", "accept", "capture", "disabled"];
43
- const _hoisted_5 = ["src"];
43
+ const _hoisted_4 = ["tabindex"];
44
+ const _hoisted_5 = ["multiple", "accept", "capture", "disabled"];
45
+ const _hoisted_6 = ["src"];
44
46
  function __render__(_ctx, _cache) {
45
47
  const _component_var_icon = _resolveComponent("var-icon");
46
48
  const _component_var_hover_overlay = _resolveComponent("var-hover-overlay");
@@ -126,45 +128,45 @@ function __render__(_ctx, _cache) {
126
128
  128
127
129
  /* KEYED_FRAGMENT */
128
130
  )),
129
- !_ctx.maxlength || _ctx.modelValue.length < _ctx.toNumber(_ctx.maxlength) ? _withDirectives((_openBlock(), _createElementBlock(
130
- "div",
131
- {
132
- key: 0,
133
- class: _normalizeClass(
134
- _ctx.classes(
135
- [!_ctx.$slots.default, `${_ctx.n("action")} ${_ctx.formatElevation(_ctx.elevation, 2)}`],
136
- [_ctx.disabled || _ctx.formDisabled, _ctx.n("--disabled")]
137
- )
138
- ),
139
- onClick: _cache[2] || (_cache[2] = (...args) => _ctx.handleActionClick && _ctx.handleActionClick(...args))
140
- },
141
- [
142
- _createElementVNode("input", {
143
- ref: "input",
144
- type: "file",
145
- class: _normalizeClass(_ctx.n("action-input")),
146
- multiple: _ctx.multiple,
147
- accept: _ctx.accept,
148
- capture: _ctx.capture,
149
- disabled: _ctx.disabled || _ctx.formDisabled || _ctx.readonly || _ctx.formReadonly,
150
- onChange: _cache[0] || (_cache[0] = (...args) => _ctx.handleChange && _ctx.handleChange(...args)),
151
- onClick: _cache[1] || (_cache[1] = _withModifiers(() => {
152
- }, ["stop"]))
153
- }, null, 42, _hoisted_4),
154
- _renderSlot(_ctx.$slots, "default", {}, () => [
155
- _createVNode(_component_var_icon, {
156
- class: _normalizeClass(_ctx.n("action-icon")),
157
- "var-uploader-cover": "",
158
- name: "plus"
159
- }, null, 8, ["class"]),
160
- _createVNode(_component_var_hover_overlay, {
161
- hovering: _ctx.hovering && !_ctx.disabled && !_ctx.formDisabled
162
- }, null, 8, ["hovering"])
163
- ])
164
- ],
165
- 2
166
- /* CLASS */
167
- )), [
131
+ !_ctx.maxlength || _ctx.modelValue.length < _ctx.toNumber(_ctx.maxlength) ? _withDirectives((_openBlock(), _createElementBlock("div", {
132
+ key: 0,
133
+ ref: "actionRef",
134
+ class: _normalizeClass(
135
+ _ctx.classes(
136
+ _ctx.n("--outline-none"),
137
+ [!_ctx.$slots.default, `${_ctx.n("action")} ${_ctx.formatElevation(_ctx.elevation, 2)}`],
138
+ [_ctx.disabled || _ctx.formDisabled, _ctx.n("--disabled")]
139
+ )
140
+ ),
141
+ tabindex: _ctx.disabled || _ctx.formDisabled ? void 0 : "0",
142
+ onClick: _cache[2] || (_cache[2] = (...args) => _ctx.handleActionClick && _ctx.handleActionClick(...args)),
143
+ onFocus: _cache[3] || (_cache[3] = ($event) => _ctx.isFocusing = true),
144
+ onBlur: _cache[4] || (_cache[4] = ($event) => _ctx.isFocusing = false)
145
+ }, [
146
+ _createElementVNode("input", {
147
+ ref: "input",
148
+ type: "file",
149
+ class: _normalizeClass(_ctx.n("action-input")),
150
+ multiple: _ctx.multiple,
151
+ accept: _ctx.accept,
152
+ capture: _ctx.capture,
153
+ disabled: _ctx.disabled || _ctx.formDisabled || _ctx.readonly || _ctx.formReadonly,
154
+ onChange: _cache[0] || (_cache[0] = (...args) => _ctx.handleChange && _ctx.handleChange(...args)),
155
+ onClick: _cache[1] || (_cache[1] = _withModifiers(() => {
156
+ }, ["stop"]))
157
+ }, null, 42, _hoisted_5),
158
+ _renderSlot(_ctx.$slots, "default", {}, () => [
159
+ _createVNode(_component_var_icon, {
160
+ class: _normalizeClass(_ctx.n("action-icon")),
161
+ "var-uploader-cover": "",
162
+ name: "plus"
163
+ }, null, 8, ["class"]),
164
+ _createVNode(_component_var_hover_overlay, {
165
+ hovering: _ctx.hovering && !_ctx.disabled && !_ctx.formDisabled && !_ctx.readonly && !_ctx.formReadonly,
166
+ focusing: _ctx.isFocusing && !_ctx.disabled && !_ctx.formDisabled && !_ctx.readonly && !_ctx.formReadonly
167
+ }, null, 8, ["hovering", "focusing"])
168
+ ])
169
+ ], 42, _hoisted_4)), [
168
170
  [_directive_ripple, {
169
171
  disabled: _ctx.disabled || _ctx.formDisabled || _ctx.readonly || _ctx.formReadonly || !_ctx.ripple || Boolean(_ctx.$slots.default)
170
172
  }],
@@ -194,8 +196,8 @@ function __render__(_ctx, _cache) {
194
196
  "var-uploader-cover": "",
195
197
  position: "center",
196
198
  show: _ctx.showPreview,
197
- "onUpdate:show": _cache[3] || (_cache[3] = ($event) => _ctx.showPreview = $event),
198
- onClosed: _cache[4] || (_cache[4] = ($event) => _ctx.currentPreview = null)
199
+ "onUpdate:show": _cache[5] || (_cache[5] = ($event) => _ctx.showPreview = $event),
200
+ onClosed: _cache[6] || (_cache[6] = ($event) => _ctx.currentPreview = null)
199
201
  }, {
200
202
  default: _withCtx(() => {
201
203
  var _a, _b;
@@ -210,7 +212,7 @@ function __render__(_ctx, _cache) {
210
212
  "x5-video-player-fullscreen": "false",
211
213
  controls: "",
212
214
  src: (_b = _ctx.currentPreview) == null ? void 0 : _b.url
213
- }, null, 10, _hoisted_5)) : _createCommentVNode("v-if", true)
215
+ }, null, 10, _hoisted_6)) : _createCommentVNode("v-if", true)
214
216
  ];
215
217
  }),
216
218
  _: 1
@@ -232,6 +234,8 @@ const __sfc__ = defineComponent({
232
234
  },
233
235
  props,
234
236
  setup(props2) {
237
+ const isFocusing = ref(false);
238
+ const actionRef = ref(null);
235
239
  const input = ref(null);
236
240
  const showPreview = ref(false);
237
241
  const currentPreview = ref(null);
@@ -270,6 +274,8 @@ const __sfc__ = defineComponent({
270
274
  reset
271
275
  };
272
276
  call(bindForm, uploaderProvider);
277
+ useEventListener(() => window, "keydown", handleKeydown);
278
+ useEventListener(() => window, "keyup", handleKeyup);
273
279
  watch(
274
280
  () => props2.modelValue,
275
281
  () => {
@@ -278,6 +284,24 @@ const __sfc__ = defineComponent({
278
284
  },
279
285
  { deep: true }
280
286
  );
287
+ function handleKeydown(event) {
288
+ if (!isFocusing.value) {
289
+ return;
290
+ }
291
+ if (event.key === " " || event.key === "Enter") {
292
+ event.preventDefault();
293
+ }
294
+ if (event.key === "Enter") {
295
+ actionRef.value.click();
296
+ }
297
+ }
298
+ function handleKeyup(event) {
299
+ if (!isFocusing.value || event.key !== " ") {
300
+ return;
301
+ }
302
+ event.preventDefault();
303
+ actionRef.value.click();
304
+ }
281
305
  function preview(varFile) {
282
306
  const { disabled, previewed, preventDefaultPreview, onPreview } = props2;
283
307
  if ((form == null ? void 0 : form.disabled.value) || disabled || !previewed) {
@@ -448,12 +472,14 @@ const __sfc__ = defineComponent({
448
472
  }
449
473
  return {
450
474
  input,
475
+ actionRef,
451
476
  files,
452
477
  showPreview,
453
478
  currentPreview,
454
479
  errorMessage,
455
480
  maxlengthText,
456
481
  hovering,
482
+ isFocusing,
457
483
  formDisabled: form == null ? void 0 : form.disabled,
458
484
  formReadonly: form == null ? void 0 : form.readonly,
459
485
  n,
@@ -1 +1 @@
1
- :root { --uploader-action-background: #f7f8fa; --uploader-action-icon-color: #888; --uploader-action-icon-size: 24px; --uploader-action-margin: 0 10px 10px 0; --uploader-file-size: 80px; --uploader-file-margin: 0 10px 10px 0; --uploader-file-name-background: #f7f8fa; --uploader-file-name-color: #888; --uploader-file-name-font-size: 12px; --uploader-file-name-padding: 10px; --uploader-file-text-align: center; --uploader-file-border-radius: 0; --uploader-file-close-background: rgba(0, 0, 0, 0.3); --uploader-file-close-size: 24px; --uploader-file-close-icon-font-size: 14px; --uploader-file-close-icon-color: #fff; --uploader-file-cover-fit: cover; --uploader-file-cover-background: #f7f8fa; --uploader-preview-video-width: 100vw; --uploader-preview-video-height: 100vw; --uploader-file-indicator-height: 4px; --uploader-file-indicator-normal-color: var(--color-disabled); --uploader-file-indicator-success-color: var(--color-success); --uploader-file-indicator-error-color: var(--color-danger); --uploader-file-progress-color: var(--color-primary); --uploader-disabled-color: var(--color-disabled); --uploader-disabled-text-color: var(--color-text-disabled); --uploader-loading-background: linear-gradient(90deg, hsla(0, 0%, 100%, 0), hsla(0, 0%, 100%, 0.3), hsla(0, 0%, 100%, 0));}@keyframes var-uploader-loading-animation { from { transform: translateX(-100%); } to { transform: translateX(100%); }}.var-uploader { width: 100%;}.var-uploader__file-list { width: 100%; display: flex; flex-wrap: wrap;}.var-uploader__file { position: relative; width: var(--uploader-file-size); height: var(--uploader-file-size); margin: var(--uploader-file-margin); border-radius: var(--uploader-file-border-radius); overflow: hidden; cursor: pointer; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);}.var-uploader__file-name { position: absolute; width: 100%; height: 100%; line-height: calc(var(--uploader-file-size) - var(--uploader-file-name-padding) * 2); font-size: var(--uploader-file-name-font-size); z-index: 0; background: var(--uploader-file-name-background); padding: var(--uploader-file-name-padding); color: var(--uploader-file-name-color); text-align: var(--uploader-file-text-align); white-space: nowrap; text-overflow: ellipsis; overflow: hidden; user-select: none; transition: background-color 0.25s;}.var-uploader__file-cover { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; background: var(--uploader-file-cover-background); object-fit: var(--uploader-file-cover-fit); pointer-events: none; transition: background-color 0.25s;}.var-uploader__file-close { position: absolute; top: 0; right: 0; z-index: 2; border-top: var(--uploader-file-close-size) solid var(--uploader-file-close-background); border-left: var(--uploader-file-close-size) solid transparent;}.var-uploader__file-close-icon[var-uploader-cover] { position: absolute; top: calc(-1 * var(--uploader-file-close-size)); right: 0; font-size: var(--uploader-file-close-icon-font-size); color: var(--uploader-file-close-icon-color);}.var-uploader__file-indicator { position: absolute; left: 0; bottom: 0; z-index: 2; width: 100%; height: var(--uploader-file-indicator-height); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; background: var(--uploader-file-indicator-normal-color);}.var-uploader__action { position: relative; display: flex; justify-content: center; align-items: center; color: var(--uploader-action-icon-color); width: var(--uploader-file-size); height: var(--uploader-file-size); background: var(--uploader-action-background); margin: var(--uploader-action-margin); border-radius: var(--uploader-file-border-radius); transition: background-color 0.25s; cursor: pointer;}.var-uploader__action-icon[var-uploader-cover] { font-size: var(--uploader-action-icon-size);}.var-uploader__action-input { display: block; width: 0; height: 0; visibility: hidden;}.var-uploader__preview[var-uploader-cover] { background: #000; box-shadow: none;}.var-uploader__preview-video { width: var(--uploader-preview-video-width); height: var(--uploader-preview-video-height);}.var-uploader__progress { width: 0%; height: 100%; background-color: var(--uploader-file-progress-color); transition: all 0.25s ease-in-out;}.var-uploader--loading::after { content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; animation: var-uploader-loading-animation 0.6s infinite; background: var(--uploader-loading-background); transition: background-color 0.25s;}.var-uploader--success { background: var(--uploader-file-indicator-success-color);}.var-uploader--error { background: var(--uploader-file-indicator-error-color);}.var-uploader--disabled { background: var(--uploader-disabled-color); color: var(--uploader-disabled-text-color); cursor: not-allowed;}
1
+ :root { --uploader-action-background: #f7f8fa; --uploader-action-icon-color: #888; --uploader-action-icon-size: 24px; --uploader-action-margin: 0 10px 10px 0; --uploader-file-size: 80px; --uploader-file-margin: 0 10px 10px 0; --uploader-file-name-background: #f7f8fa; --uploader-file-name-color: #888; --uploader-file-name-font-size: 12px; --uploader-file-name-padding: 10px; --uploader-file-text-align: center; --uploader-file-border-radius: 0; --uploader-file-close-background: rgba(0, 0, 0, 0.3); --uploader-file-close-size: 24px; --uploader-file-close-icon-font-size: 14px; --uploader-file-close-icon-color: #fff; --uploader-file-cover-fit: cover; --uploader-file-cover-background: #f7f8fa; --uploader-preview-video-width: 100vw; --uploader-preview-video-height: 100vw; --uploader-file-indicator-height: 4px; --uploader-file-indicator-normal-color: var(--color-disabled); --uploader-file-indicator-success-color: var(--color-success); --uploader-file-indicator-error-color: var(--color-danger); --uploader-file-progress-color: var(--color-primary); --uploader-disabled-color: var(--color-disabled); --uploader-disabled-text-color: var(--color-text-disabled); --uploader-loading-background: linear-gradient(90deg, hsla(0, 0%, 100%, 0), hsla(0, 0%, 100%, 0.3), hsla(0, 0%, 100%, 0));}@keyframes var-uploader-loading-animation { from { transform: translateX(-100%); } to { transform: translateX(100%); }}.var-uploader { width: 100%;}.var-uploader__file-list { width: 100%; display: flex; flex-wrap: wrap;}.var-uploader__file { position: relative; width: var(--uploader-file-size); height: var(--uploader-file-size); margin: var(--uploader-file-margin); border-radius: var(--uploader-file-border-radius); overflow: hidden; cursor: pointer; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);}.var-uploader__file-name { position: absolute; width: 100%; height: 100%; line-height: calc(var(--uploader-file-size) - var(--uploader-file-name-padding) * 2); font-size: var(--uploader-file-name-font-size); z-index: 0; background: var(--uploader-file-name-background); padding: var(--uploader-file-name-padding); color: var(--uploader-file-name-color); text-align: var(--uploader-file-text-align); white-space: nowrap; text-overflow: ellipsis; overflow: hidden; user-select: none; transition: background-color 0.25s;}.var-uploader__file-cover { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; background: var(--uploader-file-cover-background); object-fit: var(--uploader-file-cover-fit); pointer-events: none; transition: background-color 0.25s;}.var-uploader__file-close { position: absolute; top: 0; right: 0; z-index: 2; border-top: var(--uploader-file-close-size) solid var(--uploader-file-close-background); border-left: var(--uploader-file-close-size) solid transparent;}.var-uploader__file-close-icon[var-uploader-cover] { position: absolute; top: calc(-1 * var(--uploader-file-close-size)); right: 0; font-size: var(--uploader-file-close-icon-font-size); color: var(--uploader-file-close-icon-color);}.var-uploader__file-indicator { position: absolute; left: 0; bottom: 0; z-index: 2; width: 100%; height: var(--uploader-file-indicator-height); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; background: var(--uploader-file-indicator-normal-color);}.var-uploader__action { position: relative; display: flex; justify-content: center; align-items: center; color: var(--uploader-action-icon-color); width: var(--uploader-file-size); height: var(--uploader-file-size); background: var(--uploader-action-background); margin: var(--uploader-action-margin); border-radius: var(--uploader-file-border-radius); transition: background-color 0.25s; cursor: pointer;}.var-uploader__action-icon[var-uploader-cover] { font-size: var(--uploader-action-icon-size);}.var-uploader__action-input { display: block; width: 0; height: 0; visibility: hidden;}.var-uploader__preview[var-uploader-cover] { background: #000; box-shadow: none;}.var-uploader__preview-video { width: var(--uploader-preview-video-width); height: var(--uploader-preview-video-height);}.var-uploader__progress { width: 0%; height: 100%; background-color: var(--uploader-file-progress-color); transition: all 0.25s ease-in-out;}.var-uploader--loading::after { content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; animation: var-uploader-loading-animation 0.6s infinite; background: var(--uploader-loading-background); transition: background-color 0.25s;}.var-uploader--success { background: var(--uploader-file-indicator-success-color);}.var-uploader--error { background: var(--uploader-file-indicator-error-color);}.var-uploader--disabled { background: var(--uploader-disabled-color); color: var(--uploader-disabled-text-color); cursor: not-allowed;}.var-uploader--outline-none { outline: none;}
@@ -163,7 +163,39 @@ function formatStyleVars(styleVars) {
163
163
  function padStartFlex(style) {
164
164
  return style === "start" || style === "end" ? `flex-${style}` : style;
165
165
  }
166
+ const focusableSelector = ["button", "input", "select", "textarea", "[tabindex]", "[href]"].map((s) => `${s}:not([disabled])`).join(", ");
167
+ function focusChildElementByKey(hostElement, parentElement, key) {
168
+ var _a;
169
+ const focusableElements = parentElement.querySelectorAll(focusableSelector);
170
+ if (!focusableElements.length) {
171
+ return;
172
+ }
173
+ const isActiveHostElement = [hostElement, ...Array.from(hostElement.querySelectorAll(focusableSelector))].findIndex(
174
+ (el) => el === document.activeElement
175
+ ) !== -1;
176
+ const activeElementIndex = Array.from(focusableElements).findIndex((el) => el === document.activeElement);
177
+ if (key === "ArrowDown") {
178
+ if (isActiveHostElement && activeElementIndex === -1 || activeElementIndex === focusableElements.length - 1) {
179
+ focusableElements[0].focus();
180
+ return;
181
+ }
182
+ if (activeElementIndex !== -1 && activeElementIndex < focusableElements.length - 1) {
183
+ focusableElements[activeElementIndex + 1].focus();
184
+ return;
185
+ }
186
+ }
187
+ if (key === "ArrowUp") {
188
+ if (isActiveHostElement && activeElementIndex === -1 || activeElementIndex === 0) {
189
+ (_a = focusableElements[focusableElements.length - 1]) == null ? void 0 : _a.focus();
190
+ return;
191
+ }
192
+ if (activeElementIndex > 0) {
193
+ focusableElements[activeElementIndex - 1].focus();
194
+ }
195
+ }
196
+ }
166
197
  export {
198
+ focusChildElementByKey,
167
199
  formatStyleVars,
168
200
  getAllParentScroller,
169
201
  getLeft,