Skip to content

Commit

Permalink
fix: polished Codeblock style
Browse files Browse the repository at this point in the history
  • Loading branch information
lynhan318 committed Apr 12, 2024
1 parent a1c43f0 commit e35214c
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 21 deletions.
1 change: 1 addition & 0 deletions packages/svelte/src/lib/Editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
emptyNodeClass: 'is-block-empty'
}
},
//@ts-ignore
extensions: [
LinkExtension,
HighlightExtension,
Expand Down
14 changes: 14 additions & 0 deletions packages/svelte/src/lib/EditorTheme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,17 @@
text-decoration: var(--shiki-dark-text-decoration) !important;
}
}

.clean-scroll::-webkit-scrollbar-thumb:hover {
background-color: theme('colors.slate.300');
}
.clean-scroll::-webkit-scrollbar {
width: 8px;
}
.clean-scroll::-webkit-scrollbar-track {
background-color: transparent;
}
.clean-scroll::-webkit-scrollbar-thumb {
background-color: theme('colors.slate.200');
border-radius: 8px;
}
5 changes: 4 additions & 1 deletion packages/svelte/src/lib/plugins/bubbleMenu/bubbleMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ class BubbleMenuView {
this.floatingRenderer = new FloatingRenderer({
editor: editor,
component: component,
portal: view.dom.parentElement!
portal: view.dom.parentElement!,
style: {
zIndex: '99'
}
});

this.floatingRenderer.element.addEventListener(
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/lib/plugins/codeBlock/CodeBlock.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import Languages from './Languages.svelte';
import {type NextlintCodeBlockAttrs} from './codeBlock';
import type {NextlintCodeBlockAttrs} from './codeBlock';
import {getHighlighter} from '.';
const contentRef = useContentRef();
Expand Down
20 changes: 13 additions & 7 deletions packages/svelte/src/lib/plugins/codeBlock/Languages.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import {derived} from 'svelte/store';
import {NextlintCodeBlock} from './codeBlock';
import {cn} from '$lib/helpers';
const props = useNodeViewProps();
Expand Down Expand Up @@ -43,8 +44,13 @@
<div class="relative">
<input
use:melt={$input}
class="flex h-10 items-center justify-between rounded-lg bg-background
px-4 pr-6 text-primary border border-border outline-none text-sm"
class={cn(
`flex h-8 items-center justify-between rounded-sm px-4 pr-6 outline-none text-sm
text-foreground capitalize bg-[unset] border border-transparent focus:border-border`,
{
'border-border': $inputValue
}
)}
placeholder="Programing Language"
/>
<div class="absolute right-2 top-1/2 z-10 -translate-y-1/2 text-border">
Expand All @@ -58,13 +64,13 @@
</div>
{#if $open}
<ul
class=" z-10 flex max-h-[300px] flex-col overflow-hidden rounded-lg shadow-md"
class=" z-10 flex max-h-[300px] flex-col overflow-hiddenshadow-md shadown-md p-1"
use:melt={$menu}
transition:fly={{duration: 150, y: -5}}
>
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
<div
class="flex max-h-full flex-col gap-0 overflow-y-auto bg-white px-2 py-2 text-black"
class="flex max-h-full flex-col gap-1 overflow-y-auto clean-scroll bg-background border border-accent px-2 py-2 text-foreground rounded-lg p-1"
tabindex="0"
>
{#each filteredLanguages as lang, index (index)}
Expand All @@ -74,17 +80,17 @@
label: lang
})}
class="flex flex-row items-center justify-between cursor-pointer
rounded-md py-2 pl-4 pr-4 data-[highlighted]:bg-accent
rounded-md py-1 pl-4 pr-4 data-[highlighted]:bg-accent
data-[highlighted]:text-accent-foreground data-[disabled]:opacity-50"
>
<span class="font-medium">{lang}</span>
<span class="font-medium capitalize">{lang}</span>
{#if $isSelected(lang)}
<Check size={16} />
{/if}
</li>
{:else}
<li
class="relative cursor-pointer rounded-md py-1 pl-8 pr-4
class="relative cursor-pointer rounded-md py-[2px] pl-8 pr-4
data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground"
>
No results found
Expand Down
5 changes: 0 additions & 5 deletions packages/svelte/src/routes/$components/Devtool.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,4 @@
>{theme}</span
>
</label>
<div class="ml-4">
<a href="/draft">Draft</a>
<button on:click={onSave}>save</button>
<button on:click={load}>load</button>
</div>
</div>
29 changes: 22 additions & 7 deletions packages/svelte/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import SvelteEditor from '$lib/Editor.svelte';
import {getContext} from 'svelte';
import {getContext, onDestroy, onMount} from 'svelte';
import type {Writable} from 'svelte/store';
import {svelteEditorToHtml} from '$lib/helpers';
import test from './test.json';
import {debounce} from 'radash';
const editor: Writable<Editor> = getContext('editor');
Expand All @@ -25,15 +25,30 @@ This is NOT a component library. It's a collection of re-usable components that
const previewUrl = URL.createObjectURL(blob);
return previewUrl;
};
</script>
const saveDraft = debounce({delay: 500}, (editor: Editor) => {
const jsContent = editor.getJSON();
localStorage.setItem('draft', JSON.stringify(jsContent));
});
const dispose = editor.subscribe(updated => {
if (updated) {
saveDraft(updated);
}
});
<button on:click={() => toHtml()}>To HTML</button>
onDestroy(dispose);
</script>

<div>
<div class="mt-10">
<SvelteEditor
content={test}
content={''}
placeholder="Press 'space' GPT support, type '/' for help"
onCreated={editor.set}
onCreated={createdEditor => {
editor.set(createdEditor);
const jsonLoaded = localStorage.getItem('draft') || '';
if (jsonLoaded) {
createdEditor.commands.setContent(JSON.parse(jsonLoaded), false);
}
}}
onChange={editor.set}
plugins={{
image: {
Expand Down

0 comments on commit e35214c

Please sign in to comment.