@weaverse/react 5.5.0-beta.5 → 5.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +86 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +83 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Weaverse, WeaverseItemStore, ElementCSS } from '@weaverse/core';
|
|
2
2
|
export * from '@weaverse/core';
|
|
3
3
|
import * as react from 'react';
|
|
4
|
-
import { ReactElement, ReactNode } from 'react';
|
|
4
|
+
import react__default, { ReactElement, ReactNode } from 'react';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
|
|
7
7
|
declare let WeaverseContext: react.Context<Weaverse>;
|
|
@@ -59,6 +59,6 @@ type ItemComponentProps = {
|
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
declare const useSafeExternalStore: (subscribe: any, getSnapshot: any, getServerSnapshot?: any) => any;
|
|
62
|
-
declare const WeaverseRoot:
|
|
62
|
+
declare const WeaverseRoot: react__default.MemoExoticComponent<({ context }: WeaverseRootPropsType) => react_jsx_runtime.JSX.Element | null>;
|
|
63
63
|
|
|
64
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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Weaverse, WeaverseItemStore, ElementCSS } from '@weaverse/core';
|
|
2
2
|
export * from '@weaverse/core';
|
|
3
3
|
import * as react from 'react';
|
|
4
|
-
import { ReactElement, ReactNode } from 'react';
|
|
4
|
+
import react__default, { ReactElement, ReactNode } from 'react';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
|
|
7
7
|
declare let WeaverseContext: react.Context<Weaverse>;
|
|
@@ -59,6 +59,6 @@ type ItemComponentProps = {
|
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
declare const useSafeExternalStore: (subscribe: any, getSnapshot: any, getServerSnapshot?: any) => any;
|
|
62
|
-
declare const WeaverseRoot:
|
|
62
|
+
declare const WeaverseRoot: react__default.MemoExoticComponent<({ context }: WeaverseRootPropsType) => react_jsx_runtime.JSX.Element | null>;
|
|
63
63
|
|
|
64
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
|
-
|
|
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
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
|
144
|
-
const routeData = dataContext[
|
|
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
|
});
|
|
@@ -272,8 +333,7 @@ var useChildInstances = (id) => {
|
|
|
272
333
|
|
|
273
334
|
// src/renderer.tsx
|
|
274
335
|
var import_clsx2 = __toESM(require("clsx"));
|
|
275
|
-
var
|
|
276
|
-
var import_react3 = require("react");
|
|
336
|
+
var import_react3 = __toESM(require("react"));
|
|
277
337
|
|
|
278
338
|
// src/utils/css.ts
|
|
279
339
|
var import_clsx = __toESM(require("clsx"));
|
|
@@ -313,13 +373,14 @@ function generateItemClassName(instance, stitchesInstance) {
|
|
|
313
373
|
// src/renderer.tsx
|
|
314
374
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
315
375
|
var import_react4 = require("react");
|
|
316
|
-
var
|
|
376
|
+
var REACT_VERSION_THRESHOLD = 18;
|
|
377
|
+
var reactVersion = Number(import_react3.default.version?.split(".")[0]) || 0;
|
|
317
378
|
var useSafeExternalStore = (subscribe, getSnapshot, getServerSnapshot = getSnapshot) => {
|
|
318
379
|
if (typeof window === "undefined") {
|
|
319
380
|
return getServerSnapshot();
|
|
320
381
|
}
|
|
321
|
-
if (
|
|
322
|
-
return
|
|
382
|
+
if (import_react3.default.useSyncExternalStore) {
|
|
383
|
+
return import_react3.default.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
323
384
|
}
|
|
324
385
|
return getSnapshot();
|
|
325
386
|
};
|
|
@@ -370,7 +431,6 @@ var ItemComponent = (0, import_react3.memo)(({ instance }) => {
|
|
|
370
431
|
type,
|
|
371
432
|
childIds = [],
|
|
372
433
|
children = [],
|
|
373
|
-
parentId,
|
|
374
434
|
createdAt,
|
|
375
435
|
updatedAt,
|
|
376
436
|
deletedAt,
|
|
@@ -378,17 +438,12 @@ var ItemComponent = (0, import_react3.memo)(({ instance }) => {
|
|
|
378
438
|
__hidden,
|
|
379
439
|
// Need to get rid of this `data` property
|
|
380
440
|
data: _,
|
|
381
|
-
content,
|
|
382
441
|
...rest
|
|
383
442
|
} = data;
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
context.dataContext
|
|
389
|
-
);
|
|
390
|
-
processedRest = { ...rest, content: processedContent };
|
|
391
|
-
}
|
|
443
|
+
const processedRest = replaceContentDataConnectorsDeep(
|
|
444
|
+
rest,
|
|
445
|
+
context.dataContext
|
|
446
|
+
);
|
|
392
447
|
(0, import_react3.useEffect)(() => {
|
|
393
448
|
if (!instance.ref.current) {
|
|
394
449
|
Object.assign(instance.ref, {
|
|
@@ -403,10 +458,13 @@ var ItemComponent = (0, import_react3.memo)(({ instance }) => {
|
|
|
403
458
|
if (Element?.Component) {
|
|
404
459
|
const Component = Element.Component;
|
|
405
460
|
Component.displayName = type;
|
|
406
|
-
if (Component.$$typeof === Symbol.for("react.forward_ref") || reactVersion >
|
|
461
|
+
if (Component.$$typeof === Symbol.for("react.forward_ref") || reactVersion > REACT_VERSION_THRESHOLD) {
|
|
407
462
|
processedRest.ref = instance.ref;
|
|
408
463
|
}
|
|
409
|
-
const
|
|
464
|
+
const childItems = children?.length ? children : childIds?.length ? childIds.map((cid) => ({ id: cid })) : [];
|
|
465
|
+
const renderChildren = childItems.map(
|
|
466
|
+
(item, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ItemInstance, { id: item.id, parentId: id }, `${item.id}-${index}`)
|
|
467
|
+
);
|
|
410
468
|
return /* @__PURE__ */ (0, import_react4.createElement)(
|
|
411
469
|
Component,
|
|
412
470
|
{
|
|
@@ -423,7 +481,6 @@ var ItemComponent = (0, import_react3.memo)(({ instance }) => {
|
|
|
423
481
|
);
|
|
424
482
|
}
|
|
425
483
|
instance._store.deleted = true;
|
|
426
|
-
console.log(`\u274C Unknown element: ${type}`);
|
|
427
484
|
return null;
|
|
428
485
|
});
|
|
429
486
|
ItemComponent.displayName = "WeaverseComponent";
|
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, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''')\n .replace(/\\//g, '/')\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 * 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 content,\n ...rest\n } = data\n\n // Replace data connectors in content (handles strings, objects, and arrays recursively)\n // IMMUTABLE: Process the entire data object to avoid mutating original content\n let processedRest = rest\n if (content !== undefined && content !== null) {\n const processedContent = replaceContentDataConnectorsDeep(\n content,\n context.dataContext\n )\n // Create new rest object instead of mutating original\n processedRest = { ...rest, content: processedContent }\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 console.log(`❌ Unknown element: ${type}`)\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;AAC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ACE,UAAU,aAAa,OAAO,IAAI,mBAAmB,KACrD,eAAe,IACf;AACA,oBAAc,MAAM,SAAS;AAAA,IAC/B;AACA,UAAM,kBACJ,UAAU,SACN,WACA,UAAU,SACR,SAAS,IAAI,CAAC,SAAiB,EAAE,IAAI,IAAI,EAAE,IAC3C,CAAC,GACP,IAAI,CAAC,MAAsB,UAC3B,4CAAC,gBAAa,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,UAAQ,IAAI,2BAAsB,IAAI,EAAE;AACxC,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","result","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, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''')\n .replace(/\\//g, '/')\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 React, { 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 REACT_VERSION_THRESHOLD = 18\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\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 > REACT_VERSION_THRESHOLD\n ) {\n processedRest.ref = instance.ref\n }\n const childItems = children?.length\n ? children\n : childIds?.length\n ? childIds.map((cid: string) => ({ id: cid }))\n : []\n\n const renderChildren = childItems.map(\n (item: { id: string }, index: number) => (\n <ItemInstance id={item.id} key={`${item.id}-${index}`} parentId={id} />\n )\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,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,EACT;AAEA,QAAM,UAAU,gBAAgB,IAAI,IAAI;AAExC,MAAI,SAAS,WAAW;AACtB,UAAM,YAAY,QAAQ;AAC1B,cAAU,cAAc;AACxB,QACE,UAAU,aAAa,OAAO,IAAI,mBAAmB,KACrD,eAAe,yBACf;AACA,oBAAc,MAAM,SAAS;AAAA,IAC/B;AACA,UAAM,aAAa,UAAU,SACzB,WACA,UAAU,SACR,SAAS,IAAI,CAAC,SAAiB,EAAE,IAAI,IAAI,EAAE,IAC3C,CAAC;AAEP,UAAM,iBAAiB,WAAW;AAAA,MAChC,CAAC,MAAsB,UACrB,4CAAC,gBAAa,IAAI,KAAK,IAAgC,UAAU,MAAjC,GAAG,KAAK,EAAE,IAAI,KAAK,EAAkB;AAAA,IAEzE;AAEA,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","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
|
-
|
|
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
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
|
100
|
-
const routeData = dataContext[
|
|
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
|
});
|
|
@@ -228,8 +289,7 @@ var useChildInstances = (id) => {
|
|
|
228
289
|
|
|
229
290
|
// src/renderer.tsx
|
|
230
291
|
import clsx2 from "clsx";
|
|
231
|
-
import
|
|
232
|
-
import { memo, useEffect, useRef } from "react";
|
|
292
|
+
import React, { memo, useEffect, useRef } from "react";
|
|
233
293
|
|
|
234
294
|
// src/utils/css.ts
|
|
235
295
|
import clsx from "clsx";
|
|
@@ -269,6 +329,7 @@ function generateItemClassName(instance, stitchesInstance) {
|
|
|
269
329
|
// src/renderer.tsx
|
|
270
330
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
271
331
|
import { createElement } from "react";
|
|
332
|
+
var REACT_VERSION_THRESHOLD = 18;
|
|
272
333
|
var reactVersion = Number(React.version?.split(".")[0]) || 0;
|
|
273
334
|
var useSafeExternalStore = (subscribe, getSnapshot, getServerSnapshot = getSnapshot) => {
|
|
274
335
|
if (typeof window === "undefined") {
|
|
@@ -326,7 +387,6 @@ var ItemComponent = memo(({ instance }) => {
|
|
|
326
387
|
type,
|
|
327
388
|
childIds = [],
|
|
328
389
|
children = [],
|
|
329
|
-
parentId,
|
|
330
390
|
createdAt,
|
|
331
391
|
updatedAt,
|
|
332
392
|
deletedAt,
|
|
@@ -334,17 +394,12 @@ var ItemComponent = memo(({ instance }) => {
|
|
|
334
394
|
__hidden,
|
|
335
395
|
// Need to get rid of this `data` property
|
|
336
396
|
data: _,
|
|
337
|
-
content,
|
|
338
397
|
...rest
|
|
339
398
|
} = data;
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
context.dataContext
|
|
345
|
-
);
|
|
346
|
-
processedRest = { ...rest, content: processedContent };
|
|
347
|
-
}
|
|
399
|
+
const processedRest = replaceContentDataConnectorsDeep(
|
|
400
|
+
rest,
|
|
401
|
+
context.dataContext
|
|
402
|
+
);
|
|
348
403
|
useEffect(() => {
|
|
349
404
|
if (!instance.ref.current) {
|
|
350
405
|
Object.assign(instance.ref, {
|
|
@@ -359,10 +414,13 @@ var ItemComponent = memo(({ instance }) => {
|
|
|
359
414
|
if (Element?.Component) {
|
|
360
415
|
const Component = Element.Component;
|
|
361
416
|
Component.displayName = type;
|
|
362
|
-
if (Component.$$typeof === Symbol.for("react.forward_ref") || reactVersion >
|
|
417
|
+
if (Component.$$typeof === Symbol.for("react.forward_ref") || reactVersion > REACT_VERSION_THRESHOLD) {
|
|
363
418
|
processedRest.ref = instance.ref;
|
|
364
419
|
}
|
|
365
|
-
const
|
|
420
|
+
const childItems = children?.length ? children : childIds?.length ? childIds.map((cid) => ({ id: cid })) : [];
|
|
421
|
+
const renderChildren = childItems.map(
|
|
422
|
+
(item, index) => /* @__PURE__ */ jsx(ItemInstance, { id: item.id, parentId: id }, `${item.id}-${index}`)
|
|
423
|
+
);
|
|
366
424
|
return /* @__PURE__ */ createElement(
|
|
367
425
|
Component,
|
|
368
426
|
{
|
|
@@ -379,7 +437,6 @@ var ItemComponent = memo(({ instance }) => {
|
|
|
379
437
|
);
|
|
380
438
|
}
|
|
381
439
|
instance._store.deleted = true;
|
|
382
|
-
console.log(`\u274C Unknown element: ${type}`);
|
|
383
440
|
return null;
|
|
384
441
|
});
|
|
385
442
|
ItemComponent.displayName = "WeaverseComponent";
|
package/dist/index.mjs.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, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''')\n .replace(/\\//g, '/')\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 * 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 content,\n ...rest\n } = data\n\n // Replace data connectors in content (handles strings, objects, and arrays recursively)\n // IMMUTABLE: Process the entire data object to avoid mutating original content\n let processedRest = rest\n if (content !== undefined && content !== null) {\n const processedContent = replaceContentDataConnectorsDeep(\n content,\n context.dataContext\n )\n // Create new rest object instead of mutating original\n processedRest = { ...rest, content: processedContent }\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 console.log(`❌ Unknown element: ${type}`)\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,qBAA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AA,EAEJ;AACF;AACA,aAAa,cAAc;","names":["result","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, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''')\n .replace(/\\//g, '/')\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 React, { 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 REACT_VERSION_THRESHOLD = 18\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\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 > REACT_VERSION_THRESHOLD\n ) {\n processedRest.ref = instance.ref\n }\n const childItems = children?.length\n ? children\n : childIds?.length\n ? childIds.map((cid: string) => ({ id: cid }))\n : []\n\n const renderChildren = childItems.map(\n (item: { id: string }, index: number) => (\n <ItemInstance id={item.id} key={`${item.id}-${index}`} parentId={id} />\n )\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,SA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|
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
|
|
5
|
+
"version": "5.5.0",
|
|
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
|
|
45
|
+
"@weaverse/core": "5.5.0",
|
|
46
46
|
"clsx": "^2.1.1",
|
|
47
47
|
"react": ">=18",
|
|
48
48
|
"react-dom": ">=18"
|