@plait/core 0.0.40 → 0.0.42

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;
@@ -730,7 +731,7 @@ function isNoSelectionElement(e) {
730
731
  * @param viewZoom 视图上显示的 zoom 缩放级别 %
731
732
  * @returns zoom 真实的 zoom
732
733
  */
733
- const transformViewZoom = (viewZoom) => (2 * viewZoom - 100) / viewZoom;
734
+ const transformViewZoom = (viewZoom) => 2 - 100 / viewZoom;
734
735
  /**
735
736
  * zoom 转 viewZoom
736
737
  * @param zoom this.board.viewport.zoom
@@ -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,69 @@ 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.markForCheck();
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
+ if (board.cursor !== BaseCursorStatus.move) {
937
+ updateCursorStatus(board, BaseCursorStatus.move);
938
+ const boardComponent = PLAIT_BOARD_TO_COMPONENT.get(board);
939
+ boardComponent.cdr.markForCheck();
940
+ }
941
+ event.preventDefault();
942
+ }
943
+ keydown(event);
944
+ };
945
+ board.keyup = (event) => {
946
+ if (board.selection && !board.readonly && event.code === 'Space') {
947
+ updateCursorStatus(board, BaseCursorStatus.select);
948
+ const boardComponent = PLAIT_BOARD_TO_COMPONENT.get(board);
949
+ boardComponent.cdr.markForCheck();
950
+ }
951
+ keyup(event);
952
+ };
953
+ return board;
954
+ }
955
+
892
956
  function withSelection(board) {
893
957
  const { mousedown, mousemove, globalMouseup } = board;
894
958
  let start = null;
@@ -1055,18 +1119,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
1055
1119
  }] } });
1056
1120
 
1057
1121
  class PlaitBoardComponent {
1058
- constructor(cdr, elementRef, renderer2) {
1122
+ constructor(cdr, renderer2) {
1059
1123
  this.cdr = cdr;
1060
- this.elementRef = elementRef;
1061
1124
  this.renderer2 = renderer2;
1062
1125
  this.hasInitialized = false;
1063
1126
  this.destroy$ = new Subject();
1064
1127
  this._viewZoom = 100;
1065
- this.plaitBoardMove = {
1066
- isMoving: false,
1067
- x: 0,
1068
- y: 0
1069
- };
1128
+ this.isMoving = false;
1070
1129
  this.plaitValue = [];
1071
1130
  this.plaitPlugins = [];
1072
1131
  this.plaitReadonly = false;
@@ -1100,6 +1159,9 @@ class PlaitBoardComponent {
1100
1159
  get readonly() {
1101
1160
  return this.plaitReadonly;
1102
1161
  }
1162
+ get moving() {
1163
+ return this.board.cursor === BaseCursorStatus.move && this.isMoving;
1164
+ }
1103
1165
  get focused() {
1104
1166
  return this.isFocused;
1105
1167
  }
@@ -1109,6 +1171,7 @@ class PlaitBoardComponent {
1109
1171
  this.initializePlugins();
1110
1172
  this.initializeEvents();
1111
1173
  this.updateViewport();
1174
+ PLAIT_BOARD_TO_COMPONENT.set(this.board, this);
1112
1175
  BOARD_TO_ON_CHANGE.set(this.board, () => {
1113
1176
  this.cdr.detectChanges();
1114
1177
  const changeEvent = {
@@ -1137,7 +1200,7 @@ class PlaitBoardComponent {
1137
1200
  }
1138
1201
  initializePlugins() {
1139
1202
  const options = { readonly: this.plaitReadonly, allowClearBoard: this.plaitAllowClearBoard };
1140
- let board = withHistroy(withSelection(withBoard(createBoard(this.host, this.plaitValue, options))));
1203
+ let board = withMove(withHistory(withSelection(withBoard(createBoard(this.host, this.plaitValue, options)))));
1141
1204
  this.plaitPlugins.forEach(plugin => {
1142
1205
  board = plugin(board);
1143
1206
  });
@@ -1151,20 +1214,16 @@ class PlaitBoardComponent {
1151
1214
  .pipe(takeUntil(this.destroy$))
1152
1215
  .subscribe((event) => {
1153
1216
  this.board.mousedown(event);
1154
- this.setCursorStatus();
1155
- this.isFocused && this.isMoveMode && this.initMove(event);
1156
1217
  });
1157
1218
  fromEvent(this.host, 'mousemove')
1158
1219
  .pipe(takeUntil(this.destroy$))
1159
1220
  .subscribe((event) => {
1160
1221
  this.board.mousemove(event);
1161
- this.isFocused && this.isMoveMode && this.plaitBoardMove.isMoving && this.moving(event);
1162
1222
  });
1163
1223
  fromEvent(document, 'mouseup')
1164
1224
  .pipe(takeUntil(this.destroy$))
1165
1225
  .subscribe((event) => {
1166
1226
  this.board.globalMouseup(event);
1167
- this.isFocused && this.moveEnd();
1168
1227
  });
1169
1228
  fromEvent(this.host, 'dblclick')
1170
1229
  .pipe(takeUntil(this.destroy$))
@@ -1187,10 +1246,6 @@ class PlaitBoardComponent {
1187
1246
  .subscribe((event) => {
1188
1247
  var _a;
1189
1248
  (_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
1249
  });
1195
1250
  fromEvent(document, 'keyup')
1196
1251
  .pipe(takeUntil(this.destroy$), filter(() => {
@@ -1199,7 +1254,6 @@ class PlaitBoardComponent {
1199
1254
  .subscribe((event) => {
1200
1255
  var _a;
1201
1256
  (_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
1257
  });
1204
1258
  fromEvent(document, 'copy')
1205
1259
  .pipe(takeUntil(this.destroy$), filter(() => {
@@ -1242,32 +1296,6 @@ class PlaitBoardComponent {
1242
1296
  const viewBox = getViewBox(this.board);
1243
1297
  this.renderer2.setAttribute(this.host, 'viewBox', `${viewBox.minX}, ${viewBox.minY}, ${viewBox.width}, ${viewBox.height}`);
1244
1298
  }
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
1299
  // 拖拽模式
1272
1300
  changeMoveMode(cursorStatus) {
1273
1301
  updateCursorStatus(this.board, cursorStatus);
@@ -1310,16 +1338,13 @@ class PlaitBoardComponent {
1310
1338
  this.destroy$.complete();
1311
1339
  HOST_TO_ROUGH_SVG.delete(this.host);
1312
1340
  }
1341
+ movingChange(isMoving) {
1342
+ this.isMoving = isMoving;
1343
+ }
1313
1344
  }
1314
- 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>
1345
+ PlaitBoardComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: PlaitBoardComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Component });
1346
+ 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: `
1347
+ <svg #svg width="100%" height="100%" style="position: relative"></svg>
1323
1348
  <plait-toolbar
1324
1349
  *ngIf="isFocused && !toolbarTemplateRef"
1325
1350
  [cursorStatus]="board.cursor"
@@ -1346,13 +1371,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
1346
1371
  args: [{
1347
1372
  selector: 'plait-board',
1348
1373
  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>
1374
+ <svg #svg width="100%" height="100%" style="position: relative"></svg>
1356
1375
  <plait-toolbar
1357
1376
  *ngIf="isFocused && !toolbarTemplateRef"
1358
1377
  [cursorStatus]="board.cursor"
@@ -1376,7 +1395,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
1376
1395
  `,
1377
1396
  changeDetection: ChangeDetectionStrategy.OnPush
1378
1397
  }]
1379
- }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: i0.Renderer2 }]; }, propDecorators: { hostClass: [{
1398
+ }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i0.Renderer2 }]; }, propDecorators: { hostClass: [{
1380
1399
  type: HostBinding,
1381
1400
  args: ['class']
1382
1401
  }], svg: [{
@@ -1402,6 +1421,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
1402
1421
  }], readonly: [{
1403
1422
  type: HostBinding,
1404
1423
  args: ['class.readonly']
1424
+ }], moving: [{
1425
+ type: HostBinding,
1426
+ args: ['class.moving']
1405
1427
  }], focused: [{
1406
1428
  type: HostBinding,
1407
1429
  args: ['class.focused']
@@ -1432,5 +1454,5 @@ const CLIP_BOARD_FORMAT_KEY = 'x-plait-fragment';
1432
1454
  * Generated bundle index. Do not edit.
1433
1455
  */
1434
1456
 
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 };
1457
+ 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
1458
  //# sourceMappingURL=plait-core.mjs.map