@weaverse/react 5.5.0-beta.4 → 5.5.0-beta.7

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.mts CHANGED
@@ -30,12 +30,13 @@ type DataContext = Record<string, unknown>;
30
30
  declare function replaceContentDataConnectors(content: string, dataContext: DataContext | null | undefined): string;
31
31
  /**
32
32
  * Recursively replaces data connector placeholders in any data structure
33
+ * IMMUTABLE: Creates deep copies during processing to avoid mutating original data
33
34
  * Handles strings, objects, arrays, and nested combinations
34
35
  *
35
36
  * @param data - The data to process (string, object, array, or primitive)
36
37
  * @param dataContext - The data context for replacements
37
38
  * @param visited - Set to track visited objects for circular reference protection
38
- * @returns The data with all string placeholders replaced
39
+ * @returns IMMUTABLE copy of the data with all string placeholders replaced
39
40
  */
40
41
  declare function replaceContentDataConnectorsDeep<T>(data: T, dataContext: DataContext | null | undefined, visited?: WeakSet<WeakKey>): T;
41
42
 
@@ -58,6 +59,6 @@ type ItemComponentProps = {
58
59
  };
59
60
 
60
61
  declare const useSafeExternalStore: (subscribe: any, getSnapshot: any, getServerSnapshot?: any) => any;
61
- declare let WeaverseRoot: react.MemoExoticComponent<({ context }: WeaverseRootPropsType) => react_jsx_runtime.JSX.Element | null>;
62
+ declare const WeaverseRoot: react.MemoExoticComponent<({ context }: WeaverseRootPropsType) => react_jsx_runtime.JSX.Element | null>;
62
63
 
63
64
  export { type ItemComponentProps, WeaverseContext, WeaverseContextProvider, type WeaverseElementProps, WeaverseItemContext, WeaverseRoot, type WeaverseRootPropsType, replaceContentDataConnectors, replaceContentDataConnectorsDeep, useChildInstances, useItemInstance, useParentInstance, useSafeExternalStore, useWeaverse };
package/dist/index.d.ts CHANGED
@@ -30,12 +30,13 @@ type DataContext = Record<string, unknown>;
30
30
  declare function replaceContentDataConnectors(content: string, dataContext: DataContext | null | undefined): string;
31
31
  /**
32
32
  * Recursively replaces data connector placeholders in any data structure
33
+ * IMMUTABLE: Creates deep copies during processing to avoid mutating original data
33
34
  * Handles strings, objects, arrays, and nested combinations
34
35
  *
35
36
  * @param data - The data to process (string, object, array, or primitive)
36
37
  * @param dataContext - The data context for replacements
37
38
  * @param visited - Set to track visited objects for circular reference protection
38
- * @returns The data with all string placeholders replaced
39
+ * @returns IMMUTABLE copy of the data with all string placeholders replaced
39
40
  */
40
41
  declare function replaceContentDataConnectorsDeep<T>(data: T, dataContext: DataContext | null | undefined, visited?: WeakSet<WeakKey>): T;
41
42
 
@@ -58,6 +59,6 @@ type ItemComponentProps = {
58
59
  };
59
60
 
60
61
  declare const useSafeExternalStore: (subscribe: any, getSnapshot: any, getServerSnapshot?: any) => any;
61
- declare let WeaverseRoot: react.MemoExoticComponent<({ context }: WeaverseRootPropsType) => react_jsx_runtime.JSX.Element | null>;
62
+ declare const WeaverseRoot: react.MemoExoticComponent<({ context }: WeaverseRootPropsType) => react_jsx_runtime.JSX.Element | null>;
62
63
 
63
64
  export { type ItemComponentProps, WeaverseContext, WeaverseContextProvider, type WeaverseElementProps, WeaverseItemContext, WeaverseRoot, type WeaverseRootPropsType, replaceContentDataConnectors, replaceContentDataConnectorsDeep, useChildInstances, useItemInstance, useParentInstance, useSafeExternalStore, useWeaverse };
package/dist/index.js CHANGED
@@ -59,12 +59,69 @@ var import_react2 = require("react");
59
59
  var TEMPLATE_REGEX = /\{\{([^}]+)\}\}/g;
60
60
  var ARRAY_INDEX_REGEX = /^(\w+)\[(\d+)\]$/;
61
61
  function isSafePropertyName(key) {
62
- return key !== "__proto__" && key !== "constructor" && key !== "prototype";
62
+ const dangerousPatterns = ["__proto__", "constructor", "prototype"];
63
+ return !dangerousPatterns.includes(key);
64
+ }
65
+ function parseRouteAndProperty(path, dataContext) {
66
+ if (!dataContext || typeof path !== "string") {
67
+ return { routeKey: null, propertyPath: path };
68
+ }
69
+ const trimmedPath = path.trim();
70
+ const availableRouteKeys = Object.keys(dataContext).sort().join("|");
71
+ const cacheKey = `${trimmedPath}::${availableRouteKeys}`;
72
+ const cachedResult = routeParsingCache.get(cacheKey);
73
+ if (cachedResult) {
74
+ cachedResult.timestamp = Date.now();
75
+ return {
76
+ routeKey: cachedResult.routeKey,
77
+ propertyPath: cachedResult.propertyPath
78
+ };
79
+ }
80
+ const availableRoutes = Object.keys(dataContext).sort(
81
+ (a, b) => b.length - a.length
82
+ );
83
+ let result = {
84
+ routeKey: null,
85
+ propertyPath: trimmedPath
86
+ };
87
+ let found = false;
88
+ for (const routeKey of availableRoutes) {
89
+ if (trimmedPath === routeKey) {
90
+ result = { routeKey, propertyPath: "" };
91
+ found = true;
92
+ break;
93
+ }
94
+ if (trimmedPath.startsWith(routeKey + ".")) {
95
+ const propertyPath = trimmedPath.substring(routeKey.length + 1);
96
+ result = { routeKey, propertyPath };
97
+ found = true;
98
+ break;
99
+ }
100
+ }
101
+ if (!found) {
102
+ result = { routeKey: null, propertyPath: trimmedPath };
103
+ }
104
+ if (routeParsingCache.size >= ROUTE_PARSING_CACHE_MAX_SIZE) {
105
+ const entries = Array.from(routeParsingCache.entries());
106
+ entries.sort((a, b) => a[1].timestamp - b[1].timestamp);
107
+ const toRemove = Math.floor(entries.length * 0.25);
108
+ for (let i = 0; i < toRemove; i++) {
109
+ routeParsingCache.delete(entries[i][0]);
110
+ }
111
+ }
112
+ routeParsingCache.set(cacheKey, {
113
+ routeKey: result.routeKey,
114
+ propertyPath: result.propertyPath,
115
+ timestamp: Date.now()
116
+ });
117
+ return result;
63
118
  }
64
119
  var templateCache = /* @__PURE__ */ new Map();
65
120
  var MAX_CACHE_SIZE = 100;
66
121
  var fallbackCache = /* @__PURE__ */ new Map();
67
122
  var FALLBACK_CACHE_MAX_SIZE = 50;
123
+ var routeParsingCache = /* @__PURE__ */ new Map();
124
+ var ROUTE_PARSING_CACHE_MAX_SIZE = 100;
68
125
  function getNestedValue(obj, path, visited = /* @__PURE__ */ new WeakSet()) {
69
126
  return path.split(".").reduce((current, key) => {
70
127
  if (!current || typeof current !== "object") {
@@ -115,14 +172,18 @@ function resolveDataFromContext(path, dataContext) {
115
172
  return;
116
173
  }
117
174
  const trimmedPath = path.trim();
118
- const pathParts = trimmedPath.split(".");
119
- const potentialRouteKey = pathParts[0];
120
- if (dataContext[potentialRouteKey] && typeof dataContext[potentialRouteKey] === "object" && dataContext[potentialRouteKey] !== null) {
121
- const remainingPath = pathParts.slice(1).join(".");
122
- if (remainingPath) {
123
- return getNestedValue(dataContext[potentialRouteKey], remainingPath);
175
+ const { routeKey, propertyPath } = parseRouteAndProperty(
176
+ trimmedPath,
177
+ dataContext
178
+ );
179
+ if (routeKey && dataContext[routeKey]) {
180
+ const routeData = dataContext[routeKey];
181
+ if (typeof routeData === "object" && routeData !== null) {
182
+ if (propertyPath) {
183
+ return getNestedValue(routeData, propertyPath);
184
+ }
185
+ return routeData;
124
186
  }
125
- return dataContext[potentialRouteKey];
126
187
  }
127
188
  const cachedResult = fallbackCache.get(trimmedPath);
128
189
  if (cachedResult && dataContext[cachedResult.routeKey]) {
@@ -140,8 +201,8 @@ function resolveDataFromContext(path, dataContext) {
140
201
  ...priorityRoutes,
141
202
  ...Object.keys(dataContext).filter((k) => !priorityRoutes.includes(k))
142
203
  ];
143
- for (const routeKey of allRoutes) {
144
- const routeData = dataContext[routeKey];
204
+ for (const routeKey2 of allRoutes) {
205
+ const routeData = dataContext[routeKey2];
145
206
  if (routeData && typeof routeData === "object" && routeData !== null) {
146
207
  const value = getNestedValue(routeData, trimmedPath);
147
208
  if (value !== void 0) {
@@ -154,7 +215,7 @@ function resolveDataFromContext(path, dataContext) {
154
215
  }
155
216
  }
156
217
  fallbackCache.set(trimmedPath, {
157
- routeKey,
218
+ routeKey: routeKey2,
158
219
  value,
159
220
  timestamp: Date.now()
160
221
  });
@@ -217,10 +278,14 @@ function replaceContentDataConnectorsDeep(data, dataContext, visited = /* @__PUR
217
278
  }
218
279
  visited.add(data);
219
280
  try {
281
+ if (data instanceof Date) {
282
+ return new Date(data.getTime());
283
+ }
220
284
  if (Array.isArray(data)) {
221
- return data.map(
285
+ const result2 = data.map(
222
286
  (item) => replaceContentDataConnectorsDeep(item, dataContext, visited)
223
287
  );
288
+ return result2;
224
289
  }
225
290
  const result = {};
226
291
  for (const [key, value] of Object.entries(data)) {
@@ -320,17 +385,17 @@ var useSafeExternalStore = (subscribe, getSnapshot, getServerSnapshot = getSnaps
320
385
  return getSnapshot();
321
386
  };
322
387
  var WeaverseRoot = (0, import_react3.memo)(({ context }) => {
323
- let data = useSafeExternalStore(
388
+ const data = useSafeExternalStore(
324
389
  context.subscribe,
325
390
  context.getSnapShot,
326
391
  context.getSnapShot
327
392
  );
328
- let rootRef = (0, import_react3.useRef)(null);
393
+ const rootRef = (0, import_react3.useRef)(null);
329
394
  (0, import_react3.useEffect)(() => {
330
395
  context.contentRootElement = rootRef.current;
331
396
  }, [context]);
332
- let eventHandlers = context?.studioBridge?.eventHandlers || {};
333
- let themeClass = context.stitchesInstance.theme.className;
397
+ const eventHandlers = context?.studioBridge?.eventHandlers || {};
398
+ const themeClass = context.stitchesInstance.theme.className;
334
399
  if (context.projectId) {
335
400
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
336
401
  "div",
@@ -354,14 +419,14 @@ var WeaverseRoot = (0, import_react3.memo)(({ context }) => {
354
419
  });
355
420
  WeaverseRoot.displayName = "WeaverseRoot";
356
421
  var ItemComponent = (0, import_react3.memo)(({ instance }) => {
357
- let context = useWeaverse();
358
- let { stitchesInstance, elementRegistry, platformType } = context;
359
- let data = useSafeExternalStore(
422
+ const context = useWeaverse();
423
+ const { stitchesInstance, elementRegistry, platformType } = context;
424
+ const data = useSafeExternalStore(
360
425
  instance.subscribe,
361
426
  instance.getSnapShot,
362
427
  instance.getSnapShot
363
428
  );
364
- let {
429
+ const {
365
430
  id,
366
431
  type,
367
432
  childIds = [],
@@ -374,13 +439,12 @@ var ItemComponent = (0, import_react3.memo)(({ instance }) => {
374
439
  __hidden,
375
440
  // Need to get rid of this `data` property
376
441
  data: _,
377
- content,
378
442
  ...rest
379
443
  } = data;
380
- if (content !== void 0 && content !== null) {
381
- content = replaceContentDataConnectorsDeep(content, context.dataContext);
382
- rest.content = content;
383
- }
444
+ const processedRest = replaceContentDataConnectorsDeep(
445
+ rest,
446
+ context.dataContext
447
+ );
384
448
  (0, import_react3.useEffect)(() => {
385
449
  if (!instance.ref.current) {
386
450
  Object.assign(instance.ref, {
@@ -391,22 +455,22 @@ var ItemComponent = (0, import_react3.memo)(({ instance }) => {
391
455
  if (__hidden) {
392
456
  return null;
393
457
  }
394
- let Element = elementRegistry.get(type);
458
+ const Element = elementRegistry.get(type);
395
459
  if (Element?.Component) {
396
- let Component = Element.Component;
460
+ const Component = Element.Component;
397
461
  Component.displayName = type;
398
462
  if (Component.$$typeof === Symbol.for("react.forward_ref") || reactVersion > 18) {
399
- rest.ref = instance.ref;
463
+ processedRest.ref = instance.ref;
400
464
  }
401
- let renderChildren = (children?.length ? children : childIds?.length ? childIds.map((cid) => ({ id: cid })) : []).map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ItemInstance, { id: item.id, parentId: id }, `${item.id}-${index}`));
465
+ const renderChildren = (children?.length ? children : childIds?.length ? childIds.map((cid) => ({ id: cid })) : []).map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ItemInstance, { id: item.id, parentId: id }, `${item.id}-${index}`));
402
466
  return /* @__PURE__ */ (0, import_react4.createElement)(
403
467
  Component,
404
468
  {
405
- ...rest,
469
+ ...processedRest,
406
470
  children: renderChildren.length ? renderChildren : void 0,
407
471
  className: (0, import_clsx2.default)(
408
472
  platformType !== "shopify-hydrogen" && generateItemClassName(instance, stitchesInstance),
409
- rest.data?.className
473
+ processedRest.data?.className
410
474
  ),
411
475
  "data-wv-id": id,
412
476
  "data-wv-type": type,
@@ -415,13 +479,12 @@ var ItemComponent = (0, import_react3.memo)(({ instance }) => {
415
479
  );
416
480
  }
417
481
  instance._store.deleted = true;
418
- console.log(`\u274C Unknown element: ${type}`);
419
482
  return null;
420
483
  });
421
484
  ItemComponent.displayName = "WeaverseComponent";
422
485
  var ItemInstance = (0, import_react3.memo)(
423
486
  ({ id, parentId }) => {
424
- let instance = useItemInstance(id);
487
+ const instance = useItemInstance(id);
425
488
  if (!instance) {
426
489
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "none" }, children: [
427
490
  "Item instance ",
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/context.ts","../src/hooks.ts","../src/utils/data-connector.ts","../src/renderer.tsx","../src/utils/css.ts"],"sourcesContent":["export * from '@weaverse/core'\nexport * from './context'\nexport * from './hooks'\nexport * from './renderer'\nexport * from './types'\n","import type { Weaverse } from '@weaverse/core'\nimport { createContext } from 'react'\n\nexport let WeaverseContext = createContext<Weaverse>({} as Weaverse)\nexport let WeaverseContextProvider = WeaverseContext.Provider\nexport let WeaverseItemContext = createContext<{\n id: string\n parentId: string\n}>({ id: '', parentId: '' })\n","import { Weaverse, type WeaverseItemStore } from '@weaverse/core'\nimport { useContext } from 'react'\nimport { WeaverseContext, WeaverseItemContext } from '~/context'\n\n// Re-export the data connector utilities\nexport {\n replaceContentDataConnectors,\n replaceContentDataConnectorsDeep,\n} from './utils/data-connector'\n\nexport function useWeaverse<T = Weaverse>() {\n let weaverse = useContext(WeaverseContext)\n return weaverse as T\n}\n\nexport let useItemInstance = (id?: string) => {\n let { id: currentId } = useContext(WeaverseItemContext)\n let instance = Weaverse.itemInstances.get(id || currentId)\n if (!instance) {\n console.log(`Item instance ${id} not found`)\n return null\n }\n return instance as WeaverseItemStore\n}\n\nexport let useParentInstance = () => {\n let { parentId } = useContext(WeaverseItemContext)\n return useItemInstance(parentId || '')\n}\n\nexport let useChildInstances = (id?: string) => {\n let currentInstance = useItemInstance(id)\n if (!currentInstance) {\n return []\n }\n let { itemInstances } = Weaverse\n\n let {\n data: { children },\n } = currentInstance\n return children\n .map(({ id }: { id: string }) => itemInstances.get(id))\n .filter(Boolean) as WeaverseItemStore[]\n}\n","// Data connector utilities for replacing placeholders with real data\n// Generic data context type for flexible usage\nexport type DataContext = Record<string, unknown>\n\n// Cached regex pattern for better performance\nconst TEMPLATE_REGEX = /\\{\\{([^}]+)\\}\\}/g\nconst ARRAY_INDEX_REGEX = /^(\\w+)\\[(\\d+)\\]$/\n\n/**\n * Validates that a property name is safe to access (prevents prototype pollution)\n */\nfunction isSafePropertyName(key: string): boolean {\n return key !== '__proto__' && key !== 'constructor' && key !== 'prototype'\n}\n\n// Simple cache for parsed templates (max 100 entries)\nconst templateCache = new Map<string, string>()\nconst MAX_CACHE_SIZE = 100\n\n// Cache for fallback lookups to improve performance (moved to module level to prevent memory leaks)\nconst fallbackCache = new Map<\n string,\n { routeKey: string; value: unknown; timestamp: number }\n>()\nconst FALLBACK_CACHE_MAX_SIZE = 50\n\n/**\n * Safely gets a nested value from an object using dot notation path\n * Supports array indexing with [index] syntax\n * @param obj - The object to traverse\n * @param path - Dot notation path (e.g., \"user.name\" or \"items[0].title\")\n * @param visited - Set to track visited objects for circular reference protection\n * @returns The resolved value or undefined if not found\n */\nfunction getNestedValue(\n obj: unknown,\n path: string,\n visited = new WeakSet()\n): unknown {\n return path.split('.').reduce((current, key) => {\n if (!current || typeof current !== 'object') {\n return\n }\n\n // Protect against circular references\n if (visited.has(current as WeakKey)) {\n console.warn('Circular reference detected in data connector path:', path)\n return\n }\n\n // Add to circular reference tracking\n visited.add(current as WeakKey)\n\n // Handle array indexing like items[0] or items[1]\n const arrayMatch = key.match(ARRAY_INDEX_REGEX)\n if (arrayMatch) {\n const [, arrayKey, index] = arrayMatch\n const arrayObj = (current as Record<string, unknown>)[arrayKey]\n if (Array.isArray(arrayObj)) {\n const indexNum = Number.parseInt(index, 10)\n if (indexNum >= 0 && indexNum < arrayObj.length) {\n return arrayObj[indexNum]\n }\n }\n return\n }\n\n // Handle regular object property access with security validation\n if (!isSafePropertyName(key)) {\n console.warn(`Unsafe property access attempted: ${key}`)\n return\n }\n\n return current !== null && key in current\n ? (current as Record<string, unknown>)[key]\n : undefined\n }, obj)\n}\n\n/**\n * Sanitizes a string value to prevent XSS attacks\n * @param value - The value to sanitize\n * @returns Sanitized string safe for HTML rendering\n */\nfunction sanitizeValue(value: unknown): string {\n if (value === null || value === undefined) {\n return ''\n }\n\n const stringValue = String(value)\n\n // Basic HTML entity encoding to prevent XSS\n return stringValue\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n .replace(/'/g, '&#x27;')\n .replace(/\\//g, '&#x2F;')\n}\n\n/**\n * Creates a safe cache key from content and data\n * Handles circular references by using a simplified approach\n */\nfunction createCacheKey(\n content: string,\n data: Record<string, unknown>\n): string {\n try {\n // Try a simple JSON stringification with a limit\n const dataStr = JSON.stringify(data)\n return `${content}:${dataStr.slice(0, 100)}`\n } catch {\n // If JSON.stringify fails (circular references), use a simpler approach\n const keys = Object.keys(data).sort().join(',')\n return `${content}:keys:${keys}`\n }\n}\n\n/**\n * Resolves data from the flat route-keyed data context\n * Supports both route-specific ({{root.layout.shop.name}}) and fallback ({{shop.name}}) access\n */\nfunction resolveDataFromContext(\n path: string,\n dataContext: DataContext | null | undefined\n): unknown {\n if (!dataContext) {\n return\n }\n\n const trimmedPath = path.trim()\n\n // Check if path starts with a route key (e.g., \"root.layout.shop.name\")\n const pathParts = trimmedPath.split('.')\n const potentialRouteKey = pathParts[0]\n\n // If we have route-keyed data and the first part matches a route\n if (\n dataContext[potentialRouteKey] &&\n typeof dataContext[potentialRouteKey] === 'object' &&\n dataContext[potentialRouteKey] !== null\n ) {\n // Remove route key and resolve rest of path from that route's data\n const remainingPath = pathParts.slice(1).join('.')\n if (remainingPath) {\n return getNestedValue(dataContext[potentialRouteKey], remainingPath)\n }\n return dataContext[potentialRouteKey]\n }\n\n // Fallback: search across all route data for backward compatibility\n // This handles cases like {{shop.name}} without route prefix\n\n // Check cache first\n const cachedResult = fallbackCache.get(trimmedPath)\n if (cachedResult && dataContext[cachedResult.routeKey]) {\n const value = getNestedValue(\n dataContext[cachedResult.routeKey],\n trimmedPath\n )\n if (value !== undefined) {\n // Update timestamp on cache hit\n cachedResult.timestamp = Date.now()\n return value\n }\n }\n\n // Search with priority order (most common routes first)\n const priorityRoutes = ['root', 'routes/product', 'routes/collection']\n const allRoutes = [\n ...priorityRoutes,\n ...Object.keys(dataContext).filter((k) => !priorityRoutes.includes(k)),\n ]\n\n for (const routeKey of allRoutes) {\n const routeData = dataContext[routeKey]\n if (routeData && typeof routeData === 'object' && routeData !== null) {\n const value = getNestedValue(routeData, trimmedPath)\n if (value !== undefined) {\n // Clean cache if it's getting too large\n if (fallbackCache.size >= FALLBACK_CACHE_MAX_SIZE) {\n const entries = Array.from(fallbackCache.entries())\n entries.sort((a, b) => a[1].timestamp - b[1].timestamp)\n // Remove oldest 25% of entries\n const toRemove = Math.floor(entries.length * 0.25)\n for (let i = 0; i < toRemove; i++) {\n fallbackCache.delete(entries[i][0])\n }\n }\n fallbackCache.set(trimmedPath, {\n routeKey,\n value,\n timestamp: Date.now(),\n })\n return value\n }\n }\n }\n\n // Final fallback: try direct access (for non-route-keyed legacy data)\n return getNestedValue(dataContext, trimmedPath)\n}\n\n/**\n * Replaces data connector placeholders in content with actual values from data context\n * Supports {{path}} syntax with dot notation, array indexing, and route prefixes\n *\n * Enhanced syntax:\n * - {{root.siteSettings.title}} - Access root route data\n * - {{layout.navigation.items}} - Access layout route data\n * - {{parent.category.name}} - Access parent route data\n * - {{current.product.title}} - Access current route data\n * - {{user.name}} - Auto-resolved from combined data (backward compatible)\n *\n * @param content - The content string containing {{}} placeholders\n * @param dataContext - The enhanced WeaverseDataContext with route-keyed data\n * @returns The content with placeholders replaced by actual values\n */\nexport function replaceContentDataConnectors(\n content: string,\n dataContext: DataContext | null | undefined\n): string {\n if (!dataContext || typeof content !== 'string') {\n return content\n }\n\n try {\n // Simplified caching - dataContext is already the combined data\n const cacheKey = createCacheKey(content, dataContext)\n\n if (templateCache.has(cacheKey)) {\n return templateCache.get(cacheKey)!\n }\n\n const newContent = content.replace(TEMPLATE_REGEX, (match, path) => {\n try {\n const value = resolveDataFromContext(path, dataContext)\n\n if (value === undefined || value === null) {\n return match // Return original placeholder if value not found\n }\n\n return sanitizeValue(value)\n } catch (pathError) {\n console.warn(\n `Error resolving data connector path \"${path}\":`,\n pathError\n )\n return match\n }\n })\n\n // Cache the result (with size limit)\n if (templateCache.size >= MAX_CACHE_SIZE) {\n const firstKey = templateCache.keys().next().value\n templateCache.delete(firstKey)\n }\n templateCache.set(cacheKey, newContent)\n\n return newContent\n } catch (error) {\n console.warn('Error processing data connectors:', error, { content })\n return content\n }\n}\n\n/**\n * Recursively replaces data connector placeholders in any data structure\n * Handles strings, objects, arrays, and nested combinations\n *\n * @param data - The data to process (string, object, array, or primitive)\n * @param dataContext - The data context for replacements\n * @param visited - Set to track visited objects for circular reference protection\n * @returns The data with all string placeholders replaced\n */\nexport function replaceContentDataConnectorsDeep<T>(\n data: T,\n dataContext: DataContext | null | undefined,\n visited = new WeakSet()\n): T {\n if (!dataContext) {\n return data\n }\n\n // Handle primitive types\n if (typeof data === 'string') {\n return replaceContentDataConnectors(data, dataContext) as T\n }\n\n if (typeof data !== 'object' || data === null) {\n return data\n }\n\n // Protect against circular references\n if (visited.has(data as WeakKey)) {\n console.warn(\n 'Circular reference detected in deep data connector replacement'\n )\n return data\n }\n\n // Add to circular reference tracking\n visited.add(data as WeakKey)\n\n try {\n // Handle arrays\n if (Array.isArray(data)) {\n return data.map((item) =>\n replaceContentDataConnectorsDeep(item, dataContext, visited)\n ) as T\n }\n\n // Handle objects\n const result = {} as T\n for (const [key, value] of Object.entries(data)) {\n ;(result as Record<string, unknown>)[key] =\n replaceContentDataConnectorsDeep(value, dataContext, visited)\n }\n\n return result\n } catch (error) {\n console.warn('Error in deep data connector replacement:', error)\n return data\n } finally {\n // Remove from tracking when done processing this object\n visited.delete(data as WeakKey)\n }\n}\n","import clsx from 'clsx'\nimport * as React from 'react'\nimport { memo, useEffect, useRef } from 'react'\nimport { useItemInstance, useWeaverse } from '~/hooks'\nimport { WeaverseContextProvider, WeaverseItemContext } from './context'\nimport type { ItemComponentProps, WeaverseRootPropsType } from './types'\nimport { generateItemClassName } from './utils/css'\nimport { replaceContentDataConnectorsDeep } from './utils/data-connector'\n\nlet reactVersion = Number(React.version?.split('.')[0]) || 0\n\n// Create a safe version of useSyncExternalStore that works in both client and server environments\nexport const useSafeExternalStore = (\n subscribe: any,\n getSnapshot: any,\n getServerSnapshot: any = getSnapshot\n) => {\n // In server environment or during SSR, just return the snapshot directly\n if (typeof window === 'undefined') {\n return getServerSnapshot()\n }\n\n // In client environment, use React.useSyncExternalStore if available (React 18+)\n if (React.useSyncExternalStore) {\n // biome-ignore lint/correctness/useHookAtTopLevel: <$>\n return React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)\n }\n\n // Fallback for older React versions - just return the current snapshot\n return getSnapshot()\n}\n\nexport let WeaverseRoot = memo(({ context }: WeaverseRootPropsType) => {\n let data = useSafeExternalStore(\n context.subscribe,\n context.getSnapShot,\n context.getSnapShot\n )\n let rootRef = useRef<HTMLElement>(null)\n\n useEffect(() => {\n context.contentRootElement = rootRef.current\n }, [context])\n\n let eventHandlers = context?.studioBridge?.eventHandlers || {}\n let themeClass = context.stitchesInstance.theme.className\n\n if (context.projectId) {\n return (\n <div\n className={`weaverse-content-root ${themeClass}`}\n {...eventHandlers}\n data-weaverse-project-id={context.projectId}\n data-weaverse-template-id={data.id}\n ref={rootRef}\n >\n <WeaverseContextProvider value={context}>\n <ItemInstance\n id={context.data.rootId || context.projectId}\n parentId={''}\n />\n </WeaverseContextProvider>\n </div>\n )\n }\n return null\n})\nWeaverseRoot.displayName = 'WeaverseRoot'\nconst ItemComponent = memo(({ instance }: ItemComponentProps) => {\n let context = useWeaverse()\n let { stitchesInstance, elementRegistry, platformType } = context\n let data = useSafeExternalStore(\n instance.subscribe,\n instance.getSnapShot,\n instance.getSnapShot\n )\n let {\n id,\n type,\n childIds = [],\n children = [],\n parentId,\n createdAt,\n updatedAt,\n deletedAt,\n css,\n __hidden,\n // Need to get rid of this `data` property\n data: _,\n content,\n ...rest\n } = data\n // Replace data connectors in content (handles strings, objects, and arrays recursively)\n if (content !== undefined && content !== null) {\n content = replaceContentDataConnectorsDeep(content, context.dataContext)\n rest.content = content\n }\n\n useEffect(() => {\n if (!instance.ref.current) {\n // Fallback `ref` if the element isn't created by `React.forwardRef`\n Object.assign(instance.ref, {\n current: document.querySelector(`[data-wv-id=\"${id}\"]`),\n })\n }\n }, [instance, id])\n\n if (__hidden) {\n return null\n }\n\n let Element = elementRegistry.get(type)\n\n if (Element?.Component) {\n let Component = Element.Component\n Component.displayName = type\n if (\n Component.$$typeof === Symbol.for('react.forward_ref') ||\n reactVersion > 18\n ) {\n rest.ref = instance.ref\n }\n let renderChildren = (\n children?.length\n ? children\n : childIds?.length\n ? childIds.map((cid: string) => ({ id: cid }))\n : []\n ).map((item: { id: string }, index: number) => (\n <ItemInstance id={item.id} key={`${item.id}-${index}`} parentId={id} />\n ))\n\n return (\n <Component\n {...rest}\n children={renderChildren.length ? renderChildren : undefined}\n className={clsx(\n platformType !== 'shopify-hydrogen' &&\n generateItemClassName(instance, stitchesInstance),\n rest.data?.className\n )}\n data-wv-id={id}\n data-wv-type={type}\n key={id}\n />\n )\n }\n instance._store.deleted = true\n console.log(`❌ Unknown element: ${type}`)\n return null\n})\nItemComponent.displayName = 'WeaverseComponent'\n\nlet ItemInstance = memo(\n ({ id, parentId }: { id: string; parentId: string }) => {\n let instance = useItemInstance(id)\n if (!instance) {\n return <div style={{ display: 'none' }}>Item instance {id} not found</div>\n }\n return (\n <WeaverseItemContext.Provider value={{ parentId, id }}>\n <ItemComponent instance={instance} key={id} />\n </WeaverseItemContext.Provider>\n )\n }\n)\nItemInstance.displayName = 'WeaverseInstanceProvider'\n","import type Stitches from '@stitches/react/types/stitches'\nimport type { ElementCSS, WeaverseItemStore } from '@weaverse/core'\nimport clsx from 'clsx'\n\n// Make the css data formatted to correct order (desktop, tablet, mobile)\nfunction formatCSS(css: ElementCSS) {\n return {\n '@desktop': css['@desktop'],\n '@mobile': css['@mobile'],\n }\n}\n\nlet permanentClasses: Record<string, string> = {}\nexport function generateItemClassName(\n instance: WeaverseItemStore,\n stitchesInstance: Stitches\n) {\n let { css, type, className: cls = '' } = instance.data\n let className = ''\n let permanentClass = ''\n let perCss = instance.Element?.permanentCss\n if (perCss) {\n if (type in permanentClasses) {\n permanentClass = permanentClasses[type]\n } else {\n // @ts-expect-error\n let { className: perCls } = stitchesInstance.css(perCss)()\n Object.assign(permanentClasses, { [type]: perCls })\n permanentClass = perCls\n }\n }\n className = permanentClass\n if (css) {\n // let stitches create the style from css object and\n // then return the classname, so we can use it in the render\n let formattedCss = formatCSS(css)\n let newStitchesClass = stitchesInstance.css(formattedCss)().className || ''\n let { stitchesClass = '' } = instance\n let otherClass = (instance.ref.current?.className || '')\n .replace(stitchesClass, '')\n .replace(cls, '')\n .replace(permanentClass, '')\n .trim()\n className = clsx(permanentClass, cls, newStitchesClass, otherClass)\n instance.stitchesClass = newStitchesClass\n }\n return className\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAc,2BAAd;;;ACCA,mBAA8B;AAEvB,IAAI,sBAAkB,4BAAwB,CAAC,CAAa;AAC5D,IAAI,0BAA0B,gBAAgB;AAC9C,IAAI,0BAAsB,4BAG9B,EAAE,IAAI,IAAI,UAAU,GAAG,CAAC;;;ACR3B,kBAAiD;AACjD,IAAAA,gBAA2B;;;ACI3B,IAAM,iBAAiB;AACvB,IAAM,oBAAoB;AAK1B,SAAS,mBAAmB,KAAsB;AAChD,SAAO,QAAQ,eAAe,QAAQ,iBAAiB,QAAQ;AACjE;AAGA,IAAM,gBAAg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AAI,KAAK,EAAkB,CACtE;AAED,WACE;AAAA,MAAC;AAAA;AAAA,QACE,GAAG;AAAA,QACJ,UAAU,eAAe,SAAS,iBAAiB;AAAA,QACnD,eAAW,aAAAC;AAAA,UACT,iBAAiB,sBACf,sBAAsB,UAAU,gBAAgB;AAAA,UAClD,KAAK,MAAM;AAAA,QACb;AAAA,QACA,cAAY;AAAA,QACZ,gBAAc;AAAA,QACd,KAAK;AAAA;AAAA,IACP;AAAA,EAEJ;AACA,WAAS,OAAO,UAAU;AAC1B,UAAQ,IAAI,2BAAsB,IAAI,EAAE;AACxC,SAAO;AACT,CAAC;AACD,cAAc,cAAc;AAE5B,IAAI,mBAAe;AAAA,EACjB,CAAC,EAAE,IAAI,SAAS,MAAwC;AACtD,QAAI,WAAW,gBAAgB,EAAE;AACjC,QAAI,CAAC,UAAU;AACb,aAAO,6CAAC,SAAI,OAAO,EAAE,SAAS,OAAO,GAAG;AAAA;AAAA,QAAe;AAAA,QAAG;AAAA,SAAU;AAAA,IACtE;AACA,WACE,4CAAC,oBAAoB,UAApB,EAA6B,OAAO,EAAE,UAAU,GAAG,GAClD,sDAAC,iBAAc,YAAyB,EAAI,GAC9C;AAAA,EAEJ;AACF;AACA,aAAa,cAAc;","names":["import_react","id","import_clsx","import_react","clsx","import_react","clsx"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/context.ts","../src/hooks.ts","../src/utils/data-connector.ts","../src/renderer.tsx","../src/utils/css.ts"],"sourcesContent":["export * from '@weaverse/core'\nexport * from './context'\nexport * from './hooks'\nexport * from './renderer'\nexport * from './types'\n","import type { Weaverse } from '@weaverse/core'\nimport { createContext } from 'react'\n\nexport let WeaverseContext = createContext<Weaverse>({} as Weaverse)\nexport let WeaverseContextProvider = WeaverseContext.Provider\nexport let WeaverseItemContext = createContext<{\n id: string\n parentId: string\n}>({ id: '', parentId: '' })\n","import { Weaverse, type WeaverseItemStore } from '@weaverse/core'\nimport { useContext } from 'react'\nimport { WeaverseContext, WeaverseItemContext } from '~/context'\n\n// Re-export the data connector utilities\nexport {\n replaceContentDataConnectors,\n replaceContentDataConnectorsDeep,\n} from './utils/data-connector'\n\nexport function useWeaverse<T = Weaverse>() {\n let weaverse = useContext(WeaverseContext)\n return weaverse as T\n}\n\nexport let useItemInstance = (id?: string) => {\n let { id: currentId } = useContext(WeaverseItemContext)\n let instance = Weaverse.itemInstances.get(id || currentId)\n if (!instance) {\n console.log(`Item instance ${id} not found`)\n return null\n }\n return instance as WeaverseItemStore\n}\n\nexport let useParentInstance = () => {\n let { parentId } = useContext(WeaverseItemContext)\n return useItemInstance(parentId || '')\n}\n\nexport let useChildInstances = (id?: string) => {\n let currentInstance = useItemInstance(id)\n if (!currentInstance) {\n return []\n }\n let { itemInstances } = Weaverse\n\n let {\n data: { children },\n } = currentInstance\n return children\n .map(({ id }: { id: string }) => itemInstances.get(id))\n .filter(Boolean) as WeaverseItemStore[]\n}\n","// Data connector utilities for replacing placeholders with real data\n// Generic data context type for flexible usage\nexport type DataContext = Record<string, unknown>\n\n// Cached regex pattern for better performance\nconst TEMPLATE_REGEX = /\\{\\{([^}]+)\\}\\}/g\nconst ARRAY_INDEX_REGEX = /^(\\w+)\\[(\\d+)\\]$/\n\n/**\n * Validates that a property name is safe to access (prevents prototype pollution)\n * Enhanced to handle route-specific patterns with special characters\n */\nfunction isSafePropertyName(key: string): boolean {\n // Block dangerous prototype pollution patterns\n const dangerousPatterns = ['__proto__', 'constructor', 'prototype']\n return !dangerousPatterns.includes(key)\n}\n\n/**\n * Parses a template path into route key and property path components\n * Handles complex routes like: routes/($locale).blogs.$blogHandle.$articleHandle\n * Enhanced with caching for improved performance\n *\n * @param path - The full path from template (e.g., \"routes/($locale)._index.weaverseData.page.name\")\n * @param dataContext - Available route data context\n * @returns Object with routeKey and propertyPath\n */\nfunction parseRouteAndProperty(\n path: string,\n dataContext: DataContext\n): {\n routeKey: string | null\n propertyPath: string\n} {\n if (!dataContext || typeof path !== 'string') {\n return { routeKey: null, propertyPath: path }\n }\n\n const trimmedPath = path.trim()\n\n // Create a cache key that includes available routes for context awareness\n const availableRouteKeys = Object.keys(dataContext).sort().join('|')\n const cacheKey = `${trimmedPath}::${availableRouteKeys}`\n\n // Check cache first\n const cachedResult = routeParsingCache.get(cacheKey)\n if (cachedResult) {\n // Update timestamp on cache hit\n cachedResult.timestamp = Date.now()\n return {\n routeKey: cachedResult.routeKey,\n propertyPath: cachedResult.propertyPath,\n }\n }\n\n // Get all available routes and sort by length (longest first for specificity)\n const availableRoutes = Object.keys(dataContext).sort(\n (a, b) => b.length - a.length\n )\n\n let result: { routeKey: string | null; propertyPath: string } = {\n routeKey: null,\n propertyPath: trimmedPath,\n }\n\n // Try to find the longest matching route key\n let found = false\n for (const routeKey of availableRoutes) {\n // Exact match\n if (trimmedPath === routeKey) {\n result = { routeKey, propertyPath: '' }\n found = true\n break\n }\n\n // Route key with property path\n if (trimmedPath.startsWith(routeKey + '.')) {\n const propertyPath = trimmedPath.substring(routeKey.length + 1)\n result = { routeKey, propertyPath }\n found = true\n break\n }\n }\n\n if (!found) {\n // No route key found, treat entire path as property path\n result = { routeKey: null, propertyPath: trimmedPath }\n }\n\n // Cache the result\n if (routeParsingCache.size >= ROUTE_PARSING_CACHE_MAX_SIZE) {\n // Clean cache by removing oldest entries\n const entries = Array.from(routeParsingCache.entries())\n entries.sort((a, b) => a[1].timestamp - b[1].timestamp)\n const toRemove = Math.floor(entries.length * 0.25)\n for (let i = 0; i < toRemove; i++) {\n routeParsingCache.delete(entries[i][0])\n }\n }\n\n routeParsingCache.set(cacheKey, {\n routeKey: result.routeKey,\n propertyPath: result.propertyPath,\n timestamp: Date.now(),\n })\n\n return result\n}\n\n// Simple cache for parsed templates (max 100 entries)\nconst templateCache = new Map<string, string>()\nconst MAX_CACHE_SIZE = 100\n\n// Cache for fallback lookups to improve performance (moved to module level to prevent memory leaks)\nconst fallbackCache = new Map<\n string,\n { routeKey: string; value: unknown; timestamp: number }\n>()\nconst FALLBACK_CACHE_MAX_SIZE = 50\n\n// Route parsing cache for performance optimization\nconst routeParsingCache = new Map<\n string,\n { routeKey: string | null; propertyPath: string; timestamp: number }\n>()\nconst ROUTE_PARSING_CACHE_MAX_SIZE = 100\n\n/**\n * Safely gets a nested value from an object using dot notation path\n * Supports array indexing with [index] syntax\n * @param obj - The object to traverse\n * @param path - Dot notation path (e.g., \"user.name\" or \"items[0].title\")\n * @param visited - Set to track visited objects for circular reference protection\n * @returns The resolved value or undefined if not found\n */\nfunction getNestedValue(\n obj: unknown,\n path: string,\n visited = new WeakSet()\n): unknown {\n return path.split('.').reduce((current, key) => {\n if (!current || typeof current !== 'object') {\n return\n }\n\n // Protect against circular references\n if (visited.has(current as WeakKey)) {\n console.warn('Circular reference detected in data connector path:', path)\n return\n }\n\n // Add to circular reference tracking\n visited.add(current as WeakKey)\n\n // Handle array indexing like items[0] or items[1]\n const arrayMatch = key.match(ARRAY_INDEX_REGEX)\n if (arrayMatch) {\n const [, arrayKey, index] = arrayMatch\n const arrayObj = (current as Record<string, unknown>)[arrayKey]\n if (Array.isArray(arrayObj)) {\n const indexNum = Number.parseInt(index, 10)\n if (indexNum >= 0 && indexNum < arrayObj.length) {\n return arrayObj[indexNum]\n }\n }\n return\n }\n\n // Handle regular object property access with security validation\n if (!isSafePropertyName(key)) {\n console.warn(`Unsafe property access attempted: ${key}`)\n return\n }\n\n return current !== null && key in current\n ? (current as Record<string, unknown>)[key]\n : undefined\n }, obj)\n}\n\n/**\n * Sanitizes a string value to prevent XSS attacks\n * @param value - The value to sanitize\n * @returns Sanitized string safe for HTML rendering\n */\nfunction sanitizeValue(value: unknown): string {\n if (value === null || value === undefined) {\n return ''\n }\n\n const stringValue = String(value)\n\n // Basic HTML entity encoding to prevent XSS\n return stringValue\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n .replace(/'/g, '&#x27;')\n .replace(/\\//g, '&#x2F;')\n}\n\n/**\n * Creates a safe cache key from content and data\n * Handles circular references by using a simplified approach\n */\nfunction createCacheKey(\n content: string,\n data: Record<string, unknown>\n): string {\n try {\n // Try a simple JSON stringification with a limit\n const dataStr = JSON.stringify(data)\n return `${content}:${dataStr.slice(0, 100)}`\n } catch {\n // If JSON.stringify fails (circular references), use a simpler approach\n const keys = Object.keys(data).sort().join(',')\n return `${content}:keys:${keys}`\n }\n}\n\n/**\n * Resolves data from the flat route-keyed data context\n * Enhanced to support complex route patterns with special characters\n * Supports: {{root.layout.shop.name}}, {{routes/($locale)._index.data}}, {{routes/($locale).blogs.$handle.$article.content}}\n */\nfunction resolveDataFromContext(\n path: string,\n dataContext: DataContext | null | undefined\n): unknown {\n if (!dataContext) {\n return\n }\n\n const trimmedPath = path.trim()\n\n // Use intelligent route parsing to separate route key from property path\n const { routeKey, propertyPath } = parseRouteAndProperty(\n trimmedPath,\n dataContext\n )\n\n // If we found a specific route key, resolve from that route's data\n if (routeKey && dataContext[routeKey]) {\n const routeData = dataContext[routeKey]\n if (typeof routeData === 'object' && routeData !== null) {\n if (propertyPath) {\n return getNestedValue(routeData, propertyPath)\n }\n return routeData\n }\n }\n\n // Fallback: search across all route data for backward compatibility\n // This handles cases like {{shop.name}} without route prefix\n\n // Check cache first\n const cachedResult = fallbackCache.get(trimmedPath)\n if (cachedResult && dataContext[cachedResult.routeKey]) {\n const value = getNestedValue(\n dataContext[cachedResult.routeKey],\n trimmedPath\n )\n if (value !== undefined) {\n // Update timestamp on cache hit\n cachedResult.timestamp = Date.now()\n return value\n }\n }\n\n // Search with priority order (most common routes first)\n const priorityRoutes = ['root', 'routes/product', 'routes/collection']\n const allRoutes = [\n ...priorityRoutes,\n ...Object.keys(dataContext).filter((k) => !priorityRoutes.includes(k)),\n ]\n\n for (const routeKey of allRoutes) {\n const routeData = dataContext[routeKey]\n if (routeData && typeof routeData === 'object' && routeData !== null) {\n const value = getNestedValue(routeData, trimmedPath)\n if (value !== undefined) {\n // Clean cache if it's getting too large\n if (fallbackCache.size >= FALLBACK_CACHE_MAX_SIZE) {\n const entries = Array.from(fallbackCache.entries())\n entries.sort((a, b) => a[1].timestamp - b[1].timestamp)\n // Remove oldest 25% of entries\n const toRemove = Math.floor(entries.length * 0.25)\n for (let i = 0; i < toRemove; i++) {\n fallbackCache.delete(entries[i][0])\n }\n }\n fallbackCache.set(trimmedPath, {\n routeKey,\n value,\n timestamp: Date.now(),\n })\n return value\n }\n }\n }\n\n // Final fallback: try direct access (for non-route-keyed legacy data)\n return getNestedValue(dataContext, trimmedPath)\n}\n\n/**\n * Replaces data connector placeholders in content with actual values from data context\n * Supports {{path}} syntax with dot notation, array indexing, and route prefixes\n *\n * Enhanced syntax:\n * - {{root.siteSettings.title}} - Access root route data\n * - {{layout.navigation.items}} - Access layout route data\n * - {{parent.category.name}} - Access parent route data\n * - {{current.product.title}} - Access current route data\n * - {{user.name}} - Auto-resolved from combined data (backward compatible)\n *\n * @param content - The content string containing {{}} placeholders\n * @param dataContext - The enhanced WeaverseDataContext with route-keyed data\n * @returns The content with placeholders replaced by actual values\n */\nexport function replaceContentDataConnectors(\n content: string,\n dataContext: DataContext | null | undefined\n): string {\n if (!dataContext || typeof content !== 'string') {\n return content\n }\n\n try {\n // Simplified caching - dataContext is already the combined data\n const cacheKey = createCacheKey(content, dataContext)\n\n if (templateCache.has(cacheKey)) {\n return templateCache.get(cacheKey)!\n }\n\n const newContent = content.replace(TEMPLATE_REGEX, (match, path) => {\n try {\n const value = resolveDataFromContext(path, dataContext)\n\n if (value === undefined || value === null) {\n return match // Return original placeholder if value not found\n }\n\n return sanitizeValue(value)\n } catch (pathError) {\n console.warn(\n `Error resolving data connector path \"${path}\":`,\n pathError\n )\n return match\n }\n })\n\n // Cache the result (with size limit)\n if (templateCache.size >= MAX_CACHE_SIZE) {\n const firstKey = templateCache.keys().next().value\n templateCache.delete(firstKey)\n }\n templateCache.set(cacheKey, newContent)\n\n return newContent\n } catch (error) {\n console.warn('Error processing data connectors:', error, { content })\n return content\n }\n}\n\n/**\n * Recursively replaces data connector placeholders in any data structure\n * IMMUTABLE: Creates deep copies during processing to avoid mutating original data\n * Handles strings, objects, arrays, and nested combinations\n *\n * @param data - The data to process (string, object, array, or primitive)\n * @param dataContext - The data context for replacements\n * @param visited - Set to track visited objects for circular reference protection\n * @returns IMMUTABLE copy of the data with all string placeholders replaced\n */\nexport function replaceContentDataConnectorsDeep<T>(\n data: T,\n dataContext: DataContext | null | undefined,\n visited = new WeakSet()\n): T {\n if (!dataContext) {\n return data\n }\n\n // Handle primitive types - no cloning needed for primitives\n if (typeof data === 'string') {\n return replaceContentDataConnectors(data, dataContext) as T\n }\n\n if (typeof data !== 'object' || data === null) {\n return data\n }\n\n // Protect against circular references\n if (visited.has(data as WeakKey)) {\n console.warn(\n 'Circular reference detected in deep data connector replacement'\n )\n return data\n }\n\n // Add to circular reference tracking\n visited.add(data as WeakKey)\n\n try {\n // Handle special objects that should be cloned as-is\n if (data instanceof Date) {\n return new Date(data.getTime()) as T\n }\n\n // Handle arrays - create new array with processed items\n if (Array.isArray(data)) {\n const result = data.map((item) =>\n replaceContentDataConnectorsDeep(item, dataContext, visited)\n ) as T\n return result\n }\n\n // Handle plain objects - create new object with processed values\n const result = {} as T\n for (const [key, value] of Object.entries(data)) {\n ;(result as Record<string, unknown>)[key] =\n replaceContentDataConnectorsDeep(value, dataContext, visited)\n }\n\n return result\n } catch (error) {\n console.warn('Error in deep data connector replacement:', error)\n return data\n } finally {\n // Remove from tracking when done processing this object\n visited.delete(data as WeakKey)\n }\n}\n","import clsx from 'clsx'\nimport * as React from 'react'\nimport { memo, useEffect, useRef } from 'react'\nimport { useItemInstance, useWeaverse } from '~/hooks'\nimport { WeaverseContextProvider, WeaverseItemContext } from './context'\nimport type { ItemComponentProps, WeaverseRootPropsType } from './types'\nimport { generateItemClassName } from './utils/css'\nimport { replaceContentDataConnectorsDeep } from './utils/data-connector'\n\nconst reactVersion = Number(React.version?.split('.')[0]) || 0\n\n// Create a safe version of useSyncExternalStore that works in both client and server environments\nexport const useSafeExternalStore = (\n subscribe: any,\n getSnapshot: any,\n getServerSnapshot: any = getSnapshot\n) => {\n // In server environment or during SSR, just return the snapshot directly\n if (typeof window === 'undefined') {\n return getServerSnapshot()\n }\n\n // In client environment, use React.useSyncExternalStore if available (React 18+)\n if (React.useSyncExternalStore) {\n // biome-ignore lint/correctness/useHookAtTopLevel: <$>\n return React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)\n }\n\n // Fallback for older React versions - just return the current snapshot\n return getSnapshot()\n}\n\nexport const WeaverseRoot = memo(({ context }: WeaverseRootPropsType) => {\n const data = useSafeExternalStore(\n context.subscribe,\n context.getSnapShot,\n context.getSnapShot\n )\n const rootRef = useRef<HTMLElement>(null)\n\n useEffect(() => {\n context.contentRootElement = rootRef.current\n }, [context])\n\n const eventHandlers = context?.studioBridge?.eventHandlers || {}\n const themeClass = context.stitchesInstance.theme.className\n\n if (context.projectId) {\n return (\n <div\n className={`weaverse-content-root ${themeClass}`}\n {...eventHandlers}\n data-weaverse-project-id={context.projectId}\n data-weaverse-template-id={data.id}\n ref={rootRef}\n >\n <WeaverseContextProvider value={context}>\n <ItemInstance\n id={context.data.rootId || context.projectId}\n parentId={''}\n />\n </WeaverseContextProvider>\n </div>\n )\n }\n return null\n})\nWeaverseRoot.displayName = 'WeaverseRoot'\nconst ItemComponent = memo(({ instance }: ItemComponentProps) => {\n const context = useWeaverse()\n const { stitchesInstance, elementRegistry, platformType } = context\n const data = useSafeExternalStore(\n instance.subscribe,\n instance.getSnapShot,\n instance.getSnapShot\n )\n const {\n id,\n type,\n childIds = [],\n children = [],\n parentId,\n createdAt,\n updatedAt,\n deletedAt,\n css,\n __hidden,\n // Need to get rid of this `data` property\n data: _,\n ...rest\n } = data\n\n // Replace data connectors in all component data (handles strings, objects, and arrays recursively)\n // IMMUTABLE: Process the entire rest object to avoid mutating original content\n const processedRest = replaceContentDataConnectorsDeep(\n rest,\n context.dataContext\n )\n\n useEffect(() => {\n if (!instance.ref.current) {\n // Fallback `ref` if the element isn't created by `React.forwardRef`\n Object.assign(instance.ref, {\n current: document.querySelector(`[data-wv-id=\"${id}\"]`),\n })\n }\n }, [instance, id])\n\n if (__hidden) {\n return null\n }\n\n const Element = elementRegistry.get(type)\n\n if (Element?.Component) {\n const Component = Element.Component\n Component.displayName = type\n if (\n Component.$$typeof === Symbol.for('react.forward_ref') ||\n reactVersion > 18\n ) {\n processedRest.ref = instance.ref\n }\n const renderChildren = (\n children?.length\n ? children\n : childIds?.length\n ? childIds.map((cid: string) => ({ id: cid }))\n : []\n ).map((item: { id: string }, index: number) => (\n <ItemInstance id={item.id} key={`${item.id}-${index}`} parentId={id} />\n ))\n\n return (\n <Component\n {...processedRest}\n children={renderChildren.length ? renderChildren : undefined}\n className={clsx(\n platformType !== 'shopify-hydrogen' &&\n generateItemClassName(instance, stitchesInstance),\n processedRest.data?.className\n )}\n data-wv-id={id}\n data-wv-type={type}\n key={id}\n />\n )\n }\n instance._store.deleted = true\n return null\n})\nItemComponent.displayName = 'WeaverseComponent'\n\nconst ItemInstance = memo(\n ({ id, parentId }: { id: string; parentId: string }) => {\n const instance = useItemInstance(id)\n if (!instance) {\n return <div style={{ display: 'none' }}>Item instance {id} not found</div>\n }\n return (\n <WeaverseItemContext.Provider value={{ parentId, id }}>\n <ItemComponent instance={instance} key={id} />\n </WeaverseItemContext.Provider>\n )\n }\n)\nItemInstance.displayName = 'WeaverseInstanceProvider'\n","import type Stitches from '@stitches/react/types/stitches'\nimport type { ElementCSS, WeaverseItemStore } from '@weaverse/core'\nimport clsx from 'clsx'\n\n// Make the css data formatted to correct order (desktop, tablet, mobile)\nfunction formatCSS(css: ElementCSS) {\n return {\n '@desktop': css['@desktop'],\n '@mobile': css['@mobile'],\n }\n}\n\nlet permanentClasses: Record<string, string> = {}\nexport function generateItemClassName(\n instance: WeaverseItemStore,\n stitchesInstance: Stitches\n) {\n let { css, type, className: cls = '' } = instance.data\n let className = ''\n let permanentClass = ''\n let perCss = instance.Element?.permanentCss\n if (perCss) {\n if (type in permanentClasses) {\n permanentClass = permanentClasses[type]\n } else {\n // @ts-expect-error\n let { className: perCls } = stitchesInstance.css(perCss)()\n Object.assign(permanentClasses, { [type]: perCls })\n permanentClass = perCls\n }\n }\n className = permanentClass\n if (css) {\n // let stitches create the style from css object and\n // then return the classname, so we can use it in the render\n let formattedCss = formatCSS(css)\n let newStitchesClass = stitchesInstance.css(formattedCss)().className || ''\n let { stitchesClass = '' } = instance\n let otherClass = (instance.ref.current?.className || '')\n .replace(stitchesClass, '')\n .replace(cls, '')\n .replace(permanentClass, '')\n .trim()\n className = clsx(permanentClass, cls, newStitchesClass, otherClass)\n instance.stitchesClass = newStitchesClass\n }\n return className\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAc,2BAAd;;;ACCA,mBAA8B;AAEvB,IAAI,sBAAkB,4BAAwB,CAAC,CAAa;AAC5D,IAAI,0BAA0B,gBAAgB;AAC9C,IAAI,0BAAsB,4BAG9B,EAAE,IAAI,IAAI,UAAU,GAAG,CAAC;;;ACR3B,kBAAiD;AACjD,IAAAA,gBAA2B;;;ACI3B,IAAM,iBAAiB;AACvB,IAAM,oBAAoB;AAM1B,SAAS,mBAAmB,KAAsB;AAEhD,QAAM,oBAAoB,CAAC,aAAa,eAAe,WAAW;AAClE,SAAO,CAAC,kBAAkB,SAAS,GAAG;AACxC;AAWA,SAAS,sBACP,MACA,aAIA;AACA,MAAI,CAAC,eAAe,OAAO,SAAS,UAAU;AAC5C,WAAO,EAAE,UAAU,MAAM,cAAc,KAAK;AAAA,EAC9C;AAEA,QAAM,cAAc,KAAK,KAAK;AAG9B,QAAM,qBAAqB,OAAO,KAAK,WAAW,EAAE,KAAK,EAAE,KAAK,GAAG;AACnE,QAAM,WAAW,GAAG,WAAW,KAAK,kB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AAa,IAAI,KAAK,IAAgC,UAAU,MAAjC,GAAG,KAAK,EAAE,IAAI,KAAK,EAAkB,CACtE;AAED,WACE;AAAA,MAAC;AAAA;AAAA,QACE,GAAG;AAAA,QACJ,UAAU,eAAe,SAAS,iBAAiB;AAAA,QACnD,eAAW,aAAAC;AAAA,UACT,iBAAiB,sBACf,sBAAsB,UAAU,gBAAgB;AAAA,UAClD,cAAc,MAAM;AAAA,QACtB;AAAA,QACA,cAAY;AAAA,QACZ,gBAAc;AAAA,QACd,KAAK;AAAA;AAAA,IACP;AAAA,EAEJ;AACA,WAAS,OAAO,UAAU;AAC1B,SAAO;AACT,CAAC;AACD,cAAc,cAAc;AAE5B,IAAM,mBAAe;AAAA,EACnB,CAAC,EAAE,IAAI,SAAS,MAAwC;AACtD,UAAM,WAAW,gBAAgB,EAAE;AACnC,QAAI,CAAC,UAAU;AACb,aAAO,6CAAC,SAAI,OAAO,EAAE,SAAS,OAAO,GAAG;AAAA;AAAA,QAAe;AAAA,QAAG;AAAA,SAAU;AAAA,IACtE;AACA,WACE,4CAAC,oBAAoB,UAApB,EAA6B,OAAO,EAAE,UAAU,GAAG,GAClD,sDAAC,iBAAc,YAAyB,EAAI,GAC9C;AAAA,EAEJ;AACF;AACA,aAAa,cAAc;","names":["import_react","routeKey","result","id","import_clsx","import_react","clsx","import_react","clsx"]}
package/dist/index.mjs CHANGED
@@ -15,12 +15,69 @@ import { useContext } from "react";
15
15
  var TEMPLATE_REGEX = /\{\{([^}]+)\}\}/g;
16
16
  var ARRAY_INDEX_REGEX = /^(\w+)\[(\d+)\]$/;
17
17
  function isSafePropertyName(key) {
18
- return key !== "__proto__" && key !== "constructor" && key !== "prototype";
18
+ const dangerousPatterns = ["__proto__", "constructor", "prototype"];
19
+ return !dangerousPatterns.includes(key);
20
+ }
21
+ function parseRouteAndProperty(path, dataContext) {
22
+ if (!dataContext || typeof path !== "string") {
23
+ return { routeKey: null, propertyPath: path };
24
+ }
25
+ const trimmedPath = path.trim();
26
+ const availableRouteKeys = Object.keys(dataContext).sort().join("|");
27
+ const cacheKey = `${trimmedPath}::${availableRouteKeys}`;
28
+ const cachedResult = routeParsingCache.get(cacheKey);
29
+ if (cachedResult) {
30
+ cachedResult.timestamp = Date.now();
31
+ return {
32
+ routeKey: cachedResult.routeKey,
33
+ propertyPath: cachedResult.propertyPath
34
+ };
35
+ }
36
+ const availableRoutes = Object.keys(dataContext).sort(
37
+ (a, b) => b.length - a.length
38
+ );
39
+ let result = {
40
+ routeKey: null,
41
+ propertyPath: trimmedPath
42
+ };
43
+ let found = false;
44
+ for (const routeKey of availableRoutes) {
45
+ if (trimmedPath === routeKey) {
46
+ result = { routeKey, propertyPath: "" };
47
+ found = true;
48
+ break;
49
+ }
50
+ if (trimmedPath.startsWith(routeKey + ".")) {
51
+ const propertyPath = trimmedPath.substring(routeKey.length + 1);
52
+ result = { routeKey, propertyPath };
53
+ found = true;
54
+ break;
55
+ }
56
+ }
57
+ if (!found) {
58
+ result = { routeKey: null, propertyPath: trimmedPath };
59
+ }
60
+ if (routeParsingCache.size >= ROUTE_PARSING_CACHE_MAX_SIZE) {
61
+ const entries = Array.from(routeParsingCache.entries());
62
+ entries.sort((a, b) => a[1].timestamp - b[1].timestamp);
63
+ const toRemove = Math.floor(entries.length * 0.25);
64
+ for (let i = 0; i < toRemove; i++) {
65
+ routeParsingCache.delete(entries[i][0]);
66
+ }
67
+ }
68
+ routeParsingCache.set(cacheKey, {
69
+ routeKey: result.routeKey,
70
+ propertyPath: result.propertyPath,
71
+ timestamp: Date.now()
72
+ });
73
+ return result;
19
74
  }
20
75
  var templateCache = /* @__PURE__ */ new Map();
21
76
  var MAX_CACHE_SIZE = 100;
22
77
  var fallbackCache = /* @__PURE__ */ new Map();
23
78
  var FALLBACK_CACHE_MAX_SIZE = 50;
79
+ var routeParsingCache = /* @__PURE__ */ new Map();
80
+ var ROUTE_PARSING_CACHE_MAX_SIZE = 100;
24
81
  function getNestedValue(obj, path, visited = /* @__PURE__ */ new WeakSet()) {
25
82
  return path.split(".").reduce((current, key) => {
26
83
  if (!current || typeof current !== "object") {
@@ -71,14 +128,18 @@ function resolveDataFromContext(path, dataContext) {
71
128
  return;
72
129
  }
73
130
  const trimmedPath = path.trim();
74
- const pathParts = trimmedPath.split(".");
75
- const potentialRouteKey = pathParts[0];
76
- if (dataContext[potentialRouteKey] && typeof dataContext[potentialRouteKey] === "object" && dataContext[potentialRouteKey] !== null) {
77
- const remainingPath = pathParts.slice(1).join(".");
78
- if (remainingPath) {
79
- return getNestedValue(dataContext[potentialRouteKey], remainingPath);
131
+ const { routeKey, propertyPath } = parseRouteAndProperty(
132
+ trimmedPath,
133
+ dataContext
134
+ );
135
+ if (routeKey && dataContext[routeKey]) {
136
+ const routeData = dataContext[routeKey];
137
+ if (typeof routeData === "object" && routeData !== null) {
138
+ if (propertyPath) {
139
+ return getNestedValue(routeData, propertyPath);
140
+ }
141
+ return routeData;
80
142
  }
81
- return dataContext[potentialRouteKey];
82
143
  }
83
144
  const cachedResult = fallbackCache.get(trimmedPath);
84
145
  if (cachedResult && dataContext[cachedResult.routeKey]) {
@@ -96,8 +157,8 @@ function resolveDataFromContext(path, dataContext) {
96
157
  ...priorityRoutes,
97
158
  ...Object.keys(dataContext).filter((k) => !priorityRoutes.includes(k))
98
159
  ];
99
- for (const routeKey of allRoutes) {
100
- const routeData = dataContext[routeKey];
160
+ for (const routeKey2 of allRoutes) {
161
+ const routeData = dataContext[routeKey2];
101
162
  if (routeData && typeof routeData === "object" && routeData !== null) {
102
163
  const value = getNestedValue(routeData, trimmedPath);
103
164
  if (value !== void 0) {
@@ -110,7 +171,7 @@ function resolveDataFromContext(path, dataContext) {
110
171
  }
111
172
  }
112
173
  fallbackCache.set(trimmedPath, {
113
- routeKey,
174
+ routeKey: routeKey2,
114
175
  value,
115
176
  timestamp: Date.now()
116
177
  });
@@ -173,10 +234,14 @@ function replaceContentDataConnectorsDeep(data, dataContext, visited = /* @__PUR
173
234
  }
174
235
  visited.add(data);
175
236
  try {
237
+ if (data instanceof Date) {
238
+ return new Date(data.getTime());
239
+ }
176
240
  if (Array.isArray(data)) {
177
- return data.map(
241
+ const result2 = data.map(
178
242
  (item) => replaceContentDataConnectorsDeep(item, dataContext, visited)
179
243
  );
244
+ return result2;
180
245
  }
181
246
  const result = {};
182
247
  for (const [key, value] of Object.entries(data)) {
@@ -276,17 +341,17 @@ var useSafeExternalStore = (subscribe, getSnapshot, getServerSnapshot = getSnaps
276
341
  return getSnapshot();
277
342
  };
278
343
  var WeaverseRoot = memo(({ context }) => {
279
- let data = useSafeExternalStore(
344
+ const data = useSafeExternalStore(
280
345
  context.subscribe,
281
346
  context.getSnapShot,
282
347
  context.getSnapShot
283
348
  );
284
- let rootRef = useRef(null);
349
+ const rootRef = useRef(null);
285
350
  useEffect(() => {
286
351
  context.contentRootElement = rootRef.current;
287
352
  }, [context]);
288
- let eventHandlers = context?.studioBridge?.eventHandlers || {};
289
- let themeClass = context.stitchesInstance.theme.className;
353
+ const eventHandlers = context?.studioBridge?.eventHandlers || {};
354
+ const themeClass = context.stitchesInstance.theme.className;
290
355
  if (context.projectId) {
291
356
  return /* @__PURE__ */ jsx(
292
357
  "div",
@@ -310,14 +375,14 @@ var WeaverseRoot = memo(({ context }) => {
310
375
  });
311
376
  WeaverseRoot.displayName = "WeaverseRoot";
312
377
  var ItemComponent = memo(({ instance }) => {
313
- let context = useWeaverse();
314
- let { stitchesInstance, elementRegistry, platformType } = context;
315
- let data = useSafeExternalStore(
378
+ const context = useWeaverse();
379
+ const { stitchesInstance, elementRegistry, platformType } = context;
380
+ const data = useSafeExternalStore(
316
381
  instance.subscribe,
317
382
  instance.getSnapShot,
318
383
  instance.getSnapShot
319
384
  );
320
- let {
385
+ const {
321
386
  id,
322
387
  type,
323
388
  childIds = [],
@@ -330,13 +395,12 @@ var ItemComponent = memo(({ instance }) => {
330
395
  __hidden,
331
396
  // Need to get rid of this `data` property
332
397
  data: _,
333
- content,
334
398
  ...rest
335
399
  } = data;
336
- if (content !== void 0 && content !== null) {
337
- content = replaceContentDataConnectorsDeep(content, context.dataContext);
338
- rest.content = content;
339
- }
400
+ const processedRest = replaceContentDataConnectorsDeep(
401
+ rest,
402
+ context.dataContext
403
+ );
340
404
  useEffect(() => {
341
405
  if (!instance.ref.current) {
342
406
  Object.assign(instance.ref, {
@@ -347,22 +411,22 @@ var ItemComponent = memo(({ instance }) => {
347
411
  if (__hidden) {
348
412
  return null;
349
413
  }
350
- let Element = elementRegistry.get(type);
414
+ const Element = elementRegistry.get(type);
351
415
  if (Element?.Component) {
352
- let Component = Element.Component;
416
+ const Component = Element.Component;
353
417
  Component.displayName = type;
354
418
  if (Component.$$typeof === Symbol.for("react.forward_ref") || reactVersion > 18) {
355
- rest.ref = instance.ref;
419
+ processedRest.ref = instance.ref;
356
420
  }
357
- let renderChildren = (children?.length ? children : childIds?.length ? childIds.map((cid) => ({ id: cid })) : []).map((item, index) => /* @__PURE__ */ jsx(ItemInstance, { id: item.id, parentId: id }, `${item.id}-${index}`));
421
+ const renderChildren = (children?.length ? children : childIds?.length ? childIds.map((cid) => ({ id: cid })) : []).map((item, index) => /* @__PURE__ */ jsx(ItemInstance, { id: item.id, parentId: id }, `${item.id}-${index}`));
358
422
  return /* @__PURE__ */ createElement(
359
423
  Component,
360
424
  {
361
- ...rest,
425
+ ...processedRest,
362
426
  children: renderChildren.length ? renderChildren : void 0,
363
427
  className: clsx2(
364
428
  platformType !== "shopify-hydrogen" && generateItemClassName(instance, stitchesInstance),
365
- rest.data?.className
429
+ processedRest.data?.className
366
430
  ),
367
431
  "data-wv-id": id,
368
432
  "data-wv-type": type,
@@ -371,13 +435,12 @@ var ItemComponent = memo(({ instance }) => {
371
435
  );
372
436
  }
373
437
  instance._store.deleted = true;
374
- console.log(`\u274C Unknown element: ${type}`);
375
438
  return null;
376
439
  });
377
440
  ItemComponent.displayName = "WeaverseComponent";
378
441
  var ItemInstance = memo(
379
442
  ({ id, parentId }) => {
380
- let instance = useItemInstance(id);
443
+ const instance = useItemInstance(id);
381
444
  if (!instance) {
382
445
  return /* @__PURE__ */ jsxs("div", { style: { display: "none" }, children: [
383
446
  "Item instance ",
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/context.ts","../src/hooks.ts","../src/utils/data-connector.ts","../src/renderer.tsx","../src/utils/css.ts"],"sourcesContent":["export * from '@weaverse/core'\nexport * from './context'\nexport * from './hooks'\nexport * from './renderer'\nexport * from './types'\n","import type { Weaverse } from '@weaverse/core'\nimport { createContext } from 'react'\n\nexport let WeaverseContext = createContext<Weaverse>({} as Weaverse)\nexport let WeaverseContextProvider = WeaverseContext.Provider\nexport let WeaverseItemContext = createContext<{\n id: string\n parentId: string\n}>({ id: '', parentId: '' })\n","import { Weaverse, type WeaverseItemStore } from '@weaverse/core'\nimport { useContext } from 'react'\nimport { WeaverseContext, WeaverseItemContext } from '~/context'\n\n// Re-export the data connector utilities\nexport {\n replaceContentDataConnectors,\n replaceContentDataConnectorsDeep,\n} from './utils/data-connector'\n\nexport function useWeaverse<T = Weaverse>() {\n let weaverse = useContext(WeaverseContext)\n return weaverse as T\n}\n\nexport let useItemInstance = (id?: string) => {\n let { id: currentId } = useContext(WeaverseItemContext)\n let instance = Weaverse.itemInstances.get(id || currentId)\n if (!instance) {\n console.log(`Item instance ${id} not found`)\n return null\n }\n return instance as WeaverseItemStore\n}\n\nexport let useParentInstance = () => {\n let { parentId } = useContext(WeaverseItemContext)\n return useItemInstance(parentId || '')\n}\n\nexport let useChildInstances = (id?: string) => {\n let currentInstance = useItemInstance(id)\n if (!currentInstance) {\n return []\n }\n let { itemInstances } = Weaverse\n\n let {\n data: { children },\n } = currentInstance\n return children\n .map(({ id }: { id: string }) => itemInstances.get(id))\n .filter(Boolean) as WeaverseItemStore[]\n}\n","// Data connector utilities for replacing placeholders with real data\n// Generic data context type for flexible usage\nexport type DataContext = Record<string, unknown>\n\n// Cached regex pattern for better performance\nconst TEMPLATE_REGEX = /\\{\\{([^}]+)\\}\\}/g\nconst ARRAY_INDEX_REGEX = /^(\\w+)\\[(\\d+)\\]$/\n\n/**\n * Validates that a property name is safe to access (prevents prototype pollution)\n */\nfunction isSafePropertyName(key: string): boolean {\n return key !== '__proto__' && key !== 'constructor' && key !== 'prototype'\n}\n\n// Simple cache for parsed templates (max 100 entries)\nconst templateCache = new Map<string, string>()\nconst MAX_CACHE_SIZE = 100\n\n// Cache for fallback lookups to improve performance (moved to module level to prevent memory leaks)\nconst fallbackCache = new Map<\n string,\n { routeKey: string; value: unknown; timestamp: number }\n>()\nconst FALLBACK_CACHE_MAX_SIZE = 50\n\n/**\n * Safely gets a nested value from an object using dot notation path\n * Supports array indexing with [index] syntax\n * @param obj - The object to traverse\n * @param path - Dot notation path (e.g., \"user.name\" or \"items[0].title\")\n * @param visited - Set to track visited objects for circular reference protection\n * @returns The resolved value or undefined if not found\n */\nfunction getNestedValue(\n obj: unknown,\n path: string,\n visited = new WeakSet()\n): unknown {\n return path.split('.').reduce((current, key) => {\n if (!current || typeof current !== 'object') {\n return\n }\n\n // Protect against circular references\n if (visited.has(current as WeakKey)) {\n console.warn('Circular reference detected in data connector path:', path)\n return\n }\n\n // Add to circular reference tracking\n visited.add(current as WeakKey)\n\n // Handle array indexing like items[0] or items[1]\n const arrayMatch = key.match(ARRAY_INDEX_REGEX)\n if (arrayMatch) {\n const [, arrayKey, index] = arrayMatch\n const arrayObj = (current as Record<string, unknown>)[arrayKey]\n if (Array.isArray(arrayObj)) {\n const indexNum = Number.parseInt(index, 10)\n if (indexNum >= 0 && indexNum < arrayObj.length) {\n return arrayObj[indexNum]\n }\n }\n return\n }\n\n // Handle regular object property access with security validation\n if (!isSafePropertyName(key)) {\n console.warn(`Unsafe property access attempted: ${key}`)\n return\n }\n\n return current !== null && key in current\n ? (current as Record<string, unknown>)[key]\n : undefined\n }, obj)\n}\n\n/**\n * Sanitizes a string value to prevent XSS attacks\n * @param value - The value to sanitize\n * @returns Sanitized string safe for HTML rendering\n */\nfunction sanitizeValue(value: unknown): string {\n if (value === null || value === undefined) {\n return ''\n }\n\n const stringValue = String(value)\n\n // Basic HTML entity encoding to prevent XSS\n return stringValue\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n .replace(/'/g, '&#x27;')\n .replace(/\\//g, '&#x2F;')\n}\n\n/**\n * Creates a safe cache key from content and data\n * Handles circular references by using a simplified approach\n */\nfunction createCacheKey(\n content: string,\n data: Record<string, unknown>\n): string {\n try {\n // Try a simple JSON stringification with a limit\n const dataStr = JSON.stringify(data)\n return `${content}:${dataStr.slice(0, 100)}`\n } catch {\n // If JSON.stringify fails (circular references), use a simpler approach\n const keys = Object.keys(data).sort().join(',')\n return `${content}:keys:${keys}`\n }\n}\n\n/**\n * Resolves data from the flat route-keyed data context\n * Supports both route-specific ({{root.layout.shop.name}}) and fallback ({{shop.name}}) access\n */\nfunction resolveDataFromContext(\n path: string,\n dataContext: DataContext | null | undefined\n): unknown {\n if (!dataContext) {\n return\n }\n\n const trimmedPath = path.trim()\n\n // Check if path starts with a route key (e.g., \"root.layout.shop.name\")\n const pathParts = trimmedPath.split('.')\n const potentialRouteKey = pathParts[0]\n\n // If we have route-keyed data and the first part matches a route\n if (\n dataContext[potentialRouteKey] &&\n typeof dataContext[potentialRouteKey] === 'object' &&\n dataContext[potentialRouteKey] !== null\n ) {\n // Remove route key and resolve rest of path from that route's data\n const remainingPath = pathParts.slice(1).join('.')\n if (remainingPath) {\n return getNestedValue(dataContext[potentialRouteKey], remainingPath)\n }\n return dataContext[potentialRouteKey]\n }\n\n // Fallback: search across all route data for backward compatibility\n // This handles cases like {{shop.name}} without route prefix\n\n // Check cache first\n const cachedResult = fallbackCache.get(trimmedPath)\n if (cachedResult && dataContext[cachedResult.routeKey]) {\n const value = getNestedValue(\n dataContext[cachedResult.routeKey],\n trimmedPath\n )\n if (value !== undefined) {\n // Update timestamp on cache hit\n cachedResult.timestamp = Date.now()\n return value\n }\n }\n\n // Search with priority order (most common routes first)\n const priorityRoutes = ['root', 'routes/product', 'routes/collection']\n const allRoutes = [\n ...priorityRoutes,\n ...Object.keys(dataContext).filter((k) => !priorityRoutes.includes(k)),\n ]\n\n for (const routeKey of allRoutes) {\n const routeData = dataContext[routeKey]\n if (routeData && typeof routeData === 'object' && routeData !== null) {\n const value = getNestedValue(routeData, trimmedPath)\n if (value !== undefined) {\n // Clean cache if it's getting too large\n if (fallbackCache.size >= FALLBACK_CACHE_MAX_SIZE) {\n const entries = Array.from(fallbackCache.entries())\n entries.sort((a, b) => a[1].timestamp - b[1].timestamp)\n // Remove oldest 25% of entries\n const toRemove = Math.floor(entries.length * 0.25)\n for (let i = 0; i < toRemove; i++) {\n fallbackCache.delete(entries[i][0])\n }\n }\n fallbackCache.set(trimmedPath, {\n routeKey,\n value,\n timestamp: Date.now(),\n })\n return value\n }\n }\n }\n\n // Final fallback: try direct access (for non-route-keyed legacy data)\n return getNestedValue(dataContext, trimmedPath)\n}\n\n/**\n * Replaces data connector placeholders in content with actual values from data context\n * Supports {{path}} syntax with dot notation, array indexing, and route prefixes\n *\n * Enhanced syntax:\n * - {{root.siteSettings.title}} - Access root route data\n * - {{layout.navigation.items}} - Access layout route data\n * - {{parent.category.name}} - Access parent route data\n * - {{current.product.title}} - Access current route data\n * - {{user.name}} - Auto-resolved from combined data (backward compatible)\n *\n * @param content - The content string containing {{}} placeholders\n * @param dataContext - The enhanced WeaverseDataContext with route-keyed data\n * @returns The content with placeholders replaced by actual values\n */\nexport function replaceContentDataConnectors(\n content: string,\n dataContext: DataContext | null | undefined\n): string {\n if (!dataContext || typeof content !== 'string') {\n return content\n }\n\n try {\n // Simplified caching - dataContext is already the combined data\n const cacheKey = createCacheKey(content, dataContext)\n\n if (templateCache.has(cacheKey)) {\n return templateCache.get(cacheKey)!\n }\n\n const newContent = content.replace(TEMPLATE_REGEX, (match, path) => {\n try {\n const value = resolveDataFromContext(path, dataContext)\n\n if (value === undefined || value === null) {\n return match // Return original placeholder if value not found\n }\n\n return sanitizeValue(value)\n } catch (pathError) {\n console.warn(\n `Error resolving data connector path \"${path}\":`,\n pathError\n )\n return match\n }\n })\n\n // Cache the result (with size limit)\n if (templateCache.size >= MAX_CACHE_SIZE) {\n const firstKey = templateCache.keys().next().value\n templateCache.delete(firstKey)\n }\n templateCache.set(cacheKey, newContent)\n\n return newContent\n } catch (error) {\n console.warn('Error processing data connectors:', error, { content })\n return content\n }\n}\n\n/**\n * Recursively replaces data connector placeholders in any data structure\n * Handles strings, objects, arrays, and nested combinations\n *\n * @param data - The data to process (string, object, array, or primitive)\n * @param dataContext - The data context for replacements\n * @param visited - Set to track visited objects for circular reference protection\n * @returns The data with all string placeholders replaced\n */\nexport function replaceContentDataConnectorsDeep<T>(\n data: T,\n dataContext: DataContext | null | undefined,\n visited = new WeakSet()\n): T {\n if (!dataContext) {\n return data\n }\n\n // Handle primitive types\n if (typeof data === 'string') {\n return replaceContentDataConnectors(data, dataContext) as T\n }\n\n if (typeof data !== 'object' || data === null) {\n return data\n }\n\n // Protect against circular references\n if (visited.has(data as WeakKey)) {\n console.warn(\n 'Circular reference detected in deep data connector replacement'\n )\n return data\n }\n\n // Add to circular reference tracking\n visited.add(data as WeakKey)\n\n try {\n // Handle arrays\n if (Array.isArray(data)) {\n return data.map((item) =>\n replaceContentDataConnectorsDeep(item, dataContext, visited)\n ) as T\n }\n\n // Handle objects\n const result = {} as T\n for (const [key, value] of Object.entries(data)) {\n ;(result as Record<string, unknown>)[key] =\n replaceContentDataConnectorsDeep(value, dataContext, visited)\n }\n\n return result\n } catch (error) {\n console.warn('Error in deep data connector replacement:', error)\n return data\n } finally {\n // Remove from tracking when done processing this object\n visited.delete(data as WeakKey)\n }\n}\n","import clsx from 'clsx'\nimport * as React from 'react'\nimport { memo, useEffect, useRef } from 'react'\nimport { useItemInstance, useWeaverse } from '~/hooks'\nimport { WeaverseContextProvider, WeaverseItemContext } from './context'\nimport type { ItemComponentProps, WeaverseRootPropsType } from './types'\nimport { generateItemClassName } from './utils/css'\nimport { replaceContentDataConnectorsDeep } from './utils/data-connector'\n\nlet reactVersion = Number(React.version?.split('.')[0]) || 0\n\n// Create a safe version of useSyncExternalStore that works in both client and server environments\nexport const useSafeExternalStore = (\n subscribe: any,\n getSnapshot: any,\n getServerSnapshot: any = getSnapshot\n) => {\n // In server environment or during SSR, just return the snapshot directly\n if (typeof window === 'undefined') {\n return getServerSnapshot()\n }\n\n // In client environment, use React.useSyncExternalStore if available (React 18+)\n if (React.useSyncExternalStore) {\n // biome-ignore lint/correctness/useHookAtTopLevel: <$>\n return React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)\n }\n\n // Fallback for older React versions - just return the current snapshot\n return getSnapshot()\n}\n\nexport let WeaverseRoot = memo(({ context }: WeaverseRootPropsType) => {\n let data = useSafeExternalStore(\n context.subscribe,\n context.getSnapShot,\n context.getSnapShot\n )\n let rootRef = useRef<HTMLElement>(null)\n\n useEffect(() => {\n context.contentRootElement = rootRef.current\n }, [context])\n\n let eventHandlers = context?.studioBridge?.eventHandlers || {}\n let themeClass = context.stitchesInstance.theme.className\n\n if (context.projectId) {\n return (\n <div\n className={`weaverse-content-root ${themeClass}`}\n {...eventHandlers}\n data-weaverse-project-id={context.projectId}\n data-weaverse-template-id={data.id}\n ref={rootRef}\n >\n <WeaverseContextProvider value={context}>\n <ItemInstance\n id={context.data.rootId || context.projectId}\n parentId={''}\n />\n </WeaverseContextProvider>\n </div>\n )\n }\n return null\n})\nWeaverseRoot.displayName = 'WeaverseRoot'\nconst ItemComponent = memo(({ instance }: ItemComponentProps) => {\n let context = useWeaverse()\n let { stitchesInstance, elementRegistry, platformType } = context\n let data = useSafeExternalStore(\n instance.subscribe,\n instance.getSnapShot,\n instance.getSnapShot\n )\n let {\n id,\n type,\n childIds = [],\n children = [],\n parentId,\n createdAt,\n updatedAt,\n deletedAt,\n css,\n __hidden,\n // Need to get rid of this `data` property\n data: _,\n content,\n ...rest\n } = data\n // Replace data connectors in content (handles strings, objects, and arrays recursively)\n if (content !== undefined && content !== null) {\n content = replaceContentDataConnectorsDeep(content, context.dataContext)\n rest.content = content\n }\n\n useEffect(() => {\n if (!instance.ref.current) {\n // Fallback `ref` if the element isn't created by `React.forwardRef`\n Object.assign(instance.ref, {\n current: document.querySelector(`[data-wv-id=\"${id}\"]`),\n })\n }\n }, [instance, id])\n\n if (__hidden) {\n return null\n }\n\n let Element = elementRegistry.get(type)\n\n if (Element?.Component) {\n let Component = Element.Component\n Component.displayName = type\n if (\n Component.$$typeof === Symbol.for('react.forward_ref') ||\n reactVersion > 18\n ) {\n rest.ref = instance.ref\n }\n let renderChildren = (\n children?.length\n ? children\n : childIds?.length\n ? childIds.map((cid: string) => ({ id: cid }))\n : []\n ).map((item: { id: string }, index: number) => (\n <ItemInstance id={item.id} key={`${item.id}-${index}`} parentId={id} />\n ))\n\n return (\n <Component\n {...rest}\n children={renderChildren.length ? renderChildren : undefined}\n className={clsx(\n platformType !== 'shopify-hydrogen' &&\n generateItemClassName(instance, stitchesInstance),\n rest.data?.className\n )}\n data-wv-id={id}\n data-wv-type={type}\n key={id}\n />\n )\n }\n instance._store.deleted = true\n console.log(`❌ Unknown element: ${type}`)\n return null\n})\nItemComponent.displayName = 'WeaverseComponent'\n\nlet ItemInstance = memo(\n ({ id, parentId }: { id: string; parentId: string }) => {\n let instance = useItemInstance(id)\n if (!instance) {\n return <div style={{ display: 'none' }}>Item instance {id} not found</div>\n }\n return (\n <WeaverseItemContext.Provider value={{ parentId, id }}>\n <ItemComponent instance={instance} key={id} />\n </WeaverseItemContext.Provider>\n )\n }\n)\nItemInstance.displayName = 'WeaverseInstanceProvider'\n","import type Stitches from '@stitches/react/types/stitches'\nimport type { ElementCSS, WeaverseItemStore } from '@weaverse/core'\nimport clsx from 'clsx'\n\n// Make the css data formatted to correct order (desktop, tablet, mobile)\nfunction formatCSS(css: ElementCSS) {\n return {\n '@desktop': css['@desktop'],\n '@mobile': css['@mobile'],\n }\n}\n\nlet permanentClasses: Record<string, string> = {}\nexport function generateItemClassName(\n instance: WeaverseItemStore,\n stitchesInstance: Stitches\n) {\n let { css, type, className: cls = '' } = instance.data\n let className = ''\n let permanentClass = ''\n let perCss = instance.Element?.permanentCss\n if (perCss) {\n if (type in permanentClasses) {\n permanentClass = permanentClasses[type]\n } else {\n // @ts-expect-error\n let { className: perCls } = stitchesInstance.css(perCss)()\n Object.assign(permanentClasses, { [type]: perCls })\n permanentClass = perCls\n }\n }\n className = permanentClass\n if (css) {\n // let stitches create the style from css object and\n // then return the classname, so we can use it in the render\n let formattedCss = formatCSS(css)\n let newStitchesClass = stitchesInstance.css(formattedCss)().className || ''\n let { stitchesClass = '' } = instance\n let otherClass = (instance.ref.current?.className || '')\n .replace(stitchesClass, '')\n .replace(cls, '')\n .replace(permanentClass, '')\n .trim()\n className = clsx(permanentClass, cls, newStitchesClass, otherClass)\n instance.stitchesClass = newStitchesClass\n }\n return className\n}\n"],"mappings":";AAAA,cAAc;;;ACCd,SAAS,qBAAqB;AAEvB,IAAI,kBAAkB,cAAwB,CAAC,CAAa;AAC5D,IAAI,0BAA0B,gBAAgB;AAC9C,IAAI,sBAAsB,cAG9B,EAAE,IAAI,IAAI,UAAU,GAAG,CAAC;;;ACR3B,SAAS,gBAAwC;AACjD,SAAS,kBAAkB;;;ACI3B,IAAM,iBAAiB;AACvB,IAAM,oBAAoB;AAK1B,SAAS,mBAAmB,KAAsB;AAChD,SAAO,QAAQ,eAAe,QAAQ,iBAAiB,QAAQ;AACjE;AAGA,IAAM,gBAAgB,oBAAI,IAAoB;AAC9C,IAAM,iBAAiB;AAGvB,IAAM,gBAAgB,oBAAI,IAGxB;AACF,IAAM,0BAA0B;AAUhC,SAAS,eACP,KACA,MACA,UAAU,oBAAI,QAAQ,GACb;AACT,SAAO,KAAK,MAAM,GAAG,EAAE,OAAO,CAAC,SAAS,QAAQ;AAC9C,QAAI,CAAC,WAAW,OAAO,YAAY,UAAU;AAC3C;AAAA,IACF;AAGA,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AAAA,EAEJ;AACA,WAAS,OAAO,UAAU;AAC1B,UAAQ,IAAI,2BAAsB,IAAI,EAAE;AACxC,SAAO;AACT,CAAC;AACD,cAAc,cAAc;AAE5B,IAAI,eAAe;AAAA,EACjB,CAAC,EAAE,IAAI,SAAS,MAAwC;AACtD,QAAI,WAAW,gBAAgB,EAAE;AACjC,QAAI,CAAC,UAAU;AACb,aAAO,qBAAC,SAAI,OAAO,EAAE,SAAS,OAAO,GAAG;AAAA;AAAA,QAAe;AAAA,QAAG;AAAA,SAAU;AAAA,IACtE;AACA,WACE,oBAAC,oBAAoB,UAApB,EAA6B,OAAO,EAAE,UAAU,GAAG,GAClD,8BAAC,iBAAc,YAAyB,EAAI,GAC9C;AAAA,EAEJ;AACF;AACA,aAAa,cAAc;","names":["id","clsx","clsx"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/context.ts","../src/hooks.ts","../src/utils/data-connector.ts","../src/renderer.tsx","../src/utils/css.ts"],"sourcesContent":["export * from '@weaverse/core'\nexport * from './context'\nexport * from './hooks'\nexport * from './renderer'\nexport * from './types'\n","import type { Weaverse } from '@weaverse/core'\nimport { createContext } from 'react'\n\nexport let WeaverseContext = createContext<Weaverse>({} as Weaverse)\nexport let WeaverseContextProvider = WeaverseContext.Provider\nexport let WeaverseItemContext = createContext<{\n id: string\n parentId: string\n}>({ id: '', parentId: '' })\n","import { Weaverse, type WeaverseItemStore } from '@weaverse/core'\nimport { useContext } from 'react'\nimport { WeaverseContext, WeaverseItemContext } from '~/context'\n\n// Re-export the data connector utilities\nexport {\n replaceContentDataConnectors,\n replaceContentDataConnectorsDeep,\n} from './utils/data-connector'\n\nexport function useWeaverse<T = Weaverse>() {\n let weaverse = useContext(WeaverseContext)\n return weaverse as T\n}\n\nexport let useItemInstance = (id?: string) => {\n let { id: currentId } = useContext(WeaverseItemContext)\n let instance = Weaverse.itemInstances.get(id || currentId)\n if (!instance) {\n console.log(`Item instance ${id} not found`)\n return null\n }\n return instance as WeaverseItemStore\n}\n\nexport let useParentInstance = () => {\n let { parentId } = useContext(WeaverseItemContext)\n return useItemInstance(parentId || '')\n}\n\nexport let useChildInstances = (id?: string) => {\n let currentInstance = useItemInstance(id)\n if (!currentInstance) {\n return []\n }\n let { itemInstances } = Weaverse\n\n let {\n data: { children },\n } = currentInstance\n return children\n .map(({ id }: { id: string }) => itemInstances.get(id))\n .filter(Boolean) as WeaverseItemStore[]\n}\n","// Data connector utilities for replacing placeholders with real data\n// Generic data context type for flexible usage\nexport type DataContext = Record<string, unknown>\n\n// Cached regex pattern for better performance\nconst TEMPLATE_REGEX = /\\{\\{([^}]+)\\}\\}/g\nconst ARRAY_INDEX_REGEX = /^(\\w+)\\[(\\d+)\\]$/\n\n/**\n * Validates that a property name is safe to access (prevents prototype pollution)\n * Enhanced to handle route-specific patterns with special characters\n */\nfunction isSafePropertyName(key: string): boolean {\n // Block dangerous prototype pollution patterns\n const dangerousPatterns = ['__proto__', 'constructor', 'prototype']\n return !dangerousPatterns.includes(key)\n}\n\n/**\n * Parses a template path into route key and property path components\n * Handles complex routes like: routes/($locale).blogs.$blogHandle.$articleHandle\n * Enhanced with caching for improved performance\n *\n * @param path - The full path from template (e.g., \"routes/($locale)._index.weaverseData.page.name\")\n * @param dataContext - Available route data context\n * @returns Object with routeKey and propertyPath\n */\nfunction parseRouteAndProperty(\n path: string,\n dataContext: DataContext\n): {\n routeKey: string | null\n propertyPath: string\n} {\n if (!dataContext || typeof path !== 'string') {\n return { routeKey: null, propertyPath: path }\n }\n\n const trimmedPath = path.trim()\n\n // Create a cache key that includes available routes for context awareness\n const availableRouteKeys = Object.keys(dataContext).sort().join('|')\n const cacheKey = `${trimmedPath}::${availableRouteKeys}`\n\n // Check cache first\n const cachedResult = routeParsingCache.get(cacheKey)\n if (cachedResult) {\n // Update timestamp on cache hit\n cachedResult.timestamp = Date.now()\n return {\n routeKey: cachedResult.routeKey,\n propertyPath: cachedResult.propertyPath,\n }\n }\n\n // Get all available routes and sort by length (longest first for specificity)\n const availableRoutes = Object.keys(dataContext).sort(\n (a, b) => b.length - a.length\n )\n\n let result: { routeKey: string | null; propertyPath: string } = {\n routeKey: null,\n propertyPath: trimmedPath,\n }\n\n // Try to find the longest matching route key\n let found = false\n for (const routeKey of availableRoutes) {\n // Exact match\n if (trimmedPath === routeKey) {\n result = { routeKey, propertyPath: '' }\n found = true\n break\n }\n\n // Route key with property path\n if (trimmedPath.startsWith(routeKey + '.')) {\n const propertyPath = trimmedPath.substring(routeKey.length + 1)\n result = { routeKey, propertyPath }\n found = true\n break\n }\n }\n\n if (!found) {\n // No route key found, treat entire path as property path\n result = { routeKey: null, propertyPath: trimmedPath }\n }\n\n // Cache the result\n if (routeParsingCache.size >= ROUTE_PARSING_CACHE_MAX_SIZE) {\n // Clean cache by removing oldest entries\n const entries = Array.from(routeParsingCache.entries())\n entries.sort((a, b) => a[1].timestamp - b[1].timestamp)\n const toRemove = Math.floor(entries.length * 0.25)\n for (let i = 0; i < toRemove; i++) {\n routeParsingCache.delete(entries[i][0])\n }\n }\n\n routeParsingCache.set(cacheKey, {\n routeKey: result.routeKey,\n propertyPath: result.propertyPath,\n timestamp: Date.now(),\n })\n\n return result\n}\n\n// Simple cache for parsed templates (max 100 entries)\nconst templateCache = new Map<string, string>()\nconst MAX_CACHE_SIZE = 100\n\n// Cache for fallback lookups to improve performance (moved to module level to prevent memory leaks)\nconst fallbackCache = new Map<\n string,\n { routeKey: string; value: unknown; timestamp: number }\n>()\nconst FALLBACK_CACHE_MAX_SIZE = 50\n\n// Route parsing cache for performance optimization\nconst routeParsingCache = new Map<\n string,\n { routeKey: string | null; propertyPath: string; timestamp: number }\n>()\nconst ROUTE_PARSING_CACHE_MAX_SIZE = 100\n\n/**\n * Safely gets a nested value from an object using dot notation path\n * Supports array indexing with [index] syntax\n * @param obj - The object to traverse\n * @param path - Dot notation path (e.g., \"user.name\" or \"items[0].title\")\n * @param visited - Set to track visited objects for circular reference protection\n * @returns The resolved value or undefined if not found\n */\nfunction getNestedValue(\n obj: unknown,\n path: string,\n visited = new WeakSet()\n): unknown {\n return path.split('.').reduce((current, key) => {\n if (!current || typeof current !== 'object') {\n return\n }\n\n // Protect against circular references\n if (visited.has(current as WeakKey)) {\n console.warn('Circular reference detected in data connector path:', path)\n return\n }\n\n // Add to circular reference tracking\n visited.add(current as WeakKey)\n\n // Handle array indexing like items[0] or items[1]\n const arrayMatch = key.match(ARRAY_INDEX_REGEX)\n if (arrayMatch) {\n const [, arrayKey, index] = arrayMatch\n const arrayObj = (current as Record<string, unknown>)[arrayKey]\n if (Array.isArray(arrayObj)) {\n const indexNum = Number.parseInt(index, 10)\n if (indexNum >= 0 && indexNum < arrayObj.length) {\n return arrayObj[indexNum]\n }\n }\n return\n }\n\n // Handle regular object property access with security validation\n if (!isSafePropertyName(key)) {\n console.warn(`Unsafe property access attempted: ${key}`)\n return\n }\n\n return current !== null && key in current\n ? (current as Record<string, unknown>)[key]\n : undefined\n }, obj)\n}\n\n/**\n * Sanitizes a string value to prevent XSS attacks\n * @param value - The value to sanitize\n * @returns Sanitized string safe for HTML rendering\n */\nfunction sanitizeValue(value: unknown): string {\n if (value === null || value === undefined) {\n return ''\n }\n\n const stringValue = String(value)\n\n // Basic HTML entity encoding to prevent XSS\n return stringValue\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n .replace(/'/g, '&#x27;')\n .replace(/\\//g, '&#x2F;')\n}\n\n/**\n * Creates a safe cache key from content and data\n * Handles circular references by using a simplified approach\n */\nfunction createCacheKey(\n content: string,\n data: Record<string, unknown>\n): string {\n try {\n // Try a simple JSON stringification with a limit\n const dataStr = JSON.stringify(data)\n return `${content}:${dataStr.slice(0, 100)}`\n } catch {\n // If JSON.stringify fails (circular references), use a simpler approach\n const keys = Object.keys(data).sort().join(',')\n return `${content}:keys:${keys}`\n }\n}\n\n/**\n * Resolves data from the flat route-keyed data context\n * Enhanced to support complex route patterns with special characters\n * Supports: {{root.layout.shop.name}}, {{routes/($locale)._index.data}}, {{routes/($locale).blogs.$handle.$article.content}}\n */\nfunction resolveDataFromContext(\n path: string,\n dataContext: DataContext | null | undefined\n): unknown {\n if (!dataContext) {\n return\n }\n\n const trimmedPath = path.trim()\n\n // Use intelligent route parsing to separate route key from property path\n const { routeKey, propertyPath } = parseRouteAndProperty(\n trimmedPath,\n dataContext\n )\n\n // If we found a specific route key, resolve from that route's data\n if (routeKey && dataContext[routeKey]) {\n const routeData = dataContext[routeKey]\n if (typeof routeData === 'object' && routeData !== null) {\n if (propertyPath) {\n return getNestedValue(routeData, propertyPath)\n }\n return routeData\n }\n }\n\n // Fallback: search across all route data for backward compatibility\n // This handles cases like {{shop.name}} without route prefix\n\n // Check cache first\n const cachedResult = fallbackCache.get(trimmedPath)\n if (cachedResult && dataContext[cachedResult.routeKey]) {\n const value = getNestedValue(\n dataContext[cachedResult.routeKey],\n trimmedPath\n )\n if (value !== undefined) {\n // Update timestamp on cache hit\n cachedResult.timestamp = Date.now()\n return value\n }\n }\n\n // Search with priority order (most common routes first)\n const priorityRoutes = ['root', 'routes/product', 'routes/collection']\n const allRoutes = [\n ...priorityRoutes,\n ...Object.keys(dataContext).filter((k) => !priorityRoutes.includes(k)),\n ]\n\n for (const routeKey of allRoutes) {\n const routeData = dataContext[routeKey]\n if (routeData && typeof routeData === 'object' && routeData !== null) {\n const value = getNestedValue(routeData, trimmedPath)\n if (value !== undefined) {\n // Clean cache if it's getting too large\n if (fallbackCache.size >= FALLBACK_CACHE_MAX_SIZE) {\n const entries = Array.from(fallbackCache.entries())\n entries.sort((a, b) => a[1].timestamp - b[1].timestamp)\n // Remove oldest 25% of entries\n const toRemove = Math.floor(entries.length * 0.25)\n for (let i = 0; i < toRemove; i++) {\n fallbackCache.delete(entries[i][0])\n }\n }\n fallbackCache.set(trimmedPath, {\n routeKey,\n value,\n timestamp: Date.now(),\n })\n return value\n }\n }\n }\n\n // Final fallback: try direct access (for non-route-keyed legacy data)\n return getNestedValue(dataContext, trimmedPath)\n}\n\n/**\n * Replaces data connector placeholders in content with actual values from data context\n * Supports {{path}} syntax with dot notation, array indexing, and route prefixes\n *\n * Enhanced syntax:\n * - {{root.siteSettings.title}} - Access root route data\n * - {{layout.navigation.items}} - Access layout route data\n * - {{parent.category.name}} - Access parent route data\n * - {{current.product.title}} - Access current route data\n * - {{user.name}} - Auto-resolved from combined data (backward compatible)\n *\n * @param content - The content string containing {{}} placeholders\n * @param dataContext - The enhanced WeaverseDataContext with route-keyed data\n * @returns The content with placeholders replaced by actual values\n */\nexport function replaceContentDataConnectors(\n content: string,\n dataContext: DataContext | null | undefined\n): string {\n if (!dataContext || typeof content !== 'string') {\n return content\n }\n\n try {\n // Simplified caching - dataContext is already the combined data\n const cacheKey = createCacheKey(content, dataContext)\n\n if (templateCache.has(cacheKey)) {\n return templateCache.get(cacheKey)!\n }\n\n const newContent = content.replace(TEMPLATE_REGEX, (match, path) => {\n try {\n const value = resolveDataFromContext(path, dataContext)\n\n if (value === undefined || value === null) {\n return match // Return original placeholder if value not found\n }\n\n return sanitizeValue(value)\n } catch (pathError) {\n console.warn(\n `Error resolving data connector path \"${path}\":`,\n pathError\n )\n return match\n }\n })\n\n // Cache the result (with size limit)\n if (templateCache.size >= MAX_CACHE_SIZE) {\n const firstKey = templateCache.keys().next().value\n templateCache.delete(firstKey)\n }\n templateCache.set(cacheKey, newContent)\n\n return newContent\n } catch (error) {\n console.warn('Error processing data connectors:', error, { content })\n return content\n }\n}\n\n/**\n * Recursively replaces data connector placeholders in any data structure\n * IMMUTABLE: Creates deep copies during processing to avoid mutating original data\n * Handles strings, objects, arrays, and nested combinations\n *\n * @param data - The data to process (string, object, array, or primitive)\n * @param dataContext - The data context for replacements\n * @param visited - Set to track visited objects for circular reference protection\n * @returns IMMUTABLE copy of the data with all string placeholders replaced\n */\nexport function replaceContentDataConnectorsDeep<T>(\n data: T,\n dataContext: DataContext | null | undefined,\n visited = new WeakSet()\n): T {\n if (!dataContext) {\n return data\n }\n\n // Handle primitive types - no cloning needed for primitives\n if (typeof data === 'string') {\n return replaceContentDataConnectors(data, dataContext) as T\n }\n\n if (typeof data !== 'object' || data === null) {\n return data\n }\n\n // Protect against circular references\n if (visited.has(data as WeakKey)) {\n console.warn(\n 'Circular reference detected in deep data connector replacement'\n )\n return data\n }\n\n // Add to circular reference tracking\n visited.add(data as WeakKey)\n\n try {\n // Handle special objects that should be cloned as-is\n if (data instanceof Date) {\n return new Date(data.getTime()) as T\n }\n\n // Handle arrays - create new array with processed items\n if (Array.isArray(data)) {\n const result = data.map((item) =>\n replaceContentDataConnectorsDeep(item, dataContext, visited)\n ) as T\n return result\n }\n\n // Handle plain objects - create new object with processed values\n const result = {} as T\n for (const [key, value] of Object.entries(data)) {\n ;(result as Record<string, unknown>)[key] =\n replaceContentDataConnectorsDeep(value, dataContext, visited)\n }\n\n return result\n } catch (error) {\n console.warn('Error in deep data connector replacement:', error)\n return data\n } finally {\n // Remove from tracking when done processing this object\n visited.delete(data as WeakKey)\n }\n}\n","import clsx from 'clsx'\nimport * as React from 'react'\nimport { memo, useEffect, useRef } from 'react'\nimport { useItemInstance, useWeaverse } from '~/hooks'\nimport { WeaverseContextProvider, WeaverseItemContext } from './context'\nimport type { ItemComponentProps, WeaverseRootPropsType } from './types'\nimport { generateItemClassName } from './utils/css'\nimport { replaceContentDataConnectorsDeep } from './utils/data-connector'\n\nconst reactVersion = Number(React.version?.split('.')[0]) || 0\n\n// Create a safe version of useSyncExternalStore that works in both client and server environments\nexport const useSafeExternalStore = (\n subscribe: any,\n getSnapshot: any,\n getServerSnapshot: any = getSnapshot\n) => {\n // In server environment or during SSR, just return the snapshot directly\n if (typeof window === 'undefined') {\n return getServerSnapshot()\n }\n\n // In client environment, use React.useSyncExternalStore if available (React 18+)\n if (React.useSyncExternalStore) {\n // biome-ignore lint/correctness/useHookAtTopLevel: <$>\n return React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)\n }\n\n // Fallback for older React versions - just return the current snapshot\n return getSnapshot()\n}\n\nexport const WeaverseRoot = memo(({ context }: WeaverseRootPropsType) => {\n const data = useSafeExternalStore(\n context.subscribe,\n context.getSnapShot,\n context.getSnapShot\n )\n const rootRef = useRef<HTMLElement>(null)\n\n useEffect(() => {\n context.contentRootElement = rootRef.current\n }, [context])\n\n const eventHandlers = context?.studioBridge?.eventHandlers || {}\n const themeClass = context.stitchesInstance.theme.className\n\n if (context.projectId) {\n return (\n <div\n className={`weaverse-content-root ${themeClass}`}\n {...eventHandlers}\n data-weaverse-project-id={context.projectId}\n data-weaverse-template-id={data.id}\n ref={rootRef}\n >\n <WeaverseContextProvider value={context}>\n <ItemInstance\n id={context.data.rootId || context.projectId}\n parentId={''}\n />\n </WeaverseContextProvider>\n </div>\n )\n }\n return null\n})\nWeaverseRoot.displayName = 'WeaverseRoot'\nconst ItemComponent = memo(({ instance }: ItemComponentProps) => {\n const context = useWeaverse()\n const { stitchesInstance, elementRegistry, platformType } = context\n const data = useSafeExternalStore(\n instance.subscribe,\n instance.getSnapShot,\n instance.getSnapShot\n )\n const {\n id,\n type,\n childIds = [],\n children = [],\n parentId,\n createdAt,\n updatedAt,\n deletedAt,\n css,\n __hidden,\n // Need to get rid of this `data` property\n data: _,\n ...rest\n } = data\n\n // Replace data connectors in all component data (handles strings, objects, and arrays recursively)\n // IMMUTABLE: Process the entire rest object to avoid mutating original content\n const processedRest = replaceContentDataConnectorsDeep(\n rest,\n context.dataContext\n )\n\n useEffect(() => {\n if (!instance.ref.current) {\n // Fallback `ref` if the element isn't created by `React.forwardRef`\n Object.assign(instance.ref, {\n current: document.querySelector(`[data-wv-id=\"${id}\"]`),\n })\n }\n }, [instance, id])\n\n if (__hidden) {\n return null\n }\n\n const Element = elementRegistry.get(type)\n\n if (Element?.Component) {\n const Component = Element.Component\n Component.displayName = type\n if (\n Component.$$typeof === Symbol.for('react.forward_ref') ||\n reactVersion > 18\n ) {\n processedRest.ref = instance.ref\n }\n const renderChildren = (\n children?.length\n ? children\n : childIds?.length\n ? childIds.map((cid: string) => ({ id: cid }))\n : []\n ).map((item: { id: string }, index: number) => (\n <ItemInstance id={item.id} key={`${item.id}-${index}`} parentId={id} />\n ))\n\n return (\n <Component\n {...processedRest}\n children={renderChildren.length ? renderChildren : undefined}\n className={clsx(\n platformType !== 'shopify-hydrogen' &&\n generateItemClassName(instance, stitchesInstance),\n processedRest.data?.className\n )}\n data-wv-id={id}\n data-wv-type={type}\n key={id}\n />\n )\n }\n instance._store.deleted = true\n return null\n})\nItemComponent.displayName = 'WeaverseComponent'\n\nconst ItemInstance = memo(\n ({ id, parentId }: { id: string; parentId: string }) => {\n const instance = useItemInstance(id)\n if (!instance) {\n return <div style={{ display: 'none' }}>Item instance {id} not found</div>\n }\n return (\n <WeaverseItemContext.Provider value={{ parentId, id }}>\n <ItemComponent instance={instance} key={id} />\n </WeaverseItemContext.Provider>\n )\n }\n)\nItemInstance.displayName = 'WeaverseInstanceProvider'\n","import type Stitches from '@stitches/react/types/stitches'\nimport type { ElementCSS, WeaverseItemStore } from '@weaverse/core'\nimport clsx from 'clsx'\n\n// Make the css data formatted to correct order (desktop, tablet, mobile)\nfunction formatCSS(css: ElementCSS) {\n return {\n '@desktop': css['@desktop'],\n '@mobile': css['@mobile'],\n }\n}\n\nlet permanentClasses: Record<string, string> = {}\nexport function generateItemClassName(\n instance: WeaverseItemStore,\n stitchesInstance: Stitches\n) {\n let { css, type, className: cls = '' } = instance.data\n let className = ''\n let permanentClass = ''\n let perCss = instance.Element?.permanentCss\n if (perCss) {\n if (type in permanentClasses) {\n permanentClass = permanentClasses[type]\n } else {\n // @ts-expect-error\n let { className: perCls } = stitchesInstance.css(perCss)()\n Object.assign(permanentClasses, { [type]: perCls })\n permanentClass = perCls\n }\n }\n className = permanentClass\n if (css) {\n // let stitches create the style from css object and\n // then return the classname, so we can use it in the render\n let formattedCss = formatCSS(css)\n let newStitchesClass = stitchesInstance.css(formattedCss)().className || ''\n let { stitchesClass = '' } = instance\n let otherClass = (instance.ref.current?.className || '')\n .replace(stitchesClass, '')\n .replace(cls, '')\n .replace(permanentClass, '')\n .trim()\n className = clsx(permanentClass, cls, newStitchesClass, otherClass)\n instance.stitchesClass = newStitchesClass\n }\n return className\n}\n"],"mappings":";AAAA,cAAc;;;ACCd,SAAS,qBAAqB;AAEvB,IAAI,kBAAkB,cAAwB,CAAC,CAAa;AAC5D,IAAI,0BAA0B,gBAAgB;AAC9C,IAAI,sBAAsB,cAG9B,EAAE,IAAI,IAAI,UAAU,GAAG,CAAC;;;ACR3B,SAAS,gBAAwC;AACjD,SAAS,kBAAkB;;;ACI3B,IAAM,iBAAiB;AACvB,IAAM,oBAAoB;AAM1B,SAAS,mBAAmB,KAAsB;AAEhD,QAAM,oBAAoB,CAAC,aAAa,eAAe,WAAW;AAClE,SAAO,CAAC,kBAAkB,SAAS,GAAG;AACxC;AAWA,SAAS,sBACP,MACA,aAIA;AACA,MAAI,CAAC,eAAe,OAAO,SAAS,UAAU;AAC5C,WAAO,EAAE,UAAU,MAAM,cAAc,KAAK;AAAA,EAC9C;AAEA,QAAM,cAAc,KAAK,KAAK;AAG9B,QAAM,qBAAqB,OAAO,KAAK,WAAW,EAAE,KAAK,EAAE,KAAK,GAAG;AACnE,QAAM,WAAW,GAAG,WAAW,KAAK,kBAAkB;AAGtD,QAAM,eAAe,kBAAkB,IAAI,QAAQ;AACnD,MAAI,cAAc;AAEhB,iBAAa,YAAY,KAAK,IAAI;AAClC,WAAO;AAAA,MACL,UAAU,aAAa;AAAA,MACvB,cAAc,aAAa;AAAA,IAC7B;AAAA,EACF;AAGA,QAAM,kBAAkB,OAAO,KAAK,WAAW,EAAE;AAAA,IAC/C,CAAC,GAAG,MAAM,EAAE,SAAS,EAAE;AAAA,EACzB;AAEA,MAAI,SAA4D;AAAA,IAC9D,UAAU;AAAA,IACV,cAAc;AAAA,EAChB;AAGA,MAAI,QAAQ;AACZ,aAAW,YAAY,iBAAiB;AAEtC,QAAI,gBAAgB,UAAU;AAC5B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,EACnB,CAAC,EAAE,IAAI,SAAS,MAAwC;AACtD,UAAM,WAAW,gBAAgB,EAAE;AACnC,QAAI,CAAC,UAAU;AACb,aAAO,qBAAC,SAAI,OAAO,EAAE,SAAS,OAAO,GAAG;AAAA;AAAA,QAAe;AAAA,QAAG;AAAA,SAAU;AAAA,IACtE;AACA,WACE,oBAAC,oBAAoB,UAApB,EAA6B,OAAO,EAAE,UAAU,GAAG,GAClD,8BAAC,iBAAc,YAAyB,EAAI,GAC9C;AAAA,EAEJ;AACF;AACA,aAAa,cAAc;","names":["routeKey","result","id","clsx","clsx"]}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@weaverse/react",
3
3
  "author": "Weaverse Team",
4
4
  "description": "React bindings for Weaverse",
5
- "version": "5.5.0-beta.4",
5
+ "version": "5.5.0-beta.7",
6
6
  "license": "MIT",
7
7
  "main": "dist/index.js",
8
8
  "typings": "dist/index.d.ts",
@@ -42,7 +42,7 @@
42
42
  "outDir": "dist"
43
43
  },
44
44
  "dependencies": {
45
- "@weaverse/core": "5.5.0-beta.4",
45
+ "@weaverse/core": "5.5.0-beta.7",
46
46
  "clsx": "^2.1.1",
47
47
  "react": ">=18",
48
48
  "react-dom": ">=18"