@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,156 @@
|
|
|
1
|
+
import { type PropType } from 'vue';
|
|
2
|
+
import { type NInputExposed } from './NInput';
|
|
3
|
+
import { type ValidationRule, type ValidationResult } from '../utils/validation';
|
|
4
|
+
import type { ValidatedForm } from './ValidatedForm';
|
|
5
|
+
export declare const validationProps: {
|
|
6
|
+
/**
|
|
7
|
+
* If set to `true` this inputs validation will always succeed and all validation
|
|
8
|
+
* rules are ignored. Default is `false`.
|
|
9
|
+
*/
|
|
10
|
+
readonly disableValidation: BooleanConstructor;
|
|
11
|
+
/**
|
|
12
|
+
* If set to `true` this input is always valid when its value is empty.
|
|
13
|
+
* If set to `false` the input receives the {@link required} rule. Default is `false`.
|
|
14
|
+
*/
|
|
15
|
+
readonly optional: BooleanConstructor;
|
|
16
|
+
/**
|
|
17
|
+
* The rules which this input is checked with.
|
|
18
|
+
* The rules are checked sequentially and the error of the first failed rule is displayed.
|
|
19
|
+
* If `optional` is set to false, the rule {@link required} will be checked first.
|
|
20
|
+
*/
|
|
21
|
+
readonly rules: {
|
|
22
|
+
readonly type: PropType<ValidationRule[] | ValidationRule>;
|
|
23
|
+
readonly default: () => never[];
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The form, which this input will be added to.
|
|
27
|
+
* On initialization, this input will call {@link ValidatedForm.addInput} passing itself to the form.
|
|
28
|
+
*/
|
|
29
|
+
readonly form: PropType<ValidatedForm>;
|
|
30
|
+
/**
|
|
31
|
+
* Overrides the internal error state. If set to true, it will always display an error.
|
|
32
|
+
*/
|
|
33
|
+
readonly error: BooleanConstructor;
|
|
34
|
+
/**
|
|
35
|
+
* Overrides the internal error message. If set, this message is always displayed.
|
|
36
|
+
*/
|
|
37
|
+
readonly errorMessage: StringConstructor;
|
|
38
|
+
/**
|
|
39
|
+
* If set to `true` the error message is not shown.
|
|
40
|
+
* However, the input is still marked red if it is in an error state.
|
|
41
|
+
*/
|
|
42
|
+
readonly hideErrorMessage: BooleanConstructor;
|
|
43
|
+
/**
|
|
44
|
+
* Disables the validation on blur. Should only be used in special occasions.
|
|
45
|
+
*/
|
|
46
|
+
readonly disableBlurValidation: BooleanConstructor;
|
|
47
|
+
};
|
|
48
|
+
export declare const nValInputProps: {
|
|
49
|
+
/**
|
|
50
|
+
* A slot to replace the input.
|
|
51
|
+
*/
|
|
52
|
+
readonly input: PropType<(props: InputSlotProps) => JSX.Element>;
|
|
53
|
+
/**
|
|
54
|
+
* If set to `true` this inputs validation will always succeed and all validation
|
|
55
|
+
* rules are ignored. Default is `false`.
|
|
56
|
+
*/
|
|
57
|
+
readonly disableValidation: BooleanConstructor;
|
|
58
|
+
/**
|
|
59
|
+
* If set to `true` this input is always valid when its value is empty.
|
|
60
|
+
* If set to `false` the input receives the {@link required} rule. Default is `false`.
|
|
61
|
+
*/
|
|
62
|
+
readonly optional: BooleanConstructor;
|
|
63
|
+
/**
|
|
64
|
+
* The rules which this input is checked with.
|
|
65
|
+
* The rules are checked sequentially and the error of the first failed rule is displayed.
|
|
66
|
+
* If `optional` is set to false, the rule {@link required} will be checked first.
|
|
67
|
+
*/
|
|
68
|
+
readonly rules: {
|
|
69
|
+
readonly type: PropType<ValidationRule[] | ValidationRule>;
|
|
70
|
+
readonly default: () => never[];
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* The form, which this input will be added to.
|
|
74
|
+
* On initialization, this input will call {@link ValidatedForm.addInput} passing itself to the form.
|
|
75
|
+
*/
|
|
76
|
+
readonly form: PropType<ValidatedForm>;
|
|
77
|
+
/**
|
|
78
|
+
* Overrides the internal error state. If set to true, it will always display an error.
|
|
79
|
+
*/
|
|
80
|
+
readonly error: BooleanConstructor;
|
|
81
|
+
/**
|
|
82
|
+
* Overrides the internal error message. If set, this message is always displayed.
|
|
83
|
+
*/
|
|
84
|
+
readonly errorMessage: StringConstructor;
|
|
85
|
+
/**
|
|
86
|
+
* If set to `true` the error message is not shown.
|
|
87
|
+
* However, the input is still marked red if it is in an error state.
|
|
88
|
+
*/
|
|
89
|
+
readonly hideErrorMessage: BooleanConstructor;
|
|
90
|
+
/**
|
|
91
|
+
* Disables the validation on blur. Should only be used in special occasions.
|
|
92
|
+
*/
|
|
93
|
+
readonly disableBlurValidation: BooleanConstructor;
|
|
94
|
+
readonly tooltipText: StringConstructor;
|
|
95
|
+
readonly tooltipContent: PropType<() => JSX.Element>;
|
|
96
|
+
readonly tooltipHide: BooleanConstructor;
|
|
97
|
+
readonly tooltipShow: BooleanConstructor;
|
|
98
|
+
readonly tooltipPlacement: {
|
|
99
|
+
readonly type: PropType<import("./NTooltip").TooltipPlacement>;
|
|
100
|
+
readonly default: "auto";
|
|
101
|
+
};
|
|
102
|
+
readonly tooltipMaxWidth: {
|
|
103
|
+
readonly type: PropType<import("../utils/tailwind").TWMaxWidth>;
|
|
104
|
+
readonly default: "max-w-xs";
|
|
105
|
+
};
|
|
106
|
+
readonly tooltipWrapperClass: StringConstructor;
|
|
107
|
+
readonly tooltipContentClass: StringConstructor;
|
|
108
|
+
readonly tooltipArrowClass: StringConstructor;
|
|
109
|
+
readonly tooltipDelay: {
|
|
110
|
+
readonly type: NumberConstructor;
|
|
111
|
+
readonly default: 0;
|
|
112
|
+
};
|
|
113
|
+
readonly name: StringConstructor;
|
|
114
|
+
readonly placeholder: StringConstructor;
|
|
115
|
+
readonly autocomplete: {
|
|
116
|
+
readonly type: StringConstructor;
|
|
117
|
+
readonly default: "off";
|
|
118
|
+
};
|
|
119
|
+
readonly type: {
|
|
120
|
+
readonly type: StringConstructor;
|
|
121
|
+
readonly default: "text";
|
|
122
|
+
};
|
|
123
|
+
readonly max: StringConstructor;
|
|
124
|
+
readonly min: StringConstructor;
|
|
125
|
+
readonly disabled: BooleanConstructor;
|
|
126
|
+
readonly small: BooleanConstructor;
|
|
127
|
+
readonly hideLabel: BooleanConstructor;
|
|
128
|
+
readonly inputClass: StringConstructor;
|
|
129
|
+
readonly onFocus: PropType<() => void>;
|
|
130
|
+
readonly onBlur: PropType<() => void>;
|
|
131
|
+
readonly value: PropType<string>;
|
|
132
|
+
readonly onUpdateValue: PropType<(newValue: string) => void>;
|
|
133
|
+
};
|
|
134
|
+
export type InputSlotProps = {
|
|
135
|
+
onBlur(): void;
|
|
136
|
+
onUpdateValue(newValue: string): void;
|
|
137
|
+
error: boolean;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* The exposed functions of NValInput
|
|
141
|
+
*/
|
|
142
|
+
export type NValInputExposed = {
|
|
143
|
+
/**
|
|
144
|
+
* Validates the input and returns the validation result
|
|
145
|
+
*/
|
|
146
|
+
validate: () => ValidationResult;
|
|
147
|
+
/**
|
|
148
|
+
* Resets the validation state of the input.
|
|
149
|
+
*/
|
|
150
|
+
reset: () => void;
|
|
151
|
+
} & NInputExposed;
|
|
152
|
+
/**
|
|
153
|
+
* The `NValInput` is a `NInput` with custom validation.
|
|
154
|
+
*/
|
|
155
|
+
declare const Component: import("vue").DefineSetupFnComponent<Record<string, any>, {}, {}, Record<string, any> & {}, import("vue").PublicProps>;
|
|
156
|
+
export { Component as NValInput, Component as default };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { mergeProps as _mergeProps, createVNode as _createVNode } from "vue";
|
|
2
|
+
import { createComponentWithSlots } from '../utils/component';
|
|
3
|
+
import { computed, onMounted, onUnmounted } from 'vue';
|
|
4
|
+
import { ref, reactive, watch } from 'vue';
|
|
5
|
+
import NInput, { nInputProps } from './NInput';
|
|
6
|
+
import { validate, required, validResult } from '../utils/validation';
|
|
7
|
+
export const validationProps = {
|
|
8
|
+
/**
|
|
9
|
+
* If set to `true` this inputs validation will always succeed and all validation
|
|
10
|
+
* rules are ignored. Default is `false`.
|
|
11
|
+
*/
|
|
12
|
+
disableValidation: Boolean,
|
|
13
|
+
/**
|
|
14
|
+
* If set to `true` this input is always valid when its value is empty.
|
|
15
|
+
* If set to `false` the input receives the {@link required} rule. Default is `false`.
|
|
16
|
+
*/
|
|
17
|
+
optional: Boolean,
|
|
18
|
+
/**
|
|
19
|
+
* The rules which this input is checked with.
|
|
20
|
+
* The rules are checked sequentially and the error of the first failed rule is displayed.
|
|
21
|
+
* If `optional` is set to false, the rule {@link required} will be checked first.
|
|
22
|
+
*/
|
|
23
|
+
rules: {
|
|
24
|
+
type: [Function, Array],
|
|
25
|
+
default: () => []
|
|
26
|
+
},
|
|
27
|
+
/**
|
|
28
|
+
* The form, which this input will be added to.
|
|
29
|
+
* On initialization, this input will call {@link ValidatedForm.addInput} passing itself to the form.
|
|
30
|
+
*/
|
|
31
|
+
form: Object,
|
|
32
|
+
/**
|
|
33
|
+
* Overrides the internal error state. If set to true, it will always display an error.
|
|
34
|
+
*/
|
|
35
|
+
error: Boolean,
|
|
36
|
+
/**
|
|
37
|
+
* Overrides the internal error message. If set, this message is always displayed.
|
|
38
|
+
*/
|
|
39
|
+
errorMessage: String,
|
|
40
|
+
/**
|
|
41
|
+
* If set to `true` the error message is not shown.
|
|
42
|
+
* However, the input is still marked red if it is in an error state.
|
|
43
|
+
*/
|
|
44
|
+
hideErrorMessage: Boolean,
|
|
45
|
+
/**
|
|
46
|
+
* Disables the validation on blur. Should only be used in special occasions.
|
|
47
|
+
*/
|
|
48
|
+
disableBlurValidation: Boolean
|
|
49
|
+
};
|
|
50
|
+
export const nValInputProps = {
|
|
51
|
+
...nInputProps,
|
|
52
|
+
...validationProps,
|
|
53
|
+
/**
|
|
54
|
+
* A slot to replace the input.
|
|
55
|
+
*/
|
|
56
|
+
input: Function
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* The `NValInput` is a `NInput` with custom validation.
|
|
60
|
+
*/
|
|
61
|
+
const Component = createComponentWithSlots('NValInput', nValInputProps, ['input'], (props, context) => {
|
|
62
|
+
const rules = computed(() => {
|
|
63
|
+
const otherRules = Array.isArray(props.rules) ? props.rules : [props.rules];
|
|
64
|
+
return props.optional ? otherRules : [required, ...otherRules];
|
|
65
|
+
});
|
|
66
|
+
const validationResult = ref();
|
|
67
|
+
const validateRules = input => {
|
|
68
|
+
const result = props.disableValidation ? validResult() : validate(input, rules.value);
|
|
69
|
+
validationResult.value = result;
|
|
70
|
+
return result;
|
|
71
|
+
};
|
|
72
|
+
const showError = computed(() => props.error || validationResult.value != null && !validationResult.value.isValid);
|
|
73
|
+
const showErrorMessage = computed(() => !props.hideErrorMessage && showError.value);
|
|
74
|
+
const errorMessage = computed(() => props.errorMessage || validationResult.value?.errorMessage);
|
|
75
|
+
const validateIfError = (value = props.value) => {
|
|
76
|
+
if (showError.value) validateRules(value);
|
|
77
|
+
};
|
|
78
|
+
watch(() => props.value, () => validateIfError());
|
|
79
|
+
watch(() => rules.value, () => validateIfError());
|
|
80
|
+
watch(() => props.disableValidation, () => validateIfError());
|
|
81
|
+
const onBlur = () => {
|
|
82
|
+
if (!props.disableBlurValidation) validateRules(props.value);
|
|
83
|
+
props.onBlur?.();
|
|
84
|
+
};
|
|
85
|
+
const onUpdateValue = newValue => {
|
|
86
|
+
validateIfError(newValue);
|
|
87
|
+
props.onUpdateValue?.(newValue);
|
|
88
|
+
};
|
|
89
|
+
const inputSlotProps = reactive({
|
|
90
|
+
onBlur,
|
|
91
|
+
onUpdateValue,
|
|
92
|
+
error: showError
|
|
93
|
+
});
|
|
94
|
+
const inputRef = ref();
|
|
95
|
+
const expose = {
|
|
96
|
+
validate: () => validateRules(props.value),
|
|
97
|
+
reset: () => validationResult.value = undefined,
|
|
98
|
+
focus: () => inputRef.value?.focus()
|
|
99
|
+
};
|
|
100
|
+
context.expose(expose);
|
|
101
|
+
let assignedId = undefined;
|
|
102
|
+
onMounted(() => assignedId = props.form?.addInput(expose));
|
|
103
|
+
onUnmounted(() => assignedId && props.form?.removeInput(assignedId));
|
|
104
|
+
return () => _createVNode("div", null, [props.input?.(inputSlotProps) || _createVNode(NInput, _mergeProps({
|
|
105
|
+
"ref": inputRef
|
|
106
|
+
}, {
|
|
107
|
+
...props,
|
|
108
|
+
...inputSlotProps
|
|
109
|
+
}), null), showErrorMessage.value && _createVNode("p", {
|
|
110
|
+
"class": "text-red-500 text-xs mt-1"
|
|
111
|
+
}, [errorMessage.value])]);
|
|
112
|
+
});
|
|
113
|
+
export { Component as NValInput, Component as default };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ValidationResult } from '../utils/validation';
|
|
2
|
+
import type { NValInputExposed } from './NValInput';
|
|
3
|
+
/**
|
|
4
|
+
* A ValidatedForm groups different inputs together and provides functions, which operate on all inputs at the same time.
|
|
5
|
+
* With a form multiple inputs can be validated together by calling the validate function.
|
|
6
|
+
* @example
|
|
7
|
+
* const form = createValidatedForm()
|
|
8
|
+
* <NValInput ... form={form} />
|
|
9
|
+
* <NValInput ... form={form} />
|
|
10
|
+
* const onClick = () => form.validate()
|
|
11
|
+
*/
|
|
12
|
+
export type ValidatedForm = {
|
|
13
|
+
/**
|
|
14
|
+
* Adds the input to the list of this form and returns the assigned `id`.
|
|
15
|
+
* If this form is passed to a `<NValInput />` via the props, will add itself to this form.
|
|
16
|
+
* @returns the newly assigned `id` of the added input.
|
|
17
|
+
* @example
|
|
18
|
+
* <NValInput ... form={form} />
|
|
19
|
+
*/
|
|
20
|
+
addInput(input: NValInputExposed): string;
|
|
21
|
+
/**
|
|
22
|
+
* Removes the input with the given `id` from this form.
|
|
23
|
+
*/
|
|
24
|
+
removeInput(id: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Validates all inputs of the form. If inputs are invalid they will show it visually.
|
|
27
|
+
* The first invalid validation result is returned.
|
|
28
|
+
*/
|
|
29
|
+
validate(): ValidationResult;
|
|
30
|
+
/**
|
|
31
|
+
* Resets the validation state of all inputs.
|
|
32
|
+
*/
|
|
33
|
+
reset(): void;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new ValidatedForm.
|
|
37
|
+
* @returns the instance of the new form.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createValidatedForm(): ValidatedForm;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Id } from '../utils/identifiable';
|
|
2
|
+
import { uniqueId } from '../utils/utils';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new ValidatedForm.
|
|
5
|
+
* @returns the instance of the new form.
|
|
6
|
+
*/
|
|
7
|
+
export function createValidatedForm() {
|
|
8
|
+
return new ValidatedFormImpl();
|
|
9
|
+
}
|
|
10
|
+
class ValidatedFormImpl {
|
|
11
|
+
inputs = [];
|
|
12
|
+
addInput(input) {
|
|
13
|
+
const id = `input-${uniqueId()}`;
|
|
14
|
+
this.inputs.push({
|
|
15
|
+
id,
|
|
16
|
+
...input
|
|
17
|
+
});
|
|
18
|
+
return id;
|
|
19
|
+
}
|
|
20
|
+
removeInput(id) {
|
|
21
|
+
Id.remove(this.inputs, id);
|
|
22
|
+
}
|
|
23
|
+
validate() {
|
|
24
|
+
const results = this.inputs.map(input => input.validate());
|
|
25
|
+
// return first invalid result
|
|
26
|
+
for (const result of results) if (result && !result.isValid) return result;
|
|
27
|
+
// else return valid result
|
|
28
|
+
return {
|
|
29
|
+
isValid: true
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
reset() {
|
|
33
|
+
this.inputs.forEach(input => input.reset());
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -1,45 +1,33 @@
|
|
|
1
|
-
import type { Nullish } from '../utils/utils'
|
|
2
|
-
|
|
1
|
+
import type { Nullish } from '../utils/utils';
|
|
3
2
|
/**
|
|
4
3
|
* @see {@link trsl}
|
|
5
4
|
*/
|
|
6
|
-
export type TranslationFunction = typeof trsl
|
|
7
|
-
|
|
5
|
+
export type TranslationFunction = typeof trsl;
|
|
8
6
|
/**
|
|
9
7
|
* @see {@link trslc}
|
|
10
8
|
*/
|
|
11
|
-
export type TranslationCountFunction = typeof trslc
|
|
12
|
-
|
|
9
|
+
export type TranslationCountFunction = typeof trslc;
|
|
13
10
|
/**
|
|
14
11
|
* A `TranslationProvider` has to implement the two functions `trsl` and `trslc`.
|
|
15
12
|
*/
|
|
16
13
|
export type TranslationProvider = {
|
|
17
|
-
trsl: TranslationFunction
|
|
18
|
-
trslc: TranslationCountFunction
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
let provider: TranslationProvider | undefined = undefined
|
|
22
|
-
|
|
14
|
+
trsl: TranslationFunction;
|
|
15
|
+
trslc: TranslationCountFunction;
|
|
16
|
+
};
|
|
23
17
|
/**
|
|
24
18
|
* Registeres a new translation provider for vue-collection.
|
|
25
19
|
* The translation provider should contain all vue-collection
|
|
26
20
|
* texts located under `i18n/<lang>/vue-collection.json`.
|
|
27
21
|
* @param newProvider
|
|
28
22
|
*/
|
|
29
|
-
export function registerTranslationProvider(newProvider: TranslationProvider): void
|
|
30
|
-
provider = newProvider
|
|
31
|
-
}
|
|
32
|
-
|
|
23
|
+
export declare function registerTranslationProvider(newProvider: TranslationProvider): void;
|
|
33
24
|
/**
|
|
34
25
|
* Translates the specified key with the according message.
|
|
35
26
|
* @param key the key to translate.
|
|
36
27
|
* @param params formatting parameters for the message.
|
|
37
28
|
* @returns the translated message.
|
|
38
29
|
*/
|
|
39
|
-
export function trsl(key: string, params?: Record<string, unknown>): string
|
|
40
|
-
return provider?.trsl(key, params) ?? key
|
|
41
|
-
}
|
|
42
|
-
|
|
30
|
+
export declare function trsl(key: string, params?: Record<string, unknown>): string;
|
|
43
31
|
/**
|
|
44
32
|
* Translates the specified key using pluralization.
|
|
45
33
|
* The provided `count`is automatically passed as the parameter `n` to the translation library.
|
|
@@ -49,6 +37,4 @@ export function trsl(key: string, params?: Record<string, unknown>): string {
|
|
|
49
37
|
* @returns the translated message.
|
|
50
38
|
* @see trsl
|
|
51
39
|
*/
|
|
52
|
-
export function trslc(key: string, count: Nullish<number>, params?: Record<string, unknown>): string
|
|
53
|
-
return provider?.trslc(key, count, params) ?? key
|
|
54
|
-
}
|
|
40
|
+
export declare function trslc(key: string, count: Nullish<number>, params?: Record<string, unknown>): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Translates the specified key with the according message.
|
|
13
|
+
* @param key the key to translate.
|
|
14
|
+
* @param params formatting parameters for the message.
|
|
15
|
+
* @returns the translated message.
|
|
16
|
+
*/
|
|
17
|
+
export function trsl(key, params) {
|
|
18
|
+
return provider?.trsl(key, params) ?? key;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Translates the specified key using pluralization.
|
|
22
|
+
* The provided `count`is automatically passed as the parameter `n` to the translation library.
|
|
23
|
+
* @param key the key to translate.
|
|
24
|
+
* @param count the count used for the pluralization.
|
|
25
|
+
* @param params formatting parameters for the message.
|
|
26
|
+
* @returns the translated message.
|
|
27
|
+
* @see trsl
|
|
28
|
+
*/
|
|
29
|
+
export function trslc(key, count, params) {
|
|
30
|
+
return provider?.trslc(key, count, params) ?? key;
|
|
31
|
+
}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ComputedRef } from 'vue';
|
|
2
|
+
export type TWBreakpoint = 'sm' | 'md' | 'lg' | 'xl' | '2xl';
|
|
3
|
+
export declare const breakpoints: Readonly<Record<TWBreakpoint, number>>;
|
|
4
|
+
export declare const bodyWidth: import("vue").Ref<number, number>;
|
|
5
|
+
/**
|
|
6
|
+
* This function has to be called once in the app two ensure that the breakpoint utilities actually update.
|
|
7
|
+
* It sets a `window.onresize` listener.
|
|
8
|
+
*/
|
|
9
|
+
export declare function addDocumentResizeEventListener(): void;
|
|
10
|
+
/**
|
|
11
|
+
* Returns a ref whose value is `true` as long as the `document.body.clientWitdh` is above the specified breakpoint.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isWidthBreakpoint(breakpoint: TWBreakpoint): ComputedRef<boolean>;
|
|
14
|
+
export declare const isWidth2xl: ComputedRef<boolean>;
|
|
15
|
+
export declare const isWidthXl: ComputedRef<boolean>;
|
|
16
|
+
export declare const isWidthLg: ComputedRef<boolean>;
|
|
17
|
+
export declare const isWidthMd: ComputedRef<boolean>;
|
|
18
|
+
export declare const isWidthSm: ComputedRef<boolean>;
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
/**
|
|
20
|
+
* Returns a ref whose value is `true` as long as the `document.body.clientWitdh` is above the specified breakpoint.
|
|
21
|
+
*/
|
|
22
|
+
export function isWidthBreakpoint(breakpoint) {
|
|
23
|
+
switch (breakpoint) {
|
|
24
|
+
case 'sm':
|
|
25
|
+
return isWidthSm;
|
|
26
|
+
case 'md':
|
|
27
|
+
return isWidthMd;
|
|
28
|
+
case 'lg':
|
|
29
|
+
return isWidthLg;
|
|
30
|
+
case 'xl':
|
|
31
|
+
return isWidthXl;
|
|
32
|
+
case '2xl':
|
|
33
|
+
return isWidth2xl;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export const isWidth2xl = computed(() => bodyWidth.value > breakpoints['2xl']);
|
|
37
|
+
export const isWidthXl = computed(() => bodyWidth.value > breakpoints.xl);
|
|
38
|
+
export const isWidthLg = computed(() => bodyWidth.value > breakpoints.lg);
|
|
39
|
+
export const isWidthMd = computed(() => bodyWidth.value > breakpoints.md);
|
|
40
|
+
export const isWidthSm = computed(() => bodyWidth.value > breakpoints.sm);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { LooseRequired } from '@vue/shared';
|
|
2
|
+
import { type ComponentObjectPropsOptions, type ExtractPropTypes, type RenderFunction, type SetupContext, type ToRefs, type UnwrapNestedRefs } from 'vue';
|
|
3
|
+
import type { AnyObject } from './utils';
|
|
4
|
+
type Data = Record<string, unknown>;
|
|
5
|
+
export type Props<T extends Data = Data> = ComponentObjectPropsOptions<T>;
|
|
6
|
+
/**
|
|
7
|
+
* `ExtractedProps` maps a prop object to the props, which are received in the `setup` function of a components.
|
|
8
|
+
*/
|
|
9
|
+
export type ExtractedProps<T extends Props> = Readonly<LooseRequired<Readonly<ExtractPropTypes<T>>>>;
|
|
10
|
+
/**
|
|
11
|
+
* Components should be created using this helper function.
|
|
12
|
+
* It only takes three arguments, the name and the props of the component and the setup function.
|
|
13
|
+
* All other arguments which the {@link defineComponent} method of vue may provide,
|
|
14
|
+
* should not be used for a better consistency across all components.
|
|
15
|
+
* @param name the name of the component, should be more than one word.
|
|
16
|
+
* @param props the props of the component.
|
|
17
|
+
* @param setup the setup function, which will be called when the component is mounted.
|
|
18
|
+
* @returns the created vue-component.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createComponent<T extends Props>(name: string, props: T, setup: (props: ExtractedProps<T>, context: SetupContext<never[]>) => RenderFunction | Promise<RenderFunction>): import("vue").DefineSetupFnComponent<Record<string, any>, {}, {}, Record<string, any> & {}, import("vue").PublicProps>;
|
|
21
|
+
/**
|
|
22
|
+
* When using this function, the created component will make available all props
|
|
23
|
+
* specifiedin `slotPropKeys` as slot. In this way, they can be used by either setting
|
|
24
|
+
* the prop directly or by using a slot with the same name. This is useful for older
|
|
25
|
+
* components (in `.vue` files), because they are dependent on slots.
|
|
26
|
+
* @see {@link createComponent}
|
|
27
|
+
*/
|
|
28
|
+
export declare function createComponentWithSlots<T extends Props>(name: string, props: T, slotPropKeys: SlotPropsKeys<ExtractedProps<T>>, setup: (props: ExtractedProps<T>, context: SetupContext<never[]>) => RenderFunction | Promise<RenderFunction>): import("vue").DefineSetupFnComponent<Record<string, any>, {}, {}, Record<string, any> & {}, import("vue").PublicProps>;
|
|
29
|
+
/**
|
|
30
|
+
* Views should be created using this helper function. Views are special components, which don't have props.
|
|
31
|
+
* They are often the parent objects in a view hierarchy and contain many components.
|
|
32
|
+
* This function is syntactic sugar to create views and just calls {@link createComponent}.
|
|
33
|
+
* @param name the name of the component, should be more than one word.
|
|
34
|
+
* @param setup the setup function, which will be called when the component is mounted.
|
|
35
|
+
* @returns the created vue-component.
|
|
36
|
+
*/
|
|
37
|
+
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").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
38
|
+
/**
|
|
39
|
+
* Extracts props from another prop object and returns a reactive object with the specified props.
|
|
40
|
+
* @param props the props to extract from
|
|
41
|
+
* @param keys the keys to extract from the props
|
|
42
|
+
* @returns the new object with the specified props
|
|
43
|
+
* @example
|
|
44
|
+
* const parentProps = { title: 'hi', text: 'ho' }
|
|
45
|
+
* const childProps = extractProps(parentProps, 'title')
|
|
46
|
+
* console.log(childProps) // { title: 'hi' }
|
|
47
|
+
*/
|
|
48
|
+
export declare function extractProps<T extends Record<string, unknown>>(props: T, ...keys: (keyof T)[]): UnwrapNestedRefs<Partial<ToRefs<T>>>;
|
|
49
|
+
type SlotFunction<Args extends any[] = any[]> = (...args: Args) => JSX.Element;
|
|
50
|
+
/**
|
|
51
|
+
* Filters object T to only have properties of type K.
|
|
52
|
+
*/
|
|
53
|
+
type FilterObject<T, K> = {
|
|
54
|
+
[P in keyof T as T[P] extends K ? P : never]: T[P];
|
|
55
|
+
};
|
|
56
|
+
type SlotPropsKeys<T extends AnyObject> = (keyof FilterObject<T, SlotFunction | undefined>)[];
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { defineComponent, reactive, toRef, toRefs, ref, Fragment as _Fragment, createVNode as _createVNode } 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
|
+
// Vue 3.5's defineComponent has strict type requirements that don't align with our simplified API.
|
|
14
|
+
// The type assertion is necessary because the generic setup function signature doesn't match
|
|
15
|
+
// Vue's complex overloaded defineComponent types, even though the runtime behavior is correct.
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
return defineComponent({
|
|
18
|
+
name,
|
|
19
|
+
props,
|
|
20
|
+
emits: [],
|
|
21
|
+
setup
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* When using this function, the created component will make available all props
|
|
26
|
+
* specifiedin `slotPropKeys` as slot. In this way, they can be used by either setting
|
|
27
|
+
* the prop directly or by using a slot with the same name. This is useful for older
|
|
28
|
+
* components (in `.vue` files), because they are dependent on slots.
|
|
29
|
+
* @see {@link createComponent}
|
|
30
|
+
*/
|
|
31
|
+
export function createComponentWithSlots(name, props, slotPropKeys, setup) {
|
|
32
|
+
const newSetup = (props, context) => {
|
|
33
|
+
const slottedProps = createSlotProps(props, context.slots, ...slotPropKeys);
|
|
34
|
+
return setup(slottedProps, context);
|
|
35
|
+
};
|
|
36
|
+
return createComponent(name, props, newSetup);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Views should be created using this helper function. Views are special components, which don't have props.
|
|
40
|
+
* They are often the parent objects in a view hierarchy and contain many components.
|
|
41
|
+
* This function is syntactic sugar to create views and just calls {@link createComponent}.
|
|
42
|
+
* @param name the name of the component, should be more than one word.
|
|
43
|
+
* @param setup the setup function, which will be called when the component is mounted.
|
|
44
|
+
* @returns the created vue-component.
|
|
45
|
+
*/
|
|
46
|
+
export function createView(name, setup) {
|
|
47
|
+
return defineComponent({
|
|
48
|
+
name,
|
|
49
|
+
emits: [],
|
|
50
|
+
setup: (props, context) => setup(context)
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Extracts props from another prop object and returns a reactive object with the specified props.
|
|
55
|
+
* @param props the props to extract from
|
|
56
|
+
* @param keys the keys to extract from the props
|
|
57
|
+
* @returns the new object with the specified props
|
|
58
|
+
* @example
|
|
59
|
+
* const parentProps = { title: 'hi', text: 'ho' }
|
|
60
|
+
* const childProps = extractProps(parentProps, 'title')
|
|
61
|
+
* console.log(childProps) // { title: 'hi' }
|
|
62
|
+
*/
|
|
63
|
+
export function extractProps(props, ...keys) {
|
|
64
|
+
const partial = {};
|
|
65
|
+
for (const key of keys) partial[key] = toRef(props, key);
|
|
66
|
+
return reactive(partial);
|
|
67
|
+
}
|
|
68
|
+
function createSlotProps(props, slots, ...keys) {
|
|
69
|
+
// create refs, don't touch all props which are not slots
|
|
70
|
+
const newProps = toRefs(props);
|
|
71
|
+
keys.forEach(key => {
|
|
72
|
+
// if a slot is set once, it is basically always set. The changing content is not a problem as it is inside the function.
|
|
73
|
+
const slot = slots[key];
|
|
74
|
+
// if the slot is set, overwrite the props
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
76
|
+
if (slot) newProps[key] = (...args) => _createVNode(_Fragment, null, [slot?.(...args)]);
|
|
77
|
+
});
|
|
78
|
+
return ref(newProps).value;
|
|
79
|
+
}
|
|
@@ -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
|
+
}
|