@redneckz/wildless-cms-uni-blocks 0.14.859 → 0.14.860

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 (121) hide show
  1. package/bundle/bundle.umd.js +1 -1
  2. package/bundle/bundle.umd.min.js +1 -1
  3. package/bundle/components/ContentPage/computeAPIFallback.d.ts +2 -1
  4. package/bundle/components/ContentPage/loadModuleFallback.d.ts +2 -0
  5. package/bundle/components/ContentPage/mapSlot.d.ts +2 -0
  6. package/bundle/components/ContentPage/normalizeBlock.d.ts +3 -0
  7. package/bundle/components/ContentPage/normalizeBlock.mobile.d.ts +3 -0
  8. package/bundle/components/ContentPage/normalizePage.d.ts +3 -0
  9. package/bundle/components/ContentPage/toMobileBlock.d.ts +2 -0
  10. package/bundle/model/Fallback.d.ts +1 -0
  11. package/dist/components/ContentPage/computeAPIFallback.d.ts +2 -1
  12. package/dist/components/ContentPage/computeAPIFallback.js +16 -2
  13. package/dist/components/ContentPage/computeAPIFallback.js.map +1 -1
  14. package/dist/components/ContentPage/loadModuleFallback.d.ts +2 -0
  15. package/dist/components/ContentPage/loadModuleFallback.js +36 -0
  16. package/dist/components/ContentPage/loadModuleFallback.js.map +1 -0
  17. package/dist/components/ContentPage/mapSlot.d.ts +2 -0
  18. package/dist/components/ContentPage/mapSlot.js +16 -0
  19. package/dist/components/ContentPage/mapSlot.js.map +1 -0
  20. package/dist/components/ContentPage/normalizeBlock.d.ts +3 -0
  21. package/dist/components/ContentPage/normalizeBlock.js +15 -0
  22. package/dist/components/ContentPage/normalizeBlock.js.map +1 -0
  23. package/dist/components/ContentPage/normalizeBlock.mobile.d.ts +3 -0
  24. package/dist/components/ContentPage/normalizeBlock.mobile.js +18 -0
  25. package/dist/components/ContentPage/normalizeBlock.mobile.js.map +1 -0
  26. package/dist/components/ContentPage/normalizePage.d.ts +3 -0
  27. package/dist/components/ContentPage/normalizePage.js +6 -0
  28. package/dist/components/ContentPage/normalizePage.js.map +1 -0
  29. package/dist/components/ContentPage/toMobileBlock.d.ts +2 -0
  30. package/dist/components/ContentPage/toMobileBlock.js +12 -0
  31. package/dist/components/ContentPage/toMobileBlock.js.map +1 -0
  32. package/dist/model/Fallback.d.ts +1 -0
  33. package/lib/common.css +1 -1
  34. package/lib/components/ContentPage/computeAPIFallback.d.ts +2 -1
  35. package/lib/components/ContentPage/computeAPIFallback.js +16 -2
  36. package/lib/components/ContentPage/computeAPIFallback.js.map +1 -1
  37. package/lib/components/ContentPage/loadModuleFallback.d.ts +2 -0
  38. package/lib/components/ContentPage/loadModuleFallback.js +10 -0
  39. package/lib/components/ContentPage/loadModuleFallback.js.map +1 -0
  40. package/lib/components/ContentPage/mapSlot.d.ts +2 -0
  41. package/lib/components/ContentPage/mapSlot.js +13 -0
  42. package/lib/components/ContentPage/mapSlot.js.map +1 -0
  43. package/lib/components/ContentPage/normalizeBlock.d.ts +3 -0
  44. package/lib/components/ContentPage/normalizeBlock.js +12 -0
  45. package/lib/components/ContentPage/normalizeBlock.js.map +1 -0
  46. package/lib/components/ContentPage/normalizeBlock.mobile.d.ts +3 -0
  47. package/lib/components/ContentPage/normalizeBlock.mobile.js +15 -0
  48. package/lib/components/ContentPage/normalizeBlock.mobile.js.map +1 -0
  49. package/lib/components/ContentPage/normalizePage.d.ts +3 -0
  50. package/lib/components/ContentPage/normalizePage.js +3 -0
  51. package/lib/components/ContentPage/normalizePage.js.map +1 -0
  52. package/lib/components/ContentPage/toMobileBlock.d.ts +2 -0
  53. package/lib/components/ContentPage/toMobileBlock.js +9 -0
  54. package/lib/components/ContentPage/toMobileBlock.js.map +1 -0
  55. package/lib/model/Fallback.d.ts +1 -0
  56. package/mobile/bundle/bundle.umd.js +1 -1
  57. package/mobile/bundle/bundle.umd.min.js +1 -1
  58. package/mobile/bundle/components/ContentPage/computeAPIFallback.d.ts +2 -1
  59. package/mobile/bundle/components/ContentPage/loadModuleFallback.d.ts +2 -0
  60. package/mobile/bundle/components/ContentPage/mapSlot.d.ts +2 -0
  61. package/mobile/bundle/components/ContentPage/normalizeBlock.d.ts +3 -0
  62. package/mobile/bundle/components/ContentPage/normalizePage.d.ts +3 -0
  63. package/mobile/bundle/components/ContentPage/toMobileBlock.d.ts +2 -0
  64. package/mobile/bundle/model/Fallback.d.ts +1 -0
  65. package/mobile/dist/components/ContentPage/computeAPIFallback.d.ts +2 -1
  66. package/mobile/dist/components/ContentPage/computeAPIFallback.js +16 -2
  67. package/mobile/dist/components/ContentPage/computeAPIFallback.js.map +1 -1
  68. package/mobile/dist/components/ContentPage/loadModuleFallback.d.ts +2 -0
  69. package/mobile/dist/components/ContentPage/loadModuleFallback.js +36 -0
  70. package/mobile/dist/components/ContentPage/loadModuleFallback.js.map +1 -0
  71. package/mobile/dist/components/ContentPage/mapSlot.d.ts +2 -0
  72. package/mobile/dist/components/ContentPage/mapSlot.js +16 -0
  73. package/mobile/dist/components/ContentPage/mapSlot.js.map +1 -0
  74. package/mobile/dist/components/ContentPage/normalizeBlock.d.ts +3 -0
  75. package/mobile/dist/components/ContentPage/normalizeBlock.js +18 -0
  76. package/mobile/dist/components/ContentPage/normalizeBlock.js.map +1 -0
  77. package/mobile/dist/components/ContentPage/normalizePage.d.ts +3 -0
  78. package/mobile/dist/components/ContentPage/normalizePage.js +6 -0
  79. package/mobile/dist/components/ContentPage/normalizePage.js.map +1 -0
  80. package/mobile/dist/components/ContentPage/toMobileBlock.d.ts +2 -0
  81. package/mobile/dist/components/ContentPage/toMobileBlock.js +12 -0
  82. package/mobile/dist/components/ContentPage/toMobileBlock.js.map +1 -0
  83. package/mobile/dist/model/Fallback.d.ts +1 -0
  84. package/mobile/lib/common.css +1 -1
  85. package/mobile/lib/components/ContentPage/computeAPIFallback.d.ts +2 -1
  86. package/mobile/lib/components/ContentPage/computeAPIFallback.js +16 -2
  87. package/mobile/lib/components/ContentPage/computeAPIFallback.js.map +1 -1
  88. package/mobile/lib/components/ContentPage/loadModuleFallback.d.ts +2 -0
  89. package/mobile/lib/components/ContentPage/loadModuleFallback.js +10 -0
  90. package/mobile/lib/components/ContentPage/loadModuleFallback.js.map +1 -0
  91. package/mobile/lib/components/ContentPage/mapSlot.d.ts +2 -0
  92. package/mobile/lib/components/ContentPage/mapSlot.js +13 -0
  93. package/mobile/lib/components/ContentPage/mapSlot.js.map +1 -0
  94. package/mobile/lib/components/ContentPage/normalizeBlock.d.ts +3 -0
  95. package/mobile/lib/components/ContentPage/normalizeBlock.js +15 -0
  96. package/mobile/lib/components/ContentPage/normalizeBlock.js.map +1 -0
  97. package/mobile/lib/components/ContentPage/normalizePage.d.ts +3 -0
  98. package/mobile/lib/components/ContentPage/normalizePage.js +3 -0
  99. package/mobile/lib/components/ContentPage/normalizePage.js.map +1 -0
  100. package/mobile/lib/components/ContentPage/toMobileBlock.d.ts +2 -0
  101. package/mobile/lib/components/ContentPage/toMobileBlock.js +9 -0
  102. package/mobile/lib/components/ContentPage/toMobileBlock.js.map +1 -0
  103. package/mobile/lib/model/Fallback.d.ts +1 -0
  104. package/mobile/src/components/ContentPage/computeAPIFallback.ts +35 -3
  105. package/mobile/src/components/ContentPage/loadModuleFallback.ts +11 -0
  106. package/mobile/src/components/ContentPage/mapSlot.ts +18 -0
  107. package/mobile/src/components/ContentPage/normalizeBlock.ts +25 -0
  108. package/mobile/src/components/ContentPage/normalizePage.ts +8 -0
  109. package/mobile/src/components/ContentPage/toMobileBlock.ts +11 -0
  110. package/mobile/src/model/Fallback.ts +1 -0
  111. package/package.json +1 -1
  112. package/src/components/ContentPage/ContentPage.fixture.mobile.tsx +4 -1
  113. package/src/components/ContentPage/ContentPage.fixture.tsx +7 -2
  114. package/src/components/ContentPage/computeAPIFallback.ts +35 -3
  115. package/src/components/ContentPage/loadModuleFallback.ts +11 -0
  116. package/src/components/ContentPage/mapSlot.ts +18 -0
  117. package/src/components/ContentPage/normalizeBlock.mobile.ts +25 -0
  118. package/src/components/ContentPage/normalizeBlock.ts +21 -0
  119. package/src/components/ContentPage/normalizePage.ts +8 -0
  120. package/src/components/ContentPage/toMobileBlock.ts +11 -0
  121. package/src/model/Fallback.ts +1 -0
@@ -1,21 +1,53 @@
1
1
  import { type JSONNode } from '@redneckz/json-op';
2
2
  import { collectRef, resolveJPointer } from '@redneckz/json-ref';
3
3
  import { ContentPageRepository } from '../../content-page-repository/ContentPageRepository';
4
+ import { type BlocksRegistry } from '../../model/BlocksRegistry';
4
5
  import { type ContentPageDef } from '../../model/ContentPageDef';
5
- import { type Fallback } from '../../model/Fallback';
6
+ import { type Fallback, type FallbackMap } from '../../model/Fallback';
6
7
  import { unique } from '../../utils/unique';
7
8
  import { joinPath } from '../../utils/url';
9
+ import { loadModuleFallback } from './loadModuleFallback';
8
10
 
9
11
  type FallbackEntry = [key: string, data: JSONNode];
10
12
 
11
13
  const BASE_DIR = 'content';
12
14
 
13
- export const computeAPIFallback = async (contentPageData: ContentPageDef): Promise<Fallback> => {
15
+ export const computeAPIFallback = async (
16
+ blocksRegistry: BlocksRegistry,
17
+ contentPageData: ContentPageDef,
18
+ ): Promise<Fallback> => {
14
19
  return Object.fromEntries(
15
- (await computeFallbackFromContentRefs(contentPageData)).filter(([key, data]) => key && data),
20
+ (
21
+ await Promise.all([
22
+ computeFallbackFromModules(blocksRegistry),
23
+ computeFallbackFromContentRefs(contentPageData),
24
+ ])
25
+ )
26
+ .flatMap((_) => _)
27
+ .filter(([key, data]) => key && data),
16
28
  );
17
29
  };
18
30
 
31
+ const computeFallbackFromModules = async (
32
+ blocksRegistry: BlocksRegistry,
33
+ ): Promise<FallbackEntry[]> => {
34
+ const fallbackMap: FallbackMap = (
35
+ await Promise.all(Object.keys(blocksRegistry).map(loadModuleFallback))
36
+ )
37
+ .filter((_): _ is FallbackMap => Boolean(_))
38
+ .reduce((acc, _) => ({ ...acc, ..._ }), {});
39
+
40
+ return (
41
+ await Promise.allSettled(
42
+ Object.entries(fallbackMap).map(
43
+ async ([key, fetcher]): Promise<FallbackEntry> => [key, await fetcher()],
44
+ ),
45
+ )
46
+ )
47
+ .filter((_): _ is PromiseFulfilledResult<FallbackEntry> => _.status === 'fulfilled')
48
+ .map(({ value }) => value);
49
+ };
50
+
19
51
  const computeFallbackFromContentRefs = async (
20
52
  contentPageData: ContentPageDef,
21
53
  ): Promise<FallbackEntry[]> => {
@@ -0,0 +1,11 @@
1
+ import { type FallbackMap } from '../../model/Fallback';
2
+
3
+ export const loadModuleFallback = async (blockName: string): Promise<FallbackMap | undefined> => {
4
+ try {
5
+ const blockFallback = await import(`../${blockName}/${blockName}.fallback`);
6
+
7
+ return blockFallback?.fallback ? await blockFallback.fallback() : undefined;
8
+ } catch (error) {
9
+ return undefined;
10
+ }
11
+ };
@@ -0,0 +1,18 @@
1
+ import { type BlockDef, type Slot } from '../../model/ContentPageDef';
2
+
3
+ export const mapSlot =
4
+ (mapper: (blocks?: BlockDef[]) => BlockDef[]) =>
5
+ <S extends Slot>(slot: S): S => ({
6
+ ...slot,
7
+ ...(slot.blocks ? { blocks: mapper(slot.blocks) } : {}),
8
+ ...(slot.slots
9
+ ? {
10
+ slots: Object.fromEntries(
11
+ Object.entries(slot.slots).map(([slotKey, slotBlocks]) => [
12
+ slotKey,
13
+ mapper(slotBlocks),
14
+ ]),
15
+ ),
16
+ }
17
+ : {}),
18
+ });
@@ -0,0 +1,25 @@
1
+ import { type BlocksRegistry } from '../../model/BlocksRegistry';
2
+ import { type BlockDef, type Slot } from '../../model/ContentPageDef';
3
+ import { mapSlot } from './mapSlot';
4
+ import { toMobileBlock } from './toMobileBlock';
5
+
6
+ export function normalizeBlock<S extends Slot>(block?: S, blocksRegistry?: BlocksRegistry): S {
7
+ const { mobile } = (block || {}) as BlockDef;
8
+
9
+ return mapSlot(filterBlocks(blocksRegistry))((mobile ? toMobileBlock(block) : block) || {}) as S;
10
+ }
11
+
12
+ const filterBlocks =
13
+ (blocksRegistry?: BlocksRegistry) =>
14
+ (blocks?: BlockDef[]): BlockDef[] =>
15
+ blocks
16
+ ? blocks
17
+ ?.filter(
18
+ (block) =>
19
+ blocksRegistry &&
20
+ (block?.type || block?.mobile?.type || '') in blocksRegistry &&
21
+ !block.mobile?.hidden &&
22
+ !block?.hidden,
23
+ )
24
+ .map((block) => normalizeBlock(block, blocksRegistry))
25
+ : [];
@@ -0,0 +1,8 @@
1
+ import { type BlocksRegistry } from '../../model/BlocksRegistry';
2
+ import { type ContentPageDef } from '../../model/ContentPageDef';
3
+ import { normalizeBlock } from './normalizeBlock';
4
+
5
+ export const normalizePage =
6
+ (blocksRegistry: BlocksRegistry) =>
7
+ (contentPage: ContentPageDef | undefined | null): ContentPageDef =>
8
+ contentPage ? normalizeBlock(contentPage, blocksRegistry) : {};
@@ -0,0 +1,11 @@
1
+ import { type BlockDef } from '../../model/ContentPageDef';
2
+
3
+ export function toMobileBlock(block: BlockDef = {}): BlockDef {
4
+ const { mobile, ...desktop } = block;
5
+
6
+ return {
7
+ ...desktop,
8
+ ...(mobile?.style ? { style: mobile.style } : {}),
9
+ ...(mobile?.content ? { content: mobile.content } : {}),
10
+ };
11
+ }
@@ -1,4 +1,5 @@
1
1
  type Key = string;
2
2
  type Data = any;
3
3
 
4
+ export type FallbackMap = Record<Key, () => Promise<Data>>;
4
5
  export type Fallback = Record<Key, Data>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redneckz/wildless-cms-uni-blocks",
3
- "version": "0.14.859",
3
+ "version": "0.14.860",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "ЦК",
@@ -4,12 +4,15 @@ import '../../setup-fixture';
4
4
  import { type ContentPageDef } from '../../model/ContentPageDef';
5
5
  import { Blocks } from '../Blocks';
6
6
  import { ContentPage } from './ContentPage';
7
+ import { normalizePage } from './normalizePage';
7
8
  import { useContentPageData } from './useContentPageData';
8
9
 
9
10
  export default {
10
11
  default: () => {
11
12
  const data = useContentPageData(Blocks);
12
13
 
13
- return <ContentPage blocksRegistry={Blocks} data={data as ContentPageDef} />;
14
+ return (
15
+ <ContentPage blocksRegistry={Blocks} data={normalizePage(Blocks)(data as ContentPageDef)} />
16
+ );
14
17
  },
15
18
  };
@@ -5,6 +5,7 @@ import { type BlockDecorator } from '../../model/BlockDecorator';
5
5
  import { type ContentPageDef } from '../../model/ContentPageDef';
6
6
  import { Blocks } from '../Blocks';
7
7
  import { ContentPage } from './ContentPage';
8
+ import { normalizePage } from './normalizePage';
8
9
  import { useContentPageData } from './useContentPageData';
9
10
 
10
11
  const blockDecorator: BlockDecorator = ({ blockClassName, block, render }, i) => (
@@ -32,7 +33,11 @@ export default {
32
33
  const data = useContentPageData(Blocks);
33
34
 
34
35
  return (
35
- <ContentPage className="bg-main" blocksRegistry={Blocks} data={data as ContentPageDef} />
36
+ <ContentPage
37
+ className="bg-main"
38
+ blocksRegistry={Blocks}
39
+ data={normalizePage(Blocks)(data as ContentPageDef)}
40
+ />
36
41
  );
37
42
  },
38
43
  editor: () => {
@@ -43,7 +48,7 @@ export default {
43
48
  <ContentPage
44
49
  className="bg-transparent"
45
50
  blocksRegistry={Blocks}
46
- data={data as ContentPageDef}
51
+ data={normalizePage(Blocks)(data as ContentPageDef)}
47
52
  blockDecorator={blockDecorator}
48
53
  />
49
54
  </div>
@@ -1,21 +1,53 @@
1
1
  import { type JSONNode } from '@redneckz/json-op';
2
2
  import { collectRef, resolveJPointer } from '@redneckz/json-ref';
3
3
  import { ContentPageRepository } from '../../content-page-repository/ContentPageRepository';
4
+ import { type BlocksRegistry } from '../../model/BlocksRegistry';
4
5
  import { type ContentPageDef } from '../../model/ContentPageDef';
5
- import { type Fallback } from '../../model/Fallback';
6
+ import { type Fallback, type FallbackMap } from '../../model/Fallback';
6
7
  import { unique } from '../../utils/unique';
7
8
  import { joinPath } from '../../utils/url';
9
+ import { loadModuleFallback } from './loadModuleFallback';
8
10
 
9
11
  type FallbackEntry = [key: string, data: JSONNode];
10
12
 
11
13
  const BASE_DIR = 'content';
12
14
 
13
- export const computeAPIFallback = async (contentPageData: ContentPageDef): Promise<Fallback> => {
15
+ export const computeAPIFallback = async (
16
+ blocksRegistry: BlocksRegistry,
17
+ contentPageData: ContentPageDef,
18
+ ): Promise<Fallback> => {
14
19
  return Object.fromEntries(
15
- (await computeFallbackFromContentRefs(contentPageData)).filter(([key, data]) => key && data),
20
+ (
21
+ await Promise.all([
22
+ computeFallbackFromModules(blocksRegistry),
23
+ computeFallbackFromContentRefs(contentPageData),
24
+ ])
25
+ )
26
+ .flatMap((_) => _)
27
+ .filter(([key, data]) => key && data),
16
28
  );
17
29
  };
18
30
 
31
+ const computeFallbackFromModules = async (
32
+ blocksRegistry: BlocksRegistry,
33
+ ): Promise<FallbackEntry[]> => {
34
+ const fallbackMap: FallbackMap = (
35
+ await Promise.all(Object.keys(blocksRegistry).map(loadModuleFallback))
36
+ )
37
+ .filter((_): _ is FallbackMap => Boolean(_))
38
+ .reduce((acc, _) => ({ ...acc, ..._ }), {});
39
+
40
+ return (
41
+ await Promise.allSettled(
42
+ Object.entries(fallbackMap).map(
43
+ async ([key, fetcher]): Promise<FallbackEntry> => [key, await fetcher()],
44
+ ),
45
+ )
46
+ )
47
+ .filter((_): _ is PromiseFulfilledResult<FallbackEntry> => _.status === 'fulfilled')
48
+ .map(({ value }) => value);
49
+ };
50
+
19
51
  const computeFallbackFromContentRefs = async (
20
52
  contentPageData: ContentPageDef,
21
53
  ): Promise<FallbackEntry[]> => {
@@ -0,0 +1,11 @@
1
+ import { type FallbackMap } from '../../model/Fallback';
2
+
3
+ export const loadModuleFallback = async (blockName: string): Promise<FallbackMap | undefined> => {
4
+ try {
5
+ const blockFallback = await import(`../${blockName}/${blockName}.fallback`);
6
+
7
+ return blockFallback?.fallback ? await blockFallback.fallback() : undefined;
8
+ } catch (error) {
9
+ return undefined;
10
+ }
11
+ };
@@ -0,0 +1,18 @@
1
+ import { type BlockDef, type Slot } from '../../model/ContentPageDef';
2
+
3
+ export const mapSlot =
4
+ (mapper: (blocks?: BlockDef[]) => BlockDef[]) =>
5
+ <S extends Slot>(slot: S): S => ({
6
+ ...slot,
7
+ ...(slot.blocks ? { blocks: mapper(slot.blocks) } : {}),
8
+ ...(slot.slots
9
+ ? {
10
+ slots: Object.fromEntries(
11
+ Object.entries(slot.slots).map(([slotKey, slotBlocks]) => [
12
+ slotKey,
13
+ mapper(slotBlocks),
14
+ ]),
15
+ ),
16
+ }
17
+ : {}),
18
+ });
@@ -0,0 +1,25 @@
1
+ import { type BlocksRegistry } from '../../model/BlocksRegistry';
2
+ import { type BlockDef, type Slot } from '../../model/ContentPageDef';
3
+ import { mapSlot } from './mapSlot';
4
+ import { toMobileBlock } from './toMobileBlock';
5
+
6
+ export function normalizeBlock<S extends Slot>(block?: S, blocksRegistry?: BlocksRegistry): S {
7
+ const { mobile } = (block || {}) as BlockDef;
8
+
9
+ return mapSlot(filterBlocks(blocksRegistry))((mobile ? toMobileBlock(block) : block) || {}) as S;
10
+ }
11
+
12
+ const filterBlocks =
13
+ (blocksRegistry?: BlocksRegistry) =>
14
+ (blocks?: BlockDef[]): BlockDef[] =>
15
+ blocks
16
+ ? blocks
17
+ ?.filter(
18
+ (block) =>
19
+ blocksRegistry &&
20
+ (block?.type || block?.mobile?.type || '') in blocksRegistry &&
21
+ !block.mobile?.hidden &&
22
+ !block?.hidden,
23
+ )
24
+ .map((block) => normalizeBlock(block, blocksRegistry))
25
+ : [];
@@ -0,0 +1,21 @@
1
+ import { type BlocksRegistry } from '../../model/BlocksRegistry';
2
+ import { type BlockDef, type Slot } from '../../model/ContentPageDef';
3
+ import { mapSlot } from './mapSlot';
4
+
5
+ export function normalizeBlock<S extends Slot>(block?: S, blocksRegistry?: BlocksRegistry): S {
6
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
7
+ const { mobile, ...result } = (block || {}) as BlockDef;
8
+
9
+ return mapSlot(filterBlocks(blocksRegistry))({ ...result }) as S;
10
+ }
11
+
12
+ const filterBlocks =
13
+ (blocksRegistry?: BlocksRegistry) =>
14
+ (blocks?: BlockDef[]): BlockDef[] =>
15
+ blocks
16
+ ? blocks
17
+ ?.filter(
18
+ (block) => blocksRegistry && (block?.type || '') in blocksRegistry && !block?.hidden,
19
+ )
20
+ .map((block) => normalizeBlock(block, blocksRegistry))
21
+ : [];
@@ -0,0 +1,8 @@
1
+ import { type BlocksRegistry } from '../../model/BlocksRegistry';
2
+ import { type ContentPageDef } from '../../model/ContentPageDef';
3
+ import { normalizeBlock } from './normalizeBlock';
4
+
5
+ export const normalizePage =
6
+ (blocksRegistry: BlocksRegistry) =>
7
+ (contentPage: ContentPageDef | undefined | null): ContentPageDef =>
8
+ contentPage ? normalizeBlock(contentPage, blocksRegistry) : {};
@@ -0,0 +1,11 @@
1
+ import { type BlockDef } from '../../model/ContentPageDef';
2
+
3
+ export function toMobileBlock(block: BlockDef = {}): BlockDef {
4
+ const { mobile, ...desktop } = block;
5
+
6
+ return {
7
+ ...desktop,
8
+ ...(mobile?.style ? { style: mobile.style } : {}),
9
+ ...(mobile?.content ? { content: mobile.content } : {}),
10
+ };
11
+ }
@@ -1,4 +1,5 @@
1
1
  type Key = string;
2
2
  type Data = any;
3
3
 
4
+ export type FallbackMap = Record<Key, () => Promise<Data>>;
4
5
  export type Fallback = Record<Key, Data>;