@oat-sa/tao-core-ui 1.67.0 → 1.69.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.
- package/dist/ckeditor/ckConfigurator.js +10 -1
- package/dist/maths/calculator/basicCalculator.js +4 -4
- package/dist/maths/calculator/calculatorComponent.js +22 -25
- package/dist/maths/calculator/core/board.js +12329 -720
- package/dist/maths/calculator/core/labels.js +7924 -138
- package/dist/maths/calculator/core/plugin.js +4 -5
- package/dist/maths/calculator/css/calculator.css +18 -5
- package/dist/maths/calculator/css/calculator.css.map +1 -1
- package/dist/maths/calculator/defaultCalculator.js +10 -6
- package/dist/maths/calculator/plugins/keyboard/templateKeyboard/templateKeyboard.js +23 -25
- package/dist/maths/calculator/plugins/screen/simpleScreen/simpleScreen.js +7979 -194
- package/dist/maths/calculator/scientificCalculator.js +7 -12
- package/package.json +5 -7
- package/src/ckeditor/ckConfigurator.js +11 -4
- package/src/maths/calculator/basicCalculator.js +1 -4
- package/src/maths/calculator/calculatorComponent.js +49 -60
- package/src/maths/calculator/core/board.js +372 -493
- package/src/maths/calculator/core/labels.js +46 -48
- package/src/maths/calculator/core/plugin.js +3 -5
- package/src/maths/calculator/core/tpl/terms.tpl +7 -1
- package/src/maths/calculator/css/calculator.css +18 -5
- package/src/maths/calculator/css/calculator.css.map +1 -1
- package/src/maths/calculator/defaultCalculator.js +7 -9
- package/src/maths/calculator/plugins/keyboard/templateKeyboard/defaultTemplate.tpl +3 -3
- package/src/maths/calculator/plugins/keyboard/templateKeyboard/templateKeyboard.js +17 -20
- package/src/maths/calculator/plugins/screen/simpleScreen/simpleScreen.js +102 -108
- package/src/maths/calculator/scientificCalculator.js +2 -10
- package/src/maths/calculator/scss/calculator.scss +14 -1
- package/src/maths/calculator/tpl/basicKeyboard.tpl +3 -3
- package/src/maths/calculator/tpl/scientificKeyboard.tpl +4 -4
- package/dist/maths/calculator/core/areaBroker.js +0 -43
- package/dist/maths/calculator/core/expression.js +0 -463
- package/dist/maths/calculator/core/terms.js +0 -456
- package/dist/maths/calculator/core/tokenizer.js +0 -229
- package/dist/maths/calculator/core/tokens.js +0 -167
- package/dist/maths/calculator/plugins/core/degrad.js +0 -71
- package/dist/maths/calculator/plugins/core/history.js +0 -149
- package/dist/maths/calculator/plugins/core/remind.js +0 -76
- package/dist/maths/calculator/plugins/core/stepNavigation.js +0 -148
- package/dist/maths/calculator/plugins/modifiers/pow10.js +0 -136
- package/dist/maths/calculator/plugins/modifiers/sign.js +0 -314
- package/dist/maths/calculator/pluginsLoader.js +0 -47
- package/src/maths/calculator/core/areaBroker.js +0 -38
- package/src/maths/calculator/core/expression.js +0 -430
- package/src/maths/calculator/core/terms.js +0 -459
- package/src/maths/calculator/core/tokenizer.js +0 -245
- package/src/maths/calculator/core/tokens.js +0 -178
- package/src/maths/calculator/plugins/core/degrad.js +0 -90
- package/src/maths/calculator/plugins/core/history.js +0 -166
- package/src/maths/calculator/plugins/core/remind.js +0 -96
- package/src/maths/calculator/plugins/core/stepNavigation.js +0 -175
- package/src/maths/calculator/plugins/modifiers/pow10.js +0 -143
- package/src/maths/calculator/plugins/modifiers/sign.js +0 -339
- package/src/maths/calculator/pluginsLoader.js +0 -46
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
define(['i18n', 'util/namespace', 'ui/maths/calculator/core/plugin', 'ui/maths/calculator/core/tokens'], function (__, nsHelper, pluginFactory, tokensHelper) { 'use strict';
|
|
2
|
-
|
|
3
|
-
__ = __ && Object.prototype.hasOwnProperty.call(__, 'default') ? __['default'] : __;
|
|
4
|
-
nsHelper = nsHelper && Object.prototype.hasOwnProperty.call(nsHelper, 'default') ? nsHelper['default'] : nsHelper;
|
|
5
|
-
pluginFactory = pluginFactory && Object.prototype.hasOwnProperty.call(pluginFactory, 'default') ? pluginFactory['default'] : pluginFactory;
|
|
6
|
-
tokensHelper = tokensHelper && Object.prototype.hasOwnProperty.call(tokensHelper, 'default') ? tokensHelper['default'] : tokensHelper;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* This program is free software; you can redistribute it and/or
|
|
10
|
-
* modify it under the terms of the GNU General Public License
|
|
11
|
-
* as published by the Free Software Foundation; under version 2
|
|
12
|
-
* of the License (non-upgradable).
|
|
13
|
-
*
|
|
14
|
-
* This program is distributed in the hope that it will be useful,
|
|
15
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
-
* GNU General Public License for more details.
|
|
18
|
-
*
|
|
19
|
-
* You should have received a copy of the GNU General Public License
|
|
20
|
-
* along with this program; if not, write to the Free Software
|
|
21
|
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
22
|
-
*
|
|
23
|
-
* Copyright (c) 2019 Open Assessment Technologies SA ;
|
|
24
|
-
*/
|
|
25
|
-
var pluginName = 'pow10';
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* The basic `10^x` expression.
|
|
29
|
-
* @type {String}
|
|
30
|
-
*/
|
|
31
|
-
var termsPow10 = '10^';
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* The multiply by `10^x` expression.
|
|
35
|
-
* @type {String}
|
|
36
|
-
*/
|
|
37
|
-
var termsMulByPow10 = '*' + termsPow10;
|
|
38
|
-
var pow10 = pluginFactory({
|
|
39
|
-
name: pluginName,
|
|
40
|
-
/**
|
|
41
|
-
* Called when the plugin is installing in its host.
|
|
42
|
-
*/
|
|
43
|
-
install: function install() {
|
|
44
|
-
this.getCalculator().setCommand('pow10', __('Power of 10'), __('Multiply the value by 10^x'));
|
|
45
|
-
},
|
|
46
|
-
/**
|
|
47
|
-
* Called when the plugin should be initialized.
|
|
48
|
-
*/
|
|
49
|
-
init: function init() {
|
|
50
|
-
var calculator = this.getCalculator();
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Checks if the expression contains a space before the current position
|
|
54
|
-
* @returns {Boolean}
|
|
55
|
-
*/
|
|
56
|
-
function spaceBefore() {
|
|
57
|
-
return calculator.getExpression().charAt(calculator.getPosition() - 1) === ' ';
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Checks if the token is considered as a separator
|
|
62
|
-
* @param {token} token
|
|
63
|
-
* @returns {Boolean}
|
|
64
|
-
*/
|
|
65
|
-
function isSeparator(token) {
|
|
66
|
-
return tokensHelper.isFunction(token) || tokensHelper.isSeparator(token) && token.type !== 'RPAR';
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// insert the sub-expression based on strategies
|
|
70
|
-
calculator.on(nsHelper.namespaceAll('command-pow10', pluginName), function () {
|
|
71
|
-
var position = calculator.getPosition();
|
|
72
|
-
var tokens = calculator.getTokens();
|
|
73
|
-
var index = calculator.getTokenIndex();
|
|
74
|
-
var token = tokens[index] || null;
|
|
75
|
-
var prevToken = tokens[index - 1] || null;
|
|
76
|
-
var nextToken = tokens[index + 1] || null;
|
|
77
|
-
var aligned = false;
|
|
78
|
-
var expr = termsMulByPow10;
|
|
79
|
-
if (token) {
|
|
80
|
-
// refine the current position, as it should be either on the start or the end of the token:
|
|
81
|
-
// "aligned" means the position is properly aligned with the token, said at the start of the value,
|
|
82
|
-
// while not "aligned" means any other position inside the token
|
|
83
|
-
aligned = token.offset === position;
|
|
84
|
-
if (token.type === 'MUL') {
|
|
85
|
-
if (aligned) {
|
|
86
|
-
// the "multiply" operator is a special case, as it is part of the complete expression,
|
|
87
|
-
// so if it is already there, we consider to use it, and move the position just after
|
|
88
|
-
calculator.setPosition(position + token.value.length);
|
|
89
|
-
aligned = false;
|
|
90
|
-
}
|
|
91
|
-
} else if (!aligned) {
|
|
92
|
-
// the strategy is to consider the position is in front of the token,
|
|
93
|
-
// the allowed exception is when the position is the last one
|
|
94
|
-
if (nextToken || position < token.offset + token.value.length) {
|
|
95
|
-
calculator.setPosition(token.offset);
|
|
96
|
-
aligned = true;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// empty expression or 0, should be replaced by the shorter version
|
|
102
|
-
if (tokens.length <= 1 && !token || token.type === 'NUM0') {
|
|
103
|
-
calculator.replace(termsPow10);
|
|
104
|
-
}
|
|
105
|
-
// will insert expression at position:
|
|
106
|
-
// - use the shorter version if there is no token before, or the previous one is either an operator
|
|
107
|
-
// or a function
|
|
108
|
-
// - user the longer version in any other cases
|
|
109
|
-
else {
|
|
110
|
-
if (aligned) {
|
|
111
|
-
if (index === 0 || isSeparator(prevToken)) {
|
|
112
|
-
expr = termsPow10;
|
|
113
|
-
}
|
|
114
|
-
} else if (isSeparator(token)) {
|
|
115
|
-
expr = termsPow10;
|
|
116
|
-
|
|
117
|
-
// the expression may need a space before if the previous token is a function
|
|
118
|
-
if (tokensHelper.isFunction(token) && !spaceBefore()) {
|
|
119
|
-
expr = ' ' + expr;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
calculator.insert(expr);
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
},
|
|
126
|
-
/**
|
|
127
|
-
* Called when the plugin is destroyed. Mostly when the host is destroyed itself.
|
|
128
|
-
*/
|
|
129
|
-
destroy: function destroy() {
|
|
130
|
-
this.getCalculator().deleteCommand('pow10').off('.' + pluginName);
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
return pow10;
|
|
135
|
-
|
|
136
|
-
});
|
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
define(['lodash', 'i18n', 'util/namespace', 'ui/maths/calculator/core/plugin', 'ui/maths/calculator/core/tokens', 'ui/maths/calculator/core/terms'], function (_, __, nsHelper, pluginFactory, tokensHelper, registeredTerms) { 'use strict';
|
|
2
|
-
|
|
3
|
-
_ = _ && Object.prototype.hasOwnProperty.call(_, 'default') ? _['default'] : _;
|
|
4
|
-
__ = __ && Object.prototype.hasOwnProperty.call(__, 'default') ? __['default'] : __;
|
|
5
|
-
nsHelper = nsHelper && Object.prototype.hasOwnProperty.call(nsHelper, 'default') ? nsHelper['default'] : nsHelper;
|
|
6
|
-
pluginFactory = pluginFactory && Object.prototype.hasOwnProperty.call(pluginFactory, 'default') ? pluginFactory['default'] : pluginFactory;
|
|
7
|
-
tokensHelper = tokensHelper && Object.prototype.hasOwnProperty.call(tokensHelper, 'default') ? tokensHelper['default'] : tokensHelper;
|
|
8
|
-
registeredTerms = registeredTerms && Object.prototype.hasOwnProperty.call(registeredTerms, 'default') ? registeredTerms['default'] : registeredTerms;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* This program is free software; you can redistribute it and/or
|
|
12
|
-
* modify it under the terms of the GNU General Public License
|
|
13
|
-
* as published by the Free Software Foundation; under version 2
|
|
14
|
-
* of the License (non-upgradable).
|
|
15
|
-
*
|
|
16
|
-
* This program is distributed in the hope that it will be useful,
|
|
17
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
-
* GNU General Public License for more details.
|
|
20
|
-
*
|
|
21
|
-
* You should have received a copy of the GNU General Public License
|
|
22
|
-
* along with this program; if not, write to the Free Software
|
|
23
|
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
24
|
-
*
|
|
25
|
-
* Copyright (c) 2019 Open Assessment Technologies SA ;
|
|
26
|
-
*/
|
|
27
|
-
var pluginName = 'sign';
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* List of tokens that refuse explicit positive sign
|
|
31
|
-
* @type {String[]}
|
|
32
|
-
*/
|
|
33
|
-
var refuseExplicitPositive = ['LPAR', 'SUB', 'ADD', 'MUL', 'DIV', 'MOD', 'POW', 'ASSIGN'];
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @typedef {Object} signChange
|
|
37
|
-
* @property {String} sign - The sign to insert
|
|
38
|
-
* @property {Number} offset - The offset where insert the sign
|
|
39
|
-
* @property {Number} length - The length of text to replace
|
|
40
|
-
* @property {Number} move - The move to apply on the current position
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* List of known strategies to apply on an expression in order to process sign change.
|
|
45
|
-
* Each strategy will return either `null` if cannot apply, or the descriptor of the change to apply.
|
|
46
|
-
* @type {Function[]}
|
|
47
|
-
*/
|
|
48
|
-
var strategies = [
|
|
49
|
-
/**
|
|
50
|
-
* Strategy that applies on numeric operands only
|
|
51
|
-
* @param {Number} index - The index of the current token
|
|
52
|
-
* @param {token[]} tokens - The list of tokens that represent the expression
|
|
53
|
-
* @returns {signChange|null} - The result of the strategy: `null` if cannot apply, or the descriptor of the change
|
|
54
|
-
*/
|
|
55
|
-
function strategyNumeric(index, tokens) {
|
|
56
|
-
var token = tokens[index] || null;
|
|
57
|
-
var type = tokensHelper.getType(token);
|
|
58
|
-
var result = null;
|
|
59
|
-
if (tokensHelper.isDigit(type) && index >= 0) {
|
|
60
|
-
// find the first token on the left of the operand
|
|
61
|
-
while (index && tokensHelper.isDigit(type)) {
|
|
62
|
-
index--;
|
|
63
|
-
token = tokens[index] || null;
|
|
64
|
-
type = tokensHelper.getType(token);
|
|
65
|
-
}
|
|
66
|
-
if (tokensHelper.isDigit(type) && index === 0) {
|
|
67
|
-
// the operand is the first of the expression, so the sign is implicit +, simply negate the value
|
|
68
|
-
result = insertNegativeSign(token);
|
|
69
|
-
} else {
|
|
70
|
-
// the operand is preceded by something else
|
|
71
|
-
result = applySignChange(index, tokens);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return result;
|
|
75
|
-
},
|
|
76
|
-
/**
|
|
77
|
-
* Strategy that applies on operators only
|
|
78
|
-
* @param {Number} index - The index of the current token
|
|
79
|
-
* @param {token[]} tokens - The list of tokens that represent the expression
|
|
80
|
-
* @returns {signChange|null} - The result of the strategy: `null` if cannot apply, or the descriptor of the change
|
|
81
|
-
*/
|
|
82
|
-
function strategyOperator(index, tokens) {
|
|
83
|
-
var token = tokens[index] || null;
|
|
84
|
-
var type = tokensHelper.getType(token);
|
|
85
|
-
var result = null;
|
|
86
|
-
if (tokensHelper.isOperator(type) && index >= 0) {
|
|
87
|
-
if (token.type === 'SUB') {
|
|
88
|
-
// the operator is -, simply replace it by +
|
|
89
|
-
result = replaceByPositiveSign(token, index, tokens);
|
|
90
|
-
} else if (token.type === 'ADD') {
|
|
91
|
-
// the operator is +, simply replace it by -
|
|
92
|
-
result = replaceByNegativeSign(token);
|
|
93
|
-
} else if (token.type === 'FAC' && index > 0) {
|
|
94
|
-
// the operator is !, need to identify the operand
|
|
95
|
-
result = applyStrategies(index - 1, tokens);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return result;
|
|
99
|
-
},
|
|
100
|
-
/**
|
|
101
|
-
* Strategy that applies on identifiers only (constants, variables, functions)
|
|
102
|
-
* @param {Number} index - The index of the current token
|
|
103
|
-
* @param {token[]} tokens - The list of tokens that represent the expression
|
|
104
|
-
* @returns {signChange|null} - The result of the strategy: `null` if cannot apply, or the descriptor of the change
|
|
105
|
-
*/
|
|
106
|
-
function strategyIdentifier(index, tokens) {
|
|
107
|
-
var token = tokens[index] || null;
|
|
108
|
-
var type = tokensHelper.getType(token);
|
|
109
|
-
var result = null;
|
|
110
|
-
if (tokensHelper.isIdentifier(type) && index >= 0) {
|
|
111
|
-
if (index === 0) {
|
|
112
|
-
// the token is the first of the expression, so the sign is implicit +, simply negate the value
|
|
113
|
-
result = insertNegativeSign(token);
|
|
114
|
-
} else {
|
|
115
|
-
// the token is preceded by something else
|
|
116
|
-
result = applySignChange(index - 1, tokens);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return result;
|
|
120
|
-
},
|
|
121
|
-
/**
|
|
122
|
-
* Strategy that applies on sub-expression only
|
|
123
|
-
* @param {Number} index - The index of the current token
|
|
124
|
-
* @param {token[]} tokens - The list of tokens that represent the expression
|
|
125
|
-
* @returns {signChange|null} - The result of the strategy: `null` if cannot apply, or the descriptor of the change
|
|
126
|
-
*/
|
|
127
|
-
function strategyExpression(index, tokens) {
|
|
128
|
-
var token = tokens[index] || null;
|
|
129
|
-
var type = tokensHelper.getType(token);
|
|
130
|
-
var result = null;
|
|
131
|
-
var count = 0;
|
|
132
|
-
if (tokensHelper.isAggregator(type) && index >= 0) {
|
|
133
|
-
if (token.type === 'RPAR') {
|
|
134
|
-
count++;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// find the opening parenthesis
|
|
138
|
-
while (index && (token.type !== 'LPAR' || count)) {
|
|
139
|
-
index--;
|
|
140
|
-
token = tokens[index] || null;
|
|
141
|
-
if (token.type === 'RPAR') {
|
|
142
|
-
count++;
|
|
143
|
-
}
|
|
144
|
-
if (token.type === 'LPAR') {
|
|
145
|
-
count--;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (!count && token.type === 'LPAR') {
|
|
149
|
-
if (index === 0) {
|
|
150
|
-
// the token is the first of the expression, so the sign is implicit +, simply negate the value
|
|
151
|
-
result = insertNegativeSign(token);
|
|
152
|
-
} else {
|
|
153
|
-
// the token is preceded by something else
|
|
154
|
-
result = applySignChange(index - 1, tokens);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return result;
|
|
159
|
-
}];
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Apply strategies to produce a sign change descriptor
|
|
163
|
-
* @param {Number} index - The index of the current token
|
|
164
|
-
* @param {token[]} tokens - The list of tokens that represent the expression
|
|
165
|
-
* @returns {signChange|null} - The result of the strategy: `null` if cannot apply, or the descriptor of the change
|
|
166
|
-
*/
|
|
167
|
-
function applyStrategies(index, tokens) {
|
|
168
|
-
var result = null;
|
|
169
|
-
_.forEach(strategies, function (strategy) {
|
|
170
|
-
result = strategy(index, tokens);
|
|
171
|
-
return !result;
|
|
172
|
-
});
|
|
173
|
-
return result;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Apply a sign change at the current index
|
|
178
|
-
* @param {Number} index - The index of the current token
|
|
179
|
-
* @param {token[]} tokens - The list of tokens that represent the expression
|
|
180
|
-
* @returns {signChange|null} - The result of the strategy: `null` if cannot apply, or the descriptor of the change
|
|
181
|
-
*/
|
|
182
|
-
function applySignChange(index, tokens) {
|
|
183
|
-
var token = tokens[index] || null;
|
|
184
|
-
var nextToken = tokens[index + 1] || null;
|
|
185
|
-
var type = tokensHelper.getType(token);
|
|
186
|
-
var result = null;
|
|
187
|
-
if (token) {
|
|
188
|
-
if (tokensHelper.isOperator(type)) {
|
|
189
|
-
// an operator precedes the operand
|
|
190
|
-
if (token.type === 'SUB') {
|
|
191
|
-
// the operator is -, simply replace it by +
|
|
192
|
-
result = replaceByPositiveSign(token, index, tokens);
|
|
193
|
-
} else if (token.type === 'ADD') {
|
|
194
|
-
// the operator is +, simply replace it by -
|
|
195
|
-
result = replaceByNegativeSign(token);
|
|
196
|
-
} else if (nextToken) {
|
|
197
|
-
// the operator is not + or -, simply negate the value
|
|
198
|
-
result = insertNegativeSign(nextToken);
|
|
199
|
-
}
|
|
200
|
-
} else if (nextToken && (tokensHelper.isFunction(type) || token.type === 'LPAR')) {
|
|
201
|
-
// a function or a left parenthesis precedes the operand, simply negate the operand
|
|
202
|
-
result = insertNegativeSign(nextToken);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return result;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Checks if a token accept an explicit positive sign on the right
|
|
210
|
-
* @param {Object} token
|
|
211
|
-
* @returns {Boolean}
|
|
212
|
-
*/
|
|
213
|
-
function acceptExplicitPositive(token) {
|
|
214
|
-
return !token || refuseExplicitPositive.indexOf(token.type) === -1 && !tokensHelper.isFunction(tokensHelper.getType(token));
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Produces a descriptor to insert a negative sign
|
|
219
|
-
* @param {token} token
|
|
220
|
-
* @returns {signChange}
|
|
221
|
-
*/
|
|
222
|
-
function insertNegativeSign(token) {
|
|
223
|
-
return {
|
|
224
|
-
offset: token.offset,
|
|
225
|
-
length: 0,
|
|
226
|
-
sign: registeredTerms.SUB.value,
|
|
227
|
-
move: registeredTerms.SUB.value.length
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Produces a descriptor to replace a sign by a negative sign
|
|
233
|
-
* @param {token} token
|
|
234
|
-
* @returns {signChange}
|
|
235
|
-
*/
|
|
236
|
-
function replaceByNegativeSign(token) {
|
|
237
|
-
return {
|
|
238
|
-
offset: token.offset,
|
|
239
|
-
length: token.value.length,
|
|
240
|
-
sign: registeredTerms.SUB.value,
|
|
241
|
-
move: registeredTerms.SUB.value.length - token.value.length
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Produces a descriptor to replace a sign by a positive sign
|
|
247
|
-
* @param {token} token
|
|
248
|
-
* @param {Number} index
|
|
249
|
-
* @param {token[]} tokens
|
|
250
|
-
* @returns {signChange}
|
|
251
|
-
*/
|
|
252
|
-
function replaceByPositiveSign(token, index, tokens) {
|
|
253
|
-
var allowExplicit = index && acceptExplicitPositive(tokens[index - 1]);
|
|
254
|
-
return {
|
|
255
|
-
offset: token.offset,
|
|
256
|
-
length: token.value.length,
|
|
257
|
-
sign: allowExplicit ? registeredTerms.ADD.value : '',
|
|
258
|
-
move: (allowExplicit ? registeredTerms.ADD.value.length : 0) - token.value.length
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Replaces text at position
|
|
264
|
-
* @param {String} str - The string in which apply the replacement
|
|
265
|
-
* @param {Number} index - The index from which applying the replacement
|
|
266
|
-
* @param {Number} length - The length of the string to replace
|
|
267
|
-
* @param {String} sub - The replacement string
|
|
268
|
-
* @returns {String}
|
|
269
|
-
*/
|
|
270
|
-
function splice(str, index, length, sub) {
|
|
271
|
-
return str.substring(0, index) + sub + str.substring(index + length);
|
|
272
|
-
}
|
|
273
|
-
var sign = pluginFactory({
|
|
274
|
-
name: pluginName,
|
|
275
|
-
/**
|
|
276
|
-
* Called when the plugin is installing in its host.
|
|
277
|
-
*/
|
|
278
|
-
install: function install() {
|
|
279
|
-
var calculator = this.getCalculator();
|
|
280
|
-
calculator.setCommand('sign', __('Sign change'), __('Change the sign of the current operand'));
|
|
281
|
-
},
|
|
282
|
-
/**
|
|
283
|
-
* Called when the plugin should be initialized.
|
|
284
|
-
*/
|
|
285
|
-
init: function init() {
|
|
286
|
-
var calculator = this.getCalculator();
|
|
287
|
-
|
|
288
|
-
// applies a sign change based on strategies
|
|
289
|
-
calculator.on(nsHelper.namespaceAll('command-sign', pluginName), function () {
|
|
290
|
-
var tokens = calculator.getTokens();
|
|
291
|
-
var index = calculator.getTokenIndex();
|
|
292
|
-
var expression = calculator.getExpression();
|
|
293
|
-
var result;
|
|
294
|
-
if (expression !== '0') {
|
|
295
|
-
result = applyStrategies(index, tokens);
|
|
296
|
-
if (result) {
|
|
297
|
-
expression = splice(expression, result.offset, result.length, result.sign);
|
|
298
|
-
calculator.replace(expression, calculator.getPosition() + result.move);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
},
|
|
303
|
-
/**
|
|
304
|
-
* Called when the plugin is destroyed. Mostly when the host is destroyed itself.
|
|
305
|
-
*/
|
|
306
|
-
destroy: function destroy() {
|
|
307
|
-
var calculator = this.getCalculator();
|
|
308
|
-
calculator.deleteCommand('sign').off('.' + pluginName);
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
return sign;
|
|
313
|
-
|
|
314
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
define(['context', 'core/pluginLoader', 'ui/maths/calculator/plugins/core/degrad', 'ui/maths/calculator/plugins/core/history', 'ui/maths/calculator/plugins/core/remind', 'ui/maths/calculator/plugins/core/stepNavigation', 'lodash'], function (context, pluginLoaderFactory, pluginDegradFactory, pluginHistoryFactory, pluginRemindFactory, pluginStepNavigationFactory, _) { 'use strict';
|
|
2
|
-
|
|
3
|
-
context = context && Object.prototype.hasOwnProperty.call(context, 'default') ? context['default'] : context;
|
|
4
|
-
pluginLoaderFactory = pluginLoaderFactory && Object.prototype.hasOwnProperty.call(pluginLoaderFactory, 'default') ? pluginLoaderFactory['default'] : pluginLoaderFactory;
|
|
5
|
-
pluginDegradFactory = pluginDegradFactory && Object.prototype.hasOwnProperty.call(pluginDegradFactory, 'default') ? pluginDegradFactory['default'] : pluginDegradFactory;
|
|
6
|
-
pluginHistoryFactory = pluginHistoryFactory && Object.prototype.hasOwnProperty.call(pluginHistoryFactory, 'default') ? pluginHistoryFactory['default'] : pluginHistoryFactory;
|
|
7
|
-
pluginRemindFactory = pluginRemindFactory && Object.prototype.hasOwnProperty.call(pluginRemindFactory, 'default') ? pluginRemindFactory['default'] : pluginRemindFactory;
|
|
8
|
-
pluginStepNavigationFactory = pluginStepNavigationFactory && Object.prototype.hasOwnProperty.call(pluginStepNavigationFactory, 'default') ? pluginStepNavigationFactory['default'] : pluginStepNavigationFactory;
|
|
9
|
-
_ = _ && Object.prototype.hasOwnProperty.call(_, 'default') ? _['default'] : _;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* This program is free software; you can redistribute it and/or
|
|
13
|
-
* modify it under the terms of the GNU General Public License
|
|
14
|
-
* as published by the Free Software Foundation; under version 2
|
|
15
|
-
* of the License (non-upgradable).
|
|
16
|
-
*
|
|
17
|
-
* This program is distributed in the hope that it will be useful,
|
|
18
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20
|
-
* GNU General Public License for more details.
|
|
21
|
-
*
|
|
22
|
-
* You should have received a copy of the GNU General Public License
|
|
23
|
-
* along with this program; if not, write to the Free Software
|
|
24
|
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
25
|
-
*
|
|
26
|
-
* Copyright (c) 2018 Open Assessment Technologies SA ;
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Load the plugins dynamically
|
|
31
|
-
* @param {Object} loadedPlugins - a collection of already loaded plugins
|
|
32
|
-
* @param {Object} dynamicPlugins - a collection of plugins to load
|
|
33
|
-
* @returns {Promise} resolves with the list of loaded plugins
|
|
34
|
-
*/
|
|
35
|
-
function loadPlugins(loadedPlugins, dynamicPlugins) {
|
|
36
|
-
// The list of default plugins is directly built here instead of using a module variable to ensure the object
|
|
37
|
-
// is unique to the instance. This wil avoid global polluting by successive instances, as nested objects and
|
|
38
|
-
// arrays might be simply copied.
|
|
39
|
-
var defaultPlugins = {
|
|
40
|
-
core: [pluginDegradFactory, pluginHistoryFactory, pluginRemindFactory, pluginStepNavigationFactory]
|
|
41
|
-
};
|
|
42
|
-
return pluginLoaderFactory(_.merge({}, defaultPlugins, loadedPlugins)).addList(dynamicPlugins).load(context.bundle);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return loadPlugins;
|
|
46
|
-
|
|
47
|
-
});
|
|
@@ -1,38 +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 (original work) Open Assessment Technologies SA ;
|
|
17
|
-
*/
|
|
18
|
-
/**
|
|
19
|
-
* @author Jean-Sébastien Conan <jean-sebastien@taotesting.com>
|
|
20
|
-
*/
|
|
21
|
-
import _ from 'lodash';
|
|
22
|
-
import areaBroker from 'ui/areaBroker';
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Creates an area broker with the required areas for the calculator panel.
|
|
26
|
-
*
|
|
27
|
-
* @see ui/areaBroker
|
|
28
|
-
*
|
|
29
|
-
* @param {jQuery|HTMLElement|String} $container - the main container
|
|
30
|
-
* @param {Object} mapping - keys are the area names, values are jQueryElement
|
|
31
|
-
* @returns {broker} the broker
|
|
32
|
-
* @throws {TypeError} without a valid container
|
|
33
|
-
*/
|
|
34
|
-
export default _.partial(areaBroker, [
|
|
35
|
-
'screen', // where the expressions and their result are rendered
|
|
36
|
-
'input', // where the expressions are input
|
|
37
|
-
'keyboard' // the keyboard area that should provide a way to interact with the calculator
|
|
38
|
-
]);
|