@modusoperandi/licit-vignette 0.0.16

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.
Files changed (51) hide show
  1. package/.eslintignore +4 -0
  2. package/.eslintrc.js +107 -0
  3. package/.prettierignore +6 -0
  4. package/.prettierrc +5 -0
  5. package/.stylelintignore +3 -0
  6. package/.stylelintrc.json +10 -0
  7. package/LICENSE +21 -0
  8. package/README.md +33 -0
  9. package/babel.config.json +53 -0
  10. package/dist/Constants.d.ts +6 -0
  11. package/dist/Constants.js +18 -0
  12. package/dist/CreateCommand.d.ts +7 -0
  13. package/dist/CreateCommand.js +30 -0
  14. package/dist/TableBackgroundColorCommand.d.ts +5 -0
  15. package/dist/TableBackgroundColorCommand.js +21 -0
  16. package/dist/TableBorderColorCommand.d.ts +5 -0
  17. package/dist/TableBorderColorCommand.js +21 -0
  18. package/dist/VignetteCommand.d.ts +12 -0
  19. package/dist/VignetteCommand.js +104 -0
  20. package/dist/VignetteMenuPlugin.d.ts +19 -0
  21. package/dist/VignetteMenuPlugin.js +120 -0
  22. package/dist/VignetteNodeSpec.d.ts +34 -0
  23. package/dist/VignetteNodeSpec.js +83 -0
  24. package/dist/VignettePlugin.d.ts +12 -0
  25. package/dist/VignettePlugin.js +49 -0
  26. package/dist/VignettePlugins.d.ts +4 -0
  27. package/dist/VignettePlugins.js +11 -0
  28. package/dist/index.d.ts +2 -0
  29. package/dist/index.js +13 -0
  30. package/dist/index.test.js +48 -0
  31. package/dist/ui/TableColorCommand.d.ts +14 -0
  32. package/dist/ui/TableColorCommand.js +64 -0
  33. package/jest.config.ts +208 -0
  34. package/jest.setup.js +2 -0
  35. package/lint.sh +4 -0
  36. package/package.json +132 -0
  37. package/sonar-project.properties +11 -0
  38. package/src/Constants.ts +6 -0
  39. package/src/CreateCommand.ts +38 -0
  40. package/src/TableBackgroundColorCommand.ts +9 -0
  41. package/src/TableBorderColorCommand.ts +9 -0
  42. package/src/VignetteCommand.ts +103 -0
  43. package/src/VignetteMenuPlugin.ts +151 -0
  44. package/src/VignetteNodeSpec.ts +74 -0
  45. package/src/VignettePlugin.ts +53 -0
  46. package/src/VignettePlugins.ts +7 -0
  47. package/src/index.test.ts +59 -0
  48. package/src/index.ts +3 -0
  49. package/src/ui/TableColorCommand.tsx +79 -0
  50. package/tsconfig.json +38 -0
  51. package/webpack.config.js +89 -0
package/.eslintignore ADDED
@@ -0,0 +1,4 @@
1
+ /package.json
2
+ /bin
3
+ /dist
4
+ /src/*.test.ts
package/.eslintrc.js ADDED
@@ -0,0 +1,107 @@
1
+ module.exports = {
2
+ parser: '@typescript-eslint/parser',
3
+ parserOptions: {
4
+ sourceType: 'module',
5
+ allowImportExportEverywhere: false,
6
+ codeFrame: true,
7
+ ecmaFeatures: {
8
+ jsx: true,
9
+ tsx: true,
10
+ },
11
+ },
12
+ plugins: ['@typescript-eslint', 'react'],
13
+ extends: [
14
+ 'eslint:recommended',
15
+ 'plugin:@typescript-eslint/eslint-recommended',
16
+ 'plugin:@typescript-eslint/recommended',
17
+ 'plugin:import/typescript',
18
+ ],
19
+ rules: {
20
+ 'react/jsx-sort-props': 'error',
21
+ 'react/jsx-uses-react': 'error',
22
+ 'react/jsx-uses-vars': 'error',
23
+ 'consistent-return': 'error',
24
+ 'no-debugger': 'error',
25
+ 'no-invalid-regexp': 'error',
26
+ 'no-mixed-spaces-and-tabs': 'error',
27
+ 'no-trailing-spaces': 'error',
28
+ 'no-undef': 'error',
29
+ '@typescript-eslint/no-unused-vars': [
30
+ 'error',
31
+ {
32
+ vars: 'all',
33
+ args: 'all',
34
+ ignoreRestSiblings: false,
35
+ argsIgnorePattern: '^_',
36
+ },
37
+ ],
38
+ 'no-var': 'error',
39
+ 'prefer-const': 'error',
40
+ quotes: [2, 'single', {avoidEscape: true}],
41
+ semi: [2, 'always'],
42
+ strict: 0,
43
+ },
44
+ globals: {
45
+ __dirname: false,
46
+ Blob: false,
47
+ File: false,
48
+ Class: false,
49
+ Component: false,
50
+ CSSPageRule: false,
51
+ ClipboardEvent: false,
52
+ Document: true,
53
+ Element: false,
54
+ Event: false,
55
+ HTMLElement: false,
56
+ HTMLDivElement: false,
57
+ HTMLTableCellElement: false,
58
+ HTMLButtonElement: false,
59
+ HTMLLIElement: false,
60
+ HTMLInputElement: false,
61
+ Image: false,
62
+ JSX: false,
63
+ TSX: false,
64
+ localStorage: false,
65
+ Map: false,
66
+ DragEvent: false,
67
+ MouseEvent: false,
68
+ KeyboardEvent: false,
69
+ MutationObserver: false,
70
+ Promise: false,
71
+ Set: false,
72
+ Slice: false,
73
+ SyntheticEvent: false,
74
+ SyntheticMouseEvent: false,
75
+ cancelAnimationFrame: false,
76
+ clearTimeout: false,
77
+ console: false,
78
+ document: false,
79
+ module: false,
80
+ process: false,
81
+ require: false,
82
+ requestAnimationFrame: false,
83
+ setTimeout: false,
84
+ window: false,
85
+ Text: false,
86
+ DataTransfer: false,
87
+ Node: false,
88
+ SVGElement: false,
89
+ structuredClone: false,
90
+ HTMLTableElement: false,
91
+ HTMLTableColElement: false,
92
+ HTMLTableSectionElement: false,
93
+ MutationRecord: false,
94
+ URL: false,
95
+ React:false,
96
+ },
97
+ overrides: [
98
+ {
99
+ files: ['*.ts', '*.tsx'],
100
+ // enable jest globals in test files
101
+ plugins: ['jest'],
102
+ env: {
103
+ 'jest/globals': true,
104
+ },
105
+ },
106
+ ],
107
+ };
@@ -0,0 +1,6 @@
1
+ /package.json
2
+ /bin
3
+ /dist
4
+ /.eslintrc
5
+ /.vscode
6
+ /.stylelintrc.json
package/.prettierrc ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "bracketSpacing": false,
3
+ "singleQuote": true,
4
+ "trailingComma": "es5"
5
+ }
@@ -0,0 +1,3 @@
1
+ /bin
2
+ /dist
3
+ /coverage
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "stylelint-config-standard",
3
+ "rules": {
4
+ "selector-type-no-unknown": [true, {
5
+ "ignoreTypes": ["nobr"]
6
+ }],
7
+ "no-descending-specificity":null,
8
+ "selector-class-pattern": null
9
+ }
10
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Modus Operandi Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Vignette ProseMirror Plugin For Licit
2
+
3
+ The Vignette Plugin provides a "vignette box" which allows the document to highlight or re-enforce information. They are used to describe emerging concepts, lessons learned, appropriate quotes, etc. See the image below. Blue background, darker blue outline, normal text/links/images inside of the box:.
4
+
5
+ ## Build
6
+
7
+ ### Dependency
8
+
9
+ ### Commands
10
+
11
+ - npm ci
12
+
13
+ - npm pack
14
+
15
+ #### To use this in Licit
16
+
17
+ Include plugin in licit component
18
+
19
+ - import VignettePlugins
20
+
21
+ - add VignettePlugins array in licit's plugin array
22
+
23
+ ```
24
+
25
+ import { VignettePlugins } from '@modusoperandi/licit-vignette';
26
+
27
+
28
+ const plugins = [...VignettePlugins]
29
+
30
+ ReactDOM.render(<Licit docID={0} plugins={plugins}/>
31
+
32
+
33
+ ```
@@ -0,0 +1,53 @@
1
+ {
2
+ "presets": [
3
+ [
4
+ "@babel/preset-env",
5
+ {
6
+ "targets": {
7
+ "node": true
8
+ }
9
+ }
10
+ ],
11
+ "@babel/preset-react",
12
+ "@babel/preset-typescript"
13
+ ],
14
+ "plugins": [
15
+ "@babel/plugin-proposal-class-properties",
16
+ "@babel/plugin-proposal-export-default-from",
17
+ "transform-react-remove-prop-types",
18
+ "@babel/plugin-transform-typescript",
19
+ "@babel/plugin-proposal-object-rest-spread",
20
+ "@babel/plugin-transform-parameters",
21
+ [
22
+ "@babel/plugin-transform-runtime",
23
+ {
24
+ "helpers": false,
25
+ "regenerator": true,
26
+ "absoluteRuntime": "babel-runtime"
27
+ }
28
+ ],
29
+ "@babel/plugin-syntax-dynamic-import",
30
+ "@babel/plugin-syntax-import-meta",
31
+ "@babel/plugin-proposal-json-strings",
32
+ [
33
+ "@babel/plugin-proposal-decorators",
34
+ {
35
+ "legacy": true
36
+ }
37
+ ],
38
+ "@babel/plugin-proposal-function-sent",
39
+ "@babel/plugin-proposal-export-namespace-from",
40
+ "@babel/plugin-proposal-numeric-separator",
41
+ "@babel/plugin-proposal-throw-expressions",
42
+ "@babel/plugin-proposal-logical-assignment-operators",
43
+ "@babel/plugin-proposal-optional-chaining",
44
+ [
45
+ "@babel/plugin-proposal-pipeline-operator",
46
+ {
47
+ "proposal": "minimal"
48
+ }
49
+ ],
50
+ "@babel/plugin-proposal-nullish-coalescing-operator",
51
+ "@babel/plugin-proposal-do-expressions"
52
+ ]
53
+ }
@@ -0,0 +1,6 @@
1
+ export declare const VIGNETTE = "vignette";
2
+ export declare const PARAGRAPH = "paragraph";
3
+ export declare const TABLE = "table";
4
+ export declare const TABLE_CELL = "table_cell";
5
+ export declare const DEF_BORDER_COLOR = "#36598d";
6
+ export declare const DEF_BORDER_RADIUS = "10px";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.VIGNETTE = exports.TABLE_CELL = exports.TABLE = exports.PARAGRAPH = exports.DEF_BORDER_RADIUS = exports.DEF_BORDER_COLOR = void 0;
7
+ const VIGNETTE = 'vignette';
8
+ exports.VIGNETTE = VIGNETTE;
9
+ const PARAGRAPH = 'paragraph';
10
+ exports.PARAGRAPH = PARAGRAPH;
11
+ const TABLE = 'table';
12
+ exports.TABLE = TABLE;
13
+ const TABLE_CELL = 'table_cell';
14
+ exports.TABLE_CELL = TABLE_CELL;
15
+ const DEF_BORDER_COLOR = '#36598d';
16
+ exports.DEF_BORDER_COLOR = DEF_BORDER_COLOR;
17
+ const DEF_BORDER_RADIUS = '10px';
18
+ exports.DEF_BORDER_RADIUS = DEF_BORDER_RADIUS;
@@ -0,0 +1,7 @@
1
+ import { EditorState } from 'prosemirror-state';
2
+ import { Transform } from 'prosemirror-transform';
3
+ import { EditorView } from 'prosemirror-view';
4
+ import { UICommand } from '@modusoperandi/licit-doc-attrs-step';
5
+ type ExecuteCall = (state: EditorState, dispatch?: (tr: Transform) => void, view?: EditorView) => boolean;
6
+ export default function createCommand(execute: ExecuteCall): UICommand;
7
+ export {};
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = createCommand;
7
+ var _licitDocAttrsStep = require("@modusoperandi/licit-doc-attrs-step");
8
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
10
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
11
+ function createCommand(execute) {
12
+ class CustomCommand extends _licitDocAttrsStep.UICommand {
13
+ constructor() {
14
+ super(...arguments);
15
+ _defineProperty(this, "isEnabled", state => {
16
+ return this.execute(state);
17
+ });
18
+ _defineProperty(this, "execute", (state, dispatch, view) => {
19
+ const tr = state.tr;
20
+ let endTr = tr;
21
+ execute(state, nextTr => {
22
+ endTr = nextTr;
23
+ dispatch && dispatch(endTr);
24
+ }, view);
25
+ return endTr.docChanged || tr !== endTr;
26
+ });
27
+ }
28
+ }
29
+ return new CustomCommand();
30
+ }
@@ -0,0 +1,5 @@
1
+ import TableColorCommand from './ui/TableColorCommand';
2
+ declare class TableBackgroundColorCommand extends TableColorCommand {
3
+ getAttrName: () => string;
4
+ }
5
+ export default TableBackgroundColorCommand;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _TableColorCommand = _interopRequireDefault(require("./ui/TableColorCommand"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
11
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
12
+ class TableBackgroundColorCommand extends _TableColorCommand.default {
13
+ constructor() {
14
+ super(...arguments);
15
+ _defineProperty(this, "getAttrName", () => {
16
+ return 'background';
17
+ });
18
+ }
19
+ }
20
+ var _default = TableBackgroundColorCommand;
21
+ exports.default = _default;
@@ -0,0 +1,5 @@
1
+ import TableColorCommand from './ui/TableColorCommand';
2
+ declare class TableBorderColorCommand extends TableColorCommand {
3
+ getAttrName: () => string;
4
+ }
5
+ export default TableBorderColorCommand;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _TableColorCommand = _interopRequireDefault(require("./ui/TableColorCommand"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
11
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
12
+ class TableBorderColorCommand extends _TableColorCommand.default {
13
+ constructor() {
14
+ super(...arguments);
15
+ _defineProperty(this, "getAttrName", () => {
16
+ return 'borderColor';
17
+ });
18
+ }
19
+ }
20
+ var _default = TableBorderColorCommand;
21
+ exports.default = _default;
@@ -0,0 +1,12 @@
1
+ import { Schema } from 'prosemirror-model';
2
+ import { EditorState, Transaction } from 'prosemirror-state';
3
+ import { EditorView } from 'prosemirror-view';
4
+ import { UICommand } from '@modusoperandi/licit-doc-attrs-step';
5
+ declare class VignetteCommand extends UICommand {
6
+ isEnabled: (state: EditorState, view?: EditorView) => boolean;
7
+ execute: (state: EditorState, dispatch?: (tr: Transaction) => void, view?: EditorView) => boolean;
8
+ __isEnabled: (_state: EditorState, _view?: EditorView) => boolean;
9
+ insertTable(tr: Transaction, schema: Schema, rows: number, cols: number): Transaction;
10
+ insertParagraph(state: EditorState, tr: Transaction): Transaction;
11
+ }
12
+ export default VignetteCommand;
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _prosemirrorModel = require("prosemirror-model");
8
+ var _prosemirrorState = require("prosemirror-state");
9
+ var _licitDocAttrsStep = require("@modusoperandi/licit-doc-attrs-step");
10
+ var _Constants = require("./Constants");
11
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
13
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
14
+ class VignetteCommand extends _licitDocAttrsStep.UICommand {
15
+ constructor() {
16
+ super(...arguments);
17
+ _defineProperty(this, "isEnabled", (state, view) => {
18
+ return this.__isEnabled(state, view);
19
+ });
20
+ _defineProperty(this, "execute", (state, dispatch, view) => {
21
+ if (dispatch) {
22
+ const {
23
+ schema
24
+ } = state;
25
+ let {
26
+ tr
27
+ } = state;
28
+ tr = this.insertTable(tr, schema, 1, 1);
29
+ tr = this.insertParagraph(state, tr);
30
+ dispatch(tr);
31
+ view && view.focus();
32
+ }
33
+ return true;
34
+ });
35
+ _defineProperty(this, "__isEnabled", (_state, _view) => {
36
+ return true;
37
+ });
38
+ }
39
+ insertTable(tr, schema, rows, cols) {
40
+ if (!tr.selection || !tr.doc) {
41
+ return tr;
42
+ }
43
+ const {
44
+ from,
45
+ to
46
+ } = tr.selection;
47
+ if (from !== to) {
48
+ return tr;
49
+ }
50
+ const {
51
+ nodes
52
+ } = schema;
53
+ const cell = nodes[_Constants.TABLE_CELL];
54
+ const paragraph = nodes[_Constants.PARAGRAPH];
55
+ const row = nodes['table_row'];
56
+ const table = nodes[_Constants.TABLE];
57
+ if (!(cell && paragraph && row && table)) {
58
+ return tr;
59
+ }
60
+ const rowNodes = [];
61
+ for (let rr = 0; rr < rows; rr++) {
62
+ const cellNodes = [];
63
+ for (let cc = 0; cc < cols; cc++) {
64
+ // [FS] IRAD-950 2020-05-25
65
+ // Fix:Extra arrow key required for cell navigation using arrow right/Left
66
+ const cellNode = cell.create({
67
+ borderColor: _Constants.DEF_BORDER_COLOR,
68
+ background: '#dce6f2',
69
+ vignette: true
70
+ }, _prosemirrorModel.Fragment.fromArray([paragraph.create()]));
71
+ cellNodes.push(cellNode);
72
+ }
73
+ const rowNode = row.create({}, _prosemirrorModel.Fragment.from(cellNodes));
74
+ rowNodes.push(rowNode);
75
+ }
76
+ const tableNode = table.create({
77
+ vignette: true
78
+ }, _prosemirrorModel.Fragment.from(rowNodes));
79
+ tr = tr.insert(from, _prosemirrorModel.Fragment.from(tableNode));
80
+ const selection = _prosemirrorState.TextSelection.create(tr.doc, from + 5, from + 5);
81
+ tr = tr.setSelection(selection);
82
+ return tr;
83
+ }
84
+
85
+ // [FS] 2021-04-01
86
+ // Add empty line after table drop
87
+ // To make easier to enter a line after table
88
+ insertParagraph(state, tr) {
89
+ const paragraph = state.schema.nodes[_Constants.PARAGRAPH];
90
+ const textNode = state.schema.text(' ');
91
+ const {
92
+ from,
93
+ to
94
+ } = tr.selection;
95
+ if (from !== to) {
96
+ return tr;
97
+ }
98
+ const paragraphNode = paragraph.create({}, textNode, null);
99
+ tr = tr.insert(from + tr.selection.$head.node(1).nodeSize - 4, _prosemirrorModel.Fragment.from(paragraphNode));
100
+ return tr;
101
+ }
102
+ }
103
+ var _default = VignetteCommand;
104
+ exports.default = _default;
@@ -0,0 +1,19 @@
1
+ import { Plugin } from 'prosemirror-state';
2
+ import TableBackgroundColorCommand from './TableBackgroundColorCommand';
3
+ import TableBorderColorCommand from './TableBorderColorCommand';
4
+ export declare const TABLE_BACKGROUND_COLOR: TableBackgroundColorCommand;
5
+ export declare const TABLE_BORDER_COLOR: TableBorderColorCommand;
6
+ export declare const TABLE_DELETE_TABLE: UICommand;
7
+ export declare const VIGNETTE_COMMANDS_GROUP: ({
8
+ 'Fill Color...': TableBackgroundColorCommand;
9
+ 'Border Color....': TableBorderColorCommand;
10
+ 'Delete Vignette'?: undefined;
11
+ } | {
12
+ 'Delete Vignette': UICommand;
13
+ 'Fill Color...'?: undefined;
14
+ 'Border Color....'?: undefined;
15
+ })[];
16
+ declare class VignetteMenuPlugin extends Plugin {
17
+ constructor();
18
+ }
19
+ export default VignetteMenuPlugin;
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.VIGNETTE_COMMANDS_GROUP = exports.TABLE_DELETE_TABLE = exports.TABLE_BORDER_COLOR = exports.TABLE_BACKGROUND_COLOR = void 0;
7
+ var _prosemirrorState = require("prosemirror-state");
8
+ var _TableBackgroundColorCommand = _interopRequireDefault(require("./TableBackgroundColorCommand"));
9
+ var _TableBorderColorCommand = _interopRequireDefault(require("./TableBorderColorCommand"));
10
+ var _CreateCommand = _interopRequireDefault(require("./CreateCommand"));
11
+ var _prosemirrorTables = require("prosemirror-tables");
12
+ var _Constants = require("./Constants");
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
16
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
17
+ const TABLE_BACKGROUND_COLOR = new _TableBackgroundColorCommand.default();
18
+ exports.TABLE_BACKGROUND_COLOR = TABLE_BACKGROUND_COLOR;
19
+ const TABLE_BORDER_COLOR = new _TableBorderColorCommand.default();
20
+ exports.TABLE_BORDER_COLOR = TABLE_BORDER_COLOR;
21
+ const TABLE_DELETE_TABLE = (0, _CreateCommand.default)(_prosemirrorTables.deleteTable);
22
+ exports.TABLE_DELETE_TABLE = TABLE_DELETE_TABLE;
23
+ const VIGNETTE_COMMANDS_GROUP = [{
24
+ 'Fill Color...': TABLE_BACKGROUND_COLOR,
25
+ 'Border Color....': TABLE_BORDER_COLOR
26
+ }, {
27
+ 'Delete Vignette': TABLE_DELETE_TABLE
28
+ }];
29
+ exports.VIGNETTE_COMMANDS_GROUP = VIGNETTE_COMMANDS_GROUP;
30
+ class VignetteView {
31
+ constructor(editorView) {
32
+ _defineProperty(this, "destroy", () => {
33
+ // do nothing.
34
+ });
35
+ this.setCustomMenu(editorView);
36
+ this.setCustomTableNodeViewUpdate(editorView);
37
+ }
38
+ setCustomMenu(editorView) {
39
+ editorView['pluginViews'].forEach(pluginView => {
40
+ if (
41
+ // 'TableCellTooltipView' has property _cellElement
42
+ Object.prototype.hasOwnProperty.call(pluginView, '_cellElement')) {
43
+ pluginView['getMenu'] = this.getMenu.bind(this);
44
+ }
45
+ });
46
+ }
47
+ setCustomTableNodeViewUpdate(editorView) {
48
+ const tableNodeView = editorView['nodeViews']['table'];
49
+ const tableNodeViewEx = this.tableNodeViewEx.bind(this, tableNodeView);
50
+ editorView['nodeViews'][_Constants.TABLE] = tableNodeViewEx;
51
+ const index = editorView.state.plugins.findIndex(plugin => {
52
+ let found = false;
53
+ if (plugin.spec.key) {
54
+ found = plugin.spec.key['key'].includes('tableColumnResizing$');
55
+ }
56
+ return found;
57
+ });
58
+ if (-1 != index) {
59
+ editorView.state.plugins[index].spec.props.nodeViews[_Constants.TABLE] = tableNodeViewEx;
60
+ }
61
+ }
62
+ tableNodeViewEx(tableNodeView, node, view) {
63
+ const base = tableNodeView && tableNodeView(node, view);
64
+ if (base && base.update && node.attrs.vignette) {
65
+ base.update = this.updateEx.bind(base, base.update, this);
66
+ this.updateBorder(base);
67
+ }
68
+ return base;
69
+ }
70
+ updateEx(update, self, node) {
71
+ const result = update.call(this, node);
72
+ if (result) {
73
+ self.updateBorder(this);
74
+ }
75
+ return result;
76
+ }
77
+ updateBorder(tableView) {
78
+ tableView.table.style.border = 'none';
79
+ }
80
+ static isVignette(state, actionNode) {
81
+ let vignette = false;
82
+ if (state.selection instanceof _prosemirrorTables.CellSelection) {
83
+ if (state.selection.$anchorCell.node(-1).attrs.vignette) {
84
+ vignette = true;
85
+ }
86
+ }
87
+ if (actionNode && actionNode.attrs.vignette) {
88
+ vignette = true;
89
+ }
90
+ if (state.selection.$anchor.node(1).attrs.vignette) {
91
+ vignette = true;
92
+ }
93
+ return vignette;
94
+ }
95
+ getMenu(state, actionNode, cmdGrps) {
96
+ let vignette = VignetteView.isVignette(state, actionNode);
97
+ cmdGrps.forEach(cmdGrp => {
98
+ Object.entries(cmdGrp).forEach(entry => {
99
+ entry[1].isEnabled = this.isEnabledEx.bind(entry[1], entry[1].isEnabled);
100
+ });
101
+ });
102
+ return vignette ? VIGNETTE_COMMANDS_GROUP : cmdGrps;
103
+ }
104
+ isEnabledEx(isEnabled, state, view) {
105
+ return VignetteView.isVignette(state, null) ? false : isEnabled.call(this, state, view);
106
+ }
107
+ }
108
+ const SPEC = {
109
+ key: new _prosemirrorState.PluginKey('VignetteMenuPlugin'),
110
+ view(editorView) {
111
+ return new VignetteView(editorView);
112
+ }
113
+ };
114
+ class VignetteMenuPlugin extends _prosemirrorState.Plugin {
115
+ constructor() {
116
+ super(SPEC);
117
+ }
118
+ }
119
+ var _default = VignetteMenuPlugin;
120
+ exports.default = _default;
@@ -0,0 +1,34 @@
1
+ import { Node, NodeSpec } from 'prosemirror-model';
2
+ export declare const VignetteTableNodeSpec: (nodespec: NodeSpec) => NodeSpec & {
3
+ attrs: {
4
+ marginLeft: {
5
+ default: any;
6
+ };
7
+ vignette: {
8
+ default: boolean;
9
+ };
10
+ };
11
+ parseDOM: {
12
+ tag: string;
13
+ getAttrs(dom: HTMLElement): unknown | null;
14
+ style: string;
15
+ }[];
16
+ toDOM(node: Node): Array<unknown>;
17
+ };
18
+ export declare const VignetteTableCellNodeSpec: (nodespec: NodeSpec) => NodeSpec & {
19
+ attrs: {
20
+ [name: string]: import("prosemirror-model").AttributeSpec;
21
+ } & {
22
+ vignette: {
23
+ default: boolean;
24
+ };
25
+ };
26
+ parseDOM: {
27
+ tag: string;
28
+ getAttrs: (dom: HTMLElement) => (false | import("prosemirror-model").Attrs) & {
29
+ vignette: string | boolean;
30
+ };
31
+ }[];
32
+ toDOM(node: Node): Array<unknown>;
33
+ };
34
+ export default VignetteTableNodeSpec;