neo.mjs 4.0.50 → 4.0.51

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.
@@ -54,7 +54,7 @@ if (programOpts.info) {
54
54
  type : 'input',
55
55
  name : 'className',
56
56
  message: 'Please choose the namespace for your class:',
57
- default: 'Covid.view.FooContainer'
57
+ default: 'Covid.view.HeaderContainerController'
58
58
  });
59
59
  }
60
60
 
@@ -63,8 +63,8 @@ if (programOpts.info) {
63
63
  type : 'list',
64
64
  name : 'baseClass',
65
65
  message: 'Please pick the base class, which you want to extend:',
66
- choices: ['component.Base', 'container.Base'],
67
- default: 'component.Base'
66
+ choices: ['component.Base', 'container.Base', 'controller.Component', 'core.Base'],
67
+ default: 'container.Base'
68
68
  });
69
69
  }
70
70
 
@@ -72,7 +72,7 @@ if (programOpts.info) {
72
72
  let baseClass = programOpts.baseClass || answers.baseClass,
73
73
  className = programOpts.className || answers.className,
74
74
  startDate = new Date(),
75
- classFolder, file, folderDelta, ns, root, rootLowerCase;
75
+ classFolder, file, folderDelta, index, ns, root, rootLowerCase, viewFile;
76
76
 
77
77
  if (className.endsWith('.mjs')) {
78
78
  className = className.slice(0, -4);
@@ -93,6 +93,18 @@ if (programOpts.info) {
93
93
  fs.mkdirpSync(classFolder);
94
94
 
95
95
  fs.writeFileSync(path.join(classFolder, file + '.mjs'), createContent({baseClass, className, file, folderDelta, ns, root}));
96
+
97
+ if (baseClass === 'controller.Component') {
98
+ index = file.indexOf('Controller');
99
+
100
+ if (index > 0) {
101
+ viewFile = path.join(classFolder, file.substr(0, index) + '.mjs');
102
+
103
+ if (fs.existsSync(viewFile)) {
104
+ adjustView({file, viewFile});
105
+ }
106
+ }
107
+ }
96
108
  } else {
97
109
  console.log('\nNon existing neo app name:', chalk.red(root));
98
110
  process.exit(1);
@@ -108,9 +120,84 @@ if (programOpts.info) {
108
120
  /**
109
121
  * Adds a comma to the last element of the contentArray
110
122
  * @param {String[]} contentArray
123
+ * @returns {String[]}
111
124
  */
112
125
  function addComma(contentArray) {
113
126
  contentArray[contentArray.length - 1] += ',';
127
+ return contentArray;
128
+ }
129
+
130
+ /**
131
+ * Adjusts the views related to controller.Component or model.Component
132
+ * @param {Object} opts
133
+ * @param {String} opts.file
134
+ * @param {String} opts.viewFile
135
+ */
136
+ function adjustView(opts) {
137
+ let file = opts.file,
138
+ viewFile = opts.viewFile,
139
+ content = fs.readFileSync(viewFile).toString().split(os.EOL),
140
+ fromMaxPosition = 0,
141
+ i = 0,
142
+ len = content.length,
143
+ adjustSpaces, codeLine, fromPosition, importLength, importName, j, spaces;
144
+
145
+ // find the index where we want to insert our import statement
146
+ for (; i < len; i++) {
147
+ codeLine = content[i];
148
+
149
+ if (codeLine === '') {
150
+ break;
151
+ }
152
+
153
+ importName = codeLine.substr(7);
154
+ importName = importName.substr(0, importName.indexOf(' '));
155
+ importLength = importName.length;
156
+
157
+ if (importName > file) {
158
+ break;
159
+ }
160
+ }
161
+
162
+ content.splice(i, 0, `import ${file} from './${file}.mjs';`);
163
+
164
+ // find the longest import module name
165
+ for (i=0; i < len; i++) {
166
+ codeLine = content[i];
167
+
168
+ if (codeLine === '') {
169
+ break;
170
+ }
171
+
172
+ fromMaxPosition = Math.max(fromMaxPosition, codeLine.indexOf('from'));
173
+ }
174
+
175
+ // adjust the block-formatting for imports
176
+ for (i=0; i < len; i++) {
177
+ codeLine = content[i];
178
+
179
+ if (codeLine === '') {
180
+ break;
181
+ }
182
+
183
+ fromPosition = codeLine.indexOf('from');
184
+ adjustSpaces = fromMaxPosition - fromPosition;
185
+
186
+ if (adjustSpaces > 0) {
187
+ spaces = '';
188
+
189
+ for (j=0; j < adjustSpaces; j++) {
190
+ spaces += ' ';
191
+ }
192
+
193
+ content[i] = codeLine.substr(0, fromPosition) + spaces + codeLine.substr(fromPosition);
194
+ }
195
+ }
196
+
197
+ fs.writeFileSync(viewFile, content.join(os.EOL));
198
+
199
+ console.log(i, opts.file);
200
+ console.log(content);
114
201
  }
115
202
 
116
203
  /**
@@ -125,13 +212,13 @@ if (programOpts.info) {
125
212
  * @returns {String}
126
213
  */
127
214
  function createContent(opts) {
128
- let baseClass = opts.baseClass,
129
- baseClassNs = baseClass.split('.'),
215
+ let baseClass = opts.baseClass,
216
+ baseClassNs = baseClass.split('.'),
130
217
  baseFileName = baseClassNs.pop(),
131
- className = opts.className,
132
- file = opts.file,
133
- i = 0,
134
- importDelta = '';
218
+ className = opts.className,
219
+ file = opts.file,
220
+ i = 0,
221
+ importDelta = '';
135
222
 
136
223
  for (; i < opts.folderDelta; i++) {
137
224
  importDelta += '../';
@@ -141,8 +228,8 @@ if (programOpts.info) {
141
228
  `import ${baseFileName} from '${importDelta}${(insideNeo ? '' : 'node_modules/neo.mjs/')}src/${baseClassNs.join('/')}/${baseFileName}.mjs';`,
142
229
  "",
143
230
  "/**",
144
- " * @class " + className,
145
- " * @extends Neo." + baseClass,
231
+ ` * @class ${className}`,
232
+ ` * @extends Neo.${baseClass}`,
146
233
  " */",
147
234
  `class ${file} extends ${baseFileName} {`,
148
235
  " static getConfig() {return {",
@@ -153,28 +240,20 @@ if (programOpts.info) {
153
240
  ` className: '${className}'`
154
241
  ];
155
242
 
156
- if (baseClass === 'component.Base') {
157
- addComma(classContent);
158
-
159
- classContent.push(
243
+ baseClass === 'container.Base' && addComma(classContent).push(
160
244
  " /*",
161
- " * @member {Object} _vdom",
245
+ " * @member {Object[]} items",
162
246
  " */",
163
- " _vdom:",
164
- " {}",
165
- );
166
- }
167
-
168
- if (baseClass === 'container.Base') {
169
- addComma(classContent);
247
+ " items: []"
248
+ );
170
249
 
171
- classContent.push(
250
+ baseClass === 'component.Base' && addComma(classContent).push(
172
251
  " /*",
173
- " * @member {Object[]} items",
252
+ " * @member {Object} _vdom",
174
253
  " */",
175
- " items: []",
176
- );
177
- }
254
+ " _vdom:",
255
+ " {}"
256
+ );
178
257
 
179
258
  classContent.push(
180
259
  " }}",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo.mjs",
3
- "version": "4.0.50",
3
+ "version": "4.0.51",
4
4
  "description": "The webworkers driven UI framework",
5
5
  "type": "module",
6
6
  "repository": {
@@ -174,6 +174,28 @@ class Number extends Text {
174
174
  return this.beforeSetEnumValue(value, oldValue, 'triggerPosition');
175
175
  }
176
176
 
177
+ /**
178
+ * @returns {Boolean}
179
+ */
180
+ isValid() {
181
+ let me = this,
182
+ value = me.value;
183
+
184
+ if (Neo.isNumber(me.maxValue) && value > me.maxValue) {
185
+ return false;
186
+ }
187
+
188
+ if (Neo.isNumber(me.minValue) && value < me.minValue) {
189
+ return false;
190
+ }
191
+
192
+ if (value % me.stepSize !== 0) {
193
+ return false;
194
+ }
195
+
196
+ return super.isValid();
197
+ }
198
+
177
199
  /**
178
200
  *
179
201
  */
@@ -93,6 +93,16 @@ class Text extends Base {
93
93
  * @member {Number|String} labelWidth_=150
94
94
  */
95
95
  labelWidth_: 150,
96
+ /**
97
+ * The maximum amount of chars which you can enter into this field
98
+ * @member {Number|null} maxLength_=null
99
+ */
100
+ maxLength_: null,
101
+ /**
102
+ * The minimum amount of chars which you can enter into this field
103
+ * @member {Number|null} minLength_=null
104
+ */
105
+ minLength_: null,
96
106
  /**
97
107
  * @member {String|null} placeholderText_=null
98
108
  */
@@ -358,6 +368,26 @@ class Text extends Base {
358
368
  }
359
369
  }
360
370
 
371
+ /**
372
+ * Triggered after the maxLength config got changed
373
+ * @param {Number|null} value
374
+ * @param {Number|null} oldValue
375
+ * @protected
376
+ */
377
+ afterSetMaxLength(value, oldValue) {
378
+ this.changeInputElKey('maxlength', value);
379
+ }
380
+
381
+ /**
382
+ * Triggered after the minLength config got changed
383
+ * @param {Number|null} value
384
+ * @param {Number|null} oldValue
385
+ * @protected
386
+ */
387
+ afterSetMinLength(value, oldValue) {
388
+ this.changeInputElKey('minlength', value);
389
+ }
390
+
361
391
  /**
362
392
  * Triggered after the mounted config got changed
363
393
  * @param {Boolean} value
@@ -776,9 +806,19 @@ class Text extends Base {
776
806
  * @returns {Boolean}
777
807
  */
778
808
  isValid() {
779
- let me = this;
809
+ let me = this,
810
+ value = me.value,
811
+ valueLength = value?.toString().length;
812
+
813
+ if (me.required && (!value || valueLength < 1)) {
814
+ return false;
815
+ }
816
+
817
+ if (Neo.isNumber(me.maxLength) && valueLength > me.maxLength) {
818
+ return false;
819
+ }
780
820
 
781
- if (me.required && (!me.value || me.value?.length < 1)) {
821
+ if (Neo.isNumber(me.minLength) && valueLength < me.minLength) {
782
822
  return false;
783
823
  }
784
824