@omicronenergy/oscd-ui 0.0.13 → 0.0.14
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/CHANGELOG.md +9 -0
- package/custom-elements.json +8243 -5766
- package/dist/decorators/localstorage.d.ts +8 -0
- package/dist/decorators/localstorage.js +136 -0
- package/dist/decorators/localstorage.js.map +1 -0
- package/dist/decorators/localstorage.spec.d.ts +1 -0
- package/dist/decorators/localstorage.spec.js +138 -0
- package/dist/decorators/localstorage.spec.js.map +1 -0
- package/dist/snackbar/OscdSnackbar.d.ts +133 -0
- package/dist/snackbar/OscdSnackbar.js +505 -0
- package/dist/snackbar/OscdSnackbar.js.map +1 -0
- package/dist/snackbar/OscdSnackbar.spec.d.ts +1 -0
- package/dist/snackbar/OscdSnackbar.spec.js +287 -0
- package/dist/snackbar/OscdSnackbar.spec.js.map +1 -0
- package/dist/snackbar/OscdSnackbar.stories.d.ts +22 -0
- package/dist/snackbar/OscdSnackbar.stories.js +214 -0
- package/dist/snackbar/OscdSnackbar.stories.js.map +1 -0
- package/dist/snackbar/oscd-snackbar.d.ts +2 -0
- package/dist/snackbar/oscd-snackbar.js +4 -0
- package/dist/snackbar/oscd-snackbar.js.map +1 -0
- package/dist/tree/OscdTree.d.ts +81 -0
- package/dist/tree/OscdTree.js +76 -0
- package/dist/tree/OscdTree.js.map +1 -0
- package/dist/tree/OscdTree.stories.d.ts +59 -0
- package/dist/tree/OscdTree.stories.js +341 -0
- package/dist/tree/OscdTree.stories.js.map +1 -0
- package/dist/tree/OscdTreeItem.d.ts +43 -0
- package/dist/tree/OscdTreeItem.js +39 -0
- package/dist/tree/OscdTreeItem.js.map +1 -0
- package/dist/tree/internal/Tree.d.ts +186 -0
- package/dist/tree/internal/Tree.js +590 -0
- package/dist/tree/internal/Tree.js.map +1 -0
- package/dist/tree/internal/TreeItem.d.ts +25 -0
- package/dist/tree/internal/TreeItem.js +200 -0
- package/dist/tree/internal/TreeItem.js.map +1 -0
- package/dist/tree/oscd-tree-item.d.ts +2 -0
- package/dist/tree/oscd-tree-item.js +4 -0
- package/dist/tree/oscd-tree-item.js.map +1 -0
- package/dist/tree/oscd-tree.d.ts +3 -0
- package/dist/tree/oscd-tree.js +5 -0
- package/dist/tree/oscd-tree.js.map +1 -0
- package/package.json +8 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Tree } from './internal/Tree.js';
|
|
2
|
+
export type { TreeChildrenState, TreeNode, TreeNodeEventDetail, TreeRenderContext, TreeSelectionChangeEventDetail, TreeSelectionMode, } from './internal/Tree.js';
|
|
3
|
+
declare global {
|
|
4
|
+
interface HTMLElementTagNameMap {
|
|
5
|
+
'oscd-tree': OscdTree;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Displays hierarchical data as an accessible, keyboard-navigable tree.
|
|
10
|
+
*
|
|
11
|
+
* `oscd-tree` is data-driven: callers provide nested node data through `data`,
|
|
12
|
+
* and the tree manages expansion, selection, active-row navigation, row
|
|
13
|
+
* indentation, and ARIA attributes. Row content stays flexible through the
|
|
14
|
+
* `renderItem` callback.
|
|
15
|
+
*
|
|
16
|
+
* The tree owns the row frame. This includes indentation, expand/collapse
|
|
17
|
+
* affordances, selection affordances, keyboard handling, focus handling, and
|
|
18
|
+
* accessibility attributes. `renderItem` only supplies the content rendered
|
|
19
|
+
* inside each row frame.
|
|
20
|
+
*
|
|
21
|
+
* Every node may provide a stable `id`. If no ID is supplied, the tree uses
|
|
22
|
+
* `getNodeId` when provided, then falls back to an index-path ID such as
|
|
23
|
+
* `0/1/2`. Index-path IDs are convenient for static demos but are not stable
|
|
24
|
+
* when nodes are inserted, removed, sorted, filtered, or lazily loaded, and
|
|
25
|
+
* should not be persisted.
|
|
26
|
+
*
|
|
27
|
+
* `selectedIds` and `expandedIds` are controlled state. They can be persisted
|
|
28
|
+
* by the caller, but persisted IDs must be scoped to the data set/context that
|
|
29
|
+
* produced them. Reset or re-key those arrays when `data` changes to a
|
|
30
|
+
* different logical tree, otherwise unrelated nodes with matching IDs may
|
|
31
|
+
* appear selected or expanded.
|
|
32
|
+
*
|
|
33
|
+
* `children` has three meanings:
|
|
34
|
+
*
|
|
35
|
+
* - `children === undefined`: children are unknown or not loaded yet.
|
|
36
|
+
* - `children === []`: children are known and the node is a leaf.
|
|
37
|
+
* - `children.length > 0`: children are known and the node is a branch.
|
|
38
|
+
*
|
|
39
|
+
* Expansion of nodes with unknown children can be intercepted with the
|
|
40
|
+
* cancelable `node-expand` event.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* type Node = TreeNode & {
|
|
45
|
+
* label: string;
|
|
46
|
+
* children?: Node[];
|
|
47
|
+
* };
|
|
48
|
+
*
|
|
49
|
+
* const data: Node[] = [
|
|
50
|
+
* {
|
|
51
|
+
* id: 'ied:PUB_A',
|
|
52
|
+
* label: 'PUB_A',
|
|
53
|
+
* children: [{ id: 'ln:TCTR1', label: 'TCTR1', children: [] }],
|
|
54
|
+
* },
|
|
55
|
+
* ];
|
|
56
|
+
*
|
|
57
|
+
* html`
|
|
58
|
+
* <oscd-tree
|
|
59
|
+
* .data=${data}
|
|
60
|
+
* .expandedIds=${['ied:PUB_A']}
|
|
61
|
+
* .renderItem=${({ node }) => html`
|
|
62
|
+
* <oscd-tree-item>
|
|
63
|
+
* <span slot="headline">${node.label}</span>
|
|
64
|
+
* </oscd-tree-item>
|
|
65
|
+
* `}
|
|
66
|
+
* ></oscd-tree>
|
|
67
|
+
* `;
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @fires selected-ids-changed - Fired when user interaction changes selected IDs.
|
|
71
|
+
* @fires expanded-ids-changed - Fired when expansion state changes.
|
|
72
|
+
* @fires node-click - Fired when a row is clicked.
|
|
73
|
+
* @fires node-activate - Fired when a row is activated with the keyboard.
|
|
74
|
+
* @fires node-expand - Cancelable event fired before a row expands.
|
|
75
|
+
* @fires node-collapse - Fired after a row collapses.
|
|
76
|
+
* @fires node-toggle - Fired after a row expansion state toggles.
|
|
77
|
+
*
|
|
78
|
+
* @tagname oscd-tree
|
|
79
|
+
*/
|
|
80
|
+
export declare class OscdTree extends Tree {
|
|
81
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Tree } from './internal/Tree.js';
|
|
2
|
+
/**
|
|
3
|
+
* Displays hierarchical data as an accessible, keyboard-navigable tree.
|
|
4
|
+
*
|
|
5
|
+
* `oscd-tree` is data-driven: callers provide nested node data through `data`,
|
|
6
|
+
* and the tree manages expansion, selection, active-row navigation, row
|
|
7
|
+
* indentation, and ARIA attributes. Row content stays flexible through the
|
|
8
|
+
* `renderItem` callback.
|
|
9
|
+
*
|
|
10
|
+
* The tree owns the row frame. This includes indentation, expand/collapse
|
|
11
|
+
* affordances, selection affordances, keyboard handling, focus handling, and
|
|
12
|
+
* accessibility attributes. `renderItem` only supplies the content rendered
|
|
13
|
+
* inside each row frame.
|
|
14
|
+
*
|
|
15
|
+
* Every node may provide a stable `id`. If no ID is supplied, the tree uses
|
|
16
|
+
* `getNodeId` when provided, then falls back to an index-path ID such as
|
|
17
|
+
* `0/1/2`. Index-path IDs are convenient for static demos but are not stable
|
|
18
|
+
* when nodes are inserted, removed, sorted, filtered, or lazily loaded, and
|
|
19
|
+
* should not be persisted.
|
|
20
|
+
*
|
|
21
|
+
* `selectedIds` and `expandedIds` are controlled state. They can be persisted
|
|
22
|
+
* by the caller, but persisted IDs must be scoped to the data set/context that
|
|
23
|
+
* produced them. Reset or re-key those arrays when `data` changes to a
|
|
24
|
+
* different logical tree, otherwise unrelated nodes with matching IDs may
|
|
25
|
+
* appear selected or expanded.
|
|
26
|
+
*
|
|
27
|
+
* `children` has three meanings:
|
|
28
|
+
*
|
|
29
|
+
* - `children === undefined`: children are unknown or not loaded yet.
|
|
30
|
+
* - `children === []`: children are known and the node is a leaf.
|
|
31
|
+
* - `children.length > 0`: children are known and the node is a branch.
|
|
32
|
+
*
|
|
33
|
+
* Expansion of nodes with unknown children can be intercepted with the
|
|
34
|
+
* cancelable `node-expand` event.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* type Node = TreeNode & {
|
|
39
|
+
* label: string;
|
|
40
|
+
* children?: Node[];
|
|
41
|
+
* };
|
|
42
|
+
*
|
|
43
|
+
* const data: Node[] = [
|
|
44
|
+
* {
|
|
45
|
+
* id: 'ied:PUB_A',
|
|
46
|
+
* label: 'PUB_A',
|
|
47
|
+
* children: [{ id: 'ln:TCTR1', label: 'TCTR1', children: [] }],
|
|
48
|
+
* },
|
|
49
|
+
* ];
|
|
50
|
+
*
|
|
51
|
+
* html`
|
|
52
|
+
* <oscd-tree
|
|
53
|
+
* .data=${data}
|
|
54
|
+
* .expandedIds=${['ied:PUB_A']}
|
|
55
|
+
* .renderItem=${({ node }) => html`
|
|
56
|
+
* <oscd-tree-item>
|
|
57
|
+
* <span slot="headline">${node.label}</span>
|
|
58
|
+
* </oscd-tree-item>
|
|
59
|
+
* `}
|
|
60
|
+
* ></oscd-tree>
|
|
61
|
+
* `;
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* @fires selected-ids-changed - Fired when user interaction changes selected IDs.
|
|
65
|
+
* @fires expanded-ids-changed - Fired when expansion state changes.
|
|
66
|
+
* @fires node-click - Fired when a row is clicked.
|
|
67
|
+
* @fires node-activate - Fired when a row is activated with the keyboard.
|
|
68
|
+
* @fires node-expand - Cancelable event fired before a row expands.
|
|
69
|
+
* @fires node-collapse - Fired after a row collapses.
|
|
70
|
+
* @fires node-toggle - Fired after a row expansion state toggles.
|
|
71
|
+
*
|
|
72
|
+
* @tagname oscd-tree
|
|
73
|
+
*/
|
|
74
|
+
export class OscdTree extends Tree {
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=OscdTree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OscdTree.js","sourceRoot":"","sources":["../../tree/OscdTree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAgB1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;AACH,MAAM,OAAO,QAAS,SAAQ,IAAI;CAAG","sourcesContent":["import { Tree } from './internal/Tree.js';\nexport type {\n TreeChildrenState,\n TreeNode,\n TreeNodeEventDetail,\n TreeRenderContext,\n TreeSelectionChangeEventDetail,\n TreeSelectionMode,\n} from './internal/Tree.js';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'oscd-tree': OscdTree;\n }\n}\n\n/**\n * Displays hierarchical data as an accessible, keyboard-navigable tree.\n *\n * `oscd-tree` is data-driven: callers provide nested node data through `data`,\n * and the tree manages expansion, selection, active-row navigation, row\n * indentation, and ARIA attributes. Row content stays flexible through the\n * `renderItem` callback.\n *\n * The tree owns the row frame. This includes indentation, expand/collapse\n * affordances, selection affordances, keyboard handling, focus handling, and\n * accessibility attributes. `renderItem` only supplies the content rendered\n * inside each row frame.\n *\n * Every node may provide a stable `id`. If no ID is supplied, the tree uses\n * `getNodeId` when provided, then falls back to an index-path ID such as\n * `0/1/2`. Index-path IDs are convenient for static demos but are not stable\n * when nodes are inserted, removed, sorted, filtered, or lazily loaded, and\n * should not be persisted.\n *\n * `selectedIds` and `expandedIds` are controlled state. They can be persisted\n * by the caller, but persisted IDs must be scoped to the data set/context that\n * produced them. Reset or re-key those arrays when `data` changes to a\n * different logical tree, otherwise unrelated nodes with matching IDs may\n * appear selected or expanded.\n *\n * `children` has three meanings:\n *\n * - `children === undefined`: children are unknown or not loaded yet.\n * - `children === []`: children are known and the node is a leaf.\n * - `children.length > 0`: children are known and the node is a branch.\n *\n * Expansion of nodes with unknown children can be intercepted with the\n * cancelable `node-expand` event.\n *\n * @example\n * ```ts\n * type Node = TreeNode & {\n * label: string;\n * children?: Node[];\n * };\n *\n * const data: Node[] = [\n * {\n * id: 'ied:PUB_A',\n * label: 'PUB_A',\n * children: [{ id: 'ln:TCTR1', label: 'TCTR1', children: [] }],\n * },\n * ];\n *\n * html`\n * <oscd-tree\n * .data=${data}\n * .expandedIds=${['ied:PUB_A']}\n * .renderItem=${({ node }) => html`\n * <oscd-tree-item>\n * <span slot=\"headline\">${node.label}</span>\n * </oscd-tree-item>\n * `}\n * ></oscd-tree>\n * `;\n * ```\n *\n * @fires selected-ids-changed - Fired when user interaction changes selected IDs.\n * @fires expanded-ids-changed - Fired when expansion state changes.\n * @fires node-click - Fired when a row is clicked.\n * @fires node-activate - Fired when a row is activated with the keyboard.\n * @fires node-expand - Cancelable event fired before a row expands.\n * @fires node-collapse - Fired after a row collapses.\n * @fires node-toggle - Fired after a row expansion state toggles.\n *\n * @tagname oscd-tree\n */\nexport class OscdTree extends Tree {}\n"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { StoryObj } from '@storybook/web-components-vite';
|
|
2
|
+
import { OscdTree } from './OscdTree.js';
|
|
3
|
+
import './oscd-tree.js';
|
|
4
|
+
import '../icon/oscd-icon.js';
|
|
5
|
+
import '../textfield/oscd-outlined-text-field.js';
|
|
6
|
+
declare const _default: {
|
|
7
|
+
title: string;
|
|
8
|
+
tags: string[];
|
|
9
|
+
id?: import("storybook/internal/csf").ComponentId;
|
|
10
|
+
includeStories?: RegExp | string[];
|
|
11
|
+
excludeStories?: RegExp | string[];
|
|
12
|
+
component?: string | undefined;
|
|
13
|
+
subcomponents?: Record<string, string> | undefined;
|
|
14
|
+
play?: import("storybook/internal/csf").PlayFunction<import("@storybook/web-components-vite").WebComponentsRenderer, OscdTree & {
|
|
15
|
+
textContent: string;
|
|
16
|
+
}> | undefined;
|
|
17
|
+
globals?: import("storybook/internal/csf").Globals | undefined;
|
|
18
|
+
decorators?: import("storybook/internal/csf").DecoratorFunction<import("@storybook/web-components-vite").WebComponentsRenderer, OscdTree & {
|
|
19
|
+
textContent: string;
|
|
20
|
+
}> | import("storybook/internal/csf").DecoratorFunction<import("@storybook/web-components-vite").WebComponentsRenderer, OscdTree & {
|
|
21
|
+
textContent: string;
|
|
22
|
+
}>[] | undefined;
|
|
23
|
+
parameters?: import("@storybook/web-components-vite").Parameters | undefined;
|
|
24
|
+
args?: Partial<OscdTree & {
|
|
25
|
+
textContent: string;
|
|
26
|
+
}> | undefined;
|
|
27
|
+
argTypes?: Partial<import("@storybook/web-components-vite").ArgTypes<OscdTree & {
|
|
28
|
+
textContent: string;
|
|
29
|
+
}>> | undefined;
|
|
30
|
+
loaders?: import("storybook/internal/csf").LoaderFunction<import("@storybook/web-components-vite").WebComponentsRenderer, OscdTree & {
|
|
31
|
+
textContent: string;
|
|
32
|
+
}> | import("storybook/internal/csf").LoaderFunction<import("@storybook/web-components-vite").WebComponentsRenderer, OscdTree & {
|
|
33
|
+
textContent: string;
|
|
34
|
+
}>[] | undefined;
|
|
35
|
+
beforeEach?: import("storybook/internal/csf").BeforeEach<import("@storybook/web-components-vite").WebComponentsRenderer, OscdTree & {
|
|
36
|
+
textContent: string;
|
|
37
|
+
}> | import("storybook/internal/csf").BeforeEach<import("@storybook/web-components-vite").WebComponentsRenderer, OscdTree & {
|
|
38
|
+
textContent: string;
|
|
39
|
+
}>[] | undefined;
|
|
40
|
+
afterEach?: import("storybook/internal/csf").AfterEach<import("@storybook/web-components-vite").WebComponentsRenderer, OscdTree & {
|
|
41
|
+
textContent: string;
|
|
42
|
+
}> | import("storybook/internal/csf").AfterEach<import("@storybook/web-components-vite").WebComponentsRenderer, OscdTree & {
|
|
43
|
+
textContent: string;
|
|
44
|
+
}>[] | undefined;
|
|
45
|
+
render?: import("storybook/internal/csf").ArgsStoryFn<import("@storybook/web-components-vite").WebComponentsRenderer, OscdTree & {
|
|
46
|
+
textContent: string;
|
|
47
|
+
}> | undefined;
|
|
48
|
+
mount?: ((context: import("storybook/internal/csf").StoryContext<import("@storybook/web-components-vite").WebComponentsRenderer, OscdTree & {
|
|
49
|
+
textContent: string;
|
|
50
|
+
}>) => () => Promise<import("storybook/internal/csf").Canvas>) | undefined;
|
|
51
|
+
};
|
|
52
|
+
export default _default;
|
|
53
|
+
export declare const Default: StoryObj;
|
|
54
|
+
export declare const MultipleSelection: StoryObj;
|
|
55
|
+
export declare const SingleSelection: StoryObj;
|
|
56
|
+
export declare const DisabledRows: StoryObj;
|
|
57
|
+
export declare const UnknownChildren: StoryObj;
|
|
58
|
+
export declare const DerivedIds: StoryObj;
|
|
59
|
+
export declare const Filtered: StoryObj;
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { html } from 'lit';
|
|
2
|
+
import { action } from 'storybook/internal/actions';
|
|
3
|
+
import { useArgs } from 'storybook/preview-api';
|
|
4
|
+
import { getStorybookMeta } from '@/utils/storybook/getStorybookMeta.js';
|
|
5
|
+
import './oscd-tree.js';
|
|
6
|
+
import '../icon/oscd-icon.js';
|
|
7
|
+
import '../textfield/oscd-outlined-text-field.js';
|
|
8
|
+
const { args, argTypes, meta } = getStorybookMeta({
|
|
9
|
+
tagName: 'oscd-tree',
|
|
10
|
+
});
|
|
11
|
+
const sampleTree = [
|
|
12
|
+
{
|
|
13
|
+
id: 'ied:PUB_A',
|
|
14
|
+
label: 'PUB_A',
|
|
15
|
+
description: 'Publisher IED',
|
|
16
|
+
kind: 'ied',
|
|
17
|
+
children: [
|
|
18
|
+
{
|
|
19
|
+
id: 'ap:PUB_A/AP1',
|
|
20
|
+
label: 'AP1',
|
|
21
|
+
description: 'Access point',
|
|
22
|
+
kind: 'access-point',
|
|
23
|
+
children: [
|
|
24
|
+
{
|
|
25
|
+
id: 'ld:PUB_A/AP1/LD_A',
|
|
26
|
+
label: 'LD_A',
|
|
27
|
+
description: 'Logical device',
|
|
28
|
+
kind: 'l-device',
|
|
29
|
+
children: [
|
|
30
|
+
{
|
|
31
|
+
id: 'ln:PUB_A|AP1|LD_A||LLN0|',
|
|
32
|
+
label: 'LLN0',
|
|
33
|
+
description: 'Logical node zero',
|
|
34
|
+
kind: 'logical-node',
|
|
35
|
+
children: [],
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: 'ln:PUB_A|AP1|LD_A||TCTR|1',
|
|
39
|
+
label: 'TCTR1',
|
|
40
|
+
description: 'Current transformer',
|
|
41
|
+
kind: 'logical-node',
|
|
42
|
+
children: [],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: 'ln:PUB_A|AP1|LD_A||XCBR|1',
|
|
46
|
+
label: 'XCBR1',
|
|
47
|
+
description: 'Circuit breaker',
|
|
48
|
+
kind: 'logical-node',
|
|
49
|
+
children: [],
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: 'ied:PUB_B',
|
|
59
|
+
label: 'PUB_B',
|
|
60
|
+
description: 'Publisher IED',
|
|
61
|
+
kind: 'ied',
|
|
62
|
+
children: [
|
|
63
|
+
{
|
|
64
|
+
id: 'ap:PUB_B/AP1',
|
|
65
|
+
label: 'AP1',
|
|
66
|
+
description: 'Access point',
|
|
67
|
+
kind: 'access-point',
|
|
68
|
+
children: [
|
|
69
|
+
{
|
|
70
|
+
id: 'ld:PUB_B/AP1/LD_B',
|
|
71
|
+
label: 'LD_B',
|
|
72
|
+
description: 'Logical device',
|
|
73
|
+
kind: 'l-device',
|
|
74
|
+
children: [
|
|
75
|
+
{
|
|
76
|
+
id: 'ln:PUB_B|AP1|LD_B||LLN0|',
|
|
77
|
+
label: 'LLN0',
|
|
78
|
+
description: 'Logical node zero',
|
|
79
|
+
kind: 'logical-node',
|
|
80
|
+
children: [],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: 'ln:PUB_B|AP1|LD_B||TCTR|1',
|
|
84
|
+
label: 'TCTR1',
|
|
85
|
+
description: 'Current transformer',
|
|
86
|
+
kind: 'logical-node',
|
|
87
|
+
children: [],
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
];
|
|
96
|
+
const treeWithUnknownChildren = [
|
|
97
|
+
...sampleTree,
|
|
98
|
+
{
|
|
99
|
+
id: 'ied:REMOTE',
|
|
100
|
+
label: 'REMOTE',
|
|
101
|
+
description: 'Children are not loaded yet',
|
|
102
|
+
kind: 'ied',
|
|
103
|
+
},
|
|
104
|
+
];
|
|
105
|
+
const kindIcon = (kind) => {
|
|
106
|
+
switch (kind) {
|
|
107
|
+
case 'ied':
|
|
108
|
+
return 'reportIcon';
|
|
109
|
+
case 'access-point':
|
|
110
|
+
return 'lan';
|
|
111
|
+
case 'l-device':
|
|
112
|
+
return 'dns';
|
|
113
|
+
case 'logical-node':
|
|
114
|
+
return 'article';
|
|
115
|
+
default:
|
|
116
|
+
return 'circle';
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const renderDemoItem = ({ node, selected, active, disabled, }) => html `<oscd-tree-item
|
|
120
|
+
?selected=${selected}
|
|
121
|
+
?active=${active}
|
|
122
|
+
?disabled=${disabled}
|
|
123
|
+
>
|
|
124
|
+
<oscd-icon slot="start">${kindIcon(node.kind)}</oscd-icon>
|
|
125
|
+
<span slot="headline">${node.label}</span>
|
|
126
|
+
<span slot="supporting-text">${node.description}</span>
|
|
127
|
+
</oscd-tree-item>`;
|
|
128
|
+
const renderCompactItem = ({ node, childrenState, selected, disabled, }) => html `<oscd-tree-item ?selected=${selected} ?disabled=${disabled}>
|
|
129
|
+
<span slot="headline">${node.label}</span>
|
|
130
|
+
<span slot="supporting-text">${node.kind} / ${childrenState}</span>
|
|
131
|
+
</oscd-tree-item>`;
|
|
132
|
+
const matchesFilter = (node, filter) => {
|
|
133
|
+
const needle = filter.trim().toLowerCase();
|
|
134
|
+
if (!needle) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
return [node.label, node.description, node.kind, node.id]
|
|
138
|
+
.filter((term) => !!term)
|
|
139
|
+
.some(term => term.toLowerCase().includes(needle));
|
|
140
|
+
};
|
|
141
|
+
const filterTree = (nodes, filter) => {
|
|
142
|
+
const needle = filter.trim();
|
|
143
|
+
if (!needle) {
|
|
144
|
+
return nodes;
|
|
145
|
+
}
|
|
146
|
+
return nodes
|
|
147
|
+
.map((node) => {
|
|
148
|
+
const children = node.children
|
|
149
|
+
? filterTree(node.children, needle)
|
|
150
|
+
: node.children;
|
|
151
|
+
const matched = matchesFilter(node, needle);
|
|
152
|
+
if (!matched && (!children || children.length === 0)) {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
const filteredNode = {
|
|
156
|
+
...node,
|
|
157
|
+
};
|
|
158
|
+
if (node.children !== undefined) {
|
|
159
|
+
filteredNode.children = children;
|
|
160
|
+
}
|
|
161
|
+
return filteredNode;
|
|
162
|
+
})
|
|
163
|
+
.filter((node) => !!node);
|
|
164
|
+
};
|
|
165
|
+
const handleSelection = (event) => {
|
|
166
|
+
action('selected-ids-changed')(event.detail.selectedIds);
|
|
167
|
+
};
|
|
168
|
+
const handleExpansion = (event) => {
|
|
169
|
+
action('expanded-ids-changed')(event.detail.expandedIds);
|
|
170
|
+
};
|
|
171
|
+
export default {
|
|
172
|
+
...meta,
|
|
173
|
+
title: 'Tree / Tree',
|
|
174
|
+
tags: ['autodocs'],
|
|
175
|
+
};
|
|
176
|
+
export const Default = {
|
|
177
|
+
argTypes,
|
|
178
|
+
args: {
|
|
179
|
+
...args,
|
|
180
|
+
['.data']: sampleTree,
|
|
181
|
+
['.expandedIds']: ['ied:PUB_A', 'ap:PUB_A/AP1'],
|
|
182
|
+
['.renderItem']: renderDemoItem,
|
|
183
|
+
},
|
|
184
|
+
render: argz => html `<div style="max-width: 520px;">
|
|
185
|
+
<oscd-tree
|
|
186
|
+
.data=${argz['.data']}
|
|
187
|
+
.expandedIds=${argz['.expandedIds']}
|
|
188
|
+
.renderItem=${argz['.renderItem']}
|
|
189
|
+
@expanded-ids-changed=${handleExpansion}
|
|
190
|
+
></oscd-tree>
|
|
191
|
+
</div>`,
|
|
192
|
+
};
|
|
193
|
+
export const MultipleSelection = {
|
|
194
|
+
argTypes,
|
|
195
|
+
args: {
|
|
196
|
+
...args,
|
|
197
|
+
['.data']: sampleTree,
|
|
198
|
+
['.expandedIds']: ['ied:PUB_A', 'ap:PUB_A/AP1', 'ld:PUB_A/AP1/LD_A'],
|
|
199
|
+
['.selectedIds']: ['ln:PUB_A|AP1|LD_A||TCTR|1'],
|
|
200
|
+
['.renderItem']: renderDemoItem,
|
|
201
|
+
selectionMode: 'multiple',
|
|
202
|
+
},
|
|
203
|
+
render: argz => html `<div style="max-width: 520px;">
|
|
204
|
+
<oscd-tree
|
|
205
|
+
selectionMode=${argz['selectionMode']}
|
|
206
|
+
.data=${argz['.data']}
|
|
207
|
+
.expandedIds=${argz['.expandedIds']}
|
|
208
|
+
.selectedIds=${argz['.selectedIds']}
|
|
209
|
+
.renderItem=${argz['.renderItem']}
|
|
210
|
+
.isSelectable=${(node) => node.kind === 'logical-node'}
|
|
211
|
+
@selected-ids-changed=${handleSelection}
|
|
212
|
+
@expanded-ids-changed=${handleExpansion}
|
|
213
|
+
></oscd-tree>
|
|
214
|
+
</div>`,
|
|
215
|
+
};
|
|
216
|
+
export const SingleSelection = {
|
|
217
|
+
argTypes,
|
|
218
|
+
args: {
|
|
219
|
+
...args,
|
|
220
|
+
['.data']: sampleTree,
|
|
221
|
+
['.expandedIds']: ['ied:PUB_A', 'ap:PUB_A/AP1', 'ld:PUB_A/AP1/LD_A'],
|
|
222
|
+
['.selectedIds']: ['ln:PUB_A|AP1|LD_A||TCTR|1'],
|
|
223
|
+
['.renderItem']: renderDemoItem,
|
|
224
|
+
selectionMode: 'single',
|
|
225
|
+
},
|
|
226
|
+
render: argz => html `<div style="max-width: 520px;">
|
|
227
|
+
<oscd-tree
|
|
228
|
+
selectionMode=${argz['selectionMode']}
|
|
229
|
+
.data=${argz['.data']}
|
|
230
|
+
.expandedIds=${argz['.expandedIds']}
|
|
231
|
+
.selectedIds=${argz['.selectedIds']}
|
|
232
|
+
.renderItem=${argz['.renderItem']}
|
|
233
|
+
.isSelectable=${(node) => node.kind === 'logical-node'}
|
|
234
|
+
@selected-ids-changed=${handleSelection}
|
|
235
|
+
@expanded-ids-changed=${handleExpansion}
|
|
236
|
+
></oscd-tree>
|
|
237
|
+
</div>`,
|
|
238
|
+
};
|
|
239
|
+
export const DisabledRows = {
|
|
240
|
+
argTypes,
|
|
241
|
+
args: {
|
|
242
|
+
...args,
|
|
243
|
+
['.data']: sampleTree,
|
|
244
|
+
['.expandedIds']: ['ied:PUB_A', 'ap:PUB_A/AP1', 'ld:PUB_A/AP1/LD_A'],
|
|
245
|
+
['.selectedIds']: ['ln:PUB_A|AP1|LD_A||TCTR|1'],
|
|
246
|
+
['.renderItem']: renderDemoItem,
|
|
247
|
+
selectionMode: 'multiple',
|
|
248
|
+
},
|
|
249
|
+
render: argz => html `<div style="max-width: 520px;">
|
|
250
|
+
<oscd-tree
|
|
251
|
+
selectionMode=${argz['selectionMode']}
|
|
252
|
+
.data=${argz['.data']}
|
|
253
|
+
.expandedIds=${argz['.expandedIds']}
|
|
254
|
+
.selectedIds=${argz['.selectedIds']}
|
|
255
|
+
.renderItem=${argz['.renderItem']}
|
|
256
|
+
.isSelectable=${(node) => node.kind === 'logical-node'}
|
|
257
|
+
.isDisabled=${(node) => node.kind === 'logical-node' &&
|
|
258
|
+
node.id !== 'ln:PUB_A|AP1|LD_A||TCTR|1'}
|
|
259
|
+
@selected-ids-changed=${handleSelection}
|
|
260
|
+
@expanded-ids-changed=${handleExpansion}
|
|
261
|
+
></oscd-tree>
|
|
262
|
+
</div>`,
|
|
263
|
+
};
|
|
264
|
+
export const UnknownChildren = {
|
|
265
|
+
argTypes,
|
|
266
|
+
args: {
|
|
267
|
+
...args,
|
|
268
|
+
['.data']: treeWithUnknownChildren,
|
|
269
|
+
['.expandedIds']: ['ied:PUB_A'],
|
|
270
|
+
['.renderItem']: renderCompactItem,
|
|
271
|
+
},
|
|
272
|
+
render: argz => html `<div style="max-width: 520px;">
|
|
273
|
+
<oscd-tree
|
|
274
|
+
.data=${argz['.data']}
|
|
275
|
+
.expandedIds=${argz['.expandedIds']}
|
|
276
|
+
.renderItem=${argz['.renderItem']}
|
|
277
|
+
@node-expand=${(event) => {
|
|
278
|
+
const customEvent = event;
|
|
279
|
+
if (customEvent.detail.id === 'ied:REMOTE') {
|
|
280
|
+
customEvent.preventDefault();
|
|
281
|
+
action('lazy node-expand prevented')(customEvent.detail.id);
|
|
282
|
+
}
|
|
283
|
+
}}
|
|
284
|
+
@expanded-ids-changed=${handleExpansion}
|
|
285
|
+
></oscd-tree>
|
|
286
|
+
</div>`,
|
|
287
|
+
};
|
|
288
|
+
export const DerivedIds = {
|
|
289
|
+
argTypes,
|
|
290
|
+
args: {
|
|
291
|
+
...args,
|
|
292
|
+
['.data']: sampleTree.map(({ id: _id, ...node }) => node),
|
|
293
|
+
['.expandedIds']: ['0', '0/0'],
|
|
294
|
+
['.renderItem']: renderDemoItem,
|
|
295
|
+
},
|
|
296
|
+
render: argz => html `<div style="max-width: 520px;">
|
|
297
|
+
<oscd-tree
|
|
298
|
+
.data=${argz['.data']}
|
|
299
|
+
.expandedIds=${argz['.expandedIds']}
|
|
300
|
+
.renderItem=${argz['.renderItem']}
|
|
301
|
+
@expanded-ids-changed=${handleExpansion}
|
|
302
|
+
></oscd-tree>
|
|
303
|
+
</div>`,
|
|
304
|
+
};
|
|
305
|
+
export const Filtered = {
|
|
306
|
+
argTypes,
|
|
307
|
+
args: {
|
|
308
|
+
...args,
|
|
309
|
+
expandedIds: ['ied:PUB_A'],
|
|
310
|
+
filter: 'TCTR',
|
|
311
|
+
},
|
|
312
|
+
render: argz => {
|
|
313
|
+
const [_, updateArgs] = useArgs();
|
|
314
|
+
const filter = String(argz['filter'] ?? '');
|
|
315
|
+
const expandedIds = argz['expandedIds'];
|
|
316
|
+
const filteredTree = filterTree(sampleTree, filter);
|
|
317
|
+
return html `<div
|
|
318
|
+
style="display: flex; flex-direction: column; gap: 12px; width: min(520px, 100%);"
|
|
319
|
+
>
|
|
320
|
+
<oscd-outlined-text-field
|
|
321
|
+
label="Filter tree"
|
|
322
|
+
.value=${filter}
|
|
323
|
+
@input=${(event) => {
|
|
324
|
+
const input = event.target;
|
|
325
|
+
action('filter input')(input.value);
|
|
326
|
+
updateArgs({ filter: input.value });
|
|
327
|
+
}}
|
|
328
|
+
></oscd-outlined-text-field>
|
|
329
|
+
<oscd-tree
|
|
330
|
+
.data=${filteredTree}
|
|
331
|
+
.expandedIds=${expandedIds}
|
|
332
|
+
.renderItem=${renderDemoItem}
|
|
333
|
+
@expanded-ids-changed=${(event) => {
|
|
334
|
+
handleExpansion(event);
|
|
335
|
+
updateArgs({ expandedIds: event.detail.expandedIds });
|
|
336
|
+
}}
|
|
337
|
+
></oscd-tree>
|
|
338
|
+
</div>`;
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
//# sourceMappingURL=OscdTree.stories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OscdTree.stories.js","sourceRoot":"","sources":["../../tree/OscdTree.stories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAE3B,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAQzE,OAAO,gBAAgB,CAAC;AACxB,OAAO,sBAAsB,CAAC;AAC9B,OAAO,0CAA0C,CAAC;AAUlD,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,gBAAgB,CAAW;IAC1D,OAAO,EAAE,WAAW;CACrB,CAAC,CAAC;AAEH,MAAM,UAAU,GAAmB;IACjC;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AAK,EAAE,CAAC,CAAC;QACtC,CAAC;;;gBAGO,YAAY;uBACL,WAAW;sBACZ,cAAc;gCACJ,CACtB,KAA6C,EAC7C,EAAE;YACF,eAAe,CAAC,KAAK,CAAC,CAAC;YACvB,UAAU,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;QACxD,CAAC;;WAEE,CAAC;IACV,CAAC;CACF,CAAC","sourcesContent":["import { html } from 'lit';\nimport type { StoryObj } from '@storybook/web-components-vite';\nimport { action } from 'storybook/internal/actions';\nimport { useArgs } from 'storybook/preview-api';\n\nimport { getStorybookMeta } from '@/utils/storybook/getStorybookMeta.js';\nimport type {\n TreeNode,\n TreeRenderContext,\n TreeSelectionChangeEventDetail,\n} from './OscdTree.js';\nimport { OscdTree } from './OscdTree.js';\n\nimport './oscd-tree.js';\nimport '../icon/oscd-icon.js';\nimport '../textfield/oscd-outlined-text-field.js';\n\ntype DemoTreeNode = TreeNode & {\n id?: string;\n label: string;\n description?: string;\n kind: 'ied' | 'access-point' | 'l-device' | 'logical-node';\n children?: DemoTreeNode[];\n};\n\nconst { args, argTypes, meta } = getStorybookMeta<OscdTree>({\n tagName: 'oscd-tree',\n});\n\nconst sampleTree: DemoTreeNode[] = [\n {\n id: 'ied:PUB_A',\n label: 'PUB_A',\n description: 'Publisher IED',\n kind: 'ied',\n children: [\n {\n id: 'ap:PUB_A/AP1',\n label: 'AP1',\n description: 'Access point',\n kind: 'access-point',\n children: [\n {\n id: 'ld:PUB_A/AP1/LD_A',\n label: 'LD_A',\n description: 'Logical device',\n kind: 'l-device',\n children: [\n {\n id: 'ln:PUB_A|AP1|LD_A||LLN0|',\n label: 'LLN0',\n description: 'Logical node zero',\n kind: 'logical-node',\n children: [],\n },\n {\n id: 'ln:PUB_A|AP1|LD_A||TCTR|1',\n label: 'TCTR1',\n description: 'Current transformer',\n kind: 'logical-node',\n children: [],\n },\n {\n id: 'ln:PUB_A|AP1|LD_A||XCBR|1',\n label: 'XCBR1',\n description: 'Circuit breaker',\n kind: 'logical-node',\n children: [],\n },\n ],\n },\n ],\n },\n ],\n },\n {\n id: 'ied:PUB_B',\n label: 'PUB_B',\n description: 'Publisher IED',\n kind: 'ied',\n children: [\n {\n id: 'ap:PUB_B/AP1',\n label: 'AP1',\n description: 'Access point',\n kind: 'access-point',\n children: [\n {\n id: 'ld:PUB_B/AP1/LD_B',\n label: 'LD_B',\n description: 'Logical device',\n kind: 'l-device',\n children: [\n {\n id: 'ln:PUB_B|AP1|LD_B||LLN0|',\n label: 'LLN0',\n description: 'Logical node zero',\n kind: 'logical-node',\n children: [],\n },\n {\n id: 'ln:PUB_B|AP1|LD_B||TCTR|1',\n label: 'TCTR1',\n description: 'Current transformer',\n kind: 'logical-node',\n children: [],\n },\n ],\n },\n ],\n },\n ],\n },\n];\n\nconst treeWithUnknownChildren: DemoTreeNode[] = [\n ...sampleTree,\n {\n id: 'ied:REMOTE',\n label: 'REMOTE',\n description: 'Children are not loaded yet',\n kind: 'ied',\n },\n];\n\nconst kindIcon = (kind: DemoTreeNode['kind']): string => {\n switch (kind) {\n case 'ied':\n return 'reportIcon';\n case 'access-point':\n return 'lan';\n case 'l-device':\n return 'dns';\n case 'logical-node':\n return 'article';\n default:\n return 'circle';\n }\n};\n\nconst renderDemoItem = ({\n node,\n selected,\n active,\n disabled,\n}: TreeRenderContext<DemoTreeNode>) =>\n html`<oscd-tree-item\n ?selected=${selected}\n ?active=${active}\n ?disabled=${disabled}\n >\n <oscd-icon slot=\"start\">${kindIcon(node.kind)}</oscd-icon>\n <span slot=\"headline\">${node.label}</span>\n <span slot=\"supporting-text\">${node.description}</span>\n </oscd-tree-item>`;\n\nconst renderCompactItem = ({\n node,\n childrenState,\n selected,\n disabled,\n}: TreeRenderContext<DemoTreeNode>) =>\n html`<oscd-tree-item ?selected=${selected} ?disabled=${disabled}>\n <span slot=\"headline\">${node.label}</span>\n <span slot=\"supporting-text\">${node.kind} / ${childrenState}</span>\n </oscd-tree-item>`;\n\nconst matchesFilter = (node: DemoTreeNode, filter: string): boolean => {\n const needle = filter.trim().toLowerCase();\n if (!needle) {\n return true;\n }\n\n return [node.label, node.description, node.kind, node.id]\n .filter((term): term is string => !!term)\n .some(term => term.toLowerCase().includes(needle));\n};\n\nconst filterTree = (nodes: DemoTreeNode[], filter: string): DemoTreeNode[] => {\n const needle = filter.trim();\n if (!needle) {\n return nodes;\n }\n\n return nodes\n .map((node): DemoTreeNode | undefined => {\n const children = node.children\n ? filterTree(node.children, needle)\n : node.children;\n const matched = matchesFilter(node, needle);\n\n if (!matched && (!children || children.length === 0)) {\n return undefined;\n }\n\n const filteredNode: DemoTreeNode = {\n ...node,\n };\n\n if (node.children !== undefined) {\n filteredNode.children = children;\n }\n\n return filteredNode;\n })\n .filter((node): node is DemoTreeNode => !!node);\n};\n\nconst handleSelection = (\n event: CustomEvent<TreeSelectionChangeEventDetail<DemoTreeNode>>,\n) => {\n action('selected-ids-changed')(event.detail.selectedIds);\n};\n\nconst handleExpansion = (event: CustomEvent<{ expandedIds: string[] }>) => {\n action('expanded-ids-changed')(event.detail.expandedIds);\n};\n\nexport default {\n ...meta,\n title: 'Tree / Tree',\n tags: ['autodocs'],\n};\n\nexport const Default: StoryObj = {\n argTypes,\n args: {\n ...args,\n ['.data']: sampleTree,\n ['.expandedIds']: ['ied:PUB_A', 'ap:PUB_A/AP1'],\n ['.renderItem']: renderDemoItem,\n },\n render: argz =>\n html`<div style=\"max-width: 520px;\">\n <oscd-tree\n .data=${argz['.data']}\n .expandedIds=${argz['.expandedIds']}\n .renderItem=${argz['.renderItem']}\n @expanded-ids-changed=${handleExpansion}\n ></oscd-tree>\n </div>`,\n};\n\nexport const MultipleSelection: StoryObj = {\n argTypes,\n args: {\n ...args,\n ['.data']: sampleTree,\n ['.expandedIds']: ['ied:PUB_A', 'ap:PUB_A/AP1', 'ld:PUB_A/AP1/LD_A'],\n ['.selectedIds']: ['ln:PUB_A|AP1|LD_A||TCTR|1'],\n ['.renderItem']: renderDemoItem,\n selectionMode: 'multiple',\n },\n render: argz =>\n html`<div style=\"max-width: 520px;\">\n <oscd-tree\n selectionMode=${argz['selectionMode']}\n .data=${argz['.data']}\n .expandedIds=${argz['.expandedIds']}\n .selectedIds=${argz['.selectedIds']}\n .renderItem=${argz['.renderItem']}\n .isSelectable=${(node: DemoTreeNode) => node.kind === 'logical-node'}\n @selected-ids-changed=${handleSelection}\n @expanded-ids-changed=${handleExpansion}\n ></oscd-tree>\n </div>`,\n};\n\nexport const SingleSelection: StoryObj = {\n argTypes,\n args: {\n ...args,\n ['.data']: sampleTree,\n ['.expandedIds']: ['ied:PUB_A', 'ap:PUB_A/AP1', 'ld:PUB_A/AP1/LD_A'],\n ['.selectedIds']: ['ln:PUB_A|AP1|LD_A||TCTR|1'],\n ['.renderItem']: renderDemoItem,\n selectionMode: 'single',\n },\n render: argz =>\n html`<div style=\"max-width: 520px;\">\n <oscd-tree\n selectionMode=${argz['selectionMode']}\n .data=${argz['.data']}\n .expandedIds=${argz['.expandedIds']}\n .selectedIds=${argz['.selectedIds']}\n .renderItem=${argz['.renderItem']}\n .isSelectable=${(node: DemoTreeNode) => node.kind === 'logical-node'}\n @selected-ids-changed=${handleSelection}\n @expanded-ids-changed=${handleExpansion}\n ></oscd-tree>\n </div>`,\n};\n\nexport const DisabledRows: StoryObj = {\n argTypes,\n args: {\n ...args,\n ['.data']: sampleTree,\n ['.expandedIds']: ['ied:PUB_A', 'ap:PUB_A/AP1', 'ld:PUB_A/AP1/LD_A'],\n ['.selectedIds']: ['ln:PUB_A|AP1|LD_A||TCTR|1'],\n ['.renderItem']: renderDemoItem,\n selectionMode: 'multiple',\n },\n render: argz =>\n html`<div style=\"max-width: 520px;\">\n <oscd-tree\n selectionMode=${argz['selectionMode']}\n .data=${argz['.data']}\n .expandedIds=${argz['.expandedIds']}\n .selectedIds=${argz['.selectedIds']}\n .renderItem=${argz['.renderItem']}\n .isSelectable=${(node: DemoTreeNode) => node.kind === 'logical-node'}\n .isDisabled=${(node: DemoTreeNode) =>\n node.kind === 'logical-node' &&\n node.id !== 'ln:PUB_A|AP1|LD_A||TCTR|1'}\n @selected-ids-changed=${handleSelection}\n @expanded-ids-changed=${handleExpansion}\n ></oscd-tree>\n </div>`,\n};\n\nexport const UnknownChildren: StoryObj = {\n argTypes,\n args: {\n ...args,\n ['.data']: treeWithUnknownChildren,\n ['.expandedIds']: ['ied:PUB_A'],\n ['.renderItem']: renderCompactItem,\n },\n render: argz =>\n html`<div style=\"max-width: 520px;\">\n <oscd-tree\n .data=${argz['.data']}\n .expandedIds=${argz['.expandedIds']}\n .renderItem=${argz['.renderItem']}\n @node-expand=${(event: Event) => {\n const customEvent = event as CustomEvent<{ id: string }>;\n if (customEvent.detail.id === 'ied:REMOTE') {\n customEvent.preventDefault();\n action('lazy node-expand prevented')(customEvent.detail.id);\n }\n }}\n @expanded-ids-changed=${handleExpansion}\n ></oscd-tree>\n </div>`,\n};\n\nexport const DerivedIds: StoryObj = {\n argTypes,\n args: {\n ...args,\n ['.data']: sampleTree.map(({ id: _id, ...node }) => node),\n ['.expandedIds']: ['0', '0/0'],\n ['.renderItem']: renderDemoItem,\n },\n render: argz =>\n html`<div style=\"max-width: 520px;\">\n <oscd-tree\n .data=${argz['.data']}\n .expandedIds=${argz['.expandedIds']}\n .renderItem=${argz['.renderItem']}\n @expanded-ids-changed=${handleExpansion}\n ></oscd-tree>\n </div>`,\n};\n\nexport const Filtered: StoryObj = {\n argTypes,\n args: {\n ...args,\n expandedIds: ['ied:PUB_A'],\n filter: 'TCTR',\n },\n render: argz => {\n const [_, updateArgs] = useArgs();\n const filter = String(argz['filter'] ?? '');\n const expandedIds = argz['expandedIds'] as string[];\n const filteredTree = filterTree(sampleTree, filter);\n\n return html`<div\n style=\"display: flex; flex-direction: column; gap: 12px; width: min(520px, 100%);\"\n >\n <oscd-outlined-text-field\n label=\"Filter tree\"\n .value=${filter}\n @input=${(event: Event) => {\n const input = event.target as HTMLInputElement;\n action('filter input')(input.value);\n updateArgs({ filter: input.value });\n }}\n ></oscd-outlined-text-field>\n <oscd-tree\n .data=${filteredTree}\n .expandedIds=${expandedIds}\n .renderItem=${renderDemoItem}\n @expanded-ids-changed=${(\n event: CustomEvent<{ expandedIds: string[] }>,\n ) => {\n handleExpansion(event);\n updateArgs({ expandedIds: event.detail.expandedIds });\n }}\n ></oscd-tree>\n </div>`;\n },\n};\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { TreeItem } from './internal/TreeItem.js';
|
|
2
|
+
declare global {
|
|
3
|
+
interface HTMLElementTagNameMap {
|
|
4
|
+
'oscd-tree-item': OscdTreeItem;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Default content component for rows rendered inside `oscd-tree`.
|
|
9
|
+
*
|
|
10
|
+
* `oscd-tree-item` is intended to be returned from an `oscd-tree` `renderItem`
|
|
11
|
+
* callback. It renders the caller-visible row content only. The parent
|
|
12
|
+
* `oscd-tree` owns the tree row frame, indentation, expand/collapse affordance,
|
|
13
|
+
* selection affordance, keyboard handling, and ARIA attributes.
|
|
14
|
+
*
|
|
15
|
+
* Use the `headline` slot for the primary label, `supporting-text` for
|
|
16
|
+
* secondary/path text, `start` for an optional leading icon, and `end` for
|
|
17
|
+
* optional trailing status or actions.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const renderItem = ({ node, selected, active, disabled }) => html`
|
|
22
|
+
* <oscd-tree-item
|
|
23
|
+
* ?selected=${selected}
|
|
24
|
+
* ?active=${active}
|
|
25
|
+
* ?disabled=${disabled}
|
|
26
|
+
* >
|
|
27
|
+
* <oscd-icon slot="start">lan</oscd-icon>
|
|
28
|
+
* <span slot="headline">${node.label}</span>
|
|
29
|
+
* <span slot="supporting-text">${node.path}</span>
|
|
30
|
+
* ${selected ? html`<oscd-icon slot="end">check</oscd-icon>` : ''}
|
|
31
|
+
* </oscd-tree-item>
|
|
32
|
+
* `;
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @slot start - Optional leading content such as an icon.
|
|
36
|
+
* @slot headline - Primary row text.
|
|
37
|
+
* @slot supporting-text - Secondary row text.
|
|
38
|
+
* @slot end - Optional trailing content such as status or actions.
|
|
39
|
+
*
|
|
40
|
+
* @tagname oscd-tree-item
|
|
41
|
+
*/
|
|
42
|
+
export declare class OscdTreeItem extends TreeItem {
|
|
43
|
+
}
|