diff --git a/editors/editoria/src/config/config.js b/editors/editoria/src/config/config.js index 7072aeab13c9c70d5f17b45059cd5bd9f521dec8..a10a5e399d5f0babefb052f069c8a1a7db5b723f 100644 --- a/editors/editoria/src/config/config.js +++ b/editors/editoria/src/config/config.js @@ -25,6 +25,7 @@ import { CodeBlockToolGroupService, TrackChangeToolGroupService, DisplayTextToolGroupService, + MathService, } from 'wax-prosemirror-services'; import { WaxSelectionPlugin } from 'wax-prosemirror-plugins'; @@ -97,5 +98,6 @@ export default { new CodeBlockToolGroupService(), new TrackChangeToolGroupService(), new DisplayTextToolGroupService(), + new MathService(), ], }; diff --git a/editors/editoria/src/layout/EditorElements.js b/editors/editoria/src/layout/EditorElements.js index 182722835e85d9acc473f553341eaf185081a75a..accd9cbc2b66e2a75b1228cf4811ba4cd0b17588 100644 --- a/editors/editoria/src/layout/EditorElements.js +++ b/editors/editoria/src/layout/EditorElements.js @@ -255,4 +255,119 @@ export default css` /* color: black; */ } } + + /* == Math Nodes ======================================== */ + + .math-node { + min-width: 1em; + min-height: 1em; + font-size: 0.95em; + font-family: 'Consolas', 'Ubuntu Mono', monospace; + cursor: auto; + .ProseMirror { + box-shadow: none; + min-height: 100%; + padding: 0; + background: #eee; + color: rgb(132, 33, 162); + } + } + + .math-node.empty-math .math-render::before { + content: '(empty)'; + color: red; + } + + .math-node .math-render.parse-error::before { + content: '(math error)'; + color: red; + cursor: help; + } + + .math-node.ProseMirror-selectednode { + outline: none; + } + + .math-node .math-src { + display: none; + color: rgb(132, 33, 162); + tab-size: 4; + } + + .math-node.ProseMirror-selectednode .math-src { + display: flex; + } + .math-node.ProseMirror-selectednode .math-render { + display: none; + } + + /* -- Inline Math --------------------------------------- */ + + math-inline { + display: inline; + white-space: nowrap; + } + + math-inline .math-render { + display: inline-block; + font-size: 0.85em; + cursor: pointer; + } + + math-inline .math-src .ProseMirror { + display: inline; + } + + math-inline .math-src::after, + math-inline .math-src::before { + content: '$'; + color: #b0b0b0; + } + + /* -- Block Math ---------------------------------------- */ + + math-display { + display: block; + } + + math-display .math-render { + display: block; + } + + math-display.ProseMirror-selectednode { + background-color: #eee; + } + + math-display .math-src .ProseMirror { + width: 100%; + display: block; + } + + math-display .math-src::after, + math-display .math-src::before { + content: '$$'; + text-align: left; + color: #b0b0b0; + } + + math-display .katex-display { + margin: 0; + } + + /* -- Selection Plugin ---------------------------------- */ + + p::selection, + p > *::selection { + background-color: #c0c0c0; + } + .katex-html *::selection { + background-color: none !important; + } + + .math-node.math-select .math-render { + background-color: #c0c0c0ff; + } + math-inline.math-select .math-render { + padding-top: 2px; + } `; diff --git a/editors/editoria/src/layout/EditoriaLayout.js b/editors/editoria/src/layout/EditoriaLayout.js index c4272033d012914a94d10901fc3e559665f95c0e..417566f11d6b4f5687f272df7fbdedaf983d0027 100644 --- a/editors/editoria/src/layout/EditoriaLayout.js +++ b/editors/editoria/src/layout/EditoriaLayout.js @@ -7,6 +7,7 @@ import { grid, th } from '@pubsweet/ui-toolkit'; import { cokoTheme } from '../theme'; import EditorElements from './EditorElements'; +import Katex from './Katex'; const divider = css` .panelGroup { @@ -79,6 +80,7 @@ const WaxSurfaceScroll = styled.div` position: absolute; /* PM styles for main content*/ ${EditorElements}; + ${Katex}; `; const EditorContainer = styled.div` @@ -117,6 +119,9 @@ const NotesAreaContainer = styled.div` position: absolute; /* PM styles for note content*/ ${EditorElements}; + .ProseMirror { + display: inline; + } `; const NotesContainer = styled.div` diff --git a/editors/editoria/src/layout/EditoriaMobileLayout.js b/editors/editoria/src/layout/EditoriaMobileLayout.js index 260bbe07a05c3cef3bdaec844bb916482d74f255..7968da4aafc50cd3d136bb4da74763735c1611b5 100644 --- a/editors/editoria/src/layout/EditoriaMobileLayout.js +++ b/editors/editoria/src/layout/EditoriaMobileLayout.js @@ -7,6 +7,7 @@ import { WaxContext, ComponentPlugin } from 'wax-prosemirror-core'; import { grid, th } from '@pubsweet/ui-toolkit'; import { cokoTheme } from '../theme'; import EditorElements from './EditorElements'; +import Katex from './Katex'; const divider = css` .panelGroup { @@ -95,6 +96,7 @@ const WaxSurfaceScroll = styled.div` position: absolute; /* PM styles for main content*/ ${EditorElements}; + ${Katex}; `; const EditorContainer = styled.div` diff --git a/editors/editoria/src/layout/Katex.js b/editors/editoria/src/layout/Katex.js new file mode 100644 index 0000000000000000000000000000000000000000..21ecafcd9084955d103c427ddd0437099c62cdba --- /dev/null +++ b/editors/editoria/src/layout/Katex.js @@ -0,0 +1,1078 @@ +import { css } from 'styled-components'; + +export default css` + /* stylelint-disable font-family-no-missing-generic-family-keyword */ + @font-face { + font-family: 'KaTeX_AMS'; + src: url(fonts/KaTeX_AMS-Regular.woff2) format('woff2'), + url(fonts/KaTeX_AMS-Regular.woff) format('woff'), + url(fonts/KaTeX_AMS-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; + } + @font-face { + font-family: 'KaTeX_Caligraphic'; + src: url(fonts/KaTeX_Caligraphic-Bold.woff2) format('woff2'), + url(fonts/KaTeX_Caligraphic-Bold.woff) format('woff'), + url(fonts/KaTeX_Caligraphic-Bold.ttf) format('truetype'); + font-weight: bold; + font-style: normal; + } + @font-face { + font-family: 'KaTeX_Caligraphic'; + src: url(fonts/KaTeX_Caligraphic-Regular.woff2) format('woff2'), + url(fonts/KaTeX_Caligraphic-Regular.woff) format('woff'), + url(fonts/KaTeX_Caligraphic-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; + } + @font-face { + font-family: 'KaTeX_Fraktur'; + src: url(fonts/KaTeX_Fraktur-Bold.woff2) format('woff2'), + url(fonts/KaTeX_Fraktur-Bold.woff) format('woff'), + url(fonts/KaTeX_Fraktur-Bold.ttf) format('truetype'); + font-weight: bold; + font-style: normal; + } + @font-face { + font-family: 'KaTeX_Fraktur'; + src: url(fonts/KaTeX_Fraktur-Regular.woff2) format('woff2'), + url(fonts/KaTeX_Fraktur-Regular.woff) format('woff'), + url(fonts/KaTeX_Fraktur-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; + } + @font-face { + font-family: 'KaTeX_Main'; + src: url(fonts/KaTeX_Main-Bold.woff2) format('woff2'), + url(fonts/KaTeX_Main-Bold.woff) format('woff'), + url(fonts/KaTeX_Main-Bold.ttf) format('truetype'); + font-weight: bold; + font-style: normal; + } + @font-face { + font-family: 'KaTeX_Main'; + src: url(fonts/KaTeX_Main-BoldItalic.woff2) format('woff2'), + url(fonts/KaTeX_Main-BoldItalic.woff) format('woff'), + url(fonts/KaTeX_Main-BoldItalic.ttf) format('truetype'); + font-weight: bold; + font-style: italic; + } + @font-face { + font-family: 'KaTeX_Main'; + src: url(fonts/KaTeX_Main-Italic.woff2) format('woff2'), + url(fonts/KaTeX_Main-Italic.woff) format('woff'), + url(fonts/KaTeX_Main-Italic.ttf) format('truetype'); + font-weight: normal; + font-style: italic; + } + @font-face { + font-family: 'KaTeX_Main'; + src: url(fonts/KaTeX_Main-Regular.woff2) format('woff2'), + url(fonts/KaTeX_Main-Regular.woff) format('woff'), + url(fonts/KaTeX_Main-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; + } + @font-face { + font-family: 'KaTeX_Math'; + src: url(fonts/KaTeX_Math-BoldItalic.woff2) format('woff2'), + url(fonts/KaTeX_Math-BoldItalic.woff) format('woff'), + url(fonts/KaTeX_Math-BoldItalic.ttf) format('truetype'); + font-weight: bold; + font-style: italic; + } + @font-face { + font-family: 'KaTeX_Math'; + src: url(fonts/KaTeX_Math-Italic.woff2) format('woff2'), + url(fonts/KaTeX_Math-Italic.woff) format('woff'), + url(fonts/KaTeX_Math-Italic.ttf) format('truetype'); + font-weight: normal; + font-style: italic; + } + @font-face { + font-family: 'KaTeX_SansSerif'; + src: url(fonts/KaTeX_SansSerif-Bold.woff2) format('woff2'), + url(fonts/KaTeX_SansSerif-Bold.woff) format('woff'), + url(fonts/KaTeX_SansSerif-Bold.ttf) format('truetype'); + font-weight: bold; + font-style: normal; + } + @font-face { + font-family: 'KaTeX_SansSerif'; + src: url(fonts/KaTeX_SansSerif-Italic.woff2) format('woff2'), + url(fonts/KaTeX_SansSerif-Italic.woff) format('woff'), + url(fonts/KaTeX_SansSerif-Italic.ttf) format('truetype'); + font-weight: normal; + font-style: italic; + } + @font-face { + font-family: 'KaTeX_SansSerif'; + src: url(fonts/KaTeX_SansSerif-Regular.woff2) format('woff2'), + url(fonts/KaTeX_SansSerif-Regular.woff) format('woff'), + url(fonts/KaTeX_SansSerif-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; + } + @font-face { + font-family: 'KaTeX_Script'; + src: url(fonts/KaTeX_Script-Regular.woff2) format('woff2'), + url(fonts/KaTeX_Script-Regular.woff) format('woff'), + url(fonts/KaTeX_Script-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; + } + @font-face { + font-family: 'KaTeX_Size1'; + src: url(fonts/KaTeX_Size1-Regular.woff2) format('woff2'), + url(fonts/KaTeX_Size1-Regular.woff) format('woff'), + url(fonts/KaTeX_Size1-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; + } + @font-face { + font-family: 'KaTeX_Size2'; + src: url(fonts/KaTeX_Size2-Regular.woff2) format('woff2'), + url(fonts/KaTeX_Size2-Regular.woff) format('woff'), + url(fonts/KaTeX_Size2-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; + } + @font-face { + font-family: 'KaTeX_Size3'; + src: url(fonts/KaTeX_Size3-Regular.woff2) format('woff2'), + url(fonts/KaTeX_Size3-Regular.woff) format('woff'), + url(fonts/KaTeX_Size3-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; + } + @font-face { + font-family: 'KaTeX_Size4'; + src: url(fonts/KaTeX_Size4-Regular.woff2) format('woff2'), + url(fonts/KaTeX_Size4-Regular.woff) format('woff'), + url(fonts/KaTeX_Size4-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; + } + @font-face { + font-family: 'KaTeX_Typewriter'; + src: url(fonts/KaTeX_Typewriter-Regular.woff2) format('woff2'), + url(fonts/KaTeX_Typewriter-Regular.woff) format('woff'), + url(fonts/KaTeX_Typewriter-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; + } + .katex { + font: normal 1.21em KaTeX_Main, Times New Roman, serif; + line-height: 1.2; + text-indent: 0; + text-rendering: auto; + border-color: currentColor; + } + .katex * { + -ms-high-contrast-adjust: none !important; + } + .katex .katex-version::after { + content: '0.12.0'; + } + .katex .katex-mathml { + position: absolute; + clip: rect(1px, 1px, 1px, 1px); + padding: 0; + border: 0; + height: 1px; + width: 1px; + overflow: hidden; + } + .katex .katex-html { + /* \newline is an empty block at top level, between .base elements */ + } + .katex .katex-html > .newline { + display: block; + } + .katex .base { + position: relative; + display: inline-block; + white-space: nowrap; + width: min-content; + } + .katex .strut { + display: inline-block; + } + .katex .textbf { + font-weight: bold; + } + .katex .textit { + font-style: italic; + } + .katex .textrm { + font-family: KaTeX_Main; + } + .katex .textsf { + font-family: KaTeX_SansSerif; + } + .katex .texttt { + font-family: KaTeX_Typewriter; + } + .katex .mathnormal { + font-family: KaTeX_Math; + font-style: italic; + } + .katex .mathit { + font-family: KaTeX_Main; + font-style: italic; + } + .katex .mathrm { + font-style: normal; + } + .katex .mathbf { + font-family: KaTeX_Main; + font-weight: bold; + } + .katex .boldsymbol { + font-family: KaTeX_Math; + font-weight: bold; + font-style: italic; + } + .katex .amsrm { + font-family: KaTeX_AMS; + } + .katex .mathbb, + .katex .textbb { + font-family: KaTeX_AMS; + } + .katex .mathcal { + font-family: KaTeX_Caligraphic; + } + .katex .mathfrak, + .katex .textfrak { + font-family: KaTeX_Fraktur; + } + .katex .mathtt { + font-family: KaTeX_Typewriter; + } + .katex .mathscr, + .katex .textscr { + font-family: KaTeX_Script; + } + .katex .mathsf, + .katex .textsf { + font-family: KaTeX_SansSerif; + } + .katex .mathboldsf, + .katex .textboldsf { + font-family: KaTeX_SansSerif; + font-weight: bold; + } + .katex .mathitsf, + .katex .textitsf { + font-family: KaTeX_SansSerif; + font-style: italic; + } + .katex .mainrm { + font-family: KaTeX_Main; + font-style: normal; + } + .katex .vlist-t { + display: inline-table; + table-layout: fixed; + border-collapse: collapse; + } + .katex .vlist-r { + display: table-row; + } + .katex .vlist { + display: table-cell; + vertical-align: bottom; + position: relative; + } + .katex .vlist > span { + display: block; + height: 0; + position: relative; + } + .katex .vlist > span > span { + display: inline-block; + } + .katex .vlist > span > .pstrut { + overflow: hidden; + width: 0; + } + .katex .vlist-t2 { + margin-right: -2px; + } + .katex .vlist-s { + display: table-cell; + vertical-align: bottom; + font-size: 1px; + width: 2px; + min-width: 2px; + } + .katex .vbox { + display: -ms-inline-flexbox; + display: inline-flex; + -ms-flex-direction: column; + flex-direction: column; + align-items: baseline; + } + .katex .hbox { + display: -ms-inline-flexbox; + display: inline-flex; + -ms-flex-direction: row; + flex-direction: row; + width: 100%; + } + .katex .thinbox { + display: inline-flex; + flex-direction: row; + width: 0; + max-width: 0; + } + .katex .msupsub { + text-align: left; + } + .katex .mfrac > span > span { + text-align: center; + } + .katex .mfrac .frac-line { + display: inline-block; + width: 100%; + border-bottom-style: solid; + } + .katex .mfrac .frac-line, + .katex .overline .overline-line, + .katex .underline .underline-line, + .katex .hline, + .katex .hdashline, + .katex .rule { + min-height: 1px; + } + .katex .mspace { + display: inline-block; + } + .katex .llap, + .katex .rlap, + .katex .clap { + width: 0; + position: relative; + } + .katex .llap > .inner, + .katex .rlap > .inner, + .katex .clap > .inner { + position: absolute; + } + .katex .llap > .fix, + .katex .rlap > .fix, + .katex .clap > .fix { + display: inline-block; + } + .katex .llap > .inner { + right: 0; + } + .katex .rlap > .inner, + .katex .clap > .inner { + left: 0; + } + .katex .clap > .inner > span { + margin-left: -50%; + margin-right: 50%; + } + .katex .rule { + display: inline-block; + border: solid 0; + position: relative; + } + .katex .overline .overline-line, + .katex .underline .underline-line, + .katex .hline { + display: inline-block; + width: 100%; + border-bottom-style: solid; + } + .katex .hdashline { + display: inline-block; + width: 100%; + border-bottom-style: dashed; + } + .katex .sqrt > .root { + margin-left: 0.27777778em; + margin-right: -0.55555556em; + } + .katex .sizing.reset-size1.size1, + .katex .fontsize-ensurer.reset-size1.size1 { + font-size: 1em; + } + .katex .sizing.reset-size1.size2, + .katex .fontsize-ensurer.reset-size1.size2 { + font-size: 1.2em; + } + .katex .sizing.reset-size1.size3, + .katex .fontsize-ensurer.reset-size1.size3 { + font-size: 1.4em; + } + .katex .sizing.reset-size1.size4, + .katex .fontsize-ensurer.reset-size1.size4 { + font-size: 1.6em; + } + .katex .sizing.reset-size1.size5, + .katex .fontsize-ensurer.reset-size1.size5 { + font-size: 1.8em; + } + .katex .sizing.reset-size1.size6, + .katex .fontsize-ensurer.reset-size1.size6 { + font-size: 2em; + } + .katex .sizing.reset-size1.size7, + .katex .fontsize-ensurer.reset-size1.size7 { + font-size: 2.4em; + } + .katex .sizing.reset-size1.size8, + .katex .fontsize-ensurer.reset-size1.size8 { + font-size: 2.88em; + } + .katex .sizing.reset-size1.size9, + .katex .fontsize-ensurer.reset-size1.size9 { + font-size: 3.456em; + } + .katex .sizing.reset-size1.size10, + .katex .fontsize-ensurer.reset-size1.size10 { + font-size: 4.148em; + } + .katex .sizing.reset-size1.size11, + .katex .fontsize-ensurer.reset-size1.size11 { + font-size: 4.976em; + } + .katex .sizing.reset-size2.size1, + .katex .fontsize-ensurer.reset-size2.size1 { + font-size: 0.83333333em; + } + .katex .sizing.reset-size2.size2, + .katex .fontsize-ensurer.reset-size2.size2 { + font-size: 1em; + } + .katex .sizing.reset-size2.size3, + .katex .fontsize-ensurer.reset-size2.size3 { + font-size: 1.16666667em; + } + .katex .sizing.reset-size2.size4, + .katex .fontsize-ensurer.reset-size2.size4 { + font-size: 1.33333333em; + } + .katex .sizing.reset-size2.size5, + .katex .fontsize-ensurer.reset-size2.size5 { + font-size: 1.5em; + } + .katex .sizing.reset-size2.size6, + .katex .fontsize-ensurer.reset-size2.size6 { + font-size: 1.66666667em; + } + .katex .sizing.reset-size2.size7, + .katex .fontsize-ensurer.reset-size2.size7 { + font-size: 2em; + } + .katex .sizing.reset-size2.size8, + .katex .fontsize-ensurer.reset-size2.size8 { + font-size: 2.4em; + } + .katex .sizing.reset-size2.size9, + .katex .fontsize-ensurer.reset-size2.size9 { + font-size: 2.88em; + } + .katex .sizing.reset-size2.size10, + .katex .fontsize-ensurer.reset-size2.size10 { + font-size: 3.45666667em; + } + .katex .sizing.reset-size2.size11, + .katex .fontsize-ensurer.reset-size2.size11 { + font-size: 4.14666667em; + } + .katex .sizing.reset-size3.size1, + .katex .fontsize-ensurer.reset-size3.size1 { + font-size: 0.71428571em; + } + .katex .sizing.reset-size3.size2, + .katex .fontsize-ensurer.reset-size3.size2 { + font-size: 0.85714286em; + } + .katex .sizing.reset-size3.size3, + .katex .fontsize-ensurer.reset-size3.size3 { + font-size: 1em; + } + .katex .sizing.reset-size3.size4, + .katex .fontsize-ensurer.reset-size3.size4 { + font-size: 1.14285714em; + } + .katex .sizing.reset-size3.size5, + .katex .fontsize-ensurer.reset-size3.size5 { + font-size: 1.28571429em; + } + .katex .sizing.reset-size3.size6, + .katex .fontsize-ensurer.reset-size3.size6 { + font-size: 1.42857143em; + } + .katex .sizing.reset-size3.size7, + .katex .fontsize-ensurer.reset-size3.size7 { + font-size: 1.71428571em; + } + .katex .sizing.reset-size3.size8, + .katex .fontsize-ensurer.reset-size3.size8 { + font-size: 2.05714286em; + } + .katex .sizing.reset-size3.size9, + .katex .fontsize-ensurer.reset-size3.size9 { + font-size: 2.46857143em; + } + .katex .sizing.reset-size3.size10, + .katex .fontsize-ensurer.reset-size3.size10 { + font-size: 2.96285714em; + } + .katex .sizing.reset-size3.size11, + .katex .fontsize-ensurer.reset-size3.size11 { + font-size: 3.55428571em; + } + .katex .sizing.reset-size4.size1, + .katex .fontsize-ensurer.reset-size4.size1 { + font-size: 0.625em; + } + .katex .sizing.reset-size4.size2, + .katex .fontsize-ensurer.reset-size4.size2 { + font-size: 0.75em; + } + .katex .sizing.reset-size4.size3, + .katex .fontsize-ensurer.reset-size4.size3 { + font-size: 0.875em; + } + .katex .sizing.reset-size4.size4, + .katex .fontsize-ensurer.reset-size4.size4 { + font-size: 1em; + } + .katex .sizing.reset-size4.size5, + .katex .fontsize-ensurer.reset-size4.size5 { + font-size: 1.125em; + } + .katex .sizing.reset-size4.size6, + .katex .fontsize-ensurer.reset-size4.size6 { + font-size: 1.25em; + } + .katex .sizing.reset-size4.size7, + .katex .fontsize-ensurer.reset-size4.size7 { + font-size: 1.5em; + } + .katex .sizing.reset-size4.size8, + .katex .fontsize-ensurer.reset-size4.size8 { + font-size: 1.8em; + } + .katex .sizing.reset-size4.size9, + .katex .fontsize-ensurer.reset-size4.size9 { + font-size: 2.16em; + } + .katex .sizing.reset-size4.size10, + .katex .fontsize-ensurer.reset-size4.size10 { + font-size: 2.5925em; + } + .katex .sizing.reset-size4.size11, + .katex .fontsize-ensurer.reset-size4.size11 { + font-size: 3.11em; + } + .katex .sizing.reset-size5.size1, + .katex .fontsize-ensurer.reset-size5.size1 { + font-size: 0.55555556em; + } + .katex .sizing.reset-size5.size2, + .katex .fontsize-ensurer.reset-size5.size2 { + font-size: 0.66666667em; + } + .katex .sizing.reset-size5.size3, + .katex .fontsize-ensurer.reset-size5.size3 { + font-size: 0.77777778em; + } + .katex .sizing.reset-size5.size4, + .katex .fontsize-ensurer.reset-size5.size4 { + font-size: 0.88888889em; + } + .katex .sizing.reset-size5.size5, + .katex .fontsize-ensurer.reset-size5.size5 { + font-size: 1em; + } + .katex .sizing.reset-size5.size6, + .katex .fontsize-ensurer.reset-size5.size6 { + font-size: 1.11111111em; + } + .katex .sizing.reset-size5.size7, + .katex .fontsize-ensurer.reset-size5.size7 { + font-size: 1.33333333em; + } + .katex .sizing.reset-size5.size8, + .katex .fontsize-ensurer.reset-size5.size8 { + font-size: 1.6em; + } + .katex .sizing.reset-size5.size9, + .katex .fontsize-ensurer.reset-size5.size9 { + font-size: 1.92em; + } + .katex .sizing.reset-size5.size10, + .katex .fontsize-ensurer.reset-size5.size10 { + font-size: 2.30444444em; + } + .katex .sizing.reset-size5.size11, + .katex .fontsize-ensurer.reset-size5.size11 { + font-size: 2.76444444em; + } + .katex .sizing.reset-size6.size1, + .katex .fontsize-ensurer.reset-size6.size1 { + font-size: 0.5em; + } + .katex .sizing.reset-size6.size2, + .katex .fontsize-ensurer.reset-size6.size2 { + font-size: 0.6em; + } + .katex .sizing.reset-size6.size3, + .katex .fontsize-ensurer.reset-size6.size3 { + font-size: 0.7em; + } + .katex .sizing.reset-size6.size4, + .katex .fontsize-ensurer.reset-size6.size4 { + font-size: 0.8em; + } + .katex .sizing.reset-size6.size5, + .katex .fontsize-ensurer.reset-size6.size5 { + font-size: 0.9em; + } + .katex .sizing.reset-size6.size6, + .katex .fontsize-ensurer.reset-size6.size6 { + font-size: 1em; + } + .katex .sizing.reset-size6.size7, + .katex .fontsize-ensurer.reset-size6.size7 { + font-size: 1.2em; + } + .katex .sizing.reset-size6.size8, + .katex .fontsize-ensurer.reset-size6.size8 { + font-size: 1.44em; + } + .katex .sizing.reset-size6.size9, + .katex .fontsize-ensurer.reset-size6.size9 { + font-size: 1.728em; + } + .katex .sizing.reset-size6.size10, + .katex .fontsize-ensurer.reset-size6.size10 { + font-size: 2.074em; + } + .katex .sizing.reset-size6.size11, + .katex .fontsize-ensurer.reset-size6.size11 { + font-size: 2.488em; + } + .katex .sizing.reset-size7.size1, + .katex .fontsize-ensurer.reset-size7.size1 { + font-size: 0.41666667em; + } + .katex .sizing.reset-size7.size2, + .katex .fontsize-ensurer.reset-size7.size2 { + font-size: 0.5em; + } + .katex .sizing.reset-size7.size3, + .katex .fontsize-ensurer.reset-size7.size3 { + font-size: 0.58333333em; + } + .katex .sizing.reset-size7.size4, + .katex .fontsize-ensurer.reset-size7.size4 { + font-size: 0.66666667em; + } + .katex .sizing.reset-size7.size5, + .katex .fontsize-ensurer.reset-size7.size5 { + font-size: 0.75em; + } + .katex .sizing.reset-size7.size6, + .katex .fontsize-ensurer.reset-size7.size6 { + font-size: 0.83333333em; + } + .katex .sizing.reset-size7.size7, + .katex .fontsize-ensurer.reset-size7.size7 { + font-size: 1em; + } + .katex .sizing.reset-size7.size8, + .katex .fontsize-ensurer.reset-size7.size8 { + font-size: 1.2em; + } + .katex .sizing.reset-size7.size9, + .katex .fontsize-ensurer.reset-size7.size9 { + font-size: 1.44em; + } + .katex .sizing.reset-size7.size10, + .katex .fontsize-ensurer.reset-size7.size10 { + font-size: 1.72833333em; + } + .katex .sizing.reset-size7.size11, + .katex .fontsize-ensurer.reset-size7.size11 { + font-size: 2.07333333em; + } + .katex .sizing.reset-size8.size1, + .katex .fontsize-ensurer.reset-size8.size1 { + font-size: 0.34722222em; + } + .katex .sizing.reset-size8.size2, + .katex .fontsize-ensurer.reset-size8.size2 { + font-size: 0.41666667em; + } + .katex .sizing.reset-size8.size3, + .katex .fontsize-ensurer.reset-size8.size3 { + font-size: 0.48611111em; + } + .katex .sizing.reset-size8.size4, + .katex .fontsize-ensurer.reset-size8.size4 { + font-size: 0.55555556em; + } + .katex .sizing.reset-size8.size5, + .katex .fontsize-ensurer.reset-size8.size5 { + font-size: 0.625em; + } + .katex .sizing.reset-size8.size6, + .katex .fontsize-ensurer.reset-size8.size6 { + font-size: 0.69444444em; + } + .katex .sizing.reset-size8.size7, + .katex .fontsize-ensurer.reset-size8.size7 { + font-size: 0.83333333em; + } + .katex .sizing.reset-size8.size8, + .katex .fontsize-ensurer.reset-size8.size8 { + font-size: 1em; + } + .katex .sizing.reset-size8.size9, + .katex .fontsize-ensurer.reset-size8.size9 { + font-size: 1.2em; + } + .katex .sizing.reset-size8.size10, + .katex .fontsize-ensurer.reset-size8.size10 { + font-size: 1.44027778em; + } + .katex .sizing.reset-size8.size11, + .katex .fontsize-ensurer.reset-size8.size11 { + font-size: 1.72777778em; + } + .katex .sizing.reset-size9.size1, + .katex .fontsize-ensurer.reset-size9.size1 { + font-size: 0.28935185em; + } + .katex .sizing.reset-size9.size2, + .katex .fontsize-ensurer.reset-size9.size2 { + font-size: 0.34722222em; + } + .katex .sizing.reset-size9.size3, + .katex .fontsize-ensurer.reset-size9.size3 { + font-size: 0.40509259em; + } + .katex .sizing.reset-size9.size4, + .katex .fontsize-ensurer.reset-size9.size4 { + font-size: 0.46296296em; + } + .katex .sizing.reset-size9.size5, + .katex .fontsize-ensurer.reset-size9.size5 { + font-size: 0.52083333em; + } + .katex .sizing.reset-size9.size6, + .katex .fontsize-ensurer.reset-size9.size6 { + font-size: 0.5787037em; + } + .katex .sizing.reset-size9.size7, + .katex .fontsize-ensurer.reset-size9.size7 { + font-size: 0.69444444em; + } + .katex .sizing.reset-size9.size8, + .katex .fontsize-ensurer.reset-size9.size8 { + font-size: 0.83333333em; + } + .katex .sizing.reset-size9.size9, + .katex .fontsize-ensurer.reset-size9.size9 { + font-size: 1em; + } + .katex .sizing.reset-size9.size10, + .katex .fontsize-ensurer.reset-size9.size10 { + font-size: 1.20023148em; + } + .katex .sizing.reset-size9.size11, + .katex .fontsize-ensurer.reset-size9.size11 { + font-size: 1.43981481em; + } + .katex .sizing.reset-size10.size1, + .katex .fontsize-ensurer.reset-size10.size1 { + font-size: 0.24108004em; + } + .katex .sizing.reset-size10.size2, + .katex .fontsize-ensurer.reset-size10.size2 { + font-size: 0.28929605em; + } + .katex .sizing.reset-size10.size3, + .katex .fontsize-ensurer.reset-size10.size3 { + font-size: 0.33751205em; + } + .katex .sizing.reset-size10.size4, + .katex .fontsize-ensurer.reset-size10.size4 { + font-size: 0.38572806em; + } + .katex .sizing.reset-size10.size5, + .katex .fontsize-ensurer.reset-size10.size5 { + font-size: 0.43394407em; + } + .katex .sizing.reset-size10.size6, + .katex .fontsize-ensurer.reset-size10.size6 { + font-size: 0.48216008em; + } + .katex .sizing.reset-size10.size7, + .katex .fontsize-ensurer.reset-size10.size7 { + font-size: 0.57859209em; + } + .katex .sizing.reset-size10.size8, + .katex .fontsize-ensurer.reset-size10.size8 { + font-size: 0.69431051em; + } + .katex .sizing.reset-size10.size9, + .katex .fontsize-ensurer.reset-size10.size9 { + font-size: 0.83317261em; + } + .katex .sizing.reset-size10.size10, + .katex .fontsize-ensurer.reset-size10.size10 { + font-size: 1em; + } + .katex .sizing.reset-size10.size11, + .katex .fontsize-ensurer.reset-size10.size11 { + font-size: 1.19961427em; + } + .katex .sizing.reset-size11.size1, + .katex .fontsize-ensurer.reset-size11.size1 { + font-size: 0.20096463em; + } + .katex .sizing.reset-size11.size2, + .katex .fontsize-ensurer.reset-size11.size2 { + font-size: 0.24115756em; + } + .katex .sizing.reset-size11.size3, + .katex .fontsize-ensurer.reset-size11.size3 { + font-size: 0.28135048em; + } + .katex .sizing.reset-size11.size4, + .katex .fontsize-ensurer.reset-size11.size4 { + font-size: 0.32154341em; + } + .katex .sizing.reset-size11.size5, + .katex .fontsize-ensurer.reset-size11.size5 { + font-size: 0.36173633em; + } + .katex .sizing.reset-size11.size6, + .katex .fontsize-ensurer.reset-size11.size6 { + font-size: 0.40192926em; + } + .katex .sizing.reset-size11.size7, + .katex .fontsize-ensurer.reset-size11.size7 { + font-size: 0.48231511em; + } + .katex .sizing.reset-size11.size8, + .katex .fontsize-ensurer.reset-size11.size8 { + font-size: 0.57877814em; + } + .katex .sizing.reset-size11.size9, + .katex .fontsize-ensurer.reset-size11.size9 { + font-size: 0.69453376em; + } + .katex .sizing.reset-size11.size10, + .katex .fontsize-ensurer.reset-size11.size10 { + font-size: 0.83360129em; + } + .katex .sizing.reset-size11.size11, + .katex .fontsize-ensurer.reset-size11.size11 { + font-size: 1em; + } + .katex .delimsizing.size1 { + font-family: KaTeX_Size1; + } + .katex .delimsizing.size2 { + font-family: KaTeX_Size2; + } + .katex .delimsizing.size3 { + font-family: KaTeX_Size3; + } + .katex .delimsizing.size4 { + font-family: KaTeX_Size4; + } + .katex .delimsizing.mult .delim-size1 > span { + font-family: KaTeX_Size1; + } + .katex .delimsizing.mult .delim-size4 > span { + font-family: KaTeX_Size4; + } + .katex .nulldelimiter { + display: inline-block; + width: 0.12em; + } + .katex .delimcenter { + position: relative; + } + .katex .op-symbol { + position: relative; + } + .katex .op-symbol.small-op { + font-family: KaTeX_Size1; + } + .katex .op-symbol.large-op { + font-family: KaTeX_Size2; + } + .katex .op-limits > .vlist-t { + text-align: center; + } + .katex .accent > .vlist-t { + text-align: center; + } + .katex .accent .accent-body { + position: relative; + } + .katex .accent .accent-body:not(.accent-full) { + width: 0; + } + .katex .overlay { + display: block; + } + .katex .mtable .vertical-separator { + display: inline-block; + min-width: 1px; + } + .katex .mtable .arraycolsep { + display: inline-block; + } + .katex .mtable .col-align-c > .vlist-t { + text-align: center; + } + .katex .mtable .col-align-l > .vlist-t { + text-align: left; + } + .katex .mtable .col-align-r > .vlist-t { + text-align: right; + } + .katex .svg-align { + text-align: left; + } + .katex svg { + display: block; + position: absolute; + width: 100%; + height: inherit; + fill: currentColor; + stroke: currentColor; + fill-rule: nonzero; + fill-opacity: 1; + stroke-width: 1; + stroke-linecap: butt; + stroke-linejoin: miter; + stroke-miterlimit: 4; + stroke-dasharray: none; + stroke-dashoffset: 0; + stroke-opacity: 1; + } + .katex svg path { + stroke: none; + } + .katex img { + border-style: none; + min-width: 0; + min-height: 0; + max-width: none; + max-height: none; + } + .katex .stretchy { + width: 100%; + display: block; + position: relative; + overflow: hidden; + } + .katex .stretchy::before, + .katex .stretchy::after { + content: ''; + } + .katex .hide-tail { + width: 100%; + position: relative; + overflow: hidden; + } + .katex .halfarrow-left { + position: absolute; + left: 0; + width: 50.2%; + overflow: hidden; + } + .katex .halfarrow-right { + position: absolute; + right: 0; + width: 50.2%; + overflow: hidden; + } + .katex .brace-left { + position: absolute; + left: 0; + width: 25.1%; + overflow: hidden; + } + .katex .brace-center { + position: absolute; + left: 25%; + width: 50%; + overflow: hidden; + } + .katex .brace-right { + position: absolute; + right: 0; + width: 25.1%; + overflow: hidden; + } + .katex .x-arrow-pad { + padding: 0 0.5em; + } + .katex .x-arrow, + .katex .mover, + .katex .munder { + text-align: center; + } + .katex .boxpad { + padding: 0 0.3em 0 0.3em; + } + .katex .fbox, + .katex .fcolorbox { + box-sizing: border-box; + border: 0.04em solid; + } + .katex .cancel-pad { + padding: 0 0.2em 0 0.2em; + } + .katex .cancel-lap { + margin-left: -0.2em; + margin-right: -0.2em; + } + .katex .sout { + border-bottom-style: solid; + border-bottom-width: 0.08em; + } + .katex-display { + display: block; + margin: 1em 0; + text-align: center; + } + .katex-display > .katex { + display: block; + text-align: center; + white-space: nowrap; + } + .katex-display > .katex > .katex-html { + display: block; + position: relative; + } + .katex-display > .katex > .katex-html > .tag { + position: absolute; + right: 0; + } + .katex-display.leqno > .katex > .katex-html > .tag { + left: 0; + right: auto; + } + .katex-display.fleqn > .katex { + text-align: left; + padding-left: 2em; + } +`; diff --git a/editors/editoria/src/layout/componentPlugin.js b/editors/editoria/src/layout/componentPlugin.js deleted file mode 100644 index 7a7f790c1532253a58afb66f547405ecaa3f43f6..0000000000000000000000000000000000000000 --- a/editors/editoria/src/layout/componentPlugin.js +++ /dev/null @@ -1,38 +0,0 @@ -import React, { Component } from 'react'; -import { useInjection } from './WaxContext'; - -class UpdateView extends Component { - constructor(props) { - super(props); - - this.state = { - view: this.props.view, - }; - } - - updateView(view) { - this.setState(view); - } - - render() { - return this.props.children({ view: this.state.view }); - } -} - -const ComponentPlugin = renderArea => layoutProps => { - const { instance } = useInjection('Layout'); - const components = instance.render(renderArea); - - return components - ? components.map(({ component: Component, componentProps }, key) => { - return ( - <Component - key={`${renderArea}-${key}`} - {...layoutProps} - {...componentProps} - /> - ); - }) - : null; -}; -export default ComponentPlugin; diff --git a/editors/editoria/src/layout/fonts/KaTeX_AMS-Regular.ttf b/editors/editoria/src/layout/fonts/KaTeX_AMS-Regular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..737cf8eb58a98d8717f742fca3f10f6d214e4e22 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_AMS-Regular.ttf differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_AMS-Regular.woff b/editors/editoria/src/layout/fonts/KaTeX_AMS-Regular.woff new file mode 100644 index 0000000000000000000000000000000000000000..38378bfba8d66d78d68b0a392316adca9e042a11 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_AMS-Regular.woff differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_AMS-Regular.woff2 b/editors/editoria/src/layout/fonts/KaTeX_AMS-Regular.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..a4d1ba64101f2102fd7dfab61bb98ade4de55870 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_AMS-Regular.woff2 differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Caligraphic-Bold.ttf b/editors/editoria/src/layout/fonts/KaTeX_Caligraphic-Bold.ttf new file mode 100644 index 0000000000000000000000000000000000000000..04d28abd99572bb80ae0cabbf3dd9072cd1d7a2a Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Caligraphic-Bold.ttf differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Caligraphic-Bold.woff b/editors/editoria/src/layout/fonts/KaTeX_Caligraphic-Bold.woff new file mode 100644 index 0000000000000000000000000000000000000000..a01ce906060328399bad5499e87b6bac40f8fb3c Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Caligraphic-Bold.woff differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Caligraphic-Bold.woff2 b/editors/editoria/src/layout/fonts/KaTeX_Caligraphic-Bold.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..37927274af1e1e3eabcf1763e9dbc261473dc4ef Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Caligraphic-Bold.woff2 differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Caligraphic-Regular.ttf b/editors/editoria/src/layout/fonts/KaTeX_Caligraphic-Regular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..b2ce555fd5d1d1eb6411cc41c3688bd077452458 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Caligraphic-Regular.ttf differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Caligraphic-Regular.woff b/editors/editoria/src/layout/fonts/KaTeX_Caligraphic-Regular.woff new file mode 100644 index 0000000000000000000000000000000000000000..bc169b7cdd8b30947558f542d59ab407a0646ab9 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Caligraphic-Regular.woff differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Caligraphic-Regular.woff2 b/editors/editoria/src/layout/fonts/KaTeX_Caligraphic-Regular.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..f1e38bba2a7612a9842254bc305626bcc8c12b97 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Caligraphic-Regular.woff2 differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Fraktur-Bold.ttf b/editors/editoria/src/layout/fonts/KaTeX_Fraktur-Bold.ttf new file mode 100644 index 0000000000000000000000000000000000000000..c42d169167d78a1d93b4fb3f85f168417b5bafd0 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Fraktur-Bold.ttf differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Fraktur-Bold.woff b/editors/editoria/src/layout/fonts/KaTeX_Fraktur-Bold.woff new file mode 100644 index 0000000000000000000000000000000000000000..f30b54b3d1c494e73e6af651165cfe572d8663dc Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Fraktur-Bold.woff differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Fraktur-Bold.woff2 b/editors/editoria/src/layout/fonts/KaTeX_Fraktur-Bold.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..b7a83593a8d3170d69921e7d3d63e0289926bae6 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Fraktur-Bold.woff2 differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Fraktur-Regular.ttf b/editors/editoria/src/layout/fonts/KaTeX_Fraktur-Regular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..413322824e3a08e33435d4247166da724ab2ecc6 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Fraktur-Regular.ttf differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Fraktur-Regular.woff b/editors/editoria/src/layout/fonts/KaTeX_Fraktur-Regular.woff new file mode 100644 index 0000000000000000000000000000000000000000..5af51de9e5dce95438e1200ae629552f9369a668 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Fraktur-Regular.woff differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Fraktur-Regular.woff2 b/editors/editoria/src/layout/fonts/KaTeX_Fraktur-Regular.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..3874f93e8dacd0b91f5fa57d045119a2b695fd77 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Fraktur-Regular.woff2 differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Main-Bold.ttf b/editors/editoria/src/layout/fonts/KaTeX_Main-Bold.ttf new file mode 100644 index 0000000000000000000000000000000000000000..14390e012a5ad45c41fe93fb6543ecefc33bf70a Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Main-Bold.ttf differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Main-Bold.woff b/editors/editoria/src/layout/fonts/KaTeX_Main-Bold.woff new file mode 100644 index 0000000000000000000000000000000000000000..33b41998e40d6bdfbe9e49dc11174bd3f74dc278 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Main-Bold.woff differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Main-Bold.woff2 b/editors/editoria/src/layout/fonts/KaTeX_Main-Bold.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..f9b71cbe7420582e03f9479a5b1781e7c8244221 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Main-Bold.woff2 differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Main-BoldItalic.ttf b/editors/editoria/src/layout/fonts/KaTeX_Main-BoldItalic.ttf new file mode 100644 index 0000000000000000000000000000000000000000..ad0761f431e3147794ead4831ff267c43fe517fe Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Main-BoldItalic.ttf differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Main-BoldItalic.woff b/editors/editoria/src/layout/fonts/KaTeX_Main-BoldItalic.woff new file mode 100644 index 0000000000000000000000000000000000000000..115af4f072e4274fa7b4d2e598da5bef26144564 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Main-BoldItalic.woff differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Main-BoldItalic.woff2 b/editors/editoria/src/layout/fonts/KaTeX_Main-BoldItalic.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..5c500c285ab55e11950be8b95b43ab163924eadd Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Main-BoldItalic.woff2 differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Main-Italic.ttf b/editors/editoria/src/layout/fonts/KaTeX_Main-Italic.ttf new file mode 100644 index 0000000000000000000000000000000000000000..fc8625c81c8443eaf422fec5138f0bcc2a78fa19 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Main-Italic.ttf differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Main-Italic.woff b/editors/editoria/src/layout/fonts/KaTeX_Main-Italic.woff new file mode 100644 index 0000000000000000000000000000000000000000..2d3087ab4960a26677e544f8f6ab204326240a85 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Main-Italic.woff differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Main-Italic.woff2 b/editors/editoria/src/layout/fonts/KaTeX_Main-Italic.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..08510d85a779a19c24b2514204ff9e204edbb3df Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Main-Italic.woff2 differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Main-Regular.ttf b/editors/editoria/src/layout/fonts/KaTeX_Main-Regular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..5115a044ea407f8ef1fc646c3485162f0df1258c Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Main-Regular.ttf differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Main-Regular.woff b/editors/editoria/src/layout/fonts/KaTeX_Main-Regular.woff new file mode 100644 index 0000000000000000000000000000000000000000..42b74ab13306c0c6c361740282b13a3b36c56065 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Main-Regular.woff differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Main-Regular.woff2 b/editors/editoria/src/layout/fonts/KaTeX_Main-Regular.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..18647fa6afbc40c64b6cb0a5142c2ebae8a21212 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Main-Regular.woff2 differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Math-BoldItalic.ttf b/editors/editoria/src/layout/fonts/KaTeX_Math-BoldItalic.ttf new file mode 100644 index 0000000000000000000000000000000000000000..326b523bd0eca107f1bfe422f211306e491eb278 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Math-BoldItalic.ttf differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Math-BoldItalic.woff b/editors/editoria/src/layout/fonts/KaTeX_Math-BoldItalic.woff new file mode 100644 index 0000000000000000000000000000000000000000..5b4041aa87c634e4550920a48e033b4af133d7c8 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Math-BoldItalic.woff differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Math-BoldItalic.woff2 b/editors/editoria/src/layout/fonts/KaTeX_Math-BoldItalic.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..ba55276d03067f0c9f592d1d9e4faa43482b7454 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Math-BoldItalic.woff2 differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Math-Italic.ttf b/editors/editoria/src/layout/fonts/KaTeX_Math-Italic.ttf new file mode 100644 index 0000000000000000000000000000000000000000..f148fceeb07b6482aeb5944dafd3749d62416327 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Math-Italic.ttf differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Math-Italic.woff b/editors/editoria/src/layout/fonts/KaTeX_Math-Italic.woff new file mode 100644 index 0000000000000000000000000000000000000000..31d0038498aa6e24ae80b7a25dce5f1636224e2b Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Math-Italic.woff differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Math-Italic.woff2 b/editors/editoria/src/layout/fonts/KaTeX_Math-Italic.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..9871ab6b83556fe1ebfe44fd44184d58432ff4ea Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Math-Italic.woff2 differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Bold.ttf b/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Bold.ttf new file mode 100644 index 0000000000000000000000000000000000000000..dce35c8fdf260dffc5b8d5cd5f9d360b5f19ce2c Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Bold.ttf differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Bold.woff b/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Bold.woff new file mode 100644 index 0000000000000000000000000000000000000000..992cb3d6d0d1f881f1dff8c1784ea52662b99a61 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Bold.woff differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Bold.woff2 b/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Bold.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..6dd10388adaf48c986009e84fe140d000dc0d8b3 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Bold.woff2 differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Italic.ttf b/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Italic.ttf new file mode 100644 index 0000000000000000000000000000000000000000..a3eb86c38da4946aed6475e9977f3a1ec090f4ce Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Italic.ttf differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Italic.woff b/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Italic.woff new file mode 100644 index 0000000000000000000000000000000000000000..f4fa252a2c1626909a43a41af1e57ca25ee0f176 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Italic.woff differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Italic.woff2 b/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Italic.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..9f2501a3aacb36edb18aa674188250d43992ff2e Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Italic.woff2 differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Regular.ttf b/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Regular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..3be73ce17f8e383d115aafd096b80310e5bbd537 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Regular.ttf differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Regular.woff b/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Regular.woff new file mode 100644 index 0000000000000000000000000000000000000000..ec283f418b58a52b4d635333e918de46dc22b2a5 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Regular.woff differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Regular.woff2 b/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Regular.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..e46094fba16105fc781298a1bb73b7e9dcf205c1 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_SansSerif-Regular.woff2 differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Script-Regular.ttf b/editors/editoria/src/layout/fonts/KaTeX_Script-Regular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..40c8a997accbb83e0912055f90889921b110beb6 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Script-Regular.ttf differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Script-Regular.woff b/editors/editoria/src/layout/fonts/KaTeX_Script-Regular.woff new file mode 100644 index 0000000000000000000000000000000000000000..4eafae7583d45b9bc8002a32f6eefb5926f7f5f8 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Script-Regular.woff differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Script-Regular.woff2 b/editors/editoria/src/layout/fonts/KaTeX_Script-Regular.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..69b1754d7e2aae2800977b68a8da73027b6cbd4a Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Script-Regular.woff2 differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Size1-Regular.ttf b/editors/editoria/src/layout/fonts/KaTeX_Size1-Regular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..f0aff83efb32936ad31565206b00af3c90d6fb2a Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Size1-Regular.ttf differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Size1-Regular.woff b/editors/editoria/src/layout/fonts/KaTeX_Size1-Regular.woff new file mode 100644 index 0000000000000000000000000000000000000000..0358ee4a3eb557fc65845240c3547b9a6bc17a7c Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Size1-Regular.woff differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Size1-Regular.woff2 b/editors/editoria/src/layout/fonts/KaTeX_Size1-Regular.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..f951ed01694dd1354a826726f73f0e388798af1d Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Size1-Regular.woff2 differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Size2-Regular.ttf b/editors/editoria/src/layout/fonts/KaTeX_Size2-Regular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..4f72f167953526b7d33051bd8cf0c2cfcbab5718 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Size2-Regular.ttf differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Size2-Regular.woff b/editors/editoria/src/layout/fonts/KaTeX_Size2-Regular.woff new file mode 100644 index 0000000000000000000000000000000000000000..8a053d23ae37b5b78b68ee2fa436e4c3600eacd9 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Size2-Regular.woff differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Size2-Regular.woff2 b/editors/editoria/src/layout/fonts/KaTeX_Size2-Regular.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..181d9625a796eea012f0ebe09f720ed3eaaeab39 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Size2-Regular.woff2 differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Size3-Regular.ttf b/editors/editoria/src/layout/fonts/KaTeX_Size3-Regular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..56d2dc6c5d2d2d620951db50de45424415b704f9 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Size3-Regular.ttf differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Size3-Regular.woff b/editors/editoria/src/layout/fonts/KaTeX_Size3-Regular.woff new file mode 100644 index 0000000000000000000000000000000000000000..0ec99ad1a9fd2e810162e3cde1a1ef8a94cc1b40 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Size3-Regular.woff differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Size3-Regular.woff2 b/editors/editoria/src/layout/fonts/KaTeX_Size3-Regular.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..c2985cd380cfbf10866dbd90d13159b5f10b156e Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Size3-Regular.woff2 differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Size4-Regular.ttf b/editors/editoria/src/layout/fonts/KaTeX_Size4-Regular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..baf02091aa2038c2771d198ab7a24c85f3fa2682 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Size4-Regular.ttf differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Size4-Regular.woff b/editors/editoria/src/layout/fonts/KaTeX_Size4-Regular.woff new file mode 100644 index 0000000000000000000000000000000000000000..ff6731972f9c71b8128634552f7dbe687e43f697 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Size4-Regular.woff differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Size4-Regular.woff2 b/editors/editoria/src/layout/fonts/KaTeX_Size4-Regular.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..a4e810da5e31a364ad7ba2ff229562f97ae0f49f Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Size4-Regular.woff2 differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Typewriter-Regular.ttf b/editors/editoria/src/layout/fonts/KaTeX_Typewriter-Regular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..e66c218df5d876ff6f8b08410d2111de3976915a Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Typewriter-Regular.ttf differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Typewriter-Regular.woff b/editors/editoria/src/layout/fonts/KaTeX_Typewriter-Regular.woff new file mode 100644 index 0000000000000000000000000000000000000000..c66d149d5e2a4a5e98d696ceaded67669edc6579 Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Typewriter-Regular.woff differ diff --git a/editors/editoria/src/layout/fonts/KaTeX_Typewriter-Regular.woff2 b/editors/editoria/src/layout/fonts/KaTeX_Typewriter-Regular.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..e5bf2ce1ff1a199931a53c6654cd08d7b2603ace Binary files /dev/null and b/editors/editoria/src/layout/fonts/KaTeX_Typewriter-Regular.woff2 differ diff --git a/wax-prosemirror-components/.gitignore b/wax-prosemirror-components/.gitignore index deb5ee0e0e98566ca4064349d5e68cbab9bfed1c..b3e3ccb6b0ce3a90e1eb3f9e78da7924ea89f116 100644 --- a/wax-prosemirror-components/.gitignore +++ b/wax-prosemirror-components/.gitignore @@ -7,6 +7,9 @@ # production /build +# dist +/dist + # misc .DS_Store .env.local diff --git a/wax-prosemirror-components/index.js b/wax-prosemirror-components/index.js index 0742df29fae1f35d3485ca5b54e9f5bd1c005f7e..0da2eedf1adc1534144ec32ffa791cc73a9713d7 100644 --- a/wax-prosemirror-components/index.js +++ b/wax-prosemirror-components/index.js @@ -1,4 +1,3 @@ -export { default as InfoArea } from './src/components/infoArea/InfoArea'; export { default as Overlay } from './src/components/Overlay'; export { default as Button } from './src/components/Button'; export { default as icons } from './src/icons/icons'; diff --git a/wax-prosemirror-components/src/components/comments/CommentBubbleComponent.js b/wax-prosemirror-components/src/components/comments/CommentBubbleComponent.js index 8443731c4d9d9fc5194d8231a452df6b482d491d..9e9f9818b5293a9c99db74ff407d8481a6eff31b 100644 --- a/wax-prosemirror-components/src/components/comments/CommentBubbleComponent.js +++ b/wax-prosemirror-components/src/components/comments/CommentBubbleComponent.js @@ -30,17 +30,31 @@ const CommentBubbleComponent = ({ activeView.focus(); }; - const isSelectionComment = () => { + const isCommentAllowed = () => { const commentMark = activeView.state.schema.marks.comment; const mark = DocumentHelpers.findMark(state, commentMark, true); + let allowed = true; + state.doc.nodesBetween( + state.selection.$from.pos, + state.selection.$to.pos, + (node, from) => { + if ( + node.type.name === 'math_display' || + node.type.name === 'math_inline' + ) { + allowed = false; + } + }, + ); + // TODO Overlapping comments . for now don't allow - if (mark.length >= 1) return true; - return false; + if (mark.length >= 1) allowed = false; + return allowed; }; return ( - !isSelectionComment() && + isCommentAllowed() && showComment(activeViewId) && ( <CommentBubble onClick={event => { diff --git a/wax-prosemirror-components/src/components/infoArea/InfoArea.js b/wax-prosemirror-components/src/components/infoArea/InfoArea.js deleted file mode 100644 index ae6e088a0436acedf57143d30c5c9929ca18edeb..0000000000000000000000000000000000000000 --- a/wax-prosemirror-components/src/components/infoArea/InfoArea.js +++ /dev/null @@ -1,15 +0,0 @@ -import React from "react"; -import styled from "styled-components"; - -const InfoAreaContainer = styled.div` - ${"" /* height: ${props => (props.height ? props.height : "30px")}; - position: fixed; - bottom: 0; - z-index: 9999; - background: #efefef; - width: 100%;*/}; -`; - -const InfoArea = () => <InfoAreaContainer />; - -export default InfoArea; diff --git a/wax-prosemirror-components/src/components/notes/NoteEditorContainer.js b/wax-prosemirror-components/src/components/notes/NoteEditorContainer.js index 81ea93833d8098ab51b0f2afc9ce5573081a29a5..8e08ea86c095800921f7b00b8ebd39c914935fc6 100644 --- a/wax-prosemirror-components/src/components/notes/NoteEditorContainer.js +++ b/wax-prosemirror-components/src/components/notes/NoteEditorContainer.js @@ -25,15 +25,6 @@ const NoteStyled = styled.div` height: 100%; border-bottom: 1px solid black; - span.comment { - border-bottom: none !important; - &: after { - content: ''; - border-bottom: 2px solid gold; - display: block; - } - } - &:focus { outline: none; } diff --git a/wax-prosemirror-core/.gitignore b/wax-prosemirror-core/.gitignore index deb5ee0e0e98566ca4064349d5e68cbab9bfed1c..b3e3ccb6b0ce3a90e1eb3f9e78da7924ea89f116 100644 --- a/wax-prosemirror-core/.gitignore +++ b/wax-prosemirror-core/.gitignore @@ -7,6 +7,9 @@ # production /build +# dist +/dist + # misc .DS_Store .env.local diff --git a/wax-prosemirror-core/src/WaxView.js b/wax-prosemirror-core/src/WaxView.js index 951965abb77e74d303b2cfab0fce17ee02938878..d8722a6a8465608a1b918398f3f31f71c611e95d 100644 --- a/wax-prosemirror-core/src/WaxView.js +++ b/wax-prosemirror-core/src/WaxView.js @@ -42,6 +42,9 @@ export default props => { transformPasted: slice => { return transformPasted(slice, view); }, + attributes: { + spellcheck: 'false', + }, }, ); diff --git a/wax-prosemirror-plugins/.gitignore b/wax-prosemirror-plugins/.gitignore index deb5ee0e0e98566ca4064349d5e68cbab9bfed1c..b3e3ccb6b0ce3a90e1eb3f9e78da7924ea89f116 100644 --- a/wax-prosemirror-plugins/.gitignore +++ b/wax-prosemirror-plugins/.gitignore @@ -7,6 +7,9 @@ # production /build +# dist +/dist + # misc .DS_Store .env.local diff --git a/wax-prosemirror-plugins/index.js b/wax-prosemirror-plugins/index.js index 72d283b67322f401b18d557fa3cd3d42652009e0..819d258b5e5fcd2f7faa176493b63799d35f2056 100644 --- a/wax-prosemirror-plugins/index.js +++ b/wax-prosemirror-plugins/index.js @@ -3,3 +3,6 @@ export { default as TrackChangePlugin } from './src/trackChanges/TrackChangePlug export { default as CommentPlugin } from './src/comments/CommentPlugin'; export { default as WaxSelectionPlugin } from './src/WaxSelectionPlugin'; export { default as highlightPlugin } from './src/highlightPlugin'; + +export { default as mathPlugin } from './src/math/math-plugin'; +export { default as mathSelectPlugin } from './src/math/math-select'; diff --git a/wax-prosemirror-plugins/package.json b/wax-prosemirror-plugins/package.json index dfe74a19c2d578d96b3528b53b70c79dfaff675a..86635e611941ae990749878a9fb698a1895eec38 100644 --- a/wax-prosemirror-plugins/package.json +++ b/wax-prosemirror-plugins/package.json @@ -18,8 +18,12 @@ "prosemirror-highlightjs": "^0.2.0", "prosemirror-state": "1.3.3", "prosemirror-view": "1.15.2", + "prosemirror-transform": "1.2.6", + "prosemirror-keymap": "1.1.4", + "prosemirror-commands": "1.1.4", "wax-prosemirror-components": "^0.0.20", "wax-prosemirror-core": "^0.0.20", - "wax-prosemirror-utilities": "^0.0.20" + "wax-prosemirror-utilities": "^0.0.20", + "katex": "^0.12.0" } } diff --git a/wax-prosemirror-plugins/src/math/math-nodeview.js b/wax-prosemirror-plugins/src/math/math-nodeview.js new file mode 100644 index 0000000000000000000000000000000000000000..1f9241d3a76acc1d6e9b99fc20945a819da44be3 --- /dev/null +++ b/wax-prosemirror-plugins/src/math/math-nodeview.js @@ -0,0 +1,280 @@ +/* eslint-disable */ +import { EditorState, TextSelection } from 'prosemirror-state'; +import { EditorView } from 'prosemirror-view'; +import { StepMap } from 'prosemirror-transform'; +import { keymap } from 'prosemirror-keymap'; +import { + newlineInCode, + chainCommands, + deleteSelection, +} from 'prosemirror-commands'; +// katex +import katex, { ParseError } from 'katex'; +export class MathView { + // == Lifecycle ===================================== // + /** + * @param onDestroy Callback for when this NodeView is destroyed. + * This NodeView should unregister itself from the list of ICursorPosObservers. + * + * Math Views support the following options: + * @option displayMode If TRUE, will render math in display mode, otherwise in inline mode. + * @option tagName HTML tag name to use for this NodeView. If none is provided, + * will use the node name with underscores converted to hyphens. + */ + constructor(node, view, getPos, options = {}, onDestroy) { + // store arguments + this._node = node; + this._outerView = view; + this._getPos = getPos; + this._onDestroy = onDestroy && onDestroy.bind(this); + // editing state + this.cursorSide = 'start'; + this._isEditing = false; + // options + this._katexOptions = Object.assign( + { globalGroup: true, throwOnError: false }, + options.katexOptions, + ); + this._tagName = options.tagName || this._node.type.name.replace('_', '-'); + // create dom representation of nodeview + this.dom = document.createElement(this._tagName); + this.dom.classList.add('math-node'); + this._mathRenderElt = document.createElement('span'); + this._mathRenderElt.textContent = ''; + this._mathRenderElt.classList.add('math-render'); + this.dom.appendChild(this._mathRenderElt); + this._mathSrcElt = document.createElement('span'); + this._mathSrcElt.classList.add('math-src'); + this.dom.appendChild(this._mathSrcElt); + // ensure + this.dom.addEventListener('click', () => this.ensureFocus()); + // render initial content + this.renderMath(); + } + destroy() { + // close the inner editor without rendering + this.closeEditor(false); + // clean up dom elements + if (this._mathRenderElt) { + this._mathRenderElt.remove(); + delete this._mathRenderElt; + } + if (this._mathSrcElt) { + this._mathSrcElt.remove(); + delete this._mathSrcElt; + } + delete this.dom; + } + /** + * Ensure focus on the inner editor whenever this node has focus. + * This helps to prevent accidental deletions of math blocks. + */ + ensureFocus() { + if (this._innerView && this._outerView.hasFocus()) { + this._innerView.focus(); + } + } + // == Updates ======================================= // + update(node, decorations) { + if (!node.sameMarkup(this._node)) return false; + this._node = node; + if (this._innerView) { + let state = this._innerView.state; + let start = node.content.findDiffStart(state.doc.content); + if (start != null) { + let diff = node.content.findDiffEnd(state.doc.content); + if (diff) { + let { a: endA, b: endB } = diff; + let overlap = start - Math.min(endA, endB); + if (overlap > 0) { + endA += overlap; + endB += overlap; + } + this._innerView.dispatch( + state.tr + .replace(start, endB, node.slice(start, endA)) + .setMeta('fromOutside', true), + ); + } + } + } + if (!this._isEditing) { + this.renderMath(); + } + return true; + } + updateCursorPos(state) { + const pos = this._getPos(); + const size = this._node.nodeSize; + const inPmSelection = + state.selection.from < pos + size && pos < state.selection.to; + if (!inPmSelection) { + this.cursorSide = pos < state.selection.from ? 'end' : 'start'; + } + } + // == Events ===================================== // + selectNode() { + this.dom.classList.add('ProseMirror-selectednode'); + if (!this._isEditing) { + this.openEditor(); + } + } + deselectNode() { + this.dom.classList.remove('ProseMirror-selectednode'); + if (this._isEditing) { + this.closeEditor(); + } + } + stopEvent(event) { + return ( + this._innerView !== undefined && + event.target !== undefined && + this._innerView.dom.contains(event.target) + ); + } + ignoreMutation() { + return true; + } + // == Rendering ===================================== // + renderMath() { + if (!this._mathRenderElt) { + return; + } + // get tex string to render + let content = this._node.content.content; + let texString = ''; + if (content.length > 0 && content[0].textContent !== null) { + texString = content[0].textContent.trim(); + } + // empty math? + if (texString.length < 1) { + this.dom.classList.add('empty-math'); + // clear rendered math, since this node is in an invalid state + while (this._mathRenderElt.firstChild) { + this._mathRenderElt.firstChild.remove(); + } + // do not render empty math + return; + } else { + this.dom.classList.remove('empty-math'); + } + // render katex, but fail gracefully + try { + katex.render(texString, this._mathRenderElt, this._katexOptions); + this._mathRenderElt.classList.remove('parse-error'); + this.dom.setAttribute('title', ''); + } catch (err) { + if (err instanceof ParseError) { + console.error(err); + this._mathRenderElt.classList.add('parse-error'); + this.dom.setAttribute('title', err.toString()); + } else { + throw err; + } + } + } + // == Inner Editor ================================== // + dispatchInner(tr) { + if (!this._innerView) { + return; + } + let { state, transactions } = this._innerView.state.applyTransaction(tr); + this._innerView.updateState(state); + if (!tr.getMeta('fromOutside')) { + let outerTr = this._outerView.state.tr, + offsetMap = StepMap.offset(this._getPos() + 1); + for (let i = 0; i < transactions.length; i++) { + let steps = transactions[i].steps; + for (let j = 0; j < steps.length; j++) { + let mapped = steps[j].map(offsetMap); + if (!mapped) { + throw Error('step discarded!'); + } + outerTr.step(mapped); + } + } + if (outerTr.docChanged) this._outerView.dispatch(outerTr); + } + } + openEditor() { + if (this._innerView) { + throw Error('inner view should not exist!'); + } + // create a nested ProseMirror view + this._innerView = new EditorView(this._mathSrcElt, { + state: EditorState.create({ + doc: this._node, + plugins: [ + keymap({ + Tab: (state, dispatch) => { + if (dispatch) { + dispatch(state.tr.insertText('\t')); + } + return true; + }, + Backspace: chainCommands( + deleteSelection, + (state, dispatch, tr_inner) => { + // default backspace behavior for non-empty selections + if (!state.selection.empty) { + return false; + } + // default backspace behavior when math node is non-empty + if (this._node.textContent.length > 0) { + return false; + } + // otherwise, we want to delete the empty math node and focus the outer view + this._outerView.dispatch( + this._outerView.state.tr.insertText(''), + ); + this._outerView.focus(); + return true; + }, + ), + Enter: newlineInCode, + 'Ctrl-Enter': (state, dispatch) => { + let { to } = this._outerView.state.selection; + let outerState = this._outerView.state; + // place cursor outside of math node + this._outerView.dispatch( + outerState.tr.setSelection( + TextSelection.create(outerState.doc, to), + ), + ); + // must return focus to the outer view, + // otherwise no cursor will appear + this._outerView.focus(); + return true; + }, + }), + ], + }), + dispatchTransaction: this.dispatchInner.bind(this), + }); + // focus element + let innerState = this._innerView.state; + this._innerView.focus(); + // determine cursor position + let pos = this.cursorSide == 'start' ? 0 : this._node.nodeSize - 2; + this._innerView.dispatch( + innerState.tr.setSelection(TextSelection.create(innerState.doc, pos)), + ); + this._isEditing = true; + } + /** + * Called when the inner ProseMirror editor should close. + * + * @param render Optionally update the rendered math after closing. (which + * is generally what we want to do, since the user is done editing!) + */ + closeEditor(render = true) { + if (this._innerView) { + this._innerView.destroy(); + this._innerView = undefined; + } + if (render) { + this.renderMath(); + } + this._isEditing = false; + } +} diff --git a/wax-prosemirror-plugins/src/math/math-plugin.js b/wax-prosemirror-plugins/src/math/math-plugin.js new file mode 100644 index 0000000000000000000000000000000000000000..aebe23521d4daf4ea5197ed2b59fac12b33d714d --- /dev/null +++ b/wax-prosemirror-plugins/src/math/math-plugin.js @@ -0,0 +1,68 @@ +/* eslint-disable */ +import { Plugin as ProsePlugin, PluginKey } from 'prosemirror-state'; +import { MathView } from './math-nodeview'; +/** + * Returns a function suitable for passing as a field in `EditorProps.nodeViews`. + * @param displayMode TRUE for block math, FALSE for inline math. + * @see https://prosemirror.net/docs/ref/#view.EditorProps.nodeViews + */ +function createMathView(displayMode) { + return (node, view, getPos) => { + /** @todo is this necessary? + * Docs says that for any function proprs, the current plugin instance + * will be bound to `this`. However, the typings don't reflect this. + */ + let pluginState = mathPluginKey.getState(view.state); + if (!pluginState) { + throw new Error('no math plugin!'); + } + let nodeViews = pluginState.activeNodeViews; + // set up NodeView + let nodeView = new MathView( + node, + view, + getPos, + { katexOptions: { displayMode, macros: pluginState.macros } }, + () => { + nodeViews.splice(nodeViews.indexOf(nodeView)); + }, + ); + nodeViews.push(nodeView); + return nodeView; + }; +} +let mathPluginKey = new PluginKey('prosemirror-math'); +let mathPluginSpec = { + key: mathPluginKey, + state: { + init(config, instance) { + return { + macros: {}, + activeNodeViews: [], + }; + }, + apply(tr, value, oldState, newState) { + /** @todo (8/21/20) + * since new state has not been fully applied yet, we don't yet have + * information about any new MathViews that were created by this transaction. + * As a result, the cursor position may be wrong for any newly created math blocks. + */ + let pluginState = mathPluginKey.getState(oldState); + if (pluginState) { + for (let mathView of pluginState.activeNodeViews) { + mathView.updateCursorPos(newState); + } + } + return value; + }, + }, + props: { + nodeViews: { + math_inline: createMathView(false), + math_display: createMathView(true), + }, + }, +}; +const mathPlugin = new ProsePlugin(mathPluginSpec); + +export default mathPlugin; diff --git a/wax-prosemirror-plugins/src/math/math-select.js b/wax-prosemirror-plugins/src/math/math-select.js new file mode 100644 index 0000000000000000000000000000000000000000..25989cb3d845525bf4f6971f3c2125ad3620fc52 --- /dev/null +++ b/wax-prosemirror-plugins/src/math/math-select.js @@ -0,0 +1,66 @@ +/* eslint-disable */ + +// prosemirror imports +import { Plugin as ProsePlugin } from 'prosemirror-state'; +import { DecorationSet, Decoration } from 'prosemirror-view'; +//////////////////////////////////////////////////////////// +/** + * Uses the selection to determine which math_select decorations + * should be applied to the given document. + * @param arg Should be either a Transaction or an EditorState, + * although any object with `selection` and `doc` will work. + */ +let checkSelection = arg => { + let { from, to } = arg.selection; + let content = arg.selection.content().content; + let result = []; + content.descendants((node, pos, parent) => { + if (node.type.name == 'text') { + return false; + } + if (node.type.name.startsWith('math_')) { + result.push({ + start: Math.max(from + pos - 1, 0), + end: from + pos + node.nodeSize - 1, + }); + return false; + } + return true; + }); + return DecorationSet.create( + arg.doc, + result.map(({ start, end }) => + Decoration.node(start, end, { class: 'math-select' }), + ), + ); +}; +/** + * Due to the internals of KaTeX, by default, selecting rendered + * math will put a box around each individual character of a + * math expression. This plugin attempts to make math selections + * slightly prettier by instead setting a background color on the node. + * + * (remember to use the included math.css!) + * + * @todo (6/13/20) math selection rectangles are not quite even with text + */ +const mathSelectPlugin = new ProsePlugin({ + state: { + init(config, partialState) { + return checkSelection(partialState); + }, + apply(tr, oldState) { + if (!tr.selection || !tr.selectionSet) { + return oldState; + } + let sel = checkSelection(tr); + return sel; + }, + }, + props: { + decorations: state => { + return mathSelectPlugin.getState(state); + }, + }, +}); +export default mathSelectPlugin; diff --git a/wax-prosemirror-schema/.gitignore b/wax-prosemirror-schema/.gitignore index deb5ee0e0e98566ca4064349d5e68cbab9bfed1c..b3e3ccb6b0ce3a90e1eb3f9e78da7924ea89f116 100644 --- a/wax-prosemirror-schema/.gitignore +++ b/wax-prosemirror-schema/.gitignore @@ -7,6 +7,9 @@ # production /build +# dist +/dist + # misc .DS_Store .env.local diff --git a/wax-prosemirror-schema/index.js b/wax-prosemirror-schema/index.js index d821cda25f31af100d0d6f5cd35b7b4acc9068fd..6e9de4854916088bdc7427bce55024fb193f5953 100644 --- a/wax-prosemirror-schema/index.js +++ b/wax-prosemirror-schema/index.js @@ -12,6 +12,7 @@ export { default as underlineMark } from './src/marks/underlineMark'; export { default as smallcapsMark } from './src/marks/smallcapsMark'; export { default as sourceMark } from './src/marks/sourceMark'; export { default as commentMark } from './src/marks/commentMark'; +export { default as mathSelectMark } from './src/marks/mathSelectMark'; /* LIST OF TRACK CHANGES MARKS */ @@ -37,6 +38,8 @@ export { default as headingNode } from './src/nodes/headingNode'; export { default as blockQuoteNode } from './src/nodes/blockQuoteNode'; export { default as footNoteNode } from './src/nodes/footNoteNode'; export { default as codeBlockNode } from './src/nodes/codeBlockNode'; +export { default as mathInlineNode } from './src/nodes/mathInlineNode'; +export { default as mathDisplayNode } from './src/nodes/mathDisplayNode'; /* LIST OF TRACK CHANGES NODES */ diff --git a/wax-prosemirror-schema/src/marks/mathSelectMark.js b/wax-prosemirror-schema/src/marks/mathSelectMark.js new file mode 100644 index 0000000000000000000000000000000000000000..bda8ec0cc19ca085679b1b2a30efc99f09f2d0eb --- /dev/null +++ b/wax-prosemirror-schema/src/marks/mathSelectMark.js @@ -0,0 +1,8 @@ +const mathSelectMark = { + toDOM() { + return ['math-select', 0]; + }, + parseDOM: [{ tag: 'math-select' }], +}; + +export default mathSelectMark; diff --git a/wax-prosemirror-schema/src/nodes/mathDisplayNode.js b/wax-prosemirror-schema/src/nodes/mathDisplayNode.js new file mode 100644 index 0000000000000000000000000000000000000000..745e2215bdaaa7a27418147e670297a348babefe --- /dev/null +++ b/wax-prosemirror-schema/src/nodes/mathDisplayNode.js @@ -0,0 +1,14 @@ +const mathDisplayNode = { + group: 'block math', + content: 'text*', + atom: true, + code: true, + toDOM: () => ['math-display', { class: 'math-node' }, 0], + parseDOM: [ + { + tag: 'math-display', + }, + ], +}; + +export default mathDisplayNode; diff --git a/wax-prosemirror-schema/src/nodes/mathInlineNode.js b/wax-prosemirror-schema/src/nodes/mathInlineNode.js new file mode 100644 index 0000000000000000000000000000000000000000..ff890f1c1b7eb916839014ffff8f85eb88dd2fe1 --- /dev/null +++ b/wax-prosemirror-schema/src/nodes/mathInlineNode.js @@ -0,0 +1,14 @@ +const mathInlineNode = { + group: 'inline math', + content: 'text*', + inline: true, + atom: true, + toDOM: () => ['math-inline', { class: 'math-node' }, 0], + parseDOM: [ + { + tag: 'math-inline', + }, + ], +}; + +export default mathInlineNode; diff --git a/wax-prosemirror-services/.gitignore b/wax-prosemirror-services/.gitignore index deb5ee0e0e98566ca4064349d5e68cbab9bfed1c..b3e3ccb6b0ce3a90e1eb3f9e78da7924ea89f116 100644 --- a/wax-prosemirror-services/.gitignore +++ b/wax-prosemirror-services/.gitignore @@ -7,6 +7,9 @@ # production /build +# dist +/dist + # misc .DS_Store .env.local diff --git a/wax-prosemirror-services/index.js b/wax-prosemirror-services/index.js index e9b9a02f04569a8859c17e9a1bcde2253901823e..6171f6a4a996f36be204f37cfd4b2fec809645c7 100644 --- a/wax-prosemirror-services/index.js +++ b/wax-prosemirror-services/index.js @@ -2,9 +2,8 @@ export { default as Service } from './src/Service'; export { default as LayoutService } from './src/LayoutService/LayoutService'; export { default as MenuService } from './src/MenuService/MenuService'; -export { default as LinkService } from './src/LinkService/LinkService'; -export { default as PlaceholderService } from './src/PlaceholderService/PlaceholderService'; export { default as OverlayService } from './src/OverlayService/OverlayService'; +export { default as PlaceholderService } from './src/PlaceholderService/PlaceholderService'; export { default as ImageService } from './src/ImageService/ImageService'; export { default as RulesService } from './src/RulesService/RulesService'; export { default as SchemaService } from './src/SchemaService/SchemaService'; @@ -12,9 +11,7 @@ export { default as SchemaService } from './src/SchemaService/SchemaService'; export { default as ShortCutsService } from './src/ShortCutsService/ShortCutsService'; export { default as Tool } from './src/lib/Tools'; -export { default as TrackChangeService } from './src/TrackChangeService/TrackChangeService'; -export { default as trackedTransaction } from './src/TrackChangeService/track-changes/trackedTransaction'; /* All Elements services */ @@ -27,6 +24,11 @@ export { default as DisplayBlockLevelService } from './src/DisplayBlockLevel/Dis export { default as NoteService } from './src/NoteService/NoteService'; export { default as CommentsService } from './src/CommentsService/CommentsService'; export { default as CodeBlockService } from './src/CodeBlockService/CodeBlockService'; +export { default as LinkService } from './src/LinkService/LinkService'; +export { default as TrackChangeService } from './src/TrackChangeService/TrackChangeService'; +export { default as trackedTransaction } from './src/TrackChangeService/track-changes/trackedTransaction'; +export { default as MathService } from './src/MathService/MathService'; + /* ToolGroups */ diff --git a/wax-prosemirror-services/package.json b/wax-prosemirror-services/package.json index 13876b3a1ef9da9287998c8a1fbee9e73933e41e..60282baf22c8b50cfbb1aa55994b2693a14d4b68 100644 --- a/wax-prosemirror-services/package.json +++ b/wax-prosemirror-services/package.json @@ -23,6 +23,7 @@ "prosemirror-schema-list": "1.1.4", "prosemirror-state": "1.3.3", "prosemirror-transform": "1.2.6", + "prosemirror-inputrules": "1.1.2", "prosemirror-view": "1.15.2", "styled-components": "^4.2.0", "uuid": "^7.0.3", diff --git a/wax-prosemirror-services/src/MathService/BlockInputRule.js b/wax-prosemirror-services/src/MathService/BlockInputRule.js new file mode 100644 index 0000000000000000000000000000000000000000..1b13412fb2e9737bc3ae85717ebb91c0c69b8420 --- /dev/null +++ b/wax-prosemirror-services/src/MathService/BlockInputRule.js @@ -0,0 +1,23 @@ +/* eslint-disable */ +import { InputRule } from 'prosemirror-inputrules'; +import { NodeSelection } from 'prosemirror-state'; + +const blockInputRule = (pattern, nodeType, getAttrs) => { + return new InputRule(pattern, (state, match, start, end) => { + let $start = state.doc.resolve(start); + let attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; + if ( + !$start + .node(-1) + .canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType) + ) + return null; + let tr = state.tr + .delete(start, end) + .setBlockType(start, start, nodeType, attrs); + return tr.setSelection( + NodeSelection.create(tr.doc, tr.mapping.map($start.pos - 1)), + ); + }); +}; +export default blockInputRule; diff --git a/wax-prosemirror-services/src/MathService/InlineInputRule.js b/wax-prosemirror-services/src/MathService/InlineInputRule.js new file mode 100644 index 0000000000000000000000000000000000000000..d0ce6c5703b674942cbdf4711404a68667d4b57d --- /dev/null +++ b/wax-prosemirror-services/src/MathService/InlineInputRule.js @@ -0,0 +1,23 @@ +import { InputRule } from 'prosemirror-inputrules'; + +const inlineInputRule = (pattern, nodeType, getAttrs) => { + return new InputRule(pattern, (state, match, start, end) => { + const $start = state.doc.resolve(start); + const index = $start.index(); + const $end = state.doc.resolve(end); + // get attrs + const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; + // check if replacement valid + if (!$start.parent.canReplaceWith(index, $end.index(), nodeType)) { + return null; + } + // perform replacement + return state.tr.replaceRangeWith( + start, + end, + nodeType.create(attrs, nodeType.schema.text(match[1])), + ); + }); +}; + +export default inlineInputRule; diff --git a/wax-prosemirror-services/src/MathService/MathService.js b/wax-prosemirror-services/src/MathService/MathService.js new file mode 100644 index 0000000000000000000000000000000000000000..8584f727995bc348a6e8fb1d26e828f13d9a1bb1 --- /dev/null +++ b/wax-prosemirror-services/src/MathService/MathService.js @@ -0,0 +1,44 @@ +import { + mathDisplayNode, + mathInlineNode, + mathSelectMark, +} from 'wax-prosemirror-schema'; +import { mathPlugin, mathSelectPlugin } from 'wax-prosemirror-plugins'; +import Service from '../Service'; +import inlineInputRule from './InlineInputRule'; +import blockInputRule from './BlockInputRule'; + +class MathService extends Service { + name = 'MathService'; + + boot() { + this.app.PmPlugins.add('mathplugin', mathPlugin); + this.app.PmPlugins.add('mathselectplugin', mathSelectPlugin); + const schema = this.container.get('Schema'); + const rules = this.container.get('Rules'); + const newRules = [ + inlineInputRule( + /(?<!\\)\$(.+)(?<!\\)\$/, + schema.schema.nodes.math_inline, + ), + blockInputRule(/^\$\$\s+$/, schema.schema.nodes.math_display), + ]; + // rules.addRule(newRules); + } + + register() { + const createNode = this.container.get('CreateNode'); + const createMark = this.container.get('CreateMark'); + createNode({ + math_display: mathDisplayNode, + }); + createNode({ + math_inline: mathInlineNode, + }); + createMark({ + math_select: mathSelectMark, + }); + } +} + +export default MathService; diff --git a/wax-prosemirror-services/src/NoteService/Editor.js b/wax-prosemirror-services/src/NoteService/Editor.js index 88a3b7298da028fa2c868c2eaf4fc580115ed138..cc569e9c8299fe0f5d3a458278600239979ce53a 100644 --- a/wax-prosemirror-services/src/NoteService/Editor.js +++ b/wax-prosemirror-services/src/NoteService/Editor.js @@ -46,6 +46,9 @@ export default ({ node, view }) => { handleKeyPress: (noteEditorView, from, to, content) => { updateMainView = false; }, + attributes: { + spellcheck: 'false', + }, }, ); diff --git a/wax-prosemirror-services/src/RulesService/Rules.js b/wax-prosemirror-services/src/RulesService/Rules.js index bb876783218e38e2bbc00b62ee9dc8df7050fca0..107bbd0256ce6a7408c8097753c6ea9925585af5 100644 --- a/wax-prosemirror-services/src/RulesService/Rules.js +++ b/wax-prosemirror-services/src/RulesService/Rules.js @@ -6,6 +6,10 @@ import { smartQuotes, } from 'prosemirror-inputrules'; +// TODO add through service. +import inlineInputRule from '../MathService/InlineInputRule'; +import blockInputRule from '../MathService/BlockInputRule'; + @injectable() class Rules { constructor(plugins, schema) { @@ -17,6 +21,7 @@ class Rules { addRule(rules) { this.extendedRules.push(...rules); + // this.extendedRules = this.allRules().concat(...rules); } createRules() { @@ -50,6 +55,8 @@ class Rules { this.schema.nodes.heading, match => ({ level: match[1].length }), ), + inlineInputRule(/(?<!\\)\$(.+)(?<!\\)\$/, this.schema.nodes.math_inline), + blockInputRule(/^\$\$\s+$/, this.schema.nodes.math_display), ]; } } diff --git a/wax-prosemirror-services/src/ShortCutsService/ShortCuts.js b/wax-prosemirror-services/src/ShortCutsService/ShortCuts.js index 2370331b4a262d70b71879fabcfc58ed803dcdfa..3d5ceac0c6495a988d231ec74fd5b26d1d2bc8b2 100644 --- a/wax-prosemirror-services/src/ShortCutsService/ShortCuts.js +++ b/wax-prosemirror-services/src/ShortCutsService/ShortCuts.js @@ -1,5 +1,4 @@ import { injectable } from 'inversify'; -import { minBy, maxBy } from 'lodash'; import { keymap } from 'prosemirror-keymap'; import { undo, redo } from 'prosemirror-history'; @@ -9,6 +8,7 @@ import { liftListItem, sinkListItem, } from 'prosemirror-schema-list'; +import { NodeSelection, TextSelection } from 'prosemirror-state'; import { baseKeymap, @@ -26,12 +26,37 @@ const backSpace = chainCommands( selectNodeBackward, ); -const backSpaceShortCut = (state, dispatch, view) => +const backSpaceShortCut = (state, dispatch, view) => { + const { $from, $to } = state.selection; + const { nodeBefore } = $from; + if (!nodeBefore) { + return false; + } + + if (nodeBefore.type.name === 'math_inline') { + const index = $from.index($from.depth); + const $beforePos = state.doc.resolve($from.posAtIndex(index - 1)); + + dispatch(state.tr.setSelection(new NodeSelection($beforePos))); + + return true; + } + + state.doc.nodesBetween($from.pos, $to.pos, (node, from) => { + if (node.type.name === 'math_display') { + const $start = state.tr.doc.resolve(state.tr.selection.$anchor.start()); + const $end = state.tr.doc.resolve(state.tr.selection.$anchor.end()); + + dispatch(state.tr.setSelection(new TextSelection($start, $end))); + } + }); + backSpace( state, tr => dispatch(tr.setMeta('inputType', 'backwardsDelete')), view, ); +}; const undoShortCut = (state, dispatch, view) => undo(state, tr => dispatch(tr.setMeta('inputType', 'Undo')), view); diff --git a/wax-prosemirror-utilities/.gitignore b/wax-prosemirror-utilities/.gitignore index deb5ee0e0e98566ca4064349d5e68cbab9bfed1c..b3e3ccb6b0ce3a90e1eb3f9e78da7924ea89f116 100644 --- a/wax-prosemirror-utilities/.gitignore +++ b/wax-prosemirror-utilities/.gitignore @@ -7,6 +7,9 @@ # production /build +# dist +/dist + # misc .DS_Store .env.local diff --git a/wax-prosemirror-utilities/src/document/DocumentHelpers.js b/wax-prosemirror-utilities/src/document/DocumentHelpers.js index 969c6daf152815137a53476a23d2be26f0ce3900..b5b0f7b9eeeeb2302f0c116f53bed69ceba0f39e 100644 --- a/wax-prosemirror-utilities/src/document/DocumentHelpers.js +++ b/wax-prosemirror-utilities/src/document/DocumentHelpers.js @@ -1,3 +1,5 @@ +import { isObject } from 'lodash'; + const findMark = (state, PMmark, toArr = false) => { const { selection: { $from, $to }, @@ -25,57 +27,48 @@ const findMark = (state, PMmark, toArr = false) => { return markFound; }; -// const getSelectionMark = (state, PMmark) => { -// const { -// selection: { $from, $to }, -// doc, -// } = state; -// let markFound; -// doc.nodesBetween($from.pos, $to.pos, (node, from) => { -// if (node.marks) { -// const actualMark = node.marks.find(mark => mark.type === PMmark); -// if (actualMark) { -// markFound = { -// from, -// to: from + node.nodeSize, -// attrs: actualMark.attrs, -// }; -// } -// } -// }); -// -// return markFound; -// }; - -/* this is a workaround for now to find marks - that are pm will break them. +/* TODO */ +/* this is a hacky workaround for now to find marks + that are pm will break them. Correct way is to be done + by the code that is comment out, but sometimes it doesn't return + the mark altouhgh it works for any other mark. Find out y? */ const findFragmentedMark = (state, PMmark) => { const { selection: { $from, $to }, doc, } = state; - const fromPos = [$from.pos - 1, $from.pos]; - const toPos = [$to.pos - 1, $to.pos]; + + // const type = state.config.schema.marks.comment; + // const mark = empty + // ? type.isInSet(state.storedMarks || $from.marks()) + // : state.doc.rangeHasMark(from, to, type); + // + + // if (isObject(mark)) + // return { + // from, + // to, + // attrs: mark.attrs, + // }; + // + // // return undefined; + let markFound; - for (let i = 0; i < fromPos.length; i++) { - doc.nodesBetween(fromPos[i], toPos[i], (node, from) => { - if (node.marks) { - const actualMark = node.marks.find(mark => mark.type === PMmark); - if (actualMark) { - markFound = { - from, - to: from + node.nodeSize, - attrs: actualMark.attrs, - }; - } + doc.nodesBetween($from.pos - 1, $to.pos, (node, from) => { + if (node.marks) { + const actualMark = node.marks.find(mark => mark.type === PMmark); + if (actualMark) { + markFound = { + from, + to: from + node.nodeSize, + attrs: actualMark.attrs, + }; } - }); - if (markFound) { - return markFound; } - } + }); + return markFound; }; diff --git a/yarn.lock b/yarn.lock index af9c52dcdbfa1966b6c5aff21c29b08120fffedf..85d6337242045a0ffa7e0089193c40e426b7c43e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10905,6 +10905,13 @@ jsx-ast-utils@^2.2.1, jsx-ast-utils@^2.2.3, jsx-ast-utils@^2.4.1: array-includes "^3.1.1" object.assign "^4.1.0" +katex@^0.12.0: + version "0.12.0" + resolved "https://registry.yarnpkg.com/katex/-/katex-0.12.0.tgz#2fb1c665dbd2b043edcf8a1f5c555f46beaa0cb9" + integrity sha512-y+8btoc/CK70XqcHqjxiGWBOeIL8upbS0peTPXTvgrh21n1RiWWcIpSWM+4uXq+IAgNh9YYQWdc7LVDPDAEEAg== + dependencies: + commander "^2.19.0" + killable@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/killable/-/killable-1.0.1.tgz#4c8ce441187a061c7474fb87ca08e2a638194892"