@khanacademy/perseus-editor 2.3.13 → 2.4.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.
package/dist/index.js CHANGED
@@ -28323,7 +28323,13 @@ const ImageEditor = createReactClass__default["default"]({
28323
28323
  const backgroundImage = this.props.backgroundImage;
28324
28324
  const imageSettings = /*#__PURE__*/React__namespace.createElement("div", {
28325
28325
  className: "image-settings"
28326
- }, /*#__PURE__*/React__namespace.createElement("div", null, /*#__PURE__*/React__namespace.createElement("label", null, /*#__PURE__*/React__namespace.createElement("div", null, "Alt text:", /*#__PURE__*/React__namespace.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__namespace.createElement(Editor, {
28326
+ }, /*#__PURE__*/React__namespace.createElement("div", null, /*#__PURE__*/React__namespace.createElement("label", null, /*#__PURE__*/React__namespace.createElement("div", null, "Preview:"), /*#__PURE__*/React__namespace.createElement("img", {
28327
+ alt: "Editor preview of image",
28328
+ src: backgroundImage.url,
28329
+ style: {
28330
+ width: "100%"
28331
+ }
28332
+ }))), /*#__PURE__*/React__namespace.createElement("div", null, /*#__PURE__*/React__namespace.createElement("label", null, /*#__PURE__*/React__namespace.createElement("div", null, "Dimensions:"), /*#__PURE__*/React__namespace.createElement("p", null, backgroundImage.width, "x", backgroundImage.height))), /*#__PURE__*/React__namespace.createElement("div", null, /*#__PURE__*/React__namespace.createElement("label", null, /*#__PURE__*/React__namespace.createElement("div", null, "Alt text:", /*#__PURE__*/React__namespace.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__namespace.createElement(Editor, {
28327
28333
  apiOptions: this.props.apiOptions,
28328
28334
  content: this.props.alt,
28329
28335
  onChange: props => {
@@ -28460,7 +28466,13 @@ const ImageEditor = createReactClass__default["default"]({
28460
28466
  // silently load the image when the component mounts
28461
28467
  // silently update url and sizes when the image loads
28462
28468
  // noisily load the image in response to the author changing it
28463
- onUrlChange: function (url, silent) {
28469
+ onUrlChange: async function (url, silent) {
28470
+ // Check if we've been passed something that looks like a URL
28471
+ if (!url) {
28472
+ this.setUrl(url, 0, 0, silent);
28473
+ return;
28474
+ }
28475
+
28464
28476
  // All article content must be KA-owned!
28465
28477
  if (!INTERNALLY_HOSTED_URL_RE.test(url)) {
28466
28478
  this.setState({
@@ -28468,24 +28480,19 @@ const ImageEditor = createReactClass__default["default"]({
28468
28480
  });
28469
28481
  return;
28470
28482
  }
28483
+
28484
+ // Clear previous errors
28471
28485
  this.setState({
28472
28486
  backgroundImageError: ""
28473
28487
  });
28474
-
28475
- // We update our background image prop after the image loads below. To
28476
- // avoid weirdness when we change to a very slow URL, then a much
28477
- // faster URL, we keep track of the URL we're trying to change to.
28478
- this._leadingUrl = url;
28479
- if (!url) {
28480
- this.setUrl(url, 0, 0, silent);
28481
- return;
28488
+ try {
28489
+ const size = await perseus.Util.getImageSizeModern(url);
28490
+ this.setUrl(url, size[0], size[1], true);
28491
+ } catch (error) {
28492
+ this.setState({
28493
+ backgroundImageError: "There was an error loading the image URL: ".concat(error)
28494
+ });
28482
28495
  }
28483
- perseus.Util.getImageSize(url, (width, height) => {
28484
- if (this._leadingUrl !== url) {
28485
- return;
28486
- }
28487
- this.setUrl(url, width, height, true);
28488
- });
28489
28496
  },
28490
28497
  onRangeChange: function (type, newRange) {
28491
28498
  const range = this.props.range.slice();