@praxisjs/shared 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ # @praxisjs/shared
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - aaf7dab: Initial beta release
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-present Mateus Martins
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ import type { ChildrenInternal } from "./types/children";
2
+ export declare const flattenChildren: (children: ChildrenInternal | ChildrenInternal[], out?: ChildrenInternal[]) => ChildrenInternal[];
3
+ //# sourceMappingURL=children.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"children.d.ts","sourceRoot":"","sources":["../src/children.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,eAAO,MAAM,eAAe,GAC1B,UAAU,gBAAgB,GAAG,gBAAgB,EAAE,EAC/C,MAAK,gBAAgB,EAAO,uBAU7B,CAAC"}
@@ -0,0 +1,12 @@
1
+ export const flattenChildren = (children, out = []) => {
2
+ if (Array.isArray(children)) {
3
+ for (const child of children) {
4
+ flattenChildren(child, out);
5
+ }
6
+ }
7
+ else {
8
+ out.push(children);
9
+ }
10
+ return out;
11
+ };
12
+ //# sourceMappingURL=children.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"children.js","sourceRoot":"","sources":["../src/children.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,QAA+C,EAC/C,MAA0B,EAAE,EAC5B,EAAE;IACF,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;YAC7B,eAAe,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;SAAM,CAAC;QACN,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { isSignal, isComputed } from "./signal";
2
+ export type { Computed, Signal } from "./types/signal";
3
+ export { flattenChildren } from "./children";
4
+ export type { VNode, Children, ChildrenInternal, FunctionComponent, ComponentConstructor, ComponentInstance, Component, } from "./types/children";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAChD,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,YAAY,EACV,KAAK,EACL,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,SAAS,GACV,MAAM,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { isSignal, isComputed } from "./signal";
2
+ export { flattenChildren } from "./children";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { Computed, Signal } from "./types/signal";
2
+ export declare function isSignal<T>(source: Signal<T> | Computed<T> | (() => T)): boolean;
3
+ export declare function isComputed(source: unknown): source is Function & Record<"subscribe", unknown>;
4
+ //# sourceMappingURL=signal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signal.d.ts","sourceRoot":"","sources":["../src/signal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEvD,wBAAgB,QAAQ,CAAC,CAAC,EACxB,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAC1C,OAAO,CAET;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,qDAEzC"}
package/dist/signal.js ADDED
@@ -0,0 +1,7 @@
1
+ export function isSignal(source) {
2
+ return typeof source.set === "function";
3
+ }
4
+ export function isComputed(source) {
5
+ return typeof source === "function" && "subscribe" in source;
6
+ }
7
+ //# sourceMappingURL=signal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signal.js","sourceRoot":"","sources":["../src/signal.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,QAAQ,CACtB,MAA2C;IAE3C,OAAO,OAAQ,MAAoB,CAAC,GAAG,KAAK,UAAU,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAe;IACxC,OAAO,OAAO,MAAM,KAAK,UAAU,IAAI,WAAW,IAAI,MAAM,CAAC;AAC/D,CAAC"}
@@ -0,0 +1,32 @@
1
+ export type Primitive = string | number | boolean | bigint | symbol | null | undefined;
2
+ export type ReactiveChildren = () => Primitive | VNode | VNode[] | ReactiveChildren[];
3
+ export type ChildrenInternal = Primitive | VNode | ReactiveChildren | ChildrenInternal[];
4
+ export type Children = ChildrenInternal | ChildrenInternal[];
5
+ export type Component = FunctionComponent | ComponentConstructor;
6
+ export interface VNode {
7
+ type: string | Component;
8
+ props: Record<string, unknown>;
9
+ children: ChildrenInternal[];
10
+ key?: string | number;
11
+ }
12
+ export type FunctionComponent<P = Record<string, unknown>> = (props: P & {
13
+ children?: Children;
14
+ }) => VNode | null;
15
+ export interface ComponentConstructor<P = Record<string, unknown>> {
16
+ new (props: P): ComponentInstance;
17
+ isComponent: true;
18
+ }
19
+ export interface ComponentInstance {
20
+ _mounted: boolean;
21
+ _stateDirty: boolean;
22
+ _lastResolvedProps?: Record<string, unknown>;
23
+ _isMemorized?: boolean;
24
+ _arePropsEqual?: (prevProps: Record<string, unknown>, nextProps: Record<string, unknown>) => boolean;
25
+ _setProps(p: Record<string, unknown>): void;
26
+ render(): VNode | null;
27
+ onBeforeMount?(): void;
28
+ onMount?(): void;
29
+ onUnmount?(): void;
30
+ onError?(e: Error): void;
31
+ }
32
+ //# sourceMappingURL=children.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"children.d.ts","sourceRoot":"","sources":["../../src/types/children.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,MAAM,GACN,OAAO,GACP,MAAM,GACN,MAAM,GACN,IAAI,GACJ,SAAS,CAAC;AAEd,MA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AC;IACb,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5C,MAAM,IAAI,KAAK,GAAG,IAAI,CAAC;IACvB,aAAa,CAAC,IAAI,IAAI,CAAC;IACvB,OAAO,CAAC,IAAI,IAAI,CAAC;IACjB,SAAS,CAAC,IAAI,IAAI,CAAC;IACnB,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;CAC1B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=children.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"children.js","sourceRoot":"","sources":["../../src/types/children.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ export interface Computed<T> {
2
+ (): T;
3
+ subscribe(effect: (value: T) => void): () => void;
4
+ }
5
+ export interface Signal<T> {
6
+ (): T;
7
+ set(value: T): void;
8
+ update(updater: (prev: T) => T): void;
9
+ subscribe(effect: (value: T) => void): () => void;
10
+ }
11
+ //# sourceMappingURL=signal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signal.d.ts","sourceRoot":"","sources":["../../src/types/signal.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ,CAAC,CAAC;IACzB,IAAI,CAAC,CAAC;IACN,SAAS,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CACnD;AAED,MAAM,WAAW,MAAM,CAAC,CAAC;IACvB,IAAI,CAAC,CAAC;IACN,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IACpB,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IACtC,SAAS,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CACnD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=signal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signal.js","sourceRoot":"","sources":["../../src/types/signal.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@praxisjs/shared",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "types": "./dist/index.d.ts"
11
+ }
12
+ },
13
+ "devDependencies": {
14
+ "typescript": "^5.9.3"
15
+ },
16
+ "scripts": {
17
+ "build": "tsc",
18
+ "dev": "tsc --watch"
19
+ }
20
+ }
@@ -0,0 +1,15 @@
1
+ import type { ChildrenInternal } from "./types/children";
2
+
3
+ export const flattenChildren = (
4
+ children: ChildrenInternal | ChildrenInternal[],
5
+ out: ChildrenInternal[] = [],
6
+ ) => {
7
+ if (Array.isArray(children)) {
8
+ for (const child of children) {
9
+ flattenChildren(child, out);
10
+ }
11
+ } else {
12
+ out.push(children);
13
+ }
14
+ return out;
15
+ };
package/src/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ export { isSignal, isComputed } from "./signal";
2
+ export type { Computed, Signal } from "./types/signal";
3
+ export { flattenChildren } from "./children";
4
+ export type {
5
+ VNode,
6
+ Children,
7
+ ChildrenInternal,
8
+ FunctionComponent,
9
+ ComponentConstructor,
10
+ ComponentInstance,
11
+ Component,
12
+ } from "./types/children";
package/src/signal.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type { Computed, Signal } from "./types/signal";
2
+
3
+ export function isSignal<T>(
4
+ source: Signal<T> | Computed<T> | (() => T),
5
+ ): boolean {
6
+ return typeof (source as Signal<T>).set === "function";
7
+ }
8
+
9
+ export function isComputed(source: unknown) {
10
+ return typeof source === "function" && "subscribe" in source;
11
+ }
@@ -0,0 +1,57 @@
1
+ export type Primitive =
2
+ | string
3
+ | number
4
+ | boolean
5
+ | bigint
6
+ | symbol
7
+ | null
8
+ | undefined;
9
+
10
+ export type ReactiveChildren = () =>
11
+ | Primitive
12
+ | VNode
13
+ | VNode[]
14
+ | ReactiveChildren[];
15
+
16
+ export type ChildrenInternal =
17
+ | Primitive
18
+ | VNode
19
+ | ReactiveChildren
20
+ | ChildrenInternal[];
21
+
22
+ export type Children = ChildrenInternal | ChildrenInternal[];
23
+
24
+ export type Component = FunctionComponent | ComponentConstructor;
25
+
26
+ export interface VNode {
27
+ type: string | Component;
28
+ props: Record<string, unknown>;
29
+ children: ChildrenInternal[];
30
+ key?: string | number;
31
+ }
32
+
33
+ export type FunctionComponent<P = Record<string, unknown>> = (
34
+ props: P & { children?: Children },
35
+ ) => VNode | null;
36
+
37
+ export interface ComponentConstructor<P = Record<string, unknown>> {
38
+ new (props: P): ComponentInstance;
39
+ isComponent: true;
40
+ }
41
+
42
+ export interface ComponentInstance {
43
+ _mounted: boolean;
44
+ _stateDirty: boolean;
45
+ _lastResolvedProps?: Record<string, unknown>;
46
+ _isMemorized?: boolean;
47
+ _arePropsEqual?: (
48
+ prevProps: Record<string, unknown>,
49
+ nextProps: Record<string, unknown>,
50
+ ) => boolean;
51
+ _setProps(p: Record<string, unknown>): void;
52
+ render(): VNode | null;
53
+ onBeforeMount?(): void;
54
+ onMount?(): void;
55
+ onUnmount?(): void;
56
+ onError?(e: Error): void;
57
+ }
@@ -0,0 +1,11 @@
1
+ export interface Computed<T> {
2
+ (): T;
3
+ subscribe(effect: (value: T) => void): () => void;
4
+ }
5
+
6
+ export interface Signal<T> {
7
+ (): T;
8
+ set(value: T): void;
9
+ update(updater: (prev: T) => T): void;
10
+ subscribe(effect: (value: T) => void): () => void;
11
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src",
6
+ "declarationDir": "./dist"
7
+ },
8
+ "include": ["src"]
9
+ }