-
Notifications
You must be signed in to change notification settings - Fork 90
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(NcDialog): New component (moved from @nextcloud/dialogs
)
#4415
Conversation
…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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks unrelated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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-tsc
instead of usingts-loader
withtsc
and 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if I'm not wrong: "./src/**/*.vue"
to the include
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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".
See: https://github.com/vuejs/language-tools/tree/master/packages/vscode-vue#usage
P.S. Works fine in JetBrains
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
glob
in entrypoints doesn't include .ts
files, so NcDialog
is not included into cjs
bundle.
@@ -9,11 +12,21 @@ module.exports = { | |||
appVersion: true, | |||
}, | |||
extends: [ | |||
'@nextcloud', | |||
'@nextcloud/eslint-config/typescript', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, could with default with a size small or normal for the modal?
Close in favor of #4550 |
☑️ Resolves
AppSettingsDialog
does 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/dialogs
package 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