@variousjs/various 4.2.0 → 5.0.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/index.dev.js +1741 -0
- package/dist/index.dev.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/loader.js +1 -1
- package/dist/loader.js.map +1 -1
- package/index.d.ts +78 -36
- package/package.json +8 -4
package/index.d.ts
CHANGED
|
@@ -5,6 +5,12 @@ declare module '@variousjs/various' {
|
|
|
5
5
|
|
|
6
6
|
export { default as Nycticorax, Dispatch } from 'nycticorax'
|
|
7
7
|
|
|
8
|
+
export interface ModuleDefined { name: string, module?: string }
|
|
9
|
+
|
|
10
|
+
export type ObjectRecord<T = any> = Record<string, T>
|
|
11
|
+
|
|
12
|
+
export type VariousComponentType = 'react' | 'vue3'
|
|
13
|
+
|
|
8
14
|
export type ErrorType =
|
|
9
15
|
'LOADING_ERROR' |
|
|
10
16
|
'SUBMODULE_LOADING_ERROR' |
|
|
@@ -16,24 +22,24 @@ declare module '@variousjs/various' {
|
|
|
16
22
|
'SUBMODULE_NOT_DEFINED' |
|
|
17
23
|
'SUBMODULE_SCRIPT_ERROR' |
|
|
18
24
|
'DISPATCH' |
|
|
19
|
-
'I18N'
|
|
25
|
+
'I18N' | (string & {})
|
|
20
26
|
|
|
21
27
|
export interface ComponentDefaultProps {
|
|
22
28
|
$silent?: boolean,
|
|
29
|
+
/**
|
|
30
|
+
* for React Component only
|
|
31
|
+
*/
|
|
23
32
|
$ref?: RefObject<unknown>,
|
|
33
|
+
[k: string]: any,
|
|
24
34
|
}
|
|
25
35
|
|
|
26
36
|
export interface VariousError extends Error {
|
|
27
37
|
type: ErrorType,
|
|
28
38
|
originalError: Error,
|
|
29
|
-
module?:
|
|
30
|
-
name:
|
|
39
|
+
module?: ModuleDefined['module'],
|
|
40
|
+
name: ModuleDefined['name'],
|
|
31
41
|
}
|
|
32
42
|
|
|
33
|
-
type ObjectAny = Record<string, any>
|
|
34
|
-
|
|
35
|
-
export interface ModuleDefined { name: string, module?: string }
|
|
36
|
-
|
|
37
43
|
interface Message { event: string, value: any, trigger: ModuleDefined }
|
|
38
44
|
|
|
39
45
|
type $dispatch = (args: ModuleDefined & {
|
|
@@ -42,17 +48,30 @@ declare module '@variousjs/various' {
|
|
|
42
48
|
}) => Promise<any>
|
|
43
49
|
type $postMessage = (event: string, value?: any) => void
|
|
44
50
|
|
|
45
|
-
|
|
51
|
+
interface $logger {
|
|
52
|
+
info: (message: any, type?: string) => void,
|
|
53
|
+
warn: (message: any, type?: string) => void,
|
|
54
|
+
error: (message: any, type?: string) => void,
|
|
55
|
+
}
|
|
46
56
|
|
|
47
|
-
export type
|
|
57
|
+
export type Intl = ((
|
|
58
|
+
key: string,
|
|
59
|
+
paramsOrDefaultText?: Record<string, string | number> | string,
|
|
60
|
+
defaultText?: string,
|
|
61
|
+
) => string) & {
|
|
62
|
+
update: (config: Partial<I18nConfig>, type?: 'app') => void,
|
|
63
|
+
}
|
|
48
64
|
|
|
49
65
|
export type PublicAction = (value: any, trigger: ModuleDefined) => any
|
|
50
66
|
|
|
51
|
-
export
|
|
52
|
-
|
|
67
|
+
export interface I18nConfig {
|
|
68
|
+
/** app store key */
|
|
69
|
+
lngStoreKey: string,
|
|
53
70
|
resources: Record<string, Record<string, string>>,
|
|
54
71
|
}
|
|
55
72
|
|
|
73
|
+
export type I18n = () => I18nConfig | Promise<I18nConfig>
|
|
74
|
+
|
|
56
75
|
export type OnMessage = (message: Message) => void
|
|
57
76
|
|
|
58
77
|
export interface StaticProps {
|
|
@@ -62,13 +81,14 @@ declare module '@variousjs/various' {
|
|
|
62
81
|
}
|
|
63
82
|
|
|
64
83
|
export type ComponentProps<
|
|
65
|
-
S extends object =
|
|
66
|
-
P extends object =
|
|
84
|
+
S extends object = ObjectRecord,
|
|
85
|
+
P extends object = ObjectRecord
|
|
67
86
|
> = {
|
|
68
87
|
$store: Readonly<S>,
|
|
69
88
|
$dispatch: $dispatch,
|
|
70
89
|
$postMessage: $postMessage,
|
|
71
90
|
$t: Intl,
|
|
91
|
+
$logger: $logger,
|
|
72
92
|
} & P
|
|
73
93
|
|
|
74
94
|
export type ComponentNode<
|
|
@@ -76,23 +96,23 @@ declare module '@variousjs/various' {
|
|
|
76
96
|
P extends object = {}
|
|
77
97
|
> = FC<ComponentProps<S, P>> & StaticProps
|
|
78
98
|
|
|
79
|
-
export interface ErrorNodeProps<S extends object =
|
|
80
|
-
$reload
|
|
99
|
+
export interface ErrorNodeProps<S extends object = ObjectRecord> {
|
|
100
|
+
$reload: () => void,
|
|
81
101
|
$error: VariousError,
|
|
82
102
|
$store: Readonly<S>,
|
|
83
|
-
$name:
|
|
84
|
-
$module?:
|
|
103
|
+
$name: ModuleDefined['name'],
|
|
104
|
+
$module?: ModuleDefined['module'],
|
|
85
105
|
}
|
|
86
|
-
export type ErrorNode<S extends object =
|
|
106
|
+
export type ErrorNode<S extends object = ObjectRecord> = ComponentType<ErrorNodeProps<S>>
|
|
87
107
|
|
|
88
|
-
export interface LoaderNodeProps<S extends object =
|
|
108
|
+
export interface LoaderNodeProps<S extends object = ObjectRecord> {
|
|
89
109
|
$store: Readonly<S>,
|
|
90
|
-
$name:
|
|
91
|
-
$module?:
|
|
110
|
+
$name: ModuleDefined['name'],
|
|
111
|
+
$module?: ModuleDefined['module'],
|
|
92
112
|
}
|
|
93
|
-
export type LoaderNode<S extends object =
|
|
113
|
+
export type LoaderNode<S extends object = ObjectRecord> = ComponentType<LoaderNodeProps<S>>
|
|
94
114
|
|
|
95
|
-
type Dispatch<T extends object =
|
|
115
|
+
type Dispatch<T extends object = ObjectRecord> = (
|
|
96
116
|
nycticorax: {
|
|
97
117
|
getStore: <K extends keyof T | undefined = undefined>(k?: K | undefined) =>
|
|
98
118
|
K extends keyof T ? T[K] : T,
|
|
@@ -121,12 +141,20 @@ declare module '@variousjs/various' {
|
|
|
121
141
|
beenLoaded: boolean,
|
|
122
142
|
}
|
|
123
143
|
|
|
144
|
+
type LogLevel = 'info' | 'warn' | 'error'
|
|
145
|
+
interface LogArgs extends ModuleDefined {
|
|
146
|
+
level: LogLevel,
|
|
147
|
+
type?: string,
|
|
148
|
+
message: any,
|
|
149
|
+
}
|
|
150
|
+
|
|
124
151
|
export type MessageEvent = (e: MessageEventArgs) => Promise<MessageEventRes> | MessageEventRes
|
|
125
152
|
export type DispatchEvent = (e: DispatchEventArgs) => Promise<DispatchEventRes> | DispatchEventRes
|
|
126
153
|
export type LoadEvent = (e: LoadEventArgs) => void
|
|
127
154
|
export type ErrorEvent = (e: VariousError) => void
|
|
155
|
+
export type LogEvent = (e: LogArgs) => boolean
|
|
128
156
|
|
|
129
|
-
export interface App<S extends object =
|
|
157
|
+
export interface App<S extends object = ObjectRecord> {
|
|
130
158
|
store?: readonly S,
|
|
131
159
|
Error?: ErrorNode<S>,
|
|
132
160
|
Loader?: LoaderNode<S>,
|
|
@@ -137,53 +165,67 @@ declare module '@variousjs/various' {
|
|
|
137
165
|
onError?: ErrorEvent,
|
|
138
166
|
onMessage?: MessageEvent,
|
|
139
167
|
onDispatch?: DispatchEvent,
|
|
168
|
+
onLog?: LogEvent,
|
|
140
169
|
},
|
|
170
|
+
i18n?: I18n,
|
|
141
171
|
}
|
|
142
172
|
|
|
143
173
|
export interface Config {
|
|
144
174
|
dependencies: {
|
|
145
175
|
app: string,
|
|
146
176
|
'@variousjs/various'?: string,
|
|
177
|
+
react?: string,
|
|
178
|
+
'react-dom'?: string,
|
|
179
|
+
vue?: string,
|
|
147
180
|
[x: string]: string,
|
|
148
181
|
},
|
|
149
182
|
root?: string,
|
|
150
|
-
env?: ENV,
|
|
151
183
|
timeout?: number,
|
|
152
184
|
earlyParallelDependencies?: string[],
|
|
153
185
|
}
|
|
154
186
|
|
|
155
187
|
export function createComponent<
|
|
156
|
-
S extends object =
|
|
157
|
-
P extends object =
|
|
188
|
+
S extends object = ObjectRecord,
|
|
189
|
+
P extends object = ObjectRecord
|
|
158
190
|
>(
|
|
159
|
-
config: ModuleDefined & { url?: string },
|
|
191
|
+
config: ModuleDefined & { url?: string, type?: VariousComponentType },
|
|
160
192
|
storeKeys?: (keyof S)[],
|
|
161
193
|
): ComponentType<ComponentDefaultProps & P>
|
|
162
194
|
|
|
163
195
|
export function createModule<T = unknown> (params: ModuleDefined & {
|
|
164
196
|
url?: string,
|
|
165
|
-
}): Promise<T>
|
|
197
|
+
}, logError?: boolean): Promise<T>
|
|
166
198
|
|
|
167
|
-
export function renderComponent<P extends object =
|
|
199
|
+
export function renderComponent<P extends object = ObjectRecord>(params: ModuleDefined & {
|
|
168
200
|
url?: string,
|
|
201
|
+
type?: VariousComponentType,
|
|
169
202
|
props?: P & ComponentDefaultProps,
|
|
170
203
|
target: Element | null,
|
|
171
204
|
renderNode?: (children: ReactNode) => ReactNode,
|
|
172
205
|
onMounted?: () => void,
|
|
173
206
|
}): () => Promise<void>
|
|
174
207
|
|
|
175
|
-
export
|
|
208
|
+
export interface VueVarious<S extends object = ObjectRecord> {
|
|
209
|
+
$dispatch: $dispatch,
|
|
210
|
+
$logger: $logger,
|
|
211
|
+
$postMessage: $postMessage,
|
|
212
|
+
$t: Intl,
|
|
213
|
+
$store: Readonly<S>,
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export const isModuleLoaded: (name: string) => boolean
|
|
176
217
|
export const getMountedComponents: () => ModuleDefined[]
|
|
177
|
-
export const
|
|
218
|
+
export const preloadModules: (name: string | string[]) => Promise<void>
|
|
178
219
|
export const onComponentMounted: (
|
|
179
220
|
name: ModuleDefined | ModuleDefined[], callback: () => void
|
|
180
|
-
) => () => void
|
|
221
|
+
) => (() => void) | void
|
|
181
222
|
export const defineDependencies: (deps: Record<string, string>) => void
|
|
182
223
|
|
|
183
|
-
export const
|
|
184
|
-
export function getConfig<C extends object =
|
|
185
|
-
export function getStore<S extends object =
|
|
224
|
+
export const version: string
|
|
225
|
+
export function getConfig<C extends object = ObjectRecord>(): C
|
|
226
|
+
export function getStore<S extends object = ObjectRecord>(): S
|
|
186
227
|
|
|
187
228
|
export const createDispatch: (m: ModuleDefined) => $dispatch
|
|
188
229
|
export const createPostMessage: (m: ModuleDefined) => $postMessage
|
|
230
|
+
export const createLogger: (m: ModuleDefined) => $logger
|
|
189
231
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@variousjs/various",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "RequireJS(AMD) + React",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -19,10 +19,11 @@
|
|
|
19
19
|
"types": "index.d.ts",
|
|
20
20
|
"scripts": {
|
|
21
21
|
"lint": "tsc --noemit && eslint . --ext .ts,.tsx,.js",
|
|
22
|
-
"prestart": "mkdir -p
|
|
22
|
+
"prestart": "mkdir -p docs/dist && touch docs/dist/empty.js",
|
|
23
23
|
"start": "webpack --config webpack/components.js --progress & webpack serve --config webpack/index.js --progress --no-client-overlay",
|
|
24
|
-
"prebuild": "npm run lint",
|
|
25
|
-
"build": "
|
|
24
|
+
"prebuild": "npm run lint && rm -rf dist && rm -rf docs/dist",
|
|
25
|
+
"build": "NODE_ENV=production webpack --config webpack/components.js --progress && NODE_ENV=production webpack --config webpack/index.js --progress",
|
|
26
|
+
"postbuild": "cp dist/* docs/dist/ && touch docs/dist/empty.js",
|
|
26
27
|
"cy:run": "rm -rf .nyc_output && cypress run",
|
|
27
28
|
"ci": "start-server-and-test start http://127.0.0.1:2333 cy:run",
|
|
28
29
|
"cypress": "cypress open"
|
|
@@ -56,6 +57,7 @@
|
|
|
56
57
|
"@types/requirejs": "^2.1.34",
|
|
57
58
|
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
58
59
|
"@typescript-eslint/parser": "^4.33.0",
|
|
60
|
+
"@vue/compiler-sfc": "^3.5.22",
|
|
59
61
|
"babel-loader": "^8.2.5",
|
|
60
62
|
"babel-plugin-istanbul": "^6.1.1",
|
|
61
63
|
"cypress": "^9.7.0",
|
|
@@ -69,6 +71,8 @@
|
|
|
69
71
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
70
72
|
"start-server-and-test": "^2.0.3",
|
|
71
73
|
"typescript": "^4.9.5",
|
|
74
|
+
"vue": "^3.5.21",
|
|
75
|
+
"vue-loader": "^17.3.1",
|
|
72
76
|
"webpack": "^5.101.0",
|
|
73
77
|
"webpack-bundle-analyzer": "^4.6.1",
|
|
74
78
|
"webpack-cli": "^4.10.0",
|