Skip to content
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

fix: add css scope in appflowy editor #8

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dev/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>AppFlowy Web Editor Demo</title>
</head>
<body>
<body id="appflowy-editor">
<div id="root"></div>
<script type="module" src="./main.tsx"></script>
</body>
Expand Down
2 changes: 2 additions & 0 deletions src/editor/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useContext, useEffect, useMemo } from 'react';
import { EditorProps } from '@/types';
import '@/styles/index.scss';
import '@/styles/editor.scss';
import { initI18n, EditorI18nContext } from '@/i18n/config';
import { addResourceBundle, changeLanguage } from '@/i18n';
import RichText from './RichText';
Expand Down Expand Up @@ -61,6 +62,7 @@ export function Editor({
return (
<EditorI18nContext.Provider value={editorI18n}>
<div
id={'appflowy-editor'}
className="appflowy-editor flex flex-col selection:bg-selection w-full text-foreground overflow-hidden">
<RichText ToolbarComponent={ToolbarComponent} editor={context.editor} onChange={handleChange}
initialValue={value} readOnly={readOnly}/>
Expand Down
123 changes: 123 additions & 0 deletions src/styles/editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
.appflowy-editor {
@apply h-full overflow-hidden;
[role="textbox"] {
@apply flex-1 overflow-auto;
}

div[data-slate-node="element"]:not([data-block-type="nested-block"]) {
@apply py-1 relative whitespace-pre-wrap break-words;
}

div[data-slate-node="element"] div[data-slate-placeholder="true"] {
@apply leading-[2em];
}


div[data-slate-node="element"] > div[data-slate-node="element"] {
padding-left: 1.5em;
}

div[data-slate-node="element"] > div[data-slate-node="element"]:first-child {
padding-left: 0;
}

div[data-block-type="heading"][data-level="1"] {
@apply py-[8px] text-[2rem] max-md:text-[24px] font-semibold;
}


div[data-block-type="heading"][data-level="2"] {
@apply py-[6px] text-[1.75rem] max-md:text-[22px] font-semibold;
}

div[data-block-type="heading"][data-level="3"] {
@apply py-[4px] text-[1.5rem] max-md:text-[20px] font-semibold;
}

div[data-block-type="heading"][data-level="4"] {
@apply py-[4px] text-[1.25rem] max-md:text-[16px] font-semibold;
}

div[data-block-type="heading"][data-level="5"] {
@apply py-[2px] text-[1.125rem] font-semibold;
}

div[data-block-type="heading"][data-level="6"] {
@apply py-[2px] text-[1rem] font-semibold;
}


div[data-block-type="todo_list"][data-checked="true"] {
text-decoration: line-through;
color: hsl(var(--muted-foreground));

.text-color span {
color: hsl(var(--muted-foreground));
}

}
}


@keyframes dots-loading {
20% {
background-position: 0% 0%, 50% 50%, 100% 50%;
}
40% {
background-position: 0% 100%, 50% 0%, 100% 50%;
}
60% {
background-position: 0% 50%, 50% 100%, 100% 0%;
}
80% {
background-position: 0% 50%, 50% 50%, 100% 100%;
}
}

.appflowy-editor {
table {
&.row-header-hl {
tbody > tr:first-child {
td [data-slate-node="text"] {
@apply font-semibold;
}
}
}

tr {
vertical-align: top;
}

tr td:first-child {
@apply border-l border-t border-border;
}

tr:first-child > td {
@apply border-t border-border;
}

td {
@apply border-r p-2 border-b border-border whitespace-pre-wrap break-words;
}
}
}


@mixin scrollbar-style {
::-webkit-scrollbar, &::-webkit-scrollbar {
width: 8px;
height: 8px;
}

&:hover {

&::-webkit-scrollbar-thumb, & *::-webkit-scrollbar-thumb {
border-radius: 4px;
background-color: var(--scrollbar-thumb);
}
}
}

.appflowy-scrollbar {
@include scrollbar-style;
}
122 changes: 0 additions & 122 deletions src/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -123,126 +123,4 @@
}


.appflowy-editor {
@apply h-full overflow-hidden;
[role="textbox"] {
@apply flex-1 overflow-auto;
}

div[data-slate-node="element"]:not([data-block-type="nested-block"]) {
@apply py-1 relative whitespace-pre-wrap break-words;
}

div[data-slate-node="element"] div[data-slate-placeholder="true"] {
@apply leading-[2em];
}


div[data-slate-node="element"] > div[data-slate-node="element"] {
padding-left: 1.5em;
}

div[data-slate-node="element"] > div[data-slate-node="element"]:first-child {
padding-left: 0;
}

div[data-block-type="heading"][data-level="1"] {
@apply py-[8px] text-[2rem] max-md:text-[24px] font-semibold;
}


div[data-block-type="heading"][data-level="2"] {
@apply py-[6px] text-[1.75rem] max-md:text-[22px] font-semibold;
}

div[data-block-type="heading"][data-level="3"] {
@apply py-[4px] text-[1.5rem] max-md:text-[20px] font-semibold;
}

div[data-block-type="heading"][data-level="4"] {
@apply py-[4px] text-[1.25rem] max-md:text-[16px] font-semibold;
}

div[data-block-type="heading"][data-level="5"] {
@apply py-[2px] text-[1.125rem] font-semibold;
}

div[data-block-type="heading"][data-level="6"] {
@apply py-[2px] text-[1rem] font-semibold;
}


div[data-block-type="todo_list"][data-checked="true"] {
text-decoration: line-through;
color: hsl(var(--muted-foreground));

.text-color span {
color: hsl(var(--muted-foreground));
}

}
}


@keyframes dots-loading {
20% {
background-position: 0% 0%, 50% 50%, 100% 50%;
}
40% {
background-position: 0% 100%, 50% 0%, 100% 50%;
}
60% {
background-position: 0% 50%, 50% 100%, 100% 0%;
}
80% {
background-position: 0% 50%, 50% 50%, 100% 100%;
}
}

.appflowy-editor {
table {
&.row-header-hl {
tbody > tr:first-child {
td [data-slate-node="text"] {
@apply font-semibold;
}
}
}

tr {
vertical-align: top;
}

tr td:first-child {
@apply border-l border-t border-border;
}

tr:first-child > td {
@apply border-t border-border;
}

td {
@apply border-r p-2 border-b border-border whitespace-pre-wrap break-words;
}
}
}


@mixin scrollbar-style {
::-webkit-scrollbar, &::-webkit-scrollbar {
width: 8px;
height: 8px;
}

&:hover {

&::-webkit-scrollbar-thumb, & *::-webkit-scrollbar-thumb {
border-radius: 4px;
background-color: var(--scrollbar-thumb);
}
}
}

.appflowy-scrollbar {
@include scrollbar-style;
}
1 change: 1 addition & 0 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default {
content: [
'./src/**/*.{js,jsx,ts,tsx}',
],
important: '#appflowy-editor',
darkMode: ['class', 'class'],
theme: {
extend: {
Expand Down