@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.
- package/CHANGELOG.md +24 -0
- package/README.md +13 -0
- package/build/button/index.js +1 -1
- package/build/button/index.js.map +1 -1
- package/build/color-picker/component.js +2 -12
- package/build/color-picker/component.js.map +1 -1
- package/build/color-picker/picker.js +18 -77
- package/build/color-picker/picker.js.map +1 -1
- package/build/color-picker/types.js.map +1 -1
- package/build/custom-select-control-v2/default-component/index.js +4 -2
- package/build/custom-select-control-v2/default-component/index.js.map +1 -1
- package/build/custom-select-control-v2/index.js +1 -8
- package/build/custom-select-control-v2/index.js.map +1 -1
- package/build/custom-select-control-v2/{custom-select-item.js → item.js} +2 -1
- package/build/custom-select-control-v2/{custom-select-item.js.map → item.js.map} +1 -1
- package/build/custom-select-control-v2/legacy-component/index.js +5 -5
- package/build/custom-select-control-v2/legacy-component/index.js.map +1 -1
- package/build/input-control/input-field.js +2 -1
- package/build/input-control/input-field.js.map +1 -1
- package/build/mobile/color-settings/palette.screen.native.js +1 -0
- package/build/mobile/color-settings/palette.screen.native.js.map +1 -1
- package/build/navigable-container/container.js.map +1 -1
- package/build/navigator/navigator-provider/component.js +162 -120
- package/build/navigator/navigator-provider/component.js.map +1 -1
- package/build/navigator/navigator-screen/component.js +2 -2
- package/build/navigator/navigator-screen/component.js.map +1 -1
- package/build/popover/index.js +7 -34
- package/build/popover/index.js.map +1 -1
- package/build/range-control/styles/range-control-styles.js +29 -29
- package/build/range-control/styles/range-control-styles.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control-option-base/component.js +1 -1
- package/build/toggle-group-control/toggle-group-control-option-base/component.js.map +1 -1
- package/build-module/button/index.js +1 -1
- package/build-module/button/index.js.map +1 -1
- package/build-module/color-picker/component.js +3 -13
- package/build-module/color-picker/component.js.map +1 -1
- package/build-module/color-picker/picker.js +19 -78
- package/build-module/color-picker/picker.js.map +1 -1
- package/build-module/color-picker/types.js.map +1 -1
- package/build-module/custom-select-control-v2/default-component/index.js +4 -2
- package/build-module/custom-select-control-v2/default-component/index.js.map +1 -1
- package/build-module/custom-select-control-v2/index.js +1 -2
- package/build-module/custom-select-control-v2/index.js.map +1 -1
- package/build-module/custom-select-control-v2/{custom-select-item.js → item.js} +2 -1
- package/build-module/custom-select-control-v2/{custom-select-item.js.map → item.js.map} +1 -1
- package/build-module/custom-select-control-v2/legacy-component/index.js +4 -4
- package/build-module/custom-select-control-v2/legacy-component/index.js.map +1 -1
- package/build-module/input-control/input-field.js +2 -1
- package/build-module/input-control/input-field.js.map +1 -1
- package/build-module/mobile/color-settings/palette.screen.native.js +1 -0
- package/build-module/mobile/color-settings/palette.screen.native.js.map +1 -1
- package/build-module/navigable-container/container.js.map +1 -1
- package/build-module/navigator/navigator-provider/component.js +163 -121
- package/build-module/navigator/navigator-provider/component.js.map +1 -1
- package/build-module/navigator/navigator-screen/component.js +2 -2
- package/build-module/navigator/navigator-screen/component.js.map +1 -1
- package/build-module/popover/index.js +9 -36
- package/build-module/popover/index.js.map +1 -1
- package/build-module/range-control/styles/range-control-styles.js +29 -29
- package/build-module/range-control/styles/range-control-styles.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control-option-base/component.js +2 -2
- package/build-module/toggle-group-control/toggle-group-control-option-base/component.js.map +1 -1
- package/build-style/style-rtl.css +2 -8
- package/build-style/style.css +2 -8
- package/build-types/color-picker/component.d.ts.map +1 -1
- package/build-types/color-picker/picker.d.ts +1 -1
- package/build-types/color-picker/picker.d.ts.map +1 -1
- package/build-types/color-picker/types.d.ts +0 -3
- package/build-types/color-picker/types.d.ts.map +1 -1
- package/build-types/custom-select-control/stories/index.story.d.ts +35 -0
- package/build-types/custom-select-control/stories/index.story.d.ts.map +1 -0
- package/build-types/custom-select-control-v2/default-component/index.d.ts +5 -2
- package/build-types/custom-select-control-v2/default-component/index.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/index.d.ts +1 -2
- package/build-types/custom-select-control-v2/index.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/{custom-select-item.d.ts → item.d.ts} +4 -1
- package/build-types/custom-select-control-v2/item.d.ts.map +1 -0
- package/build-types/custom-select-control-v2/legacy-component/index.d.ts +2 -2
- package/build-types/custom-select-control-v2/legacy-component/index.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/stories/default.story.d.ts +2 -2
- package/build-types/custom-select-control-v2/stories/default.story.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/stories/legacy.story.d.ts +4 -2
- package/build-types/custom-select-control-v2/stories/legacy.story.d.ts.map +1 -1
- package/build-types/input-control/input-field.d.ts.map +1 -1
- package/build-types/navigator/navigator-provider/component.d.ts.map +1 -1
- package/build-types/navigator/navigator-screen/component.d.ts.map +1 -1
- package/build-types/popover/index.d.ts.map +1 -1
- package/package.json +21 -21
- package/src/button/index.tsx +1 -1
- package/src/color-picker/component.tsx +3 -25
- package/src/color-picker/picker.tsx +12 -96
- package/src/color-picker/types.ts +0 -3
- package/src/custom-select-control/stories/{index.story.js → index.story.tsx} +8 -3
- package/src/custom-select-control/test/index.js +24 -0
- package/src/custom-select-control-v2/README.md +27 -27
- package/src/custom-select-control-v2/default-component/index.tsx +5 -2
- package/src/custom-select-control-v2/index.tsx +1 -2
- package/src/custom-select-control-v2/{custom-select-item.tsx → item.tsx} +2 -0
- package/src/custom-select-control-v2/legacy-component/index.tsx +4 -6
- package/src/custom-select-control-v2/legacy-component/test/index.tsx +13 -10
- package/src/custom-select-control-v2/stories/default.story.tsx +16 -17
- package/src/custom-select-control-v2/stories/legacy.story.tsx +20 -35
- package/src/custom-select-control-v2/test/index.tsx +26 -16
- package/src/dropdown/style.scss +3 -3
- package/src/input-control/input-field.tsx +2 -1
- package/src/mobile/color-settings/palette.screen.native.js +5 -1
- package/src/navigable-container/container.tsx +1 -1
- package/src/navigator/navigator-provider/component.tsx +187 -188
- package/src/navigator/navigator-screen/component.tsx +2 -4
- package/src/popover/index.tsx +59 -99
- package/src/popover/style.scss +0 -9
- package/src/range-control/styles/range-control-styles.ts +1 -1
- package/src/text-control/style.scss +2 -0
- package/src/toggle-group-control/toggle-group-control-option-base/component.tsx +2 -2
- package/src/toolbar/toolbar/style.scss +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/build-types/custom-select-control-v2/custom-select-item.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Ariakit","useMemo","_CustomSelect","CustomSelectItem","Styled","ContextSystemProvider","
|
|
1
|
+
{"version":3,"names":["Ariakit","useMemo","_CustomSelect","CustomSelectItem","Styled","ContextSystemProvider","CustomSelectControl","props","__experimentalShowSelectedHint","__next40pxDefaultSize","options","onChange","size","value","restProps","store","useSelectStore","setValue","nextValue","Promise","resolve","state","getState","changeObject","highlightedIndex","renderedItems","findIndex","item","inputValue","isOpen","open","selectedItem","name","key","type","children","map","__experimentalHint","rest","withHint","createElement","WithHintWrapper","ExperimentalHintItem","className","renderSelectedValueHint","currentValue","currentHint","find","Fragment","SelectedExperimentalHintItem","contextSystemValue","selectedSize","CustomSelectControlButton","_overrides","translatedProps","describedBy","renderSelectedValue","undefined"],"sources":["@wordpress/components/src/custom-select-control-v2/legacy-component/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\n// eslint-disable-next-line no-restricted-imports\nimport * as Ariakit from '@ariakit/react';\n/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\n/**\n * Internal dependencies\n */\nimport _CustomSelect from '../custom-select';\nimport CustomSelectItem from '../item';\nimport type { LegacyCustomSelectProps } from '../types';\nimport * as Styled from '../styles';\nimport { ContextSystemProvider } from '../../context';\n\nfunction CustomSelectControl( props: LegacyCustomSelectProps ) {\n\tconst {\n\t\t__experimentalShowSelectedHint,\n\t\t__next40pxDefaultSize = false,\n\t\toptions,\n\t\tonChange,\n\t\tsize = 'default',\n\t\tvalue,\n\t\t...restProps\n\t} = props;\n\n\t// Forward props + store from v2 implementation\n\tconst store = Ariakit.useSelectStore( {\n\t\tasync setValue( nextValue ) {\n\t\t\tif ( ! onChange ) return;\n\n\t\t\t// Executes the logic in a microtask after the popup is closed.\n\t\t\t// This is simply to ensure the isOpen state matches that in Downshift.\n\t\t\tawait Promise.resolve();\n\t\t\tconst state = store.getState();\n\n\t\t\tconst changeObject = {\n\t\t\t\thighlightedIndex: state.renderedItems.findIndex(\n\t\t\t\t\t( item ) => item.value === nextValue\n\t\t\t\t),\n\t\t\t\tinputValue: '',\n\t\t\t\tisOpen: state.open,\n\t\t\t\tselectedItem: {\n\t\t\t\t\tname: nextValue as string,\n\t\t\t\t\tkey: nextValue as string,\n\t\t\t\t},\n\t\t\t\ttype: '',\n\t\t\t};\n\t\t\tonChange( changeObject );\n\t\t},\n\t} );\n\n\tconst children = options.map(\n\t\t( { name, key, __experimentalHint, ...rest } ) => {\n\t\t\tconst withHint = (\n\t\t\t\t<Styled.WithHintWrapper>\n\t\t\t\t\t<span>{ name }</span>\n\t\t\t\t\t<Styled.ExperimentalHintItem className=\"components-custom-select-control__item-hint\">\n\t\t\t\t\t\t{ __experimentalHint }\n\t\t\t\t\t</Styled.ExperimentalHintItem>\n\t\t\t\t</Styled.WithHintWrapper>\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t<CustomSelectItem\n\t\t\t\t\tkey={ key }\n\t\t\t\t\tvalue={ name }\n\t\t\t\t\tchildren={ __experimentalHint ? withHint : name }\n\t\t\t\t\t{ ...rest }\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\t);\n\n\tconst renderSelectedValueHint = () => {\n\t\tconst { value: currentValue } = store.getState();\n\n\t\tconst currentHint = options?.find(\n\t\t\t( { name } ) => currentValue === name\n\t\t);\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ currentValue }\n\t\t\t\t<Styled.SelectedExperimentalHintItem className=\"components-custom-select-control__hint\">\n\t\t\t\t\t{ currentHint?.__experimentalHint }\n\t\t\t\t</Styled.SelectedExperimentalHintItem>\n\t\t\t</>\n\t\t);\n\t};\n\n\t// translate legacy button sizing\n\tconst contextSystemValue = useMemo( () => {\n\t\tlet selectedSize;\n\n\t\tif (\n\t\t\t( __next40pxDefaultSize && size === 'default' ) ||\n\t\t\tsize === '__unstable-large'\n\t\t) {\n\t\t\tselectedSize = 'default';\n\t\t} else if ( ! __next40pxDefaultSize && size === 'default' ) {\n\t\t\tselectedSize = 'compact';\n\t\t} else {\n\t\t\tselectedSize = size;\n\t\t}\n\n\t\treturn {\n\t\t\tCustomSelectControlButton: { _overrides: { size: selectedSize } },\n\t\t};\n\t}, [ __next40pxDefaultSize, size ] );\n\n\tconst translatedProps = {\n\t\t'aria-describedby': props.describedBy,\n\t\tchildren,\n\t\trenderSelectedValue: __experimentalShowSelectedHint\n\t\t\t? renderSelectedValueHint\n\t\t\t: undefined,\n\t\t...restProps,\n\t};\n\n\treturn (\n\t\t<ContextSystemProvider value={ contextSystemValue }>\n\t\t\t<_CustomSelect { ...translatedProps } store={ store } />\n\t\t</ContextSystemProvider>\n\t);\n}\n\nexport default CustomSelectControl;\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC;AACA;AACA;AACA,SAASC,OAAO,QAAQ,oBAAoB;AAC5C;AACA;AACA;AACA,OAAOC,aAAa,MAAM,kBAAkB;AAC5C,OAAOC,gBAAgB,MAAM,SAAS;AAEtC,OAAO,KAAKC,MAAM,MAAM,WAAW;AACnC,SAASC,qBAAqB,QAAQ,eAAe;AAErD,SAASC,mBAAmBA,CAAEC,KAA8B,EAAG;EAC9D,MAAM;IACLC,8BAA8B;IAC9BC,qBAAqB,GAAG,KAAK;IAC7BC,OAAO;IACPC,QAAQ;IACRC,IAAI,GAAG,SAAS;IAChBC,KAAK;IACL,GAAGC;EACJ,CAAC,GAAGP,KAAK;;EAET;EACA,MAAMQ,KAAK,GAAGf,OAAO,CAACgB,cAAc,CAAE;IACrC,MAAMC,QAAQA,CAAEC,SAAS,EAAG;MAC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KAAMa,YAAY,KAAKb,IAClC,CAAC;IAED,OACCQ,aAAA,CAAAQ,QAAA,QACGH,YAAY,EACdL,aAAA,CAACpC,MAAM,CAAC6C,4BAA4B;MAACN,SAAS,EAAC;IAAwC,GACpFG,WAAW,EAAET,kBACqB,CACpC,CAAC;EAEL,CAAC;;EAED;EACA,MAAMa,kBAAkB,GAAGjD,OAAO,CAAE,MAAM;IACzC,IAAIkD,YAAY;IAEhB,IACG1C,qBAAqB,IAAIG,IAAI,KAAK,SAAS,IAC7CA,IAAI,KAAK,kBAAkB,EAC1B;MACDuC,YAAY,GAAG,SAAS;IACzB,CAAC,MAAM,IAAK,CAAE1C,qBAAqB,IAAIG,IAAI,KAAK,SAAS,EAAG;MAC3DuC,YAAY,GAAG,SAAS;IACzB,CAAC,MAAM;MACNA,YAAY,GAAGvC,IAAI;IACpB;IAEA,OAAO;MACNwC,yBAAyB,EAAE;QAAEC,UAAU,EAAE;UAAEzC,IAAI,EAAEuC;QAAa;MAAE;IACjE,CAAC;EACF,CAAC,EAAE,CAAE1C,qBAAqB,EAAEG,IAAI,CAAG,CAAC;EAEpC,MAAM0C,eAAe,GAAG;IACvB,kBAAkB,EAAE/C,KAAK,CAACgD,WAAW;IACrCpB,QAAQ;IACRqB,mBAAmB,EAAEhD,8BAA8B,GAChDoC,uBAAuB,GACvBa,SAAS;IACZ,GAAG3C;EACJ,CAAC;EAED,OACC0B,aAAA,CAACnC,qBAAqB;IAACQ,KAAK,EAAGqC;EAAoB,GAClDV,aAAA,CAACtC,aAAa;IAAA,GAAMoD,eAAe;IAAGvC,KAAK,EAAGA;EAAO,CAAE,CACjC,CAAC;AAE1B;AAEA,eAAeT,mBAAmB"}
|
|
@@ -14,6 +14,7 @@ import { forwardRef, useRef } from '@wordpress/element';
|
|
|
14
14
|
import { useDragCursor } from './utils';
|
|
15
15
|
import { Input } from './styles/input-control-styles';
|
|
16
16
|
import { useInputControlStateReducer } from './reducer/reducer';
|
|
17
|
+
import { withIgnoreIMEEvents } from '../utils/with-ignore-ime-events';
|
|
17
18
|
const noop = () => {};
|
|
18
19
|
function InputField({
|
|
19
20
|
disabled = false,
|
|
@@ -190,7 +191,7 @@ function InputField({
|
|
|
190
191
|
onBlur: handleOnBlur,
|
|
191
192
|
onChange: handleOnChange,
|
|
192
193
|
onFocus: handleOnFocus,
|
|
193
|
-
onKeyDown: handleOnKeyDown,
|
|
194
|
+
onKeyDown: withIgnoreIMEEvents(handleOnKeyDown),
|
|
194
195
|
onMouseDown: handleOnMouseDown,
|
|
195
196
|
ref: ref,
|
|
196
197
|
inputSize: size
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useDrag","forwardRef","useRef","useDragCursor","Input","useInputControlStateReducer","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","isDragging","isDirty","wasDirtyOnBlur","dragCursor","handleOnBlur","event","target","validity","valid","current","handleOnCommit","handleOnFocus","handleOnChange","nextValue","currentTarget","err","handleOnKeyDown","key","preventDefault","dragGestureProps","dragProps","distance","dragging","stopPropagation","axis","threshold","enabled","pointer","capture","handleOnMouseDown","onMouseDown","ownerDocument","activeElement","focus","createElement","className","inputSize","ForwardedComponent"],"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":";AAAA;AACA;AACA;AACA,SAASA,OAAO,QAAQ,oBAAoB;AAW5C;AACA;AACA;AACA,SAASC,UAAU,EAAEC,MAAM,QAAQ,oBAAoB;AACvD;AACA;AACA;;AAEA,SAASC,aAAa,QAAQ,SAAS;AACvC,SAASC,KAAK,QAAQ,+BAA+B;AACrD,SAASC,2BAA2B,QAAQ,mBAAmB;AAG/D,MAAMC,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,GAAGpC,2BAA2B,CAC9BoB,YAAY,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G,GAAG;IAChE0D,SAAS,EAAEzD,aAAa;IACxB0D,OAAO,EAAExD,aAAa;IACtByD,OAAO,EAAE;MAAEC,OAAO,EAAE;IAAM;EAC3B,CACD,CAAC;EAED,MAAMR,SAAS,GAAGlD,aAAa,GAAGiD,gBAAgB,CAAC,CAAC,GAAG,CAAC,CAAC;EACzD;AACD;AACA;AACA;EACC,IAAIU,iBAAiB;EACrB,IAAK1C,IAAI,KAAK,QAAQ,EAAG;IACxB0C,iBAAiB,GAAKxB,KAAqC,IAAM;MAChEjB,KAAK,CAAC0C,WAAW,GAAIzB,KAAM,CAAC;MAC5B,IACCA,KAAK,CAACS,aAAa,KACnBT,KAAK,CAACS,aAAa,CAACiB,aAAa,CAACC,aAAa,EAC9C;QACD3B,KAAK,CAACS,aAAa,CAACmB,KAAK,CAAC,CAAC;MAC5B;IACD,CAAC;EACF;EAEA,OACCC,aAAA,CAACxE,KAAK;IAAA,GACA0B,KAAK;IAAA,GACLgC,SAAS;IACde,SAAS,EAAC,iCAAiC;IAC3CrE,QAAQ,EAAGA,QAAU;IACrBqC,UAAU,EAAGA,UAAY;IACzBH,UAAU,EAAGA,UAAY;IACzB/B,EAAE,EAAGA,EAAI;IACTI,MAAM,EAAG+B,YAAc;IACvB9B,QAAQ,EAAGsC,cAAgB;IAC3BlC,OAAO,EAAGiC,aAAe;IACzBhC,SAAS,EAAGqC,eAAiB;IAC7Bc,WAAW,EAAGD,iBAAmB;IACjCxC,GAAG,EAAGA,GAAK;IACX+C,SAAS,EAAGvD;IACZ;IACA;IAAA;IACAI,KAAK,EAAGA,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,EAAI;IACrBE,IAAI,EAAGA;EAAM,CACb,CAAC;AAEJ;AAEA,MAAMkD,kBAAkB,GAAG9E,UAAU,CAAEM,UAAW,CAAC;AAEnD,eAAewE,kBAAkB"}
|
|
1
|
+
{"version":3,"names":["useDrag","forwardRef","useRef","useDragCursor","Input","useInputControlStateReducer","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","isDragging","isDirty","wasDirtyOnBlur","dragCursor","handleOnBlur","event","target","validity","valid","current","handleOnCommit","handleOnFocus","handleOnChange","nextValue","currentTarget","err","handleOnKeyDown","key","preventDefault","dragGestureProps","dragProps","distance","dragging","stopPropagation","axis","threshold","enabled","pointer","capture","handleOnMouseDown","onMouseDown","ownerDocument","activeElement","focus","createElement","className","inputSize","ForwardedComponent"],"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":";AAAA;AACA;AACA;AACA,SAASA,OAAO,QAAQ,oBAAoB;AAW5C;AACA;AACA;AACA,SAASC,UAAU,EAAEC,MAAM,QAAQ,oBAAoB;AACvD;AACA;AACA;;AAEA,SAASC,aAAa,QAAQ,SAAS;AACvC,SAASC,KAAK,QAAQ,+BA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IzB,KAAM,CAAC;MAC5B,IACCA,KAAK,CAACS,aAAa,KACnBT,KAAK,CAACS,aAAa,CAACiB,aAAa,CAACC,aAAa,EAC9C;QACD3B,KAAK,CAACS,aAAa,CAACmB,KAAK,CAAC,CAAC;MAC5B;IACD,CAAC;EACF;EAEA,OACCC,aAAA,CAACzE,KAAK;IAAA,GACA2B,KAAK;IAAA,GACLgC,SAAS;IACde,SAAS,EAAC,iCAAiC;IAC3CrE,QAAQ,EAAGA,QAAU;IACrBqC,UAAU,EAAGA,UAAY;IACzBH,UAAU,EAAGA,UAAY;IACzB/B,EAAE,EAAGA,EAAI;IACTI,MAAM,EAAG+B,YAAc;IACvB9B,QAAQ,EAAGsC,cAAgB;IAC3BlC,OAAO,EAAGiC,aAAe;IACzBhC,SAAS,EAAGhB,mBAAmB,CAAEqD,eAAgB,CAAG;IACpDc,WAAW,EAAGD,iBAAmB;IACjCxC,GAAG,EAAGA,GAAK;IACX+C,SAAS,EAAGvD;IACZ;IACA;IAAA;IACAI,KAAK,EAAGA,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,EAAI;IACrBE,IAAI,EAAGA;EAAM,CACb,CAAC;AAEJ;AAEA,MAAMkD,kBAAkB,GAAG/E,UAAU,CAAEO,UAAW,CAAC;AAEnD,eAAewE,kBAAkB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["View","Text","TouchableWithoutFeedback","__","useState","useContext","usePreferredColorSchemeStyle","ColorControl","PanelBody","BottomSheetContext","useMobileGlobalStylesColors","useRoute","useNavigation","ColorPalette","ColorIndicator","NavBar","SegmentedControls","colorsUtils","styles","HIT_SLOP","top","bottom","left","right","PaletteScreen","route","navigation","shouldEnableBottomSheetScroll","label","onColorChange","onGradientChange","onColorCleared","colorValue","defaultSettings","hideNavigation","params","segments","isGradient","currentValue","setCurrentValue","isGradientColor","selectedSegmentIndex","currentSegment","setCurrentSegment","isGradientSegment","currentSegmentColors","colors","gradients","allAvailableColors","allAvailableGradients","flatMap","filter","Boolean","horizontalSeparatorStyle","horizontalSeparator","horizontalSeparatorDark","clearButtonStyle","clearButton","clearButtonDark","selectedColorTextStyle","colorText","colorTextDark","isSolidSegment","isCustomGadientShown","setColor","color","onClear","undefined","onCustomPress","navigate","screens","picker","gradientPicker","getClearButton","createElement","onPress","hitSlop","style","clearButtonContainer","getFooter","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","withColorIndicator"],"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":";AAAA;AACA;AACA;AACA,SAASA,IAAI,EAAEC,IAAI,EAAEC,wBAAwB,QAAQ,cAAc;;AAEnE;AACA;AACA;AACA,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,QAAQ,EAAEC,UAAU,QAAQ,oBAAoB;AACzD,SAASC,4BAA4B,QAAQ,oBAAoB;AACjE,SACCC,YAAY,EACZC,SAAS,EACTC,kBAAkB,EAClBC,2BAA2B,QACrB,uBAAuB;AAC9B,SAASC,QAAQ,EAAEC,aAAa,QAAQ,0BAA0B;;AAElE;AACA;AACA;AACA,OAAOC,YAAY,MAAM,qBAAqB;AAC9C,OAAOC,cAAc,MAAM,uBAAuB;AAClD,OAAOC,MAAM,MAAM,yBAAyB;AAC5C,OAAOC,iBAAiB,MAAM,sBAAsB;AACpD,SAASC,WAAW,QAAQ,SAAS;AAErC,OAAOC,MAAM,MAAM,cAAc;AAEjC,MAAMC,QAAQ,GAAG;EAAEC,GAAG,EAAE,CAAC;EAAEC,MAAM,EAAE,CAAC;EAAEC,IAAI,EAAE,CAAC;EAAEC,KAAK,EAAE;AAAE,CAAC;AAEzD,MAAMC,aAAa,GAAGA,CAAA,KAAM;EAC3B,MAAMC,KAAK,GAAGd,QAAQ,CAAC,CAAC;EACxB,MAAMe,UAAU,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BAAkB,EAAG;EAAO,CAC5B,CACS,CACV,CACF,EACDjC,aAAA,CAAC1E,IAAI;IAAC6E,KAAK,EAAGxB;EAA0B,CAAE,CAAC,EACzC0B,SAAS,CAAC,CACP,CAAC;AAET,CAAC;AAED,eAAevD,aAAa"}
|
|
1
|
+
{"version":3,"names":["View","Text","TouchableWithoutFeedback","__","useState","useContext","usePreferredColorSchemeStyle","ColorControl","PanelBody","BottomSheetContext","useMobileGlobalStylesColors","useRoute","useNavigation","ColorPalette","ColorIndicator","NavBar","SegmentedControls","colorsUtils","styles","HIT_SLOP","top","bottom","left","right","PaletteScreen","route","navigation","shouldEnableBottomSheetScroll","label","onColorChange","onGradientChange","onColorCleared","colorValue","defaultSettings","hideNavigation","params","segments","isGradient","currentValue","setCurrentValue","isGradientColor","selectedSegmentIndex","currentSegment","setCurrentSegment","isGradientSegment","currentSegmentColors","colors","gradients","allAvailableColors","allAvailableGradients","flatMap","filter","Boolean","horizontalSeparatorStyle","horizontalSeparator","horizontalSeparatorDark","clearButtonStyle","clearButton","clearButtonDark","selectedColorTextStyle","colorText","colorTextDark","isSolidSegment","isCustomGadientShown","setColor","color","onClear","undefined","onCustomPress","navigate","screens","picker","gradientPicker","getClearButton","createElement","accessibilityLabel","onPress","hitSlop","style","clearButtonContainer","getFooter","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","withColorIndicator"],"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\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":";AAAA;AACA;AACA;AACA,SAASA,IAAI,EAAEC,IAAI,EAAEC,wBAAwB,QAAQ,cAAc;;AAEnE;AACA;AACA;AACA,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SA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;MAC7BsD,YAAY,EAAErD;IACf,CAAC;IACD;IACA,MAAMsD,iBAAiB,GAAGJ,UAAU,KAAK,CAAC;IAE1C,OACCzB,aAAA,CAAC7D,YAAY;MACZ0F,iBAAiB,EAAGA,iBAAmB;MACvC3E,KAAK,EAAGsE,OAAO,CAACM,IAAM;MACtBC,GAAG,EAAGN,UAAY;MAClBnC,QAAQ,EAAGA,QAAU;MACrB0C,WAAW,EAAGpE,YAAc;MAC5BE,eAAe,EAAGA,eAAiB;MACnCE,cAAc,EAAGA,cAAgB;MACjC0B,aAAa,EAAGA,aAAe;MAC/BzC,6BAA6B,EAC5BA,6BACA;MACDM,eAAe,EAAGmE;IAAiB,CACnC,CAAC;EAEJ,CAAE,CACG,CAAC,EAELrC,oBAAoB,IACrBW,aAAA,CAAAiC,QAAA,QACCjC,aAAA,CAAC1E,IAAI;IAAC8E,KAAK,EAAGzB;EAA0B,CAAE,CAAC,EAC3CqB,aAAA,CAAClE,SAAS,QACTkE,aAAA,CAACnE,YAAY;IACZqB,KAAK,EAAGzB,EAAE,CAAE,oBAAqB,CAAG;IACpCyE,OAAO,EAAGR,aAAe;IACzBwC,kBAAkB,EAAG;EAAO,CAC5B,CACS,CACV,CACF,EACDlC,aAAA,CAAC1E,IAAI;IAAC8E,KAAK,EAAGzB;EAA0B,CAAE,CAAC,EACzC2B,SAAS,CAAC,CACP,CAAC;AAET,CAAC;AAED,eAAexD,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Component","forwardRef","focus","noop","MENU_ITEM_ROLES","cycleValue","value","total","offset","nextValue","NavigableContainer","constructor","args","onKeyDown","bind","bindContainer","getFocusableContext","getFocusableIndex","componentDidMount","container","addEventListener","componentWillUnmount","removeEventListener","ref","forwardedRef","props","current","target","onlyBrowserTabstops","finder","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","createElement","forwardedNavigableContainer","displayName"],"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":";AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,UAAU,QAAQ,oBAAoB;AAC1D,SAASC,KAAK,QAAQ,gBAAgB;;AAEtC;AACA;AACA;;AAGA,MAAMC,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AACrB,MAAMC,eAAe,GAAG,CAAE,UAAU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MACRf,oBAAoB;MACpBF,aAAa;MACbC,UAAU;MACV1B,SAAS;MACTwB,KAAK;MACLT,mBAAmB;MACnBJ,YAAY;MACZ,GAAGgC;IACJ,CAAC,GAAG,IAAI,CAAC/B,KAAK;IACd,OACCgC,aAAA;MAAKlC,GAAG,EAAG,IAAI,CAACR,aAAe;MAAA,GAAMyC;IAAS,GAC3CD,QACE,CAAC;EAER;AACD;AAEA,MAAMG,2BAA2B,GAAGA,CACnCjC,KAA8B,EAC9BF,GAAmC,KAC/B;EACJ,OAAOkC,aAAA,CAAC/C,kBAAkB;IAAA,GAAMe,KAAK;IAAGD,YAAY,EAAGD;EAAK,CAAE,CAAC;AAChE,CAAC;AACDmC,2BAA2B,CAACC,WAAW,GAAG,oBAAoB;AAE9D,eAAe1D,UAAU,CAAEyD,2BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"names":["Component","forwardRef","focus","noop","MENU_ITEM_ROLES","cycleValue","value","total","offset","nextValue","NavigableContainer","constructor","args","onKeyDown","bind","bindContainer","getFocusableContext","getFocusableIndex","componentDidMount","container","addEventListener","componentWillUnmount","removeEventListener","ref","forwardedRef","props","current","target","onlyBrowserTabstops","finder","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","createElement","forwardedNavigableContainer","displayName"],"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":";AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,UAAU,QAAQ,oBAAoB;AAC1D,SAASC,KAAK,QAAQ,gBAAgB;;AAEtC;AACA;AACA;;AAGA,MAAMC,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,SAASV,SAAS,CAA4B;EAGrEW,WAAWA,CAAEC,IAA6B,EAA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AAE,CAAC;AAChE,CAAC;AACDmC,2BAA2B,CAACC,WAAW,GAAG,oBAAoB;AAE9D,eAAe1D,UAAU,CAAEyD,2BAA4B,CAAC"}
|
|
@@ -6,7 +6,7 @@ import { createElement } from "react";
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
|
-
import { useMemo,
|
|
9
|
+
import { useMemo, useReducer } from '@wordpress/element';
|
|
10
10
|
import isShallowEqual from '@wordpress/is-shallow-equal';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -20,14 +20,127 @@ import { View } from '../../view';
|
|
|
20
20
|
import { NavigatorContext } from '../context';
|
|
21
21
|
import * as styles from '../styles';
|
|
22
22
|
const MAX_HISTORY_LENGTH = 50;
|
|
23
|
-
function
|
|
23
|
+
function addScreen({
|
|
24
|
+
screens
|
|
25
|
+
}, screen) {
|
|
26
|
+
return [...screens, screen];
|
|
27
|
+
}
|
|
28
|
+
function removeScreen({
|
|
29
|
+
screens
|
|
30
|
+
}, screen) {
|
|
31
|
+
return screens.filter(s => s.id !== screen.id);
|
|
32
|
+
}
|
|
33
|
+
function goBack({
|
|
34
|
+
locationHistory
|
|
35
|
+
}) {
|
|
36
|
+
if (locationHistory.length <= 1) {
|
|
37
|
+
return locationHistory;
|
|
38
|
+
}
|
|
39
|
+
return [...locationHistory.slice(0, -2), {
|
|
40
|
+
...locationHistory[locationHistory.length - 2],
|
|
41
|
+
isBack: true,
|
|
42
|
+
hasRestoredFocus: false
|
|
43
|
+
}];
|
|
44
|
+
}
|
|
45
|
+
function goTo(state, path, options = {}) {
|
|
46
|
+
const {
|
|
47
|
+
locationHistory
|
|
48
|
+
} = state;
|
|
49
|
+
const {
|
|
50
|
+
focusTargetSelector,
|
|
51
|
+
isBack = false,
|
|
52
|
+
skipFocus = false,
|
|
53
|
+
replace = false,
|
|
54
|
+
...restOptions
|
|
55
|
+
} = options;
|
|
56
|
+
const isNavigatingToPreviousPath = isBack && locationHistory.length > 1 && locationHistory[locationHistory.length - 2].path === path;
|
|
57
|
+
if (isNavigatingToPreviousPath) {
|
|
58
|
+
return goBack(state);
|
|
59
|
+
}
|
|
60
|
+
const newLocation = {
|
|
61
|
+
...restOptions,
|
|
62
|
+
path,
|
|
63
|
+
isBack,
|
|
64
|
+
hasRestoredFocus: false,
|
|
65
|
+
skipFocus
|
|
66
|
+
};
|
|
67
|
+
if (locationHistory.length === 0) {
|
|
68
|
+
return replace ? [] : [newLocation];
|
|
69
|
+
}
|
|
70
|
+
const newLocationHistory = locationHistory.slice(locationHistory.length > MAX_HISTORY_LENGTH - 1 ? 1 : 0, -1);
|
|
71
|
+
if (!replace) {
|
|
72
|
+
newLocationHistory.push(
|
|
73
|
+
// Assign `focusTargetSelector` to the previous location in history
|
|
74
|
+
// (the one we just navigated from).
|
|
75
|
+
{
|
|
76
|
+
...locationHistory[locationHistory.length - 1],
|
|
77
|
+
focusTargetSelector
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
newLocationHistory.push(newLocation);
|
|
81
|
+
return newLocationHistory;
|
|
82
|
+
}
|
|
83
|
+
function goToParent(state, options = {}) {
|
|
84
|
+
const {
|
|
85
|
+
locationHistory,
|
|
86
|
+
screens
|
|
87
|
+
} = state;
|
|
88
|
+
const currentPath = locationHistory[locationHistory.length - 1].path;
|
|
89
|
+
if (currentPath === undefined) {
|
|
90
|
+
return locationHistory;
|
|
91
|
+
}
|
|
92
|
+
const parentPath = findParent(currentPath, screens);
|
|
93
|
+
if (parentPath === undefined) {
|
|
94
|
+
return locationHistory;
|
|
95
|
+
}
|
|
96
|
+
return goTo(state, parentPath, {
|
|
97
|
+
...options,
|
|
98
|
+
isBack: true
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function routerReducer(state, action) {
|
|
102
|
+
let {
|
|
103
|
+
screens,
|
|
104
|
+
locationHistory,
|
|
105
|
+
matchedPath
|
|
106
|
+
} = state;
|
|
24
107
|
switch (action.type) {
|
|
25
108
|
case 'add':
|
|
26
|
-
|
|
109
|
+
screens = addScreen(state, action.screen);
|
|
110
|
+
break;
|
|
27
111
|
case 'remove':
|
|
28
|
-
|
|
112
|
+
screens = removeScreen(state, action.screen);
|
|
113
|
+
break;
|
|
114
|
+
case 'goback':
|
|
115
|
+
locationHistory = goBack(state);
|
|
116
|
+
break;
|
|
117
|
+
case 'goto':
|
|
118
|
+
locationHistory = goTo(state, action.path, action.options);
|
|
119
|
+
break;
|
|
120
|
+
case 'gotoparent':
|
|
121
|
+
locationHistory = goToParent(state, action.options);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Return early in case there is no change
|
|
126
|
+
if (screens === state.screens && locationHistory === state.locationHistory) {
|
|
127
|
+
return state;
|
|
29
128
|
}
|
|
30
|
-
|
|
129
|
+
|
|
130
|
+
// Compute the matchedPath
|
|
131
|
+
const currentPath = locationHistory.length > 0 ? locationHistory[locationHistory.length - 1].path : undefined;
|
|
132
|
+
matchedPath = currentPath !== undefined ? patternMatch(currentPath, screens) : undefined;
|
|
133
|
+
|
|
134
|
+
// If the new match is the same as the previous match,
|
|
135
|
+
// return the previous one to keep immutability.
|
|
136
|
+
if (matchedPath && state.matchedPath && matchedPath.id === state.matchedPath.id && isShallowEqual(matchedPath.params, state.matchedPath.params)) {
|
|
137
|
+
matchedPath = state.matchedPath;
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
screens,
|
|
141
|
+
locationHistory,
|
|
142
|
+
matchedPath
|
|
143
|
+
};
|
|
31
144
|
}
|
|
32
145
|
function UnconnectedNavigatorProvider(props, forwardedRef) {
|
|
33
146
|
const {
|
|
@@ -36,124 +149,53 @@ function UnconnectedNavigatorProvider(props, forwardedRef) {
|
|
|
36
149
|
className,
|
|
37
150
|
...otherProps
|
|
38
151
|
} = useContextSystem(props, 'NavigatorProvider');
|
|
39
|
-
const [
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
currentScreens.current = screens;
|
|
47
|
-
}, [screens]);
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
currentLocationHistory.current = locationHistory;
|
|
50
|
-
}, [locationHistory]);
|
|
51
|
-
const currentMatch = useRef();
|
|
52
|
-
const matchedPath = useMemo(() => {
|
|
53
|
-
let currentPath;
|
|
54
|
-
if (locationHistory.length === 0 || (currentPath = locationHistory[locationHistory.length - 1].path) === undefined) {
|
|
55
|
-
currentMatch.current = undefined;
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
58
|
-
const resolvePath = path => {
|
|
59
|
-
const newMatch = patternMatch(path, screens);
|
|
152
|
+
const [routerState, dispatch] = useReducer(routerReducer, initialPath, path => ({
|
|
153
|
+
screens: [],
|
|
154
|
+
locationHistory: [{
|
|
155
|
+
path
|
|
156
|
+
}],
|
|
157
|
+
matchedPath: undefined
|
|
158
|
+
}));
|
|
60
159
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
160
|
+
// The methods are constant forever, create stable references to them.
|
|
161
|
+
const methods = useMemo(() => ({
|
|
162
|
+
goBack: () => dispatch({
|
|
163
|
+
type: 'goback'
|
|
164
|
+
}),
|
|
165
|
+
goTo: (path, options) => dispatch({
|
|
166
|
+
type: 'goto',
|
|
167
|
+
path,
|
|
168
|
+
options
|
|
169
|
+
}),
|
|
170
|
+
goToParent: options => dispatch({
|
|
171
|
+
type: 'gotoparent',
|
|
172
|
+
options
|
|
173
|
+
}),
|
|
174
|
+
addScreen: screen => dispatch({
|
|
175
|
+
type: 'add',
|
|
176
|
+
screen
|
|
177
|
+
}),
|
|
178
|
+
removeScreen: screen => dispatch({
|
|
179
|
+
type: 'remove',
|
|
180
|
+
screen
|
|
181
|
+
})
|
|
75
182
|
}), []);
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
}, []);
|
|
92
|
-
const goTo = useCallback((path, options = {}) => {
|
|
93
|
-
const {
|
|
94
|
-
focusTargetSelector,
|
|
95
|
-
isBack = false,
|
|
96
|
-
skipFocus = false,
|
|
97
|
-
replace = false,
|
|
98
|
-
...restOptions
|
|
99
|
-
} = options;
|
|
100
|
-
const isNavigatingToPreviousPath = isBack && currentLocationHistory.current.length > 1 && currentLocationHistory.current[currentLocationHistory.current.length - 2].path === path;
|
|
101
|
-
if (isNavigatingToPreviousPath) {
|
|
102
|
-
goBack();
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
setLocationHistory(prevLocationHistory => {
|
|
106
|
-
const newLocation = {
|
|
107
|
-
...restOptions,
|
|
108
|
-
path,
|
|
109
|
-
isBack,
|
|
110
|
-
hasRestoredFocus: false,
|
|
111
|
-
skipFocus
|
|
112
|
-
};
|
|
113
|
-
if (prevLocationHistory.length === 0) {
|
|
114
|
-
return replace ? [] : [newLocation];
|
|
115
|
-
}
|
|
116
|
-
const newLocationHistory = prevLocationHistory.slice(prevLocationHistory.length > MAX_HISTORY_LENGTH - 1 ? 1 : 0, -1);
|
|
117
|
-
if (!replace) {
|
|
118
|
-
newLocationHistory.push(
|
|
119
|
-
// Assign `focusTargetSelector` to the previous location in history
|
|
120
|
-
// (the one we just navigated from).
|
|
121
|
-
{
|
|
122
|
-
...prevLocationHistory[prevLocationHistory.length - 1],
|
|
123
|
-
focusTargetSelector
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
newLocationHistory.push(newLocation);
|
|
127
|
-
return newLocationHistory;
|
|
128
|
-
});
|
|
129
|
-
}, [goBack]);
|
|
130
|
-
const goToParent = useCallback((options = {}) => {
|
|
131
|
-
const currentPath = currentLocationHistory.current[currentLocationHistory.current.length - 1].path;
|
|
132
|
-
if (currentPath === undefined) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
const parentPath = findParent(currentPath, currentScreens.current);
|
|
136
|
-
if (parentPath === undefined) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
goTo(parentPath, {
|
|
140
|
-
...options,
|
|
141
|
-
isBack: true
|
|
142
|
-
});
|
|
143
|
-
}, [goTo]);
|
|
144
|
-
const navigatorContextValue = useMemo(() => ({
|
|
145
|
-
location: {
|
|
146
|
-
...locationHistory[locationHistory.length - 1],
|
|
147
|
-
isInitial: locationHistory.length === 1
|
|
148
|
-
},
|
|
149
|
-
params: matchedPath ? matchedPath.params : {},
|
|
150
|
-
match: matchedPath ? matchedPath.id : undefined,
|
|
151
|
-
goTo,
|
|
152
|
-
goBack,
|
|
153
|
-
goToParent,
|
|
154
|
-
addScreen,
|
|
155
|
-
removeScreen
|
|
156
|
-
}), [locationHistory, matchedPath, goTo, goBack, goToParent, addScreen, removeScreen]);
|
|
183
|
+
const {
|
|
184
|
+
locationHistory,
|
|
185
|
+
matchedPath
|
|
186
|
+
} = routerState;
|
|
187
|
+
const navigatorContextValue = useMemo(() => {
|
|
188
|
+
var _matchedPath$params;
|
|
189
|
+
return {
|
|
190
|
+
location: {
|
|
191
|
+
...locationHistory[locationHistory.length - 1],
|
|
192
|
+
isInitial: locationHistory.length === 1
|
|
193
|
+
},
|
|
194
|
+
params: (_matchedPath$params = matchedPath?.params) !== null && _matchedPath$params !== void 0 ? _matchedPath$params : {},
|
|
195
|
+
match: matchedPath?.id,
|
|
196
|
+
...methods
|
|
197
|
+
};
|
|
198
|
+
}, [locationHistory, matchedPath, methods]);
|
|
157
199
|
const cx = useCx();
|
|
158
200
|
const classes = useMemo(() => cx(styles.navigatorProviderWrapper, className), [className, cx]);
|
|
159
201
|
return createElement(View, {
|