@lvce-editor/title-bar-worker 2.18.0 → 2.20.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.
@@ -2291,7 +2291,7 @@ const getRecentlyOpened = () => {
2291
2291
 
2292
2292
  const File = 'file://';
2293
2293
 
2294
- const getTitle = (homeDir, uri) => {
2294
+ const getTitle$1 = (homeDir, uri) => {
2295
2295
  if (!uri) {
2296
2296
  return '';
2297
2297
  }
@@ -2315,7 +2315,7 @@ const getHomeDir = () => {
2315
2315
  const MAX_MENU_RECENT_ENTRIES = 10;
2316
2316
  const toMenuItem = folder => {
2317
2317
  const homeDir = getHomeDir();
2318
- const label = getTitle(homeDir, folder);
2318
+ const label = getTitle$1(homeDir, folder);
2319
2319
  return {
2320
2320
  label,
2321
2321
  flags: None,
@@ -2526,153 +2526,6 @@ const getMenuEntries$1 = async (id, platform) => {
2526
2526
  return menu.getMenuEntries(platform);
2527
2527
  };
2528
2528
 
2529
- const MaskIconCheck = 'MaskIconCheck';
2530
- const Menu = 'Menu';
2531
- const MenuItem = 'MenuItem';
2532
- const MenuItemCheckMark = 'MenuItemCheckMark';
2533
- const MenuItemCheckmarkIcon = 'MenuItemCheckmarkIcon';
2534
- const MenuItemFocused = 'MenuItemFocused';
2535
- const MenuItemKeyBinding = 'MenuItemKeyBinding';
2536
- const MenuItemSeparator = 'MenuItemSeparator';
2537
- const MenuItemSeparatorLine = 'MenuItemSeparatorLine';
2538
- const MenuItemSubMenu = 'MenuItemSubMenu';
2539
- const MenuItemSubMenuArrowRight = 'MenuItemSubMenuArrowRight';
2540
- const TitleBarButtons = 'TitleBarButtons';
2541
- const TitleBarEntryActive = 'TitleBarEntryActive';
2542
- const TitleBarIcon = 'TitleBarIcon';
2543
- const TitleBarIconIcon = 'TitleBarIconIcon';
2544
- const TitleBarMenuBar = 'TitleBarMenuBar';
2545
- const TitleBarTopLevelEntry = 'TitleBarTopLevelEntry';
2546
- const TitleBarTopLevelEntryLabel = 'TitleBarTopLevelEntryLabel';
2547
- const Viewlet = 'Viewlet';
2548
-
2549
- const getIconVirtualDom = (icon, type = Div) => {
2550
- return {
2551
- type,
2552
- className: `MaskIcon MaskIcon${icon}`,
2553
- role: None$1,
2554
- childCount: 0
2555
- };
2556
- };
2557
-
2558
- const createTitleBarButton = button => {
2559
- const {
2560
- id,
2561
- icon,
2562
- label,
2563
- onClick
2564
- } = button;
2565
- const dom = [{
2566
- type: Button$1,
2567
- className: `TitleBarButton TitleBarButton${id}`,
2568
- ariaLabel: label,
2569
- childCount: 1,
2570
- onClick
2571
- }, getIconVirtualDom(icon, I)];
2572
- return dom;
2573
- };
2574
-
2575
- const getTitleBarButtonsVirtualDom = buttons => {
2576
- return [{
2577
- type: Div,
2578
- className: mergeClassNames(Viewlet, TitleBarButtons),
2579
- childCount: buttons.length
2580
- }, ...buttons.flatMap(createTitleBarButton)];
2581
- };
2582
-
2583
- const parentNode$1 = {
2584
- type: Div,
2585
- className: mergeClassNames(Viewlet, TitleBarIcon),
2586
- childCount: 1
2587
- };
2588
- const getTitleBarIconVirtualDom = iconSrc => {
2589
- return [parentNode$1, {
2590
- type: Img,
2591
- className: TitleBarIconIcon,
2592
- src: iconSrc,
2593
- alt: '',
2594
- childCount: 0
2595
- }];
2596
- };
2597
-
2598
- const HandleClick = 1;
2599
- const HandleClickMinimize = 2;
2600
- const HandleClickToggleClose = 3;
2601
- const HandleClickToggleMaximize = 4;
2602
- const HandleFocusIn = 5;
2603
- const HandleFocusOut = 6;
2604
- const HandlePointerOut = 7;
2605
- const HandlePointerOver = 8;
2606
- const HandleMenuClick = 9;
2607
- const HandleMenuMouseOver = 10;
2608
-
2609
- const getItemVirtualDom = item => {
2610
- // @ts-ignore
2611
- const {
2612
- keyboardShortCut,
2613
- label,
2614
- isOpen,
2615
- isFocused
2616
- } = item;
2617
- // TODO avoid mutation
2618
- const dom = [];
2619
- dom.push({
2620
- type: Div,
2621
- className: TitleBarTopLevelEntry,
2622
- ariaHasPopup: true,
2623
- ariaExpanded: isOpen,
2624
- role: MenuItem$1,
2625
- childCount: 1,
2626
- ariaKeyShortcuts: keyboardShortCut
2627
- });
2628
- if (isOpen) {
2629
- // @ts-ignore
2630
- dom[0].ariaOwns = 'Menu-0';
2631
- }
2632
- if (isFocused) {
2633
- dom[0].className += ' ' + TitleBarEntryActive;
2634
- // @ts-ignore
2635
- dom[0].id = 'TitleBarEntryActive';
2636
- dom.push({
2637
- type: Div,
2638
- className: TitleBarTopLevelEntryLabel,
2639
- childCount: 1
2640
- });
2641
- }
2642
- dom.push(text(label));
2643
- return dom;
2644
- };
2645
- const getTitleBarMenuBarItemsVirtualDom = visibleItems => {
2646
- const dom = visibleItems.flatMap(getItemVirtualDom);
2647
- return dom;
2648
- };
2649
-
2650
- const activeId = 'TitleBarEntryActive';
2651
- const getTitleBarMenuBarVirtualDom = (visibleItems, focusedIndex) => {
2652
- return [{
2653
- type: Div,
2654
- className: mergeClassNames(Viewlet, TitleBarMenuBar),
2655
- role: MenuBar,
2656
- tabIndex: 0,
2657
- childCount: visibleItems.length,
2658
- onMouseDown: HandleClick,
2659
- onFocusOut: HandleFocusOut,
2660
- onFocusIn: HandleFocusIn,
2661
- onPointerOver: HandlePointerOver,
2662
- onPointerOut: HandlePointerOut,
2663
- ariaActivedescendant: focusedIndex === -1 ? '' : activeId
2664
- }, ...getTitleBarMenuBarItemsVirtualDom(visibleItems)];
2665
- };
2666
-
2667
- const parentNode = {
2668
- type: Div,
2669
- className: 'TitleBarTitle',
2670
- childCount: 1
2671
- };
2672
- const getTitleVirtualDom = title => {
2673
- return [parentNode, text(title)];
2674
- };
2675
-
2676
2529
  const maximize = async () => {
2677
2530
  await invoke('ElectronWindow.maximize');
2678
2531
  };
@@ -3028,6 +2881,15 @@ const addWidths = (entries, labelPadding, fontWeight, fontSize, fontFamily, lett
3028
2881
  return withWidths;
3029
2882
  };
3030
2883
 
2884
+ const getTitle = workspaceUri => {
2885
+ if (!workspaceUri) {
2886
+ return '';
2887
+ }
2888
+ const slashIndex = workspaceUri.lastIndexOf('/');
2889
+ const baseName = workspaceUri.slice(slashIndex);
2890
+ return baseName;
2891
+ };
2892
+
3031
2893
  const loadContent2 = async state => {
3032
2894
  const {
3033
2895
  platform,
@@ -3042,85 +2904,20 @@ const loadContent2 = async state => {
3042
2904
  const titleBarEntries = await getMenuEntries(TitleBar$1);
3043
2905
  const withWidths = addWidths(titleBarEntries, labelPadding, labelFontWeight, labelFontSize, labelFontFamily, labelLetterSpacing);
3044
2906
  const buttons = getTitleBarButtons(platform, controlsOverlayEnabled, titleBarStyleCustom);
3045
- const title = 'test';
2907
+ // @ts-ignore
2908
+ const workspaceUri = await invoke('Workspace.getUri');
2909
+ const title = getTitle(workspaceUri);
3046
2910
  const iconWidth = 30;
3047
2911
  return {
3048
2912
  ...state,
3049
2913
  titleBarEntries: withWidths,
2914
+ titleBarButtons: buttons,
3050
2915
  buttons,
3051
2916
  title,
3052
2917
  iconWidth
3053
2918
  };
3054
2919
  };
3055
2920
 
3056
- const loadContent = async (state, titleBarEntries) => {
3057
- const {
3058
- platform,
3059
- controlsOverlayEnabled,
3060
- titleBarStyleCustom,
3061
- labelFontFamily,
3062
- labelFontSize,
3063
- labelFontWeight,
3064
- labelLetterSpacing,
3065
- labelPadding
3066
- } = state;
3067
- const withWidths = addWidths(titleBarEntries, labelPadding, labelFontWeight, labelFontSize, labelFontFamily, labelLetterSpacing);
3068
- const buttons = getTitleBarButtons(platform, controlsOverlayEnabled, titleBarStyleCustom);
3069
- const title = 'test';
3070
- return {
3071
- ...state,
3072
- titleBarEntries: withWidths,
3073
- buttons,
3074
- title
3075
- };
3076
- };
3077
-
3078
- const Ellipsis = 'Ellipsis';
3079
-
3080
- const getVisibleTitleBarEntries = (entries, width, focusedIndex, isMenuOpen) => {
3081
- array(entries);
3082
- number(width);
3083
- let total = 0;
3084
- const visible = [];
3085
- for (let i = 0; i < entries.length; i++) {
3086
- const entry = entries[i];
3087
- total += entry.width;
3088
- if (total >= width) {
3089
- break;
3090
- }
3091
- const isOpen = i === focusedIndex && isMenuOpen;
3092
- const isFocused = i === focusedIndex;
3093
- visible.push({
3094
- ...entry,
3095
- isOpen,
3096
- isFocused
3097
- });
3098
- }
3099
- const hasOverflow = visible.length < entries.length;
3100
- if (hasOverflow) {
3101
- const padding = 8;
3102
- const moreIconWidth = 22;
3103
- const totalPadding = padding * 2;
3104
- const hasStillOverflow = total + moreIconWidth + totalPadding > width;
3105
- if (hasStillOverflow) {
3106
- visible.pop();
3107
- }
3108
- visible.push({
3109
- ariaLabel: moreDot(),
3110
- icon: Ellipsis,
3111
- label: '',
3112
- width: moreIconWidth + totalPadding
3113
- });
3114
- }
3115
- return visible;
3116
- };
3117
-
3118
- const renderEntries = (oldState, newState) => {
3119
- const visibleEntries = getVisibleTitleBarEntries(newState.titleBarEntries, newState.width, newState.focusedIndex, newState.isMenuOpen);
3120
- const dom = getTitleBarMenuBarVirtualDom(visibleEntries, newState.focusedIndex);
3121
- return ['Viewlet.setDom2', newState.uid, dom];
3122
- };
3123
-
3124
2921
  const renderFocusedIndex = (oldState, newState) => {
3125
2922
  if (newState.focusedIndex === -1) {
3126
2923
  return [];
@@ -3128,6 +2925,26 @@ const renderFocusedIndex = (oldState, newState) => {
3128
2925
  return ['Viewlet.focusSelector', '.ViewletTitleBarMenuBar'];
3129
2926
  };
3130
2927
 
2928
+ const MaskIconCheck = 'MaskIconCheck';
2929
+ const Menu = 'Menu';
2930
+ const MenuItem = 'MenuItem';
2931
+ const MenuItemCheckMark = 'MenuItemCheckMark';
2932
+ const MenuItemCheckmarkIcon = 'MenuItemCheckmarkIcon';
2933
+ const MenuItemFocused = 'MenuItemFocused';
2934
+ const MenuItemKeyBinding = 'MenuItemKeyBinding';
2935
+ const MenuItemSeparator = 'MenuItemSeparator';
2936
+ const MenuItemSeparatorLine = 'MenuItemSeparatorLine';
2937
+ const MenuItemSubMenu = 'MenuItemSubMenu';
2938
+ const MenuItemSubMenuArrowRight = 'MenuItemSubMenuArrowRight';
2939
+ const TitleBarButtons = 'TitleBarButtons';
2940
+ const TitleBarEntryActive = 'TitleBarEntryActive';
2941
+ const TitleBarIcon = 'TitleBarIcon';
2942
+ const TitleBarIconIcon = 'TitleBarIconIcon';
2943
+ const TitleBarMenuBar = 'TitleBarMenuBar';
2944
+ const TitleBarTopLevelEntry = 'TitleBarTopLevelEntry';
2945
+ const TitleBarTopLevelEntryLabel = 'TitleBarTopLevelEntryLabel';
2946
+ const Viewlet = 'Viewlet';
2947
+
3131
2948
  const checkboxChecked = {
3132
2949
  type: Div,
3133
2950
  className: mergeClassNames(MenuItem, MenuItemCheckMark),
@@ -3359,43 +3176,175 @@ const renderMenus = (oldState, newState) => {
3359
3176
  return ['Viewlet.send', newState.uid, /* method */SetMenus, /* changes */changes, newState.uid];
3360
3177
  };
3361
3178
 
3362
- const getRenderer = diffType => {
3363
- switch (diffType) {
3364
- case RenderEntries:
3365
- return renderEntries;
3366
- case RenderFocusedIndex:
3367
- return renderFocusedIndex;
3368
- case RenderMenus:
3369
- return renderMenus;
3370
- default:
3371
- throw new Error('unknown renderer');
3372
- }
3179
+ const getIcon = assetDir => {
3180
+ return `${assetDir}/icons/icon.svg`;
3373
3181
  };
3374
3182
 
3375
- const applyRender = (oldState, newState, diffResult) => {
3376
- const commands = [];
3377
- for (const item of diffResult) {
3378
- const fn = getRenderer(item);
3379
- const result = fn(oldState, newState);
3380
- if (result.length > 0) {
3381
- commands.push(result);
3382
- }
3383
- }
3384
- return commands;
3183
+ const getIconVirtualDom = (icon, type = Div) => {
3184
+ return {
3185
+ type,
3186
+ className: `MaskIcon MaskIcon${icon}`,
3187
+ role: None$1,
3188
+ childCount: 0
3189
+ };
3385
3190
  };
3386
3191
 
3387
- const render2 = async (uid, diffResult) => {
3192
+ const createTitleBarButton = button => {
3388
3193
  const {
3389
- oldState,
3390
- newState
3391
- } = get$1(uid);
3392
- set$3(uid, newState, newState);
3393
- const commands = applyRender(oldState, newState, diffResult);
3394
- return commands;
3194
+ id,
3195
+ icon,
3196
+ label,
3197
+ onClick
3198
+ } = button;
3199
+ const dom = [{
3200
+ type: Button$1,
3201
+ className: `TitleBarButton TitleBarButton${id}`,
3202
+ ariaLabel: label,
3203
+ childCount: 1,
3204
+ onClick
3205
+ }, getIconVirtualDom(icon, I)];
3206
+ return dom;
3395
3207
  };
3396
3208
 
3397
- const getIcon = assetDir => {
3398
- return `${assetDir}/icons/icon.svg`;
3209
+ const getTitleBarButtonsVirtualDom = buttons => {
3210
+ return [{
3211
+ type: Div,
3212
+ className: mergeClassNames(Viewlet, TitleBarButtons),
3213
+ childCount: buttons.length
3214
+ }, ...buttons.flatMap(createTitleBarButton)];
3215
+ };
3216
+
3217
+ const parentNode$1 = {
3218
+ type: Div,
3219
+ className: mergeClassNames(Viewlet, TitleBarIcon),
3220
+ childCount: 1
3221
+ };
3222
+ const getTitleBarIconVirtualDom = iconSrc => {
3223
+ return [parentNode$1, {
3224
+ type: Img,
3225
+ className: TitleBarIconIcon,
3226
+ src: iconSrc,
3227
+ alt: '',
3228
+ childCount: 0
3229
+ }];
3230
+ };
3231
+
3232
+ const HandleClick = 1;
3233
+ const HandleClickMinimize = 2;
3234
+ const HandleClickToggleClose = 3;
3235
+ const HandleClickToggleMaximize = 4;
3236
+ const HandleFocusIn = 5;
3237
+ const HandleFocusOut = 6;
3238
+ const HandlePointerOut = 7;
3239
+ const HandlePointerOver = 8;
3240
+ const HandleMenuClick = 9;
3241
+ const HandleMenuMouseOver = 10;
3242
+
3243
+ const getItemVirtualDom = item => {
3244
+ // @ts-ignore
3245
+ const {
3246
+ keyboardShortCut,
3247
+ label,
3248
+ isOpen,
3249
+ isFocused
3250
+ } = item;
3251
+ // TODO avoid mutation
3252
+ const dom = [];
3253
+ dom.push({
3254
+ type: Div,
3255
+ className: TitleBarTopLevelEntry,
3256
+ ariaHasPopup: true,
3257
+ ariaExpanded: isOpen,
3258
+ role: MenuItem$1,
3259
+ childCount: 1,
3260
+ ariaKeyShortcuts: keyboardShortCut
3261
+ });
3262
+ if (isOpen) {
3263
+ // @ts-ignore
3264
+ dom[0].ariaOwns = 'Menu-0';
3265
+ }
3266
+ if (isFocused) {
3267
+ dom[0].className += ' ' + TitleBarEntryActive;
3268
+ // @ts-ignore
3269
+ dom[0].id = 'TitleBarEntryActive';
3270
+ dom.push({
3271
+ type: Div,
3272
+ className: TitleBarTopLevelEntryLabel,
3273
+ childCount: 1
3274
+ });
3275
+ }
3276
+ dom.push(text(label));
3277
+ return dom;
3278
+ };
3279
+ const getTitleBarMenuBarItemsVirtualDom = visibleItems => {
3280
+ const dom = visibleItems.flatMap(getItemVirtualDom);
3281
+ return dom;
3282
+ };
3283
+
3284
+ const activeId = 'TitleBarEntryActive';
3285
+ const getTitleBarMenuBarVirtualDom = (visibleItems, focusedIndex) => {
3286
+ return [{
3287
+ type: Div,
3288
+ className: mergeClassNames(Viewlet, TitleBarMenuBar),
3289
+ role: MenuBar,
3290
+ tabIndex: 0,
3291
+ childCount: visibleItems.length,
3292
+ onMouseDown: HandleClick,
3293
+ onFocusOut: HandleFocusOut,
3294
+ onFocusIn: HandleFocusIn,
3295
+ onPointerOver: HandlePointerOver,
3296
+ onPointerOut: HandlePointerOut,
3297
+ ariaActivedescendant: focusedIndex === -1 ? '' : activeId
3298
+ }, ...getTitleBarMenuBarItemsVirtualDom(visibleItems)];
3299
+ };
3300
+
3301
+ const parentNode = {
3302
+ type: Div,
3303
+ className: 'TitleBarTitle',
3304
+ childCount: 1
3305
+ };
3306
+ const getTitleVirtualDom = title => {
3307
+ return [parentNode, text(title)];
3308
+ };
3309
+
3310
+ const Ellipsis = 'Ellipsis';
3311
+
3312
+ const getVisibleTitleBarEntries = (entries, width, focusedIndex, isMenuOpen) => {
3313
+ array(entries);
3314
+ number(width);
3315
+ let total = 0;
3316
+ const visible = [];
3317
+ for (let i = 0; i < entries.length; i++) {
3318
+ const entry = entries[i];
3319
+ total += entry.width;
3320
+ if (total >= width) {
3321
+ break;
3322
+ }
3323
+ const isOpen = i === focusedIndex && isMenuOpen;
3324
+ const isFocused = i === focusedIndex;
3325
+ visible.push({
3326
+ ...entry,
3327
+ isOpen,
3328
+ isFocused
3329
+ });
3330
+ }
3331
+ const hasOverflow = visible.length < entries.length;
3332
+ if (hasOverflow) {
3333
+ const padding = 8;
3334
+ const moreIconWidth = 22;
3335
+ const totalPadding = padding * 2;
3336
+ const hasStillOverflow = total + moreIconWidth + totalPadding > width;
3337
+ if (hasStillOverflow) {
3338
+ visible.pop();
3339
+ }
3340
+ visible.push({
3341
+ ariaLabel: moreDot(),
3342
+ icon: Ellipsis,
3343
+ label: '',
3344
+ width: moreIconWidth + totalPadding
3345
+ });
3346
+ }
3347
+ return visible;
3399
3348
  };
3400
3349
 
3401
3350
  const getTitleBarVirtualDom = state => {
@@ -4066,17 +4015,12 @@ const commandMap = {
4066
4015
  'TitleBar.focusLast': wrapCommand(focusIndex),
4067
4016
  'TitleBar.focusNext': wrapCommand(focusNext),
4068
4017
  'TitleBar.focusPrevious': wrapCommand(focusPrevious),
4069
- 'TitleBar.getButtonsVirtualDom': getTitleBarButtonsVirtualDom,
4070
4018
  'TitleBar.getCommandIds': getCommandIds,
4071
4019
  'TitleBar.getCommands': getCommandIds,
4072
- 'TitleBar.getIconVirtualDom': getTitleBarIconVirtualDom,
4073
4020
  'TitleBar.getKeyBindings': getKeyBindings$1,
4074
4021
  'TitleBar.getMenuEntries': getMenuEntries$1,
4075
4022
  'TitleBar.getMenuIds': getMenuIds,
4076
4023
  'TitleBar.getMenus': getMenus,
4077
- 'TitleBar.getTitleBarButtons': getTitleBarButtons,
4078
- 'TitleBar.getTitleVirtualDom': getTitleVirtualDom,
4079
- 'TitleBar.getVirtualDom': getTitleBarMenuBarVirtualDom,
4080
4024
  'TitleBar.handleButtonsClick': handleClick$1,
4081
4025
  'TitleBar.handleClick': wrapCommand(handleClick),
4082
4026
  'TitleBar.handleClickAt': wrapCommand(handleClickAt),
@@ -4101,9 +4045,7 @@ const commandMap = {
4101
4045
  'TitleBar.handleMouseOver': wrapCommand(handleMouseOver),
4102
4046
  'TitleBar.handlePointerOut': wrapCommand(handlePointerOut),
4103
4047
  'TitleBar.handlePointerOver': wrapCommand(handlePointerOver),
4104
- 'TitleBar.loadContent': wrapCommand(loadContent),
4105
4048
  'TitleBar.loadContent2': wrapCommand(loadContent2),
4106
- 'TitleBar.render2': render2,
4107
4049
  'TitleBar.render3': render3,
4108
4050
  'TitleBar.renderEventListeners': renderEventListeners,
4109
4051
  'TitleBar.resize': wrapCommand(resize),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/title-bar-worker",
3
- "version": "2.18.0",
3
+ "version": "2.20.0",
4
4
  "description": "Title Bar Worker",
5
5
  "repository": {
6
6
  "type": "git",