@weaverse/hydrogen 5.17.1 → 5.18.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.
Files changed (70) hide show
  1. package/dist/index.js +83 -1
  2. package/dist/index.js.map +1 -1
  3. package/dist/index.mjs +83 -1
  4. package/dist/index.mjs.map +1 -1
  5. package/dist/types/WeaverseHydrogenRoot.d.ts +218 -0
  6. package/dist/types/WeaverseHydrogenRoot.d.ts.map +1 -0
  7. package/dist/types/components/index.d.ts +4 -0
  8. package/dist/types/components/index.d.ts.map +1 -0
  9. package/dist/types/components/main.d.ts +7 -0
  10. package/dist/types/components/main.d.ts.map +1 -0
  11. package/dist/types/hooks/theme-text-context.d.ts +2 -0
  12. package/dist/types/hooks/theme-text-context.d.ts.map +1 -0
  13. package/dist/types/hooks/translation-context.d.ts +138 -0
  14. package/dist/types/hooks/translation-context.d.ts.map +1 -0
  15. package/dist/types/hooks/use-weaverse-data-context.d.ts +29 -0
  16. package/dist/types/hooks/use-weaverse-data-context.d.ts.map +1 -0
  17. package/dist/types/index.d.ts +99 -0
  18. package/dist/types/index.d.ts.map +1 -0
  19. package/dist/types/seo.d.ts +43 -0
  20. package/dist/types/seo.d.ts.map +1 -0
  21. package/dist/types/types.d.ts +826 -0
  22. package/dist/types/types.d.ts.map +1 -0
  23. package/dist/types/utils/index.d.ts +44 -0
  24. package/dist/types/utils/index.d.ts.map +1 -0
  25. package/dist/types/utils/normalize-page-url.d.ts +16 -0
  26. package/dist/types/utils/normalize-page-url.d.ts.map +1 -0
  27. package/dist/types/utils/pick-weaverse-data.d.ts +44 -0
  28. package/dist/types/utils/pick-weaverse-data.d.ts.map +1 -0
  29. package/dist/types/utils/pixel.d.ts +16 -0
  30. package/dist/types/utils/pixel.d.ts.map +1 -0
  31. package/dist/types/utils/studio-request-info.d.ts +17 -0
  32. package/dist/types/utils/studio-request-info.d.ts.map +1 -0
  33. package/dist/types/utils/studio-script-src.d.ts +78 -0
  34. package/dist/types/utils/studio-script-src.d.ts.map +1 -0
  35. package/dist/types/utils/sync-reused-instance.d.ts +21 -0
  36. package/dist/types/utils/sync-reused-instance.d.ts.map +1 -0
  37. package/dist/types/utils/theme-text-store.d.ts +2 -0
  38. package/dist/types/utils/theme-text-store.d.ts.map +1 -0
  39. package/dist/types/utils/translation-store.d.ts +40 -0
  40. package/dist/types/utils/translation-store.d.ts.map +1 -0
  41. package/dist/types/utils/use-studio.d.ts +33 -0
  42. package/dist/types/utils/use-studio.d.ts.map +1 -0
  43. package/dist/types/utils/use-theme-settings-store.d.ts +39 -0
  44. package/dist/types/utils/use-theme-settings-store.d.ts.map +1 -0
  45. package/dist/types/weaverse-client.d.ts +227 -0
  46. package/dist/types/weaverse-client.d.ts.map +1 -0
  47. package/package.json +7 -6
  48. package/src/WeaverseHydrogenRoot.tsx +649 -0
  49. package/src/components/index.ts +10 -0
  50. package/src/components/main.tsx +28 -0
  51. package/src/hooks/theme-text-context.tsx +14 -0
  52. package/src/hooks/translation-context.tsx +275 -0
  53. package/src/hooks/use-weaverse-data-context.ts +69 -0
  54. package/src/index.ts +179 -0
  55. package/src/seo.ts +125 -0
  56. package/src/types.ts +1020 -0
  57. package/src/utils/index.ts +351 -0
  58. package/src/utils/normalize-page-url.ts +44 -0
  59. package/src/utils/pick-weaverse-data.ts +89 -0
  60. package/src/utils/pixel.ts +71 -0
  61. package/src/utils/studio-request-info.ts +66 -0
  62. package/src/utils/studio-script-src.ts +162 -0
  63. package/src/utils/sync-reused-instance.ts +57 -0
  64. package/src/utils/theme-text-store.ts +1 -0
  65. package/src/utils/translation-store.ts +65 -0
  66. package/src/utils/use-studio.ts +168 -0
  67. package/src/utils/use-theme-settings-store.ts +160 -0
  68. package/src/weaverse-client.ts +1179 -0
  69. package/dist/index.d.mts +0 -1260
  70. package/dist/index.d.ts +0 -1260
package/dist/index.mjs CHANGED
@@ -207,9 +207,13 @@ function isProjectIdFunction(projectId) {
207
207
  return typeof projectId === "function";
208
208
  }
209
209
  var WeaverseError = class _WeaverseError extends Error {
210
+ /** Machine-readable error code. */
210
211
  code;
212
+ /** HTTP status associated with the failure, when available. */
211
213
  statusCode;
214
+ /** Structured diagnostic details for logging and error handling. */
212
215
  context;
216
+ /** Creates a Weaverse request error with a stable code and diagnostics. */
213
217
  constructor(message, code = "WEAVERSE_ERROR", statusCode, context) {
214
218
  super(message);
215
219
  this.name = "WeaverseError";
@@ -515,18 +519,24 @@ function getPreviewData(type, components, weaverseHost) {
515
519
 
516
520
  // src/utils/translation-store.ts
517
521
  var TranslationStore = class {
522
+ /** Current flat translation overrides keyed by dot-path. */
518
523
  overrides = {};
519
524
  listeners = /* @__PURE__ */ new Set();
525
+ /** Replaces all overrides and notifies subscribers. */
520
526
  setOverrides = (overrides) => {
521
527
  this.overrides = { ...overrides };
522
528
  this.emit();
523
529
  };
530
+ /** Merges changed overrides and notifies subscribers. */
524
531
  updateOverrides = (newOverrides) => {
525
532
  this.overrides = { ...this.overrides, ...newOverrides };
526
533
  this.emit();
527
534
  };
535
+ /** Returns the current client snapshot for `useSyncExternalStore`. */
528
536
  getSnapshot = () => this.overrides;
537
+ /** Returns the current server snapshot for `useSyncExternalStore`. */
529
538
  getServerSnapshot = () => this.overrides;
539
+ /** Subscribes to override changes and returns an unsubscribe callback. */
530
540
  subscribe = (callback) => {
531
541
  this.listeners.add(callback);
532
542
  return () => {
@@ -658,12 +668,16 @@ function registerPixelInstance() {
658
668
  };
659
669
  }
660
670
  var ThemeSettingsStore = class {
671
+ /** Current merged theme setting values. */
661
672
  settings = {};
673
+ /** Theme schema exposed to Studio, when available. */
662
674
  schema;
675
+ /** Storefront-safe environment values, when available. */
663
676
  publicEnv;
664
677
  listeners = /* @__PURE__ */ new Set();
665
678
  hasWarnedListenerCount = false;
666
679
  isDestroyed = false;
680
+ /** Creates a theme settings store from root-loader theme data. */
667
681
  constructor(data) {
668
682
  const { theme, schema: schema2, publicEnv } = data || {};
669
683
  this.settings = { ...theme };
@@ -673,6 +687,7 @@ var ThemeSettingsStore = class {
673
687
  window.__weaverseThemeSettingsStore = this;
674
688
  }
675
689
  }
690
+ /** Merges setting changes into the current snapshot and notifies subscribers. */
676
691
  updateThemeSettings = (newSettings) => {
677
692
  if (this.isDestroyed) {
678
693
  console.warn("ThemeSettingsStore: Cannot update destroyed store");
@@ -684,8 +699,11 @@ var ThemeSettingsStore = class {
684
699
  };
685
700
  this.emit();
686
701
  };
702
+ /** Returns the current client snapshot for `useSyncExternalStore`. */
687
703
  getSnapshot = () => this.settings;
704
+ /** Returns the current server snapshot for `useSyncExternalStore`. */
688
705
  getServerSnapshot = () => this.settings;
706
+ /** Subscribes to setting changes and returns an unsubscribe callback. */
689
707
  subscribe = (callback) => {
690
708
  if (this.isDestroyed) {
691
709
  console.warn("ThemeSettingsStore: Cannot subscribe to destroyed store");
@@ -716,6 +734,7 @@ var ThemeSettingsStore = class {
716
734
  }
717
735
  }
718
736
  };
737
+ /** Clears subscribers and detaches the browser-global store reference. */
719
738
  destroy = () => {
720
739
  if (this.isDestroyed) {
721
740
  return;
@@ -865,6 +884,7 @@ var WeaverseHydrogenItem = class extends WeaverseItemStore {
865
884
  _cachedSnapshot = null;
866
885
  _snapshotStoreRef = null;
867
886
  _snapshotTranslationRef = null;
887
+ /** Creates an item store from serialized component data and its owner. */
868
888
  constructor(initialData, weaverse) {
869
889
  super(initialData, weaverse);
870
890
  const { data, ...rest } = initialData;
@@ -875,6 +895,7 @@ var WeaverseHydrogenItem = class extends WeaverseItemStore {
875
895
  const schemaData = generateDataFromSchema(this.Element.schema);
876
896
  Object.assign(this._store, schemaData, data, rest);
877
897
  }
898
+ /** Registered component definition for this item's type. */
878
899
  get Element() {
879
900
  return super.Element;
880
901
  }
@@ -907,17 +928,32 @@ var WeaverseHydrogenItem = class extends WeaverseItemStore {
907
928
  };
908
929
  Weaverse.ItemConstructor = WeaverseHydrogenItem;
909
930
  var WeaverseHydrogen = class extends Weaverse {
931
+ /** Identifier of the rendered page. */
910
932
  pageId;
933
+ /** Runtime services and project metadata exposed to integrations. */
911
934
  internal;
935
+ /** Normalized URL and locale information for the current request. */
912
936
  requestInfo;
937
+ /** Identifier of the project supplying the page. */
913
938
  projectId;
939
+ /** Origin used for Studio assets and editor communication. */
914
940
  weaverseHost;
941
+ /** Base URL used for public content API requests. */
915
942
  weaverseApiBase;
943
+ /**
944
+ * API key read from environment/configuration for storefront requests or
945
+ * supplied by Studio requests while editing and previewing.
946
+ */
916
947
  weaverseApiKey;
948
+ /** Studio asset version supplied by the preview request. */
917
949
  weaverseVersion;
950
+ /** Whether the page is running inside the visual editor. */
918
951
  isDesignMode;
952
+ /** Whether a single component preview is being rendered. */
919
953
  isPreviewMode;
954
+ /** Whether a saved page revision is being previewed. */
920
955
  isRevisionPreview;
956
+ /** Component type requested by section preview mode. */
921
957
  sectionType;
922
958
  // ─── Translation sidecar (design mode only) ────────────────────────
923
959
  /**
@@ -927,8 +963,11 @@ var WeaverseHydrogen = class extends Weaverse {
927
963
  * returned to components, so translations render without monkey-patching.
928
964
  */
929
965
  translationMap = {};
966
+ /** Locale code for the active translation sidecar. */
930
967
  translationLocale = "";
968
+ /** Builder language identifier for the active translation sidecar. */
931
969
  translationLanguageId = "";
970
+ /** Creates a page runtime from resolved loader data and request settings. */
932
971
  constructor(params) {
933
972
  const { internal, pageId, requestInfo, ...coreParams } = params;
934
973
  super({ ...coreParams });
@@ -1231,25 +1270,38 @@ var SMART_CACHE_STRATEGIES = {
1231
1270
  }
1232
1271
  };
1233
1272
  var WeaverseClient = class {
1273
+ /** Builder API version used by this client. */
1234
1274
  API = API_PATH;
1275
+ /** Stable project configuration shared by page requests. */
1235
1276
  basePageConfigs;
1277
+ /** Stable request body fields shared by page requests. */
1236
1278
  basePageRequestBody;
1279
+ /** Resolved project and rendering-mode configuration. */
1237
1280
  configs;
1281
+ /** Hydrogen cache wrapper used for Builder API requests. */
1238
1282
  withCache;
1239
- // Required dependencies
1283
+ /** Incoming request associated with this client instance. */
1240
1284
  request;
1285
+ /** Hydrogen customer-account client, when configured. */
1241
1286
  customerAccount;
1287
+ /** Hydrogen Storefront API client and locale context. */
1242
1288
  storefront;
1289
+ /** Components registered for page rendering and component loaders. */
1243
1290
  components;
1291
+ /** Theme schema used for defaults and Studio editing. */
1244
1292
  themeSchema;
1293
+ /** Hydrogen runtime environment variables. */
1245
1294
  env;
1295
+ /** Cache storage supplied by the Hydrogen runtime. */
1246
1296
  cache;
1297
+ /** Background execution hook supplied by the Oxygen runtime. */
1247
1298
  waitUntil;
1248
1299
  // Performance optimizations
1249
1300
  parsedUrl;
1250
1301
  componentsByType;
1251
1302
  // Configuration
1252
1303
  fetchTimeoutMs;
1304
+ /** Creates a request-scoped client from the Hydrogen app context. */
1253
1305
  constructor(args) {
1254
1306
  this.request = args.request;
1255
1307
  this.storefront = args.storefront;
@@ -1998,6 +2050,7 @@ var WeaverseClient = class {
1998
2050
  return null;
1999
2051
  }
2000
2052
  };
2053
+ /** Executes the registered loader for one component and attaches its result. */
2001
2054
  execComponentLoader = async (item) => {
2002
2055
  const { data = {}, type, id } = item;
2003
2056
  const component = this.componentsByType.get(type);
@@ -2030,34 +2083,63 @@ function getSelectedProductOptions(request) {
2030
2083
  );
2031
2084
  }
2032
2085
  var IMAGES_PLACEHOLDERS = {
2086
+ /** White Weaverse logo placeholder. */
2033
2087
  logo_white: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-logo-w-600x200.svg",
2088
+ /** Black Weaverse logo placeholder. */
2034
2089
  logo_black: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-logo-k-600x200.svg",
2090
+ /** Generic square image placeholder. */
2035
2091
  image: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-image-1024x1024.svg",
2092
+ /** First landscape banner placeholder. */
2036
2093
  banner_1: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-lifestyle-1-1800x900.svg",
2094
+ /** Second landscape banner placeholder. */
2037
2095
  banner_2: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-lifestyle-2-1800x900.svg",
2096
+ /** Hats collection placeholder. */
2038
2097
  collection_1: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-collection-hats-1024x1024.svg",
2098
+ /** Shoes collection placeholder. */
2039
2099
  collection_2: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-collection-shoes-1024x1024.svg",
2100
+ /** Glasses collection placeholder. */
2040
2101
  collection_3: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-collection-glasses-1024x1024.svg",
2102
+ /** Lamps collection placeholder. */
2041
2103
  collection_4: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-collection-lamps-1024x1024.svg",
2104
+ /** Bags collection placeholder. */
2042
2105
  collection_5: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-collection-bags-1024x1024.svg",
2106
+ /** Watches collection placeholder. */
2043
2107
  collection_6: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-collection-watches-1024x1024.svg",
2108
+ /** Third watch product placeholder. */
2044
2109
  product_1: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-product-watch-3-1024x1024.svg",
2110
+ /** Second bag product placeholder. */
2045
2111
  product_2: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-product-bag-2-1024x1024.svg",
2112
+ /** First shoe product placeholder. */
2046
2113
  product_3: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-product-shoe-1-1024x1024.svg",
2114
+ /** Second lamp product placeholder. */
2047
2115
  product_4: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-product-lamp-2-1024x1024.svg",
2116
+ /** First glasses product placeholder. */
2048
2117
  product_5: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-product-glasses-1-1024x1024.svg",
2118
+ /** First lamp product placeholder. */
2049
2119
  product_6: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-product-lamp-1-1024x1024.svg",
2120
+ /** Second glasses product placeholder. */
2050
2121
  product_7: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-product-glasses-2-1024x1024.svg",
2122
+ /** Third hat product placeholder. */
2051
2123
  product_8: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-product-hat-3-1024x1024.svg",
2124
+ /** First bag product placeholder. */
2052
2125
  product_9: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-product-bag-1-1024x1024.svg",
2126
+ /** Second shoe product placeholder. */
2053
2127
  product_10: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-product-shoe-2-1024x1024.svg",
2128
+ /** Second hat product placeholder. */
2054
2129
  product_11: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-product-hat-2-1024x1024.svg",
2130
+ /** Third glasses product placeholder. */
2055
2131
  product_12: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-product-glasses-3-1024x1024.svg",
2132
+ /** Third shoe product placeholder. */
2056
2133
  product_13: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-product-shoe-3-1024x1024.svg",
2134
+ /** Third bag product placeholder. */
2057
2135
  product_14: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-product-bag-3-1024x1024.svg",
2136
+ /** First hat product placeholder. */
2058
2137
  product_15: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-product-hat-1-1024x1024.svg",
2138
+ /** Third lamp product placeholder. */
2059
2139
  product_16: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-product-lamp-3-1024x1024.svg",
2140
+ /** First watch product placeholder. */
2060
2141
  product_17: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-product-watch-1-1024x1024.svg",
2142
+ /** Second watch product placeholder. */
2061
2143
  product_18: "https://cdn.shopify.com/s/files/1/0838/0052/3057/files/fpo-product-watch-2-1024x1024.svg"
2062
2144
  };
2063
2145