@lvce-editor/status-bar-worker 3.33.0 → 3.34.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.
@@ -412,6 +412,7 @@ const Polyline = 88;
412
412
  const Rect = 89;
413
413
  const Svg = 90;
414
414
  const Use = 91;
415
+ const Progress = 92;
415
416
  const Reference = 100;
416
417
 
417
418
  const VirtualDomElements = {
@@ -473,6 +474,7 @@ const VirtualDomElements = {
473
474
  Polygon,
474
475
  Polyline,
475
476
  Pre,
477
+ Progress,
476
478
  Quote,
477
479
  Rect,
478
480
  Reference,
@@ -813,6 +815,22 @@ const getIconVirtualDom = (element, name) => {
813
815
  type: Div
814
816
  }];
815
817
  };
818
+ const getProgressVirtualDom = (element, name) => {
819
+ const node = {
820
+ ariaLabel: element.ariaLabel,
821
+ className: 'StatusBarItemProgress',
822
+ max: element.max,
823
+ name,
824
+ type: Progress
825
+ };
826
+ if (element.value !== undefined) {
827
+ return [{
828
+ ...node,
829
+ value: element.value
830
+ }];
831
+ }
832
+ return [node];
833
+ };
816
834
  const getStatusBarItemElementVirtualDom = (element, name) => {
817
835
  if (element.type === 'text') {
818
836
  return getTextVirtualDom(element, name);
@@ -820,6 +838,9 @@ const getStatusBarItemElementVirtualDom = (element, name) => {
820
838
  if (element.type === 'icon') {
821
839
  return getIconVirtualDom(element, name);
822
840
  }
841
+ if (element.type === 'progress') {
842
+ return getProgressVirtualDom(element, name);
843
+ }
823
844
  return [];
824
845
  };
825
846
 
@@ -870,16 +891,21 @@ const getStatusBarItemsRightDom = statusBarItemsRight => {
870
891
  return getStatusBarItemsVirtualDom(statusBarItemsRight, StatusBarItemsRight);
871
892
  };
872
893
 
894
+ const Focusable = 0;
895
+
873
896
  const getChildCount = rightCount => {
874
897
  return rightCount > 0 ? 2 : 1;
875
898
  };
876
899
  const getStatusBarVirtualDom = (statusBarItemsLeft, statusBarItemsRight) => {
877
900
  const dom = [{
901
+ ariaLive: 'off',
902
+ ariaRoleDescription: 'Status Bar',
878
903
  childCount: getChildCount(statusBarItemsRight.length),
879
904
  className: 'StatusBar',
880
905
  onClick: HandleClick,
881
906
  onContextMenu: HandleContextMenu,
882
907
  role: Status,
908
+ tabIndex: Focusable,
883
909
  type: Div
884
910
  }, ...getStatusBarItemsLeftDom(statusBarItemsLeft), ...getStatusBarItemsRightDom(statusBarItemsRight)];
885
911
  return dom;
@@ -2510,6 +2536,7 @@ const fontSize = 12;
2510
2536
  const fontFamily = 'system-ui, Ubuntu, Droid Sans, sans-serif';
2511
2537
  const itemPaddingAndMargin = 16;
2512
2538
  const iconWidth = 20;
2539
+ const progressWidth = 69;
2513
2540
  const horizontalGroupPadding = 14;
2514
2541
  const measuredWidths = new WeakMap();
2515
2542
  const fallbackTextWidth = 150;
@@ -2523,6 +2550,16 @@ const measureTextWidths = async values => {
2523
2550
  return values.map(() => fallbackTextWidth);
2524
2551
  }
2525
2552
  };
2553
+ const getElementWidth = (element, textWidths, textIndex) => {
2554
+ switch (element.type) {
2555
+ case 'icon':
2556
+ return iconWidth;
2557
+ case 'progress':
2558
+ return progressWidth;
2559
+ case 'text':
2560
+ return textWidths[textIndex];
2561
+ }
2562
+ };
2526
2563
  const getItemWidths = async items => {
2527
2564
  const unmeasuredItems = [...new Set(items.filter(item => !measuredWidths.has(item)))];
2528
2565
  const textElements = unmeasuredItems.flatMap(item => item.elements.filter(element => element.type === 'text'));
@@ -2531,10 +2568,8 @@ const getItemWidths = async items => {
2531
2568
  for (const item of unmeasuredItems) {
2532
2569
  let itemWidth = itemPaddingAndMargin;
2533
2570
  for (const element of item.elements) {
2534
- if (element.type === 'icon') {
2535
- itemWidth += iconWidth;
2536
- } else {
2537
- itemWidth += textWidths[textIndex];
2571
+ itemWidth += getElementWidth(element, textWidths, textIndex);
2572
+ if (element.type === 'text') {
2538
2573
  textIndex++;
2539
2574
  }
2540
2575
  }
@@ -3077,6 +3112,50 @@ const handleProblemsSummaryChange = (state, summary) => {
3077
3112
  };
3078
3113
  };
3079
3114
 
3115
+ const itemName = 'update-progress';
3116
+ const handleUpdateProgress = (state, progress) => {
3117
+ const {
3118
+ statusBarItemsLeft
3119
+ } = state;
3120
+ const updatedStatusBarItems = statusBarItemsLeft.filter(item => item.name !== itemName);
3121
+ if (progress === null) {
3122
+ return {
3123
+ ...state,
3124
+ statusBarItemsLeft: updatedStatusBarItems
3125
+ };
3126
+ }
3127
+ const value = progress === undefined ? undefined : Math.max(0, Math.min(1, progress));
3128
+ const percentage = value === undefined ? undefined : Math.round(value * 100);
3129
+ const ariaLabel = percentage === undefined ? 'Update download progress' : `Update download progress ${percentage}%`;
3130
+ const progressElement = {
3131
+ ariaLabel: 'Update download progress',
3132
+ max: 1,
3133
+ type: 'progress'
3134
+ };
3135
+ const elements = [{
3136
+ type: 'text',
3137
+ value: 'Update'
3138
+ }];
3139
+ if (value === undefined) {
3140
+ elements.push(progressElement);
3141
+ } else {
3142
+ elements.push({
3143
+ ...progressElement,
3144
+ value
3145
+ });
3146
+ }
3147
+ const item = {
3148
+ ariaLabel,
3149
+ elements,
3150
+ name: itemName,
3151
+ tooltip: ariaLabel
3152
+ };
3153
+ return {
3154
+ ...state,
3155
+ statusBarItemsLeft: [...updatedStatusBarItems, item]
3156
+ };
3157
+ };
3158
+
3080
3159
  const handleWorkspaceChange = async state => {
3081
3160
  const {
3082
3161
  assetDir,
@@ -3290,6 +3369,7 @@ const commandMap = {
3290
3369
  'StatusBar.handleMessagePort': handleDirectMessagePort,
3291
3370
  'StatusBar.handleNotificationCountChanged': wrapCommand(handleNotificationCountChanged),
3292
3371
  'StatusBar.handleProblemsSummaryChange': wrapCommand(handleProblemsSummaryChange),
3372
+ 'StatusBar.handleUpdateProgress': wrapCommand(handleUpdateProgress),
3293
3373
  'StatusBar.handleWorkspaceChange': handleWorkspaceChangeAndRefresh,
3294
3374
  'StatusBar.initialize': initialize,
3295
3375
  'StatusBar.itemLeftUpdate': wrapCommand(itemLeftUpdate),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/status-bar-worker",
3
- "version": "3.33.0",
3
+ "version": "3.34.0",
4
4
  "description": "Status Bar Worker",
5
5
  "repository": {
6
6
  "type": "git",