@plait/core 0.16.1 → 0.19.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/constants/index.d.ts +2 -0
- package/constants/resize.d.ts +3 -0
- package/esm2020/constants/index.mjs +3 -1
- package/esm2020/constants/resize.mjs +5 -0
- package/esm2020/plugins/with-selection.mjs +16 -5
- package/esm2020/utils/draw/rectangle.mjs +8 -47
- package/esm2020/utils/selected-element.mjs +3 -10
- package/esm2020/utils/tree.mjs +12 -1
- package/fesm2015/plait-core.mjs +40 -59
- package/fesm2015/plait-core.mjs.map +1 -1
- package/fesm2020/plait-core.mjs +40 -59
- package/fesm2020/plait-core.mjs.map +1 -1
- package/package.json +1 -1
- package/plugins/with-selection.d.ts +4 -0
- package/styles/styles.scss +4 -0
- package/utils/draw/rectangle.d.ts +0 -1
- package/utils/tree.d.ts +3 -0
package/fesm2020/plait-core.mjs
CHANGED
|
@@ -42,6 +42,16 @@ function depthFirstRecursion(node, callback, recursion, isReverse) {
|
|
|
42
42
|
}
|
|
43
43
|
callback(node);
|
|
44
44
|
}
|
|
45
|
+
const getIsRecursionFunc = (board) => {
|
|
46
|
+
return (element) => {
|
|
47
|
+
if (PlaitBoard.isBoard(element) || board.isRecursion(element)) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
};
|
|
45
55
|
|
|
46
56
|
function getRectangleByElements(board, elements, recursion) {
|
|
47
57
|
const boundaryBox = {
|
|
@@ -845,6 +855,11 @@ const CLOSE_SQUARE_BRACKET = 221;
|
|
|
845
855
|
const SINGLE_QUOTE = 222;
|
|
846
856
|
const MAC_META = 224;
|
|
847
857
|
|
|
858
|
+
var ResizeCursorClass;
|
|
859
|
+
(function (ResizeCursorClass) {
|
|
860
|
+
ResizeCursorClass["ew-resize"] = "ew-resize";
|
|
861
|
+
})(ResizeCursorClass || (ResizeCursorClass = {}));
|
|
862
|
+
|
|
848
863
|
const CLIP_BOARD_FORMAT_KEY = 'x-plait-fragment';
|
|
849
864
|
const HOST_CLASS_NAME = 'plait-board-container';
|
|
850
865
|
const SCROLL_BAR_WIDTH = 20;
|
|
@@ -855,6 +870,7 @@ const POINTER_BUTTON = {
|
|
|
855
870
|
SECONDARY: 2,
|
|
856
871
|
TOUCH: -1,
|
|
857
872
|
};
|
|
873
|
+
const PRESS_AND_MOVE_BUFFER = 5;
|
|
858
874
|
|
|
859
875
|
const NS = 'http://www.w3.org/2000/svg';
|
|
860
876
|
function toPoint(x, y, container) {
|
|
@@ -941,14 +957,7 @@ const getHitElements = (board, selection, match = () => true) => {
|
|
|
941
957
|
})) {
|
|
942
958
|
selectedElements.push(node);
|
|
943
959
|
}
|
|
944
|
-
},
|
|
945
|
-
if (PlaitBoard.isBoard(node) || board.isRecursion(node)) {
|
|
946
|
-
return true;
|
|
947
|
-
}
|
|
948
|
-
else {
|
|
949
|
-
return false;
|
|
950
|
-
}
|
|
951
|
-
}, true);
|
|
960
|
+
}, getIsRecursionFunc(board), true);
|
|
952
961
|
return selectedElements;
|
|
953
962
|
};
|
|
954
963
|
const getHitElementOfRoot = (board, rootElements, range) => {
|
|
@@ -1312,10 +1321,13 @@ function idCreator(length = 5) {
|
|
|
1312
1321
|
function drawRoundRectangle(rs, x1, y1, x2, y2, options, outline = false, borderRadius) {
|
|
1313
1322
|
const width = Math.abs(x1 - x2);
|
|
1314
1323
|
const height = Math.abs(y1 - y2);
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
radius =
|
|
1324
|
+
let radius = borderRadius || 0;
|
|
1325
|
+
if (radius === 0) {
|
|
1326
|
+
const defaultRadius = Math.min(width, height) / 8;
|
|
1327
|
+
let radius = defaultRadius;
|
|
1328
|
+
if (defaultRadius > MAX_RADIUS) {
|
|
1329
|
+
radius = outline ? MAX_RADIUS + 2 : MAX_RADIUS;
|
|
1330
|
+
}
|
|
1319
1331
|
}
|
|
1320
1332
|
const point1 = [x1 + radius, y1];
|
|
1321
1333
|
const point2 = [x2 - radius, y1];
|
|
@@ -1327,48 +1339,6 @@ function drawRoundRectangle(rs, x1, y1, x2, y2, options, outline = false, border
|
|
|
1327
1339
|
const point8 = [x1, y1 + radius];
|
|
1328
1340
|
return rs.path(`M${point2[0]} ${point2[1]} A ${radius} ${radius}, 0, 0, 1, ${point3[0]} ${point3[1]} L ${point4[0]} ${point4[1]} A ${radius} ${radius}, 0, 0, 1, ${point5[0]} ${point5[1]} L ${point6[0]} ${point6[1]} A ${radius} ${radius}, 0, 0, 1, ${point7[0]} ${point7[1]} L ${point8[0]} ${point8[1]} A ${radius} ${radius}, 0, 0, 1, ${point1[0]} ${point1[1]} Z`, options);
|
|
1329
1341
|
}
|
|
1330
|
-
function drawAbstractRoundRectangle(rs, x1, y1, x2, y2, isHorizontal, options) {
|
|
1331
|
-
const width = Math.abs(x1 - x2);
|
|
1332
|
-
const height = Math.abs(y1 - y2);
|
|
1333
|
-
const radius = 5;
|
|
1334
|
-
const handleGap = 4;
|
|
1335
|
-
const handleLength = 10;
|
|
1336
|
-
const handleSpace = handleLength + handleGap * 2;
|
|
1337
|
-
if (isHorizontal) {
|
|
1338
|
-
const handleSideLine = (width - handleSpace - radius * 2) / 2;
|
|
1339
|
-
const sideLine = height - radius * 2;
|
|
1340
|
-
return rs.path(`M${x1 + radius},${y1}
|
|
1341
|
-
l${handleSideLine},0
|
|
1342
|
-
m${handleSpace},0
|
|
1343
|
-
l${handleSideLine},0
|
|
1344
|
-
a${radius},${radius},0,0,1,${radius},${radius}
|
|
1345
|
-
l0,${sideLine}
|
|
1346
|
-
a${radius},${radius},0,0,1,-${radius},${radius}
|
|
1347
|
-
l-${handleSideLine},0
|
|
1348
|
-
m-${handleSpace},0
|
|
1349
|
-
l-${handleSideLine},0
|
|
1350
|
-
a${radius},${radius},0,0,1,-${radius},-${radius}
|
|
1351
|
-
l0,-${sideLine}
|
|
1352
|
-
a${radius},${radius},0,0,1,${radius},-${radius}`, options);
|
|
1353
|
-
}
|
|
1354
|
-
else {
|
|
1355
|
-
const handleSideLine = (height - handleSpace - radius * 2) / 2;
|
|
1356
|
-
const sideLine = width - radius * 2;
|
|
1357
|
-
return rs.path(`M${x1 + radius},${y1}
|
|
1358
|
-
l${sideLine},0
|
|
1359
|
-
a${radius},${radius},0,0,1,${radius},${radius}
|
|
1360
|
-
l0,${handleSideLine}
|
|
1361
|
-
m0,${handleSpace}
|
|
1362
|
-
l0,${handleSideLine}
|
|
1363
|
-
a${radius},${radius},0,0,1,-${radius},${radius}
|
|
1364
|
-
l-${sideLine},0
|
|
1365
|
-
a${radius},${radius},0,0,1,-${radius},-${radius}
|
|
1366
|
-
l0,-${handleSideLine}
|
|
1367
|
-
m0,-${handleSpace}
|
|
1368
|
-
l0,-${handleSideLine}
|
|
1369
|
-
a${radius},${radius},0,0,1,${radius},-${radius}`, options);
|
|
1370
|
-
}
|
|
1371
|
-
}
|
|
1372
1342
|
|
|
1373
1343
|
function arrowPoints(start, end, maxHypotenuseLength = 10, degree = 40) {
|
|
1374
1344
|
const width = Math.abs(start[0] - end[0]);
|
|
@@ -2287,7 +2257,12 @@ function withSelection(board) {
|
|
|
2287
2257
|
let selectionMovingG;
|
|
2288
2258
|
let selectionOuterG;
|
|
2289
2259
|
let previousSelectedElements;
|
|
2260
|
+
// prevent text from being selected when user pressed main pointer and is moving
|
|
2261
|
+
let needPreventNativeSelectionWhenMoving = false;
|
|
2290
2262
|
board.mousedown = (event) => {
|
|
2263
|
+
if (event.target instanceof Element && !event.target.closest('.plait-richtext-container')) {
|
|
2264
|
+
needPreventNativeSelectionWhenMoving = true;
|
|
2265
|
+
}
|
|
2291
2266
|
if (!isMainPointer(event)) {
|
|
2292
2267
|
mousedown(event);
|
|
2293
2268
|
return;
|
|
@@ -2307,14 +2282,13 @@ function withSelection(board) {
|
|
|
2307
2282
|
!options.isDisabledSelect) {
|
|
2308
2283
|
start = point;
|
|
2309
2284
|
}
|
|
2310
|
-
if (PlaitBoard.isPointer(board, PlaitPointerType.selection) && hitElements.length === 0 && !PlaitBoard.hasBeenTextEditing(board)) {
|
|
2311
|
-
// prevent text from being selected
|
|
2312
|
-
event.preventDefault();
|
|
2313
|
-
}
|
|
2314
2285
|
Transforms.setSelection(board, { ranges: [range] });
|
|
2315
2286
|
mousedown(event);
|
|
2316
2287
|
};
|
|
2317
2288
|
board.globalMousemove = (event) => {
|
|
2289
|
+
if (needPreventNativeSelectionWhenMoving) {
|
|
2290
|
+
preventNativeSelection(board, event);
|
|
2291
|
+
}
|
|
2318
2292
|
if (start) {
|
|
2319
2293
|
const movedTarget = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
|
|
2320
2294
|
const { x, y, width, height } = RectangleClient.toRectangleClient([start, movedTarget]);
|
|
@@ -2357,6 +2331,7 @@ function withSelection(board) {
|
|
|
2357
2331
|
}
|
|
2358
2332
|
start = null;
|
|
2359
2333
|
end = null;
|
|
2334
|
+
needPreventNativeSelectionWhenMoving = false;
|
|
2360
2335
|
globalMouseup(event);
|
|
2361
2336
|
};
|
|
2362
2337
|
board.onChange = () => {
|
|
@@ -2438,6 +2413,12 @@ function createSelectionOuterG(board, selectElements) {
|
|
|
2438
2413
|
fillStyle: 'solid'
|
|
2439
2414
|
});
|
|
2440
2415
|
}
|
|
2416
|
+
/**
|
|
2417
|
+
* prevent text from being selected
|
|
2418
|
+
*/
|
|
2419
|
+
const preventNativeSelection = (board, event) => {
|
|
2420
|
+
event.preventDefault();
|
|
2421
|
+
};
|
|
2441
2422
|
|
|
2442
2423
|
function withViewport(board) {
|
|
2443
2424
|
const { onChange } = board;
|
|
@@ -3322,5 +3303,5 @@ function createModModifierKeys() {
|
|
|
3322
3303
|
* Generated bundle index. Do not edit.
|
|
3323
3304
|
*/
|
|
3324
3305
|
|
|
3325
|
-
export { A, ALT, APOSTROPHE, AT_SIGN, B, BACKSLASH, BACKSPACE, 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_MOVING_POINT_IN_BOARD, BOARD_TO_ON_CHANGE, BOARD_TO_ROUGH_SVG, BOARD_TO_SELECTED_ELEMENT, BOARD_TO_TEMPORARY_ELEMENTS, BOARD_TO_VIEWPORT_ORIGINATION, BoardTransforms, C, CAPS_LOCK, CLIP_BOARD_FORMAT_KEY, CLOSE_SQUARE_BRACKET, COMMA, CONTEXT_MENU, CONTROL, ColorfulThemeColor, D, DASH, DELETE, DOWN_ARROW, DarkThemeColor, DefaultThemeColor, E, EIGHT, ELEMENT_TO_COMPONENT, END, ENTER, EQUALS, ESCAPE, F, F1, F10, F11, F12, F2, F3, F4, F5, F6, F7, F8, F9, FF_EQUALS, FF_MINUS, FF_MUTE, FF_SEMICOLON, FF_VOLUME_DOWN, FF_VOLUME_UP, FIRST_MEDIA, FIVE, FLUSHING, FOUR, G, H, HOME, HOST_CLASS_NAME, I, INSERT, IS_APPLE, IS_BOARD_CACHE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_FIREFOX, IS_IOS, IS_MAC, IS_SAFARI, IS_TEXT_EDITABLE, J, K, L, LAST_MEDIA, LEFT_ARROW, M, MAC_ENTER, MAC_META, MAC_WK_CMD_LEFT, MAC_WK_CMD_RIGHT, MAX_RADIUS, MERGING, META, MUTE, N, NINE, NODE_TO_INDEX, NODE_TO_PARENT, NS, NUMPAD_DIVIDE, NUMPAD_EIGHT, NUMPAD_FIVE, NUMPAD_FOUR, NUMPAD_MINUS, NUMPAD_MULTIPLY, NUMPAD_NINE, NUMPAD_ONE, NUMPAD_PERIOD, NUMPAD_PLUS, NUMPAD_SEVEN, NUMPAD_SIX, NUMPAD_THREE, NUMPAD_TWO, NUMPAD_ZERO, NUM_CENTER, NUM_LOCK, O, ONE, OPEN_SQUARE_BRACKET, P, PAGE_DOWN, PAGE_UP, PATH_REFS, PAUSE, PERIOD, PLUS_SIGN, POINTER_BUTTON, PRINT_SCREEN, Path, PlaitBoard, PlaitBoardComponent, PlaitChildrenElement, PlaitElement, PlaitElementComponent, PlaitHistoryBoard, PlaitIslandBaseComponent, PlaitIslandPopoverBaseComponent, PlaitModule, PlaitNode, PlaitOperation, PlaitPluginElementComponent, PlaitPluginKey, PlaitPointerType, Point, Q, QUESTION_MARK, R, RIGHT_ARROW, RectangleClient, RetroThemeColor, S, SAVING, SCROLL_BAR_WIDTH, SCROLL_LOCK, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, SEMICOLON, SEVEN, SHIFT, SINGLE_QUOTE, SIX, SLASH, SPACE, Selection, SoftThemeColor, StarryThemeColor, T, TAB, THREE, TILDE, TWO, ThemeColorMode, ThemeColors, Transforms, U, UP_ARROW, V, VOLUME_DOWN, VOLUME_UP, Viewport, W, X, Y, Z, ZERO, addMovingElements, addSelectedElement, arrowPoints, cacheMovingElements, cacheSelectedElements, clampZoomLevel, clearNodeWeakMap, clearSelectedElement, clearSelectionMoving, clearViewportOrigination, createFakeEvent, createForeignObject, createG, createKeyboardEvent, createModModifierKeys, createMouseEvent, createPath, createPointerEvent, createSVG, createSelectionOuterG, createTestingBoard, createText, createTouchEvent, debounce, deleteTemporaryElements, depthFirstRecursion, distanceBetweenPointAndPoint, distanceBetweenPointAndRectangle, distanceBetweenPointAndSegment, downloadImage,
|
|
3306
|
+
export { A, ALT, APOSTROPHE, AT_SIGN, B, BACKSLASH, BACKSPACE, 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_MOVING_POINT_IN_BOARD, BOARD_TO_ON_CHANGE, BOARD_TO_ROUGH_SVG, BOARD_TO_SELECTED_ELEMENT, BOARD_TO_TEMPORARY_ELEMENTS, BOARD_TO_VIEWPORT_ORIGINATION, BoardTransforms, C, CAPS_LOCK, CLIP_BOARD_FORMAT_KEY, CLOSE_SQUARE_BRACKET, COMMA, CONTEXT_MENU, CONTROL, ColorfulThemeColor, D, DASH, DELETE, DOWN_ARROW, DarkThemeColor, DefaultThemeColor, E, EIGHT, ELEMENT_TO_COMPONENT, END, ENTER, EQUALS, ESCAPE, F, F1, F10, F11, F12, F2, F3, F4, F5, F6, F7, F8, F9, FF_EQUALS, FF_MINUS, FF_MUTE, FF_SEMICOLON, FF_VOLUME_DOWN, FF_VOLUME_UP, FIRST_MEDIA, FIVE, FLUSHING, FOUR, G, H, HOME, HOST_CLASS_NAME, I, INSERT, IS_APPLE, IS_BOARD_CACHE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_FIREFOX, IS_IOS, IS_MAC, IS_SAFARI, IS_TEXT_EDITABLE, J, K, L, LAST_MEDIA, LEFT_ARROW, M, MAC_ENTER, MAC_META, MAC_WK_CMD_LEFT, MAC_WK_CMD_RIGHT, MAX_RADIUS, MERGING, META, MUTE, N, NINE, NODE_TO_INDEX, NODE_TO_PARENT, NS, NUMPAD_DIVIDE, NUMPAD_EIGHT, NUMPAD_FIVE, NUMPAD_FOUR, NUMPAD_MINUS, NUMPAD_MULTIPLY, NUMPAD_NINE, NUMPAD_ONE, NUMPAD_PERIOD, NUMPAD_PLUS, NUMPAD_SEVEN, NUMPAD_SIX, NUMPAD_THREE, NUMPAD_TWO, NUMPAD_ZERO, NUM_CENTER, NUM_LOCK, O, ONE, OPEN_SQUARE_BRACKET, P, PAGE_DOWN, PAGE_UP, PATH_REFS, PAUSE, PERIOD, PLUS_SIGN, POINTER_BUTTON, PRESS_AND_MOVE_BUFFER, PRINT_SCREEN, Path, PlaitBoard, PlaitBoardComponent, PlaitChildrenElement, PlaitElement, PlaitElementComponent, PlaitHistoryBoard, PlaitIslandBaseComponent, PlaitIslandPopoverBaseComponent, PlaitModule, PlaitNode, PlaitOperation, PlaitPluginElementComponent, PlaitPluginKey, PlaitPointerType, Point, Q, QUESTION_MARK, R, RIGHT_ARROW, RectangleClient, ResizeCursorClass, RetroThemeColor, S, SAVING, SCROLL_BAR_WIDTH, SCROLL_LOCK, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, SEMICOLON, SEVEN, SHIFT, SINGLE_QUOTE, SIX, SLASH, SPACE, Selection, SoftThemeColor, StarryThemeColor, T, TAB, THREE, TILDE, TWO, ThemeColorMode, ThemeColors, Transforms, U, UP_ARROW, V, VOLUME_DOWN, VOLUME_UP, Viewport, W, X, Y, Z, ZERO, addMovingElements, addSelectedElement, arrowPoints, cacheMovingElements, cacheSelectedElements, clampZoomLevel, clearNodeWeakMap, clearSelectedElement, clearSelectionMoving, clearViewportOrigination, createFakeEvent, createForeignObject, createG, createKeyboardEvent, createModModifierKeys, createMouseEvent, createPath, createPointerEvent, createSVG, createSelectionOuterG, createTestingBoard, createText, createTouchEvent, debounce, deleteTemporaryElements, depthFirstRecursion, distanceBetweenPointAndPoint, distanceBetweenPointAndRectangle, distanceBetweenPointAndSegment, downloadImage, drawArrow, drawBezierPath, drawCircle, drawLine, drawLinearPath, drawRoundRectangle, fakeNodeWeakMap, getBoardRectangle, getElementHostBBox, getHitElementOfRoot, getHitElements, getIsRecursionFunc, getMovingElements, getRealScrollBarWidth, getRectangleByElements, getSelectedElements, getTemporaryElements, getViewBox, getViewBoxCenterPoint, getViewportContainerRect, getViewportOrigination, hasBeforeContextChange, hasInputOrTextareaTarget, hasOnBoardChange, hasOnContextChanged, hotkeys, idCreator, initializeViewBox, initializeViewportContainer, initializeViewportOffset, inverse, isDOMElement, isDOMNode, isFromScrolling, isFromViewportChange, isHitElements, isInPlaitBoard, isMainPointer, isNullOrUndefined, isSecondaryPointer, isSelectedElement, isSelectionMoving, isSetViewportOperation, normalizePoint, preventNativeSelection, removeMovingElements, removeSelectedElement, rotate, scrollToRectangle, setIsFromScrolling, setIsFromViewportChange, setSVGViewBox, setSelectionMoving, shouldClear, shouldMerge, shouldSave, throttleRAF, toImage, toPoint, transformPoint, transformPoints, updateForeignObject, updateViewportContainerScroll, updateViewportOffset, updateViewportOrigination, withMoving, withOptions, withSelection };
|
|
3326
3307
|
//# sourceMappingURL=plait-core.mjs.map
|