flexui-svelte 0.0.0-stage → 2.0.0-alpha.1
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/index.d.ts +36 -0
- package/dist/index.js +59 -0
- package/package.json +39 -6
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Svelte actions for `@flexui/runtime`.
|
|
3
|
+
*
|
|
4
|
+
* ```svelte
|
|
5
|
+
* <script>
|
|
6
|
+
* import { dialog, dropdown, tabs } from "@flexui/svelte";
|
|
7
|
+
* </script>
|
|
8
|
+
*
|
|
9
|
+
* <dialog class="fui-dialog" use:dialog={{ closeOnBackdrop: true }}>…</dialog>
|
|
10
|
+
* <button class="fui-btn" use:dropdown={"#account-menu"}>Account</button>
|
|
11
|
+
* <div class="fui-tabs" data-fui-tabs use:tabs>…</div>
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Actions need no Svelte imports, so the package has no build-time dependency
|
|
15
|
+
* on the framework and works with Svelte 4 and 5 component syntax alike.
|
|
16
|
+
* Parameters are read once, when the action runs.
|
|
17
|
+
*/
|
|
18
|
+
import { bindDialog, type DialogOptions } from "@flexui/runtime/dialog";
|
|
19
|
+
import { bindDropdown, type DropdownOptions } from "@flexui/runtime/dropdown";
|
|
20
|
+
import { bindPopover, type PopoverOptions } from "@flexui/runtime/popover";
|
|
21
|
+
import { bindTabs } from "@flexui/runtime/tabs";
|
|
22
|
+
/** The shape Svelte uses for an action's return value. */
|
|
23
|
+
export interface Action<Params = undefined> {
|
|
24
|
+
update?(params: Params): void;
|
|
25
|
+
destroy?(): void;
|
|
26
|
+
}
|
|
27
|
+
/** Binds a native `<dialog>`. */
|
|
28
|
+
export declare function dialog(node: HTMLDialogElement, options?: DialogOptions): Action<DialogOptions>;
|
|
29
|
+
/** Binds a trigger to a menu element or an id. */
|
|
30
|
+
export declare function dropdown(node: HTMLElement, menu: string | HTMLElement | null, options?: DropdownOptions): Action<string | HTMLElement | null>;
|
|
31
|
+
/** Binds a trigger to a `popover` panel element or an id. */
|
|
32
|
+
export declare function popover(node: HTMLElement, panel: string | HTMLElement | null, options?: PopoverOptions): Action<string | HTMLElement | null>;
|
|
33
|
+
/** Binds an ARIA tablist container. */
|
|
34
|
+
export declare function tabs(node: HTMLElement): Action<undefined>;
|
|
35
|
+
export { bindDialog, bindDropdown, bindPopover, bindTabs };
|
|
36
|
+
export type { DialogOptions, DropdownOptions, PopoverOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Svelte actions for `@flexui/runtime`.
|
|
3
|
+
*
|
|
4
|
+
* ```svelte
|
|
5
|
+
* <script>
|
|
6
|
+
* import { dialog, dropdown, tabs } from "@flexui/svelte";
|
|
7
|
+
* </script>
|
|
8
|
+
*
|
|
9
|
+
* <dialog class="fui-dialog" use:dialog={{ closeOnBackdrop: true }}>…</dialog>
|
|
10
|
+
* <button class="fui-btn" use:dropdown={"#account-menu"}>Account</button>
|
|
11
|
+
* <div class="fui-tabs" data-fui-tabs use:tabs>…</div>
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Actions need no Svelte imports, so the package has no build-time dependency
|
|
15
|
+
* on the framework and works with Svelte 4 and 5 component syntax alike.
|
|
16
|
+
* Parameters are read once, when the action runs.
|
|
17
|
+
*/
|
|
18
|
+
import { bindDialog } from "@flexui/runtime/dialog";
|
|
19
|
+
import { bindDropdown } from "@flexui/runtime/dropdown";
|
|
20
|
+
import { bindPopover } from "@flexui/runtime/popover";
|
|
21
|
+
import { bindTabs } from "@flexui/runtime/tabs";
|
|
22
|
+
function noop() {
|
|
23
|
+
// Actions without a parameter still need a destroy hook.
|
|
24
|
+
}
|
|
25
|
+
/** Binds a native `<dialog>`. */
|
|
26
|
+
export function dialog(node, options = {}) {
|
|
27
|
+
const controller = bindDialog(node, options);
|
|
28
|
+
return { destroy: () => controller.dispose() };
|
|
29
|
+
}
|
|
30
|
+
/** Binds a trigger to a menu element or an id. */
|
|
31
|
+
export function dropdown(node, menu, options = {}) {
|
|
32
|
+
if (menu === null) {
|
|
33
|
+
return { destroy: noop };
|
|
34
|
+
}
|
|
35
|
+
const target = typeof menu === "string" ? document.getElementById(menu.replace(/^#/, "")) : menu;
|
|
36
|
+
if (target === null) {
|
|
37
|
+
return { destroy: noop };
|
|
38
|
+
}
|
|
39
|
+
const controller = bindDropdown(node, target, options);
|
|
40
|
+
return { destroy: () => controller.dispose() };
|
|
41
|
+
}
|
|
42
|
+
/** Binds a trigger to a `popover` panel element or an id. */
|
|
43
|
+
export function popover(node, panel, options = {}) {
|
|
44
|
+
if (panel === null) {
|
|
45
|
+
return { destroy: noop };
|
|
46
|
+
}
|
|
47
|
+
const target = typeof panel === "string" ? document.getElementById(panel.replace(/^#/, "")) : panel;
|
|
48
|
+
if (target === null) {
|
|
49
|
+
return { destroy: noop };
|
|
50
|
+
}
|
|
51
|
+
const controller = bindPopover(node, target, options);
|
|
52
|
+
return { destroy: () => controller.dispose() };
|
|
53
|
+
}
|
|
54
|
+
/** Binds an ARIA tablist container. */
|
|
55
|
+
export function tabs(node) {
|
|
56
|
+
const controller = bindTabs(node);
|
|
57
|
+
return { destroy: () => controller.dispose() };
|
|
58
|
+
}
|
|
59
|
+
export { bindDialog, bindDropdown, bindPopover, bindTabs };
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "flexui-svelte",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "flexui-svelte",
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
|
+
"description": "Svelte actions 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.1"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"svelte": ">=4.0.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependenciesMeta": {
|
|
30
|
+
"svelte": {
|
|
31
|
+
"optional": true
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"flexui",
|
|
36
|
+
"svelte",
|
|
37
|
+
"actions"
|
|
38
|
+
]
|
|
39
|
+
}
|
package/README.md
DELETED