From 00941a375632811d32f61088e161bcdf08edcc20 Mon Sep 17 00:00:00 2001 From: albertjcuac Date: Mon, 25 Mar 2024 15:54:34 +0100 Subject: [PATCH 01/41] feat: migrating to vue 2.7 sintax and using hybridInject --- .../scroll/components/main-scroll-item.vue | 171 ++++++++++-------- 1 file changed, 93 insertions(+), 78 deletions(-) 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..77aa4f846e 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,14 @@ From 561408c745b5f71cb9719534bbea5bdfb5d459db Mon Sep 17 00:00:00 2001 From: albertjcuac Date: Tue, 26 Mar 2024 09:13:56 +0100 Subject: [PATCH 02/41] chore: add space between doc comments and precious code lines --- .../src/x-modules/scroll/components/main-scroll-item.vue | 3 +++ 1 file changed, 3 insertions(+) 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 77aa4f846e..894cfb87e4 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 @@ -30,6 +30,7 @@ type: Object as PropType, required: true }, + /** * The tag to render. * @@ -44,6 +45,7 @@ setup(props) { useRegisterXModule(scrollXModule); const $x = use$x(); + /** * Rendered HTML node. * @@ -96,6 +98,7 @@ return { el, firstVisibleItemObserver, observeItem }; }, + /** * Initialise scroll behavior. * - Observes the rendered element to detect if it is the first visible item. From 37a33d6e390f0d4bbf6ba800d8ede2a6351c0566 Mon Sep 17 00:00:00 2001 From: albertjcuac Date: Tue, 26 Mar 2024 09:51:05 +0100 Subject: [PATCH 03/41] chore: change @link comment to point to props.item correctly --- .../src/x-modules/scroll/components/main-scroll-item.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 894cfb87e4..c1d529db5f 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 @@ -54,7 +54,7 @@ const el = ref(null); /** - * Pending identifier scroll position to restore. If it matches the {@link MainScrollItem.item} + * Pending identifier scroll position to restore. If it matches the {@link props.item} * `id` property, this component should be scrolled into view. * * @internal From b725dcddcdf707823bf6e07ad14b244c9a109037 Mon Sep 17 00:00:00 2001 From: albertjcuac Date: Tue, 26 Mar 2024 10:07:00 +0100 Subject: [PATCH 04/41] chore: removing @link in docs comment --- .../src/x-modules/scroll/components/main-scroll-item.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c1d529db5f..82eeb0748b 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 @@ -54,7 +54,7 @@ const el = ref(null); /** - * Pending identifier scroll position to restore. If it matches the {@link props.item} + * Pending identifier scroll position to restore. If it matches the item * `id` property, this component should be scrolled into view. * * @internal From bf7e95ae32e2cb44d6505a8960473928eb42664b Mon Sep 17 00:00:00 2001 From: albertjcuac Date: Tue, 26 Mar 2024 11:23:10 +0100 Subject: [PATCH 05/41] feat: use useXBus composable instead of use and fix docs warning --- .../src/x-modules/scroll/components/main-scroll-item.vue | 9 +++++---- .../src/x-modules/scroll/components/main-scroll.vue | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) 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 82eeb0748b..9af8cd4f32 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 @@ -8,9 +8,10 @@ import Vue, { defineComponent, nextTick, PropType, ref } from 'vue'; import { NoElement } from '../../../components'; import { scrollXModule } from '../x-module'; - import { useState, useHybridInject, useRegisterXModule, use$x } from '../../../composables'; + import { useState, useHybridInject, useRegisterXModule } from '../../../composables'; import { ScrollObserverKey } from './scroll.const'; import { ScrollVisibilityObserver } from './scroll.types'; + import { useXBus } from '../../../composables/use-x-bus'; /** * Wrapper for elements contained in the {@link MainScroll} that should store/restore its @@ -44,7 +45,7 @@ setup(props) { useRegisterXModule(scrollXModule); - const $x = use$x(); + const xBus = useXBus(); /** * Rendered HTML node. @@ -54,7 +55,7 @@ const el = ref(null); /** - * Pending identifier scroll position to restore. If it matches the item + * Pending identifier scroll position to restore. If it matches the {@link MainScrollItem} item * `id` property, this component should be scrolled into view. * * @internal @@ -90,7 +91,7 @@ block: 'center' }); }); - $x.emit('ScrollRestoreSucceeded'); + xBus.emit('ScrollRestoreSucceeded'); } } } 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..2cca410fff 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 @@ -90,7 +90,7 @@ protected restoreScrollFailTimeoutId?: number; /** - * Pending identifier scroll position to restore. If it matches the {@link MainScrollItem.item} + * Pending identifier scroll position to restore. If it matches the {@link MainScrollItem} item * `id` property, this component should be scrolled into view. * * @internal From 6504b4b3bb8bf3b96a56bdde97a3fa1e1c09043d Mon Sep 17 00:00:00 2001 From: albertjcuac Date: Wed, 27 Mar 2024 08:44:54 +0100 Subject: [PATCH 06/41] feat: change import order to avoid lint error --- .../src/x-modules/scroll/components/main-scroll-item.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9af8cd4f32..4159da6f81 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 @@ -9,9 +9,9 @@ import { NoElement } from '../../../components'; import { scrollXModule } from '../x-module'; import { useState, useHybridInject, useRegisterXModule } from '../../../composables'; + import { useXBus } from '../../../composables/use-x-bus'; import { ScrollObserverKey } from './scroll.const'; import { ScrollVisibilityObserver } from './scroll.types'; - import { useXBus } from '../../../composables/use-x-bus'; /** * Wrapper for elements contained in the {@link MainScroll} that should store/restore its From 86a9c529de479b0669283e5bb491a2b8b53634ba Mon Sep 17 00:00:00 2001 From: albertjcuac Date: Wed, 27 Mar 2024 16:04:27 +0100 Subject: [PATCH 07/41] feat: getting correctly value and provisional use of any type --- .../scroll/components/main-scroll-item.vue | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 4159da6f81..d02d56a590 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 @@ -52,7 +52,7 @@ * * @public */ - const el = ref(null); + const el = ref(null); /** * Pending identifier scroll position to restore. If it matches the {@link MainScrollItem} item @@ -82,12 +82,12 @@ oldObserver: ScrollVisibilityObserver | null ): void => { { - if (el.value !== null && el.value instanceof HTMLElement) { - oldObserver?.unobserve(el.value); - newObserver?.observe(el.value); + if (el.value !== null) { + oldObserver?.unobserve(el.value.$el); + newObserver?.observe(el.value.$el); if (pendingScrollTo === props.item.id) { Vue.nextTick(() => { - el.value?.scrollIntoView({ + el.value?.$el.scrollIntoView({ block: 'center' }); }); @@ -122,8 +122,8 @@ * @internal */ beforeDestroy() { - if (this.el !== null && this.el instanceof HTMLElement) { - this.firstVisibleItemObserver?.unobserve(this.el); + if (this.el !== null) { + this.firstVisibleItemObserver?.unobserve(this.el.$el); } } }); From cd76aa35100661a8e3998aad175e7f2f555b26be Mon Sep 17 00:00:00 2001 From: albertjcuac Date: Thu, 28 Mar 2024 10:20:59 +0100 Subject: [PATCH 08/41] feat: create ElementRef interface to avoid use of any --- .../src/x-modules/scroll/components/main-scroll-item.vue | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 d02d56a590..3ea689bed4 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 @@ -44,6 +44,9 @@ }, setup(props) { + interface ElementRef { + $el: HTMLElement; + } useRegisterXModule(scrollXModule); const xBus = useXBus(); @@ -52,7 +55,7 @@ * * @public */ - const el = ref(null); + const el = ref(null); /** * Pending identifier scroll position to restore. If it matches the {@link MainScrollItem} item From 3d55c2ac22fe89ecbc33fd1e6582a7e02ddec3a8 Mon Sep 17 00:00:00 2001 From: albertjcuac Date: Tue, 2 Apr 2024 13:38:32 +0200 Subject: [PATCH 09/41] feat: use of native inject instead of hybrid inject --- .../scroll/components/main-scroll-item.vue | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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 3ea689bed4..2697e861c6 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 @@ -5,10 +5,10 @@ From 23781731eaa71f8f0c8d552449c0e9e692445233 Mon Sep 17 00:00:00 2001 From: Laura Martinez Garcia Date: Wed, 10 Apr 2024 15:34:47 +0200 Subject: [PATCH 12/41] feat: migrate main-scroll to composition api syntax --- .../scroll/components/main-scroll.vue | 474 ++++++++++-------- .../tests/unit/main-scroll.spec.ts | 5 +- 2 files changed, 260 insertions(+), 219 deletions(-) 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 2cca410fff..91602d6222 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,26 @@ diff --git a/packages/x-components/tests/unit/main-scroll.spec.ts b/packages/x-components/tests/unit/main-scroll.spec.ts index 802025c260..85782f8a35 100644 --- a/packages/x-components/tests/unit/main-scroll.spec.ts +++ b/packages/x-components/tests/unit/main-scroll.spec.ts @@ -8,6 +8,7 @@ import MainScroll from '../../src/x-modules/scroll/components/main-scroll.vue'; import { scrollXModule } from '../../src/x-modules/scroll/x-module'; import { e2eAdapter } from '../../src/adapter/e2e-adapter'; import { XDummyBus } from '../../src/__tests__/bus.dummy'; +import { bus } from '../../src/plugins/x-bus'; import { loadCss } from './css.utils'; /** @@ -87,9 +88,9 @@ function renderMainScroll({ }; }, beforeCreate() { - XPlugin.bus.on('UserScrolledToElement').subscribe(userScrolledToElementSpy); + bus.on('UserScrolledToElement').subscribe(userScrolledToElementSpy); if (pendingScroll) { - XPlugin.bus.emit('ParamsLoadedFromUrl', { scroll: `item-${pendingScroll}` }); + bus.emit('ParamsLoadedFromUrl', { scroll: `item-${pendingScroll}` }); } } }, From 19580d7b0deae72113189446d53e95d89c2934fc Mon Sep 17 00:00:00 2001 From: Laura Martinez Garcia Date: Thu, 11 Apr 2024 09:19:26 +0200 Subject: [PATCH 13/41] chore: fix pendingScrollTo watcher --- .../x-modules/scroll/components/main-scroll.vue | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) 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 91602d6222..328ff63eb2 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 @@ -4,17 +4,7 @@ + + + + diff --git a/packages/_vue3-migration-test/src/router.ts b/packages/_vue3-migration-test/src/router.ts index 9ec37cfd11..638414a14f 100644 --- a/packages/_vue3-migration-test/src/router.ts +++ b/packages/_vue3-migration-test/src/router.ts @@ -1,4 +1,5 @@ import { createRouter, createWebHistory } from 'vue-router'; +import TestScroll from './components/scroll/test-scroll.vue'; import { TestAnimateWidth, TestFade } from './'; const routes = [ @@ -11,6 +12,11 @@ const routes = [ path: '/fade', name: 'Fade', component: TestFade + }, + { + path: '/scroll', + name: 'Scroll', + component: TestScroll } ]; diff --git a/packages/x-components/src/components/no-element.ts b/packages/x-components/src/components/no-element.ts index f46bb96a6e..ba4daaebb3 100644 --- a/packages/x-components/src/components/no-element.ts +++ b/packages/x-components/src/components/no-element.ts @@ -1,5 +1,5 @@ import { defineComponent } from 'vue'; -import { useNoElementRender } from '../composables/index'; +import { useNoElementRender } from '../composables/use-no-element-render'; /** * The purpose of this Component is to use as default value for props that receive a Component that 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 b06110ff20..50268f59c4 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 @@ -18,9 +18,10 @@ WatchCallback, ComputedRef } from 'vue'; - import { NoElement } from '../../../components'; + import { NoElement } from '../../../components/no-element'; import { scrollXModule } from '../x-module'; - import { useState, useRegisterXModule } from '../../../composables'; + import { useState } from '../../../composables/use-state'; + import { useRegisterXModule } from '../../../composables/use-register-x-module'; import { useXBus } from '../../../composables/use-x-bus'; import { ScrollObserverKey } from './scroll.const'; import { ScrollVisibilityObserver } from './scroll.types'; 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 120430a0ae..e30bdbf1f1 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 @@ -6,10 +6,11 @@