@khanacademy/wonder-blocks-link 3.9.0 → 3.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/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var _extends = require('@babel/runtime/helpers/extends');
4
- var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose');
5
3
  var React = require('react');
6
4
  var reactRouter = require('react-router');
7
5
  var wonderBlocksClickable = require('@khanacademy/wonder-blocks-clickable');
@@ -13,72 +11,116 @@ var Color = require('@khanacademy/wonder-blocks-color');
13
11
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
12
 
15
13
  function _interopNamespace(e) {
16
- if (e && e.__esModule) return e;
17
- var n = Object.create(null);
18
- if (e) {
19
- Object.keys(e).forEach(function (k) {
20
- if (k !== 'default') {
21
- var d = Object.getOwnPropertyDescriptor(e, k);
22
- Object.defineProperty(n, k, d.get ? d : {
23
- enumerable: true,
24
- get: function () { return e[k]; }
25
- });
26
- }
14
+ if (e && e.__esModule) return e;
15
+ var n = Object.create(null);
16
+ if (e) {
17
+ Object.keys(e).forEach(function (k) {
18
+ if (k !== 'default') {
19
+ var d = Object.getOwnPropertyDescriptor(e, k);
20
+ Object.defineProperty(n, k, d.get ? d : {
21
+ enumerable: true,
22
+ get: function () { return e[k]; }
27
23
  });
28
- }
29
- n["default"] = e;
30
- return Object.freeze(n);
24
+ }
25
+ });
26
+ }
27
+ n["default"] = e;
28
+ return Object.freeze(n);
31
29
  }
32
30
 
33
- var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
34
- var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose);
35
31
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
36
32
  var Color__default = /*#__PURE__*/_interopDefaultLegacy(Color);
37
33
 
34
+ function _objectDestructuringEmpty(obj) {
35
+ if (obj == null) throw new TypeError("Cannot destructure " + obj);
36
+ }
37
+
38
+ function _extends() {
39
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
40
+ for (var i = 1; i < arguments.length; i++) {
41
+ var source = arguments[i];
42
+ for (var key in source) {
43
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
44
+ target[key] = source[key];
45
+ }
46
+ }
47
+ }
48
+ return target;
49
+ };
50
+ return _extends.apply(this, arguments);
51
+ }
52
+
53
+ function _objectWithoutPropertiesLoose(source, excluded) {
54
+ if (source == null) return {};
55
+ var target = {};
56
+ var sourceKeys = Object.keys(source);
57
+ var key, i;
58
+ for (i = 0; i < sourceKeys.length; i++) {
59
+ key = sourceKeys[i];
60
+ if (excluded.indexOf(key) >= 0) continue;
61
+ target[key] = source[key];
62
+ }
63
+ return target;
64
+ }
65
+
66
+ function _setPrototypeOf(o, p) {
67
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
68
+ o.__proto__ = p;
69
+ return o;
70
+ };
71
+ return _setPrototypeOf(o, p);
72
+ }
73
+
74
+ function _inheritsLoose(subClass, superClass) {
75
+ subClass.prototype = Object.create(superClass.prototype);
76
+ subClass.prototype.constructor = subClass;
77
+ _setPrototypeOf(subClass, superClass);
78
+ }
79
+
38
80
  const _excluded$1 = ["children", "skipClientNav", "focused", "hovered", "href", "inline", "kind", "light", "visitable", "pressed", "style", "testId", "waiting"];
39
81
  const StyledAnchor = wonderBlocksCore.addStyle("a");
40
82
  const StyledLink = wonderBlocksCore.addStyle(reactRouterDom.Link);
41
- class LinkCore extends React__namespace.Component {
42
- renderInner(router) {
83
+ let LinkCore = function (_React$Component) {
84
+ _inheritsLoose(LinkCore, _React$Component);
85
+ function LinkCore() {
86
+ return _React$Component.apply(this, arguments) || this;
87
+ }
88
+ var _proto = LinkCore.prototype;
89
+ _proto.renderInner = function renderInner(router) {
43
90
  const _this$props = this.props,
44
- {
45
- children,
46
- skipClientNav,
47
- focused,
48
- hovered,
49
- href,
50
- inline,
51
- kind,
52
- light,
53
- visitable,
54
- pressed,
55
- style,
56
- testId
57
- } = _this$props,
58
- restProps = _objectWithoutPropertiesLoose__default["default"](_this$props, _excluded$1);
59
-
91
+ {
92
+ children,
93
+ skipClientNav,
94
+ focused,
95
+ hovered,
96
+ href,
97
+ inline,
98
+ kind,
99
+ light,
100
+ visitable,
101
+ pressed,
102
+ style,
103
+ testId
104
+ } = _this$props,
105
+ restProps = _objectWithoutPropertiesLoose(_this$props, _excluded$1);
60
106
  const linkStyles = _generateStyles(inline, kind, light, visitable);
61
-
62
107
  const restingStyles = inline ? linkStyles.restingInline : linkStyles.resting;
63
108
  const defaultStyles = [sharedStyles.shared, !(hovered || focused || pressed) && restingStyles, pressed && linkStyles.active, !pressed && hovered && linkStyles.hover, !pressed && focused && linkStyles.focus];
64
-
65
- const commonProps = _extends__default["default"]({
109
+ const commonProps = _extends({
66
110
  "data-test-id": testId,
67
111
  style: [defaultStyles, style]
68
112
  }, restProps);
69
-
70
- return router && !skipClientNav && wonderBlocksClickable.isClientSideUrl(href) ? React__namespace.createElement(StyledLink, _extends__default["default"]({}, commonProps, {
113
+ return router && !skipClientNav && wonderBlocksClickable.isClientSideUrl(href) ? React__namespace.createElement(StyledLink, _extends({}, commonProps, {
71
114
  to: href
72
- }), children) : React__namespace.createElement(StyledAnchor, _extends__default["default"]({}, commonProps, {
115
+ }), children) : React__namespace.createElement(StyledAnchor, _extends({}, commonProps, {
73
116
  href: href
74
117
  }), children);
75
- }
76
-
77
- render() {
118
+ };
119
+ _proto.render = function render() {
78
120
  return React__namespace.createElement(reactRouter.__RouterContext.Consumer, null, router => this.renderInner(router));
79
- }
80
-
81
- }
121
+ };
122
+ return LinkCore;
123
+ }(React__namespace.Component);
82
124
  const styles = {};
83
125
  const sharedStyles = aphrodite.StyleSheet.create({
84
126
  shared: {
@@ -90,22 +132,17 @@ const sharedStyles = aphrodite.StyleSheet.create({
90
132
  lineHeight: "22px"
91
133
  }
92
134
  });
93
-
94
135
  const _generateStyles = (inline, kind, light, visitable) => {
95
136
  const buttonType = `${kind}-${inline.toString()}-${light.toString()}-${visitable.toString()}`;
96
-
97
137
  if (styles[buttonType]) {
98
138
  return styles[buttonType];
99
139
  }
100
-
101
140
  if (kind === "secondary" && light) {
102
141
  throw new Error("Secondary Light links are not supported");
103
142
  }
104
-
105
143
  if (visitable && kind !== "primary") {
106
144
  throw new Error("Only primary link is visitable");
107
145
  }
108
-
109
146
  const {
110
147
  blue,
111
148
  pink,
@@ -136,25 +173,25 @@ const _generateStyles = (inline, kind, light, visitable) => {
136
173
  }
137
174
  } : Object.freeze({});
138
175
  const newStyles = {
139
- resting: _extends__default["default"]({
176
+ resting: _extends({
140
177
  color: defaultTextColor
141
178
  }, defaultVisited),
142
- restingInline: _extends__default["default"]({
179
+ restingInline: _extends({
143
180
  color: defaultTextColor,
144
181
  textDecoration: "underline currentcolor solid 1px",
145
182
  textUnderlineOffset: 4
146
183
  }, defaultVisited),
147
- hover: _extends__default["default"]({
184
+ hover: _extends({
148
185
  textDecoration: "underline currentcolor dashed 2px",
149
186
  color: defaultTextColor,
150
187
  textUnderlineOffset: 4
151
188
  }, defaultVisited),
152
- focus: _extends__default["default"]({
189
+ focus: _extends({
153
190
  color: defaultTextColor,
154
191
  outline: `1px solid ${light ? white : blue}`,
155
192
  borderRadius: 3
156
193
  }, defaultVisited),
157
- active: _extends__default["default"]({
194
+ active: _extends({
158
195
  color: activeColor,
159
196
  textDecoration: "underline currentcolor solid 1px",
160
197
  textUnderlineOffset: 4
@@ -165,25 +202,28 @@ const _generateStyles = (inline, kind, light, visitable) => {
165
202
  };
166
203
 
167
204
  const _excluded = ["onClick", "beforeNav", "safeWithNav", "href", "skipClientNav", "children", "tabIndex", "onKeyDown", "onKeyUp", "target"];
168
- class Link extends React__namespace.Component {
169
- renderClickableBehavior(router) {
205
+ let Link = function (_React$Component) {
206
+ _inheritsLoose(Link, _React$Component);
207
+ function Link() {
208
+ return _React$Component.apply(this, arguments) || this;
209
+ }
210
+ var _proto = Link.prototype;
211
+ _proto.renderClickableBehavior = function renderClickableBehavior(router) {
170
212
  const _this$props = this.props,
171
- {
172
- onClick,
173
- beforeNav = undefined,
174
- safeWithNav,
175
- href,
176
- skipClientNav,
177
- children,
178
- tabIndex,
179
- onKeyDown,
180
- onKeyUp,
181
- target = undefined
182
- } = _this$props,
183
- sharedProps = _objectWithoutPropertiesLoose__default["default"](_this$props, _excluded);
184
-
213
+ {
214
+ onClick,
215
+ beforeNav = undefined,
216
+ safeWithNav,
217
+ href,
218
+ skipClientNav,
219
+ children,
220
+ tabIndex,
221
+ onKeyDown,
222
+ onKeyUp,
223
+ target = undefined
224
+ } = _this$props,
225
+ sharedProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
185
226
  const ClickableBehavior = wonderBlocksClickable.getClickableBehavior(href, skipClientNav, router);
186
-
187
227
  if (beforeNav) {
188
228
  return React__namespace.createElement(ClickableBehavior, {
189
229
  disabled: false,
@@ -195,9 +235,8 @@ class Link extends React__namespace.Component {
195
235
  onKeyDown: onKeyDown,
196
236
  onKeyUp: onKeyUp
197
237
  }, (state, _ref) => {
198
- let childrenProps = _extends__default["default"]({}, _ref);
199
-
200
- return React__namespace.createElement(LinkCore, _extends__default["default"]({}, sharedProps, state, childrenProps, {
238
+ let childrenProps = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
239
+ return React__namespace.createElement(LinkCore, _extends({}, sharedProps, state, childrenProps, {
201
240
  skipClientNav: skipClientNav,
202
241
  href: href,
203
242
  target: target,
@@ -215,9 +254,8 @@ class Link extends React__namespace.Component {
215
254
  onKeyDown: onKeyDown,
216
255
  onKeyUp: onKeyUp
217
256
  }, (state, _ref2) => {
218
- let childrenProps = _extends__default["default"]({}, _ref2);
219
-
220
- return React__namespace.createElement(LinkCore, _extends__default["default"]({}, sharedProps, state, childrenProps, {
257
+ let childrenProps = _extends({}, (_objectDestructuringEmpty(_ref2), _ref2));
258
+ return React__namespace.createElement(LinkCore, _extends({}, sharedProps, state, childrenProps, {
221
259
  skipClientNav: skipClientNav,
222
260
  href: href,
223
261
  target: target,
@@ -225,13 +263,12 @@ class Link extends React__namespace.Component {
225
263
  }), children);
226
264
  });
227
265
  }
228
- }
229
-
230
- render() {
266
+ };
267
+ _proto.render = function render() {
231
268
  return React__namespace.createElement(reactRouter.__RouterContext.Consumer, null, router => this.renderClickableBehavior(router));
232
- }
233
-
234
- }
269
+ };
270
+ return Link;
271
+ }(React__namespace.Component);
235
272
  Link.defaultProps = {
236
273
  inline: false,
237
274
  kind: "primary",
@@ -1,2 +1,9 @@
1
- // @flow
2
- export * from "../src/index.js";
1
+ /**
2
+ * Flowtype definitions for index
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import Link from "./components/link";
9
+ declare export { Link as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-link",
3
- "version": "3.9.0",
3
+ "version": "3.9.2",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -8,7 +8,7 @@
8
8
  "description": "Link component for Wonder Blocks design system.",
9
9
  "main": "dist/index.js",
10
10
  "module": "dist/es/index.js",
11
- "source": "src/index.js",
11
+ "types": "dist/index.d.ts",
12
12
  "scripts": {
13
13
  "test": "echo \"Error: no test specified\" && exit 1"
14
14
  },
@@ -16,9 +16,9 @@
16
16
  "license": "MIT",
17
17
  "dependencies": {
18
18
  "@babel/runtime": "^7.18.6",
19
- "@khanacademy/wonder-blocks-clickable": "^2.4.4",
20
- "@khanacademy/wonder-blocks-color": "^1.2.0",
21
- "@khanacademy/wonder-blocks-core": "^4.6.2"
19
+ "@khanacademy/wonder-blocks-clickable": "^2.4.6",
20
+ "@khanacademy/wonder-blocks-color": "^1.2.2",
21
+ "@khanacademy/wonder-blocks-core": "^4.8.0"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "aphrodite": "^1.2.5",
@@ -27,6 +27,6 @@
27
27
  "react-router-dom": "5.3.0"
28
28
  },
29
29
  "devDependencies": {
30
- "wb-dev-build-settings": "^0.7.0"
30
+ "wb-dev-build-settings": "^0.7.2"
31
31
  }
32
32
  }
@@ -1,9 +1,8 @@
1
- // @flow
2
- import React from "react";
3
- import renderer from "react-test-renderer";
1
+ import * as React from "react";
2
+ import * as renderer from "react-test-renderer";
4
3
 
5
- import LinkCore from "../components/link-core.js";
6
- import Link from "../components/link.js";
4
+ import LinkCore from "../components/link-core";
5
+ import Link from "../components/link";
7
6
 
8
7
  const defaultHandlers = {
9
8
  onClick: () => void 0,
@@ -19,7 +18,7 @@ const defaultHandlers = {
19
18
  onFocus: () => void 0,
20
19
  onBlur: () => void 0,
21
20
  tabIndex: 0,
22
- };
21
+ } as const;
23
22
 
24
23
  describe("Link", () => {
25
24
  test.each`
@@ -27,7 +26,7 @@ describe("Link", () => {
27
26
  ${-1}
28
27
  ${0}
29
28
  ${1}
30
- `("<Link tabIndex={$tabIndex}>", ({tabIndex}) => {
29
+ `("<Link tabIndex={$tabIndex}>", ({tabIndex}: any) => {
31
30
  const tree = renderer
32
31
  .create(
33
32
  <Link href="#" tabIndex={tabIndex}>
@@ -53,7 +52,7 @@ describe("LinkCore", () => {
53
52
  hovered: state === "hovered",
54
53
  pressed: state === "pressed",
55
54
  waiting: false,
56
- };
55
+ } as const;
57
56
  test(`kind:${kind} href:${href} light:${String(
58
57
  light,
59
58
  )} visitable:${String(visitable)} ${state}`, () => {
@@ -62,6 +61,7 @@ describe("LinkCore", () => {
62
61
  <LinkCore
63
62
  href="#"
64
63
  inline={inline}
64
+ // @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
65
65
  kind={kind}
66
66
  light={light}
67
67
  visitable={visitable}
@@ -1,14 +1,12 @@
1
- // @flow
2
- /* eslint-disable ft-flow/no-unused-expressions */
3
1
  import * as React from "react";
4
2
 
5
- import Link from "../link.js";
3
+ import Link from "../link";
6
4
 
7
- // $FlowExpectedError[incompatible-type]: href must be used with beforeNav
8
- <Link beforeNav={() => Promise.resolve()}>Hello, world!</Link>;
5
+ // TODO(FEI-5000): Re-enable test after updating props to be conditional.
6
+ // <Link beforeNav={() => Promise.resolve()}>Hello, world!</Link>;
9
7
 
10
- // $FlowExpectedError[incompatible-type]: href must be used with safeWithNav
11
- <Link safeWithNav={() => Promise.resolve()}>Hello, world!</Link>;
8
+ // TODO(FEI-5000): Re-enable test after updating props to be conditional.
9
+ // <Link safeWithNav={() => Promise.resolve()}>Hello, world!</Link>;
12
10
 
13
11
  // It's okay to use onClick with href
14
12
  <Link href="/foo" onClick={() => {}}>
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import * as React from "react";
3
2
  import {MemoryRouter, Route, Switch} from "react-router-dom";
4
3
  import {fireEvent, render, screen, waitFor} from "@testing-library/react";
@@ -6,17 +5,20 @@ import userEvent from "@testing-library/user-event";
6
5
 
7
6
  import Color from "@khanacademy/wonder-blocks-color";
8
7
 
9
- import Link from "../link.js";
8
+ import Link from "../link";
10
9
 
11
10
  describe("Link", () => {
12
11
  beforeEach(() => {
13
12
  // Note: window.location.assign needs a mock function in the testing
14
13
  // environment.
14
+ // @ts-expect-error [FEI-5019] - TS2790 - The operand of a 'delete' operator must be optional.
15
15
  delete window.location;
16
+ // @ts-expect-error [FEI-5019] - TS2740 - Type '{ assign: Mock<any, any, any>; }' is missing the following properties from type 'Location': ancestorOrigins, hash, host, hostname, and 8 more.
16
17
  window.location = {assign: jest.fn()};
17
18
  });
18
19
 
19
20
  afterEach(() => {
21
+ // @ts-expect-error [FEI-5019] - TS2339 - Property 'mockClear' does not exist on type '(url: string | URL) => void'.
20
22
  window.location.assign.mockClear();
21
23
  jest.clearAllMocks();
22
24
  });
@@ -300,9 +302,9 @@ describe("Link", () => {
300
302
  describe("raw events", () => {
301
303
  test("onKeyDown", () => {
302
304
  // Arrange
303
- let keyCode;
305
+ let keyCode: any;
304
306
  render(
305
- <Link href="/" onKeyDown={(e) => (keyCode = e.keyCode)}>
307
+ <Link href="/" onKeyDown={(e: any) => (keyCode = e.keyCode)}>
306
308
  Click me!
307
309
  </Link>,
308
310
  );
@@ -318,9 +320,9 @@ describe("Link", () => {
318
320
 
319
321
  test("onKeyUp", () => {
320
322
  // Arrange
321
- let keyCode;
323
+ let keyCode: any;
322
324
  render(
323
- <Link href="/" onKeyUp={(e) => (keyCode = e.keyCode)}>
325
+ <Link href="/" onKeyUp={(e: any) => (keyCode = e.keyCode)}>
324
326
  Click me!
325
327
  </Link>,
326
328
  );
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import * as React from "react";
3
2
  import {StyleSheet} from "aphrodite";
4
3
  import {Link} from "react-router-dom";
@@ -13,20 +12,19 @@ import type {
13
12
  ClickableState,
14
13
  } from "@khanacademy/wonder-blocks-clickable";
15
14
  import type {StyleDeclaration} from "aphrodite";
16
- import type {SharedProps} from "./link.js";
15
+ import type {SharedProps} from "./link";
17
16
 
18
- type Props = {|
19
- ...SharedProps,
20
- ...ChildrenProps,
21
- ...ClickableState,
22
- href: string,
23
- |};
17
+ type Props = SharedProps &
18
+ ChildrenProps &
19
+ ClickableState & {
20
+ href: string;
21
+ };
24
22
 
25
23
  const StyledAnchor = addStyle<"a">("a");
26
24
  const StyledLink = addStyle<typeof Link>(Link);
27
25
 
28
26
  export default class LinkCore extends React.Component<Props> {
29
- renderInner(router: any): React.Node {
27
+ renderInner(router: any): React.ReactNode {
30
28
  const {
31
29
  children,
32
30
  skipClientNav,
@@ -66,7 +64,7 @@ export default class LinkCore extends React.Component<Props> {
66
64
  "data-test-id": testId,
67
65
  style: [defaultStyles, style],
68
66
  ...restProps,
69
- };
67
+ } as const;
70
68
 
71
69
  return router && !skipClientNav && isClientSideUrl(href) ? (
72
70
  <StyledLink {...commonProps} to={href}>
@@ -79,7 +77,7 @@ export default class LinkCore extends React.Component<Props> {
79
77
  );
80
78
  }
81
79
 
82
- render(): React.Node {
80
+ render(): React.ReactElement {
83
81
  return (
84
82
  <__RouterContext.Consumer>
85
83
  {(router) => this.renderInner(router)}
@@ -88,7 +86,7 @@ export default class LinkCore extends React.Component<Props> {
88
86
  }
89
87
  }
90
88
 
91
- const styles = {};
89
+ const styles: Record<string, any> = {};
92
90
 
93
91
  const sharedStyles = StyleSheet.create({
94
92
  shared: {
@@ -101,7 +99,12 @@ const sharedStyles = StyleSheet.create({
101
99
  },
102
100
  });
103
101
 
104
- const _generateStyles = (inline, kind, light, visitable) => {
102
+ const _generateStyles = (
103
+ inline: boolean,
104
+ kind: "primary" | "secondary",
105
+ light: boolean,
106
+ visitable: boolean,
107
+ ) => {
105
108
  const buttonType = `${kind}-${inline.toString()}-${light.toString()}-${visitable.toString()}`;
106
109
  if (styles[buttonType]) {
107
110
  return styles[buttonType];