Skip to content

feat(app): display inputsignals as inputs rather than properties #1439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/app/compiler/angular-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,12 @@ export class AngularDependencies extends FrameworkDependencies {
if (IO.constructor && !Configuration.mainData.disableConstructors) {
deps.constructorObj = IO.constructor;
}
if (IO.inputs) {
deps.inputsClass = IO.inputs;
}
if (IO.properties) {
deps.properties = IO.properties;
deps.inputsClass = deps.inputsClass ? deps.inputsClass.concat(this.componentHelper.getInputSignals(IO.properties)) : this.componentHelper.getInputSignals(IO.properties);
}
if (IO.description) {
deps.description = IO.description;
Expand All @@ -272,9 +276,6 @@ export class AngularDependencies extends FrameworkDependencies {
if (IO.accessors) {
deps.accessors = IO.accessors;
}
if (IO.inputs) {
deps.inputsClass = IO.inputs;
}
if (IO.outputs) {
deps.outputsClass = IO.outputs;
}
Expand Down
3 changes: 3 additions & 0 deletions src/app/compiler/angular/deps/component-dep.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ export class ComponentDepFactory {
if (IO.accessors) {
componentDep.accessors = IO.accessors;
}
if (IO.properties) {
componentDep.inputsClass = componentDep.inputsClass.concat(this.helper.getInputSignals(IO.properties));
}

return componentDep;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/compiler/angular/deps/directive-dep.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class DirectiveDepFactory {

standalone: this.helper.getComponentStandalone(props, srcFile) ? true : false,

inputsClass: IO.inputs,
inputsClass: this.helper.getInputSignals(IO.properties).concat(IO.inputs),
outputsClass: IO.outputs,

deprecated: IO.deprecated,
Expand Down
15 changes: 15 additions & 0 deletions src/app/compiler/angular/deps/helpers/component-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ export class ComponentHelper {
return this.symbolHelper.getSymbolDeps(props, 'inputs', srcFile);
}

public getInputSignals(props) {
let inputSignals = [];
props?.forEach((prop, i) => {
const regexp = /input(?:\.(required))?(?:<([\w-]+)>)?\(([\w-]+)?\)/;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@astrutz This regex has quite some limitations. I will list the most obvious ones and potentially we can adjust the regex to cover the cases:

  • input("helloworld") -> strings are not supported as default values
  • input(false, { transform: booleanAttribute }); -> as soon as a transformation option is used, the regex doesn't match

I am thinking of potentially rather use some babel parsing here instead of relying on a regex, since the expression might also have some new line characters, especially if the options object is used to provide a transform function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vogloblinsky thank you so much for this if you can support the cases @valentinpalkovic mentioned, thank you so much in advance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@valentinpalkovic I agree with you, although I can't really do much, as I don't have the capacity atm. I'll check with company and can come back to you in about 3 weeks

Copy link

@tobiaskau tobiaskau Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@astrutz Is there a Github issue ticket for that? This issue in relation to Storybook is quite important to me currently as it unfortunately makes it kind of unusable currently :(

const res = regexp.exec(prop.defaultValue);
if (res) {
const newInput = prop;
newInput.defaultValue = res[res.length - 1];
newInput.required = res[0]?.includes('.required') ?? false;
inputSignals.push(newInput);
}
});
return inputSignals;
}

public getComponentStandalone(
props: ReadonlyArray<ts.ObjectLiteralElementLike>,
srcFile: ts.SourceFile
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy