dynim-react 1.0.3 → 1.0.5

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.
@@ -1 +1 @@
1
- {"version":3,"file":"BuilderProvider.d.ts","sourceRoot":"","sources":["../../src/builder/BuilderProvider.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAQL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AASf,OAAO,KAAK,EAEV,eAAe,EAGf,QAAQ,EACR,SAAS,EACT,WAAW,EAGX,WAAW,EACZ,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,2CAA2C;IAC3C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mDAAmD;IACnD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,KAAK,IAAI,CAAC;IACzC,oEAAoE;IACpE,mBAAmB,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;IACrD,0CAA0C;IAC1C,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;IACtC,kDAAkD;IAClD,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IAG3C,gFAAgF;IAChF,gBAAgB,CAAC,EAAE,WAAW,CAAC;IAC/B,qDAAqD;IACrD,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM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,CAAC;IACtD,wDAAwD;IACxD,cAAc,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,2CAA2C;IAC3C,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;IACxE,qCAAqC;IACrC,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9D,wCAAwC;IACxC,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC3E,2CAA2C;IAC3C,gBAAgB,EAAE,OAAO,CAAC;IAC1B,4CAA4C;IAC5C,cAAc,EAAE,OAAO,CAAC;IACxB,iCAAiC;IACjC,eAAe,EAAE,OAAO,CAAC;IACzB,4BAA4B;IAC5B,YAAY,EAAE,MAAM,IAAI,CAAC;CAC1B;AAID,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,CAAC;CACzD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,MAAW,EACX,cAAc,GACf,EAAE,oBAAoB,GAAG,GAAG,CAAC,OAAO,CA8apC;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,mBAAmB,CAMhD"}
@@ -18,8 +18,6 @@ export function BuilderProvider({ children, config = {}, onBuilderReady, }) {
18
18
  const bundleManagerRef = useRef(null);
19
19
  const styleApplierRef = useRef(null);
20
20
  const [internalContainer, setInternalContainer] = useState(null);
21
- // Pending bundle load - queued when bundle_ready arrives before bundle manager initializes
22
- const pendingBundleLoadRef = useRef(null);
23
21
  const [isBuilderActive, setIsBuilderActive] = useState(false);
24
22
  const [isBundleLoaded, setIsBundleLoaded] = useState(false);
25
23
  const [isBundleLoading, setIsBundleLoading] = useState(false);
@@ -32,10 +30,44 @@ export function BuilderProvider({ children, config = {}, onBuilderReady, }) {
32
30
  bundleReady: false,
33
31
  bundleError: undefined,
34
32
  });
35
- // Initialize visual builder (createBuilder from core)
33
+ // Initialize code client FIRST (before builder, so we can share it)
34
+ useEffect(() => {
35
+ const { apiBase = 'http://localhost:8080', sessionToken, refreshToken, getSession, onCodeMessageUpdate, onCodeMessage, // deprecated
36
+ onCodeEdit, onError, autoApplyStyles = true, } = config;
37
+ codeClientRef.current = createCodeClient({
38
+ apiBase,
39
+ sessionToken,
40
+ refreshToken,
41
+ getSession,
42
+ onMessageUpdate: (message) => {
43
+ // Update local state with the structured message
44
+ setCodeMessage(message);
45
+ // Forward to consumer callback
46
+ onCodeMessageUpdate?.(message);
47
+ },
48
+ onRawEvent: (event) => {
49
+ // Forward raw events for debugging/advanced use
50
+ onCodeMessage?.(event);
51
+ },
52
+ onEdit: (edit) => {
53
+ console.log('[BuilderProvider] Code edit:', edit);
54
+ // Auto-apply style changes if enabled and style applier is available
55
+ if (autoApplyStyles && styleApplierRef.current && hasStyleChanges(edit)) {
56
+ const result = styleApplierRef.current.processEdit(edit);
57
+ console.log('[BuilderProvider] Style changes:', result.changes.length, 'applied:', result.applied);
58
+ }
59
+ onCodeEdit?.(edit);
60
+ },
61
+ onError: (error) => {
62
+ console.error('[BuilderProvider] Code error:', error);
63
+ onError?.(error);
64
+ },
65
+ });
66
+ }, [config]);
67
+ // Initialize visual builder (createBuilder from core) - AFTER codeClient
36
68
  useEffect(() => {
37
69
  const { apiBase = 'http://localhost:8080', pageId = window.location.pathname, logo = 'Builder', contentRoot = document.body, sessionToken, refreshToken, getSession, } = config;
38
- // Create the visual builder instance
70
+ // Create the visual builder instance, sharing our CodeClient
39
71
  builderRef.current = createBuilder({
40
72
  logo,
41
73
  contentRoot,
@@ -44,6 +76,7 @@ export function BuilderProvider({ children, config = {}, onBuilderReady, }) {
44
76
  sessionToken,
45
77
  refreshToken,
46
78
  getSession,
79
+ codeClient: codeClientRef.current ?? undefined,
47
80
  onEnter: () => {
48
81
  console.log('[BuilderProvider] Visual builder entered');
49
82
  setIsBuilderActive(true);
@@ -145,40 +178,6 @@ export function BuilderProvider({ children, config = {}, onBuilderReady, }) {
145
178
  setHasBundleManager(false);
146
179
  };
147
180
  }, [config, internalContainer]);
148
- // Initialize code client for flexcode integration
149
- useEffect(() => {
150
- const { apiBase = 'http://localhost:8080', sessionToken, refreshToken, getSession, onCodeMessageUpdate, onCodeMessage, // deprecated
151
- onCodeEdit, onError, autoApplyStyles = true, } = config;
152
- codeClientRef.current = createCodeClient({
153
- apiBase,
154
- sessionToken,
155
- refreshToken,
156
- getSession,
157
- onMessageUpdate: (message) => {
158
- // Update local state with the structured message
159
- setCodeMessage(message);
160
- // Forward to consumer callback
161
- onCodeMessageUpdate?.(message);
162
- },
163
- onRawEvent: (event) => {
164
- // Forward raw events for debugging/advanced use
165
- onCodeMessage?.(event);
166
- },
167
- onEdit: (edit) => {
168
- console.log('[BuilderProvider] Code edit:', edit);
169
- // Auto-apply style changes if enabled and style applier is available
170
- if (autoApplyStyles && styleApplierRef.current && hasStyleChanges(edit)) {
171
- const result = styleApplierRef.current.processEdit(edit);
172
- console.log('[BuilderProvider] Style changes:', result.changes.length, 'applied:', result.applied);
173
- }
174
- onCodeEdit?.(edit);
175
- },
176
- onError: (error) => {
177
- console.error('[BuilderProvider] Code error:', error);
178
- onError?.(error);
179
- },
180
- });
181
- }, [config]);
182
181
  // Enter builder mode - activates the visual builder UI
183
182
  const enterBuilder = useCallback(() => {
184
183
  if (builderRef.current && !builderRef.current.isActive()) {
@@ -240,29 +239,14 @@ export function BuilderProvider({ children, config = {}, onBuilderReady, }) {
240
239
  await loadBundle(bundleUrl);
241
240
  console.log('[BuilderProvider] Temp bundle loaded');
242
241
  }, [config, loadBundle]);
243
- // Auto-reload temp bundle when bundle is ready (projectId comes from server event)
244
- useEffect(() => {
245
- if (codeMessage.bundleReady && codeMessage.projectId) {
246
- if (bundleManagerRef.current) {
247
- // Bundle manager is ready - load immediately
248
- console.log('[BuilderProvider] Bundle ready - loading temp bundle:', codeMessage.projectId);
249
- loadTempBundle(codeMessage.projectId);
250
- }
251
- else {
252
- // Bundle manager not ready yet - queue the load for later
253
- console.log('[BuilderProvider] Bundle ready but manager not initialized - queueing load for:', codeMessage.projectId);
254
- pendingBundleLoadRef.current = codeMessage.projectId;
255
- }
256
- }
257
- }, [codeMessage.bundleReady, codeMessage.projectId, loadTempBundle]);
258
- // Process pending bundle load when bundle manager becomes available
242
+ // Auto-reload temp bundle when bundle is ready and bundle manager is available
243
+ // Uses hasBundleManager as dependency so it re-runs when manager initializes
259
244
  useEffect(() => {
260
- if (hasBundleManager && pendingBundleLoadRef.current) {
261
- console.log('[BuilderProvider] Bundle manager ready - processing queued load:', pendingBundleLoadRef.current);
262
- loadTempBundle(pendingBundleLoadRef.current);
263
- pendingBundleLoadRef.current = null;
245
+ if (codeMessage.bundleReady && codeMessage.projectId && hasBundleManager) {
246
+ console.log('[BuilderProvider] Bundle ready - loading temp bundle:', codeMessage.projectId);
247
+ loadTempBundle(codeMessage.projectId);
264
248
  }
265
- }, [hasBundleManager, loadTempBundle]);
249
+ }, [codeMessage.bundleReady, codeMessage.projectId, hasBundleManager, loadTempBundle]);
266
250
  const applyStyles = useCallback((selector, styles) => {
267
251
  bundleManagerRef.current?.applyStyles(selector, styles);
268
252
  }, []);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dynim-react",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -13,7 +13,7 @@
13
13
  "dev": "tsc --watch"
14
14
  },
15
15
  "dependencies": {
16
- "dynim-core": "^1.0.1"
16
+ "dynim-core": "^1.0.3"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "react": ">=17.0.0",