@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
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type Nullish } from './utils';
|
|
2
|
+
export type Identifiable<Id = string> = Readonly<{
|
|
3
|
+
id: Id;
|
|
4
|
+
}>;
|
|
5
|
+
export type MaybeIdentifiable<Id = string> = Readonly<{
|
|
6
|
+
id?: Nullish<Id>;
|
|
7
|
+
}>;
|
|
8
|
+
/**
|
|
9
|
+
* Looks for the `id` in the given array of `Identifiables`.
|
|
10
|
+
* @param array The array to search the item in.
|
|
11
|
+
* @param id The `id` of the desired item.
|
|
12
|
+
* @returns The first item with the specified `id` or `undefined` if none exists.
|
|
13
|
+
*/
|
|
14
|
+
declare function find<Id, Item extends Identifiable<Id>>(array: Nullish<Item[]>, id: Id): Item | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Checks if the given array contains an item with the `id`.
|
|
17
|
+
* @param array The array to search the item in.
|
|
18
|
+
* @param id The `id` to check the array for.
|
|
19
|
+
* @returns `true` if there is at least one item in the array with the given `id`.
|
|
20
|
+
*/
|
|
21
|
+
declare function contains<Id, Item extends Identifiable<Id>>(array: Item[], id: Id): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Inserts the items into the given array, replacing items with the same `id`.
|
|
24
|
+
* If no item with the same `id` exists, the item is appended to the array.
|
|
25
|
+
* If multiple items with the same `id` exist, just the first item is replaced.
|
|
26
|
+
* @param array The array to insert the items into.
|
|
27
|
+
* @param insertItems The items to insert into the array.
|
|
28
|
+
* @returns The reference to the same array, which was passed.
|
|
29
|
+
*/
|
|
30
|
+
declare function insert<Id, Item extends Identifiable<Id>>(array: Item[], ...insertItems: Item[]): Item[];
|
|
31
|
+
/**
|
|
32
|
+
* Removes all items with the specified `ids` from the given array.
|
|
33
|
+
* @param array The array to remove the items from.
|
|
34
|
+
* @param ids The `ids` of the items which should be removed.
|
|
35
|
+
* @returns The reference to the same array, which was passed.
|
|
36
|
+
*/
|
|
37
|
+
declare function remove<Id, Item extends Identifiable>(array: Item[], ...ids: Id[]): Item[];
|
|
38
|
+
/**
|
|
39
|
+
* Compares the two arrays and checks if they both have
|
|
40
|
+
* items with the same `ids` in the same order.
|
|
41
|
+
* @param first The first array to compare.
|
|
42
|
+
* @param second The second array to compare.
|
|
43
|
+
* @returns `true` if the arrays contain item with the same `ids` in the same order.
|
|
44
|
+
*/
|
|
45
|
+
declare function areSameArrays<Id>(first: Identifiable<Id>[], second: Identifiable<Id>[]): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* This object contains utility functions to deal with {@link Identifiable} objects.
|
|
48
|
+
*/
|
|
49
|
+
export declare const Id: {
|
|
50
|
+
readonly find: typeof find;
|
|
51
|
+
readonly contains: typeof contains;
|
|
52
|
+
readonly insert: typeof insert;
|
|
53
|
+
readonly remove: typeof remove;
|
|
54
|
+
readonly areSameArrays: typeof areSameArrays;
|
|
55
|
+
};
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { isNullish } from './utils';
|
|
2
|
+
/**
|
|
3
|
+
* Looks for the `id` in the given array of `Identifiables`.
|
|
4
|
+
* @param array The array to search the item in.
|
|
5
|
+
* @param id The `id` of the desired item.
|
|
6
|
+
* @returns The first item with the specified `id` or `undefined` if none exists.
|
|
7
|
+
*/
|
|
8
|
+
function find(array, id) {
|
|
9
|
+
if (isNullish(array)) return undefined;
|
|
10
|
+
const filtered = array.filter(item => item.id === id);
|
|
11
|
+
if (filtered.length > 0) return filtered[0];else return undefined;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Checks if the given array contains an item with the `id`.
|
|
15
|
+
* @param array The array to search the item in.
|
|
16
|
+
* @param id The `id` to check the array for.
|
|
17
|
+
* @returns `true` if there is at least one item in the array with the given `id`.
|
|
18
|
+
*/
|
|
19
|
+
function contains(array, id) {
|
|
20
|
+
return find(array, id) !== undefined;
|
|
21
|
+
}
|
|
22
|
+
function insertSingle(baseArray, insertItem) {
|
|
23
|
+
const index = baseArray.findIndex(item => item.id === insertItem.id);
|
|
24
|
+
if (index === -1) {
|
|
25
|
+
baseArray.push(insertItem);
|
|
26
|
+
} else {
|
|
27
|
+
baseArray.splice(index, 1, insertItem);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Inserts the items into the given array, replacing items with the same `id`.
|
|
32
|
+
* If no item with the same `id` exists, the item is appended to the array.
|
|
33
|
+
* If multiple items with the same `id` exist, just the first item is replaced.
|
|
34
|
+
* @param array The array to insert the items into.
|
|
35
|
+
* @param insertItems The items to insert into the array.
|
|
36
|
+
* @returns The reference to the same array, which was passed.
|
|
37
|
+
*/
|
|
38
|
+
function insert(array, ...insertItems) {
|
|
39
|
+
insertItems.forEach(item => insertSingle(array, item));
|
|
40
|
+
return array;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Removes all items with the specified `ids` from the given array.
|
|
44
|
+
* @param array The array to remove the items from.
|
|
45
|
+
* @param ids The `ids` of the items which should be removed.
|
|
46
|
+
* @returns The reference to the same array, which was passed.
|
|
47
|
+
*/
|
|
48
|
+
function remove(array, ...ids) {
|
|
49
|
+
ids.forEach(id => {
|
|
50
|
+
let noMatches = false;
|
|
51
|
+
while (!noMatches) {
|
|
52
|
+
const index = array.findIndex(item => item.id === id);
|
|
53
|
+
if (index != -1) array.splice(index, 1);else noMatches = true;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return array;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Compares the two arrays and checks if they both have
|
|
60
|
+
* items with the same `ids` in the same order.
|
|
61
|
+
* @param first The first array to compare.
|
|
62
|
+
* @param second The second array to compare.
|
|
63
|
+
* @returns `true` if the arrays contain item with the same `ids` in the same order.
|
|
64
|
+
*/
|
|
65
|
+
function areSameArrays(first, second) {
|
|
66
|
+
if (first.length != second.length) return false;
|
|
67
|
+
for (let i = 0; i < first.length; i++) {
|
|
68
|
+
if (first[i]?.id !== second[i]?.id) return false;
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* This object contains utility functions to deal with {@link Identifiable} objects.
|
|
74
|
+
*/
|
|
75
|
+
export const Id = {
|
|
76
|
+
find,
|
|
77
|
+
contains,
|
|
78
|
+
insert,
|
|
79
|
+
remove,
|
|
80
|
+
areSameArrays
|
|
81
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
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 declare function maxLength(input: string | null, maxLength: number): string;
|
|
8
|
+
/**
|
|
9
|
+
* Returns a shortened string with '...' in the center of the string if it is longer than the given `maxLength`.
|
|
10
|
+
* @param input the string to shorten
|
|
11
|
+
* @param maxLength the max length
|
|
12
|
+
* @see maxLength
|
|
13
|
+
*/
|
|
14
|
+
export declare function maxLengthSplitCenter(input: string | null, maxLength: number): string;
|
|
@@ -0,0 +1,23 @@
|
|
|
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, maxLength) {
|
|
8
|
+
if (input && input.length > maxLength) return `${input.substring(0, maxLength - 3).trim()}...`;else return input || '';
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Returns a shortened string with '...' in the center of the string if it is longer than the given `maxLength`.
|
|
12
|
+
* @param input the string to shorten
|
|
13
|
+
* @param maxLength the max length
|
|
14
|
+
* @see maxLength
|
|
15
|
+
*/
|
|
16
|
+
export function maxLengthSplitCenter(input, maxLength) {
|
|
17
|
+
if (input && input.length > maxLength) {
|
|
18
|
+
const chars = maxLength - 3;
|
|
19
|
+
const charsAtStart = Math.ceil(chars / 2);
|
|
20
|
+
const charsAtEnd = Math.floor(chars / 2);
|
|
21
|
+
return `${input.substring(0, charsAtStart).trim()}...${input.substring(input.length - charsAtEnd).trim()}`;
|
|
22
|
+
} else return input || '';
|
|
23
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FunctionalComponent, HTMLAttributes, VNodeProps } from 'vue';
|
|
2
|
+
export type TWTextSize = 'text-xs' | 'text-sm' | 'text-base' | 'text-lg' | 'text-xl' | 'text-2xl' | 'text-3xl' | 'text-4xl' | 'text-5xl' | 'text-6xl' | 'text-7xl' | 'text-8xl' | 'text-9xl';
|
|
3
|
+
export type TWMaxWidth = 'max-w-xs' | 'max-w-sm' | 'max-w-md' | 'max-w-lg' | 'max-w-xl' | 'max-w-2xl' | 'max-w-3xl' | 'max-w-4xl' | 'max-w-5xl' | 'max-w-6xl' | 'max-w-7xl' | 'max-w-full' | 'max-w-min' | 'max-w-max' | 'max-w-fit' | 'max-w-prose' | 'max-w-screen-sm' | 'max-w-screen-md' | 'max-w-screen-lg' | 'max-w-screen-xl' | 'max-w-screen-2xl';
|
|
4
|
+
export type HeroIcon = FunctionalComponent<HTMLAttributes & VNodeProps>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Ref } from 'vue';
|
|
2
|
+
export type Optional<T> = T | undefined;
|
|
3
|
+
export type Nullable<T> = T | null;
|
|
4
|
+
export type Nullish<T> = T | null | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* Determines if a value is not null or undefined.
|
|
7
|
+
* @param value the value to check
|
|
8
|
+
* @returns `true` if the value is anything but `null` or `undefined`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function notNullish<T>(value: Nullish<T>): value is T;
|
|
11
|
+
/**
|
|
12
|
+
* Determines if a value is null or undefined.
|
|
13
|
+
* @param value the value to check
|
|
14
|
+
* @returns `true` if the value is `null` or `undefined`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isNullish(value: Nullish<unknown>): value is null | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Determines if the value of a ref is not nullish.
|
|
19
|
+
* @param ref the ref to check
|
|
20
|
+
* @returns `true` if the value of the ref is not nullish.
|
|
21
|
+
* @see notNullish
|
|
22
|
+
*/
|
|
23
|
+
export declare function notNullishRef<T>(ref: Ref<T>): ref is Ref<NonNullable<T>>;
|
|
24
|
+
/**
|
|
25
|
+
* Determines if the value of a ref is null or undefined.
|
|
26
|
+
* @param ref the ref to check
|
|
27
|
+
* @returns `true` if the value of the ref is `null` or `undefined`.
|
|
28
|
+
* @see isNullish
|
|
29
|
+
*/
|
|
30
|
+
export declare function isNullishRef(ref: Ref<Nullish<unknown>>): ref is Ref<null | undefined>;
|
|
31
|
+
export type AnyObject = Record<string | number | symbol, unknown>;
|
|
32
|
+
export type EmptyObject = Record<string | number | symbol, never>;
|
|
33
|
+
export declare function isAnyObject(object: unknown): object is AnyObject;
|
|
34
|
+
/**
|
|
35
|
+
* Marks all properties of an object (including sub-objects) as readonly.
|
|
36
|
+
*/
|
|
37
|
+
export type ReadonlyObject<T extends AnyObject> = {
|
|
38
|
+
readonly [P in keyof T]: T[P] extends ReadonlyObject<infer _U> ? T[P] : T[P] extends AnyObject ? ReadonlyObject<T[P]> : T[P];
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Returns the same object casted to a {@link ReadonlyObject}.
|
|
42
|
+
*/
|
|
43
|
+
export declare function readonlyObject<T extends AnyObject>(object: T): ReadonlyObject<T>;
|
|
44
|
+
/**
|
|
45
|
+
* Generates and returns a non random but unique id.
|
|
46
|
+
*/
|
|
47
|
+
export declare function uniqueId(): number;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ---------- Null and Undefined ----------
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Determines if a value is not null or undefined.
|
|
6
|
+
* @param value the value to check
|
|
7
|
+
* @returns `true` if the value is anything but `null` or `undefined`.
|
|
8
|
+
*/
|
|
9
|
+
export function notNullish(value) {
|
|
10
|
+
return value !== null && value !== undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Determines if a value is null or undefined.
|
|
14
|
+
* @param value the value to check
|
|
15
|
+
* @returns `true` if the value is `null` or `undefined`.
|
|
16
|
+
*/
|
|
17
|
+
export function isNullish(value) {
|
|
18
|
+
return value === null || value === undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Determines if the value of a ref is not nullish.
|
|
22
|
+
* @param ref the ref to check
|
|
23
|
+
* @returns `true` if the value of the ref is not nullish.
|
|
24
|
+
* @see notNullish
|
|
25
|
+
*/
|
|
26
|
+
export function notNullishRef(ref) {
|
|
27
|
+
return notNullish(ref.value);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Determines if the value of a ref is null or undefined.
|
|
31
|
+
* @param ref the ref to check
|
|
32
|
+
* @returns `true` if the value of the ref is `null` or `undefined`.
|
|
33
|
+
* @see isNullish
|
|
34
|
+
*/
|
|
35
|
+
export function isNullishRef(ref) {
|
|
36
|
+
return isNullish(ref.value);
|
|
37
|
+
}
|
|
38
|
+
export function isAnyObject(object) {
|
|
39
|
+
return typeof object === 'object' && !Array.isArray(object);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Returns the same object casted to a {@link ReadonlyObject}.
|
|
43
|
+
*/
|
|
44
|
+
export function readonlyObject(object) {
|
|
45
|
+
return object;
|
|
46
|
+
}
|
|
47
|
+
/*
|
|
48
|
+
* ---------- Unique Id ----------
|
|
49
|
+
*/
|
|
50
|
+
let currentId = 1;
|
|
51
|
+
/**
|
|
52
|
+
* Generates and returns a non random but unique id.
|
|
53
|
+
*/
|
|
54
|
+
export function uniqueId() {
|
|
55
|
+
return currentId++;
|
|
56
|
+
}
|
|
@@ -1,104 +1,76 @@
|
|
|
1
|
-
import type { PropType, Ref } from 'vue'
|
|
2
|
-
import type { AnyObject } from './utils'
|
|
3
|
-
|
|
4
|
-
/*
|
|
5
|
-
* ---------- VModel as Props ----------
|
|
6
|
-
*/
|
|
7
|
-
|
|
1
|
+
import type { PropType, Ref } from 'vue';
|
|
2
|
+
import type { AnyObject } from './utils';
|
|
8
3
|
/**
|
|
9
4
|
* Creates props for a `v-model` of the given type.
|
|
10
5
|
* A `v-model` consits of a value-property and a update-function.
|
|
11
6
|
* @param propType The propType of the `v-model`.
|
|
12
7
|
* @returns An object containing the value-property and the update-function.
|
|
13
8
|
*/
|
|
14
|
-
export function vModelProps<T>(propType: PropType<T>) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
} as const
|
|
25
|
-
}
|
|
26
|
-
|
|
9
|
+
export declare function vModelProps<T>(propType: PropType<T>): {
|
|
10
|
+
/**
|
|
11
|
+
* The value of the component.
|
|
12
|
+
*/
|
|
13
|
+
readonly value: PropType<T>;
|
|
14
|
+
/**
|
|
15
|
+
* This will be called, when the value of the component has changed.
|
|
16
|
+
*/
|
|
17
|
+
readonly onUpdateValue: PropType<(newValue: T) => void>;
|
|
18
|
+
};
|
|
27
19
|
/**
|
|
28
20
|
* Creates props for a required `v-model` of the given type.
|
|
29
21
|
* @see {@link vModelProps}
|
|
30
22
|
*/
|
|
31
|
-
export function vModelRequiredProps<T>(propType: PropType<T>) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
} as const
|
|
45
|
-
}
|
|
46
|
-
|
|
23
|
+
export declare function vModelRequiredProps<T>(propType: PropType<T>): {
|
|
24
|
+
/**
|
|
25
|
+
* The value of the component.
|
|
26
|
+
*/
|
|
27
|
+
readonly value: {
|
|
28
|
+
readonly type: PropType<T>;
|
|
29
|
+
readonly required: true;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* This will be called, when the value of the component has changed.
|
|
33
|
+
*/
|
|
34
|
+
readonly onUpdateValue: PropType<(newValue: T) => void>;
|
|
35
|
+
};
|
|
47
36
|
/**
|
|
48
37
|
* Creates props for a `v-model` of the given type with a default value.
|
|
49
38
|
* @see {@link vModelProps}
|
|
50
39
|
*/
|
|
51
|
-
export function vModelDefaultProps<T>(propType: PropType<T>, defaultValue: () => T) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
} as const
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/*
|
|
68
|
-
* ---------- VModel to pass to components ----------
|
|
69
|
-
*/
|
|
70
|
-
|
|
40
|
+
export declare function vModelDefaultProps<T>(propType: PropType<T>, defaultValue: () => T): {
|
|
41
|
+
/**
|
|
42
|
+
* The value of the component.
|
|
43
|
+
*/
|
|
44
|
+
readonly value: {
|
|
45
|
+
readonly type: PropType<T>;
|
|
46
|
+
readonly default: () => T;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* This will be called, when the value of the component has changed.
|
|
50
|
+
*/
|
|
51
|
+
readonly onUpdateValue: PropType<(newValue: T) => void>;
|
|
52
|
+
};
|
|
71
53
|
/**
|
|
72
54
|
* The `VModel` type contains a value and an optional update-function.
|
|
73
55
|
* This object is passed to a component to create a two-way binding.
|
|
74
56
|
*/
|
|
75
57
|
export type VModel<T, U = T> = {
|
|
76
|
-
value: T
|
|
77
|
-
onUpdateValue?: (newValue: U) => void
|
|
78
|
-
}
|
|
79
|
-
|
|
58
|
+
value: T;
|
|
59
|
+
onUpdateValue?: (newValue: U) => void;
|
|
60
|
+
};
|
|
80
61
|
/**
|
|
81
62
|
* The `VModelForArray` contains the normal `VModel` properties,
|
|
82
63
|
* but aditionally a function, which removes the value from the array.
|
|
83
64
|
*/
|
|
84
65
|
export type VModelForArray<T, U = T> = VModel<T, U> & {
|
|
85
|
-
remove(): void
|
|
86
|
-
}
|
|
87
|
-
|
|
66
|
+
remove(): void;
|
|
67
|
+
};
|
|
88
68
|
/**
|
|
89
69
|
* Uses the given `ref` as a `v-model`, to create a two-way binding with the `ref`.
|
|
90
70
|
* @param ref The `ref` which should be used as the `v-model`.
|
|
91
71
|
* @returns An object of type {@link VModel}, which connects the `ref` to the `v-model`.
|
|
92
72
|
*/
|
|
93
|
-
export function vModelForRef<T>(ref: Ref<T>): VModel<T
|
|
94
|
-
return {
|
|
95
|
-
value: ref.value,
|
|
96
|
-
onUpdateValue: (newValue: T) => {
|
|
97
|
-
ref.value = newValue
|
|
98
|
-
},
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
73
|
+
export declare function vModelForRef<T>(ref: Ref<T>): VModel<T>;
|
|
102
74
|
/**
|
|
103
75
|
* This creates a `v-model` for a property of an object. The property of the object is taken as the
|
|
104
76
|
* value of the `v-model`, the `onUpdate` function, is called every time when the property is updated
|
|
@@ -121,19 +93,7 @@ export function vModelForRef<T>(ref: Ref<T>): VModel<T> {
|
|
|
121
93
|
* )
|
|
122
94
|
* ```
|
|
123
95
|
*/
|
|
124
|
-
export function vModelForObjectProperty<T extends AnyObject, K extends keyof T>(
|
|
125
|
-
object: T,
|
|
126
|
-
key: K,
|
|
127
|
-
onUpdate?: (newValue: T) => void
|
|
128
|
-
): VModel<T[K]> {
|
|
129
|
-
return {
|
|
130
|
-
value: object[key],
|
|
131
|
-
onUpdateValue: (newValue: T[K]) => {
|
|
132
|
-
onUpdate?.({ ...object, [key]: newValue })
|
|
133
|
-
},
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
96
|
+
export declare function vModelForObjectProperty<T extends AnyObject, K extends keyof T>(object: T, key: K, onUpdate?: (newValue: T) => void): VModel<T[K]>;
|
|
137
97
|
/**
|
|
138
98
|
* This creates a `v-model` which operates on one property of a parent `v-model`. It takes the value of
|
|
139
99
|
* the property as the value of the `v-model` and calls the function `onUpdateValue` of the parent `v-model`
|
|
@@ -163,19 +123,7 @@ export function vModelForObjectProperty<T extends AnyObject, K extends keyof T>(
|
|
|
163
123
|
* )
|
|
164
124
|
* ```
|
|
165
125
|
*/
|
|
166
|
-
export function vModelForVModelProperty<
|
|
167
|
-
Model extends VModel<ModelValue>,
|
|
168
|
-
Key extends keyof ModelValue,
|
|
169
|
-
ModelValue extends AnyObject = Model['value'],
|
|
170
|
-
>(vModel: Model, key: Key): VModel<ModelValue[Key]> {
|
|
171
|
-
return {
|
|
172
|
-
value: vModel.value[key],
|
|
173
|
-
onUpdateValue: (newValue: ModelValue[Key]) => {
|
|
174
|
-
vModel.onUpdateValue?.({ ...vModel.value, [key]: newValue })
|
|
175
|
-
},
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
126
|
+
export declare function vModelForVModelProperty<Model extends VModel<ModelValue>, Key extends keyof ModelValue, ModelValue extends AnyObject = Model['value']>(vModel: Model, key: Key): VModel<ModelValue[Key]>;
|
|
179
127
|
/**
|
|
180
128
|
* This function does the same thing as {@link vModelForVModelProperty},
|
|
181
129
|
* but can be provided with a mapper function for the modified property.
|
|
@@ -206,20 +154,7 @@ export function vModelForVModelProperty<
|
|
|
206
154
|
* )
|
|
207
155
|
* ```
|
|
208
156
|
*/
|
|
209
|
-
export function vModelForVModelPropertyMapType<
|
|
210
|
-
Model extends VModel<ModelValue>,
|
|
211
|
-
Key extends keyof ModelValue,
|
|
212
|
-
UpdateValue,
|
|
213
|
-
ModelValue extends AnyObject = Model['value'],
|
|
214
|
-
>(vModel: Model, key: Key, mapType: (value: UpdateValue) => ModelValue[Key]): VModel<ModelValue[Key], UpdateValue> {
|
|
215
|
-
return {
|
|
216
|
-
value: vModel.value[key],
|
|
217
|
-
onUpdateValue: (newValue: UpdateValue) => {
|
|
218
|
-
vModel.onUpdateValue?.({ ...vModel.value, [key]: mapType(newValue) })
|
|
219
|
-
},
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
157
|
+
export declare function vModelForVModelPropertyMapType<Model extends VModel<ModelValue>, Key extends keyof ModelValue, UpdateValue, ModelValue extends AnyObject = Model['value']>(vModel: Model, key: Key, mapType: (value: UpdateValue) => ModelValue[Key]): VModel<ModelValue[Key], UpdateValue>;
|
|
223
158
|
/**
|
|
224
159
|
* Creates an array of `v-models`, one for every element of an array. All changes in
|
|
225
160
|
* a `v-model` of any element, will call the `onUpdate` function, with the updated array.
|
|
@@ -244,17 +179,4 @@ export function vModelForVModelPropertyMapType<
|
|
|
244
179
|
* )
|
|
245
180
|
* ```
|
|
246
181
|
*/
|
|
247
|
-
export function vModelsForArray<T>(array: T[], onUpdate?: (newValue: T[]) => void): VModelForArray<T>[]
|
|
248
|
-
return array.map((entry, index) => ({
|
|
249
|
-
value: entry,
|
|
250
|
-
onUpdateValue: (entry: T) => {
|
|
251
|
-
const newArray = [...array]
|
|
252
|
-
newArray[index] = entry
|
|
253
|
-
onUpdate?.(newArray)
|
|
254
|
-
},
|
|
255
|
-
remove: () => {
|
|
256
|
-
const newArray = [...array.slice(0, index), ...array.slice(index + 1)]
|
|
257
|
-
onUpdate?.(newArray)
|
|
258
|
-
},
|
|
259
|
-
}))
|
|
260
|
-
}
|
|
182
|
+
export declare function vModelsForArray<T>(array: T[], onUpdate?: (newValue: T[]) => void): VModelForArray<T>[];
|