2017-11-30 18:35:56 -08:00
|
|
|
/* global Y, HTMLElement, customElements, CanvasJS */
|
2017-11-12 13:34:23 -08:00
|
|
|
|
2017-11-29 15:08:49 -08:00
|
|
|
window.onload = function () {
|
|
|
|
|
window.yXmlType.bindToDom(document.body)
|
|
|
|
|
let mt = document.createElement('magic-table')
|
|
|
|
|
mt.innerHTML = '<table><tr><th>Amount</th></tr><tr><td>1</td></tr><tr><td>1</td></tr></table>'
|
|
|
|
|
document.body.append(mt)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-12 13:34:23 -08:00
|
|
|
class MagicTable extends HTMLElement {
|
|
|
|
|
constructor () {
|
|
|
|
|
super()
|
2017-11-29 15:08:49 -08:00
|
|
|
this.createShadowRoot()
|
|
|
|
|
}
|
|
|
|
|
get _yjsHook () {
|
|
|
|
|
return 'magic-table'
|
|
|
|
|
}
|
|
|
|
|
showTable () {
|
|
|
|
|
this.shadowRoot.innerHTML = ''
|
|
|
|
|
this.shadowRoot.append(document.createElement('content'))
|
|
|
|
|
}
|
|
|
|
|
showDiagram () {
|
|
|
|
|
let dataPoints = []
|
|
|
|
|
this.querySelectorAll('td').forEach(td => {
|
|
|
|
|
let number = Number(td.textContent)
|
|
|
|
|
dataPoints.push({
|
2017-11-30 18:35:56 -08:00
|
|
|
x: (dataPoints.length + 1) * 10,
|
2017-11-29 15:08:49 -08:00
|
|
|
y: number,
|
|
|
|
|
label: '<magic-table> content'
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
this.shadowRoot.innerHTML = ''
|
2017-11-30 18:35:56 -08:00
|
|
|
var chart = new CanvasJS.Chart(this.shadowRoot,
|
|
|
|
|
{
|
|
|
|
|
title: {
|
|
|
|
|
text: 'Bar chart'
|
|
|
|
|
},
|
|
|
|
|
data: [
|
|
|
|
|
{
|
|
|
|
|
type: 'bar',
|
2017-11-29 15:08:49 -08:00
|
|
|
|
2017-11-30 18:35:56 -08:00
|
|
|
dataPoints: dataPoints
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
})
|
2017-11-29 15:08:49 -08:00
|
|
|
|
2017-11-30 18:35:56 -08:00
|
|
|
chart.render()
|
2017-11-29 15:08:49 -08:00
|
|
|
|
2017-11-30 18:35:56 -08:00
|
|
|
// this.shadowRoot.innerHTML = '<p>dtrn</p>'
|
2017-11-12 13:34:23 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
customElements.define('magic-table', MagicTable)
|
2017-08-25 20:35:06 +02:00
|
|
|
|
2017-11-29 15:08:49 -08:00
|
|
|
Y.XmlHook.addHook('magic-table', {
|
|
|
|
|
fillType: function (dom, type) {
|
|
|
|
|
type.set('table', new Y.XmlElement(dom.querySelector('table')))
|
|
|
|
|
},
|
|
|
|
|
createDom: function (type) {
|
|
|
|
|
const table = type.get('table').getDom()
|
|
|
|
|
const dom = document.createElement('magic-table')
|
|
|
|
|
dom.insertBefore(table, null)
|
|
|
|
|
return dom
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2017-08-25 20:35:06 +02:00
|
|
|
// initialize a shared object. This function call returns a promise!
|
2017-10-19 17:36:28 +02:00
|
|
|
let y = new Y({
|
2017-08-25 20:35:06 +02:00
|
|
|
connector: {
|
|
|
|
|
name: 'websockets-client',
|
2017-09-29 22:33:28 +02:00
|
|
|
url: 'http://127.0.0.1:1234',
|
2017-10-02 15:50:56 +02:00
|
|
|
room: 'html-editor-example6'
|
2017-10-02 15:45:23 +02:00
|
|
|
// maxBufferLength: 100
|
2017-08-25 20:35:06 +02:00
|
|
|
}
|
|
|
|
|
})
|
2017-10-19 17:36:28 +02:00
|
|
|
window.yXml = y
|
2017-11-08 13:40:36 -08:00
|
|
|
window.yXmlType = y.define('xml', Y.XmlFragment)
|
2017-11-08 17:31:12 -08:00
|
|
|
window.undoManager = new Y.utils.UndoManager(window.yXmlType, {
|
2017-11-12 13:34:23 -08:00
|
|
|
captureTimeout: 500
|
2017-11-08 17:31:12 -08:00
|
|
|
})
|
2017-10-30 11:33:00 +01:00
|
|
|
|
|
|
|
|
document.onkeydown = function interceptUndoRedo (e) {
|
2017-11-09 17:31:58 -08:00
|
|
|
if (e.keyCode === 90 && e.metaKey) {
|
2017-10-30 11:33:00 +01:00
|
|
|
if (!e.shiftKey) {
|
|
|
|
|
window.undoManager.undo()
|
|
|
|
|
} else {
|
|
|
|
|
window.undoManager.redo()
|
|
|
|
|
}
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
}
|
2017-10-19 17:36:28 +02:00
|
|
|
}
|