-
-
Notifications
You must be signed in to change notification settings - Fork 34
Open in LLM feature #753
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
Open
cycle4passion
wants to merge
10
commits into
techniq:docs-v2
Choose a base branch
from
cycle4passion:open-in-llm-component
base: docs-v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Open in LLM feature #753
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cb01a2c
Open in LLM feature
cycle4passion d11704b
removed grok
cycle4passion 9867588
open-in-llm-component
cycle4passion a5c924e
Merge branch 'docs-v2' into open-in-llm-component
cycle4passion d44d6f1
minor copy change
cycle4passion b207674
used markdown icons
cycle4passion 0b97b36
llms.txt - 3 levels
cycle4passion 9c8a128
fix spelling error
cycle4passion eb51725
another spelling fix
cycle4passion 3a91975
Change OpenLLMs.svelte to OpenWithButton.svelte
cycle4passion 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| <script lang="ts"> | ||
| import { page } from '$app/state'; | ||
| import { fly } from 'svelte/transition'; | ||
| import { Button, Dialog, Toggle, ButtonGroup, Icon, MenuItem, Menu } from 'svelte-ux'; | ||
|
|
||
| import ChevronDownIcon from '~icons/lucide/chevron-down'; | ||
| import SimpleIconsOpenai from '~icons/simple-icons/openai'; | ||
| import SimpleIconsClaude from '~icons/simple-icons/claude'; | ||
| import LucideCopyIcon from '~icons/lucide/copy'; | ||
| import LucideCodeIcon from '~icons/lucide/code'; | ||
| import SimpleIconsMarkdown from '~icons/simple-icons/markdown'; | ||
| import LucideGithub from '~icons/lucide/github'; | ||
| import Code from './Code.svelte'; | ||
|
|
||
| let { metadata = {}, example = false } = $props(); | ||
| // svelte-ignore state_referenced_locally | ||
| let isOpen = $state(example); | ||
| let openSourceModal = $state(false); | ||
| let showButtonCopied = $state(false); | ||
| const pkg = { | ||
| name: 'LayerChart', | ||
| url: 'https://layerchart.com/docs', | ||
| description: 'A charting/visualization library for Svelte 5' | ||
| }; | ||
| const pageName = page.url.href.split('/').pop(); | ||
| const llmBaseContext = `The following is a documentation page from ${pkg.name} (${pkg.description}). The page URL for "${pageName}" is ${page.url.href}. Be ready to help answer questions about this page.`; | ||
|
|
||
| const llms = $state([ | ||
| { | ||
| label: 'View Page Markdown', | ||
| icon: SimpleIconsMarkdown, | ||
| fn: () => window.open(`${page.url.href}/llms.txt`, '_self') | ||
| }, | ||
| { | ||
| lineBreakBefore: true, | ||
| label: 'Open in Claude', | ||
| icon: SimpleIconsClaude, | ||
| fn: () => window.open(generateLlmUrl('https://claude.ai/new?q='), '_blank') | ||
| }, | ||
| { | ||
| label: 'Open in ChatGPT', | ||
| icon: SimpleIconsOpenai, | ||
| fn: () => { | ||
| window.open(generateLlmUrl('https://chatgpt.com/?q='), '_blank'); | ||
| } | ||
| } | ||
| ]); | ||
|
|
||
| // Add source button if component page | ||
| // svelte-ignore state_referenced_locally | ||
| if (metadata?.source || example) { | ||
| llms.unshift({ | ||
| label: 'View Component Source', | ||
| icon: LucideCodeIcon, | ||
| fn: () => { | ||
| // show menu item, but do not open source modal when it's an example page | ||
| if (!example) openSourceModal = true; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| function copy(text: string) { | ||
| navigator.clipboard.writeText(text); | ||
| showButtonCopied = true; | ||
| setTimeout(() => { | ||
| showButtonCopied = false; | ||
| }, 2000); | ||
| } | ||
|
|
||
| function generateLlmUrl(url: string): string { | ||
| return `${url}${encodeURIComponent(llmBaseContext)}`; | ||
| } | ||
| </script> | ||
|
|
||
| <ButtonGroup variant="fill-light" size="sm" color="primary" class={example ? 'mb-40 mt-4' : ''}> | ||
| <Button | ||
| icon={LucideCopyIcon} | ||
| variant="fill-light" | ||
| size="sm" | ||
| color="primary" | ||
| onclick={async () => { | ||
| const md = await fetch(`${page.url.href}/llms.txt`).then((res) => res.text()); | ||
| copy(md); | ||
| }} | ||
| > | ||
| <span class="overflow-hidden relative inline-block" style="width: 70px; height: 1.2em;"> | ||
| {#key showButtonCopied} | ||
| <span | ||
| in:fly={{ y: showButtonCopied ? 20 : -20, duration: 500 }} | ||
| out:fly={{ y: showButtonCopied ? -20 : 20, duration: 500 }} | ||
| class="absolute inset-0 flex items-center justify-center ml-1" | ||
| > | ||
| {showButtonCopied ? 'Copied!' : 'Copy Page'} | ||
| </span> | ||
| {/key} | ||
| </span> | ||
| </Button> | ||
| <Toggle bind:on={isOpen} let:on={open} let:toggle let:toggleOff> | ||
| <Button on:click={toggle}> | ||
| <span style="transition: transform 300ms ease; transform: rotate({open ? -180 : 0}deg);"> | ||
| <ChevronDownIcon /> | ||
| </span> | ||
| <Menu {open} on:close={toggleOff} placement="bottom-start" class="z-25"> | ||
| {#each llms as llm (llm.label)} | ||
| {#if llm.lineBreakBefore} | ||
| <hr class="my-1" /> | ||
| {/if} | ||
| <MenuItem | ||
| onclick={() => { | ||
| toggleOff(); | ||
| llm.fn?.(); | ||
| }} | ||
| > | ||
| <Icon data={llm.icon} /> | ||
| {llm.label} | ||
| </MenuItem> | ||
| {/each} | ||
| </Menu> | ||
| </Button> | ||
| </Toggle> | ||
| </ButtonGroup> | ||
| <Dialog | ||
| bind:open={openSourceModal} | ||
| on:close={() => (openSourceModal = false)} | ||
| class="max-h-[98dvh] md:max-h-[90dvh] max-w-[98vw] md:max-w-[90vw] grid grid-rows-[auto_1fr_auto]" | ||
| > | ||
| <div class="grid grid-cols-[1fr_auto] gap-3 items-center p-4"> | ||
| <div class="overflow-auto"> | ||
| <div class="text-lg font-semibold">Source</div> | ||
| <div class="text-xs text-surface-content/50 truncate">{metadata?.sourceUrl}</div> | ||
| </div> | ||
|
|
||
| {#if metadata?.sourceUrl} | ||
| <Button | ||
| icon={LucideGithub} | ||
| variant="fill-light" | ||
| color="primary" | ||
| href={metadata.sourceUrl} | ||
| target="_blank" | ||
| > | ||
| View on Github | ||
| </Button> | ||
| {/if} | ||
| </div> | ||
|
|
||
| <div class="overflow-auto border-t"> | ||
| <Code | ||
| source={metadata?.source} | ||
| language={metadata?.source?.startsWith('<script') ? 'svelte' : 'js'} | ||
| /> | ||
| </div> | ||
|
|
||
| <div slot="actions"> | ||
| <Button variant="fill" color="primary">Close</Button> | ||
| </div> | ||
| </Dialog> |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cycle4passion let's call this
OpenWithButton.svelteinstead ofOpenLLMs.svelteand update the applicable imports / usage