@modusoperandi/licit 1.5.0 → 1.6.1

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.
package/EditorCommands.js CHANGED
@@ -16,6 +16,7 @@ import MarksClearCommand from './MarksClearCommand.js';
16
16
  import PrintCommand from './PrintCommand.js';
17
17
  import TableBackgroundColorCommand from './TableBackgroundColorCommand.js';
18
18
  import TableBorderColorCommand from './TableBorderColorCommand.js';
19
+ import TableDetailsCommand from './TableDetailsCommand.js';
19
20
  import TableInsertCommand from './TableInsertCommand.js';
20
21
  import TableMergeCellsCommand from './TableMergeCellsCommand.js';
21
22
  import { HeadingCommand, IndentCommand, MarkToggleCommand, TextAlignCommand, TextColorCommand, TextHighlightCommand, TextLineSpacingCommand } from '@modusoperandi/licit-ui-commands';
@@ -79,6 +80,7 @@ export var TABLE_ADD_ROW_AFTER = createCommand(addRowAfter);
79
80
  export var TABLE_ADD_ROW_BEFORE = createCommand(addRowBefore);
80
81
  export var TABLE_BACKGROUND_COLOR = new TableBackgroundColorCommand();
81
82
  export var TABLE_BORDER_COLOR = new TableBorderColorCommand();
83
+ export var TABLE_DETAILS = new TableDetailsCommand();
82
84
  export var TABLE_DELETE_COLUMN = createCommand(deleteColumn);
83
85
  export var TABLE_DELETE_ROW = createCommand(deleteRow);
84
86
  export var TABLE_DELETE_TABLE = createCommand(deleteTable);
@@ -18,6 +18,7 @@ import MarksClearCommand from './MarksClearCommand.js';
18
18
  import PrintCommand from './PrintCommand.js';
19
19
  import TableBackgroundColorCommand from './TableBackgroundColorCommand.js';
20
20
  import TableBorderColorCommand from './TableBorderColorCommand.js';
21
+ import TableDetailsCommand from './TableDetailsCommand.js';
21
22
  import TableInsertCommand from './TableInsertCommand.js';
22
23
  import TableMergeCellsCommand from './TableMergeCellsCommand.js';
23
24
  import {
@@ -101,6 +102,7 @@ export const TABLE_ADD_ROW_AFTER = createCommand(addRowAfter);
101
102
  export const TABLE_ADD_ROW_BEFORE = createCommand(addRowBefore);
102
103
  export const TABLE_BACKGROUND_COLOR = new TableBackgroundColorCommand();
103
104
  export const TABLE_BORDER_COLOR = new TableBorderColorCommand();
105
+ export const TABLE_DETAILS = new TableDetailsCommand();
104
106
  export const TABLE_DELETE_COLUMN = createCommand(deleteColumn);
105
107
  export const TABLE_DELETE_ROW = createCommand(deleteRow);
106
108
  export const TABLE_DELETE_TABLE = createCommand(deleteTable);
@@ -0,0 +1,123 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
3
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
4
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
5
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
6
+ function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
7
+ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
8
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
9
+ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
10
+ function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
11
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
12
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
13
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
14
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
15
+ import { EditorState, TextSelection } from 'prosemirror-state';
16
+ import * as React from 'react';
17
+ import { Transform } from 'prosemirror-transform';
18
+ import { EditorView } from 'prosemirror-view';
19
+ import TableDetails from './ui/TableDetails';
20
+ import { findParentNodeOfType } from 'prosemirror-utils';
21
+ import { createPopUp } from '@modusoperandi/licit-ui-commands';
22
+ import { UICommand } from '@modusoperandi/licit-doc-attrs-step';
23
+ var TableDetailsCommand = /*#__PURE__*/function (_UICommand) {
24
+ function TableDetailsCommand() {
25
+ var _this;
26
+ _classCallCheck(this, TableDetailsCommand);
27
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
28
+ args[_key] = arguments[_key];
29
+ }
30
+ _this = _callSuper(this, TableDetailsCommand, [].concat(args));
31
+ _defineProperty(_this, "_popUp", null);
32
+ _defineProperty(_this, "isEnabled", function (state) {
33
+ return true;
34
+ });
35
+ _defineProperty(_this, "execute", function (state, dispatch, view) {
36
+ if (!view) {
37
+ return false;
38
+ }
39
+ var selection = state.selection,
40
+ schema = state.schema;
41
+ var tableNode = findParentNodeOfType(schema.nodes.table)(selection);
42
+ if (!tableNode) {
43
+ return false;
44
+ }
45
+ var tableDOM = _this.findTableDOM(view, tableNode.start);
46
+ if (!tableDOM) {
47
+ return false;
48
+ }
49
+ var tableRect = tableDOM.getBoundingClientRect();
50
+ var cellDOM = _this.getSelectedCellDOM(view);
51
+ var cellRect = cellDOM === null || cellDOM === void 0 ? void 0 : cellDOM.getBoundingClientRect();
52
+ var viewProps = {
53
+ close: function close() {
54
+ var _this$_popUp;
55
+ (_this$_popUp = _this._popUp) === null || _this$_popUp === void 0 || _this$_popUp.close(undefined);
56
+ },
57
+ editorView: view,
58
+ table: {
59
+ width: Math.round(tableRect.width),
60
+ height: Math.round(tableRect.height)
61
+ },
62
+ cell: cellRect ? {
63
+ width: Math.round(cellRect.width),
64
+ height: Math.round(cellRect.height)
65
+ } : null
66
+ };
67
+ return new Promise(function (resolve) {
68
+ _this._popUp = createPopUp(TableDetails, viewProps, {
69
+ modal: true,
70
+ onClose: function onClose(val) {
71
+ if (_this._popUp) {
72
+ resolve(val);
73
+ _this._popUp = null;
74
+ }
75
+ }
76
+ });
77
+ });
78
+ });
79
+ _defineProperty(_this, "waitForUserInput", function (_state, _dispatch, _view, _event) {
80
+ return Promise.resolve(undefined);
81
+ });
82
+ _defineProperty(_this, "executeWithUserInput", function (_state, _dispatch, _view, _inputs) {
83
+ return false;
84
+ });
85
+ return _this;
86
+ }
87
+ _inherits(TableDetailsCommand, _UICommand);
88
+ return _createClass(TableDetailsCommand, [{
89
+ key: "findTableDOM",
90
+ value: function findTableDOM(view, pos) {
91
+ var dom = view.domAtPos(pos);
92
+ if (dom.node instanceof HTMLElement) {
93
+ return dom.node.closest('table');
94
+ }
95
+ return null;
96
+ }
97
+ /**
98
+ * Finds the currently selected cell DOM
99
+ */
100
+ }, {
101
+ key: "getSelectedCellDOM",
102
+ value: function getSelectedCellDOM(view) {
103
+ var selection = view.state.selection;
104
+ if (!(selection instanceof TextSelection)) {
105
+ return null;
106
+ }
107
+ var _view$domAtPos = view.domAtPos(selection.from),
108
+ node = _view$domAtPos.node;
109
+
110
+ // 👇 Convert Text node → Element safely
111
+ var element = node.nodeType === Node.TEXT_NODE ? node.parentElement : node instanceof HTMLElement ? node : null;
112
+ if (!element) return null;
113
+ return element.closest('td, th');
114
+ }
115
+ }, {
116
+ key: "cancel",
117
+ value: function cancel() {
118
+ var _this$_popUp2;
119
+ (_this$_popUp2 = this._popUp) === null || _this$_popUp2 === void 0 || _this$_popUp2.close(undefined);
120
+ }
121
+ }]);
122
+ }(UICommand);
123
+ export default TableDetailsCommand;
@@ -0,0 +1,125 @@
1
+ // @flow
2
+
3
+ import { EditorState, TextSelection } from 'prosemirror-state';
4
+ import * as React from 'react';
5
+ import { Transform } from 'prosemirror-transform';
6
+ import { EditorView } from 'prosemirror-view';
7
+ import TableDetails from './ui/TableDetails';
8
+ import { findParentNodeOfType } from 'prosemirror-utils';
9
+ import { createPopUp } from '@modusoperandi/licit-ui-commands';
10
+ import { UICommand } from '@modusoperandi/licit-doc-attrs-step';
11
+
12
+
13
+ class TableDetailsCommand extends UICommand {
14
+ _popUp = null;
15
+ isEnabled = (state: EditorState): boolean => {
16
+ return true;
17
+ };
18
+ execute = (
19
+ state: EditorState,
20
+ dispatch: ?(tr: Transform) => void,
21
+ view: ?EditorView
22
+ ): boolean => {
23
+ if (!view) {
24
+ return false;
25
+ }
26
+ const { selection, schema } = state;
27
+ const tableNode = findParentNodeOfType(schema.nodes.table)(selection);
28
+ if (!tableNode) {
29
+ return false;
30
+ }
31
+ const tableDOM = this.findTableDOM(view, tableNode.start);
32
+ if (!tableDOM) {
33
+ return false;
34
+ }
35
+ const tableRect = tableDOM.getBoundingClientRect();
36
+
37
+ const cellDOM = this.getSelectedCellDOM(view);
38
+ const cellRect = cellDOM?.getBoundingClientRect();
39
+
40
+ const viewProps = {
41
+ close: () => {
42
+ this._popUp?.close(undefined);
43
+ },
44
+ editorView: view,
45
+ table: {
46
+ width: Math.round(tableRect.width),
47
+ height: Math.round(tableRect.height),
48
+ },
49
+ cell: cellRect
50
+ ? {
51
+ width: Math.round(cellRect.width),
52
+ height: Math.round(cellRect.height),
53
+ }
54
+ : null,
55
+ };
56
+
57
+ return new Promise((resolve) => {
58
+ this._popUp = createPopUp(TableDetails, viewProps, {
59
+ modal: true,
60
+ onClose: (val) => {
61
+ if (this._popUp) {
62
+ resolve(val);
63
+ this._popUp = null;
64
+ }
65
+ },
66
+ });
67
+ });
68
+ };
69
+
70
+ waitForUserInput = (
71
+ _state: EditorState,
72
+ _dispatch: ?(tr: Transform) => void,
73
+ _view: ?EditorView,
74
+ _event: ?React.SyntheticEvent
75
+ ): Promise<undefined> => {
76
+ return Promise.resolve(undefined);
77
+ };
78
+
79
+ executeWithUserInput = (
80
+ _state: EditorState,
81
+ _dispatch: ?(tr: Transform) => void,
82
+ _view: ?EditorView,
83
+ _inputs: ?string
84
+ ): boolean => {
85
+ return false;
86
+ };
87
+
88
+ findTableDOM(view: EditorView, pos: number): HTMLElement | null {
89
+ const dom = view.domAtPos(pos);
90
+
91
+ if (dom.node instanceof HTMLElement) {
92
+ return dom.node.closest('table');
93
+ }
94
+
95
+ return null;
96
+ }
97
+ /**
98
+ * Finds the currently selected cell DOM
99
+ */
100
+ getSelectedCellDOM(view: EditorView): HTMLElement | null {
101
+ const { selection } = view.state;
102
+
103
+ if (!(selection instanceof TextSelection)) {
104
+ return null;
105
+ }
106
+
107
+ const { node } = view.domAtPos(selection.from);
108
+
109
+ // 👇 Convert Text node → Element safely
110
+ const element =
111
+ node.nodeType === Node.TEXT_NODE
112
+ ? node.parentElement
113
+ : (node instanceof HTMLElement ? node : null);
114
+
115
+ if (!element) return null;
116
+
117
+ return element.closest('td, th');
118
+ }
119
+
120
+ cancel(): void {
121
+ this._popUp?.close(undefined);
122
+ }
123
+ }
124
+
125
+ export default TableDetailsCommand;