@kerebron/extension-menu 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import { MenuElement } from './menu.js';
|
|
2
1
|
import { Plugin } from 'prosemirror-state';
|
|
3
2
|
import { Schema } from 'prosemirror-model';
|
|
4
3
|
import { type CoreEditor, Extension } from '../../editor/src/mod.js';
|
|
4
|
+
import { MenuElement } from './menu.js';
|
|
5
|
+
export { blockTypeItem, Dropdown, DropdownSubmenu, MenuItem, wrapItem, } from './menu.js';
|
|
5
6
|
export declare function buildMenu(editor: CoreEditor, schema: Schema): MenuElement[][];
|
|
7
|
+
export interface MenuConfig {
|
|
8
|
+
modifyMenu?(menus: MenuElement[][]): MenuElement[][];
|
|
9
|
+
floating: boolean;
|
|
10
|
+
}
|
|
6
11
|
export declare class ExtensionMenu extends Extension {
|
|
12
|
+
protected config: MenuConfig;
|
|
7
13
|
name: string;
|
|
14
|
+
constructor(config?: MenuConfig);
|
|
8
15
|
getProseMirrorPlugins(editor: CoreEditor, schema: Schema): Plugin[];
|
|
9
16
|
}
|
|
10
17
|
//# sourceMappingURL=ExtensionMenu.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionMenu.d.ts","sourceRoot":"","sources":["../../../src/extension-menu/src/ExtensionMenu.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ExtensionMenu.d.ts","sourceRoot":"","sources":["../../../src/extension-menu/src/ExtensionMenu.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAsB,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE/D,OAAO,EAAE,KAAK,UAAU,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGrE,OAAO,EAIL,WAAW,EAIZ,MAAM,WAAW,CAAC;AAKnB,OAAO,EACL,aAAa,EACb,QAAQ,EACR,eAAe,EAEf,QAAQ,EAER,QAAQ,GACT,MAAM,WAAW,CAAC;AAkDnB,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,EAAE,EAAE,CAuR7E;AAED,MAAM,WAAW,UAAU;IACzB,UAAU,CAAC,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,GAAG,WAAW,EAAE,EAAE,CAAC;IACrD,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,qBAAa,aAAc,SAAQ,SAAS;IAG9B,SAAS,CAAC,MAAM,EAAE,UAAU;IAFxC,IAAI,SAAU;gBAEQ,MAAM,GAAE,UAA+B;IAIpD,qBAAqB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;CAY7E"}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { blockTypeItem, Dropdown, DropdownSubmenu, MenuItem, wrapItem, } from './menu.js';
|
|
2
1
|
import { NodeSelection } from 'prosemirror-state';
|
|
3
2
|
import { Extension } from '../../editor/src/mod.js';
|
|
4
3
|
import { toggleMark, wrapInList } from '../../editor/src/commands/mod.js';
|
|
4
|
+
import { blockTypeItem, Dropdown, DropdownSubmenu, MenuItem, wrapItem, } from './menu.js';
|
|
5
5
|
import { MenuPlugin } from './MenuPlugin.js';
|
|
6
6
|
import { icons } from './icons.js';
|
|
7
7
|
import { openPrompt, TextField } from './prompt.js';
|
|
8
|
+
export { blockTypeItem, Dropdown, DropdownSubmenu,
|
|
9
|
+
// MenuElement,
|
|
10
|
+
MenuItem,
|
|
11
|
+
// MenuItemSpec,
|
|
12
|
+
wrapItem, } from './menu.js';
|
|
8
13
|
function canInsert(state, nodeType) {
|
|
9
14
|
let $from = state.selection.$from;
|
|
10
15
|
for (let d = $from.depth; d >= 0; d--) {
|
|
@@ -240,10 +245,6 @@ export function buildMenu(editor, schema) {
|
|
|
240
245
|
selectParentNodeItem,
|
|
241
246
|
]),
|
|
242
247
|
];
|
|
243
|
-
r.fullMenu = r.inlineMenu.concat([[r.insertMenu, r.typeMenu]], [[
|
|
244
|
-
undoItem,
|
|
245
|
-
redoItem,
|
|
246
|
-
]], r.blockMenu);
|
|
247
248
|
*/
|
|
248
249
|
menu.push(new MenuItem({
|
|
249
250
|
title: 'Undo last change',
|
|
@@ -257,33 +258,40 @@ export function buildMenu(editor, schema) {
|
|
|
257
258
|
enable: () => editor.can().redo().run(),
|
|
258
259
|
icon: icons.redo,
|
|
259
260
|
}));
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
261
|
+
if (schema.nodes.table) {
|
|
262
|
+
const item = (label, cmdName) => {
|
|
263
|
+
return new MenuItem({ label, enable: () => editor.can()[cmdName]().run(), run: () => editor.chain()[cmdName]().run() });
|
|
264
|
+
};
|
|
265
|
+
const tableMenu = [
|
|
266
|
+
item('Insert table', 'insertTable'),
|
|
267
|
+
item('Insert column before', 'addColumnBefore'),
|
|
268
|
+
item('Insert column after', 'addColumnAfter'),
|
|
269
|
+
item('Delete column', 'deleteColumn'),
|
|
270
|
+
item('Insert row before', 'addRowBefore'),
|
|
271
|
+
item('Insert row after', 'addRowAfter'),
|
|
272
|
+
item('Delete row', 'deleteRow'),
|
|
273
|
+
item('Delete table', 'deleteTable'),
|
|
274
|
+
item('Merge cells', 'mergeCells'),
|
|
275
|
+
item('Split cell', 'splitCell'),
|
|
276
|
+
item('Toggle header column', 'toggleHeaderColumn'),
|
|
277
|
+
item('Toggle header row', 'toggleHeaderRow'),
|
|
278
|
+
item('Toggle header cells', 'toggleHeaderCell'),
|
|
279
|
+
// item('Make cell green', setCellAttr('background', '#dfd')),
|
|
280
|
+
// item('Make cell not-green', setCellAttr('background', null)),
|
|
281
|
+
];
|
|
282
|
+
menu.push(new Dropdown(tableMenu, { label: 'Table' }));
|
|
263
283
|
}
|
|
264
|
-
const tableMenu = [
|
|
265
|
-
item('Insert column before', addColumnBefore),
|
|
266
|
-
item('Insert column after', addColumnAfter),
|
|
267
|
-
item('Delete column', deleteColumn),
|
|
268
|
-
item('Insert row before', addRowBefore),
|
|
269
|
-
item('Insert row after', addRowAfter),
|
|
270
|
-
item('Delete row', deleteRow),
|
|
271
|
-
item('Delete table', deleteTable),
|
|
272
|
-
item('Merge cells', mergeCells),
|
|
273
|
-
item('Split cell', splitCell),
|
|
274
|
-
item('Toggle header column', toggleHeaderColumn),
|
|
275
|
-
item('Toggle header row', toggleHeaderRow),
|
|
276
|
-
item('Toggle header cells', toggleHeaderCell),
|
|
277
|
-
item('Make cell green', setCellAttr('background', '#dfd')),
|
|
278
|
-
item('Make cell not-green', setCellAttr('background', null)),
|
|
279
|
-
];
|
|
280
|
-
menu.splice(2, 0, [new Dropdown(tableMenu, { label: 'Table' })]);
|
|
281
|
-
*/
|
|
282
284
|
return [menu, blockMenu];
|
|
283
285
|
}
|
|
284
286
|
export class ExtensionMenu extends Extension {
|
|
285
|
-
constructor() {
|
|
286
|
-
super(
|
|
287
|
+
constructor(config = { floating: true }) {
|
|
288
|
+
super(config);
|
|
289
|
+
Object.defineProperty(this, "config", {
|
|
290
|
+
enumerable: true,
|
|
291
|
+
configurable: true,
|
|
292
|
+
writable: true,
|
|
293
|
+
value: config
|
|
294
|
+
});
|
|
287
295
|
Object.defineProperty(this, "name", {
|
|
288
296
|
enumerable: true,
|
|
289
297
|
configurable: true,
|
|
@@ -292,10 +300,14 @@ export class ExtensionMenu extends Extension {
|
|
|
292
300
|
});
|
|
293
301
|
}
|
|
294
302
|
getProseMirrorPlugins(editor, schema) {
|
|
303
|
+
let content = buildMenu(editor, schema);
|
|
304
|
+
if (this.config.modifyMenu) {
|
|
305
|
+
content = this.config.modifyMenu(content);
|
|
306
|
+
}
|
|
295
307
|
return [
|
|
296
308
|
new MenuPlugin({
|
|
297
|
-
content
|
|
298
|
-
floating:
|
|
309
|
+
content,
|
|
310
|
+
floating: this.config.floating,
|
|
299
311
|
}),
|
|
300
312
|
];
|
|
301
313
|
}
|