@storybook/addon-a11y 7.0.0-alpha.4 → 7.0.0-alpha.7

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.
@@ -13,6 +13,8 @@ var _api = require("@storybook/api");
13
13
 
14
14
  var _coreEvents = require("@storybook/core-events");
15
15
 
16
+ var _addonHighlight = require("@storybook/addon-highlight");
17
+
16
18
  var _constants = require("../constants");
17
19
 
18
20
  const _excluded = ["active"];
@@ -58,9 +60,8 @@ const A11yContextProvider = _ref => {
58
60
  const [results, setResults] = (0, _api.useAddonState)(_constants.ADDON_ID, defaultResult);
59
61
  const [tab, setTab] = React.useState(0);
60
62
  const [highlighted, setHighlighted] = React.useState([]);
61
- const {
62
- storyId
63
- } = (0, _api.useStorybookState)();
63
+ const api = (0, _api.useStorybookApi)();
64
+ const storyEntry = api.getCurrentStoryData();
64
65
  const handleToggleHighlight = React.useCallback((target, highlight) => {
65
66
  setHighlighted(prevHighlighted => highlight ? [...prevHighlighted, ...target] : prevHighlighted.filter(t => !target.includes(t)));
66
67
  }, []);
@@ -76,25 +77,25 @@ const A11yContextProvider = _ref => {
76
77
  }, []);
77
78
  const handleReset = React.useCallback(() => {
78
79
  setTab(0);
79
- setResults(defaultResult); // Highlights is cleared by a11yHighlights.ts
80
+ setResults(defaultResult); // Highlights is cleared by addon-highlight
80
81
  }, []);
81
82
  const emit = (0, _api.useChannel)({
82
83
  [_coreEvents.STORY_RENDERED]: handleRun,
83
84
  [_coreEvents.STORY_CHANGED]: handleReset
84
85
  });
85
86
  React.useEffect(() => {
86
- emit(_constants.EVENTS.HIGHLIGHT, {
87
+ emit(_addonHighlight.HIGHLIGHT, {
87
88
  elements: highlighted,
88
89
  color: colorsByType[tab]
89
90
  });
90
91
  }, [highlighted, tab]);
91
92
  React.useEffect(() => {
92
- if (active) {
93
- handleRun(storyId);
93
+ if (active && storyEntry?.type === 'story') {
94
+ handleRun(storyEntry.id);
94
95
  } else {
95
96
  handleClearHighlights();
96
97
  }
97
- }, [active, handleClearHighlights, emit, storyId]);
98
+ }, [active, handleClearHighlights, emit, storyEntry]);
98
99
  if (!active) return null;
99
100
  return /*#__PURE__*/React.createElement(A11yContext.Provider, _extends({
100
101
  value: {
@@ -3,27 +3,23 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.PARAM_KEY = exports.PANEL_ID = exports.HIGHLIGHT_STYLE_ID = exports.EVENTS = exports.ADDON_ID = void 0;
6
+ exports.PARAM_KEY = exports.PANEL_ID = exports.EVENTS = exports.ADDON_ID = void 0;
7
7
  const ADDON_ID = 'storybook/a11y';
8
8
  exports.ADDON_ID = ADDON_ID;
9
9
  const PANEL_ID = `${ADDON_ID}/panel`;
10
10
  exports.PANEL_ID = PANEL_ID;
11
11
  const PARAM_KEY = `a11y`;
12
12
  exports.PARAM_KEY = PARAM_KEY;
13
- const HIGHLIGHT_STYLE_ID = 'a11yHighlight';
14
- exports.HIGHLIGHT_STYLE_ID = HIGHLIGHT_STYLE_ID;
15
13
  const RESULT = `${ADDON_ID}/result`;
16
14
  const REQUEST = `${ADDON_ID}/request`;
17
15
  const RUNNING = `${ADDON_ID}/running`;
18
16
  const ERROR = `${ADDON_ID}/error`;
19
17
  const MANUAL = `${ADDON_ID}/manual`;
20
- const HIGHLIGHT = `${ADDON_ID}/highlight`;
21
18
  const EVENTS = {
22
19
  RESULT,
23
20
  REQUEST,
24
21
  RUNNING,
25
22
  ERROR,
26
- MANUAL,
27
- HIGHLIGHT
23
+ MANUAL
28
24
  };
29
25
  exports.EVENTS = EVENTS;
package/dist/cjs/index.js CHANGED
@@ -21,20 +21,6 @@ var _tsDedent = _interopRequireDefault(require("ts-dedent"));
21
21
 
22
22
  var _constants = require("./constants");
23
23
 
24
- var _highlight = require("./highlight");
25
-
26
- Object.keys(_highlight).forEach(function (key) {
27
- if (key === "default" || key === "__esModule") return;
28
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
29
- if (key in exports && exports[key] === _highlight[key]) return;
30
- Object.defineProperty(exports, key, {
31
- enumerable: true,
32
- get: function () {
33
- return _highlight[key];
34
- }
35
- });
36
- });
37
-
38
24
  var _params = require("./params");
39
25
 
40
26
  Object.keys(_params).forEach(function (key) {
@@ -26,11 +26,9 @@ _addons.addons.register(_constants.ADDON_ID, api => {
26
26
 
27
27
  _addons.addons.add(_constants.PANEL_ID, {
28
28
  title() {
29
- var _addonState$violation, _addonState$incomplet;
30
-
31
- const addonState = api === null || api === void 0 ? void 0 : api.getAddonState(_constants.ADDON_ID);
32
- const violationsNb = (addonState === null || addonState === void 0 ? void 0 : (_addonState$violation = addonState.violations) === null || _addonState$violation === void 0 ? void 0 : _addonState$violation.length) || 0;
33
- const incompleteNb = (addonState === null || addonState === void 0 ? void 0 : (_addonState$incomplet = addonState.incomplete) === null || _addonState$incomplet === void 0 ? void 0 : _addonState$incomplet.length) || 0;
29
+ const addonState = api?.getAddonState(_constants.ADDON_ID);
30
+ const violationsNb = addonState?.violations?.length || 0;
31
+ const incompleteNb = addonState?.incomplete?.length || 0;
34
32
  const totalNb = violationsNb + incompleteNb;
35
33
  return totalNb !== 0 ? `Accessibility (${totalNb})` : 'Accessibility';
36
34
  },
@@ -1,5 +1,3 @@
1
1
  "use strict";
2
2
 
3
- require("./a11yRunner");
4
-
5
- require("./a11yHighlight");
3
+ require("./a11yRunner");
@@ -6,8 +6,9 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
6
6
 
7
7
  import * as React from 'react';
8
8
  import { themes, convert } from '@storybook/theming';
9
- import { useChannel, useStorybookState, useAddonState } from '@storybook/api';
9
+ import { useChannel, useAddonState, useStorybookApi } from '@storybook/api';
10
10
  import { STORY_CHANGED, STORY_RENDERED } from '@storybook/core-events';
11
+ import { HIGHLIGHT } from '@storybook/addon-highlight';
11
12
  import { ADDON_ID, EVENTS } from '../constants';
12
13
  const colorsByType = [convert(themes.normal).color.negative, // VIOLATION,
13
14
  convert(themes.normal).color.positive, // PASS,
@@ -40,9 +41,8 @@ export const A11yContextProvider = _ref => {
40
41
  const [results, setResults] = useAddonState(ADDON_ID, defaultResult);
41
42
  const [tab, setTab] = React.useState(0);
42
43
  const [highlighted, setHighlighted] = React.useState([]);
43
- const {
44
- storyId
45
- } = useStorybookState();
44
+ const api = useStorybookApi();
45
+ const storyEntry = api.getCurrentStoryData();
46
46
  const handleToggleHighlight = React.useCallback((target, highlight) => {
47
47
  setHighlighted(prevHighlighted => highlight ? [...prevHighlighted, ...target] : prevHighlighted.filter(t => !target.includes(t)));
48
48
  }, []);
@@ -58,25 +58,25 @@ export const A11yContextProvider = _ref => {
58
58
  }, []);
59
59
  const handleReset = React.useCallback(() => {
60
60
  setTab(0);
61
- setResults(defaultResult); // Highlights is cleared by a11yHighlights.ts
61
+ setResults(defaultResult); // Highlights is cleared by addon-highlight
62
62
  }, []);
63
63
  const emit = useChannel({
64
64
  [STORY_RENDERED]: handleRun,
65
65
  [STORY_CHANGED]: handleReset
66
66
  });
67
67
  React.useEffect(() => {
68
- emit(EVENTS.HIGHLIGHT, {
68
+ emit(HIGHLIGHT, {
69
69
  elements: highlighted,
70
70
  color: colorsByType[tab]
71
71
  });
72
72
  }, [highlighted, tab]);
73
73
  React.useEffect(() => {
74
- if (active) {
75
- handleRun(storyId);
74
+ if (active && storyEntry?.type === 'story') {
75
+ handleRun(storyEntry.id);
76
76
  } else {
77
77
  handleClearHighlights();
78
78
  }
79
- }, [active, handleClearHighlights, emit, storyId]);
79
+ }, [active, handleClearHighlights, emit, storyEntry]);
80
80
  if (!active) return null;
81
81
  return /*#__PURE__*/React.createElement(A11yContext.Provider, _extends({
82
82
  value: {
@@ -1,18 +1,15 @@
1
1
  export const ADDON_ID = 'storybook/a11y';
2
2
  export const PANEL_ID = `${ADDON_ID}/panel`;
3
3
  export const PARAM_KEY = `a11y`;
4
- export const HIGHLIGHT_STYLE_ID = 'a11yHighlight';
5
4
  const RESULT = `${ADDON_ID}/result`;
6
5
  const REQUEST = `${ADDON_ID}/request`;
7
6
  const RUNNING = `${ADDON_ID}/running`;
8
7
  const ERROR = `${ADDON_ID}/error`;
9
8
  const MANUAL = `${ADDON_ID}/manual`;
10
- const HIGHLIGHT = `${ADDON_ID}/highlight`;
11
9
  export const EVENTS = {
12
10
  RESULT,
13
11
  REQUEST,
14
12
  RUNNING,
15
13
  ERROR,
16
- MANUAL,
17
- HIGHLIGHT
14
+ MANUAL
18
15
  };
package/dist/esm/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import deprecate from 'util-deprecate';
2
2
  import dedent from 'ts-dedent';
3
3
  export { PARAM_KEY } from './constants';
4
- export * from './highlight';
5
4
  export * from './params';
6
5
 
7
6
  if (module && module.hot && module.hot.decline) {
@@ -1,2 +1 @@
1
- import './a11yRunner';
2
- import './a11yHighlight';
1
+ import './a11yRunner';
@@ -1,12 +1,10 @@
1
1
  export declare const ADDON_ID = "storybook/a11y";
2
2
  export declare const PANEL_ID: string;
3
3
  export declare const PARAM_KEY = "a11y";
4
- export declare const HIGHLIGHT_STYLE_ID = "a11yHighlight";
5
4
  export declare const EVENTS: {
6
5
  RESULT: string;
7
6
  REQUEST: string;
8
7
  RUNNING: string;
9
8
  ERROR: string;
10
9
  MANUAL: string;
11
- HIGHLIGHT: string;
12
10
  };
@@ -1,5 +1,4 @@
1
1
  import type { AnyFramework, DecoratorFunction } from '@storybook/csf';
2
2
  export { PARAM_KEY } from './constants';
3
- export * from './highlight';
4
3
  export * from './params';
5
4
  export declare const withA11y: DecoratorFunction<AnyFramework>;
@@ -1,2 +1 @@
1
1
  import './a11yRunner';
2
- import './a11yHighlight';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/addon-a11y",
3
- "version": "7.0.0-alpha.4",
3
+ "version": "7.0.0-alpha.7",
4
4
  "description": "Test component compliance with web accessibility standards",
5
5
  "keywords": [
6
6
  "a11y",
@@ -38,14 +38,15 @@
38
38
  "prepare": "node ../../scripts/prepare.js"
39
39
  },
40
40
  "dependencies": {
41
- "@storybook/addons": "7.0.0-alpha.4",
42
- "@storybook/api": "7.0.0-alpha.4",
43
- "@storybook/channels": "7.0.0-alpha.4",
44
- "@storybook/client-logger": "7.0.0-alpha.4",
45
- "@storybook/components": "7.0.0-alpha.4",
46
- "@storybook/core-events": "7.0.0-alpha.4",
41
+ "@storybook/addon-highlight": "7.0.0-alpha.7",
42
+ "@storybook/addons": "7.0.0-alpha.7",
43
+ "@storybook/api": "7.0.0-alpha.7",
44
+ "@storybook/channels": "7.0.0-alpha.7",
45
+ "@storybook/client-logger": "7.0.0-alpha.7",
46
+ "@storybook/components": "7.0.0-alpha.7",
47
+ "@storybook/core-events": "7.0.0-alpha.7",
47
48
  "@storybook/csf": "0.0.2--canary.4566f4d.1",
48
- "@storybook/theming": "7.0.0-alpha.4",
49
+ "@storybook/theming": "7.0.0-alpha.7",
49
50
  "axe-core": "^4.2.0",
50
51
  "core-js": "^3.8.2",
51
52
  "global": "^4.4.0",
@@ -72,7 +73,7 @@
72
73
  "publishConfig": {
73
74
  "access": "public"
74
75
  },
75
- "gitHead": "006ed54452dd7c37a8cbe91a84f5312182f7ca00",
76
+ "gitHead": "d334cabd251cd0ed8b845a87707dc84f007d4074",
76
77
  "storybook": {
77
78
  "displayName": "Accessibility",
78
79
  "icon": "https://user-images.githubusercontent.com/263385/101991665-47042f80-3c7c-11eb-8f00-64b5a18f498a.png",
@@ -1,48 +0,0 @@
1
- "use strict";
2
-
3
- var _global = _interopRequireDefault(require("global"));
4
-
5
- var _addons = require("@storybook/addons");
6
-
7
- var _coreEvents = require("@storybook/core-events");
8
-
9
- var _constants = require("./constants");
10
-
11
- var _highlight = require("./highlight");
12
-
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
-
15
- const {
16
- document
17
- } = _global.default;
18
-
19
- if (module && module.hot && module.hot.decline) {
20
- module.hot.decline();
21
- }
22
-
23
- const channel = _addons.addons.getChannel();
24
-
25
- const highlight = infos => {
26
- const id = _constants.HIGHLIGHT_STYLE_ID;
27
- resetHighlight(); // Make sure there are no duplicated selectors
28
-
29
- const elements = Array.from(new Set(infos.elements));
30
- const sheet = document.createElement('style');
31
- sheet.setAttribute('id', id);
32
- sheet.innerHTML = elements.map(target => `${target}{
33
- ${(0, _highlight.highlightStyle)(infos.color)}
34
- }`).join(' ');
35
- document.head.appendChild(sheet);
36
- };
37
-
38
- const resetHighlight = () => {
39
- const id = _constants.HIGHLIGHT_STYLE_ID;
40
- const sheetToBeRemoved = document.getElementById(id);
41
-
42
- if (sheetToBeRemoved) {
43
- sheetToBeRemoved.parentNode.removeChild(sheetToBeRemoved);
44
- }
45
- };
46
-
47
- channel.on(_coreEvents.STORY_CHANGED, resetHighlight);
48
- channel.on(_constants.EVENTS.HIGHLIGHT, highlight);
@@ -1,22 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.highlightStyle = exports.highlightObject = void 0;
7
-
8
- const highlightStyle = color => `
9
- outline: 2px dashed ${color};
10
- outline-offset: 2px;
11
- box-shadow: 0 0 0 6px rgba(255,255,255,0.6);
12
- `;
13
-
14
- exports.highlightStyle = highlightStyle;
15
-
16
- const highlightObject = color => ({
17
- outline: `2px dashed ${color}`,
18
- outlineOffset: 2,
19
- boxShadow: '0 0 0 6px rgba(255,255,255,0.6),'
20
- });
21
-
22
- exports.highlightObject = highlightObject;
@@ -1,39 +0,0 @@
1
- import global from 'global';
2
- import { addons } from '@storybook/addons';
3
- import { STORY_CHANGED } from '@storybook/core-events';
4
- import { EVENTS, HIGHLIGHT_STYLE_ID } from './constants';
5
- import { highlightStyle } from './highlight';
6
- const {
7
- document
8
- } = global;
9
-
10
- if (module && module.hot && module.hot.decline) {
11
- module.hot.decline();
12
- }
13
-
14
- const channel = addons.getChannel();
15
-
16
- const highlight = infos => {
17
- const id = HIGHLIGHT_STYLE_ID;
18
- resetHighlight(); // Make sure there are no duplicated selectors
19
-
20
- const elements = Array.from(new Set(infos.elements));
21
- const sheet = document.createElement('style');
22
- sheet.setAttribute('id', id);
23
- sheet.innerHTML = elements.map(target => `${target}{
24
- ${highlightStyle(infos.color)}
25
- }`).join(' ');
26
- document.head.appendChild(sheet);
27
- };
28
-
29
- const resetHighlight = () => {
30
- const id = HIGHLIGHT_STYLE_ID;
31
- const sheetToBeRemoved = document.getElementById(id);
32
-
33
- if (sheetToBeRemoved) {
34
- sheetToBeRemoved.parentNode.removeChild(sheetToBeRemoved);
35
- }
36
- };
37
-
38
- channel.on(STORY_CHANGED, resetHighlight);
39
- channel.on(EVENTS.HIGHLIGHT, highlight);
@@ -1,10 +0,0 @@
1
- export const highlightStyle = color => `
2
- outline: 2px dashed ${color};
3
- outline-offset: 2px;
4
- box-shadow: 0 0 0 6px rgba(255,255,255,0.6);
5
- `;
6
- export const highlightObject = color => ({
7
- outline: `2px dashed ${color}`,
8
- outlineOffset: 2,
9
- boxShadow: '0 0 0 6px rgba(255,255,255,0.6),'
10
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- export declare const highlightStyle: (color: string) => string;
2
- export declare const highlightObject: (color: string) => {
3
- outline: string;
4
- outlineOffset: number;
5
- boxShadow: string;
6
- };