@lvce-editor/main-area-worker 5.11.0 → 5.12.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/dist/mainAreaWorkerMain.js +151 -48
- package/package.json +1 -1
|
@@ -1541,12 +1541,24 @@ const closeTab = (state, groupId, tabId) => {
|
|
|
1541
1541
|
activeGroupId,
|
|
1542
1542
|
groups
|
|
1543
1543
|
} = layout;
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1544
|
+
|
|
1545
|
+
// Find the group to close the tab from
|
|
1546
|
+
const groupIndex = groups.findIndex(g => g.id === groupId);
|
|
1547
|
+
if (groupIndex === -1) {
|
|
1548
|
+
return state;
|
|
1549
|
+
}
|
|
1550
|
+
const group = groups[groupIndex];
|
|
1551
|
+
// Check if the tab exists in the group
|
|
1552
|
+
const tabWasRemoved = group.tabs.some(tab => tab.id === tabId);
|
|
1553
|
+
if (!tabWasRemoved) {
|
|
1554
|
+
return state;
|
|
1555
|
+
}
|
|
1556
|
+
const newGroups = groups.map(grp => {
|
|
1557
|
+
if (grp.id === groupId) {
|
|
1558
|
+
const newTabs = grp.tabs.filter(tab => tab.id !== tabId);
|
|
1559
|
+
let newActiveTabId = grp.activeTabId;
|
|
1560
|
+
if (grp.activeTabId === tabId) {
|
|
1561
|
+
const tabIndex = grp.tabs.findIndex(tab => tab.id === tabId);
|
|
1550
1562
|
if (newTabs.length > 0) {
|
|
1551
1563
|
newActiveTabId = newTabs[Math.min(tabIndex, newTabs.length - 1)].id;
|
|
1552
1564
|
} else {
|
|
@@ -1554,29 +1566,43 @@ const closeTab = (state, groupId, tabId) => {
|
|
|
1554
1566
|
}
|
|
1555
1567
|
}
|
|
1556
1568
|
return {
|
|
1557
|
-
...
|
|
1569
|
+
...grp,
|
|
1558
1570
|
activeTabId: newActiveTabId,
|
|
1559
1571
|
tabs: newTabs
|
|
1560
1572
|
};
|
|
1561
1573
|
}
|
|
1562
|
-
return
|
|
1574
|
+
return grp;
|
|
1563
1575
|
});
|
|
1564
1576
|
|
|
1565
|
-
// If the group has no tabs left
|
|
1566
|
-
const
|
|
1567
|
-
if (
|
|
1577
|
+
// If the group has no tabs left after closing, remove the group
|
|
1578
|
+
const groupIsNowEmpty = newGroups[groupIndex].tabs.length === 0;
|
|
1579
|
+
if (groupIsNowEmpty) {
|
|
1568
1580
|
const remainingGroups = newGroups.filter(group => group.id !== groupId);
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1581
|
+
|
|
1582
|
+
// If there are remaining groups, redistribute sizes
|
|
1583
|
+
if (remainingGroups.length > 0) {
|
|
1584
|
+
const redistributedGroups = remainingGroups.map(grp => ({
|
|
1585
|
+
...grp,
|
|
1586
|
+
size: Math.round(100 / remainingGroups.length)
|
|
1587
|
+
}));
|
|
1588
|
+
const newActiveGroupId = activeGroupId === groupId ? remainingGroups[0]?.id : activeGroupId;
|
|
1589
|
+
return {
|
|
1590
|
+
...state,
|
|
1591
|
+
layout: {
|
|
1592
|
+
...layout,
|
|
1593
|
+
activeGroupId: newActiveGroupId,
|
|
1594
|
+
groups: redistributedGroups
|
|
1595
|
+
}
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
// If no remaining groups, return empty layout
|
|
1574
1600
|
return {
|
|
1575
1601
|
...state,
|
|
1576
1602
|
layout: {
|
|
1577
1603
|
...layout,
|
|
1578
|
-
activeGroupId:
|
|
1579
|
-
groups:
|
|
1604
|
+
activeGroupId: undefined,
|
|
1605
|
+
groups: []
|
|
1580
1606
|
}
|
|
1581
1607
|
};
|
|
1582
1608
|
}
|
|
@@ -1671,6 +1697,73 @@ const handleClick = async (state, name) => {
|
|
|
1671
1697
|
return state;
|
|
1672
1698
|
};
|
|
1673
1699
|
|
|
1700
|
+
const getActiveGroup = (groups, activeGroupId) => {
|
|
1701
|
+
return groups.find(g => g.id === activeGroupId);
|
|
1702
|
+
};
|
|
1703
|
+
|
|
1704
|
+
const Right = 'right';
|
|
1705
|
+
|
|
1706
|
+
const splitEditorGroup$1 = (state, groupId, direction) => {
|
|
1707
|
+
const {
|
|
1708
|
+
layout
|
|
1709
|
+
} = state;
|
|
1710
|
+
const {
|
|
1711
|
+
groups
|
|
1712
|
+
} = layout;
|
|
1713
|
+
const sourceGroup = groups.find(group => group.id === groupId);
|
|
1714
|
+
if (!sourceGroup) {
|
|
1715
|
+
return state;
|
|
1716
|
+
}
|
|
1717
|
+
const newGroupId = create$1();
|
|
1718
|
+
const isHorizontalSplit = direction === Right;
|
|
1719
|
+
const newLayoutDirection = isHorizontalSplit ? 'horizontal' : 'vertical';
|
|
1720
|
+
const updatedGroups = groups.map(group => {
|
|
1721
|
+
if (group.id === groupId) {
|
|
1722
|
+
return {
|
|
1723
|
+
...group,
|
|
1724
|
+
focused: false,
|
|
1725
|
+
size: 50
|
|
1726
|
+
};
|
|
1727
|
+
}
|
|
1728
|
+
return group;
|
|
1729
|
+
});
|
|
1730
|
+
const newGroup = {
|
|
1731
|
+
activeTabId: undefined,
|
|
1732
|
+
focused: true,
|
|
1733
|
+
id: newGroupId,
|
|
1734
|
+
size: 50,
|
|
1735
|
+
tabs: []
|
|
1736
|
+
};
|
|
1737
|
+
let reorderedGroups;
|
|
1738
|
+
{
|
|
1739
|
+
reorderedGroups = [...updatedGroups, newGroup];
|
|
1740
|
+
}
|
|
1741
|
+
return {
|
|
1742
|
+
...state,
|
|
1743
|
+
layout: {
|
|
1744
|
+
activeGroupId: newGroupId,
|
|
1745
|
+
direction: newLayoutDirection,
|
|
1746
|
+
groups: reorderedGroups
|
|
1747
|
+
}
|
|
1748
|
+
};
|
|
1749
|
+
};
|
|
1750
|
+
|
|
1751
|
+
const handleClickAction = async (state, action) => {
|
|
1752
|
+
if (!action) {
|
|
1753
|
+
return state;
|
|
1754
|
+
}
|
|
1755
|
+
const activeGroup = getActiveGroup(state.layout.groups, state.layout.activeGroupId);
|
|
1756
|
+
if (!activeGroup) {
|
|
1757
|
+
return state;
|
|
1758
|
+
}
|
|
1759
|
+
switch (action) {
|
|
1760
|
+
case 'split-right':
|
|
1761
|
+
return splitEditorGroup$1(state, activeGroup.id, Right);
|
|
1762
|
+
default:
|
|
1763
|
+
return state;
|
|
1764
|
+
}
|
|
1765
|
+
};
|
|
1766
|
+
|
|
1674
1767
|
const handleClickCloseTab = (state, rawGroupIndex, rawIndex) => {
|
|
1675
1768
|
if (!rawGroupIndex || !rawIndex) {
|
|
1676
1769
|
return state;
|
|
@@ -3099,23 +3192,6 @@ const HandleClickClose = 12;
|
|
|
3099
3192
|
const HandleClickTab = 13;
|
|
3100
3193
|
const HandleTabContextMenu = 14;
|
|
3101
3194
|
|
|
3102
|
-
const renderEditorGroupActions = (group, groupIndex, splitButtonEnabled) => {
|
|
3103
|
-
return [{
|
|
3104
|
-
childCount: 1,
|
|
3105
|
-
className: 'EditorGroupActions',
|
|
3106
|
-
role: 'toolbar',
|
|
3107
|
-
type: Div
|
|
3108
|
-
}, {
|
|
3109
|
-
childCount: 1,
|
|
3110
|
-
className: 'EditorGroupActionButton SplitEditorGroupButton',
|
|
3111
|
-
'data-action': 'split-right',
|
|
3112
|
-
'data-groupId': String(group.id),
|
|
3113
|
-
onClick: HandleClickAction,
|
|
3114
|
-
title: splitEditorGroup(),
|
|
3115
|
-
type: Button
|
|
3116
|
-
}, text('split')];
|
|
3117
|
-
};
|
|
3118
|
-
|
|
3119
3195
|
const renderTab = (tab, isActive, tabIndex, groupIndex) => {
|
|
3120
3196
|
return [{
|
|
3121
3197
|
'aria-selected': isActive,
|
|
@@ -3153,36 +3229,60 @@ const renderTab = (tab, isActive, tabIndex, groupIndex) => {
|
|
|
3153
3229
|
}];
|
|
3154
3230
|
};
|
|
3155
3231
|
|
|
3232
|
+
const getTabsVirtualDom = (group, groupIndex, tabsChildCount) => {
|
|
3233
|
+
return [{
|
|
3234
|
+
childCount: tabsChildCount,
|
|
3235
|
+
className: 'MainTabs',
|
|
3236
|
+
role: 'tablist',
|
|
3237
|
+
type: Div
|
|
3238
|
+
}, ...group.tabs.flatMap((tab, tabIndex) => renderTab(tab, tab.id === group.activeTabId, tabIndex, groupIndex))];
|
|
3239
|
+
};
|
|
3240
|
+
|
|
3241
|
+
const renderEditorGroupActions = (group, groupIndex, splitButtonEnabled) => {
|
|
3242
|
+
if (!splitButtonEnabled) {
|
|
3243
|
+
return [];
|
|
3244
|
+
}
|
|
3245
|
+
return [{
|
|
3246
|
+
childCount: 1,
|
|
3247
|
+
className: 'EditorGroupActions',
|
|
3248
|
+
role: 'toolbar',
|
|
3249
|
+
type: Div
|
|
3250
|
+
}, {
|
|
3251
|
+
childCount: 1,
|
|
3252
|
+
className: 'EditorGroupActionButton SplitEditorGroupButton',
|
|
3253
|
+
'data-action': 'split-right',
|
|
3254
|
+
'data-groupId': String(group.id),
|
|
3255
|
+
onClick: HandleClickAction,
|
|
3256
|
+
title: splitEditorGroup(),
|
|
3257
|
+
type: Button
|
|
3258
|
+
}, text('split')];
|
|
3259
|
+
};
|
|
3260
|
+
|
|
3156
3261
|
const renderEditorGroupHeader = (group, groupIndex, splitButtonEnabled) => {
|
|
3157
3262
|
const tabsChildCount = group.tabs.length;
|
|
3158
|
-
const actions = renderEditorGroupActions(group);
|
|
3263
|
+
const actions = renderEditorGroupActions(group, groupIndex, splitButtonEnabled);
|
|
3159
3264
|
return [{
|
|
3160
|
-
childCount: 2,
|
|
3265
|
+
childCount: actions.length > 0 ? 2 : 1,
|
|
3161
3266
|
className: 'EditorGroupHeader',
|
|
3162
3267
|
role: 'none',
|
|
3163
3268
|
type: Div
|
|
3164
|
-
},
|
|
3165
|
-
childCount: tabsChildCount,
|
|
3166
|
-
className: 'MainTabs',
|
|
3167
|
-
role: 'tablist',
|
|
3168
|
-
type: Div
|
|
3169
|
-
}, ...group.tabs.flatMap((tab, tabIndex) => renderTab(tab, tab.id === group.activeTabId, tabIndex, groupIndex)), ...actions];
|
|
3269
|
+
}, ...getTabsVirtualDom(group, groupIndex, tabsChildCount), ...actions];
|
|
3170
3270
|
};
|
|
3171
3271
|
|
|
3172
|
-
const renderEditorGroup = (group, groupIndex) => {
|
|
3272
|
+
const renderEditorGroup = (group, groupIndex, splitButtonEnabled = false) => {
|
|
3173
3273
|
const activeTab = group.tabs.find(tab => tab.id === group.activeTabId);
|
|
3174
3274
|
return [{
|
|
3175
3275
|
childCount: 2,
|
|
3176
3276
|
className: 'EditorGroup',
|
|
3177
3277
|
type: Div
|
|
3178
|
-
}, ...renderEditorGroupHeader(group, groupIndex), {
|
|
3278
|
+
}, ...renderEditorGroupHeader(group, groupIndex, splitButtonEnabled), {
|
|
3179
3279
|
childCount: activeTab ? 1 : 1,
|
|
3180
3280
|
className: 'EditorContainer',
|
|
3181
3281
|
type: Div
|
|
3182
3282
|
}, ...renderEditor(activeTab)];
|
|
3183
3283
|
};
|
|
3184
3284
|
|
|
3185
|
-
const getMainAreaVirtualDom = layout => {
|
|
3285
|
+
const getMainAreaVirtualDom = (layout, splitButtonEnabled = false) => {
|
|
3186
3286
|
return [{
|
|
3187
3287
|
childCount: 1,
|
|
3188
3288
|
className: 'Main',
|
|
@@ -3190,16 +3290,18 @@ const getMainAreaVirtualDom = layout => {
|
|
|
3190
3290
|
}, {
|
|
3191
3291
|
childCount: layout.groups.length,
|
|
3192
3292
|
className: CSS_CLASSES.EDITOR_GROUPS_CONTAINER,
|
|
3293
|
+
role: 'none',
|
|
3193
3294
|
type: Div
|
|
3194
|
-
}, ...layout.groups.flatMap((group, groupIndex) => renderEditorGroup(group, groupIndex))];
|
|
3295
|
+
}, ...layout.groups.flatMap((group, groupIndex) => renderEditorGroup(group, groupIndex, splitButtonEnabled))];
|
|
3195
3296
|
};
|
|
3196
3297
|
|
|
3197
3298
|
const renderItems = (oldState, newState) => {
|
|
3198
3299
|
const {
|
|
3199
3300
|
layout,
|
|
3301
|
+
splitButtonEnabled,
|
|
3200
3302
|
uid
|
|
3201
3303
|
} = newState;
|
|
3202
|
-
const dom = getMainAreaVirtualDom(layout);
|
|
3304
|
+
const dom = getMainAreaVirtualDom(layout, splitButtonEnabled);
|
|
3203
3305
|
return [SetDom2, uid, dom];
|
|
3204
3306
|
};
|
|
3205
3307
|
|
|
@@ -3326,6 +3428,7 @@ const commandMap = {
|
|
|
3326
3428
|
'MainArea.getMenuEntries': wrapGetter(getMenuEntries),
|
|
3327
3429
|
'MainArea.getMenuIds': getMenuIds,
|
|
3328
3430
|
'MainArea.handleClick': wrapCommand(handleClick),
|
|
3431
|
+
'MainArea.handleClickAction': wrapCommand(handleClickAction),
|
|
3329
3432
|
'MainArea.handleClickCloseTab': wrapCommand(handleClickCloseTab),
|
|
3330
3433
|
'MainArea.handleClickTab': wrapCommand(handleClickTab),
|
|
3331
3434
|
'MainArea.handleTabContextMenu': wrapCommand(handleTabContextMenu),
|