@gedit/editor-2d 0.2.47 → 0.2.48

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.
@@ -88,6 +88,7 @@ export class CanvasLayer extends Layer<PlaygroundContext2d> {
88
88
  () => !!this.documentEntity.config?.visible
89
89
  );
90
90
  this.canvasDrawer = new CanvasDraw({
91
+ entityManager: this.entityManager,
91
92
  host: this.node,
92
93
  renderEngine: this.context.renderEngine,
93
94
  assetsURI: this.getAssetsURI(),
@@ -105,6 +106,14 @@ export class CanvasLayer extends Layer<PlaygroundContext2d> {
105
106
  ]);
106
107
  // this.entityManager.getEntity<RulerConfigEntity>(RulerConfigEntity)?.customizeOriginClick(this.config.scrollPageBoundsToCenter.bind(this));
107
108
  this.config.loading = true;
109
+ if (this.stateService) {
110
+ this.toDispose.push(this.stateService?.onStateChanged(state => {
111
+ // 布局完成后再归位画布;
112
+ if (state === 'ready') {
113
+ this.tryToResizeToCenter();
114
+ }
115
+ }));
116
+ }
108
117
  }
109
118
  onContainerInitOrigin(
110
119
  entity?: Editor2dEntity,
@@ -148,28 +157,26 @@ export class CanvasLayer extends Layer<PlaygroundContext2d> {
148
157
  }
149
158
  }
150
159
  };
151
- onUpdateEntity(update: boolean): void {
152
- clearTimeout(this.updateTimeout);
153
- this.updateTimeout = setTimeout(() => {
154
- const updateList = getListData(this.updateList);
155
- updateList.forEach(item => {
156
- if (item.disposed) {
157
- return;
158
- }
159
- // console.log('------------------updateddddddddddddddd-----------', item.name);
160
- this.selectionEntityManager.updateEntity(item.id, item);
161
- const entity = this.selectionEntityManager.nodeEntitiesCache.get(item.id);
162
- this.onContainerInitOrigin(entity, update);
163
- });
164
- this.updateList = [];
165
- }, 150);
166
- }
160
+ onUpdateEntity = debounce((update: boolean) => {
161
+ const updateList = getListData(this.updateList);
162
+ updateList.forEach(item => {
163
+ if (item.disposed) {
164
+ return;
165
+ }
166
+ // console.log('------------------updateddddddddddddddd-----------', item);
167
+ this.selectionEntityManager.updateEntity(item.id, item, this.config.config.zoom);
168
+ const entity = this.selectionEntityManager.nodeEntitiesCache.get(item.id);
169
+ this.onContainerInitOrigin(entity, update);
170
+ });
171
+ this.updateList = [];
172
+ });
173
+
167
174
  onGameObjectChange(e: GameObjectChangeEvent): void {
168
- const { gameObject, state } = e;
175
+ const { gameObject, state, node } = e;
169
176
  switch (e.type) {
170
177
  case GameObjectEventType.CREATE:
171
- this.document?.updateNode(e.node, { error: undefined });
172
- this.selectionEntityManager.createEntity(gameObject.id, e.node, gameObject!, !!state?.selectable, !!state?.adsorbable);
178
+ this.document?.updateNode(node, { error: undefined });
179
+ this.selectionEntityManager.createEntity(gameObject.id, node, gameObject!, !!state?.selectable, !!state?.adsorbable);
173
180
  break;
174
181
  case GameObjectEventType.DESTROY:
175
182
  this.selectionEntityManager.removeEntity(gameObject.id);
@@ -179,12 +186,12 @@ export class CanvasLayer extends Layer<PlaygroundContext2d> {
179
186
  // console.log('------------------update-----------', gameObject.name);
180
187
  if (!this.updateList.includes(gameObject)) {
181
188
  this.updateList.push(gameObject);
182
- this.nodeCache.set(gameObject.id, e.node);
189
+ this.nodeCache.set(gameObject.id, node);
183
190
  }
184
191
  this.onUpdateEntity(true);
185
192
  break;
186
193
  case GameObjectEventType.ERROR:
187
- this.document?.updateNode(e.node, {error: e.error});
194
+ this.document?.updateNode(node, {error: e.error});
188
195
  break;
189
196
  }
190
197
  this.context.onCanvasDataChangedEmitter.fire(this.canvasDrawer!);
@@ -207,7 +214,7 @@ export class CanvasLayer extends Layer<PlaygroundContext2d> {
207
214
  if (!this.config.loading && !reload) return;
208
215
  if (loaded || allCount <= currentCount || allCount === 0) {
209
216
  this.config.loading = false;
210
- this.tryToResizeToCenter();
217
+ // this.tryToResizeToCenter();
211
218
  this.node.classList.add('ready');
212
219
  this.loaded();
213
220
  } else {
@@ -236,6 +243,15 @@ export class CanvasLayer extends Layer<PlaygroundContext2d> {
236
243
  onZoom = debounce(() => {
237
244
  const config = this.config.config;
238
245
  this.canvasDrawer?.refreshScale(true, config.zoom);
246
+ const selectedEntities = this.selectionEntityManager.getSelectedEntities();
247
+ if (this.document?.engineName === 'dom' && selectedEntities?.length) {
248
+ selectedEntities.forEach(c => {
249
+ const {gameObject} = c;
250
+ if (gameObject) {
251
+ this.selectionEntityManager.updateEntity(gameObject.id, gameObject, this.config.config.zoom);
252
+ }
253
+ });
254
+ }
239
255
  });
240
256
  onResize = debounce((size: PipelineDimension) => {
241
257
  const renderWidget = this.canvasDrawer?.renderWidget;
@@ -254,11 +270,11 @@ export class CanvasLayer extends Layer<PlaygroundContext2d> {
254
270
  private currentRectangle: Rectangle | undefined;
255
271
  // private currentResolution = 1;
256
272
 
257
- tryToResizeToCenter(): void {
273
+ tryToResizeToCenter = debounce(() => {
258
274
  const {visible } = this.documentEntity.config;
259
275
  // const resolution = appConfig?.resolution || 1;
260
276
  const size = this.canvasDrawer?.getSceneSize();
261
- if (!visible || !size || this.config.loading || this.config.config.width === 0 || this.config.config.height === 0) return;
277
+ if (!visible || !size || this.config.config.width === 0 || this.config.config.height === 0) return;
262
278
  const newRect = new Rectangle(0, 0, size.width, size.height);
263
279
  if (!this.currentRectangle || !this.currentRectangle.isEqual(newRect)) {
264
280
  this.currentRectangle = newRect;
@@ -268,7 +284,7 @@ export class CanvasLayer extends Layer<PlaygroundContext2d> {
268
284
  this.config.scrollPageBoundsToCenter(true, 16, !this.context.options.isTemplate)
269
285
  .then(() => this.onZoom());
270
286
  }
271
- }
287
+ }, 100); // 打开时会有一次 tag 大小的视图,宽是 98px,,dom 下没有引擎加载,会响应 98 宽,加 100 ms 延时
272
288
  draw(): void {
273
289
  const config = this.documentEntity.config;
274
290
  const document = config.document;
@@ -18,7 +18,7 @@ import { HistoryService } from '@gedit/history';
18
18
  import { Editor2dModelOptions, Editor2dNode } from '../model/editor2d';
19
19
  import { ContextMenuRenderer } from '@gedit/layout';
20
20
  import { CommandService } from '@gedit/command';
21
- import { CommonCommands } from '@gedit/application-common/lib/browser';
21
+ import { CommonCommands, FrontendApplicationStateService } from '@gedit/application-common/lib/browser';
22
22
  import { ExtendEditLayer, EXTEND_EDIT_STATE } from './extend-edit-layer';
23
23
  import { Editor2dSelection } from '../model/editor2d-selection';
24
24
 
@@ -32,6 +32,7 @@ export class PlaygroundContribution2d implements PlaygroundContribution {
32
32
  @inject(ContextMenuRenderer) readonly menuRender: ContextMenuRenderer;
33
33
  @inject(Editor2dSelection) readonly editor2dSelection: Editor2dSelection;
34
34
  @inject(PathPointSelectionService) readonly pathPointSelectionService: PathPointSelectionService;
35
+ @inject(FrontendApplicationStateService) readonly stateService: FrontendApplicationStateService;
35
36
  registerPlayground(registry: PlaygroundRegistry): void {
36
37
  registry.registerLayer(CanvasLayer);
37
38
  registry.registerLayer(PathEditLayer);
@@ -110,8 +111,19 @@ export class PlaygroundContribution2d implements PlaygroundContribution {
110
111
  percentageInfoVisible: false,
111
112
  });
112
113
  }
113
- playground.getConfigEntity<SnaplineConfigEntity>(SnaplineConfigEntity).updateConfig({
114
- originlineVisible: isComponent, // 是否隐藏原点线条,如果是组件模式则显示
114
+ const snaplineEntity = playground.getConfigEntity<SnaplineConfigEntity>(SnaplineConfigEntity);
115
+ snaplineEntity.updateConfig({
116
+ lines: [],
117
+ originlineVisible: this.appConfig.configData?.engine === 'dom' ? false : isComponent, // 是否隐藏原点线条,如果是组件模式则显示
118
+ });
119
+ this.stateService.onStateChanged(state => {
120
+ if (state === 'initialized_layout') {
121
+ // 部局完成后再是否显示中心线,pixi 组件用
122
+ snaplineEntity.updateConfig({
123
+ lines: [],
124
+ originlineVisible: this.appConfig.configData?.engine === 'dom' ? false : isComponent,
125
+ });
126
+ }
115
127
  });
116
128
  playground.toDispose.push(
117
129
  // TODO 放在这里处理会增加复杂度
@@ -120,6 +120,12 @@ export class SelectionEntityManager {
120
120
  entity.nodeId = node.id;
121
121
  entity.context = this.context;
122
122
  entity.transform.sizeToScale = !!deco.sizeToScale;
123
+ if (deco.useComponentSceneSize) {
124
+ entity.transform.componentSceneSize = {
125
+ width: gameObject.data.scene?.width || 400,
126
+ height: gameObject.data.scene?.height || 400,
127
+ };
128
+ }
123
129
 
124
130
  this.setTransformMask(entity, nodePath, node);
125
131
  // 切换选择框的类型,如圆形、矩形, 默认矩形
@@ -209,7 +215,7 @@ export class SelectionEntityManager {
209
215
  entity.dispose();
210
216
  }
211
217
  }
212
- updateEntity(nodePath: string, gameObject: GameObject): void {
218
+ updateEntity(nodePath: string, gameObject: GameObject, scale?: number): void {
213
219
  const register = this.context.renderEngine.getGameObjectIDERegister(gameObject.scene.config.engine, gameObject.type);
214
220
  const deco = register.decoration;
215
221
  const entity = this.nodeEntitiesCache.get(nodePath);
@@ -225,7 +231,13 @@ export class SelectionEntityManager {
225
231
  }
226
232
  }
227
233
  entity.transform.isContainer = !!deco.isContainer;
228
- entity.update(register.getSelectionData(gameObject));
234
+ if (deco.useComponentSceneSize) {
235
+ entity.transform.componentSceneSize = {
236
+ width: gameObject.data.scene?.width || 400,
237
+ height: gameObject.data.scene?.height || 400,
238
+ };
239
+ }
240
+ entity.update(register.getSelectionData(gameObject, scale));
229
241
  entity.ignoreTransformChanged = false;
230
242
  const sizeVisible = !this.isHidden(entity.node); // && (entity.transform.size.width > 0 && entity.transform.size.height > 0 || !!deco.isContainer);
231
243
  const opacityZero = this.isOpacityZero(node);
@@ -55,3 +55,9 @@
55
55
  background-color: var(--g-icon-foreground);
56
56
  }
57
57
 
58
+
59
+ .gedit-editor-snapshots {
60
+ position: absolute;
61
+ z-index: -9999;
62
+ opacity: 0;
63
+ }
@@ -76,7 +76,7 @@ export class SnapshotCreator extends DisposableImpl {
76
76
  if (!host) {
77
77
  host = document.createElement('div');
78
78
  host.className = 'gedit-editor-snapshots';
79
- host.style.display = 'none';
79
+ // host.style.display = 'none';
80
80
  document.body.appendChild(host);
81
81
  }
82
82
  this.drawer = new CanvasDraw({
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 GEdit
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.