From 94bef73d1725a9f7f6d4b7fa165bef62838f5460 Mon Sep 17 00:00:00 2001 From: Edie Lemoine Date: Wed, 20 Nov 2024 17:17:43 +0100 Subject: [PATCH] refactor: replace get with toValue --- apps/admin-component-tests/package.json | 9 ++- apps/admin-components.shim.ts | 49 ++++++------ apps/admin-preset-dashicons/package.json | 2 +- apps/admin/package.json | 3 +- .../executors/resolveOrderParameters.ts | 4 +- .../OrderBox/OrderShipmentsTable.vue | 5 +- .../OrderBox/ShipmentOptionsBox.vue | 7 +- .../components/OrderBox/ShipmentTableBox.vue | 10 +-- .../ShipmentModeOrderListItem.vue | 7 +- .../PluginSettings/AccountSettings.vue | 12 +-- .../PluginSettings/EditApiKeyForm.vue | 5 +- .../PluginSettings/PluginSettingsForms.vue | 9 +-- .../PluginSettings/WebhooksStatus.vue | 7 +- .../common/DeliveryOptionsExcerpt.vue | 7 +- .../DeliveryOptionsExcerptCarrierName.vue | 5 +- .../common/DeliveryOptionsPackageType.vue | 21 +++-- .../components/common/ShipmentOptionsForm.vue | 6 +- .../modals/ShipmentOptionsModal.vue | 9 +-- .../modals/ShipmentOptionsModalForm.vue | 7 +- .../components/useDropdownButtonContext.ts | 5 +- .../components/useInputWithOptionsContext.ts | 7 +- .../components/useRadioGroupContext.ts | 7 +- .../components/useToggleInputContext.ts | 5 +- .../components/useTriStateInputContext.ts | 9 +-- .../src/composables/context/useContext.ts | 4 +- .../src/composables/orders/useOrderData.ts | 9 ++- .../composables/products/useProductData.ts | 5 +- .../composables/shipments/useShipmentData.ts | 10 +-- .../src/composables/useDigitalStampRanges.ts | 8 +- .../form-builder/utils/createValueGetter.ts | 4 +- .../forms/helpers/triStateFieldIsEnabled.ts | 4 +- .../src/forms/helpers/updateFieldsDefaults.ts | 4 +- .../fields/createCarrierField.ts | 8 +- .../fields/createDigitalStampRangeField.ts | 5 +- apps/admin/src/stores/useQueryStore.ts | 6 +- apps/admin/src/utils/getOrderShipmentIds.ts | 5 +- apps/admin/src/views/OrderBox.vue | 7 +- apps/admin/src/views/OrderListItem.vue | 5 +- apps/admin/src/views/PluginSettings.vue | 5 +- apps/admin/src/views/ProductSettings.vue | 12 ++- yarn.lock | 79 +------------------ 41 files changed, 154 insertions(+), 243 deletions(-) diff --git a/apps/admin-component-tests/package.json b/apps/admin-component-tests/package.json index 74f12cc8f..86eb9964f 100644 --- a/apps/admin-component-tests/package.json +++ b/apps/admin-component-tests/package.json @@ -19,16 +19,16 @@ "./dist" ], "scripts": { - "build": "run ws:ts:build \"$(pwd)\"", + "build": "run ws:vue:build \"$(pwd)\"", "clean": "run ws:clean \"$(pwd)\"", - "emit": "run ws:ts:emit \"$(pwd)\"", + "emit": "run ws:vue:emit \"$(pwd)\"", "lint": "run ws:lint \"$(pwd)\"", "lint:fix": "run ws:lint:fix \"$(pwd)\"", "test": "run ws:test \"$(pwd)\"", "test:coverage": "run ws:test:coverage \"$(pwd)\"", "test:run": "run ws:test:run \"$(pwd)\"", "test:update": "run ws:test:update \"$(pwd)\"", - "typecheck": "run ws:ts:typecheck \"$(pwd)\"" + "typecheck": "run ws:vue:typecheck \"$(pwd)\"" }, "dependencies": { "@myparcel-pdk/admin": "workspace:^1.5.3", @@ -43,7 +43,8 @@ "devDependencies": { "typescript": "^5.2.2", "vitest": "^2.1.3", - "vue": "^3.3.0" + "vue": "^3.3.0", + "vue-tsc": "^2.0.0" }, "peerDependencies": { "vue": "^3" diff --git a/apps/admin-components.shim.ts b/apps/admin-components.shim.ts index 948f8cb10..c98b5a3d4 100644 --- a/apps/admin-components.shim.ts +++ b/apps/admin-components.shim.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention,@typescript-eslint/ban-types,@typescript-eslint/no-unnecessary-type-arguments,@typescript-eslint/no-explicit-any */ +// noinspection ES6PreferShortImport import { type ComponentOptionsMixin, @@ -20,21 +21,11 @@ import { type ButtonGroupSlots, type ButtonProps, type ButtonSlots, - type CheckboxGroupEmits, - type CheckboxGroupProps, - type CheckboxInputEmits, - type CheckboxInputProps, - type CodeEditorEmits, - type CodeEditorProps, type ColProps, type ColSlots, type ConceptBoxWrapperProps, - type CurrencyInputEmits, - type CurrencyInputProps, type DropdownButtonProps, type DropdownButtonSlots, - type DropOffInputEmits, - type DropOffInputProps, type FormGroupProps, type FormGroupSlots, type HeadingProps, @@ -47,25 +38,13 @@ import { type LoaderProps, type ModalProps, type ModalSlots, - type MultiSelectInputEmits, - type MultiSelectInputProps, type NotificationProps, - type NumberInputEmits, - type NumberInputProps, type PluginSettingsWrapperProps, - type RadioGroupEmits, - type RadioGroupProps, - type RadioInputEmits, - type RadioInputProps, type RowProps, type RowSlots, - type SelectInputEmits, - type SelectInputProps, type SettingsDividerProps, type ShipmentLabelWrapperProps, type ShipmentLabelWrapperSlots, - type ShippingMethodsInputEmits, - type ShippingMethodsInputProps, type TableColProps, type TableColSlots, type TableProps, @@ -78,6 +57,30 @@ import { type TabNavButtonWrapperSlots, type TabNavContentWrapperProps, type TabNavContentWrapperSlots, +} from './admin/src/types/components.types'; +import { + type CheckboxGroupEmits, + type CheckboxGroupProps, + type CheckboxInputEmits, + type CheckboxInputProps, + type CodeEditorEmits, + type CodeEditorProps, + type CurrencyInputEmits, + type CurrencyInputProps, + type DropOffInputEmits, + type DropOffInputProps, + type MultiSelectInputEmits, + type MultiSelectInputProps, + type NumberInputEmits, + type NumberInputProps, + type RadioGroupEmits, + type RadioGroupProps, + type RadioInputEmits, + type RadioInputProps, + type SelectInputEmits, + type SelectInputProps, + type ShippingMethodsInputEmits, + type ShippingMethodsInputProps, type TextAreaEmits, type TextAreaProps, type TextInputEmits, @@ -88,7 +91,7 @@ import { type ToggleInputProps, type TriStateInputEmits, type TriStateInputProps, -} from './admin/src/types'; +} from './admin/src/types/components-form.types'; /** * @note This file should NOT be imported. Its purpose is to resolve the global pdk components in your IDE. diff --git a/apps/admin-preset-dashicons/package.json b/apps/admin-preset-dashicons/package.json index f50768e40..54206b318 100644 --- a/apps/admin-preset-dashicons/package.json +++ b/apps/admin-preset-dashicons/package.json @@ -37,7 +37,7 @@ "@myparcel-pdk/build-vite": "workspace:*", "typescript": "^5.2.2", "vitest": "^2.1.3", - "vue-tsc": "^1.8.0" + "vue-tsc": "^2.0.0" }, "engines": { "node": ">=20" diff --git a/apps/admin/package.json b/apps/admin/package.json index 1356d9884..74c5d8122 100644 --- a/apps/admin/package.json +++ b/apps/admin/package.json @@ -55,8 +55,7 @@ "@vue/test-utils": "^2.0.0", "typescript": "^5.2.2", "vite": "^5.4.10", - "vitest": "^2.1.3", - "vue-tsc": "^2.0.0" + "vitest": "^2.1.3" }, "engines": { "node": ">=20" diff --git a/apps/admin/src/actions/executors/resolveOrderParameters.ts b/apps/admin/src/actions/executors/resolveOrderParameters.ts index 5bcc90795..baf88751d 100644 --- a/apps/admin/src/actions/executors/resolveOrderParameters.ts +++ b/apps/admin/src/actions/executors/resolveOrderParameters.ts @@ -1,4 +1,4 @@ -import {get} from '@vueuse/core'; +import {toValue} from 'vue'; import {useFormBuilder} from '@myparcel/vue-form-builder'; import {createShipmentFormName, getOrderId} from '../../utils'; import {type ActionParameters, type OrderAction} from '../../types'; @@ -13,7 +13,7 @@ export const resolveOrderParameters = ({ parameters.orderIds ??= getOrderId(instance); // @ts-expect-error todo - parameters.form ??= get(formBuilder.forms)?.[createShipmentFormName(parameters.orderIds)]; + parameters.form ??= toValue(formBuilder.forms)?.[createShipmentFormName(parameters.orderIds)]; return Promise.resolve(parameters as ActionParameters); }; diff --git a/apps/admin/src/components/OrderBox/OrderShipmentsTable.vue b/apps/admin/src/components/OrderBox/OrderShipmentsTable.vue index a47b9d186..8ea8f372d 100644 --- a/apps/admin/src/components/OrderBox/OrderShipmentsTable.vue +++ b/apps/admin/src/components/OrderBox/OrderShipmentsTable.vue @@ -35,8 +35,7 @@ diff --git a/apps/admin/src/components/OrderBox/ShipmentTableBox.vue b/apps/admin/src/components/OrderBox/ShipmentTableBox.vue index ca100022e..8064b2c5c 100644 --- a/apps/admin/src/components/OrderBox/ShipmentTableBox.vue +++ b/apps/admin/src/components/OrderBox/ShipmentTableBox.vue @@ -23,14 +23,14 @@ - diff --git a/apps/admin/src/components/common/DeliveryOptionsExcerptCarrierName.vue b/apps/admin/src/components/common/DeliveryOptionsExcerptCarrierName.vue index 9e6042686..f0382d6b3 100644 --- a/apps/admin/src/components/common/DeliveryOptionsExcerptCarrierName.vue +++ b/apps/admin/src/components/common/DeliveryOptionsExcerptCarrierName.vue @@ -7,8 +7,7 @@ diff --git a/apps/admin/src/components/common/DeliveryOptionsPackageType.vue b/apps/admin/src/components/common/DeliveryOptionsPackageType.vue index da964abdd..831c06b2a 100644 --- a/apps/admin/src/components/common/DeliveryOptionsPackageType.vue +++ b/apps/admin/src/components/common/DeliveryOptionsPackageType.vue @@ -1,31 +1,30 @@ diff --git a/apps/admin/src/components/common/ShipmentOptionsForm.vue b/apps/admin/src/components/common/ShipmentOptionsForm.vue index 6bb597e65..fe10ccf48 100644 --- a/apps/admin/src/components/common/ShipmentOptionsForm.vue +++ b/apps/admin/src/components/common/ShipmentOptionsForm.vue @@ -5,8 +5,8 @@ diff --git a/apps/admin/src/components/modals/ShipmentOptionsModal.vue b/apps/admin/src/components/modals/ShipmentOptionsModal.vue index 215051649..6d851e87f 100644 --- a/apps/admin/src/components/modals/ShipmentOptionsModal.vue +++ b/apps/admin/src/components/modals/ShipmentOptionsModal.vue @@ -12,9 +12,9 @@ diff --git a/apps/admin/src/composables/components/useDropdownButtonContext.ts b/apps/admin/src/composables/components/useDropdownButtonContext.ts index 9eadb6d5f..c76e358cf 100644 --- a/apps/admin/src/composables/components/useDropdownButtonContext.ts +++ b/apps/admin/src/composables/components/useDropdownButtonContext.ts @@ -1,5 +1,4 @@ -import {computed, type ComputedRef, type Ref, ref, toRefs} from 'vue'; -import {get} from '@vueuse/core'; +import {computed, type ComputedRef, type Ref, ref, toRefs, toValue} from 'vue'; import {partitionArray} from '@myparcel/ts-utils'; import {type ActionDefinition, type DropdownButtonProps} from '../../types'; import {AdminIcon} from '../../data'; @@ -24,7 +23,7 @@ export const useDropdownButtonContext = (props: DropdownButtonProps): DropdownDa return { dropdownActions: computed(() => { - const [standalone, hidden] = partitionArray(get(propRefs.actions), (action) => action.standalone === true); + const [standalone, hidden] = partitionArray(toValue(propRefs.actions), (action) => action.standalone === true); return { standalone, diff --git a/apps/admin/src/composables/components/useInputWithOptionsContext.ts b/apps/admin/src/composables/components/useInputWithOptionsContext.ts index fd8bf4e1c..62cbf71ab 100644 --- a/apps/admin/src/composables/components/useInputWithOptionsContext.ts +++ b/apps/admin/src/composables/components/useInputWithOptionsContext.ts @@ -1,5 +1,4 @@ -import {onMounted, watch, type WritableComputedRef} from 'vue'; -import {get} from '@vueuse/core'; +import {onMounted, toValue, watch, type WritableComputedRef} from 'vue'; import {toArray} from '@myparcel/ts-utils'; import {type ArrayItem, type SelectInputEmits, type SelectInputModelValue, type SelectInputProps} from '../../types'; import {type ElementOptionsContext, useElementOptions} from './useElementOptions'; @@ -29,7 +28,7 @@ export const useInputWithOptionsContext = < watch( options, (newOptions) => { - const values = toArray(get(model)); + const values = toArray(toValue(model)); const hasExistingValue = values.length && newOptions.some((option) => values.includes(option.value as ModelValue)); @@ -39,7 +38,7 @@ export const useInputWithOptionsContext = < model.value = (multiple ? [newOptions[0].value] : newOptions[0].value) as ModelValue; }, - {immediate: Number(get(options)?.length) > 0}, + {immediate: Number(toValue(options)?.length) > 0}, ); }); diff --git a/apps/admin/src/composables/components/useRadioGroupContext.ts b/apps/admin/src/composables/components/useRadioGroupContext.ts index 5cfb01ed7..e65de4a3e 100644 --- a/apps/admin/src/composables/components/useRadioGroupContext.ts +++ b/apps/admin/src/composables/components/useRadioGroupContext.ts @@ -1,5 +1,4 @@ -import {computed, type ComputedRef, type WritableComputedRef} from 'vue'; -import {get} from '@vueuse/core'; +import {computed, type ComputedRef, toValue, type WritableComputedRef} from 'vue'; import {isOfType} from '@myparcel/ts-utils'; import {createFormElement, createObjectWithKeys} from '../../utils'; import { @@ -30,10 +29,10 @@ export const useRadioGroupContext = < const context = useInputWithOptionsContext(props, emit); const elements = computed(() => { - const optionValues = (get(context.options) ?? []).map((option) => option.value); + const optionValues = (toValue(context.options) ?? []).map((option) => option.value); return createObjectWithKeys(optionValues, (value) => { - const option = (get(context.options) ?? []).find((option) => option.value === value) as SelectOption; + const option = (toValue(context.options) ?? []).find((option) => option.value === value) as SelectOption; return createFormElement({ ref: context.model, diff --git a/apps/admin/src/composables/components/useToggleInputContext.ts b/apps/admin/src/composables/components/useToggleInputContext.ts index 11633d1c6..ea4675e19 100644 --- a/apps/admin/src/composables/components/useToggleInputContext.ts +++ b/apps/admin/src/composables/components/useToggleInputContext.ts @@ -1,5 +1,4 @@ -import {ref, type Ref, watch, type WritableComputedRef} from 'vue'; -import {get} from '@vueuse/core'; +import {ref, type Ref, toValue, watch, type WritableComputedRef} from 'vue'; import {booleanToTriState, triStateToBoolean} from '../../utils'; import {type ToggleInputEmits, type ToggleInputModelValue, type ToggleInputProps} from '../../types'; import {useElementContext} from './useElementContext'; @@ -14,7 +13,7 @@ interface ToggleInputContext { type UseToggleInputContext = (props: ToggleInputProps, emit: ToggleInputEmits) => ToggleInputContext; export const useToggleInputContext: UseToggleInputContext = (props, emit) => { - const toggleModel = ref(triStateToBoolean(get(props.modelValue))); + const toggleModel = ref(triStateToBoolean(toValue(props.modelValue))); const {id, model} = useElementContext(props, emit); // When the toggle is changed, the model is updated to 1/0 diff --git a/apps/admin/src/composables/components/useTriStateInputContext.ts b/apps/admin/src/composables/components/useTriStateInputContext.ts index 304f6904d..80f78fa30 100644 --- a/apps/admin/src/composables/components/useTriStateInputContext.ts +++ b/apps/admin/src/composables/components/useTriStateInputContext.ts @@ -1,5 +1,4 @@ -import {computed, markRaw, reactive, ref, type Ref, watch, type WritableComputedRef} from 'vue'; -import {get} from '@vueuse/core'; +import {computed, markRaw, reactive, ref, type Ref, toValue, watch, type WritableComputedRef} from 'vue'; import {TriState} from '@myparcel-pdk/common'; import {type AnyElementConfiguration, defineField, useForm} from '@myparcel/vue-form-builder'; import {useLanguage} from '../language'; @@ -34,8 +33,8 @@ export const useTriStateInputContext: UseTriStateInputContext = (props, emit) => const {translate} = useLanguage(); const form = useForm(); - const inheritModel = ref(TriState.Inherit === get(props.modelValue)); - const toggleModel = ref(triStateToBoolean(get(props.modelValue))); + const inheritModel = ref(TriState.Inherit === toValue(props.modelValue)); + const toggleModel = ref(triStateToBoolean(toValue(props.modelValue))); const {id, model} = useElementContext(props, emit); @@ -70,7 +69,7 @@ export const useTriStateInputContext: UseTriStateInputContext = (props, emit) => name: `${props.element.name}__toggle`, ref: toggleModel, // The toggle is readonly when inherit is enabled or the element itself is set to readonly. - isReadOnly: markRaw(computed(() => get(inheritModel) || get(props.element.isReadOnly))), + isReadOnly: markRaw(computed(() => toValue(inheritModel) || toValue(props.element.isReadOnly))), }), ); diff --git a/apps/admin/src/composables/context/useContext.ts b/apps/admin/src/composables/context/useContext.ts index 9a5808acb..a9c9f0641 100644 --- a/apps/admin/src/composables/context/useContext.ts +++ b/apps/admin/src/composables/context/useContext.ts @@ -1,4 +1,4 @@ -import {get} from '@vueuse/core'; +import {toValue} from 'vue'; import {AdminContextKey} from '@myparcel-pdk/common'; import {useStoreContextQuery} from '../useStoreContextQuery'; import {type AdminContext} from '../../types'; @@ -8,7 +8,7 @@ export const useContext = ( contextKey: C = AdminContextKey.Dynamic, ): NonNullable> => { const query = useStoreContextQuery(contextKey); - const data = get(query.data); + const data = toValue(query.data); if (!data) { throw new Error(`Context ${contextKey} not found`); diff --git a/apps/admin/src/composables/orders/useOrderData.ts b/apps/admin/src/composables/orders/useOrderData.ts index b2487c04a..1dc0234d4 100644 --- a/apps/admin/src/composables/orders/useOrderData.ts +++ b/apps/admin/src/composables/orders/useOrderData.ts @@ -1,5 +1,4 @@ -import {computed, type ComputedRef} from 'vue'; -import {get} from '@vueuse/core'; +import {computed, type ComputedRef, toValue} from 'vue'; import {type BackendEndpoint} from '@myparcel-pdk/common'; import {getOrderId, validateId} from '../../utils'; import {type ResolvedQuery, useQueryStore} from '../../stores'; @@ -21,8 +20,10 @@ export const useOrderData = (externalIdentifier?: string): UseOrderData => { const allQueries = queryStore.getQueriesForOrder(orderId); return { - loading: computed(() => Object.values(get(allQueries)).some((item) => (item ? get(item.isLoading) : false))), - order: computed(() => get(fetchQuery.data)), + loading: computed(() => { + return Object.values(toValue(allQueries)).some((item) => (item ? toValue(item.isLoading) : false)); + }), + order: computed(() => toValue(fetchQuery.data)), query: fetchQuery, }; }; diff --git a/apps/admin/src/composables/products/useProductData.ts b/apps/admin/src/composables/products/useProductData.ts index aa30ee932..7c7580ebc 100644 --- a/apps/admin/src/composables/products/useProductData.ts +++ b/apps/admin/src/composables/products/useProductData.ts @@ -1,5 +1,4 @@ -import {computed, type ComputedRef} from 'vue'; -import {get} from '@vueuse/core'; +import {computed, type ComputedRef, toValue} from 'vue'; import {BackendEndpoint} from '@myparcel-pdk/common'; import {useStoreQuery} from '../useStoreQuery'; import {useInstanceContext} from '../context'; @@ -18,7 +17,7 @@ export const useProductData = (externalIdentifier?: string): UseProductData => { const fetchQuery = useStoreQuery(BackendEndpoint.FetchProducts, productId); return { - product: computed(() => get(fetchQuery.data)), + product: computed(() => toValue(fetchQuery.data)), query: fetchQuery, }; }; diff --git a/apps/admin/src/composables/shipments/useShipmentData.ts b/apps/admin/src/composables/shipments/useShipmentData.ts index 7ac2877cf..5d9bfc38d 100644 --- a/apps/admin/src/composables/shipments/useShipmentData.ts +++ b/apps/admin/src/composables/shipments/useShipmentData.ts @@ -1,5 +1,5 @@ -import {computed, type ComputedRef, type Ref, ref, unref} from 'vue'; -import {get, type MaybeRef} from '@vueuse/core'; +import {computed, type ComputedRef, type Ref, ref, toValue, unref} from 'vue'; +import {type MaybeRef} from '@vueuse/core'; import {type Shipment} from '@myparcel-pdk/common'; import {type Carrier} from '@myparcel/sdk'; import {type AnyActionDefinition} from '../../types'; @@ -23,9 +23,9 @@ export const useShipmentData = (id: MaybeRef): UseShipmentData => { const fetchQuery = useShipment(shipmentId); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const shipment = computed(() => get(fetchQuery.data)!); + const shipment = computed(() => toValue(fetchQuery.data)!); - const orderId = get(shipment)?.orderId; + const orderId = toValue(shipment)?.orderId; const allQueries = [ queryStore.getQueriesForShipment(shipmentId), @@ -44,7 +44,7 @@ export const useShipmentData = (id: MaybeRef): UseShipmentData => { carrier: carriersQuery?.data ?? ref(), loading: computed(() => { return allQueries.some((obj) => - Object.values(get(obj) ?? {}).some((item) => (item ? get(item.isLoading) : false)), + Object.values(toValue(obj) ?? {}).some((item) => (item ? toValue(item.isLoading) : false)), ); }), shipment, diff --git a/apps/admin/src/composables/useDigitalStampRanges.ts b/apps/admin/src/composables/useDigitalStampRanges.ts index 52b38b019..8b267342d 100644 --- a/apps/admin/src/composables/useDigitalStampRanges.ts +++ b/apps/admin/src/composables/useDigitalStampRanges.ts @@ -1,5 +1,5 @@ -import {computed, type ComputedRef} from 'vue'; -import {get, type MaybeRef} from '@vueuse/core'; +import {computed, type ComputedRef, toValue} from 'vue'; +import {type MaybeRef} from '@vueuse/core'; import {type Plugin} from '@myparcel-pdk/common'; import {type SelectOptionWithPlainLabel} from '../types'; import {useOrderData} from './orders'; @@ -14,7 +14,7 @@ export const useDigitalStampRanges = (weight: MaybeRef): UseDigitalStamp // todo: move this to global context const {order} = useOrderData(); - const allRanges = computed(() => get(order).digitalStampRanges ?? []); + const allRanges = computed(() => toValue(order).digitalStampRanges ?? []); const ranges = computed[]>(() => { return allRanges.value.map((range) => ({ @@ -24,7 +24,7 @@ export const useDigitalStampRanges = (weight: MaybeRef): UseDigitalStamp }); const currentRange = computed(() => { - const resolvedWeight = get(weight); + const resolvedWeight = toValue(weight); const matchingRange = allRanges.value.find((range) => range.min <= resolvedWeight && range.max >= resolvedWeight); diff --git a/apps/admin/src/forms/form-builder/utils/createValueGetter.ts b/apps/admin/src/forms/form-builder/utils/createValueGetter.ts index 9ecab8cb7..a1e3a689d 100644 --- a/apps/admin/src/forms/form-builder/utils/createValueGetter.ts +++ b/apps/admin/src/forms/form-builder/utils/createValueGetter.ts @@ -1,4 +1,4 @@ -import {get} from '@vueuse/core'; +import {toValue} from 'vue'; import {type InteractiveElementInstance} from '@myparcel/vue-form-builder'; import {type AnyVal} from '../types'; @@ -11,6 +11,6 @@ export const createValueGetter = (instance: InteractiveElementInstance, prefix: } // @ts-expect-error todo - return get(instance.ref); + return toValue(instance.ref); }; }; diff --git a/apps/admin/src/forms/helpers/triStateFieldIsEnabled.ts b/apps/admin/src/forms/helpers/triStateFieldIsEnabled.ts index debeb7c4f..9db302781 100644 --- a/apps/admin/src/forms/helpers/triStateFieldIsEnabled.ts +++ b/apps/admin/src/forms/helpers/triStateFieldIsEnabled.ts @@ -1,4 +1,4 @@ -import {get} from '@vueuse/core'; +import {toValue} from 'vue'; import {TriState} from '@myparcel-pdk/common'; import {type FormInstance} from '@myparcel/vue-form-builder'; import {type ElementInstance, type TriStateInputProps} from '../../types'; @@ -10,7 +10,7 @@ export const triStateFieldIsEnabled = (form: FormInstance, fieldName: string): b return false; } - const value = get(field.ref); + const value = toValue(field.ref); if (TriState.Inherit === value) { return TriState.On === field.props.defaultValue; diff --git a/apps/admin/src/forms/helpers/updateFieldsDefaults.ts b/apps/admin/src/forms/helpers/updateFieldsDefaults.ts index d0ef461d3..626830993 100644 --- a/apps/admin/src/forms/helpers/updateFieldsDefaults.ts +++ b/apps/admin/src/forms/helpers/updateFieldsDefaults.ts @@ -1,5 +1,5 @@ +import {toValue} from 'vue'; import {get as lodashGet} from 'lodash-unified'; -import {get} from '@vueuse/core'; import {type Shipment} from '@myparcel-pdk/common'; import {type InteractiveElementInstance} from '@myparcel/vue-form-builder'; @@ -11,7 +11,7 @@ export const updateFieldsDefaults = ( {form, name}: InteractiveElementInstance, inheritedDeliveryOptions: Record, ): void => { - (get(form.fields) as InteractiveElementInstance[]).forEach((otherField) => { + (toValue(form.fields) as InteractiveElementInstance[]).forEach((otherField) => { if (otherField.name === name) { return; } diff --git a/apps/admin/src/forms/shipmentOptions/fields/createCarrierField.ts b/apps/admin/src/forms/shipmentOptions/fields/createCarrierField.ts index 11dcdba99..5748c08cd 100644 --- a/apps/admin/src/forms/shipmentOptions/fields/createCarrierField.ts +++ b/apps/admin/src/forms/shipmentOptions/fields/createCarrierField.ts @@ -1,4 +1,4 @@ -import {get} from '@vueuse/core'; +import {toValue} from 'vue'; import {AdminContextKey, type Plugin} from '@myparcel-pdk/common'; import {type InteractiveElementConfiguration} from '@myparcel/vue-form-builder'; import {PackageTypeName} from '@myparcel/constants'; @@ -46,7 +46,7 @@ export const createCarrierField = ( const query = useFetchCarrier(carrier.name); await query.suspense(); - const apiCarrier = get(query.data); + const apiCarrier = toValue(query.data); let plainLabel = apiCarrier?.human ?? carrier.human ?? ''; @@ -64,9 +64,9 @@ export const createCarrierField = ( setFieldProp(field, PROP_OPTIONS, carrierSelectOptions); - await field?.afterUpdate?.(field, get(field.ref), undefined); + await field?.afterUpdate?.(field, toValue(field.ref), undefined); - updateFieldsDefaults(get(field.ref) as string, field, inheritedDeliveryOptions); + updateFieldsDefaults(toValue(field.ref) as string, field, inheritedDeliveryOptions); }, afterUpdate: (field, newCarrier: string) => { diff --git a/apps/admin/src/forms/shipmentOptions/fields/createDigitalStampRangeField.ts b/apps/admin/src/forms/shipmentOptions/fields/createDigitalStampRangeField.ts index e96a3312a..b891d2ee6 100644 --- a/apps/admin/src/forms/shipmentOptions/fields/createDigitalStampRangeField.ts +++ b/apps/admin/src/forms/shipmentOptions/fields/createDigitalStampRangeField.ts @@ -1,6 +1,5 @@ -import {ref} from 'vue'; +import {ref, toValue} from 'vue'; import {get} from 'lodash-unified'; -import {get as vuGet} from '@vueuse/core'; import {TriState} from '@myparcel-pdk/common'; import {type InteractiveElementConfiguration} from '@myparcel/vue-form-builder'; import {PackageTypeName} from '@myparcel/constants'; @@ -15,7 +14,7 @@ export const createDigitalStampRangeField = (refs: ShipmentOptionsRefs): Interac const pluginSettings = usePluginSettings(); const {order} = useOrderData(); - const orderData = vuGet(order); + const orderData = toValue(order); const {initialWeight, manualWeight} = orderData?.physicalProperties ?? {}; diff --git a/apps/admin/src/stores/useQueryStore.ts b/apps/admin/src/stores/useQueryStore.ts index 19c879740..94cad0f63 100644 --- a/apps/admin/src/stores/useQueryStore.ts +++ b/apps/admin/src/stores/useQueryStore.ts @@ -1,6 +1,6 @@ -import {computed, type ComputedRef, type Ref, ref, unref} from 'vue'; +import {computed, type ComputedRef, type Ref, ref, toValue, unref} from 'vue'; import {defineStore} from 'pinia'; -import {get as vuGet, type MaybeRef} from '@vueuse/core'; +import {type MaybeRef} from '@vueuse/core'; import {type QueryClient, useQueryClient} from '@tanstack/vue-query'; import {AdminContextKey, BackendEndpoint} from '@myparcel-pdk/common'; import {type OneOrMore, toArray} from '@myparcel/ts-utils'; @@ -136,7 +136,7 @@ export const useQueryStore = defineStore('query', () => { toArray(id).forEach((orderId) => { const ordersQuery = register(BackendEndpoint.FetchOrders, orderId, useFetchOrdersQuery(orderId)); - vuGet(ordersQuery.data)?.shipments?.forEach((shipment) => registerShipmentQueries(shipment.id, orderId)); + toValue(ordersQuery.data)?.shipments?.forEach((shipment) => registerShipmentQueries(shipment.id, orderId)); register(BackendEndpoint.FetchOrders, orderId, useFetchOrdersQuery(orderId)); register(BackendEndpoint.ExportOrders, orderId, useExportOrdersMutation(orderId, mode)); register(BackendEndpoint.PrintOrders, orderId, usePrintOrdersMutation(orderId)); diff --git a/apps/admin/src/utils/getOrderShipmentIds.ts b/apps/admin/src/utils/getOrderShipmentIds.ts index 901ff2af4..6bae3035a 100644 --- a/apps/admin/src/utils/getOrderShipmentIds.ts +++ b/apps/admin/src/utils/getOrderShipmentIds.ts @@ -1,10 +1,11 @@ -import {get, isDef} from '@vueuse/core'; +import {toValue} from 'vue'; +import {isDef} from '@vueuse/core'; import {type OrderIds} from '../types'; import {useOrdersData} from '../composables'; export const getOrderShipmentIds = (orderIds: OrderIds): number[] => { return useOrdersData(orderIds) - .map(({order}) => get(order)?.shipments) + .map(({order}) => toValue(order)?.shipments) .flat() .filter(isDef) .map((shipment) => shipment.id); diff --git a/apps/admin/src/views/OrderBox.vue b/apps/admin/src/views/OrderBox.vue index afb9e8a03..076860d09 100644 --- a/apps/admin/src/views/OrderBox.vue +++ b/apps/admin/src/views/OrderBox.vue @@ -1,12 +1,11 @@ diff --git a/apps/admin/src/views/OrderListItem.vue b/apps/admin/src/views/OrderListItem.vue index bb6ec258b..daf8550af 100644 --- a/apps/admin/src/views/OrderListItem.vue +++ b/apps/admin/src/views/OrderListItem.vue @@ -14,8 +14,7 @@ /** * This is the main entry point for the order list column. */ -import {defineAsyncComponent} from 'vue'; -import {get} from '@vueuse/core'; +import {defineAsyncComponent, toValue} from 'vue'; import {type NotificationFilter} from '../types'; import {useActionStore, useQueryStore} from '../stores'; import {NotificationCategory} from '../data'; @@ -48,6 +47,6 @@ const {orderMode} = pluginSettings.order; const {query} = useOrderData(); const notificationFilter: NotificationFilter = (notification) => { - return notification.tags?.orderIds === get(query.data)?.externalIdentifier; + return notification.tags?.orderIds === toValue(query.data)?.externalIdentifier; }; diff --git a/apps/admin/src/views/PluginSettings.vue b/apps/admin/src/views/PluginSettings.vue index 0c1ee46bb..fdc76c134 100644 --- a/apps/admin/src/views/PluginSettings.vue +++ b/apps/admin/src/views/PluginSettings.vue @@ -10,8 +10,7 @@ /** * Plugin settings screen. */ -import {computed} from 'vue'; -import {get} from '@vueuse/core'; +import {computed, toValue} from 'vue'; import {AdminContextKey, BackendEndpoint} from '@myparcel-pdk/common'; import {useActionStore, useQueryStore} from '../stores'; import {useStoreContextQuery} from '../composables'; @@ -40,5 +39,5 @@ actionStore.register([pluginSettingsUpdateAction, fetchPluginSettingsViewContext const dynamicContextQuery = useStoreContextQuery(); -const hasAccount = computed(() => Boolean(get(dynamicContextQuery.data)?.account)); +const hasAccount = computed(() => Boolean(toValue(dynamicContextQuery.data)?.account)); diff --git a/apps/admin/src/views/ProductSettings.vue b/apps/admin/src/views/ProductSettings.vue index 9c970d7c8..f16f6c0d6 100644 --- a/apps/admin/src/views/ProductSettings.vue +++ b/apps/admin/src/views/ProductSettings.vue @@ -6,16 +6,14 @@ /** * Product settings. */ -import {toRefs} from 'vue'; -import {get} from '@vueuse/core'; +import {toRefs, toValue} from 'vue'; +import {AdminContextKey} from '@myparcel-pdk/common'; import {defineForm, type FormInstance, MagicForm} from '@myparcel/vue-form-builder'; import {useQueryStore} from '../stores'; import {FORM_KEY_CHILD_PRODUCT_SETTINGS, FORM_KEY_PRODUCT_SETTINGS, generateFormFields} from '../forms'; import {useAdminConfig, useContext, useProductData} from '../composables'; import {useUpdateProductSettingsMutation} from '../actions'; -import {AdminContextKey} from "@myparcel-pdk/common"; - const props = withDefaults( defineProps<{ formName?: string; @@ -41,21 +39,21 @@ const updateProductSettingsMutation = useUpdateProductSettingsMutation(); const adminConfig = useAdminConfig(); const createProductSettingsForm = (): FormInstance => { - const resolvedProduct = get(product); + const resolvedProduct = toValue(product); if (!resolvedProduct || !viewContext.view) { throw new Error('Product settings not loaded'); } const overrides = - FORM_KEY_CHILD_PRODUCT_SETTINGS === get(propRefs.formKey) + FORM_KEY_CHILD_PRODUCT_SETTINGS === toValue(propRefs.formKey) ? { ...adminConfig.formConfigOverrides?.[FORM_KEY_PRODUCT_SETTINGS], ...adminConfig.formConfigOverrides?.[FORM_KEY_CHILD_PRODUCT_SETTINGS], } : adminConfig.formConfigOverrides?.[FORM_KEY_PRODUCT_SETTINGS]; - return defineForm(get(propRefs.formName), { + return defineForm(toValue(propRefs.formName), { ...overrides, fields: [ ...generateFormFields({ diff --git a/yarn.lock b/yarn.lock index 20e18ea05..584575467 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2452,6 +2452,7 @@ __metadata: typescript: "npm:^5.2.2" vitest: "npm:^2.1.3" vue: "npm:^3.3.0" + vue-tsc: "npm:^2.0.0" peerDependencies: vue: ^3 languageName: unknown @@ -2526,7 +2527,7 @@ __metadata: vite: "npm:^5.4.10" vitest: "npm:^2.1.3" vue: "npm:^3.3.0" - vue-tsc: "npm:^1.8.0" + vue-tsc: "npm:^2.0.0" languageName: unknown linkType: soft @@ -5124,15 +5125,6 @@ __metadata: languageName: node linkType: hard -"@volar/language-core@npm:1.11.1, @volar/language-core@npm:~1.11.1": - version: 1.11.1 - resolution: "@volar/language-core@npm:1.11.1" - dependencies: - "@volar/source-map": "npm:1.11.1" - checksum: 10c0/92c4439e3a9ccc534c970031388c318740f6fa032283d03e136c6c8c0228f549c68a7c363af1a28252617a0dca6069e14028329ac906d5acf1912931d0cdcb69 - languageName: node - linkType: hard - "@volar/language-core@npm:2.2.0-alpha.7": version: 2.2.0-alpha.7 resolution: "@volar/language-core@npm:2.2.0-alpha.7" @@ -5151,15 +5143,6 @@ __metadata: languageName: node linkType: hard -"@volar/source-map@npm:1.11.1, @volar/source-map@npm:~1.11.1": - version: 1.11.1 - resolution: "@volar/source-map@npm:1.11.1" - dependencies: - muggle-string: "npm:^0.3.1" - checksum: 10c0/0bfc639889802705f8036ea8b2052a95a4d691a68bc2b6744ba8b9d312d887393dd3278101180a5ee5304972899d493972a483afafd41e097968746c77d724cb - languageName: node - linkType: hard - "@volar/source-map@npm:2.2.0-alpha.7": version: 2.2.0-alpha.7 resolution: "@volar/source-map@npm:2.2.0-alpha.7" @@ -5197,16 +5180,6 @@ __metadata: languageName: node linkType: hard -"@volar/typescript@npm:~1.11.1": - version: 1.11.1 - resolution: "@volar/typescript@npm:1.11.1" - dependencies: - "@volar/language-core": "npm:1.11.1" - path-browserify: "npm:^1.0.1" - checksum: 10c0/86fe153db3a14d8eb3632784a1d7fcbfbfb51fa5517c3878bfdd49ee8d15a83b1a09f9c589454b7396454c104d3a8e2db3a987dc99b37c33816772fc3e292bf2 - languageName: node - linkType: hard - "@vue/compiler-core@npm:3.4.21": version: 3.4.21 resolution: "@vue/compiler-core@npm:3.4.21" @@ -5220,7 +5193,7 @@ __metadata: languageName: node linkType: hard -"@vue/compiler-dom@npm:3.4.21, @vue/compiler-dom@npm:^3.3.0, @vue/compiler-dom@npm:^3.4.0": +"@vue/compiler-dom@npm:3.4.21, @vue/compiler-dom@npm:^3.4.0": version: 3.4.21 resolution: "@vue/compiler-dom@npm:3.4.21" dependencies: @@ -5292,28 +5265,6 @@ __metadata: languageName: node linkType: hard -"@vue/language-core@npm:1.8.27": - version: 1.8.27 - resolution: "@vue/language-core@npm:1.8.27" - dependencies: - "@volar/language-core": "npm:~1.11.1" - "@volar/source-map": "npm:~1.11.1" - "@vue/compiler-dom": "npm:^3.3.0" - "@vue/shared": "npm:^3.3.0" - computeds: "npm:^0.0.1" - minimatch: "npm:^9.0.3" - muggle-string: "npm:^0.3.1" - path-browserify: "npm:^1.0.1" - vue-template-compiler: "npm:^2.7.14" - peerDependencies: - typescript: "*" - peerDependenciesMeta: - typescript: - optional: true - checksum: 10c0/2018214d8ce2643d19e8e84eddaeacddca28b2980984d7916d97f97556c3716be184cf9f8c4f506d072a11f265401e3bc0391117cf7cfcc1e4a25048f4432dc7 - languageName: node - linkType: hard - "@vue/language-core@npm:2.0.12": version: 2.0.12 resolution: "@vue/language-core@npm:2.0.12" @@ -5397,7 +5348,7 @@ __metadata: languageName: node linkType: hard -"@vue/shared@npm:3.4.21, @vue/shared@npm:^3.3.0, @vue/shared@npm:^3.4.0": +"@vue/shared@npm:3.4.21, @vue/shared@npm:^3.4.0": version: 3.4.21 resolution: "@vue/shared@npm:3.4.21" checksum: 10c0/79cba4228c3c1769ba8024302d7dbebf6ed1b77fb2e7a69e635cdebaa1c18b409e9c27ce27ccbe3a98e702a7e2dae1b87754d87f0b29adfe2a8f9e1e7c7899d5 @@ -12337,13 +12288,6 @@ __metadata: languageName: node linkType: hard -"muggle-string@npm:^0.3.1": - version: 0.3.1 - resolution: "muggle-string@npm:0.3.1" - checksum: 10c0/489b0575fa76e30914393915a36638590052409fca2206a6bef0fb0ad7b181c1cbf99761191bfd16fe402c6f5a3164897965422fa32ef20ada1b44024ba46ab6 - languageName: node - linkType: hard - "muggle-string@npm:^0.4.0, muggle-string@npm:^0.4.1": version: 0.4.1 resolution: "muggle-string@npm:0.4.1" @@ -16483,21 +16427,6 @@ __metadata: languageName: node linkType: hard -"vue-tsc@npm:^1.8.0": - version: 1.8.27 - resolution: "vue-tsc@npm:1.8.27" - dependencies: - "@volar/typescript": "npm:~1.11.1" - "@vue/language-core": "npm:1.8.27" - semver: "npm:^7.5.4" - peerDependencies: - typescript: "*" - bin: - vue-tsc: bin/vue-tsc.js - checksum: 10c0/6e6ba37eb7a0c8b9cc613225729c74edf8bd0632d265e62aca28b1969b5615b9dbe2de03aefb8aed2e26fdbd4b93f134785c8ab0095f92c2469192e2db5d09fd - languageName: node - linkType: hard - "vue-tsc@npm:^2.0.0": version: 2.0.12 resolution: "vue-tsc@npm:2.0.12"