|
2 | 2 | import { browser } from '$app/environment'; |
3 | 3 | import type { Content, Editor } from '@tiptap/core'; |
4 | 4 | import type { Transaction } from '@tiptap/pm/state'; |
5 | | - import { Checkbox } from '$lib/components/ui/checkbox/index.js'; |
6 | | - import { Label } from '$lib/components/ui/label/index.js'; |
7 | 5 | import { cn } from '$lib/utils.js'; |
8 | 6 | import GridPattern from '$lib/components/custom/grid-pattern.svelte'; |
9 | | - import { Button, buttonVariants } from '$lib/components/ui/button/index.js'; |
| 7 | + import { Button } from '$lib/components/ui/button/index.js'; |
10 | 8 | import Document from 'lucide-svelte/icons/file-text'; |
11 | 9 | import GitHub from 'lucide-svelte/icons/github'; |
12 | | - import * as Dialog from '$lib/components/ui/dialog/index.js'; |
13 | | - import FileJson from 'lucide-svelte/icons/file-json'; |
14 | | - import ShikiCode from '$lib/components/custom/shiki-code.svelte'; |
15 | | - import { toast } from 'svelte-sonner'; |
16 | | - import { Edra, EdraToolbar } from '$lib/edra/shadcn/index.js'; |
| 10 | + import { Edra, EdraToolbar, EdraBubbleMenu } from '$lib/edra/shadcn/index.js'; |
17 | 11 | import { slide } from 'svelte/transition'; |
18 | 12 | import defaultContent from '$lib/default_content.js'; |
| 13 | + import DemoEditorSettings from '$lib/components/custom/demo-editor-settings.svelte'; |
| 14 | + import EditorOutput from '$lib/components/custom/editor-output.svelte'; |
19 | 15 |
|
20 | 16 | let content = $state<Content>(); |
21 | 17 | let editor = $state<Editor>(); |
|
26 | 22 | }); |
27 | 23 |
|
28 | 24 | let showToolBar = $state(true); |
29 | | - let showMenu = $state(true); |
| 25 | + let showBubbleMenus = $state(true); |
| 26 | + let editable = $state(true); |
| 27 | +
|
| 28 | + $effect(() => { |
| 29 | + console.log('editable', editable); |
| 30 | + editor?.setEditable(editable); |
| 31 | + }); |
30 | 32 |
|
31 | 33 | if (browser) { |
32 | 34 | const rawDataString = localStorage.getItem('edra-content'); |
|
74 | 76 | </Button> |
75 | 77 | </div> |
76 | 78 | <div class="size-full *:my-2"> |
| 79 | + <div class="text-center text-xl font-bold">Explore Demo</div> |
77 | 80 | <div class="flex flex-col items-center justify-center gap-4 sm:flex-row"> |
78 | | - <div class="flex items-center gap-2"> |
79 | | - <Checkbox id="toolbar" bind:checked={showToolBar} /> |
80 | | - <Label for="toolbar" class="text-sm font-medium leading-none">Show Editor Toolbar</Label> |
81 | | - </div> |
82 | | - <div class="flex items-center gap-2"> |
83 | | - <Checkbox id="menus" bind:checked={showMenu} /> |
84 | | - <Label for="menus" class="text-sm font-medium leading-none">Show Editor Menus</Label> |
85 | | - </div> |
86 | | - <Dialog.Root> |
87 | | - <Dialog.Trigger class={buttonVariants({ variant: 'outline' })}> |
88 | | - <FileJson /> Show Output |
89 | | - </Dialog.Trigger> |
90 | | - <Dialog.Content class="h-[95%] w-[95vw] sm:h-[80%] sm:min-w-[50%]"> |
91 | | - <Dialog.Header> |
92 | | - <Dialog.Title>JSON Output</Dialog.Title> |
93 | | - <Dialog.Description>Observe the JSON output of the editor content</Dialog.Description> |
94 | | - </Dialog.Header> |
95 | | - {@const stringContent = JSON.stringify(content, null, 2)} |
96 | | - <ShikiCode class="size-full overflow-auto" code={stringContent} lang="json" /> |
97 | | - <Button |
98 | | - variant="outline" |
99 | | - class="ml-auto w-fit" |
100 | | - onclick={() => { |
101 | | - navigator.clipboard.writeText(stringContent); |
102 | | - toast.success(`Copied to clipboard`); |
103 | | - }}>Copy JSON Output</Button |
104 | | - > |
105 | | - </Dialog.Content> |
106 | | - </Dialog.Root> |
| 81 | + <DemoEditorSettings bind:showToolBar bind:showBubbleMenus bind:editable /> |
| 82 | + <EditorOutput code={JSON.stringify(content, null, 2)} /> |
107 | 83 | </div> |
108 | 84 | </div> |
109 | 85 | </div> |
110 | 86 | <div class="m-auto flex h-[35rem] w-[95%] flex-col rounded border sm:w-[85%]"> |
111 | | - {#if editor && showToolBar} |
112 | | - <div transition:slide> |
113 | | - <EdraToolbar {editor} /> |
114 | | - </div> |
| 87 | + {#if editor} |
| 88 | + {#if showToolBar} |
| 89 | + <div transition:slide> |
| 90 | + <EdraToolbar {editor} /> |
| 91 | + </div> |
| 92 | + {/if} |
| 93 | + <EdraBubbleMenu {editor} /> |
115 | 94 | {/if} |
116 | | - <Edra class="overflow-auto" bind:editor {showMenu} {content} {onUpdate} /> |
| 95 | + <Edra class="overflow-auto" bind:editor {editable} {showBubbleMenus} {content} {onUpdate} /> |
117 | 96 | </div> |
118 | 97 | </div> |
119 | 98 |
|
|
0 commit comments