From 0798f9b865659e9a122b7235c410cdc7e1740ca9 Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Mon, 28 Aug 2023 19:03:51 +0300 Subject: [PATCH] new schema --- editors/demo/src/Editoria/Editoria.js | 15 ++++++++++++- .../InsertTableService/InsertTableService.js | 16 +++++++++++++- .../src/TablesService/tableSrc/index.js | 22 +++++++++++++++++-- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/editors/demo/src/Editoria/Editoria.js b/editors/demo/src/Editoria/Editoria.js index 3a72be1e7..8bd8ed095 100644 --- a/editors/demo/src/Editoria/Editoria.js +++ b/editors/demo/src/Editoria/Editoria.js @@ -40,6 +40,19 @@ const Editoria = () => { } const editorRef = useRef(); + const text = `<table> + <caption>Monthly savings</caption> + <tr> + <th>Month</th> + <th>Savings</th> + </tr> + <tr> + <td>January</td> + <td>$100</td> + </tr> +</table> + `; + const EditoriaComponent = useMemo( () => ( <> @@ -50,7 +63,7 @@ const Editoria = () => { autoFocus placeholder="Type Something..." fileUpload={file => renderImage(file)} - value={demo} + value={text} // readonly layout={layout} // onChange={debounce(source => { diff --git a/wax-prosemirror-services/src/TablesService/InsertTableService/InsertTableService.js b/wax-prosemirror-services/src/TablesService/InsertTableService/InsertTableService.js index ce9c7f423..c722bea85 100644 --- a/wax-prosemirror-services/src/TablesService/InsertTableService/InsertTableService.js +++ b/wax-prosemirror-services/src/TablesService/InsertTableService/InsertTableService.js @@ -1,3 +1,4 @@ +/* eslint-disable camelcase */ import { Service } from 'wax-prosemirror-core'; import { tableNodes, goToNextCell } from '../tableSrc'; import Table from './Table'; @@ -8,7 +9,14 @@ class InsertTableService extends Service { const CreateShortCut = this.container.get('CreateShortCut'); // eslint-disable-next-line camelcase - const { table, table_row, table_cell, table_header } = tableNodes({ + const { + table, + table_row, + table_caption, + table_body, + table_cell, + table_header, + } = tableNodes({ tableGroup: 'block', cellContent: 'block+', }); @@ -17,6 +25,12 @@ class InsertTableService extends Service { createNode({ table, }); + createNode({ + table_caption, + }); + createNode({ + table_body, + }); createNode({ table_row, }); diff --git a/wax-prosemirror-services/src/TablesService/tableSrc/index.js b/wax-prosemirror-services/src/TablesService/tableSrc/index.js index e5b83c099..ed1ddc8e6 100644 --- a/wax-prosemirror-services/src/TablesService/tableSrc/index.js +++ b/wax-prosemirror-services/src/TablesService/tableSrc/index.js @@ -332,13 +332,31 @@ function tableNodes(options) { cellAttrs[prop] = { default: extraAttrs[prop].default }; return { table: { - content: 'table_row+', + content: 'table_caption? table_body*', tableRole: 'table', isolating: true, group: options.tableGroup, parseDOM: [{ tag: 'table' }], toDOM() { - return ['table', ['tbody', 0]]; + return ['table', 0]; + }, + }, + table_caption: { + content: 'block+', + tableRole: 'caption', + isolating: true, + parseDOM: [{ tag: 'caption' }], + toDOM() { + return ['caption', 0]; + }, + }, + table_body: { + content: 'table_row+', + tableRole: 'body', + isolating: true, + parseDOM: [{ tag: 'tbody' }], + toDOM() { + return ['tbody', 0]; }, }, table_row: { -- GitLab