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(NcDialog): New component (moved from @nextcloud/dialogs) #4415

Closed
wants to merge 3 commits into from

Conversation

susnux
Copy link
Contributor

@susnux susnux commented Aug 12, 2023

☑️ Resolves

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:

image

🚧 Tasks

  • Maybe migrate to not use <script setup> ? I just copied it, but it would be possible to align with the other components in this library.

🏁 Checklist

  • ⛑️ Tests are included or are not applicable
  • 📘 Component documentation has been extended, updated or is not applicable

@susnux susnux added 3. to review Waiting for reviews feature: dialog Related to the dialog component labels Aug 12, 2023
Comment on lines +141 to +149
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]
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks unrelated

Copy link
Contributor Author

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 susnux requested review from szaimen and skjnldsv August 15, 2023 13:14
@szaimen
Copy link
Contributor

szaimen commented Aug 15, 2023

@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 :)

Copy link
Contributor

@szaimen szaimen left a comment

Choose a reason for hiding this comment

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

Tested and the buttons do not show on mobile:
image

Copy link
Contributor

@ShGKme ShGKme left a 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 using ts-loader with tsc 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 😀

Comment on lines +26 to +31
<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>
Copy link
Contributor

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).

Suggested change
<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>

Comment on lines +208 to +213
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
}>()
Copy link
Contributor

@ShGKme ShGKme Aug 13, 2023

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.

Suggested change
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]
}>()

Comment on lines +116 to +117
// Support vue + Typescript
webpackRules.RULE_TS.use = ['babel-loader', { loader: 'ts-loader', options: { appendTsSuffixTo: [/\.vue$/] } }]
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor

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

with-vue-shims

P.S. Works fine in JetBrains

Copy link
Contributor

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',
Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
Contributor

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.

Comment on lines +214 to +215

const slots = useSlots()
Copy link
Contributor

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.

Copy link
Contributor

@marcoambrosini marcoambrosini left a 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?

@susnux susnux added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Aug 16, 2023
@susnux susnux marked this pull request as draft August 16, 2023 21:24
@susnux
Copy link
Contributor Author

susnux commented Sep 20, 2023

Close in favor of #4550

@susnux susnux closed this Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2. developing Work in progress feature: dialog Related to the dialog component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AppSettingsDialog does scroll the section list when clicking on entry Filepicker/dialogs component
5 participants