@plait/core 0.62.0-next.7 → 0.62.0-next.9
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/esm2022/core/list-render.mjs +10 -2
- package/esm2022/utils/common.mjs +16 -13
- package/esm2022/utils/drawing/rectangle.mjs +4 -2
- package/esm2022/utils/selected-element.mjs +25 -4
- package/fesm2022/plait-core.mjs +140 -107
- package/fesm2022/plait-core.mjs.map +1 -1
- package/package.json +15 -4
- package/utils/common.d.ts +2 -2
package/fesm2022/plait-core.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createDraft, finishDraft, isDraft } from 'immer';
|
|
2
2
|
import { isKeyHotkey, isHotkey } from 'is-hotkey';
|
|
3
|
-
import {
|
|
3
|
+
import { Subject } from 'rxjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @license
|
|
@@ -1576,6 +1576,96 @@ var PlaitPluginKey;
|
|
|
1576
1576
|
PlaitPluginKey["withSelection"] = "withSelection";
|
|
1577
1577
|
})(PlaitPluginKey || (PlaitPluginKey = {}));
|
|
1578
1578
|
|
|
1579
|
+
const TEMPORARY_G = new Map();
|
|
1580
|
+
const getTemporaryGArray = (debugKey) => {
|
|
1581
|
+
return TEMPORARY_G.get(debugKey) || [];
|
|
1582
|
+
};
|
|
1583
|
+
const setTemporaryGArray = (debugKey, gArray) => {
|
|
1584
|
+
TEMPORARY_G.set(debugKey, gArray);
|
|
1585
|
+
};
|
|
1586
|
+
class DebugGenerator {
|
|
1587
|
+
constructor(debugKey) {
|
|
1588
|
+
this.debugKey = debugKey;
|
|
1589
|
+
}
|
|
1590
|
+
isDebug() {
|
|
1591
|
+
return isDebug(this.debugKey);
|
|
1592
|
+
}
|
|
1593
|
+
clear() {
|
|
1594
|
+
if (!this.isDebug()) {
|
|
1595
|
+
return;
|
|
1596
|
+
}
|
|
1597
|
+
const gArray = getTemporaryGArray(this.debugKey);
|
|
1598
|
+
setTemporaryGArray(this.debugKey, []);
|
|
1599
|
+
gArray.forEach(g => g.remove());
|
|
1600
|
+
}
|
|
1601
|
+
drawPolygon(board, points, options) {
|
|
1602
|
+
if (!isDebug(this.debugKey)) {
|
|
1603
|
+
return;
|
|
1604
|
+
}
|
|
1605
|
+
const polygonG = PlaitBoard.getRoughSVG(board).polygon(points, options || { stroke: 'red' });
|
|
1606
|
+
polygonG.classList.add(this.debugKey);
|
|
1607
|
+
PlaitBoard.getElementActiveHost(board).append(polygonG);
|
|
1608
|
+
const gArray = getTemporaryGArray(this.debugKey);
|
|
1609
|
+
gArray.push(polygonG);
|
|
1610
|
+
setTemporaryGArray(this.debugKey, gArray);
|
|
1611
|
+
return polygonG;
|
|
1612
|
+
}
|
|
1613
|
+
drawLine(board, points, options) {
|
|
1614
|
+
if (!isDebug(this.debugKey)) {
|
|
1615
|
+
return;
|
|
1616
|
+
}
|
|
1617
|
+
const lineG = PlaitBoard.getRoughSVG(board).linearPath(points, options || { stroke: 'red' });
|
|
1618
|
+
lineG.classList.add(this.debugKey);
|
|
1619
|
+
PlaitBoard.getElementActiveHost(board).append(lineG);
|
|
1620
|
+
const gArray = getTemporaryGArray(this.debugKey);
|
|
1621
|
+
gArray.push(lineG);
|
|
1622
|
+
setTemporaryGArray(this.debugKey, gArray);
|
|
1623
|
+
return lineG;
|
|
1624
|
+
}
|
|
1625
|
+
drawRectangle(board, data, options) {
|
|
1626
|
+
if (!isDebug(this.debugKey)) {
|
|
1627
|
+
return;
|
|
1628
|
+
}
|
|
1629
|
+
let rectangle;
|
|
1630
|
+
if (data instanceof Array) {
|
|
1631
|
+
rectangle = RectangleClient.getRectangleByPoints(data);
|
|
1632
|
+
}
|
|
1633
|
+
else {
|
|
1634
|
+
rectangle = data;
|
|
1635
|
+
}
|
|
1636
|
+
const rectangleG = PlaitBoard.getRoughSVG(board).rectangle(rectangle.x, rectangle.y, rectangle.width, rectangle.height, options || { stroke: 'red' });
|
|
1637
|
+
rectangleG.classList.add(this.debugKey);
|
|
1638
|
+
PlaitBoard.getElementActiveHost(board).append(rectangleG);
|
|
1639
|
+
const gArray = getTemporaryGArray(this.debugKey);
|
|
1640
|
+
gArray.push(rectangleG);
|
|
1641
|
+
setTemporaryGArray(this.debugKey, gArray);
|
|
1642
|
+
return rectangleG;
|
|
1643
|
+
}
|
|
1644
|
+
drawCircles(board, points, diameter = 0, isCumulativeDiameter = false, options) {
|
|
1645
|
+
if (!isDebug(this.debugKey)) {
|
|
1646
|
+
return;
|
|
1647
|
+
}
|
|
1648
|
+
const result = [];
|
|
1649
|
+
points.forEach((p, i) => {
|
|
1650
|
+
const circle = PlaitBoard.getRoughSVG(board).circle(p[0], p[1], isCumulativeDiameter ? diameter * (i + 1) : diameter, Object.assign({}, { stroke: 'red', fill: 'red', fillStyle: 'solid' }, options || {}));
|
|
1651
|
+
circle.classList.add(this.debugKey);
|
|
1652
|
+
PlaitBoard.getElementActiveHost(board).append(circle);
|
|
1653
|
+
const gArray = getTemporaryGArray(this.debugKey);
|
|
1654
|
+
gArray.push(circle);
|
|
1655
|
+
result.push(circle);
|
|
1656
|
+
setTemporaryGArray(this.debugKey, gArray);
|
|
1657
|
+
});
|
|
1658
|
+
return result;
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
const createDebugGenerator = (debugKey) => {
|
|
1662
|
+
return new DebugGenerator(debugKey);
|
|
1663
|
+
};
|
|
1664
|
+
const isDebug = (key) => {
|
|
1665
|
+
const defaultKey = 'debug:plait';
|
|
1666
|
+
return localStorage.getItem(key || defaultKey) === 'true';
|
|
1667
|
+
};
|
|
1668
|
+
|
|
1579
1669
|
const getHitElementsBySelection = (board, selection, match = () => true) => {
|
|
1580
1670
|
const newSelection = selection || board.selection;
|
|
1581
1671
|
const rectangleHitElements = [];
|
|
@@ -1593,8 +1683,19 @@ const getHitElementsBySelection = (board, selection, match = () => true) => {
|
|
|
1593
1683
|
}
|
|
1594
1684
|
}
|
|
1595
1685
|
depthFirstRecursion(board, node => {
|
|
1596
|
-
if (!PlaitBoard.isBoard(node) && match(node)
|
|
1597
|
-
|
|
1686
|
+
if (!PlaitBoard.isBoard(node) && match(node)) {
|
|
1687
|
+
let isRectangleHit = false;
|
|
1688
|
+
try {
|
|
1689
|
+
isRectangleHit = board.isRectangleHit(node, newSelection);
|
|
1690
|
+
}
|
|
1691
|
+
catch (error) {
|
|
1692
|
+
if (isDebug()) {
|
|
1693
|
+
console.error('isRectangleHit', error, 'node', node);
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
if (isRectangleHit) {
|
|
1697
|
+
rectangleHitElements.push(node);
|
|
1698
|
+
}
|
|
1598
1699
|
}
|
|
1599
1700
|
}, getIsRecursionFunc(board), true);
|
|
1600
1701
|
return rectangleHitElements;
|
|
@@ -1605,7 +1706,16 @@ const getHitElementsByPoint = (board, point, match = () => true) => {
|
|
|
1605
1706
|
if (PlaitBoard.isBoard(node) || !match(node) || !PlaitElement.hasMounted(node)) {
|
|
1606
1707
|
return;
|
|
1607
1708
|
}
|
|
1608
|
-
|
|
1709
|
+
let isHit = false;
|
|
1710
|
+
try {
|
|
1711
|
+
isHit = board.isHit(node, point);
|
|
1712
|
+
}
|
|
1713
|
+
catch (error) {
|
|
1714
|
+
if (isDebug()) {
|
|
1715
|
+
console.error('isHit', error, 'node', node);
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
if (isHit) {
|
|
1609
1719
|
hitElements.push(node);
|
|
1610
1720
|
return;
|
|
1611
1721
|
}
|
|
@@ -1709,7 +1819,9 @@ function drawRoundRectangle(rs, x1, y1, x2, y2, options, outline = false, border
|
|
|
1709
1819
|
const point6 = [x1 + radius, y2];
|
|
1710
1820
|
const point7 = [x1, y2 - radius];
|
|
1711
1821
|
const point8 = [x1, y1 + radius];
|
|
1712
|
-
|
|
1822
|
+
const rectangleG = 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);
|
|
1823
|
+
setStrokeLinecap(rectangleG, 'round');
|
|
1824
|
+
return rectangleG;
|
|
1713
1825
|
}
|
|
1714
1826
|
const drawRectangle = (board, rectangle, options) => {
|
|
1715
1827
|
const roughSVG = PlaitBoard.getRoughSVG(board);
|
|
@@ -2205,21 +2317,25 @@ const throttleRAF = (board, key, fn) => {
|
|
|
2205
2317
|
scheduleFunc();
|
|
2206
2318
|
};
|
|
2207
2319
|
const debounce = (func, wait, options) => {
|
|
2208
|
-
let
|
|
2209
|
-
return () => {
|
|
2210
|
-
if (
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
func();
|
|
2214
|
-
|
|
2320
|
+
let timeout = null;
|
|
2321
|
+
return (args) => {
|
|
2322
|
+
if (timeout !== null) {
|
|
2323
|
+
clearTimeout(timeout);
|
|
2324
|
+
timeout = setTimeout(() => {
|
|
2325
|
+
func(args);
|
|
2326
|
+
timeout = null;
|
|
2327
|
+
}, wait);
|
|
2215
2328
|
}
|
|
2216
2329
|
else {
|
|
2217
2330
|
if (options?.leading) {
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2331
|
+
func(args);
|
|
2332
|
+
}
|
|
2333
|
+
else {
|
|
2334
|
+
timeout = setTimeout(() => {
|
|
2335
|
+
func(args);
|
|
2336
|
+
timeout = null;
|
|
2337
|
+
}, wait);
|
|
2221
2338
|
}
|
|
2222
|
-
timerSubscription = timer(wait).subscribe();
|
|
2223
2339
|
}
|
|
2224
2340
|
};
|
|
2225
2341
|
};
|
|
@@ -4890,7 +5006,14 @@ const trackBy = (index, element) => {
|
|
|
4890
5006
|
const createPluginComponent = (board, componentType, context, childrenContext) => {
|
|
4891
5007
|
const instance = new componentType();
|
|
4892
5008
|
instance.context = context;
|
|
4893
|
-
|
|
5009
|
+
try {
|
|
5010
|
+
instance.initialize();
|
|
5011
|
+
}
|
|
5012
|
+
catch (error) {
|
|
5013
|
+
if (isDebug()) {
|
|
5014
|
+
console.error('list-render-initialize', error, 'context', context);
|
|
5015
|
+
}
|
|
5016
|
+
}
|
|
4894
5017
|
const g = instance.getContainerG();
|
|
4895
5018
|
mountElementG(context.index, g, childrenContext);
|
|
4896
5019
|
instance.initializeListRender();
|
|
@@ -6405,96 +6528,6 @@ function createModModifierKeys() {
|
|
|
6405
6528
|
return modifiers;
|
|
6406
6529
|
}
|
|
6407
6530
|
|
|
6408
|
-
const TEMPORARY_G = new Map();
|
|
6409
|
-
const getTemporaryGArray = (debugKey) => {
|
|
6410
|
-
return TEMPORARY_G.get(debugKey) || [];
|
|
6411
|
-
};
|
|
6412
|
-
const setTemporaryGArray = (debugKey, gArray) => {
|
|
6413
|
-
TEMPORARY_G.set(debugKey, gArray);
|
|
6414
|
-
};
|
|
6415
|
-
class DebugGenerator {
|
|
6416
|
-
constructor(debugKey) {
|
|
6417
|
-
this.debugKey = debugKey;
|
|
6418
|
-
}
|
|
6419
|
-
isDebug() {
|
|
6420
|
-
return isDebug(this.debugKey);
|
|
6421
|
-
}
|
|
6422
|
-
clear() {
|
|
6423
|
-
if (!this.isDebug()) {
|
|
6424
|
-
return;
|
|
6425
|
-
}
|
|
6426
|
-
const gArray = getTemporaryGArray(this.debugKey);
|
|
6427
|
-
setTemporaryGArray(this.debugKey, []);
|
|
6428
|
-
gArray.forEach(g => g.remove());
|
|
6429
|
-
}
|
|
6430
|
-
drawPolygon(board, points, options) {
|
|
6431
|
-
if (!isDebug(this.debugKey)) {
|
|
6432
|
-
return;
|
|
6433
|
-
}
|
|
6434
|
-
const polygonG = PlaitBoard.getRoughSVG(board).polygon(points, options || { stroke: 'red' });
|
|
6435
|
-
polygonG.classList.add(this.debugKey);
|
|
6436
|
-
PlaitBoard.getElementActiveHost(board).append(polygonG);
|
|
6437
|
-
const gArray = getTemporaryGArray(this.debugKey);
|
|
6438
|
-
gArray.push(polygonG);
|
|
6439
|
-
setTemporaryGArray(this.debugKey, gArray);
|
|
6440
|
-
return polygonG;
|
|
6441
|
-
}
|
|
6442
|
-
drawLine(board, points, options) {
|
|
6443
|
-
if (!isDebug(this.debugKey)) {
|
|
6444
|
-
return;
|
|
6445
|
-
}
|
|
6446
|
-
const lineG = PlaitBoard.getRoughSVG(board).linearPath(points, options || { stroke: 'red' });
|
|
6447
|
-
lineG.classList.add(this.debugKey);
|
|
6448
|
-
PlaitBoard.getElementActiveHost(board).append(lineG);
|
|
6449
|
-
const gArray = getTemporaryGArray(this.debugKey);
|
|
6450
|
-
gArray.push(lineG);
|
|
6451
|
-
setTemporaryGArray(this.debugKey, gArray);
|
|
6452
|
-
return lineG;
|
|
6453
|
-
}
|
|
6454
|
-
drawRectangle(board, data, options) {
|
|
6455
|
-
if (!isDebug(this.debugKey)) {
|
|
6456
|
-
return;
|
|
6457
|
-
}
|
|
6458
|
-
let rectangle;
|
|
6459
|
-
if (data instanceof Array) {
|
|
6460
|
-
rectangle = RectangleClient.getRectangleByPoints(data);
|
|
6461
|
-
}
|
|
6462
|
-
else {
|
|
6463
|
-
rectangle = data;
|
|
6464
|
-
}
|
|
6465
|
-
const rectangleG = PlaitBoard.getRoughSVG(board).rectangle(rectangle.x, rectangle.y, rectangle.width, rectangle.height, options || { stroke: 'red' });
|
|
6466
|
-
rectangleG.classList.add(this.debugKey);
|
|
6467
|
-
PlaitBoard.getElementActiveHost(board).append(rectangleG);
|
|
6468
|
-
const gArray = getTemporaryGArray(this.debugKey);
|
|
6469
|
-
gArray.push(rectangleG);
|
|
6470
|
-
setTemporaryGArray(this.debugKey, gArray);
|
|
6471
|
-
return rectangleG;
|
|
6472
|
-
}
|
|
6473
|
-
drawCircles(board, points, diameter = 0, isCumulativeDiameter = false, options) {
|
|
6474
|
-
if (!isDebug(this.debugKey)) {
|
|
6475
|
-
return;
|
|
6476
|
-
}
|
|
6477
|
-
const result = [];
|
|
6478
|
-
points.forEach((p, i) => {
|
|
6479
|
-
const circle = PlaitBoard.getRoughSVG(board).circle(p[0], p[1], isCumulativeDiameter ? diameter * (i + 1) : diameter, Object.assign({}, { stroke: 'red', fill: 'red', fillStyle: 'solid' }, options || {}));
|
|
6480
|
-
circle.classList.add(this.debugKey);
|
|
6481
|
-
PlaitBoard.getElementActiveHost(board).append(circle);
|
|
6482
|
-
const gArray = getTemporaryGArray(this.debugKey);
|
|
6483
|
-
gArray.push(circle);
|
|
6484
|
-
result.push(circle);
|
|
6485
|
-
setTemporaryGArray(this.debugKey, gArray);
|
|
6486
|
-
});
|
|
6487
|
-
return result;
|
|
6488
|
-
}
|
|
6489
|
-
}
|
|
6490
|
-
const createDebugGenerator = (debugKey) => {
|
|
6491
|
-
return new DebugGenerator(debugKey);
|
|
6492
|
-
};
|
|
6493
|
-
const isDebug = (key) => {
|
|
6494
|
-
const defaultKey = 'debug:plait';
|
|
6495
|
-
return localStorage.getItem(key || defaultKey) === 'true';
|
|
6496
|
-
};
|
|
6497
|
-
|
|
6498
6531
|
/*
|
|
6499
6532
|
* Public API Surface of plait
|
|
6500
6533
|
*/
|