@ibyar/core 0.2.0 → 0.3.6
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/LICENSE +1 -1
- package/README.md +18 -0
- package/annotation/decorators.d.ts +1 -1
- package/annotation/decorators.js +12 -2
- package/annotation/decorators.js.map +1 -1
- package/component/component.d.ts +4 -0
- package/component/component.js +45 -24
- package/component/component.js.map +1 -1
- package/component/custom-element.d.ts +6 -0
- package/component/custom-element.js.map +1 -1
- package/component/events.d.ts +1 -1
- package/component/events.js +11 -11
- package/component/events.js.map +1 -1
- package/component/provider.d.ts +12 -0
- package/component/provider.js +29 -0
- package/component/provider.js.map +1 -0
- package/context/stack.d.ts +2 -18
- package/context/stack.js +9 -48
- package/context/stack.js.map +1 -1
- package/directive/directive.d.ts +5 -4
- package/directive/directive.js +3 -0
- package/directive/directive.js.map +1 -1
- package/directive/providers.d.ts +7 -4
- package/directive/providers.js +3 -5
- package/directive/providers.js.map +1 -1
- package/html/expression.js +24 -12
- package/html/expression.js.map +1 -1
- package/html/update.d.ts +12 -0
- package/html/update.js +24 -0
- package/html/update.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/package.json +11 -8
- package/pipe/pipe.d.ts +3 -3
- package/pipe/pipe.js +5 -5
- package/pipe/pipe.js.map +1 -1
- package/providers/injector.js.map +1 -1
- package/providers/provider.js +9 -9
- package/providers/provider.js.map +1 -1
- package/view/base-view.js +43 -28
- package/view/base-view.js.map +1 -1
- package/view/form-view.js +1 -1
- package/view/form-view.js.map +1 -1
- package/view/render.d.ts +15 -13
- package/view/render.js +65 -35
- package/view/render.js.map +1 -1
- package/view/view.d.ts +2 -1
- package/view/view.js +26 -33
- package/view/view.js.map +1 -1
package/context/stack.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReadOnlyScope, Stack } from '@ibyar/expressions';
|
|
2
2
|
import { PipeProvider, AsyncPipeProvider } from '../pipe/pipe.js';
|
|
3
3
|
const Constant = {
|
|
4
4
|
Math: {
|
|
@@ -57,52 +57,13 @@ const Constant = {
|
|
|
57
57
|
isArray: Array.isArray,
|
|
58
58
|
},
|
|
59
59
|
Symbol,
|
|
60
|
-
String
|
|
61
|
-
|
|
62
|
-
},
|
|
60
|
+
String,
|
|
61
|
+
Number,
|
|
63
62
|
};
|
|
64
|
-
const
|
|
65
|
-
export const documentStack = new
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
notify(propertyKey) {
|
|
71
|
-
this.notification.push(propertyKey);
|
|
72
|
-
console.log(this.notification);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
export class BindingContextProvider {
|
|
76
|
-
constructor(context, notifier) {
|
|
77
|
-
this.context = context;
|
|
78
|
-
this.notifier = notifier;
|
|
79
|
-
}
|
|
80
|
-
static createOrGetProvider(object) {
|
|
81
|
-
if (this.contextMapping.has(object)) {
|
|
82
|
-
return this.contextMapping.get(object);
|
|
83
|
-
}
|
|
84
|
-
const notifier = new BindingNotification();
|
|
85
|
-
const provider = new BindingContextProvider(object, notifier);
|
|
86
|
-
this.contextMapping.set(object, provider);
|
|
87
|
-
return provider;
|
|
88
|
-
}
|
|
89
|
-
getNotifier() {
|
|
90
|
-
return this.notifier;
|
|
91
|
-
}
|
|
92
|
-
get(propertyKey) {
|
|
93
|
-
return Reflect.get(this.context, propertyKey);
|
|
94
|
-
}
|
|
95
|
-
set(propertyKey, value, receiver) {
|
|
96
|
-
const hasSet = Reflect.set(this.context, propertyKey, value);
|
|
97
|
-
this.notifier.notify(propertyKey);
|
|
98
|
-
return hasSet;
|
|
99
|
-
}
|
|
100
|
-
has(propertyKey) {
|
|
101
|
-
return propertyKey in this.context;
|
|
102
|
-
}
|
|
103
|
-
getProviderBy() {
|
|
104
|
-
return this.context;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
BindingContextProvider.contextMapping = new WeakMap();
|
|
63
|
+
const CONSTANT_SCOPE = new ReadOnlyScope(Constant, 'block');
|
|
64
|
+
export const documentStack = new Stack([
|
|
65
|
+
CONSTANT_SCOPE,
|
|
66
|
+
new PipeProvider(),
|
|
67
|
+
new AsyncPipeProvider()
|
|
68
|
+
]);
|
|
108
69
|
//# sourceMappingURL=stack.js.map
|
package/context/stack.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../src/core/context/stack.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../src/core/context/stack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAS,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAElE,MAAM,QAAQ,GAAyB;IAEtC,IAAI,EAAE;QACL,CAAC,EAAE,IAAI,CAAC,CAAC;QACT,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,KAAK,EAAE,IAAI,CAAC,KAAK;QAEjB,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,GAAG,EAAE,IAAI,CA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,YAAY,EAAE;IAClB,IAAI,iBAAiB,EAAE;CACvB,CACD,CAAC","sourcesContent":["import { ReadOnlyScope, Scope, Stack } from '@ibyar/expressions';\nimport { PipeProvider, AsyncPipeProvider } from '../pipe/pipe.js';\n\nconst Constant: { [k: string]: any } = {\n\t// math\n\tMath: {\n\t\tE: Math.E,\n\t\tLN10: Math.LN10,\n\t\tLN2: Math.LN2,\n\t\tLOG10E: Math.LOG10E,\n\t\tLOG2E: Math.LOG2E,\n\t\tPI: Math.PI,\n\t\tSQRT1_2: Math.SQRT1_2,\n\t\tSQRT2: Math.SQRT2,\n\n\t\tabs: Math.abs,\n\t\tacos: Math.acos,\n\t\tasin: Math.asin,\n\t\tatan: Math.atan,\n\t\tatan2: Math.atan2,\n\t\tceil: Math.ceil,\n\t\tcos: Math.cos,\n\t\texp: Math.exp,\n\t\tfloor: Math.floor,\n\t\tlog: Math.log,\n\t\tmax: Math.max,\n\t\tmin: Math.min,\n\t\tpow: Math.pow,\n\t\trandom: Math.random,\n\t\tround: Math.round,\n\t\tsin: Math.sin,\n\t\tsqrt: Math.sqrt,\n\t\ttan: Math.tan,\n\t\tclz32: Math.clz32,\n\t\timul: Math.imul,\n\t\tsign: Math.sign,\n\t\tlog10: Math.log10,\n\t\tlog2: Math.log2,\n\t\tlog1p: Math.log1p,\n\t\texpm1: Math.expm1,\n\t\tcosh: Math.cosh,\n\t\tsinh: Math.sinh,\n\t\ttanh: Math.tanh,\n\t\tacosh: Math.acosh,\n\t\tasinh: Math.asinh,\n\t\tatanh: Math.atanh,\n\t\thypot: Math.hypot,\n\t\ttrunc: Math.trunc,\n\t\tfround: Math.fround,\n\t\tcbrt: Math.cbrt,\n\t},\n\t// object\n\tObject,\n\t// number\n\tparseFloat,\n\tparseInt,\n\tInfinity,\n\tNaN,\n\tisNaN,\n\tisFinite,\n\t// array\n\tArray: {\n\t\tisArray: Array.isArray,\n\t},\n\tSymbol,\n\tString,\n\tNumber,\n};\n\nconst CONSTANT_SCOPE = new ReadOnlyScope(Constant, 'block');\nexport const documentStack = new Stack(\n\t[\n\t\tCONSTANT_SCOPE,\n\t\tnew PipeProvider(),\n\t\tnew AsyncPipeProvider()\n\t]\n);\n"]}
|
package/directive/directive.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { DOMDirectiveNode } from '@ibyar/elements';
|
|
1
|
+
import { DOMDirectiveNode, DOMElementNode } from '@ibyar/elements';
|
|
2
2
|
import { ComponentRender } from '../view/render.js';
|
|
3
|
-
import type { ExpressionNode,
|
|
3
|
+
import type { ExpressionNode, Stack } from '@ibyar/expressions';
|
|
4
4
|
export declare class StructuralDirective<T> {
|
|
5
5
|
protected render: ComponentRender<T>;
|
|
6
6
|
protected comment: Comment;
|
|
7
7
|
protected directive: DOMDirectiveNode<ExpressionNode>;
|
|
8
|
-
protected directiveStack:
|
|
9
|
-
constructor(render: ComponentRender<T>, comment: Comment, directive: DOMDirectiveNode<ExpressionNode>, directiveStack:
|
|
8
|
+
protected directiveStack: Stack;
|
|
9
|
+
constructor(render: ComponentRender<T>, comment: Comment, directive: DOMDirectiveNode<ExpressionNode>, directiveStack: Stack);
|
|
10
|
+
protected findTemplate(templateRefName: string): DOMElementNode<ExpressionNode> | undefined;
|
|
10
11
|
}
|
|
11
12
|
export declare class AttributeDirective {
|
|
12
13
|
protected el: HTMLElement;
|
package/directive/directive.js
CHANGED
|
@@ -5,6 +5,9 @@ export class StructuralDirective {
|
|
|
5
5
|
this.directive = directive;
|
|
6
6
|
this.directiveStack = directiveStack;
|
|
7
7
|
}
|
|
8
|
+
findTemplate(templateRefName) {
|
|
9
|
+
return this.render.templateRefMap.get(templateRefName);
|
|
10
|
+
}
|
|
8
11
|
}
|
|
9
12
|
export class AttributeDirective {
|
|
10
13
|
constructor(el) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"directive.js","sourceRoot":"","sources":["../../../src/core/directive/directive.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,mBAAmB;IAC/B,YACW,MAA0B,EAC1B,OAAgB,EAChB,SAA2C,EAC3C,
|
|
1
|
+
{"version":3,"file":"directive.js","sourceRoot":"","sources":["../../../src/core/directive/directive.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,mBAAmB;IAC/B,YACW,MAA0B,EAC1B,OAAgB,EAChB,SAA2C,EAC3C,cAAqB;QAHrB,WAAM,GAAN,MAAM,CAAoB;QAC1B,YAAO,GAAP,OAAO,CAAS;QAChB,cAAS,GAAT,SAAS,CAAkC;QAC3C,mBAAc,GAAd,cAAc,CAAO;IAC5B,CAAC;IACK,YAAY,CAAC,eAAuB;QAC7C,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IACxD,CAAC;CACD;AAKD,MAAM,OAAO,kBAAkB;IAC9B,YAAsB,EAAe;QAAf,OAAE,GAAF,EAAE,CAAa;IAAI,CAAC;CAC1C","sourcesContent":["import { DOMDirectiveNode, DOMElementNode } from '@ibyar/elements';\nimport { ComponentRender } from '../view/render.js';\n\nimport type { ExpressionNode, Stack } from '@ibyar/expressions';\n\n/**\n * A structural directive selector as '*if'\n */\nexport class StructuralDirective<T> {\n\tconstructor(\n\t\tprotected render: ComponentRender<T>,\n\t\tprotected comment: Comment,\n\t\tprotected directive: DOMDirectiveNode<ExpressionNode>,\n\t\tprotected directiveStack: Stack\n\t) { }\n\tprotected findTemplate(templateRefName: string): DOMElementNode<ExpressionNode> | undefined {\n\t\treturn this.render.templateRefMap.get(templateRefName);\n\t}\n}\n\n/**\n * An attributes directive selector as '[class] [style]'\n */\nexport class AttributeDirective {\n\tconstructor(protected el: HTMLElement) { }\n}\n"]}
|
package/directive/providers.d.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReactiveScope } from '@ibyar/expressions';
|
|
2
2
|
import { AttributeDirective } from './directive.js';
|
|
3
|
-
export declare
|
|
3
|
+
export declare type ElementContext = {
|
|
4
|
+
this: HTMLElement;
|
|
5
|
+
} & {
|
|
6
|
+
[key: string]: AttributeDirective | undefined;
|
|
7
|
+
};
|
|
8
|
+
export declare class ElementReactiveScope extends ReactiveScope<ElementContext> {
|
|
4
9
|
private el;
|
|
5
10
|
private directiveMap;
|
|
6
|
-
private context;
|
|
7
11
|
constructor(el: HTMLElement);
|
|
8
12
|
getElement(): HTMLElement;
|
|
9
13
|
getDirectives(): Map<string, AttributeDirective>;
|
|
10
14
|
get(propertyKey: PropertyKey): any;
|
|
11
15
|
set(propertyKey: PropertyKey, value: any, receiver?: any): boolean;
|
|
12
16
|
has(propertyKey: string): boolean;
|
|
13
|
-
getProviderBy(propertyKey: string): any;
|
|
14
17
|
}
|
package/directive/providers.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { ReactiveScope } from '@ibyar/expressions';
|
|
1
2
|
import { isOnInit } from '../component/lifecycle.js';
|
|
2
3
|
import { ClassRegistryProvider } from '../providers/provider.js';
|
|
3
4
|
import { AttributeDirective } from './directive.js';
|
|
4
|
-
export class
|
|
5
|
+
export class ElementReactiveScope extends ReactiveScope {
|
|
5
6
|
constructor(el) {
|
|
7
|
+
super({}, 'block');
|
|
6
8
|
this.el = el;
|
|
7
9
|
this.directiveMap = new Map();
|
|
8
|
-
this.context = {};
|
|
9
10
|
this.context.this = el;
|
|
10
11
|
}
|
|
11
12
|
getElement() {
|
|
@@ -84,8 +85,5 @@ export class ElementContextProvider {
|
|
|
84
85
|
}
|
|
85
86
|
return false;
|
|
86
87
|
}
|
|
87
|
-
getProviderBy(propertyKey) {
|
|
88
|
-
return this.context;
|
|
89
|
-
}
|
|
90
88
|
}
|
|
91
89
|
//# sourceMappingURL=providers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../../../src/core/directive/providers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../../../src/core/directive/provid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,CAAC;YAC7E,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,WAAqB,EAAE,SAAS,CAAC,CAAC;YACxD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;YAC1D,IAAI,QAAQ,CAAC,SAAS,CAAC,EAAE;gBACxB,SAAS,CAAC,MAAM,EAAE,CAAC;aACnB;YACD,OAAO,MAAM,CAAC;SACd;QACD,OAAO,KAAK,CAAC;IACd,CAAC;IACD,GAAG,CAAC,WAAmB;QACtB,IAAI,WAAW,IAAI,IAAI,CAAC,OAAO,EAAE;YAChC,OAAO,IAAI,CAAC;SACZ;QACD,IAAI,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;YACvC,OAAO,IAAI,CAAC;SACZ;QACD,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE;YACnD,IAAI,WAAW,IAAI,SAAS,EAAE;gBAC7B,OAAO,IAAI,CAAC;aACZ;SACD;QACD,IAAI,qBAAqB,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE;YACpD,OAAO,IAAI,CAAC;SACZ;QACD,IAAI,qBAAqB,CAAC,iBAAiB,CAAC,WAAW,CAAC,EAAE;YACzD,OAAO,IAAI,CAAC;SACZ;QACD,OAAO,KAAK,CAAC;IACd,CAAC;CACD","sourcesContent":["import { ReactiveScope } from '@ibyar/expressions';\nimport { isOnInit } from '../component/lifecycle.js';\nimport { ClassRegistryProvider } from '../providers/provider.js';\nimport { AttributeDirective } from './directive.js';\n\nexport type ElementContext = { this: HTMLElement } & { [key: string]: AttributeDirective | undefined; };\nexport class ElementReactiveScope extends ReactiveScope<ElementContext> {\n\tprivate directiveMap: Map<string, AttributeDirective> = new Map();\n\tconstructor(private el: HTMLElement) {\n\t\tsuper({} as ElementContext, 'block');\n\t\tthis.context.this = el;\n\t}\n\tgetElement() {\n\t\treturn this.el;\n\t}\n\tgetDirectives() {\n\t\treturn this.directiveMap;\n\t}\n\tget(propertyKey: PropertyKey): any {\n\t\tif (propertyKey === 'this') {\n\t\t\treturn this.el;\n\t\t}\n\t\tif (this.directiveMap.has(propertyKey as string)) {\n\t\t\tconst directive = this.directiveMap.get(propertyKey as string)!;\n\t\t\treturn directive;\n\t\t}\n\t\tfor (const directive of this.directiveMap.values()) {\n\t\t\tif (propertyKey in directive) {\n\t\t\t\treturn Reflect.get(directive, propertyKey);\n\t\t\t}\n\t\t}\n\t\tconst directiveRef = ClassRegistryProvider.getDirectiveRef<any>(propertyKey as string);\n\t\tif (directiveRef && directiveRef.modelClass instanceof AttributeDirective) {\n\t\t\tconst directive = new directiveRef.modelClass(this.el) as AttributeDirective;\n\t\t\tthis.directiveMap.set(propertyKey as string, directive);\n\t\t\tthis.context[propertyKey as string] = directive;\n\t\t\tif (isOnInit(directive)) {\n\t\t\t\tdirective.onInit();\n\t\t\t}\n\t\t\treturn Reflect.get(directive, propertyKey as string);\n\t\t}\n\t\treturn void 0;\n\t}\n\tset(propertyKey: PropertyKey, value: any, receiver?: any): boolean {\n\t\tif (propertyKey in this.el) {\n\t\t\treturn Reflect.set(this.el, propertyKey, value);\n\t\t}\n\t\tif (this.directiveMap.has(propertyKey as string)) {\n\t\t\tconst directive = this.directiveMap.get(propertyKey as string)!;\n\t\t\treturn Reflect.set(directive, propertyKey, value);\n\t\t}\n\t\tfor (const directive of this.directiveMap.values()) {\n\t\t\tif (propertyKey in directive) {\n\t\t\t\treturn Reflect.set(directive, propertyKey, value);\n\t\t\t}\n\t\t}\n\t\tconst directiveRef = ClassRegistryProvider.getDirectiveRef<any>(propertyKey as string);\n\t\tif (directiveRef && directiveRef.modelClass.prototype instanceof AttributeDirective) {\n\t\t\tconst directive = new directiveRef.modelClass(this.el) as AttributeDirective;\n\t\t\tthis.directiveMap.set(propertyKey as string, directive);\n\t\t\tconst result = Reflect.set(directive, propertyKey, value);\n\t\t\tif (isOnInit(directive)) {\n\t\t\t\tdirective.onInit();\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\t\treturn false;\n\t}\n\thas(propertyKey: string): boolean {\n\t\tif (propertyKey in this.context) {\n\t\t\treturn true;\n\t\t}\n\t\tif (this.directiveMap.has(propertyKey)) {\n\t\t\treturn true;\n\t\t}\n\t\tfor (const directive of this.directiveMap.values()) {\n\t\t\tif (propertyKey in directive) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\tif (ClassRegistryProvider.hasDirective(propertyKey)) {\n\t\t\treturn true;\n\t\t}\n\t\tif (ClassRegistryProvider.directiveHasInput(propertyKey)) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n}\n"]}
|
package/html/expression.js
CHANGED
|
@@ -1,29 +1,41 @@
|
|
|
1
1
|
import { DOMDirectiveNode, DOMElementNode, DOMFragmentNode, LiveTextContent } from '@ibyar/elements';
|
|
2
|
-
import {
|
|
2
|
+
import { AssignmentExpression, JavaScriptParser } from '@ibyar/expressions';
|
|
3
|
+
import { HTMLNodeAssignmentExpression, TextNodeAssignmentExpression } from './update.js';
|
|
3
4
|
const ThisTextContent = JavaScriptParser.parse('this.textContent');
|
|
4
5
|
function parseLiveText(text) {
|
|
5
|
-
text.expression = new
|
|
6
|
+
text.expression = new TextNodeAssignmentExpression(ThisTextContent, JavaScriptParser.parse(text.value));
|
|
6
7
|
}
|
|
7
|
-
function
|
|
8
|
-
const dashSplits =
|
|
8
|
+
function convertToMemberAccessStyle(source) {
|
|
9
|
+
const dashSplits = source.split('-');
|
|
10
|
+
if (dashSplits.length === 1) {
|
|
11
|
+
return source;
|
|
12
|
+
}
|
|
9
13
|
return dashSplits[0] + dashSplits.splice(1).map(s => (s[0].toUpperCase() + s.substring(1))).join('');
|
|
10
14
|
}
|
|
15
|
+
function checkAndValidateObjectSyntax(source) {
|
|
16
|
+
if (source.startsWith('{')) {
|
|
17
|
+
return `(${source})`;
|
|
18
|
+
}
|
|
19
|
+
return source;
|
|
20
|
+
}
|
|
11
21
|
function parseLiveAttribute(attr) {
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
attr.
|
|
22
|
+
const elementSource = `this.${convertToMemberAccessStyle(attr.name)}`;
|
|
23
|
+
const elementExpression = JavaScriptParser.parse(elementSource);
|
|
24
|
+
const modelExpression = JavaScriptParser.parse(checkAndValidateObjectSyntax(attr.value));
|
|
25
|
+
attr.expression = new HTMLNodeAssignmentExpression(elementExpression, modelExpression);
|
|
26
|
+
attr.callbackExpression = new AssignmentExpression('=', modelExpression, elementExpression);
|
|
16
27
|
}
|
|
17
28
|
function parseLiveAttributeUpdateElement(attr) {
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
29
|
+
const elementSource = `this.${convertToMemberAccessStyle(attr.name)}`;
|
|
30
|
+
const elementExpression = JavaScriptParser.parse(elementSource);
|
|
31
|
+
const modelExpression = JavaScriptParser.parse(checkAndValidateObjectSyntax(attr.value));
|
|
32
|
+
attr.expression = new HTMLNodeAssignmentExpression(elementExpression, modelExpression);
|
|
21
33
|
}
|
|
22
34
|
function parseOutputExpression(attr) {
|
|
23
35
|
attr.expression = JavaScriptParser.parse(attr.value);
|
|
24
36
|
}
|
|
25
37
|
function parseElementAttribute(attr) {
|
|
26
|
-
attr.expression = JavaScriptParser.parse('this.' +
|
|
38
|
+
attr.expression = JavaScriptParser.parse('this.' + convertToMemberAccessStyle(attr.name));
|
|
27
39
|
}
|
|
28
40
|
function parseBaseNode(base) {
|
|
29
41
|
base.inputs?.forEach(parseLiveAttributeUpdateElement);
|
package/html/expression.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expression.js","sourceRoot":"","sources":["../../../src/core/html/expression.ts"],"names":[],"mappings":"AAAA,OAAO,EACI,gBAAgB,EAAE,cAAc,EAAE,eAAe,EACX,eAAe,EAC/D,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"expression.js","s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AE,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAChD,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAChD,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAChD,kBAAkB,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,SAAS,UAAU,CAAC,KAA8B;IACjD,IAAI,KAAK,YAAY,cAAc,EAAE;QAEpC,aAAa,CAAC,KAAK,CAAC,CAAC;KACrB;SAAM,IAAI,KAAK,YAAY,gBAAgB,EAAE;QAE7C,kBAAkB,CAAC,KAAK,CAAC,CAAC;KAC1B;SAAM,IAAI,KAAK,YAAY,eAAe,EAAE;QAC5C,aAAa,CAAC,KAAK,CAAC,CAAC;KACrB;AACF,CAAC;AACD,SAAS,kBAAkB,CAAC,MAAqC;IAChE,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,IAA6B;IACjE,IAAI,IAAI,YAAY,eAAe,EAAE;QACpC,kBAAkB,CAAC,IAAI,CAAC,CAAC;KACzB;SAAM;QACN,UAAU,CAAC,IAAI,CAAC,CAAC;KACjB;AACF,CAAC","sourcesContent":["import {\n\tBaseNode, DOMDirectiveNode, DOMElementNode, DOMFragmentNode, DOMNode,\n\tDOMParentNode, ElementAttribute, LiveAttribute, LiveTextContent\n} from '@ibyar/elements';\nimport { AssignmentExpression, ExpressionNode, JavaScriptParser } from '@ibyar/expressions';\nimport { HTMLNodeAssignmentExpression, TextNodeAssignmentExpression } from './update.js';\n\nconst ThisTextContent = JavaScriptParser.parse('this.textContent');\nfunction parseLiveText(text: LiveTextContent<ExpressionNode>) {\n\ttext.expression = new TextNodeAssignmentExpression(ThisTextContent, JavaScriptParser.parse(text.value));\n}\n\nfunction convertToMemberAccessStyle(source: string) {\n\tconst dashSplits = source.split('-');\n\tif (dashSplits.length === 1) {\n\t\treturn source;\n\t}\n\treturn dashSplits[0] + dashSplits.splice(1).map(s => (s[0].toUpperCase() + s.substring(1))).join('');\n}\n\n/**\n * warp js code with `()` if necessary\n * \n * `{name: 'alex'}` will be `({name: 'alex'})`\n * \n * @param params \n */\nfunction checkAndValidateObjectSyntax(source: string) {\n\tif (source.startsWith('{')) {\n\t\treturn `(${source})`;\n\t}\n\treturn source;\n}\nfunction parseLiveAttribute(attr: LiveAttribute<ExpressionNode>) {\n\tconst elementSource = `this.${convertToMemberAccessStyle(attr.name)}`;\n\tconst elementExpression = JavaScriptParser.parse(elementSource);\n\tconst modelExpression = JavaScriptParser.parse(checkAndValidateObjectSyntax(attr.value));\n\n\tattr.expression = new HTMLNodeAssignmentExpression(elementExpression, modelExpression);\n\tattr.callbackExpression = new AssignmentExpression('=', modelExpression, elementExpression);\n}\n\nfunction parseLiveAttributeUpdateElement(attr: LiveAttribute<ExpressionNode>) {\n\tconst elementSource = `this.${convertToMemberAccessStyle(attr.name)}`;\n\tconst elementExpression = JavaScriptParser.parse(elementSource);\n\tconst modelExpression = JavaScriptParser.parse(checkAndValidateObjectSyntax(attr.value));\n\tattr.expression = new HTMLNodeAssignmentExpression(elementExpression, modelExpression);\n}\n\nfunction parseOutputExpression(attr: ElementAttribute<string, string, ExpressionNode>) {\n\tattr.expression = JavaScriptParser.parse(attr.value);\n}\n\nfunction parseElementAttribute(attr: ElementAttribute<string, any, ExpressionNode>) {\n\tattr.expression = JavaScriptParser.parse('this.' + convertToMemberAccessStyle(attr.name));\n}\n\n\nfunction parseBaseNode(base: BaseNode<ExpressionNode>) {\n\tbase.inputs?.forEach(parseLiveAttributeUpdateElement);\n\tbase.outputs?.forEach(parseOutputExpression);\n\tbase.twoWayBinding?.forEach(parseLiveAttribute);\n\tbase.templateAttrs?.forEach(parseLiveAttribute);\n\tbase.attributes?.forEach(parseElementAttribute);\n\tparseDomParentNode(base);\n}\n\nfunction parseChild(child: DOMNode<ExpressionNode>) {\n\tif (child instanceof DOMElementNode) {\n\t\t// DomElementNode\n\t\tparseBaseNode(child);\n\t} else if (child instanceof DOMDirectiveNode) {\n\t\t// DomDirectiveNode\n\t\tparseDomParentNode(child);\n\t} else if (child instanceof LiveTextContent) {\n\t\tparseLiveText(child);\n\t}\n}\nfunction parseDomParentNode(parent: DOMParentNode<ExpressionNode>) {\n\tparent.children?.forEach(parseChild);\n}\n\nexport function buildExpressionNodes(node: DOMNode<ExpressionNode>) {\n\tif (node instanceof DOMFragmentNode) {\n\t\tparseDomParentNode(node);\n\t} else {\n\t\tparseChild(node);\n\t}\n}\n"]}
|
package/html/update.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ExpressionNode, InfixExpressionNode, Stack } from '@ibyar/expressions';
|
|
2
|
+
export declare class NodeAssignmentExpression extends InfixExpressionNode<':=:'> {
|
|
3
|
+
constructor(left: ExpressionNode, right: ExpressionNode);
|
|
4
|
+
set(stack: Stack, value: any): any;
|
|
5
|
+
get(stack: Stack): any;
|
|
6
|
+
}
|
|
7
|
+
export declare class TextNodeAssignmentExpression extends NodeAssignmentExpression {
|
|
8
|
+
}
|
|
9
|
+
export declare class HTMLNodeAssignmentExpression extends NodeAssignmentExpression {
|
|
10
|
+
}
|
|
11
|
+
export declare class DirectiveNodeAssignmentExpression extends NodeAssignmentExpression {
|
|
12
|
+
}
|
package/html/update.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { InfixExpressionNode } from '@ibyar/expressions';
|
|
2
|
+
export class NodeAssignmentExpression extends InfixExpressionNode {
|
|
3
|
+
constructor(left, right) {
|
|
4
|
+
super(':=:', left, right);
|
|
5
|
+
}
|
|
6
|
+
set(stack, value) {
|
|
7
|
+
return this.left.set(stack, value);
|
|
8
|
+
}
|
|
9
|
+
get(stack) {
|
|
10
|
+
const lv = this.left.get(stack);
|
|
11
|
+
const rv = this.right.get(stack);
|
|
12
|
+
if (lv !== rv) {
|
|
13
|
+
this.set(stack, rv);
|
|
14
|
+
}
|
|
15
|
+
return rv;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export class TextNodeAssignmentExpression extends NodeAssignmentExpression {
|
|
19
|
+
}
|
|
20
|
+
export class HTMLNodeAssignmentExpression extends NodeAssignmentExpression {
|
|
21
|
+
}
|
|
22
|
+
export class DirectiveNodeAssignmentExpression extends NodeAssignmentExpression {
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=update.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../../src/core/html/update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,mBAAmB,EAAS,MAAM,oBAAoB,CAAC;AAEhF,MAAM,OAAO,wBAAyB,SAAQ,mBAA0B;IACvE,YAAY,IAAoB,EAAE,KAAqB;QACtD,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAC3B,CAAC;IACD,GAAG,CAAC,KAAY,EAAE,KAAU;QAC3B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IACD,GAAG,CAAC,KAAY;QACf,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAChC,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACjC,IAAI,EAAE,KAAK,EAAE,EAAE;YACd,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;SACpB;QACD,OAAO,EAAE,CAAC;IACX,CAAC;CACD;AAED,MAAM,OAAO,4BAA6B,SAAQ,wBAAwB;CAEzE;AAED,MAAM,OAAO,4BAA6B,SAAQ,wBAAwB;CAEzE;AAED,MAAM,OAAO,iCAAkC,SAAQ,wBAAwB;CAE9E","sourcesContent":["import { ExpressionNode, InfixExpressionNode, Stack } from '@ibyar/expressions';\n\nexport class NodeAssignmentExpression extends InfixExpressionNode<':=:'> {\n\tconstructor(left: ExpressionNode, right: ExpressionNode) {\n\t\tsuper(':=:', left, right);\n\t}\n\tset(stack: Stack, value: any) {\n\t\treturn this.left.set(stack, value);\n\t}\n\tget(stack: Stack): any {\n\t\tconst lv = this.left.get(stack);\n\t\tconst rv = this.right.get(stack);\n\t\tif (lv !== rv) {\n\t\t\tthis.set(stack, rv);\n\t\t}\n\t\treturn rv;\n\t}\n}\n\nexport class TextNodeAssignmentExpression extends NodeAssignmentExpression {\n\n}\n\nexport class HTMLNodeAssignmentExpression extends NodeAssignmentExpression {\n\n}\n\nexport class DirectiveNodeAssignmentExpression extends NodeAssignmentExpression {\n\n}\n\n"]}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,cAAc,4BAA4B,CAAC;AAE3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AAEzC,cAAc,oBAAoB,CAAC;AAEnC,cAAc,0BAA0B,CAAC;AAEzC,cAAc,6BAA6B,CAAC;AAE5C,cAAc,gBAAgB,CAAC;AAE/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AAExC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC","sourcesContent":["import 'reflect-metadata';\n\nexport * from './annotation/decorators.js';\n\nexport * from './component/component.js';\nexport * from './component/custom-element.js';\nexport * from './component/events.js';\nexport * from './component/lifecycle.js';\n\nexport * from './context/stack.js';\n\nexport * from './directive/directive.js';\n\nexport * from './model/change-detection.js';\n\nexport * from './pipe/pipe.js';\n\nexport * from './providers/injector.js';\nexport * from './providers/provider.js';\n\nexport * from './utils/elements-util.js';\nexport * from './utils/observable.js';\nexport * from './utils/path.js';\nexport * from './utils/utils.js';\n\nexport * from './view/mutation.js';\nexport * from './view/render.js';\nexport * from './view/view.js';\n\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ibyar/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "Implements Aurora's core functionality, low-level services, and utilities",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/ibyar/aurora",
|
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
"access": "public"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@ibyar/elements": "^0.
|
|
19
|
-
"@ibyar/expressions": "^0.
|
|
20
|
-
"
|
|
21
|
-
"tslib": "^2.
|
|
18
|
+
"@ibyar/elements": "^0.3.6",
|
|
19
|
+
"@ibyar/expressions": "^0.3.6",
|
|
20
|
+
"reflect-metadata": "^0.1.13",
|
|
21
|
+
"tslib": "^2.3.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"typescript": "^4.
|
|
24
|
+
"typescript": "^4.4.3"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
27
|
"build": "tsc --build --verbose"
|
|
@@ -30,6 +30,10 @@
|
|
|
30
30
|
"aurora",
|
|
31
31
|
"ibyar",
|
|
32
32
|
"custom-elements",
|
|
33
|
+
"web-components",
|
|
34
|
+
"webcomponents",
|
|
35
|
+
"shadow-dom",
|
|
36
|
+
"shadowdom",
|
|
33
37
|
"dependency-injection",
|
|
34
38
|
"reflect-metadata",
|
|
35
39
|
"services",
|
|
@@ -48,8 +52,7 @@
|
|
|
48
52
|
"elements-info",
|
|
49
53
|
"element",
|
|
50
54
|
"interceptor",
|
|
51
|
-
"shadow-dom",
|
|
52
55
|
"typescript"
|
|
53
56
|
],
|
|
54
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "b641c29b0dbac9a13c5ee2ef6f2a0b0bf427a10d"
|
|
55
58
|
}
|
package/pipe/pipe.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReadOnlyScope } from '@ibyar/expressions';
|
|
2
2
|
export interface PipeTransform<T, U> {
|
|
3
3
|
transform(value: T, ...args: any[]): U;
|
|
4
4
|
}
|
|
5
5
|
export declare function isPipeTransform<T extends any, U extends any>(pipe: any): pipe is PipeTransform<T, U>;
|
|
6
|
-
export declare class PipeProvider extends
|
|
6
|
+
export declare class PipeProvider extends ReadOnlyScope<Map<string, Function>> {
|
|
7
7
|
static PipeContext: Map<string, Function>;
|
|
8
8
|
constructor();
|
|
9
9
|
has(pipeName: string): boolean;
|
|
10
10
|
get(pipeName: string): any;
|
|
11
11
|
}
|
|
12
|
-
export declare class AsyncPipeProvider extends
|
|
12
|
+
export declare class AsyncPipeProvider extends ReadOnlyScope<object> {
|
|
13
13
|
static AsyncPipeContext: any;
|
|
14
14
|
constructor();
|
|
15
15
|
has(pipeName: string): boolean;
|
package/pipe/pipe.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReadOnlyScope } from '@ibyar/expressions';
|
|
2
2
|
import { ClassRegistryProvider } from '../providers/provider.js';
|
|
3
3
|
export function isPipeTransform(pipe) {
|
|
4
4
|
return Reflect.has(Object.getPrototypeOf(pipe), 'transform');
|
|
5
5
|
}
|
|
6
|
-
export class PipeProvider extends
|
|
6
|
+
export class PipeProvider extends ReadOnlyScope {
|
|
7
7
|
constructor() {
|
|
8
|
-
super(PipeProvider.PipeContext);
|
|
8
|
+
super(PipeProvider.PipeContext, 'block');
|
|
9
9
|
}
|
|
10
10
|
has(pipeName) {
|
|
11
11
|
if (this.context.has(pipeName)) {
|
|
@@ -30,9 +30,9 @@ export class PipeProvider extends ReadOnlyContextProvider {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
PipeProvider.PipeContext = new Map();
|
|
33
|
-
export class AsyncPipeProvider extends
|
|
33
|
+
export class AsyncPipeProvider extends ReadOnlyScope {
|
|
34
34
|
constructor() {
|
|
35
|
-
super(AsyncPipeProvider.AsyncPipeContext);
|
|
35
|
+
super(AsyncPipeProvider.AsyncPipeContext, 'block');
|
|
36
36
|
}
|
|
37
37
|
has(pipeName) {
|
|
38
38
|
const pipeRef = ClassRegistryProvider.getPipe(pipeName);
|
package/pipe/pipe.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipe.js","sourceRoot":"","sources":["../../../src/core/pipe/pipe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"pipe.js","sourceRoot":"","sources":["../../../src/core/pipe/pipe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAajE,MAAM,UAAU,eAAe,CAA+B,IAAS;IACtE,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,OAAO,YAAa,SAAQ,aAAoC;IAErE;QACC,KAAK,CAAC,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;IACD,GAAG,CAAC,QAAgB;QACnB,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;YAC/B,OAAO,IAAI,CAAC;SACZ;QACD,MAAM,OAAO,GAAG,qBAAqB,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AU,EAAE,CAAC;SAChC;QACD,OAAO,KAAK,CAAC,CAAC;IACf,CAAC;;AAdM,kCAAgB,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC","sourcesContent":["import { ReadOnlyScope } from '@ibyar/expressions';\nimport { ClassRegistryProvider } from '../providers/provider.js';\n\n/**\n * Pipes are used as singleton\n * it will be created if it needed, had no life cycle\n * \n * * no dependency injection applied on filters for now,\n * TODO: add support of dependency injection\n */\nexport interface PipeTransform<T, U> {\n\ttransform(value: T, ...args: any[]): U;\n}\n\nexport function isPipeTransform<T extends any, U extends any>(pipe: any): pipe is PipeTransform<T, U> {\n\treturn Reflect.has(Object.getPrototypeOf(pipe), 'transform');\n}\n\nexport class PipeProvider extends ReadOnlyScope<Map<string, Function>> {\n\tstatic PipeContext = new Map<string, Function>();\n\tconstructor() {\n\t\tsuper(PipeProvider.PipeContext, 'block');\n\t}\n\thas(pipeName: string): boolean {\n\t\tif (this.context.has(pipeName)) {\n\t\t\treturn true;\n\t\t}\n\t\tconst pipeRef = ClassRegistryProvider.getPipe<PipeTransform<any, any>>(pipeName);\n\t\treturn pipeRef !== undefined && !pipeRef.asynchronous;\n\t}\n\tget(pipeName: string): any {\n\t\tlet transformFunc: Function | undefined;\n\t\tif (transformFunc = this.context.get(pipeName)) {\n\t\t\treturn transformFunc;\n\t\t}\n\t\tconst pipeRef = ClassRegistryProvider.getPipe<PipeTransform<any, any>>(pipeName);\n\t\tif (pipeRef !== undefined && !pipeRef.asynchronous) {\n\t\t\tconst pipe = new pipeRef.modelClass();\n\t\t\ttransformFunc = pipe.transform.bind(pipe);\n\t\t\tthis.context.set(pipeRef.name, transformFunc);\n\t\t\treturn transformFunc;\n\t\t}\n\t\treturn void 0;\n\t}\n}\n\nexport class AsyncPipeProvider extends ReadOnlyScope<object> {\n\n\tstatic AsyncPipeContext = Object.create(null);\n\tconstructor() {\n\t\tsuper(AsyncPipeProvider.AsyncPipeContext, 'block');\n\t}\n\thas(pipeName: string): boolean {\n\t\tconst pipeRef = ClassRegistryProvider.getPipe<PipeTransform<any, any>>(pipeName);\n\t\treturn pipeRef?.asynchronous ? true : false;\n\t}\n\tget(pipeName: string): PipeTransform<any, any> | undefined {\n\t\tconst pipeRef = ClassRegistryProvider.getPipe<PipeTransform<any, any>>(pipeName);\n\t\tif (pipeRef?.asynchronous) {\n\t\t\treturn new pipeRef.modelClass();\n\t\t}\n\t\treturn void 0;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injector.js","sourceRoot":"","sources":["../../../src/core/providers/injector.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"injector.js","sourceRoot":"","sources":["../../../src/core/providers/injector.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,QAAQ;IAIpB;QAFQ,2BAAsB,GAAG,IAAI,GAAG,EAAE,CAAC;IAE3B,CAAC;IAEjB,WAAW,CAAI,KAAuB;QACrC,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAC7C,OAAO,QAAQ,CAAC;IACjB,CAAC;IAEO,eAAe,CAAC,WAA0B;QACjD,IAAI,eAAe,GAAG,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACnE,IAAI,eAAe;YAAE,OAAO,eAAe,CAAC;QAE5C,MAAM,MAAM,GACX,OAAO,CAAC,WAAW,CAAC,mBAAmB,EAAE,WAAW,CAAC,CAAC;QAEvD,IAAI,MAAM,EAAE;YACX,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAClD,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAC9B,CAAC;YACF,eAAe,GAAG,IAAI,WAAW,CAAC,GAAG,kBAAkB,CAAC,CAAC;SACzD;aAAM;YACN,eAAe,GAAG,IAAI,WAAW,EAAE,CAAC;SACpC;QACD,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;QAC9D,OAAO,eAAe,CAAC;IACxB,CAAC;CACD;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAa,IAAI,QAAQ,EAAE,CAAC","sourcesContent":["\nexport interface Constructable<T = any> {\n\tnew(...params: any[]): T;\n}\n\nexport class Injector {\n\n\tprivate dependencyInjectionMap = new Map();\n\n\tconstructor() { }\n\n\tgetInstance<T>(contr: Constructable<T>): T {\n\t\tconst instance = this.constructObject(contr);\n\t\treturn instance;\n\t}\n\n\tprivate constructObject(constructor: Constructable) {\n\t\tlet currentInstance = this.dependencyInjectionMap.get(constructor);\n\t\tif (currentInstance) return currentInstance;\n\n\t\tconst params: Constructable[] =\n\t\t\tReflect.getMetadata('design:paramtypes', constructor);\n\t\t// We need to init each constructor function into it's instance\n\t\tif (params) {\n\t\t\tconst argumentsInstances = params.map((paramter) =>\n\t\t\t\tthis.constructObject(paramter)\n\t\t\t);\n\t\t\tcurrentInstance = new constructor(...argumentsInstances);\n\t\t} else {\n\t\t\tcurrentInstance = new constructor();\n\t\t}\n\t\tthis.dependencyInjectionMap.set(constructor, currentInstance);\n\t\treturn currentInstance;\n\t}\n}\n\nexport const dependencyInjector: Injector = new Injector();\n"]}
|
package/providers/provider.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Components } from '../component/component.js';
|
|
2
2
|
export class ClassRegistry {
|
|
3
3
|
constructor() {
|
|
4
4
|
this.viewSet = new Set();
|
|
@@ -24,7 +24,7 @@ export class ClassRegistry {
|
|
|
24
24
|
}
|
|
25
25
|
hasComponent(selector) {
|
|
26
26
|
for (const modelClass of this.componentSet) {
|
|
27
|
-
const componentRef =
|
|
27
|
+
const componentRef = Components.getComponentRef(modelClass);
|
|
28
28
|
if (componentRef.selector === selector) {
|
|
29
29
|
return true;
|
|
30
30
|
}
|
|
@@ -33,7 +33,7 @@ export class ClassRegistry {
|
|
|
33
33
|
}
|
|
34
34
|
getComponentRef(selector) {
|
|
35
35
|
for (const modelClass of this.componentSet) {
|
|
36
|
-
const componentRef =
|
|
36
|
+
const componentRef = Components.getComponentRef(modelClass);
|
|
37
37
|
if (componentRef.selector === selector) {
|
|
38
38
|
return componentRef;
|
|
39
39
|
}
|
|
@@ -41,7 +41,7 @@ export class ClassRegistry {
|
|
|
41
41
|
}
|
|
42
42
|
getComponent(selector) {
|
|
43
43
|
for (const modelClass of this.componentSet) {
|
|
44
|
-
const componentRef =
|
|
44
|
+
const componentRef = Components.getComponentRef(modelClass);
|
|
45
45
|
if (componentRef.selector === selector) {
|
|
46
46
|
return modelClass;
|
|
47
47
|
}
|
|
@@ -78,7 +78,7 @@ export class ClassRegistry {
|
|
|
78
78
|
}
|
|
79
79
|
hasDirective(selector) {
|
|
80
80
|
for (const directiveClass of this.directiveSet) {
|
|
81
|
-
const directiveRef =
|
|
81
|
+
const directiveRef = Components.getBootstrap(directiveClass.prototype);
|
|
82
82
|
if (directiveRef.selector === selector) {
|
|
83
83
|
return true;
|
|
84
84
|
}
|
|
@@ -87,7 +87,7 @@ export class ClassRegistry {
|
|
|
87
87
|
}
|
|
88
88
|
directiveHasInput(input) {
|
|
89
89
|
for (const directiveClass of this.directiveSet) {
|
|
90
|
-
const directiveRef =
|
|
90
|
+
const directiveRef = Components.getBootstrap(directiveClass.prototype);
|
|
91
91
|
if (directiveRef.inputs?.filter(ref => ref.viewAttribute === input).length > 0) {
|
|
92
92
|
return true;
|
|
93
93
|
}
|
|
@@ -96,7 +96,7 @@ export class ClassRegistry {
|
|
|
96
96
|
}
|
|
97
97
|
getDirectiveRef(selector) {
|
|
98
98
|
for (const directiveClass of this.directiveSet) {
|
|
99
|
-
const directiveRef =
|
|
99
|
+
const directiveRef = Components.getBootstrap(directiveClass.prototype);
|
|
100
100
|
if (directiveRef.selector === selector) {
|
|
101
101
|
return directiveRef;
|
|
102
102
|
}
|
|
@@ -105,7 +105,7 @@ export class ClassRegistry {
|
|
|
105
105
|
}
|
|
106
106
|
getPipe(pipeName) {
|
|
107
107
|
for (const pipeClass of this.pipeSet) {
|
|
108
|
-
const pipeRef =
|
|
108
|
+
const pipeRef = Components.getBootstrap(pipeClass.prototype);
|
|
109
109
|
if (pipeRef.name === pipeName) {
|
|
110
110
|
return pipeRef;
|
|
111
111
|
}
|
|
@@ -114,7 +114,7 @@ export class ClassRegistry {
|
|
|
114
114
|
}
|
|
115
115
|
getService(serviceName) {
|
|
116
116
|
for (const serviceClass of this.serviceSet) {
|
|
117
|
-
const serviceRef =
|
|
117
|
+
const serviceRef = Components.getBootstrap(serviceClass.prototype);
|
|
118
118
|
if (serviceRef.name === serviceName) {
|
|
119
119
|
return serviceRef;
|
|
120
120
|
}
|