@gedit/editor-2d 0.1.93 → 0.1.99
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/lib/browser/editor2d-contribution.js +6 -6
- package/lib/browser/editor2d-contribution.js.map +1 -1
- package/lib/browser/editor2d-frontend-module.d.ts.map +1 -1
- package/lib/browser/editor2d-frontend-module.js +1 -0
- package/lib/browser/editor2d-frontend-module.js.map +1 -1
- package/lib/browser/editor2d-service.d.ts +14 -2
- package/lib/browser/editor2d-service.d.ts.map +1 -1
- package/lib/browser/editor2d-service.js +33 -9
- package/lib/browser/editor2d-service.js.map +1 -1
- package/lib/browser/model/editor2d-document.d.ts +2 -0
- package/lib/browser/model/editor2d-document.d.ts.map +1 -1
- package/lib/browser/model/editor2d-document.js +22 -3
- package/lib/browser/model/editor2d-document.js.map +1 -1
- package/lib/browser/model/editor2d-selection.d.ts +1 -0
- package/lib/browser/model/editor2d-selection.d.ts.map +1 -1
- package/lib/browser/model/editor2d-selection.js +11 -0
- package/lib/browser/model/editor2d-selection.js.map +1 -1
- package/lib/browser/model/editor2d.d.ts +9 -0
- package/lib/browser/model/editor2d.d.ts.map +1 -1
- package/lib/browser/model/editor2d.js +35 -3
- package/lib/browser/model/editor2d.js.map +1 -1
- package/lib/browser/playground/canvas-layer.js +1 -1
- package/lib/browser/playground/canvas-layer.js.map +1 -1
- package/lib/browser/playground/playground-context.d.ts +7 -3
- package/lib/browser/playground/playground-context.d.ts.map +1 -1
- package/lib/browser/playground/playground-context.js +9 -6
- package/lib/browser/playground/playground-context.js.map +1 -1
- package/lib/browser/playground/playground-contribution.d.ts +6 -1
- package/lib/browser/playground/playground-contribution.d.ts.map +1 -1
- package/lib/browser/playground/playground-contribution.js +50 -0
- package/lib/browser/playground/playground-contribution.js.map +1 -1
- package/lib/browser/playground/selection-entity-manager.d.ts.map +1 -1
- package/lib/browser/playground/selection-entity-manager.js +19 -17
- package/lib/browser/playground/selection-entity-manager.js.map +1 -1
- package/lib/browser/utils/snapshot.d.ts +16 -2
- package/lib/browser/utils/snapshot.d.ts.map +1 -1
- package/lib/browser/utils/snapshot.js +85 -47
- package/lib/browser/utils/snapshot.js.map +1 -1
- package/package.json +7 -7
- package/src/browser/editor2d-contribution.ts +2 -2
- package/src/browser/editor2d-frontend-module.ts +1 -0
- package/src/browser/editor2d-service.ts +33 -11
- package/src/browser/model/editor2d-document.ts +25 -4
- package/src/browser/model/editor2d-selection.ts +10 -0
- package/src/browser/model/editor2d.ts +31 -2
- package/src/browser/playground/canvas-layer.ts +1 -1
- package/src/browser/playground/playground-context.ts +10 -8
- package/src/browser/playground/playground-contribution.ts +44 -1
- package/src/browser/playground/selection-entity-manager.tsx +18 -16
- package/src/browser/style/canvas-draw-layer.less +1 -1
- package/src/browser/style/index.less +0 -1
- package/src/browser/utils/snapshot.ts +53 -7
|
@@ -65,6 +65,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
65
65
|
exports.SnapshotCreator = exports.createSnapshots = exports.SnapshotOptsDefault = void 0;
|
|
66
66
|
var canvas_draw_1 = require("../playground/canvas-draw");
|
|
67
67
|
var utils_1 = require("@gedit/utils");
|
|
68
|
+
var model_1 = require("../model");
|
|
68
69
|
exports.SnapshotOptsDefault = {
|
|
69
70
|
quility: 0.8,
|
|
70
71
|
imageType: 'image/webp',
|
|
@@ -119,6 +120,24 @@ var SnapshotCreator = /** @class */ (function (_super) {
|
|
|
119
120
|
]);
|
|
120
121
|
return _this;
|
|
121
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* 清楚缓存数据
|
|
125
|
+
*/
|
|
126
|
+
SnapshotCreator.prototype.clearResultCache = function (includeUris) {
|
|
127
|
+
var _this = this;
|
|
128
|
+
Object.keys(this.result).forEach(function (key) {
|
|
129
|
+
if (!includeUris.includes(key)) {
|
|
130
|
+
delete _this.result[key];
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
SnapshotCreator.prototype.getResultFromCache = function () {
|
|
135
|
+
var _this = this;
|
|
136
|
+
return Object.keys(this.result).map(function (k) { return _this.result[k]; });
|
|
137
|
+
};
|
|
138
|
+
SnapshotCreator.prototype.updateResultCache = function (data) {
|
|
139
|
+
this.result[data.uri] = data;
|
|
140
|
+
};
|
|
122
141
|
SnapshotCreator.prototype.getSnapshot = function (uri) {
|
|
123
142
|
return this.result[uri];
|
|
124
143
|
};
|
|
@@ -144,55 +163,46 @@ var SnapshotCreator = /** @class */ (function (_super) {
|
|
|
144
163
|
});
|
|
145
164
|
});
|
|
146
165
|
};
|
|
147
|
-
SnapshotCreator.prototype.getResult = function () {
|
|
148
|
-
var _this = this;
|
|
149
|
-
return Object.keys(this.result).map(function (k) { return _this.result[k]; });
|
|
150
|
-
};
|
|
151
166
|
SnapshotCreator.prototype.process = function () {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
167
|
+
var _this = this;
|
|
168
|
+
if (this.processing) {
|
|
169
|
+
return this.processing.promise;
|
|
170
|
+
}
|
|
171
|
+
var deferred = this.processing = new utils_1.PromiseDeferred();
|
|
172
|
+
var drawer = this.drawer;
|
|
173
|
+
var dispose = new utils_1.DisposableCollection();
|
|
174
|
+
dispose.push(utils_1.Disposable.create(function () {
|
|
175
|
+
deferred.resolve();
|
|
176
|
+
_this.current = undefined;
|
|
177
|
+
_this.processing = undefined;
|
|
178
|
+
}));
|
|
179
|
+
dispose.push(drawer.onLoading(function (e) {
|
|
180
|
+
var loaded = e.loaded, allCount = e.allCount, currentCount = e.currentCount;
|
|
181
|
+
if (loaded || allCount <= currentCount) {
|
|
182
|
+
var widget = drawer.renderWidget;
|
|
183
|
+
if (_this.opts.limitSize) {
|
|
184
|
+
fixDrawerScale(drawer, _this.opts.limitSize);
|
|
158
185
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
fixDrawerScale(drawer, _this.opts.limitSize);
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
drawer.refreshScale(false, 1);
|
|
176
|
-
}
|
|
177
|
-
widget.createSnapShot(_this.opts.imageType || exports.SnapshotOptsDefault.imageType, _this.opts.quility || exports.SnapshotOptsDefault.quility).then(function (imageData) {
|
|
178
|
-
var current = _this.current;
|
|
179
|
-
if (current) {
|
|
180
|
-
_this.result[current.uri] = {
|
|
181
|
-
uri: current.uri,
|
|
182
|
-
version: current.version,
|
|
183
|
-
name: current.name,
|
|
184
|
-
imageData: imageData
|
|
185
|
-
};
|
|
186
|
-
_this.onUpdateEmitter.fire();
|
|
187
|
-
}
|
|
188
|
-
_this.next(function () { return dispose.dispose(); });
|
|
189
|
-
});
|
|
186
|
+
else {
|
|
187
|
+
drawer.refreshScale(false, 1);
|
|
188
|
+
}
|
|
189
|
+
widget.createSnapShot(_this.opts.imageType || exports.SnapshotOptsDefault.imageType, _this.opts.quility || exports.SnapshotOptsDefault.quility).then(function (imageData) {
|
|
190
|
+
var current = _this.current;
|
|
191
|
+
if (current) {
|
|
192
|
+
_this.result[current.uri] = {
|
|
193
|
+
uri: current.uri,
|
|
194
|
+
version: current.version,
|
|
195
|
+
name: current.name,
|
|
196
|
+
imageData: imageData
|
|
197
|
+
};
|
|
198
|
+
_this.onUpdateEmitter.fire();
|
|
190
199
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
});
|
|
200
|
+
_this.next(function () { return dispose.dispose(); });
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}));
|
|
204
|
+
this.next(function () { return dispose.dispose(); });
|
|
205
|
+
return deferred.promise;
|
|
196
206
|
};
|
|
197
207
|
SnapshotCreator.prototype.next = function (end) {
|
|
198
208
|
var _a, _b;
|
|
@@ -201,18 +211,46 @@ var SnapshotCreator = /** @class */ (function (_super) {
|
|
|
201
211
|
this.current = next;
|
|
202
212
|
(_b = (_a = this.drawer.renderWidget) === null || _a === void 0 ? void 0 : _a.currentScene) === null || _b === void 0 ? void 0 : _b.dispose();
|
|
203
213
|
var appConfig = typeof this.opts.appConfig === 'function' ? this.opts.appConfig() : this.opts.appConfig;
|
|
214
|
+
var content = next.content;
|
|
215
|
+
// Empty
|
|
216
|
+
if (!content || !content.children || Object.keys(content).length === 0) {
|
|
217
|
+
content = model_1.Editor2dNode.createRootNode(new utils_1.URI(next.uri));
|
|
218
|
+
var attrs = this.opts.renderEngine.getDisplayDefaultData(this.opts.engineName, content.displayType);
|
|
219
|
+
Object.assign(content, __assign({}, attrs));
|
|
220
|
+
}
|
|
204
221
|
this.drawer.update({
|
|
205
222
|
visible: true,
|
|
206
223
|
uri: next.uri,
|
|
207
224
|
engineName: this.opts.engineName,
|
|
208
225
|
appConfig: appConfig,
|
|
209
|
-
content:
|
|
226
|
+
content: content,
|
|
210
227
|
});
|
|
211
228
|
}
|
|
212
229
|
else {
|
|
213
230
|
end();
|
|
214
231
|
}
|
|
215
232
|
};
|
|
233
|
+
/**
|
|
234
|
+
* 监听变化,并自动刷新缩略图缓存
|
|
235
|
+
* @param model
|
|
236
|
+
* @param fn
|
|
237
|
+
* @param quility 缩略图质量
|
|
238
|
+
* @param delay 延迟生成
|
|
239
|
+
*/
|
|
240
|
+
SnapshotCreator.prototype.listenModelChanged = function (model, fn, quility, delay) {
|
|
241
|
+
var _this = this;
|
|
242
|
+
if (quility === void 0) { quility = 0.1; }
|
|
243
|
+
if (delay === void 0) { delay = 1000; }
|
|
244
|
+
return model.playground.context.onCanvasDataChanged((0, utils_1.debounce)(function (drawer) {
|
|
245
|
+
var _a = drawer.getData() || {}, content = _a.content, visible = _a.visible;
|
|
246
|
+
if (!content || drawer.loading)
|
|
247
|
+
return;
|
|
248
|
+
if (visible) {
|
|
249
|
+
var widget = drawer.renderWidget;
|
|
250
|
+
widget.createSnapShot(_this.opts.imageType, quility).then(function (base64) { return fn(base64); });
|
|
251
|
+
}
|
|
252
|
+
}, delay));
|
|
253
|
+
};
|
|
216
254
|
return SnapshotCreator;
|
|
217
255
|
}(utils_1.DisposableImpl));
|
|
218
256
|
exports.SnapshotCreator = SnapshotCreator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../../../src/browser/utils/snapshot.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAAuE;AACvE,
|
|
1
|
+
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../../../src/browser/utils/snapshot.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAAuE;AACvE,sCASsB;AAEtB,kCAAwC;AAW3B,QAAA,mBAAmB,GAAG;IACjC,OAAO,EAAE,GAAG;IACZ,SAAS,EAAE,YAAY;CACxB,CAAC;AAgBF,SAAS,cAAc,CAAC,MAAkB,EAAE,SAAqB;IAC/D,iDAAiD;IACjD,0BAA0B;IAC1B,IAAM,WAAW,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC;IAC1C,IAAM,KAAK,GAAG,kBAAU,CAAC,OAAO,CAAC,WAAY,EAAE;QAC7C,KAAK,EAAE,SAAS,CAAC,KAAK;QACtB,MAAM,EAAE,SAAS,CAAC,MAAM;KACzB,CAAC,CAAC;IACH,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACpC,CAAC;AAED,SAAsB,eAAe,CAAC,IAAkB,EAAE,UAA2B;;;;;;oBAC7E,OAAO,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;oBAC3B,qBAAM,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,EAAA;;oBAAvC,MAAM,GAAG,SAA8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ib/browser/index",
|
|
6
6
|
"typings": "lib/browser/index.d.ts",
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
"src"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@gedit/app-config": "^0.1.
|
|
13
|
-
"@gedit/editor": "^0.1.
|
|
14
|
-
"@gedit/playground": "^0.1.
|
|
15
|
-
"@gedit/render-engine-ide": "^0.1.
|
|
16
|
-
"@gedit/workspace-2d": "^0.1.
|
|
12
|
+
"@gedit/app-config": "^0.1.93",
|
|
13
|
+
"@gedit/editor": "^0.1.75",
|
|
14
|
+
"@gedit/playground": "^0.1.83",
|
|
15
|
+
"@gedit/render-engine-ide": "^0.1.99",
|
|
16
|
+
"@gedit/workspace-2d": "^0.1.79",
|
|
17
17
|
"json-stringify-pretty-compact": "^2.0.0"
|
|
18
18
|
},
|
|
19
19
|
"geditExtensions": [
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"nyc": {
|
|
35
35
|
"extends": "../../configs/nyc.json"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "ab65209853e8f4806908425345aedaaad8ba08e2"
|
|
38
38
|
}
|
|
@@ -118,12 +118,12 @@ export class Editor2dContribution implements FrontendApplicationContribution, Co
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
registerToolbarItems(toolbars: TabBarToolbarRegistry): void {
|
|
121
|
-
toolbars.registerItem({
|
|
121
|
+
/* toolbars.registerItem({
|
|
122
122
|
id: Editor2dCommands.FULLSCREEN.id,
|
|
123
123
|
command: Editor2dCommands.FULLSCREEN.id,
|
|
124
124
|
tooltip: Editor2dCommands.FULLSCREEN.label,
|
|
125
125
|
priority: 0,
|
|
126
|
-
});
|
|
126
|
+
}); */
|
|
127
127
|
/*
|
|
128
128
|
toolbars.registerItem({
|
|
129
129
|
id: Editor2dCommands.ZOOM_IN.id,
|
|
@@ -25,6 +25,7 @@ export default new ContainerModule(bind => {
|
|
|
25
25
|
Editor2dRefProviderContribution,
|
|
26
26
|
Editor2dContextKeyService,
|
|
27
27
|
]);
|
|
28
|
+
bind(Editor2dService.Provider).toFactory(ctx => () => ctx.container.get(Editor2dService));
|
|
28
29
|
bindContributions(bind, Editor2dContribution, [
|
|
29
30
|
FrontendApplicationContribution,
|
|
30
31
|
CommandContribution,
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
SelectionService,
|
|
6
6
|
} from '@gedit/application-common';
|
|
7
7
|
import { Editor2dModel } from './model/editor2d-model';
|
|
8
|
-
import { EditorAccess, EditorManager, EditorWidget } from '@gedit/editor';
|
|
8
|
+
import { EditorAccess, EditorDocumentChangeEvent, EditorManager, EditorWidget } from '@gedit/editor';
|
|
9
9
|
import { Editor2dNode } from './model/editor2d';
|
|
10
10
|
import { Editor2dDocument } from './model/editor2d-document';
|
|
11
11
|
import { SelectableTreeNode, TreeSelection } from '@gedit/tree';
|
|
@@ -17,6 +17,10 @@ export interface Editor2dSelectedNodesChangedEvent {
|
|
|
17
17
|
document: Editor2dDocument | undefined; // 如果为空,代表当前没有在编辑文档
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
export interface Editor2dModelContentChangedEvent extends Editor2dSelectedNodesChangedEvent {
|
|
21
|
+
event: EditorDocumentChangeEvent<Editor2dDocument>
|
|
22
|
+
}
|
|
23
|
+
|
|
20
24
|
@injectable()
|
|
21
25
|
export class Editor2dService {
|
|
22
26
|
@inject(SelectionService) protected readonly selectionService: SelectionService;
|
|
@@ -59,7 +63,21 @@ export class Editor2dService {
|
|
|
59
63
|
fn(this.getCurrentModel());
|
|
60
64
|
});
|
|
61
65
|
}
|
|
62
|
-
onDeleteNode(fn: (e:
|
|
66
|
+
onDeleteNode(fn: (e: Editor2dModelContentChangedEvent & { deleteNodes: Editor2dNode[] }) => void): Disposable {
|
|
67
|
+
return this.onCurrentModelContentChanged(e => {
|
|
68
|
+
if (e.event.type === 'delete') {
|
|
69
|
+
return fn({
|
|
70
|
+
...e,
|
|
71
|
+
deleteNodes: (e.event.nodes as Editor2dNode[]) || [],
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 内容修改触发
|
|
78
|
+
* @param fn
|
|
79
|
+
*/
|
|
80
|
+
onCurrentModelContentChanged(fn: (e: Editor2dModelContentChangedEvent) => void): Disposable {
|
|
63
81
|
const self = this;
|
|
64
82
|
let model: Editor2dModel | undefined;
|
|
65
83
|
const toDispose = new DisposableCollection();
|
|
@@ -71,15 +89,13 @@ export class Editor2dService {
|
|
|
71
89
|
preDispose.dispose();
|
|
72
90
|
preDispose = new DisposableCollection();
|
|
73
91
|
if (model) {
|
|
74
|
-
preDispose.push(model.onDocumentContentChanged(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
});
|
|
82
|
-
}
|
|
92
|
+
preDispose.push(model.onDocumentContentChanged(event => {
|
|
93
|
+
fn({
|
|
94
|
+
selectedNodes: model?.selection.selectedNodes || [],
|
|
95
|
+
document: model?.document,
|
|
96
|
+
model,
|
|
97
|
+
event
|
|
98
|
+
});
|
|
83
99
|
}));
|
|
84
100
|
}
|
|
85
101
|
toDispose.push(preDispose);
|
|
@@ -153,3 +169,9 @@ export class Editor2dService {
|
|
|
153
169
|
return toDispose;
|
|
154
170
|
}
|
|
155
171
|
}
|
|
172
|
+
|
|
173
|
+
export namespace Editor2dService {
|
|
174
|
+
// 动态获取, 用于循环依赖情况, 可以在AppShell加载之后使用
|
|
175
|
+
export type Provider = () => Editor2dService;
|
|
176
|
+
export const Provider = Symbol('Editor2dService.Provider');
|
|
177
|
+
}
|
|
@@ -12,7 +12,13 @@ import {
|
|
|
12
12
|
PromiseDeferred,
|
|
13
13
|
URI,
|
|
14
14
|
} from '@gedit/utils';
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
checkDuplicateNodes,
|
|
17
|
+
Editor2dContainerNode,
|
|
18
|
+
Editor2dContent,
|
|
19
|
+
Editor2dModelOptions,
|
|
20
|
+
Editor2dNode,
|
|
21
|
+
} from './editor2d';
|
|
16
22
|
import { GameObject, GameObjectBaseType, GameObjectType } from '@gedit/render-engine';
|
|
17
23
|
import { GameObjectDecoration, RenderEngineIDEService } from '@gedit/render-engine-ide';
|
|
18
24
|
import { CompositeTreeNode, ExpandableTreeNode, Tree, TreeImpl, TreeNode } from '@gedit/tree';
|
|
@@ -36,7 +42,8 @@ export class Editor2dDocument extends TreeImpl<Editor2dNode, Editor2dContainerNo
|
|
|
36
42
|
readonly onSaved = this.onSavedEmitter.event;
|
|
37
43
|
public animationStarted: boolean = false;
|
|
38
44
|
protected animationIds: string[] = []; // 当前正在录制的动画节点
|
|
39
|
-
private _localVersion: number =
|
|
45
|
+
private _localVersion: number = 0;
|
|
46
|
+
private _saveVersion: number = 0;
|
|
40
47
|
protected errors: ResourceRefError[] = [];
|
|
41
48
|
protected componentContents: { [key: string]: Editor2dNode } = {};
|
|
42
49
|
protected _snaplines: any[] = [];
|
|
@@ -61,6 +68,7 @@ export class Editor2dDocument extends TreeImpl<Editor2dNode, Editor2dContainerNo
|
|
|
61
68
|
super();
|
|
62
69
|
this.toDispose.push(this.onContentChangedEmitter);
|
|
63
70
|
this.toDispose.push(this.onSavedEmitter);
|
|
71
|
+
// this.toDispose.
|
|
64
72
|
// this.toDispose.push(this.resourceAutoSaveService);
|
|
65
73
|
this.toDispose.push(this.resourceAutoSaveService.onSyncContent(content => this.reloadContent(content || '')));
|
|
66
74
|
this.toDispose.push(this.onSaved(event => this.resourceAutoSaveService.fireDidChangeContent(event)));
|
|
@@ -217,6 +225,11 @@ export class Editor2dDocument extends TreeImpl<Editor2dNode, Editor2dContainerNo
|
|
|
217
225
|
// }
|
|
218
226
|
// }
|
|
219
227
|
// 这里采用深度比较, 因为数据层次定义不会太多
|
|
228
|
+
if (data && data.id && data.id !== treeNode.id) {
|
|
229
|
+
alert('节点更新出错,不同节点无法互相覆盖');
|
|
230
|
+
console.error('无法覆盖同步节点数据: ', treeNode, data);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
220
233
|
const changed = forceUpdate ? true : Compare.isDeepChanged(treeNode, data);
|
|
221
234
|
if (changed) {
|
|
222
235
|
Object.assign(treeNode, data);
|
|
@@ -264,7 +277,9 @@ export class Editor2dDocument extends TreeImpl<Editor2dNode, Editor2dContainerNo
|
|
|
264
277
|
}
|
|
265
278
|
if (data.content) {
|
|
266
279
|
this._localVersion = data.content.version;
|
|
267
|
-
|
|
280
|
+
(data.content as any).visible = false;
|
|
281
|
+
this._saveVersion = data.version || 0;
|
|
282
|
+
this.root = checkDuplicateNodes(data.content);
|
|
268
283
|
} else {
|
|
269
284
|
this.root = this.createRootNode();
|
|
270
285
|
}
|
|
@@ -296,6 +311,10 @@ export class Editor2dDocument extends TreeImpl<Editor2dNode, Editor2dContainerNo
|
|
|
296
311
|
this.onContentChangedEmitter.fire({ document: this, contentChanges: contents, nodes, type });
|
|
297
312
|
}
|
|
298
313
|
if (!this.loading && !noSave) {
|
|
314
|
+
this._saveVersion++;
|
|
315
|
+
if (this._saveVersion === Number.MAX_VALUE) {
|
|
316
|
+
this._saveVersion = 0;
|
|
317
|
+
}
|
|
299
318
|
this.onSavedEmitter.fire({ document: this, contentChanges: contents, nodes, type });
|
|
300
319
|
}
|
|
301
320
|
};
|
|
@@ -576,7 +595,6 @@ export class Editor2dDocument extends TreeImpl<Editor2dNode, Editor2dContainerNo
|
|
|
576
595
|
});
|
|
577
596
|
if (nodes.length) {
|
|
578
597
|
// TODO: 音乐素材变更
|
|
579
|
-
console.log('document update to timeline', nodes, e.type);
|
|
580
598
|
onNodeChange(nodes, e.type);
|
|
581
599
|
}
|
|
582
600
|
}
|
|
@@ -756,4 +774,7 @@ export class Editor2dDocument extends TreeImpl<Editor2dNode, Editor2dContainerNo
|
|
|
756
774
|
this.fireContentChanged([], 'update');
|
|
757
775
|
}
|
|
758
776
|
}
|
|
777
|
+
get saveVersion(): number {
|
|
778
|
+
return this._saveVersion;
|
|
779
|
+
}
|
|
759
780
|
}
|
|
@@ -2,10 +2,20 @@ import { injectable } from 'inversify';
|
|
|
2
2
|
import { EditorDocumentSelection } from '@gedit/editor';
|
|
3
3
|
import { TreeSelectionServiceImpl } from '@gedit/tree/lib/browser/tree-selection-impl';
|
|
4
4
|
import { Editor2dNode } from './editor2d';
|
|
5
|
+
import { SelectableTreeNode, TreeSelection } from '@gedit/tree';
|
|
6
|
+
import SelectionType = TreeSelection.SelectionType;
|
|
5
7
|
|
|
6
8
|
@injectable()
|
|
7
9
|
export class Editor2dSelection extends TreeSelectionServiceImpl implements EditorDocumentSelection {
|
|
8
10
|
get selectedNodes(): Editor2dNode[] {
|
|
9
11
|
return this.state.selection() as Editor2dNode[];
|
|
10
12
|
}
|
|
13
|
+
clearSelection(): void {
|
|
14
|
+
this.selectedNodes.forEach(node =>
|
|
15
|
+
this.addSelection({
|
|
16
|
+
node: node as Readonly<SelectableTreeNode>,
|
|
17
|
+
type: SelectionType.TOGGLE
|
|
18
|
+
})
|
|
19
|
+
);
|
|
20
|
+
}
|
|
11
21
|
}
|
|
@@ -86,6 +86,7 @@ export interface Editor2dContainerNode extends Editor2dNode, ExpandableTreeNode
|
|
|
86
86
|
|
|
87
87
|
export namespace Editor2dNode {
|
|
88
88
|
export const ROOT_NODE_ID = 'root';
|
|
89
|
+
export const GLOBAL_ADD_EVENT = 'global_add_event'; // 全局添加标记事件
|
|
89
90
|
export function createNodeId(): string {
|
|
90
91
|
return generateUuid();
|
|
91
92
|
}
|
|
@@ -112,6 +113,14 @@ export namespace Editor2dNode {
|
|
|
112
113
|
}
|
|
113
114
|
return path.join('/');
|
|
114
115
|
}
|
|
116
|
+
export function getDepth(node: Editor2dNode | Editor2dContainerNode | TreeNode): number {
|
|
117
|
+
let depth = 0;
|
|
118
|
+
while (node && !Editor2dNode.isRootNode(node)) {
|
|
119
|
+
depth ++;
|
|
120
|
+
node = node.parent as Editor2dContainerNode;
|
|
121
|
+
}
|
|
122
|
+
return depth;
|
|
123
|
+
}
|
|
115
124
|
export function toLeafNode(node: Editor2dNode | Editor2dContainerNode): Editor2dNode {
|
|
116
125
|
if (node.children) {
|
|
117
126
|
delete node.children;
|
|
@@ -188,7 +197,7 @@ export namespace Editor2dNode {
|
|
|
188
197
|
parent: undefined,
|
|
189
198
|
name: uri.displayName,
|
|
190
199
|
children: [],
|
|
191
|
-
visible:
|
|
200
|
+
visible: false,
|
|
192
201
|
expanded: true,
|
|
193
202
|
selected: false,
|
|
194
203
|
locked: false,
|
|
@@ -247,7 +256,7 @@ export async function getEditor2dModelOpts(resource: Resource, resourceService:
|
|
|
247
256
|
const options: ResourceAutoSaveOptions = {
|
|
248
257
|
encoding,
|
|
249
258
|
resource,
|
|
250
|
-
saveAsString: e => Editor2dContent.parseToString({version: e.document.
|
|
259
|
+
saveAsString: e => Editor2dContent.parseToString({version: e.document.saveVersion, content: e.document.root, snaplines: e.document.snaplines})
|
|
251
260
|
};
|
|
252
261
|
const autoSaveService = await resourceService.createAutoSaveResource(options);
|
|
253
262
|
return {
|
|
@@ -255,3 +264,23 @@ export async function getEditor2dModelOpts(resource: Resource, resourceService:
|
|
|
255
264
|
autoSaveService,
|
|
256
265
|
};
|
|
257
266
|
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* 检测重复节点数据, 可能为误操作造成,避免对编辑态造成影响
|
|
270
|
+
* @param node
|
|
271
|
+
*/
|
|
272
|
+
export function checkDuplicateNodes(node: Editor2dNode, map: { [key: string]: Editor2dNode } = {}): Editor2dNode {
|
|
273
|
+
if (node.children) {
|
|
274
|
+
node.children.slice().forEach((c: Editor2dNode) => {
|
|
275
|
+
if (map[c.id]) {
|
|
276
|
+
const index = node.children!.indexOf(c);
|
|
277
|
+
node.children!.splice(index, 1);
|
|
278
|
+
console.log('>>> 清除重复数据: ', c.name);
|
|
279
|
+
} else {
|
|
280
|
+
map[c.id] = c;
|
|
281
|
+
checkDuplicateNodes(c, map);
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
return node;
|
|
286
|
+
}
|
|
@@ -61,7 +61,7 @@ export class CanvasLayer extends Layer<PlaygroundContext2d> {
|
|
|
61
61
|
this.document?.updateNode(e.node, {error: e.error});
|
|
62
62
|
break;
|
|
63
63
|
}
|
|
64
|
-
this.context.
|
|
64
|
+
this.context.onCanvasDataChangedEmitter.fire(this.canvasDrawer!);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
getAssetsURI(): string {
|
|
@@ -2,7 +2,7 @@ import { inject, injectable } from 'inversify';
|
|
|
2
2
|
import { RenderEngineIDEService } from '@gedit/render-engine-ide';
|
|
3
3
|
import { SelectableTreeNode, TreeSelection } from '@gedit/tree';
|
|
4
4
|
import { AppConfigService } from '@gedit/app-config';
|
|
5
|
-
import { debounce, URI } from '@gedit/utils';
|
|
5
|
+
import { debounce, Emitter, URI } from '@gedit/utils';
|
|
6
6
|
import { Editor2dEntity } from './entities/editor2d-entity';
|
|
7
7
|
import type { SelectionEntityManager } from './selection-entity-manager';
|
|
8
8
|
import { Playground, Selectable } from '@gedit/playground';
|
|
@@ -16,10 +16,15 @@ import type { CanvasDraw } from './canvas-draw';
|
|
|
16
16
|
|
|
17
17
|
export const Editor2dPlayGround = Symbol('Editor2dPlayGround');
|
|
18
18
|
|
|
19
|
-
export type Editor2dPlayGround = Playground
|
|
19
|
+
export type Editor2dPlayGround = Playground<PlaygroundContext2d>;
|
|
20
20
|
|
|
21
21
|
@injectable()
|
|
22
22
|
export class PlaygroundContext2d {
|
|
23
|
+
readonly onCanvasDataChangedEmitter = new Emitter<CanvasDraw>();
|
|
24
|
+
/**
|
|
25
|
+
* 监听画布变化,可用于生成缩略图
|
|
26
|
+
*/
|
|
27
|
+
readonly onCanvasDataChanged = this.onCanvasDataChangedEmitter.event;
|
|
23
28
|
constructor(
|
|
24
29
|
@inject(RenderEngineIDEService) readonly renderEngine: RenderEngineIDEService,
|
|
25
30
|
@inject(Editor2dDocument) readonly document: Editor2dDocument,
|
|
@@ -29,12 +34,9 @@ export class PlaygroundContext2d {
|
|
|
29
34
|
@inject(Editor2dModelOptions) readonly options: Editor2dModelOptions,
|
|
30
35
|
@inject(Editor2dContextKeyService) readonly contextKeyService: Editor2dContextKeyService
|
|
31
36
|
) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
onCanvasDataChanged(drawer: CanvasDraw): void {
|
|
36
|
-
if (this.options.onCanvasDataChanged) {
|
|
37
|
-
this.options.onCanvasDataChanged(drawer);
|
|
37
|
+
this.document.toDispose.push(this.onCanvasDataChangedEmitter);
|
|
38
|
+
if (options.onCanvasDataChanged) {
|
|
39
|
+
this.onCanvasDataChanged(drawer => options.onCanvasDataChanged!(drawer));
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
/**
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { inject, injectable } from 'inversify';
|
|
2
2
|
import {
|
|
3
|
+
EditorStateConfigEntity,
|
|
3
4
|
Playground,
|
|
5
|
+
PlaygroundConfig,
|
|
4
6
|
PlaygroundContribution,
|
|
5
7
|
PlaygroundRegistry,
|
|
6
8
|
RulerConfigEntity,
|
|
@@ -12,13 +14,19 @@ import { CanvasDrawLayer } from './canvas-draw-layer';
|
|
|
12
14
|
// import { SelectionLayer } from './selection-layer';
|
|
13
15
|
import { AppConfigData, AppConfigService } from '@gedit/app-config';
|
|
14
16
|
import { HistoryService } from '@gedit/history';
|
|
15
|
-
import { Editor2dModelOptions } from '../model/editor2d';
|
|
17
|
+
import { Editor2dModelOptions, Editor2dNode } from '../model/editor2d';
|
|
18
|
+
import { ContextMenuRenderer } from '@gedit/layout';
|
|
19
|
+
import { CommandService } from '@gedit/command';
|
|
20
|
+
import { CommonCommands } from '@gedit/application-common/lib/browser';
|
|
16
21
|
|
|
17
22
|
@injectable()
|
|
18
23
|
export class PlaygroundContribution2d implements PlaygroundContribution {
|
|
19
24
|
@inject(AppConfigService) readonly appConfig: AppConfigService;
|
|
20
25
|
@inject(Editor2dModelOptions) readonly modelOpts: Editor2dModelOptions;
|
|
21
26
|
@inject(HistoryService) readonly historyService: HistoryService;
|
|
27
|
+
@inject(PlaygroundConfig) readonly config: PlaygroundConfig;
|
|
28
|
+
@inject(CommandService) readonly commandService: CommandService;
|
|
29
|
+
@inject(ContextMenuRenderer) readonly menuRender: ContextMenuRenderer;
|
|
22
30
|
registerPlayground(registry: PlaygroundRegistry): void {
|
|
23
31
|
registry.registerLayer(CanvasLayer);
|
|
24
32
|
registry.registerLayer(CanvasDrawLayer);
|
|
@@ -34,6 +42,7 @@ export class PlaygroundContribution2d implements PlaygroundContribution {
|
|
|
34
42
|
// 开启缩放
|
|
35
43
|
playground.zoomEnable = true;
|
|
36
44
|
const rulerEntity = playground.entityManager.getEntity<RulerConfigEntity>(RulerConfigEntity);
|
|
45
|
+
const stateEntity = playground.entityManager.getEntity<EditorStateConfigEntity>(EditorStateConfigEntity);
|
|
37
46
|
// 新版隐藏标尺
|
|
38
47
|
if (rulerEntity) {
|
|
39
48
|
rulerEntity.updateConfig({
|
|
@@ -41,6 +50,40 @@ export class PlaygroundContribution2d implements PlaygroundContribution {
|
|
|
41
50
|
gridVisible: false,
|
|
42
51
|
});
|
|
43
52
|
}
|
|
53
|
+
if (stateEntity) {
|
|
54
|
+
stateEntity.registerState({
|
|
55
|
+
id: 'FULL_SCREEN',
|
|
56
|
+
icon: 'gedit-toolbar-full',
|
|
57
|
+
title: '全屏',
|
|
58
|
+
priority: 6,
|
|
59
|
+
cancelMode: 'once',
|
|
60
|
+
handle: () => {
|
|
61
|
+
this.commandService.executeCommand(CommonCommands.TOGGLE_MAXIMIZED.id);
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
playground.config.scrollPageBoundsToCenter();
|
|
64
|
+
}, 10);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
stateEntity.registerState({
|
|
68
|
+
id: 'ADD_ELEMENT',
|
|
69
|
+
icon: 'gedit-toolbar-add',
|
|
70
|
+
title: '添加',
|
|
71
|
+
shortcut: '',
|
|
72
|
+
showTitle: true,
|
|
73
|
+
priority: 0,
|
|
74
|
+
cancelMode: 'once',
|
|
75
|
+
handle: (_: any, e: any) => {
|
|
76
|
+
const dom = e.event.target as HTMLElement;
|
|
77
|
+
const parentNode = (dom.className.match('gedit-toolbar-item') ? dom : dom.parentNode) as HTMLDivElement;
|
|
78
|
+
const rect = parentNode.getBoundingClientRect();
|
|
79
|
+
this.menuRender.render({
|
|
80
|
+
menuPath: this.config.contextMenuPath!,
|
|
81
|
+
anchor: {x: rect.x + rect.width + 8, y: rect.y},
|
|
82
|
+
args: [Editor2dNode.GLOBAL_ADD_EVENT],
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
44
87
|
// 模板编辑器模式
|
|
45
88
|
if (this.modelOpts.isTemplate) {
|
|
46
89
|
// playground.getConfigEntity<RulerConfigEntity>(RulerConfigEntity).updateConfig({
|