piral-page-layouts 1.10.0-beta.8462 → 1.10.0-beta.8470

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.
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"actions.js","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAsB,MAAM,YAAY,CAAC;AAIrE,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,5 +1,5 @@
1
- import * as actions from './actions';
2
1
  import { withApi } from 'piral-core';
2
+ import * as actions from './actions';
3
3
  import { getPageLayouts, withPageLayouts } from './utils';
4
4
  /**
5
5
  * Creates new Pilet API extensions for dealing with page layouts.
package/lib/create.js.map CHANGED
@@ -1 +1 @@
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,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CAAC;AACJ,CAAC"}
package/lib/utils.js CHANGED
@@ -1,14 +1,17 @@
1
1
  import { createElement, useEffect, useState } from 'react';
2
2
  import { defaultRender, useGlobalState, useGlobalStateContext, } from 'piral-core';
3
3
  const DefaultLayout = (props) => defaultRender(props.children);
4
+ function findLayout(paths, path, fallback) {
5
+ const data = paths.find((m) => m.matcher.test(path));
6
+ return data?.meta?.layout || fallback;
7
+ }
4
8
  function createPageWrapper(Routes, fallback = 'default') {
5
9
  return (props) => {
6
10
  const { navigation } = useGlobalStateContext();
7
- const [layout, setLayout] = useState(fallback);
11
+ const [layout, setLayout] = useState(() => findLayout(props.paths, navigation.path, fallback));
8
12
  useEffect(() => {
9
13
  return navigation.listen(({ location }) => {
10
- const data = props.paths.find((m) => m.matcher.test(location.pathname));
11
- setLayout(data?.meta?.layout || fallback);
14
+ setLayout(findLayout(props.paths, location.pathname, fallback));
12
15
  });
13
16
  }, []);
14
17
  const registration = useGlobalState((s) => s.registry.pageLayouts[layout] || s.registry.pageLayouts[fallback]);
package/lib/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,aAAa,EAAqB,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC7F,OAAO,EAGL,aAAa,EACb,cAAc,EAGd,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAGpB,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,EAAE,UAAU,EAAE,GAAG,qBAAqB,EAAE,CAAC;QAC/C,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAE/C,SAAS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,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.10.0-beta.8462",
3
+ "version": "1.10.0-beta.8470",
4
4
  "description": "Plugin for providing different page layouts in Piral.",
5
5
  "keywords": [
6
6
  "piral",
@@ -50,7 +50,7 @@
50
50
  "test": "echo \"Error: run tests from root\" && exit 1"
51
51
  },
52
52
  "devDependencies": {
53
- "piral-core": "1.10.0-beta.8462"
53
+ "piral-core": "1.10.0-beta.8470"
54
54
  },
55
- "gitHead": "df185e8aafc71b1d78320624ebc4413aa809ddce"
55
+ "gitHead": "dd72d126bf871906cbf5fa19578e6365b3c36361"
56
56
  }
@@ -1 +1 @@
1
- var piralPageLayouts=(()=>{var m=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var c=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,o)=>(typeof require<"u"?require:e)[o]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var L=(t,e)=>{for(var o in e)m(t,o,{get:e[o],enumerable:!0})},w=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of R(e))!b.call(t,a)&&a!==o&&m(t,a,{get:()=>e[a],enumerable:!(r=S(e,a))||r.enumerable});return t};var G=t=>w(m({},"__esModule",{value:!0}),t);var W={};L(W,{createPageLayoutsApi:()=>E});var f={};L(f,{registerPageLayout:()=>x,unregisterPageLayout:()=>T});var P=c("piral-core");function x(t,e,o){t.dispatch(r=>({...r,registry:{...r.registry,pageLayouts:(0,P.withKey)(r.registry.pageLayouts,e,o)}}))}function T(t,e){t.dispatch(o=>({...o,registry:{...o.registry,pageLayouts:(0,P.withoutKey)(o.registry.pageLayouts,e)}}))}var d=c("piral-core");var u=c("react"),p=c("piral-core"),A=t=>(0,p.defaultRender)(t.children);function D(t,e="default"){return o=>{let{navigation:r}=(0,p.useGlobalStateContext)(),[a,i]=(0,u.useState)(e);(0,u.useEffect)(()=>r.listen(({location:s})=>{let y=o.paths.find(l=>l.matcher.test(s.pathname));i(y?.meta?.layout||e)}),[]);let n=(0,p.useGlobalState)(s=>s.registry.pageLayouts[a]||s.registry.pageLayouts[e])?.component||A;return(0,u.createElement)(n,o,(0,u.createElement)(t,o))}}function h(t){let e={};return t&&typeof t=="object"&&Object.keys(t).forEach(o=>{e[o]={pilet:void 0,component:t[o]}}),e}function C(t,e){return o=>({...o,components:{...o.components,RouteSwitch:D(o.components.RouteSwitch,e)},registry:{...o.registry,pageLayouts:t}})}function E(t={}){let{layouts:e={},fallback:o}=t;return r=>{let a=i=>r.readState(g=>g.registry.pageLayouts[i]);return r.defineActions(f),r.dispatch(C(h(e),o)),i=>{let g=i.meta.name;return{registerPageLayout(n,s){let y=a(n);if(!y||y.pilet===g){let l=(0,d.withApi)(r,s,i,"pageLayout");r.registerPageLayout(n,{component:l,pilet:g})}return()=>i.unregisterPageLayout(n)},unregisterPageLayout(n){a(n)?.pilet===g&&r.unregisterPageLayout(n)}}}}}return G(W);})();
1
+ var piralPageLayouts=(()=>{var P=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var y=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(o,e)=>(typeof require<"u"?require:o)[e]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var m=(t,o)=>{for(var e in o)P(t,e,{get:o[e],enumerable:!0})},A=(t,o,e,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of b(o))!w.call(t,a)&&a!==e&&P(t,a,{get:()=>o[a],enumerable:!(r=R(o,a))||r.enumerable});return t};var G=t=>A(P({},"__esModule",{value:!0}),t);var j={};m(j,{createPageLayoutsApi:()=>W});var C=y("piral-core");var l={};m(l,{registerPageLayout:()=>x,unregisterPageLayout:()=>T});var c=y("piral-core");function x(t,o,e){t.dispatch(r=>({...r,registry:{...r.registry,pageLayouts:(0,c.withKey)(r.registry.pageLayouts,o,e)}}))}function T(t,o){t.dispatch(e=>({...e,registry:{...e.registry,pageLayouts:(0,c.withoutKey)(e.registry.pageLayouts,o)}}))}var u=y("react"),g=y("piral-core"),D=t=>(0,g.defaultRender)(t.children);function L(t,o,e){return t.find(a=>a.matcher.test(o))?.meta?.layout||e}function E(t,o="default"){return e=>{let{navigation:r}=(0,g.useGlobalStateContext)(),[a,i]=(0,u.useState)(()=>L(e.paths,r.path,o));(0,u.useEffect)(()=>r.listen(({location:s})=>{i(L(e.paths,s.pathname,o))}),[]);let n=(0,g.useGlobalState)(s=>s.registry.pageLayouts[a]||s.registry.pageLayouts[o])?.component||D;return(0,u.createElement)(n,e,(0,u.createElement)(t,e))}}function h(t){let o={};return t&&typeof t=="object"&&Object.keys(t).forEach(e=>{o[e]={pilet:void 0,component:t[e]}}),o}function d(t,o){return e=>({...e,components:{...e.components,RouteSwitch:E(e.components.RouteSwitch,o)},registry:{...e.registry,pageLayouts:t}})}function W(t={}){let{layouts:o={},fallback:e}=t;return r=>{let a=i=>r.readState(p=>p.registry.pageLayouts[i]);return r.defineActions(l),r.dispatch(d(h(o),e)),i=>{let p=i.meta.name;return{registerPageLayout(n,s){let f=a(n);if(!f||f.pilet===p){let S=(0,C.withApi)(r,s,i,"pageLayout");r.registerPageLayout(n,{component:S,pilet:p})}return()=>i.unregisterPageLayout(n)},unregisterPageLayout(n){a(n)?.pilet===p&&r.unregisterPageLayout(n)}}}}}return G(j);})();
package/src/actions.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { withKey, withoutKey, GlobalStateContext } from 'piral-core';
2
+
2
3
  import type { PageLayoutRegistration } from './types';
3
4
 
4
5
  export function registerPageLayout(ctx: GlobalStateContext, name: string, value: PageLayoutRegistration) {
package/src/create.ts CHANGED
@@ -1,6 +1,7 @@
1
- import * as actions from './actions';
2
1
  import { ComponentType } from 'react';
3
2
  import { PiralPlugin, PageComponentProps, withApi } from 'piral-core';
3
+
4
+ import * as actions from './actions';
4
5
  import { getPageLayouts, withPageLayouts } from './utils';
5
6
  import type { PiletPageLayoutsApi } from './types';
6
7
 
package/src/utils.ts CHANGED
@@ -7,23 +7,29 @@ import {
7
7
  RouteSwitchProps,
8
8
  GlobalState,
9
9
  useGlobalStateContext,
10
+ AppPath,
10
11
  } from 'piral-core';
12
+
11
13
  import type { PageLayoutRegistration } from './types';
12
14
 
13
15
  const DefaultLayout: React.FC<PropsWithChildren> = (props) => defaultRender(props.children);
14
16
 
17
+ function findLayout(paths: Array<AppPath>, path: string, fallback: string) {
18
+ const data = paths.find((m) => m.matcher.test(path));
19
+ return data?.meta?.layout || fallback;
20
+ }
21
+
15
22
  function createPageWrapper(
16
23
  Routes: ComponentType<RouteSwitchProps>,
17
24
  fallback = 'default',
18
25
  ): ComponentType<RouteSwitchProps> {
19
26
  return (props) => {
20
27
  const { navigation } = useGlobalStateContext();
21
- const [layout, setLayout] = useState(fallback);
28
+ const [layout, setLayout] = useState(() => findLayout(props.paths, navigation.path, fallback));
22
29
 
23
30
  useEffect(() => {
24
31
  return navigation.listen(({ location }) => {
25
- const data = props.paths.find((m) => m.matcher.test(location.pathname));
26
- setLayout(data?.meta?.layout || fallback);
32
+ setLayout(findLayout(props.paths, location.pathname, fallback));
27
33
  });
28
34
  }, []);
29
35