Skip to content

Commit 1be4c67

Browse files
committed
object-auto-expand
1 parent 1795b54 commit 1be4c67

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

config/main.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
14
module.exports = {
25
stories: [
36
"../src/stories/**/*.stories.mdx",
@@ -7,4 +10,26 @@ module.exports = {
710
"@storybook/addon-links",
811
"@storybook/addon-essentials"
912
],
13+
webpackFinal: async (config) => {
14+
config.module.rules.push({
15+
test: require.resolve('jquery'),
16+
use: [{
17+
loader: 'expose-loader',
18+
options: '$'
19+
}]
20+
});
21+
config.plugins.push({
22+
apply: (compiler) => {
23+
compiler.hooks.afterEmit.tap('AfterEmitPlugin', () => {
24+
const from = path.resolve(__dirname, '../template/object-auto-expand.js');
25+
const to = path.resolve(__dirname, '../dist/index.html');
26+
console.log();
27+
console.log('patching', from, to);
28+
fs.appendFileSync(to, `<script>${fs.readFileSync(from)}</script>`);
29+
console.log('done')
30+
});
31+
}
32+
});
33+
return config;
34+
},
1035
};

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"dependencies": {
1616
"@emotion/css": "^11.7.1",
1717
"@mui/material": "^5.2.8",
18+
"expose-loader": "^3.1.0",
19+
"jquery": "^3.6.0",
1820
"react": "^17.0.1",
1921
"react-declarative": "^1.6.6",
2022
"react-dom": "^17.0.1"

template/object-auto-expand.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(function() {
2+
3+
const rnd = () => (Math.random() + 1).toString(36).substring(7);
4+
5+
const main = () => {
6+
const EXPANDED_CLASS = `preview-head-expanded-${rnd()}`;
7+
debugger
8+
const observer = new MutationObserver(() => {
9+
const expandButtons = [...document.querySelectorAll('button[type=button] > span')]
10+
.filter((el) => el.innerHTML === 'RAW')
11+
.map((el) => el.closest('button'));
12+
for (const button of expandButtons) {
13+
if (!button.classList.contains(EXPANDED_CLASS)) {
14+
button.classList.add(EXPANDED_CLASS);
15+
button.click();
16+
}
17+
}
18+
});
19+
observer.observe(document.body, {
20+
childList: true,
21+
subtree: true,
22+
});
23+
};
24+
25+
document.addEventListener('DOMContentLoaded', main);
26+
})();

0 commit comments

Comments
 (0)