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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/******************************************************************************
|
|
2
2
|
* *
|
|
3
3
|
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
4
|
-
* Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net>
|
|
4
|
+
* Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
5
5
|
* *
|
|
6
6
|
* This program is free software: you can redistribute it and/or *
|
|
7
7
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -21,11 +21,27 @@
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
.test-item,
|
|
24
|
+
.test-item-container,
|
|
24
25
|
#test-app {
|
|
25
26
|
display: inline-block;
|
|
26
|
-
line-height: 0px;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
body {
|
|
30
|
+
background-color: lightgray;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.test-item-container {
|
|
34
|
+
margin: 2px;
|
|
35
|
+
padding: 3px;
|
|
36
|
+
background-color: white;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
#sandbox {
|
|
40
|
+
padding: 3px;
|
|
41
|
+
background-color: lightgoldenrodyellow;
|
|
42
|
+
height: 100px;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.width-600 .test-item {
|
|
46
|
+
width: 600px;
|
|
31
47
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/******************************************************************************
|
|
2
2
|
* *
|
|
3
3
|
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
4
|
-
* Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net>
|
|
4
|
+
* Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
5
5
|
* *
|
|
6
6
|
* This program is free software: you can redistribute it and/or *
|
|
7
7
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -25,19 +25,19 @@ import ReactDOM from 'react-dom';
|
|
|
25
25
|
import './test_app.css';
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
function flattenMultiElements(elements) {
|
|
28
|
+
function flattenMultiElements(elements, containerClassName) {
|
|
29
29
|
let items = [];
|
|
30
30
|
for (let i = 0; i < elements.length; ++i) {
|
|
31
|
-
items.push(<div key={
|
|
31
|
+
items.push(<div key={i} className="test-item-container"><div className="test-item" id={'test-item-' + i}>{elements[i]}</div></div>);
|
|
32
32
|
}
|
|
33
|
-
return <div>{items}</div>;
|
|
33
|
+
return <div className={Array.isArray(containerClassName) ? containerClassName.join(' ') : containerClassName}>{items}</div>;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Create an DIV element at the root of the current document, and render the given elements in it.
|
|
39
39
|
*/
|
|
40
|
-
export default function(elements) {
|
|
40
|
+
export default function(elements, containerClassName) {
|
|
41
41
|
|
|
42
42
|
// Create the main anchor.
|
|
43
43
|
let anchor = document.createElement('div');
|
|
@@ -45,7 +45,7 @@ export default function(elements) {
|
|
|
45
45
|
document.body.appendChild(anchor);
|
|
46
46
|
|
|
47
47
|
// Render the content.
|
|
48
|
-
let content =
|
|
48
|
+
let content = flattenMultiElements(elements, containerClassName);
|
|
49
49
|
ReactDOM.render(content, anchor);
|
|
50
50
|
|
|
51
51
|
// Append a text area
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kokopu-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "A React-based library to create and display chessboard components.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chess",
|
|
@@ -29,41 +29,42 @@
|
|
|
29
29
|
".nycrc.yml"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"
|
|
33
|
-
"
|
|
32
|
+
"htmlparser2": "^7.2.0",
|
|
33
|
+
"kokopu": "^2.7.0",
|
|
34
|
+
"prop-types": "^15.8.1",
|
|
34
35
|
"react": "^17.0.2",
|
|
35
36
|
"react-draggable": "^4.4.4",
|
|
36
37
|
"react-motion": "^0.5.2"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
|
-
"@babel/cli": "^7.
|
|
40
|
-
"@babel/core": "^7.
|
|
41
|
-
"@babel/preset-env": "^7.
|
|
42
|
-
"@babel/preset-react": "^7.
|
|
43
|
-
"@emotion/react": "^11.
|
|
44
|
-
"@emotion/styled": "^11.
|
|
45
|
-
"@mui/material": "^5.
|
|
46
|
-
"babel-loader": "^8.2.
|
|
47
|
-
"babel-plugin-istanbul": "^6.
|
|
48
|
-
"copy-webpack-plugin": "^
|
|
40
|
+
"@babel/cli": "^7.17.6",
|
|
41
|
+
"@babel/core": "^7.17.9",
|
|
42
|
+
"@babel/preset-env": "^7.16.11",
|
|
43
|
+
"@babel/preset-react": "^7.16.7",
|
|
44
|
+
"@emotion/react": "^11.9.0",
|
|
45
|
+
"@emotion/styled": "^11.8.1",
|
|
46
|
+
"@mui/material": "^5.6.2",
|
|
47
|
+
"babel-loader": "^8.2.5",
|
|
48
|
+
"babel-plugin-istanbul": "^6.1.1",
|
|
49
|
+
"copy-webpack-plugin": "^10.2.4",
|
|
49
50
|
"coveralls": "^3.1.1",
|
|
50
|
-
"css-loader": "^6.
|
|
51
|
-
"eslint": "^
|
|
52
|
-
"eslint-plugin-react": "^7.
|
|
53
|
-
"html-webpack-plugin": "^5.
|
|
51
|
+
"css-loader": "^6.7.1",
|
|
52
|
+
"eslint": "^8.13.0",
|
|
53
|
+
"eslint-plugin-react": "^7.29.4",
|
|
54
|
+
"html-webpack-plugin": "^5.5.0",
|
|
54
55
|
"img-diff-js": "^0.5.2",
|
|
55
|
-
"mocha": "^9.
|
|
56
|
+
"mocha": "^9.2.2",
|
|
56
57
|
"null-loader": "^4.0.1",
|
|
57
58
|
"nyc": "^15.1.0",
|
|
58
|
-
"prompt": "^1.
|
|
59
|
+
"prompt": "^1.3.0",
|
|
59
60
|
"react-dom": "^17.0.2",
|
|
60
|
-
"react-styleguidist": "^11.
|
|
61
|
-
"selenium-webdriver": "^4.
|
|
62
|
-
"ssh2-sftp-client": "^
|
|
63
|
-
"style-loader": "^3.3.
|
|
61
|
+
"react-styleguidist": "^11.2.0",
|
|
62
|
+
"selenium-webdriver": "^4.1.1",
|
|
63
|
+
"ssh2-sftp-client": "^8.0.0",
|
|
64
|
+
"style-loader": "^3.3.1",
|
|
64
65
|
"unit.js": "^2.1.1",
|
|
65
|
-
"webpack": "^5.
|
|
66
|
-
"webpack-cli": "^4.
|
|
66
|
+
"webpack": "^5.72.0",
|
|
67
|
+
"webpack-cli": "^4.9.2"
|
|
67
68
|
},
|
|
68
69
|
"scripts": {
|
|
69
70
|
"lint": "eslint doc_src graphic_test_app src test",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/******************************************************************************
|
|
2
2
|
* *
|
|
3
3
|
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
4
|
-
* Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net>
|
|
4
|
+
* Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
5
5
|
* *
|
|
6
6
|
* This program is free software: you can redistribute it and/or *
|
|
7
7
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/******************************************************************************
|
|
2
2
|
* *
|
|
3
3
|
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
4
|
-
* Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net>
|
|
4
|
+
* Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
5
5
|
* *
|
|
6
6
|
* This program is free software: you can redistribute it and/or *
|
|
7
7
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -39,7 +39,7 @@ var plugins = items.map(item => new HtmlWebpackPlugin({
|
|
|
39
39
|
filename: item + '/index.html',
|
|
40
40
|
}));
|
|
41
41
|
plugins.push(new CopyWebpackPlugin({
|
|
42
|
-
patterns: [ { from: './graphic_test_app/common/
|
|
42
|
+
patterns: [ { from: './graphic_test_app/common/heartbeat.txt', to: 'heartbeat.txt' } ],
|
|
43
43
|
}));
|
|
44
44
|
|
|
45
45
|
module.exports = {
|
|
@@ -47,6 +47,7 @@ module.exports = {
|
|
|
47
47
|
entry: entries,
|
|
48
48
|
output: {
|
|
49
49
|
path: path.resolve(__dirname, '../../build/test_graphic'),
|
|
50
|
+
hashFunction: "xxhash64", // FIXME The default hash function used by Webpack has been removed from OpenSSL.
|
|
50
51
|
},
|
|
51
52
|
plugins: plugins,
|
|
52
53
|
module: {
|
|
@@ -65,9 +66,13 @@ module.exports = {
|
|
|
65
66
|
use: ['style-loader', 'css-loader'],
|
|
66
67
|
},
|
|
67
68
|
{
|
|
68
|
-
test: /\.(png|txt)$/i,
|
|
69
|
+
test: /\.(png|woff|woff2|txt)$/i,
|
|
69
70
|
type: 'asset/resource',
|
|
70
71
|
},
|
|
72
|
+
{
|
|
73
|
+
test: /\.pgn$/i,
|
|
74
|
+
type: 'asset/source',
|
|
75
|
+
},
|
|
71
76
|
],
|
|
72
77
|
}
|
|
73
78
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/******************************************************************************
|
|
2
2
|
* *
|
|
3
3
|
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
4
|
-
* Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net>
|
|
4
|
+
* Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
5
5
|
* *
|
|
6
6
|
* This program is free software: you can redistribute it and/or *
|
|
7
7
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -32,6 +32,7 @@ module.exports = {
|
|
|
32
32
|
library: {
|
|
33
33
|
type: 'commonjs2',
|
|
34
34
|
},
|
|
35
|
+
hashFunction: "xxhash64", // FIXME The default hash function used by Webpack has been removed from OpenSSL.
|
|
35
36
|
},
|
|
36
37
|
module: {
|
|
37
38
|
rules: [
|
|
@@ -49,7 +50,7 @@ module.exports = {
|
|
|
49
50
|
use: 'null-loader',
|
|
50
51
|
},
|
|
51
52
|
{
|
|
52
|
-
test: /\.png$/i,
|
|
53
|
+
test: /\.(png|woff|woff2)$/i,
|
|
53
54
|
use: 'null-loader',
|
|
54
55
|
},
|
|
55
56
|
],
|
package/src/ArrowMarkerIcon.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/******************************************************************************
|
|
2
2
|
* *
|
|
3
3
|
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
4
|
-
* Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net>
|
|
4
|
+
* Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
5
5
|
* *
|
|
6
6
|
* This program is free software: you can redistribute it and/or *
|
|
7
7
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -54,7 +54,7 @@ export default class ArrowMarkerIcon extends React.Component {
|
|
|
54
54
|
<ArrowTip id={this.arrowTipId} color={this.props.color} />
|
|
55
55
|
</defs>
|
|
56
56
|
<line className="kokopu-arrow" x1={halfThickness} y1={size / 2} x2={size - halfThickness * 3} y2={size / 2} stroke={this.props.color}
|
|
57
|
-
|
|
57
|
+
strokeWidth={halfThickness * 2} markerEnd={`url(#${this.arrowTipId})`} />
|
|
58
58
|
</svg>
|
|
59
59
|
);
|
|
60
60
|
}
|
package/src/Chessboard.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/******************************************************************************
|
|
2
2
|
* *
|
|
3
3
|
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
4
|
-
* Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net>
|
|
4
|
+
* Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
5
5
|
* *
|
|
6
6
|
* This program is free software: you can redistribute it and/or *
|
|
7
7
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -29,6 +29,7 @@ import kokopu from 'kokopu';
|
|
|
29
29
|
import colorsets from './impl/colorsets';
|
|
30
30
|
import piecesets from './impl/piecesets';
|
|
31
31
|
import ArrowTip from './impl/ArrowTip';
|
|
32
|
+
import TextSymbol from './impl/TextSymbol';
|
|
32
33
|
import ErrorBox from './ErrorBox';
|
|
33
34
|
import i18n from './i18n';
|
|
34
35
|
import { parseSquareMarkers, parseTextMarkers, parseArrowMarkers } from './markers';
|
|
@@ -36,7 +37,6 @@ import { MIN_SQUARE_SIZE, MAX_SQUARE_SIZE, sanitizeInteger, generateRandomId, is
|
|
|
36
37
|
|
|
37
38
|
import './css/chessboard.css';
|
|
38
39
|
import './css/arrow.css';
|
|
39
|
-
import './css/label.css';
|
|
40
40
|
|
|
41
41
|
const TURN_FLAG_SPACING_FACTOR = 0.1;
|
|
42
42
|
const RANK_COORDINATE_WIDTH_FACTOR = 1;
|
|
@@ -272,7 +272,7 @@ export default class Chessboard extends React.Component {
|
|
|
272
272
|
return (
|
|
273
273
|
<line
|
|
274
274
|
className="kokopu-annotation kokopu-arrow kokopu-arrowDraggable kokopu-dragging" x1={xFrom} y1={yFrom} x2={xTo} y2={yTo}
|
|
275
|
-
stroke={colorset[this.props.editedArrowColor]}
|
|
275
|
+
stroke={colorset[this.props.editedArrowColor]} strokeWidth={strokeWidth} markerEnd={`url(#${arrowTipId})`}
|
|
276
276
|
/>
|
|
277
277
|
);
|
|
278
278
|
}
|
|
@@ -347,9 +347,9 @@ export default class Chessboard extends React.Component {
|
|
|
347
347
|
x += squareSize / 2;
|
|
348
348
|
y += squareSize / 2;
|
|
349
349
|
result.push(
|
|
350
|
-
<
|
|
351
|
-
{value.symbol}
|
|
352
|
-
</
|
|
350
|
+
<g key={'txtm-' + sq} className="kokopu-annotation">
|
|
351
|
+
<TextSymbol x={x} y={y} size={squareSize} symbol={value.symbol} color={colorset[value.color]} />
|
|
352
|
+
</g>
|
|
353
353
|
);
|
|
354
354
|
});
|
|
355
355
|
return result;
|
|
@@ -376,7 +376,7 @@ export default class Chessboard extends React.Component {
|
|
|
376
376
|
result.push(
|
|
377
377
|
<line
|
|
378
378
|
key={'arm-' + vect} className="kokopu-annotation kokopu-arrow" x1={xFrom} y1={yFrom} x2={xTo} y2={yTo}
|
|
379
|
-
stroke={colorset[color]}
|
|
379
|
+
stroke={colorset[color]} strokeWidth={strokeWidth} markerEnd={`url(#${arrowTipId})`}
|
|
380
380
|
/>
|
|
381
381
|
);
|
|
382
382
|
});
|
|
@@ -400,7 +400,7 @@ export default class Chessboard extends React.Component {
|
|
|
400
400
|
return (
|
|
401
401
|
<line
|
|
402
402
|
className="kokopu-annotation kokopu-arrow" x1={xFrom} y1={yFrom} x2={x} y2={y} stroke={colorset['highlight']}
|
|
403
|
-
|
|
403
|
+
strokeWidth={squareSize * STROKE_THICKNESS_FACTOR} markerEnd={`url(#${this.getArrowTipId('highlight')})`}
|
|
404
404
|
/>
|
|
405
405
|
);
|
|
406
406
|
}
|
|
@@ -419,14 +419,14 @@ export default class Chessboard extends React.Component {
|
|
|
419
419
|
let x = Math.round(-RANK_COORDINATE_WIDTH_FACTOR * fontSize) / 2;
|
|
420
420
|
let y = (this.props.flipped ? rank + 0.5 : 7.5 - rank) * squareSize;
|
|
421
421
|
let label = RANK_LABELS[rank];
|
|
422
|
-
return <text key={'rank-' + label} className="kokopu-coordinate
|
|
422
|
+
return <text key={'rank-' + label} className="kokopu-coordinate" x={x} y={y} fontSize={fontSize}>{label}</text>;
|
|
423
423
|
}
|
|
424
424
|
|
|
425
425
|
renderFileCoordinate(squareSize, fontSize, file) {
|
|
426
426
|
let x = (this.props.flipped ? 7.5 - file : 0.5 + file) * squareSize;
|
|
427
427
|
let y = 8 * squareSize + Math.round(FILE_COORDINATE_HEIGHT_FACTOR * fontSize) / 2;
|
|
428
428
|
let label = FILE_LABELS[file];
|
|
429
|
-
return <text key={'file-' + label} className="kokopu-coordinate
|
|
429
|
+
return <text key={'file-' + label} className="kokopu-coordinate" x={x} y={y} fontSize={fontSize}>{label}</text>;
|
|
430
430
|
}
|
|
431
431
|
|
|
432
432
|
handleWindowResize() {
|
|
@@ -580,7 +580,7 @@ export default class Chessboard extends React.Component {
|
|
|
580
580
|
}
|
|
581
581
|
|
|
582
582
|
/**
|
|
583
|
-
* Return information regarding the
|
|
583
|
+
* Return information regarding the currently displayed position and move, or parsing error message if something went wrong.
|
|
584
584
|
*/
|
|
585
585
|
getPositionAndMoveInfo() {
|
|
586
586
|
|
package/src/ErrorBox.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/******************************************************************************
|
|
2
2
|
* *
|
|
3
3
|
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
4
|
-
* Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net>
|
|
4
|
+
* Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
5
5
|
* *
|
|
6
6
|
* This program is free software: you can redistribute it and/or *
|
|
7
7
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -23,21 +23,31 @@
|
|
|
23
23
|
import PropTypes from 'prop-types';
|
|
24
24
|
import React from 'react';
|
|
25
25
|
|
|
26
|
+
import i18n from './i18n';
|
|
27
|
+
|
|
26
28
|
import './css/error_box.css';
|
|
27
29
|
|
|
30
|
+
const BACKWARD_CHARACTERS = 5;
|
|
31
|
+
const FORWARD_CHARACTERS = 36;
|
|
32
|
+
|
|
33
|
+
|
|
28
34
|
|
|
29
35
|
/**
|
|
30
36
|
* Display an error message.
|
|
31
37
|
*/
|
|
32
38
|
export default function ErrorBox(props) {
|
|
39
|
+
let excerpt = typeof props.text === 'string' && props.errorIndex >= 0 && props.errorIndex < props.text.length ?
|
|
40
|
+
<div className="kokopu-errorExcerpt">{ellipsisAt(props.text, props.errorIndex, BACKWARD_CHARACTERS, FORWARD_CHARACTERS, props.lineNumber)}</div> : undefined;
|
|
33
41
|
return (
|
|
34
42
|
<div className="kokopu-errorBox">
|
|
35
43
|
<div className="kokopu-errorTitle">{props.title}</div>
|
|
36
44
|
<div className="kokopu-errorMessage">{props.message}</div>
|
|
45
|
+
{excerpt}
|
|
37
46
|
</div>
|
|
38
47
|
);
|
|
39
48
|
}
|
|
40
49
|
|
|
50
|
+
|
|
41
51
|
ErrorBox.propTypes = {
|
|
42
52
|
|
|
43
53
|
/**
|
|
@@ -49,4 +59,73 @@ ErrorBox.propTypes = {
|
|
|
49
59
|
* Additional message providing details about the error.
|
|
50
60
|
*/
|
|
51
61
|
message: PropTypes.string.isRequired,
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Raw text whose processing results in the error.
|
|
65
|
+
*/
|
|
66
|
+
text: PropTypes.string,
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Index of the character within `text` that results in the error.
|
|
70
|
+
*/
|
|
71
|
+
errorIndex: PropTypes.number,
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Index (1-based) of the line in which is the character that results in the error.
|
|
75
|
+
*/
|
|
76
|
+
lineNumber: PropTypes.number,
|
|
52
77
|
};
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Ellipsis function.
|
|
82
|
+
*
|
|
83
|
+
* Example: if `text` is `0123456789`, then `ellipsis(text, 5, 1, 3)` returns
|
|
84
|
+
* the following string:
|
|
85
|
+
*
|
|
86
|
+
* ```
|
|
87
|
+
* ...45678...
|
|
88
|
+
* ^
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @param {string} text Text from a substring must be extracted.
|
|
92
|
+
* @param {number} pos Index of the character in `text` around which the substring must be extracted.
|
|
93
|
+
* @param {number} backwardCharacters Number of characters to keep before `pos`.
|
|
94
|
+
* @param {number} forwardCharacters Number of characters to keep after `pos`.
|
|
95
|
+
* @returns {string}
|
|
96
|
+
*/
|
|
97
|
+
function ellipsisAt(text, pos, backwardCharacters, forwardCharacters, lineNumber) {
|
|
98
|
+
|
|
99
|
+
// p1 => begin of the extracted sub-string
|
|
100
|
+
let p1 = pos;
|
|
101
|
+
let e1 = '... ';
|
|
102
|
+
while (p1 > pos - backwardCharacters) {
|
|
103
|
+
--p1;
|
|
104
|
+
if (p1 < 0 || text.charAt(p1) === '\n' || text.charAt(p1) === '\r') {
|
|
105
|
+
++p1;
|
|
106
|
+
e1 = '';
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// p2 => one character after the end of the extracted sub-string
|
|
112
|
+
let p2 = pos;
|
|
113
|
+
let e2 = ' ...';
|
|
114
|
+
while (p2 < pos + forwardCharacters) {
|
|
115
|
+
++p2;
|
|
116
|
+
if (p2 >= text.length || text.charAt(p2) === '\n' || text.charAt(p2) === '\r') {
|
|
117
|
+
--p2;
|
|
118
|
+
e2 = '';
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Extract the sub-string around the requested position.
|
|
124
|
+
let excerpt = e1 + text.substring(p1, p2 + 1) + e2;
|
|
125
|
+
excerpt = excerpt.replace(/\n|\r|\t/g, ' ');
|
|
126
|
+
let secondLine = Array(1 + e1.length + pos - p1).join(' ') + '^';
|
|
127
|
+
if (lineNumber) {
|
|
128
|
+
secondLine += ' (' + i18n.LINE.replace(/\{0\}/g, lineNumber) + ')';
|
|
129
|
+
}
|
|
130
|
+
return excerpt + '\n' + secondLine;
|
|
131
|
+
}
|