@andersundsehr/storybook-typo3 0.1.16 → 0.1.17
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/README.md +9 -7
- package/dist/functions/fetchRenderAction.js +17 -1
- package/dist/preset.d.ts +1 -1
- package/dist/preset.js +40 -6
- package/package.json +1 -1
package/README.md
CHANGED
@@ -73,21 +73,23 @@ const config: StorybookConfig = {
|
|
73
73
|
framework: '@andersundsehr/storybook-typo3', // required
|
74
74
|
|
75
75
|
stories: [
|
76
|
-
"../src
|
77
|
-
'../src/**/*.stories.@(js|jsx|mjs|ts|tsx)',
|
76
|
+
"../src/**/*.@(mdx|stories.@(mdx|js|jsx|mjs|ts|tsx))",
|
78
77
|
],
|
79
78
|
|
80
79
|
core: {
|
81
80
|
disableTelemetry: true,
|
82
81
|
},
|
83
82
|
|
84
|
-
env: (envs) =>
|
85
|
-
|
86
|
-
|
87
|
-
|
83
|
+
env: (envs) => {
|
84
|
+
return {
|
85
|
+
STORYBOOK_TYPO3_ENDPOINT: 'http://localhost/_storybook/',
|
86
|
+
STORYBOOK_TYPO3_WATCH_ONLY_STORIES: '0', // set to '1' If you already use vite in your TYPO3 with HMR
|
87
|
+
// do not set your api key here! https://www.deployhq.com/blog/protecting-your-api-keys-a-quick-guide
|
88
|
+
...envs, // envs given to storybook have precedence
|
89
|
+
};
|
90
|
+
},
|
88
91
|
};
|
89
92
|
export default config;
|
90
|
-
|
91
93
|
```
|
92
94
|
|
93
95
|
## Usage: How to use the extension? (Examples, screenshots, typical use cases)
|
@@ -1,6 +1,22 @@
|
|
1
1
|
import { url } from '@andersundsehr/storybook-typo3';
|
2
2
|
import { fetchWithUserRetry } from './fetchWithUserRetry';
|
3
3
|
import { error } from './error';
|
4
|
+
let iframeContextId = 'sb-iframe-id-' + Math.random().toString(36).substring(2, 15);
|
5
|
+
/**
|
6
|
+
* the IframeContextId is used to cache bust JS and CSS files,
|
7
|
+
* but on docs mode we want the same context ID as all the stories are rendered in the same iframe
|
8
|
+
*/
|
9
|
+
function getIframeContextId(viewMode) {
|
10
|
+
if (viewMode === 'story') {
|
11
|
+
// for story render we always create a new context ID
|
12
|
+
return (iframeContextId = 'sb-iframe-id-' + Math.random().toString(36).substring(2, 15));
|
13
|
+
}
|
14
|
+
// for docs we only want to create a new context ID if we were in story mode before
|
15
|
+
if (iframeContextId.startsWith('sb-iframe-id-')) {
|
16
|
+
return (iframeContextId = 'sb-docs-id-' + Math.random().toString(36).substring(2, 15));
|
17
|
+
}
|
18
|
+
return iframeContextId;
|
19
|
+
}
|
4
20
|
export async function fetchRenderAction(urlA, id, params, storyContext) {
|
5
21
|
if (!storyContext.component) {
|
6
22
|
error('No component found in story context. This function requires a Fluid component to render.', 4123764578913);
|
@@ -11,10 +27,10 @@ export async function fetchRenderAction(urlA, id, params, storyContext) {
|
|
11
27
|
arguments: params,
|
12
28
|
site: storyContext.globals?.site || 'default',
|
13
29
|
siteLanguage: storyContext.globals?.language || 'default',
|
30
|
+
iframeContextId: getIframeContextId(storyContext.viewMode),
|
14
31
|
};
|
15
32
|
return await fetchWithUserRetry(url + '/_storybook/render', {
|
16
33
|
method: 'POST',
|
17
34
|
body: JSON.stringify(body),
|
18
35
|
}, 'rendering component', 'text');
|
19
36
|
}
|
20
|
-
;
|
package/dist/preset.d.ts
CHANGED
@@ -10,7 +10,7 @@ export declare const core: PresetProperty<'core'>;
|
|
10
10
|
export declare const previewAnnotations: PresetProperty<'previewAnnotations'>;
|
11
11
|
export declare const tags: string[];
|
12
12
|
/**
|
13
|
-
* BUGFIX for chromium based browsers
|
13
|
+
* BUGFIX for chromium based browsers on windows
|
14
14
|
* @see https://github.com/talkjs/country-flag-emoji-polyfill?tab=readme-ov-file
|
15
15
|
*/
|
16
16
|
export declare const managerHead = "<style>\n body {\n font-family: \"Twemoji Country Flags\", \"Nunito Sans\", -apple-system, \".SFNSText-Regular\", \"San Francisco\", BlinkMacSystemFont, \"Segoe UI\", \"Helvetica Neue\", Helvetica, Arial, sans-serif !important;\n }\n @font-face {\n font-family: \"Twemoji Country Flags\";\n unicode-range: U+1F1E6-1F1FF, U+1F3F4, U+E0062-E0063, U+E0065, U+E0067, U+E006C, U+E006E, U+E0073-E0074, U+E0077, U+E007F;\n src: url('https://cdn.jsdelivr.net/npm/country-flag-emoji-polyfill@0.1/dist/TwemojiCountryFlags.woff2') format('woff2');\n font-display: swap;\n }\n</style>";
|
package/dist/preset.js
CHANGED
@@ -1,18 +1,52 @@
|
|
1
1
|
import { dirname, join } from 'node:path';
|
2
2
|
import { createRequire } from 'module';
|
3
|
+
import { glob } from 'node:fs/promises';
|
4
|
+
import { basename } from 'node:path';
|
3
5
|
const require = createRequire(import.meta.url);
|
4
6
|
function getAbsolutePath(value) {
|
5
7
|
return dirname(require.resolve(join(value, 'package.json')));
|
6
8
|
}
|
7
|
-
export const addons = [
|
8
|
-
'@storybook/addon-docs',
|
9
|
-
'@storybook/addon-a11y',
|
10
|
-
];
|
9
|
+
export const addons = ['@storybook/addon-docs', '@storybook/addon-a11y'];
|
11
10
|
/**
|
12
11
|
* We want storybook to not use your local vite config.
|
13
12
|
* As that is not really needed, and can cause issues or break storybook.
|
14
13
|
*/
|
15
|
-
export const viteFinal = (config, options) => {
|
14
|
+
export const viteFinal = async (config, options) => {
|
15
|
+
const envs = await options.presets.apply('env');
|
16
|
+
const watchOnlyStoriesActive = ['true', '1'].includes(envs.STORYBOOK_TYPO3_WATCH_ONLY_STORIES);
|
17
|
+
if (!watchOnlyStoriesActive) {
|
18
|
+
return config; // do not change anything if we are not in watch only mode
|
19
|
+
}
|
20
|
+
const colorYellow = '\x1b[33m';
|
21
|
+
const colorReset = '\x1b[0m';
|
22
|
+
console.log(colorYellow + '@andersundsehr/storybook-typo3:' + colorReset + ' STORYBOOK_TYPO3_WATCH_ONLY_STORIES enabled, only watching stories files');
|
23
|
+
const defaultGlobPattern = '/**/*.@(mdx|stories.@(mdx|js|jsx|mjs|ts|tsx))';
|
24
|
+
const storiesGlob = await options.presets.apply('stories');
|
25
|
+
const storiesFiles = [];
|
26
|
+
for (let globs of storiesGlob) {
|
27
|
+
if (typeof globs !== 'string') {
|
28
|
+
globs = globs.directory + (globs.files || defaultGlobPattern);
|
29
|
+
}
|
30
|
+
for await (const entry of glob(globs)) {
|
31
|
+
storiesFiles.push(entry);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
const alwaysWatch = ['.env'];
|
35
|
+
config.server = config.server || {};
|
36
|
+
config.server.watch = config.server.watch || {};
|
37
|
+
config.server.watch.ignored = (file) => {
|
38
|
+
const filename = basename(file);
|
39
|
+
if (alwaysWatch.includes(filename)) {
|
40
|
+
return false; // always watch these files
|
41
|
+
}
|
42
|
+
if (!filename.includes('.')) {
|
43
|
+
return false; // ignore directories
|
44
|
+
}
|
45
|
+
if (!storiesFiles.includes(file)) {
|
46
|
+
return true;
|
47
|
+
}
|
48
|
+
return false;
|
49
|
+
};
|
16
50
|
return config;
|
17
51
|
};
|
18
52
|
export const core = {
|
@@ -28,7 +62,7 @@ export const previewAnnotations = async (entry = [], options) => {
|
|
28
62
|
};
|
29
63
|
export const tags = ['autodocs'];
|
30
64
|
/**
|
31
|
-
* BUGFIX for chromium based browsers
|
65
|
+
* BUGFIX for chromium based browsers on windows
|
32
66
|
* @see https://github.com/talkjs/country-flag-emoji-polyfill?tab=readme-ov-file
|
33
67
|
*/
|
34
68
|
export const managerHead = `<style>
|
package/package.json
CHANGED