@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.
@@ -250,6 +250,7 @@ const FLUSHING = new WeakMap();
250
250
  const IS_TEXT_EDITABLE = new WeakMap();
251
251
  const BOARD_TO_ON_CHANGE = new WeakMap();
252
252
  const HOST_TO_ROUGH_SVG = new WeakMap();
253
+ const PLAIT_BOARD_TO_COMPONENT = new WeakMap();
253
254
 
254
255
  const applyToDraft = (board, selection, viewport, op) => {
255
256
  var _a, _b;
@@ -805,7 +806,7 @@ const PlaitHistoryBoard = {
805
806
  }
806
807
  };
807
808
 
808
- function withHistroy(board) {
809
+ function withHistory(board) {
809
810
  const { apply, keydown } = board;
810
811
  board.history = { undos: [], redos: [] };
811
812
  board.redo = () => {
@@ -889,6 +890,65 @@ function withHistroy(board) {
889
890
  return board;
890
891
  }
891
892
 
893
+ function withMove(board) {
894
+ const { mousedown, mousemove, globalMouseup, keydown, keyup } = board;
895
+ const plaitBoardMove = {
896
+ x: 0,
897
+ y: 0
898
+ };
899
+ board.mousedown = (event) => {
900
+ if (board.readonly) {
901
+ updateCursorStatus(board, BaseCursorStatus.move);
902
+ }
903
+ else if (!board.selection) {
904
+ updateCursorStatus(board, BaseCursorStatus.select);
905
+ }
906
+ if (board.cursor === BaseCursorStatus.move && board.selection) {
907
+ const boardComponent = PLAIT_BOARD_TO_COMPONENT.get(board);
908
+ boardComponent.movingChange(true);
909
+ plaitBoardMove.x = event.x;
910
+ plaitBoardMove.y = event.y;
911
+ boardComponent.cdr.detectChanges();
912
+ }
913
+ mousedown(event);
914
+ };
915
+ board.mousemove = (event) => {
916
+ const boardComponent = PLAIT_BOARD_TO_COMPONENT.get(board);
917
+ if (board.cursor === BaseCursorStatus.move && board.selection && boardComponent.isMoving) {
918
+ const viewport = board === null || board === void 0 ? void 0 : board.viewport;
919
+ Transforms.setViewport(board, Object.assign(Object.assign({}, viewport), { offsetX: viewport.offsetX + ((event.x - plaitBoardMove.x) * 100) / transformZoom(board.viewport.zoom), offsetY: viewport.offsetY + ((event.y - plaitBoardMove.y) * 100) / transformZoom(board.viewport.zoom) }));
920
+ plaitBoardMove.x = event.x;
921
+ plaitBoardMove.y = event.y;
922
+ }
923
+ mousemove(event);
924
+ };
925
+ board.globalMouseup = (event) => {
926
+ if (board.selection) {
927
+ const boardComponent = PLAIT_BOARD_TO_COMPONENT.get(board);
928
+ boardComponent.movingChange(false);
929
+ plaitBoardMove.x = 0;
930
+ plaitBoardMove.y = 0;
931
+ }
932
+ globalMouseup(event);
933
+ };
934
+ board.keydown = (event) => {
935
+ if (board.selection && event.code === 'Space') {
936
+ updateCursorStatus(board, BaseCursorStatus.move);
937
+ const boardComponent = PLAIT_BOARD_TO_COMPONENT.get(board);
938
+ boardComponent.cdr.detectChanges();
939
+ event.preventDefault();
940
+ }
941
+ keydown(event);
942
+ };
943
+ board.keyup = (event) => {
944
+ board.selection && !board.readonly && event.code === 'Space' && updateCursorStatus(board, BaseCursorStatus.select);
945
+ const boardComponent = PLAIT_BOARD_TO_COMPONENT.get(board);
946
+ boardComponent.cdr.detectChanges();
947
+ keyup(event);
948
+ };
949
+ return board;
950
+ }
951
+
892
952
  function withSelection(board) {
893
953
  const { mousedown, mousemove, globalMouseup } = board;
894
954
  let start = null;
@@ -1062,11 +1122,7 @@ class PlaitBoardComponent {
1062
1122
  this.hasInitialized = false;
1063
1123
  this.destroy$ = new Subject();
1064
1124
  this._viewZoom = 100;
1065
- this.plaitBoardMove = {
1066
- isMoving: false,
1067
- x: 0,
1068
- y: 0
1069
- };
1125
+ this.isMoving = false;
1070
1126
  this.plaitValue = [];
1071
1127
  this.plaitPlugins = [];
1072
1128
  this.plaitReadonly = false;
@@ -1100,6 +1156,9 @@ class PlaitBoardComponent {
1100
1156
  get readonly() {
1101
1157
  return this.plaitReadonly;
1102
1158
  }
1159
+ get moving() {
1160
+ return this.isMoving;
1161
+ }
1103
1162
  get focused() {
1104
1163
  return this.isFocused;
1105
1164
  }
@@ -1109,6 +1168,7 @@ class PlaitBoardComponent {
1109
1168
  this.initializePlugins();
1110
1169
  this.initializeEvents();
1111
1170
  this.updateViewport();
1171
+ PLAIT_BOARD_TO_COMPONENT.set(this.board, this);
1112
1172
  BOARD_TO_ON_CHANGE.set(this.board, () => {
1113
1173
  this.cdr.detectChanges();
1114
1174
  const changeEvent = {
@@ -1137,7 +1197,7 @@ class PlaitBoardComponent {
1137
1197
  }
1138
1198
  initializePlugins() {
1139
1199
  const options = { readonly: this.plaitReadonly, allowClearBoard: this.plaitAllowClearBoard };
1140
- let board = withHistroy(withSelection(withBoard(createBoard(this.host, this.plaitValue, options))));
1200
+ let board = withMove(withHistory(withSelection(withBoard(createBoard(this.host, this.plaitValue, options)))));
1141
1201
  this.plaitPlugins.forEach(plugin => {
1142
1202
  board = plugin(board);
1143
1203
  });
@@ -1151,20 +1211,16 @@ class PlaitBoardComponent {
1151
1211
  .pipe(takeUntil(this.destroy$))
1152
1212
  .subscribe((event) => {
1153
1213
  this.board.mousedown(event);
1154
- this.setCursorStatus();
1155
- this.isFocused && this.isMoveMode && this.initMove(event);
1156
1214
  });
1157
1215
  fromEvent(this.host, 'mousemove')
1158
1216
  .pipe(takeUntil(this.destroy$))
1159
1217
  .subscribe((event) => {
1160
1218
  this.board.mousemove(event);
1161
- this.isFocused && this.isMoveMode && this.plaitBoardMove.isMoving && this.moving(event);
1162
1219
  });
1163
1220
  fromEvent(document, 'mouseup')
1164
1221
  .pipe(takeUntil(this.destroy$))
1165
1222
  .subscribe((event) => {
1166
1223
  this.board.globalMouseup(event);
1167
- this.isFocused && this.moveEnd();
1168
1224
  });
1169
1225
  fromEvent(this.host, 'dblclick')
1170
1226
  .pipe(takeUntil(this.destroy$))
@@ -1187,10 +1243,6 @@ class PlaitBoardComponent {
1187
1243
  .subscribe((event) => {
1188
1244
  var _a;
1189
1245
  (_a = this.board) === null || _a === void 0 ? void 0 : _a.keydown(event);
1190
- if (this.isFocused && event.code === 'Space') {
1191
- this.changeMoveMode(BaseCursorStatus.move);
1192
- event.preventDefault();
1193
- }
1194
1246
  });
1195
1247
  fromEvent(document, 'keyup')
1196
1248
  .pipe(takeUntil(this.destroy$), filter(() => {
@@ -1199,7 +1251,6 @@ class PlaitBoardComponent {
1199
1251
  .subscribe((event) => {
1200
1252
  var _a;
1201
1253
  (_a = this.board) === null || _a === void 0 ? void 0 : _a.keyup(event);
1202
- this.isFocused && !this.plaitReadonly && event.code === 'Space' && this.changeMoveMode(BaseCursorStatus.select);
1203
1254
  });
1204
1255
  fromEvent(document, 'copy')
1205
1256
  .pipe(takeUntil(this.destroy$), filter(() => {
@@ -1242,32 +1293,6 @@ class PlaitBoardComponent {
1242
1293
  const viewBox = getViewBox(this.board);
1243
1294
  this.renderer2.setAttribute(this.host, 'viewBox', `${viewBox.minX}, ${viewBox.minY}, ${viewBox.width}, ${viewBox.height}`);
1244
1295
  }
1245
- setCursorStatus() {
1246
- if (this.plaitReadonly) {
1247
- this.changeMoveMode(BaseCursorStatus.move);
1248
- }
1249
- else if (!this.isFocused) {
1250
- this.changeMoveMode(BaseCursorStatus.select);
1251
- }
1252
- }
1253
- initMove(e) {
1254
- this.plaitBoardMove.isMoving = true;
1255
- this.plaitBoardMove.x = e.x;
1256
- this.plaitBoardMove.y = e.y;
1257
- this.cdr.detectChanges();
1258
- }
1259
- moving(e) {
1260
- var _a;
1261
- const viewport = (_a = this.board) === null || _a === void 0 ? void 0 : _a.viewport;
1262
- Transforms.setViewport(this.board, Object.assign(Object.assign({}, viewport), { offsetX: viewport.offsetX + ((e.x - this.plaitBoardMove.x) * 100) / this._viewZoom, offsetY: viewport.offsetY + ((e.y - this.plaitBoardMove.y) * 100) / this._viewZoom }));
1263
- this.plaitBoardMove.x = e.x;
1264
- this.plaitBoardMove.y = e.y;
1265
- }
1266
- moveEnd() {
1267
- this.plaitBoardMove.isMoving = false;
1268
- this.plaitBoardMove.x = 0;
1269
- this.plaitBoardMove.y = 0;
1270
- }
1271
1296
  // 拖拽模式
1272
1297
  changeMoveMode(cursorStatus) {
1273
1298
  updateCursorStatus(this.board, cursorStatus);
@@ -1310,16 +1335,13 @@ class PlaitBoardComponent {
1310
1335
  this.destroy$.complete();
1311
1336
  HOST_TO_ROUGH_SVG.delete(this.host);
1312
1337
  }
1338
+ movingChange(isMoving) {
1339
+ this.isMoving = isMoving;
1340
+ }
1313
1341
  }
1314
1342
  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 });
1315
- 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: `
1316
- <svg
1317
- #svg
1318
- width="100%"
1319
- height="100%"
1320
- style="position: relative"
1321
- [style.cursor]="isMoveMode ? (plaitBoardMove.isMoving ? 'grabbing' : 'grab') : 'auto'"
1322
- ></svg>
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.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: `
1344
+ <svg #svg width="100%" height="100%" style="position: relative"></svg>
1323
1345
  <plait-toolbar
1324
1346
  *ngIf="isFocused && !toolbarTemplateRef"
1325
1347
  [cursorStatus]="board.cursor"
@@ -1346,13 +1368,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
1346
1368
  args: [{
1347
1369
  selector: 'plait-board',
1348
1370
  template: `
1349
- <svg
1350
- #svg
1351
- width="100%"
1352
- height="100%"
1353
- style="position: relative"
1354
- [style.cursor]="isMoveMode ? (plaitBoardMove.isMoving ? 'grabbing' : 'grab') : 'auto'"
1355
- ></svg>
1371
+ <svg #svg width="100%" height="100%" style="position: relative"></svg>
1356
1372
  <plait-toolbar
1357
1373
  *ngIf="isFocused && !toolbarTemplateRef"
1358
1374
  [cursorStatus]="board.cursor"
@@ -1402,6 +1418,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
1402
1418
  }], readonly: [{
1403
1419
  type: HostBinding,
1404
1420
  args: ['class.readonly']
1421
+ }], moving: [{
1422
+ type: HostBinding,
1423
+ args: ['class.moving']
1405
1424
  }], focused: [{
1406
1425
  type: HostBinding,
1407
1426
  args: ['class.focused']
@@ -1432,5 +1451,5 @@ const CLIP_BOARD_FORMAT_KEY = 'x-plait-fragment';
1432
1451
  * Generated bundle index. Do not edit.
1433
1452
  */
1434
1453
 
1435
- 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 };
1454
+ 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 };
1436
1455
  //# sourceMappingURL=plait-core.mjs.map