2026-04-06 22:18:55 +08:00
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { CheckOutlined, CloseOutlined, DeleteOutlined, LoadingOutlined, RedoOutlined } from "@ant-design/icons-vue";
|
|
|
|
|
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch, type CSSProperties } from "vue";
|
|
|
|
|
|
|
|
|
|
type EditorAiAssistStatus = "idle" | "generating" | "completed" | "error";
|
2026-04-25 22:41:40 +08:00
|
|
|
type EditorAiAssistBoundary = {
|
|
|
|
|
left: number;
|
|
|
|
|
top: number;
|
|
|
|
|
right: number;
|
|
|
|
|
bottom: number;
|
|
|
|
|
};
|
|
|
|
|
type EditorAiAssistPlacement = "bottom" | "top";
|
2026-04-06 22:18:55 +08:00
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
|
x: number;
|
|
|
|
|
y: number;
|
|
|
|
|
width: number;
|
2026-04-25 22:41:40 +08:00
|
|
|
boundary?: EditorAiAssistBoundary | null;
|
|
|
|
|
boundaryElement?: HTMLElement | null;
|
|
|
|
|
placement?: EditorAiAssistPlacement;
|
2026-04-06 22:18:55 +08:00
|
|
|
prompt: string;
|
|
|
|
|
status: EditorAiAssistStatus;
|
|
|
|
|
streaming: boolean;
|
|
|
|
|
hasPreview: boolean;
|
|
|
|
|
error: string;
|
|
|
|
|
title: string;
|
|
|
|
|
promptPlaceholder: string;
|
|
|
|
|
continuePlaceholder?: string;
|
|
|
|
|
loadingLabel: string;
|
|
|
|
|
errorLabel: string;
|
|
|
|
|
disclaimer: string;
|
|
|
|
|
historyLabel?: string;
|
|
|
|
|
regenerateLabel: string;
|
|
|
|
|
discardLabel: string;
|
|
|
|
|
applyLabel: string;
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
|
"update:prompt": [value: string];
|
|
|
|
|
submit: [];
|
|
|
|
|
close: [];
|
|
|
|
|
reset: [];
|
|
|
|
|
apply: [];
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
const IDLE_MAX_WIDTH = 760;
|
2026-04-25 22:41:40 +08:00
|
|
|
const PANEL_OFFSET = 16;
|
|
|
|
|
const MIN_PANEL_WIDTH = 240;
|
|
|
|
|
const RESULT_CHROME_HEIGHT = 176;
|
2026-04-06 22:18:55 +08:00
|
|
|
|
|
|
|
|
const panelRef = ref<HTMLElement | null>(null);
|
2026-04-25 22:41:40 +08:00
|
|
|
const resultContentRef = ref<HTMLElement | null>(null);
|
2026-04-06 22:18:55 +08:00
|
|
|
const promptInputRef = ref<HTMLInputElement | null>(null);
|
|
|
|
|
const frame = ref({
|
|
|
|
|
x: props.x,
|
|
|
|
|
y: props.y,
|
|
|
|
|
width: props.width,
|
2026-04-25 22:41:40 +08:00
|
|
|
maxHeight: 480,
|
|
|
|
|
resultMaxHeight: 300,
|
2026-04-06 22:18:55 +08:00
|
|
|
});
|
2026-04-25 22:41:40 +08:00
|
|
|
let resizeObserver: ResizeObserver | null = null;
|
|
|
|
|
let mutationObserver: MutationObserver | null = null;
|
|
|
|
|
let syncFrameId = 0;
|
|
|
|
|
let scrollFrameId = 0;
|
2026-04-06 22:18:55 +08:00
|
|
|
|
|
|
|
|
const promptValue = computed({
|
|
|
|
|
get: () => props.prompt,
|
|
|
|
|
set: (value: string) => {
|
|
|
|
|
emit("update:prompt", value);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const resolvedContinuePlaceholder = computed(
|
|
|
|
|
() => props.continuePlaceholder?.trim() || props.promptPlaceholder,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const panelStyle = computed<CSSProperties>(() => ({
|
|
|
|
|
left: `${frame.value.x}px`,
|
|
|
|
|
top: `${frame.value.y}px`,
|
|
|
|
|
width: `${frame.value.width}px`,
|
2026-04-25 22:41:40 +08:00
|
|
|
maxHeight: `${frame.value.maxHeight}px`,
|
|
|
|
|
"--editor-ai-assist-result-max-height": `${frame.value.resultMaxHeight}px`,
|
|
|
|
|
} as CSSProperties));
|
2026-04-06 22:18:55 +08:00
|
|
|
|
|
|
|
|
function clamp(value: number, min: number, max: number): number {
|
|
|
|
|
return Math.min(Math.max(value, min), max);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-25 22:41:40 +08:00
|
|
|
function normalizeBoundary(rawBoundary: EditorAiAssistBoundary | null | undefined): EditorAiAssistBoundary {
|
|
|
|
|
const viewportBoundary = {
|
|
|
|
|
left: 0,
|
|
|
|
|
top: 0,
|
|
|
|
|
right: window.innerWidth,
|
|
|
|
|
bottom: window.innerHeight,
|
|
|
|
|
};
|
|
|
|
|
if (!rawBoundary) {
|
|
|
|
|
return viewportBoundary;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const left = clamp(rawBoundary.left, 0, window.innerWidth);
|
|
|
|
|
const top = clamp(rawBoundary.top, 0, window.innerHeight);
|
|
|
|
|
const right = clamp(rawBoundary.right, left, window.innerWidth);
|
|
|
|
|
const bottom = clamp(rawBoundary.bottom, top, window.innerHeight);
|
|
|
|
|
|
|
|
|
|
if (right - left < 1 || bottom - top < 1) {
|
|
|
|
|
return viewportBoundary;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { left, top, right, bottom };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function resolveBoundary(): EditorAiAssistBoundary {
|
|
|
|
|
if (props.boundaryElement) {
|
|
|
|
|
const rect = props.boundaryElement.getBoundingClientRect();
|
|
|
|
|
return normalizeBoundary({
|
|
|
|
|
left: rect.left,
|
|
|
|
|
top: rect.top,
|
|
|
|
|
right: rect.right,
|
|
|
|
|
bottom: rect.bottom,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return normalizeBoundary(props.boundary);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateFrame(nextFrame: typeof frame.value): void {
|
|
|
|
|
const current = frame.value;
|
|
|
|
|
const hasChanged =
|
|
|
|
|
Math.abs(current.x - nextFrame.x) > 0.5 ||
|
|
|
|
|
Math.abs(current.y - nextFrame.y) > 0.5 ||
|
|
|
|
|
Math.abs(current.width - nextFrame.width) > 0.5 ||
|
|
|
|
|
Math.abs(current.maxHeight - nextFrame.maxHeight) > 0.5 ||
|
|
|
|
|
Math.abs(current.resultMaxHeight - nextFrame.resultMaxHeight) > 0.5;
|
|
|
|
|
|
|
|
|
|
if (hasChanged) {
|
|
|
|
|
frame.value = nextFrame;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function scrollResultContentToLatest(): void {
|
|
|
|
|
if (!(props.streaming || props.status === "generating")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (scrollFrameId) {
|
|
|
|
|
cancelAnimationFrame(scrollFrameId);
|
|
|
|
|
}
|
|
|
|
|
scrollFrameId = requestAnimationFrame(() => {
|
|
|
|
|
scrollFrameId = 0;
|
|
|
|
|
const resultContent = resultContentRef.value;
|
|
|
|
|
if (resultContent) {
|
|
|
|
|
resultContent.scrollTop = resultContent.scrollHeight;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleResultContentChanged(): void {
|
|
|
|
|
schedulePanelFrameSync();
|
|
|
|
|
scrollResultContentToLatest();
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-06 22:18:55 +08:00
|
|
|
function syncPanelFrame(): void {
|
|
|
|
|
void nextTick(() => {
|
|
|
|
|
const panel = panelRef.value;
|
|
|
|
|
if (!panel) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-25 22:41:40 +08:00
|
|
|
const boundary = resolveBoundary();
|
|
|
|
|
const availableWidth = Math.max(0, boundary.right - boundary.left - PANEL_OFFSET * 2);
|
|
|
|
|
const maxWidth = Math.max(160, availableWidth);
|
|
|
|
|
const minWidth = Math.min(MIN_PANEL_WIDTH, maxWidth);
|
2026-04-06 22:18:55 +08:00
|
|
|
const width =
|
|
|
|
|
props.status === "idle"
|
2026-04-25 22:41:40 +08:00
|
|
|
? clamp(Math.min(props.width, IDLE_MAX_WIDTH), minWidth, maxWidth)
|
|
|
|
|
: clamp(props.width, minWidth, maxWidth);
|
|
|
|
|
const placement = props.placement ?? "bottom";
|
|
|
|
|
const anchorY = clamp(props.y, boundary.top + PANEL_OFFSET, boundary.bottom - PANEL_OFFSET);
|
|
|
|
|
const availableHeight = Math.max(
|
|
|
|
|
120,
|
|
|
|
|
placement === "top"
|
|
|
|
|
? anchorY - boundary.top - PANEL_OFFSET
|
|
|
|
|
: boundary.bottom - anchorY - PANEL_OFFSET,
|
|
|
|
|
);
|
|
|
|
|
const panelHeight = Math.min(panel.offsetHeight || availableHeight, availableHeight);
|
|
|
|
|
const resultMaxHeight = Math.max(
|
|
|
|
|
48,
|
|
|
|
|
availableHeight - RESULT_CHROME_HEIGHT,
|
|
|
|
|
);
|
|
|
|
|
const panelTop = placement === "top" ? anchorY - panelHeight : anchorY;
|
|
|
|
|
|
|
|
|
|
updateFrame({
|
|
|
|
|
x: clamp(
|
|
|
|
|
props.x - width / 2,
|
|
|
|
|
boundary.left + PANEL_OFFSET,
|
|
|
|
|
Math.max(boundary.left + PANEL_OFFSET, boundary.right - width - PANEL_OFFSET),
|
|
|
|
|
),
|
|
|
|
|
y: clamp(
|
|
|
|
|
panelTop,
|
|
|
|
|
boundary.top + PANEL_OFFSET,
|
|
|
|
|
Math.max(boundary.top + PANEL_OFFSET, boundary.bottom - panelHeight - PANEL_OFFSET),
|
|
|
|
|
),
|
2026-04-06 22:18:55 +08:00
|
|
|
width,
|
2026-04-25 22:41:40 +08:00
|
|
|
maxHeight: availableHeight,
|
|
|
|
|
resultMaxHeight,
|
|
|
|
|
});
|
|
|
|
|
scrollResultContentToLatest();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function schedulePanelFrameSync(): void {
|
|
|
|
|
if (syncFrameId) {
|
|
|
|
|
cancelAnimationFrame(syncFrameId);
|
|
|
|
|
}
|
|
|
|
|
syncFrameId = requestAnimationFrame(() => {
|
|
|
|
|
syncFrameId = 0;
|
|
|
|
|
syncPanelFrame();
|
2026-04-06 22:18:55 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function focusPromptInput(): void {
|
|
|
|
|
if (props.status !== "idle") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nextTick(() => {
|
|
|
|
|
promptInputRef.value?.focus();
|
|
|
|
|
promptInputRef.value?.setSelectionRange(props.prompt.length, props.prompt.length);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleWindowResize(): void {
|
|
|
|
|
syncPanelFrame();
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-25 22:41:40 +08:00
|
|
|
function refreshResultContentObserver(): void {
|
|
|
|
|
void nextTick(() => {
|
|
|
|
|
mutationObserver?.disconnect();
|
|
|
|
|
const resultContent = resultContentRef.value;
|
|
|
|
|
if (!resultContent) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mutationObserver?.observe(resultContent, {
|
|
|
|
|
childList: true,
|
|
|
|
|
characterData: true,
|
|
|
|
|
subtree: true,
|
|
|
|
|
});
|
|
|
|
|
scrollResultContentToLatest();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-06 22:18:55 +08:00
|
|
|
watch(
|
|
|
|
|
() => ({
|
|
|
|
|
x: props.x,
|
|
|
|
|
y: props.y,
|
|
|
|
|
width: props.width,
|
|
|
|
|
status: props.status,
|
|
|
|
|
hasPreview: props.hasPreview,
|
|
|
|
|
error: props.error,
|
2026-04-25 22:41:40 +08:00
|
|
|
boundary: props.boundary,
|
|
|
|
|
boundaryElement: props.boundaryElement,
|
|
|
|
|
placement: props.placement,
|
2026-04-06 22:18:55 +08:00
|
|
|
}),
|
|
|
|
|
() => {
|
|
|
|
|
syncPanelFrame();
|
2026-04-25 22:41:40 +08:00
|
|
|
refreshResultContentObserver();
|
2026-04-06 22:18:55 +08:00
|
|
|
focusPromptInput();
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
immediate: true,
|
|
|
|
|
flush: "post",
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
window.addEventListener("resize", handleWindowResize);
|
2026-04-25 22:41:40 +08:00
|
|
|
mutationObserver = new MutationObserver(handleResultContentChanged);
|
|
|
|
|
if ("ResizeObserver" in window) {
|
|
|
|
|
resizeObserver = new ResizeObserver(schedulePanelFrameSync);
|
|
|
|
|
if (panelRef.value) {
|
|
|
|
|
resizeObserver.observe(panelRef.value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
refreshResultContentObserver();
|
2026-04-06 22:18:55 +08:00
|
|
|
syncPanelFrame();
|
|
|
|
|
focusPromptInput();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
|
window.removeEventListener("resize", handleWindowResize);
|
2026-04-25 22:41:40 +08:00
|
|
|
mutationObserver?.disconnect();
|
|
|
|
|
mutationObserver = null;
|
|
|
|
|
resizeObserver?.disconnect();
|
|
|
|
|
resizeObserver = null;
|
|
|
|
|
if (syncFrameId) {
|
|
|
|
|
cancelAnimationFrame(syncFrameId);
|
|
|
|
|
syncFrameId = 0;
|
|
|
|
|
}
|
|
|
|
|
if (scrollFrameId) {
|
|
|
|
|
cancelAnimationFrame(scrollFrameId);
|
|
|
|
|
scrollFrameId = 0;
|
|
|
|
|
}
|
2026-04-06 22:18:55 +08:00
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<Teleport to="body">
|
|
|
|
|
<div
|
|
|
|
|
ref="panelRef"
|
|
|
|
|
class="editor-ai-assist"
|
|
|
|
|
:style="panelStyle"
|
|
|
|
|
@pointerdown.stop
|
|
|
|
|
@contextmenu.prevent
|
|
|
|
|
>
|
|
|
|
|
<div class="editor-ai-assist__shell">
|
|
|
|
|
<div v-if="status === 'idle'" class="editor-ai-assist__bar">
|
|
|
|
|
<div class="editor-ai-assist__bar-icon">
|
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none">
|
|
|
|
|
<path d="M6.75 15.25L8.78 9.78L14.25 7.75L12.22 13.22L6.75 15.25Z" stroke="url(#editor-ai-assist-gradient)" stroke-width="2" stroke-linejoin="round" />
|
|
|
|
|
<path d="M14.5 4.5L15.07 6.43L17 7L15.07 7.57L14.5 9.5L13.93 7.57L12 7L13.93 6.43L14.5 4.5Z" fill="url(#editor-ai-assist-gradient)" />
|
|
|
|
|
<path d="M18 13L18.58 14.92L20.5 15.5L18.58 16.08L18 18L17.42 16.08L15.5 15.5L17.42 14.92L18 13Z" fill="url(#editor-ai-assist-gradient)" />
|
|
|
|
|
<defs>
|
|
|
|
|
<linearGradient id="editor-ai-assist-gradient" x1="4.5" y1="4.5" x2="20.5" y2="18.5" gradientUnits="userSpaceOnUse">
|
|
|
|
|
<stop stop-color="#245bdb" />
|
|
|
|
|
<stop offset="1" stop-color="#ef5da8" />
|
|
|
|
|
</linearGradient>
|
|
|
|
|
</defs>
|
|
|
|
|
</svg>
|
|
|
|
|
</div>
|
|
|
|
|
<span class="editor-ai-assist__bar-label">{{ title }}</span>
|
|
|
|
|
<input
|
|
|
|
|
ref="promptInputRef"
|
|
|
|
|
v-model="promptValue"
|
|
|
|
|
type="text"
|
|
|
|
|
class="editor-ai-assist__bar-input"
|
|
|
|
|
:placeholder="promptPlaceholder"
|
|
|
|
|
@keydown.enter.prevent="emit('submit')"
|
|
|
|
|
/>
|
|
|
|
|
<div class="editor-ai-assist__bar-actions">
|
|
|
|
|
<button type="button" class="editor-ai-assist__icon-button" @click="emit('close')">
|
|
|
|
|
<CloseOutlined />
|
|
|
|
|
</button>
|
|
|
|
|
<span class="editor-ai-assist__divider"></span>
|
|
|
|
|
<button type="button" class="editor-ai-assist__send-button" @click="emit('submit')">
|
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
|
|
|
<line x1="22" y1="2" x2="11" y2="13"></line>
|
|
|
|
|
<polygon points="22 2 15 22 11 13 2 9 22 2"></polygon>
|
|
|
|
|
</svg>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div v-else class="editor-ai-assist__result">
|
|
|
|
|
<div class="editor-ai-assist__result-box">
|
2026-04-25 22:41:40 +08:00
|
|
|
<div ref="resultContentRef" class="editor-ai-assist__result-content">
|
2026-04-06 22:18:55 +08:00
|
|
|
<slot v-if="hasPreview" name="preview"></slot>
|
|
|
|
|
<div v-else-if="streaming" class="editor-ai-assist__placeholder">
|
|
|
|
|
<LoadingOutlined />
|
|
|
|
|
<span>{{ loadingLabel }}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div v-else class="editor-ai-assist__placeholder editor-ai-assist__placeholder--error">
|
|
|
|
|
{{ error || errorLabel }}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="editor-ai-assist__result-footer">
|
|
|
|
|
<span>{{ disclaimer }}</span>
|
|
|
|
|
<span class="editor-ai-assist__result-badges">
|
|
|
|
|
<CheckOutlined />
|
|
|
|
|
<span class="editor-ai-assist__thumb">👍</span>
|
|
|
|
|
<span class="editor-ai-assist__thumb editor-ai-assist__thumb--down">👍</span>
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="editor-ai-assist__toolbar">
|
|
|
|
|
<div class="editor-ai-assist__toolbar-head">
|
|
|
|
|
<button type="button" class="editor-ai-assist__back-button" @click="emit('reset')">
|
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
|
|
|
<line x1="19" y1="12" x2="5" y2="12"></line>
|
|
|
|
|
<polyline points="12 19 5 12 12 5"></polyline>
|
|
|
|
|
</svg>
|
|
|
|
|
<span>{{ title }}</span>
|
|
|
|
|
</button>
|
|
|
|
|
<div class="editor-ai-assist__history">
|
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
|
|
|
<circle cx="12" cy="12" r="10"></circle>
|
|
|
|
|
<polyline points="12 6 12 12 16 14"></polyline>
|
|
|
|
|
</svg>
|
|
|
|
|
<span>{{ historyLabel || "1/1" }}</span>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
class="editor-ai-assist__icon-button editor-ai-assist__icon-button--close"
|
|
|
|
|
@click="emit('close')"
|
|
|
|
|
>
|
|
|
|
|
<CloseOutlined />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="editor-ai-assist__toolbar-body">
|
|
|
|
|
<div class="editor-ai-assist__continue">
|
|
|
|
|
<input
|
|
|
|
|
v-model="promptValue"
|
|
|
|
|
type="text"
|
|
|
|
|
:placeholder="resolvedContinuePlaceholder"
|
|
|
|
|
@keydown.enter.prevent="emit('submit')"
|
|
|
|
|
/>
|
|
|
|
|
<button type="button" class="editor-ai-assist__continue-send" @click="emit('submit')">
|
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
|
|
|
<line x1="22" y1="2" x2="11" y2="13"></line>
|
|
|
|
|
<polygon points="22 2 15 22 11 13 2 9 22 2"></polygon>
|
|
|
|
|
</svg>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="editor-ai-assist__toolbar-actions">
|
|
|
|
|
<button type="button" class="editor-ai-assist__toolbar-button" @click="emit('submit')">
|
|
|
|
|
<RedoOutlined />
|
|
|
|
|
<span>{{ regenerateLabel }}</span>
|
|
|
|
|
</button>
|
|
|
|
|
<button type="button" class="editor-ai-assist__toolbar-button" @click="emit('close')">
|
|
|
|
|
<DeleteOutlined />
|
|
|
|
|
<span>{{ discardLabel }}</span>
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
class="editor-ai-assist__toolbar-button editor-ai-assist__toolbar-button--primary"
|
|
|
|
|
@click="emit('apply')"
|
|
|
|
|
>
|
|
|
|
|
<span>{{ applyLabel }}</span>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Teleport>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
.editor-ai-assist {
|
|
|
|
|
position: fixed;
|
|
|
|
|
z-index: 1300;
|
|
|
|
|
max-width: min(1120px, calc(100vw - 32px));
|
2026-04-25 22:41:40 +08:00
|
|
|
/* Removed overflow: hidden to prevent shadow clipping */
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__shell {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
2026-04-25 22:41:40 +08:00
|
|
|
max-height: inherit;
|
|
|
|
|
min-height: 0;
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__bar {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 12px;
|
2026-04-25 22:41:40 +08:00
|
|
|
padding: 8px 8px 8px 16px;
|
|
|
|
|
border-radius: 16px;
|
|
|
|
|
background: rgba(255, 255, 255, 0.95);
|
|
|
|
|
backdrop-filter: blur(16px);
|
|
|
|
|
-webkit-backdrop-filter: blur(16px);
|
|
|
|
|
border: 1px solid rgba(17, 24, 39, 0.08);
|
2026-04-06 22:18:55 +08:00
|
|
|
box-shadow:
|
2026-04-25 22:41:40 +08:00
|
|
|
0 16px 48px -4px rgba(17, 24, 39, 0.12),
|
|
|
|
|
0 6px 20px -4px rgba(17, 24, 39, 0.08);
|
|
|
|
|
transition: all 0.2s ease;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__bar:focus-within {
|
|
|
|
|
border-color: rgba(37, 99, 235, 0.3);
|
|
|
|
|
box-shadow:
|
|
|
|
|
0 12px 32px -4px rgba(37, 99, 235, 0.12),
|
|
|
|
|
0 4px 16px -4px rgba(37, 99, 235, 0.06),
|
|
|
|
|
0 0 0 3px rgba(37, 99, 235, 0.1);
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__bar-icon {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
margin-right: -4px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__bar-label {
|
2026-04-25 22:41:40 +08:00
|
|
|
color: #111827;
|
|
|
|
|
font-size: 14px;
|
2026-04-06 22:18:55 +08:00
|
|
|
font-weight: 700;
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__bar-input {
|
|
|
|
|
flex: 1;
|
|
|
|
|
min-width: 280px;
|
|
|
|
|
border: none;
|
|
|
|
|
outline: none;
|
|
|
|
|
background: transparent;
|
2026-04-25 22:41:40 +08:00
|
|
|
color: #111827;
|
2026-04-06 22:18:55 +08:00
|
|
|
font-size: 14px;
|
2026-04-25 22:41:40 +08:00
|
|
|
font-weight: 500;
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__bar-input::placeholder {
|
2026-04-25 22:41:40 +08:00
|
|
|
color: #9ca3af;
|
|
|
|
|
font-weight: 400;
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__bar-actions {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
2026-04-25 22:41:40 +08:00
|
|
|
gap: 6px;
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__divider {
|
|
|
|
|
width: 1px;
|
|
|
|
|
height: 16px;
|
|
|
|
|
margin: 0 4px;
|
2026-04-25 22:41:40 +08:00
|
|
|
background: #e5e7eb;
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__icon-button {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
2026-04-25 22:41:40 +08:00
|
|
|
width: 30px;
|
|
|
|
|
height: 30px;
|
2026-04-06 22:18:55 +08:00
|
|
|
border: none;
|
2026-04-25 22:41:40 +08:00
|
|
|
border-radius: 8px;
|
2026-04-06 22:18:55 +08:00
|
|
|
background: transparent;
|
2026-04-25 22:41:40 +08:00
|
|
|
color: #6b7280;
|
2026-04-06 22:18:55 +08:00
|
|
|
cursor: pointer;
|
|
|
|
|
transition: all 0.2s ease;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__icon-button:hover {
|
2026-04-25 22:41:40 +08:00
|
|
|
background: #f3f4f6;
|
|
|
|
|
color: #111827;
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__send-button {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
width: 32px;
|
|
|
|
|
height: 32px;
|
|
|
|
|
border: none;
|
2026-04-25 22:41:40 +08:00
|
|
|
border-radius: 10px;
|
|
|
|
|
background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
|
2026-04-06 22:18:55 +08:00
|
|
|
color: #ffffff;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
transition: all 0.2s ease;
|
2026-04-25 22:41:40 +08:00
|
|
|
box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__send-button:hover {
|
2026-04-25 22:41:40 +08:00
|
|
|
background: linear-gradient(135deg, #1d4ed8 0%, #1e3a8a 100%);
|
|
|
|
|
box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
|
|
|
|
|
transform: translateY(-1px);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__send-button:active {
|
|
|
|
|
transform: translateY(0);
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__result {
|
|
|
|
|
width: 100%;
|
2026-04-25 22:41:40 +08:00
|
|
|
max-height: inherit;
|
|
|
|
|
min-height: 0;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
2026-04-06 22:18:55 +08:00
|
|
|
overflow: hidden;
|
|
|
|
|
border-radius: 16px;
|
2026-04-25 22:41:40 +08:00
|
|
|
background: rgba(255, 255, 255, 0.95);
|
|
|
|
|
backdrop-filter: blur(16px);
|
|
|
|
|
-webkit-backdrop-filter: blur(16px);
|
|
|
|
|
border: 1px solid rgba(17, 24, 39, 0.08);
|
2026-04-06 22:18:55 +08:00
|
|
|
box-shadow:
|
2026-04-25 22:41:40 +08:00
|
|
|
0 16px 48px -4px rgba(17, 24, 39, 0.12),
|
|
|
|
|
0 6px 20px -4px rgba(17, 24, 39, 0.08);
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__result-box {
|
2026-04-25 22:41:40 +08:00
|
|
|
flex: 1 1 auto;
|
|
|
|
|
display: flex;
|
|
|
|
|
min-height: 0;
|
|
|
|
|
flex-direction: column;
|
2026-04-06 22:18:55 +08:00
|
|
|
margin: 12px;
|
|
|
|
|
overflow: hidden;
|
2026-04-25 22:41:40 +08:00
|
|
|
border: 1px solid rgba(17, 24, 39, 0.06);
|
2026-04-06 22:18:55 +08:00
|
|
|
border-radius: 12px;
|
2026-04-25 22:41:40 +08:00
|
|
|
background: #f9fafb;
|
|
|
|
|
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__result-content {
|
2026-04-25 22:41:40 +08:00
|
|
|
flex: 1 1 auto;
|
|
|
|
|
min-height: min(80px, var(--editor-ai-assist-result-max-height, 80px));
|
|
|
|
|
max-height: var(--editor-ai-assist-result-max-height, 300px);
|
2026-04-06 22:18:55 +08:00
|
|
|
padding: 16px;
|
|
|
|
|
overflow-y: auto;
|
2026-04-25 22:41:40 +08:00
|
|
|
color: #111827;
|
|
|
|
|
font-size: 14px;
|
2026-04-06 22:18:55 +08:00
|
|
|
line-height: 1.6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__placeholder {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 8px;
|
2026-04-25 22:41:40 +08:00
|
|
|
color: #6b7280;
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__placeholder--error {
|
|
|
|
|
color: #ef4444;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__result-footer {
|
2026-04-25 22:41:40 +08:00
|
|
|
flex: 0 0 auto;
|
2026-04-06 22:18:55 +08:00
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
padding: 10px 16px;
|
2026-04-25 22:41:40 +08:00
|
|
|
border-top: 1px solid rgba(229, 231, 235, 0.8);
|
2026-04-06 22:18:55 +08:00
|
|
|
background: rgba(255, 255, 255, 0.5);
|
2026-04-25 22:41:40 +08:00
|
|
|
color: #9ca3af;
|
2026-04-06 22:18:55 +08:00
|
|
|
font-size: 12px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__result-badges {
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 8px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__result-badges :deep(svg) {
|
2026-04-25 22:41:40 +08:00
|
|
|
color: #10b981;
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__thumb {
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__thumb--down {
|
|
|
|
|
display: inline-block;
|
|
|
|
|
transform: scaleY(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__toolbar {
|
2026-04-25 22:41:40 +08:00
|
|
|
flex: 0 0 auto;
|
2026-04-06 22:18:55 +08:00
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
padding: 0 16px 16px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__toolbar-head {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
margin-bottom: 12px;
|
2026-04-25 22:41:40 +08:00
|
|
|
color: #6b7280;
|
2026-04-06 22:18:55 +08:00
|
|
|
font-size: 13px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__back-button {
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 4px;
|
|
|
|
|
padding: 0;
|
|
|
|
|
border: none;
|
|
|
|
|
background: transparent;
|
|
|
|
|
color: inherit;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
font-weight: 500;
|
2026-04-25 22:41:40 +08:00
|
|
|
transition: color 0.2s ease;
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__back-button:hover {
|
2026-04-25 22:41:40 +08:00
|
|
|
color: #111827;
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__history {
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 8px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__icon-button--close {
|
|
|
|
|
margin-left: 8px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__toolbar-body {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
gap: 16px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__continue {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex: 1;
|
|
|
|
|
align-items: center;
|
|
|
|
|
padding: 4px 4px 4px 16px;
|
2026-04-25 22:41:40 +08:00
|
|
|
border: 1px solid #e5e7eb;
|
|
|
|
|
border-radius: 12px;
|
|
|
|
|
background: #ffffff;
|
|
|
|
|
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.02);
|
|
|
|
|
transition: all 0.2s ease;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__continue:focus-within {
|
|
|
|
|
border-color: rgba(37, 99, 235, 0.4);
|
|
|
|
|
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.02), 0 0 0 2px rgba(37, 99, 235, 0.1);
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__continue input {
|
|
|
|
|
flex: 1;
|
|
|
|
|
border: none;
|
|
|
|
|
outline: none;
|
|
|
|
|
background: transparent;
|
2026-04-25 22:41:40 +08:00
|
|
|
color: #111827;
|
2026-04-06 22:18:55 +08:00
|
|
|
font-size: 13px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__continue-send {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
width: 28px;
|
|
|
|
|
height: 28px;
|
|
|
|
|
border: none;
|
2026-04-25 22:41:40 +08:00
|
|
|
border-radius: 8px;
|
|
|
|
|
background: #eff6ff;
|
|
|
|
|
color: #2563eb;
|
2026-04-06 22:18:55 +08:00
|
|
|
cursor: pointer;
|
2026-04-25 22:41:40 +08:00
|
|
|
transition: all 0.2s ease;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__continue-send:hover {
|
|
|
|
|
background: #dbeafe;
|
|
|
|
|
color: #1d4ed8;
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__toolbar-actions {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 8px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__toolbar-button {
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 6px;
|
|
|
|
|
padding: 6px 14px;
|
2026-04-25 22:41:40 +08:00
|
|
|
border: 1px solid rgba(17, 24, 39, 0.05);
|
2026-04-06 22:18:55 +08:00
|
|
|
border-radius: 8px;
|
2026-04-25 22:41:40 +08:00
|
|
|
background: #ffffff;
|
|
|
|
|
color: #4b5563;
|
2026-04-06 22:18:55 +08:00
|
|
|
font-size: 13px;
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
transition: all 0.2s ease;
|
2026-04-25 22:41:40 +08:00
|
|
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__toolbar-button:hover {
|
2026-04-25 22:41:40 +08:00
|
|
|
background: #f9fafb;
|
|
|
|
|
color: #111827;
|
|
|
|
|
border-color: rgba(17, 24, 39, 0.1);
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__toolbar-button--primary {
|
2026-04-25 22:41:40 +08:00
|
|
|
background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
|
|
|
|
|
border: none;
|
2026-04-06 22:18:55 +08:00
|
|
|
color: #ffffff;
|
2026-04-25 22:41:40 +08:00
|
|
|
box-shadow: 0 2px 6px rgba(37, 99, 235, 0.2);
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__toolbar-button--primary:hover {
|
2026-04-25 22:41:40 +08:00
|
|
|
background: linear-gradient(135deg, #1d4ed8 0%, #1e3a8a 100%);
|
|
|
|
|
color: #ffffff;
|
|
|
|
|
box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
|
|
|
|
|
transform: translateY(-1px);
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@media (max-width: 768px) {
|
|
|
|
|
.editor-ai-assist {
|
|
|
|
|
max-width: calc(100vw - 24px);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__bar {
|
|
|
|
|
flex-wrap: wrap;
|
2026-04-25 22:41:40 +08:00
|
|
|
border-radius: 16px;
|
2026-04-06 22:18:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__bar-input {
|
|
|
|
|
min-width: 100%;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__toolbar-body {
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
align-items: stretch;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__toolbar-actions {
|
|
|
|
|
justify-content: stretch;
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__toolbar-button {
|
|
|
|
|
justify-content: center;
|
|
|
|
|
flex: 1 1 calc(50% - 8px);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.editor-ai-assist__toolbar-button--primary {
|
|
|
|
|
flex-basis: 100%;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|