@pack/react 0.0.5 → 0.0.6

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.
@@ -1,3 +1,3 @@
1
- import React from "react";
1
+ import React from 'react';
2
2
  export declare function RenderSections({ content }: any): React.JSX.Element | null;
3
3
  //# sourceMappingURL=render-sections.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../src/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAmCzC,wBAAgB,cAAc,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,4BA4B9C"}
1
+ {"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../src/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAmCvC,wBAAgB,cAAc,CAAC,EAAC,OAAO,EAAC,EAAE,GAAG,4BA4B5C"}
@@ -1,9 +1,9 @@
1
- import React, { useEffect } from "react";
2
- import { v4 as uuidv4 } from "uuid";
3
- import { useCustomizerShell } from "./use-customizer-shell";
4
- import { usePreviewContext } from "./preview/preview-content";
5
- import { sectionMap } from "./register-section";
6
- import { storefrontSettingsSchema } from "./register-storefront-settings-schema";
1
+ import React, { useEffect } from 'react';
2
+ import { v4 as uuidv4 } from 'uuid';
3
+ import { useCustomizerShell } from './use-customizer-shell';
4
+ import { usePreviewContext } from './preview/preview-content';
5
+ import { sectionMap } from './register-section';
6
+ import { storefrontSettingsSchema } from './register-storefront-settings-schema';
7
7
  function Sections({ content, sections }) {
8
8
  const renderedSections = sections
9
9
  .map((section) => {
@@ -14,7 +14,7 @@ function Sections({ content, sections }) {
14
14
  const Component = sectionMap.get(schemaKey);
15
15
  if (!Component)
16
16
  return null;
17
- return (React.createElement("section", { key: uuidv4(), "data-comp": schemaKey, "data-comp-id": section?.id, hidden: data?.sectionVisibility === "hidden" },
17
+ return (React.createElement("section", { key: uuidv4(), "data-comp": schemaKey, "data-comp-id": section?.id, hidden: data?.sectionVisibility === 'hidden' },
18
18
  React.createElement(Component, { "comp-name": schemaKey, cms: data })));
19
19
  })
20
20
  .filter(Boolean);
@@ -23,16 +23,16 @@ function Sections({ content, sections }) {
23
23
  export function RenderSections({ content }) {
24
24
  const { isPreview, setPreviewStorefrontSettings } = usePreviewContext();
25
25
  const { content: liveContent, storefrontSettings } = useCustomizerShell({
26
- environment: "production",
26
+ environment: 'production',
27
27
  isPreview,
28
28
  sectionComponents: sectionMap,
29
29
  data: {
30
30
  content,
31
- template: content?.template?.type,
32
- templateType: content?.template?.type,
33
- handle: content?.handle,
34
- title: content?.title,
35
- description: content?.description,
31
+ template: content.template?.type,
32
+ templateType: content.template?.type,
33
+ handle: content.handle,
34
+ title: content.title,
35
+ description: content.description,
36
36
  },
37
37
  storefrontSettingsSchema,
38
38
  });
@@ -1 +1 @@
1
- {"version":3,"file":"use-customizer-shell.d.ts","sourceRoot":"","sources":["../src/use-customizer-shell.tsx"],"names":[],"mappings":"AAIA,eAAO,MAAM,kBAAkB,mFAM5B,GAAG;;;CAyGL,CAAC"}
1
+ {"version":3,"file":"use-customizer-shell.d.ts","sourceRoot":"","sources":["../src/use-customizer-shell.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB,mFAM5B,GAAG;;;CAkHL,CAAC"}
@@ -1,18 +1,22 @@
1
- import { useCallback, useEffect, useState } from 'react';
2
- import { useLocation, useNavigate } from '@remix-run/react';
3
- import { connectToParent } from 'penpal';
4
- export const useCustomizerShell = ({ environment = 'production', isPreview, sectionComponents, data = {}, storefrontSettingsSchema, }) => {
5
- const navigate = useNavigate();
6
- const location = useLocation();
1
+ import { useCallback, useEffect, useState } from "react";
2
+ import { connectToParent } from "penpal";
3
+ export const useCustomizerShell = ({ environment = "production", isPreview, sectionComponents, data = {}, storefrontSettingsSchema, }) => {
4
+ const [location, setLocation] = useState();
7
5
  const [content, setContent] = useState(data.content);
8
6
  const [storefrontSettings, setStorefrontSettings] = useState(null);
9
7
  const [parentConnection, setParentConnection] = useState(null);
8
+ const navigate = (path) => {
9
+ window.location.href = path;
10
+ };
11
+ useEffect(() => {
12
+ setLocation(window.location);
13
+ }, []);
10
14
  const refreshSections = useCallback(() => {
11
15
  if (!sectionComponents || !parentConnection)
12
16
  return [];
13
17
  const sectionSchemas = Array.from(sectionComponents)
14
18
  .map(([, section]) => {
15
- return typeof section.Schema === 'function'
19
+ return typeof section.Schema === "function"
16
20
  ? section.Schema(data)
17
21
  : section.Schema;
18
22
  })
@@ -21,7 +25,7 @@ export const useCustomizerShell = ({ environment = 'production', isPreview, sect
21
25
  parentConnection.setSectionsSchemas(JSON.stringify(sectionSchemas));
22
26
  }
23
27
  catch (error) {
24
- parentConnection.displayError('Something went wrong parsing sections');
28
+ parentConnection.displayError("Something went wrong parsing sections");
25
29
  }
26
30
  return;
27
31
  }, [data, parentConnection, sectionComponents]);
@@ -34,7 +38,7 @@ export const useCustomizerShell = ({ environment = 'production', isPreview, sect
34
38
  // eslint-disable-next-line react-hooks/exhaustive-deps
35
39
  }, [data, parentConnection, storefrontSettingsSchema]);
36
40
  useEffect(() => {
37
- if (!isPreview)
41
+ if (!isPreview || !location)
38
42
  return;
39
43
  const connection = connectToParent({
40
44
  methods: {
@@ -44,7 +48,7 @@ export const useCustomizerShell = ({ environment = 'production', isPreview, sect
44
48
  scrollToSection(sectionId) {
45
49
  const sectionEl = document.querySelector(`[data-comp-id="${sectionId}"]`);
46
50
  if (sectionEl)
47
- sectionEl.scrollIntoView({ behavior: 'smooth' });
51
+ sectionEl.scrollIntoView({ behavior: "smooth" });
48
52
  },
49
53
  setPageData(content) {
50
54
  setContent(content);
@@ -59,7 +63,7 @@ export const useCustomizerShell = ({ environment = 'production', isPreview, sect
59
63
  parent.sendStorefrontSettings();
60
64
  parent.setCurrentRoute({
61
65
  environment,
62
- currentPath: location.pathname,
66
+ currentPath: location?.pathname,
63
67
  template,
64
68
  templateType,
65
69
  handle: content.handle,
@@ -71,7 +75,7 @@ export const useCustomizerShell = ({ environment = 'production', isPreview, sect
71
75
  return () => {
72
76
  connection.destroy();
73
77
  };
74
- }, []);
78
+ }, [location]);
75
79
  useEffect(() => {
76
80
  if (!isPreview)
77
81
  return;
@@ -85,7 +89,10 @@ export const useCustomizerShell = ({ environment = 'production', isPreview, sect
85
89
  sectionComponents,
86
90
  ]);
87
91
  if (!isPreview) {
88
- return { content: data.content, storefrontSettings: data.settings?.settings };
92
+ return {
93
+ content: data.content,
94
+ storefrontSettings: data.settings?.settings,
95
+ };
89
96
  }
90
97
  return { content, storefrontSettings };
91
98
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pack/react",
3
3
  "description": "React",
4
- "version": "0.0.5",
4
+ "version": "0.0.6",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "engines": {
@@ -23,7 +23,6 @@
23
23
  ],
24
24
  "dependencies": {},
25
25
  "devDependencies": {
26
- "@remix-run/react": "^1.19.3",
27
26
  "@shopify/remix-oxygen": "^1.1.3",
28
27
  "@types/react": "^18.2.20",
29
28
  "@types/uuid": "^9.0.2",