@atlaskit/editor-plugin-media 0.3.4 → 0.3.6

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-media
2
2
 
3
+ ## 0.3.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#41747](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41747) [`8b2001e7bbe`](https://bitbucket.org/atlassian/atlassian-frontend/commits/8b2001e7bbe) - Extend mediaSingle from Component as props were not causing PureComponent to rerender correctly
8
+
9
+ ## 0.3.5
10
+
11
+ ### Patch Changes
12
+
13
+ - [#40861](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/40861) [`a7e65721b8b`](https://bitbucket.org/atlassian/atlassian-frontend/commits/a7e65721b8b) - ECA11Y-73: Add announcements for the screen reader users when the user types incorrect values in Alt text input field
14
+
3
15
  ## 0.3.4
4
16
 
5
17
  ### Patch Changes
@@ -47,8 +47,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
47
47
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
48
48
  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; } } /** @jsx jsx */
49
49
  // eslint-disable-next-line @repo/internal/react/no-class-components
50
- var MediaSingleNode = exports.default = /*#__PURE__*/function (_PureComponent) {
51
- (0, _inherits2.default)(MediaSingleNode, _PureComponent);
50
+ var MediaSingleNode = exports.default = /*#__PURE__*/function (_Component) {
51
+ (0, _inherits2.default)(MediaSingleNode, _Component);
52
52
  var _super = _createSuper(MediaSingleNode);
53
53
  function MediaSingleNode() {
54
54
  var _this;
@@ -442,7 +442,7 @@ var MediaSingleNode = exports.default = /*#__PURE__*/function (_PureComponent) {
442
442
  }
443
443
  }]);
444
444
  return MediaSingleNode;
445
- }(_react.PureComponent);
445
+ }(_react.Component);
446
446
  (0, _defineProperty2.default)(MediaSingleNode, "defaultProps", {
447
447
  mediaOptions: {}
448
448
  });
@@ -75,7 +75,18 @@ var AltTextEditComponent = exports.AltTextEditComponent = /*#__PURE__*/function
75
75
  (0, _commands.updateAltText)(newValue)(view.state, view.dispatch);
76
76
  });
77
77
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleOnChange", function (newAltText) {
78
+ var _this$state;
78
79
  var validationErrors = _this.getValidationErrors(newAltText);
80
+ if (((_this$state = _this.state) === null || _this$state === void 0 || (_this$state = _this$state.validationErrors) === null || _this$state === void 0 ? void 0 : _this$state.length) !== (validationErrors === null || validationErrors === void 0 ? void 0 : validationErrors.length)) {
81
+ // If number of errors was changed we need to reset attribute to get new SR announcement
82
+
83
+ if (_this.errorsListRef) {
84
+ var _this$errorsListRef;
85
+ var errorsArea = (_this$errorsListRef = _this.errorsListRef) === null || _this$errorsListRef === void 0 ? void 0 : _this$errorsListRef.current;
86
+ errorsArea === null || errorsArea === void 0 || errorsArea.removeAttribute('aria-live');
87
+ errorsArea === null || errorsArea === void 0 || errorsArea.setAttribute('aria-live', 'assertive');
88
+ }
89
+ }
79
90
  _this.setState({
80
91
  showClearTextButton: Boolean(newAltText),
81
92
  validationErrors: validationErrors,
@@ -98,6 +109,7 @@ var AltTextEditComponent = exports.AltTextEditComponent = /*#__PURE__*/function
98
109
  });
99
110
  var createAnalyticsEvent = props.createAnalyticsEvent;
100
111
  _this.fireCustomAnalytics = (0, _analytics.fireAnalyticsEvent)(createAnalyticsEvent);
112
+ _this.errorsListRef = /*#__PURE__*/_react.default.createRef();
101
113
  return _this;
102
114
  }
103
115
  (0, _createClass2.default)(AltTextEditComponent, [{
@@ -144,6 +156,7 @@ var AltTextEditComponent = exports.AltTextEditComponent = /*#__PURE__*/function
144
156
  key: index
145
157
  }, error);
146
158
  });
159
+ var hasErrors = !!errorsList.length;
147
160
  return (0, _react2.jsx)("div", {
148
161
  css: container
149
162
  }, (0, _react2.jsx)("section", {
@@ -160,7 +173,7 @@ var AltTextEditComponent = exports.AltTextEditComponent = /*#__PURE__*/function
160
173
  })), (0, _react2.jsx)(_ui.PanelTextInput, {
161
174
  testId: "alt-text-input",
162
175
  ariaLabel: formatMessage(_messages.messages.placeholder),
163
- describedById: "support-text",
176
+ describedById: "".concat(hasErrors ? 'errors-list' : '', " support-text"),
164
177
  placeholder: formatMessage(_messages.messages.placeholder),
165
178
  defaultValue: this.state.lastValue,
166
179
  onCancel: this.dispatchCancelEvent,
@@ -168,6 +181,8 @@ var AltTextEditComponent = exports.AltTextEditComponent = /*#__PURE__*/function
168
181
  onBlur: this.handleOnBlur,
169
182
  onSubmit: this.closeMediaAltTextMenu,
170
183
  maxLength: MAX_ALT_TEXT_LENGTH,
184
+ ariaRequired: true,
185
+ ariaInvalid: hasErrors,
171
186
  autoFocus: true
172
187
  }), showClearTextButton && (0, _react2.jsx)("div", {
173
188
  css: buttonWrapper
@@ -181,7 +196,10 @@ var AltTextEditComponent = exports.AltTextEditComponent = /*#__PURE__*/function
181
196
  })),
182
197
  tooltipContent: formatMessage(_messages.messages.clear),
183
198
  onClick: this.handleClearText
184
- }))), !!errorsList.length && (0, _react2.jsx)("section", {
199
+ }))), hasErrors && (0, _react2.jsx)("section", {
200
+ id: "errors-list",
201
+ ref: this.errorsListRef,
202
+ "aria-live": "assertive",
185
203
  css: validationWrapper
186
204
  }, errorsList), (0, _react2.jsx)("p", {
187
205
  css: supportText,
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  /** @jsx jsx */
4
4
 
5
- import React, { PureComponent } from 'react';
5
+ import React, { Component } from 'react';
6
6
  import { jsx } from '@emotion/react';
7
7
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
8
8
  import { calcMediaSinglePixelWidth, DEFAULT_IMAGE_HEIGHT, DEFAULT_IMAGE_WIDTH, getMaxWidthForNestedNode, MEDIA_SINGLE_GUTTER_SIZE } from '@atlaskit/editor-common/media-single';
@@ -26,7 +26,7 @@ import { hasPrivateAttrsChanged } from './helpers';
26
26
  import { MediaNodeUpdater } from './mediaNodeUpdater';
27
27
  import { figureWrapper, MediaSingleNodeSelector } from './styles';
28
28
  // eslint-disable-next-line @repo/internal/react/no-class-components
29
- export default class MediaSingleNode extends PureComponent {
29
+ export default class MediaSingleNode extends Component {
30
30
  constructor(...args) {
31
31
  super(...args);
32
32
  _defineProperty(this, "mediaNodeUpdater", null);
@@ -93,7 +93,18 @@ export class AltTextEditComponent extends React.Component {
93
93
  updateAltText(newValue)(view.state, view.dispatch);
94
94
  });
95
95
  _defineProperty(this, "handleOnChange", newAltText => {
96
+ var _this$state, _this$state$validatio;
96
97
  const validationErrors = this.getValidationErrors(newAltText);
98
+ if (((_this$state = this.state) === null || _this$state === void 0 ? void 0 : (_this$state$validatio = _this$state.validationErrors) === null || _this$state$validatio === void 0 ? void 0 : _this$state$validatio.length) !== (validationErrors === null || validationErrors === void 0 ? void 0 : validationErrors.length)) {
99
+ // If number of errors was changed we need to reset attribute to get new SR announcement
100
+
101
+ if (this.errorsListRef) {
102
+ var _this$errorsListRef;
103
+ const errorsArea = (_this$errorsListRef = this.errorsListRef) === null || _this$errorsListRef === void 0 ? void 0 : _this$errorsListRef.current;
104
+ errorsArea === null || errorsArea === void 0 ? void 0 : errorsArea.removeAttribute('aria-live');
105
+ errorsArea === null || errorsArea === void 0 ? void 0 : errorsArea.setAttribute('aria-live', 'assertive');
106
+ }
107
+ }
97
108
  this.setState({
98
109
  showClearTextButton: Boolean(newAltText),
99
110
  validationErrors,
@@ -120,6 +131,7 @@ export class AltTextEditComponent extends React.Component {
120
131
  createAnalyticsEvent
121
132
  } = props;
122
133
  this.fireCustomAnalytics = fireAnalyticsEvent(createAnalyticsEvent);
134
+ this.errorsListRef = /*#__PURE__*/React.createRef();
123
135
  }
124
136
  componentDidMount() {
125
137
  this.prevValue = this.props.value;
@@ -165,6 +177,7 @@ export class AltTextEditComponent extends React.Component {
165
177
  key: index
166
178
  }, error);
167
179
  });
180
+ const hasErrors = !!errorsList.length;
168
181
  return jsx("div", {
169
182
  css: container
170
183
  }, jsx("section", {
@@ -181,7 +194,7 @@ export class AltTextEditComponent extends React.Component {
181
194
  })), jsx(PanelTextInput, {
182
195
  testId: "alt-text-input",
183
196
  ariaLabel: formatMessage(messages.placeholder),
184
- describedById: "support-text",
197
+ describedById: `${hasErrors ? 'errors-list' : ''} support-text`,
185
198
  placeholder: formatMessage(messages.placeholder),
186
199
  defaultValue: this.state.lastValue,
187
200
  onCancel: this.dispatchCancelEvent,
@@ -189,6 +202,8 @@ export class AltTextEditComponent extends React.Component {
189
202
  onBlur: this.handleOnBlur,
190
203
  onSubmit: this.closeMediaAltTextMenu,
191
204
  maxLength: MAX_ALT_TEXT_LENGTH,
205
+ ariaRequired: true,
206
+ ariaInvalid: hasErrors,
192
207
  autoFocus: true
193
208
  }), showClearTextButton && jsx("div", {
194
209
  css: buttonWrapper
@@ -202,7 +217,10 @@ export class AltTextEditComponent extends React.Component {
202
217
  })),
203
218
  tooltipContent: formatMessage(messages.clear),
204
219
  onClick: this.handleClearText
205
- }))), !!errorsList.length && jsx("section", {
220
+ }))), hasErrors && jsx("section", {
221
+ id: "errors-list",
222
+ ref: this.errorsListRef,
223
+ "aria-live": "assertive",
206
224
  css: validationWrapper
207
225
  }, errorsList), jsx("p", {
208
226
  css: supportText,
@@ -15,7 +15,7 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
15
15
  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; } }
16
16
  /** @jsx jsx */
17
17
 
18
- import React, { PureComponent } from 'react';
18
+ import React, { Component } from 'react';
19
19
  import { jsx } from '@emotion/react';
20
20
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
21
21
  import { calcMediaSinglePixelWidth, DEFAULT_IMAGE_HEIGHT, DEFAULT_IMAGE_WIDTH, getMaxWidthForNestedNode, MEDIA_SINGLE_GUTTER_SIZE } from '@atlaskit/editor-common/media-single';
@@ -39,8 +39,8 @@ import { hasPrivateAttrsChanged } from './helpers';
39
39
  import { MediaNodeUpdater } from './mediaNodeUpdater';
40
40
  import { figureWrapper, MediaSingleNodeSelector } from './styles';
41
41
  // eslint-disable-next-line @repo/internal/react/no-class-components
42
- var MediaSingleNode = /*#__PURE__*/function (_PureComponent) {
43
- _inherits(MediaSingleNode, _PureComponent);
42
+ var MediaSingleNode = /*#__PURE__*/function (_Component) {
43
+ _inherits(MediaSingleNode, _Component);
44
44
  var _super = _createSuper(MediaSingleNode);
45
45
  function MediaSingleNode() {
46
46
  var _this;
@@ -434,7 +434,7 @@ var MediaSingleNode = /*#__PURE__*/function (_PureComponent) {
434
434
  }
435
435
  }]);
436
436
  return MediaSingleNode;
437
- }(PureComponent);
437
+ }(Component);
438
438
  _defineProperty(MediaSingleNode, "defaultProps", {
439
439
  mediaOptions: {}
440
440
  });
@@ -72,7 +72,18 @@ export var AltTextEditComponent = /*#__PURE__*/function (_React$Component) {
72
72
  updateAltText(newValue)(view.state, view.dispatch);
73
73
  });
74
74
  _defineProperty(_assertThisInitialized(_this), "handleOnChange", function (newAltText) {
75
+ var _this$state;
75
76
  var validationErrors = _this.getValidationErrors(newAltText);
77
+ if (((_this$state = _this.state) === null || _this$state === void 0 || (_this$state = _this$state.validationErrors) === null || _this$state === void 0 ? void 0 : _this$state.length) !== (validationErrors === null || validationErrors === void 0 ? void 0 : validationErrors.length)) {
78
+ // If number of errors was changed we need to reset attribute to get new SR announcement
79
+
80
+ if (_this.errorsListRef) {
81
+ var _this$errorsListRef;
82
+ var errorsArea = (_this$errorsListRef = _this.errorsListRef) === null || _this$errorsListRef === void 0 ? void 0 : _this$errorsListRef.current;
83
+ errorsArea === null || errorsArea === void 0 || errorsArea.removeAttribute('aria-live');
84
+ errorsArea === null || errorsArea === void 0 || errorsArea.setAttribute('aria-live', 'assertive');
85
+ }
86
+ }
76
87
  _this.setState({
77
88
  showClearTextButton: Boolean(newAltText),
78
89
  validationErrors: validationErrors,
@@ -95,6 +106,7 @@ export var AltTextEditComponent = /*#__PURE__*/function (_React$Component) {
95
106
  });
96
107
  var createAnalyticsEvent = props.createAnalyticsEvent;
97
108
  _this.fireCustomAnalytics = fireAnalyticsEvent(createAnalyticsEvent);
109
+ _this.errorsListRef = /*#__PURE__*/React.createRef();
98
110
  return _this;
99
111
  }
100
112
  _createClass(AltTextEditComponent, [{
@@ -141,6 +153,7 @@ export var AltTextEditComponent = /*#__PURE__*/function (_React$Component) {
141
153
  key: index
142
154
  }, error);
143
155
  });
156
+ var hasErrors = !!errorsList.length;
144
157
  return jsx("div", {
145
158
  css: container
146
159
  }, jsx("section", {
@@ -157,7 +170,7 @@ export var AltTextEditComponent = /*#__PURE__*/function (_React$Component) {
157
170
  })), jsx(PanelTextInput, {
158
171
  testId: "alt-text-input",
159
172
  ariaLabel: formatMessage(messages.placeholder),
160
- describedById: "support-text",
173
+ describedById: "".concat(hasErrors ? 'errors-list' : '', " support-text"),
161
174
  placeholder: formatMessage(messages.placeholder),
162
175
  defaultValue: this.state.lastValue,
163
176
  onCancel: this.dispatchCancelEvent,
@@ -165,6 +178,8 @@ export var AltTextEditComponent = /*#__PURE__*/function (_React$Component) {
165
178
  onBlur: this.handleOnBlur,
166
179
  onSubmit: this.closeMediaAltTextMenu,
167
180
  maxLength: MAX_ALT_TEXT_LENGTH,
181
+ ariaRequired: true,
182
+ ariaInvalid: hasErrors,
168
183
  autoFocus: true
169
184
  }), showClearTextButton && jsx("div", {
170
185
  css: buttonWrapper
@@ -178,7 +193,10 @@ export var AltTextEditComponent = /*#__PURE__*/function (_React$Component) {
178
193
  })),
179
194
  tooltipContent: formatMessage(messages.clear),
180
195
  onClick: this.handleClearText
181
- }))), !!errorsList.length && jsx("section", {
196
+ }))), hasErrors && jsx("section", {
197
+ id: "errors-list",
198
+ ref: this.errorsListRef,
199
+ "aria-live": "assertive",
182
200
  css: validationWrapper
183
201
  }, errorsList), jsx("p", {
184
202
  css: supportText,
@@ -1,6 +1,6 @@
1
1
  /** @jsx jsx */
2
2
  import type { MouseEvent } from 'react';
3
- import React, { PureComponent } from 'react';
3
+ import React, { Component } from 'react';
4
4
  import { jsx } from '@emotion/react';
5
5
  import type { RichMediaLayout as MediaSingleLayout } from '@atlaskit/adf-schema';
6
6
  import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
@@ -25,7 +25,7 @@ export interface MediaSingleNodeState {
25
25
  contextIdentifierProvider?: ContextIdentifierProvider;
26
26
  isCopying: boolean;
27
27
  }
28
- export default class MediaSingleNode extends PureComponent<MediaSingleNodeProps, MediaSingleNodeState> {
28
+ export default class MediaSingleNode extends Component<MediaSingleNodeProps, MediaSingleNodeState> {
29
29
  static defaultProps: Partial<MediaSingleNodeProps>;
30
30
  static displayName: string;
31
31
  mediaNodeUpdater: MediaNodeUpdater | null;
@@ -18,6 +18,7 @@ export type AltTextEditComponentState = {
18
18
  };
19
19
  export declare class AltTextEditComponent extends React.Component<Props, AltTextEditComponentState> {
20
20
  private fireCustomAnalytics?;
21
+ private errorsListRef;
21
22
  state: {
22
23
  showClearTextButton: boolean;
23
24
  validationErrors: string[];
@@ -1,6 +1,6 @@
1
1
  /** @jsx jsx */
2
2
  import type { MouseEvent } from 'react';
3
- import React, { PureComponent } from 'react';
3
+ import React, { Component } from 'react';
4
4
  import { jsx } from '@emotion/react';
5
5
  import type { RichMediaLayout as MediaSingleLayout } from '@atlaskit/adf-schema';
6
6
  import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
@@ -25,7 +25,7 @@ export interface MediaSingleNodeState {
25
25
  contextIdentifierProvider?: ContextIdentifierProvider;
26
26
  isCopying: boolean;
27
27
  }
28
- export default class MediaSingleNode extends PureComponent<MediaSingleNodeProps, MediaSingleNodeState> {
28
+ export default class MediaSingleNode extends Component<MediaSingleNodeProps, MediaSingleNodeState> {
29
29
  static defaultProps: Partial<MediaSingleNodeProps>;
30
30
  static displayName: string;
31
31
  mediaNodeUpdater: MediaNodeUpdater | null;
@@ -18,6 +18,7 @@ export type AltTextEditComponentState = {
18
18
  };
19
19
  export declare class AltTextEditComponent extends React.Component<Props, AltTextEditComponentState> {
20
20
  private fireCustomAnalytics?;
21
+ private errorsListRef;
21
22
  state: {
22
23
  showClearTextButton: boolean;
23
24
  validationErrors: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-media",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "description": "Media plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -36,7 +36,7 @@
36
36
  "@atlaskit/analytics-namespaced-context": "^6.7.0",
37
37
  "@atlaskit/analytics-next": "^9.1.0",
38
38
  "@atlaskit/button": "^16.10.0",
39
- "@atlaskit/editor-common": "^76.10.0",
39
+ "@atlaskit/editor-common": "^76.11.0",
40
40
  "@atlaskit/editor-palette": "1.5.1",
41
41
  "@atlaskit/editor-plugin-analytics": "^0.2.0",
42
42
  "@atlaskit/editor-plugin-decorations": "^0.2.0",
@@ -62,7 +62,7 @@
62
62
  "@atlaskit/platform-feature-flags": "^0.2.0",
63
63
  "@atlaskit/textfield": "^5.6.0",
64
64
  "@atlaskit/theme": "^12.6.0",
65
- "@atlaskit/tokens": "^1.26.0",
65
+ "@atlaskit/tokens": "^1.27.0",
66
66
  "@atlaskit/tooltip": "^17.8.0",
67
67
  "@babel/runtime": "^7.0.0",
68
68
  "@emotion/react": "^11.7.1",