@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.
- package/bundle/bundle.umd.js +1 -1
- package/bundle/bundle.umd.min.js +1 -1
- package/bundle/components/ContentPage/computeAPIFallback.d.ts +2 -1
- package/bundle/components/ContentPage/loadModuleFallback.d.ts +2 -0
- package/bundle/components/ContentPage/mapSlot.d.ts +2 -0
- package/bundle/components/ContentPage/normalizeBlock.d.ts +3 -0
- package/bundle/components/ContentPage/normalizeBlock.mobile.d.ts +3 -0
- package/bundle/components/ContentPage/normalizePage.d.ts +3 -0
- package/bundle/components/ContentPage/toMobileBlock.d.ts +2 -0
- package/bundle/model/Fallback.d.ts +1 -0
- package/dist/components/ContentPage/computeAPIFallback.d.ts +2 -1
- package/dist/components/ContentPage/computeAPIFallback.js +16 -2
- package/dist/components/ContentPage/computeAPIFallback.js.map +1 -1
- package/dist/components/ContentPage/loadModuleFallback.d.ts +2 -0
- package/dist/components/ContentPage/loadModuleFallback.js +36 -0
- package/dist/components/ContentPage/loadModuleFallback.js.map +1 -0
- package/dist/components/ContentPage/mapSlot.d.ts +2 -0
- package/dist/components/ContentPage/mapSlot.js +16 -0
- package/dist/components/ContentPage/mapSlot.js.map +1 -0
- package/dist/components/ContentPage/normalizeBlock.d.ts +3 -0
- package/dist/components/ContentPage/normalizeBlock.js +15 -0
- package/dist/components/ContentPage/normalizeBlock.js.map +1 -0
- package/dist/components/ContentPage/normalizeBlock.mobile.d.ts +3 -0
- package/dist/components/ContentPage/normalizeBlock.mobile.js +18 -0
- package/dist/components/ContentPage/normalizeBlock.mobile.js.map +1 -0
- package/dist/components/ContentPage/normalizePage.d.ts +3 -0
- package/dist/components/ContentPage/normalizePage.js +6 -0
- package/dist/components/ContentPage/normalizePage.js.map +1 -0
- package/dist/components/ContentPage/toMobileBlock.d.ts +2 -0
- package/dist/components/ContentPage/toMobileBlock.js +12 -0
- package/dist/components/ContentPage/toMobileBlock.js.map +1 -0
- package/dist/model/Fallback.d.ts +1 -0
- package/lib/common.css +1 -1
- package/lib/components/ContentPage/computeAPIFallback.d.ts +2 -1
- package/lib/components/ContentPage/computeAPIFallback.js +16 -2
- package/lib/components/ContentPage/computeAPIFallback.js.map +1 -1
- package/lib/components/ContentPage/loadModuleFallback.d.ts +2 -0
- package/lib/components/ContentPage/loadModuleFallback.js +10 -0
- package/lib/components/ContentPage/loadModuleFallback.js.map +1 -0
- package/lib/components/ContentPage/mapSlot.d.ts +2 -0
- package/lib/components/ContentPage/mapSlot.js +13 -0
- package/lib/components/ContentPage/mapSlot.js.map +1 -0
- package/lib/components/ContentPage/normalizeBlock.d.ts +3 -0
- package/lib/components/ContentPage/normalizeBlock.js +12 -0
- package/lib/components/ContentPage/normalizeBlock.js.map +1 -0
- package/lib/components/ContentPage/normalizeBlock.mobile.d.ts +3 -0
- package/lib/components/ContentPage/normalizeBlock.mobile.js +15 -0
- package/lib/components/ContentPage/normalizeBlock.mobile.js.map +1 -0
- package/lib/components/ContentPage/normalizePage.d.ts +3 -0
- package/lib/components/ContentPage/normalizePage.js +3 -0
- package/lib/components/ContentPage/normalizePage.js.map +1 -0
- package/lib/components/ContentPage/toMobileBlock.d.ts +2 -0
- package/lib/components/ContentPage/toMobileBlock.js +9 -0
- package/lib/components/ContentPage/toMobileBlock.js.map +1 -0
- package/lib/model/Fallback.d.ts +1 -0
- package/mobile/bundle/bundle.umd.js +1 -1
- package/mobile/bundle/bundle.umd.min.js +1 -1
- package/mobile/bundle/components/ContentPage/computeAPIFallback.d.ts +2 -1
- package/mobile/bundle/components/ContentPage/loadModuleFallback.d.ts +2 -0
- package/mobile/bundle/components/ContentPage/mapSlot.d.ts +2 -0
- package/mobile/bundle/components/ContentPage/normalizeBlock.d.ts +3 -0
- package/mobile/bundle/components/ContentPage/normalizePage.d.ts +3 -0
- package/mobile/bundle/components/ContentPage/toMobileBlock.d.ts +2 -0
- package/mobile/bundle/model/Fallback.d.ts +1 -0
- package/mobile/dist/components/ContentPage/computeAPIFallback.d.ts +2 -1
- package/mobile/dist/components/ContentPage/computeAPIFallback.js +16 -2
- package/mobile/dist/components/ContentPage/computeAPIFallback.js.map +1 -1
- package/mobile/dist/components/ContentPage/loadModuleFallback.d.ts +2 -0
- package/mobile/dist/components/ContentPage/loadModuleFallback.js +36 -0
- package/mobile/dist/components/ContentPage/loadModuleFallback.js.map +1 -0
- package/mobile/dist/components/ContentPage/mapSlot.d.ts +2 -0
- package/mobile/dist/components/ContentPage/mapSlot.js +16 -0
- package/mobile/dist/components/ContentPage/mapSlot.js.map +1 -0
- package/mobile/dist/components/ContentPage/normalizeBlock.d.ts +3 -0
- package/mobile/dist/components/ContentPage/normalizeBlock.js +18 -0
- package/mobile/dist/components/ContentPage/normalizeBlock.js.map +1 -0
- package/mobile/dist/components/ContentPage/normalizePage.d.ts +3 -0
- package/mobile/dist/components/ContentPage/normalizePage.js +6 -0
- package/mobile/dist/components/ContentPage/normalizePage.js.map +1 -0
- package/mobile/dist/components/ContentPage/toMobileBlock.d.ts +2 -0
- package/mobile/dist/components/ContentPage/toMobileBlock.js +12 -0
- package/mobile/dist/components/ContentPage/toMobileBlock.js.map +1 -0
- package/mobile/dist/model/Fallback.d.ts +1 -0
- package/mobile/lib/common.css +1 -1
- package/mobile/lib/components/ContentPage/computeAPIFallback.d.ts +2 -1
- package/mobile/lib/components/ContentPage/computeAPIFallback.js +16 -2
- package/mobile/lib/components/ContentPage/computeAPIFallback.js.map +1 -1
- package/mobile/lib/components/ContentPage/loadModuleFallback.d.ts +2 -0
- package/mobile/lib/components/ContentPage/loadModuleFallback.js +10 -0
- package/mobile/lib/components/ContentPage/loadModuleFallback.js.map +1 -0
- package/mobile/lib/components/ContentPage/mapSlot.d.ts +2 -0
- package/mobile/lib/components/ContentPage/mapSlot.js +13 -0
- package/mobile/lib/components/ContentPage/mapSlot.js.map +1 -0
- package/mobile/lib/components/ContentPage/normalizeBlock.d.ts +3 -0
- package/mobile/lib/components/ContentPage/normalizeBlock.js +15 -0
- package/mobile/lib/components/ContentPage/normalizeBlock.js.map +1 -0
- package/mobile/lib/components/ContentPage/normalizePage.d.ts +3 -0
- package/mobile/lib/components/ContentPage/normalizePage.js +3 -0
- package/mobile/lib/components/ContentPage/normalizePage.js.map +1 -0
- package/mobile/lib/components/ContentPage/toMobileBlock.d.ts +2 -0
- package/mobile/lib/components/ContentPage/toMobileBlock.js +9 -0
- package/mobile/lib/components/ContentPage/toMobileBlock.js.map +1 -0
- package/mobile/lib/model/Fallback.d.ts +1 -0
- package/mobile/src/components/ContentPage/computeAPIFallback.ts +35 -3
- package/mobile/src/components/ContentPage/loadModuleFallback.ts +11 -0
- package/mobile/src/components/ContentPage/mapSlot.ts +18 -0
- package/mobile/src/components/ContentPage/normalizeBlock.ts +25 -0
- package/mobile/src/components/ContentPage/normalizePage.ts +8 -0
- package/mobile/src/components/ContentPage/toMobileBlock.ts +11 -0
- package/mobile/src/model/Fallback.ts +1 -0
- package/package.json +1 -1
- package/src/components/ContentPage/ContentPage.fixture.mobile.tsx +4 -1
- package/src/components/ContentPage/ContentPage.fixture.tsx +7 -2
- package/src/components/ContentPage/computeAPIFallback.ts +35 -3
- package/src/components/ContentPage/loadModuleFallback.ts +11 -0
- package/src/components/ContentPage/mapSlot.ts +18 -0
- package/src/components/ContentPage/normalizeBlock.mobile.ts +25 -0
- package/src/components/ContentPage/normalizeBlock.ts +21 -0
- package/src/components/ContentPage/normalizePage.ts +8 -0
- package/src/components/ContentPage/toMobileBlock.ts +11 -0
- 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 (
|
|
15
|
+
export const computeAPIFallback = async (
|
|
16
|
+
blocksRegistry: BlocksRegistry,
|
|
17
|
+
contentPageData: ContentPageDef,
|
|
18
|
+
): Promise<Fallback> => {
|
|
14
19
|
return Object.fromEntries(
|
|
15
|
-
(
|
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -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
|
|
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
|
|
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 (
|
|
15
|
+
export const computeAPIFallback = async (
|
|
16
|
+
blocksRegistry: BlocksRegistry,
|
|
17
|
+
contentPageData: ContentPageDef,
|
|
18
|
+
): Promise<Fallback> => {
|
|
14
19
|
return Object.fromEntries(
|
|
15
|
-
(
|
|
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
|
+
}
|