@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
package/index.d.ts
DELETED
|
@@ -1,345 +0,0 @@
|
|
|
1
|
-
declare module '@variousjs/various' {
|
|
2
|
-
import {
|
|
3
|
-
ComponentType, FC, ReactNode, RefObject,
|
|
4
|
-
} from 'react'
|
|
5
|
-
import { PropType } from 'vue'
|
|
6
|
-
|
|
7
|
-
export { default as Nycticorax, Dispatch } from 'nycticorax'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* module name
|
|
11
|
-
* - e.g. A.B
|
|
12
|
-
* - e.g. B
|
|
13
|
-
* - e.g. app
|
|
14
|
-
* - e.g. A.default -> A
|
|
15
|
-
*/
|
|
16
|
-
export type ModuleDef = string
|
|
17
|
-
|
|
18
|
-
export type ObjectRecord<T = any> = Record<string, T>
|
|
19
|
-
|
|
20
|
-
export type VariousComponentType = 'react' | 'vue3'
|
|
21
|
-
|
|
22
|
-
export type ErrorType =
|
|
23
|
-
'LOADING_ERROR' |
|
|
24
|
-
'SUBMODULE_LOADING_ERROR' |
|
|
25
|
-
'NOT_DEFINED' |
|
|
26
|
-
'INVALID_COMPONENT' |
|
|
27
|
-
'SCRIPT_ERROR' |
|
|
28
|
-
'APP_ERROR' |
|
|
29
|
-
'INVALID_MODULE' |
|
|
30
|
-
'SUBMODULE_NOT_DEFINED' |
|
|
31
|
-
'DISPATCH' |
|
|
32
|
-
'I18N' | (string & {})
|
|
33
|
-
|
|
34
|
-
export interface ComponentDefaultProps<Ref = unknown> {
|
|
35
|
-
$silent?: boolean,
|
|
36
|
-
/**
|
|
37
|
-
* for React Component only
|
|
38
|
-
*/
|
|
39
|
-
$ref?: RefObject<Ref>,
|
|
40
|
-
[k: string]: any,
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface VariousError extends Error {
|
|
44
|
-
type: ErrorType,
|
|
45
|
-
originalError: Error,
|
|
46
|
-
module: ModuleDef,
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
interface ActionDef {
|
|
50
|
-
payload: any,
|
|
51
|
-
result: any,
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
interface MessageDef {
|
|
55
|
-
payload: any,
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export type PublicAction<A extends ActionDef = never> = (params: {
|
|
59
|
-
payload: [A] extends [never] ? any : A['payload'],
|
|
60
|
-
trigger: ModuleDef,
|
|
61
|
-
}) => [A] extends [never] ? any : A['result']
|
|
62
|
-
|
|
63
|
-
type PublicActionDef = Record<string, ActionDef>
|
|
64
|
-
|
|
65
|
-
type MessagesDef = Record<string, MessageDef>
|
|
66
|
-
|
|
67
|
-
export type DefineActions<T extends PublicActionDef> = T
|
|
68
|
-
|
|
69
|
-
export type DefineMessages<T extends MessagesDef> = T
|
|
70
|
-
|
|
71
|
-
interface Message<T extends MessagesDef = never> {
|
|
72
|
-
event: [T] extends [never] ? string : keyof T,
|
|
73
|
-
payload: [T] extends [never] ? any : T[keyof T]['payload'],
|
|
74
|
-
trigger: ModuleDef,
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export type StaticMethods<T extends PublicActionDef = never> =
|
|
78
|
-
[T] extends [never]
|
|
79
|
-
? Record<string, (params: { payload: any, trigger: ModuleDef }) => any>
|
|
80
|
-
: {
|
|
81
|
-
[K in keyof T]: T[K] extends { payload: infer V, result: infer R }
|
|
82
|
-
? (params: { payload?: V, trigger: ModuleDef }) => R
|
|
83
|
-
: never
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export type ComponentStatics<S extends PublicActionDef = never, T extends MessagesDef = never> = {
|
|
87
|
-
$i18n?: I18n,
|
|
88
|
-
$onMessage?: OnMessage<T>,
|
|
89
|
-
} & StaticMethods<S>
|
|
90
|
-
|
|
91
|
-
type ComponentPublicActionMap = {
|
|
92
|
-
[name: string]: PublicActionDef,
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
type $dispatch<M extends ComponentPublicActionMap = never> = [M] extends [never]
|
|
96
|
-
? {
|
|
97
|
-
(params: {
|
|
98
|
-
target: string,
|
|
99
|
-
action: string,
|
|
100
|
-
payload?: any,
|
|
101
|
-
}): Promise<any>
|
|
102
|
-
}
|
|
103
|
-
: {
|
|
104
|
-
<T extends keyof M, A extends keyof M[T]>(
|
|
105
|
-
params: {
|
|
106
|
-
target: T,
|
|
107
|
-
action: A,
|
|
108
|
-
payload?: M[T][A]['payload'],
|
|
109
|
-
}
|
|
110
|
-
): Promise<M[T][A]['result']>
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export type DefineAppActions<T extends PublicActionDef = {}> = DefineActions<{
|
|
114
|
-
setLocale: {
|
|
115
|
-
payload: string,
|
|
116
|
-
result: string,
|
|
117
|
-
},
|
|
118
|
-
getLocale: {
|
|
119
|
-
payload: undefined,
|
|
120
|
-
result: string,
|
|
121
|
-
},
|
|
122
|
-
updateI18nConfig: {
|
|
123
|
-
payload: Partial<I18nConfig>,
|
|
124
|
-
result: string,
|
|
125
|
-
},
|
|
126
|
-
} & T>
|
|
127
|
-
|
|
128
|
-
type $postMessage<T extends MessagesDef = never> = [T] extends [never]
|
|
129
|
-
? (params: { event: string, payload?: any }) => void
|
|
130
|
-
: <K extends keyof T>(params: { event: K, payload?: T[K]['payload'] }) => void
|
|
131
|
-
|
|
132
|
-
type $logger = {
|
|
133
|
-
info: (message: any, type?: string) => void,
|
|
134
|
-
warn: (message: any, type?: string) => void,
|
|
135
|
-
error: (message: any, type?: string) => void,
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export type Intl = ((
|
|
139
|
-
key: string,
|
|
140
|
-
paramsOrDefaultText?: Record<string, string | number> | string,
|
|
141
|
-
defaultText?: string,
|
|
142
|
-
) => string) & {
|
|
143
|
-
update: (config: Partial<I18nConfig>) => void,
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
interface ComponentBuiltinProps<
|
|
147
|
-
Store extends object = ObjectRecord,
|
|
148
|
-
Messages extends MessagesDef = never,
|
|
149
|
-
Actions extends ComponentPublicActionMap = never
|
|
150
|
-
> {
|
|
151
|
-
$store: Readonly<Store>,
|
|
152
|
-
$dispatch: $dispatch<Actions>,
|
|
153
|
-
$postMessage: $postMessage<Messages>,
|
|
154
|
-
$t: Intl,
|
|
155
|
-
$logger: $logger,
|
|
156
|
-
$self: { url: string, module: ModuleDef },
|
|
157
|
-
$locale: string,
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export interface I18nConfig {
|
|
161
|
-
resources: Record<string, Record<string, string>>,
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export type I18n = () => I18nConfig | Promise<I18nConfig>
|
|
165
|
-
|
|
166
|
-
export type GlobalI18n = {
|
|
167
|
-
defaultLocale?: string, // en
|
|
168
|
-
getResources?: () => I18nConfig | Promise<I18nConfig>
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export type OnMessage<T extends MessagesDef = never> = (message: Message<T>) => void
|
|
172
|
-
|
|
173
|
-
export type VariousProps<
|
|
174
|
-
Props extends object = ObjectRecord,
|
|
175
|
-
Store extends object = ObjectRecord,
|
|
176
|
-
Messages extends MessagesDef = never,
|
|
177
|
-
Actions extends ComponentPublicActionMap = never
|
|
178
|
-
> = ComponentBuiltinProps<Store, Messages, Actions> & Props
|
|
179
|
-
|
|
180
|
-
export type VariousFC<
|
|
181
|
-
Props extends object = ObjectRecord,
|
|
182
|
-
Store extends object = ObjectRecord,
|
|
183
|
-
SelfActions extends PublicActionDef = never,
|
|
184
|
-
Messages extends MessagesDef = never,
|
|
185
|
-
Actions extends ComponentPublicActionMap = never
|
|
186
|
-
> = FC<VariousProps<Props, Store, Messages, Actions>> & ComponentStatics<SelfActions, Messages>
|
|
187
|
-
|
|
188
|
-
export interface ErrorFallbackProps<Store extends object = ObjectRecord> {
|
|
189
|
-
$reload: () => void,
|
|
190
|
-
$error: VariousError,
|
|
191
|
-
$store: Readonly<Store>,
|
|
192
|
-
$self: { url: string, module: ModuleDef },
|
|
193
|
-
$locale: string,
|
|
194
|
-
}
|
|
195
|
-
export type ErrorFallbackNode<
|
|
196
|
-
Store extends object = ObjectRecord
|
|
197
|
-
> = ComponentType<ErrorFallbackProps<Store>>
|
|
198
|
-
|
|
199
|
-
export interface FallbackProps<Store extends object = ObjectRecord> {
|
|
200
|
-
$store: Readonly<Store>,
|
|
201
|
-
$self: { url: string, module: ModuleDef },
|
|
202
|
-
$locale: string,
|
|
203
|
-
}
|
|
204
|
-
export type FallbackNode<
|
|
205
|
-
Store extends object = ObjectRecord
|
|
206
|
-
> = ComponentType<FallbackProps<Store>>
|
|
207
|
-
|
|
208
|
-
type Dispatch<T extends object = ObjectRecord> = (
|
|
209
|
-
nycticorax: {
|
|
210
|
-
getStore: <K extends keyof T | undefined = undefined>(k?: K | undefined) =>
|
|
211
|
-
K extends keyof T ? T[K] : T,
|
|
212
|
-
emit: (next: Partial<T>) => void,
|
|
213
|
-
},
|
|
214
|
-
payload: any,
|
|
215
|
-
trigger: ModuleDef,
|
|
216
|
-
) => Promise<any>
|
|
217
|
-
|
|
218
|
-
interface MessageEventArgs {
|
|
219
|
-
trigger: ModuleDef,
|
|
220
|
-
event: string,
|
|
221
|
-
payload?: any,
|
|
222
|
-
}
|
|
223
|
-
type MessageEventRes = boolean | Omit<MessageEventArgs, 'trigger'>
|
|
224
|
-
interface DispatchEventArgs {
|
|
225
|
-
target: ModuleDef,
|
|
226
|
-
trigger: ModuleDef,
|
|
227
|
-
action: string,
|
|
228
|
-
payload?: any,
|
|
229
|
-
}
|
|
230
|
-
type DispatchEventRes = boolean | Omit<DispatchEventArgs, 'trigger'>
|
|
231
|
-
interface LoadEventArgs {
|
|
232
|
-
module: ModuleDef,
|
|
233
|
-
loadStart: number,
|
|
234
|
-
loadEnd: number,
|
|
235
|
-
beenLoaded: boolean,
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
type LogLevel = 'info' | 'warn' | 'error'
|
|
239
|
-
interface LogArgs {
|
|
240
|
-
module: ModuleDef,
|
|
241
|
-
level: LogLevel,
|
|
242
|
-
type?: string,
|
|
243
|
-
message: any,
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
export type MessageEvent = (e: MessageEventArgs) => Promise<MessageEventRes> | MessageEventRes
|
|
247
|
-
export type DispatchEvent = (e: DispatchEventArgs) => Promise<DispatchEventRes> | DispatchEventRes
|
|
248
|
-
export type LoadEvent = (e: LoadEventArgs) => void
|
|
249
|
-
export type ErrorEvent = (e: VariousError) => void
|
|
250
|
-
export type LogEvent = (e: LogArgs) => boolean
|
|
251
|
-
|
|
252
|
-
export interface App<Store extends object = ObjectRecord> {
|
|
253
|
-
store?: Store,
|
|
254
|
-
ErrorFallback?: ErrorFallbackNode<Store>,
|
|
255
|
-
Fallback?: FallbackNode<Store>,
|
|
256
|
-
actions?: Record<string, Dispatch<Store>>,
|
|
257
|
-
Root: ComponentType,
|
|
258
|
-
middlewares?: {
|
|
259
|
-
onLoad?: LoadEvent,
|
|
260
|
-
onError?: ErrorEvent,
|
|
261
|
-
onMessage?: MessageEvent,
|
|
262
|
-
onDispatch?: DispatchEvent,
|
|
263
|
-
onLog?: LogEvent,
|
|
264
|
-
},
|
|
265
|
-
i18n?: GlobalI18n,
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
export interface Config {
|
|
269
|
-
dependencies: {
|
|
270
|
-
app: string,
|
|
271
|
-
'@variousjs/various'?: string,
|
|
272
|
-
react?: string,
|
|
273
|
-
'react-dom'?: string,
|
|
274
|
-
vue?: string,
|
|
275
|
-
} & Record<string, string>,
|
|
276
|
-
root?: string,
|
|
277
|
-
timeout?: number,
|
|
278
|
-
earlyParallelDependencies?: string[],
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
export function createComponent<
|
|
282
|
-
Props extends object = ObjectRecord,
|
|
283
|
-
Ref = unknown,
|
|
284
|
-
Store extends object = ObjectRecord
|
|
285
|
-
>(
|
|
286
|
-
config: {
|
|
287
|
-
url?: string,
|
|
288
|
-
type?: VariousComponentType,
|
|
289
|
-
module: ModuleDef,
|
|
290
|
-
},
|
|
291
|
-
/**
|
|
292
|
-
* set store keys if component created before store initialization
|
|
293
|
-
*/
|
|
294
|
-
storeKeys?: (keyof Store)[],
|
|
295
|
-
): ComponentType<ComponentDefaultProps<Ref> & Props>
|
|
296
|
-
|
|
297
|
-
export function createModule<T = unknown> (params: {
|
|
298
|
-
url?: string,
|
|
299
|
-
module: ModuleDef,
|
|
300
|
-
}, logError?: boolean): Promise<T>
|
|
301
|
-
|
|
302
|
-
export function renderComponent<
|
|
303
|
-
Props extends object = ObjectRecord
|
|
304
|
-
>(params: {
|
|
305
|
-
module: ModuleDef,
|
|
306
|
-
url?: string,
|
|
307
|
-
type?: VariousComponentType,
|
|
308
|
-
props?: Props & ComponentDefaultProps,
|
|
309
|
-
target: Element | null,
|
|
310
|
-
renderNode?: (children: ReactNode) => ReactNode,
|
|
311
|
-
onMounted?: () => void,
|
|
312
|
-
}): Promise<() => Promise<void>>
|
|
313
|
-
|
|
314
|
-
export type VariousComponentProps<
|
|
315
|
-
Store extends object = ObjectRecord,
|
|
316
|
-
Messages extends MessagesDef = never,
|
|
317
|
-
Actions extends ComponentPublicActionMap = never,
|
|
318
|
-
> = PropType<ComponentBuiltinProps<Store, Messages, Actions>>
|
|
319
|
-
|
|
320
|
-
export const isModuleLoaded: (module: ModuleDef) => boolean
|
|
321
|
-
export const removeLoadedModules: (modules: ModuleDef[]) => void
|
|
322
|
-
export const getMountedComponents: () => ModuleDef[]
|
|
323
|
-
export const preloadModules: (modules: ModuleDef[]) => Promise<void>
|
|
324
|
-
export const onComponentMounted: (
|
|
325
|
-
module: ModuleDef | ModuleDef[],
|
|
326
|
-
callback: () => void
|
|
327
|
-
) => (() => void) | void
|
|
328
|
-
export const defineDependencies: (deps: Record<string, string>) => void
|
|
329
|
-
|
|
330
|
-
export const version: string
|
|
331
|
-
export function getConfig<C extends object = ObjectRecord>(): C
|
|
332
|
-
export function getStore<Store extends object = ObjectRecord>(): Store
|
|
333
|
-
|
|
334
|
-
export const createDispatch: <M extends ComponentPublicActionMap = never>(
|
|
335
|
-
module: ModuleDef,
|
|
336
|
-
) => $dispatch<M>
|
|
337
|
-
export const createPostMessage: <Messages extends MessagesDef = never>(
|
|
338
|
-
module: ModuleDef
|
|
339
|
-
) => $postMessage<Messages>
|
|
340
|
-
export const createLogger: (module: ModuleDef) => $logger
|
|
341
|
-
export const getModuleInfo: (module: ModuleDef) => {
|
|
342
|
-
name: string,
|
|
343
|
-
entry?: string,
|
|
344
|
-
}
|
|
345
|
-
}
|
package/standalone.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
declare module '@variousjs/various/standalone' {
|
|
2
|
-
import { ComponentType, RefObject } from 'react'
|
|
3
|
-
import {
|
|
4
|
-
VariousComponentType,
|
|
5
|
-
ObjectRecord,
|
|
6
|
-
ModuleDef,
|
|
7
|
-
App,
|
|
8
|
-
} from '@variousjs/various'
|
|
9
|
-
|
|
10
|
-
export {
|
|
11
|
-
createDispatch,
|
|
12
|
-
createLogger,
|
|
13
|
-
createPostMessage,
|
|
14
|
-
} from '@variousjs/various'
|
|
15
|
-
|
|
16
|
-
export type DependencyType = string | object | Function
|
|
17
|
-
|
|
18
|
-
export function createComponent<
|
|
19
|
-
Props extends object = ObjectRecord,
|
|
20
|
-
Ref = unknown,
|
|
21
|
-
Store extends object = ObjectRecord
|
|
22
|
-
>(
|
|
23
|
-
config: {
|
|
24
|
-
module: ModuleDef,
|
|
25
|
-
url?: string,
|
|
26
|
-
type?: VariousComponentType,
|
|
27
|
-
dependencies?: Partial<Record<
|
|
28
|
-
string,
|
|
29
|
-
DependencyType
|
|
30
|
-
>>,
|
|
31
|
-
/**
|
|
32
|
-
* set store keys if component created before store initialization
|
|
33
|
-
*/
|
|
34
|
-
storeKeys?: (keyof Store)[],
|
|
35
|
-
},
|
|
36
|
-
): ComponentType<Props & {
|
|
37
|
-
/**
|
|
38
|
-
* for React Component only
|
|
39
|
-
*/
|
|
40
|
-
$ref?: RefObject<Ref>,
|
|
41
|
-
}>
|
|
42
|
-
|
|
43
|
-
export type AppConfig<Store extends object = ObjectRecord> = Pick<
|
|
44
|
-
App<Store>,
|
|
45
|
-
'actions' | 'store' | 'Fallback' | 'ErrorFallback' | 'i18n'
|
|
46
|
-
> & {
|
|
47
|
-
dependencies: Partial<Record<
|
|
48
|
-
string,
|
|
49
|
-
DependencyType
|
|
50
|
-
>>
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function createAppConfig<Store extends object = ObjectRecord>(
|
|
54
|
-
config: AppConfig<Store>
|
|
55
|
-
): void
|
|
56
|
-
}
|