@leaflink/stash 50.8.0 → 50.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Tab.js +1 -1
- package/dist/Tabs.js +2 -2
- package/dist/Tabs.vue_vue_type_script_setup_true_lang-NZm1OrRT.js +159 -0
- package/dist/Tabs.vue_vue_type_script_setup_true_lang-NZm1OrRT.js.map +1 -0
- package/dist/Textarea.js +16 -14
- package/dist/Textarea.js.map +1 -1
- package/dist/Textarea.vue.d.ts +10 -0
- package/package.json +1 -1
- package/dist/Tabs.vue_vue_type_script_setup_true_lang-l41hWkV4.js +0 -153
- package/dist/Tabs.vue_vue_type_script_setup_true_lang-l41hWkV4.js.map +0 -1
package/dist/Tab.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineComponent as x, useCssModule as T, inject as y, computed as r, onMounted as k, nextTick as g, toRefs as c, openBlock as u, createElementBlock as C, normalizeClass as P, unref as a, withKeys as $, createBlock as B, resolveDynamicComponent as E, mergeProps as N, withCtx as b, createElementVNode as A, createVNode as I, renderSlot as j } from "vue";
|
|
2
2
|
import M from "@leaflink/snitch";
|
|
3
3
|
import D from "./Badge.js";
|
|
4
|
-
import { T as L } from "./Tabs.vue_vue_type_script_setup_true_lang-
|
|
4
|
+
import { T as L } from "./Tabs.vue_vue_type_script_setup_true_lang-NZm1OrRT.js";
|
|
5
5
|
import { _ as V } from "./_plugin-vue_export-helper-CHgC5LLL.js";
|
|
6
6
|
const K = ["id", "aria-selected", "aria-controls", "aria-disabled"], O = { class: "tw-mt-0.5" }, S = /* @__PURE__ */ x({
|
|
7
7
|
__name: "Tab",
|
package/dist/Tabs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { _ as s } from "./Tabs.vue_vue_type_script_setup_true_lang-
|
|
2
|
-
import { T as c, a as f } from "./Tabs.vue_vue_type_script_setup_true_lang-
|
|
1
|
+
import { _ as s } from "./Tabs.vue_vue_type_script_setup_true_lang-NZm1OrRT.js";
|
|
2
|
+
import { T as c, a as f } from "./Tabs.vue_vue_type_script_setup_true_lang-NZm1OrRT.js";
|
|
3
3
|
import { _ as a } from "./_plugin-vue_export-helper-CHgC5LLL.js";
|
|
4
4
|
const t = {
|
|
5
5
|
"menu-tab": "_menu-tab_frbn6_2"
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { defineComponent as U, useCssModule as V, ref as s, computed as f, provide as q, onMounted as J, onUpdated as R, onDeactivated as F, onBeforeUnmount as H, openBlock as k, createElementBlock as K, createElementVNode as m, normalizeStyle as W, normalizeClass as I, renderSlot as A, createBlock as Y, withCtx as N, unref as h, createTextVNode as Z, toDisplayString as G, createVNode as P, createCommentVNode as Q } from "vue";
|
|
2
|
+
import X from "lodash-es/debounce";
|
|
3
|
+
import ee from "lodash-es/uniqueId";
|
|
4
|
+
import { DEBOUNCE as te } from "./constants.js";
|
|
5
|
+
import { t as oe } from "./locale.js";
|
|
6
|
+
import re from "./Dropdown.js";
|
|
7
|
+
import ae from "./Icon.js";
|
|
8
|
+
const se = Object.freeze({
|
|
9
|
+
key: Symbol("TABS_INJECTION_KEY")
|
|
10
|
+
});
|
|
11
|
+
var M = /* @__PURE__ */ ((i) => (i.Line = "line", i.Enclosed = "enclosed", i))(M || {});
|
|
12
|
+
const ie = {
|
|
13
|
+
class: "stash-tabs tw-relative",
|
|
14
|
+
role: "tabList",
|
|
15
|
+
"data-test": "stash-tabs"
|
|
16
|
+
}, ne = ["aria-controls", "aria-expanded", "onClick"], le = ["id"], fe = /* @__PURE__ */ U({
|
|
17
|
+
__name: "Tabs",
|
|
18
|
+
props: {
|
|
19
|
+
activeTab: {},
|
|
20
|
+
variant: { default: M.Line }
|
|
21
|
+
},
|
|
22
|
+
emits: ["update:activeTab"],
|
|
23
|
+
setup(i, { emit: O }) {
|
|
24
|
+
const B = O, d = i, D = V(), l = s(), c = s(), n = s(void 0), S = "IntersectionObserver" in window, a = s(/* @__PURE__ */ new Set()), g = s(0), E = s(), x = ee("more-dropdown-menu-"), u = s(!1), v = f({
|
|
25
|
+
get() {
|
|
26
|
+
return d.activeTab;
|
|
27
|
+
},
|
|
28
|
+
set(t) {
|
|
29
|
+
B("update:activeTab", t);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
function $(t) {
|
|
33
|
+
v.value = t;
|
|
34
|
+
}
|
|
35
|
+
q(se.key, {
|
|
36
|
+
activeTab: f(() => v.value),
|
|
37
|
+
variant: f(() => d.variant),
|
|
38
|
+
setActiveTab: $
|
|
39
|
+
});
|
|
40
|
+
function y() {
|
|
41
|
+
var p, L, T;
|
|
42
|
+
if (!S || !l.value)
|
|
43
|
+
return;
|
|
44
|
+
const t = Array.from((p = l.value) == null ? void 0 : p.children), _ = {
|
|
45
|
+
root: l.value,
|
|
46
|
+
rootMargin: "0px",
|
|
47
|
+
threshold: Array.from({ length: 100 }).map((e, o) => (o + 1) / 100)
|
|
48
|
+
};
|
|
49
|
+
if (n.value = new IntersectionObserver((e) => {
|
|
50
|
+
e.forEach((o) => {
|
|
51
|
+
const r = o.target.getAttribute("id");
|
|
52
|
+
o.intersectionRatio > 0.94 ? a.value.has(r) && a.value.delete(r) : r && !a.value.has(r) && a.value.add(r);
|
|
53
|
+
});
|
|
54
|
+
}, _), t.forEach((e) => {
|
|
55
|
+
var o;
|
|
56
|
+
(o = n.value) == null || o.observe(e), a.value.has(e.getAttribute("id")) ? e.classList.add("tw-invisible") : e.classList.remove("tw-invisible");
|
|
57
|
+
}), g.value = ((T = (L = E.value) == null ? void 0 : L.$el) == null ? void 0 : T.getBoundingClientRect().width) || 0, !c.value)
|
|
58
|
+
return;
|
|
59
|
+
Array.from(c.value.children).forEach((e) => {
|
|
60
|
+
var r;
|
|
61
|
+
const o = e.firstElementChild;
|
|
62
|
+
if (o.className = "", e.className = "", e.classList.add(
|
|
63
|
+
D["menu-tab"],
|
|
64
|
+
"tw-flex",
|
|
65
|
+
"tw-items-center",
|
|
66
|
+
"tw-justify-between",
|
|
67
|
+
"tw-rounded",
|
|
68
|
+
"tw-text-sm",
|
|
69
|
+
"tw-p-1.5",
|
|
70
|
+
"tw-text-left",
|
|
71
|
+
"tw-cursor-pointer",
|
|
72
|
+
"tw-text-ice-700",
|
|
73
|
+
"hover:!tw-bg-ice-200",
|
|
74
|
+
"aria-disabled:tw-text-ice-500",
|
|
75
|
+
"aria-disabled:tw-pointer-events-none",
|
|
76
|
+
"aria-disabled:hover:tw-text-ice-500",
|
|
77
|
+
"aria-disabled:hover:tw-bg-inherit",
|
|
78
|
+
"aria-disabled:hover:tw-cursor-default",
|
|
79
|
+
"aria-selected:tw-bg-blue-100"
|
|
80
|
+
), (r = e.querySelector(".stash-tabs__dropdown-selected-tab-icon")) == null || r.remove(), e.getAttribute("id") === `tab-${v.value}`) {
|
|
81
|
+
const b = document.createElement("span");
|
|
82
|
+
b.className = "stash-tabs__dropdown-selected-tab-icon", b.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" class="tw-text-blue-500 tw-w-6 tw-h-6" viewBox="0 0 24 24" fill="none"><path fill="currentColor" fill-rule="evenodd" d="M20.707 6.854 9 18.561l-5.707-5.707 1.414-1.414L9 15.733 19.293 5.44l1.414 1.414Z" clip-rule="evenodd"/></svg>', e.appendChild(b);
|
|
83
|
+
}
|
|
84
|
+
a.value.has(e.getAttribute("id")) ? e.classList.remove("tw-hidden") : e.classList.add("tw-hidden"), e.removeEventListener("click", () => {
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const z = X(y, te.FAST, { leading: !0 });
|
|
89
|
+
function w() {
|
|
90
|
+
n.value && (n.value.disconnect(), n.value = void 0);
|
|
91
|
+
}
|
|
92
|
+
J(() => {
|
|
93
|
+
y();
|
|
94
|
+
}), R(() => {
|
|
95
|
+
w(), z();
|
|
96
|
+
}), F(() => {
|
|
97
|
+
w();
|
|
98
|
+
}), H(() => {
|
|
99
|
+
w();
|
|
100
|
+
});
|
|
101
|
+
function j(t) {
|
|
102
|
+
t(), u.value = !u.value;
|
|
103
|
+
}
|
|
104
|
+
return (t, _) => (k(), K("div", ie, [
|
|
105
|
+
m("ul", {
|
|
106
|
+
ref_key: "tabListEl",
|
|
107
|
+
ref: l,
|
|
108
|
+
style: W({
|
|
109
|
+
width: `calc(100% - ${g.value}px)`
|
|
110
|
+
}),
|
|
111
|
+
class: I(["stash-tabs-list tw-flex tw-items-end", {
|
|
112
|
+
"stash-tabs-list--line": t.variant === "line",
|
|
113
|
+
"stash-tabs-list--enclosed": t.variant === "enclosed",
|
|
114
|
+
"tw-gap-6": t.variant === "line"
|
|
115
|
+
}])
|
|
116
|
+
}, [
|
|
117
|
+
A(t.$slots, "default"),
|
|
118
|
+
a.value.size ? (k(), Y(re, {
|
|
119
|
+
key: 0,
|
|
120
|
+
ref_key: "moreDropdownEl",
|
|
121
|
+
ref: E,
|
|
122
|
+
class: "!tw-absolute tw-right-0 tw-top-0"
|
|
123
|
+
}, {
|
|
124
|
+
toggle: N(({ toggle: C }) => [
|
|
125
|
+
m("button", {
|
|
126
|
+
"aria-haspopup": "menu",
|
|
127
|
+
"aria-controls": h(x),
|
|
128
|
+
"aria-expanded": u.value,
|
|
129
|
+
class: I(["tw-flex tw-cursor-pointer tw-items-center tw-justify-center tw-border-solid tw-px-6 tw-py-1.5 tw-text-sm tw-font-medium tw-text-blue-500 hover:tw-text-blue-700", { "tw-border-t-4 tw-border-transparent": d.variant === "enclosed" }]),
|
|
130
|
+
type: "button",
|
|
131
|
+
onClick: (p) => j(C)
|
|
132
|
+
}, [
|
|
133
|
+
Z(G(h(oe)("ll.more")) + " ", 1),
|
|
134
|
+
P(ae, { name: "caret-down" })
|
|
135
|
+
], 10, ne)
|
|
136
|
+
]),
|
|
137
|
+
default: N(() => [
|
|
138
|
+
m("ul", {
|
|
139
|
+
id: h(x),
|
|
140
|
+
ref_key: "moreDropdownMenuEl",
|
|
141
|
+
ref: c,
|
|
142
|
+
class: "tw-space-y-1.5 tw-px-1.5 tw-pb-1.5",
|
|
143
|
+
role: "menu"
|
|
144
|
+
}, [
|
|
145
|
+
A(t.$slots, "default")
|
|
146
|
+
], 8, le)
|
|
147
|
+
]),
|
|
148
|
+
_: 3
|
|
149
|
+
}, 512)) : Q("", !0)
|
|
150
|
+
], 6)
|
|
151
|
+
]));
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
export {
|
|
155
|
+
se as T,
|
|
156
|
+
fe as _,
|
|
157
|
+
M as a
|
|
158
|
+
};
|
|
159
|
+
//# sourceMappingURL=Tabs.vue_vue_type_script_setup_true_lang-NZm1OrRT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tabs.vue_vue_type_script_setup_true_lang-NZm1OrRT.js","sources":["../src/components/Tabs/keys.ts","../src/components/Tabs/models.ts","../src/components/Tabs/Tabs.vue"],"sourcesContent":["import { Injection } from '../../../types/utils';\nimport { TabsInjection } from './models';\n\nexport const TABS_INJECTION: Injection<TabsInjection> = Object.freeze({\n key: Symbol('TABS_INJECTION_KEY'),\n});\n","import { ComputedRef } from 'vue';\n\nexport enum TabVariant {\n Line = 'line',\n Enclosed = 'enclosed',\n}\n\nexport type TabVariants = `${TabVariant}`;\n\nexport interface TabsInjection {\n activeTab: ComputedRef<string>;\n variant: ComputedRef<TabVariants>;\n setActiveTab: (newTabValue: string) => void;\n}\n","<script lang=\"ts\">\n import { TabVariant, TabVariants } from './models';\n\n export * from './keys';\n export * from './models';\n\n export interface TabsProps {\n /**\n * The currently active tab value\n */\n activeTab: string;\n\n /**\n * Tabs variant\n */\n variant?: TabVariants;\n }\n</script>\n\n<script setup lang=\"ts\">\n import debounce from 'lodash-es/debounce';\n import uniqueId from 'lodash-es/uniqueId';\n import { computed, onBeforeUnmount, onDeactivated, onMounted, onUpdated, provide, Ref, ref, useCssModule } from 'vue';\n\n import { DEBOUNCE } from '../../constants';\n import { t } from '../../locale';\n import Dropdown from '../Dropdown/Dropdown.vue';\n import Icon from '../Icon/Icon.vue';\n import { TABS_INJECTION } from './keys';\n\n const emit = defineEmits<{\n (e: 'update:activeTab', newTabValue: TabsProps['activeTab']): void;\n }>();\n\n const props = withDefaults(defineProps<TabsProps>(), {\n variant: TabVariant.Line,\n });\n const classes = useCssModule();\n\n const tabListEl = ref();\n const moreDropdownMenuEl = ref();\n const observer: Ref<IntersectionObserver | undefined> = ref(undefined);\n const hasIntersectionObserver = 'IntersectionObserver' in window;\n const overflowIds = ref<Set<string>>(new Set());\n const moreDropdownWidth = ref(0);\n const moreDropdownEl = ref<InstanceType<typeof Dropdown>>();\n const moreMenuId = uniqueId('more-dropdown-menu-');\n const isMoreMenuOpen = ref(false);\n\n const currentActiveTab = computed({\n get() {\n return props.activeTab;\n },\n set(nv: TabsProps['activeTab']) {\n emit('update:activeTab', nv);\n },\n });\n\n function setActiveTab(newTabValue: TabsProps['activeTab']) {\n currentActiveTab.value = newTabValue;\n }\n\n provide(TABS_INJECTION.key, {\n activeTab: computed(() => currentActiveTab.value),\n variant: computed(() => props.variant),\n setActiveTab,\n });\n\n function initObserve() {\n if (!hasIntersectionObserver) {\n return;\n }\n\n if (!tabListEl.value) {\n return;\n }\n\n const tabs = Array.from(tabListEl.value?.children as HTMLLIElement[]);\n const options = {\n root: tabListEl.value,\n rootMargin: '0px',\n threshold: Array.from({ length: 100 }).map((v, i) => (i + 1) / 100),\n };\n\n observer.value = new IntersectionObserver((entries) => {\n entries.forEach((entry) => {\n const dataId = entry.target.getAttribute('id') as string;\n /**\n * Check for partial intersection.\n * Zooming out can result in ratio of approx 0.984\n * Anything higher will result in nav items disappearing\n */\n if (entry.intersectionRatio > 0.94) {\n // show tab, hide in dropdown\n if (overflowIds.value.has(dataId)) {\n overflowIds.value.delete(dataId);\n }\n } else {\n // hide tab, show in dropdown\n if (dataId && !overflowIds.value.has(dataId)) {\n overflowIds.value.add(dataId);\n }\n }\n });\n }, options);\n\n tabs.forEach((element) => {\n observer.value?.observe(element);\n if (overflowIds.value.has(element.getAttribute('id') as string)) {\n element.classList.add('tw-invisible');\n } else {\n element.classList.remove('tw-invisible');\n }\n });\n\n moreDropdownWidth.value = moreDropdownEl.value?.$el?.getBoundingClientRect().width || 0;\n\n if (!moreDropdownMenuEl.value) {\n return;\n }\n\n const dropdownList = Array.from(moreDropdownMenuEl.value.children as HTMLLIElement[]);\n dropdownList.forEach((element) => {\n const firstElementChild = element.firstElementChild as Element;\n firstElementChild.className = '';\n element.className = '';\n\n element.classList.add(\n classes['menu-tab'],\n 'tw-flex',\n 'tw-items-center',\n 'tw-justify-between',\n 'tw-rounded',\n 'tw-text-sm',\n 'tw-p-1.5',\n 'tw-text-left',\n 'tw-cursor-pointer',\n 'tw-text-ice-700',\n 'hover:!tw-bg-ice-200',\n 'aria-disabled:tw-text-ice-500',\n 'aria-disabled:tw-pointer-events-none',\n 'aria-disabled:hover:tw-text-ice-500',\n 'aria-disabled:hover:tw-bg-inherit',\n 'aria-disabled:hover:tw-cursor-default',\n 'aria-selected:tw-bg-blue-100',\n );\n\n element.querySelector('.stash-tabs__dropdown-selected-tab-icon')?.remove();\n\n if (element.getAttribute('id') === `tab-${currentActiveTab.value}`) {\n const span = document.createElement('span');\n span.className = 'stash-tabs__dropdown-selected-tab-icon';\n span.innerHTML = `<svg xmlns=\"http://www.w3.org/2000/svg\" class=\"tw-text-blue-500 tw-w-6 tw-h-6\" viewBox=\"0 0 24 24\" fill=\"none\"><path fill=\"currentColor\" fill-rule=\"evenodd\" d=\"M20.707 6.854 9 18.561l-5.707-5.707 1.414-1.414L9 15.733 19.293 5.44l1.414 1.414Z\" clip-rule=\"evenodd\"/></svg>`;\n element.appendChild(span);\n }\n\n if (!overflowIds.value.has(element.getAttribute('id') as string)) {\n element.classList.add('tw-hidden');\n } else {\n element.classList.remove('tw-hidden');\n }\n\n element.removeEventListener('click', () => {});\n });\n }\n\n const debouncedInitObserve = debounce(initObserve, DEBOUNCE.FAST, { leading: true });\n\n function destroyObserver() {\n if (observer.value) {\n observer.value.disconnect();\n observer.value = undefined;\n }\n }\n\n onMounted(() => {\n initObserve();\n });\n\n onUpdated(() => {\n destroyObserver();\n debouncedInitObserve();\n });\n\n onDeactivated(() => {\n destroyObserver();\n });\n\n onBeforeUnmount(() => {\n destroyObserver();\n });\n\n function onMoreClick(toggleMoreDropdown) {\n toggleMoreDropdown();\n isMoreMenuOpen.value = !isMoreMenuOpen.value;\n }\n</script>\n\n<template>\n <div class=\"stash-tabs tw-relative\" role=\"tabList\" data-test=\"stash-tabs\">\n <ul\n ref=\"tabListEl\"\n :style=\"{\n width: `calc(100% - ${moreDropdownWidth}px)`,\n }\"\n class=\"stash-tabs-list tw-flex tw-items-end\"\n :class=\"{\n 'stash-tabs-list--line': variant === 'line',\n 'stash-tabs-list--enclosed': variant === 'enclosed',\n 'tw-gap-6': variant === 'line',\n }\"\n >\n <slot></slot>\n\n <Dropdown v-if=\"overflowIds.size\" ref=\"moreDropdownEl\" class=\"!tw-absolute tw-right-0 tw-top-0\">\n <template #toggle=\"{ toggle }\">\n <button\n aria-haspopup=\"menu\"\n :aria-controls=\"moreMenuId\"\n :aria-expanded=\"isMoreMenuOpen\"\n class=\"tw-flex tw-cursor-pointer tw-items-center tw-justify-center tw-border-solid tw-px-6 tw-py-1.5 tw-text-sm tw-font-medium tw-text-blue-500 hover:tw-text-blue-700\"\n :class=\"{ 'tw-border-t-4 tw-border-transparent': props.variant === 'enclosed' }\"\n type=\"button\"\n @click=\"onMoreClick(toggle)\"\n >\n {{ t('ll.more') }}\n <Icon name=\"caret-down\" />\n </button>\n </template>\n <template #default>\n <ul :id=\"moreMenuId\" ref=\"moreDropdownMenuEl\" class=\"tw-space-y-1.5 tw-px-1.5 tw-pb-1.5\" role=\"menu\">\n <slot></slot>\n </ul>\n </template>\n </Dropdown>\n </ul>\n </div>\n</template>\n\n<style module>\n .menu-tab > a {\n /* prevents the global link styles to overwrite the overflowed tab styles */\n &,\n &:hover,\n &:focus {\n color: inherit;\n }\n }\n</style>\n"],"names":["TABS_INJECTION","TabVariant","emit","__emit","props","__props","classes","useCssModule","tabListEl","ref","moreDropdownMenuEl","observer","hasIntersectionObserver","overflowIds","moreDropdownWidth","moreDropdownEl","moreMenuId","uniqueId","isMoreMenuOpen","currentActiveTab","computed","nv","setActiveTab","newTabValue","provide","initObserve","tabs","_a","options","v","i","entries","entry","dataId","element","_c","_b","firstElementChild","span","debouncedInitObserve","debounce","DEBOUNCE","destroyObserver","onMounted","onUpdated","onDeactivated","onBeforeUnmount","onMoreClick","toggleMoreDropdown"],"mappings":";;;;;;;AAGa,MAAAA,KAA2C,OAAO,OAAO;AAAA,EACpE,KAAK,OAAO,oBAAoB;AAClC,CAAC;ACHW,IAAAC,sBAAAA,OACVA,EAAA,OAAO,QACPA,EAAA,WAAW,YAFDA,IAAAA,KAAA,CAAA,CAAA;;;;;;;;;;;;;AC4BV,UAAMC,IAAOC,GAIPC,IAAQC,GAGRC,IAAUC,EAAa,GAEvBC,IAAYC,EAAI,GAChBC,IAAqBD,EAAI,GACzBE,IAAkDF,EAAI,MAAS,GAC/DG,IAA0B,0BAA0B,QACpDC,IAAcJ,EAAqB,oBAAA,KAAK,GACxCK,IAAoBL,EAAI,CAAC,GACzBM,IAAiBN,EAAmC,GACpDO,IAAaC,GAAS,qBAAqB,GAC3CC,IAAiBT,EAAI,EAAK,GAE1BU,IAAmBC,EAAS;AAAA,MAChC,MAAM;AACJ,eAAOhB,EAAM;AAAA,MACf;AAAA,MACA,IAAIiB,GAA4B;AAC9B,QAAAnB,EAAK,oBAAoBmB,CAAE;AAAA,MAAA;AAAA,IAC7B,CACD;AAED,aAASC,EAAaC,GAAqC;AACzD,MAAAJ,EAAiB,QAAQI;AAAA,IAAA;AAG3B,IAAAC,EAAQxB,GAAe,KAAK;AAAA,MAC1B,WAAWoB,EAAS,MAAMD,EAAiB,KAAK;AAAA,MAChD,SAASC,EAAS,MAAMhB,EAAM,OAAO;AAAA,MACrC,cAAAkB;AAAA,IAAA,CACD;AAED,aAASG,IAAc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 @@
|
|
|
1
|
-
import { defineComponent as E, useAttrs as M, useSlots as k, useCssModule as H, ref as
|
|
1
|
+
import { defineComponent as E, useAttrs as M, useSlots as k, useCssModule as H, ref as x, computed as w, watch as A, onMounted as I, nextTick as P, onBeforeUnmount as V, openBlock as $, createBlock as q, mergeProps as y, unref as p, createSlots as D, withCtx as b, createElementVNode as j, renderSlot as F } from "vue";
|
|
2
2
|
import { _ as L } from "./Field.vue_vue_type_script_setup_true_lang-DEizIcDo.js";
|
|
3
3
|
import { _ as N } from "./_plugin-vue_export-helper-CHgC5LLL.js";
|
|
4
|
-
const U = ["id", "value", "placeholder", "disabled", "readonly", "rows"], W = /* @__PURE__ */ E({
|
|
4
|
+
const U = ["id", "maxlength", "value", "placeholder", "disabled", "readonly", "rows"], W = /* @__PURE__ */ E({
|
|
5
5
|
name: "ll-textarea",
|
|
6
6
|
__name: "Textarea",
|
|
7
7
|
props: {
|
|
@@ -9,7 +9,8 @@ const U = ["id", "value", "placeholder", "disabled", "readonly", "rows"], W = /*
|
|
|
9
9
|
value: { default: null },
|
|
10
10
|
resize: { type: [Boolean, Object], default: !1 },
|
|
11
11
|
placeholder: { default: void 0 },
|
|
12
|
-
rows: {},
|
|
12
|
+
rows: { default: void 0 },
|
|
13
|
+
maxlength: { default: void 0 },
|
|
13
14
|
addBottomSpace: { type: Boolean },
|
|
14
15
|
errorText: {},
|
|
15
16
|
hintText: {},
|
|
@@ -25,7 +26,7 @@ const U = ["id", "value", "placeholder", "disabled", "readonly", "rows"], W = /*
|
|
|
25
26
|
},
|
|
26
27
|
emits: ["update:model-value"],
|
|
27
28
|
setup(_, { emit: g }) {
|
|
28
|
-
const c = M(), B = k(), m = H(), t = _, z = g, u =
|
|
29
|
+
const c = M(), B = k(), m = H(), t = _, z = g, u = x(), r = x(), R = w(() => t.isReadOnly || "readonly" in c && c.readonly !== !1), T = w(() => {
|
|
29
30
|
const e = { ...c };
|
|
30
31
|
return delete e["data-test"], delete e.class, e;
|
|
31
32
|
});
|
|
@@ -33,26 +34,26 @@ const U = ["id", "value", "placeholder", "disabled", "readonly", "rows"], W = /*
|
|
|
33
34
|
() => t.resize,
|
|
34
35
|
(e) => {
|
|
35
36
|
var o;
|
|
36
|
-
e ? h() : (o =
|
|
37
|
+
e ? h() : (o = r.value) == null || o.disconnect();
|
|
37
38
|
}
|
|
38
39
|
);
|
|
39
40
|
const O = (e) => {
|
|
40
41
|
z("update:model-value", e.target.value);
|
|
41
42
|
}, h = () => {
|
|
42
|
-
|
|
43
|
+
r.value || !u.value || (r.value = new ResizeObserver(([e]) => {
|
|
43
44
|
const { target: o } = e, s = v(u.value) || document.documentElement, { scrollTop: a } = s;
|
|
44
45
|
let n = 0;
|
|
45
46
|
if (s === document.documentElement) {
|
|
46
|
-
const { top:
|
|
47
|
-
n = Math.max(
|
|
47
|
+
const { top: l, height: i } = C(o), { innerHeight: d } = window;
|
|
48
|
+
n = Math.max(l + i - (d + a), 0);
|
|
48
49
|
} else {
|
|
49
|
-
const { top:
|
|
50
|
+
const { top: l, height: i } = o.getBoundingClientRect(), { top: d } = s.getBoundingClientRect(), { offsetHeight: f } = s, S = l - d;
|
|
50
51
|
n = Math.max(S + i - f, 0);
|
|
51
52
|
}
|
|
52
53
|
n && requestAnimationFrame(() => {
|
|
53
54
|
s.scrollTop = a + n;
|
|
54
55
|
});
|
|
55
|
-
}),
|
|
56
|
+
}), r.value.observe(u.value));
|
|
56
57
|
}, v = (e) => {
|
|
57
58
|
const o = e.parentElement;
|
|
58
59
|
if (!o)
|
|
@@ -62,10 +63,10 @@ const U = ["id", "value", "placeholder", "disabled", "readonly", "rows"], W = /*
|
|
|
62
63
|
}, C = (e) => {
|
|
63
64
|
const { offsetWidth: o, offsetHeight: s } = e;
|
|
64
65
|
let a = 0, n = 0;
|
|
65
|
-
const
|
|
66
|
-
a += i, n += d, f &&
|
|
66
|
+
const l = function({ offsetLeft: i, offsetTop: d, offsetParent: f }) {
|
|
67
|
+
a += i, n += d, f && l(f);
|
|
67
68
|
};
|
|
68
|
-
return
|
|
69
|
+
return l(e), {
|
|
69
70
|
top: n,
|
|
70
71
|
left: a,
|
|
71
72
|
width: o,
|
|
@@ -81,7 +82,7 @@ const U = ["id", "value", "placeholder", "disabled", "readonly", "rows"], W = /*
|
|
|
81
82
|
(typeof t.resize == "boolean" && t.resize || (e = t.resize) != null && e.forceBrowserScroll) && (await P(), h());
|
|
82
83
|
}), V(() => {
|
|
83
84
|
var e;
|
|
84
|
-
(e =
|
|
85
|
+
(e = r.value) == null || e.disconnect();
|
|
85
86
|
}), (e, o) => ($(), q(L, y(t, {
|
|
86
87
|
class: ["stash-textarea", [p(m).root]],
|
|
87
88
|
"data-test": "stash-textarea"
|
|
@@ -102,6 +103,7 @@ const U = ["id", "value", "placeholder", "disabled", "readonly", "rows"], W = /*
|
|
|
102
103
|
"tw-resize-none": !t.resize
|
|
103
104
|
}
|
|
104
105
|
],
|
|
106
|
+
maxlength: t.maxlength,
|
|
105
107
|
value: t.modelValue,
|
|
106
108
|
"data-test": "stash-textarea|textarea",
|
|
107
109
|
placeholder: t.placeholder
|
package/dist/Textarea.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Textarea.js","sources":["../src/components/Textarea/Textarea.vue"],"sourcesContent":["<script lang=\"ts\" setup>\n import { computed, nextTick, onBeforeUnmount, onMounted, ref, useAttrs, useCssModule, useSlots, watch } from 'vue';\n\n import { FieldProps } from '../Field/Field.types';\n import Field from '../Field/Field.vue';\n\n export interface TextareaResizeOptions {\n /**\n * It will automatically scroll the page down when it reaches the bottom of the viewport/element\n */\n forceBrowserScroll: boolean;\n }\n\n export interface TextAreaProps extends FieldProps {\n /**\n * Value for the textarea element.\n */\n modelValue?: string;\n\n /**\n * Deprecated. Use :model-value or v-model instead of :value.\n * @deprecated Use :model-value or v-model instead of :value.\n */\n value?: string | number | null;\n\n /**\n * Allow textarea to be resizable vertically.\n * Alternatively if you want to disable automatic scroll when resizing, you can set `{ forceBrowserScroll: false }`\n */\n resize?: boolean | TextareaResizeOptions;\n\n /**\n * Placeholder text for the textarea element.\n * **Note:** placeholders should be used to display examples; they should not be used as labels because they are not accessible as labels. If a real label cannot be used, use the `aria-label` attribute.\n */\n placeholder?: string;\n\n /**\n * Number of rows to display in the textarea.\n */\n rows?: number;\n }\n\n defineOptions({\n name: 'll-textarea',\n });\n\n const attrs = useAttrs();\n const slots = useSlots();\n const classes = useCssModule();\n\n const props = withDefaults(defineProps<TextAreaProps>(), {\n modelValue: '',\n value: null,\n resize: false,\n placeholder: undefined,\n });\n\n const emits = defineEmits<{\n /**\n * Emitted when the model value changes.\n */\n (e: 'update:model-value', value: string): void;\n }>();\n\n const textareaRef = ref<HTMLTextAreaElement>();\n const observer = ref<ResizeObserver>();\n const isReadOnly = computed(() => props.isReadOnly || ('readonly' in attrs && attrs.readonly !== false));\n\n const inputAttrs = computed(() => {\n const allAttrs = { ...attrs };\n\n delete allAttrs['data-test'];\n delete allAttrs.class;\n\n return allAttrs;\n });\n\n watch(\n () => props.resize,\n (v) => {\n v ? setupResizeObserver() : observer.value?.disconnect();\n },\n );\n\n const onInput = (event: Event) => {\n emits('update:model-value', (event.target as HTMLTextAreaElement).value);\n };\n\n const setupResizeObserver = () => {\n if (observer.value || !textareaRef.value) {\n return;\n }\n\n // the ResizeObserver will be in charge to detect if page needs to scroll when resizing the component\n observer.value = new ResizeObserver(([entry]) => {\n const { target } = entry;\n const parent = findParentScrollable(textareaRef.value as HTMLTextAreaElement) || document.documentElement;\n\n const { scrollTop: scrollPosition } = parent;\n let offsetDiff = 0;\n\n // checks if the closest parent element scrollable is the document page\n if (parent === document.documentElement) {\n const { top, height } = getOffsetClipRect(target as HTMLElement);\n const { innerHeight: viewportHeight } = window;\n\n offsetDiff = Math.max(top + height - (viewportHeight + scrollPosition), 0);\n } else {\n const { top, height } = (target as HTMLElement).getBoundingClientRect();\n const { top: parentTop } = parent.getBoundingClientRect();\n const { offsetHeight: parentHeight } = parent;\n const offsetTop = top - parentTop;\n\n offsetDiff = Math.max(offsetTop + height - parentHeight, 0);\n }\n\n if (offsetDiff) {\n requestAnimationFrame(() => {\n parent.scrollTop = scrollPosition + offsetDiff;\n });\n }\n });\n\n observer.value.observe(textareaRef.value);\n };\n\n /**\n * Retrieve the closest parent that has a scroll. Defaults to the document page.\n */\n const findParentScrollable = (el: HTMLElement): HTMLElement | null => {\n const parent = el.parentElement as HTMLElement;\n if (!parent) {\n return null;\n }\n\n const { overflowY } = getComputedStyle(parent);\n if (overflowY !== 'visible') {\n return parent;\n }\n\n if (parent === document.body) {\n return document.documentElement;\n }\n\n return findParentScrollable(parent);\n };\n\n /**\n * Retrieve element absolute positioning relative to the page.\n */\n const getOffsetClipRect = (el: HTMLElement) => {\n const { offsetWidth: width, offsetHeight: height } = el;\n\n let left = 0;\n let top = 0;\n\n const findPos = function ({ offsetLeft, offsetTop, offsetParent }: HTMLElement) {\n left += offsetLeft;\n top += offsetTop;\n\n if (offsetParent) {\n findPos(offsetParent as HTMLElement);\n }\n };\n\n findPos(el);\n\n return {\n top,\n left,\n width,\n height,\n };\n };\n\n onMounted(async () => {\n if (props.value !== null) {\n throw new Error('ll-input: use :model-value or v-model instead of :value.');\n }\n\n if (attrs.onInput) {\n throw new Error('ll-input: use the @update:model-value event instead of @input');\n }\n\n if (\n (typeof props.resize === 'boolean' && props.resize) ||\n (props.resize as TextareaResizeOptions)?.forceBrowserScroll\n ) {\n await nextTick();\n setupResizeObserver();\n }\n });\n\n onBeforeUnmount(() => {\n observer.value?.disconnect();\n });\n</script>\n\n<template>\n <Field v-bind=\"props\" class=\"stash-textarea\" :class=\"[classes.root]\" data-test=\"stash-textarea\">\n <template #default=\"{ fieldId, hasError }\">\n <textarea\n :id=\"fieldId\"\n ref=\"textareaRef\"\n :class=\"[\n classes.textarea,\n 'tw-border tw-border-ice-500',\n {\n 'stash-textarea--error tw-border-red-500 tw-text-red-500': hasError,\n 'tw-text-ice-700 hover:tw-border-ice-500 focus:tw-border-blue-500 active:tw-border-blue-500':\n !hasError && !props.disabled,\n 'tw-resize-y': props.resize,\n 'tw-min-h-[100px]': !props.rows,\n 'tw-resize-none': !props.resize,\n },\n ]\"\n :value=\"props.modelValue\"\n data-test=\"stash-textarea|textarea\"\n :placeholder=\"props.placeholder\"\n v-bind=\"inputAttrs\"\n :disabled=\"props.disabled\"\n :readonly=\"isReadOnly\"\n :rows=\"props.rows\"\n @input=\"onInput\"\n ></textarea>\n </template>\n <template v-if=\"slots.hint\" #hint>\n <!-- @slot Hint content -->\n <slot name=\"hint\"></slot>\n </template>\n </Field>\n</template>\n\n<style module>\n .root {\n position: relative;\n width: 100%;\n }\n\n .textarea {\n background: var(--color-white);\n border-radius: theme('borderRadius.DEFAULT');\n display: block;\n outline: none;\n padding: theme('spacing[1.5]');\n width: 100%;\n\n &::placeholder {\n color: var(--color-ice-500);\n opacity: 1;\n }\n\n &[disabled] {\n background-color: var(--color-ice-100);\n border-color: var(--color-ice-500);\n color: var(--color-ice-500);\n pointer-events: none;\n }\n\n &[disabled]:active,\n &[disabled]:focus {\n box-shadow: none;\n }\n\n &[disabled]::placeholder {\n text-transform: none;\n color: var(--color-ice-500);\n }\n\n &[readonly] {\n border-color: transparent;\n background-color: transparent;\n padding-left: 0;\n padding-right: 0;\n min-height: unset;\n }\n }\n</style>\n"],"names":["attrs","useAttrs","slots","useSlots","classes","useCssModule","props","__props","emits","__emit","textareaRef","ref","observer","isReadOnly","computed","inputAttrs","allAttrs","watch","v","setupResizeObserver","_a","onInput","event","entry","target","parent","findParentScrollable","scrollPosition","offsetDiff","top","height","getOffsetClipRect","viewportHeight","parentTop","parentHeight","offsetTop","el","overflowY","width","left","findPos","offsetLeft","offsetParent","onMounted","nextTick","onBeforeUnmount"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CE,UAAMA,IAAQC,EAAS,GACjBC,IAAQC,EAAS,GACjBC,IAAUC,EAAa,GAEvBC,IAAQC,GAORC,IAAQC,GAORC,IAAcC,EA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"ts\" setup>\n import { computed, nextTick, onBeforeUnmount, onMounted, ref, useAttrs, useCssModule, useSlots, watch } from 'vue';\n\n import { FieldProps } from '../Field/Field.types';\n import Field from '../Field/Field.vue';\n\n export interface TextareaResizeOptions {\n /**\n * It will automatically scroll the page down when it reaches the bottom of the viewport/element\n */\n forceBrowserScroll: boolean;\n }\n\n export interface TextAreaProps extends FieldProps {\n /**\n * Value for the textarea element.\n */\n modelValue?: string;\n\n /**\n * Deprecated. Use :model-value or v-model instead of :value.\n * @deprecated Use :model-value or v-model instead of :value.\n */\n value?: string | number | null;\n\n /**\n * Allow textarea to be resizable vertically.\n * Alternatively if you want to disable automatic scroll when resizing, you can set `{ forceBrowserScroll: false }`\n */\n resize?: boolean | TextareaResizeOptions;\n\n /**\n * Placeholder text for the textarea element.\n * **Note:** placeholders should be used to display examples; they should not be used as labels because they are not accessible as labels. If a real label cannot be used, use the `aria-label` attribute.\n */\n placeholder?: string;\n\n /**\n * Number of rows to display in the textarea.\n */\n rows?: number;\n\n /**\n * Maximum number of characters allowed in the textarea.\n */\n maxlength?: number;\n }\n\n defineOptions({\n name: 'll-textarea',\n });\n\n const attrs = useAttrs();\n const slots = useSlots();\n const classes = useCssModule();\n\n const props = withDefaults(defineProps<TextAreaProps>(), {\n modelValue: '',\n value: null,\n resize: false,\n maxlength: undefined,\n rows: undefined,\n placeholder: undefined,\n });\n\n const emits = defineEmits<{\n /**\n * Emitted when the model value changes.\n */\n (e: 'update:model-value', value: string): void;\n }>();\n\n const textareaRef = ref<HTMLTextAreaElement>();\n const observer = ref<ResizeObserver>();\n const isReadOnly = computed(() => props.isReadOnly || ('readonly' in attrs && attrs.readonly !== false));\n\n const inputAttrs = computed(() => {\n const allAttrs = { ...attrs };\n\n delete allAttrs['data-test'];\n delete allAttrs.class;\n\n return allAttrs;\n });\n\n watch(\n () => props.resize,\n (v) => {\n v ? setupResizeObserver() : observer.value?.disconnect();\n },\n );\n\n const onInput = (event: Event) => {\n emits('update:model-value', (event.target as HTMLTextAreaElement).value);\n };\n\n const setupResizeObserver = () => {\n if (observer.value || !textareaRef.value) {\n return;\n }\n\n // the ResizeObserver will be in charge to detect if page needs to scroll when resizing the component\n observer.value = new ResizeObserver(([entry]) => {\n const { target } = entry;\n const parent = findParentScrollable(textareaRef.value as HTMLTextAreaElement) || document.documentElement;\n\n const { scrollTop: scrollPosition } = parent;\n let offsetDiff = 0;\n\n // checks if the closest parent element scrollable is the document page\n if (parent === document.documentElement) {\n const { top, height } = getOffsetClipRect(target as HTMLElement);\n const { innerHeight: viewportHeight } = window;\n\n offsetDiff = Math.max(top + height - (viewportHeight + scrollPosition), 0);\n } else {\n const { top, height } = (target as HTMLElement).getBoundingClientRect();\n const { top: parentTop } = parent.getBoundingClientRect();\n const { offsetHeight: parentHeight } = parent;\n const offsetTop = top - parentTop;\n\n offsetDiff = Math.max(offsetTop + height - parentHeight, 0);\n }\n\n if (offsetDiff) {\n requestAnimationFrame(() => {\n parent.scrollTop = scrollPosition + offsetDiff;\n });\n }\n });\n\n observer.value.observe(textareaRef.value);\n };\n\n /**\n * Retrieve the closest parent that has a scroll. Defaults to the document page.\n */\n const findParentScrollable = (el: HTMLElement): HTMLElement | null => {\n const parent = el.parentElement as HTMLElement;\n if (!parent) {\n return null;\n }\n\n const { overflowY } = getComputedStyle(parent);\n if (overflowY !== 'visible') {\n return parent;\n }\n\n if (parent === document.body) {\n return document.documentElement;\n }\n\n return findParentScrollable(parent);\n };\n\n /**\n * Retrieve element absolute positioning relative to the page.\n */\n const getOffsetClipRect = (el: HTMLElement) => {\n const { offsetWidth: width, offsetHeight: height } = el;\n\n let left = 0;\n let top = 0;\n\n const findPos = function ({ offsetLeft, offsetTop, offsetParent }: HTMLElement) {\n left += offsetLeft;\n top += offsetTop;\n\n if (offsetParent) {\n findPos(offsetParent as HTMLElement);\n }\n };\n\n findPos(el);\n\n return {\n top,\n left,\n width,\n height,\n };\n };\n\n onMounted(async () => {\n if (props.value !== null) {\n throw new Error('ll-input: use :model-value or v-model instead of :value.');\n }\n\n if (attrs.onInput) {\n throw new Error('ll-input: use the @update:model-value event instead of @input');\n }\n\n if (\n (typeof props.resize === 'boolean' && props.resize) ||\n (props.resize as TextareaResizeOptions)?.forceBrowserScroll\n ) {\n await nextTick();\n setupResizeObserver();\n }\n });\n\n onBeforeUnmount(() => {\n observer.value?.disconnect();\n });\n</script>\n\n<template>\n <Field v-bind=\"props\" class=\"stash-textarea\" :class=\"[classes.root]\" data-test=\"stash-textarea\">\n <template #default=\"{ fieldId, hasError }\">\n <textarea\n :id=\"fieldId\"\n ref=\"textareaRef\"\n :class=\"[\n classes.textarea,\n 'tw-border tw-border-ice-500',\n {\n 'stash-textarea--error tw-border-red-500 tw-text-red-500': hasError,\n 'tw-text-ice-700 hover:tw-border-ice-500 focus:tw-border-blue-500 active:tw-border-blue-500':\n !hasError && !props.disabled,\n 'tw-resize-y': props.resize,\n 'tw-min-h-[100px]': !props.rows,\n 'tw-resize-none': !props.resize,\n },\n ]\"\n :maxlength=\"props.maxlength\"\n :value=\"props.modelValue\"\n data-test=\"stash-textarea|textarea\"\n :placeholder=\"props.placeholder\"\n v-bind=\"inputAttrs\"\n :disabled=\"props.disabled\"\n :readonly=\"isReadOnly\"\n :rows=\"props.rows\"\n @input=\"onInput\"\n ></textarea>\n </template>\n <template v-if=\"slots.hint\" #hint>\n <!-- @slot Hint content -->\n <slot name=\"hint\"></slot>\n </template>\n </Field>\n</template>\n\n<style module>\n .root {\n position: relative;\n width: 100%;\n }\n\n .textarea {\n background: var(--color-white);\n border-radius: theme('borderRadius.DEFAULT');\n display: block;\n outline: none;\n padding: theme('spacing[1.5]');\n width: 100%;\n\n &::placeholder {\n color: var(--color-ice-500);\n opacity: 1;\n }\n\n &[disabled] {\n background-color: var(--color-ice-100);\n border-color: var(--color-ice-500);\n color: var(--color-ice-500);\n pointer-events: none;\n }\n\n &[disabled]:active,\n &[disabled]:focus {\n box-shadow: none;\n }\n\n &[disabled]::placeholder {\n text-transform: none;\n color: var(--color-ice-500);\n }\n\n &[readonly] {\n border-color: transparent;\n background-color: transparent;\n padding-left: 0;\n padding-right: 0;\n min-height: unset;\n }\n }\n</style>\n"],"names":["attrs","useAttrs","slots","useSlots","classes","useCssModule","props","__props","emits","__emit","textareaRef","ref","observer","isReadOnly","computed","inputAttrs","allAttrs","watch","v","setupResizeObserver","_a","onInput","event","entry","target","parent","findParentScrollable","scrollPosition","offsetDiff","top","height","getOffsetClipRect","viewportHeight","parentTop","parentHeight","offsetTop","el","overflowY","width","left","findPos","offsetLeft","offsetParent","onMounted","nextTick","onBeforeUnmount"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDE,UAAMA,IAAQC,EAAS,GACjBC,IAAQC,EAAS,GACjBC,IAAUC,EAAa,GAEvBC,IAAQC,GASRC,IAAQC,GAORC,IAAcC,EAAyB,GACvCC,IAAWD,EAAoB,GAC/BE,IAAaC,EAAS,MAAMR,EAAM,cAAe,cAAcN,KAASA,EAAM,aAAa,EAAM,GAEjGe,IAAaD,EAAS,MAAM;AAC1B,YAAAE,IAAW,EAAE,GAAGhB,EAAM;AAE5B,oBAAOgB,EAAS,WAAW,GAC3B,OAAOA,EAAS,OAETA;AAAA,IAAA,CACR;AAED,IAAAC;AAAA,MACE,MAAMX,EAAM;AAAA,MACZ,CAACY,MAAM;;AACL,QAAAA,IAAIC,EAAoB,KAAIC,IAAAR,EAAS,UAAT,QAAAQ,EAAgB;AAAA,MAAW;AAAA,IAE3D;AAEM,UAAAC,IAAU,CAACC,MAAiB;AAC1B,MAAAd,EAAA,sBAAuBc,EAAM,OAA+B,KAAK;AAAA,IACzE,GAEMH,IAAsB,MAAM;AAChC,MAAIP,EAAS,SAAS,CAACF,EAAY,UAKnCE,EAAS,QAAQ,IAAI,eAAe,CAAC,CAACW,CAAK,MAAM;AACzC,cAAA,EAAE,QAAAC,MAAWD,GACbE,IAASC,EAAqBhB,EAAY,KAA4B,KAAK,SAAS,iBAEpF,EAAE,WAAWiB,E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AA,MACF;AAAA,IACF;AAEA,WAAAa,EAAU,YAAY;;AAChB,UAAArC,EAAM,UAAU;AACZ,cAAA,IAAI,MAAM,0DAA0D;AAG5E,UAAIN,EAAM;AACF,cAAA,IAAI,MAAM,+DAA+D;AAI9E,OAAA,OAAOM,EAAM,UAAW,aAAaA,EAAM,WAC3Cc,IAAAd,EAAM,WAAN,QAAAc,EAAwC,wBAEzC,MAAMwB,EAAS,GACKzB,EAAA;AAAA,IACtB,CACD,GAED0B,EAAgB,MAAM;;AACpB,OAAAzB,IAAAR,EAAS,UAAT,QAAAQ,EAAgB;AAAA,IAAW,CAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/Textarea.vue.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ declare const _default: __VLS_WithTemplateSlots<DefineComponent<ExtractPropTypes
|
|
|
36
36
|
modelValue: string;
|
|
37
37
|
value: null;
|
|
38
38
|
resize: boolean;
|
|
39
|
+
maxlength: undefined;
|
|
40
|
+
rows: undefined;
|
|
39
41
|
placeholder: undefined;
|
|
40
42
|
}>>, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
|
|
41
43
|
"update:model-value": (value: string) => void;
|
|
@@ -43,6 +45,8 @@ placeholder: undefined;
|
|
|
43
45
|
modelValue: string;
|
|
44
46
|
value: null;
|
|
45
47
|
resize: boolean;
|
|
48
|
+
maxlength: undefined;
|
|
49
|
+
rows: undefined;
|
|
46
50
|
placeholder: undefined;
|
|
47
51
|
}>>> & Readonly<{
|
|
48
52
|
"onUpdate:model-value"?: ((value: string) => any) | undefined;
|
|
@@ -51,6 +55,8 @@ resize: boolean | TextareaResizeOptions;
|
|
|
51
55
|
placeholder: string;
|
|
52
56
|
modelValue: string;
|
|
53
57
|
value: string | number | null;
|
|
58
|
+
maxlength: number;
|
|
59
|
+
rows: number;
|
|
54
60
|
}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>, {
|
|
55
61
|
hint?(_: {}): any;
|
|
56
62
|
}>;
|
|
@@ -133,6 +139,10 @@ export declare interface TextAreaProps extends FieldProps {
|
|
|
133
139
|
* Number of rows to display in the textarea.
|
|
134
140
|
*/
|
|
135
141
|
rows?: number;
|
|
142
|
+
/**
|
|
143
|
+
* Maximum number of characters allowed in the textarea.
|
|
144
|
+
*/
|
|
145
|
+
maxlength?: number;
|
|
136
146
|
}
|
|
137
147
|
|
|
138
148
|
export declare interface TextareaResizeOptions {
|
package/package.json
CHANGED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { defineComponent as U, useCssModule as V, ref as a, computed as b, provide as j, onMounted as J, onUpdated as R, onDeactivated as q, onBeforeUnmount as F, openBlock as k, createElementBlock as K, createElementVNode as p, normalizeStyle as W, normalizeClass as I, renderSlot as L, createBlock as Y, withCtx as A, unref as f, createTextVNode as G, toDisplayString as H, createVNode as P, createCommentVNode as Q } from "vue";
|
|
2
|
-
import X from "lodash-es/debounce";
|
|
3
|
-
import Z from "lodash-es/uniqueId";
|
|
4
|
-
import { DEBOUNCE as ee } from "./constants.js";
|
|
5
|
-
import { t as te } from "./locale.js";
|
|
6
|
-
import oe from "./Dropdown.js";
|
|
7
|
-
import re from "./Icon.js";
|
|
8
|
-
const ae = Object.freeze({
|
|
9
|
-
key: Symbol("TABS_INJECTION_KEY")
|
|
10
|
-
});
|
|
11
|
-
var N = /* @__PURE__ */ ((s) => (s.Line = "line", s.Enclosed = "enclosed", s))(N || {});
|
|
12
|
-
const se = {
|
|
13
|
-
class: "stash-tabs tw-relative",
|
|
14
|
-
role: "tabList",
|
|
15
|
-
"data-test": "stash-tabs"
|
|
16
|
-
}, ie = ["aria-controls", "aria-expanded", "onClick"], ne = ["id"], pe = /* @__PURE__ */ U({
|
|
17
|
-
__name: "Tabs",
|
|
18
|
-
props: {
|
|
19
|
-
activeTab: {},
|
|
20
|
-
variant: { default: N.Line }
|
|
21
|
-
},
|
|
22
|
-
emits: ["update:activeTab"],
|
|
23
|
-
setup(s, { emit: O }) {
|
|
24
|
-
const D = O, d = s, M = V(), l = a(), c = a(), i = a(void 0), B = "IntersectionObserver" in window, r = a(/* @__PURE__ */ new Set()), m = a(0), h = a(), E = Z("more-dropdown-menu-"), u = a(!1), g = b({
|
|
25
|
-
get() {
|
|
26
|
-
return d.activeTab;
|
|
27
|
-
},
|
|
28
|
-
set(t) {
|
|
29
|
-
D("update:activeTab", t);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
function S(t) {
|
|
33
|
-
g.value = t;
|
|
34
|
-
}
|
|
35
|
-
j(ae.key, {
|
|
36
|
-
activeTab: b(() => g.value),
|
|
37
|
-
variant: b(() => d.variant),
|
|
38
|
-
setActiveTab: S
|
|
39
|
-
});
|
|
40
|
-
function x() {
|
|
41
|
-
var w, C, T;
|
|
42
|
-
if (!B || !l.value)
|
|
43
|
-
return;
|
|
44
|
-
const t = Array.from((w = l.value) == null ? void 0 : w.children), y = {
|
|
45
|
-
root: l.value,
|
|
46
|
-
rootMargin: "0px",
|
|
47
|
-
threshold: Array.from({ length: 100 }).map((e, o) => (o + 1) / 100)
|
|
48
|
-
};
|
|
49
|
-
if (i.value = new IntersectionObserver((e) => {
|
|
50
|
-
e.forEach((o) => {
|
|
51
|
-
const n = o.target.getAttribute("id");
|
|
52
|
-
o.intersectionRatio > 0.94 ? r.value.has(n) && r.value.delete(n) : n && !r.value.has(n) && r.value.add(n);
|
|
53
|
-
});
|
|
54
|
-
}, y), t.forEach((e) => {
|
|
55
|
-
var o;
|
|
56
|
-
(o = i.value) == null || o.observe(e), r.value.has(e.getAttribute("id")) ? e.classList.add("tw-invisible") : e.classList.remove("tw-invisible");
|
|
57
|
-
}), m.value = ((T = (C = h.value) == null ? void 0 : C.$el) == null ? void 0 : T.getBoundingClientRect().width) || 0, !c.value)
|
|
58
|
-
return;
|
|
59
|
-
Array.from(c.value.children).forEach((e) => {
|
|
60
|
-
const o = e.firstElementChild;
|
|
61
|
-
o.className = "", e.className = "", e.classList.add(
|
|
62
|
-
M["menu-tab"],
|
|
63
|
-
"tw-rounded",
|
|
64
|
-
"tw-text-sm",
|
|
65
|
-
"tw-p-1.5",
|
|
66
|
-
"tw-text-left",
|
|
67
|
-
"tw-cursor-pointer",
|
|
68
|
-
"tw-text-ice-700",
|
|
69
|
-
"hover:tw-text-white",
|
|
70
|
-
"hover:tw-bg-blue-500",
|
|
71
|
-
"aria-disabled:tw-text-ice-500",
|
|
72
|
-
"aria-disabled:tw-pointer-events-none",
|
|
73
|
-
"aria-disabled:hover:tw-text-ice-500",
|
|
74
|
-
"aria-disabled:hover:tw-bg-inherit",
|
|
75
|
-
"aria-disabled:hover:tw-cursor-default",
|
|
76
|
-
"aria-selected:tw-text-white",
|
|
77
|
-
"aria-selected:tw-bg-blue-500"
|
|
78
|
-
), r.value.has(e.getAttribute("id")) ? e.classList.remove("tw-hidden") : e.classList.add("tw-hidden"), e.removeEventListener("click", () => {
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
const $ = X(x, ee.FAST, { leading: !0 });
|
|
83
|
-
function v() {
|
|
84
|
-
i.value && (i.value.disconnect(), i.value = void 0);
|
|
85
|
-
}
|
|
86
|
-
J(() => {
|
|
87
|
-
x();
|
|
88
|
-
}), R(() => {
|
|
89
|
-
v(), $();
|
|
90
|
-
}), q(() => {
|
|
91
|
-
v();
|
|
92
|
-
}), F(() => {
|
|
93
|
-
v();
|
|
94
|
-
});
|
|
95
|
-
function z(t) {
|
|
96
|
-
t(), u.value = !u.value;
|
|
97
|
-
}
|
|
98
|
-
return (t, y) => (k(), K("div", se, [
|
|
99
|
-
p("ul", {
|
|
100
|
-
ref_key: "tabListEl",
|
|
101
|
-
ref: l,
|
|
102
|
-
style: W({
|
|
103
|
-
width: `calc(100% - ${m.value}px)`
|
|
104
|
-
}),
|
|
105
|
-
class: I(["stash-tabs-list tw-flex tw-items-end", {
|
|
106
|
-
"stash-tabs-list--line": t.variant === "line",
|
|
107
|
-
"stash-tabs-list--enclosed": t.variant === "enclosed",
|
|
108
|
-
"tw-gap-6": t.variant === "line"
|
|
109
|
-
}])
|
|
110
|
-
}, [
|
|
111
|
-
L(t.$slots, "default"),
|
|
112
|
-
r.value.size ? (k(), Y(oe, {
|
|
113
|
-
key: 0,
|
|
114
|
-
ref_key: "moreDropdownEl",
|
|
115
|
-
ref: h,
|
|
116
|
-
class: "!tw-absolute tw-right-0 tw-top-0"
|
|
117
|
-
}, {
|
|
118
|
-
toggle: A(({ toggle: _ }) => [
|
|
119
|
-
p("button", {
|
|
120
|
-
"aria-haspopup": "menu",
|
|
121
|
-
"aria-controls": f(E),
|
|
122
|
-
"aria-expanded": u.value,
|
|
123
|
-
class: I(["tw-flex tw-cursor-pointer tw-items-center tw-justify-center tw-border-solid tw-px-6 tw-py-1.5 tw-text-sm tw-font-medium tw-text-blue-500 hover:tw-text-blue-700", { "tw-border-t-4 tw-border-transparent": d.variant === "enclosed" }]),
|
|
124
|
-
type: "button",
|
|
125
|
-
onClick: (w) => z(_)
|
|
126
|
-
}, [
|
|
127
|
-
G(H(f(te)("ll.more")) + " ", 1),
|
|
128
|
-
P(re, { name: "caret-down" })
|
|
129
|
-
], 10, ie)
|
|
130
|
-
]),
|
|
131
|
-
default: A(() => [
|
|
132
|
-
p("ul", {
|
|
133
|
-
id: f(E),
|
|
134
|
-
ref_key: "moreDropdownMenuEl",
|
|
135
|
-
ref: c,
|
|
136
|
-
class: "tw-space-y-1.5 tw-px-1.5 tw-pb-1.5",
|
|
137
|
-
role: "menu"
|
|
138
|
-
}, [
|
|
139
|
-
L(t.$slots, "default")
|
|
140
|
-
], 8, ne)
|
|
141
|
-
]),
|
|
142
|
-
_: 3
|
|
143
|
-
}, 512)) : Q("", !0)
|
|
144
|
-
], 6)
|
|
145
|
-
]));
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
export {
|
|
149
|
-
ae as T,
|
|
150
|
-
pe as _,
|
|
151
|
-
N as a
|
|
152
|
-
};
|
|
153
|
-
//# sourceMappingURL=Tabs.vue_vue_type_script_setup_true_lang-l41hWkV4.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Tabs.vue_vue_type_script_setup_true_lang-l41hWkV4.js","sources":["../src/components/Tabs/keys.ts","../src/components/Tabs/models.ts","../src/components/Tabs/Tabs.vue"],"sourcesContent":["import { Injection } from '../../../types/utils';\nimport { TabsInjection } from './models';\n\nexport const TABS_INJECTION: Injection<TabsInjection> = Object.freeze({\n key: Symbol('TABS_INJECTION_KEY'),\n});\n","import { ComputedRef } from 'vue';\n\nexport enum TabVariant {\n Line = 'line',\n Enclosed = 'enclosed',\n}\n\nexport type TabVariants = `${TabVariant}`;\n\nexport interface TabsInjection {\n activeTab: ComputedRef<string>;\n variant: ComputedRef<TabVariants>;\n setActiveTab: (newTabValue: string) => void;\n}\n","<script lang=\"ts\">\n import { TabVariant, TabVariants } from './models';\n\n export * from './keys';\n export * from './models';\n\n export interface TabsProps {\n /**\n * The currently active tab value\n */\n activeTab: string;\n\n /**\n * Tabs variant\n */\n variant?: TabVariants;\n }\n</script>\n\n<script setup lang=\"ts\">\n import debounce from 'lodash-es/debounce';\n import uniqueId from 'lodash-es/uniqueId';\n import { computed, onBeforeUnmount, onDeactivated, onMounted, onUpdated, provide, Ref, ref, useCssModule } from 'vue';\n\n import { DEBOUNCE } from '../../constants';\n import { t } from '../../locale';\n import Dropdown from '../Dropdown/Dropdown.vue';\n import Icon from '../Icon/Icon.vue';\n import { TABS_INJECTION } from './keys';\n\n const emit = defineEmits<{\n (e: 'update:activeTab', newTabValue: TabsProps['activeTab']): void;\n }>();\n\n const props = withDefaults(defineProps<TabsProps>(), {\n variant: TabVariant.Line,\n });\n const classes = useCssModule();\n\n const tabListEl = ref();\n const moreDropdownMenuEl = ref();\n const observer: Ref<IntersectionObserver | undefined> = ref(undefined);\n const hasIntersectionObserver = 'IntersectionObserver' in window;\n const overflowIds = ref<Set<string>>(new Set());\n const moreDropdownWidth = ref(0);\n const moreDropdownEl = ref<InstanceType<typeof Dropdown>>();\n const moreMenuId = uniqueId('more-dropdown-menu-');\n const isMoreMenuOpen = ref(false);\n\n const currentActiveTab = computed({\n get() {\n return props.activeTab;\n },\n set(nv: TabsProps['activeTab']) {\n emit('update:activeTab', nv);\n },\n });\n\n function setActiveTab(newTabValue: TabsProps['activeTab']) {\n currentActiveTab.value = newTabValue;\n }\n\n provide(TABS_INJECTION.key, {\n activeTab: computed(() => currentActiveTab.value),\n variant: computed(() => props.variant),\n setActiveTab,\n });\n\n function initObserve() {\n if (!hasIntersectionObserver) {\n return;\n }\n\n if (!tabListEl.value) {\n return;\n }\n\n const tabs = Array.from(tabListEl.value?.children as HTMLLIElement[]);\n const options = {\n root: tabListEl.value,\n rootMargin: '0px',\n threshold: Array.from({ length: 100 }).map((v, i) => (i + 1) / 100),\n };\n\n observer.value = new IntersectionObserver((entries) => {\n entries.forEach((entry) => {\n const dataId = entry.target.getAttribute('id') as string;\n /**\n * Check for partial intersection.\n * Zooming out can result in ratio of approx 0.984\n * Anything higher will result in nav items disappearing\n */\n if (entry.intersectionRatio > 0.94) {\n // show tab, hide in dropdown\n if (overflowIds.value.has(dataId)) {\n overflowIds.value.delete(dataId);\n }\n } else {\n // hide tab, show in dropdown\n if (dataId && !overflowIds.value.has(dataId)) {\n overflowIds.value.add(dataId);\n }\n }\n });\n }, options);\n\n tabs.forEach((element) => {\n observer.value?.observe(element);\n if (overflowIds.value.has(element.getAttribute('id') as string)) {\n element.classList.add('tw-invisible');\n } else {\n element.classList.remove('tw-invisible');\n }\n });\n\n moreDropdownWidth.value = moreDropdownEl.value?.$el?.getBoundingClientRect().width || 0;\n\n if (!moreDropdownMenuEl.value) {\n return;\n }\n\n const dropdownList = Array.from(moreDropdownMenuEl.value.children as HTMLLIElement[]);\n dropdownList.forEach((element) => {\n const firstElementChild = element.firstElementChild as Element;\n firstElementChild.className = '';\n element.className = '';\n\n element.classList.add(\n classes['menu-tab'],\n 'tw-rounded',\n 'tw-text-sm',\n 'tw-p-1.5',\n 'tw-text-left',\n 'tw-cursor-pointer',\n 'tw-text-ice-700',\n 'hover:tw-text-white',\n 'hover:tw-bg-blue-500',\n 'aria-disabled:tw-text-ice-500',\n 'aria-disabled:tw-pointer-events-none',\n 'aria-disabled:hover:tw-text-ice-500',\n 'aria-disabled:hover:tw-bg-inherit',\n 'aria-disabled:hover:tw-cursor-default',\n 'aria-selected:tw-text-white',\n 'aria-selected:tw-bg-blue-500',\n );\n\n if (!overflowIds.value.has(element.getAttribute('id') as string)) {\n element.classList.add('tw-hidden');\n } else {\n element.classList.remove('tw-hidden');\n }\n\n element.removeEventListener('click', () => {});\n });\n }\n\n const debouncedInitObserve = debounce(initObserve, DEBOUNCE.FAST, { leading: true });\n\n function destroyObserver() {\n if (observer.value) {\n observer.value.disconnect();\n observer.value = undefined;\n }\n }\n\n onMounted(() => {\n initObserve();\n });\n\n onUpdated(() => {\n destroyObserver();\n debouncedInitObserve();\n });\n\n onDeactivated(() => {\n destroyObserver();\n });\n\n onBeforeUnmount(() => {\n destroyObserver();\n });\n\n function onMoreClick(toggleMoreDropdown) {\n toggleMoreDropdown();\n isMoreMenuOpen.value = !isMoreMenuOpen.value;\n }\n</script>\n\n<template>\n <div class=\"stash-tabs tw-relative\" role=\"tabList\" data-test=\"stash-tabs\">\n <ul\n ref=\"tabListEl\"\n :style=\"{\n width: `calc(100% - ${moreDropdownWidth}px)`,\n }\"\n class=\"stash-tabs-list tw-flex tw-items-end\"\n :class=\"{\n 'stash-tabs-list--line': variant === 'line',\n 'stash-tabs-list--enclosed': variant === 'enclosed',\n 'tw-gap-6': variant === 'line',\n }\"\n >\n <slot></slot>\n\n <Dropdown v-if=\"overflowIds.size\" ref=\"moreDropdownEl\" class=\"!tw-absolute tw-right-0 tw-top-0\">\n <template #toggle=\"{ toggle }\">\n <button\n aria-haspopup=\"menu\"\n :aria-controls=\"moreMenuId\"\n :aria-expanded=\"isMoreMenuOpen\"\n class=\"tw-flex tw-cursor-pointer tw-items-center tw-justify-center tw-border-solid tw-px-6 tw-py-1.5 tw-text-sm tw-font-medium tw-text-blue-500 hover:tw-text-blue-700\"\n :class=\"{ 'tw-border-t-4 tw-border-transparent': props.variant === 'enclosed' }\"\n type=\"button\"\n @click=\"onMoreClick(toggle)\"\n >\n {{ t('ll.more') }}\n <Icon name=\"caret-down\" />\n </button>\n </template>\n <template #default>\n <ul :id=\"moreMenuId\" ref=\"moreDropdownMenuEl\" class=\"tw-space-y-1.5 tw-px-1.5 tw-pb-1.5\" role=\"menu\">\n <slot></slot>\n </ul>\n </template>\n </Dropdown>\n </ul>\n </div>\n</template>\n\n<style module>\n .menu-tab > a {\n /* prevents the global link styles to overwrite the overflowed tab styles */\n &,\n &:hover,\n &:focus {\n color: inherit;\n }\n }\n</style>\n"],"names":["TABS_INJECTION","TabVariant","emit","__emit","props","__props","classes","useCssModule","tabListEl","ref","moreDropdownMenuEl","observer","hasIntersectionObserver","overflowIds","moreDropdownWidth","moreDropdownEl","moreMenuId","uniqueId","isMoreMenuOpen","currentActiveTab","computed","nv","setActiveTab","newTabValue","provide","initObserve","tabs","_a","options","v","i","entries","entry","dataId","element","_c","_b","firstElementChild","debouncedInitObserve","debounce","DEBOUNCE","destroyObserver","onMounted","onUpdated","onDeactivated","onBeforeUnmount","onMoreClick","toggleMoreDropdown"],"mappings":";;;;;;;AAGa,MAAAA,KAA2C,OAAO,OAAO;AAAA,EACpE,KAAK,OAAO,oBAAoB;AAClC,CAAC;ACHW,IAAAC,sBAAAA,OACVA,EAAA,OAAO,QACPA,EAAA,WAAW,YAFDA,IAAAA,KAAA,CAAA,CAAA;;;;;;;;;;;;;AC4BV,UAAMC,IAAOC,GAIPC,IAAQC,GAGRC,IAAUC,EAAa,GAEvBC,IAAYC,EAAI,GAChBC,IAAqBD,EAAI,GACzBE,IAAkDF,EAAI,MAAS,GAC/DG,IAA0B,0BAA0B,QACpDC,IAAcJ,EAAqB,oBAAA,KAAK,GACxCK,IAAoB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