@modusoperandi/licit 1.0.8 → 1.0.10

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 (38) hide show
  1. package/DocNodeSpec.js +0 -2
  2. package/DocNodeSpec.js.flow +0 -2
  3. package/EditorCommands.js +0 -2
  4. package/EditorCommands.js.flow +0 -2
  5. package/EditorNodes.js +1 -3
  6. package/EditorNodes.js.flow +0 -3
  7. package/bom.xml +789 -608
  8. package/package.json +2 -4
  9. package/styles.css +1 -6
  10. package/ui/DocLayoutEditor.js +0 -10
  11. package/ui/DocLayoutEditor.js.flow +0 -12
  12. package/ui/Editor.js +2 -3
  13. package/ui/Editor.js.flow +1 -3
  14. package/ui/EditorToolbarConfig.js +1 -3
  15. package/ui/EditorToolbarConfig.js.flow +0 -2
  16. package/ui/czi-editor.css +0 -12
  17. package/MathEditCommand.js +0 -114
  18. package/MathEditCommand.js.flow +0 -119
  19. package/MathNodeSpec.js +0 -49
  20. package/MathNodeSpec.js.flow +0 -46
  21. package/ui/MathEditor.js +0 -86
  22. package/ui/MathEditor.js.flow +0 -70
  23. package/ui/MathInlineEditor.js +0 -121
  24. package/ui/MathInlineEditor.js.flow +0 -100
  25. package/ui/MathNodeView.js +0 -215
  26. package/ui/MathNodeView.js.flow +0 -175
  27. package/ui/mathquill-editor/MathQuillEditor.js +0 -183
  28. package/ui/mathquill-editor/MathQuillEditor.js.flow +0 -157
  29. package/ui/mathquill-editor/MathQuillEditorSymbols.js +0 -416
  30. package/ui/mathquill-editor/MathQuillEditorSymbols.js.flow +0 -483
  31. package/ui/mathquill-editor/MathQuillEditorSymbolsPanel.js +0 -67
  32. package/ui/mathquill-editor/MathQuillEditorSymbolsPanel.js.flow +0 -49
  33. package/ui/mathquill-editor/czi-mathquill-editor-symbols-panel.css +0 -39
  34. package/ui/mathquill-editor/czi-mathquill-editor.css +0 -50
  35. package/ui/mathquill-editor/mathquill-import-kludge.js +0 -13
  36. package/ui/mathquill-editor/mathquill-import-kludge.js.flow +0 -15
  37. package/ui/renderLaTeXAsHTML.js +0 -51
  38. package/ui/renderLaTeXAsHTML.js.flow +0 -42
@@ -1,70 +0,0 @@
1
- // @flow
2
-
3
- import * as React from 'react';
4
- import PropTypes from 'prop-types';
5
- import { CustomButton, preventEventDefault } from '@modusoperandi/licit-ui-commands';
6
- import MathQuillEditor from './mathquill-editor/MathQuillEditor.js';
7
-
8
- class MathEditor extends React.PureComponent<any, any> {
9
- // [FS] IRAD-1005 2020-07-07
10
- // Upgrade outdated packages.
11
- // To take care of the property type declaration.
12
- static propsTypes = {
13
- initialValue: PropTypes.string,
14
- close: function (props: any, propName: string) {
15
- const fn = props[propName];
16
- if (
17
- !fn.prototype ||
18
- (typeof fn.prototype.constructor !== 'function' &&
19
- fn.prototype.constructor.length !== 1)
20
- ) {
21
- return new Error(
22
- propName + 'must be a function with 1 arg of type string'
23
- );
24
- }
25
- return null;
26
- },
27
- };
28
-
29
- state = {
30
- initialValue: this.props.initialValue,
31
- value: this.props.initialValue || '',
32
- };
33
-
34
- render(): React.Element<any> {
35
- const { initialValue, value } = this.state;
36
- return (
37
- <div className="czi-math-editor">
38
- <form className="czi-form" onSubmit={preventEventDefault}>
39
- <fieldset>
40
- <legend>Insert Math</legend>
41
- <MathQuillEditor onChange={this._onChange} value={value} />
42
- </fieldset>
43
- <div className="czi-form-buttons">
44
- <CustomButton label="Cancel" onClick={this._cancel} />
45
- <CustomButton
46
- active={true}
47
- disabled={!this.state.value}
48
- label={initialValue ? 'Update' : 'Insert'}
49
- onClick={this._insert}
50
- />
51
- </div>
52
- </form>
53
- </div>
54
- );
55
- }
56
-
57
- _onChange = (value: string): void => {
58
- this.setState({ value });
59
- };
60
-
61
- _cancel = (): void => {
62
- this.props.close();
63
- };
64
-
65
- _insert = (): void => {
66
- this.props.close(this.state.value);
67
- };
68
- }
69
-
70
- export default MathEditor;
@@ -1,121 +0,0 @@
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
5
- 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); } }
6
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
7
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
8
- 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); }
9
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
10
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
11
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
12
- 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); }
13
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
14
- 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; }
15
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
16
- 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); }
17
- import { CustomButton, createPopUp } from '@modusoperandi/licit-ui-commands';
18
- import CustomEditorView from './CustomEditorView.js';
19
- import MathEditor from './MathEditor.js';
20
- import * as React from 'react';
21
- var MathAlignValues = {
22
- NONE: {
23
- value: null,
24
- text: 'Inline'
25
- },
26
- CENTER: {
27
- value: 'center',
28
- text: 'Break text'
29
- }
30
- };
31
- var bpfrpt_proptype_MathInlineEditorValue = {
32
- "align": PropTypes.string,
33
- "latex": PropTypes.string.isRequired
34
- };
35
- var MathInlineEditor = /*#__PURE__*/function (_React$PureComponent) {
36
- function MathInlineEditor() {
37
- var _this;
38
- _classCallCheck(this, MathInlineEditor);
39
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
40
- args[_key] = arguments[_key];
41
- }
42
- _this = _callSuper(this, MathInlineEditor, [].concat(args));
43
- _defineProperty(_this, "props", void 0);
44
- _defineProperty(_this, "_popUp", null);
45
- _defineProperty(_this, "_onClick", function (align) {
46
- var value = _this.props.value || {};
47
- _this.props.onSelect(_objectSpread(_objectSpread({}, value), {}, {
48
- align: align
49
- }));
50
- });
51
- _defineProperty(_this, "_editLatex", function (latex) {
52
- if (_this._popUp) {
53
- return;
54
- }
55
- var _this$props = _this.props,
56
- editorView = _this$props.editorView,
57
- value = _this$props.value;
58
- var props = {
59
- runtime: editorView ? editorView.runtime : null,
60
- initialValue: (value === null || value === void 0 ? void 0 : value.latex) || ''
61
- };
62
- _this._popUp = createPopUp(MathEditor, props, {
63
- autoDismiss: false,
64
- modal: true,
65
- onClose: function onClose(latex) {
66
- if (_this._popUp) {
67
- _this._popUp = null;
68
- if (latex !== undefined) {
69
- var _value = _this.props.value || {};
70
- _this.props.onSelect(_objectSpread(_objectSpread({}, _value), {}, {
71
- latex: latex
72
- }));
73
- }
74
- _this.props.onEditEnd();
75
- }
76
- }
77
- });
78
- _this.props.onEditStart();
79
- });
80
- return _this;
81
- }
82
- _inherits(MathInlineEditor, _React$PureComponent);
83
- return _createClass(MathInlineEditor, [{
84
- key: "componentWillUnmount",
85
- value: function componentWillUnmount() {
86
- var _this$_popUp;
87
- (_this$_popUp = this._popUp) === null || _this$_popUp === void 0 || _this$_popUp.close();
88
- }
89
- }, {
90
- key: "render",
91
- value: function render() {
92
- var _ref = this.props.value || {},
93
- align = _ref.align,
94
- latex = _ref.latex;
95
- var onClick = this._onClick;
96
- var buttons = Object.keys(MathAlignValues).map(function (key) {
97
- var _MathAlignValues$key = MathAlignValues[key],
98
- value = _MathAlignValues$key.value,
99
- text = _MathAlignValues$key.text;
100
- return /*#__PURE__*/React.createElement(CustomButton, {
101
- active: align === value,
102
- key: key,
103
- label: text,
104
- onClick: onClick,
105
- value: value
106
- });
107
- });
108
- return /*#__PURE__*/React.createElement("div", {
109
- className: "czi-inline-editor"
110
- }, buttons, /*#__PURE__*/React.createElement(CustomButton, {
111
- key: "edit",
112
- label: "Edit",
113
- onClick: this._editLatex,
114
- value: latex || ''
115
- }));
116
- }
117
- }]);
118
- }(React.PureComponent);
119
- export default MathInlineEditor;
120
- import PropTypes from "prop-types";
121
- export { bpfrpt_proptype_MathInlineEditorValue };
@@ -1,100 +0,0 @@
1
- // @flow
2
-
3
- import { CustomButton, createPopUp } from '@modusoperandi/licit-ui-commands';
4
- import CustomEditorView from './CustomEditorView.js';
5
- import MathEditor from './MathEditor.js';
6
- import * as React from 'react';
7
-
8
- const MathAlignValues = {
9
- NONE: {
10
- value: null,
11
- text: 'Inline',
12
- },
13
- CENTER: {
14
- value: 'center',
15
- text: 'Break text',
16
- },
17
- };
18
-
19
- export type MathInlineEditorValue = {
20
- align: ?string,
21
- latex: string,
22
- };
23
-
24
- class MathInlineEditor extends React.PureComponent<any, any> {
25
- props: {
26
- onEditEnd: () => void,
27
- onEditStart: () => void,
28
- onSelect: (val: any) => void,
29
- value: ?MathInlineEditorValue,
30
- editorView: ?CustomEditorView,
31
- };
32
-
33
- _popUp = null;
34
-
35
- componentWillUnmount(): void {
36
- this._popUp?.close();
37
- }
38
-
39
- render(): React.Element<any> {
40
- const { align, latex } = this.props.value || {};
41
- const onClick = this._onClick;
42
- const buttons = Object.keys(MathAlignValues).map((key) => {
43
- const { value, text } = MathAlignValues[key];
44
- return (
45
- <CustomButton
46
- active={align === value}
47
- key={key}
48
- label={text}
49
- onClick={onClick}
50
- value={value}
51
- />
52
- );
53
- });
54
-
55
- return (
56
- <div className="czi-inline-editor">
57
- {buttons}
58
- <CustomButton
59
- key="edit"
60
- label="Edit"
61
- onClick={this._editLatex}
62
- value={latex || ''}
63
- />
64
- </div>
65
- );
66
- }
67
-
68
- _onClick = (align: ?string): void => {
69
- const value = this.props.value || {};
70
- this.props.onSelect({ ...value, align });
71
- };
72
-
73
- _editLatex = (latex: string): void => {
74
- if (this._popUp) {
75
- return;
76
- }
77
- const { editorView, value } = this.props;
78
- const props = {
79
- runtime: editorView ? editorView.runtime : null,
80
- initialValue: (value?.latex) || '',
81
- };
82
- this._popUp = createPopUp(MathEditor, props, {
83
- autoDismiss: false,
84
- modal: true,
85
- onClose: (latex) => {
86
- if (this._popUp) {
87
- this._popUp = null;
88
- if (latex !== undefined) {
89
- const value = this.props.value || {};
90
- this.props.onSelect({ ...value, latex });
91
- }
92
- this.props.onEditEnd();
93
- }
94
- },
95
- });
96
- this.props.onEditStart();
97
- };
98
- }
99
-
100
- export default MathInlineEditor;
@@ -1,215 +0,0 @@
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 _superPropGet(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
3
- function _get() { return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { var p = _superPropBase(e, t); if (p) { var n = Object.getOwnPropertyDescriptor(p, t); return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; } }, _get.apply(null, arguments); }
4
- function _superPropBase(t, o) { for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));); return t; }
5
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
8
- 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); } }
9
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
10
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
11
- 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); }
12
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
13
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
14
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
15
- 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); }
16
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
17
- 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; }
18
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
19
- 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); }
20
- import CustomNodeView from './CustomNodeView.js';
21
- import MathInlineEditor from './MathInlineEditor.js';
22
- import * as React from 'react';
23
- import { createPopUp, atAnchorBottomCenter } from '@modusoperandi/licit-ui-commands';
24
- import cx from 'classnames';
25
- import renderLaTeXAsHTML from './renderLaTeXAsHTML.js';
26
- import uuid from './uuid.js';
27
- import { Decoration } from 'prosemirror-view';
28
- import { FRAMESET_BODY_CLASSNAME } from './EditorFrameset.js';
29
- import { Node } from 'prosemirror-model';
30
- import { NodeSelection } from 'prosemirror-state';
31
- var EMPTY_SRC = 'data:image/gif;base64,' + 'R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
32
- var MathViewBody = /*#__PURE__*/function (_React$PureComponent) {
33
- function MathViewBody() {
34
- var _this;
35
- _classCallCheck(this, MathViewBody);
36
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
37
- args[_key] = arguments[_key];
38
- }
39
- _this = _callSuper(this, MathViewBody, [].concat(args));
40
- _defineProperty(_this, "props", void 0);
41
- _defineProperty(_this, "state", {
42
- isEditing: false
43
- });
44
- _defineProperty(_this, "_inlineEditor", null);
45
- _defineProperty(_this, "_id", uuid());
46
- _defineProperty(_this, "_mounted", false);
47
- _defineProperty(_this, "_onEditStart", function () {
48
- _this.setState({
49
- isEditing: true
50
- });
51
- });
52
- _defineProperty(_this, "_onEditEnd", function () {
53
- _this.setState({
54
- isEditing: false
55
- });
56
- });
57
- _defineProperty(_this, "_onChange", function (value) {
58
- if (!_this._mounted) {
59
- return;
60
- }
61
- var align = value ? value.align : null;
62
- var latex = value ? value.latex : null;
63
- var _this$props = _this.props,
64
- getPos = _this$props.getPos,
65
- node = _this$props.node,
66
- editorView = _this$props.editorView;
67
- var pos = getPos();
68
- var attrs = _objectSpread(_objectSpread({}, node.attrs), {}, {
69
- latex: latex,
70
- align: align
71
- });
72
- var tr = editorView.state.tr;
73
- var selection = editorView.state.selection;
74
- tr = tr.setNodeMarkup(pos, null, attrs);
75
- // [FS] IRAD-1005 2020-07-23
76
- // Upgrade outdated packages.
77
- // reset selection to original using the latest doc.
78
- var origSelection = NodeSelection.create(tr.doc, selection.from);
79
- tr = tr.setSelection(origSelection);
80
- editorView.dispatch(tr);
81
- });
82
- return _this;
83
- }
84
- _inherits(MathViewBody, _React$PureComponent);
85
- return _createClass(MathViewBody, [{
86
- key: "componentDidMount",
87
- value: function componentDidMount() {
88
- this._mounted = true;
89
- this._renderInlineEditor();
90
- }
91
- }, {
92
- key: "componentWillUnmount",
93
- value: function componentWillUnmount() {
94
- this._mounted = false;
95
- }
96
- }, {
97
- key: "componentDidUpdate",
98
- value: function componentDidUpdate(prevProps) {
99
- this._renderInlineEditor();
100
- }
101
- }, {
102
- key: "render",
103
- value: function render() {
104
- // TODO: Resolve `readOnly`;
105
- var readOnly = false;
106
- var _this$props2 = this.props,
107
- node = _this$props2.node,
108
- selected = _this$props2.selected,
109
- focused = _this$props2.focused;
110
- var attrs = node.attrs;
111
- var latex = attrs.latex;
112
- var isEditing = this.state.isEditing;
113
- var active = (focused || isEditing) && !readOnly;
114
- var className = cx('czi-math-view-body', {
115
- active: active,
116
- selected: selected
117
- });
118
- var html = renderLaTeXAsHTML(latex);
119
- return /*#__PURE__*/React.createElement("span", {
120
- className: className,
121
- "data-active": active ? 'true' : null,
122
- "data-latex": latex || '',
123
- id: this._id,
124
- title: latex
125
- }, /*#__PURE__*/React.createElement("img", {
126
- alt: latex,
127
- className: "czi-math-view-body-img",
128
- src: EMPTY_SRC,
129
- title: latex
130
- }), /*#__PURE__*/React.createElement("span", {
131
- className: "czi-math-view-body-content",
132
- dangerouslySetInnerHTML: {
133
- __html: html
134
- }
135
- }));
136
- }
137
- }, {
138
- key: "_renderInlineEditor",
139
- value: function _renderInlineEditor() {
140
- var _this2 = this;
141
- var el = document.getElementById(this._id);
142
- if (!el || el.getAttribute('data-active') !== 'true') {
143
- var _this$_inlineEditor;
144
- (_this$_inlineEditor = this._inlineEditor) === null || _this$_inlineEditor === void 0 || _this$_inlineEditor.close();
145
- return;
146
- }
147
- var node = this.props.node;
148
- var editorProps = {
149
- value: node.attrs,
150
- onSelect: this._onChange,
151
- onEditStart: this._onEditStart,
152
- onEditEnd: this._onEditEnd
153
- };
154
- if (this._inlineEditor) {
155
- this._inlineEditor.update(editorProps);
156
- } else {
157
- this._inlineEditor = createPopUp(MathInlineEditor, editorProps, {
158
- anchor: el,
159
- autoDismiss: false,
160
- container: el.closest(".".concat(FRAMESET_BODY_CLASSNAME)),
161
- position: atAnchorBottomCenter,
162
- onClose: function onClose() {
163
- _this2._inlineEditor = null;
164
- }
165
- });
166
- }
167
- }
168
- }]);
169
- }(React.PureComponent);
170
- var MathNodeView = /*#__PURE__*/function (_CustomNodeView) {
171
- function MathNodeView() {
172
- _classCallCheck(this, MathNodeView);
173
- return _callSuper(this, MathNodeView, arguments);
174
- }
175
- _inherits(MathNodeView, _CustomNodeView);
176
- return _createClass(MathNodeView, [{
177
- key: "createDOMElement",
178
- value:
179
- // @override
180
- function createDOMElement() {
181
- var el = document.createElement('span');
182
- el.className = 'czi-math-view';
183
- this._updateDOM(el);
184
- return el;
185
- }
186
-
187
- // @override
188
- }, {
189
- key: "update",
190
- value: function update(node, decorations) {
191
- _superPropGet(MathNodeView, "update", this, 3)([node, decorations]);
192
- this._updateDOM(this.dom);
193
- return true;
194
- }
195
-
196
- // @override
197
- }, {
198
- key: "renderReactComponent",
199
- value: function renderReactComponent() {
200
- return /*#__PURE__*/React.createElement(MathViewBody, this.props);
201
- }
202
- }, {
203
- key: "_updateDOM",
204
- value: function _updateDOM(el) {
205
- var align = this.props.node.attrs.align;
206
- var className = 'czi-math-view';
207
- if (align) {
208
- className += ' align-' + align;
209
- }
210
- el.className = className;
211
- }
212
- }]);
213
- }(CustomNodeView);
214
- export default MathNodeView;
215
- import { bpfrpt_proptype_NodeViewProps } from "./CustomNodeView.js";
@@ -1,175 +0,0 @@
1
- // @flow
2
-
3
- import CustomNodeView from './CustomNodeView.js';
4
- import MathInlineEditor from './MathInlineEditor.js';
5
- import * as React from 'react';
6
- import {
7
- createPopUp,
8
- atAnchorBottomCenter,
9
- } from '@modusoperandi/licit-ui-commands';
10
- import cx from 'classnames';
11
- import renderLaTeXAsHTML from './renderLaTeXAsHTML.js';
12
- import uuid from './uuid.js';
13
- import { Decoration } from 'prosemirror-view';
14
- import { FRAMESET_BODY_CLASSNAME } from './EditorFrameset.js';
15
- import { Node } from 'prosemirror-model';
16
- import { NodeSelection } from 'prosemirror-state';
17
-
18
- import type { NodeViewProps } from './CustomNodeView.js';
19
- const EMPTY_SRC =
20
- 'data:image/gif;base64,' +
21
- 'R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
22
-
23
- class MathViewBody extends React.PureComponent<any, any> {
24
- props: NodeViewProps;
25
-
26
- state = {
27
- isEditing: false,
28
- };
29
-
30
- _inlineEditor = null;
31
- _id = uuid();
32
- _mounted = false;
33
-
34
- componentDidMount(): void {
35
- this._mounted = true;
36
- this._renderInlineEditor();
37
- }
38
-
39
- componentWillUnmount(): void {
40
- this._mounted = false;
41
- }
42
-
43
- componentDidUpdate(prevProps: NodeViewProps): void {
44
- this._renderInlineEditor();
45
- }
46
-
47
- render(): React.Element<any> {
48
- // TODO: Resolve `readOnly`;
49
- const readOnly = false;
50
- const { node, selected, focused } = this.props;
51
- const { attrs } = node;
52
- const { latex } = attrs;
53
- const { isEditing } = this.state;
54
-
55
- const active = (focused || isEditing) && !readOnly;
56
- const className = cx('czi-math-view-body', { active, selected });
57
- const html = renderLaTeXAsHTML(latex);
58
- return (
59
- <span
60
- className={className}
61
- data-active={active ? 'true' : null}
62
- data-latex={latex || ''}
63
- id={this._id}
64
- title={latex}
65
- >
66
- <img
67
- alt={latex}
68
- className="czi-math-view-body-img"
69
- src={EMPTY_SRC}
70
- title={latex}
71
- />
72
- <span
73
- className="czi-math-view-body-content"
74
- dangerouslySetInnerHTML={{ __html: html }}
75
- />
76
- </span>
77
- );
78
- }
79
-
80
- _renderInlineEditor(): void {
81
- const el = document.getElementById(this._id);
82
- if (!el || el.getAttribute('data-active') !== 'true') {
83
- this._inlineEditor?.close();
84
- return;
85
- }
86
- const { node } = this.props;
87
- const editorProps = {
88
- value: node.attrs,
89
- onSelect: this._onChange,
90
- onEditStart: this._onEditStart,
91
- onEditEnd: this._onEditEnd,
92
- };
93
- if (this._inlineEditor) {
94
- this._inlineEditor.update(editorProps);
95
- } else {
96
- this._inlineEditor = createPopUp(MathInlineEditor, editorProps, {
97
- anchor: el,
98
- autoDismiss: false,
99
- container: el.closest(`.${FRAMESET_BODY_CLASSNAME}`),
100
- position: atAnchorBottomCenter,
101
- onClose: () => {
102
- this._inlineEditor = null;
103
- },
104
- });
105
- }
106
- }
107
-
108
- _onEditStart = (): void => {
109
- this.setState({ isEditing: true });
110
- };
111
-
112
- _onEditEnd = (): void => {
113
- this.setState({ isEditing: false });
114
- };
115
-
116
- _onChange = (value: ?{ align: ?string, latex: string }): void => {
117
- if (!this._mounted) {
118
- return;
119
- }
120
-
121
- const align = value ? value.align : null;
122
- const latex = value ? value.latex : null;
123
-
124
- const { getPos, node, editorView } = this.props;
125
- const pos = getPos();
126
- const attrs = {
127
- ...node.attrs,
128
- latex,
129
- align,
130
- };
131
-
132
- let tr = editorView.state.tr;
133
- const { selection } = editorView.state;
134
- tr = tr.setNodeMarkup(pos, null, attrs);
135
- // [FS] IRAD-1005 2020-07-23
136
- // Upgrade outdated packages.
137
- // reset selection to original using the latest doc.
138
- const origSelection = NodeSelection.create(tr.doc, selection.from);
139
- tr = tr.setSelection(origSelection);
140
- editorView.dispatch(tr);
141
- };
142
- }
143
-
144
- class MathNodeView extends CustomNodeView {
145
- // @override
146
- createDOMElement(): HTMLElement {
147
- const el = document.createElement('span');
148
- el.className = 'czi-math-view';
149
- this._updateDOM(el);
150
- return el;
151
- }
152
-
153
- // @override
154
- update(node: Node, decorations: Array<Decoration>): boolean {
155
- super.update(node, decorations);
156
- this._updateDOM(this.dom);
157
- return true;
158
- }
159
-
160
- // @override
161
- renderReactComponent(): React.Element<any> {
162
- return <MathViewBody {...this.props} />;
163
- }
164
-
165
- _updateDOM(el: HTMLElement): void {
166
- const { align } = this.props.node.attrs;
167
- let className = 'czi-math-view';
168
- if (align) {
169
- className += ' align-' + align;
170
- }
171
- el.className = className;
172
- }
173
- }
174
-
175
- export default MathNodeView;