@gem-sdk/core 1.46.0-staging.16 → 1.46.0-staging.23
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/dist/cjs/helpers/third-party/generateAppBlockConfigs.js +14 -1
- package/dist/cjs/helpers/third-party/getAppBlocks.js +15 -25
- package/dist/cjs/helpers/third-party/mergeBlock.js +19 -0
- package/dist/cjs/helpers/third-party/mergeBlockOrder.js +47 -0
- package/dist/cjs/helpers/third-party/removeGPAppItems.js +18 -0
- package/dist/esm/helpers/third-party/generateAppBlockConfigs.js +14 -1
- package/dist/esm/helpers/third-party/getAppBlocks.js +15 -25
- package/dist/esm/helpers/third-party/mergeBlock.js +17 -0
- package/dist/esm/helpers/third-party/mergeBlockOrder.js +45 -0
- package/dist/esm/helpers/third-party/removeGPAppItems.js +15 -0
- package/dist/types/index.d.ts +7 -2
- package/package.json +1 -1
- package/dist/cjs/helpers/remove-matching-key.js +0 -12
- package/dist/esm/helpers/remove-matching-key.js +0 -10
|
@@ -15,7 +15,20 @@ const generateAppBlockConfigs = (component)=>{
|
|
|
15
15
|
if (!config) return;
|
|
16
16
|
configs.push(config);
|
|
17
17
|
});
|
|
18
|
-
return
|
|
18
|
+
if (!configs.length) return null;
|
|
19
|
+
return {
|
|
20
|
+
newBlocks: extractBlocks(configs),
|
|
21
|
+
newBlockOrder: extractBlockOrder(configs)
|
|
22
|
+
};
|
|
19
23
|
};
|
|
24
|
+
function extractBlocks(array) {
|
|
25
|
+
return array.reduce((acc, item)=>{
|
|
26
|
+
acc[item.key] = item.value;
|
|
27
|
+
return acc;
|
|
28
|
+
}, {});
|
|
29
|
+
}
|
|
30
|
+
function extractBlockOrder(array) {
|
|
31
|
+
return array.map((item)=>item.key);
|
|
32
|
+
}
|
|
20
33
|
|
|
21
34
|
exports.generateAppBlockConfigs = generateAppBlockConfigs;
|
|
@@ -1,40 +1,30 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var removeMatchingKey = require('../remove-matching-key.js');
|
|
4
3
|
var addAppBlockId = require('./addAppBlockId.js');
|
|
5
4
|
var generateAppBlockConfigs = require('./generateAppBlockConfigs.js');
|
|
5
|
+
var mergeBlock = require('./mergeBlock.js');
|
|
6
|
+
var mergeBlockOrder = require('./mergeBlockOrder.js');
|
|
7
|
+
var removeGPAppItems = require('./removeGPAppItems.js');
|
|
6
8
|
|
|
7
|
-
const getAppBlocks = (section
|
|
9
|
+
const getAppBlocks = (section)=>{
|
|
10
|
+
if (!section?.appBlocks) return {};
|
|
11
|
+
const { blocks: currentBlock, block_order: currentBlockOrder } = JSON.parse(section.appBlocks);
|
|
12
|
+
if (!currentBlock || !currentBlockOrder) return {};
|
|
8
13
|
const component = JSON.parse(section?.component || '');
|
|
9
14
|
const componentWithAppBlockId = addAppBlockId.addAppBlockId(component);
|
|
10
15
|
const appBlockConfigs = generateAppBlockConfigs.generateAppBlockConfigs(componentWithAppBlockId);
|
|
11
|
-
if (!appBlockConfigs
|
|
16
|
+
if (!appBlockConfigs) {
|
|
12
17
|
return {
|
|
13
|
-
blocks: currentBlock,
|
|
14
|
-
block_order: currentBlockOrder
|
|
18
|
+
blocks: removeGPAppItems.removeAllGPAppItemsFromBlocks(currentBlock),
|
|
19
|
+
block_order: removeGPAppItems.removeAllGPAppItemsFromBlockOrder(currentBlockOrder)
|
|
15
20
|
};
|
|
16
21
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const newBlock = {
|
|
21
|
-
[key]: value
|
|
22
|
-
};
|
|
23
|
-
const oldKeyRemovedBlock = removeMatchingKey.removeMatchingKey(newBlocks, key);
|
|
24
|
-
newBlocks = {
|
|
25
|
-
...oldKeyRemovedBlock,
|
|
26
|
-
...newBlock
|
|
27
|
-
};
|
|
28
|
-
newBlockOrder = newBlockOrder ? [
|
|
29
|
-
...newBlockOrder,
|
|
30
|
-
key
|
|
31
|
-
] : [
|
|
32
|
-
key
|
|
33
|
-
];
|
|
34
|
-
});
|
|
22
|
+
const { newBlocks, newBlockOrder } = appBlockConfigs;
|
|
23
|
+
const blocks = mergeBlock.mergeBlocks(newBlocks, currentBlock);
|
|
24
|
+
const block_order = mergeBlockOrder.mergeBlockOrder(newBlockOrder, currentBlockOrder);
|
|
35
25
|
return {
|
|
36
|
-
blocks
|
|
37
|
-
block_order
|
|
26
|
+
blocks,
|
|
27
|
+
block_order
|
|
38
28
|
};
|
|
39
29
|
};
|
|
40
30
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function mergeBlocks(newBlocks, blocks) {
|
|
4
|
+
if (!blocks) return newBlocks;
|
|
5
|
+
const result = {};
|
|
6
|
+
// Add all non-gp_app blocks from the original blocks
|
|
7
|
+
for (const [key, value] of Object.entries(blocks)){
|
|
8
|
+
if (!key.startsWith('gp_app')) {
|
|
9
|
+
result[key] = value;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
// Add all blocks from new-blocks
|
|
13
|
+
for (const [key, value] of Object.entries(newBlocks)){
|
|
14
|
+
result[key] = value;
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exports.mergeBlocks = mergeBlocks;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constant = require('./constant.js');
|
|
4
|
+
|
|
5
|
+
function isGpAppItem(item) {
|
|
6
|
+
if (!item) return false;
|
|
7
|
+
return item.startsWith(constant.THIRD_PARTY_APP_BLOCK_ID_PREFIX);
|
|
8
|
+
}
|
|
9
|
+
function filterCurrentOrder(currentOrder, newOrderSet) {
|
|
10
|
+
return currentOrder.filter((item)=>!isGpAppItem(item) || newOrderSet.has(item));
|
|
11
|
+
}
|
|
12
|
+
function processNonGpAppItem(item, resultOrder) {
|
|
13
|
+
resultOrder.push(item);
|
|
14
|
+
}
|
|
15
|
+
function processGpAppItems(newOrder, newOrderIndex, resultOrder) {
|
|
16
|
+
while(newOrderIndex < newOrder.length && isGpAppItem(newOrder[newOrderIndex])){
|
|
17
|
+
resultOrder.push(newOrder[newOrderIndex]);
|
|
18
|
+
newOrderIndex++;
|
|
19
|
+
}
|
|
20
|
+
return newOrderIndex;
|
|
21
|
+
}
|
|
22
|
+
function addRemainingGpAppItems(newOrder, startIndex, resultOrder) {
|
|
23
|
+
for(let i = startIndex; i < newOrder.length; i++){
|
|
24
|
+
const item = newOrder[i];
|
|
25
|
+
if (item && isGpAppItem(item)) {
|
|
26
|
+
resultOrder.push(item);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function mergeBlockOrder(newOrder, currentOrder) {
|
|
31
|
+
if (!currentOrder) return newOrder;
|
|
32
|
+
const newOrderSet = new Set(newOrder);
|
|
33
|
+
const filteredCurrentOrder = filterCurrentOrder(currentOrder, newOrderSet);
|
|
34
|
+
const resultOrder = [];
|
|
35
|
+
let newOrderIndex = 0;
|
|
36
|
+
filteredCurrentOrder.forEach((item)=>{
|
|
37
|
+
if (!isGpAppItem(item)) {
|
|
38
|
+
processNonGpAppItem(item, resultOrder);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
newOrderIndex = processGpAppItems(newOrder, newOrderIndex, resultOrder);
|
|
42
|
+
});
|
|
43
|
+
addRemainingGpAppItems(newOrder, newOrderIndex, resultOrder);
|
|
44
|
+
return resultOrder;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
exports.mergeBlockOrder = mergeBlockOrder;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constant = require('./constant.js');
|
|
4
|
+
|
|
5
|
+
const removeAllGPAppItemsFromBlocks = (blocks)=>{
|
|
6
|
+
for(const key in blocks){
|
|
7
|
+
if (key.startsWith(constant.THIRD_PARTY_APP_BLOCK_ID_PREFIX)) {
|
|
8
|
+
delete blocks[key];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return blocks;
|
|
12
|
+
};
|
|
13
|
+
const removeAllGPAppItemsFromBlockOrder = (blockOrder)=>{
|
|
14
|
+
return blockOrder.filter((item)=>!item.includes(constant.THIRD_PARTY_APP_BLOCK_ID_PREFIX));
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
exports.removeAllGPAppItemsFromBlockOrder = removeAllGPAppItemsFromBlockOrder;
|
|
18
|
+
exports.removeAllGPAppItemsFromBlocks = removeAllGPAppItemsFromBlocks;
|
|
@@ -13,7 +13,20 @@ const generateAppBlockConfigs = (component)=>{
|
|
|
13
13
|
if (!config) return;
|
|
14
14
|
configs.push(config);
|
|
15
15
|
});
|
|
16
|
-
return
|
|
16
|
+
if (!configs.length) return null;
|
|
17
|
+
return {
|
|
18
|
+
newBlocks: extractBlocks(configs),
|
|
19
|
+
newBlockOrder: extractBlockOrder(configs)
|
|
20
|
+
};
|
|
17
21
|
};
|
|
22
|
+
function extractBlocks(array) {
|
|
23
|
+
return array.reduce((acc, item)=>{
|
|
24
|
+
acc[item.key] = item.value;
|
|
25
|
+
return acc;
|
|
26
|
+
}, {});
|
|
27
|
+
}
|
|
28
|
+
function extractBlockOrder(array) {
|
|
29
|
+
return array.map((item)=>item.key);
|
|
30
|
+
}
|
|
18
31
|
|
|
19
32
|
export { generateAppBlockConfigs };
|
|
@@ -1,38 +1,28 @@
|
|
|
1
|
-
import { removeMatchingKey } from '../remove-matching-key.js';
|
|
2
1
|
import { addAppBlockId } from './addAppBlockId.js';
|
|
3
2
|
import { generateAppBlockConfigs } from './generateAppBlockConfigs.js';
|
|
3
|
+
import { mergeBlocks } from './mergeBlock.js';
|
|
4
|
+
import { mergeBlockOrder } from './mergeBlockOrder.js';
|
|
5
|
+
import { removeAllGPAppItemsFromBlocks, removeAllGPAppItemsFromBlockOrder } from './removeGPAppItems.js';
|
|
4
6
|
|
|
5
|
-
const getAppBlocks = (section
|
|
7
|
+
const getAppBlocks = (section)=>{
|
|
8
|
+
if (!section?.appBlocks) return {};
|
|
9
|
+
const { blocks: currentBlock, block_order: currentBlockOrder } = JSON.parse(section.appBlocks);
|
|
10
|
+
if (!currentBlock || !currentBlockOrder) return {};
|
|
6
11
|
const component = JSON.parse(section?.component || '');
|
|
7
12
|
const componentWithAppBlockId = addAppBlockId(component);
|
|
8
13
|
const appBlockConfigs = generateAppBlockConfigs(componentWithAppBlockId);
|
|
9
|
-
if (!appBlockConfigs
|
|
14
|
+
if (!appBlockConfigs) {
|
|
10
15
|
return {
|
|
11
|
-
blocks: currentBlock,
|
|
12
|
-
block_order: currentBlockOrder
|
|
16
|
+
blocks: removeAllGPAppItemsFromBlocks(currentBlock),
|
|
17
|
+
block_order: removeAllGPAppItemsFromBlockOrder(currentBlockOrder)
|
|
13
18
|
};
|
|
14
19
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const newBlock = {
|
|
19
|
-
[key]: value
|
|
20
|
-
};
|
|
21
|
-
const oldKeyRemovedBlock = removeMatchingKey(newBlocks, key);
|
|
22
|
-
newBlocks = {
|
|
23
|
-
...oldKeyRemovedBlock,
|
|
24
|
-
...newBlock
|
|
25
|
-
};
|
|
26
|
-
newBlockOrder = newBlockOrder ? [
|
|
27
|
-
...newBlockOrder,
|
|
28
|
-
key
|
|
29
|
-
] : [
|
|
30
|
-
key
|
|
31
|
-
];
|
|
32
|
-
});
|
|
20
|
+
const { newBlocks, newBlockOrder } = appBlockConfigs;
|
|
21
|
+
const blocks = mergeBlocks(newBlocks, currentBlock);
|
|
22
|
+
const block_order = mergeBlockOrder(newBlockOrder, currentBlockOrder);
|
|
33
23
|
return {
|
|
34
|
-
blocks
|
|
35
|
-
block_order
|
|
24
|
+
blocks,
|
|
25
|
+
block_order
|
|
36
26
|
};
|
|
37
27
|
};
|
|
38
28
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function mergeBlocks(newBlocks, blocks) {
|
|
2
|
+
if (!blocks) return newBlocks;
|
|
3
|
+
const result = {};
|
|
4
|
+
// Add all non-gp_app blocks from the original blocks
|
|
5
|
+
for (const [key, value] of Object.entries(blocks)){
|
|
6
|
+
if (!key.startsWith('gp_app')) {
|
|
7
|
+
result[key] = value;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
// Add all blocks from new-blocks
|
|
11
|
+
for (const [key, value] of Object.entries(newBlocks)){
|
|
12
|
+
result[key] = value;
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { mergeBlocks };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { THIRD_PARTY_APP_BLOCK_ID_PREFIX } from './constant.js';
|
|
2
|
+
|
|
3
|
+
function isGpAppItem(item) {
|
|
4
|
+
if (!item) return false;
|
|
5
|
+
return item.startsWith(THIRD_PARTY_APP_BLOCK_ID_PREFIX);
|
|
6
|
+
}
|
|
7
|
+
function filterCurrentOrder(currentOrder, newOrderSet) {
|
|
8
|
+
return currentOrder.filter((item)=>!isGpAppItem(item) || newOrderSet.has(item));
|
|
9
|
+
}
|
|
10
|
+
function processNonGpAppItem(item, resultOrder) {
|
|
11
|
+
resultOrder.push(item);
|
|
12
|
+
}
|
|
13
|
+
function processGpAppItems(newOrder, newOrderIndex, resultOrder) {
|
|
14
|
+
while(newOrderIndex < newOrder.length && isGpAppItem(newOrder[newOrderIndex])){
|
|
15
|
+
resultOrder.push(newOrder[newOrderIndex]);
|
|
16
|
+
newOrderIndex++;
|
|
17
|
+
}
|
|
18
|
+
return newOrderIndex;
|
|
19
|
+
}
|
|
20
|
+
function addRemainingGpAppItems(newOrder, startIndex, resultOrder) {
|
|
21
|
+
for(let i = startIndex; i < newOrder.length; i++){
|
|
22
|
+
const item = newOrder[i];
|
|
23
|
+
if (item && isGpAppItem(item)) {
|
|
24
|
+
resultOrder.push(item);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function mergeBlockOrder(newOrder, currentOrder) {
|
|
29
|
+
if (!currentOrder) return newOrder;
|
|
30
|
+
const newOrderSet = new Set(newOrder);
|
|
31
|
+
const filteredCurrentOrder = filterCurrentOrder(currentOrder, newOrderSet);
|
|
32
|
+
const resultOrder = [];
|
|
33
|
+
let newOrderIndex = 0;
|
|
34
|
+
filteredCurrentOrder.forEach((item)=>{
|
|
35
|
+
if (!isGpAppItem(item)) {
|
|
36
|
+
processNonGpAppItem(item, resultOrder);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
newOrderIndex = processGpAppItems(newOrder, newOrderIndex, resultOrder);
|
|
40
|
+
});
|
|
41
|
+
addRemainingGpAppItems(newOrder, newOrderIndex, resultOrder);
|
|
42
|
+
return resultOrder;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { mergeBlockOrder };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { THIRD_PARTY_APP_BLOCK_ID_PREFIX } from './constant.js';
|
|
2
|
+
|
|
3
|
+
const removeAllGPAppItemsFromBlocks = (blocks)=>{
|
|
4
|
+
for(const key in blocks){
|
|
5
|
+
if (key.startsWith(THIRD_PARTY_APP_BLOCK_ID_PREFIX)) {
|
|
6
|
+
delete blocks[key];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return blocks;
|
|
10
|
+
};
|
|
11
|
+
const removeAllGPAppItemsFromBlockOrder = (blockOrder)=>{
|
|
12
|
+
return blockOrder.filter((item)=>!item.includes(THIRD_PARTY_APP_BLOCK_ID_PREFIX));
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { removeAllGPAppItemsFromBlockOrder, removeAllGPAppItemsFromBlocks };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -37365,8 +37365,13 @@ declare const getProductBySlug: (fetcher: FetchFunc, slug?: string) => Promise<P
|
|
|
37365
37365
|
|
|
37366
37366
|
declare const getAppBlocks: (section: PublishedPageSection$1 & {
|
|
37367
37367
|
appBlocks: string;
|
|
37368
|
-
}
|
|
37369
|
-
blocks
|
|
37368
|
+
}) => {
|
|
37369
|
+
blocks?: undefined;
|
|
37370
|
+
block_order?: undefined;
|
|
37371
|
+
} | {
|
|
37372
|
+
blocks: {
|
|
37373
|
+
[key: string]: any;
|
|
37374
|
+
};
|
|
37370
37375
|
block_order: string[];
|
|
37371
37376
|
};
|
|
37372
37377
|
|
package/package.json
CHANGED