@softer-components/app-utilities 0.8.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/lib/index.d.ts +26 -0
- package/lib/index.js +26 -0
- package/package.json +41 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ComponentContract } from '../../../types/src';
|
|
2
|
+
import { State } from '../../../types/src';
|
|
3
|
+
|
|
4
|
+
export declare type BaseSelectors<T extends Record<string, State>> = {
|
|
5
|
+
[K in keyof T]: (state: T) => T[K];
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
declare type ContextNameOfType<T, C> = {
|
|
9
|
+
[K in keyof T]: [T[K]] extends [C] ? K : never;
|
|
10
|
+
}[keyof T];
|
|
11
|
+
|
|
12
|
+
export declare const createBaseSelectors: <T extends Record<string, State>>(initialState: T) => BaseSelectors<T>;
|
|
13
|
+
|
|
14
|
+
export declare const emptyContext: SofterContext<{}>;
|
|
15
|
+
|
|
16
|
+
export declare class SofterContext<T extends Record<string, ComponentContract>> {
|
|
17
|
+
private readonly contextPaths;
|
|
18
|
+
constructor(contextPaths: {
|
|
19
|
+
[K in keyof T]: string;
|
|
20
|
+
});
|
|
21
|
+
addContext: <K extends string, C extends ComponentContract>(contextName: K, contextPath?: string) => SofterContext<T & { [P in K]: C; }>;
|
|
22
|
+
getPath<C extends ComponentContract>(contextName: ContextNameOfType<T, C>): string;
|
|
23
|
+
forChild(): SofterContext<T>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { }
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/base-selectors.functions.ts
|
|
2
|
+
var e = (e) => Object.fromEntries(Object.keys(e).map((e) => [e, (t) => t[e]]));
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region src/assert.functions.ts
|
|
5
|
+
function t(e, t) {
|
|
6
|
+
if (e === void 0) throw Error(t ?? "Value is not defined");
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/softer-context.ts
|
|
10
|
+
var n = class e {
|
|
11
|
+
constructor(t) {
|
|
12
|
+
this.contextPaths = t, this.addContext = (t, n = t) => new e({
|
|
13
|
+
...this.contextPaths,
|
|
14
|
+
[t]: n
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
getPath(e) {
|
|
18
|
+
let n = this.contextPaths[e];
|
|
19
|
+
return t(n), n;
|
|
20
|
+
}
|
|
21
|
+
forChild() {
|
|
22
|
+
return new e(Object.fromEntries(Object.entries(this.contextPaths).map(([e, t]) => [e, `../${t}`])));
|
|
23
|
+
}
|
|
24
|
+
}, r = new n({});
|
|
25
|
+
//#endregion
|
|
26
|
+
export { n as SofterContext, e as createBaseSelectors, r as emptyContext };
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@softer-components/app-utilities",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.8.0",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/BenLayet/softer-components.git",
|
|
9
|
+
"directory": "packages/app-utilities"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"lib"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./lib/index.d.ts",
|
|
17
|
+
"import": "./lib/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"clean": "rimraf lib",
|
|
22
|
+
"build": "tsc --noEmit && vite build",
|
|
23
|
+
"build:watch": "vite build --watch",
|
|
24
|
+
"test": "vitest",
|
|
25
|
+
"test:ci": "vitest run",
|
|
26
|
+
"test-for-debug": "vitest --testTimeout=100000 --bail=1",
|
|
27
|
+
"format": "prettier --write .",
|
|
28
|
+
"format:check": "prettier --check .",
|
|
29
|
+
"tsc": "tsc --noEmit"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@softer-components/types": "workspace:^"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"vite-plugin-dts": "^4.5.4",
|
|
36
|
+
"vitest": "^3.2.4"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
}
|
|
41
|
+
}
|