Files
klz-cables.com/.pnpm-store/v10/files/73/b9db213a1737796b423f8396b1102f83e2f15e57b02f77e2e291e224fad4b6e0310ebdbfb35f5f64e06138e0f3942b4a80b417ab62b709c0033e401b597de4
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

92 lines
3.2 KiB
Plaintext

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
'use strict';
var lexical = require('lexical');
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
function registerDragonSupport(editor) {
const origin = window.location.origin;
const handler = event => {
if (event.origin !== origin) {
return;
}
const rootElement = editor.getRootElement();
if (document.activeElement !== rootElement) {
return;
}
const data = event.data;
if (typeof data === 'string') {
let parsedData;
try {
parsedData = JSON.parse(data);
} catch (e) {
return;
}
if (parsedData && parsedData.protocol === 'nuanria_messaging' && parsedData.type === 'request') {
const payload = parsedData.payload;
if (payload && payload.functionId === 'makeChanges') {
const args = payload.args;
if (args) {
const [elementStart, elementLength, text, selStart, selLength, formatCommand] = args;
editor.update(() => {
const selection = lexical.$getSelection();
if (lexical.$isRangeSelection(selection)) {
const anchor = selection.anchor;
let anchorNode = anchor.getNode();
let setSelStart = 0;
let setSelEnd = 0;
if (lexical.$isTextNode(anchorNode)) {
// set initial selection
if (elementStart >= 0 && elementLength >= 0) {
setSelStart = elementStart;
setSelEnd = elementStart + elementLength;
// If the offset is more than the end, make it the end
selection.setTextNodeRange(anchorNode, setSelStart, anchorNode, setSelEnd);
}
}
if (setSelStart !== setSelEnd || text !== '') {
selection.insertRawText(text);
anchorNode = anchor.getNode();
}
if (lexical.$isTextNode(anchorNode)) {
// set final selection
setSelStart = selStart;
setSelEnd = selStart + selLength;
const anchorNodeTextLength = anchorNode.getTextContentSize();
// If the offset is more than the end, make it the end
setSelStart = setSelStart > anchorNodeTextLength ? anchorNodeTextLength : setSelStart;
setSelEnd = setSelEnd > anchorNodeTextLength ? anchorNodeTextLength : setSelEnd;
selection.setTextNodeRange(anchorNode, setSelStart, anchorNode, setSelEnd);
}
// block the chrome extension from handling this event
event.stopImmediatePropagation();
}
});
}
}
}
}
};
window.addEventListener('message', handler, true);
return () => {
window.removeEventListener('message', handler, true);
};
}
exports.registerDragonSupport = registerDragonSupport;