neo.mjs 8.8.0 → 8.9.1

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.
@@ -20,9 +20,9 @@ class ServiceWorker extends ServiceBase {
20
20
  */
21
21
  singleton: true,
22
22
  /**
23
- * @member {String} version='8.8.0'
23
+ * @member {String} version='8.9.1'
24
24
  */
25
- version: '8.8.0'
25
+ version: '8.9.1'
26
26
  }
27
27
 
28
28
  /**
@@ -107,7 +107,7 @@ class FooterContainer extends Container {
107
107
  }, {
108
108
  module: Component,
109
109
  cls : ['neo-version'],
110
- html : 'v8.8.0'
110
+ html : 'v8.9.1'
111
111
  }]
112
112
  }],
113
113
  /**
@@ -20,9 +20,9 @@ class ServiceWorker extends ServiceBase {
20
20
  */
21
21
  singleton: true,
22
22
  /**
23
- * @member {String} version='8.8.0'
23
+ * @member {String} version='8.9.1'
24
24
  */
25
- version: '8.8.0'
25
+ version: '8.9.1'
26
26
  }
27
27
 
28
28
  /**
@@ -33,8 +33,8 @@ class Viewport extends BaseViewport {
33
33
 
34
34
  items: ['->', {
35
35
  handler: 'up.onSwitchThemeButtonClick',
36
- iconCls: 'fas fa-moon',
37
- text : 'Dark Theme'
36
+ iconCls: 'fas fa-sun',
37
+ text : 'Light Theme'
38
38
  }]
39
39
  }, {
40
40
  module: GridContainer,
@@ -133,7 +133,7 @@ class Viewport extends BaseViewport {
133
133
  onSwitchThemeButtonClick(data) {
134
134
  let me = this,
135
135
  button = data.component,
136
- isDarkTheme = me.theme === 'neo-theme-dark',
136
+ isDarkTheme = me.theme !== 'neo-theme-light',
137
137
  theme = isDarkTheme ? 'neo-theme-light' : 'neo-theme-dark';
138
138
 
139
139
  button.set({
@@ -3,5 +3,6 @@
3
3
  "basePath" : "../../../",
4
4
  "environment" : "development",
5
5
  "mainPath" : "./Main.mjs",
6
- "mainThreadAddons": ["DragDrop", "Navigator", "ResizeObserver", "Stylesheet"]
6
+ "mainThreadAddons": ["DragDrop", "Navigator", "ResizeObserver", "Stylesheet"],
7
+ "themes" : ["neo-theme-dark", "neo-theme-light"]
7
8
  }
@@ -33,8 +33,8 @@ class Viewport extends BaseViewport {
33
33
 
34
34
  items: ['->', {
35
35
  handler: 'up.onSwitchThemeButtonClick',
36
- iconCls: 'fas fa-moon',
37
- text : 'Dark Theme'
36
+ iconCls: 'fas fa-sun',
37
+ text : 'Light Theme'
38
38
  }]
39
39
  }, {
40
40
  module: TableContainer,
@@ -129,7 +129,7 @@ class Viewport extends BaseViewport {
129
129
  onSwitchThemeButtonClick(data) {
130
130
  let me = this,
131
131
  button = data.component,
132
- isDarkTheme = me.theme === 'neo-theme-dark',
132
+ isDarkTheme = me.theme !== 'neo-theme-light',
133
133
  theme = isDarkTheme ? 'neo-theme-light' : 'neo-theme-dark';
134
134
 
135
135
  button.set({
@@ -2,5 +2,6 @@
2
2
  "appPath" : "examples/table/nestedRecordFields/app.mjs",
3
3
  "basePath" : "../../../",
4
4
  "environment": "development",
5
- "mainPath" : "./Main.mjs"
5
+ "mainPath" : "./Main.mjs",
6
+ "themes" : ["neo-theme-dark", "neo-theme-light"]
6
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo.mjs",
3
- "version": "8.8.0",
3
+ "version": "8.9.1",
4
4
  "description": "The webworkers driven UI framework",
5
5
  "type": "module",
6
6
  "repository": {
@@ -262,12 +262,12 @@ const DefaultConfig = {
262
262
  useVdomWorker: true,
263
263
  /**
264
264
  * buildScripts/injectPackageVersion.mjs will update this value
265
- * @default '8.8.0'
265
+ * @default '8.9.1'
266
266
  * @memberOf! module:Neo
267
267
  * @name config.version
268
268
  * @type String
269
269
  */
270
- version: '8.8.0'
270
+ version: '8.9.1'
271
271
  };
272
272
 
273
273
  Object.assign(DefaultConfig, {
@@ -970,12 +970,24 @@ class Component extends Base {
970
970
  */
971
971
  afterSetTheme(value, oldValue) {
972
972
  if (value || oldValue !== undefined) {
973
- let cls = this.cls;
973
+ let me = this,
974
+ {cls} = me,
975
+ needsUpdate = false;
974
976
 
975
- NeoArray.remove(cls, oldValue);
976
- value && NeoArray.add(cls, value);
977
+ if (oldValue && cls.includes(oldValue)) {
978
+ NeoArray.remove(cls, oldValue);
979
+ needsUpdate = true
980
+ }
977
981
 
978
- this.cls = cls
982
+ // We do not need to add a DOM based CSS selector, in case the theme is already inherited
983
+ if (value !== me.parent?.theme) {
984
+ value && NeoArray.add(cls, value);
985
+ needsUpdate = true
986
+ }
987
+
988
+ if (needsUpdate) {
989
+ me.cls = cls
990
+ }
979
991
  }
980
992
  }
981
993
 
@@ -1672,7 +1684,7 @@ class Component extends Base {
1672
1684
  * Convenience shortcut
1673
1685
  * @param {String[]|String} id=this.id
1674
1686
  * @param {String} appName=this.appName
1675
- * @returns {Promise<Neo.util.Rectangle>}
1687
+ * @returns {Promise<Neo.util.Rectangle||Neo.util.Rectangle[]>}
1676
1688
  */
1677
1689
  async getDomRect(id=this.id, appName=this.appName) {
1678
1690
  let result = await Neo.main.DomAccess.getBoundingClientRect({appName, id, windowId: this.windowId});
@@ -1684,6 +1696,42 @@ class Component extends Base {
1684
1696
  return Rectangle.clone(result)
1685
1697
  }
1686
1698
 
1699
+ /**
1700
+ * In case you are sure a DOMRect exists, use getDomRect()
1701
+ * Otherwise you can wait for it using this method.
1702
+ * @example:
1703
+ * await this.render(true);
1704
+ * await this.waitForDomRect();
1705
+ * @param {Object} opts
1706
+ * @param {String} opts.appName=this.appName
1707
+ * @param {Number} opts.attempts=10 Reruns in case the rect height or width equals 0
1708
+ * @param {Number} opts.delay=50 Time in ms before checking again
1709
+ * @param {String[]|String} opts.id=this.id
1710
+ * @returns {Promise<Neo.util.Rectangle||Neo.util.Rectangle[]>}
1711
+ */
1712
+ async waitForDomRect({appName=this.appName, attempts=10, delay=50, id=this.id}) {
1713
+ let me = this,
1714
+ result = await me.getDomRect(id, appName),
1715
+ reRun = false;
1716
+
1717
+ if (Array.isArray(result)) {
1718
+ result.forEach(rect => {
1719
+ if (rect.height < 1 || rect.width < 1) {
1720
+ reRun = true
1721
+ }
1722
+ })
1723
+ } else if (result.height < 1 || result.width < 1) {
1724
+ reRun = true
1725
+ }
1726
+
1727
+ if (reRun && attempts > 0) {
1728
+ await me.timeout(delay);
1729
+ return await me.waitForDomRect({appName, attempts: attempts-1, delay, id})
1730
+ }
1731
+
1732
+ return result
1733
+ }
1734
+
1687
1735
  /**
1688
1736
  * Honors different item roots for mount / render OPs
1689
1737
  * @returns {String}
@@ -216,6 +216,22 @@ class Container extends Component {
216
216
  }
217
217
  }
218
218
 
219
+ /**
220
+ * Triggered after the theme config got changed
221
+ * @param {String|null} value
222
+ * @param {String|null} oldValue
223
+ * @protected
224
+ */
225
+ afterSetTheme(value, oldValue) {
226
+ super.afterSetTheme(value, oldValue);
227
+
228
+ value && this.items?.forEach(item => {
229
+ if (!Neo.isString(item)) {
230
+ item.theme = value
231
+ }
232
+ })
233
+ }
234
+
219
235
  /**
220
236
  * Triggered after the windowId config got changed
221
237
  * @param {Number|null} value
@@ -411,11 +411,23 @@ class Dialog extends Panel {
411
411
 
412
412
  rect = await me.getDomRect(me.animateTargetId);
413
413
 
414
+ if (style.left || style.top) {
415
+ let tempStyle = {...style};
416
+
417
+ // Ensure that the initial mounting happens outside the visible area
418
+ delete style.left;
419
+ delete style.top;
420
+
421
+ me.style = style;
422
+
423
+ // Silent update & ensure that a given starting position won't get lost
424
+ me._style = style = tempStyle
425
+ }
426
+
414
427
  // rendered outside the visible area
415
428
  await me.render(true);
416
- await me.timeout(150);
417
429
 
418
- let [dialogRect, bodyRect] = await me.getDomRect([me.id, 'document.body']);
430
+ let [dialogRect, bodyRect] = await me.waitForDomRect({id: [me.id, 'document.body']});
419
431
 
420
432
  // Move to cover the animation target
421
433
  await Neo.applyDeltas(appName, {