@twreporter/react-components 8.5.0-rc.1
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 +544 -0
- package/LICENSE +21 -0
- package/README.md +46 -0
- package/lib/bookmark-list/bookmark.js +251 -0
- package/lib/bookmark-list/bookmarks.js +93 -0
- package/lib/bookmark-list/customized-link.js +45 -0
- package/lib/bookmark-list/image-wrapper.js +119 -0
- package/lib/bookmark-list/index.js +312 -0
- package/lib/bookmark-list/redirect-to-sign-in.js +35 -0
- package/lib/bookmark-widget/index.js +259 -0
- package/lib/confirmation/index.js +125 -0
- package/lib/donation-link.js +75 -0
- package/lib/error/index.js +17 -0
- package/lib/error/message.js +567 -0
- package/lib/footer/constants/paths.js +8 -0
- package/lib/footer/constants/styles.js +81 -0
- package/lib/footer/content.js +227 -0
- package/lib/footer/icon-list.js +191 -0
- package/lib/footer/index.js +123 -0
- package/lib/footer/logo.js +92 -0
- package/lib/is-fetching-wrapper.js +126 -0
- package/lib/link-with-tracker.js +153 -0
- package/lib/listing-page/components/image.js +185 -0
- package/lib/listing-page/components/list-item.js +197 -0
- package/lib/listing-page/components/list.js +188 -0
- package/lib/listing-page/components/topics/index.js +215 -0
- package/lib/listing-page/components/topics/page-content.js +44 -0
- package/lib/listing-page/components/topics/post-item.js +139 -0
- package/lib/listing-page/components/topics/posts.js +24 -0
- package/lib/listing-page/components/topics/section.js +104 -0
- package/lib/listing-page/components/topics/topic-item.js +206 -0
- package/lib/listing-page/constants/mockup-spec.js +39 -0
- package/lib/listing-page/constants/predefined-css.js +21 -0
- package/lib/listing-page/constants/topics.js +13 -0
- package/lib/listing-page/index.js +30 -0
- package/lib/mobile-pop-up-modal.js +161 -0
- package/lib/more.js +98 -0
- package/lib/pagination/index.js +310 -0
- package/lib/podcast-link.js +73 -0
- package/lib/side-bar/index.js +317 -0
- package/lib/table-of-contents/index.js +532 -0
- package/lib/utils/link-with-params.js +27 -0
- package/package.json +33 -0
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
var _react = _interopRequireDefault(require("react"));
|
|
13
|
+
|
|
14
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
|
15
|
+
|
|
16
|
+
var _indexOf = _interopRequireDefault(require("lodash/indexOf"));
|
|
17
|
+
|
|
18
|
+
var _memoizeOne = _interopRequireDefault(require("memoize-one"));
|
|
19
|
+
|
|
20
|
+
var _smoothscroll = _interopRequireDefault(require("smoothscroll"));
|
|
21
|
+
|
|
22
|
+
var _some = _interopRequireDefault(require("lodash/some"));
|
|
23
|
+
|
|
24
|
+
var _sortBy = _interopRequireDefault(require("lodash/sortBy"));
|
|
25
|
+
|
|
26
|
+
var _debounce = _interopRequireDefault(require("lodash/debounce"));
|
|
27
|
+
|
|
28
|
+
var _reactWaypoint = require("react-waypoint");
|
|
29
|
+
|
|
30
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
31
|
+
|
|
32
|
+
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); }
|
|
33
|
+
|
|
34
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
35
|
+
|
|
36
|
+
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); }; }
|
|
37
|
+
|
|
38
|
+
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); }
|
|
39
|
+
|
|
40
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
41
|
+
|
|
42
|
+
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; } }
|
|
43
|
+
|
|
44
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
45
|
+
|
|
46
|
+
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
|
+
|
|
50
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
51
|
+
|
|
52
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
53
|
+
|
|
54
|
+
var _ = {
|
|
55
|
+
debounce: _debounce["default"],
|
|
56
|
+
get: _get["default"],
|
|
57
|
+
indexOf: _indexOf["default"],
|
|
58
|
+
some: _some["default"],
|
|
59
|
+
sortBy: _sortBy["default"]
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* TOCManager is a bridge between `Anchor` and `TableOfContents`.
|
|
63
|
+
* It provides APIs to make them communicate with each others.
|
|
64
|
+
* For instances, `TOCManager` provides `Anchor`s for `TableOfContents`,
|
|
65
|
+
* hence, `TableOfContents` could know how to render correspoding labels and
|
|
66
|
+
* know how to handle those labels clicked(scroll to that `Anchor`).
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
var TOCManager = /*#__PURE__*/function () {
|
|
70
|
+
/**
|
|
71
|
+
* @constructs
|
|
72
|
+
* @param {Object} props
|
|
73
|
+
* @param {Anchor[]} [props.anchors=[]] - anchors of table of contents
|
|
74
|
+
* @param {Anchor} [props.highlightAnchor=null] - it indicates which anchor is entering the viewport and should be highlighted
|
|
75
|
+
* @param {TableOfContents} [props.toc=null] - table of contents
|
|
76
|
+
* @param {boolean} [props.toStopAutoUpdateHighlightAnchor=false] - it stops automatically updating highlight anchor
|
|
77
|
+
*/
|
|
78
|
+
function TOCManager() {
|
|
79
|
+
var _this = this;
|
|
80
|
+
|
|
81
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
82
|
+
_ref$anchors = _ref.anchors,
|
|
83
|
+
_anchors = _ref$anchors === void 0 ? [] : _ref$anchors,
|
|
84
|
+
_ref$highlightAnchor = _ref.highlightAnchor,
|
|
85
|
+
highlightAnchor = _ref$highlightAnchor === void 0 ? null : _ref$highlightAnchor,
|
|
86
|
+
_ref$toc = _ref.toc,
|
|
87
|
+
toc = _ref$toc === void 0 ? null : _ref$toc,
|
|
88
|
+
_ref$toStopAutoUpdate = _ref.toStopAutoUpdateHighlightAnchor,
|
|
89
|
+
toStopAutoUpdateHighlightAnchor = _ref$toStopAutoUpdate === void 0 ? false : _ref$toStopAutoUpdate;
|
|
90
|
+
|
|
91
|
+
_classCallCheck(this, TOCManager);
|
|
92
|
+
|
|
93
|
+
_defineProperty(this, "renderTOC", _.debounce(function () {
|
|
94
|
+
if (_this._toc instanceof TableOfContents) {
|
|
95
|
+
_this._toc.forceUpdate();
|
|
96
|
+
}
|
|
97
|
+
}, 100));
|
|
98
|
+
|
|
99
|
+
_defineProperty(this, "updateHighlightAnchor", _.debounce(function () {
|
|
100
|
+
// sort the anchors by the distance to viewport top in ascending order.
|
|
101
|
+
// the reason to sort anchors is because CSS styles(like flex order) might
|
|
102
|
+
// change the anchors' position.
|
|
103
|
+
var anchors = _this.memoizeSortAnchorsByViewportTop(_this._anchors);
|
|
104
|
+
|
|
105
|
+
if (anchors.length === 0) {
|
|
106
|
+
return;
|
|
107
|
+
} // viewport is above first anchor
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
var firstAnchor = anchors[0];
|
|
111
|
+
|
|
112
|
+
if (firstAnchor.currentPosition === TOCManager.position.below) {
|
|
113
|
+
_this.highlightAnchor = null;
|
|
114
|
+
return;
|
|
115
|
+
} // viewport is below last anchor
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
var lastAnchor = anchors[anchors.length - 1];
|
|
119
|
+
|
|
120
|
+
if (lastAnchor.currentPosition === TOCManager.position.above) {
|
|
121
|
+
_this.highlightAnchor = lastAnchor;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
_.some(anchors, function (anchor, index) {
|
|
126
|
+
var curAnchor = anchor;
|
|
127
|
+
var nextAnchor = anchors[index + 1];
|
|
128
|
+
|
|
129
|
+
if ( // anchor[i] is inside the viewport
|
|
130
|
+
curAnchor.currentPosition === TOCManager.position.inside || curAnchor.currentPosition === TOCManager.position.above && nextAnchor instanceof Anchor && nextAnchor.currentPosition === TOCManager.position.below) {
|
|
131
|
+
_this.highlightAnchor = curAnchor;
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return false;
|
|
136
|
+
});
|
|
137
|
+
}, 100));
|
|
138
|
+
|
|
139
|
+
_defineProperty(this, "memoizeSortAnchorsByViewportTop", (0, _memoizeOne["default"])(this.sortAnchorsByViewportTop));
|
|
140
|
+
|
|
141
|
+
this._anchors = _anchors;
|
|
142
|
+
this._highlightAnchor = highlightAnchor;
|
|
143
|
+
this._toc = toc;
|
|
144
|
+
this._toStopAutoUpdateHighlightAnchor = toStopAutoUpdateHighlightAnchor;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* use `Array.concat` to add `Anchor` into array
|
|
148
|
+
*
|
|
149
|
+
* @method
|
|
150
|
+
* @param {Anchor} anchor - an instance of `Anchor`
|
|
151
|
+
* @returns
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
_createClass(TOCManager, [{
|
|
156
|
+
key: "addAnchor",
|
|
157
|
+
value: function addAnchor(anchor) {
|
|
158
|
+
if (anchor instanceof Anchor) {
|
|
159
|
+
// we don't use `this._anchors.push(anchor)` here.
|
|
160
|
+
// Instead, we use `concat` function to create a new array.
|
|
161
|
+
// The reason why we create a new array is because
|
|
162
|
+
// we want to make `TableOfContents(PureComponent)` re-render
|
|
163
|
+
this._anchors = this._anchors.concat(anchor);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Re-render `TableOfContents` if needed.
|
|
168
|
+
* Use debounce for optimizing rendering performance.
|
|
169
|
+
* @returns
|
|
170
|
+
*/
|
|
171
|
+
|
|
172
|
+
}, {
|
|
173
|
+
key: "sortAnchorsByViewportTop",
|
|
174
|
+
value:
|
|
175
|
+
/**
|
|
176
|
+
* Sort anchors by the distance to viewport top in ascending order.
|
|
177
|
+
* @param {Anchor[]} anchors
|
|
178
|
+
* @returns {Anchor[]}
|
|
179
|
+
*/
|
|
180
|
+
function sortAnchorsByViewportTop(anchors) {
|
|
181
|
+
return _.sortBy(anchors, function (anchor) {
|
|
182
|
+
return anchor.getViewportTop();
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Use memoize to improve performance
|
|
187
|
+
*/
|
|
188
|
+
|
|
189
|
+
}, {
|
|
190
|
+
key: "highlightAnchor",
|
|
191
|
+
get:
|
|
192
|
+
/**
|
|
193
|
+
* This a getter function.
|
|
194
|
+
* @method
|
|
195
|
+
* @return {Anchor} - the anchor is highlighted
|
|
196
|
+
*/
|
|
197
|
+
function get() {
|
|
198
|
+
return this._highlightAnchor;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* This is a setter function.
|
|
202
|
+
* @method
|
|
203
|
+
* @return {undefined}
|
|
204
|
+
*/
|
|
205
|
+
,
|
|
206
|
+
set:
|
|
207
|
+
/**
|
|
208
|
+
* This is a setter function.
|
|
209
|
+
* It indicates which anchor is entering the viewport
|
|
210
|
+
* and should be highlighted in the table of contents.
|
|
211
|
+
* @method
|
|
212
|
+
* @param {Anchor} anchor - an instance of `Anchor`
|
|
213
|
+
* @returns
|
|
214
|
+
*/
|
|
215
|
+
function set(anchor) {
|
|
216
|
+
if (anchor instanceof Anchor) {
|
|
217
|
+
this._highlightAnchor = anchor;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (this._toc instanceof TableOfContents) {
|
|
221
|
+
this._toc.setHighlightAnchor(anchor);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}, {
|
|
225
|
+
key: "anchors",
|
|
226
|
+
get:
|
|
227
|
+
/**
|
|
228
|
+
* This is a getter function.
|
|
229
|
+
* @method
|
|
230
|
+
* @returns {Anchor[]}
|
|
231
|
+
*/
|
|
232
|
+
function get() {
|
|
233
|
+
return this._anchors;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* This is a setter function.
|
|
237
|
+
* @method
|
|
238
|
+
* @returns
|
|
239
|
+
*/
|
|
240
|
+
,
|
|
241
|
+
set: function set(anchors) {
|
|
242
|
+
this._anchors = anchors;
|
|
243
|
+
}
|
|
244
|
+
}, {
|
|
245
|
+
key: "toc",
|
|
246
|
+
get:
|
|
247
|
+
/**
|
|
248
|
+
* This is a getter function.
|
|
249
|
+
* @method
|
|
250
|
+
* @returns {TableOfContents}
|
|
251
|
+
*/
|
|
252
|
+
function get() {
|
|
253
|
+
return this._toc;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* This is a setter function.
|
|
257
|
+
* @method
|
|
258
|
+
* @returns
|
|
259
|
+
*/
|
|
260
|
+
,
|
|
261
|
+
set: function set(toc) {
|
|
262
|
+
this._toc = toc;
|
|
263
|
+
}
|
|
264
|
+
}, {
|
|
265
|
+
key: "toStopAutoUpdateHighlightAnchor",
|
|
266
|
+
get:
|
|
267
|
+
/**
|
|
268
|
+
* This is a getter function.
|
|
269
|
+
* @method
|
|
270
|
+
* @returns {boolean}
|
|
271
|
+
*/
|
|
272
|
+
function get() {
|
|
273
|
+
return this._toStopAutoUpdateHighlightAnchor;
|
|
274
|
+
},
|
|
275
|
+
set: function set(toStopAutoUpdateHighlightAnchor) {
|
|
276
|
+
this._toStopAutoUpdateHighlightAnchor = toStopAutoUpdateHighlightAnchor;
|
|
277
|
+
}
|
|
278
|
+
}]);
|
|
279
|
+
|
|
280
|
+
return TOCManager;
|
|
281
|
+
}();
|
|
282
|
+
|
|
283
|
+
_defineProperty(TOCManager, "position", {
|
|
284
|
+
above: _reactWaypoint.Waypoint.above,
|
|
285
|
+
below: _reactWaypoint.Waypoint.below,
|
|
286
|
+
inside: _reactWaypoint.Waypoint.inside,
|
|
287
|
+
invisible: _reactWaypoint.Waypoint.invisible
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
var Anchor = /*#__PURE__*/function (_React$PureComponent) {
|
|
291
|
+
_inherits(Anchor, _React$PureComponent);
|
|
292
|
+
|
|
293
|
+
var _super = _createSuper(Anchor);
|
|
294
|
+
|
|
295
|
+
function Anchor(props) {
|
|
296
|
+
var _this2;
|
|
297
|
+
|
|
298
|
+
_classCallCheck(this, Anchor);
|
|
299
|
+
|
|
300
|
+
_this2 = _super.call(this, props);
|
|
301
|
+
_this2._ref = /*#__PURE__*/_react["default"].createRef();
|
|
302
|
+
_this2.getViewportTop = _this2._getViewportTop.bind(_assertThisInitialized(_this2));
|
|
303
|
+
_this2.handleOnPositionChange = _this2._handleOnPositionChange.bind(_assertThisInitialized(_this2));
|
|
304
|
+
_this2.currentPosition = TOCManager.position.invisible;
|
|
305
|
+
var manager = props.manager;
|
|
306
|
+
manager.addAnchor(_assertThisInitialized(_this2));
|
|
307
|
+
manager.renderTOC();
|
|
308
|
+
return _this2;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* @returns {number} - the distance between the top edge of anchor and the top of window
|
|
312
|
+
*/
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
_createClass(Anchor, [{
|
|
316
|
+
key: "_getViewportTop",
|
|
317
|
+
value: function _getViewportTop() {
|
|
318
|
+
try {
|
|
319
|
+
if (typeof window !== 'undefined' && this._ref.current) {
|
|
320
|
+
var scrollY = window.scrollY;
|
|
321
|
+
|
|
322
|
+
var _this$_ref$current$ge = this._ref.current.getBoundingClientRect(),
|
|
323
|
+
_this$_ref$current$ge2 = _this$_ref$current$ge.top,
|
|
324
|
+
top = _this$_ref$current$ge2 === void 0 ? 0 : _this$_ref$current$ge2;
|
|
325
|
+
|
|
326
|
+
return scrollY + top;
|
|
327
|
+
}
|
|
328
|
+
} catch (e) {
|
|
329
|
+
console.warn("Anchor(id: ".concat(this.props.id, ").getViewportTop occurs error"), e);
|
|
330
|
+
console.warn('Return default value: 0');
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return 0;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* @param {Object} [posObj={}]
|
|
337
|
+
* @param {string} [posObj.currentPosition=''] - it could be one of
|
|
338
|
+
* Waypoint.below, Waypoint.above, Waypoint.inside and Waypoint.invisible
|
|
339
|
+
*
|
|
340
|
+
* @returns
|
|
341
|
+
*/
|
|
342
|
+
|
|
343
|
+
}, {
|
|
344
|
+
key: "_handleOnPositionChange",
|
|
345
|
+
value: function _handleOnPositionChange() {
|
|
346
|
+
var posObj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
347
|
+
var manager = this.props.manager;
|
|
348
|
+
this.currentPosition = posObj.currentPosition;
|
|
349
|
+
|
|
350
|
+
if (manager.toStopAutoUpdateHighlightAnchor) {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
manager.updateHighlightAnchor();
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* This is a getter function.
|
|
358
|
+
* @method
|
|
359
|
+
* @returns {string} - id of anchor
|
|
360
|
+
*/
|
|
361
|
+
|
|
362
|
+
}, {
|
|
363
|
+
key: "anchorID",
|
|
364
|
+
get: function get() {
|
|
365
|
+
return this.props.id;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* This is a getter function.
|
|
369
|
+
* @method
|
|
370
|
+
* @returns {string} - label of anchor
|
|
371
|
+
*/
|
|
372
|
+
|
|
373
|
+
}, {
|
|
374
|
+
key: "anchorLable",
|
|
375
|
+
get: function get() {
|
|
376
|
+
return this.props.label;
|
|
377
|
+
}
|
|
378
|
+
}, {
|
|
379
|
+
key: "render",
|
|
380
|
+
value: function render() {
|
|
381
|
+
var _this$props = this.props,
|
|
382
|
+
bottomOffset = _this$props.bottomOffset,
|
|
383
|
+
className = _this$props.className,
|
|
384
|
+
children = _this$props.children,
|
|
385
|
+
id = _this$props.id,
|
|
386
|
+
topOffset = _this$props.topOffset;
|
|
387
|
+
return (
|
|
388
|
+
/*#__PURE__*/
|
|
389
|
+
// set fireOnRapidScroll=false since we are not using `onEnter` and `onLeave`
|
|
390
|
+
_react["default"].createElement(_reactWaypoint.Waypoint, {
|
|
391
|
+
bottomOffset: bottomOffset,
|
|
392
|
+
topOffset: topOffset,
|
|
393
|
+
onPositionChange: this.handleOnPositionChange,
|
|
394
|
+
fireOnRapidScroll: false
|
|
395
|
+
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
396
|
+
id: id,
|
|
397
|
+
className: className,
|
|
398
|
+
ref: this._ref
|
|
399
|
+
}, children))
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
}]);
|
|
403
|
+
|
|
404
|
+
return Anchor;
|
|
405
|
+
}(_react["default"].PureComponent);
|
|
406
|
+
|
|
407
|
+
_defineProperty(Anchor, "propTypes", {
|
|
408
|
+
className: _propTypes["default"].string,
|
|
409
|
+
children: _propTypes["default"].node,
|
|
410
|
+
manager: _propTypes["default"].instanceOf(TOCManager).isRequired,
|
|
411
|
+
id: _propTypes["default"].string.isRequired,
|
|
412
|
+
label: _propTypes["default"].string.isRequired,
|
|
413
|
+
bottomOffset: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
|
|
414
|
+
topOffset: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number])
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
_defineProperty(Anchor, "defaultProps", {
|
|
418
|
+
className: '',
|
|
419
|
+
bottomOffset: '69%',
|
|
420
|
+
topOffset: '30%'
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
var smoothScrollDuration = 500;
|
|
424
|
+
|
|
425
|
+
var TableOfContents = /*#__PURE__*/function (_React$PureComponent2) {
|
|
426
|
+
_inherits(TableOfContents, _React$PureComponent2);
|
|
427
|
+
|
|
428
|
+
var _super2 = _createSuper(TableOfContents);
|
|
429
|
+
|
|
430
|
+
function TableOfContents(props) {
|
|
431
|
+
var _this3;
|
|
432
|
+
|
|
433
|
+
_classCallCheck(this, TableOfContents);
|
|
434
|
+
|
|
435
|
+
_this3 = _super2.call(this, props);
|
|
436
|
+
var manager = props.manager;
|
|
437
|
+
_this3.state = {
|
|
438
|
+
highlightAnchor: manager.highlightAnchor
|
|
439
|
+
};
|
|
440
|
+
_this3.setHighlightAnchor = _this3._setHighlightAnchor.bind(_assertThisInitialized(_this3));
|
|
441
|
+
_this3.handleAnchorClick = _this3._handleAnchorClick.bind(_assertThisInitialized(_this3));
|
|
442
|
+
manager.toc = _assertThisInitialized(_this3);
|
|
443
|
+
return _this3;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* @param {Anchor} anchor - anchor to highlight
|
|
447
|
+
* @returns
|
|
448
|
+
*/
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
_createClass(TableOfContents, [{
|
|
452
|
+
key: "_setHighlightAnchor",
|
|
453
|
+
value: function _setHighlightAnchor(anchor) {
|
|
454
|
+
this.setState({
|
|
455
|
+
highlightAnchor: anchor
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* @param {string} anchorID - id of clicked anchor
|
|
460
|
+
* @returns
|
|
461
|
+
*/
|
|
462
|
+
|
|
463
|
+
}, {
|
|
464
|
+
key: "_handleAnchorClick",
|
|
465
|
+
value: function _handleAnchorClick(anchorID) {
|
|
466
|
+
var _this4 = this;
|
|
467
|
+
|
|
468
|
+
var manager = this.props.manager;
|
|
469
|
+
var anchors = manager.anchors;
|
|
470
|
+
|
|
471
|
+
_.some(anchors, function (anchor) {
|
|
472
|
+
if (anchorID === anchor.anchorID) {
|
|
473
|
+
_this4.setState({
|
|
474
|
+
highlightAnchor: anchor
|
|
475
|
+
}, function () {
|
|
476
|
+
manager.toStopAutoUpdateHighlightAnchor = true;
|
|
477
|
+
(0, _smoothscroll["default"])(anchor.getViewportTop(), smoothScrollDuration, function () {
|
|
478
|
+
return manager.toStopAutoUpdateHighlightAnchor = false;
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
return false;
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
}, {
|
|
489
|
+
key: "render",
|
|
490
|
+
value: function render() {
|
|
491
|
+
var _this$props2 = this.props,
|
|
492
|
+
manager = _this$props2.manager,
|
|
493
|
+
render = _this$props2.render;
|
|
494
|
+
var highlightAnchor = this.state.highlightAnchor;
|
|
495
|
+
var anchors = manager.anchors;
|
|
496
|
+
var orderedAnchors = manager.memoizeSortAnchorsByViewportTop(anchors);
|
|
497
|
+
|
|
498
|
+
if (typeof render === 'function') {
|
|
499
|
+
return render(orderedAnchors, highlightAnchor, this.handleAnchorClick);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
return null;
|
|
503
|
+
}
|
|
504
|
+
}]);
|
|
505
|
+
|
|
506
|
+
return TableOfContents;
|
|
507
|
+
}(_react["default"].PureComponent);
|
|
508
|
+
/**
|
|
509
|
+
* @module TOC
|
|
510
|
+
*/
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
_defineProperty(TableOfContents, "propTypes", {
|
|
514
|
+
manager: _propTypes["default"].instanceOf(TOCManager).isRequired,
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* @callback
|
|
518
|
+
* @param {Anchor[]} anchors
|
|
519
|
+
* @param {?Anchor} highlightAnchor
|
|
520
|
+
* @param {Function} handleAnchorClick - callback function for handling clicking anchor
|
|
521
|
+
*/
|
|
522
|
+
render: _propTypes["default"].func
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
var _default = {
|
|
526
|
+
Manager: TOCManager,
|
|
527
|
+
React: {
|
|
528
|
+
Anchor: Anchor,
|
|
529
|
+
TableOfContents: TableOfContents
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = linkWithParams;
|
|
7
|
+
|
|
8
|
+
var _url = _interopRequireDefault(require("url"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param { string } originalUrl - The original url
|
|
14
|
+
* @param { Object } params - search params to be set
|
|
15
|
+
* @return { string } originalUrl with search params
|
|
16
|
+
*/
|
|
17
|
+
function linkWithParams(originalUrl, params) {
|
|
18
|
+
var urlObj = new URL(originalUrl);
|
|
19
|
+
|
|
20
|
+
for (var key in params) {
|
|
21
|
+
if (params[key]) {
|
|
22
|
+
urlObj.searchParams.set(key, params[key]);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return _url["default"].format(urlObj);
|
|
27
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@twreporter/react-components",
|
|
3
|
+
"version": "8.5.0-rc.1",
|
|
4
|
+
"main": "lib/index.js",
|
|
5
|
+
"repository": "https://github.com/twreporter/twreporter-npm-packages.git",
|
|
6
|
+
"author": "twreporter <developer@twreporter.org>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"clean": "make clean",
|
|
10
|
+
"build": "make build",
|
|
11
|
+
"dev": "make dev",
|
|
12
|
+
"prepublishOnly": "make build"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@twreporter/core": "^1.2.1",
|
|
16
|
+
"@twreporter/redux": "^7.2.0",
|
|
17
|
+
"hoist-non-react-statics": "^2.3.1",
|
|
18
|
+
"lodash": "^4.0.0",
|
|
19
|
+
"memoize-one": "^5.0.5",
|
|
20
|
+
"prop-types": "^15.0.0",
|
|
21
|
+
"react": "^16.3.0",
|
|
22
|
+
"react-redux": "^6.0.0",
|
|
23
|
+
"react-router-dom": "^5.1.2",
|
|
24
|
+
"react-transition-group": "^2.0.0",
|
|
25
|
+
"react-waypoint": "^9.0.2",
|
|
26
|
+
"smoothscroll": "^0.3.0",
|
|
27
|
+
"styled-components": "^4.0.0"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"lib"
|
|
31
|
+
],
|
|
32
|
+
"gitHead": "62a706e2369ff578eecd86c24aa5549516227c22"
|
|
33
|
+
}
|