@weni/unnnic-system 3.36.0 → 3.36.1-alpha.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 (42) hide show
  1. package/dist/assets/scss/tailwind.css +1 -1
  2. package/dist/components/MultiSelect/MultiSelectOption.css +1 -1
  3. package/dist/components/MultiSelect/MultiSelectOption.vue.mjs +2 -2
  4. package/dist/components/MultiSelect/MultiSelectOption.vue2.mjs +41 -15
  5. package/dist/components/MultiSelect/MultiSelectTreeOptions.css +1 -0
  6. package/dist/components/MultiSelect/MultiSelectTreeOptions.vue.mjs +7 -0
  7. package/dist/components/MultiSelect/MultiSelectTreeOptions.vue2.mjs +50 -0
  8. package/dist/components/MultiSelect/index.css +1 -1
  9. package/dist/components/MultiSelect/index.vue.mjs +2 -2
  10. package/dist/components/MultiSelect/index.vue2.mjs +126 -114
  11. package/dist/components/SelectTime/index.css +1 -1
  12. package/dist/components/SelectTime/index.vue.mjs +55 -42
  13. package/dist/composables/useMultiSelectRows.mjs +74 -0
  14. package/dist/composables/useMultiSelectSelection.mjs +44 -0
  15. package/dist/composables/useSelectBase.mjs +44 -39
  16. package/dist/composables/useSelectKeyboard.mjs +70 -35
  17. package/dist/composables/useTreeExpansion.mjs +24 -0
  18. package/dist/lib/tree-selection.mjs +66 -0
  19. package/dist/locales/en.json.mjs +9 -5
  20. package/dist/style.css +6 -4
  21. package/dist/unnnic.umd.js +19 -19
  22. package/package.json +2 -2
  23. package/src/components/MultiSelect/MultiSelectOption.vue +66 -3
  24. package/src/components/MultiSelect/MultiSelectTreeOptions.vue +73 -0
  25. package/src/components/MultiSelect/__tests__/MultiSelect.spec.js +556 -0
  26. package/src/components/MultiSelect/__tests__/MultiSelectOption.spec.js +55 -1
  27. package/src/components/MultiSelect/__tests__/__snapshots__/MultiSelectOption.spec.js.snap +5 -0
  28. package/src/components/MultiSelect/index.vue +57 -50
  29. package/src/components/Select/_select-shared.scss +8 -0
  30. package/src/components/Select/types.ts +1 -0
  31. package/src/components/SelectTime/__tests__/SelectTime.spec.js +88 -0
  32. package/src/components/SelectTime/index.vue +31 -7
  33. package/src/composables/useMultiSelectRows.ts +121 -0
  34. package/src/composables/useMultiSelectSelection.ts +97 -0
  35. package/src/composables/useSelectBase.ts +40 -16
  36. package/src/composables/useSelectKeyboard.ts +92 -18
  37. package/src/composables/useTreeExpansion.ts +44 -0
  38. package/src/lib/__tests__/tree-selection.spec.ts +141 -0
  39. package/src/lib/tree-selection.ts +156 -0
  40. package/src/locales/en.json +3 -1
  41. package/src/stories/MultiSelect.stories.js +62 -1
  42. package/src/stories/SelectTime.stories.js +5 -1
@@ -0,0 +1,74 @@
1
+ import { computed as c, toValue as w } from "vue";
2
+ import { getVisibleChildren as V } from "../lib/tree-selection.mjs";
3
+ import { useTreeExpansion as C } from "./useTreeExpansion.mjs";
4
+ function S(x, {
5
+ filteredOptions: h,
6
+ isSearchActive: m,
7
+ matchesSearch: E,
8
+ getCheckState: a
9
+ }) {
10
+ const i = C(m);
11
+ function s(n) {
12
+ return n[x.itemValue];
13
+ }
14
+ const l = c(() => {
15
+ let n = 0;
16
+ return w(h).map((e) => {
17
+ const r = V(e, E), u = r.length > 0, d = u && i.isExpanded(s(e)), p = {
18
+ option: e,
19
+ parent: null,
20
+ level: 1,
21
+ hasChildren: u,
22
+ isExpanded: d,
23
+ checkState: a(e),
24
+ index: n++
25
+ };
26
+ return d ? [
27
+ p,
28
+ ...r.map(
29
+ (f) => ({
30
+ option: f,
31
+ parent: e,
32
+ level: 2,
33
+ hasChildren: !1,
34
+ isExpanded: !1,
35
+ checkState: a(f),
36
+ index: n++
37
+ })
38
+ )
39
+ ] : [p];
40
+ });
41
+ }), t = c(() => l.value.flat());
42
+ function o(n, e) {
43
+ i.setExpanded(s(n), e);
44
+ }
45
+ function v(n) {
46
+ const e = t.value[n];
47
+ if (e != null && e.hasChildren) {
48
+ if (e.isExpanded) return n + 1;
49
+ o(e.option, !0);
50
+ }
51
+ }
52
+ function g(n) {
53
+ const e = t.value[n];
54
+ if (e) {
55
+ if (e.isExpanded) {
56
+ o(e.option, !1);
57
+ return;
58
+ }
59
+ if (e.parent)
60
+ return t.value.findIndex((r) => r.option === e.parent);
61
+ }
62
+ }
63
+ return {
64
+ optionGroups: l,
65
+ visibleRows: t,
66
+ toggleExpanded: o,
67
+ resetExpanded: i.reset,
68
+ handleArrowRight: v,
69
+ handleArrowLeft: g
70
+ };
71
+ }
72
+ export {
73
+ S as useMultiSelectRows
74
+ };
@@ -0,0 +1,44 @@
1
+ import { computed as l } from "vue";
2
+ import { isTreeOptions as S, withImpliedChildren as h, getDisplayOptions as y, toggleOptionValue as b, getCheckState as C, flattenTreeOptions as I } from "../lib/tree-selection.mjs";
3
+ function k(e, f) {
4
+ const c = l(() => S(e.options));
5
+ function n(t) {
6
+ return t[e.itemValue];
7
+ }
8
+ const a = l(
9
+ () => Array.isArray(e.modelValue) ? e.modelValue : [e.modelValue]
10
+ ), g = l(
11
+ () => e.returnObject ? a.value.map(n) : a.value
12
+ ), r = l(
13
+ () => h(e.options, g.value, n)
14
+ ), m = l(() => new Set(r.value));
15
+ function V(t) {
16
+ if (!e.returnObject) return t;
17
+ const o = [
18
+ ...I(e.options),
19
+ ...a.value
20
+ ], i = new Map(o.map((u) => [n(u), u]));
21
+ return t.map((u) => i.get(u));
22
+ }
23
+ function s(t) {
24
+ return C(t, m.value, n);
25
+ }
26
+ function d(t, o) {
27
+ const i = b(
28
+ e.options,
29
+ r.value,
30
+ t,
31
+ o,
32
+ n
33
+ );
34
+ f("update:modelValue", V(i));
35
+ }
36
+ function v(t) {
37
+ t.disabled || d(t, s(t) !== !0);
38
+ }
39
+ const O = l(() => e.returnObject && !c.value ? e.modelValue : y(e.options, m.value, n));
40
+ return { isTreeMode: c, getCheckState: s, toggleOption: d, toggle: v, displayItems: O };
41
+ }
42
+ export {
43
+ k as useMultiSelectSelection
44
+ };
@@ -1,63 +1,68 @@
1
- import { ref as b, computed as s } from "vue";
2
- import { useElementSize as w } from "../node_modules/@vueuse/core/dist/index.mjs";
3
- function V(n, g, c, d) {
4
- const v = b(!1), { width: f } = w(c), m = s(() => `${f.value}px`), l = s(() => {
5
- var t;
6
- const e = n.options;
7
- if (!n.enableSearch || !n.search) return e;
8
- const o = ((t = n.search) == null ? void 0 : t.toLowerCase()) ?? "";
9
- return e.filter((i) => {
10
- const a = String(i[n.itemLabel] ?? "").toLowerCase().includes(o), r = String(i[n.itemValue] ?? "").toLowerCase().includes(o);
11
- return a || r;
12
- });
13
- });
14
- function L(e) {
1
+ import { ref as G, computed as s } from "vue";
2
+ import { useElementSize as P } from "../node_modules/@vueuse/core/dist/index.mjs";
3
+ function A(e, d, l, f, {
4
+ filterOptions: m = (a, c) => a.filter(c)
5
+ } = {}) {
6
+ const a = G(!1), { width: c } = P(l), S = s(() => `${c.value}px`), r = s(
7
+ () => e.enableSearch && !!e.search
8
+ );
9
+ function u(t) {
10
+ if (!r.value) return !0;
11
+ const o = e.search.toLowerCase(), n = String(t[e.itemLabel] ?? "").toLowerCase().includes(o), i = String(t[e.itemValue] ?? "").toLowerCase().includes(o);
12
+ return n || i;
13
+ }
14
+ const h = s(
15
+ () => r.value ? m(e.options, u) : e.options
16
+ );
17
+ function L(t) {
15
18
  const {
16
19
  optionsLength: o,
17
- optionsLines: t,
20
+ optionsLines: n,
18
21
  enableSearch: i,
19
- variant: a
20
- } = e;
22
+ variant: H
23
+ } = t;
21
24
  if (o === 0) return "unset";
22
- if (a === "single") {
23
- const x = 37 * t, H = i ? 1 : 2, h = x + 32 + (4 * t - H);
24
- return `${i ? h + 45 + 1 : h}px`;
25
+ if (H === "single") {
26
+ const w = 37 * n, C = i ? 1 : 2, g = w + 32 + (4 * n - C);
27
+ return `${i ? g + 45 + 1 : g}px`;
25
28
  }
26
- const r = i ? 16 : 0, u = 22 * t + (24 * t - 2);
27
- return `${i ? u + 51 + r : u}px`;
29
+ const b = i ? 16 : 0, v = 22 * n + (24 * n - 2);
30
+ return `${i ? v + 51 + b : v}px`;
28
31
  }
29
32
  const p = s(
30
33
  () => {
31
- var e;
34
+ var t;
32
35
  return L({
33
- optionsLength: ((e = n.options) == null ? void 0 : e.length) ?? 0,
34
- optionsLines: n.optionsLines,
35
- enableSearch: n.enableSearch,
36
- variant: g
36
+ optionsLength: ((t = e.options) == null ? void 0 : t.length) ?? 0,
37
+ optionsLines: e.optionsLines,
38
+ enableSearch: e.enableSearch,
39
+ variant: d
37
40
  });
38
41
  }
39
- ), S = s(() => {
40
- var t;
41
- const e = ((t = l.value) == null ? void 0 : t.length) === 0, o = p.value;
42
+ ), x = s(() => {
43
+ var n;
44
+ const t = ((n = h.value) == null ? void 0 : n.length) === 0, o = p.value;
42
45
  return {
43
46
  overflow: "auto",
44
47
  display: "flex",
45
48
  flexDirection: "column",
46
49
  minHeight: o,
47
- maxHeight: e ? "unset" : o,
48
- height: e ? o : "unset"
50
+ maxHeight: t ? "unset" : o,
51
+ height: t ? o : "unset"
49
52
  };
50
53
  });
51
54
  return {
52
- openPopover: v,
53
- triggerRef: c,
54
- contentRef: d,
55
- inputWidthString: m,
55
+ openPopover: a,
56
+ triggerRef: l,
57
+ contentRef: f,
58
+ inputWidthString: S,
56
59
  calculatedPopoverHeight: p,
57
- popoverContentCustomStyles: S,
58
- filteredOptions: l
60
+ popoverContentCustomStyles: x,
61
+ isSearchActive: r,
62
+ matchesSearch: u,
63
+ filteredOptions: h
59
64
  };
60
65
  }
61
66
  export {
62
- V as useSelectBase
67
+ A as useSelectBase
63
68
  };
@@ -1,53 +1,88 @@
1
- import { ref as K, watch as k, nextTick as f, onBeforeUnmount as A } from "vue";
2
- const E = "data-option-index";
3
- function b(a, w, y) {
4
- const { closeOnSelect: v = !0, closePopover: m, openPopoverRef: u } = y, n = K(-1);
5
- function r(e, s = "smooth", t = "center") {
6
- f(() => {
7
- var d;
1
+ import { ref as E, watch as w, nextTick as y, onBeforeUnmount as K, toValue as T } from "vue";
2
+ const I = "data-option-index";
3
+ function v(u) {
4
+ const i = u.target;
5
+ return i instanceof HTMLElement ? i.closest('input, textarea, button, [contenteditable="true"]') ? !0 : i.isContentEditable : !1;
6
+ }
7
+ function O(u, i, m) {
8
+ const {
9
+ closeOnSelect: D = !0,
10
+ closePopover: b,
11
+ openPopoverRef: a,
12
+ onArrowRight: k,
13
+ onArrowLeft: A,
14
+ toggleOnSpace: g = !1
15
+ } = m, n = E(-1);
16
+ function l(e, t = "smooth", f = "center") {
17
+ y(() => {
18
+ var r;
8
19
  const o = document.querySelector(
9
- `[${E}="${e}"]`
20
+ `[${I}="${e}"]`
10
21
  );
11
- (d = o == null ? void 0 : o.scrollIntoView) == null || d.call(o, { behavior: s, block: t });
22
+ (r = o == null ? void 0 : o.scrollIntoView) == null || r.call(o, { behavior: t, block: f });
12
23
  });
13
24
  }
14
- function i(e) {
15
- if (!["ArrowUp", "ArrowDown", "Enter"].includes(e.key)) return;
16
- e.preventDefault();
17
- const t = a();
25
+ function c() {
26
+ const t = u()[n.value];
27
+ n.value < 0 || !t || t.disabled || (i(t), D && b());
28
+ }
29
+ function s(e) {
30
+ const t = u();
18
31
  if (e.key === "ArrowUp") {
19
- if (n.value <= 0) return;
20
- n.value--, r(n.value);
21
- } else if (e.key === "ArrowDown") {
22
- if (n.value >= t.length - 1) return;
23
- n.value++, r(n.value);
24
- } else if (e.key === "Enter" && n.value >= 0 && t[n.value]) {
32
+ if (e.preventDefault(), n.value <= 0) return;
33
+ n.value--, l(n.value);
34
+ return;
35
+ }
36
+ if (e.key === "ArrowDown") {
37
+ if (e.preventDefault(), n.value >= t.length - 1) return;
38
+ n.value++, l(n.value);
39
+ return;
40
+ }
41
+ if (e.key === "Enter") {
42
+ e.preventDefault(), c();
43
+ return;
44
+ }
45
+ const f = e.key === "ArrowRight" ? k : e.key === "ArrowLeft" ? A : void 0;
46
+ if (f) {
47
+ if (v(e)) return;
48
+ e.preventDefault();
25
49
  const o = t[n.value];
26
- if (o != null && o.disabled) return;
27
- w(o), v && m();
50
+ if (!o) return;
51
+ const r = f(n.value, o);
52
+ typeof r == "number" && r >= 0 && (n.value = r, l(r));
53
+ return;
54
+ }
55
+ if (e.key === " " && T(g)) {
56
+ if (v(e)) return;
57
+ e.preventDefault(), c();
28
58
  }
29
59
  }
30
- function c(e) {
31
- u.value && i(e);
60
+ function d(e) {
61
+ a.value && s(e);
32
62
  }
33
- function p() {
34
- document.addEventListener("keydown", c);
63
+ function h() {
64
+ document.addEventListener("keydown", d);
35
65
  }
36
- function l() {
37
- document.removeEventListener("keydown", c);
66
+ function p() {
67
+ document.removeEventListener("keydown", d);
38
68
  }
39
- function D() {
40
- k(u, (e) => {
41
- e ? f(p) : l();
42
- }), A(l);
69
+ function x() {
70
+ w(a, (e) => {
71
+ e ? y(h) : p();
72
+ }), w(
73
+ () => u().length,
74
+ (e) => {
75
+ n.value >= e && (n.value = e - 1);
76
+ }
77
+ ), K(p);
43
78
  }
44
79
  return {
45
80
  focusedOptionIndex: n,
46
- scrollToOption: r,
47
- handleKeyDown: i,
48
- setupKeydownBinding: D
81
+ scrollToOption: l,
82
+ handleKeyDown: s,
83
+ setupKeydownBinding: x
49
84
  };
50
85
  }
51
86
  export {
52
- b as useSelectKeyboard
87
+ O as useSelectKeyboard
53
88
  };
@@ -0,0 +1,24 @@
1
+ import { ref as d, watch as i, toValue as a } from "vue";
2
+ function h(t) {
3
+ const s = d(/* @__PURE__ */ new Set()), n = d(/* @__PURE__ */ new Set());
4
+ i(
5
+ () => a(t),
6
+ () => {
7
+ n.value = /* @__PURE__ */ new Set();
8
+ }
9
+ );
10
+ function u(e) {
11
+ return a(t) ? !n.value.has(e) : s.value.has(e);
12
+ }
13
+ function f(e, l = !u(e)) {
14
+ const r = a(t), c = r ? n : s, p = r ? !l : l, o = new Set(c.value);
15
+ p ? o.add(e) : o.delete(e), c.value = o;
16
+ }
17
+ function w() {
18
+ s.value = /* @__PURE__ */ new Set(), n.value = /* @__PURE__ */ new Set();
19
+ }
20
+ return { isExpanded: u, setExpanded: f, reset: w };
21
+ }
22
+ export {
23
+ h as useTreeExpansion
24
+ };
@@ -0,0 +1,66 @@
1
+ function l(e) {
2
+ return Array.isArray(e.children) ? e.children : [];
3
+ }
4
+ function a(e) {
5
+ return l(e).length > 0;
6
+ }
7
+ function y(e) {
8
+ return e.some(a);
9
+ }
10
+ function C(e) {
11
+ return e.flatMap((t) => [t, ...l(t)]);
12
+ }
13
+ function o(e) {
14
+ const t = l(e), n = t.filter((i) => !i.disabled);
15
+ return n.length ? n : t;
16
+ }
17
+ function b(e, t) {
18
+ return e.filter(
19
+ (n) => t(n) || l(n).some(t)
20
+ );
21
+ }
22
+ function S(e, t) {
23
+ const n = l(e);
24
+ return t(e) ? n : n.filter(t);
25
+ }
26
+ function p(e, t, n) {
27
+ const i = new Set(t), r = e.filter((s) => i.has(n(s))).flatMap(l).filter((s) => !s.disabled && !i.has(n(s))).map(n);
28
+ return [...t, ...r];
29
+ }
30
+ function g(e, t, n) {
31
+ const i = (s) => t.has(n(s)), r = l(e);
32
+ return r.length ? o(e).every(i) ? !0 : r.some(i) ? "less" : !1 : i(e);
33
+ }
34
+ function O(e, t, n) {
35
+ const i = n(t);
36
+ return e.find(
37
+ (r) => l(r).some((s) => n(s) === i)
38
+ );
39
+ }
40
+ function m(e, t, n) {
41
+ const i = n(e), r = new Set(t), s = t.filter((c) => c !== i);
42
+ return o(e).every(
43
+ (c) => r.has(n(c))
44
+ ) ? [...s, i] : s;
45
+ }
46
+ function w(e, t, n, i, r) {
47
+ const s = a(n), f = s ? n : O(e, n, r), h = (s ? l(n).filter((d) => !d.disabled) : [n]).map(r), u = t.filter((d) => !h.includes(d));
48
+ return i && u.push(...h), f ? m(f, u, r) : u;
49
+ }
50
+ function x(e, t, n) {
51
+ const i = (r) => t.has(n(r));
52
+ return e.flatMap((r) => a(r) ? g(r, t, n) === !0 ? [r] : l(r).filter(i) : i(r) ? [r] : []);
53
+ }
54
+ export {
55
+ b as filterTreeOptions,
56
+ C as flattenTreeOptions,
57
+ g as getCheckState,
58
+ x as getDisplayOptions,
59
+ o as getDrivingChildren,
60
+ l as getOptionChildren,
61
+ S as getVisibleChildren,
62
+ a as hasOptionChildren,
63
+ y as isTreeOptions,
64
+ w as toggleOptionValue,
65
+ p as withImpliedChildren
66
+ };
@@ -40,7 +40,7 @@ const e = {
40
40
  flags: "Flags",
41
41
  custom: "Custom"
42
42
  }
43
- }, i = "Search", l = "No results found", u = {
43
+ }, i = "Collapse", l = "Expand", d = "Search", n = "No results found", u = {
44
44
  upload_area: e,
45
45
  import_card: t,
46
46
  audio_recorder: o,
@@ -48,18 +48,22 @@ const e = {
48
48
  chats_contact: a,
49
49
  data_table: r,
50
50
  emoji_picker: c,
51
- search: i,
52
- without_results: l
51
+ collapse: i,
52
+ expand: l,
53
+ search: d,
54
+ without_results: n
53
55
  };
54
56
  export {
55
57
  o as audio_recorder,
56
58
  s as chat_message,
57
59
  a as chats_contact,
60
+ i as collapse,
58
61
  r as data_table,
59
62
  u as default,
60
63
  c as emoji_picker,
64
+ l as expand,
61
65
  t as import_card,
62
- i as search,
66
+ d as search,
63
67
  e as upload_area,
64
- l as without_results
68
+ n as without_results
65
69
  };