Skip to content

Commit

Permalink
Retrieve default values for the input properties defined using setter…
Browse files Browse the repository at this point in the history
…s/getters (#360)

#SkipVersionBump
  • Loading branch information
lukasmatta authored Mar 28, 2024
1 parent 8f1a0a8 commit 2da0f48
Show file tree
Hide file tree
Showing 19 changed files with 33 additions and 6 deletions.
19 changes: 14 additions & 5 deletions api-generator/api-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,22 @@ async function main() {
let doc = {};
let typesMap = {};

const parseText = (text) => {
return text.replace(/{/g, '{').replace(/}/g, '}');
const parseText = (content) => {
if (content.kind === 'text') {
return content.text.replace(/{/g, '{').replace(/}/g, '}');
} else if (content.kind === 'code') {
return content.text.replace(/^```ts\n/g, '').replace(/\n```$/g, '');
}
};

const getDeprecatedText = (signature) => {
const deprecatedTag = signature?.comment?.getTag('@deprecated');
return deprecatedTag ? parseText(deprecatedTag.content[0].text) : undefined;
return deprecatedTag ? parseText(deprecatedTag.content[0]) : undefined;
};

const getDefaultValue = (signature) => {
const defaultValueTag = signature?.comment?.getTag('@default') ?? signature?.comment?.getTag('@defaultValue');
return defaultValueTag ? parseText(defaultValueTag.content[0]) : undefined;
};

const modules = project.groups.find((g) => g.title === 'Modules');
Expand Down Expand Up @@ -127,13 +136,13 @@ async function main() {
? prop.type.toString()
: null,
default:
prop.type &&
(prop.type &&
prop.type.name === 'boolean' &&
!prop.defaultValue
? 'false'
: prop.defaultValue
? prop.defaultValue.replace(/^'|'$/g, '')
: undefined,
: undefined) ?? getDefaultValue(prop.setSignature) ?? getDefaultValue(prop.getSignature),
description: ((prop.getSignature?.comment?.summary || prop.setSignature?.comment?.summary) || prop.comment?.summary)?.map((s) => s.text || '').join(' '),
deprecated: getDeprecatedText(prop.getSignature)
|| getDeprecatedText(prop.setSignature)
Expand Down
1 change: 1 addition & 0 deletions projects/composition/src/app/api-data/cps-checkbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"optional": false,
"readonly": false,
"type": "boolean",
"default": "false",
"description": "Value of the checkbox."
}
]
Expand Down
1 change: 1 addition & 0 deletions projects/composition/src/app/api-data/cps-datepicker.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
"optional": false,
"readonly": false,
"type": "null | Date",
"default": "null",
"description": "Value of the datepicker."
}
]
Expand Down
1 change: 1 addition & 0 deletions projects/composition/src/app/api-data/cps-input.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
"optional": false,
"readonly": false,
"type": "string",
"default": "''",
"description": "Value of the input."
}
]
Expand Down
1 change: 1 addition & 0 deletions projects/composition/src/app/api-data/cps-switch.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"optional": false,
"readonly": false,
"type": "boolean",
"default": "false",
"description": "Value of the switch component."
}
]
Expand Down
1 change: 1 addition & 0 deletions projects/composition/src/app/api-data/cps-tab-group.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"optional": false,
"readonly": false,
"type": "number",
"default": "0",
"description": "Index of the selected tab."
},
{
Expand Down
1 change: 1 addition & 0 deletions projects/composition/src/app/api-data/cps-table.json
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@
"optional": false,
"readonly": false,
"type": "any[]",
"default": "[]",
"description": "An array of objects to display."
}
]
Expand Down
1 change: 1 addition & 0 deletions projects/composition/src/app/api-data/cps-tag.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"optional": false,
"readonly": false,
"type": "boolean",
"default": "false",
"description": "Tag value."
}
]
Expand Down
1 change: 1 addition & 0 deletions projects/composition/src/app/api-data/cps-textarea.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
"optional": false,
"readonly": false,
"type": "string",
"default": "''",
"description": "Value of the textarea."
}
]
Expand Down
1 change: 1 addition & 0 deletions projects/composition/src/app/api-data/cps-tree-table.json
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@
"optional": false,
"readonly": false,
"type": "any[]",
"default": "[]",
"description": "An array of objects to display."
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export class CpsCheckboxComponent implements OnInit, ControlValueAccessor {

/**
* Value of the checkbox.
* @default false
* @group Props
*/
@Input() set value(value: boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export class CpsDatepickerComponent

/**
* Value of the datepicker.
* @default null
* @group Props
*/
@Input() set value(value: Date | null) {
Expand Down Expand Up @@ -190,7 +191,7 @@ export class CpsDatepickerComponent
cvtWidth = '';

private _statusChangesSubscription?: Subscription;
private _value!: Date | null;
private _value: Date | null = null;

constructor(@Self() @Optional() private _control: NgControl) {
if (this._control) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export class CpsInputComponent

/**
* Value of the input.
* @default ''
* @group Props
*/
@Input() set value(value: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class CpsSwitchComponent implements ControlValueAccessor {

/**
* Value of the switch component.
* @default false
* @group Props
*/
@Input() set value(value: boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export class CpsTabGroupComponent
{
/**
* Index of the selected tab.
* @default 0
* @group Props
*/
@Input() set selectedIndex(value: number) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ export class CpsTableComponent implements OnInit, AfterViewChecked, OnChanges {

/**
* An array of objects to display.
* @default []
* @group Props
*/
@Input() set data(value: any[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class CpsTagComponent implements ControlValueAccessor, OnChanges {

/**
* Tag value.
* @default false
* @group Props
*/
@Input() set value(value: boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export class CpsTextareaComponent

/**
* Value of the textarea.
* @default ''
* @group Props
*/
@Input() set value(value: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ export class CpsTreeTableComponent

/**
* An array of objects to display.
* @default []
* @group Props
*/
@Input() set data(value: any[]) {
Expand Down

0 comments on commit 2da0f48

Please sign in to comment.