piral-page-layouts 1.6.0-beta.7216 → 1.6.0-beta.7243
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/lib/actions.js +5 -10
- package/lib/actions.js.map +1 -1
- package/lib/create.js +6 -10
- package/lib/create.js.map +1 -1
- package/lib/index.js +2 -5
- package/lib/index.js.map +1 -1
- package/lib/types.js +1 -2
- package/lib/utils.js +9 -14
- package/lib/utils.js.map +1 -1
- package/package.json +8 -22
- package/esm/actions.d.ts +0 -4
- package/esm/actions.js +0 -20
- package/esm/actions.js.map +0 -1
- package/esm/create.d.ts +0 -21
- package/esm/create.js +0 -37
- package/esm/create.js.map +0 -1
- package/esm/index.d.ts +0 -2
- package/esm/index.js +0 -3
- package/esm/index.js.map +0 -1
- package/esm/types.d.ts +0 -72
- package/esm/types.js +0 -2
- package/esm/types.js.map +0 -1
- package/esm/utils.d.ts +0 -5
- package/esm/utils.js +0 -40
- package/esm/utils.js.map +0 -1
package/lib/actions.js
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.unregisterPageLayout = exports.registerPageLayout = void 0;
|
|
4
|
-
const piral_core_1 = require("piral-core");
|
|
5
|
-
function registerPageLayout(ctx, name, value) {
|
|
1
|
+
import { withKey, withoutKey } from 'piral-core';
|
|
2
|
+
export function registerPageLayout(ctx, name, value) {
|
|
6
3
|
ctx.dispatch((state) => ({
|
|
7
4
|
...state,
|
|
8
5
|
registry: {
|
|
9
6
|
...state.registry,
|
|
10
|
-
pageLayouts:
|
|
7
|
+
pageLayouts: withKey(state.registry.pageLayouts, name, value),
|
|
11
8
|
},
|
|
12
9
|
}));
|
|
13
10
|
}
|
|
14
|
-
|
|
15
|
-
function unregisterPageLayout(ctx, name) {
|
|
11
|
+
export function unregisterPageLayout(ctx, name) {
|
|
16
12
|
ctx.dispatch((state) => ({
|
|
17
13
|
...state,
|
|
18
14
|
registry: {
|
|
19
15
|
...state.registry,
|
|
20
|
-
pageLayouts:
|
|
16
|
+
pageLayouts: withoutKey(state.registry.pageLayouts, name),
|
|
21
17
|
},
|
|
22
18
|
}));
|
|
23
19
|
}
|
|
24
|
-
exports.unregisterPageLayout = unregisterPageLayout;
|
|
25
20
|
//# sourceMappingURL=actions.js.map
|
package/lib/actions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAsB,MAAM,YAAY,CAAC;AAGrE,MAAM,UAAU,kBAAkB,CAAC,GAAuB,EAAE,IAAY,EAAE,KAA6B;IACrG,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACvB,GAAG,KAAK;QACR,QAAQ,EAAE;YACR,GAAG,KAAK,CAAC,QAAQ;YACjB,WAAW,EAAE,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,IAAI,EAAE,KAAK,CAAC;SAC9D;KACF,CAAC,CAAC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,GAAuB,EAAE,IAAY;IACxE,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACvB,GAAG,KAAK;QACR,QAAQ,EAAE;YACR,GAAG,KAAK,CAAC,QAAQ;YACjB,WAAW,EAAE,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC;SAC1D;KACF,CAAC,CAAC,CAAC;AACN,CAAC"}
|
package/lib/create.js
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const actions = require("./actions");
|
|
5
|
-
const piral_core_1 = require("piral-core");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
1
|
+
import * as actions from './actions';
|
|
2
|
+
import { withApi } from 'piral-core';
|
|
3
|
+
import { getPageLayouts, withPageLayouts } from './utils';
|
|
7
4
|
/**
|
|
8
5
|
* Creates new Pilet API extensions for dealing with page layouts.
|
|
9
6
|
*/
|
|
10
|
-
function createPageLayoutsApi(config = {}) {
|
|
7
|
+
export function createPageLayoutsApi(config = {}) {
|
|
11
8
|
const { layouts = {}, fallback } = config;
|
|
12
9
|
return (context) => {
|
|
13
10
|
const findPageLayout = (name) => context.readState((s) => s.registry.pageLayouts[name]);
|
|
14
11
|
context.defineActions(actions);
|
|
15
|
-
context.dispatch(
|
|
12
|
+
context.dispatch(withPageLayouts(getPageLayouts(layouts), fallback));
|
|
16
13
|
return (api) => {
|
|
17
14
|
const pilet = api.meta.name;
|
|
18
15
|
return {
|
|
19
16
|
registerPageLayout(name, pageLayout) {
|
|
20
17
|
const current = findPageLayout(name);
|
|
21
18
|
if (!current || current.pilet === pilet) {
|
|
22
|
-
const component =
|
|
19
|
+
const component = withApi(context, pageLayout, api, 'pageLayout');
|
|
23
20
|
context.registerPageLayout(name, {
|
|
24
21
|
component,
|
|
25
22
|
pilet,
|
|
@@ -37,5 +34,4 @@ function createPageLayoutsApi(config = {}) {
|
|
|
37
34
|
};
|
|
38
35
|
};
|
|
39
36
|
}
|
|
40
|
-
exports.createPageLayoutsApi = createPageLayoutsApi;
|
|
41
37
|
//# sourceMappingURL=create.js.map
|
package/lib/create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,OAAO,EAAmC,OAAO,EAAE,MAAM,YAAY,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MA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AAC;qBACpC;gBACH,CAAC;aACF,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./create"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./types"), exports);
|
|
1
|
+
export * from './create';
|
|
2
|
+
export * from './types';
|
|
6
3
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
package/lib/types.js
CHANGED
package/lib/utils.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const react_router_dom_1 = require("react-router-dom");
|
|
6
|
-
const piral_core_1 = require("piral-core");
|
|
7
|
-
const DefaultLayout = (props) => (0, piral_core_1.defaultRender)(props.children);
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
import { useLocation } from 'react-router-dom';
|
|
3
|
+
import { defaultRender, useGlobalState } from 'piral-core';
|
|
4
|
+
const DefaultLayout = (props) => defaultRender(props.children);
|
|
8
5
|
function createPageWrapper(Routes, fallback = 'default') {
|
|
9
6
|
return (props) => {
|
|
10
|
-
const location =
|
|
7
|
+
const location = useLocation();
|
|
11
8
|
const data = props.paths.find((m) => m.matcher.test(location.pathname));
|
|
12
9
|
const layout = data?.meta?.layout || fallback;
|
|
13
|
-
const registration =
|
|
10
|
+
const registration = useGlobalState((s) => s.registry.pageLayouts[layout] || s.registry.pageLayouts[fallback]);
|
|
14
11
|
const Layout = registration?.component || DefaultLayout;
|
|
15
|
-
return
|
|
12
|
+
return createElement(Layout, props, createElement(Routes, props));
|
|
16
13
|
};
|
|
17
14
|
}
|
|
18
|
-
function getPageLayouts(items) {
|
|
15
|
+
export function getPageLayouts(items) {
|
|
19
16
|
const layouts = {};
|
|
20
17
|
if (items && typeof items === 'object') {
|
|
21
18
|
Object.keys(items).forEach((name) => {
|
|
@@ -27,8 +24,7 @@ function getPageLayouts(items) {
|
|
|
27
24
|
}
|
|
28
25
|
return layouts;
|
|
29
26
|
}
|
|
30
|
-
|
|
31
|
-
function withPageLayouts(pageLayouts, fallback) {
|
|
27
|
+
export function withPageLayouts(pageLayouts, fallback) {
|
|
32
28
|
return (state) => ({
|
|
33
29
|
...state,
|
|
34
30
|
components: {
|
|
@@ -41,5 +37,4 @@ function withPageLayouts(pageLayouts, fallback) {
|
|
|
41
37
|
},
|
|
42
38
|
});
|
|
43
39
|
}
|
|
44
|
-
exports.withPageLayouts = withPageLayouts;
|
|
45
40
|
//# sourceMappingURL=utils.js.map
|
package/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,aAAa,EAAqB,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAA4B,aAAa,EAAE,cAAc,EAAiC,MAAM,YAAY,CAAC;AAGpH,MAAM,aAAa,GAAgC,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAE5F,SAAS,iBAAiB,CACxB,MAAuC,EACvC,QAAQ,GAAG,SAAS;IAEpB,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC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W,EAAE,QAAQ,CAAC;SACvE;QACD,QAAQ,EAAE;YACR,GAAG,KAAK,CAAC,QAAQ;YACjB,WAAW;SACZ;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-page-layouts",
|
|
3
|
-
"version": "1.6.0-beta.
|
|
3
|
+
"version": "1.6.0-beta.7243",
|
|
4
4
|
"description": "Plugin for providing different page layouts in Piral.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"piral",
|
|
@@ -17,29 +17,16 @@
|
|
|
17
17
|
"author": "smapiot",
|
|
18
18
|
"homepage": "https://piral.io",
|
|
19
19
|
"license": "MIT",
|
|
20
|
-
"module": "
|
|
20
|
+
"module": "lib/index.js",
|
|
21
21
|
"main": "lib/index.js",
|
|
22
22
|
"typings": "lib/index.d.ts",
|
|
23
23
|
"exports": {
|
|
24
|
-
".":
|
|
25
|
-
|
|
26
|
-
"require": "./lib/index.js"
|
|
27
|
-
},
|
|
28
|
-
"./esm/*": {
|
|
29
|
-
"import": "./esm/*"
|
|
30
|
-
},
|
|
31
|
-
"./lib/*": {
|
|
32
|
-
"require": "./lib/*"
|
|
33
|
-
},
|
|
34
|
-
"./_/*": {
|
|
35
|
-
"import": "./esm/*.js",
|
|
36
|
-
"require": "./lib/*.js"
|
|
37
|
-
},
|
|
24
|
+
".": "./lib/index.js",
|
|
25
|
+
"./lib/*": "./lib/*",
|
|
38
26
|
"./package.json": "./package.json"
|
|
39
27
|
},
|
|
40
28
|
"sideEffects": false,
|
|
41
29
|
"files": [
|
|
42
|
-
"esm",
|
|
43
30
|
"lib",
|
|
44
31
|
"src",
|
|
45
32
|
"piral-page-layouts.min.js"
|
|
@@ -53,16 +40,15 @@
|
|
|
53
40
|
},
|
|
54
41
|
"scripts": {
|
|
55
42
|
"cleanup": "rimraf esm lib piral-page-layouts.min.js",
|
|
56
|
-
"build": "yarn build:bundle && yarn build:
|
|
43
|
+
"build": "yarn build:bundle && yarn build:esnext",
|
|
57
44
|
"build:bundle": "esbuild src/index.ts --outfile=piral-page-layouts.min.js --bundle --external:piral-core --external:react --minify --global-name=piralPageLayouts",
|
|
58
|
-
"build:
|
|
59
|
-
"build:esnext": "tsc --project tsconfig.json --outDir esm --module esnext",
|
|
45
|
+
"build:esnext": "tsc --project tsconfig.json --outDir lib --module esnext",
|
|
60
46
|
"typedoc": "typedoc --json ../../../docs/types/piral-page-layouts.json src --exclude \"src/**/*.test.*\"",
|
|
61
47
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
62
48
|
},
|
|
63
49
|
"devDependencies": {
|
|
64
|
-
"piral-core": "1.6.0-beta.
|
|
50
|
+
"piral-core": "1.6.0-beta.7243",
|
|
65
51
|
"react-router-dom": "^5.2.0"
|
|
66
52
|
},
|
|
67
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "bbb6e4f78c61b6ef753099a5b378ad2708565ce3"
|
|
68
54
|
}
|
package/esm/actions.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { GlobalStateContext } from 'piral-core';
|
|
2
|
-
import type { PageLayoutRegistration } from './types';
|
|
3
|
-
export declare function registerPageLayout(ctx: GlobalStateContext, name: string, value: PageLayoutRegistration): void;
|
|
4
|
-
export declare function unregisterPageLayout(ctx: GlobalStateContext, name: string): void;
|
package/esm/actions.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { withKey, withoutKey } from 'piral-core';
|
|
2
|
-
export function registerPageLayout(ctx, name, value) {
|
|
3
|
-
ctx.dispatch((state) => ({
|
|
4
|
-
...state,
|
|
5
|
-
registry: {
|
|
6
|
-
...state.registry,
|
|
7
|
-
pageLayouts: withKey(state.registry.pageLayouts, name, value),
|
|
8
|
-
},
|
|
9
|
-
}));
|
|
10
|
-
}
|
|
11
|
-
export function unregisterPageLayout(ctx, name) {
|
|
12
|
-
ctx.dispatch((state) => ({
|
|
13
|
-
...state,
|
|
14
|
-
registry: {
|
|
15
|
-
...state.registry,
|
|
16
|
-
pageLayouts: withoutKey(state.registry.pageLayouts, name),
|
|
17
|
-
},
|
|
18
|
-
}));
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=actions.js.map
|
package/esm/actions.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAsB,MAAM,YAAY,CAAC;AAGrE,MAAM,UAAU,kBAAkB,CAAC,GAAuB,EAAE,IAAY,EAAE,KAA6B;IACrG,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACvB,GAAG,KAAK;QACR,QAAQ,EAAE;YACR,GAAG,KAAK,CAAC,QAAQ;YACjB,WAAW,EAAE,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,IAAI,EAAE,KAAK,CAAC;SAC9D;KACF,CAAC,CAAC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,GAAuB,EAAE,IAAY;IACxE,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACvB,GAAG,KAAK;QACR,QAAQ,EAAE;YACR,GAAG,KAAK,CAAC,QAAQ;YACjB,WAAW,EAAE,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC;SAC1D;KACF,CAAC,CAAC,CAAC;AACN,CAAC"}
|
package/esm/create.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ComponentType } from 'react';
|
|
2
|
-
import { PiralPlugin, PageComponentProps } from 'piral-core';
|
|
3
|
-
import type { PiletPageLayoutsApi } from './types';
|
|
4
|
-
/**
|
|
5
|
-
* Available configuration options for the page layout plugin.
|
|
6
|
-
*/
|
|
7
|
-
export interface PageLayoutsConfig {
|
|
8
|
-
/**
|
|
9
|
-
* Defines the name of the layout that should be used by default,
|
|
10
|
-
* i.e., in case no layout was specified or found.
|
|
11
|
-
*/
|
|
12
|
-
fallback?: string;
|
|
13
|
-
/**
|
|
14
|
-
* Defines the initially available layouts that can be used.
|
|
15
|
-
*/
|
|
16
|
-
layouts?: Record<string, ComponentType<PageComponentProps>>;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Creates new Pilet API extensions for dealing with page layouts.
|
|
20
|
-
*/
|
|
21
|
-
export declare function createPageLayoutsApi(config?: PageLayoutsConfig): PiralPlugin<PiletPageLayoutsApi>;
|
package/esm/create.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import * as actions from './actions';
|
|
2
|
-
import { withApi } from 'piral-core';
|
|
3
|
-
import { getPageLayouts, withPageLayouts } from './utils';
|
|
4
|
-
/**
|
|
5
|
-
* Creates new Pilet API extensions for dealing with page layouts.
|
|
6
|
-
*/
|
|
7
|
-
export function createPageLayoutsApi(config = {}) {
|
|
8
|
-
const { layouts = {}, fallback } = config;
|
|
9
|
-
return (context) => {
|
|
10
|
-
const findPageLayout = (name) => context.readState((s) => s.registry.pageLayouts[name]);
|
|
11
|
-
context.defineActions(actions);
|
|
12
|
-
context.dispatch(withPageLayouts(getPageLayouts(layouts), fallback));
|
|
13
|
-
return (api) => {
|
|
14
|
-
const pilet = api.meta.name;
|
|
15
|
-
return {
|
|
16
|
-
registerPageLayout(name, pageLayout) {
|
|
17
|
-
const current = findPageLayout(name);
|
|
18
|
-
if (!current || current.pilet === pilet) {
|
|
19
|
-
const component = withApi(context, pageLayout, api, 'pageLayout');
|
|
20
|
-
context.registerPageLayout(name, {
|
|
21
|
-
component,
|
|
22
|
-
pilet,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return () => api.unregisterPageLayout(name);
|
|
26
|
-
},
|
|
27
|
-
unregisterPageLayout(name) {
|
|
28
|
-
const current = findPageLayout(name);
|
|
29
|
-
if (current?.pilet === pilet) {
|
|
30
|
-
context.unregisterPageLayout(name);
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=create.js.map
|
package/esm/create.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,OAAO,EAAmC,OAAO,EAAE,MAAM,YAAY,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAkB1D;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,SAA4B,EAAE;IACjE,MAAM,EAAE,OAAO,GAAG,EAAE,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;IAE1C,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,cAAc,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;QAEhG,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAE/B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;QAErE,OAAO,CAAC,GAAG,EAAE,EAAE;YACb,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;YAC5B,OAAO;gBACL,kBAAkB,CAAC,IAAI,EAAE,UAAU;oBACjC,MAAM,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;oBAErC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,KAAK,KAAK,KAAK,EAAE;wBACvC,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC;wBAClE,OAAO,CAAC,kBAAkB,CAAC,IAAI,EAAE;4BAC/B,SAAS;4BACT,KAAK;yBACN,CAAC,CAAC;qBACJ;oBAED,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC;gBAC9C,CAAC;gBACD,oBAAoB,CAAC,IAAI;oBACvB,MAAM,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;oBAErC,IAAI,OAAO,EAAE,KAAK,KAAK,KAAK,EAAE;wBAC5B,OAAO,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC;qBACpC;gBACH,CAAC;aACF,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
package/esm/index.d.ts
DELETED
package/esm/index.js
DELETED
package/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
package/esm/types.d.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type { PropsWithChildren } from 'react';
|
|
2
|
-
import type { RouteComponentProps } from 'react-router';
|
|
3
|
-
import type { AnyComponent, BaseRegistration, Dict, PageComponentProps, PiralPageMeta, RegistrationDisposer, WrappedComponent } from 'piral-core';
|
|
4
|
-
declare module 'piral-core/lib/types/custom' {
|
|
5
|
-
interface PiletCustomApi extends PiletPageLayoutsApi {
|
|
6
|
-
}
|
|
7
|
-
interface PiralCustomActions {
|
|
8
|
-
/**
|
|
9
|
-
* Registers a new page layout.
|
|
10
|
-
* @param name The name of the layout.
|
|
11
|
-
* @param value The page layout registration.
|
|
12
|
-
*/
|
|
13
|
-
registerPageLayout(name: string, value: PageLayoutRegistration): void;
|
|
14
|
-
/**
|
|
15
|
-
* Unregisters an existing page layout.
|
|
16
|
-
* @param name The name of the page layout to be removed.
|
|
17
|
-
*/
|
|
18
|
-
unregisterPageLayout(name: string): void;
|
|
19
|
-
}
|
|
20
|
-
interface PiralCustomPageMeta {
|
|
21
|
-
/**
|
|
22
|
-
* The layout to use for the page.
|
|
23
|
-
*/
|
|
24
|
-
layout?: string;
|
|
25
|
-
}
|
|
26
|
-
interface PiralCustomRegistryState {
|
|
27
|
-
/**
|
|
28
|
-
* The registered page layouts.
|
|
29
|
-
*/
|
|
30
|
-
pageLayouts: Dict<PageLayoutRegistration>;
|
|
31
|
-
}
|
|
32
|
-
interface PiralCustomErrors {
|
|
33
|
-
pageLayout: PageLayoutErrorInfoProps;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
export interface PageLayoutRegistration extends BaseRegistration {
|
|
37
|
-
component: WrappedComponent<PageComponentProps>;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* The error used when a page layout crashed.
|
|
41
|
-
*/
|
|
42
|
-
export interface PageLayoutErrorInfoProps extends RouteComponentProps {
|
|
43
|
-
/**
|
|
44
|
-
* The type of the error.
|
|
45
|
-
*/
|
|
46
|
-
type: 'pageLayout';
|
|
47
|
-
/**
|
|
48
|
-
* The provided error details.
|
|
49
|
-
*/
|
|
50
|
-
error: any;
|
|
51
|
-
/**
|
|
52
|
-
* The available page meta data.
|
|
53
|
-
*/
|
|
54
|
-
meta: PiralPageMeta;
|
|
55
|
-
/**
|
|
56
|
-
* The name of the pilet emitting the error.
|
|
57
|
-
*/
|
|
58
|
-
pilet?: string;
|
|
59
|
-
}
|
|
60
|
-
export interface PiletPageLayoutsApi {
|
|
61
|
-
/**
|
|
62
|
-
* Registers a page layout.
|
|
63
|
-
* @param name The name of the layout.
|
|
64
|
-
* @param layout The component responsible for the layout.
|
|
65
|
-
*/
|
|
66
|
-
registerPageLayout(name: string, layout: AnyComponent<PropsWithChildren<PageComponentProps>>): RegistrationDisposer;
|
|
67
|
-
/**
|
|
68
|
-
* Unregisters a page layout.
|
|
69
|
-
* @param name The name of the layout.
|
|
70
|
-
*/
|
|
71
|
-
unregisterPageLayout(name: string): void;
|
|
72
|
-
}
|
package/esm/types.js
DELETED
package/esm/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/esm/utils.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { ComponentType } from 'react';
|
|
2
|
-
import { PageComponentProps, Dict, GlobalState } from 'piral-core';
|
|
3
|
-
import type { PageLayoutRegistration } from './types';
|
|
4
|
-
export declare function getPageLayouts(items: Record<string, ComponentType<PageComponentProps>>): Dict<PageLayoutRegistration>;
|
|
5
|
-
export declare function withPageLayouts(pageLayouts: Dict<PageLayoutRegistration>, fallback: string): (state: GlobalState) => GlobalState;
|
package/esm/utils.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { createElement } from 'react';
|
|
2
|
-
import { useLocation } from 'react-router-dom';
|
|
3
|
-
import { defaultRender, useGlobalState } from 'piral-core';
|
|
4
|
-
const DefaultLayout = (props) => defaultRender(props.children);
|
|
5
|
-
function createPageWrapper(Routes, fallback = 'default') {
|
|
6
|
-
return (props) => {
|
|
7
|
-
const location = useLocation();
|
|
8
|
-
const data = props.paths.find((m) => m.matcher.test(location.pathname));
|
|
9
|
-
const layout = data?.meta?.layout || fallback;
|
|
10
|
-
const registration = useGlobalState((s) => s.registry.pageLayouts[layout] || s.registry.pageLayouts[fallback]);
|
|
11
|
-
const Layout = registration?.component || DefaultLayout;
|
|
12
|
-
return createElement(Layout, props, createElement(Routes, props));
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export function getPageLayouts(items) {
|
|
16
|
-
const layouts = {};
|
|
17
|
-
if (items && typeof items === 'object') {
|
|
18
|
-
Object.keys(items).forEach((name) => {
|
|
19
|
-
layouts[name] = {
|
|
20
|
-
pilet: undefined,
|
|
21
|
-
component: items[name],
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return layouts;
|
|
26
|
-
}
|
|
27
|
-
export function withPageLayouts(pageLayouts, fallback) {
|
|
28
|
-
return (state) => ({
|
|
29
|
-
...state,
|
|
30
|
-
components: {
|
|
31
|
-
...state.components,
|
|
32
|
-
RouteSwitch: createPageWrapper(state.components.RouteSwitch, fallback),
|
|
33
|
-
},
|
|
34
|
-
registry: {
|
|
35
|
-
...state.registry,
|
|
36
|
-
pageLayouts,
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=utils.js.map
|
package/esm/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,aAAa,EAAqB,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAA4B,aAAa,EAAE,cAAc,EAAiC,MAAM,YAAY,CAAC;AAGpH,MAAM,aAAa,GAAgC,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAE5F,SAAS,iBAAiB,CACxB,MAAuC,EACvC,QAAQ,GAAG,SAAS;IAEpB,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;QACxE,MAAM,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,IAAI,QAAQ,CAAC;QAC9C,MAAM,YAAY,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,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