@stratusjs/angular 0.5.0 → 0.5.2
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/dist/angular.bundle.js +30609 -2673
- package/dist/angular.bundle.min.js +1 -1
- package/package.json +5 -4
- package/src/angular.modules.js +18 -33
- package/src/angular.modules.js.map +1 -1
- package/src/app.module.js +181 -227
- package/src/app.module.js.map +1 -1
- package/src/app.module.min.js +1 -1
- package/src/app.module.ts +17 -17
- package/src/backend.service.js +66 -87
- package/src/backend.service.js.map +1 -1
- package/src/base/base.component.js +101 -124
- package/src/base/base.component.js.map +1 -1
- package/src/boot.js +42 -55
- package/src/boot.js.map +1 -1
- package/src/confirm-dialog/confirm-dialog.component.js +41 -60
- package/src/confirm-dialog/confirm-dialog.component.js.map +1 -1
- package/src/core/base.interface.js +1 -9
- package/src/core/base.interface.js.map +1 -1
- package/src/core/dialog.interface.js.map +1 -0
- package/src/core/refresh.interface.js +1 -9
- package/src/core/refresh.interface.js.map +1 -1
- package/src/core/responsive.component.js +40 -58
- package/src/core/responsive.component.js.map +1 -1
- package/src/core/responsive.interface.js +1 -9
- package/src/core/responsive.interface.js.map +1 -1
- package/src/core/root.component.js +24 -43
- package/src/core/root.component.js.map +1 -1
- package/src/core/trigger.interface.js +1 -9
- package/src/core/trigger.interface.js.map +1 -1
- package/src/data/contact-meta.interface.js +1 -9
- package/src/data/contact-meta.interface.js.map +1 -1
- package/src/data/content.interface.js +1 -9
- package/src/data/content.interface.js.map +1 -1
- package/src/data/convoy.interface.js +1 -9
- package/src/data/convoy.interface.js.map +1 -1
- package/src/editor/citation-dialog.component.js +174 -207
- package/src/editor/citation-dialog.component.js.map +1 -1
- package/src/editor/code-mirror-bridge.js +63 -0
- package/src/editor/code-mirror-bridge.js.map +1 -0
- package/src/editor/code-mirror-bridge.min.js +1 -0
- package/src/editor/code-mirror-bridge.ts +85 -0
- package/src/editor/code-view-dialog.component.js +87 -116
- package/src/editor/code-view-dialog.component.js.map +1 -1
- package/src/editor/editor.component.js +903 -925
- package/src/editor/editor.component.js.map +1 -1
- package/src/editor/editor.component.min.js +1 -1
- package/src/editor/editor.component.ts +60 -21
- package/src/editor/link-dialog.component.js +356 -395
- package/src/editor/link-dialog.component.js.map +1 -1
- package/src/editor/media-dialog.component.js +270 -303
- package/src/editor/media-dialog.component.js.map +1 -1
- package/src/froala/plugins/citationManager.js +170 -191
- package/src/froala/plugins/citationManager.js.map +1 -1
- package/src/froala/plugins/inputButton.js +122 -138
- package/src/froala/plugins/inputButton.js.map +1 -1
- package/src/froala/plugins/linkManager.js +89 -104
- package/src/froala/plugins/linkManager.js.map +1 -1
- package/src/froala/plugins/mediaManager.js +72 -87
- package/src/froala/plugins/mediaManager.js.map +1 -1
- package/src/froala/plugins/menuButton.js +71 -86
- package/src/froala/plugins/menuButton.js.map +1 -1
- package/src/main.js +13 -33
- package/src/main.js.map +1 -1
- package/src/material.js +99 -194
- package/src/material.js.map +1 -1
- package/src/media-selector/media-selector.component.js +406 -441
- package/src/media-selector/media-selector.component.js.map +1 -1
- package/src/polyfills.js +3 -16
- package/src/polyfills.js.map +1 -1
- package/src/quill-plugins/quill-break-blot.plugin.js +19 -35
- package/src/quill-plugins/quill-break-blot.plugin.js.map +1 -1
- package/src/quill-plugins/quill-html-edit.plugin.js +140 -153
- package/src/quill-plugins/quill-html-edit.plugin.js.map +1 -1
- package/src/quill-plugins/quill-image-format.plugin.js +33 -47
- package/src/quill-plugins/quill-image-format.plugin.js.map +1 -1
- package/src/quill-plugins/quill-input-button.plugin.js +77 -95
- package/src/quill-plugins/quill-input-button.plugin.js.map +1 -1
- package/src/selector/selector.component.js +241 -276
- package/src/selector/selector.component.js.map +1 -1
- package/src/test/test.directive.js +49 -66
- package/src/test/test.directive.js.map +1 -1
- package/src/tree/tree-dialog.component.js +202 -231
- package/src/tree/tree-dialog.component.js.map +1 -1
- package/src/tree/tree-node.component.js +253 -279
- package/src/tree/tree-node.component.js.map +1 -1
- package/src/tree/tree-node.component.min.js +1 -1
- package/src/tree/tree-node.component.ts +10 -18
- package/src/tree/tree.component.js +531 -568
- package/src/tree/tree.component.js.map +1 -1
- package/src/tree/tree.component.min.js +1 -1
- package/src/tree/tree.component.ts +7 -10
|
@@ -1,589 +1,552 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
import { ChangeDetectorRef, Component, ElementRef, Input, Inject, } from '@angular/core';
|
|
23
|
+
import { moveItemInArray, } from '@angular/cdk/drag-drop';
|
|
24
|
+
import { NestedTreeControl } from '@angular/cdk/tree';
|
|
25
|
+
import { DomSanitizer } from '@angular/platform-browser';
|
|
26
|
+
import { MatIconRegistry } from '@angular/material/icon';
|
|
27
|
+
import { Observable, Subject } from 'rxjs';
|
|
28
|
+
import { Stratus } from '@stratusjs/runtime/stratus';
|
|
29
|
+
import _ from 'lodash';
|
|
30
|
+
import { debounce } from '@agentepsilon/decko';
|
|
31
|
+
import { RootComponent } from '../core/root.component';
|
|
32
|
+
import { BackendService } from '../backend.service';
|
|
33
|
+
import { Registry } from '@stratusjs/angularjs/services/registry';
|
|
34
|
+
import { cookie } from '@stratusjs/core/environment';
|
|
35
|
+
import { EventManager } from '@stratusjs/core/events/eventManager';
|
|
36
|
+
import { DOCUMENT } from '@angular/common';
|
|
37
|
+
const systemDir = '@stratusjs/angular';
|
|
38
|
+
const moduleName = 'tree';
|
|
39
|
+
const min = !cookie('env') ? '.min' : '';
|
|
40
|
+
const localDir = `${Stratus.BaseUrl}${boot.configuration.paths[`${systemDir}/*`].replace(/[^/]*$/, '').replace(/\/dist\/$/, '/src/')}`;
|
|
41
|
+
let TreeComponent = class TreeComponent extends RootComponent {
|
|
42
|
+
constructor(iconRegistry, sanitizer, backend, ref, elementRef, document) {
|
|
43
|
+
super();
|
|
44
|
+
this.iconRegistry = iconRegistry;
|
|
45
|
+
this.sanitizer = sanitizer;
|
|
46
|
+
this.backend = backend;
|
|
47
|
+
this.ref = ref;
|
|
48
|
+
this.elementRef = elementRef;
|
|
49
|
+
this.document = document;
|
|
50
|
+
this.title = moduleName + '_component';
|
|
51
|
+
this.isInitialized = false;
|
|
52
|
+
this.isDestroyed = false;
|
|
53
|
+
this.isStyled = false;
|
|
54
|
+
this._ = _;
|
|
55
|
+
this.Stratus = Stratus;
|
|
56
|
+
this.registry = new Registry();
|
|
57
|
+
this.onChange = new Subject();
|
|
58
|
+
this.unsettled = false;
|
|
59
|
+
this.svgIcons = {};
|
|
60
|
+
this.dblClickWait = 500;
|
|
61
|
+
this.dropLists = [];
|
|
62
|
+
this.dropListIdMap = {};
|
|
63
|
+
this.dropListMap = {};
|
|
64
|
+
this.expandedNodeSet = new Set();
|
|
65
|
+
this.dragging = false;
|
|
66
|
+
this.expandDelay = 1000;
|
|
67
|
+
this.dropData = null;
|
|
68
|
+
this.cdkDropListSortingDisabled = true;
|
|
69
|
+
this.dropDebug = false;
|
|
70
|
+
this.treeControl = new NestedTreeControl((node) => node.children || []);
|
|
71
|
+
}
|
|
72
|
+
ngOnInit() {
|
|
73
|
+
this.uid = _.uniqueId(`sa_${_.snakeCase(moduleName)}_component_`);
|
|
74
|
+
Stratus.Instances[this.uid] = this;
|
|
75
|
+
this.hydrate(this.elementRef, this.sanitizer, ["title", "uid", "isInitialized", "isDestroyed", "isStyled", "target", "targetSuffix", "id", "manifest", "decouple", "direct", "api", "urlRoot", "type", "property", "_", "Stratus", "registry", "fetched", "data", "collection", "model", "dataSub", "onChange", "subscriber", "unsettled", "svgIcons", "isSingleClick", "dblClickWait", "dropLists", "dropListIdMap", "dropListMap", "expandedNodeSet", "dragging", "expandTimeout", "expandDelay", "dropData", "cdkDropListSortingDisabled", "dropDebug", "tree", "treeMap", "metaMap", "dataSource", "treeControl", "iconRegistry", "sanitizer", "backend", "ref", "elementRef", "document", "ngOnInit", "ngOnDestroy", "refresh", "remove", "removeNode", "nodeIsEqual", "fetchData", "dataDefer", "dataRef", "trackDropLists", "setExpanded", "setExpandedClick", "setExpandedDblClick", "onDragDrop", "onDragMove", "showDragData", "clearDragData", "buildNodePatch", "getSvg", "addSvgIcon", "hydrate", "disableRefresh", "stagger", "reloading"]);
|
|
76
|
+
Stratus.Internals.CssLoader(`${localDir}/${moduleName}/${moduleName}.component${min}.css`)
|
|
77
|
+
.then(() => {
|
|
78
|
+
this.isStyled = true;
|
|
79
|
+
this.refresh();
|
|
80
|
+
})
|
|
81
|
+
.catch((err) => {
|
|
82
|
+
console.warn('Issue detected in CSS Loader for Component:', this);
|
|
83
|
+
console.error(err);
|
|
84
|
+
this.isStyled = true;
|
|
85
|
+
this.refresh();
|
|
86
|
+
});
|
|
87
|
+
_.forEach({
|
|
88
|
+
tree_check: `${Stratus.BaseUrl}sitetheorycore/images/icons/check.svg`,
|
|
89
|
+
tree_add: `${Stratus.BaseUrl}sitetheorycore/images/icons/actionButtons/add.svg`,
|
|
90
|
+
tree_delete: `${Stratus.BaseUrl}sitetheorycore/images/icons/actionButtons/delete.svg`,
|
|
91
|
+
tree_edit: `${Stratus.BaseUrl}sitetheorycore/images/icons/actionButtons/edit.svg`,
|
|
92
|
+
tree_visibility: `${Stratus.BaseUrl}sitetheorycore/images/icons/actionButtons/visibility.svg`,
|
|
93
|
+
}, (value, key) => this.iconRegistry.addSvgIcon(key, this.sanitizer.bypassSecurityTrustResourceUrl(value)).getNamedSvgIcon(key));
|
|
94
|
+
this.fetchData()
|
|
95
|
+
.then(data => {
|
|
96
|
+
if (!data || !(data instanceof EventManager)) {
|
|
97
|
+
console.warn('Unable to bind data from Registry!');
|
|
98
|
+
return;
|
|
70
99
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
moduleName = 'tree';
|
|
75
|
-
min = !environment_1.cookie('env') ? '.min' : '';
|
|
76
|
-
localDir = `${stratus_1.Stratus.BaseUrl}${boot.configuration.paths[`${systemDir}/*`].replace(/[^/]*$/, '').replace(/\/dist\/$/, '/src/')}`;
|
|
77
|
-
TreeComponent = class TreeComponent extends root_component_1.RootComponent {
|
|
78
|
-
constructor(iconRegistry, sanitizer, backend, ref, elementRef, document) {
|
|
79
|
-
super();
|
|
80
|
-
this.iconRegistry = iconRegistry;
|
|
81
|
-
this.sanitizer = sanitizer;
|
|
82
|
-
this.backend = backend;
|
|
83
|
-
this.ref = ref;
|
|
84
|
-
this.elementRef = elementRef;
|
|
85
|
-
this.document = document;
|
|
86
|
-
this.title = moduleName + '_component';
|
|
87
|
-
this.isInitialized = false;
|
|
88
|
-
this.isDestroyed = false;
|
|
89
|
-
this.isStyled = false;
|
|
90
|
-
this._ = lodash_1.default;
|
|
91
|
-
this.Stratus = stratus_1.Stratus;
|
|
92
|
-
this.registry = new registry_1.Registry();
|
|
93
|
-
this.onChange = new rxjs_1.Subject();
|
|
94
|
-
this.unsettled = false;
|
|
95
|
-
this.svgIcons = {};
|
|
96
|
-
this.dblClickWait = 500;
|
|
97
|
-
this.dropLists = [];
|
|
98
|
-
this.dropListIdMap = {};
|
|
99
|
-
this.dropListMap = {};
|
|
100
|
-
this.expandedNodeSet = new Set();
|
|
101
|
-
this.dragging = false;
|
|
102
|
-
this.expandDelay = 1000;
|
|
103
|
-
this.dropData = null;
|
|
104
|
-
this.cdkDropListSortingDisabled = true;
|
|
105
|
-
this.dropDebug = false;
|
|
106
|
-
this.treeControl = new tree_1.NestedTreeControl((node) => node.children || []);
|
|
100
|
+
const onDataChange = () => {
|
|
101
|
+
if (this.unsettled || !data.completed) {
|
|
102
|
+
return;
|
|
107
103
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
.catch((err) => {
|
|
118
|
-
console.warn('Issue detected in CSS Loader for Component:', this);
|
|
119
|
-
console.error(err);
|
|
120
|
-
this.isStyled = true;
|
|
121
|
-
this.refresh();
|
|
122
|
-
});
|
|
123
|
-
lodash_1.default.forEach({
|
|
124
|
-
tree_check: `${stratus_1.Stratus.BaseUrl}sitetheorycore/images/icons/check.svg`,
|
|
125
|
-
tree_add: `${stratus_1.Stratus.BaseUrl}sitetheorycore/images/icons/actionButtons/add.svg`,
|
|
126
|
-
tree_delete: `${stratus_1.Stratus.BaseUrl}sitetheorycore/images/icons/actionButtons/delete.svg`,
|
|
127
|
-
tree_edit: `${stratus_1.Stratus.BaseUrl}sitetheorycore/images/icons/actionButtons/edit.svg`,
|
|
128
|
-
tree_visibility: `${stratus_1.Stratus.BaseUrl}sitetheorycore/images/icons/actionButtons/visibility.svg`,
|
|
129
|
-
}, (value, key) => this.iconRegistry.addSvgIcon(key, this.sanitizer.bypassSecurityTrustResourceUrl(value)).getNamedSvgIcon(key));
|
|
130
|
-
this.fetchData()
|
|
131
|
-
.then(data => {
|
|
132
|
-
if (!data || !(data instanceof eventManager_1.EventManager)) {
|
|
133
|
-
console.warn('Unable to bind data from Registry!');
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
const onDataChange = () => {
|
|
137
|
-
if (this.unsettled || !data.completed) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
this.dataDefer(this.subscriber);
|
|
141
|
-
this.refresh();
|
|
142
|
-
};
|
|
143
|
-
data.on('change', onDataChange);
|
|
144
|
-
onDataChange();
|
|
145
|
-
data.on('add', (event, model) => {
|
|
146
|
-
let modelCompleted = false;
|
|
147
|
-
const onModelChange = () => {
|
|
148
|
-
if (!model.completed) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
if (modelCompleted) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
modelCompleted = true;
|
|
155
|
-
if (!(model.getIdentifier() in this.treeMap)) {
|
|
156
|
-
model.meta.set('postPersist', true);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
const node = this.treeMap[model.getIdentifier()];
|
|
160
|
-
if (!node.meta.component || !(node.meta.component instanceof tree_node_component_1.TreeNodeComponent)) {
|
|
161
|
-
model.meta.set('postPersist', true);
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
node.meta.component.openDialog();
|
|
165
|
-
};
|
|
166
|
-
model.on('change', onModelChange);
|
|
167
|
-
onModelChange();
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
this.dataSub = new rxjs_1.Observable((subscriber) => this.dataDefer(subscriber));
|
|
171
|
-
this.dropListIdMap[`${this.uid}_parent_drop_list`] = true;
|
|
172
|
-
this.trackDropLists();
|
|
173
|
-
this.isInitialized = true;
|
|
174
|
-
this.refresh();
|
|
175
|
-
}
|
|
176
|
-
ngOnDestroy() {
|
|
177
|
-
this.isDestroyed = true;
|
|
178
|
-
}
|
|
179
|
-
refresh() {
|
|
180
|
-
if (this.isDestroyed) {
|
|
181
|
-
return new Promise(resolve => resolve());
|
|
182
|
-
}
|
|
183
|
-
lodash_1.default.forEach(this.metaMap, (meta) => {
|
|
184
|
-
if (!meta.component || !('refresh' in meta.component)) {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
meta.component.refresh();
|
|
188
|
-
});
|
|
189
|
-
return super.refresh();
|
|
190
|
-
}
|
|
191
|
-
remove(model) {
|
|
192
|
-
}
|
|
193
|
-
removeNode(list, node) {
|
|
194
|
-
const index = list.indexOf(node);
|
|
195
|
-
if (index === -1) {
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
list.splice(index, 1);
|
|
199
|
-
return true;
|
|
200
|
-
}
|
|
201
|
-
nodeIsEqual(node, other) {
|
|
202
|
-
if (!node || !other) {
|
|
203
|
-
return node === other;
|
|
204
|
-
}
|
|
205
|
-
return node.id === other.id;
|
|
206
|
-
}
|
|
207
|
-
async fetchData() {
|
|
208
|
-
if (this.fetched) {
|
|
209
|
-
return this.fetched;
|
|
210
|
-
}
|
|
211
|
-
return this.fetched = this.registry.fetch(stratus_1.Stratus.Select(this.elementRef.nativeElement), this);
|
|
212
|
-
}
|
|
213
|
-
dataDefer(subscriber) {
|
|
214
|
-
this.subscriber = this.subscriber || subscriber;
|
|
215
|
-
if (!this.subscriber || !this.collection || !this.collection.completed) {
|
|
216
|
-
setTimeout(() => {
|
|
217
|
-
this.dataDefer(subscriber);
|
|
218
|
-
}, 500);
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
const tree = this.dataRef(true);
|
|
222
|
-
if (tree && tree.length) {
|
|
223
|
-
subscriber.next(tree);
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
setTimeout(() => this.dataDefer(subscriber), 200);
|
|
227
|
-
}
|
|
228
|
-
dataRef(force = false) {
|
|
229
|
-
if (!this.collection) {
|
|
230
|
-
return [];
|
|
231
|
-
}
|
|
232
|
-
if (!force && this.tree && this.tree.length > 0) {
|
|
233
|
-
return this.tree;
|
|
234
|
-
}
|
|
235
|
-
let models = this.collection.models;
|
|
236
|
-
if (!models || !lodash_1.default.isArray(models) || !models.length) {
|
|
237
|
-
return [];
|
|
238
|
-
}
|
|
239
|
-
models = lodash_1.default.sortBy(models, ['data.priority']);
|
|
240
|
-
this.metaMap = this.metaMap || {};
|
|
241
|
-
this.treeMap = {};
|
|
242
|
-
this.tree = [];
|
|
243
|
-
lodash_1.default.forEach(models, (model) => {
|
|
244
|
-
const modelId = lodash_1.default.get(model, 'data.id');
|
|
245
|
-
const parentId = lodash_1.default.get(model, 'data.nestParent.id');
|
|
246
|
-
this.dropListIdMap[`${this.uid}_node_${modelId}_drop_list`] = true;
|
|
247
|
-
if (!lodash_1.default.has(this.metaMap, modelId)) {
|
|
248
|
-
this.metaMap[modelId] = {
|
|
249
|
-
id: modelId,
|
|
250
|
-
expanded: true
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
if (!lodash_1.default.has(this.treeMap, modelId)) {
|
|
254
|
-
this.treeMap[modelId] = {
|
|
255
|
-
id: modelId,
|
|
256
|
-
model,
|
|
257
|
-
children: [],
|
|
258
|
-
meta: this.metaMap[modelId]
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
this.treeMap[modelId].model = model;
|
|
262
|
-
this.treeMap[modelId].meta = this.metaMap[modelId];
|
|
263
|
-
if (parentId) {
|
|
264
|
-
if (!lodash_1.default.has(this.treeMap, parentId)) {
|
|
265
|
-
this.treeMap[parentId] = {
|
|
266
|
-
id: parentId,
|
|
267
|
-
model: null,
|
|
268
|
-
children: [],
|
|
269
|
-
meta: null
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
this.treeMap[parentId].children.push(this.treeMap[modelId]);
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
this.tree.push(this.treeMap[modelId]);
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
this.trackDropLists();
|
|
279
|
-
return this.tree;
|
|
280
|
-
}
|
|
281
|
-
trackDropLists() {
|
|
282
|
-
this.dropLists = [];
|
|
283
|
-
lodash_1.default.forEach(this.dropListIdMap, (value, key) => {
|
|
284
|
-
if (!value) {
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
const cached = key in this.dropListMap;
|
|
288
|
-
const element = cached ? this.dropListMap[key] : document.getElementById(key);
|
|
289
|
-
if (!element) {
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
this.dropLists.push(key);
|
|
293
|
-
if (cached) {
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
this.dropListMap[key] = element;
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
setExpanded(expanded) {
|
|
300
|
-
if (!this.metaMap || !lodash_1.default.size(this.metaMap)) {
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
lodash_1.default.forEach(this.metaMap, (nodeMeta) => {
|
|
304
|
-
nodeMeta.expanded = expanded;
|
|
305
|
-
});
|
|
306
|
-
this.refresh();
|
|
307
|
-
}
|
|
308
|
-
setExpandedClick(expanded) {
|
|
309
|
-
this.isSingleClick = true;
|
|
310
|
-
setTimeout(() => {
|
|
311
|
-
if (!this.isSingleClick) {
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
this.setExpanded(expanded);
|
|
315
|
-
}, this.dblClickWait);
|
|
316
|
-
}
|
|
317
|
-
setExpandedDblClick(expanded) {
|
|
318
|
-
this.isSingleClick = false;
|
|
319
|
-
this.setExpanded(expanded);
|
|
320
|
-
}
|
|
321
|
-
onDragDrop(event) {
|
|
322
|
-
if (!event.isPointerOverContainer) {
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
const targetNode = event.item.data;
|
|
326
|
-
if (!targetNode) {
|
|
104
|
+
this.dataDefer(this.subscriber);
|
|
105
|
+
this.refresh();
|
|
106
|
+
};
|
|
107
|
+
data.on('change', onDataChange);
|
|
108
|
+
onDataChange();
|
|
109
|
+
data.on('add', (event, model) => {
|
|
110
|
+
let modelCompleted = false;
|
|
111
|
+
const onModelChange = () => {
|
|
112
|
+
if (!model.completed) {
|
|
327
113
|
return;
|
|
328
114
|
}
|
|
329
|
-
|
|
330
|
-
const pastParentNode = event.previousContainer.data;
|
|
331
|
-
const tree = parentNode ? parentNode.children : this.dataRef();
|
|
332
|
-
if (!tree) {
|
|
115
|
+
if (modelCompleted) {
|
|
333
116
|
return;
|
|
334
117
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
if (environment_1.cookie('env') && this.dropDebug) {
|
|
339
|
-
console.group('onDragDrop()');
|
|
340
|
-
lodash_1.default.forEach([
|
|
341
|
-
`model drop: ${targetNode.model.get('name')}`,
|
|
342
|
-
`list shift: ${event.container.element.nativeElement.id} -> ${event.previousContainer.element.nativeElement.id}`,
|
|
343
|
-
`index change (event): ${event.previousIndex} -> ${event.currentIndex}`,
|
|
344
|
-
`current priority: ${targetNode.model.get('priority')}`,
|
|
345
|
-
`target drop action: ${this.dropData.action}`,
|
|
346
|
-
], (message) => console.log(message));
|
|
347
|
-
}
|
|
348
|
-
if (targetDropNode && !this.nodeIsEqual(parentNode, targetDropNode)) {
|
|
349
|
-
if (environment_1.cookie('env') && this.dropDebug) {
|
|
350
|
-
console.log(`target drop node differs: ${targetDropNode.id} -> ${targetDropNode.model.get('name')}`);
|
|
351
|
-
console.log('target drop node is the same as target node:', targetNode.id === targetDropNode.id);
|
|
352
|
-
}
|
|
353
|
-
if (targetNode.id !== targetDropNode.id) {
|
|
354
|
-
switch (this.dropData.action) {
|
|
355
|
-
case 'before':
|
|
356
|
-
case 'after':
|
|
357
|
-
const nestParentId = targetDropNode.model.get('nestParent.id');
|
|
358
|
-
const nestParent = (nestParentId && nestParentId in this.treeMap) ? this.treeMap[nestParentId] : null;
|
|
359
|
-
parentNode = nestParent;
|
|
360
|
-
break;
|
|
361
|
-
case 'inside':
|
|
362
|
-
parentNode = targetDropNode;
|
|
363
|
-
break;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
if (environment_1.cookie('env') && this.dropDebug) {
|
|
367
|
-
console.log('target drop node selected:', parentNode ? `${parentNode.id} -> ${parentNode.model.get('name')}` : 'none');
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
if (!this.nodeIsEqual(parentNode, pastParentNode)) {
|
|
371
|
-
if (parentNode) {
|
|
372
|
-
switch (this.dropData.action) {
|
|
373
|
-
case 'before':
|
|
374
|
-
case 'after':
|
|
375
|
-
let targetIndex = parentNode.children.findIndex((n) => n.id === targetNode.id);
|
|
376
|
-
if (this.dropData.action === 'after') {
|
|
377
|
-
targetIndex++;
|
|
378
|
-
}
|
|
379
|
-
parentNode.children.splice(targetIndex, 0, targetNode);
|
|
380
|
-
break;
|
|
381
|
-
case 'inside':
|
|
382
|
-
parentNode.children.push(targetNode);
|
|
383
|
-
break;
|
|
384
|
-
}
|
|
385
|
-
parentNode.meta.expanded = true;
|
|
386
|
-
}
|
|
387
|
-
if (pastParentNode) {
|
|
388
|
-
this.removeNode(pastParentNode.children, targetNode);
|
|
389
|
-
}
|
|
390
|
-
targetNode.model.set('nestParent', this.buildNodePatch(parentNode));
|
|
391
|
-
if (environment_1.cookie('env') && this.dropDebug) {
|
|
392
|
-
console.log(`new parent: ${targetNode.model.get('nestParent.name') || null}`);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
const branch = parentNode ? parentNode.children : tree;
|
|
396
|
-
let targetDropIndex = event.currentIndex;
|
|
397
|
-
if (this.cdkDropListSortingDisabled) {
|
|
398
|
-
targetDropIndex = null;
|
|
399
|
-
switch (this.dropData.action) {
|
|
400
|
-
case 'before':
|
|
401
|
-
case 'after':
|
|
402
|
-
targetDropIndex = branch.findIndex((n) => n.id === targetDropNode.id);
|
|
403
|
-
if (this.dropData.action === 'after') {
|
|
404
|
-
targetDropIndex++;
|
|
405
|
-
}
|
|
406
|
-
if (environment_1.cookie('env') && this.dropDebug) {
|
|
407
|
-
console.log('index change (drop node):', `${event.previousIndex} -> ${targetDropIndex}`);
|
|
408
|
-
}
|
|
409
|
-
break;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
if (lodash_1.default.isNumber(targetDropIndex)) {
|
|
413
|
-
drag_drop_1.moveItemInArray(branch, event.previousIndex, targetDropIndex);
|
|
414
|
-
let priority = 0;
|
|
415
|
-
lodash_1.default.forEach(branch, (node) => {
|
|
416
|
-
if (!node.model || !node.model.set) {
|
|
417
|
-
return;
|
|
418
|
-
}
|
|
419
|
-
node.model.set('priority', priority++);
|
|
420
|
-
});
|
|
421
|
-
if (environment_1.cookie('env') && this.dropDebug) {
|
|
422
|
-
console.log('new priority:', targetNode.model.get('priority'));
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
if (environment_1.cookie('env') && this.dropDebug) {
|
|
426
|
-
console.log(`new parent: ${targetNode.model.get('nestParent.name') || null}`);
|
|
427
|
-
console.groupEnd();
|
|
428
|
-
}
|
|
429
|
-
targetNode.model.save();
|
|
430
|
-
this.unsettled = false;
|
|
431
|
-
}
|
|
432
|
-
onDragMove(event) {
|
|
433
|
-
const e = this.document.elementFromPoint(event.pointerPosition.x, event.pointerPosition.y);
|
|
434
|
-
if (!e) {
|
|
435
|
-
this.clearDragData();
|
|
118
|
+
modelCompleted = true;
|
|
119
|
+
if (!(model.getIdentifier() in this.treeMap)) {
|
|
120
|
+
model.meta.set('postPersist', true);
|
|
436
121
|
return;
|
|
437
122
|
}
|
|
438
|
-
const
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
this.clearDragData();
|
|
123
|
+
const node = this.treeMap[model.getIdentifier()];
|
|
124
|
+
if (!node.meta.component || !('openDialog' in node.meta.component)) {
|
|
125
|
+
model.meta.set('postPersist', true);
|
|
442
126
|
return;
|
|
443
127
|
}
|
|
444
|
-
|
|
445
|
-
|
|
128
|
+
node.meta.component.openDialog();
|
|
129
|
+
};
|
|
130
|
+
model.on('change', onModelChange);
|
|
131
|
+
onModelChange();
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
this.dataSub = new Observable((subscriber) => this.dataDefer(subscriber));
|
|
135
|
+
this.dropListIdMap[`${this.uid}_parent_drop_list`] = true;
|
|
136
|
+
this.trackDropLists();
|
|
137
|
+
this.isInitialized = true;
|
|
138
|
+
this.refresh();
|
|
139
|
+
}
|
|
140
|
+
ngOnDestroy() {
|
|
141
|
+
this.isDestroyed = true;
|
|
142
|
+
}
|
|
143
|
+
refresh() {
|
|
144
|
+
if (this.isDestroyed) {
|
|
145
|
+
return new Promise(resolve => resolve());
|
|
146
|
+
}
|
|
147
|
+
_.forEach(this.metaMap, (meta) => {
|
|
148
|
+
if (!meta.component || !('refresh' in meta.component)) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
meta.component.refresh();
|
|
152
|
+
});
|
|
153
|
+
return super.refresh();
|
|
154
|
+
}
|
|
155
|
+
remove(model) {
|
|
156
|
+
}
|
|
157
|
+
removeNode(list, node) {
|
|
158
|
+
const index = list.indexOf(node);
|
|
159
|
+
if (index === -1) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
list.splice(index, 1);
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
nodeIsEqual(node, other) {
|
|
166
|
+
if (!node || !other) {
|
|
167
|
+
return node === other;
|
|
168
|
+
}
|
|
169
|
+
return node.id === other.id;
|
|
170
|
+
}
|
|
171
|
+
fetchData() {
|
|
172
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
if (this.fetched) {
|
|
174
|
+
return this.fetched;
|
|
175
|
+
}
|
|
176
|
+
return this.fetched = this.registry.fetch(Stratus.Select(this.elementRef.nativeElement), this);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
dataDefer(subscriber) {
|
|
180
|
+
this.subscriber = this.subscriber || subscriber;
|
|
181
|
+
if (!this.subscriber || !this.collection || !this.collection.completed) {
|
|
182
|
+
setTimeout(() => {
|
|
183
|
+
this.dataDefer(subscriber);
|
|
184
|
+
}, 500);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const tree = this.dataRef(true);
|
|
188
|
+
if (tree && tree.length) {
|
|
189
|
+
subscriber.next(tree);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
setTimeout(() => this.dataDefer(subscriber), 200);
|
|
193
|
+
}
|
|
194
|
+
dataRef(force = false) {
|
|
195
|
+
if (!this.collection) {
|
|
196
|
+
return [];
|
|
197
|
+
}
|
|
198
|
+
if (!force && this.tree && this.tree.length > 0) {
|
|
199
|
+
return this.tree;
|
|
200
|
+
}
|
|
201
|
+
let models = this.collection.models;
|
|
202
|
+
if (!models || !_.isArray(models) || !models.length) {
|
|
203
|
+
return [];
|
|
204
|
+
}
|
|
205
|
+
models = _.sortBy(models, ['data.priority']);
|
|
206
|
+
this.metaMap = this.metaMap || {};
|
|
207
|
+
this.treeMap = {};
|
|
208
|
+
this.tree = [];
|
|
209
|
+
_.forEach(models, (model) => {
|
|
210
|
+
const modelId = _.get(model, 'data.id');
|
|
211
|
+
const parentId = _.get(model, 'data.nestParent.id');
|
|
212
|
+
this.dropListIdMap[`${this.uid}_node_${modelId}_drop_list`] = true;
|
|
213
|
+
if (!_.has(this.metaMap, modelId)) {
|
|
214
|
+
this.metaMap[modelId] = {
|
|
215
|
+
id: modelId,
|
|
216
|
+
expanded: true
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
if (!_.has(this.treeMap, modelId)) {
|
|
220
|
+
this.treeMap[modelId] = {
|
|
221
|
+
id: modelId,
|
|
222
|
+
model,
|
|
223
|
+
children: [],
|
|
224
|
+
meta: this.metaMap[modelId]
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
this.treeMap[modelId].model = model;
|
|
228
|
+
this.treeMap[modelId].meta = this.metaMap[modelId];
|
|
229
|
+
if (parentId) {
|
|
230
|
+
if (!_.has(this.treeMap, parentId)) {
|
|
231
|
+
this.treeMap[parentId] = {
|
|
232
|
+
id: parentId,
|
|
233
|
+
model: null,
|
|
234
|
+
children: [],
|
|
235
|
+
meta: null
|
|
446
236
|
};
|
|
447
|
-
const targetRect = container.getBoundingClientRect();
|
|
448
|
-
const oneThird = targetRect.height / 3;
|
|
449
|
-
if (event.pointerPosition.y - targetRect.top < oneThird) {
|
|
450
|
-
this.dropData.action = 'before';
|
|
451
|
-
}
|
|
452
|
-
else if (event.pointerPosition.y - targetRect.top > 2 * oneThird) {
|
|
453
|
-
this.dropData.action = 'after';
|
|
454
|
-
}
|
|
455
|
-
else {
|
|
456
|
-
this.dropData.action = 'inside';
|
|
457
|
-
}
|
|
458
|
-
this.showDragData();
|
|
459
|
-
}
|
|
460
|
-
showDragData() {
|
|
461
|
-
this.clearDragData();
|
|
462
|
-
if (!this.dropData) {
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
465
|
-
this.document.getElementById(`node-${this.dropData.targetId}`).classList.add(`drop-${this.dropData.action}`);
|
|
466
237
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
238
|
+
this.treeMap[parentId].children.push(this.treeMap[modelId]);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
this.tree.push(this.treeMap[modelId]);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
this.trackDropLists();
|
|
245
|
+
return this.tree;
|
|
246
|
+
}
|
|
247
|
+
trackDropLists() {
|
|
248
|
+
this.dropLists = [];
|
|
249
|
+
_.forEach(this.dropListIdMap, (value, key) => {
|
|
250
|
+
if (!value) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
const cached = key in this.dropListMap;
|
|
254
|
+
const element = cached ? this.dropListMap[key] : document.getElementById(key);
|
|
255
|
+
if (!element) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
this.dropLists.push(key);
|
|
259
|
+
if (cached) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
this.dropListMap[key] = element;
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
setExpanded(expanded) {
|
|
266
|
+
if (!this.metaMap || !_.size(this.metaMap)) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
_.forEach(this.metaMap, (nodeMeta) => {
|
|
270
|
+
nodeMeta.expanded = expanded;
|
|
271
|
+
});
|
|
272
|
+
this.refresh();
|
|
273
|
+
}
|
|
274
|
+
setExpandedClick(expanded) {
|
|
275
|
+
this.isSingleClick = true;
|
|
276
|
+
setTimeout(() => {
|
|
277
|
+
if (!this.isSingleClick) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
this.setExpanded(expanded);
|
|
281
|
+
}, this.dblClickWait);
|
|
282
|
+
}
|
|
283
|
+
setExpandedDblClick(expanded) {
|
|
284
|
+
this.isSingleClick = false;
|
|
285
|
+
this.setExpanded(expanded);
|
|
286
|
+
}
|
|
287
|
+
onDragDrop(event) {
|
|
288
|
+
if (!event.isPointerOverContainer) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
const targetNode = event.item.data;
|
|
292
|
+
if (!targetNode) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
let parentNode = event.container.data;
|
|
296
|
+
const pastParentNode = event.previousContainer.data;
|
|
297
|
+
const tree = parentNode ? parentNode.children : this.dataRef();
|
|
298
|
+
if (!tree) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
this.unsettled = true;
|
|
302
|
+
const targetDropNode = (this.dropData.targetId && this.dropData.targetId in this.treeMap) ?
|
|
303
|
+
this.treeMap[_.toNumber(this.dropData.targetId)] : null;
|
|
304
|
+
if (cookie('env') && this.dropDebug) {
|
|
305
|
+
console.group('onDragDrop()');
|
|
306
|
+
_.forEach([
|
|
307
|
+
`model drop: ${targetNode.model.get('name')}`,
|
|
308
|
+
`list shift: ${event.container.element.nativeElement.id} -> ${event.previousContainer.element.nativeElement.id}`,
|
|
309
|
+
`index change (event): ${event.previousIndex} -> ${event.currentIndex}`,
|
|
310
|
+
`current priority: ${targetNode.model.get('priority')}`,
|
|
311
|
+
`target drop action: ${this.dropData.action}`,
|
|
312
|
+
], (message) => console.log(message));
|
|
313
|
+
}
|
|
314
|
+
if (targetDropNode && !this.nodeIsEqual(parentNode, targetDropNode)) {
|
|
315
|
+
if (cookie('env') && this.dropDebug) {
|
|
316
|
+
console.log(`target drop node differs: ${targetDropNode.id} -> ${targetDropNode.model.get('name')}`);
|
|
317
|
+
console.log('target drop node is the same as target node:', targetNode.id === targetDropNode.id);
|
|
318
|
+
}
|
|
319
|
+
if (targetNode.id !== targetDropNode.id) {
|
|
320
|
+
switch (this.dropData.action) {
|
|
321
|
+
case 'before':
|
|
322
|
+
case 'after':
|
|
323
|
+
const nestParentId = targetDropNode.model.get('nestParent.id');
|
|
324
|
+
const nestParent = (nestParentId && nestParentId in this.treeMap) ? this.treeMap[nestParentId] : null;
|
|
325
|
+
parentNode = nestParent;
|
|
326
|
+
break;
|
|
327
|
+
case 'inside':
|
|
328
|
+
parentNode = targetDropNode;
|
|
329
|
+
break;
|
|
480
330
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
331
|
+
}
|
|
332
|
+
if (cookie('env') && this.dropDebug) {
|
|
333
|
+
console.log('target drop node selected:', parentNode ? `${parentNode.id} -> ${parentNode.model.get('name')}` : 'none');
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (!this.nodeIsEqual(parentNode, pastParentNode)) {
|
|
337
|
+
if (parentNode) {
|
|
338
|
+
switch (this.dropData.action) {
|
|
339
|
+
case 'before':
|
|
340
|
+
case 'after':
|
|
341
|
+
let targetIndex = parentNode.children.findIndex((n) => n.id === targetNode.id);
|
|
342
|
+
if (this.dropData.action === 'after') {
|
|
343
|
+
targetIndex++;
|
|
493
344
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
const uid = this.addSvgIcon(url, options);
|
|
500
|
-
return new rxjs_1.Observable((subscriber) => {
|
|
501
|
-
this.iconRegistry
|
|
502
|
-
.getNamedSvgIcon(uid)
|
|
503
|
-
.subscribe({
|
|
504
|
-
error(err) {
|
|
505
|
-
console.error(`getSvg(${url}): ${err}`);
|
|
506
|
-
},
|
|
507
|
-
complete() {
|
|
508
|
-
subscriber.next(uid);
|
|
509
|
-
}
|
|
510
|
-
});
|
|
511
|
-
});
|
|
345
|
+
parentNode.children.splice(targetIndex, 0, targetNode);
|
|
346
|
+
break;
|
|
347
|
+
case 'inside':
|
|
348
|
+
parentNode.children.push(targetNode);
|
|
349
|
+
break;
|
|
512
350
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
351
|
+
parentNode.meta.expanded = true;
|
|
352
|
+
}
|
|
353
|
+
if (pastParentNode) {
|
|
354
|
+
this.removeNode(pastParentNode.children, targetNode);
|
|
355
|
+
}
|
|
356
|
+
targetNode.model.set('nestParent', this.buildNodePatch(parentNode));
|
|
357
|
+
if (cookie('env') && this.dropDebug) {
|
|
358
|
+
console.log(`new parent: ${targetNode.model.get('nestParent.name') || null}`);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
const branch = parentNode ? parentNode.children : tree;
|
|
362
|
+
let targetDropIndex = event.currentIndex;
|
|
363
|
+
if (this.cdkDropListSortingDisabled) {
|
|
364
|
+
targetDropIndex = null;
|
|
365
|
+
switch (this.dropData.action) {
|
|
366
|
+
case 'before':
|
|
367
|
+
case 'after':
|
|
368
|
+
targetDropIndex = branch.findIndex((n) => n.id === targetDropNode.id);
|
|
369
|
+
if (this.dropData.action === 'after') {
|
|
370
|
+
targetDropIndex++;
|
|
516
371
|
}
|
|
517
|
-
if (
|
|
518
|
-
|
|
372
|
+
if (cookie('env') && this.dropDebug) {
|
|
373
|
+
console.log('index change (drop node):', `${event.previousIndex} -> ${targetDropIndex}`);
|
|
519
374
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if (_.isNumber(targetDropIndex)) {
|
|
379
|
+
moveItemInArray(branch, event.previousIndex, targetDropIndex);
|
|
380
|
+
let priority = 0;
|
|
381
|
+
_.forEach(branch, (node) => {
|
|
382
|
+
if (!node.model || !node.model.set) {
|
|
383
|
+
return;
|
|
523
384
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
385
|
+
node.model.set('priority', priority++);
|
|
386
|
+
});
|
|
387
|
+
if (cookie('env') && this.dropDebug) {
|
|
388
|
+
console.log('new priority:', targetNode.model.get('priority'));
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
if (cookie('env') && this.dropDebug) {
|
|
392
|
+
console.log(`new parent: ${targetNode.model.get('nestParent.name') || null}`);
|
|
393
|
+
console.groupEnd();
|
|
394
|
+
}
|
|
395
|
+
targetNode.model.save();
|
|
396
|
+
this.unsettled = false;
|
|
397
|
+
}
|
|
398
|
+
onDragMove(event) {
|
|
399
|
+
const e = this.document.elementFromPoint(event.pointerPosition.x, event.pointerPosition.y);
|
|
400
|
+
if (!e) {
|
|
401
|
+
this.clearDragData();
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
const containerClass = 'tree-node-content';
|
|
405
|
+
const container = e.classList.contains(containerClass) ? e : e.closest(`.${containerClass}`);
|
|
406
|
+
if (!container) {
|
|
407
|
+
this.clearDragData();
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
this.dropData = {
|
|
411
|
+
targetId: container.getAttribute('data-id')
|
|
412
|
+
};
|
|
413
|
+
const targetRect = container.getBoundingClientRect();
|
|
414
|
+
const oneThird = targetRect.height / 3;
|
|
415
|
+
if (event.pointerPosition.y - targetRect.top < oneThird) {
|
|
416
|
+
this.dropData.action = 'before';
|
|
417
|
+
}
|
|
418
|
+
else if (event.pointerPosition.y - targetRect.top > 2 * oneThird) {
|
|
419
|
+
this.dropData.action = 'after';
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
this.dropData.action = 'inside';
|
|
423
|
+
}
|
|
424
|
+
this.showDragData();
|
|
425
|
+
}
|
|
426
|
+
showDragData() {
|
|
427
|
+
this.clearDragData();
|
|
428
|
+
if (!this.dropData) {
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
this.document.getElementById(`node-${this.dropData.targetId}`).classList.add(`drop-${this.dropData.action}`);
|
|
432
|
+
}
|
|
433
|
+
clearDragData(dropped = false) {
|
|
434
|
+
if (dropped) {
|
|
435
|
+
this.dropData = null;
|
|
436
|
+
}
|
|
437
|
+
this.document
|
|
438
|
+
.querySelectorAll('.drop-before')
|
|
439
|
+
.forEach(element => element.classList.remove('drop-before'));
|
|
440
|
+
this.document
|
|
441
|
+
.querySelectorAll('.drop-after')
|
|
442
|
+
.forEach(element => element.classList.remove('drop-after'));
|
|
443
|
+
this.document
|
|
444
|
+
.querySelectorAll('.drop-inside')
|
|
445
|
+
.forEach(element => element.classList.remove('drop-inside'));
|
|
446
|
+
}
|
|
447
|
+
buildNodePatch(node = null) {
|
|
448
|
+
if (!node || !node.model) {
|
|
449
|
+
return null;
|
|
450
|
+
}
|
|
451
|
+
const nodePatch = {};
|
|
452
|
+
_.forEach([
|
|
453
|
+
'id',
|
|
454
|
+
'name'
|
|
455
|
+
], (key) => {
|
|
456
|
+
const value = node.model.get(key);
|
|
457
|
+
if (!value) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
_.set(nodePatch, key, value);
|
|
461
|
+
});
|
|
462
|
+
return nodePatch;
|
|
463
|
+
}
|
|
464
|
+
getSvg(url, options) {
|
|
465
|
+
const uid = this.addSvgIcon(url, options);
|
|
466
|
+
return new Observable((subscriber) => {
|
|
467
|
+
this.iconRegistry
|
|
468
|
+
.getNamedSvgIcon(uid)
|
|
469
|
+
.subscribe({
|
|
470
|
+
error(err) {
|
|
471
|
+
console.error(`getSvg(${url}): ${err}`);
|
|
472
|
+
},
|
|
473
|
+
complete() {
|
|
474
|
+
subscriber.next(uid);
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
addSvgIcon(url, options) {
|
|
480
|
+
if (url in this.svgIcons) {
|
|
481
|
+
return this.svgIcons[url];
|
|
482
|
+
}
|
|
483
|
+
if (!options) {
|
|
484
|
+
options = {};
|
|
585
485
|
}
|
|
586
|
-
|
|
587
|
-
|
|
486
|
+
const uid = this.svgIcons[url] = _.uniqueId('selector_svg');
|
|
487
|
+
this.iconRegistry.addSvgIcon(uid, this.sanitizer.bypassSecurityTrustResourceUrl(url), options);
|
|
488
|
+
return uid;
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
__decorate([
|
|
492
|
+
Input(),
|
|
493
|
+
__metadata("design:type", String)
|
|
494
|
+
], TreeComponent.prototype, "target", void 0);
|
|
495
|
+
__decorate([
|
|
496
|
+
Input(),
|
|
497
|
+
__metadata("design:type", String)
|
|
498
|
+
], TreeComponent.prototype, "targetSuffix", void 0);
|
|
499
|
+
__decorate([
|
|
500
|
+
Input(),
|
|
501
|
+
__metadata("design:type", Number)
|
|
502
|
+
], TreeComponent.prototype, "id", void 0);
|
|
503
|
+
__decorate([
|
|
504
|
+
Input(),
|
|
505
|
+
__metadata("design:type", Boolean)
|
|
506
|
+
], TreeComponent.prototype, "manifest", void 0);
|
|
507
|
+
__decorate([
|
|
508
|
+
Input(),
|
|
509
|
+
__metadata("design:type", Boolean)
|
|
510
|
+
], TreeComponent.prototype, "decouple", void 0);
|
|
511
|
+
__decorate([
|
|
512
|
+
Input(),
|
|
513
|
+
__metadata("design:type", Boolean)
|
|
514
|
+
], TreeComponent.prototype, "direct", void 0);
|
|
515
|
+
__decorate([
|
|
516
|
+
Input(),
|
|
517
|
+
__metadata("design:type", Object)
|
|
518
|
+
], TreeComponent.prototype, "api", void 0);
|
|
519
|
+
__decorate([
|
|
520
|
+
Input(),
|
|
521
|
+
__metadata("design:type", String)
|
|
522
|
+
], TreeComponent.prototype, "urlRoot", void 0);
|
|
523
|
+
__decorate([
|
|
524
|
+
Input(),
|
|
525
|
+
__metadata("design:type", String)
|
|
526
|
+
], TreeComponent.prototype, "type", void 0);
|
|
527
|
+
__decorate([
|
|
528
|
+
Input(),
|
|
529
|
+
__metadata("design:type", String)
|
|
530
|
+
], TreeComponent.prototype, "property", void 0);
|
|
531
|
+
__decorate([
|
|
532
|
+
debounce(50),
|
|
533
|
+
__metadata("design:type", Function),
|
|
534
|
+
__metadata("design:paramtypes", [Object]),
|
|
535
|
+
__metadata("design:returntype", void 0)
|
|
536
|
+
], TreeComponent.prototype, "onDragMove", null);
|
|
537
|
+
TreeComponent = __decorate([
|
|
538
|
+
Component({
|
|
539
|
+
selector: `sa-${moduleName}`,
|
|
540
|
+
templateUrl: `${localDir}/${moduleName}/${moduleName}.component${min}.html`,
|
|
541
|
+
}),
|
|
542
|
+
__param(5, Inject(DOCUMENT)),
|
|
543
|
+
__metadata("design:paramtypes", [MatIconRegistry,
|
|
544
|
+
DomSanitizer,
|
|
545
|
+
BackendService,
|
|
546
|
+
ChangeDetectorRef,
|
|
547
|
+
ElementRef,
|
|
548
|
+
Document])
|
|
549
|
+
], TreeComponent);
|
|
550
|
+
export { TreeComponent };
|
|
588
551
|
|
|
589
552
|
//# sourceMappingURL=tree.component.js.map
|