@naptics/vue-collection 0.0.1

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.
Files changed (105) hide show
  1. package/README.md +27 -0
  2. package/lib/components/NAlert.d.ts +72 -0
  3. package/lib/components/NAlert.jsx +69 -0
  4. package/lib/components/NBadge.d.ts +174 -0
  5. package/lib/components/NBadge.jsx +58 -0
  6. package/lib/components/NBreadcrub.d.ts +161 -0
  7. package/lib/components/NBreadcrub.jsx +64 -0
  8. package/lib/components/NButton.d.ts +149 -0
  9. package/lib/components/NButton.jsx +58 -0
  10. package/lib/components/NCheckbox.d.ts +51 -0
  11. package/lib/components/NCheckbox.jsx +38 -0
  12. package/lib/components/NCheckboxLabel.d.ts +70 -0
  13. package/lib/components/NCheckboxLabel.jsx +42 -0
  14. package/lib/components/NCrudModal.d.ts +301 -0
  15. package/lib/components/NCrudModal.jsx +89 -0
  16. package/lib/components/NDialog.d.ts +190 -0
  17. package/lib/components/NDialog.jsx +144 -0
  18. package/lib/components/NDropdown.d.ts +116 -0
  19. package/lib/components/NDropdown.jsx +92 -0
  20. package/lib/components/NDropzone.d.ts +162 -0
  21. package/lib/components/NDropzone.jsx +211 -0
  22. package/lib/components/NForm.d.ts +43 -0
  23. package/lib/components/NForm.jsx +26 -0
  24. package/lib/components/NFormModal.d.ts +190 -0
  25. package/lib/components/NFormModal.jsx +48 -0
  26. package/lib/components/NIconButton.d.ts +202 -0
  27. package/lib/components/NIconButton.jsx +71 -0
  28. package/lib/components/NIconCircle.d.ts +135 -0
  29. package/lib/components/NIconCircle.jsx +67 -0
  30. package/lib/components/NInput.css +11 -0
  31. package/lib/components/NInput.d.ts +232 -0
  32. package/lib/components/NInput.jsx +97 -0
  33. package/lib/components/NInputPhone.d.ts +150 -0
  34. package/lib/components/NInputPhone.jsx +31 -0
  35. package/lib/components/NInputSelect.d.ts +271 -0
  36. package/lib/components/NInputSelect.jsx +89 -0
  37. package/lib/components/NInputSuggestion.d.ts +212 -0
  38. package/lib/components/NInputSuggestion.jsx +48 -0
  39. package/lib/components/NLink.d.ts +111 -0
  40. package/lib/components/NLink.jsx +58 -0
  41. package/lib/components/NList.d.ts +43 -0
  42. package/lib/components/NList.jsx +24 -0
  43. package/lib/components/NLoadingIndicator.css +46 -0
  44. package/lib/components/NLoadingIndicator.d.ts +77 -0
  45. package/lib/components/NLoadingIndicator.jsx +42 -0
  46. package/lib/components/NModal.d.ts +333 -0
  47. package/lib/components/NModal.jsx +170 -0
  48. package/lib/components/NPagination.css +15 -0
  49. package/lib/components/NPagination.d.ts +99 -0
  50. package/lib/components/NPagination.jsx +104 -0
  51. package/lib/components/NSearchbar.d.ts +94 -0
  52. package/lib/components/NSearchbar.jsx +58 -0
  53. package/lib/components/NSearchbarList.d.ts +90 -0
  54. package/lib/components/NSearchbarList.jsx +20 -0
  55. package/lib/components/NSelect.d.ts +159 -0
  56. package/lib/components/NSelect.jsx +81 -0
  57. package/lib/components/NSuggestionList.d.ts +275 -0
  58. package/lib/components/NSuggestionList.jsx +157 -0
  59. package/lib/components/NTable.css +3 -0
  60. package/lib/components/NTable.d.ts +187 -0
  61. package/lib/components/NTable.jsx +146 -0
  62. package/lib/components/NTableAction.d.ts +74 -0
  63. package/lib/components/NTableAction.jsx +35 -0
  64. package/lib/components/NTextArea.d.ts +252 -0
  65. package/lib/components/NTextArea.jsx +108 -0
  66. package/lib/components/NTooltip.css +37 -0
  67. package/lib/components/NTooltip.d.ts +186 -0
  68. package/lib/components/NTooltip.jsx +161 -0
  69. package/lib/components/NValInput.d.ts +297 -0
  70. package/lib/components/NValInput.jsx +101 -0
  71. package/lib/components/ValidatedForm.d.ts +34 -0
  72. package/lib/components/ValidatedForm.js +25 -0
  73. package/lib/i18n/de/template.json +10 -0
  74. package/lib/i18n/de/vue-collection.json +58 -0
  75. package/lib/i18n/de.d.ts +61 -0
  76. package/lib/i18n/de.js +5 -0
  77. package/lib/i18n/en/template.json +10 -0
  78. package/lib/i18n/en/vue-collection.json +58 -0
  79. package/lib/i18n/en.d.ts +61 -0
  80. package/lib/i18n/en.js +5 -0
  81. package/lib/i18n/index.d.ts +17 -0
  82. package/lib/i18n/index.js +34 -0
  83. package/lib/index.d.ts +64 -0
  84. package/lib/index.js +65 -0
  85. package/lib/utils/breakpoints.d.ts +15 -0
  86. package/lib/utils/breakpoints.js +37 -0
  87. package/lib/utils/component.d.ts +50 -0
  88. package/lib/utils/component.js +51 -0
  89. package/lib/utils/deferred.d.ts +13 -0
  90. package/lib/utils/deferred.js +17 -0
  91. package/lib/utils/identifiable.d.ts +57 -0
  92. package/lib/utils/identifiable.js +78 -0
  93. package/lib/utils/stringMaxLength.d.ts +14 -0
  94. package/lib/utils/stringMaxLength.js +28 -0
  95. package/lib/utils/tailwind.d.ts +2 -0
  96. package/lib/utils/tailwind.js +1 -0
  97. package/lib/utils/utils.d.ts +27 -0
  98. package/lib/utils/utils.js +26 -0
  99. package/lib/utils/vModel.d.ts +182 -0
  100. package/lib/utils/vModel.js +215 -0
  101. package/lib/utils/validation.d.ts +84 -0
  102. package/lib/utils/validation.js +163 -0
  103. package/lib/utils/vue.d.ts +13 -0
  104. package/lib/utils/vue.js +19 -0
  105. package/package.json +56 -0
@@ -0,0 +1,37 @@
1
+ import { computed, ref } from 'vue';
2
+ export const breakpoints = {
3
+ sm: 640,
4
+ md: 768,
5
+ lg: 1024,
6
+ xl: 1280,
7
+ '2xl': 1536,
8
+ };
9
+ export const bodyWidth = ref(document.body.clientWidth);
10
+ /**
11
+ * This function has to be called once in the app two ensure that the breakpoint utilities actually update.
12
+ * It sets a `window.onresize` listener.
13
+ */
14
+ export function addDocumentResizeEventListener() {
15
+ window.onresize = () => {
16
+ bodyWidth.value = document.body.clientWidth;
17
+ };
18
+ }
19
+ export function isWidthBreakpoint(breakpoint) {
20
+ switch (breakpoint) {
21
+ case 'sm':
22
+ return isWidthSm;
23
+ case 'md':
24
+ return isWidthMd;
25
+ case 'lg':
26
+ return isWidthLg;
27
+ case 'xl':
28
+ return isWidthXl;
29
+ case '2xl':
30
+ return isWidth2xl;
31
+ }
32
+ }
33
+ export const isWidth2xl = computed(() => bodyWidth.value > breakpoints['2xl']);
34
+ export const isWidthXl = computed(() => bodyWidth.value > breakpoints.xl);
35
+ export const isWidthLg = computed(() => bodyWidth.value > breakpoints.lg);
36
+ export const isWidthMd = computed(() => bodyWidth.value > breakpoints.md);
37
+ export const isWidthSm = computed(() => bodyWidth.value > breakpoints.sm);
@@ -0,0 +1,50 @@
1
+ import type { LooseRequired } from '@vue/shared';
2
+ import { type ComponentObjectPropsOptions, type ExtractPropTypes, type RenderFunction, type SetupContext, type ToRefs, type UnwrapNestedRefs } from 'vue';
3
+ type Data = Record<string, unknown>;
4
+ export type Props<T = Data> = ComponentObjectPropsOptions<T>;
5
+ /**
6
+ * `ExtractedProps` maps a prop object to the props, which are received in the `setup` function of a components.
7
+ */
8
+ export type ExtractedProps<T extends Props> = Readonly<LooseRequired<Readonly<ExtractPropTypes<T>>>>;
9
+ /**
10
+ * Components should be created using this helper function.
11
+ * It only takes three arguments, the name and the props of the component and the setup function.
12
+ * All other arguments which the {@link defineComponent} method of vue may provide,
13
+ * should not be used for a better consistency across all components.
14
+ * @param name the name of the component, should be more than one word.
15
+ * @param props the props of the component.
16
+ * @param setup the setup function, which will be called when the component is mounted.
17
+ * @returns the created vue-component.
18
+ */
19
+ export declare function createComponent<T extends Props>(name: string, props: T, setup: (props: ExtractedProps<T>, context: SetupContext<never[]>) => RenderFunction | Promise<RenderFunction>): import("vue").DefineComponent<T, RenderFunction, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, never[], never, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<T extends import("vue").ComponentPropsOptions<{
20
+ [x: string]: unknown;
21
+ }> ? ExtractPropTypes<T> : T> & {}, import("vue").ExtractDefaultPropTypes<T>>;
22
+ /**
23
+ * Views should be created using this helper function. Views are special components, which don't have props.
24
+ * They are often the parent objects in a view hierarchy and contain many components.
25
+ * This function is syntactic sugar to create views and just calls {@link createComponent}.
26
+ * @param name the name of the component, should be more than one word.
27
+ * @param setup the setup function, which will be called when the component is mounted.
28
+ * @returns the created vue-component.
29
+ */
30
+ export declare function createView(name: string, setup: (context: SetupContext<never[]>) => RenderFunction | Promise<RenderFunction>): import("vue").DefineComponent<{}, RenderFunction, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, never[], never, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<ExtractPropTypes<{}>> & {}, {}>;
31
+ /**
32
+ * If props are specified outside of the {@link createComponent}
33
+ * function - e.g. to export them or for better code style -
34
+ * this helper function can be used to ensure strict typing.
35
+ * @param props the props which should be created.
36
+ * @returns the created props, with correct typing.
37
+ */
38
+ export declare function createProps<T extends Props>(props: T): T;
39
+ /**
40
+ * Extracts props from another prop object and returns a reactive object with the specified props.
41
+ * @param props the props to extract from
42
+ * @param keys the keys to extract from the props
43
+ * @returns the new object with the specified props
44
+ * @example
45
+ * const parentProps = { title: 'hi', text: 'ho' }
46
+ * const childProps = extractProps(parentProps, 'title')
47
+ * console.log(childProps) // { title: 'hi' }
48
+ */
49
+ export declare function extractProps<T extends Record<string, unknown>>(props: T, ...keys: (keyof T)[]): UnwrapNestedRefs<Partial<ToRefs<T>>>;
50
+ export {};
@@ -0,0 +1,51 @@
1
+ import { defineComponent, reactive, toRef, } from 'vue';
2
+ /**
3
+ * Components should be created using this helper function.
4
+ * It only takes three arguments, the name and the props of the component and the setup function.
5
+ * All other arguments which the {@link defineComponent} method of vue may provide,
6
+ * should not be used for a better consistency across all components.
7
+ * @param name the name of the component, should be more than one word.
8
+ * @param props the props of the component.
9
+ * @param setup the setup function, which will be called when the component is mounted.
10
+ * @returns the created vue-component.
11
+ */
12
+ export function createComponent(name, props, setup) {
13
+ return defineComponent({ name, props, emits: [], setup });
14
+ }
15
+ /**
16
+ * Views should be created using this helper function. Views are special components, which don't have props.
17
+ * They are often the parent objects in a view hierarchy and contain many components.
18
+ * This function is syntactic sugar to create views and just calls {@link createComponent}.
19
+ * @param name the name of the component, should be more than one word.
20
+ * @param setup the setup function, which will be called when the component is mounted.
21
+ * @returns the created vue-component.
22
+ */
23
+ export function createView(name, setup) {
24
+ return defineComponent({ name, emits: [], setup: (props, context) => setup(context) });
25
+ }
26
+ /**
27
+ * If props are specified outside of the {@link createComponent}
28
+ * function - e.g. to export them or for better code style -
29
+ * this helper function can be used to ensure strict typing.
30
+ * @param props the props which should be created.
31
+ * @returns the created props, with correct typing.
32
+ */
33
+ export function createProps(props) {
34
+ return props;
35
+ }
36
+ /**
37
+ * Extracts props from another prop object and returns a reactive object with the specified props.
38
+ * @param props the props to extract from
39
+ * @param keys the keys to extract from the props
40
+ * @returns the new object with the specified props
41
+ * @example
42
+ * const parentProps = { title: 'hi', text: 'ho' }
43
+ * const childProps = extractProps(parentProps, 'title')
44
+ * console.log(childProps) // { title: 'hi' }
45
+ */
46
+ export function extractProps(props, ...keys) {
47
+ const partial = {};
48
+ for (const key of keys)
49
+ partial[key] = toRef(props, key);
50
+ return reactive(partial);
51
+ }
@@ -0,0 +1,13 @@
1
+ type PromiseResolve<T> = (value: T | PromiseLike<T>) => void;
2
+ type PromiseReject = (reason?: unknown) => void;
3
+ export type DeferredPromise<T> = {
4
+ promise: Promise<T>;
5
+ resolve: PromiseResolve<T>;
6
+ reject: PromiseReject;
7
+ };
8
+ /**
9
+ * Utlitity to return a deferred promise, which can be resolved from outside.
10
+ * @returns promise, resolve and reject
11
+ */
12
+ export declare function deferred<T>(): DeferredPromise<T>;
13
+ export {};
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Utlitity to return a deferred promise, which can be resolved from outside.
3
+ * @returns promise, resolve and reject
4
+ */
5
+ export function deferred() {
6
+ let resolve;
7
+ let reject;
8
+ const promise = new Promise((_resolve, _reject) => {
9
+ resolve = _resolve;
10
+ reject = _reject;
11
+ });
12
+ return {
13
+ promise,
14
+ resolve,
15
+ reject,
16
+ };
17
+ }
@@ -0,0 +1,57 @@
1
+ import { type Nullish } from './utils';
2
+ type IdType = string;
3
+ export type Identifiable = Readonly<{
4
+ id: IdType;
5
+ }>;
6
+ export type MaybeIdentifiable = Readonly<{
7
+ id?: Nullish<IdType>;
8
+ }>;
9
+ /**
10
+ * Looks for the `id` in the given array of `Identifiables`.
11
+ * @param array The array to search the item in.
12
+ * @param id The `id` of the desired item.
13
+ * @returns The first item with the specified `id` or `undefined` if none exists.
14
+ */
15
+ declare function find<T extends Identifiable>(array: T[], id: IdType): T | undefined;
16
+ /**
17
+ * Checks if the given array contains an item with the `id`.
18
+ * @param array The array to search the item in.
19
+ * @param id The `id` to check the array for.
20
+ * @returns `true` if there is at least one item in the array with the given `id`.
21
+ */
22
+ declare function contains<T extends Identifiable>(array: T[], id: IdType): boolean;
23
+ /**
24
+ * Inserts the items into the given array, replacing items with the same `id`.
25
+ * If no item with the same `id` exists, the item is appended to the array.
26
+ * If multiple items with the same `id` exist, just the first item is replaced.
27
+ * @param array The array to insert the items into.
28
+ * @param insertItems The items to insert into the array.
29
+ * @returns The reference to the same array, which was passed.
30
+ */
31
+ declare function insert<T extends Identifiable>(array: T[], ...insertItems: T[]): T[];
32
+ /**
33
+ * Removes all items with the specified `ids` from the given array.
34
+ * @param array The array to remove the items from.
35
+ * @param ids The `ids` of the items which should be removed.
36
+ * @returns The reference to the same array, which was passed.
37
+ */
38
+ declare function remove<T extends Identifiable>(array: T[], ...ids: IdType[]): T[];
39
+ /**
40
+ * Compares the two arrays and checks if they both have
41
+ * items with the same `ids` in the same order.
42
+ * @param first The first array to compare.
43
+ * @param second The second array to compare.
44
+ * @returns `true` if the arrays contain item with the same `ids` in the same order.
45
+ */
46
+ declare function areSameArrays(first: Identifiable[], second: Identifiable[]): boolean;
47
+ /**
48
+ * This object contains utility functions to deal with {@link Identifiable} objects.
49
+ */
50
+ export declare const Id: import("./utils").ReadonlyObject<{
51
+ find: typeof find;
52
+ contains: typeof contains;
53
+ insert: typeof insert;
54
+ remove: typeof remove;
55
+ areSameArrays: typeof areSameArrays;
56
+ }>;
57
+ export {};
@@ -0,0 +1,78 @@
1
+ import { markReadonly } 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
+ const filtered = array.filter(item => item.id === id);
10
+ if (filtered.length > 0)
11
+ return filtered[0];
12
+ else
13
+ return undefined;
14
+ }
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
+ function contains(array, id) {
22
+ return find(array, id) !== undefined;
23
+ }
24
+ function insertSingle(baseArray, insertItem) {
25
+ const index = baseArray.findIndex(item => item.id === insertItem.id);
26
+ index === -1 ? baseArray.push(insertItem) : baseArray.splice(index, 1, insertItem);
27
+ }
28
+ /**
29
+ * Inserts the items into the given array, replacing items with the same `id`.
30
+ * If no item with the same `id` exists, the item is appended to the array.
31
+ * If multiple items with the same `id` exist, just the first item is replaced.
32
+ * @param array The array to insert the items into.
33
+ * @param insertItems The items to insert into the array.
34
+ * @returns The reference to the same array, which was passed.
35
+ */
36
+ function insert(array, ...insertItems) {
37
+ insertItems.forEach(item => insertSingle(array, item));
38
+ return array;
39
+ }
40
+ /**
41
+ * Removes all items with the specified `ids` from the given array.
42
+ * @param array The array to remove the items from.
43
+ * @param ids The `ids` of the items which should be removed.
44
+ * @returns The reference to the same array, which was passed.
45
+ */
46
+ function remove(array, ...ids) {
47
+ ids.forEach(id => {
48
+ let noMatches = false;
49
+ while (!noMatches) {
50
+ const index = array.findIndex(item => item.id === id);
51
+ if (index != -1)
52
+ array.splice(index, 1);
53
+ else
54
+ noMatches = true;
55
+ }
56
+ });
57
+ return array;
58
+ }
59
+ /**
60
+ * Compares the two arrays and checks if they both have
61
+ * items with the same `ids` in the same order.
62
+ * @param first The first array to compare.
63
+ * @param second The second array to compare.
64
+ * @returns `true` if the arrays contain item with the same `ids` in the same order.
65
+ */
66
+ function areSameArrays(first, second) {
67
+ if (first.length != second.length)
68
+ return false;
69
+ for (let i = 0; i < first.length; i++) {
70
+ if (first[i]?.id !== second[i]?.id)
71
+ return false;
72
+ }
73
+ return true;
74
+ }
75
+ /**
76
+ * This object contains utility functions to deal with {@link Identifiable} objects.
77
+ */
78
+ export const Id = markReadonly({ find, contains, insert, remove, areSameArrays });
@@ -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,28 @@
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)
9
+ return `${input.substring(0, maxLength - 3).trim()}...`;
10
+ else
11
+ return input || '';
12
+ }
13
+ /**
14
+ * Returns a shortened string with '...' in the center of the string if it is longer than the given `maxLength`.
15
+ * @param input the string to shorten
16
+ * @param maxLength the max length
17
+ * @see maxLength
18
+ */
19
+ export function maxLengthSplitCenter(input, maxLength) {
20
+ if (input && input.length > maxLength) {
21
+ const chars = maxLength - 3;
22
+ const charsAtStart = Math.ceil(chars / 2);
23
+ const charsAtEnd = Math.floor(chars / 2);
24
+ return `${input.substring(0, charsAtStart).trim()}...${input.substring(input.length - charsAtEnd).trim()}`;
25
+ }
26
+ else
27
+ return input || '';
28
+ }
@@ -0,0 +1,2 @@
1
+ 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';
2
+ 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';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ import type { FunctionalComponent, HTMLAttributes, VNodeProps } from 'vue';
2
+ export type AnyObject = Record<string | number | symbol, unknown>;
3
+ export type EmptyObject = Record<string, never>;
4
+ export type Optional<T> = T | undefined;
5
+ export type Nullable<T> = T | null;
6
+ export type Nullish<T> = T | null | undefined;
7
+ export type HeroIcon = FunctionalComponent<HTMLAttributes & VNodeProps>;
8
+ export type ReadonlyObject<T extends AnyObject> = {
9
+ readonly [P in keyof T]: T[P] extends ReadonlyObject<infer _U> ? T[P] : T[P] extends AnyObject ? ReadonlyObject<T[P]> : T[P];
10
+ };
11
+ export declare function markReadonly<T extends AnyObject>(object: T): ReadonlyObject<T>;
12
+ /**
13
+ * Generates and returns a non random but unique id.
14
+ */
15
+ export declare function uniqueId(): number;
16
+ /**
17
+ * Determines if a value is not null or undefined.
18
+ * @param value the value to check
19
+ * @returns `true` if the value is anything but `null` or `undefined`.
20
+ */
21
+ export declare function notNullish<T>(value: Nullish<T>): value is T;
22
+ /**
23
+ * Determines if a value is null or undefined.
24
+ * @param value the value to check
25
+ * @returns `true` if the value is `null` or `undefined`.
26
+ */
27
+ export declare function isNullish(value: Nullish<unknown>): value is null | undefined;
@@ -0,0 +1,26 @@
1
+ export function markReadonly(object) {
2
+ return object;
3
+ }
4
+ let currentId = 1;
5
+ /**
6
+ * Generates and returns a non random but unique id.
7
+ */
8
+ export function uniqueId() {
9
+ return currentId++;
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(value) {
17
+ return value !== null && value !== undefined;
18
+ }
19
+ /**
20
+ * Determines if a value is null or undefined.
21
+ * @param value the value to check
22
+ * @returns `true` if the value is `null` or `undefined`.
23
+ */
24
+ export function isNullish(value) {
25
+ return value === null || value === undefined;
26
+ }
@@ -0,0 +1,182 @@
1
+ import type { PropType, Ref } from 'vue';
2
+ import type { AnyObject } from './utils';
3
+ /**
4
+ * Creates props for a `v-model` of the given type.
5
+ * A `v-model` consits of a value-property and a update-function.
6
+ * @param propType The propType of the `v-model`.
7
+ * @returns An object containing the value-property and the update-function.
8
+ */
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
+ };
19
+ /**
20
+ * Creates props for a required `v-model` of the given type.
21
+ * @see {@link vModelProps}
22
+ */
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
+ };
36
+ /**
37
+ * Creates props for a `v-model` of the given type with a default value.
38
+ * @see {@link vModelProps}
39
+ */
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
+ };
53
+ /**
54
+ * The `VModel` type contains a value and an optional update-function.
55
+ * This object is passed to a component to create a two-way binding.
56
+ */
57
+ export type VModel<T, U = T> = {
58
+ value: T;
59
+ onUpdateValue?: (newValue: U) => void;
60
+ };
61
+ /**
62
+ * The `VModelForArray` contains the normal `VModel` properties,
63
+ * but aditionally a function, which removes the value from the array.
64
+ */
65
+ export type VModelForArray<T, U = T> = VModel<T, U> & {
66
+ remove(): void;
67
+ };
68
+ /**
69
+ * Uses the given `ref` as a `v-model`, to create a two-way binding with the `ref`.
70
+ * @param ref The `ref` which should be used as the `v-model`.
71
+ * @returns An object of type {@link VModel}, which connects the `ref` to the `v-model`.
72
+ */
73
+ export declare function vModelForRef<T>(ref: Ref<T>): VModel<T>;
74
+ /**
75
+ * This creates a `v-model` for a property of an object. The property of the object is taken as the
76
+ * value of the `v-model`, the `onUpdate` function, is called every time when the property is updated
77
+ * with the whole object and its updated property.
78
+ * @param object The object which contains the relevant property.
79
+ * @param key The key of the property which should be used as the v-model.
80
+ * @param onUpdate The updater function which is called with the entire object when the property has changed.
81
+ * @returns An object containing of type {@link VModel}.
82
+ * @example
83
+ * ```tsx
84
+ * // inside setup function
85
+ * const customer = ref({ firstName: 'Hansi', lastName: 'Halunk' })
86
+ *
87
+ * // This input needs a v-model for the `firstName` property.
88
+ * return () => (
89
+ * <NInput
90
+ * name="First Name"
91
+ * {...vModelForObjectProperty(customer.value, 'firstName', newVal => (customer.value = newValue))}
92
+ * />
93
+ * )
94
+ * ```
95
+ */
96
+ export declare function vModelForObjectProperty<T extends AnyObject, K extends keyof T>(object: T, key: K, onUpdate?: (newValue: T) => void): VModel<T[K]>;
97
+ /**
98
+ * This creates a `v-model` which operates on one property of a parent `v-model`. It takes the value of
99
+ * the property as the value of the `v-model` and calls the function `onUpdateValue` of the parent `v-model`
100
+ * whenever the property changes. This function can be seen as a kind of mapper for a `v-model`.
101
+ * @param vModel The parent `v-model`, which this function extracts a single property from.
102
+ * @param key The key of the relevant property.
103
+ * @returns An object of type {@link VModel}.
104
+ * @example
105
+ * ```tsx
106
+ * type Customer = { firstName: string, lastName: String }
107
+ *
108
+ * // inside setup function,
109
+ * // This vModel would normally be inside the props of a component e.g., `CustomerEditor`.
110
+ * const parentVModel = {
111
+ * value: { firstName: 'Hansi', lastName: 'Halunk' },
112
+ * onUpdateValue: (newValue: Customer) => {
113
+ * // update something
114
+ * }
115
+ * }
116
+ *
117
+ * // This input needs a v-model for the `firstName` property.
118
+ * return () => (
119
+ * <NInput
120
+ * name="First Name"
121
+ * {...vModelForVModelProperty(parentVModel, 'firstName'))}
122
+ * />
123
+ * )
124
+ * ```
125
+ */
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]>;
127
+ /**
128
+ * This function does the same thing as {@link vModelForVModelProperty},
129
+ * but can be provided with a mapper function for the modified property.
130
+ * @see {@link vModelForVModelProperty}
131
+ * @example
132
+ * ```tsx
133
+ * type Customer = { firstName: string, lastName: String, type: 'admin' | 'user' }
134
+ *
135
+ * // inside setup function,
136
+ * // This vModel would normally be inside the props of a component e.g., `CustomerEditor`.
137
+ * const parentVModel = {
138
+ * value: { firstName: 'Hansi', lastName: 'Halunk', type: 'user' },
139
+ * onUpdateValue: (newValue: Customer) => {
140
+ * // update something
141
+ * }
142
+ * }
143
+ *
144
+ * // This input needs a v-model for the `type` property.
145
+ * // Unfortunately the NSelect input expects an `onUpdateValue` with a
146
+ * // parameter of type `string`, not type `admin | user`.
147
+ * // So we have to provide a mapper function from `string` to `admin | user`.
148
+ * // In this example, we just cast the value.
149
+ * return () => (
150
+ * <NSelect
151
+ * name="Type"
152
+ * {...vModelForVModelPropertyMapType(parentVModel, 'type', newVal => newVal as 'admin' | 'user'))}
153
+ * />
154
+ * )
155
+ * ```
156
+ */
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>;
158
+ /**
159
+ * Creates an array of `v-models`, one for every element of an array. All changes in
160
+ * a `v-model` of any element, will call the `onUpdate` function, with the updated array.
161
+ * @param array The array to create `v-models` for.
162
+ * @param onUpdate The updater function, which is called whenever an element has changed.
163
+ * @returns An object of type {@link VModelForArray}.
164
+ * @example
165
+ * ```tsx
166
+ * // inside setup function
167
+ * const todos = ref([
168
+ * 'Create v-model helper functions.',
169
+ * 'Document them!'
170
+ * ])
171
+ *
172
+ * // For every todo, there should be an input to modifiy it.
173
+ * return () => (
174
+ * <div>
175
+ * {vModelsForArray(todos.value, newValue => (todos.value = newValue)).map(todoVModel => (
176
+ * <NInput name="Todo" {...todoVModel} />
177
+ * ))}
178
+ * </div>
179
+ * )
180
+ * ```
181
+ */
182
+ export declare function vModelsForArray<T>(array: T[], onUpdate?: (newValue: T[]) => void): VModelForArray<T>[];