vite-plugin-react-shopify 2.2.0 → 2.2.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.
- package/dist/index.js +19 -0
- package/dist/runtime/index.js +8 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -590,6 +590,21 @@ function pathToFileURL(filePath) {
|
|
|
590
590
|
return "file://" + absPath;
|
|
591
591
|
}
|
|
592
592
|
var log6 = logger("ssg:renderer");
|
|
593
|
+
var DEFAULT_LIQUID_FILTERS = {
|
|
594
|
+
textarea: " | newline_to_br",
|
|
595
|
+
image_picker: " | img_url: 'master'"
|
|
596
|
+
};
|
|
597
|
+
function buildLiquidFilterMap(settings, prefix) {
|
|
598
|
+
const map = {};
|
|
599
|
+
if (!settings) return map;
|
|
600
|
+
for (const s of settings) {
|
|
601
|
+
const filter = DEFAULT_LIQUID_FILTERS[s.type];
|
|
602
|
+
if (filter) {
|
|
603
|
+
map[`${prefix}${s.id}`] = filter;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
return map;
|
|
607
|
+
}
|
|
593
608
|
function renderEntry(tmpFile, entry, projectRoot) {
|
|
594
609
|
return import(pathToFileURL(tmpFile)).then((mod) => {
|
|
595
610
|
const Component = mod.default;
|
|
@@ -612,11 +627,15 @@ function renderEntry(tmpFile, entry, projectRoot) {
|
|
|
612
627
|
return null;
|
|
613
628
|
}
|
|
614
629
|
globalThis.__shopify_ssg_target = entry.targetType;
|
|
630
|
+
const prefix = entry.targetType === "block" ? "block.settings." : "section.settings.";
|
|
631
|
+
const filterMap = buildLiquidFilterMap(shopifyMeta?.settings, prefix);
|
|
632
|
+
globalThis.__shopify_ssg_liquid_filters = filterMap;
|
|
615
633
|
const trackedExpressions = /* @__PURE__ */ new Set();
|
|
616
634
|
globalThis.__shopify_ssg_liquid_track = trackedExpressions;
|
|
617
635
|
const element = createElement(Component);
|
|
618
636
|
let html = renderToStaticMarkup(element);
|
|
619
637
|
delete globalThis.__shopify_ssg_liquid_track;
|
|
638
|
+
delete globalThis.__shopify_ssg_liquid_filters;
|
|
620
639
|
html = normalizeVoidElements(html);
|
|
621
640
|
html = normalizeStyleAttributes(html);
|
|
622
641
|
html = unwrapHtmlEntities(html);
|
package/dist/runtime/index.js
CHANGED
|
@@ -7,12 +7,17 @@ var LiquidDataContext = createContext({});
|
|
|
7
7
|
var LiquidDataProvider = LiquidDataContext.Provider;
|
|
8
8
|
|
|
9
9
|
// src/runtime/hooks.ts
|
|
10
|
+
function getLiquidFilter(expr) {
|
|
11
|
+
const filterMap = globalThis.__shopify_ssg_liquid_filters;
|
|
12
|
+
return filterMap?.[expr] ?? "";
|
|
13
|
+
}
|
|
10
14
|
function useLiquidRaw(expr) {
|
|
11
15
|
const data = useContext(LiquidDataContext);
|
|
12
16
|
if (typeof globalThis.document === "undefined") {
|
|
13
17
|
const tracker = globalThis.__shopify_ssg_liquid_track;
|
|
14
18
|
if (tracker) tracker.add(expr);
|
|
15
|
-
|
|
19
|
+
const filter = getLiquidFilter(expr);
|
|
20
|
+
return `{{ ${expr}${filter} }}`;
|
|
16
21
|
}
|
|
17
22
|
if (Object.prototype.hasOwnProperty.call(data, expr)) {
|
|
18
23
|
return data[expr];
|
|
@@ -26,7 +31,8 @@ function useLiquidRawValues(map) {
|
|
|
26
31
|
const values2 = {};
|
|
27
32
|
for (const [key, expr] of Object.entries(map)) {
|
|
28
33
|
if (tracker) tracker.add(expr);
|
|
29
|
-
|
|
34
|
+
const filter = getLiquidFilter(expr);
|
|
35
|
+
values2[key] = `{{ ${expr}${filter} }}`;
|
|
30
36
|
}
|
|
31
37
|
return values2;
|
|
32
38
|
}
|