MCPcopy Create free account
hub / github.com/OneNoteDev/WebClipper / clipButtonEnabled

Function clipButtonEnabled

src/scripts/clipperUI/clipperStateUtilities.ts:13–49  ·  view source on GitHub ↗
(clipperState: ClipperState)

Source from the content-addressed store, hash-verified

11 }
12
13 export function clipButtonEnabled(clipperState: ClipperState): boolean {
14 let currentMode = clipperState.currentMode.get();
15 switch (currentMode) {
16 case ClipMode.Pdf:
17 if (!clipperState.pdfPreviewInfo.isLocalFileAndNotAllowed) {
18 return false;
19 } else if (clipperState.pdfResult.status !== Status.Succeeded) {
20 return false;
21 } else if (clipperState.pdfPreviewInfo.allPages) {
22 return true;
23 } else if (!clipperState.pdfPreviewInfo.allPages && ObjectUtils.isNullOrUndefined(clipperState.pdfPreviewInfo.selectedPageRange)) {
24 return false;
25 }
26
27 // If the user has an invalidPageRange, the clipButton is still enabled,
28 // but when the user clips, we short circuit it and display a message instead
29 return true;
30 case ClipMode.FullPage:
31 // In the past, we used to allow clips while this is pending, however, we found some pages can't be clipped in full page mode
32 let fullPageScreenshotResult = clipperState.fullPageResult;
33 return fullPageScreenshotResult.status === Status.Succeeded;
34 case ClipMode.Region:
35 let regionResult = clipperState.regionResult;
36 return regionResult.status === Status.Succeeded && regionResult.data && regionResult.data.length > 0;
37 case ClipMode.Augmentation:
38 let augmentationResult = clipperState.augmentationResult;
39 return augmentationResult.status === Status.Succeeded && augmentationResult.data && !!augmentationResult.data.ContentInHtml;
40 case ClipMode.Bookmark:
41 let bookmarkResult = clipperState.bookmarkResult;
42 return bookmarkResult.status === Status.Succeeded;
43 case ClipMode.Selection:
44 // The availability of this mode is passed together with the selected text, so it's always available
45 return true;
46 default:
47 return undefined;
48 }
49 }
50}

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected