piral-page-layouts 1.6.0-beta.7240 → 1.6.0-beta.7244

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 CHANGED
@@ -1,25 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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: (0, piral_core_1.withKey)(state.registry.pageLayouts, name, value),
7
+ pageLayouts: withKey(state.registry.pageLayouts, name, value),
11
8
  },
12
9
  }));
13
10
  }
14
- exports.registerPageLayout = registerPageLayout;
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: (0, piral_core_1.withoutKey)(state.registry.pageLayouts, name),
16
+ pageLayouts: withoutKey(state.registry.pageLayouts, name),
21
17
  },
22
18
  }));
23
19
  }
24
- exports.unregisterPageLayout = unregisterPageLayout;
25
20
  //# sourceMappingURL=actions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"actions.js","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":";;;AAAA,2CAAqE;AAGrE,SAAgB,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,IAAA,oBAAO,EAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,IAAI,EAAE,KAAK,CAAC;SAC9D;KACF,CAAC,CAAC,CAAC;AACN,CAAC;AARD,gDAQC;AAED,SAAgB,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,IAAA,uBAAU,EAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC;SAC1D;KACF,CAAC,CAAC,CAAC;AACN,CAAC;AARD,oDAQC"}
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createPageLayoutsApi = void 0;
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((0, utils_1.withPageLayouts)((0, utils_1.getPageLayouts)(layouts), fallback));
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 = (0, piral_core_1.withApi)(context, pageLayout, api, 'pageLayout');
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":";;;AAAA,qCAAqC;AAErC,2CAAsE;AACtE,mCAA0D;AAkB1D;;GAEG;AACH,SAAgB,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,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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/lib/index.js CHANGED
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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":";;;AAAA,mDAAyB;AACzB,kDAAwB"}
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
@@ -1,3 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
3
2
  //# sourceMappingURL=types.js.map
package/lib/utils.js CHANGED
@@ -1,21 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withPageLayouts = exports.getPageLayouts = void 0;
4
- const react_1 = require("react");
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 = (0, react_router_dom_1.useLocation)();
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 = (0, piral_core_1.useGlobalState)((s) => s.registry.pageLayouts[layout] || s.registry.pageLayouts[fallback]);
10
+ const registration = useGlobalState((s) => s.registry.pageLayouts[layout] || s.registry.pageLayouts[fallback]);
14
11
  const Layout = registration?.component || DefaultLayout;
15
- return (0, react_1.createElement)(Layout, props, (0, react_1.createElement)(Routes, props));
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
- exports.getPageLayouts = getPageLayouts;
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":";;;AAAA,iCAAwE;AACxE,uDAA+C;AAC/C,2CAAoH;AAGpH,MAAM,aAAa,GAAgC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,0BAAa,EAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAE5F,SAAS,iBAAiB,CACxB,MAAuC,EACvC,QAAQ,GAAG,SAAS;IAEpB,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,QAAQ,GAAG,IAAA,8BAAW,GAAE,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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MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAClC,OAAO,CAAC,IAAI,CAAC,GAAG;gBACd,KAAK,EAAE,SAAS;gBAChB,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC;aACvB,CAAC;QACJ,CAAC,CAAC,CAAC;KACJ;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,WAAyC,EAAE,QAAgB;IACzF,OAAO,CAAC,KAAkB,EAAe,EAAE,CAAC,CAAC;QAC3C,GAAG,KAAK;QACR,UAAU,EAAE;YACV,GAAG,KAAK,CAAC,UAAU;YACnB,WAAW,EAAE,iBAAiB,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,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.7240",
3
+ "version": "1.6.0-beta.7244",
4
4
  "description": "Plugin for providing different page layouts in Piral.",
5
5
  "keywords": [
6
6
  "piral",
@@ -17,29 +17,19 @@
17
17
  "author": "smapiot",
18
18
  "homepage": "https://piral.io",
19
19
  "license": "MIT",
20
- "module": "esm/index.js",
20
+ "module": "lib/index.js",
21
21
  "main": "lib/index.js",
22
22
  "typings": "lib/index.d.ts",
23
23
  "exports": {
24
- ".": {
25
- "import": "./esm/index.js",
26
- "require": "./lib/index.js"
27
- },
28
- "./esm/*": {
29
- "import": "./esm/*"
30
- },
24
+ ".": "./lib/index.js",
31
25
  "./lib/*": {
32
- "require": "./lib/*"
33
- },
34
- "./_/*": {
35
- "import": "./esm/*.js",
36
- "require": "./lib/*.js"
26
+ "import": "./lib/*",
27
+ "types": "./lib/*.d.ts"
37
28
  },
38
29
  "./package.json": "./package.json"
39
30
  },
40
31
  "sideEffects": false,
41
32
  "files": [
42
- "esm",
43
33
  "lib",
44
34
  "src",
45
35
  "piral-page-layouts.min.js"
@@ -53,16 +43,15 @@
53
43
  },
54
44
  "scripts": {
55
45
  "cleanup": "rimraf esm lib piral-page-layouts.min.js",
56
- "build": "yarn build:bundle && yarn build:commonjs && yarn build:esnext",
46
+ "build": "yarn build:bundle && yarn build:esnext",
57
47
  "build:bundle": "esbuild src/index.ts --outfile=piral-page-layouts.min.js --bundle --external:piral-core --external:react --minify --global-name=piralPageLayouts",
58
- "build:commonjs": "tsc --project tsconfig.json --outDir lib --module commonjs",
59
- "build:esnext": "tsc --project tsconfig.json --outDir esm --module esnext",
48
+ "build:esnext": "tsc --project tsconfig.json --outDir lib --module esnext",
60
49
  "typedoc": "typedoc --json ../../../docs/types/piral-page-layouts.json src --exclude \"src/**/*.test.*\"",
61
50
  "test": "echo \"Error: run tests from root\" && exit 1"
62
51
  },
63
52
  "devDependencies": {
64
- "piral-core": "1.6.0-beta.7240",
53
+ "piral-core": "1.6.0-beta.7244",
65
54
  "react-router-dom": "^5.2.0"
66
55
  },
67
- "gitHead": "2fd8ff47d9a7e0666e4e6bc1dc5a7ef45e8e9f39"
56
+ "gitHead": "65ac1291c3429dbf16079b4deb6138b24c5719f7"
68
57
  }
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
@@ -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,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@
1
- export * from './create';
2
- export * from './types';
3
- //# sourceMappingURL=index.js.map
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
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
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,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC/G,MAAM,MAAM,GAAG,YAAY,EAAE,SAAS,IAAI,aAAa,CAAC;QACxD,OAAO,aAAa,CAAC,MAAM,EAAE,KAAK,EAAE,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC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