fix: Resolve the issue of possible abnormal text generated during page creation.
This commit is contained in:
@@ -4,11 +4,11 @@ interface BridgeContext {
|
||||
loaded: boolean;
|
||||
}
|
||||
|
||||
export const bridgeContext: BridgeContext = import.meta.hot?.data.editorBridgeContext ?? {
|
||||
export const bridgeContext: BridgeContext = import.meta.hot?.data?.editorBridgeContext ?? {
|
||||
loaded: false,
|
||||
};
|
||||
|
||||
if (import.meta.hot) {
|
||||
if (import.meta.hot && import.meta.hot.data) {
|
||||
import.meta.hot.data.editorBridgeContext = bridgeContext;
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ export let editorBridge: Promise<EditorBridge> = new Promise(() => {
|
||||
|
||||
if (!import.meta.env.SSR) {
|
||||
editorBridge =
|
||||
import.meta.hot?.data.editorBridge ??
|
||||
import.meta.hot?.data?.editorBridge ??
|
||||
Promise.resolve()
|
||||
.then(() => {
|
||||
return new EditorBridge();
|
||||
@@ -181,7 +181,7 @@ if (!import.meta.env.SSR) {
|
||||
return editorBridge;
|
||||
});
|
||||
|
||||
if (import.meta.hot) {
|
||||
if (import.meta.hot && import.meta.hot.data) {
|
||||
import.meta.hot.data.editorBridge = editorBridge;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,14 +27,14 @@ export class ChatStore {
|
||||
|
||||
// 当前消息 id
|
||||
currentMessageId: WritableAtom<string | undefined> =
|
||||
import.meta.hot?.data.currentMessageId ?? atom<string | undefined>(undefined);
|
||||
import.meta.hot?.data?.currentMessageId ?? atom<string | undefined>(undefined);
|
||||
currentDescription: WritableAtom<string | undefined> =
|
||||
import.meta.hot?.data.currentDescription ?? atom<string | undefined>(undefined);
|
||||
import.meta.hot?.data?.currentDescription ?? atom<string | undefined>(undefined);
|
||||
|
||||
artifacts: Artifacts = import.meta.hot?.data.artifacts ?? map({});
|
||||
artifacts: Artifacts = import.meta.hot?.data?.artifacts ?? map({});
|
||||
artifactIdList: string[] = [];
|
||||
actionAlert: WritableAtom<ActionAlert | undefined> =
|
||||
import.meta.hot?.data.actionAlert ?? atom<ActionAlert | undefined>(undefined);
|
||||
import.meta.hot?.data?.actionAlert ?? atom<ActionAlert | undefined>(undefined);
|
||||
|
||||
// 添加对webBuilderStore和pagesStore的引用
|
||||
readonly webBuilderStore: WebBuilderStore;
|
||||
@@ -44,7 +44,7 @@ export class ChatStore {
|
||||
this.webBuilderStore = webBuilderStore;
|
||||
this.pagesStore = pagesStore;
|
||||
|
||||
if (import.meta.hot) {
|
||||
if (import.meta.hot && import.meta.hot.data) {
|
||||
import.meta.hot.data.artifacts = this.artifacts;
|
||||
import.meta.hot.data.actionAlert = this.actionAlert;
|
||||
import.meta.hot.data.currentDescription = this.currentDescription;
|
||||
|
||||
@@ -31,11 +31,11 @@ export const editorCommands = atom<EditorCommand | null>(null);
|
||||
export class EditorStore {
|
||||
private readonly pagesStore: PagesStore;
|
||||
|
||||
editorInstance: WritableAtom<Editor | null> = import.meta.hot?.data.editorInstance ?? atom<Editor | null>(null);
|
||||
editorInstance: WritableAtom<Editor | null> = import.meta.hot?.data?.editorInstance ?? atom<Editor | null>(null);
|
||||
// 编辑器中当前选中的文档。
|
||||
selectedDocument: SelectedDocument = import.meta.hot?.data.selectedPage ?? atom<string | undefined>();
|
||||
selectedDocument: SelectedDocument = import.meta.hot?.data?.selectedPage ?? atom<string | undefined>();
|
||||
// 编辑器文档数据,始终是与编辑器所保持的最新数据,但此数据不一定执行了保存。
|
||||
editorDocuments: MapStore<EditorDocuments> = import.meta.hot?.data.documents ?? map({});
|
||||
editorDocuments: MapStore<EditorDocuments> = import.meta.hot?.data?.documents ?? map({});
|
||||
// 当前编辑器文档,基于 editorDocuments 和 selectedDocument 计算而来。始终是与编辑器所保持的最新数据,但此数据不一定执行了保存。
|
||||
currentDocument = computed([this.editorDocuments, this.selectedDocument], (documents, selectedDocument) => {
|
||||
if (!selectedDocument) {
|
||||
@@ -44,15 +44,15 @@ export class EditorStore {
|
||||
return documents[selectedDocument];
|
||||
});
|
||||
// 当前编辑器未保存的页面
|
||||
unsavedDocuments: WritableAtom<Set<string>> = import.meta.hot?.data.unsavedDocuments ?? atom(new Set<string>());
|
||||
unsavedDocuments: WritableAtom<Set<string>> = import.meta.hot?.data?.unsavedDocuments ?? atom(new Set<string>());
|
||||
// 编辑器文档最后保存时间
|
||||
documentLastSaved: WritableAtom<Record<string, number>> =
|
||||
import.meta.hot?.data.documentLastSaved ?? atom<Record<string, number>>({});
|
||||
import.meta.hot?.data?.documentLastSaved ?? atom<Record<string, number>>({});
|
||||
|
||||
constructor(pagesStore: PagesStore) {
|
||||
this.pagesStore = pagesStore;
|
||||
|
||||
if (import.meta.hot) {
|
||||
if (import.meta.hot && import.meta.hot.data) {
|
||||
import.meta.hot.data.unsavedDocuments = this.unsavedDocuments;
|
||||
import.meta.hot.data.selectedDocument = this.selectedDocument;
|
||||
import.meta.hot.data.editorDocuments = this.editorDocuments;
|
||||
|
||||
@@ -33,27 +33,27 @@ export class PagesStore {
|
||||
* @note 跟踪所有自上次用户消息以来被修改的文件及其原始内容,以便模型感知这些更改。
|
||||
* 当用户发送另一条消息且所有更改都需要提交时,需要重置。
|
||||
*/
|
||||
private modifiedPages: Map<string, string> = import.meta.hot?.data.modifiedPages ?? new Map();
|
||||
private modifiedPages: Map<string, string> = import.meta.hot?.data?.modifiedPages ?? new Map();
|
||||
|
||||
/**
|
||||
* 跟踪已删除的页面,防止它们在重新加载时重新出现
|
||||
*/
|
||||
private deletedPages: Set<string> = import.meta.hot?.data.deletedPages ?? new Set();
|
||||
private deletedPages: Set<string> = import.meta.hot?.data?.deletedPages ?? new Set();
|
||||
|
||||
/**
|
||||
* 页面映射,与 AI 做交互,基于 artifacts 数据解析而来。
|
||||
* 因此,此数据表示与数据库通信的底层数据,未保存的数据将不会在此处体现。
|
||||
* 如果在编辑器中确定保存了数据,则需要实时同步进 #modifiedPages 中。
|
||||
*/
|
||||
pages: MapStore<PageMap> = import.meta.hot?.data.pages ?? map({});
|
||||
pages: MapStore<PageMap> = import.meta.hot?.data?.pages ?? map({});
|
||||
|
||||
/**
|
||||
* 页面历史记录,用于 diff 视图。
|
||||
* 每次页面保存时,会保存上一次的页面内容。
|
||||
*/
|
||||
pageHistory: MapStore<Record<string, PageHistory>> = import.meta.hot?.data.pageHistory ?? map({});
|
||||
pageHistory: MapStore<Record<string, PageHistory>> = import.meta.hot?.data?.pageHistory ?? map({});
|
||||
|
||||
activePage: ActivePage = import.meta.hot?.data.activePage ?? atom<string | undefined>();
|
||||
activePage: ActivePage = import.meta.hot?.data?.activePage ?? atom<string | undefined>();
|
||||
currentPage = computed([this.pages, this.activePage], (pages, activePage) => {
|
||||
if (!activePage) {
|
||||
return undefined;
|
||||
@@ -64,11 +64,11 @@ export class PagesStore {
|
||||
/**
|
||||
* 基于 action 的 section 映射,作为与 AI 交互的底层数据,基于 actions 数据解析而来。
|
||||
*/
|
||||
sections: MapStore<SectionMap> = import.meta.hot?.data.sections ?? map({});
|
||||
sections: MapStore<SectionMap> = import.meta.hot?.data?.sections ?? map({});
|
||||
/**
|
||||
* 当前活跃的 section。
|
||||
*/
|
||||
activeSection: ActiveSection = import.meta.hot?.data.activeSection ?? atom<string | undefined>();
|
||||
activeSection: ActiveSection = import.meta.hot?.data?.activeSection ?? atom<string | undefined>();
|
||||
|
||||
currentSection = computed([this.sections, this.activeSection], (sections, activeSection) => {
|
||||
if (!activeSection) {
|
||||
@@ -100,7 +100,7 @@ export class PagesStore {
|
||||
logger.error('Failed to load deleted paths from localStorage', error);
|
||||
}
|
||||
|
||||
if (import.meta.hot) {
|
||||
if (import.meta.hot && import.meta.hot.data) {
|
||||
// Persist our state across hot reloads
|
||||
import.meta.hot.data.pages = this.pages;
|
||||
import.meta.hot.data.modifiedPages = this.modifiedPages;
|
||||
|
||||
@@ -37,9 +37,9 @@ export class WebBuilderStore {
|
||||
readonly editorStore: EditorStore;
|
||||
|
||||
// 是否显示 webBuilder
|
||||
showWorkbench: WritableAtom<boolean> = import.meta.hot?.data.showWorkbench ?? atom(false);
|
||||
showWorkbench: WritableAtom<boolean> = import.meta.hot?.data?.showWorkbench ?? atom(false);
|
||||
// 当前 webBuilder 所在的视图
|
||||
currentView: WritableAtom<WebBuilderViewType> = import.meta.hot?.data.currentView ?? atom('code');
|
||||
currentView: WritableAtom<WebBuilderViewType> = import.meta.hot?.data?.currentView ?? atom('code');
|
||||
|
||||
constructor() {
|
||||
this.previewsStore = new PreviewsStore();
|
||||
@@ -47,7 +47,7 @@ export class WebBuilderStore {
|
||||
this.chatStore = new ChatStore(this, this.pagesStore);
|
||||
this.editorStore = new EditorStore(this.pagesStore);
|
||||
|
||||
if (import.meta.hot) {
|
||||
if (import.meta.hot && import.meta.hot.data) {
|
||||
import.meta.hot.data.showWorkbench = this.showWorkbench;
|
||||
import.meta.hot.data.currentView = this.currentView;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user