@indielayer/ui 0.2.0 → 0.2.1

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.
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ var colors_vue_vue_type_template_id_227ea690_lang = require('./colors.vue_vue_type_template_id_227ea690_lang.js');
4
+
5
+ const script = {};
6
+
7
+
8
+ script.render = colors_vue_vue_type_template_id_227ea690_lang.render;
9
+ var script$1 = script;
10
+
11
+ module.exports = script$1;
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var Form_vue_vue_type_script_lang = require('./Form.vue_vue_type_script_lang.js');
4
+ var Form_vue_vue_type_template_id_bf90a49e_lang = require('./Form.vue_vue_type_template_id_bf90a49e_lang.js');
4
5
 
5
-
6
+ Form_vue_vue_type_script_lang.render = Form_vue_vue_type_template_id_bf90a49e_lang.render;
6
7
 
7
8
  module.exports = Form_vue_vue_type_script_lang;
@@ -2,7 +2,7 @@
2
2
 
3
3
  var vue = require('vue');
4
4
 
5
- var script = vue.defineComponent({
5
+ var script = {
6
6
  name: 'XForm',
7
7
  inheritAttrs: false,
8
8
  props: {
@@ -23,42 +23,46 @@ var script = vue.defineComponent({
23
23
  default: () => [],
24
24
  },
25
25
  },
26
- data() {
27
- return {
28
- inputs: [],
29
- }
30
- },
31
- watch: {
32
- errors(errors) {
33
- this.$nextTick(() => {
26
+
27
+ setup(props, { emit }) {
28
+ const inputs = [];
29
+
30
+ vue.provide('form', {
31
+ registerInput: (name, { focus, validate, setError }) => {
32
+ const exists = inputs.find((i) => i.name === name);
33
+
34
+ if (exists) {
35
+ exists.focus = focus;
36
+ exists.validate = validate;
37
+ exists.setError = setError;
38
+ }
39
+ else inputs.push({ name, focus, validate, setError });
40
+ },
41
+ unregisterInput: (name) => {
42
+ const index = inputs.findIndex((i) => i.name === name);
43
+
44
+ inputs.splice(index, 1);
45
+ },
46
+ });
47
+
48
+ vue.onMounted(() => {
49
+ if (props.autoFocus && inputs && inputs.length > 0) inputs[0].focus();
50
+ });
51
+
52
+ vue.watch(() => props.errors, (errors) => {
53
+ vue.nextTick(() => {
34
54
  errors.forEach((error) => {
35
- const input = this.inputs.find((i) => i.name === error.field);
55
+ const input = inputs.find((i) => i.name === error.field);
36
56
 
37
- if (input) input.setErrorInternal(error.msg);
57
+ if (input) input.setError(error.msg);
38
58
  });
39
59
  });
40
- },
41
- },
42
- mounted() {
43
- this.getInputs(this.vnodesInDefaultSlot);
44
-
45
- if (this.autoFocus) {
46
- if (this.inputs && this.inputs.length > 0) this.inputs[0].focus();
47
- }
48
- },
49
- methods: {
50
- submit(e) {
51
- e.preventDefault();
52
- e.stopPropagation();
53
-
54
- const isFormValid = this.autoValidate ? this.validate() : true;
60
+ });
55
61
 
56
- this.$emit('submit', isFormValid);
57
- },
58
- validate() {
62
+ const validate = () => {
59
63
  let isFormValid = true;
60
64
 
61
- this.inputs.forEach((input) => {
65
+ inputs.forEach((input) => {
62
66
  const isInputValid = input.validate();
63
67
 
64
68
  if (!isInputValid && isFormValid) {
@@ -70,40 +74,22 @@ var script = vue.defineComponent({
70
74
  });
71
75
 
72
76
  return isFormValid
73
- },
74
- getInputs(vnodesInDefaultSlot) {
75
- if (!Array.isArray(vnodesInDefaultSlot)) return
77
+ };
78
+
79
+ const submit = (e) => {
80
+ e.preventDefault();
81
+ e.stopPropagation();
76
82
 
77
- vnodesInDefaultSlot.forEach((vNode) => {
78
- const vInstance = vNode.component?.ctx;
83
+ const isFormValid = props.autoValidate ? validate() : true;
79
84
 
80
- if (vInstance && typeof vInstance.validate === 'function') this.inputs.push(vInstance);
81
- else if (vNode.children) this.getInputs(vNode.children);
82
- });
83
- },
84
- },
85
- render() {
86
- const vnodesInDefaultSlot = this.$slots.default ? this.$slots.default() : [];
87
-
88
- this.vnodesInDefaultSlot = vnodesInDefaultSlot;
89
-
90
- return vue.h(
91
- 'form',
92
- {
93
- onKeyUp: (event) => {
94
- if (event.target !== event.currentTarget) return
95
- if (event.key === 'Enter') this.submit(event);
96
- },
97
- onSubmit: this.submit,
98
- },
99
- [
100
- vue.h('fieldset', {
101
- disabled: this.disabled,
102
- },
103
- vnodesInDefaultSlot),
104
- ],
105
- )
85
+ emit('submit', isFormValid);
86
+ };
87
+
88
+ return {
89
+ validate,
90
+ submit,
91
+ }
106
92
  },
107
- });
93
+ };
108
94
 
109
95
  module.exports = script;
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var vue = require('vue');
6
+
7
+ const _hoisted_1 = ["disabled"];
8
+
9
+ function render(_ctx, _cache, $props, $setup, $data, $options) {
10
+ return (vue.openBlock(), vue.createElementBlock("form", {
11
+ onSubmit: _cache[0] || (_cache[0] = (...args) => ($setup.submit && $setup.submit(...args))),
12
+ onKeypress: _cache[1] || (_cache[1] = vue.withKeys((...args) => ($setup.submit && $setup.submit(...args)), ["enter"]))
13
+ }, [
14
+ vue.createElementVNode("fieldset", { disabled: $props.disabled }, [
15
+ vue.renderSlot(_ctx.$slots, "default")
16
+ ], 8, _hoisted_1)
17
+ ], 32))
18
+ }
19
+
20
+ exports.render = render;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var Spacer = require('./spacer/Spacer.vue.js');
6
- var Colors = require('./Colors.vue.js');
6
+ var colors = require('./colors.vue.js');
7
7
  var Avatar_vue_vue_type_script_lang = require('./avatar/Avatar.vue_vue_type_script_lang.js');
8
8
  var Button_vue_vue_type_script_lang = require('./button/Button.vue_vue_type_script_lang.js');
9
9
  var Card_vue_vue_type_script_lang = require('./card/Card.vue_vue_type_script_lang.js');
@@ -46,7 +46,7 @@ var Tooltip_vue_vue_type_script_lang = require('./tooltip/Tooltip.vue_vue_type_s
46
46
 
47
47
 
48
48
  exports.Spacer = Spacer;
49
- exports.Colors = Colors;
49
+ exports.Colors = colors;
50
50
  exports.Avatar = Avatar_vue_vue_type_script_lang;
51
51
  exports.Button = Button_vue_vue_type_script_lang;
52
52
  exports.Card = Card_vue_vue_type_script_lang;
@@ -52,10 +52,21 @@ const withEmits = (useListeners = true) => {
52
52
  };
53
53
 
54
54
  const useInputtable = (props, { attrs, emit, useListeners = true } = {}) => {
55
+ const interactive$1 = interactive.useInteractive();
56
+
55
57
  const isFirstValidation = vue.ref(true);
56
58
  const errorInternal = vue.ref(props.error);
57
59
 
60
+ const name = props.name ? props.name : (Math.random() + 1).toString(36).substring(7);
61
+ const nameInternal = vue.ref(name);
62
+
58
63
  vue.watch(() => props.error, (val) => { errorInternal.value = val; });
64
+ vue.watch(() => props.name, (val) => { if (val) nameInternal.value = val; });
65
+
66
+ const form = vue.inject('form', {
67
+ registerInput: () => {},
68
+ unregisterInput: () => {},
69
+ });
59
70
 
60
71
  const reset = () => {
61
72
  errorInternal.value = '';
@@ -63,7 +74,7 @@ const useInputtable = (props, { attrs, emit, useListeners = true } = {}) => {
63
74
  emit('update:modelValue', '');
64
75
  };
65
76
 
66
- const setErrorInternal = (val) => {
77
+ const setError = (val) => {
67
78
  errorInternal.value = val;
68
79
  };
69
80
 
@@ -120,8 +131,16 @@ const useInputtable = (props, { attrs, emit, useListeners = true } = {}) => {
120
131
  }
121
132
  }) : vue.ref({});
122
133
 
134
+ vue.onMounted(() => {
135
+ form.registerInput(nameInternal.value, { focus: interactive$1.focus, validate, setError });
136
+ });
137
+
138
+ vue.onUnmounted(() => {
139
+ form.unregisterInput(nameInternal.value);
140
+ });
141
+
123
142
  return {
124
- ...interactive.useInteractive(),
143
+ ...interactive$1,
125
144
 
126
145
  // data
127
146
  isFirstValidation,
@@ -133,7 +152,7 @@ const useInputtable = (props, { attrs, emit, useListeners = true } = {}) => {
133
152
  // methods
134
153
  reset,
135
154
  validate,
136
- setErrorInternal,
155
+ setError,
137
156
  }
138
157
  };
139
158
 
@@ -26,15 +26,13 @@ const withValidator = () => validator;
26
26
  const useInteractive = () => {
27
27
  const focusRef = vue.ref(null);
28
28
 
29
- const methods = {
30
- focus: () => {
31
- if (focusRef.value) focusRef.value.focus();
32
- },
29
+ const focus = () => {
30
+ if (focusRef.value) focusRef.value.focus();
33
31
  };
34
32
 
35
33
  return {
36
34
  focusRef,
37
- ...methods,
35
+ focus,
38
36
  }
39
37
  };
40
38
 
package/lib/cjs/index.js CHANGED
@@ -17,6 +17,7 @@ require('./components/container/Container.vue.js');
17
17
  var Container_vue_vue_type_script_lang = require('./components/container/Container.vue_vue_type_script_lang.js');
18
18
  require('./components/divider/Divider.vue.js');
19
19
  var Divider_vue_vue_type_script_lang = require('./components/divider/Divider.vue_vue_type_script_lang.js');
20
+ require('./components/form/Form.vue.js');
20
21
  var Form_vue_vue_type_script_lang = require('./components/form/Form.vue_vue_type_script_lang.js');
21
22
  require('./components/image/Image.vue.js');
22
23
  var Image_vue_vue_type_script_lang = require('./components/image/Image.vue_vue_type_script_lang.js');
@@ -71,7 +72,7 @@ var TableCell_vue_vue_type_script_lang = require('./components/table/TableCell.v
71
72
  var TableHead_vue_vue_type_script_lang = require('./components/table/TableHead.vue_vue_type_script_lang.js');
72
73
  var TableHeader_vue_vue_type_script_lang = require('./components/table/TableHeader.vue_vue_type_script_lang.js');
73
74
  var TableRow_vue_vue_type_script_lang = require('./components/table/TableRow.vue_vue_type_script_lang.js');
74
- var Colors = require('./components/Colors.vue.js');
75
+ var colors = require('./components/colors.vue.js');
75
76
 
76
77
  const install = (Vue, config = {}) => {
77
78
  Object.entries(index).forEach(([name, component]) => {
@@ -124,5 +125,5 @@ exports.TableCell = TableCell_vue_vue_type_script_lang;
124
125
  exports.TableHead = TableHead_vue_vue_type_script_lang;
125
126
  exports.TableHeader = TableHeader_vue_vue_type_script_lang;
126
127
  exports.TableRow = TableRow_vue_vue_type_script_lang;
127
- exports.Colors = Colors;
128
+ exports.Colors = colors;
128
129
  exports["default"] = install;
@@ -1,4 +1,4 @@
1
- import { render } from './Colors.vue_vue_type_template_id_039e5c98_lang.js';
1
+ import { render } from './colors.vue_vue_type_template_id_227ea690_lang.js';
2
2
 
3
3
  const script = {};
4
4
 
@@ -1,2 +1,5 @@
1
1
  import script from './Form.vue_vue_type_script_lang.js';
2
2
  export { default } from './Form.vue_vue_type_script_lang.js';
3
+ import { render } from './Form.vue_vue_type_template_id_bf90a49e_lang.js';
4
+
5
+ script.render = render;
@@ -1,6 +1,6 @@
1
- import { defineComponent, h } from 'vue';
1
+ import { provide, onMounted, watch, nextTick } from 'vue';
2
2
 
3
- var script = defineComponent({
3
+ var script = {
4
4
  name: 'XForm',
5
5
  inheritAttrs: false,
6
6
  props: {
@@ -21,42 +21,46 @@ var script = defineComponent({
21
21
  default: () => [],
22
22
  },
23
23
  },
24
- data() {
25
- return {
26
- inputs: [],
27
- }
28
- },
29
- watch: {
30
- errors(errors) {
31
- this.$nextTick(() => {
24
+
25
+ setup(props, { emit }) {
26
+ const inputs = [];
27
+
28
+ provide('form', {
29
+ registerInput: (name, { focus, validate, setError }) => {
30
+ const exists = inputs.find((i) => i.name === name);
31
+
32
+ if (exists) {
33
+ exists.focus = focus;
34
+ exists.validate = validate;
35
+ exists.setError = setError;
36
+ }
37
+ else inputs.push({ name, focus, validate, setError });
38
+ },
39
+ unregisterInput: (name) => {
40
+ const index = inputs.findIndex((i) => i.name === name);
41
+
42
+ inputs.splice(index, 1);
43
+ },
44
+ });
45
+
46
+ onMounted(() => {
47
+ if (props.autoFocus && inputs && inputs.length > 0) inputs[0].focus();
48
+ });
49
+
50
+ watch(() => props.errors, (errors) => {
51
+ nextTick(() => {
32
52
  errors.forEach((error) => {
33
- const input = this.inputs.find((i) => i.name === error.field);
53
+ const input = inputs.find((i) => i.name === error.field);
34
54
 
35
- if (input) input.setErrorInternal(error.msg);
55
+ if (input) input.setError(error.msg);
36
56
  });
37
57
  });
38
- },
39
- },
40
- mounted() {
41
- this.getInputs(this.vnodesInDefaultSlot);
42
-
43
- if (this.autoFocus) {
44
- if (this.inputs && this.inputs.length > 0) this.inputs[0].focus();
45
- }
46
- },
47
- methods: {
48
- submit(e) {
49
- e.preventDefault();
50
- e.stopPropagation();
51
-
52
- const isFormValid = this.autoValidate ? this.validate() : true;
58
+ });
53
59
 
54
- this.$emit('submit', isFormValid);
55
- },
56
- validate() {
60
+ const validate = () => {
57
61
  let isFormValid = true;
58
62
 
59
- this.inputs.forEach((input) => {
63
+ inputs.forEach((input) => {
60
64
  const isInputValid = input.validate();
61
65
 
62
66
  if (!isInputValid && isFormValid) {
@@ -68,40 +72,22 @@ var script = defineComponent({
68
72
  });
69
73
 
70
74
  return isFormValid
71
- },
72
- getInputs(vnodesInDefaultSlot) {
73
- if (!Array.isArray(vnodesInDefaultSlot)) return
75
+ };
76
+
77
+ const submit = (e) => {
78
+ e.preventDefault();
79
+ e.stopPropagation();
74
80
 
75
- vnodesInDefaultSlot.forEach((vNode) => {
76
- const vInstance = vNode.component?.ctx;
81
+ const isFormValid = props.autoValidate ? validate() : true;
77
82
 
78
- if (vInstance && typeof vInstance.validate === 'function') this.inputs.push(vInstance);
79
- else if (vNode.children) this.getInputs(vNode.children);
80
- });
81
- },
82
- },
83
- render() {
84
- const vnodesInDefaultSlot = this.$slots.default ? this.$slots.default() : [];
85
-
86
- this.vnodesInDefaultSlot = vnodesInDefaultSlot;
87
-
88
- return h(
89
- 'form',
90
- {
91
- onKeyUp: (event) => {
92
- if (event.target !== event.currentTarget) return
93
- if (event.key === 'Enter') this.submit(event);
94
- },
95
- onSubmit: this.submit,
96
- },
97
- [
98
- h('fieldset', {
99
- disabled: this.disabled,
100
- },
101
- vnodesInDefaultSlot),
102
- ],
103
- )
83
+ emit('submit', isFormValid);
84
+ };
85
+
86
+ return {
87
+ validate,
88
+ submit,
89
+ }
104
90
  },
105
- });
91
+ };
106
92
 
107
93
  export { script as default };
@@ -0,0 +1,16 @@
1
+ import { openBlock, createElementBlock, withKeys, createElementVNode, renderSlot } from 'vue';
2
+
3
+ const _hoisted_1 = ["disabled"];
4
+
5
+ function render(_ctx, _cache, $props, $setup, $data, $options) {
6
+ return (openBlock(), createElementBlock("form", {
7
+ onSubmit: _cache[0] || (_cache[0] = (...args) => ($setup.submit && $setup.submit(...args))),
8
+ onKeypress: _cache[1] || (_cache[1] = withKeys((...args) => ($setup.submit && $setup.submit(...args)), ["enter"]))
9
+ }, [
10
+ createElementVNode("fieldset", { disabled: $props.disabled }, [
11
+ renderSlot(_ctx.$slots, "default")
12
+ ], 8, _hoisted_1)
13
+ ], 32))
14
+ }
15
+
16
+ export { render };
@@ -1,5 +1,5 @@
1
1
  export { default as Spacer } from './spacer/Spacer.vue.js';
2
- export { default as Colors } from './Colors.vue.js';
2
+ export { default as Colors } from './colors.vue.js';
3
3
  export { default as Avatar } from './avatar/Avatar.vue_vue_type_script_lang.js';
4
4
  export { default as Button } from './button/Button.vue_vue_type_script_lang.js';
5
5
  export { default as Card } from './card/Card.vue_vue_type_script_lang.js';
@@ -1,4 +1,4 @@
1
- import { ref, watch, computed } from 'vue';
1
+ import { ref, watch, inject, computed, onMounted, onUnmounted } from 'vue';
2
2
  import { withProps as withProps$1, useInteractive, withValidator as withValidator$1 } from './interactive.js';
3
3
 
4
4
  const validator = {
@@ -48,10 +48,21 @@ const withEmits = (useListeners = true) => {
48
48
  };
49
49
 
50
50
  const useInputtable = (props, { attrs, emit, useListeners = true } = {}) => {
51
+ const interactive = useInteractive();
52
+
51
53
  const isFirstValidation = ref(true);
52
54
  const errorInternal = ref(props.error);
53
55
 
56
+ const name = props.name ? props.name : (Math.random() + 1).toString(36).substring(7);
57
+ const nameInternal = ref(name);
58
+
54
59
  watch(() => props.error, (val) => { errorInternal.value = val; });
60
+ watch(() => props.name, (val) => { if (val) nameInternal.value = val; });
61
+
62
+ const form = inject('form', {
63
+ registerInput: () => {},
64
+ unregisterInput: () => {},
65
+ });
55
66
 
56
67
  const reset = () => {
57
68
  errorInternal.value = '';
@@ -59,7 +70,7 @@ const useInputtable = (props, { attrs, emit, useListeners = true } = {}) => {
59
70
  emit('update:modelValue', '');
60
71
  };
61
72
 
62
- const setErrorInternal = (val) => {
73
+ const setError = (val) => {
63
74
  errorInternal.value = val;
64
75
  };
65
76
 
@@ -116,8 +127,16 @@ const useInputtable = (props, { attrs, emit, useListeners = true } = {}) => {
116
127
  }
117
128
  }) : ref({});
118
129
 
130
+ onMounted(() => {
131
+ form.registerInput(nameInternal.value, { focus: interactive.focus, validate, setError });
132
+ });
133
+
134
+ onUnmounted(() => {
135
+ form.unregisterInput(nameInternal.value);
136
+ });
137
+
119
138
  return {
120
- ...useInteractive(),
139
+ ...interactive,
121
140
 
122
141
  // data
123
142
  isFirstValidation,
@@ -129,7 +148,7 @@ const useInputtable = (props, { attrs, emit, useListeners = true } = {}) => {
129
148
  // methods
130
149
  reset,
131
150
  validate,
132
- setErrorInternal,
151
+ setError,
133
152
  }
134
153
  };
135
154
 
@@ -22,15 +22,13 @@ const withValidator = () => validator;
22
22
  const useInteractive = () => {
23
23
  const focusRef = ref(null);
24
24
 
25
- const methods = {
26
- focus: () => {
27
- if (focusRef.value) focusRef.value.focus();
28
- },
25
+ const focus = () => {
26
+ if (focusRef.value) focusRef.value.focus();
29
27
  };
30
28
 
31
29
  return {
32
30
  focusRef,
33
- ...methods,
31
+ focus,
34
32
  }
35
33
  };
36
34
 
package/lib/esm/index.js CHANGED
@@ -13,6 +13,7 @@ import './components/container/Container.vue.js';
13
13
  export { default as Container } from './components/container/Container.vue_vue_type_script_lang.js';
14
14
  import './components/divider/Divider.vue.js';
15
15
  export { default as Divider } from './components/divider/Divider.vue_vue_type_script_lang.js';
16
+ import './components/form/Form.vue.js';
16
17
  export { default as Form } from './components/form/Form.vue_vue_type_script_lang.js';
17
18
  import './components/image/Image.vue.js';
18
19
  export { default as Image } from './components/image/Image.vue_vue_type_script_lang.js';
@@ -67,7 +68,7 @@ export { default as TableCell } from './components/table/TableCell.vue_vue_type_
67
68
  export { default as TableHead } from './components/table/TableHead.vue_vue_type_script_lang.js';
68
69
  export { default as TableHeader } from './components/table/TableHeader.vue_vue_type_script_lang.js';
69
70
  export { default as TableRow } from './components/table/TableRow.vue_vue_type_script_lang.js';
70
- export { default as Colors } from './components/Colors.vue.js';
71
+ export { default as Colors } from './components/colors.vue.js';
71
72
 
72
73
  const install = (Vue, config = {}) => {
73
74
  Object.entries(index).forEach(([name, component]) => {