From b7201322bbf1f5696e80e00622d21d653228177c Mon Sep 17 00:00:00 2001 From: Diego Pascual Date: Wed, 8 May 2024 16:20:31 +0200 Subject: [PATCH 1/2] feat: migrate `MainScroll` and `MainScrollItem` components (#1456) BREAKING CHANGE: `MainScroll` drops the usage of `NoElement` as root element and uses a div instead. This extra div could break the style of an application that relies on `MainScroll` rendering their content directly. `MainScrollItem` drops the usage of `NoElement` if no `tag` prop is passed and uses a div as fallback. --- packages/_vue3-migration-test/src/main.ts | 9 +- packages/_vue3-migration-test/src/router.ts | 6 + .../src/x-modules/index.ts | 1 + .../src/x-modules/scroll/index.ts | 2 + .../src/x-modules/scroll/test-scroll.vue | 22 + .../src/x-modules/scroll/x-module.ts | 10 + .../__tests__/disable-animation-mixin.spec.ts | 5 +- .../animations/disable-animation.mixin.ts | 5 +- .../layouts/multi-column-max-width-layout.vue | 2 +- .../x-components/src/composables/use-state.ts | 2 +- .../scroll/components/main-scroll-item.vue | 232 +++++---- .../scroll/components/main-scroll.vue | 464 +++++++++--------- .../tests/unit/main-scroll.spec.ts | 9 +- 13 files changed, 442 insertions(+), 327 deletions(-) create mode 100644 packages/_vue3-migration-test/src/x-modules/scroll/index.ts create mode 100644 packages/_vue3-migration-test/src/x-modules/scroll/test-scroll.vue create mode 100644 packages/_vue3-migration-test/src/x-modules/scroll/x-module.ts diff --git a/packages/_vue3-migration-test/src/main.ts b/packages/_vue3-migration-test/src/main.ts index 58fdfd9f62..bf9c6ba6cb 100644 --- a/packages/_vue3-migration-test/src/main.ts +++ b/packages/_vue3-migration-test/src/main.ts @@ -4,6 +4,7 @@ import { createStore } from 'vuex'; import { xPlugin } from '../../x-components/src/plugins/x-plugin'; import App from './App.vue'; import router from './router'; +import { scrollXModule } from './x-modules/scroll/x-module'; // Warnings that cannot be solved in Vue 2 (a.k.a. breaking changes) are suppressed const VUE_COMPAT_MODE = Number(import.meta.env.VITE_VUE_COMPAT_MODE); @@ -30,5 +31,11 @@ const store = createStore({}); createApp(App as Component) .use(router) .use(store) - .use(xPlugin, { adapter, store }) + .use(xPlugin, { + adapter, + store, + __PRIVATE__xModules: { + scroll: scrollXModule + } + }) .mount('#app'); diff --git a/packages/_vue3-migration-test/src/router.ts b/packages/_vue3-migration-test/src/router.ts index 436788fafc..a19f19f3a4 100644 --- a/packages/_vue3-migration-test/src/router.ts +++ b/packages/_vue3-migration-test/src/router.ts @@ -8,6 +8,7 @@ import { TestSortDropdown, TestSortList, TestSortPickerList, + TestScroll, TestBaseColumnPickerDropdown } from './'; @@ -22,6 +23,11 @@ const routes = [ name: 'Fade', component: TestFade }, + { + path: '/scroll', + name: 'Scroll', + component: TestScroll + }, { path: '/base-dropdown', name: 'BaseDropdown', diff --git a/packages/_vue3-migration-test/src/x-modules/index.ts b/packages/_vue3-migration-test/src/x-modules/index.ts index 5a2bdeb5b8..0778e03578 100644 --- a/packages/_vue3-migration-test/src/x-modules/index.ts +++ b/packages/_vue3-migration-test/src/x-modules/index.ts @@ -1 +1,2 @@ export * from './search'; +export * from './scroll'; diff --git a/packages/_vue3-migration-test/src/x-modules/scroll/index.ts b/packages/_vue3-migration-test/src/x-modules/scroll/index.ts new file mode 100644 index 0000000000..0a0c301dd9 --- /dev/null +++ b/packages/_vue3-migration-test/src/x-modules/scroll/index.ts @@ -0,0 +1,2 @@ +export { default as TestScroll } from './test-scroll.vue'; +export * from './x-module'; diff --git a/packages/_vue3-migration-test/src/x-modules/scroll/test-scroll.vue b/packages/_vue3-migration-test/src/x-modules/scroll/test-scroll.vue new file mode 100644 index 0000000000..8f74707be1 --- /dev/null +++ b/packages/_vue3-migration-test/src/x-modules/scroll/test-scroll.vue @@ -0,0 +1,22 @@ + + + + + diff --git a/packages/_vue3-migration-test/src/x-modules/scroll/x-module.ts b/packages/_vue3-migration-test/src/x-modules/scroll/x-module.ts new file mode 100644 index 0000000000..8ecf56eab0 --- /dev/null +++ b/packages/_vue3-migration-test/src/x-modules/scroll/x-module.ts @@ -0,0 +1,10 @@ +import { PrivateXModuleOptions } from '../../../../x-components/src/plugins/x-plugin.types'; +import { ScrollXModule } from '../../../../x-components/src/x-modules/scroll/x-module'; + +export const scrollXModule: PrivateXModuleOptions = { + storeModule: { + state: { + pendingScrollTo: 'item-10' + } + } +}; diff --git a/packages/x-components/src/components/animations/__tests__/disable-animation-mixin.spec.ts b/packages/x-components/src/components/animations/__tests__/disable-animation-mixin.spec.ts index ba1c7f481a..c3bc5bf904 100644 --- a/packages/x-components/src/components/animations/__tests__/disable-animation-mixin.spec.ts +++ b/packages/x-components/src/components/animations/__tests__/disable-animation-mixin.spec.ts @@ -1,14 +1,13 @@ import { mount, Wrapper } from '@vue/test-utils'; -import { Component, Prop } from 'vue-property-decorator'; +import { Component, Prop, Provide } from 'vue-property-decorator'; import Vue, { ComponentOptions, CreateElement, VNode } from 'vue'; import DisableAnimationMixin from '../disable-animation.mixin'; -import { XProvide } from '../../decorators/injection.decorators'; import { DISABLE_ANIMATIONS_KEY } from '../../decorators/injection.consts'; @Component class Provider extends Vue { @Prop() - @XProvide(DISABLE_ANIMATIONS_KEY) + @Provide(DISABLE_ANIMATIONS_KEY as string) public disableAnimation!: boolean; render(h: CreateElement): VNode { diff --git a/packages/x-components/src/components/animations/disable-animation.mixin.ts b/packages/x-components/src/components/animations/disable-animation.mixin.ts index a49e1c46ab..9581fa47cf 100644 --- a/packages/x-components/src/components/animations/disable-animation.mixin.ts +++ b/packages/x-components/src/components/animations/disable-animation.mixin.ts @@ -1,6 +1,5 @@ import Vue from 'vue'; -import { Component } from 'vue-property-decorator'; -import { XInject } from '../decorators/injection.decorators'; +import { Component, Inject } from 'vue-property-decorator'; import { DISABLE_ANIMATIONS_KEY } from '../decorators/injection.consts'; /** @@ -22,7 +21,7 @@ export default class DisableAnimationMixin extends Vue { * * @public */ - @XInject(DISABLE_ANIMATIONS_KEY) + @Inject({ from: DISABLE_ANIMATIONS_KEY as string, default: false }) public disableAnimation!: boolean; /** diff --git a/packages/x-components/src/components/layouts/multi-column-max-width-layout.vue b/packages/x-components/src/components/layouts/multi-column-max-width-layout.vue index 8eadb62fbb..9b55ef31c5 100644 --- a/packages/x-components/src/components/layouts/multi-column-max-width-layout.vue +++ b/packages/x-components/src/components/layouts/multi-column-max-width-layout.vue @@ -69,7 +69,7 @@ - +
diff --git a/packages/x-components/src/composables/use-state.ts b/packages/x-components/src/composables/use-state.ts index 55612eb464..e26c4c47da 100644 --- a/packages/x-components/src/composables/use-state.ts +++ b/packages/x-components/src/composables/use-state.ts @@ -19,7 +19,7 @@ export function useState< const store = useStore(); return paths.reduce>((stateDictionary, path) => { - stateDictionary[path] = computed(() => store.state.x[module]?.[path]); + stateDictionary[path] = computed(() => store?.state.x[module]?.[path]); return stateDictionary; }, {}); } diff --git a/packages/x-components/src/x-modules/scroll/components/main-scroll-item.vue b/packages/x-components/src/x-modules/scroll/components/main-scroll-item.vue index 9f67b2e50f..8c5c330016 100644 --- a/packages/x-components/src/x-modules/scroll/components/main-scroll-item.vue +++ b/packages/x-components/src/x-modules/scroll/components/main-scroll-item.vue @@ -1,15 +1,26 @@ diff --git a/packages/x-components/src/x-modules/scroll/components/main-scroll.vue b/packages/x-components/src/x-modules/scroll/components/main-scroll.vue index 9c9f970eb5..710a53b52f 100644 --- a/packages/x-components/src/x-modules/scroll/components/main-scroll.vue +++ b/packages/x-components/src/x-modules/scroll/components/main-scroll.vue @@ -1,19 +1,16 @@ diff --git a/packages/x-components/tests/unit/main-scroll.spec.ts b/packages/x-components/tests/unit/main-scroll.spec.ts index 802025c260..b3f99e43c7 100644 --- a/packages/x-components/tests/unit/main-scroll.spec.ts +++ b/packages/x-components/tests/unit/main-scroll.spec.ts @@ -24,7 +24,8 @@ function renderMainScroll({ useWindow, windowScrollingElement, template = ` - +
{ ...defaultParameters, template: ` -
+
{ userScrolledToElementSpy().should('have.been.calledWith', 'item-5'); userScrolledToElementSpy().should('not.have.been.calledWith', 'item-6'); /* By just scrolling 1 px down, as we require the 100% of the element to intersect to be - considered visible, the 5th element does no longer meet this condition. Therefore the 6th + considered visible, the 5th element does no longer meet this condition. Therefore, the 6th element is considered the first one. */ scrollBy(1); userScrolledToElementSpy().should('have.been.calledWith', 'item-6'); From 5c345dbd7d4f8841da124b36515fcb871d9c0a76 Mon Sep 17 00:00:00 2001 From: empathy/x Date: Wed, 8 May 2024 14:35:29 +0000 Subject: [PATCH 2/2] chore(release): publish - vue3-migration-test@1.0.0-alpha.5 - @empathyco/x-components@5.0.0-alpha.8 --- packages/_vue3-migration-test/CHANGELOG.md | 14 ++++++++++++++ packages/_vue3-migration-test/package.json | 2 +- packages/x-components/CHANGELOG.md | 14 ++++++++++++++ packages/x-components/package.json | 2 +- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/_vue3-migration-test/CHANGELOG.md b/packages/_vue3-migration-test/CHANGELOG.md index ed6684f43c..2a1f99fbf1 100644 --- a/packages/_vue3-migration-test/CHANGELOG.md +++ b/packages/_vue3-migration-test/CHANGELOG.md @@ -3,6 +3,20 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.0.0-alpha.5](https://github.com/empathyco/x/compare/vue3-migration-test@1.0.0-alpha.4...vue3-migration-test@1.0.0-alpha.5) (2024-05-08) + + +### ⚠ BREAKING CHANGES + +* `MainScroll` drops the usage of `NoElement` as root element and uses a div instead. This extra div could break the style of an application that relies on `MainScroll` rendering their content directly. +`MainScrollItem` drops the usage of `NoElement` if no `tag` prop is passed and uses a div as fallback. + +### Features + +* migrate `MainScroll` and `MainScrollItem` components (#1456) ([b720132](https://github.com/empathyco/x/commit/b7201322bbf1f5696e80e00622d21d653228177c)) + + + ## [1.0.0-alpha.4](https://github.com/empathyco/x/compare/vue3-migration-test@1.0.0-alpha.3...vue3-migration-test@1.0.0-alpha.4) (2024-05-06) diff --git a/packages/_vue3-migration-test/package.json b/packages/_vue3-migration-test/package.json index 3a69593937..524ba70571 100644 --- a/packages/_vue3-migration-test/package.json +++ b/packages/_vue3-migration-test/package.json @@ -1,7 +1,7 @@ { "name": "vue3-migration-test", "private": "true", - "version": "1.0.0-alpha.4", + "version": "1.0.0-alpha.5", "scripts": { "dev": "vite", "preview": "vite preview", diff --git a/packages/x-components/CHANGELOG.md b/packages/x-components/CHANGELOG.md index 26f48ceeb2..c1942a65d2 100644 --- a/packages/x-components/CHANGELOG.md +++ b/packages/x-components/CHANGELOG.md @@ -3,6 +3,20 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [5.0.0-alpha.8](https://github.com/empathyco/x/compare/@empathyco/x-components@5.0.0-alpha.7...@empathyco/x-components@5.0.0-alpha.8) (2024-05-08) + + +### ⚠ BREAKING CHANGES + +* `MainScroll` drops the usage of `NoElement` as root element and uses a div instead. This extra div could break the style of an application that relies on `MainScroll` rendering their content directly. +`MainScrollItem` drops the usage of `NoElement` if no `tag` prop is passed and uses a div as fallback. + +### Features + +* migrate `MainScroll` and `MainScrollItem` components (#1456) ([b720132](https://github.com/empathyco/x/commit/b7201322bbf1f5696e80e00622d21d653228177c)) + + + ## [5.0.0-alpha.7](https://github.com/empathyco/x/compare/@empathyco/x-components@5.0.0-alpha.6...@empathyco/x-components@5.0.0-alpha.7) (2024-05-06) diff --git a/packages/x-components/package.json b/packages/x-components/package.json index a1db541388..24c765013f 100644 --- a/packages/x-components/package.json +++ b/packages/x-components/package.json @@ -1,6 +1,6 @@ { "name": "@empathyco/x-components", - "version": "5.0.0-alpha.7", + "version": "5.0.0-alpha.8", "description": "Empathy X Components", "author": "Empathy Systems Corporation S.L.", "license": "Apache-2.0",