hys-ui 0.1.0 → 0.1.1

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 (99) hide show
  1. package/CHANGELOG.md +26 -1
  2. package/README.md +16 -6
  3. package/dist/components/HysAlert/HysAlert.vue.js +14 -14
  4. package/dist/components/HysAnimatedNumber/HysAnimatedNumber.vue.js +23 -20
  5. package/dist/components/HysBadge/HysBadge.vue.js +1 -1
  6. package/dist/components/HysBadge/HysBadge2.vue.js +20 -19
  7. package/dist/components/HysCalendar/HysCalendar.vue.js +48 -40
  8. package/dist/components/HysCard/HysCard.vue.js +2 -2
  9. package/dist/components/HysCard/HysCard2.vue.js +9 -9
  10. package/dist/components/HysCascader/HysCascader.vue.js +88 -76
  11. package/dist/components/HysCheckbox/HysCheckbox.vue.js +5 -39
  12. package/dist/components/HysCheckbox/HysCheckbox2.vue.js +85 -2
  13. package/dist/components/HysCommandPalette/HysCommandPalette.vue.js +52 -51
  14. package/dist/components/HysCommentEditor/HysCommentEditor.vue.js +17 -17
  15. package/dist/components/HysDataGrid/HysDataGrid2.vue.js +22 -22
  16. package/dist/components/HysDrawer/HysDrawer.vue.js +1 -1
  17. package/dist/components/HysDrawer/HysDrawer2.vue.js +55 -54
  18. package/dist/components/HysFileManager/HysFileManager.vue.js +5 -63
  19. package/dist/components/HysFileManager/HysFileManager2.vue.js +85 -2
  20. package/dist/components/HysForm/HysForm.vue.js +2 -2
  21. package/dist/components/HysForm/HysForm2.vue.js +66 -64
  22. package/dist/components/HysFormItem/HysFormItem.vue.js +53 -37
  23. package/dist/components/HysGantt/HysGantt.vue.js +5 -264
  24. package/dist/components/HysGantt/HysGantt2.vue.js +302 -2
  25. package/dist/components/HysInput/HysInput.vue.js +1 -1
  26. package/dist/components/HysInput/HysInput2.vue.js +42 -41
  27. package/dist/components/HysModal/HysModal.vue.js +2 -2
  28. package/dist/components/HysModal/HysModal2.vue.js +35 -35
  29. package/dist/components/HysNotificationCenter/HysNotificationCenter.vue.js +37 -36
  30. package/dist/components/HysNumberInput/HysNumberInput.vue.js +2 -2
  31. package/dist/components/HysNumberInput/HysNumberInput2.vue.js +49 -40
  32. package/dist/components/HysOrgTree/HysOrgTree.vue.js +34 -32
  33. package/dist/components/HysPagination/HysPagination.vue.js +2 -2
  34. package/dist/components/HysPagination/HysPagination2.vue.js +91 -91
  35. package/dist/components/HysPermissionMatrix/HysPermissionMatrix.vue.js +5 -41
  36. package/dist/components/HysPermissionMatrix/HysPermissionMatrix2.vue.js +100 -2
  37. package/dist/components/HysRadioGroup/HysRadioGroup.vue.js +5 -40
  38. package/dist/components/HysRadioGroup/HysRadioGroup2.vue.js +80 -2
  39. package/dist/components/HysResizablePanel/HysResizablePanel.vue.js +46 -28
  40. package/dist/components/HysRichTextEditor/HysRichTextEditor.vue.js +2 -2
  41. package/dist/components/HysRichTextEditor/HysRichTextEditor2.vue.js +86 -67
  42. package/dist/components/HysSearch/HysSearch.vue.js +49 -38
  43. package/dist/components/HysSegmented/HysSegmented.vue.js +39 -34
  44. package/dist/components/HysSelect/HysSelect.vue.js +2 -2
  45. package/dist/components/HysSelect/HysSelect2.vue.js +130 -109
  46. package/dist/components/HysSlider/HysSlider.vue.js +2 -2
  47. package/dist/components/HysSlider/HysSlider2.vue.js +40 -40
  48. package/dist/components/HysSplitPane/HysSplitPane.vue.js +48 -42
  49. package/dist/components/HysSteps/HysSteps.vue.js +2 -2
  50. package/dist/components/HysSteps/HysSteps2.vue.js +15 -14
  51. package/dist/components/HysSwitch/HysSwitch.vue.js +2 -2
  52. package/dist/components/HysSwitch/HysSwitch2.vue.js +38 -27
  53. package/dist/components/HysTable/HysTable.vue.js +2 -2
  54. package/dist/components/HysTable/HysTable2.vue.js +42 -38
  55. package/dist/components/HysTabs/HysTabs.vue.js +1 -1
  56. package/dist/components/HysTabs/HysTabs2.vue.js +8 -6
  57. package/dist/components/HysTextarea/HysTextarea.vue.js +58 -48
  58. package/dist/components/HysToast/HysToast.vue.js +2 -2
  59. package/dist/components/HysToast/HysToast2.vue.js +121 -38
  60. package/dist/components/HysTour/HysTour.vue.js +47 -42
  61. package/dist/components/HysTransfer/HysTransfer.vue.js +159 -143
  62. package/dist/components/HysTree/HysTree.vue.js +2 -2
  63. package/dist/components/HysTree/HysTree2.vue.js +62 -61
  64. package/dist/components/HysTreeSelect/HysTreeSelect.vue.js +64 -57
  65. package/dist/components/HysUpload/HysUpload.vue.js +2 -2
  66. package/dist/components/HysUpload/HysUpload2.vue.js +95 -77
  67. package/dist/composables/formContext.js +9 -3
  68. package/dist/composables/toastEscape.js +16 -0
  69. package/dist/composables/useDialog.js +16 -16
  70. package/dist/composables/useFloating.js +40 -40
  71. package/dist/composables/useHysToast.js +148 -0
  72. package/dist/config.js +18 -15
  73. package/dist/index.js +10 -7
  74. package/dist/style.css +1 -1
  75. package/dist/types/components/HysCalendar/HysCalendar.vue.d.ts +2 -0
  76. package/dist/types/components/HysCard/HysCard.vue.d.ts +5 -1
  77. package/dist/types/components/HysCheckbox/HysCheckbox.vue.d.ts +21 -4
  78. package/dist/types/components/HysDrawer/HysDrawer.vue.d.ts +1 -0
  79. package/dist/types/components/HysFileManager/HysFileManager.vue.d.ts +6 -2
  80. package/dist/types/components/HysGantt/HysGantt.vue.d.ts +6 -0
  81. package/dist/types/components/HysNumberInput/HysNumberInput.vue.d.ts +2 -0
  82. package/dist/types/components/HysOrgTree/HysOrgTree.vue.d.ts +3 -1
  83. package/dist/types/components/HysPermissionMatrix/HysPermissionMatrix.vue.d.ts +8 -1
  84. package/dist/types/components/HysRadioGroup/HysRadioGroup.vue.d.ts +40 -17
  85. package/dist/types/components/HysResizablePanel/HysResizablePanel.vue.d.ts +6 -0
  86. package/dist/types/components/HysSelect/HysSelect.vue.d.ts +7 -1
  87. package/dist/types/components/HysSplitPane/HysSplitPane.vue.d.ts +6 -0
  88. package/dist/types/components/HysSteps/HysSteps.vue.d.ts +1 -0
  89. package/dist/types/components/HysSwitch/HysSwitch.vue.d.ts +1 -1
  90. package/dist/types/components/HysTextarea/HysTextarea.vue.d.ts +1 -1
  91. package/dist/types/components/HysToast/HysToast.vue.d.ts +55 -7
  92. package/dist/types/components/HysTour/HysTour.vue.d.ts +3 -1
  93. package/dist/types/components/HysTransfer/HysTransfer.vue.d.ts +11 -1
  94. package/dist/types/composables/formContext.d.ts +5 -0
  95. package/dist/types/composables/toastEscape.d.ts +1 -0
  96. package/dist/types/composables/useFloating.d.ts +1 -1
  97. package/dist/types/composables/useHysToast.d.ts +50 -0
  98. package/dist/types/index.d.ts +5 -0
  99. package/package.json +46 -11
@@ -1,7 +1,7 @@
1
- import { defineComponent as B, ref as v, openBlock as f, createElementBlock as c, normalizeProps as D, guardReactiveProps as F, unref as p, createElementVNode as u, withModifiers as b, withKeys as h, normalizeClass as L, renderSlot as k, createVNode as y, toDisplayString as z, Fragment as S, renderList as A, createTextVNode as N, createCommentVNode as V } from "vue";
2
- import { CloudUpload as W, FileText as E, X as R } from "lucide-vue-next";
3
- import { useHysRootAttrs as T } from "../../config.js";
4
- const H = ["aria-disabled", "tabindex"], K = ["accept", "multiple", "disabled"], P = { key: 0 }, I = ["aria-label", "disabled", "onClick"], q = /* @__PURE__ */ B({
1
+ import { defineComponent as L, ref as b, watch as S, onActivated as N, onDeactivated as V, onBeforeUnmount as W, openBlock as p, createElementBlock as y, normalizeProps as E, guardReactiveProps as R, unref as g, createElementVNode as m, withModifiers as h, withKeys as x, normalizeClass as T, renderSlot as C, createVNode as k, toDisplayString as U, Fragment as H, renderList as K, createTextVNode as P, createCommentVNode as I } from "vue";
2
+ import { CloudUpload as M, FileText as X, X as j } from "lucide-vue-next";
3
+ import { useHysRootAttrs as q } from "../../config.js";
4
+ const G = ["aria-disabled", "tabindex"], J = ["accept", "multiple", "disabled"], O = { key: 0 }, Q = ["aria-label", "disabled", "onClick"], ee = /* @__PURE__ */ L({
5
5
  __name: "HysUpload",
6
6
  props: {
7
7
  accept: {},
@@ -14,115 +14,133 @@ const H = ["aria-disabled", "tabindex"], K = ["accept", "multiple", "disabled"],
14
14
  beforeUpload: {}
15
15
  },
16
16
  emits: ["change", "remove", "exceed", "error", "select"],
17
- setup(l, { expose: w, emit: x }) {
18
- const i = l, r = x, C = T(), o = v([]), d = v(), m = v(!1), s = v(!1);
19
- function $(a) {
20
- return !i.accept || i.accept.split(",").some((e) => (e = e.trim().toLowerCase(), e.startsWith(".") ? a.name.toLowerCase().endsWith(e) : e.endsWith("/*") ? a.type.startsWith(e.slice(0, -1)) : a.type === e));
17
+ setup(n, { expose: $, emit: B }) {
18
+ const l = n, r = B, D = q(), o = b([]), d = b(), v = b(!1), u = b(!1);
19
+ function A(i) {
20
+ return !l.accept || l.accept.split(",").some((e) => (e = e.trim().toLowerCase(), e.startsWith(".") ? i.name.toLowerCase().endsWith(e) : e.endsWith("/*") ? i.type.startsWith(e.slice(0, -1)) : i.type === e));
21
21
  }
22
- async function g(a) {
23
- if (i.disabled || s.value) return;
24
- if (i.multiple || (a = a.slice(0, 1)), i.limit && o.value.length + a.length > i.limit) {
25
- r("exceed", a);
22
+ let f = 0, s = !0;
23
+ function c() {
24
+ f++, u.value = !1, v.value = !1, d.value && (d.value.value = "");
25
+ }
26
+ S(() => l.disabled, c), N(() => {
27
+ s = !0;
28
+ }), V(() => {
29
+ s = !1, c();
30
+ }), W(() => {
31
+ s = !1, c();
32
+ });
33
+ async function z(i) {
34
+ if (!s || l.disabled || u.value) return;
35
+ if (l.multiple || (i = i.slice(0, 1)), l.limit && (l.multiple ? o.value.length : 0) + i.length > l.limit) {
36
+ r("exceed", i);
26
37
  return;
27
38
  }
28
- s.value = !0;
29
- const e = [];
39
+ const e = ++f;
40
+ u.value = !0;
41
+ const a = [];
30
42
  try {
31
- for (const t of a) {
32
- if (!$(t)) {
33
- r("error", "文件类型不符合要求:" + t.name);
34
- continue;
35
- }
36
- if (i.maxSize && t.size > i.maxSize) {
37
- r("error", "文件超过大小限制:" + t.name);
38
- continue;
43
+ for (const t of i) {
44
+ if (!s || e !== f || l.disabled) return;
45
+ try {
46
+ if (!A(t)) {
47
+ r("error", "文件类型不符合要求:" + t.name);
48
+ continue;
49
+ }
50
+ if (l.maxSize && t.size > l.maxSize) {
51
+ r("error", "文件超过大小限制:" + t.name);
52
+ continue;
53
+ }
54
+ if (l.beforeUpload && await l.beforeUpload(t) === !1) continue;
55
+ if (!s || e !== f || l.disabled) return;
56
+ a.push({ uid: crypto.randomUUID(), name: t.name, size: t.size, raw: t });
57
+ } catch (w) {
58
+ s && e === f && r("error", w instanceof Error ? w.message : "文件检查失败");
39
59
  }
40
- i.beforeUpload && await i.beforeUpload(t) === !1 || e.push({ uid: crypto.randomUUID(), name: t.name, size: t.size, raw: t });
41
60
  }
42
- o.value = i.multiple ? [...o.value, ...e] : e, e.length && (r("select", e.map((t) => t.raw)), r("change", [...o.value]));
43
- } catch (t) {
44
- r("error", t instanceof Error ? t.message : "文件检查失败");
61
+ if (!s || e !== f || l.disabled || !a.length) return;
62
+ o.value = l.multiple ? [...o.value, ...a] : a, a.length && (r("select", a.map((t) => t.raw)), r("change", [...o.value]));
45
63
  } finally {
46
- s.value = !1, d.value && (d.value.value = "");
64
+ e === f && (u.value = !1, d.value && (d.value.value = ""));
47
65
  }
48
66
  }
49
- function U(a) {
50
- i.disabled || (o.value = o.value.filter((e) => e.uid !== a.uid), r("remove", a), r("change", [...o.value]));
67
+ function F(i) {
68
+ l.disabled || (o.value = o.value.filter((e) => e.uid !== i.uid), r("remove", i), r("change", [...o.value]));
51
69
  }
52
- return w({ clearFiles: () => {
53
- o.value = [], r("change", []);
70
+ return $({ clearFiles: () => {
71
+ c(), o.value = [], r("change", []);
54
72
  }, open: () => {
55
- var a;
56
- i.disabled || (a = d.value) == null || a.click();
57
- } }), (a, e) => (f(), c("div", D(F(p(C))), [
58
- u("div", {
59
- class: L(["hys-ui-upload-zone", { "hys-ui-upload-dragging": m.value }]),
73
+ var i;
74
+ s && !l.disabled && !u.value && ((i = d.value) == null || i.click());
75
+ } }), (i, e) => (p(), y("div", E(R(g(D))), [
76
+ m("div", {
77
+ class: T(["hys-ui-upload-zone", { "hys-ui-upload-dragging": v.value }]),
60
78
  role: "button",
61
- "aria-disabled": l.disabled || s.value,
62
- tabindex: l.disabled ? -1 : 0,
79
+ "aria-disabled": n.disabled || u.value,
80
+ tabindex: n.disabled ? -1 : 0,
63
81
  "aria-label": "选择上传文件",
64
- onClick: e[0] || (e[0] = (t) => {
65
- var n;
66
- return !l.disabled && ((n = d.value) == null ? void 0 : n.click());
82
+ onClick: e[0] || (e[0] = (a) => {
83
+ var t;
84
+ return !n.disabled && ((t = d.value) == null ? void 0 : t.click());
67
85
  }),
68
86
  onKeydown: [
69
- e[1] || (e[1] = h(b((t) => {
70
- var n;
71
- return !l.disabled && ((n = d.value) == null ? void 0 : n.click());
87
+ e[1] || (e[1] = x(h((a) => {
88
+ var t;
89
+ return !n.disabled && ((t = d.value) == null ? void 0 : t.click());
72
90
  }, ["prevent"]), ["enter"])),
73
- e[2] || (e[2] = h(b((t) => {
74
- var n;
75
- return !l.disabled && ((n = d.value) == null ? void 0 : n.click());
91
+ e[2] || (e[2] = x(h((a) => {
92
+ var t;
93
+ return !n.disabled && ((t = d.value) == null ? void 0 : t.click());
76
94
  }, ["prevent"]), ["space"]))
77
95
  ],
78
- onDragover: e[3] || (e[3] = b((t) => l.drag && !l.disabled && (m.value = !0), ["prevent"])),
79
- onDragleave: e[4] || (e[4] = (t) => m.value = !1),
80
- onDrop: e[5] || (e[5] = b((t) => {
81
- var n;
82
- m.value = !1, l.drag && g(Array.from(((n = t.dataTransfer) == null ? void 0 : n.files) || []));
96
+ onDragover: e[3] || (e[3] = h((a) => n.drag && !n.disabled && (v.value = !0), ["prevent"])),
97
+ onDragleave: e[4] || (e[4] = (a) => v.value = !1),
98
+ onDrop: e[5] || (e[5] = h((a) => {
99
+ var t;
100
+ v.value = !1, n.drag && z(Array.from(((t = a.dataTransfer) == null ? void 0 : t.files) || []));
83
101
  }, ["prevent"]))
84
102
  }, [
85
- k(a.$slots, "default", {}, () => [
86
- y(p(W), {
103
+ C(i.$slots, "default", {}, () => [
104
+ k(g(M), {
87
105
  size: 28,
88
106
  "aria-hidden": "true"
89
107
  }),
90
- u("strong", null, z(s.value ? "正在检查文件…" : "点击选择或拖入文件"), 1),
91
- e[7] || (e[7] = u("span", null, "文件通过事件交给业务层上传", -1))
108
+ m("strong", null, U(u.value ? "正在检查文件…" : "点击选择或拖入文件"), 1),
109
+ e[7] || (e[7] = m("span", null, "文件通过事件交给业务层上传", -1))
92
110
  ], !0)
93
- ], 42, H),
94
- u("input", {
111
+ ], 42, G),
112
+ m("input", {
95
113
  ref_key: "input",
96
114
  ref: d,
97
115
  hidden: "",
98
116
  type: "file",
99
- accept: l.accept,
100
- multiple: l.multiple,
101
- disabled: l.disabled || s.value,
102
- onChange: e[6] || (e[6] = (t) => g(Array.from(t.target.files || [])))
103
- }, null, 40, K),
104
- l.showFileList ? (f(), c("div", P, [
105
- (f(!0), c(S, null, A(o.value, (t) => (f(), c("div", {
106
- key: t.uid,
117
+ accept: n.accept,
118
+ multiple: n.multiple,
119
+ disabled: n.disabled || u.value,
120
+ onChange: e[6] || (e[6] = (a) => z(Array.from(a.target.files || [])))
121
+ }, null, 40, J),
122
+ n.showFileList ? (p(), y("div", O, [
123
+ (p(!0), y(H, null, K(o.value, (a) => (p(), y("div", {
124
+ key: a.uid,
107
125
  class: "hys-ui-upload-file"
108
126
  }, [
109
- y(p(E), { size: 16 }),
110
- k(a.$slots, "file", { file: t }, () => [
111
- N(z(t.name), 1)
127
+ k(g(X), { size: 16 }),
128
+ C(i.$slots, "file", { file: a }, () => [
129
+ P(U(a.name), 1)
112
130
  ], !0),
113
- u("button", {
131
+ m("button", {
114
132
  type: "button",
115
- "aria-label": "移除" + t.name,
116
- disabled: l.disabled,
117
- onClick: (n) => U(t)
133
+ "aria-label": "移除" + a.name,
134
+ disabled: n.disabled,
135
+ onClick: (t) => F(a)
118
136
  }, [
119
- y(p(R), { size: 14 })
120
- ], 8, I)
137
+ k(g(j), { size: 14 })
138
+ ], 8, Q)
121
139
  ]))), 128))
122
- ])) : V("", !0)
140
+ ])) : I("", !0)
123
141
  ], 16));
124
142
  }
125
143
  });
126
144
  export {
127
- q as default
145
+ ee as default
128
146
  };
@@ -1,5 +1,11 @@
1
- const o = Symbol("hys-ui-form"), y = Symbol("hys-ui-field");
1
+ const i = Symbol("hys-ui-form"), d = Symbol("hys-ui-field");
2
+ function n(e) {
3
+ if (!e || e.closest("[inert],fieldset[disabled]") || e.getAttribute("aria-disabled") === "true") return;
4
+ const t = e.matches('input,button,textarea,select,a[href],[tabindex],[contenteditable="true"]') ? e : e.querySelector('input:checked:not(:disabled),input:not(:disabled):not([hidden]),button:not(:disabled),[tabindex]:not([tabindex="-1"])');
5
+ t == null || t.focus();
6
+ }
2
7
  export {
3
- y as fieldKey,
4
- o as formKey
8
+ d as fieldKey,
9
+ n as focusHysField,
10
+ i as formKey
5
11
  };
@@ -0,0 +1,16 @@
1
+ const e = [];
2
+ function i(t) {
3
+ if (t.key !== "Escape" || t.defaultPrevented) return;
4
+ const n = e.at(-1);
5
+ n && (t.preventDefault(), n.close());
6
+ }
7
+ function o(t) {
8
+ const n = { close: t };
9
+ return e.length || document.addEventListener("keydown", i), e.push(n), () => {
10
+ const s = e.indexOf(n);
11
+ s >= 0 && e.splice(s, 1), e.length || document.removeEventListener("keydown", i);
12
+ };
13
+ }
14
+ export {
15
+ o as registerToastEscape
16
+ };
@@ -2,13 +2,13 @@ import { ref as k, computed as D, onActivated as w, onDeactivated as x, watch as
2
2
  import { lockBodyScroll as T, registerOverlay as A } from "./overlayManager.js";
3
3
  const C = 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])';
4
4
  function B(h, t, m) {
5
- const i = k(!0), s = D(() => h.value && i.value);
5
+ const o = k(!0), s = D(() => h.value && o.value);
6
6
  w(() => {
7
- i.value = !0;
7
+ o.value = !0;
8
8
  }), x(() => {
9
- i.value = !1, c++, f();
9
+ o.value = !1, c++, f();
10
10
  });
11
- let d = null, a, u, c = 0;
11
+ let d = null, i, u, c = 0;
12
12
  function v() {
13
13
  var e;
14
14
  return Array.from(((e = t.value) == null ? void 0 : e.querySelectorAll(C)) ?? []).filter((n) => n.getClientRects().length > 0 && getComputedStyle(n).visibility !== "hidden");
@@ -25,31 +25,31 @@ function B(h, t, m) {
25
25
  e.preventDefault(), t.value.focus();
26
26
  return;
27
27
  }
28
- const r = n[0], l = n[n.length - 1];
29
- e.shiftKey && (document.activeElement === r || document.activeElement === t.value || !t.value.contains(document.activeElement)) ? (e.preventDefault(), l.focus()) : !e.shiftKey && (document.activeElement === l || !t.value.contains(document.activeElement)) && (e.preventDefault(), r.focus());
28
+ const l = n[0], r = n[n.length - 1];
29
+ e.shiftKey && (document.activeElement === l || document.activeElement === t.value || !t.value.contains(document.activeElement)) ? (e.preventDefault(), r.focus()) : !e.shiftKey && (document.activeElement === r || !t.value.contains(document.activeElement)) && (e.preventDefault(), l.focus());
30
30
  }
31
31
  function p(e) {
32
32
  !s.value || !(u != null && u()) || !t.value || e.target instanceof Node && !t.value.contains(e.target) && (v()[0] ?? t.value).focus();
33
33
  }
34
34
  function f() {
35
- a == null || a(), a = void 0, u = void 0, document.removeEventListener("keydown", y, !0), document.removeEventListener("focusin", p, !0);
35
+ i == null || i(), i = void 0, u = void 0, document.removeEventListener("keydown", y, !0), document.removeEventListener("focusin", p, !0);
36
36
  }
37
37
  return L(s, async (e) => {
38
- var r, l;
38
+ var l, r;
39
39
  const n = ++c;
40
40
  if (e) {
41
41
  f(), d = document.activeElement instanceof HTMLElement ? document.activeElement : null;
42
- const o = T(), E = A("dialog", m);
43
- u = E.isTop, a = () => {
44
- E.unregister(), o();
45
- }, document.addEventListener("keydown", y, !0), document.addEventListener("focusin", p, !0), await b(), n === c && s.value && ((l = ((r = t.value) == null ? void 0 : r.querySelector("[autofocus]")) ?? v()[0] ?? t.value) == null || l.focus());
42
+ const a = T(), E = A("dialog", m);
43
+ u = E.isTop, i = () => {
44
+ E.unregister(), a();
45
+ }, document.addEventListener("keydown", y, !0), document.addEventListener("focusin", p, !0), await b(), n === c && s.value && ((r = ((l = t.value) == null ? void 0 : l.querySelector("[autofocus]")) ?? v()[0] ?? t.value) == null || r.focus());
46
46
  } else {
47
- const o = d;
48
- f(), await b(), n === c && i.value && (o != null && o.isConnected) && o.focus();
47
+ const a = d;
48
+ f(), await b(), n === c && o.value && (a != null && a.isConnected) && a.focus();
49
49
  }
50
50
  }, { immediate: !0, flush: "post" }), S(() => {
51
- c++, f();
52
- }), { active: i };
51
+ o.value = !1, c++, f();
52
+ }), { active: o };
53
53
  }
54
54
  export {
55
55
  B as useDialog
@@ -1,34 +1,34 @@
1
- import { ref as y, onDeactivated as R, onBeforeUnmount as q, nextTick as D } from "vue";
2
- import { registerOverlay as H } from "./overlayManager.js";
3
- function O(f, u, m = {}) {
4
- const a = y(!1), E = y(!1), L = y({ position: "fixed", top: "0px", left: "0px", visibility: "hidden" }), z = y(m.placement ?? "bottom-start"), d = m.gap ?? 8, r = m.padding ?? 10;
5
- let M = 0, p, c, g = 0;
6
- function W() {
7
- if (!a.value || !f.value || !u.value) return;
1
+ import { ref as E, onDeactivated as q, onBeforeUnmount as D, nextTick as H } from "vue";
2
+ import { registerOverlay as I } from "./overlayManager.js";
3
+ function P(f, a, m = {}) {
4
+ const l = E(!1), W = E(!1), M = E({ position: "fixed", top: "0px", left: "0px", visibility: "hidden" }), A = E(m.placement ?? "bottom-start"), d = m.gap ?? 8, r = m.padding ?? 10;
5
+ let L = 0, h, c, g = 0;
6
+ function $() {
7
+ if (!l.value || !f.value || !a.value) return;
8
8
  const t = f.value.getBoundingClientRect();
9
9
  if (!t.width && !t.height) {
10
10
  s();
11
11
  return;
12
12
  }
13
- const e = document.documentElement.clientWidth, n = document.documentElement.clientHeight, o = Math.min(t.width, Math.max(0, e - 2 * r));
14
- m.matchWidth && (u.value.style.width = `${o}px`, u.value.style.minWidth = "0", u.value.style.maxWidth = `${o}px`);
15
- const h = u.value.getBoundingClientRect(), v = Math.min(h.width, Math.max(0, e - 2 * r)), w = Math.min(h.height, Math.max(0, n - 2 * r));
13
+ const e = document.documentElement.clientWidth, n = document.documentElement.clientHeight, o = Math.min(t.width, Math.max(0, e - 2 * r)), v = typeof m.matchWidth == "function" ? m.matchWidth() : m.matchWidth;
14
+ v === !0 && (a.value.style.width = `${o}px`, a.value.style.minWidth = "0", a.value.style.maxWidth = `${o}px`), v === "min" && (a.value.style.width = "max-content", a.value.style.minWidth = `${o}px`, a.value.style.maxWidth = `calc(100vw - ${r * 2}px)`);
15
+ const w = a.value.getBoundingClientRect(), p = Math.min(w.width, Math.max(0, e - 2 * r)), x = Math.min(w.height, Math.max(0, n - 2 * r));
16
16
  let i = m.placement ?? "bottom-start";
17
- const k = n - t.bottom - d, $ = t.top - d;
18
- i.startsWith("bottom") && k < w && $ > k ? i = i.replace("bottom", "top") : i.startsWith("top") && $ < w && k > $ ? i = i.replace("top", "bottom") : i === "right" && e - t.right - d < v && t.left > e - t.right ? i = "left" : i === "left" && t.left - d < v && e - t.right > t.left && (i = "right");
19
- let x = i.endsWith("end") ? t.right - v : t.left, b = i.startsWith("top") ? t.top - w - d : t.bottom + d;
20
- (i === "right" || i === "left") && (x = i === "right" ? t.right + d : t.left - v - d, b = t.top + (t.height - w) / 2), x = Math.max(r, Math.min(x, e - v - r)), b = Math.max(r, Math.min(b, n - w - r)), z.value = i, L.value = { ...m.matchWidth ? { width: `${o}px`, minWidth: "0" } : {}, position: "fixed", left: `${Math.round(x)}px`, top: `${Math.round(b)}px`, visibility: "visible", zIndex: "1200", maxWidth: `calc(100vw - ${r * 2}px)`, maxHeight: `calc(100vh - ${r * 2}px)`, overflowY: "auto", overscrollBehavior: "contain" };
17
+ const k = n - t.bottom - d, z = t.top - d;
18
+ i.startsWith("bottom") && k < x && z > k ? i = i.replace("bottom", "top") : i.startsWith("top") && z < x && k > z ? i = i.replace("top", "bottom") : i === "right" && e - t.right - d < p && t.left > e - t.right ? i = "left" : i === "left" && t.left - d < p && e - t.right > t.left && (i = "right");
19
+ let y = i.endsWith("end") ? t.right - p : t.left, b = i.startsWith("top") ? t.top - x - d : t.bottom + d;
20
+ (i === "right" || i === "left") && (y = i === "right" ? t.right + d : t.left - p - d, b = t.top + (t.height - x) / 2), y = Math.max(r, Math.min(y, e - p - r)), b = Math.max(r, Math.min(b, n - x - r)), A.value = i, M.value = { ...v === !0 ? { width: `${o}px`, minWidth: "0" } : v === "min" ? { width: "max-content", minWidth: `${o}px` } : {}, position: "fixed", left: `${Math.round(y)}px`, top: `${Math.round(b)}px`, visibility: "visible", zIndex: "1200", maxWidth: `calc(100vw - ${r * 2}px)`, maxHeight: `calc(100vh - ${r * 2}px)`, overflowY: "auto", overscrollBehavior: "contain" };
21
21
  }
22
- function l() {
23
- cancelAnimationFrame(M), M = requestAnimationFrame(W);
22
+ function u() {
23
+ cancelAnimationFrame(L), L = requestAnimationFrame($);
24
24
  }
25
- function A(t) {
25
+ function F(t) {
26
26
  var e, n;
27
- c != null && c() && !((e = f.value) != null && e.contains(t.target)) && !((n = u.value) != null && n.contains(t.target)) && s();
27
+ c != null && c() && !((e = f.value) != null && e.contains(t.target)) && !((n = a.value) != null && n.contains(t.target)) && s();
28
28
  }
29
- function F(t) {
29
+ function B(t) {
30
30
  var e, n;
31
- if (!(!a.value || !(c != null && c()))) {
31
+ if (!(!l.value || !(c != null && c()))) {
32
32
  if (t.key === "Escape")
33
33
  t.preventDefault(), t.stopImmediatePropagation(), s(!0);
34
34
  else if (t.key === "Tab") {
@@ -37,46 +37,46 @@ function O(f, u, m = {}) {
37
37
  s();
38
38
  return;
39
39
  }
40
- if ((n = u.value) != null && n.contains(o)) {
41
- const h = Array.from(u.value.querySelectorAll('a[href],button:not(:disabled),input:not(:disabled),textarea:not(:disabled),select:not(:disabled),[tabindex]:not([tabindex="-1"])')).filter((v) => v.getClientRects().length && !v.closest("[inert]"));
42
- (!h.length || o === (t.shiftKey ? h[0] : h.at(-1))) && s(!0);
40
+ if ((n = a.value) != null && n.contains(o)) {
41
+ const v = Array.from(a.value.querySelectorAll('a[href],button:not(:disabled),input:not(:disabled),textarea:not(:disabled),select:not(:disabled),[tabindex]:not([tabindex="-1"])')).filter((w) => w.getClientRects().length && !w.closest("[inert]"));
42
+ (!v.length || o === (t.shiftKey ? v[0] : v.at(-1))) && s(!0);
43
43
  }
44
44
  }
45
45
  }
46
46
  }
47
- function B() {
47
+ function C() {
48
48
  var t, e;
49
- document.removeEventListener("pointerdown", A, !0), document.removeEventListener("keydown", F, !0), window.removeEventListener("resize", l), window.removeEventListener("scroll", l, !0), (t = window.visualViewport) == null || t.removeEventListener("resize", l), (e = window.visualViewport) == null || e.removeEventListener("scroll", l), cancelAnimationFrame(M), p == null || p(), p = void 0, c = void 0;
49
+ document.removeEventListener("pointerdown", F, !0), document.removeEventListener("keydown", B, !0), window.removeEventListener("resize", u), window.removeEventListener("scroll", u, !0), (t = window.visualViewport) == null || t.removeEventListener("resize", u), (e = window.visualViewport) == null || e.removeEventListener("scroll", u), cancelAnimationFrame(L), h == null || h(), h = void 0, c = void 0;
50
50
  }
51
51
  function s(t = !1) {
52
52
  var e;
53
- if (g++, !!a.value && (a.value = !1, B(), t && ((e = f.value) != null && e.isConnected))) {
54
- E.value = !0;
53
+ if (g++, !!l.value && (l.value = !1, C(), t && ((e = f.value) != null && e.isConnected))) {
54
+ W.value = !0;
55
55
  try {
56
56
  f.value.focus();
57
57
  } finally {
58
- E.value = !1;
58
+ W.value = !1;
59
59
  }
60
60
  }
61
61
  }
62
- async function C() {
62
+ async function V() {
63
63
  var n, o;
64
- if (a.value) {
65
- l();
64
+ if (l.value) {
65
+ u();
66
66
  return;
67
67
  }
68
68
  const t = ++g;
69
- if (a.value = !0, L.value = { position: "fixed", top: "0px", left: "0px", visibility: "hidden" }, await D(), t !== g || !a.value) return;
70
- const e = H("floating", () => s(!0));
71
- p = e.unregister, c = e.isTop, W(), document.addEventListener("pointerdown", A, !0), document.addEventListener("keydown", F, !0), window.addEventListener("resize", l), window.addEventListener("scroll", l, !0), (n = window.visualViewport) == null || n.addEventListener("resize", l), (o = window.visualViewport) == null || o.addEventListener("scroll", l);
69
+ if (l.value = !0, M.value = { position: "fixed", top: "0px", left: "0px", visibility: "hidden" }, await H(), t !== g || !l.value) return;
70
+ const e = I("floating", () => s(!0));
71
+ h = e.unregister, c = e.isTop, $(), document.addEventListener("pointerdown", F, !0), document.addEventListener("keydown", B, !0), window.addEventListener("resize", u), window.addEventListener("scroll", u, !0), (n = window.visualViewport) == null || n.addEventListener("resize", u), (o = window.visualViewport) == null || o.addEventListener("scroll", u);
72
72
  }
73
- function V() {
74
- return a.value ? s() : C();
73
+ function R() {
74
+ return l.value ? s() : V();
75
75
  }
76
- return R(() => s()), q(() => {
77
- g++, B();
78
- }), { open: a, style: L, placement: z, update: W, show: C, close: s, toggle: V, restoringFocus: E };
76
+ return q(() => s()), D(() => {
77
+ g++, C();
78
+ }), { open: l, style: M, placement: A, update: $, show: V, close: s, toggle: R, restoringFocus: W };
79
79
  }
80
80
  export {
81
- O as useFloating
81
+ P as useFloating
82
82
  };
@@ -0,0 +1,148 @@
1
+ import { defineComponent as k, createApp as F, h as m, getCurrentInstance as Q, shallowReactive as A, Fragment as R, onDeactivated as B, onActivated as N, onScopeDispose as P, nextTick as W, render as b } from "vue";
2
+ import X from "../components/HysToast/HysToast.vue.js";
3
+ import { provideHysConfig as z, useHysRootAttrs as G } from "../config.js";
4
+ let J = 0;
5
+ const g = (n = "top-center") => n === "top" ? "top-center" : n === "bottom" ? "bottom-center" : n;
6
+ function K(n = {}) {
7
+ const l = Q();
8
+ if (!l) throw new Error("useHysToast must be called during component setup");
9
+ const p = G(), a = A([]), d = /* @__PURE__ */ new Map();
10
+ let r, x = !0, v = !1;
11
+ const M = Number.isFinite(n.maxCount) ? Math.max(1, Math.floor(n.maxCount)) : 5, w = (e) => typeof e == "string" ? { message: e } : e;
12
+ function C(e) {
13
+ try {
14
+ e == null || e();
15
+ } catch (o) {
16
+ try {
17
+ l.appContext.config.errorHandler ? l.appContext.config.errorHandler(o, l.proxy, "HysToast callback") : console.error(o);
18
+ } catch (s) {
19
+ console.error(s);
20
+ }
21
+ }
22
+ }
23
+ function H(e) {
24
+ if (e.finished) return;
25
+ e.finished = !0;
26
+ const o = a.indexOf(e);
27
+ o >= 0 && a.splice(o, 1), d.delete(e.token), e.resolve(), C(e.onAfterClose);
28
+ const s = r;
29
+ W(() => {
30
+ s && s === r && !a.length && (b(null, s), s.remove(), r = void 0);
31
+ });
32
+ }
33
+ function h(e) {
34
+ if (!(e.closing || e.finished)) {
35
+ e.closing = !0;
36
+ try {
37
+ C(e.onClose);
38
+ } finally {
39
+ const o = d.get(e.token);
40
+ o ? o.close() : H(e);
41
+ }
42
+ }
43
+ }
44
+ function I(e, o) {
45
+ if (e.closing || e.finished || v) return;
46
+ const s = w(o), t = e.type;
47
+ Object.assign(e, s, { id: e.id }), s.type && s.type !== t && s.duration === void 0 && (e.duration = s.type === "loading" ? 0 : n.duration), W(() => {
48
+ var f;
49
+ e.closing || (f = d.get(e.token)) == null || f.restart();
50
+ });
51
+ }
52
+ function j(e) {
53
+ const o = g(e.position), s = Math.max(0, e.offset ?? 24) + "px", t = { position: "fixed", width: "max-content", display: "flex", flexDirection: o.startsWith("bottom") ? "column-reverse" : "column", gap: "10px", alignItems: o.endsWith("left") ? "flex-start" : o.endsWith("right") ? "flex-end" : "center", maxWidth: `calc(100vw - ${Math.max(16, e.offset ?? 24) * 2}px)`, pointerEvents: "none", zIndex: e.zIndex ?? 2e3 };
54
+ return o === "center" ? Object.assign(t, { left: "50%", top: "50%", transform: "translate(-50%,-50%)" }) : (o.startsWith("bottom") ? t.bottom = `max(${s},env(safe-area-inset-bottom))` : t.top = `max(${s},env(safe-area-inset-top))`, o.endsWith("left") ? t.left = `max(${s},env(safe-area-inset-left))` : o.endsWith("right") ? t.right = `max(${s},env(safe-area-inset-right))` : Object.assign(t, { left: "50%", transform: "translateX(-50%)" })), t;
55
+ }
56
+ const q = k({
57
+ name: "HysToastQueue",
58
+ setup() {
59
+ return z({ theme: () => p.value["data-hys-theme"], motion: () => p.value["data-hys-motion"] }), () => {
60
+ const e = /* @__PURE__ */ new Map();
61
+ for (const o of a) {
62
+ const s = `${g(o.position)}:${o.offset ?? 24}:${o.zIndex ?? 2e3}`, t = e.get(s) || [];
63
+ t.push(o), e.set(s, t);
64
+ }
65
+ return m(R, [...e].map(([o, s]) => m("div", { key: o, ...p.value, class: "hys-ui-toast-stack", style: j(s[0]) }, s.map((t) => m(X, {
66
+ key: t.token,
67
+ ref: (f) => {
68
+ f ? d.set(t.token, f) : d.delete(t.token);
69
+ },
70
+ "data-toast-id": t.id,
71
+ message: t.message,
72
+ type: t.type,
73
+ duration: t.duration,
74
+ closable: t.closable ?? !0,
75
+ showIcon: t.showIcon ?? !0,
76
+ pauseOnHover: t.pauseOnHover ?? !0,
77
+ closeOnEscape: t.closeOnEscape,
78
+ position: t.position,
79
+ offset: t.offset,
80
+ zIndex: t.zIndex,
81
+ plain: t.plain,
82
+ repeat: t.repeat,
83
+ teleport: !1,
84
+ onClose: () => h(t),
85
+ onAfterClose: () => H(t)
86
+ }, {
87
+ ...t.content !== void 0 ? { default: () => typeof t.content == "function" ? t.content() : t.content } : {},
88
+ ...t.icon !== void 0 ? { icon: () => typeof t.icon == "function" ? t.icon() : t.icon } : {}
89
+ })))));
90
+ };
91
+ }
92
+ });
93
+ function D() {
94
+ if (r) return;
95
+ const e = typeof n.appendTo == "string" ? document.querySelector(n.appendTo) : n.appendTo ?? document.body;
96
+ if (!e) throw new Error("Toast appendTo target was not found");
97
+ r = document.createElement("div"), r.dataset.hysToastHost = "", e.appendChild(r);
98
+ const o = m(q);
99
+ o.appContext = l.appContext, b(o, r);
100
+ }
101
+ function O(e) {
102
+ const o = w(e), s = { type: "info", ...n, ...o };
103
+ s.type === "loading" && o.duration === void 0 && (s.duration = 0);
104
+ const t = a.find((i) => !i.closing && (o.id && i.id === o.id || s.grouping && o.message && o.content === void 0 && i.message === o.message && i.type === s.type && g(i.position) === g(s.position)));
105
+ if (t)
106
+ return o.id || t.repeat++, I(t, o), t.handle;
107
+ const f = "hys-toast-" + ++J, $ = o.id ?? f;
108
+ let T;
109
+ const S = new Promise((i) => {
110
+ T = i;
111
+ }), c = A({ ...s, token: f, id: $, repeat: 1, closing: !1, finished: !1, resolve: T });
112
+ if (c.handle = { id: $, closed: S, close: () => h(c), update: (i) => I(c, i) }, v || !x || !c.message && (c.content == null || c.content === !1 || c.content === ""))
113
+ return c.finished = !0, T(), c.handle;
114
+ for (; a.filter((i) => !i.closing).length >= M; ) h(a.find((i) => !i.closing));
115
+ return D(), a.push(c), c.handle;
116
+ }
117
+ function E() {
118
+ for (const e of [...a])
119
+ e.closing || (e.closing = !0, C(e.onClose)), H(e);
120
+ r && (b(null, r), r.remove(), r = void 0);
121
+ }
122
+ B(() => {
123
+ x = !1, E();
124
+ }), N(() => {
125
+ x = !0;
126
+ }), P(() => {
127
+ v = !0, E();
128
+ });
129
+ const u = (e) => (o) => O({ ...w(o), type: e });
130
+ return { show: O, success: u("success"), info: u("info"), warning: u("warning"), error: u("error"), loading: u("loading"), closeAll: () => {
131
+ for (const e of [...a]) h(e);
132
+ } };
133
+ }
134
+ function Y(n = {}) {
135
+ let l, p = !1;
136
+ const a = k({ setup() {
137
+ return l = K(n), () => null;
138
+ } }), d = F(k({ setup() {
139
+ return z(n), () => m(a);
140
+ } }));
141
+ return d.mount(document.createElement("div")), { ...l, dispose() {
142
+ p || (p = !0, d.unmount());
143
+ } };
144
+ }
145
+ export {
146
+ Y as createHysToast,
147
+ K as useHysToast
148
+ };
package/dist/config.js CHANGED
@@ -1,21 +1,24 @@
1
- import { computed as s, toValue as i, inject as u, provide as r } from "vue";
2
- const n = Symbol("hys-ui-config");
3
- function f(e) {
4
- const t = u(n, {});
5
- r(n, { theme: e.theme ?? t.theme, motion: e.motion ?? t.motion });
1
+ import { computed as a, toValue as s, provide as m, getCurrentInstance as i, inject as f } from "vue";
2
+ const u = Symbol("hys-ui-config"), r = /* @__PURE__ */ new WeakMap();
3
+ function h(t) {
4
+ const e = c(), n = { theme: t.theme ?? e.theme, motion: t.motion ?? e.motion };
5
+ m(u, n);
6
+ const o = i();
7
+ o && r.set(o, n);
6
8
  }
7
- function m() {
8
- return u(n, {});
9
+ function c() {
10
+ const t = i();
11
+ return t && r.get(t) || f(u, {});
9
12
  }
10
- function l() {
11
- const e = m();
12
- return s(() => {
13
- const t = i(e.theme), o = i(e.motion);
14
- return { "data-hys-ui": "", "data-hys-theme": t && ["blue", "dark", "green", "purple", "orange", "forest"].includes(t) ? t : "blue", "data-hys-motion": o && ["full", "subtle", "off"].includes(o) ? o : "subtle" };
13
+ function d() {
14
+ const t = c();
15
+ return a(() => {
16
+ const e = s(t.theme), n = s(t.motion);
17
+ return { "data-hys-ui": "", "data-hys-theme": e && ["blue", "dark", "green", "purple", "orange", "forest"].includes(e) ? e : "blue", "data-hys-motion": n && ["full", "subtle", "off"].includes(n) ? n : "subtle" };
15
18
  });
16
19
  }
17
20
  export {
18
- f as provideHysConfig,
19
- m as useHysConfig,
20
- l as useHysRootAttrs
21
+ h as provideHysConfig,
22
+ c as useHysConfig,
23
+ d as useHysRootAttrs
21
24
  };