@lvce-editor/title-bar-worker 4.22.1 → 4.24.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/titleBarWorkerMain.js +331 -302
- package/package.json +1 -1
|
@@ -3372,6 +3372,37 @@ const hydrate = async state => {
|
|
|
3372
3372
|
};
|
|
3373
3373
|
};
|
|
3374
3374
|
|
|
3375
|
+
const getComponentState = uid => {
|
|
3376
|
+
return get(uid).newState;
|
|
3377
|
+
};
|
|
3378
|
+
|
|
3379
|
+
const MaskIconCheck = 'MaskIconCheck';
|
|
3380
|
+
const MaskIcon = 'MaskIcon';
|
|
3381
|
+
const Menu = 'Menu';
|
|
3382
|
+
const MenuItem = 'MenuItem';
|
|
3383
|
+
const MenuItemCheckMark = 'MenuItemCheckMark';
|
|
3384
|
+
const MenuItemCheckmarkIcon = 'MenuItemCheckmarkIcon';
|
|
3385
|
+
const MenuItemDisabled = 'MenuItemDisabled';
|
|
3386
|
+
const MenuItemFocused = 'MenuItemFocused';
|
|
3387
|
+
const MenuItemKeyBinding = 'MenuItemKeyBinding';
|
|
3388
|
+
const MenuItemSeparator = 'MenuItemSeparator';
|
|
3389
|
+
const MenuItemSeparatorLine = 'MenuItemSeparatorLine';
|
|
3390
|
+
const MenuItemSubMenu = 'MenuItemSubMenu';
|
|
3391
|
+
const MenuItemSubMenuArrowRight = 'MenuItemSubMenuArrowRight';
|
|
3392
|
+
const TitleBar = 'TitleBar';
|
|
3393
|
+
const TitleBarButton = 'TitleBarButton';
|
|
3394
|
+
const TitleBarButtons = 'TitleBarButtons';
|
|
3395
|
+
const TitleBarCommandCenter = 'TitleBarCommandCenter';
|
|
3396
|
+
const TitleBarEntryActive = 'TitleBarEntryActive';
|
|
3397
|
+
const TitleBarIcon = 'TitleBarIcon';
|
|
3398
|
+
const TitleBarIconIcon = 'TitleBarIconIcon';
|
|
3399
|
+
const TitleBarMenuBar = 'TitleBarMenuBar';
|
|
3400
|
+
const TitleBarTopLevelEntry = 'TitleBarTopLevelEntry';
|
|
3401
|
+
const TitleBarTopLevelEntryLabel = 'TitleBarTopLevelEntryLabel';
|
|
3402
|
+
const Viewlet = 'Viewlet';
|
|
3403
|
+
|
|
3404
|
+
const Focusable = 0;
|
|
3405
|
+
|
|
3375
3406
|
const mergeClassNames = (...classNames) => {
|
|
3376
3407
|
return classNames.filter(Boolean).join(' ');
|
|
3377
3408
|
};
|
|
@@ -3386,6 +3417,263 @@ const text = data => {
|
|
|
3386
3417
|
|
|
3387
3418
|
new Set(Object.values(VirtualDomElements));
|
|
3388
3419
|
|
|
3420
|
+
const getCommandCenterVirtualDom = commandCenterEnabled => {
|
|
3421
|
+
if (!commandCenterEnabled) {
|
|
3422
|
+
return [];
|
|
3423
|
+
}
|
|
3424
|
+
return [{
|
|
3425
|
+
ariaLabel: commandCenter(),
|
|
3426
|
+
childCount: 1,
|
|
3427
|
+
className: TitleBarCommandCenter,
|
|
3428
|
+
onClick: HandleCommandCenterClick,
|
|
3429
|
+
onKeyDown: HandleCommandCenterKeyDown,
|
|
3430
|
+
role: Button$2,
|
|
3431
|
+
tabIndex: Focusable,
|
|
3432
|
+
type: Div
|
|
3433
|
+
}, text(search())];
|
|
3434
|
+
};
|
|
3435
|
+
|
|
3436
|
+
const getIcon = assetDir => {
|
|
3437
|
+
return `${assetDir}/icons/icon.svg`;
|
|
3438
|
+
};
|
|
3439
|
+
|
|
3440
|
+
const getIconVirtualDom = (icon, type = Div) => {
|
|
3441
|
+
return {
|
|
3442
|
+
childCount: 0,
|
|
3443
|
+
className: mergeClassNames(MaskIcon, `MaskIcon${icon}`),
|
|
3444
|
+
role: None$1,
|
|
3445
|
+
type
|
|
3446
|
+
};
|
|
3447
|
+
};
|
|
3448
|
+
|
|
3449
|
+
const createTitleBarButton = button => {
|
|
3450
|
+
const {
|
|
3451
|
+
icon,
|
|
3452
|
+
id,
|
|
3453
|
+
label,
|
|
3454
|
+
onClick
|
|
3455
|
+
} = button;
|
|
3456
|
+
const dom = [{
|
|
3457
|
+
ariaLabel: label,
|
|
3458
|
+
childCount: 1,
|
|
3459
|
+
className: mergeClassNames(TitleBarButton, `TitleBarButton${id}`),
|
|
3460
|
+
name: id,
|
|
3461
|
+
onClick,
|
|
3462
|
+
type: Button$1
|
|
3463
|
+
}, getIconVirtualDom(icon, I)];
|
|
3464
|
+
return dom;
|
|
3465
|
+
};
|
|
3466
|
+
|
|
3467
|
+
const getTitleBarButtonsVirtualDom = (buttonsEnabled, buttons) => {
|
|
3468
|
+
if (!buttonsEnabled) {
|
|
3469
|
+
return [];
|
|
3470
|
+
}
|
|
3471
|
+
return [{
|
|
3472
|
+
childCount: buttons.length,
|
|
3473
|
+
className: mergeClassNames(Viewlet, TitleBarButtons),
|
|
3474
|
+
type: Div
|
|
3475
|
+
}, ...buttons.flatMap(createTitleBarButton)];
|
|
3476
|
+
};
|
|
3477
|
+
|
|
3478
|
+
const parentNode$1 = {
|
|
3479
|
+
childCount: 1,
|
|
3480
|
+
className: mergeClassNames(Viewlet, TitleBarIcon),
|
|
3481
|
+
type: Div
|
|
3482
|
+
};
|
|
3483
|
+
const getTitleBarIconVirtualDom = (titleBarIconEnabled, iconSrc) => {
|
|
3484
|
+
if (!titleBarIconEnabled) {
|
|
3485
|
+
return [];
|
|
3486
|
+
}
|
|
3487
|
+
return [parentNode$1, {
|
|
3488
|
+
alt: '',
|
|
3489
|
+
childCount: 0,
|
|
3490
|
+
className: TitleBarIconIcon,
|
|
3491
|
+
src: iconSrc,
|
|
3492
|
+
type: Img
|
|
3493
|
+
}];
|
|
3494
|
+
};
|
|
3495
|
+
|
|
3496
|
+
const activeEntryLabelNode = {
|
|
3497
|
+
childCount: 1,
|
|
3498
|
+
className: TitleBarTopLevelEntryLabel,
|
|
3499
|
+
type: Div
|
|
3500
|
+
};
|
|
3501
|
+
const getActiveEntryLabelDom = isFocused => {
|
|
3502
|
+
if (!isFocused) {
|
|
3503
|
+
return [];
|
|
3504
|
+
}
|
|
3505
|
+
return [activeEntryLabelNode];
|
|
3506
|
+
};
|
|
3507
|
+
const getItemVirtualDom = item => {
|
|
3508
|
+
const {
|
|
3509
|
+
ariaLabel,
|
|
3510
|
+
isFocused,
|
|
3511
|
+
isOpen,
|
|
3512
|
+
keyboardShortCut,
|
|
3513
|
+
label
|
|
3514
|
+
} = item;
|
|
3515
|
+
const className = isFocused ? mergeClassNames(TitleBarTopLevelEntry, TitleBarEntryActive) : TitleBarTopLevelEntry;
|
|
3516
|
+
return [{
|
|
3517
|
+
ariaExpanded: isOpen,
|
|
3518
|
+
ariaHasPopup: true,
|
|
3519
|
+
ariaKeyShortcuts: keyboardShortCut,
|
|
3520
|
+
ariaLabel: ariaLabel || label,
|
|
3521
|
+
ariaOwns: isOpen ? 'Menu-0' : undefined,
|
|
3522
|
+
childCount: 1,
|
|
3523
|
+
className,
|
|
3524
|
+
id: isFocused ? 'TitleBarEntryActive' : undefined,
|
|
3525
|
+
name: label,
|
|
3526
|
+
// TODO have separate name attribute
|
|
3527
|
+
role: MenuItem$1,
|
|
3528
|
+
type: Button$1
|
|
3529
|
+
}, ...getActiveEntryLabelDom(isFocused), text(label)];
|
|
3530
|
+
};
|
|
3531
|
+
const getTitleBarMenuBarItemsVirtualDom = visibleItems => {
|
|
3532
|
+
const dom = visibleItems.flatMap(getItemVirtualDom);
|
|
3533
|
+
return dom;
|
|
3534
|
+
};
|
|
3535
|
+
|
|
3536
|
+
const activeId = 'TitleBarEntryActive';
|
|
3537
|
+
const getTitleBarMenuBarVirtualDom = (menuBarEnabled, visibleItems, focusedIndex) => {
|
|
3538
|
+
if (!menuBarEnabled) {
|
|
3539
|
+
return [];
|
|
3540
|
+
}
|
|
3541
|
+
return [{
|
|
3542
|
+
ariaActivedescendant: focusedIndex === -1 ? '' : activeId,
|
|
3543
|
+
childCount: visibleItems.length,
|
|
3544
|
+
className: mergeClassNames(Viewlet, TitleBarMenuBar),
|
|
3545
|
+
onContextMenu: HandleContextMenu,
|
|
3546
|
+
onFocusIn: HandleFocusIn,
|
|
3547
|
+
onFocusOut: HandleFocusOut,
|
|
3548
|
+
onMouseDown: HandleClick,
|
|
3549
|
+
onPointerOut: HandlePointerOut,
|
|
3550
|
+
onPointerOver: HandlePointerOver,
|
|
3551
|
+
role: MenuBar$1,
|
|
3552
|
+
tabIndex: 0,
|
|
3553
|
+
type: Div
|
|
3554
|
+
}, ...getTitleBarMenuBarItemsVirtualDom(visibleItems)];
|
|
3555
|
+
};
|
|
3556
|
+
|
|
3557
|
+
const parentNode = {
|
|
3558
|
+
childCount: 1,
|
|
3559
|
+
className: 'TitleBarTitle',
|
|
3560
|
+
type: Div
|
|
3561
|
+
};
|
|
3562
|
+
const getTitleVirtualDom = (titleBarTitleEnabled, title) => {
|
|
3563
|
+
if (!titleBarTitleEnabled) {
|
|
3564
|
+
return [];
|
|
3565
|
+
}
|
|
3566
|
+
return [parentNode, text(title)];
|
|
3567
|
+
};
|
|
3568
|
+
|
|
3569
|
+
const Ellipsis = 'Ellipsis';
|
|
3570
|
+
|
|
3571
|
+
const MoreEntryWidth = 38;
|
|
3572
|
+
const OverflowMenuId = 'title-bar-overflow';
|
|
3573
|
+
const getTotalWidth$1 = entries => {
|
|
3574
|
+
let total = 0;
|
|
3575
|
+
for (const entry of entries) {
|
|
3576
|
+
total += entry.width;
|
|
3577
|
+
}
|
|
3578
|
+
return total;
|
|
3579
|
+
};
|
|
3580
|
+
const createOverflowEntry = (hiddenEntries, overflowIndex, focusedIndex, isMenuOpen) => {
|
|
3581
|
+
return {
|
|
3582
|
+
ariaLabel: moreDot(),
|
|
3583
|
+
hiddenEntries,
|
|
3584
|
+
icon: Ellipsis,
|
|
3585
|
+
id: OverflowMenuId,
|
|
3586
|
+
isFocused: overflowIndex === focusedIndex,
|
|
3587
|
+
isOpen: overflowIndex === focusedIndex && isMenuOpen,
|
|
3588
|
+
label: '...',
|
|
3589
|
+
width: MoreEntryWidth
|
|
3590
|
+
};
|
|
3591
|
+
};
|
|
3592
|
+
const isOverflowTitleBarEntry = entry => {
|
|
3593
|
+
return entry.id === OverflowMenuId;
|
|
3594
|
+
};
|
|
3595
|
+
const getVisibleTitleBarEntries = (entries, width, focusedIndex, isMenuOpen) => {
|
|
3596
|
+
array(entries);
|
|
3597
|
+
number(width);
|
|
3598
|
+
let total = 0;
|
|
3599
|
+
const visible = [];
|
|
3600
|
+
for (let i = 0; i < entries.length; i++) {
|
|
3601
|
+
const entry = entries[i];
|
|
3602
|
+
const nextTotal = total + entry.width;
|
|
3603
|
+
if (nextTotal >= width) {
|
|
3604
|
+
break;
|
|
3605
|
+
}
|
|
3606
|
+
total = nextTotal;
|
|
3607
|
+
const visibleIndex = visible.length;
|
|
3608
|
+
const isOpen = visibleIndex === focusedIndex && isMenuOpen;
|
|
3609
|
+
const isFocused = visibleIndex === focusedIndex;
|
|
3610
|
+
visible.push({
|
|
3611
|
+
...entry,
|
|
3612
|
+
isFocused,
|
|
3613
|
+
isOpen
|
|
3614
|
+
});
|
|
3615
|
+
}
|
|
3616
|
+
const hasOverflow = visible.length < entries.length;
|
|
3617
|
+
if (hasOverflow) {
|
|
3618
|
+
while (visible.length > 0 && getTotalWidth$1(visible) + MoreEntryWidth > width) {
|
|
3619
|
+
visible.pop();
|
|
3620
|
+
}
|
|
3621
|
+
const hiddenEntries = entries.slice(visible.length);
|
|
3622
|
+
const overflowIndex = visible.length;
|
|
3623
|
+
visible.push(createOverflowEntry(hiddenEntries, overflowIndex, focusedIndex, isMenuOpen));
|
|
3624
|
+
}
|
|
3625
|
+
return visible;
|
|
3626
|
+
};
|
|
3627
|
+
|
|
3628
|
+
const emptyTitleBarNode = {
|
|
3629
|
+
childCount: 0,
|
|
3630
|
+
type: Div
|
|
3631
|
+
};
|
|
3632
|
+
const getTitleBarVirtualDom = state => {
|
|
3633
|
+
const {
|
|
3634
|
+
assetDir,
|
|
3635
|
+
commandCenterEnabled,
|
|
3636
|
+
focusedIndex,
|
|
3637
|
+
isMenuOpen,
|
|
3638
|
+
platform,
|
|
3639
|
+
title,
|
|
3640
|
+
titleBarButtons,
|
|
3641
|
+
titleBarButtonsEnabled,
|
|
3642
|
+
titleBarEntries,
|
|
3643
|
+
titleBarIconEnabled,
|
|
3644
|
+
titleBarMenuBarEnabled,
|
|
3645
|
+
titleBarStyleCustom,
|
|
3646
|
+
titleBarTitleEnabled,
|
|
3647
|
+
width
|
|
3648
|
+
} = state;
|
|
3649
|
+
if (platform === Electron$1 && !titleBarStyleCustom) {
|
|
3650
|
+
return [emptyTitleBarNode];
|
|
3651
|
+
}
|
|
3652
|
+
const iconSrc = getIcon(assetDir);
|
|
3653
|
+
const visibleEntries = getVisibleTitleBarEntries(titleBarEntries, width, focusedIndex, isMenuOpen);
|
|
3654
|
+
const titleEnabled = titleBarTitleEnabled && !commandCenterEnabled;
|
|
3655
|
+
const childCount = Number(titleBarIconEnabled) + Number(titleBarMenuBarEnabled) + Number(commandCenterEnabled) + Number(titleEnabled) + Number(titleBarButtonsEnabled);
|
|
3656
|
+
return [{
|
|
3657
|
+
ariaLabel: titleBar(),
|
|
3658
|
+
childCount,
|
|
3659
|
+
className: mergeClassNames(Viewlet, TitleBar),
|
|
3660
|
+
id: 'TitleBar',
|
|
3661
|
+
onContextMenu: HandleTitleBarContextMenu,
|
|
3662
|
+
role: ContentInfo,
|
|
3663
|
+
type: Div
|
|
3664
|
+
}, ...getTitleBarIconVirtualDom(titleBarIconEnabled, iconSrc), ...getTitleBarMenuBarVirtualDom(titleBarMenuBarEnabled, visibleEntries, focusedIndex), ...getCommandCenterVirtualDom(commandCenterEnabled), ...getTitleVirtualDom(titleEnabled, title), ...getTitleBarButtonsVirtualDom(titleBarButtonsEnabled, titleBarButtons)];
|
|
3665
|
+
};
|
|
3666
|
+
|
|
3667
|
+
const renderTitleBar = (oldState, newState) => {
|
|
3668
|
+
const dom = getTitleBarVirtualDom(newState);
|
|
3669
|
+
return [SetDom2, newState.uid, dom];
|
|
3670
|
+
};
|
|
3671
|
+
|
|
3672
|
+
const getComponentDom = uid => {
|
|
3673
|
+
const state = getComponentState(uid);
|
|
3674
|
+
return renderTitleBar(state, state)[2];
|
|
3675
|
+
};
|
|
3676
|
+
|
|
3389
3677
|
const getKeyBindings = () => {
|
|
3390
3678
|
return [{
|
|
3391
3679
|
command: 'TitleBar.handleKeyArrowDown',
|
|
@@ -3568,90 +3856,31 @@ const handleMessagePort = async (port, viewletCommandMap, setAsRendererProcess =
|
|
|
3568
3856
|
} = Promise.withResolvers();
|
|
3569
3857
|
commandQueues.set(uid, next);
|
|
3570
3858
|
if (previous) {
|
|
3571
|
-
await previous;
|
|
3572
|
-
}
|
|
3573
|
-
try {
|
|
3574
|
-
await fn(uid, ...args);
|
|
3575
|
-
await invoke$1('Viewlet.requestRender', uid);
|
|
3576
|
-
} finally {
|
|
3577
|
-
resolve();
|
|
3578
|
-
if (commandQueues.get(uid) === next) {
|
|
3579
|
-
commandQueues.delete(uid);
|
|
3580
|
-
}
|
|
3581
|
-
}
|
|
3582
|
-
};
|
|
3583
|
-
const rpc = await create$5({
|
|
3584
|
-
commandMap: {
|
|
3585
|
-
'Viewlet.executeViewletCommand': executeViewletCommand
|
|
3586
|
-
},
|
|
3587
|
-
messagePort: port
|
|
3588
|
-
});
|
|
3589
|
-
if (setAsRendererProcess) {
|
|
3590
|
-
set(rpc);
|
|
3591
|
-
}
|
|
3592
|
-
};
|
|
3593
|
-
|
|
3594
|
-
const getMenuOffset = (x, clientX, iconWidth) => {
|
|
3595
|
-
return clientX - x - iconWidth;
|
|
3596
|
-
};
|
|
3597
|
-
|
|
3598
|
-
const Ellipsis = 'Ellipsis';
|
|
3599
|
-
|
|
3600
|
-
const MoreEntryWidth = 38;
|
|
3601
|
-
const OverflowMenuId = 'title-bar-overflow';
|
|
3602
|
-
const getTotalWidth$1 = entries => {
|
|
3603
|
-
let total = 0;
|
|
3604
|
-
for (const entry of entries) {
|
|
3605
|
-
total += entry.width;
|
|
3606
|
-
}
|
|
3607
|
-
return total;
|
|
3608
|
-
};
|
|
3609
|
-
const createOverflowEntry = (hiddenEntries, overflowIndex, focusedIndex, isMenuOpen) => {
|
|
3610
|
-
return {
|
|
3611
|
-
ariaLabel: moreDot(),
|
|
3612
|
-
hiddenEntries,
|
|
3613
|
-
icon: Ellipsis,
|
|
3614
|
-
id: OverflowMenuId,
|
|
3615
|
-
isFocused: overflowIndex === focusedIndex,
|
|
3616
|
-
isOpen: overflowIndex === focusedIndex && isMenuOpen,
|
|
3617
|
-
label: '...',
|
|
3618
|
-
width: MoreEntryWidth
|
|
3619
|
-
};
|
|
3620
|
-
};
|
|
3621
|
-
const isOverflowTitleBarEntry = entry => {
|
|
3622
|
-
return entry.id === OverflowMenuId;
|
|
3623
|
-
};
|
|
3624
|
-
const getVisibleTitleBarEntries = (entries, width, focusedIndex, isMenuOpen) => {
|
|
3625
|
-
array(entries);
|
|
3626
|
-
number(width);
|
|
3627
|
-
let total = 0;
|
|
3628
|
-
const visible = [];
|
|
3629
|
-
for (let i = 0; i < entries.length; i++) {
|
|
3630
|
-
const entry = entries[i];
|
|
3631
|
-
const nextTotal = total + entry.width;
|
|
3632
|
-
if (nextTotal >= width) {
|
|
3633
|
-
break;
|
|
3634
|
-
}
|
|
3635
|
-
total = nextTotal;
|
|
3636
|
-
const visibleIndex = visible.length;
|
|
3637
|
-
const isOpen = visibleIndex === focusedIndex && isMenuOpen;
|
|
3638
|
-
const isFocused = visibleIndex === focusedIndex;
|
|
3639
|
-
visible.push({
|
|
3640
|
-
...entry,
|
|
3641
|
-
isFocused,
|
|
3642
|
-
isOpen
|
|
3643
|
-
});
|
|
3644
|
-
}
|
|
3645
|
-
const hasOverflow = visible.length < entries.length;
|
|
3646
|
-
if (hasOverflow) {
|
|
3647
|
-
while (visible.length > 0 && getTotalWidth$1(visible) + MoreEntryWidth > width) {
|
|
3648
|
-
visible.pop();
|
|
3859
|
+
await previous;
|
|
3649
3860
|
}
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3861
|
+
try {
|
|
3862
|
+
await fn(uid, ...args);
|
|
3863
|
+
await invoke$1('Viewlet.requestRender', uid);
|
|
3864
|
+
} finally {
|
|
3865
|
+
resolve();
|
|
3866
|
+
if (commandQueues.get(uid) === next) {
|
|
3867
|
+
commandQueues.delete(uid);
|
|
3868
|
+
}
|
|
3869
|
+
}
|
|
3870
|
+
};
|
|
3871
|
+
const rpc = await create$5({
|
|
3872
|
+
commandMap: {
|
|
3873
|
+
'Viewlet.executeViewletCommand': executeViewletCommand
|
|
3874
|
+
},
|
|
3875
|
+
messagePort: port
|
|
3876
|
+
});
|
|
3877
|
+
if (setAsRendererProcess) {
|
|
3878
|
+
set(rpc);
|
|
3653
3879
|
}
|
|
3654
|
-
|
|
3880
|
+
};
|
|
3881
|
+
|
|
3882
|
+
const getMenuOffset = (x, clientX, iconWidth) => {
|
|
3883
|
+
return clientX - x - iconWidth;
|
|
3655
3884
|
};
|
|
3656
3885
|
|
|
3657
3886
|
const getNavigableTitleBarEntries = state => {
|
|
@@ -4184,31 +4413,6 @@ const renderFocusedIndex = (oldState, newState) => {
|
|
|
4184
4413
|
return [FocusSelector, newState.uid, '.ViewletTitleBarMenuBar'];
|
|
4185
4414
|
};
|
|
4186
4415
|
|
|
4187
|
-
const MaskIconCheck = 'MaskIconCheck';
|
|
4188
|
-
const MaskIcon = 'MaskIcon';
|
|
4189
|
-
const Menu = 'Menu';
|
|
4190
|
-
const MenuItem = 'MenuItem';
|
|
4191
|
-
const MenuItemCheckMark = 'MenuItemCheckMark';
|
|
4192
|
-
const MenuItemCheckmarkIcon = 'MenuItemCheckmarkIcon';
|
|
4193
|
-
const MenuItemDisabled = 'MenuItemDisabled';
|
|
4194
|
-
const MenuItemFocused = 'MenuItemFocused';
|
|
4195
|
-
const MenuItemKeyBinding = 'MenuItemKeyBinding';
|
|
4196
|
-
const MenuItemSeparator = 'MenuItemSeparator';
|
|
4197
|
-
const MenuItemSeparatorLine = 'MenuItemSeparatorLine';
|
|
4198
|
-
const MenuItemSubMenu = 'MenuItemSubMenu';
|
|
4199
|
-
const MenuItemSubMenuArrowRight = 'MenuItemSubMenuArrowRight';
|
|
4200
|
-
const TitleBar = 'TitleBar';
|
|
4201
|
-
const TitleBarButton = 'TitleBarButton';
|
|
4202
|
-
const TitleBarButtons = 'TitleBarButtons';
|
|
4203
|
-
const TitleBarCommandCenter = 'TitleBarCommandCenter';
|
|
4204
|
-
const TitleBarEntryActive = 'TitleBarEntryActive';
|
|
4205
|
-
const TitleBarIcon = 'TitleBarIcon';
|
|
4206
|
-
const TitleBarIconIcon = 'TitleBarIconIcon';
|
|
4207
|
-
const TitleBarMenuBar = 'TitleBarMenuBar';
|
|
4208
|
-
const TitleBarTopLevelEntry = 'TitleBarTopLevelEntry';
|
|
4209
|
-
const TitleBarTopLevelEntryLabel = 'TitleBarTopLevelEntryLabel';
|
|
4210
|
-
const Viewlet = 'Viewlet';
|
|
4211
|
-
|
|
4212
4416
|
const getKeyBindingString = (key, altKey, ctrlKey, shiftKey, metaKey) => {
|
|
4213
4417
|
let string = '';
|
|
4214
4418
|
if (ctrlKey) {
|
|
@@ -4490,201 +4694,6 @@ const renderMenus = (oldState, newState) => {
|
|
|
4490
4694
|
return ['Viewlet.send', uid, /* method */SetMenus, /* changes */changes, uid];
|
|
4491
4695
|
};
|
|
4492
4696
|
|
|
4493
|
-
const Focusable = 0;
|
|
4494
|
-
|
|
4495
|
-
const getCommandCenterVirtualDom = commandCenterEnabled => {
|
|
4496
|
-
if (!commandCenterEnabled) {
|
|
4497
|
-
return [];
|
|
4498
|
-
}
|
|
4499
|
-
return [{
|
|
4500
|
-
ariaLabel: commandCenter(),
|
|
4501
|
-
childCount: 1,
|
|
4502
|
-
className: TitleBarCommandCenter,
|
|
4503
|
-
onClick: HandleCommandCenterClick,
|
|
4504
|
-
onKeyDown: HandleCommandCenterKeyDown,
|
|
4505
|
-
role: Button$2,
|
|
4506
|
-
tabIndex: Focusable,
|
|
4507
|
-
type: Div
|
|
4508
|
-
}, text(search())];
|
|
4509
|
-
};
|
|
4510
|
-
|
|
4511
|
-
const getIcon = assetDir => {
|
|
4512
|
-
return `${assetDir}/icons/icon.svg`;
|
|
4513
|
-
};
|
|
4514
|
-
|
|
4515
|
-
const getIconVirtualDom = (icon, type = Div) => {
|
|
4516
|
-
return {
|
|
4517
|
-
childCount: 0,
|
|
4518
|
-
className: mergeClassNames(MaskIcon, `MaskIcon${icon}`),
|
|
4519
|
-
role: None$1,
|
|
4520
|
-
type
|
|
4521
|
-
};
|
|
4522
|
-
};
|
|
4523
|
-
|
|
4524
|
-
const createTitleBarButton = button => {
|
|
4525
|
-
const {
|
|
4526
|
-
icon,
|
|
4527
|
-
id,
|
|
4528
|
-
label,
|
|
4529
|
-
onClick
|
|
4530
|
-
} = button;
|
|
4531
|
-
const dom = [{
|
|
4532
|
-
ariaLabel: label,
|
|
4533
|
-
childCount: 1,
|
|
4534
|
-
className: mergeClassNames(TitleBarButton, `TitleBarButton${id}`),
|
|
4535
|
-
name: id,
|
|
4536
|
-
onClick,
|
|
4537
|
-
type: Button$1
|
|
4538
|
-
}, getIconVirtualDom(icon, I)];
|
|
4539
|
-
return dom;
|
|
4540
|
-
};
|
|
4541
|
-
|
|
4542
|
-
const getTitleBarButtonsVirtualDom = (buttonsEnabled, buttons) => {
|
|
4543
|
-
if (!buttonsEnabled) {
|
|
4544
|
-
return [];
|
|
4545
|
-
}
|
|
4546
|
-
return [{
|
|
4547
|
-
childCount: buttons.length,
|
|
4548
|
-
className: mergeClassNames(Viewlet, TitleBarButtons),
|
|
4549
|
-
type: Div
|
|
4550
|
-
}, ...buttons.flatMap(createTitleBarButton)];
|
|
4551
|
-
};
|
|
4552
|
-
|
|
4553
|
-
const parentNode$1 = {
|
|
4554
|
-
childCount: 1,
|
|
4555
|
-
className: mergeClassNames(Viewlet, TitleBarIcon),
|
|
4556
|
-
type: Div
|
|
4557
|
-
};
|
|
4558
|
-
const getTitleBarIconVirtualDom = (titleBarIconEnabled, iconSrc) => {
|
|
4559
|
-
if (!titleBarIconEnabled) {
|
|
4560
|
-
return [];
|
|
4561
|
-
}
|
|
4562
|
-
return [parentNode$1, {
|
|
4563
|
-
alt: '',
|
|
4564
|
-
childCount: 0,
|
|
4565
|
-
className: TitleBarIconIcon,
|
|
4566
|
-
src: iconSrc,
|
|
4567
|
-
type: Img
|
|
4568
|
-
}];
|
|
4569
|
-
};
|
|
4570
|
-
|
|
4571
|
-
const activeEntryLabelNode = {
|
|
4572
|
-
childCount: 1,
|
|
4573
|
-
className: TitleBarTopLevelEntryLabel,
|
|
4574
|
-
type: Div
|
|
4575
|
-
};
|
|
4576
|
-
const getActiveEntryLabelDom = isFocused => {
|
|
4577
|
-
if (!isFocused) {
|
|
4578
|
-
return [];
|
|
4579
|
-
}
|
|
4580
|
-
return [activeEntryLabelNode];
|
|
4581
|
-
};
|
|
4582
|
-
const getItemVirtualDom = item => {
|
|
4583
|
-
const {
|
|
4584
|
-
ariaLabel,
|
|
4585
|
-
isFocused,
|
|
4586
|
-
isOpen,
|
|
4587
|
-
keyboardShortCut,
|
|
4588
|
-
label
|
|
4589
|
-
} = item;
|
|
4590
|
-
const className = isFocused ? mergeClassNames(TitleBarTopLevelEntry, TitleBarEntryActive) : TitleBarTopLevelEntry;
|
|
4591
|
-
return [{
|
|
4592
|
-
ariaExpanded: isOpen,
|
|
4593
|
-
ariaHasPopup: true,
|
|
4594
|
-
ariaKeyShortcuts: keyboardShortCut,
|
|
4595
|
-
ariaLabel: ariaLabel || label,
|
|
4596
|
-
ariaOwns: isOpen ? 'Menu-0' : undefined,
|
|
4597
|
-
childCount: 1,
|
|
4598
|
-
className,
|
|
4599
|
-
id: isFocused ? 'TitleBarEntryActive' : undefined,
|
|
4600
|
-
name: label,
|
|
4601
|
-
// TODO have separate name attribute
|
|
4602
|
-
role: MenuItem$1,
|
|
4603
|
-
type: Button$1
|
|
4604
|
-
}, ...getActiveEntryLabelDom(isFocused), text(label)];
|
|
4605
|
-
};
|
|
4606
|
-
const getTitleBarMenuBarItemsVirtualDom = visibleItems => {
|
|
4607
|
-
const dom = visibleItems.flatMap(getItemVirtualDom);
|
|
4608
|
-
return dom;
|
|
4609
|
-
};
|
|
4610
|
-
|
|
4611
|
-
const activeId = 'TitleBarEntryActive';
|
|
4612
|
-
const getTitleBarMenuBarVirtualDom = (menuBarEnabled, visibleItems, focusedIndex) => {
|
|
4613
|
-
if (!menuBarEnabled) {
|
|
4614
|
-
return [];
|
|
4615
|
-
}
|
|
4616
|
-
return [{
|
|
4617
|
-
ariaActivedescendant: focusedIndex === -1 ? '' : activeId,
|
|
4618
|
-
childCount: visibleItems.length,
|
|
4619
|
-
className: mergeClassNames(Viewlet, TitleBarMenuBar),
|
|
4620
|
-
onContextMenu: HandleContextMenu,
|
|
4621
|
-
onFocusIn: HandleFocusIn,
|
|
4622
|
-
onFocusOut: HandleFocusOut,
|
|
4623
|
-
onMouseDown: HandleClick,
|
|
4624
|
-
onPointerOut: HandlePointerOut,
|
|
4625
|
-
onPointerOver: HandlePointerOver,
|
|
4626
|
-
role: MenuBar$1,
|
|
4627
|
-
tabIndex: 0,
|
|
4628
|
-
type: Div
|
|
4629
|
-
}, ...getTitleBarMenuBarItemsVirtualDom(visibleItems)];
|
|
4630
|
-
};
|
|
4631
|
-
|
|
4632
|
-
const parentNode = {
|
|
4633
|
-
childCount: 1,
|
|
4634
|
-
className: 'TitleBarTitle',
|
|
4635
|
-
type: Div
|
|
4636
|
-
};
|
|
4637
|
-
const getTitleVirtualDom = (titleBarTitleEnabled, title) => {
|
|
4638
|
-
if (!titleBarTitleEnabled) {
|
|
4639
|
-
return [];
|
|
4640
|
-
}
|
|
4641
|
-
return [parentNode, text(title)];
|
|
4642
|
-
};
|
|
4643
|
-
|
|
4644
|
-
const emptyTitleBarNode = {
|
|
4645
|
-
childCount: 0,
|
|
4646
|
-
type: Div
|
|
4647
|
-
};
|
|
4648
|
-
const getTitleBarVirtualDom = state => {
|
|
4649
|
-
const {
|
|
4650
|
-
assetDir,
|
|
4651
|
-
commandCenterEnabled,
|
|
4652
|
-
focusedIndex,
|
|
4653
|
-
isMenuOpen,
|
|
4654
|
-
platform,
|
|
4655
|
-
title,
|
|
4656
|
-
titleBarButtons,
|
|
4657
|
-
titleBarButtonsEnabled,
|
|
4658
|
-
titleBarEntries,
|
|
4659
|
-
titleBarIconEnabled,
|
|
4660
|
-
titleBarMenuBarEnabled,
|
|
4661
|
-
titleBarStyleCustom,
|
|
4662
|
-
titleBarTitleEnabled,
|
|
4663
|
-
width
|
|
4664
|
-
} = state;
|
|
4665
|
-
if (platform === Electron$1 && !titleBarStyleCustom) {
|
|
4666
|
-
return [emptyTitleBarNode];
|
|
4667
|
-
}
|
|
4668
|
-
const iconSrc = getIcon(assetDir);
|
|
4669
|
-
const visibleEntries = getVisibleTitleBarEntries(titleBarEntries, width, focusedIndex, isMenuOpen);
|
|
4670
|
-
const titleEnabled = titleBarTitleEnabled && !commandCenterEnabled;
|
|
4671
|
-
const childCount = Number(titleBarIconEnabled) + Number(titleBarMenuBarEnabled) + Number(commandCenterEnabled) + Number(titleEnabled) + Number(titleBarButtonsEnabled);
|
|
4672
|
-
return [{
|
|
4673
|
-
ariaLabel: titleBar(),
|
|
4674
|
-
childCount,
|
|
4675
|
-
className: mergeClassNames(Viewlet, TitleBar),
|
|
4676
|
-
id: 'TitleBar',
|
|
4677
|
-
onContextMenu: HandleTitleBarContextMenu,
|
|
4678
|
-
role: ContentInfo,
|
|
4679
|
-
type: Div
|
|
4680
|
-
}, ...getTitleBarIconVirtualDom(titleBarIconEnabled, iconSrc), ...getTitleBarMenuBarVirtualDom(titleBarMenuBarEnabled, visibleEntries, focusedIndex), ...getCommandCenterVirtualDom(commandCenterEnabled), ...getTitleVirtualDom(titleEnabled, title), ...getTitleBarButtonsVirtualDom(titleBarButtonsEnabled, titleBarButtons)];
|
|
4681
|
-
};
|
|
4682
|
-
|
|
4683
|
-
const renderTitleBar = (oldState, newState) => {
|
|
4684
|
-
const dom = getTitleBarVirtualDom(newState);
|
|
4685
|
-
return [SetDom2, newState.uid, dom];
|
|
4686
|
-
};
|
|
4687
|
-
|
|
4688
4697
|
const getRenderer3 = diffType => {
|
|
4689
4698
|
switch (diffType) {
|
|
4690
4699
|
case RenderEntries:
|
|
@@ -4802,6 +4811,23 @@ const saveState = state => {
|
|
|
4802
4811
|
};
|
|
4803
4812
|
};
|
|
4804
4813
|
|
|
4814
|
+
const applyComponentState = (currentState, state) => {
|
|
4815
|
+
if (!state || typeof state !== 'object' || Array.isArray(state)) {
|
|
4816
|
+
throw new TypeError('Title Bar state must be an object');
|
|
4817
|
+
}
|
|
4818
|
+
const {
|
|
4819
|
+
uid
|
|
4820
|
+
} = state;
|
|
4821
|
+
const {
|
|
4822
|
+
uid: currentUid
|
|
4823
|
+
} = currentState;
|
|
4824
|
+
if (uid !== currentUid) {
|
|
4825
|
+
throw new Error(`Title Bar state uid must remain ${currentUid}`);
|
|
4826
|
+
}
|
|
4827
|
+
return state;
|
|
4828
|
+
};
|
|
4829
|
+
const setComponentState = wrapCommand(applyComponentState);
|
|
4830
|
+
|
|
4805
4831
|
const setPlatform = (state, platform) => {
|
|
4806
4832
|
return {
|
|
4807
4833
|
...state,
|
|
@@ -5522,6 +5548,8 @@ const commandMap = {
|
|
|
5522
5548
|
'TitleBar.focusPrevious': wrapCommand(focusPrevious),
|
|
5523
5549
|
'TitleBar.getCommandIds': getCommandIds,
|
|
5524
5550
|
'TitleBar.getCommands': getCommandIds,
|
|
5551
|
+
'TitleBar.getComponentDom': getComponentDom,
|
|
5552
|
+
'TitleBar.getComponentState': getComponentState,
|
|
5525
5553
|
'TitleBar.getKeyBindings': getKeyBindings,
|
|
5526
5554
|
'TitleBar.getMenuEntries2': wrapGetter(getMenuEntries2),
|
|
5527
5555
|
'TitleBar.getMenuIds': getMenuIds,
|
|
@@ -5563,6 +5591,7 @@ const commandMap = {
|
|
|
5563
5591
|
'TitleBar.renderEventListeners': renderEventListeners,
|
|
5564
5592
|
'TitleBar.resize': wrapCommand(resize),
|
|
5565
5593
|
'TitleBar.saveState': wrapGetter(saveState),
|
|
5594
|
+
'TitleBar.setComponentState': setComponentState,
|
|
5566
5595
|
'TitleBar.setPlatform': wrapCommand(setPlatform),
|
|
5567
5596
|
'TitleBar.setTitleTemplate': wrapCommand(setTitleTemplate),
|
|
5568
5597
|
'TitleBar.setWidth': wrapCommand(setWidth),
|