@teammodlr/ui-kit 2.1.6 → 2.1.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teammodlr/ui-kit",
3
- "version": "2.1.6",
3
+ "version": "2.1.7",
4
4
  "description": "",
5
5
  "main": "lib/index.cjs.js",
6
6
  "module": "lib/index.es.js",
@@ -30,13 +30,16 @@ export default defineComponent({
30
30
  components: {TreeNode, VVirtualList},
31
31
  name: 'Tree',
32
32
  props: treeProps,
33
- setup: function (props) {
33
+ emits: ['update:expandedKeys', 'dblclick'],
34
+ setup: function (props, {emit}) {
34
35
  const selfElRef = ref<HTMLDivElement | null>(null);
35
36
  const virtualListInstRef = ref<VirtualListInst | null>(null)
36
- function getScrollContainer (): HTMLElement | null | undefined {
37
+
38
+ function getScrollContainer(): HTMLElement | null | undefined {
37
39
  return virtualListInstRef.value?.listElRef
38
40
  }
39
- function getScrollContent (): HTMLElement | null | undefined {
41
+
42
+ function getScrollContent(): HTMLElement | null | undefined {
40
43
  return virtualListInstRef.value?.itemsElRef
41
44
  }
42
45
 
@@ -64,10 +67,14 @@ export default defineComponent({
64
67
  });
65
68
 
66
69
  provide(treeInjectionKey, {
70
+ mergedExpandedKeysRef,
67
71
  indentRef: toRef(props, 'indent'),
68
72
  expandOnClickRef: toRef(props, 'expandOnClick'),
69
73
  nodePropsRef: toRef(props, 'nodeProps'),
70
- handleSwitcherClick
74
+ labelFieldRef: toRef(props, 'labelField'),
75
+ keyFieldRef: toRef(props, 'keyField'),
76
+ handleDoubleClick,
77
+ handleToggleClick
71
78
  });
72
79
 
73
80
  // const { watchProps } = props;
@@ -76,11 +83,15 @@ export default defineComponent({
76
83
  // initUncontrolledExpandedKeys(undefined);
77
84
  // })
78
85
 
79
- function handleSwitcherClick(node: TmNode): void {
80
- console.log('i')
86
+ function handleToggleClick(node: TmNode): void {
87
+
81
88
  toggleExpand(node);
82
89
  }
83
90
 
91
+ function handleDoubleClick(node: TreeOption): void {
92
+ emit('dblclick', node);
93
+ }
94
+
84
95
  function toggleExpand(node: TmNode): void {
85
96
  const {key} = node;
86
97
  const {value: mergedExpandedKeys} = mergedExpandedKeysRef
@@ -1,71 +1,103 @@
1
1
  <template>
2
- <div
3
- @click="handleLineClick"
4
- style="display: flex;"
5
- >
6
- <template v-if="indentCount > 0">
7
- <div v-for="i in indentCount" style="flex-grow: 0; flex-shrink: 0; height: 0;">
8
- <div :key="i" style="width: 16px;"></div>
9
- </div>
10
- </template>
11
- {{node.rawNode.label}}
12
- </div>
2
+ <div
3
+ @dblclick="doDoubleClick"
4
+ style="display: flex;"
5
+ >
6
+ <template v-if="indentCount > 0">
7
+ <div v-for="i in indentCount" style="flex-grow: 0; flex-shrink: 0; height: 0;">
8
+ <div :key="i" style="width: 16px;"></div>
9
+ </div>
10
+ </template>
11
+ <TreeNodeToggle
12
+ :hide="node.isLeaf"
13
+ :node="node"
14
+ :expanded="expanded"
15
+ @click="handleToggleClick"
16
+ />
17
+ {{ labelField }}
18
+ </div>
13
19
  </template>
14
20
 
15
21
  <script lang="ts">
16
22
  import {ref, defineComponent, type PropType, inject, computed} from "vue";
17
- import type {TmNode} from "./types";
23
+ import type {TmNode, TreeOption} from "./types";
18
24
  import {treeInjectionKey} from "./types";
25
+ import TreeNodeToggle from "@/components/tree/TreeNodeToggle.vue";
26
+ import type {TreeNode} from "treemate";
19
27
 
20
28
  export default defineComponent({
21
- name: 'TreeNode',
22
- props: {
23
- node: {
24
- type: Object as PropType<TmNode>,
25
- required: true
26
- }
27
- },
28
- setup(props) {
29
- const NTree = inject(treeInjectionKey)!;
30
- const {
31
- nodePropsRef,
32
- indentRef,
33
- handleSwitcherClick: handleSwitcherClickTree
34
- } = NTree;
29
+ name: 'TreeNode',
30
+ components: {TreeNodeToggle},
31
+ props: {
32
+ node: {
33
+ type: Object as PropType<TmNode>,
34
+ required: true
35
+ }
36
+ },
37
+ setup(props) {
38
+ const NTree = inject(treeInjectionKey)!;
39
+ const {
40
+ nodePropsRef,
41
+ labelFieldRef,
42
+ keyFieldRef,
43
+ indentRef,
44
+ handleToggleClick: handleToggleClickTree,
45
+ handleDoubleClick
46
+ } = NTree;
47
+
48
+ const selfElRef = ref<HTMLDivElement | null>(null);
49
+
50
+ function _handleClick(e: MouseEvent): void {
51
+ const {value: expandOnClick} = NTree.expandOnClickRef;
52
+ const {node} = props
53
+ if (!expandOnClick && !node.isLeaf) {
54
+ handleToggleClick();
55
+ }
56
+ }
35
57
 
36
- const selfElRef = ref<HTMLDivElement | null>(null);
58
+ function handleToggleClick(): void {
59
+ const {node} = props;
37
60
 
38
- function _handleClick (e: MouseEvent): void {
39
- const { value: expandOnClick } = NTree.expandOnClickRef;
40
- const { node } = props
41
- if (!expandOnClick && !node.isLeaf) {
42
- handleSwitcherClick();
43
- }
44
- }
45
61
 
46
- function handleSwitcherClick(): void {
47
- const { node } = props;
62
+ if (!node.isLastChild && !node.shallowLoaded) {
63
+ return;
64
+ }
48
65
 
49
- if (!node.isLastChild && !node.shallowLoaded) {
50
- return;
51
- }
66
+ handleToggleClickTree(node)
67
+ }
68
+
69
+ function doDoubleClick(e: MouseEvent) {
70
+ // get only id and name from node
71
+ let node = props.node;
72
+ let nodeData = {
73
+ [keyFieldRef.value]: node.rawNode[keyFieldRef.value],
74
+ [labelFieldRef.value]: node.rawNode[labelFieldRef.value]
75
+ } as TreeOption;
76
+ handleDoubleClick(nodeData);
77
+ }
78
+ const indentCount = computed(() => {
79
+ return props.node.level;
80
+ })
52
81
 
53
- handleSwitcherClickTree(node)
54
- }
82
+ function handleLineClick(e: MouseEvent) {
83
+ _handleClick(e);
84
+ }
55
85
 
56
- const indentCount = computed(() => {
57
- return props.node.level;
58
- })
86
+ const labelField = computed(() => {
87
+ return props.node.rawNode[labelFieldRef.value];
88
+ })
59
89
 
60
- function handleLineClick (e: MouseEvent) {
61
- _handleClick(e);
62
- }
90
+ const expanded = computed(() => NTree.mergedExpandedKeysRef.value.includes(props.node.key));
63
91
 
64
- return {
65
- selfElRef,
66
- handleLineClick,
67
- indentCount
68
- }
92
+ return {
93
+ selfElRef,
94
+ handleLineClick,
95
+ indentCount,
96
+ labelField,
97
+ expanded: expanded,
98
+ handleToggleClick,
99
+ doDoubleClick
69
100
  }
101
+ }
70
102
  });
71
103
  </script>
@@ -0,0 +1,36 @@
1
+ <template>
2
+ <div
3
+ @click="onClick"
4
+ style="width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center; vertical-align: bottom;"
5
+ >
6
+ <template v-if="!hide">
7
+ <svg v-if="expanded" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-chevron-down"><path d="m6 9 6 6 6-6"/></svg>
8
+ <svg v-else xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-chevron-right"><path d="m9 18 6-6-6-6"/></svg>
9
+ </template>
10
+ </div>
11
+ </template>
12
+
13
+ <script lang="ts">
14
+ import {defineComponent, type PropType} from "vue";
15
+ import type {TmNode} from "./types";
16
+
17
+ export default defineComponent({
18
+ name: "TreeNodeToggle",
19
+ props: {
20
+ expanded: Boolean,
21
+ selected: Boolean,
22
+ onClick: Function as PropType<(e: MouseEvent) => void>,
23
+ hide: Boolean,
24
+ node: {
25
+ type: Object as PropType<TmNode>,
26
+ required: true
27
+ }
28
+ },
29
+ setup (props) {
30
+
31
+ return {
32
+
33
+ }
34
+ }
35
+ })
36
+ </script>
@@ -1,33 +1,13 @@
1
1
  <template>
2
- <MTree :data="data"/>
2
+ <MTree :data="data" label-field="name" key-field="id" @dblclick="dblclick"/>
3
3
  </template>
4
4
  <script lang="ts" setup>
5
5
  import {ref} from 'vue'
6
- import type {TreeOption} from "../types";
6
+ import type {TmNode} from "../../../../lib/components/tree/types";
7
7
 
8
- function createData (level = 4, baseKey = ''): TreeOption[] | undefined {
9
- if (!level) return undefined
8
+ const data = ref([{"children":[{"children":[{"name":"Advertising & Marketing","weight":1,"type":"N","childrenCount":0,"id":"b5511a25-f9d4-402f-9f49-7bb9cff0bd97"},{"children":[],"name":"Finance","weight":1,"type":"N","childrenCount":0,"id":"b21ac382-ae7d-4cb0-b504-10a7ef6eac55"},{"children":[],"name":"Information Technology","weight":1,"type":"N","childrenCount":0,"id":"af71b879-0ea0-4cf6-8b70-4e764f08210b"},{"children":[],"name":"Legal","weight":1,"type":"N","childrenCount":0,"id":"c7d58cb8-d70c-4f70-99fb-7e8fdbb44b80"},{"children":[],"name":"Management","weight":1,"type":"N","childrenCount":0,"id":"2fef19d7-c744-4c36-9066-b077d1641f58"}],"name":"Cost Centers","weight":1,"type":"N","childrenCount":5,"id":"9bb9a4e9-749e-468a-9d39-d98625d8f3a1"},{"children":[{"children":[{"children":[{"children":[],"name":"Brisbane 01","weight":1,"type":"N","childrenCount":0,"id":"3beab845-9660-4cc3-8943-deb5672a72d1"},{"children":[],"name":"Brisbane 02","weight":1,"type":"N","childrenCount":0,"id":"812c3874-2103-4e35-b129-861811e9e582"},{"children":[],"name":"Brisbane 03","weight":1,"type":"N","childrenCount":0,"id":"df622e95-b7d9-41f5-9bd3-473bd0305b02"},{"children":[],"name":"Brisbane 04","weight":1,"type":"N","childrenCount":0,"id":"926b904c-4392-4bbb-b824-acaa1f62bb00"}],"name":"Queensland","weight":1,"type":"N","childrenCount":4,"id":"09661d2c-a90f-4c18-991b-d69500ffbdd5"},{"children":[{"children":[],"name":"Melbourne 01","weight":1,"type":"N","childrenCount":0,"id":"9ac3ce45-1bef-43dc-a3ac-227b1759b720"},{"children":[],"name":"Melbourne 02","weight":1,"type":"N","childrenCount":0,"id":"c66ec03a-431a-43e6-94aa-6b72dae73f98"},{"children":[],"name":"Melbourne 03","weight":1,"type":"N","childrenCount":0,"id":"3177b5e0-1b6e-4c7e-90bd-8e55b85880a4"},{"children":[],"name":"Melbourne 04","weight":1,"type":"N","childrenCount":0,"id":"88a1dd59-1b17-47fe-9a66-710cdff04a4f"},{"children":[],"name":"Melbourne 05","weight":1,"type":"N","childrenCount":0,"id":"400ac864-de9d-4afe-802e-880e41bb227c"}],"name":"Victoria","weight":1,"type":"N","childrenCount":5,"id":"063612b1-2cf3-47a6-a4c3-8fb552146d07"},{"children":[{"children":[],"name":"Sydney 01","weight":1,"type":"N","childrenCount":0,"id":"fed2081a-edf5-4823-bdc8-2860dd6e8a5d"},{"children":[],"name":"Sydney 02","weight":1,"type":"N","childrenCount":0,"id":"1b80744b-f2d3-4bbf-b4e5-63d9318d9538"},{"children":[],"name":"Sydney 03","weight":1,"type":"N","childrenCount":0,"id":"3aa2f7f7-8299-4ac9-95d8-d98f97cddda3"},{"children":[],"name":"Sydney 04","weight":1,"type":"N","childrenCount":0,"id":"657b512c-e77e-495a-bb75-bee4c8cd8ee0"},{"children":[],"name":"Sydney 05","weight":1,"type":"N","childrenCount":0,"id":"da5efcc4-3e88-4b5c-a0c5-7c096c5b83c5"},{"children":[],"name":"Sydney 06","weight":1,"type":"N","childrenCount":0,"id":"10fcae0f-3614-4e44-ace4-0c0423f19952"}],"name":"New South Wales","weight":1,"type":"N","childrenCount":6,"id":"3bdf2a0f-41ef-411c-9749-84301dd8088f"},{"children":[{"children":[],"name":"Perth 01","weight":1,"type":"N","childrenCount":0,"id":"0880d1ac-c7d3-4059-b0a8-25bed41496c7"},{"children":[],"name":"Perth 02","weight":1,"type":"N","childrenCount":0,"id":"0998eb28-769d-4a11-a609-10043a7d482f"}],"name":"Western Australia","weight":1,"type":"N","childrenCount":2,"id":"1b8c1791-fc09-4d2e-b681-cd58f027f2fe"},{"children":[{"children":[],"name":"Darwin 01","weight":1,"type":"N","childrenCount":0,"id":"068e40e2-6fde-4d65-a11c-357f694af697"},{"children":[],"name":"Darwin 02","weight":1,"type":"N","childrenCount":0,"id":"1411b083-7c4e-4810-b92e-372f521f2e7c"},{"children":[],"name":"Darwin 03","weight":1,"type":"N","childrenCount":0,"id":"4684a7ea-aabe-47d2-81fc-00d68196d3f6"},{"children":[],"name":"Darwin 04","weight":1,"type":"N","childrenCount":0,"id":"3fdd5254-639f-4efb-bd40-5c0dc5c1c314"}],"name":"Northern Territory","weight":1,"type":"N","childrenCount":4,"id":"c2ca2fa5-07ce-4529-8745-94567d785736"}],"name":"Australia","weight":1,"type":"N","childrenCount":5,"id":"70a043fc-e70c-4a30-8fbb-7784123c85a5"},{"children":[{"children":[],"name":"Auckland 01","weight":1,"type":"N","childrenCount":0,"id":"6293f121-f50e-42b4-a996-15263c45c3ee"},{"children":[],"name":"Auckland 02","weight":1,"type":"N","childrenCount":0,"id":"2cd3eda8-ab87-46da-8300-27261ee91d68"},{"children":[],"name":"Auckland 03","weight":1,"type":"N","childrenCount":0,"id":"88e6c0ae-e891-4faf-9b62-4270207fea91"},{"children":[],"name":"Wellington 01","weight":1,"type":"N","childrenCount":0,"id":"13ecbd3f-0b53-4a96-8627-07886173c8a6"},{"children":[],"name":"Wellington 02","weight":1,"type":"N","childrenCount":0,"id":"767b982c-ac81-44aa-90a3-b2f276919779"}],"name":"New Zealand","weight":1,"type":"N","childrenCount":5,"id":"c987df16-0757-4d04-97ec-386a423aef8d"},{"children":[],"name":"Online","weight":1,"type":"N","childrenCount":0,"id":"367a3afb-cc66-42d7-a022-f7f92683d768"}],"name":"Profit Centers","weight":1,"type":"N","childrenCount":3,"id":"782c9acf-dfdb-4e60-ace9-0f420aeecae6"}],"name":"All Departments","type":"N","childrenCount":2,"id":"a4b0784f-3d57-4a4d-a849-9700b27e6a6f"}]);
10
9
 
11
- const result: TreeOption[] = [];
12
- for (let index = 0; index < (20 - level); index++) {
13
- const key = '' + baseKey + level + index;
14
- result.push({
15
- label: createLabel(level),
16
- key,
17
- children: createData(level - 1, key)
18
- });
19
- }
20
-
21
- return result;
22
- }
23
-
24
- function createLabel (level: number): string {
25
- if (level === 4) return 'Out of Tao, One is born'
26
- if (level === 3) return 'Out of One, Two'
27
- if (level === 2) return 'Out of Two, Three'
28
- if (level === 1) return 'Out of Three, the created universe'
29
- return ''
10
+ function dblclick(node: TmNode) {
11
+ console.log(node);
30
12
  }
31
-
32
- const data = ref(createData());
33
13
  </script>
@@ -1,5 +1,12 @@
1
1
  import type {ExtractPublicPropTypes, PropType} from "vue";
2
- import type {TreeOptions, Key, TreeNodeProps, OnUpdateIndeterminateKeys, onUpdateExpandedKeys} from "./types";
2
+ import type {
3
+ TreeOptions,
4
+ Key,
5
+ TreeNodeProps,
6
+ OnUpdateIndeterminateKeys,
7
+ onUpdateExpandedKeys,
8
+ TreeNodeDoubleClick
9
+ } from "./types";
3
10
  import type {TreeMateOptions} from "treemate";
4
11
  import type {MaybeArray} from "../../call";
5
12
 
@@ -18,6 +25,7 @@ export const treeSharedProps = {
18
25
  type: String,
19
26
  default: 'children',
20
27
  },
28
+ onDblClick: Function as PropType<TreeNodeDoubleClick>,
21
29
  onUpdateIndeterminateKeys: [Function, Array] as PropType<
22
30
  MaybeArray<OnUpdateIndeterminateKeys>
23
31
  >,
@@ -13,15 +13,23 @@ export interface TreeOptionBase {
13
13
  export type TreeOption = TreeOptionBase & Record<string, unknown>;
14
14
  export type TreeOptions = TreeOption[];
15
15
 
16
- export type TreeNodeProps = (info: {
16
+ export type TreeNodeProps = (
17
+ node: TreeOption,
18
+ ) => HTMLAttributes & Record<string, unknown>;
19
+
20
+ export type TreeNodeDoubleClick = (info: {
17
21
  option: TreeOption,
18
- }) => HTMLAttributes & Record<string, unknown>;
22
+ }) => void;
19
23
 
20
24
  export interface TreeInjection {
25
+ mergedExpandedKeysRef: Ref<Key[]>,
21
26
  indentRef: Ref<number>,
22
27
  expandOnClickRef: Ref<boolean>,
23
28
  nodePropsRef: Ref<TreeNodeProps | undefined>,
24
- handleSwitcherClick: (node: TreeNode<TreeOption>) => void
29
+ labelFieldRef: Ref<string>,
30
+ keyFieldRef: Ref<string>,
31
+ handleToggleClick: (node: TreeNode<TreeOption>) => void,
32
+ handleDoubleClick: (node: TreeOption) => void,
25
33
  }
26
34
 
27
35
  export const treeInjectionKey = createInjectionKey<TreeInjection>('tree')