Skip to content

Commit

Permalink
Fix #4917: Datatable/Calendar doc props
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Sep 14, 2023
1 parent ddf3fcc commit d1e9a0a
Show file tree
Hide file tree
Showing 5 changed files with 10,279 additions and 12,440 deletions.
98 changes: 60 additions & 38 deletions api-generator/build-apidoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ if (project) {
};

const module_component_group = module.groups.find((g) => g.title === 'Component');
const module_properties_group = module.groups.find((g) => g.title === 'Properties');

module_component_group &&
module_component_group.children.forEach((component) => {
Expand Down Expand Up @@ -103,8 +104,7 @@ if (project) {
});

const component_props_id = component.extendedTypes && component.extendedTypes[0].typeArguments && component.extendedTypes[0].typeArguments[0] && component.extendedTypes[0].typeArguments[0]._target;
const module_properties_group = module.groups.find((g) => g.title === 'Properties');
const component_props = module_properties_group && module_properties_group.children.find((c) => (component_props_id ? c.id === component_props_id : true));
const component_properties = module_properties_group && module_properties_group.children.find((c) => (component_props_id ? c.id === component_props_id : true));

const props = {
description: '',
Expand All @@ -115,48 +115,70 @@ if (project) {
values: []
};

if (component_props) {
props.description = component_props.comment ? component_props.comment.summary.map((s) => parseText(s.text || '')).join(' ') : '';

const component_props_group = component_props.groups && component_props.groups.find((g) => g.title === 'Properties');

component_props_group &&
component_props_group.children.forEach((prop) => {
if (!prop.inheritedFrom || (prop.inheritedFrom && !prop.inheritedFrom.toString().startsWith('Omit.data-pr-'))) {
props.values.push({
name: prop.name,
optional: prop.flags.isOptional,
readonly: prop.flags.isReadonly,
type: prop.type.toString(),
default: prop.comment && prop.comment.getTag('@defaultValue') ? parseText(prop.comment.getTag('@defaultValue').content[0].text) : '', // TODO: Check
description: prop.comment && prop.comment.summary.map((s) => parseText(s.text || '')).join(' '),
deprecated: prop.comment && prop.comment.getTag('@deprecated') ? parseText(prop.comment.getTag('@deprecated').content[0].text) : undefined
});
}
});
if (component_properties) {
let collected_properties = [component_properties];

const component_props_methods_group = component_props.groups && component_props.groups.find((g) => g.title === 'Methods');
// Calendar/DataTable have multiple subtypes for properties
if (component_properties.type && component_properties.type.types) {
component_properties.type.types.forEach((type) => {
const type_props = module_properties_group.children.find((c) => (type._target ? c.id === type._target : true));

component_props_methods_group &&
component_props_methods_group.children.forEach((method) => {
const signature = method.getAllSignatures()[0];
if (type_props) {
collected_properties = [type_props];

callbacks.values.push({
name: signature.name,
parameters: signature.parameters.map((param) => {
return {
name: param.name,
optional: param.flags.isOptional,
type: param.type.toString(),
description: param.comment && param.comment.summary.map((s) => parseText(s.text || '')).join(' ')
};
}),
returnType: signature.type.toString(),
description: signature.comment.summary.map((s) => parseText(s.text || '')).join(' ')
});
return;
}
});
}

collected_properties.forEach((component_props) => {
props.description = component_props.comment ? component_props.comment.summary.map((s) => parseText(s.text || '')).join(' ') : '';

const component_props_group = component_props.groups && component_props.groups.find((g) => g.title === 'Properties');

component_props_group &&
component_props_group.children.forEach((prop) => {
if ((!prop.inheritedFrom || (prop.inheritedFrom && !prop.inheritedFrom.toString().startsWith('Omit.data-pr-'))) && !prop.name.startsWith('data-pr-')) {
props.values.push({
name: prop.name,
optional: prop.flags.isOptional,
readonly: prop.flags.isReadonly,
type: prop.type.toString(),
default: prop.comment && prop.comment.getTag('@defaultValue') ? parseText(prop.comment.getTag('@defaultValue').content[0].text) : '', // TODO: Check
description: prop.comment && prop.comment.summary.map((s) => parseText(s.text || '')).join(' '),
deprecated: prop.comment && prop.comment.getTag('@deprecated') ? parseText(prop.comment.getTag('@deprecated').content[0].text) : undefined
});
}
});

const component_props_methods_group = component_props.groups && component_props.groups.find((g) => g.title === 'Methods');

component_props_methods_group &&
component_props_methods_group.children.forEach((method) => {
const signature = method.getAllSignatures()[0];

callbacks.values.push({
name: signature.name,
parameters: signature.parameters.map((param) => {
return {
name: param.name,
optional: param.flags.isOptional,
type: param.type.toString(),
description: param.comment && param.comment.summary.map((s) => parseText(s.text || '')).join(' ')
};
}),
returnType: signature.type.toString(),
description: signature.comment.summary.map((s) => parseText(s.text || '')).join(' ')
});
});
});
}

// sorts
props.values.sort((a, b) => a.name.localeCompare(b.name));
methods.values.sort((a, b) => a.name.localeCompare(b.name));
callbacks.values.sort((a, b) => a.name.localeCompare(b.name));

doc[name]['components'][component.name] = {
description,
methods,
Expand Down
Loading

0 comments on commit d1e9a0a

Please sign in to comment.