@arronqzy/vue-view 0.1.24 → 0.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -11
- package/package.json +7 -7
- package/src/index.ts +25 -1
- package/src/panel/VueViewOnlinePreview.vue +25 -0
- package/src/panel/VueViewPanel.vue +53 -2
- package/src/panel/hooks/useWorkspaceProjects.ts +209 -67
- package/src/panel/library/abuilder-storage.ts +101 -3
- package/src/panel/library/abuilder-view-handle.ts +100 -0
- package/src/panel/library/capture-preview-snapshot.ts +800 -0
- package/src/panel/library/event-subscription.ts +70 -5
- package/src/panel/library/preview-snapshot.ts +252 -0
- package/src/panel/library/workspace-project-sync.ts +7 -1
- package/src/panel/library/workspace-storage.ts +58 -4
|
@@ -1,10 +1,22 @@
|
|
|
1
|
+
import { normalizeAppNameSpace } from "@arronqzy/blueprint-dsl";
|
|
1
2
|
import {
|
|
2
3
|
clearAllExecutionRunRecords,
|
|
3
|
-
clearApiCollections,
|
|
4
|
+
clearApiCollections as clearApiCollectionsRaw,
|
|
4
5
|
clearBlueprintLibrary as clearBlueprintLibraryRecords,
|
|
6
|
+
deleteApiCollection as deleteApiCollectionRaw,
|
|
5
7
|
deleteBlueprintLibraryRecord as deleteBlueprintLibraryRecordRaw,
|
|
8
|
+
putApiCollection as putApiCollectionRaw,
|
|
9
|
+
putBlueprintLibraryRecord as putBlueprintLibraryRecordRaw,
|
|
10
|
+
putExecutionRunRecord as putExecutionRunRecordRaw,
|
|
11
|
+
upsertApiCollectionFromJson as upsertApiCollectionFromJsonRaw,
|
|
12
|
+
type BlueprintLibraryRecord,
|
|
13
|
+
type ExecutionRunRecord,
|
|
14
|
+
type UpsertApiCollectionInput,
|
|
15
|
+
type UpsertApiCollectionResult,
|
|
6
16
|
} from "@arronqzy/vue-blueprint";
|
|
17
|
+
import type { ApiCollectionRecord } from "@arronqzy/blueprint-dsl";
|
|
7
18
|
import { broadcastBlueprintLibraryChanged } from "./blueprint-library-sync";
|
|
19
|
+
import { AbuilderEvents, emitAbuilderEvent } from "./event-subscription";
|
|
8
20
|
import { clearWorkspaceProjects } from "./workspace-storage";
|
|
9
21
|
|
|
10
22
|
export {
|
|
@@ -19,17 +31,36 @@ export {
|
|
|
19
31
|
readExecutionLogSettings,
|
|
20
32
|
writeExecutionLogSettings,
|
|
21
33
|
listApiCollectionRecords,
|
|
22
|
-
deleteApiCollection,
|
|
23
|
-
clearApiCollections,
|
|
24
34
|
} from "@arronqzy/vue-blueprint";
|
|
25
35
|
export type {
|
|
26
36
|
BlueprintLibraryListItem,
|
|
27
37
|
BlueprintLibraryRecord,
|
|
28
38
|
ExecutionRunRecord,
|
|
29
39
|
ExecutionLogSettings,
|
|
40
|
+
UpsertApiCollectionInput,
|
|
41
|
+
UpsertApiCollectionResult,
|
|
30
42
|
} from "@arronqzy/vue-blueprint";
|
|
31
43
|
export type { ApiCollectionRecord } from "@arronqzy/blueprint-dsl";
|
|
32
44
|
|
|
45
|
+
function resolvedNameSpace(nameSpace?: string | null): string | null {
|
|
46
|
+
return normalizeAppNameSpace(nameSpace) || null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 写入 / 覆盖蓝图库记录;已挂载的编辑器会刷新蓝图库列表 */
|
|
50
|
+
export async function putBlueprintLibraryRecord(
|
|
51
|
+
record: BlueprintLibraryRecord,
|
|
52
|
+
nameSpace?: string | null
|
|
53
|
+
): Promise<BlueprintLibraryRecord> {
|
|
54
|
+
const saved = await putBlueprintLibraryRecordRaw(record, nameSpace);
|
|
55
|
+
broadcastBlueprintLibraryChanged(nameSpace);
|
|
56
|
+
emitAbuilderEvent(AbuilderEvents.blueprintLibraryChanged, {
|
|
57
|
+
nameSpace: resolvedNameSpace(nameSpace),
|
|
58
|
+
action: "put",
|
|
59
|
+
ids: [saved.id],
|
|
60
|
+
});
|
|
61
|
+
return saved;
|
|
62
|
+
}
|
|
63
|
+
|
|
33
64
|
/** 删除蓝图库中的一条蓝图;已挂载的编辑器会刷新蓝图库列表 */
|
|
34
65
|
export async function deleteBlueprintLibraryRecord(
|
|
35
66
|
id: string,
|
|
@@ -37,12 +68,79 @@ export async function deleteBlueprintLibraryRecord(
|
|
|
37
68
|
): Promise<void> {
|
|
38
69
|
await deleteBlueprintLibraryRecordRaw(id, nameSpace);
|
|
39
70
|
broadcastBlueprintLibraryChanged(nameSpace);
|
|
71
|
+
emitAbuilderEvent(AbuilderEvents.blueprintLibraryChanged, {
|
|
72
|
+
nameSpace: resolvedNameSpace(nameSpace),
|
|
73
|
+
action: "delete",
|
|
74
|
+
ids: [id],
|
|
75
|
+
});
|
|
40
76
|
}
|
|
41
77
|
|
|
42
78
|
/** 清空该 nameSpace 下的蓝图库,返回删除数量;已挂载的编辑器会刷新蓝图库列表 */
|
|
43
79
|
export async function clearBlueprintLibrary(nameSpace?: string | null): Promise<number> {
|
|
44
80
|
const count = await clearBlueprintLibraryRecords(nameSpace);
|
|
45
81
|
broadcastBlueprintLibraryChanged(nameSpace);
|
|
82
|
+
emitAbuilderEvent(AbuilderEvents.blueprintLibraryChanged, {
|
|
83
|
+
nameSpace: resolvedNameSpace(nameSpace),
|
|
84
|
+
action: "clear",
|
|
85
|
+
});
|
|
86
|
+
return count;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** 写入一条蓝图执行日志 */
|
|
90
|
+
export async function putExecutionRunRecord(
|
|
91
|
+
record: ExecutionRunRecord,
|
|
92
|
+
nameSpace?: string | null
|
|
93
|
+
): Promise<ExecutionRunRecord> {
|
|
94
|
+
return putExecutionRunRecordRaw(record, nameSpace);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** 写入接口集合;persistLocal 时落 IndexedDB,并同步已挂载编辑器的内存列表 */
|
|
98
|
+
export async function putApiCollection(
|
|
99
|
+
record: ApiCollectionRecord,
|
|
100
|
+
nameSpace?: string | null
|
|
101
|
+
): Promise<ApiCollectionRecord> {
|
|
102
|
+
const saved = await putApiCollectionRaw(record, nameSpace);
|
|
103
|
+
emitAbuilderEvent(AbuilderEvents.apiCollectionChanged, {
|
|
104
|
+
nameSpace: resolvedNameSpace(nameSpace),
|
|
105
|
+
action: "put",
|
|
106
|
+
ids: [saved.id],
|
|
107
|
+
});
|
|
108
|
+
return saved;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** 从 JSON 文本 upsert 接口集合;可传 nameSpace */
|
|
112
|
+
export async function upsertApiCollectionFromJson(
|
|
113
|
+
input: UpsertApiCollectionInput
|
|
114
|
+
): Promise<UpsertApiCollectionResult> {
|
|
115
|
+
const result = await upsertApiCollectionFromJsonRaw(input);
|
|
116
|
+
if (result.ok) {
|
|
117
|
+
emitAbuilderEvent(AbuilderEvents.apiCollectionChanged, {
|
|
118
|
+
nameSpace: resolvedNameSpace(input.nameSpace),
|
|
119
|
+
action: "put",
|
|
120
|
+
ids: [result.record.id],
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export async function deleteApiCollection(
|
|
127
|
+
id: string,
|
|
128
|
+
nameSpace?: string | null
|
|
129
|
+
): Promise<void> {
|
|
130
|
+
await deleteApiCollectionRaw(id, nameSpace);
|
|
131
|
+
emitAbuilderEvent(AbuilderEvents.apiCollectionChanged, {
|
|
132
|
+
nameSpace: resolvedNameSpace(nameSpace),
|
|
133
|
+
action: "delete",
|
|
134
|
+
ids: [id],
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export async function clearApiCollections(nameSpace?: string | null): Promise<number> {
|
|
139
|
+
const count = await clearApiCollectionsRaw(nameSpace);
|
|
140
|
+
emitAbuilderEvent(AbuilderEvents.apiCollectionChanged, {
|
|
141
|
+
nameSpace: resolvedNameSpace(nameSpace),
|
|
142
|
+
action: "clear",
|
|
143
|
+
});
|
|
46
144
|
return count;
|
|
47
145
|
}
|
|
48
146
|
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { normalizeAppNameSpace } from "@arronqzy/blueprint-dsl";
|
|
2
|
+
import type { WorkspaceProjectRecord } from "./workspace-project-db";
|
|
3
|
+
|
|
4
|
+
/** 已挂载编辑面板的命令式句柄(也可通过 `ref` 拿到) */
|
|
5
|
+
export type AbuilderViewHandle = {
|
|
6
|
+
/** 当前 nameSpace */
|
|
7
|
+
getNameSpace: () => string | null;
|
|
8
|
+
/** 导出当前编辑器中的完整工作区;尚无关联 id 时返回 null */
|
|
9
|
+
getCurrentWorkspace: () => WorkspaceProjectRecord | null;
|
|
10
|
+
/** 按 id 从 IndexedDB 打开,或直接应用完整记录 */
|
|
11
|
+
openWorkspace: (idOrRecord: string | WorkspaceProjectRecord) => Promise<void>;
|
|
12
|
+
/** 创建新工作区并写入 IndexedDB,发出 workspace:add */
|
|
13
|
+
createWorkspace: () => Promise<{ name: string; id: string }>;
|
|
14
|
+
/** 保存当前工作区到 IndexedDB,发出 workspace:sync;无 active 时等同创建 */
|
|
15
|
+
saveWorkspace: () => Promise<{ name: string; id: string }>;
|
|
16
|
+
/** 同步当前工作区到 IndexedDB,发出 workspace:sync */
|
|
17
|
+
syncWorkspace: () => Promise<string>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const handles = new Set<AbuilderViewHandle>();
|
|
21
|
+
|
|
22
|
+
export function registerAbuilderViewHandle(handle: AbuilderViewHandle): () => void {
|
|
23
|
+
handles.add(handle);
|
|
24
|
+
return () => {
|
|
25
|
+
handles.delete(handle);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function findHandle(nameSpace?: string | null): AbuilderViewHandle | null {
|
|
30
|
+
if (handles.size === 0) return null;
|
|
31
|
+
if (nameSpace === undefined) {
|
|
32
|
+
return handles.values().next().value ?? null;
|
|
33
|
+
}
|
|
34
|
+
const wanted = normalizeAppNameSpace(nameSpace);
|
|
35
|
+
for (const handle of handles) {
|
|
36
|
+
if (normalizeAppNameSpace(handle.getNameSpace()) === wanted) return handle;
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 读取当前已挂载编辑器中的工作区快照。
|
|
43
|
+
* 同页多个实例时请传入 `nameSpace`;未挂载或尚无 active 工作区时返回 null。
|
|
44
|
+
*/
|
|
45
|
+
export function getCurrentWorkspace(
|
|
46
|
+
nameSpace?: string | null
|
|
47
|
+
): WorkspaceProjectRecord | null {
|
|
48
|
+
return findHandle(nameSpace)?.getCurrentWorkspace() ?? null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 命令式打开工作区(不 remount)。
|
|
53
|
+
* 同页多个实例时请传入 `nameSpace`。
|
|
54
|
+
*/
|
|
55
|
+
export async function openWorkspace(
|
|
56
|
+
idOrRecord: string | WorkspaceProjectRecord,
|
|
57
|
+
nameSpace?: string | null
|
|
58
|
+
): Promise<void> {
|
|
59
|
+
const handle = findHandle(nameSpace);
|
|
60
|
+
if (!handle) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
"No mounted Abuilder panel. Pass initialWorkspace or mount <App> first."
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
await handle.openWorkspace(idOrRecord);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function createWorkspace(
|
|
69
|
+
nameSpace?: string | null
|
|
70
|
+
): Promise<{ name: string; id: string }> {
|
|
71
|
+
const handle = findHandle(nameSpace);
|
|
72
|
+
if (!handle) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
"No mounted Abuilder panel. Pass initialWorkspace or mount <App> first."
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
return handle.createWorkspace();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export async function saveWorkspace(
|
|
81
|
+
nameSpace?: string | null
|
|
82
|
+
): Promise<{ name: string; id: string }> {
|
|
83
|
+
const handle = findHandle(nameSpace);
|
|
84
|
+
if (!handle) {
|
|
85
|
+
throw new Error(
|
|
86
|
+
"No mounted Abuilder panel. Pass initialWorkspace or mount <App> first."
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return handle.saveWorkspace();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export async function syncWorkspace(nameSpace?: string | null): Promise<string> {
|
|
93
|
+
const handle = findHandle(nameSpace);
|
|
94
|
+
if (!handle) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
"No mounted Abuilder panel. Pass initialWorkspace or mount <App> first."
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
return handle.syncWorkspace();
|
|
100
|
+
}
|