@plait/core 0.2.0-next.8 → 0.2.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.
- package/esm2020/core/element/element.component.mjs +3 -3
- package/esm2020/core/element/plugin-element.mjs +2 -2
- package/esm2020/interfaces/path.mjs +8 -1
- package/esm2020/interfaces/rectangle-client.mjs +7 -1
- package/esm2020/plugins/with-moving.mjs +2 -2
- package/esm2020/plugins/with-selection.mjs +8 -3
- package/esm2020/utils/dom/common.mjs +22 -0
- package/esm2020/utils/dom/foreign.mjs +19 -0
- package/esm2020/utils/index.mjs +3 -2
- package/esm2020/utils/viewport.mjs +2 -2
- package/fesm2015/plait-core.mjs +39 -4
- package/fesm2015/plait-core.mjs.map +1 -1
- package/fesm2020/plait-core.mjs +39 -4
- package/fesm2020/plait-core.mjs.map +1 -1
- package/interfaces/path.d.ts +1 -0
- package/interfaces/rectangle-client.d.ts +1 -0
- package/package.json +1 -1
- package/utils/{dom.d.ts → dom/common.d.ts} +1 -1
- package/utils/dom/foreign.d.ts +2 -0
- package/utils/index.d.ts +2 -1
- package/esm2020/utils/dom.mjs +0 -22
package/fesm2020/plait-core.mjs
CHANGED
|
@@ -213,6 +213,13 @@ const Path = {
|
|
|
213
213
|
const last = path[path.length - 1];
|
|
214
214
|
return path.slice(0, -1).concat(last + 1);
|
|
215
215
|
},
|
|
216
|
+
previous(path) {
|
|
217
|
+
if (path.length === 0) {
|
|
218
|
+
throw new Error(`Cannot get the next path of a root path [${path}], because it has no previous index.`);
|
|
219
|
+
}
|
|
220
|
+
const last = path[path.length - 1];
|
|
221
|
+
return path.slice(0, -1).concat(last - 1);
|
|
222
|
+
},
|
|
216
223
|
/**
|
|
217
224
|
* Check if a path is an ancestor of another.
|
|
218
225
|
*/
|
|
@@ -660,6 +667,24 @@ function createText(x, y, fill, textContent) {
|
|
|
660
667
|
return text;
|
|
661
668
|
}
|
|
662
669
|
|
|
670
|
+
function createForeignObject(x, y, width, height) {
|
|
671
|
+
var newForeignObject = document.createElementNS(NS, 'foreignObject');
|
|
672
|
+
newForeignObject.setAttribute('x', `${x}`);
|
|
673
|
+
newForeignObject.setAttribute('y', `${y}`);
|
|
674
|
+
newForeignObject.setAttribute('width', `${width}`);
|
|
675
|
+
newForeignObject.setAttribute('height', `${height}`);
|
|
676
|
+
return newForeignObject;
|
|
677
|
+
}
|
|
678
|
+
function updateForeignObject(g, width, height, x, y) {
|
|
679
|
+
const foreignObject = g.querySelector('foreignObject');
|
|
680
|
+
if (foreignObject) {
|
|
681
|
+
foreignObject.setAttribute('width', `${width}`);
|
|
682
|
+
foreignObject.setAttribute('height', `${height}`);
|
|
683
|
+
foreignObject.setAttribute('x', `${x}`);
|
|
684
|
+
foreignObject.setAttribute('y', `${y}`);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
|
|
663
688
|
const IS_IOS = typeof navigator !== 'undefined' &&
|
|
664
689
|
typeof window !== 'undefined' &&
|
|
665
690
|
/iPad|iPhone|iPod/.test(navigator.userAgent) &&
|
|
@@ -860,6 +885,12 @@ const RectangleClient = {
|
|
|
860
885
|
width: rectangle.width + Math.abs(offset) * 2,
|
|
861
886
|
height: rectangle.height + Math.abs(offset) * 2
|
|
862
887
|
};
|
|
888
|
+
},
|
|
889
|
+
isEqual: (rectangle, otherRectangle) => {
|
|
890
|
+
return (rectangle.x === otherRectangle.x &&
|
|
891
|
+
rectangle.y === otherRectangle.y &&
|
|
892
|
+
rectangle.width === otherRectangle.width &&
|
|
893
|
+
rectangle.height === otherRectangle.height);
|
|
863
894
|
}
|
|
864
895
|
};
|
|
865
896
|
|
|
@@ -1750,7 +1781,11 @@ function withSelection(board) {
|
|
|
1750
1781
|
selectionMovingG?.remove();
|
|
1751
1782
|
if (Math.hypot(width, height) > 5) {
|
|
1752
1783
|
end = movedTarget;
|
|
1753
|
-
|
|
1784
|
+
throttleRAF(() => {
|
|
1785
|
+
if (start && end) {
|
|
1786
|
+
Transforms.setSelection(board, { ranges: [{ anchor: start, focus: end }] });
|
|
1787
|
+
}
|
|
1788
|
+
});
|
|
1754
1789
|
setSelectionMoving(board);
|
|
1755
1790
|
const rough = PlaitBoard.getRoughSVG(board);
|
|
1756
1791
|
selectionMovingG = rough.rectangle(x, y, width, height, {
|
|
@@ -2005,8 +2040,8 @@ class PlaitElementComponent {
|
|
|
2005
2040
|
if (this.index > 0) {
|
|
2006
2041
|
const brotherElement = this.parent.children[this.index - 1];
|
|
2007
2042
|
const lastElement = PlaitNode.last(this.board, PlaitBoard.findPath(this.board, brotherElement));
|
|
2008
|
-
|
|
2009
|
-
siblingG =
|
|
2043
|
+
let component = PlaitElement.getComponent(lastElement) || PlaitElement.getComponent(brotherElement);
|
|
2044
|
+
siblingG = component.g;
|
|
2010
2045
|
}
|
|
2011
2046
|
this.parentG.insertBefore(g, siblingG);
|
|
2012
2047
|
}
|
|
@@ -2493,5 +2528,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
|
|
|
2493
2528
|
* Generated bundle index. Do not edit.
|
|
2494
2529
|
*/
|
|
2495
2530
|
|
|
2496
|
-
export { BOARD_TO_COMPONENT, BOARD_TO_ELEMENT_HOST, BOARD_TO_HOST, BOARD_TO_IS_SELECTION_MOVING, BOARD_TO_MOVING_ELEMENT, BOARD_TO_MOVING_POINT, BOARD_TO_ON_CHANGE, BOARD_TO_ROUGH_SVG, BOARD_TO_SELECTED_ELEMENT, BOARD_TO_TEMPORARY_ELEMENTS, BOARD_TO_VIEWPORT_ORIGINATION, BoardTransforms, CLIP_BOARD_FORMAT_KEY, ELEMENT_TO_COMPONENT, FLUSHING, IS_APPLE, IS_BOARD_CACHE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_FIREFOX, IS_IOS, IS_SAFARI, IS_TEXT_EDITABLE, MAX_RADIUS, MERGING, NODE_TO_INDEX, NODE_TO_PARENT, NS, Path, PlaitBoard, PlaitBoardComponent, PlaitChildrenElement, PlaitElement, PlaitElementComponent, PlaitHistoryBoard, PlaitModule, PlaitNode, PlaitOperation, PlaitPluginElementComponent, PlaitPointerType, PlaitToolbarComponent, Point, RectangleClient, SAVING, SCROLL_BAR_WIDTH, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, Selection, Transforms, Viewport, addMovingElements, addSelectedElement, arrowPoints, cacheMovingElements, cacheSelectedElements, changeZoom, clampZoomLevel, clearSelectedElement, clearSelectionMoving, clearViewportOrigination, createG, createSVG, createSelectionOuterG, createText, debounce, deleteTemporaryElements, depthFirstRecursion, distanceBetweenPointAndPoint, distanceBetweenPointAndRectangle, distanceBetweenPointAndSegment, drawAbstractRoundRectangle, drawArrow, drawCircle, drawLine, drawRoundRectangle, fitViewport, getBoardRectangle, getElementHostBBox, getHitElements, getMovingElements, getRectangleByElements, getSelectedElements, getTemporaryElements, getViewBox, getViewportContainerRect, getViewportOrigination, hasBeforeContextChange, hasOnContextChanged, hotkeys, idCreator, initializeViewBox, initializeViewportContainer, initializeViewportOffset, inverse, isFromScrolling, isFromViewportChange, isInPlaitBoard, isIntersectionElements, isNullOrUndefined, isSelectedElement, isSelectionMoving, isSetViewportOperation, normalizePoint, removeMovingElements, removeSelectedElement, rotate, scrollToRectangle, setIsFromScrolling, setIsFromViewportChange, setSVGViewBox, setSelectionMoving, setViewport, shouldClear, shouldMerge, shouldSave, throttleRAF, toPoint, transformPoint, transformPoints, updateViewportContainerScroll, updateViewportOffset, updateViewportOrigination, withMoving, withSelection };
|
|
2531
|
+
export { BOARD_TO_COMPONENT, BOARD_TO_ELEMENT_HOST, BOARD_TO_HOST, BOARD_TO_IS_SELECTION_MOVING, BOARD_TO_MOVING_ELEMENT, BOARD_TO_MOVING_POINT, BOARD_TO_ON_CHANGE, BOARD_TO_ROUGH_SVG, BOARD_TO_SELECTED_ELEMENT, BOARD_TO_TEMPORARY_ELEMENTS, BOARD_TO_VIEWPORT_ORIGINATION, BoardTransforms, CLIP_BOARD_FORMAT_KEY, ELEMENT_TO_COMPONENT, FLUSHING, IS_APPLE, IS_BOARD_CACHE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_FIREFOX, IS_IOS, IS_SAFARI, IS_TEXT_EDITABLE, MAX_RADIUS, MERGING, NODE_TO_INDEX, NODE_TO_PARENT, NS, Path, PlaitBoard, PlaitBoardComponent, PlaitChildrenElement, PlaitElement, PlaitElementComponent, PlaitHistoryBoard, PlaitModule, PlaitNode, PlaitOperation, PlaitPluginElementComponent, PlaitPointerType, PlaitToolbarComponent, Point, RectangleClient, SAVING, SCROLL_BAR_WIDTH, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, Selection, Transforms, Viewport, addMovingElements, addSelectedElement, arrowPoints, cacheMovingElements, cacheSelectedElements, changeZoom, clampZoomLevel, clearSelectedElement, clearSelectionMoving, clearViewportOrigination, createForeignObject, createG, createSVG, createSelectionOuterG, createText, debounce, deleteTemporaryElements, depthFirstRecursion, distanceBetweenPointAndPoint, distanceBetweenPointAndRectangle, distanceBetweenPointAndSegment, drawAbstractRoundRectangle, drawArrow, drawCircle, drawLine, drawRoundRectangle, fitViewport, getBoardRectangle, getElementHostBBox, getHitElements, getMovingElements, getRectangleByElements, getSelectedElements, getTemporaryElements, getViewBox, getViewportContainerRect, getViewportOrigination, hasBeforeContextChange, hasOnContextChanged, hotkeys, idCreator, initializeViewBox, initializeViewportContainer, initializeViewportOffset, inverse, isFromScrolling, isFromViewportChange, isInPlaitBoard, isIntersectionElements, isNullOrUndefined, isSelectedElement, isSelectionMoving, isSetViewportOperation, normalizePoint, removeMovingElements, removeSelectedElement, rotate, scrollToRectangle, setIsFromScrolling, setIsFromViewportChange, setSVGViewBox, setSelectionMoving, setViewport, shouldClear, shouldMerge, shouldSave, throttleRAF, toPoint, transformPoint, transformPoints, updateForeignObject, updateViewportContainerScroll, updateViewportOffset, updateViewportOrigination, withMoving, withSelection };
|
|
2497
2532
|
//# sourceMappingURL=plait-core.mjs.map
|