@wavemaker/app-ng-runtime 11.4.0-next.28152 → 11.4.0-rc.121

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 (153) hide show
  1. app-ng-runtime/build-task/basic/tree/tree.build.d.ts +1 -2
  2. app-ng-runtime/build-task/bundles/index.umd.js +8 -10
  3. app-ng-runtime/build-task/bundles/index.umd.js.map +1 -1
  4. app-ng-runtime/build-task/esm2015/basic/tree/tree.build.js +3 -4
  5. app-ng-runtime/build-task/esm2015/data/form/form-field/form-field.build.js +2 -2
  6. app-ng-runtime/build-task/esm2015/navigation/popover/popover.build.js +3 -3
  7. app-ng-runtime/build-task/fesm2015/index.js +8 -10
  8. app-ng-runtime/build-task/fesm2015/index.js.map +1 -1
  9. app-ng-runtime/components/base/bundles/index.umd.js +44 -8
  10. app-ng-runtime/components/base/bundles/index.umd.js.map +1 -1
  11. app-ng-runtime/components/base/esm2015/directives/show-in-device.directive.js +16 -5
  12. app-ng-runtime/components/base/esm2015/public_api.js +2 -2
  13. app-ng-runtime/components/base/esm2015/utils/widget-utils.js +22 -4
  14. app-ng-runtime/components/base/esm2015/widgets/common/base/base-field-validations.js +3 -2
  15. app-ng-runtime/components/base/esm2015/widgets/common/dialog/dialog.service.js +7 -1
  16. app-ng-runtime/components/base/fesm2015/index.js +45 -10
  17. app-ng-runtime/components/base/fesm2015/index.js.map +1 -1
  18. app-ng-runtime/components/base/index.metadata.json +1 -1
  19. app-ng-runtime/components/base/public_api.d.ts +1 -1
  20. app-ng-runtime/components/base/utils/widget-utils.d.ts +8 -1
  21. app-ng-runtime/components/basic/tree/bundles/index.umd.js +369 -245
  22. app-ng-runtime/components/basic/tree/bundles/index.umd.js.map +1 -1
  23. app-ng-runtime/components/basic/tree/esm2015/public_api.js +2 -2
  24. app-ng-runtime/components/basic/tree/esm2015/tree.component.js +403 -0
  25. app-ng-runtime/components/basic/tree/esm2015/tree.module.js +3 -3
  26. app-ng-runtime/components/basic/tree/fesm2015/index.js +333 -240
  27. app-ng-runtime/components/basic/tree/fesm2015/index.js.map +1 -1
  28. app-ng-runtime/components/basic/tree/index.metadata.json +1 -1
  29. app-ng-runtime/components/basic/tree/public_api.d.ts +1 -1
  30. app-ng-runtime/components/basic/tree/tree.component.d.ts +43 -0
  31. app-ng-runtime/components/chart/bundles/index.umd.js +1 -1
  32. app-ng-runtime/components/chart/bundles/index.umd.js.map +1 -1
  33. app-ng-runtime/components/chart/esm2015/chart.component.js +2 -2
  34. app-ng-runtime/components/chart/fesm2015/index.js +1 -1
  35. app-ng-runtime/components/chart/fesm2015/index.js.map +1 -1
  36. app-ng-runtime/components/containers/tabs/bundles/index.umd.js +39 -23
  37. app-ng-runtime/components/containers/tabs/bundles/index.umd.js.map +1 -1
  38. app-ng-runtime/components/containers/tabs/esm2015/tab-pane/tab-pane.component.js +8 -1
  39. app-ng-runtime/components/containers/tabs/esm2015/tabs.animator.js +33 -13
  40. app-ng-runtime/components/containers/tabs/fesm2015/index.js +40 -13
  41. app-ng-runtime/components/containers/tabs/fesm2015/index.js.map +1 -1
  42. app-ng-runtime/components/containers/tabs/tabs.animator.d.ts +5 -1
  43. app-ng-runtime/components/containers/wizard/bundles/index.umd.js +43 -2
  44. app-ng-runtime/components/containers/wizard/bundles/index.umd.js.map +1 -1
  45. app-ng-runtime/components/containers/wizard/esm2015/wizard-step/wizard-step.props.js +3 -2
  46. app-ng-runtime/components/containers/wizard/esm2015/wizard.component.js +42 -2
  47. app-ng-runtime/components/containers/wizard/fesm2015/index.js +43 -2
  48. app-ng-runtime/components/containers/wizard/fesm2015/index.js.map +1 -1
  49. app-ng-runtime/components/containers/wizard/index.metadata.json +1 -1
  50. app-ng-runtime/components/containers/wizard/wizard.component.d.ts +2 -0
  51. app-ng-runtime/components/data/form/bundles/index.umd.js +37 -13
  52. app-ng-runtime/components/data/form/bundles/index.umd.js.map +1 -1
  53. app-ng-runtime/components/data/form/esm2015/form-field/form-field.directive.js +26 -7
  54. app-ng-runtime/components/data/form/esm2015/form.component.js +10 -5
  55. app-ng-runtime/components/data/form/fesm2015/index.js +34 -10
  56. app-ng-runtime/components/data/form/fesm2015/index.js.map +1 -1
  57. app-ng-runtime/components/data/form/index.metadata.json +1 -1
  58. app-ng-runtime/components/data/list/bundles/index.umd.js +52 -43
  59. app-ng-runtime/components/data/list/bundles/index.umd.js.map +1 -1
  60. app-ng-runtime/components/data/list/esm2015/list.component.js +52 -43
  61. app-ng-runtime/components/data/list/fesm2015/index.js +51 -42
  62. app-ng-runtime/components/data/list/fesm2015/index.js.map +1 -1
  63. app-ng-runtime/components/data/list/index.metadata.json +1 -1
  64. app-ng-runtime/components/data/list/list.component.d.ts +1 -1
  65. app-ng-runtime/components/data/pagination/bundles/index.umd.js +22 -5
  66. app-ng-runtime/components/data/pagination/bundles/index.umd.js.map +1 -1
  67. app-ng-runtime/components/data/pagination/esm2015/pagination.component.js +23 -6
  68. app-ng-runtime/components/data/pagination/fesm2015/index.js +22 -5
  69. app-ng-runtime/components/data/pagination/fesm2015/index.js.map +1 -1
  70. app-ng-runtime/components/data/pagination/index.metadata.json +1 -1
  71. app-ng-runtime/components/data/pagination/pagination.component.d.ts +1 -0
  72. app-ng-runtime/components/data/table/bundles/index.umd.js +64 -12
  73. app-ng-runtime/components/data/table/bundles/index.umd.js.map +1 -1
  74. app-ng-runtime/components/data/table/esm2015/table.component.js +63 -13
  75. app-ng-runtime/components/data/table/esm2015/table.props.js +3 -1
  76. app-ng-runtime/components/data/table/fesm2015/index.js +64 -12
  77. app-ng-runtime/components/data/table/fesm2015/index.js.map +1 -1
  78. app-ng-runtime/components/data/table/index.metadata.json +1 -1
  79. app-ng-runtime/components/data/table/table.component.d.ts +9 -0
  80. app-ng-runtime/components/dialogs/default/base-dialog.d.ts +1 -0
  81. app-ng-runtime/components/dialogs/default/bundles/index.umd.js +17 -3
  82. app-ng-runtime/components/dialogs/default/bundles/index.umd.js.map +1 -1
  83. app-ng-runtime/components/dialogs/default/esm2015/base-dialog.js +18 -5
  84. app-ng-runtime/components/dialogs/default/fesm2015/index.js +17 -4
  85. app-ng-runtime/components/dialogs/default/fesm2015/index.js.map +1 -1
  86. app-ng-runtime/components/dialogs/default/index.metadata.json +1 -1
  87. app-ng-runtime/components/input/epoch/base-date-time.component.d.ts +1 -0
  88. app-ng-runtime/components/input/epoch/bundles/index.umd.js +78 -35
  89. app-ng-runtime/components/input/epoch/bundles/index.umd.js.map +1 -1
  90. app-ng-runtime/components/input/epoch/date-time/date-time-picker.component.d.ts +1 -0
  91. app-ng-runtime/components/input/epoch/esm2015/base-date-time.component.js +55 -31
  92. app-ng-runtime/components/input/epoch/esm2015/date/date.component.js +3 -3
  93. app-ng-runtime/components/input/epoch/esm2015/date-time/date-time-picker.component.js +31 -11
  94. app-ng-runtime/components/input/epoch/esm2015/date-time/date-time.component.js +2 -2
  95. app-ng-runtime/components/input/epoch/fesm2015/index.js +87 -43
  96. app-ng-runtime/components/input/epoch/fesm2015/index.js.map +1 -1
  97. app-ng-runtime/components/input/epoch/index.metadata.json +1 -1
  98. app-ng-runtime/components/navigation/menu/bundles/index.umd.js +25 -19
  99. app-ng-runtime/components/navigation/menu/bundles/index.umd.js.map +1 -1
  100. app-ng-runtime/components/navigation/menu/esm2015/menu-dropdown-item/menu-dropdown-item.component.js +15 -5
  101. app-ng-runtime/components/navigation/menu/esm2015/menu.component.js +14 -19
  102. app-ng-runtime/components/navigation/menu/fesm2015/index.js +25 -20
  103. app-ng-runtime/components/navigation/menu/fesm2015/index.js.map +1 -1
  104. app-ng-runtime/components/navigation/menu/index.metadata.json +1 -1
  105. app-ng-runtime/components/navigation/menu/menu-dropdown-item/menu-dropdown-item.component.d.ts +7 -4
  106. app-ng-runtime/components/navigation/menu/menu.component.d.ts +3 -7
  107. app-ng-runtime/components/navigation/popover/bundles/index.umd.js +3 -1
  108. app-ng-runtime/components/navigation/popover/bundles/index.umd.js.map +1 -1
  109. app-ng-runtime/components/navigation/popover/esm2015/popover.component.js +5 -3
  110. app-ng-runtime/components/navigation/popover/fesm2015/index.js +4 -2
  111. app-ng-runtime/components/navigation/popover/fesm2015/index.js.map +1 -1
  112. app-ng-runtime/core/bundles/index.umd.js +19 -3
  113. app-ng-runtime/core/bundles/index.umd.js.map +1 -1
  114. app-ng-runtime/core/esm2015/services/pagination.service.js +8 -2
  115. app-ng-runtime/core/esm2015/services/viewport.service.js +6 -4
  116. app-ng-runtime/core/esm2015/utils/utils.js +11 -3
  117. app-ng-runtime/core/fesm2015/index.js +22 -6
  118. app-ng-runtime/core/fesm2015/index.js.map +1 -1
  119. app-ng-runtime/core/index.metadata.json +1 -1
  120. app-ng-runtime/core/utils/utils.d.ts +2 -2
  121. app-ng-runtime/mobile/components/page/default/bundles/index.umd.js +24 -6
  122. app-ng-runtime/mobile/components/page/default/bundles/index.umd.js.map +1 -1
  123. app-ng-runtime/mobile/components/page/default/esm2015/page.directive.js +20 -3
  124. app-ng-runtime/mobile/components/page/default/fesm2015/index.js +19 -2
  125. app-ng-runtime/mobile/components/page/default/fesm2015/index.js.map +1 -1
  126. app-ng-runtime/mobile/components/page/default/index.metadata.json +1 -1
  127. app-ng-runtime/mobile/components/page/default/page.directive.d.ts +4 -1
  128. app-ng-runtime/package.json +1 -1
  129. app-ng-runtime/runtime/base/bundles/index.umd.js +164 -133
  130. app-ng-runtime/runtime/base/bundles/index.umd.js.map +1 -1
  131. app-ng-runtime/runtime/base/esm2015/components/app-component/app.component.js +2 -2
  132. app-ng-runtime/runtime/base/esm2015/public_api.js +2 -1
  133. app-ng-runtime/runtime/base/esm2015/runtime-base.module.js +3 -1
  134. app-ng-runtime/runtime/base/esm2015/services/app.service.js +3 -1
  135. app-ng-runtime/runtime/base/esm2015/services/pipe.service.js +33 -0
  136. app-ng-runtime/runtime/base/fesm2015/index.js +149 -120
  137. app-ng-runtime/runtime/base/fesm2015/index.js.map +1 -1
  138. app-ng-runtime/runtime/base/index.metadata.json +1 -1
  139. app-ng-runtime/runtime/base/public_api.d.ts +1 -0
  140. app-ng-runtime/runtime/base/services/pipe.service.d.ts +9 -0
  141. app-ng-runtime/scripts/datatable/datatable.js +86 -36
  142. app-ng-runtime/scripts/tree-keyboard-navigation/keyboard-navigation.js +251 -0
  143. app-ng-runtime/variables/bundles/index.umd.js +37 -22
  144. app-ng-runtime/variables/bundles/index.umd.js.map +1 -1
  145. app-ng-runtime/variables/esm2015/manager/action/notification-action.manager.js +29 -24
  146. app-ng-runtime/variables/esm2015/service/variables.service.js +8 -1
  147. app-ng-runtime/variables/fesm2015/index.js +35 -24
  148. app-ng-runtime/variables/fesm2015/index.js.map +1 -1
  149. app-ng-runtime/variables/index.metadata.json +1 -1
  150. app-ng-runtime/variables/manager/action/notification-action.manager.d.ts +1 -0
  151. app-ng-runtime/variables/service/variables.service.d.ts +4 -0
  152. app-ng-runtime/components/basic/tree/esm2015/tree.directive.js +0 -310
  153. app-ng-runtime/components/basic/tree/tree.directive.d.ts +0 -35
@@ -1,7 +1,7 @@
1
- import { Directive, Injector, Attribute, NgModule } from '@angular/core';
1
+ import { Component, ViewEncapsulation, Injector, NgModule } from '@angular/core';
2
2
  import { CommonModule } from '@angular/common';
3
- import { register, PROP_STRING, PROP_ANY, PROP_NUMBER, PROP_BOOLEAN, StylableComponent, styler, APPLY_STYLES_TYPE, getEvaluatedData, getOrderedDataset, provideAsWidgetRef, WmComponentsModule } from '@wm/components/base';
4
- import { $parseExpr, getClonedObject, $appDigest, $parseEvent } from '@wm/core';
3
+ import { register, PROP_STRING, PROP_ANY, PROP_NUMBER, PROP_BOOLEAN, StylableComponent, styler, APPLY_STYLES_TYPE, getOrderedDataset, provideAsWidgetRef, WmComponentsModule } from '@wm/components/base';
4
+ import { getClonedObject } from '@wm/core';
5
5
 
6
6
  const registerProps = () => {
7
7
  register('wm-tree', new Map([
@@ -23,136 +23,106 @@ const registerProps = () => {
23
23
  ]));
24
24
  };
25
25
 
26
- const defaultTreeIconClass = 'plus-minus';
27
- const ICON_CLASSES = {
28
- 'folder': {
29
- 'expanded': 'wi-folder-open',
30
- 'collapsed': 'wi-folder'
31
- },
32
- 'circle-plus-minus': {
33
- 'expanded': 'wi-remove-circle-outline',
34
- 'collapsed': 'wi-add-circle-outline'
35
- },
36
- 'chevron': {
37
- 'expanded': 'wi-keyboard-arrow-down',
38
- 'collapsed': 'wi-keyboard-arrow-right'
39
- },
40
- 'menu': {
41
- 'expanded': 'wi-arrow-down',
42
- 'collapsed': 'wi-arrow-right'
43
- },
44
- 'triangle': {
45
- 'expanded': 'wi-arrow-drop-down-circle',
46
- 'collapsed': 'wi-play-circle-filled'
47
- },
48
- 'expand-collapse': {
49
- 'expanded': 'wi-expand-less',
50
- 'collapsed': 'wi-expand-more'
51
- },
52
- 'plus-minus': {
53
- 'expanded': 'wi-minus',
54
- 'collapsed': 'wi-plus'
55
- }
56
- };
57
26
  const WIDGET_INFO = { widgetType: 'wm-tree', hostClass: 'app-tree' };
58
- class TreeDirective extends StylableComponent {
59
- constructor(inj, binddatavalue, bindnodelabel, bindnodeicon, bindnodechildren, bindnodeid) {
27
+ const defaultTreeIconClass = 'plus-minus';
28
+ class TreeComponent extends StylableComponent {
29
+ constructor(inj) {
60
30
  super(inj, WIDGET_INFO);
61
- this.binddatavalue = binddatavalue;
62
- this.bindnodelabel = bindnodelabel;
63
- this.bindnodeicon = bindnodeicon;
64
- this.bindnodechildren = bindnodechildren;
65
- this.bindnodeid = bindnodeid;
31
+ this.setting = {
32
+ data: {
33
+ simpleData: {
34
+ enable: false
35
+ },
36
+ key: {
37
+ children: 'children',
38
+ name: 'label'
39
+ }
40
+ },
41
+ view: {
42
+ dblClickExpand: false,
43
+ fontCss: {
44
+ 'font-awesome': true
45
+ },
46
+ switchIcon: {},
47
+ },
48
+ check: {},
49
+ callback: {}
50
+ };
66
51
  styler(this.nativeElement, this, APPLY_STYLES_TYPE.CONTAINER);
67
- this.bindEvents();
68
52
  }
69
53
  onPropertyChange(key, nv, ov) {
70
54
  switch (key) {
71
55
  case 'dataset':
72
56
  this.nodes = this.getNodes(nv);
73
- this._selectNode = undefined;
57
+ if (this.level > 0) {
58
+ this.expandTree(this.level, this.nodes, 0);
59
+ }
60
+ this.renderTree();
61
+ break;
62
+ case 'levels':
63
+ if (nv > 0) {
64
+ this.level = nv;
65
+ }
66
+ this.renderTree();
67
+ break;
68
+ case 'treeicons':
69
+ this.treeicon = nv;
74
70
  this.renderTree();
75
71
  break;
76
- case 'nodeicon':
77
72
  case 'nodelabel':
73
+ this.setting.data.key.name = this.labelKey;
74
+ this.renderTree();
75
+ break;
78
76
  case 'nodechildren':
79
- case 'orderby':
77
+ this.setting.data.key.children = this.childrenKey;
80
78
  this.renderTree();
81
79
  break;
82
- case 'treeicons':
83
- this.changeTreeIcons(nv, ov);
80
+ case 'nodeicon':
81
+ this.nodeicon = this.iconKey;
82
+ this.renderTree();
84
83
  break;
85
- case 'datavalue':
86
- this.selectById(nv);
84
+ case 'orderby':
85
+ this.renderTree();
86
+ break;
87
+ case 'class':
88
+ this.treeClass = nv;
89
+ this.renderTree();
87
90
  break;
88
91
  default:
89
92
  super.onPropertyChange(key, nv, ov);
93
+ break;
90
94
  }
91
95
  }
92
- constructNodes(nodes, parent, levels, deep, _evalDataValue) {
93
- const $ul = $('<ul></ul>');
94
- const _iconClses = ICON_CLASSES[this.treeicons || defaultTreeIconClass];
95
- const _expr = (this.binddatavalue || this.datavalue);
96
- let _iconCls, _cls;
97
- _cls = levels > 0 ? ' expanded ' : ' collapsed ';
98
- _iconCls = _cls + (levels > 0 ? _iconClses.expanded : _iconClses.collapsed);
99
- deep = deep || 0;
100
- parent.append($ul);
101
- nodes.forEach((node, idx) => {
102
- const $li = $('<li></li>'), $iconNode = $('<i></i>'), nodeLabel = getEvaluatedData(node, { field: this.nodelabel, bindExpression: this.bindnodelabel }, this.viewParent) || node.label, nodeIcon = getEvaluatedData(node, { field: this.nodeicon, bindExpression: this.bindnodeicon }, this.viewParent) || node.icon, nodeChildren = getEvaluatedData(node, { field: this.nodechildren, bindExpression: this.bindnodechildren }, this.viewParent) || node.children;
103
- let nodeIdValue = getEvaluatedData(node, { field: this.nodeid, bindExpression: this.bindnodeid }, this.viewParent);
104
- if (nodeIdValue === undefined) {
105
- nodeIdValue = node.children;
106
- }
107
- let isNodeMatched = false, expandCollapseIcon;
108
- $li.data('nodedata', node)
109
- .append($iconNode)
110
- .append(`<span class="title">${nodeLabel}</span>`)
111
- .appendTo($ul);
112
- // if datavalue(ie, expr) is provided select the tree node accordingly
113
- // if datavalue === 'FirstNode' -- select the FirstNode at level 0
114
- // if datavalue === 'LastNode' -- select the LastNode at level 0
115
- // if datavalue is a bind expression evaluate the expression for each node of the tree till the condition is satisfied.
116
- // if node identifier is present then verify the datavalue is bound expr or static value and compare with the node model
117
- if (this.bindnodeid || this.nodeid) {
118
- isNodeMatched = this.binddatavalue ? nodeIdValue === _evalDataValue : nodeIdValue === _expr;
119
- if (nodeIdValue !== undefined) {
120
- $li.attr('id', nodeIdValue);
121
- }
122
- }
123
- else if (this.binddatavalue) { // evaluate the expression only if it is bound (useExpression)
124
- isNodeMatched = !!$parseExpr(_expr)(this, node);
125
- }
126
- // Perform LastNode check only at level 0.(ie, deep = 0);
127
- if (!this._selectNode) {
128
- if ((_expr === 'FirstNode' && idx === 0)
129
- || (!deep && _expr === 'LastNode' && idx === nodes.length - 1)
130
- || isNodeMatched) {
131
- // save a reference of the node to be selected in `_selectNode`
132
- this._selectNode = $li;
133
- this.datavalue = nodeIdValue;
134
- }
135
- }
136
- if (nodeIcon) {
137
- $iconNode.addClass(nodeIcon);
138
- }
139
- if (nodeChildren && nodeChildren.length) { // parent node
140
- $li.addClass(`parent-node ${_cls}`);
141
- expandCollapseIcon = $(`<i class="wi ${_iconCls}"></i>`);
142
- if (nodeIcon) {
143
- $iconNode.addClass(nodeIcon);
144
- }
145
- $li.prepend(expandCollapseIcon);
146
- this.constructNodes(nodeChildren, $li, levels - 1, deep + 1, _evalDataValue);
96
+ // expands the tree nodes if the property is selected.
97
+ expandTree(level, node, childLevel) {
98
+ node.map(childNode => {
99
+ const children = this.getChildren(childNode);
100
+ if (children && !("open" in childNode) && childLevel < level) {
101
+ childNode["open"] = true;
102
+ this.expandTree(level, children, childLevel + 1);
147
103
  }
148
104
  else {
149
- if (!nodeIcon) {
150
- $iconNode.addClass('leaf-node');
151
- }
152
- $li.addClass('leaf-node');
105
+ childLevel = 0;
106
+ return;
153
107
  }
154
108
  });
155
109
  }
110
+ // sets the template for the tree based on the property selected.
111
+ setTreeTemplate(value) {
112
+ if (value === 'Classic') {
113
+ this.setting.check["enable"] = false;
114
+ }
115
+ else if (value === 'Checkbox') {
116
+ this.setting.check["enable"] = true;
117
+ this.setting.check["chkStyle"] = 'checkbox';
118
+ }
119
+ else if (value === 'Radio') {
120
+ this.setting.check["enable"] = true;
121
+ this.setting.check["chkStyle"] = 'radio';
122
+ this.setting.check["radioType"] = "all";
123
+ }
124
+ }
125
+ // extracts nodes from string format
156
126
  getNodesFromString(value) {
157
127
  return value.split(',').map((item) => {
158
128
  return {
@@ -160,177 +130,300 @@ class TreeDirective extends StylableComponent {
160
130
  };
161
131
  });
162
132
  }
133
+ // gets the nodes and orders the nodes if required
163
134
  getNodes(newVal) {
164
135
  let nodes;
165
- if (_.isString(newVal) && !_.isEmpty(newVal)) {
136
+ if (_.isArray(newVal)) {
137
+ nodes = getOrderedDataset(newVal, this.orderby);
138
+ }
139
+ else if (_.isObject(newVal)) {
140
+ nodes = [newVal];
141
+ }
142
+ else if (_.isString(newVal) && !_.isEmpty(newVal)) {
166
143
  newVal = newVal.trim();
167
144
  if (newVal) {
168
145
  nodes = this.getNodesFromString(newVal);
169
146
  }
170
147
  }
171
- else if (_.isArray(newVal)) {
172
- newVal = getOrderedDataset(newVal, this.orderby);
173
- nodes = newVal;
148
+ return nodes;
149
+ }
150
+ // adds class to the nodes inorder to add icons to respective node.
151
+ setNodeclasses(treeId, treeNode) {
152
+ return treeNode.icon ? { add: [`${treeNode.icon}`] } : '';
153
+ }
154
+ ;
155
+ // Sets the node label with any icon if bound to
156
+ setNodeData(nodes, depth, level, parentNode, type) {
157
+ if (depth === 0) {
158
+ nodes.map(node => {
159
+ const children = this.getChildren(node);
160
+ if (children) {
161
+ this.setNodeData(children, depth, level, parentNode, type);
162
+ }
163
+ if (node.icon && this.nodelabel == 'icon') {
164
+ node[type] = node.icon;
165
+ }
166
+ else if (node.name && this.nodelabel == 'name') {
167
+ node[type] = node.name;
168
+ }
169
+ else {
170
+ return;
171
+ }
172
+ });
174
173
  }
175
- else if (_.isObject(newVal)) {
176
- nodes = [newVal];
174
+ else {
175
+ nodes.map(node => {
176
+ const children = this.getChildren(node);
177
+ if (children && level > 1) {
178
+ if (depth === level) {
179
+ parentNode = node;
180
+ }
181
+ this.setNodeData(children, depth, level - 1, parentNode, type);
182
+ }
183
+ if (level === 1 && (type === "name" ? this.nodelabel.includes("label") || this.nodelabel.includes("name") : this.nodeicon.includes("label") || this.nodeicon.includes("name"))) {
184
+ parentNode[type] = node.name || node.label;
185
+ return;
186
+ }
187
+ else if (level === 1 && (node.icon !== undefined) && (type === "name" ? this.nodelabel.includes("icon") : this.nodeicon.includes("icon"))) {
188
+ parentNode[type] = node.icon;
189
+ return;
190
+ }
191
+ else {
192
+ return;
193
+ }
194
+ });
177
195
  }
178
- return nodes;
179
196
  }
180
- changeTreeIcons(nv, ov) {
181
- const $el = $(this.nativeElement);
182
- nv = nv || defaultTreeIconClass;
183
- ov = ov || defaultTreeIconClass;
184
- $el.find('i.expanded').removeClass(ICON_CLASSES[ov].expanded).addClass(ICON_CLASSES[nv].expanded);
185
- $el.find('i.collapsed').removeClass(ICON_CLASSES[ov].collapsed).addClass(ICON_CLASSES[nv].collapsed);
197
+ // adds tree icons to the nodes on load of the tree
198
+ changeTreeIcons(nv) {
199
+ let eleClose = $('ul[name="' + this.name + '"] li span.button.switch');
200
+ $(eleClose).map((idx, ele) => {
201
+ $(ele).addClass(nv);
202
+ $(ele).on("click", function (e) {
203
+ setTimeout(() => {
204
+ $(ele).addClass(nv);
205
+ }, 0);
206
+ });
207
+ });
208
+ }
209
+ getPath(treeNode, path) {
210
+ if (treeNode.getParentNode() === null) {
211
+ path = "/" + treeNode[this.labelKey] + path;
212
+ }
213
+ else {
214
+ path = this.getPath(treeNode.getParentNode(), path) + "/" + treeNode[this.labelKey];
215
+ }
216
+ return path;
217
+ }
218
+ // binds the click event to all nodes to open the child nodes
219
+ onClick(event, treeId, treeNode, clickFlag) {
220
+ if (this.nodeclick === "expand") {
221
+ var nodes = this.treeObj.getSelectedNodes();
222
+ if (nodes.length > 0) {
223
+ this.expandNode(nodes[0], !nodes[0].open, true);
224
+ }
225
+ }
226
+ let path = this.getPath(treeNode, "");
227
+ const eventParams = {
228
+ '$event': event,
229
+ "$item": treeNode,
230
+ "$path": path
231
+ };
232
+ this.setSelectedItem(treeNode);
233
+ this.invokeEventCallback('select', eventParams);
186
234
  }
187
- toggleExpandCollapseNode($event, $i, $li) {
188
- const treeIcons = ICON_CLASSES[this.treeicons || defaultTreeIconClass];
189
- const $liPath = this.findSelectedNodeParent($li);
190
- let path = '';
191
- // construct the path of the node
192
- $liPath
193
- .each((i, el) => {
194
- const current = $(el).children('.title').text();
195
- path = `/${current + path}`;
235
+ // Adds tree icon classes to child nodes when expanded
236
+ onExpand(event, treeId, treeNode) {
237
+ let self = this;
238
+ let path = this.getPath(treeNode, "");
239
+ const eventParams = {
240
+ '$event': event,
241
+ "$item": treeNode,
242
+ "$path": path
243
+ };
244
+ this.invokeEventCallback('expand', eventParams);
245
+ const children = this.getChildren(treeNode);
246
+ children === null || children === void 0 ? void 0 : children.map((el) => {
247
+ if (el.isParent) {
248
+ let ele = $(`#${el.tId}_switch`);
249
+ $(ele).addClass(self.treeicon || defaultTreeIconClass);
250
+ $(ele).on("click", function (e) {
251
+ setTimeout(() => {
252
+ $(ele).addClass(self.treeicon || defaultTreeIconClass);
253
+ }, 0);
254
+ });
255
+ }
196
256
  });
257
+ }
258
+ onCollapse(event, treeId, treeNode) {
259
+ let path = this.getPath(treeNode, "");
197
260
  const eventParams = {
198
- '$event': $event,
199
- "$item": $li.data('nodedata'),
261
+ '$event': event,
262
+ "$item": treeNode,
200
263
  "$path": path
201
264
  };
202
- if ($i.hasClass('collapsed')) {
203
- $i.removeClass(`collapsed ${treeIcons.collapsed}`).addClass(`expanded ${treeIcons.expanded}`);
204
- $li.removeClass('collapsed').addClass('expanded');
205
- this.invokeEventCallback('expand', eventParams);
206
- }
207
- else if ($i.hasClass('expanded')) {
208
- $i.removeClass(`expanded ${treeIcons.expanded}`).addClass(`collapsed ${treeIcons.collapsed}`);
209
- $li.removeClass('expanded').addClass('collapsed');
210
- this.invokeEventCallback('collapse', eventParams);
265
+ this.invokeEventCallback('collapse', eventParams);
266
+ }
267
+ getChildren(node) {
268
+ return node[this.childrenKey];
269
+ }
270
+ get childrenKey() {
271
+ if (!this.nodechildren) {
272
+ return 'children';
211
273
  }
274
+ const depth = this.countDepth(this.nodechildren);
275
+ return depth ? this.nodechildren.split('.').pop() : this.nodechildren;
212
276
  }
213
- renderTree(forceRender) {
214
- let docFrag, $li, $liPath, data, path = '';
215
- const levels = +this.nativeElement.getAttribute('levels') || 0, $el = $(this.nativeElement);
216
- $el.empty();
217
- if (forceRender) {
218
- this._selectNode = undefined;
277
+ get labelKey() {
278
+ if (!this.nodelabel) {
279
+ return 'label';
219
280
  }
220
- if (this.nodes && this.nodes.length) {
221
- docFrag = document.createDocumentFragment();
222
- this.constructNodes(this.nodes, $(docFrag), levels, 0, this.datavalue);
223
- $el.append(docFrag);
281
+ const depth = this.countDepth(this.nodelabel);
282
+ return depth ? this.nodelabel.split('.').pop() : this.nodelabel;
283
+ }
284
+ get iconKey() {
285
+ if (!this.nodeicon) {
286
+ return 'icon';
224
287
  }
225
- if (this._selectNode) {
226
- $li = this._selectNode;
227
- $li.addClass('selected');
228
- data = $li.data('nodedata');
229
- $liPath = this.findSelectedNodeParent($li);
230
- if (!$liPath.length) {
231
- $liPath = $li;
288
+ const depth = this.countDepth(this.nodeicon);
289
+ return depth ? this.nodeicon.split('.').pop() : this.nodeicon;
290
+ }
291
+ get treeObj() {
292
+ return $.fn.zTree.getZTreeObj(`${this.name}`);
293
+ }
294
+ // function to support backward compatibility of objects
295
+ modifyObjects(array) {
296
+ array.forEach(obj => {
297
+ obj.icon = obj[this.nodeicon];
298
+ const children = this.getChildren(obj);
299
+ if (children === null || children === void 0 ? void 0 : children.length) {
300
+ this.modifyObjects(children);
232
301
  }
233
- $liPath
234
- .each((i, el) => {
235
- const $current = $(el), $i = $current.children('i.collapsed'), $title = $current.children('.title');
236
- this.toggleExpandCollapseNode(undefined, $i, $current);
237
- path = `/${$title.text() + path}`;
238
- });
239
- this.selecteditem = getClonedObject(data) || {};
240
- this.selecteditem.path = path;
241
- this.invokeEventCallback('select', { $event: undefined, $item: data, $path: path });
242
- $appDigest();
243
- }
302
+ });
244
303
  }
245
- selectNode(evt, value) {
246
- const target = evt && $(evt.target), $el = $(this.nativeElement), $li = _.isObject(value) ? value : $el.find(`li[id="${value}"]`).first();
247
- let data, path = '', $liPath, nodeAction;
248
- $el.find('.selected').removeClass('selected');
249
- if (!$li.length) {
250
- return;
304
+ // sets the node children property to parent nodes
305
+ setNodeChildren(nodes, depth, level, parentNode) {
306
+ if (depth <= 0) {
307
+ return nodes;
251
308
  }
252
- $li.addClass('selected');
253
- data = $li.data('nodedata');
254
- nodeAction = data[this.nodeaction || 'action'];
255
- // if the selectNode is initiated by click event then use the nativeElement target from event
256
- $liPath = target ? target.parents('.app-tree li') : this.findSelectedNodeParent($li);
257
- // construct the path of the node
258
- $liPath
259
- .each((i, el) => {
260
- const current = $(el).children('.title').text();
261
- path = `/${current + path}`;
262
- });
263
- // expand the current node till the viewParent level which is collapsed
264
- $li.parentsUntil($el, 'li.parent-node.collapsed')
265
- .each((index, el) => {
266
- const $current = $(el), $i = $current.children('i.collapsed');
267
- this.toggleExpandCollapseNode(undefined, $i, $current);
268
- });
269
- this.selecteditem = getClonedObject(data) || {};
270
- this.selecteditem.path = path;
271
- if (target) {
272
- if (this.nodeid || this.bindnodeid) {
273
- this.datavalue = getEvaluatedData(data, { field: this.nodeid, bindExpression: this.bindnodeid }, this.viewParent);
309
+ for (let i = 0; i < nodes.length; i++) {
310
+ const node = nodes[i];
311
+ if (depth === level) {
312
+ parentNode = nodes[i];
274
313
  }
275
- else {
276
- this.datavalue = getClonedObject(data) || {};
314
+ const children = this.getChildren(node);
315
+ if (children === null || children === void 0 ? void 0 : children.length) {
316
+ if (level === 1) {
317
+ parentNode[this.childrenKey] = children.map(child => ({ [this.labelKey]: child[this.labelKey], [this.childrenKey]: this.getChildren(child), icon: child[this.iconKey] }));
318
+ return;
319
+ }
320
+ else {
321
+ this.setNodeChildren(children, depth, level - 1, parentNode);
322
+ }
277
323
  }
278
324
  }
279
- else {
280
- this.datavalue = value;
281
- }
282
- //[Todo-CSP]: this data will be dynamic, can not generate function upfront
283
- if (nodeAction) {
284
- $parseEvent(nodeAction)(this);
325
+ return nodes;
326
+ }
327
+ countDepth(str) {
328
+ const regex = /\[.*?\]/g;
329
+ let matches = str.match(regex);
330
+ let count = 1;
331
+ if (matches === null)
332
+ return count;
333
+ for (let match of matches) {
334
+ count++;
285
335
  }
286
- this.invokeEventCallback('select', { $event: evt, $item: data, $path: path });
287
- $appDigest();
336
+ return count;
288
337
  }
289
- // click event is added on the host nativeElement
290
- bindEvents() {
291
- $(this.nativeElement).on('click', (evt) => {
292
- const target = $(evt.target), li = target.closest('li'), $i = target.is('i') ? target : target.siblings('i.collapsed,i.expanded');
293
- evt.stopPropagation();
294
- if (target.is('span.title')) { // select the node only if it is nodelabel
295
- this.selecteditem = {};
296
- this.selectNode(evt, li);
338
+ // Renders the tree on to the dom
339
+ renderTree() {
340
+ if (this.nodes) {
341
+ this.nativeElement.setAttribute('id', this.name);
342
+ if (this.nodeicon && this.nodeicon !== 'icon') {
343
+ this.modifyObjects(this.nodes);
297
344
  }
298
- if (target.is('i') || (target.is('span.title') && this.nodeclick === 'expand')) {
299
- this.toggleExpandCollapseNode(evt, $i, li);
345
+ this.setTreeTemplate(this.treeClass);
346
+ if (this.nodelabel) {
347
+ let depth = 0;
348
+ if (this.nodelabel.includes("children")) {
349
+ depth = this.countDepth(this.nodelabel);
350
+ }
351
+ this.setNodeData(this.nodes, depth, depth, null, "name");
300
352
  }
301
- });
353
+ if (this.nodeicon) {
354
+ let depth = 0;
355
+ if (this.nodeicon.includes("children")) {
356
+ depth = this.countDepth(this.nodeicon);
357
+ }
358
+ this.setNodeData(this.nodes, depth, depth, null, "icon");
359
+ }
360
+ if (this.nodechildren) {
361
+ let depth = this.countDepth(this.nodechildren);
362
+ if (depth > 1) {
363
+ this.nodes = this.setNodeChildren(this.nodes, depth, depth, null);
364
+ }
365
+ }
366
+ }
367
+ this.setting.view['nodeClasses'] = this.setNodeclasses;
368
+ this.setting.callback["onClick"] = this.onClick.bind(this);
369
+ this.setting.callback["onExpand"] = this.onExpand.bind(this);
370
+ this.setting.callback["onCollapse"] = this.onCollapse.bind(this);
371
+ let zTree = $.fn.zTree.init($('ul[name="' + this.name + '"]'), this.setting, this.nodes);
372
+ $.fn.zTreeKeyboardNavigation(zTree, $('ul[name="' + this.name + '"]'), null, this.treeicon || defaultTreeIconClass);
302
373
  }
303
- findSelectedNodeParent($li) {
304
- return $li.find('> span.title').parents('.app-tree li');
374
+ setSelectedItem(treeNode) {
375
+ this.selecteditem = getClonedObject(treeNode) || {};
376
+ this.selecteditem.path = this.getPath(treeNode, "");
377
+ const deSelectElm = $(`li[treenode].selected`);
378
+ deSelectElm.removeClass('selected');
379
+ const selectElm = $(`#${treeNode.tId}:has(.curSelectedNode)`);
380
+ selectElm.addClass('selected');
305
381
  }
306
- selectById(value) {
307
- this.selectNode(undefined, value);
382
+ expandNode(node, expand, eventFlag) {
383
+ this.treeObj.expandNode(node, expand, false, false, eventFlag);
384
+ const el = $(`#${node.tId}_switch`);
385
+ $(el).addClass(this.treeicon || defaultTreeIconClass);
308
386
  }
309
- deselectById(value) {
310
- this.selecteditem = {};
311
- this.selectById();
387
+ ngAfterViewInit() {
388
+ setTimeout(() => {
389
+ this.changeTreeIcons(this.treeicon || defaultTreeIconClass);
390
+ if (this.datavalue) {
391
+ const nodes = this.treeObj.getNodes();
392
+ let selectNode;
393
+ if (this.datavalue === 'FirstNode') {
394
+ if (nodes.length) {
395
+ selectNode = nodes[0];
396
+ }
397
+ }
398
+ if (this.datavalue === 'LastNode') {
399
+ if (nodes.length) {
400
+ selectNode = nodes[nodes.length - 1];
401
+ }
402
+ }
403
+ this.treeObj.selectNode(selectNode, false);
404
+ this.setSelectedItem(selectNode);
405
+ this.expandNode(selectNode, true, false);
406
+ }
407
+ }, 200);
312
408
  }
313
409
  }
314
- TreeDirective.initializeProps = registerProps();
315
- TreeDirective.decorators = [
316
- { type: Directive, args: [{
317
- selector: 'div[wmTree]',
410
+ TreeComponent.initializeProps = registerProps();
411
+ TreeComponent.decorators = [
412
+ { type: Component, args: [{
413
+ selector: 'ul[wmTree]',
414
+ template: "<ul #wmTree class=\"ztree\" id=\"ztree\"></ul> ",
318
415
  providers: [
319
- provideAsWidgetRef(TreeDirective)
320
- ]
416
+ provideAsWidgetRef(TreeComponent)
417
+ ],
418
+ encapsulation: ViewEncapsulation.None
321
419
  },] }
322
420
  ];
323
- TreeDirective.ctorParameters = () => [
324
- { type: Injector },
325
- { type: undefined, decorators: [{ type: Attribute, args: ['datavalue.bind',] }] },
326
- { type: undefined, decorators: [{ type: Attribute, args: ['nodelabel.bind',] }] },
327
- { type: undefined, decorators: [{ type: Attribute, args: ['nodeicon.bind',] }] },
328
- { type: undefined, decorators: [{ type: Attribute, args: ['nodechildren.bind',] }] },
329
- { type: undefined, decorators: [{ type: Attribute, args: ['nodeid.bind',] }] }
421
+ TreeComponent.ctorParameters = () => [
422
+ { type: Injector }
330
423
  ];
331
424
 
332
425
  const components = [
333
- TreeDirective
426
+ TreeComponent
334
427
  ];
335
428
  class TreeModule {
336
429
  }
@@ -350,5 +443,5 @@ TreeModule.decorators = [
350
443
  * Generated bundle index. Do not edit.
351
444
  */
352
445
 
353
- export { TreeDirective, TreeModule, registerProps as ɵa };
446
+ export { TreeComponent, TreeModule, registerProps as ɵa };
354
447
  //# sourceMappingURL=index.js.map