neo.mjs 5.1.0 → 5.1.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.
- package/apps/ServiceWorker.mjs +2 -2
- package/apps/realworld/view/HomeComponent.mjs +16 -16
- package/apps/realworld/view/MainContainerController.mjs +7 -0
- package/examples/ServiceWorker.mjs +2 -2
- package/package.json +1 -1
- package/src/DefaultConfig.mjs +2 -2
- package/src/Neo.mjs +3 -3
- package/src/container/Base.mjs +1 -0
- package/src/controller/Component.mjs +11 -0
- package/src/core/Base.mjs +16 -16
- package/src/core/Observable.mjs +3 -1
- package/src/form/field/Text.mjs +15 -2
package/apps/ServiceWorker.mjs
CHANGED
@@ -62,26 +62,26 @@ class HomeComponent extends Component {
|
|
62
62
|
* @member {Object} _vdom
|
63
63
|
*/
|
64
64
|
_vdom:
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
]}
|
65
|
+
{cn: [
|
66
|
+
{cls: ['banner'], cn: [
|
67
|
+
{cls: ['container'], cn: [
|
68
|
+
{tag: 'h1', cls: ['logo-font'], html: 'conduit'},
|
69
|
+
{tag: 'p', html: 'A place to share your knowledge.'}
|
70
|
+
]}
|
71
|
+
]},
|
72
|
+
{cls: ['container', 'page'], cn: [
|
73
|
+
{cls: ['row'], cn: [
|
74
|
+
{cls: ['col-md-9'], cn: [
|
75
|
+
{cls: ['feed-toggle'], cn: [
|
76
|
+
{tag: 'ul', cls: ['nav', 'nav-pills', 'outline-active'], flag: 'feed-header', cn: []}
|
77
|
+
]},
|
78
|
+
{tag: 'nav', cn: [
|
79
|
+
{tag: 'ul', cls: ['pagination'], flag: 'pagination'}
|
81
80
|
]}
|
82
81
|
]}
|
83
82
|
]}
|
84
83
|
]}
|
84
|
+
]}
|
85
85
|
}
|
86
86
|
|
87
87
|
/**
|
@@ -11,6 +11,13 @@ import UserApi from '../api/User.mjs';
|
|
11
11
|
* @extends Neo.controller.Component
|
12
12
|
*/
|
13
13
|
class MainContainerController extends ComponentController {
|
14
|
+
/**
|
15
|
+
* True automatically applies the core.Observable mixin
|
16
|
+
* @member {Boolean} observable=false
|
17
|
+
* @static
|
18
|
+
*/
|
19
|
+
static observable = true
|
20
|
+
|
14
21
|
static config = {
|
15
22
|
/**
|
16
23
|
* @member {String} className='RealWorld.view.MainContainerController'
|
package/package.json
CHANGED
package/src/DefaultConfig.mjs
CHANGED
@@ -237,12 +237,12 @@ const DefaultConfig = {
|
|
237
237
|
useVdomWorker: true,
|
238
238
|
/**
|
239
239
|
* buildScripts/injectPackageVersion.mjs will update this value
|
240
|
-
* @default '5.1.
|
240
|
+
* @default '5.1.1'
|
241
241
|
* @memberOf! module:Neo
|
242
242
|
* @name config.version
|
243
243
|
* @type String
|
244
244
|
*/
|
245
|
-
version: '5.1.
|
245
|
+
version: '5.1.1'
|
246
246
|
};
|
247
247
|
|
248
248
|
Object.assign(DefaultConfig, {
|
package/src/Neo.mjs
CHANGED
@@ -70,13 +70,13 @@ Neo = globalThis.Neo = Object.assign({
|
|
70
70
|
|
71
71
|
protos.forEach(element => {
|
72
72
|
let mixins;
|
73
|
-
|
73
|
+
|
74
74
|
ctor = element.constructor;
|
75
75
|
|
76
76
|
cfg = ctor.config || {};
|
77
77
|
|
78
|
-
if (Neo.
|
79
|
-
ctor.
|
78
|
+
if (Neo.overwrites) {
|
79
|
+
ctor.applyOverwrites(cfg);
|
80
80
|
}
|
81
81
|
|
82
82
|
Object.entries(cfg).forEach(([key, value]) => {
|
package/src/container/Base.mjs
CHANGED
@@ -141,6 +141,7 @@ class Component extends Base {
|
|
141
141
|
let me = this,
|
142
142
|
listeners = component.listeners,
|
143
143
|
reference = component.reference,
|
144
|
+
validator = component.validator,
|
144
145
|
eventHandler, handlerScope;
|
145
146
|
|
146
147
|
if (listeners) {
|
@@ -174,6 +175,16 @@ class Component extends Base {
|
|
174
175
|
});
|
175
176
|
}
|
176
177
|
|
178
|
+
if (Neo.isString(validator)) {
|
179
|
+
handlerScope = me.getHandlerScope(validator);
|
180
|
+
|
181
|
+
if (!handlerScope) {
|
182
|
+
Logger.logError('Unknown validator for', component.id, component);
|
183
|
+
} else {
|
184
|
+
component.validator = handlerScope[validator].bind(handlerScope);
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
177
188
|
if (reference) {
|
178
189
|
me.references[reference] = component;
|
179
190
|
}
|
package/src/core/Base.mjs
CHANGED
@@ -23,10 +23,10 @@ class Base {
|
|
23
23
|
*/
|
24
24
|
static observable = false
|
25
25
|
/**
|
26
|
-
* Keep the
|
26
|
+
* Keep the overwritten methods
|
27
27
|
* @type {Object}
|
28
28
|
*/
|
29
|
-
static
|
29
|
+
static overwrittenMethods = {}
|
30
30
|
|
31
31
|
/**
|
32
32
|
* Set this one to false in case you don't want to stick
|
@@ -150,29 +150,29 @@ class Base {
|
|
150
150
|
}
|
151
151
|
|
152
152
|
/**
|
153
|
-
* Applying
|
153
|
+
* Applying overwrites and adding overwrittenMethods to the class constructors
|
154
154
|
* @param {Object} cfg
|
155
155
|
* @protected
|
156
156
|
*/
|
157
|
-
static
|
158
|
-
let
|
157
|
+
static applyOverwrites(cfg) {
|
158
|
+
let overwrites = Neo.ns(cfg.className, false, Neo.overwrites),
|
159
159
|
cls, item;
|
160
160
|
|
161
|
-
if (
|
161
|
+
if (overwrites) {
|
162
162
|
// Apply all methods
|
163
|
-
for (item in
|
164
|
-
if (Neo.isFunction(
|
163
|
+
for (item in overwrites) {
|
164
|
+
if (Neo.isFunction(overwrites[item])) {
|
165
165
|
// Already existing ones
|
166
166
|
cls = this.prototype;
|
167
167
|
|
168
168
|
if (cls[item]) {
|
169
|
-
// add to
|
170
|
-
cls.constructor.
|
169
|
+
// add to overwrittenMethods
|
170
|
+
cls.constructor.overwrittenMethods[item] = cls[item];
|
171
171
|
}
|
172
172
|
}
|
173
173
|
}
|
174
174
|
// Apply configs to prototype
|
175
|
-
|
175
|
+
overwrites && Object.assign(cfg, overwrites);
|
176
176
|
}
|
177
177
|
}
|
178
178
|
|
@@ -196,12 +196,12 @@ class Base {
|
|
196
196
|
}
|
197
197
|
|
198
198
|
/**
|
199
|
-
* From within an
|
199
|
+
* From within an overwrite, a method can call a parent method, by using callOverwritten.
|
200
200
|
*
|
201
201
|
* @example
|
202
202
|
* afterSetHeight(value, oldValue) {
|
203
203
|
* // do the standard
|
204
|
-
* this.
|
204
|
+
* this.callOverwritten(...arguments);
|
205
205
|
* // do you own stuff
|
206
206
|
* }
|
207
207
|
*
|
@@ -209,17 +209,17 @@ class Base {
|
|
209
209
|
* This is based on the following error structure, e.g. afterSetHeight.
|
210
210
|
*
|
211
211
|
* Error
|
212
|
-
* at Base.
|
212
|
+
* at Base.callOverwritten (Base.mjs:176:21)
|
213
213
|
* at Base.afterSetHeight (Overrides.mjs:19:26)
|
214
214
|
*
|
215
215
|
* @param args
|
216
216
|
*/
|
217
|
-
|
217
|
+
callOverwritten(...args) {
|
218
218
|
let stack = new Error().stack,
|
219
219
|
regex = Base.methodNameRegex,
|
220
220
|
methodName = stack.match(regex)[1];
|
221
221
|
|
222
|
-
this.__proto__.constructor.
|
222
|
+
this.__proto__.constructor.overwrittenMethods[methodName].call(this, ...args);
|
223
223
|
}
|
224
224
|
|
225
225
|
/**
|
package/src/core/Observable.mjs
CHANGED
@@ -148,8 +148,10 @@ class Observable extends Base {
|
|
148
148
|
}
|
149
149
|
|
150
150
|
while (proto?.constructor.isClass) {
|
151
|
+
ctor = proto.constructor;
|
152
|
+
|
151
153
|
if (ctor.observable && !ctor.listeners) {
|
152
|
-
Object.assign(
|
154
|
+
Object.assign(ctor, {
|
153
155
|
addListener : me.addListener,
|
154
156
|
fire : me.fire,
|
155
157
|
listeners : {},
|
package/src/form/field/Text.mjs
CHANGED
@@ -158,6 +158,11 @@ class Text extends Base {
|
|
158
158
|
* @member {Object|Object[]|null} triggers_=null
|
159
159
|
*/
|
160
160
|
triggers_: null,
|
161
|
+
/**
|
162
|
+
* A string based value will get resolved into the closest controller which implements it
|
163
|
+
* @member {Function|String|null} validator=null
|
164
|
+
*/
|
165
|
+
validator: null,
|
161
166
|
/**
|
162
167
|
* @member {Object} _vdom
|
163
168
|
*/
|
@@ -1289,9 +1294,17 @@ class Text extends Base {
|
|
1289
1294
|
value = me.value,
|
1290
1295
|
valueLength = value?.toString().length,
|
1291
1296
|
isEmpty = !value || valueLength < 1,
|
1292
|
-
errorParam = {maxLength, minLength, valueLength}
|
1297
|
+
errorParam = {maxLength, minLength, valueLength},
|
1298
|
+
errorText;
|
1299
|
+
|
1300
|
+
if (Neo.isFunction(me.validator)) {
|
1301
|
+
errorText = me.validator(me);
|
1293
1302
|
|
1294
|
-
|
1303
|
+
if (errorText !== true) {
|
1304
|
+
me[errorField] = errorText;
|
1305
|
+
returnValue = false;
|
1306
|
+
}
|
1307
|
+
} else if (required && isEmpty) {
|
1295
1308
|
me[errorField] = me.errorTextRequired;
|
1296
1309
|
returnValue = false;
|
1297
1310
|
} else if (Neo.isNumber(maxLength) && valueLength > maxLength) {
|