@pack/react 2.0.1 → 2.1.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.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { RenderSections, useSections } from "./preview/render-sections";
2
- import { PreviewProvider, RenderContent, usePreviewContext } from "./preview/preview-content";
2
+ import { PreviewProvider, RenderContent, usePackContent, usePreviewContext } from "./preview/preview-content";
3
3
  import { useSiteSettings } from "./use-site-settings";
4
4
  import { useOverlayScript } from "./use-overlay-script";
5
5
  import { registerSection } from "./register-section";
6
6
  import { registerStorefrontSettingsSchema } from "./register-storefront-settings-schema";
7
- export { PreviewProvider, registerSection, registerStorefrontSettingsSchema, RenderContent, RenderSections, useOverlayScript, usePreviewContext, useSiteSettings, useSections, };
7
+ export { PreviewProvider, RenderContent, RenderSections, registerSection, registerStorefrontSettingsSchema, useOverlayScript, usePackContent, usePreviewContext, useSections, useSiteSettings, };
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EACL,eAAe,EACf,aAAa,EACb,iBAAiB,EAClB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gCAAgC,EAAE,MAAM,uCAAuC,CAAC;AAEzF,OAAO,EACL,eAAe,EACf,eAAe,EACf,gCAAgC,EAChC,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,WAAW,GACZ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EACL,eAAe,EACf,aAAa,EACb,cAAc,EACd,iBAAiB,EAClB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gCAAgC,EAAE,MAAM,uCAAuC,CAAC;AAEzF,OAAO,EACL,eAAe,EACf,aAAa,EACb,cAAc,EACd,eAAe,EACf,gCAAgC,EAChC,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,WAAW,EACX,eAAe,GAChB,CAAC"}
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { RenderSections, useSections } from "./preview/render-sections";
2
- import { PreviewProvider, RenderContent, usePreviewContext, } from "./preview/preview-content";
2
+ import { PreviewProvider, RenderContent, usePackContent, usePreviewContext, } from "./preview/preview-content";
3
3
  import { useSiteSettings } from "./use-site-settings";
4
4
  import { useOverlayScript } from "./use-overlay-script";
5
5
  import { registerSection } from "./register-section";
6
6
  import { registerStorefrontSettingsSchema } from "./register-storefront-settings-schema";
7
- export { PreviewProvider, registerSection, registerStorefrontSettingsSchema, RenderContent, RenderSections, useOverlayScript, usePreviewContext, useSiteSettings, useSections, };
7
+ export { PreviewProvider, RenderContent, RenderSections, registerSection, registerStorefrontSettingsSchema, useOverlayScript, usePackContent, usePreviewContext, useSections, useSiteSettings, };
@@ -1,4 +1,4 @@
1
- import { Section, SectionConfig, SectionMap } from "./types";
1
+ import { Section, SectionConfig, SectionMap } from "@pack/types";
2
2
  export declare const sectionMap: SectionMap;
3
3
  export declare function registerSection(section: Section, config: SectionConfig): void;
4
4
  //# sourceMappingURL=register-section.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"register-section.d.ts","sourceRoot":"","sources":["../src/register-section.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE7D,eAAO,MAAM,UAAU,EAAE,UAAuC,CAAC;AAEjE,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,QAQtE"}
1
+ {"version":3,"file":"register-section.d.ts","sourceRoot":"","sources":["../src/register-section.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAuB,MAAM,aAAa,CAAC;AAEtF,eAAO,MAAM,UAAU,EAAE,UAAuC,CAAC;AAEjE,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,QAwCtE"}
@@ -1,7 +1,34 @@
1
+ import { SectionObjectSchema } from "@pack/types";
1
2
  export const sectionMap = new Map();
2
3
  export function registerSection(section, config) {
3
4
  if (typeof section !== "function") {
4
5
  throw new Error(`The section "${config.name}" is not a valid React component.`);
5
6
  }
7
+ if (!section.Schema) {
8
+ throw new Error(`The section "${config.name}" does not have a valid schema.`);
9
+ }
10
+ let result;
11
+ if (typeof section.Schema === "function") {
12
+ const schemaResult = section.Schema({ template: "dummy" });
13
+ if (schemaResult) {
14
+ result = SectionObjectSchema.safeParse(schemaResult);
15
+ }
16
+ }
17
+ else {
18
+ result = SectionObjectSchema.safeParse(section.Schema);
19
+ }
20
+ if (result && !result.success) {
21
+ const errorParts = [
22
+ '\n\x1b[1m\x1b[31m@pack/react Schema Validation Error:\x1b[0m',
23
+ '\x1b[31mInvalid schema for section "' + config.name + '"\x1b[0m',
24
+ '\n\x1b[33mDetailed Errors:\x1b[0m'
25
+ ];
26
+ result.error.issues.forEach(issue => {
27
+ errorParts.push(`\x1b[33m- Path:\x1b[0m ${issue.path.join('.')}`);
28
+ errorParts.push(` \x1b[31m${issue.message}\x1b[0m`);
29
+ });
30
+ console.error(errorParts.join('\n'));
31
+ return;
32
+ }
6
33
  sectionMap.set(config.name, section);
7
34
  }
@@ -1,4 +1,4 @@
1
- import { Schema } from "./types";
2
- export declare const storefrontSettingsSchema: Schema[];
3
- export declare function registerStorefrontSettingsSchema(settings: Schema[]): void;
1
+ import { SiteSetting } from "@pack/types";
2
+ export declare const storefrontSettingsSchema: SiteSetting[];
3
+ export declare function registerStorefrontSettingsSchema(settings: SiteSetting[]): void;
4
4
  //# sourceMappingURL=register-storefront-settings-schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"register-storefront-settings-schema.d.ts","sourceRoot":"","sources":["../src/register-storefront-settings-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,eAAO,MAAM,wBAAwB,EAAE,MAAM,EAAO,CAAC;AAErD,wBAAgB,gCAAgC,CAAC,QAAQ,EAAE,MAAM,EAAE,QAElE"}
1
+ {"version":3,"file":"register-storefront-settings-schema.d.ts","sourceRoot":"","sources":["../src/register-storefront-settings-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA4B,MAAM,aAAa,CAAC;AAEpE,eAAO,MAAM,wBAAwB,EAAE,WAAW,EAAO,CAAC;AAE1D,wBAAgB,gCAAgC,CAAC,QAAQ,EAAE,WAAW,EAAE,QAsBvE"}
@@ -1,4 +1,21 @@
1
+ import { SiteSettingsObjectSchema } from "@pack/types";
1
2
  export const storefrontSettingsSchema = [];
2
3
  export function registerStorefrontSettingsSchema(settings) {
4
+ for (const setting of settings) {
5
+ const result = SiteSettingsObjectSchema.safeParse(setting);
6
+ if (result && !result.success) {
7
+ const errorParts = [
8
+ '\n\x1b[1m\x1b[31m@pack/react Schema Validation Error:\x1b[0m',
9
+ '\x1b[31mInvalid storefront settings schema\x1b[0m',
10
+ '\n\x1b[33mDetailed Errors:\x1b[0m'
11
+ ];
12
+ result.error.issues.forEach(issue => {
13
+ errorParts.push(`\x1b[33m- Path:\x1b[0m ${issue.path.join('.')}`);
14
+ errorParts.push(` \x1b[31m${issue.message}\x1b[0m`);
15
+ });
16
+ console.error(errorParts.join('\n'));
17
+ return;
18
+ }
19
+ }
3
20
  storefrontSettingsSchema.push(...settings);
4
21
  }
package/dist/types.d.ts CHANGED
@@ -1,12 +1,3 @@
1
- import React from "react";
2
- export type Schema = Record<string, any>;
3
- export type Section = React.ComponentType<any> & {
4
- Schema?: Schema;
5
- };
6
- export type SectionConfig = {
7
- name: string;
8
- };
9
- export type SectionMap = Map<string, Section>;
10
1
  export interface MessageTypeDataMap {
11
2
  INIT: {
12
3
  version: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACzC,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AACrE,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAG9C,MAAM,WAAW,kBAAkB;IAEjC,IAAI,EAAE;QACJ,OAAO,EAAE,MAAM,CAAC;QAChB,cAAc,EAAE,GAAG,EAAE,CAAC;KACvB,CAAC;IACF,GAAG,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3B,IAAI,EAAE,KAAK,CAAC;IACZ,IAAI,EAAE;QACJ,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IAGF,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,aAAa,EAAE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,MAAM,kBAAkB,GAAG,MAAM,kBAAkB;IAE7D,IAAI,EAAE;QACJ,IAAI,EAAE,CAAC,CAAC;QACR,IAAI,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC;QAC7B,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH"}
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "2.0.1";
1
+ export const VERSION = "2.1.0";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pack/react",
3
3
  "description": "React",
4
- "version": "2.0.1",
4
+ "version": "2.1.0",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "engines": {
@@ -30,5 +30,7 @@
30
30
  "react": "^18.0.0",
31
31
  "react-dom": "^18.0.0"
32
32
  },
33
- "dependencies": {}
33
+ "dependencies": {
34
+ "@pack/types": "^0.0.1"
35
+ }
34
36
  }