@plait/core 0.0.40 → 0.0.41

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.
@@ -270,6 +270,7 @@ const FLUSHING = new WeakMap();
270
270
  const IS_TEXT_EDITABLE = new WeakMap();
271
271
  const BOARD_TO_ON_CHANGE = new WeakMap();
272
272
  const HOST_TO_ROUGH_SVG = new WeakMap();
273
+ const PLAIT_BOARD_TO_COMPONENT = new WeakMap();
273
274
 
274
275
  const applyToDraft = (board, selection, viewport, op) => {
275
276
  switch (op.type) {
@@ -828,7 +829,7 @@ const PlaitHistoryBoard = {
828
829
  }
829
830
  };
830
831
 
831
- function withHistroy(board) {
832
+ function withHistory(board) {
832
833
  const { apply, keydown } = board;
833
834
  board.history = { undos: [], redos: [] };
834
835
  board.redo = () => {
@@ -912,6 +913,69 @@ function withHistroy(board) {
912
913
  return board;
913
914
  }
914
915
 
916
+ function withMove(board) {
917
+ const { mousedown, mousemove, globalMouseup, keydown, keyup } = board;
918
+ const plaitBoardMove = {
919
+ x: 0,
920
+ y: 0
921
+ };
922
+ board.mousedown = (event) => {
923
+ if (board.readonly) {
924
+ updateCursorStatus(board, BaseCursorStatus.move);
925
+ }
926
+ else if (!board.selection) {
927
+ updateCursorStatus(board, BaseCursorStatus.select);
928
+ }
929
+ if (board.cursor === BaseCursorStatus.move && board.selection) {
930
+ const boardComponent = PLAIT_BOARD_TO_COMPONENT.get(board);
931
+ boardComponent.movingChange(true);
932
+ plaitBoardMove.x = event.x;
933
+ plaitBoardMove.y = event.y;
934
+ boardComponent.cdr.detectChanges();
935
+ }
936
+ mousedown(event);
937
+ };
938
+ board.mousemove = (event) => {
939
+ const boardComponent = PLAIT_BOARD_TO_COMPONENT.get(board);
940
+ if (board.cursor === BaseCursorStatus.move && board.selection && boardComponent.isMoving) {
941
+ const viewport = board?.viewport;
942
+ Transforms.setViewport(board, {
943
+ ...viewport,
944
+ offsetX: viewport.offsetX + ((event.x - plaitBoardMove.x) * 100) / transformZoom(board.viewport.zoom),
945
+ offsetY: viewport.offsetY + ((event.y - plaitBoardMove.y) * 100) / transformZoom(board.viewport.zoom)
946
+ });
947
+ plaitBoardMove.x = event.x;
948
+ plaitBoardMove.y = event.y;
949
+ }
950
+ mousemove(event);
951
+ };
952
+ board.globalMouseup = (event) => {
953
+ if (board.selection) {
954
+ const boardComponent = PLAIT_BOARD_TO_COMPONENT.get(board);
955
+ boardComponent.movingChange(false);
956
+ plaitBoardMove.x = 0;
957
+ plaitBoardMove.y = 0;
958
+ }
959
+ globalMouseup(event);
960
+ };
961
+ board.keydown = (event) => {
962
+ if (board.selection && event.code === 'Space') {
963
+ updateCursorStatus(board, BaseCursorStatus.move);
964
+ const boardComponent = PLAIT_BOARD_TO_COMPONENT.get(board);
965
+ boardComponent.cdr.detectChanges();
966
+ event.preventDefault();
967
+ }
968
+ keydown(event);
969
+ };
970
+ board.keyup = (event) => {
971
+ board.selection && !board.readonly && event.code === 'Space' && updateCursorStatus(board, BaseCursorStatus.select);
972
+ const boardComponent = PLAIT_BOARD_TO_COMPONENT.get(board);
973
+ boardComponent.cdr.detectChanges();
974
+ keyup(event);
975
+ };
976
+ return board;
977
+ }
978
+
915
979
  function withSelection(board) {
916
980
  const { mousedown, mousemove, globalMouseup } = board;
917
981
  let start = null;
@@ -1085,11 +1149,7 @@ class PlaitBoardComponent {
1085
1149
  this.hasInitialized = false;
1086
1150
  this.destroy$ = new Subject();
1087
1151
  this._viewZoom = 100;
1088
- this.plaitBoardMove = {
1089
- isMoving: false,
1090
- x: 0,
1091
- y: 0
1092
- };
1152
+ this.isMoving = false;
1093
1153
  this.plaitValue = [];
1094
1154
  this.plaitPlugins = [];
1095
1155
  this.plaitReadonly = false;
@@ -1122,6 +1182,9 @@ class PlaitBoardComponent {
1122
1182
  get readonly() {
1123
1183
  return this.plaitReadonly;
1124
1184
  }
1185
+ get moving() {
1186
+ return this.isMoving;
1187
+ }
1125
1188
  get focused() {
1126
1189
  return this.isFocused;
1127
1190
  }
@@ -1131,6 +1194,7 @@ class PlaitBoardComponent {
1131
1194
  this.initializePlugins();
1132
1195
  this.initializeEvents();
1133
1196
  this.updateViewport();
1197
+ PLAIT_BOARD_TO_COMPONENT.set(this.board, this);
1134
1198
  BOARD_TO_ON_CHANGE.set(this.board, () => {
1135
1199
  this.cdr.detectChanges();
1136
1200
  const changeEvent = {
@@ -1159,7 +1223,7 @@ class PlaitBoardComponent {
1159
1223
  }
1160
1224
  initializePlugins() {
1161
1225
  const options = { readonly: this.plaitReadonly, allowClearBoard: this.plaitAllowClearBoard };
1162
- let board = withHistroy(withSelection(withBoard(createBoard(this.host, this.plaitValue, options))));
1226
+ let board = withMove(withHistory(withSelection(withBoard(createBoard(this.host, this.plaitValue, options)))));
1163
1227
  this.plaitPlugins.forEach(plugin => {
1164
1228
  board = plugin(board);
1165
1229
  });
@@ -1173,20 +1237,16 @@ class PlaitBoardComponent {
1173
1237
  .pipe(takeUntil(this.destroy$))
1174
1238
  .subscribe((event) => {
1175
1239
  this.board.mousedown(event);
1176
- this.setCursorStatus();
1177
- this.isFocused && this.isMoveMode && this.initMove(event);
1178
1240
  });
1179
1241
  fromEvent(this.host, 'mousemove')
1180
1242
  .pipe(takeUntil(this.destroy$))
1181
1243
  .subscribe((event) => {
1182
1244
  this.board.mousemove(event);
1183
- this.isFocused && this.isMoveMode && this.plaitBoardMove.isMoving && this.moving(event);
1184
1245
  });
1185
1246
  fromEvent(document, 'mouseup')
1186
1247
  .pipe(takeUntil(this.destroy$))
1187
1248
  .subscribe((event) => {
1188
1249
  this.board.globalMouseup(event);
1189
- this.isFocused && this.moveEnd();
1190
1250
  });
1191
1251
  fromEvent(this.host, 'dblclick')
1192
1252
  .pipe(takeUntil(this.destroy$))
@@ -1212,10 +1272,6 @@ class PlaitBoardComponent {
1212
1272
  }))
1213
1273
  .subscribe((event) => {
1214
1274
  this.board?.keydown(event);
1215
- if (this.isFocused && event.code === 'Space') {
1216
- this.changeMoveMode(BaseCursorStatus.move);
1217
- event.preventDefault();
1218
- }
1219
1275
  });
1220
1276
  fromEvent(document, 'keyup')
1221
1277
  .pipe(takeUntil(this.destroy$), filter(() => {
@@ -1223,7 +1279,6 @@ class PlaitBoardComponent {
1223
1279
  }))
1224
1280
  .subscribe((event) => {
1225
1281
  this.board?.keyup(event);
1226
- this.isFocused && !this.plaitReadonly && event.code === 'Space' && this.changeMoveMode(BaseCursorStatus.select);
1227
1282
  });
1228
1283
  fromEvent(document, 'copy')
1229
1284
  .pipe(takeUntil(this.destroy$), filter(() => {
@@ -1262,35 +1317,6 @@ class PlaitBoardComponent {
1262
1317
  const viewBox = getViewBox(this.board);
1263
1318
  this.renderer2.setAttribute(this.host, 'viewBox', `${viewBox.minX}, ${viewBox.minY}, ${viewBox.width}, ${viewBox.height}`);
1264
1319
  }
1265
- setCursorStatus() {
1266
- if (this.plaitReadonly) {
1267
- this.changeMoveMode(BaseCursorStatus.move);
1268
- }
1269
- else if (!this.isFocused) {
1270
- this.changeMoveMode(BaseCursorStatus.select);
1271
- }
1272
- }
1273
- initMove(e) {
1274
- this.plaitBoardMove.isMoving = true;
1275
- this.plaitBoardMove.x = e.x;
1276
- this.plaitBoardMove.y = e.y;
1277
- this.cdr.detectChanges();
1278
- }
1279
- moving(e) {
1280
- const viewport = this.board?.viewport;
1281
- Transforms.setViewport(this.board, {
1282
- ...viewport,
1283
- offsetX: viewport.offsetX + ((e.x - this.plaitBoardMove.x) * 100) / this._viewZoom,
1284
- offsetY: viewport.offsetY + ((e.y - this.plaitBoardMove.y) * 100) / this._viewZoom
1285
- });
1286
- this.plaitBoardMove.x = e.x;
1287
- this.plaitBoardMove.y = e.y;
1288
- }
1289
- moveEnd() {
1290
- this.plaitBoardMove.isMoving = false;
1291
- this.plaitBoardMove.x = 0;
1292
- this.plaitBoardMove.y = 0;
1293
- }
1294
1320
  // 拖拽模式
1295
1321
  changeMoveMode(cursorStatus) {
1296
1322
  updateCursorStatus(this.board, cursorStatus);
@@ -1338,16 +1364,13 @@ class PlaitBoardComponent {
1338
1364
  this.destroy$.complete();
1339
1365
  HOST_TO_ROUGH_SVG.delete(this.host);
1340
1366
  }
1367
+ movingChange(isMoving) {
1368
+ this.isMoving = isMoving;
1369
+ }
1341
1370
  }
1342
1371
  PlaitBoardComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: PlaitBoardComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ElementRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Component });
1343
- PlaitBoardComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.11", type: PlaitBoardComponent, selector: "plait-board", inputs: { plaitValue: "plaitValue", plaitViewport: "plaitViewport", plaitPlugins: "plaitPlugins", plaitReadonly: "plaitReadonly", plaitAllowClearBoard: "plaitAllowClearBoard" }, outputs: { plaitChange: "plaitChange", plaitBoardInitialized: "plaitBoardInitialized" }, host: { properties: { "class": "this.hostClass", "class.readonly": "this.readonly", "class.focused": "this.focused" } }, queries: [{ propertyName: "toolbarTemplateRef", first: true, predicate: ["plaitToolbar"], descendants: true }], viewQueries: [{ propertyName: "svg", first: true, predicate: ["svg"], descendants: true, static: true }], usesOnChanges: true, ngImport: i0, template: `
1344
- <svg
1345
- #svg
1346
- width="100%"
1347
- height="100%"
1348
- style="position: relative"
1349
- [style.cursor]="isMoveMode ? (plaitBoardMove.isMoving ? 'grabbing' : 'grab') : 'auto'"
1350
- ></svg>
1372
+ PlaitBoardComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.11", type: PlaitBoardComponent, selector: "plait-board", inputs: { plaitValue: "plaitValue", plaitViewport: "plaitViewport", plaitPlugins: "plaitPlugins", plaitReadonly: "plaitReadonly", plaitAllowClearBoard: "plaitAllowClearBoard" }, outputs: { plaitChange: "plaitChange", plaitBoardInitialized: "plaitBoardInitialized" }, host: { properties: { "class": "this.hostClass", "class.readonly": "this.readonly", "class.moving": "this.moving", "class.focused": "this.focused" } }, queries: [{ propertyName: "toolbarTemplateRef", first: true, predicate: ["plaitToolbar"], descendants: true }], viewQueries: [{ propertyName: "svg", first: true, predicate: ["svg"], descendants: true, static: true }], usesOnChanges: true, ngImport: i0, template: `
1373
+ <svg #svg width="100%" height="100%" style="position: relative"></svg>
1351
1374
  <plait-toolbar
1352
1375
  *ngIf="isFocused && !toolbarTemplateRef"
1353
1376
  [cursorStatus]="board.cursor"
@@ -1374,13 +1397,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
1374
1397
  args: [{
1375
1398
  selector: 'plait-board',
1376
1399
  template: `
1377
- <svg
1378
- #svg
1379
- width="100%"
1380
- height="100%"
1381
- style="position: relative"
1382
- [style.cursor]="isMoveMode ? (plaitBoardMove.isMoving ? 'grabbing' : 'grab') : 'auto'"
1383
- ></svg>
1400
+ <svg #svg width="100%" height="100%" style="position: relative"></svg>
1384
1401
  <plait-toolbar
1385
1402
  *ngIf="isFocused && !toolbarTemplateRef"
1386
1403
  [cursorStatus]="board.cursor"
@@ -1430,6 +1447,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
1430
1447
  }], readonly: [{
1431
1448
  type: HostBinding,
1432
1449
  args: ['class.readonly']
1450
+ }], moving: [{
1451
+ type: HostBinding,
1452
+ args: ['class.moving']
1433
1453
  }], focused: [{
1434
1454
  type: HostBinding,
1435
1455
  args: ['class.focused']
@@ -1460,5 +1480,5 @@ const CLIP_BOARD_FORMAT_KEY = 'x-plait-fragment';
1460
1480
  * Generated bundle index. Do not edit.
1461
1481
  */
1462
1482
 
1463
- export { BOARD_TO_ON_CHANGE, BaseCursorStatus, CLIP_BOARD_FORMAT_KEY, FLUSHING, HOST_TO_ROUGH_SVG, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_FIREFOX, IS_IOS, IS_SAFARI, IS_TEXT_EDITABLE, MERGING, NS, Path, PlaitBoardComponent, PlaitElementComponent, PlaitHistoryBoard, PlaitModule, PlaitNode, PlaitOperation, PlaitToolbarComponent, SAVING, Transforms, Viewport, createG, createSVG, createText, distanceBetweenPointAndPoint, distanceBetweenPointAndSegment, getViewBox, hotkeys, idCreator, inverse, isNoSelectionElement, isNullOrUndefined, isSetViewportOperation, rotate, shouldClear, shouldMerge, shouldSave, toPoint, toRectangleClient, transformPoint, transformPoints, transformViewZoom, transformZoom, updateCursorStatus };
1483
+ export { BOARD_TO_ON_CHANGE, BaseCursorStatus, CLIP_BOARD_FORMAT_KEY, FLUSHING, HOST_TO_ROUGH_SVG, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_FIREFOX, IS_IOS, IS_SAFARI, IS_TEXT_EDITABLE, MERGING, NS, PLAIT_BOARD_TO_COMPONENT, Path, PlaitBoardComponent, PlaitElementComponent, PlaitHistoryBoard, PlaitModule, PlaitNode, PlaitOperation, PlaitToolbarComponent, SAVING, Transforms, Viewport, createG, createSVG, createText, distanceBetweenPointAndPoint, distanceBetweenPointAndSegment, getViewBox, hotkeys, idCreator, inverse, isNoSelectionElement, isNullOrUndefined, isSetViewportOperation, rotate, shouldClear, shouldMerge, shouldSave, toPoint, toRectangleClient, transformPoint, transformPoints, transformViewZoom, transformZoom, updateCursorStatus };
1464
1484
  //# sourceMappingURL=plait-core.mjs.map