Move transformTable function

This commit is contained in:
Peter Stuifzand 2020-10-25 19:49:22 +01:00
parent 5859046169
commit 9e295eee25
3 changed files with 76 additions and 70 deletions

View File

@ -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)

View File

@ -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'

View File

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