@naptics/vue-collection 1.0.0-beta.1 → 1.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/NAlert.d.ts +29 -0
- package/lib/components/NAlert.js +84 -0
- package/lib/components/NBadge.d.ts +73 -0
- package/lib/components/NBadge.js +64 -0
- package/lib/components/NBreadcrub.d.ts +69 -0
- package/lib/components/NBreadcrub.js +71 -0
- package/lib/components/NButton.d.ts +64 -0
- package/lib/components/NButton.js +70 -0
- package/lib/components/NCheckbox.d.ts +20 -0
- package/lib/components/NCheckbox.js +43 -0
- package/lib/components/NCheckboxLabel.d.ts +26 -0
- package/lib/components/NCheckboxLabel.js +42 -0
- package/lib/components/NCrudModal.d.ts +118 -0
- package/lib/components/NCrudModal.js +120 -0
- package/lib/components/NDialog.d.ts +81 -0
- package/lib/components/NDialog.js +161 -0
- package/lib/components/NDropdown.d.ts +67 -0
- package/lib/components/NDropdown.js +115 -0
- package/lib/components/NDropzone.d.ts +61 -0
- package/lib/components/NDropzone.js +218 -0
- package/lib/components/NForm.d.ts +21 -0
- package/lib/components/NForm.js +29 -0
- package/lib/components/NFormModal.d.ts +75 -0
- package/lib/components/NFormModal.js +59 -0
- package/lib/components/NIconButton.d.ts +83 -0
- package/lib/components/NIconButton.js +88 -0
- package/lib/components/NIconCircle.d.ts +49 -0
- package/lib/components/NIconCircle.js +67 -0
- package/lib/components/NInput.d.ts +94 -0
- package/lib/components/NInput.js +110 -0
- package/lib/components/NInputPhone.d.ts +58 -0
- package/lib/components/NInputPhone.js +47 -0
- package/lib/components/NInputSelect.d.ts +103 -0
- package/lib/components/NInputSelect.js +115 -0
- package/lib/components/NInputSuggestion.d.ts +79 -0
- package/lib/components/NInputSuggestion.js +64 -0
- package/lib/components/NLink.d.ts +47 -0
- package/lib/components/NLink.js +67 -0
- package/lib/components/NList.d.ts +37 -0
- package/lib/components/NList.js +40 -0
- package/lib/components/NLoadingIndicator.d.ts +29 -0
- package/lib/components/NLoadingIndicator.js +54 -0
- package/lib/components/NModal.d.ts +133 -0
- package/lib/components/NModal.js +235 -0
- package/{src/lib → lib}/components/NPagination.css +1 -1
- package/lib/components/NPagination.d.ts +37 -0
- package/lib/components/NPagination.js +105 -0
- package/lib/components/NSearchbar.d.ts +39 -0
- package/lib/components/NSearchbar.js +64 -0
- package/lib/components/NSearchbarList.d.ts +33 -0
- package/lib/components/NSearchbarList.js +41 -0
- package/lib/components/NSelect.d.ts +82 -0
- package/lib/components/NSelect.js +101 -0
- package/lib/components/NSuggestionList.d.ts +153 -0
- package/lib/components/NSuggestionList.js +160 -0
- package/{src/lib → lib}/components/NTable.css +1 -1
- package/lib/components/NTable.d.ts +97 -0
- package/lib/components/NTable.js +128 -0
- package/lib/components/NTableAction.d.ts +30 -0
- package/lib/components/NTableAction.js +50 -0
- package/lib/components/NTextArea.d.ts +96 -0
- package/lib/components/NTextArea.js +133 -0
- package/{src/lib → lib}/components/NTooltip.css +1 -1
- package/lib/components/NTooltip.d.ts +152 -0
- package/lib/components/NTooltip.js +241 -0
- package/lib/components/NValInput.d.ts +156 -0
- package/lib/components/NValInput.js +113 -0
- package/lib/components/ValidatedForm.d.ts +39 -0
- package/lib/components/ValidatedForm.js +35 -0
- package/{src/lib/i18n/index.ts → lib/i18n/index.d.ts} +9 -23
- package/lib/i18n/index.js +31 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/utils/breakpoints.d.ts +18 -0
- package/lib/utils/breakpoints.js +40 -0
- package/lib/utils/component.d.ts +57 -0
- package/lib/utils/component.js +79 -0
- package/lib/utils/deferred.d.ts +13 -0
- package/lib/utils/deferred.js +17 -0
- package/lib/utils/identifiable.d.ts +56 -0
- package/lib/utils/identifiable.js +81 -0
- package/lib/utils/stringMaxLength.d.ts +14 -0
- package/lib/utils/stringMaxLength.js +23 -0
- package/lib/utils/tailwind.d.ts +4 -0
- package/lib/utils/tailwind.js +1 -0
- package/lib/utils/utils.d.ts +47 -0
- package/lib/utils/utils.js +56 -0
- package/{src/lib/utils/vModel.ts → lib/utils/vModel.d.ts} +48 -126
- package/lib/utils/vModel.js +224 -0
- package/lib/utils/validation.d.ts +90 -0
- package/lib/utils/validation.js +147 -0
- package/lib/utils/vue.d.ts +13 -0
- package/lib/utils/vue.js +21 -0
- package/package.json +6 -2
- package/.github/workflows/build.yml +0 -26
- package/.github/workflows/deploy-demo.yml +0 -46
- package/.github/workflows/deploy-lib.yml +0 -59
- package/.gitlab-ci.yml +0 -57
- package/.nvmrc +0 -1
- package/.prettierrc +0 -8
- package/.vscode/extensions.json +0 -10
- package/.vscode/launch.json +0 -23
- package/.vscode/settings.json +0 -13
- package/babel.config.json +0 -3
- package/env.d.ts +0 -15
- package/eslint.config.cjs +0 -27
- package/index.html +0 -13
- package/postcss.config.js +0 -3
- package/public/favicon.ico +0 -0
- package/scripts/build-lib.sh +0 -52
- package/scripts/sync-node-types.js +0 -70
- package/src/demo/App.css +0 -53
- package/src/demo/App.tsx +0 -5
- package/src/demo/components/ColorGrid.tsx +0 -26
- package/src/demo/components/ComponentGrid.tsx +0 -26
- package/src/demo/components/ComponentSection.tsx +0 -30
- package/src/demo/components/VariantSection.tsx +0 -18
- package/src/demo/i18n/de.ts +0 -7
- package/src/demo/i18n/en.ts +0 -7
- package/src/demo/i18n/index.ts +0 -24
- package/src/demo/main.ts +0 -13
- package/src/demo/router/index.ts +0 -21
- package/src/demo/views/HomeView.tsx +0 -94
- package/src/demo/views/NavigationView.tsx +0 -43
- package/src/demo/views/presentation/AlertView.tsx +0 -40
- package/src/demo/views/presentation/BadgeView.tsx +0 -61
- package/src/demo/views/presentation/BreadcrumbView.tsx +0 -52
- package/src/demo/views/presentation/ButtonView.tsx +0 -49
- package/src/demo/views/presentation/CheckboxView.tsx +0 -59
- package/src/demo/views/presentation/DropdownView.tsx +0 -59
- package/src/demo/views/presentation/DropzoneView.tsx +0 -39
- package/src/demo/views/presentation/IconButtonView.tsx +0 -47
- package/src/demo/views/presentation/IconCircleView.tsx +0 -38
- package/src/demo/views/presentation/InputView.tsx +0 -179
- package/src/demo/views/presentation/LinkView.tsx +0 -60
- package/src/demo/views/presentation/ListView.tsx +0 -29
- package/src/demo/views/presentation/LoadingIndicatorView.tsx +0 -38
- package/src/demo/views/presentation/ModalView.tsx +0 -210
- package/src/demo/views/presentation/PaginationView.tsx +0 -25
- package/src/demo/views/presentation/SearchbarView.tsx +0 -80
- package/src/demo/views/presentation/TableView.tsx +0 -146
- package/src/demo/views/presentation/TooltipView.tsx +0 -92
- package/src/lib/components/NAlert.tsx +0 -85
- package/src/lib/components/NBadge.tsx +0 -75
- package/src/lib/components/NBreadcrub.tsx +0 -97
- package/src/lib/components/NButton.tsx +0 -82
- package/src/lib/components/NCheckbox.tsx +0 -55
- package/src/lib/components/NCheckboxLabel.tsx +0 -51
- package/src/lib/components/NCrudModal.tsx +0 -133
- package/src/lib/components/NDialog.tsx +0 -182
- package/src/lib/components/NDropdown.tsx +0 -169
- package/src/lib/components/NDropzone.tsx +0 -265
- package/src/lib/components/NForm.tsx +0 -32
- package/src/lib/components/NFormModal.tsx +0 -66
- package/src/lib/components/NIconButton.tsx +0 -92
- package/src/lib/components/NIconCircle.tsx +0 -78
- package/src/lib/components/NInput.tsx +0 -139
- package/src/lib/components/NInputPhone.tsx +0 -53
- package/src/lib/components/NInputSelect.tsx +0 -126
- package/src/lib/components/NInputSuggestion.tsx +0 -80
- package/src/lib/components/NLink.tsx +0 -82
- package/src/lib/components/NList.tsx +0 -67
- package/src/lib/components/NLoadingIndicator.tsx +0 -63
- package/src/lib/components/NModal.tsx +0 -243
- package/src/lib/components/NPagination.tsx +0 -131
- package/src/lib/components/NSearchbar.tsx +0 -78
- package/src/lib/components/NSearchbarList.tsx +0 -47
- package/src/lib/components/NSelect.tsx +0 -128
- package/src/lib/components/NSuggestionList.tsx +0 -216
- package/src/lib/components/NTable.tsx +0 -247
- package/src/lib/components/NTableAction.tsx +0 -49
- package/src/lib/components/NTextArea.tsx +0 -159
- package/src/lib/components/NTooltip.tsx +0 -289
- package/src/lib/components/NValInput.tsx +0 -163
- package/src/lib/components/ValidatedForm.ts +0 -71
- package/src/lib/components/__tests__/NButton.spec.tsx +0 -26
- package/src/lib/components/__tests__/NCheckbox.spec.tsx +0 -39
- package/src/lib/index.ts +0 -2
- package/src/lib/jsx.d.ts +0 -13
- package/src/lib/utils/__tests__/identifiable.spec.ts +0 -72
- package/src/lib/utils/__tests__/validation.spec.ts +0 -92
- package/src/lib/utils/breakpoints.ts +0 -47
- package/src/lib/utils/component.tsx +0 -131
- package/src/lib/utils/deferred.ts +0 -28
- package/src/lib/utils/identifiable.ts +0 -87
- package/src/lib/utils/stringMaxLength.ts +0 -25
- package/src/lib/utils/tailwind.ts +0 -41
- package/src/lib/utils/utils.ts +0 -90
- package/src/lib/utils/validation.ts +0 -189
- package/src/lib/utils/vue.ts +0 -25
- package/tsconfig.config.json +0 -9
- package/tsconfig.demo.json +0 -19
- package/tsconfig.json +0 -16
- package/tsconfig.lib.json +0 -19
- package/tsconfig.vitest.json +0 -8
- package/vite.config.ts +0 -30
- /package/{src/lib → lib}/components/NInput.css +0 -0
- /package/{src/lib → lib}/components/NLoadingIndicator.css +0 -0
- /package/{src/lib → lib}/i18n/de/vue-collection.json +0 -0
- /package/{src/lib → lib}/i18n/en/vue-collection.json +0 -0
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { trsl } from '../../i18n'
|
|
2
|
-
import { describe, expect, test } from 'vitest'
|
|
3
|
-
import { email, external, matches, option, password, regex, required } from '../validation'
|
|
4
|
-
|
|
5
|
-
const expectValid = (test: unknown) => expect(test).toMatchObject({ isValid: true })
|
|
6
|
-
const expectInvalid = (test: unknown, errKey: string) =>
|
|
7
|
-
expect(test).toMatchObject({ isValid: false, errorMessage: trsl(`vue-collection.validation.rules.${errKey}`) })
|
|
8
|
-
|
|
9
|
-
describe('validation', () => {
|
|
10
|
-
test('required', () => {
|
|
11
|
-
expectValid(required('_'))
|
|
12
|
-
expectValid(required(' i '))
|
|
13
|
-
expectValid(required('hellooh'))
|
|
14
|
-
expectValid(required('`'))
|
|
15
|
-
|
|
16
|
-
expectInvalid(required(undefined), 'required')
|
|
17
|
-
expectInvalid(required(null), 'required')
|
|
18
|
-
expectInvalid(required(''), 'required')
|
|
19
|
-
expectInvalid(required(' '), 'required')
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
test('email', () => {
|
|
23
|
-
expectValid(email(''))
|
|
24
|
-
expectValid(email('_@_.ch'))
|
|
25
|
-
expectValid(email('dfadfasd.dfad.fdak@_.ch'))
|
|
26
|
-
expectValid(email('dfadfasd.dfad.fdak@dfdaf.chdl.ch'))
|
|
27
|
-
expectValid(email('deslek-djsl@dfdaf-cas.ch'))
|
|
28
|
-
|
|
29
|
-
expectInvalid(email('a'), 'email')
|
|
30
|
-
expectInvalid(email('a@'), 'email')
|
|
31
|
-
expectInvalid(email('a@d'), 'email')
|
|
32
|
-
expectInvalid(email('a@d.c'), 'email')
|
|
33
|
-
expectInvalid(email('a.ch'), 'email')
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
test('password', () => {
|
|
37
|
-
expectValid(password(''))
|
|
38
|
-
expectValid(password('Password1+'))
|
|
39
|
-
expectValid(password('+Password1'))
|
|
40
|
-
expectValid(password('1+Password'))
|
|
41
|
-
expectValid(password('assword1+P'))
|
|
42
|
-
expectValid(password('12p+D678'))
|
|
43
|
-
|
|
44
|
-
expectInvalid(password('p'), 'password.to-short')
|
|
45
|
-
expectInvalid(password('Pword1+'), 'password.to-short')
|
|
46
|
-
expectInvalid(password('PASSWORD1+'), 'password.no-lowercase')
|
|
47
|
-
expectInvalid(password('password1+'), 'password.no-uppercase')
|
|
48
|
-
expectInvalid(password('Password+'), 'password.no-digits')
|
|
49
|
-
expectInvalid(password('Password1'), 'password.no-special-chars')
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
test('matches', () => {
|
|
53
|
-
const testValid = [undefined, null, '', '1', 'hello', 'So cooool']
|
|
54
|
-
testValid.forEach(value => {
|
|
55
|
-
expectValid(matches(value)(value))
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
// This rule does not allow the input to be falsy, always has to match.
|
|
59
|
-
const testInvalid = ['', '1', 'hi', 'noice', 'not-null', 'not-null', 'not-null']
|
|
60
|
-
const checkInvalid = ['ho', '11', 'HI', 'noices', '', null, undefined]
|
|
61
|
-
|
|
62
|
-
testInvalid.forEach((value, index) => {
|
|
63
|
-
expectInvalid(matches(value)(checkInvalid[index]), 'matches')
|
|
64
|
-
})
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
test('regex', () => {
|
|
68
|
-
expectValid(regex(/\d+/)('123'))
|
|
69
|
-
expectValid(regex(/\d*/)(null))
|
|
70
|
-
expectValid(regex(/\d+/)(null))
|
|
71
|
-
|
|
72
|
-
expectInvalid(regex(/\d+/)('abc'), 'regex')
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
test('option', () => {
|
|
76
|
-
const options1 = ['a', 'b', 'ab', 'ac', 'a']
|
|
77
|
-
expectValid(option(options1)(null))
|
|
78
|
-
expectValid(option(options1)('a'))
|
|
79
|
-
expectValid(option(options1)('b'))
|
|
80
|
-
expectValid(option(options1)('ab'))
|
|
81
|
-
|
|
82
|
-
expectInvalid(option(options1)('c'), 'option')
|
|
83
|
-
expectInvalid(option(options1)('A'), 'option')
|
|
84
|
-
expectInvalid(option(options1)('aB'), 'option')
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
test('external', () => {
|
|
88
|
-
expectValid(external(true, trsl('vue-collection.validation.rules.phone'))('hi'))
|
|
89
|
-
expectValid(external(false, trsl('vue-collection.validation.rules.phone'))(null))
|
|
90
|
-
expectInvalid(external(false, trsl('vue-collection.validation.rules.phone'))('hi'), 'phone')
|
|
91
|
-
})
|
|
92
|
-
})
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { computed, ref, type ComputedRef } from 'vue'
|
|
2
|
-
|
|
3
|
-
export type TWBreakpoint = 'sm' | 'md' | 'lg' | 'xl' | '2xl'
|
|
4
|
-
|
|
5
|
-
export const breakpoints: Readonly<Record<TWBreakpoint, number>> = {
|
|
6
|
-
sm: 640,
|
|
7
|
-
md: 768,
|
|
8
|
-
lg: 1024,
|
|
9
|
-
xl: 1280,
|
|
10
|
-
'2xl': 1536,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const bodyWidth = ref(document.body.clientWidth)
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* This function has to be called once in the app two ensure that the breakpoint utilities actually update.
|
|
17
|
-
* It sets a `window.onresize` listener.
|
|
18
|
-
*/
|
|
19
|
-
export function addDocumentResizeEventListener(): void {
|
|
20
|
-
window.onresize = () => {
|
|
21
|
-
bodyWidth.value = document.body.clientWidth
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Returns a ref whose value is `true` as long as the `document.body.clientWitdh` is above the specified breakpoint.
|
|
27
|
-
*/
|
|
28
|
-
export function isWidthBreakpoint(breakpoint: TWBreakpoint): ComputedRef<boolean> {
|
|
29
|
-
switch (breakpoint) {
|
|
30
|
-
case 'sm':
|
|
31
|
-
return isWidthSm
|
|
32
|
-
case 'md':
|
|
33
|
-
return isWidthMd
|
|
34
|
-
case 'lg':
|
|
35
|
-
return isWidthLg
|
|
36
|
-
case 'xl':
|
|
37
|
-
return isWidthXl
|
|
38
|
-
case '2xl':
|
|
39
|
-
return isWidth2xl
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const isWidth2xl = computed(() => bodyWidth.value > breakpoints['2xl'])
|
|
44
|
-
export const isWidthXl = computed(() => bodyWidth.value > breakpoints.xl)
|
|
45
|
-
export const isWidthLg = computed(() => bodyWidth.value > breakpoints.lg)
|
|
46
|
-
export const isWidthMd = computed(() => bodyWidth.value > breakpoints.md)
|
|
47
|
-
export const isWidthSm = computed(() => bodyWidth.value > breakpoints.sm)
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
// eslint-disable @typescript-eslint/explicit-module-boundary-types
|
|
2
|
-
// eslint-disable-next-line vue/prefer-import-from-vue
|
|
3
|
-
import type { LooseRequired } from '@vue/shared'
|
|
4
|
-
import {
|
|
5
|
-
defineComponent,
|
|
6
|
-
reactive,
|
|
7
|
-
toRef,
|
|
8
|
-
type ComponentObjectPropsOptions,
|
|
9
|
-
type ExtractPropTypes,
|
|
10
|
-
type RenderFunction,
|
|
11
|
-
type SetupContext,
|
|
12
|
-
type ToRefs,
|
|
13
|
-
type UnwrapNestedRefs,
|
|
14
|
-
type Slots,
|
|
15
|
-
toRefs,
|
|
16
|
-
ref,
|
|
17
|
-
} from 'vue'
|
|
18
|
-
import type { AnyObject } from './utils'
|
|
19
|
-
|
|
20
|
-
type Data = Record<string, unknown>
|
|
21
|
-
export type Props<T extends Data = Data> = ComponentObjectPropsOptions<T>
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* `ExtractedProps` maps a prop object to the props, which are received in the `setup` function of a components.
|
|
25
|
-
*/
|
|
26
|
-
export type ExtractedProps<T extends Props> = Readonly<LooseRequired<Readonly<ExtractPropTypes<T>>>>
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Components should be created using this helper function.
|
|
30
|
-
* It only takes three arguments, the name and the props of the component and the setup function.
|
|
31
|
-
* All other arguments which the {@link defineComponent} method of vue may provide,
|
|
32
|
-
* should not be used for a better consistency across all components.
|
|
33
|
-
* @param name the name of the component, should be more than one word.
|
|
34
|
-
* @param props the props of the component.
|
|
35
|
-
* @param setup the setup function, which will be called when the component is mounted.
|
|
36
|
-
* @returns the created vue-component.
|
|
37
|
-
*/
|
|
38
|
-
export function createComponent<T extends Props>(
|
|
39
|
-
name: string,
|
|
40
|
-
props: T,
|
|
41
|
-
setup: (props: ExtractedProps<T>, context: SetupContext<never[]>) => RenderFunction | Promise<RenderFunction>
|
|
42
|
-
) {
|
|
43
|
-
// Vue 3.5's defineComponent has strict type requirements that don't align with our simplified API.
|
|
44
|
-
// The type assertion is necessary because the generic setup function signature doesn't match
|
|
45
|
-
// Vue's complex overloaded defineComponent types, even though the runtime behavior is correct.
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
-
return defineComponent({ name, props, emits: [], setup } as any)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* When using this function, the created component will make available all props
|
|
52
|
-
* specifiedin `slotPropKeys` as slot. In this way, they can be used by either setting
|
|
53
|
-
* the prop directly or by using a slot with the same name. This is useful for older
|
|
54
|
-
* components (in `.vue` files), because they are dependent on slots.
|
|
55
|
-
* @see {@link createComponent}
|
|
56
|
-
*/
|
|
57
|
-
export function createComponentWithSlots<T extends Props>(
|
|
58
|
-
name: string,
|
|
59
|
-
props: T,
|
|
60
|
-
slotPropKeys: SlotPropsKeys<ExtractedProps<T>>,
|
|
61
|
-
setup: (props: ExtractedProps<T>, context: SetupContext<never[]>) => RenderFunction | Promise<RenderFunction>
|
|
62
|
-
) {
|
|
63
|
-
const newSetup: typeof setup = (props, context) => {
|
|
64
|
-
const slottedProps = createSlotProps(props, context.slots, ...slotPropKeys)
|
|
65
|
-
return setup(slottedProps, context)
|
|
66
|
-
}
|
|
67
|
-
return createComponent(name, props, newSetup)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Views should be created using this helper function. Views are special components, which don't have props.
|
|
72
|
-
* They are often the parent objects in a view hierarchy and contain many components.
|
|
73
|
-
* This function is syntactic sugar to create views and just calls {@link createComponent}.
|
|
74
|
-
* @param name the name of the component, should be more than one word.
|
|
75
|
-
* @param setup the setup function, which will be called when the component is mounted.
|
|
76
|
-
* @returns the created vue-component.
|
|
77
|
-
*/
|
|
78
|
-
export function createView(
|
|
79
|
-
name: string,
|
|
80
|
-
setup: (context: SetupContext<never[]>) => RenderFunction | Promise<RenderFunction>
|
|
81
|
-
) {
|
|
82
|
-
return defineComponent({ name, emits: [], setup: (props, context) => setup(context) })
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Extracts props from another prop object and returns a reactive object with the specified props.
|
|
87
|
-
* @param props the props to extract from
|
|
88
|
-
* @param keys the keys to extract from the props
|
|
89
|
-
* @returns the new object with the specified props
|
|
90
|
-
* @example
|
|
91
|
-
* const parentProps = { title: 'hi', text: 'ho' }
|
|
92
|
-
* const childProps = extractProps(parentProps, 'title')
|
|
93
|
-
* console.log(childProps) // { title: 'hi' }
|
|
94
|
-
*/
|
|
95
|
-
export function extractProps<T extends Record<string, unknown>>(
|
|
96
|
-
props: T,
|
|
97
|
-
...keys: (keyof T)[]
|
|
98
|
-
): UnwrapNestedRefs<Partial<ToRefs<T>>> {
|
|
99
|
-
const partial: Partial<ToRefs<T>> = {}
|
|
100
|
-
for (const key of keys) partial[key] = toRef(props, key) as never
|
|
101
|
-
return reactive(partial)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/*
|
|
105
|
-
* ---------- Slot Helpers ----------
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
109
|
-
type SlotFunction<Args extends any[] = any[]> = (...args: Args) => JSX.Element
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Filters object T to only have properties of type K.
|
|
113
|
-
*/
|
|
114
|
-
type FilterObject<T, K> = {
|
|
115
|
-
[P in keyof T as T[P] extends K ? P : never]: T[P]
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
type SlotPropsKeys<T extends AnyObject> = (keyof FilterObject<T, SlotFunction | undefined>)[]
|
|
119
|
-
|
|
120
|
-
function createSlotProps<T extends AnyObject, U extends SlotPropsKeys<T>>(props: T, slots: Slots, ...keys: U): T {
|
|
121
|
-
// create refs, don't touch all props which are not slots
|
|
122
|
-
const newProps = toRefs(props)
|
|
123
|
-
keys.forEach(key => {
|
|
124
|
-
// if a slot is set once, it is basically always set. The changing content is not a problem as it is inside the function.
|
|
125
|
-
const slot = slots[key as string]
|
|
126
|
-
// if the slot is set, overwrite the props
|
|
127
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
128
|
-
if (slot) newProps[key] = ((...args: any) => <>{slot?.(...args)}</>) as any
|
|
129
|
-
})
|
|
130
|
-
return ref(newProps).value
|
|
131
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
type PromiseResolve<T> = (value: T | PromiseLike<T>) => void
|
|
2
|
-
type PromiseReject = (reason?: unknown) => void
|
|
3
|
-
|
|
4
|
-
export type DeferredPromise<T> = {
|
|
5
|
-
promise: Promise<T>
|
|
6
|
-
resolve: PromiseResolve<T>
|
|
7
|
-
reject: PromiseReject
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Utlitity to return a deferred promise, which can be resolved from outside.
|
|
12
|
-
* @returns promise, resolve and reject
|
|
13
|
-
*/
|
|
14
|
-
export function deferred<T>(): DeferredPromise<T> {
|
|
15
|
-
let resolve!: PromiseResolve<T>
|
|
16
|
-
let reject!: PromiseReject
|
|
17
|
-
|
|
18
|
-
const promise = new Promise<T>((_resolve, _reject) => {
|
|
19
|
-
resolve = _resolve
|
|
20
|
-
reject = _reject
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
promise,
|
|
25
|
-
resolve,
|
|
26
|
-
reject,
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { isNullish, type Nullish } from './utils'
|
|
2
|
-
|
|
3
|
-
export type Identifiable<Id = string> = Readonly<{ id: Id }>
|
|
4
|
-
export type MaybeIdentifiable<Id = string> = Readonly<{ id?: Nullish<Id> }>
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Looks for the `id` in the given array of `Identifiables`.
|
|
8
|
-
* @param array The array to search the item in.
|
|
9
|
-
* @param id The `id` of the desired item.
|
|
10
|
-
* @returns The first item with the specified `id` or `undefined` if none exists.
|
|
11
|
-
*/
|
|
12
|
-
function find<Id, Item extends Identifiable<Id>>(array: Nullish<Item[]>, id: Id): Item | undefined {
|
|
13
|
-
if (isNullish(array)) return undefined
|
|
14
|
-
const filtered = array.filter(item => item.id === id)
|
|
15
|
-
if (filtered.length > 0) return filtered[0]
|
|
16
|
-
else return undefined
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Checks if the given array contains an item with the `id`.
|
|
21
|
-
* @param array The array to search the item in.
|
|
22
|
-
* @param id The `id` to check the array for.
|
|
23
|
-
* @returns `true` if there is at least one item in the array with the given `id`.
|
|
24
|
-
*/
|
|
25
|
-
function contains<Id, Item extends Identifiable<Id>>(array: Item[], id: Id): boolean {
|
|
26
|
-
return find(array, id) !== undefined
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function insertSingle<Id, Item extends Identifiable<Id>>(baseArray: Item[], insertItem: Item) {
|
|
30
|
-
const index = baseArray.findIndex(item => item.id === insertItem.id)
|
|
31
|
-
if (index === -1) {
|
|
32
|
-
baseArray.push(insertItem)
|
|
33
|
-
} else {
|
|
34
|
-
baseArray.splice(index, 1, insertItem)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Inserts the items into the given array, replacing items with the same `id`.
|
|
40
|
-
* If no item with the same `id` exists, the item is appended to the array.
|
|
41
|
-
* If multiple items with the same `id` exist, just the first item is replaced.
|
|
42
|
-
* @param array The array to insert the items into.
|
|
43
|
-
* @param insertItems The items to insert into the array.
|
|
44
|
-
* @returns The reference to the same array, which was passed.
|
|
45
|
-
*/
|
|
46
|
-
function insert<Id, Item extends Identifiable<Id>>(array: Item[], ...insertItems: Item[]): Item[] {
|
|
47
|
-
insertItems.forEach(item => insertSingle(array, item))
|
|
48
|
-
return array
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Removes all items with the specified `ids` from the given array.
|
|
53
|
-
* @param array The array to remove the items from.
|
|
54
|
-
* @param ids The `ids` of the items which should be removed.
|
|
55
|
-
* @returns The reference to the same array, which was passed.
|
|
56
|
-
*/
|
|
57
|
-
function remove<Id, Item extends Identifiable>(array: Item[], ...ids: Id[]): Item[] {
|
|
58
|
-
ids.forEach(id => {
|
|
59
|
-
let noMatches = false
|
|
60
|
-
while (!noMatches) {
|
|
61
|
-
const index = array.findIndex(item => item.id === id)
|
|
62
|
-
if (index != -1) array.splice(index, 1)
|
|
63
|
-
else noMatches = true
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
return array
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Compares the two arrays and checks if they both have
|
|
71
|
-
* items with the same `ids` in the same order.
|
|
72
|
-
* @param first The first array to compare.
|
|
73
|
-
* @param second The second array to compare.
|
|
74
|
-
* @returns `true` if the arrays contain item with the same `ids` in the same order.
|
|
75
|
-
*/
|
|
76
|
-
function areSameArrays<Id>(first: Identifiable<Id>[], second: Identifiable<Id>[]): boolean {
|
|
77
|
-
if (first.length != second.length) return false
|
|
78
|
-
for (let i = 0; i < first.length; i++) {
|
|
79
|
-
if (first[i]?.id !== second[i]?.id) return false
|
|
80
|
-
}
|
|
81
|
-
return true
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* This object contains utility functions to deal with {@link Identifiable} objects.
|
|
86
|
-
*/
|
|
87
|
-
export const Id = { find, contains, insert, remove, areSameArrays } as const
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns a shortened string with '...' at the end if it is longer than the given `maxLength`.
|
|
3
|
-
* @param input the string to shorten
|
|
4
|
-
* @param maxLength the max length
|
|
5
|
-
* @see maxLengthSplitCenter
|
|
6
|
-
*/
|
|
7
|
-
export function maxLength(input: string | null, maxLength: number): string {
|
|
8
|
-
if (input && input.length > maxLength) return `${input.substring(0, maxLength - 3).trim()}...`
|
|
9
|
-
else return input || ''
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Returns a shortened string with '...' in the center of the string if it is longer than the given `maxLength`.
|
|
14
|
-
* @param input the string to shorten
|
|
15
|
-
* @param maxLength the max length
|
|
16
|
-
* @see maxLength
|
|
17
|
-
*/
|
|
18
|
-
export function maxLengthSplitCenter(input: string | null, maxLength: number): string {
|
|
19
|
-
if (input && input.length > maxLength) {
|
|
20
|
-
const chars = maxLength - 3
|
|
21
|
-
const charsAtStart = Math.ceil(chars / 2)
|
|
22
|
-
const charsAtEnd = Math.floor(chars / 2)
|
|
23
|
-
return `${input.substring(0, charsAtStart).trim()}...${input.substring(input.length - charsAtEnd).trim()}`
|
|
24
|
-
} else return input || ''
|
|
25
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { FunctionalComponent, HTMLAttributes, VNodeProps } from 'vue'
|
|
2
|
-
|
|
3
|
-
export type TWTextSize =
|
|
4
|
-
| 'text-xs'
|
|
5
|
-
| 'text-sm'
|
|
6
|
-
| 'text-base'
|
|
7
|
-
| 'text-lg'
|
|
8
|
-
| 'text-xl'
|
|
9
|
-
| 'text-2xl'
|
|
10
|
-
| 'text-3xl'
|
|
11
|
-
| 'text-4xl'
|
|
12
|
-
| 'text-5xl'
|
|
13
|
-
| 'text-6xl'
|
|
14
|
-
| 'text-7xl'
|
|
15
|
-
| 'text-8xl'
|
|
16
|
-
| 'text-9xl'
|
|
17
|
-
|
|
18
|
-
export type TWMaxWidth =
|
|
19
|
-
| 'max-w-xs'
|
|
20
|
-
| 'max-w-sm'
|
|
21
|
-
| 'max-w-md'
|
|
22
|
-
| 'max-w-lg'
|
|
23
|
-
| 'max-w-xl'
|
|
24
|
-
| 'max-w-2xl'
|
|
25
|
-
| 'max-w-3xl'
|
|
26
|
-
| 'max-w-4xl'
|
|
27
|
-
| 'max-w-5xl'
|
|
28
|
-
| 'max-w-6xl'
|
|
29
|
-
| 'max-w-7xl'
|
|
30
|
-
| 'max-w-full'
|
|
31
|
-
| 'max-w-min'
|
|
32
|
-
| 'max-w-max'
|
|
33
|
-
| 'max-w-fit'
|
|
34
|
-
| 'max-w-prose'
|
|
35
|
-
| 'max-w-screen-sm'
|
|
36
|
-
| 'max-w-screen-md'
|
|
37
|
-
| 'max-w-screen-lg'
|
|
38
|
-
| 'max-w-screen-xl'
|
|
39
|
-
| 'max-w-screen-2xl'
|
|
40
|
-
|
|
41
|
-
export type HeroIcon = FunctionalComponent<HTMLAttributes & VNodeProps>
|
package/src/lib/utils/utils.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* ---------- Null and Undefined ----------
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { Ref } from 'vue'
|
|
6
|
-
|
|
7
|
-
export type Optional<T> = T | undefined
|
|
8
|
-
export type Nullable<T> = T | null
|
|
9
|
-
export type Nullish<T> = T | null | undefined
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Determines if a value is not null or undefined.
|
|
13
|
-
* @param value the value to check
|
|
14
|
-
* @returns `true` if the value is anything but `null` or `undefined`.
|
|
15
|
-
*/
|
|
16
|
-
export function notNullish<T>(value: Nullish<T>): value is T {
|
|
17
|
-
return value !== null && value !== undefined
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Determines if a value is null or undefined.
|
|
22
|
-
* @param value the value to check
|
|
23
|
-
* @returns `true` if the value is `null` or `undefined`.
|
|
24
|
-
*/
|
|
25
|
-
export function isNullish(value: Nullish<unknown>): value is null | undefined {
|
|
26
|
-
return value === null || value === undefined
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Determines if the value of a ref is not nullish.
|
|
31
|
-
* @param ref the ref to check
|
|
32
|
-
* @returns `true` if the value of the ref is not nullish.
|
|
33
|
-
* @see notNullish
|
|
34
|
-
*/
|
|
35
|
-
export function notNullishRef<T>(ref: Ref<T>): ref is Ref<NonNullable<T>> {
|
|
36
|
-
return notNullish(ref.value)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Determines if the value of a ref is null or undefined.
|
|
41
|
-
* @param ref the ref to check
|
|
42
|
-
* @returns `true` if the value of the ref is `null` or `undefined`.
|
|
43
|
-
* @see isNullish
|
|
44
|
-
*/
|
|
45
|
-
export function isNullishRef(ref: Ref<Nullish<unknown>>): ref is Ref<null | undefined> {
|
|
46
|
-
return isNullish(ref.value)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/*
|
|
50
|
-
* ---------- Objects ----------
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
export type AnyObject = Record<string | number | symbol, unknown>
|
|
54
|
-
export type EmptyObject = Record<string | number | symbol, never>
|
|
55
|
-
|
|
56
|
-
export function isAnyObject(object: unknown): object is AnyObject {
|
|
57
|
-
return typeof object === 'object' && !Array.isArray(object)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Marks all properties of an object (including sub-objects) as readonly.
|
|
62
|
-
*/
|
|
63
|
-
export type ReadonlyObject<T extends AnyObject> = {
|
|
64
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
65
|
-
readonly [P in keyof T]: T[P] extends ReadonlyObject<infer _U>
|
|
66
|
-
? T[P]
|
|
67
|
-
: T[P] extends AnyObject
|
|
68
|
-
? ReadonlyObject<T[P]>
|
|
69
|
-
: T[P]
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Returns the same object casted to a {@link ReadonlyObject}.
|
|
74
|
-
*/
|
|
75
|
-
export function readonlyObject<T extends AnyObject>(object: T): ReadonlyObject<T> {
|
|
76
|
-
return object as ReadonlyObject<T>
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/*
|
|
80
|
-
* ---------- Unique Id ----------
|
|
81
|
-
*/
|
|
82
|
-
|
|
83
|
-
let currentId = 1
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Generates and returns a non random but unique id.
|
|
87
|
-
*/
|
|
88
|
-
export function uniqueId(): number {
|
|
89
|
-
return currentId++
|
|
90
|
-
}
|