@ibyar/core 0.5.6 → 0.5.62
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/annotation/decorators.d.ts +97 -0
- package/binding/binding.expressions.d.ts +5 -0
- package/binding/binding.expressions.js +7 -0
- package/binding/binding.expressions.js.map +1 -1
- package/component/component.js +1 -0
- package/component/component.js.map +1 -1
- package/component/custom-element.d.ts +42 -0
- package/context/stack.js +4 -0
- package/context/stack.js.map +1 -1
- package/directive/directive.d.ts +9 -0
- package/directive/directive.js +9 -0
- package/directive/directive.js.map +1 -1
- package/directive/parser.d.ts +4 -0
- package/directive/parser.js +19 -0
- package/directive/parser.js.map +1 -1
- package/html/expression.d.ts +5 -0
- package/html/expression.js +12 -0
- package/html/expression.js.map +1 -1
- package/linker/change-detector-ref.d.ts +14 -0
- package/linker/change-detector-ref.js +3 -0
- package/linker/change-detector-ref.js.map +1 -1
- package/linker/template-ref.d.ts +12 -0
- package/linker/template-ref.js +2 -0
- package/linker/template-ref.js.map +1 -1
- package/linker/view-container-ref.d.ts +78 -0
- package/linker/view-container-ref.js +1 -0
- package/linker/view-container-ref.js.map +1 -1
- package/linker/view-ref.d.ts +39 -0
- package/package.json +4 -4
- package/pipe/pipe.d.ts +7 -0
- package/providers/injector.js +1 -0
- package/providers/injector.js.map +1 -1
- package/render/host-listener.handler.d.ts +17 -0
- package/render/host-listener.handler.js +17 -0
- package/render/host-listener.handler.js.map +1 -1
- package/render/render-handler.d.ts +6 -0
- package/utils/typeof.d.ts +3 -0
- package/utils/utils.js +1 -0
- package/utils/utils.js.map +1 -1
- package/view/base-view.js +12 -1
- package/view/base-view.js.map +1 -1
- package/view/form-view.js +21 -0
- package/view/form-view.js.map +1 -1
- package/view/mutation.js +1 -0
- package/view/mutation.js.map +1 -1
- package/view/render.js +28 -3
- package/view/render.js.map +1 -1
- package/view/view.d.ts +5 -0
- package/view/view.js +6 -0
- package/view/view.js.map +1 -1
package/html/expression.js
CHANGED
|
@@ -16,6 +16,13 @@ function convertToMemberAccessStyle(source) {
|
|
|
16
16
|
}
|
|
17
17
|
return dashSplits[0] + dashSplits.splice(1).map(s => (s[0].toUpperCase() + s.substring(1))).join('');
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* warp js code with `()` if necessary
|
|
21
|
+
*
|
|
22
|
+
* `{name: 'alex'}` will be `({name: 'alex'})`
|
|
23
|
+
*
|
|
24
|
+
* @param params
|
|
25
|
+
*/
|
|
19
26
|
function checkAndValidateObjectSyntax(source) {
|
|
20
27
|
if (source.startsWith('{')) {
|
|
21
28
|
return `(${source})`;
|
|
@@ -76,6 +83,7 @@ function parseBaseNode(base) {
|
|
|
76
83
|
}
|
|
77
84
|
function parseChild(child) {
|
|
78
85
|
if (child instanceof DomElementNode) {
|
|
86
|
+
// DomElementNode
|
|
79
87
|
parseBaseNode(child);
|
|
80
88
|
parseDomParentNode(child);
|
|
81
89
|
}
|
|
@@ -83,8 +91,10 @@ function parseChild(child) {
|
|
|
83
91
|
let expressions = [];
|
|
84
92
|
child.templateExpressions = expressions;
|
|
85
93
|
if (child.value) {
|
|
94
|
+
// use shorthand syntax, possible mixed with input and outputs
|
|
86
95
|
const info = DirectiveExpressionParser.parse(child.name.substring(1), child.value);
|
|
87
96
|
expressions.push(...info.templateExpressions.map(template => JavaScriptParser.parseScript(template)));
|
|
97
|
+
// <div let-i="index">{{item}}</div>
|
|
88
98
|
searchForLetAttributes(child, expressions);
|
|
89
99
|
if (info.directiveInputs.size > 0) {
|
|
90
100
|
const ref = ClassRegistryProvider.getDirectiveRef(child.name);
|
|
@@ -102,6 +112,8 @@ function parseChild(child) {
|
|
|
102
112
|
else {
|
|
103
113
|
searchForLetAttributes(child, expressions);
|
|
104
114
|
}
|
|
115
|
+
// DomDirectiveNode
|
|
116
|
+
// in case if add input/output support need to handle that here.
|
|
105
117
|
parseChild(child.node);
|
|
106
118
|
parseBaseNode(child);
|
|
107
119
|
}
|
package/html/expression.js.map
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AAC,CAAC,CAAC,CAAC,CAAC;QAC3E,MAAM,UAAU,GAAG,OAAO,QAAQ,MAAM,CAAC,OAAO,IAAI,CAAC,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QACrG,WAAW,CAAC,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,kBAAkB,CAAC,MAAqB;IAChD,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,IAAa;IACjD,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, createLiveAttribute,\n\tDomStructuralDirectiveNode, DomElementNode, DomNode,\n\tDomFragmentNode, DomParentNode, ElementAttribute,\n\tisLiveTextContent, LiveAttribute, LiveTextContent,\n\tDomStructuralDirectiveNodeUpgrade, DomAttributeDirectiveNode\n} from '@ibyar/elements';\nimport {\n\tExpressionNode, expressionVisitor, Identifier,\n\tJavaScriptParser, LanguageMode, MemberExpression, PipelineExpression\n} from '@ibyar/expressions';\nimport {\n\tBindingAssignment,\n\tOneWayAssignmentExpression,\n\tTwoWayAssignmentExpression\n} from '../binding/binding.expressions.js';\nimport { DirectiveExpressionParser } from '../directive/parser.js';\nimport { ClassRegistryProvider } from '../providers/provider.js';\n\ndeclare module '@ibyar/elements' {\n\texport interface ElementAttribute<N, V> {\n\t\texpression: ExpressionNode;\n\t}\n\n\texport interface LiveAttribute {\n\t\texpression: BindingAssignment;\n\t\tpipelineNames?: string[];\n\t}\n\n\texport interface LiveTextContent {\n\t\texpression: OneWayAssignmentExpression;\n\t\tpipelineNames?: string[];\n\t}\n\texport interface DomStructuralDirectiveNodeUpgrade extends DomStructuralDirectiveNode {\n\t\t/**\n\t\t * create a new scope for a template and bind the new variables to the directive scope.\n\t\t * \n\t\t * execution for let-i=\"index\".\n\t\t */\n\t\ttemplateExpressions: ExpressionNode[];\n\t}\n\n\texport interface DomAttributeDirectiveNodeUpgrade extends DomAttributeDirectiveNode {\n\n\t}\n}\n\nconst ThisTextContent = JavaScriptParser.parseScript('this.textContent') as MemberExpression;\nfunction parseLiveText(text: LiveTextContent) {\n\tconst textExpression = JavaScriptParser.parse(text.value);\n\ttext.expression = new OneWayAssignmentExpression(ThisTextContent, textExpression);\n\ttext.pipelineNames = getPipelineNames(textExpression);\n}\n\nfunction convertToMemberAccessStyle(source: string | string[]) {\n\tconst dashSplits = Array.isArray(source) ? source : 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) {\n\tconst elementSource = `this.${convertToMemberAccessStyle(attr.name)}`;\n\tconst elementExpression = JavaScriptParser.parseScript(elementSource);\n\tconst modelExpression = JavaScriptParser.parseScript(checkAndValidateObjectSyntax(attr.value));\n\tif (elementExpression instanceof MemberExpression\n\t\t&& (modelExpression instanceof MemberExpression || modelExpression instanceof Identifier)) {\n\t\tattr.expression = new TwoWayAssignmentExpression(elementExpression, modelExpression);\n\t} else {\n\t\tconsole.error(`${attr.name}=\"${attr.value}\"\" is not a valid MemberExpression or Identifier 'x.y.z'`);\n\t}\n\n}\n\nfunction getPipelineNames(modelExpression: ExpressionNode): string[] | undefined {\n\tconst pipelineNames: string[] = [];\n\texpressionVisitor.visit(modelExpression, (expression, type, control) => {\n\t\tif (type === 'PipelineExpression') {\n\t\t\tconst pipelineName = (expression as PipelineExpression).getRight();\n\t\t\tif (pipelineName instanceof Identifier) {\n\t\t\t\tpipelineNames.push(pipelineName.getName() as string);\n\t\t\t}\n\t\t}\n\t});\n\treturn pipelineNames.length ? pipelineNames : undefined;\n}\n\nfunction parseLiveAttributeUpdateElement(attr: LiveAttribute) {\n\tconst elementSource = `this.${convertToMemberAccessStyle(attr.name)}`;\n\tconst elementExpression = JavaScriptParser.parseScript(elementSource);\n\tconst modelExpression = JavaScriptParser.parseScript(checkAndValidateObjectSyntax(attr.value));\n\tif (elementExpression instanceof MemberExpression) {\n\t\tattr.expression = new OneWayAssignmentExpression(elementExpression, modelExpression);\n\t} else {\n\t\tconsole.error(`${attr.name} is not a valid MemberExpression 'x.y.z'`);\n\t}\n\tattr.pipelineNames = getPipelineNames(modelExpression);\n}\n\nfunction parseOutputExpression(attr: ElementAttribute<string, string>) {\n\tattr.expression = JavaScriptParser.parseScript(attr.value);\n}\n\nfunction parseAttributeDirectives(directive: DomAttributeDirectiveNode) {\n\tdirective.inputs?.forEach(parseLiveAttributeUpdateElement);\n\tdirective.outputs?.forEach(parseOutputExpression);\n\tdirective.twoWayBinding?.forEach(parseLiveAttribute);\n\tdirective.templateAttrs?.forEach(parseLiveAttributeUpdateElement);\n}\n\nfunction parseBaseNode(base: BaseNode) {\n\tbase.inputs?.forEach(parseLiveAttributeUpdateElement);\n\tbase.outputs?.forEach(parseOutputExpression);\n\tbase.twoWayBinding?.forEach(parseLiveAttribute);\n\tbase.templateAttrs?.forEach(parseLiveAttributeUpdateElement);\n\tbase.attributeDirectives?.forEach(parseAttributeDirectives);\n}\n\nfunction parseChild(child: DomNode) {\n\tif (child instanceof DomElementNode) {\n\t\t// DomElementNode\n\t\tparseBaseNode(child);\n\t\tparseDomParentNode(child);\n\t} else if (child instanceof DomStructuralDirectiveNode) {\n\t\tlet expressions: ExpressionNode[] = [];\n\t\t(child as DomStructuralDirectiveNodeUpgrade).templateExpressions = expressions;\n\t\tif (child.value) {\n\t\t\t// use shorthand syntax, possible mixed with input and outputs\n\t\t\tconst info = DirectiveExpressionParser.parse(child.name.substring(1), child.value);\n\t\t\texpressions.push(...info.templateExpressions.map(template => JavaScriptParser.parseScript(template)));\n\t\t\t// <div let-i=\"index\">{{item}}</div>\n\n\t\t\tsearchForLetAttributes(child, expressions);\n\n\t\t\tif (info.directiveInputs.size > 0) {\n\t\t\t\tconst ref = ClassRegistryProvider.getDirectiveRef(child.name);\n\t\t\t\tif (!ref?.inputs?.length) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tchild.inputs ??= [];\n\t\t\t\tinfo.directiveInputs.forEach((expression, input) => {\n\t\t\t\t\tconst modelName = ref?.inputs.find(i => i.viewAttribute === input)?.modelProperty ?? input;\n\t\t\t\t\tconst attr: LiveAttribute = createLiveAttribute(modelName, expression);\n\t\t\t\t\t(child.inputs ??= []).push(attr);\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\tsearchForLetAttributes(child, expressions);\n\t\t}\n\t\t// DomDirectiveNode\n\t\t// in case if add input/output support need to handle that here.\n\t\tparseChild(child.node);\n\t\tparseBaseNode(child);\n\t} else if (isLiveTextContent(child)) {\n\t\tparseLiveText(child);\n\t} else if (child instanceof DomFragmentNode) {\n\t\tparseDomParentNode(child);\n\t}\n}\n\nfunction searchForLetAttributes(child: DomStructuralDirectiveNode, expressions: ExpressionNode[]) {\n\tconst templateExpressionsFromInput = child.attributes?.filter(attr => attr.name.startsWith('let-'));\n\ttemplateExpressionsFromInput?.forEach(attr => {\n\t\tchild.attributes!.splice(child.attributes!.indexOf(attr), 1);\n\t\tconst attrName = convertToMemberAccessStyle(attr.name.split('-').slice(1));\n\t\tconst expression = `let ${attrName} = ${(typeof attr.value == 'string') ? attr.value : '$implicit'}`;\n\t\texpressions.push(JavaScriptParser.parseScript(expression));\n\t});\n}\n\nfunction parseDomParentNode(parent: DomParentNode) {\n\tparent.children?.forEach(parseChild);\n}\n\nexport function buildExpressionNodes(node: DomNode) {\n\tif (node instanceof DomFragmentNode) {\n\t\tparseDomParentNode(node);\n\t} else {\n\t\tparseChild(node);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"expression.js","sourceRoot":"","sources":["../../../src/core/html/expression.ts"],"names":[],"mappings":"AAAA,OAAO,EACI,mBAAmB,EAC7B,0BAA0B,EAAE,cAAc,EAC1C,eAAe,EACf,iBAAiB,EAEjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACU,iBAAiB,EAAE,UAAU,EAC7C,gBAAgB,EAAgB,gBAAgB,EAChD,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAEN,0BAA0B,EAC1B,0BAA0B,EAC1B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AA8BjE,MAAM,eAAe,GAAG,gBAAgB,CAAC,WAAW,CAAC,kBAAkB,CAAqB,CAAC;AAC7F,SAAS,aAAa,CAAC,IAAqB;IAC3C,MAAM,cAAc,GAAG,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1D,IAAI,CAAC,UAAU,GAAG,IAAI,0BAA0B,CAAC,eAAe,EAAE,cAAc,CAAC,CAAC;IAClF,IAAI,CAAC,aAAa,GAAG,gBAAgB,CAAC,cAAc,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,0BAA0B,CAAC,MAAyB;IAC5D,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtE,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QAC5B,OAAO,MAAM,CAAC;KACd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AI,CAAC,EAAE;QAC5C,KAAK,CAAC,UAAW,CAAC,MAAM,CAAC,KAAK,CAAC,UAAW,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7D,MAAM,QAAQ,GAAG,0BAA0B,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3E,MAAM,UAAU,GAAG,OAAO,QAAQ,MAAM,CAAC,OAAO,IAAI,CAAC,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QACrG,WAAW,CAAC,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,kBAAkB,CAAC,MAAqB;IAChD,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,IAAa;IACjD,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, createLiveAttribute,\n\tDomStructuralDirectiveNode, DomElementNode, DomNode,\n\tDomFragmentNode, DomParentNode, ElementAttribute,\n\tisLiveTextContent, LiveAttribute, LiveTextContent,\n\tDomStructuralDirectiveNodeUpgrade, DomAttributeDirectiveNode\n} from '@ibyar/elements';\nimport {\n\tExpressionNode, expressionVisitor, Identifier,\n\tJavaScriptParser, LanguageMode, MemberExpression, PipelineExpression\n} from '@ibyar/expressions';\nimport {\n\tBindingAssignment,\n\tOneWayAssignmentExpression,\n\tTwoWayAssignmentExpression\n} from '../binding/binding.expressions.js';\nimport { DirectiveExpressionParser } from '../directive/parser.js';\nimport { ClassRegistryProvider } from '../providers/provider.js';\n\ndeclare module '@ibyar/elements' {\n\texport interface ElementAttribute<N, V> {\n\t\texpression: ExpressionNode;\n\t}\n\n\texport interface LiveAttribute {\n\t\texpression: BindingAssignment;\n\t\tpipelineNames?: string[];\n\t}\n\n\texport interface LiveTextContent {\n\t\texpression: OneWayAssignmentExpression;\n\t\tpipelineNames?: string[];\n\t}\n\texport interface DomStructuralDirectiveNodeUpgrade extends DomStructuralDirectiveNode {\n\t\t/**\n\t\t * create a new scope for a template and bind the new variables to the directive scope.\n\t\t * \n\t\t * execution for let-i=\"index\".\n\t\t */\n\t\ttemplateExpressions: ExpressionNode[];\n\t}\n\n\texport interface DomAttributeDirectiveNodeUpgrade extends DomAttributeDirectiveNode {\n\n\t}\n}\n\nconst ThisTextContent = JavaScriptParser.parseScript('this.textContent') as MemberExpression;\nfunction parseLiveText(text: LiveTextContent) {\n\tconst textExpression = JavaScriptParser.parse(text.value);\n\ttext.expression = new OneWayAssignmentExpression(ThisTextContent, textExpression);\n\ttext.pipelineNames = getPipelineNames(textExpression);\n}\n\nfunction convertToMemberAccessStyle(source: string | string[]) {\n\tconst dashSplits = Array.isArray(source) ? source : 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) {\n\tconst elementSource = `this.${convertToMemberAccessStyle(attr.name)}`;\n\tconst elementExpression = JavaScriptParser.parseScript(elementSource);\n\tconst modelExpression = JavaScriptParser.parseScript(checkAndValidateObjectSyntax(attr.value));\n\tif (elementExpression instanceof MemberExpression\n\t\t&& (modelExpression instanceof MemberExpression || modelExpression instanceof Identifier)) {\n\t\tattr.expression = new TwoWayAssignmentExpression(elementExpression, modelExpression);\n\t} else {\n\t\tconsole.error(`${attr.name}=\"${attr.value}\"\" is not a valid MemberExpression or Identifier 'x.y.z'`);\n\t}\n\n}\n\nfunction getPipelineNames(modelExpression: ExpressionNode): string[] | undefined {\n\tconst pipelineNames: string[] = [];\n\texpressionVisitor.visit(modelExpression, (expression, type, control) => {\n\t\tif (type === 'PipelineExpression') {\n\t\t\tconst pipelineName = (expression as PipelineExpression).getRight();\n\t\t\tif (pipelineName instanceof Identifier) {\n\t\t\t\tpipelineNames.push(pipelineName.getName() as string);\n\t\t\t}\n\t\t}\n\t});\n\treturn pipelineNames.length ? pipelineNames : undefined;\n}\n\nfunction parseLiveAttributeUpdateElement(attr: LiveAttribute) {\n\tconst elementSource = `this.${convertToMemberAccessStyle(attr.name)}`;\n\tconst elementExpression = JavaScriptParser.parseScript(elementSource);\n\tconst modelExpression = JavaScriptParser.parseScript(checkAndValidateObjectSyntax(attr.value));\n\tif (elementExpression instanceof MemberExpression) {\n\t\tattr.expression = new OneWayAssignmentExpression(elementExpression, modelExpression);\n\t} else {\n\t\tconsole.error(`${attr.name} is not a valid MemberExpression 'x.y.z'`);\n\t}\n\tattr.pipelineNames = getPipelineNames(modelExpression);\n}\n\nfunction parseOutputExpression(attr: ElementAttribute<string, string>) {\n\tattr.expression = JavaScriptParser.parseScript(attr.value);\n}\n\nfunction parseAttributeDirectives(directive: DomAttributeDirectiveNode) {\n\tdirective.inputs?.forEach(parseLiveAttributeUpdateElement);\n\tdirective.outputs?.forEach(parseOutputExpression);\n\tdirective.twoWayBinding?.forEach(parseLiveAttribute);\n\tdirective.templateAttrs?.forEach(parseLiveAttributeUpdateElement);\n}\n\nfunction parseBaseNode(base: BaseNode) {\n\tbase.inputs?.forEach(parseLiveAttributeUpdateElement);\n\tbase.outputs?.forEach(parseOutputExpression);\n\tbase.twoWayBinding?.forEach(parseLiveAttribute);\n\tbase.templateAttrs?.forEach(parseLiveAttributeUpdateElement);\n\tbase.attributeDirectives?.forEach(parseAttributeDirectives);\n}\n\nfunction parseChild(child: DomNode) {\n\tif (child instanceof DomElementNode) {\n\t\t// DomElementNode\n\t\tparseBaseNode(child);\n\t\tparseDomParentNode(child);\n\t} else if (child instanceof DomStructuralDirectiveNode) {\n\t\tlet expressions: ExpressionNode[] = [];\n\t\t(child as DomStructuralDirectiveNodeUpgrade).templateExpressions = expressions;\n\t\tif (child.value) {\n\t\t\t// use shorthand syntax, possible mixed with input and outputs\n\t\t\tconst info = DirectiveExpressionParser.parse(child.name.substring(1), child.value);\n\t\t\texpressions.push(...info.templateExpressions.map(template => JavaScriptParser.parseScript(template)));\n\t\t\t// <div let-i=\"index\">{{item}}</div>\n\n\t\t\tsearchForLetAttributes(child, expressions);\n\n\t\t\tif (info.directiveInputs.size > 0) {\n\t\t\t\tconst ref = ClassRegistryProvider.getDirectiveRef(child.name);\n\t\t\t\tif (!ref?.inputs?.length) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tchild.inputs ??= [];\n\t\t\t\tinfo.directiveInputs.forEach((expression, input) => {\n\t\t\t\t\tconst modelName = ref?.inputs.find(i => i.viewAttribute === input)?.modelProperty ?? input;\n\t\t\t\t\tconst attr: LiveAttribute = createLiveAttribute(modelName, expression);\n\t\t\t\t\t(child.inputs ??= []).push(attr);\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\tsearchForLetAttributes(child, expressions);\n\t\t}\n\t\t// DomDirectiveNode\n\t\t// in case if add input/output support need to handle that here.\n\t\tparseChild(child.node);\n\t\tparseBaseNode(child);\n\t} else if (isLiveTextContent(child)) {\n\t\tparseLiveText(child);\n\t} else if (child instanceof DomFragmentNode) {\n\t\tparseDomParentNode(child);\n\t}\n}\n\nfunction searchForLetAttributes(child: DomStructuralDirectiveNode, expressions: ExpressionNode[]) {\n\tconst templateExpressionsFromInput = child.attributes?.filter(attr => attr.name.startsWith('let-'));\n\ttemplateExpressionsFromInput?.forEach(attr => {\n\t\tchild.attributes!.splice(child.attributes!.indexOf(attr), 1);\n\t\tconst attrName = convertToMemberAccessStyle(attr.name.split('-').slice(1));\n\t\tconst expression = `let ${attrName} = ${(typeof attr.value == 'string') ? attr.value : '$implicit'}`;\n\t\texpressions.push(JavaScriptParser.parseScript(expression));\n\t});\n}\n\nfunction parseDomParentNode(parent: DomParentNode) {\n\tparent.children?.forEach(parseChild);\n}\n\nexport function buildExpressionNodes(node: DomNode) {\n\tif (node instanceof DomFragmentNode) {\n\t\tparseDomParentNode(node);\n\t} else {\n\t\tparseChild(node);\n\t}\n}\n"]}
|
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
import { ReactiveScopeControl, ScopeContext } from '@ibyar/expressions';
|
|
2
2
|
export declare abstract class ChangeDetectorRef {
|
|
3
|
+
/**
|
|
4
|
+
* used when want to update ui-view like, you want to replace an array with another
|
|
5
|
+
* without reflect changes on view until reattached again.
|
|
6
|
+
*/
|
|
3
7
|
abstract detach(): void;
|
|
8
|
+
/**
|
|
9
|
+
* apply all the not emitted changes, and continue emit in time.
|
|
10
|
+
*/
|
|
4
11
|
abstract reattach(): void;
|
|
12
|
+
/**
|
|
13
|
+
* apply changes now,
|
|
14
|
+
* will not effect the state of the detector wither if attached ot not.
|
|
15
|
+
*/
|
|
5
16
|
abstract markForCheck(): void;
|
|
6
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* create a change Detector Reference by property key.
|
|
20
|
+
*/
|
|
7
21
|
export declare function createChangeDetectorRef(scope: ReactiveScopeControl<ScopeContext>, propertyKey: keyof ScopeContext): ChangeDetectorRef;
|
|
@@ -15,6 +15,9 @@ class ChangeDetectorRefImpl extends ChangeDetectorRef {
|
|
|
15
15
|
this.changeDetectorRef.markForCheck();
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* create a change Detector Reference by property key.
|
|
20
|
+
*/
|
|
18
21
|
export function createChangeDetectorRef(scope, propertyKey) {
|
|
19
22
|
const changeDetectorRef = {
|
|
20
23
|
detach() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"change-detector-ref.js","sourceRoot":"","sources":["../../../src/core/linker/change-detector-ref.ts"],"names":[],"mappings":"AAEA,MAAM,OAAgB,iBAAiB;CAkBtC;AAED,MAAM,qBAAsB,SAAQ,iBAAiB;IACpD,YAAoB,iBAAoC;QAAI,KAAK,EAAE,CAAC;QAAhD,sBAAiB,GAAjB,iBAAiB,CAAmB;IAAa,CAAC;IACtE,MAAM;QACL,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,CAAC;IACjC,CAAC;IACD,QAAQ;QACP,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,CAAC;IACnC,CAAC;IACD,YAAY;QACX,IAAI,CAAC,iBAAiB,CAAC,YAAY,EAAE,CAAC;IACvC,CAAC;CACD;
|
|
1
|
+
{"version":3,"file":"change-detector-ref.js","sourceRoot":"","sources":["../../../src/core/linker/change-detector-ref.ts"],"names":[],"mappings":"AAEA,MAAM,OAAgB,iBAAiB;CAkBtC;AAED,MAAM,qBAAsB,SAAQ,iBAAiB;IACpD,YAAoB,iBAAoC;QAAI,KAAK,EAAE,CAAC;QAAhD,sBAAiB,GAAjB,iBAAiB,CAAmB;IAAa,CAAC;IACtE,MAAM;QACL,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,CAAC;IACjC,CAAC;IACD,QAAQ;QACP,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,CAAC;IACnC,CAAC;IACD,YAAY;QACX,IAAI,CAAC,iBAAiB,CAAC,YAAY,EAAE,CAAC;IACvC,CAAC;CACD;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAyC,EAAE,WAA+B;IACjH,MAAM,iBAAiB,GAAsB;QAC5C,MAAM;YACL,KAAK,CAAC,MAAM,EAAE,CAAC;QAChB,CAAC;QACD,QAAQ;YACP,KAAK,CAAC,QAAQ,EAAE,CAAC;QAClB,CAAC;QACD,YAAY;YACX,KAAK,CAAC,WAAW,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC;QACxD,CAAC;KACD,CAAC;IACF,OAAO,IAAI,qBAAqB,CAAC,iBAAiB,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import { ReactiveScopeControl, ScopeContext } from '@ibyar/expressions';\n\nexport abstract class ChangeDetectorRef {\n\n\t/**\n\t * used when want to update ui-view like, you want to replace an array with another \n\t * without reflect changes on view until reattached again.\n\t */\n\tabstract detach(): void;\n\n\t/**\n\t * apply all the not emitted changes, and continue emit in time.\n\t */\n\tabstract reattach(): void;\n\n\t/**\n\t * apply changes now,\n\t * will not effect the state of the detector wither if attached ot not.\n\t */\n\tabstract markForCheck(): void;\n}\n\nclass ChangeDetectorRefImpl extends ChangeDetectorRef {\n\tconstructor(private changeDetectorRef: ChangeDetectorRef) { super(); }\n\tdetach(): void {\n\t\tthis.changeDetectorRef.detach();\n\t}\n\treattach(): void {\n\t\tthis.changeDetectorRef.reattach();\n\t}\n\tmarkForCheck(): void {\n\t\tthis.changeDetectorRef.markForCheck();\n\t}\n}\n\n/**\n * create a change Detector Reference by property key.\n */\nexport function createChangeDetectorRef(scope: ReactiveScopeControl<ScopeContext>, propertyKey: keyof ScopeContext): ChangeDetectorRef {\n\tconst changeDetectorRef: ChangeDetectorRef = {\n\t\tdetach() {\n\t\t\tscope.detach();\n\t\t},\n\t\treattach() {\n\t\t\tscope.reattach();\n\t\t},\n\t\tmarkForCheck() {\n\t\t\tscope.emitChanges(propertyKey, scope.get(propertyKey));\n\t\t}\n\t};\n\treturn new ChangeDetectorRefImpl(changeDetectorRef);\n}\n"]}
|
package/linker/template-ref.d.ts
CHANGED
|
@@ -5,7 +5,19 @@ import { StructuralDirective } from '../directive/directive.js';
|
|
|
5
5
|
import { ComponentRender } from '../view/render.js';
|
|
6
6
|
import { EmbeddedViewRef } from './view-ref.js';
|
|
7
7
|
export declare abstract class TemplateRef {
|
|
8
|
+
/**
|
|
9
|
+
* get the current ref of this template
|
|
10
|
+
*/
|
|
8
11
|
abstract get astNode(): DomNode;
|
|
12
|
+
/**
|
|
13
|
+
* Instantiates an embedded view based on this template,
|
|
14
|
+
* `Not attached to the view`.
|
|
15
|
+
* @param context The data-binding context of the embedded view, as declared
|
|
16
|
+
* in the `<template>` usage.
|
|
17
|
+
*
|
|
18
|
+
* To insert it to a view need to use a `ViewContainerRef.createEmbeddedView()`
|
|
19
|
+
* @returns The new embedded view object.
|
|
20
|
+
*/
|
|
9
21
|
abstract createEmbeddedView<C extends object>(context: C, parentNode: Node): EmbeddedViewRef<C>;
|
|
10
22
|
}
|
|
11
23
|
export declare class TemplateRefImpl extends TemplateRef {
|
package/linker/template-ref.js
CHANGED
|
@@ -37,9 +37,11 @@ export class TemplateRefImpl extends TemplateRef {
|
|
|
37
37
|
if (!this.templateExpressions?.length) {
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
+
// init value
|
|
40
41
|
this.templateExpressions.forEach(expression => {
|
|
41
42
|
expression.get(sandBox);
|
|
42
43
|
});
|
|
44
|
+
// subscribe to changes
|
|
43
45
|
const scopeSubscriptions = [];
|
|
44
46
|
this.templateExpressions.forEach(expression => {
|
|
45
47
|
const events = expression.events();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-ref.js","sourceRoot":"","sources":["../../../src/core/linker/template-ref.ts"],"names":[],"mappings":"AACA,OAAO,EACN,qBAAqB,EACrB,2BAA2B,EACR,KAAK,EACxB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAmB,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAErE,MAAM,OAAgB,WAAW;CAiBhC;AAGD,MAAM,OAAO,eAAgB,SAAQ,WAAW;IAG/C,YACS,MAA4B,EAC5B,IAAa,EACb,KAAY,EACZ,mBAAqC;QAE7C,KAAK,EAAE,CAAC;QALA,WAAM,GAAN,MAAM,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E;gBAC3B,MAAM,YAAY,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE;oBACtD,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBACzB,CAAC,CAAC,CAAC;gBACH,kBAAkB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YACvC,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,OAAO,kBAAkB,CAAC;IAC3B,CAAC;CACD","sourcesContent":["import { DomNode, htmlParser } from '@ibyar/elements';\nimport {\n\tcreateProxyForContext, ExpressionNode,\n\tfindReactiveScopeByEventMap, ScopeContext,\n\tScopeSubscription, Stack\n} from '@ibyar/expressions';\nimport { HTMLComponent } from '../component/custom-element.js';\nimport { StructuralDirective } from '../directive/directive.js';\nimport { ComponentRender } from '../view/render.js';\nimport { EmbeddedViewRef, EmbeddedViewRefImpl } from './view-ref.js';\n\nexport abstract class TemplateRef {\n\n\t/**\n\t * get the current ref of this template\n\t */\n\tabstract get astNode(): DomNode;\n\n\t/**\n\t * Instantiates an embedded view based on this template,\n\t * `Not attached to the view`.\n\t * @param context The data-binding context of the embedded view, as declared\n\t * in the `<template>` usage.\n\t * \n\t * To insert it to a view need to use a `ViewContainerRef.createEmbeddedView()`\n\t * @returns The new embedded view object.\n\t */\n\tabstract createEmbeddedView<C extends object>(context: C, parentNode: Node): EmbeddedViewRef<C>;\n}\n\n\nexport class TemplateRefImpl extends TemplateRef {\n\tprivate _host: HTMLComponent<any> | StructuralDirective;\n\n\tconstructor(\n\t\tprivate render: ComponentRender<any>,\n\t\tprivate node: DomNode,\n\t\tprivate stack: Stack,\n\t\tprivate templateExpressions: ExpressionNode[],\n\t) {\n\t\tsuper();\n\t}\n\tget astNode(): DomNode {\n\t\treturn this.node;\n\t}\n\tset host(host: HTMLComponent<any> | StructuralDirective) {\n\t\tthis._host = host;\n\t}\n\tcreateEmbeddedView<C extends object>(context: C, parentNode: Node): EmbeddedViewRef<C> {\n\t\tconst directiveStack = this.stack.copyStack();\n\n\t\tconst templateScope = directiveStack.pushReactiveScope();\n\n\t\tconst sandBox = new Stack();\n\t\tconst contextScope = sandBox.pushReactiveScopeFor(context ?? {});\n\t\tsandBox.pushScope(templateScope);\n\n\t\tconst elements: Node[] = [];\n\t\tconst contextProxy = createProxyForContext(contextScope);\n\t\tconst subscriptions: ScopeSubscription<ScopeContext>[] = [];\n\t\tconst embeddedViewRef = new EmbeddedViewRefImpl(contextProxy, elements, subscriptions);\n\t\tconst scopeSubscriptions = this.executeTemplateExpressions(sandBox);\n\t\tscopeSubscriptions && subscriptions.push(...scopeSubscriptions);\n\n\t\tconst fragment = document.createDocumentFragment();\n\t\tthis.render.appendChildToParent(fragment, this.node, directiveStack, parentNode, subscriptions, this._host);\n\n\t\tfragment.childNodes.forEach(item => elements.push(item));\n\t\treturn embeddedViewRef;\n\t}\n\tprivate executeTemplateExpressions(sandBox: Stack): ScopeSubscription<ScopeContext>[] | undefined {\n\t\tif (!this.templateExpressions?.length) {\n\t\t\treturn;\n\t\t}\n\t\t// init value\n\t\tthis.templateExpressions.forEach(expression => {\n\t\t\texpression.get(sandBox);\n\t\t});\n\n\t\t// subscribe to changes\n\t\tconst scopeSubscriptions: ScopeSubscription<object>[] = [];\n\t\tthis.templateExpressions.forEach(expression => {\n\t\t\tconst events = expression.events();\n\t\t\tconst scopeTuples = findReactiveScopeByEventMap(events, sandBox);\n\t\t\tscopeTuples.forEach(tuple => {\n\t\t\t\tconst subscription = tuple[1].subscribe(tuple[0], () => {\n\t\t\t\t\texpression.get(sandBox);\n\t\t\t\t});\n\t\t\t\tscopeSubscriptions.push(subscription);\n\t\t\t});\n\t\t});\n\t\treturn scopeSubscriptions;\n\t}\n}\n"]}
|
|
@@ -10,16 +10,94 @@ export declare type ViewContainerComponentOptions = {
|
|
|
10
10
|
selector?: string;
|
|
11
11
|
};
|
|
12
12
|
export declare abstract class ViewContainerRef {
|
|
13
|
+
/**
|
|
14
|
+
* Anchor element that specifies the location of this container in the containing view.
|
|
15
|
+
* Each view container can have only one anchor element, and each anchor element
|
|
16
|
+
* can have only a single view container.
|
|
17
|
+
*
|
|
18
|
+
* Root elements of views attached to this container become siblings of the anchor element in
|
|
19
|
+
* the rendered view.
|
|
20
|
+
*
|
|
21
|
+
* Access the `ViewContainerRef` of an element by placing a `Directive` injected
|
|
22
|
+
* with `ViewContainerRef` on the element, or use a `ViewChild` query.
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
13
25
|
abstract get anchorElement(): Element;
|
|
26
|
+
/**
|
|
27
|
+
* Destroys all views in this container.
|
|
28
|
+
*/
|
|
14
29
|
abstract clear(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Retrieves a view from this container.
|
|
32
|
+
* @param index The 0-based index of the view to retrieve.
|
|
33
|
+
* @returns The `ViewRef` instance, or null if the index is out of range.
|
|
34
|
+
*/
|
|
15
35
|
abstract get(index: number): ViewRef | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Reports how many views are currently attached to this container.
|
|
38
|
+
* @returns The number of views.
|
|
39
|
+
*/
|
|
16
40
|
abstract get length(): number;
|
|
41
|
+
/**
|
|
42
|
+
* Instantiates an embedded view and inserts it
|
|
43
|
+
* into this container.
|
|
44
|
+
* @param templateRef The HTML template that defines the view.
|
|
45
|
+
* @param context The data-binding context of the embedded view, as declared
|
|
46
|
+
* in the `<ng-template>` usage.
|
|
47
|
+
* @param index The 0-based index at which to insert the new view into this container.
|
|
48
|
+
* If not specified, appends the new view as the last entry.
|
|
49
|
+
*
|
|
50
|
+
* @returns The `ViewRef` instance for the newly created view.
|
|
51
|
+
*/
|
|
17
52
|
abstract createEmbeddedView<C extends {}>(templateRef: TemplateRef, options?: ViewContainerOptions<C>): EmbeddedViewRef<C>;
|
|
53
|
+
/**
|
|
54
|
+
* Instantiates a single component and inserts its host view into this container.
|
|
55
|
+
*
|
|
56
|
+
* @param componentType Component Type to use.
|
|
57
|
+
* @param options An object that contains extra parameters:
|
|
58
|
+
* * index: the index at which to insert the new component's host view into this container.
|
|
59
|
+
* If not specified, appends the new view as the last entry.
|
|
60
|
+
* * selector: the tag name of the new create component that attached with this model class.
|
|
61
|
+
* Any Model class can have many views with different selectors.
|
|
62
|
+
*
|
|
63
|
+
* @returns The new `HTMLComponent` which contains the component instance and the host view.
|
|
64
|
+
*/
|
|
18
65
|
abstract createComponent<C extends {}>(componentType: TypeOf<C>, options?: ViewContainerComponentOptions): C;
|
|
66
|
+
/**
|
|
67
|
+
* Inserts a view into this container.
|
|
68
|
+
* @param viewRef The view to insert.
|
|
69
|
+
* @param index The 0-based index at which to insert the view.
|
|
70
|
+
* If not specified, appends the new view as the last entry.
|
|
71
|
+
* @returns The inserted `ViewRef` instance.
|
|
72
|
+
*
|
|
73
|
+
*/
|
|
19
74
|
abstract insert(viewRef: ViewRef, index?: number): ViewRef;
|
|
75
|
+
/**
|
|
76
|
+
* Moves a view to a new location in this container.
|
|
77
|
+
* @param viewRef The view to move.
|
|
78
|
+
* @param newIndex The 0-based index of the new location.
|
|
79
|
+
* @returns The moved `ViewRef` instance.
|
|
80
|
+
*/
|
|
20
81
|
abstract move(viewRef: ViewRef, newIndex: number): ViewRef;
|
|
82
|
+
/**
|
|
83
|
+
* Returns the index of a view within the current container.
|
|
84
|
+
* @param viewRef The view to query.
|
|
85
|
+
* @returns The 0-based index of the view's position in this container,
|
|
86
|
+
* or `-1` if this container doesn't contain the view.
|
|
87
|
+
*/
|
|
21
88
|
abstract indexOf(viewRef: ViewRef): number;
|
|
89
|
+
/**
|
|
90
|
+
* Destroys a view attached to this container
|
|
91
|
+
* @param index The 0-based index of the view to destroy.
|
|
92
|
+
* If not specified, the last view in the container is removed.
|
|
93
|
+
*/
|
|
22
94
|
abstract remove(index?: number): void;
|
|
95
|
+
/**
|
|
96
|
+
* Detaches a view from this container without destroying it.
|
|
97
|
+
* Use along with `insert()` to move a view within the current container.
|
|
98
|
+
* @param index The 0-based index of the view to detach.
|
|
99
|
+
* If not specified, the last view in the container is detached.
|
|
100
|
+
*/
|
|
23
101
|
abstract detach(index?: number): ViewRef | undefined;
|
|
24
102
|
}
|
|
25
103
|
export declare class ViewContainerRefImpl extends ViewContainerRef {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view-container-ref.js","sourceRoot":"","sources":["../../../src/core/linker/view-container-ref.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEvD,OAAO,EAAmB,mBAAmB,EAAW,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAWnD,MAAM,OAAgB,gBAAgB;CAqGrC;AAGD,MAAM,OAAO,oBAAqB,SAAQ,gBAAgB;IAIzD,YACS,MAAe,EACf,YAAqB;QAE7B,KAAK,EAAE,CAAC;QAHA,WAAM,GAAN,MAAM,CAAS;QACf,iBAAY,GAAZ,YAAY,CAAS;QAJtB,UAAK,GAA2B,EAAE,CAAC;IAO3C,CAAC;IACD,IAAa,aAAa;QACzB,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IACD,IAAa,MAAM;QAClB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC1B,CAAC;IACQ,KAAK;QACb,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,EAAE;gBAC7B,GAAG,CAAC,OAAO,EAAE,CAAC;aACd;YACD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;SACrB;IACF,CAAC;IACQ,GAAG,CAAC,KAAa;QACzB,IAAI,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;YAC/B,OAAO,SAAS,CAAC;SACjB;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IACQ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TypeOf } from '../utils/typeof.js';\nimport { Components } from '../component/component.js';\nimport { TemplateRef } from './template-ref.js';\nimport { EmbeddedViewRef, EmbeddedViewRefImpl, ViewRef } from './view-ref.js';\nimport { getComponentView } from '../view/view.js';\n\nexport type ViewContainerOptions<C> = {\n\tindex?: number;\n\tcontext?: C;\n};\n\nexport type ViewContainerComponentOptions = {\n\tindex?: number | undefined;\n\tselector?: string;\n};\nexport abstract class ViewContainerRef {\n\n\t/**\n\t * Anchor element that specifies the location of this container in the containing view.\n\t * Each view container can have only one anchor element, and each anchor element\n\t * can have only a single view container.\n\t * \n\t * Root elements of views attached to this container become siblings of the anchor element in\n\t * the rendered view.\n\t *\n\t * Access the `ViewContainerRef` of an element by placing a `Directive` injected\n\t * with `ViewContainerRef` on the element, or use a `ViewChild` query.\n\t *\n\t */\n\tabstract get anchorElement(): Element;\n\n\t/**\n\t * Destroys all views in this container.\n\t */\n\tabstract clear(): void;\n\n\t/**\n\t * Retrieves a view from this container.\n\t * @param index The 0-based index of the view to retrieve.\n\t * @returns The `ViewRef` instance, or null if the index is out of range.\n\t */\n\tabstract get(index: number): ViewRef | undefined;\n\n\t/**\n\t * Reports how many views are currently attached to this container.\n\t * @returns The number of views.\n\t */\n\tabstract get length(): number;\n\n\t/**\n\t * Instantiates an embedded view and inserts it\n\t * into this container.\n\t * @param templateRef The HTML template that defines the view.\n\t * @param context The data-binding context of the embedded view, as declared\n\t * in the `<ng-template>` usage.\n\t * @param index The 0-based index at which to insert the new view into this container.\n\t * If not specified, appends the new view as the last entry.\n\t *\n\t * @returns The `ViewRef` instance for the newly created view.\n\t */\n\tabstract createEmbeddedView<C extends {}>(templateRef: TemplateRef, options?: ViewContainerOptions<C>): EmbeddedViewRef<C>;\n\n\t/**\n * Instantiates a single component and inserts its host view into this container.\n *\n * @param componentType Component Type to use.\n * @param options An object that contains extra parameters:\n * * index: the index at which to insert the new component's host view into this container.\n * If not specified, appends the new view as the last entry.\n * * selector: the tag name of the new create component that attached with this model class.\n * \t\t\tAny Model class can have many views with different selectors. \n *\n * @returns The new `HTMLComponent` which contains the component instance and the host view.\n */\n\tabstract createComponent<C extends {}>(componentType: TypeOf<C>, options?: ViewContainerComponentOptions): C;\n\n\t/**\n\t * Inserts a view into this container.\n\t * @param viewRef The view to insert.\n\t * @param index The 0-based index at which to insert the view.\n\t * If not specified, appends the new view as the last entry.\n\t * @returns The inserted `ViewRef` instance.\n\t *\n\t */\n\tabstract insert(viewRef: ViewRef, index?: number): ViewRef;\n\n\t/**\n\t * Moves a view to a new location in this container.\n\t * @param viewRef The view to move.\n\t * @param newIndex The 0-based index of the new location.\n\t * @returns The moved `ViewRef` instance.\n\t */\n\tabstract move(viewRef: ViewRef, newIndex: number): ViewRef;\n\n\t/**\n\t * Returns the index of a view within the current container.\n\t * @param viewRef The view to query.\n\t * @returns The 0-based index of the view's position in this container,\n\t * or `-1` if this container doesn't contain the view.\n\t */\n\tabstract indexOf(viewRef: ViewRef): number;\n\n\t/**\n\t * Destroys a view attached to this container\n\t * @param index The 0-based index of the view to destroy.\n\t * If not specified, the last view in the container is removed.\n\t */\n\tabstract remove(index?: number): void;\n\n\t/**\n\t * Detaches a view from this container without destroying it.\n\t * Use along with `insert()` to move a view within the current container.\n\t * @param index The 0-based index of the view to detach.\n\t * If not specified, the last view in the container is detached.\n\t */\n\tabstract detach(index?: number): ViewRef | undefined;\n}\n\n\nexport class ViewContainerRefImpl extends ViewContainerRef {\n\n\tprivate views: EmbeddedViewRef<any>[] = [];\n\n\tconstructor(\n\t\tprivate parent: Element,\n\t\tprivate firstComment: Comment\n\t) {\n\t\tsuper();\n\t}\n\toverride get anchorElement(): Element {\n\t\treturn this.parent;\n\t}\n\toverride get length(): number {\n\t\treturn this.views.length;\n\t}\n\toverride clear(): void {\n\t\tif (this.views.length > 0) {\n\t\t\tfor (const elm of this.views) {\n\t\t\t\telm.destroy();\n\t\t\t}\n\t\t\tthis.views.splice(0);\n\t\t}\n\t}\n\toverride get(index: number): ViewRef | undefined {\n\t\tif (index >= this.views.length) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.views[index];\n\t}\n\toverride detach(index?: number): ViewRef | undefined {\n\t\tindex ??= this.views.length - 1;\n\t\tconst viewRef = this.views[index];\n\t\tviewRef.detach();\n\t\tthis.views.splice(index, 1);\n\t\treturn viewRef;\n\t}\n\toverride indexOf(viewRef: EmbeddedViewRef<any>): number {\n\t\treturn this.views.indexOf(viewRef);\n\t}\n\toverride remove(index?: number): void {\n\t\tindex ??= this.views.length - 1;\n\t\tthis.views[index].destroy();\n\t\tthis.views.splice(index, 1);\n\t}\n\toverride insert(viewRef: EmbeddedViewRef<any>, index?: number): ViewRef {\n\t\tindex = ((index ??= this.views.length) > this.views.length) ? this.views.length : index;\n\t\tconst lastNode = index == 0 ? this.firstComment : this.views[index - 1].last;\n\t\tthis.views.splice(index, 0, viewRef);\n\t\tviewRef.after(lastNode);\n\t\treturn viewRef;\n\t}\n\toverride move(viewRef: EmbeddedViewRef<any>, newIndex: number): ViewRef {\n\t\tconst oldIndex = this.indexOf(viewRef);\n\t\tif (oldIndex > -1) {\n\t\t\tthis.detach(oldIndex);\n\t\t} else {\n\t\t\t// should remove it from the container first\n\t\t\tviewRef.detach();\n\t\t}\n\t\treturn this.insert(viewRef, newIndex);\n\t}\n\toverride createEmbeddedView<C extends {}>(templateRef: TemplateRef, options?: ViewContainerOptions<C>): EmbeddedViewRef<C> {\n\t\tconst viewRef = templateRef.createEmbeddedView<C>(options?.context || <C>{}, this.parent);\n\t\tthis.insert(viewRef, options?.index);\n\t\treturn viewRef;\n\t}\n\toverride createComponent<C extends {}>(componentType: TypeOf<C>, options?: ViewContainerComponentOptions): C {\n\t\tconst defaultTagName = Components.getComponentRef<C>(componentType).selector;\n\t\tconst ViewClass = getComponentView(componentType, options?.selector ?? defaultTagName);\n\t\tif (!ViewClass) {\n\t\t\tthrow new Error(`Can't find View component for class ${componentType.name}`);\n\t\t}\n\t\tconst component = new ViewClass();\n\t\tconst viewRef = new EmbeddedViewRefImpl<C>(component._proxyModel, [component]);\n\t\tthis.insert(viewRef, options?.index);\n\t\treturn component._proxyModel;\n\t}\n\n}\n"]}
|
|
1
|
+
{"version":3,"file":"view-container-ref.js","sourceRoot":"","sources":["../../../src/core/linker/view-container-ref.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEvD,OAAO,EAAmB,mBAAmB,EAAW,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAWnD,MAAM,OAAgB,gBAAgB;CAqGrC;AAGD,MAAM,OAAO,oBAAqB,SAAQ,gBAAgB;IAIzD,YACS,MAAe,EACf,YAAqB;QAE7B,KAAK,EAAE,CAAC;QAHA,WAAM,GAAN,MAAM,CAAS;QACf,iBAAY,GAAZ,YAAY,CAAS;QAJtB,UAAK,GAA2B,EAAE,CAAC;IAO3C,CAAC;IACD,IAAa,aAAa;QACzB,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IACD,IAAa,MAAM;QAClB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC1B,CAAC;IACQ,KAAK;QACb,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,EAAE;gBAC7B,GAAG,CAAC,OAAO,EAAE,CAAC;aACd;YACD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;SACrB;IACF,CAAC;IACQ,GAAG,CAAC,KAAa;QACzB,IAAI,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;YAC/B,OAAO,SAAS,CAAC;SACjB;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IACQ,MAAM,CAAC,KAAc;QAC7B,KAAK,KAAL,KAAK,GAAK,IAAI,CAAC,KAA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ateRef } from './template-ref.js';\nimport { EmbeddedViewRef, EmbeddedViewRefImpl, ViewRef } from './view-ref.js';\nimport { getComponentView } from '../view/view.js';\n\nexport type ViewContainerOptions<C> = {\n\tindex?: number;\n\tcontext?: C;\n};\n\nexport type ViewContainerComponentOptions = {\n\tindex?: number | undefined;\n\tselector?: string;\n};\nexport abstract class ViewContainerRef {\n\n\t/**\n\t * Anchor element that specifies the location of this container in the containing view.\n\t * Each view container can have only one anchor element, and each anchor element\n\t * can have only a single view container.\n\t * \n\t * Root elements of views attached to this container become siblings of the anchor element in\n\t * the rendered view.\n\t *\n\t * Access the `ViewContainerRef` of an element by placing a `Directive` injected\n\t * with `ViewContainerRef` on the element, or use a `ViewChild` query.\n\t *\n\t */\n\tabstract get anchorElement(): Element;\n\n\t/**\n\t * Destroys all views in this container.\n\t */\n\tabstract clear(): void;\n\n\t/**\n\t * Retrieves a view from this container.\n\t * @param index The 0-based index of the view to retrieve.\n\t * @returns The `ViewRef` instance, or null if the index is out of range.\n\t */\n\tabstract get(index: number): ViewRef | undefined;\n\n\t/**\n\t * Reports how many views are currently attached to this container.\n\t * @returns The number of views.\n\t */\n\tabstract get length(): number;\n\n\t/**\n\t * Instantiates an embedded view and inserts it\n\t * into this container.\n\t * @param templateRef The HTML template that defines the view.\n\t * @param context The data-binding context of the embedded view, as declared\n\t * in the `<ng-template>` usage.\n\t * @param index The 0-based index at which to insert the new view into this container.\n\t * If not specified, appends the new view as the last entry.\n\t *\n\t * @returns The `ViewRef` instance for the newly created view.\n\t */\n\tabstract createEmbeddedView<C extends {}>(templateRef: TemplateRef, options?: ViewContainerOptions<C>): EmbeddedViewRef<C>;\n\n\t/**\n * Instantiates a single component and inserts its host view into this container.\n *\n * @param componentType Component Type to use.\n * @param options An object that contains extra parameters:\n * * index: the index at which to insert the new component's host view into this container.\n * If not specified, appends the new view as the last entry.\n * * selector: the tag name of the new create component that attached with this model class.\n * \t\t\tAny Model class can have many views with different selectors. \n *\n * @returns The new `HTMLComponent` which contains the component instance and the host view.\n */\n\tabstract createComponent<C extends {}>(componentType: TypeOf<C>, options?: ViewContainerComponentOptions): C;\n\n\t/**\n\t * Inserts a view into this container.\n\t * @param viewRef The view to insert.\n\t * @param index The 0-based index at which to insert the view.\n\t * If not specified, appends the new view as the last entry.\n\t * @returns The inserted `ViewRef` instance.\n\t *\n\t */\n\tabstract insert(viewRef: ViewRef, index?: number): ViewRef;\n\n\t/**\n\t * Moves a view to a new location in this container.\n\t * @param viewRef The view to move.\n\t * @param newIndex The 0-based index of the new location.\n\t * @returns The moved `ViewRef` instance.\n\t */\n\tabstract move(viewRef: ViewRef, newIndex: number): ViewRef;\n\n\t/**\n\t * Returns the index of a view within the current container.\n\t * @param viewRef The view to query.\n\t * @returns The 0-based index of the view's position in this container,\n\t * or `-1` if this container doesn't contain the view.\n\t */\n\tabstract indexOf(viewRef: ViewRef): number;\n\n\t/**\n\t * Destroys a view attached to this container\n\t * @param index The 0-based index of the view to destroy.\n\t * If not specified, the last view in the container is removed.\n\t */\n\tabstract remove(index?: number): void;\n\n\t/**\n\t * Detaches a view from this container without destroying it.\n\t * Use along with `insert()` to move a view within the current container.\n\t * @param index The 0-based index of the view to detach.\n\t * If not specified, the last view in the container is detached.\n\t */\n\tabstract detach(index?: number): ViewRef | undefined;\n}\n\n\nexport class ViewContainerRefImpl extends ViewContainerRef {\n\n\tprivate views: EmbeddedViewRef<any>[] = [];\n\n\tconstructor(\n\t\tprivate parent: Element,\n\t\tprivate firstComment: Comment\n\t) {\n\t\tsuper();\n\t}\n\toverride get anchorElement(): Element {\n\t\treturn this.parent;\n\t}\n\toverride get length(): number {\n\t\treturn this.views.length;\n\t}\n\toverride clear(): void {\n\t\tif (this.views.length > 0) {\n\t\t\tfor (const elm of this.views) {\n\t\t\t\telm.destroy();\n\t\t\t}\n\t\t\tthis.views.splice(0);\n\t\t}\n\t}\n\toverride get(index: number): ViewRef | undefined {\n\t\tif (index >= this.views.length) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.views[index];\n\t}\n\toverride detach(index?: number): ViewRef | undefined {\n\t\tindex ??= this.views.length - 1;\n\t\tconst viewRef = this.views[index];\n\t\tviewRef.detach();\n\t\tthis.views.splice(index, 1);\n\t\treturn viewRef;\n\t}\n\toverride indexOf(viewRef: EmbeddedViewRef<any>): number {\n\t\treturn this.views.indexOf(viewRef);\n\t}\n\toverride remove(index?: number): void {\n\t\tindex ??= this.views.length - 1;\n\t\tthis.views[index].destroy();\n\t\tthis.views.splice(index, 1);\n\t}\n\toverride insert(viewRef: EmbeddedViewRef<any>, index?: number): ViewRef {\n\t\tindex = ((index ??= this.views.length) > this.views.length) ? this.views.length : index;\n\t\tconst lastNode = index == 0 ? this.firstComment : this.views[index - 1].last;\n\t\tthis.views.splice(index, 0, viewRef);\n\t\tviewRef.after(lastNode);\n\t\treturn viewRef;\n\t}\n\toverride move(viewRef: EmbeddedViewRef<any>, newIndex: number): ViewRef {\n\t\tconst oldIndex = this.indexOf(viewRef);\n\t\tif (oldIndex > -1) {\n\t\t\tthis.detach(oldIndex);\n\t\t} else {\n\t\t\t// should remove it from the container first\n\t\t\tviewRef.detach();\n\t\t}\n\t\treturn this.insert(viewRef, newIndex);\n\t}\n\toverride createEmbeddedView<C extends {}>(templateRef: TemplateRef, options?: ViewContainerOptions<C>): EmbeddedViewRef<C> {\n\t\tconst viewRef = templateRef.createEmbeddedView<C>(options?.context || <C>{}, this.parent);\n\t\tthis.insert(viewRef, options?.index);\n\t\treturn viewRef;\n\t}\n\toverride createComponent<C extends {}>(componentType: TypeOf<C>, options?: ViewContainerComponentOptions): C {\n\t\tconst defaultTagName = Components.getComponentRef<C>(componentType).selector;\n\t\tconst ViewClass = getComponentView(componentType, options?.selector ?? defaultTagName);\n\t\tif (!ViewClass) {\n\t\t\tthrow new Error(`Can't find View component for class ${componentType.name}`);\n\t\t}\n\t\tconst component = new ViewClass();\n\t\tconst viewRef = new EmbeddedViewRefImpl<C>(component._proxyModel, [component]);\n\t\tthis.insert(viewRef, options?.index);\n\t\treturn component._proxyModel;\n\t}\n\n}\n"]}
|
package/linker/view-ref.d.ts
CHANGED
|
@@ -1,18 +1,57 @@
|
|
|
1
1
|
import { ScopeContext, ScopeSubscription } from '@ibyar/expressions';
|
|
2
2
|
export declare abstract class ViewRef {
|
|
3
|
+
/**
|
|
4
|
+
* Destroys this view and all of the data structures associated with it.
|
|
5
|
+
*/
|
|
3
6
|
abstract destroy(): void;
|
|
7
|
+
/**
|
|
8
|
+
* Reports whether this view has been destroyed.
|
|
9
|
+
* @returns True after the `destroy()` method has been called, false otherwise.
|
|
10
|
+
*/
|
|
4
11
|
abstract get destroyed(): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* A lifecycle hook that provides additional developer-defined cleanup
|
|
14
|
+
* functionality for views.
|
|
15
|
+
* @param callback A handler function that cleans up developer-defined data
|
|
16
|
+
* associated with a view. Called when the `destroy()` method is invoked.
|
|
17
|
+
*/
|
|
5
18
|
abstract onDestroy(callback: Function): {
|
|
6
19
|
unsubscribe(): void;
|
|
7
20
|
};
|
|
8
21
|
}
|
|
9
22
|
export declare abstract class EmbeddedViewRef<C extends object> extends ViewRef {
|
|
23
|
+
/**
|
|
24
|
+
* The context for this view, inherited from the anchor element.
|
|
25
|
+
*/
|
|
10
26
|
abstract get context(): C;
|
|
27
|
+
/**
|
|
28
|
+
* The root nodes for this embedded view.
|
|
29
|
+
*/
|
|
11
30
|
abstract get rootNodes(): Node[];
|
|
31
|
+
/**
|
|
32
|
+
* the first node for this embedded view.
|
|
33
|
+
*/
|
|
12
34
|
abstract get first(): ChildNode;
|
|
35
|
+
/**
|
|
36
|
+
* the last node for this embedded view.
|
|
37
|
+
*/
|
|
13
38
|
abstract get last(): ChildNode;
|
|
39
|
+
/**
|
|
40
|
+
* insert view after the node.
|
|
41
|
+
* @param node
|
|
42
|
+
*/
|
|
14
43
|
abstract after(node: ChildNode): void;
|
|
44
|
+
/**
|
|
45
|
+
* insert view before the node.
|
|
46
|
+
* @param node
|
|
47
|
+
*/
|
|
15
48
|
abstract before(node: ChildNode): void;
|
|
49
|
+
/**
|
|
50
|
+
* remove the root nodes from the view, but keep reference to them.
|
|
51
|
+
*
|
|
52
|
+
* Detaches a view from this container without destroying it.
|
|
53
|
+
* Use along with after()/before() to move a view within the current container.
|
|
54
|
+
*/
|
|
16
55
|
abstract detach(): void;
|
|
17
56
|
}
|
|
18
57
|
export declare class EmbeddedViewRefImpl<C extends object> extends EmbeddedViewRef<C> {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ibyar/core",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.62",
|
|
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/tree/dev/packages/core",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@ibyar/elements": "^0.5.
|
|
27
|
-
"@ibyar/expressions": "^0.5.
|
|
26
|
+
"@ibyar/elements": "^0.5.62",
|
|
27
|
+
"@ibyar/expressions": "^0.5.62",
|
|
28
28
|
"reflect-metadata": "^0.1.13",
|
|
29
29
|
"tslib": "^2.4.0"
|
|
30
30
|
},
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"interceptor",
|
|
63
63
|
"typescript"
|
|
64
64
|
],
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "17e31ddaba2c87e6b98e1415de85f62cb5ba7ba9"
|
|
66
66
|
}
|
package/pipe/pipe.d.ts
CHANGED
|
@@ -2,6 +2,13 @@ import { ReactiveScopeControl, ReadOnlyScope, ScopeSubscription } from '@ibyar/e
|
|
|
2
2
|
import { OnDestroy } from '../component/lifecycle.js';
|
|
3
3
|
import { ChangeDetectorRef } from '../linker/change-detector-ref.js';
|
|
4
4
|
import { TypeOf } from '../utils/typeof.js';
|
|
5
|
+
/**
|
|
6
|
+
* Pipes are used as singleton
|
|
7
|
+
* it will be created if it needed, had no life cycle
|
|
8
|
+
*
|
|
9
|
+
* * no dependency injection applied on filters for now,
|
|
10
|
+
* TODO: add support of dependency injection
|
|
11
|
+
*/
|
|
5
12
|
export interface PipeTransform<T, U> {
|
|
6
13
|
transform(value: T, ...args: any[]): U;
|
|
7
14
|
}
|
package/providers/injector.js
CHANGED
|
@@ -11,6 +11,7 @@ export class Injector {
|
|
|
11
11
|
if (currentInstance)
|
|
12
12
|
return currentInstance;
|
|
13
13
|
const params = Reflect.getMetadata('design:paramtypes', constructor);
|
|
14
|
+
// We need to init each constructor function into it's instance
|
|
14
15
|
if (params) {
|
|
15
16
|
const argumentsInstances = params.map((paramter) => this.constructObject(paramter));
|
|
16
17
|
currentInstance = new constructor(...argumentsInstances);
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;QACvD,+DAA+D;QAC/D,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"]}
|
|
@@ -5,6 +5,23 @@ import { RenderHandler } from './render-handler.js';
|
|
|
5
5
|
declare type ElementScope = {
|
|
6
6
|
[element: string]: HTMLElement;
|
|
7
7
|
};
|
|
8
|
+
/**
|
|
9
|
+
* ```ts
|
|
10
|
+
* class View {
|
|
11
|
+
*
|
|
12
|
+
* @HostListener('window:load', ['$event.target', '"load"'])
|
|
13
|
+
* @HostListener('click', ['$event.target', '"click"'])
|
|
14
|
+
* public onClick(target: any, type: string){
|
|
15
|
+
* console.log(target, type);
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* window.addEventListener('load', $event => listener($event.target, 'load'));
|
|
21
|
+
*
|
|
22
|
+
* view.addEventListener('click', $event => listener($event.target, 'click'));
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
8
25
|
export declare class HostListenerHandler implements RenderHandler {
|
|
9
26
|
private listenerRef;
|
|
10
27
|
private element;
|
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import { JavaScriptParser, Stack } from '@ibyar/expressions';
|
|
2
|
+
/**
|
|
3
|
+
* ```ts
|
|
4
|
+
* class View {
|
|
5
|
+
*
|
|
6
|
+
* @HostListener('window:load', ['$event.target', '"load"'])
|
|
7
|
+
* @HostListener('click', ['$event.target', '"click"'])
|
|
8
|
+
* public onClick(target: any, type: string){
|
|
9
|
+
* console.log(target, type);
|
|
10
|
+
* }
|
|
11
|
+
* }
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* window.addEventListener('load', $event => listener($event.target, 'load'));
|
|
15
|
+
*
|
|
16
|
+
* view.addEventListener('click', $event => listener($event.target, 'click'));
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
2
19
|
export class HostListenerHandler {
|
|
3
20
|
constructor(listenerRef, element, elementScope) {
|
|
4
21
|
this.listenerRef = listenerRef;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-listener.handler.js","sourceRoot":"","sources":["../../../src/core/render/host-listener.handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,gBAAgB,EAAoC,KAAK,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"host-listener.handler.js","sourceRoot":"","sources":["../../../src/core/render/host-listener.handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,gBAAgB,EAAoC,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAOhH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,mBAAmB;IAsB/B,YAAoB,WAAwB,EAAU,OAA2B,EAAU,YAAyC;QAAhH,gBAAW,GAAX,WAAW,CAAa;QAAU,YAAO,GAAP,OAAO,CAAoB;QAAU,iBAAY,GAAZ,YAAY,CAA6B;QAX5H,aAAQ,GAAG,CAAC,KAAY,EAAE,EAAE;YACnC,MAAM,MAAM,GAAyB,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;YAClG,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE;gBACjC,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;gBACnE,MAAM,MAAM,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACxD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;gBAC/B,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,O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AQ,CAAC;oBAClB,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBACzB,CAAC,CAAC,CAAC;gBACH,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;aACrB;SACD;aAAM;YACN,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;YAC5C,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC;SAC3B;QACD,IAAI,CAAC,gBAAgB,EAAE,CAAC;IACzB,CAAC;IAEO,gBAAgB;QACvB,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9D,CAAC;IAEO,mBAAmB;QAC1B,IAAI,CAAC,MAAM,EAAE,mBAAmB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACjE,CAAC;IAED,SAAS;QACR,IAAI,CAAC,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAClC,CAAC;IAED,YAAY;QACX,IAAI,CAAC,iBAAiB,EAAE,KAAK,EAAE,CAAC;IACjC,CAAC;IAED,SAAS;QACR,IAAI,CAAC,iBAAiB,EAAE,WAAW,EAAE,CAAC;QACtC,IAAI,CAAC,mBAAmB,EAAE,CAAC;IAC5B,CAAC;CAED","sourcesContent":["import { ArrayExpression, JavaScriptParser, ReactiveScope, ScopeSubscription, Stack } from '@ibyar/expressions';\nimport { ListenerRef } from '../component/component.js';\nimport { HTMLComponent } from '../component/custom-element.js';\nimport { RenderHandler } from './render-handler.js';\n\ntype ElementScope = { [element: string]: HTMLElement };\n\n/**\n * ```ts\n * class View {\n * \n *\t@HostListener('window:load', ['$event.target', '\"load\"'])\n * \t@HostListener('click', ['$event.target', '\"click\"'])\n * \tpublic onClick(target: any, type: string){\n * \t\tconsole.log(target, type);\n * \t}\n * }\n * ```\n * \n * window.addEventListener('load', $event => listener($event.target, 'load'));\n * \n * view.addEventListener('click', $event => listener($event.target, 'click'));\n * \n */\nexport class HostListenerHandler implements RenderHandler {\n\n\tprivate source: HTMLElement | Window;\n\tprivate eventName: string;\n\n\tprivate argumentsExpression: ArrayExpression;\n\tprivate stack: Stack;\n\n\tprivate scopeSubscription?: ScopeSubscription<ElementScope>;\n\n\n\tprivate listener = (event: Event) => {\n\t\tconst method: Function | undefined = this.element._proxyModel[this.listenerRef.modelCallbackName];\n\t\tif (typeof method === 'function') {\n\t\t\tconst eventScope = this.stack.pushBlockScopeFor({ $event: event });\n\t\t\tconst params = this.argumentsExpression.get(this.stack);\n\t\t\tthis.stack.clearTo(eventScope);\n\t\t\tmethod.apply(this.element._proxyModel, params);\n\t\t\ttypeof event.preventDefault === 'function' && event.preventDefault();\n\t\t}\n\t};\n\n\tconstructor(private listenerRef: ListenerRef, private element: HTMLComponent<any>, private elementScope: ReactiveScope<ElementScope>) {\n\t\tthis.stack = new Stack(elementScope);\n\t}\n\tonInit(): void {\n\t\tconst args = this.listenerRef.args ?? [];\n\t\tconst array = `[${args.join(', ')}]`;\n\t\tthis.argumentsExpression = JavaScriptParser.parseScript(array) as ArrayExpression;\n\t\tif (this.listenerRef.eventName.includes(':')) {\n\t\t\tconst [eventSource, eventName] = this.listenerRef.eventName.split(':', 2);\n\t\t\tthis.eventName = eventName;\n\t\t\tif ('window' === eventSource.toLowerCase()) {\n\t\t\t\tthis.source = window;\n\t\t\t} else {\n\t\t\t\tlet source = this.elementScope.get(eventSource) as HTMLElement;\n\t\t\t\tthis.scopeSubscription = this.elementScope.subscribe(eventSource, (newValue: HTMLElement) => {\n\t\t\t\t\tif (source !== newValue) {\n\t\t\t\t\t\tif (source) {\n\t\t\t\t\t\t\tthis.removeEventListener();\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (!newValue) {\n\t\t\t\t\t\tthis.removeEventListener();\n\t\t\t\t\t}\n\t\t\t\t\tsource = newValue;\n\t\t\t\t\tthis.addEventListener();\n\t\t\t\t});\n\t\t\t\tthis.source = source;\n\t\t\t}\n\t\t} else {\n\t\t\tthis.eventName = this.listenerRef.eventName;\n\t\t\tthis.source = this.element;\n\t\t}\n\t\tthis.addEventListener();\n\t}\n\n\tprivate addEventListener() {\n\t\tthis.source?.addEventListener(this.eventName, this.listener);\n\t}\n\n\tprivate removeEventListener() {\n\t\tthis.source?.removeEventListener(this.eventName, this.listener);\n\t}\n\n\tonConnect() {\n\t\tthis.scopeSubscription?.resume();\n\t}\n\n\tonDisconnect() {\n\t\tthis.scopeSubscription?.pause();\n\t}\n\n\tonDestroy(): void {\n\t\tthis.scopeSubscription?.unsubscribe();\n\t\tthis.removeEventListener();\n\t}\n\n}\n"]}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { OnDestroy, OnInit } from '../component/lifecycle.js';
|
|
2
2
|
export interface RenderHandler extends Partial<OnInit>, Partial<OnDestroy> {
|
|
3
|
+
/**
|
|
4
|
+
* execute when element attached to parent from ui
|
|
5
|
+
*/
|
|
3
6
|
onConnect?(): void;
|
|
7
|
+
/**
|
|
8
|
+
* execute when element disconnected from ui
|
|
9
|
+
*/
|
|
4
10
|
onDisconnect?(): void;
|
|
5
11
|
}
|
package/utils/typeof.d.ts
CHANGED
package/utils/utils.js
CHANGED
package/utils/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/core/utils/utils.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,WAAW,CAAC,GAAW;IACtC,OAAO,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/core/utils/utils.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,WAAW,CAAC,GAAW;IACtC,OAAO,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC;QACpC,gCAAgC;SAC/B,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,OAAO,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC;SAC3D,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AACrB,CAAC","sourcesContent":["\nexport function ToCamelCase(str: string) {\n\treturn str.replace(/([A-Z])/g, ' $1')\n\t\t// uppercase the first character\n\t\t.replace(/^./, function (str) { return str.toUpperCase(); })\n\t\t.replace(/ /g, '');\n}\n"]}
|