-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
316 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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 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
9 changes: 8 additions & 1 deletion
9
apps/frontend/src/lib/components/blocks/field-control/long-text-control.svelte
This file contains 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 |
---|---|---|
@@ -1,8 +1,15 @@ | ||
<script lang="ts"> | ||
import Tiptap from "$lib/components/tiptap/tiptap.svelte" | ||
import Textarea from "$lib/components/ui/textarea/textarea.svelte" | ||
import type { LongTextField } from "@undb/table" | ||
export let field: LongTextField | ||
export let value: string | ||
export let readonly = false | ||
</script> | ||
|
||
<Textarea rows={5} bind:value {...$$restProps} on:change disabled={readonly} /> | ||
{#if field.allowRichText} | ||
<Tiptap bind:value /> | ||
{:else} | ||
<Textarea rows={5} bind:value {...$$restProps} on:change disabled={readonly} /> | ||
{/if} |
This file contains 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 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 |
---|---|---|
|
@@ -145,6 +145,7 @@ | |
if (!open) { | ||
} | ||
}} | ||
portal="body" | ||
> | ||
<Dialog.Trigger> | ||
<button> | ||
|
This file contains 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 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,92 @@ | ||
.tiptap { | ||
padding-left: 1rem; | ||
padding-right: 1rem; | ||
padding-top: 0.5rem; | ||
padding-bottom: 0.5rem; | ||
border: 1px solid hsl(var(--border)); | ||
height: 100%; | ||
|
||
:first-child { | ||
margin-top: 0; | ||
} | ||
|
||
/* List styles */ | ||
ul, | ||
ol { | ||
padding: 0 1rem; | ||
margin: 1.25rem 1rem 1.25rem 0.4rem; | ||
|
||
li p { | ||
margin-top: 0.25em; | ||
margin-bottom: 0.25em; | ||
} | ||
} | ||
|
||
/* Heading styles */ | ||
h1, | ||
h2, | ||
h3, | ||
h4, | ||
h5, | ||
h6 { | ||
line-height: 1.1; | ||
margin-top: 1rem; | ||
margin-bottom: 1rem; | ||
text-wrap: pretty; | ||
} | ||
|
||
h1 { | ||
font-size: 1.8rem; | ||
} | ||
|
||
h2 { | ||
font-size: 1.6rem; | ||
} | ||
|
||
h3 { | ||
font-size: 1.4rem; | ||
} | ||
|
||
h4, | ||
h5, | ||
h6 { | ||
font-size: 1rem; | ||
} | ||
|
||
/* Code and preformatted text styles */ | ||
code { | ||
background-color: hsl(var(--secondary)); | ||
border-radius: 0.4rem; | ||
color: var(--black); | ||
font-size: 0.85rem; | ||
padding: 0.25em 0.3em; | ||
} | ||
|
||
pre { | ||
background: var(--black); | ||
border-radius: 0.5rem; | ||
color: var(--white); | ||
font-family: 'JetBrainsMono', monospace; | ||
margin: 1.5rem 0; | ||
padding: 0.75rem 1rem; | ||
|
||
code { | ||
background: none; | ||
color: inherit; | ||
font-size: 0.8rem; | ||
padding: 0; | ||
} | ||
} | ||
|
||
blockquote { | ||
border-left: 3px solid var(--gray-3); | ||
margin: 1.5rem 0; | ||
padding-left: 1rem; | ||
} | ||
|
||
hr { | ||
border: none; | ||
border-top: 1px solid var(--gray-2); | ||
margin: 2rem 0; | ||
} | ||
} |
This file contains 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,121 @@ | ||
<script lang="ts"> | ||
import "./tiptap.css" | ||
import { onMount, onDestroy, createEventDispatcher } from "svelte" | ||
import { Editor } from "@tiptap/core" | ||
import StarterKit from "@tiptap/starter-kit" | ||
import { Button } from "../ui/button" | ||
import { cn } from "$lib/utils" | ||
import { BoldIcon, CodeIcon, ItalicIcon } from "lucide-svelte" | ||
let element: HTMLDivElement | ||
let editor: Editor | ||
export let readonly = false | ||
const dispatch = createEventDispatcher() | ||
export let value: string | undefined | ||
onMount(() => { | ||
editor = new Editor({ | ||
element: element, | ||
editable: !readonly, | ||
extensions: [StarterKit], | ||
content: value, | ||
onTransaction: () => { | ||
// force re-render so `editor.isActive` works as expected | ||
editor = editor | ||
}, | ||
onBlur(props) { | ||
const html = props.editor.getHTML() | ||
value = html | ||
dispatch("blur", html) | ||
}, | ||
onUpdate(props) { | ||
const html = props.editor.getHTML() | ||
value = html | ||
dispatch("change", html) | ||
}, | ||
}) | ||
}) | ||
onDestroy(() => { | ||
if (editor) { | ||
editor.destroy() | ||
} | ||
}) | ||
</script> | ||
|
||
{#if editor && !readonly} | ||
<div class="flex h-10 items-center justify-between"> | ||
<slot /> | ||
|
||
<div class="flex items-center gap-1"> | ||
<Button | ||
size="sm" | ||
type="button" | ||
variant={editor.isActive("bold") ? "default" : "ghost"} | ||
class="h-7 w-7 px-2" | ||
on:click={() => editor.chain().focus().toggleBold().run()} | ||
> | ||
<BoldIcon class="h-full w-full font-bold" /> | ||
</Button> | ||
<Button | ||
size="sm" | ||
type="button" | ||
variant={editor.isActive("italic") ? "default" : "ghost"} | ||
class="h-7 w-7 px-2" | ||
on:click={() => editor.chain().focus().toggleItalic().run()} | ||
> | ||
<ItalicIcon class="h-full w-full" /> | ||
</Button> | ||
<Button | ||
size="sm" | ||
type="button" | ||
variant={editor.isActive("code") ? "default" : "ghost"} | ||
class="h-7 w-7 px-2" | ||
on:click={() => editor.chain().focus().toggleCode().run()} | ||
> | ||
<CodeIcon class="h-full w-full" /> | ||
</Button> | ||
<Button | ||
size="sm" | ||
type="button" | ||
variant={editor.isActive("heading", { level: 1 }) ? "default" : "ghost"} | ||
class="h-7 w-7" | ||
on:click={() => editor.chain().focus().toggleHeading({ level: 1 }).run()} | ||
> | ||
H1 | ||
</Button> | ||
<Button | ||
size="sm" | ||
type="button" | ||
on:click={() => editor.chain().focus().toggleHeading({ level: 2 }).run()} | ||
variant={editor.isActive("heading", { level: 2 }) ? "default" : "ghost"} | ||
class="h-7 w-7" | ||
> | ||
H2 | ||
</Button> | ||
<Button | ||
size="sm" | ||
type="button" | ||
on:click={() => editor.chain().focus().toggleHeading({ level: 3 }).run()} | ||
variant={editor.isActive("heading", { level: 3 }) ? "default" : "ghost"} | ||
class="h-7 w-7" | ||
> | ||
H3 | ||
</Button> | ||
<Button | ||
size="sm" | ||
type="button" | ||
on:click={() => editor.chain().focus().setParagraph().run()} | ||
variant={editor.isActive("paragraph") ? "default" : "ghost"} | ||
class="h-7 w-7" | ||
> | ||
P | ||
</Button> | ||
</div> | ||
</div> | ||
{/if} | ||
|
||
<div class={$$restProps.class} bind:this={element} /> |
Oops, something went wrong.