@pie-lib/editable-html 7.17.4-next.452 → 7.17.4-next.454
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/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.jsx +2 -2
package/lib/index.js
CHANGED
|
@@ -136,7 +136,9 @@ var EditableHtml = /*#__PURE__*/function (_React$Component) {
|
|
|
136
136
|
c.focus();
|
|
137
137
|
|
|
138
138
|
if (position === 'end' && lastText) {
|
|
139
|
-
|
|
139
|
+
var _lastText$text, _lastText$text2;
|
|
140
|
+
|
|
141
|
+
c.moveFocusTo(lastText.key, (_lastText$text = lastText.text) === null || _lastText$text === void 0 ? void 0 : _lastText$text.length).moveAnchorTo(lastText.key, (_lastText$text2 = lastText.text) === null || _lastText$text2 === void 0 ? void 0 : _lastText$text2.length);
|
|
140
142
|
}
|
|
141
143
|
|
|
142
144
|
if (position === 'beginning' && lastText) {
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["log","debug","reduceMultipleBrs","markup","replace","e","console","EditableHtml","props","value","done","html","valueToHtml","htmlParsed","parseDegrees","onChange","onDone","position","node","editorRef","change","c","lastText","document","getNextText","key","getLastText","editorDOM","querySelector","activeElement","blur","focus","moveFocusTo","text","length","moveAnchorTo","onEditingDone","v","htmlToValue","state","allowValidation","current","equals","setState","toolbarOpts","error","ref","rootRef","React","Component","PropTypes","func","isRequired","string","bool"],"sources":["../src/index.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport Editor, { DEFAULT_PLUGINS, ALL_PLUGINS } from './editor';\nimport { htmlToValue, valueToHtml } from './serialization';\nimport { parseDegrees } from './parse-html';\nimport debug from 'debug';\n\nconst log = debug('@pie-lib:editable-html');\n/**\n * Export lower level Editor and serialization functions.\n */\nexport { htmlToValue, valueToHtml, Editor, DEFAULT_PLUGINS, ALL_PLUGINS };\n\n/**\n * Wrapper around the editor that exposes a `markup` and `onChange(markup:string)` api.\n * Because of the mismatch between the markup and the `Value` we need to convert the incoming markup to a value and\n * compare it. TODO: This is an interim fix, we'll need to strip back `Editor` and look how best to maintain the\n * `markup` api whilst avoiding the serialization mismatch. We should be making better use of schemas w/ normalize.\n */\n\nconst reduceMultipleBrs = markup => {\n try {\n return markup.replace(/(<br\\s*\\/?>){3,}/gi, '<br>');\n } catch (e) {\n console.log(\"Couldn't remove <br/> tags: \", e);\n }\n\n return markup;\n};\n\nexport default class EditableHtml extends React.Component {\n static propTypes = {\n onChange: PropTypes.func.isRequired,\n onDone: PropTypes.func,\n markup: PropTypes.string.isRequired,\n allowValidation: PropTypes.bool\n };\n\n static defaultProps = {\n onDone: () => {},\n allowValidation: false\n };\n\n constructor(props) {\n super(props);\n const v = htmlToValue(props.markup);\n this.state = {\n value: v\n };\n }\n\n // eslint-disable-next-line react/no-deprecated\n componentWillReceiveProps(props) {\n if (!props.allowValidation && props.markup === this.props.markup) {\n return;\n }\n\n const v = htmlToValue(reduceMultipleBrs(props.markup));\n const current = htmlToValue(reduceMultipleBrs(this.props.markup));\n\n if (v.equals && !v.equals(current)) {\n this.setState({ value: v });\n }\n }\n\n onChange = (value, done) => {\n const html = valueToHtml(value);\n const htmlParsed = parseDegrees(html);\n\n log('value as html: ', html);\n\n if (html !== this.props.markup) {\n this.props.onChange(htmlParsed);\n }\n\n if (done) {\n this.props.onDone(htmlParsed);\n }\n };\n\n focus = (position, node) => {\n if (this.editorRef) {\n this.editorRef.change(c => {\n const lastText = node\n ? c.value.document.getNextText(node.key)\n : c.value.document.getLastText();\n const editorDOM = document.querySelector(\n `[data-key=\"${this.editorRef.value.document.key}\"]`\n );\n\n if (editorDOM !== document.activeElement) {\n document.activeElement.blur();\n }\n\n c.focus();\n\n if (position === 'end' && lastText) {\n c.moveFocusTo(lastText.key, lastText.text
|
|
1
|
+
{"version":3,"file":"index.js","names":["log","debug","reduceMultipleBrs","markup","replace","e","console","EditableHtml","props","value","done","html","valueToHtml","htmlParsed","parseDegrees","onChange","onDone","position","node","editorRef","change","c","lastText","document","getNextText","key","getLastText","editorDOM","querySelector","activeElement","blur","focus","moveFocusTo","text","length","moveAnchorTo","onEditingDone","v","htmlToValue","state","allowValidation","current","equals","setState","toolbarOpts","error","ref","rootRef","React","Component","PropTypes","func","isRequired","string","bool"],"sources":["../src/index.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport Editor, { DEFAULT_PLUGINS, ALL_PLUGINS } from './editor';\nimport { htmlToValue, valueToHtml } from './serialization';\nimport { parseDegrees } from './parse-html';\nimport debug from 'debug';\n\nconst log = debug('@pie-lib:editable-html');\n/**\n * Export lower level Editor and serialization functions.\n */\nexport { htmlToValue, valueToHtml, Editor, DEFAULT_PLUGINS, ALL_PLUGINS };\n\n/**\n * Wrapper around the editor that exposes a `markup` and `onChange(markup:string)` api.\n * Because of the mismatch between the markup and the `Value` we need to convert the incoming markup to a value and\n * compare it. TODO: This is an interim fix, we'll need to strip back `Editor` and look how best to maintain the\n * `markup` api whilst avoiding the serialization mismatch. We should be making better use of schemas w/ normalize.\n */\n\nconst reduceMultipleBrs = markup => {\n try {\n return markup.replace(/(<br\\s*\\/?>){3,}/gi, '<br>');\n } catch (e) {\n console.log(\"Couldn't remove <br/> tags: \", e);\n }\n\n return markup;\n};\n\nexport default class EditableHtml extends React.Component {\n static propTypes = {\n onChange: PropTypes.func.isRequired,\n onDone: PropTypes.func,\n markup: PropTypes.string.isRequired,\n allowValidation: PropTypes.bool\n };\n\n static defaultProps = {\n onDone: () => {},\n allowValidation: false\n };\n\n constructor(props) {\n super(props);\n const v = htmlToValue(props.markup);\n this.state = {\n value: v\n };\n }\n\n // eslint-disable-next-line react/no-deprecated\n componentWillReceiveProps(props) {\n if (!props.allowValidation && props.markup === this.props.markup) {\n return;\n }\n\n const v = htmlToValue(reduceMultipleBrs(props.markup));\n const current = htmlToValue(reduceMultipleBrs(this.props.markup));\n\n if (v.equals && !v.equals(current)) {\n this.setState({ value: v });\n }\n }\n\n onChange = (value, done) => {\n const html = valueToHtml(value);\n const htmlParsed = parseDegrees(html);\n\n log('value as html: ', html);\n\n if (html !== this.props.markup) {\n this.props.onChange(htmlParsed);\n }\n\n if (done) {\n this.props.onDone(htmlParsed);\n }\n };\n\n focus = (position, node) => {\n if (this.editorRef) {\n this.editorRef.change(c => {\n const lastText = node\n ? c.value.document.getNextText(node.key)\n : c.value.document.getLastText();\n const editorDOM = document.querySelector(\n `[data-key=\"${this.editorRef.value.document.key}\"]`\n );\n\n if (editorDOM !== document.activeElement) {\n document.activeElement.blur();\n }\n\n c.focus();\n\n if (position === 'end' && lastText) {\n c.moveFocusTo(lastText.key, lastText.text?.length).moveAnchorTo(\n lastText.key,\n lastText.text?.length\n );\n }\n\n if (position === 'beginning' && lastText) {\n c.moveFocusTo(lastText.key, 0).moveAnchorTo(lastText.key, 0);\n }\n });\n }\n };\n\n finishEditing = () => {\n if (this.editorRef) {\n this.editorRef.props.onEditingDone();\n }\n };\n\n render() {\n const { value } = this.state;\n const { toolbarOpts, error } = this.props;\n\n if (toolbarOpts) {\n toolbarOpts.error = error;\n }\n\n const props = {\n ...this.props,\n markup: null,\n value,\n onChange: this.onChange,\n focus: this.focus\n };\n\n return (\n <Editor\n onRef={ref => {\n if (ref) {\n this.rootRef = ref;\n }\n }}\n editorRef={ref => ref && (this.editorRef = ref)}\n {...props}\n />\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;AAEA,IAAMA,GAAG,GAAG,IAAAC,iBAAA,EAAM,wBAAN,CAAZ;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AAEA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAAAC,MAAM,EAAI;EAClC,IAAI;IACF,OAAOA,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+f3e7da78",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"@material-ui/styles": "^3.0.0-alpha.10",
|
|
13
13
|
"@pie-lib/drag": "^1.1.52",
|
|
14
14
|
"@pie-lib/math-rendering": "^2.4.2",
|
|
15
|
-
"@pie-lib/math-toolbar": "^1.
|
|
15
|
+
"@pie-lib/math-toolbar": "^1.9.3",
|
|
16
16
|
"@pie-lib/render-ui": "^4.12.8",
|
|
17
17
|
"change-case": "^3.0.2",
|
|
18
18
|
"classnames": "^2.2.6",
|
|
@@ -47,6 +47,6 @@
|
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "f3e7da784732c9bf23c4a806037d6da91cfdcc99",
|
|
51
51
|
"scripts": {}
|
|
52
52
|
}
|
package/src/index.jsx
CHANGED
|
@@ -95,9 +95,9 @@ export default class EditableHtml extends React.Component {
|
|
|
95
95
|
c.focus();
|
|
96
96
|
|
|
97
97
|
if (position === 'end' && lastText) {
|
|
98
|
-
c.moveFocusTo(lastText.key, lastText.text
|
|
98
|
+
c.moveFocusTo(lastText.key, lastText.text?.length).moveAnchorTo(
|
|
99
99
|
lastText.key,
|
|
100
|
-
lastText.text
|
|
100
|
+
lastText.text?.length
|
|
101
101
|
);
|
|
102
102
|
}
|
|
103
103
|
|