@pie-lib/text-select 1.8.5 → 1.8.6-next.86
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/CHANGELOG.json +15 -0
- package/CHANGELOG.md +11 -79
- package/lib/token-select/index.js +2 -3
- package/lib/token-select/index.js.map +1 -1
- package/lib/tokenizer/selection-utils.js +1 -1
- package/lib/tokenizer/selection-utils.js.map +1 -1
- package/lib/tokenizer/token-text.js +15 -4
- package/lib/tokenizer/token-text.js.map +1 -1
- package/package.json +3 -3
- package/src/token-select/index.jsx +1 -2
- package/src/tokenizer/selection-utils.js +1 -1
- package/src/tokenizer/token-text.jsx +34 -6
package/CHANGELOG.json
CHANGED
|
@@ -613,5 +613,20 @@
|
|
|
613
613
|
"committerDate": "2021-08-09 09:58:13 +0300",
|
|
614
614
|
"isTagged": true,
|
|
615
615
|
"tag": "@pie-lib/text-select@1.8.5"
|
|
616
|
+
},
|
|
617
|
+
{
|
|
618
|
+
"type": "fix",
|
|
619
|
+
"scope": "select-text",
|
|
620
|
+
"subject": "made sure the new line characters are taken into consideration for offsets [PD-1145]",
|
|
621
|
+
"merge": null,
|
|
622
|
+
"header": "fix(select-text): made sure the new line characters are taken into consideration for offsets [PD-1145]",
|
|
623
|
+
"body": null,
|
|
624
|
+
"footer": null,
|
|
625
|
+
"notes": [],
|
|
626
|
+
"hash": "a7bb44a833e2931177e122010aa160a924982530",
|
|
627
|
+
"gitTags": " (origin/feat/PD-1145-new-line-offset-handling)",
|
|
628
|
+
"committerDate": "2021-09-24 13:15:39 +0300",
|
|
629
|
+
"isTagged": true,
|
|
630
|
+
"tag": "@pie-lib/text-select@1.8.8"
|
|
616
631
|
}
|
|
617
632
|
]
|
package/CHANGELOG.md
CHANGED
|
@@ -24,152 +24,84 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
24
24
|
|
|
25
25
|
## [1.8.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.8.2...@pie-lib/text-select@1.8.3) (2021-07-23)
|
|
26
26
|
|
|
27
|
-
|
|
28
27
|
### Bug Fixes
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
- **text-select:** Fixed white space collapse PD-477 ([1f9481f](https://github.com/pie-framework/pie-lib/commit/1f9481f))
|
|
35
30
|
|
|
36
31
|
## [1.8.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.8.0...@pie-lib/text-select@1.8.2) (2021-06-25)
|
|
37
32
|
|
|
38
33
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
39
34
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
35
|
# [1.8.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.7.13...@pie-lib/text-select@1.8.0) (2021-06-25)
|
|
45
36
|
|
|
46
|
-
|
|
47
37
|
### Bug Fixes
|
|
48
38
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
39
|
+
- **text-select:** fix incorrect indenting PD-1038 ([4d56509](https://github.com/pie-framework/pie-lib/commit/4d56509))
|
|
40
|
+
- **text-select:** select text view mode should use black for text color PD-1154 ([0db5b1e](https://github.com/pie-framework/pie-lib/commit/0db5b1e))
|
|
52
41
|
|
|
53
42
|
### Features
|
|
54
43
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
44
|
+
- **text-select:** when select-text item permits only one selection, change behavior of gather PD-958 ([c181314](https://github.com/pie-framework/pie-lib/commit/c181314))
|
|
60
45
|
|
|
61
46
|
## [1.7.13](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.7.12...@pie-lib/text-select@1.7.13) (2021-03-01)
|
|
62
47
|
|
|
63
48
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
64
49
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
50
|
## [1.7.12](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.7.11...@pie-lib/text-select@1.7.12) (2021-03-01)
|
|
70
51
|
|
|
71
|
-
|
|
72
52
|
### Bug Fixes
|
|
73
53
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
54
|
+
- **text-select:** fix layout for legacy items with line number ([d50865e](https://github.com/pie-framework/pie-lib/commit/d50865e))
|
|
55
|
+
- **text-select:** fix padding for tokens in order to fix PD-860 ([eacb81c](https://github.com/pie-framework/pie-lib/commit/eacb81c))
|
|
56
|
+
- **text-select:** show tokens if they are selected in view mode to fix PD-464 ([7821536](https://github.com/pie-framework/pie-lib/commit/7821536))
|
|
81
57
|
|
|
82
58
|
## [1.7.11](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.7.10...@pie-lib/text-select@1.7.11) (2021-02-15)
|
|
83
59
|
|
|
84
60
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
85
61
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
62
|
## [1.7.10](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.7.8...@pie-lib/text-select@1.7.10) (2021-02-15)
|
|
91
63
|
|
|
92
64
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
93
65
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
66
|
## [1.7.8](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.7.7...@pie-lib/text-select@1.7.8) (2021-02-15)
|
|
99
67
|
|
|
100
|
-
|
|
101
68
|
### Bug Fixes
|
|
102
69
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
70
|
+
- **text-select:** fix space between lines ([5633537](https://github.com/pie-framework/pie-lib/commit/5633537))
|
|
108
71
|
|
|
109
72
|
## [1.7.7](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.7.6...@pie-lib/text-select@1.7.7) (2021-02-01)
|
|
110
73
|
|
|
111
74
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
112
75
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
76
|
## [1.7.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.7.5...@pie-lib/text-select@1.7.6) (2021-01-28)
|
|
118
77
|
|
|
119
78
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
120
79
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
80
|
## [1.7.5](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.7.4...@pie-lib/text-select@1.7.5) (2021-01-28)
|
|
126
81
|
|
|
127
82
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
128
83
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
84
|
## [1.7.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.7.3...@pie-lib/text-select@1.7.4) (2021-01-25)
|
|
134
85
|
|
|
135
|
-
|
|
136
86
|
### Bug Fixes
|
|
137
87
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
88
|
+
- **text-select:** fix token rendering issue - PD-642 ([89f3b70](https://github.com/pie-framework/pie-lib/commit/89f3b70))
|
|
143
89
|
|
|
144
90
|
## [1.7.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.7.2...@pie-lib/text-select@1.7.3) (2021-01-11)
|
|
145
91
|
|
|
146
|
-
|
|
147
92
|
### Bug Fixes
|
|
148
93
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
94
|
+
- Added fix for style changes after selection of max tokens PD-646 ([30183a9](https://github.com/pie-framework/pie-lib/commit/30183a9))
|
|
154
95
|
|
|
155
96
|
## [1.7.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.7.1...@pie-lib/text-select@1.7.2) (2020-10-29)
|
|
156
97
|
|
|
157
98
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
158
99
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
100
|
## [1.7.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.7.0...@pie-lib/text-select@1.7.1) (2020-10-26)
|
|
164
101
|
|
|
165
|
-
|
|
166
102
|
### Bug Fixes
|
|
167
103
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
104
|
+
- **select-text:** fix text indent styling for tokens ([0d13170](https://github.com/pie-framework/pie-lib/commit/0d13170))
|
|
173
105
|
|
|
174
106
|
# [1.7.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.6.1...@pie-lib/text-select@1.7.0) (2020-10-26)
|
|
175
107
|
|
|
@@ -172,10 +172,9 @@ function (_React$Component) {
|
|
|
172
172
|
|
|
173
173
|
if (isLineBreak(t.text)) {
|
|
174
174
|
return finalAcc + '<br>';
|
|
175
|
-
}
|
|
176
|
-
|
|
175
|
+
}
|
|
177
176
|
|
|
178
|
-
if (!disabled || showCorrectAnswer || t.selected) {
|
|
177
|
+
if (selectable && !disabled || showCorrectAnswer || t.selected) {
|
|
179
178
|
return finalAcc + (0, _server.renderToString)(_react["default"].createElement(_token["default"], _extends({
|
|
180
179
|
key: index,
|
|
181
180
|
disabled: disabled,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/token-select/index.jsx"],"names":["log","TokenSelect","props","tokens","filter","t","selected","length","selectedCount","maxNoOfSelections","isFinite","event","target","tokensCloned","targetSpanWrapper","closest","Token","rootClassName","targetedTokenIndex","dataset","indexkey","correct","undefined","onChange","selectedToken","updatedTokens","map","token","selectable","update","splice","disabled","highlightChoices","isLineBreak","text","isNewParagraph","reducer","accumulator","index","canSelectMore","showCorrectAnswer","finalAcc","reduceResult","reduce","classes","classNameProp","className","tokenSelect","html","generateTokensInHtml","__html","toggleToken","React","Component","PropTypes","arrayOf","shape","TokenTypes","isRequired","string","object","func","bool","number","backgroundColor","whiteSpace"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,mCAAN,CAAZ;;IAEaC,W;;;;;;;;;;;;;;;;;;oEAiBK;AAAA,aAAM,MAAKC,KAAL,CAAWC,MAAX,CAAkBC,MAAlB,CAAyB,UAAAC,CAAC;AAAA,eAAIA,CAAC,CAACC,QAAN;AAAA,OAA1B,EAA0CC,MAAhD;AAAA,K;;oEAEA,UAAAC,aAAa,EAAI;AAAA,UACvBC,iBADuB,GACD,MAAKP,KADJ,CACvBO,iBADuB;;AAG/B,UAAIA,iBAAiB,KAAK,CAA1B,EAA6B;AAC3B,eAAO,IAAP;AACD;;AAEDT,MAAAA,GAAG,CAAC,qCAAD,EAAwCS,iBAAxC,EAA2D,iBAA3D,EAA8ED,aAA9E,CAAH;AACA,aACEC,iBAAiB,IAAI,CAArB,IAA2BC,QAAQ,CAACD,iBAAD,CAAR,IAA+BD,aAAa,GAAGC,iBAD5E;AAGD,K;;kEAUa,UAAAE,KAAK,EAAI;AAAA,UACbC,MADa,GACFD,KADE,CACbC,MADa;AAAA,UAEbT,MAFa,GAEF,MAAKD,KAFH,CAEbC,MAFa;AAGrB,UAAMU,YAAY,GAAG,uBAAMV,MAAN,CAArB;AACA,UAAMW,iBAAiB,GAAGF,MAAM,CAACG,OAAP,YAAmBC,kBAAMC,aAAzB,EAA1B;AACA,UAAMC,kBAAkB,GACtBJ,iBAAiB,IAAIA,iBAAiB,CAACK,OAAvC,IAAkDL,iBAAiB,CAACK,OAAlB,CAA0BC,QAD9E;AAEA,UAAMf,CA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EAAE6C,sBAAUS;AAPZ,C;;gBADR9D,W,kBAWW;AACpB+B,EAAAA,gBAAgB,EAAE,KADE;AAEpBvB,EAAAA,iBAAiB,EAAE,CAFC;AAGpBN,EAAAA,MAAM,EAAE;AAHY,C;;eAkIT,wBAAW;AAAA,SAAO;AAC/B4C,IAAAA,WAAW;AACTiB,MAAAA,eAAe,EAAE,MADR;AAETC,MAAAA,UAAU,EAAE;AAFH,OAGN,2BAHM;AAIT,aAAO;AACLA,QAAAA,UAAU,EAAE;AADP;AAJE;AADoB,GAAP;AAAA,CAAX,EASXhE,WATW,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport Token, { TokenTypes } from './token';\nimport { withStyles } from '@material-ui/core/styles';\nimport classNames from 'classnames';\nimport clone from 'lodash/clone';\nimport debug from 'debug';\nimport { noSelect } from '@pie-lib/style-utils';\nimport { renderToString } from 'react-dom/server';\nimport isEqual from 'lodash/isEqual';\n\nconst log = debug('@pie-lib:text-select:token-select');\n\nexport class TokenSelect extends React.Component {\n static propTypes = {\n tokens: PropTypes.arrayOf(PropTypes.shape(TokenTypes)).isRequired,\n className: PropTypes.string,\n classes: PropTypes.object.isRequired,\n onChange: PropTypes.func.isRequired,\n disabled: PropTypes.bool,\n highlightChoices: PropTypes.bool,\n maxNoOfSelections: PropTypes.number\n };\n\n static defaultProps = {\n highlightChoices: false,\n maxNoOfSelections: 0,\n tokens: []\n };\n\n selectedCount = () => this.props.tokens.filter(t => t.selected).length;\n\n canSelectMore = selectedCount => {\n const { maxNoOfSelections } = this.props;\n\n if (maxNoOfSelections === 1) {\n return true;\n }\n\n log('[canSelectMore] maxNoOfSelections: ', maxNoOfSelections, 'selectedCount: ', selectedCount);\n return (\n maxNoOfSelections <= 0 || (isFinite(maxNoOfSelections) && selectedCount < maxNoOfSelections)\n );\n };\n\n /**\n @function\n @param { object } event\n\n @description\n each token is wrapped into a span that has Token.rootClassName class and indexkey attribute (represents the index of the token)\n tokens are updated with the targeted token having the correct value set for 'selected' property\n */\n toggleToken = event => {\n const { target } = event;\n const { tokens } = this.props;\n const tokensCloned = clone(tokens);\n const targetSpanWrapper = target.closest(`.${Token.rootClassName}`);\n const targetedTokenIndex =\n targetSpanWrapper && targetSpanWrapper.dataset && targetSpanWrapper.dataset.indexkey;\n const t = targetedTokenIndex && tokensCloned[targetedTokenIndex];\n\n if (t && t.correct === undefined) {\n const { onChange, maxNoOfSelections } = this.props;\n const selected = !t.selected;\n\n if (maxNoOfSelections === 1 && this.selectedCount() === 1) {\n const selectedToken = (tokens || []).filter(t => t.selected);\n\n const updatedTokens = tokensCloned.map(token => {\n if (isEqual(token, selectedToken[0])) {\n return { ...token, selected: false };\n }\n\n return { ...token, selectable: true };\n });\n\n const update = { ...t, selected: !t.selected };\n\n updatedTokens.splice(targetedTokenIndex, 1, update);\n onChange(updatedTokens);\n } else {\n if (selected && maxNoOfSelections > 0 && this.selectedCount() >= maxNoOfSelections) {\n log('skip toggle max reached');\n return;\n }\n\n const update = { ...t, selected: !t.selected };\n\n tokensCloned.splice(targetedTokenIndex, 1, update);\n onChange(tokensCloned);\n }\n }\n };\n\n generateTokensInHtml = () => {\n const { tokens, disabled, highlightChoices } = this.props;\n const selectedCount = this.selectedCount();\n const isLineBreak = text => text === '\\n';\n const isNewParagraph = text => text === '\\n\\n';\n\n const reducer = (accumulator, t, index) => {\n const selectable = t.selected || (t.selectable && this.canSelectMore(selectedCount));\n const showCorrectAnswer = t.correct !== undefined && (t.selectable || t.selected);\n let finalAcc = accumulator;\n\n if (isNewParagraph(t.text)) {\n return finalAcc + '</p><p>';\n }\n\n if (isLineBreak(t.text)) {\n return finalAcc + '<br>';\n }\n\n //modified (selectable && !disabled) to !disabled to fix PD-646\n if (!disabled || showCorrectAnswer || t.selected) {\n return (\n finalAcc +\n renderToString(\n <Token\n key={index}\n disabled={disabled}\n index={index}\n {...t}\n selectable={selectable}\n highlight={highlightChoices}\n />\n )\n );\n } else {\n return accumulator + t.text;\n }\n };\n\n const reduceResult = (tokens || []).reduce(reducer, '<p>');\n\n return reduceResult + '</p>';\n };\n\n render() {\n const { classes, className: classNameProp } = this.props;\n const className = classNames(classes.tokenSelect, classNameProp);\n const html = this.generateTokensInHtml();\n\n return (\n <div\n className={className}\n dangerouslySetInnerHTML={{ __html: html }}\n onClick={this.toggleToken}\n />\n );\n }\n}\n\nexport default withStyles(() => ({\n tokenSelect: {\n backgroundColor: 'none',\n whiteSpace: 'pre',\n ...noSelect(),\n '& p': {\n whiteSpace: 'break-spaces'\n }\n }\n}))(TokenSelect);\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/token-select/index.jsx"],"names":["log","TokenSelect","props","tokens","filter","t","selected","length","selectedCount","maxNoOfSelections","isFinite","event","target","tokensCloned","targetSpanWrapper","closest","Token","rootClassName","targetedTokenIndex","dataset","indexkey","correct","undefined","onChange","selectedToken","updatedTokens","map","token","selectable","update","splice","disabled","highlightChoices","isLineBreak","text","isNewParagraph","reducer","accumulator","index","canSelectMore","showCorrectAnswer","finalAcc","reduceResult","reduce","classes","classNameProp","className","tokenSelect","html","generateTokensInHtml","__html","toggleToken","React","Component","PropTypes","arrayOf","shape","TokenTypes","isRequired","string","object","func","bool","number","backgroundColor","whiteSpace"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,mCAAN,CAAZ;;IAEaC,W;;;;;;;;;;;;;;;;;;oEAiBK;AAAA,aAAM,MAAKC,KAAL,CAAWC,MAAX,CAAkBC,MAAlB,CAAyB,UAAAC,CAAC;AAAA,eAAIA,CAAC,CAACC,QAAN;AAAA,OAA1B,EAA0CC,MAAhD;AAAA,K;;oEAEA,UAAAC,aAAa,EAAI;AAAA,UACvBC,iBADuB,GACD,MAAKP,KADJ,CACvBO,iBADuB;;AAG/B,UAAIA,iBAAiB,KAAK,CAA1B,E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b;AAEA,aACE;AACE,QAAA,SAAS,EAAEH,SADb;AAEE,QAAA,uBAAuB,EAAE;AAAEI,UAAAA,MAAM,EAAEF;AAAV,SAF3B;AAGE,QAAA,OAAO,EAAE,KAAKG;AAHhB,QADF;AAOD;;;;EAzI8BC,kBAAMC,S;;;;gBAA1BpD,W,eACQ;AACjBE,EAAAA,MAAM,EAAEmD,sBAAUC,OAAV,CAAkBD,sBAAUE,KAAV,CAAgBC,iBAAhB,CAAlB,EAA+CC,UADtC;AAEjBZ,EAAAA,SAAS,EAAEQ,sBAAUK,MAFJ;AAGjBf,EAAAA,OAAO,EAAEU,sBAAUM,MAAV,CAAiBF,UAHT;AAIjBnC,EAAAA,QAAQ,EAAE+B,sBAAUO,IAAV,CAAeH,UAJR;AAKjB3B,EAAAA,QAAQ,EAAEuB,sBAAUQ,IALH;AAMjB9B,EAAAA,gBAAgB,EAAEsB,sBAAUQ,IANX;AAOjBrD,EAAAA,iBAAiB,EAAE6C,sBAAUS;AAPZ,C;;gBADR9D,W,kBAWW;AACpB+B,EAAAA,gBAAgB,EAAE,KADE;AAEpBvB,EAAAA,iBAAiB,EAAE,CAFC;AAGpBN,EAAAA,MAAM,EAAE;AAHY,C;;eAiIT,wBAAW;AAAA,SAAO;AAC/B4C,IAAAA,WAAW;AACTiB,MAAAA,eAAe,EAAE,MADR;AAETC,MAAAA,UAAU,EAAE;AAFH,OAGN,2BAHM;AAIT,aAAO;AACLA,QAAAA,UAAU,EAAE;AADP;AAJE;AADoB,GAAP;AAAA,CAAX,EASXhE,WATW,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport Token, { TokenTypes } from './token';\nimport { withStyles } from '@material-ui/core/styles';\nimport classNames from 'classnames';\nimport clone from 'lodash/clone';\nimport debug from 'debug';\nimport { noSelect } from '@pie-lib/style-utils';\nimport { renderToString } from 'react-dom/server';\nimport isEqual from 'lodash/isEqual';\n\nconst log = debug('@pie-lib:text-select:token-select');\n\nexport class TokenSelect extends React.Component {\n static propTypes = {\n tokens: PropTypes.arrayOf(PropTypes.shape(TokenTypes)).isRequired,\n className: PropTypes.string,\n classes: PropTypes.object.isRequired,\n onChange: PropTypes.func.isRequired,\n disabled: PropTypes.bool,\n highlightChoices: PropTypes.bool,\n maxNoOfSelections: PropTypes.number\n };\n\n static defaultProps = {\n highlightChoices: false,\n maxNoOfSelections: 0,\n tokens: []\n };\n\n selectedCount = () => this.props.tokens.filter(t => t.selected).length;\n\n canSelectMore = selectedCount => {\n const { maxNoOfSelections } = this.props;\n\n if (maxNoOfSelections === 1) {\n return true;\n }\n\n log('[canSelectMore] maxNoOfSelections: ', maxNoOfSelections, 'selectedCount: ', selectedCount);\n return (\n maxNoOfSelections <= 0 || (isFinite(maxNoOfSelections) && selectedCount < maxNoOfSelections)\n );\n };\n\n /**\n @function\n @param { object } event\n\n @description\n each token is wrapped into a span that has Token.rootClassName class and indexkey attribute (represents the index of the token)\n tokens are updated with the targeted token having the correct value set for 'selected' property\n */\n toggleToken = event => {\n const { target } = event;\n const { tokens } = this.props;\n const tokensCloned = clone(tokens);\n const targetSpanWrapper = target.closest(`.${Token.rootClassName}`);\n const targetedTokenIndex =\n targetSpanWrapper && targetSpanWrapper.dataset && targetSpanWrapper.dataset.indexkey;\n const t = targetedTokenIndex && tokensCloned[targetedTokenIndex];\n\n if (t && t.correct === undefined) {\n const { onChange, maxNoOfSelections } = this.props;\n const selected = !t.selected;\n\n if (maxNoOfSelections === 1 && this.selectedCount() === 1) {\n const selectedToken = (tokens || []).filter(t => t.selected);\n\n const updatedTokens = tokensCloned.map(token => {\n if (isEqual(token, selectedToken[0])) {\n return { ...token, selected: false };\n }\n\n return { ...token, selectable: true };\n });\n\n const update = { ...t, selected: !t.selected };\n\n updatedTokens.splice(targetedTokenIndex, 1, update);\n onChange(updatedTokens);\n } else {\n if (selected && maxNoOfSelections > 0 && this.selectedCount() >= maxNoOfSelections) {\n log('skip toggle max reached');\n return;\n }\n\n const update = { ...t, selected: !t.selected };\n\n tokensCloned.splice(targetedTokenIndex, 1, update);\n onChange(tokensCloned);\n }\n }\n };\n\n generateTokensInHtml = () => {\n const { tokens, disabled, highlightChoices } = this.props;\n const selectedCount = this.selectedCount();\n const isLineBreak = text => text === '\\n';\n const isNewParagraph = text => text === '\\n\\n';\n\n const reducer = (accumulator, t, index) => {\n const selectable = t.selected || (t.selectable && this.canSelectMore(selectedCount));\n const showCorrectAnswer = t.correct !== undefined && (t.selectable || t.selected);\n let finalAcc = accumulator;\n\n if (isNewParagraph(t.text)) {\n return finalAcc + '</p><p>';\n }\n\n if (isLineBreak(t.text)) {\n return finalAcc + '<br>';\n }\n\n if ((selectable && !disabled) || showCorrectAnswer || t.selected) {\n return (\n finalAcc +\n renderToString(\n <Token\n key={index}\n disabled={disabled}\n index={index}\n {...t}\n selectable={selectable}\n highlight={highlightChoices}\n />\n )\n );\n } else {\n return accumulator + t.text;\n }\n };\n\n const reduceResult = (tokens || []).reduce(reducer, '<p>');\n\n return reduceResult + '</p>';\n };\n\n render() {\n const { classes, className: classNameProp } = this.props;\n const className = classNames(classes.tokenSelect, classNameProp);\n const html = this.generateTokensInHtml();\n\n return (\n <div\n className={className}\n dangerouslySetInnerHTML={{ __html: html }}\n onClick={this.toggleToken}\n />\n );\n }\n}\n\nexport default withStyles(() => ({\n tokenSelect: {\n backgroundColor: 'none',\n whiteSpace: 'pre',\n ...noSelect(),\n '& p': {\n whiteSpace: 'break-spaces'\n }\n }\n}))(TokenSelect);\n"],"file":"index.js"}
|
|
@@ -50,7 +50,7 @@ var getCaretCharacterOffsetWithin = function getCaretCharacterOffsetWithin(eleme
|
|
|
50
50
|
caretOffset = preCaretRange.toString().length;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
} else if ((sel = doc.selection) && sel.type
|
|
53
|
+
} else if ((sel = doc.selection) && sel.type !== 'Control') {
|
|
54
54
|
var textRange = sel.createRange();
|
|
55
55
|
var preCaretTextRange = doc.body.createTextRange();
|
|
56
56
|
preCaretTextRange.moveToElementText(element);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tokenizer/selection-utils.js"],"names":["clearSelection","document","getSelection","removeAllRanges","addRange","createRange","window","empty","selection","getCaretCharacterOffsetWithin","element","caretOffset","doc","ownerDocument","win","defaultView","parentWindow","sel","rangeCount","range","getRangeAt","selected","toString","length","preCaretRange","cloneRange","selectNodeContents","setEnd","endContainer","endOffset","type","textRange","preCaretTextRange","body","createTextRange","moveToElementText","setEndPoint","text"],"mappings":";;;;;;;AAAO,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,GAAM;AAClC,MAAIC,QAAQ,CAACC,YAAb,EAA2B;AACzB;AACAD,IAAAA,QAAQ,CAACC,YAAT,GAAwBC,eAAxB;AACAF,IAAAA,QAAQ,CAACC,YAAT,GAAwBE,QAAxB,CAAiCH,QAAQ,CAACI,WAAT,EAAjC;AACD,GAJD,MAIO,IAAIC,MAAM,CAACJ,YAAX,EAAyB;AAC9B;AACA,QAAII,MAAM,CAACJ,YAAP,GAAsBC,eAA1B,EAA2C;AACzC;AACAG,MAAAA,MAAM,CAACJ,YAAP,GAAsBC,eAAtB;AACAG,MAAAA,MAAM,CAACJ,YAAP,GAAsBE,QAAtB,CAA+BH,QAAQ,CAACI,WAAT,EAA/B;AACD,KAJD,MAIO,IAAIC,MAAM,CAACJ,YAAP,GAAsBK,KAA1B,EAAiC;AACtC;AACAD,MAAAA,MAAM,CAACJ,YAAP,GAAsBK,KAAtB;AACD;AACF,GAVM,MAUA,IAAIN,QAAQ,CAACO,SAAb,EAAwB;AAC7B;AACAP,IAAAA,QAAQ,CAACO,SAAT,CAAmBD,KAAnB;AACD;AACF,CAnBM;;;;AAqBA,IAAME,6BAA6B,GAAG,SAAhCA,6BAAgC,CAAAC,OAAO,EAAI;AACtD,MAAIC,WAAW,GAAG,CAAlB;AACA,MAAIC,GAAG,GAAGF,OAAO,CAACG,aAAR,IAAyBH,OAAO,CAACT,QAA3C;AACA,MAAIa,GAAG,GAAGF,GAAG,CAACG,WAAJ,IAAmBH,GAAG,CAACI,YAAjC;AACA,MAAIC,GAAJ;;AACA,MAAI,OAAOH,GAAG,CAACZ,YAAX,KAA4B,WAAhC,EAA6C;AAC3Ce,IAAAA,GAAG,GAAGH,GAAG,CAACZ,YAAJ,EAAN;;AACA,QAAIe,GAAG,CAACC,UAAJ,GAAiB,CAArB,EAAwB;AACtB,UAAIC,KAAK,GAAGL,GAAG,CAACZ,YAAJ,GAAmBkB,UAAnB,CAA8B,CAA9B,CAAZ;AACA,UAAIC,QAAQ,GAAGF,KAAK,CAACG,QAAN,GAAiBC,MAAhC;AACA,UAAIC,aAAa,GAAGL,KAAK,CAACM,UAAN,EAApB;AACAD,MAAAA,aAAa,CAACE,kBAAd,CAAiChB,OAAjC;AACAc,MAAAA,aAAa,CAACG,MAAd,CAAqBR,KAAK,CAACS,YAA3B,EAAyCT,KAAK,CAACU,SAA/C;;AACA,UAAIR,QAAJ,EAAc;AACZV,QAAAA,WAAW,GAAGa,aAAa,CAACF,QAAd,GAAyBC,MAAzB,GAAkCF,QAAhD;AACD,OAFD,MAEO;AACLV,QAAAA,WAAW,GAAGa,aAAa,CAACF,QAAd,GAAyBC,MAAvC;AACD;AACF;AACF,GAdD,MAcO,IAAI,CAACN,GAAG,GAAGL,GAAG,CAACJ,SAAX,KAAyBS,GAAG,CAACa,IAAJ,
|
|
1
|
+
{"version":3,"sources":["../../src/tokenizer/selection-utils.js"],"names":["clearSelection","document","getSelection","removeAllRanges","addRange","createRange","window","empty","selection","getCaretCharacterOffsetWithin","element","caretOffset","doc","ownerDocument","win","defaultView","parentWindow","sel","rangeCount","range","getRangeAt","selected","toString","length","preCaretRange","cloneRange","selectNodeContents","setEnd","endContainer","endOffset","type","textRange","preCaretTextRange","body","createTextRange","moveToElementText","setEndPoint","text"],"mappings":";;;;;;;AAAO,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,GAAM;AAClC,MAAIC,QAAQ,CAACC,YAAb,EAA2B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AGL,KAAK,CAACM,UAAN,EAApB;AACAD,MAAAA,aAAa,CAACE,kBAAd,CAAiChB,OAAjC;AACAc,MAAAA,aAAa,CAACG,MAAd,CAAqBR,KAAK,CAACS,YAA3B,EAAyCT,KAAK,CAACU,SAA/C;;AACA,UAAIR,QAAJ,EAAc;AACZV,QAAAA,WAAW,GAAGa,aAAa,CAACF,QAAd,GAAyBC,MAAzB,GAAkCF,QAAhD;AACD,OAFD,MAEO;AACLV,QAAAA,WAAW,GAAGa,aAAa,CAACF,QAAd,GAAyBC,MAAvC;AACD;AACF;AACF,GAdD,MAcO,IAAI,CAACN,GAAG,GAAGL,GAAG,CAACJ,SAAX,KAAyBS,GAAG,CAACa,IAAJ,KAAa,SAA1C,EAAqD;AAC1D,QAAIC,SAAS,GAAGd,GAAG,CAACZ,WAAJ,EAAhB;AACA,QAAI2B,iBAAiB,GAAGpB,GAAG,CAACqB,IAAJ,CAASC,eAAT,EAAxB;AACAF,IAAAA,iBAAiB,CAACG,iBAAlB,CAAoCzB,OAApC;AACAsB,IAAAA,iBAAiB,CAACI,WAAlB,CAA8B,UAA9B,EAA0CL,SAA1C;AACApB,IAAAA,WAAW,GAAGqB,iBAAiB,CAACK,IAAlB,CAAuBd,MAArC;AACD;;AACD,SAAOZ,WAAP;AACD,CA3BM","sourcesContent":["export const clearSelection = () => {\n if (document.getSelection) {\n // for all new browsers (IE9+, Chrome, Firefox)\n document.getSelection().removeAllRanges();\n document.getSelection().addRange(document.createRange());\n } else if (window.getSelection) {\n // equals with the document.getSelection (MSDN info)\n if (window.getSelection().removeAllRanges) {\n // for all new browsers (IE9+, Chrome, Firefox)\n window.getSelection().removeAllRanges();\n window.getSelection().addRange(document.createRange());\n } else if (window.getSelection().empty) {\n // Chrome supports this as well\n window.getSelection().empty();\n }\n } else if (document.selection) {\n // IE8-\n document.selection.empty();\n }\n};\n\nexport const getCaretCharacterOffsetWithin = element => {\n var caretOffset = 0;\n var doc = element.ownerDocument || element.document;\n var win = doc.defaultView || doc.parentWindow;\n var sel;\n if (typeof win.getSelection !== 'undefined') {\n sel = win.getSelection();\n if (sel.rangeCount > 0) {\n var range = win.getSelection().getRangeAt(0);\n var selected = range.toString().length;\n var preCaretRange = range.cloneRange();\n preCaretRange.selectNodeContents(element);\n preCaretRange.setEnd(range.endContainer, range.endOffset);\n if (selected) {\n caretOffset = preCaretRange.toString().length - selected;\n } else {\n caretOffset = preCaretRange.toString().length;\n }\n }\n } else if ((sel = doc.selection) && sel.type !== 'Control') {\n var textRange = sel.createRange();\n var preCaretTextRange = doc.body.createTextRange();\n preCaretTextRange.moveToElementText(element);\n preCaretTextRange.setEndPoint('EndToEnd', textRange);\n caretOffset = preCaretTextRange.text.length;\n }\n return caretOffset;\n};\n"],"file":"selection-utils.js"}
|
|
@@ -85,6 +85,7 @@ var Text = (0, _styles.withStyles)(function () {
|
|
|
85
85
|
}
|
|
86
86
|
});
|
|
87
87
|
exports.Text = Text;
|
|
88
|
+
var notAllowedCharacters = ['\n', ' ', '\t'];
|
|
88
89
|
|
|
89
90
|
var TokenText =
|
|
90
91
|
/*#__PURE__*/
|
|
@@ -104,12 +105,12 @@ function (_React$Component) {
|
|
|
104
105
|
|
|
105
106
|
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(TokenText)).call.apply(_getPrototypeOf2, [this].concat(args)));
|
|
106
107
|
|
|
107
|
-
_defineProperty(_assertThisInitialized(_this), "
|
|
108
|
-
event.preventDefault();
|
|
108
|
+
_defineProperty(_assertThisInitialized(_this), "onClick", function (event) {
|
|
109
109
|
var _this$props = _this.props,
|
|
110
110
|
onSelectToken = _this$props.onSelectToken,
|
|
111
111
|
text = _this$props.text,
|
|
112
112
|
tokens = _this$props.tokens;
|
|
113
|
+
event.preventDefault();
|
|
113
114
|
|
|
114
115
|
if (typeof window === 'undefined') {
|
|
115
116
|
return;
|
|
@@ -118,9 +119,19 @@ function (_React$Component) {
|
|
|
118
119
|
var selection = window.getSelection();
|
|
119
120
|
var textSelected = selection.toString();
|
|
120
121
|
|
|
121
|
-
if (textSelected.length > 0) {
|
|
122
|
+
if (textSelected.length > 0 && notAllowedCharacters.indexOf(textSelected) < 0) {
|
|
122
123
|
if (_this.root) {
|
|
123
124
|
var offset = (0, _selectionUtils.getCaretCharacterOffsetWithin)(_this.root);
|
|
125
|
+
/*
|
|
126
|
+
Since we implemented new line functionality (\n) using <br /> dom elements
|
|
127
|
+
and window.getSelection is not taking that into consideration, the offset might
|
|
128
|
+
be off by a few characters.
|
|
129
|
+
To combat that, we check if the selected text is right at the beginning of the offset.
|
|
130
|
+
If it's not, we add the additional offset in order for that to be accurate
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
var newLineOffset = text.slice(offset).indexOf(textSelected);
|
|
134
|
+
offset += newLineOffset;
|
|
124
135
|
|
|
125
136
|
if (offset !== undefined) {
|
|
126
137
|
var endIndex = offset + textSelected.length;
|
|
@@ -169,7 +180,7 @@ function (_React$Component) {
|
|
|
169
180
|
ref: function ref(r) {
|
|
170
181
|
return _this2.root = r;
|
|
171
182
|
},
|
|
172
|
-
|
|
183
|
+
onClick: this.onClick
|
|
173
184
|
}, normalized.map(function (t, index) {
|
|
174
185
|
return _react["default"].createElement(Text, _extends({
|
|
175
186
|
key: index
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tokenizer/token-text.jsx"],"names":["log","Text","predefined","cursor","backgroundColor","yellow","border","correct","green","text","classes","onClick","formattedText","replace","className","__html","
|
|
1
|
+
{"version":3,"sources":["../../src/tokenizer/token-text.jsx"],"names":["log","Text","predefined","cursor","backgroundColor","yellow","border","correct","green","text","classes","onClick","formattedText","replace","className","__html","notAllowedCharacters","TokenText","event","props","onSelectToken","tokens","preventDefault","window","selection","getSelection","textSelected","toString","length","indexOf","root","offset","newLineOffset","slice","undefined","endIndex","i","start","end","hasOverlap","tokensToRemove","surroundedTokens","token","onTokenClick","normalized","r","map","t","index","React","Component","PropTypes","string","isRequired","array","func"],"m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AAEN,MAFK;AAGZO,kBAAAA,GAAG,EAAEH;AAHO,iBAAd;AAMAf,gBAAAA,aAAa,CAACsB,KAAD,EAAQF,cAAR,CAAb;AACA;AACD;AACF;AACF;AACF;AACF;AACF,K;;;;;;;6BAEQ;AAAA;;AAAA,yBAC2C,KAAKrB,KADhD;AAAA,UACCV,IADD,gBACCA,IADD;AAAA,UACOY,MADP,gBACOA,MADP;AAAA,UACeP,SADf,gBACeA,SADf;AAAA,UAC0B6B,YAD1B,gBAC0BA,YAD1B;AAEP,UAAMC,UAAU,GAAG,wBAAUnC,IAAV,EAAgBY,MAAhB,CAAnB;AAEA,aACE;AAAK,QAAA,SAAS,EAAEP,SAAhB;AAA2B,QAAA,GAAG,EAAE,aAAA+B,CAAC;AAAA,iBAAK,MAAI,CAACf,IAAL,GAAYe,CAAjB;AAAA,SAAjC;AAAsD,QAAA,OAAO,EAAE,KAAKlC;AAApE,SACGiC,UAAU,CAACE,GAAX,CAAe,UAACC,CAAD,EAAIC,KAAJ,EAAc;AAC5B,eAAO,gCAAC,IAAD;AAAM,UAAA,GAAG,EAAEA;AAAX,WAAsBD,CAAtB;AAAyB,UAAA,OAAO,EAAE;AAAA,mBAAMJ,YAAY,CAACI,CAAD,CAAlB;AAAA;AAAlC,WAAP;AACD,OAFA,CADH,CADF;AAOD;;;;EAtFoCE,kBAAMC,S;;;;gBAAxBjC,S,eACA;AACjBR,EAAAA,IAAI,EAAE0C,sBAAUC,MAAV,CAAiBC,UADN;AAEjBhC,EAAAA,MAAM,EAAE8B,sBAAUG,KAAV,CAAgBD,UAFP;AAGjBV,EAAAA,YAAY,EAAEQ,sBAAUI,IAAV,CAAeF,UAHZ;AAIjBjC,EAAAA,aAAa,EAAE+B,sBAAUI,IAAV,CAAeF,UAJb;AAKjBvC,EAAAA,SAAS,EAAEqC,sBAAUC;AALJ,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport { normalize, intersection } from './builder';\nimport yellow from '@material-ui/core/colors/yellow';\nimport green from '@material-ui/core/colors/green';\nimport debug from 'debug';\nimport classNames from 'classnames';\n\nimport { clearSelection, getCaretCharacterOffsetWithin } from './selection-utils';\n\nconst log = debug('@pie-lib:text-select:token-text');\n\nexport const Text = withStyles(() => ({\n predefined: {\n cursor: 'pointer',\n backgroundColor: yellow[100],\n border: `dashed 0px ${yellow[700]}`\n },\n correct: {\n backgroundColor: green[500]\n }\n}))(({ text, predefined, classes, onClick, correct }) => {\n const formattedText = (text || '').replace(/\\n/g, '<br>');\n\n if (predefined) {\n const className = classNames(classes.predefined, correct && classes.correct);\n\n return (\n <span\n onClick={onClick}\n className={className}\n dangerouslySetInnerHTML={{ __html: formattedText }}\n />\n );\n } else {\n return <span dangerouslySetInnerHTML={{ __html: formattedText }} />;\n }\n});\n\nconst notAllowedCharacters = ['\\n', ' ', '\\t'];\n\nexport default class TokenText extends React.Component {\n static propTypes = {\n text: PropTypes.string.isRequired,\n tokens: PropTypes.array.isRequired,\n onTokenClick: PropTypes.func.isRequired,\n onSelectToken: PropTypes.func.isRequired,\n className: PropTypes.string\n };\n\n /*\n Change this to onClick instead of mouseUp because previously, in some cases\n the onClick event from the <Text /> component was called right after the user\n selected token and that token was then removed because the setCorrectMode was not true.\n\n const { setCorrectMode } = this.state;\n\n if (setCorrectMode) {\n this.setCorrect(token);\n } else {\n this.removeToken(token);\n }\n */\n onClick = event => {\n const { onSelectToken, text, tokens } = this.props;\n\n event.preventDefault();\n\n if (typeof window === 'undefined') {\n return;\n }\n\n const selection = window.getSelection();\n const textSelected = selection.toString();\n\n if (textSelected.length > 0 && notAllowedCharacters.indexOf(textSelected) < 0) {\n if (this.root) {\n let offset = getCaretCharacterOffsetWithin(this.root);\n /*\n Since we implemented new line functionality (\\n) using <br /> dom elements\n and window.getSelection is not taking that into consideration, the offset might\n be off by a few characters.\n\n To combat that, we check if the selected text is right at the beginning of the offset.\n\n If it's not, we add the additional offset in order for that to be accurate\n */\n const newLineOffset = text.slice(offset).indexOf(textSelected);\n\n offset += newLineOffset;\n\n if (offset !== undefined) {\n const endIndex = offset + textSelected.length;\n\n if (endIndex <= text.length) {\n const i = intersection({ start: offset, end: endIndex }, tokens);\n if (i.hasOverlap) {\n log('hasOverlap - do nothing');\n clearSelection();\n } else {\n const tokensToRemove = i.surroundedTokens;\n const token = {\n text: textSelected,\n start: offset,\n end: endIndex\n };\n\n onSelectToken(token, tokensToRemove);\n clearSelection();\n }\n }\n }\n }\n }\n };\n\n render() {\n const { text, tokens, className, onTokenClick } = this.props;\n const normalized = normalize(text, tokens);\n\n return (\n <div className={className} ref={r => (this.root = r)} onClick={this.onClick}>\n {normalized.map((t, index) => {\n return <Text key={index} {...t} onClick={() => onTokenClick(t)} />;\n })}\n </div>\n );\n }\n}\n"],"file":"token-text.js"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.8.
|
|
6
|
+
"version": "1.8.6-next.86+f45a2d2e",
|
|
7
7
|
"description": "Some react components for text selection",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"react",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@pie-framework/parse-english": "^1.0.0",
|
|
21
|
-
"@pie-lib/render-ui": "^4.12.
|
|
21
|
+
"@pie-lib/render-ui": "^4.12.1-next.86+f45a2d2e",
|
|
22
22
|
"@pie-lib/style-utils": "^0.1.25",
|
|
23
23
|
"classnames": "^2.2.6",
|
|
24
24
|
"debug": "^4.1.1",
|
|
@@ -38,6 +38,6 @@
|
|
|
38
38
|
"@material-ui/core": "^3.8.3",
|
|
39
39
|
"react": "^16.8.1"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "f45a2d2e117fa21914e67a74c97fbec724227986",
|
|
42
42
|
"scripts": {}
|
|
43
43
|
}
|
|
@@ -112,8 +112,7 @@ export class TokenSelect extends React.Component {
|
|
|
112
112
|
return finalAcc + '<br>';
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
|
|
116
|
-
if (!disabled || showCorrectAnswer || t.selected) {
|
|
115
|
+
if ((selectable && !disabled) || showCorrectAnswer || t.selected) {
|
|
117
116
|
return (
|
|
118
117
|
finalAcc +
|
|
119
118
|
renderToString(
|
|
@@ -38,7 +38,7 @@ export const getCaretCharacterOffsetWithin = element => {
|
|
|
38
38
|
caretOffset = preCaretRange.toString().length;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
} else if ((sel = doc.selection) && sel.type
|
|
41
|
+
} else if ((sel = doc.selection) && sel.type !== 'Control') {
|
|
42
42
|
var textRange = sel.createRange();
|
|
43
43
|
var preCaretTextRange = doc.body.createTextRange();
|
|
44
44
|
preCaretTextRange.moveToElementText(element);
|
|
@@ -38,6 +38,8 @@ export const Text = withStyles(() => ({
|
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
+
const notAllowedCharacters = ['\n', ' ', '\t'];
|
|
42
|
+
|
|
41
43
|
export default class TokenText extends React.Component {
|
|
42
44
|
static propTypes = {
|
|
43
45
|
text: PropTypes.string.isRequired,
|
|
@@ -47,10 +49,24 @@ export default class TokenText extends React.Component {
|
|
|
47
49
|
className: PropTypes.string
|
|
48
50
|
};
|
|
49
51
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
/*
|
|
53
|
+
Change this to onClick instead of mouseUp because previously, in some cases
|
|
54
|
+
the onClick event from the <Text /> component was called right after the user
|
|
55
|
+
selected token and that token was then removed because the setCorrectMode was not true.
|
|
56
|
+
|
|
57
|
+
const { setCorrectMode } = this.state;
|
|
58
|
+
|
|
59
|
+
if (setCorrectMode) {
|
|
60
|
+
this.setCorrect(token);
|
|
61
|
+
} else {
|
|
62
|
+
this.removeToken(token);
|
|
63
|
+
}
|
|
64
|
+
*/
|
|
65
|
+
onClick = event => {
|
|
52
66
|
const { onSelectToken, text, tokens } = this.props;
|
|
53
67
|
|
|
68
|
+
event.preventDefault();
|
|
69
|
+
|
|
54
70
|
if (typeof window === 'undefined') {
|
|
55
71
|
return;
|
|
56
72
|
}
|
|
@@ -58,9 +74,22 @@ export default class TokenText extends React.Component {
|
|
|
58
74
|
const selection = window.getSelection();
|
|
59
75
|
const textSelected = selection.toString();
|
|
60
76
|
|
|
61
|
-
if (textSelected.length > 0) {
|
|
77
|
+
if (textSelected.length > 0 && notAllowedCharacters.indexOf(textSelected) < 0) {
|
|
62
78
|
if (this.root) {
|
|
63
|
-
|
|
79
|
+
let offset = getCaretCharacterOffsetWithin(this.root);
|
|
80
|
+
/*
|
|
81
|
+
Since we implemented new line functionality (\n) using <br /> dom elements
|
|
82
|
+
and window.getSelection is not taking that into consideration, the offset might
|
|
83
|
+
be off by a few characters.
|
|
84
|
+
|
|
85
|
+
To combat that, we check if the selected text is right at the beginning of the offset.
|
|
86
|
+
|
|
87
|
+
If it's not, we add the additional offset in order for that to be accurate
|
|
88
|
+
*/
|
|
89
|
+
const newLineOffset = text.slice(offset).indexOf(textSelected);
|
|
90
|
+
|
|
91
|
+
offset += newLineOffset;
|
|
92
|
+
|
|
64
93
|
if (offset !== undefined) {
|
|
65
94
|
const endIndex = offset + textSelected.length;
|
|
66
95
|
|
|
@@ -88,11 +117,10 @@ export default class TokenText extends React.Component {
|
|
|
88
117
|
|
|
89
118
|
render() {
|
|
90
119
|
const { text, tokens, className, onTokenClick } = this.props;
|
|
91
|
-
|
|
92
120
|
const normalized = normalize(text, tokens);
|
|
93
121
|
|
|
94
122
|
return (
|
|
95
|
-
<div className={className} ref={r => (this.root = r)}
|
|
123
|
+
<div className={className} ref={r => (this.root = r)} onClick={this.onClick}>
|
|
96
124
|
{normalized.map((t, index) => {
|
|
97
125
|
return <Text key={index} {...t} onClick={() => onTokenClick(t)} />;
|
|
98
126
|
})}
|