Files
formipay/node_modules/@wordpress/rich-text/build/get-active-formats.js
dwindown e8fbfb14c1 fix: prevent asset conflicts between React and Grid.js versions
Add coexistence checks to all enqueue methods to prevent loading
both React and Grid.js assets simultaneously.

Changes:
- ReactAdmin.php: Only enqueue React assets when ?react=1
- Init.php: Skip Grid.js when React active on admin pages
- Form.php, Coupon.php, Access.php: Restore classic assets when ?react=0
- Customer.php, Product.php, License.php: Add coexistence checks

Now the toggle between Classic and React versions works correctly.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-18 17:02:14 +07:00

89 lines
2.7 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getActiveFormats = getActiveFormats;
var _isFormatEqual = require("./is-format-equal");
/** @typedef {import('./types').RichTextValue} RichTextValue */
/** @typedef {import('./types').RichTextFormatList} RichTextFormatList */
/**
* Internal dependencies
*/
/**
* Gets the all format objects at the start of the selection.
*
* @param {RichTextValue} value Value to inspect.
* @param {Array} EMPTY_ACTIVE_FORMATS Array to return if there are no
* active formats.
*
* @return {RichTextFormatList} Active format objects.
*/
function getActiveFormats(value, EMPTY_ACTIVE_FORMATS = []) {
const {
formats,
start,
end,
activeFormats
} = value;
if (start === undefined) {
return EMPTY_ACTIVE_FORMATS;
}
if (start === end) {
// For a collapsed caret, it is possible to override the active formats.
if (activeFormats) {
return activeFormats;
}
const formatsBefore = formats[start - 1] || EMPTY_ACTIVE_FORMATS;
const formatsAfter = formats[start] || EMPTY_ACTIVE_FORMATS;
// By default, select the lowest amount of formats possible (which means
// the caret is positioned outside the format boundary). The user can
// then use arrow keys to define `activeFormats`.
if (formatsBefore.length < formatsAfter.length) {
return formatsBefore;
}
return formatsAfter;
}
// If there's no formats at the start index, there are not active formats.
if (!formats[start]) {
return EMPTY_ACTIVE_FORMATS;
}
const selectedFormats = formats.slice(start, end);
// Clone the formats so we're not mutating the live value.
const _activeFormats = [...selectedFormats[0]];
let i = selectedFormats.length;
// For performance reasons, start from the end where it's much quicker to
// realise that there are no active formats.
while (i--) {
const formatsAtIndex = selectedFormats[i];
// If we run into any index without formats, we're sure that there's no
// active formats.
if (!formatsAtIndex) {
return EMPTY_ACTIVE_FORMATS;
}
let ii = _activeFormats.length;
// Loop over the active formats and remove any that are not present at
// the current index.
while (ii--) {
const format = _activeFormats[ii];
if (!formatsAtIndex.find(_format => (0, _isFormatEqual.isFormatEqual)(format, _format))) {
_activeFormats.splice(ii, 1);
}
}
// If there are no active formats, we can stop.
if (_activeFormats.length === 0) {
return EMPTY_ACTIVE_FORMATS;
}
}
return _activeFormats || EMPTY_ACTIVE_FORMATS;
}
//# sourceMappingURL=get-active-formats.js.map