@quenk/wml 2.14.1 → 2.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/parse/test.js CHANGED
@@ -112,39 +112,12 @@ exports.tests = {
112
112
  {% endif %}
113
113
  </Tag>`,
114
114
  },
115
- "should parse short fun statements": {
116
- input: "{% fun vue () = <View/> %}",
117
- },
118
- "should parse short fun statements with arguments": {
119
- input: "{% fun vue (a:String, b:String, c:String) = " +
120
- "<View a={{a}} b={{b}} c={{c}}/> %}",
121
- },
122
- "should parse short fun statements with type parameters": {
123
- input: "{% fun vue [A,B:C,C] (a:A, b:B) = " + "{{ (a + b) + c }} %}",
124
- },
125
- "should parse extended fun statements": {
126
- input: "{% fun vue () %} <View/> {% endfun %}",
127
- },
128
- "should parse extended fun statements with arguments": {
129
- input: "{% fun vue (a:String, b:String, c:String) %}" +
130
- "<View a={{a}} b={{b}} c={{c}}/> {% endfun %}",
131
- },
132
- "should parse extended fun statements with type parameters": {
133
- input: "{% fun vue [A,B:C,C] (a:A, b:B) %} {{ ((a + b) + c) }} {% endfun %}",
134
- },
135
115
  "should parse binary expressions": {
136
116
  input: "<p>{{(Styles.A + Styles.B)}}</p>",
137
117
  },
138
118
  "should parse complicated expressions": {
139
119
  input: '<div class={{((Styles.A + " ") + Style.B)}}/>',
140
120
  },
141
- "should allow for statement as child of fun": {
142
- input: "{% fun sven () %} {% for a in b %} {{b}} {% endfor %} {% endfun %}",
143
- },
144
- "should allow if statement as child of fun": {
145
- input: "{% fun ate (o:Object) %} {% if a %} {{a}} {% else %} {{a}} " +
146
- "{% endif %} {% endfun %}",
147
- },
148
121
  "should allow for booleans in interpolations": {
149
122
  input: "<bool active={{true}}>{{if fun() then false else true}}</bool>",
150
123
  },
@@ -192,33 +165,9 @@ exports.tests = {
192
165
  "should allow fun application with context": {
193
166
  input: "<div>{{ <panel(@,12)> }}</div>",
194
167
  },
195
- "should parse list types": {
196
- input: "{% fun action [A] (s: String[], a:A[]) = {{ '${s}${a}' }} %}",
197
- },
198
168
  "should allow context properties as fun application": {
199
169
  input: "<div>{{ <@action()> }}</div>",
200
170
  },
201
- "should allow view statements after short fun": {
202
- input: `
203
-
204
- {% fun template [A] (d: Date[A], o:A, _:String, __:A[]) = {{String(o)}} %}
205
-
206
- {% view Results [A](Date[A]) %}
207
-
208
- <ul>
209
-
210
- {% for option,index in [1,3,4] %}
211
-
212
- <li>{{option}}and{{index}}</li>
213
-
214
- {% else %}
215
-
216
- <p>De nada!</p>
217
-
218
- {% endfor %}
219
-
220
- </ul>`,
221
- },
222
171
  "should allow actual code": {
223
172
  input: `
224
173
  {% import (Table) from "@quenk/wml-widgets/lib/data/table" %}
@@ -272,9 +221,6 @@ exports.tests = {
272
221
 
273
222
  </Panel>`,
274
223
  },
275
- "should recognize type parameters": {
276
- input: "{% fun test[A:String] (a:A) %} {{a}} {% endfun %}",
277
- },
278
224
  "should allow ifs without elses": {
279
225
  input: "{% view Test (Object) %}" +
280
226
  "<div> {% if (value == true) %} <span/> {% endif %} </div>",
@@ -455,8 +401,6 @@ exports.tests = {
455
401
  "[comment] should parse html comments": `<!-- This is an html comment. -->`,
456
402
  "[comment] should parse wml comments": `{# This is a wml comment #}`,
457
403
  "[comment] should parse wml comments in statements": `{% view Name {# This is a comment! #} (Object) %} <div/> %}`,
458
- "[fun] should parse multi dimensional array parameters": `
459
- {% fun test (value:List[][]) %}<p/>{% endfun %}`,
460
404
  "should allow index access on context properties": `{% view Test (Object) %}
461
405
  <div>
462
406
  {% if @["type"] == 1 %}
@@ -496,5 +440,41 @@ exports.tests = {
496
440
  m-20,10 h 10
497
441
  m-20,10 h 10" />
498
442
  </svg>`,
443
+ "should support part statements": `
444
+ {% part myPart0 (Ctx) %}
445
+ {% let name:String = "Me" %}
446
+ <h1>{{@name}}</h1>
447
+ {% endpart %}
448
+
449
+ {% part myPart1 (Ctx) %}<h1>{{@name}}</h1>{% endpart %}
450
+
451
+ {% part myPart2 (Ctx from "..") %}<h1>{{@name}}</h1>{% endpart %}
452
+
453
+ {% part myPart3 where name: String %}<h1>{{@name}}</h1>{% endpart %}
454
+
455
+ {% part myPart4 where name: String %}
456
+ {% let name:String = "Me" %}
457
+ <h1>{{@name}}</h1>
458
+ {% endpart %}
459
+ `,
460
+ "should support use statments": `
461
+ <div>
462
+ {% use part myPart %}
463
+ {% use view MyView %}
464
+ {% use part path.to.part %}
465
+ {% use view path.to.View %}
466
+ {% use part @path.to.part %}
467
+ {% use view @path.to.View %}
468
+ {% use view SomeView(@) %}
469
+ {% use part path.to.part({}) %}
470
+ {% use part myPath with @ %}
471
+ </div>
472
+ `,
473
+ "should support function types with optional params": `
474
+ {% context FuncContext where
475
+ func0: String? -> Void,
476
+ func1: (String, Number?) -> Void
477
+ %}
478
+ `
499
479
  };
500
480
  //# sourceMappingURL=test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":";;;AAAa,QAAA,KAAK,GAA2B;IAC3C,+BAA+B,EAAE;QAC/B,KAAK,EAAE,2CAA2C;KACnD;IACD,2BAA2B,EAAE;QAC3B,KAAK,EAAE,qCAAqC;KAC7C;IACD,uCAAuC,EAAE;QACvC,KAAK,EAAE,qDAAqD;KAC7D;IACD,iCAAiC,EAAE;QACjC,KAAK,EAAE,WAAW;KACnB;IACD,mDAAmD,EAAE;QACnD,KAAK,EAAE,6DAA6D;KACrE;IACD,mDAAmD,EAAE;QACnD,KAAK,EAAE,4BAA4B;KACpC;IACD,mDAAmD,EAAE;QACnD,KAAK,EAAE,8CAA8C;KACtD;IACD,2BAA2B,EAAE;QAC3B,KAAK,EAAE,uCAAuC;KAC/C;IACD,2CAA2C,EAAE;QAC3C,KAAK,EAAE,wDAAwD;KAChE;IACD,8CAA8C,EAAE;QAC9C,KAAK,EAAE,oEAAoE;KAC5E;IACD,iDAAiD,EAAE;QACjD,KAAK,EAAE,wBAAwB;KAChC;IACD,iDAAiD,EAAE;QACj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;IAE7E,gDAAgD,EAC9C,0CAA0C;IAE5C,qCAAqC,EAAE;;;;;;;;;;;;;eAa1B;IAEb,sBAAsB,EAAE;;;;;;OAMnB;IAEL,+BAA+B,EAAE,+EAA+E;IAEhH,sCAAsC,EAAE,mFAAmF;IAE3H,mCAAmC,EAAE;;KAElC;IAEH,kCAAkC,EAAE;;;;KAIjC;IAEH,sCAAsC,EAAE,mCAAmC;IAE3E,qCAAqC,EAAE,6BAA6B;IAEpE,mDAAmD,EAAE,6DAA6D;IAElH,iDAAiD,EAAE;;;;;aAKxC;IAEX,oCAAoC,EAAE;;;;;WAK7B;IAET,uCAAuC,EAAE,8DAA8D;IAEvG,yDAAyD,EAAE,qDAAqD;IAEhH,gDAAgD,EAAE,wEAAwE;IAE1H,0CAA0C,EAAE;;;;;WAKnC;IAET,oDAAoD,EAAE,iCAAiC;IAEvF,8DAA8D,EAAE;;;;;;;;;;;;;;;;WAgBvD;IACT,gCAAgC,EAAE;;;;;;;;;;;;;;;;KAgB/B;IACH,8BAA8B,EAAE;;;;;;;;;;;;GAY/B;IACD,oDAAoD,EAAE;;;;;GAKrD;CACF,CAAC"}
package/lib/parse/test.ts CHANGED
@@ -121,35 +121,6 @@ export const tests: { [key: string]: any } = {
121
121
  </Tag>`,
122
122
  },
123
123
 
124
- "should parse short fun statements": {
125
- input: "{% fun vue () = <View/> %}",
126
- },
127
-
128
- "should parse short fun statements with arguments": {
129
- input:
130
- "{% fun vue (a:String, b:String, c:String) = " +
131
- "<View a={{a}} b={{b}} c={{c}}/> %}",
132
- },
133
-
134
- "should parse short fun statements with type parameters": {
135
- input: "{% fun vue [A,B:C,C] (a:A, b:B) = " + "{{ (a + b) + c }} %}",
136
- },
137
-
138
- "should parse extended fun statements": {
139
- input: "{% fun vue () %} <View/> {% endfun %}",
140
- },
141
-
142
- "should parse extended fun statements with arguments": {
143
- input:
144
- "{% fun vue (a:String, b:String, c:String) %}" +
145
- "<View a={{a}} b={{b}} c={{c}}/> {% endfun %}",
146
- },
147
-
148
- "should parse extended fun statements with type parameters": {
149
- input:
150
- "{% fun vue [A,B:C,C] (a:A, b:B) %} {{ ((a + b) + c) }} {% endfun %}",
151
- },
152
-
153
124
  "should parse binary expressions": {
154
125
  input: "<p>{{(Styles.A + Styles.B)}}</p>",
155
126
  },
@@ -158,14 +129,6 @@ export const tests: { [key: string]: any } = {
158
129
  input: '<div class={{((Styles.A + " ") + Style.B)}}/>',
159
130
  },
160
131
 
161
- "should allow for statement as child of fun": {
162
- input: "{% fun sven () %} {% for a in b %} {{b}} {% endfor %} {% endfun %}",
163
- },
164
- "should allow if statement as child of fun": {
165
- input:
166
- "{% fun ate (o:Object) %} {% if a %} {{a}} {% else %} {{a}} " +
167
- "{% endif %} {% endfun %}",
168
- },
169
132
  "should allow for booleans in interpolations": {
170
133
  input: "<bool active={{true}}>{{if fun() then false else true}}</bool>",
171
134
  },
@@ -215,33 +178,9 @@ export const tests: { [key: string]: any } = {
215
178
  "should allow fun application with context": {
216
179
  input: "<div>{{ <panel(@,12)> }}</div>",
217
180
  },
218
- "should parse list types": {
219
- input: "{% fun action [A] (s: String[], a:A[]) = {{ '${s}${a}' }} %}",
220
- },
221
181
  "should allow context properties as fun application": {
222
182
  input: "<div>{{ <@action()> }}</div>",
223
183
  },
224
- "should allow view statements after short fun": {
225
- input: `
226
-
227
- {% fun template [A] (d: Date[A], o:A, _:String, __:A[]) = {{String(o)}} %}
228
-
229
- {% view Results [A](Date[A]) %}
230
-
231
- <ul>
232
-
233
- {% for option,index in [1,3,4] %}
234
-
235
- <li>{{option}}and{{index}}</li>
236
-
237
- {% else %}
238
-
239
- <p>De nada!</p>
240
-
241
- {% endfor %}
242
-
243
- </ul>`,
244
- },
245
184
  "should allow actual code": {
246
185
  input: `
247
186
  {% import (Table) from "@quenk/wml-widgets/lib/data/table" %}
@@ -296,10 +235,6 @@ export const tests: { [key: string]: any } = {
296
235
  </Panel>`,
297
236
  },
298
237
 
299
- "should recognize type parameters": {
300
- input: "{% fun test[A:String] (a:A) %} {{a}} {% endfun %}",
301
- },
302
-
303
238
  "should allow ifs without elses": {
304
239
  input:
305
240
  "{% view Test (Object) %}" +
@@ -533,9 +468,6 @@ export const tests: { [key: string]: any } = {
533
468
 
534
469
  "[comment] should parse wml comments in statements": `{% view Name {# This is a comment! #} (Object) %} <div/> %}`,
535
470
 
536
- "[fun] should parse multi dimensional array parameters": `
537
- {% fun test (value:List[][]) %}<p/>{% endfun %}`,
538
-
539
471
  "should allow index access on context properties": `{% view Test (Object) %}
540
472
  <div>
541
473
  {% if @["type"] == 1 %}
@@ -582,4 +514,40 @@ export const tests: { [key: string]: any } = {
582
514
  m-20,10 h 10
583
515
  m-20,10 h 10" />
584
516
  </svg>`,
517
+ "should support part statements": `
518
+ {% part myPart0 (Ctx) %}
519
+ {% let name:String = "Me" %}
520
+ <h1>{{@name}}</h1>
521
+ {% endpart %}
522
+
523
+ {% part myPart1 (Ctx) %}<h1>{{@name}}</h1>{% endpart %}
524
+
525
+ {% part myPart2 (Ctx from "..") %}<h1>{{@name}}</h1>{% endpart %}
526
+
527
+ {% part myPart3 where name: String %}<h1>{{@name}}</h1>{% endpart %}
528
+
529
+ {% part myPart4 where name: String %}
530
+ {% let name:String = "Me" %}
531
+ <h1>{{@name}}</h1>
532
+ {% endpart %}
533
+ `,
534
+ "should support use statments": `
535
+ <div>
536
+ {% use part myPart %}
537
+ {% use view MyView %}
538
+ {% use part path.to.part %}
539
+ {% use view path.to.View %}
540
+ {% use part @path.to.part %}
541
+ {% use view @path.to.View %}
542
+ {% use view SomeView(@) %}
543
+ {% use part path.to.part({}) %}
544
+ {% use part myPath with @ %}
545
+ </div>
546
+ `,
547
+ "should support function types with optional params": `
548
+ {% context FuncContext where
549
+ func0: String? -> Void,
550
+ func1: (String, Number?) -> Void
551
+ %}
552
+ `
585
553
  };
package/lib/parse/wml.y CHANGED
@@ -77,8 +77,9 @@ Text ({DoubleStringCharacter}*)|({SingleStringCharacter}*)
77
77
  <CONTROL>'import' return 'IMPORT';
78
78
  <CONTROL>'from' return 'FROM';
79
79
  <CONTROL>'as' return 'AS';
80
- <CONTROL>'macro' return 'MACRO';
81
- <CONTROL>'endmacro' return 'ENDMACRO';
80
+ <CONTROL>'part' return 'PART';
81
+ <CONTROL>'endpart' return 'ENDPART';
82
+ <CONTROL>'use' return 'USE';
82
83
  <CONTROL>'for' return 'FOR';
83
84
  <CONTROL>'endfor' return 'ENDFOR';
84
85
  <CONTROL>'if' return 'IF';
@@ -101,6 +102,7 @@ Text ({DoubleStringCharacter}*)|({SingleStringCharacter}*)
101
102
  <CONTROL>'where' return 'WHERE';
102
103
  <CONTROL>'let' return 'LET';
103
104
  <CONTROL>'to' return 'TO';
105
+ <CONTROL>'with' return 'WITH';
104
106
  <CONTROL>{Constructor} return 'CONSTRUCTOR';
105
107
  <CONTROL>{Identifier} return 'IDENTIFIER';
106
108
  <CONTROL>'@' return '@';
@@ -249,7 +251,7 @@ export
249
251
 
250
252
  | view_statement
251
253
 
252
- | fun_statement
254
+ | part_statment
253
255
 
254
256
  | element
255
257
  {$$ = $1; }
@@ -398,24 +400,53 @@ view_directives
398
400
  { $$ = $1.concat($2); }
399
401
  ;
400
402
 
401
- fun_statement
403
+ part_statment
404
+ : '{%' PART unqualified_identifier '(' view_statement_context ')' '%}'
405
+ view_directives children
406
+ '{%' ENDPART '%}'
407
+ {$$ = new yy.ast.PartStatement($3, $5, $8, $9, @$); }
402
408
 
403
- : '{%' FUN unqualified_identifier type_parameters parameters '%}'
404
- children
405
- '{%' ENDFUN '%}'
406
- {$$ = new yy.ast.FunStatement($3, $4, $5, $7, @$); }
409
+ | '{%' PART unqualified_identifier '(' view_statement_context ')' '%}'
410
+ children
411
+ '{%' ENDPART '%}'
412
+ {$$ = new yy.ast.PartStatement($3, $5, [], $8, @$); }
407
413
 
408
- | '{%' FUN unqualified_identifier parameters '%}'
409
- children
410
- '{%' ENDFUN '%}'
411
- {$$ = new yy.ast.FunStatement($3, [], $4, $6, @$); }
414
+ | '{%' PART unqualified_identifier '%}'
415
+ view_directives children
416
+ '{%' ENDPART '%}'
417
+ {$$ = new yy.ast.PartStatement($3, undefined, $5, $6, @$); }
418
+
419
+ | '{%' PART unqualified_identifier '%}'
420
+ children
421
+ '{%' ENDPART '%}'
422
+ {$$ = new yy.ast.PartStatement($3, undefined, [], $5, @$); }
423
+
424
+ | '{%' PART unqualified_identifier WHERE context_members '%}'
425
+ view_directives children
426
+ '{%' ENDPART '%}'
427
+ {$$ = new yy.ast.PartStatement($3, $5, $7, $8, @$); }
428
+
429
+ | '{%' PART unqualified_identifier WHERE context_members '%}'
430
+ children
431
+ '{%' ENDPART '%}'
432
+ {$$ = new yy.ast.PartStatement($3, $5, [], $7, @$); }
433
+ ;
412
434
 
413
- | '{%' FUN unqualified_identifier type_parameters parameters '='
414
- child '%}'
415
- {$$ = new yy.ast.FunStatement($3, $4, $5, [$7], @$); }
435
+ use_statement
436
+ : '{%' USE PART use_target WITH expression '%}'
437
+ {$$ = new yy.ast.UsePartStatement($4, $6, @$); }
416
438
 
417
- | '{%' FUN unqualified_identifier parameters '=' child '%}'
418
- {$$ = new yy.ast.FunStatement($3, [], $4, [$6], @$); }
439
+ | '{%' USE PART use_target '%}'
440
+ {$$ = new yy.ast.UsePartStatement($4, undefined, @$); }
441
+
442
+ | '{%' USE VIEW use_target '%}'
443
+ {$$ = new yy.ast.UseViewStatement($4, @$); }
444
+ ;
445
+
446
+ use_target
447
+ : (construct_expression | call_expression | member_expression
448
+ | context_property | unqualified_constructor | unqualified_identifier
449
+ | context_variable)
419
450
  ;
420
451
 
421
452
  type_parameters
@@ -450,6 +481,7 @@ type
450
481
  { $$ = $1; }
451
482
  ;
452
483
 
484
+
453
485
  grouped_type
454
486
  : '(' non_function_type ')'
455
487
  { $$ = $2; }
@@ -541,27 +573,42 @@ function_type
541
573
  | '(' ')' '->' type
542
574
  { $$ = new yy.ast.FunctionType([], $4, @$); }
543
575
 
544
- | non_function_type '->' type
576
+ | function_type_parameter '->' type
545
577
  { $$ = new yy.ast.FunctionType([$1], $3, @$); }
546
578
 
547
- // If we don't use grouped_type here jison will trip up on the
548
- // ambiguity that implicitly exists between the type sub rules
549
- | grouped_type '->' type
579
+ | grouped_type '->' type
550
580
  { $$ = new yy.ast.FunctionType([$1], $3, @$); }
551
-
581
+
552
582
  | '(' function_type_parameters ')' '->' type
553
583
  { $$ = new yy.ast.FunctionType($2, $5, @$); }
554
584
  ;
555
585
 
586
+ function_type_parameter
587
+ : non_function_type
588
+ { $$ = $1; }
589
+
590
+ | optional_function_type
591
+ { $$ = $1; }
592
+ ;
593
+
594
+ optional_function_type
595
+ : non_function_type '?'
596
+ { $$ = new yy.ast.OptionalType($1, @$); }
597
+
598
+ | '(' function_type ')' '?'
599
+ { $$ = new yy.ast.OptionalType($1, @$); }
600
+
601
+ ;
602
+
556
603
  function_type_parameters
557
604
 
558
- : non_function_type ',' non_function_type
605
+ : function_type_parameter ',' function_type_parameter
559
606
  { $$ = [$1, $3]; }
560
607
 
561
608
  | '(' function_type ')' ',' '(' function_type ')'
562
609
  { $$ = [$2, $6]; }
563
610
 
564
- | function_type_parameters ',' non_function_type
611
+ | function_type_parameters ',' function_type_parameter
565
612
  { $$ = $1.concat($3); }
566
613
 
567
614
  | function_type_parameters ',' '(' function_type ')'
@@ -689,7 +736,7 @@ filter
689
736
  ;
690
737
 
691
738
  control
692
- : (for_statement|if_statement)
739
+ : (for_statement|if_statement|use_statement)
693
740
  {$$ = $1;}
694
741
  ;
695
742
 
@@ -966,7 +1013,10 @@ member_expression_head:
966
1013
  ;
967
1014
 
968
1015
  member_expression_tail
969
- : (unqualified_identifier| unqualified_constructor|string_literal)
1016
+ : unqualified_identifier
1017
+ | unqualified_constructor
1018
+ | string_literal
1019
+ | keyword
970
1020
  ;
971
1021
 
972
1022
  function_expression
@@ -1088,3 +1138,9 @@ binary_operator
1088
1138
  { $$ = $1; }
1089
1139
  ;
1090
1140
 
1141
+ keyword
1142
+ : (IMPORT | FROM | AS | TYPE | CONTEXT | WHERE | LET | VIEW | PART |
1143
+ ENDPART | FOR | IN | OF | TO | ENDFOR | IF | ELSE | ENDIF | USE |
1144
+ TRUE | FALSE | INSTANCEOF | WITH)
1145
+ {$$ = new yy.ast.UnqualifiedIdentifier($1, @$)}
1146
+ ;
@@ -47,6 +47,10 @@ declare class SetList {
47
47
  * wml ids and groups.
48
48
  */
49
49
  export interface Frame {
50
+ /**
51
+ * tree when sets is the rendered DOM content of the view
52
+ */
53
+ tree?: Content;
50
54
  /**
51
55
  * root sets the root element of a View's tree.
52
56
  */
@@ -68,37 +72,14 @@ export interface Frame {
68
72
  * this one.
69
73
  */
70
74
  view(view: View): Content;
71
- }
72
- /**
73
- * MultiFrame is a composite that allows more than one Frame to be rendered
74
- * at the same time.
75
- */
76
- export declare class MultiFrame implements Frame {
77
- frames: Frame[];
78
- constructor(frames?: Frame[]);
79
- root(el: Content): void;
80
- node(tag: string, attrs: Attrs, children: Content[]): Content;
81
- widget(w: Widget, attrs: Attrs): Content;
82
- view(view: View): Content;
83
- }
84
- /**
85
- * ViewFrame contains helper methods for retreiving elements by id or
86
- * group freeing the View class of such logic.
87
- */
88
- export declare class ViewFrame implements Frame {
89
- nodes: SetList;
90
- widgets: Map<number, Widget>;
91
- groups: Map<WMLId, Index[]>;
92
- ids: Map<string, number>;
93
- indexes: Map<number, string>;
94
- tree?: Content | undefined;
95
- constructor(nodes?: SetList, widgets?: Map<number, Widget>, groups?: Map<WMLId, Index[]>, ids?: Map<string, number>, indexes?: Map<number, string>, tree?: Content | undefined);
96
- _register(id: WMLId, node: Content, widget?: Widget): void;
97
- _registerGroupMember(id: WMLId, node: Content, widget?: Widget): void;
98
- root(el: Content): void;
99
- node(tag: string, attrs: Attrs, children: Content[]): Content;
100
- widget(w: Widget, attrs: Attrs): Content;
101
- view(view: View): Content;
75
+ /**
76
+ * register content and widget under the specified id.
77
+ */
78
+ register(id: WMLId, node: Content, widget?: Widget): void;
79
+ /**
80
+ * registerGroupMember registers a content and widget as a member of a group.
81
+ */
82
+ registerGroupMember(id: WMLId, node: Content, widget?: Widget): void;
102
83
  /**
103
84
  * findById returns the entry stored for the specified wml element.
104
85
  */
@@ -123,5 +104,36 @@ export declare class ViewFrame implements Frame {
123
104
  * replaceByGroup allows WMLElement replaced by using a group identifier.
124
105
  */
125
106
  replaceByGroup(next: ViewFrame, id: WMLId): void;
107
+ /**
108
+ * destroy the frame.
109
+ *
110
+ * Currently a no-op but may be used in the future.
111
+ */
112
+ destroy(): void;
113
+ }
114
+ /**
115
+ * ViewFrame contains helper methods for retreiving elements by id or
116
+ * group freeing the View class of such logic.
117
+ */
118
+ export declare class ViewFrame implements Frame {
119
+ nodes: SetList;
120
+ widgets: Map<number, Widget>;
121
+ groups: Map<WMLId, Index[]>;
122
+ ids: Map<string, number>;
123
+ indexes: Map<number, string>;
124
+ tree?: Content | undefined;
125
+ constructor(nodes?: SetList, widgets?: Map<number, Widget>, groups?: Map<WMLId, Index[]>, ids?: Map<string, number>, indexes?: Map<number, string>, tree?: Content | undefined);
126
+ register(id: WMLId, node: Content, widget?: Widget): void;
127
+ registerGroupMember(id: WMLId, node: Content, widget?: Widget): void;
128
+ root(el: Content): void;
129
+ node(tag: string, attrs: Attrs, children: Content[]): Content;
130
+ widget(w: Widget, attrs: Attrs): Content;
131
+ view(view: View): Content;
132
+ findById(id: WMLId): Maybe<Entry>;
133
+ findByGroup(id: WMLId): Entry[];
134
+ replaceByIndex(next: ViewFrame, idx: Index): void;
135
+ replaceById(next: ViewFrame, id: WMLId): void;
136
+ replaceByGroup(next: ViewFrame, id: WMLId): void;
137
+ destroy(): void;
126
138
  }
127
139
  export {};