@plait/core 0.55.0 → 0.56.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.
Files changed (40) hide show
  1. package/board/board.component.d.ts +2 -0
  2. package/core/element/element-ref.d.ts +5 -0
  3. package/core/element/plugin-element.d.ts +9 -6
  4. package/esm2022/board/board.component.mjs +10 -5
  5. package/esm2022/core/element/element-ref.mjs +2 -0
  6. package/esm2022/core/element/plugin-element.mjs +16 -7
  7. package/esm2022/core/list-render.mjs +4 -3
  8. package/esm2022/interfaces/board.mjs +1 -1
  9. package/esm2022/interfaces/element.mjs +5 -2
  10. package/esm2022/plugins/create-board.mjs +2 -2
  11. package/esm2022/plugins/with-hotkey.mjs +2 -2
  12. package/esm2022/plugins/with-moving.mjs +88 -10
  13. package/esm2022/plugins/with-related-fragment.mjs +20 -13
  14. package/esm2022/public-api.mjs +3 -2
  15. package/esm2022/services/context.service.mjs +30 -0
  16. package/esm2022/utils/angle.mjs +24 -1
  17. package/esm2022/utils/common.mjs +5 -3
  18. package/esm2022/utils/dom/common.mjs +1 -21
  19. package/esm2022/utils/fragment.mjs +10 -8
  20. package/esm2022/utils/group.mjs +25 -22
  21. package/esm2022/utils/math.mjs +36 -1
  22. package/esm2022/utils/selected-element.mjs +3 -2
  23. package/esm2022/utils/selection.mjs +2 -3
  24. package/esm2022/utils/weak-maps.mjs +2 -1
  25. package/esm2022/utils/z-index.mjs +2 -2
  26. package/fesm2022/plait-core.mjs +235 -80
  27. package/fesm2022/plait-core.mjs.map +1 -1
  28. package/interfaces/board.d.ts +1 -1
  29. package/interfaces/element.d.ts +6 -4
  30. package/package.json +1 -1
  31. package/plugins/with-moving.d.ts +3 -1
  32. package/public-api.d.ts +2 -1
  33. package/services/{image-context.service.d.ts → context.service.d.ts} +3 -0
  34. package/utils/angle.d.ts +2 -0
  35. package/utils/dom/common.d.ts +1 -2
  36. package/utils/fragment.d.ts +2 -2
  37. package/utils/group.d.ts +5 -5
  38. package/utils/math.d.ts +1 -0
  39. package/utils/weak-maps.d.ts +2 -0
  40. package/esm2022/services/image-context.service.mjs +0 -22
@@ -39,7 +39,7 @@ export interface PlaitBoard {
39
39
  keyDown: (event: KeyboardEvent) => void;
40
40
  globalKeyDown: (event: KeyboardEvent) => void;
41
41
  keyUp: (event: KeyboardEvent) => void;
42
- buildFragment: (clipboardContext: WritableClipboardContext | null, rectangle: RectangleClient | null, type: 'copy' | 'cut') => WritableClipboardContext | null;
42
+ buildFragment: (clipboardContext: WritableClipboardContext | null, rectangle: RectangleClient | null, type: 'copy' | 'cut', originData?: PlaitElement[]) => WritableClipboardContext | null;
43
43
  insertFragment: (clipboardData: ClipboardData | null, targetPoint: Point) => void;
44
44
  deleteFragment: (data: PlaitElement[]) => void;
45
45
  getDeletedFragment: (data: PlaitElement[]) => PlaitElement[];
@@ -1,6 +1,7 @@
1
1
  import { PlaitPluginElementComponent } from '../core/element/plugin-element';
2
2
  import { PlaitBoard } from './board';
3
3
  import { Point } from './point';
4
+ import { PlaitElementRef } from '../core/element/element-ref';
4
5
  export interface PlaitElement {
5
6
  [key: string]: any;
6
7
  id: string;
@@ -11,12 +12,13 @@ export interface PlaitElement {
11
12
  }
12
13
  export declare const PlaitElement: {
13
14
  isRootElement(value: PlaitElement): boolean;
14
- getComponent(value: PlaitElement): PlaitPluginElementComponent<PlaitElement, PlaitBoard>;
15
+ getComponent(value: PlaitElement): PlaitPluginElementComponent<PlaitElement, PlaitBoard, PlaitElementRef>;
16
+ getElementRef<T extends PlaitElementRef = PlaitElementRef>(value: PlaitElement): T;
15
17
  getElementG(value: PlaitElement): SVGGElement;
16
18
  hasMounted(element: PlaitElement): boolean;
17
- getContainerG<T extends boolean>(value: PlaitElement, options: {
18
- suppressThrow: T;
19
- }): T extends true ? SVGGElement | null : SVGGElement;
19
+ getContainerG<T_1 extends boolean>(value: PlaitElement, options: {
20
+ suppressThrow: T_1;
21
+ }): T_1 extends true ? SVGGElement | null : SVGGElement;
20
22
  };
21
23
  export interface ComponentType<T> {
22
24
  new (...args: any[]): T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plait/core",
3
- "version": "0.55.0",
3
+ "version": "0.56.0",
4
4
  "peerDependencies": {
5
5
  "@angular/common": "^17.2.4",
6
6
  "@angular/core": "^17.2.4",
@@ -3,4 +3,6 @@ import { PlaitElement } from '../interfaces/element';
3
3
  export declare function withMoving(board: PlaitBoard): PlaitBoard;
4
4
  export declare function withArrowMoving(board: PlaitBoard): PlaitBoard;
5
5
  export declare function getSelectedTargetElements(board: PlaitBoard): PlaitElement[];
6
- export declare function updatePoints(board: PlaitBoard, targetElements: PlaitElement[], offsetX: number, offsetY: number): PlaitElement[];
6
+ export declare function getValidElements(board: PlaitBoard, activeElements: PlaitElement[]): PlaitElement[];
7
+ export declare function updatePoints(board: PlaitBoard, activeElements: PlaitElement[], offsetX: number, offsetY: number): PlaitElement[];
8
+ export declare function drawPendingNodesG(board: PlaitBoard, activeElements: PlaitElement[], offsetX: number, offsetY: number): null;
package/public-api.d.ts CHANGED
@@ -3,6 +3,7 @@ export * from './constants';
3
3
  export * from './core/element/plugin-element';
4
4
  export * from './core/element/context-change';
5
5
  export * from './core/island/island-base.component';
6
+ export * from './core/element/element-ref';
6
7
  export * from './interfaces';
7
8
  export * from './transforms';
8
9
  export * from './utils';
@@ -10,5 +11,5 @@ export * from './plugins/with-selection';
10
11
  export * from './plugins/with-moving';
11
12
  export * from './plugins/with-options';
12
13
  export * from './testing';
13
- export * from './services/image-context.service';
14
+ export * from './services/context.service';
14
15
  export * from './utils/debug';
@@ -1,10 +1,13 @@
1
1
  import { ImageEntry } from '../interfaces';
2
2
  import * as i0 from "@angular/core";
3
3
  export declare class PlaitContextService {
4
+ private _stable;
4
5
  private uploadingFiles;
5
6
  getUploadingFile(url: string): ImageEntry | undefined;
6
7
  setUploadingFile(file: ImageEntry): number;
7
8
  removeUploadingFile(fileEntry: ImageEntry): void;
9
+ onStable(): import("rxjs").Observable<unknown>;
10
+ nextStable(): void;
8
11
  static ɵfac: i0.ɵɵFactoryDeclaration<PlaitContextService, never>;
9
12
  static ɵprov: i0.ɵɵInjectableDeclaration<PlaitContextService>;
10
13
  }
package/utils/angle.d.ts CHANGED
@@ -18,3 +18,5 @@ export declare function radiansToDegrees(r: number): number;
18
18
  export declare function rotateElements(board: PlaitBoard, elements: PlaitElement[], angle: number): void;
19
19
  export declare const normalizeAngle: (angle: number) => number;
20
20
  export declare const getAngleBetweenPoints: (startPoint: Point, endPoint: Point, centerPoint: Point) => number;
21
+ export declare const getAngleByElement: (element: PlaitElement) => number;
22
+ export declare const setAngleForG: (g: SVGGElement, centerPoint: Point, angle: number) => void;
@@ -1,11 +1,10 @@
1
1
  import { Options } from 'roughjs/bin/core';
2
- import { Point, RectangleClient } from '../../interfaces';
2
+ import { RectangleClient } from '../../interfaces';
3
3
  export declare const NS = "http://www.w3.org/2000/svg";
4
4
  export declare function createG(): SVGGElement;
5
5
  export declare function createPath(): SVGPathElement;
6
6
  export declare function createRect(rectangle: RectangleClient, options?: Options): SVGRectElement;
7
7
  export declare const setStrokeLinecap: (g: SVGGElement, value: 'round' | 'square') => void;
8
- export declare const setAngleForG: (g: SVGGElement, centerPoint: Point, angle: number) => void;
9
8
  export declare const setPathStrokeLinecap: (g: SVGGElement, value: 'round' | 'square') => void;
10
9
  export declare function createMask(): SVGMaskElement;
11
10
  export declare function createSVG(): SVGSVGElement;
@@ -1,4 +1,4 @@
1
- import { PlaitBoard, PlaitElement } from '../interfaces';
1
+ import { PlaitBoard, PlaitElement, Point } from '../interfaces';
2
2
  export declare const deleteFragment: (board: PlaitBoard) => void;
3
3
  export declare const setFragment: (board: PlaitBoard, type: 'copy' | 'cut', clipboardData: DataTransfer | null) => void;
4
- export declare const duplicateElements: (board: PlaitBoard, elements?: PlaitElement[]) => void;
4
+ export declare const duplicateElements: (board: PlaitBoard, elements?: PlaitElement[], point?: Point) => void;
package/utils/group.d.ts CHANGED
@@ -2,15 +2,15 @@ import { Path, PlaitBoard, PlaitElement, PlaitGroup, RectangleClient } from '../
2
2
  export declare const getElementsInGroup: (board: PlaitBoard, group: PlaitGroup, recursion?: boolean, includeGroup?: boolean) => PlaitElement[];
3
3
  export declare const getAllElementsInGroup: (board: PlaitBoard, group: PlaitGroup, recursion?: boolean, includeGroup?: boolean) => PlaitElement[];
4
4
  export declare const getRectangleByGroup: (board: PlaitBoard, group: PlaitGroup, recursion?: boolean) => RectangleClient;
5
- export declare const getGroupByElement: (board: PlaitBoard, element: PlaitElement, recursion?: boolean, source?: PlaitElement[]) => PlaitGroup | PlaitGroup[] | null;
5
+ export declare const getGroupByElement: (board: PlaitBoard, element: PlaitElement, recursion?: boolean, originElements?: PlaitElement[]) => PlaitGroup | PlaitGroup[] | null;
6
6
  export declare const getHighestGroup: (board: PlaitBoard, element: PlaitElement) => PlaitGroup | null;
7
7
  export declare const getElementsInGroupByElement: (board: PlaitBoard, element: PlaitElement) => PlaitElement[];
8
8
  export declare const isSelectedElementOrGroup: (board: PlaitBoard, element: PlaitElement, elements?: PlaitElement[]) => boolean;
9
9
  export declare const isSelectedAllElementsInGroup: (board: PlaitBoard, group: PlaitGroup, elements?: PlaitElement[]) => boolean;
10
10
  export declare const filterSelectedGroups: (board: PlaitBoard, groups: PlaitGroup[], elements?: PlaitElement[]) => PlaitGroup[];
11
- export declare const getSelectedGroups: (board: PlaitBoard, elements?: PlaitElement[]) => PlaitGroup[];
12
- export declare const getHighestSelectedGroup: (board: PlaitBoard, element: PlaitElement, elements?: PlaitElement[]) => PlaitGroup | null;
13
- export declare const getHighestSelectedGroups: (board: PlaitBoard, elements?: PlaitElement[]) => PlaitGroup[];
11
+ export declare const getSelectedGroups: (board: PlaitBoard, elements?: PlaitElement[], originElements?: PlaitElement[]) => PlaitGroup[];
12
+ export declare const getHighestSelectedGroup: (board: PlaitBoard, element: PlaitElement, elements?: PlaitElement[], originElements?: PlaitElement[]) => PlaitGroup | null;
13
+ export declare const getHighestSelectedGroups: (board: PlaitBoard, elements?: PlaitElement[], originElements?: PlaitElement[]) => PlaitGroup[];
14
14
  export declare const getSelectedIsolatedElements: (board: PlaitBoard, elements?: PlaitElement[]) => PlaitElement[];
15
15
  export declare const getSelectedIsolatedElementsCanAddToGroup: (board: PlaitBoard, elements?: PlaitElement[]) => PlaitElement[];
16
16
  export declare const getHighestSelectedElements: (board: PlaitBoard, elements?: PlaitElement[]) => PlaitElement[];
@@ -19,6 +19,6 @@ export declare const createGroup: (groupId?: string) => PlaitGroup;
19
19
  export declare const nonGroupInHighestSelectedElements: (elements: PlaitElement[]) => boolean;
20
20
  export declare const hasSelectedElementsInSameGroup: (elements: PlaitElement[]) => boolean;
21
21
  export declare const canAddGroup: (board: PlaitBoard, elements?: PlaitElement[]) => boolean;
22
- export declare const canRemoveGroup: (board: PlaitBoard, elements?: PlaitElement[]) => boolean;
22
+ export declare const canRemoveGroup: (board: PlaitBoard, elements?: PlaitElement[], originElements?: PlaitElement[]) => boolean;
23
23
  export declare const getEditingGroup: (board: PlaitBoard, element: PlaitElement) => PlaitGroup | null;
24
24
  export declare const moveElementsToNewPathAfterAddGroup: (board: PlaitBoard, selectedElements: PlaitElement[], newPath: Path) => void;
package/utils/math.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare function distanceBetweenPointAndSegment(x: number, y: number, x1:
4
4
  export declare function getNearestPointBetweenPointAndSegment(point: Point, linePoints: [Point, Point]): Point;
5
5
  export declare function distanceBetweenPointAndSegments(points: Point[], point: Point): number;
6
6
  export declare function getNearestPointBetweenPointAndSegments(point: Point, points: Point[], isClose?: Boolean): Point;
7
+ export declare function getNearestPointBetweenPointAndEllipse(point: Point, center: Point, rx: number, ry: number, rotation?: number): Point;
7
8
  export declare function rotate(x1: number, y1: number, x2: number, y2: number, angle: number): number[];
8
9
  export declare function distanceBetweenPointAndPoint(x1: number, y1: number, x2: number, y2: number): number;
9
10
  export declare function distanceBetweenPointAndRectangle(x: number, y: number, rect: RectangleClient): number;
@@ -5,6 +5,7 @@ import { PlaitBoard } from '../interfaces/board';
5
5
  import { Point } from '../interfaces/point';
6
6
  import { Ancestor } from '../interfaces/node';
7
7
  import { PathRef } from '../interfaces/path-ref';
8
+ import { PlaitElementRef } from '../core/element/element-ref';
8
9
  export declare const IS_BOARD_CACHE: WeakMap<Object, boolean>;
9
10
  export declare const FLUSHING: WeakMap<PlaitBoard, boolean>;
10
11
  export declare const NODE_TO_INDEX: WeakMap<PlaitElement, number>;
@@ -36,3 +37,4 @@ export declare const BOARD_TO_TEMPORARY_ELEMENTS: WeakMap<PlaitBoard, {
36
37
  }>;
37
38
  export declare const BOARD_TO_MOVING_ELEMENT: WeakMap<PlaitBoard, PlaitElement[]>;
38
39
  export declare const PATH_REFS: WeakMap<PlaitBoard, Set<PathRef>>;
40
+ export declare const ELEMENT_TO_REF: WeakMap<PlaitElement, PlaitElementRef>;
@@ -1,22 +0,0 @@
1
- import { Injectable } from '@angular/core';
2
- import * as i0 from "@angular/core";
3
- export class PlaitContextService {
4
- constructor() {
5
- this.uploadingFiles = [];
6
- }
7
- getUploadingFile(url) {
8
- return this.uploadingFiles.find(file => file.url === url);
9
- }
10
- setUploadingFile(file) {
11
- return this.uploadingFiles.push(file);
12
- }
13
- removeUploadingFile(fileEntry) {
14
- this.uploadingFiles = this.uploadingFiles.filter(file => file.url !== fileEntry.url);
15
- }
16
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.4", ngImport: i0, type: PlaitContextService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
17
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.2.4", ngImport: i0, type: PlaitContextService }); }
18
- }
19
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.4", ngImport: i0, type: PlaitContextService, decorators: [{
20
- type: Injectable
21
- }] });
22
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW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