amotify 0.0.6 → 0.0.8

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 (160) hide show
  1. package/dist/@jsminAmotifyExtension/formCollect.js +2 -2
  2. package/dist/Atoms/Logo/parts.js +11 -11
  3. package/dist/Atoms/Various/parts.js +5 -5
  4. package/dist/Functions/Button/_.js +5 -5
  5. package/dist/Functions/Cropper/parts.js +47 -47
  6. package/dist/Functions/Effects/Fade.js +5 -5
  7. package/dist/Functions/Input/Chips/Selector.js +32 -32
  8. package/dist/Functions/Input/Chips/_.js +10 -10
  9. package/dist/Functions/Input/DigitCharacters.js +8 -8
  10. package/dist/Functions/Input/File/_.js +33 -33
  11. package/dist/Functions/Input/List/_.js +17 -17
  12. package/dist/Functions/Input/Segmented/_.js +13 -13
  13. package/dist/Functions/Input/Select/_.js +12 -12
  14. package/dist/Functions/Input/Slider/_.js +16 -16
  15. package/dist/Functions/Input/Switch/_.js +12 -12
  16. package/dist/Functions/Input/Text.js +12 -12
  17. package/dist/Functions/Input/TextArea.js +4 -4
  18. package/dist/Functions/Input/Time/Picker.js +65 -65
  19. package/dist/Functions/Input/Time/_.js +10 -10
  20. package/dist/Functions/Input/_.js +31 -31
  21. package/dist/Functions/Input/core.js +27 -27
  22. package/dist/Functions/Inputs/text.js +2 -2
  23. package/dist/Functions/Layout/PageNotFound.js +15 -15
  24. package/dist/Functions/Layout/PageRouter.js +5 -5
  25. package/dist/Functions/Layout/PageViewController/parts.js +5 -5
  26. package/dist/Functions/Layout/Plate.js +2 -2
  27. package/dist/Functions/Layout/RootViewController/parts.js +22 -22
  28. package/dist/Functions/Layout/SwipeView/parts.js +6 -6
  29. package/dist/Functions/Layout/TabBar.js +7 -7
  30. package/dist/Functions/Loader/corner.js +13 -13
  31. package/dist/Functions/Loader/mini.js +4 -4
  32. package/dist/Functions/Loader/parts.js +9 -9
  33. package/dist/Functions/Loader/top.js +22 -22
  34. package/dist/Functions/Sheet/parts.js +46 -46
  35. package/dist/Functions/SnackBar/parts.js +16 -16
  36. package/dist/Functions/Table/Data/parts.js +72 -72
  37. package/dist/Functions/Table/Drag/parts.js +15 -15
  38. package/dist/Functions/Table/_.js +11 -11
  39. package/dist/Functions/Tooltips/parts.js +6 -6
  40. package/dist/Molecules/@export.js +14 -14
  41. package/dist/Molecules/Accordion/parts.js +10 -10
  42. package/dist/Molecules/LinkifyText/parts.js +4 -4
  43. package/dist/Molecules/List.js +3 -3
  44. package/dist/Organisms/DisplayStyleInput/darkmode.js +17 -17
  45. package/dist/Organisms/DisplayStyleInput/themeColor.js +25 -25
  46. package/dist/Templates/PlayGround/parts.js +22 -22
  47. package/dist/launch.js +12 -12
  48. package/package.json +1 -1
  49. package/public/amotify.js +47 -47
  50. package/src/@jsminAmotifyExtension/_.tsx +4 -0
  51. package/src/@jsminAmotifyExtension/fetch.tsx +107 -0
  52. package/src/@jsminAmotifyExtension/formCollect.tsx +89 -0
  53. package/src/@jsminAmotifyExtension/spreadSheet.tsx +159 -0
  54. package/src/@jsminAmotifyExtension/variables.tsx +130 -0
  55. package/src/@styles/@app.scss +4 -0
  56. package/src/@styles/UniStyling.scss +996 -0
  57. package/src/@styles/init.scss +154 -0
  58. package/src/@styles/props.scss +109 -0
  59. package/src/@styles/styleSet.scss +38 -0
  60. package/src/@styles/themeColor.scss +71 -0
  61. package/src/@styles/var.scss +171 -0
  62. package/src/@types/_.tsx +6 -0
  63. package/src/@types/amot.tsx +323 -0
  64. package/src/@types/fn.tsx +1210 -0
  65. package/src/@types/index.tsx +74 -0
  66. package/src/@types/jsminAmotifyExtension.tsx +143 -0
  67. package/src/@types/module.tsx +2 -0
  68. package/src/@types/state.tsx +199 -0
  69. package/src/Atoms/@export.tsx +32 -0
  70. package/src/Atoms/FAIcon/parts.tsx +117 -0
  71. package/src/Atoms/FAIcon/style.module.scss +9 -0
  72. package/src/Atoms/Logo/parts.tsx +335 -0
  73. package/src/Atoms/Logo/style.module.scss +96 -0
  74. package/src/Atoms/Various/parts.tsx +157 -0
  75. package/src/Atoms/Various/style.module.scss +40 -0
  76. package/src/Functions/@export.tsx +29 -0
  77. package/src/Functions/Button/_.tsx +305 -0
  78. package/src/Functions/Button/style.module.scss +183 -0
  79. package/src/Functions/Cropper/parts.tsx +1061 -0
  80. package/src/Functions/Cropper/style.module.scss +62 -0
  81. package/src/Functions/Effects/Fade.tsx +81 -0
  82. package/src/Functions/Effects/Ripple.tsx +141 -0
  83. package/src/Functions/Effects/_.tsx +33 -0
  84. package/src/Functions/Effects/style.module.scss +83 -0
  85. package/src/Functions/Input/Chips/Selector.tsx +451 -0
  86. package/src/Functions/Input/Chips/_.tsx +286 -0
  87. package/src/Functions/Input/Chips/style.module.scss +6 -0
  88. package/src/Functions/Input/DigitCharacters.tsx +241 -0
  89. package/src/Functions/Input/File/_.tsx +596 -0
  90. package/src/Functions/Input/File/style.module.scss +34 -0
  91. package/src/Functions/Input/Hidden.tsx +18 -0
  92. package/src/Functions/Input/List/_.tsx +383 -0
  93. package/src/Functions/Input/List/style.module.scss +84 -0
  94. package/src/Functions/Input/Segmented/_.tsx +238 -0
  95. package/src/Functions/Input/Segmented/style.module.scss +81 -0
  96. package/src/Functions/Input/Select/_.tsx +225 -0
  97. package/src/Functions/Input/Select/style.module.scss +10 -0
  98. package/src/Functions/Input/Slider/_.tsx +519 -0
  99. package/src/Functions/Input/Slider/style.module.scss +67 -0
  100. package/src/Functions/Input/Switch/_.tsx +177 -0
  101. package/src/Functions/Input/Switch/style.module.scss +18 -0
  102. package/src/Functions/Input/Text.tsx +437 -0
  103. package/src/Functions/Input/TextArea.tsx +115 -0
  104. package/src/Functions/Input/Time/Picker.tsx +950 -0
  105. package/src/Functions/Input/Time/_.tsx +736 -0
  106. package/src/Functions/Input/Time/style.module.scss +72 -0
  107. package/src/Functions/Input/_.tsx +793 -0
  108. package/src/Functions/Input/core.tsx +461 -0
  109. package/src/Functions/Input/style.module.scss +43 -0
  110. package/src/Functions/Inputs/_.tsx +5 -0
  111. package/src/Functions/Inputs/style.module.scss +15 -0
  112. package/src/Functions/Inputs/text.tsx +67 -0
  113. package/src/Functions/Inputs/types.d.ts +1 -0
  114. package/src/Functions/Layout/PageNotFound.tsx +81 -0
  115. package/src/Functions/Layout/PageRouter.tsx +107 -0
  116. package/src/Functions/Layout/PageViewController/parts.tsx +32 -0
  117. package/src/Functions/Layout/Plate.tsx +30 -0
  118. package/src/Functions/Layout/RootViewController/parts.tsx +290 -0
  119. package/src/Functions/Layout/RootViewController/style.module.scss +24 -0
  120. package/src/Functions/Layout/SwipeView/parts.tsx +380 -0
  121. package/src/Functions/Layout/SwipeView/style.module.scss +19 -0
  122. package/src/Functions/Layout/TabBar.tsx +64 -0
  123. package/src/Functions/Layout/_.tsx +20 -0
  124. package/src/Functions/Loader/corner.tsx +78 -0
  125. package/src/Functions/Loader/mini.tsx +117 -0
  126. package/src/Functions/Loader/parts.tsx +105 -0
  127. package/src/Functions/Loader/style.module.scss +222 -0
  128. package/src/Functions/Loader/top.tsx +90 -0
  129. package/src/Functions/Sheet/parts.tsx +972 -0
  130. package/src/Functions/Sheet/style.module.scss +235 -0
  131. package/src/Functions/SnackBar/parts.tsx +215 -0
  132. package/src/Functions/SnackBar/style.module.scss +25 -0
  133. package/src/Functions/Table/Data/parts.tsx +955 -0
  134. package/src/Functions/Table/Drag/parts.tsx +448 -0
  135. package/src/Functions/Table/Normal/parts.tsx +123 -0
  136. package/src/Functions/Table/_.tsx +170 -0
  137. package/src/Functions/Table/style.module.scss +92 -0
  138. package/src/Functions/Tooltips/parts.tsx +52 -0
  139. package/src/Global/@export.tsx +138 -0
  140. package/src/Global/LaunchReactApplication.tsx +30 -0
  141. package/src/Global/exe.tsx +0 -0
  142. package/src/Global/styleConverter.tsx +435 -0
  143. package/src/Molecules/@export.tsx +95 -0
  144. package/src/Molecules/Accordion/parts.tsx +146 -0
  145. package/src/Molecules/Accordion/style.module.scss +13 -0
  146. package/src/Molecules/LinkifyText/parts.tsx +54 -0
  147. package/src/Molecules/List.tsx +30 -0
  148. package/src/Organisms/@export.tsx +5 -0
  149. package/src/Organisms/DisplayStyleInput/_.tsx +18 -0
  150. package/src/Organisms/DisplayStyleInput/darkmode.tsx +112 -0
  151. package/src/Organisms/DisplayStyleInput/themeColor.tsx +210 -0
  152. package/src/Templates/@export.tsx +7 -0
  153. package/src/Templates/PlayGround/parts.tsx +116 -0
  154. package/src/Templates/PlayGround/style.module.scss +38 -0
  155. package/src/config.tsx +132 -0
  156. package/src/index.js +0 -0
  157. package/src/launch.tsx +100 -0
  158. package/src/preload.tsx +49 -0
  159. package/tsconfig.json +4 -22
  160. package/webpack.config.js +105 -0
@@ -0,0 +1,736 @@
1
+ import {
2
+ useStore
3
+ } from '~/Global/@export';
4
+ import {
5
+ Box
6
+ } from '~/Atoms/@export';
7
+ import {
8
+ Input,
9
+ Buttons,
10
+ Tooltips
11
+ } from '~/Functions/@export';
12
+
13
+ import {
14
+ BoxWrapper,
15
+ SubmitForm,
16
+ ValidationCheck,
17
+ CommonEffects
18
+ } from '../core';
19
+ import { Picker } from './Picker';
20
+ const {
21
+ useEffect,
22
+ useState,
23
+ useRef
24
+ } = React;
25
+
26
+ const PeriodMargin = ' ~ ';
27
+
28
+ const TimeFormatDatas: {
29
+ [ key: string ]: {
30
+ defaultValue: string
31
+ format: RegExp
32
+ ranges: amotify.fn.Input.Time.RangeProps[]
33
+ sets: number
34
+ }
35
+ } = {
36
+ clock: {
37
+ defaultValue: '--:--',format: /^\d{2}\D\d{2}$/,ranges: [
38
+ { type: 'hour',from: 0,length: 2 },
39
+ { type: 'minute',from: 3,length: 2 }
40
+ ],sets: 1
41
+ },
42
+ date: {
43
+ defaultValue: '----/--/--',format: /^\d{4}\D\d{2}\D\d{2}$/,ranges: [
44
+ { type: 'year',from: 0,length: 4 },
45
+ { type: 'month',from: 5,length: 2 },
46
+ { type: 'date',from: 8,length: 2 }
47
+ ],sets: 1
48
+ },
49
+ week: {
50
+ defaultValue: '----年第--週',format: /^\d{4}\D\d{2}$/,ranges: [
51
+ { type: 'year',from: 0,length: 4,region: 6 },
52
+ { type: 'week',from: 6,length: 2,region: 3 }
53
+ ],sets: 1
54
+ },
55
+ month: {
56
+ defaultValue: '----年--月',format: /^\d{4}\D\d{2}$/,ranges: [
57
+ { type: 'year',from: 0,length: 4 },
58
+ { type: 'month',from: 5,length: 2,region: 3 }
59
+ ],sets: 1
60
+ },
61
+ year: {
62
+ defaultValue: '----年',format: /^\d{4}$/,ranges: [
63
+ { type: 'year',from: 0,length: 4,region: 5 }
64
+ ],sets: 1
65
+ },
66
+ dates: {
67
+ defaultValue: '----/--/--',format: /^\d{4}\D\d{2}\D\d{2}$/,ranges: [
68
+ { type: 'year',from: 0,length: 4 },
69
+ { type: 'month',from: 5,length: 2 },
70
+ { type: 'date',from: 8,length: 2,region: 5 },
71
+ { type: 'year',from: 10 + PeriodMargin.length,length: 4 },
72
+ { type: 'month',from: 15 + PeriodMargin.length,length: 2 },
73
+ { type: 'date',from: 18 + PeriodMargin.length,length: 2 }
74
+ ],sets: 2
75
+ },
76
+ months: {
77
+ defaultValue: '----年--月',format: /^\d{4}\D\d{2}$/,ranges: [
78
+ { type: 'year',from: 0,length: 4 },
79
+ { type: 'month',from: 5,length: 2,region: 6 },
80
+ { type: 'year',from: 8 + PeriodMargin.length,length: 4 },
81
+ { type: 'month',from: 13 + PeriodMargin.length,length: 2,region: 3 }
82
+ ],sets: 2
83
+ },
84
+ dateWareki: {
85
+ defaultValue: '----年--月--日',format: /^\d{4}\D\d{2}\D\d{2}$/,ranges: [
86
+ { type: 'dateWareki',from: 0,length: 4,region: 5 },
87
+ { type: 'month',from: 5,length: 2,region: 3 },
88
+ { type: 'date',from: 8,length: 2,region: 3 }
89
+ ],sets: 1
90
+ }
91
+ }
92
+
93
+ const DataLeveling = ( params: {
94
+ restrict: amotify.fn.Input.Time.RestrictTypes
95
+ value: any
96
+ era: amotify.fn.Input.Time.EraTypes
97
+ } ) => {
98
+ let {
99
+ restrict,
100
+ value,
101
+ era
102
+ } = params;
103
+
104
+ let dataValue = $.flatArray( value || '' );
105
+
106
+ let {
107
+ defaultValue,
108
+ format,
109
+ ranges,
110
+ sets
111
+ } = TimeFormatDatas[ restrict ];
112
+ let formatValues: string[] = [];
113
+
114
+ let separateStr = restrict == 'clock' ? ':' : '/';
115
+ for ( let index = 0; index < dataValue.length; index++ ) {
116
+ dataValue[ index ] = String( dataValue[ index ] ).replace( /\D/ig,separateStr );
117
+ }
118
+ for ( let index = 0; index < sets; index++ ) {
119
+ let val = dataValue[ index ] || '';
120
+ if ( !val.match( format ) ) {
121
+ dataValue[ index ] = '';
122
+ formatValues.push( defaultValue );
123
+ } else {
124
+ let _value = defaultValue;
125
+ val.split( /\D/ ).forEach( ( v: string,i: number ) => {
126
+ if ( i == 0 && restrict == 'dateWareki' ) {
127
+ let Year = Number( v );
128
+ if ( era != 'year' ) {
129
+ if ( Year >= 2019 ) Year -= 2019;
130
+ else if ( Year >= 1989 ) Year -= 1989;
131
+ else if ( Year >= 1926 ) Year -= 1926;
132
+ else if ( Year >= 1912 ) Year -= 1912;
133
+ else if ( Year >= 1868 ) Year -= 1868;
134
+ Year += 1;
135
+ }
136
+ v = Year.zeroEmbed( 4 );
137
+ }
138
+ _value = _value.replace( new RegExp( '------------------'.slice( 0,v.length ) ),v );
139
+ } );
140
+ formatValues.push( _value );
141
+ }
142
+ }
143
+
144
+ return {
145
+ formatValue: formatValues.join( PeriodMargin ),
146
+ dataValue: [ 'dates','months' ].includes( restrict ) ? dataValue : dataValue[ 0 ],
147
+ ranges
148
+ };
149
+ }
150
+
151
+ function DefaultValidation( props: {
152
+ value: any
153
+ params: any
154
+ } ): amotify.fn.Input.Validation.Result {
155
+ let {
156
+ params
157
+ } = props;
158
+ let {
159
+ restrict,
160
+ min,max,
161
+ required
162
+ } = params as amotify.fn.Input.Time.OriginParams
163
+ let notice: amotify.fn.Input.Validation.NoticeTypes[] = [];
164
+ let values: string[] = $.flatArray( props.value );
165
+
166
+ let validate = {
167
+ empty: false,
168
+ escalated: 1,
169
+ filled: true,
170
+ correct: true,
171
+ prohibited: false
172
+ };
173
+
174
+ ( () => {
175
+ let separateStr = restrict == 'clock' ? ':' : '/';
176
+ for ( let index = 0; index < values.length; index++ ) {
177
+ values[ index ] = String( values[ index ] ).replace( /\D/ig,separateStr );
178
+ }
179
+ for ( let index = 0; index < values.length; index++ ) {
180
+ let value = values[ index ];
181
+ let prevValue = values[ index - 1 ];
182
+ if ( !value.removeLetters() ) validate.empty = true;
183
+ if ( index > 0 ) validate.escalated &= Number( value >= prevValue );
184
+ }
185
+ if ( !validate.escalated ) return;
186
+ if ( validate.empty ) return;
187
+
188
+ if ( restrict.match( /clock/ ) ) {
189
+ values.forEach( value => {
190
+ let [ hour,minute ] = value.split( /\D+/ );
191
+
192
+ if ( !hour || !minute ) {
193
+ validate.filled = false;
194
+ } else if ( Number( hour ) > 23 || Number( minute ) > 59 ) {
195
+ validate.correct = false;
196
+ }
197
+ } );
198
+ } else if ( restrict.match( /date/ ) ) {
199
+ values.forEach( value => {
200
+ let [ year,month,day ] = value.split( /\D+/ );
201
+ if ( !year || !month || !day ) {
202
+ validate.filled = false;
203
+ } else {
204
+ let Time = $.Time( value );
205
+ if ( !Time.validate || value != Time.toFormatYMD() ) {
206
+ validate.correct = false;
207
+ }
208
+ }
209
+ } );
210
+ } else if ( restrict.match( /week/ ) ) {
211
+ values.forEach( value => {
212
+ let [ year,week ] = value.split( /\D+/ );
213
+ if ( !year || !week ) {
214
+ validate.filled = false;
215
+ } else {
216
+ let yearFirstDay = $.Time( year + '/01/01' ).weekday;
217
+ let yearFirstWeek0Day = $.Time( year + '/01/0' + ( 7 - yearFirstDay + 1 ) );
218
+ let yearValueWeek0Day = yearFirstWeek0Day.addWeek( Number( week ) - 1 );
219
+ if ( year != String( yearValueWeek0Day.year ) ) {
220
+ validate.correct = false;
221
+ }
222
+ }
223
+ } );
224
+ } else if ( restrict.match( /month/ ) ) {
225
+ values.forEach( value => {
226
+ let [ year,month ] = value.split( /\D+/ );
227
+ if ( !year || !month ) {
228
+ validate.filled = false;
229
+ } else {
230
+ let date = $.Time( [ year,month,'01' ].join( '/' ) );
231
+ if ( !date.validate ) validate.correct = false;
232
+ }
233
+ } )
234
+ } else if ( restrict.match( /year/ ) ) {
235
+
236
+ }
237
+
238
+ if ( validate.filled && validate.correct ) {
239
+ values.forEach( value => {
240
+ {
241
+ let VAL = Number( String( value ).replace( /\D/ig,'' ) );
242
+ if ( min ) {
243
+ let MIN = Number( String( min ).replace( /\D/ig,'' ) );
244
+ if ( MIN > VAL ) validate.prohibited = true;
245
+ }
246
+ if ( max ) {
247
+ let MAX = Number( String( max ).replace( /\D/ig,'' ) );
248
+ if ( VAL > MAX ) validate.prohibited = true;
249
+ }
250
+ }
251
+ } )
252
+ }
253
+ } )();
254
+
255
+ {
256
+ let {
257
+ empty,
258
+ escalated,
259
+ filled,
260
+ correct,
261
+ prohibited
262
+ } = validate;
263
+ if ( empty && required ) {
264
+ notice = [
265
+ { type: 'invalid',label: '必須項目です' }
266
+ ];
267
+ }
268
+ if ( !escalated ) {
269
+ notice.push( { type: 'invalid',label: '時系列を正しく入力してください' } );
270
+ }
271
+ if ( !correct ) {
272
+ notice.push( { type: 'invalid',label: '無効な値が入力されています' } );
273
+ }
274
+ if ( !filled ) {
275
+ notice.push( { type: 'invalid',label: '最後まで値を埋めてください' } );
276
+ }
277
+ if ( prohibited ) {
278
+ notice.push( {
279
+ type: 'invalid',label: <>
280
+ <Box>
281
+ 入力範囲が制限されています
282
+ </Box>
283
+ [{ min || '下限無し' }] ~ [{ max || '上限無し' }]
284
+ </>
285
+ } );
286
+ }
287
+ }
288
+
289
+ return {
290
+ ok: !notice.filter( ( { type } ) => type == 'invalid' ).length,
291
+ notice: notice
292
+ }
293
+ }
294
+
295
+ type FocusProps = {
296
+ active: boolean
297
+ index: number
298
+ prevIndex: number
299
+ }
300
+
301
+ export const TimeInput: FNC<amotify.fn.Input.Time.OriginParams> = ( params ) => {
302
+ let {
303
+ tone,
304
+ required,
305
+ restrict = 'clock',
306
+ componentID,
307
+ era,
308
+ form,
309
+ name,
310
+ min,max,
311
+ className,
312
+
313
+ enableFormSubmit,
314
+
315
+ checkValidationAtFirst,
316
+ onKeyDown,
317
+ onValidate,
318
+ onUpdateValue,
319
+ onUpdateValidValue,
320
+ value = '',
321
+ leftIndicator,rightIndicator,
322
+
323
+ ...others
324
+ } = params;
325
+
326
+ let [ val_era,set_era ] = useState( era! );
327
+
328
+ let [ val_status,set_status ] = useState( {
329
+ componentID: params.componentID || '',
330
+ ...DataLeveling( {
331
+ restrict,
332
+ value,
333
+ era: val_era
334
+ } ),
335
+ eventType: 'init',
336
+ eventID: $.uuidGen(),
337
+ } as amotify.fn.Input.Status.Time );
338
+
339
+ let [ val_validate,set_validate ] = useState( {
340
+ ok: false,
341
+ notice: []
342
+ } as amotify.fn.Input.Validation.Result );
343
+ let [ val_focus,set_focus ] = useState( {
344
+ active: false,
345
+ index: 0,
346
+ prevIndex: -1
347
+ } as FocusProps );
348
+
349
+ CommonEffects( {
350
+ type: 'time',
351
+ params,
352
+ val_status,
353
+ set_status,
354
+ val_validate,
355
+ set_validate,
356
+ DefaultValidation,
357
+ onUpdateValue,
358
+ onUpdateValidValue,
359
+ ExtraOverrideParams: {
360
+ ...DataLeveling( {
361
+ restrict,
362
+ value,
363
+ era: val_era!
364
+ } )
365
+ }
366
+ } );
367
+
368
+ const mounted = useRef( false );
369
+ useEffect( () => {
370
+ if ( mounted.current ) {
371
+ set_status( {
372
+ ...val_status,
373
+ ...DataLeveling( {
374
+ restrict,
375
+ value: val_status.dataValue,
376
+ era: val_era
377
+ } )
378
+ } );
379
+ } else {
380
+ mounted.current = true;
381
+ }
382
+ },[ val_era ] );
383
+
384
+ useStore.update( {
385
+ key: val_status.componentID,
386
+ value: {
387
+ openPicker: () => {
388
+ if ( params.disabled ) return;
389
+
390
+ TimeFNs.picker.launch( {
391
+ parent: '#Picker-' + val_status.componentID,
392
+ tipsID: 'PickerTips-' + val_status.componentID,
393
+ restrict,
394
+ min,max,
395
+ defaultValue: val_status.dataValue,
396
+ onValueUpdate: ( value ) => {
397
+ set_status( {
398
+ ...val_status,
399
+ ...DataLeveling( {
400
+ restrict,
401
+ value: value,
402
+ era: val_era!
403
+ } ),
404
+ eventType: 'update',
405
+ eventID: $.uuidGen()
406
+ } );
407
+ }
408
+ } );
409
+ },
410
+ resetEra: ( era: amotify.fn.Input.Time.EraTypes ) => {
411
+ set_era( era );
412
+ set_status( {
413
+ ...val_status,
414
+ ...DataLeveling( {
415
+ restrict,
416
+ value: '',
417
+ era: val_era!
418
+ } ),
419
+ eventType: 'update',
420
+ eventID: $.uuidGen()
421
+ } );
422
+ }
423
+ }
424
+ } );
425
+
426
+ useEffect( () => {
427
+ let { index,active } = val_focus;
428
+ if ( active ) {
429
+ index = Math.max( index,0 );
430
+ index = Math.min( index,val_status.ranges.length - 1 );
431
+
432
+ let { from,length } = val_status.ranges[ index ];
433
+ let input = $( '#' + params.id )[ 0 ] as HTMLInputElement;
434
+ if ( input ) input.setSelectionRange( from,( from + length ) );
435
+ }
436
+ },[ val_focus ] );
437
+
438
+ return (
439
+ <BoxWrapper
440
+ val_status={ val_status }
441
+ set_status={ set_status }
442
+ val_validate={ val_validate }
443
+ params={ params }
444
+ >
445
+ <Input.Hidden
446
+ name={ name }
447
+ data-input-type={ 'time' }
448
+ data-form={ form }
449
+ data-validation={ val_validate.ok }
450
+ componentID={ val_status.componentID }
451
+ data-value={ JSON.stringify(
452
+ [ 'dates','months' ].includes( restrict ) ?
453
+ !val_status.dataValue[ 0 ] || !val_status.dataValue[ 1 ] ? null
454
+ : val_status.dataValue
455
+ : ( val_status.dataValue || null )
456
+ ) }
457
+ />
458
+ { amotify.config.device.isTouchDevice ?
459
+ <Buttons.Button.Plain
460
+ className={ className }
461
+ freeCSS={ {
462
+ textAlign: 'left'
463
+ } }
464
+ children={ val_status.formatValue }
465
+ onClick={ ( event ) => {
466
+ let component = useStore.get( val_status.componentID );
467
+ if ( component ) component.openPicker();
468
+ event.stopPropagation();
469
+ } }
470
+ /> : <input
471
+ type={ 'text' }
472
+ inputMode={ 'numeric' }
473
+ data-input-type={ 'time' }
474
+ data-form-name={ form }
475
+ value={ val_status.formatValue }
476
+ className={ className }
477
+ tabIndex={ amotify.config.device.isTouchDevice ? -1 : 0 }
478
+ onKeyDown={ ( event ) => {
479
+ KeyDownEvent( {
480
+ restrict,
481
+ event,
482
+ val_era,
483
+ val_status,set_status,
484
+ val_focus,set_focus
485
+ } );
486
+
487
+ if ( onKeyDown ) onKeyDown( event );
488
+ if ( enableFormSubmit ) SubmitForm( event );
489
+ } }
490
+ onKeyUp={ ( event ) => {
491
+ if ( event.key == 'Tab' ) set_focus( {
492
+ ...val_focus,
493
+ active: true
494
+ } );
495
+ } }
496
+ onClick={ ( event ) => {
497
+ let caretTo = ( event.target as HTMLInputElement ).selectionEnd as number;
498
+ let Index = 0;
499
+
500
+ val_status.ranges.forEach( ( range,index ) => {
501
+ let { from,length,region } = range;
502
+ if ( from <= caretTo && caretTo <= ( from + ( region || length ) ) ) {
503
+ Index = index;
504
+ }
505
+ } );
506
+ set_focus( {
507
+ ...val_focus,
508
+ active: true,
509
+ index: Index
510
+ } );
511
+ event.preventDefault();
512
+ } }
513
+ { ...others }
514
+ /> }
515
+ </BoxWrapper>
516
+ );
517
+ }
518
+
519
+ const KeyDownEvent = ( props: {
520
+ restrict: amotify.fn.Input.Time.RestrictTypes
521
+ event: React.KeyboardEvent<HTMLInputElement>
522
+ val_era: amotify.fn.Input.Time.EraTypes
523
+ val_status: amotify.fn.Input.Status.Time
524
+ set_status: React.Dispatch<React.SetStateAction<amotify.fn.Input.Status.Time>>
525
+ val_focus: FocusProps
526
+ set_focus: React.Dispatch<React.SetStateAction<FocusProps>>
527
+ } ) => {
528
+ let {
529
+ val_era,
530
+ restrict,
531
+ event,
532
+ val_status,set_status,
533
+ val_focus,set_focus
534
+ } = props;
535
+
536
+ let { key,shiftKey,ctrlKey,metaKey } = event;
537
+ let auxKey = ctrlKey || metaKey;
538
+ let {
539
+ selectionStart: caretFrom,
540
+ selectionEnd: caretTo
541
+ } = event.target as HTMLInputElement;
542
+
543
+ let {
544
+ index: currentFocusIndex,
545
+ prevIndex: prevFocusIndex
546
+ } = val_focus;
547
+ let {
548
+ ranges,
549
+ formatValue
550
+ } = val_status;
551
+ let maxFocusIndex = ranges.length - 1;
552
+
553
+ if ( [ 'Tab','ArrowLeft','ArrowRight' ].includes( key ) ) {
554
+ let nextFocusIndex = 0;
555
+ if ( key == 'Tab' ) {
556
+ let direction = Number( !shiftKey ) * 2 - 1;
557
+ nextFocusIndex = val_focus.index + direction;
558
+ if ( nextFocusIndex < 0 || nextFocusIndex > maxFocusIndex ) return;
559
+ } else {
560
+ let direction = key == 'ArrowLeft' ? -1 : key == 'ArrowRight' ? 1 : 0;
561
+
562
+ if ( auxKey ) {
563
+ nextFocusIndex = direction == 1 ? maxFocusIndex : 0;
564
+ } else {
565
+ if ( caretFrom == 0 && caretTo == String( val_status.formatValue ).length ) {
566
+ nextFocusIndex = direction == 1 ? maxFocusIndex : 0;
567
+ } else {
568
+ nextFocusIndex = Math.max( 0,Math.min( currentFocusIndex + direction,maxFocusIndex ) );
569
+ }
570
+ }
571
+ }
572
+ set_focus( {
573
+ ...val_focus,
574
+ index: nextFocusIndex,
575
+ prevIndex: currentFocusIndex
576
+ } );
577
+ event.preventDefault();
578
+ }
579
+
580
+ if ( [ 'Backspace','ArrowUp','ArrowDown','0','1','2','3','4','5','6','7','8','9' ].includes( key ) ) {
581
+ event.preventDefault();
582
+
583
+ let nextFocusIndex = currentFocusIndex;
584
+ nextFocusIndex = Math.max( nextFocusIndex,0 );
585
+ nextFocusIndex = Math.min( nextFocusIndex,maxFocusIndex );
586
+ let {
587
+ type,
588
+ from,
589
+ length
590
+ } = ranges[ nextFocusIndex ];
591
+
592
+ let prevValue: any = formatValue.slice( from,( from + length ) );
593
+ let partsValue: any;
594
+
595
+ if ( key == 'Backspace' ) {
596
+ partsValue = '------'.slice( 0,length );
597
+ } else if ( [ 'ArrowUp','ArrowDown' ].includes( key ) ) {
598
+ let direction = key == 'ArrowUp' ? 1 : -1;
599
+
600
+ prevValue = prevValue | 0;
601
+ partsValue = prevValue + direction;
602
+
603
+ let [ min,max,range ] =
604
+ type == 'dateWareki' ?
605
+ val_era == 'year' ? [ 0,2999,4 ]
606
+ : val_era == 'reiwa' ? [ 1,2999,4 ]
607
+ : val_era == 'heisei' ? [ 1,31,4 ]
608
+ : val_era == 'shouwa' ? [ 1,64,4 ]
609
+ : val_era == 'taisho' ? [ 1,15,4 ]
610
+ : val_era == 'meiji' ? [ 1,45,4 ] : [ 0,0,0 ]
611
+ : type == 'minute' ? [ 0,59,2 ]
612
+ : type == 'hour' ? [ 0,23,2 ]
613
+ : type == 'date' ? [ 1,31,2 ]
614
+ : type == 'week' ? [ 1,53,2 ]
615
+ : type == 'month' ? [ 1,12,2 ]
616
+ : type == 'year' ? [ 0,2999,4 ] : [ 0,0,0 ];
617
+
618
+ if ( partsValue > max ) partsValue = min;
619
+ else if ( partsValue < min ) partsValue = max;
620
+ partsValue = ( Number( partsValue ) ).zeroEmbed( range );
621
+ } else if ( [ '0','1','2','3','4','5','6','7','8','9' ].includes( key ) ) {
622
+ let prev = prevValue | 0;
623
+ let add = key;
624
+ let compound: any = `${ prev }${ add }`;
625
+
626
+ if ( prevFocusIndex != currentFocusIndex && prevFocusIndex >= 0 ) {
627
+ prev = 0,compound = '0' + add;
628
+ }
629
+
630
+ if ( type == 'year' || ( type == 'dateWareki' && val_era == 'year' ) ) {
631
+ if ( Number( compound ) > 10000 ) partsValue = add;
632
+ else partsValue = compound;
633
+
634
+ if ( ( partsValue | 0 ) > 1000 ) nextFocusIndex++;
635
+ } else if (
636
+ [ 'hour','minute','date','week','month' ].includes( type ) ||
637
+ ( type == 'dateWareki' && val_era != 'year' )
638
+ ) {
639
+ let base =
640
+ type == 'dateWareki' ?
641
+ val_era == 'reiwa' ? 100
642
+ : val_era == 'heisei' ? 31
643
+ : val_era == 'shouwa' ? 64
644
+ : val_era == 'taisho' ? 15
645
+ : val_era == 'meiji' ? 45 : 0
646
+ : type == 'minute' ? 59
647
+ : type == 'hour' ? 23
648
+ : type == 'date' ? 31
649
+ : type == 'week' ? 53
650
+ : type == 'month' ? 12 : 0;
651
+
652
+ partsValue = ( compound | 0 ) > base ? add : compound;
653
+
654
+ if ( Number( add ) > Number( String( base )[ 0 ] ) ||
655
+ (
656
+ prevValue == '0000'.slice( 0,String( base ).length ) && (
657
+ compound != '0000'.slice( 0,String( base ).length ) ||
658
+ ( [ 'minute','hour' ].includes( type ) && prevFocusIndex == currentFocusIndex )
659
+ )
660
+ ) || ( compound | 0 ) >= ( 10 ** ( String( base ).length - 1 ) )
661
+ ) nextFocusIndex++;
662
+ }
663
+
664
+ if ( type == 'year' || type == 'dateWareki' ) partsValue = ( partsValue | 0 ).zeroEmbed( 4 );
665
+ else partsValue = ( partsValue | 0 ).zeroEmbed( 2 );
666
+ }
667
+
668
+ {
669
+ let nextFormatValue = String( formatValue ).partReplace( from,String( partsValue ) );
670
+ let nextDataValue = nextFormatValue.split( PeriodMargin ).map( ( value ) => {
671
+ return value.replace( /(^\D|\D$)/,'' ).split( /\D+/ ).join( restrict == 'clock' ? ':' : '/' );
672
+ } );
673
+ if ( restrict == 'dateWareki' ) {
674
+ let v = nextDataValue[ 0 ].split( /\D/ );
675
+ let [ year,month,day ] = v;
676
+ if ( v.length == 3 && year ) {
677
+ let yearYear: any = Number( year ) - 1 + Number(
678
+ {
679
+ year: 1,reiwa: 2019,heisei: 1989,shouwa: 1926,taisho: 1912,meiji: 1868
680
+ }[ val_era as string ]
681
+ );
682
+ nextDataValue = [ [ yearYear,month,day ].join( '/' ) ];
683
+ }
684
+ }
685
+
686
+ nextFocusIndex = Math.max( nextFocusIndex,0 );
687
+ nextFocusIndex = Math.min( nextFocusIndex,maxFocusIndex );
688
+
689
+ set_status( {
690
+ ...val_status,
691
+ dataValue: [ 'dates','months' ].includes( restrict ) ? nextDataValue : nextDataValue[ 0 ],
692
+ formatValue: nextFormatValue,
693
+ eventType: 'update',
694
+ eventID: $.uuidGen(),
695
+ } );
696
+ set_focus( {
697
+ ...val_focus,
698
+ index: nextFocusIndex,
699
+ prevIndex: val_focus.index
700
+ } );
701
+ }
702
+ }
703
+ }
704
+
705
+
706
+ export const TimeFNs: amotify.fn.Input.Time.FNTypes = {
707
+ picker: {
708
+ launch: ( params ) => {
709
+ let tipsID = params.tipsID || $.uuidGen();
710
+ Tooltips.open( {
711
+ gravityPoint: params.gravityPoint || 24,
712
+ padding: [ 1,0 ],
713
+ tipsID,
714
+ ...params,
715
+ closeOption: {
716
+ aroundClick: true,
717
+ elementBlur: false,
718
+ ...params.closeOption
719
+ },
720
+ content: <Picker
721
+ restrict={ params.restrict }
722
+ min={ params.min }
723
+ max={ params.max }
724
+ defaultValue={ params.defaultValue }
725
+ tipsID={ tipsID }
726
+ onValueUpdate={ ( value ) => {
727
+ params.onValueUpdate( value );
728
+ } }
729
+ />
730
+ } )
731
+ },
732
+ remove: ( tipsID ) => {
733
+ Tooltips.close( tipsID );
734
+ }
735
+ }
736
+ }