@atlaskit/editor-plugin-table
Version:
Table plugin for the @atlaskit/editor
47 lines (46 loc) • 2.09 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
export var shallowEqualExcept = function shallowEqualExcept(previousValue, currentValue, ignoredKey) {
var previousKeys = Object.keys(previousValue);
var currentKeys = Object.keys(currentValue);
return previousKeys.length === currentKeys.length && currentKeys.every(function (key) {
return key === ignoredKey || Object.prototype.hasOwnProperty.call(previousValue, key) && Object.is(previousValue[key], currentValue[key]);
});
};
/**
* Returns true when editor focus is the only table plugin state value that changed.
*
* Table reducers preserve references for unchanged values. If a reducer rebuilds a value, this
* returns false and callers take the original full-work path rather than skipping incorrectly.
*/
export var isFocusOnlyChange = function isFocusOnlyChange(previousState, currentState) {
return previousState.editorHasFocus !== currentState.editorHasFocus && shallowEqualExcept(previousState, currentState, 'editorHasFocus');
};
export var FocusOnlyUpdateGuard = /*#__PURE__*/function () {
function FocusOnlyUpdateGuard() {
_classCallCheck(this, FocusOnlyUpdateGuard);
}
return _createClass(FocusOnlyUpdateGuard, [{
key: "skipIfFocusOnly",
value: /** Returns true and records the state when this is a skippable focus-only update. */
function skipIfFocusOnly(state) {
var lastProcessedState = this.lastProcessedState;
if (lastProcessedState !== undefined && isFocusOnlyChange(lastProcessedState, state) && isExperimentEnabled('platform_editor_improve_inp')) {
this.lastProcessedState = state;
return true;
}
return false;
}
}, {
key: "markProcessed",
value: function markProcessed(state) {
this.lastProcessedState = state;
}
}, {
key: "reset",
value: function reset() {
this.lastProcessedState = undefined;
}
}]);
}();