diff --git a/packages/editor/src/components/CodeBlockEditor.vue b/packages/editor/src/components/CodeBlockEditor.vue index f3f936ee..b69940d4 100644 --- a/packages/editor/src/components/CodeBlockEditor.vue +++ b/packages/editor/src/components/CodeBlockEditor.vue @@ -6,6 +6,7 @@ v-model:height="codeBlockEditorHeight" :body-style="{ padding: '0 16px' }" :title="content.name ? `${disabled ? '查看' : '编辑'}${content.name}` : '新增代码'" + :framework-width="frameworkWidth" :position="boxPosition" :before-close="beforeClose" > @@ -207,6 +208,7 @@ const closedHandler = () => { const parentFloating = inject>('parentFloating', ref(null)); const { boxPosition, calcBoxPosition } = useNextFloatBoxPosition(uiService, parentFloating); +const frameworkWidth = computed(() => uiService.get('frameworkRect')?.width || 0); watch(boxVisible, (visible) => { nextTick(() => { diff --git a/packages/editor/src/components/FloatingBox.vue b/packages/editor/src/components/FloatingBox.vue index 2fdf00b4..da0cbbc3 100644 --- a/packages/editor/src/components/FloatingBox.vue +++ b/packages/editor/src/components/FloatingBox.vue @@ -30,7 +30,6 @@ import VanillaMoveable from 'moveable'; import { TMagicButton, useZIndex } from '@tmagic/design'; import MIcon from '@editor/components/Icon.vue'; -import { useServices } from '@editor/hooks/use-services'; interface Position { left: number; @@ -46,11 +45,17 @@ const props = withDefaults( position?: Position; title?: string; bodyStyle?: CSSProperties; + /** 浮窗初始样式,会与内部计算样式合并,外部传入优先 */ + initialStyle?: CSSProperties; + /** 用于约束浮窗 left 的容器宽度,传入时按宽度收敛 left,避免超出右边界;默认取视窗宽度 */ + frameworkWidth?: number; beforeClose?: (_done: (_cancel?: boolean) => void) => void; }>(), { title: '', position: () => ({ left: 0, top: 0 }), + initialStyle: () => ({}), + frameworkWidth: 0, }, ); @@ -73,12 +78,11 @@ const bodyHeight = computed(() => { return 'auto'; }); -const { uiService } = useServices(); -const frameworkWidth = computed(() => uiService.get('frameworkRect').width || 0); const style = computed(() => { let { left } = props.position; - if (width.value) { - left = left + width.value > frameworkWidth.value ? frameworkWidth.value - width.value : left; + const frameworkWidth = props.frameworkWidth || globalThis.window?.innerWidth || 0; + if (width.value && frameworkWidth) { + left = left + width.value > frameworkWidth ? frameworkWidth - width.value : left; } return { @@ -86,6 +90,7 @@ const style = computed(() => { top: `${props.position.top}px`, width: width.value ? `${width.value}px` : 'auto', height: height.value ? `${height.value}px` : 'auto', + ...props.initialStyle, }; }); diff --git a/packages/editor/src/fields/DataSourceFields.vue b/packages/editor/src/fields/DataSourceFields.vue index c5e64cb2..e904e45e 100644 --- a/packages/editor/src/fields/DataSourceFields.vue +++ b/packages/editor/src/fields/DataSourceFields.vue @@ -13,6 +13,7 @@ v-model:width="width" v-model:height="editorHeight" :title="fieldTitle" + :framework-width="frameworkWidth" :position="boxPosition" >