@kizmann/nano-ui 0.7.27 → 0.7.29

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kizmann/nano-ui",
3
- "version": "0.7.27",
3
+ "version": "0.7.29",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "author": "Eduard Kizmann <kizmann@protonmail.ch>",
@@ -1,15 +1,26 @@
1
1
  import { UUID, Num, Arr, Obj, Any, Dom, Locale } from "@kizmann/pico-js";
2
+ import { h } from "vue";
2
3
 
3
4
  export default {
4
5
 
5
6
  name: 'NForm',
6
7
 
8
+ inheritAttrs: false,
9
+
7
10
  model: {
8
11
  prop: 'form'
9
12
  },
10
13
 
11
14
  props: {
12
15
 
16
+ dom: {
17
+ default()
18
+ {
19
+ return 'div';
20
+ },
21
+ type: [String]
22
+ },
23
+
13
24
  form: {
14
25
  default()
15
26
  {
@@ -68,16 +79,31 @@ export default {
68
79
 
69
80
  },
70
81
 
82
+ computed: {
83
+
84
+ classList()
85
+ {
86
+ if ( ! this.$attrs.class ) {
87
+ return [];
88
+ }
89
+
90
+ return Any.isArray(this.$attrs) ? this.$attrs.class :
91
+ [this.$attrs.class];
92
+ }
93
+
94
+ },
95
+
71
96
  methods: {
72
97
 
73
98
  onSubmit(event)
74
99
  {
75
- if ( this.prevent ) {
76
- event.preventDefault();
77
- event.stopPropagation();
78
- }
100
+ console.log('hmm', event.which);
101
+ event.preventDefault();
102
+ event.stopPropagation();
79
103
 
80
- this.$emit('submit', event);
104
+ if ( Dom.find(event.target).is('input') ) {
105
+ this.$emit('submit', event);
106
+ }
81
107
 
82
108
  return this.prevent;
83
109
  },
@@ -96,28 +122,11 @@ export default {
96
122
  });
97
123
  },
98
124
 
99
- setForm(form)
125
+ emitChange(form)
100
126
  {
101
- let veForm = Obj.clone(form);
102
-
103
- if ( Any.md5(veForm) !== Any.md5(this.veForm) || this.forceChange ) {
104
- this.$emit('change');
105
- }
106
-
107
- this.veForm = veForm;
127
+ this.$emit('change');
108
128
  },
109
129
 
110
- setErrors(errors)
111
- {
112
- let veErrors = Obj.clone(errors);
113
-
114
- if ( Any.md5(veErrors) !== Any.md5(this.veErrors) || this.forceErrors ) {
115
- this.$emit('errors');
116
- }
117
-
118
- this.veErrors = veErrors;
119
- }
120
-
121
130
  },
122
131
 
123
132
  data()
@@ -137,36 +146,12 @@ export default {
137
146
 
138
147
  mounted()
139
148
  {
140
- // this.$watch('form', () => this.setForm(this.form),
141
- // { deep: true });
142
-
143
- // this.$watch('errors', () => this.setErrors(this.errors),
144
- // { deep: true });
145
-
146
- // let ident = {
147
- // _uid: this.uid
148
- // };
149
-
150
- // if ( this.propagation ) {
151
- // return;
152
- // }
153
-
154
- // Dom.find(this.$el).on('submit',
155
- // this.onSubmit, this._.uid);
149
+ Any.delay(this.ctor('ready'), 1000);
156
150
  },
157
151
 
158
- beforeUnmount()
152
+ ready()
159
153
  {
160
- // let ident = {
161
- // _uid: this.uid
162
- // };
163
-
164
- // if ( this.propagation ) {
165
- // return;
166
- // }
167
-
168
- // Dom.find(this.$el).off('submit',
169
- // null, this._.uid);
154
+ this.$watch('form', this.emitChange, { deep: true });
170
155
  },
171
156
 
172
157
  render()
@@ -176,10 +161,17 @@ export default {
176
161
  'n-form--' + this.align,
177
162
  ];
178
163
 
179
- return (
180
- <form class={classList} onSubmit={this.onSubmit}>
181
- { this.$slots.default && this.$slots.default() }
182
- </form>
183
- );
164
+ let attrs = Obj.except(this.$attrs, ['class', 'onChange', 'onSubmit'], {
165
+ class: this.cmer(classList)
166
+ });
167
+
168
+ attrs['onSubmit'] = (e) => {
169
+ return false;
170
+ }
171
+
172
+ return h(this.dom, { ...attrs }, [
173
+ this.$slots.default && this.$slots.default()
174
+ ]);
184
175
  }
176
+
185
177
  }
@@ -5,6 +5,14 @@ export default {
5
5
 
6
6
  name: 'NInput',
7
7
 
8
+ inject: {
9
+
10
+ NForm: {
11
+ default: undefined
12
+ }
13
+
14
+ },
15
+
8
16
  inheritAttrs: false,
9
17
 
10
18
  props: {
@@ -111,10 +119,25 @@ export default {
111
119
 
112
120
  onInput(event)
113
121
  {
114
- this.$emit('update:modelValue',
122
+ this.$emit('update:modelValue',
115
123
  this.tempValue = event.target.value);
116
124
  },
117
125
 
126
+ onKeydown(event)
127
+ {
128
+ if ( event.which !== 13 ) {
129
+ return;
130
+ }
131
+
132
+ event.preventDefault();
133
+
134
+ if ( ! this.NForm ) {
135
+ return;
136
+ }
137
+
138
+ this.NForm.onSubmit();
139
+ },
140
+
118
141
  onFocus(event)
119
142
  {
120
143
  this.focus = true;
@@ -129,22 +152,22 @@ export default {
129
152
 
130
153
  renderIcon()
131
154
  {
132
- if ( ! this.icon ) {
155
+ if ( !this.icon ) {
133
156
  return null;
134
157
  }
135
158
 
136
- let disabled = this.disabled ||
159
+ let disabled = this.disabled ||
137
160
  this.iconDisabled;
138
161
 
139
162
  let props = {
140
- type: 'input',
141
- icon: this.icon,
142
- size: this.size,
143
- square: true,
144
- disabled: disabled,
163
+ type: 'input',
164
+ icon: this.icon,
165
+ size: this.size,
166
+ square: true,
167
+ disabled: disabled,
145
168
  };
146
169
 
147
- if ( ! disabled ) {
170
+ if ( !disabled ) {
148
171
  props.onClick = this.onIconClick;
149
172
  }
150
173
 
@@ -158,13 +181,14 @@ export default {
158
181
  ]);
159
182
 
160
183
  Obj.assign(props, {
161
- value: this.tempValue,
162
- type: this.nativeType,
163
- disabled: this.disabled,
164
- placeholder: this.placeholder,
165
- onInput: this.onInput,
166
- onFocus: this.onFocus,
167
- onBlur: this.onBlur,
184
+ value: this.tempValue,
185
+ type: this.nativeType,
186
+ disabled: this.disabled,
187
+ placeholder: this.placeholder,
188
+ onInput: this.onInput,
189
+ onFocus: this.onFocus,
190
+ onBlur: this.onBlur,
191
+ onKeydown: this.onKeydown
168
192
  });
169
193
 
170
194
  return h('input', props);