@neurodyn/react-room-viewer 0.0.25 → 0.0.27

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.ts CHANGED
@@ -309,9 +309,9 @@ declare const resources: {
309
309
  };
310
310
  };
311
311
 
312
- export declare function RoomViewer({ type, src, tinuuid, name, language, width, height, dimensionUnit, displayUnit, apiKey, source, widgetSession, className, ...props }: RoomViewerProps & React_2.ComponentProps<'div'>): JSX.Element;
312
+ export declare function RoomViewer({ type, src, tinuuid, roomId, name, language, width, height, dimensionUnit, displayUnit, apiKey, source, widgetSession, className, ...props }: RoomViewerProps & React_2.ComponentProps<'div'>): JSX.Element;
313
313
 
314
- export declare function RoomViewerDialog({ type, src, tinuuid, width, height, dimensionUnit, displayUnit, name, language, apiKey, source, widgetSession, disableClose, open, defaultOpen, onOpenChange, }: RoomViewerDialogProps): JSX.Element;
314
+ export declare function RoomViewerDialog({ type, src, tinuuid, roomId, width, height, dimensionUnit, displayUnit, name, language, apiKey, source, widgetSession, disableClose, open, defaultOpen, onOpenChange, }: RoomViewerDialogProps): JSX.Element;
315
315
 
316
316
  declare interface RoomViewerDialogProps extends Omit<RoomViewerRootProps, 'showDialogCloseButton' | 'viewerSurface' | 'dialogPortalContainer' | 'viewerDialogOpen' | 'onViewerDialogOpenChange'>, Omit<DialogProps, 'children' | 'modal'> {
317
317
  /** Hide close controls and prevent user dismissal for rugs and flooring. Defaults to false. */
@@ -378,6 +378,12 @@ declare interface RoomViewerRootProps {
378
378
  src?: string;
379
379
  /** The object's tinuuid. Used for modelled products (`rugs`, `flooring`, `wall-panel`). */
380
380
  tinuuid?: string;
381
+ /**
382
+ * Initial Room from the available catalog. Skips the new layout's initial chooser.
383
+ * Changed nonempty values select another Room; empty values do nothing.
384
+ * Ignored by the legacy poster layout.
385
+ */
386
+ roomId?: string;
381
387
  /** Title shown in the dialog header. */
382
388
  name: string;
383
389
  /**
package/dist/index.js CHANGED
@@ -7423,6 +7423,19 @@ async function inferenceControllerRunRoomPlanesRaw(data, config = {}) {
7423
7423
  });
7424
7424
  return res.data;
7425
7425
  }
7426
+ async function layoutControllerReadLayoutConfig(headers, config = {}) {
7427
+ const { client: request = node_client_node_client, ...requestConfig } = config;
7428
+ const res = await request({
7429
+ method: "POST",
7430
+ url: "/layout/GetConfig",
7431
+ ...requestConfig,
7432
+ headers: {
7433
+ ...headers,
7434
+ ...requestConfig.headers
7435
+ }
7436
+ });
7437
+ return res.data;
7438
+ }
7426
7439
  async function publicApiControllerActivateWallart(params, config = {}) {
7427
7440
  const { client: request = node_client_node_client, ...requestConfig } = config;
7428
7441
  const res = await request({
@@ -17432,17 +17445,6 @@ function Room() {
17432
17445
  ]
17433
17446
  });
17434
17447
  }
17435
- async function layoutGetConfig(data, config = {}) {
17436
- const { client: request = client_client, ...requestConfig } = config;
17437
- const requestData = data;
17438
- const res = await request({
17439
- method: "POST",
17440
- url: "/layout/GetConfig",
17441
- data: requestData,
17442
- ...requestConfig
17443
- });
17444
- return res.data;
17445
- }
17446
17448
  const HDR_NEUTRAL_LINK_TYPE = 'hdr_neutral';
17447
17449
  const ROOM_VIEWER_CONFIG_QUERY_KEY = [
17448
17450
  'room-viewer',
@@ -17462,7 +17464,7 @@ function getNeutralHdrUrl(config) {
17462
17464
  function RemoteNeutralHdrEnvironment() {
17463
17465
  const configQuery = react_query_useQuery({
17464
17466
  queryKey: ROOM_VIEWER_CONFIG_QUERY_KEY,
17465
- queryFn: ()=>layoutGetConfig(),
17467
+ queryFn: ()=>layoutControllerReadLayoutConfig(),
17466
17468
  staleTime: 1 / 0
17467
17469
  });
17468
17470
  if (configQuery.isPending) return null;
@@ -18014,6 +18016,9 @@ function AR({ className, buttonClassName, buttonLeadingIcon, buttonLabel, button
18014
18016
  clone.updateMatrix();
18015
18017
  clone.updateMatrixWorld(true);
18016
18018
  if (isIOS) {
18019
+ clone.rotation.set(-Math.PI / 2, 0, 0);
18020
+ clone.updateMatrix();
18021
+ clone.updateMatrixWorld(true);
18017
18022
  const usdzExporter = new USDZExporter();
18018
18023
  const usdzBuffer = await usdzExporter.parseAsync(clone, {
18019
18024
  ar: {
@@ -19998,6 +20003,20 @@ function getInitialFloorViewerFlowState(viewerSurface) {
19998
20003
  }
19999
20004
  function reduceFloorViewerFlow(state, action) {
20000
20005
  switch(action.type){
20006
+ case 'clear-interior-selection':
20007
+ return {
20008
+ ...state,
20009
+ step: 'interior-selection',
20010
+ hasSceneSelection: false,
20011
+ automaticRoomId: action.automaticRoomId
20012
+ };
20013
+ case 'select-initial-room':
20014
+ return {
20015
+ step: 'scene',
20016
+ hasSceneSelection: true,
20017
+ sceneResetKey: state.sceneResetKey + 1,
20018
+ automaticRoomId: action.roomId
20019
+ };
20001
20020
  case 'open-interior-selection':
20002
20021
  return {
20003
20022
  ...state,
@@ -20409,8 +20428,18 @@ function useCustomInteriorIntakeFlow({ apiOptions, floorFlow, commitCustomInteri
20409
20428
  uploadRetryRequestId
20410
20429
  ]);
20411
20430
  }
20412
- function useFloorViewerFlow(viewerSurface, resetHandlers) {
20431
+ function useFloorViewerFlow(viewerSurface, resetHandlers, initialRoomSelection) {
20413
20432
  const [state, dispatch] = (0, __rspack_external_react.useReducer)(reduceFloorViewerFlow, viewerSurface, getInitialFloorViewerFlowState);
20433
+ const [appliedInitialRoomId, setAppliedInitialRoomId] = (0, __rspack_external_react.useState)();
20434
+ if (!initialRoomSelection?.isPending && appliedInitialRoomId !== initialRoomSelection?.roomId) {
20435
+ setAppliedInitialRoomId(initialRoomSelection?.roomId);
20436
+ if (initialRoomSelection) dispatch(initialRoomSelection.isAvailable ? {
20437
+ type: 'select-initial-room',
20438
+ roomId: initialRoomSelection.roomId
20439
+ } : {
20440
+ type: 'clear-interior-selection'
20441
+ });
20442
+ }
20414
20443
  const commitInteriorSelection = (0, __rspack_external_react.useCallback)((applySelection)=>{
20415
20444
  applySelection();
20416
20445
  resetSceneState(resetHandlers);
@@ -20440,6 +20469,14 @@ function useFloorViewerFlow(viewerSurface, resetHandlers) {
20440
20469
  type: 'return-to-interior-selection'
20441
20470
  });
20442
20471
  }, []);
20472
+ const clearInteriorSelection = (0, __rspack_external_react.useCallback)(()=>{
20473
+ dispatch({
20474
+ type: 'clear-interior-selection',
20475
+ automaticRoomId: state.automaticRoomId
20476
+ });
20477
+ }, [
20478
+ state.automaticRoomId
20479
+ ]);
20443
20480
  const startCustomInteriorProcessing = (0, __rspack_external_react.useCallback)(()=>{
20444
20481
  dispatch({
20445
20482
  type: 'start-custom-interior-processing'
@@ -20452,6 +20489,7 @@ function useFloorViewerFlow(viewerSurface, resetHandlers) {
20452
20489
  openInteriorSelection,
20453
20490
  recoverToScene,
20454
20491
  returnToInteriorSelection,
20492
+ clearInteriorSelection,
20455
20493
  startCustomInteriorProcessing
20456
20494
  }), [
20457
20495
  commitInteriorSelection,
@@ -20459,11 +20497,15 @@ function useFloorViewerFlow(viewerSurface, resetHandlers) {
20459
20497
  openInteriorSelection,
20460
20498
  recoverToScene,
20461
20499
  returnToInteriorSelection,
20500
+ clearInteriorSelection,
20462
20501
  startCustomInteriorProcessing,
20463
20502
  state
20464
20503
  ]);
20465
20504
  }
20466
20505
  function useRoomViewerFloorFlow(viewerSurface) {
20506
+ const { initialRoomId, room, sourceRooms } = useRoomViewerRooms();
20507
+ const { isViewerAccessPending, loadError, setLoadError } = useRoomViewerResource();
20508
+ const { type } = useRoomViewerMetadata();
20467
20509
  const { patchSceneLoad, setAngle, setRotation } = useRoomViewerSceneState();
20468
20510
  const resetHandlers = (0, __rspack_external_react.useMemo)(()=>({
20469
20511
  patchSceneLoad,
@@ -20474,7 +20516,27 @@ function useRoomViewerFloorFlow(viewerSurface) {
20474
20516
  setAngle,
20475
20517
  setRotation
20476
20518
  ]);
20477
- return useFloorViewerFlow(viewerSurface, resetHandlers);
20519
+ const initialRoom = sourceRooms.find((room)=>room.id === initialRoomId);
20520
+ const isAvailable = Boolean(initialRoom) && (!initialRoom?.scene || getAllowedRoomScenePlanes(initialRoom.scene, resolveResourceSurfaces(type)).length > 0);
20521
+ const floorFlow = useFloorViewerFlow(viewerSurface, resetHandlers, initialRoomId ? {
20522
+ roomId: initialRoomId,
20523
+ isAvailable,
20524
+ isPending: isViewerAccessPending
20525
+ } : void 0);
20526
+ const { automaticRoomId, clearInteriorSelection } = floorFlow;
20527
+ (0, __rspack_external_react.useEffect)(()=>{
20528
+ if (automaticRoomId && room.id === automaticRoomId && 'room-load-failed' === loadError) {
20529
+ clearInteriorSelection();
20530
+ setLoadError(null);
20531
+ }
20532
+ }, [
20533
+ automaticRoomId,
20534
+ clearInteriorSelection,
20535
+ loadError,
20536
+ room.id,
20537
+ setLoadError
20538
+ ]);
20539
+ return floorFlow;
20478
20540
  }
20479
20541
  function useRoomViewerFloorInteriorSelectionCommands(options) {
20480
20542
  const { room, setRoomId, setRooms } = useRoomViewerRooms();
@@ -21197,10 +21259,11 @@ function mergeRuntimeRooms(currentRooms, currentSourceRooms, nextSourceRooms) {
21197
21259
  ...nextSourceRooms
21198
21260
  ] : nextSourceRooms;
21199
21261
  }
21200
- function RoomViewerProvider({ children, src, tinuuid: initialTinuuid, type, viewerSurface, dialogPortalContainer = null, viewerDialogOpen = true, onViewerDialogOpenChange, width, height, displayUnit, name, apiKey, baseURL, source, externalWidgetSession }) {
21262
+ function RoomViewerProvider({ children, src, tinuuid: initialTinuuid, roomId: configuredRoomId, type, viewerSurface, dialogPortalContainer = null, viewerDialogOpen = true, onViewerDialogOpenChange, width, height, displayUnit, name, apiKey, baseURL, source, externalWidgetSession }) {
21201
21263
  const frameWidthOptions = useFrameWidthOptions();
21202
21264
  const mattingOptions = useMattingOptions(displayUnit);
21203
21265
  const identity = resolveResourceIdentityAnswers(type);
21266
+ const initialRoomId = 'immersive-room' === resolveResourceProfile(type).chrome ? configuredRoomId?.trim() || void 0 : void 0;
21204
21267
  const hasPanelFinishes = 'finish' === resolveResourceProfile(type).materialRole;
21205
21268
  const { offersSizeVariants } = resolveProductCompositionAnswers(type);
21206
21269
  const defaultRooms = resolveRoomPresets(resolveResourceProfile(type).roomPresets);
@@ -21343,7 +21406,18 @@ function RoomViewerProvider({ children, src, tinuuid: initialTinuuid, type, view
21343
21406
  }, [
21344
21407
  sourceRooms
21345
21408
  ]);
21346
- const [roomId, setRoomId] = (0, __rspack_external_react.useState)(()=>defaultRooms[0].id);
21409
+ const [roomId, setRoomId] = (0, __rspack_external_react.useState)(()=>initialRoomId ?? defaultRooms[0].id);
21410
+ const [previousInitialRoomId, setPreviousInitialRoomId] = (0, __rspack_external_react.useState)(initialRoomId);
21411
+ if (previousInitialRoomId !== initialRoomId) {
21412
+ setPreviousInitialRoomId(initialRoomId);
21413
+ if (initialRoomId) {
21414
+ setRoomId(initialRoomId);
21415
+ setAngle(0);
21416
+ setRotation(0);
21417
+ setSceneLoad(getInitialSceneLoadState(identity));
21418
+ setLoadError((current)=>'room-load-failed' === current ? null : current);
21419
+ }
21420
+ }
21347
21421
  const selectedRoom = rooms.find((currentRoom)=>currentRoom.id === roomId);
21348
21422
  const room = selectedRoom ?? rooms[0] ?? defaultRooms[0];
21349
21423
  const resetsRotationOnRoomChange = 'rotate-on-floor' === resolveResourceProfile(type).manipulation;
@@ -21586,10 +21660,12 @@ function RoomViewerProvider({ children, src, tinuuid: initialTinuuid, type, view
21586
21660
  sourceRooms,
21587
21661
  setRooms,
21588
21662
  room,
21663
+ initialRoomId,
21589
21664
  setRoomId
21590
21665
  }), [
21591
21666
  rooms,
21592
21667
  room,
21668
+ initialRoomId,
21593
21669
  setRooms,
21594
21670
  sourceRooms
21595
21671
  ]);
@@ -21728,7 +21804,7 @@ const root_queryClient = new QueryClient({
21728
21804
  }
21729
21805
  }
21730
21806
  });
21731
- function RoomViewerRoot({ type, src, tinuuid, name, height, width, language, dimensionUnit = "m", displayUnit = "cm", apiKey, source = 'default', showDialogCloseButton = false, viewerSurface = 'inline', dialogPortalContainer = null, viewerDialogOpen = true, onViewerDialogOpenChange, widgetSession }) {
21807
+ function RoomViewerRoot({ type, src, tinuuid, roomId, name, height, width, language, dimensionUnit = "m", displayUnit = "cm", apiKey, source = 'default', showDialogCloseButton = false, viewerSurface = 'inline', dialogPortalContainer = null, viewerDialogOpen = true, onViewerDialogOpenChange, widgetSession }) {
21732
21808
  const { i18n } = useTranslation();
21733
21809
  const normalizedApiKey = normalizeRoomViewerApiKey(apiKey);
21734
21810
  const normalizedTinuuid = normalizeRoomViewerTinuuid(tinuuid);
@@ -21751,6 +21827,7 @@ function RoomViewerRoot({ type, src, tinuuid, name, height, width, language, dim
21751
21827
  children: /*#__PURE__*/ jsx_runtime_jsx(RoomViewerProvider, {
21752
21828
  src: src ?? null,
21753
21829
  tinuuid: normalizedTinuuid ?? null,
21830
+ roomId: roomId,
21754
21831
  type: resourceType,
21755
21832
  viewerSurface: viewerSurface,
21756
21833
  dialogPortalContainer: dialogPortalContainer,
@@ -21776,7 +21853,7 @@ configureApiClient({
21776
21853
  configureNodeApiClient({
21777
21854
  baseURL: config_env.NODE_API_BASE_URL
21778
21855
  });
21779
- function RoomViewerDialog({ type, src, tinuuid, width, height, dimensionUnit, displayUnit, name, language, apiKey, source, widgetSession, disableClose = false, open, defaultOpen, onOpenChange }) {
21856
+ function RoomViewerDialog({ type, src, tinuuid, roomId, width, height, dimensionUnit, displayUnit, name, language, apiKey, source, widgetSession, disableClose = false, open, defaultOpen, onOpenChange }) {
21780
21857
  const [themeRoot, setThemeRoot] = (0, __rspack_external_react.useState)(null);
21781
21858
  const isCloseDisabled = 'immersive-room' === resolveResourceProfile(normalizeResourceType(type)).chrome && disableClose;
21782
21859
  const [uncontrolledOpen, setUncontrolledOpen] = (0, __rspack_external_react.useState)(defaultOpen ?? false);
@@ -21797,6 +21874,7 @@ function RoomViewerDialog({ type, src, tinuuid, width, height, dimensionUnit, di
21797
21874
  type: type,
21798
21875
  src: src,
21799
21876
  tinuuid: tinuuid,
21877
+ roomId: roomId,
21800
21878
  name: name,
21801
21879
  height: height,
21802
21880
  width: width,
@@ -21848,7 +21926,7 @@ function RoomViewerDialog({ type, src, tinuuid, width, height, dimensionUnit, di
21848
21926
  ]
21849
21927
  });
21850
21928
  }
21851
- function RoomViewer({ type, src, tinuuid, name, language, width, height, dimensionUnit, displayUnit, apiKey, source, widgetSession, className, ...props }) {
21929
+ function RoomViewer({ type, src, tinuuid, roomId, name, language, width, height, dimensionUnit, displayUnit, apiKey, source, widgetSession, className, ...props }) {
21852
21930
  const [themeRoot, setThemeRoot] = (0, __rspack_external_react.useState)(null);
21853
21931
  return /*#__PURE__*/ jsxs(Fragment, {
21854
21932
  children: [
@@ -21884,6 +21962,7 @@ function RoomViewer({ type, src, tinuuid, name, language, width, height, dimensi
21884
21962
  type: type,
21885
21963
  src: src,
21886
21964
  tinuuid: tinuuid,
21965
+ roomId: roomId,
21887
21966
  name: name,
21888
21967
  language: language,
21889
21968
  width: width,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@neurodyn/react-room-viewer",
3
3
  "type": "module",
4
- "version": "0.0.25",
4
+ "version": "0.0.27",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },