@hydrateless/svelte 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 +66 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +49 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# @hydrateless/svelte
|
|
2
|
+
|
|
3
|
+
Svelte bindings for [Hydrateless](https://github.com/hydrateless/hydrateless).
|
|
4
|
+
Tiny actions that wire the framework-agnostic enhancers and clean up
|
|
5
|
+
automatically when the element is destroyed.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install hydrateless @hydrateless/svelte
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Import the CSS once (e.g. in your root layout):
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import 'hydrateless/hydrateless.css';
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Actions
|
|
20
|
+
|
|
21
|
+
```svelte
|
|
22
|
+
<script lang="ts">
|
|
23
|
+
import { tabs, dropdown } from '@hydrateless/svelte';
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<div use:tabs data-hl-tabs>
|
|
27
|
+
<div role="tablist">
|
|
28
|
+
<button role="tab">Overview</button>
|
|
29
|
+
<button role="tab">Install</button>
|
|
30
|
+
</div>
|
|
31
|
+
<div role="tabpanel">Zero runtime by default.</div>
|
|
32
|
+
<div role="tabpanel"><code>npm i hydrateless</code></div>
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
<div use:dropdown data-hl-dropdown>
|
|
36
|
+
<button data-hl-dropdown-trigger>Actions</button>
|
|
37
|
+
<ul data-hl-dropdown-menu>
|
|
38
|
+
<li><button role="menuitem">Edit</button></li>
|
|
39
|
+
<li><button role="menuitem">Delete</button></li>
|
|
40
|
+
</ul>
|
|
41
|
+
</div>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Available actions: `accordion`, `disclosure`, `tabs`, `dropdown`, `modal`,
|
|
45
|
+
`drawer`, `popover`, `tooltip`, `toc`. For container-scoped components (modal,
|
|
46
|
+
drawer, popover, tooltip) put the action on a wrapper that contains the trigger
|
|
47
|
+
and target.
|
|
48
|
+
|
|
49
|
+
## Toasts
|
|
50
|
+
|
|
51
|
+
```svelte
|
|
52
|
+
<script lang="ts">
|
|
53
|
+
import { onMount, onDestroy } from 'svelte';
|
|
54
|
+
import { createToast } from '@hydrateless/svelte';
|
|
55
|
+
|
|
56
|
+
let toast: ReturnType<typeof createToast>;
|
|
57
|
+
onMount(() => (toast = createToast()));
|
|
58
|
+
onDestroy(() => toast?.destroy());
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
<button on:click={() => toast.show('Saved')}>Save</button>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
[MIT](../../LICENSE)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Action } from 'svelte/action';
|
|
2
|
+
import { ToastApi } from '@hydrateless/enhancers';
|
|
3
|
+
export { Disposer } from '@hydrateless/enhancers';
|
|
4
|
+
|
|
5
|
+
/** `use:accordion` — single-open behavior on a `[data-hl-accordion]` element. */
|
|
6
|
+
declare const accordion: Action<HTMLElement, undefined, Record<never, any>>;
|
|
7
|
+
/** `use:disclosure` — groups `[data-hl-disclosure]` elements within the node. */
|
|
8
|
+
declare const disclosure: Action<HTMLElement, undefined, Record<never, any>>;
|
|
9
|
+
/** `use:tabs` — ARIA + keyboard navigation on a `[data-hl-tabs]` element. */
|
|
10
|
+
declare const tabs: Action<HTMLElement, undefined, Record<never, any>>;
|
|
11
|
+
/** `use:dropdown` — menu pattern on a `[data-hl-dropdown]` element. */
|
|
12
|
+
declare const dropdown: Action<HTMLElement, undefined, Record<never, any>>;
|
|
13
|
+
/** `use:modal` — wires modal openers/closers + focus trap within the node. */
|
|
14
|
+
declare const modal: Action<HTMLElement, undefined, Record<never, any>>;
|
|
15
|
+
/** `use:drawer` — wires drawer openers/closers within the node. */
|
|
16
|
+
declare const drawer: Action<HTMLElement, undefined, Record<never, any>>;
|
|
17
|
+
/** `use:popover` — wires popover openers/closers within the node. */
|
|
18
|
+
declare const popover: Action<HTMLElement, undefined, Record<never, any>>;
|
|
19
|
+
/** `use:tooltip` — wires `[data-hl-tooltip]` triggers within the node. */
|
|
20
|
+
declare const tooltip: Action<HTMLElement, undefined, Record<never, any>>;
|
|
21
|
+
/** `use:toc` — builds a table of contents from the surrounding document. */
|
|
22
|
+
declare const toc: Action<HTMLElement, undefined, Record<never, any>>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Create a toast controller. Call in `onMount` and tear down in `onDestroy`:
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { onMount, onDestroy } from 'svelte';
|
|
29
|
+
* import { createToast } from '@hydrateless/svelte';
|
|
30
|
+
*
|
|
31
|
+
* let toast: ReturnType<typeof createToast>;
|
|
32
|
+
* onMount(() => (toast = createToast()));
|
|
33
|
+
* onDestroy(() => toast?.destroy());
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare function createToast(container?: Document | HTMLElement): ToastApi;
|
|
37
|
+
|
|
38
|
+
export { accordion, createToast, disclosure, drawer, dropdown, modal, popover, tabs, toc, tooltip };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// src/actions.ts
|
|
2
|
+
import {
|
|
3
|
+
enhanceAccordion,
|
|
4
|
+
enhanceDisclosure,
|
|
5
|
+
enhanceDropdown,
|
|
6
|
+
enhanceDrawer,
|
|
7
|
+
enhanceModal,
|
|
8
|
+
enhancePopover,
|
|
9
|
+
enhanceTabs,
|
|
10
|
+
enhanceToc,
|
|
11
|
+
enhanceTooltip
|
|
12
|
+
} from "@hydrateless/enhancers";
|
|
13
|
+
function actionFor(enhance) {
|
|
14
|
+
return (node) => {
|
|
15
|
+
const dispose = enhance(node);
|
|
16
|
+
return {
|
|
17
|
+
destroy() {
|
|
18
|
+
dispose();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
var accordion = actionFor((node) => enhanceAccordion(node));
|
|
24
|
+
var disclosure = actionFor((node) => enhanceDisclosure(node));
|
|
25
|
+
var tabs = actionFor((node) => enhanceTabs(node));
|
|
26
|
+
var dropdown = actionFor((node) => enhanceDropdown(node));
|
|
27
|
+
var modal = actionFor((node) => enhanceModal(node));
|
|
28
|
+
var drawer = actionFor((node) => enhanceDrawer(node));
|
|
29
|
+
var popover = actionFor((node) => enhancePopover(node));
|
|
30
|
+
var tooltip = actionFor((node) => enhanceTooltip(node));
|
|
31
|
+
var toc = actionFor((node) => enhanceToc(node.ownerDocument));
|
|
32
|
+
|
|
33
|
+
// src/toast.ts
|
|
34
|
+
import { enhanceToast } from "@hydrateless/enhancers";
|
|
35
|
+
function createToast(container = document) {
|
|
36
|
+
return enhanceToast(container);
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
accordion,
|
|
40
|
+
createToast,
|
|
41
|
+
disclosure,
|
|
42
|
+
drawer,
|
|
43
|
+
dropdown,
|
|
44
|
+
modal,
|
|
45
|
+
popover,
|
|
46
|
+
tabs,
|
|
47
|
+
toc,
|
|
48
|
+
tooltip
|
|
49
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hydrateless/svelte",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Svelte bindings for Hydrateless — actions that wire the framework-agnostic enhancers.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/hydrateless/hydrateless.git",
|
|
9
|
+
"directory": "packages/svelte"
|
|
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 svelte",
|
|
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
|
+
"svelte": ">=4"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"jsdom": "^29.0.0",
|
|
38
|
+
"svelte": "^5.0.0",
|
|
39
|
+
"vitest": "^4.1.0"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
}
|
|
44
|
+
}
|