@nubisco/ui 5.5.0 → 5.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/Avatar-672086EP.js +57 -0
  2. package/dist/Avatar-DqHh71ha.cjs +1 -0
  3. package/dist/{Pagination-Dz24gpb7.cjs → Pagination-CcZB4Lp_.cjs} +1 -1
  4. package/dist/{Pagination-BInZQpJS.js → Pagination-DDIc4vUH.js} +1 -1
  5. package/dist/Select-BMamCNcN.cjs +1 -0
  6. package/dist/Select-CB4BSCaj.js +405 -0
  7. package/dist/{Tree-DI_ouWnv.cjs → Tree-CMXvRX6y.cjs} +1 -1
  8. package/dist/{Tree-DHdPsRXV.js → Tree-Clpnh7Mh.js} +1 -1
  9. package/dist/TreeContext-51-0WkVM.cjs +1 -0
  10. package/dist/TreeContext-C77g-WGF.js +4 -0
  11. package/dist/TreeNode-DsOOkac_.js +171 -0
  12. package/dist/TreeNode-n65SoYln.cjs +1 -0
  13. package/dist/all.cjs +1 -1
  14. package/dist/all.mjs +19 -18
  15. package/dist/components/Avatar.cjs +1 -1
  16. package/dist/components/Avatar.d.ts +19 -2
  17. package/dist/components/Avatar.mjs +1 -1
  18. package/dist/components/Avatar.vue.d.ts +3 -1
  19. package/dist/components/Avatar.vue.d.ts.map +1 -1
  20. package/dist/components/Pagination.cjs +1 -1
  21. package/dist/components/Pagination.mjs +1 -1
  22. package/dist/components/Select.cjs +1 -1
  23. package/dist/components/Select.d.ts +10 -0
  24. package/dist/components/Select.mjs +1 -1
  25. package/dist/components/Select.vue.d.ts +7 -7
  26. package/dist/components/Select.vue.d.ts.map +1 -1
  27. package/dist/components/Tree.cjs +1 -1
  28. package/dist/components/Tree.d.ts +2 -3
  29. package/dist/components/Tree.mjs +1 -1
  30. package/dist/components/TreeContext.d.ts +5 -0
  31. package/dist/components/TreeContext.d.ts.map +1 -1
  32. package/dist/components/TreeNode.cjs +1 -1
  33. package/dist/components/TreeNode.mjs +1 -1
  34. package/dist/components/TreeNode.vue.d.ts.map +1 -1
  35. package/dist/index.cjs +1 -1
  36. package/dist/index.mjs +14 -13
  37. package/dist/main.d.ts +2 -0
  38. package/dist/main.d.ts.map +1 -1
  39. package/dist/styles/Select.css +1 -1
  40. package/dist/styles/TreeNode.css +1 -1
  41. package/dist/ui.css +2 -2
  42. package/dist/utils/treeMove.helper.cjs +1 -0
  43. package/dist/utils/treeMove.helper.d.ts +87 -0
  44. package/dist/utils/treeMove.helper.d.ts.map +1 -0
  45. package/dist/utils/treeMove.helper.mjs +86 -0
  46. package/package.json +1 -1
  47. package/src/utils/treeMove.helper.ts +223 -0
  48. package/dist/Avatar-C6pCz1lv.cjs +0 -1
  49. package/dist/Avatar-DdI07lRT.js +0 -47
  50. package/dist/Select-BbsEiJ4j.cjs +0 -1
  51. package/dist/Select-Ep1fFBFj.js +0 -378
  52. package/dist/TreeContext-BH2qpPud.cjs +0 -1
  53. package/dist/TreeContext-DMADOfuO.js +0 -4
  54. package/dist/TreeNode-CME77z98.js +0 -165
  55. package/dist/TreeNode-CpV3GOzv.cjs +0 -1
@@ -0,0 +1,223 @@
1
+ /**
2
+ * Moving a node around a tree, as data.
3
+ *
4
+ * Dragging a row and a "Move to" picker ask the same questions, and neither of
5
+ * them is about the DOM: where may this node go, and what does the tree look
6
+ * like afterwards. Every product that reorders a tree writes this again, and
7
+ * the one rule that is easy to miss is the one that does real damage: a node
8
+ * dropped into its own subtree detaches that subtree from the root, and
9
+ * everything under it disappears.
10
+ *
11
+ * These work on any tree of `{ id, children }` and never touch the tree they
12
+ * are given: a plan is a new tree of shallow copies, so every field a product
13
+ * carries on its nodes comes through. `NbTree` enforces the same rule for
14
+ * pointer drags, so a product that uses both gets one answer.
15
+ */
16
+
17
+ /** The shape these read: an id, and children when it has any. */
18
+ export interface ITreeMoveNode {
19
+ id: string
20
+ children?: ITreeMoveNode[]
21
+ }
22
+
23
+ /** Where a node goes: next to another node, inside it, or at the top level. */
24
+ export type TTreeMovePlacement =
25
+ | { kind: 'inside'; target: string }
26
+ | { kind: 'before'; target: string }
27
+ | { kind: 'after'; target: string }
28
+ | { kind: 'root' }
29
+
30
+ export interface ITreeMovePlan<T extends ITreeMoveNode> {
31
+ /** The tree after the move, as shallow copies. The original is untouched. */
32
+ tree: T[]
33
+ /** The node's new parent, or null at the top level. */
34
+ parentId: string | null
35
+ /** Its index among its new siblings. */
36
+ index: number
37
+ /** The sibling it now follows, or null when it is first. */
38
+ afterId: string | null
39
+ /** The sibling it now precedes, or null when it is last. */
40
+ beforeId: string | null
41
+ }
42
+
43
+ interface ILocated<T extends ITreeMoveNode> {
44
+ node: T
45
+ siblings: T[]
46
+ parent: T | null
47
+ }
48
+
49
+ function childrenOf<T extends ITreeMoveNode>(node: T): T[] {
50
+ return (node.children ?? []) as T[]
51
+ }
52
+
53
+ function locate<T extends ITreeMoveNode>(
54
+ nodes: T[],
55
+ id: string,
56
+ parent: T | null = null,
57
+ ): ILocated<T> | null {
58
+ for (const node of nodes) {
59
+ if (node.id === id) return { node, siblings: nodes, parent }
60
+ const found = locate(childrenOf(node), id, node)
61
+ if (found) return found
62
+ }
63
+ return null
64
+ }
65
+
66
+ /** The ids of the nodes above `id`, outermost first. Empty for a root node. */
67
+ export function ancestorsOf<T extends ITreeMoveNode>(
68
+ nodes: T[],
69
+ id: string,
70
+ ): string[] {
71
+ const walk = (list: T[], trail: string[]): string[] | null => {
72
+ for (const node of list) {
73
+ if (node.id === id) return trail
74
+ const found = walk(childrenOf(node), [...trail, node.id])
75
+ if (found) return found
76
+ }
77
+ return null
78
+ }
79
+ return walk(nodes, []) ?? []
80
+ }
81
+
82
+ /** `id` and every node under it. Empty when `id` is not in the tree. */
83
+ export function subtreeOf<T extends ITreeMoveNode>(
84
+ nodes: T[],
85
+ id: string,
86
+ ): Set<string> {
87
+ const out = new Set<string>()
88
+ const found = locate(nodes, id)
89
+ const walk = (node: T) => {
90
+ out.add(node.id)
91
+ childrenOf(node).forEach(walk)
92
+ }
93
+ if (found) walk(found.node)
94
+ return out
95
+ }
96
+
97
+ /**
98
+ * Whether `target` is `source` itself or somewhere under it, which is the one
99
+ * place a node can never go.
100
+ */
101
+ export function isInvalidTarget<T extends ITreeMoveNode>(
102
+ nodes: T[],
103
+ source: string,
104
+ target: string,
105
+ ): boolean {
106
+ return subtreeOf(nodes, source).has(target)
107
+ }
108
+
109
+ /** A node `source` may move to, in reading order, with its nesting depth. */
110
+ export interface ITreeMoveTarget<T extends ITreeMoveNode> {
111
+ id: string
112
+ depth: number
113
+ node: T
114
+ }
115
+
116
+ /**
117
+ * Every node `source` may move to: all of them but itself and its own subtree.
118
+ * The list a "Move to" picker offers.
119
+ */
120
+ export function moveTargets<T extends ITreeMoveNode>(
121
+ nodes: T[],
122
+ source: string,
123
+ ): ITreeMoveTarget<T>[] {
124
+ const out: ITreeMoveTarget<T>[] = []
125
+ const walk = (list: T[], depth: number) => {
126
+ for (const node of list) {
127
+ if (node.id === source) continue
128
+ out.push({ id: node.id, depth, node })
129
+ walk(childrenOf(node), depth + 1)
130
+ }
131
+ }
132
+ walk(nodes, 0)
133
+ return out
134
+ }
135
+
136
+ /**
137
+ * The tree after moving `source` to `placement`, or null when the move is
138
+ * refused (into its own subtree, or a node or target that is not there) or
139
+ * would change nothing.
140
+ *
141
+ * "Inside" appends as the last child, so dragging a node onto its own current
142
+ * parent moves it to the end rather than leaving it where it was. The returned
143
+ * `parentId`, `index`, `afterId` and `beforeId` describe the new position, for
144
+ * a product to turn into whatever its own storage records.
145
+ */
146
+ export function planTreeMove<T extends ITreeMoveNode>(
147
+ nodes: T[],
148
+ source: string,
149
+ placement: TTreeMovePlacement,
150
+ ): ITreeMovePlan<T> | null {
151
+ const from = locate(nodes, source)
152
+ if (!from) return null
153
+ if (placement.kind !== 'root') {
154
+ if (isInvalidTarget(nodes, source, placement.target)) return null
155
+ if (!locate(nodes, placement.target)) return null
156
+ }
157
+
158
+ const clone = (list: T[]): T[] =>
159
+ list.map((node) =>
160
+ node.children === undefined
161
+ ? ({ ...node } as T)
162
+ : ({ ...node, children: clone(childrenOf(node)) } as T),
163
+ )
164
+
165
+ const tree = clone(nodes)
166
+ const moving = locate(tree, source)!
167
+ moving.siblings.splice(moving.siblings.indexOf(moving.node), 1)
168
+
169
+ if (placement.kind === 'root' || placement.kind === 'inside') {
170
+ const parent =
171
+ placement.kind === 'root' ? null : locate(tree, placement.target)!.node
172
+ if (parent && parent.children === undefined) parent.children = []
173
+ const list = parent ? childrenOf(parent) : tree
174
+ list.push(moving.node)
175
+ } else {
176
+ const anchor = locate(tree, placement.target)!
177
+ const index = anchor.siblings.indexOf(anchor.node)
178
+ anchor.siblings.splice(
179
+ placement.kind === 'before' ? index : index + 1,
180
+ 0,
181
+ moving.node,
182
+ )
183
+ }
184
+
185
+ const after = locate(tree, source)!
186
+ const index = after.siblings.indexOf(after.node)
187
+ const unchanged =
188
+ (after.parent?.id ?? null) === (from.parent?.id ?? null) &&
189
+ index === from.siblings.indexOf(from.node)
190
+ if (unchanged) return null
191
+
192
+ return {
193
+ tree,
194
+ parentId: after.parent?.id ?? null,
195
+ index,
196
+ afterId: index > 0 ? after.siblings[index - 1].id : null,
197
+ beforeId:
198
+ index < after.siblings.length - 1 ? after.siblings[index + 1].id : null,
199
+ }
200
+ }
201
+
202
+ /**
203
+ * A flat list in reading order, each row carrying its nesting depth, rebuilt
204
+ * into a tree. The shape most APIs return a tree in.
205
+ */
206
+ export function nestByDepth<T extends { id: string; depth: number }>(
207
+ rows: T[],
208
+ ): (Omit<T, 'depth'> & { children: unknown[] })[] {
209
+ type TNested = Omit<T, 'depth'> & { children: TNested[] }
210
+ const roots: TNested[] = []
211
+ const stack: { node: TNested; depth: number }[] = []
212
+ for (const row of rows) {
213
+ const { depth, ...rest } = row
214
+ const node = { ...rest, children: [] } as unknown as TNested
215
+ while (stack.length > 0 && stack[stack.length - 1].depth >= depth) {
216
+ stack.pop()
217
+ }
218
+ if (stack.length === 0) roots.push(node)
219
+ else stack[stack.length - 1].node.children.push(node)
220
+ stack.push({ node, depth })
221
+ }
222
+ return roots
223
+ }
@@ -1 +0,0 @@
1
- require(`./chunk-D-qHiVGv.cjs`);const e=require(`./utils/initials.helper.cjs`);let t=require(`vue`);var n=[`role`,`aria-label`,`aria-hidden`,`title`],r=[`src`],i={key:1,class:`nb-avatar__initials`,"aria-hidden":`true`},a=(0,t.defineComponent)({__name:`Avatar`,props:{name:{default:void 0},email:{default:void 0},picture:{default:void 0},size:{default:`md`},decorative:{type:Boolean,default:!1}},setup(a){let o=a,s=(0,t.ref)(!1);(0,t.watch)(()=>o.picture,()=>{s.value=!1});let c=(0,t.computed)(()=>!!o.picture&&!s.value),l=(0,t.computed)(()=>e.initialsOf(o)),u=(0,t.computed)(()=>o.name?.trim()||o.email?.trim()||``);return(e,o)=>((0,t.openBlock)(),(0,t.createElementBlock)(`span`,{class:(0,t.normalizeClass)([`nb-avatar`,[`nb-avatar--${a.size}`]]),role:a.decorative?void 0:`img`,"aria-label":a.decorative?void 0:u.value||void 0,"aria-hidden":a.decorative?`true`:void 0,title:a.decorative?void 0:u.value||void 0},[c.value?((0,t.openBlock)(),(0,t.createElementBlock)(`img`,{key:0,class:`nb-avatar__picture`,src:a.picture??void 0,alt:``,onError:o[0]||=e=>s.value=!0},null,40,r)):((0,t.openBlock)(),(0,t.createElementBlock)(`span`,i,(0,t.toDisplayString)(l.value),1))],10,n))}});Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return a}});
@@ -1,47 +0,0 @@
1
- import { initialsOf as e } from "./utils/initials.helper.mjs";
2
- import { computed as t, createElementBlock as n, defineComponent as r, normalizeClass as i, openBlock as a, ref as o, toDisplayString as s, watch as c } from "vue";
3
- //#region src/components/Avatar.vue?vue&type=script&setup=true&lang.ts
4
- var l = [
5
- "role",
6
- "aria-label",
7
- "aria-hidden",
8
- "title"
9
- ], u = ["src"], d = {
10
- key: 1,
11
- class: "nb-avatar__initials",
12
- "aria-hidden": "true"
13
- }, f = /* @__PURE__ */ r({
14
- __name: "Avatar",
15
- props: {
16
- name: { default: void 0 },
17
- email: { default: void 0 },
18
- picture: { default: void 0 },
19
- size: { default: "md" },
20
- decorative: {
21
- type: Boolean,
22
- default: !1
23
- }
24
- },
25
- setup(r) {
26
- let f = r, p = o(!1);
27
- c(() => f.picture, () => {
28
- p.value = !1;
29
- });
30
- let m = t(() => !!f.picture && !p.value), h = t(() => e(f)), g = t(() => f.name?.trim() || f.email?.trim() || "");
31
- return (e, t) => (a(), n("span", {
32
- class: i(["nb-avatar", [`nb-avatar--${r.size}`]]),
33
- role: r.decorative ? void 0 : "img",
34
- "aria-label": r.decorative ? void 0 : g.value || void 0,
35
- "aria-hidden": r.decorative ? "true" : void 0,
36
- title: r.decorative ? void 0 : g.value || void 0
37
- }, [m.value ? (a(), n("img", {
38
- key: 0,
39
- class: "nb-avatar__picture",
40
- src: r.picture ?? void 0,
41
- alt: "",
42
- onError: t[0] ||= (e) => p.value = !0
43
- }, null, 40, u)) : (a(), n("span", d, s(h.value), 1))], 10, l));
44
- }
45
- });
46
- //#endregion
47
- export { f as t };
@@ -1 +0,0 @@
1
- require(`./chunk-D-qHiVGv.cjs`);const e=require(`./Icon-C8R_r_In.cjs`),t=require(`./Label-DtXh4XR5.cjs`),n=require(`./Message-D8ZE4uGZ.cjs`),r=require(`./Grid-DTZTlxd_.cjs`);let i=require(`vue`),a=require(`@nubisco/ui/icons/caret-down`),o=require(`@nubisco/ui/icons/caret-up`);var s=[`id`,`aria-expanded`,`aria-disabled`,`aria-required`,`disabled`],c=[`id`,`aria-expanded`,`aria-disabled`,`aria-required`,`disabled`],l={key:1,class:`nb-select__inner-label`},u={key:0,class:`nb-select__asterisk`,"aria-hidden":`true`},d=[`aria-multiselectable`],f=[`aria-selected`,`aria-disabled`,`onMouseenter`,`onClick`],p={key:0,class:`nb-select__option-check`,"aria-hidden":`true`},m={key:0,viewBox:`0 0 10 8`,fill:`none`,width:`10`,height:`8`},h={class:`nb-select__option-label`},g={key:0,class:`nb-select__empty`},_=[`placeholder`,`onKeydown`],v=(0,i.defineComponent)({__name:`Select`,props:{modelValue:{default:null},options:{default:()=>[]},multiple:{type:Boolean,default:!1},creatable:{type:Boolean,default:!1},createPlaceholder:{default:``},placeholder:{default:`Select…`},name:{default:``},disabled:{type:Boolean,default:!1},required:{type:Boolean,default:!1},id:{default:void 0},label:{default:``},error:{default:``},warning:{default:``},helper:{default:``},variant:{default:`default`},size:{default:`md`}},emits:[`update:modelValue`,`change`,`create`],setup(v,{expose:y,emit:b}){let x=v,S=b,C=(0,i.ref)(``);function w(){let e=C.value.trim();e&&(S(`create`,e),C.value=``)}let T=(0,i.ref)(!1),E=(0,i.ref)(!1),D=(0,i.ref)(-1),O=(0,i.ref)(null),k=(0,i.ref)(null),A=(0,i.ref)(null),j=(0,i.ref)({position:`fixed`,top:`0px`,left:`0px`,width:`0px`,zIndex:`9999`}),M=`nb-select-${(0,i.useId)()}`,N=(0,i.computed)(()=>x.id??M),P=(0,i.computed)(()=>x.modelValue==null?[]:Array.isArray(x.modelValue)?x.modelValue:[x.modelValue]),F=(0,i.computed)(()=>{if(P.value.length===0)return``;let e=x.options??[];return x.multiple?P.value.length===1?e.find(e=>e.value===P.value[0])?.label??String(P.value[0]):P.value.length===2?P.value.map(t=>e.find(e=>e.value===t)?.label??String(t)).join(`, `):`${P.value.length} selected`:e.find(e=>e.value===P.value[0])?.label??String(P.value[0])});function I(e){return P.value.includes(e)}function L(e){if(e.disabled)return;let t;if(x.multiple){let n=[...P.value],r=n.indexOf(e.value);r>=0?n.splice(r,1):n.push(e.value),t=n}else t=e.value,B();S(`update:modelValue`,t),S(`change`,t)}function R(){if(!k.value)return;let e=k.value.getBoundingClientRect(),t=A.value?.offsetHeight??0,n=window.innerHeight-e.bottom,r=e.top;j.value={position:`fixed`,top:t>0&&n<t&&r>n?`${e.top-t}px`:`${e.bottom}px`,left:`${e.left}px`,width:`${e.width}px`,zIndex:`9999`}}function z(){if(x.disabled)return;T.value=!0,R();let e=x.options??[];D.value=P.value.length>0?Math.max(0,e.findIndex(e=>e.value===P.value[0])):-1,(0,i.nextTick)(()=>{R(),G()})}function B(){T.value=!1,D.value=-1}function V(){T.value?B():z()}function H(e){let t=e.target,n=O.value?.contains(t)??!1,r=A.value?.contains(t)??!1;!n&&!r&&B()}function U(){T.value&&R()}(0,i.watch)(T,e=>{e?(document.addEventListener(`mousedown`,H),window.addEventListener(`scroll`,U,!0),window.addEventListener(`resize`,U)):(document.removeEventListener(`mousedown`,H),window.removeEventListener(`scroll`,U,!0),window.removeEventListener(`resize`,U))}),(0,i.onBeforeUnmount)(()=>{document.removeEventListener(`mousedown`,H),window.removeEventListener(`scroll`,U,!0),window.removeEventListener(`resize`,U)});function W(e){let t=x.options??[];if(!T.value){(e.key===`Enter`||e.key===` `||e.key===`ArrowDown`)&&(e.preventDefault(),z());return}e.key===`Escape`?(B(),e.preventDefault()):e.key===`Tab`?B():e.key===`ArrowDown`?(e.preventDefault(),D.value=Math.min(D.value+1,t.length-1),G()):e.key===`ArrowUp`?(e.preventDefault(),D.value=Math.max(D.value-1,0),G()):(e.key===`Enter`||e.key===` `)&&D.value>=0&&(e.preventDefault(),L(t[D.value]))}function G(){(0,i.nextTick)(()=>{!A.value||D.value<0||A.value.querySelectorAll(`.nb-select__option`)[D.value]?.scrollIntoView({block:`nearest`})})}let K=(0,i.computed)(()=>[`nb-select`,`nb-select--${x.variant}`,`nb-select--${x.size}`,{"nb-select--open":T.value,"nb-select--focused":E.value&&!T.value,"nb-select--error":!!x.error,"nb-select--warning":!x.error&&!!x.warning,"nb-select--multiple":x.multiple}]);return y({open:z,close:B}),(y,b)=>((0,i.openBlock)(),(0,i.createElementBlock)(i.Fragment,null,[(0,i.createElementVNode)(`div`,{ref_key:`rootRef`,ref:O,class:(0,i.normalizeClass)(K.value),onKeydown:W},[v.variant===`default`?((0,i.openBlock)(),(0,i.createElementBlock)(i.Fragment,{key:0},[y.$slots.label?(0,i.renderSlot)(y.$slots,`label`,{key:0}):v.label?((0,i.openBlock)(),(0,i.createBlock)(t.t,{key:1,for:N.value,required:v.required,disabled:v.disabled},{default:(0,i.withCtx)(()=>[(0,i.createTextVNode)((0,i.toDisplayString)(v.label),1)]),_:1},8,[`for`,`required`,`disabled`])):(0,i.createCommentVNode)(``,!0),(0,i.createElementVNode)(`button`,{id:N.value,ref_key:`triggerRef`,ref:k,type:`button`,class:`nb-select__trigger`,role:`combobox`,"aria-expanded":T.value,"aria-haspopup":`listbox`,"aria-disabled":v.disabled||void 0,"aria-required":v.required||void 0,disabled:v.disabled||void 0,onClick:V,onFocus:b[0]||=e=>E.value=!0,onBlur:b[1]||=e=>E.value=!1},[(0,i.createElementVNode)(`span`,{class:(0,i.normalizeClass)([`nb-select__value`,{"nb-select__value--placeholder":!F.value}])},[F.value?(0,i.renderSlot)(y.$slots,`value`,{key:0,values:P.value},()=>[(0,i.createTextVNode)((0,i.toDisplayString)(F.value),1)]):((0,i.openBlock)(),(0,i.createElementBlock)(i.Fragment,{key:1},[(0,i.createTextVNode)((0,i.toDisplayString)(v.placeholder),1)],64))],2),v.error?((0,i.openBlock)(),(0,i.createBlock)(n.t,{key:0,variant:`error`,"icon-only":!0,class:`nb-select__status-icon`},{default:(0,i.withCtx)(()=>[(0,i.createTextVNode)((0,i.toDisplayString)(v.error),1)]),_:1})):v.warning?((0,i.openBlock)(),(0,i.createBlock)(n.t,{key:1,variant:`warning`,"icon-only":!0,class:`nb-select__status-icon`},{default:(0,i.withCtx)(()=>[(0,i.createTextVNode)((0,i.toDisplayString)(v.warning),1)]),_:1})):(0,i.createCommentVNode)(``,!0),(0,i.createVNode)(r.t,{align:`center`,justify:`center`,class:`nb-select__caret`},{default:(0,i.withCtx)(()=>[(0,i.createVNode)(e.t,{name:T.value?(0,i.unref)(o.regular):(0,i.unref)(a.regular),size:16},null,8,[`name`])]),_:1})],40,s),v.error?((0,i.openBlock)(),(0,i.createBlock)(n.t,{key:2,variant:`error`,class:`nb-select__message`},{default:(0,i.withCtx)(()=>[(0,i.createTextVNode)((0,i.toDisplayString)(v.error),1)]),_:1})):v.warning?((0,i.openBlock)(),(0,i.createBlock)(n.t,{key:3,variant:`warning`,class:`nb-select__message`},{default:(0,i.withCtx)(()=>[(0,i.createTextVNode)((0,i.toDisplayString)(v.warning),1)]),_:1})):v.helper?((0,i.openBlock)(),(0,i.createBlock)(n.t,{key:4,variant:`helper`,class:`nb-select__message`},{default:(0,i.withCtx)(()=>[(0,i.createTextVNode)((0,i.toDisplayString)(v.helper),1)]),_:1})):(0,i.createCommentVNode)(``,!0)],64)):v.variant===`fluid`?((0,i.openBlock)(),(0,i.createElementBlock)(i.Fragment,{key:1},[(0,i.createElementVNode)(`button`,{id:N.value,ref_key:`triggerRef`,ref:k,type:`button`,class:`nb-select__trigger`,role:`combobox`,"aria-expanded":T.value,"aria-haspopup":`listbox`,"aria-disabled":v.disabled||void 0,"aria-required":v.required||void 0,disabled:v.disabled||void 0,onClick:V,onFocus:b[2]||=e=>E.value=!0,onBlur:b[3]||=e=>E.value=!1},[v.label||y.$slots.label?((0,i.openBlock)(),(0,i.createBlock)(r.t,{key:0,dir:`row`,align:`center`,gap:`xs`,class:`nb-select__inner-header`},{default:(0,i.withCtx)(()=>[y.$slots.label?(0,i.renderSlot)(y.$slots,`label`,{key:0}):((0,i.openBlock)(),(0,i.createElementBlock)(`label`,l,[(0,i.createTextVNode)((0,i.toDisplayString)(v.label)+` `,1),v.required?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,u,`*`)):(0,i.createCommentVNode)(``,!0)])),v.helper&&!v.error&&!v.warning?((0,i.openBlock)(),(0,i.createBlock)(n.t,{key:2,variant:`helper`,"icon-only":!0,class:`nb-select__inner-message`},{default:(0,i.withCtx)(()=>[(0,i.createTextVNode)((0,i.toDisplayString)(v.helper),1)]),_:1})):(0,i.createCommentVNode)(``,!0)]),_:3})):(0,i.createCommentVNode)(``,!0),(0,i.createVNode)(r.t,{dir:`row`,align:`end`,flex:``,class:`nb-select__value-row`},{default:(0,i.withCtx)(()=>[(0,i.createElementVNode)(`span`,{class:(0,i.normalizeClass)([`nb-select__value`,{"nb-select__value--placeholder":!F.value}])},[F.value?(0,i.renderSlot)(y.$slots,`value`,{key:0,values:P.value},()=>[(0,i.createTextVNode)((0,i.toDisplayString)(F.value),1)]):((0,i.openBlock)(),(0,i.createElementBlock)(i.Fragment,{key:1},[(0,i.createTextVNode)((0,i.toDisplayString)(v.placeholder),1)],64))],2),(0,i.createVNode)(r.t,{align:`center`,justify:`center`,class:`nb-select__caret`},{default:(0,i.withCtx)(()=>[(0,i.createVNode)(e.t,{name:T.value?(0,i.unref)(o.regular):(0,i.unref)(a.regular),size:16},null,8,[`name`])]),_:1})]),_:3})],40,c),v.error?((0,i.openBlock)(),(0,i.createBlock)(n.t,{key:0,variant:`error`,class:`nb-select__fluid-message`},{default:(0,i.withCtx)(()=>[(0,i.createTextVNode)((0,i.toDisplayString)(v.error),1)]),_:1})):v.warning?((0,i.openBlock)(),(0,i.createBlock)(n.t,{key:1,variant:`warning`,class:`nb-select__fluid-message`},{default:(0,i.withCtx)(()=>[(0,i.createTextVNode)((0,i.toDisplayString)(v.warning),1)]),_:1})):(0,i.createCommentVNode)(``,!0)],64)):(0,i.createCommentVNode)(``,!0)],34),((0,i.openBlock)(),(0,i.createBlock)(i.Teleport,{to:`body`},[T.value?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,{key:0,ref_key:`dropdownRef`,ref:A,class:`nb-select__dropdown`,style:(0,i.normalizeStyle)(j.value),role:`listbox`,"aria-multiselectable":v.multiple||void 0},[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(v.options,(e,t)=>((0,i.openBlock)(),(0,i.createElementBlock)(`div`,{key:e.value,class:(0,i.normalizeClass)([`nb-select__option`,{"nb-select__option--selected":I(e.value),"nb-select__option--highlighted":D.value===t,"nb-select__option--disabled":e.disabled}]),role:`option`,"aria-selected":I(e.value),"aria-disabled":e.disabled||void 0,onMouseenter:e=>D.value=t,onClick:t=>L(e)},[v.multiple?((0,i.openBlock)(),(0,i.createElementBlock)(`span`,p,[I(e.value)?((0,i.openBlock)(),(0,i.createElementBlock)(`svg`,m,[...b[7]||=[(0,i.createElementVNode)(`path`,{d:`M1 4l3 3 5-6`,stroke:`currentColor`,"stroke-width":`1.5`,"stroke-linecap":`round`,"stroke-linejoin":`round`},null,-1)]])):(0,i.createCommentVNode)(``,!0)])):(0,i.createCommentVNode)(``,!0),(0,i.createElementVNode)(`span`,h,[(0,i.renderSlot)(y.$slots,`option`,{option:e},()=>[(0,i.createTextVNode)((0,i.toDisplayString)(e.label),1)])])],42,f))),128)),!v.options||v.options.length===0?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,g,` No options `)):(0,i.createCommentVNode)(``,!0),v.creatable?((0,i.openBlock)(),(0,i.createElementBlock)(`div`,{key:1,class:`nb-select__create`,onMousedown:b[6]||=(0,i.withModifiers)(()=>{},[`prevent`])},[(0,i.withDirectives)((0,i.createElementVNode)(`input`,{"onUpdate:modelValue":b[4]||=e=>C.value=e,type:`text`,class:`nb-select__create-input`,placeholder:v.createPlaceholder||`Add new…`,onKeydown:[(0,i.withKeys)((0,i.withModifiers)(w,[`prevent`]),[`enter`]),b[5]||=(0,i.withModifiers)(()=>{},[`stop`])]},null,40,_),[[i.vModelText,C.value]])],32)):(0,i.createCommentVNode)(``,!0)],12,d)):(0,i.createCommentVNode)(``,!0)]))],64))}});Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return v}});
@@ -1,378 +0,0 @@
1
- import { t as e } from "./Icon-rREAqsu0.js";
2
- import { t } from "./Label-glcQoGCr.js";
3
- import { t as n } from "./Message-Ciyc2nN6.js";
4
- import { t as r } from "./Grid-CgUyhsw4.js";
5
- import { Fragment as i, Teleport as ee, computed as a, createBlock as o, createCommentVNode as s, createElementBlock as c, createElementVNode as l, createTextVNode as u, createVNode as d, defineComponent as f, nextTick as p, normalizeClass as m, normalizeStyle as h, onBeforeUnmount as te, openBlock as g, ref as _, renderList as ne, renderSlot as v, toDisplayString as y, unref as b, useId as x, vModelText as S, watch as re, withCtx as C, withDirectives as ie, withKeys as ae, withModifiers as w } from "vue";
6
- import { regular as T } from "@nubisco/ui/icons/caret-down";
7
- import { regular as E } from "@nubisco/ui/icons/caret-up";
8
- //#region src/components/Select.vue?vue&type=script&setup=true&lang.ts
9
- var D = [
10
- "id",
11
- "aria-expanded",
12
- "aria-disabled",
13
- "aria-required",
14
- "disabled"
15
- ], O = [
16
- "id",
17
- "aria-expanded",
18
- "aria-disabled",
19
- "aria-required",
20
- "disabled"
21
- ], oe = {
22
- key: 1,
23
- class: "nb-select__inner-label"
24
- }, se = {
25
- key: 0,
26
- class: "nb-select__asterisk",
27
- "aria-hidden": "true"
28
- }, k = ["aria-multiselectable"], ce = [
29
- "aria-selected",
30
- "aria-disabled",
31
- "onMouseenter",
32
- "onClick"
33
- ], le = {
34
- key: 0,
35
- class: "nb-select__option-check",
36
- "aria-hidden": "true"
37
- }, ue = {
38
- key: 0,
39
- viewBox: "0 0 10 8",
40
- fill: "none",
41
- width: "10",
42
- height: "8"
43
- }, de = { class: "nb-select__option-label" }, fe = {
44
- key: 0,
45
- class: "nb-select__empty"
46
- }, pe = ["placeholder", "onKeydown"], A = /* @__PURE__ */ f({
47
- __name: "Select",
48
- props: {
49
- modelValue: { default: null },
50
- options: { default: () => [] },
51
- multiple: {
52
- type: Boolean,
53
- default: !1
54
- },
55
- creatable: {
56
- type: Boolean,
57
- default: !1
58
- },
59
- createPlaceholder: { default: "" },
60
- placeholder: { default: "Select…" },
61
- name: { default: "" },
62
- disabled: {
63
- type: Boolean,
64
- default: !1
65
- },
66
- required: {
67
- type: Boolean,
68
- default: !1
69
- },
70
- id: { default: void 0 },
71
- label: { default: "" },
72
- error: { default: "" },
73
- warning: { default: "" },
74
- helper: { default: "" },
75
- variant: { default: "default" },
76
- size: { default: "md" }
77
- },
78
- emits: [
79
- "update:modelValue",
80
- "change",
81
- "create"
82
- ],
83
- setup(f, { expose: A, emit: me }) {
84
- let j = f, M = me, N = _("");
85
- function P() {
86
- let e = N.value.trim();
87
- e && (M("create", e), N.value = "");
88
- }
89
- let F = _(!1), I = _(!1), L = _(-1), R = _(null), z = _(null), B = _(null), V = _({
90
- position: "fixed",
91
- top: "0px",
92
- left: "0px",
93
- width: "0px",
94
- zIndex: "9999"
95
- }), he = `nb-select-${x()}`, H = a(() => j.id ?? he), U = a(() => j.modelValue == null ? [] : Array.isArray(j.modelValue) ? j.modelValue : [j.modelValue]), W = a(() => {
96
- if (U.value.length === 0) return "";
97
- let e = j.options ?? [];
98
- return j.multiple ? U.value.length === 1 ? e.find((e) => e.value === U.value[0])?.label ?? String(U.value[0]) : U.value.length === 2 ? U.value.map((t) => e.find((e) => e.value === t)?.label ?? String(t)).join(", ") : `${U.value.length} selected` : e.find((e) => e.value === U.value[0])?.label ?? String(U.value[0]);
99
- });
100
- function G(e) {
101
- return U.value.includes(e);
102
- }
103
- function K(e) {
104
- if (e.disabled) return;
105
- let t;
106
- if (j.multiple) {
107
- let n = [...U.value], r = n.indexOf(e.value);
108
- r >= 0 ? n.splice(r, 1) : n.push(e.value), t = n;
109
- } else t = e.value, Y();
110
- M("update:modelValue", t), M("change", t);
111
- }
112
- function q() {
113
- if (!z.value) return;
114
- let e = z.value.getBoundingClientRect(), t = B.value?.offsetHeight ?? 0, n = window.innerHeight - e.bottom, r = e.top;
115
- V.value = {
116
- position: "fixed",
117
- top: t > 0 && n < t && r > n ? `${e.top - t}px` : `${e.bottom}px`,
118
- left: `${e.left}px`,
119
- width: `${e.width}px`,
120
- zIndex: "9999"
121
- };
122
- }
123
- function J() {
124
- if (j.disabled) return;
125
- F.value = !0, q();
126
- let e = j.options ?? [];
127
- L.value = U.value.length > 0 ? Math.max(0, e.findIndex((e) => e.value === U.value[0])) : -1, p(() => {
128
- q(), $();
129
- });
130
- }
131
- function Y() {
132
- F.value = !1, L.value = -1;
133
- }
134
- function X() {
135
- F.value ? Y() : J();
136
- }
137
- function Z(e) {
138
- let t = e.target, n = R.value?.contains(t) ?? !1, r = B.value?.contains(t) ?? !1;
139
- !n && !r && Y();
140
- }
141
- function Q() {
142
- F.value && q();
143
- }
144
- re(F, (e) => {
145
- e ? (document.addEventListener("mousedown", Z), window.addEventListener("scroll", Q, !0), window.addEventListener("resize", Q)) : (document.removeEventListener("mousedown", Z), window.removeEventListener("scroll", Q, !0), window.removeEventListener("resize", Q));
146
- }), te(() => {
147
- document.removeEventListener("mousedown", Z), window.removeEventListener("scroll", Q, !0), window.removeEventListener("resize", Q);
148
- });
149
- function ge(e) {
150
- let t = j.options ?? [];
151
- if (!F.value) {
152
- (e.key === "Enter" || e.key === " " || e.key === "ArrowDown") && (e.preventDefault(), J());
153
- return;
154
- }
155
- e.key === "Escape" ? (Y(), e.preventDefault()) : e.key === "Tab" ? Y() : e.key === "ArrowDown" ? (e.preventDefault(), L.value = Math.min(L.value + 1, t.length - 1), $()) : e.key === "ArrowUp" ? (e.preventDefault(), L.value = Math.max(L.value - 1, 0), $()) : (e.key === "Enter" || e.key === " ") && L.value >= 0 && (e.preventDefault(), K(t[L.value]));
156
- }
157
- function $() {
158
- p(() => {
159
- !B.value || L.value < 0 || B.value.querySelectorAll(".nb-select__option")[L.value]?.scrollIntoView({ block: "nearest" });
160
- });
161
- }
162
- let _e = a(() => [
163
- "nb-select",
164
- `nb-select--${j.variant}`,
165
- `nb-select--${j.size}`,
166
- {
167
- "nb-select--open": F.value,
168
- "nb-select--focused": I.value && !F.value,
169
- "nb-select--error": !!j.error,
170
- "nb-select--warning": !j.error && !!j.warning,
171
- "nb-select--multiple": j.multiple
172
- }
173
- ]);
174
- return A({
175
- open: J,
176
- close: Y
177
- }), (a, p) => (g(), c(i, null, [l("div", {
178
- ref_key: "rootRef",
179
- ref: R,
180
- class: m(_e.value),
181
- onKeydown: ge
182
- }, [f.variant === "default" ? (g(), c(i, { key: 0 }, [
183
- a.$slots.label ? v(a.$slots, "label", { key: 0 }) : f.label ? (g(), o(t, {
184
- key: 1,
185
- for: H.value,
186
- required: f.required,
187
- disabled: f.disabled
188
- }, {
189
- default: C(() => [u(y(f.label), 1)]),
190
- _: 1
191
- }, 8, [
192
- "for",
193
- "required",
194
- "disabled"
195
- ])) : s("", !0),
196
- l("button", {
197
- id: H.value,
198
- ref_key: "triggerRef",
199
- ref: z,
200
- type: "button",
201
- class: "nb-select__trigger",
202
- role: "combobox",
203
- "aria-expanded": F.value,
204
- "aria-haspopup": "listbox",
205
- "aria-disabled": f.disabled || void 0,
206
- "aria-required": f.required || void 0,
207
- disabled: f.disabled || void 0,
208
- onClick: X,
209
- onFocus: p[0] ||= (e) => I.value = !0,
210
- onBlur: p[1] ||= (e) => I.value = !1
211
- }, [
212
- l("span", { class: m(["nb-select__value", { "nb-select__value--placeholder": !W.value }]) }, [W.value ? v(a.$slots, "value", {
213
- key: 0,
214
- values: U.value
215
- }, () => [u(y(W.value), 1)]) : (g(), c(i, { key: 1 }, [u(y(f.placeholder), 1)], 64))], 2),
216
- f.error ? (g(), o(n, {
217
- key: 0,
218
- variant: "error",
219
- "icon-only": !0,
220
- class: "nb-select__status-icon"
221
- }, {
222
- default: C(() => [u(y(f.error), 1)]),
223
- _: 1
224
- })) : f.warning ? (g(), o(n, {
225
- key: 1,
226
- variant: "warning",
227
- "icon-only": !0,
228
- class: "nb-select__status-icon"
229
- }, {
230
- default: C(() => [u(y(f.warning), 1)]),
231
- _: 1
232
- })) : s("", !0),
233
- d(r, {
234
- align: "center",
235
- justify: "center",
236
- class: "nb-select__caret"
237
- }, {
238
- default: C(() => [d(e, {
239
- name: F.value ? b(E) : b(T),
240
- size: 16
241
- }, null, 8, ["name"])]),
242
- _: 1
243
- })
244
- ], 40, D),
245
- f.error ? (g(), o(n, {
246
- key: 2,
247
- variant: "error",
248
- class: "nb-select__message"
249
- }, {
250
- default: C(() => [u(y(f.error), 1)]),
251
- _: 1
252
- })) : f.warning ? (g(), o(n, {
253
- key: 3,
254
- variant: "warning",
255
- class: "nb-select__message"
256
- }, {
257
- default: C(() => [u(y(f.warning), 1)]),
258
- _: 1
259
- })) : f.helper ? (g(), o(n, {
260
- key: 4,
261
- variant: "helper",
262
- class: "nb-select__message"
263
- }, {
264
- default: C(() => [u(y(f.helper), 1)]),
265
- _: 1
266
- })) : s("", !0)
267
- ], 64)) : f.variant === "fluid" ? (g(), c(i, { key: 1 }, [l("button", {
268
- id: H.value,
269
- ref_key: "triggerRef",
270
- ref: z,
271
- type: "button",
272
- class: "nb-select__trigger",
273
- role: "combobox",
274
- "aria-expanded": F.value,
275
- "aria-haspopup": "listbox",
276
- "aria-disabled": f.disabled || void 0,
277
- "aria-required": f.required || void 0,
278
- disabled: f.disabled || void 0,
279
- onClick: X,
280
- onFocus: p[2] ||= (e) => I.value = !0,
281
- onBlur: p[3] ||= (e) => I.value = !1
282
- }, [f.label || a.$slots.label ? (g(), o(r, {
283
- key: 0,
284
- dir: "row",
285
- align: "center",
286
- gap: "xs",
287
- class: "nb-select__inner-header"
288
- }, {
289
- default: C(() => [a.$slots.label ? v(a.$slots, "label", { key: 0 }) : (g(), c("label", oe, [u(y(f.label) + " ", 1), f.required ? (g(), c("span", se, "*")) : s("", !0)])), f.helper && !f.error && !f.warning ? (g(), o(n, {
290
- key: 2,
291
- variant: "helper",
292
- "icon-only": !0,
293
- class: "nb-select__inner-message"
294
- }, {
295
- default: C(() => [u(y(f.helper), 1)]),
296
- _: 1
297
- })) : s("", !0)]),
298
- _: 3
299
- })) : s("", !0), d(r, {
300
- dir: "row",
301
- align: "end",
302
- flex: "",
303
- class: "nb-select__value-row"
304
- }, {
305
- default: C(() => [l("span", { class: m(["nb-select__value", { "nb-select__value--placeholder": !W.value }]) }, [W.value ? v(a.$slots, "value", {
306
- key: 0,
307
- values: U.value
308
- }, () => [u(y(W.value), 1)]) : (g(), c(i, { key: 1 }, [u(y(f.placeholder), 1)], 64))], 2), d(r, {
309
- align: "center",
310
- justify: "center",
311
- class: "nb-select__caret"
312
- }, {
313
- default: C(() => [d(e, {
314
- name: F.value ? b(E) : b(T),
315
- size: 16
316
- }, null, 8, ["name"])]),
317
- _: 1
318
- })]),
319
- _: 3
320
- })], 40, O), f.error ? (g(), o(n, {
321
- key: 0,
322
- variant: "error",
323
- class: "nb-select__fluid-message"
324
- }, {
325
- default: C(() => [u(y(f.error), 1)]),
326
- _: 1
327
- })) : f.warning ? (g(), o(n, {
328
- key: 1,
329
- variant: "warning",
330
- class: "nb-select__fluid-message"
331
- }, {
332
- default: C(() => [u(y(f.warning), 1)]),
333
- _: 1
334
- })) : s("", !0)], 64)) : s("", !0)], 34), (g(), o(ee, { to: "body" }, [F.value ? (g(), c("div", {
335
- key: 0,
336
- ref_key: "dropdownRef",
337
- ref: B,
338
- class: "nb-select__dropdown",
339
- style: h(V.value),
340
- role: "listbox",
341
- "aria-multiselectable": f.multiple || void 0
342
- }, [
343
- (g(!0), c(i, null, ne(f.options, (e, t) => (g(), c("div", {
344
- key: e.value,
345
- class: m(["nb-select__option", {
346
- "nb-select__option--selected": G(e.value),
347
- "nb-select__option--highlighted": L.value === t,
348
- "nb-select__option--disabled": e.disabled
349
- }]),
350
- role: "option",
351
- "aria-selected": G(e.value),
352
- "aria-disabled": e.disabled || void 0,
353
- onMouseenter: (e) => L.value = t,
354
- onClick: (t) => K(e)
355
- }, [f.multiple ? (g(), c("span", le, [G(e.value) ? (g(), c("svg", ue, [...p[7] ||= [l("path", {
356
- d: "M1 4l3 3 5-6",
357
- stroke: "currentColor",
358
- "stroke-width": "1.5",
359
- "stroke-linecap": "round",
360
- "stroke-linejoin": "round"
361
- }, null, -1)]])) : s("", !0)])) : s("", !0), l("span", de, [v(a.$slots, "option", { option: e }, () => [u(y(e.label), 1)])])], 42, ce))), 128)),
362
- !f.options || f.options.length === 0 ? (g(), c("div", fe, " No options ")) : s("", !0),
363
- f.creatable ? (g(), c("div", {
364
- key: 1,
365
- class: "nb-select__create",
366
- onMousedown: p[6] ||= w(() => {}, ["prevent"])
367
- }, [ie(l("input", {
368
- "onUpdate:modelValue": p[4] ||= (e) => N.value = e,
369
- type: "text",
370
- class: "nb-select__create-input",
371
- placeholder: f.createPlaceholder || "Add new…",
372
- onKeydown: [ae(w(P, ["prevent"]), ["enter"]), p[5] ||= w(() => {}, ["stop"])]
373
- }, null, 40, pe), [[S, N.value]])], 32)) : s("", !0)
374
- ], 12, k)) : s("", !0)]))], 64));
375
- }
376
- });
377
- //#endregion
378
- export { A as t };
@@ -1 +0,0 @@
1
- var e=Symbol(`nb-tree`),t=Symbol(`nb-tree-depth`);Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return t}});
@@ -1,4 +0,0 @@
1
- //#region src/components/TreeContext.ts
2
- var e = Symbol("nb-tree"), t = Symbol("nb-tree-depth");
3
- //#endregion
4
- export { e as n, t };