neo.mjs 4.0.44 → 4.0.47

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.
@@ -174,7 +174,7 @@ if (programOpts.info) {
174
174
  appPath : `${insideNeo ? '' : '../../'}${appPath}app.mjs`,
175
175
  basePath : '../../',
176
176
  environment: 'development',
177
- mainPath : './Main.mjs'
177
+ mainPath : `${insideNeo ? './' : '../node_modules/neo.mjs/src/'}Main.mjs`
178
178
  };
179
179
 
180
180
  if (!(mainThreadAddons.includes('DragDrop') && mainThreadAddons.includes('Stylesheet') && mainThreadAddons.length === 2)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo.mjs",
3
- "version": "4.0.44",
3
+ "version": "4.0.47",
4
4
  "description": "The webworkers driven UI framework",
5
5
  "type": "module",
6
6
  "repository": {
@@ -1007,7 +1007,7 @@ class Base extends CoreBase {
1007
1007
  * @returns {Promise<*>}
1008
1008
  */
1009
1009
  getDomRect(id=this.id, appName=this.appName) {
1010
- return Neo.main.DomAccess.getBoundingClientRect({ appName, id });
1010
+ return Neo.main.DomAccess.getBoundingClientRect({appName, id});
1011
1011
  }
1012
1012
 
1013
1013
  /**
@@ -1,6 +1,8 @@
1
1
  import ClassSystemUtil from '../util/ClassSystem.mjs';
2
2
  import Component from './Base.mjs';
3
3
  import Store from '../data/Store.mjs';
4
+ import TaskManager from '../manager/Task.mjs';
5
+
4
6
 
5
7
  /**
6
8
  * @class Neo.component.Carousel
@@ -31,6 +33,14 @@ class Carousel extends Component {
31
33
  * @protected
32
34
  */
33
35
  ntype: 'carousel',
36
+ /**
37
+ * autoRun allows to run through the all items timebased
38
+ * 0 means it is turned off. Other values are the timer in ms,
39
+ * which will hide the arrows.
40
+ *
41
+ * @member {int} autoRun=0
42
+ */
43
+ autoRun_: 0,
34
44
  /**
35
45
  * @member {String[]} cls=['neo-carousel']
36
46
  */
@@ -82,6 +92,8 @@ class Carousel extends Component {
82
92
  let me = this,
83
93
  domListeners = me.domListeners;
84
94
 
95
+ if(me.autoRun) return;
96
+
85
97
  domListeners.push({
86
98
  click: {
87
99
  fn : me.onCarouselBtnClick,
@@ -93,6 +105,30 @@ class Carousel extends Component {
93
105
  me.domListeners = domListeners;
94
106
  }
95
107
 
108
+ /**
109
+ * Triggered after autoRun config got changed
110
+ * @param {boolean|integer} value
111
+ * @protected
112
+ */
113
+ afterSetAutoRun(value, oldValue) {
114
+ let me = this;
115
+
116
+ if(!value) return;
117
+
118
+ TaskManager.start({
119
+ id: this.id,
120
+ interval: value,
121
+ run: function() {
122
+ me.onCarouselBtnClick('forward');
123
+ }
124
+ });
125
+
126
+ let vdom = this._vdom;
127
+ vdom.cn[0].cn[0].removeDom = true;
128
+
129
+ this._vdom = vdom;
130
+ }
131
+
96
132
  /**
97
133
  * Triggered after the store config got changed
98
134
  * @param {Neo.data.Store|Object|null} value
@@ -188,7 +224,7 @@ class Carousel extends Component {
188
224
  */
189
225
  onCarouselBtnClick(event) {
190
226
  let me = this,
191
- action = event.target.data.carouselaction,
227
+ action = (typeof event === 'string') ? event : event.target.data.carouselaction,
192
228
  store = me.store,
193
229
  countItems = store.getCount(),
194
230
  vdom = me.vdom,
@@ -182,18 +182,30 @@ class Component extends Base {
182
182
  if (listeners) {
183
183
  Object.entries(listeners).forEach(([key, value]) => {
184
184
  if (key !== 'scope' && key !== 'delegate') {
185
- value.forEach(listener => {
186
- if (Neo.isObject(listener) && listener.hasOwnProperty('fn') && Neo.isString(listener.fn)) {
187
- eventHandler = listener.fn;
188
- handlerScope = me.getHandlerScope(eventHandler);
189
-
190
- if (!handlerScope) {
191
- Logger.logError('Unknown event handler for', eventHandler, component);
192
- } else {
193
- listener.fn = handlerScope[eventHandler].bind(handlerScope);
194
- }
185
+ if (Neo.isString(value)) {
186
+ eventHandler = value;
187
+ handlerScope = me.getHandlerScope(eventHandler);
188
+
189
+ if (!handlerScope) {
190
+ Logger.logError('Unknown event handler for', eventHandler, component);
191
+ } else {
192
+ listeners[key] = {};
193
+ listeners[key].fn = handlerScope[eventHandler].bind(handlerScope);
195
194
  }
196
- });
195
+ } else {
196
+ value.forEach(listener => {
197
+ if (Neo.isObject(listener) && listener.hasOwnProperty('fn') && Neo.isString(listener.fn)) {
198
+ eventHandler = listener.fn;
199
+ handlerScope = me.getHandlerScope(eventHandler);
200
+
201
+ if (!handlerScope) {
202
+ Logger.logError('Unknown event handler for', eventHandler, component);
203
+ } else {
204
+ listener.fn = handlerScope[eventHandler].bind(handlerScope);
205
+ }
206
+ }
207
+ });
208
+ }
197
209
  }
198
210
  });
199
211
  }
@@ -0,0 +1,54 @@
1
+ import Base from '../../core/Base.mjs';
2
+
3
+ /**
4
+ * Addon to register WebComponents
5
+ * @class Neo.main.addon.WebComponent
6
+ * @extends Neo.core.Base
7
+ * @singleton
8
+ */
9
+ class WebComponent extends Base {
10
+ static getConfig() {return {
11
+ /**
12
+ * @member {String} className='Neo.main.addon.WebComponent'
13
+ * @protected
14
+ */
15
+ className: 'Neo.main.addon.WebComponent',
16
+ /**
17
+ * @member {Boolean} singleton=true
18
+ * @protected
19
+ */
20
+ singleton: true
21
+ }}
22
+
23
+ /**
24
+ * @param {Object} config
25
+ */
26
+ construct(config) {
27
+ super.construct(config);
28
+
29
+ this.registerElementLoader();
30
+ }
31
+
32
+ /**
33
+ *
34
+ */
35
+ registerElementLoader() {
36
+ customElements.define('element-loader', class extends HTMLElement {
37
+ async connectedCallback() {
38
+ let me = this,
39
+ content = await (await fetch(me.getAttribute('src'))).text();
40
+
41
+ me.attachShadow({mode: 'open'}).innerHTML = content;
42
+ me.shadowRoot.append(me.querySelector('style'));
43
+ }
44
+ });
45
+ }
46
+ }
47
+
48
+ Neo.applyClassConfig(WebComponent);
49
+
50
+ let instance = Neo.create(WebComponent);
51
+
52
+ Neo.applyToGlobalNs(instance);
53
+
54
+ export default instance;
@@ -0,0 +1,197 @@
1
+ import Base from './Base.mjs';
2
+
3
+ /**
4
+ * @class Neo.manager.Task
5
+ * @extends Neo.manager.Base
6
+ * @singleton
7
+ *
8
+ * @example
9
+ * import TaskManager from '../../../node_modules/neo.mjs/src/manager/Task.mjs';
10
+ *
11
+ * task = {
12
+ * args: [clockDom], // arguments passed into the run fn
13
+ * addCountToArgs: true, // adds the count to the arguments
14
+ * fireOnStart: false // run before the first interval
15
+ * id: 'clockcounter', // id for the task or autocreated
16
+ * interval: 1000, // in ms
17
+ * onError: function(){}, // runs in case an error occurred
18
+ * repeat: 10, // stopAfterTenTimes
19
+ * run: function(clock) { // function to run
20
+ * clock.setHtml(new Date());
21
+ * },
22
+ * scope: this // scope of the function
23
+ * };
24
+ *
25
+ * TaskManager.start(task); // or taskId if exists
26
+ * TaskManager.stop('clockcounter', remove); // false to not remove it from the TaskManager
27
+ * TaskManager.stopAll(remove);
28
+ *
29
+ * TaskManager.createTask(task);
30
+ * TaskManager.remove(taskId);
31
+ *
32
+ * TaskManager.run(taskId);
33
+ * TaskManager.get(taskId).repeat = 20;
34
+ */
35
+ class Task extends Base {
36
+ static getConfig() {return {
37
+ /**
38
+ * @member {String} className='Neo.manager.Task'
39
+ * @protected
40
+ */
41
+ className: 'Neo.manager.Task',
42
+ /**
43
+ * @member {Boolean} singleton=true
44
+ * @protected
45
+ */
46
+ singleton: true
47
+ }}
48
+
49
+ /**
50
+ * Adds a task to collection.
51
+ * Typically used via `start(task)`
52
+ * @param {Object} task
53
+ * @returns {Object}
54
+ */
55
+ createTask(task) {
56
+ let me = this;
57
+
58
+ if (!task.id) {
59
+ task.id = Neo.core.IdGenerator.getId('task');
60
+ }
61
+
62
+ task.scope && task.run.bind(task.scope);
63
+ task.addCountToArgs && task.args.push(0);
64
+
65
+ task = {
66
+ args : [],
67
+ isRunning : false,
68
+ onError : Neo.emptyFn,
69
+ runCount : 0,
70
+ runner : null,
71
+ runOnStart: false,
72
+ ...task
73
+ };
74
+
75
+ me.register(task);
76
+
77
+ return task;
78
+ }
79
+
80
+ /**
81
+ * Removes a task from collection.
82
+ * @param {String} taskId
83
+ */
84
+ removeTask(taskId) {
85
+ this.unregister(taskId);
86
+ }
87
+
88
+ /**
89
+ * Runs a task from collection.
90
+ * @param {String} taskId
91
+ */
92
+ run(taskId) {
93
+ let me = this,
94
+ task = me.get(taskId);
95
+
96
+ if (task.isRunning) {
97
+ Neo.logError('[Neo.util.TaskManager] Task is already running');
98
+ return task;
99
+ }
100
+
101
+ try {
102
+ let fn = function(task) {
103
+ task.runCount++;
104
+
105
+ if(task.addCountToArgs) {
106
+ task.args[task.args.length - 1] = task.runCount;
107
+ }
108
+
109
+ if (task.repeat && task.runCount === task.repeat) {
110
+ me.stop(task.id);
111
+ }
112
+
113
+ task.run(...task.args);
114
+ };
115
+
116
+ task.isRunning = true;
117
+ task.runner = setInterval(fn, task.interval, task);
118
+ } catch (taskError) {
119
+ Neo.logError('[Neo.util.TaskManager] Error while running task ' + task.id);
120
+ task.onError(taskError);
121
+ task.isRunning = false;
122
+ }
123
+ }
124
+
125
+ /**
126
+ * Adds a task and runs it.
127
+ * @param {Object|String} task or taskId
128
+ * @returns {Object}
129
+ */
130
+ start(task) {
131
+ let me = this;
132
+
133
+ if (Neo.isString(task)) {
134
+ task = me.get(task);
135
+ !task && Neo.logError('[Neo.util.TaskManager] You passed a taskId which does not exits');
136
+ } else if (!task.id || !me.get(task.id)){
137
+ task = me.createTask(task);
138
+ }
139
+
140
+ if (task.isRunning) {
141
+ Neo.logError('[Neo.util.TaskManager] Task is already running');
142
+ return task;
143
+ }
144
+
145
+ if (task.runOnStart) {
146
+ task.runCount++;
147
+ task.run(...task.args);
148
+ }
149
+
150
+ me.run(task.id);
151
+
152
+ return task;
153
+ }
154
+
155
+ /**
156
+ * Stops a task and resets configs.
157
+ * If remove is true it will remove the task from the collection
158
+ * @param {String} taskId
159
+ * @param {Boolean} remove
160
+ */
161
+ stop(taskId, remove) {
162
+ let task = this.get(taskId);
163
+
164
+ task.isRunning && clearInterval(task.runner);
165
+
166
+ if (remove) {
167
+ this.removeTask(task);
168
+ } else {
169
+ task.isRunning = false;
170
+ task.runCount = 0;
171
+ task.runner = null;
172
+
173
+ if(task.addCountToArgs) {
174
+ task.args[task.args.length - 1] = 0;
175
+ }
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Stops all running tasks from collection.
181
+ * If remove is true, it will remove all tasks from Manager
182
+ * @param {Boolean} remove
183
+ */
184
+ stopAll(remove) {
185
+ Object.keys(this.map).forEach(key => {
186
+ this.stop(key, remove);
187
+ });
188
+ }
189
+ }
190
+
191
+ Neo.applyClassConfig(Task);
192
+
193
+ let instance = Neo.create(Task);
194
+
195
+ Neo.applyToGlobalNs(instance);
196
+
197
+ export default instance;
@@ -124,7 +124,10 @@ class Component extends Base {
124
124
  * @protected
125
125
  */
126
126
  beforeSetStores(value, oldValue) {
127
+ let controller = this.component.getController();
128
+
127
129
  value && Object.entries(value).forEach(([key, storeValue]) => {
130
+ controller?.parseConfig(storeValue);
128
131
  value[key] = ClassSystemUtil.beforeSetInstance(storeValue);
129
132
  });
130
133
 
@@ -86,7 +86,7 @@ class View extends Component {
86
86
 
87
87
  data.push({
88
88
  tag : 'tr',
89
- id : id,
89
+ id,
90
90
  cls : trCls,
91
91
  cn : [],
92
92
  tabIndex: '-1'
@@ -108,7 +108,7 @@ class View extends Component {
108
108
  rendererOutput = column.renderer.call(column.rendererScope || container, {
109
109
  dataField: column.dataField,
110
110
  index : i,
111
- record : record,
111
+ record,
112
112
  value : rendererValue
113
113
  });
114
114
 
@@ -65,15 +65,16 @@ class HashHistory extends Base {
65
65
  * @param {String} data.hashString
66
66
  */
67
67
  push(data) {
68
- let me = this;
68
+ let me = this,
69
+ stack = me.stack;
69
70
 
70
- me.stack.unshift(data);
71
+ stack.unshift(data);
71
72
 
72
- if (me.stack.length > me.maxItems) {
73
- me.stack.length = me.maxItems;
73
+ if (stack.length > me.maxItems) {
74
+ stack.length = me.maxItems;
74
75
  }
75
76
 
76
- me.fire('change', data, me.stack[1]);
77
+ me.fire('change', data, stack[1]);
77
78
  }
78
79
  }
79
80
 
@@ -118,10 +118,10 @@ class App extends Base {
118
118
  if (Neo.config.themes.length > 0) {
119
119
  className = className || proto.className;
120
120
 
121
- let me = this,
122
- lAppName = appName.toLowerCase(),
123
- cssMap = Neo.cssMap,
124
- parent = proto?.__proto__,
121
+ let me = this,
122
+ lAppName = appName.toLowerCase(),
123
+ cssMap = Neo.cssMap,
124
+ parent = proto?.__proto__,
125
125
  classPath, fileName, mapClassName, ns, themeFolders;
126
126
 
127
127
  if (!cssMap) {