@plait/core 0.4.0 → 0.5.0

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.
@@ -1613,7 +1613,8 @@ function createBoard(children, options) {
1613
1613
  selection: null,
1614
1614
  options: options || {
1615
1615
  readonly: false,
1616
- hideScrollbar: false
1616
+ hideScrollbar: false,
1617
+ disabledScrollOnNonFocus: false
1617
1618
  },
1618
1619
  pointer: (options === null || options === void 0 ? void 0 : options.readonly) ? PlaitPointerType.hand : PlaitPointerType.selection,
1619
1620
  undo: () => { },
@@ -1856,9 +1857,9 @@ function withSelection(board) {
1856
1857
  }
1857
1858
  const range = { anchor: point, focus: point };
1858
1859
  if (PlaitBoard.isPointer(board, PlaitPointerType.selection) &&
1859
- PlaitBoard.isFocus(board) &&
1860
1860
  getHitElements(board, { ranges: [range] }).length === 0 &&
1861
- options.isMultiple) {
1861
+ options.isMultiple &&
1862
+ !options.isDisabledSelect) {
1862
1863
  start = point;
1863
1864
  }
1864
1865
  Transforms.setSelection(board, { ranges: ranges });
@@ -1910,14 +1911,14 @@ function withSelection(board) {
1910
1911
  globalMouseup(event);
1911
1912
  };
1912
1913
  board.onChange = () => {
1914
+ const options = board.getPluginOptions(PlaitPluginKey.withSelection);
1913
1915
  // calc selected elements entry
1914
- if (board.pointer !== PlaitPointerType.hand) {
1916
+ if (board.pointer !== PlaitPointerType.hand && !options.isDisabledSelect) {
1915
1917
  try {
1916
1918
  if (board.operations.find(value => value.type === 'set_selection')) {
1917
1919
  selectionOuterG === null || selectionOuterG === void 0 ? void 0 : selectionOuterG.remove();
1918
1920
  const temporaryElements = getTemporaryElements(board);
1919
1921
  let elements = temporaryElements ? temporaryElements : getHitElements(board);
1920
- const options = board.getPluginOptions(PlaitPluginKey.withSelection);
1921
1922
  if (!options.isMultiple && elements.length > 1) {
1922
1923
  elements = [elements[0]];
1923
1924
  }
@@ -1956,7 +1957,10 @@ function withSelection(board) {
1956
1957
  }
1957
1958
  onChange();
1958
1959
  };
1959
- board.setPluginOptions(PlaitPluginKey.withSelection, { isMultiple: true });
1960
+ board.setPluginOptions(PlaitPluginKey.withSelection, {
1961
+ isMultiple: true,
1962
+ isDisabledSelect: false
1963
+ });
1960
1964
  return board;
1961
1965
  }
1962
1966
  function getTemporaryElements(board) {
@@ -2306,6 +2310,9 @@ class PlaitBoardComponent {
2306
2310
  get isFocused() {
2307
2311
  return PlaitBoard.isFocus(this.board);
2308
2312
  }
2313
+ get disabledScrollOnNonFocus() {
2314
+ return this.board.options.disabledScrollOnNonFocus && !PlaitBoard.isFocus(this.board);
2315
+ }
2309
2316
  get nativeElement() {
2310
2317
  return this.elementRef.nativeElement;
2311
2318
  }
@@ -2400,12 +2407,12 @@ class PlaitBoardComponent {
2400
2407
  fromEvent(this.host, 'mousemove')
2401
2408
  .pipe(takeUntil(this.destroy$))
2402
2409
  .subscribe((event) => {
2410
+ BOARD_TO_MOVING_POINT.set(this.board, [event.x, event.y]);
2403
2411
  this.board.mousemove(event);
2404
2412
  });
2405
2413
  fromEvent(document, 'mousemove')
2406
2414
  .pipe(takeUntil(this.destroy$))
2407
2415
  .subscribe((event) => {
2408
- BOARD_TO_MOVING_POINT.set(this.board, [event.x, event.y]);
2409
2416
  this.board.globalMousemove(event);
2410
2417
  });
2411
2418
  fromEvent(this.host, 'mouseup')
@@ -2457,8 +2464,7 @@ class PlaitBoardComponent {
2457
2464
  .pipe(takeUntil(this.destroy$), filter(() => this.isFocused && !PlaitBoard.isReadonly(this.board) && !PlaitBoard.hasBeenTextEditing(this.board)))
2458
2465
  .subscribe((clipboardEvent) => {
2459
2466
  const mousePoint = PlaitBoard.getMovingPoint(this.board);
2460
- const rect = this.nativeElement.getBoundingClientRect();
2461
- if (mousePoint && distanceBetweenPointAndRectangle(mousePoint[0], mousePoint[1], rect) === 0) {
2467
+ if (mousePoint) {
2462
2468
  const targetPoint = transformPoint(this.board, toPoint(mousePoint[0], mousePoint[1], this.host));
2463
2469
  this.board.insertFragment(clipboardEvent.clipboardData, targetPoint);
2464
2470
  }
@@ -2480,7 +2486,7 @@ class PlaitBoardComponent {
2480
2486
  setIsFromViewportChange(this.board, false);
2481
2487
  return false;
2482
2488
  }
2483
- return this.isFocused;
2489
+ return true;
2484
2490
  }))
2485
2491
  .subscribe((event) => {
2486
2492
  const { scrollLeft, scrollTop } = event.target;
@@ -2545,7 +2551,7 @@ class PlaitBoardComponent {
2545
2551
  }
2546
2552
  }
2547
2553
  PlaitBoardComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitBoardComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ViewContainerRef }, { token: i0.ElementRef }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component });
2548
- PlaitBoardComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.5", type: PlaitBoardComponent, selector: "plait-board", inputs: { plaitValue: "plaitValue", plaitViewport: "plaitViewport", plaitPlugins: "plaitPlugins", plaitOptions: "plaitOptions" }, outputs: { plaitChange: "plaitChange", plaitBoardInitialized: "plaitBoardInitialized" }, host: { properties: { "class": "this.hostClass", "class.readonly": "this.readonly", "class.focused": "this.isFocused" } }, queries: [{ propertyName: "islands", predicate: PlaitIslandBaseComponent, descendants: true }], viewQueries: [{ propertyName: "svg", first: true, predicate: ["svg"], descendants: true, static: true }, { propertyName: "viewportContainer", first: true, predicate: ["viewportContainer"], descendants: true, read: ElementRef, static: true }], usesOnChanges: true, ngImport: i0, template: `
2554
+ PlaitBoardComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.5", type: PlaitBoardComponent, selector: "plait-board", inputs: { plaitValue: "plaitValue", plaitViewport: "plaitViewport", plaitPlugins: "plaitPlugins", plaitOptions: "plaitOptions" }, outputs: { plaitChange: "plaitChange", plaitBoardInitialized: "plaitBoardInitialized" }, host: { properties: { "class": "this.hostClass", "class.readonly": "this.readonly", "class.focused": "this.isFocused", "class.disabled-scroll": "this.disabledScrollOnNonFocus" } }, queries: [{ propertyName: "islands", predicate: PlaitIslandBaseComponent, descendants: true }], viewQueries: [{ propertyName: "svg", first: true, predicate: ["svg"], descendants: true, static: true }, { propertyName: "viewportContainer", first: true, predicate: ["viewportContainer"], descendants: true, read: ElementRef, static: true }], usesOnChanges: true, ngImport: i0, template: `
2549
2555
  <div class="viewport-container" #viewportContainer>
2550
2556
  <svg #svg width="100%" height="100%" style="position: relative;"><g class="element-host"></g></svg>
2551
2557
  <plait-children [board]="board" [effect]="effect"></plait-children>
@@ -2586,6 +2592,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
2586
2592
  }], isFocused: [{
2587
2593
  type: HostBinding,
2588
2594
  args: ['class.focused']
2595
+ }], disabledScrollOnNonFocus: [{
2596
+ type: HostBinding,
2597
+ args: ['class.disabled-scroll']
2589
2598
  }], svg: [{
2590
2599
  type: ViewChild,
2591
2600
  args: ['svg', { static: true }]
@@ -2616,7 +2625,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
2616
2625
  * 1.create board instance
2617
2626
  * 2.build fake node weak map
2618
2627
  */
2619
- const createTestingBoard = (plugins, children, options = { readonly: false, hideScrollbar: true }) => {
2628
+ const createTestingBoard = (plugins, children, options = { readonly: false, hideScrollbar: true, disabledScrollOnNonFocus: false }) => {
2620
2629
  let board = createBoard(children, options);
2621
2630
  plugins.forEach(plugin => {
2622
2631
  board = plugin(board);