From e74229e6a5b3142ef46d9047be738796bd3302a6 Mon Sep 17 00:00:00 2001 From: Adam Brin Date: Wed, 3 Jul 2024 15:20:45 -0700 Subject: [PATCH] allow setContentStateFromText to be immediate We have a use-case for content-state to be updated immediately when switching to a full-screen behavior. This should allow that to be possible --- .../canvas-panel/src/helpers/content-state/content-state.ts | 1 + packages/canvas-panel/src/web-components/canvas-panel.tsx | 6 ++++-- packages/canvas-panel/src/web-components/sequence-panel.tsx | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/canvas-panel/src/helpers/content-state/content-state.ts b/packages/canvas-panel/src/helpers/content-state/content-state.ts index 25f4830..4edde9c 100644 --- a/packages/canvas-panel/src/helpers/content-state/content-state.ts +++ b/packages/canvas-panel/src/helpers/content-state/content-state.ts @@ -26,6 +26,7 @@ export type NormalisedContentState = { motivation: ['contentState', ...string[]]; target: Array; extensions: Record; + immediate?: boolean; }; /** diff --git a/packages/canvas-panel/src/web-components/canvas-panel.tsx b/packages/canvas-panel/src/web-components/canvas-panel.tsx index 3bb84cb..ecc1466 100644 --- a/packages/canvas-panel/src/web-components/canvas-panel.tsx +++ b/packages/canvas-panel/src/web-components/canvas-panel.tsx @@ -219,11 +219,12 @@ export const CanvasPanel: FC = (props) => { contentStateStack.current = []; }, - setContentStateFromText(text: string) { + setContentStateFromText(text: string, immediate = false) { if (text == undefined || text.trim() === '') { return; } const contentState = normaliseContentState(parseContentState(text)); + contentState.immediate = immediate; const firstTarget = contentState.target[0]; if (canvasIdRef.current === firstTarget.source.id) { @@ -234,7 +235,7 @@ export const CanvasPanel: FC = (props) => { contentState.target[0].selector && contentState.target[0].selector.type === 'BoxSelector' ) { - runtime.current.world.gotoRegion(contentState.target[0].selector.spatial); + runtime.current.world.gotoRegion({ ...contentState.target[0].selector.spatial, immediate }); } } else { setParsedContentState(contentState); @@ -275,6 +276,7 @@ export const CanvasPanel: FC = (props) => { y, width, height, + immediate: contentState.immediate, }); } else { setParsedTarget(firstTarget); diff --git a/packages/canvas-panel/src/web-components/sequence-panel.tsx b/packages/canvas-panel/src/web-components/sequence-panel.tsx index 1b45224..299aa38 100644 --- a/packages/canvas-panel/src/web-components/sequence-panel.tsx +++ b/packages/canvas-panel/src/web-components/sequence-panel.tsx @@ -120,11 +120,12 @@ export function SequencePanel(props: SequencePanelProps) { return ContentStateEvent; }, - setContentStateFromText(text: string) { + setContentStateFromText(text: string, immediate = false) { if (text == undefined || text.trim() === '') { return; } const contentState = normaliseContentState(parseContentState(text)); + contentState.immediate = immediate; setParsedContentState(contentState); }, @@ -185,6 +186,7 @@ export function SequencePanel(props: SequencePanelProps) { y, width, height, + immediate: contentState.immediate, }); } }