@rokkit/forms 1.0.0-next.122

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.
Files changed (84) hide show
  1. package/dist/src/forms-old/input/types.d.ts +7 -0
  2. package/dist/src/forms-old/lib/form.d.ts +95 -0
  3. package/dist/src/forms-old/lib/index.d.ts +1 -0
  4. package/dist/src/index.d.ts +5 -0
  5. package/dist/src/input/index.d.ts +18 -0
  6. package/dist/src/lib/builder.svelte.d.ts +140 -0
  7. package/dist/src/lib/deprecated/nested.d.ts +48 -0
  8. package/dist/src/lib/deprecated/nested.spec.d.ts +1 -0
  9. package/dist/src/lib/deprecated/validator.d.ts +30 -0
  10. package/dist/src/lib/deprecated/validator.spec.d.ts +1 -0
  11. package/dist/src/lib/fields.d.ts +16 -0
  12. package/dist/src/lib/fields.spec.d.ts +1 -0
  13. package/dist/src/lib/index.d.ts +7 -0
  14. package/dist/src/lib/layout.d.ts +7 -0
  15. package/dist/src/lib/schema.d.ts +7 -0
  16. package/dist/src/lib/validation.d.ts +41 -0
  17. package/dist/src/types.d.ts +5 -0
  18. package/package.json +38 -0
  19. package/src/DataEditor.svelte +30 -0
  20. package/src/FieldLayout.svelte +48 -0
  21. package/src/FormRenderer.svelte +118 -0
  22. package/src/Input.svelte +75 -0
  23. package/src/InputField.svelte +55 -0
  24. package/src/ListEditor.svelte +44 -0
  25. package/src/NestedEditor.svelte +85 -0
  26. package/src/forms-old/CheckBox.svelte +56 -0
  27. package/src/forms-old/DataEditor.svelte +30 -0
  28. package/src/forms-old/FieldLayout.svelte +48 -0
  29. package/src/forms-old/Form.svelte +17 -0
  30. package/src/forms-old/Icon.svelte +76 -0
  31. package/src/forms-old/Item.svelte +25 -0
  32. package/src/forms-old/ListEditor.svelte +44 -0
  33. package/src/forms-old/Tabs.svelte +57 -0
  34. package/src/forms-old/Wrapper.svelte +12 -0
  35. package/src/forms-old/input/Input.svelte +17 -0
  36. package/src/forms-old/input/InputField.svelte +70 -0
  37. package/src/forms-old/input/InputSelect.svelte +23 -0
  38. package/src/forms-old/input/InputSwitch.svelte +19 -0
  39. package/src/forms-old/input/types.js +29 -0
  40. package/src/forms-old/lib/form.js +72 -0
  41. package/src/forms-old/lib/index.js +12 -0
  42. package/src/forms-old/mocks/CustomField.svelte +7 -0
  43. package/src/forms-old/mocks/CustomWrapper.svelte +8 -0
  44. package/src/forms-old/mocks/Register.svelte +25 -0
  45. package/src/index.js +7 -0
  46. package/src/inp/Input.svelte +17 -0
  47. package/src/inp/InputField.svelte +69 -0
  48. package/src/inp/InputSelect.svelte +23 -0
  49. package/src/inp/InputSwitch.svelte +19 -0
  50. package/src/input/InputCheckbox.svelte +74 -0
  51. package/src/input/InputColor.svelte +42 -0
  52. package/src/input/InputDate.svelte +54 -0
  53. package/src/input/InputDateTime.svelte +54 -0
  54. package/src/input/InputEmail.svelte +63 -0
  55. package/src/input/InputFile.svelte +45 -0
  56. package/src/input/InputMonth.svelte +54 -0
  57. package/src/input/InputNumber.svelte +57 -0
  58. package/src/input/InputPassword.svelte +60 -0
  59. package/src/input/InputRadio.svelte +60 -0
  60. package/src/input/InputRange.svelte +51 -0
  61. package/src/input/InputSelect.svelte +71 -0
  62. package/src/input/InputSwitch.svelte +29 -0
  63. package/src/input/InputTel.svelte +60 -0
  64. package/src/input/InputText.svelte +60 -0
  65. package/src/input/InputTextArea.svelte +59 -0
  66. package/src/input/InputTime.svelte +54 -0
  67. package/src/input/InputUrl.svelte +60 -0
  68. package/src/input/InputWeek.svelte +54 -0
  69. package/src/input/index.js +23 -0
  70. package/src/lib/Input.svelte +291 -0
  71. package/src/lib/builder.svelte.js +359 -0
  72. package/src/lib/deprecated/Form.svelte +17 -0
  73. package/src/lib/deprecated/FormRenderer.svelte +121 -0
  74. package/src/lib/deprecated/nested.js +192 -0
  75. package/src/lib/deprecated/nested.spec.js +512 -0
  76. package/src/lib/deprecated/validator.js +137 -0
  77. package/src/lib/deprecated/validator.spec.js +348 -0
  78. package/src/lib/fields.js +119 -0
  79. package/src/lib/fields.spec.js +250 -0
  80. package/src/lib/index.js +7 -0
  81. package/src/lib/layout.js +63 -0
  82. package/src/lib/schema.js +32 -0
  83. package/src/lib/validation.js +273 -0
  84. package/src/types.js +29 -0
@@ -0,0 +1,54 @@
1
+ <script>
2
+ /**
3
+ * @typedef {Object} InputDateTimeProps
4
+ * @property {string} value
5
+ * @property {Function} onchange
6
+ * @property {Function} onfocus
7
+ * @property {Function} onblur
8
+ * @property {string} min
9
+ * @property {string} max
10
+ * @property {number} step
11
+ * @property {boolean} required
12
+ * @property {boolean} disabled
13
+ * @property {boolean} readonly
14
+ * @property {string} name
15
+ * @property {string} id
16
+ * @property {string} autocomplete
17
+ */
18
+
19
+ /** @type {InputDateTimeProps & { [key: string]: any }} */
20
+ let {
21
+ value = $bindable(),
22
+ onchange,
23
+ onfocus,
24
+ onblur,
25
+ min,
26
+ max,
27
+ step,
28
+ required,
29
+ disabled,
30
+ readonly,
31
+ name,
32
+ id,
33
+ autocomplete,
34
+ ...rest
35
+ } = $props()
36
+ </script>
37
+
38
+ <input
39
+ bind:value
40
+ type="datetime-local"
41
+ {min}
42
+ {max}
43
+ {step}
44
+ {required}
45
+ {disabled}
46
+ {readonly}
47
+ {name}
48
+ {id}
49
+ {autocomplete}
50
+ {onchange}
51
+ {onfocus}
52
+ {onblur}
53
+ {...rest}
54
+ />
@@ -0,0 +1,63 @@
1
+ <script>
2
+ /**
3
+ * @typedef {Object} InputEmailProps
4
+ * @property {string} value
5
+ * @property {Function} onchange
6
+ * @property {Function} onfocus
7
+ * @property {Function} onblur
8
+ * @property {string} placeholder
9
+ * @property {boolean} required
10
+ * @property {boolean} disabled
11
+ * @property {boolean} readonly
12
+ * @property {string} name
13
+ * @property {string} id
14
+ * @property {string} autocomplete
15
+ * @property {number} maxlength
16
+ * @property {number} minlength
17
+ * @property {string} pattern
18
+ * @property {number} size
19
+ * @property {boolean} multiple
20
+ */
21
+
22
+ /** @type {InputEmailProps & { [key: string]: any }} */
23
+ let {
24
+ value = $bindable(),
25
+ onchange,
26
+ onfocus,
27
+ onblur,
28
+ placeholder,
29
+ required,
30
+ disabled,
31
+ readonly,
32
+ name,
33
+ id,
34
+ autocomplete,
35
+ maxlength,
36
+ minlength,
37
+ pattern,
38
+ size,
39
+ multiple,
40
+ ...rest
41
+ } = $props()
42
+ </script>
43
+
44
+ <input
45
+ bind:value
46
+ type="email"
47
+ {placeholder}
48
+ {required}
49
+ {disabled}
50
+ {readonly}
51
+ {name}
52
+ {id}
53
+ {autocomplete}
54
+ {maxlength}
55
+ {minlength}
56
+ {pattern}
57
+ {size}
58
+ {multiple}
59
+ {onchange}
60
+ {onfocus}
61
+ {onblur}
62
+ {...rest}
63
+ />
@@ -0,0 +1,45 @@
1
+ <script>
2
+ /**
3
+ * @typedef {Object} InputFileProps
4
+ * @property {FileList} value
5
+ * @property {Function} onchange
6
+ * @property {Function} onfocus
7
+ * @property {Function} onblur
8
+ * @property {string} accept
9
+ * @property {boolean} multiple
10
+ * @property {boolean} required
11
+ * @property {boolean} disabled
12
+ * @property {string} name
13
+ * @property {string} id
14
+ */
15
+
16
+ /** @type {InputFileProps & { [key: string]: any }} */
17
+ let {
18
+ value = $bindable(),
19
+ onchange,
20
+ onfocus,
21
+ onblur,
22
+ accept,
23
+ multiple,
24
+ required,
25
+ disabled,
26
+ name,
27
+ id,
28
+ ...rest
29
+ } = $props()
30
+ </script>
31
+
32
+ <input
33
+ bind:value
34
+ type="file"
35
+ {accept}
36
+ {multiple}
37
+ {required}
38
+ {disabled}
39
+ {name}
40
+ {id}
41
+ {onchange}
42
+ {onfocus}
43
+ {onblur}
44
+ {...rest}
45
+ />
@@ -0,0 +1,54 @@
1
+ <script>
2
+ /**
3
+ * @typedef {Object} InputMonthProps
4
+ * @property {string} value
5
+ * @property {Function} onchange
6
+ * @property {Function} onfocus
7
+ * @property {Function} onblur
8
+ * @property {string} min
9
+ * @property {string} max
10
+ * @property {number} step
11
+ * @property {boolean} required
12
+ * @property {boolean} disabled
13
+ * @property {boolean} readonly
14
+ * @property {string} name
15
+ * @property {string} id
16
+ * @property {string} autocomplete
17
+ */
18
+
19
+ /** @type {InputMonthProps & { [key: string]: any }} */
20
+ let {
21
+ value = $bindable(),
22
+ onchange,
23
+ onfocus,
24
+ onblur,
25
+ min,
26
+ max,
27
+ step,
28
+ required,
29
+ disabled,
30
+ readonly,
31
+ name,
32
+ id,
33
+ autocomplete,
34
+ ...rest
35
+ } = $props()
36
+ </script>
37
+
38
+ <input
39
+ bind:value
40
+ type="month"
41
+ {min}
42
+ {max}
43
+ {step}
44
+ {required}
45
+ {disabled}
46
+ {readonly}
47
+ {name}
48
+ {id}
49
+ {autocomplete}
50
+ {onchange}
51
+ {onfocus}
52
+ {onblur}
53
+ {...rest}
54
+ />
@@ -0,0 +1,57 @@
1
+ <script>
2
+ /**
3
+ * @typedef {Object} InputNumberProps
4
+ * @property {number} value
5
+ * @property {Function} onchange
6
+ * @property {Function} onfocus
7
+ * @property {Function} onblur
8
+ * @property {number} min
9
+ * @property {number} max
10
+ * @property {number} step
11
+ * @property {string} placeholder
12
+ * @property {boolean} required
13
+ * @property {boolean} disabled
14
+ * @property {boolean} readonly
15
+ * @property {string} name
16
+ * @property {string} id
17
+ * @property {string} autocomplete
18
+ */
19
+
20
+ /** @type {InputNumberProps & { [key: string]: any }} */
21
+ let {
22
+ value = $bindable(),
23
+ onchange,
24
+ onfocus,
25
+ onblur,
26
+ min,
27
+ max,
28
+ step,
29
+ placeholder,
30
+ required,
31
+ disabled,
32
+ readonly,
33
+ name,
34
+ id,
35
+ autocomplete,
36
+ ...rest
37
+ } = $props()
38
+ </script>
39
+
40
+ <input
41
+ bind:value
42
+ type="number"
43
+ {min}
44
+ {max}
45
+ {step}
46
+ {placeholder}
47
+ {required}
48
+ {disabled}
49
+ {readonly}
50
+ {name}
51
+ {id}
52
+ {autocomplete}
53
+ {onchange}
54
+ {onfocus}
55
+ {onblur}
56
+ {...rest}
57
+ />
@@ -0,0 +1,60 @@
1
+ <script>
2
+ /**
3
+ * @typedef {Object} InputPasswordProps
4
+ * @property {string} value
5
+ * @property {Function} onchange
6
+ * @property {Function} onfocus
7
+ * @property {Function} onblur
8
+ * @property {string} placeholder
9
+ * @property {boolean} required
10
+ * @property {boolean} disabled
11
+ * @property {boolean} readonly
12
+ * @property {string} name
13
+ * @property {string} id
14
+ * @property {string} autocomplete
15
+ * @property {number} maxlength
16
+ * @property {number} minlength
17
+ * @property {string} pattern
18
+ * @property {number} size
19
+ */
20
+
21
+ /** @type {InputPasswordProps & { [key: string]: any }} */
22
+ let {
23
+ value = $bindable(),
24
+ onchange,
25
+ onfocus,
26
+ onblur,
27
+ placeholder,
28
+ required,
29
+ disabled,
30
+ readonly,
31
+ name,
32
+ id,
33
+ autocomplete,
34
+ maxlength,
35
+ minlength,
36
+ pattern,
37
+ size,
38
+ ...rest
39
+ } = $props()
40
+ </script>
41
+
42
+ <input
43
+ bind:value
44
+ type="password"
45
+ {placeholder}
46
+ {required}
47
+ {disabled}
48
+ {readonly}
49
+ {name}
50
+ {id}
51
+ {autocomplete}
52
+ {maxlength}
53
+ {minlength}
54
+ {pattern}
55
+ {size}
56
+ {onchange}
57
+ {onfocus}
58
+ {onblur}
59
+ {...rest}
60
+ />
@@ -0,0 +1,60 @@
1
+ <script>
2
+ import { getItemAtIndex, getIndexForItem, noop } from '@rokkit/core'
3
+ import { Proxy as RokProxy } from '@rokkit/states'
4
+ // import { equals } from 'ramda'
5
+ /**
6
+ * @typedef {Object} InputRadioProps
7
+ * @property {string} [class]
8
+ * @property {any} value
9
+ * @property {Object} [fields]
10
+ * @property {any} [options]
11
+ * @property {boolean} [disabled]
12
+ * @property {boolean} [flip]
13
+ * @property {Function} onchange
14
+ * @property {Function} onfocus
15
+ * @property {Function} onblur
16
+ */
17
+
18
+ /** @type {InputRadioProps & { [key: string]: any }} */
19
+ let {
20
+ class: className = '',
21
+ value = $bindable(),
22
+ fields,
23
+ options = [],
24
+ disabled = false,
25
+ onchange = noop,
26
+ onfocus,
27
+ onblur,
28
+ ...rest
29
+ } = $props()
30
+
31
+ const handleChange = () => {
32
+ value = getItemAtIndex(options, currentIndex)
33
+ onchange?.(value)
34
+ }
35
+
36
+ let currentIndex = $derived(getIndexForItem(options, value))
37
+
38
+ // $effect.pre(() => {
39
+ // currentIndex = getIndexForItem(options, value)
40
+ // })
41
+ </script>
42
+
43
+ <radio-group class={className} class:disabled>
44
+ {#each options as item, index (index)}
45
+ {@const proxy = new RokProxy(item, fields)}
46
+ <label class="flex flex-row items-center gap-2 rtl:flex-row-reverse">
47
+ <input
48
+ type="radio"
49
+ {...rest}
50
+ bind:group={currentIndex}
51
+ value={index}
52
+ {disabled}
53
+ onchange={handleChange}
54
+ {onfocus}
55
+ {onblur}
56
+ />
57
+ <p>{proxy.get('text')}</p>
58
+ </label>
59
+ {/each}
60
+ </radio-group>
@@ -0,0 +1,51 @@
1
+ <script>
2
+ /**
3
+ * @typedef {Object} InputRangeProps
4
+ * @property {number} value
5
+ * @property {Function} onchange
6
+ * @property {Function} onfocus
7
+ * @property {Function} onblur
8
+ * @property {number} min
9
+ * @property {number} max
10
+ * @property {number} step
11
+ * @property {string} list
12
+ * @property {boolean} required
13
+ * @property {boolean} disabled
14
+ * @property {string} name
15
+ * @property {string} id
16
+ */
17
+
18
+ /** @type {InputRangeProps & { [key: string]: any }} */
19
+ let {
20
+ value = $bindable(),
21
+ min = undefined,
22
+ max = undefined,
23
+ step = undefined,
24
+ list = undefined,
25
+ required,
26
+ disabled,
27
+ name,
28
+ id,
29
+ onchange,
30
+ onfocus,
31
+ onblur,
32
+ ...rest
33
+ } = $props()
34
+ </script>
35
+
36
+ <input
37
+ bind:value
38
+ type="range"
39
+ {min}
40
+ {max}
41
+ {step}
42
+ {list}
43
+ {required}
44
+ {disabled}
45
+ {name}
46
+ {id}
47
+ {onchange}
48
+ {onfocus}
49
+ {onblur}
50
+ {...rest}
51
+ />
@@ -0,0 +1,71 @@
1
+ <script>
2
+ import { defaultStateIcons } from '@rokkit/core'
3
+ import { Proxy } from '@rokkit/states'
4
+ import { equals } from 'ramda'
5
+
6
+ /**
7
+ * @typedef {Object} InputSelectProps
8
+ * @property {any} value
9
+ * @property {Object} fields
10
+ * @property {Array<Object>} options
11
+ * @property {Function} onchange
12
+ * @property {Function} onfocus
13
+ * @property {Function} onblur
14
+ */
15
+
16
+ /** @type {InputSelectProps & { [key: string]: any }} */
17
+ let {
18
+ class: classes = '',
19
+ value = $bindable(),
20
+ fields,
21
+ options = [],
22
+ icons = defaultStateIcons['selector'],
23
+ placeholder = null,
24
+ onchange,
25
+ onfocus,
26
+ onblur,
27
+ ...rest
28
+ } = $props()
29
+
30
+ let focused = $state(false)
31
+ let icon = $derived(focused ? icons['opened'] : icons['closed'])
32
+ let indexValue = $state(options.findIndex((item) => equals(item, value)))
33
+ let proxiedOptions = $derived(options.map((option) => new Proxy(option, fields)))
34
+
35
+ function handleChange(event) {
36
+ value = options[indexValue]
37
+ onchange?.(options[indexValue])
38
+ }
39
+
40
+ function handleFocus(event) {
41
+ focused = true
42
+ onfocus?.(event)
43
+ }
44
+
45
+ function handleBlur(event) {
46
+ focused = false
47
+ onblur?.(event)
48
+ }
49
+ </script>
50
+
51
+ <div data-input-select class={classes}>
52
+ <select
53
+ bind:value={indexValue}
54
+ {...rest}
55
+ onchange={handleChange}
56
+ onfocus={handleFocus}
57
+ onblur={handleBlur}
58
+ >
59
+ {#if placeholder}
60
+ <option value="" disabled selected>{placeholder}</option>
61
+ {/if}
62
+ {#each proxiedOptions as option, index (index)}
63
+ <option value={index} aria-current={equals(option.value, value)}>
64
+ {option.get('text')}
65
+ </option>
66
+ {/each}
67
+ </select>
68
+ <span>
69
+ <i class={icon}></i>
70
+ </span>
71
+ </div>
@@ -0,0 +1,29 @@
1
+ <script>
2
+ import { getValue, defaultFields } from '@rokkit/core'
3
+ import Switch from '@rokkit/bits-ui'
4
+
5
+ /**
6
+ * @typedef {Object} InputSwitchProps
7
+ * @property {string} name
8
+ * @property {any} value
9
+ * @property {Array<Object>} options
10
+ * @property {Object} fields
11
+ * @property {Function} onchange
12
+ */
13
+
14
+ /** @type {InputSwitchProps & { [key: string]: any }} */
15
+ let { name, value, options, fields, onchange, ...restProps } = $props()
16
+ // let selected = $state(null)
17
+ let configFields = $derived({ ...defaultFields, ...fields })
18
+ function handle(data) {
19
+ value = getValue(data.value, configFields)
20
+ onchange?.(data.value)
21
+ }
22
+ let selected = $derived(options.find((option) => getValue(option, configFields) === value))
23
+ // $effect(() => {
24
+ // selected = options.find((option) => getValue(option, configFields) === value)
25
+ // })
26
+ </script>
27
+
28
+ <input {name} type="hidden" bind:value />
29
+ <Switch bind:value={selected} {options} {fields} {...restProps} onchange={handle} />
@@ -0,0 +1,60 @@
1
+ <script>
2
+ /**
3
+ * @typedef {Object} InputTelProps
4
+ * @property {string} value
5
+ * @property {Function} onchange
6
+ * @property {Function} onfocus
7
+ * @property {Function} onblur
8
+ * @property {string} placeholder
9
+ * @property {boolean} required
10
+ * @property {boolean} disabled
11
+ * @property {boolean} readonly
12
+ * @property {string} name
13
+ * @property {string} id
14
+ * @property {string} autocomplete
15
+ * @property {number} maxlength
16
+ * @property {number} minlength
17
+ * @property {string} pattern
18
+ * @property {number} size
19
+ */
20
+
21
+ /** @type {InputTelProps & { [key: string]: any }} */
22
+ let {
23
+ value = $bindable(),
24
+ onchange,
25
+ onfocus,
26
+ onblur,
27
+ placeholder,
28
+ required,
29
+ disabled,
30
+ readonly,
31
+ name,
32
+ id,
33
+ autocomplete,
34
+ maxlength,
35
+ minlength,
36
+ pattern,
37
+ size,
38
+ ...rest
39
+ } = $props()
40
+ </script>
41
+
42
+ <input
43
+ bind:value
44
+ type="tel"
45
+ {placeholder}
46
+ {required}
47
+ {disabled}
48
+ {readonly}
49
+ {name}
50
+ {id}
51
+ {autocomplete}
52
+ {maxlength}
53
+ {minlength}
54
+ {pattern}
55
+ {size}
56
+ {onchange}
57
+ {onfocus}
58
+ {onblur}
59
+ {...rest}
60
+ />
@@ -0,0 +1,60 @@
1
+ <script>
2
+ /**
3
+ * @typedef {Object} InputTextProps
4
+ * @property {string} value
5
+ * @property {Function} onchange
6
+ * @property {Function} onfocus
7
+ * @property {Function} onblur
8
+ * @property {string} placeholder
9
+ * @property {boolean} required
10
+ * @property {boolean} disabled
11
+ * @property {boolean} readonly
12
+ * @property {string} name
13
+ * @property {string} id
14
+ * @property {string} autocomplete
15
+ * @property {number} maxlength
16
+ * @property {number} minlength
17
+ * @property {string} pattern
18
+ * @property {number} size
19
+ */
20
+
21
+ /** @type {InputTextProps & { [key: string]: any }} */
22
+ let {
23
+ value = $bindable(),
24
+ onchange,
25
+ onfocus,
26
+ onblur,
27
+ placeholder,
28
+ required,
29
+ disabled,
30
+ readonly,
31
+ name,
32
+ id,
33
+ autocomplete,
34
+ maxlength,
35
+ minlength,
36
+ pattern,
37
+ size,
38
+ ...rest
39
+ } = $props()
40
+ </script>
41
+
42
+ <input
43
+ bind:value
44
+ type="text"
45
+ {placeholder}
46
+ {required}
47
+ {disabled}
48
+ {readonly}
49
+ {name}
50
+ {id}
51
+ {autocomplete}
52
+ {maxlength}
53
+ {minlength}
54
+ {pattern}
55
+ {size}
56
+ {onchange}
57
+ {onfocus}
58
+ {onblur}
59
+ {...rest}
60
+ />