@lvce-editor/status-bar-worker 3.33.1 → 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
 
@@ -2515,6 +2536,7 @@ const fontSize = 12;
2515
2536
  const fontFamily = 'system-ui, Ubuntu, Droid Sans, sans-serif';
2516
2537
  const itemPaddingAndMargin = 16;
2517
2538
  const iconWidth = 20;
2539
+ const progressWidth = 69;
2518
2540
  const horizontalGroupPadding = 14;
2519
2541
  const measuredWidths = new WeakMap();
2520
2542
  const fallbackTextWidth = 150;
@@ -2528,6 +2550,16 @@ const measureTextWidths = async values => {
2528
2550
  return values.map(() => fallbackTextWidth);
2529
2551
  }
2530
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
+ };
2531
2563
  const getItemWidths = async items => {
2532
2564
  const unmeasuredItems = [...new Set(items.filter(item => !measuredWidths.has(item)))];
2533
2565
  const textElements = unmeasuredItems.flatMap(item => item.elements.filter(element => element.type === 'text'));
@@ -2536,10 +2568,8 @@ const getItemWidths = async items => {
2536
2568
  for (const item of unmeasuredItems) {
2537
2569
  let itemWidth = itemPaddingAndMargin;
2538
2570
  for (const element of item.elements) {
2539
- if (element.type === 'icon') {
2540
- itemWidth += iconWidth;
2541
- } else {
2542
- itemWidth += textWidths[textIndex];
2571
+ itemWidth += getElementWidth(element, textWidths, textIndex);
2572
+ if (element.type === 'text') {
2543
2573
  textIndex++;
2544
2574
  }
2545
2575
  }
@@ -3082,6 +3112,50 @@ const handleProblemsSummaryChange = (state, summary) => {
3082
3112
  };
3083
3113
  };
3084
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
+
3085
3159
  const handleWorkspaceChange = async state => {
3086
3160
  const {
3087
3161
  assetDir,
@@ -3295,6 +3369,7 @@ const commandMap = {
3295
3369
  'StatusBar.handleMessagePort': handleDirectMessagePort,
3296
3370
  'StatusBar.handleNotificationCountChanged': wrapCommand(handleNotificationCountChanged),
3297
3371
  'StatusBar.handleProblemsSummaryChange': wrapCommand(handleProblemsSummaryChange),
3372
+ 'StatusBar.handleUpdateProgress': wrapCommand(handleUpdateProgress),
3298
3373
  'StatusBar.handleWorkspaceChange': handleWorkspaceChangeAndRefresh,
3299
3374
  'StatusBar.initialize': initialize,
3300
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.1",
3
+ "version": "3.34.0",
4
4
  "description": "Status Bar Worker",
5
5
  "repository": {
6
6
  "type": "git",