@linzjs/windows 11.3.0 → 12.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 +41 -12
- package/dist/index.js.map +1 -1
- package/dist/panel/PopoutWindow.js +9 -4
- package/dist/panel/PopoutWindow.js.map +1 -1
- package/dist/panel/handleStyleSheetsChanges.d.ts +4 -2
- package/dist/panel/handleStyleSheetsChanges.js +23 -8
- package/dist/panel/handleStyleSheetsChanges.js.map +1 -1
- package/dist/panel/openExternalWindow.js +12 -3
- package/dist/panel/openExternalWindow.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10679,6 +10679,26 @@ const makePopoutId = (str) => str
|
|
|
10679
10679
|
.toLowerCase();
|
|
10680
10680
|
const popoutWindowDivId = (windowTitle) => `popoutWindow-${makePopoutId(windowTitle)}`;
|
|
10681
10681
|
|
|
10682
|
+
// Shared patch for CSSStyleSheet.insertRule so multiple concurrent popouts don't stomp each other.
|
|
10683
|
+
// Emotion (used by react-select) injects styles via insertRule, bypassing DOM mutations entirely.
|
|
10684
|
+
const insertRuleListeners = new Set();
|
|
10685
|
+
const originalInsertRule = CSSStyleSheet.prototype.insertRule;
|
|
10686
|
+
const addInsertRuleListener = (fn) => {
|
|
10687
|
+
if (insertRuleListeners.size === 0) {
|
|
10688
|
+
CSSStyleSheet.prototype.insertRule = function (rule, index) {
|
|
10689
|
+
const result = originalInsertRule.call(this, rule, index);
|
|
10690
|
+
insertRuleListeners.forEach((listener) => listener());
|
|
10691
|
+
return result;
|
|
10692
|
+
};
|
|
10693
|
+
}
|
|
10694
|
+
insertRuleListeners.add(fn);
|
|
10695
|
+
};
|
|
10696
|
+
const removeInsertRuleListener = (fn) => {
|
|
10697
|
+
insertRuleListeners.delete(fn);
|
|
10698
|
+
if (insertRuleListeners.size === 0) {
|
|
10699
|
+
CSSStyleSheet.prototype.insertRule = originalInsertRule;
|
|
10700
|
+
}
|
|
10701
|
+
};
|
|
10682
10702
|
// Copy the app's styles into the new window
|
|
10683
10703
|
const copyStyleSheets = (newHeadMountElement) => {
|
|
10684
10704
|
const stylesheets = Array.from(document.styleSheets);
|
|
@@ -10706,19 +10726,15 @@ const copyStyleSheets = (newHeadMountElement) => {
|
|
|
10706
10726
|
* This works by listening to any changes to the head element
|
|
10707
10727
|
* If there are any changes it replaces all the styles in the floating window
|
|
10708
10728
|
* at most every 100ms
|
|
10709
|
-
* @param
|
|
10729
|
+
* @param onStyleChange throttled callback to trigger a style copy
|
|
10710
10730
|
*/
|
|
10711
|
-
const observeStyleSheetChanges = (
|
|
10731
|
+
const observeStyleSheetChanges = (onStyleChange) => {
|
|
10712
10732
|
const targetNode = document.querySelector('head');
|
|
10713
10733
|
if (!targetNode) {
|
|
10714
10734
|
return null;
|
|
10715
10735
|
}
|
|
10716
10736
|
// Options for the observer (which mutations to observe)
|
|
10717
10737
|
const config = { /*attributes: true,*/ childList: true /*, subtree: true */ };
|
|
10718
|
-
//throttle the copying of the all the styles at most 100ms
|
|
10719
|
-
const throttleCopyStyleSheets = throttle(() => {
|
|
10720
|
-
copyStyleSheets(newHeadMountElement);
|
|
10721
|
-
}, 100);
|
|
10722
10738
|
// Callback function to execute when mutations are observed
|
|
10723
10739
|
const callback = function (mutationList) {
|
|
10724
10740
|
for (const mutation of mutationList) {
|
|
@@ -10729,7 +10745,7 @@ const observeStyleSheetChanges = (newHeadMountElement) => {
|
|
|
10729
10745
|
//floating window is complicated, so the easiest way is to just wait for modifications for finish
|
|
10730
10746
|
//updating, then replace them all
|
|
10731
10747
|
//we could probably just copy all style on every modification, by that might have a performance hit
|
|
10732
|
-
|
|
10748
|
+
onStyleChange();
|
|
10733
10749
|
} /*else if (mutation.type === "attributes") {
|
|
10734
10750
|
//Do we need to handle attribute modifications?
|
|
10735
10751
|
// console.log("The " + mutation.attributeName + " attribute was modified.");
|
|
@@ -10790,11 +10806,19 @@ const openExternalWindow = ({ title, size, setContainerElement, setHeadElement,
|
|
|
10790
10806
|
// so the modal shows up in the popped out window instead the main window
|
|
10791
10807
|
newMountElement.id = popoutWindowDivId(title);
|
|
10792
10808
|
copyStyleSheets(newHeadMountElement);
|
|
10809
|
+
// Always intercept insertRule so styles injected after the initial copy (e.g. react-select
|
|
10810
|
+
// rendering after the window opens) are synced to the popout. Uses a shared throttled
|
|
10811
|
+
// callback so both this and the optional MutationObserver drive the same copy call.
|
|
10812
|
+
const throttledCopy = throttle(() => copyStyleSheets(newHeadMountElement), 100);
|
|
10813
|
+
addInsertRuleListener(throttledCopy);
|
|
10793
10814
|
let observer = null;
|
|
10794
10815
|
if (observeStyleChanges) {
|
|
10795
|
-
observer = observeStyleSheetChanges(
|
|
10816
|
+
observer = observeStyleSheetChanges(throttledCopy);
|
|
10796
10817
|
}
|
|
10797
|
-
externalWindow.onbeforeunload = () =>
|
|
10818
|
+
externalWindow.onbeforeunload = () => {
|
|
10819
|
+
observer?.disconnect();
|
|
10820
|
+
removeInsertRuleListener(throttledCopy);
|
|
10821
|
+
};
|
|
10798
10822
|
response.onCloseExternalWindow = () => {
|
|
10799
10823
|
// Make sure the window closes when the component unmounts
|
|
10800
10824
|
externalWindow.close();
|
|
@@ -10861,9 +10885,14 @@ const PopoutWindow = ({ name, title = name, size, popInPanelPosition, popInPanel
|
|
|
10861
10885
|
// The `@emotion/react/CacheProvider`provides a cache derived from createCache for inline styles
|
|
10862
10886
|
// these will be generated into the `container` and prefixed with the `key` below, ensuring
|
|
10863
10887
|
// the styles are in the popout rather than the root window.
|
|
10864
|
-
|
|
10865
|
-
|
|
10866
|
-
|
|
10888
|
+
// Memoised so the cache (and its deduplication tracking) is stable across re-renders,
|
|
10889
|
+
// and only created once headElement is defined — if container is undefined Emotion falls
|
|
10890
|
+
// back to document.head, causing styles to be orphaned in the root window.
|
|
10891
|
+
const myCache = useMemo(() => (headElement ? createCache({ key: makePopoutId(name), container: headElement }) : null), [headElement, name]);
|
|
10892
|
+
if (!containerElement || !myCache) {
|
|
10893
|
+
return null;
|
|
10894
|
+
}
|
|
10895
|
+
return createPortal(jsx(CacheProvider, { value: myCache, children: children }), containerElement);
|
|
10867
10896
|
};
|
|
10868
10897
|
|
|
10869
10898
|
const defaultInitialSize = { width: 320, height: 200 };
|