@milkdown/plugin-table
Advanced tools
Comparing version 4.5.3 to 4.6.0
# @milkdown/plugin-table | ||
## 4.6.0 | ||
### Minor Changes | ||
- e1fbf79: Refactor the plugin system to functional plugin for better extension ability. | ||
### Patch Changes | ||
- Updated dependencies [e1fbf79] | ||
- @milkdown/utils@4.6.0 | ||
## 4.5.3 | ||
@@ -4,0 +15,0 @@ |
@@ -1,7 +0,7 @@ | ||
export declare const remarkGFMPlugin: import("@milkdown/core").Atom<import("@milkdown/core").LoadState, import("@milkdown/core").AnyRecord, import("@milkdown/core").IdleContext | import("@milkdown/core").SchemaReadyContext | import("@milkdown/core").LoadPluginContext | import("@milkdown/core").CompleteContext, import("@milkdown/core").IdleContext | import("@milkdown/core").SchemaReadyContext | import("@milkdown/core").LoadPluginContext | import("@milkdown/core").CompleteContext>; | ||
export declare const tableEditPlugin: import("@milkdown/core").Atom<import("@milkdown/core").LoadState, import("@milkdown/core").AnyRecord, import("@milkdown/core").IdleContext | import("@milkdown/core").SchemaReadyContext | import("@milkdown/core").LoadPluginContext | import("@milkdown/core").CompleteContext, import("@milkdown/core").IdleContext | import("@milkdown/core").SchemaReadyContext | import("@milkdown/core").LoadPluginContext | import("@milkdown/core").CompleteContext>; | ||
export declare const tablePlugin: import("@milkdown/core").Atom<import("@milkdown/core").LoadState, import("@milkdown/core").AnyRecord, import("@milkdown/core").IdleContext | import("@milkdown/core").SchemaReadyContext | import("@milkdown/core").LoadPluginContext | import("@milkdown/core").CompleteContext, import("@milkdown/core").IdleContext | import("@milkdown/core").SchemaReadyContext | import("@milkdown/core").LoadPluginContext | import("@milkdown/core").CompleteContext>[]; | ||
export declare const table: import("@milkdown/core").Atom<import("@milkdown/core").LoadState, import("@milkdown/core").AnyRecord, import("@milkdown/core").IdleContext | import("@milkdown/core").SchemaReadyContext | import("@milkdown/core").LoadPluginContext | import("@milkdown/core").CompleteContext, import("@milkdown/core").IdleContext | import("@milkdown/core").SchemaReadyContext | import("@milkdown/core").LoadPluginContext | import("@milkdown/core").CompleteContext>[]; | ||
export declare const remarkGFMPlugin: import("@milkdown/core").MilkdownPlugin; | ||
export declare const tableEditPlugin: import("@milkdown/core").MilkdownPlugin; | ||
export declare const tablePlugins: import("@milkdown/core").MilkdownPlugin[]; | ||
export declare const table: import("@milkdown/core").MilkdownPlugin[]; | ||
export * from './nodes'; | ||
export * from './utils'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { createProsemirrorPlugin, createRemarkPlugin } from '@milkdown/core'; | ||
import { prosePluginFactory, remarkPluginFactory } from '@milkdown/core'; | ||
import { columnResizing, tableEditing } from 'prosemirror-tables'; | ||
@@ -6,12 +6,8 @@ import gfm from 'remark-gfm'; | ||
import { tableOperatorPlugin } from './table-operator-plugin'; | ||
export const remarkGFMPlugin = createRemarkPlugin('remark-table-markdown', () => [gfm]); | ||
export const tableEditPlugin = createProsemirrorPlugin('prosemirror-table-edit', () => [ | ||
columnResizing({}), | ||
tableOperatorPlugin(), | ||
tableEditing(), | ||
]); | ||
export const tablePlugin = [remarkGFMPlugin, tableEditPlugin]; | ||
export const table = [...tablePlugin, ...tableNodes]; | ||
export const remarkGFMPlugin = remarkPluginFactory(gfm); | ||
export const tableEditPlugin = prosePluginFactory([columnResizing({}), tableOperatorPlugin(), tableEditing()]); | ||
export const tablePlugins = [remarkGFMPlugin, tableEditPlugin]; | ||
export const table = [...tablePlugins, ...tableNodes]; | ||
export * from './nodes'; | ||
export * from './utils'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,44 +0,15 @@ | ||
import { Atom, Node, NodeParserSpec, NodeSerializerSpec } from '@milkdown/core'; | ||
import { NodeSpec, NodeType, Schema } from 'prosemirror-model'; | ||
import { InputRule } from 'prosemirror-inputrules'; | ||
import { BaseNode } from './base-node'; | ||
export declare enum SupportedKeys { | ||
NextCell = "NextCell", | ||
PrevCell = "PrevCell", | ||
ExitTable = "ExitTable" | ||
} | ||
declare type Keys = SupportedKeys.NextCell | SupportedKeys.PrevCell | SupportedKeys.ExitTable; | ||
export declare class Table extends BaseNode<Keys> { | ||
readonly id = "table"; | ||
readonly schema: NodeSpec; | ||
readonly parser: NodeParserSpec; | ||
readonly serializer: NodeSerializerSpec; | ||
inputRules: (nodeType: NodeType, schema: Schema) => InputRule[]; | ||
readonly commands: BaseNode<Keys>['commands']; | ||
} | ||
export declare class TableRow extends Node { | ||
id: string; | ||
schema: NodeSpec; | ||
parser: NodeParserSpec; | ||
serializer: NodeSerializerSpec; | ||
} | ||
export declare class TableCell extends Node { | ||
id: string; | ||
schema: NodeSpec; | ||
parser: NodeParserSpec; | ||
serializer: NodeSerializerSpec; | ||
} | ||
export declare class TableHeader extends Node { | ||
id: string; | ||
schema: NodeSpec; | ||
parser: NodeParserSpec; | ||
serializer: NodeSerializerSpec; | ||
} | ||
declare type ConstructorOf<T> = T extends InstanceType<infer U> ? U : T; | ||
declare class NodeList<T extends Atom = Atom> extends Array<T> { | ||
configure<U extends ConstructorOf<T>>(Target: U, config: ConstructorParameters<U>[0]): this; | ||
static create<T extends Atom = Atom>(from: T[]): NodeList; | ||
} | ||
export declare const tableNodes: NodeList<Atom<import("@milkdown/core").LoadState, import("@milkdown/core").AnyRecord, import("@milkdown/core").IdleContext | import("@milkdown/core").SchemaReadyContext | import("@milkdown/core").LoadPluginContext | import("@milkdown/core").CompleteContext, import("@milkdown/core").IdleContext | import("@milkdown/core").SchemaReadyContext | import("@milkdown/core").LoadPluginContext | import("@milkdown/core").CompleteContext>>; | ||
export {}; | ||
import { AtomList } from '@milkdown/utils'; | ||
export declare const SupportedKeys: { | ||
readonly NextCell: "NextCell"; | ||
readonly PrevCell: "PrevCell"; | ||
readonly ExitTable: "ExitTable"; | ||
}; | ||
export declare type SupportedKeys = typeof SupportedKeys; | ||
export declare const table: import("@milkdown/utils/lib/atom/types").Origin<"Node", "NextCell" | "PrevCell" | "ExitTable", import("@milkdown/utils/lib/type-utility").UnknownRecord>; | ||
export declare const tableRow: import("@milkdown/utils/lib/atom/types").Origin<"Node", string, import("@milkdown/utils/lib/type-utility").UnknownRecord>; | ||
export declare const tableCell: import("@milkdown/utils/lib/atom/types").Origin<"Node", string, import("@milkdown/utils/lib/type-utility").UnknownRecord>; | ||
export declare const tableHeader: import("@milkdown/utils/lib/atom/types").Origin<"Node", string, import("@milkdown/utils/lib/type-utility").UnknownRecord>; | ||
export declare const tableNodes: AtomList<import("@milkdown/core").MilkdownPlugin & { | ||
origin: import("@milkdown/utils/lib/atom/types").Origin<"Node" | "Mark", string, import("@milkdown/utils/lib/type-utility").UnknownRecord>; | ||
}>; | ||
//# sourceMappingURL=nodes.d.ts.map |
136
lib/nodes.js
@@ -1,8 +0,7 @@ | ||
import { Node } from '@milkdown/core'; | ||
import { tableNodes as tableNodesSpecCreator, goToNextCell } from 'prosemirror-tables'; | ||
import { AtomList, createNode } from '@milkdown/utils'; | ||
import { InputRule } from 'prosemirror-inputrules'; | ||
import { TextSelection } from 'prosemirror-state'; | ||
import { goToNextCell, tableNodes as tableNodesSpecCreator } from 'prosemirror-tables'; | ||
import { exitTable } from './command'; | ||
import { createTable } from './utils'; | ||
import { BaseNode } from './base-node'; | ||
import { exitTable } from './command'; | ||
const tableNodesSpec = tableNodesSpecCreator({ | ||
@@ -21,14 +20,13 @@ tableGroup: 'block', | ||
}); | ||
export var SupportedKeys; | ||
(function (SupportedKeys) { | ||
SupportedKeys["NextCell"] = "NextCell"; | ||
SupportedKeys["PrevCell"] = "PrevCell"; | ||
SupportedKeys["ExitTable"] = "ExitTable"; | ||
})(SupportedKeys || (SupportedKeys = {})); | ||
export class Table extends BaseNode { | ||
constructor() { | ||
super(...arguments); | ||
this.id = 'table'; | ||
this.schema = tableNodesSpec.table; | ||
this.parser = { | ||
export const SupportedKeys = { | ||
NextCell: 'NextCell', | ||
PrevCell: 'PrevCell', | ||
ExitTable: 'ExitTable', | ||
}; | ||
export const table = createNode(() => { | ||
const id = 'table'; | ||
return { | ||
id, | ||
schema: tableNodesSpec.table, | ||
parser: { | ||
match: (node) => node.type === 'table', | ||
@@ -42,5 +40,5 @@ runner: (state, node, type) => { | ||
}, | ||
}; | ||
this.serializer = { | ||
match: (node) => node.type.name === this.id, | ||
}, | ||
serializer: { | ||
match: (node) => node.type.name === id, | ||
runner: (state, node) => { | ||
@@ -59,4 +57,4 @@ var _a; | ||
}, | ||
}; | ||
this.inputRules = (nodeType, schema) => [ | ||
}, | ||
inputRules: (nodeType, schema) => [ | ||
new InputRule(/^\|\|\s$/, (state, _match, start, end) => { | ||
@@ -70,4 +68,4 @@ const $start = state.doc.resolve(start); | ||
}), | ||
]; | ||
this.commands = (_, schema) => ({ | ||
], | ||
commands: (_, schema) => ({ | ||
[SupportedKeys.NextCell]: { | ||
@@ -85,11 +83,11 @@ defaultKey: 'Mod-]', | ||
}, | ||
}); | ||
} | ||
} | ||
export class TableRow extends Node { | ||
constructor() { | ||
super(...arguments); | ||
this.id = 'table_row'; | ||
this.schema = tableNodesSpec.table_row; | ||
this.parser = { | ||
}), | ||
}; | ||
}); | ||
export const tableRow = createNode(() => { | ||
const id = 'table_row'; | ||
return { | ||
id, | ||
schema: tableNodesSpec.table_row, | ||
parser: { | ||
match: (node) => node.type === 'tableRow', | ||
@@ -103,5 +101,5 @@ runner: (state, node, type) => { | ||
}, | ||
}; | ||
this.serializer = { | ||
match: (node) => node.type.name === this.id, | ||
}, | ||
serializer: { | ||
match: (node) => node.type.name === id, | ||
runner: (state, node) => { | ||
@@ -112,11 +110,11 @@ state.openNode('tableRow'); | ||
}, | ||
}; | ||
} | ||
} | ||
export class TableCell extends Node { | ||
constructor() { | ||
super(...arguments); | ||
this.id = 'table_cell'; | ||
this.schema = tableNodesSpec.table_cell; | ||
this.parser = { | ||
}, | ||
}; | ||
}); | ||
export const tableCell = createNode(() => { | ||
const id = 'table_cell'; | ||
return { | ||
id, | ||
schema: tableNodesSpec.table_cell, | ||
parser: { | ||
match: (node) => node.type === 'tableCell' && !node.isHeader, | ||
@@ -132,17 +130,17 @@ runner: (state, node, type) => { | ||
}, | ||
}; | ||
this.serializer = { | ||
match: (node) => node.type.name === this.id, | ||
}, | ||
serializer: { | ||
match: (node) => node.type.name === id, | ||
runner: (state, node) => { | ||
state.openNode('tableCell').next(node.content).closeNode(); | ||
}, | ||
}; | ||
} | ||
} | ||
export class TableHeader extends Node { | ||
constructor() { | ||
super(...arguments); | ||
this.id = 'table_header'; | ||
this.schema = tableNodesSpec.table_header; | ||
this.parser = { | ||
}, | ||
}; | ||
}); | ||
export const tableHeader = createNode(() => { | ||
const id = 'table_header'; | ||
return { | ||
id, | ||
schema: tableNodesSpec.table_header, | ||
parser: { | ||
match: (node) => node.type === 'tableCell' && !!node.isHeader, | ||
@@ -157,5 +155,5 @@ runner: (state, node, type) => { | ||
}, | ||
}; | ||
this.serializer = { | ||
match: (node) => node.type.name === this.id, | ||
}, | ||
serializer: { | ||
match: (node) => node.type.name === id, | ||
runner: (state, node) => { | ||
@@ -166,18 +164,6 @@ state.openNode('tableCell'); | ||
}, | ||
}; | ||
} | ||
} | ||
class NodeList extends Array { | ||
configure(Target, config) { | ||
const index = this.findIndex((x) => x.constructor === Target); | ||
if (index < 0) | ||
return this; | ||
this.splice(index, 1, new Target(config)); | ||
return this; | ||
} | ||
static create(from) { | ||
return new NodeList(...from); | ||
} | ||
} | ||
export const tableNodes = NodeList.create([new Table(), new TableRow(), new TableCell(), new TableHeader()]); | ||
}, | ||
}; | ||
}); | ||
export const tableNodes = AtomList.create([table(), tableRow(), tableCell(), tableHeader()]); | ||
//# sourceMappingURL=nodes.js.map |
{ | ||
"name": "@milkdown/plugin-table", | ||
"version": "4.5.3", | ||
"version": "4.6.0", | ||
"main": "lib/index.js", | ||
@@ -11,18 +11,6 @@ "module": "lib/index.js", | ||
"peerDependencies": { | ||
"@milkdown/core": "*", | ||
"@types/prosemirror-commands": "*", | ||
"@types/prosemirror-inputrules": "*", | ||
"@types/prosemirror-keymap": "*", | ||
"@types/prosemirror-model": "*", | ||
"@types/prosemirror-state": "*", | ||
"@types/prosemirror-view": "*", | ||
"prosemirror-commands": "*", | ||
"prosemirror-inputrules": "*", | ||
"prosemirror-keymap": "*", | ||
"prosemirror-model": "*", | ||
"prosemirror-state": "*", | ||
"prosemirror-view": "*" | ||
"@milkdown/core": "*" | ||
}, | ||
"dependencies": { | ||
"@milkdown/utils": "4.5.3", | ||
"@milkdown/utils": "4.6.0", | ||
"prosemirror-tables": "*", | ||
@@ -33,3 +21,2 @@ "remark-gfm": "^1.0.0", | ||
"devDependencies": { | ||
"@milkdown/core": "4.5.3", | ||
"concurrently": "^6.0.2" | ||
@@ -40,6 +27,8 @@ }, | ||
"watch": "concurrently -n ts,css \"tsc -w\" \"postcss style/style.css --watch --verbose -o lib/style.css\"", | ||
"watch:css": "postcss style/style.css --watch --verbose -o lib/style.css", | ||
"test": "jest", | ||
"tsc": "tsc --noEmit", | ||
"build": "tsc && postcss style/style.css --verbose -o lib/style.css" | ||
"build": "tsc && postcss style/style.css --verbose -o lib/style.css", | ||
"build:css": "postcss style/style.css --verbose -o lib/style.css" | ||
} | ||
} |
@@ -20,4 +20,3 @@ # @milkdown/plugin-table | ||
const root = document.body; | ||
new Editor({ root }).use(commonmark).use(table).create(); | ||
new Editor().use(commonmark).use(table).create(); | ||
``` | ||
@@ -28,11 +27,10 @@ | ||
```typescript | ||
import { tableNodes, tablePlugin, SupportedKeys, Table } from '@milkdown/plugin-table'; | ||
import { tableNodes, tablePlugin, SupportedKeys, table } from '@milkdown/plugin-table'; | ||
// import style | ||
import '@milkdown/plugin-table/lib/style.css'; | ||
const root = document.body; | ||
new Editor({ root }) | ||
new Editor() | ||
.use(commonmark) | ||
.use( | ||
tableNodes.configure(Table, { | ||
tableNodes.configure(table, { | ||
keymap: { | ||
@@ -39,0 +37,0 @@ [SupportedKeys.NextCell]: 'Enter', |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5
1
67628
25
903
49
+ Added@milkdown/utils@4.6.0(transitive)
+ Added@types/lodash@4.17.13(transitive)
+ Added@types/lodash-es@4.17.12(transitive)
+ Addedlodash-es@4.17.21(transitive)
- Removed@milkdown/utils@4.5.3(transitive)
- Removed@types/prosemirror-commands@1.3.0(transitive)
- Removed@types/prosemirror-inputrules@1.2.0(transitive)
- Removed@types/prosemirror-keymap@1.2.0(transitive)
- Removed@types/prosemirror-model@1.17.0(transitive)
- Removed@types/prosemirror-state@1.4.0(transitive)
- Removed@types/prosemirror-view@1.24.0(transitive)
Updated@milkdown/utils@4.6.0