@zzish/math-rich-input 0.1.55 → 0.1.56
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 +30 -4
- package/dist/standalone.js +1 -1
- package/package.json +4 -2
- package/src/MathRichInput.jsx +35 -5
package/dist/index.js
CHANGED
|
@@ -22010,6 +22010,7 @@ var EMPTY_INLINE_FORMATTING_REG_EXP = /<(B|STRONG|I|EM|U|SUB|SUP)>(?:\s| |\
|
|
|
22010
22010
|
// const LATEX_MARKER_END = "</annotation>"
|
|
22011
22011
|
|
|
22012
22012
|
var MAX_HISTORY_LENGTH = 100;
|
|
22013
|
+
var CONTROLLED_VALUE_ECHO_TIMEOUT_MS = 50;
|
|
22013
22014
|
var DEFAULT_OPTIONS = {
|
|
22014
22015
|
useExpertMode: false,
|
|
22015
22016
|
selectedTab: null
|
|
@@ -22197,6 +22198,18 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
22197
22198
|
isExpertMode: isExpertMode,
|
|
22198
22199
|
selectedTab: selectedTab
|
|
22199
22200
|
});
|
|
22201
|
+
if (applyOptions.skipControlledRender === true) {
|
|
22202
|
+
var pendingNativeValue = value;
|
|
22203
|
+
// Give a scheduled controlled echo one short render window. If the host
|
|
22204
|
+
// never echoes the value, release the gate rather than preserving a
|
|
22205
|
+
// rejected native edit indefinitely.
|
|
22206
|
+
setTimeout(function () {
|
|
22207
|
+
if (_this2.skipNextControlledValueRender === true && _this2.skipNextControlledValue === pendingNativeValue) {
|
|
22208
|
+
_this2.skipNextControlledValueRender = false;
|
|
22209
|
+
_this2.skipNextControlledValue = null;
|
|
22210
|
+
}
|
|
22211
|
+
}, CONTROLLED_VALUE_ECHO_TIMEOUT_MS);
|
|
22212
|
+
}
|
|
22200
22213
|
debugMathRichInput("applyChangesToComponent:after-onChange", {
|
|
22201
22214
|
afterComponentUpdateData: _this2.afterComponentUpdateData,
|
|
22202
22215
|
selection: getSelectionSnapshot(_this2.editableDiv)
|
|
@@ -24685,7 +24698,8 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
24685
24698
|
value: function getEditableHtmlForRender(html) {
|
|
24686
24699
|
var currentRawText = this.editableDiv ? this.getCurrentRawTextForProps(this.props) : null;
|
|
24687
24700
|
var liveEditableHtml = this.editableDiv ? this.editableDiv.innerHTML : null;
|
|
24688
|
-
var
|
|
24701
|
+
var pendingNativeInputMatchesLiveDom = this.skipNextControlledValueRender === true && currentRawText === this.skipNextControlledValue;
|
|
24702
|
+
var canPreserveNativeDom = this.state.hasFocus === true && this.editableDiv !== null && this.editableDiv !== undefined && (this.afterComponentUpdateData === null || this.afterComponentUpdateData === undefined) && this.lastRenderedEditableHtml !== null && (currentRawText === this.props.value || pendingNativeInputMatchesLiveDom);
|
|
24689
24703
|
var preserveRangeParams = canPreserveNativeDom ? this.getRangeParamsPreservingInlinePlaceholder() : null;
|
|
24690
24704
|
debugMathRichInput("render:editable-html", {
|
|
24691
24705
|
canPreserveNativeDom: canPreserveNativeDom,
|
|
@@ -24696,6 +24710,7 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
24696
24710
|
liveEditableHtml: liveEditableHtml,
|
|
24697
24711
|
lastRenderedEditableHtml: this.lastRenderedEditableHtml,
|
|
24698
24712
|
currentRawText: currentRawText,
|
|
24713
|
+
pendingNativeInputMatchesLiveDom: pendingNativeInputMatchesLiveDom,
|
|
24699
24714
|
preserveRangeParams: preserveRangeParams,
|
|
24700
24715
|
afterComponentUpdateData: this.afterComponentUpdateData,
|
|
24701
24716
|
hasFocus: this.state.hasFocus,
|
|
@@ -25043,18 +25058,29 @@ var MathRichInput = /*#__PURE__*/function (_React$Component) {
|
|
|
25043
25058
|
key: "shouldComponentUpdate",
|
|
25044
25059
|
value: function shouldComponentUpdate(nextProps, nextState) {
|
|
25045
25060
|
if (this.skipNextControlledValueRender === true) {
|
|
25046
|
-
var
|
|
25061
|
+
var controlledValueArrived = nextProps.value === this.skipNextControlledValue;
|
|
25062
|
+
var canSkip = controlledValueArrived && nextState === this.state;
|
|
25047
25063
|
debugMathRichInput("shouldComponentUpdate:native-input-gate", {
|
|
25048
25064
|
canSkip: canSkip,
|
|
25049
25065
|
nextValue: nextProps.value,
|
|
25050
25066
|
skipNextControlledValue: this.skipNextControlledValue,
|
|
25067
|
+
controlledValueArrived: controlledValueArrived,
|
|
25051
25068
|
currentPropsValue: this.props.value,
|
|
25052
25069
|
stateChanged: nextState !== this.state,
|
|
25053
25070
|
innerHTML: this.editableDiv ? this.editableDiv.innerHTML : null,
|
|
25054
25071
|
selection: getSelectionSnapshot(this.editableDiv)
|
|
25055
25072
|
});
|
|
25056
|
-
|
|
25057
|
-
|
|
25073
|
+
|
|
25074
|
+
// A controlled host may commit an unrelated render before it echoes the
|
|
25075
|
+
// value from this native input event. Keep the gate armed through that
|
|
25076
|
+
// stale render so getEditableHtmlForRender can preserve the browser DOM
|
|
25077
|
+
// and its selection. The time-bounded fallback armed by
|
|
25078
|
+
// applyChangesToComponent keeps a host that rejects the value from
|
|
25079
|
+
// leaving the gate armed indefinitely.
|
|
25080
|
+
if (controlledValueArrived) {
|
|
25081
|
+
this.skipNextControlledValueRender = false;
|
|
25082
|
+
this.skipNextControlledValue = null;
|
|
25083
|
+
}
|
|
25058
25084
|
if (canSkip) return false;
|
|
25059
25085
|
}
|
|
25060
25086
|
if (this.shouldSkipRedundantFocusedRender(nextProps, nextState)) {
|