Skip to content

Commit f8a9092

Browse files
committed
Merge branch 'master' into update-yarn-version
2 parents 5680c73 + 54f2bdf commit f8a9092

File tree

110 files changed

+12998
-1475
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+12998
-1475
lines changed

.babelrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"presets": [
3+
"@babel/env",
4+
"@babel/preset-react"
5+
]
6+
}

.eslintrc.json

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{
2+
"parser": "babel-eslint",
3+
"parserOptions": {
4+
"sourceType": "module",
5+
"allowImportExportEverywhere": false,
6+
"codeFrame": true,
7+
"ecmaFeatures": {
8+
"jsx": true
9+
}
10+
},
11+
"plugins": [
12+
"react"
13+
],
14+
"extends": [
15+
"plugin:prettier/recommended"
16+
],
17+
"rules": {
18+
"react/jsx-sort-props": "error",
19+
"react/jsx-uses-react": "error",
20+
"react/jsx-uses-vars": "error",
21+
"consistent-return": "error",
22+
"no-debugger": "error",
23+
"no-invalid-regexp": "error",
24+
"no-undef": "error",
25+
"no-unused-expression": [
26+
0,
27+
"allow-fast-null-checks"
28+
],
29+
"no-unused-vars": [
30+
"error",
31+
{
32+
"vars": "all",
33+
"args": "none",
34+
"ignoreRestSiblings": false
35+
}
36+
],
37+
"no-var": "error",
38+
"prefer-const": "error",
39+
"semi": [
40+
2,
41+
"always"
42+
],
43+
"strict": 0,
44+
// max length at 250 characters, ignores comments
45+
"max-len": [
46+
"warn",
47+
250,
48+
{
49+
"ignoreComments": true,
50+
"ignoreTrailingComments": true
51+
}
52+
]
53+
},
54+
"globals": {
55+
"$ReadOnlyArray": false,
56+
"Blob": false,
57+
"Class": false,
58+
"ClipboardEvent": false,
59+
"Component": false,
60+
"DataTransferItem": false,
61+
"Document": true,
62+
"DragEvent": true,
63+
"Element": false,
64+
"Event": false,
65+
"EventTarget": false,
66+
"File": false,
67+
"FileReader": false,
68+
"HTMLElement": false,
69+
"HTMLLIElement": false,
70+
"HTMLTableElement": false,
71+
"Image": false,
72+
"KeyboardEvent": false,
73+
"Map": false,
74+
"MouseEvent": false,
75+
"MutationObserver": false,
76+
"Promise": false,
77+
"Set": false,
78+
"SyntheticEvent": false,
79+
"SyntheticInputEvent": false,
80+
"SyntheticMouseEvent": false,
81+
"cancelAnimationFrame": false,
82+
"clearTimeout": false,
83+
"console": false,
84+
"document": false,
85+
"requestAnimationFrame": false,
86+
"setTimeout": false,
87+
"window": false,
88+
"Intl": false,
89+
"WeakMap": false
90+
}
91+
}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.tern-port
33
/dist
44
/demo_bundle.js
5+
/yarn-error.log

.prettierignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/package.json
2+
/bin
3+
/dist
4+
/.eslintrc
5+
/.vscode
6+
/.stylelintrc.json

.prettierrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2+
"bracketSpacing": false,
23
"singleQuote": true,
3-
"trailingComma": "all",
4-
"bracketSpacing": true
4+
"trailingComma": "none"
55
}

.vscode/settings.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"editor.codeActionsOnSave": {
3+
"source.fixAll.eslint": true,
4+
"source.fixAll": true,
5+
},
6+
"eslint.validate": [
7+
"javascript"
8+
]
9+
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ available to users.
145145
into smaller cells. Use the first cell type for the new cells.
146146

147147

148-
* **`splitCellWithType`**`(getType: fn({row: number, col: number, node: Node}) → NodeType) → fn(EditorState, dispatch: ?fn(tr: Transaction)) → bool`\
148+
* **`splitCellWithType`**`(getCellType: fn({row: number, col: number, node: Node}) → NodeType) → fn(EditorState, dispatch: ?fn(tr: Transaction)) → bool`\
149149
Split a selected cell, whose rowpan or colspan is greater than one,
150150
into smaller cells with the cell type (th, td) returned by getType function.
151151

demo.js

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { EditorView } from 'prosemirror-view';
2-
import { EditorState } from 'prosemirror-state';
3-
import { DOMParser, Schema } from 'prosemirror-model';
4-
import { schema as baseSchema } from 'prosemirror-schema-basic';
5-
import { keymap } from 'prosemirror-keymap';
6-
import { exampleSetup, buildMenuItems } from 'prosemirror-example-setup';
7-
import { MenuItem, Dropdown } from 'prosemirror-menu';
1+
import {EditorView} from 'prosemirror-view';
2+
import {EditorState} from 'prosemirror-state';
3+
import {DOMParser, Schema} from 'prosemirror-model';
4+
import {schema as baseSchema} from 'prosemirror-schema-basic';
5+
import {keymap} from 'prosemirror-keymap';
6+
import {exampleSetup, buildMenuItems} from 'prosemirror-example-setup';
7+
import {MenuItem, Dropdown} from 'prosemirror-menu';
88

99
import {
1010
addColumnAfter,
@@ -20,11 +20,11 @@ import {
2020
toggleHeaderColumn,
2121
toggleHeaderCell,
2222
goToNextCell,
23-
deleteTable,
23+
deleteTable
2424
} from './src/commands';
25-
import { tableEditing, columnResizing, tableNodes, fixTables } from './src';
25+
import {tableEditing, columnResizing, tableNodes, fixTables} from './src';
2626

27-
let schema = new Schema({
27+
const schema = new Schema({
2828
nodes: baseSchema.spec.nodes.append(
2929
tableNodes({
3030
tableGroup: 'block',
@@ -38,19 +38,19 @@ let schema = new Schema({
3838
setDOMAttr(value, attrs) {
3939
if (value)
4040
attrs.style = (attrs.style || '') + `background-color: ${value};`;
41-
},
42-
},
43-
},
44-
}),
41+
}
42+
}
43+
}
44+
})
4545
),
46-
marks: baseSchema.spec.marks,
46+
marks: baseSchema.spec.marks
4747
});
4848

49-
let menu = buildMenuItems(schema).fullMenu;
49+
const menu = buildMenuItems(schema).fullMenu;
5050
function item(label, cmd) {
51-
return new MenuItem({ label, select: cmd, run: cmd });
51+
return new MenuItem({label, select: cmd, run: cmd});
5252
}
53-
let tableMenu = [
53+
const tableMenu = [
5454
item('Insert column before', addColumnBefore),
5555
item('Insert column after', addColumnAfter),
5656
item('Delete column', deleteColumn),
@@ -64,12 +64,12 @@ let tableMenu = [
6464
item('Toggle header row', toggleHeaderRow),
6565
item('Toggle header cells', toggleHeaderCell),
6666
item('Make cell green', setCellAttr('background', '#dfd')),
67-
item('Make cell not-green', setCellAttr('background', null)),
67+
item('Make cell not-green', setCellAttr('background', null))
6868
];
69-
menu.splice(2, 0, [new Dropdown(tableMenu, { label: 'Table' })]);
69+
menu.splice(2, 0, [new Dropdown(tableMenu, {label: 'Table'})]);
7070

71-
let doc = DOMParser.fromSchema(schema).parse(
72-
document.querySelector('#content'),
71+
const doc = DOMParser.fromSchema(schema).parse(
72+
document.querySelector('#content')
7373
);
7474
let state = EditorState.create({
7575
doc,
@@ -78,14 +78,14 @@ let state = EditorState.create({
7878
tableEditing(),
7979
keymap({
8080
Tab: goToNextCell(1),
81-
'Shift-Tab': goToNextCell(-1),
82-
}),
83-
].concat(exampleSetup({ schema, menuContent: menu })),
81+
'Shift-Tab': goToNextCell(-1)
82+
})
83+
].concat(exampleSetup({schema, menuContent: menu}))
8484
});
85-
let fix = fixTables(state);
85+
const fix = fixTables(state);
8686
if (fix) state = state.apply(fix.setMeta('addToHistory', false));
8787

88-
window.view = new EditorView(document.querySelector('#editor'), { state });
88+
window.view = new EditorView(document.querySelector('#editor'), {state});
8989

9090
document.execCommand('enableObjectResizing', false, false);
9191
document.execCommand('enableInlineTableEditing', false, false);

index.d.ts

+81-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
NodeType,
2323
} from 'prosemirror-model';
2424
import { Mappable } from 'prosemirror-transform';
25-
import { NodeView } from 'prosemirror-view';
25+
import { EditorView, NodeView } from 'prosemirror-view';
2626

2727
export interface TableEditingOptions {
2828
allowTableNodeSelection?: boolean;
@@ -32,6 +32,7 @@ export interface TableNodesOptions {
3232
tableGroup?: string;
3333
cellContent: string;
3434
cellAttributes: { [key: string]: CellAttributes };
35+
cellContentGroup: string;
3536
}
3637

3738
export type getFromDOM = (dom: Element) => any;
@@ -43,6 +44,16 @@ export interface CellAttributes {
4344
setDOMAttr?: setDOMAttr;
4445
}
4546

47+
export enum NodeNames {
48+
TABLE= 'table',
49+
TABLE_ROW= 'table_row',
50+
TABLE_CELL= 'table_cell',
51+
TABLE_HEADER= 'table_header',
52+
CHECKBOX= 'checkbox',
53+
DATE= 'date',
54+
LABEL= 'label'
55+
}
56+
4657
export interface TableNodes {
4758
table: NodeSpec;
4859
table_row: NodeSpec;
@@ -134,12 +145,18 @@ export class TableMap {
134145
}
135146

136147
export function tableEditing(options?: TableEditingOptions): Plugin;
148+
export function columnHandles(): Plugin;
137149

138150
export function deleteTable<S extends Schema = any>(
139151
state: EditorState<S>,
140152
dispatch?: (tr: Transaction<S>) => void,
141153
): boolean;
142154

155+
export function sortColumn<S extends Schema = any>(
156+
state: EditorState<S>,
157+
dispatch?: (tr: Transaction<S>) => void
158+
): boolean;
159+
143160
export function goToNextCell<S extends Schema = any>(
144161
direction: number,
145162
): (state: EditorState<S>, dispatch?: (tr: Transaction<S>) => void) => boolean;
@@ -319,3 +336,66 @@ export function fixTables<S extends Schema = any>(
319336
state: EditorState<S>,
320337
oldState?: EditorState<S>,
321338
): null | Transaction<S>;
339+
340+
341+
export function addBottomRow(
342+
state: EditorState,
343+
dispatch: (tr: Transaction) => void,
344+
pos: number
345+
): void
346+
347+
348+
export function addRightColumn(
349+
state: EditorState,
350+
dispatch: (tr: Transaction) => void,
351+
pos: number
352+
): void
353+
354+
export function deleteLastRow(
355+
state: EditorState,
356+
dispatch: (tr: Transaction) => void,
357+
): void
358+
359+
export function deleteLastCol(
360+
state: EditorState,
361+
dispatch: (tr: Transaction) => void,
362+
): void
363+
364+
export function changeCellsBackgroundColor(
365+
state: EditorState,
366+
dispatch: (tr: Transaction) => void,
367+
color: string
368+
): void
369+
370+
export function toggleTableHeaders(
371+
state: EditorState,
372+
dispatch: (tr: Transaction) => void,
373+
view: EditorView
374+
): void
375+
376+
export function getDeleteCommand(
377+
state: EditorState
378+
): (
379+
state: EditorState,
380+
dispatch: (tr: Transaction) => void,
381+
) => void
382+
383+
export function isCellColorActive(
384+
state: EditorState,
385+
color: string
386+
)
387+
388+
export function getSelectedCellsCoords(
389+
view: EditorView
390+
): {
391+
top: number,
392+
bottom: number,
393+
right: number,
394+
left: number,
395+
width: number,
396+
height: number
397+
}
398+
399+
export function setBaseName(
400+
name: string
401+
)

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<link rel=stylesheet href="node_modules/prosemirror-view/style/prosemirror.css">
66
<link rel=stylesheet href="node_modules/prosemirror-menu/style/menu.css">
77
<link rel=stylesheet href="node_modules/prosemirror-example-setup/style/style.css">
8-
<link rel=stylesheet href="style/tables.css">
98
<link rel=stylesheet href="node_modules/prosemirror-gapcursor/style/gapcursor.css">
109
<link rel=stylesheet href="style/tables.css">
10+
1111
<style>
1212
body {
1313
max-width: 50em;

0 commit comments

Comments
 (0)