@naptics/vue-collection 0.0.2 → 0.0.4
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/README.md +123 -15
- package/components/NAlert.js +81 -0
- package/components/NBadge.js +57 -0
- package/components/NBreadcrub.js +66 -0
- package/components/NButton.js +65 -0
- package/components/NCheckbox.js +42 -0
- package/components/NCheckboxLabel.js +39 -0
- package/components/NCrudModal.js +105 -0
- package/components/NDialog.js +160 -0
- package/components/NDropdown.js +108 -0
- package/components/NDropzone.js +210 -0
- package/components/NForm.js +28 -0
- package/components/NFormModal.js +54 -0
- package/components/NIconButton.js +81 -0
- package/components/NIconCircle.js +66 -0
- package/components/NInput.js +105 -0
- package/components/NInputPhone.d.ts +1 -1
- package/components/NInputPhone.js +46 -0
- package/components/NInputPhone.jsx +2 -1
- package/components/NInputSelect.js +114 -0
- package/components/NInputSuggestion.d.ts +1 -1
- package/components/NInputSuggestion.js +63 -0
- package/components/NLink.js +59 -0
- package/components/NList.js +24 -0
- package/components/NLoadingIndicator.js +53 -0
- package/components/NModal.js +210 -0
- package/components/NPagination.js +108 -0
- package/components/NSearchbar.js +66 -0
- package/components/NSearchbarList.js +36 -0
- package/components/NSelect.js +84 -0
- package/components/NSuggestionList.js +156 -0
- package/components/NTable.js +126 -0
- package/components/NTableAction.js +49 -0
- package/components/NTextArea.d.ts +1 -1
- package/components/NTextArea.js +128 -0
- package/components/NTooltip.js +178 -0
- package/components/NValInput.d.ts +1 -1
- package/components/NValInput.js +104 -0
- package/components/ValidatedForm.js +18 -18
- package/i18n/index.d.ts +24 -1
- package/i18n/index.js +13 -16
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +11 -4
- package/utils/breakpoints.js +21 -21
- package/utils/component.js +17 -9
- package/utils/deferred.js +12 -12
- package/utils/identifiable.js +27 -29
- package/utils/stringMaxLength.js +8 -13
- package/utils/tailwind.js +1 -1
- package/utils/utils.js +5 -5
- package/utils/vModel.js +82 -73
- package/utils/validation.d.ts +9 -3
- package/utils/validation.js +67 -83
- package/utils/vue.js +7 -5
- package/i18n/de/template.json +0 -10
- package/i18n/de.d.ts +0 -61
- package/i18n/de.js +0 -5
- package/i18n/en/template.json +0 -10
- package/i18n/en.d.ts +0 -61
- package/i18n/en.js +0 -5
package/i18n/index.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
});
|
|
1
|
+
let provider = undefined;
|
|
2
|
+
/**
|
|
3
|
+
* Registeres a new translation provider for vue-collection.
|
|
4
|
+
* The translation provider should contain all vue-collection
|
|
5
|
+
* texts located under `i18n/<lang>/vue-collection.json`.
|
|
6
|
+
* @param newProvider
|
|
7
|
+
*/
|
|
8
|
+
export function registerTranslationProvider(newProvider) {
|
|
9
|
+
provider = newProvider;
|
|
10
|
+
}
|
|
12
11
|
/**
|
|
13
12
|
* Translates the specified key with the according message.
|
|
14
13
|
* @param key the key to translate.
|
|
@@ -16,7 +15,7 @@ const i18n = createI18n({
|
|
|
16
15
|
* @returns the translated message.
|
|
17
16
|
*/
|
|
18
17
|
export function trsl(key, params) {
|
|
19
|
-
|
|
18
|
+
return provider?.trsl(key, params) ?? key;
|
|
20
19
|
}
|
|
21
20
|
/**
|
|
22
21
|
* Translates the specified key using pluralization.
|
|
@@ -28,7 +27,5 @@ export function trsl(key, params) {
|
|
|
28
27
|
* @see trsl
|
|
29
28
|
*/
|
|
30
29
|
export function trslc(key, count, params) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return i18n.global.t(key, newParams, { plural: newCount });
|
|
34
|
-
}
|
|
30
|
+
return provider?.trslc(key, count, params) ?? key;
|
|
31
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -62,3 +62,5 @@ import NValInput from './components/NValInput';
|
|
|
62
62
|
export { NValInput };
|
|
63
63
|
import { type ValidatedForm, createValidatedForm } from './components/ValidatedForm';
|
|
64
64
|
export { ValidatedForm, createValidatedForm };
|
|
65
|
+
import { createComponent, createView, createProps } from './utils/component';
|
|
66
|
+
export { createComponent, createView, createProps };
|
package/index.js
CHANGED
|
@@ -63,3 +63,5 @@ import NValInput from './components/NValInput';
|
|
|
63
63
|
export { NValInput };
|
|
64
64
|
import { createValidatedForm } from './components/ValidatedForm';
|
|
65
65
|
export { createValidatedForm };
|
|
66
|
+
import { createComponent, createView, createProps } from './utils/component';
|
|
67
|
+
export { createComponent, createView, createProps };
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naptics/vue-collection",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"main": "./index.js",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/naptics/vue-collection"
|
|
8
|
+
},
|
|
5
9
|
"scripts": {
|
|
6
10
|
"dev": "vite",
|
|
7
11
|
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
|
|
@@ -12,7 +16,7 @@
|
|
|
12
16
|
"build-demo": "run-p type-check-demo build-only-demo",
|
|
13
17
|
"build-lib": "run-p type-check-lib build-only-lib",
|
|
14
18
|
"build-only-demo": "vite build",
|
|
15
|
-
"build-only-lib": "
|
|
19
|
+
"build-only-lib": "bash ./scripts/build-lib.sh"
|
|
16
20
|
},
|
|
17
21
|
"dependencies": {
|
|
18
22
|
"@headlessui/vue": "^1.7.10",
|
|
@@ -21,10 +25,11 @@
|
|
|
21
25
|
},
|
|
22
26
|
"peerDependencies": {
|
|
23
27
|
"@heroicons/vue": "^2.0.16",
|
|
24
|
-
"vue": "^3.2.36"
|
|
25
|
-
"vue-i18n": "^9.2.2"
|
|
28
|
+
"vue": "^3.2.36"
|
|
26
29
|
},
|
|
27
30
|
"devDependencies": {
|
|
31
|
+
"@babel/cli": "^7.21.0",
|
|
32
|
+
"@babel/core": "^7.21.3",
|
|
28
33
|
"@intlify/unplugin-vue-i18n": "^0.8.2",
|
|
29
34
|
"@rushstack/eslint-patch": "^1.2.0",
|
|
30
35
|
"@tailwindcss/forms": "^0.5.3",
|
|
@@ -32,6 +37,7 @@
|
|
|
32
37
|
"@types/node": "^18.14.0",
|
|
33
38
|
"@vitejs/plugin-vue": "^4.0.0",
|
|
34
39
|
"@vitejs/plugin-vue-jsx": "^3.0.0",
|
|
40
|
+
"@vue/babel-plugin-jsx": "^1.1.1",
|
|
35
41
|
"@vue/eslint-config-prettier": "^7.1.0",
|
|
36
42
|
"@vue/eslint-config-typescript": "^11.0.2",
|
|
37
43
|
"@vue/test-utils": "^2.3.0",
|
|
@@ -47,6 +53,7 @@
|
|
|
47
53
|
"typescript": "^4.9.5",
|
|
48
54
|
"vite": "^4.1.3",
|
|
49
55
|
"vitest": "^0.28.5",
|
|
56
|
+
"vue-i18n": "^9.2.2",
|
|
50
57
|
"vue-router": "^4.1.6",
|
|
51
58
|
"vue-tsc": "^1.1.5"
|
|
52
59
|
}
|
package/utils/breakpoints.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { computed, ref } from 'vue';
|
|
2
2
|
export const breakpoints = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
sm: 640,
|
|
4
|
+
md: 768,
|
|
5
|
+
lg: 1024,
|
|
6
|
+
xl: 1280,
|
|
7
|
+
'2xl': 1536
|
|
8
8
|
};
|
|
9
9
|
export const bodyWidth = ref(document.body.clientWidth);
|
|
10
10
|
/**
|
|
@@ -12,26 +12,26 @@ export const bodyWidth = ref(document.body.clientWidth);
|
|
|
12
12
|
* It sets a `window.onresize` listener.
|
|
13
13
|
*/
|
|
14
14
|
export function addDocumentResizeEventListener() {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
window.onresize = () => {
|
|
16
|
+
bodyWidth.value = document.body.clientWidth;
|
|
17
|
+
};
|
|
18
18
|
}
|
|
19
19
|
export function isWidthBreakpoint(breakpoint) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
32
|
}
|
|
33
33
|
export const isWidth2xl = computed(() => bodyWidth.value > breakpoints['2xl']);
|
|
34
34
|
export const isWidthXl = computed(() => bodyWidth.value > breakpoints.xl);
|
|
35
35
|
export const isWidthLg = computed(() => bodyWidth.value > breakpoints.lg);
|
|
36
36
|
export const isWidthMd = computed(() => bodyWidth.value > breakpoints.md);
|
|
37
|
-
export const isWidthSm = computed(() => bodyWidth.value > breakpoints.sm);
|
|
37
|
+
export const isWidthSm = computed(() => bodyWidth.value > breakpoints.sm);
|
package/utils/component.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent, reactive, toRef
|
|
1
|
+
import { defineComponent, reactive, toRef } from 'vue';
|
|
2
2
|
/**
|
|
3
3
|
* Components should be created using this helper function.
|
|
4
4
|
* It only takes three arguments, the name and the props of the component and the setup function.
|
|
@@ -10,7 +10,12 @@ import { defineComponent, reactive, toRef, } from 'vue';
|
|
|
10
10
|
* @returns the created vue-component.
|
|
11
11
|
*/
|
|
12
12
|
export function createComponent(name, props, setup) {
|
|
13
|
-
|
|
13
|
+
return defineComponent({
|
|
14
|
+
name,
|
|
15
|
+
props,
|
|
16
|
+
emits: [],
|
|
17
|
+
setup
|
|
18
|
+
});
|
|
14
19
|
}
|
|
15
20
|
/**
|
|
16
21
|
* Views should be created using this helper function. Views are special components, which don't have props.
|
|
@@ -21,7 +26,11 @@ export function createComponent(name, props, setup) {
|
|
|
21
26
|
* @returns the created vue-component.
|
|
22
27
|
*/
|
|
23
28
|
export function createView(name, setup) {
|
|
24
|
-
|
|
29
|
+
return defineComponent({
|
|
30
|
+
name,
|
|
31
|
+
emits: [],
|
|
32
|
+
setup: (props, context) => setup(context)
|
|
33
|
+
});
|
|
25
34
|
}
|
|
26
35
|
/**
|
|
27
36
|
* If props are specified outside of the {@link createComponent}
|
|
@@ -31,7 +40,7 @@ export function createView(name, setup) {
|
|
|
31
40
|
* @returns the created props, with correct typing.
|
|
32
41
|
*/
|
|
33
42
|
export function createProps(props) {
|
|
34
|
-
|
|
43
|
+
return props;
|
|
35
44
|
}
|
|
36
45
|
/**
|
|
37
46
|
* Extracts props from another prop object and returns a reactive object with the specified props.
|
|
@@ -44,8 +53,7 @@ export function createProps(props) {
|
|
|
44
53
|
* console.log(childProps) // { title: 'hi' }
|
|
45
54
|
*/
|
|
46
55
|
export function extractProps(props, ...keys) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
56
|
+
const partial = {};
|
|
57
|
+
for (const key of keys) partial[key] = toRef(props, key);
|
|
58
|
+
return reactive(partial);
|
|
59
|
+
}
|
package/utils/deferred.js
CHANGED
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
* @returns promise, resolve and reject
|
|
4
4
|
*/
|
|
5
5
|
export function deferred() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
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
|
+
}
|
package/utils/identifiable.js
CHANGED
|
@@ -6,11 +6,8 @@ import { markReadonly } from './utils';
|
|
|
6
6
|
* @returns The first item with the specified `id` or `undefined` if none exists.
|
|
7
7
|
*/
|
|
8
8
|
function find(array, id) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return filtered[0];
|
|
12
|
-
else
|
|
13
|
-
return undefined;
|
|
9
|
+
const filtered = array.filter(item => item.id === id);
|
|
10
|
+
if (filtered.length > 0) return filtered[0];else return undefined;
|
|
14
11
|
}
|
|
15
12
|
/**
|
|
16
13
|
* Checks if the given array contains an item with the `id`.
|
|
@@ -19,11 +16,11 @@ function find(array, id) {
|
|
|
19
16
|
* @returns `true` if there is at least one item in the array with the given `id`.
|
|
20
17
|
*/
|
|
21
18
|
function contains(array, id) {
|
|
22
|
-
|
|
19
|
+
return find(array, id) !== undefined;
|
|
23
20
|
}
|
|
24
21
|
function insertSingle(baseArray, insertItem) {
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
const index = baseArray.findIndex(item => item.id === insertItem.id);
|
|
23
|
+
index === -1 ? baseArray.push(insertItem) : baseArray.splice(index, 1, insertItem);
|
|
27
24
|
}
|
|
28
25
|
/**
|
|
29
26
|
* Inserts the items into the given array, replacing items with the same `id`.
|
|
@@ -34,8 +31,8 @@ function insertSingle(baseArray, insertItem) {
|
|
|
34
31
|
* @returns The reference to the same array, which was passed.
|
|
35
32
|
*/
|
|
36
33
|
function insert(array, ...insertItems) {
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
insertItems.forEach(item => insertSingle(array, item));
|
|
35
|
+
return array;
|
|
39
36
|
}
|
|
40
37
|
/**
|
|
41
38
|
* Removes all items with the specified `ids` from the given array.
|
|
@@ -44,17 +41,14 @@ function insert(array, ...insertItems) {
|
|
|
44
41
|
* @returns The reference to the same array, which was passed.
|
|
45
42
|
*/
|
|
46
43
|
function remove(array, ...ids) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
return array;
|
|
44
|
+
ids.forEach(id => {
|
|
45
|
+
let noMatches = false;
|
|
46
|
+
while (!noMatches) {
|
|
47
|
+
const index = array.findIndex(item => item.id === id);
|
|
48
|
+
if (index != -1) array.splice(index, 1);else noMatches = true;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return array;
|
|
58
52
|
}
|
|
59
53
|
/**
|
|
60
54
|
* Compares the two arrays and checks if they both have
|
|
@@ -64,15 +58,19 @@ function remove(array, ...ids) {
|
|
|
64
58
|
* @returns `true` if the arrays contain item with the same `ids` in the same order.
|
|
65
59
|
*/
|
|
66
60
|
function areSameArrays(first, second) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
return true;
|
|
61
|
+
if (first.length != second.length) return false;
|
|
62
|
+
for (let i = 0; i < first.length; i++) {
|
|
63
|
+
if (first[i]?.id !== second[i]?.id) return false;
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
74
66
|
}
|
|
75
67
|
/**
|
|
76
68
|
* This object contains utility functions to deal with {@link Identifiable} objects.
|
|
77
69
|
*/
|
|
78
|
-
export const Id = markReadonly({
|
|
70
|
+
export const Id = markReadonly({
|
|
71
|
+
find,
|
|
72
|
+
contains,
|
|
73
|
+
insert,
|
|
74
|
+
remove,
|
|
75
|
+
areSameArrays
|
|
76
|
+
});
|
package/utils/stringMaxLength.js
CHANGED
|
@@ -5,10 +5,7 @@
|
|
|
5
5
|
* @see maxLengthSplitCenter
|
|
6
6
|
*/
|
|
7
7
|
export function maxLength(input, maxLength) {
|
|
8
|
-
|
|
9
|
-
return `${input.substring(0, maxLength - 3).trim()}...`;
|
|
10
|
-
else
|
|
11
|
-
return input || '';
|
|
8
|
+
if (input && input.length > maxLength) return `${input.substring(0, maxLength - 3).trim()}...`;else return input || '';
|
|
12
9
|
}
|
|
13
10
|
/**
|
|
14
11
|
* Returns a shortened string with '...' in the center of the string if it is longer than the given `maxLength`.
|
|
@@ -17,12 +14,10 @@ export function maxLength(input, maxLength) {
|
|
|
17
14
|
* @see maxLength
|
|
18
15
|
*/
|
|
19
16
|
export function maxLengthSplitCenter(input, maxLength) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return input || '';
|
|
28
|
-
}
|
|
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
|
+
}
|
package/utils/tailwind.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/utils/utils.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export function markReadonly(object) {
|
|
2
|
-
|
|
2
|
+
return object;
|
|
3
3
|
}
|
|
4
4
|
let currentId = 1;
|
|
5
5
|
/**
|
|
6
6
|
* Generates and returns a non random but unique id.
|
|
7
7
|
*/
|
|
8
8
|
export function uniqueId() {
|
|
9
|
-
|
|
9
|
+
return currentId++;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Determines if a value is not null or undefined.
|
|
@@ -14,7 +14,7 @@ export function uniqueId() {
|
|
|
14
14
|
* @returns `true` if the value is anything but `null` or `undefined`.
|
|
15
15
|
*/
|
|
16
16
|
export function notNullish(value) {
|
|
17
|
-
|
|
17
|
+
return value !== null && value !== undefined;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Determines if a value is null or undefined.
|
|
@@ -22,5 +22,5 @@ export function notNullish(value) {
|
|
|
22
22
|
* @returns `true` if the value is `null` or `undefined`.
|
|
23
23
|
*/
|
|
24
24
|
export function isNullish(value) {
|
|
25
|
-
|
|
26
|
-
}
|
|
25
|
+
return value === null || value === undefined;
|
|
26
|
+
}
|
package/utils/vModel.js
CHANGED
|
@@ -8,54 +8,54 @@
|
|
|
8
8
|
* @returns An object containing the value-property and the update-function.
|
|
9
9
|
*/
|
|
10
10
|
export function vModelProps(propType) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
return {
|
|
12
|
+
/**
|
|
13
|
+
* The value of the component.
|
|
14
|
+
*/
|
|
15
|
+
value: propType,
|
|
16
|
+
/**
|
|
17
|
+
* This will be called, when the value of the component has changed.
|
|
18
|
+
*/
|
|
19
|
+
onUpdateValue: Function
|
|
20
|
+
};
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Creates props for a required `v-model` of the given type.
|
|
24
24
|
* @see {@link vModelProps}
|
|
25
25
|
*/
|
|
26
26
|
export function vModelRequiredProps(propType) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
return {
|
|
28
|
+
/**
|
|
29
|
+
* The value of the component.
|
|
30
|
+
*/
|
|
31
|
+
value: {
|
|
32
|
+
type: propType,
|
|
33
|
+
required: true
|
|
34
|
+
},
|
|
35
|
+
/**
|
|
36
|
+
* This will be called, when the value of the component has changed.
|
|
37
|
+
*/
|
|
38
|
+
onUpdateValue: Function
|
|
39
|
+
};
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* Creates props for a `v-model` of the given type with a default value.
|
|
43
43
|
* @see {@link vModelProps}
|
|
44
44
|
*/
|
|
45
45
|
export function vModelDefaultProps(propType, defaultValue) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
46
|
+
return {
|
|
47
|
+
/**
|
|
48
|
+
* The value of the component.
|
|
49
|
+
*/
|
|
50
|
+
value: {
|
|
51
|
+
type: propType,
|
|
52
|
+
default: defaultValue
|
|
53
|
+
},
|
|
54
|
+
/**
|
|
55
|
+
* This will be called, when the value of the component has changed.
|
|
56
|
+
*/
|
|
57
|
+
onUpdateValue: Function
|
|
58
|
+
};
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
61
|
* Uses the given `ref` as a `v-model`, to create a two-way binding with the `ref`.
|
|
@@ -63,12 +63,12 @@ export function vModelDefaultProps(propType, defaultValue) {
|
|
|
63
63
|
* @returns An object of type {@link VModel}, which connects the `ref` to the `v-model`.
|
|
64
64
|
*/
|
|
65
65
|
export function vModelForRef(ref) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
return {
|
|
67
|
+
value: ref.value,
|
|
68
|
+
onUpdateValue: newValue => {
|
|
69
|
+
ref.value = newValue;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
74
|
* This creates a `v-model` for a property of an object. The property of the object is taken as the
|
|
@@ -93,12 +93,15 @@ export function vModelForRef(ref) {
|
|
|
93
93
|
* ```
|
|
94
94
|
*/
|
|
95
95
|
export function vModelForObjectProperty(object, key, onUpdate) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
96
|
+
return {
|
|
97
|
+
value: object[key],
|
|
98
|
+
onUpdateValue: newValue => {
|
|
99
|
+
onUpdate?.({
|
|
100
|
+
...object,
|
|
101
|
+
[key]: newValue
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
};
|
|
102
105
|
}
|
|
103
106
|
/**
|
|
104
107
|
* This creates a `v-model` which operates on one property of a parent `v-model`. It takes the value of
|
|
@@ -130,12 +133,15 @@ export function vModelForObjectProperty(object, key, onUpdate) {
|
|
|
130
133
|
* ```
|
|
131
134
|
*/
|
|
132
135
|
export function vModelForVModelProperty(vModel, key) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
return {
|
|
137
|
+
value: vModel.value[key],
|
|
138
|
+
onUpdateValue: newValue => {
|
|
139
|
+
vModel.onUpdateValue?.({
|
|
140
|
+
...vModel.value,
|
|
141
|
+
[key]: newValue
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
};
|
|
139
145
|
}
|
|
140
146
|
/**
|
|
141
147
|
* This function does the same thing as {@link vModelForVModelProperty},
|
|
@@ -168,12 +174,15 @@ export function vModelForVModelProperty(vModel, key) {
|
|
|
168
174
|
* ```
|
|
169
175
|
*/
|
|
170
176
|
export function vModelForVModelPropertyMapType(vModel, key, mapType) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
+
return {
|
|
178
|
+
value: vModel.value[key],
|
|
179
|
+
onUpdateValue: newValue => {
|
|
180
|
+
vModel.onUpdateValue?.({
|
|
181
|
+
...vModel.value,
|
|
182
|
+
[key]: mapType(newValue)
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
};
|
|
177
186
|
}
|
|
178
187
|
/**
|
|
179
188
|
* Creates an array of `v-models`, one for every element of an array. All changes in
|
|
@@ -200,16 +209,16 @@ export function vModelForVModelPropertyMapType(vModel, key, mapType) {
|
|
|
200
209
|
* ```
|
|
201
210
|
*/
|
|
202
211
|
export function vModelsForArray(array, onUpdate) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
212
|
+
return array.map((entry, index) => ({
|
|
213
|
+
value: entry,
|
|
214
|
+
onUpdateValue: entry => {
|
|
215
|
+
const newArray = [...array];
|
|
216
|
+
newArray[index] = entry;
|
|
217
|
+
onUpdate?.(newArray);
|
|
218
|
+
},
|
|
219
|
+
remove: () => {
|
|
220
|
+
const newArray = [...array.slice(0, index), ...array.slice(index + 1)];
|
|
221
|
+
onUpdate?.(newArray);
|
|
222
|
+
}
|
|
223
|
+
}));
|
|
224
|
+
}
|
package/utils/validation.d.ts
CHANGED
|
@@ -15,8 +15,14 @@ export type ValidationResult = ValidationResultValid | ValidationResultInvalid;
|
|
|
15
15
|
* with the {@link required} rule.
|
|
16
16
|
*/
|
|
17
17
|
export type ValidationRule = (input: InputValue) => ValidationResult;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a valid result.
|
|
20
|
+
*/
|
|
18
21
|
export declare function validResult(): ValidationResultValid;
|
|
19
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Creates an invalid result with the provided error message.
|
|
24
|
+
*/
|
|
25
|
+
export declare function invalidResult(errorMessage: string): ValidationResultInvalid;
|
|
20
26
|
/**
|
|
21
27
|
* Validates a given input with the specified rules.
|
|
22
28
|
* The rules are evaluated in the order they're in the array.
|
|
@@ -76,9 +82,9 @@ export declare function option(options: string[]): ValidationRule;
|
|
|
76
82
|
*/
|
|
77
83
|
export declare function regex(pattern: RegExp): ValidationRule;
|
|
78
84
|
/**
|
|
79
|
-
* This rule can be used if the validation logic happens
|
|
85
|
+
* This rule can be used if the validation logic happens somewhere else.
|
|
80
86
|
* When `isValid = true` is passed, the function will return a valid result,
|
|
81
87
|
* otherwise it will return the invalid result with the passed `errorKey`.
|
|
82
88
|
* Like always, a falsy input is always valid to not interefere with the {@link required} rule.
|
|
83
89
|
*/
|
|
84
|
-
export declare function external(isValid: boolean,
|
|
90
|
+
export declare function external(isValid: boolean, errorMessage: string): ValidationRule;
|