mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-19 12:14:27 +08:00
refactor(editor): useTemplateRef参数不能与变量名一样,不然会有一个warn
This commit is contained in:
parent
552df3a614
commit
1baec3f1d4
@ -104,14 +104,14 @@ const { height: codeBlockEditorHeight } = useEditorContentHeight();
|
|||||||
const difVisible = ref(false);
|
const difVisible = ref(false);
|
||||||
const { rect: windowRect } = useWindowRect();
|
const { rect: windowRect } = useWindowRect();
|
||||||
|
|
||||||
const magicVsEditor = useTemplateRef<InstanceType<typeof CodeEditor>>('magicVsEditor');
|
const magicVsEditorRef = useTemplateRef<InstanceType<typeof CodeEditor>>('magicVsEditor');
|
||||||
|
|
||||||
const diffChange = () => {
|
const diffChange = () => {
|
||||||
if (!magicVsEditor.value || !formBox.value?.form) {
|
if (!magicVsEditorRef.value || !formBox.value?.form) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
formBox.value.form.values.content = magicVsEditor.value.getEditorValue();
|
formBox.value.form.values.content = magicVsEditorRef.value.getEditorValue();
|
||||||
|
|
||||||
difVisible.value = false;
|
difVisible.value = false;
|
||||||
};
|
};
|
||||||
|
@ -32,7 +32,7 @@ const props = defineProps<{
|
|||||||
|
|
||||||
const emit = defineEmits(['change']);
|
const emit = defineEmits(['change']);
|
||||||
|
|
||||||
const form = useTemplateRef<InstanceType<typeof MForm>>('form');
|
const formRef = useTemplateRef<InstanceType<typeof MForm>>('form');
|
||||||
|
|
||||||
const getFormConfig = (items: FormConfig = []) => [
|
const getFormConfig = (items: FormConfig = []) => [
|
||||||
{
|
{
|
||||||
@ -61,7 +61,7 @@ const codeParamsConfig = computed(() =>
|
|||||||
*/
|
*/
|
||||||
const onParamsChangeHandler = async (v: FormValue, eventData: ContainerChangeEventData) => {
|
const onParamsChangeHandler = async (v: FormValue, eventData: ContainerChangeEventData) => {
|
||||||
try {
|
try {
|
||||||
const value = await form.value?.submitForm(true);
|
const value = await formRef.value?.submitForm(true);
|
||||||
emit('change', value, eventData);
|
emit('change', value, eventData);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error(e);
|
error(e);
|
||||||
|
@ -69,9 +69,9 @@ const emit = defineEmits<{
|
|||||||
mouseenter: [];
|
mouseenter: [];
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const menu = useTemplateRef<HTMLDivElement>('menu');
|
const menuEl = useTemplateRef<HTMLDivElement>('menu');
|
||||||
const buttons = useTemplateRef<InstanceType<typeof ToolButton>[]>('buttons');
|
const buttonRefs = useTemplateRef<InstanceType<typeof ToolButton>[]>('buttons');
|
||||||
const subMenu = useTemplateRef<any>('subMenu');
|
const subMenuRef = useTemplateRef<any>('subMenu');
|
||||||
const visible = ref(false);
|
const visible = ref(false);
|
||||||
const subMenuData = ref<(MenuButton | MenuComponent)[]>([]);
|
const subMenuData = ref<(MenuButton | MenuComponent)[]>([]);
|
||||||
const zIndex = useZIndex();
|
const zIndex = useZIndex();
|
||||||
@ -88,13 +88,13 @@ const menuStyle = computed(() => ({
|
|||||||
zIndex: curZIndex.value,
|
zIndex: curZIndex.value,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const contains = (el: HTMLElement) => menu.value?.contains(el) || subMenu.value?.contains(el);
|
const contains = (el: HTMLElement) => menuEl.value?.contains(el) || subMenuRef.value?.contains(el);
|
||||||
|
|
||||||
const hide = () => {
|
const hide = () => {
|
||||||
if (!visible.value) return;
|
if (!visible.value) return;
|
||||||
|
|
||||||
visible.value = false;
|
visible.value = false;
|
||||||
subMenu.value?.hide();
|
subMenuRef.value?.hide();
|
||||||
|
|
||||||
emit('hide');
|
emit('hide');
|
||||||
};
|
};
|
||||||
@ -121,7 +121,7 @@ const outsideClickHideHandler = (e: MouseEvent) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const setPosition = (e: { clientY: number; clientX: number }) => {
|
const setPosition = (e: { clientY: number; clientX: number }) => {
|
||||||
const menuHeight = menu.value?.clientHeight || 0;
|
const menuHeight = menuEl.value?.clientHeight || 0;
|
||||||
|
|
||||||
let top = e.clientY;
|
let top = e.clientY;
|
||||||
if (menuHeight + e.clientY > document.body.clientHeight) {
|
if (menuHeight + e.clientY > document.body.clientHeight) {
|
||||||
@ -158,15 +158,15 @@ const showSubMenu = (item: MenuButton | MenuComponent, index: number) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (menu.value) {
|
if (menuEl.value) {
|
||||||
// 将子菜单放置在按钮右侧,与按钮齐平
|
// 将子菜单放置在按钮右侧,与按钮齐平
|
||||||
let y = menu.value.offsetTop;
|
let y = menuEl.value.offsetTop;
|
||||||
if (buttons.value?.[index].$el) {
|
if (buttonRefs.value?.[index].$el) {
|
||||||
const rect = buttons.value?.[index].$el.getBoundingClientRect();
|
const rect = buttonRefs.value?.[index].$el.getBoundingClientRect();
|
||||||
y = rect.top;
|
y = rect.top;
|
||||||
}
|
}
|
||||||
subMenu.value?.show({
|
subMenuRef.value?.show({
|
||||||
clientX: menu.value.offsetLeft + menu.value.clientWidth - 2,
|
clientX: menuEl.value.offsetLeft + menuEl.value.clientWidth - 2,
|
||||||
clientY: y,
|
clientY: y,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -190,7 +190,7 @@ onBeforeUnmount(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
menu,
|
menu: menuEl,
|
||||||
menuPosition,
|
menuPosition,
|
||||||
hide,
|
hide,
|
||||||
show,
|
show,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<Teleport to="body" v-if="visible">
|
<Teleport to="body" v-if="visible">
|
||||||
<div ref="target" class="m-editor-float-box" :style="{ ...style, zIndex: curZIndex }" @mousedown="nextZIndex">
|
<div ref="target" class="m-editor-float-box" :style="{ ...style, zIndex: curZIndex }" @mousedown="nextZIndex">
|
||||||
<div ref="titleEl" class="m-editor-float-box-title">
|
<div ref="title" class="m-editor-float-box-title">
|
||||||
<slot name="title">
|
<slot name="title">
|
||||||
<span>{{ title }}</span>
|
<span>{{ title }}</span>
|
||||||
</slot>
|
</slot>
|
||||||
@ -47,8 +47,8 @@ const props = withDefaults(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const target = useTemplateRef<HTMLDivElement>('target');
|
const targetEl = useTemplateRef<HTMLDivElement>('target');
|
||||||
const titleEl = useTemplateRef<HTMLDivElement>('titleEl');
|
const titleEl = useTemplateRef<HTMLDivElement>('title');
|
||||||
|
|
||||||
const zIndex = useZIndex();
|
const zIndex = useZIndex();
|
||||||
const curZIndex = ref<number>(0);
|
const curZIndex = ref<number>(0);
|
||||||
@ -59,8 +59,8 @@ const bodyHeight = computed(() => {
|
|||||||
return height.value - titleHeight.value;
|
return height.value - titleHeight.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target.value) {
|
if (targetEl.value) {
|
||||||
return target.value.clientHeight - titleHeight.value;
|
return targetEl.value.clientHeight - titleHeight.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'auto';
|
return 'auto';
|
||||||
@ -87,7 +87,7 @@ let moveable: VanillaMoveable | null = null;
|
|||||||
const initMoveable = () => {
|
const initMoveable = () => {
|
||||||
moveable = new VanillaMoveable(globalThis.document.body, {
|
moveable = new VanillaMoveable(globalThis.document.body, {
|
||||||
className: 'm-editor-floating-box-moveable',
|
className: 'm-editor-floating-box-moveable',
|
||||||
target: target.value,
|
target: targetEl.value,
|
||||||
draggable: true,
|
draggable: true,
|
||||||
resizable: true,
|
resizable: true,
|
||||||
edge: true,
|
edge: true,
|
||||||
@ -126,7 +126,7 @@ watch(
|
|||||||
await nextTick();
|
await nextTick();
|
||||||
curZIndex.value = zIndex.nextZIndex();
|
curZIndex.value = zIndex.nextZIndex();
|
||||||
|
|
||||||
const targetRect = target.value?.getBoundingClientRect();
|
const targetRect = targetEl.value?.getBoundingClientRect();
|
||||||
if (targetRect) {
|
if (targetRect) {
|
||||||
width.value = targetRect.width;
|
width.value = targetRect.width;
|
||||||
height.value = targetRect.height;
|
height.value = targetRect.height;
|
||||||
@ -168,11 +168,11 @@ const nextZIndex = () => {
|
|||||||
curZIndex.value = zIndex.nextZIndex();
|
curZIndex.value = zIndex.nextZIndex();
|
||||||
};
|
};
|
||||||
|
|
||||||
provide('parentFloating', target);
|
provide('parentFloating', targetEl);
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
bodyHeight,
|
bodyHeight,
|
||||||
target,
|
target: targetEl,
|
||||||
titleEl,
|
titleEl,
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -18,6 +18,6 @@ const emit = defineEmits<{
|
|||||||
change: [e: OnDrag];
|
change: [e: OnDrag];
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const target = useTemplateRef<HTMLSpanElement>('target');
|
const targetEl = useTemplateRef<HTMLSpanElement>('target');
|
||||||
const { isDragging } = useGetSo(target, emit);
|
const { isDragging } = useGetSo(targetEl, emit);
|
||||||
</script>
|
</script>
|
||||||
|
@ -21,8 +21,8 @@ const props = defineProps<{
|
|||||||
|
|
||||||
const emit = defineEmits(['scroll']);
|
const emit = defineEmits(['scroll']);
|
||||||
|
|
||||||
const bar = useTemplateRef<HTMLDivElement>('bar');
|
const barEl = useTemplateRef<HTMLDivElement>('bar');
|
||||||
const thumb = useTemplateRef<HTMLDivElement>('thumb');
|
const thumbEl = useTemplateRef<HTMLDivElement>('thumb');
|
||||||
|
|
||||||
const thumbSize = computed(() => props.size * (props.size / props.scrollSize));
|
const thumbSize = computed(() => props.size * (props.size / props.scrollSize));
|
||||||
const thumbPos = computed(() => (props.pos / props.scrollSize) * props.size);
|
const thumbPos = computed(() => (props.pos / props.scrollSize) * props.size);
|
||||||
@ -35,9 +35,8 @@ const thumbStyle = computed(() => ({
|
|||||||
let gesto: Gesto;
|
let gesto: Gesto;
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (!thumb.value) return;
|
if (!thumbEl.value) return;
|
||||||
const thumbEl = thumb.value;
|
gesto = new Gesto(thumbEl.value, {
|
||||||
gesto = new Gesto(thumbEl, {
|
|
||||||
container: window,
|
container: window,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -50,12 +49,12 @@ onMounted(() => {
|
|||||||
scrollBy(getDelta(e));
|
scrollBy(getDelta(e));
|
||||||
});
|
});
|
||||||
|
|
||||||
bar.value?.addEventListener('wheel', wheelHandler, false);
|
barEl.value?.addEventListener('wheel', wheelHandler, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
if (gesto) gesto.off();
|
if (gesto) gesto.off();
|
||||||
bar.value?.removeEventListener('wheel', wheelHandler, false);
|
barEl.value?.removeEventListener('wheel', wheelHandler, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
const wheelHandler = (e: WheelEvent) => {
|
const wheelHandler = (e: WheelEvent) => {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="m-editor-scroll-viewer-container" ref="container">
|
<div class="m-editor-scroll-viewer-container" ref="container">
|
||||||
<div ref="el" :style="style">
|
<div ref="target" :style="style">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -63,8 +63,8 @@ const props = withDefaults(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const container = useTemplateRef<HTMLDivElement>('container');
|
const containerEl = useTemplateRef<HTMLDivElement>('container');
|
||||||
const el = useTemplateRef<HTMLDivElement>('el');
|
const el = useTemplateRef<HTMLDivElement>('target');
|
||||||
const style = computed(
|
const style = computed(
|
||||||
() => `
|
() => `
|
||||||
width: ${isNumber(`${props.width}`) ? `${props.width}px` : props.width};
|
width: ${isNumber(`${props.width}`) ? `${props.width}px` : props.width};
|
||||||
@ -80,9 +80,9 @@ const scrollHeight = ref(0);
|
|||||||
let scrollViewer: ScrollViewer;
|
let scrollViewer: ScrollViewer;
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (!container.value || !el.value) return;
|
if (!containerEl.value || !el.value) return;
|
||||||
scrollViewer = new ScrollViewer({
|
scrollViewer = new ScrollViewer({
|
||||||
container: container.value,
|
container: containerEl.value,
|
||||||
target: el.value,
|
target: el.value,
|
||||||
zoom: props.zoom,
|
zoom: props.zoom,
|
||||||
correctionScrollSize: props.correctionScrollSize,
|
correctionScrollSize: props.correctionScrollSize,
|
||||||
@ -123,6 +123,6 @@ const hScrollHandler = (delta: number) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
container,
|
container: containerEl,
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div ref="el" class="m-editor-layout" :style="`min-width: ${props.minCenter + props.minLeft + props.minRight}px`">
|
<div ref="target" class="m-editor-layout" :style="`min-width: ${props.minCenter + props.minLeft + props.minRight}px`">
|
||||||
<template v-if="hasLeft && $slots.left">
|
<template v-if="hasLeft && $slots.left">
|
||||||
<div class="m-editor-layout-left" :class="leftClass" :style="`width: ${left}px`">
|
<div class="m-editor-layout-left" :class="leftClass" :style="`width: ${left}px`">
|
||||||
<slot name="left"></slot>
|
<slot name="left"></slot>
|
||||||
@ -51,7 +51,7 @@ const props = withDefaults(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const el = useTemplateRef<HTMLElement>('el');
|
const el = useTemplateRef<HTMLElement>('target');
|
||||||
|
|
||||||
const hasLeft = computed(() => typeof props.left !== 'undefined');
|
const hasLeft = computed(() => typeof props.left !== 'undefined');
|
||||||
const hasRight = computed(() => typeof props.right !== 'undefined');
|
const hasRight = computed(() => typeof props.right !== 'undefined');
|
||||||
|
@ -83,12 +83,12 @@ const emit = defineEmits<{
|
|||||||
|
|
||||||
const { dataSourceService } = inject<Services>('services') || {};
|
const { dataSourceService } = inject<Services>('services') || {};
|
||||||
|
|
||||||
const autocomplete = useTemplateRef<InstanceType<typeof TMagicAutocomplete>>('autocomplete');
|
const autocompleteRef = useTemplateRef<InstanceType<typeof TMagicAutocomplete>>('autocomplete');
|
||||||
const isFocused = ref(false);
|
const isFocused = ref(false);
|
||||||
const state = ref('');
|
const state = ref('');
|
||||||
const displayState = ref<{ value: string; type: 'var' | 'text' }[]>([]);
|
const displayState = ref<{ value: string; type: 'var' | 'text' }[]>([]);
|
||||||
|
|
||||||
const input = computed<HTMLInputElement>(() => autocomplete.value?.inputRef?.input);
|
const input = computed<HTMLInputElement>(() => autocompleteRef.value?.inputRef?.input);
|
||||||
const dataSources = computed(() => dataSourceService?.get('dataSources') || []);
|
const dataSources = computed(() => dataSourceService?.get('dataSources') || []);
|
||||||
|
|
||||||
const setDisplayState = () => {
|
const setDisplayState = () => {
|
||||||
@ -112,7 +112,7 @@ const mouseupHandler = async () => {
|
|||||||
|
|
||||||
isFocused.value = true;
|
isFocused.value = true;
|
||||||
await nextTick();
|
await nextTick();
|
||||||
autocomplete.value?.focus();
|
autocompleteRef.value?.focus();
|
||||||
|
|
||||||
if (focusOffset && input.value) {
|
if (focusOffset && input.value) {
|
||||||
input.value.setSelectionRange(anchorOffset, focusOffset);
|
input.value.setSelectionRange(anchorOffset, focusOffset);
|
||||||
|
@ -51,7 +51,7 @@ const props = withDefaults(
|
|||||||
const emit = defineEmits(['change']);
|
const emit = defineEmits(['change']);
|
||||||
|
|
||||||
const codeConfig = ref<CodeBlockContent>();
|
const codeConfig = ref<CodeBlockContent>();
|
||||||
const codeBlockEditor = useTemplateRef<InstanceType<typeof CodeBlockEditor>>('codeBlockEditor');
|
const codeBlockEditorRef = useTemplateRef<InstanceType<typeof CodeBlockEditor>>('codeBlockEditor');
|
||||||
|
|
||||||
let editIndex = -1;
|
let editIndex = -1;
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ const methodColumns: ColumnConfig[] = [
|
|||||||
editIndex = index;
|
editIndex = index;
|
||||||
|
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
codeBlockEditor.value?.show();
|
codeBlockEditorRef.value?.show();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -121,7 +121,7 @@ const createCodeHandler = () => {
|
|||||||
editIndex = -1;
|
editIndex = -1;
|
||||||
|
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
codeBlockEditor.value?.show();
|
codeBlockEditorRef.value?.show();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -157,6 +157,6 @@ const submitCodeHandler = (value: CodeBlockContent, data: ContainerChangeEventDa
|
|||||||
editIndex = -1;
|
editIndex = -1;
|
||||||
codeConfig.value = void 0;
|
codeConfig.value = void 0;
|
||||||
|
|
||||||
codeBlockEditor.value?.hide();
|
codeBlockEditorRef.value?.hide();
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -10,7 +10,7 @@ import type { CodeBlockService } from '@editor/services/codeBlock';
|
|||||||
export const useCodeBlockEdit = (codeBlockService?: CodeBlockService) => {
|
export const useCodeBlockEdit = (codeBlockService?: CodeBlockService) => {
|
||||||
const codeConfig = ref<CodeBlockContent>();
|
const codeConfig = ref<CodeBlockContent>();
|
||||||
const codeId = ref<string>();
|
const codeId = ref<string>();
|
||||||
const codeBlockEditor = useTemplateRef<InstanceType<typeof CodeBlockEditor>>('codeBlockEditor');
|
const codeBlockEditorRef = useTemplateRef<InstanceType<typeof CodeBlockEditor>>('codeBlockEditor');
|
||||||
|
|
||||||
// 新增代码块
|
// 新增代码块
|
||||||
const createCodeBlock = async () => {
|
const createCodeBlock = async () => {
|
||||||
@ -29,7 +29,7 @@ export const useCodeBlockEdit = (codeBlockService?: CodeBlockService) => {
|
|||||||
|
|
||||||
await nextTick();
|
await nextTick();
|
||||||
|
|
||||||
codeBlockEditor.value?.show();
|
codeBlockEditorRef.value?.show();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 编辑代码块
|
// 编辑代码块
|
||||||
@ -54,7 +54,7 @@ export const useCodeBlockEdit = (codeBlockService?: CodeBlockService) => {
|
|||||||
codeId.value = id;
|
codeId.value = id;
|
||||||
|
|
||||||
await nextTick();
|
await nextTick();
|
||||||
codeBlockEditor.value?.show();
|
codeBlockEditorRef.value?.show();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 删除代码块
|
// 删除代码块
|
||||||
@ -67,13 +67,13 @@ export const useCodeBlockEdit = (codeBlockService?: CodeBlockService) => {
|
|||||||
|
|
||||||
await codeBlockService?.setCodeDslById(codeId.value, values);
|
await codeBlockService?.setCodeDslById(codeId.value, values);
|
||||||
|
|
||||||
codeBlockEditor.value?.hide();
|
codeBlockEditorRef.value?.hide();
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
codeId,
|
codeId,
|
||||||
codeConfig,
|
codeConfig,
|
||||||
codeBlockEditor,
|
codeBlockEditor: codeBlockEditorRef,
|
||||||
|
|
||||||
createCodeBlock,
|
createCodeBlock,
|
||||||
editCode,
|
editCode,
|
||||||
|
@ -93,7 +93,7 @@ let vsDiffEditor: monaco.editor.IStandaloneDiffEditor | null = null;
|
|||||||
|
|
||||||
const values = ref('');
|
const values = ref('');
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const codeEditor = useTemplateRef<HTMLDivElement>('codeEditor');
|
const codeEditorEl = useTemplateRef<HTMLDivElement>('codeEditor');
|
||||||
|
|
||||||
const resizeObserver = new globalThis.ResizeObserver(
|
const resizeObserver = new globalThis.ResizeObserver(
|
||||||
throttle((): void => {
|
throttle((): void => {
|
||||||
@ -122,7 +122,7 @@ const getEditorValue = () =>
|
|||||||
(props.type === 'diff' ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue()) || '';
|
(props.type === 'diff' ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue()) || '';
|
||||||
|
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
if (!codeEditor.value) return;
|
if (!codeEditorEl.value) return;
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
value: values.value,
|
value: values.value,
|
||||||
@ -132,9 +132,9 @@ const init = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (props.type === 'diff') {
|
if (props.type === 'diff') {
|
||||||
vsDiffEditor = monaco.editor.createDiffEditor(codeEditor.value, options);
|
vsDiffEditor = monaco.editor.createDiffEditor(codeEditorEl.value, options);
|
||||||
} else {
|
} else {
|
||||||
vsEditor = monaco.editor.create(codeEditor.value, options);
|
vsEditor = monaco.editor.create(codeEditorEl.value, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
setEditorValue(props.initValues, props.modifiedValues);
|
setEditorValue(props.initValues, props.modifiedValues);
|
||||||
@ -143,7 +143,7 @@ const init = async () => {
|
|||||||
|
|
||||||
emit('initd', vsEditor);
|
emit('initd', vsEditor);
|
||||||
|
|
||||||
codeEditor.value.addEventListener('keydown', (e) => {
|
codeEditorEl.value.addEventListener('keydown', (e) => {
|
||||||
if (e.keyCode === 83 && (navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey)) {
|
if (e.keyCode === 83 && (navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey)) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
@ -163,7 +163,7 @@ const init = async () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
resizeObserver.observe(codeEditor.value);
|
resizeObserver.observe(codeEditorEl.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
@ -90,8 +90,8 @@ const DEFAULT_RIGHT_COLUMN_WIDTH = 480;
|
|||||||
const codeOptions = inject('codeOptions', {});
|
const codeOptions = inject('codeOptions', {});
|
||||||
const { editorService, uiService } = inject<Services>('services') || {};
|
const { editorService, uiService } = inject<Services>('services') || {};
|
||||||
|
|
||||||
const content = useTemplateRef<HTMLDivElement>('content');
|
const contentEl = useTemplateRef<HTMLDivElement>('content');
|
||||||
const splitView = useTemplateRef<InstanceType<typeof SplitView>>('splitView');
|
const splitViewRef = useTemplateRef<InstanceType<typeof SplitView>>('splitView');
|
||||||
|
|
||||||
const root = computed(() => editorService?.get('root'));
|
const root = computed(() => editorService?.get('root'));
|
||||||
const page = computed(() => editorService?.get('page'));
|
const page = computed(() => editorService?.get('page'));
|
||||||
@ -115,7 +115,7 @@ const columnWidth = ref<Partial<GetColumnWidth>>({
|
|||||||
});
|
});
|
||||||
|
|
||||||
watch(pageLength, () => {
|
watch(pageLength, () => {
|
||||||
splitView.value?.updateWidth();
|
splitViewRef.value?.updateWidth();
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
@ -146,8 +146,8 @@ const resizerObserver = new ResizeObserver((entries) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (content.value) {
|
if (contentEl.value) {
|
||||||
resizerObserver.observe(content.value);
|
resizerObserver.observe(contentEl.value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -179,8 +179,10 @@ const buttons = computed(() => {
|
|||||||
return data;
|
return data;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const navMenuEl = useTemplateRef<HTMLDivElement>('navMenu');
|
||||||
|
|
||||||
const resizeObserver = new ResizeObserver(() => {
|
const resizeObserver = new ResizeObserver(() => {
|
||||||
const rect = navMenu.value?.getBoundingClientRect();
|
const rect = navMenuEl.value?.getBoundingClientRect();
|
||||||
if (rect) {
|
if (rect) {
|
||||||
uiService?.set('navMenuRect', {
|
uiService?.set('navMenuRect', {
|
||||||
left: rect.left,
|
left: rect.left,
|
||||||
@ -190,10 +192,11 @@ const resizeObserver = new ResizeObserver(() => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const navMenu = useTemplateRef<HTMLDivElement>('navMenu');
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
navMenu.value && resizeObserver.observe(navMenu.value);
|
navMenuEl.value && resizeObserver.observe(navMenuEl.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
resizeObserver.disconnect();
|
resizeObserver.disconnect();
|
||||||
});
|
});
|
||||||
|
@ -144,40 +144,40 @@ const remove = (node: MPage | MPageFragment) => {
|
|||||||
editorService?.remove(node);
|
editorService?.remove(node);
|
||||||
};
|
};
|
||||||
|
|
||||||
const pageBarScrollContainer = useTemplateRef<InstanceType<typeof PageBarScrollContainer>>('pageBarScrollContainer');
|
const pageBarScrollContainerRef = useTemplateRef<InstanceType<typeof PageBarScrollContainer>>('pageBarScrollContainer');
|
||||||
const pageBarItems = useTemplateRef<HTMLDivElement[]>('pageBarItems');
|
const pageBarItemEls = useTemplateRef<HTMLDivElement[]>('pageBarItems');
|
||||||
watch(page, (page) => {
|
watch(page, (page) => {
|
||||||
if (
|
if (
|
||||||
!page ||
|
!page ||
|
||||||
!pageBarScrollContainer.value?.itemsContainerWidth ||
|
!pageBarScrollContainerRef.value?.itemsContainerWidth ||
|
||||||
!pageBarItems.value ||
|
!pageBarItemEls.value ||
|
||||||
pageBarItems.value.length < 2
|
pageBarItemEls.value.length < 2
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const firstItem = pageBarItems.value[0];
|
const firstItem = pageBarItemEls.value[0];
|
||||||
const lastItem = pageBarItems.value[pageBarItems.value.length - 1];
|
const lastItem = pageBarItemEls.value[pageBarItemEls.value.length - 1];
|
||||||
|
|
||||||
if (page.id === firstItem.dataset.pageId) {
|
if (page.id === firstItem.dataset.pageId) {
|
||||||
pageBarScrollContainer.value.scroll('start');
|
pageBarScrollContainerRef.value.scroll('start');
|
||||||
} else if (page.id === lastItem.dataset.pageId) {
|
} else if (page.id === lastItem.dataset.pageId) {
|
||||||
pageBarScrollContainer.value.scroll('end');
|
pageBarScrollContainerRef.value.scroll('end');
|
||||||
} else {
|
} else {
|
||||||
const pageItem = pageBarItems.value.find((item) => item.dataset.pageId === page.id);
|
const pageItem = pageBarItemEls.value.find((item) => item.dataset.pageId === page.id);
|
||||||
if (!pageItem) {
|
if (!pageItem) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const pageItemRect = pageItem.getBoundingClientRect();
|
const pageItemRect = pageItem.getBoundingClientRect();
|
||||||
const offsetLeft = pageItemRect.left - firstItem.getBoundingClientRect().left;
|
const offsetLeft = pageItemRect.left - firstItem.getBoundingClientRect().left;
|
||||||
const { itemsContainerWidth } = pageBarScrollContainer.value;
|
const { itemsContainerWidth } = pageBarScrollContainerRef.value;
|
||||||
|
|
||||||
const left = itemsContainerWidth - offsetLeft - pageItemRect.width;
|
const left = itemsContainerWidth - offsetLeft - pageItemRect.width;
|
||||||
|
|
||||||
const translateLeft = pageBarScrollContainer.value.getTranslateLeft();
|
const translateLeft = pageBarScrollContainerRef.value.getTranslateLeft();
|
||||||
if (offsetLeft + translateLeft < 0 || offsetLeft + pageItemRect.width > itemsContainerWidth - translateLeft) {
|
if (offsetLeft + translateLeft < 0 || offsetLeft + pageItemRect.width > itemsContainerWidth - translateLeft) {
|
||||||
pageBarScrollContainer.value.scrollTo(left);
|
pageBarScrollContainerRef.value.scrollTo(left);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -46,7 +46,7 @@ const services = inject<Services>('services');
|
|||||||
const editorService = services?.editorService;
|
const editorService = services?.editorService;
|
||||||
const uiService = services?.uiService;
|
const uiService = services?.uiService;
|
||||||
|
|
||||||
const itemsContainer = useTemplateRef<HTMLElement>('itemsContainer');
|
const itemsContainerEl = useTemplateRef<HTMLElement>('itemsContainer');
|
||||||
const canScroll = ref(false);
|
const canScroll = ref(false);
|
||||||
|
|
||||||
const showAddPageButton = computed(() => uiService?.get('showAddPageButton'));
|
const showAddPageButton = computed(() => uiService?.get('showAddPageButton'));
|
||||||
@ -54,19 +54,21 @@ const showPageListButton = computed(() => uiService?.get('showPageListButton'));
|
|||||||
|
|
||||||
const itemsContainerWidth = ref(0);
|
const itemsContainerWidth = ref(0);
|
||||||
|
|
||||||
|
const pageBarEl = useTemplateRef<HTMLDivElement>('pageBar');
|
||||||
|
|
||||||
const setCanScroll = () => {
|
const setCanScroll = () => {
|
||||||
// 减去新增、搜索、页面列表、左移、右移5个按钮的宽度
|
// 减去新增、搜索、页面列表、左移、右移5个按钮的宽度
|
||||||
// 37 = icon width 16 + padding 10 * 2 + border-right 1
|
// 37 = icon width 16 + padding 10 * 2 + border-right 1
|
||||||
itemsContainerWidth.value =
|
itemsContainerWidth.value =
|
||||||
(pageBar.value?.clientWidth || 0) -
|
(pageBarEl.value?.clientWidth || 0) -
|
||||||
37 * 2 -
|
37 * 2 -
|
||||||
37 -
|
37 -
|
||||||
(showAddPageButton.value ? 37 : 21) -
|
(showAddPageButton.value ? 37 : 21) -
|
||||||
(showPageListButton.value ? 37 : 0);
|
(showPageListButton.value ? 37 : 0);
|
||||||
|
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
if (itemsContainer.value) {
|
if (itemsContainerEl.value) {
|
||||||
canScroll.value = itemsContainer.value.scrollWidth - itemsContainerWidth.value > 1;
|
canScroll.value = itemsContainerEl.value.scrollWidth - itemsContainerWidth.value > 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -75,9 +77,8 @@ const resizeObserver = new ResizeObserver(() => {
|
|||||||
setCanScroll();
|
setCanScroll();
|
||||||
});
|
});
|
||||||
|
|
||||||
const pageBar = useTemplateRef<HTMLDivElement>('pageBar');
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
pageBar.value && resizeObserver.observe(pageBar.value);
|
pageBarEl.value && resizeObserver.observe(pageBarEl.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
@ -87,9 +88,9 @@ onBeforeUnmount(() => {
|
|||||||
let translateLeft = 0;
|
let translateLeft = 0;
|
||||||
|
|
||||||
const scroll = (type: 'left' | 'right' | 'start' | 'end') => {
|
const scroll = (type: 'left' | 'right' | 'start' | 'end') => {
|
||||||
if (!itemsContainer.value || !canScroll.value) return;
|
if (!itemsContainerEl.value || !canScroll.value) return;
|
||||||
|
|
||||||
const maxScrollLeft = itemsContainer.value.scrollWidth - itemsContainerWidth.value;
|
const maxScrollLeft = itemsContainerEl.value.scrollWidth - itemsContainerWidth.value;
|
||||||
|
|
||||||
if (type === 'left') {
|
if (type === 'left') {
|
||||||
scrollTo(translateLeft + 200);
|
scrollTo(translateLeft + 200);
|
||||||
@ -103,8 +104,8 @@ const scroll = (type: 'left' | 'right' | 'start' | 'end') => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const scrollTo = (value: number) => {
|
const scrollTo = (value: number) => {
|
||||||
if (!itemsContainer.value || !canScroll.value) return;
|
if (!itemsContainerEl.value || !canScroll.value) return;
|
||||||
const maxScrollLeft = itemsContainer.value.scrollWidth - itemsContainerWidth.value;
|
const maxScrollLeft = itemsContainerEl.value.scrollWidth - itemsContainerWidth.value;
|
||||||
|
|
||||||
if (value >= 0) {
|
if (value >= 0) {
|
||||||
value = 0;
|
value = 0;
|
||||||
@ -116,7 +117,7 @@ const scrollTo = (value: number) => {
|
|||||||
|
|
||||||
translateLeft = value;
|
translateLeft = value;
|
||||||
|
|
||||||
itemsContainer.value.style.transform = `translate(${translateLeft}px, 0px)`;
|
itemsContainerEl.value.style.transform = `translate(${translateLeft}px, 0px)`;
|
||||||
};
|
};
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
@ -88,12 +88,12 @@ const propsPanelSize = computed(() => services?.uiService.get('propsPanelSize')
|
|||||||
const { height: editorContentHeight } = useEditorContentHeight();
|
const { height: editorContentHeight } = useEditorContentHeight();
|
||||||
const stage = computed(() => services?.editorService.get('stage'));
|
const stage = computed(() => services?.editorService.get('stage'));
|
||||||
|
|
||||||
const configForm = useTemplateRef<InstanceType<typeof MForm>>('configForm');
|
const configFormRef = useTemplateRef<InstanceType<typeof MForm>>('configForm');
|
||||||
|
|
||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
if (configForm.value) {
|
if (configFormRef.value) {
|
||||||
configForm.value.formState.stage = stage.value;
|
configFormRef.value.formState.stage = stage.value;
|
||||||
configForm.value.formState.services = services;
|
configFormRef.value.formState.services = services;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ onMounted(() => {
|
|||||||
|
|
||||||
const submit = async (v: FormValue, eventData: ContainerChangeEventData) => {
|
const submit = async (v: FormValue, eventData: ContainerChangeEventData) => {
|
||||||
try {
|
try {
|
||||||
const values = await configForm.value?.submitForm();
|
const values = await configFormRef.value?.submitForm();
|
||||||
emit('submit', values, eventData);
|
emit('submit', values, eventData);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
emit('submit-error', e);
|
emit('submit-error', e);
|
||||||
@ -119,5 +119,5 @@ const saveCode = (values: any) => {
|
|||||||
emit('submit', props.codeValueKey ? { [props.codeValueKey]: values } : values);
|
emit('submit', props.codeValueKey ? { [props.codeValueKey]: values } : values);
|
||||||
};
|
};
|
||||||
|
|
||||||
defineExpose({ configForm, submit });
|
defineExpose({ configForm: configFormRef, submit });
|
||||||
</script>
|
</script>
|
||||||
|
@ -89,10 +89,10 @@ const editable = computed(() => codeBlockService?.getEditStatus());
|
|||||||
const { codeBlockEditor, codeConfig, editCode, deleteCode, createCodeBlock, submitCodeBlockHandler } =
|
const { codeBlockEditor, codeConfig, editCode, deleteCode, createCodeBlock, submitCodeBlockHandler } =
|
||||||
useCodeBlockEdit(codeBlockService);
|
useCodeBlockEdit(codeBlockService);
|
||||||
|
|
||||||
const codeBlockList = useTemplateRef<InstanceType<typeof CodeBlockList>>('codeBlockList');
|
const codeBlockListRef = useTemplateRef<InstanceType<typeof CodeBlockList>>('codeBlockList');
|
||||||
|
|
||||||
const filterTextChangeHandler = (val: string) => {
|
const filterTextChangeHandler = (val: string) => {
|
||||||
codeBlockList.value?.filter(val);
|
codeBlockListRef.value?.filter(val);
|
||||||
};
|
};
|
||||||
|
|
||||||
eventBus?.on('edit-code', (id: string) => {
|
eventBus?.on('edit-code', (id: string) => {
|
||||||
@ -104,7 +104,7 @@ const {
|
|||||||
menuData: contentMenuData,
|
menuData: contentMenuData,
|
||||||
contentMenuHideHandler,
|
contentMenuHideHandler,
|
||||||
} = useContentMenu((id: string) => {
|
} = useContentMenu((id: string) => {
|
||||||
codeBlockList.value?.deleteCode(id);
|
codeBlockListRef.value?.deleteCode(id);
|
||||||
});
|
});
|
||||||
const menuData = computed<(MenuButton | MenuComponent)[]>(() => props.customContentMenu(contentMenuData, 'code-block'));
|
const menuData = computed<(MenuButton | MenuComponent)[]>(() => props.customContentMenu(contentMenuData, 'code-block'));
|
||||||
</script>
|
</script>
|
||||||
|
@ -27,7 +27,7 @@ const emit = defineEmits<{
|
|||||||
}>();
|
}>();
|
||||||
|
|
||||||
const services = inject<Services>('services');
|
const services = inject<Services>('services');
|
||||||
const menu = useTemplateRef<InstanceType<typeof ContentMenu>>('menu');
|
const menuRef = useTemplateRef<InstanceType<typeof ContentMenu>>('menu');
|
||||||
const node = computed(() => services?.editorService.get('node'));
|
const node = computed(() => services?.editorService.get('node'));
|
||||||
const nodes = computed(() => services?.editorService.get('nodes'));
|
const nodes = computed(() => services?.editorService.get('nodes'));
|
||||||
const componentList = computed(() => services?.componentListService.getList() || []);
|
const componentList = computed(() => services?.componentListService.getList() || []);
|
||||||
@ -113,7 +113,7 @@ const menuData = computed<(MenuButton | MenuComponent)[]>(() =>
|
|||||||
);
|
);
|
||||||
|
|
||||||
const show = (e: MouseEvent) => {
|
const show = (e: MouseEvent) => {
|
||||||
menu.value?.show(e);
|
menuRef.value?.show(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
|
@ -87,13 +87,13 @@ defineProps<{
|
|||||||
const services = inject<Services>('services');
|
const services = inject<Services>('services');
|
||||||
const editorService = services?.editorService;
|
const editorService = services?.editorService;
|
||||||
|
|
||||||
const tree = useTemplateRef<InstanceType<typeof Tree>>('tree');
|
const treeRef = useTemplateRef<InstanceType<typeof Tree>>('tree');
|
||||||
|
|
||||||
const page = computed(() => editorService?.get('page'));
|
const page = computed(() => editorService?.get('page'));
|
||||||
const nodeData = computed<TreeNodeData[]>(() => (!page.value ? [] : [page.value]));
|
const nodeData = computed<TreeNodeData[]>(() => (!page.value ? [] : [page.value]));
|
||||||
|
|
||||||
const { nodeStatusMap } = useNodeStatus(services);
|
const { nodeStatusMap } = useNodeStatus(services);
|
||||||
const { isCtrlKeyDown } = useKeybinding(services, tree);
|
const { isCtrlKeyDown } = useKeybinding(services, treeRef);
|
||||||
|
|
||||||
const filterNodeMethod = (v: string, data: MNode): boolean => {
|
const filterNodeMethod = (v: string, data: MNode): boolean => {
|
||||||
let name = '';
|
let name = '';
|
||||||
@ -121,10 +121,11 @@ const collapseAllHandler = () => {
|
|||||||
|
|
||||||
const { handleDragStart, handleDragEnd, handleDragLeave, handleDragOver } = useDrag(services);
|
const { handleDragStart, handleDragEnd, handleDragLeave, handleDragOver } = useDrag(services);
|
||||||
|
|
||||||
|
// 右键菜单
|
||||||
|
const menuRef = useTemplateRef<InstanceType<typeof LayerMenu>>('menu');
|
||||||
const {
|
const {
|
||||||
menu,
|
|
||||||
nodeClickHandler,
|
nodeClickHandler,
|
||||||
nodeContentMenuHandler,
|
nodeContentMenuHandler,
|
||||||
highlightHandler: mouseenterHandler,
|
highlightHandler: mouseenterHandler,
|
||||||
} = useClick(services, isCtrlKeyDown, nodeStatusMap);
|
} = useClick(services, isCtrlKeyDown, nodeStatusMap, menuRef);
|
||||||
</script>
|
</script>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { computed, type ComputedRef, nextTick, type Ref, useTemplateRef } from 'vue';
|
import { computed, type ComputedRef, nextTick, type Ref, type ShallowRef } from 'vue';
|
||||||
import { throttle } from 'lodash-es';
|
import { throttle } from 'lodash-es';
|
||||||
|
|
||||||
import { Id, MNode } from '@tmagic/core';
|
import { Id, MNode } from '@tmagic/core';
|
||||||
@ -13,6 +13,7 @@ export const useClick = (
|
|||||||
services: Services | undefined,
|
services: Services | undefined,
|
||||||
isCtrlKeyDown: Ref<boolean>,
|
isCtrlKeyDown: Ref<boolean>,
|
||||||
nodeStatusMap: ComputedRef<Map<Id, LayerNodeStatus> | undefined>,
|
nodeStatusMap: ComputedRef<Map<Id, LayerNodeStatus> | undefined>,
|
||||||
|
menuRef: ShallowRef<InstanceType<typeof LayerMenu> | null>,
|
||||||
) => {
|
) => {
|
||||||
const isMultiSelect = computed(() => isCtrlKeyDown.value && !services?.editorService.get('disabledMultiSelect'));
|
const isMultiSelect = computed(() => isCtrlKeyDown.value && !services?.editorService.get('disabledMultiSelect'));
|
||||||
|
|
||||||
@ -98,11 +99,8 @@ export const useClick = (
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// 右键菜单
|
|
||||||
const menu = useTemplateRef<InstanceType<typeof LayerMenu>>('menu');
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
menu,
|
menuRef,
|
||||||
|
|
||||||
nodeClickHandler,
|
nodeClickHandler,
|
||||||
|
|
||||||
@ -114,7 +112,7 @@ export const useClick = (
|
|||||||
nodeClickHandler(event, data);
|
nodeClickHandler(event, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.value?.show(event);
|
menuRef.value?.show(event);
|
||||||
},
|
},
|
||||||
|
|
||||||
highlightHandler,
|
highlightHandler,
|
||||||
|
@ -39,8 +39,8 @@ const editorService = services?.editorService;
|
|||||||
|
|
||||||
const visible = ref(false);
|
const visible = ref(false);
|
||||||
const buttonVisible = ref(false);
|
const buttonVisible = ref(false);
|
||||||
const button = useTemplateRef<HTMLDivElement>('button');
|
const buttonEl = useTemplateRef<HTMLDivElement>('button');
|
||||||
const box = useTemplateRef<InstanceType<typeof FloatingBox>>('box');
|
const boxRef = useTemplateRef<InstanceType<typeof FloatingBox>>('box');
|
||||||
|
|
||||||
const stage = computed(() => editorService?.get('stage'));
|
const stage = computed(() => editorService?.get('stage'));
|
||||||
const page = computed(() => editorService?.get('page'));
|
const page = computed(() => editorService?.get('page'));
|
||||||
@ -99,14 +99,14 @@ const menuPosition = ref({
|
|||||||
});
|
});
|
||||||
|
|
||||||
watch(visible, async (visible) => {
|
watch(visible, async (visible) => {
|
||||||
if (!button.value || !visible) {
|
if (!buttonEl.value || !visible) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await nextTick();
|
await nextTick();
|
||||||
|
|
||||||
const rect = button.value.getBoundingClientRect();
|
const rect = buttonEl.value.getBoundingClientRect();
|
||||||
const height = box.value?.target?.clientHeight || 0;
|
const height = boxRef.value?.target?.clientHeight || 0;
|
||||||
|
|
||||||
menuPosition.value = {
|
menuPosition.value = {
|
||||||
left: rect.left + rect.width + 5,
|
left: rect.left + rect.width + 5,
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
width: 60,
|
width: 60,
|
||||||
height: 50,
|
height: 50,
|
||||||
}"
|
}"
|
||||||
@click="stageWrap?.container?.focus()"
|
@click="stageWrapRef?.container?.focus()"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="m-editor-stage-container"
|
class="m-editor-stage-container"
|
||||||
@ -95,9 +95,9 @@ const services = inject<Services>('services');
|
|||||||
|
|
||||||
const stageLoading = computed(() => services?.editorService.get('stageLoading') || false);
|
const stageLoading = computed(() => services?.editorService.get('stageLoading') || false);
|
||||||
|
|
||||||
const stageWrap = useTemplateRef<InstanceType<typeof ScrollViewer>>('stageWrap');
|
const stageWrapRef = useTemplateRef<InstanceType<typeof ScrollViewer>>('stageWrap');
|
||||||
const stageContainer = useTemplateRef<HTMLDivElement>('stageContainer');
|
const stageContainerEl = useTemplateRef<HTMLDivElement>('stageContainer');
|
||||||
const menu = useTemplateRef<InstanceType<typeof ViewerMenu>>('menu');
|
const menuRef = useTemplateRef<InstanceType<typeof ViewerMenu>>('menu');
|
||||||
|
|
||||||
const nodes = computed(() => services?.editorService.get('nodes') || []);
|
const nodes = computed(() => services?.editorService.get('nodes') || []);
|
||||||
const isMultiSelect = computed(() => nodes.value.length > 1);
|
const isMultiSelect = computed(() => nodes.value.length > 1);
|
||||||
@ -111,18 +111,18 @@ const node = computed(() => services?.editorService.get('node'));
|
|||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
if (stage || !page.value) return;
|
if (stage || !page.value) return;
|
||||||
|
|
||||||
if (!stageContainer.value) return;
|
if (!stageContainerEl.value) return;
|
||||||
if (!(props.stageOptions?.runtimeUrl || props.stageOptions?.render) || !root.value) return;
|
if (!(props.stageOptions?.runtimeUrl || props.stageOptions?.render) || !root.value) return;
|
||||||
|
|
||||||
stage = useStage(props.stageOptions);
|
stage = useStage(props.stageOptions);
|
||||||
|
|
||||||
stage.on('select', () => {
|
stage.on('select', () => {
|
||||||
stageWrap.value?.container?.focus();
|
stageWrapRef.value?.container?.focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
services?.editorService.set('stage', markRaw(stage));
|
services?.editorService.set('stage', markRaw(stage));
|
||||||
|
|
||||||
stage.mount(stageContainer.value);
|
stage.mount(stageContainerEl.value);
|
||||||
|
|
||||||
if (!node.value?.id) {
|
if (!node.value?.id) {
|
||||||
return;
|
return;
|
||||||
@ -188,9 +188,9 @@ const resizeObserver = new ResizeObserver((entries) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (stageWrap.value?.container) {
|
if (stageWrapRef.value?.container) {
|
||||||
resizeObserver.observe(stageWrap.value.container);
|
resizeObserver.observe(stageWrapRef.value.container);
|
||||||
services?.keybindingService.registerEl(KeyBindingContainerKey.STAGE, stageWrap.value.container);
|
services?.keybindingService.registerEl(KeyBindingContainerKey.STAGE, stageWrapRef.value.container);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -206,7 +206,7 @@ const parseDSL = getEditorConfig('parseDSL');
|
|||||||
|
|
||||||
const contextmenuHandler = (e: MouseEvent) => {
|
const contextmenuHandler = (e: MouseEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
menu.value?.show(e);
|
menuRef.value?.show(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
const dragoverHandler = (e: DragEvent) => {
|
const dragoverHandler = (e: DragEvent) => {
|
||||||
@ -239,10 +239,10 @@ const dropHandler = async (e: DragEvent) => {
|
|||||||
parent = services?.editorService.getNodeById(parentId, false) as MContainer;
|
parent = services?.editorService.getNodeById(parentId, false) as MContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent && stageContainer.value && stage) {
|
if (parent && stageContainerEl.value && stage) {
|
||||||
const layout = await services?.editorService.getLayout(parent);
|
const layout = await services?.editorService.getLayout(parent);
|
||||||
|
|
||||||
const containerRect = stageContainer.value.getBoundingClientRect();
|
const containerRect = stageContainerEl.value.getBoundingClientRect();
|
||||||
const { scrollTop, scrollLeft } = stage.mask!;
|
const { scrollTop, scrollLeft } = stage.mask!;
|
||||||
const { style = {} } = config.data;
|
const { style = {} } = config.data;
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ const services = inject<Services>('services');
|
|||||||
|
|
||||||
const stageOptions = inject<StageOptions>('stageOptions');
|
const stageOptions = inject<StageOptions>('stageOptions');
|
||||||
|
|
||||||
const stageOverlay = useTemplateRef<HTMLDivElement>('stageOverlay');
|
const stageOverlayEl = useTemplateRef<HTMLDivElement>('stageOverlay');
|
||||||
|
|
||||||
const stageOverlayVisible = computed(() => services?.stageOverlayService.get('stageOverlayVisible'));
|
const stageOverlayVisible = computed(() => services?.stageOverlayService.get('stageOverlayVisible'));
|
||||||
const wrapWidth = computed(() => services?.stageOverlayService.get('wrapWidth') || 0);
|
const wrapWidth = computed(() => services?.stageOverlayService.get('wrapWidth') || 0);
|
||||||
@ -42,7 +42,7 @@ watch(stage, (stage) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(stageOverlay, (stageOverlay) => {
|
watch(stageOverlayEl, (stageOverlay) => {
|
||||||
if (!services) return;
|
if (!services) return;
|
||||||
|
|
||||||
const subStage = services.stageOverlayService.createStage(stageOptions);
|
const subStage = services.stageOverlayService.createStage(stageOptions);
|
||||||
|
@ -31,7 +31,7 @@ const props = withDefaults(
|
|||||||
|
|
||||||
const services = inject<Services>('services');
|
const services = inject<Services>('services');
|
||||||
const editorService = services?.editorService;
|
const editorService = services?.editorService;
|
||||||
const menu = useTemplateRef<InstanceType<typeof ContentMenu>>('menu');
|
const menuRef = useTemplateRef<InstanceType<typeof ContentMenu>>('menu');
|
||||||
const canCenter = ref(false);
|
const canCenter = ref(false);
|
||||||
|
|
||||||
const node = computed(() => editorService?.get('node'));
|
const node = computed(() => editorService?.get('node'));
|
||||||
@ -52,7 +52,7 @@ const menuData = computed<(MenuButton | MenuComponent)[]>(() =>
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
useCopyMenu(),
|
useCopyMenu(),
|
||||||
usePasteMenu(menu),
|
usePasteMenu(menuRef),
|
||||||
{
|
{
|
||||||
type: 'divider',
|
type: 'divider',
|
||||||
direction: 'horizontal',
|
direction: 'horizontal',
|
||||||
@ -136,7 +136,7 @@ watch(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const show = (e: MouseEvent) => {
|
const show = (e: MouseEvent) => {
|
||||||
menu.value?.show(e);
|
menuRef.value?.show(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
defineExpose({ show });
|
defineExpose({ show });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user