jmx-runtime 0.0.24 → 0.0.26
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/dist/base.d.ts +5 -5
- package/dist/base.js +21 -21
- package/dist/config.d.ts +8 -8
- package/dist/config.js +4 -4
- package/dist/h.d.ts +57 -57
- package/dist/h.js +6 -6
- package/dist/index.d.ts +5 -5
- package/dist/index.js +5 -5
- package/dist/jmx.d.ts +8 -8
- package/dist/jmx.js +134 -135
- package/dist/jmx.js.map +1 -1
- package/dist/jsx.d.ts +647 -647
- package/dist/jsx.js +1 -1
- package/dist/lib.d.ts +19 -19
- package/dist/lib.js +15 -15
- package/jmx.ts +1 -1
- package/lib.ts +1 -0
- package/package.json +1 -1
package/dist/base.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare function rebind(o: Record<string, any>): Record<string, any>;
|
|
2
|
-
export declare function mount(o: Record<string, any>): void;
|
|
3
|
-
export declare const loggedmethodsex: <T extends Record<string, any>>(o: T, logger: (name: string, args: any[], result: any) => void) => T;
|
|
4
|
-
export declare const loggedmethods: <T extends Record<string, any>>(o: T) => T;
|
|
5
|
-
export declare const loggedmethodscolored: <T extends Record<string, any>>(bgcolor: string, o: T) => T;
|
|
1
|
+
export declare function rebind(o: Record<string, any>): Record<string, any>;
|
|
2
|
+
export declare function mount(o: Record<string, any>): void;
|
|
3
|
+
export declare const loggedmethodsex: <T extends Record<string, any>>(o: T, logger: (name: string, args: any[], result: any) => void) => T;
|
|
4
|
+
export declare const loggedmethods: <T extends Record<string, any>>(o: T) => T;
|
|
5
|
+
export declare const loggedmethodscolored: <T extends Record<string, any>>(bgcolor: string, o: T) => T;
|
|
6
6
|
//# sourceMappingURL=base.d.ts.map
|
package/dist/base.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
export function rebind(o) {
|
|
2
|
-
Object.entries(Object.getOwnPropertyDescriptors(Object.getPrototypeOf(o)))
|
|
3
|
-
.filter(([name, p]) => name != 'constructor' && p.value instanceof Function)
|
|
4
|
-
.forEach(([name]) => o[name] = o[name].bind(o));
|
|
5
|
-
return o;
|
|
6
|
-
}
|
|
7
|
-
export function mount(o) { Object.assign(globalThis, o); }
|
|
8
|
-
export const loggedmethodsex = (o, logger) => new Proxy(o, {
|
|
9
|
-
get(target, name, receiver) {
|
|
10
|
-
if (typeof target[name] === "function") {
|
|
11
|
-
return function (...args) {
|
|
12
|
-
logger(name, args, undefined);
|
|
13
|
-
let r = target[name].apply(this, args);
|
|
14
|
-
return r;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
return Reflect.get(target, name, receiver);
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
export const loggedmethods = (o) => loggedmethodsex(o, (name, args, result) => console.log("%c" + name, "background:#585059;color:white;padding:2px;font-weight:bold", args));
|
|
21
|
-
export const loggedmethodscolored = (bgcolor, o) => loggedmethodsex(o, (name, args, result) => console.log("%c" + name, `background:${bgcolor};color:white;padding:2px;font-weight:bold`, args));
|
|
1
|
+
export function rebind(o) {
|
|
2
|
+
Object.entries(Object.getOwnPropertyDescriptors(Object.getPrototypeOf(o)))
|
|
3
|
+
.filter(([name, p]) => name != 'constructor' && p.value instanceof Function)
|
|
4
|
+
.forEach(([name]) => o[name] = o[name].bind(o));
|
|
5
|
+
return o;
|
|
6
|
+
}
|
|
7
|
+
export function mount(o) { Object.assign(globalThis, o); }
|
|
8
|
+
export const loggedmethodsex = (o, logger) => new Proxy(o, {
|
|
9
|
+
get(target, name, receiver) {
|
|
10
|
+
if (typeof target[name] === "function") {
|
|
11
|
+
return function (...args) {
|
|
12
|
+
logger(name, args, undefined);
|
|
13
|
+
let r = target[name].apply(this, args);
|
|
14
|
+
return r;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return Reflect.get(target, name, receiver);
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
export const loggedmethods = (o) => loggedmethodsex(o, (name, args, result) => console.log("%c" + name, "background:#585059;color:white;padding:2px;font-weight:bold", args));
|
|
21
|
+
export const loggedmethodscolored = (bgcolor, o) => loggedmethodsex(o, (name, args, result) => console.log("%c" + name, `background:${bgcolor};color:white;padding:2px;font-weight:bold`, args));
|
|
22
22
|
//# sourceMappingURL=base.js.map
|
package/dist/config.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
declare global {
|
|
2
|
-
interface Window {
|
|
3
|
-
jmx?: {
|
|
4
|
-
getnamespace: (tag: string) => string;
|
|
5
|
-
};
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
export declare function createElement(tag: string): Element;
|
|
1
|
+
declare global {
|
|
2
|
+
interface Window {
|
|
3
|
+
jmx?: {
|
|
4
|
+
getnamespace: (tag: string) => string;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export declare function createElement(tag: string): Element;
|
|
9
9
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export function createElement(tag) {
|
|
2
|
-
let ns = window.jmx?.getnamespace?.(tag);
|
|
3
|
-
return ns ? document.createElementNS(ns, tag) : document.createElement(tag);
|
|
4
|
-
}
|
|
1
|
+
export function createElement(tag) {
|
|
2
|
+
let ns = window.jmx?.getnamespace?.(tag);
|
|
3
|
+
return ns ? document.createElementNS(ns, tag) : document.createElement(tag);
|
|
4
|
+
}
|
|
5
5
|
//# sourceMappingURL=config.js.map
|
package/dist/h.d.ts
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
type Func<T> = () => T;
|
|
2
|
-
export type Expr<T> = T | Func<T>;
|
|
3
|
-
export type Props = Record<string, any>;
|
|
4
|
-
export type FComponent = (props: Props | undefined, children?: ChildrenH) => HElement;
|
|
5
|
-
export type FComponentT<P> = (pcn: P, cn?: Children) => H | void;
|
|
6
|
-
export interface IClassComponent {
|
|
7
|
-
element: Node;
|
|
8
|
-
props?: Record<string, any>;
|
|
9
|
-
view(): H;
|
|
10
|
-
update(uc: IUpdateContext): boolean | void;
|
|
11
|
-
mounted?(): void;
|
|
12
|
-
}
|
|
13
|
-
interface CComponent {
|
|
14
|
-
new (props: any): IClassComponent;
|
|
15
|
-
}
|
|
16
|
-
export type ChildrenH = (H | undefined)[];
|
|
17
|
-
export type Children = Expr<ChildrenH>;
|
|
18
|
-
type HText = string | number | boolean;
|
|
19
|
-
export type HFragment = {
|
|
20
|
-
cn: Children;
|
|
21
|
-
};
|
|
22
|
-
export type HElement = {
|
|
23
|
-
tag: string;
|
|
24
|
-
p?: Expr<Props>;
|
|
25
|
-
cn: Children;
|
|
26
|
-
i?: any;
|
|
27
|
-
};
|
|
28
|
-
type HCompFun = {
|
|
29
|
-
tag: FComponent;
|
|
30
|
-
p?: Expr<Props>;
|
|
31
|
-
cn?: Children;
|
|
32
|
-
};
|
|
33
|
-
export type HCompClass = {
|
|
34
|
-
tag: CComponent;
|
|
35
|
-
p?: Expr<Props>;
|
|
36
|
-
cn: Children;
|
|
37
|
-
i: IClassComponent;
|
|
38
|
-
};
|
|
39
|
-
export type HComp = HCompFun | HCompClass;
|
|
40
|
-
export type H = HText | HElement | HComp | HFragment;
|
|
41
|
-
declare global {
|
|
42
|
-
interface Node {
|
|
43
|
-
h?: HElement | HCompFun | HCompClass;
|
|
44
|
-
}
|
|
45
|
-
export interface IUpdateContext {
|
|
46
|
-
patchElementOnly?: boolean;
|
|
47
|
-
replace?: boolean;
|
|
48
|
-
}
|
|
49
|
-
export interface Window {
|
|
50
|
-
jmx?: {
|
|
51
|
-
getnamespace: (tag: string) => string | undefined;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
export declare function jsx(): HElement;
|
|
56
|
-
export declare function jsxf(): HElement;
|
|
57
|
-
export {};
|
|
1
|
+
type Func<T> = () => T;
|
|
2
|
+
export type Expr<T> = T | Func<T>;
|
|
3
|
+
export type Props = Record<string, any>;
|
|
4
|
+
export type FComponent = (props: Props | undefined, children?: ChildrenH) => HElement;
|
|
5
|
+
export type FComponentT<P> = (pcn: P, cn?: Children) => H | void;
|
|
6
|
+
export interface IClassComponent {
|
|
7
|
+
element: Node;
|
|
8
|
+
props?: Record<string, any>;
|
|
9
|
+
view(): H;
|
|
10
|
+
update(uc: IUpdateContext): boolean | void;
|
|
11
|
+
mounted?(): void;
|
|
12
|
+
}
|
|
13
|
+
interface CComponent {
|
|
14
|
+
new (props: any): IClassComponent;
|
|
15
|
+
}
|
|
16
|
+
export type ChildrenH = (H | undefined)[];
|
|
17
|
+
export type Children = Expr<ChildrenH>;
|
|
18
|
+
type HText = string | number | boolean;
|
|
19
|
+
export type HFragment = {
|
|
20
|
+
cn: Children;
|
|
21
|
+
};
|
|
22
|
+
export type HElement = {
|
|
23
|
+
tag: string;
|
|
24
|
+
p?: Expr<Props>;
|
|
25
|
+
cn: Children;
|
|
26
|
+
i?: any;
|
|
27
|
+
};
|
|
28
|
+
type HCompFun = {
|
|
29
|
+
tag: FComponent;
|
|
30
|
+
p?: Expr<Props>;
|
|
31
|
+
cn?: Children;
|
|
32
|
+
};
|
|
33
|
+
export type HCompClass = {
|
|
34
|
+
tag: CComponent;
|
|
35
|
+
p?: Expr<Props>;
|
|
36
|
+
cn: Children;
|
|
37
|
+
i: IClassComponent;
|
|
38
|
+
};
|
|
39
|
+
export type HComp = HCompFun | HCompClass;
|
|
40
|
+
export type H = HText | HElement | HComp | HFragment;
|
|
41
|
+
declare global {
|
|
42
|
+
interface Node {
|
|
43
|
+
h?: HElement | HCompFun | HCompClass;
|
|
44
|
+
}
|
|
45
|
+
export interface IUpdateContext {
|
|
46
|
+
patchElementOnly?: boolean;
|
|
47
|
+
replace?: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface Window {
|
|
50
|
+
jmx?: {
|
|
51
|
+
getnamespace: (tag: string) => string | undefined;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export declare function jsx(): HElement;
|
|
56
|
+
export declare function jsxf(): HElement;
|
|
57
|
+
export {};
|
|
58
58
|
//# sourceMappingURL=h.d.ts.map
|
package/dist/h.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export function jsx() {
|
|
2
|
-
throw 'jmx plugin not configured';
|
|
3
|
-
}
|
|
4
|
-
export function jsxf() {
|
|
5
|
-
throw 'jmx plugin not configured';
|
|
6
|
-
}
|
|
1
|
+
export function jsx() {
|
|
2
|
+
throw 'jmx plugin not configured';
|
|
3
|
+
}
|
|
4
|
+
export function jsxf() {
|
|
5
|
+
throw 'jmx plugin not configured';
|
|
6
|
+
}
|
|
7
7
|
//# sourceMappingURL=h.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './jmx';
|
|
2
|
-
export * from './lib';
|
|
3
|
-
export * from './base';
|
|
4
|
-
export * from './h';
|
|
5
|
-
export * from './jsx';
|
|
1
|
+
export * from './jmx';
|
|
2
|
+
export * from './lib';
|
|
3
|
+
export * from './base';
|
|
4
|
+
export * from './h';
|
|
5
|
+
export * from './jsx';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './jmx';
|
|
2
|
-
export * from './lib';
|
|
3
|
-
export * from './base';
|
|
4
|
-
export * from './h';
|
|
5
|
-
export * from './jsx';
|
|
1
|
+
export * from './jmx';
|
|
2
|
+
export * from './lib';
|
|
3
|
+
export * from './base';
|
|
4
|
+
export * from './h';
|
|
5
|
+
export * from './jsx';
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/dist/jmx.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Expr, H } from './h';
|
|
2
|
-
export declare function createElement(tag: string): Element;
|
|
3
|
-
export declare function patch(e: Node | null, h: Expr<H>): void;
|
|
4
|
-
type Selector = string | Node | undefined | null;
|
|
5
|
-
type Selectors = Selector[];
|
|
6
|
-
export declare function updateviewuc(uc: IUpdateContext, ...sels: Selectors): void;
|
|
7
|
-
export declare function updateview(...sels: Selectors): void;
|
|
8
|
-
export {};
|
|
1
|
+
import { Expr, H } from './h';
|
|
2
|
+
export declare function createElement(tag: string): Element;
|
|
3
|
+
export declare function patch(e: Node | null, h: Expr<H>): void;
|
|
4
|
+
type Selector = string | Node | undefined | null;
|
|
5
|
+
type Selectors = Selector[];
|
|
6
|
+
export declare function updateviewuc(uc: IUpdateContext, ...sels: Selectors): void;
|
|
7
|
+
export declare function updateview(...sels: Selectors): void;
|
|
8
|
+
export {};
|
|
9
9
|
//# sourceMappingURL=jmx.d.ts.map
|
package/dist/jmx.js
CHANGED
|
@@ -1,136 +1,135 @@
|
|
|
1
|
-
import { rebind } from './base';
|
|
2
|
-
export function createElement(tag) {
|
|
3
|
-
let ns = window.jmx?.getnamespace?.(tag);
|
|
4
|
-
return ns ? document.createElementNS(ns, tag) : document.createElement(tag);
|
|
5
|
-
}
|
|
6
|
-
let evaluate = (expr) => (expr instanceof Function ? expr() : expr);
|
|
7
|
-
let removeexcesschildren = (n, i) => {
|
|
8
|
-
let c;
|
|
9
|
-
while ((c = n.childNodes[i])) {
|
|
10
|
-
c.remove();
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
let iswebcomponent = (h) => h.tag.includes('-');
|
|
14
|
-
let isclasscomponent = (h) => h.tag?.prototype?.view;
|
|
15
|
-
let iselement = (h) => typeof h.tag == 'string';
|
|
16
|
-
let isfragment = (h) => {
|
|
17
|
-
return h.tag == undefined && h.cn != undefined;
|
|
18
|
-
};
|
|
19
|
-
let isobject = (o) => typeof o === 'object';
|
|
20
|
-
let isproperty = (name, value) => ['value', 'checked', 'disabled', 'className', 'style', 'href', 'src', 'selected', 'readOnly', 'tabIndex'].includes(name) ||
|
|
21
|
-
value instanceof Object ||
|
|
22
|
-
value instanceof Function;
|
|
23
|
-
let setprops = (e, newprops = {}) => {
|
|
24
|
-
let oldprops = evaluate(e.h?.p) ?? {};
|
|
25
|
-
for (let p in oldprops)
|
|
26
|
-
!(p in newprops) && isproperty(p, oldprops[p]) ? (e[p] = null) : e.removeAttribute(p);
|
|
27
|
-
for (let p in newprops)
|
|
28
|
-
isproperty(p, newprops[p]) ? (e[p] = newprops[p]) : e.setAttribute(p, newprops[p]);
|
|
29
|
-
};
|
|
30
|
-
function sync(p, i, h) {
|
|
31
|
-
|
|
32
|
-
h
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
n
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
n
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
let
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
ci.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
let
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
1
|
+
import { rebind } from './base';
|
|
2
|
+
export function createElement(tag) {
|
|
3
|
+
let ns = window.jmx?.getnamespace?.(tag);
|
|
4
|
+
return ns ? document.createElementNS(ns, tag) : document.createElement(tag);
|
|
5
|
+
}
|
|
6
|
+
let evaluate = (expr) => (expr instanceof Function ? expr() : expr);
|
|
7
|
+
let removeexcesschildren = (n, i) => {
|
|
8
|
+
let c;
|
|
9
|
+
while ((c = n.childNodes[i])) {
|
|
10
|
+
c.remove();
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
let iswebcomponent = (h) => h.tag.includes('-');
|
|
14
|
+
let isclasscomponent = (h) => h.tag?.prototype?.view;
|
|
15
|
+
let iselement = (h) => typeof h.tag == 'string';
|
|
16
|
+
let isfragment = (h) => {
|
|
17
|
+
return h.tag == undefined && h.cn != undefined;
|
|
18
|
+
};
|
|
19
|
+
let isobject = (o) => typeof o === 'object';
|
|
20
|
+
let isproperty = (name, value) => ['value', 'checked', 'disabled', 'className', 'style', 'href', 'src', 'selected', 'readOnly', 'tabIndex'].includes(name) ||
|
|
21
|
+
value instanceof Object ||
|
|
22
|
+
value instanceof Function;
|
|
23
|
+
let setprops = (e, newprops = {}) => {
|
|
24
|
+
let oldprops = evaluate(e.h?.p) ?? {};
|
|
25
|
+
for (let p in oldprops)
|
|
26
|
+
!(p in newprops) && isproperty(p, oldprops[p]) ? (e[p] = null) : e.removeAttribute(p);
|
|
27
|
+
for (let p in newprops)
|
|
28
|
+
isproperty(p, newprops[p]) ? (e[p] = newprops[p]) : e.setAttribute(p, newprops[p]);
|
|
29
|
+
};
|
|
30
|
+
function sync(p, i, h) {
|
|
31
|
+
h = evaluate(h);
|
|
32
|
+
if (h === null || h === undefined)
|
|
33
|
+
return i;
|
|
34
|
+
let c = p.childNodes[i];
|
|
35
|
+
function synctextnode(text) {
|
|
36
|
+
if (c && c.nodeType == 3) {
|
|
37
|
+
if (c.textContent != text)
|
|
38
|
+
c.textContent = text;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
let tn = document.createTextNode(text);
|
|
42
|
+
c ? c.replaceWith(tn) : p.appendChild(tn);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (isobject(h)) {
|
|
46
|
+
function syncchildren(p, h, i) {
|
|
47
|
+
evaluate(h.cn)
|
|
48
|
+
?.flat()
|
|
49
|
+
.forEach(hc => (i = sync(p, i, hc)));
|
|
50
|
+
return i;
|
|
51
|
+
}
|
|
52
|
+
if (isfragment(h))
|
|
53
|
+
return syncchildren(p, h, i);
|
|
54
|
+
const props = evaluate(h.p);
|
|
55
|
+
if (iselement(h)) {
|
|
56
|
+
let n;
|
|
57
|
+
if (c?.tagName?.toLowerCase() != h.tag.toLowerCase()) {
|
|
58
|
+
n = createElement(h.tag);
|
|
59
|
+
c ? c.replaceWith(n) : p.appendChild(n);
|
|
60
|
+
setprops(n, props);
|
|
61
|
+
props?.mounted?.(n);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
n = c;
|
|
65
|
+
setprops(n, props);
|
|
66
|
+
if (props?.update?.(c, globaluc))
|
|
67
|
+
return i + 1;
|
|
68
|
+
}
|
|
69
|
+
n.h = h;
|
|
70
|
+
if (!globaluc.patchElementOnly && !iswebcomponent(h)) {
|
|
71
|
+
const j = syncchildren(n, h, 0);
|
|
72
|
+
removeexcesschildren(n, j);
|
|
73
|
+
}
|
|
74
|
+
return i + 1;
|
|
75
|
+
}
|
|
76
|
+
switch (typeof h.tag) {
|
|
77
|
+
case 'function':
|
|
78
|
+
let isupdate = c?.h?.tag == h.tag;
|
|
79
|
+
let ci;
|
|
80
|
+
if (isclasscomponent(h)) {
|
|
81
|
+
h.i = ci = c?.h?.i ?? rebind(new h.tag(props));
|
|
82
|
+
ci.props = props;
|
|
83
|
+
if (isupdate && ci.update(globaluc))
|
|
84
|
+
return i + 1;
|
|
85
|
+
}
|
|
86
|
+
let hr = ci?.view ? ci?.view() : h.tag(props, evaluate(h.cn));
|
|
87
|
+
if (hr === undefined || hr == null)
|
|
88
|
+
return i;
|
|
89
|
+
let j = sync(p, i, hr);
|
|
90
|
+
let cn = p.childNodes[i];
|
|
91
|
+
cn.h = h;
|
|
92
|
+
if (ci)
|
|
93
|
+
ci.element = cn;
|
|
94
|
+
if (!isupdate)
|
|
95
|
+
ci?.mounted?.();
|
|
96
|
+
return j;
|
|
97
|
+
case 'object':
|
|
98
|
+
return sync(p, i, h.tag);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
synctextnode(h);
|
|
102
|
+
return i + 1;
|
|
103
|
+
}
|
|
104
|
+
let globaluc = {};
|
|
105
|
+
export function patch(e, h) {
|
|
106
|
+
if (!e)
|
|
107
|
+
return;
|
|
108
|
+
if (globaluc.replace)
|
|
109
|
+
e.replaceChildren();
|
|
110
|
+
const p = e.parentElement;
|
|
111
|
+
const i = [].indexOf.call(p.childNodes, e);
|
|
112
|
+
sync(p, i, h);
|
|
113
|
+
}
|
|
114
|
+
export function updateviewuc(uc, ...sels) {
|
|
115
|
+
{
|
|
116
|
+
globaluc = uc;
|
|
117
|
+
updateviewinternal(...sels);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export function updateview(...sels) {
|
|
121
|
+
{
|
|
122
|
+
globaluc = {};
|
|
123
|
+
updateviewinternal(...sels);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function updateviewinternal(...sels) {
|
|
127
|
+
if (!sels.length)
|
|
128
|
+
sels.push('body');
|
|
129
|
+
sels.flatMap(s => (typeof s == 'string' ? [...document.querySelectorAll(s)] : s ? [s] : [])).forEach(e => {
|
|
130
|
+
if (!e?.h)
|
|
131
|
+
throw 'jmx: no h exists on the node';
|
|
132
|
+
patch(e, e.h);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
136
135
|
//# sourceMappingURL=jmx.js.map
|
package/dist/jmx.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jmx.js","sourceRoot":"./","sources":["jmx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAI/B,MAAM,UAAU,aAAa,CAAC,GAAW;IACrC,IAAI,EAAE,GAAG,MAAM,CAAC,GAAG,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,CAAA;IACxC,OAAO,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;AAC/E,CAAC;AAMD,IAAI,QAAQ,GAAG,CAAI,IAAa,EAAK,EAAE,CAAC,CAAC,IAAI,YAAY,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;AAClF,IAAI,oBAAoB,GAAG,CAAC,CAAU,EAAE,CAAS,EAAE,EAAE;IACjD,IAAI,CAAY,CAAA;IAChB,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3B,CAAC,CAAC,MAAM,EAAE,CAAA;IACd,CAAC;AACL,CAAC,CAAA;AACD,IAAI,cAAc,GAAG,CAAC,CAAW,EAAE,EAAE,CAAE,CAAC,CAAC,GAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AACrE,IAAI,gBAAgB,GAAG,CAAC,CAAQ,EAAmB,EAAE,CAAE,CAAC,CAAC,G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AC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;QACrG,IAAI,CAAC,CAAC,EAAE,CAAC;YAAE,MAAM,8BAA8B,CAAA;QAC/C,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC,CAAC,CAAA;AACN,CAAC","sourcesContent":["import { rebind } from './base'\r\nimport { Expr, FComponent, H, HComp, HCompClass, HElement, HFragment, IClassComponent, Props } from './h'\r\n\r\n// config\r\nexport function createElement(tag: string) {\r\n let ns = window.jmx?.getnamespace?.(tag)\r\n return ns ? document.createElementNS(ns, tag) : document.createElement(tag)\r\n}\r\n\r\nconst enum NodeType { // vaporizes (but for that must be in this file, otherwise not)\r\n TextNode = 3,\r\n}\r\n\r\nlet evaluate = <T>(expr: Expr<T>): T => (expr instanceof Function ? expr() : expr)\r\nlet removeexcesschildren = (n: Element, i: number) => {\r\n let c: ChildNode\r\n while ((c = n.childNodes[i])) {\r\n c.remove()\r\n }\r\n}\r\nlet iswebcomponent = (h: HElement) => (h.tag as string).includes('-')\r\nlet isclasscomponent = (h: HComp): h is HCompClass => (h.tag as any)?.prototype?.view\r\nlet iselement = (h: any): h is HElement => typeof h.tag == 'string'\r\nlet isfragment = (h: any): h is HFragment => {\r\n return h.tag == undefined && h.cn != undefined\r\n}\r\nlet isobject = (o: any): o is object => typeof o === 'object'\r\n\r\nlet isproperty = (name: string, value: any) =>\r\n ['value', 'checked', 'disabled', 'className', 'style', 'href', 'src', 'selected', 'readOnly', 'tabIndex'].includes(\r\n name\r\n ) ||\r\n value instanceof Object ||\r\n value instanceof Function\r\n\r\nlet setprops = (e: Element, newprops: Props = {}) => {\r\n let oldprops = evaluate(e.h?.p) ?? {}\r\n for (let p in oldprops)\r\n !(p in newprops) && isproperty(p, oldprops[p]) ? ((e as any)[p] = null) : e.removeAttribute(p)\r\n for (let p in newprops) isproperty(p, newprops[p]) ? ((e as any)[p] = newprops[p]) : e.setAttribute(p, newprops[p])\r\n}\r\n\r\n/** syncs at position i of p. returns the number of the element past the last added element.\r\n * if no element was added (eg when h=null) then it returns i\r\n * if a fragment with 5 nodes was added, it returns i + 5\r\n * when a single element or component is added, it is i+1 since they always create exactly 1 node\r\n */\r\nfunction sync(p: Element, i: number, h: Expr<H | undefined>): number {\r\n console.log('%csync', \"background:orange\", p.tagName, i, h)\r\n\r\n h = evaluate(h)\r\n if (h === null || h === undefined) return i // skip this element. not that !!h would forbid to render the number 0 or the boolean value false\r\n\r\n let c = p.childNodes[i] // is often null, eg during fresh creation\r\n\r\n function synctextnode(text: string) {\r\n if (c && c.nodeType == NodeType.TextNode) {\r\n if (c.textContent != text) c.textContent = text // firefox updates even equal text, loosing an existing text selection\r\n } else {\r\n let tn = document.createTextNode(text)\r\n c ? c.replaceWith(tn) : p.appendChild(tn)\r\n }\r\n }\r\n\r\n if (isobject(h)) {\r\n // element nodes\r\n\r\n /** synchronizes children starting at the i-th element. returns the index of the last child synchronized */\r\n function syncchildren(p: Element, h: HElement | HComp | HFragment, i: number): number {\r\n evaluate(h.cn)\r\n ?.flat()\r\n .forEach(hc => (i = sync(p, i, hc)))\r\n return i\r\n }\r\n\r\n if (isfragment(h)) return syncchildren(p, h, i)\r\n\r\n const props = evaluate(h.p)\r\n\r\n if (iselement(h)) {\r\n let n: Element\r\n\r\n if ((<Element>c)?.tagName?.toLowerCase() != h.tag.toLowerCase()) {\r\n n = createElement(h.tag)\r\n c ? c.replaceWith(n) : p.appendChild(n)\r\n setprops(n, props)\r\n props?.mounted?.(n)\r\n } else {\r\n n = c as Element\r\n setprops(n, props)\r\n if (props?.update?.(c, globaluc)) return i + 1\r\n }\r\n\r\n // if only components shall be updateable (advantage: close variables inside component functions are always fresh materialized, avoids surprises), comment this out\r\n n.h = h\r\n\r\n if (!globaluc.patchElementOnly && !iswebcomponent(h as HElement)) {\r\n // tbd: make \"island\" attribute\r\n const j = syncchildren(n, h, 0)\r\n removeexcesschildren(n, j)\r\n }\r\n return i + 1\r\n }\r\n\r\n switch (typeof h.tag) {\r\n case 'function':\r\n let isupdate = c?.h?.tag == h.tag\r\n\r\n let ci: IClassComponent | undefined\r\n\r\n if (isclasscomponent(h)) {\r\n h.i = ci = (c?.h as HCompClass)?.i ?? rebind(new h.tag(props))\r\n ci.props = props\r\n\r\n // if component instance returns truthy for update(), then syncing is susbstituted by the component\r\n if (isupdate && ci.update(globaluc)) return i + 1\r\n }\r\n\r\n // materialize the component\r\n // we run compoents view() and fun code often, we do not compare properties to avoid their computation\r\n // this means that the inner hr (h resolved) is run often\r\n //\r\n // if ci has a view, return ci.view() even if it is falsy, this is perfectly valid\r\n let hr = ci?.view ? ci?.view() : (h.tag as FComponent)(props, evaluate(h.cn))\r\n\r\n // a component can return undefined or null if it has no elements to show\r\n if (hr === undefined || hr == null) return i\r\n\r\n let j = sync(p, i, hr)\r\n\r\n let cn = p.childNodes[i]!\r\n cn.h = h // attach h onto the materialized component node\r\n // ;(cn as HTMLElement).setAttribute?.('comp', '')\r\n\r\n if (ci) ci.element = cn\r\n if (!isupdate) ci?.mounted?.()\r\n\r\n return j\r\n\r\n case 'object':\r\n return sync(p, i, h.tag) // tbd: type of h is not correct, h.tag == never\r\n }\r\n }\r\n // text nodes\r\n synctextnode(h as string)\r\n return i + 1\r\n}\r\n\r\nlet globaluc: IUpdateContext = {}\r\n\r\nexport function patch(e: Node | null, h: Expr<H>) {\r\n if (!e) return\r\n if (globaluc.replace) (e as HTMLElement).replaceChildren()\r\n const p = e.parentElement as HTMLElement\r\n const i = [].indexOf.call<any, any, any>(p.childNodes, e)\r\n // always called deferred, because removing elements can trigger events and their handlers (like blur)\r\n sync(p, i, h)\r\n}\r\n\r\n// Overload signatures\r\ntype Selector = string | Node | undefined | null\r\ntype Selectors = Selector[]\r\n\r\nexport function updateviewuc(uc: IUpdateContext, ...sels: Selectors): void {\r\n {\r\n globaluc = uc\r\n updateviewinternal(...sels)\r\n }\r\n}\r\nexport function updateview(...sels: Selectors): void {\r\n {\r\n globaluc = {}\r\n updateviewinternal(...sels)\r\n }\r\n}\r\n\r\nfunction updateviewinternal(...sels: Selector[]): void {\r\n if (!sels.length) sels.push('body')\r\n sels.flatMap(s => (typeof s == 'string' ? [...document.querySelectorAll(s)] : s ? [s] : [])).forEach(e => {\r\n if (!e?.h) throw 'jmx: no h exists on the node'\r\n patch(e, e.h)\r\n })\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"jmx.js","sourceRoot":"./","sources":["jmx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAI/B,MAAM,UAAU,aAAa,CAAC,GAAW;IACrC,IAAI,EAAE,GAAG,MAAM,CAAC,GAAG,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,CAAA;IACxC,OAAO,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;AAC/E,CAAC;AAMD,IAAI,QAAQ,GAAG,CAAI,IAAa,EAAK,EAAE,CAAC,CAAC,IAAI,YAAY,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;AAClF,IAAI,oBAAoB,GAAG,CAAC,CAAU,EAAE,CAAS,EAAE,EAAE;IACjD,IAAI,CAAY,CAAA;IAChB,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3B,CAAC,CAAC,MAAM,EAAE,CAAA;IACd,CAAC;AACL,CAAC,CAAA;AACD,IAAI,cAAc,GAAG,CAAC,CAAW,EAAE,EAAE,CAAE,CAAC,CAAC,GAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AACrE,IAAI,gBAAgB,GAAG,CAAC,CAAQ,EAAmB,EAAE,CAAE,CAAC,CAAC,GAAW,EAAE,SAAS,EAAE,IAAI,CAAA;AACrF,I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AC,CAAA;IACjB,CAAC,CAAC,CAAA;AACN,CAAC","sourcesContent":["import { rebind } from './base'\r\nimport { Expr, FComponent, H, HComp, HCompClass, HElement, HFragment, IClassComponent, Props } from './h'\r\n\r\n// config\r\nexport function createElement(tag: string) {\r\n let ns = window.jmx?.getnamespace?.(tag)\r\n return ns ? document.createElementNS(ns, tag) : document.createElement(tag)\r\n}\r\n\r\nconst enum NodeType { // vaporizes (but for that must be in this file, otherwise not)\r\n TextNode = 3,\r\n}\r\n\r\nlet evaluate = <T>(expr: Expr<T>): T => (expr instanceof Function ? expr() : expr)\r\nlet removeexcesschildren = (n: Element, i: number) => {\r\n let c: ChildNode\r\n while ((c = n.childNodes[i])) {\r\n c.remove()\r\n }\r\n}\r\nlet iswebcomponent = (h: HElement) => (h.tag as string).includes('-')\r\nlet isclasscomponent = (h: HComp): h is HCompClass => (h.tag as any)?.prototype?.view\r\nlet iselement = (h: any): h is HElement => typeof h.tag == 'string'\r\nlet isfragment = (h: any): h is HFragment => {\r\n return h.tag == undefined && h.cn != undefined\r\n}\r\nlet isobject = (o: any): o is object => typeof o === 'object'\r\n\r\nlet isproperty = (name: string, value: any) =>\r\n ['value', 'checked', 'disabled', 'className', 'style', 'href', 'src', 'selected', 'readOnly', 'tabIndex'].includes(\r\n name\r\n ) ||\r\n value instanceof Object ||\r\n value instanceof Function\r\n\r\nlet setprops = (e: Element, newprops: Props = {}) => {\r\n let oldprops = evaluate(e.h?.p) ?? {}\r\n for (let p in oldprops)\r\n !(p in newprops) && isproperty(p, oldprops[p]) ? ((e as any)[p] = null) : e.removeAttribute(p)\r\n for (let p in newprops) isproperty(p, newprops[p]) ? ((e as any)[p] = newprops[p]) : e.setAttribute(p, newprops[p])\r\n}\r\n\r\n/** syncs at position i of p. returns the number of the element past the last added element.\r\n * if no element was added (eg when h=null) then it returns i\r\n * if a fragment with 5 nodes was added, it returns i + 5\r\n * when a single element or component is added, it is i+1 since they always create exactly 1 node\r\n */\r\nfunction sync(p: Element, i: number, h: Expr<H | undefined>): number {\r\n // console.log('%csync', \"background:orange\", p.tagName, i, h)\r\n\r\n h = evaluate(h)\r\n if (h === null || h === undefined) return i // skip this element. not that !!h would forbid to render the number 0 or the boolean value false\r\n\r\n let c = p.childNodes[i] // is often null, eg during fresh creation\r\n\r\n function synctextnode(text: string) {\r\n if (c && c.nodeType == NodeType.TextNode) {\r\n if (c.textContent != text) c.textContent = text // firefox updates even equal text, loosing an existing text selection\r\n } else {\r\n let tn = document.createTextNode(text)\r\n c ? c.replaceWith(tn) : p.appendChild(tn)\r\n }\r\n }\r\n\r\n if (isobject(h)) {\r\n // element nodes\r\n\r\n /** synchronizes children starting at the i-th element. returns the index of the last child synchronized */\r\n function syncchildren(p: Element, h: HElement | HComp | HFragment, i: number): number {\r\n evaluate(h.cn)\r\n ?.flat()\r\n .forEach(hc => (i = sync(p, i, hc)))\r\n return i\r\n }\r\n\r\n if (isfragment(h)) return syncchildren(p, h, i)\r\n\r\n const props = evaluate(h.p)\r\n\r\n if (iselement(h)) {\r\n let n: Element\r\n\r\n if ((<Element>c)?.tagName?.toLowerCase() != h.tag.toLowerCase()) {\r\n n = createElement(h.tag)\r\n c ? c.replaceWith(n) : p.appendChild(n)\r\n setprops(n, props)\r\n props?.mounted?.(n)\r\n } else {\r\n n = c as Element\r\n setprops(n, props)\r\n if (props?.update?.(c, globaluc)) return i + 1\r\n }\r\n\r\n // if only components shall be updateable (advantage: close variables inside component functions are always fresh materialized, avoids surprises), comment this out\r\n n.h = h\r\n\r\n if (!globaluc.patchElementOnly && !iswebcomponent(h as HElement)) {\r\n // tbd: make \"island\" attribute\r\n const j = syncchildren(n, h, 0)\r\n removeexcesschildren(n, j)\r\n }\r\n return i + 1\r\n }\r\n\r\n switch (typeof h.tag) {\r\n case 'function':\r\n let isupdate = c?.h?.tag == h.tag\r\n\r\n let ci: IClassComponent | undefined\r\n\r\n if (isclasscomponent(h)) {\r\n h.i = ci = (c?.h as HCompClass)?.i ?? rebind(new h.tag(props))\r\n ci.props = props\r\n\r\n // if component instance returns truthy for update(), then syncing is susbstituted by the component\r\n if (isupdate && ci.update(globaluc)) return i + 1\r\n }\r\n\r\n // materialize the component\r\n // we run compoents view() and fun code often, we do not compare properties to avoid their computation\r\n // this means that the inner hr (h resolved) is run often\r\n //\r\n // if ci has a view, return ci.view() even if it is falsy, this is perfectly valid\r\n let hr = ci?.view ? ci?.view() : (h.tag as FComponent)(props, evaluate(h.cn))\r\n\r\n // a component can return undefined or null if it has no elements to show\r\n if (hr === undefined || hr == null) return i\r\n\r\n let j = sync(p, i, hr)\r\n\r\n let cn = p.childNodes[i]!\r\n cn.h = h // attach h onto the materialized component node\r\n // ;(cn as HTMLElement).setAttribute?.('comp', '')\r\n\r\n if (ci) ci.element = cn\r\n if (!isupdate) ci?.mounted?.()\r\n\r\n return j\r\n\r\n case 'object':\r\n return sync(p, i, h.tag) // tbd: type of h is not correct, h.tag == never\r\n }\r\n }\r\n // text nodes\r\n synctextnode(h as string)\r\n return i + 1\r\n}\r\n\r\nlet globaluc: IUpdateContext = {}\r\n\r\nexport function patch(e: Node | null, h: Expr<H>) {\r\n if (!e) return\r\n if (globaluc.replace) (e as HTMLElement).replaceChildren()\r\n const p = e.parentElement as HTMLElement\r\n const i = [].indexOf.call<any, any, any>(p.childNodes, e)\r\n // always called deferred, because removing elements can trigger events and their handlers (like blur)\r\n sync(p, i, h)\r\n}\r\n\r\n// Overload signatures\r\ntype Selector = string | Node | undefined | null\r\ntype Selectors = Selector[]\r\n\r\nexport function updateviewuc(uc: IUpdateContext, ...sels: Selectors): void {\r\n {\r\n globaluc = uc\r\n updateviewinternal(...sels)\r\n }\r\n}\r\nexport function updateview(...sels: Selectors): void {\r\n {\r\n globaluc = {}\r\n updateviewinternal(...sels)\r\n }\r\n}\r\n\r\nfunction updateviewinternal(...sels: Selector[]): void {\r\n if (!sels.length) sels.push('body')\r\n sels.flatMap(s => (typeof s == 'string' ? [...document.querySelectorAll(s)] : s ? [s] : [])).forEach(e => {\r\n if (!e?.h) throw 'jmx: no h exists on the node'\r\n patch(e, e.h)\r\n })\r\n}\r\n"]}
|