@weaverse/next 0.1.0-alpha.15 → 0.1.0-alpha.16

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":"runtime.d.ts","sourceRoot":"","sources":["../../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC1C,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,QAAQ,CAAA;AAIf,OAAO,KAAK,EAGV,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,EACzB,2BAA2B,EAC3B,8BAA8B,EAE9B,0BAA0B,EAC3B,MAAM,SAAS,CAAA;AAEhB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,UAAU,CAAC,EAAE,mBAAmB,CAAA;QAChC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAA;KAClD;CACF;AAkHD,yEAAyE;AACzE,MAAM,WAAW,0BAA2B,SAAQ,oBAAoB;IACtE,oEAAoE;IACpE,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,QAAQ;IAC/C,mDAAmD;IACnD,MAAM,EAAE,MAAM,CAAA;IACd,kEAAkE;IAClE,QAAQ,EAAE,2BAA2B,CAAA;IACrC,8DAA8D;IAC9D,WAAW,EAAE,uBAAuB,CAAA;IACpC,wDAAwD;IACxD,aAAa,EAAE,OAAO,CAAA;IACtB,qDAAqD;IACrD,iBAAiB,EAAE,OAAO,CAAA;IAC1B,uDAAuD;IACvD,WAAW,CAAC,EAAE,MAAM,CAAA;IAGpB;;;;OAIG;IACH,cAAc,EAAE,0BAA0B,CAAK;IAC/C,iEAAiE;IACjE,iBAAiB,SAAW;IAC5B,iEAAiE;IACjE,qBAAqB,SAAW;IAEhC;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,0BAA0B,CA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
4
  "description": "Next.js App Router integration for building Weaverse-powered storefronts",
5
- "version": "0.1.0-alpha.15",
5
+ "version": "0.1.0-alpha.16",
6
6
  "license": "MIT",
7
7
  "main": "dist/index.js",
8
8
  "typings": "dist/types/index.d.ts",
package/src/renderer.tsx CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { WeaverseRoot } from '@weaverse/react'
4
4
  import { memo, useContext, useEffect, useLayoutEffect, useMemo } from 'react'
5
+ import type { JSX } from 'react/jsx-runtime'
5
6
  import { WeaverseNextContext } from './provider'
6
7
  import { createWeaverseNextRuntime } from './runtime'
7
8
  import type {
@@ -50,7 +51,7 @@ export interface WeaverseNextRendererProps {
50
51
  */
51
52
  export const WeaverseNextRenderer = memo(function WeaverseNextRendererComponent(
52
53
  props: WeaverseNextRendererProps
53
- ) {
54
+ ): JSX.Element | null {
54
55
  let context = useContext(WeaverseNextContext)
55
56
  let client = props.client ?? context?.client
56
57
  let data = props.data ?? client?.data ?? null
package/src/runtime.ts CHANGED
@@ -56,6 +56,36 @@ function getConfigString(
56
56
  return typeof value === 'string' ? value : undefined
57
57
  }
58
58
 
59
+ /**
60
+ * Resolve a non-published mode flag from the request context OR the serialized
61
+ * loader configs.
62
+ *
63
+ * These flags only ever suppress Studio rendering, so the two sources are
64
+ * OR-ed rather than nullish-coalesced. A
65
+ * client-supplied `requestContext` that explicitly sets `false` must not shadow
66
+ * a `true` the server resolved for this request.
67
+ */
68
+ function resolveModeFlag(
69
+ config: WeaverseNextRuntimeConfig,
70
+ key: 'isDesignMode' | 'isPreviewMode' | 'isRevisionPreview'
71
+ ): boolean {
72
+ return (
73
+ config.client?.requestContext?.[key] === true ||
74
+ config.data.configs?.[key] === true
75
+ )
76
+ }
77
+
78
+ /** Section preview type from either source; see {@link resolveModeFlag}. */
79
+ function resolveSectionType(
80
+ config: WeaverseNextRuntimeConfig
81
+ ): string | undefined {
82
+ return (
83
+ config.client?.requestContext?.sectionType ||
84
+ getConfigString(config.data.configs, 'sectionType') ||
85
+ undefined
86
+ )
87
+ }
88
+
59
89
  function getRecordString(
60
90
  record: Record<string, unknown> | undefined,
61
91
  key: string
@@ -198,13 +228,17 @@ export class WeaverseNextRuntime extends Weaverse {
198
228
  let page = getRenderablePage(data)
199
229
  let configs = data.configs
200
230
  let requestContext = client?.requestContext
231
+ let isDesignMode = resolveModeFlag(config, 'isDesignMode')
232
+ let isPreviewMode = resolveModeFlag(config, 'isPreviewMode')
233
+ let isRevisionPreview = resolveModeFlag(config, 'isRevisionPreview')
234
+ let sectionType = resolveSectionType(config)
201
235
  let projectId = resolveProjectId(client, data, page.id)
202
236
 
203
237
  ensureNextItemConstructor()
204
238
  super({
205
239
  projectId,
206
240
  data: page,
207
- isDesignMode: requestContext?.isDesignMode ?? false,
241
+ isDesignMode,
208
242
  weaverseHost: getConfigString(configs, 'weaverseHost'),
209
243
  weaverseVersion: getConfigString(configs, 'weaverseVersion'),
210
244
  })
@@ -212,10 +246,10 @@ export class WeaverseNextRuntime extends Weaverse {
212
246
  this.pageId = page.id
213
247
  this.dataContext = resolveDataContext(config)
214
248
  this.requestInfo = buildWeaverseNextRequestInfo(requestContext)
215
- this.isDesignMode = requestContext?.isDesignMode ?? false
216
- this.isPreviewMode = requestContext?.isPreviewMode ?? false
217
- this.isRevisionPreview = requestContext?.isRevisionPreview ?? false
218
- this.sectionType = requestContext?.sectionType
249
+ this.isDesignMode = isDesignMode
250
+ this.isPreviewMode = isPreviewMode
251
+ this.isRevisionPreview = isRevisionPreview
252
+ this.sectionType = sectionType
219
253
 
220
254
  // One store instance backs both the canonical `translationStore` and the
221
255
  // deprecated `themeTextStore` alias, so Builder's `updateStaticText()` RPC
@@ -390,7 +424,11 @@ export function createWeaverseNextRuntime(
390
424
  let requestKey = getRuntimeKey(page.id, requestInfo)
391
425
 
392
426
  if (existing?.__weaverseNextRequestKey === requestKey) {
393
- let nextIsDesignMode = config.client?.requestContext?.isDesignMode ?? false
427
+ let configs = config.data.configs
428
+ let nextIsDesignMode = resolveModeFlag(config, 'isDesignMode')
429
+ let nextIsPreviewMode = resolveModeFlag(config, 'isPreviewMode')
430
+ let nextIsRevisionPreview = resolveModeFlag(config, 'isRevisionPreview')
431
+ let nextSectionType = resolveSectionType(config)
394
432
  // In design mode the live Studio runtime owns the page tree, including
395
433
  // unsaved drafts. Reapplying loader `page` data here would clobber those
396
434
  // edits, so leave the project data untouched and let
@@ -418,17 +456,13 @@ export function createWeaverseNextRuntime(
418
456
  existing.requestInfo = requestInfo
419
457
  existing.projectId = resolveProjectId(config.client, config.data, page.id)
420
458
  existing.isDesignMode = nextIsDesignMode
421
- existing.isPreviewMode =
422
- config.client?.requestContext?.isPreviewMode ?? false
423
- existing.isRevisionPreview =
424
- config.client?.requestContext?.isRevisionPreview ?? false
425
- existing.sectionType = config.client?.requestContext?.sectionType
459
+ existing.isPreviewMode = nextIsPreviewMode
460
+ existing.isRevisionPreview = nextIsRevisionPreview
461
+ existing.sectionType = nextSectionType
426
462
  existing.weaverseHost =
427
- getConfigString(config.data.configs, 'weaverseHost') ??
428
- existing.weaverseHost
463
+ getConfigString(configs, 'weaverseHost') ?? existing.weaverseHost
429
464
  existing.weaverseVersion =
430
- getConfigString(config.data.configs, 'weaverseVersion') ??
431
- existing.weaverseVersion
465
+ getConfigString(configs, 'weaverseVersion') ?? existing.weaverseVersion
432
466
  existing.internal.pageAssignment = config.data.pageAssignment
433
467
  existing.internal.project = config.data.project
434
468
  if (config.navigate) {