@praxisjs/decorators 0.4.3 → 0.5.0
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/CHANGELOG.md +25 -0
- package/dist/__tests__/component.test.js +10 -1
- package/dist/__tests__/component.test.js.map +1 -1
- package/dist/__tests__/compose.test.d.ts +2 -0
- package/dist/__tests__/compose.test.d.ts.map +1 -0
- package/dist/__tests__/compose.test.js +171 -0
- package/dist/__tests__/compose.test.js.map +1 -0
- package/dist/__tests__/events.test.js +26 -0
- package/dist/__tests__/events.test.js.map +1 -1
- package/dist/__tests__/functions.test.js +142 -47
- package/dist/__tests__/functions.test.js.map +1 -1
- package/dist/__tests__/lazy.test.js +5 -7
- package/dist/__tests__/lazy.test.js.map +1 -1
- package/dist/__tests__/memo.test.js +61 -25
- package/dist/__tests__/memo.test.js.map +1 -1
- package/dist/__tests__/resource.test.d.ts +2 -0
- package/dist/__tests__/resource.test.d.ts.map +1 -0
- package/dist/__tests__/resource.test.js +103 -0
- package/dist/__tests__/resource.test.js.map +1 -0
- package/dist/__tests__/slot.test.js +32 -0
- package/dist/__tests__/slot.test.js.map +1 -1
- package/dist/__tests__/virtual.test.js +56 -15
- package/dist/__tests__/virtual.test.js.map +1 -1
- package/dist/component/component.d.ts +1 -1
- package/dist/component/component.d.ts.map +1 -1
- package/dist/component/component.js +15 -10
- package/dist/component/component.js.map +1 -1
- package/dist/component/lazy.d.ts.map +1 -1
- package/dist/component/lazy.js +29 -30
- package/dist/component/lazy.js.map +1 -1
- package/dist/component/virtual.d.ts.map +1 -1
- package/dist/component/virtual.js +46 -50
- package/dist/component/virtual.js.map +1 -1
- package/dist/create-class-decorator.d.ts +16 -0
- package/dist/create-class-decorator.d.ts.map +1 -0
- package/dist/create-class-decorator.js +35 -0
- package/dist/create-class-decorator.js.map +1 -0
- package/dist/create-field-decorator.d.ts +14 -0
- package/dist/create-field-decorator.d.ts.map +1 -0
- package/dist/create-field-decorator.js +37 -0
- package/dist/create-field-decorator.js.map +1 -0
- package/dist/create-getter-decorator.d.ts +18 -0
- package/dist/create-getter-decorator.d.ts.map +1 -0
- package/dist/create-getter-decorator.js +15 -0
- package/dist/create-getter-decorator.js.map +1 -0
- package/dist/create-lifecycle-method-decorator.d.ts +6 -0
- package/dist/create-lifecycle-method-decorator.d.ts.map +1 -0
- package/dist/create-lifecycle-method-decorator.js +22 -0
- package/dist/create-lifecycle-method-decorator.js.map +1 -0
- package/dist/create-method-decorator.d.ts +6 -0
- package/dist/create-method-decorator.d.ts.map +1 -0
- package/dist/create-method-decorator.js +14 -0
- package/dist/create-method-decorator.js.map +1 -0
- package/dist/events/emit.d.ts +1 -1
- package/dist/events/emit.d.ts.map +1 -1
- package/dist/events/emit.js +24 -29
- package/dist/events/emit.js.map +1 -1
- package/dist/events/on-command.d.ts +1 -2
- package/dist/events/on-command.d.ts.map +1 -1
- package/dist/events/on-command.js +15 -32
- package/dist/events/on-command.js.map +1 -1
- package/dist/functions/bind.d.ts +1 -2
- package/dist/functions/bind.d.ts.map +1 -1
- package/dist/functions/bind.js +4 -11
- package/dist/functions/bind.js.map +1 -1
- package/dist/functions/debounce.d.ts +1 -2
- package/dist/functions/debounce.d.ts.map +1 -1
- package/dist/functions/debounce.js +12 -20
- package/dist/functions/debounce.js.map +1 -1
- package/dist/functions/log.d.ts +1 -2
- package/dist/functions/log.d.ts.map +1 -1
- package/dist/functions/log.js +40 -38
- package/dist/functions/log.js.map +1 -1
- package/dist/functions/memo.d.ts +1 -2
- package/dist/functions/memo.d.ts.map +1 -1
- package/dist/functions/memo.js +15 -27
- package/dist/functions/memo.js.map +1 -1
- package/dist/functions/once.d.ts +1 -2
- package/dist/functions/once.d.ts.map +1 -1
- package/dist/functions/once.js +14 -12
- package/dist/functions/once.js.map +1 -1
- package/dist/functions/retry.d.ts +1 -2
- package/dist/functions/retry.d.ts.map +1 -1
- package/dist/functions/retry.js +23 -20
- package/dist/functions/retry.js.map +1 -1
- package/dist/functions/throttle.d.ts +1 -2
- package/dist/functions/throttle.d.ts.map +1 -1
- package/dist/functions/throttle.js +9 -16
- package/dist/functions/throttle.js.map +1 -1
- package/dist/functions/watch.d.ts +1 -1
- package/dist/functions/watch.d.ts.map +1 -1
- package/dist/functions/watch.js +25 -39
- package/dist/functions/watch.js.map +1 -1
- package/dist/functions/when.d.ts +1 -2
- package/dist/functions/when.d.ts.map +1 -1
- package/dist/functions/when.js +10 -26
- package/dist/functions/when.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/properties/compose.d.ts +3 -0
- package/dist/properties/compose.d.ts.map +1 -0
- package/dist/properties/compose.js +40 -0
- package/dist/properties/compose.js.map +1 -0
- package/dist/properties/computed.d.ts +1 -2
- package/dist/properties/computed.d.ts.map +1 -1
- package/dist/properties/computed.js +10 -9
- package/dist/properties/computed.js.map +1 -1
- package/dist/properties/history.d.ts.map +1 -1
- package/dist/properties/history.js +37 -32
- package/dist/properties/history.js.map +1 -1
- package/dist/properties/index.d.ts +2 -0
- package/dist/properties/index.d.ts.map +1 -1
- package/dist/properties/index.js +2 -0
- package/dist/properties/index.js.map +1 -1
- package/dist/properties/persisted.d.ts +1 -2
- package/dist/properties/persisted.d.ts.map +1 -1
- package/dist/properties/persisted.js +13 -29
- package/dist/properties/persisted.js.map +1 -1
- package/dist/properties/prop.d.ts +1 -2
- package/dist/properties/prop.d.ts.map +1 -1
- package/dist/properties/prop.js +21 -25
- package/dist/properties/prop.js.map +1 -1
- package/dist/properties/resource.d.ts +14 -0
- package/dist/properties/resource.d.ts.map +1 -0
- package/dist/properties/resource.js +27 -0
- package/dist/properties/resource.js.map +1 -0
- package/dist/properties/slot.d.ts +1 -2
- package/dist/properties/slot.d.ts.map +1 -1
- package/dist/properties/slot.js +15 -20
- package/dist/properties/slot.js.map +1 -1
- package/dist/properties/state.d.ts +1 -2
- package/dist/properties/state.d.ts.map +1 -1
- package/dist/properties/state.js +13 -18
- package/dist/properties/state.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/component.test.ts +10 -0
- package/src/__tests__/compose.test.ts +202 -0
- package/src/__tests__/events.test.ts +32 -0
- package/src/__tests__/functions.test.ts +177 -46
- package/src/__tests__/lazy.test.ts +3 -5
- package/src/__tests__/memo.test.ts +76 -25
- package/src/__tests__/resource.test.ts +113 -0
- package/src/__tests__/slot.test.ts +38 -0
- package/src/__tests__/virtual.test.ts +26 -7
- package/src/component/component.ts +27 -12
- package/src/component/lazy.ts +33 -37
- package/src/component/virtual.tsx +62 -75
- package/src/create-class-decorator.ts +61 -0
- package/src/create-field-decorator.ts +66 -0
- package/src/create-getter-decorator.ts +52 -0
- package/src/create-lifecycle-method-decorator.ts +38 -0
- package/src/create-method-decorator.ts +26 -0
- package/src/events/emit.ts +22 -33
- package/src/events/on-command.ts +22 -47
- package/src/functions/bind.ts +4 -15
- package/src/functions/debounce.ts +11 -26
- package/src/functions/log.ts +40 -43
- package/src/functions/memo.ts +15 -45
- package/src/functions/once.ts +13 -16
- package/src/functions/retry.ts +21 -22
- package/src/functions/throttle.ts +9 -23
- package/src/functions/watch.ts +27 -43
- package/src/functions/when.ts +11 -36
- package/src/index.ts +28 -0
- package/src/properties/compose.ts +53 -0
- package/src/properties/computed.ts +11 -13
- package/src/properties/history.ts +42 -41
- package/src/properties/index.ts +2 -0
- package/src/properties/persisted.ts +17 -58
- package/src/properties/prop.ts +21 -31
- package/src/properties/resource.ts +34 -0
- package/src/properties/slot.ts +17 -30
- package/src/properties/state.ts +14 -24
package/dist/component/lazy.js
CHANGED
|
@@ -1,47 +1,46 @@
|
|
|
1
1
|
import { signal } from "@praxisjs/core/internal";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
import { ClassBehavior, createClassDecorator } from "../create-class-decorator";
|
|
3
|
+
class LazyBehavior extends ClassBehavior {
|
|
4
|
+
constructor(placeholder) {
|
|
5
|
+
super();
|
|
6
|
+
this.placeholder = placeholder;
|
|
7
|
+
}
|
|
8
|
+
create(instance) {
|
|
9
|
+
const placeholder = this.placeholder;
|
|
10
|
+
const visible = signal(false);
|
|
11
|
+
let observer;
|
|
12
|
+
return {
|
|
12
13
|
onMount() {
|
|
13
|
-
|
|
14
|
-
// Use the end anchor to find the parent element
|
|
15
|
-
const el = this._anchor
|
|
16
|
-
?.parentElement ?? null;
|
|
14
|
+
const el = instance._anchor?.parentElement ?? null;
|
|
17
15
|
if (!el)
|
|
18
16
|
return;
|
|
19
17
|
if (!("IntersectionObserver" in window)) {
|
|
20
|
-
|
|
18
|
+
visible.set(true);
|
|
21
19
|
return;
|
|
22
20
|
}
|
|
23
|
-
if (!
|
|
21
|
+
if (!visible())
|
|
24
22
|
el.style.minHeight = `${String(placeholder)}px`;
|
|
25
|
-
|
|
26
|
-
this._observer = new IntersectionObserver((entries) => {
|
|
23
|
+
observer = new IntersectionObserver((entries) => {
|
|
27
24
|
if (entries[0]?.isIntersecting) {
|
|
28
|
-
|
|
25
|
+
visible.set(true);
|
|
29
26
|
el.style.minHeight = "";
|
|
30
|
-
|
|
27
|
+
observer?.disconnect();
|
|
31
28
|
}
|
|
32
29
|
}, { rootMargin: "100px" });
|
|
33
|
-
|
|
34
|
-
}
|
|
30
|
+
observer.observe(el);
|
|
31
|
+
},
|
|
35
32
|
onUnmount() {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (!this._lazyVisible())
|
|
33
|
+
observer?.disconnect();
|
|
34
|
+
},
|
|
35
|
+
render(originalRender) {
|
|
36
|
+
if (!visible())
|
|
41
37
|
return null;
|
|
42
|
-
return
|
|
43
|
-
}
|
|
38
|
+
return originalRender();
|
|
39
|
+
},
|
|
44
40
|
};
|
|
45
|
-
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export function Lazy(placeholder = 200) {
|
|
44
|
+
return createClassDecorator(new LazyBehavior(placeholder));
|
|
46
45
|
}
|
|
47
46
|
//# sourceMappingURL=lazy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy.js","sourceRoot":"","sources":["../../src/component/lazy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAErE,
|
|
1
|
+
{"version":3,"file":"lazy.js","sourceRoot":"","sources":["../../src/component/lazy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAErE,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAyB,MAAM,2BAA2B,CAAC;AAEvG,MAAM,YAAa,SAAQ,aAAa;IACtC,YAA6B,WAAmB;QAC9C,KAAK,EAAE,CAAC;QADmB,gBAAW,GAAX,WAAW,CAAQ;IAEhD,CAAC;IAED,MAAM,CAAC,QAAuB;QAC5B,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACrC,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC9B,IAAI,QAA0C,CAAC;QAE/C,OAAO;YACL,OAAO;gBACL,MAAM,EAAE,GACL,QAAkC,CAAC,OAAO,EAAE,aAAa,IAAI,IAAI,CAAC;gBACrE,IAAI,CAAC,EAAE;oBAAE,OAAO;gBAEhB,IAAI,CAAC,CAAC,sBAAsB,IAAI,MAAM,CAAC,EAAE,CAAC;oBACxC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;oBAClB,OAAO;gBACT,CAAC;gBAED,IAAI,CAAC,OAAO,EAAE;oBAAE,EAAE,CAAC,KAAK,CAAC,SAAS,GAAG,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC;gBAEhE,QAAQ,GAAG,IAAI,oBAAoB,CACjC,CAAC,OAAO,EAAE,EAAE;oBACV,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC;wBAC/B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;wBAClB,EAAE,CAAC,KAAK,CAAC,SAAS,GAAG,EAAE,CAAC;wBACxB,QAAQ,EAAE,UAAU,EAAE,CAAC;oBACzB,CAAC;gBACH,CAAC,EACD,EAAE,UAAU,EAAE,OAAO,EAAE,CACxB,CAAC;gBAEF,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACvB,CAAC;YAED,SAAS;gBACP,QAAQ,EAAE,UAAU,EAAE,CAAC;YACzB,CAAC;YAED,MAAM,CAAC,cAAc;gBACnB,IAAI,CAAC,OAAO,EAAE;oBAAE,OAAO,IAAI,CAAC;gBAC5B,OAAO,cAAc,EAAE,CAAC;YAC1B,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AAED,MAAM,UAAU,IAAI,CAAC,WAAW,GAAG,GAAG;IACpC,OAAO,oBAAoB,CAAC,IAAI,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual.d.ts","sourceRoot":"","sources":["../../src/component/virtual.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,aAAa,EAAU,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"virtual.d.ts","sourceRoot":"","sources":["../../src/component/virtual.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,aAAa,EAAU,MAAM,yBAAyB,CAAC;AAmIvF,wBAAgB,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,SAAI,mBA1GxC,GAAG,0GA4GhB"}
|
|
@@ -1,56 +1,51 @@
|
|
|
1
1
|
import { computed, effect, signal } from "@praxisjs/core/internal";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import { ClassBehavior, createClassDecorator } from "../create-class-decorator";
|
|
3
|
+
class VirtualBehavior extends ClassBehavior {
|
|
4
|
+
constructor(itemHeight, buffer) {
|
|
5
|
+
super();
|
|
6
|
+
this.itemHeight = itemHeight;
|
|
7
|
+
this.buffer = buffer;
|
|
8
|
+
}
|
|
9
|
+
create(instance) {
|
|
10
|
+
const { itemHeight, buffer } = this;
|
|
11
|
+
const host = instance;
|
|
12
|
+
const scrollTop = signal(0);
|
|
13
|
+
const viewHeight = signal(600);
|
|
14
|
+
let container;
|
|
15
|
+
let scrollHandler;
|
|
16
|
+
const cleanups = [];
|
|
17
|
+
return {
|
|
11
18
|
onMount() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this._container =
|
|
15
|
-
this._anchor?.parentElement ?? undefined;
|
|
16
|
-
if (!this._container)
|
|
19
|
+
container = host._anchor?.parentElement ?? undefined;
|
|
20
|
+
if (!container)
|
|
17
21
|
return;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (
|
|
23
|
-
|
|
22
|
+
container.style.overflowY = "auto";
|
|
23
|
+
container.style.position = "relative";
|
|
24
|
+
viewHeight.set(container.clientHeight || 600);
|
|
25
|
+
scrollHandler = () => {
|
|
26
|
+
if (container)
|
|
27
|
+
scrollTop.set(container.scrollTop);
|
|
24
28
|
};
|
|
25
|
-
|
|
26
|
-
}
|
|
29
|
+
container.addEventListener("scroll", scrollHandler);
|
|
30
|
+
},
|
|
27
31
|
onUnmount() {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
this._container.removeEventListener("scroll", this._scrollHandler);
|
|
32
|
+
if (container && scrollHandler) {
|
|
33
|
+
container.removeEventListener("scroll", scrollHandler);
|
|
31
34
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
render() {
|
|
36
|
-
const host = this;
|
|
35
|
+
cleanups.forEach((c) => { c(); });
|
|
36
|
+
cleanups.length = 0;
|
|
37
|
+
},
|
|
38
|
+
render(originalRender) {
|
|
37
39
|
const items = host.items ?? [];
|
|
38
40
|
const total = items.length;
|
|
39
41
|
const totalH = total * itemHeight;
|
|
40
42
|
if (typeof host.renderItem !== "function") {
|
|
41
|
-
console.warn(`[Virtual]
|
|
42
|
-
return
|
|
43
|
+
console.warn(`[Virtual] component must implement renderItem(item, index)`);
|
|
44
|
+
return originalRender();
|
|
43
45
|
}
|
|
44
46
|
const renderItem = host.renderItem.bind(host);
|
|
45
|
-
const startIdx = computed(() =>
|
|
46
|
-
|
|
47
|
-
return Math.max(0, start);
|
|
48
|
-
});
|
|
49
|
-
const endIdx = computed(() => {
|
|
50
|
-
const end = Math.ceil((this._scrollTop() + this._viewHeight()) / itemHeight) +
|
|
51
|
-
buffer;
|
|
52
|
-
return Math.min(total - 1, end);
|
|
53
|
-
});
|
|
47
|
+
const startIdx = computed(() => Math.max(0, Math.floor(scrollTop() / itemHeight) - buffer));
|
|
48
|
+
const endIdx = computed(() => Math.min(total - 1, Math.ceil((scrollTop() + viewHeight()) / itemHeight) + buffer));
|
|
54
49
|
const visibleItems = computed(() => {
|
|
55
50
|
const result = [];
|
|
56
51
|
for (let i = startIdx(); i <= endIdx(); i++) {
|
|
@@ -63,35 +58,36 @@ export function Virtual(itemHeight, buffer = 3) {
|
|
|
63
58
|
const outer = document.createElement("div");
|
|
64
59
|
outer.setAttribute("style", `height:${String(totalH)}px; position:relative;`);
|
|
65
60
|
const spacerTop = document.createElement("div");
|
|
66
|
-
|
|
61
|
+
cleanups.push(effect(() => {
|
|
67
62
|
spacerTop.setAttribute("style", `height:${String(offsetTop())}px;`);
|
|
68
63
|
}));
|
|
69
64
|
const itemsSlot = document.createElement("div");
|
|
70
|
-
|
|
71
|
-
while (itemsSlot.firstChild)
|
|
65
|
+
cleanups.push(effect(() => {
|
|
66
|
+
while (itemsSlot.firstChild)
|
|
72
67
|
itemsSlot.removeChild(itemsSlot.firstChild);
|
|
73
|
-
}
|
|
74
68
|
visibleItems().forEach(({ item, index }) => {
|
|
75
69
|
const wrapper = document.createElement("div");
|
|
76
70
|
wrapper.setAttribute("style", `height:${String(itemHeight)}px; overflow:hidden;`);
|
|
77
71
|
const rendered = renderItem(item, index);
|
|
78
72
|
if (rendered) {
|
|
79
|
-
|
|
80
|
-
nodes.forEach((n) => wrapper.appendChild(n));
|
|
73
|
+
(Array.isArray(rendered) ? rendered.flat() : [rendered]).forEach((n) => { wrapper.appendChild(n); });
|
|
81
74
|
}
|
|
82
75
|
itemsSlot.appendChild(wrapper);
|
|
83
76
|
});
|
|
84
77
|
}));
|
|
85
78
|
const spacerBottom = document.createElement("div");
|
|
86
|
-
|
|
79
|
+
cleanups.push(effect(() => {
|
|
87
80
|
spacerBottom.setAttribute("style", `height:${String(offsetBottom())}px;`);
|
|
88
81
|
}));
|
|
89
82
|
outer.appendChild(spacerTop);
|
|
90
83
|
outer.appendChild(itemsSlot);
|
|
91
84
|
outer.appendChild(spacerBottom);
|
|
92
85
|
return outer;
|
|
93
|
-
}
|
|
86
|
+
},
|
|
94
87
|
};
|
|
95
|
-
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export function Virtual(itemHeight, buffer = 3) {
|
|
91
|
+
return createClassDecorator(new VirtualBehavior(itemHeight, buffer));
|
|
96
92
|
}
|
|
97
93
|
//# sourceMappingURL=virtual.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual.js","sourceRoot":"","sources":["../../src/component/virtual.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAsB,MAAM,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"virtual.js","sourceRoot":"","sources":["../../src/component/virtual.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAsB,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEvF,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAyB,MAAM,2BAA2B,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EAAE,CAAC;4BACb,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAC9D,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACnC,CAAC;wBACJ,CAAC;wBACD,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;oBACjC,CAAC,CAAC,CAAC;gBACL,CAAC,CAAC,CACH,CAAC;gBAEF,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;gBACnD,QAAQ,CAAC,IAAI,CACX,MAAM,CAAC,GAAG,EAAE;oBACV,YAAY,CAAC,YAAY,CAAC,OAAO,EAAE,UAAU,MAAM,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,CAAC;gBAC5E,CAAC,CAAC,CACH,CAAC;gBAEF,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;gBAC7B,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;gBAC7B,KAAK,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;gBAEhC,OAAO,KAAK,CAAC;YACf,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AAED,MAAM,UAAU,OAAO,CAAC,UAAkB,EAAE,MAAM,GAAG,CAAC;IACpD,OAAO,oBAAoB,CAAC,IAAI,eAAe,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { RootComponent } from "@praxisjs/core/internal";
|
|
2
|
+
export interface ClassEnhancement {
|
|
3
|
+
onMount?(): void;
|
|
4
|
+
onUnmount?(): void;
|
|
5
|
+
render?(originalRender: () => Node | Node[] | null): Node | Node[] | null;
|
|
6
|
+
}
|
|
7
|
+
export declare abstract class ClassBehavior {
|
|
8
|
+
abstract create(instance: RootComponent): ClassEnhancement;
|
|
9
|
+
/**
|
|
10
|
+
* Called once after the enhanced class is created.
|
|
11
|
+
* Use this to set static properties on the class constructor itself.
|
|
12
|
+
*/
|
|
13
|
+
initialize?(_Enhanced: new (...args: any[]) => unknown, _original: new (...args: any[]) => unknown): void;
|
|
14
|
+
}
|
|
15
|
+
export declare function createClassDecorator(behavior: ClassBehavior): <T extends new (...args: any[]) => RootComponent<Record<string, any>>>(constructor: T, _context: ClassDecoratorContext) => T;
|
|
16
|
+
//# sourceMappingURL=create-class-decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-class-decorator.d.ts","sourceRoot":"","sources":["../src/create-class-decorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,IAAI,IAAI,CAAC;IACjB,SAAS,CAAC,IAAI,IAAI,CAAC;IACnB,MAAM,CAAC,CACL,cAAc,EAAE,MAAM,IAAI,GAAG,IAAI,EAAE,GAAG,IAAI,GACzC,IAAI,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;CACzB;AAED,8BAAsB,aAAa;IACjC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,aAAa,GAAG,gBAAgB;IAE1D;;;OAGG;IAEH,UAAU,CAAC,CAAC,SAAS,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,EAAE,SAAS,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,GAAG,IAAI;CAC1G;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,aAAa,IAGxD,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EACpE,aAAa,CAAC,EAAE,UAAU,qBAAqB,KAAG,CAAC,CAmCtD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export class ClassBehavior {
|
|
2
|
+
}
|
|
3
|
+
export function createClassDecorator(behavior) {
|
|
4
|
+
return function (constructor, _context) {
|
|
5
|
+
const Enhanced = class extends constructor {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this._enh = behavior.create(this);
|
|
9
|
+
}
|
|
10
|
+
onMount() {
|
|
11
|
+
super.onMount?.();
|
|
12
|
+
this._enh.onMount?.();
|
|
13
|
+
}
|
|
14
|
+
onUnmount() {
|
|
15
|
+
super.onUnmount?.();
|
|
16
|
+
this._enh.onUnmount?.();
|
|
17
|
+
}
|
|
18
|
+
render(...args) {
|
|
19
|
+
const originalRender = () => constructor.prototype.render.apply(this, args);
|
|
20
|
+
if (this._enh.render) {
|
|
21
|
+
return this._enh.render(originalRender);
|
|
22
|
+
}
|
|
23
|
+
return originalRender();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
// If the original class has no render, remove the wrapper so instances see `undefined`.
|
|
27
|
+
if (typeof constructor.prototype.render !== "function") {
|
|
28
|
+
delete Enhanced.prototype.render;
|
|
29
|
+
}
|
|
30
|
+
Object.defineProperty(Enhanced, "name", { value: constructor.name });
|
|
31
|
+
behavior.initialize?.(Enhanced, constructor);
|
|
32
|
+
return Enhanced;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=create-class-decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-class-decorator.js","sourceRoot":"","sources":["../src/create-class-decorator.ts"],"names":[],"mappings":"AAUA,MAAM,OAAgB,aAAa;CASlC;AAED,MAAM,UAAU,oBAAoB,CAAC,QAAuB;IAC1D,OAAO,UAGL,WAAc,EAAE,QAA+B;QAC/C,MAAM,QAAQ,GAAG,KAAM,SAAQ,WAAW;YAAzB;;gBACE,SAAI,GAAqB,QAAQ,CAAC,MAAM,CACvD,IAAgC,CACjC,CAAC;YAoBJ,CAAC;YAlBC,OAAO;gBACL,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;gBAClB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;YACxB,CAAC;YAED,SAAS;gBACP,KAAK,CAAC,SAAS,EAAE,EAAE,CAAC;gBACpB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;YAC1B,CAAC;YAED,MAAM,CAAC,GAAG,IAAe;gBACvB,MAAM,cAAc,GAAG,GAAG,EAAE,CACzB,WAAW,CAAC,SAAmE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBAC5G,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;oBACrB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;gBAC1C,CAAC;gBACD,OAAO,cAAc,EAAE,CAAC;YAC1B,CAAC;SACF,CAAC;QAEF,wFAAwF;QACxF,IAAI,OAAQ,WAAW,CAAC,SAAkC,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;YACjF,OAAQ,QAAQ,CAAC,SAAkC,CAAC,MAAM,CAAC;QAC7D,CAAC;QAED,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;QACrE,QAAQ,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QAC7C,OAAO,QAAwB,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { StatefulComponent } from "@praxisjs/core";
|
|
2
|
+
export interface FieldBinding {
|
|
3
|
+
/** Replaces the decorated property. If absent, the original property is left untouched. */
|
|
4
|
+
descriptor?: PropertyDescriptor;
|
|
5
|
+
/** Extra properties to define on the instance (e.g. companion properties like `nameHistory`). */
|
|
6
|
+
additional?: Record<string, PropertyDescriptor>;
|
|
7
|
+
onMount?: () => void;
|
|
8
|
+
onUnmount?: () => void;
|
|
9
|
+
}
|
|
10
|
+
export interface FieldBehavior {
|
|
11
|
+
bind(instance: StatefulComponent, name: string, initialValue: unknown): FieldBinding;
|
|
12
|
+
}
|
|
13
|
+
export declare function createFieldDecorator(behavior: FieldBehavior): (_value: undefined, context: ClassFieldDecoratorContext<StatefulComponent>) => void;
|
|
14
|
+
//# sourceMappingURL=create-field-decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-field-decorator.d.ts","sourceRoot":"","sources":["../src/create-field-decorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,MAAM,WAAW,YAAY;IAC3B,2FAA2F;IAC3F,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAChC,iGAAiG;IACjG,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAChD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,CACF,QAAQ,EAAE,iBAAiB,EAC3B,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,OAAO,GACpB,YAAY,CAAC;CACjB;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,aAAa,IAExD,QAAQ,SAAS,EACjB,SAAS,0BAA0B,CAAC,iBAAiB,CAAC,KACrD,IAAI,CA0CR"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export function createFieldDecorator(behavior) {
|
|
2
|
+
return function (_value, context) {
|
|
3
|
+
context.addInitializer(function () {
|
|
4
|
+
const instance = this;
|
|
5
|
+
const name = context.name;
|
|
6
|
+
const initialValue = instance[name];
|
|
7
|
+
const { descriptor, additional, onMount, onUnmount } = behavior.bind(instance, name, initialValue);
|
|
8
|
+
if (descriptor) {
|
|
9
|
+
Reflect.deleteProperty(instance, name);
|
|
10
|
+
Object.defineProperty(instance, name, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
...descriptor,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
for (const [key, desc] of Object.entries(additional ?? {})) {
|
|
17
|
+
Object.defineProperty(instance, key, {
|
|
18
|
+
configurable: true,
|
|
19
|
+
...desc,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (onMount ?? onUnmount) {
|
|
23
|
+
const prevMount = instance.onMount?.bind(instance);
|
|
24
|
+
const prevUnmount = instance.onUnmount?.bind(instance);
|
|
25
|
+
instance.onMount = () => {
|
|
26
|
+
prevMount?.();
|
|
27
|
+
onMount?.();
|
|
28
|
+
};
|
|
29
|
+
instance.onUnmount = () => {
|
|
30
|
+
prevUnmount?.();
|
|
31
|
+
onUnmount?.();
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=create-field-decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-field-decorator.js","sourceRoot":"","sources":["../src/create-field-decorator.ts"],"names":[],"mappings":"AAmBA,MAAM,UAAU,oBAAoB,CAAC,QAAuB;IAC1D,OAAO,UACL,MAAiB,EACjB,OAAsD;QAEtD,OAAO,CAAC,cAAc,CAAC;YACrB,MAAM,QAAQ,GAAG,IAAmD,CAAC;YACrE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAc,CAAC;YACpC,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;YAEpC,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAC,IAAI,CAClE,QAAQ,EACR,IAAI,EACJ,YAAY,CACb,CAAC;YAEF,IAAI,UAAU,EAAE,CAAC;gBACf,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;gBACvC,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE;oBACpC,UAAU,EAAE,IAAI;oBAChB,YAAY,EAAE,IAAI;oBAClB,GAAG,UAAU;iBACd,CAAC,CAAC;YACL,CAAC;YAED,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,CAAC;gBAC3D,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,GAAG,EAAE;oBACnC,YAAY,EAAE,IAAI;oBAClB,GAAG,IAAI;iBACR,CAAC,CAAC;YACL,CAAC;YAED,IAAI,OAAO,IAAI,SAAS,EAAE,CAAC;gBACzB,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACnD,MAAM,WAAW,GAAG,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACvD,QAAQ,CAAC,OAAO,GAAG,GAAG,EAAE;oBACtB,SAAS,EAAE,EAAE,CAAC;oBACd,OAAO,EAAE,EAAE,CAAC;gBACd,CAAC,CAAC;gBACF,QAAQ,CAAC,SAAS,GAAG,GAAG,EAAE;oBACxB,WAAW,EAAE,EAAE,CAAC;oBAChB,SAAS,EAAE,EAAE,CAAC;gBAChB,CAAC,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface GetterBehavior {
|
|
2
|
+
/**
|
|
3
|
+
* Given the original getter and the current instance, returns a function
|
|
4
|
+
* that produces the getter value. Called on every property access.
|
|
5
|
+
*/
|
|
6
|
+
wrap(original: (this: object) => unknown, instance: object): () => unknown;
|
|
7
|
+
}
|
|
8
|
+
export declare function createGetterDecorator(behavior: GetterBehavior): <This, T>(target: (this: This) => T, _context: ClassGetterDecoratorContext<This, T>) => (this: This) => T;
|
|
9
|
+
export interface GetterObserverBehavior {
|
|
10
|
+
/**
|
|
11
|
+
* Called once per instance when the class is initialized.
|
|
12
|
+
* Use this to set up observation side-effects on the getter without
|
|
13
|
+
* changing its return value (e.g. tracking changes for devtools).
|
|
14
|
+
*/
|
|
15
|
+
observe(getter: (this: object) => unknown, instance: object, name: string): void;
|
|
16
|
+
}
|
|
17
|
+
export declare function createGetterObserverDecorator(behavior: GetterObserverBehavior): <This, T>(target: (this: This) => T, context: ClassGetterDecoratorContext<This, T>) => void;
|
|
18
|
+
//# sourceMappingURL=create-getter-decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-getter-decorator.d.ts","sourceRoot":"","sources":["../src/create-getter-decorator.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,IAAI,CACF,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,EACnC,QAAQ,EAAE,MAAM,GACf,MAAM,OAAO,CAAC;CAClB;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,cAAc,IAC3C,IAAI,EAAE,CAAC,EACtB,QAAQ,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC,EACzB,UAAU,2BAA2B,CAAC,IAAI,EAAE,CAAC,CAAC,KAC7C,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC,CAQrB;AAED,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,OAAO,CACL,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,EACjC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,IAAI,CAAC;CACT;AAED,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,sBAAsB,IAC3D,IAAI,EAAE,CAAC,EACtB,QAAQ,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC,EACzB,SAAS,2BAA2B,CAAC,IAAI,EAAE,CAAC,CAAC,KAC5C,IAAI,CASR"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function createGetterDecorator(behavior) {
|
|
2
|
+
return function (target, _context) {
|
|
3
|
+
return function () {
|
|
4
|
+
return behavior.wrap(target, this)();
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export function createGetterObserverDecorator(behavior) {
|
|
9
|
+
return function (target, context) {
|
|
10
|
+
context.addInitializer(function () {
|
|
11
|
+
behavior.observe(target, this, context.name);
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=create-getter-decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-getter-decorator.js","sourceRoot":"","sources":["../src/create-getter-decorator.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,qBAAqB,CAAC,QAAwB;IAC5D,OAAO,UACL,MAAyB,EACzB,QAA8C;QAE9C,OAAO;YACL,OAAO,QAAQ,CAAC,IAAI,CAClB,MAAmC,EACnC,IAAc,CACf,EAAO,CAAC;QACX,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAeD,MAAM,UAAU,6BAA6B,CAAC,QAAgC;IAC5E,OAAO,UACL,MAAyB,EACzB,OAA6C;QAE7C,OAAO,CAAC,cAAc,CAAC;YACrB,QAAQ,CAAC,OAAO,CACd,MAAmC,EACnC,IAAc,EACd,OAAO,CAAC,IAAc,CACvB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { StatefulComponent } from "@praxisjs/core";
|
|
2
|
+
export interface LifecycleMethodBehavior<T extends StatefulComponent = StatefulComponent> {
|
|
3
|
+
register(callback: (...args: unknown[]) => void, instance: T): (() => void) | undefined;
|
|
4
|
+
}
|
|
5
|
+
export declare function createLifecycleMethodDecorator<T extends StatefulComponent = StatefulComponent>(behavior: LifecycleMethodBehavior<T>): (value: (this: T, ...args: unknown[]) => void, _context: ClassMethodDecoratorContext<T>) => void;
|
|
6
|
+
//# sourceMappingURL=create-lifecycle-method-decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-lifecycle-method-decorator.d.ts","sourceRoot":"","sources":["../src/create-lifecycle-method-decorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,MAAM,WAAW,uBAAuB,CACtC,CAAC,SAAS,iBAAiB,GAAG,iBAAiB;IAE/C,QAAQ,CACN,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,EACtC,QAAQ,EAAE,CAAC,GACV,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;CAC7B;AAED,wBAAgB,8BAA8B,CAC5C,CAAC,SAAS,iBAAiB,GAAG,iBAAiB,EAC/C,QAAQ,EAAE,uBAAuB,CAAC,CAAC,CAAC,IAElC,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,EAC5C,UAAU,2BAA2B,CAAC,CAAC,CAAC,KACvC,IAAI,CAoBR"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function createLifecycleMethodDecorator(behavior) {
|
|
2
|
+
return function (value, _context) {
|
|
3
|
+
_context.addInitializer(function () {
|
|
4
|
+
const instance = this;
|
|
5
|
+
const prevMount = instance.onMount?.bind(instance);
|
|
6
|
+
const prevUnmount = instance.onUnmount?.bind(instance);
|
|
7
|
+
let cleanup;
|
|
8
|
+
instance.onMount = function () {
|
|
9
|
+
prevMount?.call(this);
|
|
10
|
+
const result = behavior.register(value.bind(this), this);
|
|
11
|
+
if (result)
|
|
12
|
+
cleanup = result;
|
|
13
|
+
};
|
|
14
|
+
instance.onUnmount = function () {
|
|
15
|
+
prevUnmount?.call(this);
|
|
16
|
+
cleanup?.();
|
|
17
|
+
cleanup = undefined;
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=create-lifecycle-method-decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-lifecycle-method-decorator.js","sourceRoot":"","sources":["../src/create-lifecycle-method-decorator.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,8BAA8B,CAE5C,QAAoC;IACpC,OAAO,UACL,KAA4C,EAC5C,QAAwC;QAExC,QAAQ,CAAC,cAAc,CAAC;YACtB,MAAM,QAAQ,GAAG,IAAS,CAAC;YAC3B,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YACnD,MAAM,WAAW,GAAG,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YACvD,IAAI,OAAiC,CAAC;YAEtC,QAAQ,CAAC,OAAO,GAAG;gBACjB,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;gBACtB,MAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;gBACzD,IAAI,MAAM;oBAAE,OAAO,GAAG,MAAM,CAAC;YAC/B,CAAC,CAAC;YAEF,QAAQ,CAAC,SAAS,GAAG;gBACnB,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;gBACxB,OAAO,EAAE,EAAE,CAAC;gBACZ,OAAO,GAAG,SAAS,CAAC;YACtB,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { StatefulComponent } from "@praxisjs/core";
|
|
2
|
+
export interface MethodBehavior {
|
|
3
|
+
wrap(original: (...args: unknown[]) => unknown, instance: object, name: string): (...args: unknown[]) => unknown;
|
|
4
|
+
}
|
|
5
|
+
export declare function createMethodDecorator(behavior: MethodBehavior): (value: (this: object, ...args: unknown[]) => unknown, context: ClassMethodDecoratorContext<StatefulComponent>) => void;
|
|
6
|
+
//# sourceMappingURL=create-method-decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-method-decorator.d.ts","sourceRoot":"","sources":["../src/create-method-decorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,MAAM,WAAW,cAAc;IAC7B,IAAI,CACF,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EACzC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;CACpC;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,cAAc,IAE1D,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EACpD,SAAS,2BAA2B,CAAC,iBAAiB,CAAC,KACtD,IAAI,CAWR"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function createMethodDecorator(behavior) {
|
|
2
|
+
return function (value, context) {
|
|
3
|
+
context.addInitializer(function () {
|
|
4
|
+
const instance = this;
|
|
5
|
+
const name = context.name;
|
|
6
|
+
Object.defineProperty(instance, name, {
|
|
7
|
+
value: behavior.wrap(value, instance, name),
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true,
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=create-method-decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-method-decorator.js","sourceRoot":"","sources":["../src/create-method-decorator.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,qBAAqB,CAAC,QAAwB;IAC5D,OAAO,UACL,KAAoD,EACpD,OAAuD;QAEvD,OAAO,CAAC,cAAc,CAAC;YACrB,MAAM,QAAQ,GAAG,IAAc,CAAC;YAChC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAc,CAAC;YACpC,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE;gBACpC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC;gBAC3C,YAAY,EAAE,IAAI;gBAClB,QAAQ,EAAE,IAAI;aACf,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/events/emit.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { StatefulComponent } from "@praxisjs/core";
|
|
2
|
-
export declare function Emit(propName: string): (value: (this:
|
|
2
|
+
export declare function Emit(propName: string): (value: (this: object, ...args: unknown[]) => unknown, context: ClassMethodDecoratorContext<StatefulComponent>) => void;
|
|
3
3
|
//# sourceMappingURL=emit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/events/emit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/events/emit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAKxD,wBAAgB,IAAI,CAAC,QAAQ,EAAE,MAAM,0BAIjB,GAAI,8FAqBvB"}
|
package/dist/events/emit.js
CHANGED
|
@@ -1,34 +1,29 @@
|
|
|
1
|
+
import { createMethodDecorator } from "../create-method-decorator";
|
|
1
2
|
import { readProp } from "./helper";
|
|
2
3
|
export function Emit(propName) {
|
|
3
|
-
return
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
return createMethodDecorator({
|
|
5
|
+
wrap(original, instance) {
|
|
6
|
+
const comp = instance;
|
|
7
|
+
return (...args) => {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
|
|
9
|
+
const result = original.apply(instance, args);
|
|
10
|
+
const callback = readProp(comp, propName);
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
12
|
+
if (typeof callback !== "function")
|
|
13
|
+
return result;
|
|
14
|
+
if (result !== undefined) {
|
|
15
|
+
callback(result);
|
|
16
|
+
}
|
|
17
|
+
else if (args.length > 0) {
|
|
18
|
+
callback(...args);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
callback();
|
|
22
|
+
}
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
11
24
|
return result;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
else if (args.length > 0) {
|
|
16
|
-
callback(...args);
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
callback();
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
};
|
|
23
|
-
context.addInitializer(function () {
|
|
24
|
-
const name = context.name;
|
|
25
|
-
const bound = wrapped.bind(this);
|
|
26
|
-
Object.defineProperty(this, name, {
|
|
27
|
-
value: bound,
|
|
28
|
-
configurable: true,
|
|
29
|
-
writable: true,
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
};
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
});
|
|
33
28
|
}
|
|
34
29
|
//# sourceMappingURL=emit.js.map
|
package/dist/events/emit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit.js","sourceRoot":"","sources":["../../src/events/emit.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,MAAM,UAAU,IAAI,CAAC,QAAgB;IACnC,OAAO
|
|
1
|
+
{"version":3,"file":"emit.js","sourceRoot":"","sources":["../../src/events/emit.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,MAAM,UAAU,IAAI,CAAC,QAAgB;IACnC,OAAO,qBAAqB,CAAC;QAC3B,IAAI,CAAC,QAAQ,EAAE,QAAQ;YACrB,MAAM,IAAI,GAAG,QAA6B,CAAC;YAC3C,OAAO,CAAC,GAAG,IAAe,EAAE,EAAE;gBAC5B,uGAAuG;gBACvG,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAQ,CAAC;gBAErD,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;gBAC1C,+DAA+D;gBAC/D,IAAI,OAAO,QAAQ,KAAK,UAAU;oBAAE,OAAO,MAAM,CAAC;gBAElD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;oBACxB,QAAiC,CAAC,MAAM,CAAC,CAAC;gBAC7C,CAAC;qBAAM,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBAC1B,QAAsC,CAAC,GAAG,IAAI,CAAC,CAAC;gBACnD,CAAC;qBAAM,CAAC;oBACL,QAAuB,EAAE,CAAC;gBAC7B,CAAC;gBAED,+DAA+D;gBAC/D,OAAO,MAAM,CAAC;YAChB,CAAC,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function OnCommand(propName: string): (value: (this: StatefulComponent, ...args: unknown[]) => void, context: ClassMethodDecoratorContext<StatefulComponent>) => void;
|
|
1
|
+
export declare function OnCommand(propName: string): (value: (this: import("@praxisjs/core").StatefulComponent, ...args: unknown[]) => void, _context: ClassMethodDecoratorContext<import("@praxisjs/core").StatefulComponent, (this: import("@praxisjs/core").StatefulComponent, ...args: any) => any>) => void;
|
|
3
2
|
//# sourceMappingURL=on-command.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"on-command.d.ts","sourceRoot":"","sources":["../../src/events/on-command.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"on-command.d.ts","sourceRoot":"","sources":["../../src/events/on-command.ts"],"names":[],"mappings":"AAMA,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,+PAsBzC"}
|