Skip to content

Commit a5c72c6

Browse files
authored
Merge pull request #2685 from pie-framework/feat/PD-363-poc
fix(select-text): remove extended-text-entry dependencies and fix clear tokens method PD-363
2 parents d97e157 + 1c67096 commit a5c72c6

2 files changed

Lines changed: 58 additions & 30 deletions

File tree

packages/select-text/configure/src/design.jsx

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import Info from '@material-ui/icons/Info';
1111
import debug from 'debug';
1212
import { EditableHtml } from '@pie-lib/pie-toolbox/editable-html';
1313
import Tooltip from '@material-ui/core/Tooltip';
14-
import { generateValidationMessage } from './utils';
15-
import {
16-
clearSelection,
17-
getDOMNodes,
18-
getLabelElement,
19-
getRangeDetails,
20-
isSideLabel,
21-
wrapRange,
22-
} from '@pie-element/extended-text-entry/src/annotation/annotation-utils';
14+
import { clearSelection, generateValidationMessage } from './utils';
15+
// import {
16+
// clearSelection,
17+
// getDOMNodes,
18+
// getLabelElement,
19+
// getRangeDetails,
20+
// isSideLabel,
21+
// wrapRange,
22+
// } from '@pie-element/extended-text-entry/src/annotation/annotation-utils';
2323
import classNames from 'classnames';
2424

2525
import Switch from '@material-ui/core/Switch';
@@ -184,23 +184,23 @@ export class Design extends React.Component {
184184
return annotation;
185185
};
186186

187-
addAnnotation = (type) => {
188-
const { annotations, onChange } = this.props;
189-
const annotation = this.createNewAnnotation('', type);
190-
const labelElem = getLabelElement(annotation.id);
191-
192-
annotations.push(annotation);
193-
194-
this.setState({
195-
openedMenu: false,
196-
openedEditor: true,
197-
annotationIndex: annotations.length - 1,
198-
annotation,
199-
labelElem,
200-
});
201-
202-
onChange(annotations);
203-
};
187+
// addAnnotation = (type) => {
188+
// const { annotations, onChange } = this.props;
189+
// const annotation = this.createNewAnnotation('', type);
190+
// const labelElem = getLabelElement(annotation.id);
191+
//
192+
// annotations.push(annotation);
193+
//
194+
// this.setState({
195+
// openedMenu: false,
196+
// openedEditor: true,
197+
// annotationIndex: annotations.length - 1,
198+
// annotation,
199+
// labelElem,
200+
// });
201+
//
202+
// onChange(annotations);
203+
// };
204204

205205
// new functionalities
206206

@@ -357,9 +357,16 @@ export class Design extends React.Component {
357357
};
358358

359359
clearTokens = () => {
360-
const { text } = this.state;
360+
const { model } = this.props;
361+
362+
const container = document.createElement('div');
363+
container.innerHTML = model.text;
364+
365+
// Remove all children and add new content
366+
this.textRef.innerHTML = '';
367+
this.textRef.appendChild(container);
361368

362-
this.setState({ tokenizedText: text });
369+
this.setState({ tokenizedText: model.text });
363370
};
364371

365372
selectWords = () => {

packages/select-text/configure/src/utils.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
var createElementFromHTML = function createElementFromHTML() {
32
var htmlString = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
43
var div = document.createElement('div');
@@ -28,7 +27,7 @@ var prepareText = function prepareText(text) {
2827
var txtDom = createElementFromHTML(text);
2928

3029
var div = document.createElement('div');
31-
div.innerHTML = '<div separator=\'true\'>'.concat(txtDom.innerHTML, '</div>');
30+
div.innerHTML = "<div separator='true'>".concat(txtDom.innerHTML, '</div>');
3231
txtDom = div;
3332

3433
var allDomElements = Array.from(txtDom.querySelectorAll('*'));
@@ -111,3 +110,25 @@ export const generateValidationMessage = (config) => {
111110

112111
return message;
113112
};
113+
114+
// also used in extended-text-entry
115+
export const clearSelection = () => {
116+
if (document.getSelection) {
117+
// for all new browsers (IE9+, Chrome, Firefox)
118+
document.getSelection().removeAllRanges();
119+
document.getSelection().addRange(document.createRange());
120+
} else if (window.getSelection) {
121+
// equals with the document.getSelection (MSDN info)
122+
if (window.getSelection().removeAllRanges) {
123+
// for all new browsers (IE9+, Chrome, Firefox)
124+
window.getSelection().removeAllRanges();
125+
window.getSelection().addRange(document.createRange());
126+
} else if (window.getSelection().empty) {
127+
// Chrome supports this as well
128+
window.getSelection().empty();
129+
}
130+
} else if (document.selection) {
131+
// IE8-
132+
document.selection.empty();
133+
}
134+
};

0 commit comments

Comments
 (0)