@v1nt1248/3nclient-lib 0.1.23 → 0.1.24

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@v1nt1248/3nclient-lib",
3
3
  "license": "AGPL-3.0-or-later",
4
4
  "author": "v1nt1248",
5
- "version": "0.1.23",
5
+ "version": "0.1.24",
6
6
  "description": "Library for 3NWeb clients",
7
7
  "type": "module",
8
8
  "files": [
@@ -15,12 +15,20 @@ export interface Ui3nInputProps {
15
15
  }
16
16
 
17
17
  export interface Ui3nInputEmits {
18
- (ev: 'init', value: HTMLInputElement): void;
19
- (ev: 'input', value: string): void;
20
- (ev: 'focus', value: Event): void;
21
- (ev: 'blur', value: Event): void;
22
- (ev: 'clear'): void;
23
- (ev: 'change', value: string): void;
24
- (ev: 'update:modelValue', value: string): void;
25
- (ev: 'update:valid', value: boolean): void;
18
+ (event: 'init', value: HTMLInputElement): void;
19
+ (event: 'input', value: string): void;
20
+ (event: 'focus', value: Event): void;
21
+ (event: 'blur', value: Event): void;
22
+ (event: 'clear'): void;
23
+ (event: 'change', value: string): void;
24
+ (event: 'enter', value: {
25
+ value: string;
26
+ altKey: boolean;
27
+ ctrlKey: boolean;
28
+ shiftKey: boolean;
29
+ metaKey: boolean;
30
+ }): void;
31
+ (event: 'escape', value: Event): void;
32
+ (event: 'update:modelValue', value: string): void;
33
+ (event: 'update:valid', value: boolean): void;
26
34
  }
@@ -77,6 +77,21 @@ function onInput(ev: Event) {
77
77
  emits('input', value);
78
78
  }
79
79
 
80
+ function onEnterKeydown(event: KeyboardEvent) {
81
+ const { altKey, ctrlKey, metaKey, shiftKey, target } = event;
82
+ const value = (target as HTMLInputElement).value;
83
+ validate(value);
84
+ emits('update:modelValue', value);
85
+ emits('enter', { value , altKey, ctrlKey, metaKey, shiftKey });
86
+ }
87
+
88
+ function onEscapeKeydown(event: KeyboardEvent) {
89
+ const value = (event.target as HTMLInputElement).value;
90
+ validate(value);
91
+ emits('update:modelValue', value);
92
+ emits('escape', event);
93
+ }
94
+
80
95
  function clearValue() {
81
96
  text.value = '';
82
97
  validate('');
@@ -127,6 +142,8 @@ function validate(text: string) {
127
142
  :disabled="disabled"
128
143
  :class="$style.field"
129
144
  @input="onInput"
145
+ @keydown.enter="onEnterKeydown"
146
+ @keydown.escape="onEscapeKeydown"
130
147
  @focusin="onFocus"
131
148
  @focusout="onBlur"
132
149
  @change="onChange"
@@ -9,10 +9,19 @@ export interface Ui3nTextProps {
9
9
  }
10
10
 
11
11
  export interface Ui3nTextEmits {
12
- (ev: 'init', value: HTMLTextAreaElement): void;
13
- (ev: 'input', value: string): void;
14
- (ev: 'focus', value: Event): void;
15
- (ev: 'blur', value: Event): void;
16
- (ev: 'update:text', value: string): void;
17
- (ev: 'update:valid', value: boolean): void;
12
+ (event: 'init', value: HTMLTextAreaElement): void;
13
+ (event: 'input', value: string): void;
14
+ (event: 'change', value: string): void;
15
+ (event: 'enter', value: {
16
+ value: string;
17
+ altKey: boolean;
18
+ ctrlKey: boolean;
19
+ shiftKey: boolean;
20
+ metaKey: boolean;
21
+ }): void;
22
+ (event: 'escape', value: Event): void;
23
+ (event: 'focus', value: Event): void;
24
+ (event: 'blur', value: Event): void;
25
+ (event: 'update:text', value: string): void;
26
+ (event: 'update:valid', value: boolean): void;
18
27
  }
@@ -40,7 +40,7 @@ watch(
40
40
  { immediate: true },
41
41
  );
42
42
 
43
- const validate = (text: string) => {
43
+ function validate(text: string) {
44
44
  errorMessage.value = '';
45
45
  if (props.rules && props.rules.length) {
46
46
  for (const validateFunction of props.rules) {
@@ -52,24 +52,45 @@ const validate = (text: string) => {
52
52
  }
53
53
  }
54
54
  }
55
- };
55
+ }
56
56
 
57
- const onFocus = (event: Event) => {
57
+ function onFocus(event: Event) {
58
58
  isFocused.value = true;
59
59
  emit('focus', event);
60
- };
60
+ }
61
61
 
62
- const onBlur = (event: Event) => {
62
+ function onBlur(event: Event) {
63
63
  isFocused.value = false;
64
+ const value = (event.target as HTMLInputElement).value;
65
+ validate(value);
64
66
  emit('blur', event);
65
- };
67
+ emit('change', value);
68
+ emit('update:text', value);
69
+ }
66
70
 
67
- const onInput = (ev: Event) => {
68
- const value = (ev.target as HTMLInputElement).value;
71
+ function onInput(event: Event) {
72
+ console.log('onInput!');
73
+ const value = (event.target as HTMLInputElement).value;
69
74
  validate(value);
70
75
  emit('update:text', value);
71
76
  emit('input', value);
72
- };
77
+ }
78
+
79
+ function onEnterKeydown(event: KeyboardEvent) {
80
+ console.log('onEnterKeydown: ', event);
81
+ const { altKey, ctrlKey, shiftKey, metaKey, target } = event;
82
+ const value = (target as HTMLInputElement).value;
83
+ validate(value);
84
+ emit('update:text', value);
85
+ emit('enter', { value , altKey, ctrlKey, shiftKey, metaKey });
86
+ }
87
+
88
+ function onEscapeKeydown(event: KeyboardEvent) {
89
+ const value = (event.target as HTMLInputElement).value;
90
+ validate(value);
91
+ emit('update:text', value);
92
+ emit('escape', event);
93
+ }
73
94
  </script>
74
95
 
75
96
  <template>
@@ -89,6 +110,8 @@ const onInput = (ev: Event) => {
89
110
  :disabled="disabled"
90
111
  v-bind="$attrs"
91
112
  @input="onInput"
113
+ @keydown.enter="onEnterKeydown"
114
+ @keydown.escape="onEscapeKeydown"
92
115
  @focusin="onFocus"
93
116
  @focusout="onBlur"
94
117
  />