flexui-vue 0.0.0-stage → 2.0.0-alpha.2

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.
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Vue bindings for `@flexui/runtime`.
3
+ *
4
+ * Composables bind on mount and dispose on unmount, so Dialog/Dropdown state is
5
+ * destroyed with the component that owns it instead of leaking listeners.
6
+ * Template refs use `ref="..."` on the element and the returned `ref`.
7
+ */
8
+ import { type Ref, type ShallowRef } from "vue";
9
+ import { type Dialog, type DialogOptions } from "@flexui/runtime/dialog";
10
+ import { type Dropdown, type DropdownOptions } from "@flexui/runtime/dropdown";
11
+ import { type PopoverController, type PopoverOptions } from "@flexui/runtime/popover";
12
+ import { type Tabs } from "@flexui/runtime/tabs";
13
+ import { type ResolvedTheme, type ThemeMode } from "@flexui/runtime/theme";
14
+ export interface UseDialogResult {
15
+ /** `ref` for the `<dialog>` element. */
16
+ element: Ref<HTMLDialogElement | null>;
17
+ controller: ShallowRef<Dialog | null>;
18
+ isOpen: Ref<boolean>;
19
+ open(): void;
20
+ close(reason?: string): void;
21
+ }
22
+ /** Binds a native `<dialog class="fui-dialog" data-fui-dialog>`. */
23
+ export declare function useDialog(options?: DialogOptions): UseDialogResult;
24
+ export interface UseDropdownResult {
25
+ /** `ref` for the trigger button. */
26
+ trigger: Ref<HTMLElement | null>;
27
+ controller: ShallowRef<Dropdown | null>;
28
+ isOpen: Ref<boolean>;
29
+ open(focus?: "first" | "last" | "none"): void;
30
+ close(restoreFocus?: boolean): void;
31
+ toggle(): void;
32
+ }
33
+ /** Binds a trigger to a menu element. */
34
+ export declare function useDropdown(menu: HTMLElement | null, options?: DropdownOptions): UseDropdownResult;
35
+ export interface UsePopoverResult {
36
+ trigger: Ref<HTMLElement | null>;
37
+ controller: ShallowRef<PopoverController | null>;
38
+ isOpen: Ref<boolean>;
39
+ open(): void;
40
+ close(): void;
41
+ toggle(): void;
42
+ }
43
+ /** Binds a trigger to a `popover` panel element. */
44
+ export declare function usePopover(panel: HTMLElement | null, options?: PopoverOptions): UsePopoverResult;
45
+ export interface UseTabsResult {
46
+ /** `ref` for the `[data-fui-tabs]` container. */
47
+ element: Ref<HTMLElement | null>;
48
+ controller: ShallowRef<Tabs | null>;
49
+ activeIndex: Ref<number>;
50
+ activate(index: number, focus?: boolean): void;
51
+ }
52
+ /** Binds an ARIA tablist and tracks its active index. */
53
+ export declare function useTabs(): UseTabsResult;
54
+ export interface UseThemeResult {
55
+ mode: Ref<ThemeMode>;
56
+ resolved: Ref<ResolvedTheme>;
57
+ setMode(mode: ThemeMode): void;
58
+ toggle(): void;
59
+ }
60
+ /** Reads and changes the FlexUI theme mode. */
61
+ export declare function useTheme(): UseThemeResult;
package/dist/index.js ADDED
@@ -0,0 +1,190 @@
1
+ /**
2
+ * Vue bindings for `@flexui/runtime`.
3
+ *
4
+ * Composables bind on mount and dispose on unmount, so Dialog/Dropdown state is
5
+ * destroyed with the component that owns it instead of leaking listeners.
6
+ * Template refs use `ref="..."` on the element and the returned `ref`.
7
+ */
8
+ import { onBeforeUnmount, onMounted, ref, shallowRef } from "vue";
9
+ import { bindDialog } from "@flexui/runtime/dialog";
10
+ import { bindDropdown } from "@flexui/runtime/dropdown";
11
+ import { bindPopover } from "@flexui/runtime/popover";
12
+ import { bindTabs } from "@flexui/runtime/tabs";
13
+ import { getResolvedTheme, getTheme, setTheme, toggleTheme, } from "@flexui/runtime/theme";
14
+ /** Binds a native `<dialog class="fui-dialog" data-fui-dialog>`. */
15
+ export function useDialog(options = {}) {
16
+ const element = ref(null);
17
+ const controller = shallowRef(null);
18
+ const isOpen = ref(false);
19
+ onMounted(() => {
20
+ const target = element.value;
21
+ if (target === null) {
22
+ return;
23
+ }
24
+ const instance = bindDialog(target, options);
25
+ controller.value = instance;
26
+ isOpen.value = instance.isOpen;
27
+ instance.element.addEventListener("fui:open", handleOpen);
28
+ instance.element.addEventListener("fui:close", handleClose);
29
+ });
30
+ onBeforeUnmount(() => {
31
+ const instance = controller.value;
32
+ if (instance === null) {
33
+ return;
34
+ }
35
+ instance.element.removeEventListener("fui:open", handleOpen);
36
+ instance.element.removeEventListener("fui:close", handleClose);
37
+ instance.dispose();
38
+ controller.value = null;
39
+ });
40
+ function handleOpen() {
41
+ isOpen.value = true;
42
+ }
43
+ function handleClose() {
44
+ isOpen.value = false;
45
+ }
46
+ return {
47
+ element,
48
+ controller,
49
+ isOpen,
50
+ open: () => controller.value?.open(),
51
+ close: (reason) => controller.value?.close(reason),
52
+ };
53
+ }
54
+ /** Binds a trigger to a menu element. */
55
+ export function useDropdown(menu, options = {}) {
56
+ const trigger = ref(null);
57
+ const controller = shallowRef(null);
58
+ const isOpen = ref(false);
59
+ const handleOpen = () => {
60
+ isOpen.value = true;
61
+ };
62
+ const handleClose = () => {
63
+ isOpen.value = false;
64
+ };
65
+ onMounted(() => {
66
+ const source = trigger.value;
67
+ if (source === null || menu === null) {
68
+ return;
69
+ }
70
+ const instance = bindDropdown(source, menu, options);
71
+ controller.value = instance;
72
+ isOpen.value = instance.isOpen;
73
+ source.addEventListener("fui:open", handleOpen);
74
+ source.addEventListener("fui:close", handleClose);
75
+ });
76
+ onBeforeUnmount(() => {
77
+ const instance = controller.value;
78
+ if (instance === null) {
79
+ return;
80
+ }
81
+ instance.trigger.removeEventListener("fui:open", handleOpen);
82
+ instance.trigger.removeEventListener("fui:close", handleClose);
83
+ instance.dispose();
84
+ controller.value = null;
85
+ });
86
+ return {
87
+ trigger,
88
+ controller,
89
+ isOpen,
90
+ open: (focus) => controller.value?.open(focus),
91
+ close: (restoreFocus) => controller.value?.close(restoreFocus),
92
+ toggle: () => controller.value?.toggle(),
93
+ };
94
+ }
95
+ /** Binds a trigger to a `popover` panel element. */
96
+ export function usePopover(panel, options = {}) {
97
+ const trigger = ref(null);
98
+ const controller = shallowRef(null);
99
+ const isOpen = ref(false);
100
+ const handleOpen = () => {
101
+ isOpen.value = true;
102
+ };
103
+ const handleClose = () => {
104
+ isOpen.value = false;
105
+ };
106
+ onMounted(() => {
107
+ const source = trigger.value;
108
+ if (source === null || panel === null) {
109
+ return;
110
+ }
111
+ const instance = bindPopover(source, panel, options);
112
+ controller.value = instance;
113
+ isOpen.value = instance.isOpen;
114
+ source.addEventListener("fui:popoveropen", handleOpen);
115
+ source.addEventListener("fui:popoverclose", handleClose);
116
+ });
117
+ onBeforeUnmount(() => {
118
+ const instance = controller.value;
119
+ if (instance === null) {
120
+ return;
121
+ }
122
+ instance.trigger.removeEventListener("fui:popoveropen", handleOpen);
123
+ instance.trigger.removeEventListener("fui:popoverclose", handleClose);
124
+ instance.dispose();
125
+ controller.value = null;
126
+ });
127
+ return {
128
+ trigger,
129
+ controller,
130
+ isOpen,
131
+ open: () => controller.value?.open(),
132
+ close: () => controller.value?.close(),
133
+ toggle: () => controller.value?.toggle(),
134
+ };
135
+ }
136
+ /** Binds an ARIA tablist and tracks its active index. */
137
+ export function useTabs() {
138
+ const element = ref(null);
139
+ const controller = shallowRef(null);
140
+ const activeIndex = ref(0);
141
+ const handle = (event) => {
142
+ activeIndex.value = event.detail.index;
143
+ };
144
+ onMounted(() => {
145
+ const target = element.value;
146
+ if (target === null) {
147
+ return;
148
+ }
149
+ const instance = bindTabs(target);
150
+ controller.value = instance;
151
+ activeIndex.value = instance.active?.index ?? 0;
152
+ target.addEventListener("fui:tabchange", handle);
153
+ });
154
+ onBeforeUnmount(() => {
155
+ const target = element.value;
156
+ if (target !== null) {
157
+ target.removeEventListener("fui:tabchange", handle);
158
+ }
159
+ controller.value?.dispose();
160
+ controller.value = null;
161
+ });
162
+ return {
163
+ element,
164
+ controller,
165
+ activeIndex,
166
+ activate: (index, focus) => controller.value?.activate(index, focus),
167
+ };
168
+ }
169
+ /** Reads and changes the FlexUI theme mode. */
170
+ export function useTheme() {
171
+ const mode = ref(getTheme());
172
+ const resolved = ref(getResolvedTheme());
173
+ const handle = (event) => {
174
+ const detail = event.detail;
175
+ mode.value = detail.mode;
176
+ resolved.value = detail.resolved;
177
+ };
178
+ onMounted(() => {
179
+ document.addEventListener("fui:themechange", handle);
180
+ });
181
+ onBeforeUnmount(() => {
182
+ document.removeEventListener("fui:themechange", handle);
183
+ });
184
+ return {
185
+ mode,
186
+ resolved,
187
+ setMode: (next) => setTheme(next),
188
+ toggle: () => toggleTheme(),
189
+ };
190
+ }
package/package.json CHANGED
@@ -1,6 +1,34 @@
1
- {
2
- "name": "flexui-vue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "flexui-vue",
3
+ "version": "2.0.0-alpha.2",
4
+ "description": "Vue composables for FlexUI interactive components",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc -p tsconfig.json",
21
+ "typecheck": "tsc -p tsconfig.json --noEmit"
22
+ },
23
+ "dependencies": {
24
+ "flexui-runtime": "2.0.0-alpha.2"
25
+ },
26
+ "peerDependencies": {
27
+ "vue": "^3.5.46"
28
+ },
29
+ "keywords": [
30
+ "flexui",
31
+ "vue",
32
+ "composables"
33
+ ]
34
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.