Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@lerna-lite/publish": "^4.10.5",
"@lerna-lite/run": "^4.10.5",
"@lerna-lite/version": "^4.10.5",
"@standardnotes/component-relay": "standardnotes/component-relay#632daf1ac731e77bb1bc0ef8db21160868de6048",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"@typescript-eslint/parser": "^5.20.0",
"changelog-parser": "^2.8.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/com.sncommunity.advanced-checklist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"@reach/visually-hidden": "0.16.0",
"@react-hook/resize-observer": "^1.2.5",
"@reduxjs/toolkit": "1.8.0",
"@standardnotes/editor-kit": "standardnotes/editor-kit#46f753b8a00f581d2428687fd269ec299f9da2c2",
"@standardnotes/editor-kit": "standardnotes/editor-kit#fc7d1121f553cbb4cfb577d46c44cae07c87a511",
"@standardnotes/stylekit": "5.23.0",
"@testing-library/dom": "8.11.3",
"@testing-library/jest-dom": "5.16.2",
Expand Down
4 changes: 4 additions & 0 deletions packages/com.sncommunity.bold-editor/app/components/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ export default class Editor extends React.Component {
if (!this.redactor.editor.isEmpty()) {
this.redactor.editor.endFocus();
}

this.editorKit.registerScrollContainer(document.scrollingElement, {
moveCaretToEnd: () => this.redactor.editor.endFocus()
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/com.sncommunity.bold-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@babel/eslint-parser": "^7.13.14",
"@babel/preset-env": "^7.13.12",
"@babel/preset-react": "^7.13.13",
"@standardnotes/editor-kit": "standardnotes/editor-kit#46f753b8a00f581d2428687fd269ec299f9da2c2",
"@standardnotes/editor-kit": "standardnotes/editor-kit#fc7d1121f553cbb4cfb577d46c44cae07c87a511",
"babel-loader": "^8.2.2",
"copy-webpack-plugin": "*",
"css-loader": "^5.2.0",
Expand Down
23 changes: 23 additions & 0 deletions packages/com.sncommunity.markdown-basic/app/components/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default class Home extends React.Component {

this.configureMarkdown();
this.connectToBridge();
this.registerScrollContainer();
this.updatePreviewText();
this.addChangeListener();

Expand All @@ -41,6 +42,27 @@ export default class Home extends React.Component {
];
}

componentDidUpdate(prevProps, prevState) {
if (prevState.mode !== this.state.mode) {
this.registerScrollContainer();
}
}

registerScrollContainer() {
if (this.state.mode.mode === PreviewMode) {
this.scrollContainer = this.componentRelay.registerScrollContainer(this.preview);
return;
}

this.scrollContainer = this.componentRelay.registerScrollContainer(this.editor, {
moveCaretToEnd: () => {
const end = this.editor.value.length;
this.editor.focus({ preventScroll: true });
this.editor.setSelectionRange(end, end);
},
});
}

UNSAFE_componentWillUpdate(nextProps, nextState) {
let prevMode = this.state.mode.mode;
let nextMode = nextState.mode.mode;
Expand Down Expand Up @@ -133,6 +155,7 @@ export default class Home extends React.Component {

this.editor.value = note.content.text;
this.preview.innerHTML = this.markdown.render(note.content.text);
this.scrollContainer.notifyContentChange();

document.getElementById('editor').setAttribute(
'spellcheck',
Expand Down
2 changes: 1 addition & 1 deletion packages/com.sncommunity.markdown-basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@babel/preset-stage-0": "^7.8.3",
"@babel/register": "^7.10.5",
"@babel/runtime": "^7.11.2",
"@standardnotes/component-relay": "standardnotes/component-relay#77c1c70dd48facb8f2e3b47a62d26ff5810d79ee",
"@standardnotes/component-relay": "standardnotes/component-relay#632daf1ac731e77bb1bc0ef8db21160868de6048",
"@standardnotes/eslint-config-extensions": "^1.0.0",
"babel-loader": "^8.1.0",
"copy-webpack-plugin": "*",
Expand Down
2 changes: 1 addition & 1 deletion packages/com.sncommunity.markdown-math/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@babel/cli": "^7.7.7",
"@babel/core": "^7.7.7",
"@babel/preset-env": "^7.7.7",
"@standardnotes/component-relay": "standardnotes/component-relay#77c1c70dd48facb8f2e3b47a62d26ff5810d79ee",
"@standardnotes/component-relay": "standardnotes/component-relay#632daf1ac731e77bb1bc0ef8db21160868de6048",
"draggabilly": "^2.2.0",
"grunt": "^1.0.4",
"grunt-babel": "^8.0.0",
Expand Down
12 changes: 12 additions & 0 deletions packages/com.sncommunity.markdown-math/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ document.addEventListener('DOMContentLoaded', function (event) {
},
})

// The textarea decorator wraps the textarea in the element that scrolls
componentRelay.registerScrollContainer(editor.closest('.ldt'), {
moveCaretToEnd: () => {
const end = editor.value.length
editor.focus({ preventScroll: true })
editor.setSelectionRange(end, end)
},
// The preview only follows the source while the source leads, which hovering the preview would otherwise change
beforeScrollToEnd: () => window.upmath.lockScrollToSrc(),
afterScrollToEnd: () => window.upmath.unlockScrollToSrc(),
})

componentRelay.streamContextItem((note) => {
workingNote = note

Expand Down
19 changes: 17 additions & 2 deletions packages/com.sncommunity.markdown-math/vendor/upmath/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,16 @@
eTextarea.addEventListener('touchstart', syncScroll.switchScrollToSrc);
eTextarea.addEventListener('mouseover', syncScroll.switchScrollToSrc);

eResultHtml.addEventListener('touchstart', syncScroll.switchScrollToResult);
eResultHtml.addEventListener('mouseover', syncScroll.switchScrollToResult);
// While locked, hovering the preview mustn't make it lead, or it overwrites the source's scroll position
var isScrollLockedToSrc = false;
var switchScrollToResult = function () {
if (!isScrollLockedToSrc) {
syncScroll.switchScrollToResult();
}
};

eResultHtml.addEventListener('touchstart', switchScrollToResult);
eResultHtml.addEventListener('mouseover', switchScrollToResult);

syncScroll.switchScrollToSrc();

Expand Down Expand Up @@ -574,6 +582,13 @@
getHTML: () => {
var result = document.getElementsByClassName('result-html');
return eResultHtml.innerHTML;
},
lockScrollToSrc: () => {
isScrollLockedToSrc = true;
syncScroll.switchScrollToSrc();
},
unlockScrollToSrc: () => {
isScrollLockedToSrc = false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/com.sncommunity.markdown-visual/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"test": "echo \"Error: no test specified\" && exit 0"
},
"dependencies": {
"@standardnotes/editor-kit": "standardnotes/editor-kit#46f753b8a00f581d2428687fd269ec299f9da2c2",
"@standardnotes/editor-kit": "standardnotes/editor-kit#fc7d1121f553cbb4cfb577d46c44cae07c87a511",
"@standardnotes/styles": "1.6.1"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defaultValueCtx, Editor, editorViewOptionsCtx, rootCtx } from '@milkdown/core'
import { defaultValueCtx, Editor, editorViewCtx, editorViewOptionsCtx, rootCtx } from '@milkdown/core'
import { clipboard } from '@milkdown/plugin-clipboard'
import { cursor } from '@milkdown/plugin-cursor'
import { diagram } from '@milkdown/plugin-diagram'
Expand All @@ -7,6 +7,7 @@ import { indent } from '@milkdown/plugin-indent'
import { listener, listenerCtx } from '@milkdown/plugin-listener'
import { math } from '@milkdown/plugin-math'
import { prism } from '@milkdown/plugin-prism'
import { EditorView } from '@milkdown/prose'
import { slash } from '@milkdown/plugin-slash'
import { tooltip } from '@milkdown/plugin-tooltip'
import { gfm } from '@milkdown/preset-gfm'
Expand All @@ -18,21 +19,34 @@ import { MenuConfig } from './plugins/advanced-menu/config'
export type CreateEditorParams = {
root: HTMLElement | null
onChange: (text: string) => void
/** Called each time the editor is created, which replaces its DOM */
onMounted: (view: EditorView) => void
value?: string
menuConfig: MenuConfig
editable: boolean
spellcheck: boolean
}

export const createEditor = ({ root, onChange, value, menuConfig, editable, spellcheck }: CreateEditorParams) => {
export const createEditor = ({
root,
onChange,
onMounted,
value,
menuConfig,
editable,
spellcheck,
}: CreateEditorParams) => {
const editor = Editor.make()
.config((ctx) => {
ctx.set(rootCtx, root)
value && ctx.set(defaultValueCtx, value)

ctx.get(listenerCtx).markdownUpdated((_, markdown) => {
onChange(markdown)
})
ctx
.get(listenerCtx)
.markdownUpdated((_, markdown) => {
onChange(markdown)
})
.mounted((ctx) => onMounted(ctx.get(editorViewCtx)))

ctx.set(editorViewOptionsCtx, {
editable: () => editable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ export type MilkdownRef = {

type MilkdownProps = {
onChange: CreateEditorParams['onChange']
onMounted: CreateEditorParams['onMounted']
value?: CreateEditorParams['value']
menuConfig: MenuConfig
editable: CreateEditorParams['editable']
spellcheck: CreateEditorParams['spellcheck']
}

const Milkdown = (
{ onChange, value, menuConfig, editable, spellcheck }: MilkdownProps,
{ onChange, onMounted, value, menuConfig, editable, spellcheck }: MilkdownProps,
ref: React.ForwardedRef<MilkdownRef>,
) => {
const editorRef = useRef<EditorRef>(null)
Expand Down Expand Up @@ -58,13 +59,14 @@ const Milkdown = (
return createEditor({
root,
onChange,
onMounted,
value,
menuConfig,
editable,
spellcheck,
})
},
[value, onChange, value, menuConfig, editable, spellcheck],
[value, onChange, onMounted, value, menuConfig, editable, spellcheck],
)

return (
Expand Down
11 changes: 11 additions & 0 deletions packages/com.sncommunity.markdown-visual/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import MilkdownEditor, { MilkdownRef } from './components/Milkdown'
import SplitView, { SplitViewDirection } from './components/SplitView'

import EditorKit, { EditorKitDelegate } from '@standardnotes/editor-kit'
import { EditorView, Selection } from '@milkdown/prose'
import { marked } from 'marked'

import { MenuConfig, menuConfig } from './components/Milkdown/plugins/advanced-menu/config'
Expand Down Expand Up @@ -147,6 +148,15 @@ class AppWrapper extends Component<AppProps, AppState> {
}
}

private registerScrollContainer = (view: EditorView) => {
this.editorKit!.registerScrollContainer(view.dom.closest('.milkdown') as HTMLElement, {
moveCaretToEnd: () => {
view.focus()
view.dispatch(view.state.tr.setSelection(Selection.atEnd(view.state.doc)))
},
})
}

private toggleSplitView = () => {
const { splitView } = this.state

Expand Down Expand Up @@ -198,6 +208,7 @@ class AppWrapper extends Component<AppProps, AppState> {
<MilkdownEditor
ref={this.milkdownRef}
onChange={this.onTextChange}
onMounted={this.registerScrollContainer}
value={this.prevText}
menuConfig={customMenu}
editable={editable}
Expand Down
2 changes: 1 addition & 1 deletion packages/com.sncommunity.minimal-markdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"devDependencies": {
"@babel/core": "^7.11.1",
"@babel/preset-env": "^7.11.0",
"@standardnotes/component-relay": "standardnotes/component-relay#77c1c70dd48facb8f2e3b47a62d26ff5810d79ee",
"@standardnotes/component-relay": "standardnotes/component-relay#632daf1ac731e77bb1bc0ef8db21160868de6048",
"babel-cli": "^6.26.0",
"codemirror": "^5.56.0",
"grunt": "^1.2.1",
Expand Down
9 changes: 9 additions & 0 deletions packages/com.sncommunity.minimal-markdown/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ document.addEventListener('DOMContentLoaded', function (event) {
}
saveNote()
})

const { notifyContentChange } = componentRelay.registerScrollContainer(editor.getScrollerElement(), {
moveCaretToEnd: () => {
editor.focus()
editor.execCommand('goDocEnd')
},
})
// CodeMirror sizes its content area through style changes, which the relay doesn't observe
editor.on('update', notifyContentChange)
}

function getInputStyleForEnvironment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"skip:format": "prettier --write 'src/**/*.{html,css,scss,js,jsx,ts,tsx,json}' README.md"
},
"dependencies": {
"@standardnotes/component-relay": "standardnotes/component-relay#77c1c70dd48facb8f2e3b47a62d26ff5810d79ee",
"@standardnotes/component-relay": "standardnotes/component-relay#632daf1ac731e77bb1bc0ef8db21160868de6048",
"ttag": "^1.8.12"
},
"devDependencies": {
Expand Down
Loading
Loading