@lumx/vue 4.4.1-alpha.1 → 4.4.1-alpha.3

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/package.json CHANGED
@@ -24,13 +24,18 @@
24
24
  ".": {
25
25
  "types": "./index.d.ts",
26
26
  "default": "./index.js"
27
+ },
28
+ "./utils": {
29
+ "types": "./utils/index.d.ts",
30
+ "default": "./utils/index.js"
27
31
  }
28
32
  },
29
33
  "sideEffects": false,
30
- "version": "4.4.1-alpha.1",
34
+ "version": "4.4.1-alpha.3",
31
35
  "dependencies": {
32
- "@lumx/core": "^4.4.1-alpha.1",
33
- "@lumx/icons": "^4.4.1-alpha.1",
36
+ "@floating-ui/vue": "^1.1.10",
37
+ "@lumx/core": "^4.4.1-alpha.3",
38
+ "@lumx/icons": "^4.4.1-alpha.3",
34
39
  "@vueuse/core": "^14.1.0"
35
40
  },
36
41
  "peerDependencies": {
@@ -40,9 +45,9 @@
40
45
  "devDependencies": {
41
46
  "@babel/plugin-transform-react-jsx": "^7.27.1",
42
47
  "@chromatic-com/storybook": "^5.0.0",
48
+ "@lumx/storybook-testing": "workspace:*",
43
49
  "@rollup/plugin-node-resolve": "^16.0.3",
44
50
  "@storybook/addon-a11y": "^10.2.0",
45
- "@storybook/addon-vitest": "10.2.0",
46
51
  "@storybook/vue3-vite": "^10.2.0",
47
52
  "@testing-library/dom": "^10.4.1",
48
53
  "@testing-library/user-event": "^14.4.3",
@@ -50,12 +55,10 @@
50
55
  "@types/lodash": "^4.14.149",
51
56
  "@vitejs/plugin-vue": "^6.0.3",
52
57
  "@vitejs/plugin-vue-jsx": "^5.1.3",
53
- "@vitest/browser-playwright": "^4.0.18",
54
58
  "chromatic": "^13.3.5",
55
59
  "focus-visible": "^5.2.1",
56
60
  "jsdom": "^27.2.0",
57
61
  "storybook": "^10.2.0",
58
- "storybook-addon-vis": "^3.1.2",
59
62
  "typescript": "^5.4.3",
60
63
  "vite": "^7.3.1",
61
64
  "vite-plugin-dts": "^4.5.4",
@@ -0,0 +1,2 @@
1
+ /** Story decorator used to force a minimum screen size when running in chromatic */
2
+ export declare const withChromaticForceScreenSize: () => (story: any) => any;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * SB decorator managing a local reactive state for a value prop,
3
+ * updating it via the onChange callback.
4
+ *
5
+ * This is the Vue equivalent of the React withValueOnChange decorator.
6
+ */
7
+ export declare const withValueOnChange: ({ valueProp, valueTransform, }?: {
8
+ valueProp?: string;
9
+ valueTransform?: (v: any) => any;
10
+ }) => (story: any, ctx: any) => () => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
11
+ [key: string]: any;
12
+ }>;
@@ -0,0 +1,21 @@
1
+ import { InjectionKey, Ref } from 'vue';
2
+ import { ClickAwayCallback } from '@lumx/core/js/utils/ClickAway';
3
+ interface ContextValue {
4
+ childrenRefs: HTMLElement[];
5
+ addRefs(...newChildrenRefs: Array<Ref<HTMLElement | undefined>>): void;
6
+ }
7
+ export declare const CLICK_AWAY_KEY: InjectionKey<ContextValue>;
8
+ /**
9
+ * Component combining click away detection with Vue's provide/inject to hook into the component tree
10
+ * and take into account both the DOM tree and the component tree to detect click away.
11
+ */
12
+ export declare const ClickAwayProvider: import('vue').DefineSetupFnComponent<{
13
+ callback: ClickAwayCallback;
14
+ childrenRefs: Ref<Array<Ref<HTMLElement | undefined>>>;
15
+ parentRef?: Ref<HTMLElement | undefined>;
16
+ }, {}, {}, {
17
+ callback: ClickAwayCallback;
18
+ childrenRefs: Ref<Array<Ref<HTMLElement | undefined>>>;
19
+ parentRef?: Ref<HTMLElement | undefined>;
20
+ } & {}, import('vue').PublicProps>;
21
+ export {};
@@ -0,0 +1,25 @@
1
+ declare const _default: {
2
+ component: any;
3
+ parameters: {
4
+ chromatic: {
5
+ disable: boolean;
6
+ };
7
+ };
8
+ tags: string[];
9
+ title: string;
10
+ };
11
+ export default _default;
12
+ export declare const NestedClickAway: {
13
+ render: () => import("vue/jsx-runtime").JSX.Element;
14
+ };
15
+ export declare const InShadowDOM: {
16
+ render: () => import("vue/jsx-runtime").JSX.Element;
17
+ };
18
+ export declare const TestClickAwayCloses: {
19
+ render: () => import("vue/jsx-runtime").JSX.Element;
20
+ play(): Promise<void>;
21
+ };
22
+ export declare const TestNestedClickAway: {
23
+ render: () => import("vue/jsx-runtime").JSX.Element;
24
+ play(): Promise<void>;
25
+ };
@@ -0,0 +1,2 @@
1
+ export { ClickAwayProvider } from './ClickAwayProvider';
2
+ export { useClickAway } from './useClickAway';
@@ -0,0 +1,18 @@
1
+ import { Ref } from 'vue';
2
+ import { ClickAwayCallback } from '@lumx/core/js/utils/ClickAway';
3
+ export interface ClickAwayParameters {
4
+ /**
5
+ * A callback function to call when the user clicks away from the elements.
6
+ */
7
+ callback: ClickAwayCallback;
8
+ /**
9
+ * Elements considered within the click away context (clicking outside them will trigger the click away callback).
10
+ */
11
+ childrenRefs: Ref<Array<Ref<HTMLElement | undefined>>>;
12
+ }
13
+ /**
14
+ * Listen to clicks away from the given elements and callback the passed in function.
15
+ *
16
+ * Warning: If you need to detect click away on nested Vue portals, please use the `ClickAwayProvider` component.
17
+ */
18
+ export declare function useClickAway({ callback, childrenRefs }: ClickAwayParameters): void;
@@ -0,0 +1,7 @@
1
+ import { PortalProps } from '@lumx/core/js/utils/Portal';
2
+ export type { PortalProps } from '@lumx/core/js/utils/Portal';
3
+ /**
4
+ * Render children in a portal outside the current DOM position
5
+ * (defaults to `document.body` but can be customized with the PortalProvider)
6
+ */
7
+ export declare const Portal: import('vue').DefineSetupFnComponent<PortalProps, {}, {}, PortalProps & {}, import('vue').PublicProps>;
@@ -0,0 +1,9 @@
1
+ import { InjectionKey } from 'vue';
2
+ import { PortalInit, PortalProviderProps } from '@lumx/core/js/utils/Portal';
3
+ export type { PortalInit, PortalProviderProps } from '@lumx/core/js/utils/Portal';
4
+ export declare const PORTAL_KEY: InjectionKey<PortalInit>;
5
+ export declare const defaultPortalInit: PortalInit;
6
+ /**
7
+ * Customize where <Portal> wrapped elements render (tooltip, popover, dialog, etc.)
8
+ */
9
+ export declare const PortalProvider: import('vue').DefineSetupFnComponent<PortalProviderProps, {}, {}, PortalProviderProps & {}, import('vue').PublicProps>;
@@ -0,0 +1,19 @@
1
+ declare const _default: {
2
+ component: any;
3
+ args: {
4
+ enabled: boolean;
5
+ };
6
+ parameters: {
7
+ chromatic: {
8
+ disable: boolean;
9
+ };
10
+ };
11
+ tags: string[];
12
+ title: string;
13
+ };
14
+ export default _default;
15
+ export declare const RenderInShadowDOM: {
16
+ render: ({ enabled }: {
17
+ enabled: boolean;
18
+ }) => import("vue/jsx-runtime").JSX.Element;
19
+ };
@@ -0,0 +1,2 @@
1
+ export { type PortalInit, PortalProvider, type PortalProviderProps } from './PortalProvider';
2
+ export { type PortalProps, Portal } from './Portal';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * WARNING: All modules exported here are exposed to NPM in '@lumx/vue/utils'.
3
+ */
4
+ export { Portal, type PortalProps, type PortalInit, PortalProvider, type PortalProviderProps } from './Portal';
5
+ export { ClickAwayProvider, useClickAway } from './ClickAway';
package/utils/index.js ADDED
@@ -0,0 +1,73 @@
1
+ import { defineComponent as m, inject as C, provide as p, onMounted as E, onBeforeUnmount as d, watchEffect as R } from "vue";
2
+ import { P as k, a as x } from "../_internal/CCjQX5wE.js";
3
+ const s = ["mousedown", "touchstart"];
4
+ function h(n, o) {
5
+ return !o.some((t) => n.some((e) => t?.contains(e)));
6
+ }
7
+ function u(n, o) {
8
+ if (!o)
9
+ return;
10
+ const t = (e) => {
11
+ const r = [e.composedPath?.()[0], e.target], a = n();
12
+ a.length > 0 && h(r, a) && o(e);
13
+ };
14
+ return s.forEach((e) => document.addEventListener(e, t)), () => {
15
+ s.forEach((e) => document.removeEventListener(e, t));
16
+ };
17
+ }
18
+ const i = /* @__PURE__ */ Symbol("LumxClickAway"), w = /* @__PURE__ */ m((n, {
19
+ slots: o
20
+ }) => {
21
+ const t = C(i, null), e = [], r = {
22
+ childrenRefs: e,
23
+ addRefs(...c) {
24
+ for (const l of c) {
25
+ const f = l.value;
26
+ f && e.push(f);
27
+ }
28
+ t && (t.addRefs(...c), n.parentRef && t.addRefs(n.parentRef));
29
+ }
30
+ };
31
+ p(i, r);
32
+ let a;
33
+ return E(() => {
34
+ const c = n.childrenRefs.value;
35
+ c && r.addRefs(...c), a = u(() => e, n.callback);
36
+ }), d(() => {
37
+ a?.();
38
+ }), () => o.default?.();
39
+ }, {
40
+ name: "LumxClickAwayProvider",
41
+ props: {
42
+ callback: {
43
+ type: [Function, Boolean, void 0],
44
+ default: void 0
45
+ },
46
+ childrenRefs: {
47
+ type: Object,
48
+ required: !0
49
+ },
50
+ parentRef: {
51
+ type: Object,
52
+ default: void 0
53
+ }
54
+ }
55
+ });
56
+ function y({ callback: n, childrenRefs: o }) {
57
+ let t;
58
+ R(() => {
59
+ t?.(), t = u(() => {
60
+ const r = o.value;
61
+ return r ? r.map((a) => a?.value).filter(Boolean) : [];
62
+ }, n);
63
+ }), d(() => {
64
+ t?.();
65
+ });
66
+ }
67
+ export {
68
+ w as ClickAwayProvider,
69
+ k as Portal,
70
+ x as PortalProvider,
71
+ y as useClickAway
72
+ };
73
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../lumx-core/src/js/utils/ClickAway/index.ts","../../src/utils/ClickAway/ClickAwayProvider.tsx","../../src/utils/ClickAway/useClickAway.ts"],"sourcesContent":["/**\n * Shared types and logic for ClickAway detection.\n *\n * ClickAway detects clicks outside a set of elements and triggers a callback.\n * The core logic (event listening + target checking) is framework-agnostic.\n * Framework-specific wrappers (React hook, Vue composable) and context providers\n * (React context, Vue provide/inject) are implemented in each framework package.\n */\n\nimport type { Falsy } from '@lumx/core/js/types';\n\n/** Event types that trigger click away detection. */\nexport const CLICK_AWAY_EVENT_TYPES = ['mousedown', 'touchstart'] as const;\n\n/** Callback triggered when a click away is detected. */\nexport type ClickAwayCallback = EventListener | Falsy;\n\n/**\n * Check if the click event targets are outside all the given elements.\n *\n * @param targets - The event target elements (from `event.target` and `event.composedPath()`).\n * @param elements - The elements considered \"inside\" the click away context.\n * @returns `true` if the click is outside all elements (i.e. a click away).\n */\nexport function isClickAway(targets: HTMLElement[], elements: HTMLElement[]): boolean {\n return !elements.some((element) => targets.some((target) => element?.contains(target)));\n}\n\n/**\n * Imperative setup for click away detection.\n * Adds mousedown/touchstart listeners on `document` and calls the callback when a click\n * occurs outside the elements returned by `getElements`.\n *\n * @param getElements - Getter returning the current list of elements considered \"inside\".\n * @param callback - Callback to invoke on click away.\n * @returns A teardown function that removes the event listeners.\n */\nexport function setupClickAway(\n getElements: () => HTMLElement[],\n callback: ClickAwayCallback,\n): (() => void) | undefined {\n if (!callback) {\n return undefined;\n }\n\n const listener: EventListener = (evt) => {\n const targets = [evt.composedPath?.()[0], evt.target] as HTMLElement[];\n const elements = getElements();\n if (elements.length > 0 && isClickAway(targets, elements)) {\n callback(evt);\n }\n };\n\n CLICK_AWAY_EVENT_TYPES.forEach((evtType) => document.addEventListener(evtType, listener));\n return () => {\n CLICK_AWAY_EVENT_TYPES.forEach((evtType) => document.removeEventListener(evtType, listener));\n };\n}\n","import {\n defineComponent,\n inject,\n onBeforeUnmount,\n onMounted,\n provide,\n type InjectionKey,\n type PropType,\n type Ref,\n} from 'vue';\nimport { setupClickAway, type ClickAwayCallback } from '@lumx/core/js/utils/ClickAway';\n\ninterface ContextValue {\n childrenRefs: HTMLElement[];\n addRefs(...newChildrenRefs: Array<Ref<HTMLElement | undefined>>): void;\n}\n\nexport const CLICK_AWAY_KEY: InjectionKey<ContextValue> = Symbol('LumxClickAway');\n\n/**\n * Component combining click away detection with Vue's provide/inject to hook into the component tree\n * and take into account both the DOM tree and the component tree to detect click away.\n */\nexport const ClickAwayProvider = defineComponent(\n (\n props: {\n callback: ClickAwayCallback;\n childrenRefs: Ref<Array<Ref<HTMLElement | undefined>>>;\n parentRef?: Ref<HTMLElement | undefined>;\n },\n { slots },\n ) => {\n const parentContext = inject(CLICK_AWAY_KEY, null);\n\n const contextChildrenRefs: HTMLElement[] = [];\n\n const currentContext: ContextValue = {\n childrenRefs: contextChildrenRefs,\n addRefs(...newChildrenRefs) {\n for (const newRef of newChildrenRefs) {\n const el = newRef.value;\n if (el) {\n contextChildrenRefs.push(el);\n }\n }\n if (parentContext) {\n parentContext.addRefs(...newChildrenRefs);\n if (props.parentRef) {\n parentContext.addRefs(props.parentRef);\n }\n }\n },\n };\n\n provide(CLICK_AWAY_KEY, currentContext);\n\n let teardown: (() => void) | undefined;\n\n onMounted(() => {\n const refs = props.childrenRefs.value;\n if (refs) {\n currentContext.addRefs(...refs);\n }\n\n // Setup click away using the context's collected refs directly\n teardown = setupClickAway(() => contextChildrenRefs, props.callback);\n });\n\n onBeforeUnmount(() => {\n teardown?.();\n });\n\n return () => slots.default?.();\n },\n {\n name: 'LumxClickAwayProvider',\n props: {\n callback: {\n type: [Function, Boolean, undefined] as PropType<ClickAwayCallback>,\n default: undefined,\n },\n childrenRefs: {\n type: Object as PropType<Ref<Array<Ref<HTMLElement | undefined>>>>,\n required: true,\n },\n parentRef: {\n type: Object as PropType<Ref<HTMLElement | undefined>>,\n default: undefined,\n },\n },\n },\n);\n","import { onBeforeUnmount, watchEffect, type Ref } from 'vue';\nimport { setupClickAway, type ClickAwayCallback } from '@lumx/core/js/utils/ClickAway';\n\nexport interface ClickAwayParameters {\n /**\n * A callback function to call when the user clicks away from the elements.\n */\n callback: ClickAwayCallback;\n /**\n * Elements considered within the click away context (clicking outside them will trigger the click away callback).\n */\n childrenRefs: Ref<Array<Ref<HTMLElement | undefined>>>;\n}\n\n/**\n * Listen to clicks away from the given elements and callback the passed in function.\n *\n * Warning: If you need to detect click away on nested Vue portals, please use the `ClickAwayProvider` component.\n */\nexport function useClickAway({ callback, childrenRefs }: ClickAwayParameters): void {\n let teardown: (() => void) | undefined;\n\n watchEffect(() => {\n // Clean up previous listener\n teardown?.();\n\n const getElements = () => {\n const refs = childrenRefs.value;\n if (!refs) return [];\n return refs.map((ref) => ref?.value).filter(Boolean) as HTMLElement[];\n };\n\n teardown = setupClickAway(getElements, callback);\n });\n\n onBeforeUnmount(() => {\n teardown?.();\n });\n}\n"],"names":["CLICK_AWAY_EVENT_TYPES","isClickAway","targets","elements","element","target","setupClickAway","getElements","callback","listener","evt","evtType","CLICK_AWAY_KEY","Symbol","ClickAwayProvider","props","slots","parentContext","inject","contextChildrenRefs","currentContext","childrenRefs","addRefs","newChildrenRefs","newRef","el","value","push","parentRef","provide","teardown","onMounted","refs","onBeforeUnmount","default","name","type","Function","Boolean","undefined","Object","required","useClickAway","watchEffect","ref"],"mappings":";;AAYO,MAAMA,IAAyB,CAAC,aAAa,YAAY;AAYzD,SAASC,EAAYC,GAAwBC,GAAkC;AAClF,SAAO,CAACA,EAAS,KAAK,CAACC,MAAYF,EAAQ,KAAK,CAACG,MAAWD,GAAS,SAASC,CAAM,CAAC,CAAC;AAC1F;AAWO,SAASC,EACZC,GACAC,GACwB;AACxB,MAAI,CAACA;AACD;AAGJ,QAAMC,IAA0B,CAACC,MAAQ;AACrC,UAAMR,IAAU,CAACQ,EAAI,eAAA,EAAiB,CAAC,GAAGA,EAAI,MAAM,GAC9CP,IAAWI,EAAA;AACjB,IAAIJ,EAAS,SAAS,KAAKF,EAAYC,GAASC,CAAQ,KACpDK,EAASE,CAAG;AAAA,EAEpB;AAEA,SAAAV,EAAuB,QAAQ,CAACW,MAAY,SAAS,iBAAiBA,GAASF,CAAQ,CAAC,GACjF,MAAM;AACT,IAAAT,EAAuB,QAAQ,CAACW,MAAY,SAAS,oBAAoBA,GAASF,CAAQ,CAAC;AAAA,EAC/F;AACJ;ACxCO,MAAMG,IAA6CC,uBAAO,eAAe,GAMnEC,sBACT,CACIC,GAKA;AAAA,EAAEC,OAAAA;AAAM,MACP;AACD,QAAMC,IAAgBC,EAAON,GAAgB,IAAI,GAE3CO,IAAqC,CAAA,GAErCC,IAA+B;AAAA,IACjCC,c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