Mithril 2 Update (#19)

Update for Mithril 2
This commit is contained in:
Alexander Skvortsov 2020-09-23 22:51:50 -04:00 committed by GitHub
parent 5081cd47c1
commit ab63a55d60
3 changed files with 23 additions and 23 deletions

View File

@ -5,17 +5,19 @@ import apply from '../util/apply';
const modifierKey = navigator.userAgent.match(/Macintosh/) ? '⌘' : 'ctrl'; const modifierKey = navigator.userAgent.match(/Macintosh/) ? '⌘' : 'ctrl';
export default class MarkdownButton extends Component { export default class MarkdownButton extends Component {
config(isInitialized) { oncreate(vnode) {
if (isInitialized) return; super.oncreate(vnode);
this.$().tooltip(); this.$().tooltip();
} }
view() { view() {
return <button className="Button Button--icon Button--link" title={this.title()} data-hotkey={this.props.hotkey} return (
onclick={this.click.bind(this)} onkeydown={this.keydown.bind(this)}> <button className="Button Button--icon Button--link" title={this.title()} data-hotkey={this.attrs.hotkey}
{icon(this.props.icon)} onclick={this.click.bind(this)} onkeydown={this.keydown.bind(this)}>
</button>; {icon(this.attrs.icon)}
</button>
);
} }
keydown(event) { keydown(event) {
@ -26,13 +28,13 @@ export default class MarkdownButton extends Component {
} }
click() { click() {
return apply(this.element, this.props.style); return apply(this.element, this.attrs.style);
} }
title() { title() {
let tooltip = this.props.title; let tooltip = this.attrs.title;
if (this.props.hotkey) tooltip += ` <${modifierKey}-${this.props.hotkey}>`; if (this.attrs.hotkey) tooltip += ` <${modifierKey}-${this.attrs.hotkey}>`;
return tooltip; return tooltip;
} }

View File

@ -3,17 +3,17 @@ import Component from 'flarum/Component';
const modifierKey = navigator.userAgent.match(/Macintosh/) ? 'Meta' : 'Control'; const modifierKey = navigator.userAgent.match(/Macintosh/) ? 'Meta' : 'Control';
export default class MarkdownToolbar extends Component { export default class MarkdownToolbar extends Component {
config(isInitialized) { oncreate(vnode) {
if (isInitialized) return; super.oncreate(vnode);
const field = document.getElementById(this.props.for); const field = document.getElementById(this.attrs.for);
field.addEventListener('keydown', this.shortcut.bind(this)); field.addEventListener('keydown', this.shortcut.bind(this));
} }
view() { view(vnode) {
return <div id="MarkdownToolbar" data-for={this.props.for} style={{ display: 'inline-block' }}> return <div id="MarkdownToolbar" data-for={this.attrs.for} style={{ display: 'inline-block' }}>
{this.props.children} {vnode.children}
</div>; </div>;
} }

View File

@ -17,7 +17,7 @@ import MarkdownButton from './components/MarkdownButton';
app.initializers.add('flarum-markdown', function(app) { app.initializers.add('flarum-markdown', function(app) {
let index = 1; let index = 1;
extend(TextEditor.prototype, 'init', function() { extend(TextEditor.prototype, 'oninit', function() {
this.textareaId = 'textarea'+(index++); this.textareaId = 'textarea'+(index++);
}); });
@ -25,19 +25,17 @@ app.initializers.add('flarum-markdown', function(app) {
vdom.children[0].attrs.id = this.textareaId; vdom.children[0].attrs.id = this.textareaId;
}); });
extend(TextEditor.prototype, 'configTextarea', function(value, element, isInitialized, context) { extend(TextEditor.prototype, 'oncreate', function() {
if (isInitialized) return; this.editor = new MarkdownArea(this.$('textarea')[0], {
const editor = new MarkdownArea(element, {
keyMap: { keyMap: {
indent: ['Ctrl+m'], indent: ['Ctrl+m'],
outdent: ['Ctrl+M'] outdent: ['Ctrl+M']
} }
}); });
});
context.onunload = function() { extend(TextEditor.prototype, 'onremove', function () {
editor.destroy(); this.editor.destroy();
};
}); });
extend(TextEditor.prototype, 'toolbarItems', function(items) { extend(TextEditor.prototype, 'toolbarItems', function(items) {