rask-ui 0.2.7 → 0.3.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/dist/component.d.ts +31 -0
- package/dist/component.d.ts.map +1 -0
- package/dist/component.js +111 -0
- package/dist/createContext.d.ts.map +1 -1
- package/dist/createContext.js +2 -13
- package/dist/createState.js +16 -0
- package/dist/error.d.ts +13 -3
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +16 -18
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/jsx-dev-runtime.d.ts +3 -2
- package/dist/jsx-dev-runtime.d.ts.map +1 -1
- package/dist/jsx-dev-runtime.js +3 -2
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/jsx-runtime.d.ts.map +1 -1
- package/dist/jsx-runtime.js +15 -4
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +15 -1
- package/dist/test-setup.d.ts +2 -2
- package/dist/test-setup.d.ts.map +1 -1
- package/dist/test-setup.js +2 -1
- package/dist/vdom/AbstractVNode.d.ts +1 -1
- package/dist/vdom/AbstractVNode.d.ts.map +1 -1
- package/dist/vdom/AbstractVNode.js +4 -2
- package/dist/vdom/ComponentVNode.js +2 -2
- package/dist/vdom/ElementVNode.js +1 -1
- package/dist/vdom/FragmentVNode.js +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { VNode, Component, Props, InfernoNode } from "inferno";
|
|
2
|
+
export declare function getCurrentComponent(): RaskComponent<any>;
|
|
3
|
+
export declare function onMount(cb: () => void): void;
|
|
4
|
+
export declare function onCleanup(cb: () => void): void;
|
|
5
|
+
export type RaskFunctionComponent<P extends Props<any>> = (() => () => VNode) | ((props: P) => () => VNode);
|
|
6
|
+
declare class RaskComponent<P extends Props<any>> extends Component<P & {
|
|
7
|
+
__component: RaskFunctionComponent<P>;
|
|
8
|
+
}> {
|
|
9
|
+
private renderFn?;
|
|
10
|
+
private reactiveProps?;
|
|
11
|
+
private prevChildren;
|
|
12
|
+
private observer;
|
|
13
|
+
contexts: Map<any, any>;
|
|
14
|
+
getChildContext(): {
|
|
15
|
+
getContext: (context: any) => any;
|
|
16
|
+
};
|
|
17
|
+
onMounts: Array<() => void>;
|
|
18
|
+
onCleanups: Array<() => void>;
|
|
19
|
+
componentDidMount(): void;
|
|
20
|
+
componentWillReceiveProps(nextProps: Readonly<{
|
|
21
|
+
children?: InfernoNode;
|
|
22
|
+
} & P & {
|
|
23
|
+
__component: RaskFunctionComponent<P>;
|
|
24
|
+
}>): void;
|
|
25
|
+
componentWillUnmount(): void;
|
|
26
|
+
shouldComponentUpdate(): boolean;
|
|
27
|
+
render(): any;
|
|
28
|
+
}
|
|
29
|
+
export declare function createComponent(props: Props<any>, key?: string): VNode;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,EACL,SAAS,EACT,KAAK,EACL,WAAW,EACZ,MAAM,SAAS,CAAC;AAMjB,wBAAgB,mBAAmB,uBAQlC;AAED,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,IAAI,QAQrC;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,IAAI,QAQvC;AAED,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,IAClD,CAAC,MAAM,MAAM,KAAK,CAAC,GACnB,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,KAAK,CAAC,CAAC;AAEhC,cAAM,aAAa,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,CAAE,SAAQ,SAAS,CACzD,CAAC,GAAG;IAAE,WAAW,EAAE,qBAAqB,CAAC,CAAC,CAAC,CAAA;CAAE,CAC9C;IACC,OAAO,CAAC,QAAQ,CAAC,CAAc;IAC/B,OAAO,CAAC,aAAa,CAAC,CAAa;IACnC,OAAO,CAAC,YAAY,CAAM;IAC1B,OAAO,CAAC,QAAQ,CAEb;IACH,QAAQ,gBAAa;IACrB,eAAe;8BAEW,GAAG;;IAK7B,QAAQ,EAAE,KAAK,CAAC,MAAM,IAAI,CAAC,CAAM;IACjC,UAAU,EAAE,KAAK,CAAC,MAAM,IAAI,CAAC,CAAM;IACnC,iBAAiB,IAAI,IAAI;IAGzB,yBAAyB,CACvB,SAAS,EAAE,QAAQ,CACjB;QAAE,QAAQ,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,CAAC,GAAG;QAAE,WAAW,EAAE,qBAAqB,CAAC,CAAC,CAAC,CAAA;KAAE,CAC3E,GACA,IAAI;IAaP,oBAAoB,IAAI,IAAI;IAG5B,qBAAqB,IAAI,OAAO;IAGhC,MAAM;CAoBP;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,SAQ9D"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { createComponentVNode, Component, } from "inferno";
|
|
2
|
+
import { getCurrentObserver, Observer, Signal } from "./observation";
|
|
3
|
+
const componentStack = [];
|
|
4
|
+
export function getCurrentComponent() {
|
|
5
|
+
const currentComponent = componentStack[0];
|
|
6
|
+
if (!currentComponent) {
|
|
7
|
+
throw new Error("No current component");
|
|
8
|
+
}
|
|
9
|
+
return currentComponent;
|
|
10
|
+
}
|
|
11
|
+
export function onMount(cb) {
|
|
12
|
+
const current = componentStack[0];
|
|
13
|
+
if (!current) {
|
|
14
|
+
throw new Error("Only use onCleanup in component setup");
|
|
15
|
+
}
|
|
16
|
+
current.onMounts.push(cb);
|
|
17
|
+
}
|
|
18
|
+
export function onCleanup(cb) {
|
|
19
|
+
const current = componentStack[0];
|
|
20
|
+
if (!current) {
|
|
21
|
+
throw new Error("Only use onCleanup in component setup");
|
|
22
|
+
}
|
|
23
|
+
current.onCleanups.push(cb);
|
|
24
|
+
}
|
|
25
|
+
class RaskComponent extends Component {
|
|
26
|
+
renderFn;
|
|
27
|
+
reactiveProps;
|
|
28
|
+
prevChildren;
|
|
29
|
+
observer = new Observer(() => {
|
|
30
|
+
this.forceUpdate();
|
|
31
|
+
});
|
|
32
|
+
contexts = new Map();
|
|
33
|
+
getChildContext() {
|
|
34
|
+
return {
|
|
35
|
+
getContext: (context) => {
|
|
36
|
+
return this.contexts.get(context);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
onMounts = [];
|
|
41
|
+
onCleanups = [];
|
|
42
|
+
componentDidMount() {
|
|
43
|
+
this.onMounts.forEach((cb) => cb());
|
|
44
|
+
}
|
|
45
|
+
componentWillReceiveProps(nextProps) {
|
|
46
|
+
if (this.props.children === nextProps.children) {
|
|
47
|
+
for (const prop in nextProps) {
|
|
48
|
+
if (prop === "children") {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
this.reactiveProps[prop] = nextProps[prop];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
this.prevChildren = this.props.children;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
componentWillUnmount() {
|
|
60
|
+
this.onCleanups.forEach((cb) => cb());
|
|
61
|
+
}
|
|
62
|
+
shouldComponentUpdate() {
|
|
63
|
+
return this.prevChildren !== this.props.children;
|
|
64
|
+
}
|
|
65
|
+
render() {
|
|
66
|
+
if (!this.renderFn) {
|
|
67
|
+
componentStack.unshift(this);
|
|
68
|
+
this.reactiveProps = createReactiveProps(this.props);
|
|
69
|
+
this.renderFn = this.props.__component(this.reactiveProps);
|
|
70
|
+
componentStack.shift();
|
|
71
|
+
}
|
|
72
|
+
const stopObserving = this.observer.observe();
|
|
73
|
+
let result = null;
|
|
74
|
+
try {
|
|
75
|
+
result = this.renderFn();
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
this.context.notifyError(error);
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
stopObserving();
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export function createComponent(props, key) {
|
|
87
|
+
console.log(props);
|
|
88
|
+
return createComponentVNode(4 /* VNodeFlags.ComponentClass */, RaskComponent, props, key);
|
|
89
|
+
}
|
|
90
|
+
function createReactiveProps(props) {
|
|
91
|
+
const reactiveProps = {};
|
|
92
|
+
for (const prop in props) {
|
|
93
|
+
const signal = new Signal();
|
|
94
|
+
Object.defineProperty(reactiveProps, prop, {
|
|
95
|
+
get() {
|
|
96
|
+
const observer = getCurrentObserver();
|
|
97
|
+
if (observer) {
|
|
98
|
+
observer.subscribeSignal(signal);
|
|
99
|
+
}
|
|
100
|
+
return props[prop];
|
|
101
|
+
},
|
|
102
|
+
set(value) {
|
|
103
|
+
if (props[prop] !== value) {
|
|
104
|
+
props[prop] = value;
|
|
105
|
+
signal.notify();
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return reactiveProps;
|
|
111
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createContext.d.ts","sourceRoot":"","sources":["../src/createContext.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createContext.d.ts","sourceRoot":"","sources":["../src/createContext.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH,wBAAgB,aAAa,CAAC,CAAC;kBAEb,CAAC;WASR,CAAC;EAYX"}
|
package/dist/createContext.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { getCurrentComponent, } from "./vdom/ComponentVNode";
|
|
2
|
-
import { findComponentVNode } from "./vdom/utils";
|
|
3
1
|
/**
|
|
4
2
|
* Creates a context object for providing and consuming values across component trees.
|
|
5
3
|
*
|
|
@@ -24,6 +22,7 @@ import { findComponentVNode } from "./vdom/utils";
|
|
|
24
22
|
*
|
|
25
23
|
* @returns Context object with inject() and get() methods
|
|
26
24
|
*/
|
|
25
|
+
import { getCurrentComponent } from "./component";
|
|
27
26
|
export function createContext() {
|
|
28
27
|
const context = {
|
|
29
28
|
inject(value) {
|
|
@@ -31,9 +30,6 @@ export function createContext() {
|
|
|
31
30
|
if (!currentComponent) {
|
|
32
31
|
throw new Error("You can not inject context outside component setup");
|
|
33
32
|
}
|
|
34
|
-
if (!currentComponent.contexts) {
|
|
35
|
-
currentComponent.contexts = new Map();
|
|
36
|
-
}
|
|
37
33
|
currentComponent.contexts.set(context, value);
|
|
38
34
|
},
|
|
39
35
|
get() {
|
|
@@ -41,14 +37,7 @@ export function createContext() {
|
|
|
41
37
|
if (!currentComponent) {
|
|
42
38
|
throw new Error("You can not get context outside component setup");
|
|
43
39
|
}
|
|
44
|
-
|
|
45
|
-
if (currentComponent.contexts?.has(context)) {
|
|
46
|
-
return currentComponent.contexts.get(context);
|
|
47
|
-
}
|
|
48
|
-
const componentNode = findComponentVNode(currentComponent.parent);
|
|
49
|
-
currentComponent = componentNode?.instance ?? null;
|
|
50
|
-
}
|
|
51
|
-
throw new Error("Could not find context in parent components");
|
|
40
|
+
return currentComponent.context.getContext(context);
|
|
52
41
|
},
|
|
53
42
|
};
|
|
54
43
|
return context;
|
package/dist/createState.js
CHANGED
|
@@ -27,13 +27,29 @@ export function createState(state) {
|
|
|
27
27
|
return getProxy(state);
|
|
28
28
|
}
|
|
29
29
|
const proxyCache = new WeakMap();
|
|
30
|
+
const PROXY_MARKER = Symbol('isProxy');
|
|
30
31
|
function getProxy(value) {
|
|
32
|
+
// Check if already a proxy to avoid double-wrapping
|
|
33
|
+
if (PROXY_MARKER in value) {
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
31
36
|
if (proxyCache.has(value)) {
|
|
32
37
|
return proxyCache.get(value);
|
|
33
38
|
}
|
|
34
39
|
const signals = {};
|
|
35
40
|
const proxy = new Proxy(value, {
|
|
41
|
+
has(target, key) {
|
|
42
|
+
// Support the "in" operator check for PROXY_MARKER
|
|
43
|
+
if (key === PROXY_MARKER) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return Reflect.has(target, key);
|
|
47
|
+
},
|
|
36
48
|
get(target, key) {
|
|
49
|
+
// Mark this as a proxy to prevent double-wrapping
|
|
50
|
+
if (key === PROXY_MARKER) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
37
53
|
const value = Reflect.get(target, key);
|
|
38
54
|
if (typeof key === "symbol" || typeof value === "function") {
|
|
39
55
|
return value;
|
package/dist/error.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Component } from "inferno";
|
|
2
|
+
export declare class ErrorBoundary extends Component<{
|
|
3
3
|
children: any;
|
|
4
|
-
}
|
|
4
|
+
}, {
|
|
5
|
+
hasError: boolean;
|
|
6
|
+
}> {
|
|
7
|
+
getChildContext(): {
|
|
8
|
+
notifyError: (error: unknown) => void;
|
|
9
|
+
};
|
|
10
|
+
state: {
|
|
11
|
+
hasError: boolean;
|
|
12
|
+
};
|
|
13
|
+
render(): any;
|
|
14
|
+
}
|
|
5
15
|
//# sourceMappingURL=error.d.ts.map
|
package/dist/error.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,qBAAa,aAAc,SAAQ,SAAS,CAC1C;IAAE,QAAQ,EAAE,GAAG,CAAA;CAAE,EACjB;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,CACtB;IACC,eAAe;6BAEU,OAAO;;IAKhC,KAAK;;MAAuB;IAE5B,MAAM;CAOP"}
|
package/dist/error.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { jsx as _jsx } from "./jsx-runtime";
|
|
2
|
+
import { Component } from "inferno";
|
|
3
|
+
export class ErrorBoundary extends Component {
|
|
4
|
+
getChildContext() {
|
|
5
|
+
return {
|
|
6
|
+
notifyError: (error) => {
|
|
7
|
+
this.setState({ hasError: true });
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
state = { hasError: false };
|
|
12
|
+
render() {
|
|
13
|
+
if (this.state.hasError) {
|
|
14
|
+
return _jsx("div", { style: "color: red", children: "Something went wrong." });
|
|
7
15
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const children = Array.isArray(props.children)
|
|
11
|
-
? props.children
|
|
12
|
-
: [props.children];
|
|
13
|
-
children.forEach((child) => {
|
|
14
|
-
if (child?.data?.parentComponent) {
|
|
15
|
-
child.data.parentComponent = component;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
return props.children;
|
|
19
|
-
};
|
|
16
|
+
return this.props.children;
|
|
17
|
+
}
|
|
20
18
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { render } from "
|
|
2
|
-
export { onCleanup, onMount } from "./
|
|
1
|
+
export { render } from "inferno";
|
|
2
|
+
export { onCleanup, onMount } from "./component";
|
|
3
3
|
export { createContext } from "./createContext";
|
|
4
4
|
export { createState } from "./createState";
|
|
5
5
|
export { createAsync } from "./createAsync";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { render } from "
|
|
2
|
-
export { onCleanup, onMount } from "./
|
|
1
|
+
export { render } from "inferno";
|
|
2
|
+
export { onCleanup, onMount } from "./component";
|
|
3
3
|
export { createContext } from "./createContext";
|
|
4
4
|
export { createState } from "./createState";
|
|
5
5
|
export { createAsync } from "./createAsync";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { jsx, jsxs
|
|
1
|
+
export { jsx, jsxs } from "./jsx-runtime";
|
|
2
2
|
export type { JSX } from "./jsx-runtime";
|
|
3
|
-
export {
|
|
3
|
+
export { Fragment } from "inferno";
|
|
4
|
+
export { jsx as jsxDEV } from "./jsx-runtime";
|
|
4
5
|
//# sourceMappingURL=jsx-dev-runtime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsx-dev-runtime.d.ts","sourceRoot":"","sources":["../src/jsx-dev-runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"jsx-dev-runtime.d.ts","sourceRoot":"","sources":["../src/jsx-dev-runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC1C,YAAY,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAInC,OAAO,EAAE,GAAG,IAAI,MAAM,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/jsx-dev-runtime.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// JSX dev runtime - adds jsxDEV for development mode
|
|
2
|
-
export { jsx, jsxs
|
|
2
|
+
export { jsx, jsxs } from "./jsx-runtime";
|
|
3
|
+
export { Fragment } from "inferno";
|
|
3
4
|
// In development mode, TypeScript uses jsxDEV instead of jsx
|
|
4
5
|
// We just alias it to jsx since we don't need the extra dev-mode params
|
|
5
|
-
export { jsx as jsxDEV } from "./
|
|
6
|
+
export { jsx as jsxDEV } from "./jsx-runtime";
|
package/dist/jsx-runtime.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { JSXInternal } from "./jsx";
|
|
2
|
-
export { Fragment } from "
|
|
2
|
+
export { Fragment } from "inferno";
|
|
3
3
|
export declare function jsx(type: string, props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record<string, any>, key?: string): any;
|
|
4
4
|
export declare function jsx<P>(type: (props: P) => any, props: P & {
|
|
5
5
|
children?: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsx-runtime.d.ts","sourceRoot":"","sources":["../src/jsx-runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"jsx-runtime.d.ts","sourceRoot":"","sources":["../src/jsx-runtime.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAIzC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,wBAAgB,GAAG,CACjB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,WAAW,CAAC,cAAc,GAC/B,WAAW,CAAC,aAAa,GACzB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACrB,GAAG,CAAC,EAAE,MAAM,GACX,GAAG,CAAC;AACP,wBAAgB,GAAG,CAAC,CAAC,EACnB,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,EACvB,KAAK,EAAE,CAAC,GAAG;IAAE,QAAQ,CAAC,EAAE,GAAG,CAAA;CAAE,EAC7B,GAAG,CAAC,EAAE,MAAM,GACX,GAAG,CAAC;AAmBP,wBAAgB,IAAI,CAClB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,WAAW,CAAC,cAAc,GAC/B,WAAW,CAAC,aAAa,GACzB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACrB,GAAG,CAAC,EAAE,MAAM,GACX,GAAG,CAAC;AACP,wBAAgB,IAAI,CAAC,CAAC,EACpB,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,EACvB,KAAK,EAAE,CAAC,GAAG;IAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAA;CAAE,EAC/B,GAAG,CAAC,EAAE,MAAM,GACX,GAAG,CAAC;AAMP,YAAY,EAAE,WAAW,IAAI,GAAG,EAAE,MAAM,OAAO,CAAC"}
|
package/dist/jsx-runtime.js
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// JSX runtime implementation
|
|
2
|
+
import { createComponentVNode } from "inferno";
|
|
3
|
+
import { createElement } from "inferno-create-element";
|
|
4
|
+
import { createComponent } from "./component";
|
|
5
|
+
import { ErrorBoundary } from "./error";
|
|
6
|
+
export { Fragment } from "inferno";
|
|
7
|
+
export function jsx(type, { children, ...props }, key) {
|
|
8
|
+
if (typeof type === "string") {
|
|
9
|
+
return createElement(type, { ...props, key }, ...children);
|
|
10
|
+
}
|
|
11
|
+
if (type === ErrorBoundary) {
|
|
12
|
+
console.log("WTF");
|
|
13
|
+
return createComponentVNode(14 /* VNodeFlags.Component */, ErrorBoundary, { ...props, children }, key);
|
|
14
|
+
}
|
|
15
|
+
return createComponent({ ...props, children, __component: type }, key);
|
|
5
16
|
}
|
|
6
17
|
export function jsxs(type, props, key) {
|
|
7
18
|
return jsx(type, props, key);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observation.d.ts","sourceRoot":"","sources":["../src/observation.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,aAEjC;
|
|
1
|
+
{"version":3,"file":"observation.d.ts","sourceRoot":"","sources":["../src/observation.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,aAEjC;AAKD,qBAAa,MAAM;IACjB,OAAO,CAAC,WAAW,CAAyB;IAC5C,SAAS,CAAC,EAAE,EAAE,MAAM,IAAI;IAOxB,MAAM;CAgBP;AAED,qBAAa,QAAQ;IACnB,UAAU,UAAS;IACnB,OAAO,CAAC,eAAe,CAAyB;IAChD,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,QAAQ,CAAa;gBACjB,QAAQ,EAAE,MAAM,IAAI;IAGhC,eAAe,CAAC,MAAM,EAAE,MAAM;IAG9B,OAAO;IAOP,OAAO;CAIR"}
|
package/dist/observation.js
CHANGED
|
@@ -2,6 +2,8 @@ const observerStack = [];
|
|
|
2
2
|
export function getCurrentObserver() {
|
|
3
3
|
return observerStack[0];
|
|
4
4
|
}
|
|
5
|
+
let isQueuingNotify = false;
|
|
6
|
+
let notifyQueue = [];
|
|
5
7
|
export class Signal {
|
|
6
8
|
subscribers = new Set();
|
|
7
9
|
subscribe(cb) {
|
|
@@ -11,7 +13,19 @@ export class Signal {
|
|
|
11
13
|
};
|
|
12
14
|
}
|
|
13
15
|
notify() {
|
|
14
|
-
this.subscribers
|
|
16
|
+
const currentSubscribers = Array.from(this.subscribers);
|
|
17
|
+
notifyQueue.push(() => {
|
|
18
|
+
currentSubscribers.forEach((cb) => cb());
|
|
19
|
+
});
|
|
20
|
+
if (!isQueuingNotify) {
|
|
21
|
+
isQueuingNotify = true;
|
|
22
|
+
queueMicrotask(() => {
|
|
23
|
+
isQueuingNotify = false;
|
|
24
|
+
const queue = notifyQueue;
|
|
25
|
+
notifyQueue = [];
|
|
26
|
+
queue.forEach((cb) => cb());
|
|
27
|
+
});
|
|
28
|
+
}
|
|
15
29
|
}
|
|
16
30
|
}
|
|
17
31
|
export class Observer {
|
package/dist/test-setup.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VNode } from "
|
|
1
|
+
import { VNode } from "inferno";
|
|
2
2
|
/**
|
|
3
3
|
* Test helper to render a component and provide easy cleanup
|
|
4
4
|
*
|
|
@@ -9,7 +9,7 @@ import { VNode } from "./vdom/types";
|
|
|
9
9
|
*/
|
|
10
10
|
export declare function renderComponent(vnode: VNode): {
|
|
11
11
|
container: HTMLElement;
|
|
12
|
-
vnode:
|
|
12
|
+
vnode: void;
|
|
13
13
|
unmount: () => void;
|
|
14
14
|
rerender: (newVnode: VNode) => void;
|
|
15
15
|
};
|
package/dist/test-setup.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-setup.d.ts","sourceRoot":"","sources":["../src/test-setup.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"test-setup.d.ts","sourceRoot":"","sources":["../src/test-setup.ts"],"names":[],"mappings":"AAGA,OAAO,EAAU,KAAK,EAAE,MAAM,SAAS,CAAC;AAUxC;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK;;;;yBAoBnB,KAAK;EAI7B"}
|
package/dist/test-setup.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Test setup file for vitest
|
|
2
2
|
import { afterEach } from "vitest";
|
|
3
|
-
import { render } from "
|
|
3
|
+
import { render } from "inferno";
|
|
4
4
|
// Clean up after each test
|
|
5
5
|
afterEach(() => {
|
|
6
6
|
document.body.innerHTML = "";
|
|
@@ -19,6 +19,7 @@ export function renderComponent(vnode) {
|
|
|
19
19
|
const container = document.createElement("div");
|
|
20
20
|
document.body.appendChild(container);
|
|
21
21
|
let currentVnode = render(vnode, container);
|
|
22
|
+
// @ts-ignore
|
|
22
23
|
const actualElement = currentVnode.elm;
|
|
23
24
|
return {
|
|
24
25
|
// The actual rendered DOM element (after patch replaces container)
|
|
@@ -31,7 +31,7 @@ export declare abstract class AbstractVNode {
|
|
|
31
31
|
patchChildren(newChildren: VNode[]): {
|
|
32
32
|
children: VNode[];
|
|
33
33
|
hasChangedStructure: boolean;
|
|
34
|
-
operations
|
|
34
|
+
operations?: PatchOperation[];
|
|
35
35
|
};
|
|
36
36
|
applyPatchOperations(target: HTMLElement, operations: PatchOperation[]): void;
|
|
37
37
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractVNode.d.ts","sourceRoot":"","sources":["../../src/vdom/AbstractVNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,MAAM,MAAM,cAAc,GACtB;IACE,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC;CACpB,GACD;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC;IACtB,MAAM,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC;CACvB,GACD;IACE,IAAI,EAAE,QAAQ,CAAC;IACf,GAAG,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC;CACpB,CAAC;AAEN,8BAAsB,aAAa;IACjC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,KAAK,CAAC;IACf,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,GAAG,CAAC,EAAE,IAAI,CAAC;IACX,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC;IACnB,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,GAAG,IAAI,GAAG,IAAI,EAAE;IAC7C,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,GAAG,IAAI;IACpC,QAAQ,CAAC,OAAO,IAAI,IAAI;IACxB,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,cAAc,EAAE,GAAG,IAAI;IACtD,SAAS,CAAC,cAAc;IAOxB;;OAEG;IACH,WAAW,IAAI,IAAI,EAAE;IAmBrB,gBAAgB,IAAI,WAAW;IAiB/B,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,GAAG,OAAO;IAoB3D,aAAa,CAAC,WAAW,EAAE,KAAK,EAAE,GAAG;QACnC,QAAQ,EAAE,KAAK,EAAE,CAAC;QAClB,mBAAmB,EAAE,OAAO,CAAC;QAC7B,UAAU,EAAE,cAAc,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"AbstractVNode.d.ts","sourceRoot":"","sources":["../../src/vdom/AbstractVNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,MAAM,MAAM,cAAc,GACtB;IACE,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC;CACpB,GACD;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC;IACtB,MAAM,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC;CACvB,GACD;IACE,IAAI,EAAE,QAAQ,CAAC;IACf,GAAG,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC;CACpB,CAAC;AAEN,8BAAsB,aAAa;IACjC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,KAAK,CAAC;IACf,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,GAAG,CAAC,EAAE,IAAI,CAAC;IACX,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC;IACnB,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,GAAG,IAAI,GAAG,IAAI,EAAE;IAC7C,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,GAAG,IAAI;IACpC,QAAQ,CAAC,OAAO,IAAI,IAAI;IACxB,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,cAAc,EAAE,GAAG,IAAI;IACtD,SAAS,CAAC,cAAc;IAOxB;;OAEG;IACH,WAAW,IAAI,IAAI,EAAE;IAmBrB,gBAAgB,IAAI,WAAW;IAiB/B,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,GAAG,OAAO;IAoB3D,aAAa,CAAC,WAAW,EAAE,KAAK,EAAE,GAAG;QACnC,QAAQ,EAAE,KAAK,EAAE,CAAC;QAClB,mBAAmB,EAAE,OAAO,CAAC;QAC7B,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;KAC/B;IAqJD,oBAAoB,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE;IAqCtE;;;;OAIG;IACH,SAAS,CAAC,eAAe;CA6B1B"}
|
|
@@ -63,13 +63,15 @@ export class AbstractVNode {
|
|
|
63
63
|
}
|
|
64
64
|
patchChildren(newChildren) {
|
|
65
65
|
const prevChildren = this.children;
|
|
66
|
+
if (newChildren.length === 0 && prevChildren.length === 0) {
|
|
67
|
+
return { children: [], hasChangedStructure: false };
|
|
68
|
+
}
|
|
66
69
|
// When there are only new children, we just mount them
|
|
67
|
-
if (
|
|
70
|
+
if (prevChildren.length === 0) {
|
|
68
71
|
newChildren.forEach((child) => child.mount(this));
|
|
69
72
|
return {
|
|
70
73
|
children: newChildren,
|
|
71
74
|
hasChangedStructure: true,
|
|
72
|
-
operations: [],
|
|
73
75
|
};
|
|
74
76
|
}
|
|
75
77
|
// If we want to remove all children, we just unmount the previous ones
|
|
@@ -100,11 +100,11 @@ export class ComponentVNode extends AbstractVNode {
|
|
|
100
100
|
this.children = children;
|
|
101
101
|
// So if a fragment is returned where we add new elements we can not safely
|
|
102
102
|
// add them yet, check Fragment for a potential later optimization
|
|
103
|
-
const hasAddOperation = operations
|
|
103
|
+
const hasAddOperation = operations?.some((operation) => operation.type === "add");
|
|
104
104
|
if (hasChangedStructure || hasAddOperation) {
|
|
105
105
|
this.parent?.rerender();
|
|
106
106
|
}
|
|
107
|
-
else if (operations
|
|
107
|
+
else if (operations?.length) {
|
|
108
108
|
this.parent?.rerender(operations);
|
|
109
109
|
}
|
|
110
110
|
this.root?.clearCurrent();
|
|
@@ -36,7 +36,7 @@ export class FragmentVNode extends AbstractVNode {
|
|
|
36
36
|
// handled with some additional detection, changing it to insertBefore. This can be
|
|
37
37
|
// done by passing this vnode up to the parent
|
|
38
38
|
this.rerender(hasChangedStructure ||
|
|
39
|
-
operations
|
|
39
|
+
operations?.some((operation) => operation.type === "add")
|
|
40
40
|
? undefined
|
|
41
41
|
: operations);
|
|
42
42
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rask-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -35,5 +35,10 @@
|
|
|
35
35
|
"jsdom": "^27.1.0",
|
|
36
36
|
"typescript": "^5.7.3",
|
|
37
37
|
"vitest": "^4.0.7"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"inferno": "^9.0.4",
|
|
41
|
+
"inferno-create-element": "^9.0.4",
|
|
42
|
+
"inferno-vnode-flags": "^9.0.4"
|
|
38
43
|
}
|
|
39
44
|
}
|