|
@@ -3,9 +3,13 @@ import { BaseText } from 'slate';
|
|
import { useCallback, useRef } from 'react';
|
|
import { useCallback, useRef } from 'react';
|
|
import { converToIndexLength } from '$app/utils/document/slate_editor';
|
|
import { converToIndexLength } from '$app/utils/document/slate_editor';
|
|
import TemporaryInput from '$app/components/document/_shared/TemporaryInput';
|
|
import TemporaryInput from '$app/components/document/_shared/TemporaryInput';
|
|
-import InlineContainer from '$app/components/document/_shared/InlineBlock/InlineContainer';
|
|
|
|
|
|
+import FormulaInline from '$app/components/document/_shared/InlineBlock/FormulaInline';
|
|
import { TemporaryType } from '$app/interfaces/document';
|
|
import { TemporaryType } from '$app/interfaces/document';
|
|
import LinkInline from '$app/components/document/_shared/InlineBlock/LinkInline';
|
|
import LinkInline from '$app/components/document/_shared/InlineBlock/LinkInline';
|
|
|
|
+import { MentionType } from '$app_reducers/document/async-actions/mention';
|
|
|
|
+import PageInline from '$app/components/document/_shared/InlineBlock/PageInline';
|
|
|
|
+import { FakeCursorContainer } from '$app/components/document/_shared/InlineBlock/FakeCursorContainer';
|
|
|
|
+import CodeInline from '$app/components/document/_shared/InlineBlock/CodeInline';
|
|
|
|
|
|
interface Attributes {
|
|
interface Attributes {
|
|
bold?: boolean;
|
|
bold?: boolean;
|
|
@@ -20,6 +24,7 @@ interface Attributes {
|
|
formula?: string;
|
|
formula?: string;
|
|
font_color?: string;
|
|
font_color?: string;
|
|
bg_color?: string;
|
|
bg_color?: string;
|
|
|
|
+ mention?: Record<string, string>;
|
|
}
|
|
}
|
|
interface TextLeafProps extends RenderLeafProps {
|
|
interface TextLeafProps extends RenderLeafProps {
|
|
leaf: BaseText & Attributes;
|
|
leaf: BaseText & Attributes;
|
|
@@ -30,7 +35,10 @@ interface TextLeafProps extends RenderLeafProps {
|
|
const TextLeaf = (props: TextLeafProps) => {
|
|
const TextLeaf = (props: TextLeafProps) => {
|
|
const { attributes, children, leaf, isCodeBlock, editor } = props;
|
|
const { attributes, children, leaf, isCodeBlock, editor } = props;
|
|
const ref = useRef<HTMLSpanElement>(null);
|
|
const ref = useRef<HTMLSpanElement>(null);
|
|
|
|
+ const { isLast, text, parent } = children.props;
|
|
|
|
+ const isSelected = Boolean(leaf.selection_high_lighted);
|
|
|
|
|
|
|
|
+ const isFirst = text === parent?.children?.[0];
|
|
const customAttributes = {
|
|
const customAttributes = {
|
|
...attributes,
|
|
...attributes,
|
|
};
|
|
};
|
|
@@ -38,15 +46,9 @@ const TextLeaf = (props: TextLeafProps) => {
|
|
|
|
|
|
if (leaf.code && !leaf.temporary) {
|
|
if (leaf.code && !leaf.temporary) {
|
|
newChildren = (
|
|
newChildren = (
|
|
- <span
|
|
|
|
- className={`bg-content-blue-50 text-text-title`}
|
|
|
|
- style={{
|
|
|
|
- fontSize: '85%',
|
|
|
|
- lineHeight: 'normal',
|
|
|
|
- }}
|
|
|
|
- >
|
|
|
|
|
|
+ <CodeInline selected={isSelected} text={text}>
|
|
{newChildren}
|
|
{newChildren}
|
|
- </span>
|
|
|
|
|
|
+ </CodeInline>
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -79,34 +81,38 @@ const TextLeaf = (props: TextLeafProps) => {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- if (leaf.formula) {
|
|
|
|
- const { isLast, text, parent } = children.props;
|
|
|
|
- const temporaryType = TemporaryType.Equation;
|
|
|
|
|
|
+ if (leaf.formula && leaf.text) {
|
|
const data = { latex: leaf.formula };
|
|
const data = { latex: leaf.formula };
|
|
|
|
|
|
newChildren = (
|
|
newChildren = (
|
|
- <InlineContainer
|
|
|
|
- isLast={isLast}
|
|
|
|
- isFirst={text === parent.children[0]}
|
|
|
|
|
|
+ <FormulaInline isLast={isLast} isFirst={isFirst} getSelection={getSelection} data={data} selectedText={leaf.text}>
|
|
|
|
+ {newChildren}
|
|
|
|
+ </FormulaInline>
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const mention = leaf.mention;
|
|
|
|
+ if (mention && mention.type === MentionType.PAGE && leaf.text) {
|
|
|
|
+ newChildren = (
|
|
|
|
+ <FakeCursorContainer
|
|
getSelection={getSelection}
|
|
getSelection={getSelection}
|
|
- data={data}
|
|
|
|
- temporaryType={temporaryType}
|
|
|
|
- selectedText={leaf.text}
|
|
|
|
|
|
+ isFirst={isFirst}
|
|
|
|
+ isLast={isLast}
|
|
|
|
+ renderNode={() => <PageInline pageId={mention.page} />}
|
|
>
|
|
>
|
|
{newChildren}
|
|
{newChildren}
|
|
- </InlineContainer>
|
|
|
|
|
|
+ </FakeCursorContainer>
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
const className = [
|
|
const className = [
|
|
isCodeBlock && 'token',
|
|
isCodeBlock && 'token',
|
|
leaf.prism_token && leaf.prism_token,
|
|
leaf.prism_token && leaf.prism_token,
|
|
- leaf.strikethrough && 'line-through',
|
|
|
|
- leaf.selection_high_lighted && 'bg-content-blue-100',
|
|
|
|
- leaf.code && !leaf.temporary && 'inline-code',
|
|
|
|
|
|
+ isSelected && 'bg-content-blue-100',
|
|
leaf.bold && 'font-bold',
|
|
leaf.bold && 'font-bold',
|
|
leaf.italic && 'italic',
|
|
leaf.italic && 'italic',
|
|
leaf.underline && 'underline',
|
|
leaf.underline && 'underline',
|
|
|
|
+ leaf.strikethrough && 'line-through',
|
|
].filter(Boolean);
|
|
].filter(Boolean);
|
|
|
|
|
|
if (leaf.temporary) {
|
|
if (leaf.temporary) {
|