@khanacademy/perseus-editor 2.16.2 → 3.0.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
@@ -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 = "2.16.2";
67
+ const libVersion = "3.0.0";
68
68
  perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
69
69
 
70
70
  function _extends() {
@@ -20587,8 +20587,7 @@ const DragTarget = createReactClass__default["default"]({
20587
20587
  });
20588
20588
 
20589
20589
  const {
20590
- InlineIcon: InlineIcon$b,
20591
- PropCheckBox: PropCheckBox$e
20590
+ InlineIcon: InlineIcon$b
20592
20591
  } = perseus.components;
20593
20592
  const {
20594
20593
  iconChevronDown: iconChevronDown$1,
@@ -20599,7 +20598,7 @@ const _upgradeWidgetInfo = props => {
20599
20598
  // We can't call serialize here because this.refs.widget
20600
20599
  // doesn't exist before this component is mounted.
20601
20600
  const filteredProps = ___default["default"].omit(props, perseus.WIDGET_PROP_DENYLIST);
20602
- // @ts-expect-error - TS2322 - Type 'PerseusWidget' is not assignable to type 'ReactElement<any, string | JSXElementConstructor<any>>'. | TS2345 - Argument of type 'Partial<{ id: string; onChange: (widgetInfo: PerseusWidget, cb?: (() => unknown) | undefined, silent?: boolean | undefined) => unknown; onRemove: () => unknown; apiOptions: any; } & CategorizerWidget & { ...; }> | ... 38 more ... | Partial<...>' is not assignable to parameter of type 'PerseusWidget'.
20601
+ // @ts-expect-error TS(2345) Type '"categorizer" | undefined' is not assignable to type '"deprecated-standin"'.
20603
20602
  return perseus.Widgets.upgradeWidgetInfoToLatestVersion(filteredProps);
20604
20603
  };
20605
20604
 
@@ -20613,14 +20612,12 @@ class WidgetEditor extends React__namespace.Component {
20613
20612
  super(props);
20614
20613
  this.state = {
20615
20614
  showWidget: false,
20616
- // @ts-expect-error - TS2322 - Type 'ReactElement<any, any> | null' is not assignable to type 'PerseusWidget'.
20617
20615
  widgetInfo: _upgradeWidgetInfo(props)
20618
20616
  };
20619
20617
  }
20620
20618
 
20621
20619
  // eslint-disable-next-line react/no-unsafe
20622
20620
  UNSAFE_componentWillReceiveProps(nextProps) {
20623
- // @ts-expect-error - TS2322 - Type 'ReactElement<any, any> | null' is not assignable to type 'PerseusWidget'.
20624
20621
  this.setState({
20625
20622
  widgetInfo: _upgradeWidgetInfo(nextProps)
20626
20623
  });
@@ -20685,12 +20682,6 @@ class WidgetEditor extends React__namespace.Component {
20685
20682
  supportedAlignments = ["default"];
20686
20683
  }
20687
20684
  const supportsStaticMode = perseus.Widgets.supportsStaticMode(widgetInfo.type);
20688
- const isUngradedEnabled = widgetInfo.type === "transformer";
20689
- const gradedPropBox = /*#__PURE__*/React__namespace.createElement(PropCheckBox$e, {
20690
- label: "Graded:",
20691
- graded: widgetInfo.graded,
20692
- onChange: this.props.onChange
20693
- });
20694
20685
  return /*#__PURE__*/React__namespace.createElement("div", {
20695
20686
  className: "perseus-widget-editor"
20696
20687
  }, /*#__PURE__*/React__namespace.createElement("div", {
@@ -20720,7 +20711,7 @@ class WidgetEditor extends React__namespace.Component {
20720
20711
  title: "Remove image widget"
20721
20712
  })), /*#__PURE__*/React__namespace.createElement("div", {
20722
20713
  className: "perseus-widget-editor-content " + (this.state.showWidget ? "enter" : "leave")
20723
- }, isUngradedEnabled && gradedPropBox, Ed && /*#__PURE__*/React__namespace.createElement(Ed
20714
+ }, Ed && /*#__PURE__*/React__namespace.createElement(Ed
20724
20715
  // eslint-disable-next-line react/no-string-refs
20725
20716
  , _extends({
20726
20717
  ref: "widget",
@@ -20994,19 +20985,13 @@ class Editor extends React__namespace.Component {
20994
20985
  // eslint-disable-next-line no-restricted-syntax
20995
20986
  clearTimeout(this.deferredChange);
20996
20987
  }
20997
- getWidgetEditor = (id, type) => {
20988
+ getWidgetEditor(id, type) {
20998
20989
  if (!perseus.Widgets.getEditor(type)) {
20999
20990
  return;
21000
20991
  }
21001
- return /*#__PURE__*/React__namespace.createElement(WidgetEditor
21002
- // @ts-expect-error - TS2322 - Type 'string' is not assignable to type 'number | undefined'.
21003
- , _extends({
21004
- key: id,
20992
+ return /*#__PURE__*/React__namespace.createElement(WidgetEditor, _extends({
21005
20993
  ref: id,
21006
20994
  id: id
21007
- // @ts-expect-error - TS2783 - 'type' is specified more than once, so this usage will be overwritten.
21008
- ,
21009
- type: type
21010
20995
  // eslint-disable-next-line react/jsx-no-bind
21011
20996
  ,
21012
20997
  onChange: this._handleWidgetEditorChange.bind(this, id)
@@ -21015,7 +21000,7 @@ class Editor extends React__namespace.Component {
21015
21000
  onRemove: this._handleWidgetEditorRemove.bind(this, id),
21016
21001
  apiOptions: this.props.apiOptions
21017
21002
  }, this.props.widgets[id]));
21018
- };
21003
+ }
21019
21004
  _handleWidgetEditorChange = (id, newWidgetInfo, cb, silent) => {
21020
21005
  const widgets = Object.assign({}, this.props.widgets);
21021
21006
  widgets[id] = Object.assign({}, widgets[id], newWidgetInfo);
@@ -21024,6 +21009,10 @@ class Editor extends React__namespace.Component {
21024
21009
  }, cb, silent);
21025
21010
  };
21026
21011
  _handleWidgetEditorRemove = id => {
21012
+ // eslint-disable-next-line no-alert
21013
+ if (!confirm("Are you sure you want to delete this item?")) {
21014
+ return;
21015
+ }
21027
21016
  const textarea = this.textarea.current;
21028
21017
  const re = new RegExp(widgetRegExp.replace("{id}", id), "gm");
21029
21018
  this.props.onChange({
@@ -21342,14 +21331,13 @@ class Editor extends React__namespace.Component {
21342
21331
  const newPostlude = isBlock ? makeStartWithAParagraphAlways(postlude) : postlude;
21343
21332
  const newContent = newPrelude + widgetContent + newPostlude;
21344
21333
  const newWidgets = ___default["default"].clone(this.props.widgets);
21334
+ // @ts-expect-error TS(2345) Type '"categorizer" | undefined' is not assignable to type '"deprecated-standin"'.
21345
21335
  newWidgets[id] = {
21346
21336
  options: perseus.Widgets.getEditor(widgetType)?.defaultProps,
21347
- // @ts-expect-error - TS2322 - Type 'string' is not assignable to type '"video" | "image" | "iframe" | "table" | "radio" | "definition" | "group" | "matrix" | "categorizer" | "cs-program" | "dropdown" | "example-graphie-widget" | "example-widget" | ... 26 more ... | "unit-input"'.
21348
21337
  type: widgetType,
21349
21338
  // Track widget version on creation, so that a widget editor
21350
21339
  // without a valid version prop can only possibly refer to a
21351
21340
  // pre-versioning creation time.
21352
- // @ts-expect-error - TS2322 - Type 'Version | null | undefined' is not assignable to type 'Version | undefined'.
21353
21341
  version: perseus.Widgets.getVersion(widgetType)
21354
21342
  };
21355
21343
 
@@ -21494,6 +21482,8 @@ class Editor extends React__namespace.Component {
21494
21482
  widgets = {};
21495
21483
  underlayPieces = [];
21496
21484
  for (let i = 0; i < pieces.length; i++) {
21485
+ // We split on widgets so every even-numbered indexed piece is
21486
+ // text and odd-numbered indexes are the widget references.
21497
21487
  if (i % 2 === 0) {
21498
21488
  // Normal text
21499
21489
  underlayPieces.push(pieces[i]);
@@ -23653,6 +23643,10 @@ class CombinedHintsEditor extends React__namespace.Component {
23653
23643
  }, cb, silent);
23654
23644
  };
23655
23645
  handleHintRemove = i => {
23646
+ // eslint-disable-next-line no-alert
23647
+ if (!confirm("Are you sure you want to delete this hint?")) {
23648
+ return;
23649
+ }
23656
23650
  const hints = ___default["default"](this.props.hints).clone();
23657
23651
  // @ts-expect-error - TS2339 - Property 'splice' does not exist on type 'Hint'.
23658
23652
  hints.splice(i, 1);
@@ -26127,6 +26121,16 @@ class DefinitionEditor extends React__namespace.Component {
26127
26121
  }
26128
26122
  }
26129
26123
 
26124
+ class DeprecatedStandinEditor extends React__namespace.Component {
26125
+ static widgetName = "deprecated-standin";
26126
+ serialize() {
26127
+ return perseus.EditorJsonify.serialize.call(this);
26128
+ }
26129
+ render() {
26130
+ return /*#__PURE__*/React__namespace.createElement("div", null, /*#__PURE__*/React__namespace.createElement("p", null, "This widget has been deprecated and removed"), /*#__PURE__*/React__namespace.createElement("p", null, "Learners will see a message and they will not be graded on this part. Please replace this widget with a supported one."));
26131
+ }
26132
+ }
26133
+
26130
26134
  /* eslint-disable @khanacademy/ts-no-error-suppressions */
26131
26135
  const {
26132
26136
  InfoTip: InfoTip$k,
@@ -35349,7 +35353,7 @@ class VideoEditor extends React__namespace.Component {
35349
35353
  }
35350
35354
  }
35351
35355
 
35352
- var AllEditors = [CategorizerEditor, CSProgramEditor, DefinitionEditor, DropdownEditor, ExampleGraphieWidgetEditor, ExampleWidgetEditor, ExplanationEditor, ExpressionEditor, GradedGroupEditor, GradedGroupSetEditor, GrapherEditor, GroupEditor, IframeEditor, ImageEditor, InputNumberEditor, InteractionEditor, InteractiveGraphEditor, LabelImageEditor, LightsPuzzleEditor, MatcherEditor, MatrixEditor, MeasurerEditor, MoleculeWidgetEditor, NumberLineEditor, NumericInputEditor, OrdererEditor, PassageEditor, PassageRefEditor, PassageRefTargetEditor, PlotterEditor, ReactionDiagramWidgetEditor, SequenceEditor, SimpleMarkdownTesterEditor, SimulatorEditor, SorterEditor, TableEditor, TransformerEditor, UnitInputEditor, VideoEditor, RadioEditor];
35356
+ var AllEditors = [CategorizerEditor, CSProgramEditor, DefinitionEditor, DropdownEditor, ExampleGraphieWidgetEditor, ExampleWidgetEditor, ExplanationEditor, ExpressionEditor, GradedGroupEditor, GradedGroupSetEditor, GrapherEditor, GroupEditor, IframeEditor, ImageEditor, InputNumberEditor, InteractionEditor, InteractiveGraphEditor, LabelImageEditor, LightsPuzzleEditor, MatcherEditor, MatrixEditor, MeasurerEditor, MoleculeWidgetEditor, NumberLineEditor, NumericInputEditor, OrdererEditor, PassageEditor, PassageRefEditor, PassageRefTargetEditor, PlotterEditor, ReactionDiagramWidgetEditor, SequenceEditor, SimpleMarkdownTesterEditor, SimulatorEditor, SorterEditor, TableEditor, TransformerEditor, UnitInputEditor, VideoEditor, RadioEditor, DeprecatedStandinEditor];
35353
35357
 
35354
35358
  /* eslint-disable @khanacademy/ts-no-error-suppressions */
35355
35359
  class TextInput extends React__namespace.Component {