-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move theme styles below other styles (#23)
- Loading branch information
1 parent
fa1b759
commit c80aad5
Showing
10 changed files
with
169 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body { | ||
background: white; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 30 additions & 19 deletions
49
packages/gatsby-plugin-eufemia-theme-handler/src/inlineScriptDev.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,34 @@ | ||
if (typeof window !== 'undefined') { | ||
try { | ||
const headElement = document.querySelector('html head') | ||
const logMutations = (mutations) => { | ||
for (const mutation of mutations) { | ||
const element = mutation.nextSibling | ||
if ( | ||
element && | ||
(element.src || element.href || '').includes('/commons.') | ||
) { | ||
const themeName = globalThis.__getEufemiaThemeName() | ||
globalThis.__updateEufemiaThemeFile(themeName, true) | ||
break | ||
} | ||
if (!window.__hasEufemiaObserver) { | ||
window.__hasEufemiaObserver = true | ||
onElementInsertion('[href="/commons.css"]', () => { | ||
const themeName = globalThis.__getEufemiaThemeName() | ||
globalThis.__updateEufemiaThemeFile(themeName, true) | ||
}) | ||
} | ||
} | ||
|
||
function onElementInsertion(targetSelector, callback) { | ||
const headElement = document.head | ||
|
||
const observer = new MutationObserver((mutations) => { | ||
mutations.forEach((mutation) => { | ||
const addedNodes = Array.from(mutation.addedNodes) | ||
|
||
const targetElementAdded = addedNodes.find((node) => { | ||
return ( | ||
node.nodeType === Node.ELEMENT_NODE && | ||
node.matches(targetSelector) | ||
) | ||
}) | ||
|
||
if (targetElementAdded) { | ||
callback(targetElementAdded, observer) | ||
} | ||
} | ||
}) | ||
}) | ||
|
||
const observer = new MutationObserver(logMutations) | ||
observer.observe(headElement, { childList: true }) | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
observer.observe(headElement, { | ||
childList: true, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters