minimal-piral 0.15.0-beta.4411
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/app/index.5cddef.js +45575 -0
- package/app/index.5cddef.js.map +1 -0
- package/app/index.d.ts +1465 -0
- package/app/index.html +12 -0
- package/app/index.js +16 -0
- package/files.tar +0 -0
- package/files_once.tar +0 -0
- package/package.json +60 -0
package/app/index.d.ts
ADDED
|
@@ -0,0 +1,1465 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as ReactRouter from 'react-router';
|
|
3
|
+
|
|
4
|
+
declare module "minimal-piral" {
|
|
5
|
+
/**
|
|
6
|
+
* Defines the API accessible from pilets.
|
|
7
|
+
*/
|
|
8
|
+
export interface PiletApi extends EventEmitter, PiletCustomApi, PiletCoreApi {
|
|
9
|
+
/**
|
|
10
|
+
* Gets the metadata of the current pilet.
|
|
11
|
+
*/
|
|
12
|
+
meta: PiletMetadata;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The emitter for Piral app shell events.
|
|
17
|
+
*/
|
|
18
|
+
export interface EventEmitter {
|
|
19
|
+
/**
|
|
20
|
+
* Attaches a new event listener.
|
|
21
|
+
* @param type The type of the event to listen for.
|
|
22
|
+
* @param callback The callback to trigger.
|
|
23
|
+
*/
|
|
24
|
+
on<K extends keyof PiralEventMap>(type: K, callback: Listener<PiralEventMap[K]>): EventEmitter;
|
|
25
|
+
/**
|
|
26
|
+
* Detaches an existing event listener.
|
|
27
|
+
* @param type The type of the event to listen for.
|
|
28
|
+
* @param callback The callback to trigger.
|
|
29
|
+
*/
|
|
30
|
+
off<K extends keyof PiralEventMap>(type: K, callback: Listener<PiralEventMap[K]>): EventEmitter;
|
|
31
|
+
/**
|
|
32
|
+
* Emits a new event with the given type.
|
|
33
|
+
* @param type The type of the event to emit.
|
|
34
|
+
* @param arg The payload of the event.
|
|
35
|
+
*/
|
|
36
|
+
emit<K extends keyof PiralEventMap>(type: K, arg: PiralEventMap[K]): EventEmitter;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Custom Pilet API parts defined outside of piral-core.
|
|
41
|
+
*/
|
|
42
|
+
export interface PiletCustomApi {}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Defines the Pilet API from piral-core.
|
|
46
|
+
* This interface will be consumed by pilet developers so that their pilet can interact with the piral instance.
|
|
47
|
+
*/
|
|
48
|
+
export interface PiletCoreApi {
|
|
49
|
+
/**
|
|
50
|
+
* Gets a shared data value.
|
|
51
|
+
* @param name The name of the data to retrieve.
|
|
52
|
+
*/
|
|
53
|
+
getData<TKey extends string>(name: TKey): SharedData[TKey];
|
|
54
|
+
/**
|
|
55
|
+
* Sets the data using a given name. The name needs to be used exclusively by the current pilet.
|
|
56
|
+
* Using the name occupied by another pilet will result in no change.
|
|
57
|
+
* @param name The name of the data to store.
|
|
58
|
+
* @param value The value of the data to store.
|
|
59
|
+
* @param options The optional configuration for storing this piece of data.
|
|
60
|
+
* @returns True if the data could be set, otherwise false.
|
|
61
|
+
*/
|
|
62
|
+
setData<TKey extends string>(name: TKey, value: SharedData[TKey], options?: DataStoreOptions): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Registers a route for predefined page component.
|
|
65
|
+
* The route needs to be unique and can contain params.
|
|
66
|
+
* Params are following the path-to-regexp notation, e.g., :id for an id parameter.
|
|
67
|
+
* @param route The route to register.
|
|
68
|
+
* @param Component The component to render the page.
|
|
69
|
+
* @param meta The optional metadata to use.
|
|
70
|
+
*/
|
|
71
|
+
registerPage(route: string, Component: AnyComponent<PageComponentProps>, meta?: PiralPageMeta): RegistrationDisposer;
|
|
72
|
+
/**
|
|
73
|
+
* Unregisters the page identified by the given route.
|
|
74
|
+
* @param route The route that was previously registered.
|
|
75
|
+
*/
|
|
76
|
+
unregisterPage(route: string): void;
|
|
77
|
+
/**
|
|
78
|
+
* Registers an extension component with a predefined extension component.
|
|
79
|
+
* The name must refer to the extension slot.
|
|
80
|
+
* @param name The global name of the extension slot.
|
|
81
|
+
* @param Component The component to be rendered.
|
|
82
|
+
* @param defaults Optionally, sets the default values for the expected data.
|
|
83
|
+
*/
|
|
84
|
+
registerExtension<TName>(name: TName extends string ? TName : string, Component: AnyExtensionComponent<TName>, defaults?: Partial<ExtensionParams<TName>>): RegistrationDisposer;
|
|
85
|
+
/**
|
|
86
|
+
* Unregisters a global extension component.
|
|
87
|
+
* Only previously registered extension components can be unregistered.
|
|
88
|
+
* @param name The name of the extension slot to unregister from.
|
|
89
|
+
* @param Component The registered extension component to unregister.
|
|
90
|
+
*/
|
|
91
|
+
unregisterExtension<TName>(name: TName extends string ? TName : string, Component: AnyExtensionComponent<TName>): void;
|
|
92
|
+
/**
|
|
93
|
+
* React component for displaying extensions for a given name.
|
|
94
|
+
* @param props The extension's rendering props.
|
|
95
|
+
* @return The created React element.
|
|
96
|
+
*/
|
|
97
|
+
Extension<TName>(props: ExtensionSlotProps<TName>): React.ReactElement | null;
|
|
98
|
+
/**
|
|
99
|
+
* Renders an extension in a plain DOM component.
|
|
100
|
+
* @param element The DOM element or shadow root as a container for rendering the extension.
|
|
101
|
+
* @param props The extension's rendering props.
|
|
102
|
+
* @return The disposer to clear the extension.
|
|
103
|
+
*/
|
|
104
|
+
renderHtmlExtension<TName>(element: HTMLElement | ShadowRoot, props: ExtensionSlotProps<TName>): Disposable;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Describes the metadata of a pilet available in its API.
|
|
109
|
+
*/
|
|
110
|
+
export interface PiletMetadata {
|
|
111
|
+
/**
|
|
112
|
+
* The name of the pilet, i.e., the package id.
|
|
113
|
+
*/
|
|
114
|
+
name: string;
|
|
115
|
+
/**
|
|
116
|
+
* The version of the pilet. Should be semantically versioned.
|
|
117
|
+
*/
|
|
118
|
+
version: string;
|
|
119
|
+
/**
|
|
120
|
+
* Provides the version of the specification for this pilet.
|
|
121
|
+
*/
|
|
122
|
+
spec: string;
|
|
123
|
+
/**
|
|
124
|
+
* Provides some custom metadata for the pilet.
|
|
125
|
+
*/
|
|
126
|
+
custom?: any;
|
|
127
|
+
/**
|
|
128
|
+
* Optionally indicates the global require reference, if any.
|
|
129
|
+
*/
|
|
130
|
+
requireRef?: string;
|
|
131
|
+
/**
|
|
132
|
+
* Additional shared dependencies from the pilet.
|
|
133
|
+
*/
|
|
134
|
+
dependencies: Record<string, string>;
|
|
135
|
+
/**
|
|
136
|
+
* Provides some configuration to be used in the pilet.
|
|
137
|
+
*/
|
|
138
|
+
config: Record<string, any>;
|
|
139
|
+
/**
|
|
140
|
+
* The URL of the main script of the pilet.
|
|
141
|
+
*/
|
|
142
|
+
link: string;
|
|
143
|
+
/**
|
|
144
|
+
* The base path to the pilet. Can be used to make resource requests
|
|
145
|
+
* and override the public path.
|
|
146
|
+
*/
|
|
147
|
+
basePath: string;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Listener for Piral app shell events.
|
|
152
|
+
*/
|
|
153
|
+
export interface Listener<T> {
|
|
154
|
+
(arg: T): void;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The map of known Piral app shell events.
|
|
159
|
+
*/
|
|
160
|
+
export interface PiralEventMap extends PiralCustomEventMap {
|
|
161
|
+
"unload-pilet": PiralUnloadPiletEvent;
|
|
162
|
+
[custom: string]: any;
|
|
163
|
+
"store-data": PiralStoreDataEvent;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Defines the shape of the data store for storing shared data.
|
|
168
|
+
*/
|
|
169
|
+
export interface SharedData<TValue = any> {
|
|
170
|
+
[key: string]: TValue;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Defines the options to be used for storing data.
|
|
175
|
+
*/
|
|
176
|
+
export type DataStoreOptions = DataStoreTarget | CustomDataStoreOptions;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Possible shapes for a component.
|
|
180
|
+
*/
|
|
181
|
+
export type AnyComponent<T> = React.ComponentType<T> | FirstParametersOf<ComponentConverters<T>>;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* The props used by a page component.
|
|
185
|
+
*/
|
|
186
|
+
export interface PageComponentProps<T = any, S = any> extends RouteBaseProps<T, S> {
|
|
187
|
+
/**
|
|
188
|
+
* The meta data registered with the page.
|
|
189
|
+
*/
|
|
190
|
+
meta: PiralPageMeta;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* The meta data registered for a page.
|
|
195
|
+
*/
|
|
196
|
+
export interface PiralPageMeta extends PiralCustomPageMeta, PiralCustomPageMeta {}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* The shape of an implicit unregister function.
|
|
200
|
+
*/
|
|
201
|
+
export interface RegistrationDisposer {
|
|
202
|
+
(): void;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Shorthand for the definition of an extension component.
|
|
207
|
+
*/
|
|
208
|
+
export type AnyExtensionComponent<TName> = TName extends keyof PiralExtensionSlotMap ? AnyComponent<ExtensionComponentProps<TName>> : TName extends string ? AnyComponent<ExtensionComponentProps<any>> : AnyComponent<ExtensionComponentProps<TName>>;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Gives the extension params shape for the given extension slot name.
|
|
212
|
+
*/
|
|
213
|
+
export type ExtensionParams<TName> = TName extends keyof PiralExtensionSlotMap ? PiralExtensionSlotMap[TName] : TName extends string ? any : TName;
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* The props for defining an extension slot.
|
|
217
|
+
*/
|
|
218
|
+
export type ExtensionSlotProps<TName = string> = BaseExtensionSlotProps<TName extends string ? TName : string, ExtensionParams<TName>>;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Can be implemented by functions to be used for disposal purposes.
|
|
222
|
+
*/
|
|
223
|
+
export interface Disposable {
|
|
224
|
+
(): void;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Custom events defined outside of piral-core.
|
|
229
|
+
*/
|
|
230
|
+
export interface PiralCustomEventMap {}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Gets fired when a pilet gets unloaded.
|
|
234
|
+
*/
|
|
235
|
+
export interface PiralUnloadPiletEvent {
|
|
236
|
+
/**
|
|
237
|
+
* The name of the pilet to be unloaded.
|
|
238
|
+
*/
|
|
239
|
+
name: string;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Gets fired when a data item gets stored in piral.
|
|
244
|
+
*/
|
|
245
|
+
export interface PiralStoreDataEvent<TValue = any> {
|
|
246
|
+
/**
|
|
247
|
+
* The name of the item that was stored.
|
|
248
|
+
*/
|
|
249
|
+
name: string;
|
|
250
|
+
/**
|
|
251
|
+
* The storage target of the item.
|
|
252
|
+
*/
|
|
253
|
+
target: string;
|
|
254
|
+
/**
|
|
255
|
+
* The value that was stored.
|
|
256
|
+
*/
|
|
257
|
+
value: TValue;
|
|
258
|
+
/**
|
|
259
|
+
* The owner of the item.
|
|
260
|
+
*/
|
|
261
|
+
owner: string;
|
|
262
|
+
/**
|
|
263
|
+
* The expiration of the item.
|
|
264
|
+
*/
|
|
265
|
+
expires: number;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Defines the potential targets when storing data.
|
|
270
|
+
*/
|
|
271
|
+
export type DataStoreTarget = "memory" | "local" | "remote";
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Defines the custom options for storing data.
|
|
275
|
+
*/
|
|
276
|
+
export interface CustomDataStoreOptions {
|
|
277
|
+
/**
|
|
278
|
+
* The target data store. By default the data is only stored in memory.
|
|
279
|
+
*/
|
|
280
|
+
target?: DataStoreTarget;
|
|
281
|
+
/**
|
|
282
|
+
* Optionally determines when the data expires.
|
|
283
|
+
*/
|
|
284
|
+
expires?: "never" | Date | number;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export type FirstParametersOf<T> = {
|
|
288
|
+
[K in keyof T]: T[K] extends (arg: any) => any ? FirstParameter<T[K]> : never;
|
|
289
|
+
}[keyof T];
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Mapping of available component converters.
|
|
293
|
+
*/
|
|
294
|
+
export interface ComponentConverters<TProps> extends PiralCustomComponentConverters<TProps> {
|
|
295
|
+
/**
|
|
296
|
+
* Converts the HTML component to a framework-independent component.
|
|
297
|
+
* @param component The vanilla JavaScript component to be converted.
|
|
298
|
+
*/
|
|
299
|
+
html(component: HtmlComponent<TProps>): ForeignComponent<TProps>;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* The props that every registered page component obtains.
|
|
304
|
+
*/
|
|
305
|
+
export interface RouteBaseProps<UrlParams = any, UrlState = any> extends ReactRouter.RouteComponentProps<UrlParams, {}, UrlState>, BaseComponentProps {}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Custom meta data to include for pages.
|
|
309
|
+
*/
|
|
310
|
+
export interface PiralCustomPageMeta {}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* The props of an extension component.
|
|
314
|
+
*/
|
|
315
|
+
export interface ExtensionComponentProps<T> extends BaseComponentProps {
|
|
316
|
+
/**
|
|
317
|
+
* The provided parameters for showing the extension.
|
|
318
|
+
*/
|
|
319
|
+
params: T extends keyof PiralExtensionSlotMap ? PiralExtensionSlotMap[T] : T extends string ? any : T;
|
|
320
|
+
/**
|
|
321
|
+
* The optional children to receive, if any.
|
|
322
|
+
*/
|
|
323
|
+
children?: React.ReactNode;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* The mapping of the existing (known) extension slots.
|
|
328
|
+
*/
|
|
329
|
+
export interface PiralExtensionSlotMap extends PiralCustomExtensionSlotMap {}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* The basic props for defining an extension slot.
|
|
333
|
+
*/
|
|
334
|
+
export interface BaseExtensionSlotProps<TName, TParams> {
|
|
335
|
+
/**
|
|
336
|
+
* The children to transport, if any.
|
|
337
|
+
*/
|
|
338
|
+
children?: React.ReactNode;
|
|
339
|
+
/**
|
|
340
|
+
* Defines what should be rendered when no components are available
|
|
341
|
+
* for the specified extension.
|
|
342
|
+
*/
|
|
343
|
+
empty?(): React.ReactNode;
|
|
344
|
+
/**
|
|
345
|
+
* Determines if the `render` function should be called in case no
|
|
346
|
+
* components are available for the specified extension.
|
|
347
|
+
*
|
|
348
|
+
* If true, `empty` will be called and returned from the slot.
|
|
349
|
+
* If false, `render` will be called with the result of calling `empty`.
|
|
350
|
+
* The result of calling `render` will then be returned from the slot.
|
|
351
|
+
*/
|
|
352
|
+
emptySkipsRender?: boolean;
|
|
353
|
+
/**
|
|
354
|
+
* Defines the order of the components to render.
|
|
355
|
+
* May be more convient than using `render` w.r.t. ordering extensions
|
|
356
|
+
* by their supplied metadata.
|
|
357
|
+
* @param extensions The registered extensions.
|
|
358
|
+
* @returns The ordered extensions.
|
|
359
|
+
*/
|
|
360
|
+
order?(extensions: Array<ExtensionRegistration>): Array<ExtensionRegistration>;
|
|
361
|
+
/**
|
|
362
|
+
* Defines how the provided nodes should be rendered.
|
|
363
|
+
* @param nodes The rendered extension nodes.
|
|
364
|
+
* @returns The rendered nodes, i.e., an ReactElement.
|
|
365
|
+
*/
|
|
366
|
+
render?(nodes: Array<React.ReactNode>): React.ReactElement<any, any> | null;
|
|
367
|
+
/**
|
|
368
|
+
* The custom parameters for the given extension.
|
|
369
|
+
*/
|
|
370
|
+
params?: TParams;
|
|
371
|
+
/**
|
|
372
|
+
* The name of the extension to render.
|
|
373
|
+
*/
|
|
374
|
+
name: TName;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export type FirstParameter<T extends (arg: any) => any> = T extends (arg: infer P) => any ? P : never;
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Custom component converters defined outside of piral-core.
|
|
381
|
+
*/
|
|
382
|
+
export interface PiralCustomComponentConverters<TProps> {}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Definition of a vanilla JavaScript component.
|
|
386
|
+
*/
|
|
387
|
+
export interface HtmlComponent<TProps> {
|
|
388
|
+
/**
|
|
389
|
+
* Renders a component into the provided element using the given props and context.
|
|
390
|
+
*/
|
|
391
|
+
component: ForeignComponent<TProps>;
|
|
392
|
+
/**
|
|
393
|
+
* The type of the HTML component.
|
|
394
|
+
*/
|
|
395
|
+
type: "html";
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Generic definition of a framework-independent component.
|
|
400
|
+
*/
|
|
401
|
+
export interface ForeignComponent<TProps> {
|
|
402
|
+
/**
|
|
403
|
+
* Called when the component is mounted.
|
|
404
|
+
* @param element The container hosting the element.
|
|
405
|
+
* @param props The props to transport.
|
|
406
|
+
* @param ctx The associated context.
|
|
407
|
+
* @param locals The local state of this component instance.
|
|
408
|
+
*/
|
|
409
|
+
mount(element: HTMLElement, props: TProps, ctx: ComponentContext, locals: Record<string, any>): void;
|
|
410
|
+
/**
|
|
411
|
+
* Called when the component should be updated.
|
|
412
|
+
* @param element The container hosting the element.
|
|
413
|
+
* @param props The props to transport.
|
|
414
|
+
* @param ctx The associated context.
|
|
415
|
+
* @param locals The local state of this component instance.
|
|
416
|
+
*/
|
|
417
|
+
update?(element: HTMLElement, props: TProps, ctx: ComponentContext, locals: Record<string, any>): void;
|
|
418
|
+
/**
|
|
419
|
+
* Called when a component is unmounted.
|
|
420
|
+
* @param element The container that was hosting the element.
|
|
421
|
+
* @param locals The local state of this component instance.
|
|
422
|
+
*/
|
|
423
|
+
unmount?(element: HTMLElement, locals: Record<string, any>): void;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* The props that every registered component obtains.
|
|
428
|
+
*/
|
|
429
|
+
export interface BaseComponentProps {
|
|
430
|
+
/**
|
|
431
|
+
* The currently used pilet API.
|
|
432
|
+
*/
|
|
433
|
+
piral: PiletApi;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Custom extension slots outside of piral-core.
|
|
438
|
+
*/
|
|
439
|
+
export interface PiralCustomExtensionSlotMap {}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* The interface modeling the registration of a pilet extension component.
|
|
443
|
+
*/
|
|
444
|
+
export interface ExtensionRegistration extends BaseRegistration {
|
|
445
|
+
/**
|
|
446
|
+
* The wrapped registered extension component.
|
|
447
|
+
*/
|
|
448
|
+
component: WrappedComponent<ExtensionComponentProps<string>>;
|
|
449
|
+
/**
|
|
450
|
+
* The original extension component that has been registered.
|
|
451
|
+
*/
|
|
452
|
+
reference: any;
|
|
453
|
+
/**
|
|
454
|
+
* The default params (i.e., meta) of the extension.
|
|
455
|
+
*/
|
|
456
|
+
defaults: any;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* The context to be transported into the generic components.
|
|
461
|
+
*/
|
|
462
|
+
export interface ComponentContext {
|
|
463
|
+
router: ReactRouter.RouteComponentProps;
|
|
464
|
+
readState: PiralActions["readState"];
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* The base type for pilet component registration in the global state context.
|
|
469
|
+
*/
|
|
470
|
+
export interface BaseRegistration {
|
|
471
|
+
/**
|
|
472
|
+
* The pilet registering the component.
|
|
473
|
+
*/
|
|
474
|
+
pilet: string;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
export type WrappedComponent<TProps> = React.ComponentType<React.PropsWithChildren<Without<TProps, keyof BaseComponentProps>>>;
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* The globally defined actions.
|
|
481
|
+
*/
|
|
482
|
+
export interface PiralActions extends PiralCustomActions {
|
|
483
|
+
/**
|
|
484
|
+
* Initializes the application shell.
|
|
485
|
+
* @param loading The current loading state.
|
|
486
|
+
* @param error The application error, if any.
|
|
487
|
+
* @param modules The loaded pilets.
|
|
488
|
+
*/
|
|
489
|
+
initialize(loading: boolean, error: Error | undefined, modules: Array<Pilet>): void;
|
|
490
|
+
/**
|
|
491
|
+
* Injects an evaluated pilet at runtime - removes the pilet from registry first if available.
|
|
492
|
+
* @param pilet The pilet to be injected.
|
|
493
|
+
* @returns The injected pilet.
|
|
494
|
+
*/
|
|
495
|
+
injectPilet(pilet: Pilet): Pilet;
|
|
496
|
+
/**
|
|
497
|
+
* Adds a pilet at runtime by loading it, evaluating it, and then injecting it.
|
|
498
|
+
* @param pilet The pilet to be added.
|
|
499
|
+
* @returns The promise indicating when the pilet was fully added.
|
|
500
|
+
*/
|
|
501
|
+
addPilet(pilet: PiletEntry): Promise<void>;
|
|
502
|
+
/**
|
|
503
|
+
* Removes a pilet by unloading it and deleting all component registrations.
|
|
504
|
+
* @param name The name of the pilet to remove.
|
|
505
|
+
*/
|
|
506
|
+
removePilet(name: string): Promise<void>;
|
|
507
|
+
/**
|
|
508
|
+
* Defines a single action for Piral.
|
|
509
|
+
* @param actionName The name of the action to define.
|
|
510
|
+
* @param action The action to include.
|
|
511
|
+
*/
|
|
512
|
+
defineAction<T extends keyof PiralActions>(actionName: T, action: PiralAction<PiralActions[T]>): void;
|
|
513
|
+
/**
|
|
514
|
+
* Defines a set of actions for Piral.
|
|
515
|
+
* @param actions The actions to define.
|
|
516
|
+
*/
|
|
517
|
+
defineActions(actions: PiralDefineActions): void;
|
|
518
|
+
/**
|
|
519
|
+
* Reads the value of a shared data item.
|
|
520
|
+
* @param name The name of the shared item.
|
|
521
|
+
*/
|
|
522
|
+
readDataValue(name: string): any;
|
|
523
|
+
/**
|
|
524
|
+
* Tries to write a shared data item. The write access is only
|
|
525
|
+
* possible if the name belongs to the provided owner or has not
|
|
526
|
+
* been taken yet.
|
|
527
|
+
* Setting the value to null will release it.
|
|
528
|
+
* @param name The name of the shared data item.
|
|
529
|
+
* @param value The value of the shared data item.
|
|
530
|
+
* @param owner The owner of the shared data item.
|
|
531
|
+
* @param target The target storage locatation.
|
|
532
|
+
* @param expiration The time for when to dispose the shared item.
|
|
533
|
+
*/
|
|
534
|
+
tryWriteDataItem(name: string, value: any, owner: string, target: DataStoreTarget, expiration: number): boolean;
|
|
535
|
+
/**
|
|
536
|
+
* Registers a new route to be resolved.
|
|
537
|
+
* @param route The route to register.
|
|
538
|
+
* @param value The page to be rendered on the route.
|
|
539
|
+
*/
|
|
540
|
+
registerPage(route: string, value: PageRegistration): void;
|
|
541
|
+
/**
|
|
542
|
+
* Unregisters an existing route.
|
|
543
|
+
* @param route The route to be removed.
|
|
544
|
+
*/
|
|
545
|
+
unregisterPage(route: string): void;
|
|
546
|
+
/**
|
|
547
|
+
* Registers a new extension.
|
|
548
|
+
* @param name The name of the extension category.
|
|
549
|
+
* @param value The extension registration.
|
|
550
|
+
*/
|
|
551
|
+
registerExtension(name: string, value: ExtensionRegistration): void;
|
|
552
|
+
/**
|
|
553
|
+
* Unregisters an existing extension.
|
|
554
|
+
* @param name The name of the extension category.
|
|
555
|
+
* @param value The extension that will be removed.
|
|
556
|
+
*/
|
|
557
|
+
unregisterExtension(name: string, reference: any): void;
|
|
558
|
+
/**
|
|
559
|
+
* Sets the common component to render.
|
|
560
|
+
* @param name The name of the component.
|
|
561
|
+
* @param component The component to use for rendering.
|
|
562
|
+
*/
|
|
563
|
+
setComponent<TKey extends keyof ComponentsState>(name: TKey, component: ComponentsState[TKey]): void;
|
|
564
|
+
/**
|
|
565
|
+
* Sets the error component to render.
|
|
566
|
+
* @param type The type of the error.
|
|
567
|
+
* @param component The component to use for rendering.
|
|
568
|
+
*/
|
|
569
|
+
setErrorComponent<TKey extends keyof ErrorComponentsState>(type: TKey, component: ErrorComponentsState[TKey]): void;
|
|
570
|
+
/**
|
|
571
|
+
* Sets the common routes to render.
|
|
572
|
+
* @param path The name of the component.
|
|
573
|
+
* @param component The component to use for rendering.
|
|
574
|
+
*/
|
|
575
|
+
setRoute<T = {}>(path: string, component: React.ComponentType<ReactRouter.RouteComponentProps<T>>): void;
|
|
576
|
+
/**
|
|
577
|
+
* Includes a new provider as a sub-provider to the current provider.
|
|
578
|
+
* @param provider The provider to include.
|
|
579
|
+
*/
|
|
580
|
+
includeProvider(provider: JSX.Element): void;
|
|
581
|
+
/**
|
|
582
|
+
* Destroys (i.e., resets) the given portal instance.
|
|
583
|
+
* @param id The id of the portal to destroy.
|
|
584
|
+
*/
|
|
585
|
+
destroyPortal(id: string): void;
|
|
586
|
+
/**
|
|
587
|
+
* Includes the provided portal in the rendering pipeline.
|
|
588
|
+
* @param id The id of the portal to use.
|
|
589
|
+
* @param entry The child to render.
|
|
590
|
+
*/
|
|
591
|
+
showPortal(id: string, entry: React.ReactPortal): void;
|
|
592
|
+
/**
|
|
593
|
+
* Hides the provided portal in the rendering pipeline.
|
|
594
|
+
* @param id The id of the portal to use.
|
|
595
|
+
* @param entry The child to remove.
|
|
596
|
+
*/
|
|
597
|
+
hidePortal(id: string, entry: React.ReactPortal): void;
|
|
598
|
+
/**
|
|
599
|
+
* Updates the provided portal in the rendering pipeline.
|
|
600
|
+
* @param id The id of the portal to use.
|
|
601
|
+
* @param current The currently displayed child.
|
|
602
|
+
* @param next The updated child that should be displayed.
|
|
603
|
+
*/
|
|
604
|
+
updatePortal(id: string, current: React.ReactPortal, next: React.ReactPortal): void;
|
|
605
|
+
/**
|
|
606
|
+
* Dispatches a state change.
|
|
607
|
+
* @param update The update function creating a new state.
|
|
608
|
+
*/
|
|
609
|
+
dispatch(update: (state: GlobalState) => GlobalState): void;
|
|
610
|
+
/**
|
|
611
|
+
* Reads the selected part of the global state.
|
|
612
|
+
* @param select The selector for getting the desired part.
|
|
613
|
+
* @returns The desired part.
|
|
614
|
+
*/
|
|
615
|
+
readState<S>(select: (state: GlobalState) => S): S;
|
|
616
|
+
/**
|
|
617
|
+
* Performs a navigation.
|
|
618
|
+
* @param path The path to navigate to.
|
|
619
|
+
* @param state The optional state for the navigation.
|
|
620
|
+
*/
|
|
621
|
+
navigate(path: string, state?: any): void;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
export type Without<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* Custom actions defined outside of piral-core.
|
|
628
|
+
*/
|
|
629
|
+
export interface PiralCustomActions {}
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* An evaluated pilet, i.e., a full pilet: functionality and metadata.
|
|
633
|
+
*/
|
|
634
|
+
export type Pilet = SinglePilet | MultiPilet;
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Pilet entry representing part of a response from the feed service.
|
|
638
|
+
*/
|
|
639
|
+
export type PiletEntry = MultiPiletEntry | SinglePiletEntry;
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* The shape of an app action in Piral.
|
|
643
|
+
*/
|
|
644
|
+
export interface PiralAction<T extends (...args: any) => any> {
|
|
645
|
+
(ctx: GlobalStateContext, ...args: Parameters<T>): ReturnType<T>;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* A subset of the available app actions in Piral.
|
|
650
|
+
*/
|
|
651
|
+
export type PiralDefineActions = Partial<{
|
|
652
|
+
[P in keyof PiralActions]: PiralAction<PiralActions[P]>;
|
|
653
|
+
}>;
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* The interface modeling the registration of a pilet page component.
|
|
657
|
+
*/
|
|
658
|
+
export interface PageRegistration extends BaseRegistration {
|
|
659
|
+
/**
|
|
660
|
+
* The registered page component.
|
|
661
|
+
*/
|
|
662
|
+
component: WrappedComponent<PageComponentProps>;
|
|
663
|
+
/**
|
|
664
|
+
* The page's associated metadata.
|
|
665
|
+
*/
|
|
666
|
+
meta: PiralPageMeta;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* The Piral global app sub-state container for shared components.
|
|
671
|
+
*/
|
|
672
|
+
export interface ComponentsState extends PiralCustomComponentsState {
|
|
673
|
+
/**
|
|
674
|
+
* The loading indicator renderer.
|
|
675
|
+
*/
|
|
676
|
+
LoadingIndicator: React.ComponentType<LoadingIndicatorProps>;
|
|
677
|
+
/**
|
|
678
|
+
* The error renderer.
|
|
679
|
+
*/
|
|
680
|
+
ErrorInfo: React.ComponentType<ErrorInfoProps>;
|
|
681
|
+
/**
|
|
682
|
+
* The router context.
|
|
683
|
+
*/
|
|
684
|
+
Router: React.ComponentType<RouterProps>;
|
|
685
|
+
/**
|
|
686
|
+
* The layout used for pages.
|
|
687
|
+
*/
|
|
688
|
+
Layout: React.ComponentType<LayoutProps>;
|
|
689
|
+
/**
|
|
690
|
+
* The route switch used for determining the route registration.
|
|
691
|
+
*/
|
|
692
|
+
RouteSwitch: React.ComponentType<RouteSwitchProps>;
|
|
693
|
+
/**
|
|
694
|
+
* A component that can be used for debugging purposes.
|
|
695
|
+
*/
|
|
696
|
+
Debug?: React.ComponentType;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
export type ErrorComponentsState = {
|
|
700
|
+
[P in keyof Errors]?: React.ComponentType<Errors[P]>;
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* The Piral global app state container.
|
|
705
|
+
*/
|
|
706
|
+
export interface GlobalState extends PiralCustomState {
|
|
707
|
+
/**
|
|
708
|
+
* The relevant state for the app itself.
|
|
709
|
+
*/
|
|
710
|
+
app: AppState;
|
|
711
|
+
/**
|
|
712
|
+
* The relevant state for rendering errors of the app.
|
|
713
|
+
*/
|
|
714
|
+
errorComponents: ErrorComponentsState;
|
|
715
|
+
/**
|
|
716
|
+
* The relevant state for rendering parts of the app.
|
|
717
|
+
*/
|
|
718
|
+
components: ComponentsState;
|
|
719
|
+
/**
|
|
720
|
+
* The relevant state for the registered components.
|
|
721
|
+
*/
|
|
722
|
+
registry: RegistryState;
|
|
723
|
+
/**
|
|
724
|
+
* Gets the loaded modules.
|
|
725
|
+
*/
|
|
726
|
+
modules: Array<Pilet>;
|
|
727
|
+
/**
|
|
728
|
+
* The foreign component portals to render.
|
|
729
|
+
*/
|
|
730
|
+
portals: Record<string, Array<React.ReactPortal>>;
|
|
731
|
+
/**
|
|
732
|
+
* The application's shared data.
|
|
733
|
+
*/
|
|
734
|
+
data: Dict<SharedDataItem>;
|
|
735
|
+
/**
|
|
736
|
+
* The used (exact) application routes.
|
|
737
|
+
*/
|
|
738
|
+
routes: Dict<React.ComponentType<ReactRouter.RouteComponentProps<any>>>;
|
|
739
|
+
/**
|
|
740
|
+
* The current provider.
|
|
741
|
+
*/
|
|
742
|
+
provider?: React.ComponentType;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* An evaluated single pilet.
|
|
747
|
+
*/
|
|
748
|
+
export type SinglePilet = SinglePiletApp & PiletMetadata;
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* An evaluated multi pilet.
|
|
752
|
+
*/
|
|
753
|
+
export type MultiPilet = MultiPiletApp & PiletMetadata;
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* The metadata response for a multi pilet.
|
|
757
|
+
*/
|
|
758
|
+
export type MultiPiletEntry = PiletBundleEntry;
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* The metadata response for a single pilet.
|
|
762
|
+
*/
|
|
763
|
+
export type SinglePiletEntry = PiletV0Entry | PiletV1Entry | PiletV2Entry | PiletVxEntry;
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* The Piral app instance context.
|
|
767
|
+
*/
|
|
768
|
+
export interface GlobalStateContext extends PiralActions, EventEmitter {
|
|
769
|
+
/**
|
|
770
|
+
* The global state context atom.
|
|
771
|
+
* Changes to the state should always be dispatched via the `dispatch` action.
|
|
772
|
+
*/
|
|
773
|
+
state: UseBoundStore<GlobalState>;
|
|
774
|
+
/**
|
|
775
|
+
* The API objects created for the loaded pilets.
|
|
776
|
+
*/
|
|
777
|
+
apis: PiletsBag;
|
|
778
|
+
/**
|
|
779
|
+
* The available component converters.
|
|
780
|
+
*/
|
|
781
|
+
converters: ComponentConverters<any>;
|
|
782
|
+
/**
|
|
783
|
+
* The initial options.
|
|
784
|
+
*/
|
|
785
|
+
options: LoadPiletsOptions;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* Custom parts of the global custom component state defined outside of piral-core.
|
|
790
|
+
*/
|
|
791
|
+
export interface PiralCustomComponentsState {}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* The props of a Loading indicator component.
|
|
795
|
+
*/
|
|
796
|
+
export interface LoadingIndicatorProps {}
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* The props for the ErrorInfo component.
|
|
800
|
+
*/
|
|
801
|
+
export type ErrorInfoProps = UnionOf<Errors>;
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* The props of a Router component.
|
|
805
|
+
*/
|
|
806
|
+
export interface RouterProps {
|
|
807
|
+
/**
|
|
808
|
+
* The content to be rendered inside the router.
|
|
809
|
+
*/
|
|
810
|
+
children?: React.ReactNode;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
/**
|
|
814
|
+
* The props of a Layout component.
|
|
815
|
+
*/
|
|
816
|
+
export interface LayoutProps {
|
|
817
|
+
/**
|
|
818
|
+
* The currently selected layout type.
|
|
819
|
+
*/
|
|
820
|
+
currentLayout: LayoutType;
|
|
821
|
+
/**
|
|
822
|
+
* The page's content.
|
|
823
|
+
*/
|
|
824
|
+
children: React.ReactNode;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
/**
|
|
828
|
+
* The props of the RouteSwitch component.
|
|
829
|
+
*/
|
|
830
|
+
export interface RouteSwitchProps extends ReactRouter.SwitchProps {
|
|
831
|
+
/**
|
|
832
|
+
* The component that should be used in case nothing was found.
|
|
833
|
+
*/
|
|
834
|
+
NotFound: React.ComponentType<ReactRouter.RouteComponentProps>;
|
|
835
|
+
/**
|
|
836
|
+
* The component to register for the different paths.
|
|
837
|
+
*/
|
|
838
|
+
paths: Array<AppPath>;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
/**
|
|
842
|
+
* Map of all error types to their respective props.
|
|
843
|
+
*/
|
|
844
|
+
export interface Errors extends PiralCustomErrors {
|
|
845
|
+
/**
|
|
846
|
+
* The props type for an extension error.
|
|
847
|
+
*/
|
|
848
|
+
extension: ExtensionErrorInfoProps;
|
|
849
|
+
/**
|
|
850
|
+
* The props type for a loading error.
|
|
851
|
+
*/
|
|
852
|
+
loading: LoadingErrorInfoProps;
|
|
853
|
+
/**
|
|
854
|
+
* The props type for a page error.
|
|
855
|
+
*/
|
|
856
|
+
page: PageErrorInfoProps;
|
|
857
|
+
/**
|
|
858
|
+
* The props type for a not found error.
|
|
859
|
+
*/
|
|
860
|
+
not_found: NotFoundErrorInfoProps;
|
|
861
|
+
/**
|
|
862
|
+
* The props type for an unknown error.
|
|
863
|
+
*/
|
|
864
|
+
unknown: UnknownErrorInfoProps;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* Custom state extensions defined outside of piral-core.
|
|
869
|
+
*/
|
|
870
|
+
export interface PiralCustomState {}
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* The Piral global app sub-state container for app information.
|
|
874
|
+
*/
|
|
875
|
+
export interface AppState {
|
|
876
|
+
/**
|
|
877
|
+
* Gets if the application is currently performing a background loading
|
|
878
|
+
* activity, e.g., for loading modules asynchronously or fetching
|
|
879
|
+
* translations.
|
|
880
|
+
*/
|
|
881
|
+
loading: boolean;
|
|
882
|
+
/**
|
|
883
|
+
* Gets an unrecoverable application error, if any.
|
|
884
|
+
*/
|
|
885
|
+
error: Error | undefined;
|
|
886
|
+
/**
|
|
887
|
+
* Gets the public path of the application.
|
|
888
|
+
*/
|
|
889
|
+
publicPath: string;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
* The Piral global app sub-state container for component registrations.
|
|
894
|
+
*/
|
|
895
|
+
export interface RegistryState extends PiralCustomRegistryState {
|
|
896
|
+
/**
|
|
897
|
+
* The registered page components for the router.
|
|
898
|
+
*/
|
|
899
|
+
pages: Dict<PageRegistration>;
|
|
900
|
+
/**
|
|
901
|
+
* The registered extension components for extension slots.
|
|
902
|
+
*/
|
|
903
|
+
extensions: Dict<Array<ExtensionRegistration>>;
|
|
904
|
+
/**
|
|
905
|
+
* The registered wrappers for any component.
|
|
906
|
+
*/
|
|
907
|
+
wrappers: Dict<React.ComponentType<any>>;
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
export type Dict<T> = Record<string, T>;
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* Defines the shape of a shared data item.
|
|
914
|
+
*/
|
|
915
|
+
export interface SharedDataItem<TValue = any> {
|
|
916
|
+
/**
|
|
917
|
+
* Gets the associated value.
|
|
918
|
+
*/
|
|
919
|
+
value: TValue;
|
|
920
|
+
/**
|
|
921
|
+
* Gets the owner of the item.
|
|
922
|
+
*/
|
|
923
|
+
owner: string;
|
|
924
|
+
/**
|
|
925
|
+
* Gets the storage location.
|
|
926
|
+
*/
|
|
927
|
+
target: DataStoreTarget;
|
|
928
|
+
/**
|
|
929
|
+
* Gets the expiration of the item.
|
|
930
|
+
*/
|
|
931
|
+
expires: number;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* The pilet app, i.e., the functional exports.
|
|
936
|
+
*/
|
|
937
|
+
export interface SinglePiletApp {
|
|
938
|
+
/**
|
|
939
|
+
* Integrates the evaluated pilet into the application.
|
|
940
|
+
* @param api The API to access the application.
|
|
941
|
+
*/
|
|
942
|
+
setup(api: PiletApi): void | Promise<void>;
|
|
943
|
+
/**
|
|
944
|
+
* Optional function for cleanup.
|
|
945
|
+
* @param api The API to access the application.
|
|
946
|
+
*/
|
|
947
|
+
teardown?(api: PiletApi): void;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
/**
|
|
951
|
+
* The pilet app, i.e., the functional exports.
|
|
952
|
+
*/
|
|
953
|
+
export interface MultiPiletApp {
|
|
954
|
+
/**
|
|
955
|
+
* Integrates the evaluated pilet into the application.
|
|
956
|
+
* @param api The API to access the application.
|
|
957
|
+
*/
|
|
958
|
+
setup(apiFactory: PiletApiCreator): void | Promise<void>;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
/**
|
|
962
|
+
* Metadata for pilets using the bundle schema.
|
|
963
|
+
*/
|
|
964
|
+
export interface PiletBundleEntry {
|
|
965
|
+
/**
|
|
966
|
+
* The name of the bundle pilet, i.e., the package id.
|
|
967
|
+
*/
|
|
968
|
+
name?: string;
|
|
969
|
+
/**
|
|
970
|
+
* Optionally provides the version of the specification for this pilet.
|
|
971
|
+
*/
|
|
972
|
+
spec?: "v1";
|
|
973
|
+
/**
|
|
974
|
+
* The link for retrieving the bundle content of the pilet.
|
|
975
|
+
*/
|
|
976
|
+
link: string;
|
|
977
|
+
/**
|
|
978
|
+
* The reference name for the global bundle-shared require.
|
|
979
|
+
*/
|
|
980
|
+
bundle: string;
|
|
981
|
+
/**
|
|
982
|
+
* The computed integrity of the pilet. Will be used to set the
|
|
983
|
+
* integrity value of the script.
|
|
984
|
+
*/
|
|
985
|
+
integrity?: string;
|
|
986
|
+
/**
|
|
987
|
+
* Optionally provides some custom metadata for the pilet.
|
|
988
|
+
*/
|
|
989
|
+
custom?: any;
|
|
990
|
+
/**
|
|
991
|
+
* Additional shared dependency script files.
|
|
992
|
+
*/
|
|
993
|
+
dependencies?: Record<string, string>;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
/**
|
|
997
|
+
* Metadata for pilets using the v0 schema.
|
|
998
|
+
*/
|
|
999
|
+
export type PiletV0Entry = PiletV0ContentEntry | PiletV0LinkEntry;
|
|
1000
|
+
|
|
1001
|
+
/**
|
|
1002
|
+
* Metadata for pilets using the v1 schema.
|
|
1003
|
+
*/
|
|
1004
|
+
export interface PiletV1Entry {
|
|
1005
|
+
/**
|
|
1006
|
+
* The name of the pilet, i.e., the package id.
|
|
1007
|
+
*/
|
|
1008
|
+
name: string;
|
|
1009
|
+
/**
|
|
1010
|
+
* The version of the pilet. Should be semantically versioned.
|
|
1011
|
+
*/
|
|
1012
|
+
version: string;
|
|
1013
|
+
/**
|
|
1014
|
+
* Optionally provides the version of the specification for this pilet.
|
|
1015
|
+
*/
|
|
1016
|
+
spec?: "v1";
|
|
1017
|
+
/**
|
|
1018
|
+
* The link for retrieving the content of the pilet.
|
|
1019
|
+
*/
|
|
1020
|
+
link: string;
|
|
1021
|
+
/**
|
|
1022
|
+
* The reference name for the global require.
|
|
1023
|
+
*/
|
|
1024
|
+
requireRef: string;
|
|
1025
|
+
/**
|
|
1026
|
+
* The computed integrity of the pilet. Will be used to set the
|
|
1027
|
+
* integrity value of the script.
|
|
1028
|
+
*/
|
|
1029
|
+
integrity?: string;
|
|
1030
|
+
/**
|
|
1031
|
+
* Optionally provides some custom metadata for the pilet.
|
|
1032
|
+
*/
|
|
1033
|
+
custom?: any;
|
|
1034
|
+
/**
|
|
1035
|
+
* Optionally provides some configuration to be used in the pilet.
|
|
1036
|
+
*/
|
|
1037
|
+
config?: Record<string, any>;
|
|
1038
|
+
/**
|
|
1039
|
+
* Additional shared dependency script files.
|
|
1040
|
+
*/
|
|
1041
|
+
dependencies?: Record<string, string>;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
/**
|
|
1045
|
+
* Metadata for pilets using the v2 schema.
|
|
1046
|
+
*/
|
|
1047
|
+
export interface PiletV2Entry {
|
|
1048
|
+
/**
|
|
1049
|
+
* The name of the pilet, i.e., the package id.
|
|
1050
|
+
*/
|
|
1051
|
+
name: string;
|
|
1052
|
+
/**
|
|
1053
|
+
* The version of the pilet. Should be semantically versioned.
|
|
1054
|
+
*/
|
|
1055
|
+
version: string;
|
|
1056
|
+
/**
|
|
1057
|
+
* Provides the version of the specification for this pilet.
|
|
1058
|
+
*/
|
|
1059
|
+
spec: "v2";
|
|
1060
|
+
/**
|
|
1061
|
+
* The reference name for the global require.
|
|
1062
|
+
*/
|
|
1063
|
+
requireRef: string;
|
|
1064
|
+
/**
|
|
1065
|
+
* The computed integrity of the pilet.
|
|
1066
|
+
*/
|
|
1067
|
+
integrity?: string;
|
|
1068
|
+
/**
|
|
1069
|
+
* The link for retrieving the content of the pilet.
|
|
1070
|
+
*/
|
|
1071
|
+
link: string;
|
|
1072
|
+
/**
|
|
1073
|
+
* Optionally provides some custom metadata for the pilet.
|
|
1074
|
+
*/
|
|
1075
|
+
custom?: any;
|
|
1076
|
+
/**
|
|
1077
|
+
* Optionally provides some configuration to be used in the pilet.
|
|
1078
|
+
*/
|
|
1079
|
+
config?: Record<string, any>;
|
|
1080
|
+
/**
|
|
1081
|
+
* Additional shared dependency script files.
|
|
1082
|
+
*/
|
|
1083
|
+
dependencies?: Record<string, string>;
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
export interface PiletVxEntry {
|
|
1087
|
+
/**
|
|
1088
|
+
* The name of the pilet, i.e., the package id.
|
|
1089
|
+
*/
|
|
1090
|
+
name: string;
|
|
1091
|
+
/**
|
|
1092
|
+
* The version of the pilet. Should be semantically versioned.
|
|
1093
|
+
*/
|
|
1094
|
+
version: string;
|
|
1095
|
+
/**
|
|
1096
|
+
* Provides an identifier for the custom specification.
|
|
1097
|
+
*/
|
|
1098
|
+
spec: string;
|
|
1099
|
+
/**
|
|
1100
|
+
* Optionally provides some custom metadata for the pilet.
|
|
1101
|
+
*/
|
|
1102
|
+
custom?: any;
|
|
1103
|
+
/**
|
|
1104
|
+
* Optionally provides some configuration to be used in the pilet.
|
|
1105
|
+
*/
|
|
1106
|
+
config?: Record<string, any>;
|
|
1107
|
+
/**
|
|
1108
|
+
* Additional shared dependency script files.
|
|
1109
|
+
*/
|
|
1110
|
+
dependencies?: Record<string, string>;
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
export type UseBoundStore<T extends State, CustomStoreApi extends StoreApi<T> = StoreApi<T>> = {
|
|
1114
|
+
(): T;
|
|
1115
|
+
<U>(selector: StateSelector<T, U>, equalityFn?: EqualityChecker<U>): U;
|
|
1116
|
+
} & CustomStoreApi;
|
|
1117
|
+
|
|
1118
|
+
/**
|
|
1119
|
+
* Represents the dictionary of the loaded pilets and their APIs.
|
|
1120
|
+
*/
|
|
1121
|
+
export interface PiletsBag {
|
|
1122
|
+
[name: string]: PiletApi;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
/**
|
|
1126
|
+
* The options for loading pilets.
|
|
1127
|
+
*/
|
|
1128
|
+
export interface LoadPiletsOptions {
|
|
1129
|
+
/**
|
|
1130
|
+
* The callback function for creating an API object.
|
|
1131
|
+
* The API object is passed on to a specific pilet.
|
|
1132
|
+
*/
|
|
1133
|
+
createApi: PiletApiCreator;
|
|
1134
|
+
/**
|
|
1135
|
+
* The callback for fetching the dynamic pilets.
|
|
1136
|
+
*/
|
|
1137
|
+
fetchPilets: PiletRequester;
|
|
1138
|
+
/**
|
|
1139
|
+
* Optionally, some already existing evaluated pilets, e.g.,
|
|
1140
|
+
* helpful when debugging or in SSR scenarios.
|
|
1141
|
+
*/
|
|
1142
|
+
pilets?: Array<Pilet>;
|
|
1143
|
+
/**
|
|
1144
|
+
* Optionally, configures the default loader.
|
|
1145
|
+
*/
|
|
1146
|
+
config?: DefaultLoaderConfig;
|
|
1147
|
+
/**
|
|
1148
|
+
* Optionally, defines the default way how to load a pilet.
|
|
1149
|
+
*/
|
|
1150
|
+
loadPilet?: PiletLoader;
|
|
1151
|
+
/**
|
|
1152
|
+
* Optionally, defines loaders for custom specifications.
|
|
1153
|
+
*/
|
|
1154
|
+
loaders?: CustomSpecLoaders;
|
|
1155
|
+
/**
|
|
1156
|
+
* Optionally, defines a set of loading hooks to be used.
|
|
1157
|
+
*/
|
|
1158
|
+
hooks?: PiletLifecycleHooks;
|
|
1159
|
+
/**
|
|
1160
|
+
* Gets the map of globally available dependencies with their names
|
|
1161
|
+
* as keys and their evaluated pilet content as value.
|
|
1162
|
+
*/
|
|
1163
|
+
dependencies?: AvailableDependencies;
|
|
1164
|
+
/**
|
|
1165
|
+
* Optionally, defines the loading strategy to use.
|
|
1166
|
+
*/
|
|
1167
|
+
strategy?: PiletLoadingStrategy;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
export type UnionOf<T> = {
|
|
1171
|
+
[K in keyof T]: T[K];
|
|
1172
|
+
}[keyof T];
|
|
1173
|
+
|
|
1174
|
+
/**
|
|
1175
|
+
* The different known layout types.
|
|
1176
|
+
*/
|
|
1177
|
+
export type LayoutType = "mobile" | "tablet" | "desktop";
|
|
1178
|
+
|
|
1179
|
+
/**
|
|
1180
|
+
* Represents a path in the app registration.
|
|
1181
|
+
*/
|
|
1182
|
+
export interface AppPath {
|
|
1183
|
+
/**
|
|
1184
|
+
* The exact path to use.
|
|
1185
|
+
*/
|
|
1186
|
+
path: string;
|
|
1187
|
+
/**
|
|
1188
|
+
* The component to register for this path.
|
|
1189
|
+
*/
|
|
1190
|
+
Component: React.ComponentType<ReactRouter.RouteComponentProps>;
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
/**
|
|
1194
|
+
* Custom errors defined outside of piral-core.
|
|
1195
|
+
*/
|
|
1196
|
+
export interface PiralCustomErrors {}
|
|
1197
|
+
|
|
1198
|
+
/**
|
|
1199
|
+
* The error used when a registered extension component crashed.
|
|
1200
|
+
*/
|
|
1201
|
+
export interface ExtensionErrorInfoProps {
|
|
1202
|
+
/**
|
|
1203
|
+
* The type of the error.
|
|
1204
|
+
*/
|
|
1205
|
+
type: "extension";
|
|
1206
|
+
/**
|
|
1207
|
+
* The provided error details.
|
|
1208
|
+
*/
|
|
1209
|
+
error: any;
|
|
1210
|
+
/**
|
|
1211
|
+
* The name of the pilet emitting the error.
|
|
1212
|
+
*/
|
|
1213
|
+
pilet?: string;
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
/**
|
|
1217
|
+
* The error used when the app could not be loaded.
|
|
1218
|
+
*/
|
|
1219
|
+
export interface LoadingErrorInfoProps {
|
|
1220
|
+
/**
|
|
1221
|
+
* The type of the error.
|
|
1222
|
+
*/
|
|
1223
|
+
type: "loading";
|
|
1224
|
+
/**
|
|
1225
|
+
* The provided error details.
|
|
1226
|
+
*/
|
|
1227
|
+
error: any;
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
/**
|
|
1231
|
+
* The error used when a registered page component crashes.
|
|
1232
|
+
*/
|
|
1233
|
+
export interface PageErrorInfoProps extends ReactRouter.RouteComponentProps {
|
|
1234
|
+
/**
|
|
1235
|
+
* The type of the error.
|
|
1236
|
+
*/
|
|
1237
|
+
type: "page";
|
|
1238
|
+
/**
|
|
1239
|
+
* The provided error details.
|
|
1240
|
+
*/
|
|
1241
|
+
error: any;
|
|
1242
|
+
/**
|
|
1243
|
+
* The name of the pilet emitting the error.
|
|
1244
|
+
*/
|
|
1245
|
+
pilet?: string;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
/**
|
|
1249
|
+
* The error used when a route cannot be resolved.
|
|
1250
|
+
*/
|
|
1251
|
+
export interface NotFoundErrorInfoProps extends ReactRouter.RouteComponentProps {
|
|
1252
|
+
/**
|
|
1253
|
+
* The type of the error.
|
|
1254
|
+
*/
|
|
1255
|
+
type: "not_found";
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
/**
|
|
1259
|
+
* The error used when the exact type is unknown.
|
|
1260
|
+
*/
|
|
1261
|
+
export interface UnknownErrorInfoProps {
|
|
1262
|
+
/**
|
|
1263
|
+
* The type of the error.
|
|
1264
|
+
*/
|
|
1265
|
+
type: "unknown";
|
|
1266
|
+
/**
|
|
1267
|
+
* The provided error details.
|
|
1268
|
+
*/
|
|
1269
|
+
error: any;
|
|
1270
|
+
/**
|
|
1271
|
+
* The name of the pilet emitting the error.
|
|
1272
|
+
*/
|
|
1273
|
+
pilet?: string;
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
/**
|
|
1277
|
+
* Custom parts of the global registry state defined outside of piral-core.
|
|
1278
|
+
*/
|
|
1279
|
+
export interface PiralCustomRegistryState {}
|
|
1280
|
+
|
|
1281
|
+
/**
|
|
1282
|
+
* The creator function for the pilet API.
|
|
1283
|
+
*/
|
|
1284
|
+
export interface PiletApiCreator {
|
|
1285
|
+
(target: PiletMetadata): PiletApi;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
/**
|
|
1289
|
+
* Metadata for pilets using the v0 schema with a content.
|
|
1290
|
+
*/
|
|
1291
|
+
export interface PiletV0ContentEntry extends PiletV0BaseEntry {
|
|
1292
|
+
/**
|
|
1293
|
+
* The content of the pilet. If the content is not available
|
|
1294
|
+
* the link will be used (unless caching has been activated).
|
|
1295
|
+
*/
|
|
1296
|
+
content: string;
|
|
1297
|
+
/**
|
|
1298
|
+
* If available indicates that the pilet should not be cached.
|
|
1299
|
+
* In case of a string this is interpreted as the expiration time
|
|
1300
|
+
* of the cache. In case of an accurate hash this should not be
|
|
1301
|
+
* required or set.
|
|
1302
|
+
*/
|
|
1303
|
+
noCache?: boolean | string;
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
/**
|
|
1307
|
+
* Metadata for pilets using the v0 schema with a link.
|
|
1308
|
+
*/
|
|
1309
|
+
export interface PiletV0LinkEntry extends PiletV0BaseEntry {
|
|
1310
|
+
/**
|
|
1311
|
+
* The link for retrieving the content of the pilet.
|
|
1312
|
+
*/
|
|
1313
|
+
link: string;
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
export type StateSelector<T extends State, U> = (state: T) => U;
|
|
1317
|
+
|
|
1318
|
+
export type EqualityChecker<T> = (state: T, newState: T) => boolean;
|
|
1319
|
+
|
|
1320
|
+
export type State = object;
|
|
1321
|
+
|
|
1322
|
+
export type StoreApi<T extends State> = {
|
|
1323
|
+
setState: SetState<T>;
|
|
1324
|
+
getState: GetState<T>;
|
|
1325
|
+
subscribe: Subscribe<T>;
|
|
1326
|
+
destroy: Destroy;
|
|
1327
|
+
};
|
|
1328
|
+
|
|
1329
|
+
/**
|
|
1330
|
+
* The interface describing a function capable of fetching pilets.
|
|
1331
|
+
*/
|
|
1332
|
+
export interface PiletRequester {
|
|
1333
|
+
(): Promise<PiletEntries>;
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
/**
|
|
1337
|
+
* Additional configuration options for the default loader.
|
|
1338
|
+
*/
|
|
1339
|
+
export interface DefaultLoaderConfig {
|
|
1340
|
+
/**
|
|
1341
|
+
* Sets the cross-origin attribute of potential script tags.
|
|
1342
|
+
* For pilets v1 this may be useful. Otherwise, only pilets that
|
|
1343
|
+
* have an integrity defined will be set to "anonymous".
|
|
1344
|
+
*/
|
|
1345
|
+
crossOrigin?: string;
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
/**
|
|
1349
|
+
* The callback to be used to load a single pilet.
|
|
1350
|
+
*/
|
|
1351
|
+
export interface PiletLoader {
|
|
1352
|
+
(entry: PiletEntry): Promise<Pilet>;
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
/**
|
|
1356
|
+
* Defines the spec identifiers for custom loading.
|
|
1357
|
+
*/
|
|
1358
|
+
export type CustomSpecLoaders = Record<string, PiletLoader>;
|
|
1359
|
+
|
|
1360
|
+
/**
|
|
1361
|
+
* A set of pipeline hooks used by the Piral loading orchestrator.
|
|
1362
|
+
*/
|
|
1363
|
+
export interface PiletLifecycleHooks {
|
|
1364
|
+
/**
|
|
1365
|
+
* Hook fired before a pilet is loaded.
|
|
1366
|
+
*/
|
|
1367
|
+
loadPilet?(pilet: PiletMetadata): void;
|
|
1368
|
+
/**
|
|
1369
|
+
* Hook fired before a pilet is being set up.
|
|
1370
|
+
*/
|
|
1371
|
+
setupPilet?(pilet: Pilet): void;
|
|
1372
|
+
/**
|
|
1373
|
+
* Hook fired before a pilet is being cleaned up.
|
|
1374
|
+
*/
|
|
1375
|
+
cleanupPilet?(pilet: Pilet): void;
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
/**
|
|
1379
|
+
* The record containing all available dependencies.
|
|
1380
|
+
*/
|
|
1381
|
+
export interface AvailableDependencies {
|
|
1382
|
+
[name: string]: any;
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
/**
|
|
1386
|
+
* The strategy for how pilets are loaded at runtime.
|
|
1387
|
+
*/
|
|
1388
|
+
export interface PiletLoadingStrategy {
|
|
1389
|
+
(options: LoadPiletsOptions, pilets: PiletsLoaded): PromiseLike<void>;
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
/**
|
|
1393
|
+
* Basic metadata for pilets using the v0 schema.
|
|
1394
|
+
*/
|
|
1395
|
+
export interface PiletV0BaseEntry {
|
|
1396
|
+
/**
|
|
1397
|
+
* The name of the pilet, i.e., the package id.
|
|
1398
|
+
*/
|
|
1399
|
+
name: string;
|
|
1400
|
+
/**
|
|
1401
|
+
* The version of the pilet. Should be semantically versioned.
|
|
1402
|
+
*/
|
|
1403
|
+
version: string;
|
|
1404
|
+
/**
|
|
1405
|
+
* Optionally provides the version of the specification for this pilet.
|
|
1406
|
+
*/
|
|
1407
|
+
spec?: "v0";
|
|
1408
|
+
/**
|
|
1409
|
+
* The computed hash value of the pilet's content. Should be
|
|
1410
|
+
* accurate to allow caching.
|
|
1411
|
+
*/
|
|
1412
|
+
hash: string;
|
|
1413
|
+
/**
|
|
1414
|
+
* Optionally provides some custom metadata for the pilet.
|
|
1415
|
+
*/
|
|
1416
|
+
custom?: any;
|
|
1417
|
+
/**
|
|
1418
|
+
* Optionally provides some configuration to be used in the pilet.
|
|
1419
|
+
*/
|
|
1420
|
+
config?: Record<string, any>;
|
|
1421
|
+
/**
|
|
1422
|
+
* Additional shared dependency script files.
|
|
1423
|
+
*/
|
|
1424
|
+
dependencies?: Record<string, string>;
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
export type SetState<T extends State> = {
|
|
1428
|
+
<K1 extends keyof T, K2 extends keyof T = K1, K3 extends keyof T = K2, K4 extends keyof T = K3>(partial: PartialState<T, K1, K2, K3, K4>, replace?: boolean): void;
|
|
1429
|
+
};
|
|
1430
|
+
|
|
1431
|
+
export type GetState<T extends State> = () => T;
|
|
1432
|
+
|
|
1433
|
+
export type Subscribe<T extends State> = {
|
|
1434
|
+
(listener: StateListener<T>): () => void;
|
|
1435
|
+
<StateSlice>(listener: StateSliceListener<StateSlice>, selector?: StateSelector<T, StateSlice>, equalityFn?: EqualityChecker<StateSlice>): () => void;
|
|
1436
|
+
};
|
|
1437
|
+
|
|
1438
|
+
export type Destroy = () => void;
|
|
1439
|
+
|
|
1440
|
+
/**
|
|
1441
|
+
* The entries representing pilets from a feed service response.
|
|
1442
|
+
*/
|
|
1443
|
+
export type PiletEntries = Array<PiletEntry>;
|
|
1444
|
+
|
|
1445
|
+
/**
|
|
1446
|
+
* The callback to be used when pilets have been loaded.
|
|
1447
|
+
*/
|
|
1448
|
+
export interface PiletsLoaded {
|
|
1449
|
+
(error: Error | undefined, pilets: Array<Pilet>): void;
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
/**
|
|
1453
|
+
* @deprecated Use the builtin `Partial<T>` instead of `PartialState<T>`.
|
|
1454
|
+
* Additionally turn on `--exactOptionalPropertyTypes` tsc flag.
|
|
1455
|
+
* `PartialState` will be removed in next major
|
|
1456
|
+
*/
|
|
1457
|
+
export type PartialState<T extends State, K1 extends keyof T = keyof T, K2 extends keyof T = K1, K3 extends keyof T = K2, K4 extends keyof T = K3> = (Pick<T, K1> | Pick<T, K2> | Pick<T, K3> | Pick<T, K4> | T) | ((state: T) => Pick<T, K1> | Pick<T, K2> | Pick<T, K3> | Pick<T, K4> | T);
|
|
1458
|
+
|
|
1459
|
+
export type StateListener<T> = (state: T, previousState: T) => void;
|
|
1460
|
+
|
|
1461
|
+
/**
|
|
1462
|
+
* @deprecated Use `StateListener<T>` instead of `StateSliceListener<T>`.
|
|
1463
|
+
*/
|
|
1464
|
+
export type StateSliceListener<T> = (slice: T, previousSlice: T) => void;
|
|
1465
|
+
}
|