Skip to content
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

feat(docs&api&ts): Add new top-level section 'fields' #14243

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 4 additions & 13 deletions docs/src/components/DocApiEntry.js
Expand Up @@ -277,7 +277,7 @@ function copyPropName (propName) {

const describe = {}

describe.props = props => {
const describePropsLike = props => {
const child = []

for (const propName in props) {
Expand All @@ -288,18 +288,9 @@ describe.props = props => {

return child
}

describe.slots = slots => {
const child = []

for (const slot in slots) {
child.push(
getProp(slots[ slot ], slot, 0)
)
}

return child
}
describe.props = describePropsLike
describe.fields = describePropsLike
describe.slots = describePropsLike

describe.events = events => {
const child = []
Expand Down
12 changes: 10 additions & 2 deletions ui/build/build.api.js
Expand Up @@ -38,7 +38,7 @@ function getMixedInAPI (api, mainFile) {

const topSections = {
plugin: [ 'meta', 'injection', 'quasarConfOptions', 'addedIn', 'props', 'methods' ],
component: [ 'meta', 'quasarConfOptions', 'addedIn', 'props', 'slots', 'events', 'methods' ],
component: [ 'meta', 'quasarConfOptions', 'addedIn', 'props', 'slots', 'events', 'methods', 'fields' ],
directive: [ 'meta', 'quasarConfOptions', 'addedIn', 'value', 'arg', 'modifiers' ]
}

Expand Down Expand Up @@ -129,6 +129,14 @@ const objectTypes = {
isBoolean: [ 'internal' ]
},

// component only
fields: {
props: [ 'desc', 'tsType', 'examples', 'addedIn', 'internal' ],
required: [ 'desc' ],
isBoolean: [ 'internal' ],
isArray: [ 'examples' ]
},

methods: {
props: [ 'tsInjectionPoint', 'tsType', 'desc', 'link', 'params', 'returns', 'addedIn' ],
required: [ 'desc' ],
Expand Down Expand Up @@ -472,7 +480,7 @@ function parseAPI (file, apiType) {
banner: `${ banner } "${ type }"/"${ itemName }"`,
api: api[ type ],
itemName,
masterType: type,
masterType: type === 'fields' ? 'props' : type,
verifyCategory: type === 'props' && isComponent
})
}
Expand Down
13 changes: 11 additions & 2 deletions ui/build/build.types.js
Expand Up @@ -101,7 +101,7 @@ function getTypeVal (def) {
: convertTypeVal(def.type, def)
}

function getPropDefinition ({ name, definition, docs = true, isMethodParam = false, isCompProps = false, escapeName = true }) {
function getPropDefinition ({ name, definition, docs = true, isMethodParam = false, isCompProps = false, escapeName = true, isReadonly = false }) {
let propName = escapeName ? toCamelCase(name) : name

if (propName.startsWith('...')) {
Expand Down Expand Up @@ -147,7 +147,7 @@ function getPropDefinition ({ name, definition, docs = true, isMethodParam = fal
jsDoc += ' */\n'
}

return `${ jsDoc }${ propName }${ !definition.required ? '?' : '' }: ${ propType }`
return `${ jsDoc }${ isReadonly ? 'readonly ' : '' }${ propName }${ !definition.required ? '?' : '' }: ${ propType }`
}

function getPropDefinitions ({ definitions, docs = true, areMethodParams = false, isCompProps = false }) {
Expand Down Expand Up @@ -344,6 +344,9 @@ function writeIndexDTS (apis) {
prop.type = 'Function'
})

// Fields should always be required
content.fields = transformObject(content.fields, makeRequired)

const props = getPropDefinitions({
definitions: content.props,
isCompProps: content.type === 'component'
Expand Down Expand Up @@ -449,6 +452,12 @@ function writeIndexDTS (apis) {
writeLines(contents, methodDefinition, 1)
}

// Write Fields
for (const [ fieldName, field ] of Object.entries(content.fields)) {
const fieldDefinition = getPropDefinition({ name: fieldName, definition: field, isReadonly: true })
writeLines(contents, fieldDefinition, 1)
}

// Close class declaration
writeLine(contents, '}')
writeLine(contents)
Expand Down
20 changes: 20 additions & 0 deletions ui/src/components/table/QTable.json
Expand Up @@ -2414,5 +2414,25 @@
}
}
}
},

"fields": {
"filteredSortedRows": {
"desc": "The filtered and sorted rows (same as the rows prop if using server-side fetching)",
"type": "Array",
"examples": [ "[ { name: 'Ice Cream Sandwich', calories: 237, fat: 9.0, carbs: 37, protein: 4.3, sodium: 129, calcium: 8, iron: 1 }, ... ]" ]
},

"computedRows": {
"desc": "Paginated, filtered, and sorted rows (same as the rows prop if using server-side fetching)",
"type": "Array",
"examples": [ "[ { name: 'Ice Cream Sandwich', calories: 237, fat: 9.0, carbs: 37, protein: 4.3, sodium: 129, calcium: 8, iron: 1 }, ... ]" ]
},

"computedRowsNumber": {
"desc": "The number of computed rows",
"type": "Number",
"examples": [ 10 ]
}
}
}
48 changes: 48 additions & 0 deletions ui/src/components/uploader/QUploader.json
Expand Up @@ -152,5 +152,53 @@
}
}
}
},

"fields": {
Copy link
Member

Choose a reason for hiding this comment

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

If we don't merge in #14241 as I suggested to avoid, these definitions need to be moved into scoped slots params

"files": {
"type": "Array",
"desc": "List of all files",
"__exemption": [ "examples" ]
},

"queuedFiles": {
"type": "Array",
"desc": "List of files that are waiting to be uploaded",
"__exemption": [ "examples" ]
},

"uploadedFiles": {
"type": "Array",
"desc": "List of files that have been uploaded",
"__exemption": [ "examples" ]
},

"uploadedSize": {
"type": "Number",
"desc": "Size of all uploaded files in bytes",
"examples": [ 1024 ]
},

"uploadSizeLabel": {
"type": "String",
"desc": "Label for the size total of all files",
"examples": [ "1.0MB" ]
},

"uploadProgressLabel": {
"type": "String",
"desc": "Label for the upload progress (in %)",
"examples": [ "52.76%" ]
},

"canAddFiles": {
"type": "Boolean",
"desc": "Whether new files can be added to the list"
},

"canUpload": {
"type": "Boolean",
"desc": "Whether the files can be uploaded"
}
}
}
7 changes: 7 additions & 0 deletions ui/src/composables/private/use-validate.json
Expand Up @@ -74,5 +74,12 @@
]
}
}
},

"fields": {
"hasError": {
"type": "Boolean",
"desc": "Whether the component is in error state"
}
}
}