From adc86130923196de7637cb1c55d25278aa6bcc2f Mon Sep 17 00:00:00 2001 From: Nicholas Tindle Date: Wed, 28 May 2025 13:38:06 -0500 Subject: [PATCH 01/12] feat: add snippets to github files Co-Authored-By: Claude <81847+claude@users.noreply.github.com> --- .../github-files/gitbook-manifest.yaml | 9 +- integrations/github-files/src/github.ts | 60 ++++++- integrations/github-files/src/index.tsx | 158 +++++++++++++++++- integrations/github-files/src/types.ts | 7 +- 4 files changed, 227 insertions(+), 7 deletions(-) diff --git a/integrations/github-files/gitbook-manifest.yaml b/integrations/github-files/gitbook-manifest.yaml index 1937af070..8c2aeaa3c 100644 --- a/integrations/github-files/gitbook-manifest.yaml +++ b/integrations/github-files/gitbook-manifest.yaml @@ -12,13 +12,15 @@ externalLinks: summary: | # Overview - The GitHub Files integration allows you to take a link to a GitHub file or a permalink to lines of code and display them into code blocks in GitBook. + The GitHub Files integration allows you to take a link to a GitHub file or a permalink to lines of code and display them into code blocks in GitBook. It also supports snippet tags for extracting specific code sections. # How it works After installing the GitHub Files integration, you're able to insert it into a GitBook file in the (CMD + /) menu. - Insert the integration, paste your link, and the integration will display the code in a formatted code block. + **GitHub Files**: Insert the integration, paste your link, and the integration will display the code in a formatted code block. + + **GitHub Snippet**: Insert the snippet block, provide a GitHub URL and a snippet tag (e.g., "BaseOAuthExample"), and the integration will extract and display only the code between the `--8<-- [start:tag]` and `--8<-- [end:tag]` markers. # Configure @@ -31,6 +33,9 @@ blocks: description: Insert a GitHub file as a code block urlUnfurl: - https://github.com/** + - id: github-snippet-block + title: GitHub Snippet + description: Insert a GitHub file snippet using tags configurations: account: properties: diff --git a/integrations/github-files/src/github.ts b/integrations/github-files/src/github.ts index c0f81edef..cb7ef7b98 100644 --- a/integrations/github-files/src/github.ts +++ b/integrations/github-files/src/github.ts @@ -1,5 +1,5 @@ import { ExposableError } from '@gitbook/runtime'; -import { GithubInstallationConfiguration, GithubRuntimeContext } from './types'; +import { GithubInstallationConfiguration, GithubRuntimeContext, GithubSnippetProps } from './types'; export interface GithubProps { url: string; @@ -66,6 +66,31 @@ const getLinesFromGithubFile = (content: string[], lines: number[]) => { return content.slice(lines[0] - 1, lines[1]); }; +const extractSnippetSection = (content: string, snippetTag: string) => { + const lines = content.split('\n'); + const startMarker = `--8<-- [start:${snippetTag}]`; + const endMarker = `--8<-- [end:${snippetTag}]`; + + let startIndex = -1; + let endIndex = -1; + + for (let i = 0; i < lines.length; i++) { + const line = lines[i].trim(); + if (line.includes(startMarker)) { + startIndex = i + 1; // Start from the line after the marker + } else if (line.includes(endMarker) && startIndex !== -1) { + endIndex = i; // End at the line before the marker + break; + } + } + + if (startIndex === -1 || endIndex === -1) { + return null; // Snippet tag not found + } + + return lines.slice(startIndex, endIndex).join('\n'); +}; + const getHeaders = (authorise: boolean, accessToken = '') => { const headers: { 'User-Agent': string; Authorization?: string } = { 'User-Agent': 'request', @@ -144,3 +169,36 @@ export const getGithubContent = async (url: string, context: GithubRuntimeContex return { content, fileName: urlObject.fileName }; }; + +export const getGithubSnippetContent = async (url: string, snippetTag: string, context: GithubRuntimeContext) => { + const urlObject = splitGithubUrl(url); + if (!urlObject) { + return; + } + + let content: string | boolean = ''; + const configuration = context.environment.installation + ?.configuration as GithubInstallationConfiguration; + const accessToken = configuration.oauth_credentials?.access_token; + if (!accessToken) { + throw new ExposableError('Integration is not authenticated with GitHub'); + } + + content = await fetchGithubFile( + urlObject.orgName, + urlObject.repoName, + urlObject.fileName, + urlObject.ref, + accessToken, + ); + + if (content && snippetTag) { + const snippetContent = extractSnippetSection(content, snippetTag); + if (snippetContent === null) { + throw new ExposableError(`Snippet tag '${snippetTag}' not found in file`); + } + content = snippetContent; + } + + return { content, fileName: urlObject.fileName }; +}; diff --git a/integrations/github-files/src/index.tsx b/integrations/github-files/src/index.tsx index 36d4bf1d3..48d979ec8 100644 --- a/integrations/github-files/src/index.tsx +++ b/integrations/github-files/src/index.tsx @@ -9,8 +9,8 @@ import { FetchEventCallback, } from '@gitbook/runtime'; -import { getGithubContent, GithubProps } from './github'; -import { GithubRuntimeContext } from './types'; +import { getGithubContent, getGithubSnippetContent, GithubProps } from './github'; +import { GithubRuntimeContext, GithubSnippetProps } from './types'; import { getFileExtension } from './utils'; const embedBlock = createComponent< @@ -130,6 +130,158 @@ const embedBlock = createComponent< }, }); +const snippetBlock = createComponent< + { url?: string; snippetTag?: string }, + { visible: boolean }, + { + action: 'show' | 'hide' | 'updateUrl' | 'updateSnippetTag'; + url?: string; + snippetTag?: string; + }, + GithubRuntimeContext +>({ + componentId: 'github-snippet-block', + initialState: { + visible: true, + }, + + async action(element, action) { + switch (action.action) { + case 'updateUrl': { + return { + props: { + ...element.props, + url: action.url, + }, + }; + } + case 'updateSnippetTag': { + return { + props: { + ...element.props, + snippetTag: action.snippetTag, + }, + }; + } + case 'show': { + return { state: { visible: true } }; + } + case 'hide': { + return { state: { visible: false } }; + } + } + + return element; + }, + + async render(element, context) { + const { url, snippetTag } = element.props as GithubSnippetProps; + + if (!url || !snippetTag) { + return ( + + } + onValueChange={{ + action: 'updateUrl', + url: { bind: 'value' }, + }} + value={url} + /> + } + onValueChange={{ + action: 'updateSnippetTag', + snippetTag: { bind: 'value' }, + }} + value={snippetTag} + /> + + ); + } + + const found = await getGithubSnippetContent(url, snippetTag, context); + + if (!found) { + return ( + + + ) : undefined + } + /> + + ); + } + + const { content, fileName } = found; + const fileExtension = await getFileExtension(fileName); + + return ( + + + ) : undefined + } + > + {content ? ( + + ) : null} + + + ); + }, +}); + const handleFetchEvent: FetchEventCallback = async (request, context) => { const { environment } = context; @@ -187,5 +339,5 @@ const extractCredentials = async ( export default createIntegration({ fetch: handleFetchEvent, - components: [embedBlock], + components: [embedBlock, snippetBlock], }); diff --git a/integrations/github-files/src/types.ts b/integrations/github-files/src/types.ts index 5e194eb27..e58b46366 100644 --- a/integrations/github-files/src/types.ts +++ b/integrations/github-files/src/types.ts @@ -6,5 +6,10 @@ export interface GithubInstallationConfiguration { }; } -export type GithubRuntimeEnvironment = RuntimeEnvironment; +export interface GithubSnippetProps { + url: string; + snippetTag?: string; +} + +export type GithubRuntimeEnvironment = RuntimeEnvironment; export type GithubRuntimeContext = RuntimeContext; From e322f97c9111750af1b7cda487187d86084d7814 Mon Sep 17 00:00:00 2001 From: Nicholas Tindle Date: Wed, 28 May 2025 13:41:14 -0500 Subject: [PATCH 02/12] Revert "feat: add snippets to github files" This reverts commit adc86130923196de7637cb1c55d25278aa6bcc2f. --- .../github-files/gitbook-manifest.yaml | 9 +- integrations/github-files/src/github.ts | 60 +------ integrations/github-files/src/index.tsx | 158 +----------------- integrations/github-files/src/types.ts | 7 +- 4 files changed, 7 insertions(+), 227 deletions(-) diff --git a/integrations/github-files/gitbook-manifest.yaml b/integrations/github-files/gitbook-manifest.yaml index 8c2aeaa3c..1937af070 100644 --- a/integrations/github-files/gitbook-manifest.yaml +++ b/integrations/github-files/gitbook-manifest.yaml @@ -12,15 +12,13 @@ externalLinks: summary: | # Overview - The GitHub Files integration allows you to take a link to a GitHub file or a permalink to lines of code and display them into code blocks in GitBook. It also supports snippet tags for extracting specific code sections. + The GitHub Files integration allows you to take a link to a GitHub file or a permalink to lines of code and display them into code blocks in GitBook. # How it works After installing the GitHub Files integration, you're able to insert it into a GitBook file in the (CMD + /) menu. - **GitHub Files**: Insert the integration, paste your link, and the integration will display the code in a formatted code block. - - **GitHub Snippet**: Insert the snippet block, provide a GitHub URL and a snippet tag (e.g., "BaseOAuthExample"), and the integration will extract and display only the code between the `--8<-- [start:tag]` and `--8<-- [end:tag]` markers. + Insert the integration, paste your link, and the integration will display the code in a formatted code block. # Configure @@ -33,9 +31,6 @@ blocks: description: Insert a GitHub file as a code block urlUnfurl: - https://github.com/** - - id: github-snippet-block - title: GitHub Snippet - description: Insert a GitHub file snippet using tags configurations: account: properties: diff --git a/integrations/github-files/src/github.ts b/integrations/github-files/src/github.ts index cb7ef7b98..c0f81edef 100644 --- a/integrations/github-files/src/github.ts +++ b/integrations/github-files/src/github.ts @@ -1,5 +1,5 @@ import { ExposableError } from '@gitbook/runtime'; -import { GithubInstallationConfiguration, GithubRuntimeContext, GithubSnippetProps } from './types'; +import { GithubInstallationConfiguration, GithubRuntimeContext } from './types'; export interface GithubProps { url: string; @@ -66,31 +66,6 @@ const getLinesFromGithubFile = (content: string[], lines: number[]) => { return content.slice(lines[0] - 1, lines[1]); }; -const extractSnippetSection = (content: string, snippetTag: string) => { - const lines = content.split('\n'); - const startMarker = `--8<-- [start:${snippetTag}]`; - const endMarker = `--8<-- [end:${snippetTag}]`; - - let startIndex = -1; - let endIndex = -1; - - for (let i = 0; i < lines.length; i++) { - const line = lines[i].trim(); - if (line.includes(startMarker)) { - startIndex = i + 1; // Start from the line after the marker - } else if (line.includes(endMarker) && startIndex !== -1) { - endIndex = i; // End at the line before the marker - break; - } - } - - if (startIndex === -1 || endIndex === -1) { - return null; // Snippet tag not found - } - - return lines.slice(startIndex, endIndex).join('\n'); -}; - const getHeaders = (authorise: boolean, accessToken = '') => { const headers: { 'User-Agent': string; Authorization?: string } = { 'User-Agent': 'request', @@ -169,36 +144,3 @@ export const getGithubContent = async (url: string, context: GithubRuntimeContex return { content, fileName: urlObject.fileName }; }; - -export const getGithubSnippetContent = async (url: string, snippetTag: string, context: GithubRuntimeContext) => { - const urlObject = splitGithubUrl(url); - if (!urlObject) { - return; - } - - let content: string | boolean = ''; - const configuration = context.environment.installation - ?.configuration as GithubInstallationConfiguration; - const accessToken = configuration.oauth_credentials?.access_token; - if (!accessToken) { - throw new ExposableError('Integration is not authenticated with GitHub'); - } - - content = await fetchGithubFile( - urlObject.orgName, - urlObject.repoName, - urlObject.fileName, - urlObject.ref, - accessToken, - ); - - if (content && snippetTag) { - const snippetContent = extractSnippetSection(content, snippetTag); - if (snippetContent === null) { - throw new ExposableError(`Snippet tag '${snippetTag}' not found in file`); - } - content = snippetContent; - } - - return { content, fileName: urlObject.fileName }; -}; diff --git a/integrations/github-files/src/index.tsx b/integrations/github-files/src/index.tsx index 48d979ec8..36d4bf1d3 100644 --- a/integrations/github-files/src/index.tsx +++ b/integrations/github-files/src/index.tsx @@ -9,8 +9,8 @@ import { FetchEventCallback, } from '@gitbook/runtime'; -import { getGithubContent, getGithubSnippetContent, GithubProps } from './github'; -import { GithubRuntimeContext, GithubSnippetProps } from './types'; +import { getGithubContent, GithubProps } from './github'; +import { GithubRuntimeContext } from './types'; import { getFileExtension } from './utils'; const embedBlock = createComponent< @@ -130,158 +130,6 @@ const embedBlock = createComponent< }, }); -const snippetBlock = createComponent< - { url?: string; snippetTag?: string }, - { visible: boolean }, - { - action: 'show' | 'hide' | 'updateUrl' | 'updateSnippetTag'; - url?: string; - snippetTag?: string; - }, - GithubRuntimeContext ->({ - componentId: 'github-snippet-block', - initialState: { - visible: true, - }, - - async action(element, action) { - switch (action.action) { - case 'updateUrl': { - return { - props: { - ...element.props, - url: action.url, - }, - }; - } - case 'updateSnippetTag': { - return { - props: { - ...element.props, - snippetTag: action.snippetTag, - }, - }; - } - case 'show': { - return { state: { visible: true } }; - } - case 'hide': { - return { state: { visible: false } }; - } - } - - return element; - }, - - async render(element, context) { - const { url, snippetTag } = element.props as GithubSnippetProps; - - if (!url || !snippetTag) { - return ( - - } - onValueChange={{ - action: 'updateUrl', - url: { bind: 'value' }, - }} - value={url} - /> - } - onValueChange={{ - action: 'updateSnippetTag', - snippetTag: { bind: 'value' }, - }} - value={snippetTag} - /> - - ); - } - - const found = await getGithubSnippetContent(url, snippetTag, context); - - if (!found) { - return ( - - - ) : undefined - } - /> - - ); - } - - const { content, fileName } = found; - const fileExtension = await getFileExtension(fileName); - - return ( - - - ) : undefined - } - > - {content ? ( - - ) : null} - - - ); - }, -}); - const handleFetchEvent: FetchEventCallback = async (request, context) => { const { environment } = context; @@ -339,5 +187,5 @@ const extractCredentials = async ( export default createIntegration({ fetch: handleFetchEvent, - components: [embedBlock, snippetBlock], + components: [embedBlock], }); diff --git a/integrations/github-files/src/types.ts b/integrations/github-files/src/types.ts index e58b46366..5e194eb27 100644 --- a/integrations/github-files/src/types.ts +++ b/integrations/github-files/src/types.ts @@ -6,10 +6,5 @@ export interface GithubInstallationConfiguration { }; } -export interface GithubSnippetProps { - url: string; - snippetTag?: string; -} - -export type GithubRuntimeEnvironment = RuntimeEnvironment; +export type GithubRuntimeEnvironment = RuntimeEnvironment; export type GithubRuntimeContext = RuntimeContext; From d514747f256aeae714a443b0f488295bc9619c91 Mon Sep 17 00:00:00 2001 From: Nicholas Tindle Date: Wed, 28 May 2025 13:38:06 -0500 Subject: [PATCH 03/12] feat: add snippets to github files Co-Authored-By: Claude <81847+claude@users.noreply.github.com> --- .../github-files/gitbook-manifest.yaml | 9 +- integrations/github-files/src/github.ts | 60 ++++++- integrations/github-files/src/index.tsx | 158 +++++++++++++++++- integrations/github-files/src/types.ts | 7 +- 4 files changed, 227 insertions(+), 7 deletions(-) diff --git a/integrations/github-files/gitbook-manifest.yaml b/integrations/github-files/gitbook-manifest.yaml index 1937af070..8c2aeaa3c 100644 --- a/integrations/github-files/gitbook-manifest.yaml +++ b/integrations/github-files/gitbook-manifest.yaml @@ -12,13 +12,15 @@ externalLinks: summary: | # Overview - The GitHub Files integration allows you to take a link to a GitHub file or a permalink to lines of code and display them into code blocks in GitBook. + The GitHub Files integration allows you to take a link to a GitHub file or a permalink to lines of code and display them into code blocks in GitBook. It also supports snippet tags for extracting specific code sections. # How it works After installing the GitHub Files integration, you're able to insert it into a GitBook file in the (CMD + /) menu. - Insert the integration, paste your link, and the integration will display the code in a formatted code block. + **GitHub Files**: Insert the integration, paste your link, and the integration will display the code in a formatted code block. + + **GitHub Snippet**: Insert the snippet block, provide a GitHub URL and a snippet tag (e.g., "BaseOAuthExample"), and the integration will extract and display only the code between the `--8<-- [start:tag]` and `--8<-- [end:tag]` markers. # Configure @@ -31,6 +33,9 @@ blocks: description: Insert a GitHub file as a code block urlUnfurl: - https://github.com/** + - id: github-snippet-block + title: GitHub Snippet + description: Insert a GitHub file snippet using tags configurations: account: properties: diff --git a/integrations/github-files/src/github.ts b/integrations/github-files/src/github.ts index c0f81edef..cb7ef7b98 100644 --- a/integrations/github-files/src/github.ts +++ b/integrations/github-files/src/github.ts @@ -1,5 +1,5 @@ import { ExposableError } from '@gitbook/runtime'; -import { GithubInstallationConfiguration, GithubRuntimeContext } from './types'; +import { GithubInstallationConfiguration, GithubRuntimeContext, GithubSnippetProps } from './types'; export interface GithubProps { url: string; @@ -66,6 +66,31 @@ const getLinesFromGithubFile = (content: string[], lines: number[]) => { return content.slice(lines[0] - 1, lines[1]); }; +const extractSnippetSection = (content: string, snippetTag: string) => { + const lines = content.split('\n'); + const startMarker = `--8<-- [start:${snippetTag}]`; + const endMarker = `--8<-- [end:${snippetTag}]`; + + let startIndex = -1; + let endIndex = -1; + + for (let i = 0; i < lines.length; i++) { + const line = lines[i].trim(); + if (line.includes(startMarker)) { + startIndex = i + 1; // Start from the line after the marker + } else if (line.includes(endMarker) && startIndex !== -1) { + endIndex = i; // End at the line before the marker + break; + } + } + + if (startIndex === -1 || endIndex === -1) { + return null; // Snippet tag not found + } + + return lines.slice(startIndex, endIndex).join('\n'); +}; + const getHeaders = (authorise: boolean, accessToken = '') => { const headers: { 'User-Agent': string; Authorization?: string } = { 'User-Agent': 'request', @@ -144,3 +169,36 @@ export const getGithubContent = async (url: string, context: GithubRuntimeContex return { content, fileName: urlObject.fileName }; }; + +export const getGithubSnippetContent = async (url: string, snippetTag: string, context: GithubRuntimeContext) => { + const urlObject = splitGithubUrl(url); + if (!urlObject) { + return; + } + + let content: string | boolean = ''; + const configuration = context.environment.installation + ?.configuration as GithubInstallationConfiguration; + const accessToken = configuration.oauth_credentials?.access_token; + if (!accessToken) { + throw new ExposableError('Integration is not authenticated with GitHub'); + } + + content = await fetchGithubFile( + urlObject.orgName, + urlObject.repoName, + urlObject.fileName, + urlObject.ref, + accessToken, + ); + + if (content && snippetTag) { + const snippetContent = extractSnippetSection(content, snippetTag); + if (snippetContent === null) { + throw new ExposableError(`Snippet tag '${snippetTag}' not found in file`); + } + content = snippetContent; + } + + return { content, fileName: urlObject.fileName }; +}; diff --git a/integrations/github-files/src/index.tsx b/integrations/github-files/src/index.tsx index 36d4bf1d3..48d979ec8 100644 --- a/integrations/github-files/src/index.tsx +++ b/integrations/github-files/src/index.tsx @@ -9,8 +9,8 @@ import { FetchEventCallback, } from '@gitbook/runtime'; -import { getGithubContent, GithubProps } from './github'; -import { GithubRuntimeContext } from './types'; +import { getGithubContent, getGithubSnippetContent, GithubProps } from './github'; +import { GithubRuntimeContext, GithubSnippetProps } from './types'; import { getFileExtension } from './utils'; const embedBlock = createComponent< @@ -130,6 +130,158 @@ const embedBlock = createComponent< }, }); +const snippetBlock = createComponent< + { url?: string; snippetTag?: string }, + { visible: boolean }, + { + action: 'show' | 'hide' | 'updateUrl' | 'updateSnippetTag'; + url?: string; + snippetTag?: string; + }, + GithubRuntimeContext +>({ + componentId: 'github-snippet-block', + initialState: { + visible: true, + }, + + async action(element, action) { + switch (action.action) { + case 'updateUrl': { + return { + props: { + ...element.props, + url: action.url, + }, + }; + } + case 'updateSnippetTag': { + return { + props: { + ...element.props, + snippetTag: action.snippetTag, + }, + }; + } + case 'show': { + return { state: { visible: true } }; + } + case 'hide': { + return { state: { visible: false } }; + } + } + + return element; + }, + + async render(element, context) { + const { url, snippetTag } = element.props as GithubSnippetProps; + + if (!url || !snippetTag) { + return ( + + } + onValueChange={{ + action: 'updateUrl', + url: { bind: 'value' }, + }} + value={url} + /> + } + onValueChange={{ + action: 'updateSnippetTag', + snippetTag: { bind: 'value' }, + }} + value={snippetTag} + /> + + ); + } + + const found = await getGithubSnippetContent(url, snippetTag, context); + + if (!found) { + return ( + + + ) : undefined + } + /> + + ); + } + + const { content, fileName } = found; + const fileExtension = await getFileExtension(fileName); + + return ( + + + ) : undefined + } + > + {content ? ( + + ) : null} + + + ); + }, +}); + const handleFetchEvent: FetchEventCallback = async (request, context) => { const { environment } = context; @@ -187,5 +339,5 @@ const extractCredentials = async ( export default createIntegration({ fetch: handleFetchEvent, - components: [embedBlock], + components: [embedBlock, snippetBlock], }); diff --git a/integrations/github-files/src/types.ts b/integrations/github-files/src/types.ts index 5e194eb27..e58b46366 100644 --- a/integrations/github-files/src/types.ts +++ b/integrations/github-files/src/types.ts @@ -6,5 +6,10 @@ export interface GithubInstallationConfiguration { }; } -export type GithubRuntimeEnvironment = RuntimeEnvironment; +export interface GithubSnippetProps { + url: string; + snippetTag?: string; +} + +export type GithubRuntimeEnvironment = RuntimeEnvironment; export type GithubRuntimeContext = RuntimeContext; From b8c0b811830f9082bcd10d8957286bc8f581452e Mon Sep 17 00:00:00 2001 From: Nicholas Tindle Date: Wed, 28 May 2025 13:43:32 -0500 Subject: [PATCH 04/12] fix: format --- integrations/github-files/src/github.ts | 14 +++++++++----- integrations/github-files/src/index.tsx | 4 +++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/integrations/github-files/src/github.ts b/integrations/github-files/src/github.ts index cb7ef7b98..e8fdb2a14 100644 --- a/integrations/github-files/src/github.ts +++ b/integrations/github-files/src/github.ts @@ -70,10 +70,10 @@ const extractSnippetSection = (content: string, snippetTag: string) => { const lines = content.split('\n'); const startMarker = `--8<-- [start:${snippetTag}]`; const endMarker = `--8<-- [end:${snippetTag}]`; - + let startIndex = -1; let endIndex = -1; - + for (let i = 0; i < lines.length; i++) { const line = lines[i].trim(); if (line.includes(startMarker)) { @@ -83,11 +83,11 @@ const extractSnippetSection = (content: string, snippetTag: string) => { break; } } - + if (startIndex === -1 || endIndex === -1) { return null; // Snippet tag not found } - + return lines.slice(startIndex, endIndex).join('\n'); }; @@ -170,7 +170,11 @@ export const getGithubContent = async (url: string, context: GithubRuntimeContex return { content, fileName: urlObject.fileName }; }; -export const getGithubSnippetContent = async (url: string, snippetTag: string, context: GithubRuntimeContext) => { +export const getGithubSnippetContent = async ( + url: string, + snippetTag: string, + context: GithubRuntimeContext, +) => { const urlObject = splitGithubUrl(url); if (!urlObject) { return; diff --git a/integrations/github-files/src/index.tsx b/integrations/github-files/src/index.tsx index 48d979ec8..52f803dc1 100644 --- a/integrations/github-files/src/index.tsx +++ b/integrations/github-files/src/index.tsx @@ -182,7 +182,9 @@ const snippetBlock = createComponent< } + element={ + + } onValueChange={{ action: 'updateUrl', url: { bind: 'value' }, From 651e2478bedb3110e0c433a359cd520f68b0fd86 Mon Sep 17 00:00:00 2001 From: Nicholas Tindle Date: Fri, 30 May 2025 17:05:31 -0500 Subject: [PATCH 05/12] feat: after testing, do some fixes Co-Authored-By: Claude <81847+claude@users.noreply.github.com> --- integrations/github-files/src/index.tsx | 74 +++++++++++++++---------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/integrations/github-files/src/index.tsx b/integrations/github-files/src/index.tsx index 52f803dc1..bab8df07c 100644 --- a/integrations/github-files/src/index.tsx +++ b/integrations/github-files/src/index.tsx @@ -101,9 +101,9 @@ const embedBlock = createComponent< onPress={ element.state.visible ? { - action: '@ui.url.open', - url, - } + action: '@ui.url.open', + url, + } : { action: 'null' } } icon={ @@ -132,7 +132,7 @@ const embedBlock = createComponent< const snippetBlock = createComponent< { url?: string; snippetTag?: string }, - { visible: boolean }, + { visible: boolean; url?: string; snippetTag?: string }, { action: 'show' | 'hide' | 'updateUrl' | 'updateSnippetTag'; url?: string; @@ -143,6 +143,8 @@ const snippetBlock = createComponent< componentId: 'github-snippet-block', initialState: { visible: true, + url: '', + snippetTag: '', }, async action(element, action) { @@ -152,6 +154,7 @@ const snippetBlock = createComponent< props: { ...element.props, url: action.url, + snippetTag: action.snippetTag, }, }; } @@ -180,31 +183,44 @@ const snippetBlock = createComponent< if (!url || !snippetTag) { return ( - - } - onValueChange={{ - action: 'updateUrl', - url: { bind: 'value' }, - }} - value={url} - /> - } - onValueChange={{ - action: 'updateSnippetTag', - snippetTag: { bind: 'value' }, - }} - value={snippetTag} - /> + + + } + /> + + } + /> +