I want to remove the default cellAttrs from table schema as mentioned in the tableNodes from prosemirror-tables.
The way i am building my content editor is by cloning all the files from prosemirror-tables and fork them locally so that i can customize them.
most of the solution out there like milkdown, tiptap uses the tableNodes, which i don’t want to use. instead i have forked the file and i am using it.
/**
* NOTE(rohitt-gupta, 2024-11-26): Forked from `prosemirror-tables` so we can
* remove features we don't use and customize the user experience. We intend to
* modify this file a lot so each modification may not be documented.
*
* The MIT License
*
* Copyright (C) 2015-2016 by Marijn Haverbeke <marijnh@gmail.com> and others
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
// I WANT TO REMOVE THESE DEFULT ATTRS FROM THE SCHEMA
const cellAttrs: Record<string, AttributeSpec> = {
colspan: {default: 1, schema: Schema.integer},
rowspan: {default: 1, schema: Schema.integer},
colwidth: {default: null, schema: Schema.array(Schema.integer).nullable()},
};
export const contentTableProsemirrorNodeSpec = {
name: "table",
content: "tableRow+",
group: "block",
copyable: true,
selectable: true,
isolating: true,
tableRole: "table",
parseDOM: [{tag: "table"}],
toDOM() {
return ["table", {class: tableClassName}, ["tbody", 0]] as const;
},
};
export const contentTableRowProsemirrorNodeSpec = {
name: "tableRow",
content: "(tableCell | tableHeader)+",
tableRole: "row",
isolating: true,
selectable: true,
copyable: true,
parseDOM: [{tag: "tr"}],
toDOM() {
return ["tr", 0] as const;
},
};
export const contentTableCellProsemirrorNodeSpec = {
name: "tableCell",
content: "tableBlock+",
tableRole: "cell",
selectable: true,
isolating: true,
copyable: true,
attrs: cellAttrs,
parseDOM: [{tag: "td"}],
toDOM() {
return ["td", {class: tableCellClassName}, 0] as const;
},
};
export const contentTableHeaderProsemirrorNodeSpec = {
name: "tableHeader", // name must match the name in the column definition
content: "tableBlock+",
selectable: true,
isolating: true,
copyable: true,
tableRole: "header_cell",
parseDOM: [{tag: "th"}],
toDOM() {
return ["th", {class: tableHeaderClassName}, 0] as const; // added class to match the css
},
attrs: cellAttrs, //TODO(rohitt-gupta, 2024-11-26): remove this once we have a better way to handle table cell attrs
};
PS i am trying to build a notion like editor and i want to make it super extensive and customizable. If anyone has good experience with prosemirror-tables, please let me know.