@douyinfe/semi-foundation 2.56.2 → 2.56.3

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.
@@ -107,6 +107,8 @@ export interface TreeSelectAdapter<P = Record<string, any>, S = Record<string, a
107
107
  updateInputFocus: (bool: boolean) => void;
108
108
  updateLoadKeys: (data: BasicTreeNodeData, resolve: (value?: any) => void) => void;
109
109
  updateIsFocus: (bool: boolean) => void;
110
+ setClearInputFlag: (flag: boolean) => void;
111
+ getClearInputFlag: () => boolean;
110
112
  }
111
113
  export default class TreeSelectFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<TreeSelectAdapter<P, S>, P, S> {
112
114
  constructor(adapter: TreeSelectAdapter<P, S>);
@@ -183,4 +185,6 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
183
185
  */
184
186
  handleInputTriggerFocus(): void;
185
187
  setLoadKeys(data: BasicTreeNodeData, resolve: (value?: any) => void): void;
188
+ handlePopoverVisibleChange(isVisible: boolean): void;
189
+ handleAfterClose(): void;
186
190
  }
@@ -443,7 +443,7 @@ class TreeSelectFoundation extends _foundation.default {
443
443
  } = this.getProps();
444
444
  const newExpandedKeys = new Set(expandedKeys);
445
445
  const isExpandControlled = this._isExpandControlled();
446
- const expandedOptsKeys = (0, _treeUtil.findAncestorKeys)(selectedKeys, keyEntities);
446
+ const expandedOptsKeys = (0, _treeUtil.findAncestorKeys)(selectedKeys, keyEntities, false);
447
447
  expandedOptsKeys.forEach(item => newExpandedKeys.add(item));
448
448
  const newFlattenNodes = (0, _treeUtil.flattenTreeData)(treeData, newExpandedKeys, keyMaps);
449
449
  this._adapter.updateState({
@@ -455,6 +455,7 @@ class TreeSelectFoundation extends _foundation.default {
455
455
  filteredExpandedKeys: new Set(expandedOptsKeys),
456
456
  filteredShownKeys: new Set([])
457
457
  });
458
+ this._adapter.rePositionDropdown();
458
459
  }
459
460
  handleInputChange(sugInput) {
460
461
  // Input is used as controlled component
@@ -479,7 +480,7 @@ class TreeSelectFoundation extends _foundation.default {
479
480
  let newFlattenNodes = [];
480
481
  let filteredShownKeys = new Set([]);
481
482
  if (!sugInput) {
482
- expandedOptsKeys = (0, _treeUtil.findAncestorKeys)(selectedKeys, keyEntities);
483
+ expandedOptsKeys = (0, _treeUtil.findAncestorKeys)(selectedKeys, keyEntities, false);
483
484
  expandedOptsKeys.forEach(item => newExpandedKeys.add(item));
484
485
  newFlattenNodes = (0, _treeUtil.flattenTreeData)(treeData, newExpandedKeys, keyMaps);
485
486
  } else {
@@ -504,6 +505,7 @@ class TreeSelectFoundation extends _foundation.default {
504
505
  filteredExpandedKeys: newFilteredExpandedKeys,
505
506
  filteredShownKeys
506
507
  });
508
+ this._adapter.rePositionDropdown();
507
509
  }
508
510
  handleNodeSelect(e, treeNode) {
509
511
  const isDisabled = this._isDisabled(treeNode);
@@ -772,7 +774,8 @@ class TreeSelectFoundation extends _foundation.default {
772
774
  * When the search box is on the trigger, the focus event processing method
773
775
  */
774
776
  handleInputTriggerFocus() {
775
- this.clearInput();
777
+ const inputValue = this.getState('inputValue');
778
+ inputValue && this.clearInput();
776
779
  this._adapter.updateState({
777
780
  inputTriggerFocus: true
778
781
  });
@@ -780,5 +783,35 @@ class TreeSelectFoundation extends _foundation.default {
780
783
  setLoadKeys(data, resolve) {
781
784
  this._adapter.updateLoadKeys(data, resolve);
782
785
  }
786
+ handlePopoverVisibleChange(isVisible) {
787
+ const {
788
+ filterTreeNode,
789
+ searchAutoFocus,
790
+ searchPosition
791
+ } = this.getProps();
792
+ const inputValue = this.getState('inputValue');
793
+ // 将 inputValue 清空,如果有选中值的话,选中项能够快速回显
794
+ // Clear the inputValue. If there is a selected value, the selected item can be quickly echoed.
795
+ if (isVisible === false && filterTreeNode) {
796
+ inputValue && this._adapter.setClearInputFlag(true);
797
+ this.clearInputValue();
798
+ }
799
+ if (filterTreeNode && searchPosition === _constants.strings.SEARCH_POSITION_DROPDOWN && isVisible && searchAutoFocus) {
800
+ this.focusInput(true);
801
+ }
802
+ }
803
+ handleAfterClose() {
804
+ // flattenNode 的变化将导致弹出层面板中的选项数目变化
805
+ // 在弹层完全收起之后,再通过 clearInput 重新计算 state 中的 expandedKey, flattenNode
806
+ // 防止在弹出层未收起时弹层面板中选项数目变化导致视觉上出现弹层闪动问题
807
+ // Changes to flattenNode will cause the number of options in the popup panel to change
808
+ // After the pop-up layer is completely closed, recalculate the expandedKey and flattenNode in the state through clearInput.
809
+ // Prevent the pop-up layer from flickering visually due to changes in the number of options in the pop-up panel when the pop-up layer is not collapsed.
810
+ const {
811
+ filterTreeNode
812
+ } = this.getProps();
813
+ const shouldClear = this._adapter.getClearInputFlag();
814
+ filterTreeNode && shouldClear && this.clearInput();
815
+ }
783
816
  }
784
817
  exports.default = TreeSelectFoundation;
@@ -66,7 +66,7 @@ class UploadFoundation extends _foundation.default {
66
66
  addOnPasting
67
67
  } = this.getProps();
68
68
  this.releaseMemory();
69
- if (addOnPasting && !disabled) {
69
+ if (!disabled) {
70
70
  this.unbindPastingHandler();
71
71
  }
72
72
  }
@@ -949,27 +949,31 @@ class UploadFoundation extends _foundation.default {
949
949
  handlePasting(e) {
950
950
  const isMac = this._adapter.isMac();
951
951
  const isCombineKeydown = isMac ? e.metaKey : e.ctrlKey;
952
- if (isCombineKeydown && e.code === 'KeyV' && e.target === document.body) {
953
- // https://github.com/microsoft/TypeScript/issues/33923
954
- const permissionName = "clipboard-read";
955
- // The main thread should not be blocked by clipboard, so callback writing is required here. No await here
956
- navigator.permissions.query({
957
- name: permissionName
958
- }).then(result => {
959
- console.log(result);
960
- if (result.state === 'granted' || result.state === 'prompt') {
961
- // user has authorized or will authorize
962
- navigator.clipboard.read().then(clipboardItems => {
963
- // Process the data read from the pasteboard
964
- // Check the returned data type to determine if it is image data, and process accordingly
965
- this.readFileFromClipboard(clipboardItems);
966
- });
967
- } else {
968
- this._adapter.notifyPastingError(result);
969
- }
970
- }).catch(error => {
971
- this._adapter.notifyPastingError(error);
972
- });
952
+ const {
953
+ addOnPasting
954
+ } = this.getProps();
955
+ if (addOnPasting) {
956
+ if (isCombineKeydown && e.code === 'KeyV' && e.target === document.body) {
957
+ // https://github.com/microsoft/TypeScript/issues/33923
958
+ const permissionName = 'clipboard-read';
959
+ // The main thread should not be blocked by clipboard, so callback writing is required here. No await here
960
+ navigator.permissions.query({
961
+ name: permissionName
962
+ }).then(result => {
963
+ if (result.state === 'granted' || result.state === 'prompt') {
964
+ // user has authorized or will authorize
965
+ navigator.clipboard.read().then(clipboardItems => {
966
+ // Process the data read from the pasteboard
967
+ // Check the returned data type to determine if it is image data, and process accordingly
968
+ this.readFileFromClipboard(clipboardItems);
969
+ });
970
+ } else {
971
+ this._adapter.notifyPastingError(result);
972
+ }
973
+ }).catch(error => {
974
+ this._adapter.notifyPastingError(error);
975
+ });
976
+ }
973
977
  }
974
978
  }
975
979
  bindPastingHandler() {
@@ -107,6 +107,8 @@ export interface TreeSelectAdapter<P = Record<string, any>, S = Record<string, a
107
107
  updateInputFocus: (bool: boolean) => void;
108
108
  updateLoadKeys: (data: BasicTreeNodeData, resolve: (value?: any) => void) => void;
109
109
  updateIsFocus: (bool: boolean) => void;
110
+ setClearInputFlag: (flag: boolean) => void;
111
+ getClearInputFlag: () => boolean;
110
112
  }
111
113
  export default class TreeSelectFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<TreeSelectAdapter<P, S>, P, S> {
112
114
  constructor(adapter: TreeSelectAdapter<P, S>);
@@ -183,4 +185,6 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
183
185
  */
184
186
  handleInputTriggerFocus(): void;
185
187
  setLoadKeys(data: BasicTreeNodeData, resolve: (value?: any) => void): void;
188
+ handlePopoverVisibleChange(isVisible: boolean): void;
189
+ handleAfterClose(): void;
186
190
  }
@@ -436,7 +436,7 @@ export default class TreeSelectFoundation extends BaseFoundation {
436
436
  } = this.getProps();
437
437
  const newExpandedKeys = new Set(expandedKeys);
438
438
  const isExpandControlled = this._isExpandControlled();
439
- const expandedOptsKeys = findAncestorKeys(selectedKeys, keyEntities);
439
+ const expandedOptsKeys = findAncestorKeys(selectedKeys, keyEntities, false);
440
440
  expandedOptsKeys.forEach(item => newExpandedKeys.add(item));
441
441
  const newFlattenNodes = flattenTreeData(treeData, newExpandedKeys, keyMaps);
442
442
  this._adapter.updateState({
@@ -448,6 +448,7 @@ export default class TreeSelectFoundation extends BaseFoundation {
448
448
  filteredExpandedKeys: new Set(expandedOptsKeys),
449
449
  filteredShownKeys: new Set([])
450
450
  });
451
+ this._adapter.rePositionDropdown();
451
452
  }
452
453
  handleInputChange(sugInput) {
453
454
  // Input is used as controlled component
@@ -472,7 +473,7 @@ export default class TreeSelectFoundation extends BaseFoundation {
472
473
  let newFlattenNodes = [];
473
474
  let filteredShownKeys = new Set([]);
474
475
  if (!sugInput) {
475
- expandedOptsKeys = findAncestorKeys(selectedKeys, keyEntities);
476
+ expandedOptsKeys = findAncestorKeys(selectedKeys, keyEntities, false);
476
477
  expandedOptsKeys.forEach(item => newExpandedKeys.add(item));
477
478
  newFlattenNodes = flattenTreeData(treeData, newExpandedKeys, keyMaps);
478
479
  } else {
@@ -497,6 +498,7 @@ export default class TreeSelectFoundation extends BaseFoundation {
497
498
  filteredExpandedKeys: newFilteredExpandedKeys,
498
499
  filteredShownKeys
499
500
  });
501
+ this._adapter.rePositionDropdown();
500
502
  }
501
503
  handleNodeSelect(e, treeNode) {
502
504
  const isDisabled = this._isDisabled(treeNode);
@@ -765,7 +767,8 @@ export default class TreeSelectFoundation extends BaseFoundation {
765
767
  * When the search box is on the trigger, the focus event processing method
766
768
  */
767
769
  handleInputTriggerFocus() {
768
- this.clearInput();
770
+ const inputValue = this.getState('inputValue');
771
+ inputValue && this.clearInput();
769
772
  this._adapter.updateState({
770
773
  inputTriggerFocus: true
771
774
  });
@@ -773,4 +776,34 @@ export default class TreeSelectFoundation extends BaseFoundation {
773
776
  setLoadKeys(data, resolve) {
774
777
  this._adapter.updateLoadKeys(data, resolve);
775
778
  }
779
+ handlePopoverVisibleChange(isVisible) {
780
+ const {
781
+ filterTreeNode,
782
+ searchAutoFocus,
783
+ searchPosition
784
+ } = this.getProps();
785
+ const inputValue = this.getState('inputValue');
786
+ // 将 inputValue 清空,如果有选中值的话,选中项能够快速回显
787
+ // Clear the inputValue. If there is a selected value, the selected item can be quickly echoed.
788
+ if (isVisible === false && filterTreeNode) {
789
+ inputValue && this._adapter.setClearInputFlag(true);
790
+ this.clearInputValue();
791
+ }
792
+ if (filterTreeNode && searchPosition === strings.SEARCH_POSITION_DROPDOWN && isVisible && searchAutoFocus) {
793
+ this.focusInput(true);
794
+ }
795
+ }
796
+ handleAfterClose() {
797
+ // flattenNode 的变化将导致弹出层面板中的选项数目变化
798
+ // 在弹层完全收起之后,再通过 clearInput 重新计算 state 中的 expandedKey, flattenNode
799
+ // 防止在弹出层未收起时弹层面板中选项数目变化导致视觉上出现弹层闪动问题
800
+ // Changes to flattenNode will cause the number of options in the popup panel to change
801
+ // After the pop-up layer is completely closed, recalculate the expandedKey and flattenNode in the state through clearInput.
802
+ // Prevent the pop-up layer from flickering visually due to changes in the number of options in the pop-up panel when the pop-up layer is not collapsed.
803
+ const {
804
+ filterTreeNode
805
+ } = this.getProps();
806
+ const shouldClear = this._adapter.getClearInputFlag();
807
+ filterTreeNode && shouldClear && this.clearInput();
808
+ }
776
809
  }
@@ -59,7 +59,7 @@ class UploadFoundation extends BaseFoundation {
59
59
  addOnPasting
60
60
  } = this.getProps();
61
61
  this.releaseMemory();
62
- if (addOnPasting && !disabled) {
62
+ if (!disabled) {
63
63
  this.unbindPastingHandler();
64
64
  }
65
65
  }
@@ -942,27 +942,31 @@ class UploadFoundation extends BaseFoundation {
942
942
  handlePasting(e) {
943
943
  const isMac = this._adapter.isMac();
944
944
  const isCombineKeydown = isMac ? e.metaKey : e.ctrlKey;
945
- if (isCombineKeydown && e.code === 'KeyV' && e.target === document.body) {
946
- // https://github.com/microsoft/TypeScript/issues/33923
947
- const permissionName = "clipboard-read";
948
- // The main thread should not be blocked by clipboard, so callback writing is required here. No await here
949
- navigator.permissions.query({
950
- name: permissionName
951
- }).then(result => {
952
- console.log(result);
953
- if (result.state === 'granted' || result.state === 'prompt') {
954
- // user has authorized or will authorize
955
- navigator.clipboard.read().then(clipboardItems => {
956
- // Process the data read from the pasteboard
957
- // Check the returned data type to determine if it is image data, and process accordingly
958
- this.readFileFromClipboard(clipboardItems);
959
- });
960
- } else {
961
- this._adapter.notifyPastingError(result);
962
- }
963
- }).catch(error => {
964
- this._adapter.notifyPastingError(error);
965
- });
945
+ const {
946
+ addOnPasting
947
+ } = this.getProps();
948
+ if (addOnPasting) {
949
+ if (isCombineKeydown && e.code === 'KeyV' && e.target === document.body) {
950
+ // https://github.com/microsoft/TypeScript/issues/33923
951
+ const permissionName = 'clipboard-read';
952
+ // The main thread should not be blocked by clipboard, so callback writing is required here. No await here
953
+ navigator.permissions.query({
954
+ name: permissionName
955
+ }).then(result => {
956
+ if (result.state === 'granted' || result.state === 'prompt') {
957
+ // user has authorized or will authorize
958
+ navigator.clipboard.read().then(clipboardItems => {
959
+ // Process the data read from the pasteboard
960
+ // Check the returned data type to determine if it is image data, and process accordingly
961
+ this.readFileFromClipboard(clipboardItems);
962
+ });
963
+ } else {
964
+ this._adapter.notifyPastingError(result);
965
+ }
966
+ }).catch(error => {
967
+ this._adapter.notifyPastingError(error);
968
+ });
969
+ }
966
970
  }
967
971
  }
968
972
  bindPastingHandler() {
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@douyinfe/semi-foundation",
3
- "version": "2.56.2",
3
+ "version": "2.56.3",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build:lib": "node ./scripts/compileLib.js",
7
7
  "prepublishOnly": "npm run build:lib"
8
8
  },
9
9
  "dependencies": {
10
- "@douyinfe/semi-animation": "2.56.2",
10
+ "@douyinfe/semi-animation": "2.56.3",
11
11
  "async-validator": "^3.5.0",
12
12
  "classnames": "^2.2.6",
13
13
  "date-fns": "^2.29.3",
@@ -24,7 +24,7 @@
24
24
  "*.scss",
25
25
  "*.css"
26
26
  ],
27
- "gitHead": "c2d893b432056eac3b7b9aa14828867fa74467fc",
27
+ "gitHead": "933e2bf0c8d66a690b83d0410656ba4cdf265537",
28
28
  "devDependencies": {
29
29
  "@babel/plugin-transform-runtime": "^7.15.8",
30
30
  "@babel/preset-env": "^7.15.8",
@@ -199,7 +199,9 @@ export interface TreeSelectAdapter<P = Record<string, any>, S = Record<string, a
199
199
  notifyLoad: (newLoadedKeys: Set<string>, data: BasicTreeNodeData) => void;
200
200
  updateInputFocus: (bool: boolean) => void;
201
201
  updateLoadKeys: (data: BasicTreeNodeData, resolve: (value?: any) => void) => void;
202
- updateIsFocus: (bool: boolean) => void
202
+ updateIsFocus: (bool: boolean) => void;
203
+ setClearInputFlag: (flag: boolean) => void;
204
+ getClearInputFlag: () => boolean
203
205
  }
204
206
 
205
207
  export default class TreeSelectFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<TreeSelectAdapter<P, S>, P, S> {
@@ -588,7 +590,7 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
588
590
  const { keyMaps } = this.getProps();
589
591
  const newExpandedKeys: Set<string> = new Set(expandedKeys);
590
592
  const isExpandControlled = this._isExpandControlled();
591
- const expandedOptsKeys = findAncestorKeys(selectedKeys, keyEntities);
593
+ const expandedOptsKeys = findAncestorKeys(selectedKeys, keyEntities, false);
592
594
  expandedOptsKeys.forEach(item => newExpandedKeys.add(item));
593
595
  const newFlattenNodes = flattenTreeData(treeData, newExpandedKeys, keyMaps);
594
596
 
@@ -601,6 +603,7 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
601
603
  filteredExpandedKeys: new Set(expandedOptsKeys),
602
604
  filteredShownKeys: new Set([])
603
605
  });
606
+ this._adapter.rePositionDropdown();
604
607
  }
605
608
 
606
609
  handleInputChange(sugInput: string) {
@@ -615,7 +618,7 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
615
618
  let newFlattenNodes = [];
616
619
  let filteredShownKeys = new Set([]);
617
620
  if (!sugInput) {
618
- expandedOptsKeys = findAncestorKeys(selectedKeys, keyEntities);
621
+ expandedOptsKeys = findAncestorKeys(selectedKeys, keyEntities, false);
619
622
  expandedOptsKeys.forEach(item => newExpandedKeys.add(item));
620
623
  newFlattenNodes = flattenTreeData(treeData, newExpandedKeys, keyMaps);
621
624
  } else {
@@ -640,6 +643,7 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
640
643
  filteredExpandedKeys: newFilteredExpandedKeys,
641
644
  filteredShownKeys,
642
645
  });
646
+ this._adapter.rePositionDropdown();
643
647
  }
644
648
 
645
649
  handleNodeSelect(e: any, treeNode: BasicTreeNodeProps) {
@@ -871,7 +875,8 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
871
875
  * When the search box is on the trigger, the focus event processing method
872
876
  */
873
877
  handleInputTriggerFocus() {
874
- this.clearInput();
878
+ const inputValue = this.getState('inputValue');
879
+ inputValue && this.clearInput();
875
880
  this._adapter.updateState({
876
881
  inputTriggerFocus: true
877
882
  });
@@ -880,4 +885,30 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
880
885
  setLoadKeys(data: BasicTreeNodeData, resolve: (value?: any) => void) {
881
886
  this._adapter.updateLoadKeys(data, resolve);
882
887
  }
888
+
889
+ handlePopoverVisibleChange(isVisible: boolean) {
890
+ const { filterTreeNode, searchAutoFocus, searchPosition } = this.getProps();
891
+ const inputValue = this.getState('inputValue');
892
+ // 将 inputValue 清空,如果有选中值的话,选中项能够快速回显
893
+ // Clear the inputValue. If there is a selected value, the selected item can be quickly echoed.
894
+ if (isVisible === false && filterTreeNode) {
895
+ inputValue && this._adapter.setClearInputFlag(true);
896
+ this.clearInputValue();
897
+ }
898
+ if (filterTreeNode && searchPosition === strings.SEARCH_POSITION_DROPDOWN && isVisible && searchAutoFocus) {
899
+ this.focusInput(true);
900
+ }
901
+ }
902
+
903
+ handleAfterClose() {
904
+ // flattenNode 的变化将导致弹出层面板中的选项数目变化
905
+ // 在弹层完全收起之后,再通过 clearInput 重新计算 state 中的 expandedKey, flattenNode
906
+ // 防止在弹出层未收起时弹层面板中选项数目变化导致视觉上出现弹层闪动问题
907
+ // Changes to flattenNode will cause the number of options in the popup panel to change
908
+ // After the pop-up layer is completely closed, recalculate the expandedKey and flattenNode in the state through clearInput.
909
+ // Prevent the pop-up layer from flickering visually due to changes in the number of options in the pop-up panel when the pop-up layer is not collapsed.
910
+ const { filterTreeNode } = this.getProps();
911
+ const shouldClear = this._adapter.getClearInputFlag();
912
+ filterTreeNode && shouldClear && this.clearInput();
913
+ }
883
914
  }
@@ -107,7 +107,7 @@ class UploadFoundation<P = Record<string, any>, S = Record<string, any>> extends
107
107
  destroy() {
108
108
  const { disabled, addOnPasting } = this.getProps();
109
109
  this.releaseMemory();
110
- if (addOnPasting && !disabled) {
110
+ if (!disabled) {
111
111
  this.unbindPastingHandler();
112
112
  }
113
113
  }
@@ -884,31 +884,31 @@ class UploadFoundation<P = Record<string, any>, S = Record<string, any>> extends
884
884
  handlePasting(e: any) {
885
885
  const isMac = this._adapter.isMac();
886
886
  const isCombineKeydown = isMac ? e.metaKey : e.ctrlKey;
887
-
888
- if (isCombineKeydown && e.code === 'KeyV' && e.target === document.body) {
889
- // https://github.com/microsoft/TypeScript/issues/33923
890
- const permissionName = "clipboard-read" as PermissionName;
891
- // The main thread should not be blocked by clipboard, so callback writing is required here. No await here
892
- navigator.permissions
893
- .query({ name: permissionName })
894
- .then(result => {
895
- console.log(result);
896
- if (result.state === 'granted' || result.state === 'prompt') {
897
- // user has authorized or will authorize
898
- navigator.clipboard
899
- .read()
900
- .then(clipboardItems => {
887
+ const { addOnPasting } = this.getProps();
888
+
889
+ if (addOnPasting) {
890
+ if (isCombineKeydown && e.code === 'KeyV' && e.target === document.body) {
891
+ // https://github.com/microsoft/TypeScript/issues/33923
892
+ const permissionName = 'clipboard-read' as PermissionName;
893
+ // The main thread should not be blocked by clipboard, so callback writing is required here. No await here
894
+ navigator.permissions
895
+ .query({ name: permissionName })
896
+ .then(result => {
897
+ if (result.state === 'granted' || result.state === 'prompt') {
898
+ // user has authorized or will authorize
899
+ navigator.clipboard.read().then(clipboardItems => {
901
900
  // Process the data read from the pasteboard
902
901
  // Check the returned data type to determine if it is image data, and process accordingly
903
902
  this.readFileFromClipboard(clipboardItems);
904
903
  });
905
- } else {
906
- this._adapter.notifyPastingError(result);
907
- }
908
- })
909
- .catch(error => {
910
- this._adapter.notifyPastingError(error);
911
- });
904
+ } else {
905
+ this._adapter.notifyPastingError(result);
906
+ }
907
+ })
908
+ .catch(error => {
909
+ this._adapter.notifyPastingError(error);
910
+ });
911
+ }
912
912
  }
913
913
  }
914
914