amotify 0.0.2 → 0.0.4

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 (185) hide show
  1. package/dist/src/@jsminAmotifyExtension/_.d.ts +4 -0
  2. package/dist/src/@jsminAmotifyExtension/fetch.d.ts +9 -0
  3. package/dist/src/@jsminAmotifyExtension/formCollect.d.ts +1 -0
  4. package/dist/src/@jsminAmotifyExtension/spreadSheet.d.ts +4 -0
  5. package/dist/src/@jsminAmotifyExtension/variables.d.ts +0 -0
  6. package/dist/src/@types/_.d.ts +6 -0
  7. package/dist/src/@types/amot.d.ts +260 -0
  8. package/dist/src/@types/fn.d.ts +1040 -0
  9. package/dist/src/@types/index.d.ts +62 -0
  10. package/dist/src/@types/jsminAmotifyExtension.d.ts +134 -0
  11. package/dist/src/@types/module.d.ts +2 -0
  12. package/dist/src/@types/state.d.ts +145 -0
  13. package/dist/src/Atoms/@export.d.ts +4 -0
  14. package/dist/src/Atoms/FAIcon/parts.d.ts +2 -0
  15. package/dist/src/Atoms/Logo/parts.d.ts +1 -0
  16. package/dist/src/Atoms/Various/parts.d.ts +9 -0
  17. package/dist/src/Functions/@export.d.ts +12 -0
  18. package/dist/src/Functions/Button/_.d.ts +1 -0
  19. package/dist/src/Functions/Cropper/parts.d.ts +1 -0
  20. package/dist/src/Functions/Effects/Fade.d.ts +1 -0
  21. package/dist/src/Functions/Effects/Ripple.d.ts +1 -0
  22. package/dist/src/Functions/Effects/_.d.ts +3 -0
  23. package/dist/src/Functions/Input/Chips/Selector.d.ts +1 -0
  24. package/dist/src/Functions/Input/Chips/_.d.ts +2 -0
  25. package/dist/src/Functions/Input/DigitCharacters.d.ts +1 -0
  26. package/dist/src/Functions/Input/File/_.d.ts +2 -0
  27. package/dist/src/Functions/Input/Hidden.d.ts +1 -0
  28. package/dist/src/Functions/Input/List/_.d.ts +1 -0
  29. package/dist/src/Functions/Input/Segmented/_.d.ts +1 -0
  30. package/dist/src/Functions/Input/Select/_.d.ts +1 -0
  31. package/dist/src/Functions/Input/Slider/_.d.ts +1 -0
  32. package/dist/src/Functions/Input/Switch/_.d.ts +1 -0
  33. package/dist/src/Functions/Input/Text.d.ts +5 -0
  34. package/dist/src/Functions/Input/TextArea.d.ts +1 -0
  35. package/dist/src/Functions/Input/Time/Picker.d.ts +1 -0
  36. package/dist/src/Functions/Input/Time/_.d.ts +2 -0
  37. package/dist/src/Functions/Input/_.d.ts +5 -0
  38. package/dist/src/Functions/Input/core.d.ts +34 -0
  39. package/dist/src/Functions/Inputs/_.d.ts +3 -0
  40. package/dist/src/Functions/Inputs/text.d.ts +12 -0
  41. package/dist/src/Functions/Layout/PageNotFound.d.ts +1 -0
  42. package/dist/src/Functions/Layout/PageRouter.d.ts +2 -0
  43. package/dist/src/Functions/Layout/PageViewController/parts.d.ts +1 -0
  44. package/dist/src/Functions/Layout/Plate.d.ts +1 -0
  45. package/dist/src/Functions/Layout/RootViewController/parts.d.ts +1 -0
  46. package/dist/src/Functions/Layout/SwipeView/parts.d.ts +2 -0
  47. package/dist/src/Functions/Layout/TabBar.d.ts +1 -0
  48. package/dist/src/Functions/Layout/_.d.ts +2 -0
  49. package/dist/src/Functions/Loader/corner.d.ts +1 -0
  50. package/dist/src/Functions/Loader/mini.d.ts +33 -0
  51. package/dist/src/Functions/Loader/parts.d.ts +3 -0
  52. package/dist/src/Functions/Loader/top.d.ts +1 -0
  53. package/dist/src/Functions/Sheet/parts.d.ts +2 -0
  54. package/dist/src/Functions/SnackBar/parts.d.ts +2 -0
  55. package/dist/src/Functions/Table/Data/parts.d.ts +3 -0
  56. package/dist/src/Functions/Table/Drag/parts.d.ts +1 -0
  57. package/dist/src/Functions/Table/Normal/parts.d.ts +1 -0
  58. package/dist/src/Functions/Table/_.d.ts +9 -0
  59. package/dist/src/Functions/Tooltips/parts.d.ts +2 -0
  60. package/dist/src/Global/@export.d.ts +12 -0
  61. package/dist/src/Global/LaunchReactApplication.d.ts +1 -0
  62. package/dist/src/Global/styleConverter.d.ts +2 -0
  63. package/dist/src/Molecules/@export.d.ts +21 -0
  64. package/dist/src/Molecules/Accordion/parts.d.ts +2 -0
  65. package/dist/src/Molecules/LinkifyText/parts.d.ts +1 -0
  66. package/dist/src/Molecules/List.d.ts +1 -0
  67. package/dist/src/Organisms/@export.d.ts +2 -0
  68. package/dist/src/Organisms/DisplayStyleInput/_.d.ts +1 -0
  69. package/dist/src/Organisms/DisplayStyleInput/darkmode.d.ts +1 -0
  70. package/dist/src/Organisms/DisplayStyleInput/themeColor.d.ts +27 -0
  71. package/dist/src/Templates/@export.d.ts +2 -0
  72. package/dist/src/Templates/PlayGround/parts.d.ts +1 -0
  73. package/dist/src/config.d.ts +16 -0
  74. package/dist/src/launch.d.ts +9 -0
  75. package/dist/src/preload.d.ts +1 -0
  76. package/package.json +2 -2
  77. package/src/@jsminAmotifyExtension/_.tsx +4 -0
  78. package/src/@jsminAmotifyExtension/fetch.tsx +107 -0
  79. package/src/@jsminAmotifyExtension/formCollect.tsx +89 -0
  80. package/src/@jsminAmotifyExtension/spreadSheet.tsx +159 -0
  81. package/src/@jsminAmotifyExtension/variables.tsx +130 -0
  82. package/src/@styles/@app.scss +4 -0
  83. package/src/@styles/@variables/customProps.scss +109 -0
  84. package/src/@styles/@variables/styleSet.scss +38 -0
  85. package/src/@styles/@variables/themeColor.scss +71 -0
  86. package/src/@styles/@variables/var.scss +171 -0
  87. package/src/@styles/UniStyling.scss +996 -0
  88. package/src/@styles/init.scss +154 -0
  89. package/src/@types/_.tsx +6 -0
  90. package/src/@types/amot.tsx +323 -0
  91. package/src/@types/fn.tsx +1210 -0
  92. package/src/@types/index.tsx +74 -0
  93. package/src/@types/jsminAmotifyExtension.tsx +143 -0
  94. package/src/@types/module.tsx +2 -0
  95. package/src/@types/state.tsx +199 -0
  96. package/src/Atoms/@export.tsx +32 -0
  97. package/src/Atoms/FAIcon/parts.tsx +117 -0
  98. package/src/Atoms/FAIcon/style.module.scss +9 -0
  99. package/src/Atoms/Logo/parts.tsx +335 -0
  100. package/src/Atoms/Logo/style.module.scss +96 -0
  101. package/src/Atoms/Various/parts.tsx +157 -0
  102. package/src/Atoms/Various/style.module.scss +40 -0
  103. package/src/Functions/@export.tsx +29 -0
  104. package/src/Functions/Button/_.tsx +305 -0
  105. package/src/Functions/Button/style.module.scss +183 -0
  106. package/src/Functions/Cropper/parts.tsx +1061 -0
  107. package/src/Functions/Cropper/style.module.scss +62 -0
  108. package/src/Functions/Effects/Fade.tsx +81 -0
  109. package/src/Functions/Effects/Ripple.tsx +141 -0
  110. package/src/Functions/Effects/_.tsx +33 -0
  111. package/src/Functions/Effects/style.module.scss +83 -0
  112. package/src/Functions/Input/Chips/Selector.tsx +451 -0
  113. package/src/Functions/Input/Chips/_.tsx +286 -0
  114. package/src/Functions/Input/Chips/style.module.scss +6 -0
  115. package/src/Functions/Input/DigitCharacters.tsx +241 -0
  116. package/src/Functions/Input/File/_.tsx +596 -0
  117. package/src/Functions/Input/File/style.module.scss +34 -0
  118. package/src/Functions/Input/Hidden.tsx +18 -0
  119. package/src/Functions/Input/List/_.tsx +383 -0
  120. package/src/Functions/Input/List/style.module.scss +84 -0
  121. package/src/Functions/Input/Segmented/_.tsx +238 -0
  122. package/src/Functions/Input/Segmented/style.module.scss +81 -0
  123. package/src/Functions/Input/Select/_.tsx +225 -0
  124. package/src/Functions/Input/Select/style.module.scss +10 -0
  125. package/src/Functions/Input/Slider/_.tsx +519 -0
  126. package/src/Functions/Input/Slider/style.module.scss +67 -0
  127. package/src/Functions/Input/Switch/_.tsx +177 -0
  128. package/src/Functions/Input/Switch/style.module.scss +18 -0
  129. package/src/Functions/Input/Text.tsx +437 -0
  130. package/src/Functions/Input/TextArea.tsx +115 -0
  131. package/src/Functions/Input/Time/Picker.tsx +950 -0
  132. package/src/Functions/Input/Time/_.tsx +736 -0
  133. package/src/Functions/Input/Time/style.module.scss +72 -0
  134. package/src/Functions/Input/_.tsx +793 -0
  135. package/src/Functions/Input/core.tsx +461 -0
  136. package/src/Functions/Input/style.module.scss +43 -0
  137. package/src/Functions/Inputs/_.tsx +5 -0
  138. package/src/Functions/Inputs/style.module.scss +15 -0
  139. package/src/Functions/Inputs/text.tsx +67 -0
  140. package/src/Functions/Inputs/types.d.ts +1 -0
  141. package/src/Functions/Layout/PageNotFound.tsx +81 -0
  142. package/src/Functions/Layout/PageRouter.tsx +107 -0
  143. package/src/Functions/Layout/PageViewController/parts.tsx +32 -0
  144. package/src/Functions/Layout/Plate.tsx +30 -0
  145. package/src/Functions/Layout/RootViewController/parts.tsx +290 -0
  146. package/src/Functions/Layout/RootViewController/style.module.scss +24 -0
  147. package/src/Functions/Layout/SwipeView/parts.tsx +380 -0
  148. package/src/Functions/Layout/SwipeView/style.module.scss +19 -0
  149. package/src/Functions/Layout/TabBar.tsx +64 -0
  150. package/src/Functions/Layout/_.tsx +20 -0
  151. package/src/Functions/Loader/corner.tsx +78 -0
  152. package/src/Functions/Loader/mini.tsx +117 -0
  153. package/src/Functions/Loader/parts.tsx +105 -0
  154. package/src/Functions/Loader/style.module.scss +222 -0
  155. package/src/Functions/Loader/top.tsx +90 -0
  156. package/src/Functions/Sheet/parts.tsx +972 -0
  157. package/src/Functions/Sheet/style.module.scss +235 -0
  158. package/src/Functions/SnackBar/parts.tsx +215 -0
  159. package/src/Functions/SnackBar/style.module.scss +25 -0
  160. package/src/Functions/Table/Data/parts.tsx +955 -0
  161. package/src/Functions/Table/Drag/parts.tsx +448 -0
  162. package/src/Functions/Table/Normal/parts.tsx +123 -0
  163. package/src/Functions/Table/_.tsx +170 -0
  164. package/src/Functions/Table/style.module.scss +92 -0
  165. package/src/Functions/Tooltips/parts.tsx +52 -0
  166. package/src/Global/@export.tsx +138 -0
  167. package/src/Global/LaunchReactApplication.tsx +30 -0
  168. package/src/Global/exe.tsx +0 -0
  169. package/src/Global/styleConverter.tsx +435 -0
  170. package/src/Molecules/@export.tsx +95 -0
  171. package/src/Molecules/Accordion/parts.tsx +146 -0
  172. package/src/Molecules/Accordion/style.module.scss +13 -0
  173. package/src/Molecules/LinkifyText/parts.tsx +54 -0
  174. package/src/Molecules/List.tsx +30 -0
  175. package/src/Organisms/@export.tsx +5 -0
  176. package/src/Organisms/DisplayStyleInput/_.tsx +18 -0
  177. package/src/Organisms/DisplayStyleInput/darkmode.tsx +112 -0
  178. package/src/Organisms/DisplayStyleInput/themeColor.tsx +210 -0
  179. package/src/Templates/@export.tsx +7 -0
  180. package/src/Templates/PlayGround/parts.tsx +115 -0
  181. package/src/Templates/PlayGround/style.module.scss +38 -0
  182. package/src/config.tsx +132 -0
  183. package/src/launch.tsx +100 -0
  184. package/src/preload.tsx +49 -0
  185. package/tsconfig.json +27 -14
@@ -0,0 +1,286 @@
1
+ import {
2
+ useRecycle,
3
+ useStore
4
+ } from '@global';
5
+ const {
6
+ useEffect,
7
+ useState
8
+ } = React;
9
+ import {
10
+ FAIcon
11
+ } from '@atoms';
12
+ import {
13
+ Column,
14
+ Row,
15
+ Text
16
+ } from '@mols';
17
+ import {
18
+ Input,
19
+ Buttons,
20
+ Loader,
21
+ Sheet
22
+ } from '@functions';
23
+
24
+ import {
25
+ BoxWrapper,
26
+ SubmitForm,
27
+ ValidationCheck,
28
+ CommonEffects
29
+ } from '../core';
30
+
31
+ import {
32
+ ChipsInputFNs
33
+ } from './Selector';
34
+
35
+ import coreStyle from '../style.module.scss';
36
+
37
+ function DefaultValidation( props: {
38
+ value: any
39
+ params: any
40
+ } ): amotify.fn.Input.Validation.Result {
41
+ let {
42
+ value,
43
+ params
44
+ } = props;
45
+ let {
46
+ required
47
+ } = params as amotify.fn.Input.Chips.PlainParams;
48
+ let notice: amotify.fn.Input.Validation.NoticeTypes[] = [];
49
+
50
+ if ( required && !value.length ) {
51
+ notice.push( { type: 'invalid',label: '一つ以上選択してください' } );
52
+ }
53
+
54
+ return {
55
+ ok: !notice.filter( ( { type } ) => type == 'invalid' ).length,
56
+ notice: notice
57
+ }
58
+ }
59
+
60
+ const DataWrapping: FNC<amotify.fn.Input.Chips.PlainParams> = ( params ) => {
61
+ let DefaultValues = [ ...( params.value || [] ) ];
62
+ let Values = DefaultValues.splice( 0,params.limit || 65535 );
63
+
64
+ return ( <Core
65
+ SelectedCellComponent={ ( params ) => {
66
+ let {
67
+ value,
68
+ label,
69
+ removeCallback
70
+ } = params;
71
+
72
+ return <Row.Left
73
+ ssCardBox
74
+ padding={ '1/2' }
75
+ gap={ '1/2' }
76
+ isRounded
77
+ textAlign='left'
78
+ >
79
+ { label }
80
+ { params.defaultRemoveButton }
81
+ </Row.Left>;
82
+ } }
83
+ AddButtonComponent={ ( props ) => {
84
+ if ( params.limit && params.limit <= props.selected.length ) return null;
85
+
86
+ return <Buttons.Button.Sub.R
87
+ color='cloud'
88
+ padding={ '1/2' }
89
+ onClick={ () => {
90
+ props.openCallback();
91
+ } }
92
+ >
93
+ <FAIcon.Plus />
94
+ 追加する
95
+ </Buttons.Button.Sub.R>;
96
+ } }
97
+ { ...params }
98
+ value={ Values }
99
+ /> );
100
+ }
101
+
102
+ const Core: FNC<amotify.fn.Input.Chips.PlainParams> = ( params ) => {
103
+ let {
104
+ required,
105
+ form,
106
+ name,
107
+
108
+ checkValidationAtFirst,
109
+ onValidate,
110
+ onUpdateValue,onUpdateValidValue,
111
+ value = [],
112
+ limit,
113
+
114
+ SelectedCellComponent,
115
+ AddButtonComponent,
116
+
117
+ ...others
118
+ } = params;
119
+ AddButtonComponent = AddButtonComponent!;
120
+
121
+ let [ val_selectorID ] = useState( $.uuidGen() );
122
+ let [ val_status,set_status ] = useState( {
123
+ componentID: params.componentID || '',
124
+ dataValue: value.map( ( val: any ) => val ),
125
+ eventID: $.uuidGen(),
126
+ eventType: 'init'
127
+ } as amotify.fn.Input.Status.Plain );
128
+ let [ val_validate,set_validate ] = useState( {
129
+ ok: false,
130
+ notice: []
131
+ } as amotify.fn.Input.Validation.Result );
132
+
133
+ let [ val_selected,set_selected ] = useState( [ ...value ] );
134
+
135
+ CommonEffects( {
136
+ params,
137
+ val_status,set_status,
138
+ val_validate,set_validate,
139
+ DefaultValidation,
140
+ onUpdateValue,onUpdateValidValue,
141
+ ExtraOverrideParams: {
142
+ formatValue: val_selected,
143
+ dataValue: val_selected.map( ( val: any ) => val )
144
+ },
145
+ ExtraStoreParams: {
146
+ searchTimer: null
147
+ }
148
+ } );
149
+
150
+ const UpdateValue = ( values: amotify.fn.Input.Chips.OptionParams[] ) => {
151
+ set_selected( values );
152
+ set_status( {
153
+ ...val_status,
154
+ dataValue: values.map( ( val: any ) => val ),
155
+ eventID: $.uuidGen(),
156
+ eventType: 'update'
157
+ } as amotify.fn.Input.Status.Plain );
158
+ }
159
+ const OpenSelector = () => {
160
+ ChipsInputFNs.openSelector( {
161
+ parent: DefaultParentQuerySelector,
162
+ gravityPoint: params.selectorGravityPoint,
163
+ SelectorCellComponent: params.SelectorCellComponent,
164
+ selectorID: val_selectorID,
165
+ options: params.defaultOptions || [],
166
+ selected: val_selected,
167
+ limit: params.limit,
168
+ onDynamicSearch: params.onDynamicSearch,
169
+ onUpdated: ( args ) => {
170
+ UpdateValue( args.values );
171
+ },
172
+ onClosed: () => {
173
+ $( DefaultParentQuerySelector ).focus();
174
+ }
175
+ } );
176
+ }
177
+
178
+ let DefaultParentQuerySelector = `[data-chips-input-wrapper="${ val_selectorID }"]`;
179
+ let isFully = limit && limit <= val_selected.length;
180
+
181
+ const mounted = React.useRef( false );
182
+ useEffect( () => {
183
+ if ( mounted.current ) {
184
+ if ( isFully ) {
185
+ Sheet.close( val_selectorID );
186
+ $( DefaultParentQuerySelector ).focus();
187
+ }
188
+ } else {
189
+ mounted.current = true;
190
+ }
191
+ },[ val_selected ] );
192
+
193
+ let Selected = val_selected.map( ( s ) => {
194
+ let { value,label } = s;
195
+ SelectedCellComponent = SelectedCellComponent!;
196
+
197
+ const removeCallback = () => {
198
+ let findIndex = val_selected.findIndex( ( v ) => v.value == value );
199
+ if ( findIndex == -1 ) return;
200
+ let newSelected = [ ...val_selected ];
201
+ newSelected.splice( findIndex,1 );
202
+ UpdateValue( newSelected );
203
+ if ( !newSelected.length ) {
204
+ setTimeout( () => {
205
+ $( DefaultParentQuerySelector ).focus();
206
+ },200 );
207
+ }
208
+ }
209
+ return <SelectedCellComponent
210
+ value={ value }
211
+ label={ label }
212
+ removeCallback={ removeCallback }
213
+ defaultRemoveButton={ <Buttons.Button.Sub.S
214
+ flexSizing={ 'none' }
215
+ color='cloud'
216
+ backgroundColor='cloud'
217
+ isRounded
218
+ onClick={ () => {
219
+ removeCallback();
220
+ } }
221
+ >
222
+ <FAIcon.Times />
223
+ </Buttons.Button.Sub.S> }
224
+ openCallback={ () => {
225
+ OpenSelector();
226
+ } }
227
+ />
228
+ } );
229
+
230
+ return ( <BoxWrapper
231
+ val_status={ val_status }
232
+ set_status={ set_status }
233
+ val_validate={ val_validate }
234
+ params={ params }
235
+ >
236
+ <Input.Hidden
237
+ data-value={ JSON.stringify( val_status.dataValue.map( ( v: any ) => v.value ) ) }
238
+ name={ name }
239
+ form={ form }
240
+ data-input-type={ 'chips-' + [ 'single','multi' ][ Number( params.limit != 1 ) ] }
241
+ data-validation={ val_validate.ok }
242
+ componentID={ val_status.componentID }
243
+ data-focusor={ val_selectorID }
244
+ />
245
+ <button
246
+ data-chips-input-wrapper={ val_selectorID }
247
+ onKeyDown={ ( e ) => {
248
+ let { key,ctrlKey,metaKey,keyCode } = e;
249
+ let auxKey = ctrlKey || metaKey;
250
+ let isString = ( keyCode >= 48 && keyCode <= 57 ) || ( keyCode >= 65 && keyCode <= 90 ) || ( keyCode >= 96 && keyCode <= 105 );
251
+
252
+ if ( isString ) {
253
+ if ( isFully ) return;
254
+ OpenSelector();
255
+ } else if ( key == 'Tab' ) {
256
+
257
+ } else if ( key == 'Backspace' ) {
258
+ if ( !val_selected.length ) return;
259
+ if ( auxKey ) {
260
+ UpdateValue( [] );
261
+ } else {
262
+ let newSelected = [ ...val_selected ];
263
+ newSelected.pop();
264
+ UpdateValue( newSelected );
265
+ }
266
+ }
267
+ } }
268
+ onClick={ () => {
269
+ if ( isFully ) return;
270
+ if ( val_selected.length ) return;
271
+ OpenSelector();
272
+ } }
273
+ { ...others }
274
+ >
275
+ { !isFully ? <AddButtonComponent
276
+ selected={ val_selected }
277
+ openCallback={ OpenSelector }
278
+ /> : null }
279
+ { Selected }
280
+ </button>
281
+ </BoxWrapper> );
282
+ }
283
+
284
+ const ChipsInput: amotify.fn.Input.Chips.Methods = DataWrapping as any;
285
+ ChipsInput.fn = ChipsInputFNs;
286
+ export { ChipsInput }
@@ -0,0 +1,6 @@
1
+ @use '@uniVar' as *;
2
+ @use'@styleSet' as *;
3
+
4
+ .SelectorWrapper {
5
+ @include OriginScrollBar();
6
+ }
@@ -0,0 +1,241 @@
1
+ import {
2
+ React
3
+ } from '@global';
4
+ const {
5
+ useState
6
+ } = React;
7
+
8
+ import {
9
+ Flex
10
+ } from '@atoms';
11
+ import {
12
+ Input
13
+ } from '@functions';
14
+ import {
15
+ BoxWrapper,
16
+ SubmitForm,
17
+ CommonEffects
18
+ } from './core'
19
+
20
+ import style from './style.module.scss';
21
+
22
+ function DefaultValidation( props: {
23
+ value: any
24
+ params: any
25
+ } ): amotify.fn.Input.Validation.Result {
26
+ let { value,params } = props;
27
+ let {
28
+ required,
29
+ numericOnly = false,
30
+ digits
31
+ } = params as amotify.fn.Input.DigitCharacters.PlainParams;
32
+ let notice: amotify.fn.Input.Validation.NoticeTypes[] = [];
33
+
34
+ if ( required && !value ) {
35
+ notice.push( { type: 'invalid',label: '必須項目です' } );
36
+ }
37
+ if ( value ) {
38
+ if ( numericOnly && value.match( /\D/ ) ) {
39
+ notice.push( { type: 'invalid',label: '数字のみで入力してください' } );
40
+ }
41
+ if ( value.length != digits ) {
42
+ notice.push( { type: 'warn',label: '最後まで入力してください' } );
43
+ }
44
+ }
45
+
46
+ return {
47
+ ok: !notice.filter( ( { type } ) => type == 'invalid' || type == 'warn' ).length,
48
+ notice: notice
49
+ }
50
+ }
51
+
52
+
53
+ const dataToFormat = ( digits: number,value: any = '' ) => {
54
+ let dataValue = String( value );
55
+ let formatValue: any = [];
56
+ for ( let index = 0; index < digits; index++ ) {
57
+ formatValue[ index ] = dataValue[ index ] || '';
58
+ }
59
+ return {
60
+ formatValue,
61
+ dataValue
62
+ };
63
+ }
64
+ const formatToData = ( value: any = '' ) => {
65
+ let formatValue = value;
66
+ let dataValue = formatValue.join( '' );
67
+ return {
68
+ formatValue,
69
+ dataValue
70
+ }
71
+ }
72
+
73
+
74
+ export const DigitCharactersInput: FNC<amotify.fn.Input.DigitCharacters.PlainParams> = ( params ) => {
75
+ let {
76
+ tone,
77
+ required,
78
+ form,
79
+ name,
80
+
81
+ className = '',
82
+ digits,
83
+ numericOnly = false,
84
+ enableFormSubmit,
85
+
86
+ checkValidationAtFirst,
87
+ onChange,onKeyDown,
88
+ onValidate,
89
+ onUpdateValue,
90
+ onUpdateValidValue,
91
+ value = '',
92
+
93
+ override,
94
+ statusID,
95
+ componentID,
96
+ listStyles,
97
+ ...others
98
+ } = params;
99
+
100
+ if ( numericOnly ) {
101
+ params.inputMode = params.inputMode || 'numeric';
102
+ }
103
+
104
+ let Default_Status: amotify.fn.Input.Status.DigitCharacters = {
105
+ componentID: params.componentID || '',
106
+ ...dataToFormat( digits,value ),
107
+ eventType: 'init',
108
+ eventID: $.uuidGen()
109
+ }
110
+
111
+ let [ val_status,set_status ] = useState( Default_Status );
112
+ let [ val_validate,set_validate ] = useState( {
113
+ ok: false,
114
+ notice: []
115
+ } as amotify.fn.Input.Validation.Result );
116
+
117
+ CommonEffects( {
118
+ params,
119
+ val_status,
120
+ set_status,
121
+ val_validate,
122
+ set_validate,
123
+ onUpdateValue,
124
+ onUpdateValidValue,
125
+ DefaultValidation
126
+ } );
127
+
128
+ let Digits = [];
129
+ for ( let index = 0; index < digits; index++ ) {
130
+ let Character = val_status.formatValue[ index ];
131
+
132
+ let Styles: React.CSSProperties = {}
133
+
134
+ if ( params.combineInput ) {
135
+ if ( index == 0 ) {
136
+ Styles = {
137
+ borderTopLeftRadius: 'inherit',
138
+ borderBottomLeftRadius: 'inherit'
139
+ }
140
+ } else if ( index == digits - 1 ) {
141
+ Styles = {
142
+ borderTopRightRadius: 'inherit',
143
+ borderBottomRightRadius: 'inherit'
144
+ }
145
+ }
146
+ }
147
+
148
+ Digits.push( <input
149
+ type={ 'text' }
150
+ inputMode={ params.inputMode || 'text' }
151
+ value={ Character }
152
+ data-form-name={ form }
153
+ id={ 'Digit-' + index + '-' + val_status.componentID }
154
+ className={ className }
155
+ style={ {
156
+ ...params.style,
157
+ ...Styles
158
+ } }
159
+ onKeyDown={ ( event ) => {
160
+ let {
161
+ key,
162
+ code
163
+ } = event;
164
+
165
+ if ( key == 'Tab' ) return;
166
+ event.preventDefault();
167
+ let nextFocusIndex = null;
168
+
169
+ if ( key == 'Backspace' ) {
170
+ let newFormatValue = val_status.formatValue;
171
+ newFormatValue[ index ] = '';
172
+
173
+ set_status( {
174
+ ...val_status,
175
+ ...formatToData( newFormatValue ),
176
+ eventType: 'update',
177
+ eventID: $.uuidGen()
178
+ } );
179
+ nextFocusIndex = index - 1;
180
+ } else if ( [ 'ArrowLeft','ArrowRight' ].includes( key ) ) {
181
+ let dir = Number( key == 'ArrowRight' ) * 2 - 1;
182
+ nextFocusIndex = index + dir;
183
+ } else {
184
+ if ( enableFormSubmit ) SubmitForm( event );
185
+
186
+ ( () => {
187
+ let regExp = code.match( /^(Key(.)|Digit(\d)|Numpad(\d))/ );
188
+ if ( !regExp ) return;
189
+
190
+ let newCharacter: string = regExp[ 2 ] || regExp[ 3 ] || regExp[ 4 ];
191
+ if ( numericOnly ) {
192
+ if ( !newCharacter.match( /\d/ ) ) return;
193
+ }
194
+ if ( !newCharacter ) return;
195
+
196
+ let newFormatValue = val_status.formatValue;
197
+ newFormatValue[ index ] = newCharacter;
198
+
199
+ set_status( {
200
+ ...val_status,
201
+ ...formatToData( newFormatValue ),
202
+ eventType: 'update',
203
+ eventID: $.uuidGen()
204
+ } );
205
+ nextFocusIndex = index + 1;
206
+ } )();
207
+ }
208
+
209
+ if ( $.is.exist( nextFocusIndex ) ) {
210
+ $( '#Digit-' + nextFocusIndex + '-' + val_status.componentID ).focus();
211
+ }
212
+ } }
213
+ /> );
214
+ }
215
+
216
+ return ( <BoxWrapper
217
+ val_status={ val_status }
218
+ set_status={ set_status }
219
+ val_validate={ val_validate }
220
+ params={ params }
221
+ >
222
+ <Input.Hidden
223
+ name={ name }
224
+ data-input-type={ 'digitCharacters' }
225
+ data-form={ form }
226
+ data-validation={ val_validate.ok }
227
+ componentID={ val_status.componentID }
228
+ data-value={ val_status.dataValue }
229
+ { ...others }
230
+ />
231
+ <Flex
232
+ gap={ '1/2' }
233
+ flexChilds='even'
234
+ flexWrap={ false }
235
+ flexSizing='auto'
236
+ { ...listStyles }
237
+ >
238
+ { Digits }
239
+ </Flex>
240
+ </BoxWrapper> );
241
+ }