-
Notifications
You must be signed in to change notification settings - Fork 6
fix: export prop types from manifest/jsdoc #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| /** | ||
| * Copyright 2024 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import fs from "node:fs"; | ||
| import prettier from "prettier"; | ||
| import ts, { factory } from "typescript"; | ||
|
|
||
| import type { | ||
| CustomElementDeclaration, | ||
| Declaration, | ||
| Package, | ||
| } from "custom-elements-manifest/schema"; | ||
|
|
||
| const manifest = JSON.parse( | ||
| fs.readFileSync("custom-elements.json", "utf-8"), | ||
| ) as Package; | ||
|
|
||
| function isCustomElementDeclaration( | ||
| declaration?: Declaration, | ||
| ): declaration is CustomElementDeclaration { | ||
| return (declaration as CustomElementDeclaration)?.customElement === true; | ||
| } | ||
|
|
||
| const customElements = manifest.modules | ||
| .flatMap((module) => module.declarations) | ||
| .filter(isCustomElementDeclaration) | ||
| .sort((a, b) => a.tagName?.localeCompare(b.tagName ?? "") ?? 0); | ||
|
|
||
| const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed }); | ||
| const resultFile = ts.createSourceFile( | ||
| "props.ts", | ||
| "", | ||
| ts.ScriptTarget.Latest, | ||
| false, | ||
| ts.ScriptKind.TS, | ||
| ); | ||
|
|
||
| const statements: ts.Statement[] = []; | ||
|
|
||
| for (const element of customElements) { | ||
| const properties: ts.PropertySignature[] = []; | ||
|
|
||
| for (const attribute of element.attributes ?? []) { | ||
| // Create the property signature | ||
| const prop = factory.createPropertySignature( | ||
| undefined, // No modifiers | ||
| attribute.name.includes("-") | ||
| ? factory.createStringLiteral(`${attribute.name}`) | ||
| : factory.createIdentifier(attribute.name), | ||
| factory.createToken(ts.SyntaxKind.QuestionToken), // Make props optional | ||
| factory.createTypeReferenceNode( | ||
| attribute.type?.text ?? "unknown", | ||
| undefined, | ||
| ), | ||
| ); | ||
|
|
||
| if (attribute.description) { | ||
| const jsDocText = `* ${attribute.description.replace(/\n/g, "\n * ")}`; | ||
| ts.addSyntheticLeadingComment( | ||
| prop, | ||
| ts.SyntaxKind.MultiLineCommentTrivia, | ||
| jsDocText, | ||
| true, | ||
| ); | ||
| } | ||
|
|
||
| properties.push(prop); | ||
| } | ||
|
|
||
| const propsInterface = factory.createInterfaceDeclaration( | ||
| [factory.createModifier(ts.SyntaxKind.ExportKeyword)], | ||
| factory.createIdentifier(`${element.name}Props`), | ||
| undefined, | ||
| undefined, | ||
| properties, | ||
| ); | ||
|
|
||
| statements.push(propsInterface); | ||
| } | ||
|
|
||
| const outputFile = "src/drive-picker/props.ts"; | ||
| const resultText = await prettier.format( | ||
| printer.printList( | ||
| ts.ListFormat.MultiLine, | ||
| factory.createNodeArray(statements), | ||
| resultFile, | ||
| ), | ||
| { | ||
| parser: "typescript", | ||
| useTabs: true, | ||
| }, | ||
| ); | ||
|
|
||
| const licenseHeader = `/** | ||
| * Copyright 2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */`; | ||
|
|
||
| fs.writeFileSync(outputFile, `${licenseHeader}\n\n${resultText}`, "utf8"); | ||
| console.log(`Generated Drive Picker prop type definitions at ${outputFile}`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /** | ||
| * Copyright 2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| export interface DrivePickerElementProps { | ||
| /** The Google Drive app ID. See [`PickerBuilder.setAppId`](https://developers.google.com/drive/picker/reference/picker.pickerbuilder.setappid).*/ | ||
| "app-id"?: string; | ||
| /** The OAuth 2.0 client ID. See [Using OAuth 2.0 to Access Google APIs](https://developers.google.com/identity/protocols/oauth2).*/ | ||
| "client-id"?: string; | ||
| /** The API key for accessing Google Picker API. See [`PickerBuilder.setDeveloperKey`](https://developers.google.com/drive/picker/reference/picker.pickerbuilder.setdeveloperkey).*/ | ||
| "developer-key"?: string; | ||
| /** Hides the title bar of the picker if set to true. See [`PickerBuilder.hideTitleBar`](https://developers.google.com/drive/picker/reference/picker.pickerbuilder.hidetitlebar).*/ | ||
| "hide-title-bar"?: "default" | "true" | "false"; | ||
| /** The locale to use for the picker. See [`PickerBuilder.setLocale`](https://developers.google.com/drive/picker/reference/picker.pickerbuilder.setlocale).*/ | ||
| locale?: string; | ||
| /** The maximum number of items that can be selected. See [`PickerBuilder.setMaxItems`](https://developers.google.com/drive/picker/reference/picker.pickerbuilder.setmaxitems).*/ | ||
| "max-items"?: number; | ||
| /** If set to true, only shows files owned by the user. See [`PickerBuilder.enableFeature`](https://developers.google.com/drive/picker/reference/picker.pickerbuilder.enablefeature).*/ | ||
| "mine-only"?: boolean; | ||
| /** Enables multiple file selection if set to true. See [`PickerBuilder.enableFeature`](https://developers.google.com/drive/picker/reference/picker.pickerbuilder.enablefeature).*/ | ||
| multiselect?: boolean; | ||
| /** Hides the navigation pane if set to true. See [`PickerBuilder.enableFeature`](https://developers.google.com/drive/picker/reference/picker.pickerbuilder.enablefeature).*/ | ||
| "nav-hidden"?: boolean; | ||
| /** The OAuth 2.0 token for authentication. See [`PickerBuilder.setOAuthToken`](https://developers.google.com/drive/picker/reference/picker.pickerbuilder.setoauthtoken).*/ | ||
| "oauth-token"?: string; | ||
| /** The origin parameter for the picker. See [`PickerBuilder.setOrigin`](https://developers.google.com/drive/picker/reference/picker.pickerbuilder.setorigin).*/ | ||
| origin?: string; | ||
| /** The relay URL for the picker. See [`PickerBuilder.setRelayUrl`](https://developers.google.com/drive/picker/reference/picker.pickerbuilder.setrelayurl).*/ | ||
| "relay-url"?: string; | ||
| /** The OAuth 2.0 scope for the picker. The default is `https://www.googleapis.com/auth/drive.file`. See [Drive API scopes](https://developers.google.com/drive/api/guides/api-specific-auth#drive-scopes).*/ | ||
| scope?: string; | ||
| /** The title of the picker. See [`PickerBuilder.setTitle`](https://developers.google.com/drive/picker/reference/picker.pickerbuilder.settitle).*/ | ||
| title?: string; | ||
| /** The hosted domain to restrict sign-in to. (Optional) See the `hd` field in the OpenID Connect docs.*/ | ||
| hd?: string; | ||
| /** Enables applications to use incremental authorization. See [`TokenClientConfig.include_granted_scopes`](https://developers.google.com/identity/oauth2/web/reference/js-reference#TokenClientConfig).*/ | ||
| "include-granted-scopes"?: boolean; | ||
| /** An email address or an ID token 'sub' value. Google will use the value as a hint of which user to sign in. See the `login_hint` field in the OpenID Connect docs.*/ | ||
| "login-hint"?: string; | ||
| /** A space-delimited, case-sensitive list of prompts to present the user. See [`TokenClientConfig.prompt`](https://developers.google.com/identity/oauth2/web/reference/js-reference#TokenClientConfig)*/ | ||
| prompt?: "" | "none" | "consent" | "select_account"; | ||
| } | ||
| export interface DrivePickerDocsViewElementProps { | ||
| /** Whether to allow the user to select files from shared drives. See [`DocsView.enableDrives`](https://developers.google.com/drive/picker/reference/picker.docsview.setenabledrives).*/ | ||
| "enable-drives"?: "default" | "true" | "false"; | ||
| /** Whether to include folders in the view. See [`DocsView.includeFolders`](https://developers.google.com/drive/picker/reference/picker.docsview.setincludefolders).*/ | ||
| "include-folders"?: "default" | "true" | "false"; | ||
| /** A comma-separated list of MIME types to filter the view. See [`View.setMimeTypes`](https://developers.google.com/drive/picker/reference/picker.view.setmimetypes).*/ | ||
| "mime-types"?: string; | ||
| /** The mode of the view. See [`DocsViewMode`](https://developers.google.com/drive/picker/reference/picker.docsviewmode).*/ | ||
| mode?: string; | ||
| /** Whether to show files owned by the user. See [`DocsView.ownedByMe`](https://developers.google.com/drive/picker/reference/picker.docsview.setownedbyme).*/ | ||
| "owned-by-me"?: "default" | "true" | "false"; | ||
| /** The ID of the folder to view. See [`DocsView.setParent`](https://developers.google.com/drive/picker/reference/picker.docsview.setparent).*/ | ||
| parent?: string; | ||
| /** The query string to filter the view. See [`View.setQuery`](https://developers.google.com/drive/picker/reference/picker.view.setquery).*/ | ||
| query?: string; | ||
| /** Whether to allow the user to select folders. See [`DocsView.selectFolderEnabled`](https://developers.google.com/drive/picker/reference/picker.docsview.setselectfolderenabled).*/ | ||
| "select-folder-enabled"?: "default" | "true" | "false"; | ||
| /** Whether to show starred files. See [`DocsView.starred`](https://developers.google.com/drive/picker/reference/picker.docsview.setstarred).*/ | ||
| starred?: "default" | "true" | "false"; | ||
| /** The `keyof typeof google.picker.ViewId`. For example, `"DOCS"`, which is equivalent to `google.picker.ViewId.DOCS`. See [`ViewId`](https://developers.google.com/drive/picker/reference/picker.viewid).*/ | ||
| "view-id"?: string; | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.