@lorion-org/react 1.0.0-beta.2 → 1.0.0-beta.4
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/README.md +304 -15
- package/dist/index.cjs +49 -38
- package/dist/index.d.cts +21 -5
- package/dist/index.d.ts +21 -5
- package/dist/index.js +53 -15
- package/dist/vite.cjs +317 -130
- package/dist/vite.d.cts +64 -6
- package/dist/vite.d.ts +64 -6
- package/dist/vite.js +325 -107
- package/package.json +15 -8
- package/src/index.ts +3 -0
- package/src/relations.ts +8 -37
- package/src/runtime-config.ts +63 -0
- package/src/vite.ts +575 -129
- package/dist/chunk-5FUI4JPB.js +0 -38
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { createContext, createElement, useContext, type ReactElement, type ReactNode } from 'react';
|
|
2
|
+
import type { RuntimeConfigSection } from '@lorion-org/runtime-config';
|
|
3
|
+
|
|
4
|
+
export type CapabilityRuntimeConfig = {
|
|
5
|
+
public: Record<string, RuntimeConfigSection>;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type CapabilityRuntimeConfigFragment<T extends RuntimeConfigSection = RuntimeConfigSection> =
|
|
9
|
+
{
|
|
10
|
+
public: T;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type CapabilityRuntimeConfigProviderProps = {
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
runtimeConfig: CapabilityRuntimeConfig;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const emptyRuntimeConfig: CapabilityRuntimeConfig = Object.freeze({ public: Object.freeze({}) });
|
|
19
|
+
const CapabilityRuntimeConfigContext = createContext<CapabilityRuntimeConfig>(emptyRuntimeConfig);
|
|
20
|
+
|
|
21
|
+
export function CapabilityRuntimeConfigProvider({
|
|
22
|
+
children,
|
|
23
|
+
runtimeConfig,
|
|
24
|
+
}: CapabilityRuntimeConfigProviderProps): ReactElement {
|
|
25
|
+
return createElement(CapabilityRuntimeConfigContext.Provider, { value: runtimeConfig }, children);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function useCapabilityRuntimeConfigScope<
|
|
29
|
+
T extends RuntimeConfigSection = RuntimeConfigSection,
|
|
30
|
+
>(capabilityId: string): T {
|
|
31
|
+
return getCapabilityRuntimeConfigScope<T>(useCapabilityRuntimeConfigRoot(), capabilityId);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function useCapabilityRuntimeConfig<T extends RuntimeConfigSection = RuntimeConfigSection>(
|
|
35
|
+
capabilityId: string,
|
|
36
|
+
): CapabilityRuntimeConfigFragment<T> {
|
|
37
|
+
return getCapabilityRuntimeConfig<T>(useCapabilityRuntimeConfigRoot(), capabilityId);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function useCapabilityRuntimeConfigRoot(): CapabilityRuntimeConfig {
|
|
41
|
+
return useContext(CapabilityRuntimeConfigContext);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function getCapabilityRuntimeConfigScope<
|
|
45
|
+
T extends RuntimeConfigSection = RuntimeConfigSection,
|
|
46
|
+
>(runtimeConfig: CapabilityRuntimeConfig, capabilityId: string): T {
|
|
47
|
+
const publicConfig = runtimeConfig.public[capabilityId];
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
publicConfig && typeof publicConfig === 'object' && !Array.isArray(publicConfig)
|
|
51
|
+
? publicConfig
|
|
52
|
+
: {}
|
|
53
|
+
) as T;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function getCapabilityRuntimeConfig<T extends RuntimeConfigSection = RuntimeConfigSection>(
|
|
57
|
+
runtimeConfig: CapabilityRuntimeConfig,
|
|
58
|
+
capabilityId: string,
|
|
59
|
+
): CapabilityRuntimeConfigFragment<T> {
|
|
60
|
+
return {
|
|
61
|
+
public: getCapabilityRuntimeConfigScope<T>(runtimeConfig, capabilityId),
|
|
62
|
+
};
|
|
63
|
+
}
|