@web-atoms/core 2.6.24 → 2.6.25

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 (120) hide show
  1. package/dist-esm/App.js +231 -235
  2. package/dist-esm/Atom.js +93 -96
  3. package/dist-esm/MockApp.js +17 -18
  4. package/dist-esm/Pack.js +1 -3
  5. package/dist-esm/core/AtomBinder.js +189 -187
  6. package/dist-esm/core/AtomComponent.js +479 -502
  7. package/dist-esm/core/AtomDispatcher.js +46 -48
  8. package/dist-esm/core/AtomDisposableList.js +24 -25
  9. package/dist-esm/core/AtomEnumerator.js +15 -16
  10. package/dist-esm/core/AtomList.js +193 -192
  11. package/dist-esm/core/AtomLoader.js +229 -215
  12. package/dist-esm/core/AtomMap.js +7 -8
  13. package/dist-esm/core/AtomOnce.js +22 -24
  14. package/dist-esm/core/AtomSelectableList.js +240 -243
  15. package/dist-esm/core/AtomUri.js +70 -72
  16. package/dist-esm/core/AtomWatcher.js +105 -111
  17. package/dist-esm/core/Bind.js +271 -269
  18. package/dist-esm/core/BindableProperty.js +26 -27
  19. package/dist-esm/core/CancelTokenFactory.js +21 -24
  20. package/dist-esm/core/Color.js +1 -2
  21. package/dist-esm/core/Colors.js +545 -231
  22. package/dist-esm/core/Command.js +236 -223
  23. package/dist-esm/core/Defer.js +21 -22
  24. package/dist-esm/core/EventScope.js +96 -88
  25. package/dist-esm/core/ExpressionParser.js +132 -144
  26. package/dist-esm/core/ExtendControl.js +7 -8
  27. package/dist-esm/core/FormattedError.js +7 -8
  28. package/dist-esm/core/FormattedString.js +4 -5
  29. package/dist-esm/core/Hacks.js +41 -42
  30. package/dist-esm/core/IFetchEvent.js +1 -2
  31. package/dist-esm/core/IScreen.js +1 -2
  32. package/dist-esm/core/IValueConverter.js +1 -2
  33. package/dist-esm/core/InheritedProperty.js +61 -63
  34. package/dist-esm/core/InjectProperty.js +12 -13
  35. package/dist-esm/core/KeyValuePairs.js +1 -2
  36. package/dist-esm/core/Markdown.js +14 -17
  37. package/dist-esm/core/MarkdownError.js +6 -7
  38. package/dist-esm/core/PropertyBinding.js +1 -2
  39. package/dist-esm/core/PropertyMap.js +28 -27
  40. package/dist-esm/core/Route.js +149 -148
  41. package/dist-esm/core/SingleInvoker.js +32 -35
  42. package/dist-esm/core/StringHelper.js +49 -51
  43. package/dist-esm/core/TransientDisposable.js +14 -16
  44. package/dist-esm/core/WatchProperty.js +18 -17
  45. package/dist-esm/core/WebImage.js +7 -8
  46. package/dist-esm/core/XNode.js +134 -117
  47. package/dist-esm/core/sleep.js +21 -24
  48. package/dist-esm/core/types.js +102 -103
  49. package/dist-esm/di/DISingleton.js +7 -5
  50. package/dist-esm/di/DITransient.js +7 -5
  51. package/dist-esm/di/IMockOrInject.js +1 -2
  52. package/dist-esm/di/IServiceProvider.js +1 -2
  53. package/dist-esm/di/Inject.js +67 -67
  54. package/dist-esm/di/Register.js +25 -26
  55. package/dist-esm/di/RegisterScoped.js +4 -3
  56. package/dist-esm/di/RegisterSingleton.js +4 -3
  57. package/dist-esm/di/ServiceCollection.js +38 -37
  58. package/dist-esm/di/ServiceProvider.js +94 -94
  59. package/dist-esm/di/TypeKey.js +13 -12
  60. package/dist-esm/services/BusyIndicatorService.js +7 -11
  61. package/dist-esm/services/CacheService.js +54 -62
  62. package/dist-esm/services/FetchBuilder.js +327 -278
  63. package/dist-esm/services/JsonService.js +118 -116
  64. package/dist-esm/services/MockNavigationService.js +127 -126
  65. package/dist-esm/services/NavigationService.js +95 -102
  66. package/dist-esm/services/ReferenceService.js +30 -33
  67. package/dist-esm/services/http/AjaxOptions.js +1 -3
  68. package/dist-esm/services/http/JsonError.js +16 -15
  69. package/dist-esm/services/http/RestService.js +314 -323
  70. package/dist-esm/style/StyleRule.js +1 -2
  71. package/dist-esm/test.js +0 -1
  72. package/dist-esm/unit/AtomTest.js +10 -11
  73. package/dist-esm/view-model/Action.js +258 -223
  74. package/dist-esm/view-model/AtomViewModel.js +234 -232
  75. package/dist-esm/view-model/AtomWindowViewModel.js +13 -14
  76. package/dist-esm/view-model/BindableUrlParameter.js +7 -8
  77. package/dist-esm/view-model/Delay.js +21 -25
  78. package/dist-esm/view-model/Disposable.js +28 -29
  79. package/dist-esm/view-model/Load.js +72 -73
  80. package/dist-esm/view-model/Once.js +33 -35
  81. package/dist-esm/view-model/baseTypes.js +4 -5
  82. package/dist-esm/view-model/bindPromise.js +24 -27
  83. package/dist-esm/view-model/bindProperty.js +3 -4
  84. package/dist-esm/view-model/bindUrlParameter.js +39 -43
  85. package/dist-esm/web/controls/AtomComboBox.js +56 -63
  86. package/dist-esm/web/controls/AtomControl.js +485 -490
  87. package/dist-esm/web/controls/AtomGridSplitter.js +57 -50
  88. package/dist-esm/web/controls/AtomGridView.js +230 -222
  89. package/dist-esm/web/controls/AtomItemsControl.js +677 -688
  90. package/dist-esm/web/controls/AtomPage.js +6 -7
  91. package/dist-esm/web/controls/AtomTemplate.js +1 -3
  92. package/dist-esm/web/controls/AtomTemplateControl.js +28 -29
  93. package/dist-esm/web/controls/AtomViewStack.js +19 -20
  94. package/dist-esm/web/core/AtomUI.js +200 -200
  95. package/dist-esm/web/core/Encoder.js +142 -152
  96. package/dist-esm/web/core/HtmlNode.js +141 -139
  97. package/dist-esm/web/images/Busy.js +1 -2
  98. package/dist-esm/web/images/BusyDataUrl.js +2 -869
  99. package/dist-esm/web/images/Button.js +1 -2
  100. package/dist-esm/web/images/ButtonDataUrl.js +2 -30
  101. package/dist-esm/web/images/CloseButton.js +1 -2
  102. package/dist-esm/web/images/CloseButtonDataUrl.js +2 -30
  103. package/dist-esm/web/images/CloseButtonHover.js +1 -2
  104. package/dist-esm/web/images/CloseButtonHoverDataUrl.js +2 -24
  105. package/dist-esm/web/services/LastTarget.js +31 -29
  106. package/dist-esm/web/services/MarkdownService.js +19 -31
  107. package/dist-esm/web/services/NotificationPopup.js +28 -21
  108. package/dist-esm/web/services/PopupService.js +512 -478
  109. package/dist-esm/web/services/PopupWindow.js +266 -247
  110. package/dist-esm/web/styles/AtomAlertWindowStyle.js +39 -40
  111. package/dist-esm/web/styles/AtomFrameStyle.js +15 -16
  112. package/dist-esm/web/styles/AtomNotificationStyle.js +19 -20
  113. package/dist-esm/web/styles/AtomPageLinkStyle.js +11 -12
  114. package/dist-esm/web/styles/AtomPopupStyle.js +9 -10
  115. package/dist-esm/web/styles/AtomStyle.js +61 -64
  116. package/dist-esm/web/styles/AtomStyleSheet.js +50 -51
  117. package/dist-esm/web/styles/AtomWindowStyle.js +116 -117
  118. package/dist-esm/web/styles/IStyleDeclaration.js +1 -2
  119. package/dist-esm/web/styles/StyleBuilder.js +79 -80
  120. package/package.json +1 -1
@@ -13,543 +13,520 @@ import { isControl, isFactorySymbol, xnodeSymbol } from "./XNode.js";
13
13
  const localBindSymbol = bindSymbol;
14
14
  const localXNodeSymbol = xnodeSymbol;
15
15
  let AtomComponent = class AtomComponent {
16
- static { _a = isControl, _b = isFactorySymbol; }
17
- static { this[_a] = true; }
18
- static { this[_b] = true; }
19
- get vsProps() {
20
- return undefined;
16
+ static {
17
+ _a = isControl, _b = isFactorySymbol;
18
+ }
19
+ static {
20
+ this[_a] = true;
21
+ }
22
+ static {
23
+ this[_b] = true;
24
+ }
25
+ get vsProps() {
26
+ return undefined;
27
+ }
28
+ constructor(app, element = null) {
29
+ this.app = app;
30
+ this.mInvalidated = 0;
31
+ this.mPendingPromises = {};
32
+ this.disposables = new AtomDisposableList();
33
+ this.bindings = [];
34
+ this.eventHandlers = [];
35
+ this.element = element;
36
+ this.element.atomControl = this;
37
+ const a = this.beginEdit();
38
+ this.preCreate();
39
+ this.create();
40
+ app.callLater(() => a.dispose());
41
+ }
42
+ bind(element, name, path, twoWays, valueFunc, source) {
43
+ const binding = new PropertyBinding(this, element, name, path, twoWays, valueFunc, source);
44
+ this.bindings.push(binding);
45
+ return {
46
+ dispose: () => {
47
+ binding.dispose();
48
+ ArrayHelper.remove(this.bindings, x => x === binding);
49
+ }
50
+ };
51
+ }
52
+ unbind(element, name) {
53
+ const toDelete = this.bindings.filter(x => x.element === element && (!name || x.name === name));
54
+ for (const iterator of toDelete) {
55
+ iterator.dispose();
56
+ ArrayHelper.remove(this.bindings, x => x === iterator);
21
57
  }
22
- constructor(app, element = null) {
23
- this.app = app;
24
- this.mInvalidated = 0;
25
- this.mPendingPromises = {};
26
- this.disposables = new AtomDisposableList();
27
- this.bindings = [];
28
- this.eventHandlers = [];
29
- this.element = element;
30
- this.element.atomControl = this;
31
- const a = this.beginEdit();
32
- this.preCreate();
33
- this.create();
34
- app.callLater(() => a.dispose());
58
+ }
59
+ bindEvent(element, name, method, key, capture) {
60
+ if (!element) {
61
+ return;
35
62
  }
36
- bind(element, name, path, twoWays, valueFunc, source) {
37
- const binding = new PropertyBinding(this, element, name, path, twoWays, valueFunc, source);
38
- this.bindings.push(binding);
39
- return {
40
- dispose: () => {
41
- binding.dispose();
42
- ArrayHelper.remove(this.bindings, (x) => x === binding);
43
- }
44
- };
63
+ if (!method) {
64
+ return;
45
65
  }
46
- unbind(element, name) {
47
- const toDelete = this.bindings.filter((x) => x.element === element && (!name || (x.name === name)));
48
- for (const iterator of toDelete) {
49
- iterator.dispose();
50
- ArrayHelper.remove(this.bindings, (x) => x === iterator);
51
- }
66
+ const be = {
67
+ element,
68
+ name,
69
+ handler: method
70
+ };
71
+ if (key) {
72
+ be.key = key;
52
73
  }
53
- bindEvent(element, name, method, key, capture) {
54
- if (!element) {
55
- return;
56
- }
57
- if (!method) {
58
- return;
59
- }
60
- const be = {
61
- element,
62
- name,
63
- handler: method
64
- };
65
- if (key) {
66
- be.key = key;
67
- }
68
- const handler = (e) => {
69
- try {
70
- let r = method(e);
71
- e.executed = true;
72
- if (r) {
73
- const originalReturn = r;
74
- r = r.then ? r : Promise.resolve(r);
75
- e.promise = e.promise ? e.promise.then(() => r) : r;
76
- if (originalReturn.catch) {
77
- return originalReturn.catch((c) => {
78
- if (CancelToken.isCancelled(c ?? "Unknown error")) {
79
- return;
80
- }
81
- alert(c.stack ?? c);
82
- });
83
- }
84
- return r;
85
- }
86
- }
87
- catch (error) {
88
- if (CancelToken.isCancelled(error)) {
89
- return;
90
- }
91
- alert(error.stack ?? error);
92
- }
93
- };
94
- element.addEventListener(name, handler, capture);
95
- be.disposable = {
96
- dispose: () => {
97
- element.removeEventListener(name, handler, capture);
98
- be.disposable.dispose = () => undefined;
99
- }
100
- };
101
- this.eventHandlers.push(be);
102
- return {
103
- dispose: () => {
104
- be.disposable.dispose();
105
- ArrayHelper.remove(this.eventHandlers, (e) => e.disposable === be.disposable);
106
- }
107
- };
108
- }
109
- unbindEvent(element, name, method, key) {
110
- const deleted = [];
111
- for (const be of this.eventHandlers) {
112
- if (element && be.element !== element) {
74
+ const handler = e => {
75
+ try {
76
+ let r = method(e);
77
+ e.executed = true;
78
+ if (r) {
79
+ const originalReturn = r;
80
+ r = r.then ? r : Promise.resolve(r);
81
+ e.promise = e.promise ? e.promise.then(() => r) : r;
82
+ if (originalReturn.catch) {
83
+ return originalReturn.catch(c => {
84
+ if (CancelToken.isCancelled(c ?? "Unknown error")) {
113
85
  return;
114
- }
115
- if (key && be.key !== key) {
116
- return;
117
- }
118
- if (name && be.name !== name) {
119
- return;
120
- }
121
- if (method && be.handler !== method) {
122
- return;
123
- }
124
- be.disposable.dispose();
125
- be.handler = null;
126
- be.element = null;
127
- be.name = null;
128
- be.key = null;
129
- deleted.push(() => this.eventHandlers.remove(be));
130
- }
131
- for (const iterator of deleted) {
132
- iterator();
133
- }
86
+ }
87
+ alert(c.stack ?? c);
88
+ });
89
+ }
90
+ return r;
91
+ }
92
+ } catch (error) {
93
+ if (CancelToken.isCancelled(error)) {
94
+ return;
95
+ }
96
+ alert(error.stack ?? error);
97
+ }
98
+ };
99
+ element.addEventListener(name, handler, capture);
100
+ be.disposable = {
101
+ dispose: () => {
102
+ element.removeEventListener(name, handler, capture);
103
+ be.disposable.dispose = () => undefined;
104
+ }
105
+ };
106
+ this.eventHandlers.push(be);
107
+ return {
108
+ dispose: () => {
109
+ be.disposable.dispose();
110
+ ArrayHelper.remove(this.eventHandlers, e => e.disposable === be.disposable);
111
+ }
112
+ };
113
+ }
114
+ unbindEvent(element, name, method, key) {
115
+ const deleted = [];
116
+ for (const be of this.eventHandlers) {
117
+ if (element && be.element !== element) {
118
+ return;
119
+ }
120
+ if (key && be.key !== key) {
121
+ return;
122
+ }
123
+ if (name && be.name !== name) {
124
+ return;
125
+ }
126
+ if (method && be.handler !== method) {
127
+ return;
128
+ }
129
+ be.disposable.dispose();
130
+ be.handler = null;
131
+ be.element = null;
132
+ be.name = null;
133
+ be.key = null;
134
+ deleted.push(() => this.eventHandlers.remove(be));
134
135
  }
135
- hasProperty(name) {
136
- if (/^(data|viewModel|localViewModel|element)$/.test(name)) {
137
- return true;
138
- }
139
- const map = PropertyMap.from(this);
140
- if (map.map[name]) {
141
- return true;
142
- }
143
- if (this[name] !== undefined) {
144
- return true;
145
- }
146
- return false;
136
+ for (const iterator of deleted) {
137
+ iterator();
147
138
  }
148
- setPrimitiveValue(element, name, value) {
149
- const p = value;
150
- if (p && p.then && p.catch) {
151
- console.warn(`Do not bind promises, instead use Bind.oneWayAsync`);
152
- this.mPendingPromises[name] = p;
153
- p.then((r) => {
154
- if (this.mPendingPromises[name] !== p) {
155
- return;
156
- }
157
- this.mPendingPromises[name] = null;
158
- this.setPrimitiveValue(element, name, r);
159
- }).catch((e) => {
160
- if (this.mPendingPromises[name] !== p) {
161
- return;
162
- }
163
- this.mPendingPromises[name] = null;
164
- console.error(e);
165
- });
166
- return;
167
- }
168
- if (/^(viewModel|localViewModel)$/.test(name)) {
169
- this[name] = value;
170
- return;
171
- }
172
- if ((!element || element === this.element) && this.hasProperty(name)) {
173
- this.runAfterInit(() => {
174
- this[name] = value;
175
- });
176
- }
177
- else {
178
- this.setElementValue(element, name, value);
179
- }
139
+ }
140
+ hasProperty(name) {
141
+ if (/^(data|viewModel|localViewModel|element)$/.test(name)) {
142
+ return true;
180
143
  }
181
- setLocalValue(element, name, value) {
182
- const p = value;
183
- if (p && p.then && p.catch) {
184
- console.warn(`Do not bind promises, instead use Bind.oneWayAsync`);
185
- this.mPendingPromises[name] = p;
186
- p.then((r) => {
187
- if (this.mPendingPromises[name] !== p) {
188
- return;
189
- }
190
- this.mPendingPromises[name] = null;
191
- this.setLocalValue(element, name, r);
192
- }).catch((e) => {
193
- if (this.mPendingPromises[name] !== p) {
194
- return;
195
- }
196
- this.mPendingPromises[name] = null;
197
- console.error(e);
198
- });
199
- return;
200
- }
201
- if ((!element || element === this.element) && Reflect.has(this, name)) {
202
- this[name] = value;
203
- }
204
- else {
205
- this.setElementValue(element, name, value);
206
- }
144
+ const map = PropertyMap.from(this);
145
+ if (map.map[name]) {
146
+ return true;
207
147
  }
208
- dispose(e) {
209
- if (this.mInvalidated) {
210
- clearTimeout(this.mInvalidated);
211
- this.mInvalidated = 0;
212
- }
213
- visitDescendents(e || this.element, (ex, ac) => {
214
- if (ac) {
215
- ac.dispose();
216
- return false;
217
- }
218
- return true;
219
- });
220
- if (!e) {
221
- this.unbindEvent(null, null, null);
222
- for (const binding of this.bindings) {
223
- binding.dispose();
224
- }
225
- this.bindings.length = 0;
226
- this.bindings = null;
227
- const e1 = this.element;
228
- if (typeof e1.dispose === "function") {
229
- e1.dispose();
230
- }
231
- this.element = null;
232
- const lvm = this.localViewModel;
233
- if (lvm && lvm.dispose) {
234
- lvm.dispose();
235
- this.localViewModel = null;
236
- }
237
- const vm = this.viewModel;
238
- if (vm && vm.dispose) {
239
- vm.dispose();
240
- this.viewModel = null;
241
- }
242
- this.disposables.dispose();
243
- this.pendingInits = null;
244
- }
148
+ if (this[name] !== undefined) {
149
+ return true;
245
150
  }
246
- onPropertyChanged(name) {
151
+ return false;
152
+ }
153
+ setPrimitiveValue(element, name, value) {
154
+ const p = value;
155
+ if (p && p.then && p.catch) {
156
+ console.warn(`Do not bind promises, instead use Bind.oneWayAsync`);
157
+ this.mPendingPromises[name] = p;
158
+ p.then(r => {
159
+ if (this.mPendingPromises[name] !== p) {
160
+ return;
161
+ }
162
+ this.mPendingPromises[name] = null;
163
+ this.setPrimitiveValue(element, name, r);
164
+ }).catch(e => {
165
+ if (this.mPendingPromises[name] !== p) {
166
+ return;
167
+ }
168
+ this.mPendingPromises[name] = null;
169
+ console.error(e);
170
+ });
171
+ return;
247
172
  }
248
- beginEdit() {
249
- this.pendingInits = [];
250
- const a = this.pendingInits;
251
- return {
252
- dispose: () => {
253
- if (this.pendingInits == null) {
254
- return;
255
- }
256
- this.pendingInits = null;
257
- if (a) {
258
- for (const iterator of a) {
259
- iterator();
260
- }
261
- }
262
- this.invalidate();
263
- }
264
- };
173
+ if (/^(viewModel|localViewModel)$/.test(name)) {
174
+ this[name] = value;
175
+ return;
265
176
  }
266
- invalidate() {
267
- if (this.mInvalidated) {
268
- clearTimeout(this.mInvalidated);
269
- }
270
- this.mInvalidated = setTimeout(() => {
271
- this.mInvalidated = 0;
272
- this.app.callLater(() => {
273
- this.onUpdateUI();
274
- });
275
- }, 5);
177
+ if ((!element || element === this.element) && this.hasProperty(name)) {
178
+ this.runAfterInit(() => {
179
+ this[name] = value;
180
+ });
181
+ } else {
182
+ this.setElementValue(element, name, value);
276
183
  }
277
- onUpdateUI() {
184
+ }
185
+ setLocalValue(element, name, value) {
186
+ const p = value;
187
+ if (p && p.then && p.catch) {
188
+ console.warn(`Do not bind promises, instead use Bind.oneWayAsync`);
189
+ this.mPendingPromises[name] = p;
190
+ p.then(r => {
191
+ if (this.mPendingPromises[name] !== p) {
192
+ return;
193
+ }
194
+ this.mPendingPromises[name] = null;
195
+ this.setLocalValue(element, name, r);
196
+ }).catch(e => {
197
+ if (this.mPendingPromises[name] !== p) {
198
+ return;
199
+ }
200
+ this.mPendingPromises[name] = null;
201
+ console.error(e);
202
+ });
203
+ return;
278
204
  }
279
- runAfterInit(f) {
280
- if (this.pendingInits) {
281
- this.pendingInits.push(f);
282
- }
283
- else {
284
- f();
285
- }
205
+ if ((!element || element === this.element) && Reflect.has(this, name)) {
206
+ this[name] = value;
207
+ } else {
208
+ this.setElementValue(element, name, value);
286
209
  }
287
- registerDisposable(d) {
288
- return this.disposables.add(d);
210
+ }
211
+ dispose(e) {
212
+ if (this.mInvalidated) {
213
+ clearTimeout(this.mInvalidated);
214
+ this.mInvalidated = 0;
289
215
  }
290
- render(node, e = this.element, creator = this.creator || this) {
291
- const app = this.app;
292
- const attr = node.attributes;
293
- if (attr) {
294
- for (const key in attr) {
295
- if (attr.hasOwnProperty(key)) {
296
- const item = attr[key];
297
- const isObject = typeof item === "object";
298
- if (isObject && item !== null) {
299
- const localSymbol = item[localBindSymbol];
300
- if (localSymbol) {
301
- localSymbol(key, this, e, creator);
302
- continue;
303
- }
304
- const localXNode = item[localXNodeSymbol];
305
- if (localXNode) {
306
- if (item.isTemplate) {
307
- this.setLocalValue(e, key, this.toTemplate(app, item, creator));
308
- continue;
309
- }
310
- this.setLocalValue(e, key, this.createNode(app, null, item, creator));
311
- continue;
312
- }
313
- }
314
- this.setLocalValue(e, key, item);
315
- }
316
- }
317
- }
318
- const children = node.children;
319
- if (children === void 0) {
320
- return;
321
- }
322
- for (const iterator of children) {
323
- if (!iterator) {
324
- continue;
325
- }
326
- if (!iterator[localXNodeSymbol]) {
327
- e.appendChild(document.createTextNode(iterator.toString()));
328
- continue;
329
- }
330
- if (iterator.isProperty) {
331
- if (iterator.isTemplate) {
332
- this.setLocalValue(e, iterator.name, this.toTemplate(app, iterator.children[0], creator));
333
- continue;
334
- }
335
- this.createNode(app, e, iterator, creator);
336
- continue;
337
- }
338
- const t = iterator.attributes && iterator.attributes.template;
339
- if (t) {
340
- console.warn(`This path is deprecated, check who is calling it.`);
341
- this.setLocalValue(e, t, this.toTemplate(app, iterator, creator));
342
- continue;
343
- }
344
- this.createNode(app, e, iterator, creator);
345
- }
216
+ visitDescendents(e || this.element, (ex, ac) => {
217
+ if (ac) {
218
+ ac.dispose();
219
+ return false;
220
+ }
221
+ return true;
222
+ });
223
+ if (!e) {
224
+ this.unbindEvent(null, null, null);
225
+ for (const binding of this.bindings) {
226
+ binding.dispose();
227
+ }
228
+ this.bindings.length = 0;
229
+ this.bindings = null;
230
+ const e1 = this.element;
231
+ if (typeof e1.dispose === "function") {
232
+ e1.dispose();
233
+ }
234
+ this.element = null;
235
+ const lvm = this.localViewModel;
236
+ if (lvm && lvm.dispose) {
237
+ lvm.dispose();
238
+ this.localViewModel = null;
239
+ }
240
+ const vm = this.viewModel;
241
+ if (vm && vm.dispose) {
242
+ vm.dispose();
243
+ this.viewModel = null;
244
+ }
245
+ this.disposables.dispose();
246
+ this.pendingInits = null;
346
247
  }
347
- extractControlProperties(x, name = "div") {
348
- const a = x.attributes;
349
- const extracted = {};
350
- if (typeof x.name === "function" && this instanceof x.name) {
351
- x.name = name;
352
- }
248
+ }
249
+ onPropertyChanged(name) {}
250
+ beginEdit() {
251
+ this.pendingInits = [];
252
+ const a = this.pendingInits;
253
+ return {
254
+ dispose: () => {
255
+ if (this.pendingInits == null) {
256
+ return;
257
+ }
258
+ this.pendingInits = null;
353
259
  if (a) {
354
- for (const key in a) {
355
- if (Object.prototype.hasOwnProperty.call(a, key)) {
356
- if (Reflect.has(this, key)) {
357
- const element = a[key];
358
- extracted[key] = element;
359
- delete a[key];
360
- }
361
- }
260
+ for (const iterator of a) {
261
+ iterator();
262
+ }
263
+ }
264
+ this.invalidate();
265
+ }
266
+ };
267
+ }
268
+ invalidate() {
269
+ if (this.mInvalidated) {
270
+ clearTimeout(this.mInvalidated);
271
+ }
272
+ this.mInvalidated = setTimeout(() => {
273
+ this.mInvalidated = 0;
274
+ this.app.callLater(() => {
275
+ this.onUpdateUI();
276
+ });
277
+ }, 5);
278
+ }
279
+ onUpdateUI() {}
280
+ runAfterInit(f) {
281
+ if (this.pendingInits) {
282
+ this.pendingInits.push(f);
283
+ } else {
284
+ f();
285
+ }
286
+ }
287
+ registerDisposable(d) {
288
+ return this.disposables.add(d);
289
+ }
290
+ render(node, e = this.element, creator = this.creator || this) {
291
+ const app = this.app;
292
+ const attr = node.attributes;
293
+ if (attr) {
294
+ for (const key in attr) {
295
+ if (attr.hasOwnProperty(key)) {
296
+ const item = attr[key];
297
+ const isObject = typeof item === "object";
298
+ if (isObject && item !== null) {
299
+ const localSymbol = item[localBindSymbol];
300
+ if (localSymbol) {
301
+ localSymbol(key, this, e, creator);
302
+ continue;
303
+ }
304
+ const localXNode = item[localXNodeSymbol];
305
+ if (localXNode) {
306
+ if (item.isTemplate) {
307
+ this.setLocalValue(e, key, this.toTemplate(app, item, creator));
308
+ continue;
309
+ }
310
+ this.setLocalValue(e, key, this.createNode(app, null, item, creator));
311
+ continue;
362
312
  }
313
+ }
314
+ this.setLocalValue(e, key, item);
363
315
  }
364
- return extracted;
316
+ }
365
317
  }
366
- create() {
318
+ const children = node.children;
319
+ if (children === void 0) {
320
+ return;
367
321
  }
368
- preCreate() {
322
+ for (const iterator of children) {
323
+ if (!iterator) {
324
+ continue;
325
+ }
326
+ if (!iterator[localXNodeSymbol]) {
327
+ e.appendChild(document.createTextNode(iterator.toString()));
328
+ continue;
329
+ }
330
+ if (iterator.isProperty) {
331
+ if (iterator.isTemplate) {
332
+ this.setLocalValue(e, iterator.name, this.toTemplate(app, iterator.children[0], creator));
333
+ continue;
334
+ }
335
+ this.createNode(app, e, iterator, creator);
336
+ continue;
337
+ }
338
+ const t = iterator.attributes && iterator.attributes.template;
339
+ if (t) {
340
+ console.warn(`This path is deprecated, check who is calling it.`);
341
+ this.setLocalValue(e, t, this.toTemplate(app, iterator, creator));
342
+ continue;
343
+ }
344
+ this.createNode(app, e, iterator, creator);
369
345
  }
370
- setElementValue(element, name, value) {
371
- element[name] = value;
346
+ }
347
+ extractControlProperties(x, name = "div") {
348
+ const a = x.attributes;
349
+ const extracted = {};
350
+ if (typeof x.name === "function" && this instanceof x.name) {
351
+ x.name = name;
372
352
  }
373
- resolve(c, selfName) {
374
- const result = this.app.resolve(c, true);
375
- if (selfName) {
376
- if (typeof selfName === "function") {
377
- this.runAfterInit(() => {
378
- const v = selfName();
379
- if (v) {
380
- for (const key in v) {
381
- if (v.hasOwnProperty(key)) {
382
- const element = v[key];
383
- result[key] = element;
384
- }
385
- }
386
- }
387
- });
388
- }
389
- else {
390
- result[selfName] = this;
391
- }
392
- }
393
- return result;
353
+ if (a) {
354
+ for (const key in a) {
355
+ if (Object.prototype.hasOwnProperty.call(a, key)) {
356
+ if (Reflect.has(this, key)) {
357
+ const element = a[key];
358
+ extracted[key] = element;
359
+ delete a[key];
360
+ }
361
+ }
362
+ }
394
363
  }
395
- pushInit() {
364
+ return extracted;
365
+ }
366
+ create() {}
367
+ preCreate() {}
368
+ setElementValue(element, name, value) {
369
+ element[name] = value;
370
+ }
371
+ resolve(c, selfName) {
372
+ const result = this.app.resolve(c, true);
373
+ if (selfName) {
374
+ if (typeof selfName === "function") {
396
375
  this.runAfterInit(() => {
397
- this.init?.()?.catch((error) => CancelToken.isCancelled(error) ? void 0 : console.error(error));
376
+ const v = selfName();
377
+ if (v) {
378
+ for (const key in v) {
379
+ if (v.hasOwnProperty(key)) {
380
+ const element = v[key];
381
+ result[key] = element;
382
+ }
383
+ }
384
+ }
398
385
  });
386
+ } else {
387
+ result[selfName] = this;
388
+ }
399
389
  }
390
+ return result;
391
+ }
392
+ pushInit() {
393
+ this.runAfterInit(() => {
394
+ this.init?.()?.catch(error => CancelToken.isCancelled(error) ? void 0 : console.error(error));
395
+ });
396
+ }
400
397
  };
401
- __decorate([
402
- InheritedProperty,
403
- __metadata("design:type", Object)
404
- ], AtomComponent.prototype, "data", void 0);
405
- __decorate([
406
- InheritedProperty,
407
- __metadata("design:type", Object)
408
- ], AtomComponent.prototype, "viewModel", void 0);
409
- __decorate([
410
- InheritedProperty,
411
- __metadata("design:type", Object)
412
- ], AtomComponent.prototype, "localViewModel", void 0);
413
- AtomComponent = __decorate([
414
- __param(0, Inject),
415
- __metadata("design:paramtypes", [App, Object])
416
- ], AtomComponent);
398
+ __decorate([InheritedProperty, __metadata("design:type", Object)], AtomComponent.prototype, "data", void 0);
399
+ __decorate([InheritedProperty, __metadata("design:type", Object)], AtomComponent.prototype, "viewModel", void 0);
400
+ __decorate([InheritedProperty, __metadata("design:type", Object)], AtomComponent.prototype, "localViewModel", void 0);
401
+ AtomComponent = __decorate([__param(0, Inject), __metadata("design:paramtypes", [App, Object])], AtomComponent);
417
402
  export { AtomComponent };
418
403
  export class PropertyBinding {
419
- constructor(target, element, name, path, twoWays, valueFunc, source) {
420
- this.target = target;
421
- this.element = element;
422
- this.name = name;
423
- this.twoWays = twoWays;
424
- this.source = source;
425
- this.isTwoWaySetup = false;
426
- this.name = name;
427
- this.twoWays = twoWays;
428
- this.target = target;
429
- this.element = element;
430
- this.isRunning = false;
431
- if (valueFunc) {
432
- if (typeof valueFunc !== "function") {
433
- this.fromSourceToTarget = valueFunc.fromSource;
434
- this.fromTargetToSource = valueFunc.fromTarget;
435
- }
436
- else {
437
- this.fromSourceToTarget = valueFunc;
438
- }
439
- }
440
- this.watcher = new AtomWatcher(target, path, (...v) => {
441
- if (this.isRunning) {
442
- return;
443
- }
444
- if (this.disposed) {
445
- return;
446
- }
447
- for (const iterator of v) {
448
- if (iterator === undefined) {
449
- return;
450
- }
451
- }
452
- const cv = this.fromSourceToTarget ? this.fromSourceToTarget.apply(this, v) : v[0];
453
- if (cv === ignoreValue) {
454
- return;
455
- }
456
- this.isRunning = true;
457
- try {
458
- if (this.target instanceof AtomComponent) {
459
- this.target.setLocalValue(this.element, this.name, cv);
460
- }
461
- else {
462
- this.target[name] = cv;
463
- }
464
- }
465
- finally {
466
- this.isRunning = false;
467
- }
468
- }, source);
469
- this.path = this.watcher.path;
470
- if (this.target instanceof AtomComponent) {
471
- this.target.runAfterInit(() => {
472
- if (!this.watcher) {
473
- return;
474
- }
475
- this.watcher.init(true);
476
- if (twoWays) {
477
- this.setupTwoWayBinding();
478
- }
479
- });
480
- }
481
- else {
482
- this.watcher.init(true);
483
- if (twoWays) {
484
- this.setupTwoWayBinding();
485
- }
486
- }
404
+ constructor(target, element, name, path, twoWays, valueFunc, source) {
405
+ this.target = target;
406
+ this.element = element;
407
+ this.name = name;
408
+ this.twoWays = twoWays;
409
+ this.source = source;
410
+ this.isTwoWaySetup = false;
411
+ this.name = name;
412
+ this.twoWays = twoWays;
413
+ this.target = target;
414
+ this.element = element;
415
+ this.isRunning = false;
416
+ if (valueFunc) {
417
+ if (typeof valueFunc !== "function") {
418
+ this.fromSourceToTarget = valueFunc.fromSource;
419
+ this.fromTargetToSource = valueFunc.fromTarget;
420
+ } else {
421
+ this.fromSourceToTarget = valueFunc;
422
+ }
487
423
  }
488
- setupTwoWayBinding() {
424
+ this.watcher = new AtomWatcher(target, path, (...v) => {
425
+ if (this.isRunning) {
426
+ return;
427
+ }
428
+ if (this.disposed) {
429
+ return;
430
+ }
431
+ for (const iterator of v) {
432
+ if (iterator === undefined) {
433
+ return;
434
+ }
435
+ }
436
+ const cv = this.fromSourceToTarget ? this.fromSourceToTarget.apply(this, v) : v[0];
437
+ if (cv === ignoreValue) {
438
+ return;
439
+ }
440
+ this.isRunning = true;
441
+ try {
489
442
  if (this.target instanceof AtomComponent) {
490
- if (this.element
491
- && (this.element !== this.target.element || !this.target.hasProperty(this.name))) {
492
- let events = [];
493
- if (typeof this.twoWays !== "boolean") {
494
- events = this.twoWays;
495
- }
496
- this.twoWaysDisposable = watchProperty(this.element, this.name, events, (v) => {
497
- this.setInverseValue(v);
498
- });
499
- return;
500
- }
443
+ this.target.setLocalValue(this.element, this.name, cv);
444
+ } else {
445
+ this.target[name] = cv;
501
446
  }
502
- const watcher = new AtomWatcher(this.target, [[this.name]], (...values) => {
503
- if (this.isTwoWaySetup) {
504
- this.setInverseValue(values[0]);
505
- }
447
+ } finally {
448
+ this.isRunning = false;
449
+ }
450
+ }, source);
451
+ this.path = this.watcher.path;
452
+ if (this.target instanceof AtomComponent) {
453
+ this.target.runAfterInit(() => {
454
+ if (!this.watcher) {
455
+ return;
456
+ }
457
+ this.watcher.init(true);
458
+ if (twoWays) {
459
+ this.setupTwoWayBinding();
460
+ }
461
+ });
462
+ } else {
463
+ this.watcher.init(true);
464
+ if (twoWays) {
465
+ this.setupTwoWayBinding();
466
+ }
467
+ }
468
+ }
469
+ setupTwoWayBinding() {
470
+ if (this.target instanceof AtomComponent) {
471
+ if (this.element && (this.element !== this.target.element || !this.target.hasProperty(this.name))) {
472
+ let events = [];
473
+ if (typeof this.twoWays !== "boolean") {
474
+ events = this.twoWays;
475
+ }
476
+ this.twoWaysDisposable = watchProperty(this.element, this.name, events, v => {
477
+ this.setInverseValue(v);
506
478
  });
507
- watcher.init(true);
508
- this.isTwoWaySetup = true;
509
- this.twoWaysDisposable = watcher;
479
+ return;
480
+ }
510
481
  }
511
- setInverseValue(value) {
512
- if (!this.twoWays) {
513
- throw new Error("This Binding is not two ways.");
514
- }
515
- if (this.disposed) {
516
- return;
517
- }
518
- if (this.isRunning) {
519
- return;
520
- }
521
- this.isRunning = true;
522
- try {
523
- const first = this.path[0];
524
- const length = first.length;
525
- let v = this.target;
526
- let i = 0;
527
- let name;
528
- for (i = 0; i < length - 1; i++) {
529
- name = first[i].name;
530
- if (name === "this") {
531
- v = this.source || this.target;
532
- }
533
- else {
534
- v = v[name];
535
- }
536
- if (!v) {
537
- return;
538
- }
539
- }
540
- name = first[i].name;
541
- v[name] = this.fromTargetToSource ? this.fromTargetToSource.call(this, value) : value;
542
- }
543
- finally {
544
- this.isRunning = false;
545
- }
482
+ const watcher = new AtomWatcher(this.target, [[this.name]], (...values) => {
483
+ if (this.isTwoWaySetup) {
484
+ this.setInverseValue(values[0]);
485
+ }
486
+ });
487
+ watcher.init(true);
488
+ this.isTwoWaySetup = true;
489
+ this.twoWaysDisposable = watcher;
490
+ }
491
+ setInverseValue(value) {
492
+ if (!this.twoWays) {
493
+ throw new Error("This Binding is not two ways.");
494
+ }
495
+ if (this.disposed) {
496
+ return;
497
+ }
498
+ if (this.isRunning) {
499
+ return;
546
500
  }
547
- dispose() {
548
- this.twoWaysDisposable?.dispose();
549
- this.twoWaysDisposable = undefined;
550
- this.watcher.dispose();
551
- this.disposed = true;
552
- this.watcher = null;
501
+ this.isRunning = true;
502
+ try {
503
+ const first = this.path[0];
504
+ const length = first.length;
505
+ let v = this.target;
506
+ let i = 0;
507
+ let name;
508
+ for (i = 0; i < length - 1; i++) {
509
+ name = first[i].name;
510
+ if (name === "this") {
511
+ v = this.source || this.target;
512
+ } else {
513
+ v = v[name];
514
+ }
515
+ if (!v) {
516
+ return;
517
+ }
518
+ }
519
+ name = first[i].name;
520
+ v[name] = this.fromTargetToSource ? this.fromTargetToSource.call(this, value) : value;
521
+ } finally {
522
+ this.isRunning = false;
553
523
  }
554
- }
555
- //# sourceMappingURL=AtomComponent.js.map
524
+ }
525
+ dispose() {
526
+ this.twoWaysDisposable?.dispose();
527
+ this.twoWaysDisposable = undefined;
528
+ this.watcher.dispose();
529
+ this.disposed = true;
530
+ this.watcher = null;
531
+ }
532
+ }