react-input-material 0.0.376 → 0.0.379

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.
@@ -19,9 +19,8 @@
19
19
  // region imports
20
20
  import {Ace as CodeEditorNamespace} from 'ace-builds'
21
21
  import Tools, {optionalRequire} from 'clientnode'
22
- import {EvaluationResult} from 'clientnode/type'
22
+ import {EvaluationResult, Mapping} from 'clientnode/type'
23
23
  import {
24
- ComponentType,
25
24
  FocusEvent as ReactFocusEvent,
26
25
  forwardRef,
27
26
  ForwardedRef,
@@ -39,8 +38,11 @@ import {
39
38
  } from 'react'
40
39
  import CodeEditorType, {IAceEditorProps as CodeEditorProps} from 'react-ace'
41
40
  import {TransitionProps} from 'react-transition-group/Transition'
41
+ import UseAnimationsType from 'react-useanimations'
42
+ import LockAnimation from 'react-useanimations/lib/lock'
43
+ import PlusToXAnimation from 'react-useanimations/lib/plusToX'
42
44
  import {
43
- Editor as RichTextEditor, RawEditorSettings as RawTinyMCEEditorSettings
45
+ Editor as RichTextEditor, RawEditorSettings as RawTinyMCEEditorOptions
44
46
  } from 'tinymce'
45
47
  import {MDCMenuFoundation} from '@material/menu'
46
48
  import {MDCSelectFoundation} from '@material/select'
@@ -78,7 +80,7 @@ import {
78
80
  genericInputSuggestionsPendingClassName
79
81
  } from './GenericInput.module'
80
82
  */
81
- import styles from './GenericInput.module'
83
+ import cssClassNames from './GenericInput.module'
82
84
  import WrapConfigurations from './WrapConfigurations'
83
85
  import WrapTooltip from './WrapTooltip'
84
86
  import {
@@ -126,30 +128,33 @@ import {
126
128
  declare const TARGET_TECHNOLOGY:string
127
129
  const isBrowser =
128
130
  !(TARGET_TECHNOLOGY === 'node' || typeof window === undefined)
129
- const UseAnimations:any|null =
131
+ const UseAnimations:null|typeof Dummy|typeof UseAnimationsType =
130
132
  isBrowser ? optionalRequire('react-useanimations') : null
131
- const lock:any|null = isBrowser ?
133
+ const lockAnimation:null|typeof LockAnimation = isBrowser ?
132
134
  optionalRequire('react-useanimations/lib/lock') :
133
135
  null
134
- const plusToX:any|null = isBrowser ?
136
+ const plusToXAnimation:null|typeof PlusToXAnimation = isBrowser ?
135
137
  optionalRequire('react-useanimations/lib/plusToX') :
136
138
  null
137
139
  // endregion
140
+ const CSS_CLASS_NAMES:Mapping = cssClassNames as Mapping
138
141
  // region code editor configuration
139
142
  export const ACEEditorOptions = {
140
143
  basePath: '/node_modules/ace-builds/src-noconflict/',
141
144
  useWorker: false
142
145
  }
143
- const CodeEditor = lazy(async ():Promise<{default:ComponentType<any>}> => {
144
- const {config} = await import('ace-builds')
145
- for (const [name, value] of Object.entries(ACEEditorOptions))
146
- config.set(name, value)
146
+ const CodeEditor = lazy<typeof CodeEditorType>(
147
+ async ():Promise<{default:typeof CodeEditorType}> => {
148
+ const {config} = await import('ace-builds')
149
+ for (const [name, value] of Object.entries(ACEEditorOptions))
150
+ config.set(name, value)
147
151
 
148
- return await import('react-ace')
149
- })
152
+ return await import('react-ace')
153
+ }
154
+ )
150
155
  // endregion
151
156
  // region rich text editor configuration
152
- export type TinyMCEOptions = RawTinyMCEEditorSettings & {
157
+ export interface TinyMCEOptions extends RawTinyMCEEditorOptions {
153
158
  selector?:undefined
154
159
  target?:undefined
155
160
  }
@@ -315,6 +320,7 @@ export function suggestionMatches(
315
320
  return false
316
321
  }
317
322
  // endregion
323
+ /* eslint-disable jsdoc/require-description-complete-sentence */
318
324
  /**
319
325
  * Generic input wrapper component which automatically determines a useful
320
326
  * input field depending on given model specification.
@@ -342,6 +348,7 @@ export function suggestionMatches(
342
348
  export const GenericInputInner = function<Type = unknown>(
343
349
  props:Props<Type>, reference?:ForwardedRef<Adapter<Type>>
344
350
  ):ReactElement {
351
+ /* eslint-enable jsdoc/require-description-complete-sentence */
345
352
  // region live-cycle
346
353
  /**
347
354
  * Is triggered immediate after a re-rendering. Re-stores cursor selection
@@ -358,7 +365,9 @@ export const GenericInputInner = function<Type = unknown>(
358
365
  "editorState.selectionIsUnstable" is set to "true".
359
366
  */
360
367
  if (codeEditorReference.current?.editor?.selection) {
361
- codeEditorReference.current.editor.textInput.focus()
368
+ (codeEditorReference.current.editor.textInput as
369
+ HTMLInputElement
370
+ ).focus()
362
371
  setCodeEditorSelectionState(codeEditorReference.current)
363
372
 
364
373
  if (editorState.selectionIsUnstable)
@@ -410,11 +419,14 @@ export const GenericInputInner = function<Type = unknown>(
410
419
  in={!Tools.equals(properties.value, properties.default)}
411
420
  >
412
421
  {(
413
- UseAnimations === null ||
414
- (UseAnimations as typeof Dummy).isDummy
422
+ UseAnimations &&
423
+ !(UseAnimations as typeof Dummy).isDummy &&
424
+ plusToXAnimation
415
425
  ) ?
416
- <IconButton icon="clear"/> :
417
- <UseAnimations animation={plusToX} reverse={true}/>
426
+ <UseAnimations
427
+ animation={plusToXAnimation} reverse={true}
428
+ /> :
429
+ <IconButton icon="clear"/>
418
430
  }
419
431
  </GenericAnimate>,
420
432
  onClick: (event:ReactMouseEvent):void => {
@@ -434,14 +446,16 @@ export const GenericInputInner = function<Type = unknown>(
434
446
  return useMemorizedValue(
435
447
  {
436
448
  icon: (
437
- UseAnimations === null ||
438
- (UseAnimations as typeof Dummy).isDummy
449
+ UseAnimations &&
450
+ !(UseAnimations as typeof Dummy).isDummy &&
451
+ lockAnimation
439
452
  ) ?
453
+ <UseAnimations
454
+ animation={lockAnimation}
455
+ reverse={!properties.hidden}
456
+ /> :
440
457
  <IconButton
441
458
  icon={properties.hidden ? 'lock_open' : 'lock'}
442
- /> :
443
- <UseAnimations
444
- animation={lock} reverse={!properties.hidden}
445
459
  />,
446
460
  onClick: (event:ReactMouseEvent):void => {
447
461
  event.preventDefault()
@@ -450,6 +464,7 @@ export const GenericInputInner = function<Type = unknown>(
450
464
  if (value === undefined)
451
465
  value = properties.hidden
452
466
  properties.hidden = !value
467
+
453
468
  onChange(event)
454
469
 
455
470
  return properties.hidden
@@ -556,7 +571,7 @@ export const GenericInputInner = function<Type = unknown>(
556
571
  *
557
572
  * @returns Evaluated template or an empty string if something goes wrong.
558
573
  */
559
- const renderMessage = (template?:any):string => {
574
+ const renderMessage = (template?:unknown):string => {
560
575
  if (typeof template === 'string') {
561
576
  const evaluated:EvaluationResult = Tools.stringEvaluate(
562
577
  `\`${template}\``,
@@ -566,15 +581,19 @@ export const GenericInputInner = function<Type = unknown>(
566
581
  ...properties
567
582
  }
568
583
  )
584
+
569
585
  if (evaluated.error) {
570
586
  console.warn(
571
587
  'Given message template could not be proceed:',
572
588
  evaluated.error
573
589
  )
590
+
574
591
  return ''
575
592
  }
593
+
576
594
  return evaluated.result
577
595
  }
596
+
578
597
  return ''
579
598
  }
580
599
  /**
@@ -1015,7 +1034,9 @@ export const GenericInputInner = function<Type = unknown>(
1015
1034
  properties.editorIsActive &&
1016
1035
  editorState.selectionIsUnstable
1017
1036
  ) {
1018
- codeEditorReference.current.editor.textInput.focus()
1037
+ (codeEditorReference.current.editor.textInput as
1038
+ HTMLInputElement
1039
+ ).focus()
1019
1040
  setCodeEditorSelectionState(codeEditorReference.current)
1020
1041
  setEditorState({...editorState, selectionIsUnstable: false})
1021
1042
  }
@@ -1234,13 +1255,13 @@ export const GenericInputInner = function<Type = unknown>(
1234
1255
 
1235
1256
  let event:GenericEvent|undefined
1236
1257
  if (eventOrValue !== null && typeof eventOrValue === 'object') {
1237
- const target:any =
1238
- (eventOrValue as GenericEvent).target ||
1239
- (eventOrValue as GenericEvent).detail
1258
+ const target:HTMLInputElement|null|undefined =
1259
+ (eventOrValue as GenericEvent).target as HTMLInputElement ||
1260
+ (eventOrValue as GenericEvent).detail as HTMLInputElement
1240
1261
  if (target)
1241
1262
  properties.value = typeof target.value === 'undefined' ?
1242
1263
  null :
1243
- target.value
1264
+ target.value as unknown as Type
1244
1265
  else
1245
1266
  properties.value = eventOrValue as null|Type
1246
1267
  } else
@@ -1340,14 +1361,11 @@ export const GenericInputInner = function<Type = unknown>(
1340
1361
  currentSuggestionLabels[selectedIndex] :
1341
1362
  typeof properties.value === 'string' ?
1342
1363
  properties.value :
1343
- formatValue<Type>(
1344
- properties, properties.value as null|Type, transformer
1345
- )
1364
+ formatValue<Type>(properties, properties.value, transformer)
1346
1365
 
1347
1366
  if (!useSuggestions) {
1348
- properties.value = parseValue<Type>(
1349
- properties, properties.value as null|Type, transformer
1350
- )
1367
+ properties.value =
1368
+ parseValue<Type>(properties, properties.value, transformer)
1351
1369
 
1352
1370
  setHelper()
1353
1371
  } else if (properties.suggestionCreator) {
@@ -1905,9 +1923,9 @@ export const GenericInputInner = function<Type = unknown>(
1905
1923
  if (result) {
1906
1924
  currentRenderableSuggestions.push(
1907
1925
  <MenuItem
1908
- className={
1909
- styles['generic-input__suggestions__suggestion']
1910
- }
1926
+ className={CSS_CLASS_NAMES[
1927
+ 'generic-input__suggestions__suggestion'
1928
+ ]}
1911
1929
  key={index}
1912
1930
  >
1913
1931
  {result}
@@ -1923,9 +1941,9 @@ export const GenericInputInner = function<Type = unknown>(
1923
1941
  ) {
1924
1942
  currentRenderableSuggestions.push(
1925
1943
  <MenuItem
1926
- className={
1927
- styles['generic-input__suggestions__suggestion']
1928
- }
1944
+ className={CSS_CLASS_NAMES[
1945
+ 'generic-input__suggestions__suggestion'
1946
+ ]}
1929
1947
  dangerouslySetInnerHTML={{
1930
1948
  __html: Tools.stringMark(
1931
1949
  suggestion,
@@ -1933,10 +1951,10 @@ export const GenericInputInner = function<Type = unknown>(
1933
1951
  (value:unknown):string =>
1934
1952
  `${value as string}`.toLowerCase(),
1935
1953
  '<span class="' +
1936
- (styles[
1954
+ CSS_CLASS_NAMES[
1937
1955
  'generic-input__suggestions__suggestion' +
1938
1956
  '__mark'
1939
- ] as string) +
1957
+ ] +
1940
1958
  '">{1}</span>'
1941
1959
  ) as string
1942
1960
  }}
@@ -1961,9 +1979,11 @@ export const GenericInputInner = function<Type = unknown>(
1961
1979
  tooltip={properties.tooltip}
1962
1980
  >
1963
1981
  <div
1964
- className={[styles['generic-input']]
1982
+ className={[CSS_CLASS_NAMES['generic-input']]
1965
1983
  .concat(
1966
- isAdvancedEditor ? styles['generic-input--custom'] : [],
1984
+ isAdvancedEditor ?
1985
+ CSS_CLASS_NAMES['generic-input--custom'] :
1986
+ [],
1967
1987
  properties.className ?? []
1968
1988
  )
1969
1989
  .join(' ')
@@ -2010,7 +2030,9 @@ export const GenericInputInner = function<Type = unknown>(
2010
2030
  >
2011
2031
  <label>
2012
2032
  <span className={
2013
- [styles['generic-input__editor__label']]
2033
+ [CSS_CLASS_NAMES[
2034
+ 'generic-input__editor__label'
2035
+ ]]
2014
2036
  .concat(
2015
2037
  'mdc-floating-label',
2016
2038
  'mdc-floating-label--float-above'
@@ -2057,7 +2079,13 @@ export const GenericInputInner = function<Type = unknown>(
2057
2079
  'javascript'
2058
2080
  }
2059
2081
  name={properties.name}
2060
- onChange={onChangeValue}
2082
+ onChange={onChangeValue as
2083
+ unknown as
2084
+ (
2085
+ _value:string,
2086
+ _event?:unknown
2087
+ ) => void
2088
+ }
2061
2089
  onCursorChange={onSelectionChange}
2062
2090
  onSelectionChange={
2063
2091
  onSelectionChange
@@ -2142,18 +2170,14 @@ export const GenericInputInner = function<Type = unknown>(
2142
2170
  <MenuSurface
2143
2171
  anchorCorner="bottomLeft"
2144
2172
  className={
2145
- (
2146
- styles[
2147
- 'generic-input__suggestions'
2148
- ] as string
2149
- ) +
2173
+ CSS_CLASS_NAMES[
2174
+ 'generic-input__suggestions'
2175
+ ] +
2150
2176
  ' ' +
2151
- (
2152
- styles[
2153
- 'generic-input__suggestions' +
2154
- '--pending'
2155
- ] as string
2156
- )
2177
+ CSS_CLASS_NAMES[
2178
+ 'generic-input__suggestions' +
2179
+ '--pending'
2180
+ ]
2157
2181
  }
2158
2182
  open={true}
2159
2183
  >
@@ -2165,9 +2189,9 @@ export const GenericInputInner = function<Type = unknown>(
2165
2189
  suggestionMenuAPIReference.current =
2166
2190
  instance
2167
2191
  }}
2168
- className={
2169
- styles['generic-input__suggestions']
2170
- }
2192
+ className={CSS_CLASS_NAMES[
2193
+ 'generic-input__suggestions'
2194
+ ]}
2171
2195
  focusOnOpen={false}
2172
2196
  foundationRef={
2173
2197
  suggestionMenuFoundationReference
@@ -11,7 +11,7 @@ import { InputProps, InputsAdapter as Adapter, InputsComponent, InputsProperties
11
11
  * @returns React elements.
12
12
  */
13
13
  export declare const InputsInner: {
14
- <T = unknown, P extends InputsPropertiesItem<T> = InputProps<T>, State = Mapping<unknown>>(props: InputsProps<T, P>, reference?: ForwardedRef<Adapter<T, P>> | undefined): ReactElement;
14
+ <T = unknown, P extends InputsPropertiesItem<T, unknown> = InputProps<T>, State = Mapping<unknown>>(props: InputsProps<T, P>, reference?: ForwardedRef<Adapter<T, P>> | undefined): ReactElement;
15
15
  displayName: string;
16
16
  };
17
17
  /**