@onereach/ui-components 3.0.1 → 3.0.2-beta.2473.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.
Files changed (38) hide show
  1. package/dist/bundled/v2/components/or-tree-v3/OrTree.vue.d.ts +47 -0
  2. package/dist/bundled/v2/components/or-tree-v3/TreeNode.vue.d.ts +69 -0
  3. package/dist/bundled/v2/components/or-tree-v3/index.d.ts +2 -0
  4. package/dist/bundled/v2/components/or-tree-v3/index.js +236 -0
  5. package/dist/bundled/v2/components/or-tree-v3/styles.d.ts +1 -0
  6. package/dist/bundled/v2/components/or-tree-v3/types.d.ts +10 -0
  7. package/dist/bundled/v2/components/or-tree-v3/utils.d.ts +5 -0
  8. package/dist/bundled/v2/index.js +1 -1
  9. package/dist/bundled/v3/components/or-tree-v3/OrTree.vue.d.ts +47 -0
  10. package/dist/bundled/v3/components/or-tree-v3/TreeNode.vue.d.ts +69 -0
  11. package/dist/bundled/v3/components/or-tree-v3/index.d.ts +2 -0
  12. package/dist/bundled/v3/components/or-tree-v3/index.js +176 -0
  13. package/dist/bundled/v3/components/or-tree-v3/styles.d.ts +1 -0
  14. package/dist/bundled/v3/components/or-tree-v3/types.d.ts +10 -0
  15. package/dist/bundled/v3/components/or-tree-v3/utils.d.ts +5 -0
  16. package/dist/bundled/v3/index.js +1 -1
  17. package/dist/esm/v2/components/or-tree-v3/OrTree.vue.d.ts +47 -0
  18. package/dist/esm/v2/components/or-tree-v3/TreeNode.vue.d.ts +69 -0
  19. package/dist/esm/v2/components/or-tree-v3/index.d.ts +2 -0
  20. package/dist/esm/v2/components/or-tree-v3/index.js +232 -0
  21. package/dist/esm/v2/components/or-tree-v3/styles.d.ts +1 -0
  22. package/dist/esm/v2/components/or-tree-v3/types.d.ts +10 -0
  23. package/dist/esm/v2/components/or-tree-v3/utils.d.ts +5 -0
  24. package/dist/esm/v3/components/or-tree-v3/OrTree.vue.d.ts +47 -0
  25. package/dist/esm/v3/components/or-tree-v3/TreeNode.vue.d.ts +69 -0
  26. package/dist/esm/v3/components/or-tree-v3/index.d.ts +2 -0
  27. package/dist/esm/v3/components/or-tree-v3/index.js +174 -0
  28. package/dist/esm/v3/components/or-tree-v3/styles.d.ts +1 -0
  29. package/dist/esm/v3/components/or-tree-v3/types.d.ts +10 -0
  30. package/dist/esm/v3/components/or-tree-v3/utils.d.ts +5 -0
  31. package/package.json +3 -4
  32. package/src/components/or-tree-v3/OrTree.stories3.ts +104 -0
  33. package/src/components/or-tree-v3/OrTree.vue +80 -0
  34. package/src/components/or-tree-v3/TreeNode.vue +67 -0
  35. package/src/components/or-tree-v3/index.ts +2 -0
  36. package/src/components/or-tree-v3/styles.ts +13 -0
  37. package/src/components/or-tree-v3/types.ts +12 -0
  38. package/src/components/or-tree-v3/utils.ts +31 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onereach/ui-components",
3
- "version": "3.0.1",
3
+ "version": "3.0.2-beta.2473.0",
4
4
  "description": "Vue components library for v2/3",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/auto/index.js",
@@ -38,7 +38,7 @@
38
38
  "@codemirror/lang-json": "6.0.0",
39
39
  "@codemirror/lang-markdown": "6.0.1",
40
40
  "@floating-ui/dom": "0.3.1",
41
- "@onereach/styles": "^2.37.3",
41
+ "@onereach/styles": "^2.37.4-beta.2473.0",
42
42
  "@splidejs/splide": "4.0.6",
43
43
  "@types/lodash": "4.14.173",
44
44
  "@types/sortablejs": "1.10.7",
@@ -124,6 +124,5 @@
124
124
  "default": "./dist/bundled/v3/components/*/index.js"
125
125
  },
126
126
  "./package.json": "./package.json"
127
- },
128
- "gitHead": "011555419b20001e8b4691da8d27b016bb106c67"
127
+ }
129
128
  }
@@ -0,0 +1,104 @@
1
+ import { action } from '@storybook/addon-actions';
2
+ import { StoryFn } from '@storybook/vue3';
3
+ import OrTree from './OrTree.vue';
4
+
5
+ const TREE_DATA = [
6
+ {
7
+ key: '0-0',
8
+ children: [
9
+ {
10
+ key: '0-0-0',
11
+ children: [
12
+ {
13
+ key: '0-0-0-0',
14
+ },
15
+ {
16
+ key: '0-0-0-1',
17
+ },
18
+ {
19
+ key: '0-0-0-2',
20
+ },
21
+ ],
22
+ },
23
+ {
24
+ key: '0-0-1',
25
+ children: [
26
+ {
27
+ key: '0-0-1-0',
28
+ },
29
+ {
30
+ key: '0-0-1-1',
31
+ },
32
+ {
33
+ key: '0-0-1-2',
34
+ children: [
35
+ {
36
+ key: '0-0-1-2-0',
37
+ },
38
+ ],
39
+ },
40
+ ],
41
+ },
42
+ {
43
+ key: '0-0-2',
44
+ },
45
+ ],
46
+ },
47
+ {
48
+ key: '0-1',
49
+ children: [
50
+ {
51
+ key: '0-1-0-0',
52
+ },
53
+ {
54
+ key: '0-1-0-1',
55
+ },
56
+ {
57
+ key: '0-1-0-2',
58
+ },
59
+ ],
60
+ },
61
+ {
62
+ key: '0-2',
63
+ isLeaf: true,
64
+ },
65
+ ];
66
+
67
+ export default {
68
+ title: 'Components/Tree',
69
+ component: OrTree,
70
+ argTypes: {
71
+ },
72
+ };
73
+
74
+ const Template: StoryFn<typeof OrTree> = (args) => ({
75
+ components: {
76
+ OrTree,
77
+ },
78
+
79
+ data() {
80
+ return {
81
+ TREE_DATA,
82
+ };
83
+ },
84
+
85
+ setup() {
86
+ return {
87
+ args,
88
+ onUpdateState: action('update:state'),
89
+ };
90
+ },
91
+
92
+ template: `
93
+ <OrTree
94
+ v-bind="args"
95
+ />
96
+ `,
97
+ });
98
+
99
+ export const Default = Template.bind({});
100
+
101
+ Default.args = {
102
+ // Props
103
+ initialData: TREE_DATA,
104
+ };
@@ -0,0 +1,80 @@
1
+ <template>
2
+ <div
3
+ class="or-tree"
4
+ @drop="onDrop"
5
+ >
6
+ <tree-node
7
+ v-for="node in visibleItems"
8
+ v-bind="node"
9
+ :key="node[identifierKey]"
10
+ :node-key="node[identifierKey]"
11
+ :is-expanded="nodeMetadataByKey[node.key].isExpanded"
12
+ :level="nodeMetadataByKey[node.key].level"
13
+ @trigger-expand="onTriggerExpand"
14
+ >
15
+ <slot />
16
+ </tree-node>
17
+ </div>
18
+ </template>
19
+
20
+ <script lang="ts">
21
+ import { defineComponent, PropType } from 'vue-demi';
22
+ import { ITreeNode, ITreeNodeMetadata } from './types';
23
+ import { getFlatTree } from './utils';
24
+ import TreeNode from './TreeNode.vue';
25
+
26
+ export default defineComponent({
27
+ components: {
28
+ TreeNode,
29
+ },
30
+ props: {
31
+ initialData: {
32
+ type: Array as PropType<ITreeNode[]>,
33
+ default: () => ([]),
34
+ },
35
+ identifierKey: {
36
+ type: String,
37
+ default: 'key',
38
+ },
39
+ },
40
+
41
+ data() {
42
+ return {
43
+ flatTree: [] as ITreeNode[],
44
+ nodeMetadataByKey: {} as Record<string, ITreeNodeMetadata>,
45
+ };
46
+ },
47
+
48
+ computed: {
49
+ visibleItems() {
50
+ return this.flatTree.filter(treeNode => {
51
+ return this.isNodeExpanded(treeNode.key);
52
+ });
53
+ },
54
+ },
55
+
56
+ mounted() {
57
+ const {
58
+ nodeMetadataByKey, flatTree,
59
+ } = getFlatTree(this.initialData);
60
+ this.flatTree = flatTree;
61
+ this.nodeMetadataByKey = nodeMetadataByKey;
62
+ },
63
+
64
+ methods: {
65
+ onTriggerExpand(key: string) {
66
+ this.nodeMetadataByKey[key].isExpanded = !this.nodeMetadataByKey[key].isExpanded;
67
+ },
68
+
69
+ isNodeExpanded(key: string): boolean {
70
+ const { parentNodeKey, level } = this.nodeMetadataByKey[key];
71
+ const parentMetadata = this.nodeMetadataByKey[parentNodeKey];
72
+
73
+ if (level === 0) return true;
74
+ if (!parentMetadata.isExpanded) return false;
75
+
76
+ return this.isNodeExpanded(parentNodeKey);
77
+ },
78
+ },
79
+ });
80
+ </script>
@@ -0,0 +1,67 @@
1
+ <template>
2
+ <div
3
+ class="tree-node"
4
+ :class="rootClasses"
5
+ :style="styleCSS"
6
+ >
7
+ <or-icon-button
8
+ v-if="!isLeaf"
9
+ :icon="expandIcon"
10
+ @click="$emit('trigger-expand', nodeKey)"
11
+ />
12
+
13
+ <slot v-bind="$props">
14
+ {{ nodeKey }}
15
+ </slot>
16
+ </div>
17
+ </template>
18
+
19
+ <script lang="ts">
20
+ import { defineComponent } from 'vue-demi';
21
+ import { OrIconButtonV3 as OrIconButton } from '../or-icon-button-v3';
22
+ import { TreeNodeRoot } from './styles';
23
+
24
+ export default defineComponent({
25
+ components: {
26
+ OrIconButton,
27
+ },
28
+ props: {
29
+ nodeKey: {
30
+ type: String,
31
+ default: '',
32
+ },
33
+ isExpanded: {
34
+ type: Boolean,
35
+ default: false,
36
+ },
37
+ isLeaf: {
38
+ type: Boolean,
39
+ default: false,
40
+ },
41
+ level: {
42
+ type: Number,
43
+ default: 0,
44
+ },
45
+ },
46
+ emits: ['trigger-expand'],
47
+
48
+ setup() {
49
+ return {
50
+ rootClasses: TreeNodeRoot,
51
+ };
52
+ },
53
+
54
+ computed: {
55
+ expandIcon() {
56
+ return this.isExpanded ? 'keyboard_arrow_down' : 'arrow_right';
57
+ },
58
+
59
+ styleCSS() {
60
+ return {
61
+ // 24px -- gap-sm + tooltip width
62
+ 'padding-left': (this.isLeaf && this.level === 0) ? '24px' : `${this.level * 10}px`,
63
+ };
64
+ },
65
+ },
66
+ });
67
+ </script>
@@ -0,0 +1,2 @@
1
+ export { default as OrTreeV3 } from './OrTree.vue';
2
+ export * from './types';
@@ -0,0 +1,13 @@
1
+ export const TreeNodeRoot: string[] = [
2
+ 'flex',
3
+ 'items-center',
4
+ 'gap-sm',
5
+ 'pt-6',
6
+ 'my-sm',
7
+
8
+ // Theme
9
+ 'text-on-background',
10
+ 'dark:text-on-background-dark',
11
+ 'hover:bg-primary-opacity-0-08',
12
+ 'dark:hover:bg-primary-opacity-0-08-dark',
13
+ ];
@@ -0,0 +1,12 @@
1
+ export interface ITreeNode {
2
+ key: string;
3
+ isLeaf: boolean;
4
+ children?: ITreeNode[];
5
+ }
6
+
7
+
8
+ export interface ITreeNodeMetadata {
9
+ level: number;
10
+ isExpanded: boolean;
11
+ parentNodeKey: string;
12
+ }
@@ -0,0 +1,31 @@
1
+ import { ITreeNode, ITreeNodeMetadata } from './types';
2
+
3
+ export const getFlatTree = (tree: ITreeNode[]) => {
4
+ const flatTree: ITreeNode[] = [];
5
+ const nodeMetadataByKey: Record<string, ITreeNodeMetadata> = {};
6
+
7
+ const goDeeper = (treeNode: ITreeNode, level: number, parentNodeKey: string) => {
8
+ flatTree.push(treeNode);
9
+ nodeMetadataByKey[treeNode.key] = {
10
+ level,
11
+ isExpanded: false,
12
+ parentNodeKey,
13
+ };
14
+
15
+ if (treeNode.children) {
16
+ for (const child of treeNode.children) {
17
+ goDeeper(child, level + 1, treeNode.key);
18
+ }
19
+
20
+ }
21
+ };
22
+
23
+ for (const node of tree) {
24
+ goDeeper(node, 0, '');
25
+ }
26
+
27
+ return {
28
+ flatTree,
29
+ nodeMetadataByKey,
30
+ };
31
+ };