@btst/stack 3.0.2 → 3.1.0-rc.1

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.
Files changed (55) hide show
  1. package/dist/context/index.d.cts +3 -1
  2. package/dist/context/index.d.mts +3 -1
  3. package/dist/context/index.d.ts +3 -1
  4. package/dist/packages/stack/src/context/auth.cjs +20 -14
  5. package/dist/packages/stack/src/context/auth.mjs +20 -14
  6. package/dist/packages/stack/src/context/provider.cjs +42 -22
  7. package/dist/packages/stack/src/context/provider.mjs +43 -23
  8. package/dist/packages/stack/src/plugins/blog/client/components/pages/home-page.cjs +32 -28
  9. package/dist/packages/stack/src/plugins/blog/client/components/pages/home-page.mjs +32 -29
  10. package/dist/packages/stack/src/plugins/blog/client/components/pages/post-page.cjs +53 -47
  11. package/dist/packages/stack/src/plugins/blog/client/components/pages/post-page.mjs +53 -48
  12. package/dist/packages/stack/src/plugins/blog/client/components/pages/tag-page.cjs +30 -24
  13. package/dist/packages/stack/src/plugins/blog/client/components/pages/tag-page.mjs +30 -25
  14. package/dist/plugins/blog/client/components/index.d.cts +6 -10
  15. package/dist/plugins/blog/client/components/index.d.mts +6 -10
  16. package/dist/plugins/blog/client/components/index.d.ts +6 -10
  17. package/dist/plugins/blog/client/pages/post.cjs +9 -0
  18. package/dist/plugins/blog/client/pages/post.d.cts +8 -0
  19. package/dist/plugins/blog/client/pages/post.d.mts +8 -0
  20. package/dist/plugins/blog/client/pages/post.d.ts +8 -0
  21. package/dist/plugins/blog/client/pages/post.mjs +7 -0
  22. package/dist/plugins/blog/client/pages/posts.cjs +9 -0
  23. package/dist/plugins/blog/client/pages/posts.d.cts +8 -0
  24. package/dist/plugins/blog/client/pages/posts.d.mts +8 -0
  25. package/dist/plugins/blog/client/pages/posts.d.ts +8 -0
  26. package/dist/plugins/blog/client/pages/posts.mjs +7 -0
  27. package/dist/plugins/blog/client/pages/tag.cjs +9 -0
  28. package/dist/plugins/blog/client/pages/tag.d.cts +8 -0
  29. package/dist/plugins/blog/client/pages/tag.d.mts +8 -0
  30. package/dist/plugins/blog/client/pages/tag.d.ts +8 -0
  31. package/dist/plugins/blog/client/pages/tag.mjs +7 -0
  32. package/dist/plugins/form-builder/api/index.d.cts +1 -1
  33. package/dist/plugins/form-builder/api/index.d.mts +1 -1
  34. package/dist/plugins/form-builder/api/index.d.ts +1 -1
  35. package/dist/plugins/form-builder/client/hooks/index.d.cts +1 -1
  36. package/dist/plugins/form-builder/client/hooks/index.d.mts +1 -1
  37. package/dist/plugins/form-builder/client/hooks/index.d.ts +1 -1
  38. package/dist/plugins/form-builder/query-keys.d.cts +1 -1
  39. package/dist/plugins/form-builder/query-keys.d.mts +1 -1
  40. package/dist/plugins/form-builder/query-keys.d.ts +1 -1
  41. package/package.json +41 -2
  42. package/src/__tests__/provider-hydration.test.tsx +164 -0
  43. package/src/context/auth.tsx +21 -14
  44. package/src/context/provider.tsx +51 -28
  45. package/src/plugins/blog/__tests__/page-load-error.test.tsx +53 -0
  46. package/src/plugins/blog/__tests__/page-loading.test.tsx +106 -0
  47. package/src/plugins/blog/client/components/pages/home-page.tsx +39 -35
  48. package/src/plugins/blog/client/components/pages/post-page.tsx +62 -54
  49. package/src/plugins/blog/client/components/pages/tag-page.tsx +35 -29
  50. package/src/plugins/blog/client/pages/post.tsx +7 -0
  51. package/src/plugins/blog/client/pages/posts.tsx +7 -0
  52. package/src/plugins/blog/client/pages/tag.tsx +7 -0
  53. package/dist/shared/{stack.D20bOqfr.d.ts → stack.BuxUQqL8.d.ts} +20 -20
  54. package/dist/shared/{stack.AWSs6TXN.d.cts → stack.CX83YNuS.d.cts} +20 -20
  55. package/dist/shared/{stack.HB5uGLpE.d.mts → stack.Egr3RWhA.d.mts} +20 -20
@@ -123,6 +123,8 @@ type StackProviderServices = {
123
123
  notify?: StackNotifyProvider;
124
124
  i18n?: StackI18nProvider;
125
125
  };
126
+ /** Plugin override configuration inferred from a resolved client stack. */
127
+ type ClientStackOverrides<TStack extends ResolvedClientStack<any, any>> = InferredPluginOverrides<RegisteredClientPlugins<TStack>>;
126
128
  type CanonicalStackProviderOverrideProps<TStack extends ResolvedClientStack<any, any>> = InferredPluginOverrides<NoInfer<RegisteredClientPlugins<TStack>>> extends infer TOverrides extends Record<string, any> ? {} extends TOverrides ? {
127
129
  overrides?: TOverrides;
128
130
  } : {
@@ -339,4 +341,4 @@ type TranslateFn = (key: string, defaultValue: string, params?: Record<string, u
339
341
  declare function useTranslate(): TranslateFn;
340
342
 
341
343
  export { PermissionAccess, PermissionCheck, StackApiConfig, StackClientAuth, StackIdentity, StackProvider, StackRouter, StackRouterConfig, defaultNotifyProvider, useBasePath, useIdentity, useIdentityResolutionPromise, useIdentitySourceGeneration, useNotify, usePluginOverrides, usePluginSiteNavigation, useStack, useStackOrNull, useTranslate };
342
- export type { NotifyOptions, PermissionCheckState, StackI18nProvider, StackNotifyProvider, TranslateFn };
344
+ export type { ClientStackOverrides, NotifyOptions, PermissionCheckState, StackI18nProvider, StackNotifyProvider, TranslateFn };
@@ -123,6 +123,8 @@ type StackProviderServices = {
123
123
  notify?: StackNotifyProvider;
124
124
  i18n?: StackI18nProvider;
125
125
  };
126
+ /** Plugin override configuration inferred from a resolved client stack. */
127
+ type ClientStackOverrides<TStack extends ResolvedClientStack<any, any>> = InferredPluginOverrides<RegisteredClientPlugins<TStack>>;
126
128
  type CanonicalStackProviderOverrideProps<TStack extends ResolvedClientStack<any, any>> = InferredPluginOverrides<NoInfer<RegisteredClientPlugins<TStack>>> extends infer TOverrides extends Record<string, any> ? {} extends TOverrides ? {
127
129
  overrides?: TOverrides;
128
130
  } : {
@@ -339,4 +341,4 @@ type TranslateFn = (key: string, defaultValue: string, params?: Record<string, u
339
341
  declare function useTranslate(): TranslateFn;
340
342
 
341
343
  export { PermissionAccess, PermissionCheck, StackApiConfig, StackClientAuth, StackIdentity, StackProvider, StackRouter, StackRouterConfig, defaultNotifyProvider, useBasePath, useIdentity, useIdentityResolutionPromise, useIdentitySourceGeneration, useNotify, usePluginOverrides, usePluginSiteNavigation, useStack, useStackOrNull, useTranslate };
342
- export type { NotifyOptions, PermissionCheckState, StackI18nProvider, StackNotifyProvider, TranslateFn };
344
+ export type { ClientStackOverrides, NotifyOptions, PermissionCheckState, StackI18nProvider, StackNotifyProvider, TranslateFn };
@@ -123,6 +123,8 @@ type StackProviderServices = {
123
123
  notify?: StackNotifyProvider;
124
124
  i18n?: StackI18nProvider;
125
125
  };
126
+ /** Plugin override configuration inferred from a resolved client stack. */
127
+ type ClientStackOverrides<TStack extends ResolvedClientStack<any, any>> = InferredPluginOverrides<RegisteredClientPlugins<TStack>>;
126
128
  type CanonicalStackProviderOverrideProps<TStack extends ResolvedClientStack<any, any>> = InferredPluginOverrides<NoInfer<RegisteredClientPlugins<TStack>>> extends infer TOverrides extends Record<string, any> ? {} extends TOverrides ? {
127
129
  overrides?: TOverrides;
128
130
  } : {
@@ -339,4 +341,4 @@ type TranslateFn = (key: string, defaultValue: string, params?: Record<string, u
339
341
  declare function useTranslate(): TranslateFn;
340
342
 
341
343
  export { PermissionAccess, PermissionCheck, StackApiConfig, StackClientAuth, StackIdentity, StackProvider, StackRouter, StackRouterConfig, defaultNotifyProvider, useBasePath, useIdentity, useIdentityResolutionPromise, useIdentitySourceGeneration, useNotify, usePluginOverrides, usePluginSiteNavigation, useStack, useStackOrNull, useTranslate };
342
- export type { NotifyOptions, PermissionCheckState, StackI18nProvider, StackNotifyProvider, TranslateFn };
344
+ export type { ClientStackOverrides, NotifyOptions, PermissionCheckState, StackI18nProvider, StackNotifyProvider, TranslateFn };
@@ -119,21 +119,27 @@ function StackAuthBoundary({
119
119
  if (initialIdentity !== void 0) return;
120
120
  void resolveIdentity(false);
121
121
  }, [initialIdentity, resolveIdentity]);
122
- return /* @__PURE__ */ jsxRuntime.jsx(
123
- AuthContext.Provider,
124
- {
125
- value: {
126
- provider,
127
- identity: currentState.identity,
128
- isPending: currentState.isPending,
129
- sourceGeneration: currentResolutionGeneration,
130
- ...currentState.error ? { error: currentState.error } : {},
131
- refetch,
132
- waitForResolution
133
- },
134
- children
135
- }
122
+ const value = React.useMemo(
123
+ () => ({
124
+ provider,
125
+ identity: currentState.identity,
126
+ isPending: currentState.isPending,
127
+ sourceGeneration: currentResolutionGeneration,
128
+ ...currentState.error ? { error: currentState.error } : {},
129
+ refetch,
130
+ waitForResolution
131
+ }),
132
+ [
133
+ provider,
134
+ currentState.identity,
135
+ currentState.isPending,
136
+ currentResolutionGeneration,
137
+ currentState.error,
138
+ refetch,
139
+ waitForResolution
140
+ ]
136
141
  );
142
+ return /* @__PURE__ */ jsxRuntime.jsx(AuthContext.Provider, { value, children });
137
143
  }
138
144
  function useAuthContext() {
139
145
  return React.useContext(AuthContext);
@@ -117,21 +117,27 @@ function StackAuthBoundary({
117
117
  if (initialIdentity !== void 0) return;
118
118
  void resolveIdentity(false);
119
119
  }, [initialIdentity, resolveIdentity]);
120
- return /* @__PURE__ */ jsx(
121
- AuthContext.Provider,
122
- {
123
- value: {
124
- provider,
125
- identity: currentState.identity,
126
- isPending: currentState.isPending,
127
- sourceGeneration: currentResolutionGeneration,
128
- ...currentState.error ? { error: currentState.error } : {},
129
- refetch,
130
- waitForResolution
131
- },
132
- children
133
- }
120
+ const value = useMemo(
121
+ () => ({
122
+ provider,
123
+ identity: currentState.identity,
124
+ isPending: currentState.isPending,
125
+ sourceGeneration: currentResolutionGeneration,
126
+ ...currentState.error ? { error: currentState.error } : {},
127
+ refetch,
128
+ waitForResolution
129
+ }),
130
+ [
131
+ provider,
132
+ currentState.identity,
133
+ currentState.isPending,
134
+ currentResolutionGeneration,
135
+ currentState.error,
136
+ refetch,
137
+ waitForResolution
138
+ ]
134
139
  );
140
+ return /* @__PURE__ */ jsx(AuthContext.Provider, { value, children });
135
141
  }
136
142
  function useAuthContext() {
137
143
  return useContext(AuthContext);
@@ -17,10 +17,20 @@ function stripUndefined(obj) {
17
17
  }
18
18
  return result;
19
19
  }
20
- function resolveStaticRouter(router) {
21
- if (!router) return void 0;
22
- const { useRouter: _useRouter, ...staticFields } = router;
23
- return stripUndefined(staticFields);
20
+ function useStaticRouter(router) {
21
+ const { Link, Image, navigate, refresh, getSearchParams, setSearchParams } = router ?? {};
22
+ const present = router !== void 0;
23
+ return React.useMemo(
24
+ () => present ? stripUndefined({
25
+ Link,
26
+ Image,
27
+ navigate,
28
+ refresh,
29
+ getSearchParams,
30
+ setSearchParams
31
+ }) : void 0,
32
+ [present, Link, Image, navigate, refresh, getSearchParams, setSearchParams]
33
+ );
24
34
  }
25
35
  function RouterBridge({
26
36
  useRouter,
@@ -29,11 +39,14 @@ function RouterBridge({
29
39
  children
30
40
  }) {
31
41
  const hookRouter = useRouter();
32
- const router = {
33
- ...staticRouter,
34
- ...stripUndefined(hookRouter)
35
- };
36
- return /* @__PURE__ */ jsxRuntime.jsx(StackContext.Provider, { value: { ...value, router }, children });
42
+ const context = React.useMemo(
43
+ () => ({
44
+ ...value,
45
+ router: { ...staticRouter, ...stripUndefined(hookRouter) }
46
+ }),
47
+ [value, staticRouter, hookRouter]
48
+ );
49
+ return /* @__PURE__ */ jsxRuntime.jsx(StackContext.Provider, { value: context, children });
37
50
  }
38
51
  function StackProvider({
39
52
  children,
@@ -46,18 +59,25 @@ function StackProvider({
46
59
  i18n: i18n$1
47
60
  }) {
48
61
  const projection = stack.provider;
49
- const staticRouter = resolveStaticRouter(router);
50
- const value = {
51
- overrides: overrides ?? {},
52
- basePath: projection.site.basePath,
53
- api: projection.api,
54
- site: projection.site,
55
- plugins: projection.plugins,
56
- queryClient: projection.queryClient,
57
- clientStackContext: stack.context,
58
- resolvedStack: stack,
59
- auth: auth$1
60
- };
62
+ const staticRouter = useStaticRouter(router);
63
+ const value = React.useMemo(
64
+ () => ({
65
+ overrides: overrides ?? {},
66
+ basePath: projection.site.basePath,
67
+ api: projection.api,
68
+ site: projection.site,
69
+ plugins: projection.plugins,
70
+ queryClient: projection.queryClient,
71
+ clientStackContext: stack.context,
72
+ resolvedStack: stack,
73
+ auth: auth$1
74
+ }),
75
+ [overrides, stack, auth$1]
76
+ );
77
+ const context = React.useMemo(
78
+ () => ({ ...value, router: staticRouter }),
79
+ [value, staticRouter]
80
+ );
61
81
  const content = auth$1 ? /* @__PURE__ */ jsxRuntime.jsx(auth.StackAuthBoundary, { provider: auth$1, initialIdentity, children }) : children;
62
82
  const stackTree = router?.useRouter ? /* @__PURE__ */ jsxRuntime.jsx(
63
83
  RouterBridge,
@@ -67,7 +87,7 @@ function StackProvider({
67
87
  value,
68
88
  children: content
69
89
  }
70
- ) : /* @__PURE__ */ jsxRuntime.jsx(StackContext.Provider, { value: { ...value, router: staticRouter }, children: content });
90
+ ) : /* @__PURE__ */ jsxRuntime.jsx(StackContext.Provider, { value: context, children: content });
71
91
  return /* @__PURE__ */ jsxRuntime.jsx(notify.StackNotifyBoundary, { notify: notify$1, children: /* @__PURE__ */ jsxRuntime.jsx(i18n.StackI18nBoundary, { i18n: i18n$1, children: stackTree }) });
72
92
  }
73
93
  function useStack() {
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx } from 'react/jsx-runtime';
3
- import { createContext, useContext } from 'react';
3
+ import { useMemo, createContext, useContext } from 'react';
4
4
  import { StackAuthBoundary } from './auth.mjs';
5
5
  import { StackI18nBoundary } from './i18n.mjs';
6
6
  import { StackNotifyBoundary } from './notify.mjs';
@@ -15,10 +15,20 @@ function stripUndefined(obj) {
15
15
  }
16
16
  return result;
17
17
  }
18
- function resolveStaticRouter(router) {
19
- if (!router) return void 0;
20
- const { useRouter: _useRouter, ...staticFields } = router;
21
- return stripUndefined(staticFields);
18
+ function useStaticRouter(router) {
19
+ const { Link, Image, navigate, refresh, getSearchParams, setSearchParams } = router ?? {};
20
+ const present = router !== void 0;
21
+ return useMemo(
22
+ () => present ? stripUndefined({
23
+ Link,
24
+ Image,
25
+ navigate,
26
+ refresh,
27
+ getSearchParams,
28
+ setSearchParams
29
+ }) : void 0,
30
+ [present, Link, Image, navigate, refresh, getSearchParams, setSearchParams]
31
+ );
22
32
  }
23
33
  function RouterBridge({
24
34
  useRouter,
@@ -27,11 +37,14 @@ function RouterBridge({
27
37
  children
28
38
  }) {
29
39
  const hookRouter = useRouter();
30
- const router = {
31
- ...staticRouter,
32
- ...stripUndefined(hookRouter)
33
- };
34
- return /* @__PURE__ */ jsx(StackContext.Provider, { value: { ...value, router }, children });
40
+ const context = useMemo(
41
+ () => ({
42
+ ...value,
43
+ router: { ...staticRouter, ...stripUndefined(hookRouter) }
44
+ }),
45
+ [value, staticRouter, hookRouter]
46
+ );
47
+ return /* @__PURE__ */ jsx(StackContext.Provider, { value: context, children });
35
48
  }
36
49
  function StackProvider({
37
50
  children,
@@ -44,18 +57,25 @@ function StackProvider({
44
57
  i18n
45
58
  }) {
46
59
  const projection = stack.provider;
47
- const staticRouter = resolveStaticRouter(router);
48
- const value = {
49
- overrides: overrides ?? {},
50
- basePath: projection.site.basePath,
51
- api: projection.api,
52
- site: projection.site,
53
- plugins: projection.plugins,
54
- queryClient: projection.queryClient,
55
- clientStackContext: stack.context,
56
- resolvedStack: stack,
57
- auth
58
- };
60
+ const staticRouter = useStaticRouter(router);
61
+ const value = useMemo(
62
+ () => ({
63
+ overrides: overrides ?? {},
64
+ basePath: projection.site.basePath,
65
+ api: projection.api,
66
+ site: projection.site,
67
+ plugins: projection.plugins,
68
+ queryClient: projection.queryClient,
69
+ clientStackContext: stack.context,
70
+ resolvedStack: stack,
71
+ auth
72
+ }),
73
+ [overrides, stack, auth]
74
+ );
75
+ const context = useMemo(
76
+ () => ({ ...value, router: staticRouter }),
77
+ [value, staticRouter]
78
+ );
59
79
  const content = auth ? /* @__PURE__ */ jsx(StackAuthBoundary, { provider: auth, initialIdentity, children }) : children;
60
80
  const stackTree = router?.useRouter ? /* @__PURE__ */ jsx(
61
81
  RouterBridge,
@@ -65,7 +85,7 @@ function StackProvider({
65
85
  value,
66
86
  children: content
67
87
  }
68
- ) : /* @__PURE__ */ jsx(StackContext.Provider, { value: { ...value, router: staticRouter }, children: content });
88
+ ) : /* @__PURE__ */ jsx(StackContext.Provider, { value: context, children: content });
69
89
  return /* @__PURE__ */ jsx(StackNotifyBoundary, { notify, children: /* @__PURE__ */ jsx(StackI18nBoundary, { i18n, children: stackTree }) });
70
90
  }
71
91
  function useStack() {
@@ -11,36 +11,40 @@ const index = require('../loading/index.cjs');
11
11
  const _404Page = require('./404-page.cjs');
12
12
  const plugins_blog_permissions = require('../../../../../../../../plugins/blog/permissions.cjs');
13
13
 
14
- const HomePage = React.lazy(
15
- () => import('./home-page.internal.cjs').then((m) => ({ default: m.HomePage }))
16
- );
17
- function HomePageComponent({
18
- published = true
19
- }) {
20
- const { onRouteError } = context.usePluginOverrides(constants.BLOG_PLUGIN_ID);
21
- return /* @__PURE__ */ jsxRuntime.jsx(
22
- components.ComposedRoute,
23
- {
24
- path: published ? "/blog" : "/blog/drafts",
25
- PageComponent: HomePage,
26
- ErrorComponent: defaultError.DefaultError,
27
- LoadingComponent: index.PostsLoading,
28
- NotFoundComponent: _404Page.NotFoundPage,
29
- permission: plugins_blog_permissions.blogPermissions.post.read({
30
- scope: published ? "published" : "drafts"
31
- }),
32
- props: { published },
33
- onError: (error) => {
34
- if (onRouteError) {
35
- onRouteError("posts", error, {
36
- path: published ? "/blog" : "/blog/drafts",
37
- isSSR: typeof window === "undefined",
38
- published
39
- });
14
+ function createHomePage(HomePage) {
15
+ function HomePageComponent2({ published = true }) {
16
+ const { onRouteError } = context.usePluginOverrides(constants.BLOG_PLUGIN_ID);
17
+ return /* @__PURE__ */ jsxRuntime.jsx(
18
+ components.ComposedRoute,
19
+ {
20
+ path: published ? "/blog" : "/blog/drafts",
21
+ PageComponent: HomePage,
22
+ ErrorComponent: defaultError.DefaultError,
23
+ LoadingComponent: index.PostsLoading,
24
+ NotFoundComponent: _404Page.NotFoundPage,
25
+ permission: plugins_blog_permissions.blogPermissions.post.read({
26
+ scope: published ? "published" : "drafts"
27
+ }),
28
+ props: { published },
29
+ onError: (error) => {
30
+ if (onRouteError) {
31
+ onRouteError("posts", error, {
32
+ path: published ? "/blog" : "/blog/drafts",
33
+ isSSR: typeof window === "undefined",
34
+ published
35
+ });
36
+ }
40
37
  }
41
38
  }
42
- }
43
- );
39
+ );
40
+ }
41
+ return HomePageComponent2;
44
42
  }
43
+ const HomePageComponent = createHomePage(
44
+ React.lazy(
45
+ () => import('./home-page.internal.cjs').then((m) => ({ default: m.HomePage }))
46
+ )
47
+ );
45
48
 
46
49
  exports.HomePageComponent = HomePageComponent;
50
+ exports.createHomePage = createHomePage;
@@ -9,36 +9,39 @@ import { PostsLoading } from '../loading/index.mjs';
9
9
  import { NotFoundPage } from './404-page.mjs';
10
10
  import { blogPermissions } from '../../../../../../../../plugins/blog/permissions.mjs';
11
11
 
12
- const HomePage = lazy(
13
- () => import('./home-page.internal.mjs').then((m) => ({ default: m.HomePage }))
14
- );
15
- function HomePageComponent({
16
- published = true
17
- }) {
18
- const { onRouteError } = usePluginOverrides(BLOG_PLUGIN_ID);
19
- return /* @__PURE__ */ jsx(
20
- ComposedRoute,
21
- {
22
- path: published ? "/blog" : "/blog/drafts",
23
- PageComponent: HomePage,
24
- ErrorComponent: DefaultError,
25
- LoadingComponent: PostsLoading,
26
- NotFoundComponent: NotFoundPage,
27
- permission: blogPermissions.post.read({
28
- scope: published ? "published" : "drafts"
29
- }),
30
- props: { published },
31
- onError: (error) => {
32
- if (onRouteError) {
33
- onRouteError("posts", error, {
34
- path: published ? "/blog" : "/blog/drafts",
35
- isSSR: typeof window === "undefined",
36
- published
37
- });
12
+ function createHomePage(HomePage) {
13
+ function HomePageComponent2({ published = true }) {
14
+ const { onRouteError } = usePluginOverrides(BLOG_PLUGIN_ID);
15
+ return /* @__PURE__ */ jsx(
16
+ ComposedRoute,
17
+ {
18
+ path: published ? "/blog" : "/blog/drafts",
19
+ PageComponent: HomePage,
20
+ ErrorComponent: DefaultError,
21
+ LoadingComponent: PostsLoading,
22
+ NotFoundComponent: NotFoundPage,
23
+ permission: blogPermissions.post.read({
24
+ scope: published ? "published" : "drafts"
25
+ }),
26
+ props: { published },
27
+ onError: (error) => {
28
+ if (onRouteError) {
29
+ onRouteError("posts", error, {
30
+ path: published ? "/blog" : "/blog/drafts",
31
+ isSSR: typeof window === "undefined",
32
+ published
33
+ });
34
+ }
38
35
  }
39
36
  }
40
- }
41
- );
37
+ );
38
+ }
39
+ return HomePageComponent2;
42
40
  }
41
+ const HomePageComponent = createHomePage(
42
+ lazy(
43
+ () => import('./home-page.internal.mjs').then((m) => ({ default: m.HomePage }))
44
+ )
45
+ );
43
46
 
44
- export { HomePageComponent };
47
+ export { HomePageComponent, createHomePage };
@@ -12,55 +12,61 @@ const _404Page = require('./404-page.cjs');
12
12
  const blogHooks = require('../../hooks/blog-hooks.cjs');
13
13
  const plugins_blog_permissions = require('../../../../../../../../plugins/blog/permissions.cjs');
14
14
 
15
- const PostPageContent = React.lazy(
16
- () => import('./post-page.internal.cjs').then((m) => ({ default: m.PostPage }))
17
- );
18
- function AuthorizedPostPage({ slug }) {
19
- const { post } = blogHooks.useSuspensePost(slug);
20
- const permission = post ? plugins_blog_permissions.blogPermissions.post.read({
21
- scope: "post",
22
- slug: post.slug,
23
- exists: true,
24
- id: post.id,
25
- ...post.authorId ? { authorId: post.authorId } : {},
26
- published: post.published
27
- }) : plugins_blog_permissions.blogPermissions.post.read({
28
- scope: "post",
29
- slug,
30
- exists: false,
31
- published: false
32
- });
33
- return /* @__PURE__ */ jsxRuntime.jsx(
34
- components.PermissionRouteAccess,
35
- {
36
- permission,
37
- LoadingComponent: index.PostLoading,
38
- children: /* @__PURE__ */ jsxRuntime.jsx(PostPageContent, { slug })
39
- }
40
- );
41
- }
42
- function PostPageComponent({ slug }) {
43
- const { onRouteError } = context.usePluginOverrides(constants.BLOG_PLUGIN_ID);
44
- return /* @__PURE__ */ jsxRuntime.jsx(
45
- components.ComposedRoute,
46
- {
47
- path: `/blog/${slug}`,
48
- PageComponent: AuthorizedPostPage,
49
- ErrorComponent: defaultError.DefaultError,
50
- LoadingComponent: index.PostLoading,
51
- NotFoundComponent: _404Page.NotFoundPage,
52
- props: { slug },
53
- onError: (error) => {
54
- if (onRouteError) {
55
- onRouteError("post", error, {
56
- path: `/blog/${slug}`,
57
- isSSR: typeof window === "undefined",
58
- slug
59
- });
15
+ function createPostPage(PostPageContent) {
16
+ function AuthorizedPostPage({ slug }) {
17
+ const { post } = blogHooks.useSuspensePost(slug);
18
+ const permission = post ? plugins_blog_permissions.blogPermissions.post.read({
19
+ scope: "post",
20
+ slug: post.slug,
21
+ exists: true,
22
+ id: post.id,
23
+ ...post.authorId ? { authorId: post.authorId } : {},
24
+ published: post.published
25
+ }) : plugins_blog_permissions.blogPermissions.post.read({
26
+ scope: "post",
27
+ slug,
28
+ exists: false,
29
+ published: false
30
+ });
31
+ return /* @__PURE__ */ jsxRuntime.jsx(
32
+ components.PermissionRouteAccess,
33
+ {
34
+ permission,
35
+ LoadingComponent: index.PostLoading,
36
+ children: /* @__PURE__ */ jsxRuntime.jsx(PostPageContent, { slug })
37
+ }
38
+ );
39
+ }
40
+ function PostPageComponent2({ slug }) {
41
+ const { onRouteError } = context.usePluginOverrides(constants.BLOG_PLUGIN_ID);
42
+ return /* @__PURE__ */ jsxRuntime.jsx(
43
+ components.ComposedRoute,
44
+ {
45
+ path: `/blog/${slug}`,
46
+ PageComponent: AuthorizedPostPage,
47
+ ErrorComponent: defaultError.DefaultError,
48
+ LoadingComponent: index.PostLoading,
49
+ NotFoundComponent: _404Page.NotFoundPage,
50
+ props: { slug },
51
+ onError: (error) => {
52
+ if (onRouteError) {
53
+ onRouteError("post", error, {
54
+ path: `/blog/${slug}`,
55
+ isSSR: typeof window === "undefined",
56
+ slug
57
+ });
58
+ }
60
59
  }
61
60
  }
62
- }
63
- );
61
+ );
62
+ }
63
+ return PostPageComponent2;
64
64
  }
65
+ const PostPageComponent = createPostPage(
66
+ React.lazy(
67
+ () => import('./post-page.internal.cjs').then((m) => ({ default: m.PostPage }))
68
+ )
69
+ );
65
70
 
66
71
  exports.PostPageComponent = PostPageComponent;
72
+ exports.createPostPage = createPostPage;