@arronqzy/vue-view 0.1.23 → 0.1.24

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 CHANGED
@@ -49,9 +49,17 @@ import {
49
49
  } from "@arronqzy/vue-view";
50
50
  ```
51
51
 
52
- 创建 / 同步发出 `workspace:add` / `workspace:sync`。`parseWorkspaceData` 的 `value` 可作 `initialWorkspace`。
52
+ 创建 / 同步发出 `workspace:add` / `workspace:sync`,删除工作区发出 `workspace:delete`(参数 `{ ids, nameSpace }`)。`parseWorkspaceData` 的 `value` 可作 `initialWorkspace`。
53
53
 
54
- 本地保存的工作区可用 `listWorkspaceProjects` / `deleteWorkspaceProject` / `clearWorkspaceProjects`(参数为 `nameSpace`)列出和清理。其余 IndexedDB 读写与 `getPreviewSnapshot` **不导出**,缩略图只在 React 包实现。
54
+ 浏览器里的本地数据可以读取和清理,最后一个参数都是 `nameSpace`:
55
+
56
+ - 工作区:`listWorkspaceProjects` / `getWorkspaceProject` / `deleteWorkspaceProject` / `clearWorkspaceProjects`
57
+ - 蓝图库:`listBlueprintLibrary` / `getBlueprintLibraryRecord` / `deleteBlueprintLibraryRecord` / `clearBlueprintLibrary`
58
+ - 蓝图执行日志:`listExecutionRunRecords` / `getExecutionRunRecord` / `deleteExecutionRunRecord` / `clearAllExecutionRunRecords` / `purgeExecutionRunsOlderThan` / `trimExecutionRunRecordsToMax`,保留策略用 `readExecutionLogSettings` / `writeExecutionLogSettings`
59
+ - 接口集合:`listApiCollectionRecords` / `deleteApiCollection` / `clearApiCollections`
60
+ - `clearAbuilderStorage`:一次清空以上四类,返回各自删除数量
61
+
62
+ 工作区、蓝图库的写入接口不导出(由编辑器自己维护)。`getPreviewSnapshot` 只在 React 包实现。
55
63
 
56
64
  ## 和 React 版的差别
57
65
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arronqzy/vue-view",
3
- "version": "0.1.23",
3
+ "version": "0.1.24",
4
4
  "description": "Vue 3 visual view editor for Abuilder (Ant Design Vue)",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -24,12 +24,12 @@
24
24
  "uuid": "^13.0.0",
25
25
  "vue": "^3.5.13",
26
26
  "@arronqzy/i18n": "0.1.17",
27
- "@arronqzy/blueprint-dsl": "1.0.17",
28
27
  "@arronqzy/rx-store": "1.0.8",
28
+ "@arronqzy/blueprint-dsl": "1.0.17",
29
29
  "@arronqzy/view-scene3d": "0.1.5",
30
30
  "@arronqzy/view-table": "0.1.8",
31
31
  "@arronqzy/vue-rx-store": "0.1.6",
32
- "@arronqzy/vue-blueprint": "0.1.17"
32
+ "@arronqzy/vue-blueprint": "0.1.18"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "vue": "^3.4.0"
package/src/index.ts CHANGED
@@ -15,10 +15,37 @@ export {
15
15
  export { createWorkspaceProjectId } from "./panel/library/workspace-project-db";
16
16
  export {
17
17
  listWorkspaceProjects,
18
+ getWorkspaceProject,
18
19
  deleteWorkspaceProject,
19
20
  clearWorkspaceProjects,
20
21
  } from "./panel/library/workspace-storage";
21
22
  export type { WorkspaceProjectListItem } from "./panel/library/workspace-storage";
23
+ export {
24
+ listBlueprintLibrary,
25
+ getBlueprintLibraryRecord,
26
+ deleteBlueprintLibraryRecord,
27
+ clearBlueprintLibrary,
28
+ listExecutionRunRecords,
29
+ getExecutionRunRecord,
30
+ deleteExecutionRunRecord,
31
+ clearAllExecutionRunRecords,
32
+ purgeExecutionRunsOlderThan,
33
+ trimExecutionRunRecordsToMax,
34
+ readExecutionLogSettings,
35
+ writeExecutionLogSettings,
36
+ listApiCollectionRecords,
37
+ deleteApiCollection,
38
+ clearApiCollections,
39
+ clearAbuilderStorage,
40
+ } from "./panel/library/abuilder-storage";
41
+ export type {
42
+ AbuilderStorageClearResult,
43
+ BlueprintLibraryListItem,
44
+ BlueprintLibraryRecord,
45
+ ExecutionRunRecord,
46
+ ExecutionLogSettings,
47
+ ApiCollectionRecord,
48
+ } from "./panel/library/abuilder-storage";
22
49
  export {
23
50
  addEventSubscription,
24
51
  AbuilderEvents,
@@ -28,6 +55,7 @@ export type {
28
55
  AbuilderEventPayloadMap,
29
56
  WorkspaceAddEventPayload,
30
57
  WorkspaceSyncEventPayload,
58
+ WorkspaceDeleteEventPayload,
31
59
  ApiCollectionUploadStartEventPayload,
32
60
  ApiCollectionUploadSuccessEventPayload,
33
61
  WorkspaceData,
@@ -53,6 +53,7 @@ import {
53
53
  } from "./hooks/useWorkspaceProjects";
54
54
  import type { WorkspaceProjectRecord } from "./library/workspace-project-db";
55
55
  import { AbuilderEvents, emitAbuilderEvent } from "./library/event-subscription";
56
+ import { subscribeBlueprintLibraryChanged } from "./library/blueprint-library-sync";
56
57
  import { type ViewportZoom } from "./viewportZoom";
57
58
  import PanelCanvas from "./components/PanelCanvas.vue";
58
59
  import ElementsLayer from "./components/ElementsLayer.vue";
@@ -424,6 +425,14 @@ onMounted(() => {
424
425
  void refreshBlueprintLibrary();
425
426
  });
426
427
 
428
+ watch(
429
+ () => props.nameSpace,
430
+ (nameSpace, _prev, onCleanup) => {
431
+ onCleanup(subscribeBlueprintLibraryChanged(() => void refreshBlueprintLibrary(), nameSpace));
432
+ },
433
+ { immediate: true }
434
+ );
435
+
427
436
  function handleWorkspaceProjectApplied(record: WorkspaceProjectRecord) {
428
437
  workspaceBlueprintRef.value = {
429
438
  document: record.blueprintDocument,
@@ -0,0 +1,70 @@
1
+ import {
2
+ clearAllExecutionRunRecords,
3
+ clearApiCollections,
4
+ clearBlueprintLibrary as clearBlueprintLibraryRecords,
5
+ deleteBlueprintLibraryRecord as deleteBlueprintLibraryRecordRaw,
6
+ } from "@arronqzy/vue-blueprint";
7
+ import { broadcastBlueprintLibraryChanged } from "./blueprint-library-sync";
8
+ import { clearWorkspaceProjects } from "./workspace-storage";
9
+
10
+ export {
11
+ listBlueprintLibrary,
12
+ getBlueprintLibraryRecord,
13
+ listExecutionRunRecords,
14
+ getExecutionRunRecord,
15
+ deleteExecutionRunRecord,
16
+ clearAllExecutionRunRecords,
17
+ purgeExecutionRunsOlderThan,
18
+ trimExecutionRunRecordsToMax,
19
+ readExecutionLogSettings,
20
+ writeExecutionLogSettings,
21
+ listApiCollectionRecords,
22
+ deleteApiCollection,
23
+ clearApiCollections,
24
+ } from "@arronqzy/vue-blueprint";
25
+ export type {
26
+ BlueprintLibraryListItem,
27
+ BlueprintLibraryRecord,
28
+ ExecutionRunRecord,
29
+ ExecutionLogSettings,
30
+ } from "@arronqzy/vue-blueprint";
31
+ export type { ApiCollectionRecord } from "@arronqzy/blueprint-dsl";
32
+
33
+ /** 删除蓝图库中的一条蓝图;已挂载的编辑器会刷新蓝图库列表 */
34
+ export async function deleteBlueprintLibraryRecord(
35
+ id: string,
36
+ nameSpace?: string | null
37
+ ): Promise<void> {
38
+ await deleteBlueprintLibraryRecordRaw(id, nameSpace);
39
+ broadcastBlueprintLibraryChanged(nameSpace);
40
+ }
41
+
42
+ /** 清空该 nameSpace 下的蓝图库,返回删除数量;已挂载的编辑器会刷新蓝图库列表 */
43
+ export async function clearBlueprintLibrary(nameSpace?: string | null): Promise<number> {
44
+ const count = await clearBlueprintLibraryRecords(nameSpace);
45
+ broadcastBlueprintLibraryChanged(nameSpace);
46
+ return count;
47
+ }
48
+
49
+ export type AbuilderStorageClearResult = {
50
+ workspaces: number;
51
+ blueprints: number;
52
+ executionRuns: number;
53
+ apiCollections: number;
54
+ };
55
+
56
+ /**
57
+ * 清空该 nameSpace 下编辑器写入浏览器的全部数据:工作区、蓝图库、执行日志、接口集合。
58
+ * 主题、字号、日志保留设置等偏好不受影响。
59
+ */
60
+ export async function clearAbuilderStorage(
61
+ nameSpace?: string | null
62
+ ): Promise<AbuilderStorageClearResult> {
63
+ const [workspaces, blueprints, executionRuns, apiCollections] = await Promise.all([
64
+ clearWorkspaceProjects(nameSpace),
65
+ clearBlueprintLibrary(nameSpace),
66
+ clearAllExecutionRunRecords(nameSpace),
67
+ clearApiCollections(nameSpace),
68
+ ]);
69
+ return { workspaces, blueprints, executionRuns, apiCollections };
70
+ }
@@ -0,0 +1,22 @@
1
+ import { appStorageKey } from "@arronqzy/blueprint-dsl";
2
+
3
+ const CHANNEL = "arronqzy-blueprint-library-changed";
4
+
5
+ export function broadcastBlueprintLibraryChanged(nameSpace?: string | null): void {
6
+ if (typeof BroadcastChannel === "undefined") return;
7
+ const channel = new BroadcastChannel(appStorageKey(CHANNEL, nameSpace));
8
+ channel.postMessage({ type: "changed" });
9
+ channel.close();
10
+ }
11
+
12
+ export function subscribeBlueprintLibraryChanged(
13
+ onChange: () => void,
14
+ nameSpace?: string | null
15
+ ): () => void {
16
+ if (typeof BroadcastChannel === "undefined") {
17
+ return () => {};
18
+ }
19
+ const channel = new BroadcastChannel(appStorageKey(CHANNEL, nameSpace));
20
+ channel.onmessage = () => onChange();
21
+ return () => channel.close();
22
+ }
@@ -5,6 +5,8 @@ export const AbuilderEvents = {
5
5
  workspaceAdd: "workspace:add",
6
6
  /** 同步工作区 */
7
7
  workspaceSync: "workspace:sync",
8
+ /** 删除工作区(界面删除,或调用 deleteWorkspaceProject / clearWorkspaceProjects) */
9
+ workspaceDelete: "workspace:delete",
8
10
  /** 开始上传接口集合 */
9
11
  apiCollectionUploadStart: "api-collection:upload-start",
10
12
  /** 上传接口集合成功 */
@@ -18,6 +20,12 @@ export type WorkspaceData = WorkspaceProjectRecord;
18
20
 
19
21
  export type WorkspaceAddEventPayload = WorkspaceData;
20
22
  export type WorkspaceSyncEventPayload = WorkspaceData;
23
+ export type WorkspaceDeleteEventPayload = {
24
+ /** 被删除的工作区 id */
25
+ ids: string[];
26
+ /** 所属 nameSpace,默认库为 null */
27
+ nameSpace: string | null;
28
+ };
21
29
 
22
30
  export type ApiCollectionUploadStartEventPayload = {
23
31
  fileNames: string[];
@@ -36,6 +44,7 @@ export type ApiCollectionUploadSuccessEventPayload = {
36
44
  export type AbuilderEventPayloadMap = {
37
45
  [AbuilderEvents.workspaceAdd]: WorkspaceAddEventPayload;
38
46
  [AbuilderEvents.workspaceSync]: WorkspaceSyncEventPayload;
47
+ [AbuilderEvents.workspaceDelete]: WorkspaceDeleteEventPayload;
39
48
  [AbuilderEvents.apiCollectionUploadStart]: ApiCollectionUploadStartEventPayload;
40
49
  [AbuilderEvents.apiCollectionUploadSuccess]: ApiCollectionUploadSuccessEventPayload;
41
50
  };
@@ -1,6 +1,8 @@
1
+ import { normalizeAppNameSpace } from "@arronqzy/blueprint-dsl";
1
2
  import {
2
3
  clearWorkspaceProjectStore,
3
4
  deleteWorkspaceProject as deleteWorkspaceProjectRecord,
5
+ getWorkspaceProject,
4
6
  listWorkspaceProjects,
5
7
  } from "./workspace-project-db";
6
8
  import {
@@ -8,8 +10,9 @@ import {
8
10
  removeWorkspacePreviewCache,
9
11
  } from "./workspace-project-cache";
10
12
  import { broadcastWorkspaceProjectsChanged } from "./workspace-project-sync";
13
+ import { AbuilderEvents, emitAbuilderEvent } from "./event-subscription";
11
14
 
12
- export { listWorkspaceProjects };
15
+ export { listWorkspaceProjects, getWorkspaceProject };
13
16
  export type { WorkspaceProjectListItem } from "./workspace-project-db";
14
17
 
15
18
  /**
@@ -23,6 +26,10 @@ export async function deleteWorkspaceProject(
23
26
  await deleteWorkspaceProjectRecord(id, nameSpace);
24
27
  removeWorkspacePreviewCache(id, nameSpace);
25
28
  broadcastWorkspaceProjectsChanged({ type: "deleted", projectIds: [id] }, nameSpace);
29
+ emitAbuilderEvent(AbuilderEvents.workspaceDelete, {
30
+ ids: [id],
31
+ nameSpace: normalizeAppNameSpace(nameSpace) || null,
32
+ });
26
33
  }
27
34
 
28
35
  /**
@@ -34,5 +41,11 @@ export async function clearWorkspaceProjects(nameSpace?: string | null): Promise
34
41
  await clearWorkspaceProjectStore(nameSpace);
35
42
  clearWorkspacePreviewCaches(nameSpace);
36
43
  broadcastWorkspaceProjectsChanged({ type: "cleared" }, nameSpace);
44
+ if (items.length > 0) {
45
+ emitAbuilderEvent(AbuilderEvents.workspaceDelete, {
46
+ ids: items.map((item) => item.id),
47
+ nameSpace: normalizeAppNameSpace(nameSpace) || null,
48
+ });
49
+ }
37
50
  return items.length;
38
51
  }