@quenk/wml 2.13.11 → 2.14.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/cli.d.ts +8 -8
- package/lib/cli.js +1 -3
- package/lib/cli.js.map +1 -1
- package/lib/cli.ts +48 -60
- package/lib/compile/codegen.d.ts +4 -9
- package/lib/compile/codegen.js +161 -367
- package/lib/compile/codegen.js.map +1 -1
- package/lib/compile/codegen.ts +643 -952
- package/lib/compile/index.d.ts +2 -2
- package/lib/compile/index.js +4 -4
- package/lib/compile/index.js.map +1 -1
- package/lib/compile/index.ts +14 -17
- package/lib/compile/transform.d.ts +1 -1
- package/lib/compile/transform.js +9 -11
- package/lib/compile/transform.js.map +1 -1
- package/lib/compile/transform.ts +136 -143
- package/lib/{dom.d.ts → dom/index.d.ts} +8 -2
- package/lib/{dom.js → dom/index.js} +84 -70
- package/lib/dom/index.js.map +1 -0
- package/lib/dom/index.ts +425 -0
- package/lib/dom/monitor.d.ts +33 -0
- package/lib/dom/monitor.js +60 -0
- package/lib/dom/monitor.js.map +1 -0
- package/lib/dom/monitor.ts +75 -0
- package/lib/index.d.ts +10 -95
- package/lib/index.js +10 -10
- package/lib/index.js.map +1 -1
- package/lib/index.ts +57 -182
- package/lib/main.js +17 -17
- package/lib/main.js.map +1 -1
- package/lib/main.ts +38 -44
- package/lib/parse/ast.d.ts +2 -2
- package/lib/parse/ast.js +52 -53
- package/lib/parse/ast.js.map +1 -1
- package/lib/parse/ast.ts +396 -483
- package/lib/parse/generated.d.ts +3 -5
- package/lib/parse/generated.js +9504 -9264
- package/lib/parse/index.d.ts +2 -3
- package/lib/parse/index.js.map +1 -1
- package/lib/parse/index.ts +7 -9
- package/lib/parse/test.js +194 -192
- package/lib/parse/test.js.map +1 -1
- package/lib/parse/test.ts +294 -404
- package/lib/parse/wml.y +4 -0
- package/lib/tsconfig.json +19 -20
- package/lib/util.d.ts +10 -0
- package/lib/util.js +21 -0
- package/lib/util.js.map +1 -0
- package/lib/util.ts +39 -0
- package/lib/view/frame.d.ts +127 -0
- package/lib/view/frame.js +214 -0
- package/lib/view/frame.js.map +1 -0
- package/lib/view/frame.ts +295 -0
- package/lib/view/index.d.ts +58 -0
- package/lib/view/index.js +48 -0
- package/lib/view/index.js.map +1 -0
- package/lib/view/index.ts +98 -0
- package/package.json +3 -3
- package/lib/dom.js.map +0 -1
- package/lib/dom.ts +0 -479
package/lib/parse/wml.y
CHANGED
|
@@ -371,6 +371,10 @@ view_statement
|
|
|
371
371
|
| '{%' VIEW unqualified_constructor type_parameters WHERE
|
|
372
372
|
context_members '%}' view_directives element
|
|
373
373
|
{ $$ = new yy.ast.ViewStatement($3, $4, $6, $8, $9, @$); }
|
|
374
|
+
|
|
375
|
+
| '{%' VIEW unqualified_constructor '%}'
|
|
376
|
+
view_directives? element
|
|
377
|
+
{ $$ = new yy.ast.ViewStatement($3, [], undefined, $5 || [], $6, @$); }
|
|
374
378
|
;
|
|
375
379
|
|
|
376
380
|
view_statement_context
|
package/lib/tsconfig.json
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"baseUrl": "src",
|
|
4
|
+
"lib": ["es5", "ES2015", "dom", "dom.iterable"],
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"target": "ES2021",
|
|
7
|
+
"rootDir": ".",
|
|
8
|
+
"moduleResolution": "node",
|
|
9
|
+
"allowUnreachableCode": true,
|
|
10
|
+
"noUnusedParameters": true,
|
|
11
|
+
"noUnusedLocals": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"noImplicitAny": true,
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"declaration": true,
|
|
16
|
+
"strict": true,
|
|
17
|
+
"types": ["node"],
|
|
18
|
+
"typeRoots": ["../node_modules/@types"]
|
|
19
|
+
},
|
|
20
|
+
"exclude": ["node_modules"]
|
|
22
21
|
}
|
package/lib/util.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Record } from "@quenk/noni/lib/data/record";
|
|
2
|
+
import { Type } from "@quenk/noni/lib/data/type";
|
|
3
|
+
import { Content } from "./";
|
|
4
|
+
export type IfArg = () => Content[];
|
|
5
|
+
export type ForAlt = () => Content[];
|
|
6
|
+
export type ForInBody<A> = (val: A, idx: number, all: A[]) => Content[];
|
|
7
|
+
export type ForOfBody<A> = (val: A, key: string, all: object) => Content[];
|
|
8
|
+
export declare const forIn: <A>(list: A[], f: ForInBody<A>, alt: ForAlt) => Content[];
|
|
9
|
+
export declare const forOf: <A>(o: Record<A>, f: ForOfBody<A>, alt: ForAlt) => Content[];
|
|
10
|
+
export declare const isSet: (value: Type) => boolean;
|
package/lib/util.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSet = exports.forOf = exports.forIn = void 0;
|
|
4
|
+
const forIn = (list, f, alt) => {
|
|
5
|
+
let ret = [];
|
|
6
|
+
for (let i = 0; i < list.length; i++)
|
|
7
|
+
ret = ret.concat(f(list[i], i, list));
|
|
8
|
+
return ret.length === 0 ? alt() : ret;
|
|
9
|
+
};
|
|
10
|
+
exports.forIn = forIn;
|
|
11
|
+
const forOf = (o, f, alt) => {
|
|
12
|
+
let ret = [];
|
|
13
|
+
for (let key in o)
|
|
14
|
+
if (o.hasOwnProperty(key))
|
|
15
|
+
ret = ret.concat(f(o[key], key, o));
|
|
16
|
+
return ret.length === 0 ? alt() : ret;
|
|
17
|
+
};
|
|
18
|
+
exports.forOf = forOf;
|
|
19
|
+
const isSet = (value) => value != null;
|
|
20
|
+
exports.isSet = isSet;
|
|
21
|
+
//# sourceMappingURL=util.js.map
|
package/lib/util.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["util.ts"],"names":[],"mappings":";;;AAaO,MAAM,KAAK,GAAG,CACnB,IAAS,EACT,CAAe,EACf,GAAW,EACA,EAAE;IACb,IAAI,GAAG,GAAc,EAAE,CAAC;IAExB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;IAE5E,OAAO,GAAG,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;AACxC,CAAC,CAAC;AAVW,QAAA,KAAK,SAUhB;AAEK,MAAM,KAAK,GAAG,CACnB,CAAY,EACZ,CAAe,EACf,GAAW,EACA,EAAE;IACb,IAAI,GAAG,GAAc,EAAE,CAAC;IAExB,KAAK,IAAI,GAAG,IAAI,CAAC;QACf,IAAI,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC;YAAE,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IAEjE,OAAO,GAAG,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;AACxC,CAAC,CAAC;AAXW,QAAA,KAAK,SAWhB;AAEK,MAAM,KAAK,GAAG,CAAC,KAAW,EAAE,EAAE,CAAC,KAAK,IAAI,IAAI,CAAC;AAAvC,QAAA,KAAK,SAAkC"}
|
package/lib/util.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Record } from "@quenk/noni/lib/data/record";
|
|
2
|
+
import { Type } from "@quenk/noni/lib/data/type";
|
|
3
|
+
|
|
4
|
+
import { Content } from "./";
|
|
5
|
+
|
|
6
|
+
export type IfArg = () => Content[];
|
|
7
|
+
|
|
8
|
+
export type ForAlt = () => Content[];
|
|
9
|
+
|
|
10
|
+
export type ForInBody<A> = (val: A, idx: number, all: A[]) => Content[];
|
|
11
|
+
|
|
12
|
+
export type ForOfBody<A> = (val: A, key: string, all: object) => Content[];
|
|
13
|
+
|
|
14
|
+
export const forIn = <A>(
|
|
15
|
+
list: A[],
|
|
16
|
+
f: ForInBody<A>,
|
|
17
|
+
alt: ForAlt,
|
|
18
|
+
): Content[] => {
|
|
19
|
+
let ret: Content[] = [];
|
|
20
|
+
|
|
21
|
+
for (let i = 0; i < list.length; i++) ret = ret.concat(f(list[i], i, list));
|
|
22
|
+
|
|
23
|
+
return ret.length === 0 ? alt() : ret;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const forOf = <A>(
|
|
27
|
+
o: Record<A>,
|
|
28
|
+
f: ForOfBody<A>,
|
|
29
|
+
alt: ForAlt,
|
|
30
|
+
): Content[] => {
|
|
31
|
+
let ret: Content[] = [];
|
|
32
|
+
|
|
33
|
+
for (let key in o)
|
|
34
|
+
if (o.hasOwnProperty(key)) ret = ret.concat(f(o[key], key, o));
|
|
35
|
+
|
|
36
|
+
return ret.length === 0 ? alt() : ret;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const isSet = (value: Type) => value != null;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Maybe } from "@quenk/noni/lib/data/maybe";
|
|
2
|
+
import { Attrs, Content, WMLId, Widget } from "..";
|
|
3
|
+
import { View } from ".";
|
|
4
|
+
/**
|
|
5
|
+
* Index used for lists and other data structures.
|
|
6
|
+
*
|
|
7
|
+
* TODO: migrate to noni.
|
|
8
|
+
*/
|
|
9
|
+
export type Index = number;
|
|
10
|
+
/**
|
|
11
|
+
* Entry contains the DOM node and optional widget for an WMLElement.
|
|
12
|
+
*/
|
|
13
|
+
export interface Entry {
|
|
14
|
+
node: Content;
|
|
15
|
+
widget?: Widget;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* SetList is a list like data structure that ensures an object is only added
|
|
19
|
+
* once.
|
|
20
|
+
*
|
|
21
|
+
* This allows for items to be added and their index returned without having
|
|
22
|
+
* to iterate over the members to determine if the item was added already.
|
|
23
|
+
*
|
|
24
|
+
* Instead a map of item -> index values is kept internally allowing for fast
|
|
25
|
+
* lookup of new items being added.
|
|
26
|
+
*
|
|
27
|
+
* TODO:
|
|
28
|
+
* 1. Migrate to noni.
|
|
29
|
+
* 2. Find a way to support nested objects, example: {node, widget}
|
|
30
|
+
*/
|
|
31
|
+
declare class SetList {
|
|
32
|
+
items: Content[];
|
|
33
|
+
cache: Map<Content, Index>;
|
|
34
|
+
constructor(items?: Content[], cache?: Map<Content, Index>);
|
|
35
|
+
add(item: Content): number;
|
|
36
|
+
set(id: Index, item: Content): number;
|
|
37
|
+
has(id: Index): boolean;
|
|
38
|
+
get(id: Index): Content;
|
|
39
|
+
delete(idx: Index): void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Frame serves as a container for the DOM elements a View's template
|
|
43
|
+
* renders.
|
|
44
|
+
*
|
|
45
|
+
* Each time the render() method is called a new Frame is created and passed
|
|
46
|
+
* to the rendering logic so that a DOM tree is built along with accesible
|
|
47
|
+
* wml ids and groups.
|
|
48
|
+
*/
|
|
49
|
+
export interface Frame {
|
|
50
|
+
/**
|
|
51
|
+
* root sets the root element of a View's tree.
|
|
52
|
+
*/
|
|
53
|
+
root(el: Content): void;
|
|
54
|
+
/**
|
|
55
|
+
* node constructs a DOM node to be used in the View's tree.
|
|
56
|
+
*
|
|
57
|
+
* Any id or group assignment will be honored.
|
|
58
|
+
*/
|
|
59
|
+
node(tag: string, attrs: Attrs, children: Content[]): Content;
|
|
60
|
+
/**
|
|
61
|
+
* widget constructs a DOM sub-tree for a Widget in the View's tree.
|
|
62
|
+
*
|
|
63
|
+
* Any id or group assignment will be honored.
|
|
64
|
+
*/
|
|
65
|
+
widget(w: Widget, attrs: Attrs): Content;
|
|
66
|
+
/**
|
|
67
|
+
* view renders the content of another view, saving its ids and groups to
|
|
68
|
+
* this one.
|
|
69
|
+
*/
|
|
70
|
+
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;
|
|
102
|
+
/**
|
|
103
|
+
* findById returns the entry stored for the specified wml element.
|
|
104
|
+
*/
|
|
105
|
+
findById(id: WMLId): Maybe<Entry>;
|
|
106
|
+
/**
|
|
107
|
+
* findByGroup returns all the entries stored fro a group.
|
|
108
|
+
*/
|
|
109
|
+
findByGroup(id: WMLId): Entry[];
|
|
110
|
+
/**
|
|
111
|
+
* replaceByIndex performs the heavy work of replacing a WMLElement
|
|
112
|
+
* with the corresponding index from another ViewFrame.
|
|
113
|
+
*
|
|
114
|
+
* The replaced element will have its DOM content redrawn if a parentNode
|
|
115
|
+
* is detected.
|
|
116
|
+
*/
|
|
117
|
+
replaceByIndex(next: ViewFrame, idx: Index): void;
|
|
118
|
+
/**
|
|
119
|
+
* replaceById allows WMLElement replacement by using an id.
|
|
120
|
+
*/
|
|
121
|
+
replaceById(next: ViewFrame, id: WMLId): void;
|
|
122
|
+
/**
|
|
123
|
+
* replaceByGroup allows WMLElement replaced by using a group identifier.
|
|
124
|
+
*/
|
|
125
|
+
replaceByGroup(next: ViewFrame, id: WMLId): void;
|
|
126
|
+
}
|
|
127
|
+
export {};
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ViewFrame = exports.MultiFrame = void 0;
|
|
4
|
+
const dom = require("../dom");
|
|
5
|
+
const maybe_1 = require("@quenk/noni/lib/data/maybe");
|
|
6
|
+
const monitor_1 = require("../dom/monitor");
|
|
7
|
+
/**
|
|
8
|
+
* SetList is a list like data structure that ensures an object is only added
|
|
9
|
+
* once.
|
|
10
|
+
*
|
|
11
|
+
* This allows for items to be added and their index returned without having
|
|
12
|
+
* to iterate over the members to determine if the item was added already.
|
|
13
|
+
*
|
|
14
|
+
* Instead a map of item -> index values is kept internally allowing for fast
|
|
15
|
+
* lookup of new items being added.
|
|
16
|
+
*
|
|
17
|
+
* TODO:
|
|
18
|
+
* 1. Migrate to noni.
|
|
19
|
+
* 2. Find a way to support nested objects, example: {node, widget}
|
|
20
|
+
*/
|
|
21
|
+
class SetList {
|
|
22
|
+
constructor(items = [], cache = new Map()) {
|
|
23
|
+
this.items = items;
|
|
24
|
+
this.cache = cache;
|
|
25
|
+
}
|
|
26
|
+
add(item) {
|
|
27
|
+
let idx = this.cache.get(item) ?? this.items.push(item) - 1;
|
|
28
|
+
this.cache.set(item, idx);
|
|
29
|
+
return idx;
|
|
30
|
+
}
|
|
31
|
+
set(id, item) {
|
|
32
|
+
let prev = this.items[id];
|
|
33
|
+
this.items[id] = item;
|
|
34
|
+
this.cache.delete(prev);
|
|
35
|
+
this.cache.set(item, id);
|
|
36
|
+
return id;
|
|
37
|
+
}
|
|
38
|
+
has(id) {
|
|
39
|
+
return Boolean(this.get(id));
|
|
40
|
+
}
|
|
41
|
+
get(id) {
|
|
42
|
+
return this.items[id];
|
|
43
|
+
}
|
|
44
|
+
delete(idx) {
|
|
45
|
+
let node = this.items[idx];
|
|
46
|
+
this.items.splice(idx, 1);
|
|
47
|
+
this.cache.delete(node);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* MultiFrame is a composite that allows more than one Frame to be rendered
|
|
52
|
+
* at the same time.
|
|
53
|
+
*/
|
|
54
|
+
class MultiFrame {
|
|
55
|
+
constructor(frames = []) {
|
|
56
|
+
this.frames = frames;
|
|
57
|
+
}
|
|
58
|
+
root(el) {
|
|
59
|
+
for (let f of this.frames) {
|
|
60
|
+
f.root(el);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
node(tag, attrs, children) {
|
|
64
|
+
let results = this.frames.map((f) => f.node(tag, attrs, children));
|
|
65
|
+
return results[0] ?? dom.createElement('div', {}, []);
|
|
66
|
+
}
|
|
67
|
+
widget(w, attrs) {
|
|
68
|
+
let results = this.frames.map((f) => f.widget(w, attrs));
|
|
69
|
+
return results[0] ?? dom.createElement('div', {}, []);
|
|
70
|
+
}
|
|
71
|
+
view(view) {
|
|
72
|
+
let results = this.frames.map((f) => f.view(view));
|
|
73
|
+
return results[0] ?? dom.createElement('div', {}, []);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.MultiFrame = MultiFrame;
|
|
77
|
+
/**
|
|
78
|
+
* ViewFrame contains helper methods for retreiving elements by id or
|
|
79
|
+
* group freeing the View class of such logic.
|
|
80
|
+
*/
|
|
81
|
+
class ViewFrame {
|
|
82
|
+
constructor(nodes = new SetList(), widgets = new Map(), groups = new Map(), ids = new Map(), indexes = new Map(), tree) {
|
|
83
|
+
this.nodes = nodes;
|
|
84
|
+
this.widgets = widgets;
|
|
85
|
+
this.groups = groups;
|
|
86
|
+
this.ids = ids;
|
|
87
|
+
this.indexes = indexes;
|
|
88
|
+
this.tree = tree;
|
|
89
|
+
}
|
|
90
|
+
_register(id, node, widget) {
|
|
91
|
+
let idx = this.nodes.add(node);
|
|
92
|
+
this.ids.set(id, idx);
|
|
93
|
+
this.indexes.set(idx, id);
|
|
94
|
+
if (widget) {
|
|
95
|
+
this.widgets.set(idx, widget);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
_registerGroupMember(id, node, widget) {
|
|
99
|
+
let group = this.groups.get(id) ?? [];
|
|
100
|
+
let idx = this.nodes.add(node);
|
|
101
|
+
group.push(idx);
|
|
102
|
+
if (widget)
|
|
103
|
+
this.widgets.set(idx, widget);
|
|
104
|
+
this.groups.set(id, group);
|
|
105
|
+
}
|
|
106
|
+
root(el) {
|
|
107
|
+
this.tree = el;
|
|
108
|
+
}
|
|
109
|
+
node(tag, attrs, children) {
|
|
110
|
+
let elm = dom.createElement(tag, attrs, children, (attrs.wml && attrs.wml.ns) || "");
|
|
111
|
+
if (attrs?.wml?.id)
|
|
112
|
+
this._register(attrs.wml.id, elm);
|
|
113
|
+
if (attrs?.wml?.group)
|
|
114
|
+
this._registerGroupMember(attrs.wml.group, elm);
|
|
115
|
+
return elm;
|
|
116
|
+
}
|
|
117
|
+
widget(w, attrs) {
|
|
118
|
+
let tree = w.render();
|
|
119
|
+
monitor_1.DOMMonitor.getInstance().monitor(tree, w);
|
|
120
|
+
if (attrs?.wml?.id)
|
|
121
|
+
this._register(attrs.wml.id, tree, w);
|
|
122
|
+
if (attrs?.wml?.group)
|
|
123
|
+
this._registerGroupMember(attrs.wml.group, tree, w);
|
|
124
|
+
return tree;
|
|
125
|
+
}
|
|
126
|
+
view(view) {
|
|
127
|
+
let { root } = this;
|
|
128
|
+
let tree = view.render(this);
|
|
129
|
+
this.root = root;
|
|
130
|
+
return tree;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* findById returns the entry stored for the specified wml element.
|
|
134
|
+
*/
|
|
135
|
+
findById(id) {
|
|
136
|
+
let idx = this.ids.get(id) ?? -1;
|
|
137
|
+
let node = this.nodes.get(idx);
|
|
138
|
+
if (node == null)
|
|
139
|
+
return maybe_1.Maybe.nothing();
|
|
140
|
+
return maybe_1.Maybe.just({
|
|
141
|
+
node,
|
|
142
|
+
widget: this.widgets.get(idx),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* findByGroup returns all the entries stored fro a group.
|
|
147
|
+
*/
|
|
148
|
+
findByGroup(id) {
|
|
149
|
+
let result = [];
|
|
150
|
+
for (let idx of this.groups.get(id) ?? []) {
|
|
151
|
+
let node = this.nodes.get(idx);
|
|
152
|
+
let widget = this.widgets.get(idx);
|
|
153
|
+
if (node == null)
|
|
154
|
+
continue;
|
|
155
|
+
result.push({ node, widget });
|
|
156
|
+
}
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* replaceByIndex performs the heavy work of replacing a WMLElement
|
|
161
|
+
* with the corresponding index from another ViewFrame.
|
|
162
|
+
*
|
|
163
|
+
* The replaced element will have its DOM content redrawn if a parentNode
|
|
164
|
+
* is detected.
|
|
165
|
+
*/
|
|
166
|
+
replaceByIndex(next, idx) {
|
|
167
|
+
let originalNode = this.nodes.get(idx);
|
|
168
|
+
let id = this.indexes.get(idx) ?? "";
|
|
169
|
+
if (idx == null || originalNode == null) {
|
|
170
|
+
console.warn(`Not replacing missing WMLElement for id "${id}"!`);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
let { parentNode } = originalNode;
|
|
174
|
+
let node = next.nodes.get(idx);
|
|
175
|
+
let widget = next.widgets.get(idx);
|
|
176
|
+
if (node == null) {
|
|
177
|
+
// Remove references since the node no longer exists.
|
|
178
|
+
this.nodes.delete(idx);
|
|
179
|
+
this.widgets.delete(idx);
|
|
180
|
+
this.ids.delete(id);
|
|
181
|
+
this.indexes.delete(idx);
|
|
182
|
+
if (parentNode)
|
|
183
|
+
parentNode.removeChild(originalNode);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
this.nodes.set(idx, node);
|
|
187
|
+
this.widgets.delete(idx);
|
|
188
|
+
if (widget)
|
|
189
|
+
this.widgets.set(idx, widget);
|
|
190
|
+
if (parentNode)
|
|
191
|
+
parentNode.replaceChild(node, originalNode);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* replaceById allows WMLElement replacement by using an id.
|
|
195
|
+
*/
|
|
196
|
+
replaceById(next, id) {
|
|
197
|
+
this.replaceByIndex(next, this.ids.get(id) ?? -1);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* replaceByGroup allows WMLElement replaced by using a group identifier.
|
|
201
|
+
*/
|
|
202
|
+
replaceByGroup(next, id) {
|
|
203
|
+
let group = this.groups.get(id) ?? [];
|
|
204
|
+
let newGroup = [];
|
|
205
|
+
for (let idx of group) {
|
|
206
|
+
this.replaceByIndex(next, idx);
|
|
207
|
+
if (this.nodes.has(idx))
|
|
208
|
+
newGroup.push(idx);
|
|
209
|
+
}
|
|
210
|
+
this.groups.set(id, newGroup);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
exports.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