kokopu-react 1.9.0 → 1.9.2
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/lib/ArrowMarkerIcon.js +4 -30
- package/dist/lib/Chessboard.js +109 -244
- package/dist/lib/ErrorBox.js +7 -24
- package/dist/lib/Movetext.js +78 -180
- package/dist/lib/SquareMarkerIcon.js +2 -10
- package/dist/lib/TextMarkerIcon.js +0 -11
- package/dist/lib/css/movetext.css +4 -0
- package/dist/lib/formatmove.js +2 -14
- package/dist/lib/i18n.js +1 -1
- package/dist/lib/impl/ArrowTip.js +0 -6
- package/dist/lib/impl/HtmlSanitizer.js +18 -49
- package/dist/lib/impl/Motion.js +10 -34
- package/dist/lib/impl/TextSymbol.js +2 -11
- package/dist/lib/impl/colorsets.js +0 -2
- package/dist/lib/impl/piecesets.js +0 -87
- package/dist/lib/impl/util.js +1 -11
- package/dist/lib/index.js +0 -10
- package/dist/lib/markers.js +19 -39
- package/package.json +18 -18
- package/scripts/docker-compose.yml +1 -1
- package/src/Chessboard.js +5 -1
- package/src/css/movetext.css +4 -0
package/dist/lib/Movetext.js
CHANGED
|
@@ -1,91 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
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
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports["default"] = void 0;
|
|
9
|
-
|
|
10
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
9
|
var _react = _interopRequireDefault(require("react"));
|
|
13
|
-
|
|
14
10
|
var _kokopu = require("kokopu");
|
|
15
|
-
|
|
16
11
|
var _HtmlSanitizer = _interopRequireDefault(require("./impl/HtmlSanitizer"));
|
|
17
|
-
|
|
18
12
|
var _util = require("./impl/util");
|
|
19
|
-
|
|
20
13
|
var _Chessboard = _interopRequireDefault(require("./Chessboard"));
|
|
21
|
-
|
|
22
14
|
var _ErrorBox = _interopRequireDefault(require("./ErrorBox"));
|
|
23
|
-
|
|
24
15
|
var _formatmove = require("./formatmove");
|
|
25
|
-
|
|
26
16
|
var _i18n = _interopRequireDefault(require("./i18n"));
|
|
27
|
-
|
|
28
17
|
require("./css/movetext.css");
|
|
29
|
-
|
|
30
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
31
|
-
|
|
32
19
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
33
|
-
|
|
34
20
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
35
|
-
|
|
36
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
37
|
-
|
|
21
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
38
22
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
39
|
-
|
|
40
23
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
41
|
-
|
|
42
24
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
43
|
-
|
|
44
25
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
45
|
-
|
|
46
26
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
47
|
-
|
|
48
|
-
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); } }
|
|
49
|
-
|
|
27
|
+
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
50
28
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
51
|
-
|
|
29
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
30
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
52
31
|
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); }
|
|
53
|
-
|
|
54
32
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
55
|
-
|
|
56
33
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
57
|
-
|
|
58
34
|
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
59
|
-
|
|
60
35
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
61
|
-
|
|
62
36
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
63
|
-
|
|
64
37
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
65
|
-
|
|
66
38
|
/**
|
|
67
39
|
* Display a chess game, i.e. the headers (name of the players, event, etc.), the moves, and all the related annotations if any (comments, variations, NAGs...).
|
|
68
40
|
*/
|
|
69
41
|
var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
70
42
|
_inherits(Movetext, _React$Component);
|
|
71
|
-
|
|
72
43
|
var _super = _createSuper(Movetext);
|
|
73
|
-
|
|
74
44
|
function Movetext(props) {
|
|
75
45
|
var _this;
|
|
76
|
-
|
|
77
46
|
_classCallCheck(this, Movetext);
|
|
78
|
-
|
|
79
47
|
_this = _super.call(this, props);
|
|
80
48
|
_this.focusFieldRef = /*#__PURE__*/_react["default"].createRef();
|
|
81
49
|
return _this;
|
|
82
50
|
}
|
|
83
|
-
|
|
84
51
|
_createClass(Movetext, [{
|
|
85
52
|
key: "render",
|
|
86
53
|
value: function render() {
|
|
87
54
|
var info = parseGame(this.props.game, this.props.gameIndex);
|
|
88
|
-
|
|
89
55
|
if (info.error) {
|
|
90
56
|
return /*#__PURE__*/_react["default"].createElement(_ErrorBox["default"], {
|
|
91
57
|
title: _i18n["default"].INVALID_PGN_ERROR_TITLE,
|
|
@@ -95,7 +61,6 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
95
61
|
lineNumber: info.lineNumber
|
|
96
62
|
});
|
|
97
63
|
}
|
|
98
|
-
|
|
99
64
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
100
65
|
className: "kokopu-movetext"
|
|
101
66
|
}, this.renderHeaders(info.game), this.renderBody(info.game), this.renderFocusField(info.game));
|
|
@@ -106,7 +71,6 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
106
71
|
if (!this.props.headerVisible) {
|
|
107
72
|
return undefined;
|
|
108
73
|
}
|
|
109
|
-
|
|
110
74
|
var headers = [];
|
|
111
75
|
headers.push(this.renderPlayerHeaders(game, 'w'));
|
|
112
76
|
headers.push(this.renderPlayerHeaders(game, 'b'));
|
|
@@ -119,31 +83,26 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
119
83
|
className: "kokopu-headers"
|
|
120
84
|
}, headers) : undefined;
|
|
121
85
|
}
|
|
86
|
+
|
|
122
87
|
/**
|
|
123
88
|
* Header containing the player-related information (name, rating, title) corresponding to the given color.
|
|
124
89
|
*/
|
|
125
|
-
|
|
126
90
|
}, {
|
|
127
91
|
key: "renderPlayerHeaders",
|
|
128
92
|
value: function renderPlayerHeaders(game, color) {
|
|
129
93
|
var playerName = game.playerName(color);
|
|
130
|
-
|
|
131
94
|
if (playerName === undefined) {
|
|
132
95
|
return undefined;
|
|
133
96
|
}
|
|
134
|
-
|
|
135
97
|
var title = game.playerTitle(color);
|
|
136
98
|
var rating = game.playerElo(color);
|
|
137
99
|
var classNames = ['kokopu-headerGroup-player', color === 'w' ? 'kokopu-headerGroup-whitePlayer' : 'kokopu-headerGroup-blackPlayer'];
|
|
138
|
-
|
|
139
100
|
var colorTag = /*#__PURE__*/_react["default"].createElement("span", {
|
|
140
101
|
className: "kokopu-colorTag"
|
|
141
102
|
});
|
|
142
|
-
|
|
143
103
|
var playerNameElement = /*#__PURE__*/_react["default"].createElement("span", {
|
|
144
104
|
className: "kokopu-header-playerName"
|
|
145
105
|
}, sanitizeHtml(playerName));
|
|
146
|
-
|
|
147
106
|
var titleElement = title === undefined ? undefined : /*#__PURE__*/_react["default"].createElement("span", {
|
|
148
107
|
className: "kokopu-header-playerTitle"
|
|
149
108
|
}, sanitizeHtml(title));
|
|
@@ -151,7 +110,6 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
151
110
|
className: "kokopu-header-playerRating"
|
|
152
111
|
}, rating);
|
|
153
112
|
var separator = title === undefined || rating === undefined ? undefined : "\xA0"; // \u00a0 ==
|
|
154
|
-
|
|
155
113
|
var titleRatingGroup = title === undefined && rating === undefined ? undefined : /*#__PURE__*/_react["default"].createElement("span", {
|
|
156
114
|
className: "kokopu-headerGroup-titleRating"
|
|
157
115
|
}, titleElement, separator, ratingElement);
|
|
@@ -160,47 +118,41 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
160
118
|
key: 'player-' + color
|
|
161
119
|
}, colorTag, playerNameElement, titleRatingGroup);
|
|
162
120
|
}
|
|
121
|
+
|
|
163
122
|
/**
|
|
164
123
|
* Header containing the event-related information: event + round.
|
|
165
124
|
*/
|
|
166
|
-
|
|
167
125
|
}, {
|
|
168
126
|
key: "renderEventRoundHeaders",
|
|
169
127
|
value: function renderEventRoundHeaders(game) {
|
|
170
128
|
var evt = game.event();
|
|
171
|
-
|
|
172
129
|
if (evt === undefined) {
|
|
173
130
|
return undefined;
|
|
174
131
|
}
|
|
175
|
-
|
|
176
132
|
var round = game.round();
|
|
177
133
|
var roundElement = round === undefined ? undefined : /*#__PURE__*/_react["default"].createElement("span", {
|
|
178
134
|
className: "kokopu-header-round"
|
|
179
135
|
}, sanitizeHtml(round));
|
|
180
|
-
|
|
181
136
|
var evtElement = /*#__PURE__*/_react["default"].createElement("span", {
|
|
182
137
|
className: "kokopu-header-event"
|
|
183
138
|
}, sanitizeHtml(evt));
|
|
184
|
-
|
|
185
139
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
186
140
|
className: "kokopu-headerGroup-eventRound",
|
|
187
141
|
key: "event-round"
|
|
188
142
|
}, evtElement, roundElement);
|
|
189
143
|
}
|
|
144
|
+
|
|
190
145
|
/**
|
|
191
146
|
* Header containing the date/place information.
|
|
192
147
|
*/
|
|
193
|
-
|
|
194
148
|
}, {
|
|
195
149
|
key: "renderDateSiteHeaders",
|
|
196
150
|
value: function renderDateSiteHeaders(game) {
|
|
197
151
|
var date = game.date();
|
|
198
152
|
var site = game.site();
|
|
199
|
-
|
|
200
153
|
if (date === undefined && site === undefined) {
|
|
201
154
|
return undefined;
|
|
202
155
|
}
|
|
203
|
-
|
|
204
156
|
var dateElement = date === undefined ? undefined : /*#__PURE__*/_react["default"].createElement("span", {
|
|
205
157
|
className: "kokopu-header-date"
|
|
206
158
|
}, capitalizeFirstWord(game.dateAsString()));
|
|
@@ -208,25 +160,22 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
208
160
|
className: "kokopu-header-site"
|
|
209
161
|
}, sanitizeHtml(site));
|
|
210
162
|
var separator = date === undefined || site === undefined ? undefined : "\xA0\u2013\xA0"; // \u00a0 == \u2013 == –
|
|
211
|
-
|
|
212
163
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
213
164
|
className: "kokopu-headerGroup-dateSite",
|
|
214
165
|
key: "date-site"
|
|
215
166
|
}, dateElement, separator, siteElement);
|
|
216
167
|
}
|
|
168
|
+
|
|
217
169
|
/**
|
|
218
170
|
* Header containing the annotator information.
|
|
219
171
|
*/
|
|
220
|
-
|
|
221
172
|
}, {
|
|
222
173
|
key: "renderAnnotatorHeader",
|
|
223
174
|
value: function renderAnnotatorHeader(game) {
|
|
224
175
|
var annotator = game.annotator();
|
|
225
|
-
|
|
226
176
|
if (annotator === undefined) {
|
|
227
177
|
return undefined;
|
|
228
178
|
}
|
|
229
|
-
|
|
230
179
|
annotator = (0, _util.fillPlaceholder)(_i18n["default"].ANNOTATED_BY, annotator);
|
|
231
180
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
232
181
|
className: "kokopu-header-annotator",
|
|
@@ -237,11 +186,9 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
237
186
|
key: "renderFocusField",
|
|
238
187
|
value: function renderFocusField(game) {
|
|
239
188
|
var _this2 = this;
|
|
240
|
-
|
|
241
189
|
if (this.props.interactionMode !== 'selectMove') {
|
|
242
190
|
return undefined;
|
|
243
191
|
}
|
|
244
|
-
|
|
245
192
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
246
193
|
className: "kokopu-focusFieldContainer"
|
|
247
194
|
}, /*#__PURE__*/_react["default"].createElement("a", {
|
|
@@ -259,50 +206,47 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
259
206
|
var notationTextBuilder = (0, _formatmove.moveFormatter)(this.props.pieceSymbols);
|
|
260
207
|
return this.renderVariation(notationTextBuilder, game.mainVariation(), 'main-variation', true, game.result());
|
|
261
208
|
}
|
|
209
|
+
|
|
262
210
|
/**
|
|
263
211
|
* Render the given variation and its sub-variations, recursively.
|
|
264
212
|
*/
|
|
265
|
-
|
|
266
213
|
}, {
|
|
267
214
|
key: "renderVariation",
|
|
268
215
|
value: function renderVariation(notationTextBuilder, variation, variationKey, isMainVariation, gameResult) {
|
|
269
216
|
var moveGroups = []; // ... and also long comments and long sub-variations
|
|
217
|
+
var currentMoveGroupElements = [];
|
|
270
218
|
|
|
271
|
-
|
|
272
|
-
|
|
219
|
+
// Close the current move group, if any.
|
|
273
220
|
function closeMoveGroup() {
|
|
274
221
|
if (!variation.isLongVariation() || currentMoveGroupElements.length === 0) {
|
|
275
222
|
return;
|
|
276
223
|
}
|
|
277
|
-
|
|
278
224
|
moveGroups.push( /*#__PURE__*/_react["default"].createElement("div", {
|
|
279
225
|
className: "kokopu-moveGroup",
|
|
280
226
|
key: 'group-' + moveGroups.length
|
|
281
227
|
}, currentMoveGroupElements));
|
|
282
228
|
currentMoveGroupElements = [];
|
|
283
|
-
}
|
|
284
|
-
|
|
229
|
+
}
|
|
285
230
|
|
|
231
|
+
// Write the initial comment, if any.
|
|
286
232
|
var variationComment = this.extractComment(variation);
|
|
287
|
-
|
|
288
233
|
if (variationComment !== undefined) {
|
|
289
234
|
if (variation.isLongComment()) {
|
|
290
235
|
moveGroups.push(this.renderComment(variation, variationComment, true));
|
|
291
236
|
} else {
|
|
292
237
|
currentMoveGroupElements.push(this.renderComment(variation, variationComment, true));
|
|
293
238
|
}
|
|
294
|
-
}
|
|
295
|
-
|
|
239
|
+
}
|
|
296
240
|
|
|
241
|
+
// Visit all the PGN nodes (one node per move) within the variation.
|
|
297
242
|
var forcePrintMoveNumber = true;
|
|
298
243
|
var node = variation.first();
|
|
299
|
-
|
|
300
244
|
while (node !== undefined) {
|
|
301
245
|
// Write the move, including directly related information (i.e. move number + NAGs).
|
|
302
|
-
currentMoveGroupElements.push(this.renderMove(notationTextBuilder, node, forcePrintMoveNumber));
|
|
246
|
+
currentMoveGroupElements.push(this.renderMove(notationTextBuilder, node, forcePrintMoveNumber));
|
|
303
247
|
|
|
248
|
+
// Write the comment (if any).
|
|
304
249
|
var nodeComment = this.extractComment(node);
|
|
305
|
-
|
|
306
250
|
if (nodeComment !== undefined) {
|
|
307
251
|
if (node.isLongComment()) {
|
|
308
252
|
closeMoveGroup();
|
|
@@ -310,22 +254,18 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
310
254
|
} else {
|
|
311
255
|
currentMoveGroupElements.push(this.renderComment(node, nodeComment, false));
|
|
312
256
|
}
|
|
313
|
-
}
|
|
314
|
-
|
|
257
|
+
}
|
|
315
258
|
|
|
259
|
+
// Write the sub-variations.
|
|
316
260
|
var hasNonEmptySubVariations = false;
|
|
317
|
-
|
|
318
261
|
var _iterator = _createForOfIteratorHelper(node.variations().entries()),
|
|
319
|
-
|
|
320
|
-
|
|
262
|
+
_step;
|
|
321
263
|
try {
|
|
322
264
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
323
265
|
var _step$value = _slicedToArray(_step.value, 2),
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
266
|
+
index = _step$value[0],
|
|
267
|
+
subVariation = _step$value[1];
|
|
327
268
|
var subVariationElement = this.renderVariation(notationTextBuilder, subVariation, node.fullMoveNumber() + node.moveColor() + '-variation-' + index, false);
|
|
328
|
-
|
|
329
269
|
if (subVariationElement) {
|
|
330
270
|
if (subVariation.isLongVariation()) {
|
|
331
271
|
closeMoveGroup();
|
|
@@ -333,37 +273,34 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
333
273
|
} else {
|
|
334
274
|
currentMoveGroupElements.push(subVariationElement);
|
|
335
275
|
}
|
|
336
|
-
|
|
337
276
|
hasNonEmptySubVariations = true;
|
|
338
277
|
}
|
|
339
|
-
}
|
|
278
|
+
}
|
|
340
279
|
|
|
280
|
+
// Back to the current variation, go to the next move.
|
|
341
281
|
} catch (err) {
|
|
342
282
|
_iterator.e(err);
|
|
343
283
|
} finally {
|
|
344
284
|
_iterator.f();
|
|
345
285
|
}
|
|
346
|
-
|
|
347
286
|
forcePrintMoveNumber = nodeComment !== undefined || hasNonEmptySubVariations;
|
|
348
287
|
node = node.next();
|
|
349
|
-
}
|
|
350
|
-
|
|
288
|
+
}
|
|
351
289
|
|
|
290
|
+
// Append the game result at the end of the main variation.
|
|
352
291
|
if (isMainVariation && gameResult !== '*') {
|
|
353
292
|
currentMoveGroupElements.push( /*#__PURE__*/_react["default"].createElement("span", {
|
|
354
293
|
className: "kokopu-gameResult",
|
|
355
294
|
key: "gameResult"
|
|
356
295
|
}, formatResult(gameResult)));
|
|
357
|
-
}
|
|
358
|
-
|
|
296
|
+
}
|
|
359
297
|
|
|
298
|
+
// Close the last move group, and return the result.
|
|
360
299
|
closeMoveGroup();
|
|
361
300
|
var elements = variation.isLongVariation() ? moveGroups : currentMoveGroupElements;
|
|
362
|
-
|
|
363
301
|
if (elements.length === 0) {
|
|
364
302
|
return undefined;
|
|
365
303
|
}
|
|
366
|
-
|
|
367
304
|
if (isMainVariation) {
|
|
368
305
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
369
306
|
className: "kokopu-variation kokopu-mainVariation",
|
|
@@ -381,51 +318,47 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
381
318
|
}, elements);
|
|
382
319
|
}
|
|
383
320
|
}
|
|
321
|
+
|
|
384
322
|
/**
|
|
385
323
|
* Render the given move, move number, and NAG (if any).
|
|
386
324
|
*/
|
|
387
|
-
|
|
388
325
|
}, {
|
|
389
326
|
key: "renderMove",
|
|
390
327
|
value: function renderMove(notationTextBuilder, node, forcePrintMoveNumber) {
|
|
391
328
|
var _this3 = this;
|
|
392
|
-
|
|
393
329
|
// Move number
|
|
394
330
|
var moveNumber = undefined;
|
|
395
|
-
|
|
396
331
|
if (forcePrintMoveNumber || node.moveColor() === 'w') {
|
|
397
332
|
var moveNumberText = node.fullMoveNumber() + (node.moveColor() === 'w' ? '.' : "\u2026");
|
|
398
333
|
moveNumber = /*#__PURE__*/_react["default"].createElement("span", {
|
|
399
334
|
className: "kokopu-moveNumber"
|
|
400
335
|
}, moveNumberText);
|
|
401
|
-
}
|
|
402
|
-
|
|
336
|
+
}
|
|
403
337
|
|
|
404
|
-
|
|
338
|
+
// SAN notation.
|
|
339
|
+
var notationText = notationTextBuilder(node.notation());
|
|
405
340
|
|
|
341
|
+
// NAGs
|
|
406
342
|
var nagElements = node.nags().map(function (nag) {
|
|
407
343
|
return /*#__PURE__*/_react["default"].createElement("span", {
|
|
408
344
|
className: "kokopu-nag",
|
|
409
345
|
key: nag
|
|
410
346
|
}, (0, _kokopu.nagSymbol)(nag));
|
|
411
|
-
});
|
|
347
|
+
});
|
|
412
348
|
|
|
349
|
+
// Class
|
|
413
350
|
var nodeId = node.id();
|
|
414
351
|
var moveClassNames = ['kokopu-move'];
|
|
415
352
|
var onClick = undefined;
|
|
416
|
-
|
|
417
353
|
if (this.props.selection && this.props.selection === nodeId) {
|
|
418
354
|
moveClassNames.push('kokopu-selectedMove');
|
|
419
355
|
}
|
|
420
|
-
|
|
421
356
|
if (this.props.interactionMode === 'selectMove') {
|
|
422
357
|
moveClassNames.push('kokopu-clickableMove');
|
|
423
|
-
|
|
424
358
|
onClick = function onClick() {
|
|
425
359
|
return _this3.handleNodeClicked(nodeId);
|
|
426
360
|
};
|
|
427
361
|
}
|
|
428
|
-
|
|
429
362
|
return /*#__PURE__*/_react["default"].createElement("span", {
|
|
430
363
|
className: moveClassNames.join(' '),
|
|
431
364
|
key: node.fullMoveNumber() + node.moveColor()
|
|
@@ -436,32 +369,27 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
436
369
|
className: "kokopu-moveNotation"
|
|
437
370
|
}, notationText), nagElements.length === 0 ? undefined : nagElements));
|
|
438
371
|
}
|
|
372
|
+
|
|
439
373
|
/**
|
|
440
374
|
* Render the given text comment with its diagrams, if any.
|
|
441
375
|
*/
|
|
442
|
-
|
|
443
376
|
}, {
|
|
444
377
|
key: "renderComment",
|
|
445
378
|
value: function renderComment(node, comment, isVariation) {
|
|
446
379
|
var content;
|
|
447
380
|
var sanitizer = createSanitizer(true);
|
|
448
|
-
|
|
449
381
|
if (this.props.diagramVisible && comment.includes('[#]')) {
|
|
450
382
|
content = [];
|
|
451
383
|
var isFirstPart = true;
|
|
452
|
-
|
|
453
384
|
var _iterator2 = _createForOfIteratorHelper(comment.split('[#]').entries()),
|
|
454
|
-
|
|
455
|
-
|
|
385
|
+
_step2;
|
|
456
386
|
try {
|
|
457
387
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
458
388
|
var _step2$value = _slicedToArray(_step2.value, 2),
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
389
|
+
index = _step2$value[0],
|
|
390
|
+
part = _step2$value[1];
|
|
462
391
|
if (!isFirstPart) {
|
|
463
392
|
var position = isVariation ? node.initialPosition() : node.position();
|
|
464
|
-
|
|
465
393
|
var diagram = /*#__PURE__*/_react["default"].createElement(_Chessboard["default"], {
|
|
466
394
|
position: position,
|
|
467
395
|
squareMarkers: node.tag('csl'),
|
|
@@ -474,16 +402,13 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
474
402
|
colorset: this.props.diagramOptions.colorset,
|
|
475
403
|
pieceset: this.props.diagramOptions.pieceset
|
|
476
404
|
});
|
|
477
|
-
|
|
478
405
|
content.push( /*#__PURE__*/_react["default"].createElement("div", {
|
|
479
406
|
className: "kokopu-diagram",
|
|
480
407
|
key: 'diagram-' + index
|
|
481
408
|
}, diagram));
|
|
482
409
|
}
|
|
483
|
-
|
|
484
410
|
isFirstPart = false;
|
|
485
411
|
part = part.trim();
|
|
486
|
-
|
|
487
412
|
if (part.length !== 0) {
|
|
488
413
|
content.push(sanitizeHtml(part, sanitizer));
|
|
489
414
|
}
|
|
@@ -496,7 +421,6 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
496
421
|
} else {
|
|
497
422
|
content = sanitizeHtml(comment, sanitizer);
|
|
498
423
|
}
|
|
499
|
-
|
|
500
424
|
var key = isVariation ? 'initial-comment' : node.fullMoveNumber() + node.moveColor() + '-comment';
|
|
501
425
|
return node.isLongComment() ? /*#__PURE__*/_react["default"].createElement("div", {
|
|
502
426
|
className: "kokopu-comment",
|
|
@@ -510,17 +434,15 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
510
434
|
key: "extractComment",
|
|
511
435
|
value: function extractComment(node) {
|
|
512
436
|
var comment = node.comment();
|
|
513
|
-
|
|
514
437
|
if (comment) {
|
|
515
438
|
// Remove the diagrams if necessary.
|
|
516
439
|
if (!this.props.diagramVisible) {
|
|
517
440
|
comment = comment.replace(/\[#\]/g, ' ');
|
|
518
|
-
}
|
|
519
|
-
|
|
441
|
+
}
|
|
520
442
|
|
|
443
|
+
// Trim and sanitize the space characters.
|
|
521
444
|
comment = comment.replace(/\s+/g, ' ').trim();
|
|
522
445
|
}
|
|
523
|
-
|
|
524
446
|
return comment ? comment : undefined;
|
|
525
447
|
}
|
|
526
448
|
}, {
|
|
@@ -529,16 +451,12 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
529
451
|
if (evt.key !== 'Home' && evt.key !== 'ArrowLeft' && evt.key !== 'ArrowRight' && evt.key !== 'End') {
|
|
530
452
|
return;
|
|
531
453
|
}
|
|
532
|
-
|
|
533
454
|
evt.preventDefault();
|
|
534
|
-
|
|
535
455
|
if (!this.props.selection) {
|
|
536
456
|
return;
|
|
537
457
|
}
|
|
538
|
-
|
|
539
458
|
var nodeId = undefined;
|
|
540
459
|
var evtOrigin = '';
|
|
541
|
-
|
|
542
460
|
if (evt.key === 'Home') {
|
|
543
461
|
nodeId = Movetext.firstNodeId(game, this.props.selection);
|
|
544
462
|
evtOrigin = 'key-first';
|
|
@@ -553,7 +471,6 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
553
471
|
nodeId = Movetext.lastNodeId(game, this.props.selection);
|
|
554
472
|
evtOrigin = 'key-last';
|
|
555
473
|
}
|
|
556
|
-
|
|
557
474
|
if (nodeId && this.props.onMoveSelected) {
|
|
558
475
|
this.props.onMoveSelected(nodeId, evtOrigin);
|
|
559
476
|
}
|
|
@@ -562,22 +479,22 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
562
479
|
key: "handleNodeClicked",
|
|
563
480
|
value: function handleNodeClicked(nodeId) {
|
|
564
481
|
this.focus();
|
|
565
|
-
|
|
566
482
|
if (this.props.onMoveSelected) {
|
|
567
483
|
this.props.onMoveSelected(nodeId === this.props.selection ? undefined : nodeId, 'click');
|
|
568
484
|
}
|
|
569
485
|
}
|
|
486
|
+
|
|
570
487
|
/**
|
|
571
488
|
* Set the focus to the current component.
|
|
572
489
|
*
|
|
573
490
|
* @public
|
|
574
491
|
*/
|
|
575
|
-
|
|
576
492
|
}, {
|
|
577
493
|
key: "focus",
|
|
578
494
|
value: function focus() {
|
|
579
495
|
this.focusFieldRef.current.focus();
|
|
580
496
|
}
|
|
497
|
+
|
|
581
498
|
/**
|
|
582
499
|
* Return the ID of the main variation in the given chess game.
|
|
583
500
|
* If the given selection corresponds already at the main variation, `undefined` is returned.
|
|
@@ -589,16 +506,15 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
589
506
|
* @returns {string?}
|
|
590
507
|
* @public
|
|
591
508
|
*/
|
|
592
|
-
|
|
593
509
|
}], [{
|
|
594
510
|
key: "firstNodeId",
|
|
595
511
|
value: function firstNodeId(game, selection) {
|
|
596
512
|
if (!game.findById(selection)) {
|
|
597
513
|
return undefined;
|
|
598
514
|
}
|
|
599
|
-
|
|
600
515
|
return selection === 'start' ? undefined : 'start';
|
|
601
516
|
}
|
|
517
|
+
|
|
602
518
|
/**
|
|
603
519
|
* Return the ID of the node immediately preceding the given selection in the given chess game.
|
|
604
520
|
* If no such node exists, `undefined` is returned.
|
|
@@ -610,16 +526,13 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
610
526
|
* @returns {string?}
|
|
611
527
|
* @public
|
|
612
528
|
*/
|
|
613
|
-
|
|
614
529
|
}, {
|
|
615
530
|
key: "previousNodeId",
|
|
616
531
|
value: function previousNodeId(game, selection) {
|
|
617
532
|
var currentNode = game.findById(selection);
|
|
618
|
-
|
|
619
533
|
if (!currentNode) {
|
|
620
534
|
return undefined;
|
|
621
535
|
}
|
|
622
|
-
|
|
623
536
|
if (selection === 'start') {
|
|
624
537
|
return undefined;
|
|
625
538
|
} else if (selection.endsWith('start')) {
|
|
@@ -628,16 +541,14 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
628
541
|
|
|
629
542
|
while (currentNode) {
|
|
630
543
|
var previousNode = currentNode.previous();
|
|
631
|
-
|
|
632
544
|
if (previousNode) {
|
|
633
545
|
return previousNode.id();
|
|
634
546
|
}
|
|
635
|
-
|
|
636
547
|
currentNode = currentNode.parentVariation().parentNode();
|
|
637
548
|
}
|
|
638
|
-
|
|
639
549
|
return 'start';
|
|
640
550
|
}
|
|
551
|
+
|
|
641
552
|
/**
|
|
642
553
|
* Return the ID of the node immediately following the given selection in the given chess game.
|
|
643
554
|
* If no such node exists, `undefined` is returned.
|
|
@@ -649,19 +560,17 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
649
560
|
* @returns {string?}
|
|
650
561
|
* @public
|
|
651
562
|
*/
|
|
652
|
-
|
|
653
563
|
}, {
|
|
654
564
|
key: "nextNodeId",
|
|
655
565
|
value: function nextNodeId(game, selection) {
|
|
656
566
|
var currentNode = game.findById(selection);
|
|
657
|
-
|
|
658
567
|
if (!currentNode) {
|
|
659
568
|
return undefined;
|
|
660
569
|
}
|
|
661
|
-
|
|
662
570
|
var nextNode = selection.endsWith('start') ? currentNode.first() : currentNode.next();
|
|
663
571
|
return nextNode ? nextNode.id() : undefined;
|
|
664
572
|
}
|
|
573
|
+
|
|
665
574
|
/**
|
|
666
575
|
* Return the ID of the node at then end of the variation in which lies the given selection in the given chess game.
|
|
667
576
|
* If the selection is already at the end its variation, `undefined` is returned.
|
|
@@ -673,38 +582,29 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
673
582
|
* @returns {string?}
|
|
674
583
|
* @public
|
|
675
584
|
*/
|
|
676
|
-
|
|
677
585
|
}, {
|
|
678
586
|
key: "lastNodeId",
|
|
679
587
|
value: function lastNodeId(game, selection) {
|
|
680
588
|
var currentNode = game.findById(selection);
|
|
681
|
-
|
|
682
589
|
if (!currentNode) {
|
|
683
590
|
return undefined;
|
|
684
591
|
}
|
|
685
|
-
|
|
686
592
|
currentNode = selection.endsWith('start') ? currentNode.first() : currentNode.next();
|
|
687
|
-
|
|
688
593
|
if (!currentNode) {
|
|
689
594
|
// Ensure that the input node is not already the last one.
|
|
690
595
|
return undefined;
|
|
691
596
|
}
|
|
692
|
-
|
|
693
597
|
while (true) {
|
|
694
598
|
var nextNode = currentNode.next();
|
|
695
|
-
|
|
696
599
|
if (!nextNode) {
|
|
697
600
|
return currentNode.id();
|
|
698
601
|
}
|
|
699
|
-
|
|
700
602
|
currentNode = nextNode;
|
|
701
603
|
}
|
|
702
604
|
}
|
|
703
605
|
}]);
|
|
704
|
-
|
|
705
606
|
return Movetext;
|
|
706
607
|
}(_react["default"].Component);
|
|
707
|
-
|
|
708
608
|
exports["default"] = Movetext;
|
|
709
609
|
Movetext.propTypes = {
|
|
710
610
|
/**
|
|
@@ -713,14 +613,12 @@ Movetext.propTypes = {
|
|
|
713
613
|
* or a [PGN string](https://en.wikipedia.org/wiki/Portable_Game_Notation).
|
|
714
614
|
*/
|
|
715
615
|
game: _propTypes["default"].oneOfType([_propTypes["default"].instanceOf(_kokopu.Game), _propTypes["default"].instanceOf(_kokopu.Database), _propTypes["default"].string]),
|
|
716
|
-
|
|
717
616
|
/**
|
|
718
617
|
* Index of the game to display (only if attribute `game` is a [kokopu.Database](https://kokopu.yo35.org/docs/current/classes/Database.html)
|
|
719
618
|
* or a [PGN string](https://en.wikipedia.org/wiki/Portable_Game_Notation)): `0` for the first game of the database/PGN, `1` for the second one, etc.
|
|
720
619
|
* If omitted, the first game of the database/PGN is displayed.
|
|
721
620
|
*/
|
|
722
621
|
gameIndex: _propTypes["default"].number,
|
|
723
|
-
|
|
724
622
|
/**
|
|
725
623
|
* Options applicable to the diagrams in the comments. See [Chessboard](#/Components/Chessboard) for more details about each option.
|
|
726
624
|
*/
|
|
@@ -732,7 +630,6 @@ Movetext.propTypes = {
|
|
|
732
630
|
colorset: _Chessboard["default"].propTypes.colorset,
|
|
733
631
|
pieceset: _Chessboard["default"].propTypes.pieceset
|
|
734
632
|
}),
|
|
735
|
-
|
|
736
633
|
/**
|
|
737
634
|
* Symbols to use for the chess pieces. Can be:
|
|
738
635
|
* - `'native'`: use the first letter of the piece names (in English),
|
|
@@ -748,30 +645,25 @@ Movetext.propTypes = {
|
|
|
748
645
|
N: _propTypes["default"].string.isRequired,
|
|
749
646
|
P: _propTypes["default"].string.isRequired
|
|
750
647
|
})]),
|
|
751
|
-
|
|
752
648
|
/**
|
|
753
649
|
* Whether the diagrams within the comments (if any) are displayed or not.
|
|
754
650
|
*/
|
|
755
651
|
diagramVisible: _propTypes["default"].bool,
|
|
756
|
-
|
|
757
652
|
/**
|
|
758
653
|
* Whether the game headers (if any) are displayed or not.
|
|
759
654
|
*/
|
|
760
655
|
headerVisible: _propTypes["default"].bool,
|
|
761
|
-
|
|
762
656
|
/**
|
|
763
657
|
* ID of the selected move (or `'start'` for the beginning of the main variation).
|
|
764
658
|
* Use [kokopu.Node#id](https://kokopu.yo35.org/docs/current/classes/Node.html#id) to get the ID of a game move.
|
|
765
659
|
*/
|
|
766
660
|
selection: _propTypes["default"].string,
|
|
767
|
-
|
|
768
661
|
/**
|
|
769
662
|
* Type of action allowed with the mouse/keys on the component. If undefined, then the user cannot interact with the component.
|
|
770
663
|
*
|
|
771
664
|
* - `'selectMove'` allows the user to select a move.
|
|
772
665
|
*/
|
|
773
666
|
interactionMode: _propTypes["default"].oneOf(['selectMove']),
|
|
774
|
-
|
|
775
667
|
/**
|
|
776
668
|
* Callback invoked when the user selects a move (only if `interactionMode` is set to `'selectMove'`).
|
|
777
669
|
*
|
|
@@ -794,76 +686,83 @@ Movetext.defaultProps = {
|
|
|
794
686
|
diagramVisible: true,
|
|
795
687
|
headerVisible: true
|
|
796
688
|
};
|
|
689
|
+
|
|
797
690
|
/**
|
|
798
691
|
* Example: `'hello world'` is turned into `'Hello world'`.
|
|
799
692
|
*/
|
|
800
|
-
|
|
801
693
|
function capitalizeFirstWord(text) {
|
|
802
694
|
return text.length === 0 ? '' : text.charAt(0).toUpperCase() + text.slice(1);
|
|
803
695
|
}
|
|
804
|
-
|
|
805
696
|
function formatResult(result) {
|
|
806
697
|
switch (result) {
|
|
807
698
|
case '1/2-1/2':
|
|
808
699
|
return "\xBD\u2013\xBD";
|
|
809
|
-
|
|
810
700
|
case '1-0':
|
|
811
701
|
return "1\u20130";
|
|
812
|
-
|
|
813
702
|
case '0-1':
|
|
814
703
|
return "0\u20131";
|
|
815
704
|
}
|
|
816
705
|
}
|
|
817
|
-
|
|
818
706
|
function createSanitizer(withBlockTags) {
|
|
819
|
-
var allowedTags = ['span',
|
|
820
|
-
|
|
821
|
-
'
|
|
822
|
-
|
|
823
|
-
'
|
|
824
|
-
|
|
825
|
-
'
|
|
826
|
-
|
|
707
|
+
var allowedTags = ['span',
|
|
708
|
+
// general purpose
|
|
709
|
+
'a',
|
|
710
|
+
// links
|
|
711
|
+
'b', 'strong', 'i', 'em',
|
|
712
|
+
// bold, italic
|
|
713
|
+
'del', 'ins', 's', 'u',
|
|
714
|
+
// underline, strikethrough
|
|
715
|
+
'sub', 'sup',
|
|
716
|
+
// subscript, superscript
|
|
717
|
+
'abbr',
|
|
718
|
+
// acronym (typically associated to a title=".." tooltip)
|
|
719
|
+
'q', 'cite',
|
|
720
|
+
// quotation and title of a work
|
|
721
|
+
'mark',
|
|
722
|
+
// highlighted text
|
|
827
723
|
'small' // smaller text
|
|
828
724
|
];
|
|
725
|
+
|
|
829
726
|
var allowedAttributes = {
|
|
830
727
|
'*': ['class', 'id', 'title'],
|
|
831
728
|
'a': ['href', 'target']
|
|
832
729
|
};
|
|
833
|
-
|
|
834
730
|
if (withBlockTags) {
|
|
835
|
-
allowedTags = allowedTags.concat(['div',
|
|
836
|
-
|
|
837
|
-
'
|
|
838
|
-
|
|
839
|
-
'
|
|
840
|
-
|
|
731
|
+
allowedTags = allowedTags.concat(['div',
|
|
732
|
+
// general purpose
|
|
733
|
+
'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
|
|
734
|
+
// headings
|
|
735
|
+
'p', 'br',
|
|
736
|
+
// paragraph and line break
|
|
737
|
+
'blockquote',
|
|
738
|
+
// long quotation
|
|
739
|
+
'img',
|
|
740
|
+
// image
|
|
741
|
+
'pre',
|
|
742
|
+
// preformatted text
|
|
841
743
|
'ul', 'ol', 'li' // lists
|
|
842
744
|
]);
|
|
745
|
+
|
|
843
746
|
Object.assign(allowedAttributes, {
|
|
844
747
|
'img': ['alt', 'src', 'height', 'width']
|
|
845
748
|
});
|
|
846
749
|
}
|
|
847
|
-
|
|
848
750
|
return new _HtmlSanitizer["default"]({
|
|
849
751
|
allowedTags: allowedTags,
|
|
850
752
|
allowedAttributes: allowedAttributes
|
|
851
753
|
});
|
|
852
754
|
}
|
|
853
|
-
|
|
854
755
|
function sanitizeHtml(text, sanitizer) {
|
|
855
756
|
if (!sanitizer) {
|
|
856
757
|
sanitizer = createSanitizer(false);
|
|
857
758
|
}
|
|
858
|
-
|
|
859
759
|
var result = sanitizer.parse(text);
|
|
860
760
|
return result !== null && result !== void 0 ? result : text;
|
|
861
761
|
}
|
|
762
|
+
|
|
862
763
|
/**
|
|
863
764
|
* Try to interpret the given object as a chess game.
|
|
864
765
|
*/
|
|
865
|
-
|
|
866
|
-
|
|
867
766
|
function parseGame(game, gameIndex) {
|
|
868
767
|
if (game instanceof _kokopu.Game) {
|
|
869
768
|
return {
|
|
@@ -877,7 +776,6 @@ function parseGame(game, gameIndex) {
|
|
|
877
776
|
message: _i18n["default"].INVALID_GAME_INDEX_ATTRIBUTE_ERROR_MESSAGE
|
|
878
777
|
};
|
|
879
778
|
}
|
|
880
|
-
|
|
881
779
|
try {
|
|
882
780
|
var result = game instanceof _kokopu.Database ? game.game(gameIndex) : (0, _kokopu.pgnRead)(game, gameIndex);
|
|
883
781
|
return {
|