vite-plugin-react-shopify 1.1.0 → 2.0.0

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.
@@ -0,0 +1,73 @@
1
+ // src/runtime/hooks.ts
2
+ import { useContext } from "react";
3
+
4
+ // src/runtime/provider.ts
5
+ import { createContext } from "react";
6
+ var LiquidDataContext = createContext({});
7
+ var LiquidDataProvider = LiquidDataContext.Provider;
8
+
9
+ // src/runtime/hooks.ts
10
+ function useLiquid(expr) {
11
+ const data = useContext(LiquidDataContext);
12
+ if (typeof globalThis.document === "undefined") {
13
+ const tracker = globalThis.__shopify_ssg_liquid_track;
14
+ if (tracker) tracker.add(expr);
15
+ return { value: `{{ ${expr} }}` };
16
+ }
17
+ if (Object.prototype.hasOwnProperty.call(data, expr)) {
18
+ return { value: data[expr] };
19
+ }
20
+ return { value: void 0 };
21
+ }
22
+ function useLiquidValues(map) {
23
+ const data = useContext(LiquidDataContext);
24
+ if (typeof globalThis.document === "undefined") {
25
+ const tracker = globalThis.__shopify_ssg_liquid_track;
26
+ const values2 = {};
27
+ for (const [key, expr] of Object.entries(map)) {
28
+ if (tracker) tracker.add(expr);
29
+ values2[key] = `{{ ${expr} }}`;
30
+ }
31
+ return { values: values2 };
32
+ }
33
+ const values = {};
34
+ for (const [key, expr] of Object.entries(map)) {
35
+ values[key] = Object.prototype.hasOwnProperty.call(data, expr) ? data[expr] : void 0;
36
+ }
37
+ return { values };
38
+ }
39
+ function useSectionSettings(key) {
40
+ return useLiquid(`section.settings.${key}`);
41
+ }
42
+ function useBlockSettings(key) {
43
+ return useLiquid(`block.settings.${key}`);
44
+ }
45
+ function useSnippetParams(key) {
46
+ return useLiquid(key);
47
+ }
48
+ function useBlockParams(key) {
49
+ return useLiquid(key);
50
+ }
51
+ function parseLiquidBoolean(value) {
52
+ if (typeof value === "boolean") return value;
53
+ if (value === void 0 || value === null) return false;
54
+ return value !== "" && value !== "0" && value !== "false";
55
+ }
56
+ function parseLiquidNumber(value, defaultVal = 0) {
57
+ if (typeof value === "number") return Number.isNaN(value) ? defaultVal : value;
58
+ if (value === void 0 || value === null) return defaultVal;
59
+ const num = Number(value);
60
+ return Number.isNaN(num) ? defaultVal : num;
61
+ }
62
+ export {
63
+ LiquidDataContext,
64
+ LiquidDataProvider,
65
+ parseLiquidBoolean,
66
+ parseLiquidNumber,
67
+ useBlockParams,
68
+ useBlockSettings,
69
+ useLiquid,
70
+ useLiquidValues,
71
+ useSectionSettings,
72
+ useSnippetParams
73
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-react-shopify",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "description": "Vite plugin for React Shopify themes",
5
5
  "files": [
6
6
  "dist"
@@ -13,20 +13,8 @@
13
13
  "default": "./dist/index.js"
14
14
  },
15
15
  "./runtime": {
16
- "types": "./dist/runtime/Liquid.d.ts",
17
- "default": "./dist/runtime/Liquid.js"
18
- },
19
- "./runtime/Liquid": {
20
- "types": "./dist/runtime/Liquid.d.ts",
21
- "default": "./dist/runtime/Liquid.js"
22
- },
23
- "./runtime/Liquid.client": {
24
- "types": "./dist/runtime/Liquid.client.d.ts",
25
- "default": "./dist/runtime/Liquid.client.js"
26
- },
27
- "./runtime/settings": {
28
- "types": "./dist/runtime/settings.d.ts",
29
- "default": "./dist/runtime/settings.js"
16
+ "types": "./dist/runtime/index.d.ts",
17
+ "default": "./dist/runtime/index.js"
30
18
  }
31
19
  },
32
20
  "scripts": {
@@ -1,6 +0,0 @@
1
- interface LiquidProps {
2
- code: string;
3
- }
4
- declare function Liquid(_props: LiquidProps): null;
5
-
6
- export { Liquid };
@@ -1,7 +0,0 @@
1
- // src/runtime/Liquid.client.tsx
2
- function Liquid(_props) {
3
- return null;
4
- }
5
- export {
6
- Liquid
7
- };
@@ -1,11 +0,0 @@
1
- import * as react from 'react';
2
-
3
- declare function Liquid({ code }: {
4
- code: string;
5
- }): react.DOMElement<{
6
- dangerouslySetInnerHTML: {
7
- __html: string;
8
- };
9
- }, Element>;
10
-
11
- export { Liquid };
@@ -1,10 +0,0 @@
1
- // src/runtime/Liquid.tsx
2
- import { createElement } from "react";
3
- function Liquid({ code }) {
4
- return createElement("react-liquid", {
5
- dangerouslySetInnerHTML: { __html: code }
6
- });
7
- }
8
- export {
9
- Liquid
10
- };
@@ -1,8 +0,0 @@
1
- import * as react from 'react';
2
-
3
- declare const SettingsProvider: react.Provider<Record<string, any>>;
4
- declare function useShopifySettings<T = Record<string, any>>(): T;
5
- declare const ParamsProvider: react.Provider<Record<string, any>>;
6
- declare function useShopifyParams<T = Record<string, any>>(): T;
7
-
8
- export { ParamsProvider, SettingsProvider, useShopifyParams, useShopifySettings };
@@ -1,44 +0,0 @@
1
- // src/runtime/settings.tsx
2
- import { createContext, useContext } from "react";
3
- var SettingsContext = createContext({});
4
- var SettingsProvider = SettingsContext.Provider;
5
- function useShopifySettings() {
6
- const ctx = useContext(SettingsContext);
7
- if (Object.keys(ctx).length > 0) return ctx;
8
- if (typeof globalThis.window === "undefined") {
9
- const target = globalThis.__shopify_ssg_target || "section";
10
- const prefix = target === "block" ? "block" : "section";
11
- return new Proxy(
12
- {},
13
- {
14
- get(_, key) {
15
- return `{{ ${prefix}.settings.${String(key)} }}`;
16
- }
17
- }
18
- );
19
- }
20
- return {};
21
- }
22
- var ParamsContext = createContext({});
23
- var ParamsProvider = ParamsContext.Provider;
24
- function useShopifyParams() {
25
- const ctx = useContext(ParamsContext);
26
- if (Object.keys(ctx).length > 0) return ctx;
27
- if (typeof globalThis.window === "undefined") {
28
- return new Proxy(
29
- {},
30
- {
31
- get(_, key) {
32
- return `{{ ${String(key)} }}`;
33
- }
34
- }
35
- );
36
- }
37
- return {};
38
- }
39
- export {
40
- ParamsProvider,
41
- SettingsProvider,
42
- useShopifyParams,
43
- useShopifySettings
44
- };