@swell/apps-sdk 1.0.179 → 1.0.181
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/index.cjs +114 -103
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +110 -101
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +114 -104
- package/dist/index.mjs.map +3 -3
- package/dist/src/compatibility/shopify.d.ts +1 -1
- package/dist/src/easyblocks/index.d.ts +1 -1
- package/dist/src/easyblocks/utils.d.ts +1 -0
- package/dist/src/liquid/filters/image_url.d.ts +1 -0
- package/dist/src/liquid/filters/shopify/img_url.d.ts +1 -1
- package/dist/types/swell.d.ts +3 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3279,7 +3279,7 @@
|
|
|
3279
3279
|
(block) => block.type === blockType
|
|
3280
3280
|
);
|
|
3281
3281
|
return {
|
|
3282
|
-
id,
|
|
3282
|
+
id: toBlockId(id),
|
|
3283
3283
|
type: blockType,
|
|
3284
3284
|
disabled: isDisabled,
|
|
3285
3285
|
settings: blockSchema?.fields?.reduce(
|
|
@@ -3308,6 +3308,12 @@
|
|
|
3308
3308
|
}
|
|
3309
3309
|
return fieldId.replace(/·/g, ".");
|
|
3310
3310
|
}
|
|
3311
|
+
function toBlockId(id) {
|
|
3312
|
+
if (!id) {
|
|
3313
|
+
return id;
|
|
3314
|
+
}
|
|
3315
|
+
return id.replace(/\./g, "_");
|
|
3316
|
+
}
|
|
3311
3317
|
|
|
3312
3318
|
// src/utils/md5.ts
|
|
3313
3319
|
function md5(inputString) {
|
|
@@ -5780,86 +5786,76 @@ ${formattedMessage}`;
|
|
|
5780
5786
|
}
|
|
5781
5787
|
function getAllSectionComponentTemplates(allSections) {
|
|
5782
5788
|
const list = [];
|
|
5789
|
+
const processFields = (fields, settings = {}) => {
|
|
5790
|
+
const result = {};
|
|
5791
|
+
for (const field of fields) {
|
|
5792
|
+
if (!field?.id) {
|
|
5793
|
+
continue;
|
|
5794
|
+
}
|
|
5795
|
+
const { id: fieldId, $locale } = field;
|
|
5796
|
+
result[fieldId] = schemaToEasyblocksValue(
|
|
5797
|
+
fields,
|
|
5798
|
+
fieldId,
|
|
5799
|
+
settings[fieldId]
|
|
5800
|
+
);
|
|
5801
|
+
if ($locale) {
|
|
5802
|
+
for (const [locale, localeValues] of Object.entries($locale)) {
|
|
5803
|
+
const defaultValue = localeValues?.default;
|
|
5804
|
+
if (defaultValue) {
|
|
5805
|
+
(0, import_lodash_es4.set)(result, `$locale.${locale}.${fieldId}`, defaultValue);
|
|
5806
|
+
}
|
|
5807
|
+
}
|
|
5808
|
+
}
|
|
5809
|
+
}
|
|
5810
|
+
return result;
|
|
5811
|
+
};
|
|
5783
5812
|
for (const section of allSections) {
|
|
5784
5813
|
if (section.presets) {
|
|
5785
|
-
|
|
5786
|
-
|
|
5814
|
+
for (let index = 0; index < section.presets.length; index++) {
|
|
5815
|
+
const preset = section.presets[index];
|
|
5816
|
+
const entry = {
|
|
5817
|
+
_id: `${section.id}__preset_${index}`,
|
|
5818
|
+
_component: section.id,
|
|
5819
|
+
custom_css: preset.settings?.["custom_css"] || "",
|
|
5820
|
+
...processFields(section.fields, preset.settings),
|
|
5821
|
+
// Process blocks inside the preset
|
|
5822
|
+
Blocks: (preset.blocks || []).map((block) => {
|
|
5823
|
+
const blockSchema = section.blocks?.find(
|
|
5824
|
+
({ type }) => type === block.type
|
|
5825
|
+
);
|
|
5826
|
+
if (!blockSchema) {
|
|
5827
|
+
return null;
|
|
5828
|
+
}
|
|
5829
|
+
return {
|
|
5830
|
+
_id: `Block__${section.id}__${block.type}__preset_${index}`,
|
|
5831
|
+
_component: `Block__${section.id}__${block.type}`,
|
|
5832
|
+
...processFields(blockSchema.fields, block.settings)
|
|
5833
|
+
};
|
|
5834
|
+
}).filter(Boolean)
|
|
5835
|
+
};
|
|
5836
|
+
list.push({
|
|
5787
5837
|
id: `${section.id}__preset_${index}`,
|
|
5788
|
-
entry
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
custom_css: preset.settings?.["custom_css"] || "",
|
|
5792
|
-
...(0, import_lodash_es4.reduce)(
|
|
5793
|
-
section.fields,
|
|
5794
|
-
(acc, field) => {
|
|
5795
|
-
if (field.id) {
|
|
5796
|
-
acc[field.id] = schemaToEasyblocksValue(
|
|
5797
|
-
section.fields,
|
|
5798
|
-
field.id,
|
|
5799
|
-
preset.settings?.[field.id]
|
|
5800
|
-
);
|
|
5801
|
-
}
|
|
5802
|
-
return acc;
|
|
5803
|
-
},
|
|
5804
|
-
{}
|
|
5805
|
-
),
|
|
5806
|
-
Blocks: preset.blocks?.reduce(
|
|
5807
|
-
(acc, block) => {
|
|
5808
|
-
const blockDef = section.blocks?.find(
|
|
5809
|
-
({ type }) => type === block.type
|
|
5810
|
-
);
|
|
5811
|
-
if (blockDef) {
|
|
5812
|
-
acc.push({
|
|
5813
|
-
_id: `Block__${section.id}__${block.type}__preset_${index}`,
|
|
5814
|
-
_component: `Block__${section.id}__${block.type}`,
|
|
5815
|
-
...(0, import_lodash_es4.reduce)(
|
|
5816
|
-
blockDef.fields,
|
|
5817
|
-
(acc2, blockField) => {
|
|
5818
|
-
if (blockField.id) {
|
|
5819
|
-
acc2[blockField.id] = schemaToEasyblocksValue(
|
|
5820
|
-
blockDef.fields,
|
|
5821
|
-
blockField.id,
|
|
5822
|
-
block.settings?.[blockField.id]
|
|
5823
|
-
);
|
|
5824
|
-
}
|
|
5825
|
-
return acc2;
|
|
5826
|
-
},
|
|
5827
|
-
{}
|
|
5828
|
-
)
|
|
5829
|
-
});
|
|
5830
|
-
}
|
|
5831
|
-
return acc;
|
|
5832
|
-
},
|
|
5833
|
-
[]
|
|
5834
|
-
)
|
|
5835
|
-
}
|
|
5836
|
-
}))
|
|
5837
|
-
);
|
|
5838
|
+
entry
|
|
5839
|
+
});
|
|
5840
|
+
}
|
|
5838
5841
|
}
|
|
5839
5842
|
if (section.blocks) {
|
|
5840
|
-
|
|
5841
|
-
|
|
5843
|
+
for (const block of section.blocks) {
|
|
5844
|
+
list.push({
|
|
5842
5845
|
id: `Block__${section.id}__${block.type}`,
|
|
5843
5846
|
entry: {
|
|
5844
5847
|
_id: `Block__${section.id}__${block.type}`,
|
|
5845
5848
|
_component: `Block__${section.id}__${block.type}`,
|
|
5846
|
-
...(
|
|
5849
|
+
...processFields(
|
|
5847
5850
|
block.fields,
|
|
5848
|
-
(acc,
|
|
5849
|
-
if (
|
|
5850
|
-
acc[field.id] = schemaToEasyblocksValue(
|
|
5851
|
-
block.fields,
|
|
5852
|
-
field.id,
|
|
5853
|
-
field.default
|
|
5854
|
-
);
|
|
5855
|
-
}
|
|
5851
|
+
block.fields.reduce((acc, f) => {
|
|
5852
|
+
if (f.id) acc[f.id] = f.default;
|
|
5856
5853
|
return acc;
|
|
5857
|
-
},
|
|
5858
|
-
{}
|
|
5854
|
+
}, {})
|
|
5859
5855
|
)
|
|
5860
5856
|
}
|
|
5861
|
-
})
|
|
5862
|
-
|
|
5857
|
+
});
|
|
5858
|
+
}
|
|
5863
5859
|
}
|
|
5864
5860
|
}
|
|
5865
5861
|
return list;
|
|
@@ -11579,16 +11575,16 @@ ${formattedMessage}`;
|
|
|
11579
11575
|
if (!Array.isArray(blogs?.results)) {
|
|
11580
11576
|
return [];
|
|
11581
11577
|
}
|
|
11582
|
-
const
|
|
11583
|
-
(
|
|
11578
|
+
const set3 = blogs.results.reduce(
|
|
11579
|
+
(set4, blog) => {
|
|
11584
11580
|
for (const tag of blog.tags || []) {
|
|
11585
|
-
|
|
11581
|
+
set4.add(tag);
|
|
11586
11582
|
}
|
|
11587
|
-
return
|
|
11583
|
+
return set4;
|
|
11588
11584
|
},
|
|
11589
11585
|
/* @__PURE__ */ new Set()
|
|
11590
11586
|
);
|
|
11591
|
-
return Array.from(
|
|
11587
|
+
return Array.from(set3.values());
|
|
11592
11588
|
});
|
|
11593
11589
|
return new ShopifyResource({
|
|
11594
11590
|
all_tags: allTags,
|
|
@@ -11972,18 +11968,18 @@ ${formattedMessage}`;
|
|
|
11972
11968
|
if (!resolved) {
|
|
11973
11969
|
return [];
|
|
11974
11970
|
}
|
|
11975
|
-
const
|
|
11971
|
+
const set3 = /* @__PURE__ */ new Set();
|
|
11976
11972
|
await Promise.all(
|
|
11977
11973
|
resolved.results.map(async (product) => {
|
|
11978
11974
|
const tags2 = await Promise.resolve().then(() => product.tags);
|
|
11979
11975
|
if (Array.isArray(tags2)) {
|
|
11980
11976
|
for (const tag of tags2) {
|
|
11981
|
-
|
|
11977
|
+
set3.add(tag);
|
|
11982
11978
|
}
|
|
11983
11979
|
}
|
|
11984
11980
|
})
|
|
11985
11981
|
);
|
|
11986
|
-
return Array.from(
|
|
11982
|
+
return Array.from(set3.values());
|
|
11987
11983
|
}),
|
|
11988
11984
|
all_types: defer(async () => {
|
|
11989
11985
|
const products = await resolveProducts();
|
|
@@ -14333,26 +14329,32 @@ ${injects.join("\n")}<\/script>`;
|
|
|
14333
14329
|
if (!(0, import_lodash_es7.isObject)(schema)) {
|
|
14334
14330
|
return schema;
|
|
14335
14331
|
}
|
|
14336
|
-
const
|
|
14337
|
-
|
|
14338
|
-
localeCode
|
|
14339
|
-
|
|
14332
|
+
const locales = await theme.swell.storefront.locale.list();
|
|
14333
|
+
const localeCodes = /* @__PURE__ */ new Set([
|
|
14334
|
+
localeCode,
|
|
14335
|
+
...locales.map((locale) => locale.code)
|
|
14336
|
+
]);
|
|
14337
|
+
const localeConfigs = {};
|
|
14338
|
+
for (const locale of localeCodes) {
|
|
14339
|
+
localeConfigs[locale] = await this.getEditorLocaleConfig(theme, locale);
|
|
14340
|
+
}
|
|
14340
14341
|
return this.renderSchemaTranslationValue(
|
|
14341
14342
|
theme,
|
|
14342
14343
|
schema,
|
|
14343
14344
|
localeCode,
|
|
14344
|
-
|
|
14345
|
+
localeConfigs
|
|
14345
14346
|
);
|
|
14346
14347
|
}
|
|
14347
|
-
|
|
14348
|
+
renderSchemaTranslationValue(theme, schemaValue, localeCode, localeConfigs) {
|
|
14348
14349
|
switch (typeof schemaValue) {
|
|
14349
14350
|
case "string": {
|
|
14350
14351
|
if (schemaValue.startsWith("t:")) {
|
|
14352
|
+
const localeConfig = localeConfigs[localeCode];
|
|
14351
14353
|
const key = schemaValue.slice(2);
|
|
14352
14354
|
const keyParts = key?.split(".");
|
|
14353
14355
|
const keyName = keyParts.pop() || "";
|
|
14354
14356
|
const keyPath = keyParts.join(".");
|
|
14355
|
-
const langObject = (0, import_lodash_es7.get)(
|
|
14357
|
+
const langObject = (0, import_lodash_es7.get)(localeConfig, keyPath);
|
|
14356
14358
|
return langObject?.[keyName] ?? key;
|
|
14357
14359
|
}
|
|
14358
14360
|
break;
|
|
@@ -14362,11 +14364,11 @@ ${injects.join("\n")}<\/script>`;
|
|
|
14362
14364
|
const result = [];
|
|
14363
14365
|
for (const value of schemaValue) {
|
|
14364
14366
|
result.push(
|
|
14365
|
-
|
|
14367
|
+
this.renderSchemaTranslationValue(
|
|
14366
14368
|
theme,
|
|
14367
14369
|
value,
|
|
14368
|
-
|
|
14369
|
-
|
|
14370
|
+
localeCode,
|
|
14371
|
+
localeConfigs
|
|
14370
14372
|
)
|
|
14371
14373
|
);
|
|
14372
14374
|
}
|
|
@@ -14375,12 +14377,26 @@ ${injects.join("\n")}<\/script>`;
|
|
|
14375
14377
|
if (schemaValue !== null) {
|
|
14376
14378
|
const result = { ...schemaValue };
|
|
14377
14379
|
for (const [key, value] of Object.entries(schemaValue)) {
|
|
14378
|
-
result[key] =
|
|
14380
|
+
result[key] = this.renderSchemaTranslationValue(
|
|
14379
14381
|
theme,
|
|
14380
14382
|
value,
|
|
14381
|
-
|
|
14382
|
-
|
|
14383
|
+
localeCode,
|
|
14384
|
+
localeConfigs
|
|
14383
14385
|
);
|
|
14386
|
+
if (typeof value === "string" && value.startsWith("t:")) {
|
|
14387
|
+
for (const locale of Object.keys(localeConfigs)) {
|
|
14388
|
+
if (locale === localeCode) {
|
|
14389
|
+
continue;
|
|
14390
|
+
}
|
|
14391
|
+
const localeValue = this.renderSchemaTranslationValue(
|
|
14392
|
+
theme,
|
|
14393
|
+
value,
|
|
14394
|
+
locale,
|
|
14395
|
+
localeConfigs
|
|
14396
|
+
);
|
|
14397
|
+
(0, import_lodash_es7.set)(result, `$locale.${locale}.${key}`, localeValue);
|
|
14398
|
+
}
|
|
14399
|
+
}
|
|
14384
14400
|
}
|
|
14385
14401
|
return result;
|
|
14386
14402
|
}
|
|
@@ -16262,18 +16278,11 @@ ${injects.join("\n")}<\/script>`;
|
|
|
16262
16278
|
}
|
|
16263
16279
|
|
|
16264
16280
|
// src/liquid/filters/shopify/img_url.ts
|
|
16265
|
-
function bind59(
|
|
16266
|
-
return function filterImgUrl(input, ...params) {
|
|
16267
|
-
|
|
16268
|
-
|
|
16269
|
-
|
|
16270
|
-
if (input.url) {
|
|
16271
|
-
url = input.url;
|
|
16272
|
-
} else {
|
|
16273
|
-
return "";
|
|
16274
|
-
}
|
|
16275
|
-
} else {
|
|
16276
|
-
url = String(input);
|
|
16281
|
+
function bind59(liquidSwell) {
|
|
16282
|
+
return async function filterImgUrl(input, ...params) {
|
|
16283
|
+
const url = await getImageUrlFromInput(input, liquidSwell);
|
|
16284
|
+
if (typeof url !== "string" || url === "") {
|
|
16285
|
+
return "";
|
|
16277
16286
|
}
|
|
16278
16287
|
const query = [];
|
|
16279
16288
|
params.forEach((param) => {
|