Skip to content

Commit

Permalink
refactor: simplify project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Oct 3, 2024
1 parent d13cbdd commit c97cf24
Show file tree
Hide file tree
Showing 137 changed files with 143 additions and 2,126 deletions.
1 change: 0 additions & 1 deletion apps/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"typecheck": "run ws:vite:typecheck \"$(pwd)\""
},
"dependencies": {
"@myparcel-vfb/utils": "workspace:*",
"@myparcel/constants": "^2.0.0",
"@myparcel/sdk": "^4.0.0",
"@myparcel/ts-utils": "^1.6.0",
Expand Down
3 changes: 1 addition & 2 deletions apps/demo/src/components/FormDiagnostics.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@

<script generic="V extends FormValues" lang="ts" setup>
import {toRefs} from 'vue';
import {type MaybeUnwrapNestedRefs, type FormValues} from '@myparcel-vfb/core';
import {type FormInstance} from '@myparcel/vue-form-builder';
import {type MaybeUnwrapNestedRefs, type FormValues, type FormInstance} from '@myparcel/vue-form-builder';
import {useFormEventLog} from '../composables/useFormEventLog';
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/src/components/Heading.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</template>

<script lang="ts" setup>
import {type FieldInstance} from '@myparcel-vfb/core';
import {type FieldInstance} from '@myparcel/vue-form-builder';
defineProps<{element: FieldInstance}>();
</script>
3 changes: 1 addition & 2 deletions apps/demo/src/components/template/ErrorBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
import {computed} from 'vue';
// eslint-disable-next-line vue/prefer-import-from-vue
import {isFunction} from '@vue/shared';
import {type FunctionOr} from '@myparcel-vfb/utils';
const props = defineProps<{errors: FunctionOr<string>[]}>();
const props = defineProps<{errors: ((() => string) | string)[]}>();
const resolvedErrors = computed(() => props.errors.map((error) => (isFunction(error) ? error() : error)));
</script>
2 changes: 1 addition & 1 deletion apps/demo/src/components/template/FormGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</template>

<script lang="ts" setup>
import {type FieldWrapperProps} from '@myparcel-vfb/core';
import {type FieldWrapperProps} from '@myparcel/vue-form-builder';
import {translate} from '../../translate';
import ErrorBox from './ErrorBox.vue';
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/src/components/template/THiddenInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<script lang="ts" setup generic="Type extends string | number">
import {useVModel} from '@vueuse/core';
import {type FieldProps} from '@myparcel-vfb/core';
import {type FieldProps} from '@myparcel/vue-form-builder';
// eslint-disable-next-line vue/no-unused-properties
const props = defineProps<FieldProps<Type>>();
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/src/components/template/TNumberInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<script lang="ts" setup generic="Type extends number | string">
import {useVModel} from '@vueuse/core';
import {type FieldEmits, type FieldProps} from '@myparcel-vfb/core';
import {type FieldEmits, type FieldProps} from '@myparcel/vue-form-builder';
// eslint-disable-next-line vue/no-unused-properties
const props = defineProps<FieldProps<Type>>();
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/src/components/template/TSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/* eslint-disable @typescript-eslint/no-unnecessary-type-arguments */
import {type ComputedRef, computed, watch, onUnmounted} from 'vue';
import {useVModel} from '@vueuse/core';
import {type FieldEmits, type FieldProps} from '@myparcel-vfb/core';
import {type FieldEmits, type FieldProps} from '@myparcel/vue-form-builder';
import {type SelectOption} from '@myparcel/vue-form-builder';
// eslint-disable-next-line vue/no-unused-properties
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/src/components/template/TTextInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<script lang="ts" setup generic="Type extends string">
import {useVModel} from '@vueuse/core';
import {type FieldEmits, type FieldProps} from '@myparcel-vfb/core';
import {type FieldEmits, type FieldProps} from '@myparcel/vue-form-builder';
// eslint-disable-next-line vue/no-unused-properties
const props = defineProps<FieldProps<Type>>();
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/src/components/template/TToggleSwitch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<script lang="ts" setup generic="Type extends boolean">
import {useVModel} from '@vueuse/core';
import {type FieldEmits, type FieldProps} from '@myparcel-vfb/core';
import {type FieldEmits, type FieldProps} from '@myparcel/vue-form-builder';
// eslint-disable-next-line vue/no-unused-properties
const props = defineProps<FieldProps<Type>>();
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/src/components/template/TableFormGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</template>

<script lang="ts" setup>
import {type FieldWrapperProps} from '@myparcel-vfb/core';
import {type FieldWrapperProps} from '@myparcel/vue-form-builder';
import {translate} from '../../translate';
defineProps<FieldWrapperProps>();
Expand Down
7 changes: 6 additions & 1 deletion apps/demo/src/composables/useFormEventLog.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import {type Ref, ref} from 'vue';
import {type FormInstance, type MaybeUnwrapNestedRefs, FORM_HOOKS, type FieldInstance} from '@myparcel-vfb/core';
import {
type FormInstance,
type MaybeUnwrapNestedRefs,
FORM_HOOKS,
type FieldInstance,
} from '@myparcel/vue-form-builder';
import {isOfType} from '@myparcel/ts-utils';

export const useFormEventLog = (form: MaybeUnwrapNestedRefs<FormInstance>): Ref<string> => {
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/src/validation/emailValidator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {type Validator} from '@myparcel-vfb/core';
import {type Validator} from '@myparcel/vue-form-builder';

export const emailValidator = (): Validator<string> => ({
validate: (_, value) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value),
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/src/validation/regexValidator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {type Validator} from '@myparcel-vfb/core';
import {type Validator} from '@myparcel/vue-form-builder';

export const regexValidator = (regex: RegExp): Validator<string> => ({
validate: (_, value) => regex.test(value),
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/src/validation/stringLengthValidator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {type Validator} from '@myparcel-vfb/core';
import {type Validator} from '@myparcel/vue-form-builder';

export const stringLengthValidator = (minLength: number, maxLength?: number): Validator<string> => {
return {
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/src/validation/stringNotContainsValidator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {type Validator} from '@myparcel-vfb/core';
import {type Validator} from '@myparcel/vue-form-builder';
import {type OneOrMore, toArray} from '@myparcel/ts-utils';

export const stringNotContainsValidator = (search: OneOrMore<string>): Validator<string> => {
Expand Down
19 changes: 10 additions & 9 deletions apps/demo/src/views/FormView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
<script lang="ts" setup>
/* eslint-disable @typescript-eslint/naming-convention */
import {computed, h, ref} from 'vue';
import {createField, createForm} from '@myparcel-vfb/core';
import {createField, createForm, type FormInstance} from '@myparcel/vue-form-builder';
import {regexValidator, stringLengthValidator, stringNotContainsValidator, emailValidator} from '../validation';
import TTextInput from '../components/template/TTextInput.vue';
import TSubmitButton from '../components/template/TSubmitButton.vue';
Expand All @@ -165,9 +165,9 @@ const Form = createForm<{
},
afterAddElement(form, field) {
if (field.name === 'firstName') {
form.setValue(field.name, 'Spongebob');
}
if (field.name === 'firstName') {
form.setValue(field.name, 'Spongebob');
}
},
afterSubmit: (form: FormInstance) => {
Expand Down Expand Up @@ -255,24 +255,25 @@ const form2Classes = computed(() => {
const resetForms = () => {
Form.instance.reset();
Form2.instance.reset();
}
};
const onSubmitClick = () => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const descriptionField = Form2.instance.getField('description');
const descriptionField = Form2.instance.getField('description')!;
descriptionField.errors.value.push('This is an error from afterSubmit');
descriptionField.isValid.value = false;
const lastNameField = Form.instance.getField('lastName');
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const lastNameField = Form.instance.getField('lastName')!;
lastNameField.errors.value.push('This is an error from afterSubmit');
lastNameField.isValid.value = false;
};
const switchOptional = () => {
const field = Form.instance.getField('lastName');
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const field = Form.instance.getField('lastName')!;
field.setOptional(!field.isOptional.value);
};
</script>
4 changes: 2 additions & 2 deletions apps/demo/src/views/MiddleName.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</template>

<script lang="ts" setup>
import {createField, createForm} from '@myparcel-vfb/core';
import {createField, createForm} from '@myparcel/vue-form-builder';
import TTextInput from '../components/template/TTextInput.vue';
import {ref} from 'vue';
Expand All @@ -17,4 +17,4 @@ const MiddleName = createField({
optional: true,
});
</script>
</script>
2 changes: 1 addition & 1 deletion apps/demo/src/views/NoPropView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<script lang="ts" setup>
import {ref} from 'vue';
import {createField, createForm} from '@myparcel-vfb/core';
import {createField, createForm} from '@myparcel/vue-form-builder';
import FormGroupWithoutElementProp from '../components/FormGroupWithoutElementProp.vue';
import FormDiagnostics from '../components/FormDiagnostics.vue';
import ComponentWithoutElementProp from '../components/ComponentWithoutElementProp.vue';
Expand Down
7 changes: 2 additions & 5 deletions apps/vue-form-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@
"typecheck": "run ws:vite:typecheck \"$(pwd)\""
},
"dependencies": {
"@myparcel-vfb/core": "workspace:^1.0.0-beta.43",
"@myparcel-vfb/hook-manager": "workspace:^1.0.0-beta.13",
"@myparcel-vfb/plugin": "workspace:^1.0.0-beta.43",
"@myparcel-vfb/utils": "workspace:^1.0.0-beta.9",
"@myparcel/ts-utils": ">= 1.6.0",
"@vueuse/core": ">= 10.1.0"
"@vueuse/core": ">= 10.1.0",
"vue-component-type-helpers": "^2.1.6"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.0.0",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {h, ref, reactive, nextTick} from 'vue';
import {h, ref, reactive} from 'vue';
import {afterEach, describe, expect, it, vi} from 'vitest';
import {flushPromises, mount} from '@vue/test-utils';
import {createField, createForm, getDefaultFormConfiguration} from '../../utils';
Expand All @@ -12,13 +12,15 @@ interface TestFormValues {
field3: string;
}

const renderTestForm = async (config = {
afterAddElement(form, field) {
if (field.name === 'field2') {
form.setValue(field.name, '');
}
const renderTestForm = async (
config = {
afterAddElement(form, field) {
if (field.name === 'field2') {
form.setValue(field.name, '');
}
},
},
}) => {
) => {
const fields = [
{
name: 'field1',
Expand Down Expand Up @@ -109,13 +111,11 @@ describe('rendering a form', () => {
});

it('wraps fields with a wrapper element', async () => {
const {wrapper} = await renderTestForm(
{
field: {
wrapper: h('span', {class: 'inner-wrapper'}),
},
const {wrapper} = await renderTestForm({
field: {
wrapper: h('span', {class: 'inner-wrapper'}),
},
);
});

const wrapperElements = wrapper.findAll('span.inner-wrapper');

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {type Ref, ref, toValue} from 'vue';
import {HookManager} from '@myparcel-vfb/hook-manager';
import {normalizeFormConfiguration, getDefaultFormConfiguration} from '../utils';
import {type FormInstance, type InstanceFormConfiguration, type FormConfiguration, type FormBuilder} from '../types';
import {HookManager} from '../hooks';
import {Form} from '../form';

let forms: Ref<Record<string, FormInstance>>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Vue from 'vue';
import {type HookManagerInstance} from '@myparcel-vfb/hook-manager';
import {type ComponentLifecycleHooks} from '../types';
import {type HookManagerInstance} from '../hooks';
import {COMPONENT_LIFECYCLE_HOOKS} from '../data';

type UseLifeCycleHooks = () => {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// noinspection JSUnusedGlobalSymbols

/** @deprecated use Field */
export {Field as InteractiveElement} from './form/Field';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// noinspection JSUnusedGlobalSymbols
import {ref, watch, toValue, reactive, type UnwrapNestedRefs, computed, markRaw, type Ref, isRef} from 'vue';
import {ref, watch, toValue, reactive, type UnwrapNestedRefs, computed, markRaw, type Ref} from 'vue';
import {isDefined} from '@vueuse/core';
import {type CustomHookItem, createHookManager} from '@myparcel-vfb/hook-manager';
import {isOfType, asyncEvery, type PromiseOr} from '@myparcel/ts-utils';
import {isRequired} from '../validators';
import {normalizeFieldConfiguration} from '../utils/normalizeFieldConfiguration';
import {useDynamicWatcher, updateMaybeRef} from '../utils';
import {normalizeFieldConfiguration, useDynamicWatcher, updateMaybeRef} from '../utils';
import {
type ToRecord,
type FieldConfiguration,
Expand All @@ -15,9 +13,12 @@ import {
type Validator,
type WithMultiValidator,
type ComponentProps,
type CustomHookItem,
} from '../types';
import {createHookManager} from '../hooks';
import {FIELD_HOOKS, FormHook} from '../data';

// noinspection JSUnusedGlobalSymbols
export class Field<Type = unknown, Props extends ComponentProps = ComponentProps> {
public readonly name: FieldInstance<Type, Props>['name'];
public readonly component: FieldInstance<Type, Props>['component'];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {computed, ref, watch, reactive, toValue, type Ref} from 'vue';
import {useMemoize} from '@vueuse/core';
import {createHookManager} from '@myparcel-vfb/hook-manager';
import {markComponentAsRaw} from '../utils';
import {
type ToRecord,
Expand All @@ -11,6 +10,7 @@ import {
type FieldInstance,
type ComponentProps,
} from '../types';
import {createHookManager} from '../hooks';
import {FormHook, FORM_HOOKS} from '../data';
import {Field} from './Field';

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {beforeEach, describe, expect, it, vi} from 'vitest';
import {createHookManager} from '../createHookManager';
import {type HookManagerInstance} from '../HookManager';
import {createHookManager} from './createHookManager';
import {type HookManagerInstance} from './HookManager';

const HOOKS = ['start', 'sanitize'] as const;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// noinspection JSUnusedGlobalSymbols

import {type ReadonlyOr, type ResolvePromise} from '@myparcel/ts-utils';
import {filterMatchingHooks} from './utils';
import {type CustomHookItem, type HookCallback, type HookManagerConfiguration} from './types';
import {type HookManagerConfiguration, type CustomHookItem, type HookCallback} from '../types';
import {filterMatchingHooks} from './filterMatchingHooks';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type GetParameters<T> = T extends (...args: any[]) => any ? Parameters<T> : any[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {type HookManagerConfiguration} from './types';
import {type HookManagerConfiguration} from '../types';
import {HookManager, type HookManagerInstance} from './HookManager';

export const createHookManager = <HC extends HookManagerConfiguration = HookManagerConfiguration>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {describe, expect, it} from 'vitest';
import {filterMatchingHooks} from '../utils/filterMatchingHooks';
import {filterMatchingHooks} from './filterMatchingHooks';

describe('filterMatchingHooks', () => {
it.each([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
export * from './HookManager';
export * from './createHookManager';
export * from './types';
export * from './utils';
Loading

0 comments on commit c97cf24

Please sign in to comment.