@xpert-ai/plugin-excalidraw 0.1.0
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/.xpertai-plugin/plugin.json +118 -0
- package/README.md +5 -0
- package/assets/composerIcon.svg +5 -0
- package/assets/logo.svg +8 -0
- package/dist/docs/excalidraw-agent-skill.md +32 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +153 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/constants.d.ts +24 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/constants.js +42 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/entities/excalidraw-action-log.entity.d.ts +18 -0
- package/dist/lib/entities/excalidraw-action-log.entity.d.ts.map +1 -0
- package/dist/lib/entities/excalidraw-action-log.entity.js +69 -0
- package/dist/lib/entities/excalidraw-action-log.entity.js.map +1 -0
- package/dist/lib/entities/excalidraw-drawing-version.entity.d.ts +21 -0
- package/dist/lib/entities/excalidraw-drawing-version.entity.d.ts.map +1 -0
- package/dist/lib/entities/excalidraw-drawing-version.entity.js +82 -0
- package/dist/lib/entities/excalidraw-drawing-version.entity.js.map +1 -0
- package/dist/lib/entities/excalidraw-drawing.entity.d.ts +24 -0
- package/dist/lib/entities/excalidraw-drawing.entity.d.ts.map +1 -0
- package/dist/lib/entities/excalidraw-drawing.entity.js +94 -0
- package/dist/lib/entities/excalidraw-drawing.entity.js.map +1 -0
- package/dist/lib/entities/index.d.ts +4 -0
- package/dist/lib/entities/index.d.ts.map +1 -0
- package/dist/lib/entities/index.js +4 -0
- package/dist/lib/entities/index.js.map +1 -0
- package/dist/lib/excalidraw-view.provider.d.ts +14 -0
- package/dist/lib/excalidraw-view.provider.d.ts.map +1 -0
- package/dist/lib/excalidraw-view.provider.js +423 -0
- package/dist/lib/excalidraw-view.provider.js.map +1 -0
- package/dist/lib/excalidraw.middleware.d.ts +10 -0
- package/dist/lib/excalidraw.middleware.d.ts.map +1 -0
- package/dist/lib/excalidraw.middleware.js +173 -0
- package/dist/lib/excalidraw.middleware.js.map +1 -0
- package/dist/lib/excalidraw.plugin.d.ts +8 -0
- package/dist/lib/excalidraw.plugin.d.ts.map +1 -0
- package/dist/lib/excalidraw.plugin.js +27 -0
- package/dist/lib/excalidraw.plugin.js.map +1 -0
- package/dist/lib/excalidraw.service.d.ts +169 -0
- package/dist/lib/excalidraw.service.d.ts.map +1 -0
- package/dist/lib/excalidraw.service.js +441 -0
- package/dist/lib/excalidraw.service.js.map +1 -0
- package/dist/lib/excalidraw.templates.d.ts +3 -0
- package/dist/lib/excalidraw.templates.d.ts.map +1 -0
- package/dist/lib/excalidraw.templates.js +78 -0
- package/dist/lib/excalidraw.templates.js.map +1 -0
- package/dist/lib/remote-components/excalidraw-workbench/app.css +1 -0
- package/dist/lib/remote-components/excalidraw-workbench/app.js +5105 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/i18n.d.ts +3 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/i18n.d.ts.map +1 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/i18n.js +103 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/i18n.js.map +1 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/i18n.ts +151 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/main.tsx +1411 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/react-dom-client-shim.d.ts +3 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/react-dom-client-shim.d.ts.map +1 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/react-dom-client-shim.js +4 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/react-dom-client-shim.js.map +1 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/react-dom-client-shim.ts +4 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/react-dom-shim.d.ts +11 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/react-dom-shim.d.ts.map +1 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/react-dom-shim.js +11 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/react-dom-shim.js.map +1 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/react-dom-shim.ts +11 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/react-jsx-runtime-shim.d.ts +5 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/react-jsx-runtime-shim.d.ts.map +1 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/react-jsx-runtime-shim.js +8 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/react-jsx-runtime-shim.js.map +1 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/react-jsx-runtime-shim.ts +8 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/react-shim.d.ts +36 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/react-shim.d.ts.map +1 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/react-shim.js +36 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/react-shim.js.map +1 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/react-shim.ts +36 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/runtime.d.ts +21 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/runtime.d.ts.map +1 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/runtime.js +198 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/runtime.js.map +1 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/runtime.ts +228 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/styles.d.ts +2 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/styles.d.ts.map +1 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/styles.js +324 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/styles.js.map +1 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/styles.ts +323 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/vendor.d.ts +4 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/vendor.d.ts.map +1 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/vendor.js +4 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/vendor.js.map +1 -0
- package/dist/lib/remote-components/excalidraw-workbench/src/vendor.ts +3 -0
- package/dist/lib/types.d.ts +74 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +2 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/xpert-excalidraw-assistant.yaml +129 -0
- package/package.json +87 -0
- package/skills/index/SKILL.md +46 -0
- package/skills/index/agents/xpertai.yaml +6 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IOnPluginBootstrap, IOnPluginDestroy } from '@xpert-ai/plugin-sdk';
|
|
2
|
+
import { ExcalidrawActionLog, ExcalidrawDrawing, ExcalidrawDrawingVersion } from './entities/index.js';
|
|
3
|
+
export declare const EXCALIDRAW_ENTITIES: (typeof ExcalidrawActionLog | typeof ExcalidrawDrawing | typeof ExcalidrawDrawingVersion)[];
|
|
4
|
+
export declare class ExcalidrawPlugin implements IOnPluginBootstrap, IOnPluginDestroy {
|
|
5
|
+
onPluginBootstrap(): void | Promise<void>;
|
|
6
|
+
onPluginDestroy(): void | Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=excalidraw.plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"excalidraw.plugin.d.ts","sourceRoot":"","sources":["../../src/lib/excalidraw.plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAEhF,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAKtG,eAAO,MAAM,mBAAmB,6FAAqE,CAAA;AAErG,qBAMa,gBAAiB,YAAW,kBAAkB,EAAE,gBAAgB;IAC3E,iBAAiB,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC,eAAe,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CAGxC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var ExcalidrawPlugin_1;
|
|
2
|
+
import { __decorate } from "tslib";
|
|
3
|
+
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
4
|
+
import { XpertServerPlugin } from '@xpert-ai/plugin-sdk';
|
|
5
|
+
import { ExcalidrawActionLog, ExcalidrawDrawing, ExcalidrawDrawingVersion } from './entities/index.js';
|
|
6
|
+
import { ExcalidrawMiddleware } from './excalidraw.middleware.js';
|
|
7
|
+
import { ExcalidrawService } from './excalidraw.service.js';
|
|
8
|
+
import { ExcalidrawViewProvider } from './excalidraw-view.provider.js';
|
|
9
|
+
export const EXCALIDRAW_ENTITIES = [ExcalidrawDrawing, ExcalidrawDrawingVersion, ExcalidrawActionLog];
|
|
10
|
+
let ExcalidrawPlugin = ExcalidrawPlugin_1 = class ExcalidrawPlugin {
|
|
11
|
+
onPluginBootstrap() {
|
|
12
|
+
console.log(`${ExcalidrawPlugin_1.name} is being bootstrapped...`);
|
|
13
|
+
}
|
|
14
|
+
onPluginDestroy() {
|
|
15
|
+
console.log(`${ExcalidrawPlugin_1.name} is being destroyed...`);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
ExcalidrawPlugin = ExcalidrawPlugin_1 = __decorate([
|
|
19
|
+
XpertServerPlugin({
|
|
20
|
+
imports: [TypeOrmModule.forFeature(EXCALIDRAW_ENTITIES)],
|
|
21
|
+
entities: EXCALIDRAW_ENTITIES,
|
|
22
|
+
providers: [ExcalidrawService, ExcalidrawMiddleware, ExcalidrawViewProvider],
|
|
23
|
+
exports: [ExcalidrawService]
|
|
24
|
+
})
|
|
25
|
+
], ExcalidrawPlugin);
|
|
26
|
+
export { ExcalidrawPlugin };
|
|
27
|
+
//# sourceMappingURL=excalidraw.plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"excalidraw.plugin.js","sourceRoot":"","sources":["../../src/lib/excalidraw.plugin.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AACtG,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAA;AAEtE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,iBAAiB,EAAE,wBAAwB,EAAE,mBAAmB,CAAC,CAAA;AAQ9F,IAAM,gBAAgB,wBAAtB,MAAM,gBAAgB;IAC3B,iBAAiB;QACf,OAAO,CAAC,GAAG,CAAC,GAAG,kBAAgB,CAAC,IAAI,2BAA2B,CAAC,CAAA;IAClE,CAAC;IAED,eAAe;QACb,OAAO,CAAC,GAAG,CAAC,GAAG,kBAAgB,CAAC,IAAI,wBAAwB,CAAC,CAAA;IAC/D,CAAC;CACF,CAAA;AARY,gBAAgB;IAN5B,iBAAiB,CAAC;QACjB,OAAO,EAAE,CAAC,aAAa,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC;QACxD,QAAQ,EAAE,mBAAmB;QAC7B,SAAS,EAAE,CAAC,iBAAiB,EAAE,oBAAoB,EAAE,sBAAsB,CAAC;QAC5E,OAAO,EAAE,CAAC,iBAAiB,CAAC;KAC7B,CAAC;GACW,gBAAgB,CAQ5B"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { Repository } from 'typeorm';
|
|
2
|
+
import { ExcalidrawActionLog, ExcalidrawDrawing, ExcalidrawDrawingVersion } from './entities/index.js';
|
|
3
|
+
import type { CreateExcalidrawDrawingInput, ExcalidrawScope, PatchExcalidrawSceneInput, ReportExcalidrawFailureInput, SaveExcalidrawMermaidDraftInput, SaveExcalidrawSceneVersionInput, SearchExcalidrawDrawingsInput, UpdateExcalidrawDrawingStatusInput } from './types.js';
|
|
4
|
+
export declare class ExcalidrawService {
|
|
5
|
+
private readonly drawingRepository;
|
|
6
|
+
private readonly versionRepository;
|
|
7
|
+
private readonly logRepository;
|
|
8
|
+
constructor(drawingRepository: Repository<ExcalidrawDrawing>, versionRepository: Repository<ExcalidrawDrawingVersion>, logRepository: Repository<ExcalidrawActionLog>);
|
|
9
|
+
createDrawing(scope: ExcalidrawScope, input: CreateExcalidrawDrawingInput): Promise<{
|
|
10
|
+
item: ExcalidrawDrawing;
|
|
11
|
+
currentVersion: ExcalidrawDrawingVersion;
|
|
12
|
+
versions: ExcalidrawDrawingVersion[];
|
|
13
|
+
logs: ExcalidrawActionLog[];
|
|
14
|
+
total: number;
|
|
15
|
+
summary: {
|
|
16
|
+
versionCount: number;
|
|
17
|
+
currentVersionNumber: number;
|
|
18
|
+
hasMermaidDraft: boolean;
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
21
|
+
saveSceneVersion(scope: ExcalidrawScope, input: SaveExcalidrawSceneVersionInput): Promise<{
|
|
22
|
+
success: boolean;
|
|
23
|
+
message: string;
|
|
24
|
+
drawing: {
|
|
25
|
+
item: ExcalidrawDrawing;
|
|
26
|
+
currentVersion: ExcalidrawDrawingVersion;
|
|
27
|
+
versions: ExcalidrawDrawingVersion[];
|
|
28
|
+
logs: ExcalidrawActionLog[];
|
|
29
|
+
total: number;
|
|
30
|
+
summary: {
|
|
31
|
+
versionCount: number;
|
|
32
|
+
currentVersionNumber: number;
|
|
33
|
+
hasMermaidDraft: boolean;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
version: ExcalidrawDrawingVersion;
|
|
37
|
+
}>;
|
|
38
|
+
patchScene(scope: ExcalidrawScope, input: PatchExcalidrawSceneInput): Promise<{
|
|
39
|
+
success: boolean;
|
|
40
|
+
message: string;
|
|
41
|
+
drawing: {
|
|
42
|
+
item: ExcalidrawDrawing;
|
|
43
|
+
currentVersion: ExcalidrawDrawingVersion;
|
|
44
|
+
versions: ExcalidrawDrawingVersion[];
|
|
45
|
+
logs: ExcalidrawActionLog[];
|
|
46
|
+
total: number;
|
|
47
|
+
summary: {
|
|
48
|
+
versionCount: number;
|
|
49
|
+
currentVersionNumber: number;
|
|
50
|
+
hasMermaidDraft: boolean;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
version: ExcalidrawDrawingVersion;
|
|
54
|
+
}>;
|
|
55
|
+
saveMermaidDraft(scope: ExcalidrawScope, input: SaveExcalidrawMermaidDraftInput): Promise<{
|
|
56
|
+
success: boolean;
|
|
57
|
+
message: string;
|
|
58
|
+
drawing: {
|
|
59
|
+
item: ExcalidrawDrawing;
|
|
60
|
+
currentVersion: ExcalidrawDrawingVersion;
|
|
61
|
+
versions: ExcalidrawDrawingVersion[];
|
|
62
|
+
logs: ExcalidrawActionLog[];
|
|
63
|
+
total: number;
|
|
64
|
+
summary: {
|
|
65
|
+
versionCount: number;
|
|
66
|
+
currentVersionNumber: number;
|
|
67
|
+
hasMermaidDraft: boolean;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
version: ExcalidrawDrawingVersion;
|
|
71
|
+
}>;
|
|
72
|
+
searchDrawings(scope: ExcalidrawScope, query?: SearchExcalidrawDrawingsInput): Promise<{
|
|
73
|
+
items: ExcalidrawDrawing[];
|
|
74
|
+
total: number;
|
|
75
|
+
page: number;
|
|
76
|
+
pageSize: number;
|
|
77
|
+
search: string;
|
|
78
|
+
}>;
|
|
79
|
+
getDrawing(scope: ExcalidrawScope, drawingId: string): Promise<{
|
|
80
|
+
item: ExcalidrawDrawing;
|
|
81
|
+
currentVersion: ExcalidrawDrawingVersion;
|
|
82
|
+
versions: ExcalidrawDrawingVersion[];
|
|
83
|
+
logs: ExcalidrawActionLog[];
|
|
84
|
+
total: number;
|
|
85
|
+
summary: {
|
|
86
|
+
versionCount: number;
|
|
87
|
+
currentVersionNumber: number;
|
|
88
|
+
hasMermaidDraft: boolean;
|
|
89
|
+
};
|
|
90
|
+
}>;
|
|
91
|
+
getWorkbenchData(scope: ExcalidrawScope, query?: SearchExcalidrawDrawingsInput & {
|
|
92
|
+
drawingId?: string;
|
|
93
|
+
}): Promise<{
|
|
94
|
+
item: ExcalidrawDrawing;
|
|
95
|
+
currentVersion: ExcalidrawDrawingVersion;
|
|
96
|
+
versions: ExcalidrawDrawingVersion[];
|
|
97
|
+
logs: ExcalidrawActionLog[];
|
|
98
|
+
total: number;
|
|
99
|
+
summary: {
|
|
100
|
+
versionCount: number;
|
|
101
|
+
currentVersionNumber: number;
|
|
102
|
+
hasMermaidDraft: boolean;
|
|
103
|
+
};
|
|
104
|
+
} | {
|
|
105
|
+
summary: {
|
|
106
|
+
page: number;
|
|
107
|
+
pageSize: number;
|
|
108
|
+
search: string;
|
|
109
|
+
};
|
|
110
|
+
items: ExcalidrawDrawing[];
|
|
111
|
+
total: number;
|
|
112
|
+
page: number;
|
|
113
|
+
pageSize: number;
|
|
114
|
+
search: string;
|
|
115
|
+
}>;
|
|
116
|
+
updateDrawingStatus(scope: ExcalidrawScope, input: UpdateExcalidrawDrawingStatusInput): Promise<{
|
|
117
|
+
success: boolean;
|
|
118
|
+
message: string;
|
|
119
|
+
item: {
|
|
120
|
+
status: import("./types.js").ExcalidrawDrawingStatus;
|
|
121
|
+
lastEditedById: string;
|
|
122
|
+
lastEditedAt: Date;
|
|
123
|
+
id?: string;
|
|
124
|
+
tenantId?: string;
|
|
125
|
+
organizationId?: string;
|
|
126
|
+
workspaceId?: string;
|
|
127
|
+
projectId?: string;
|
|
128
|
+
createdById?: string;
|
|
129
|
+
assistantId?: string;
|
|
130
|
+
conversationId?: string;
|
|
131
|
+
title: string;
|
|
132
|
+
description?: string;
|
|
133
|
+
kind?: import("./types.js").ExcalidrawDrawingKind;
|
|
134
|
+
tags?: string[];
|
|
135
|
+
source?: string;
|
|
136
|
+
currentVersionId?: string;
|
|
137
|
+
currentVersionNumber?: number;
|
|
138
|
+
createdAt?: Date;
|
|
139
|
+
updatedAt?: Date;
|
|
140
|
+
} & ExcalidrawDrawing;
|
|
141
|
+
}>;
|
|
142
|
+
restoreVersion(scope: ExcalidrawScope, drawingId: string, versionId: string, changeSummary?: string): Promise<{
|
|
143
|
+
success: boolean;
|
|
144
|
+
message: string;
|
|
145
|
+
drawing: {
|
|
146
|
+
item: ExcalidrawDrawing;
|
|
147
|
+
currentVersion: ExcalidrawDrawingVersion;
|
|
148
|
+
versions: ExcalidrawDrawingVersion[];
|
|
149
|
+
logs: ExcalidrawActionLog[];
|
|
150
|
+
total: number;
|
|
151
|
+
summary: {
|
|
152
|
+
versionCount: number;
|
|
153
|
+
currentVersionNumber: number;
|
|
154
|
+
hasMermaidDraft: boolean;
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
version: ExcalidrawDrawingVersion;
|
|
158
|
+
}>;
|
|
159
|
+
reportFailure(scope: ExcalidrawScope, input: ReportExcalidrawFailureInput): Promise<{
|
|
160
|
+
success: boolean;
|
|
161
|
+
message: string;
|
|
162
|
+
log: ExcalidrawActionLog;
|
|
163
|
+
}>;
|
|
164
|
+
private createVersion;
|
|
165
|
+
private getCurrentVersion;
|
|
166
|
+
private requireDrawing;
|
|
167
|
+
private writeLog;
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=excalidraw.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"excalidraw.service.d.ts","sourceRoot":"","sources":["../../src/lib/excalidraw.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AACtG,OAAO,KAAK,EACV,4BAA4B,EAG5B,eAAe,EAGf,yBAAyB,EACzB,4BAA4B,EAC5B,+BAA+B,EAC/B,+BAA+B,EAC/B,6BAA6B,EAC7B,kCAAkC,EACnC,MAAM,YAAY,CAAA;AASnB,qBACa,iBAAiB;IAG1B,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAElC,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAElC,OAAO,CAAC,QAAQ,CAAC,aAAa;gBAJb,iBAAiB,EAAE,UAAU,CAAC,iBAAiB,CAAC,EAEhD,iBAAiB,EAAE,UAAU,CAAC,wBAAwB,CAAC,EAEvD,aAAa,EAAE,UAAU,CAAC,mBAAmB,CAAC;IAG3D,aAAa,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,4BAA4B;;;;;;;;;;;;IA0CzE,gBAAgB,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,+BAA+B;;;;;;;;;;;;;;;;;IAmB/E,UAAU,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,yBAAyB;;;;;;;;;;;;;;;;;IAyCnE,gBAAgB,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,+BAA+B;;;;;;;;;;;;;;;;;IAsC/E,cAAc,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,GAAE,6BAAkC;;;;;;;IAmChF,UAAU,CAAC,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM;;;;;;;;;;;;IAgCpD,gBAAgB,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,GAAE,6BAA6B,GAAG;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO;;;;;;;;;;;;;;;;;;;;;;;IAe3G,mBAAmB,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;IAyBrF,cAAc,CAAC,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM;;;;;;;;;;;;;;;;;IAmCnG,aAAa,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,4BAA4B;;;;;YAqBjE,aAAa;YAoDb,iBAAiB;YASjB,cAAc;YAUd,QAAQ;CA0BvB"}
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
+
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
|
3
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
4
|
+
import { Repository } from 'typeorm';
|
|
5
|
+
import { ExcalidrawActionLog, ExcalidrawDrawing, ExcalidrawDrawingVersion } from './entities/index.js';
|
|
6
|
+
let ExcalidrawService = class ExcalidrawService {
|
|
7
|
+
constructor(drawingRepository, versionRepository, logRepository) {
|
|
8
|
+
this.drawingRepository = drawingRepository;
|
|
9
|
+
this.versionRepository = versionRepository;
|
|
10
|
+
this.logRepository = logRepository;
|
|
11
|
+
}
|
|
12
|
+
async createDrawing(scope, input) {
|
|
13
|
+
const title = normalizeRequired(input.title, 'Drawing title is required.');
|
|
14
|
+
const drawing = await this.drawingRepository.save(this.drawingRepository.create({
|
|
15
|
+
...scopedCreate(scope),
|
|
16
|
+
assistantId: scope.assistantId ?? null,
|
|
17
|
+
conversationId: scope.conversationId ?? null,
|
|
18
|
+
createdById: scope.userId ?? null,
|
|
19
|
+
title,
|
|
20
|
+
description: normalizeOptional(input.description),
|
|
21
|
+
kind: input.kind ?? 'diagram',
|
|
22
|
+
status: 'draft',
|
|
23
|
+
tags: normalizeStringArray(input.tags),
|
|
24
|
+
source: normalizeOptional(input.source),
|
|
25
|
+
currentVersionNumber: 0,
|
|
26
|
+
lastEditedById: scope.userId ?? null,
|
|
27
|
+
lastEditedAt: new Date()
|
|
28
|
+
}));
|
|
29
|
+
await this.writeLog(scope, {
|
|
30
|
+
drawingId: drawing.id,
|
|
31
|
+
action: 'drawing_created',
|
|
32
|
+
actorType: scope.assistantId ? 'agent' : 'user',
|
|
33
|
+
message: `Drawing "${title}" was created.`,
|
|
34
|
+
snapshot: { title, kind: drawing.kind, source: drawing.source }
|
|
35
|
+
});
|
|
36
|
+
if (hasSceneContent(input)) {
|
|
37
|
+
await this.createVersion(scope, drawing, {
|
|
38
|
+
sourceType: input.mermaidSource ? 'agent_mermaid' : 'agent_json',
|
|
39
|
+
elements: normalizeElements(input.elements),
|
|
40
|
+
appState: normalizeObject(input.appState),
|
|
41
|
+
files: normalizeObject(input.files),
|
|
42
|
+
mermaidSource: normalizeNullableText(input.mermaidSource),
|
|
43
|
+
changeSummary: normalizeOptional(input.changeSummary) ?? 'Initial scene'
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return this.getDrawing(scope, drawing.id);
|
|
47
|
+
}
|
|
48
|
+
async saveSceneVersion(scope, input) {
|
|
49
|
+
const drawing = await this.requireDrawing(scope, input.drawingId);
|
|
50
|
+
const version = await this.createVersion(scope, drawing, {
|
|
51
|
+
sourceType: input.sourceType ?? 'agent_json',
|
|
52
|
+
elements: normalizeElements(input.elements),
|
|
53
|
+
appState: normalizeObject(input.appState),
|
|
54
|
+
files: normalizeObject(input.files),
|
|
55
|
+
mermaidSource: normalizeNullableText(input.mermaidSource),
|
|
56
|
+
changeSummary: normalizeOptional(input.changeSummary)
|
|
57
|
+
});
|
|
58
|
+
return {
|
|
59
|
+
success: true,
|
|
60
|
+
message: 'Excalidraw scene version was saved.',
|
|
61
|
+
drawing: await this.getDrawing(scope, drawing.id),
|
|
62
|
+
version
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
async patchScene(scope, input) {
|
|
66
|
+
const drawing = await this.requireDrawing(scope, input.drawingId);
|
|
67
|
+
const currentVersion = await this.getCurrentVersion(scope, drawing);
|
|
68
|
+
const patchedElements = applyElementPatch(currentVersion?.elements ?? [], input);
|
|
69
|
+
const appState = {
|
|
70
|
+
...(isPlainObject(currentVersion?.appState) ? currentVersion?.appState : {}),
|
|
71
|
+
...(isPlainObject(input.appStatePatch) ? input.appStatePatch : {})
|
|
72
|
+
};
|
|
73
|
+
const version = await this.createVersion(scope, drawing, {
|
|
74
|
+
sourceType: 'agent_patch',
|
|
75
|
+
elements: patchedElements,
|
|
76
|
+
appState,
|
|
77
|
+
files: input.files === undefined ? normalizeObject(currentVersion?.files) : normalizeObject(input.files),
|
|
78
|
+
mermaidSource: input.mermaidSource === undefined
|
|
79
|
+
? normalizeNullableText(currentVersion?.mermaidSource)
|
|
80
|
+
: normalizeNullableText(input.mermaidSource),
|
|
81
|
+
changeSummary: normalizeOptional(input.changeSummary) ?? 'Agent patch'
|
|
82
|
+
});
|
|
83
|
+
await this.writeLog(scope, {
|
|
84
|
+
drawingId: drawing.id,
|
|
85
|
+
versionId: version.id,
|
|
86
|
+
action: 'scene_patched',
|
|
87
|
+
actorType: 'agent',
|
|
88
|
+
message: input.changeSummary,
|
|
89
|
+
snapshot: {
|
|
90
|
+
addCount: input.addElements?.length ?? 0,
|
|
91
|
+
updateCount: input.updateElements?.length ?? 0,
|
|
92
|
+
deleteCount: input.deleteElementIds?.length ?? 0
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
success: true,
|
|
97
|
+
message: 'Excalidraw scene patch was saved as a new version.',
|
|
98
|
+
drawing: await this.getDrawing(scope, drawing.id),
|
|
99
|
+
version
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
async saveMermaidDraft(scope, input) {
|
|
103
|
+
const mermaidSource = normalizeRequired(input.mermaidSource, 'Mermaid source is required.');
|
|
104
|
+
const drawing = input.drawingId
|
|
105
|
+
? await this.requireDrawing(scope, input.drawingId)
|
|
106
|
+
: (await this.createDrawing(scope, {
|
|
107
|
+
title: input.title ?? 'Untitled Mermaid Diagram',
|
|
108
|
+
description: input.description,
|
|
109
|
+
kind: input.kind ?? 'flowchart'
|
|
110
|
+
})).item;
|
|
111
|
+
const version = await this.createVersion(scope, drawing, {
|
|
112
|
+
sourceType: 'agent_mermaid',
|
|
113
|
+
elements: [],
|
|
114
|
+
appState: {},
|
|
115
|
+
files: {},
|
|
116
|
+
mermaidSource,
|
|
117
|
+
changeSummary: normalizeOptional(input.changeSummary) ?? 'Mermaid draft'
|
|
118
|
+
});
|
|
119
|
+
await this.writeLog(scope, {
|
|
120
|
+
drawingId: drawing.id,
|
|
121
|
+
versionId: version.id,
|
|
122
|
+
action: 'mermaid_draft_saved',
|
|
123
|
+
actorType: 'agent',
|
|
124
|
+
message: input.changeSummary,
|
|
125
|
+
snapshot: { mermaidSource }
|
|
126
|
+
});
|
|
127
|
+
return {
|
|
128
|
+
success: true,
|
|
129
|
+
message: 'Mermaid draft was saved. Convert it in the Excalidraw workbench to make it editable.',
|
|
130
|
+
drawing: await this.getDrawing(scope, drawing.id),
|
|
131
|
+
version
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
async searchDrawings(scope, query = {}) {
|
|
135
|
+
const page = Math.max(1, query.page ?? 1);
|
|
136
|
+
const pageSize = Math.max(1, Math.min(query.pageSize ?? 20, 100));
|
|
137
|
+
const search = query.search?.trim().toLowerCase() ?? '';
|
|
138
|
+
const drawings = await this.drawingRepository.find({
|
|
139
|
+
where: scopedWhere(scope),
|
|
140
|
+
order: {
|
|
141
|
+
updatedAt: 'DESC'
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
const filtered = drawings.filter((drawing) => {
|
|
145
|
+
if (query.status && drawing.status !== query.status) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
if (query.kind && drawing.kind !== query.kind) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
if (!search) {
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
return [drawing.title, drawing.description, drawing.kind, ...(drawing.tags ?? [])]
|
|
155
|
+
.filter(isString)
|
|
156
|
+
.some((value) => value.toLowerCase().includes(search));
|
|
157
|
+
});
|
|
158
|
+
const start = (page - 1) * pageSize;
|
|
159
|
+
return {
|
|
160
|
+
items: filtered.slice(start, start + pageSize),
|
|
161
|
+
total: filtered.length,
|
|
162
|
+
page,
|
|
163
|
+
pageSize,
|
|
164
|
+
search
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
async getDrawing(scope, drawingId) {
|
|
168
|
+
const drawing = await this.requireDrawing(scope, drawingId);
|
|
169
|
+
const [versions, logs] = await Promise.all([
|
|
170
|
+
this.versionRepository.find({
|
|
171
|
+
where: scopedWhere(scope, { drawingId }),
|
|
172
|
+
order: {
|
|
173
|
+
versionNumber: 'DESC'
|
|
174
|
+
}
|
|
175
|
+
}),
|
|
176
|
+
this.logRepository.find({
|
|
177
|
+
where: scopedWhere(scope, { drawingId }),
|
|
178
|
+
order: {
|
|
179
|
+
createdAt: 'DESC'
|
|
180
|
+
}
|
|
181
|
+
})
|
|
182
|
+
]);
|
|
183
|
+
const currentVersion = versions.find((version) => version.id === drawing.currentVersionId) ?? versions[0] ?? null;
|
|
184
|
+
return {
|
|
185
|
+
item: drawing,
|
|
186
|
+
currentVersion,
|
|
187
|
+
versions,
|
|
188
|
+
logs,
|
|
189
|
+
total: versions.length,
|
|
190
|
+
summary: {
|
|
191
|
+
versionCount: versions.length,
|
|
192
|
+
currentVersionNumber: drawing.currentVersionNumber ?? currentVersion?.versionNumber ?? 0,
|
|
193
|
+
hasMermaidDraft: versions.some((version) => Boolean(version.mermaidSource))
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
async getWorkbenchData(scope, query = {}) {
|
|
198
|
+
if (query.drawingId) {
|
|
199
|
+
return this.getDrawing(scope, query.drawingId);
|
|
200
|
+
}
|
|
201
|
+
const result = await this.searchDrawings(scope, query);
|
|
202
|
+
return {
|
|
203
|
+
...result,
|
|
204
|
+
summary: {
|
|
205
|
+
page: result.page,
|
|
206
|
+
pageSize: result.pageSize,
|
|
207
|
+
search: result.search
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
async updateDrawingStatus(scope, input) {
|
|
212
|
+
const drawing = await this.requireDrawing(scope, input.drawingId);
|
|
213
|
+
const updated = await this.drawingRepository.save({
|
|
214
|
+
...drawing,
|
|
215
|
+
status: input.status,
|
|
216
|
+
lastEditedById: scope.userId ?? null,
|
|
217
|
+
lastEditedAt: new Date()
|
|
218
|
+
});
|
|
219
|
+
await this.writeLog(scope, {
|
|
220
|
+
drawingId: drawing.id,
|
|
221
|
+
versionId: drawing.currentVersionId,
|
|
222
|
+
action: input.status === 'archived' ? 'drawing_archived' : 'status_updated',
|
|
223
|
+
actorType: scope.assistantId ? 'agent' : 'user',
|
|
224
|
+
message: input.reason ?? `Status updated to ${input.status}`,
|
|
225
|
+
snapshot: { status: input.status }
|
|
226
|
+
});
|
|
227
|
+
return {
|
|
228
|
+
success: true,
|
|
229
|
+
message: 'Excalidraw drawing status was updated.',
|
|
230
|
+
item: updated
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
async restoreVersion(scope, drawingId, versionId, changeSummary) {
|
|
234
|
+
const drawing = await this.requireDrawing(scope, drawingId);
|
|
235
|
+
const version = await this.versionRepository.findOne({
|
|
236
|
+
where: scopedWhere(scope, { id: versionId, drawingId })
|
|
237
|
+
});
|
|
238
|
+
if (!version) {
|
|
239
|
+
throw new NotFoundException('Excalidraw drawing version was not found.');
|
|
240
|
+
}
|
|
241
|
+
const restored = await this.createVersion(scope, drawing, {
|
|
242
|
+
sourceType: 'restore',
|
|
243
|
+
elements: normalizeElements(version.elements),
|
|
244
|
+
appState: normalizeObject(version.appState),
|
|
245
|
+
files: normalizeObject(version.files),
|
|
246
|
+
mermaidSource: normalizeNullableText(version.mermaidSource),
|
|
247
|
+
changeSummary: normalizeOptional(changeSummary) ?? `Restored version ${version.versionNumber}`
|
|
248
|
+
});
|
|
249
|
+
await this.writeLog(scope, {
|
|
250
|
+
drawingId,
|
|
251
|
+
versionId: restored.id,
|
|
252
|
+
action: 'version_restored',
|
|
253
|
+
actorType: 'user',
|
|
254
|
+
message: changeSummary,
|
|
255
|
+
snapshot: { restoredFromVersionId: versionId, restoredFromVersionNumber: version.versionNumber }
|
|
256
|
+
});
|
|
257
|
+
return {
|
|
258
|
+
success: true,
|
|
259
|
+
message: 'Excalidraw drawing version was restored.',
|
|
260
|
+
drawing: await this.getDrawing(scope, drawingId),
|
|
261
|
+
version: restored
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
async reportFailure(scope, input) {
|
|
265
|
+
const log = await this.writeLog(scope, {
|
|
266
|
+
drawingId: input.drawingId,
|
|
267
|
+
versionId: input.versionId,
|
|
268
|
+
action: 'failure_reported',
|
|
269
|
+
actorType: scope.assistantId ? 'agent' : 'system',
|
|
270
|
+
message: input.operation,
|
|
271
|
+
errorMessage: input.errorMessage,
|
|
272
|
+
snapshot: {
|
|
273
|
+
recoverable: input.recoverable,
|
|
274
|
+
evidence: input.evidence
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
return {
|
|
278
|
+
success: true,
|
|
279
|
+
message: 'Excalidraw drawing failure was recorded.',
|
|
280
|
+
log
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
async createVersion(scope, drawing, input) {
|
|
284
|
+
const currentVersionNumber = drawing.currentVersionNumber ?? 0;
|
|
285
|
+
const versionNumber = currentVersionNumber + 1;
|
|
286
|
+
const version = await this.versionRepository.save(this.versionRepository.create({
|
|
287
|
+
...scopedCreate(scope),
|
|
288
|
+
drawingId: drawing.id,
|
|
289
|
+
versionNumber,
|
|
290
|
+
sourceType: input.sourceType,
|
|
291
|
+
elements: normalizeElements(input.elements),
|
|
292
|
+
appState: normalizeObject(input.appState),
|
|
293
|
+
files: normalizeObject(input.files),
|
|
294
|
+
mermaidSource: normalizeNullableText(input.mermaidSource),
|
|
295
|
+
changeSummary: normalizeOptional(input.changeSummary),
|
|
296
|
+
createdById: scope.userId ?? null,
|
|
297
|
+
assistantId: scope.assistantId ?? null,
|
|
298
|
+
conversationId: scope.conversationId ?? null
|
|
299
|
+
}));
|
|
300
|
+
await this.drawingRepository.save({
|
|
301
|
+
...drawing,
|
|
302
|
+
currentVersionId: version.id,
|
|
303
|
+
currentVersionNumber: version.versionNumber,
|
|
304
|
+
lastEditedById: scope.userId ?? null,
|
|
305
|
+
lastEditedAt: new Date()
|
|
306
|
+
});
|
|
307
|
+
await this.writeLog(scope, {
|
|
308
|
+
drawingId: drawing.id,
|
|
309
|
+
versionId: version.id,
|
|
310
|
+
action: 'version_saved',
|
|
311
|
+
actorType: input.sourceType.startsWith('agent') ? 'agent' : 'user',
|
|
312
|
+
message: input.changeSummary,
|
|
313
|
+
snapshot: {
|
|
314
|
+
versionNumber,
|
|
315
|
+
sourceType: input.sourceType,
|
|
316
|
+
elementCount: version.elements?.length ?? 0,
|
|
317
|
+
hasMermaidSource: Boolean(version.mermaidSource)
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
return version;
|
|
321
|
+
}
|
|
322
|
+
async getCurrentVersion(scope, drawing) {
|
|
323
|
+
if (!drawing.currentVersionId) {
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
return this.versionRepository.findOne({
|
|
327
|
+
where: scopedWhere(scope, { id: drawing.currentVersionId, drawingId: drawing.id })
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
async requireDrawing(scope, drawingId) {
|
|
331
|
+
const drawing = await this.drawingRepository.findOne({
|
|
332
|
+
where: scopedWhere(scope, { id: normalizeRequired(drawingId, 'Drawing id is required.') })
|
|
333
|
+
});
|
|
334
|
+
if (!drawing) {
|
|
335
|
+
throw new NotFoundException('Excalidraw drawing was not found.');
|
|
336
|
+
}
|
|
337
|
+
return drawing;
|
|
338
|
+
}
|
|
339
|
+
async writeLog(scope, input) {
|
|
340
|
+
return this.logRepository.save(this.logRepository.create({
|
|
341
|
+
...scopedCreate(scope),
|
|
342
|
+
drawingId: input.drawingId ?? null,
|
|
343
|
+
versionId: input.versionId ?? null,
|
|
344
|
+
action: input.action,
|
|
345
|
+
actorType: input.actorType ?? 'system',
|
|
346
|
+
actorId: scope.userId ?? scope.assistantId ?? null,
|
|
347
|
+
message: normalizeOptional(input.message),
|
|
348
|
+
errorMessage: normalizeOptional(input.errorMessage),
|
|
349
|
+
snapshot: input.snapshot
|
|
350
|
+
}));
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
ExcalidrawService = __decorate([
|
|
354
|
+
Injectable(),
|
|
355
|
+
__param(0, InjectRepository(ExcalidrawDrawing)),
|
|
356
|
+
__param(1, InjectRepository(ExcalidrawDrawingVersion)),
|
|
357
|
+
__param(2, InjectRepository(ExcalidrawActionLog)),
|
|
358
|
+
__metadata("design:paramtypes", [Repository,
|
|
359
|
+
Repository,
|
|
360
|
+
Repository])
|
|
361
|
+
], ExcalidrawService);
|
|
362
|
+
export { ExcalidrawService };
|
|
363
|
+
function scopedCreate(scope) {
|
|
364
|
+
return {
|
|
365
|
+
tenantId: scope.tenantId,
|
|
366
|
+
organizationId: scope.organizationId ?? null,
|
|
367
|
+
workspaceId: scope.workspaceId ?? null,
|
|
368
|
+
projectId: scope.projectId ?? null,
|
|
369
|
+
createdById: scope.userId ?? null
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
function scopedWhere(scope, extra) {
|
|
373
|
+
const where = {
|
|
374
|
+
tenantId: scope.tenantId
|
|
375
|
+
};
|
|
376
|
+
if (scope.organizationId != null) {
|
|
377
|
+
where.organizationId = scope.organizationId;
|
|
378
|
+
}
|
|
379
|
+
if (scope.projectId != null) {
|
|
380
|
+
where.projectId = scope.projectId;
|
|
381
|
+
}
|
|
382
|
+
else if (scope.workspaceId != null) {
|
|
383
|
+
where.workspaceId = scope.workspaceId;
|
|
384
|
+
}
|
|
385
|
+
return {
|
|
386
|
+
...where,
|
|
387
|
+
...(extra ?? {})
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
function normalizeRequired(value, message) {
|
|
391
|
+
const normalized = normalizeOptional(value);
|
|
392
|
+
if (!normalized) {
|
|
393
|
+
throw new BadRequestException(message);
|
|
394
|
+
}
|
|
395
|
+
return normalized;
|
|
396
|
+
}
|
|
397
|
+
function normalizeOptional(value) {
|
|
398
|
+
const normalized = value?.trim();
|
|
399
|
+
return normalized ? normalized : undefined;
|
|
400
|
+
}
|
|
401
|
+
function normalizeNullableText(value) {
|
|
402
|
+
return normalizeOptional(value) ?? null;
|
|
403
|
+
}
|
|
404
|
+
function normalizeStringArray(values) {
|
|
405
|
+
const normalized = (values ?? []).map((value) => normalizeOptional(value)).filter(isString);
|
|
406
|
+
return normalized.length ? Array.from(new Set(normalized)) : undefined;
|
|
407
|
+
}
|
|
408
|
+
function normalizeElements(elements) {
|
|
409
|
+
return Array.isArray(elements) ? elements : [];
|
|
410
|
+
}
|
|
411
|
+
function normalizeObject(value) {
|
|
412
|
+
return isPlainObject(value) ? value : {};
|
|
413
|
+
}
|
|
414
|
+
function hasSceneContent(input) {
|
|
415
|
+
return Boolean((Array.isArray(input.elements) && input.elements.length > 0) || input.mermaidSource || input.appState || input.files);
|
|
416
|
+
}
|
|
417
|
+
function applyElementPatch(elements, input) {
|
|
418
|
+
const deleteIds = new Set(input.deleteElementIds ?? []);
|
|
419
|
+
const updates = new Map((input.updateElements ?? []).map((item) => [item.id, item]));
|
|
420
|
+
const next = elements
|
|
421
|
+
.filter((element) => {
|
|
422
|
+
const id = readElementId(element);
|
|
423
|
+
return !id || !deleteIds.has(id);
|
|
424
|
+
})
|
|
425
|
+
.map((element) => {
|
|
426
|
+
const id = readElementId(element);
|
|
427
|
+
const update = id ? updates.get(id) : null;
|
|
428
|
+
return update && isPlainObject(element) ? { ...element, ...update } : element;
|
|
429
|
+
});
|
|
430
|
+
return [...next, ...normalizeElements(input.addElements)];
|
|
431
|
+
}
|
|
432
|
+
function readElementId(element) {
|
|
433
|
+
return isPlainObject(element) && typeof element.id === 'string' ? element.id : null;
|
|
434
|
+
}
|
|
435
|
+
function isPlainObject(value) {
|
|
436
|
+
return Boolean(value && typeof value === 'object' && !Array.isArray(value));
|
|
437
|
+
}
|
|
438
|
+
function isString(value) {
|
|
439
|
+
return typeof value === 'string' && value.length > 0;
|
|
440
|
+
}
|
|
441
|
+
//# sourceMappingURL=excalidraw.service.js.map
|