@hydrateless/vue 0.3.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/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # @hydrateless/vue
2
+
3
+ Vue 3 bindings for [Hydrateless](https://github.com/hydrateless/hydrateless):
4
+ directives, composables, and a plugin that wire the framework-agnostic
5
+ enhancers, with automatic cleanup when components unmount.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install hydrateless @hydrateless/vue
11
+ ```
12
+
13
+ Import the CSS once (e.g. in your entry):
14
+
15
+ ```ts
16
+ import 'hydrateless/hydrateless.css';
17
+ ```
18
+
19
+ ## Plugin (global directives)
20
+
21
+ ```ts
22
+ import { createApp } from 'vue';
23
+ import { HydratelessPlugin } from '@hydrateless/vue';
24
+ import App from './App.vue';
25
+
26
+ createApp(App).use(HydratelessPlugin).mount('#app');
27
+ ```
28
+
29
+ Then use the directives in any template:
30
+
31
+ ```vue
32
+ <template>
33
+ <div v-hl-tabs data-hl-tabs>
34
+ <div role="tablist">
35
+ <button role="tab">Overview</button>
36
+ <button role="tab">Install</button>
37
+ </div>
38
+ <div role="tabpanel">Zero runtime by default.</div>
39
+ <div role="tabpanel"><code>npm i hydrateless</code></div>
40
+ </div>
41
+ </template>
42
+ ```
43
+
44
+ Available directives: `v-hl-accordion`, `v-hl-disclosure`, `v-hl-tabs`,
45
+ `v-hl-dropdown`, `v-hl-modal`, `v-hl-drawer`, `v-hl-popover`, `v-hl-tooltip`,
46
+ `v-hl-toc`. You can also import individual directives (e.g. `vHlTabs`) and
47
+ register them locally.
48
+
49
+ ## Composables
50
+
51
+ ```vue
52
+ <script setup lang="ts">
53
+ import { ref } from 'vue';
54
+ import { useEnhancer, useToast } from '@hydrateless/vue';
55
+ import { enhanceDropdown } from '@hydrateless/enhancers';
56
+
57
+ const menu = ref<HTMLElement | null>(null);
58
+ useEnhancer(menu, enhanceDropdown);
59
+
60
+ const toast = useToast();
61
+ </script>
62
+
63
+ <template>
64
+ <div ref="menu" data-hl-dropdown>…</div>
65
+ <button @click="toast.show('Saved')">Save</button>
66
+ </template>
67
+ ```
68
+
69
+ ## License
70
+
71
+ [MIT](../../LICENSE)
@@ -0,0 +1,50 @@
1
+ import { Ref, Plugin, Directive } from 'vue';
2
+ import { Disposer, ToastOptions } from '@hydrateless/enhancers';
3
+ export { Disposer } from '@hydrateless/enhancers';
4
+
5
+ /**
6
+ * Attach any Hydrateless enhancer to a template ref for the lifetime of a
7
+ * component. The enhancer's disposer is called automatically on unmount.
8
+ *
9
+ * ```ts
10
+ * const el = ref<HTMLElement | null>(null);
11
+ * useEnhancer(el, enhanceTabs);
12
+ * ```
13
+ */
14
+ declare function useEnhancer(target: Ref<HTMLElement | null | undefined>, enhance: (container: HTMLElement) => Disposer): void;
15
+
16
+ interface UseToastReturn {
17
+ show: (message: string, options?: ToastOptions) => HTMLElement;
18
+ dismiss: (toast: HTMLElement) => void;
19
+ }
20
+ /**
21
+ * Sets up a toast region for the current component tree and returns an
22
+ * imperative API. The region is torn down automatically on unmount.
23
+ */
24
+ declare function useToast(): UseToastReturn;
25
+
26
+ /**
27
+ * Registers every Hydrateless directive globally:
28
+ *
29
+ * ```ts
30
+ * import { HydratelessPlugin } from '@hydrateless/vue';
31
+ * createApp(App).use(HydratelessPlugin);
32
+ * ```
33
+ *
34
+ * Then use `v-hl-tabs`, `v-hl-dropdown`, etc. in templates.
35
+ */
36
+ declare const HydratelessPlugin: Plugin;
37
+
38
+ declare const vHlAccordion: Directive<HTMLElement>;
39
+ declare const vHlDisclosure: Directive<HTMLElement>;
40
+ declare const vHlTabs: Directive<HTMLElement>;
41
+ declare const vHlDropdown: Directive<HTMLElement>;
42
+ declare const vHlModal: Directive<HTMLElement>;
43
+ declare const vHlDrawer: Directive<HTMLElement>;
44
+ declare const vHlPopover: Directive<HTMLElement>;
45
+ declare const vHlTooltip: Directive<HTMLElement>;
46
+ declare const vHlToc: Directive<HTMLElement>;
47
+ /** Map of directive names (without the `v-` prefix) to their definitions. */
48
+ declare const directives: Record<string, Directive<HTMLElement>>;
49
+
50
+ export { HydratelessPlugin, type UseToastReturn, directives, useEnhancer, useToast, vHlAccordion, vHlDisclosure, vHlDrawer, vHlDropdown, vHlModal, vHlPopover, vHlTabs, vHlToc, vHlTooltip };
package/dist/index.js ADDED
@@ -0,0 +1,99 @@
1
+ // src/useEnhancer.ts
2
+ import { onMounted, onUnmounted } from "vue";
3
+ function useEnhancer(target, enhance) {
4
+ let dispose = null;
5
+ onMounted(() => {
6
+ if (target.value) dispose = enhance(target.value);
7
+ });
8
+ onUnmounted(() => {
9
+ dispose?.();
10
+ dispose = null;
11
+ });
12
+ }
13
+
14
+ // src/useToast.ts
15
+ import { onMounted as onMounted2, onUnmounted as onUnmounted2 } from "vue";
16
+ import { enhanceToast } from "@hydrateless/enhancers";
17
+ function useToast() {
18
+ let api = null;
19
+ onMounted2(() => {
20
+ api = enhanceToast(document);
21
+ });
22
+ onUnmounted2(() => {
23
+ api?.destroy();
24
+ api = null;
25
+ });
26
+ return {
27
+ show: (message, options) => api ? api.show(message, options) : document.createElement("div"),
28
+ dismiss: (toast) => api?.dismiss(toast)
29
+ };
30
+ }
31
+
32
+ // src/directives.ts
33
+ import {
34
+ enhanceAccordion,
35
+ enhanceDisclosure,
36
+ enhanceDropdown,
37
+ enhanceDrawer,
38
+ enhanceModal,
39
+ enhancePopover,
40
+ enhanceTabs,
41
+ enhanceToc,
42
+ enhanceTooltip
43
+ } from "@hydrateless/enhancers";
44
+ function directiveFor(enhance) {
45
+ const disposers = /* @__PURE__ */ new WeakMap();
46
+ return {
47
+ mounted(el) {
48
+ disposers.set(el, enhance(el));
49
+ },
50
+ unmounted(el) {
51
+ disposers.get(el)?.();
52
+ disposers.delete(el);
53
+ }
54
+ };
55
+ }
56
+ var vHlAccordion = directiveFor((el) => enhanceAccordion(el));
57
+ var vHlDisclosure = directiveFor((el) => enhanceDisclosure(el));
58
+ var vHlTabs = directiveFor((el) => enhanceTabs(el));
59
+ var vHlDropdown = directiveFor((el) => enhanceDropdown(el));
60
+ var vHlModal = directiveFor((el) => enhanceModal(el));
61
+ var vHlDrawer = directiveFor((el) => enhanceDrawer(el));
62
+ var vHlPopover = directiveFor((el) => enhancePopover(el));
63
+ var vHlTooltip = directiveFor((el) => enhanceTooltip(el));
64
+ var vHlToc = directiveFor((el) => enhanceToc(el.ownerDocument));
65
+ var directives = {
66
+ "hl-accordion": vHlAccordion,
67
+ "hl-disclosure": vHlDisclosure,
68
+ "hl-tabs": vHlTabs,
69
+ "hl-dropdown": vHlDropdown,
70
+ "hl-modal": vHlModal,
71
+ "hl-drawer": vHlDrawer,
72
+ "hl-popover": vHlPopover,
73
+ "hl-tooltip": vHlTooltip,
74
+ "hl-toc": vHlToc
75
+ };
76
+
77
+ // src/plugin.ts
78
+ var HydratelessPlugin = {
79
+ install(app) {
80
+ for (const [name, directive] of Object.entries(directives)) {
81
+ app.directive(name, directive);
82
+ }
83
+ }
84
+ };
85
+ export {
86
+ HydratelessPlugin,
87
+ directives,
88
+ useEnhancer,
89
+ useToast,
90
+ vHlAccordion,
91
+ vHlDisclosure,
92
+ vHlDrawer,
93
+ vHlDropdown,
94
+ vHlModal,
95
+ vHlPopover,
96
+ vHlTabs,
97
+ vHlToc,
98
+ vHlTooltip
99
+ };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@hydrateless/vue",
3
+ "version": "0.3.0",
4
+ "description": "Vue 3 bindings for Hydrateless — directives, composables, and a plugin for the enhancers.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/hydrateless/hydrateless.git",
9
+ "directory": "packages/vue"
10
+ },
11
+ "type": "module",
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "sideEffects": false,
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js"
20
+ }
21
+ },
22
+ "types": "./dist/index.d.ts",
23
+ "scripts": {
24
+ "build": "tsup src/index.ts --dts --format esm --clean --external vue",
25
+ "dev": "npm run build -- --watch",
26
+ "typecheck": "tsc -p tsconfig.json --noEmit",
27
+ "lint": "eslint \"src/**/*.ts\"",
28
+ "test": "vitest run"
29
+ },
30
+ "dependencies": {
31
+ "@hydrateless/enhancers": "^0.3.0"
32
+ },
33
+ "peerDependencies": {
34
+ "vue": ">=3.3"
35
+ },
36
+ "devDependencies": {
37
+ "@vue/test-utils": "^2.4.6",
38
+ "jsdom": "^29.0.0",
39
+ "vitest": "^4.1.0",
40
+ "vue": "^3.5.0"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ }
45
+ }