@sequent-org/moodboard 1.4.20 → 1.4.21
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/package.json
CHANGED
|
@@ -9,11 +9,38 @@ function getSelectTool(board) {
|
|
|
9
9
|
|| null;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
||
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
function shouldOpenEditorForObject(objectType) {
|
|
13
|
+
return objectType === 'mindmap'
|
|
14
|
+
|| objectType === 'text'
|
|
15
|
+
|| objectType === 'simple-text'
|
|
16
|
+
|| objectType === 'note'
|
|
17
|
+
|| objectType === 'file';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function focusCreatedObject(board, createdObject) {
|
|
21
|
+
if (!board?.coreMoodboard?.eventBus || !createdObject?.id) return;
|
|
22
|
+
const objectType = createdObject?.type || null;
|
|
23
|
+
const objectPayload = {
|
|
24
|
+
id: createdObject.id,
|
|
25
|
+
type: objectType,
|
|
26
|
+
position: createdObject.position || null,
|
|
27
|
+
properties: createdObject.properties || {},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Run after object is mounted so selection/HTML overlays can sync first.
|
|
31
|
+
setTimeout(() => {
|
|
32
|
+
board.coreMoodboard.eventBus.emit(Events.Keyboard.ToolSelect, { tool: 'select' });
|
|
33
|
+
const selectTool = getSelectTool(board);
|
|
34
|
+
if (typeof selectTool?.setSelection === 'function') {
|
|
35
|
+
selectTool.setSelection([createdObject.id]);
|
|
36
|
+
}
|
|
37
|
+
if (shouldOpenEditorForObject(objectType)) {
|
|
38
|
+
board.coreMoodboard.eventBus.emit(Events.Tool.ObjectEdit, {
|
|
39
|
+
object: objectPayload,
|
|
40
|
+
create: true,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}, 0);
|
|
17
44
|
}
|
|
18
45
|
|
|
19
46
|
export function bindToolbarEvents(board) {
|
|
@@ -26,63 +53,8 @@ export function bindToolbarEvents(board) {
|
|
|
26
53
|
});
|
|
27
54
|
}
|
|
28
55
|
const createdObject = board.actionHandler.handleToolbarAction(action);
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
const createdMeta = createdObject?.properties?.mindmap || {};
|
|
32
|
-
const isRootMindmap = createdMeta?.role === 'root';
|
|
33
|
-
const mindmapObjects = (board?.coreMoodboard?.state?.state?.objects || [])
|
|
34
|
-
.filter((obj) => obj?.type === 'mindmap');
|
|
35
|
-
const rootCount = mindmapObjects.filter((obj) => (obj?.properties?.mindmap?.role || null) === 'root').length;
|
|
36
|
-
const shouldAutoOpenForRoot = !isRootMindmap || rootCount <= 1;
|
|
37
|
-
const selectTool = getSelectTool(board);
|
|
38
|
-
const hasActiveEditor = Boolean(selectTool?.textEditor?.active);
|
|
39
|
-
const hasEditorDom = hasOpenTextEditorInDom(board);
|
|
40
|
-
const shouldBlockAutoOpen = hasActiveEditor && hasEditorDom;
|
|
41
|
-
if (content.trim().length === 0 && !shouldBlockAutoOpen && shouldAutoOpenForRoot) {
|
|
42
|
-
const doc = board?.workspaceElement?.ownerDocument
|
|
43
|
-
|| (typeof document !== 'undefined' ? document : null);
|
|
44
|
-
const closeSeqAtSchedule = Number(selectTool?._mindmapEditorCloseSeq || 0);
|
|
45
|
-
let cancelledByPointer = false;
|
|
46
|
-
const cancelOnPointerDown = () => {
|
|
47
|
-
cancelledByPointer = true;
|
|
48
|
-
};
|
|
49
|
-
const cancelOnEscape = (event) => {
|
|
50
|
-
if (event?.key === 'Escape') {
|
|
51
|
-
cancelledByPointer = true;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
if (doc && typeof doc.addEventListener === 'function') {
|
|
55
|
-
doc.addEventListener('pointerdown', cancelOnPointerDown, true);
|
|
56
|
-
doc.addEventListener('keydown', cancelOnEscape, true);
|
|
57
|
-
}
|
|
58
|
-
setTimeout(() => {
|
|
59
|
-
if (doc && typeof doc.removeEventListener === 'function') {
|
|
60
|
-
doc.removeEventListener('pointerdown', cancelOnPointerDown, true);
|
|
61
|
-
doc.removeEventListener('keydown', cancelOnEscape, true);
|
|
62
|
-
}
|
|
63
|
-
if (cancelledByPointer) return;
|
|
64
|
-
const latestSelectTool = getSelectTool(board);
|
|
65
|
-
const latestCloseSeq = Number(latestSelectTool?._mindmapEditorCloseSeq || 0);
|
|
66
|
-
if (latestCloseSeq !== closeSeqAtSchedule) return;
|
|
67
|
-
|
|
68
|
-
const nextSelectTool = getSelectTool(board);
|
|
69
|
-
const nextHasActiveEditor = Boolean(nextSelectTool?.textEditor?.active);
|
|
70
|
-
const nextHasEditorDom = hasOpenTextEditorInDom(board);
|
|
71
|
-
if (nextHasActiveEditor || nextHasEditorDom) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
board.coreMoodboard.eventBus.emit(Events.Keyboard.ToolSelect, { tool: 'select' });
|
|
75
|
-
board.coreMoodboard.eventBus.emit(Events.Tool.ObjectEdit, {
|
|
76
|
-
object: {
|
|
77
|
-
id: createdObject.id,
|
|
78
|
-
type: 'mindmap',
|
|
79
|
-
position: createdObject.position || null,
|
|
80
|
-
properties: createdObject.properties || {},
|
|
81
|
-
},
|
|
82
|
-
create: true,
|
|
83
|
-
});
|
|
84
|
-
}, 0);
|
|
85
|
-
}
|
|
56
|
+
if (createdObject?.id) {
|
|
57
|
+
focusCreatedObject(board, createdObject);
|
|
86
58
|
}
|
|
87
59
|
});
|
|
88
60
|
|