@variousjs/various 6.0.0 → 6.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/README.md +1 -1
- package/dist/index.dev.js +34 -15
- package/dist/index.dev.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/loader-dev.js.map +1 -1
- package/dist/loader.js.map +1 -1
- package/dist/standalone.js +38 -35
- package/dist/standalone.js.map +1 -1
- package/dist/standalone.mjs +38 -35
- package/dist/standalone.mjs.map +1 -1
- package/dist/types/core/config.d.ts +15 -0
- package/dist/types/core/connector.d.ts +35 -0
- package/dist/types/core/create-component.d.ts +3 -0
- package/dist/types/core/create-module.d.ts +3 -0
- package/dist/types/core/default-component.d.ts +5 -0
- package/dist/types/core/dispatch.d.ts +3 -0
- package/dist/types/core/error-boundary.d.ts +18 -0
- package/dist/types/core/helper.d.ts +44 -0
- package/dist/types/core/i18n.d.ts +3 -0
- package/dist/types/core/index.d.ts +63 -0
- package/dist/types/core/logger.d.ts +3 -0
- package/dist/types/core/message.d.ts +3 -0
- package/dist/types/core/react-component.d.ts +11 -0
- package/dist/types/core/render-component.d.ts +3 -0
- package/dist/types/core/store.d.ts +22 -0
- package/dist/types/core/system.d.ts +22 -0
- package/dist/types/core/vue-component.d.ts +10 -0
- package/dist/types/loader.d.ts +1 -0
- package/dist/types/public/index.d.ts +4 -0
- package/dist/types/public/standalone.d.ts +3 -0
- package/dist/types/public/types.d.ts +272 -0
- package/dist/types/standalone/helper.d.ts +3 -0
- package/dist/types/standalone/index.d.ts +4 -0
- package/dist/types/types.d.ts +50 -0
- package/package.json +12 -11
- package/index.d.ts +0 -345
- package/standalone.d.ts +0 -56
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ModuleDef, VariousComponentType, ErrorType, ObjectRecord, GetModuleInfo, PreloadModules, RemoveLoadedModules, DefineDependencies, IsModuleLoaded, OnComponentMounted, VariousError as VariousErrorShape } from '../public/types';
|
|
2
|
+
import { RequiredComponent } from '../types';
|
|
3
|
+
import { setModule } from './system';
|
|
4
|
+
export declare const getModuleInfo: GetModuleInfo;
|
|
5
|
+
export declare const preloadModules: PreloadModules;
|
|
6
|
+
export declare const removeLoadedModules: RemoveLoadedModules;
|
|
7
|
+
export declare const defineDependencies: DefineDependencies;
|
|
8
|
+
export declare const isModuleLoaded: IsModuleLoaded;
|
|
9
|
+
export declare const isModuleSpecified: (module: ModuleDef) => boolean;
|
|
10
|
+
export declare const getMountedComponents: () => ModuleDef[];
|
|
11
|
+
export declare const onComponentMounted: OnComponentMounted;
|
|
12
|
+
export declare const resetDependencyConfig: (module: ModuleDef, url?: string) => void;
|
|
13
|
+
export declare function getConfig<C extends object = ObjectRecord>(): C;
|
|
14
|
+
export declare const onError: (e: VariousError) => void;
|
|
15
|
+
export declare class VariousError extends Error implements VariousErrorShape {
|
|
16
|
+
type: ErrorType;
|
|
17
|
+
originalError: Error;
|
|
18
|
+
module: ModuleDef;
|
|
19
|
+
constructor(data: {
|
|
20
|
+
module: ModuleDef;
|
|
21
|
+
type: ErrorType;
|
|
22
|
+
originalError: Error;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export declare function checkReactComponent(component: RequiredComponent, module: ModuleDef): Promise<void>;
|
|
26
|
+
export declare function isPromiseLike<T>(value: T | PromiseLike<T>): value is PromiseLike<T>;
|
|
27
|
+
export declare function checkVueComponent(component: RequiredComponent, module: ModuleDef): Promise<void>;
|
|
28
|
+
export declare function parseComponentActions(params: {
|
|
29
|
+
module: ModuleDef;
|
|
30
|
+
componentNode: RequiredComponent;
|
|
31
|
+
type?: VariousComponentType;
|
|
32
|
+
i18nUpdate: () => void;
|
|
33
|
+
}): () => void;
|
|
34
|
+
export declare function updateMountedComponent(module: ModuleDef): void;
|
|
35
|
+
export declare function updateUnMountComponent(module: ModuleDef): void;
|
|
36
|
+
export declare function getSelfInfo(params: {
|
|
37
|
+
url?: string;
|
|
38
|
+
module: ModuleDef;
|
|
39
|
+
}): {
|
|
40
|
+
module: string;
|
|
41
|
+
url: string;
|
|
42
|
+
};
|
|
43
|
+
export declare function getClassNameWithModule(module: ModuleDef, prefix: string): string;
|
|
44
|
+
export { setModule };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { App, Config } from '../public/types';
|
|
3
|
+
import { Store } from '../types';
|
|
4
|
+
export { default as Nycticorax } from 'nycticorax';
|
|
5
|
+
export { getUserStore as getStore } from './store';
|
|
6
|
+
export { default as createDispatch } from './dispatch';
|
|
7
|
+
export { createPostMessage } from './message';
|
|
8
|
+
export { default as createLogger } from './logger';
|
|
9
|
+
export { getConfig, preloadModules, isModuleLoaded, getMountedComponents, onComponentMounted, defineDependencies, removeLoadedModules, getModuleInfo, } from './helper';
|
|
10
|
+
export { default as createModule } from './create-module';
|
|
11
|
+
export { default as createComponent } from './create-component';
|
|
12
|
+
export { default as renderComponent } from './render-component';
|
|
13
|
+
export declare const version: string;
|
|
14
|
+
export declare const getApp: (config: Config & App<Store>) => {
|
|
15
|
+
new (props: {}): {
|
|
16
|
+
componentDidMount(): void;
|
|
17
|
+
render(): React.JSX.Element;
|
|
18
|
+
context: unknown;
|
|
19
|
+
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<{}>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
|
|
20
|
+
forceUpdate(callback?: (() => void) | undefined): void;
|
|
21
|
+
readonly props: Readonly<{}>;
|
|
22
|
+
state: Readonly<{}>;
|
|
23
|
+
refs: {
|
|
24
|
+
[key: string]: React.ReactInstance;
|
|
25
|
+
};
|
|
26
|
+
shouldComponentUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): boolean;
|
|
27
|
+
componentWillUnmount?(): void;
|
|
28
|
+
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
|
|
29
|
+
getSnapshotBeforeUpdate?(prevProps: Readonly<{}>, prevState: Readonly<{}>): any;
|
|
30
|
+
componentDidUpdate?(prevProps: Readonly<{}>, prevState: Readonly<{}>, snapshot?: any): void;
|
|
31
|
+
componentWillMount?(): void;
|
|
32
|
+
UNSAFE_componentWillMount?(): void;
|
|
33
|
+
componentWillReceiveProps?(nextProps: Readonly<{}>, nextContext: any): void;
|
|
34
|
+
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<{}>, nextContext: any): void;
|
|
35
|
+
componentWillUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): void;
|
|
36
|
+
UNSAFE_componentWillUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): void;
|
|
37
|
+
};
|
|
38
|
+
new (props: {}, context: any): {
|
|
39
|
+
componentDidMount(): void;
|
|
40
|
+
render(): React.JSX.Element;
|
|
41
|
+
context: unknown;
|
|
42
|
+
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<{}>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
|
|
43
|
+
forceUpdate(callback?: (() => void) | undefined): void;
|
|
44
|
+
readonly props: Readonly<{}>;
|
|
45
|
+
state: Readonly<{}>;
|
|
46
|
+
refs: {
|
|
47
|
+
[key: string]: React.ReactInstance;
|
|
48
|
+
};
|
|
49
|
+
shouldComponentUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): boolean;
|
|
50
|
+
componentWillUnmount?(): void;
|
|
51
|
+
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
|
|
52
|
+
getSnapshotBeforeUpdate?(prevProps: Readonly<{}>, prevState: Readonly<{}>): any;
|
|
53
|
+
componentDidUpdate?(prevProps: Readonly<{}>, prevState: Readonly<{}>, snapshot?: any): void;
|
|
54
|
+
componentWillMount?(): void;
|
|
55
|
+
UNSAFE_componentWillMount?(): void;
|
|
56
|
+
componentWillReceiveProps?(nextProps: Readonly<{}>, nextContext: any): void;
|
|
57
|
+
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<{}>, nextContext: any): void;
|
|
58
|
+
componentWillUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): void;
|
|
59
|
+
UNSAFE_componentWillUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): void;
|
|
60
|
+
};
|
|
61
|
+
displayName: string;
|
|
62
|
+
contextType?: React.Context<any> | undefined;
|
|
63
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ModuleDef } from '../public/types';
|
|
3
|
+
declare function reactComponent<P extends object>(config: {
|
|
4
|
+
module: ModuleDef;
|
|
5
|
+
url?: string;
|
|
6
|
+
watchKeys?: string[];
|
|
7
|
+
onMounted?: () => void;
|
|
8
|
+
}): React.ComponentType<{}> & {
|
|
9
|
+
[x: string]: any;
|
|
10
|
+
};
|
|
11
|
+
export default reactComponent;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ObjectRecord } from '../public/types';
|
|
2
|
+
import { Store } from '../types';
|
|
3
|
+
import { MESSAGE_KEY, MOUNTED_COMPONENTS_KEY, CONFIG_KEY, DEPENDENCIES_KEY, LOCALE_KEY, STANDALONE_CONFIG_READY } from './config';
|
|
4
|
+
export { MESSAGE_KEY, MOUNTED_COMPONENTS_KEY, CONFIG_KEY, DEPENDENCIES_KEY, LOCALE_KEY, STANDALONE_CONFIG_READY, };
|
|
5
|
+
export declare const createStore: (state: Store) => void, getStore: <K extends keyof Store | undefined = undefined>(key?: K | undefined) => K extends keyof Store ? Store[K] : Store, connect: (...keys: (keyof Store)[]) => <P extends Store>(C: import("react").ComponentType<P> & {
|
|
6
|
+
[x: string]: any;
|
|
7
|
+
}) => import("react").ComponentType<{ [P_1 in keyof P extends infer T_1 ? T_1 extends T_1 & keyof P ? T_1 extends keyof Store ? never : T_1 : never : never]: P[P_1]; }> & {
|
|
8
|
+
[x: string]: any;
|
|
9
|
+
}, emit: (next: Partial<Store>, sync?: boolean) => void, subscribe: (listener: Partial<{
|
|
10
|
+
[x: string]: (newValue: any, oldValue: any) => void;
|
|
11
|
+
[MESSAGE_KEY]: (newValue: (import("../public/types").Message<never> & {
|
|
12
|
+
timestamp: number;
|
|
13
|
+
}) | null, oldValue: (import("../public/types").Message<never> & {
|
|
14
|
+
timestamp: number;
|
|
15
|
+
}) | null) => void;
|
|
16
|
+
[MOUNTED_COMPONENTS_KEY]: (newValue: string[], oldValue: string[]) => void;
|
|
17
|
+
[CONFIG_KEY]: (newValue: Record<string | symbol, any>, oldValue: Record<string | symbol, any>) => void;
|
|
18
|
+
[DEPENDENCIES_KEY]: (newValue: Record<string, string>, oldValue: Record<string, string>) => void;
|
|
19
|
+
[STANDALONE_CONFIG_READY]?: ((newValue: boolean | undefined, oldValue: boolean | undefined) => void) | undefined;
|
|
20
|
+
[LOCALE_KEY]: (newValue: string, oldValue: string) => void;
|
|
21
|
+
}>) => () => void, dispatch: (next: import("nycticorax").Dispatch<Store>, ...params: any) => Promise<any>, useStore: (...keys: (keyof Store)[]) => Store;
|
|
22
|
+
export declare function getUserStore<S extends object = ObjectRecord>(): S;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
type Registry = {
|
|
2
|
+
modules: Map<string, any>;
|
|
3
|
+
urls: Map<string, string>;
|
|
4
|
+
loaded: Map<string, any>;
|
|
5
|
+
};
|
|
6
|
+
declare global {
|
|
7
|
+
interface Window {
|
|
8
|
+
__various?: Registry;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export declare function getRegistry(): Registry;
|
|
12
|
+
export declare function setModuleUrl(name: string, url: string): void;
|
|
13
|
+
export declare function getModuleUrl(name: string): string | undefined;
|
|
14
|
+
export declare function getAllModuleUrls(): Record<string, string>;
|
|
15
|
+
export declare function getInjectedModuleNames(): string[];
|
|
16
|
+
export declare function importModule<T = any>(name: string): Promise<T>;
|
|
17
|
+
export declare function isModuleDefined(name: string): boolean;
|
|
18
|
+
export declare function isModuleSpecified(name: string): boolean;
|
|
19
|
+
export declare function deleteModule(name: string): void;
|
|
20
|
+
export declare function setModule(name: string, mod: any): void;
|
|
21
|
+
export declare function createModuleBlobUrl(name: string): string | null;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ComponentDefaultProps, ModuleDef } from '../public/types';
|
|
3
|
+
import { CreateComponentProps } from '../types';
|
|
4
|
+
declare function vueComponent<P extends object>(config: {
|
|
5
|
+
module: ModuleDef;
|
|
6
|
+
url?: string;
|
|
7
|
+
watchKeys?: string[];
|
|
8
|
+
onMounted?: () => void;
|
|
9
|
+
}): React.FC<CreateComponentProps<P> & ComponentDefaultProps<unknown>>;
|
|
10
|
+
export default vueComponent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as Nycticorax } from 'nycticorax';
|
|
2
|
+
export type { Dispatch } from 'nycticorax';
|
|
3
|
+
export { createComponent, createModule, renderComponent, createDispatch, createPostMessage, createLogger, getConfig, getStore, getModuleInfo, preloadModules, isModuleLoaded, removeLoadedModules, getMountedComponents, onComponentMounted, defineDependencies, version, } from '../core';
|
|
4
|
+
export type { ModuleDef, ObjectRecord, VariousComponentType, ErrorType, ComponentDefaultProps, VariousError, PublicAction, DefineActions, DefineMessages, StaticMethods, ComponentStatics, DefineAppActions, Intl, I18nConfig, I18n, GlobalI18n, OnMessage, VariousProps, VariousFC, ErrorFallbackProps, ErrorFallbackNode, FallbackProps, FallbackNode, MessageEvent, DispatchEvent, LoadEvent, ErrorEvent, LogEvent, App, Config, VariousComponentProps, } from './types';
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { ComponentType, FC, ReactNode, RefObject } from 'react';
|
|
2
|
+
import { PropType } from 'vue';
|
|
3
|
+
/**
|
|
4
|
+
* module name
|
|
5
|
+
* - e.g. A.B
|
|
6
|
+
* - e.g. B
|
|
7
|
+
* - e.g. app
|
|
8
|
+
* - e.g. A.default -> A
|
|
9
|
+
*/
|
|
10
|
+
export type ModuleDef = string;
|
|
11
|
+
export type ObjectRecord<T = any> = Record<string, T>;
|
|
12
|
+
export type VariousComponentType = 'react' | 'vue3';
|
|
13
|
+
export type ErrorType = 'LOADING_ERROR' | 'SUBMODULE_LOADING_ERROR' | 'NOT_DEFINED' | 'INVALID_COMPONENT' | 'SCRIPT_ERROR' | 'APP_ERROR' | 'INVALID_MODULE' | 'SUBMODULE_NOT_DEFINED' | 'DISPATCH' | 'I18N' | (string & {});
|
|
14
|
+
export interface ComponentDefaultProps<Ref = unknown> {
|
|
15
|
+
$silent?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* for React Component only
|
|
18
|
+
*/
|
|
19
|
+
$ref?: RefObject<Ref>;
|
|
20
|
+
[k: string]: any;
|
|
21
|
+
}
|
|
22
|
+
export interface VariousError extends Error {
|
|
23
|
+
type: ErrorType;
|
|
24
|
+
originalError: Error;
|
|
25
|
+
module: ModuleDef;
|
|
26
|
+
}
|
|
27
|
+
interface ActionDef {
|
|
28
|
+
payload: any;
|
|
29
|
+
result: any;
|
|
30
|
+
}
|
|
31
|
+
interface MessageDef {
|
|
32
|
+
payload: any;
|
|
33
|
+
}
|
|
34
|
+
export type PublicAction<A extends ActionDef = never> = (params: {
|
|
35
|
+
payload: [A] extends [never] ? any : A['payload'];
|
|
36
|
+
trigger: ModuleDef;
|
|
37
|
+
}) => [A] extends [never] ? any : A['result'];
|
|
38
|
+
export type PublicActionDef = Record<string, ActionDef>;
|
|
39
|
+
export type MessagesDef = Record<string, MessageDef>;
|
|
40
|
+
export type DefineActions<T extends PublicActionDef> = T;
|
|
41
|
+
export type DefineMessages<T extends MessagesDef> = T;
|
|
42
|
+
interface Message<T extends MessagesDef = never> {
|
|
43
|
+
event: [T] extends [never] ? string : keyof T;
|
|
44
|
+
payload: [T] extends [never] ? any : T[keyof T]['payload'];
|
|
45
|
+
trigger: ModuleDef;
|
|
46
|
+
}
|
|
47
|
+
export { Message };
|
|
48
|
+
export type StaticMethods<T extends PublicActionDef = never> = [
|
|
49
|
+
T
|
|
50
|
+
] extends [never] ? Record<string, (params: {
|
|
51
|
+
payload: any;
|
|
52
|
+
trigger: ModuleDef;
|
|
53
|
+
}) => any> : {
|
|
54
|
+
[K in keyof T]: T[K] extends {
|
|
55
|
+
payload: infer V;
|
|
56
|
+
result: infer R;
|
|
57
|
+
} ? (params: {
|
|
58
|
+
payload?: V;
|
|
59
|
+
trigger: ModuleDef;
|
|
60
|
+
}) => R : never;
|
|
61
|
+
};
|
|
62
|
+
export type ComponentStatics<S extends PublicActionDef = never, T extends MessagesDef = never> = {
|
|
63
|
+
$i18n?: I18n;
|
|
64
|
+
$onMessage?: OnMessage<T>;
|
|
65
|
+
} & StaticMethods<S>;
|
|
66
|
+
export type ComponentPublicActionMap = {
|
|
67
|
+
[name: string]: PublicActionDef;
|
|
68
|
+
};
|
|
69
|
+
type $dispatch<M extends ComponentPublicActionMap = never> = [M] extends [never] ? {
|
|
70
|
+
(params: {
|
|
71
|
+
target: string;
|
|
72
|
+
action: string;
|
|
73
|
+
payload?: any;
|
|
74
|
+
}): Promise<any>;
|
|
75
|
+
} : {
|
|
76
|
+
<T extends keyof M, A extends keyof M[T]>(params: {
|
|
77
|
+
target: T;
|
|
78
|
+
action: A;
|
|
79
|
+
payload?: NonNullable<M[T][A]>['payload'];
|
|
80
|
+
}): Promise<NonNullable<M[T][A]>['result']>;
|
|
81
|
+
};
|
|
82
|
+
export type DefineAppActions<T extends PublicActionDef = {}> = DefineActions<{
|
|
83
|
+
setLocale: {
|
|
84
|
+
payload: string;
|
|
85
|
+
result: string;
|
|
86
|
+
};
|
|
87
|
+
getLocale: {
|
|
88
|
+
payload: undefined;
|
|
89
|
+
result: string;
|
|
90
|
+
};
|
|
91
|
+
updateI18nConfig: {
|
|
92
|
+
payload: Partial<I18nConfig>;
|
|
93
|
+
result: string;
|
|
94
|
+
};
|
|
95
|
+
} & T>;
|
|
96
|
+
type $postMessage<T extends MessagesDef = never> = [T] extends [never] ? (params: {
|
|
97
|
+
event: string;
|
|
98
|
+
payload?: any;
|
|
99
|
+
}) => void : <K extends keyof T>(params: {
|
|
100
|
+
event: K;
|
|
101
|
+
payload?: T[K]['payload'];
|
|
102
|
+
}) => void;
|
|
103
|
+
type $logger = {
|
|
104
|
+
info: (message: any, type?: string) => void;
|
|
105
|
+
warn: (message: any, type?: string) => void;
|
|
106
|
+
error: (message: any, type?: string) => void;
|
|
107
|
+
};
|
|
108
|
+
export type Intl = ((key: string, paramsOrDefaultText?: Record<string, string | number> | string, defaultText?: string) => string) & {
|
|
109
|
+
update: (config: Partial<I18nConfig>) => void;
|
|
110
|
+
};
|
|
111
|
+
interface ComponentBuiltinProps<Store extends object = ObjectRecord, Messages extends MessagesDef = never, Actions extends ComponentPublicActionMap = never> {
|
|
112
|
+
$store: Readonly<Store>;
|
|
113
|
+
$dispatch: $dispatch<Actions>;
|
|
114
|
+
$postMessage: $postMessage<Messages>;
|
|
115
|
+
$t: Intl;
|
|
116
|
+
$logger: $logger;
|
|
117
|
+
$self: {
|
|
118
|
+
url: string;
|
|
119
|
+
module: ModuleDef;
|
|
120
|
+
};
|
|
121
|
+
$locale: string;
|
|
122
|
+
}
|
|
123
|
+
export interface I18nConfig {
|
|
124
|
+
resources: Record<string, Record<string, string>>;
|
|
125
|
+
}
|
|
126
|
+
export type I18n = () => I18nConfig | Promise<I18nConfig>;
|
|
127
|
+
export type GlobalI18n = {
|
|
128
|
+
defaultLocale?: string;
|
|
129
|
+
getResources?: () => I18nConfig | Promise<I18nConfig>;
|
|
130
|
+
};
|
|
131
|
+
export type OnMessage<T extends MessagesDef = never> = (message: Message<T>) => void;
|
|
132
|
+
export type VariousProps<Props extends object = ObjectRecord, Store extends object = ObjectRecord, Messages extends MessagesDef = never, Actions extends ComponentPublicActionMap = never> = ComponentBuiltinProps<Store, Messages, Actions> & Props;
|
|
133
|
+
export type VariousFC<Props extends object = ObjectRecord, Store extends object = ObjectRecord, SelfActions extends PublicActionDef = never, Messages extends MessagesDef = never, Actions extends ComponentPublicActionMap = never> = FC<VariousProps<Props, Store, Messages, Actions>> & ComponentStatics<SelfActions, Messages>;
|
|
134
|
+
export interface ErrorFallbackProps<Store extends object = ObjectRecord> {
|
|
135
|
+
$reload: () => void;
|
|
136
|
+
$error: VariousError;
|
|
137
|
+
$store: Readonly<Store>;
|
|
138
|
+
$self: {
|
|
139
|
+
url: string;
|
|
140
|
+
module: ModuleDef;
|
|
141
|
+
};
|
|
142
|
+
$locale: string;
|
|
143
|
+
}
|
|
144
|
+
export type ErrorFallbackNode<Store extends object = ObjectRecord> = ComponentType<ErrorFallbackProps<Store>>;
|
|
145
|
+
export interface FallbackProps<Store extends object = ObjectRecord> {
|
|
146
|
+
$store: Readonly<Store>;
|
|
147
|
+
$self: {
|
|
148
|
+
url: string;
|
|
149
|
+
module: ModuleDef;
|
|
150
|
+
};
|
|
151
|
+
$locale: string;
|
|
152
|
+
}
|
|
153
|
+
export type FallbackNode<Store extends object = ObjectRecord> = ComponentType<FallbackProps<Store>>;
|
|
154
|
+
type Dispatch<T extends object = ObjectRecord> = (nycticorax: {
|
|
155
|
+
getStore: <K extends keyof T | undefined = undefined>(k?: K | undefined) => K extends keyof T ? T[K] : T;
|
|
156
|
+
emit: (next: Partial<T>) => void;
|
|
157
|
+
}, payload: any, trigger: ModuleDef) => Promise<any>;
|
|
158
|
+
interface MessageEventArgs {
|
|
159
|
+
trigger: ModuleDef;
|
|
160
|
+
event: string;
|
|
161
|
+
payload?: any;
|
|
162
|
+
}
|
|
163
|
+
type MessageEventRes = boolean | Omit<MessageEventArgs, 'trigger'>;
|
|
164
|
+
interface DispatchEventArgs {
|
|
165
|
+
target: ModuleDef;
|
|
166
|
+
trigger: ModuleDef;
|
|
167
|
+
action: string;
|
|
168
|
+
payload?: any;
|
|
169
|
+
}
|
|
170
|
+
type DispatchEventRes = boolean | Omit<DispatchEventArgs, 'trigger'>;
|
|
171
|
+
interface LoadEventArgs {
|
|
172
|
+
module: ModuleDef;
|
|
173
|
+
loadStart: number;
|
|
174
|
+
loadEnd: number;
|
|
175
|
+
beenLoaded: boolean;
|
|
176
|
+
}
|
|
177
|
+
type LogLevel = 'info' | 'warn' | 'error';
|
|
178
|
+
interface LogArgs {
|
|
179
|
+
module: ModuleDef;
|
|
180
|
+
level: LogLevel;
|
|
181
|
+
type?: string;
|
|
182
|
+
message: any;
|
|
183
|
+
}
|
|
184
|
+
export type MessageEvent = (e: MessageEventArgs) => Promise<MessageEventRes> | MessageEventRes;
|
|
185
|
+
export type DispatchEvent = (e: DispatchEventArgs) => Promise<DispatchEventRes> | DispatchEventRes;
|
|
186
|
+
export type LoadEvent = (e: LoadEventArgs) => void;
|
|
187
|
+
export type ErrorEvent = (e: VariousError) => void;
|
|
188
|
+
export type LogEvent = (e: LogArgs) => boolean;
|
|
189
|
+
export interface App<Store extends object = ObjectRecord> {
|
|
190
|
+
store?: Store;
|
|
191
|
+
ErrorFallback?: ErrorFallbackNode<Store>;
|
|
192
|
+
Fallback?: FallbackNode<Store>;
|
|
193
|
+
actions?: Record<string, Dispatch<Store>>;
|
|
194
|
+
Root: ComponentType;
|
|
195
|
+
middlewares?: {
|
|
196
|
+
onLoad?: LoadEvent;
|
|
197
|
+
onError?: ErrorEvent;
|
|
198
|
+
onMessage?: MessageEvent;
|
|
199
|
+
onDispatch?: DispatchEvent;
|
|
200
|
+
onLog?: LogEvent;
|
|
201
|
+
};
|
|
202
|
+
i18n?: GlobalI18n;
|
|
203
|
+
}
|
|
204
|
+
export interface Config {
|
|
205
|
+
dependencies: {
|
|
206
|
+
app: string;
|
|
207
|
+
'@variousjs/various'?: string;
|
|
208
|
+
react?: string;
|
|
209
|
+
'react-dom'?: string;
|
|
210
|
+
vue?: string;
|
|
211
|
+
} & Record<string, string>;
|
|
212
|
+
root?: string;
|
|
213
|
+
timeout?: number;
|
|
214
|
+
earlyParallelDependencies?: string[];
|
|
215
|
+
}
|
|
216
|
+
export type VariousComponentProps<Store extends object = ObjectRecord, Messages extends MessagesDef = never, Actions extends ComponentPublicActionMap = never> = PropType<ComponentBuiltinProps<Store, Messages, Actions>>;
|
|
217
|
+
export type GetModuleInfo = (module: ModuleDef) => {
|
|
218
|
+
name: string;
|
|
219
|
+
entry?: string;
|
|
220
|
+
};
|
|
221
|
+
export type PreloadModules = (modules: ModuleDef[]) => Promise<void>;
|
|
222
|
+
export type RemoveLoadedModules = (modules: ModuleDef[]) => void;
|
|
223
|
+
export type DefineDependencies = (deps: Record<string, string>) => void;
|
|
224
|
+
export type IsModuleLoaded = (module: ModuleDef) => boolean;
|
|
225
|
+
export type OnComponentMounted = (module: ModuleDef | ModuleDef[], callback: () => void) => (() => void) | void;
|
|
226
|
+
export type CreateDispatch = <M extends ComponentPublicActionMap = never>(module: ModuleDef) => $dispatch<M>;
|
|
227
|
+
export type CreatePostMessage = <Messages extends MessagesDef = never>(module: ModuleDef) => $postMessage<Messages>;
|
|
228
|
+
export type CreateLogger = (module: ModuleDef) => $logger;
|
|
229
|
+
export type GetStore = <Store extends object = ObjectRecord>() => Store;
|
|
230
|
+
export type CreateModule = <T = unknown>(params: {
|
|
231
|
+
url?: string;
|
|
232
|
+
module: ModuleDef;
|
|
233
|
+
}, logError?: boolean) => Promise<T>;
|
|
234
|
+
export type CreateComponent = <Props extends object = ObjectRecord, Ref = unknown, Store extends object = ObjectRecord>(config: {
|
|
235
|
+
url?: string;
|
|
236
|
+
type?: VariousComponentType;
|
|
237
|
+
module: ModuleDef;
|
|
238
|
+
},
|
|
239
|
+
/**
|
|
240
|
+
* set store keys if component created before store initialization
|
|
241
|
+
*/
|
|
242
|
+
storeKeys?: (keyof Store)[]) => ComponentType<ComponentDefaultProps<Ref> & Props>;
|
|
243
|
+
export type RenderComponent = <Props extends object = ObjectRecord>(params: {
|
|
244
|
+
module: ModuleDef;
|
|
245
|
+
url?: string;
|
|
246
|
+
type?: VariousComponentType;
|
|
247
|
+
props?: Props & ComponentDefaultProps;
|
|
248
|
+
target: Element | null;
|
|
249
|
+
renderNode?: (children: ReactNode) => ReactNode;
|
|
250
|
+
onMounted?: () => void;
|
|
251
|
+
}) => Promise<() => Promise<void>>;
|
|
252
|
+
export type DependencyType = string | object | Function;
|
|
253
|
+
export type StandaloneComponentConfig<Store extends object = ObjectRecord> = {
|
|
254
|
+
module: ModuleDef;
|
|
255
|
+
url?: string;
|
|
256
|
+
type?: VariousComponentType;
|
|
257
|
+
dependencies?: Partial<Record<string, DependencyType>>;
|
|
258
|
+
/**
|
|
259
|
+
* set store keys if component created before store initialization
|
|
260
|
+
*/
|
|
261
|
+
storeKeys?: (keyof Store)[];
|
|
262
|
+
};
|
|
263
|
+
export type StandaloneCreateComponent = <Props extends object = ObjectRecord, Ref = unknown, Store extends object = ObjectRecord>(config: StandaloneComponentConfig<Store>) => ComponentType<Props & {
|
|
264
|
+
/**
|
|
265
|
+
* for React Component only
|
|
266
|
+
*/
|
|
267
|
+
$ref?: RefObject<Ref>;
|
|
268
|
+
}>;
|
|
269
|
+
export type AppConfig<Store extends object = ObjectRecord> = Pick<App<Store>, 'actions' | 'store' | 'Fallback' | 'ErrorFallback' | 'i18n'> & {
|
|
270
|
+
dependencies: Partial<Record<string, DependencyType>>;
|
|
271
|
+
};
|
|
272
|
+
export type CreateAppConfig = <Store extends object = ObjectRecord>(config: AppConfig<Store>) => void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React, { ComponentType, ReactNode } from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom/client';
|
|
3
|
+
import type { Dispatch } from 'nycticorax';
|
|
4
|
+
import type { VariousProps, PublicAction, Config, OnMessage, I18n, ModuleDef, App, I18nConfig } from './public/types';
|
|
5
|
+
import { MESSAGE_KEY, DEPENDENCIES_KEY, MOUNTED_COMPONENTS_KEY, CONFIG_KEY, STANDALONE_CONFIG_READY, LOCALE_KEY } from './core/config';
|
|
6
|
+
export { MESSAGE_KEY, DEPENDENCIES_KEY, MOUNTED_COMPONENTS_KEY, CONFIG_KEY, STANDALONE_CONFIG_READY, LOCALE_KEY, };
|
|
7
|
+
export interface Store {
|
|
8
|
+
[MESSAGE_KEY]: null | (Parameters<OnMessage>[0] & {
|
|
9
|
+
timestamp: number;
|
|
10
|
+
});
|
|
11
|
+
[MOUNTED_COMPONENTS_KEY]: ModuleDef[];
|
|
12
|
+
[CONFIG_KEY]: Record<string | symbol, any>;
|
|
13
|
+
[DEPENDENCIES_KEY]: Record<string, string>;
|
|
14
|
+
[STANDALONE_CONFIG_READY]?: boolean;
|
|
15
|
+
[LOCALE_KEY]: string;
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}
|
|
18
|
+
export type Actions<S extends object> = Record<string, Dispatch<S>>;
|
|
19
|
+
export type PublicActions = Record<string, PublicAction>;
|
|
20
|
+
export type RequiredComponent = ComponentType<VariousProps> & Actions<Store> & PublicActions & {
|
|
21
|
+
$onMessage: OnMessage;
|
|
22
|
+
$i18n: I18n;
|
|
23
|
+
} & {
|
|
24
|
+
[key: string]: RequiredComponent;
|
|
25
|
+
};
|
|
26
|
+
export interface CreateComponentState {
|
|
27
|
+
isError: boolean;
|
|
28
|
+
componentReady: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface CreateComponentProps<P extends object> extends Store {
|
|
31
|
+
$componentProps: P;
|
|
32
|
+
}
|
|
33
|
+
export type ErrorBoundaryProps = {
|
|
34
|
+
module: ModuleDef;
|
|
35
|
+
url?: string;
|
|
36
|
+
children: ReactNode;
|
|
37
|
+
};
|
|
38
|
+
export interface ConnectorI18nConfig extends I18nConfig {
|
|
39
|
+
loading?: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface Various {
|
|
42
|
+
getApp: (config: Config & App) => ComponentType;
|
|
43
|
+
}
|
|
44
|
+
export type AppWithDefault = {
|
|
45
|
+
default: App;
|
|
46
|
+
};
|
|
47
|
+
export type ReactType = typeof React;
|
|
48
|
+
export type ReactDOMType = typeof ReactDOM & {
|
|
49
|
+
version: string;
|
|
50
|
+
};
|
package/package.json
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@variousjs/various",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "ESM micro-frontend framework",
|
|
5
|
+
"description": "React-based ESM micro-frontend framework",
|
|
6
6
|
"files": [
|
|
7
|
-
"dist"
|
|
8
|
-
"index.d.ts",
|
|
9
|
-
"standalone.d.ts"
|
|
7
|
+
"dist"
|
|
10
8
|
],
|
|
11
9
|
"exports": {
|
|
12
10
|
".": {
|
|
13
11
|
"import": {
|
|
14
|
-
"types": "./index.d.ts",
|
|
12
|
+
"types": "./dist/types/public/index.d.ts",
|
|
15
13
|
"default": "./dist/index.js"
|
|
16
14
|
}
|
|
17
15
|
},
|
|
18
16
|
"./standalone": {
|
|
19
17
|
"import": {
|
|
20
|
-
"types": "./standalone.d.ts",
|
|
18
|
+
"types": "./dist/types/public/standalone.d.ts",
|
|
21
19
|
"default": "./dist/standalone.mjs"
|
|
22
20
|
},
|
|
23
21
|
"require": {
|
|
24
|
-
"types": "./standalone.d.ts",
|
|
22
|
+
"types": "./dist/types/public/standalone.d.ts",
|
|
25
23
|
"default": "./dist/standalone.js"
|
|
26
24
|
}
|
|
27
25
|
}
|
|
@@ -57,9 +55,11 @@
|
|
|
57
55
|
"build:standalone": "TARGET=standalone vite build --mode development",
|
|
58
56
|
"build:standalone:esm": "TARGET=standalone-esm vite build --mode development",
|
|
59
57
|
"build:components": "TARGET=components vite build",
|
|
60
|
-
"build": "
|
|
58
|
+
"build:types": "tsc -p tsconfig.types.json",
|
|
59
|
+
"check:types": "vue-tsc -p tsconfig.consumer-check.json",
|
|
60
|
+
"build": "npm run build:core && npm run build:core:dev && npm run build:loader && npm run build:loader:dev && npm run build:standalone && npm run build:standalone:esm && npm run build:components && npm run build:types",
|
|
61
61
|
"prebuild": "npm run lint && rm -rf dist && rm -rf public/dist && mkdir -p public/dist",
|
|
62
|
-
"postbuild": "npm run create-empty",
|
|
62
|
+
"postbuild": "npm run create-empty && npm run check:types",
|
|
63
63
|
"prepublishOnly": "npm run build",
|
|
64
64
|
"cy:run": "rm -rf .nyc_output coverage && cypress run",
|
|
65
65
|
"ci": "start-server-and-test start:ci http://127.0.0.1:2333 cy:run",
|
|
@@ -104,7 +104,8 @@
|
|
|
104
104
|
"typescript": "^5.9.3",
|
|
105
105
|
"vite": "^8.1.5",
|
|
106
106
|
"vite-plugin-istanbul": "^9.0.1",
|
|
107
|
-
"vue": "^3.5.40"
|
|
107
|
+
"vue": "^3.5.40",
|
|
108
|
+
"vue-tsc": "^3.3.11"
|
|
108
109
|
},
|
|
109
110
|
"dependencies": {
|
|
110
111
|
"nycticorax": "^4.2.1"
|