@processfocus/plugin-google-drive 0.1.0-next.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.
- package/LICENSE.md +28 -0
- package/README.md +161 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/browser.d.ts +2 -0
- package/dist/lib/browser.js +4 -0
- package/dist/lib/browser.js.map +1 -0
- package/dist/lib/drive-picker-element-loader.d.ts +3 -0
- package/dist/lib/drive-picker-element-loader.js +4 -0
- package/dist/lib/drive-picker-element-loader.js.map +1 -0
- package/dist/lib/google-drive-annotations.d.ts +10 -0
- package/dist/lib/google-drive-annotations.js +11 -0
- package/dist/lib/google-drive-annotations.js.map +1 -0
- package/dist/lib/google-drive-browser-export.d.ts +37 -0
- package/dist/lib/google-drive-browser-export.js +134 -0
- package/dist/lib/google-drive-browser-export.js.map +1 -0
- package/dist/lib/google-drive-download.d.ts +15 -0
- package/dist/lib/google-drive-download.js +9 -0
- package/dist/lib/google-drive-download.js.map +1 -0
- package/dist/lib/google-drive-field.d.ts +71 -0
- package/dist/lib/google-drive-field.js +89 -0
- package/dist/lib/google-drive-field.js.map +1 -0
- package/dist/lib/google-drive-oauth.d.ts +10 -0
- package/dist/lib/google-drive-oauth.js +13 -0
- package/dist/lib/google-drive-oauth.js.map +1 -0
- package/dist/lib/google-drive-picker-config.d.ts +12 -0
- package/dist/lib/google-drive-picker-config.js +28 -0
- package/dist/lib/google-drive-picker-config.js.map +1 -0
- package/dist/lib/google-drive-picker.d.ts +92 -0
- package/dist/lib/google-drive-picker.js +324 -0
- package/dist/lib/google-drive-picker.js.map +1 -0
- package/dist/lib/google-drive-provider.d.ts +5 -0
- package/dist/lib/google-drive-provider.js +6 -0
- package/dist/lib/google-drive-provider.js.map +1 -0
- package/dist/lib/google-drive.d.ts +16 -0
- package/dist/lib/google-drive.js +35 -0
- package/dist/lib/google-drive.js.map +1 -0
- package/dist/lib/picker-token-cache.d.ts +15 -0
- package/dist/lib/picker-token-cache.js +25 -0
- package/dist/lib/picker-token-cache.js.map +1 -0
- package/dist/lib/plugin-data.d.ts +8 -0
- package/dist/lib/plugin-data.js +1 -0
- package/dist/lib/plugin-data.js.map +1 -0
- package/dist/lib/plugin-identity.d.ts +2 -0
- package/dist/lib/plugin-identity.js +3 -0
- package/dist/lib/plugin-identity.js.map +1 -0
- package/dist/lib/prepare-client.d.ts +3 -0
- package/dist/lib/prepare-client.js +4 -0
- package/dist/lib/prepare-client.js.map +1 -0
- package/dist/lib/register-client.d.ts +10 -0
- package/dist/lib/register-client.js +83 -0
- package/dist/lib/register-client.js.map +1 -0
- package/dist/lib/register-walker.d.ts +16 -0
- package/dist/lib/register-walker.js +59 -0
- package/dist/lib/register-walker.js.map +1 -0
- package/dist/lib/types.d.ts +42 -0
- package/dist/lib/types.js +4 -0
- package/dist/lib/types.js.map +1 -0
- package/package.json +70 -0
- package/styles.css +16 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { GOOGLE_DRIVE_PICKER_SCOPE } from "./google-drive-provider.js";
|
|
2
|
+
export const requestGoogleDriveAccessToken = ({ google, clientId, hint, onResponse, onError, }) => {
|
|
3
|
+
const tokenClient = google.accounts.oauth2.initTokenClient({
|
|
4
|
+
client_id: clientId,
|
|
5
|
+
scope: GOOGLE_DRIVE_PICKER_SCOPE,
|
|
6
|
+
include_granted_scopes: false,
|
|
7
|
+
callback: onResponse,
|
|
8
|
+
error_callback: onError,
|
|
9
|
+
...(hint !== undefined && hint !== "" && { hint }),
|
|
10
|
+
});
|
|
11
|
+
tokenClient.requestAccessToken();
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=google-drive-oauth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-drive-oauth.js","sourceRoot":"","sources":["../../src/lib/google-drive-oauth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAA;AAWnE,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,EAC5C,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,UAAU,EACV,OAAO,GAC4B,EAAQ,EAAE;IAC7C,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,eAAe,CAAC;QACzD,SAAS,EAAE,QAAQ;QACnB,KAAK,EAAE,yBAAyB;QAChC,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,UAAU;QACpB,cAAc,EAAE,OAAO;QACvB,GAAG,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;KACnD,CAAC,CAAA;IACF,WAAW,CAAC,kBAAkB,EAAE,CAAA;AAClC,CAAC,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { GoogleDrivePluginData } from "./plugin-data.js";
|
|
2
|
+
export declare const GOOGLE_DRIVE_NOT_CONFIGURED_USER_MESSAGE = "Google Drive is not configured. Contact your administrator.";
|
|
3
|
+
export type GoogleDrivePickerConfiguration = Pick<GoogleDrivePluginData, "clientId" | "appId" | "developerKey">;
|
|
4
|
+
/**
|
|
5
|
+
* Read public Google Picker configuration from the server runtime.
|
|
6
|
+
*/
|
|
7
|
+
export declare const readGoogleDrivePickerConfiguration: () => GoogleDrivePickerConfiguration;
|
|
8
|
+
export declare const googleDrivePickerConfigurationDiagnostics: (input: {
|
|
9
|
+
readonly clientId: string;
|
|
10
|
+
readonly appId: string;
|
|
11
|
+
readonly developerKey: string;
|
|
12
|
+
}) => readonly string[];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const GOOGLE_DRIVE_NOT_CONFIGURED_USER_MESSAGE = "Google Drive is not configured. Contact your administrator.";
|
|
2
|
+
/**
|
|
3
|
+
* Read public Google Picker configuration from the server runtime.
|
|
4
|
+
*/
|
|
5
|
+
export const readGoogleDrivePickerConfiguration = () => {
|
|
6
|
+
const clientId = process.env["GOOGLE_DRIVE_PICKER_CLIENT_ID"];
|
|
7
|
+
const appId = process.env["GOOGLE_DRIVE_PICKER_APP_ID"];
|
|
8
|
+
const developerKey = process.env["GOOGLE_DRIVE_PICKER_DEVELOPER_KEY"];
|
|
9
|
+
return {
|
|
10
|
+
...(clientId !== undefined && { clientId }),
|
|
11
|
+
...(appId !== undefined && { appId }),
|
|
12
|
+
...(developerKey !== undefined && { developerKey }),
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export const googleDrivePickerConfigurationDiagnostics = (input) => {
|
|
16
|
+
const diagnostics = [];
|
|
17
|
+
if (!input.clientId) {
|
|
18
|
+
diagnostics.push("Google Drive Picker: Missing GOOGLE_DRIVE_PICKER_CLIENT_ID Picker configuration");
|
|
19
|
+
}
|
|
20
|
+
if (!input.appId) {
|
|
21
|
+
diagnostics.push("Google Drive Picker: Missing GOOGLE_DRIVE_PICKER_APP_ID Picker configuration");
|
|
22
|
+
}
|
|
23
|
+
if (!input.developerKey) {
|
|
24
|
+
diagnostics.push("Google Drive Picker: Missing GOOGLE_DRIVE_PICKER_DEVELOPER_KEY Picker configuration");
|
|
25
|
+
}
|
|
26
|
+
return diagnostics;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=google-drive-picker-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-drive-picker-config.js","sourceRoot":"","sources":["../../src/lib/google-drive-picker-config.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,wCAAwC,GACnD,6DAA6D,CAAA;AAO/D;;GAEG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAC7C,GAAmC,EAAE;IACnC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAA;IAC7D,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAA;IACvD,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAA;IACrE,OAAO;QACL,GAAG,CAAC,QAAQ,KAAK,SAAS,IAAI,EAAE,QAAQ,EAAE,CAAC;QAC3C,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,CAAC;QACrC,GAAG,CAAC,YAAY,KAAK,SAAS,IAAI,EAAE,YAAY,EAAE,CAAC;KACpD,CAAA;AACH,CAAC,CAAA;AAEH,MAAM,CAAC,MAAM,yCAAyC,GAAG,CAAC,KAIzD,EAAqB,EAAE;IACtB,MAAM,WAAW,GAAa,EAAE,CAAA;IAChC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QACpB,WAAW,CAAC,IAAI,CACd,iFAAiF,CAClF,CAAA;IACH,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACjB,WAAW,CAAC,IAAI,CACd,8EAA8E,CAC/E,CAAA;IACH,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;QACxB,WAAW,CAAC,IAAI,CACd,qFAAqF,CACtF,CAAA;IACH,CAAC;IACD,OAAO,WAAW,CAAA;AACpB,CAAC,CAAA"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* JSX augmentation for Google Drive Picker custom elements.
|
|
4
|
+
* Inlined here because Next.js incremental mode does not pick up
|
|
5
|
+
* standalone .d.ts augmentation files from referenced projects.
|
|
6
|
+
*/
|
|
7
|
+
declare module "react" {
|
|
8
|
+
namespace JSX {
|
|
9
|
+
interface IntrinsicElements {
|
|
10
|
+
"drive-picker": React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & {
|
|
11
|
+
"app-id"?: string;
|
|
12
|
+
"client-id"?: string;
|
|
13
|
+
"developer-key"?: string;
|
|
14
|
+
"oauth-token"?: string;
|
|
15
|
+
mime?: string;
|
|
16
|
+
multiselect?: boolean;
|
|
17
|
+
}, HTMLElement>;
|
|
18
|
+
"drive-picker-docs-view": React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & {
|
|
19
|
+
"include-folders"?: string;
|
|
20
|
+
"mime-types"?: string;
|
|
21
|
+
}, HTMLElement>;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export interface GoogleDrivePickerField {
|
|
26
|
+
readonly state: {
|
|
27
|
+
readonly value: string;
|
|
28
|
+
};
|
|
29
|
+
readonly handleChange: (value: string) => void;
|
|
30
|
+
}
|
|
31
|
+
interface GoogleDrivePickerProps {
|
|
32
|
+
readonly field: GoogleDrivePickerField;
|
|
33
|
+
readonly label: string;
|
|
34
|
+
readonly description?: string;
|
|
35
|
+
readonly autoFocus?: boolean;
|
|
36
|
+
readonly readOnly?: boolean;
|
|
37
|
+
readonly clientId?: string;
|
|
38
|
+
readonly appId?: string;
|
|
39
|
+
readonly developerKey?: string;
|
|
40
|
+
readonly generatePdf?: {
|
|
41
|
+
readonly documentStore: string;
|
|
42
|
+
};
|
|
43
|
+
readonly hint?: string;
|
|
44
|
+
readonly stepPath?: string;
|
|
45
|
+
readonly requestUploadUrl: (input: {
|
|
46
|
+
readonly stepPath: string;
|
|
47
|
+
readonly documentStore: string;
|
|
48
|
+
readonly contentType: string;
|
|
49
|
+
readonly filename: string;
|
|
50
|
+
}) => Promise<{
|
|
51
|
+
readonly fileId: string;
|
|
52
|
+
readonly uploadUrl: string;
|
|
53
|
+
}>;
|
|
54
|
+
readonly requestDownloadUrl: (input: {
|
|
55
|
+
readonly stepPath: string;
|
|
56
|
+
readonly documentStore: string;
|
|
57
|
+
readonly fileId: string;
|
|
58
|
+
}) => Promise<{
|
|
59
|
+
readonly downloadUrl: string;
|
|
60
|
+
}>;
|
|
61
|
+
readonly deleteFile: (fileId: string) => Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
export type SelectedGoogleDriveFileProps = {
|
|
64
|
+
readonly kind: "editable";
|
|
65
|
+
readonly fileName: string;
|
|
66
|
+
} | {
|
|
67
|
+
readonly kind: "link";
|
|
68
|
+
readonly fileName: string;
|
|
69
|
+
readonly href: string;
|
|
70
|
+
} | {
|
|
71
|
+
readonly kind: "stored-pdf";
|
|
72
|
+
readonly fileName: string;
|
|
73
|
+
readonly opening: boolean;
|
|
74
|
+
readonly onOpen: () => void;
|
|
75
|
+
};
|
|
76
|
+
export declare function SelectedGoogleDriveFile(props: SelectedGoogleDriveFileProps): React.JSX.Element;
|
|
77
|
+
/**
|
|
78
|
+
* Google Drive file picker component using @googleworkspace/drive-picker-element.
|
|
79
|
+
*
|
|
80
|
+
* Handles its own OAuth consent via Google Identity Services since the
|
|
81
|
+
* existing login token only has profile/email scopes, not Drive.
|
|
82
|
+
*
|
|
83
|
+
* The OAuth bearer token is kept only in browser memory and shared between
|
|
84
|
+
* remounted picker fields until shortly before it expires. generatePdf fields
|
|
85
|
+
* export and upload before submission, so only the stored PDF reference enters
|
|
86
|
+
* form state.
|
|
87
|
+
*
|
|
88
|
+
* Receives public Picker configuration from field pluginData. The server-side
|
|
89
|
+
* form walker reads the runtime environment and sends those values here.
|
|
90
|
+
*/
|
|
91
|
+
export declare function GoogleDrivePicker({ field, label, description, autoFocus, readOnly, clientId, appId, developerKey, generatePdf, hint, stepPath, requestUploadUrl, requestDownloadUrl, deleteFile, }: GoogleDrivePickerProps): React.JSX.Element;
|
|
92
|
+
export {};
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useEffect, useId, useRef, useState } from "react";
|
|
4
|
+
import { loadDrivePickerElement } from "./drive-picker-element-loader.js";
|
|
5
|
+
import { GOOGLE_DRIVE_PDF_MIME_TYPES, GoogleDriveBrowserExportError, exportGoogleDriveFileToDocumentStore, } from "./google-drive-browser-export.js";
|
|
6
|
+
import { openStoredGoogleDrivePdf } from "./google-drive-download.js";
|
|
7
|
+
import { requestGoogleDriveAccessToken } from "./google-drive-oauth.js";
|
|
8
|
+
import { GOOGLE_DRIVE_NOT_CONFIGURED_USER_MESSAGE, googleDrivePickerConfigurationDiagnostics, } from "./google-drive-picker-config.js";
|
|
9
|
+
import { clearPickerTokenCache, getCachedPickerToken, setCachedPickerToken, } from "./picker-token-cache.js";
|
|
10
|
+
/** Access the GIS global loaded by the external script. */
|
|
11
|
+
function getGIS() {
|
|
12
|
+
const g = globalThis["google"];
|
|
13
|
+
if (!g?.accounts?.oauth2) {
|
|
14
|
+
throw new Error("Google Identity Services script not loaded");
|
|
15
|
+
}
|
|
16
|
+
return g;
|
|
17
|
+
}
|
|
18
|
+
const parsePickerValue = (value) => {
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(value);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const selectedGoogleDriveFileOpenClassName = "max-w-full break-all text-sm font-medium text-primary underline hover:text-primary/80 disabled:opacity-50";
|
|
27
|
+
export function SelectedGoogleDriveFile(props) {
|
|
28
|
+
switch (props.kind) {
|
|
29
|
+
case "link":
|
|
30
|
+
return (_jsx("a", { href: props.href, target: "_blank", rel: "noopener noreferrer", className: selectedGoogleDriveFileOpenClassName, children: props.fileName }));
|
|
31
|
+
case "stored-pdf":
|
|
32
|
+
return (_jsx("button", { type: "button", disabled: props.opening, onClick: props.onOpen, className: selectedGoogleDriveFileOpenClassName, children: props.opening ? "Opening PDF..." : props.fileName }));
|
|
33
|
+
case "editable":
|
|
34
|
+
return (_jsx("div", { className: "min-w-0 max-w-full rounded-md border border-input bg-muted p-2", children: _jsx("p", { className: "break-all text-sm font-medium text-foreground", children: props.fileName }) }));
|
|
35
|
+
default: {
|
|
36
|
+
const _exhaustive = props;
|
|
37
|
+
return _exhaustive;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function DrivePickerElementLoader({ onError, onLoaded, }) {
|
|
42
|
+
"use no memo";
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
loadDrivePickerElement(onLoaded, onError);
|
|
45
|
+
}, [onLoaded, onError]);
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Google Drive file picker component using @googleworkspace/drive-picker-element.
|
|
50
|
+
*
|
|
51
|
+
* Handles its own OAuth consent via Google Identity Services since the
|
|
52
|
+
* existing login token only has profile/email scopes, not Drive.
|
|
53
|
+
*
|
|
54
|
+
* The OAuth bearer token is kept only in browser memory and shared between
|
|
55
|
+
* remounted picker fields until shortly before it expires. generatePdf fields
|
|
56
|
+
* export and upload before submission, so only the stored PDF reference enters
|
|
57
|
+
* form state.
|
|
58
|
+
*
|
|
59
|
+
* Receives public Picker configuration from field pluginData. The server-side
|
|
60
|
+
* form walker reads the runtime environment and sends those values here.
|
|
61
|
+
*/
|
|
62
|
+
export function GoogleDrivePicker({ field, label, description, autoFocus, readOnly, clientId = "", appId = "", developerKey = "", generatePdf, hint, stepPath, requestUploadUrl, requestDownloadUrl, deleteFile, }) {
|
|
63
|
+
const value = field.state.value;
|
|
64
|
+
// Bearer token lives only in browser memory, never form state or storage.
|
|
65
|
+
const oauthTokenRef = useRef("");
|
|
66
|
+
const [oauthToken, setOauthToken] = useState("");
|
|
67
|
+
const [selectedFileName, setSelectedFileName] = useState("");
|
|
68
|
+
const [selectedFileUrl, setSelectedFileUrl] = useState("");
|
|
69
|
+
const [showPicker, setShowPicker] = useState(false);
|
|
70
|
+
const [error, setError] = useState(null);
|
|
71
|
+
const [componentLoaded, setComponentLoaded] = useState(false);
|
|
72
|
+
const [authenticating, setAuthenticating] = useState(false);
|
|
73
|
+
const [exportingPdf, setExportingPdf] = useState(false);
|
|
74
|
+
const [downloading, setDownloading] = useState(false);
|
|
75
|
+
const labelId = useId();
|
|
76
|
+
const handleComponentLoaded = useCallback(() => setComponentLoaded(true), []);
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
for (const message of googleDrivePickerConfigurationDiagnostics({
|
|
79
|
+
clientId,
|
|
80
|
+
appId,
|
|
81
|
+
developerKey,
|
|
82
|
+
})) {
|
|
83
|
+
console.warn(message);
|
|
84
|
+
}
|
|
85
|
+
}, [clientId, appId, developerKey]);
|
|
86
|
+
// Parse existing value to show file name and URL
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (value) {
|
|
89
|
+
const parsed = parsePickerValue(value);
|
|
90
|
+
setSelectedFileName(parsed?.name ?? parsed?.filename ?? "");
|
|
91
|
+
setSelectedFileUrl(parsed?.url ?? "");
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
setSelectedFileName("");
|
|
95
|
+
setSelectedFileUrl("");
|
|
96
|
+
}
|
|
97
|
+
}, [value]);
|
|
98
|
+
// Radix modal dialogs set pointer-events: none on document.body to
|
|
99
|
+
// prevent outside interactions. The Google Drive picker overlay is
|
|
100
|
+
// appended to body by Google, so it inherits this and becomes
|
|
101
|
+
// unclickable. Temporarily restore pointer-events while the picker
|
|
102
|
+
// is open so users can select files.
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
if (!showPicker)
|
|
105
|
+
return;
|
|
106
|
+
const prev = document.body.style.pointerEvents;
|
|
107
|
+
document.body.style.pointerEvents = "auto";
|
|
108
|
+
return () => {
|
|
109
|
+
// Only restore if still "auto" — avoids clobbering another modal
|
|
110
|
+
// that may have set pointer-events in the meantime.
|
|
111
|
+
if (document.body.style.pointerEvents === "auto") {
|
|
112
|
+
document.body.style.pointerEvents = prev;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}, [showPicker]);
|
|
116
|
+
// Shared handler for when we receive a token from GIS.
|
|
117
|
+
const handleTokenResponse = useCallback((response) => {
|
|
118
|
+
setAuthenticating(false);
|
|
119
|
+
if (response.access_token) {
|
|
120
|
+
setError(null);
|
|
121
|
+
oauthTokenRef.current = response.access_token;
|
|
122
|
+
setOauthToken(response.access_token);
|
|
123
|
+
setShowPicker(true);
|
|
124
|
+
if (response.expires_in) {
|
|
125
|
+
setCachedPickerToken({
|
|
126
|
+
clientId,
|
|
127
|
+
token: response.access_token,
|
|
128
|
+
expiresInSeconds: response.expires_in,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}, [clientId]);
|
|
133
|
+
// Handle OAuth token acquisition via Google Identity Services
|
|
134
|
+
const handleAuthClick = useCallback(() => {
|
|
135
|
+
if (readOnly || authenticating || exportingPdf)
|
|
136
|
+
return;
|
|
137
|
+
// Clear recoverable errors so the user can retry without a full reload.
|
|
138
|
+
setError(null);
|
|
139
|
+
if (generatePdf && !stepPath) {
|
|
140
|
+
setError("Cannot upload exported PDF: missing form step context.");
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
// Dynamic forms can remount fields after every change. The expiry-aware
|
|
144
|
+
// page cache is the source of truth for all repeated selections.
|
|
145
|
+
const cachedToken = getCachedPickerToken({ clientId });
|
|
146
|
+
if (cachedToken) {
|
|
147
|
+
oauthTokenRef.current = cachedToken;
|
|
148
|
+
setOauthToken(cachedToken);
|
|
149
|
+
setShowPicker(true);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
oauthTokenRef.current = "";
|
|
153
|
+
setOauthToken("");
|
|
154
|
+
let gis;
|
|
155
|
+
try {
|
|
156
|
+
gis = getGIS();
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
setError("Google Identity Services script not loaded yet. Please retry.");
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
setAuthenticating(true);
|
|
163
|
+
requestGoogleDriveAccessToken({
|
|
164
|
+
google: gis,
|
|
165
|
+
clientId,
|
|
166
|
+
...(hint !== undefined && hint !== "" && { hint }),
|
|
167
|
+
onResponse: handleTokenResponse,
|
|
168
|
+
onError: () => {
|
|
169
|
+
setAuthenticating(false);
|
|
170
|
+
setError("Google Drive authorization failed. Please try again.");
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
}, [
|
|
174
|
+
clientId,
|
|
175
|
+
generatePdf,
|
|
176
|
+
hint,
|
|
177
|
+
readOnly,
|
|
178
|
+
authenticating,
|
|
179
|
+
exportingPdf,
|
|
180
|
+
handleTokenResponse,
|
|
181
|
+
stepPath,
|
|
182
|
+
]);
|
|
183
|
+
// Ref callback: attaches the picker:picked listener when the <drive-picker>
|
|
184
|
+
// element mounts and removes it on unmount. No deps needed — React calls
|
|
185
|
+
// the callback with the element on mount and with null on unmount.
|
|
186
|
+
const pickerRef = useCallback((picker) => {
|
|
187
|
+
if (!picker)
|
|
188
|
+
return;
|
|
189
|
+
const handlePicked = (event) => {
|
|
190
|
+
const detail = event.detail;
|
|
191
|
+
const docs = detail?.docs ?? detail;
|
|
192
|
+
if (!Array.isArray(docs) || docs.length === 0)
|
|
193
|
+
return;
|
|
194
|
+
const file = docs[0];
|
|
195
|
+
const metadata = {
|
|
196
|
+
id: file.id,
|
|
197
|
+
name: file.name,
|
|
198
|
+
mimeType: file.mimeType,
|
|
199
|
+
url: file.url,
|
|
200
|
+
};
|
|
201
|
+
// Without PDF export, store metadata only — no credential.
|
|
202
|
+
if (!generatePdf) {
|
|
203
|
+
field.handleChange(JSON.stringify(metadata));
|
|
204
|
+
setSelectedFileName(file.name);
|
|
205
|
+
setShowPicker(false);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const token = oauthTokenRef.current;
|
|
209
|
+
if (!token) {
|
|
210
|
+
setError("Google Drive authorization expired. Please reauthorize and select the file again.");
|
|
211
|
+
setShowPicker(false);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (!stepPath) {
|
|
215
|
+
setError("Cannot upload exported PDF: missing form step context.");
|
|
216
|
+
setShowPicker(false);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
setExportingPdf(true);
|
|
220
|
+
setError(null);
|
|
221
|
+
void exportGoogleDriveFileToDocumentStore({
|
|
222
|
+
file: metadata,
|
|
223
|
+
accessToken: token,
|
|
224
|
+
stepPath,
|
|
225
|
+
documentStore: generatePdf.documentStore,
|
|
226
|
+
requestUploadUrl,
|
|
227
|
+
deleteFile,
|
|
228
|
+
})
|
|
229
|
+
.then((generatedPdf) => {
|
|
230
|
+
const previousFileId = parsePickerValue(value)?.fileId;
|
|
231
|
+
field.handleChange(JSON.stringify(generatedPdf));
|
|
232
|
+
setSelectedFileName(file.name);
|
|
233
|
+
setShowPicker(false);
|
|
234
|
+
if (previousFileId) {
|
|
235
|
+
void deleteFile(previousFileId).catch(() => {
|
|
236
|
+
setError("The previous stored PDF could not be removed.");
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
})
|
|
240
|
+
.catch((cause) => {
|
|
241
|
+
if (cause instanceof GoogleDriveBrowserExportError) {
|
|
242
|
+
if (cause.code === "drive-authorization" ||
|
|
243
|
+
cause.code === "drive-access") {
|
|
244
|
+
oauthTokenRef.current = "";
|
|
245
|
+
setOauthToken("");
|
|
246
|
+
clearPickerTokenCache();
|
|
247
|
+
}
|
|
248
|
+
setError(cause.message);
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
setError("Failed to export and upload the selected Drive file. Please try again.");
|
|
252
|
+
}
|
|
253
|
+
setShowPicker(false);
|
|
254
|
+
})
|
|
255
|
+
.finally(() => {
|
|
256
|
+
setExportingPdf(false);
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
picker.addEventListener("picker:picked", handlePicked);
|
|
260
|
+
// Return cleanup — React 19 ref callbacks support cleanup returns
|
|
261
|
+
return () => {
|
|
262
|
+
picker.removeEventListener("picker:picked", handlePicked);
|
|
263
|
+
};
|
|
264
|
+
}, [deleteFile, field, generatePdf, requestUploadUrl, stepPath, value]);
|
|
265
|
+
const hasPickerConfiguration = Boolean(clientId && appId && developerKey);
|
|
266
|
+
const busy = authenticating || exportingPdf;
|
|
267
|
+
const storedFileId = parsePickerValue(value)?.fileId;
|
|
268
|
+
const handleDownloadClick = useCallback(() => {
|
|
269
|
+
if (!readOnly || !generatePdf || !storedFileId || downloading) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (!stepPath) {
|
|
273
|
+
setError("Cannot download stored PDF: missing form step context.");
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
setDownloading(true);
|
|
277
|
+
setError(null);
|
|
278
|
+
void openStoredGoogleDrivePdf({
|
|
279
|
+
stepPath,
|
|
280
|
+
documentStore: generatePdf.documentStore,
|
|
281
|
+
fileId: storedFileId,
|
|
282
|
+
requestDownloadUrl,
|
|
283
|
+
openUrl: (downloadUrl) => globalThis.location.assign(downloadUrl),
|
|
284
|
+
})
|
|
285
|
+
.catch(() => {
|
|
286
|
+
setError("The stored PDF could not be opened. Please try again.");
|
|
287
|
+
})
|
|
288
|
+
.finally(() => {
|
|
289
|
+
setDownloading(false);
|
|
290
|
+
});
|
|
291
|
+
}, [
|
|
292
|
+
downloading,
|
|
293
|
+
generatePdf,
|
|
294
|
+
readOnly,
|
|
295
|
+
requestDownloadUrl,
|
|
296
|
+
stepPath,
|
|
297
|
+
storedFileId,
|
|
298
|
+
]);
|
|
299
|
+
return (_jsxs("div", { className: "min-w-0 space-y-2", children: [_jsx(DrivePickerElementLoader, { onLoaded: handleComponentLoaded, onError: setError }), _jsx("span", { id: labelId, className: "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70", children: label }), description && (_jsx("p", { className: "text-muted-foreground text-sm", children: description })), !hasPickerConfiguration && !readOnly ? (_jsx("div", { className: "rounded-md border border-yellow-500 bg-yellow-50 p-3 text-sm text-yellow-800", children: _jsx("p", { className: "font-medium", children: GOOGLE_DRIVE_NOT_CONFIGURED_USER_MESSAGE }) })) : (_jsxs("div", { className: "min-w-0 space-y-2", children: [error && (_jsx("div", { className: "rounded-md border border-red-300 bg-red-50 p-3 text-sm text-red-800", children: error })), selectedFileName &&
|
|
300
|
+
(readOnly && selectedFileUrl ? (_jsx(SelectedGoogleDriveFile, { kind: "link", fileName: selectedFileName, href: selectedFileUrl })) : readOnly && storedFileId && generatePdf ? (_jsx(SelectedGoogleDriveFile, { kind: "stored-pdf", fileName: selectedFileName, opening: downloading, onOpen: handleDownloadClick })) : (_jsx(SelectedGoogleDriveFile, { kind: "editable", fileName: selectedFileName }))), !readOnly && !componentLoaded && (_jsx("p", { className: "text-muted-foreground text-sm", children: "Loading Google Drive picker..." })), _jsx("div", { className: "flex min-w-0 flex-wrap items-center gap-2", children: !readOnly && componentLoaded && (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", disabled: busy, "aria-labelledby": labelId, className: "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background hover:bg-accent hover:text-accent-foreground h-10 px-4 py-2", onClick: handleAuthClick,
|
|
301
|
+
// biome-ignore lint/a11y/noAutofocus: form walker manages focus for first interactive field
|
|
302
|
+
autoFocus: autoFocus, children: authenticating
|
|
303
|
+
? "Authenticating..."
|
|
304
|
+
: exportingPdf
|
|
305
|
+
? "Exporting PDF..."
|
|
306
|
+
: selectedFileName
|
|
307
|
+
? "Change file"
|
|
308
|
+
: error
|
|
309
|
+
? "Try again"
|
|
310
|
+
: "Select file" }), selectedFileName && (_jsx("button", { type: "button", className: "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background hover:bg-accent hover:text-accent-foreground h-10 px-4 py-2", onClick: () => {
|
|
311
|
+
const fileId = parsePickerValue(value)?.fileId;
|
|
312
|
+
if (fileId) {
|
|
313
|
+
void deleteFile(fileId).catch(() => {
|
|
314
|
+
setError("The stored PDF could not be removed.");
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
setSelectedFileName("");
|
|
318
|
+
setError(null);
|
|
319
|
+
field.handleChange("");
|
|
320
|
+
}, children: "Remove" }))] })) }), !readOnly && showPicker && oauthToken && (_jsx("drive-picker", { ref: pickerRef, "app-id": appId, "client-id": clientId, "developer-key": developerKey, "oauth-token": oauthToken, children: _jsx("drive-picker-docs-view", { "include-folders": "false", ...(generatePdf && {
|
|
321
|
+
"mime-types": GOOGLE_DRIVE_PDF_MIME_TYPES.join(","),
|
|
322
|
+
}) }) }))] }))] }));
|
|
323
|
+
}
|
|
324
|
+
//# sourceMappingURL=google-drive-picker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-drive-picker.js","sourceRoot":"","sources":["../../src/lib/google-drive-picker.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAGZ,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAA;AACtE,OAAO,EACL,2BAA2B,EAC3B,6BAA6B,EAC7B,oCAAoC,GACrC,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAA;AAClE,OAAO,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAA;AACpE,OAAO,EACL,wCAAwC,EACxC,yCAAyC,GAC1C,MAAM,8BAA8B,CAAA;AACrC,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,sBAAsB,CAAA;AAiC7B,2DAA2D;AAC3D,SAAS,MAAM;IACb,MAAM,CAAC,GAAI,UAAsC,CAAC,QAAQ,CAE7C,CAAA;IACb,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;IAC/D,CAAC;IACD,OAAO,CAAC,CAAA;AACV,CAAC;AAmCD,MAAM,gBAAgB,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AAI,CACnB,iBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,4XAA4X,EACtY,OAAO,EAAE,GAAG,EAAE;wCACZ,MAAM,MAAM,GAAG,gBAAgB,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;wCAC9C,IAAI,MAAM,EAAE,CAAC;4CACX,KAAK,UAAU,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;gDACjC,QAAQ,CAAC,sCAAsC,CAAC,CAAA;4CAClD,CAAC,CAAC,CAAA;wCACJ,CAAC;wCACD,mBAAmB,CAAC,EAAE,CAAC,CAAA;wCACvB,QAAQ,CAAC,IAAI,CAAC,CAAA;wCACd,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,CAAA;oCACxB,CAAC,uBAGM,CACV,IACA,CACJ,GACG,EAEL,CAAC,QAAQ,IAAI,UAAU,IAAI,UAAU,IAAI,CACxC,uBACE,GAAG,EAAE,SAAS,YACN,KAAK,eACF,QAAQ,mBACJ,YAAY,iBACd,UAAU,YAEvB,oDACkB,OAAO,KACnB,CAAC,WAAW,IAAI;gCAClB,YAAY,EAAE,2BAA2B,CAAC,IAAI,CAAC,GAAG,CAAC;6BACpD,CAAC,GACF,GACW,CAChB,IACG,CACP,IACG,CACP,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-drive-provider.js","sourceRoot":"","sources":["../../src/lib/google-drive-provider.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GACpC,4CAAqD,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Construct } from "constructs";
|
|
2
|
+
import type { OrganisationBrowserPluginArtifactProvider, OrganisationBrowserPluginBuildInput, OrganisationFrontendPluginManifestClientPlugin, OrganisationFrontendPluginManifestProvider } from "processfocus/plugin";
|
|
3
|
+
/**
|
|
4
|
+
* Declares Google Drive as organisation-owned browser and server behavior.
|
|
5
|
+
*
|
|
6
|
+
* Importing the plugin's field API registers its walker in the organisation
|
|
7
|
+
* bundle realm. This construct makes the matching browser renderer and its
|
|
8
|
+
* build-time stylesheet part of the same organisation artifact.
|
|
9
|
+
*/
|
|
10
|
+
export declare class GoogleDrive extends Construct implements OrganisationFrontendPluginManifestProvider, OrganisationBrowserPluginArtifactProvider {
|
|
11
|
+
readonly isFrontendClientPluginManifestProvider: true;
|
|
12
|
+
readonly isBrowserPluginArtifactProvider: true;
|
|
13
|
+
readonly frontendManifestPluginCategory = "formComponents";
|
|
14
|
+
buildFrontendClientPluginManifest(): OrganisationFrontendPluginManifestClientPlugin;
|
|
15
|
+
buildBrowserPluginArtifact(): OrganisationBrowserPluginBuildInput;
|
|
16
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Construct } from "constructs";
|
|
2
|
+
import { FRONTEND_PLUGIN_HOST_INTERFACE_VERSION } from "processfocus/plugin";
|
|
3
|
+
import { GOOGLE_DRIVE_CLIENT_MODULE, GOOGLE_DRIVE_PLUGIN_TYPE, } from "./plugin-identity.js";
|
|
4
|
+
/**
|
|
5
|
+
* Declares Google Drive as organisation-owned browser and server behavior.
|
|
6
|
+
*
|
|
7
|
+
* Importing the plugin's field API registers its walker in the organisation
|
|
8
|
+
* bundle realm. This construct makes the matching browser renderer and its
|
|
9
|
+
* build-time stylesheet part of the same organisation artifact.
|
|
10
|
+
*/
|
|
11
|
+
export class GoogleDrive extends Construct {
|
|
12
|
+
isFrontendClientPluginManifestProvider = true;
|
|
13
|
+
isBrowserPluginArtifactProvider = true;
|
|
14
|
+
frontendManifestPluginCategory = "formComponents";
|
|
15
|
+
buildFrontendClientPluginManifest() {
|
|
16
|
+
return {
|
|
17
|
+
module: GOOGLE_DRIVE_CLIENT_MODULE,
|
|
18
|
+
type: GOOGLE_DRIVE_PLUGIN_TYPE,
|
|
19
|
+
config: null,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
buildBrowserPluginArtifact() {
|
|
23
|
+
return {
|
|
24
|
+
identity: GOOGLE_DRIVE_PLUGIN_TYPE,
|
|
25
|
+
category: "formComponents",
|
|
26
|
+
hostInterfaceVersion: FRONTEND_PLUGIN_HOST_INTERFACE_VERSION,
|
|
27
|
+
entrypoint: "@processfocus/plugin-google-drive/browser",
|
|
28
|
+
preparation: {
|
|
29
|
+
kind: "stylesheet",
|
|
30
|
+
entrypoint: "@processfocus/plugin-google-drive/styles.css",
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=google-drive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-drive.js","sourceRoot":"","sources":["../../src/lib/google-drive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,sCAAsC,EAAE,MAAM,0BAA0B,CAAA;AAQjF,OAAO,EACL,0BAA0B,EAC1B,wBAAwB,GACzB,MAAM,mBAAmB,CAAA;AAE1B;;;;;;GAMG;AACH,MAAM,OAAO,WACX,SAAQ,SAAS;IAKR,sCAAsC,GAAG,IAAa,CAAA;IACtD,+BAA+B,GAAG,IAAa,CAAA;IAC/C,8BAA8B,GACrC,gBAAqE,CAAA;IAEvE,iCAAiC;QAC/B,OAAO;YACL,MAAM,EAAE,0BAA0B;YAClC,IAAI,EAAE,wBAAwB;YAC9B,MAAM,EAAE,IAAI;SACb,CAAA;IACH,CAAC;IAED,0BAA0B;QACxB,OAAO;YACL,QAAQ,EAAE,wBAAwB;YAClC,QAAQ,EAAE,gBAAgB;YAC1B,oBAAoB,EAAE,sCAAsC;YAC5D,UAAU,EAAE,2CAA2C;YACvD,WAAW,EAAE;gBACX,IAAI,EAAE,YAAY;gBAClB,UAAU,EAAE,8CAA8C;aAC3D;SACF,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface GetCachedPickerTokenInput {
|
|
2
|
+
readonly clientId: string;
|
|
3
|
+
readonly now?: number;
|
|
4
|
+
}
|
|
5
|
+
interface SetCachedPickerTokenInput {
|
|
6
|
+
readonly clientId: string;
|
|
7
|
+
readonly token: string;
|
|
8
|
+
readonly expiresInSeconds: number;
|
|
9
|
+
readonly now?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare function getCachedPickerToken({ clientId, now, }: GetCachedPickerTokenInput): string | null;
|
|
12
|
+
export declare function setCachedPickerToken({ clientId, token, expiresInSeconds, now, }: SetCachedPickerTokenInput): void;
|
|
13
|
+
/** Remove all in-memory picker tokens during plugin cleanup or logout. */
|
|
14
|
+
export declare function clearPickerTokenCache(): void;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const EXPIRY_BUFFER_MS = 60_000;
|
|
2
|
+
// Module memory lets remounted picker fields share authorization without
|
|
3
|
+
// placing bearer tokens in browser storage or process state.
|
|
4
|
+
const pickerTokens = new Map();
|
|
5
|
+
export function getCachedPickerToken({ clientId, now = Date.now(), }) {
|
|
6
|
+
const cached = pickerTokens.get(clientId);
|
|
7
|
+
if (!cached)
|
|
8
|
+
return null;
|
|
9
|
+
if (now >= cached.expiresAt - EXPIRY_BUFFER_MS) {
|
|
10
|
+
pickerTokens.delete(clientId);
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
return cached.token;
|
|
14
|
+
}
|
|
15
|
+
export function setCachedPickerToken({ clientId, token, expiresInSeconds, now = Date.now(), }) {
|
|
16
|
+
pickerTokens.set(clientId, {
|
|
17
|
+
token,
|
|
18
|
+
expiresAt: now + expiresInSeconds * 1_000,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/** Remove all in-memory picker tokens during plugin cleanup or logout. */
|
|
22
|
+
export function clearPickerTokenCache() {
|
|
23
|
+
pickerTokens.clear();
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=picker-token-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"picker-token-cache.js","sourceRoot":"","sources":["../../src/lib/picker-token-cache.ts"],"names":[],"mappings":"AAAA,MAAM,gBAAgB,GAAG,MAAM,CAAA;AAmB/B,yEAAyE;AACzE,6DAA6D;AAC7D,MAAM,YAAY,GAAG,IAAI,GAAG,EAA6B,CAAA;AAEzD,MAAM,UAAU,oBAAoB,CAAC,EACnC,QAAQ,EACR,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,GACU;IAC1B,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IACzC,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IACxB,IAAI,GAAG,IAAI,MAAM,CAAC,SAAS,GAAG,gBAAgB,EAAE,CAAC;QAC/C,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;QAC7B,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAA;AACrB,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,EACnC,QAAQ,EACR,KAAK,EACL,gBAAgB,EAChB,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,GACU;IAC1B,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE;QACzB,KAAK;QACL,SAAS,EAAE,GAAG,GAAG,gBAAgB,GAAG,KAAK;KAC1C,CAAC,CAAA;AACJ,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,qBAAqB;IACnC,YAAY,CAAC,KAAK,EAAE,CAAA;AACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=plugin-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-data.js","sourceRoot":"","sources":["../../src/lib/plugin-data.ts"],"names":[],"mappings":""}
|