dynim-react 1.0.66 → 1.0.68
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/DynimProvider.d.ts.map +1 -1
- package/dist/DynimProvider.js +47 -16
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynimProvider.d.ts","sourceRoot":"","sources":["../src/DynimProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAc,EAQZ,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AAWf,OAAO,KAAK,EAKV,WAAW,EACX,UAAU,EACV,aAAa,EAGd,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"DynimProvider.d.ts","sourceRoot":"","sources":["../src/DynimProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAc,EAQZ,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AAWf,OAAO,KAAK,EAKV,WAAW,EACX,UAAU,EACV,aAAa,EAGd,MAAM,YAAY,CAAC;AAgBpB,MAAM,WAAW,WAAW;IAC1B,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrE,kCAAkC;IAClC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,KAAK,IAAI,CAAC;IACzC,uFAAuF;IACvF,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,wCAAwC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,iBAAiB;IAChC,yCAAyC;IACzC,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,qBAAqB;IACrB,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,0CAA0C;IAC1C,SAAS,EAAE,OAAO,CAAC;IACnB,qCAAqC;IACrC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,yBAAyB;IACzB,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,oCAAoC;IACpC,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,6CAA6C;IAC7C,cAAc,EAAE,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IAC5C,mEAAmE;IACnE,iBAAiB,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;IACpE,kDAAkD;IAClD,WAAW,EAAE,OAAO,CAAC;IACrB,yDAAyD;IACzD,WAAW,EAAE,WAAW,CAAC;IACzB,2CAA2C;IAC3C,cAAc,EAAE,OAAO,CAAC;IACxB,gCAAgC;IAChC,eAAe,EAAE,OAAO,CAAC;CAC1B;AAID,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,EAC5B,QAAQ,EACR,MAAW,GACZ,EAAE,kBAAkB,GAAG,GAAG,CAAC,OAAO,CAgelC;AAED;;GAEG;AACH,wBAAgB,QAAQ,IAAI,iBAAiB,CAM5C"}
|
package/dist/DynimProvider.js
CHANGED
|
@@ -12,6 +12,19 @@ import ReactDOM from 'react-dom';
|
|
|
12
12
|
import { createBuilderClient, createBuilder, createCodeClient, createBundleLoader, createCSSLoader, BundleNotFoundError, BundleAuthError, } from 'dynim-core';
|
|
13
13
|
import { createSharedContext, updateSharedContext, isSharedContextReady } from './inference/sharedContext';
|
|
14
14
|
import { generateThemeCSS } from './theme';
|
|
15
|
+
/** Decode JWT payload to extract claims (no verification - just for reading IDs) */
|
|
16
|
+
function decodeJwtPayload(token) {
|
|
17
|
+
try {
|
|
18
|
+
const parts = token.split('.');
|
|
19
|
+
if (parts.length !== 3)
|
|
20
|
+
return null;
|
|
21
|
+
const payload = JSON.parse(atob(parts[1]));
|
|
22
|
+
return payload;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
15
28
|
const DynimContext = createContext(null);
|
|
16
29
|
/**
|
|
17
30
|
* DynimProvider - Wrap your app with this to enable Dynim functionality
|
|
@@ -199,6 +212,17 @@ export function DynimProvider({ children, config = {}, }) {
|
|
|
199
212
|
}
|
|
200
213
|
return cssLoaderRef.current;
|
|
201
214
|
}, []);
|
|
215
|
+
// Build CSS URL with project/customer IDs from cached token
|
|
216
|
+
const buildCSSUrl = useCallback((temp = false) => {
|
|
217
|
+
const token = cachedTokenRef.current;
|
|
218
|
+
if (!token)
|
|
219
|
+
return null;
|
|
220
|
+
const claims = decodeJwtPayload(token);
|
|
221
|
+
if (!claims?.sub || !claims?.project)
|
|
222
|
+
return null;
|
|
223
|
+
const params = `project_id=${claims.project}&customer_id=${claims.sub}`;
|
|
224
|
+
return temp ? `/api/code/css?${params}&temp=true` : `/api/code/css?${params}`;
|
|
225
|
+
}, []);
|
|
202
226
|
// Load bundle (JS + CSS)
|
|
203
227
|
const loadBundle = useCallback(async (bundleUrl, loadCSS = true) => {
|
|
204
228
|
const loader = getBundleLoader();
|
|
@@ -213,16 +237,18 @@ export function DynimProvider({ children, config = {}, }) {
|
|
|
213
237
|
cleanup();
|
|
214
238
|
// Load CSS alongside JS bundle
|
|
215
239
|
if (loadCSS) {
|
|
216
|
-
const cssLoader = getCSSLoader();
|
|
217
240
|
const isTemp = bundleUrl.includes('temp=true');
|
|
218
|
-
const cssUrl = isTemp
|
|
219
|
-
if (
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
241
|
+
const cssUrl = buildCSSUrl(isTemp);
|
|
242
|
+
if (cssUrl) {
|
|
243
|
+
const cssLoader = getCSSLoader();
|
|
244
|
+
if (isTemp) {
|
|
245
|
+
// Temp/preview CSS - bust cache to get latest
|
|
246
|
+
cssLoader.loadWithCacheBust(cssUrl);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
// Saved CSS - let browser cache
|
|
250
|
+
cssLoader.load(cssUrl);
|
|
251
|
+
}
|
|
226
252
|
}
|
|
227
253
|
}
|
|
228
254
|
}
|
|
@@ -240,7 +266,7 @@ export function DynimProvider({ children, config = {}, }) {
|
|
|
240
266
|
finally {
|
|
241
267
|
setIsBundleLoading(false);
|
|
242
268
|
}
|
|
243
|
-
}, [getBundleLoader, getCSSLoader]);
|
|
269
|
+
}, [getBundleLoader, getCSSLoader, buildCSSUrl]);
|
|
244
270
|
// Keep ref updated
|
|
245
271
|
useEffect(() => {
|
|
246
272
|
loadBundleRef.current = loadBundle;
|
|
@@ -309,7 +335,8 @@ export function DynimProvider({ children, config = {}, }) {
|
|
|
309
335
|
// Note: CSS is loaded separately by saveCode/abandonCode with cache busting
|
|
310
336
|
await loadBundle('/api/code/bundle', false);
|
|
311
337
|
}, [loadBundle]);
|
|
312
|
-
// Watch for bundleReady
|
|
338
|
+
// Watch for bundleReady - use bundleSequence to detect new bundles
|
|
339
|
+
// (bundleReady alone stays true, so subsequent events wouldn't trigger re-render)
|
|
313
340
|
useEffect(() => {
|
|
314
341
|
if (codeMessage.bundleReady && codeMessage.projectId) {
|
|
315
342
|
if (isBuilderActiveRef.current && !isExitingRef.current) {
|
|
@@ -317,7 +344,7 @@ export function DynimProvider({ children, config = {}, }) {
|
|
|
317
344
|
setBundleLoadSignal(s => s + 1);
|
|
318
345
|
}
|
|
319
346
|
}
|
|
320
|
-
}, [codeMessage.bundleReady, codeMessage.projectId]);
|
|
347
|
+
}, [codeMessage.bundleReady, codeMessage.projectId, codeMessage.bundleSequence]);
|
|
321
348
|
// Load temp bundle on signal (JS + CSS with cache busting)
|
|
322
349
|
useEffect(() => {
|
|
323
350
|
if (bundleLoadSignal === 0)
|
|
@@ -352,14 +379,18 @@ export function DynimProvider({ children, config = {}, }) {
|
|
|
352
379
|
await codeClientRef.current?.saveCode();
|
|
353
380
|
await loadSavedBundle();
|
|
354
381
|
// Force reload CSS with cache bust since saved CSS has changed
|
|
355
|
-
|
|
356
|
-
|
|
382
|
+
const cssUrl = buildCSSUrl(false);
|
|
383
|
+
if (cssUrl)
|
|
384
|
+
getCSSLoader().loadWithCacheBust(cssUrl);
|
|
385
|
+
}, [loadSavedBundle, getCSSLoader, buildCSSUrl]);
|
|
357
386
|
const abandonCode = useCallback(async () => {
|
|
358
387
|
await codeClientRef.current?.abandonCode();
|
|
359
388
|
await loadSavedBundle();
|
|
360
389
|
// Reload saved CSS (may have been showing temp CSS)
|
|
361
|
-
|
|
362
|
-
|
|
390
|
+
const cssUrl = buildCSSUrl(false);
|
|
391
|
+
if (cssUrl)
|
|
392
|
+
getCSSLoader().loadWithCacheBust(cssUrl);
|
|
393
|
+
}, [loadSavedBundle, getCSSLoader, buildCSSUrl]);
|
|
363
394
|
const getCheckpoints = useCallback(async () => {
|
|
364
395
|
return codeClientRef.current?.getCheckpoints() ?? [];
|
|
365
396
|
}, []);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dynim-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.68",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"dev": "tsc --watch"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"dynim-core": "^1.0.
|
|
30
|
+
"dynim-core": "^1.0.42"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"react": ">=17.0.0",
|