@khanacademy/perseus-editor 4.0.0 → 4.1.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/dist/index.js CHANGED
@@ -64,7 +64,7 @@ var i18n__namespace = /*#__PURE__*/_interopNamespace(i18n$1);
64
64
 
65
65
  // This file is processed by a Rollup plugin (replace) to inject the production
66
66
  const libName = "@khanacademy/perseus-editor";
67
- const libVersion = "4.0.0";
67
+ const libVersion = "4.1.1";
68
68
  perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
69
69
 
70
70
  function _extends() {
@@ -28178,39 +28178,31 @@ const INTERNALLY_HOSTED_URL_RE = new RegExp("^(https?|web\\+graphie)://[^/]*" +
28178
28178
  * Alignment option for captions, relative to specified coordinates.
28179
28179
  */
28180
28180
  const captionAlignments = ["center", "above", "above right", "right", "below right", "below", "below left", "left", "above left"];
28181
- const ImageEditor = createReactClass__default["default"]({
28182
- displayName: "ImageEditor",
28183
- propTypes: {
28184
- ...perseus.Changeable.propTypes
28185
- },
28186
- statics: {
28187
- widgetName: "image"
28188
- },
28189
- componentDidMount: function () {
28181
+ class ImageEditor extends React__namespace.Component {
28182
+ _isMounted = false;
28183
+ static displayName = "ImageEditor";
28184
+ static widgetName = "image";
28185
+ static defaultProps = {
28186
+ title: "",
28187
+ range: [defaultRange, defaultRange],
28188
+ box: [defaultBoxSize, defaultBoxSize],
28189
+ backgroundImage: defaultBackgroundImage$1,
28190
+ labels: [],
28191
+ alt: "",
28192
+ caption: ""
28193
+ };
28194
+ state = {
28195
+ backgroundImageError: ""
28196
+ };
28197
+ componentDidMount() {
28190
28198
  // TODO(scottgrant): This is a hack to remove the deprecated call to
28191
28199
  // this.isMounted() but is still considered an anti-pattern.
28192
28200
  this._isMounted = true;
28193
- },
28194
- componentWillUnmount: function () {
28201
+ }
28202
+ componentWillUnmount() {
28195
28203
  this._isMounted = false;
28196
- },
28197
- getDefaultProps: function () {
28198
- return {
28199
- title: "",
28200
- range: [defaultRange, defaultRange],
28201
- box: [defaultBoxSize, defaultBoxSize],
28202
- backgroundImage: defaultBackgroundImage$1,
28203
- labels: [],
28204
- alt: "",
28205
- caption: ""
28206
- };
28207
- },
28208
- getInitialState: function () {
28209
- return {
28210
- backgroundImageError: ""
28211
- };
28212
- },
28213
- render: function () {
28204
+ }
28205
+ render() {
28214
28206
  const backgroundImage = this.props.backgroundImage;
28215
28207
  const imageSettings = /*#__PURE__*/React__namespace.createElement("div", {
28216
28208
  className: "image-settings"
@@ -28251,8 +28243,8 @@ const ImageEditor = createReactClass__default["default"]({
28251
28243
  },
28252
28244
  onChange: url => this.onUrlChange(url, false)
28253
28245
  })), backgroundImage.url && imageSettings);
28254
- },
28255
- _renderRowForLabel: function (label, i) {
28246
+ }
28247
+ _renderRowForLabel(label, i) {
28256
28248
  return /*#__PURE__*/React__namespace.createElement("tr", {
28257
28249
  key: i
28258
28250
  }, /*#__PURE__*/React__namespace.createElement("td", null, /*#__PURE__*/React__namespace.createElement(RangeInput$4, {
@@ -28291,22 +28283,22 @@ const ImageEditor = createReactClass__default["default"]({
28291
28283
  ,
28292
28284
  onClick: this.removeLabel.bind(this, i)
28293
28285
  }, /*#__PURE__*/React__namespace.createElement(InlineIcon$4, perseus.icons.iconTrash))));
28294
- },
28286
+ }
28295
28287
  change() {
28296
28288
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
28297
28289
  args[_key] = arguments[_key];
28298
28290
  }
28299
28291
  return perseus.Changeable.change.apply(this, args);
28300
- },
28301
- removeLabel: function (labelIndex, e) {
28292
+ }
28293
+ removeLabel(labelIndex, e) {
28302
28294
  e.preventDefault();
28303
- const labels = ___default["default"](this.props.labels).clone();
28295
+ const labels = [...this.props.labels];
28304
28296
  labels.splice(labelIndex, 1);
28305
28297
  this.props.onChange({
28306
28298
  labels: labels
28307
28299
  });
28308
- },
28309
- onCoordinateChange: function (labelIndex, newCoordinates) {
28300
+ }
28301
+ onCoordinateChange(labelIndex, newCoordinates) {
28310
28302
  const labels = this.props.labels.slice();
28311
28303
  labels[labelIndex] = ___default["default"].extend({}, labels[labelIndex], {
28312
28304
  coordinates: newCoordinates
@@ -28314,8 +28306,8 @@ const ImageEditor = createReactClass__default["default"]({
28314
28306
  this.props.onChange({
28315
28307
  labels: labels
28316
28308
  });
28317
- },
28318
- onContentChange: function (labelIndex, e) {
28309
+ }
28310
+ onContentChange(labelIndex, e) {
28319
28311
  const newContent = e.target.value;
28320
28312
  const labels = this.props.labels.slice();
28321
28313
  labels[labelIndex] = ___default["default"].extend({}, labels[labelIndex], {
@@ -28324,8 +28316,8 @@ const ImageEditor = createReactClass__default["default"]({
28324
28316
  this.props.onChange({
28325
28317
  labels: labels
28326
28318
  });
28327
- },
28328
- onAlignmentChange: function (labelIndex, e) {
28319
+ }
28320
+ onAlignmentChange(labelIndex, e) {
28329
28321
  const newAlignment = e.target.value;
28330
28322
  const labels = this.props.labels.slice();
28331
28323
  labels[labelIndex] = ___default["default"].extend({}, labels[labelIndex], {
@@ -28334,8 +28326,8 @@ const ImageEditor = createReactClass__default["default"]({
28334
28326
  this.props.onChange({
28335
28327
  labels: labels
28336
28328
  });
28337
- },
28338
- setUrl: function (url, width, height, silent) {
28329
+ }
28330
+ setUrl(url, width, height, silent) {
28339
28331
  // Because this calls into WidgetEditor._handleWidgetChange, which
28340
28332
  // checks for this widget's ref to serialize it.
28341
28333
  //
@@ -28353,11 +28345,12 @@ const ImageEditor = createReactClass__default["default"]({
28353
28345
  backgroundImage: image,
28354
28346
  box: box
28355
28347
  }, null, silent);
28356
- },
28348
+ }
28349
+
28357
28350
  // silently load the image when the component mounts
28358
28351
  // silently update url and sizes when the image loads
28359
28352
  // noisily load the image in response to the author changing it
28360
- onUrlChange: async function (url, silent) {
28353
+ async onUrlChange(url, silent) {
28361
28354
  // Check if we've been passed something that looks like a URL
28362
28355
  if (!url) {
28363
28356
  this.setUrl(url, 0, 0, silent);
@@ -28384,18 +28377,18 @@ const ImageEditor = createReactClass__default["default"]({
28384
28377
  backgroundImageError: `There was an error loading the image URL: ${JSON.stringify(error, null, 2)}`
28385
28378
  });
28386
28379
  }
28387
- },
28388
- onRangeChange: function (type, newRange) {
28380
+ }
28381
+ onRangeChange(type, newRange) {
28389
28382
  const range = this.props.range.slice();
28390
28383
  range[type] = newRange;
28391
28384
  this.props.onChange({
28392
28385
  range: range
28393
28386
  });
28394
- },
28387
+ }
28395
28388
  serialize() {
28396
28389
  return perseus.EditorJsonify.serialize.call(this);
28397
28390
  }
28398
- });
28391
+ }
28399
28392
 
28400
28393
  /* eslint-disable react/sort-comp */
28401
28394
  const {