@oat-sa/tao-core-ui 1.67.0 → 2.0.0

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 (239) hide show
  1. package/README.md +17 -16
  2. package/dist/animable/absorbable/css/absorb.css +25 -29
  3. package/dist/animable/absorbable/css/absorb.css.map +1 -1
  4. package/dist/animable/pulsable/css/pulse.css +20 -23
  5. package/dist/animable/pulsable/css/pulse.css.map +1 -1
  6. package/dist/autocomplete/css/autocomplete.css +20 -21
  7. package/dist/autocomplete/css/autocomplete.css.map +1 -1
  8. package/dist/badge/css/badge.css +67 -79
  9. package/dist/badge/css/badge.css.map +1 -1
  10. package/dist/breadcrumbs/css/breadcrumbs.css +54 -61
  11. package/dist/breadcrumbs/css/breadcrumbs.css.map +1 -1
  12. package/dist/bulkActionPopup/css/bulkActionPopup.css +27 -42
  13. package/dist/bulkActionPopup/css/bulkActionPopup.css.map +1 -1
  14. package/dist/calculator/css/calculator.css +91 -112
  15. package/dist/calculator/css/calculator.css.map +1 -1
  16. package/dist/class/css/selector.css +83 -97
  17. package/dist/class/css/selector.css.map +1 -1
  18. package/dist/component/css/components.css +351 -406
  19. package/dist/component/css/components.css.map +1 -1
  20. package/dist/component/css/windowComponent.css +19 -28
  21. package/dist/component/css/windowComponent.css.map +1 -1
  22. package/dist/contextualPopup/css/contextualPopup.css +42 -55
  23. package/dist/contextualPopup/css/contextualPopup.css.map +1 -1
  24. package/dist/dashboard/css/dashboard.css +43 -57
  25. package/dist/dashboard/css/dashboard.css.map +1 -1
  26. package/dist/datalist/css/datalist.css +63 -88
  27. package/dist/datalist/css/datalist.css.map +1 -1
  28. package/dist/datatable/css/datatable.css +84 -113
  29. package/dist/datatable/css/datatable.css.map +1 -1
  30. package/dist/dateRange/css/dateRange.css +1 -2
  31. package/dist/dateRange/css/dateRange.css.map +1 -1
  32. package/dist/datetime/css/picker.css +71 -103
  33. package/dist/datetime/css/picker.css.map +1 -1
  34. package/dist/destination/css/selector.css +17 -24
  35. package/dist/destination/css/selector.css.map +1 -1
  36. package/dist/documentViewer/css/documentViewer.css +137 -162
  37. package/dist/documentViewer/css/documentViewer.css.map +1 -1
  38. package/dist/dropdown/css/dropdown.css +55 -72
  39. package/dist/dropdown/css/dropdown.css.map +1 -1
  40. package/dist/dynamicComponent/css/dynamicComponent.css +78 -91
  41. package/dist/dynamicComponent/css/dynamicComponent.css.map +1 -1
  42. package/dist/form/css/dropdownForm.css +36 -45
  43. package/dist/form/css/dropdownForm.css.map +1 -1
  44. package/dist/form/css/form.css +12 -16
  45. package/dist/form/css/form.css.map +1 -1
  46. package/dist/form/validator/css/validator.css +5 -7
  47. package/dist/form/validator/css/validator.css.map +1 -1
  48. package/dist/form/widget/css/widget.css +26 -34
  49. package/dist/form/widget/css/widget.css.map +1 -1
  50. package/dist/generis/form/css/form.css +14 -18
  51. package/dist/generis/form/css/form.css.map +1 -1
  52. package/dist/generis/validator/css/validator.css +5 -7
  53. package/dist/generis/validator/css/validator.css.map +1 -1
  54. package/dist/generis/widget/css/widget.css +29 -38
  55. package/dist/generis/widget/css/widget.css.map +1 -1
  56. package/dist/itemButtonList/css/item-button-list.css +135 -172
  57. package/dist/itemButtonList/css/item-button-list.css.map +1 -1
  58. package/dist/listbox/css/listbox.css +64 -84
  59. package/dist/listbox/css/listbox.css.map +1 -1
  60. package/dist/loadingButton/css/button.css +20 -29
  61. package/dist/loadingButton/css/button.css.map +1 -1
  62. package/dist/maths/calculator/basicCalculator.js +4 -4
  63. package/dist/maths/calculator/calculatorComponent.js +22 -25
  64. package/dist/maths/calculator/core/board.js +12327 -720
  65. package/dist/maths/calculator/core/labels.js +7918 -138
  66. package/dist/maths/calculator/core/plugin.js +4 -5
  67. package/dist/maths/calculator/css/calculator.css +224 -270
  68. package/dist/maths/calculator/css/calculator.css.map +1 -1
  69. package/dist/maths/calculator/defaultCalculator.js +10 -6
  70. package/dist/maths/calculator/plugins/keyboard/templateKeyboard/templateKeyboard.js +23 -25
  71. package/dist/maths/calculator/plugins/screen/simpleScreen/simpleScreen.js +7973 -194
  72. package/dist/maths/calculator/scientificCalculator.js +7 -12
  73. package/dist/mediaplayer/css/player.css +281 -370
  74. package/dist/mediaplayer/css/player.css.map +1 -1
  75. package/dist/pagination/css/pagination.css +38 -49
  76. package/dist/pagination/css/pagination.css.map +1 -1
  77. package/dist/propertySelector/css/propertySelector.css +34 -44
  78. package/dist/propertySelector/css/propertySelector.css.map +1 -1
  79. package/dist/resource/css/selector.css +400 -490
  80. package/dist/resource/css/selector.css.map +1 -1
  81. package/dist/resourcemgr/css/resourcemgr.css +192 -237
  82. package/dist/resourcemgr/css/resourcemgr.css.map +1 -1
  83. package/dist/searchModal/css/advancedSearch.css +92 -121
  84. package/dist/searchModal/css/advancedSearch.css.map +1 -1
  85. package/dist/searchModal/css/searchModal.css +261 -333
  86. package/dist/searchModal/css/searchModal.css.map +1 -1
  87. package/dist/switch/css/switch.css +36 -47
  88. package/dist/switch/css/switch.css.map +1 -1
  89. package/dist/tabs/css/tabs.css +32 -40
  90. package/dist/tabs/css/tabs.css.map +1 -1
  91. package/dist/taskQueue/css/taskQueue.css +17 -27
  92. package/dist/taskQueue/css/taskQueue.css.map +1 -1
  93. package/dist/taskQueueButton/css/taskable.css +1 -2
  94. package/dist/taskQueueButton/css/taskable.css.map +1 -1
  95. package/dist/taskQueueButton/css/treeButton.css +20 -26
  96. package/dist/taskQueueButton/css/treeButton.css.map +1 -1
  97. package/dist/tristateCheckboxGroup/css/tristateCheckboxGroup.css +3 -5
  98. package/dist/tristateCheckboxGroup/css/tristateCheckboxGroup.css.map +1 -1
  99. package/dist/waitingDialog/css/waitingDialog.css +18 -23
  100. package/dist/waitingDialog/css/waitingDialog.css.map +1 -1
  101. package/package.json +20 -24
  102. package/scss/inc/_base.scss +9 -8
  103. package/scss/inc/_flex-grid.scss +1 -1
  104. package/scss/inc/_forms.scss +5 -5
  105. package/scss/inc/_functions.scss +8 -8
  106. package/scss/inc/fonts/_tao-icon-classes.scss +230 -230
  107. package/src/animable/absorbable/css/absorb.css +25 -29
  108. package/src/animable/absorbable/css/absorb.css.map +1 -1
  109. package/src/animable/pulsable/css/pulse.css +20 -23
  110. package/src/animable/pulsable/css/pulse.css.map +1 -1
  111. package/src/autocomplete/css/autocomplete.css +20 -21
  112. package/src/autocomplete/css/autocomplete.css.map +1 -1
  113. package/src/badge/css/badge.css +67 -79
  114. package/src/badge/css/badge.css.map +1 -1
  115. package/src/breadcrumbs/css/breadcrumbs.css +54 -61
  116. package/src/breadcrumbs/css/breadcrumbs.css.map +1 -1
  117. package/src/bulkActionPopup/css/bulkActionPopup.css +27 -42
  118. package/src/bulkActionPopup/css/bulkActionPopup.css.map +1 -1
  119. package/src/calculator/css/calculator.css +91 -112
  120. package/src/calculator/css/calculator.css.map +1 -1
  121. package/src/calculator/scss/calculator.scss +1 -1
  122. package/src/class/css/selector.css +83 -97
  123. package/src/class/css/selector.css.map +1 -1
  124. package/src/component/css/components.css +351 -406
  125. package/src/component/css/components.css.map +1 -1
  126. package/src/component/css/windowComponent.css +19 -28
  127. package/src/component/css/windowComponent.css.map +1 -1
  128. package/src/contextualPopup/css/contextualPopup.css +42 -55
  129. package/src/contextualPopup/css/contextualPopup.css.map +1 -1
  130. package/src/css/basic.css +4000 -4374
  131. package/src/css/basic.css.map +1 -1
  132. package/src/dashboard/css/dashboard.css +43 -57
  133. package/src/dashboard/css/dashboard.css.map +1 -1
  134. package/src/datalist/css/datalist.css +63 -88
  135. package/src/datalist/css/datalist.css.map +1 -1
  136. package/src/datatable/css/datatable.css +84 -113
  137. package/src/datatable/css/datatable.css.map +1 -1
  138. package/src/dateRange/css/dateRange.css +1 -2
  139. package/src/dateRange/css/dateRange.css.map +1 -1
  140. package/src/datetime/css/picker.css +71 -103
  141. package/src/datetime/css/picker.css.map +1 -1
  142. package/src/destination/css/selector.css +17 -24
  143. package/src/destination/css/selector.css.map +1 -1
  144. package/src/documentViewer/css/documentViewer.css +137 -162
  145. package/src/documentViewer/css/documentViewer.css.map +1 -1
  146. package/src/dropdown/css/dropdown.css +55 -72
  147. package/src/dropdown/css/dropdown.css.map +1 -1
  148. package/src/dynamicComponent/css/dynamicComponent.css +78 -91
  149. package/src/dynamicComponent/css/dynamicComponent.css.map +1 -1
  150. package/src/form/css/dropdownForm.css +36 -45
  151. package/src/form/css/dropdownForm.css.map +1 -1
  152. package/src/form/css/form.css +12 -16
  153. package/src/form/css/form.css.map +1 -1
  154. package/src/form/validator/css/validator.css +5 -7
  155. package/src/form/validator/css/validator.css.map +1 -1
  156. package/src/form/widget/css/widget.css +26 -34
  157. package/src/form/widget/css/widget.css.map +1 -1
  158. package/src/generis/form/css/form.css +14 -18
  159. package/src/generis/form/css/form.css.map +1 -1
  160. package/src/generis/validator/css/validator.css +5 -7
  161. package/src/generis/validator/css/validator.css.map +1 -1
  162. package/src/generis/widget/css/widget.css +29 -38
  163. package/src/generis/widget/css/widget.css.map +1 -1
  164. package/src/itemButtonList/css/item-button-list.css +135 -172
  165. package/src/itemButtonList/css/item-button-list.css.map +1 -1
  166. package/src/listbox/css/listbox.css +64 -84
  167. package/src/listbox/css/listbox.css.map +1 -1
  168. package/src/listbox/scss/listbox.scss +8 -8
  169. package/src/loadingButton/css/button.css +20 -29
  170. package/src/loadingButton/css/button.css.map +1 -1
  171. package/src/maths/calculator/basicCalculator.js +1 -4
  172. package/src/maths/calculator/calculatorComponent.js +49 -60
  173. package/src/maths/calculator/core/board.js +372 -493
  174. package/src/maths/calculator/core/labels.js +46 -48
  175. package/src/maths/calculator/core/plugin.js +3 -5
  176. package/src/maths/calculator/core/tpl/terms.tpl +7 -1
  177. package/src/maths/calculator/css/calculator.css +224 -270
  178. package/src/maths/calculator/css/calculator.css.map +1 -1
  179. package/src/maths/calculator/defaultCalculator.js +7 -9
  180. package/src/maths/calculator/plugins/keyboard/templateKeyboard/defaultTemplate.tpl +3 -3
  181. package/src/maths/calculator/plugins/keyboard/templateKeyboard/templateKeyboard.js +17 -20
  182. package/src/maths/calculator/plugins/screen/simpleScreen/simpleScreen.js +102 -108
  183. package/src/maths/calculator/scientificCalculator.js +2 -10
  184. package/src/maths/calculator/scss/calculator.scss +20 -7
  185. package/src/maths/calculator/tpl/basicKeyboard.tpl +3 -3
  186. package/src/maths/calculator/tpl/scientificKeyboard.tpl +4 -4
  187. package/src/mediaplayer/css/player.css +281 -370
  188. package/src/mediaplayer/css/player.css.map +1 -1
  189. package/src/pagination/css/pagination.css +38 -49
  190. package/src/pagination/css/pagination.css.map +1 -1
  191. package/src/propertySelector/css/propertySelector.css +34 -44
  192. package/src/propertySelector/css/propertySelector.css.map +1 -1
  193. package/src/resource/css/selector.css +400 -490
  194. package/src/resource/css/selector.css.map +1 -1
  195. package/src/resourcemgr/css/resourcemgr.css +192 -237
  196. package/src/resourcemgr/css/resourcemgr.css.map +1 -1
  197. package/src/searchModal/css/advancedSearch.css +92 -121
  198. package/src/searchModal/css/advancedSearch.css.map +1 -1
  199. package/src/searchModal/css/searchModal.css +261 -333
  200. package/src/searchModal/css/searchModal.css.map +1 -1
  201. package/src/searchModal/scss/searchModal.scss +1 -1
  202. package/src/switch/css/switch.css +36 -47
  203. package/src/switch/css/switch.css.map +1 -1
  204. package/src/tabs/css/tabs.css +32 -40
  205. package/src/tabs/css/tabs.css.map +1 -1
  206. package/src/taskQueue/css/taskQueue.css +17 -27
  207. package/src/taskQueue/css/taskQueue.css.map +1 -1
  208. package/src/taskQueueButton/css/taskable.css +1 -2
  209. package/src/taskQueueButton/css/taskable.css.map +1 -1
  210. package/src/taskQueueButton/css/treeButton.css +20 -26
  211. package/src/taskQueueButton/css/treeButton.css.map +1 -1
  212. package/src/tristateCheckboxGroup/css/tristateCheckboxGroup.css +3 -5
  213. package/src/tristateCheckboxGroup/css/tristateCheckboxGroup.css.map +1 -1
  214. package/src/waitingDialog/css/waitingDialog.css +18 -23
  215. package/src/waitingDialog/css/waitingDialog.css.map +1 -1
  216. package/dist/maths/calculator/core/areaBroker.js +0 -43
  217. package/dist/maths/calculator/core/expression.js +0 -463
  218. package/dist/maths/calculator/core/terms.js +0 -456
  219. package/dist/maths/calculator/core/tokenizer.js +0 -229
  220. package/dist/maths/calculator/core/tokens.js +0 -167
  221. package/dist/maths/calculator/plugins/core/degrad.js +0 -71
  222. package/dist/maths/calculator/plugins/core/history.js +0 -149
  223. package/dist/maths/calculator/plugins/core/remind.js +0 -76
  224. package/dist/maths/calculator/plugins/core/stepNavigation.js +0 -148
  225. package/dist/maths/calculator/plugins/modifiers/pow10.js +0 -136
  226. package/dist/maths/calculator/plugins/modifiers/sign.js +0 -314
  227. package/dist/maths/calculator/pluginsLoader.js +0 -47
  228. package/src/maths/calculator/core/areaBroker.js +0 -38
  229. package/src/maths/calculator/core/expression.js +0 -430
  230. package/src/maths/calculator/core/terms.js +0 -459
  231. package/src/maths/calculator/core/tokenizer.js +0 -245
  232. package/src/maths/calculator/core/tokens.js +0 -178
  233. package/src/maths/calculator/plugins/core/degrad.js +0 -90
  234. package/src/maths/calculator/plugins/core/history.js +0 -166
  235. package/src/maths/calculator/plugins/core/remind.js +0 -96
  236. package/src/maths/calculator/plugins/core/stepNavigation.js +0 -175
  237. package/src/maths/calculator/plugins/modifiers/pow10.js +0 -143
  238. package/src/maths/calculator/plugins/modifiers/sign.js +0 -339
  239. package/src/maths/calculator/pluginsLoader.js +0 -46
@@ -1,175 +0,0 @@
1
- /**
2
- * This program is free software; you can redistribute it and/or
3
- * modify it under the terms of the GNU General Public License
4
- * as published by the Free Software Foundation; under version 2
5
- * of the License (non-upgradable).
6
- *
7
- * This program is distributed in the hope that it will be useful,
8
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- * GNU General Public License for more details.
11
- *
12
- * You should have received a copy of the GNU General Public License
13
- * along with this program; if not, write to the Free Software
14
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15
- *
16
- * Copyright (c) 2018 Open Assessment Technologies SA ;
17
- */
18
- /**
19
- * Plugin that manages a navigation by tokens within the current expression
20
- * @author Jean-Sébastien Conan <jean-sebastien@taotesting.com>
21
- */
22
-
23
- import __ from 'i18n';
24
- import nsHelper from 'util/namespace';
25
- import pluginFactory from 'ui/maths/calculator/core/plugin';
26
-
27
- var pluginName = 'stepNavigation';
28
-
29
- export default pluginFactory({
30
- name: pluginName,
31
-
32
- /**
33
- * Called when the plugin is installing in its host.
34
- */
35
- install: function install() {
36
- var calculator = this.getCalculator();
37
-
38
- calculator
39
- .setCommand('stepMoveLeft', __('Move Left'), __('Move the cursor one step on the left'))
40
- .setCommand('stepMoveRight', __('Move Right'), __('Move the cursor one step on the right'))
41
- .setCommand('stepDeleteLeft', __('Delete Left'), __('Delete the term on the left side of the cursor'))
42
- .setCommand('stepDeleteRight', __('Delete Right'), __('Delete the term on the right side of the cursor'));
43
- },
44
-
45
- /**
46
- * Called when the plugin should be initialized.
47
- */
48
- init: function init() {
49
- var calculator = this.getCalculator();
50
-
51
- /**
52
- * Remove a sub-expresion from the expression
53
- * @param expression
54
- * @param position
55
- * @param length
56
- */
57
- function remove(expression, position, length) {
58
- if (length) {
59
- expression = calculator.getExpression();
60
- calculator
61
- .setExpression(expression.substr(0, position) + expression.substr(position + length))
62
- .setPosition(position);
63
- }
64
- }
65
-
66
- /**
67
- * Remove a token from the expression
68
- * @param expression
69
- * @param token
70
- */
71
- function removeToken(expression, token) {
72
- var from, length;
73
- if (token) {
74
- expression = calculator.getExpression();
75
- from = token.offset;
76
- length = token.value.length;
77
- while (from + length < expression.length && expression.charAt(from + length) === ' ') {
78
- length++;
79
- }
80
-
81
- remove(expression, from, length);
82
- }
83
- }
84
-
85
- calculator
86
- .on(nsHelper.namespaceAll('command-stepMoveLeft', pluginName), function() {
87
- var position = calculator.getPosition();
88
- var tokens = calculator.getTokens();
89
- var index = calculator.getTokenIndex();
90
- var token = calculator.getToken();
91
- var offset = position;
92
-
93
- if (token && position > 0) {
94
- if (position === token.offset) {
95
- if (index > 0) {
96
- token = tokens[index - 1];
97
- } else {
98
- token = null;
99
- }
100
- }
101
- } else {
102
- token = null;
103
- }
104
- if (token) {
105
- offset = token.offset;
106
- } else {
107
- offset = 0;
108
- }
109
-
110
- if (offset !== position) {
111
- calculator.setPosition(offset);
112
- }
113
- })
114
- .on(nsHelper.namespaceAll('command-stepMoveRight', pluginName), function() {
115
- var expression = calculator.getExpression();
116
- var position = calculator.getPosition();
117
- var tokens = calculator.getTokens();
118
- var index = calculator.getTokenIndex();
119
- var token = calculator.getToken();
120
- var offset = expression.length;
121
-
122
- if (token && index < tokens.length - 1) {
123
- token = tokens[index + 1];
124
- if (token) {
125
- offset = token.offset;
126
- }
127
- }
128
-
129
- if (offset !== position) {
130
- calculator.setPosition(offset);
131
- }
132
- })
133
- .on(nsHelper.namespaceAll('command-stepDeleteLeft', pluginName), function() {
134
- var expression = calculator.getExpression();
135
- var position = calculator.getPosition();
136
- var tokens = calculator.getTokens();
137
- var index = calculator.getTokenIndex();
138
- var token = calculator.getToken();
139
-
140
- if (token) {
141
- if (position > token.offset) {
142
- removeToken(expression, token);
143
- } else {
144
- if (index > 0) {
145
- removeToken(expression, tokens[index - 1]);
146
- } else if (position > 0) {
147
- remove(expression, 0, token.offset);
148
- }
149
- }
150
- }
151
- })
152
- .on(nsHelper.namespaceAll('command-stepDeleteRight', pluginName), function() {
153
- var expression = calculator.getExpression();
154
- var position = calculator.getPosition();
155
- var token = calculator.getToken();
156
-
157
- if (token && position >= token.offset && position < token.offset + token.value.length) {
158
- removeToken(expression, token);
159
- }
160
- });
161
- },
162
-
163
- /**
164
- * Called when the plugin is destroyed. Mostly when the host is destroyed itself.
165
- */
166
- destroy: function destroy() {
167
- var calculator = this.getCalculator();
168
- calculator
169
- .deleteCommand('stepMoveLeft')
170
- .deleteCommand('stepMoveRight')
171
- .deleteCommand('stepDeleteLeft')
172
- .deleteCommand('stepDeleteRight')
173
- .off('.' + pluginName);
174
- }
175
- });
@@ -1,143 +0,0 @@
1
- /**
2
- * This program is free software; you can redistribute it and/or
3
- * modify it under the terms of the GNU General Public License
4
- * as published by the Free Software Foundation; under version 2
5
- * of the License (non-upgradable).
6
- *
7
- * This program is distributed in the hope that it will be useful,
8
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- * GNU General Public License for more details.
11
- *
12
- * You should have received a copy of the GNU General Public License
13
- * along with this program; if not, write to the Free Software
14
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15
- *
16
- * Copyright (c) 2019 Open Assessment Technologies SA ;
17
- */
18
- /**
19
- * Plugin that multiplies the current operand by 10^x.
20
- * @author Jean-Sébastien Conan <jean-sebastien@taotesting.com>
21
- */
22
-
23
- import __ from 'i18n';
24
- import nsHelper from 'util/namespace';
25
- import pluginFactory from 'ui/maths/calculator/core/plugin';
26
- import tokensHelper from 'ui/maths/calculator/core/tokens';
27
-
28
- var pluginName = 'pow10';
29
-
30
- /**
31
- * The basic `10^x` expression.
32
- * @type {String}
33
- */
34
- var termsPow10 = '10^';
35
-
36
- /**
37
- * The multiply by `10^x` expression.
38
- * @type {String}
39
- */
40
- var termsMulByPow10 = '*' + termsPow10;
41
-
42
- export default pluginFactory({
43
- name: pluginName,
44
-
45
- /**
46
- * Called when the plugin is installing in its host.
47
- */
48
- install: function install() {
49
- this.getCalculator().setCommand('pow10', __('Power of 10'), __('Multiply the value by 10^x'));
50
- },
51
-
52
- /**
53
- * Called when the plugin should be initialized.
54
- */
55
- init: function init() {
56
- var calculator = this.getCalculator();
57
-
58
- /**
59
- * Checks if the expression contains a space before the current position
60
- * @returns {Boolean}
61
- */
62
- function spaceBefore() {
63
- return calculator.getExpression().charAt(calculator.getPosition() - 1) === ' ';
64
- }
65
-
66
- /**
67
- * Checks if the token is considered as a separator
68
- * @param {token} token
69
- * @returns {Boolean}
70
- */
71
- function isSeparator(token) {
72
- return tokensHelper.isFunction(token) || (tokensHelper.isSeparator(token) && token.type !== 'RPAR');
73
- }
74
-
75
- // insert the sub-expression based on strategies
76
- calculator.on(nsHelper.namespaceAll('command-pow10', pluginName), function() {
77
- var position = calculator.getPosition();
78
- var tokens = calculator.getTokens();
79
- var index = calculator.getTokenIndex();
80
- var token = tokens[index] || null;
81
- var prevToken = tokens[index - 1] || null;
82
- var nextToken = tokens[index + 1] || null;
83
- var aligned = false;
84
- var expr = termsMulByPow10;
85
-
86
- if (token) {
87
- // refine the current position, as it should be either on the start or the end of the token:
88
- // "aligned" means the position is properly aligned with the token, said at the start of the value,
89
- // while not "aligned" means any other position inside the token
90
- aligned = token.offset === position;
91
- if (token.type === 'MUL') {
92
- if (aligned) {
93
- // the "multiply" operator is a special case, as it is part of the complete expression,
94
- // so if it is already there, we consider to use it, and move the position just after
95
- calculator.setPosition(position + token.value.length);
96
- aligned = false;
97
- }
98
- } else if (!aligned) {
99
- // the strategy is to consider the position is in front of the token,
100
- // the allowed exception is when the position is the last one
101
- if (nextToken || position < token.offset + token.value.length) {
102
- calculator.setPosition(token.offset);
103
- aligned = true;
104
- }
105
- }
106
- }
107
-
108
- // empty expression or 0, should be replaced by the shorter version
109
- if ((tokens.length <= 1 && !token) || token.type === 'NUM0') {
110
- calculator.replace(termsPow10);
111
- }
112
- // will insert expression at position:
113
- // - use the shorter version if there is no token before, or the previous one is either an operator
114
- // or a function
115
- // - user the longer version in any other cases
116
- else {
117
- if (aligned) {
118
- if (index === 0 || isSeparator(prevToken)) {
119
- expr = termsPow10;
120
- }
121
- } else if (isSeparator(token)) {
122
- expr = termsPow10;
123
-
124
- // the expression may need a space before if the previous token is a function
125
- if (tokensHelper.isFunction(token) && !spaceBefore()) {
126
- expr = ' ' + expr;
127
- }
128
- }
129
-
130
- calculator.insert(expr);
131
- }
132
- });
133
- },
134
-
135
- /**
136
- * Called when the plugin is destroyed. Mostly when the host is destroyed itself.
137
- */
138
- destroy: function destroy() {
139
- this.getCalculator()
140
- .deleteCommand('pow10')
141
- .off('.' + pluginName);
142
- }
143
- });
@@ -1,339 +0,0 @@
1
- /**
2
- * This program is free software; you can redistribute it and/or
3
- * modify it under the terms of the GNU General Public License
4
- * as published by the Free Software Foundation; under version 2
5
- * of the License (non-upgradable).
6
- *
7
- * This program is distributed in the hope that it will be useful,
8
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- * GNU General Public License for more details.
11
- *
12
- * You should have received a copy of the GNU General Public License
13
- * along with this program; if not, write to the Free Software
14
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15
- *
16
- * Copyright (c) 2019 Open Assessment Technologies SA ;
17
- */
18
- /**
19
- * Plugin that allows to change the sign of the current operand
20
- * @author Jean-Sébastien Conan <jean-sebastien@taotesting.com>
21
- */
22
- import _ from 'lodash';
23
- import __ from 'i18n';
24
- import nsHelper from 'util/namespace';
25
- import pluginFactory from 'ui/maths/calculator/core/plugin';
26
- import tokensHelper from 'ui/maths/calculator/core/tokens';
27
- import registeredTerms from 'ui/maths/calculator/core/terms';
28
-
29
- var pluginName = 'sign';
30
-
31
- /**
32
- * List of tokens that refuse explicit positive sign
33
- * @type {String[]}
34
- */
35
- var refuseExplicitPositive = ['LPAR', 'SUB', 'ADD', 'MUL', 'DIV', 'MOD', 'POW', 'ASSIGN'];
36
-
37
- /**
38
- * @typedef {Object} signChange
39
- * @property {String} sign - The sign to insert
40
- * @property {Number} offset - The offset where insert the sign
41
- * @property {Number} length - The length of text to replace
42
- * @property {Number} move - The move to apply on the current position
43
- */
44
-
45
- /**
46
- * List of known strategies to apply on an expression in order to process sign change.
47
- * Each strategy will return either `null` if cannot apply, or the descriptor of the change to apply.
48
- * @type {Function[]}
49
- */
50
- var strategies = [
51
- /**
52
- * Strategy that applies on numeric operands only
53
- * @param {Number} index - The index of the current token
54
- * @param {token[]} tokens - The list of tokens that represent the expression
55
- * @returns {signChange|null} - The result of the strategy: `null` if cannot apply, or the descriptor of the change
56
- */
57
- function strategyNumeric(index, tokens) {
58
- var token = tokens[index] || null;
59
- var type = tokensHelper.getType(token);
60
- var result = null;
61
-
62
- if (tokensHelper.isDigit(type) && index >= 0) {
63
- // find the first token on the left of the operand
64
- while (index && tokensHelper.isDigit(type)) {
65
- index--;
66
- token = tokens[index] || null;
67
- type = tokensHelper.getType(token);
68
- }
69
-
70
- if (tokensHelper.isDigit(type) && index === 0) {
71
- // the operand is the first of the expression, so the sign is implicit +, simply negate the value
72
- result = insertNegativeSign(token);
73
- } else {
74
- // the operand is preceded by something else
75
- result = applySignChange(index, tokens);
76
- }
77
- }
78
-
79
- return result;
80
- },
81
-
82
- /**
83
- * Strategy that applies on operators only
84
- * @param {Number} index - The index of the current token
85
- * @param {token[]} tokens - The list of tokens that represent the expression
86
- * @returns {signChange|null} - The result of the strategy: `null` if cannot apply, or the descriptor of the change
87
- */
88
- function strategyOperator(index, tokens) {
89
- var token = tokens[index] || null;
90
- var type = tokensHelper.getType(token);
91
- var result = null;
92
-
93
- if (tokensHelper.isOperator(type) && index >= 0) {
94
- if (token.type === 'SUB') {
95
- // the operator is -, simply replace it by +
96
- result = replaceByPositiveSign(token, index, tokens);
97
- } else if (token.type === 'ADD') {
98
- // the operator is +, simply replace it by -
99
- result = replaceByNegativeSign(token);
100
- } else if (token.type === 'FAC' && index > 0) {
101
- // the operator is !, need to identify the operand
102
- result = applyStrategies(index - 1, tokens);
103
- }
104
- }
105
-
106
- return result;
107
- },
108
-
109
- /**
110
- * Strategy that applies on identifiers only (constants, variables, functions)
111
- * @param {Number} index - The index of the current token
112
- * @param {token[]} tokens - The list of tokens that represent the expression
113
- * @returns {signChange|null} - The result of the strategy: `null` if cannot apply, or the descriptor of the change
114
- */
115
- function strategyIdentifier(index, tokens) {
116
- var token = tokens[index] || null;
117
- var type = tokensHelper.getType(token);
118
- var result = null;
119
-
120
- if (tokensHelper.isIdentifier(type) && index >= 0) {
121
- if (index === 0) {
122
- // the token is the first of the expression, so the sign is implicit +, simply negate the value
123
- result = insertNegativeSign(token);
124
- } else {
125
- // the token is preceded by something else
126
- result = applySignChange(index - 1, tokens);
127
- }
128
- }
129
-
130
- return result;
131
- },
132
-
133
- /**
134
- * Strategy that applies on sub-expression only
135
- * @param {Number} index - The index of the current token
136
- * @param {token[]} tokens - The list of tokens that represent the expression
137
- * @returns {signChange|null} - The result of the strategy: `null` if cannot apply, or the descriptor of the change
138
- */
139
- function strategyExpression(index, tokens) {
140
- var token = tokens[index] || null;
141
- var type = tokensHelper.getType(token);
142
- var result = null;
143
- var count = 0;
144
-
145
- if (tokensHelper.isAggregator(type) && index >= 0) {
146
- if (token.type === 'RPAR') {
147
- count++;
148
- }
149
-
150
- // find the opening parenthesis
151
- while (index && (token.type !== 'LPAR' || count)) {
152
- index--;
153
- token = tokens[index] || null;
154
-
155
- if (token.type === 'RPAR') {
156
- count++;
157
- }
158
- if (token.type === 'LPAR') {
159
- count--;
160
- }
161
- }
162
-
163
- if (!count && token.type === 'LPAR') {
164
- if (index === 0) {
165
- // the token is the first of the expression, so the sign is implicit +, simply negate the value
166
- result = insertNegativeSign(token);
167
- } else {
168
- // the token is preceded by something else
169
- result = applySignChange(index - 1, tokens);
170
- }
171
- }
172
- }
173
-
174
- return result;
175
- }
176
- ];
177
-
178
- /**
179
- * Apply strategies to produce a sign change descriptor
180
- * @param {Number} index - The index of the current token
181
- * @param {token[]} tokens - The list of tokens that represent the expression
182
- * @returns {signChange|null} - The result of the strategy: `null` if cannot apply, or the descriptor of the change
183
- */
184
- function applyStrategies(index, tokens) {
185
- var result = null;
186
-
187
- _.forEach(strategies, function(strategy) {
188
- result = strategy(index, tokens);
189
- return !result;
190
- });
191
-
192
- return result;
193
- }
194
-
195
- /**
196
- * Apply a sign change at the current index
197
- * @param {Number} index - The index of the current token
198
- * @param {token[]} tokens - The list of tokens that represent the expression
199
- * @returns {signChange|null} - The result of the strategy: `null` if cannot apply, or the descriptor of the change
200
- */
201
- function applySignChange(index, tokens) {
202
- var token = tokens[index] || null;
203
- var nextToken = tokens[index + 1] || null;
204
- var type = tokensHelper.getType(token);
205
- var result = null;
206
-
207
- if (token) {
208
- if (tokensHelper.isOperator(type)) {
209
- // an operator precedes the operand
210
- if (token.type === 'SUB') {
211
- // the operator is -, simply replace it by +
212
- result = replaceByPositiveSign(token, index, tokens);
213
- } else if (token.type === 'ADD') {
214
- // the operator is +, simply replace it by -
215
- result = replaceByNegativeSign(token);
216
- } else if (nextToken) {
217
- // the operator is not + or -, simply negate the value
218
- result = insertNegativeSign(nextToken);
219
- }
220
- } else if (nextToken && (tokensHelper.isFunction(type) || token.type === 'LPAR')) {
221
- // a function or a left parenthesis precedes the operand, simply negate the operand
222
- result = insertNegativeSign(nextToken);
223
- }
224
- }
225
-
226
- return result;
227
- }
228
-
229
- /**
230
- * Checks if a token accept an explicit positive sign on the right
231
- * @param {Object} token
232
- * @returns {Boolean}
233
- */
234
- function acceptExplicitPositive(token) {
235
- return (
236
- !token ||
237
- (refuseExplicitPositive.indexOf(token.type) === -1 && !tokensHelper.isFunction(tokensHelper.getType(token)))
238
- );
239
- }
240
-
241
- /**
242
- * Produces a descriptor to insert a negative sign
243
- * @param {token} token
244
- * @returns {signChange}
245
- */
246
- function insertNegativeSign(token) {
247
- return {
248
- offset: token.offset,
249
- length: 0,
250
- sign: registeredTerms.SUB.value,
251
- move: registeredTerms.SUB.value.length
252
- };
253
- }
254
-
255
- /**
256
- * Produces a descriptor to replace a sign by a negative sign
257
- * @param {token} token
258
- * @returns {signChange}
259
- */
260
- function replaceByNegativeSign(token) {
261
- return {
262
- offset: token.offset,
263
- length: token.value.length,
264
- sign: registeredTerms.SUB.value,
265
- move: registeredTerms.SUB.value.length - token.value.length
266
- };
267
- }
268
-
269
- /**
270
- * Produces a descriptor to replace a sign by a positive sign
271
- * @param {token} token
272
- * @param {Number} index
273
- * @param {token[]} tokens
274
- * @returns {signChange}
275
- */
276
- function replaceByPositiveSign(token, index, tokens) {
277
- var allowExplicit = index && acceptExplicitPositive(tokens[index - 1]);
278
- return {
279
- offset: token.offset,
280
- length: token.value.length,
281
- sign: allowExplicit ? registeredTerms.ADD.value : '',
282
- move: (allowExplicit ? registeredTerms.ADD.value.length : 0) - token.value.length
283
- };
284
- }
285
-
286
- /**
287
- * Replaces text at position
288
- * @param {String} str - The string in which apply the replacement
289
- * @param {Number} index - The index from which applying the replacement
290
- * @param {Number} length - The length of the string to replace
291
- * @param {String} sub - The replacement string
292
- * @returns {String}
293
- */
294
- function splice(str, index, length, sub) {
295
- return str.substring(0, index) + sub + str.substring(index + length);
296
- }
297
-
298
- export default pluginFactory({
299
- name: pluginName,
300
-
301
- /**
302
- * Called when the plugin is installing in its host.
303
- */
304
- install: function install() {
305
- var calculator = this.getCalculator();
306
- calculator.setCommand('sign', __('Sign change'), __('Change the sign of the current operand'));
307
- },
308
-
309
- /**
310
- * Called when the plugin should be initialized.
311
- */
312
- init: function init() {
313
- var calculator = this.getCalculator();
314
-
315
- // applies a sign change based on strategies
316
- calculator.on(nsHelper.namespaceAll('command-sign', pluginName), function() {
317
- var tokens = calculator.getTokens();
318
- var index = calculator.getTokenIndex();
319
- var expression = calculator.getExpression();
320
- var result;
321
-
322
- if (expression !== '0') {
323
- result = applyStrategies(index, tokens);
324
- if (result) {
325
- expression = splice(expression, result.offset, result.length, result.sign);
326
- calculator.replace(expression, calculator.getPosition() + result.move);
327
- }
328
- }
329
- });
330
- },
331
-
332
- /**
333
- * Called when the plugin is destroyed. Mostly when the host is destroyed itself.
334
- */
335
- destroy: function destroy() {
336
- var calculator = this.getCalculator();
337
- calculator.deleteCommand('sign').off('.' + pluginName);
338
- }
339
- });