@andersundsehr/storybook-typo3 0.1.16 → 0.1.18

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 CHANGED
@@ -73,21 +73,23 @@ const config: StorybookConfig = {
73
73
  framework: '@andersundsehr/storybook-typo3', // required
74
74
 
75
75
  stories: [
76
- "../src/**/*.mdx",
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
- STORYBOOK_TYPO3_ENDPOINT: 'http://localhost/_storybook/', // env can be set here or in the .env file
86
- ...envs, // envs given to storybook have precedence
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
- ;
@@ -0,0 +1,3 @@
1
+ import { InlineConfig } from 'vite';
2
+ import type { Options } from 'storybook/internal/types';
3
+ export declare function viteFinal(config: InlineConfig, options: Options): Promise<InlineConfig>;
@@ -0,0 +1,55 @@
1
+ import { glob } from 'node:fs/promises';
2
+ import { basename } from 'node:path';
3
+ async function isFeatureEnabled(name, options) {
4
+ const envs = await options.presets.apply('env');
5
+ return ['true', '1'].includes(envs[name] || process.env[name] || '0');
6
+ }
7
+ export async function viteFinal(config, options) {
8
+ if (await isFeatureEnabled('STORYBOOK_TYPO3_WATCH_ONLY_STORIES', options)) {
9
+ config = await watchOnlyStoriesConfig(config, options);
10
+ }
11
+ config = addAllowedHosts(config);
12
+ return config;
13
+ }
14
+ async function watchOnlyStoriesConfig(config, options) {
15
+ const colorYellow = '\x1b[33m';
16
+ const colorReset = '\x1b[0m';
17
+ console.log(colorYellow + '@andersundsehr/storybook-typo3:' + colorReset + ' STORYBOOK_TYPO3_WATCH_ONLY_STORIES enabled, only watching stories files');
18
+ const defaultGlobPattern = '/**/*.@(mdx|stories.@(mdx|js|jsx|mjs|ts|tsx))';
19
+ const storiesGlob = await options.presets.apply('stories');
20
+ const storiesFiles = [];
21
+ for (let globs of storiesGlob) {
22
+ if (typeof globs !== 'string') {
23
+ globs = globs.directory + (globs.files || defaultGlobPattern);
24
+ }
25
+ for await (const entry of glob(globs)) {
26
+ storiesFiles.push(entry);
27
+ }
28
+ }
29
+ const alwaysWatch = ['.env'];
30
+ config.server = config.server || {};
31
+ config.server.watch = config.server.watch || {};
32
+ config.server.watch.ignored = (file) => {
33
+ const filename = basename(file);
34
+ if (alwaysWatch.includes(filename)) {
35
+ return false; // always watch these files
36
+ }
37
+ if (!filename.includes('.')) {
38
+ return false; // ignore directories
39
+ }
40
+ if (!storiesFiles.includes(file)) {
41
+ return true;
42
+ }
43
+ return false;
44
+ };
45
+ return config;
46
+ }
47
+ function addAllowedHosts(config) {
48
+ var _a;
49
+ config.server = config.server || {};
50
+ if (process.env.IS_DDEV_PROJECT && config.server.allowedHosts !== true) {
51
+ (_a = config.server).allowedHosts ?? (_a.allowedHosts = []);
52
+ config.server.allowedHosts.push('.ddev.site');
53
+ }
54
+ return config;
55
+ }
package/dist/preset.d.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  import type { PresetProperty } from 'storybook/internal/types';
2
- import type { ViteFinal } from '@storybook/builder-vite';
2
+ import { viteFinal } from './functions/viteFinal.ts';
3
3
  export declare const addons: string[];
4
4
  /**
5
5
  * We want storybook to not use your local vite config.
6
6
  * As that is not really needed, and can cause issues or break storybook.
7
7
  */
8
- export declare const viteFinal: ViteFinal;
8
+ export { viteFinal };
9
9
  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 and windows
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,20 +1,16 @@
1
1
  import { dirname, join } from 'node:path';
2
2
  import { createRequire } from 'module';
3
+ import { viteFinal } from "./functions/viteFinal.js";
3
4
  const require = createRequire(import.meta.url);
4
5
  function getAbsolutePath(value) {
5
6
  return dirname(require.resolve(join(value, 'package.json')));
6
7
  }
7
- export const addons = [
8
- '@storybook/addon-docs',
9
- '@storybook/addon-a11y',
10
- ];
8
+ export const addons = ['@storybook/addon-docs', '@storybook/addon-a11y'];
11
9
  /**
12
10
  * We want storybook to not use your local vite config.
13
11
  * As that is not really needed, and can cause issues or break storybook.
14
12
  */
15
- export const viteFinal = (config, options) => {
16
- return config;
17
- };
13
+ export { viteFinal };
18
14
  export const core = {
19
15
  builder: getAbsolutePath('@storybook/builder-vite'),
20
16
  renderer: getAbsolutePath('@storybook/server'),
@@ -28,7 +24,7 @@ export const previewAnnotations = async (entry = [], options) => {
28
24
  };
29
25
  export const tags = ['autodocs'];
30
26
  /**
31
- * BUGFIX for chromium based browsers and windows
27
+ * BUGFIX for chromium based browsers on windows
32
28
  * @see https://github.com/talkjs/country-flag-emoji-polyfill?tab=readme-ov-file
33
29
  */
34
30
  export const managerHead = `<style>
package/package.json CHANGED
@@ -49,5 +49,5 @@
49
49
  "dist",
50
50
  "README.md"
51
51
  ],
52
- "version": "0.1.16"
52
+ "version": "0.1.18"
53
53
  }