@ibyar/core 0.5.6 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/annotation/decorators.d.ts +121 -0
  2. package/annotation/decorators.js.map +1 -1
  3. package/binding/binding.expressions.d.ts +9 -4
  4. package/binding/binding.expressions.js +10 -15
  5. package/binding/binding.expressions.js.map +1 -1
  6. package/component/component.d.ts +3 -0
  7. package/component/component.js +1 -0
  8. package/component/component.js.map +1 -1
  9. package/component/custom-element.d.ts +48 -4
  10. package/component/custom-element.js.map +1 -1
  11. package/component/events.js +2 -6
  12. package/component/events.js.map +1 -1
  13. package/context/stack.js +4 -0
  14. package/context/stack.js.map +1 -1
  15. package/directive/directive.d.ts +9 -0
  16. package/directive/directive.js +9 -0
  17. package/directive/directive.js.map +1 -1
  18. package/directive/parser.d.ts +4 -0
  19. package/directive/parser.js +19 -0
  20. package/directive/parser.js.map +1 -1
  21. package/directive/providers.js +3 -3
  22. package/directive/providers.js.map +1 -1
  23. package/html/expression.d.ts +5 -0
  24. package/html/expression.js +13 -1
  25. package/html/expression.js.map +1 -1
  26. package/index.d.ts +4 -0
  27. package/index.js +4 -0
  28. package/index.js.map +1 -1
  29. package/linker/change-detector-ref.d.ts +25 -2
  30. package/linker/change-detector-ref.js +30 -18
  31. package/linker/change-detector-ref.js.map +1 -1
  32. package/linker/template-ref.d.ts +17 -5
  33. package/linker/template-ref.js +23 -20
  34. package/linker/template-ref.js.map +1 -1
  35. package/linker/view-container-ref.d.ts +140 -8
  36. package/linker/view-container-ref.js +82 -31
  37. package/linker/view-container-ref.js.map +1 -1
  38. package/linker/view-ref.d.ts +49 -5
  39. package/linker/view-ref.js +23 -9
  40. package/linker/view-ref.js.map +1 -1
  41. package/package.json +9 -5
  42. package/pipe/pipe.d.ts +7 -0
  43. package/pipe/pipe.js +4 -4
  44. package/pipe/pipe.js.map +1 -1
  45. package/providers/injector.js +1 -0
  46. package/providers/injector.js.map +1 -1
  47. package/render/host-listener.handler.d.ts +17 -0
  48. package/render/host-listener.handler.js +20 -3
  49. package/render/host-listener.handler.js.map +1 -1
  50. package/render/render-handler.d.ts +6 -0
  51. package/utils/typeof.d.ts +3 -0
  52. package/utils/utils.js +1 -0
  53. package/utils/utils.js.map +1 -1
  54. package/view/base-view.js +56 -19
  55. package/view/base-view.js.map +1 -1
  56. package/view/form-view.js +21 -0
  57. package/view/form-view.js.map +1 -1
  58. package/view/mutation.js +1 -0
  59. package/view/mutation.js.map +1 -1
  60. package/view/render.d.ts +9 -9
  61. package/view/render.js +38 -29
  62. package/view/render.js.map +1 -1
  63. package/view/view.d.ts +5 -0
  64. package/view/view.js +7 -0
  65. package/view/view.js.map +1 -1
  66. package/zone/bootstrap.d.ts +21 -0
  67. package/zone/bootstrap.js +35 -0
  68. package/zone/bootstrap.js.map +1 -0
  69. package/zone/proxy.d.ts +15 -0
  70. package/zone/proxy.js +41 -0
  71. package/zone/proxy.js.map +1 -0
  72. package/zone/task.d.ts +61 -0
  73. package/zone/task.js +109 -0
  74. package/zone/task.js.map +1 -0
  75. package/zone/zone.d.ts +51 -0
  76. package/zone/zone.js +193 -0
  77. package/zone/zone.js.map +1 -0
  78. package/component/provider.d.ts +0 -10
  79. package/component/provider.js +0 -17
  80. package/component/provider.js.map +0 -1
@@ -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;AAKD,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"]}
1
+ {"version":3,"file":"change-detector-ref.js","sourceRoot":"","sources":["../../../src/core/linker/change-detector-ref.ts"],"names":[],"mappings":"AAEA,MAAM,OAAgB,iBAAiB;CA6BtC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAgC,EAAE,WAA0B;IACnG,OAAO;QACN,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;QACD,aAAa;YACZ,KAAK,CAAC,aAAa,EAAE,CAAC;QACvB,CAAC;QACD,cAAc;YACb,KAAK,CAAC,cAAc,EAAE,CAAC;QACxB,CAAC;KACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,QAAyC;IACrF,OAAO;QACN,MAAM;YACL,QAAQ,EAAE,CAAC,MAAM,EAAE,CAAC;QACrB,CAAC;QACD,QAAQ;YACP,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC;QACvB,CAAC;QACD,YAAY;YACX,QAAQ,EAAE,CAAC,aAAa,EAAE,CAAA;QAC3B,CAAC;QACD,aAAa;YACZ,QAAQ,EAAE,CAAC,aAAa,EAAE,CAAC;QAC5B,CAAC;QACD,cAAc;YACb,QAAQ,EAAE,CAAC,cAAc,EAAE,CAAC;QAC7B,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { ReactiveScopeControl, Context } 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 changes now.\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\t/**\n\t * apply change detection\n\t */\n\tabstract detectChanges(): void;\n\n\n\t/**\n\t * throw error if any changes has been made\n\t */\n\tabstract checkNoChanges(): void;\n}\n\n/**\n * create a change Detector Reference by property key.\n */\nexport function createChangeDetectorRef(scope: ReactiveScopeControl<any>, propertyKey: keyof Context): ChangeDetectorRef {\n\treturn {\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\tdetectChanges() {\n\t\t\tscope.detectChanges();\n\t\t},\n\t\tcheckNoChanges() {\n\t\t\tscope.checkNoChanges();\n\t\t},\n\t};\n}\n\nexport function createModelChangeDetectorRef(resolver: () => ReactiveScopeControl<any>): ChangeDetectorRef {\n\treturn {\n\t\tdetach() {\n\t\t\tresolver().detach();\n\t\t},\n\t\treattach() {\n\t\t\tresolver().reattach();\n\t\t},\n\t\tmarkForCheck() {\n\t\t\tresolver().detectChanges()\n\t\t},\n\t\tdetectChanges() {\n\t\t\tresolver().detectChanges();\n\t\t},\n\t\tcheckNoChanges() {\n\t\t\tresolver().checkNoChanges();\n\t\t},\n\t};\n}\n"]}
@@ -5,18 +5,30 @@ 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 {
12
- private render;
13
- private node;
14
- private stack;
15
- private templateExpressions;
24
+ private _render;
25
+ private _node;
26
+ private _stack;
27
+ private _templateExpressions;
16
28
  private _host;
17
29
  constructor(render: ComponentRender<any>, node: DomNode, stack: Stack, templateExpressions: ExpressionNode[]);
18
30
  get astNode(): DomNode;
19
31
  set host(host: HTMLComponent<any> | StructuralDirective);
20
- createEmbeddedView<C extends object>(context: C, parentNode: Node): EmbeddedViewRef<C>;
32
+ createEmbeddedView<C extends object>(context: C | undefined, parentNode: Node): EmbeddedViewRef<C>;
21
33
  private executeTemplateExpressions;
22
34
  }
@@ -1,53 +1,56 @@
1
- import { createProxyForContext, findReactiveScopeByEventMap, Stack } from '@ibyar/expressions';
1
+ import { findReactiveScopeByEventMap, ReactiveScopeControl, Stack } from '@ibyar/expressions';
2
2
  import { EmbeddedViewRefImpl } from './view-ref.js';
3
3
  export class TemplateRef {
4
4
  }
5
5
  export class TemplateRefImpl extends TemplateRef {
6
- constructor(render, node, stack, templateExpressions) {
6
+ constructor(_render, _node, _stack, _templateExpressions) {
7
7
  super();
8
- this.render = render;
9
- this.node = node;
10
- this.stack = stack;
11
- this.templateExpressions = templateExpressions;
8
+ this._render = _render;
9
+ this._node = _node;
10
+ this._stack = _stack;
11
+ this._templateExpressions = _templateExpressions;
12
12
  }
13
13
  get astNode() {
14
- return this.node;
14
+ return this._node;
15
15
  }
16
16
  set host(host) {
17
17
  this._host = host;
18
18
  }
19
- createEmbeddedView(context, parentNode) {
20
- const directiveStack = this.stack.copyStack();
21
- const templateScope = directiveStack.pushReactiveScope();
19
+ createEmbeddedView(context = {}, parentNode) {
20
+ const directiveStack = this._stack.copyStack();
21
+ const templateScope = ReactiveScopeControl.blockScope();
22
+ directiveStack.pushScope(templateScope);
22
23
  const sandBox = new Stack();
23
- const contextScope = sandBox.pushReactiveScopeFor(context ?? {});
24
+ const contextScope = ReactiveScopeControl.for(context);
25
+ sandBox.pushScope(contextScope);
24
26
  sandBox.pushScope(templateScope);
25
27
  const elements = [];
26
- const contextProxy = createProxyForContext(contextScope);
27
28
  const subscriptions = [];
28
- const embeddedViewRef = new EmbeddedViewRefImpl(contextProxy, elements, subscriptions);
29
+ const embeddedViewRef = new EmbeddedViewRefImpl(contextScope, elements, subscriptions);
29
30
  const scopeSubscriptions = this.executeTemplateExpressions(sandBox);
30
31
  scopeSubscriptions && subscriptions.push(...scopeSubscriptions);
31
32
  const fragment = document.createDocumentFragment();
32
- this.render.appendChildToParent(fragment, this.node, directiveStack, parentNode, subscriptions, this._host);
33
+ this._render.appendChildToParent(fragment, this._node, directiveStack, parentNode, subscriptions, this._host);
33
34
  fragment.childNodes.forEach(item => elements.push(item));
35
+ // const updateSubscriptions = this.render.view._zone.onFinal.subscribe(() => contextScope.detectChanges());
36
+ // embeddedViewRef.onDestroy(() => updateSubscriptions.unsubscribe());
34
37
  return embeddedViewRef;
35
38
  }
36
39
  executeTemplateExpressions(sandBox) {
37
- if (!this.templateExpressions?.length) {
40
+ if (!this._templateExpressions?.length) {
38
41
  return;
39
42
  }
40
- this.templateExpressions.forEach(expression => {
43
+ // init value
44
+ this._templateExpressions.forEach(expression => {
41
45
  expression.get(sandBox);
42
46
  });
47
+ // subscribe to changes
43
48
  const scopeSubscriptions = [];
44
- this.templateExpressions.forEach(expression => {
49
+ this._templateExpressions.forEach(expression => {
45
50
  const events = expression.events();
46
51
  const scopeTuples = findReactiveScopeByEventMap(events, sandBox);
47
52
  scopeTuples.forEach(tuple => {
48
- const subscription = tuple[1].subscribe(tuple[0], () => {
49
- expression.get(sandBox);
50
- });
53
+ const subscription = tuple[1].subscribe(tuple[0], () => expression.get(sandBox));
51
54
  scopeSubscriptions.push(subscription);
52
55
  });
53
56
  });
@@ -1 +1 @@
1
- {"version":3,"file":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AC,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"]}
1
+ {"version":3,"file":"template-ref.js","sourceRoot":"","sources":["../../../src/core/linker/template-ref.ts"],"names":[],"mappings":"AACA,OAAO,EACU,2BAA2B,EAC3C,oBAAoB,EACD,KAAK,EACxB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAmB,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAErE,MAAM,OAAgB,WAAW;CAiBhC;AAGD,MAAM,OAAO,eAAgB,SAAQ,WAAW;IAU/C,YACS,OAA6B,EAC7B,KAAc,EACd,MAAa,EACb,oBAAsC;QAE9C,KAAK,EAAE,CAAC;QALA,YAAO,GAA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AQ,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACzD,4GAA4G;QAC5G,sEAAsE;QACtE,OAAO,eAAe,CAAC;IACxB,CAAC;IACO,0BAA0B,CAAC,OAAc;QAChD,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,MAAM,EAAE;YACvC,OAAO;SACP;QACD,aAAa;QACb,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YAC9C,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;QAEH,uBAAuB;QACvB,MAAM,kBAAkB,GAAgC,EAAE,CAAC;QAC3D,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YAC9C,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC;YACnC,MAAM,WAAW,GAAG,2BAA2B,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACjE,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBAC3B,MAAM,YAAY,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CACtC,KAAK,CAAC,CAAC,CAAC,EACR,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAC7B,CAAC;gBACF,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 } from '@ibyar/elements';\nimport {\n\tExpressionNode, findReactiveScopeByEventMap,\n\tReactiveScopeControl, Context,\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\trender: ComponentRender<any>,\n\t\tnode: DomNode,\n\t\tstack: Stack,\n\t\ttemplateExpressions: ExpressionNode[],\n\t);\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 = {} as C, parentNode: Node): EmbeddedViewRef<C> {\n\t\tconst directiveStack = this._stack.copyStack();\n\t\tconst templateScope = ReactiveScopeControl.blockScope<C>();\n\t\tdirectiveStack.pushScope(templateScope);\n\n\t\tconst sandBox = new Stack();\n\t\tconst contextScope = ReactiveScopeControl.for<C>(context);\n\t\tsandBox.pushScope(contextScope);\n\t\tsandBox.pushScope(templateScope);\n\n\t\tconst elements: Node[] = [];\n\t\tconst subscriptions: ScopeSubscription<Context>[] = [];\n\t\tconst embeddedViewRef = new EmbeddedViewRefImpl(contextScope, 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\t// const updateSubscriptions = this.render.view._zone.onFinal.subscribe(() => contextScope.detectChanges());\n\t\t// embeddedViewRef.onDestroy(() => updateSubscriptions.unsubscribe());\n\t\treturn embeddedViewRef;\n\t}\n\tprivate executeTemplateExpressions(sandBox: Stack): ScopeSubscription<Context>[] | 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(\n\t\t\t\t\ttuple[0],\n\t\t\t\t\t() => expression.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"]}
@@ -1,31 +1,156 @@
1
1
  import type { TypeOf } from '../utils/typeof.js';
2
2
  import { TemplateRef } from './template-ref.js';
3
3
  import { EmbeddedViewRef, ViewRef } from './view-ref.js';
4
- export declare type ViewContainerOptions<C> = {
4
+ import { HTMLComponent } from '../component/custom-element.js';
5
+ interface IndexOptions {
6
+ /**
7
+ * the index to insert the
8
+ */
5
9
  index?: number;
10
+ /**
11
+ * the default value is true
12
+ */
13
+ insert?: boolean;
14
+ }
15
+ export interface ViewContainerOptions<C> extends IndexOptions {
6
16
  context?: C;
7
- };
8
- export declare type ViewContainerComponentOptions = {
9
- index?: number | undefined;
17
+ }
18
+ export interface ViewContainerComponentOptions extends IndexOptions {
10
19
  selector?: string;
11
- };
20
+ }
21
+ export interface HTMLElementOptions extends ElementCreationOptions, IndexOptions {
22
+ }
12
23
  export declare abstract class ViewContainerRef {
24
+ /**
25
+ * Anchor element that specifies the location of this container in the containing view.
26
+ * Each view container can have only one anchor element, and each anchor element
27
+ * can have only a single view container.
28
+ *
29
+ * Root elements of views attached to this container become siblings of the anchor element in
30
+ * the rendered view.
31
+ *
32
+ * Access the `ViewContainerRef` of an element by placing a `Directive` injected
33
+ * with `ViewContainerRef` on the element, or use a `ViewChild` query.
34
+ *
35
+ */
13
36
  abstract get anchorElement(): Element;
37
+ /**
38
+ * Destroys all views in this container.
39
+ */
14
40
  abstract clear(): void;
41
+ /**
42
+ * Retrieves a view from this container.
43
+ * @param index The 0-based index of the view to retrieve.
44
+ * @returns The `ViewRef` instance, or null if the index is out of range.
45
+ */
15
46
  abstract get(index: number): ViewRef | undefined;
47
+ /**
48
+ * Reports how many views are currently attached to this container.
49
+ * @returns The number of views.
50
+ */
16
51
  abstract get length(): number;
52
+ /**
53
+ * Instantiates an embedded view and inserts it
54
+ * into this container.
55
+ * @param templateRef The HTML template that defines the view.
56
+ * @param context The data-binding context of the embedded view, as declared
57
+ * in the `<ng-template>` usage.
58
+ * @param index The 0-based index at which to insert the new view into this container.
59
+ * If not specified, appends the new view as the last entry.
60
+ *
61
+ * @returns The `ViewRef` instance for the newly created view.
62
+ */
17
63
  abstract createEmbeddedView<C extends {}>(templateRef: TemplateRef, options?: ViewContainerOptions<C>): EmbeddedViewRef<C>;
64
+ /**
65
+ * create component by tag name `selector`.
66
+ * @param selector the tag name for the aurora custom-element
67
+ * @param options
68
+ */
69
+ abstract createComponent<C extends {}>(selector: string, options?: IndexOptions): C;
70
+ /**
71
+ * create component by the aurora custom-element `View` Class
72
+ * @param viewClass the generated aurora view class
73
+ * @param options
74
+ */
75
+ abstract createComponent<C extends {}>(viewClass: TypeOf<HTMLComponent<C>>, options?: IndexOptions): C;
76
+ /**
77
+ * Instantiates a single component and inserts its host view into this container.
78
+ *
79
+ * @param componentType Component Type to use.
80
+ * @param options An object that contains extra parameters:
81
+ * * index: the index at which to insert the new component's host view into this container.
82
+ * If not specified, appends the new view as the last entry.
83
+ * * selector: the tag name of the new create component that attached with this model class.
84
+ * Any Model class can have many views with different selectors.
85
+ *
86
+ * @returns The new `HTMLComponent` which contains the component instance and the host view.
87
+ */
18
88
  abstract createComponent<C extends {}>(componentType: TypeOf<C>, options?: ViewContainerComponentOptions): C;
89
+ /**
90
+ * create an HTMLElement by tag name `selector`.
91
+ * @param selector the tag name for the aurora custom-element
92
+ * @param options
93
+ */
94
+ abstract createElement<K extends keyof HTMLElementTagNameMap>(selector: K, options?: HTMLElementOptions): HTMLElementTagNameMap[K];
95
+ abstract createElement<K extends keyof HTMLElementDeprecatedTagNameMap>(selector: K, options?: HTMLElementOptions): HTMLElementDeprecatedTagNameMap[K];
96
+ /**
97
+ * create HTMLElement by View Class reference
98
+ * @param viewClass the generated aurora view class
99
+ * @param options
100
+ */
101
+ abstract createElement<C extends HTMLElement>(htmlElementClass: TypeOf<C>, options?: HTMLElementOptions): C;
102
+ /**
103
+ * create a text node and insert to the view
104
+ * @param data
105
+ * @param options
106
+ */
107
+ abstract createTextNode(data: string, options?: IndexOptions): Text;
108
+ /**
109
+ * Inserts a view into this container.
110
+ * @param viewRef The view to insert.
111
+ * @param index The 0-based index at which to insert the view.
112
+ * If not specified, appends the new view as the last entry.
113
+ * @returns The inserted `ViewRef` instance.
114
+ *
115
+ */
19
116
  abstract insert(viewRef: ViewRef, index?: number): ViewRef;
117
+ /**
118
+ * Moves a view to a new location in this container.
119
+ * @param viewRef The view to move.
120
+ * @param newIndex The 0-based index of the new location.
121
+ * @returns The moved `ViewRef` instance.
122
+ */
20
123
  abstract move(viewRef: ViewRef, newIndex: number): ViewRef;
124
+ /**
125
+ * Returns the index of a view within the current container.
126
+ * @param viewRef The view to query.
127
+ * @returns The 0-based index of the view's position in this container,
128
+ * or `-1` if this container doesn't contain the view.
129
+ */
21
130
  abstract indexOf(viewRef: ViewRef): number;
131
+ /**
132
+ * Destroys a view attached to this container
133
+ * @param index The 0-based index of the view to destroy.
134
+ * If not specified, the last view in the container is removed.
135
+ */
22
136
  abstract remove(index?: number): void;
137
+ /**
138
+ * Detaches a view from this container without destroying it.
139
+ * Use along with `insert()` to move a view within the current container.
140
+ * @param index The 0-based index of the view to detach.
141
+ * If not specified, the last view in the container is detached.
142
+ */
23
143
  abstract detach(index?: number): ViewRef | undefined;
144
+ /**
145
+ * set the current views from this
146
+ * @param views the new `ViewRef` list
147
+ */
148
+ abstract updateViews(views: ViewRef[]): void;
24
149
  }
25
150
  export declare class ViewContainerRefImpl extends ViewContainerRef {
26
- private parent;
27
- private firstComment;
28
- private views;
151
+ private _parent;
152
+ private _firstComment;
153
+ private _views;
29
154
  constructor(parent: Element, firstComment: Comment);
30
155
  get anchorElement(): Element;
31
156
  get length(): number;
@@ -37,5 +162,12 @@ export declare class ViewContainerRefImpl extends ViewContainerRef {
37
162
  insert(viewRef: EmbeddedViewRef<any>, index?: number): ViewRef;
38
163
  move(viewRef: EmbeddedViewRef<any>, newIndex: number): ViewRef;
39
164
  createEmbeddedView<C extends {}>(templateRef: TemplateRef, options?: ViewContainerOptions<C>): EmbeddedViewRef<C>;
165
+ createComponent<C extends {}>(selector: string, options?: IndexOptions): C;
166
+ createComponent<C extends {}>(viewClass: TypeOf<HTMLComponent<C>>, options?: IndexOptions): C;
40
167
  createComponent<C extends {}>(componentType: TypeOf<C>, options?: ViewContainerComponentOptions): C;
168
+ createElement<K extends keyof HTMLElementTagNameMap>(selector: K, options?: HTMLElementOptions): HTMLElementTagNameMap[K];
169
+ createElement<K extends keyof HTMLElementDeprecatedTagNameMap>(selector: K, options?: HTMLElementOptions): HTMLElementDeprecatedTagNameMap[K];
170
+ createTextNode(data: string, options?: IndexOptions): Text;
171
+ updateViews(views: ViewRef[]): void;
41
172
  }
173
+ export {};
@@ -1,54 +1,57 @@
1
1
  import { Components } from '../component/component.js';
2
2
  import { EmbeddedViewRefImpl } from './view-ref.js';
3
3
  import { getComponentView } from '../view/view.js';
4
+ import { ReactiveScopeControl } from '@ibyar/expressions';
5
+ ;
6
+ ;
4
7
  export class ViewContainerRef {
5
8
  }
6
9
  export class ViewContainerRefImpl extends ViewContainerRef {
7
- constructor(parent, firstComment) {
10
+ constructor(_parent, _firstComment) {
8
11
  super();
9
- this.parent = parent;
10
- this.firstComment = firstComment;
11
- this.views = [];
12
+ this._parent = _parent;
13
+ this._firstComment = _firstComment;
14
+ this._views = [];
12
15
  }
13
16
  get anchorElement() {
14
- return this.parent;
17
+ return this._parent;
15
18
  }
16
19
  get length() {
17
- return this.views.length;
20
+ return this._views.length;
18
21
  }
19
22
  clear() {
20
- if (this.views.length > 0) {
21
- for (const elm of this.views) {
23
+ if (this._views.length > 0) {
24
+ for (const elm of this._views) {
22
25
  elm.destroy();
23
26
  }
24
- this.views.splice(0);
27
+ this._views.splice(0);
25
28
  }
26
29
  }
27
30
  get(index) {
28
- if (index >= this.views.length) {
31
+ if (index >= this._views.length) {
29
32
  return undefined;
30
33
  }
31
- return this.views[index];
34
+ return this._views[index];
32
35
  }
33
36
  detach(index) {
34
- index ?? (index = this.views.length - 1);
35
- const viewRef = this.views[index];
37
+ index ?? (index = this._views.length - 1);
38
+ const viewRef = this._views[index];
36
39
  viewRef.detach();
37
- this.views.splice(index, 1);
40
+ this._views.splice(index, 1);
38
41
  return viewRef;
39
42
  }
40
43
  indexOf(viewRef) {
41
- return this.views.indexOf(viewRef);
44
+ return this._views.indexOf(viewRef);
42
45
  }
43
46
  remove(index) {
44
- index ?? (index = this.views.length - 1);
45
- this.views[index].destroy();
46
- this.views.splice(index, 1);
47
+ index ?? (index = this._views.length - 1);
48
+ this._views[index].destroy();
49
+ this._views.splice(index, 1);
47
50
  }
48
51
  insert(viewRef, index) {
49
- index = ((index ?? (index = this.views.length)) > this.views.length) ? this.views.length : index;
50
- const lastNode = index == 0 ? this.firstComment : this.views[index - 1].last;
51
- this.views.splice(index, 0, viewRef);
52
+ index = ((index ?? (index = this._views.length)) > this._views.length) ? this._views.length : index;
53
+ const lastNode = index == 0 ? this._firstComment : this._views[index - 1].last;
54
+ this._views.splice(index, 0, viewRef);
52
55
  viewRef.after(lastNode);
53
56
  return viewRef;
54
57
  }
@@ -58,25 +61,73 @@ export class ViewContainerRefImpl extends ViewContainerRef {
58
61
  this.detach(oldIndex);
59
62
  }
60
63
  else {
64
+ // should remove it from the container first
61
65
  viewRef.detach();
62
66
  }
63
67
  return this.insert(viewRef, newIndex);
64
68
  }
65
69
  createEmbeddedView(templateRef, options) {
66
- const viewRef = templateRef.createEmbeddedView(options?.context || {}, this.parent);
67
- this.insert(viewRef, options?.index);
70
+ const viewRef = templateRef.createEmbeddedView(options?.context || {}, this._parent);
71
+ (options?.insert != false) && this.insert(viewRef, options?.index);
68
72
  return viewRef;
69
73
  }
70
- createComponent(componentType, options) {
71
- const defaultTagName = Components.getComponentRef(componentType).selector;
72
- const ViewClass = getComponentView(componentType, options?.selector ?? defaultTagName);
73
- if (!ViewClass) {
74
- throw new Error(`Can't find View component for class ${componentType.name}`);
74
+ createComponent(arg0, options) {
75
+ let ViewClass;
76
+ if (typeof arg0 === 'string') {
77
+ ViewClass = customElements.get(arg0);
78
+ }
79
+ else if (typeof arg0 === 'function') {
80
+ if (Reflect.has(arg0, 'observedAttributes')) {
81
+ ViewClass = arg0;
82
+ }
83
+ else {
84
+ const componentType = arg0;
85
+ const defaultTagName = Components.getComponentRef(componentType).selector;
86
+ const view = getComponentView(componentType, options?.selector ?? defaultTagName);
87
+ if (!view) {
88
+ throw new Error(`Can't find View component for class ${componentType.name}`);
89
+ }
90
+ ViewClass = view;
91
+ }
92
+ }
93
+ else {
94
+ throw new Error(`Can't find View component for args, ${arg0}, ${options}`);
75
95
  }
76
96
  const component = new ViewClass();
77
- const viewRef = new EmbeddedViewRefImpl(component._proxyModel, [component]);
78
- this.insert(viewRef, options?.index);
79
- return component._proxyModel;
97
+ const viewRef = new EmbeddedViewRefImpl(component._modelScope, [component]);
98
+ (options?.insert != false) && this.insert(viewRef, options?.index);
99
+ return component;
100
+ }
101
+ createElement(arg0, options) {
102
+ let element;
103
+ if (typeof arg0 === 'string') {
104
+ element = document.createElement(arg0, { is: options?.is });
105
+ }
106
+ else if (typeof arg0 === 'function') {
107
+ element = new arg0();
108
+ }
109
+ else {
110
+ throw new Error(`Can't find View component for args, ${arg0}, ${options}`);
111
+ }
112
+ const scope = ReactiveScopeControl.for(element);
113
+ const viewRef = new EmbeddedViewRefImpl(scope, [element]);
114
+ (options?.insert != false) && this.insert(viewRef, options?.index);
115
+ return element;
116
+ }
117
+ createTextNode(data, options) {
118
+ const text = document.createTextNode(data);
119
+ const scope = ReactiveScopeControl.for(text);
120
+ const viewRef = new EmbeddedViewRefImpl(scope, [text]);
121
+ (options?.insert != false) && this.insert(viewRef, options?.index);
122
+ return text;
123
+ }
124
+ updateViews(views) {
125
+ for (let i = 0; i < views.length; i++) {
126
+ this.move(views[i], i);
127
+ }
128
+ while (this.length > views.length) {
129
+ this.remove();
130
+ }
80
131
  }
81
132
  }
82
133
  //# sourceMappingURL=view-container-ref.js.map
@@ -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;QACz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,GAAG,UAAU,CAAC,eAAe,CAAI,aAAa,CAAC,CAAC,QAAQ,CAAC;QAC7E,MAAM,SAAS,GAAG,gBAAgB,CAAC,aAAa,EAAE,OAAO,EAAE,QAAQ,IAAI,cAAc,CAAC,CAAC;QACvF,IAAI,CAAC,SAAS,EAAE;YACf,MAAM,IAAI,KAAK,CAAC,uCAAuC,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;SAC7E;QACD,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC;QAClC,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAI,SAAS,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;QAC/E,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QACrC,OAAO,SAAS,CAAC,WAAW,CAAC;IAC9B,CAAC;CAED","sourcesContent":["import type { 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;AAEnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAezD,CAAC;AAID,CAAC;AAMF,MAAM,OAAgB,gBAAgB;CA+IrC;AAGD,MAAM,OAAO,oBAAqB,SAAQ,gBAAgB;IAKzD,YAAoB,OAAgB,EAAU,aAAsB;QACnE,KAAK,EAAE,CAAC;QADW,YAAO,GAAP,OAAO,CAAS;QAAU,kBAAa,GAAb,aAAa,CAAS;QAH5D,WAAM,GAA2B,EAAE,CAAC;IAK5C,CAAC;IACD,IAAa,aAAa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I,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE;YAClC,IAAI,CAAC,MAAM,EAAE,CAAC;SACd;IACF,CAAC;CAED","sourcesContent":["import type { 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';\nimport { HTMLComponent } from '../component/custom-element.js';\nimport { ReactiveScopeControl } from '@ibyar/expressions';\n\ninterface IndexOptions {\n\t/**\n\t * the index to insert the \n\t */\n\tindex?: number;\n\t/**\n\t * the default value is true\n\t */\n\tinsert?: boolean\n}\n\nexport interface ViewContainerOptions<C> extends IndexOptions {\n\tcontext?: C;\n};\n\nexport interface ViewContainerComponentOptions extends IndexOptions {\n\tselector?: string;\n};\n\nexport interface HTMLElementOptions extends ElementCreationOptions, IndexOptions {\n\n}\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\t * create component by tag name `selector`.\n\t * @param selector the tag name for the aurora custom-element\n\t * @param options \n\t */\n\tabstract createComponent<C extends {}>(selector: string, options?: IndexOptions): C;\n\n\t/**\n\t * create component by the aurora custom-element `View` Class\n\t * @param viewClass the generated aurora view class\n\t * @param options \n\t */\n\tabstract createComponent<C extends {}>(viewClass: TypeOf<HTMLComponent<C>>, options?: IndexOptions): C;\n\t/**\n\t * Instantiates a single component and inserts its host view into this container.\n\t *\n\t * @param componentType Component Type to use.\n\t * @param options An object that contains extra parameters:\n\t * * index: the index at which to insert the new component's host view into this container.\n\t * If not specified, appends the new view as the last entry.\n\t * * 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\t *\n\t * @returns The new `HTMLComponent` which contains the component instance and the host view.\n\t */\n\tabstract createComponent<C extends {}>(componentType: TypeOf<C>, options?: ViewContainerComponentOptions): C;\n\n\n\t/**\n\t * create an HTMLElement by tag name `selector`.\n\t * @param selector the tag name for the aurora custom-element\n\t * @param options \n\t */\n\tabstract createElement<K extends keyof HTMLElementTagNameMap>(selector: K, options?: HTMLElementOptions): HTMLElementTagNameMap[K];\n\tabstract createElement<K extends keyof HTMLElementDeprecatedTagNameMap>(selector: K, options?: HTMLElementOptions): HTMLElementDeprecatedTagNameMap[K];\n\n\t/**\n\t * create HTMLElement by View Class reference\n\t * @param viewClass the generated aurora view class\n\t * @param options \n\t */\n\tabstract createElement<C extends HTMLElement>(htmlElementClass: TypeOf<C>, options?: HTMLElementOptions): C;\n\n\t/**\n\t * create a text node and insert to the view\n\t * @param data \n\t * @param options \n\t */\n\tabstract createTextNode(data: string, options?: IndexOptions): Text;\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\t/**\n\t * set the current views from this\n\t * @param views the new `ViewRef` list \n\t */\n\tabstract updateViews(views: ViewRef[]): void;\n}\n\n\nexport class ViewContainerRefImpl extends ViewContainerRef {\n\n\tprivate _views: EmbeddedViewRef<any>[] = [];\n\n\tconstructor(parent: Element, firstComment: Comment);\n\tconstructor(private _parent: Element, private _firstComment: Comment) {\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\t(options?.insert != false) && this.insert(viewRef, options?.index);\n\t\treturn viewRef;\n\t}\n\toverride createComponent<C extends {}>(selector: string, options?: IndexOptions): C;\n\toverride createComponent<C extends {}>(viewClass: TypeOf<HTMLComponent<C>>, options?: IndexOptions): C;\n\toverride createComponent<C extends {}>(componentType: TypeOf<C>, options?: ViewContainerComponentOptions): C;\n\toverride createComponent<C extends {}>(arg0: string | TypeOf<C> | TypeOf<HTMLComponent<C>>, options?: ViewContainerComponentOptions): C {\n\t\tlet ViewClass: TypeOf<HTMLComponent<C>>;\n\t\tif (typeof arg0 === 'string') {\n\t\t\tViewClass = customElements.get(arg0) as TypeOf<HTMLComponent<C>>;\n\t\t} else if (typeof arg0 === 'function') {\n\t\t\tif (Reflect.has(arg0, 'observedAttributes')) {\n\t\t\t\tViewClass = arg0 as TypeOf<HTMLComponent<C>>;\n\t\t\t} else {\n\t\t\t\tconst componentType = arg0 as TypeOf<C>;\n\t\t\t\tconst defaultTagName = Components.getComponentRef<C>(componentType).selector;\n\t\t\t\tconst view = getComponentView(componentType, options?.selector ?? defaultTagName);\n\t\t\t\tif (!view) {\n\t\t\t\t\tthrow new Error(`Can't find View component for class ${componentType.name}`);\n\t\t\t\t}\n\t\t\t\tViewClass = view;\n\t\t\t}\n\t\t} else {\n\t\t\tthrow new Error(`Can't find View component for args, ${arg0}, ${options}`);\n\t\t}\n\t\tconst component = new ViewClass();\n\t\tconst viewRef = new EmbeddedViewRefImpl<C>(component._modelScope, [component]);\n\t\t(options?.insert != false) && this.insert(viewRef, options?.index);\n\t\treturn component as any as C;\n\t}\n\n\toverride createElement<K extends keyof HTMLElementTagNameMap>(selector: K, options?: HTMLElementOptions): HTMLElementTagNameMap[K];\n\toverride createElement<K extends keyof HTMLElementDeprecatedTagNameMap>(selector: K, options?: HTMLElementOptions): HTMLElementDeprecatedTagNameMap[K];\n\toverride createElement<C extends HTMLElement>(arg0: string | TypeOf<C>, options?: HTMLElementOptions): C {\n\t\tlet element: C;\n\t\tif (typeof arg0 === 'string') {\n\t\t\telement = document.createElement(arg0, { is: options?.is }) as C;\n\t\t} else if (typeof arg0 === 'function') {\n\t\t\telement = new arg0();\n\t\t} else {\n\t\t\tthrow new Error(`Can't find View component for args, ${arg0}, ${options}`);\n\t\t}\n\t\tconst scope = ReactiveScopeControl.for<C>(element);\n\t\tconst viewRef = new EmbeddedViewRefImpl<C>(scope, [element]);\n\t\t(options?.insert != false) && this.insert(viewRef, options?.index);\n\t\treturn element;\n\t}\n\toverride createTextNode(data: string, options?: IndexOptions): Text {\n\t\tconst text = document.createTextNode(data);\n\t\tconst scope = ReactiveScopeControl.for<Text>(text);\n\t\tconst viewRef = new EmbeddedViewRefImpl<Text>(scope, [text]);\n\t\t(options?.insert != false) && this.insert(viewRef, options?.index);\n\t\treturn text;\n\t}\n\n\toverride updateViews(views: ViewRef[]): void {\n\t\tfor (let i = 0; i < views.length; i++) {\n\t\t\tthis.move(views[i] as EmbeddedViewRef<any>, i);\n\t\t}\n\t\twhile (this.length > views.length) {\n\t\t\tthis.remove();\n\t\t}\n\t}\n\n}\n"]}