piral-core
Advanced tools
Comparing version 0.8.0-pre.685 to 0.8.0-pre.690
@@ -5,29 +5,5 @@ "use strict"; | ||
const ExtensionSlot_1 = require("./ExtensionSlot"); | ||
exports.DefaultErrorInfo = props => (React.createElement(ExtensionSlot_1.ExtensionSlot, { name: "error", params: props, empty: () => { | ||
switch (props.type) { | ||
case 'not_found': | ||
return React.createElement("div", { key: "default_error" }, | ||
"Page ", | ||
props.location.pathname, | ||
" not found."); | ||
case 'page': | ||
return React.createElement("div", { key: "default_error" }, | ||
"Page ", | ||
props.location.pathname, | ||
" crashed."); | ||
case 'extension': | ||
return React.createElement("div", { key: "default_error" }, | ||
"Extension crashed: ", | ||
props.error, | ||
"."); | ||
case 'loading': | ||
return React.createElement("div", { key: "default_error" }, | ||
"App could not be loaded: ", | ||
props.error, | ||
"."); | ||
default: | ||
return React.createElement("div", { key: "default_error" }, "The component crashed."); | ||
} | ||
} })); | ||
const SwitchErrorInfo_1 = require("./SwitchErrorInfo"); | ||
exports.DefaultErrorInfo = props => (React.createElement(ExtensionSlot_1.ExtensionSlot, { name: "error", params: props, empty: () => React.createElement(SwitchErrorInfo_1.SwitchErrorInfo, Object.assign({ key: "default_error" }, props)) })); | ||
exports.DefaultErrorInfo.displayName = 'DefaultErrorInfo'; | ||
//# sourceMappingURL=DefaultErrorInfo.js.map |
@@ -10,3 +10,3 @@ "use strict"; | ||
return render(extensions.length === 0 && react_arbiter_1.isfunc(empty) | ||
? [React.createElement(React.Fragment, { key: "empty" }, empty())] | ||
? [utils_1.defaultRender(empty(), 'empty')] | ||
: extensions.map(({ component: Component, defaults = {} }, i) => (React.createElement(Component, { key: `${Component.displayName || '_'}${i}`, params: Object.assign({}, defaults, (params || {})) })))); | ||
@@ -13,0 +13,0 @@ } |
@@ -11,4 +11,6 @@ export * from './components'; | ||
export * from './SetComponent'; | ||
export * from './SetError'; | ||
export * from './SetProvider'; | ||
export * from './SetRoute'; | ||
export * from './SwitchErrorInfo'; | ||
export * from './withApi'; |
@@ -14,5 +14,7 @@ "use strict"; | ||
tslib_1.__exportStar(require("./SetComponent"), exports); | ||
tslib_1.__exportStar(require("./SetError"), exports); | ||
tslib_1.__exportStar(require("./SetProvider"), exports); | ||
tslib_1.__exportStar(require("./SetRoute"), exports); | ||
tslib_1.__exportStar(require("./SwitchErrorInfo"), exports); | ||
tslib_1.__exportStar(require("./withApi"), exports); | ||
//# sourceMappingURL=index.js.map |
import { ComponentType } from 'react'; | ||
import { Atom } from '@dbeining/react-atom'; | ||
import { RouteComponentProps } from 'react-router-dom'; | ||
import { LayoutType, GlobalState, Pilet, ComponentsState } from '../../types'; | ||
import { LayoutType, GlobalState, Pilet, ComponentsState, ErrorComponentsState } from '../../types'; | ||
export declare function changeLayout(ctx: Atom<GlobalState>, current: LayoutType): void; | ||
export declare function initialize(ctx: Atom<GlobalState>, loading: boolean, error: Error | undefined, modules: Array<Pilet>): void; | ||
export declare function setComponent<TKey extends keyof ComponentsState>(ctx: Atom<GlobalState>, name: TKey, component: ComponentsState[TKey]): void; | ||
export declare function setErrorComponent<TKey extends keyof ErrorComponentsState>(ctx: Atom<GlobalState>, type: TKey, component: ErrorComponentsState[TKey]): void; | ||
export declare function setRoute<T = {}>(ctx: Atom<GlobalState>, path: string, component: ComponentType<RouteComponentProps<T>>): void; | ||
export declare function includeProvider(ctx: Atom<GlobalState>, provider: JSX.Element): void; |
@@ -5,4 +5,5 @@ "use strict"; | ||
const react_atom_1 = require("@dbeining/react-atom"); | ||
const utils_1 = require("../../utils"); | ||
function changeLayout(ctx, current) { | ||
react_atom_1.swap(ctx, state => (Object.assign({}, state, { app: Object.assign({}, state.app, { layout: current }) }))); | ||
react_atom_1.swap(ctx, state => (Object.assign({}, state, { app: utils_1.withKey(state.app, 'layout', current) }))); | ||
} | ||
@@ -16,7 +17,11 @@ exports.changeLayout = changeLayout; | ||
function setComponent(ctx, name, component) { | ||
react_atom_1.swap(ctx, state => (Object.assign({}, state, { components: Object.assign({}, state.components, { [name]: component }) }))); | ||
react_atom_1.swap(ctx, state => (Object.assign({}, state, { components: utils_1.withKey(state.components, name, component) }))); | ||
} | ||
exports.setComponent = setComponent; | ||
function setErrorComponent(ctx, type, component) { | ||
react_atom_1.swap(ctx, state => (Object.assign({}, state, { errorComponents: utils_1.withKey(state.errorComponents, type, component) }))); | ||
} | ||
exports.setErrorComponent = setErrorComponent; | ||
function setRoute(ctx, path, component) { | ||
react_atom_1.swap(ctx, state => (Object.assign({}, state, { routes: Object.assign({}, state.routes, { [path]: component }) }))); | ||
react_atom_1.swap(ctx, state => (Object.assign({}, state, { routes: utils_1.withKey(state.routes, path, component) }))); | ||
} | ||
@@ -23,0 +28,0 @@ exports.setRoute = setRoute; |
import { Atom } from '@dbeining/react-atom'; | ||
import { GlobalState, SharedDataItem, DataStoreTarget, EventEmitter } from '../../types'; | ||
import { GlobalState, DataStoreTarget, EventEmitter } from '../../types'; | ||
export declare function resetData(ctx: Atom<GlobalState>): void; | ||
export declare function readDataItem(ctx: Atom<GlobalState>, key: string): import("@dbeining/react-atom").DeepImmutable<SharedDataItem<any>>; | ||
export declare function readDataItem(ctx: Atom<GlobalState>, key: string): import("@dbeining/react-atom").DeepImmutable<import("../../types").SharedDataItem<any>>; | ||
export declare function readDataValue(ctx: Atom<GlobalState>, key: string): any; | ||
export declare function writeDataItem(this: EventEmitter, ctx: Atom<GlobalState>, key: string, value: any, owner: string, target: DataStoreTarget, expires: number): void; | ||
export declare function tryWriteDataItem(this: EventEmitter, ctx: Atom<GlobalState>, key: string, value: any, owner: string, target: DataStoreTarget, expires: number): boolean; |
@@ -10,5 +10,5 @@ "use strict"; | ||
function showPortal(ctx, id, entry) { | ||
react_atom_1.swap(ctx, state => (Object.assign({}, state, { portals: Object.assign({}, state.portals, { [id]: utils_1.includeItem(state.portals[id], entry) }) }))); | ||
react_atom_1.swap(ctx, state => (Object.assign({}, state, { portals: utils_1.withKey(state.portals, id, utils_1.includeItem(state.portals[id], entry)) }))); | ||
} | ||
exports.showPortal = showPortal; | ||
//# sourceMappingURL=portal.js.map |
@@ -28,2 +28,3 @@ "use strict"; | ||
}, | ||
errorComponents: {}, | ||
registry: { | ||
@@ -30,0 +31,0 @@ extensions: {}, |
@@ -71,2 +71,15 @@ import { ComponentType } from 'react'; | ||
} | ||
/** | ||
* The error used when the exact type is unknown. | ||
*/ | ||
export interface UnknownErrorInfoProps { | ||
/** | ||
* The type of the error. | ||
*/ | ||
type: 'unknown'; | ||
/** | ||
* The provided error details. | ||
*/ | ||
error: any; | ||
} | ||
export interface Errors extends PiralCustomErrors { | ||
@@ -77,2 +90,3 @@ extension: ExtensionErrorInfoProps; | ||
not_found: NotFoundErrorInfoProps; | ||
unknown: UnknownErrorInfoProps; | ||
} | ||
@@ -79,0 +93,0 @@ export declare type ErrorInfoProps = UnionOf<Errors>; |
@@ -9,3 +9,3 @@ import { ComponentType, ReactPortal } from 'react'; | ||
import { SharedDataItem, DataStoreTarget } from './data'; | ||
import { ComponentConverters, LoadingIndicatorProps, ErrorInfoProps, RouterProps, LayoutProps } from './components'; | ||
import { ComponentConverters, LoadingIndicatorProps, ErrorInfoProps, RouterProps, LayoutProps, Errors } from './components'; | ||
import { PiralCustomActions, PiralCustomState, PiralCustomRegistryState, PiralCustomComponentsState } from './custom'; | ||
@@ -69,2 +69,5 @@ import { BaseComponentProps, PageComponentProps, ExtensionComponentProps, PiletsBag, Pilet } from './api'; | ||
} | ||
export declare type ErrorComponentsState = { | ||
[P in keyof Errors]?: ComponentType<Errors[P]>; | ||
}; | ||
export interface GlobalState extends PiralCustomState { | ||
@@ -76,2 +79,6 @@ /** | ||
/** | ||
* The relevant state for rendering errors of the app. | ||
*/ | ||
errorComponents: ErrorComponentsState; | ||
/** | ||
* The relevant state for rendering parts of the app. | ||
@@ -181,2 +188,8 @@ */ | ||
/** | ||
* Sets the error component to render. | ||
* @param type The type of the error. | ||
* @param component The component to use for rendering. | ||
*/ | ||
setErrorComponent<TKey extends keyof ErrorComponentsState>(type: TKey, component: ErrorComponentsState[TKey]): void; | ||
/** | ||
* Sets the common routes to render. | ||
@@ -183,0 +196,0 @@ * @param path The name of the component. |
@@ -1,2 +0,1 @@ | ||
import { Dict } from '../types'; | ||
export declare const removeIndicator: any; | ||
@@ -10,4 +9,4 @@ export declare function prependItem<T>(items: Array<T>, item: T): T[]; | ||
export declare function excludeOn<T>(items: Array<T>, predicate: (item: T) => boolean): T[]; | ||
export declare function updateKey<T>(obj: Dict<T>, key: string, value: T): Dict<T>; | ||
export declare function withKey<T>(obj: Dict<T>, key: string, value: T): Dict<T>; | ||
export declare function withoutKey<T>(obj: Dict<T>, key: string): Dict<T>; | ||
export declare function updateKey<T, TKey extends keyof T>(obj: T, key: TKey, value: T[TKey]): T; | ||
export declare function withKey<T, TKey extends keyof T>(obj: T, key: TKey, value: T[TKey]): T; | ||
export declare function withoutKey<T, TKey extends keyof T>(obj: T, key: TKey): T; |
import * as React from 'react'; | ||
export declare function defaultRender(children: React.ReactNode): JSX.Element; | ||
export declare function defaultRender(children: React.ReactNode, key?: string): JSX.Element; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const React = require("react"); | ||
function defaultRender(children) { | ||
return React.createElement(React.Fragment, null, children); | ||
function defaultRender(children, key) { | ||
return React.createElement(React.Fragment, { key: key }, children); | ||
} | ||
exports.defaultRender = defaultRender; | ||
//# sourceMappingURL=react.js.map |
{ | ||
"name": "piral-core", | ||
"version": "0.8.0-pre.685", | ||
"version": "0.8.0-pre.690", | ||
"description": "The core library for creating a Piral instance.", | ||
@@ -54,3 +54,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "a0879e95ecaaf8c0f492ae02e5246fb839e29ace" | ||
"gitHead": "fa9824bda8ba7cfefea60e9494f3b5f91a951b67" | ||
} |
@@ -11,4 +11,6 @@ export * from './components'; | ||
export * from './SetComponent'; | ||
export * from './SetError'; | ||
export * from './SetProvider'; | ||
export * from './SetRoute'; | ||
export * from './SwitchErrorInfo'; | ||
export * from './withApi'; |
import { ComponentType, cloneElement } from 'react'; | ||
import { swap, Atom } from '@dbeining/react-atom'; | ||
import { RouteComponentProps } from 'react-router-dom'; | ||
import { LayoutType, GlobalState, Pilet, ComponentsState } from '../../types'; | ||
import { withKey } from '../../utils'; | ||
import { LayoutType, GlobalState, Pilet, ComponentsState, ErrorComponentsState } from '../../types'; | ||
@@ -9,6 +10,3 @@ export function changeLayout(ctx: Atom<GlobalState>, current: LayoutType) { | ||
...state, | ||
app: { | ||
...state.app, | ||
layout: current, | ||
}, | ||
app: withKey(state.app, 'layout', current), | ||
})); | ||
@@ -36,9 +34,17 @@ } | ||
...state, | ||
components: { | ||
...state.components, | ||
[name]: component, | ||
}, | ||
components: withKey(state.components, name, component), | ||
})); | ||
} | ||
export function setErrorComponent<TKey extends keyof ErrorComponentsState>( | ||
ctx: Atom<GlobalState>, | ||
type: TKey, | ||
component: ErrorComponentsState[TKey], | ||
) { | ||
swap(ctx, state => ({ | ||
...state, | ||
errorComponents: withKey(state.errorComponents, type, component), | ||
})); | ||
} | ||
export function setRoute<T = {}>( | ||
@@ -51,6 +57,3 @@ ctx: Atom<GlobalState>, | ||
...state, | ||
routes: { | ||
...state.routes, | ||
[path]: component, | ||
}, | ||
routes: withKey(state.routes, path, component), | ||
})); | ||
@@ -57,0 +60,0 @@ } |
@@ -1,4 +0,4 @@ | ||
import { swap, Atom, deref, DeepImmutableObject } from '@dbeining/react-atom'; | ||
import { swap, Atom, deref } from '@dbeining/react-atom'; | ||
import { updateKey } from '../../utils'; | ||
import { GlobalState, SharedDataItem, DataStoreTarget, EventEmitter } from '../../types'; | ||
import { GlobalState, DataStoreTarget, EventEmitter } from '../../types'; | ||
@@ -41,3 +41,3 @@ export function resetData(ctx: Atom<GlobalState>) { | ||
...state, | ||
data: updateKey<SharedDataItem>(state.data, key, data), | ||
data: updateKey(state.data, key, data), | ||
})); | ||
@@ -63,3 +63,3 @@ | ||
) { | ||
const item: DeepImmutableObject<SharedDataItem> = readDataItem(ctx, key); | ||
const item = readDataItem(ctx, key); | ||
@@ -66,0 +66,0 @@ if (item && item.owner !== owner) { |
import { ReactPortal } from 'react'; | ||
import { swap, Atom } from '@dbeining/react-atom'; | ||
import { withoutKey, includeItem, withKey } from '../../utils'; | ||
import { GlobalState } from '../../types'; | ||
import { withoutKey, includeItem } from '../../utils'; | ||
@@ -16,7 +16,4 @@ export function destroyPortal(ctx: Atom<GlobalState>, id: string) { | ||
...state, | ||
portals: { | ||
...state.portals, | ||
[id]: includeItem(state.portals[id], entry), | ||
}, | ||
portals: withKey(state.portals, id, includeItem(state.portals[id], entry)), | ||
})); | ||
} |
@@ -17,2 +17,3 @@ import { deref } from '@dbeining/react-atom'; | ||
}, | ||
errorComponents: {}, | ||
components: { | ||
@@ -43,2 +44,3 @@ ErrorInfo: DefaultErrorInfo, | ||
}, | ||
errorComponents: {}, | ||
components: { | ||
@@ -73,2 +75,3 @@ ErrorInfo: DefaultErrorInfo, | ||
}, | ||
errorComponents: {}, | ||
components: { | ||
@@ -99,2 +102,3 @@ ErrorInfo: DefaultErrorInfo, | ||
}, | ||
errorComponents: {}, | ||
components: { | ||
@@ -127,2 +131,3 @@ ErrorInfo: DefaultErrorInfo, | ||
}, | ||
errorComponents: {}, | ||
components: { | ||
@@ -155,2 +160,3 @@ ErrorInfo: DefaultErrorInfo, | ||
}, | ||
errorComponents: {}, | ||
components: { | ||
@@ -189,2 +195,3 @@ ErrorInfo: DefaultErrorInfo, | ||
}, | ||
errorComponents: {}, | ||
components: { | ||
@@ -191,0 +198,0 @@ ErrorInfo: DefaultErrorInfo, |
@@ -30,2 +30,3 @@ import { Atom, addChangeHandler } from '@dbeining/react-atom'; | ||
}, | ||
errorComponents: {}, | ||
registry: { | ||
@@ -32,0 +33,0 @@ extensions: {}, |
@@ -80,2 +80,16 @@ import { ComponentType } from 'react'; | ||
/** | ||
* The error used when the exact type is unknown. | ||
*/ | ||
export interface UnknownErrorInfoProps { | ||
/** | ||
* The type of the error. | ||
*/ | ||
type: 'unknown'; | ||
/** | ||
* The provided error details. | ||
*/ | ||
error: any; | ||
} | ||
export interface Errors extends PiralCustomErrors { | ||
@@ -86,2 +100,3 @@ extension: ExtensionErrorInfoProps; | ||
not_found: NotFoundErrorInfoProps; | ||
unknown: UnknownErrorInfoProps; | ||
} | ||
@@ -88,0 +103,0 @@ |
@@ -9,3 +9,10 @@ import { ComponentType, ReactPortal } from 'react'; | ||
import { SharedDataItem, DataStoreTarget } from './data'; | ||
import { ComponentConverters, LoadingIndicatorProps, ErrorInfoProps, RouterProps, LayoutProps } from './components'; | ||
import { | ||
ComponentConverters, | ||
LoadingIndicatorProps, | ||
ErrorInfoProps, | ||
RouterProps, | ||
LayoutProps, | ||
Errors, | ||
} from './components'; | ||
import { PiralCustomActions, PiralCustomState, PiralCustomRegistryState, PiralCustomComponentsState } from './custom'; | ||
@@ -77,2 +84,6 @@ import { BaseComponentProps, PageComponentProps, ExtensionComponentProps, PiletsBag, Pilet } from './api'; | ||
export type ErrorComponentsState = { | ||
[P in keyof Errors]?: ComponentType<Errors[P]>; | ||
}; | ||
export interface GlobalState extends PiralCustomState { | ||
@@ -84,2 +95,6 @@ /** | ||
/** | ||
* The relevant state for rendering errors of the app. | ||
*/ | ||
errorComponents: ErrorComponentsState; | ||
/** | ||
* The relevant state for rendering parts of the app. | ||
@@ -189,2 +204,8 @@ */ | ||
/** | ||
* Sets the error component to render. | ||
* @param type The type of the error. | ||
* @param component The component to use for rendering. | ||
*/ | ||
setErrorComponent<TKey extends keyof ErrorComponentsState>(type: TKey, component: ErrorComponentsState[TKey]): void; | ||
/** | ||
* Sets the common routes to render. | ||
@@ -191,0 +212,0 @@ * @param path The name of the component. |
@@ -1,3 +0,1 @@ | ||
import { Dict } from '../types'; | ||
// tslint:disable-next-line | ||
@@ -34,7 +32,7 @@ export const removeIndicator = null; | ||
export function updateKey<T>(obj: Dict<T>, key: string, value: T): Dict<T> { | ||
export function updateKey<T, TKey extends keyof T>(obj: T, key: TKey, value: T[TKey]): T { | ||
return value === removeIndicator ? withoutKey(obj, key) : withKey(obj, key, value); | ||
} | ||
export function withKey<T>(obj: Dict<T>, key: string, value: T): Dict<T> { | ||
export function withKey<T, TKey extends keyof T>(obj: T, key: TKey, value: T[TKey]): T { | ||
return { | ||
@@ -46,5 +44,5 @@ ...obj, | ||
export function withoutKey<T>(obj: Dict<T>, key: string): Dict<T> { | ||
export function withoutKey<T, TKey extends keyof T>(obj: T, key: TKey): T { | ||
const { [key]: _, ...newObj } = obj || {}; | ||
return newObj; | ||
return newObj as any; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
273244
306
6288