Skip to content

Commit 766b822

Browse files
committed
v0.71.37
1 parent 3e45cac commit 766b822

13 files changed

+168
-99
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ src/
1717
builds/
1818
examples/
1919
/ref-**
20+
/projects
2021

2122

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "maskjs",
3-
"version": "0.71.35",
3+
"version": "0.71.37",
44
"homepage": "https://github.com/atmajs/MaskJS",
55
"authors": [
66
"Alex Kit <[email protected]>"

package-lock.json

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "maskjs",
33
"description": "Template / Markup / HMVC Engine",
4-
"version": "0.71.35",
4+
"version": "0.71.37",
55
"homepage": "http://atmajs.com/mask",
66
"contributors": [
77
{
@@ -23,7 +23,9 @@
2323
"licenses": [
2424
"MIT"
2525
],
26-
"dependencies": {},
26+
"dependencies": {
27+
"@types/node": "^12.12.17"
28+
},
2729
"devDependencies": {
2830
"@types/jquery": "^3.3.22",
2931
"@types/sinon": "^7.0.5",
@@ -45,7 +47,7 @@
4547
"server": "atma server --TEST",
4648
"examples": "atma server --TEST",
4749
"tsc": "tsc -p tsconfig-build.json",
48-
"dts": "npm run tsc && atma run tools/build-dts"
50+
"dts": "npm run tsc && atma run tools/build-dts --TEST"
4951
},
5052
"keywords": [],
5153
"atma": {

projects/mask-compo/src/compo/CompoProto.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export const CompoProto = {
6363
serializeNodes: null,
6464
readAttributes: null,
6565
readProperties: null,
66-
readArguments: null
66+
readArguments: null,
67+
refs: null
6768
},
6869

6970
getAttribute <T = any> (key: string): T {
@@ -125,6 +126,9 @@ export const CompoProto = {
125126
if (this.compos != null) {
126127
Children_.select(this, this.compos);
127128
}
129+
if (this.meta?.refs != null) {
130+
Children_.selectSelf(this, this.meta.refs);
131+
}
128132
if (this.hotkeys != null) {
129133
KeyboardHandler.hotkeys(this, this.hotkeys);
130134
}

projects/mask-compo/src/compo/Component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { obj_create } from '@utils/obj';
44
import { compo_prepairProperties } from '../util/compo_create';
55
import { CompoProto } from './CompoProto';
66
import { CompoStatics } from './CompoStatics';
7-
import { deco_slot, deco_attr } from '@compo/deco/component_decorators';
7+
import { deco_slot, deco_attr, deco_refCompo, deco_refElement, deco_refQuery } from '@compo/deco/component_decorators';
88
import { IComponent } from '@compo/model/IComponent';
99

1010
export class Component extends class_create(CompoProto) implements IComponent {
@@ -67,7 +67,10 @@ export class Component extends class_create(CompoProto) implements IComponent {
6767

6868
static deco = {
6969
slot: deco_slot,
70-
attr: deco_attr
70+
attr: deco_attr,
71+
refCompo: deco_refCompo,
72+
refElement: deco_refElement,
73+
refQuery: deco_refQuery
7174
}
7275
}
7376

projects/mask-compo/src/compo/children.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ export const Children_ = {
1919
* });
2020
*
2121
*/
22-
select: function(component, compos) {
22+
select (component, compos) {
2323
for (var name in compos) {
2424
var data = compos[name],
2525
events = null,
2626
selector = null;
2727

2828
if (data instanceof Array) {
29+
console.error('obsolete');
2930
selector = data[0];
3031
events = data.splice(1);
3132
}
@@ -60,5 +61,25 @@ export const Children_ = {
6061
Events_.on(component, events, element);
6162
}
6263
}
63-
}
64+
},
65+
selectSelf (self, refs: { compos?: any, elements?: any, queries?: any } ) {
66+
let compos = refs.compos;
67+
if (compos) {
68+
for (let prop in compos) {
69+
self[prop] = CompoConfig.selectors.compo(self, compos[prop]);
70+
}
71+
}
72+
let q = refs.queries;
73+
if (q) {
74+
for (let prop in q) {
75+
self[prop] = CompoConfig.selectors.$(self, q[prop]);
76+
}
77+
}
78+
let els = refs.elements;
79+
if (els) {
80+
for (let prop in els) {
81+
self[prop] = self.$[0].querySelector(els[prop]);
82+
}
83+
}
84+
}
6485
};

projects/mask-compo/src/compo/events.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { fn_proxy } from '@utils/fn';
22
import { domLib_on } from '../util/domLib';
33

44
export const Events_ = {
5-
on: function(component, events, $element?) {
6-
if ($element == null) {
7-
$element = component.$;
5+
on: function(component, events, $el?) {
6+
if ($el == null) {
7+
$el = component.$;
88
}
99

1010
var isarray = events instanceof Array,
@@ -20,7 +20,7 @@ export const Events_ = {
2020
x[0] = EventDecorator(x[0]);
2121
}
2222

23-
$element.on.apply($element, x);
23+
$el.on.apply($el, x);
2424
continue;
2525
}
2626

@@ -42,7 +42,7 @@ export const Events_ = {
4242
type = EventDecorator(type);
4343
}
4444

45-
domLib_on($element, type, selector, fn_proxy(fn, component));
45+
domLib_on($el, type, selector, fn_proxy(fn, component));
4646
}
4747
}
4848
},

projects/mask-compo/src/deco/component_decorators.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,39 @@ export function deco_slot (name?: string) {
1818
export function deco_attr (opts?: IAttrDefinition) {
1919

2020
return function (target, propertyKey, descriptor?) {
21-
let meta = target.meta;
22-
if (meta == null) meta = target.meta = { attributes: {} };
23-
24-
let attr = meta.attributes;
25-
if (attr == null) attr = meta.attributes = {};
26-
21+
let attr = ensureMeta(target, 'attributes');
2722
let name = opts?.name;
2823
if (name == null) {
2924
name = propertyKey[0] + propertyKey.substring(1).replace(/[A-Z]/g, c => `_${c.toLowerCase()}`);
3025
}
3126
attr [name] = obj_extend(opts, { name: propertyKey });
3227
};
33-
};
28+
};
29+
30+
31+
export function deco_refCompo (selector: string) {
32+
return function (target, propertyKey, descriptor?) {
33+
ensureRef(target, propertyKey, selector, 'compos');
34+
};
35+
};
36+
export function deco_refElement (selector: string) {
37+
return function (target, propertyKey, descriptor?) {
38+
ensureRef(target, propertyKey, selector, 'elements');
39+
};
40+
};
41+
export function deco_refQuery (selector: string) {
42+
return function (target, propertyKey, descriptor?) {
43+
ensureRef(target, propertyKey, selector, 'queries');
44+
};
45+
};
46+
47+
function ensureMeta(proto, name: string) {
48+
let m = proto.meta;
49+
if (m == null) m = proto.meta = { [name]: {} };
50+
return m[name] ?? (m[name] = {});
51+
}
52+
function ensureRef(proto, key: string, selector: string, refName: string) {
53+
let refs = ensureMeta(proto, 'refs');
54+
let ref = refs[refName] ?? (refs[refName] = {});
55+
ref[key] = selector;
56+
}

src/mask.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ export const Mask = {
269269
deco: {
270270
slot: Component.deco.slot,
271271
attr: Component.deco.attr,
272+
refCompo: Component.deco.refCompo,
273+
refElement: Component.deco.refCompo,
274+
refQuery: Component.deco.refCompo,
272275
inject: Di.deco.injectableClass,
273276
},
274277

test.ts

Lines changed: 0 additions & 64 deletions
This file was deleted.

tools/build-dts.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)