@twreporter/react-components 9.0.2 → 9.1.0-rc.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.
Files changed (152) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/lib/badge/badge.stories.js +3 -9
  3. package/lib/badge/index.js +8 -24
  4. package/lib/bookmark-list/bookmark.js +20 -69
  5. package/lib/bookmark-list/bookmarks.js +10 -40
  6. package/lib/bookmark-list/customized-link.js +4 -14
  7. package/lib/bookmark-list/image-wrapper.js +9 -36
  8. package/lib/bookmark-list/index.js +36 -91
  9. package/lib/bookmark-list/redirect-to-sign-in.js +1 -10
  10. package/lib/bookmark-list/stories/bookmark.stories.js +3 -9
  11. package/lib/bookmark-widget/index.js +91 -220
  12. package/lib/button/components/iconButton.js +15 -34
  13. package/lib/button/components/iconWithTextButton.js +16 -31
  14. package/lib/button/components/link.js +27 -45
  15. package/lib/button/components/menuButton.js +18 -38
  16. package/lib/button/components/pillButton.js +31 -60
  17. package/lib/button/components/textButton.js +29 -61
  18. package/lib/button/components/toggleButton.js +11 -31
  19. package/lib/button/enums/index.js +4 -7
  20. package/lib/button/index.js +5 -18
  21. package/lib/button/stories/iconButton.stories.js +4 -15
  22. package/lib/button/stories/iconWithTextButton.stories.js +4 -13
  23. package/lib/button/stories/link.stories.js +9 -27
  24. package/lib/button/stories/menuButton.stories.js +3 -10
  25. package/lib/button/stories/pillButton.stories.js +4 -15
  26. package/lib/button/stories/textButton.stories.js +4 -15
  27. package/lib/button/stories/toggleButton.stories.js +3 -8
  28. package/lib/button/utils/size.js +3 -8
  29. package/lib/button/utils/theme.js +11 -102
  30. package/lib/card/components/article-card.js +31 -59
  31. package/lib/card/components/dialog.js +7 -22
  32. package/lib/card/components/short-story.js +24 -44
  33. package/lib/card/index.js +2 -8
  34. package/lib/card/stories/articleCard.stories.js +3 -14
  35. package/lib/card/stories/dialog.stories.js +3 -11
  36. package/lib/card/stories/shortStory.stories.js +3 -16
  37. package/lib/checkbox/checkbox.stories.js +3 -8
  38. package/lib/checkbox/index.js +10 -31
  39. package/lib/color.stories.js +9 -34
  40. package/lib/confirmation/index.js +7 -29
  41. package/lib/customized-link.js +5 -18
  42. package/lib/divider.js +3 -19
  43. package/lib/divider.stories.js +5 -18
  44. package/lib/donation-link.js +2 -14
  45. package/lib/empty-state/enums/index.js +2 -3
  46. package/lib/empty-state/index.js +20 -41
  47. package/lib/empty-state/stories/empty-guide.stories.js +3 -11
  48. package/lib/error/index.js +3 -8
  49. package/lib/error/message.js +3 -44
  50. package/lib/footer/constants/links.js +10 -16
  51. package/lib/footer/footer.stories.js +3 -10
  52. package/lib/footer/index.js +5 -40
  53. package/lib/footer/link.js +15 -46
  54. package/lib/footer/logo.js +12 -32
  55. package/lib/hook/index.js +3 -18
  56. package/lib/hook/use-bookmark.js +21 -47
  57. package/lib/hook/use-font-face-observer.js +9 -24
  58. package/lib/hook/use-outside-click.js +4 -9
  59. package/lib/icon/enum/index.js +5 -9
  60. package/lib/icon/index.js +49 -105
  61. package/lib/icon/stories/arrow.stories.js +7 -16
  62. package/lib/icon/stories/article.stories.js +2 -7
  63. package/lib/icon/stories/bookmark.stories.js +6 -14
  64. package/lib/icon/stories/changeIconColor.stories.js +2 -12
  65. package/lib/icon/stories/clock.stories.js +2 -7
  66. package/lib/icon/stories/copy.stories.js +2 -7
  67. package/lib/icon/stories/cross.stories.js +2 -7
  68. package/lib/icon/stories/hamburger.stories.js +2 -7
  69. package/lib/icon/stories/home.stories.js +2 -7
  70. package/lib/icon/stories/letter.stories.js +2 -7
  71. package/lib/icon/stories/loading.stories.js +2 -7
  72. package/lib/icon/stories/member.stories.js +2 -7
  73. package/lib/icon/stories/printer.stories.js +2 -7
  74. package/lib/icon/stories/search.stories.js +2 -7
  75. package/lib/icon/stories/share.stories.js +2 -7
  76. package/lib/icon/stories/socialMedia.stories.js +2 -8
  77. package/lib/icon/stories/text.stories.js +2 -7
  78. package/lib/icon/stories/topic.stories.js +2 -7
  79. package/lib/image-with-fallback.js +22 -52
  80. package/lib/input/components/search-bar.js +40 -85
  81. package/lib/input/components/text-field.js +20 -40
  82. package/lib/input/enums/index.js +6 -8
  83. package/lib/input/index.js +2 -7
  84. package/lib/input/stories/search-bar.stories.js +3 -16
  85. package/lib/input/stories/text-field.stories.js +3 -14
  86. package/lib/input/utils/theme.js +2 -9
  87. package/lib/is-fetching-wrapper.js +16 -48
  88. package/lib/junior-link.js +6 -29
  89. package/lib/link-with-tracker.js +14 -47
  90. package/lib/listing-page/components/card-list.js +20 -51
  91. package/lib/listing-page/components/image.js +15 -46
  92. package/lib/listing-page/components/list-item.js +18 -65
  93. package/lib/listing-page/components/list.js +17 -61
  94. package/lib/listing-page/components/page-content.js +2 -12
  95. package/lib/listing-page/components/topics/index.js +26 -74
  96. package/lib/listing-page/components/topics/post-item.js +14 -47
  97. package/lib/listing-page/components/topics/posts.js +1 -10
  98. package/lib/listing-page/components/topics/section.js +3 -25
  99. package/lib/listing-page/components/topics/topic-item.js +17 -56
  100. package/lib/listing-page/constants/mockup-spec.js +2 -3
  101. package/lib/listing-page/constants/predefined-css.js +2 -10
  102. package/lib/listing-page/constants/prop-types.js +2 -7
  103. package/lib/listing-page/constants/topics.js +2 -3
  104. package/lib/listing-page/index.js +2 -8
  105. package/lib/listing-page/stories/cardList.stories.js +3 -10
  106. package/lib/logo/components/logo-footer.js +6 -21
  107. package/lib/logo/components/logo-header.js +7 -23
  108. package/lib/logo/components/logo-loading-fallback.js +4 -13
  109. package/lib/logo/components/logo-symbol.js +7 -23
  110. package/lib/logo/index.js +2 -9
  111. package/lib/logo/stories/logoFooter.stories.js +2 -8
  112. package/lib/logo/stories/logoHeader.stories.js +3 -9
  113. package/lib/logo/stories/logoLoadingFallback.stories.js +2 -8
  114. package/lib/logo/stories/logoSymbol.stories.js +3 -9
  115. package/lib/logo/utils/path.js +2 -9
  116. package/lib/material-icon.js +9 -17
  117. package/lib/mobile-member-role-card/index.js +22 -49
  118. package/lib/mobile-member-role-card/stories/member-role-card.stories.js +3 -12
  119. package/lib/mobile-pop-up-modal.js +10 -44
  120. package/lib/more.js +10 -37
  121. package/lib/pagination/index.js +17 -83
  122. package/lib/podcast-link.js +6 -29
  123. package/lib/rwd.js +6 -26
  124. package/lib/shared-enum.js +2 -3
  125. package/lib/side-bar/index.js +16 -59
  126. package/lib/simple-header/index.js +2 -12
  127. package/lib/simple-header/simpleHeader.stories.js +3 -8
  128. package/lib/snack-bar/components/snack-bar.js +9 -20
  129. package/lib/snack-bar/hooks/use-snack-bar.js +12 -25
  130. package/lib/snack-bar/index.js +2 -7
  131. package/lib/snack-bar/stories/snackBar.stories.js +12 -29
  132. package/lib/snack-bar/utils/theme.js +3 -9
  133. package/lib/storybook/constants/index.js +3 -11
  134. package/lib/storybook/utils/get-enum-arg.js +2 -5
  135. package/lib/table-of-contents/index.js +62 -128
  136. package/lib/text/constants/headline-type.js +5 -8
  137. package/lib/text/enums/index.js +3 -5
  138. package/lib/text/headline.js +14 -41
  139. package/lib/text/paragraph.js +13 -34
  140. package/lib/text/stories/headline.stories.js +8 -21
  141. package/lib/text/stories/paragraph.stories.js +6 -17
  142. package/lib/text/utils/webfonts.js +9 -22
  143. package/lib/title-bar/components/tab.js +27 -69
  144. package/lib/title-bar/components/title1.js +6 -17
  145. package/lib/title-bar/components/title2.js +7 -23
  146. package/lib/title-bar/index.js +2 -8
  147. package/lib/title-bar/stories/tab.stories.js +5 -12
  148. package/lib/title-bar/stories/title1.stories.js +5 -12
  149. package/lib/title-bar/stories/title2.stories.js +3 -11
  150. package/lib/utils/link-with-params.js +0 -5
  151. package/package.json +4 -4
  152. package/lib/hook/use-store.js +0 -46
@@ -1,56 +1,35 @@
1
1
  "use strict";
2
2
 
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
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports["default"] = void 0;
9
-
10
7
  var _react = _interopRequireDefault(require("react"));
11
-
12
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
13
-
14
9
  var _memoizeOne = _interopRequireDefault(require("memoize-one"));
15
-
16
10
  var _reactWaypoint = require("react-waypoint");
17
-
18
11
  var _smoothScroll = _interopRequireDefault(require("@twreporter/core/lib/utils/smooth-scroll"));
19
-
20
12
  var _get = _interopRequireDefault(require("lodash/get"));
21
-
22
13
  var _indexOf = _interopRequireDefault(require("lodash/indexOf"));
23
-
24
14
  var _some = _interopRequireDefault(require("lodash/some"));
25
-
26
15
  var _sortBy = _interopRequireDefault(require("lodash/sortBy"));
27
-
28
16
  var _debounce = _interopRequireDefault(require("lodash/debounce"));
29
-
30
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
31
-
18
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
32
19
  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); }
33
-
34
20
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
35
-
36
21
  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
22
  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
23
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
41
-
42
24
  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
25
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
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
-
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
-
29
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
30
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
31
+ 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); } // twreporter
32
+ // lodash
54
33
  var _ = {
55
34
  debounce: _debounce["default"],
56
35
  get: _get["default"],
@@ -58,6 +37,7 @@ var _ = {
58
37
  some: _some["default"],
59
38
  sortBy: _sortBy["default"]
60
39
  };
40
+
61
41
  /**
62
42
  * TOCManager is a bridge between `Anchor` and `TableOfContents`.
63
43
  * It provides APIs to make them communicate with each others.
@@ -65,7 +45,6 @@ var _ = {
65
45
  * hence, `TableOfContents` could know how to render correspoding labels and
66
46
  * know how to handle those labels clicked(scroll to that `Anchor`).
67
47
  */
68
-
69
48
  var TOCManager = /*#__PURE__*/function () {
70
49
  /**
71
50
  * @constructs
@@ -77,73 +56,77 @@ var TOCManager = /*#__PURE__*/function () {
77
56
  */
78
57
  function TOCManager() {
79
58
  var _this = this;
80
-
81
59
  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
-
60
+ _ref$anchors = _ref.anchors,
61
+ _anchors = _ref$anchors === void 0 ? [] : _ref$anchors,
62
+ _ref$highlightAnchor = _ref.highlightAnchor,
63
+ highlightAnchor = _ref$highlightAnchor === void 0 ? null : _ref$highlightAnchor,
64
+ _ref$toc = _ref.toc,
65
+ toc = _ref$toc === void 0 ? null : _ref$toc,
66
+ _ref$toStopAutoUpdate = _ref.toStopAutoUpdateHighlightAnchor,
67
+ toStopAutoUpdateHighlightAnchor = _ref$toStopAutoUpdate === void 0 ? false : _ref$toStopAutoUpdate;
91
68
  _classCallCheck(this, TOCManager);
92
-
69
+ /**
70
+ * Re-render `TableOfContents` if needed.
71
+ * Use debounce for optimizing rendering performance.
72
+ * @returns
73
+ */
93
74
  _defineProperty(this, "renderTOC", _.debounce(function () {
94
75
  if (_this._toc instanceof TableOfContents) {
95
76
  _this._toc.forceUpdate();
96
77
  }
97
78
  }, 100));
98
-
79
+ /**
80
+ * Update highlight anchor.
81
+ * Use debounce for optimizing rendering performance.
82
+ * @returns
83
+ */
99
84
  _defineProperty(this, "updateHighlightAnchor", _.debounce(function () {
100
85
  // sort the anchors by the distance to viewport top in ascending order.
101
86
  // the reason to sort anchors is because CSS styles(like flex order) might
102
87
  // change the anchors' position.
103
88
  var anchors = _this.memoizeSortAnchorsByViewportTop(_this._anchors);
104
-
105
89
  if (anchors.length === 0) {
106
90
  return;
107
- } // viewport is above first anchor
108
-
91
+ }
109
92
 
93
+ // viewport is above first anchor
110
94
  var firstAnchor = anchors[0];
111
-
112
95
  if (firstAnchor.currentPosition === TOCManager.position.below) {
113
96
  _this.highlightAnchor = null;
114
97
  return;
115
- } // viewport is below last anchor
116
-
98
+ }
117
99
 
100
+ // viewport is below last anchor
118
101
  var lastAnchor = anchors[anchors.length - 1];
119
-
120
102
  if (lastAnchor.currentPosition === TOCManager.position.above) {
121
103
  _this.highlightAnchor = lastAnchor;
122
104
  return;
123
105
  }
124
-
125
106
  _.some(anchors, function (anchor, index) {
126
107
  var curAnchor = anchor;
127
108
  var nextAnchor = anchors[index + 1];
128
-
129
- if ( // anchor[i] is inside the viewport
130
- curAnchor.currentPosition === TOCManager.position.inside || // viewport is between anchor[i] and anchor[i+1]
109
+ if (
110
+ // anchor[i] is inside the viewport
111
+ curAnchor.currentPosition === TOCManager.position.inside ||
112
+ // viewport is between anchor[i] and anchor[i+1]
131
113
  curAnchor.currentPosition === TOCManager.position.above && nextAnchor instanceof Anchor && nextAnchor.currentPosition === TOCManager.position.below) {
132
114
  _this.highlightAnchor = curAnchor;
133
115
  return true;
134
116
  }
135
-
136
117
  return false;
137
118
  });
138
119
  }, 100));
139
-
120
+ /**
121
+ * Use memoize to improve performance
122
+ */
140
123
  _defineProperty(this, "memoizeSortAnchorsByViewportTop", (0, _memoizeOne["default"])(this.sortAnchorsByViewportTop));
141
-
142
124
  this._anchors = _anchors;
143
125
  this._highlightAnchor = highlightAnchor;
144
126
  this._toc = toc;
145
127
  this._toStopAutoUpdateHighlightAnchor = toStopAutoUpdateHighlightAnchor;
146
128
  }
129
+
147
130
  /**
148
131
  * use `Array.concat` to add `Anchor` into array
149
132
  *
@@ -151,8 +134,6 @@ var TOCManager = /*#__PURE__*/function () {
151
134
  * @param {Anchor} anchor - an instance of `Anchor`
152
135
  * @returns
153
136
  */
154
-
155
-
156
137
  _createClass(TOCManager, [{
157
138
  key: "addAnchor",
158
139
  value: function addAnchor(anchor) {
@@ -164,12 +145,6 @@ var TOCManager = /*#__PURE__*/function () {
164
145
  this._anchors = this._anchors.concat(anchor);
165
146
  }
166
147
  }
167
- /**
168
- * Re-render `TableOfContents` if needed.
169
- * Use debounce for optimizing rendering performance.
170
- * @returns
171
- */
172
-
173
148
  }, {
174
149
  key: "sortAnchorsByViewportTop",
175
150
  value:
@@ -183,10 +158,6 @@ var TOCManager = /*#__PURE__*/function () {
183
158
  return anchor.getViewportTop();
184
159
  });
185
160
  }
186
- /**
187
- * Use memoize to improve performance
188
- */
189
-
190
161
  }, {
191
162
  key: "highlightAnchor",
192
163
  get:
@@ -198,12 +169,12 @@ var TOCManager = /*#__PURE__*/function () {
198
169
  function get() {
199
170
  return this._highlightAnchor;
200
171
  }
172
+
201
173
  /**
202
174
  * This is a setter function.
203
175
  * @method
204
176
  * @return {undefined}
205
- */
206
- ,
177
+ */,
207
178
  set:
208
179
  /**
209
180
  * This is a setter function.
@@ -217,7 +188,6 @@ var TOCManager = /*#__PURE__*/function () {
217
188
  if (anchor instanceof Anchor) {
218
189
  this._highlightAnchor = anchor;
219
190
  }
220
-
221
191
  if (this._toc instanceof TableOfContents) {
222
192
  this._toc.setHighlightAnchor(anchor);
223
193
  }
@@ -233,12 +203,12 @@ var TOCManager = /*#__PURE__*/function () {
233
203
  function get() {
234
204
  return this._anchors;
235
205
  }
206
+
236
207
  /**
237
208
  * This is a setter function.
238
209
  * @method
239
210
  * @returns
240
- */
241
- ,
211
+ */,
242
212
  set: function set(anchors) {
243
213
  this._anchors = anchors;
244
214
  }
@@ -253,12 +223,12 @@ var TOCManager = /*#__PURE__*/function () {
253
223
  function get() {
254
224
  return this._toc;
255
225
  }
226
+
256
227
  /**
257
228
  * This is a setter function.
258
229
  * @method
259
230
  * @returns
260
- */
261
- ,
231
+ */,
262
232
  set: function set(toc) {
263
233
  this._toc = toc;
264
234
  }
@@ -277,27 +247,20 @@ var TOCManager = /*#__PURE__*/function () {
277
247
  this._toStopAutoUpdateHighlightAnchor = toStopAutoUpdateHighlightAnchor;
278
248
  }
279
249
  }]);
280
-
281
250
  return TOCManager;
282
251
  }();
283
-
284
252
  _defineProperty(TOCManager, "position", {
285
253
  above: _reactWaypoint.Waypoint.above,
286
254
  below: _reactWaypoint.Waypoint.below,
287
255
  inside: _reactWaypoint.Waypoint.inside,
288
256
  invisible: _reactWaypoint.Waypoint.invisible
289
257
  });
290
-
291
258
  var Anchor = /*#__PURE__*/function (_React$PureComponent) {
292
259
  _inherits(Anchor, _React$PureComponent);
293
-
294
260
  var _super = _createSuper(Anchor);
295
-
296
261
  function Anchor(props) {
297
262
  var _this2;
298
-
299
263
  _classCallCheck(this, Anchor);
300
-
301
264
  _this2 = _super.call(this, props);
302
265
  _this2._ref = /*#__PURE__*/_react["default"].createRef();
303
266
  _this2.getViewportTop = _this2._getViewportTop.bind(_assertThisInitialized(_this2));
@@ -308,31 +271,28 @@ var Anchor = /*#__PURE__*/function (_React$PureComponent) {
308
271
  manager.renderTOC();
309
272
  return _this2;
310
273
  }
274
+
311
275
  /**
312
276
  * @returns {number} - the distance between the top edge of anchor and the top of window
313
277
  */
314
-
315
-
316
278
  _createClass(Anchor, [{
317
279
  key: "_getViewportTop",
318
280
  value: function _getViewportTop() {
319
281
  try {
320
282
  if (typeof window !== 'undefined' && this._ref.current) {
321
283
  var scrollY = window.scrollY;
322
-
323
284
  var _this$_ref$current$ge = this._ref.current.getBoundingClientRect(),
324
- _this$_ref$current$ge2 = _this$_ref$current$ge.top,
325
- top = _this$_ref$current$ge2 === void 0 ? 0 : _this$_ref$current$ge2;
326
-
285
+ _this$_ref$current$ge2 = _this$_ref$current$ge.top,
286
+ top = _this$_ref$current$ge2 === void 0 ? 0 : _this$_ref$current$ge2;
327
287
  return scrollY + top;
328
288
  }
329
289
  } catch (e) {
330
290
  console.warn("Anchor(id: ".concat(this.props.id, ").getViewportTop occurs error"), e);
331
291
  console.warn('Return default value: 0');
332
292
  }
333
-
334
293
  return 0;
335
294
  }
295
+
336
296
  /**
337
297
  * @param {Object} [posObj={}]
338
298
  * @param {string} [posObj.currentPosition=''] - it could be one of
@@ -340,37 +300,34 @@ var Anchor = /*#__PURE__*/function (_React$PureComponent) {
340
300
  *
341
301
  * @returns
342
302
  */
343
-
344
303
  }, {
345
304
  key: "_handleOnPositionChange",
346
305
  value: function _handleOnPositionChange() {
347
306
  var posObj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
348
307
  var manager = this.props.manager;
349
308
  this.currentPosition = posObj.currentPosition;
350
-
351
309
  if (manager.toStopAutoUpdateHighlightAnchor) {
352
310
  return;
353
311
  }
354
-
355
312
  manager.updateHighlightAnchor();
356
313
  }
314
+
357
315
  /**
358
316
  * This is a getter function.
359
317
  * @method
360
318
  * @returns {string} - id of anchor
361
319
  */
362
-
363
320
  }, {
364
321
  key: "anchorID",
365
322
  get: function get() {
366
323
  return this.props.id;
367
324
  }
325
+
368
326
  /**
369
327
  * This is a getter function.
370
328
  * @method
371
329
  * @returns {string} - label of anchor
372
330
  */
373
-
374
331
  }, {
375
332
  key: "anchorLable",
376
333
  get: function get() {
@@ -380,11 +337,11 @@ var Anchor = /*#__PURE__*/function (_React$PureComponent) {
380
337
  key: "render",
381
338
  value: function render() {
382
339
  var _this$props = this.props,
383
- bottomOffset = _this$props.bottomOffset,
384
- className = _this$props.className,
385
- children = _this$props.children,
386
- id = _this$props.id,
387
- topOffset = _this$props.topOffset;
340
+ bottomOffset = _this$props.bottomOffset,
341
+ className = _this$props.className,
342
+ children = _this$props.children,
343
+ id = _this$props.id,
344
+ topOffset = _this$props.topOffset;
388
345
  return (
389
346
  /*#__PURE__*/
390
347
  // set fireOnRapidScroll=false since we are not using `onEnter` and `onLeave`
@@ -401,10 +358,8 @@ var Anchor = /*#__PURE__*/function (_React$PureComponent) {
401
358
  );
402
359
  }
403
360
  }]);
404
-
405
361
  return Anchor;
406
362
  }(_react["default"].PureComponent);
407
-
408
363
  _defineProperty(Anchor, "propTypes", {
409
364
  className: _propTypes["default"].string,
410
365
  children: _propTypes["default"].node,
@@ -414,25 +369,18 @@ _defineProperty(Anchor, "propTypes", {
414
369
  bottomOffset: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
415
370
  topOffset: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number])
416
371
  });
417
-
418
372
  _defineProperty(Anchor, "defaultProps", {
419
373
  className: '',
420
374
  bottomOffset: '69%',
421
375
  topOffset: '30%'
422
376
  });
423
-
424
377
  var defaultScrollDuration = 500;
425
-
426
378
  var TableOfContents = /*#__PURE__*/function (_React$PureComponent2) {
427
379
  _inherits(TableOfContents, _React$PureComponent2);
428
-
429
380
  var _super2 = _createSuper(TableOfContents);
430
-
431
381
  function TableOfContents(props) {
432
382
  var _this3;
433
-
434
383
  _classCallCheck(this, TableOfContents);
435
-
436
384
  _this3 = _super2.call(this, props);
437
385
  var manager = props.manager;
438
386
  _this3.state = {
@@ -443,12 +391,11 @@ var TableOfContents = /*#__PURE__*/function (_React$PureComponent2) {
443
391
  manager.toc = _assertThisInitialized(_this3);
444
392
  return _this3;
445
393
  }
394
+
446
395
  /**
447
396
  * @param {Anchor} anchor - anchor to highlight
448
397
  * @returns
449
398
  */
450
-
451
-
452
399
  _createClass(TableOfContents, [{
453
400
  key: "_setHighlightAnchor",
454
401
  value: function _setHighlightAnchor(anchor) {
@@ -456,21 +403,19 @@ var TableOfContents = /*#__PURE__*/function (_React$PureComponent2) {
456
403
  highlightAnchor: anchor
457
404
  });
458
405
  }
406
+
459
407
  /**
460
408
  * @param {string} anchorID - id of clicked anchor
461
409
  * @returns
462
410
  */
463
-
464
411
  }, {
465
412
  key: "_handleAnchorClick",
466
413
  value: function _handleAnchorClick(anchorID, callback) {
467
414
  var _this4 = this;
468
-
469
415
  var _this$props2 = this.props,
470
- manager = _this$props2.manager,
471
- scrollDuration = _this$props2.scrollDuration;
416
+ manager = _this$props2.manager,
417
+ scrollDuration = _this$props2.scrollDuration;
472
418
  var anchors = manager.anchors;
473
-
474
419
  _.some(anchors, function (anchor) {
475
420
  if (anchorID === anchor.anchorID) {
476
421
  _this4.setState({
@@ -479,16 +424,13 @@ var TableOfContents = /*#__PURE__*/function (_React$PureComponent2) {
479
424
  manager.toStopAutoUpdateHighlightAnchor = true;
480
425
  (0, _smoothScroll["default"])(anchor.getViewportTop(), scrollDuration || defaultScrollDuration, function () {
481
426
  manager.toStopAutoUpdateHighlightAnchor = false;
482
-
483
427
  if (callback) {
484
428
  callback();
485
429
  }
486
430
  });
487
431
  });
488
-
489
432
  return true;
490
433
  }
491
-
492
434
  return false;
493
435
  });
494
436
  }
@@ -496,30 +438,24 @@ var TableOfContents = /*#__PURE__*/function (_React$PureComponent2) {
496
438
  key: "render",
497
439
  value: function render() {
498
440
  var _this$props3 = this.props,
499
- manager = _this$props3.manager,
500
- render = _this$props3.render;
441
+ manager = _this$props3.manager,
442
+ render = _this$props3.render;
501
443
  var highlightAnchor = this.state.highlightAnchor;
502
444
  var anchors = manager.anchors;
503
445
  var orderedAnchors = manager.memoizeSortAnchorsByViewportTop(anchors);
504
-
505
446
  if (typeof render === 'function') {
506
447
  return render(orderedAnchors, highlightAnchor, this.handleAnchorClick);
507
448
  }
508
-
509
449
  return null;
510
450
  }
511
451
  }]);
512
-
513
452
  return TableOfContents;
514
453
  }(_react["default"].PureComponent);
515
454
  /**
516
455
  * @module TOC
517
456
  */
518
-
519
-
520
457
  _defineProperty(TableOfContents, "propTypes", {
521
458
  manager: _propTypes["default"].instanceOf(TOCManager).isRequired,
522
-
523
459
  /**
524
460
  * @callback
525
461
  * @param {Anchor[]} anchors
@@ -529,12 +465,10 @@ _defineProperty(TableOfContents, "propTypes", {
529
465
  render: _propTypes["default"].func,
530
466
  scrollDuration: _propTypes["default"].number
531
467
  });
532
-
533
- var _default = {
468
+ var _default = exports["default"] = {
534
469
  Manager: TOCManager,
535
470
  React: {
536
471
  Anchor: Anchor,
537
472
  TableOfContents: TableOfContents
538
473
  }
539
- };
540
- exports["default"] = _default;
474
+ };
@@ -4,14 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.TYPE_FONT_FAMILY = void 0;
7
-
8
7
  var _font = require("@twreporter/core/lib/constants/font");
9
-
10
8
  var _enums = require("../enums");
11
-
12
9
  var _Object$freeze;
13
-
14
- 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; }
15
-
16
- var TYPE_FONT_FAMILY = Object.freeze((_Object$freeze = {}, _defineProperty(_Object$freeze, _enums.Type.DEFAULT, _font.fontFamily["default"]), _defineProperty(_Object$freeze, _enums.Type.ARTICLE, _font.fontFamily.title), _Object$freeze));
17
- exports.TYPE_FONT_FAMILY = TYPE_FONT_FAMILY;
10
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
11
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
13
+ 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); }
14
+ var TYPE_FONT_FAMILY = exports.TYPE_FONT_FAMILY = Object.freeze((_Object$freeze = {}, _defineProperty(_Object$freeze, _enums.Type.DEFAULT, _font.fontFamily["default"]), _defineProperty(_Object$freeze, _enums.Type.ARTICLE, _font.fontFamily.title), _Object$freeze));
@@ -4,14 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Weight = exports.Type = void 0;
7
- var Type = Object.freeze({
7
+ var Type = exports.Type = Object.freeze({
8
8
  DEFAULT: 'default',
9
9
  ARTICLE: 'article'
10
10
  });
11
- exports.Type = Type;
12
- var Weight = Object.freeze({
11
+ var Weight = exports.Weight = Object.freeze({
13
12
  EXTRA_LIGHT: 'extraLight',
14
13
  NORMAL: 'normal',
15
14
  BOLD: 'bold'
16
- });
17
- exports.Weight = Weight;
15
+ });
@@ -4,40 +4,24 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = exports.H6 = exports.H5 = exports.H4 = exports.H3 = exports.H2 = exports.H1 = void 0;
7
-
8
7
  var _react = _interopRequireDefault(require("react"));
9
-
10
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
9
  var _styledComponents = _interopRequireDefault(require("styled-components"));
13
-
14
10
  var _headlineType = require("./constants/headline-type");
15
-
16
11
  var _enums = require("./enums");
17
-
18
12
  var _mediaQuery = _interopRequireDefault(require("@twreporter/core/lib/utils/media-query"));
19
-
20
13
  var _font = require("@twreporter/core/lib/constants/font");
21
-
22
14
  var _excluded = ["text", "type", "className"];
23
-
24
15
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
25
-
26
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
27
-
28
17
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
29
-
30
18
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
31
-
32
19
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
33
-
34
20
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
35
-
36
21
  var DefaultContainer = /*#__PURE__*/_styledComponents["default"].div.withConfig({
37
22
  displayName: "headline__DefaultContainer",
38
23
  componentId: "axdp97-0"
39
24
  })(["font-weight:", ";"], _font.fontWeight.bold);
40
-
41
25
  var H1Container = /*#__PURE__*/(0, _styledComponents["default"])(DefaultContainer).withConfig({
42
26
  displayName: "headline__H1Container",
43
27
  componentId: "axdp97-1"
@@ -74,24 +58,21 @@ var H6Container = /*#__PURE__*/(0, _styledComponents["default"])(DefaultContaine
74
58
  })(["line-height:150%;font-size:16px;font-family:", ";", ""], function (props) {
75
59
  return props.$fontFamily;
76
60
  }, _mediaQuery["default"].tabletAndBelow(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n font-size: 16px;\n "]))));
77
-
78
61
  var withContainer = function withContainer(HeadlineContainer) {
79
62
  var headline = function headline(_ref) {
80
63
  var _ref$text = _ref.text,
81
- text = _ref$text === void 0 ? '' : _ref$text,
82
- _ref$type = _ref.type,
83
- type = _ref$type === void 0 ? _enums.Type.DEFAULT : _ref$type,
84
- _ref$className = _ref.className,
85
- className = _ref$className === void 0 ? '' : _ref$className,
86
- props = _objectWithoutProperties(_ref, _excluded);
87
-
64
+ text = _ref$text === void 0 ? '' : _ref$text,
65
+ _ref$type = _ref.type,
66
+ type = _ref$type === void 0 ? _enums.Type.DEFAULT : _ref$type,
67
+ _ref$className = _ref.className,
68
+ className = _ref$className === void 0 ? '' : _ref$className,
69
+ props = _objectWithoutProperties(_ref, _excluded);
88
70
  var fontFamily = _headlineType.TYPE_FONT_FAMILY[type];
89
71
  return /*#__PURE__*/_react["default"].createElement(HeadlineContainer, _extends({
90
72
  $fontFamily: fontFamily,
91
73
  className: className
92
74
  }, props), text);
93
75
  };
94
-
95
76
  headline.displayName = 'headline';
96
77
  headline.propTypes = {
97
78
  text: _propTypes["default"].string,
@@ -101,25 +82,17 @@ var withContainer = function withContainer(HeadlineContainer) {
101
82
  headline.Type = _enums.Type;
102
83
  return headline;
103
84
  };
104
-
105
- var H1 = withContainer(H1Container);
106
- exports.H1 = H1;
107
- var H2 = withContainer(H2Container);
108
- exports.H2 = H2;
109
- var H3 = withContainer(H3Container);
110
- exports.H3 = H3;
111
- var H4 = withContainer(H4Container);
112
- exports.H4 = H4;
113
- var H5 = withContainer(H5Container);
114
- exports.H5 = H5;
115
- var H6 = withContainer(H6Container);
116
- exports.H6 = H6;
117
- var _default = {
85
+ var H1 = exports.H1 = withContainer(H1Container);
86
+ var H2 = exports.H2 = withContainer(H2Container);
87
+ var H3 = exports.H3 = withContainer(H3Container);
88
+ var H4 = exports.H4 = withContainer(H4Container);
89
+ var H5 = exports.H5 = withContainer(H5Container);
90
+ var H6 = exports.H6 = withContainer(H6Container);
91
+ var _default = exports["default"] = {
118
92
  H1: H1,
119
93
  H2: H2,
120
94
  H3: H3,
121
95
  H4: H4,
122
96
  H5: H5,
123
97
  H6: H6
124
- };
125
- exports["default"] = _default;
98
+ };