@storybook/angular-vite 11.0.0-rc.3 → 11.0.0-rc.4

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.
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  config_exports
3
- } from "./chunk-IFJFIE3P.js";
3
+ } from "./chunk-SPIIFZLB.js";
4
4
  import {
5
5
  config_exports as config_exports2
6
- } from "./chunk-S752VTMD.js";
6
+ } from "./chunk-7TI2NQDW.js";
7
7
  import {
8
8
  computesTemplateFromComponent,
9
9
  formatPropInTemplate,
10
10
  isComponent,
11
11
  render_exports
12
- } from "./chunk-6VSOLSRX.js";
12
+ } from "./chunk-V7SLOYXF.js";
13
13
 
14
14
  // src/client/portable-stories.ts
15
15
  import {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  computesTemplateSourceFromComponent
3
- } from "./chunk-6VSOLSRX.js";
3
+ } from "./chunk-V7SLOYXF.js";
4
4
  import {
5
5
  __export
6
6
  } from "./chunk-T4WQC6BZ.js";
@@ -2,7 +2,7 @@ import {
2
2
  computesTemplateFromComponent,
3
3
  render,
4
4
  renderToCanvas
5
- } from "./chunk-6VSOLSRX.js";
5
+ } from "./chunk-V7SLOYXF.js";
6
6
  import {
7
7
  __export
8
8
  } from "./chunk-T4WQC6BZ.js";
@@ -22,6 +22,11 @@ import { BehaviorSubject } from "rxjs";
22
22
  import { stringify } from "telejson";
23
23
 
24
24
  // src/template-grammar.ts
25
+ import {
26
+ SNIPPET_INDENT,
27
+ SNIPPET_PRINT_WIDTH,
28
+ printOpeningTag
29
+ } from "storybook/internal/docs-tools/snippets";
25
30
  var formatPropInTemplate = (propertyName) => isValidIdentifier(propertyName) ? propertyName : `this['${propertyName}']`, stringifyCircular = (obj) => {
26
31
  let seen = /* @__PURE__ */ new Set();
27
32
  return JSON.stringify(obj, (key, value) => {
@@ -60,26 +65,23 @@ var formatPropInTemplate = (propertyName) => isValidIdentifier(propertyName) ? p
60
65
  "source",
61
66
  "track",
62
67
  "wbr"
63
- ]), LEADING_CLASS = /^\..+/, LEADING_ATTRIBUTE = /^\[.+?]/, ID = /#([\w-]+)/, CLASS_RUN = /(\.[\w-]+)+/, ATTRIBUTE = /\[(.+?)]/g, ELEMENT_AND_ATTRIBUTES = /(\S+)(.*)/, MAX_SINGLE_LINE = 80, asWritten = (code) => code, buildTemplate = (selector, { inputs, outputs, innerTemplate = "", selfClosing = !1 }, unmarked = asWritten) => {
68
+ ]), LEADING_CLASS = /^\..+/, LEADING_ATTRIBUTE = /^\[.+?]/, ID = /#([\w-]+)/, CLASS_RUN = /(\.[\w-]+)+/, ATTRIBUTE = /\[(.+?)]/g, ELEMENT_AND_ATTRIBUTES = /(\S+)(.*)/, asWritten = (code) => code, buildTemplate = (selector, { inputs, outputs, innerTemplate = "", selfClosing = !1 }, unmarked = asWritten) => {
64
69
  let bindings = [
65
70
  ...inputs.map(({ name, expression, attribute }) => attribute ?? inputBinding(name, expression)),
66
71
  ...outputs.map((name) => `(${name})="${formatPropInTemplate(name)}($event)"`)
67
72
  ], firstSelector = selector.split(",")[0];
68
73
  return (LEADING_CLASS.test(firstSelector) || LEADING_ATTRIBUTE.test(firstSelector) ? `div${firstSelector}` : firstSelector).replace(ID, ' id="$1"').replace(CLASS_RUN, (classes) => ` class="${classes.split(".").join(" ").trim()}"`).replace(ATTRIBUTE, " $1").replace(ELEMENT_AND_ATTRIBUTES, (_, element, attributes) => {
69
- let closesItself = VOID_ELEMENTS.has(element) || selfClosing && element.includes("-") && innerTemplate === "", inlineTag = `<${element}${attributes}${bindings.map((binding) => ` ${binding}`).join("")}`, inline = closesItself ? `${inlineTag} />` : `${inlineTag}>${innerTemplate}</${element}>`;
70
- if (unmarked(inline).length <= MAX_SINGLE_LINE || bindings.every((binding) => unmarked(binding) === ""))
71
- return inline;
72
- let brokenTag = `<${element}${attributes}
73
- ${bindings.map((binding) => ` ${binding}`).join(`
74
- `)}`;
75
- if (closesItself)
76
- return selfClosing ? `${brokenTag}
77
- />` : `${brokenTag} />`;
74
+ let closesItself = VOID_ELEMENTS.has(element) || selfClosing && element.includes("-") && innerTemplate === "", closing = closesItself ? "" : `${innerTemplate}</${element}>`, { text, broken } = printOpeningTag(
75
+ { open: `<${element}${attributes}`, attributes: bindings, close: closesItself ? "/>" : ">" },
76
+ { after: closing, measure: unmarked }
77
+ );
78
+ if (!broken || closesItself)
79
+ return `${text}${closing}`;
78
80
  let content = innerTemplate === "" ? `
79
81
  ` : `
80
82
  ${innerTemplate}
81
83
  `;
82
- return `${brokenTag}>${content}</${element}>`;
84
+ return `${text}${content}</${element}>`;
83
85
  });
84
86
  }, buildComponentOutletTemplate = (componentName, { selfClosing = !1 } = {}) => selfClosing ? `<ng-container *ngComponentOutlet="${componentName}" />` : `<ng-container *ngComponentOutlet="${componentName}"></ng-container>`;
85
87
 
@@ -2,11 +2,11 @@ import {
2
2
  argTypesEnhancers,
3
3
  decorateStory,
4
4
  parameters
5
- } from "../_browser-chunks/chunk-IFJFIE3P.js";
5
+ } from "../_browser-chunks/chunk-SPIIFZLB.js";
6
6
  import {
7
7
  render,
8
8
  renderToCanvas
9
- } from "../_browser-chunks/chunk-6VSOLSRX.js";
9
+ } from "../_browser-chunks/chunk-V7SLOYXF.js";
10
10
  import "../_browser-chunks/chunk-T4WQC6BZ.js";
11
11
  export {
12
12
  decorateStory as applyDecorators,
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  decorators,
3
3
  parameters
4
- } from "../../_browser-chunks/chunk-S752VTMD.js";
4
+ } from "../../_browser-chunks/chunk-7TI2NQDW.js";
5
5
  import "../../_browser-chunks/chunk-YS33I6LM.js";
6
- import "../../_browser-chunks/chunk-6VSOLSRX.js";
6
+ import "../../_browser-chunks/chunk-V7SLOYXF.js";
7
7
  import "../../_browser-chunks/chunk-T4WQC6BZ.js";
8
8
  export {
9
9
  decorators,
@@ -5,11 +5,11 @@ import {
5
5
  componentWrapperDecorator,
6
6
  moduleMetadata,
7
7
  setProjectAnnotations
8
- } from "../_browser-chunks/chunk-Y5SREGLY.js";
9
- import "../_browser-chunks/chunk-IFJFIE3P.js";
10
- import "../_browser-chunks/chunk-S752VTMD.js";
8
+ } from "../_browser-chunks/chunk-2AD3AFBS.js";
9
+ import "../_browser-chunks/chunk-SPIIFZLB.js";
10
+ import "../_browser-chunks/chunk-7TI2NQDW.js";
11
11
  import "../_browser-chunks/chunk-YS33I6LM.js";
12
- import "../_browser-chunks/chunk-6VSOLSRX.js";
12
+ import "../_browser-chunks/chunk-V7SLOYXF.js";
13
13
  import "../_browser-chunks/chunk-T4WQC6BZ.js";
14
14
  export {
15
15
  __definePreview,
@@ -25,9 +25,6 @@ import { statSync as statSync2 } from "node:fs";
25
25
  import { logger } from "storybook/internal/node-logger";
26
26
  import { slash } from "storybook/internal/common";
27
27
  import { isInNodeModules as isInNodeModules2 } from "storybook/internal/common";
28
- import {
29
- extractComponentJsDocInfo
30
- } from "storybook/internal/component-meta";
31
28
  import { logger as logger5 } from "storybook/internal/node-logger";
32
29
  import { logger as logger4 } from "storybook/internal/node-logger";
33
30
  import { logger as logger2 } from "storybook/internal/node-logger";
@@ -2273,11 +2270,7 @@ function analyzeSourceFile(ts, sourceFile, checker, context = analyzerContext(ts
2273
2270
  );
2274
2271
  continue;
2275
2272
  }
2276
- let name = statement.name.text, file = sourceFile.fileName, members = collectClassMembers(ctx, statement, kind), common = {
2277
- file,
2278
- ...getJsDocDescription(ts, statement),
2279
- ...getJsDocTagsField(ts, statement)
2280
- };
2273
+ let name = statement.name.text, file = sourceFile.fileName, members = collectClassMembers(ctx, statement, kind), common = { file };
2281
2274
  if (kind === "component" || kind === "directive") {
2282
2275
  let { selector, standalone } = componentMetadata(ctx, statement, kind), record = {
2283
2276
  name,
@@ -2378,16 +2371,7 @@ var KNOWN_DECORATORS = {
2378
2371
  function extractComponent(typescript, checker, sourceFile, names, debug) {
2379
2372
  let context = analyzerContext(typescript, sourceFile, checker), fileMeta = analyzeSourceFile(typescript, sourceFile, checker, context), entry = pickEntry(typescript, fileMeta, sourceFile, names);
2380
2373
  if (entry)
2381
- return debug(`${describe(entry)} from ${sourceFile.fileName}`), {
2382
- entry,
2383
- json: fileMeta,
2384
- context,
2385
- ...jsDocInfoField(
2386
- typescript,
2387
- checker,
2388
- findClassDeclaration(typescript, sourceFile, entry.name)
2389
- )
2390
- };
2374
+ return debug(`${describe(entry)} from ${sourceFile.fileName}`), { entry, json: fileMeta, context };
2391
2375
  let viaExports = extractViaModuleExports(
2392
2376
  typescript,
2393
2377
  checker,
@@ -2443,12 +2427,7 @@ var importClosure = (typescript, checker, entry) => {
2443
2427
  continue;
2444
2428
  let declarationFile = declaration.getSourceFile(), targetContext = declarationFile === sourceFile ? context : analyzerContext(typescript, declarationFile, checker), targetMeta = declarationFile === sourceFile ? fileMeta : analyzeSourceFile(typescript, declarationFile, checker, targetContext), entry = findRecord(targetMeta, declaration.name.text);
2445
2429
  if (entry)
2446
- return {
2447
- entry,
2448
- json: targetMeta,
2449
- context: targetContext,
2450
- ...jsDocInfoField(typescript, checker, declaration)
2451
- };
2430
+ return { entry, json: targetMeta, context: targetContext };
2452
2431
  }
2453
2432
  }, allRecords = (fileMeta) => [
2454
2433
  ...fileMeta.components,
@@ -2460,15 +2439,6 @@ var importClosure = (typescript, checker, entry) => {
2460
2439
  let counts = "inputsClass" in entry ? `${entry.inputsClass?.length ?? 0} input(s), ${entry.outputsClass?.length ?? 0} output(s), ${"propertiesClass" in entry ? entry.propertiesClass?.length ?? 0 : 0} propertie(s)` : `${entry.properties.length} propertie(s), ${entry.methods.length} method(s)`;
2461
2440
  return `extracted ${entry.type} ${entry.name} with ${counts}`;
2462
2441
  }, findRecord = (fileMeta, name) => name ? allRecords(fileMeta).find((record) => record.name === name) : void 0;
2463
- function findClassDeclaration(typescript, sourceFile, name) {
2464
- return sourceFile.statements.find(
2465
- (statement) => typescript.isClassDeclaration(statement) && statement.name?.text === name
2466
- );
2467
- }
2468
- function jsDocInfoField(typescript, checker, declaration) {
2469
- let symbol = declaration?.name && checker.getSymbolAtLocation(declaration.name);
2470
- return symbol ? { jsDocInfo: extractComponentJsDocInfo(typescript, checker, symbol) } : {};
2471
- }
2472
2442
  function findDefaultExportedClassName(typescript, sourceFile) {
2473
2443
  for (let statement of sourceFile.statements) {
2474
2444
  if (typescript.isClassDeclaration(statement) && statement.name && statement.modifiers?.some(
@@ -2746,7 +2716,8 @@ import { logger as logger6 } from "storybook/internal/node-logger";
2746
2716
  import {
2747
2717
  componentPathFromStory,
2748
2718
  getComponentIdFromEntry,
2749
- getStoryImportPathFromEntry
2719
+ getStoryImportPathFromEntry,
2720
+ readDeclarationDocs
2750
2721
  } from "storybook/internal/common";
2751
2722
  import { resolve } from "node:path";
2752
2723
 
@@ -2813,17 +2784,7 @@ function buildApiDescription(argTypes, componentName) {
2813
2784
  }
2814
2785
 
2815
2786
  // src/docgen/build-docgen.ts
2816
- var inputsOf = (entry) => "inputsClass" in entry ? entry.inputsClass ?? [] : [], outputsOf = (entry) => "outputsClass" in entry ? entry.outputsClass ?? [] : [], describedBy = (text) => text?.trim() || void 0, analyzerJsDocTags = (entry) => {
2817
- let tags = {};
2818
- for (let tag of entry.jsdoctags ?? []) {
2819
- let name = tag.tagName?.escapedText;
2820
- if (!name)
2821
- continue;
2822
- let value = tag.comment === void 0 ? "" : String(tag.comment).trim();
2823
- (tags[name] ??= []).push(value);
2824
- }
2825
- return tags;
2826
- }, metaToSnippetMeta = (meta) => {
2787
+ var inputsOf = (entry) => "inputsClass" in entry ? entry.inputsClass ?? [] : [], outputsOf = (entry) => "outputsClass" in entry ? entry.outputsClass ?? [] : [], describedBy = (text) => text?.trim() || void 0, metaToSnippetMeta = (meta) => {
2827
2788
  let { entry } = meta, inputs = inputsOf(entry).map((input) => input.name), inputNames = new Set(inputs), outputs = [];
2828
2789
  for (let output of outputsOf(entry)) {
2829
2790
  let bindingName2 = inputNames.has(output.name) ? `${output.name}Change` : output.name;
@@ -2866,6 +2827,15 @@ Check the name against the module's exports, and any barrel that re-exports it.`
2866
2827
  throw new Error(`Unhandled resolution ${JSON.stringify(unhandled)}`);
2867
2828
  }
2868
2829
  }
2830
+ }, displayNameOf = (component) => component.exportName === "default" ? component.localName : component.exportName, readClassDocs = (component) => {
2831
+ let docs = readDeclarationDocs(component);
2832
+ return {
2833
+ // The declaration has the class name even when the story file imported it as a default export.
2834
+ name: docs?.name ?? displayNameOf(component),
2835
+ description: describedBy(docs?.description) ?? describedBy(docs?.tags.description?.[0]),
2836
+ summary: docs?.tags.summary?.[0],
2837
+ jsDocTags: docs?.tags ?? {}
2838
+ };
2869
2839
  }, extractClassDocgen = (component, displayName, reference, story, { manager, options, logger: logger8 }) => {
2870
2840
  let pathLikeStory = (file) => componentPathFromStory(story.importPath, story.filePath, file);
2871
2841
  if (!component.path)
@@ -2906,24 +2876,19 @@ Check that the file exports the component class and is covered by a tsconfig.jso
2906
2876
  propsTable: "api",
2907
2877
  logger: logger8,
2908
2878
  context: meta.context
2909
- }), jsDocTags = meta.jsDocInfo?.jsDocTags ?? analyzerJsDocTags(meta.entry), description = describedBy(meta.jsDocInfo?.description) ?? describedBy(meta.entry.rawdescription) ?? describedBy(meta.entry.description);
2879
+ });
2910
2880
  return {
2911
- // The analyzer knows the class name even when the story file imported it as a default export.
2912
- name: meta.entry.name,
2913
- description,
2914
- summary: jsDocTags.summary?.[0],
2915
- jsDocTags,
2916
2881
  argTypes,
2917
2882
  apiDescription: buildApiDescription(apiArgTypes, meta.entry.name),
2918
2883
  angularComponentMeta: metaToSnippetMeta(meta)
2919
2884
  };
2920
- }, displayNameOf = (component) => component.exportName === "default" ? component.localName : component.exportName, buildSubcomponentDocgen = ({ name, resolution }, story, context) => {
2885
+ }, nameOfUnresolved = (resolution, title) => resolution.reason === "unreadable-component-expression" ? resolution.expression : title.split("/").at(-1) ?? title, buildSubcomponentDocgen = ({ name, resolution }, story, context) => {
2921
2886
  let reference = `subcomponents.${name}`;
2922
2887
  if ("reason" in resolution) {
2923
2888
  let { error } = unresolvedError(resolution, reference, story.importPath);
2924
2889
  return { name, path: story.importPath, jsDocTags: {}, error };
2925
2890
  }
2926
- let docgen = extractClassDocgen(
2891
+ let docs = readClassDocs(resolution.component), docgen = extractClassDocgen(
2927
2892
  resolution.component,
2928
2893
  displayNameOf(resolution.component),
2929
2894
  reference,
@@ -2931,40 +2896,66 @@ Check that the file exports the component class and is covered by a tsconfig.jso
2931
2896
  context
2932
2897
  );
2933
2898
  if ("error" in docgen)
2934
- return { name, path: story.importPath, jsDocTags: {}, error: docgen.error };
2935
- let { angularComponentMeta: _, ...entry } = docgen, { path: path2 } = resolution.component;
2899
+ return { ...docs, name, path: story.importPath, error: docgen.error };
2900
+ let { angularComponentMeta: _, ...props } = docgen, { path: path2 } = resolution.component;
2936
2901
  return {
2937
- ...entry,
2902
+ ...docs,
2903
+ ...props,
2938
2904
  path: path2 ? componentPathFromStory(story.importPath, story.filePath, path2) : story.importPath,
2939
2905
  renderer: "angular"
2940
2906
  };
2941
- }, buildDocgenPayload = (input, context) => {
2907
+ }, describeStoryComponent = (input, context) => {
2942
2908
  let storyImportPath = getStoryImportPathFromEntry(input.entry);
2943
2909
  if (!storyImportPath)
2944
2910
  return;
2945
2911
  let storyFilePath = (context.resolvePath ?? ((importPath) => resolve(process.cwd(), importPath)))(storyImportPath), { component: resolved, subcomponents } = resolveStoryComponents(
2946
2912
  storyFilePath,
2947
2913
  input.entry.title
2948
- ), id = getComponentIdFromEntry(input.entry);
2914
+ ), id = getComponentIdFromEntry(input.entry), story = { importPath: storyImportPath, filePath: storyFilePath };
2949
2915
  if ("reason" in resolved) {
2950
2916
  if (resolved.reason === "no-meta-component") {
2951
- context.logger.debug(
2917
+ context.logger?.debug(
2952
2918
  `No Angular component resolved from ${storyFilePath}: ${resolved.reason}.`
2953
2919
  );
2954
2920
  return;
2955
2921
  }
2956
- let { error } = unresolvedError(resolved, "component", storyImportPath);
2957
2922
  return {
2958
- id,
2959
- name: resolved.reason === "unreadable-component-expression" ? resolved.expression : input.entry.title.split("/").at(-1) ?? input.entry.title,
2960
- path: storyImportPath,
2961
- jsDocTags: {},
2962
- error
2923
+ docs: {
2924
+ id,
2925
+ name: nameOfUnresolved(resolved, input.entry.title),
2926
+ path: storyImportPath,
2927
+ jsDocTags: {}
2928
+ },
2929
+ story,
2930
+ ...unresolvedError(resolved, "component", storyImportPath)
2963
2931
  };
2964
2932
  }
2965
- let story = { importPath: storyImportPath, filePath: storyFilePath }, base = { id, name: displayNameOf(resolved.component), path: storyImportPath }, docgen = extractClassDocgen(resolved.component, base.name, "component", story, context);
2933
+ return {
2934
+ docs: { id, path: storyImportPath, ...readClassDocs(resolved.component) },
2935
+ story,
2936
+ component: resolved.component,
2937
+ subcomponents
2938
+ };
2939
+ }, buildBasicDocgen = (input, context = {}) => {
2940
+ let described = describeStoryComponent(input, context);
2941
+ if (described)
2942
+ return "error" in described ? { ...described.docs, error: described.error } : described.docs;
2943
+ }, buildDocgenPayload = (input, context) => {
2944
+ let described = describeStoryComponent(input, context);
2945
+ if (!described)
2946
+ return;
2947
+ let { docs, story } = described;
2948
+ if ("error" in described)
2949
+ return { ...docs, error: described.error };
2950
+ let { component, subcomponents } = described, docgen = extractClassDocgen(
2951
+ component,
2952
+ displayNameOf(component),
2953
+ "component",
2954
+ story,
2955
+ context
2956
+ );
2966
2957
  if ("error" in docgen)
2967
- return { ...base, jsDocTags: {}, error: docgen.error };
2958
+ return { ...docs, error: docgen.error };
2968
2959
  let subcomponentEntries = Object.fromEntries(
2969
2960
  subcomponents.map((subcomponent) => [
2970
2961
  subcomponent.name,
@@ -2972,7 +2963,7 @@ Check that the file exports the component class and is covered by a tsconfig.jso
2972
2963
  ])
2973
2964
  );
2974
2965
  return {
2975
- ...base,
2966
+ ...docs,
2976
2967
  ...docgen,
2977
2968
  renderer: "angular",
2978
2969
  ...subcomponents.length > 0 ? { subcomponents: subcomponentEntries } : {}
@@ -2996,16 +2987,19 @@ var workerLogger = {
2996
2987
  return;
2997
2988
  }
2998
2989
  }, createDocgenProvider = (options) => {
2999
- let managerPromise;
2990
+ let managerPromise, extractFull = async (input) => {
2991
+ let manager = await (managerPromise ??= createManager(options.typeScriptSpecifier));
2992
+ if (!manager)
2993
+ return;
2994
+ let ours = buildDocgenPayload(input, { manager, options, logger: workerLogger });
2995
+ return manager.recycleIfHeapPressured(), ours;
2996
+ };
3000
2997
  return (nextDocgen) => async (input) => {
3001
2998
  let storyImportPath = getStoryImportPathFromEntry2(input.entry);
3002
2999
  if (!storyImportPath || !STORY_FILE_TEST_REGEXP.test(storyImportPath))
3003
3000
  return nextDocgen(input);
3004
- let manager = await (managerPromise ??= createManager(options.typeScriptSpecifier));
3005
- if (!manager)
3006
- return nextDocgen(input);
3007
- let ours = buildDocgenPayload(input, { manager, options, logger: workerLogger });
3008
- return manager.recycleIfHeapPressured(), ours ? ours.error ? await nextDocgen(input) ?? ours : { ...await nextDocgen(input), ...ours } : nextDocgen(input);
3001
+ let ours = input.detail === "basic" ? buildBasicDocgen(input, { logger: workerLogger }) : await extractFull(input);
3002
+ return ours ? ours.error ? await nextDocgen(input) ?? ours : { ...await nextDocgen(input), ...ours } : nextDocgen(input);
3009
3003
  };
3010
3004
  };
3011
3005
  export {
package/dist/index.js CHANGED
@@ -5,11 +5,11 @@ import {
5
5
  componentWrapperDecorator,
6
6
  moduleMetadata,
7
7
  setProjectAnnotations
8
- } from "./_browser-chunks/chunk-Y5SREGLY.js";
9
- import "./_browser-chunks/chunk-IFJFIE3P.js";
10
- import "./_browser-chunks/chunk-S752VTMD.js";
8
+ } from "./_browser-chunks/chunk-2AD3AFBS.js";
9
+ import "./_browser-chunks/chunk-SPIIFZLB.js";
10
+ import "./_browser-chunks/chunk-7TI2NQDW.js";
11
11
  import "./_browser-chunks/chunk-YS33I6LM.js";
12
- import "./_browser-chunks/chunk-6VSOLSRX.js";
12
+ import "./_browser-chunks/chunk-V7SLOYXF.js";
13
13
  import "./_browser-chunks/chunk-T4WQC6BZ.js";
14
14
  export {
15
15
  __definePreview,
package/dist/preset.js CHANGED
@@ -442,6 +442,11 @@ import {
442
442
  } from "storybook/internal/csf-tools";
443
443
 
444
444
  // src/template-grammar.ts
445
+ import {
446
+ SNIPPET_INDENT,
447
+ SNIPPET_PRINT_WIDTH,
448
+ printOpeningTag
449
+ } from "storybook/internal/docs-tools/snippets";
445
450
  var formatPropInTemplate = (propertyName) => isValidIdentifier(propertyName) ? propertyName : `this['${propertyName}']`;
446
451
  var VOID_ELEMENTS = /* @__PURE__ */ new Set([
447
452
  "area",
@@ -460,28 +465,25 @@ var VOID_ELEMENTS = /* @__PURE__ */ new Set([
460
465
  "source",
461
466
  "track",
462
467
  "wbr"
463
- ]), LEADING_CLASS = /^\..+/, LEADING_ATTRIBUTE = /^\[.+?]/, ID = /#([\w-]+)/, CLASS_RUN = /(\.[\w-]+)+/, ATTRIBUTE = /\[(.+?)]/g, ELEMENT_AND_ATTRIBUTES = /(\S+)(.*)/, MAX_SINGLE_LINE = 80, asWritten = (code) => code, buildTemplate = (selector, { inputs, outputs, innerTemplate = "", selfClosing = !1 }, unmarked = asWritten) => {
468
+ ]), LEADING_CLASS = /^\..+/, LEADING_ATTRIBUTE = /^\[.+?]/, ID = /#([\w-]+)/, CLASS_RUN = /(\.[\w-]+)+/, ATTRIBUTE = /\[(.+?)]/g, ELEMENT_AND_ATTRIBUTES = /(\S+)(.*)/, asWritten = (code) => code, buildTemplate = (selector, { inputs, outputs, innerTemplate = "", selfClosing = !1 }, unmarked = asWritten) => {
464
469
  let bindings = [
465
470
  ...inputs.map(({ name, expression, attribute }) => attribute ?? inputBinding(name, expression)),
466
471
  ...outputs.map((name) => `(${name})="${formatPropInTemplate(name)}($event)"`)
467
472
  ], firstSelector = selector.split(",")[0];
468
473
  return (LEADING_CLASS.test(firstSelector) || LEADING_ATTRIBUTE.test(firstSelector) ? `div${firstSelector}` : firstSelector).replace(ID, ' id="$1"').replace(CLASS_RUN, (classes) => ` class="${classes.split(".").join(" ").trim()}"`).replace(ATTRIBUTE, " $1").replace(ELEMENT_AND_ATTRIBUTES, (_, element, attributes) => {
469
- let closesItself = VOID_ELEMENTS.has(element) || selfClosing && element.includes("-") && innerTemplate === "", inlineTag = `<${element}${attributes}${bindings.map((binding) => ` ${binding}`).join("")}`, inline = closesItself ? `${inlineTag} />` : `${inlineTag}>${innerTemplate}</${element}>`;
470
- if (unmarked(inline).length <= MAX_SINGLE_LINE || bindings.every((binding) => unmarked(binding) === ""))
471
- return inline;
472
- let brokenTag = `<${element}${attributes}
473
- ${bindings.map((binding) => ` ${binding}`).join(`
474
- `)}`;
475
- if (closesItself)
476
- return selfClosing ? `${brokenTag}
477
- />` : `${brokenTag} />`;
474
+ let closesItself = VOID_ELEMENTS.has(element) || selfClosing && element.includes("-") && innerTemplate === "", closing = closesItself ? "" : `${innerTemplate}</${element}>`, { text, broken } = printOpeningTag(
475
+ { open: `<${element}${attributes}`, attributes: bindings, close: closesItself ? "/>" : ">" },
476
+ { after: closing, measure: unmarked }
477
+ );
478
+ if (!broken || closesItself)
479
+ return `${text}${closing}`;
478
480
  let content = innerTemplate === "" ? `
479
481
  ` : `
480
482
  ${innerTemplate}
481
483
  `;
482
- return `${brokenTag}>${content}</${element}>`;
484
+ return `${text}${content}</${element}>`;
483
485
  });
484
- }, buildComponentOutletTemplate = (componentName, { selfClosing = !1 } = {}) => selfClosing ? `<ng-container *ngComponentOutlet="${componentName}" />` : `<ng-container *ngComponentOutlet="${componentName}"></ng-container>`, INDENT = " ", MARKUP_TAG = /<(\/?)([A-Za-z][\w-]*)((?:"[^"]*"|'[^']*'|[^>"'])*)>/g, parseMarkup = (markup) => {
486
+ }, buildComponentOutletTemplate = (componentName, { selfClosing = !1 } = {}) => selfClosing ? `<ng-container *ngComponentOutlet="${componentName}" />` : `<ng-container *ngComponentOutlet="${componentName}"></ng-container>`, MARKUP_TAG = /<(\/?)([A-Za-z][\w-]*)((?:"[^"]*"|'[^']*'|[^>"'])*)>/g, parseMarkup = (markup) => {
485
487
  let root = {
486
488
  tag: "",
487
489
  rawOpen: "",
@@ -515,25 +517,30 @@ ${innerTemplate}
515
517
  }
516
518
  let trailing = markup.slice(lastIndex).trim();
517
519
  return trailing && stack.at(-1).children.push(trailing), stack.length === 1 ? root.children : void 0;
518
- }, MARKUP_ATTRIBUTE = /[^\s=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|\S+))?[\uE000-\uF8FF]*/g, openTagLines = (node, pad, forceAttrBreak, unmarked) => {
519
- let inlineOpen = `${pad}${node.rawOpen}`, attrs = node.attrText.match(MARKUP_ATTRIBUTE) ?? [];
520
- if (unmarked(inlineOpen).length <= MAX_SINGLE_LINE && !forceAttrBreak || attrs.every((attr) => unmarked(attr) === ""))
521
- return [inlineOpen];
522
- let bracket = node.closed ? " />" : ">";
523
- return [
524
- `${pad}<${node.tag}`,
525
- ...attrs.map(
526
- (attr, index) => `${pad}${INDENT}${attr}${index === attrs.length - 1 ? bracket : ""}`
527
- )
528
- ];
520
+ }, MARKUP_ATTRIBUTE = /[^\s=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|\S+))?[\uE000-\uF8FF]*/g, openTagLines = (node, pad, after, unmarked) => {
521
+ let { text, broken } = printOpeningTag(
522
+ {
523
+ open: `<${node.tag}`,
524
+ attributes: node.attrText.match(MARKUP_ATTRIBUTE) ?? [],
525
+ close: node.closed ? "/>" : ">"
526
+ },
527
+ { indent: pad, after, measure: unmarked }
528
+ );
529
+ return broken ? `${pad}${text}`.split(`
530
+ `) : [`${pad}${node.rawOpen}`];
529
531
  }, printMarkup = (markup, node, depth, unmarked) => {
530
- let pad = INDENT.repeat(depth);
532
+ let pad = SNIPPET_INDENT.repeat(depth);
531
533
  if (typeof node == "string")
532
534
  return [`${pad}${node}`];
533
535
  let hasElementChild = node.children.some((child) => typeof child != "string"), verbatim = markup.slice(node.start, node.end);
534
- if (!hasElementChild && pad.length + unmarked(verbatim).length <= MAX_SINGLE_LINE)
536
+ if (!hasElementChild && pad.length + unmarked(verbatim).length <= SNIPPET_PRINT_WIDTH)
535
537
  return [`${pad}${verbatim}`];
536
- let openLines = openTagLines(node, pad, !hasElementChild, unmarked);
538
+ let openLines = openTagLines(
539
+ node,
540
+ pad,
541
+ hasElementChild ? "" : verbatim.slice(node.rawOpen.length),
542
+ unmarked
543
+ );
537
544
  return node.closed ? openLines : [
538
545
  ...openLines,
539
546
  ...node.children.flatMap((child) => printMarkup(markup, child, depth + 1, unmarked)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/angular-vite",
3
- "version": "11.0.0-rc.3",
3
+ "version": "11.0.0-rc.4",
4
4
  "description": "Storybook for Angular: Develop, document, and test UI components in isolation",
5
5
  "keywords": [
6
6
  "storybook",
@@ -65,7 +65,7 @@
65
65
  "!src/**/*"
66
66
  ],
67
67
  "dependencies": {
68
- "@storybook/builder-vite": "11.0.0-rc.3",
68
+ "@storybook/builder-vite": "11.0.0-rc.4",
69
69
  "telejson": "8.0.0",
70
70
  "ts-dedent": "^2.2.0",
71
71
  "vite": ">=8.0.0"
@@ -82,9 +82,9 @@
82
82
  "@angular/forms": "^21.2.14",
83
83
  "@angular/platform-browser": "^21.2.14",
84
84
  "@angular/platform-browser-dynamic": "^21.2.14",
85
- "@storybook/angular-cm": "11.0.0-rc.3",
86
- "@storybook/angular-compodoc": "11.0.0-rc.3",
87
- "@storybook/component-meta-typescript": "11.0.0-rc.3",
85
+ "@storybook/angular-cm": "11.0.0-rc.4",
86
+ "@storybook/angular-compodoc": "11.0.0-rc.4",
87
+ "@storybook/component-meta-typescript": "11.0.0-rc.4",
88
88
  "@types/node": "^22.19.1",
89
89
  "empathic": "^2.0.0",
90
90
  "memfs": "^4.11.1",
@@ -107,7 +107,7 @@
107
107
  "rxjs": "^7.4.0",
108
108
  "sass": "^1.0.0",
109
109
  "sass-embedded": "^1.0.0",
110
- "storybook": "^11.0.0-rc.3",
110
+ "storybook": "^11.0.0-rc.4",
111
111
  "typescript": "^5.9.0 || ^6.0.0 || ^7.0.0",
112
112
  "vite": ">=8.0.0",
113
113
  "zone.js": ">=0.14.0"