This repository has been archived by the owner on Apr 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
122 lines (102 loc) · 3.64 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
var Nanocomponent = require('nanocomponent')
var html = require('nanohtml')
var css = require('sheetify')
var Quill = require('quill')
var MarkdownShortcuts = require('./editor/extensions/md')
css('quill/dist/quill.core.css')
css('quill/dist/quill.snow.css')
var defaultStyle = css`
.ql-editor {
height: 500px !important;
width: 100%;
}
`
// lifecycle events can optionally be imported
// and registered in Component.beforerender()
// var on = require('./on')
class Component extends Nanocomponent {
/**
* @description Represents a QuillEditor
* @contructor Create a new QuillEditor.
*
* @param {String} id (Choo) Unique DOM ID to reference the element
* @param {Object} state (Choo) State object
* @param {Function} emit (Choo) Event emitter
* @param {Object} opts Options object
* @param {String} opts.class Class names for container element
* @param {String} opts.style Inline style for container element
* @param {String} opts.placeholder Editor placeholder text
* @param {Object} opts.template Template object
*
*/
constructor (id, state, emit, opts) {
super()
this.opts = opts
}
// _Must be implemented._ Component specific render function.
// Optionally cache argument values here. Run anything here that needs
// to run alongside node rendering. Must return a DOMNode. Use beforerender
// to run code after createElement when the component is unmounted.
// Previously named _render. Arguments passed to render are passed to
// createElement. Elements returned from createElement must always return
// the same root node type.
createElement () {
var opts = this.opts
return html`<div class="${opts.class || defaultStyle}"></div>`
}
// _Must be implemented._ Return a boolean to determine if
// prototype.createElement() should be called. The update method is
// analogous to React's shouldComponentUpdate. Called only when the
// component is mounted in the DOM tree. Arguments passed to render
// are passed to update.
update () {
return false
}
// A function called right after createElement returns with el, but before
// the fully rendered element is returned to the render caller. Run any first
// render hooks here. The load and unload hooks are added at this stage. Do
// not attempt to rerender in beforerender as the component may not be in the
// DOM yet.
beforerender (el) {
Quill.register('modules/markdownShortcuts', MarkdownShortcuts)
var opts = this.opts
this.quill = new Quill(editorinner, {
theme: 'snow',
bounds: editorel,
toolbar: editorel,
placeholder: opts.placeholder,
modules: {
markdownShortcuts: {}
}
})
// set contents to markdown template
if (opts.template) quill.updateContents(opts.template)
// this is where you can register other lifecycle events:
// on.resize()
// on.ready()
// on.intersect()
// on.idle()
}
// Called when the component is mounted on the DOM.
// Uses on-load under the hood.
load (el) {
setTimeout(() => this.quill.focus(), 20)
}
// Called when the component is removed from the DOM.
unload (text) {
// noop
}
// Called after a mounted component updates (e.g. update returns true).
// You can use this hook to call element.scrollIntoView or other
// dom methods on the mounted component.
afterupdate (el) {
// noop
}
// Called after a component is re-ordered. This method is rarely needed,
// but is handy when you have a component that is sensitive to temorary
// removals from the DOM, such as externally controlled iframes or embeds
// (e.g. embedded tweets)
afterreorder (el) {
// noop
}
}