Move transformTable function

single-block-api
Peter Stuifzand 3 years ago
parent 5859046169
commit 9e295eee25

@ -163,15 +163,7 @@ function Editor(holder, input) {
return span[0];
}
const options = {
transform(text, element, id, editor) {
if (text === undefined) {
return;
}
let converted = text
if (converted === '{{table}}') {
function transformTable(editor, id, element) {
editor.treeForId(id).then(tree => {
let [header, rows] = tree[0].children
let rowData = _.map(rows.children, row => {
@ -184,7 +176,7 @@ function Editor(holder, input) {
el("td", [renderInline(row.text)]),
..._.map(header.children, col => {
let td = el("td")
this.transform(rowData[_.snakeCase(_.trim(col.text))], $(td), id, editor)
transform(rowData[_.snakeCase(_.trim(col.text))], $(td), id, editor)
return td
})
])
@ -211,6 +203,17 @@ function Editor(holder, input) {
])
}).then(table => element.html(table))
})
}
function transform(text, element, id, editor) {
if (text === undefined) {
return;
}
let converted = text
if (converted === '{{table}}') {
transformTable.call(this, editor, id, element);
return
} else if (converted.startsWith("```", 0) || converted.startsWith("$$", 0)) {
converted = MD.render(converted)
@ -236,6 +239,9 @@ function Editor(holder, input) {
element.html(converted)
}
const options = {
transform
}
let inputData = input ? input : JSON.parse(holder.dataset.input)

@ -1,8 +1,8 @@
import _ from 'lodash'
import $ from 'jquery'
import he from 'he'
import textareaAutosizeInit from "./textarea.autosize"
import dragula from 'dragula'
import textareaAutosizeInit from "./textarea.autosize"
import createCursor from './cursor'
import createSelection from './selection'
import Store from './store'

@ -1,6 +1,6 @@
{
"name": "wiki-list-editor",
"version": "0.8.12",
"version": "0.8.13",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

Loading…
Cancel
Save