kokopu-react 1.3.1 → 1.5.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/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/dist/lib/ArrowMarkerIcon.js +5 -7
- package/dist/lib/Chessboard.js +23 -33
- package/dist/lib/ErrorBox.js +85 -5
- package/dist/lib/Movetext.js +839 -0
- package/dist/lib/SquareMarkerIcon.js +1 -1
- package/dist/lib/TextMarkerIcon.js +12 -11
- package/dist/lib/css/arrow.css +1 -1
- package/dist/lib/css/chessboard.css +6 -1
- package/dist/lib/css/error_box.css +13 -2
- package/dist/lib/css/fonts.css +34 -0
- package/dist/lib/css/movetext.css +117 -0
- package/dist/lib/css/{label.css → symbol.css} +6 -2
- package/dist/lib/fonts/chessalpha.woff +0 -0
- package/dist/lib/fonts/chessalpha.woff2 +0 -0
- package/dist/lib/i18n.js +17 -2
- package/dist/lib/impl/ArrowTip.js +3 -8
- package/dist/lib/impl/HtmlSanitizer.js +171 -0
- package/dist/lib/impl/TextSymbol.js +98 -0
- package/dist/lib/impl/colorsets.js +1 -1
- package/dist/lib/impl/piecesets.js +1 -1
- package/dist/lib/impl/util.js +6 -6
- package/dist/lib/index.js +32 -24
- package/dist/lib/markers.js +10 -10
- package/doc_src/demo/PageChessboardBase.js +1 -1
- package/doc_src/demo/{PageChessboardEdition.js → PageChessboardInteraction.js} +4 -5
- package/doc_src/demo/PageChessboardMove.js +1 -1
- package/doc_src/demo/PageChessboardSmallScreens.js +1 -1
- package/doc_src/demo/PageMovetextBase.js +214 -0
- package/doc_src/demo/PageMovetextInteraction.js +155 -0
- package/doc_src/demo/demo.css +8 -1
- package/doc_src/demo/game-1.pgn +23 -0
- package/doc_src/demo/game-2.pgn +22 -0
- package/doc_src/demo/game-invalid.pgn +10 -0
- package/doc_src/demo/util.js +1 -1
- package/doc_src/examples/Movetext.md +15 -0
- package/doc_src/home.md +2 -0
- package/doc_src/theming/LogoRenderer.js +1 -1
- package/doc_src/theming/kokopu-react-favicon.png +0 -0
- package/doc_src/theming/theming.css +1 -1
- package/graphic_test_app/01_marker_icons.js +6 -4
- package/graphic_test_app/02_chessboard_simple.js +1 -1
- package/graphic_test_app/03_chessboard_flipped.js +1 -1
- package/graphic_test_app/04_chessboard_annotations.js +2 -2
- package/graphic_test_app/05_chessboard_move.js +1 -1
- package/graphic_test_app/06_chessboard_theme.js +1 -1
- package/graphic_test_app/07_chessboard_click_squares.js +1 -1
- package/graphic_test_app/08_chessboard_move_pieces.js +1 -1
- package/graphic_test_app/09_chessboard_edit_arrows.js +1 -1
- package/graphic_test_app/10_chessboard_play_moves.js +1 -1
- package/graphic_test_app/11_chessboard_play_promotions.js +1 -1
- package/graphic_test_app/12_movetext_simple.js +41 -0
- package/graphic_test_app/13_movetext_error.js +38 -0
- package/graphic_test_app/14_movetext_html.js +40 -0
- package/graphic_test_app/15_movetext_options.js +42 -0
- package/graphic_test_app/16_movetext_interaction.js +42 -0
- package/graphic_test_app/common/dummy.pgn +8 -0
- package/graphic_test_app/common/games.pgn +167 -0
- package/graphic_test_app/common/heartbeat.txt +1 -0
- package/graphic_test_app/common/test_app.css +20 -4
- package/graphic_test_app/common/test_app.js +6 -6
- package/package.json +26 -25
- package/scripts/test_graphic/clean-graphic-output.js +1 -1
- package/scripts/test_graphic/docker-compose.yml +1 -1
- package/scripts/test_graphic/webpack-config.js +8 -3
- package/scripts/test_headless.webpack-config.js +3 -2
- package/src/ArrowMarkerIcon.js +2 -2
- package/src/Chessboard.js +11 -11
- package/src/ErrorBox.js +80 -1
- package/src/Movetext.js +616 -0
- package/src/SquareMarkerIcon.js +1 -1
- package/src/TextMarkerIcon.js +7 -7
- package/src/css/arrow.css +1 -1
- package/src/css/chessboard.css +6 -1
- package/src/css/error_box.css +13 -2
- package/src/css/fonts.css +34 -0
- package/src/css/movetext.css +117 -0
- package/src/css/{label.css → symbol.css} +6 -2
- package/src/fonts/chessalpha.woff +0 -0
- package/src/fonts/chessalpha.woff2 +0 -0
- package/src/i18n.js +12 -1
- package/src/impl/ArrowTip.js +3 -7
- package/src/impl/HtmlSanitizer.js +120 -0
- package/src/impl/TextSymbol.js +76 -0
- package/src/impl/colorsets.js +1 -1
- package/src/impl/piecesets.js +1 -1
- package/src/impl/util.js +2 -2
- package/src/index.js +2 -1
- package/src/markers.js +8 -7
- package/test/1_markers.js +20 -1
- package/test/2_chessboard_util.js +1 -1
- package/test/3_marker_icons_graphic.js +2 -2
- package/test/4_chessboard_graphic.js +1 -1
- package/test/5_chessboard_interaction.js +1 -1
- package/test/6_chessboard_play_moves.js +1 -1
- package/test/7_movetext_graphic.js +43 -0
- package/test/8_movetext_interaction.js +99 -0
- package/test/common/graphic.js +2 -2
- package/test/references/01_marker_icons/10.png +0 -0
- package/test/references/01_marker_icons/9.png +0 -0
- package/test/references/04_chessboard_annotations/4.png +0 -0
- package/test/references/04_chessboard_annotations/5.png +0 -0
- package/test/references/05_chessboard_move/3.png +0 -0
- package/test/references/12_movetext_simple/0.png +0 -0
- package/test/references/12_movetext_simple/1.png +0 -0
- package/test/references/12_movetext_simple/2.png +0 -0
- package/test/references/12_movetext_simple/3.png +0 -0
- package/test/references/13_movetext_error/0.png +0 -0
- package/test/references/13_movetext_error/1.png +0 -0
- package/test/references/13_movetext_error/2.png +0 -0
- package/test/references/13_movetext_error/3.png +0 -0
- package/test/references/14_movetext_html/0.png +0 -0
- package/test/references/14_movetext_html/1.png +0 -0
- package/test/references/14_movetext_html/2.png +0 -0
- package/test/references/15_movetext_options/0.png +0 -0
- package/test/references/15_movetext_options/1.png +0 -0
- package/test/references/15_movetext_options/2.png +0 -0
- package/test/references/15_movetext_options/3.png +0 -0
- package/test/references/16_movetext_interaction/0.png +0 -0
- package/test/references/16_movetext_interaction/1.png +0 -0
- package/test/references/16_movetext_interaction/2.png +0 -0
- package/graphic_test_app/common/healthcheck.txt +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
ChangeLog
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
|
+
1.5.0 (April 27, 2022)
|
|
5
|
+
----------------------
|
|
6
|
+
* Add component `Movetext` to display chess games.
|
|
7
|
+
|
|
8
|
+
1.4.1 (January 1, 2022)
|
|
9
|
+
-----------------------
|
|
10
|
+
* Upgrade dependencies.
|
|
11
|
+
|
|
12
|
+
1.4.0 (October 21, 2021)
|
|
13
|
+
------------------------
|
|
14
|
+
* Add support for plus/times/dot/circle in text markers.
|
|
15
|
+
|
|
4
16
|
1.3.1 (September 27, 2021)
|
|
5
17
|
--------------------------
|
|
6
18
|
* Fix missing export for `ErrorBox`.
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ and [PGN](https://en.wikipedia.org/wiki/Portable_Game_Notation) formats...).
|
|
|
10
10
|
|
|
11
11
|
https://www.npmjs.com/package/kokopu-react
|
|
12
12
|
|
|
13
|
-
[](https://travis-ci.com/yo35/kokopu-react)
|
|
13
|
+
[](https://app.travis-ci.com/yo35/kokopu-react)
|
|
14
14
|
[](https://coveralls.io/github/yo35/kokopu-react?branch=master)
|
|
15
15
|
|
|
16
16
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
@@ -23,9 +23,9 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
23
23
|
|
|
24
24
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
25
25
|
|
|
26
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
26
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
27
27
|
|
|
28
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
28
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
29
29
|
|
|
30
30
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
31
31
|
|
|
@@ -85,10 +85,8 @@ var ArrowMarkerIcon = /*#__PURE__*/function (_React$Component) {
|
|
|
85
85
|
x2: size - halfThickness * 3,
|
|
86
86
|
y2: size / 2,
|
|
87
87
|
stroke: this.props.color,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
'markerEnd': "url(#".concat(this.arrowTipId, ")")
|
|
91
|
-
}
|
|
88
|
+
strokeWidth: halfThickness * 2,
|
|
89
|
+
markerEnd: "url(#".concat(this.arrowTipId, ")")
|
|
92
90
|
}));
|
|
93
91
|
}
|
|
94
92
|
}]);
|
package/dist/lib/Chessboard.js
CHANGED
|
@@ -21,6 +21,8 @@ var _piecesets2 = _interopRequireDefault(require("./impl/piecesets"));
|
|
|
21
21
|
|
|
22
22
|
var _ArrowTip = _interopRequireDefault(require("./impl/ArrowTip"));
|
|
23
23
|
|
|
24
|
+
var _TextSymbol = _interopRequireDefault(require("./impl/TextSymbol"));
|
|
25
|
+
|
|
24
26
|
var _ErrorBox = _interopRequireDefault(require("./ErrorBox"));
|
|
25
27
|
|
|
26
28
|
var _i18n = _interopRequireDefault(require("./i18n"));
|
|
@@ -33,11 +35,9 @@ require("./css/chessboard.css");
|
|
|
33
35
|
|
|
34
36
|
require("./css/arrow.css");
|
|
35
37
|
|
|
36
|
-
require("./css/label.css");
|
|
37
|
-
|
|
38
38
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
39
39
|
|
|
40
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
40
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
41
41
|
|
|
42
42
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
43
43
|
|
|
@@ -55,9 +55,9 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
55
55
|
|
|
56
56
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
57
57
|
|
|
58
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
58
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
59
59
|
|
|
60
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
60
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
61
61
|
|
|
62
62
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
63
63
|
|
|
@@ -408,10 +408,8 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
408
408
|
x2: xTo,
|
|
409
409
|
y2: yTo,
|
|
410
410
|
stroke: colorset[this.props.editedArrowColor],
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
'markerEnd': "url(#".concat(arrowTipId, ")")
|
|
414
|
-
}
|
|
411
|
+
strokeWidth: strokeWidth,
|
|
412
|
+
markerEnd: "url(#".concat(arrowTipId, ")")
|
|
415
413
|
});
|
|
416
414
|
}
|
|
417
415
|
}, {
|
|
@@ -567,16 +565,16 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
567
565
|
|
|
568
566
|
x += squareSize / 2;
|
|
569
567
|
y += squareSize / 2;
|
|
570
|
-
result.push( /*#__PURE__*/_react["default"].createElement("
|
|
568
|
+
result.push( /*#__PURE__*/_react["default"].createElement("g", {
|
|
571
569
|
key: 'txtm-' + sq,
|
|
572
|
-
className: "kokopu-annotation
|
|
570
|
+
className: "kokopu-annotation"
|
|
571
|
+
}, /*#__PURE__*/_react["default"].createElement(_TextSymbol["default"], {
|
|
573
572
|
x: x,
|
|
574
573
|
y: y,
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
}, value.symbol));
|
|
574
|
+
size: squareSize,
|
|
575
|
+
symbol: value.symbol,
|
|
576
|
+
color: colorset[value.color]
|
|
577
|
+
})));
|
|
580
578
|
});
|
|
581
579
|
return result;
|
|
582
580
|
}
|
|
@@ -624,10 +622,8 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
624
622
|
x2: xTo,
|
|
625
623
|
y2: yTo,
|
|
626
624
|
stroke: colorset[color],
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
'markerEnd': "url(#".concat(arrowTipId, ")")
|
|
630
|
-
}
|
|
625
|
+
strokeWidth: strokeWidth,
|
|
626
|
+
markerEnd: "url(#".concat(arrowTipId, ")")
|
|
631
627
|
}));
|
|
632
628
|
});
|
|
633
629
|
return result;
|
|
@@ -663,10 +659,8 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
663
659
|
x2: x,
|
|
664
660
|
y2: y,
|
|
665
661
|
stroke: colorset['highlight'],
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
'markerEnd': "url(#".concat(this.getArrowTipId('highlight'), ")")
|
|
669
|
-
}
|
|
662
|
+
strokeWidth: squareSize * STROKE_THICKNESS_FACTOR,
|
|
663
|
+
markerEnd: "url(#".concat(this.getArrowTipId('highlight'), ")")
|
|
670
664
|
});
|
|
671
665
|
}
|
|
672
666
|
}, {
|
|
@@ -699,12 +693,10 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
699
693
|
var label = RANK_LABELS[rank];
|
|
700
694
|
return /*#__PURE__*/_react["default"].createElement("text", {
|
|
701
695
|
key: 'rank-' + label,
|
|
702
|
-
className: "kokopu-coordinate
|
|
696
|
+
className: "kokopu-coordinate",
|
|
703
697
|
x: x,
|
|
704
698
|
y: y,
|
|
705
|
-
|
|
706
|
-
'fontSize': fontSize
|
|
707
|
-
}
|
|
699
|
+
fontSize: fontSize
|
|
708
700
|
}, label);
|
|
709
701
|
}
|
|
710
702
|
}, {
|
|
@@ -715,12 +707,10 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
715
707
|
var label = FILE_LABELS[file];
|
|
716
708
|
return /*#__PURE__*/_react["default"].createElement("text", {
|
|
717
709
|
key: 'file-' + label,
|
|
718
|
-
className: "kokopu-coordinate
|
|
710
|
+
className: "kokopu-coordinate",
|
|
719
711
|
x: x,
|
|
720
712
|
y: y,
|
|
721
|
-
|
|
722
|
-
'fontSize': fontSize
|
|
723
|
-
}
|
|
713
|
+
fontSize: fontSize
|
|
724
714
|
}, label);
|
|
725
715
|
}
|
|
726
716
|
}, {
|
|
@@ -925,7 +915,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
925
915
|
};
|
|
926
916
|
}
|
|
927
917
|
/**
|
|
928
|
-
* Return information regarding the
|
|
918
|
+
* Return information regarding the currently displayed position and move, or parsing error message if something went wrong.
|
|
929
919
|
*/
|
|
930
920
|
|
|
931
921
|
}, {
|
package/dist/lib/ErrorBox.js
CHANGED
|
@@ -9,6 +9,8 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
9
9
|
|
|
10
10
|
var _react = _interopRequireDefault(require("react"));
|
|
11
11
|
|
|
12
|
+
var _i18n = _interopRequireDefault(require("./i18n"));
|
|
13
|
+
|
|
12
14
|
require("./css/error_box.css");
|
|
13
15
|
|
|
14
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
@@ -16,7 +18,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
16
18
|
/******************************************************************************
|
|
17
19
|
* *
|
|
18
20
|
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
19
|
-
* Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net>
|
|
21
|
+
* Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
20
22
|
* *
|
|
21
23
|
* This program is free software: you can redistribute it and/or *
|
|
22
24
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -33,18 +35,23 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
33
35
|
* <http://www.gnu.org/licenses/>. *
|
|
34
36
|
* *
|
|
35
37
|
******************************************************************************/
|
|
36
|
-
|
|
38
|
+
var BACKWARD_CHARACTERS = 5;
|
|
39
|
+
var FORWARD_CHARACTERS = 36;
|
|
37
40
|
/**
|
|
38
41
|
* Display an error message.
|
|
39
42
|
*/
|
|
43
|
+
|
|
40
44
|
function ErrorBox(props) {
|
|
45
|
+
var excerpt = typeof props.text === 'string' && props.errorIndex >= 0 && props.errorIndex < props.text.length ? /*#__PURE__*/_react["default"].createElement("div", {
|
|
46
|
+
className: "kokopu-errorExcerpt"
|
|
47
|
+
}, ellipsisAt(props.text, props.errorIndex, BACKWARD_CHARACTERS, FORWARD_CHARACTERS, props.lineNumber)) : undefined;
|
|
41
48
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
42
49
|
className: "kokopu-errorBox"
|
|
43
50
|
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
44
51
|
className: "kokopu-errorTitle"
|
|
45
52
|
}, props.title), /*#__PURE__*/_react["default"].createElement("div", {
|
|
46
53
|
className: "kokopu-errorMessage"
|
|
47
|
-
}, props.message));
|
|
54
|
+
}, props.message), excerpt);
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
ErrorBox.propTypes = {
|
|
@@ -56,5 +63,78 @@ ErrorBox.propTypes = {
|
|
|
56
63
|
/**
|
|
57
64
|
* Additional message providing details about the error.
|
|
58
65
|
*/
|
|
59
|
-
message: _propTypes["default"].string.isRequired
|
|
60
|
-
|
|
66
|
+
message: _propTypes["default"].string.isRequired,
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Raw text whose processing results in the error.
|
|
70
|
+
*/
|
|
71
|
+
text: _propTypes["default"].string,
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Index of the character within `text` that results in the error.
|
|
75
|
+
*/
|
|
76
|
+
errorIndex: _propTypes["default"].number,
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Index (1-based) of the line in which is the character that results in the error.
|
|
80
|
+
*/
|
|
81
|
+
lineNumber: _propTypes["default"].number
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Ellipsis function.
|
|
85
|
+
*
|
|
86
|
+
* Example: if `text` is `0123456789`, then `ellipsis(text, 5, 1, 3)` returns
|
|
87
|
+
* the following string:
|
|
88
|
+
*
|
|
89
|
+
* ```
|
|
90
|
+
* ...45678...
|
|
91
|
+
* ^
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @param {string} text Text from a substring must be extracted.
|
|
95
|
+
* @param {number} pos Index of the character in `text` around which the substring must be extracted.
|
|
96
|
+
* @param {number} backwardCharacters Number of characters to keep before `pos`.
|
|
97
|
+
* @param {number} forwardCharacters Number of characters to keep after `pos`.
|
|
98
|
+
* @returns {string}
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
function ellipsisAt(text, pos, backwardCharacters, forwardCharacters, lineNumber) {
|
|
102
|
+
// p1 => begin of the extracted sub-string
|
|
103
|
+
var p1 = pos;
|
|
104
|
+
var e1 = '... ';
|
|
105
|
+
|
|
106
|
+
while (p1 > pos - backwardCharacters) {
|
|
107
|
+
--p1;
|
|
108
|
+
|
|
109
|
+
if (p1 < 0 || text.charAt(p1) === '\n' || text.charAt(p1) === '\r') {
|
|
110
|
+
++p1;
|
|
111
|
+
e1 = '';
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
} // p2 => one character after the end of the extracted sub-string
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
var p2 = pos;
|
|
118
|
+
var e2 = ' ...';
|
|
119
|
+
|
|
120
|
+
while (p2 < pos + forwardCharacters) {
|
|
121
|
+
++p2;
|
|
122
|
+
|
|
123
|
+
if (p2 >= text.length || text.charAt(p2) === '\n' || text.charAt(p2) === '\r') {
|
|
124
|
+
--p2;
|
|
125
|
+
e2 = '';
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
} // Extract the sub-string around the requested position.
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
var excerpt = e1 + text.substring(p1, p2 + 1) + e2;
|
|
132
|
+
excerpt = excerpt.replace(/\n|\r|\t/g, ' ');
|
|
133
|
+
var secondLine = Array(1 + e1.length + pos - p1).join(' ') + '^';
|
|
134
|
+
|
|
135
|
+
if (lineNumber) {
|
|
136
|
+
secondLine += ' (' + _i18n["default"].LINE.replace(/\{0\}/g, lineNumber) + ')';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return excerpt + '\n' + secondLine;
|
|
140
|
+
}
|