@khanacademy/perseus-editor 2.3.13 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @khanacademy/perseus-editor
2
2
 
3
+ ## 2.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - @khanacademy/perseus@7.0.2
8
+
9
+ ## 2.4.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 97d02dac: Fixes a bug where images don't get dimensions in the image editor, and adds small preview to the image editor
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [5611204a]
18
+ - @khanacademy/perseus@7.0.1
19
+
3
20
  ## 2.3.13
4
21
 
5
22
  ### Patch Changes
package/dist/es/index.js CHANGED
@@ -28178,7 +28178,13 @@ const ImageEditor = createReactClass({
28178
28178
  const backgroundImage = this.props.backgroundImage;
28179
28179
  const imageSettings = /*#__PURE__*/React.createElement("div", {
28180
28180
  className: "image-settings"
28181
- }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", null, /*#__PURE__*/React.createElement("div", null, "Alt text:", /*#__PURE__*/React.createElement(InfoTip$g, null, "This is important for screenreaders. The content of this alt text will be formatted as markdown (tables, emphasis, etc. are supported).")), /*#__PURE__*/React.createElement(Editor, {
28181
+ }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", null, /*#__PURE__*/React.createElement("div", null, "Preview:"), /*#__PURE__*/React.createElement("img", {
28182
+ alt: "Editor preview of image",
28183
+ src: backgroundImage.url,
28184
+ style: {
28185
+ width: "100%"
28186
+ }
28187
+ }))), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", null, /*#__PURE__*/React.createElement("div", null, "Dimensions:"), /*#__PURE__*/React.createElement("p", null, backgroundImage.width, "x", backgroundImage.height))), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", null, /*#__PURE__*/React.createElement("div", null, "Alt text:", /*#__PURE__*/React.createElement(InfoTip$g, null, "This is important for screenreaders. The content of this alt text will be formatted as markdown (tables, emphasis, etc. are supported).")), /*#__PURE__*/React.createElement(Editor, {
28182
28188
  apiOptions: this.props.apiOptions,
28183
28189
  content: this.props.alt,
28184
28190
  onChange: props => {
@@ -28312,7 +28318,13 @@ const ImageEditor = createReactClass({
28312
28318
  // silently load the image when the component mounts
28313
28319
  // silently update url and sizes when the image loads
28314
28320
  // noisily load the image in response to the author changing it
28315
- onUrlChange: function (url, silent) {
28321
+ onUrlChange: async function (url, silent) {
28322
+ // Check if we've been passed something that looks like a URL
28323
+ if (!url) {
28324
+ this.setUrl(url, 0, 0, silent);
28325
+ return;
28326
+ }
28327
+
28316
28328
  // All article content must be KA-owned!
28317
28329
  if (!INTERNALLY_HOSTED_URL_RE.test(url)) {
28318
28330
  this.setState({
@@ -28320,24 +28332,19 @@ const ImageEditor = createReactClass({
28320
28332
  });
28321
28333
  return;
28322
28334
  }
28335
+
28336
+ // Clear previous errors
28323
28337
  this.setState({
28324
28338
  backgroundImageError: ""
28325
28339
  });
28326
-
28327
- // We update our background image prop after the image loads below. To
28328
- // avoid weirdness when we change to a very slow URL, then a much
28329
- // faster URL, we keep track of the URL we're trying to change to.
28330
- this._leadingUrl = url;
28331
- if (!url) {
28332
- this.setUrl(url, 0, 0, silent);
28333
- return;
28340
+ try {
28341
+ const size = await Util.getImageSizeModern(url);
28342
+ this.setUrl(url, size[0], size[1], true);
28343
+ } catch (error) {
28344
+ this.setState({
28345
+ backgroundImageError: `There was an error loading the image URL: ${error}`
28346
+ });
28334
28347
  }
28335
- Util.getImageSize(url, (width, height) => {
28336
- if (this._leadingUrl !== url) {
28337
- return;
28338
- }
28339
- this.setUrl(url, width, height, true);
28340
- });
28341
28348
  },
28342
28349
  onRangeChange: function (type, newRange) {
28343
28350
  const range = this.props.range.slice();