feat(NcDialog): New component (moved from @nextcloud/dialogs)#4415
feat(NcDialog): New component (moved from @nextcloud/dialogs)#4415
@nextcloud/dialogs)#4415Conversation
…eric dialogs Signed-off-by: Ferdinand Thiessen <[email protected]>
Signed-off-by: Ferdinand Thiessen <[email protected]>
Signed-off-by: Ferdinand Thiessen <[email protected]>
| const placeholders = this.text.split(/(\{[a-z\-_.0-9]+\})/ig).map((entry) => { | ||
| const matches = entry.match(/^\{([a-z\-_.0-9]+)\}$/i) | ||
| // just return plain string nodes as text | ||
| if (!matches) { | ||
| return prepareTextNode({ h, context }, entry) | ||
| return prepareTextNode({ h, context: this }, entry) | ||
| } | ||
| // return component instance if argument is an object | ||
| const argumentId = matches[1] | ||
| const argument = context.arguments[argumentId] | ||
| const argument = this.arguments[argumentId] |
There was a problem hiding this comment.
Required to fix eslint errors which would break the CI test. (Comes from introducing Typescript for Vue components).
So I had to either rewrite the code as vanilla Javascript or fix this linting errors.
|
@susnux I tested this and seems to work well :) Can the dialogs be the small size at default? I think this would look much better and would eliminate the need to always overwrite it everywhere :) |
There was a problem hiding this comment.
Apart from adding a new component, this PR introduces TS and using SFC Setup. It requires more tooling updates:
- Webpack config update to support
vue-tscinstead of usingts-loaderwithtscand to build TS files - ESLint rules Vue + TS + SFC Setup support
- Possibly, tsconfig update
Also, I'm a bit afraid of using SFC Setup in Vue 2. Although it was "backported" at the moment of releasing Vue 2.7, some things were not backported (e.g. Vue 3.3 new stuff) or works differently and has no documentation. And I guess it won't be changed for Vue 2.
What do you think about adding this component first without TS and maybe without SFC Setup but with JS and plain SFC (with Composition API)?
Or, at least after full migration to Vite with another your PR. It will be easier to add first-class TypeScript support 😀
| <NcButton :aria-label="props.label" :type="props.type" @click="handleClick"> | ||
| {{ props.label }} | ||
| <template v-if="props.icon !== undefined" #icon> | ||
| <component :is="props.icon" :size="20" /> | ||
| </template> | ||
| </NcButton> |
There was a problem hiding this comment.
All props are still available directly in SFC Setup's template as in SFC's template (all props are still instance's properties).
| <NcButton :aria-label="props.label" :type="props.type" @click="handleClick"> | |
| {{ props.label }} | |
| <template v-if="props.icon !== undefined" #icon> | |
| <component :is="props.icon" :size="20" /> | |
| </template> | |
| </NcButton> | |
| <NcButton :aria-label="label" :type="type" @click="handleClick"> | |
| {{ props.label }} | |
| <template v-if="icon !== undefined" #icon> | |
| <component :is="icon" :size="20" /> | |
| </template> | |
| </NcButton> |
| const emit = defineEmits<{ | ||
| /** Emitted when the dialog is about to close but the out transition did not finished yet */ | ||
| (e: 'closing'): void | ||
| /** Emitted when the open state changed */ | ||
| (e: 'update:open', v: boolean): void | ||
| }>() |
There was a problem hiding this comment.
I don't remember if it is supported in Vue 2.7 SFC Setup, but in the latest SFC setup compiler there is a short syntax for defineEmits compile macros.
| const emit = defineEmits<{ | |
| /** Emitted when the dialog is about to close but the out transition did not finished yet */ | |
| (e: 'closing'): void | |
| /** Emitted when the open state changed */ | |
| (e: 'update:open', v: boolean): void | |
| }>() | |
| const emit = defineEmits<{ | |
| /** Emitted when the dialog is about to close but the out transition did not finished yet */ | |
| 'closing': [] | |
| /** Emitted when the open state changed */ | |
| 'update:open': [v: boolean] | |
| }>() |
| // Support vue + Typescript | ||
| webpackRules.RULE_TS.use = ['babel-loader', { loader: 'ts-loader', options: { appendTsSuffixTo: [/\.vue$/] } }] |
There was a problem hiding this comment.
ts-loader is no longer recommended way to use TS with Vue when TS is used in templates or with SFC Setup. ts-loader is using tsc to compile TS in the <script> and check types after SRC compiling.
It works, but with limitations, and is different from IDE type-checking by vue-tsc and with Vite build.
Instead, we can compile TS without tsc and check types in a separate script. For example, with babel/preset-typescript which is already added to the config.
There was a problem hiding this comment.
Or we can fully move to Vite by merging your PR :)
Then ESBuild instead of tsc will be used to transpile ts.
There was a problem hiding this comment.
If we use Vue with TS now, we should also add
"vueCompilerOptions": {
"target": 2.7,
}
And add @vue/runtime-dom as a dev dependency.
There was a problem hiding this comment.
And if I'm not wrong: "./src/**/*.vue" to the include
There was a problem hiding this comment.
Adding vue-shims.d.ts is not a solution for .vue files support in TS/IDE. With this file, by default go-to-declaration in VSCode goes to this file saying "any .vue file is just Vue".
P.S. Works fine in JetBrains
There was a problem hiding this comment.
glob in entrypoints doesn't include .ts files, so NcDialog is not included into cjs bundle.
| }, | ||
| extends: [ | ||
| '@nextcloud', | ||
| '@nextcloud/eslint-config/typescript', |
There was a problem hiding this comment.
It seems that this config is for .ts files only. We need to update @nextcloud/eslint-config to support Vue + TS with SFC Setup.
There was a problem hiding this comment.
Also, npm run lint doesn't check TS files.
|
|
||
| import { useElementSize } from '@vueuse/core' | ||
| import { computed, ref, useSlots } from 'vue' | ||
| import { Fragment } from 'vue-frag' // can be dropped with vue3 |
There was a problem hiding this comment.
Why do we need a <Fragment> here? Slot content doesn't have to have a single root element.
|
|
||
| const slots = useSlots() |
There was a problem hiding this comment.
I don't remember if it is supported in Vue 2.7, but in SFC Setup there is a defineSlots macro to define slots with TS.
marcoambrosini
left a comment
There was a problem hiding this comment.
Hi, could with default with a size small or normal for the modal?
|
Close in favor of #4550 |


☑️ Resolves
AppSettingsDialogdoes scroll the section list when clicking on entry #4348 (fixed by migrating AppSettingsDialog to NcDialog base)Introduces NcDialog as a generic base Dialog component, while NcModal is simply a base for modals like the viewer, NcDialog provides a convenient interface to define dialogs (see example).
The new FilePicker of the
@nextcloud/dialogspackage is based on top of it.🖼️ Screenshots
One example dialog:
🚧 Tasks
<script setup>? I just copied it, but it would be possible to align with the other components in this library.🏁 Checklist