@v1nt1248/3nclient-lib 0.3.3 → 0.3.5

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.
@@ -1,10 +1,11 @@
1
1
  export interface Ui3nTextProps {
2
- text: string;
2
+ modelValue: string;
3
3
  rows?: number;
4
4
  maxRows?: number;
5
5
  label?: string;
6
6
  placeholder?: string;
7
7
  rules?: Array<(v: string) => string | boolean>;
8
+ validateAtStartup?: boolean;
8
9
  disabled?: boolean;
9
10
  }
10
11
  export interface Ui3nTextEmits {
@@ -22,6 +23,6 @@ export interface Ui3nTextEmits {
22
23
  (event: 'escape', value: Event): void;
23
24
  (event: 'focus', value: Event): void;
24
25
  (event: 'blur', value: Event): void;
25
- (event: 'update:text', value: string): void;
26
+ (event: 'update:modelValue', value: string): void;
26
27
  (event: 'update:valid', value: boolean): void;
27
28
  }
@@ -13,9 +13,9 @@ declare const _default: import('vue').DefineComponent<Ui3nTextProps, {}, {}, {},
13
13
  change: (value: string) => any;
14
14
  focus: (value: Event) => any;
15
15
  init: (value: HTMLTextAreaElement) => any;
16
+ "update:modelValue": (value: string) => any;
16
17
  escape: (value: Event) => any;
17
18
  "update:valid": (value: boolean) => any;
18
- "update:text": (value: string) => any;
19
19
  }, string, import('vue').PublicProps, Readonly<Ui3nTextProps> & Readonly<{
20
20
  onInput?: ((value: string) => any) | undefined;
21
21
  onEnter?: ((value: {
@@ -30,9 +30,9 @@ declare const _default: import('vue').DefineComponent<Ui3nTextProps, {}, {}, {},
30
30
  onChange?: ((value: string) => any) | undefined;
31
31
  onFocus?: ((value: Event) => any) | undefined;
32
32
  onInit?: ((value: HTMLTextAreaElement) => any) | undefined;
33
+ "onUpdate:modelValue"?: ((value: string) => any) | undefined;
33
34
  onEscape?: ((value: Event) => any) | undefined;
34
35
  "onUpdate:valid"?: ((value: boolean) => any) | undefined;
35
- "onUpdate:text"?: ((value: string) => any) | undefined;
36
36
  }>, {
37
37
  label: string;
38
38
  disabled: boolean;
@@ -17832,12 +17832,13 @@ var Vo = {
17832
17832
  ], zs = /* @__PURE__ */ X(/* @__PURE__ */ d({
17833
17833
  __name: "ui3n-text",
17834
17834
  props: {
17835
- text: {},
17835
+ modelValue: {},
17836
17836
  rows: { default: 6 },
17837
17837
  maxRows: { default: 6 },
17838
17838
  label: { default: "" },
17839
17839
  placeholder: { default: "" },
17840
17840
  rules: {},
17841
+ validateAtStartup: { type: Boolean },
17841
17842
  disabled: {
17842
17843
  type: Boolean,
17843
17844
  default: !1
@@ -17852,37 +17853,37 @@ var Vo = {
17852
17853
  "escape",
17853
17854
  "focus",
17854
17855
  "blur",
17855
- "update:text",
17856
+ "update:modelValue",
17856
17857
  "update:valid"
17857
17858
  ],
17858
17859
  setup(e, { emit: t }) {
17859
- let n = e, r = t, a = C(null), l = C(!1), u = C(""), d = i(() => n.text ? !u.value : !0);
17860
- b(() => {
17861
- a.value && (Za(a.value), r("init", a.value));
17862
- }), F(() => d.value, (e) => r("update:valid", e), { immediate: !0 });
17860
+ let n = e, r = t, i = C(null), a = C(""), l = C(!1), u = C(!1), d = C("");
17863
17861
  function f(e) {
17864
- if (u.value = "", n.rules && n.rules.length) {
17862
+ if (d.value = "", n.rules && n.rules.length) {
17865
17863
  for (let t of n.rules) if (typeof t == "function") {
17866
17864
  let n = t(e);
17867
- typeof n == "string" && (u.value += n);
17865
+ typeof n == "string" && (d.value += n);
17868
17866
  }
17869
17867
  }
17868
+ l.value && r("update:valid", !d.value);
17870
17869
  }
17871
17870
  function p(e) {
17872
- l.value = !0, r("focus", e);
17871
+ u.value = !0, r("focus", e);
17873
17872
  }
17874
17873
  function h(e) {
17875
- l.value = !1;
17876
- let t = e.target.value;
17877
- f(t), r("blur", e), r("change", t), r("update:text", t);
17874
+ setTimeout(() => {
17875
+ u.value = !1;
17876
+ let t = e.target.value;
17877
+ f(t), r("blur", e), r("change", t), r("update:modelValue", t);
17878
+ }, 100);
17878
17879
  }
17879
17880
  function _(e) {
17880
17881
  let t = e.target.value;
17881
- f(t), r("update:text", t), r("input", t);
17882
+ a.value = t, l.value = !0, f(t), r("update:modelValue", t), r("input", t);
17882
17883
  }
17883
17884
  function v(e) {
17884
17885
  let { altKey: t, ctrlKey: n, shiftKey: i, metaKey: a, target: o } = e, s = o.value;
17885
- f(s), r("update:text", s), r("enter", {
17886
+ l.value = !0, f(s), r("update:modelValue", s), r("enter", {
17886
17887
  value: s,
17887
17888
  altKey: t,
17888
17889
  ctrlKey: n,
@@ -17892,23 +17893,27 @@ var Vo = {
17892
17893
  }
17893
17894
  function y(e) {
17894
17895
  let t = e.target.value;
17895
- f(t), r("update:text", t), r("escape", e);
17896
+ l.value = !0, f(t), r("update:modelValue", t), r("escape", e);
17896
17897
  }
17897
17898
  function S(e) {
17898
17899
  r("keydown", e);
17899
17900
  }
17900
- return (t, n) => (x(), s("div", { class: g([
17901
+ return b(() => {
17902
+ i.value && (Za(i.value), r("init", i.value)), n.validateAtStartup && f(a.value);
17903
+ }), F(() => n.modelValue, (e, t) => {
17904
+ (e ?? "") !== (t ?? "") && (a.value = e ?? "", f(a.value));
17905
+ }, { immediate: !0 }), (t, n) => (x(), s("div", { class: g([
17901
17906
  t.$style.ui3nText,
17902
17907
  e.disabled && t.$style.disabled,
17903
- l.value && t.$style.focused
17908
+ u.value && t.$style.focused
17904
17909
  ]) }, [e.label ? (x(), s("label", {
17905
17910
  key: 0,
17906
17911
  class: g(t.$style.label)
17907
17912
  }, D(e.label), 3)) : o("", !0), c("div", { class: g(t.$style.body) }, [c("textarea", m({
17908
17913
  ref_key: "textareaElement",
17909
- ref: a,
17914
+ ref: i,
17910
17915
  class: t.$style.content,
17911
- value: e.text,
17916
+ value: a.value,
17912
17917
  placeholder: e.placeholder,
17913
17918
  readonly: e.disabled,
17914
17919
  rows: e.rows,
@@ -17918,7 +17923,7 @@ var Vo = {
17918
17923
  onInput: _,
17919
17924
  onKeydown: [
17920
17925
  R(v, ["enter"]),
17921
- R(y, ["escape"]),
17926
+ R(y, ["esc"]),
17922
17927
  S
17923
17928
  ],
17924
17929
  onFocusin: p,
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.3.3",
5
+ "version": "0.3.5",
6
6
  "description": "Library for 3NWeb clients",
7
7
  "type": "module",
8
8
  "files": [
@@ -1,10 +1,11 @@
1
1
  export interface Ui3nTextProps {
2
- text: string;
2
+ modelValue: string;
3
3
  rows?: number;
4
4
  maxRows?: number;
5
5
  label?: string;
6
6
  placeholder?: string;
7
7
  rules?: Array<(v: string) => string | boolean>;
8
+ validateAtStartup?: boolean;
8
9
  disabled?: boolean;
9
10
  }
10
11
 
@@ -13,16 +14,19 @@ export interface Ui3nTextEmits {
13
14
  (event: 'input', value: string): void;
14
15
  (event: 'change', value: string): void;
15
16
  (event: 'keydown', value: KeyboardEvent): void;
16
- (event: 'enter', value: {
17
- value: string;
18
- altKey: boolean;
19
- ctrlKey: boolean;
20
- shiftKey: boolean;
21
- metaKey: boolean;
22
- }): void;
17
+ (
18
+ event: 'enter',
19
+ value: {
20
+ value: string;
21
+ altKey: boolean;
22
+ ctrlKey: boolean;
23
+ shiftKey: boolean;
24
+ metaKey: boolean;
25
+ },
26
+ ): void;
23
27
  (event: 'escape', value: Event): void;
24
28
  (event: 'focus', value: Event): void;
25
29
  (event: 'blur', value: Event): void;
26
- (event: 'update:text', value: string): void;
30
+ (event: 'update:modelValue', value: string): void;
27
31
  (event: 'update:valid', value: boolean): void;
28
32
  }
@@ -1,45 +1,23 @@
1
1
  <script lang="ts" setup>
2
- import { computed, onMounted, ref, watch } from 'vue';
2
+ import { onMounted, ref, watch } from 'vue';
3
3
  import { patchTextareaMaxRowsSupport } from '@/utils';
4
4
  import type { Ui3nTextEmits, Ui3nTextProps } from './types';
5
5
 
6
- const props = withDefaults(
7
- defineProps<Ui3nTextProps>(),
8
- {
9
- rows: 6,
10
- maxRows: 6,
11
- label: '',
12
- placeholder: '',
13
- disabled: false,
14
- },
15
- );
6
+ const props = withDefaults(defineProps<Ui3nTextProps>(), {
7
+ rows: 6,
8
+ maxRows: 6,
9
+ label: '',
10
+ placeholder: '',
11
+ disabled: false,
12
+ });
16
13
  const emits = defineEmits<Ui3nTextEmits>();
17
14
 
18
15
  const textareaElement = ref<HTMLTextAreaElement | null>(null);
16
+ const text = ref<string>('');
17
+ const isDirty = ref(false);
19
18
  const isFocused = ref(false);
20
19
  const errorMessage = ref('');
21
20
 
22
- const isValid = computed(() => {
23
- if (!props.text) {
24
- return true;
25
- }
26
-
27
- return !errorMessage.value;
28
- });
29
-
30
- onMounted(() => {
31
- if (textareaElement.value) {
32
- patchTextareaMaxRowsSupport(textareaElement.value!);
33
- emits('init', textareaElement.value!);
34
- }
35
- });
36
-
37
- watch(
38
- () => isValid.value,
39
- val => emits('update:valid', val),
40
- { immediate: true },
41
- );
42
-
43
21
  function validate(text: string) {
44
22
  errorMessage.value = '';
45
23
  if (props.rules && props.rules.length) {
@@ -52,6 +30,10 @@
52
30
  }
53
31
  }
54
32
  }
33
+
34
+ if (isDirty.value) {
35
+ emits('update:valid', !errorMessage.value);
36
+ }
55
37
  }
56
38
 
57
39
  function onFocus(event: Event) {
@@ -60,39 +42,67 @@
60
42
  }
61
43
 
62
44
  function onBlur(event: Event) {
63
- isFocused.value = false;
64
- const value = (event.target as HTMLInputElement).value;
65
- validate(value);
66
- emits('blur', event);
67
- emits('change', value);
68
- emits('update:text', value);
45
+ setTimeout(() => {
46
+ isFocused.value = false;
47
+ const value = (event.target as HTMLInputElement).value;
48
+ validate(value);
49
+ emits('blur', event);
50
+ emits('change', value);
51
+ emits('update:modelValue', value);
52
+ }, 100);
69
53
  }
70
54
 
71
55
  function onInput(event: Event) {
72
56
  const value = (event.target as HTMLInputElement).value;
57
+ text.value = value;
58
+ isDirty.value = true;
73
59
  validate(value);
74
- emits('update:text', value);
60
+ emits('update:modelValue', value);
75
61
  emits('input', value);
76
62
  }
77
63
 
78
64
  function onEnterKeydown(event: KeyboardEvent) {
79
65
  const { altKey, ctrlKey, shiftKey, metaKey, target } = event;
80
66
  const value = (target as HTMLInputElement).value;
67
+ isDirty.value = true;
81
68
  validate(value);
82
- emits('update:text', value);
69
+ emits('update:modelValue', value);
83
70
  emits('enter', { value, altKey, ctrlKey, shiftKey, metaKey });
84
71
  }
85
72
 
86
73
  function onEscapeKeydown(event: KeyboardEvent) {
87
74
  const value = (event.target as HTMLInputElement).value;
75
+ isDirty.value = true;
88
76
  validate(value);
89
- emits('update:text', value);
77
+ emits('update:modelValue', value);
90
78
  emits('escape', event);
91
79
  }
92
80
 
93
81
  function onKeydown(event: KeyboardEvent) {
94
82
  emits('keydown', event);
95
83
  }
84
+
85
+ onMounted(() => {
86
+ if (textareaElement.value) {
87
+ patchTextareaMaxRowsSupport(textareaElement.value!);
88
+ emits('init', textareaElement.value!);
89
+ }
90
+
91
+ if (props.validateAtStartup) {
92
+ validate(text.value);
93
+ }
94
+ });
95
+
96
+ watch(
97
+ () => props.modelValue,
98
+ (val, oldVal) => {
99
+ if ((val ?? '') !== (oldVal ?? '')) {
100
+ text.value = val ?? '';
101
+ validate(text.value);
102
+ }
103
+ },
104
+ { immediate: true },
105
+ );
96
106
  </script>
97
107
 
98
108
  <template>
@@ -117,7 +127,7 @@
117
127
  v-bind="$attrs"
118
128
  @input="onInput"
119
129
  @keydown.enter="onEnterKeydown"
120
- @keydown.escape="onEscapeKeydown"
130
+ @keydown.esc="onEscapeKeydown"
121
131
  @keydown="onKeydown"
122
132
  @focusin="onFocus"
123
133
  @focusout="onBlur"