@wordpress/components 27.2.0 → 27.3.0

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 (117) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +13 -0
  3. package/build/button/index.js +1 -1
  4. package/build/button/index.js.map +1 -1
  5. package/build/color-picker/component.js +2 -12
  6. package/build/color-picker/component.js.map +1 -1
  7. package/build/color-picker/picker.js +18 -77
  8. package/build/color-picker/picker.js.map +1 -1
  9. package/build/color-picker/types.js.map +1 -1
  10. package/build/custom-select-control-v2/default-component/index.js +4 -2
  11. package/build/custom-select-control-v2/default-component/index.js.map +1 -1
  12. package/build/custom-select-control-v2/index.js +1 -8
  13. package/build/custom-select-control-v2/index.js.map +1 -1
  14. package/build/custom-select-control-v2/{custom-select-item.js → item.js} +2 -1
  15. package/build/custom-select-control-v2/{custom-select-item.js.map → item.js.map} +1 -1
  16. package/build/custom-select-control-v2/legacy-component/index.js +5 -5
  17. package/build/custom-select-control-v2/legacy-component/index.js.map +1 -1
  18. package/build/input-control/input-field.js +2 -1
  19. package/build/input-control/input-field.js.map +1 -1
  20. package/build/mobile/color-settings/palette.screen.native.js +1 -0
  21. package/build/mobile/color-settings/palette.screen.native.js.map +1 -1
  22. package/build/navigable-container/container.js.map +1 -1
  23. package/build/navigator/navigator-provider/component.js +162 -120
  24. package/build/navigator/navigator-provider/component.js.map +1 -1
  25. package/build/navigator/navigator-screen/component.js +2 -2
  26. package/build/navigator/navigator-screen/component.js.map +1 -1
  27. package/build/popover/index.js +7 -34
  28. package/build/popover/index.js.map +1 -1
  29. package/build/range-control/styles/range-control-styles.js +29 -29
  30. package/build/range-control/styles/range-control-styles.js.map +1 -1
  31. package/build/toggle-group-control/toggle-group-control-option-base/component.js +1 -1
  32. package/build/toggle-group-control/toggle-group-control-option-base/component.js.map +1 -1
  33. package/build-module/button/index.js +1 -1
  34. package/build-module/button/index.js.map +1 -1
  35. package/build-module/color-picker/component.js +3 -13
  36. package/build-module/color-picker/component.js.map +1 -1
  37. package/build-module/color-picker/picker.js +19 -78
  38. package/build-module/color-picker/picker.js.map +1 -1
  39. package/build-module/color-picker/types.js.map +1 -1
  40. package/build-module/custom-select-control-v2/default-component/index.js +4 -2
  41. package/build-module/custom-select-control-v2/default-component/index.js.map +1 -1
  42. package/build-module/custom-select-control-v2/index.js +1 -2
  43. package/build-module/custom-select-control-v2/index.js.map +1 -1
  44. package/build-module/custom-select-control-v2/{custom-select-item.js → item.js} +2 -1
  45. package/build-module/custom-select-control-v2/{custom-select-item.js.map → item.js.map} +1 -1
  46. package/build-module/custom-select-control-v2/legacy-component/index.js +4 -4
  47. package/build-module/custom-select-control-v2/legacy-component/index.js.map +1 -1
  48. package/build-module/input-control/input-field.js +2 -1
  49. package/build-module/input-control/input-field.js.map +1 -1
  50. package/build-module/mobile/color-settings/palette.screen.native.js +1 -0
  51. package/build-module/mobile/color-settings/palette.screen.native.js.map +1 -1
  52. package/build-module/navigable-container/container.js.map +1 -1
  53. package/build-module/navigator/navigator-provider/component.js +163 -121
  54. package/build-module/navigator/navigator-provider/component.js.map +1 -1
  55. package/build-module/navigator/navigator-screen/component.js +2 -2
  56. package/build-module/navigator/navigator-screen/component.js.map +1 -1
  57. package/build-module/popover/index.js +9 -36
  58. package/build-module/popover/index.js.map +1 -1
  59. package/build-module/range-control/styles/range-control-styles.js +29 -29
  60. package/build-module/range-control/styles/range-control-styles.js.map +1 -1
  61. package/build-module/toggle-group-control/toggle-group-control-option-base/component.js +2 -2
  62. package/build-module/toggle-group-control/toggle-group-control-option-base/component.js.map +1 -1
  63. package/build-style/style-rtl.css +2 -8
  64. package/build-style/style.css +2 -8
  65. package/build-types/color-picker/component.d.ts.map +1 -1
  66. package/build-types/color-picker/picker.d.ts +1 -1
  67. package/build-types/color-picker/picker.d.ts.map +1 -1
  68. package/build-types/color-picker/types.d.ts +0 -3
  69. package/build-types/color-picker/types.d.ts.map +1 -1
  70. package/build-types/custom-select-control/stories/index.story.d.ts +35 -0
  71. package/build-types/custom-select-control/stories/index.story.d.ts.map +1 -0
  72. package/build-types/custom-select-control-v2/default-component/index.d.ts +5 -2
  73. package/build-types/custom-select-control-v2/default-component/index.d.ts.map +1 -1
  74. package/build-types/custom-select-control-v2/index.d.ts +1 -2
  75. package/build-types/custom-select-control-v2/index.d.ts.map +1 -1
  76. package/build-types/custom-select-control-v2/{custom-select-item.d.ts → item.d.ts} +4 -1
  77. package/build-types/custom-select-control-v2/item.d.ts.map +1 -0
  78. package/build-types/custom-select-control-v2/legacy-component/index.d.ts +2 -2
  79. package/build-types/custom-select-control-v2/legacy-component/index.d.ts.map +1 -1
  80. package/build-types/custom-select-control-v2/stories/default.story.d.ts +2 -2
  81. package/build-types/custom-select-control-v2/stories/default.story.d.ts.map +1 -1
  82. package/build-types/custom-select-control-v2/stories/legacy.story.d.ts +4 -2
  83. package/build-types/custom-select-control-v2/stories/legacy.story.d.ts.map +1 -1
  84. package/build-types/input-control/input-field.d.ts.map +1 -1
  85. package/build-types/navigator/navigator-provider/component.d.ts.map +1 -1
  86. package/build-types/navigator/navigator-screen/component.d.ts.map +1 -1
  87. package/build-types/popover/index.d.ts.map +1 -1
  88. package/package.json +21 -21
  89. package/src/button/index.tsx +1 -1
  90. package/src/color-picker/component.tsx +3 -25
  91. package/src/color-picker/picker.tsx +12 -96
  92. package/src/color-picker/types.ts +0 -3
  93. package/src/custom-select-control/stories/{index.story.js → index.story.tsx} +8 -3
  94. package/src/custom-select-control/test/index.js +24 -0
  95. package/src/custom-select-control-v2/README.md +27 -27
  96. package/src/custom-select-control-v2/default-component/index.tsx +5 -2
  97. package/src/custom-select-control-v2/index.tsx +1 -2
  98. package/src/custom-select-control-v2/{custom-select-item.tsx → item.tsx} +2 -0
  99. package/src/custom-select-control-v2/legacy-component/index.tsx +4 -6
  100. package/src/custom-select-control-v2/legacy-component/test/index.tsx +13 -10
  101. package/src/custom-select-control-v2/stories/default.story.tsx +16 -17
  102. package/src/custom-select-control-v2/stories/legacy.story.tsx +20 -35
  103. package/src/custom-select-control-v2/test/index.tsx +26 -16
  104. package/src/dropdown/style.scss +3 -3
  105. package/src/input-control/input-field.tsx +2 -1
  106. package/src/mobile/color-settings/palette.screen.native.js +5 -1
  107. package/src/navigable-container/container.tsx +1 -1
  108. package/src/navigator/navigator-provider/component.tsx +187 -188
  109. package/src/navigator/navigator-screen/component.tsx +2 -4
  110. package/src/popover/index.tsx +59 -99
  111. package/src/popover/style.scss +0 -9
  112. package/src/range-control/styles/range-control-styles.ts +1 -1
  113. package/src/text-control/style.scss +2 -0
  114. package/src/toggle-group-control/toggle-group-control-option-base/component.tsx +2 -2
  115. package/src/toolbar/toolbar/style.scss +1 -1
  116. package/tsconfig.tsbuildinfo +1 -1
  117. package/build-types/custom-select-control-v2/custom-select-item.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"names":["_react2","require","_element","_utils","_inputControlStyles","_reducer","noop","InputField","disabled","dragDirection","dragThreshold","id","isDragEnabled","isFocused","isPressEnterToChange","onBlur","onChange","onDrag","onDragEnd","onDragStart","onFocus","onKeyDown","onValidate","size","setIsFocused","stateReducer","state","value","valueProp","type","props","ref","change","commit","drag","dragEnd","dragStart","invalidate","pressDown","pressEnter","pressUp","reset","useInputControlStateReducer","isDragging","isDirty","wasDirtyOnBlur","useRef","dragCursor","useDragCursor","handleOnBlur","event","target","validity","valid","current","handleOnCommit","handleOnFocus","handleOnChange","nextValue","currentTarget","err","handleOnKeyDown","key","preventDefault","dragGestureProps","useDrag","dragProps","distance","dragging","stopPropagation","axis","threshold","enabled","pointer","capture","handleOnMouseDown","onMouseDown","ownerDocument","activeElement","focus","_react","createElement","Input","className","inputSize","ForwardedComponent","forwardRef","_default","exports","default"],"sources":["@wordpress/components/src/input-control/input-field.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport { useDrag } from '@use-gesture/react';\nimport type {\n\tSyntheticEvent,\n\tChangeEvent,\n\tKeyboardEvent,\n\tPointerEvent,\n\tFocusEvent,\n\tForwardedRef,\n\tMouseEvent,\n} from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { forwardRef, useRef } from '@wordpress/element';\n/**\n * Internal dependencies\n */\nimport type { WordPressComponentProps } from '../context';\nimport { useDragCursor } from './utils';\nimport { Input } from './styles/input-control-styles';\nimport { useInputControlStateReducer } from './reducer/reducer';\nimport type { InputFieldProps } from './types';\n\nconst noop = () => {};\n\nfunction InputField(\n\t{\n\t\tdisabled = false,\n\t\tdragDirection = 'n',\n\t\tdragThreshold = 10,\n\t\tid,\n\t\tisDragEnabled = false,\n\t\tisFocused,\n\t\tisPressEnterToChange = false,\n\t\tonBlur = noop,\n\t\tonChange = noop,\n\t\tonDrag = noop,\n\t\tonDragEnd = noop,\n\t\tonDragStart = noop,\n\t\tonFocus = noop,\n\t\tonKeyDown = noop,\n\t\tonValidate = noop,\n\t\tsize = 'default',\n\t\tsetIsFocused,\n\t\tstateReducer = ( state: any ) => state,\n\t\tvalue: valueProp,\n\t\ttype,\n\t\t...props\n\t}: WordPressComponentProps< InputFieldProps, 'input', false >,\n\tref: ForwardedRef< HTMLInputElement >\n) {\n\tconst {\n\t\t// State.\n\t\tstate,\n\t\t// Actions.\n\t\tchange,\n\t\tcommit,\n\t\tdrag,\n\t\tdragEnd,\n\t\tdragStart,\n\t\tinvalidate,\n\t\tpressDown,\n\t\tpressEnter,\n\t\tpressUp,\n\t\treset,\n\t} = useInputControlStateReducer(\n\t\tstateReducer,\n\t\t{\n\t\t\tisDragEnabled,\n\t\t\tvalue: valueProp,\n\t\t\tisPressEnterToChange,\n\t\t},\n\t\tonChange\n\t);\n\n\tconst { value, isDragging, isDirty } = state;\n\tconst wasDirtyOnBlur = useRef( false );\n\n\tconst dragCursor = useDragCursor( isDragging, dragDirection );\n\n\tconst handleOnBlur = ( event: FocusEvent< HTMLInputElement > ) => {\n\t\tonBlur( event );\n\t\tsetIsFocused?.( false );\n\n\t\t/**\n\t\t * If isPressEnterToChange is set, this commits the value to\n\t\t * the onChange callback.\n\t\t */\n\t\tif ( isDirty || ! event.target.validity.valid ) {\n\t\t\twasDirtyOnBlur.current = true;\n\t\t\thandleOnCommit( event );\n\t\t}\n\t};\n\n\tconst handleOnFocus = ( event: FocusEvent< HTMLInputElement > ) => {\n\t\tonFocus( event );\n\t\tsetIsFocused?.( true );\n\t};\n\n\tconst handleOnChange = ( event: ChangeEvent< HTMLInputElement > ) => {\n\t\tconst nextValue = event.target.value;\n\t\tchange( nextValue, event );\n\t};\n\n\tconst handleOnCommit = ( event: SyntheticEvent< HTMLInputElement > ) => {\n\t\tconst nextValue = event.currentTarget.value;\n\n\t\ttry {\n\t\t\tonValidate( nextValue );\n\t\t\tcommit( nextValue, event );\n\t\t} catch ( err ) {\n\t\t\tinvalidate( err, event );\n\t\t}\n\t};\n\n\tconst handleOnKeyDown = ( event: KeyboardEvent< HTMLInputElement > ) => {\n\t\tconst { key } = event;\n\t\tonKeyDown( event );\n\n\t\tswitch ( key ) {\n\t\t\tcase 'ArrowUp':\n\t\t\t\tpressUp( event );\n\t\t\t\tbreak;\n\n\t\t\tcase 'ArrowDown':\n\t\t\t\tpressDown( event );\n\t\t\t\tbreak;\n\n\t\t\tcase 'Enter':\n\t\t\t\tpressEnter( event );\n\n\t\t\t\tif ( isPressEnterToChange ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\thandleOnCommit( event );\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase 'Escape':\n\t\t\t\tif ( isPressEnterToChange && isDirty ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\treset( valueProp, event );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\tconst dragGestureProps = useDrag< PointerEvent< HTMLInputElement > >(\n\t\t( dragProps ) => {\n\t\t\tconst { distance, dragging, event, target } = dragProps;\n\n\t\t\t// The `target` prop always references the `input` element while, by\n\t\t\t// default, the `dragProps.event.target` property would reference the real\n\t\t\t// event target (i.e. any DOM element that the pointer is hovering while\n\t\t\t// dragging). Ensuring that the `target` is always the `input` element\n\t\t\t// allows consumers of `InputControl` (or any higher-level control) to\n\t\t\t// check the input's validity by accessing `event.target.validity.valid`.\n\t\t\tdragProps.event = {\n\t\t\t\t...dragProps.event,\n\t\t\t\ttarget,\n\t\t\t};\n\n\t\t\tif ( ! distance ) return;\n\t\t\tevent.stopPropagation();\n\n\t\t\t/**\n\t\t\t * Quick return if no longer dragging.\n\t\t\t * This prevents unnecessary value calculations.\n\t\t\t */\n\t\t\tif ( ! dragging ) {\n\t\t\t\tonDragEnd( dragProps );\n\t\t\t\tdragEnd( dragProps );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tonDrag( dragProps );\n\t\t\tdrag( dragProps );\n\n\t\t\tif ( ! isDragging ) {\n\t\t\t\tonDragStart( dragProps );\n\t\t\t\tdragStart( dragProps );\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\taxis: dragDirection === 'e' || dragDirection === 'w' ? 'x' : 'y',\n\t\t\tthreshold: dragThreshold,\n\t\t\tenabled: isDragEnabled,\n\t\t\tpointer: { capture: false },\n\t\t}\n\t);\n\n\tconst dragProps = isDragEnabled ? dragGestureProps() : {};\n\t/*\n\t * Works around the odd UA (e.g. Firefox) that does not focus inputs of\n\t * type=number when their spinner arrows are pressed.\n\t */\n\tlet handleOnMouseDown;\n\tif ( type === 'number' ) {\n\t\thandleOnMouseDown = ( event: MouseEvent< HTMLInputElement > ) => {\n\t\t\tprops.onMouseDown?.( event );\n\t\t\tif (\n\t\t\t\tevent.currentTarget !==\n\t\t\t\tevent.currentTarget.ownerDocument.activeElement\n\t\t\t) {\n\t\t\t\tevent.currentTarget.focus();\n\t\t\t}\n\t\t};\n\t}\n\n\treturn (\n\t\t<Input\n\t\t\t{ ...props }\n\t\t\t{ ...dragProps }\n\t\t\tclassName=\"components-input-control__input\"\n\t\t\tdisabled={ disabled }\n\t\t\tdragCursor={ dragCursor }\n\t\t\tisDragging={ isDragging }\n\t\t\tid={ id }\n\t\t\tonBlur={ handleOnBlur }\n\t\t\tonChange={ handleOnChange }\n\t\t\tonFocus={ handleOnFocus }\n\t\t\tonKeyDown={ handleOnKeyDown }\n\t\t\tonMouseDown={ handleOnMouseDown }\n\t\t\tref={ ref }\n\t\t\tinputSize={ size }\n\t\t\t// Fallback to `''` to avoid \"uncontrolled to controlled\" warning.\n\t\t\t// See https://github.com/WordPress/gutenberg/pull/47250 for details.\n\t\t\tvalue={ value ?? '' }\n\t\t\ttype={ type }\n\t\t/>\n\t);\n}\n\nconst ForwardedComponent = forwardRef( InputField );\n\nexport default ForwardedComponent;\n"],"mappings":";;;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AAcA,IAAAC,QAAA,GAAAD,OAAA;AAKA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAxBA;AACA;AACA;;AAYA;AACA;AACA;;AAWA,MAAMK,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AAErB,SAASC,UAAUA,CAClB;EACCC,QAAQ,GAAG,KAAK;EAChBC,aAAa,GAAG,GAAG;EACnBC,aAAa,GAAG,EAAE;EAClBC,EAAE;EACFC,aAAa,GAAG,KAAK;EACrBC,SAAS;EACTC,oBAAoB,GAAG,KAAK;EAC5BC,MAAM,GAAGT,IAAI;EACbU,QAAQ,GAAGV,IAAI;EACfW,MAAM,GAAGX,IAAI;EACbY,SAAS,GAAGZ,IAAI;EAChBa,WAAW,GAAGb,IAAI;EAClBc,OAAO,GAAGd,IAAI;EACde,SAAS,GAAGf,IAAI;EAChBgB,UAAU,GAAGhB,IAAI;EACjBiB,IAAI,GAAG,SAAS;EAChBC,YAAY;EACZC,YAAY,GAAKC,KAAU,IAAMA,KAAK;EACtCC,KAAK,EAAEC,SAAS;EAChBC,IAAI;EACJ,GAAGC;AACwD,CAAC,EAC7DC,GAAqC,EACpC;EACD,MAAM;IACL;IACAL,KAAK;IAC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AI,EAAI;IACrBE,IAAI,EAAGA;EAAM,CACb,CAAC;AAEJ;AAEA,MAAMwD,kBAAkB,GAAG,IAAAC,mBAAU,EAAE/E,UAAW,CAAC;AAAC,IAAAgF,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAErCJ,kBAAkB"}
1
+ {"version":3,"names":["_react2","require","_element","_utils","_inputControlStyles","_reducer","_withIgnoreImeEvents","noop","InputField","disabled","dragDirection","dragThreshold","id","isDragEnabled","isFocused","isPressEnterToChange","onBlur","onChange","onDrag","onDragEnd","onDragStart","onFocus","onKeyDown","onValidate","size","setIsFocused","stateReducer","state","value","valueProp","type","props","ref","change","commit","drag","dragEnd","dragStart","invalidate","pressDown","pressEnter","pressUp","reset","useInputControlStateReducer","isDragging","isDirty","wasDirtyOnBlur","useRef","dragCursor","useDragCursor","handleOnBlur","event","target","validity","valid","current","handleOnCommit","handleOnFocus","handleOnChange","nextValue","currentTarget","err","handleOnKeyDown","key","preventDefault","dragGestureProps","useDrag","dragProps","distance","dragging","stopPropagation","axis","threshold","enabled","pointer","capture","handleOnMouseDown","onMouseDown","ownerDocument","activeElement","focus","_react","createElement","Input","className","withIgnoreIMEEvents","inputSize","ForwardedComponent","forwardRef","_default","exports","default"],"sources":["@wordpress/components/src/input-control/input-field.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport { useDrag } from '@use-gesture/react';\nimport type {\n\tSyntheticEvent,\n\tChangeEvent,\n\tKeyboardEvent,\n\tPointerEvent,\n\tFocusEvent,\n\tForwardedRef,\n\tMouseEvent,\n} from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { forwardRef, useRef } from '@wordpress/element';\n/**\n * Internal dependencies\n */\nimport type { WordPressComponentProps } from '../context';\nimport { useDragCursor } from './utils';\nimport { Input } from './styles/input-control-styles';\nimport { useInputControlStateReducer } from './reducer/reducer';\nimport type { InputFieldProps } from './types';\nimport { withIgnoreIMEEvents } from '../utils/with-ignore-ime-events';\n\nconst noop = () => {};\n\nfunction InputField(\n\t{\n\t\tdisabled = false,\n\t\tdragDirection = 'n',\n\t\tdragThreshold = 10,\n\t\tid,\n\t\tisDragEnabled = false,\n\t\tisFocused,\n\t\tisPressEnterToChange = false,\n\t\tonBlur = noop,\n\t\tonChange = noop,\n\t\tonDrag = noop,\n\t\tonDragEnd = noop,\n\t\tonDragStart = noop,\n\t\tonFocus = noop,\n\t\tonKeyDown = noop,\n\t\tonValidate = noop,\n\t\tsize = 'default',\n\t\tsetIsFocused,\n\t\tstateReducer = ( state: any ) => state,\n\t\tvalue: valueProp,\n\t\ttype,\n\t\t...props\n\t}: WordPressComponentProps< InputFieldProps, 'input', false >,\n\tref: ForwardedRef< HTMLInputElement >\n) {\n\tconst {\n\t\t// State.\n\t\tstate,\n\t\t// Actions.\n\t\tchange,\n\t\tcommit,\n\t\tdrag,\n\t\tdragEnd,\n\t\tdragStart,\n\t\tinvalidate,\n\t\tpressDown,\n\t\tpressEnter,\n\t\tpressUp,\n\t\treset,\n\t} = useInputControlStateReducer(\n\t\tstateReducer,\n\t\t{\n\t\t\tisDragEnabled,\n\t\t\tvalue: valueProp,\n\t\t\tisPressEnterToChange,\n\t\t},\n\t\tonChange\n\t);\n\n\tconst { value, isDragging, isDirty } = state;\n\tconst wasDirtyOnBlur = useRef( false );\n\n\tconst dragCursor = useDragCursor( isDragging, dragDirection );\n\n\tconst handleOnBlur = ( event: FocusEvent< HTMLInputElement > ) => {\n\t\tonBlur( event );\n\t\tsetIsFocused?.( false );\n\n\t\t/**\n\t\t * If isPressEnterToChange is set, this commits the value to\n\t\t * the onChange callback.\n\t\t */\n\t\tif ( isDirty || ! event.target.validity.valid ) {\n\t\t\twasDirtyOnBlur.current = true;\n\t\t\thandleOnCommit( event );\n\t\t}\n\t};\n\n\tconst handleOnFocus = ( event: FocusEvent< HTMLInputElement > ) => {\n\t\tonFocus( event );\n\t\tsetIsFocused?.( true );\n\t};\n\n\tconst handleOnChange = ( event: ChangeEvent< HTMLInputElement > ) => {\n\t\tconst nextValue = event.target.value;\n\t\tchange( nextValue, event );\n\t};\n\n\tconst handleOnCommit = ( event: SyntheticEvent< HTMLInputElement > ) => {\n\t\tconst nextValue = event.currentTarget.value;\n\n\t\ttry {\n\t\t\tonValidate( nextValue );\n\t\t\tcommit( nextValue, event );\n\t\t} catch ( err ) {\n\t\t\tinvalidate( err, event );\n\t\t}\n\t};\n\n\tconst handleOnKeyDown = ( event: KeyboardEvent< HTMLInputElement > ) => {\n\t\tconst { key } = event;\n\t\tonKeyDown( event );\n\n\t\tswitch ( key ) {\n\t\t\tcase 'ArrowUp':\n\t\t\t\tpressUp( event );\n\t\t\t\tbreak;\n\n\t\t\tcase 'ArrowDown':\n\t\t\t\tpressDown( event );\n\t\t\t\tbreak;\n\n\t\t\tcase 'Enter':\n\t\t\t\tpressEnter( event );\n\n\t\t\t\tif ( isPressEnterToChange ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\thandleOnCommit( event );\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase 'Escape':\n\t\t\t\tif ( isPressEnterToChange && isDirty ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\treset( valueProp, event );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\tconst dragGestureProps = useDrag< PointerEvent< HTMLInputElement > >(\n\t\t( dragProps ) => {\n\t\t\tconst { distance, dragging, event, target } = dragProps;\n\n\t\t\t// The `target` prop always references the `input` element while, by\n\t\t\t// default, the `dragProps.event.target` property would reference the real\n\t\t\t// event target (i.e. any DOM element that the pointer is hovering while\n\t\t\t// dragging). Ensuring that the `target` is always the `input` element\n\t\t\t// allows consumers of `InputControl` (or any higher-level control) to\n\t\t\t// check the input's validity by accessing `event.target.validity.valid`.\n\t\t\tdragProps.event = {\n\t\t\t\t...dragProps.event,\n\t\t\t\ttarget,\n\t\t\t};\n\n\t\t\tif ( ! distance ) return;\n\t\t\tevent.stopPropagation();\n\n\t\t\t/**\n\t\t\t * Quick return if no longer dragging.\n\t\t\t * This prevents unnecessary value calculations.\n\t\t\t */\n\t\t\tif ( ! dragging ) {\n\t\t\t\tonDragEnd( dragProps );\n\t\t\t\tdragEnd( dragProps );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tonDrag( dragProps );\n\t\t\tdrag( dragProps );\n\n\t\t\tif ( ! isDragging ) {\n\t\t\t\tonDragStart( dragProps );\n\t\t\t\tdragStart( dragProps );\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\taxis: dragDirection === 'e' || dragDirection === 'w' ? 'x' : 'y',\n\t\t\tthreshold: dragThreshold,\n\t\t\tenabled: isDragEnabled,\n\t\t\tpointer: { capture: false },\n\t\t}\n\t);\n\n\tconst dragProps = isDragEnabled ? dragGestureProps() : {};\n\t/*\n\t * Works around the odd UA (e.g. Firefox) that does not focus inputs of\n\t * type=number when their spinner arrows are pressed.\n\t */\n\tlet handleOnMouseDown;\n\tif ( type === 'number' ) {\n\t\thandleOnMouseDown = ( event: MouseEvent< HTMLInputElement > ) => {\n\t\t\tprops.onMouseDown?.( event );\n\t\t\tif (\n\t\t\t\tevent.currentTarget !==\n\t\t\t\tevent.currentTarget.ownerDocument.activeElement\n\t\t\t) {\n\t\t\t\tevent.currentTarget.focus();\n\t\t\t}\n\t\t};\n\t}\n\n\treturn (\n\t\t<Input\n\t\t\t{ ...props }\n\t\t\t{ ...dragProps }\n\t\t\tclassName=\"components-input-control__input\"\n\t\t\tdisabled={ disabled }\n\t\t\tdragCursor={ dragCursor }\n\t\t\tisDragging={ isDragging }\n\t\t\tid={ id }\n\t\t\tonBlur={ handleOnBlur }\n\t\t\tonChange={ handleOnChange }\n\t\t\tonFocus={ handleOnFocus }\n\t\t\tonKeyDown={ withIgnoreIMEEvents( handleOnKeyDown ) }\n\t\t\tonMouseDown={ handleOnMouseDown }\n\t\t\tref={ ref }\n\t\t\tinputSize={ size }\n\t\t\t// Fallback to `''` to avoid \"uncontrolled to controlled\" warning.\n\t\t\t// See https://github.com/WordPress/gutenberg/pull/47250 for details.\n\t\t\tvalue={ value ?? '' }\n\t\t\ttype={ type }\n\t\t/>\n\t);\n}\n\nconst ForwardedComponent = forwardRef( InputField );\n\nexport default ForwardedComponent;\n"],"mappings":";;;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AAcA,IAAAC,QAAA,GAAAD,OAAA;AAKA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAEA,IAAAK,oBAAA,GAAAL,OAAA;AA1BA;AACA;AACA;;AAYA;AACA;AACA;;AAYA,MAAMM,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AAErB,SAASC,UAAUA,CAClB;EACCC,QAAQ,GAAG,KAAK;EAChBC,aAAa,GAAG,GAAG;EACnBC,aAAa,GAAG,EAAE;EAClBC,EAAE;EACFC,aAAa,GAAG,KAAK;EACrBC,SAAS;EACTC,oBAAoB,GAAG,KAAK;EAC5BC,MAAM,GAAGT,IAAI;EACbU,QAAQ,GAAGV,IAAI;EACfW,MAAM,GAAGX,IAAI;EACbY,SAAS,GAAGZ,IAAI;EAChBa,WAAW,GAAGb,IAAI;EAClBc,OAAO,GAAGd,IAAI;EACde,SAAS,GAAGf,IAAI;EAChBgB,UAAU,GAAGhB,IAAI;EACjBiB,IAAI,GAAG,SAAS;EAChBC,YAAY;EACZC,YAAY,GAAKC,KAAU,IAAMA,KAAK;EACtCC,KAAK,EAAEC,SAAS;EAChBC,IAAI;EACJ,GAAGC;AACwD,CAAC,EAC7DC,GAAqC,EACpC;EACD,MAAM;IACL;IACAL,KAAK;IACL;IACAM,MAAM;IACNC,MAAM;IACNC,IAAI;IACJC,OAAO;IACPC,SAAS;IACTC,UAAU;IACVC,SAAS;IACTC,UAAU;IACVC,OAAO;IACPC;EACD,CAAC,GAAG,IAAAC,oCAA2B,EAC9BjB,YAAY,EACZ;IACCb,aAAa;IACbe,KAAK,EAAEC,SAAS;IAChBd;EACD,CAA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,7 @@ const PaletteScreen = () => {
102
102
  }
103
103
  function getClearButton() {
104
104
  return (0, _react.createElement)(_reactNative.TouchableWithoutFeedback, {
105
+ accessibilityLabel: (0, _i18n.__)('Clear selected color'),
105
106
  onPress: onClear,
106
107
  hitSlop: HIT_SLOP
107
108
  }, (0, _react.createElement)(_reactNative.View, {
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","_i18n","_element","_compose","_components","_native","_colorPalette","_interopRequireDefault","_colorIndicator","_navBar","_segmentedControl","_utils","_style","HIT_SLOP","top","bottom","left","right","PaletteScreen","route","useRoute","navigation","useNavigation","shouldEnableBottomSheetScroll","useContext","BottomSheetContext","label","onColorChange","onGradientChange","onColorCleared","colorValue","defaultSettings","hideNavigation","params","segments","isGradient","colorsUtils","currentValue","setCurrentValue","useState","isGradientColor","selectedSegmentIndex","currentSegment","setCurrentSegment","isGradientSegment","currentSegmentColors","colors","gradients","allAvailableColors","useMobileGlobalStylesColors","allAvailableGradients","flatMap","filter","Boolean","horizontalSeparatorStyle","usePreferredColorSchemeStyle","styles","horizontalSeparator","horizontalSeparatorDark","clearButtonStyle","clearButton","clearButtonDark","selectedColorTextStyle","colorText","colorTextDark","isSolidSegment","isCustomGadientShown","setColor","color","onClear","undefined","onCustomPress","navigate","screens","picker","gradientPicker","getClearButton","_react","createElement","TouchableWithoutFeedback","onPress","hitSlop","View","style","clearButtonContainer","Text","__","getFooter","default","segmentHandler","selectedIndex","indexOf","addonLeft","colorIndicator","addonRight","footer","flex","maxFontSizeMultiplier","selectable","toUpperCase","selectColorText","BackButton","goBack","Heading","colorPalettes","map","palette","paletteKey","paletteSettings","allColors","allGradients","enableCustomColor","name","key","activeColor","Fragment","PanelBody","ColorControl","withColorIndicator","_default","exports"],"sources":["@wordpress/components/src/mobile/color-settings/palette.screen.native.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { View, Text, TouchableWithoutFeedback } from 'react-native';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState, useContext } from '@wordpress/element';\nimport { usePreferredColorSchemeStyle } from '@wordpress/compose';\nimport {\n\tColorControl,\n\tPanelBody,\n\tBottomSheetContext,\n\tuseMobileGlobalStylesColors,\n} from '@wordpress/components';\nimport { useRoute, useNavigation } from '@react-navigation/native';\n\n/**\n * Internal dependencies\n */\nimport ColorPalette from '../../color-palette';\nimport ColorIndicator from '../../color-indicator';\nimport NavBar from '../bottom-sheet/nav-bar';\nimport SegmentedControls from '../segmented-control';\nimport { colorsUtils } from './utils';\n\nimport styles from './style.scss';\n\nconst HIT_SLOP = { top: 8, bottom: 8, left: 8, right: 8 };\n\nconst PaletteScreen = () => {\n\tconst route = useRoute();\n\tconst navigation = useNavigation();\n\tconst { shouldEnableBottomSheetScroll } = useContext( BottomSheetContext );\n\tconst {\n\t\tlabel,\n\t\tonColorChange,\n\t\tonGradientChange,\n\t\tonColorCleared,\n\t\tcolorValue,\n\t\tdefaultSettings,\n\t\thideNavigation = false,\n\t} = route.params || {};\n\tconst { segments, isGradient } = colorsUtils;\n\tconst [ currentValue, setCurrentValue ] = useState( colorValue );\n\tconst isGradientColor = isGradient( currentValue );\n\tconst selectedSegmentIndex = isGradientColor ? 1 : 0;\n\n\tconst [ currentSegment, setCurrentSegment ] = useState(\n\t\tsegments[ selectedSegmentIndex ]\n\t);\n\tconst isGradientSegment = currentSegment === colorsUtils.segments[ 1 ];\n\tconst currentSegmentColors = ! isGradientSegment\n\t\t? defaultSettings.colors\n\t\t: defaultSettings.gradients;\n\tconst allAvailableColors = useMobileGlobalStylesColors();\n\tconst allAvailableGradients = currentSegmentColors\n\t\t.flatMap( ( { gradients } ) => gradients )\n\t\t.filter( Boolean );\n\n\tconst horizontalSeparatorStyle = usePreferredColorSchemeStyle(\n\t\tstyles.horizontalSeparator,\n\t\tstyles.horizontalSeparatorDark\n\t);\n\tconst clearButtonStyle = usePreferredColorSchemeStyle(\n\t\tstyles.clearButton,\n\t\tstyles.clearButtonDark\n\t);\n\tconst selectedColorTextStyle = usePreferredColorSchemeStyle(\n\t\tstyles.colorText,\n\t\tstyles.colorTextDark\n\t);\n\n\tconst isSolidSegment = currentSegment === segments[ 0 ];\n\tconst isCustomGadientShown = ! isSolidSegment && isGradientColor;\n\n\tconst setColor = ( color ) => {\n\t\tsetCurrentValue( color );\n\t\tif ( isSolidSegment && onColorChange && onGradientChange ) {\n\t\t\tonColorChange( color );\n\t\t} else if ( isSolidSegment && onColorChange ) {\n\t\t\tonColorChange( color );\n\t\t} else if ( ! isSolidSegment && onGradientChange ) {\n\t\t\tonGradientChange( color );\n\t\t}\n\t};\n\n\tfunction onClear() {\n\t\tsetCurrentValue( undefined );\n\n\t\tif ( onColorCleared ) {\n\t\t\tonColorCleared();\n\t\t}\n\t}\n\n\tfunction onCustomPress() {\n\t\tif ( isSolidSegment ) {\n\t\t\tnavigation.navigate( colorsUtils.screens.picker, {\n\t\t\t\tcurrentValue,\n\t\t\t\tsetColor,\n\t\t\t} );\n\t\t} else {\n\t\t\tnavigation.navigate( colorsUtils.screens.gradientPicker, {\n\t\t\t\tsetColor,\n\t\t\t\tisGradientColor,\n\t\t\t\tcurrentValue,\n\t\t\t} );\n\t\t}\n\t}\n\n\tfunction getClearButton() {\n\t\treturn (\n\t\t\t<TouchableWithoutFeedback onPress={ onClear } hitSlop={ HIT_SLOP }>\n\t\t\t\t<View style={ styles.clearButtonContainer }>\n\t\t\t\t\t<Text style={ clearButtonStyle }>{ __( 'Reset' ) }</Text>\n\t\t\t\t</View>\n\t\t\t</TouchableWithoutFeedback>\n\t\t);\n\t}\n\n\tfunction getFooter() {\n\t\tif ( onGradientChange ) {\n\t\t\treturn (\n\t\t\t\t<SegmentedControls\n\t\t\t\t\tsegments={ segments }\n\t\t\t\t\tsegmentHandler={ setCurrentSegment }\n\t\t\t\t\tselectedIndex={ segments.indexOf( currentSegment ) }\n\t\t\t\t\taddonLeft={\n\t\t\t\t\t\tcurrentValue && (\n\t\t\t\t\t\t\t<ColorIndicator\n\t\t\t\t\t\t\t\tcolor={ currentValue }\n\t\t\t\t\t\t\t\tstyle={ styles.colorIndicator }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\taddonRight={ currentValue && getClearButton() }\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\t\treturn (\n\t\t\t<View style={ styles.footer }>\n\t\t\t\t<View style={ styles.flex }>\n\t\t\t\t\t{ currentValue && (\n\t\t\t\t\t\t<ColorIndicator\n\t\t\t\t\t\t\tcolor={ currentValue }\n\t\t\t\t\t\t\tstyle={ styles.colorIndicator }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</View>\n\t\t\t\t{ currentValue ? (\n\t\t\t\t\t<Text\n\t\t\t\t\t\tstyle={ selectedColorTextStyle }\n\t\t\t\t\t\tmaxFontSizeMultiplier={ 2 }\n\t\t\t\t\t\tselectable\n\t\t\t\t\t>\n\t\t\t\t\t\t{ currentValue.toUpperCase() }\n\t\t\t\t\t</Text>\n\t\t\t\t) : (\n\t\t\t\t\t<Text\n\t\t\t\t\t\tstyle={ styles.selectColorText }\n\t\t\t\t\t\tmaxFontSizeMultiplier={ 2 }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Select a color above' ) }\n\t\t\t\t\t</Text>\n\t\t\t\t) }\n\t\t\t\t<View style={ styles.flex }>\n\t\t\t\t\t{ currentValue && getClearButton() }\n\t\t\t\t</View>\n\t\t\t</View>\n\t\t);\n\t}\n\treturn (\n\t\t<View>\n\t\t\t{ ! hideNavigation && (\n\t\t\t\t<NavBar>\n\t\t\t\t\t<NavBar.BackButton onPress={ navigation.goBack } />\n\t\t\t\t\t<NavBar.Heading>{ label } </NavBar.Heading>\n\t\t\t\t</NavBar>\n\t\t\t) }\n\n\t\t\t<View style={ styles.colorPalettes }>\n\t\t\t\t{ currentSegmentColors.map( ( palette, paletteKey ) => {\n\t\t\t\t\tconst paletteSettings = {\n\t\t\t\t\t\tcolors: palette.colors,\n\t\t\t\t\t\tgradients: palette.gradients,\n\t\t\t\t\t\tallColors: allAvailableColors,\n\t\t\t\t\t\tallGradients: allAvailableGradients,\n\t\t\t\t\t};\n\t\t\t\t\t// Limit to show the custom indicator to the first available palette\n\t\t\t\t\tconst enableCustomColor = paletteKey === 0;\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<ColorPalette\n\t\t\t\t\t\t\tenableCustomColor={ enableCustomColor }\n\t\t\t\t\t\t\tlabel={ palette.name }\n\t\t\t\t\t\t\tkey={ paletteKey }\n\t\t\t\t\t\t\tsetColor={ setColor }\n\t\t\t\t\t\t\tactiveColor={ currentValue }\n\t\t\t\t\t\t\tisGradientColor={ isGradientColor }\n\t\t\t\t\t\t\tcurrentSegment={ currentSegment }\n\t\t\t\t\t\t\tonCustomPress={ onCustomPress }\n\t\t\t\t\t\t\tshouldEnableBottomSheetScroll={\n\t\t\t\t\t\t\t\tshouldEnableBottomSheetScroll\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tdefaultSettings={ paletteSettings }\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</View>\n\n\t\t\t{ isCustomGadientShown && (\n\t\t\t\t<>\n\t\t\t\t\t<View style={ horizontalSeparatorStyle } />\n\t\t\t\t\t<PanelBody>\n\t\t\t\t\t\t<ColorControl\n\t\t\t\t\t\t\tlabel={ __( 'Customize Gradient' ) }\n\t\t\t\t\t\t\tonPress={ onCustomPress }\n\t\t\t\t\t\t\twithColorIndicator={ false }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</PanelBody>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t<View style={ horizontalSeparatorStyle } />\n\t\t\t{ getFooter() }\n\t\t</View>\n\t);\n};\n\nexport default PaletteScreen;\n"],"mappings":";;;;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAKA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IA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T,IAAAvC,MAAA,CAAAC,aAAA,EAAC1E,WAAA,CAAAiH,YAAY;IACZ3F,KAAK,EAAG,IAAA4D,QAAE,EAAE,oBAAqB,CAAG;IACpCN,OAAO,EAAGT,aAAe;IACzB+C,kBAAkB,EAAG;EAAO,CAC5B,CACS,CACV,CACF,EACD,IAAAzC,MAAA,CAAAC,aAAA,EAAC/E,YAAA,CAAAmF,IAAI;IAACC,KAAK,EAAG7B;EAA0B,CAAE,CAAC,EACzCiC,SAAS,CAAC,CACP,CAAC;AAET,CAAC;AAAC,IAAAgC,QAAA,GAAAC,OAAA,CAAAhC,OAAA,GAEatE,aAAa"}
1
+ {"version":3,"names":["_reactNative","require","_i18n","_element","_compose","_components","_native","_colorPalette","_interopRequireDefault","_colorIndicator","_navBar","_segmentedControl","_utils","_style","HIT_SLOP","top","bottom","left","right","PaletteScreen","route","useRoute","navigation","useNavigation","shouldEnableBottomSheetScroll","useContext","BottomSheetContext","label","onColorChange","onGradientChange","onColorCleared","colorValue","defaultSettings","hideNavigation","params","segments","isGradient","colorsUtils","currentValue","setCurrentValue","useState","isGradientColor","selectedSegmentIndex","currentSegment","setCurrentSegment","isGradientSegment","currentSegmentColors","colors","gradients","allAvailableColors","useMobileGlobalStylesColors","allAvailableGradients","flatMap","filter","Boolean","horizontalSeparatorStyle","usePreferredColorSchemeStyle","styles","horizontalSeparator","horizontalSeparatorDark","clearButtonStyle","clearButton","clearButtonDark","selectedColorTextStyle","colorText","colorTextDark","isSolidSegment","isCustomGadientShown","setColor","color","onClear","undefined","onCustomPress","navigate","screens","picker","gradientPicker","getClearButton","_react","createElement","TouchableWithoutFeedback","accessibilityLabel","__","onPress","hitSlop","View","style","clearButtonContainer","Text","getFooter","default","segmentHandler","selectedIndex","indexOf","addonLeft","colorIndicator","addonRight","footer","flex","maxFontSizeMultiplier","selectable","toUpperCase","selectColorText","BackButton","goBack","Heading","colorPalettes","map","palette","paletteKey","paletteSettings","allColors","allGradients","enableCustomColor","name","key","activeColor","Fragment","PanelBody","ColorControl","withColorIndicator","_default","exports"],"sources":["@wordpress/components/src/mobile/color-settings/palette.screen.native.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { View, Text, TouchableWithoutFeedback } from 'react-native';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState, useContext } from '@wordpress/element';\nimport { usePreferredColorSchemeStyle } from '@wordpress/compose';\nimport {\n\tColorControl,\n\tPanelBody,\n\tBottomSheetContext,\n\tuseMobileGlobalStylesColors,\n} from '@wordpress/components';\nimport { useRoute, useNavigation } from '@react-navigation/native';\n\n/**\n * Internal dependencies\n */\nimport ColorPalette from '../../color-palette';\nimport ColorIndicator from '../../color-indicator';\nimport NavBar from '../bottom-sheet/nav-bar';\nimport SegmentedControls from '../segmented-control';\nimport { colorsUtils } from './utils';\n\nimport styles from './style.scss';\n\nconst HIT_SLOP = { top: 8, bottom: 8, left: 8, right: 8 };\n\nconst PaletteScreen = () => {\n\tconst route = useRoute();\n\tconst navigation = useNavigation();\n\tconst { shouldEnableBottomSheetScroll } = useContext( BottomSheetContext );\n\tconst {\n\t\tlabel,\n\t\tonColorChange,\n\t\tonGradientChange,\n\t\tonColorCleared,\n\t\tcolorValue,\n\t\tdefaultSettings,\n\t\thideNavigation = false,\n\t} = route.params || {};\n\tconst { segments, isGradient } = colorsUtils;\n\tconst [ currentValue, setCurrentValue ] = useState( colorValue );\n\tconst isGradientColor = isGradient( currentValue );\n\tconst selectedSegmentIndex = isGradientColor ? 1 : 0;\n\n\tconst [ currentSegment, setCurrentSegment ] = useState(\n\t\tsegments[ selectedSegmentIndex ]\n\t);\n\tconst isGradientSegment = currentSegment === colorsUtils.segments[ 1 ];\n\tconst currentSegmentColors = ! isGradientSegment\n\t\t? defaultSettings.colors\n\t\t: defaultSettings.gradients;\n\tconst allAvailableColors = useMobileGlobalStylesColors();\n\tconst allAvailableGradients = currentSegmentColors\n\t\t.flatMap( ( { gradients } ) => gradients )\n\t\t.filter( Boolean );\n\n\tconst horizontalSeparatorStyle = usePreferredColorSchemeStyle(\n\t\tstyles.horizontalSeparator,\n\t\tstyles.horizontalSeparatorDark\n\t);\n\tconst clearButtonStyle = usePreferredColorSchemeStyle(\n\t\tstyles.clearButton,\n\t\tstyles.clearButtonDark\n\t);\n\tconst selectedColorTextStyle = usePreferredColorSchemeStyle(\n\t\tstyles.colorText,\n\t\tstyles.colorTextDark\n\t);\n\n\tconst isSolidSegment = currentSegment === segments[ 0 ];\n\tconst isCustomGadientShown = ! isSolidSegment && isGradientColor;\n\n\tconst setColor = ( color ) => {\n\t\tsetCurrentValue( color );\n\t\tif ( isSolidSegment && onColorChange && onGradientChange ) {\n\t\t\tonColorChange( color );\n\t\t} else if ( isSolidSegment && onColorChange ) {\n\t\t\tonColorChange( color );\n\t\t} else if ( ! isSolidSegment && onGradientChange ) {\n\t\t\tonGradientChange( color );\n\t\t}\n\t};\n\n\tfunction onClear() {\n\t\tsetCurrentValue( undefined );\n\n\t\tif ( onColorCleared ) {\n\t\t\tonColorCleared();\n\t\t}\n\t}\n\n\tfunction onCustomPress() {\n\t\tif ( isSolidSegment ) {\n\t\t\tnavigation.navigate( colorsUtils.screens.picker, {\n\t\t\t\tcurrentValue,\n\t\t\t\tsetColor,\n\t\t\t} );\n\t\t} else {\n\t\t\tnavigation.navigate( colorsUtils.screens.gradientPicker, {\n\t\t\t\tsetColor,\n\t\t\t\tisGradientColor,\n\t\t\t\tcurrentValue,\n\t\t\t} );\n\t\t}\n\t}\n\n\tfunction getClearButton() {\n\t\treturn (\n\t\t\t<TouchableWithoutFeedback\n\t\t\t\taccessibilityLabel={ __( 'Clear selected color' ) }\n\t\t\t\tonPress={ onClear }\n\t\t\t\thitSlop={ HIT_SLOP }\n\t\t\t>\n\t\t\t\t<View style={ styles.clearButtonContainer }>\n\t\t\t\t\t<Text style={ clearButtonStyle }>{ __( 'Reset' ) }</Text>\n\t\t\t\t</View>\n\t\t\t</TouchableWithoutFeedback>\n\t\t);\n\t}\n\n\tfunction getFooter() {\n\t\tif ( onGradientChange ) {\n\t\t\treturn (\n\t\t\t\t<SegmentedControls\n\t\t\t\t\tsegments={ segments }\n\t\t\t\t\tsegmentHandler={ setCurrentSegment }\n\t\t\t\t\tselectedIndex={ segments.indexOf( currentSegment ) }\n\t\t\t\t\taddonLeft={\n\t\t\t\t\t\tcurrentValue && (\n\t\t\t\t\t\t\t<ColorIndicator\n\t\t\t\t\t\t\t\tcolor={ currentValue }\n\t\t\t\t\t\t\t\tstyle={ styles.colorIndicator }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\taddonRight={ currentValue && getClearButton() }\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\t\treturn (\n\t\t\t<View style={ styles.footer }>\n\t\t\t\t<View style={ styles.flex }>\n\t\t\t\t\t{ currentValue && (\n\t\t\t\t\t\t<ColorIndicator\n\t\t\t\t\t\t\tcolor={ currentValue }\n\t\t\t\t\t\t\tstyle={ styles.colorIndicator }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</View>\n\t\t\t\t{ currentValue ? (\n\t\t\t\t\t<Text\n\t\t\t\t\t\tstyle={ selectedColorTextStyle }\n\t\t\t\t\t\tmaxFontSizeMultiplier={ 2 }\n\t\t\t\t\t\tselectable\n\t\t\t\t\t>\n\t\t\t\t\t\t{ currentValue.toUpperCase() }\n\t\t\t\t\t</Text>\n\t\t\t\t) : (\n\t\t\t\t\t<Text\n\t\t\t\t\t\tstyle={ styles.selectColorText }\n\t\t\t\t\t\tmaxFontSizeMultiplier={ 2 }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Select a color above' ) }\n\t\t\t\t\t</Text>\n\t\t\t\t) }\n\t\t\t\t<View style={ styles.flex }>\n\t\t\t\t\t{ currentValue && getClearButton() }\n\t\t\t\t</View>\n\t\t\t</View>\n\t\t);\n\t}\n\treturn (\n\t\t<View>\n\t\t\t{ ! hideNavigation && (\n\t\t\t\t<NavBar>\n\t\t\t\t\t<NavBar.BackButton onPress={ navigation.goBack } />\n\t\t\t\t\t<NavBar.Heading>{ label } </NavBar.Heading>\n\t\t\t\t</NavBar>\n\t\t\t) }\n\n\t\t\t<View style={ styles.colorPalettes }>\n\t\t\t\t{ currentSegmentColors.map( ( palette, paletteKey ) => {\n\t\t\t\t\tconst paletteSettings = {\n\t\t\t\t\t\tcolors: palette.colors,\n\t\t\t\t\t\tgradients: palette.gradients,\n\t\t\t\t\t\tallColors: allAvailableColors,\n\t\t\t\t\t\tallGradients: allAvailableGradients,\n\t\t\t\t\t};\n\t\t\t\t\t// Limit to show the custom indicator to the first available palette\n\t\t\t\t\tconst enableCustomColor = paletteKey === 0;\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<ColorPalette\n\t\t\t\t\t\t\tenableCustomColor={ enableCustomColor }\n\t\t\t\t\t\t\tlabel={ palette.name }\n\t\t\t\t\t\t\tkey={ paletteKey }\n\t\t\t\t\t\t\tsetColor={ setColor }\n\t\t\t\t\t\t\tactiveColor={ currentValue }\n\t\t\t\t\t\t\tisGradientColor={ isGradientColor }\n\t\t\t\t\t\t\tcurrentSegment={ currentSegment }\n\t\t\t\t\t\t\tonCustomPress={ onCustomPress }\n\t\t\t\t\t\t\tshouldEnableBottomSheetScroll={\n\t\t\t\t\t\t\t\tshouldEnableBottomSheetScroll\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tdefaultSettings={ paletteSettings }\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</View>\n\n\t\t\t{ isCustomGadientShown && (\n\t\t\t\t<>\n\t\t\t\t\t<View style={ horizontalSeparatorStyle } />\n\t\t\t\t\t<PanelBody>\n\t\t\t\t\t\t<ColorControl\n\t\t\t\t\t\t\tlabel={ __( 'Customize Gradient' ) }\n\t\t\t\t\t\t\tonPress={ onCustomPress }\n\t\t\t\t\t\t\twithColorIndicator={ false }\n\t\t\t\t\t\t/>\n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,EAC5BA,6BACA;MACDQ,eAAe,EAAG8E;IAAiB,CACnC,CAAC;EAEJ,CAAE,CACG,CAAC,EAEL3C,oBAAoB,IACrB,IAAAW,MAAA,CAAAC,aAAA,EAAAD,MAAA,CAAAuC,QAAA,QACC,IAAAvC,MAAA,CAAAC,aAAA,EAAC/E,YAAA,CAAAqF,IAAI;IAACC,KAAK,EAAG/B;EAA0B,CAAE,CAAC,EAC3C,IAAAuB,MAAA,CAAAC,aAAA,EAAC1E,WAAA,CAAAiH,SAAS,QACT,IAAAxC,MAAA,CAAAC,aAAA,EAAC1E,WAAA,CAAAkH,YAAY;IACZ5F,KAAK,EAAG,IAAAuD,QAAE,EAAE,oBAAqB,CAAG;IACpCC,OAAO,EAAGX,aAAe;IACzBgD,kBAAkB,EAAG;EAAO,CAC5B,CACS,CACV,CACF,EACD,IAAA1C,MAAA,CAAAC,aAAA,EAAC/E,YAAA,CAAAqF,IAAI;IAACC,KAAK,EAAG/B;EAA0B,CAAE,CAAC,EACzCkC,SAAS,CAAC,CACP,CAAC;AAET,CAAC;AAAC,IAAAgC,QAAA,GAAAC,OAAA,CAAAhC,OAAA,GAEavE,aAAa"}
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","_dom","noop","MENU_ITEM_ROLES","cycleValue","value","total","offset","nextValue","NavigableContainer","Component","constructor","args","onKeyDown","bind","bindContainer","getFocusableContext","getFocusableIndex","componentDidMount","container","addEventListener","componentWillUnmount","removeEventListener","ref","forwardedRef","props","current","target","onlyBrowserTabstops","finder","focus","tabbable","focusable","focusables","find","index","indexOf","event","cycle","eventToOffset","onNavigate","stopNavigationEvents","undefined","stopImmediatePropagation","targetRole","getAttribute","targetHasMenuItemRole","includes","preventDefault","activeElement","ownerDocument","context","nextIndex","length","code","render","children","restProps","_react","createElement","forwardedNavigableContainer","displayName","_default","exports","default","forwardRef"],"sources":["@wordpress/components/src/navigable-container/container.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { Component, forwardRef } from '@wordpress/element';\nimport { focus } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport type { NavigableContainerProps } from './types';\n\nconst noop = () => {};\nconst MENU_ITEM_ROLES = [ 'menuitem', 'menuitemradio', 'menuitemcheckbox' ];\n\nfunction cycleValue( value: number, total: number, offset: number ) {\n\tconst nextValue = value + offset;\n\tif ( nextValue < 0 ) {\n\t\treturn total + nextValue;\n\t} else if ( nextValue >= total ) {\n\t\treturn nextValue - total;\n\t}\n\n\treturn nextValue;\n}\n\nclass NavigableContainer extends Component< NavigableContainerProps > {\n\tcontainer?: HTMLDivElement;\n\n\tconstructor( args: NavigableContainerProps ) {\n\t\tsuper( args );\n\t\tthis.onKeyDown = this.onKeyDown.bind( this );\n\t\tthis.bindContainer = this.bindContainer.bind( this );\n\n\t\tthis.getFocusableContext = this.getFocusableContext.bind( this );\n\t\tthis.getFocusableIndex = this.getFocusableIndex.bind( this );\n\t}\n\n\tcomponentDidMount() {\n\t\tif ( ! this.container ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// We use DOM event listeners instead of React event listeners\n\t\t// because we want to catch events from the underlying DOM tree\n\t\t// The React Tree can be different from the DOM tree when using\n\t\t// portals. Block Toolbars for instance are rendered in a separate\n\t\t// React Trees.\n\t\tthis.container.addEventListener( 'keydown', this.onKeyDown );\n\t}\n\n\tcomponentWillUnmount() {\n\t\tif ( ! this.container ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.container.removeEventListener( 'keydown', this.onKeyDown );\n\t}\n\n\tbindContainer( ref: HTMLDivElement ) {\n\t\tconst { forwardedRef } = this.props;\n\t\tthis.container = ref;\n\n\t\tif ( typeof forwardedRef === 'function' ) {\n\t\t\tforwardedRef( ref );\n\t\t} else if ( forwardedRef && 'current' in forwardedRef ) {\n\t\t\tforwardedRef.current = ref;\n\t\t}\n\t}\n\n\tgetFocusableContext( target: Element ) {\n\t\tif ( ! this.container ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst { onlyBrowserTabstops } = this.props;\n\t\tconst finder = onlyBrowserTabstops ? focus.tabbable : focus.focusable;\n\t\tconst focusables = finder.find( this.container ) as HTMLElement[];\n\n\t\tconst index = this.getFocusableIndex( focusables, target );\n\t\tif ( index > -1 && target ) {\n\t\t\treturn { index, target, focusables };\n\t\t}\n\t\treturn null;\n\t}\n\n\tgetFocusableIndex( focusables: Element[], target: Element ) {\n\t\treturn focusables.indexOf( target );\n\t}\n\n\tonKeyDown( event: KeyboardEvent ) {\n\t\tif ( this.props.onKeyDown ) {\n\t\t\tthis.props.onKeyDown( event );\n\t\t}\n\n\t\tconst { getFocusableContext } = this;\n\t\tconst {\n\t\t\tcycle = true,\n\t\t\teventToOffset,\n\t\t\tonNavigate = noop,\n\t\t\tstopNavigationEvents,\n\t\t} = this.props;\n\n\t\tconst offset = eventToOffset( event );\n\n\t\t// eventToOffset returns undefined if the event is not handled by the component.\n\t\tif ( offset !== undefined && stopNavigationEvents ) {\n\t\t\t// Prevents arrow key handlers bound to the document directly interfering.\n\t\t\tevent.stopImmediatePropagation();\n\n\t\t\t// When navigating a collection of items, prevent scroll containers\n\t\t\t// from scrolling. The preventDefault also prevents Voiceover from\n\t\t\t// 'handling' the event, as voiceover will try to use arrow keys\n\t\t\t// for highlighting text.\n\t\t\tconst targetRole = (\n\t\t\t\tevent.target as HTMLDivElement | null\n\t\t\t )?.getAttribute( 'role' );\n\t\t\tconst targetHasMenuItemRole =\n\t\t\t\t!! targetRole && MENU_ITEM_ROLES.includes( targetRole );\n\n\t\t\tif ( targetHasMenuItemRole ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\n\t\tif ( ! offset ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst activeElement = ( event.target as HTMLElement | null )\n\t\t\t?.ownerDocument?.activeElement;\n\t\tif ( ! activeElement ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst context = getFocusableContext( activeElement );\n\t\tif ( ! context ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { index, focusables } = context;\n\t\tconst nextIndex = cycle\n\t\t\t? cycleValue( index, focusables.length, offset )\n\t\t\t: index + offset;\n\n\t\tif ( nextIndex >= 0 && nextIndex < focusables.length ) {\n\t\t\tfocusables[ nextIndex ].focus();\n\t\t\tonNavigate( nextIndex, focusables[ nextIndex ] );\n\n\t\t\t// `preventDefault()` on tab to avoid having the browser move the focus\n\t\t\t// after this component has already moved it.\n\t\t\tif ( event.code === 'Tab' ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\t}\n\n\trender() {\n\t\tconst {\n\t\t\tchildren,\n\t\t\tstopNavigationEvents,\n\t\t\teventToOffset,\n\t\t\tonNavigate,\n\t\t\tonKeyDown,\n\t\t\tcycle,\n\t\t\tonlyBrowserTabstops,\n\t\t\tforwardedRef,\n\t\t\t...restProps\n\t\t} = this.props;\n\t\treturn (\n\t\t\t<div ref={ this.bindContainer } { ...restProps }>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t);\n\t}\n}\n\nconst forwardedNavigableContainer = (\n\tprops: NavigableContainerProps,\n\tref: ForwardedRef< HTMLDivElement >\n) => {\n\treturn <NavigableContainer { ...props } forwardedRef={ ref } />;\n};\nforwardedNavigableContainer.displayName = 'NavigableContainer';\n\nexport default forwardRef( forwardedNavigableContainer );\n"],"mappings":";;;;;;;AAQA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AASA,MAAME,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AACrB,MAAMC,eAAe,GAAG,CAAE,UAAU,EAAE,eAAe,EAAE,kBAAkB,CAAE;AAE3E,SAASC,UAAUA,CAAEC,KAAa,EAAEC,KAAa,EAAEC,MAAc,EAAG;EACnE,MAAMC,SAAS,GAAGH,KAAK,GAAGE,MAAM;EAChC,IAAKC,SAAS,GAAG,CAAC,EAAG;IACpB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AKpC,GAAG,EAAG,IAAI,CAACR,aAAe;MAAA,GAAM0C;IAAS,GAC3CD,QACE,CAAC;EAER;AACD;AAEA,MAAMI,2BAA2B,GAAGA,CACnCnC,KAA8B,EAC9BF,GAAmC,KAC/B;EACJ,OAAO,IAAAmC,MAAA,CAAAC,aAAA,EAAClD,kBAAkB;IAAA,GAAMgB,KAAK;IAAGD,YAAY,EAAGD;EAAK,CAAE,CAAC;AAChE,CAAC;AACDqC,2BAA2B,CAACC,WAAW,GAAG,oBAAoB;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEhD,IAAAC,mBAAU,EAAEL,2BAA4B,CAAC"}
1
+ {"version":3,"names":["_element","require","_dom","noop","MENU_ITEM_ROLES","cycleValue","value","total","offset","nextValue","NavigableContainer","Component","constructor","args","onKeyDown","bind","bindContainer","getFocusableContext","getFocusableIndex","componentDidMount","container","addEventListener","componentWillUnmount","removeEventListener","ref","forwardedRef","props","current","target","onlyBrowserTabstops","finder","focus","tabbable","focusable","focusables","find","index","indexOf","event","cycle","eventToOffset","onNavigate","stopNavigationEvents","undefined","stopImmediatePropagation","targetRole","getAttribute","targetHasMenuItemRole","includes","preventDefault","activeElement","ownerDocument","context","nextIndex","length","code","render","children","restProps","_react","createElement","forwardedNavigableContainer","displayName","_default","exports","default","forwardRef"],"sources":["@wordpress/components/src/navigable-container/container.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { Component, forwardRef } from '@wordpress/element';\nimport { focus } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport type { NavigableContainerProps } from './types';\n\nconst noop = () => {};\nconst MENU_ITEM_ROLES = [ 'menuitem', 'menuitemradio', 'menuitemcheckbox' ];\n\nfunction cycleValue( value: number, total: number, offset: number ) {\n\tconst nextValue = value + offset;\n\tif ( nextValue < 0 ) {\n\t\treturn total + nextValue;\n\t} else if ( nextValue >= total ) {\n\t\treturn nextValue - total;\n\t}\n\n\treturn nextValue;\n}\n\nclass NavigableContainer extends Component< NavigableContainerProps > {\n\tcontainer?: HTMLDivElement;\n\n\tconstructor( args: NavigableContainerProps ) {\n\t\tsuper( args );\n\t\tthis.onKeyDown = this.onKeyDown.bind( this );\n\t\tthis.bindContainer = this.bindContainer.bind( this );\n\n\t\tthis.getFocusableContext = this.getFocusableContext.bind( this );\n\t\tthis.getFocusableIndex = this.getFocusableIndex.bind( this );\n\t}\n\n\tcomponentDidMount() {\n\t\tif ( ! this.container ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// We use DOM event listeners instead of React event listeners\n\t\t// because we want to catch events from the underlying DOM tree\n\t\t// The React Tree can be different from the DOM tree when using\n\t\t// portals. Block Toolbars for instance are rendered in a separate\n\t\t// React Trees.\n\t\tthis.container.addEventListener( 'keydown', this.onKeyDown );\n\t}\n\n\tcomponentWillUnmount() {\n\t\tif ( ! this.container ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.container.removeEventListener( 'keydown', this.onKeyDown );\n\t}\n\n\tbindContainer( ref: HTMLDivElement ) {\n\t\tconst { forwardedRef } = this.props;\n\t\tthis.container = ref;\n\n\t\tif ( typeof forwardedRef === 'function' ) {\n\t\t\tforwardedRef( ref );\n\t\t} else if ( forwardedRef && 'current' in forwardedRef ) {\n\t\t\tforwardedRef.current = ref;\n\t\t}\n\t}\n\n\tgetFocusableContext( target: Element ) {\n\t\tif ( ! this.container ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst { onlyBrowserTabstops } = this.props;\n\t\tconst finder = onlyBrowserTabstops ? focus.tabbable : focus.focusable;\n\t\tconst focusables = finder.find( this.container );\n\n\t\tconst index = this.getFocusableIndex( focusables, target );\n\t\tif ( index > -1 && target ) {\n\t\t\treturn { index, target, focusables };\n\t\t}\n\t\treturn null;\n\t}\n\n\tgetFocusableIndex( focusables: Element[], target: Element ) {\n\t\treturn focusables.indexOf( target );\n\t}\n\n\tonKeyDown( event: KeyboardEvent ) {\n\t\tif ( this.props.onKeyDown ) {\n\t\t\tthis.props.onKeyDown( event );\n\t\t}\n\n\t\tconst { getFocusableContext } = this;\n\t\tconst {\n\t\t\tcycle = true,\n\t\t\teventToOffset,\n\t\t\tonNavigate = noop,\n\t\t\tstopNavigationEvents,\n\t\t} = this.props;\n\n\t\tconst offset = eventToOffset( event );\n\n\t\t// eventToOffset returns undefined if the event is not handled by the component.\n\t\tif ( offset !== undefined && stopNavigationEvents ) {\n\t\t\t// Prevents arrow key handlers bound to the document directly interfering.\n\t\t\tevent.stopImmediatePropagation();\n\n\t\t\t// When navigating a collection of items, prevent scroll containers\n\t\t\t// from scrolling. The preventDefault also prevents Voiceover from\n\t\t\t// 'handling' the event, as voiceover will try to use arrow keys\n\t\t\t// for highlighting text.\n\t\t\tconst targetRole = (\n\t\t\t\tevent.target as HTMLDivElement | null\n\t\t\t )?.getAttribute( 'role' );\n\t\t\tconst targetHasMenuItemRole =\n\t\t\t\t!! targetRole && MENU_ITEM_ROLES.includes( targetRole );\n\n\t\t\tif ( targetHasMenuItemRole ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\n\t\tif ( ! offset ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst activeElement = ( event.target as HTMLElement | null )\n\t\t\t?.ownerDocument?.activeElement;\n\t\tif ( ! activeElement ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst context = getFocusableContext( activeElement );\n\t\tif ( ! context ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { index, focusables } = context;\n\t\tconst nextIndex = cycle\n\t\t\t? cycleValue( index, focusables.length, offset )\n\t\t\t: index + offset;\n\n\t\tif ( nextIndex >= 0 && nextIndex < focusables.length ) {\n\t\t\tfocusables[ nextIndex ].focus();\n\t\t\tonNavigate( nextIndex, focusables[ nextIndex ] );\n\n\t\t\t// `preventDefault()` on tab to avoid having the browser move the focus\n\t\t\t// after this component has already moved it.\n\t\t\tif ( event.code === 'Tab' ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\t}\n\n\trender() {\n\t\tconst {\n\t\t\tchildren,\n\t\t\tstopNavigationEvents,\n\t\t\teventToOffset,\n\t\t\tonNavigate,\n\t\t\tonKeyDown,\n\t\t\tcycle,\n\t\t\tonlyBrowserTabstops,\n\t\t\tforwardedRef,\n\t\t\t...restProps\n\t\t} = this.props;\n\t\treturn (\n\t\t\t<div ref={ this.bindContainer } { ...restProps }>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t);\n\t}\n}\n\nconst forwardedNavigableContainer = (\n\tprops: NavigableContainerProps,\n\tref: ForwardedRef< HTMLDivElement >\n) => {\n\treturn <NavigableContainer { ...props } forwardedRef={ ref } />;\n};\nforwardedNavigableContainer.displayName = 'NavigableContainer';\n\nexport default forwardRef( forwardedNavigableContainer );\n"],"mappings":";;;;;;;AAQA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AASA,MAAME,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AACrB,MAAMC,eAAe,GAAG,CAAE,UAAU,EAAE,eAAe,EAAE,kBAAkB,CAAE;AAE3E,SAASC,UAAUA,CAAEC,KAAa,EAAEC,KAAa,EAAEC,MAAc,EAAG;EACnE,MAAMC,SAAS,GAAGH,KAAK,GAAGE,MAAM;EAChC,IAAKC,SAAS,GAAG,CAAC,EAAG;IACpB,OAAOF,KAAK,GAAGE,SAAS;EACzB,CAAC,MAAM,IAAKA,SAAS,IAAIF,KAAK,EAAG;IAChC,OAAOE,SAAS,GAAGF,KAAK;EACzB;EAEA,OAAOE,SAAS;AACjB;AAEA,MAAMC,kBAAkB,SAASC,kBAAS,CAA4B;EAGrEC,WAAWA,CAAEC,IAA6B,EAAG;IAC5C,KAAK,CAAEA,IAAK,CAAC;IACb,IAAI,CAACC,SAAS,GAAG,IAAI,CAACA,SAAS,CAACC,IAAI,CAAE,IAAK,CAAC;IAC5C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AA,GAAAC,OAAA,CAAAC,OAAA,GAEhD,IAAAC,mBAAU,EAAEL,2BAA4B,CAAC"}
@@ -25,14 +25,127 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
25
25
  */
26
26
 
27
27
  const MAX_HISTORY_LENGTH = 50;
28
- function screensReducer(state = [], action) {
28
+ function addScreen({
29
+ screens
30
+ }, screen) {
31
+ return [...screens, screen];
32
+ }
33
+ function removeScreen({
34
+ screens
35
+ }, screen) {
36
+ return screens.filter(s => s.id !== screen.id);
37
+ }
38
+ function goBack({
39
+ locationHistory
40
+ }) {
41
+ if (locationHistory.length <= 1) {
42
+ return locationHistory;
43
+ }
44
+ return [...locationHistory.slice(0, -2), {
45
+ ...locationHistory[locationHistory.length - 2],
46
+ isBack: true,
47
+ hasRestoredFocus: false
48
+ }];
49
+ }
50
+ function goTo(state, path, options = {}) {
51
+ const {
52
+ locationHistory
53
+ } = state;
54
+ const {
55
+ focusTargetSelector,
56
+ isBack = false,
57
+ skipFocus = false,
58
+ replace = false,
59
+ ...restOptions
60
+ } = options;
61
+ const isNavigatingToPreviousPath = isBack && locationHistory.length > 1 && locationHistory[locationHistory.length - 2].path === path;
62
+ if (isNavigatingToPreviousPath) {
63
+ return goBack(state);
64
+ }
65
+ const newLocation = {
66
+ ...restOptions,
67
+ path,
68
+ isBack,
69
+ hasRestoredFocus: false,
70
+ skipFocus
71
+ };
72
+ if (locationHistory.length === 0) {
73
+ return replace ? [] : [newLocation];
74
+ }
75
+ const newLocationHistory = locationHistory.slice(locationHistory.length > MAX_HISTORY_LENGTH - 1 ? 1 : 0, -1);
76
+ if (!replace) {
77
+ newLocationHistory.push(
78
+ // Assign `focusTargetSelector` to the previous location in history
79
+ // (the one we just navigated from).
80
+ {
81
+ ...locationHistory[locationHistory.length - 1],
82
+ focusTargetSelector
83
+ });
84
+ }
85
+ newLocationHistory.push(newLocation);
86
+ return newLocationHistory;
87
+ }
88
+ function goToParent(state, options = {}) {
89
+ const {
90
+ locationHistory,
91
+ screens
92
+ } = state;
93
+ const currentPath = locationHistory[locationHistory.length - 1].path;
94
+ if (currentPath === undefined) {
95
+ return locationHistory;
96
+ }
97
+ const parentPath = (0, _router.findParent)(currentPath, screens);
98
+ if (parentPath === undefined) {
99
+ return locationHistory;
100
+ }
101
+ return goTo(state, parentPath, {
102
+ ...options,
103
+ isBack: true
104
+ });
105
+ }
106
+ function routerReducer(state, action) {
107
+ let {
108
+ screens,
109
+ locationHistory,
110
+ matchedPath
111
+ } = state;
29
112
  switch (action.type) {
30
113
  case 'add':
31
- return [...state, action.screen];
114
+ screens = addScreen(state, action.screen);
115
+ break;
32
116
  case 'remove':
33
- return state.filter(s => s.id !== action.screen.id);
117
+ screens = removeScreen(state, action.screen);
118
+ break;
119
+ case 'goback':
120
+ locationHistory = goBack(state);
121
+ break;
122
+ case 'goto':
123
+ locationHistory = goTo(state, action.path, action.options);
124
+ break;
125
+ case 'gotoparent':
126
+ locationHistory = goToParent(state, action.options);
127
+ break;
128
+ }
129
+
130
+ // Return early in case there is no change
131
+ if (screens === state.screens && locationHistory === state.locationHistory) {
132
+ return state;
34
133
  }
35
- return state;
134
+
135
+ // Compute the matchedPath
136
+ const currentPath = locationHistory.length > 0 ? locationHistory[locationHistory.length - 1].path : undefined;
137
+ matchedPath = currentPath !== undefined ? (0, _router.patternMatch)(currentPath, screens) : undefined;
138
+
139
+ // If the new match is the same as the previous match,
140
+ // return the previous one to keep immutability.
141
+ if (matchedPath && state.matchedPath && matchedPath.id === state.matchedPath.id && (0, _isShallowEqual.default)(matchedPath.params, state.matchedPath.params)) {
142
+ matchedPath = state.matchedPath;
143
+ }
144
+ return {
145
+ screens,
146
+ locationHistory,
147
+ matchedPath
148
+ };
36
149
  }
37
150
  function UnconnectedNavigatorProvider(props, forwardedRef) {
38
151
  const {
@@ -41,124 +154,53 @@ function UnconnectedNavigatorProvider(props, forwardedRef) {
41
154
  className,
42
155
  ...otherProps
43
156
  } = (0, _context.useContextSystem)(props, 'NavigatorProvider');
44
- const [locationHistory, setLocationHistory] = (0, _element.useState)([{
45
- path: initialPath
46
- }]);
47
- const currentLocationHistory = (0, _element.useRef)([]);
48
- const [screens, dispatch] = (0, _element.useReducer)(screensReducer, []);
49
- const currentScreens = (0, _element.useRef)([]);
50
- (0, _element.useEffect)(() => {
51
- currentScreens.current = screens;
52
- }, [screens]);
53
- (0, _element.useEffect)(() => {
54
- currentLocationHistory.current = locationHistory;
55
- }, [locationHistory]);
56
- const currentMatch = (0, _element.useRef)();
57
- const matchedPath = (0, _element.useMemo)(() => {
58
- let currentPath;
59
- if (locationHistory.length === 0 || (currentPath = locationHistory[locationHistory.length - 1].path) === undefined) {
60
- currentMatch.current = undefined;
61
- return undefined;
62
- }
63
- const resolvePath = path => {
64
- const newMatch = (0, _router.patternMatch)(path, screens);
157
+ const [routerState, dispatch] = (0, _element.useReducer)(routerReducer, initialPath, path => ({
158
+ screens: [],
159
+ locationHistory: [{
160
+ path
161
+ }],
162
+ matchedPath: undefined
163
+ }));
65
164
 
66
- // If the new match is the same as the current match,
67
- // return the previous one for performance reasons.
68
- if (currentMatch.current && newMatch && (0, _isShallowEqual.default)(newMatch.params, currentMatch.current.params) && newMatch.id === currentMatch.current.id) {
69
- return currentMatch.current;
70
- }
71
- return newMatch;
72
- };
73
- const newMatch = resolvePath(currentPath);
74
- currentMatch.current = newMatch;
75
- return newMatch;
76
- }, [screens, locationHistory]);
77
- const addScreen = (0, _element.useCallback)(screen => dispatch({
78
- type: 'add',
79
- screen
165
+ // The methods are constant forever, create stable references to them.
166
+ const methods = (0, _element.useMemo)(() => ({
167
+ goBack: () => dispatch({
168
+ type: 'goback'
169
+ }),
170
+ goTo: (path, options) => dispatch({
171
+ type: 'goto',
172
+ path,
173
+ options
174
+ }),
175
+ goToParent: options => dispatch({
176
+ type: 'gotoparent',
177
+ options
178
+ }),
179
+ addScreen: screen => dispatch({
180
+ type: 'add',
181
+ screen
182
+ }),
183
+ removeScreen: screen => dispatch({
184
+ type: 'remove',
185
+ screen
186
+ })
80
187
  }), []);
81
- const removeScreen = (0, _element.useCallback)(screen => dispatch({
82
- type: 'remove',
83
- screen
84
- }), []);
85
- const goBack = (0, _element.useCallback)(() => {
86
- setLocationHistory(prevLocationHistory => {
87
- if (prevLocationHistory.length <= 1) {
88
- return prevLocationHistory;
89
- }
90
- return [...prevLocationHistory.slice(0, -2), {
91
- ...prevLocationHistory[prevLocationHistory.length - 2],
92
- isBack: true,
93
- hasRestoredFocus: false
94
- }];
95
- });
96
- }, []);
97
- const goTo = (0, _element.useCallback)((path, options = {}) => {
98
- const {
99
- focusTargetSelector,
100
- isBack = false,
101
- skipFocus = false,
102
- replace = false,
103
- ...restOptions
104
- } = options;
105
- const isNavigatingToPreviousPath = isBack && currentLocationHistory.current.length > 1 && currentLocationHistory.current[currentLocationHistory.current.length - 2].path === path;
106
- if (isNavigatingToPreviousPath) {
107
- goBack();
108
- return;
109
- }
110
- setLocationHistory(prevLocationHistory => {
111
- const newLocation = {
112
- ...restOptions,
113
- path,
114
- isBack,
115
- hasRestoredFocus: false,
116
- skipFocus
117
- };
118
- if (prevLocationHistory.length === 0) {
119
- return replace ? [] : [newLocation];
120
- }
121
- const newLocationHistory = prevLocationHistory.slice(prevLocationHistory.length > MAX_HISTORY_LENGTH - 1 ? 1 : 0, -1);
122
- if (!replace) {
123
- newLocationHistory.push(
124
- // Assign `focusTargetSelector` to the previous location in history
125
- // (the one we just navigated from).
126
- {
127
- ...prevLocationHistory[prevLocationHistory.length - 1],
128
- focusTargetSelector
129
- });
130
- }
131
- newLocationHistory.push(newLocation);
132
- return newLocationHistory;
133
- });
134
- }, [goBack]);
135
- const goToParent = (0, _element.useCallback)((options = {}) => {
136
- const currentPath = currentLocationHistory.current[currentLocationHistory.current.length - 1].path;
137
- if (currentPath === undefined) {
138
- return;
139
- }
140
- const parentPath = (0, _router.findParent)(currentPath, currentScreens.current);
141
- if (parentPath === undefined) {
142
- return;
143
- }
144
- goTo(parentPath, {
145
- ...options,
146
- isBack: true
147
- });
148
- }, [goTo]);
149
- const navigatorContextValue = (0, _element.useMemo)(() => ({
150
- location: {
151
- ...locationHistory[locationHistory.length - 1],
152
- isInitial: locationHistory.length === 1
153
- },
154
- params: matchedPath ? matchedPath.params : {},
155
- match: matchedPath ? matchedPath.id : undefined,
156
- goTo,
157
- goBack,
158
- goToParent,
159
- addScreen,
160
- removeScreen
161
- }), [locationHistory, matchedPath, goTo, goBack, goToParent, addScreen, removeScreen]);
188
+ const {
189
+ locationHistory,
190
+ matchedPath
191
+ } = routerState;
192
+ const navigatorContextValue = (0, _element.useMemo)(() => {
193
+ var _matchedPath$params;
194
+ return {
195
+ location: {
196
+ ...locationHistory[locationHistory.length - 1],
197
+ isInitial: locationHistory.length === 1
198
+ },
199
+ params: (_matchedPath$params = matchedPath?.params) !== null && _matchedPath$params !== void 0 ? _matchedPath$params : {},
200
+ match: matchedPath?.id,
201
+ ...methods
202
+ };
203
+ }, [locationHistory, matchedPath, methods]);
162
204
  const cx = (0, _useCx.useCx)();
163
205
  const classes = (0, _element.useMemo)(() => cx(styles.navigatorProviderWrapper, className), [className, cx]);
164
206
  return (0, _react.createElement)(_view.View, {
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","_isShallowEqual","_interopRequireDefault","_context","_useCx","_router","_view","_context2","styles","_interopRequireWildcard","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","MAX_HISTORY_LENGTH","screensReducer","state","action","type","screen","filter","s","id","UnconnectedNavigatorProvider","props","forwardedRef","initialPath","children","className","otherProps","useContextSystem","locationHistory","setLocationHistory","useState","path","currentLocationHistory","useRef","screens","dispatch","useReducer","currentScreens","useEffect","current","currentMatch","matchedPath","useMemo","currentPath","length","undefined","resolvePath","newMatch","patternMatch","isShallowEqual","params","addScreen","useCallback","removeScreen","goBack","prevLocationHistory","slice","isBack","hasRestoredFocus","goTo","options","focusTargetSelector","skipFocus","replace","restOptions","isNavigatingToPreviousPath","newLocation","newLocationHistory","push","goToParent","parentPath","findParent","navigatorContextValue","location","isInitial","match","cx","useCx","classes","navigatorProviderWrapper","_react","createElement","View","ref","NavigatorContext","Provider","value","NavigatorProvider","exports","contextConnect","_default"],"sources":["@wordpress/components/src/navigator/navigator-provider/component.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseMemo,\n\tuseState,\n\tuseCallback,\n\tuseReducer,\n\tuseRef,\n\tuseEffect,\n} from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport type { WordPressComponentProps } from '../../context';\nimport { contextConnect, useContextSystem } from '../../context';\nimport { useCx } from '../../utils/hooks/use-cx';\nimport { patternMatch, findParent } from '../utils/router';\nimport { View } from '../../view';\nimport { NavigatorContext } from '../context';\nimport * as styles from '../styles';\nimport type {\n\tNavigatorProviderProps,\n\tNavigatorLocation,\n\tNavigatorContext as NavigatorContextType,\n\tScreen,\n} from '../types';\n\ntype MatchedPath = ReturnType< typeof patternMatch >;\ntype ScreenAction = { type: string; screen: Screen };\n\nconst MAX_HISTORY_LENGTH = 50;\n\nfunction screensReducer(\n\tstate: Screen[] = [],\n\taction: ScreenAction\n): Screen[] {\n\tswitch ( action.type ) {\n\t\tcase 'add':\n\t\t\treturn [ ...state, action.screen ];\n\t\tcase 'remove':\n\t\t\treturn state.filter( ( s: Screen ) => s.id !== action.screen.id );\n\t}\n\n\treturn state;\n}\n\nfunction UnconnectedNavigatorProvider(\n\tprops: WordPressComponentProps< NavigatorProviderProps, 'div' >,\n\tforwardedRef: ForwardedRef< any >\n) {\n\tconst { initialPath, children, className, ...otherProps } =\n\t\tuseContextSystem( props, 'NavigatorProvider' );\n\n\tconst [ locationHistory, setLocationHistory ] = useState<\n\t\tNavigatorLocation[]\n\t>( [\n\t\t{\n\t\t\tpath: initialPath,\n\t\t},\n\t] );\n\tconst currentLocationHistory = useRef< NavigatorLocation[] >( [] );\n\tconst [ screens, dispatch ] = useReducer( screensReducer, [] );\n\tconst currentScreens = useRef< Screen[] >( [] );\n\tuseEffect( () => {\n\t\tcurrentScreens.current = screens;\n\t}, [ screens ] );\n\tuseEffect( () => {\n\t\tcurrentLocationHistory.current = locationHistory;\n\t}, [ locationHistory ] );\n\tconst currentMatch = useRef< MatchedPath >();\n\tconst matchedPath = useMemo( () => {\n\t\tlet currentPath: string | undefined;\n\t\tif (\n\t\t\tlocationHistory.length === 0 ||\n\t\t\t( currentPath =\n\t\t\t\tlocationHistory[ locationHistory.length - 1 ].path ) ===\n\t\t\t\tundefined\n\t\t) {\n\t\t\tcurrentMatch.current = undefined;\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst resolvePath = ( path: string ) => {\n\t\t\tconst newMatch = patternMatch( path, screens );\n\n\t\t\t// If the new match is the same as the current match,\n\t\t\t// return the previous one for performance reasons.\n\t\t\tif (\n\t\t\t\tcurrentMatch.current &&\n\t\t\t\tnewMatch &&\n\t\t\t\tisShallowEqual(\n\t\t\t\t\tnewMatch.params,\n\t\t\t\t\tcurrentMatch.current.params\n\t\t\t\t) &&\n\t\t\t\tnewMatch.id === currentMatch.current.id\n\t\t\t) {\n\t\t\t\treturn currentMatch.current;\n\t\t\t}\n\n\t\t\treturn newMatch;\n\t\t};\n\n\t\tconst newMatch = resolvePath( currentPath );\n\t\tcurrentMatch.current = newMatch;\n\t\treturn newMatch;\n\t}, [ screens, locationHistory ] );\n\n\tconst addScreen = useCallback(\n\t\t( screen: Screen ) => dispatch( { type: 'add', screen } ),\n\t\t[]\n\t);\n\n\tconst removeScreen = useCallback(\n\t\t( screen: Screen ) => dispatch( { type: 'remove', screen } ),\n\t\t[]\n\t);\n\n\tconst goBack: NavigatorContextType[ 'goBack' ] = useCallback( () => {\n\t\tsetLocationHistory( ( prevLocationHistory ) => {\n\t\t\tif ( prevLocationHistory.length <= 1 ) {\n\t\t\t\treturn prevLocationHistory;\n\t\t\t}\n\t\t\treturn [\n\t\t\t\t...prevLocationHistory.slice( 0, -2 ),\n\t\t\t\t{\n\t\t\t\t\t...prevLocationHistory[ prevLocationHistory.length - 2 ],\n\t\t\t\t\tisBack: true,\n\t\t\t\t\thasRestoredFocus: false,\n\t\t\t\t},\n\t\t\t];\n\t\t} );\n\t}, [] );\n\n\tconst goTo: NavigatorContextType[ 'goTo' ] = useCallback(\n\t\t( path, options = {} ) => {\n\t\t\tconst {\n\t\t\t\tfocusTargetSelector,\n\t\t\t\tisBack = false,\n\t\t\t\tskipFocus = false,\n\t\t\t\treplace = false,\n\t\t\t\t...restOptions\n\t\t\t} = options;\n\n\t\t\tconst isNavigatingToPreviousPath =\n\t\t\t\tisBack &&\n\t\t\t\tcurrentLocationHistory.current.length > 1 &&\n\t\t\t\tcurrentLocationHistory.current[\n\t\t\t\t\tcurrentLocationHistory.current.length - 2\n\t\t\t\t].path === path;\n\n\t\t\tif ( isNavigatingToPreviousPath ) {\n\t\t\t\tgoBack();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetLocationHistory( ( prevLocationHistory ) => {\n\t\t\t\tconst newLocation = {\n\t\t\t\t\t...restOptions,\n\t\t\t\t\tpath,\n\t\t\t\t\tisBack,\n\t\t\t\t\thasRestoredFocus: false,\n\t\t\t\t\tskipFocus,\n\t\t\t\t};\n\n\t\t\t\tif ( prevLocationHistory.length === 0 ) {\n\t\t\t\t\treturn replace ? [] : [ newLocation ];\n\t\t\t\t}\n\n\t\t\t\tconst newLocationHistory = prevLocationHistory.slice(\n\t\t\t\t\tprevLocationHistory.length > MAX_HISTORY_LENGTH - 1 ? 1 : 0,\n\t\t\t\t\t-1\n\t\t\t\t);\n\n\t\t\t\tif ( ! replace ) {\n\t\t\t\t\tnewLocationHistory.push(\n\t\t\t\t\t\t// Assign `focusTargetSelector` to the previous location in history\n\t\t\t\t\t\t// (the one we just navigated from).\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...prevLocationHistory[\n\t\t\t\t\t\t\t\tprevLocationHistory.length - 1\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tfocusTargetSelector,\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tnewLocationHistory.push( newLocation );\n\n\t\t\t\treturn newLocationHistory;\n\t\t\t} );\n\t\t},\n\t\t[ goBack ]\n\t);\n\n\tconst goToParent: NavigatorContextType[ 'goToParent' ] = useCallback(\n\t\t( options = {} ) => {\n\t\t\tconst currentPath =\n\t\t\t\tcurrentLocationHistory.current[\n\t\t\t\t\tcurrentLocationHistory.current.length - 1\n\t\t\t\t].path;\n\t\t\tif ( currentPath === undefined ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst parentPath = findParent(\n\t\t\t\tcurrentPath,\n\t\t\t\tcurrentScreens.current\n\t\t\t);\n\t\t\tif ( parentPath === undefined ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tgoTo( parentPath, { ...options, isBack: true } );\n\t\t},\n\t\t[ goTo ]\n\t);\n\n\tconst navigatorContextValue: NavigatorContextType = useMemo(\n\t\t() => ( {\n\t\t\tlocation: {\n\t\t\t\t...locationHistory[ locationHistory.length - 1 ],\n\t\t\t\tisInitial: locationHistory.length === 1,\n\t\t\t},\n\t\t\tparams: matchedPath ? matchedPath.params : {},\n\t\t\tmatch: matchedPath ? matchedPath.id : undefined,\n\t\t\tgoTo,\n\t\t\tgoBack,\n\t\t\tgoToParent,\n\t\t\taddScreen,\n\t\t\tremoveScreen,\n\t\t} ),\n\t\t[\n\t\t\tlocationHistory,\n\t\t\tmatchedPath,\n\t\t\tgoTo,\n\t\t\tgoBack,\n\t\t\tgoToParent,\n\t\t\taddScreen,\n\t\t\tremoveScreen,\n\t\t]\n\t);\n\n\tconst cx = useCx();\n\tconst classes = useMemo(\n\t\t() => cx( styles.navigatorProviderWrapper, className ),\n\t\t[ className, cx ]\n\t);\n\n\treturn (\n\t\t<View ref={ forwardedRef } className={ classes } { ...otherProps }>\n\t\t\t<NavigatorContext.Provider value={ navigatorContextValue }>\n\t\t\t\t{ children }\n\t\t\t</NavigatorContext.Provider>\n\t\t</View>\n\t);\n}\n\n/**\n * The `NavigatorProvider` component allows rendering nested views/panels/menus\n * (via the `NavigatorScreen` component and navigate between these different\n * view (via the `NavigatorButton` and `NavigatorBackButton` components or the\n * `useNavigator` hook).\n *\n * ```jsx\n * import {\n * __experimentalNavigatorProvider as NavigatorProvider,\n * __experimentalNavigatorScreen as NavigatorScreen,\n * __experimentalNavigatorButton as NavigatorButton,\n * __experimentalNavigatorBackButton as NavigatorBackButton,\n * } from '@wordpress/components';\n *\n * const MyNavigation = () => (\n * <NavigatorProvider initialPath=\"/\">\n * <NavigatorScreen path=\"/\">\n * <p>This is the home screen.</p>\n * <NavigatorButton path=\"/child\">\n * Navigate to child screen.\n * </NavigatorButton>\n * </NavigatorScreen>\n *\n * <NavigatorScreen path=\"/child\">\n * <p>This is the child screen.</p>\n * <NavigatorBackButton>\n * Go back\n * </NavigatorBackButton>\n * </NavigatorScreen>\n * </NavigatorProvider>\n * );\n * ```\n */\nexport const NavigatorProvider = contextConnect(\n\tUnconnectedNavigatorProvider,\n\t'NavigatorProvider'\n);\n\nexport default NavigatorProvider;\n"],"mappings":";;;;;;;;AAQA,IAAAA,QAAA,GAAAC,OAAA;AAQA,IAAAC,eAAA,GAAAC,sBAAA,CAAAF,OAAA;AAMA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,SAAA,GAAAP,OAAA;AACA,IAAAQ,MAAA,GAAAC,uBAAA,CAAAT,OAAA;AAAoC,SAAAU,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CA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AAMkC,EAAE,CAAExF,MAAM,CAAC2F,wBAAwB,EAAEtD,SAAU,CAAC,EACtD,CAAEA,SAAS,EAAEmD,EAAE,CAChB,CAAC;EAED,OACC,IAAAI,MAAA,CAAAC,aAAA,EAAC/F,KAAA,CAAAgG,IAAI;IAACC,GAAG,EAAG7D,YAAc;IAACG,SAAS,EAAGqD,OAAS;IAAA,GAAMpD;EAAU,GAC/D,IAAAsD,MAAA,CAAAC,aAAA,EAAC9F,SAAA,CAAAiG,gBAAgB,CAACC,QAAQ;IAACC,KAAK,EAAGd;EAAuB,GACvDhD,QACwB,CACtB,CAAC;AAET;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM+D,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA,GAAG,IAAAE,uBAAc,EAC9CrE,4BAA4B,EAC5B,mBACD,CAAC;AAAC,IAAAsE,QAAA,GAAAF,OAAA,CAAA5F,OAAA,GAEa2F,iBAAiB"}
1
+ {"version":3,"names":["_element","require","_isShallowEqual","_interopRequireDefault","_context","_useCx","_router","_view","_context2","styles","_interopRequireWildcard","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","MAX_HISTORY_LENGTH","addScreen","screens","screen","removeScreen","filter","s","id","goBack","locationHistory","length","slice","isBack","hasRestoredFocus","goTo","state","path","options","focusTargetSelector","skipFocus","replace","restOptions","isNavigatingToPreviousPath","newLocation","newLocationHistory","push","goToParent","currentPath","undefined","parentPath","findParent","routerReducer","action","matchedPath","type","patternMatch","isShallowEqual","params","UnconnectedNavigatorProvider","props","forwardedRef","initialPath","children","className","otherProps","useContextSystem","routerState","dispatch","useReducer","methods","useMemo","navigatorContextValue","_matchedPath$params","location","isInitial","match","cx","useCx","classes","navigatorProviderWrapper","_react","createElement","View","ref","NavigatorContext","Provider","value","NavigatorProvider","exports","contextConnect","_default"],"sources":["@wordpress/components/src/navigator/navigator-provider/component.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useMemo, useReducer } from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport type { WordPressComponentProps } from '../../context';\nimport { contextConnect, useContextSystem } from '../../context';\nimport { useCx } from '../../utils/hooks/use-cx';\nimport { patternMatch, findParent } from '../utils/router';\nimport { View } from '../../view';\nimport { NavigatorContext } from '../context';\nimport * as styles from '../styles';\nimport type {\n\tNavigatorProviderProps,\n\tNavigatorLocation,\n\tNavigatorContext as NavigatorContextType,\n\tNavigateOptions,\n\tScreen,\n\tNavigateToParentOptions,\n} from '../types';\n\ntype MatchedPath = ReturnType< typeof patternMatch >;\n\ntype RouterAction =\n\t| { type: 'add' | 'remove'; screen: Screen }\n\t| { type: 'goback' }\n\t| { type: 'goto'; path: string; options?: NavigateOptions }\n\t| { type: 'gotoparent'; options?: NavigateToParentOptions };\n\ntype RouterState = {\n\tscreens: Screen[];\n\tlocationHistory: NavigatorLocation[];\n\tmatchedPath: MatchedPath;\n};\n\nconst MAX_HISTORY_LENGTH = 50;\n\nfunction addScreen( { screens }: RouterState, screen: Screen ) {\n\treturn [ ...screens, screen ];\n}\n\nfunction removeScreen( { screens }: RouterState, screen: Screen ) {\n\treturn screens.filter( ( s ) => s.id !== screen.id );\n}\n\nfunction goBack( { locationHistory }: RouterState ) {\n\tif ( locationHistory.length <= 1 ) {\n\t\treturn locationHistory;\n\t}\n\treturn [\n\t\t...locationHistory.slice( 0, -2 ),\n\t\t{\n\t\t\t...locationHistory[ locationHistory.length - 2 ],\n\t\t\tisBack: true,\n\t\t\thasRestoredFocus: false,\n\t\t},\n\t];\n}\n\nfunction goTo(\n\tstate: RouterState,\n\tpath: string,\n\toptions: NavigateOptions = {}\n) {\n\tconst { locationHistory } = state;\n\tconst {\n\t\tfocusTargetSelector,\n\t\tisBack = false,\n\t\tskipFocus = false,\n\t\treplace = false,\n\t\t...restOptions\n\t} = options;\n\n\tconst isNavigatingToPreviousPath =\n\t\tisBack &&\n\t\tlocationHistory.length > 1 &&\n\t\tlocationHistory[ locationHistory.length - 2 ].path === path;\n\n\tif ( isNavigatingToPreviousPath ) {\n\t\treturn goBack( state );\n\t}\n\n\tconst newLocation = {\n\t\t...restOptions,\n\t\tpath,\n\t\tisBack,\n\t\thasRestoredFocus: false,\n\t\tskipFocus,\n\t};\n\n\tif ( locationHistory.length === 0 ) {\n\t\treturn replace ? [] : [ newLocation ];\n\t}\n\n\tconst newLocationHistory = locationHistory.slice(\n\t\tlocationHistory.length > MAX_HISTORY_LENGTH - 1 ? 1 : 0,\n\t\t-1\n\t);\n\n\tif ( ! replace ) {\n\t\tnewLocationHistory.push(\n\t\t\t// Assign `focusTargetSelector` to the previous location in history\n\t\t\t// (the one we just navigated from).\n\t\t\t{\n\t\t\t\t...locationHistory[ locationHistory.length - 1 ],\n\t\t\t\tfocusTargetSelector,\n\t\t\t}\n\t\t);\n\t}\n\n\tnewLocationHistory.push( newLocation );\n\n\treturn newLocationHistory;\n}\n\nfunction goToParent(\n\tstate: RouterState,\n\toptions: NavigateToParentOptions = {}\n) {\n\tconst { locationHistory, screens } = state;\n\tconst currentPath = locationHistory[ locationHistory.length - 1 ].path;\n\tif ( currentPath === undefined ) {\n\t\treturn locationHistory;\n\t}\n\tconst parentPath = findParent( currentPath, screens );\n\tif ( parentPath === undefined ) {\n\t\treturn locationHistory;\n\t}\n\treturn goTo( state, parentPath, {\n\t\t...options,\n\t\tisBack: true,\n\t} );\n}\n\nfunction routerReducer(\n\tstate: RouterState,\n\taction: RouterAction\n): RouterState {\n\tlet { screens, locationHistory, matchedPath } = state;\n\n\tswitch ( action.type ) {\n\t\tcase 'add':\n\t\t\tscreens = addScreen( state, action.screen );\n\t\t\tbreak;\n\t\tcase 'remove':\n\t\t\tscreens = removeScreen( state, action.screen );\n\t\t\tbreak;\n\t\tcase 'goback':\n\t\t\tlocationHistory = goBack( state );\n\t\t\tbreak;\n\t\tcase 'goto':\n\t\t\tlocationHistory = goTo( state, action.path, action.options );\n\t\t\tbreak;\n\t\tcase 'gotoparent':\n\t\t\tlocationHistory = goToParent( state, action.options );\n\t\t\tbreak;\n\t}\n\n\t// Return early in case there is no change\n\tif (\n\t\tscreens === state.screens &&\n\t\tlocationHistory === state.locationHistory\n\t) {\n\t\treturn state;\n\t}\n\n\t// Compute the matchedPath\n\tconst currentPath =\n\t\tlocationHistory.length > 0\n\t\t\t? locationHistory[ locationHistory.length - 1 ].path\n\t\t\t: undefined;\n\tmatchedPath =\n\t\tcurrentPath !== undefined\n\t\t\t? patternMatch( currentPath, screens )\n\t\t\t: undefined;\n\n\t// If the new match is the same as the previous match,\n\t// return the previous one to keep immutability.\n\tif (\n\t\tmatchedPath &&\n\t\tstate.matchedPath &&\n\t\tmatchedPath.id === state.matchedPath.id &&\n\t\tisShallowEqual( matchedPath.params, state.matchedPath.params )\n\t) {\n\t\tmatchedPath = state.matchedPath;\n\t}\n\n\treturn { screens, locationHistory, matchedPath };\n}\n\nfunction UnconnectedNavigatorProvider(\n\tprops: WordPressComponentProps< NavigatorProviderProps, 'div' >,\n\tforwardedRef: ForwardedRef< any >\n) {\n\tconst { initialPath, children, className, ...otherProps } =\n\t\tuseContextSystem( props, 'NavigatorProvider' );\n\n\tconst [ routerState, dispatch ] = useReducer(\n\t\trouterReducer,\n\t\tinitialPath,\n\t\t( path ) => ( {\n\t\t\tscreens: [],\n\t\t\tlocationHistory: [ { path } ],\n\t\t\tmatchedPath: undefined,\n\t\t} )\n\t);\n\n\t// The methods are constant forever, create stable references to them.\n\tconst methods = useMemo(\n\t\t() => ( {\n\t\t\tgoBack: () => dispatch( { type: 'goback' } ),\n\t\t\tgoTo: ( path: string, options?: NavigateOptions ) =>\n\t\t\t\tdispatch( { type: 'goto', path, options } ),\n\t\t\tgoToParent: ( options: NavigateToParentOptions | undefined ) =>\n\t\t\t\tdispatch( { type: 'gotoparent', options } ),\n\t\t\taddScreen: ( screen: Screen ) =>\n\t\t\t\tdispatch( { type: 'add', screen } ),\n\t\t\tremoveScreen: ( screen: Screen ) =>\n\t\t\t\tdispatch( { type: 'remove', screen } ),\n\t\t} ),\n\t\t[]\n\t);\n\n\tconst { locationHistory, matchedPath } = routerState;\n\n\tconst navigatorContextValue: NavigatorContextType = useMemo(\n\t\t() => ( {\n\t\t\tlocation: {\n\t\t\t\t...locationHistory[ locationHistory.length - 1 ],\n\t\t\t\tisInitial: locationHistory.length === 1,\n\t\t\t},\n\t\t\tparams: matchedPath?.params ?? {},\n\t\t\tmatch: matchedPath?.id,\n\t\t\t...methods,\n\t\t} ),\n\t\t[ locationHistory, matchedPath, methods ]\n\t);\n\n\tconst cx = useCx();\n\tconst classes = useMemo(\n\t\t() => cx( styles.navigatorProviderWrapper, className ),\n\t\t[ className, cx ]\n\t);\n\n\treturn (\n\t\t<View ref={ forwardedRef } className={ classes } { ...otherProps }>\n\t\t\t<NavigatorContext.Provider value={ navigatorContextValue }>\n\t\t\t\t{ children }\n\t\t\t</NavigatorContext.Provider>\n\t\t</View>\n\t);\n}\n\n/**\n * The `NavigatorProvider` component allows rendering nested views/panels/menus\n * (via the `NavigatorScreen` component and navigate between these different\n * view (via the `NavigatorButton` and `NavigatorBackButton` components or the\n * `useNavigator` hook).\n *\n * ```jsx\n * import {\n * __experimentalNavigatorProvider as NavigatorProvider,\n * __experimentalNavigatorScreen as NavigatorScreen,\n * __experimentalNavigatorButton as NavigatorButton,\n * __experimentalNavigatorBackButton as NavigatorBackButton,\n * } from '@wordpress/components';\n *\n * const MyNavigation = () => (\n * <NavigatorProvider initialPath=\"/\">\n * <NavigatorScreen path=\"/\">\n * <p>This is the home screen.</p>\n * <NavigatorButton path=\"/child\">\n * Navigate to child screen.\n * </NavigatorButton>\n * </NavigatorScreen>\n *\n * <NavigatorScreen path=\"/child\">\n * <p>This is the child screen.</p>\n * <NavigatorBackButton>\n * Go back\n * </NavigatorBackButton>\n * </NavigatorScreen>\n * </NavigatorProvider>\n * );\n * ```\n */\nexport const NavigatorProvider = contextConnect(\n\tUnconnectedNavigatorProvider,\n\t'NavigatorProvider'\n);\n\nexport default NavigatorProvider;\n"],"mappings":";;;;;;;;AAQA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAC,sBAAA,CAAAF,OAAA;AAMA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,SAAA,GAAAP,OAAA;AACA,IAAAQ,MAAA,GAAAC,uBAAA,CAAAT,OAAA;AAAoC,SAAAU,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAF,wBAAAE,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cA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GACvDT,QACwB,CACtB,CAAC;AAET;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMyB,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA,GAAG,IAAAE,uBAAc,EAC9C/B,4BAA4B,EAC5B,mBACD,CAAC;AAAC,IAAAgC,QAAA,GAAAF,OAAA,CAAAnF,OAAA,GAEakF,iBAAiB"}
@@ -88,14 +88,14 @@ function UnconnectedNavigatorScreen(props, forwardedRef) {
88
88
 
89
89
  // When navigating back, if a selector is provided, use it to look for the
90
90
  // target element (assumed to be a node inside the current NavigatorScreen)
91
- if (location.isBack && location?.focusTargetSelector) {
91
+ if (location.isBack && location.focusTargetSelector) {
92
92
  elementToFocus = wrapperRef.current.querySelector(location.focusTargetSelector);
93
93
  }
94
94
 
95
95
  // If the previous query didn't run or find any element to focus, fallback
96
96
  // to the first tabbable element in the screen (or the screen itself).
97
97
  if (!elementToFocus) {
98
- const firstTabbable = _dom.focus.tabbable.find(wrapperRef.current)[0];
98
+ const [firstTabbable] = _dom.focus.tabbable.find(wrapperRef.current);
99
99
  elementToFocus = firstTabbable !== null && firstTabbable !== void 0 ? firstTabbable : wrapperRef.current;
100
100
  }
101
101
  locationRef.current.hasRestoredFocus = true;