@ticatec/uniface-element 0.1.45 → 0.1.46

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.
@@ -49,9 +49,11 @@
49
49
  <slot name="header"></slot>
50
50
  </div>
51
51
  <div style="height: 100%; flex: 1 1 auto; overflow: hidden; display: flex; flex-direction: row; position: relative">
52
- <div bind:this={sidebar} style="width: 100%; flex: 0 0 auto; overflow: auto; width: {sidebarWidth}; {minWidth} {maxWidth}">
53
- <slot name="sidebar"></slot>
54
- </div>
52
+ {#if sidebar}
53
+ <div bind:this={sidebar} style="width: 100%; flex: 0 0 auto; overflow: auto; width: {sidebarWidth}; {minWidth} {maxWidth}">
54
+ <slot name="sidebar"></slot>
55
+ </div>
56
+ {/if}
55
57
  {#if sidebarResize}
56
58
  <Split direction="vertical" bindingPanel={sidebar}/>
57
59
  {/if}
@@ -62,7 +64,8 @@
62
64
  {#if sidebarResize}
63
65
  <Split direction="vertical" bindingPanel={rightBar} reverse/>
64
66
  {/if}
65
- <div bind:this={rightBar} style="width: 100%; flex: 0 0 auto; overflow: auto; width: {rightBarWidth}; {rightMinWidth} {rightMaxWidth}">
67
+ <div bind:this={rightBar}
68
+ style="width: 100%; flex: 0 0 auto; overflow: auto; width: {rightBarWidth}; {rightMinWidth} {rightMaxWidth}">
66
69
  <slot name="right-sidebar"></slot>
67
70
  </div>
68
71
  {/if}
@@ -0,0 +1,58 @@
1
+ export declare function compareNumber(a: number, b: number): 0 | 1 | -1;
2
+ export type TreeNode<T> = {
3
+ item: T;
4
+ expand: boolean;
5
+ children?: TreeNode<T>[];
6
+ };
7
+ export type CheckIsRoot<T> = (data: T) => boolean;
8
+ export type CompareFun<T> = (o1: T, o2: T) => number | undefined;
9
+ export type GetText<T> = (data: T) => string;
10
+ export interface TreeNodeOptions<T> {
11
+ keyField?: keyof T;
12
+ textField?: keyof T | GetText<T>;
13
+ parentKeyField?: keyof T;
14
+ checkIsRoot: CheckIsRoot<T>;
15
+ compareFun: CompareFun<T>;
16
+ expendDeep?: number;
17
+ }
18
+ export default class TreeNodes<T> {
19
+ #private;
20
+ protected readonly checkIsRoot: CheckIsRoot<T>;
21
+ protected readonly keyField: keyof T;
22
+ protected readonly parentKeyField: keyof T;
23
+ protected readonly textField: keyof T | GetText<T>;
24
+ protected nodeMap: Map<any, TreeNode<T>>;
25
+ protected compareFun: any;
26
+ protected expendDeep: number;
27
+ constructor(options: TreeNodeOptions<T>);
28
+ setData(list: Array<T>): void;
29
+ private appendNode;
30
+ private collectExpandedNodes;
31
+ /**
32
+ * 获取展开的展示列表
33
+ */
34
+ getHierarchyList(): Array<TreeNode<T>>;
35
+ /**
36
+ * 获取节点
37
+ */
38
+ get nodes(): Array<TreeNode<T>>;
39
+ /**
40
+ * 增加一个新节点
41
+ * @param item
42
+ */
43
+ append(item: T): void;
44
+ /**
45
+ * 替换一个节点的数据
46
+ * @param item
47
+ */
48
+ replace(item: T): void;
49
+ remove(item: T): void;
50
+ /**
51
+ * 将一个节点移动到另外一个节点下
52
+ * @param item
53
+ * @param parentId
54
+ */
55
+ moveTo(item: T, parentId: string): void;
56
+ private extractChildrenDirectories;
57
+ extractDirectories(exclusiveValue: any): TreeNode<T>[];
58
+ }
@@ -0,0 +1,172 @@
1
+ export function compareNumber(a, b) {
2
+ return a === b ? 0 : a > b ? 1 : -1;
3
+ }
4
+ export default class TreeNodes {
5
+ checkIsRoot;
6
+ keyField;
7
+ parentKeyField;
8
+ textField;
9
+ nodeMap;
10
+ compareFun;
11
+ expendDeep;
12
+ #nodes = [];
13
+ constructor(options) {
14
+ this.checkIsRoot = options.checkIsRoot;
15
+ this.compareFun = options.compareFun;
16
+ this.keyField = options.keyField ?? 'id';
17
+ this.textField = options.textField ?? 'text';
18
+ this.parentKeyField = options.parentKeyField ?? 'parentId';
19
+ this.nodeMap = new Map();
20
+ this.expendDeep = options.expendDeep ?? 999;
21
+ }
22
+ setData(list) {
23
+ this.nodeMap = new Map();
24
+ this.#nodes = [];
25
+ // 初始化每个节点
26
+ for (const item of list) {
27
+ const node = {
28
+ item,
29
+ expand: true
30
+ };
31
+ const key = item[this.keyField];
32
+ this.nodeMap.set(key, node);
33
+ }
34
+ for (const item of list) {
35
+ const node = this.nodeMap.get(item[this.keyField]);
36
+ if (node) {
37
+ this.appendNode(node);
38
+ }
39
+ }
40
+ }
41
+ appendNode(node, doSort = false) {
42
+ let item = node.item;
43
+ const parentKey = item[this.parentKeyField];
44
+ if (this.checkIsRoot(item) || !this.nodeMap.has(parentKey)) {
45
+ this.#nodes.push(node);
46
+ }
47
+ else {
48
+ const parentNode = this.nodeMap.get(parentKey);
49
+ if (parentNode) {
50
+ parentNode.expand = true;
51
+ parentNode.children = [...(parentNode.children ?? []), node];
52
+ if (doSort && this.compareFun) {
53
+ parentNode.children = parentNode.children.sort(this.compareFun);
54
+ }
55
+ }
56
+ }
57
+ }
58
+ collectExpandedNodes(tree) {
59
+ const result = [];
60
+ function traverse(nodes) {
61
+ for (const node of nodes) {
62
+ result.push(node);
63
+ if (node.expand && node.children) {
64
+ traverse(node.children);
65
+ }
66
+ }
67
+ }
68
+ traverse(tree);
69
+ return result;
70
+ }
71
+ /**
72
+ * 获取展开的展示列表
73
+ */
74
+ getHierarchyList() {
75
+ return this.collectExpandedNodes(this.#nodes);
76
+ }
77
+ /**
78
+ * 获取节点
79
+ */
80
+ get nodes() {
81
+ return this.#nodes;
82
+ }
83
+ /**
84
+ * 增加一个新节点
85
+ * @param item
86
+ */
87
+ append(item) {
88
+ const node = {
89
+ item,
90
+ expand: true
91
+ };
92
+ this.appendNode(node, true);
93
+ this.nodeMap.set(item[this.keyField], node);
94
+ }
95
+ /**
96
+ * 替换一个节点的数据
97
+ * @param item
98
+ */
99
+ replace(item) {
100
+ let node = this.nodeMap.get(item[this.keyField]);
101
+ if (node) {
102
+ node.item = item;
103
+ let parent = this.nodeMap.get(item[this.parentKeyField]);
104
+ if (parent && parent.children && parent.children.length > 0) {
105
+ parent.children = parent.children.sort(this.compareFun);
106
+ }
107
+ }
108
+ }
109
+ remove(item) {
110
+ let idKey = item[this.keyField];
111
+ let node = this.nodeMap.get(idKey);
112
+ if (node) {
113
+ let parent = this.nodeMap.get(node.item[this.parentKeyField]);
114
+ this.nodeMap.delete(idKey);
115
+ if (parent && parent.children) {
116
+ let pos = parent.children.findIndex(el => el.item[this.keyField] == idKey);
117
+ if (pos > -1) {
118
+ parent.children.splice(pos, 1);
119
+ }
120
+ }
121
+ }
122
+ }
123
+ /**
124
+ * 将一个节点移动到另外一个节点下
125
+ * @param item
126
+ * @param parentId
127
+ */
128
+ moveTo(item, parentId) {
129
+ let newParent = this.nodeMap.get(parentId);
130
+ let node = this.nodeMap.get(item[this.keyField]);
131
+ let currentParent = this.nodeMap.get(item[this.parentKeyField]);
132
+ if (newParent && node && currentParent && currentParent.children) {
133
+ let pos = currentParent.children.findIndex(el => el.item[this.keyField] == item[this.keyField]);
134
+ if (pos > -1) {
135
+ currentParent.children.splice(pos, 1);
136
+ }
137
+ newParent.children = [...(newParent.children ?? []), node];
138
+ if (this.compareFun) {
139
+ newParent.children = newParent.children.sort(this.compareFun);
140
+ }
141
+ }
142
+ }
143
+ extractChildrenDirectories(node, exclusiveValue) {
144
+ if (node.children && node.item[this.keyField] != exclusiveValue) {
145
+ let newNode = {
146
+ item: node.item,
147
+ expand: true,
148
+ children: []
149
+ };
150
+ for (let childNode of node.children) {
151
+ let ncNode = this.extractChildrenDirectories(childNode, exclusiveValue);
152
+ if (ncNode) {
153
+ newNode.children?.push(ncNode);
154
+ }
155
+ }
156
+ return newNode;
157
+ }
158
+ else {
159
+ return;
160
+ }
161
+ }
162
+ extractDirectories(exclusiveValue) {
163
+ let dirNodes = [];
164
+ for (let node of this.nodes) {
165
+ let newNode = this.extractChildrenDirectories(node, exclusiveValue);
166
+ if (newNode) {
167
+ dirNodes.push(newNode);
168
+ }
169
+ }
170
+ return dirNodes;
171
+ }
172
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ticatec/uniface-element",
3
- "version": "0.1.45",
3
+ "version": "0.1.46",
4
4
  "description": "uniface web elements",
5
5
  "scripts": {
6
6
  "dev": "vite dev",