@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.
Files changed (92) hide show
  1. package/dist/angular.bundle.js +30609 -2673
  2. package/dist/angular.bundle.min.js +1 -1
  3. package/package.json +5 -4
  4. package/src/angular.modules.js +18 -33
  5. package/src/angular.modules.js.map +1 -1
  6. package/src/app.module.js +181 -227
  7. package/src/app.module.js.map +1 -1
  8. package/src/app.module.min.js +1 -1
  9. package/src/app.module.ts +17 -17
  10. package/src/backend.service.js +66 -87
  11. package/src/backend.service.js.map +1 -1
  12. package/src/base/base.component.js +101 -124
  13. package/src/base/base.component.js.map +1 -1
  14. package/src/boot.js +42 -55
  15. package/src/boot.js.map +1 -1
  16. package/src/confirm-dialog/confirm-dialog.component.js +41 -60
  17. package/src/confirm-dialog/confirm-dialog.component.js.map +1 -1
  18. package/src/core/base.interface.js +1 -9
  19. package/src/core/base.interface.js.map +1 -1
  20. package/src/core/dialog.interface.js.map +1 -0
  21. package/src/core/refresh.interface.js +1 -9
  22. package/src/core/refresh.interface.js.map +1 -1
  23. package/src/core/responsive.component.js +40 -58
  24. package/src/core/responsive.component.js.map +1 -1
  25. package/src/core/responsive.interface.js +1 -9
  26. package/src/core/responsive.interface.js.map +1 -1
  27. package/src/core/root.component.js +24 -43
  28. package/src/core/root.component.js.map +1 -1
  29. package/src/core/trigger.interface.js +1 -9
  30. package/src/core/trigger.interface.js.map +1 -1
  31. package/src/data/contact-meta.interface.js +1 -9
  32. package/src/data/contact-meta.interface.js.map +1 -1
  33. package/src/data/content.interface.js +1 -9
  34. package/src/data/content.interface.js.map +1 -1
  35. package/src/data/convoy.interface.js +1 -9
  36. package/src/data/convoy.interface.js.map +1 -1
  37. package/src/editor/citation-dialog.component.js +174 -207
  38. package/src/editor/citation-dialog.component.js.map +1 -1
  39. package/src/editor/code-mirror-bridge.js +63 -0
  40. package/src/editor/code-mirror-bridge.js.map +1 -0
  41. package/src/editor/code-mirror-bridge.min.js +1 -0
  42. package/src/editor/code-mirror-bridge.ts +85 -0
  43. package/src/editor/code-view-dialog.component.js +87 -116
  44. package/src/editor/code-view-dialog.component.js.map +1 -1
  45. package/src/editor/editor.component.js +903 -925
  46. package/src/editor/editor.component.js.map +1 -1
  47. package/src/editor/editor.component.min.js +1 -1
  48. package/src/editor/editor.component.ts +60 -21
  49. package/src/editor/link-dialog.component.js +356 -395
  50. package/src/editor/link-dialog.component.js.map +1 -1
  51. package/src/editor/media-dialog.component.js +270 -303
  52. package/src/editor/media-dialog.component.js.map +1 -1
  53. package/src/froala/plugins/citationManager.js +170 -191
  54. package/src/froala/plugins/citationManager.js.map +1 -1
  55. package/src/froala/plugins/inputButton.js +122 -138
  56. package/src/froala/plugins/inputButton.js.map +1 -1
  57. package/src/froala/plugins/linkManager.js +89 -104
  58. package/src/froala/plugins/linkManager.js.map +1 -1
  59. package/src/froala/plugins/mediaManager.js +72 -87
  60. package/src/froala/plugins/mediaManager.js.map +1 -1
  61. package/src/froala/plugins/menuButton.js +71 -86
  62. package/src/froala/plugins/menuButton.js.map +1 -1
  63. package/src/main.js +13 -33
  64. package/src/main.js.map +1 -1
  65. package/src/material.js +99 -194
  66. package/src/material.js.map +1 -1
  67. package/src/media-selector/media-selector.component.js +406 -441
  68. package/src/media-selector/media-selector.component.js.map +1 -1
  69. package/src/polyfills.js +3 -16
  70. package/src/polyfills.js.map +1 -1
  71. package/src/quill-plugins/quill-break-blot.plugin.js +19 -35
  72. package/src/quill-plugins/quill-break-blot.plugin.js.map +1 -1
  73. package/src/quill-plugins/quill-html-edit.plugin.js +140 -153
  74. package/src/quill-plugins/quill-html-edit.plugin.js.map +1 -1
  75. package/src/quill-plugins/quill-image-format.plugin.js +33 -47
  76. package/src/quill-plugins/quill-image-format.plugin.js.map +1 -1
  77. package/src/quill-plugins/quill-input-button.plugin.js +77 -95
  78. package/src/quill-plugins/quill-input-button.plugin.js.map +1 -1
  79. package/src/selector/selector.component.js +241 -276
  80. package/src/selector/selector.component.js.map +1 -1
  81. package/src/test/test.directive.js +49 -66
  82. package/src/test/test.directive.js.map +1 -1
  83. package/src/tree/tree-dialog.component.js +202 -231
  84. package/src/tree/tree-dialog.component.js.map +1 -1
  85. package/src/tree/tree-node.component.js +253 -279
  86. package/src/tree/tree-node.component.js.map +1 -1
  87. package/src/tree/tree-node.component.min.js +1 -1
  88. package/src/tree/tree-node.component.ts +10 -18
  89. package/src/tree/tree.component.js +531 -568
  90. package/src/tree/tree.component.js.map +1 -1
  91. package/src/tree/tree.component.min.js +1 -1
  92. package/src/tree/tree.component.ts +7 -10
@@ -1,402 +1,363 @@
1
- System.register(["@angular/core", "@angular/forms", "@angular/material/dialog", "@angular/material/snack-bar", "rxjs", "rxjs/operators", "lodash", "@stratusjs/runtime/stratus", "@stratusjs/core/environment", "../backend.service", "@stratusjs/angularjs/services/model", "../core/responsive.component", "@angular/material/icon", "@angular/platform-browser"], function (exports_1, context_1) {
2
- "use strict";
3
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
4
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6
- 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;
7
- return c > 3 && r && Object.defineProperty(target, key, r), r;
8
- };
9
- var __metadata = (this && this.__metadata) || function (k, v) {
10
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
11
- };
12
- var __param = (this && this.__param) || function (paramIndex, decorator) {
13
- return function (target, key) { decorator(target, key, paramIndex); }
14
- };
15
- var core_1, forms_1, dialog_1, snack_bar_1, rxjs_1, operators_1, lodash_1, stratus_1, environment_1, backend_service_1, model_1, responsive_component_1, icon_1, platform_browser_1, systemDir, moduleName, parentModuleName, min, localDir, LinkDialogComponent;
16
- var __moduleName = context_1 && context_1.id;
17
- return {
18
- setters: [
19
- function (core_1_1) {
20
- core_1 = core_1_1;
21
- },
22
- function (forms_1_1) {
23
- forms_1 = forms_1_1;
24
- },
25
- function (dialog_1_1) {
26
- dialog_1 = dialog_1_1;
27
- },
28
- function (snack_bar_1_1) {
29
- snack_bar_1 = snack_bar_1_1;
30
- },
31
- function (rxjs_1_1) {
32
- rxjs_1 = rxjs_1_1;
33
- },
34
- function (operators_1_1) {
35
- operators_1 = operators_1_1;
36
- },
37
- function (lodash_1_1) {
38
- lodash_1 = lodash_1_1;
39
- },
40
- function (stratus_1_1) {
41
- stratus_1 = stratus_1_1;
42
- },
43
- function (environment_1_1) {
44
- environment_1 = environment_1_1;
45
- },
46
- function (backend_service_1_1) {
47
- backend_service_1 = backend_service_1_1;
48
- },
49
- function (model_1_1) {
50
- model_1 = model_1_1;
51
- },
52
- function (responsive_component_1_1) {
53
- responsive_component_1 = responsive_component_1_1;
54
- },
55
- function (icon_1_1) {
56
- icon_1 = icon_1_1;
57
- },
58
- function (platform_browser_1_1) {
59
- platform_browser_1 = platform_browser_1_1;
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
+ import { ChangeDetectorRef, Component, Inject } from '@angular/core';
14
+ import { FormBuilder } from '@angular/forms';
15
+ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
16
+ import { MatSnackBar } from '@angular/material/snack-bar';
17
+ import { Observable } from 'rxjs';
18
+ import { debounceTime, finalize, switchMap, tap } from 'rxjs/operators';
19
+ import _ from 'lodash';
20
+ import { Stratus } from '@stratusjs/runtime/stratus';
21
+ import { cookie } from '@stratusjs/core/environment';
22
+ import { BackendService } from '../backend.service';
23
+ import { Model } from '@stratusjs/angularjs/services/model';
24
+ import { ResponsiveComponent } from '../core/responsive.component';
25
+ import { MatIconRegistry } from '@angular/material/icon';
26
+ import { DomSanitizer } from '@angular/platform-browser';
27
+ const systemDir = '@stratusjs/angular';
28
+ const moduleName = 'link-dialog';
29
+ const parentModuleName = 'editor';
30
+ const min = !cookie('env') ? '.min' : '';
31
+ const localDir = `${Stratus.BaseUrl}${boot.configuration.paths[`${systemDir}/*`].replace(/[^/]*$/, '').replace(/\/dist\/$/, '/src/')}`;
32
+ let LinkDialogComponent = class LinkDialogComponent extends ResponsiveComponent {
33
+ constructor(dialogRef, data, fb, backend, snackBar, iconRegistry, sanitizer, ref) {
34
+ super();
35
+ this.dialogRef = dialogRef;
36
+ this.data = data;
37
+ this.fb = fb;
38
+ this.backend = backend;
39
+ this.snackBar = snackBar;
40
+ this.iconRegistry = iconRegistry;
41
+ this.sanitizer = sanitizer;
42
+ this.ref = ref;
43
+ this.title = moduleName + '_component';
44
+ this._ = _;
45
+ this.Stratus = Stratus;
46
+ this.apiBase = '/Api/Content';
47
+ this.contentEntities = [];
48
+ this.isContentLoading = true;
49
+ this.isSingleContentLoading = false;
50
+ this.limit = 20;
51
+ this.eventInsert = true;
52
+ this.isListView = false;
53
+ this.selected = [];
54
+ this.linkType = '';
55
+ this.linkText = '';
56
+ this.linkURL = '';
57
+ this.linkTarget = false;
58
+ this.svgIcons = {};
59
+ this.isInitialized = false;
60
+ this.isDestroyed = false;
61
+ this.isStyled = false;
62
+ }
63
+ ngOnInit() {
64
+ this.uid = _.uniqueId(`sa_${_.snakeCase(moduleName)}_component_`);
65
+ Stratus.Instances[this.uid] = this;
66
+ Stratus.Internals.CssLoader(`${localDir}${parentModuleName}/${moduleName}.component${min}.css`)
67
+ .then(() => {
68
+ this.isStyled = true;
69
+ this.refresh();
70
+ })
71
+ .catch((err) => {
72
+ console.warn('Issue detected in CSS Loader for Component:', this);
73
+ console.error(err);
74
+ this.isStyled = true;
75
+ this.refresh();
76
+ });
77
+ _.forEach({
78
+ selector_delete: `${Stratus.BaseUrl}sitetheorycore/images/icons/actionButtons/delete.svg`,
79
+ selector_edit: `${Stratus.BaseUrl}sitetheorycore/images/icons/actionButtons/edit.svg`
80
+ }, (value, key) => this.iconRegistry.addSvgIcon(key, this.sanitizer.bypassSecurityTrustResourceUrl(value)).getNamedSvgIcon(key));
81
+ this.model = this.data.model;
82
+ this.property = this.data.property;
83
+ this.editor = this.data.editor;
84
+ this.eventManager = this.data.eventManager;
85
+ this.element = this.data.element;
86
+ if (_.isBoolean(this.data.eventInsert)) {
87
+ this.eventInsert = this.data.eventInsert;
88
+ }
89
+ this.dialogContentForm = this.fb.group({
90
+ contentSelectorInput: '',
91
+ linkTypeRadio: '',
92
+ linkTextInput: '',
93
+ linkURLInput: '',
94
+ linkTargetCheckbox: ''
95
+ });
96
+ this.dialogContentForm
97
+ .get('contentSelectorInput')
98
+ .valueChanges
99
+ .pipe(debounceTime(300), tap(() => this.isContentLoading = true), switchMap((value) => {
100
+ if (_.isUndefined(value)) {
101
+ return this.getQuery();
60
102
  }
61
- ],
62
- execute: function () {
63
- systemDir = '@stratusjs/angular';
64
- moduleName = 'link-dialog';
65
- parentModuleName = 'editor';
66
- min = !environment_1.cookie('env') ? '.min' : '';
67
- localDir = `${stratus_1.Stratus.BaseUrl}${boot.configuration.paths[`${systemDir}/*`].replace(/[^/]*$/, '').replace(/\/dist\/$/, '/src/')}`;
68
- LinkDialogComponent = class LinkDialogComponent extends responsive_component_1.ResponsiveComponent {
69
- constructor(dialogRef, data, fb, backend, snackBar, iconRegistry, sanitizer, ref) {
70
- super();
71
- this.dialogRef = dialogRef;
72
- this.data = data;
73
- this.fb = fb;
74
- this.backend = backend;
75
- this.snackBar = snackBar;
76
- this.iconRegistry = iconRegistry;
77
- this.sanitizer = sanitizer;
78
- this.ref = ref;
79
- this.title = moduleName + '_component';
80
- this._ = lodash_1.default;
81
- this.Stratus = stratus_1.Stratus;
82
- this.apiBase = '/Api/Content';
83
- this.contentEntities = [];
84
- this.isContentLoading = true;
85
- this.isSingleContentLoading = false;
86
- this.limit = 20;
87
- this.eventInsert = true;
88
- this.isListView = false;
89
- this.selected = [];
90
- this.linkType = '';
91
- this.linkText = '';
92
- this.linkURL = '';
93
- this.linkTarget = false;
94
- this.svgIcons = {};
95
- this.isInitialized = false;
96
- this.isDestroyed = false;
97
- this.isStyled = false;
98
- }
99
- ngOnInit() {
100
- this.uid = lodash_1.default.uniqueId(`sa_${lodash_1.default.snakeCase(moduleName)}_component_`);
101
- stratus_1.Stratus.Instances[this.uid] = this;
102
- stratus_1.Stratus.Internals.CssLoader(`${localDir}${parentModuleName}/${moduleName}.component${min}.css`)
103
- .then(() => {
104
- this.isStyled = true;
105
- this.refresh();
106
- })
107
- .catch((err) => {
108
- console.warn('Issue detected in CSS Loader for Component:', this);
109
- console.error(err);
110
- this.isStyled = true;
111
- this.refresh();
112
- });
113
- lodash_1.default.forEach({
114
- selector_delete: `${stratus_1.Stratus.BaseUrl}sitetheorycore/images/icons/actionButtons/delete.svg`,
115
- selector_edit: `${stratus_1.Stratus.BaseUrl}sitetheorycore/images/icons/actionButtons/edit.svg`
116
- }, (value, key) => this.iconRegistry.addSvgIcon(key, this.sanitizer.bypassSecurityTrustResourceUrl(value)).getNamedSvgIcon(key));
117
- this.model = this.data.model;
118
- this.property = this.data.property;
119
- this.editor = this.data.editor;
120
- this.eventManager = this.data.eventManager;
121
- this.element = this.data.element;
122
- if (lodash_1.default.isBoolean(this.data.eventInsert)) {
123
- this.eventInsert = this.data.eventInsert;
124
- }
125
- this.dialogContentForm = this.fb.group({
126
- contentSelectorInput: '',
127
- linkTypeRadio: '',
128
- linkTextInput: '',
129
- linkURLInput: '',
130
- linkTargetCheckbox: ''
131
- });
132
- this.dialogContentForm
133
- .get('contentSelectorInput')
134
- .valueChanges
135
- .pipe(operators_1.debounceTime(300), operators_1.tap(() => this.isContentLoading = true), operators_1.switchMap((value) => {
136
- if (lodash_1.default.isUndefined(value)) {
137
- return this.getQuery();
138
- }
139
- if (!lodash_1.default.isString(value)) {
140
- this.content = value;
141
- return this.getQuery();
142
- }
143
- return this.getQuery(value);
144
- }))
145
- .subscribe((response) => this.processContent(response));
146
- this.backend
147
- .get(this.getQueryUrl())
148
- .pipe(operators_1.finalize(() => this.isContentLoading = false))
149
- .subscribe((response) => this.processContent(response));
150
- this.dialogContentForm
151
- .get('linkTypeRadio')
152
- .valueChanges
153
- .pipe(operators_1.debounceTime(300))
154
- .subscribe((response) => this.linkType = response);
155
- this.linkType = this.element && this.element.hasAttribute('data-content-id') ? 'content' : 'url';
156
- this.dialogContentForm
157
- .get('linkTypeRadio')
158
- .patchValue(this.linkType);
159
- this.dialogContentForm
160
- .get('linkTextInput')
161
- .valueChanges
162
- .pipe(operators_1.debounceTime(300))
163
- .subscribe((response) => this.linkText = response);
164
- this.linkText = this.element ? this.element.textContent : '';
165
- this.dialogContentForm
166
- .get('linkTextInput')
167
- .patchValue(this.linkText);
168
- this.dialogContentForm
169
- .get('linkURLInput')
170
- .valueChanges
171
- .pipe(operators_1.debounceTime(300))
172
- .subscribe((response) => this.linkURL = response);
173
- this.linkURL = this.element && this.element.hasAttribute('href') ? this.element.getAttribute('href') : '';
174
- this.dialogContentForm
175
- .get('linkURLInput')
176
- .patchValue(this.linkURL);
177
- this.dialogContentForm
178
- .get('linkTargetCheckbox')
179
- .valueChanges
180
- .pipe(operators_1.debounceTime(300))
181
- .subscribe((response) => this.linkTarget = response);
182
- this.linkTarget = this.element ? this.element.hasAttribute('target') : false;
183
- this.dialogContentForm
184
- .get('linkTargetCheckbox')
185
- .patchValue(this.linkTarget);
186
- if (this.element && this.element.hasAttribute('data-content-id')) {
187
- this.isSingleContentLoading = true;
188
- this.backend
189
- .get(this.getQueryUrl(null, this.element.getAttribute('data-content-id')))
190
- .pipe(operators_1.finalize(() => this.isSingleContentLoading = false))
191
- .subscribe((response) => {
192
- if (!response.ok || response.status !== 200 || lodash_1.default.isEmpty(response.body)) {
193
- return null;
194
- }
195
- const payload = lodash_1.default.get(response.body, 'payload') || response.body;
196
- if (lodash_1.default.isEmpty(payload) || Array.isArray(payload) || !lodash_1.default.isObject(payload)) {
197
- return null;
198
- }
199
- this.contentEntity = payload;
200
- this.isSingleContentLoading = false;
201
- this.dialogContentForm
202
- .get('contentSelectorInput')
203
- .patchValue(this.contentEntity);
204
- this.refresh();
205
- return this.contentEntity;
206
- });
207
- }
208
- this.isInitialized = true;
209
- }
210
- ngOnDestroy() {
211
- this.isDestroyed = true;
212
- }
213
- refresh() {
214
- if (this.isDestroyed) {
215
- return new Promise(resolve => resolve());
216
- }
217
- return super.refresh();
218
- }
219
- onCancelClick() {
220
- this.dialogRef.close();
221
- this.refresh();
222
- }
223
- onPage(event) {
224
- this.pageEvent = event;
225
- this.getQuery(this.lastContentQuery).subscribe((response) => this.processContent(response));
226
- }
227
- getQueryUrl(query, id) {
228
- query = (!lodash_1.default.isString(query) || lodash_1.default.isEmpty(query)) ? '' : `"${query}"`;
229
- id = lodash_1.default.isEmpty(id) ? '' : `/${id}`;
230
- return `${this.apiBase}${id}?limit=${this.limit}&options[isContent]=null&options[isCollection]=null&options[showRoutable]=true&options[showRouting]=true&q=${query}`;
231
- }
232
- getQuery(query) {
233
- this.lastContentQuery = query;
234
- this.isContentLoading = true;
235
- return this.backend.get(this.getQueryUrl(query))
236
- .pipe(operators_1.finalize(() => this.isContentLoading = false));
237
- }
238
- processContent(response) {
239
- if (!response.ok || response.status !== 200 || lodash_1.default.isEmpty(response.body)) {
240
- this.meta = {};
241
- this.contentEntities = [];
242
- this.refresh();
243
- return this.contentEntities;
244
- }
245
- this.meta = lodash_1.default.get(response.body, 'meta') || {};
246
- const payload = lodash_1.default.get(response.body, 'payload') || response.body;
247
- if (lodash_1.default.isEmpty(payload) || !Array.isArray(payload)) {
248
- this.contentEntities = [];
249
- this.isContentLoading = false;
250
- this.refresh();
251
- return this.contentEntities;
252
- }
253
- this.contentEntities = payload;
254
- this.isContentLoading = false;
255
- this.refresh();
256
- return this.contentEntities;
257
- }
258
- onAcceptClick() {
259
- const link = this.linkType === 'content' ? this.createLink(this.content) : {
260
- url: this.linkURL,
261
- text: this.linkText,
262
- target: this.linkTarget,
263
- };
264
- if (!link) {
265
- const identifier = this.content && this.content.id ? `for Content ID: ${this.content.id}.` : 'without Content Selected or URL Input.';
266
- console.warn(`${moduleName}: unable to build link ${identifier}`);
267
- this.snackBar.open(`Unable to build link ${identifier}`, 'dismiss', {
268
- duration: 5000,
269
- horizontalPosition: 'right',
270
- verticalPosition: 'bottom'
271
- });
272
- return;
273
- }
274
- if (this.content && this.content.id) {
275
- this.selected.push(this.content.id);
276
- }
277
- if (!this.eventInsert) {
278
- if (!(this.model instanceof model_1.Model)) {
279
- console.warn(`${moduleName}: event manager not available.`);
280
- return;
281
- }
282
- if (!lodash_1.default.isString(this.property)) {
283
- console.warn(`${moduleName}: event manager not available.`);
284
- return;
285
- }
286
- console.warn(`${moduleName}: disabling eventInsert is not recommended.`);
287
- this.model.set(this.property, this.model.get(this.property) + link);
288
- return;
289
- }
290
- if (!this.eventManager) {
291
- console.warn(`${moduleName}: event manager is not set.`);
292
- return;
293
- }
294
- this.eventManager.trigger('insert', link, this.editor);
295
- this.onCancelClick();
296
- }
297
- isSelected(content) {
298
- if (lodash_1.default.isUndefined(content)) {
299
- return;
300
- }
301
- return lodash_1.default.includes(this.selected, content.id);
302
- }
303
- createLink(content) {
304
- if (!content) {
305
- console.warn(`${moduleName}: unable to create link for empty content`);
306
- return null;
307
- }
308
- if (!content.id) {
309
- console.warn(`${moduleName}: unable to find content id for content:`, content);
310
- return null;
311
- }
312
- if (!content.contentType || !content.contentType.name) {
313
- console.warn(`${moduleName}: unable to find content type for content id: ${content.id}`);
314
- return null;
315
- }
316
- if (!content.routing || !content.routing.length || !content.routing[0]) {
317
- console.warn(`${moduleName}: unable to find routing for ${content.contentType.name} id: ${content.id}`);
318
- return null;
319
- }
320
- if (!content.routing[0].url) {
321
- console.warn(`${moduleName}: unable to find url for ${content.contentType.name} id: ${content.id}`);
322
- return null;
323
- }
324
- if (!content.version) {
325
- console.warn(`${moduleName}: unable to find content version for ${content.contentType.name} id: ${content.id}`);
326
- return null;
327
- }
328
- if (!content.version.title || !content.version.title.length) {
329
- console.warn(`${moduleName}: unable to find title for ${content.contentType.name} id: ${content.id}`);
330
- return null;
331
- }
332
- return {
333
- url: `/${content.routing[0].url}`,
334
- title: content.version.title,
335
- text: this.linkText,
336
- target: this.linkTarget,
337
- id: content.id
338
- };
339
- }
340
- getSvg(url, options) {
341
- const uid = this.addSvgIcon(url, options);
342
- return new rxjs_1.Observable((subscriber) => {
343
- this.iconRegistry
344
- .getNamedSvgIcon(uid)
345
- .subscribe({
346
- error(err) {
347
- console.error(`getSvg(${url}): ${err}`);
348
- },
349
- complete() {
350
- subscriber.next(uid);
351
- }
352
- });
353
- });
354
- }
355
- addSvgIcon(url, options) {
356
- if (url in this.svgIcons) {
357
- return this.svgIcons[url];
358
- }
359
- if (!options) {
360
- options = {};
361
- }
362
- const uid = this.svgIcons[url] = lodash_1.default.uniqueId('selector_svg');
363
- this.iconRegistry.addSvgIcon(uid, this.sanitizer.bypassSecurityTrustResourceUrl(url), options);
364
- return uid;
103
+ if (!_.isString(value)) {
104
+ this.content = value;
105
+ return this.getQuery();
106
+ }
107
+ return this.getQuery(value);
108
+ }))
109
+ .subscribe((response) => this.processContent(response));
110
+ this.backend
111
+ .get(this.getQueryUrl())
112
+ .pipe(finalize(() => this.isContentLoading = false))
113
+ .subscribe((response) => this.processContent(response));
114
+ this.dialogContentForm
115
+ .get('linkTypeRadio')
116
+ .valueChanges
117
+ .pipe(debounceTime(300))
118
+ .subscribe((response) => this.linkType = response);
119
+ this.linkType = this.element && this.element.hasAttribute('data-content-id') ? 'content' : 'url';
120
+ this.dialogContentForm
121
+ .get('linkTypeRadio')
122
+ .patchValue(this.linkType);
123
+ this.dialogContentForm
124
+ .get('linkTextInput')
125
+ .valueChanges
126
+ .pipe(debounceTime(300))
127
+ .subscribe((response) => this.linkText = response);
128
+ this.linkText = this.element ? this.element.textContent : '';
129
+ this.dialogContentForm
130
+ .get('linkTextInput')
131
+ .patchValue(this.linkText);
132
+ this.dialogContentForm
133
+ .get('linkURLInput')
134
+ .valueChanges
135
+ .pipe(debounceTime(300))
136
+ .subscribe((response) => this.linkURL = response);
137
+ this.linkURL = this.element && this.element.hasAttribute('href') ? this.element.getAttribute('href') : '';
138
+ this.dialogContentForm
139
+ .get('linkURLInput')
140
+ .patchValue(this.linkURL);
141
+ this.dialogContentForm
142
+ .get('linkTargetCheckbox')
143
+ .valueChanges
144
+ .pipe(debounceTime(300))
145
+ .subscribe((response) => this.linkTarget = response);
146
+ this.linkTarget = this.element ? this.element.hasAttribute('target') : false;
147
+ this.dialogContentForm
148
+ .get('linkTargetCheckbox')
149
+ .patchValue(this.linkTarget);
150
+ if (this.element && this.element.hasAttribute('data-content-id')) {
151
+ this.isSingleContentLoading = true;
152
+ this.backend
153
+ .get(this.getQueryUrl(null, this.element.getAttribute('data-content-id')))
154
+ .pipe(finalize(() => this.isSingleContentLoading = false))
155
+ .subscribe((response) => {
156
+ if (!response.ok || response.status !== 200 || _.isEmpty(response.body)) {
157
+ return null;
365
158
  }
366
- displayContentText(content) {
367
- if (!content) {
368
- return;
369
- }
370
- const routing = lodash_1.default.get(content, 'routing[0].url');
371
- const routingText = !lodash_1.default.isUndefined(routing) ? ` (/${routing})` : ' (No route!)';
372
- const contentId = lodash_1.default.get(content, 'id');
373
- const contentIdText = !lodash_1.default.isUndefined(contentId) ? `Content: ${contentId}` : null;
374
- return (lodash_1.default.get(content, 'version.title') || contentIdText) + routingText;
159
+ const payload = _.get(response.body, 'payload') || response.body;
160
+ if (_.isEmpty(payload) || Array.isArray(payload) || !_.isObject(payload)) {
161
+ return null;
375
162
  }
376
- goToUrl(content) {
377
- if (!content || !content.contentType) {
378
- console.error('unable to execute goToUrl() because a valid model content was not provided.');
379
- return;
380
- }
381
- window.open(content.contentType.editUrl + '?id=' + content.id, '_blank');
163
+ this.contentEntity = payload;
164
+ this.isSingleContentLoading = false;
165
+ this.dialogContentForm
166
+ .get('contentSelectorInput')
167
+ .patchValue(this.contentEntity);
168
+ this.refresh();
169
+ return this.contentEntity;
170
+ });
171
+ }
172
+ this.isInitialized = true;
173
+ }
174
+ ngOnDestroy() {
175
+ this.isDestroyed = true;
176
+ }
177
+ refresh() {
178
+ if (this.isDestroyed) {
179
+ return new Promise(resolve => resolve());
180
+ }
181
+ return super.refresh();
182
+ }
183
+ onCancelClick() {
184
+ this.dialogRef.close();
185
+ this.refresh();
186
+ }
187
+ onPage(event) {
188
+ this.pageEvent = event;
189
+ this.getQuery(this.lastContentQuery).subscribe((response) => this.processContent(response));
190
+ }
191
+ getQueryUrl(query, id) {
192
+ query = (!_.isString(query) || _.isEmpty(query)) ? '' : `"${query}"`;
193
+ id = _.isEmpty(id) ? '' : `/${id}`;
194
+ return `${this.apiBase}${id}?limit=${this.limit}&options[isContent]=null&options[isCollection]=null&options[showRoutable]=true&options[showRouting]=true&q=${query}`;
195
+ }
196
+ getQuery(query) {
197
+ this.lastContentQuery = query;
198
+ this.isContentLoading = true;
199
+ return this.backend.get(this.getQueryUrl(query))
200
+ .pipe(finalize(() => this.isContentLoading = false));
201
+ }
202
+ processContent(response) {
203
+ if (!response.ok || response.status !== 200 || _.isEmpty(response.body)) {
204
+ this.meta = {};
205
+ this.contentEntities = [];
206
+ this.refresh();
207
+ return this.contentEntities;
208
+ }
209
+ this.meta = _.get(response.body, 'meta') || {};
210
+ const payload = _.get(response.body, 'payload') || response.body;
211
+ if (_.isEmpty(payload) || !Array.isArray(payload)) {
212
+ this.contentEntities = [];
213
+ this.isContentLoading = false;
214
+ this.refresh();
215
+ return this.contentEntities;
216
+ }
217
+ this.contentEntities = payload;
218
+ this.isContentLoading = false;
219
+ this.refresh();
220
+ return this.contentEntities;
221
+ }
222
+ onAcceptClick() {
223
+ const link = this.linkType === 'content' ? this.createLink(this.content) : {
224
+ url: this.linkURL,
225
+ text: this.linkText,
226
+ target: this.linkTarget,
227
+ };
228
+ if (!link) {
229
+ const identifier = this.content && this.content.id ? `for Content ID: ${this.content.id}.` : 'without Content Selected or URL Input.';
230
+ console.warn(`${moduleName}: unable to build link ${identifier}`);
231
+ this.snackBar.open(`Unable to build link ${identifier}`, 'dismiss', {
232
+ duration: 5000,
233
+ horizontalPosition: 'right',
234
+ verticalPosition: 'bottom'
235
+ });
236
+ return;
237
+ }
238
+ if (this.content && this.content.id) {
239
+ this.selected.push(this.content.id);
240
+ }
241
+ if (!this.eventInsert) {
242
+ if (!(this.model instanceof Model)) {
243
+ console.warn(`${moduleName}: event manager not available.`);
244
+ return;
245
+ }
246
+ if (!_.isString(this.property)) {
247
+ console.warn(`${moduleName}: event manager not available.`);
248
+ return;
249
+ }
250
+ console.warn(`${moduleName}: disabling eventInsert is not recommended.`);
251
+ this.model.set(this.property, this.model.get(this.property) + link);
252
+ return;
253
+ }
254
+ if (!this.eventManager) {
255
+ console.warn(`${moduleName}: event manager is not set.`);
256
+ return;
257
+ }
258
+ this.eventManager.trigger('insert', link, this.editor);
259
+ this.onCancelClick();
260
+ }
261
+ isSelected(content) {
262
+ if (_.isUndefined(content)) {
263
+ return;
264
+ }
265
+ return _.includes(this.selected, content.id);
266
+ }
267
+ createLink(content) {
268
+ if (!content) {
269
+ console.warn(`${moduleName}: unable to create link for empty content`);
270
+ return null;
271
+ }
272
+ if (!content.id) {
273
+ console.warn(`${moduleName}: unable to find content id for content:`, content);
274
+ return null;
275
+ }
276
+ if (!content.contentType || !content.contentType.name) {
277
+ console.warn(`${moduleName}: unable to find content type for content id: ${content.id}`);
278
+ return null;
279
+ }
280
+ if (!content.routing || !content.routing.length || !content.routing[0]) {
281
+ console.warn(`${moduleName}: unable to find routing for ${content.contentType.name} id: ${content.id}`);
282
+ return null;
283
+ }
284
+ if (!content.routing[0].url) {
285
+ console.warn(`${moduleName}: unable to find url for ${content.contentType.name} id: ${content.id}`);
286
+ return null;
287
+ }
288
+ if (!content.version) {
289
+ console.warn(`${moduleName}: unable to find content version for ${content.contentType.name} id: ${content.id}`);
290
+ return null;
291
+ }
292
+ if (!content.version.title || !content.version.title.length) {
293
+ console.warn(`${moduleName}: unable to find title for ${content.contentType.name} id: ${content.id}`);
294
+ return null;
295
+ }
296
+ return {
297
+ url: `/${content.routing[0].url}`,
298
+ title: content.version.title,
299
+ text: this.linkText,
300
+ target: this.linkTarget,
301
+ id: content.id
302
+ };
303
+ }
304
+ getSvg(url, options) {
305
+ const uid = this.addSvgIcon(url, options);
306
+ return new Observable((subscriber) => {
307
+ this.iconRegistry
308
+ .getNamedSvgIcon(uid)
309
+ .subscribe({
310
+ error(err) {
311
+ console.error(`getSvg(${url}): ${err}`);
312
+ },
313
+ complete() {
314
+ subscriber.next(uid);
382
315
  }
383
- };
384
- LinkDialogComponent = __decorate([
385
- core_1.Component({
386
- selector: `sa-${moduleName}`,
387
- templateUrl: `${localDir}/${parentModuleName}/${moduleName}.component${min}.html`,
388
- }),
389
- __param(1, core_1.Inject(dialog_1.MAT_DIALOG_DATA)),
390
- __metadata("design:paramtypes", [dialog_1.MatDialogRef, Object, forms_1.FormBuilder,
391
- backend_service_1.BackendService,
392
- snack_bar_1.MatSnackBar,
393
- icon_1.MatIconRegistry,
394
- platform_browser_1.DomSanitizer,
395
- core_1.ChangeDetectorRef])
396
- ], LinkDialogComponent);
397
- exports_1("LinkDialogComponent", LinkDialogComponent);
316
+ });
317
+ });
318
+ }
319
+ addSvgIcon(url, options) {
320
+ if (url in this.svgIcons) {
321
+ return this.svgIcons[url];
322
+ }
323
+ if (!options) {
324
+ options = {};
325
+ }
326
+ const uid = this.svgIcons[url] = _.uniqueId('selector_svg');
327
+ this.iconRegistry.addSvgIcon(uid, this.sanitizer.bypassSecurityTrustResourceUrl(url), options);
328
+ return uid;
329
+ }
330
+ displayContentText(content) {
331
+ if (!content) {
332
+ return;
333
+ }
334
+ const routing = _.get(content, 'routing[0].url');
335
+ const routingText = !_.isUndefined(routing) ? ` (/${routing})` : ' (No route!)';
336
+ const contentId = _.get(content, 'id');
337
+ const contentIdText = !_.isUndefined(contentId) ? `Content: ${contentId}` : null;
338
+ return (_.get(content, 'version.title') || contentIdText) + routingText;
339
+ }
340
+ goToUrl(content) {
341
+ if (!content || !content.contentType) {
342
+ console.error('unable to execute goToUrl() because a valid model content was not provided.');
343
+ return;
398
344
  }
399
- };
400
- });
345
+ window.open(content.contentType.editUrl + '?id=' + content.id, '_blank');
346
+ }
347
+ };
348
+ LinkDialogComponent = __decorate([
349
+ Component({
350
+ selector: `sa-${moduleName}`,
351
+ templateUrl: `${localDir}/${parentModuleName}/${moduleName}.component${min}.html`,
352
+ }),
353
+ __param(1, Inject(MAT_DIALOG_DATA)),
354
+ __metadata("design:paramtypes", [MatDialogRef, Object, FormBuilder,
355
+ BackendService,
356
+ MatSnackBar,
357
+ MatIconRegistry,
358
+ DomSanitizer,
359
+ ChangeDetectorRef])
360
+ ], LinkDialogComponent);
361
+ export { LinkDialogComponent };
401
362
 
402
363
  //# sourceMappingURL=link-dialog.component.js.map