@wordpress/components 32.0.2-next.v.0 → 32.1.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 +5 -1
- package/build/alignment-matrix-control/cell.cjs +6 -121
- package/build/alignment-matrix-control/cell.cjs.map +2 -2
- package/build/alignment-matrix-control/icon.cjs +2 -3
- package/build/alignment-matrix-control/icon.cjs.map +2 -2
- package/build/alignment-matrix-control/index.cjs +6 -121
- package/build/alignment-matrix-control/index.cjs.map +2 -2
- package/build/angle-picker-control/angle-circle.cjs +6 -85
- package/build/angle-picker-control/angle-circle.cjs.map +2 -2
- package/build/autocomplete/autocompleter-ui.cjs +1 -2
- package/build/autocomplete/autocompleter-ui.cjs.map +2 -2
- package/build/box-control/input-control.cjs +8 -12
- package/build/box-control/input-control.cjs.map +2 -2
- package/build/button/index.cjs +6 -12
- package/build/button/index.cjs.map +2 -2
- package/build/calendar/date-calendar/index.cjs +2 -2
- package/build/calendar/date-calendar/index.cjs.map +2 -2
- package/build/calendar/date-range-calendar/index.cjs +4 -6
- package/build/calendar/date-range-calendar/index.cjs.map +2 -2
- package/build/card/card/hook.cjs +1 -2
- package/build/card/card/hook.cjs.map +2 -2
- package/build/color-palette/utils.cjs +2 -2
- package/build/color-palette/utils.cjs.map +2 -2
- package/build/combobox-control/index.cjs +1 -2
- package/build/combobox-control/index.cjs.map +2 -2
- package/build/composite/group-label.cjs +1 -2
- package/build/composite/group-label.cjs.map +2 -2
- package/build/composite/group.cjs +1 -2
- package/build/composite/group.cjs.map +2 -2
- package/build/composite/hover.cjs +1 -2
- package/build/composite/hover.cjs.map +2 -2
- package/build/composite/index.cjs +1 -1
- package/build/composite/index.cjs.map +2 -2
- package/build/composite/item.cjs +1 -2
- package/build/composite/item.cjs.map +2 -2
- package/build/composite/legacy/index.cjs +1 -2
- package/build/composite/legacy/index.cjs.map +2 -2
- package/build/composite/row.cjs +1 -2
- package/build/composite/row.cjs.map +2 -2
- package/build/composite/typeahead.cjs +1 -2
- package/build/composite/typeahead.cjs.map +2 -2
- package/build/confirm-dialog/component.cjs +2 -2
- package/build/confirm-dialog/component.cjs.map +2 -2
- package/build/context/context-system-provider.cjs +1 -1
- package/build/context/context-system-provider.cjs.map +2 -2
- package/build/custom-gradient-picker/index.cjs +1 -2
- package/build/custom-gradient-picker/index.cjs.map +2 -2
- package/build/custom-gradient-picker/utils.cjs +1 -1
- package/build/custom-gradient-picker/utils.cjs.map +2 -2
- package/build/custom-select-control/index.cjs +2 -3
- package/build/custom-select-control/index.cjs.map +2 -2
- package/build/custom-select-control-v2/custom-select.cjs +1 -1
- package/build/custom-select-control-v2/custom-select.cjs.map +2 -2
- package/build/custom-select-control-v2/item.cjs +2 -3
- package/build/custom-select-control-v2/item.cjs.map +2 -2
- package/build/date-time/date/index.cjs +1 -1
- package/build/date-time/date/index.cjs.map +2 -2
- package/build/date-time/time/index.cjs +2 -2
- package/build/date-time/time/index.cjs.map +2 -2
- package/build/date-time/utils.cjs +1 -2
- package/build/date-time/utils.cjs.map +2 -2
- package/build/divider/styles.cjs +2 -2
- package/build/divider/styles.cjs.map +2 -2
- package/build/dropdown-menu/index.cjs +2 -3
- package/build/dropdown-menu/index.cjs.map +2 -2
- package/build/duotone-picker/duotone-picker.cjs +1 -1
- package/build/duotone-picker/duotone-picker.cjs.map +2 -2
- package/build/flex/flex/hook.cjs +1 -1
- package/build/flex/flex/hook.cjs.map +2 -2
- package/build/focal-point-picker/index.cjs +1 -2
- package/build/focal-point-picker/index.cjs.map +2 -2
- package/build/font-size-picker/font-size-picker-select.cjs +1 -2
- package/build/font-size-picker/font-size-picker-select.cjs.map +2 -2
- package/build/font-size-picker/index.cjs +2 -2
- package/build/font-size-picker/index.cjs.map +2 -2
- package/build/guide/index.cjs +2 -3
- package/build/guide/index.cjs.map +2 -2
- package/build/higher-order/navigate-regions/index.cjs +1 -2
- package/build/higher-order/navigate-regions/index.cjs.map +2 -2
- package/build/input-control/input-field.cjs +1 -1
- package/build/input-control/input-field.cjs.map +2 -2
- package/build/input-control/reducer/reducer.cjs +2 -4
- package/build/input-control/reducer/reducer.cjs.map +2 -2
- package/build/keyboard-shortcuts/index.cjs +1 -1
- package/build/keyboard-shortcuts/index.cjs.map +2 -2
- package/build/menu/index.cjs +1 -1
- package/build/menu/index.cjs.map +2 -2
- package/build/menu/item.cjs +1 -1
- package/build/menu/item.cjs.map +2 -2
- package/build/menu/popover.cjs +2 -2
- package/build/menu/popover.cjs.map +2 -2
- package/build/modal/index.cjs +2 -4
- package/build/modal/index.cjs.map +2 -2
- package/build/navigator/navigator/component.cjs +8 -13
- package/build/navigator/navigator/component.cjs.map +2 -2
- package/build/navigator/navigator-screen/component.cjs +1 -1
- package/build/navigator/navigator-screen/component.cjs.map +2 -2
- package/build/number-control/index.cjs +2 -3
- package/build/number-control/index.cjs.map +2 -2
- package/build/palette-edit/index.cjs +3 -4
- package/build/palette-edit/index.cjs.map +2 -2
- package/build/popover/index.cjs +1 -2
- package/build/popover/index.cjs.map +2 -2
- package/build/popover/overlay-middlewares.cjs +1 -2
- package/build/popover/overlay-middlewares.cjs.map +2 -2
- package/build/popover/utils.cjs +3 -8
- package/build/popover/utils.cjs.map +2 -2
- package/build/private-apis.cjs +1 -0
- package/build/private-apis.cjs.map +2 -2
- package/build/radio-group/index.cjs +1 -1
- package/build/radio-group/index.cjs.map +2 -2
- package/build/range-control/index.cjs +4 -4
- package/build/range-control/index.cjs.map +2 -2
- package/build/range-control/utils.cjs +1 -1
- package/build/range-control/utils.cjs.map +2 -2
- package/build/search-control/index.cjs +3 -3
- package/build/search-control/index.cjs.map +2 -2
- package/build/slot-fill/fill.cjs +1 -2
- package/build/slot-fill/fill.cjs.map +2 -2
- package/build/slot-fill/slot.cjs +1 -2
- package/build/slot-fill/slot.cjs.map +2 -2
- package/build/tabs/tab.cjs +1 -2
- package/build/tabs/tab.cjs.map +2 -2
- package/build/tabs/tablist.cjs +7 -11
- package/build/tabs/tablist.cjs.map +2 -2
- package/build/toggle-group-control/toggle-group-control/as-radio-group.cjs +1 -1
- package/build/toggle-group-control/toggle-group-control/as-radio-group.cjs.map +2 -2
- package/build/toggle-group-control/toggle-group-control/utils.cjs +1 -1
- package/build/toggle-group-control/toggle-group-control/utils.cjs.map +2 -2
- package/build/tree-grid/index.cjs +1 -2
- package/build/tree-grid/index.cjs.map +2 -2
- package/build/unit-control/index.cjs +4 -5
- package/build/unit-control/index.cjs.map +2 -2
- package/build/unit-control/utils.cjs +2 -2
- package/build/unit-control/utils.cjs.map +2 -2
- package/build/utils/element-rect.cjs +3 -4
- package/build/utils/element-rect.cjs.map +2 -2
- package/build/utils/font.cjs +1 -2
- package/build/utils/font.cjs.map +2 -2
- package/build/utils/strings.cjs +1 -2
- package/build/utils/strings.cjs.map +2 -2
- package/build/utils/use-deprecated-props.cjs +1 -1
- package/build/utils/use-deprecated-props.cjs.map +2 -2
- package/build/utils/values.cjs +1 -2
- package/build/utils/values.cjs.map +2 -2
- package/build/validated-form-controls/components/combobox-control.cjs +1 -1
- package/build/validated-form-controls/components/combobox-control.cjs.map +2 -2
- package/build/validated-form-controls/components/toggle-control.cjs +1 -1
- package/build/validated-form-controls/components/toggle-control.cjs.map +2 -2
- package/build/validated-form-controls/control-with-error.cjs +3 -6
- package/build/validated-form-controls/control-with-error.cjs.map +2 -2
- package/build-module/alignment-matrix-control/cell.mjs +6 -121
- package/build-module/alignment-matrix-control/cell.mjs.map +2 -2
- package/build-module/alignment-matrix-control/icon.mjs +2 -3
- package/build-module/alignment-matrix-control/icon.mjs.map +2 -2
- package/build-module/alignment-matrix-control/index.mjs +6 -121
- package/build-module/alignment-matrix-control/index.mjs.map +2 -2
- package/build-module/angle-picker-control/angle-circle.mjs +6 -85
- package/build-module/angle-picker-control/angle-circle.mjs.map +2 -2
- package/build-module/autocomplete/autocompleter-ui.mjs +1 -2
- package/build-module/autocomplete/autocompleter-ui.mjs.map +2 -2
- package/build-module/box-control/input-control.mjs +8 -12
- package/build-module/box-control/input-control.mjs.map +2 -2
- package/build-module/button/index.mjs +6 -12
- package/build-module/button/index.mjs.map +2 -2
- package/build-module/calendar/date-calendar/index.mjs +2 -2
- package/build-module/calendar/date-calendar/index.mjs.map +2 -2
- package/build-module/calendar/date-range-calendar/index.mjs +4 -6
- package/build-module/calendar/date-range-calendar/index.mjs.map +2 -2
- package/build-module/card/card/hook.mjs +1 -2
- package/build-module/card/card/hook.mjs.map +2 -2
- package/build-module/color-palette/utils.mjs +2 -2
- package/build-module/color-palette/utils.mjs.map +2 -2
- package/build-module/combobox-control/index.mjs +1 -2
- package/build-module/combobox-control/index.mjs.map +2 -2
- package/build-module/composite/group-label.mjs +1 -2
- package/build-module/composite/group-label.mjs.map +2 -2
- package/build-module/composite/group.mjs +1 -2
- package/build-module/composite/group.mjs.map +2 -2
- package/build-module/composite/hover.mjs +1 -2
- package/build-module/composite/hover.mjs.map +2 -2
- package/build-module/composite/index.mjs +1 -1
- package/build-module/composite/index.mjs.map +2 -2
- package/build-module/composite/item.mjs +1 -2
- package/build-module/composite/item.mjs.map +2 -2
- package/build-module/composite/legacy/index.mjs +1 -2
- package/build-module/composite/legacy/index.mjs.map +2 -2
- package/build-module/composite/row.mjs +1 -2
- package/build-module/composite/row.mjs.map +2 -2
- package/build-module/composite/typeahead.mjs +1 -2
- package/build-module/composite/typeahead.mjs.map +2 -2
- package/build-module/confirm-dialog/component.mjs +2 -2
- package/build-module/confirm-dialog/component.mjs.map +2 -2
- package/build-module/context/context-system-provider.mjs +1 -1
- package/build-module/context/context-system-provider.mjs.map +2 -2
- package/build-module/custom-gradient-picker/index.mjs +1 -2
- package/build-module/custom-gradient-picker/index.mjs.map +2 -2
- package/build-module/custom-gradient-picker/utils.mjs +1 -1
- package/build-module/custom-gradient-picker/utils.mjs.map +2 -2
- package/build-module/custom-select-control/index.mjs +2 -3
- package/build-module/custom-select-control/index.mjs.map +2 -2
- package/build-module/custom-select-control-v2/custom-select.mjs +1 -1
- package/build-module/custom-select-control-v2/custom-select.mjs.map +2 -2
- package/build-module/custom-select-control-v2/item.mjs +2 -3
- package/build-module/custom-select-control-v2/item.mjs.map +2 -2
- package/build-module/date-time/date/index.mjs +1 -1
- package/build-module/date-time/date/index.mjs.map +2 -2
- package/build-module/date-time/time/index.mjs +2 -2
- package/build-module/date-time/time/index.mjs.map +2 -2
- package/build-module/date-time/utils.mjs +1 -2
- package/build-module/date-time/utils.mjs.map +2 -2
- package/build-module/divider/styles.mjs +2 -2
- package/build-module/divider/styles.mjs.map +2 -2
- package/build-module/dropdown-menu/index.mjs +2 -3
- package/build-module/dropdown-menu/index.mjs.map +2 -2
- package/build-module/duotone-picker/duotone-picker.mjs +1 -1
- package/build-module/duotone-picker/duotone-picker.mjs.map +2 -2
- package/build-module/flex/flex/hook.mjs +1 -1
- package/build-module/flex/flex/hook.mjs.map +2 -2
- package/build-module/focal-point-picker/index.mjs +1 -2
- package/build-module/focal-point-picker/index.mjs.map +2 -2
- package/build-module/font-size-picker/font-size-picker-select.mjs +1 -2
- package/build-module/font-size-picker/font-size-picker-select.mjs.map +2 -2
- package/build-module/font-size-picker/index.mjs +2 -2
- package/build-module/font-size-picker/index.mjs.map +2 -2
- package/build-module/guide/index.mjs +2 -3
- package/build-module/guide/index.mjs.map +2 -2
- package/build-module/higher-order/navigate-regions/index.mjs +1 -2
- package/build-module/higher-order/navigate-regions/index.mjs.map +2 -2
- package/build-module/input-control/input-field.mjs +1 -1
- package/build-module/input-control/input-field.mjs.map +2 -2
- package/build-module/input-control/reducer/reducer.mjs +2 -4
- package/build-module/input-control/reducer/reducer.mjs.map +2 -2
- package/build-module/keyboard-shortcuts/index.mjs +1 -1
- package/build-module/keyboard-shortcuts/index.mjs.map +2 -2
- package/build-module/menu/index.mjs +1 -1
- package/build-module/menu/index.mjs.map +2 -2
- package/build-module/menu/item.mjs +1 -1
- package/build-module/menu/item.mjs.map +2 -2
- package/build-module/menu/popover.mjs +2 -2
- package/build-module/menu/popover.mjs.map +2 -2
- package/build-module/modal/index.mjs +2 -4
- package/build-module/modal/index.mjs.map +2 -2
- package/build-module/navigator/navigator/component.mjs +8 -13
- package/build-module/navigator/navigator/component.mjs.map +2 -2
- package/build-module/navigator/navigator-screen/component.mjs +1 -1
- package/build-module/navigator/navigator-screen/component.mjs.map +2 -2
- package/build-module/number-control/index.mjs +2 -3
- package/build-module/number-control/index.mjs.map +2 -2
- package/build-module/palette-edit/index.mjs +3 -4
- package/build-module/palette-edit/index.mjs.map +2 -2
- package/build-module/popover/index.mjs +1 -2
- package/build-module/popover/index.mjs.map +2 -2
- package/build-module/popover/overlay-middlewares.mjs +1 -2
- package/build-module/popover/overlay-middlewares.mjs.map +2 -2
- package/build-module/popover/utils.mjs +3 -8
- package/build-module/popover/utils.mjs.map +2 -2
- package/build-module/private-apis.mjs +2 -1
- package/build-module/private-apis.mjs.map +2 -2
- package/build-module/radio-group/index.mjs +1 -1
- package/build-module/radio-group/index.mjs.map +2 -2
- package/build-module/range-control/index.mjs +4 -4
- package/build-module/range-control/index.mjs.map +2 -2
- package/build-module/range-control/utils.mjs +1 -1
- package/build-module/range-control/utils.mjs.map +2 -2
- package/build-module/search-control/index.mjs +3 -3
- package/build-module/search-control/index.mjs.map +2 -2
- package/build-module/slot-fill/fill.mjs +1 -2
- package/build-module/slot-fill/fill.mjs.map +2 -2
- package/build-module/slot-fill/slot.mjs +1 -2
- package/build-module/slot-fill/slot.mjs.map +2 -2
- package/build-module/tabs/tab.mjs +1 -2
- package/build-module/tabs/tab.mjs.map +2 -2
- package/build-module/tabs/tablist.mjs +7 -11
- package/build-module/tabs/tablist.mjs.map +2 -2
- package/build-module/toggle-group-control/toggle-group-control/as-radio-group.mjs +1 -1
- package/build-module/toggle-group-control/toggle-group-control/as-radio-group.mjs.map +2 -2
- package/build-module/toggle-group-control/toggle-group-control/utils.mjs +1 -1
- package/build-module/toggle-group-control/toggle-group-control/utils.mjs.map +2 -2
- package/build-module/tree-grid/index.mjs +1 -2
- package/build-module/tree-grid/index.mjs.map +2 -2
- package/build-module/unit-control/index.mjs +4 -5
- package/build-module/unit-control/index.mjs.map +2 -2
- package/build-module/unit-control/utils.mjs +2 -2
- package/build-module/unit-control/utils.mjs.map +2 -2
- package/build-module/utils/element-rect.mjs +3 -4
- package/build-module/utils/element-rect.mjs.map +2 -2
- package/build-module/utils/font.mjs +1 -2
- package/build-module/utils/font.mjs.map +2 -2
- package/build-module/utils/strings.mjs +1 -2
- package/build-module/utils/strings.mjs.map +2 -2
- package/build-module/utils/use-deprecated-props.mjs +1 -1
- package/build-module/utils/use-deprecated-props.mjs.map +2 -2
- package/build-module/utils/values.mjs +1 -2
- package/build-module/utils/values.mjs.map +2 -2
- package/build-module/validated-form-controls/components/combobox-control.mjs +1 -1
- package/build-module/validated-form-controls/components/combobox-control.mjs.map +2 -2
- package/build-module/validated-form-controls/components/toggle-control.mjs +1 -1
- package/build-module/validated-form-controls/components/toggle-control.mjs.map +2 -2
- package/build-module/validated-form-controls/control-with-error.mjs +3 -6
- package/build-module/validated-form-controls/control-with-error.mjs.map +2 -2
- package/build-types/private-apis.d.ts.map +1 -1
- package/package.json +21 -21
- package/src/private-apis.ts +2 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/menu/popover.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport * as Ariakit from '@ariakit/react';\n\n/**\n * WordPress dependencies\n */\nimport { useContext, useMemo, forwardRef, useCallback } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\n\nimport * as Styled from './styles';\nimport { Context } from './context';\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nexport const Popover = forwardRef(function Popover({\n gutter,\n children,\n shift,\n modal = true,\n ...otherProps\n}, ref) {\n const menuContext = useContext(Context);\n\n // Extract the side from the applied placement \u2014 useful for animations.\n // Using `currentPlacement` instead of `placement` to make sure that we\n // use the final computed placement (including \"flips\" etc).\n const appliedPlacementSide = Ariakit.useStoreState(menuContext?.store, 'currentPlacement')?.split('-')[0];\n const hideOnEscape = useCallback(event => {\n // Pressing Escape can cause unexpected consequences (ie. exiting\n // full screen mode on MacOs, close parent modals...).\n event.preventDefault();\n // Returning `true` causes the menu to hide.\n return true;\n }, []);\n const computedDirection = Ariakit.useStoreState(menuContext?.store, 'rtl') ? 'rtl' : 'ltr';\n const wrapperProps = useMemo(() => ({\n dir: computedDirection,\n style: {\n direction: computedDirection\n }\n }), [computedDirection]);\n if (!menuContext?.store) {\n throw new Error('Menu.Popover can only be rendered inside a Menu component');\n }\n return /*#__PURE__*/_jsx(Styled.Menu, {\n ...otherProps,\n ref: ref,\n modal: modal,\n store: menuContext.store\n // Root menu has an 8px distance from its trigger,\n // otherwise 0 (which causes the submenu to slightly overlap)\n ,\n gutter: gutter
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,cAAyB;AAKzB,qBAA6D;AAM7D,aAAwB;AACxB,qBAAwB;AACxB,yBAA4B;AACrB,IAAM,cAAU,2BAAW,SAASA,SAAQ;AAAA,EACjD;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR,GAAG;AACL,GAAG,KAAK;AACN,QAAM,kBAAc,2BAAW,sBAAO;AAKtC,QAAM,uBAA+B,sBAAc,aAAa,OAAO,kBAAkB,GAAG,MAAM,GAAG,EAAE,CAAC;AACxG,QAAM,mBAAe,4BAAY,WAAS;AAGxC,UAAM,eAAe;AAErB,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACL,QAAM,oBAA4B,sBAAc,aAAa,OAAO,KAAK,IAAI,QAAQ;AACrF,QAAM,mBAAe,wBAAQ,OAAO;AAAA,IAClC,KAAK;AAAA,IACL,OAAO;AAAA,MACL,WAAW;AAAA,IACb;AAAA,EACF,IAAI,CAAC,iBAAiB,CAAC;AACvB,MAAI,CAAC,aAAa,OAAO;AACvB,UAAM,IAAI,MAAM,2DAA2D;AAAA,EAC7E;AACA,SAAoB,uCAAAC,KAAY,aAAM;AAAA,IACpC,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA,OAAO,YAAY;AAAA,IAInB,QAAQ,WAAW,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport * as Ariakit from '@ariakit/react';\n\n/**\n * WordPress dependencies\n */\nimport { useContext, useMemo, forwardRef, useCallback } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\n\nimport * as Styled from './styles';\nimport { Context } from './context';\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nexport const Popover = forwardRef(function Popover({\n gutter,\n children,\n shift,\n modal = true,\n ...otherProps\n}, ref) {\n const menuContext = useContext(Context);\n\n // Extract the side from the applied placement \u2014 useful for animations.\n // Using `currentPlacement` instead of `placement` to make sure that we\n // use the final computed placement (including \"flips\" etc).\n const appliedPlacementSide = Ariakit.useStoreState(menuContext?.store, 'currentPlacement')?.split('-')[0];\n const hideOnEscape = useCallback(event => {\n // Pressing Escape can cause unexpected consequences (ie. exiting\n // full screen mode on MacOs, close parent modals...).\n event.preventDefault();\n // Returning `true` causes the menu to hide.\n return true;\n }, []);\n const computedDirection = Ariakit.useStoreState(menuContext?.store, 'rtl') ? 'rtl' : 'ltr';\n const wrapperProps = useMemo(() => ({\n dir: computedDirection,\n style: {\n direction: computedDirection\n }\n }), [computedDirection]);\n if (!menuContext?.store) {\n throw new Error('Menu.Popover can only be rendered inside a Menu component');\n }\n return /*#__PURE__*/_jsx(Styled.Menu, {\n ...otherProps,\n ref: ref,\n modal: modal,\n store: menuContext.store\n // Root menu has an 8px distance from its trigger,\n // otherwise 0 (which causes the submenu to slightly overlap)\n ,\n gutter: gutter ?? (menuContext.store.parent ? 0 : 8)\n // Align nested menu by the same (but opposite) amount\n // as the menu container's padding.\n ,\n shift: shift ?? (menuContext.store.parent ? -4 : 0),\n hideOnHoverOutside: false,\n \"data-side\": appliedPlacementSide,\n \"data-submenu\": !!menuContext.store.parent || undefined,\n wrapperProps: wrapperProps,\n hideOnEscape: hideOnEscape,\n unmountOnHide: true,\n variant: menuContext.variant,\n children: children\n });\n});"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,cAAyB;AAKzB,qBAA6D;AAM7D,aAAwB;AACxB,qBAAwB;AACxB,yBAA4B;AACrB,IAAM,cAAU,2BAAW,SAASA,SAAQ;AAAA,EACjD;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR,GAAG;AACL,GAAG,KAAK;AACN,QAAM,kBAAc,2BAAW,sBAAO;AAKtC,QAAM,uBAA+B,sBAAc,aAAa,OAAO,kBAAkB,GAAG,MAAM,GAAG,EAAE,CAAC;AACxG,QAAM,mBAAe,4BAAY,WAAS;AAGxC,UAAM,eAAe;AAErB,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACL,QAAM,oBAA4B,sBAAc,aAAa,OAAO,KAAK,IAAI,QAAQ;AACrF,QAAM,mBAAe,wBAAQ,OAAO;AAAA,IAClC,KAAK;AAAA,IACL,OAAO;AAAA,MACL,WAAW;AAAA,IACb;AAAA,EACF,IAAI,CAAC,iBAAiB,CAAC;AACvB,MAAI,CAAC,aAAa,OAAO;AACvB,UAAM,IAAI,MAAM,2DAA2D;AAAA,EAC7E;AACA,SAAoB,uCAAAC,KAAY,aAAM;AAAA,IACpC,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA,OAAO,YAAY;AAAA,IAInB,QAAQ,WAAW,YAAY,MAAM,SAAS,IAAI;AAAA,IAIlD,OAAO,UAAU,YAAY,MAAM,SAAS,KAAK;AAAA,IACjD,oBAAoB;AAAA,IACpB,aAAa;AAAA,IACb,gBAAgB,CAAC,CAAC,YAAY,MAAM,UAAU;AAAA,IAC9C;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf,SAAS,YAAY;AAAA,IACrB;AAAA,EACF,CAAC;AACH,CAAC;",
|
|
6
6
|
"names": ["Popover", "_jsx"]
|
|
7
7
|
}
|
package/build/modal/index.cjs
CHANGED
|
@@ -130,9 +130,8 @@ function UnforwardedModal(props, forwardedRef) {
|
|
|
130
130
|
};
|
|
131
131
|
}, [dismissers, nestedDismissers]);
|
|
132
132
|
(0, import_element.useEffect)(() => {
|
|
133
|
-
var _bodyOpenClasses$get;
|
|
134
133
|
const theClass = bodyOpenClassName;
|
|
135
|
-
const oneMore = 1 + (
|
|
134
|
+
const oneMore = 1 + (bodyOpenClasses.get(theClass) ?? 0);
|
|
136
135
|
bodyOpenClasses.set(theClass, oneMore);
|
|
137
136
|
document.body.classList.add(bodyOpenClassName);
|
|
138
137
|
return () => {
|
|
@@ -169,8 +168,7 @@ function UnforwardedModal(props, forwardedRef) {
|
|
|
169
168
|
}
|
|
170
169
|
}
|
|
171
170
|
const onContentContainerScroll = (0, import_element.useCallback)((e) => {
|
|
172
|
-
|
|
173
|
-
const scrollY = (_e$currentTarget$scro = e?.currentTarget?.scrollTop) !== null && _e$currentTarget$scro !== void 0 ? _e$currentTarget$scro : -1;
|
|
171
|
+
const scrollY = e?.currentTarget?.scrollTop ?? -1;
|
|
174
172
|
if (!hasScrolledContent && scrollY > 0) {
|
|
175
173
|
setHasScrolledContent(true);
|
|
176
174
|
} else if (hasScrolledContent && scrollY <= 0) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/modal/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { createPortal, useCallback, useEffect, useRef, useState, forwardRef, useLayoutEffect, createContext, useContext } from '@wordpress/element';\nimport { useInstanceId, useFocusReturn, useFocusOnMount, useConstrainedTabbing, useMergeRefs } from '@wordpress/compose';\nimport { __ } from '@wordpress/i18n';\nimport { close } from '@wordpress/icons';\nimport { getScrollContainer } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport * as ariaHelper from './aria-helper';\nimport Button from '../button';\nimport StyleProvider from '../style-provider';\nimport { withIgnoreIMEEvents } from '../utils/with-ignore-ime-events';\nimport { Spacer } from '../spacer';\nimport { useModalExitAnimation } from './use-modal-exit-animation';\n\n// Used to track and dismiss the prior modal when another opens unless nested.\nimport { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from \"react/jsx-runtime\";\nconst ModalContext = createContext(new Set());\nModalContext.displayName = 'ModalContext';\n\n// Used to track body class names applied while modals are open.\nconst bodyOpenClasses = new Map();\nfunction UnforwardedModal(props, forwardedRef) {\n const {\n bodyOpenClassName = 'modal-open',\n role = 'dialog',\n title = null,\n focusOnMount = true,\n shouldCloseOnEsc = true,\n shouldCloseOnClickOutside = true,\n isDismissible = true,\n /* Accessibility. */\n aria = {\n labelledby: undefined,\n describedby: undefined\n },\n onRequestClose,\n icon,\n closeButtonLabel,\n children,\n style,\n overlayClassName: overlayClassnameProp,\n className,\n contentLabel,\n onKeyDown,\n isFullScreen = false,\n size,\n headerActions = null,\n __experimentalHideHeader = false\n } = props;\n const ref = useRef();\n const instanceId = useInstanceId(Modal);\n const headingId = title ? `components-modal-header-${instanceId}` : aria.labelledby;\n\n // The focus hook does not support 'firstContentElement' but this is a valid\n // value for the Modal's focusOnMount prop. The following code ensures the focus\n // hook will focus the first focusable node within the element to which it is applied.\n // When `firstContentElement` is passed as the value of the focusOnMount prop,\n // the focus hook is applied to the Modal's content element.\n // Otherwise, the focus hook is applied to the Modal's ref. This ensures that the\n // focus hook will focus the first element in the Modal's **content** when\n // `firstContentElement` is passed.\n const focusOnMountRef = useFocusOnMount(focusOnMount === 'firstContentElement' ? 'firstElement' : focusOnMount);\n const constrainedTabbingRef = useConstrainedTabbing();\n const focusReturnRef = useFocusReturn();\n const contentRef = useRef(null);\n const childrenContainerRef = useRef(null);\n const [hasScrolledContent, setHasScrolledContent] = useState(false);\n const [hasScrollableContent, setHasScrollableContent] = useState(false);\n let sizeClass;\n if (isFullScreen || size === 'fill') {\n sizeClass = 'is-full-screen';\n } else if (size) {\n sizeClass = `has-size-${size}`;\n }\n\n // Determines whether the Modal content is scrollable and updates the state.\n const isContentScrollable = useCallback(() => {\n if (!contentRef.current) {\n return;\n }\n const closestScrollContainer = getScrollContainer(contentRef.current);\n if (contentRef.current === closestScrollContainer) {\n setHasScrollableContent(true);\n } else {\n setHasScrollableContent(false);\n }\n }, [contentRef]);\n\n // Accessibly isolates/unisolates the modal.\n useEffect(() => {\n ariaHelper.modalize(ref.current);\n return () => ariaHelper.unmodalize();\n }, []);\n\n // Keeps a fresh ref for the subsequent effect.\n const onRequestCloseRef = useRef();\n useEffect(() => {\n onRequestCloseRef.current = onRequestClose;\n }, [onRequestClose]);\n\n // The list of `onRequestClose` callbacks of open (non-nested) Modals. Only\n // one should remain open at a time and the list enables closing prior ones.\n const dismissers = useContext(ModalContext);\n // Used for the tracking and dismissing any nested modals.\n const [nestedDismissers] = useState(() => new Set());\n\n // Updates the stack tracking open modals at this level and calls\n // onRequestClose for any prior and/or nested modals as applicable.\n useEffect(() => {\n // add this modal instance to the dismissers set\n dismissers.add(onRequestCloseRef);\n // request that all the other modals close themselves\n for (const dismisser of dismissers) {\n if (dismisser !== onRequestCloseRef) {\n dismisser.current?.();\n }\n }\n return () => {\n // request that all the nested modals close themselves\n for (const dismisser of nestedDismissers) {\n dismisser.current?.();\n }\n // remove this modal instance from the dismissers set\n dismissers.delete(onRequestCloseRef);\n };\n }, [dismissers, nestedDismissers]);\n\n // Adds/removes the value of bodyOpenClassName to body element.\n useEffect(() => {\n var _bodyOpenClasses$get;\n const theClass = bodyOpenClassName;\n const oneMore = 1 + ((_bodyOpenClasses$get = bodyOpenClasses.get(theClass)) !== null && _bodyOpenClasses$get !== void 0 ? _bodyOpenClasses$get : 0);\n bodyOpenClasses.set(theClass, oneMore);\n document.body.classList.add(bodyOpenClassName);\n return () => {\n const oneLess = bodyOpenClasses.get(theClass) - 1;\n if (oneLess === 0) {\n document.body.classList.remove(theClass);\n bodyOpenClasses.delete(theClass);\n } else {\n bodyOpenClasses.set(theClass, oneLess);\n }\n };\n }, [bodyOpenClassName]);\n const {\n closeModal,\n frameRef,\n frameStyle,\n overlayClassname\n } = useModalExitAnimation();\n\n // Calls the isContentScrollable callback when the Modal children container resizes.\n useLayoutEffect(() => {\n if (!window.ResizeObserver || !childrenContainerRef.current) {\n return;\n }\n const resizeObserver = new ResizeObserver(isContentScrollable);\n resizeObserver.observe(childrenContainerRef.current);\n isContentScrollable();\n return () => {\n resizeObserver.disconnect();\n };\n }, [isContentScrollable, childrenContainerRef]);\n function handleEscapeKeyDown(event) {\n if (shouldCloseOnEsc && (event.code === 'Escape' || event.key === 'Escape') && !event.defaultPrevented) {\n event.preventDefault();\n closeModal().then(() => onRequestClose(event));\n }\n }\n const onContentContainerScroll = useCallback(e => {\n var _e$currentTarget$scro;\n const scrollY = (_e$currentTarget$scro = e?.currentTarget?.scrollTop) !== null && _e$currentTarget$scro !== void 0 ? _e$currentTarget$scro : -1;\n if (!hasScrolledContent && scrollY > 0) {\n setHasScrolledContent(true);\n } else if (hasScrolledContent && scrollY <= 0) {\n setHasScrolledContent(false);\n }\n }, [hasScrolledContent]);\n let pressTarget = null;\n const overlayPressHandlers = {\n onPointerDown: event => {\n if (event.target === event.currentTarget) {\n pressTarget = event.target;\n // Avoids focus changing so that focus return works as expected.\n event.preventDefault();\n }\n },\n // Closes the modal with two exceptions. 1. Opening the context menu on\n // the overlay. 2. Pressing on the overlay then dragging the pointer\n // over the modal and releasing. Due to the modal being a child of the\n // overlay, such a gesture is a `click` on the overlay and cannot be\n // excepted by a `click` handler. Thus the tactic of handling\n // `pointerup` and comparing its target to that of the `pointerdown`.\n onPointerUp: ({\n target,\n button\n }) => {\n const isSameTarget = target === pressTarget;\n pressTarget = null;\n if (button === 0 && isSameTarget) {\n closeModal().then(() => onRequestClose());\n }\n }\n };\n const modal =\n /*#__PURE__*/\n // eslint-disable-next-line jsx-a11y/no-static-element-interactions\n _jsx(\"div\", {\n ref: useMergeRefs([ref, forwardedRef]),\n className: clsx('components-modal__screen-overlay', overlayClassname, overlayClassnameProp),\n onKeyDown: withIgnoreIMEEvents(handleEscapeKeyDown),\n ...(shouldCloseOnClickOutside ? overlayPressHandlers : {}),\n children: /*#__PURE__*/_jsx(StyleProvider, {\n document: document,\n children: /*#__PURE__*/_jsx(\"div\", {\n className: clsx('components-modal__frame', sizeClass, className),\n style: {\n ...frameStyle,\n ...style\n },\n ref: useMergeRefs([frameRef, constrainedTabbingRef, focusReturnRef, focusOnMount !== 'firstContentElement' ? focusOnMountRef : null]),\n role: role,\n \"aria-label\": contentLabel,\n \"aria-labelledby\": contentLabel ? undefined : headingId,\n \"aria-describedby\": aria.describedby,\n tabIndex: -1,\n onKeyDown: onKeyDown,\n children: /*#__PURE__*/_jsxs(\"div\", {\n className: clsx('components-modal__content', {\n 'hide-header': __experimentalHideHeader,\n 'is-scrollable': hasScrollableContent,\n 'has-scrolled-content': hasScrolledContent\n }),\n role: \"document\",\n onScroll: onContentContainerScroll,\n ref: contentRef,\n \"aria-label\": hasScrollableContent ? __('Scrollable section') : undefined,\n tabIndex: hasScrollableContent ? 0 : undefined,\n children: [!__experimentalHideHeader && /*#__PURE__*/_jsxs(\"div\", {\n className: \"components-modal__header\",\n children: [/*#__PURE__*/_jsxs(\"div\", {\n className: \"components-modal__header-heading-container\",\n children: [icon && /*#__PURE__*/_jsx(\"span\", {\n className: \"components-modal__icon-container\",\n \"aria-hidden\": true,\n children: icon\n }), title && /*#__PURE__*/_jsx(\"h1\", {\n id: headingId,\n className: \"components-modal__header-heading\",\n children: title\n })]\n }), headerActions, isDismissible && /*#__PURE__*/_jsxs(_Fragment, {\n children: [/*#__PURE__*/_jsx(Spacer, {\n marginBottom: 0,\n marginLeft: 2\n }), /*#__PURE__*/_jsx(Button, {\n size: \"compact\",\n onClick: event => closeModal().then(() => onRequestClose(event)),\n icon: close,\n label: closeButtonLabel || __('Close')\n })]\n })]\n }), /*#__PURE__*/_jsx(\"div\", {\n ref: useMergeRefs([childrenContainerRef, focusOnMount === 'firstContentElement' ? focusOnMountRef : null]),\n className: \"components-modal__children-container\",\n children: children\n })]\n })\n })\n })\n });\n return createPortal(/*#__PURE__*/_jsx(ModalContext.Provider, {\n value: nestedDismissers,\n children: modal\n }), document.body);\n}\n\n/**\n * Modals give users information and choices related to a task they\u2019re trying to\n * accomplish. They can contain critical information, require decisions, or\n * involve multiple tasks.\n *\n * ```jsx\n * import { Button, Modal } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyModal = () => {\n * const [ isOpen, setOpen ] = useState( false );\n * const openModal = () => setOpen( true );\n * const closeModal = () => setOpen( false );\n *\n * return (\n * <>\n * <Button variant=\"secondary\" onClick={ openModal }>\n * Open Modal\n * </Button>\n * { isOpen && (\n * <Modal title=\"This is my modal\" onRequestClose={ closeModal }>\n * <Button variant=\"secondary\" onClick={ closeModal }>\n * My custom close button\n * </Button>\n * </Modal>\n * ) }\n * </>\n * );\n * };\n * ```\n */\nexport const Modal = forwardRef(UnforwardedModal);\nModal.displayName = 'Modal';\nexport default Modal;"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,qBAA+H;AAC/H,qBAAoG;AACpG,kBAAmB;AACnB,mBAAsB;AACtB,iBAAmC;AAKnC,iBAA4B;AAC5B,oBAAmB;AACnB,4BAA0B;AAC1B,oCAAoC;AACpC,oBAAuB;AACvB,sCAAsC;AAGtC,yBAAkE;AAClE,IAAM,mBAAe,8BAAc,oBAAI,IAAI,CAAC;AAC5C,aAAa,cAAc;AAG3B,IAAM,kBAAkB,oBAAI,IAAI;AAChC,SAAS,iBAAiB,OAAO,cAAc;AAC7C,QAAM;AAAA,IACJ,oBAAoB;AAAA,IACpB,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,eAAe;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AAoB,uBAAO;AACjC,gCAAU,MAAM;AACd,sBAAkB,UAAU;AAAA,EAC9B,GAAG,CAAC,cAAc,CAAC;AAInB,QAAM,iBAAa,2BAAW,YAAY;AAE1C,QAAM,CAAC,gBAAgB,QAAI,yBAAS,MAAM,oBAAI,IAAI,CAAC;AAInD,gCAAU,MAAM;AAEd,eAAW,IAAI,iBAAiB;AAEhC,eAAW,aAAa,YAAY;AAClC,UAAI,cAAc,mBAAmB;AACnC,kBAAU,UAAU;AAAA,MACtB;AAAA,IACF;AACA,WAAO,MAAM;AAEX,iBAAW,aAAa,kBAAkB;AACxC,kBAAU,UAAU;AAAA,MACtB;AAEA,iBAAW,OAAO,iBAAiB;AAAA,IACrC;AAAA,EACF,GAAG,CAAC,YAAY,gBAAgB,CAAC;AAGjC,gCAAU,MAAM;AACd,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { createPortal, useCallback, useEffect, useRef, useState, forwardRef, useLayoutEffect, createContext, useContext } from '@wordpress/element';\nimport { useInstanceId, useFocusReturn, useFocusOnMount, useConstrainedTabbing, useMergeRefs } from '@wordpress/compose';\nimport { __ } from '@wordpress/i18n';\nimport { close } from '@wordpress/icons';\nimport { getScrollContainer } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport * as ariaHelper from './aria-helper';\nimport Button from '../button';\nimport StyleProvider from '../style-provider';\nimport { withIgnoreIMEEvents } from '../utils/with-ignore-ime-events';\nimport { Spacer } from '../spacer';\nimport { useModalExitAnimation } from './use-modal-exit-animation';\n\n// Used to track and dismiss the prior modal when another opens unless nested.\nimport { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from \"react/jsx-runtime\";\nconst ModalContext = createContext(new Set());\nModalContext.displayName = 'ModalContext';\n\n// Used to track body class names applied while modals are open.\nconst bodyOpenClasses = new Map();\nfunction UnforwardedModal(props, forwardedRef) {\n const {\n bodyOpenClassName = 'modal-open',\n role = 'dialog',\n title = null,\n focusOnMount = true,\n shouldCloseOnEsc = true,\n shouldCloseOnClickOutside = true,\n isDismissible = true,\n /* Accessibility. */\n aria = {\n labelledby: undefined,\n describedby: undefined\n },\n onRequestClose,\n icon,\n closeButtonLabel,\n children,\n style,\n overlayClassName: overlayClassnameProp,\n className,\n contentLabel,\n onKeyDown,\n isFullScreen = false,\n size,\n headerActions = null,\n __experimentalHideHeader = false\n } = props;\n const ref = useRef();\n const instanceId = useInstanceId(Modal);\n const headingId = title ? `components-modal-header-${instanceId}` : aria.labelledby;\n\n // The focus hook does not support 'firstContentElement' but this is a valid\n // value for the Modal's focusOnMount prop. The following code ensures the focus\n // hook will focus the first focusable node within the element to which it is applied.\n // When `firstContentElement` is passed as the value of the focusOnMount prop,\n // the focus hook is applied to the Modal's content element.\n // Otherwise, the focus hook is applied to the Modal's ref. This ensures that the\n // focus hook will focus the first element in the Modal's **content** when\n // `firstContentElement` is passed.\n const focusOnMountRef = useFocusOnMount(focusOnMount === 'firstContentElement' ? 'firstElement' : focusOnMount);\n const constrainedTabbingRef = useConstrainedTabbing();\n const focusReturnRef = useFocusReturn();\n const contentRef = useRef(null);\n const childrenContainerRef = useRef(null);\n const [hasScrolledContent, setHasScrolledContent] = useState(false);\n const [hasScrollableContent, setHasScrollableContent] = useState(false);\n let sizeClass;\n if (isFullScreen || size === 'fill') {\n sizeClass = 'is-full-screen';\n } else if (size) {\n sizeClass = `has-size-${size}`;\n }\n\n // Determines whether the Modal content is scrollable and updates the state.\n const isContentScrollable = useCallback(() => {\n if (!contentRef.current) {\n return;\n }\n const closestScrollContainer = getScrollContainer(contentRef.current);\n if (contentRef.current === closestScrollContainer) {\n setHasScrollableContent(true);\n } else {\n setHasScrollableContent(false);\n }\n }, [contentRef]);\n\n // Accessibly isolates/unisolates the modal.\n useEffect(() => {\n ariaHelper.modalize(ref.current);\n return () => ariaHelper.unmodalize();\n }, []);\n\n // Keeps a fresh ref for the subsequent effect.\n const onRequestCloseRef = useRef();\n useEffect(() => {\n onRequestCloseRef.current = onRequestClose;\n }, [onRequestClose]);\n\n // The list of `onRequestClose` callbacks of open (non-nested) Modals. Only\n // one should remain open at a time and the list enables closing prior ones.\n const dismissers = useContext(ModalContext);\n // Used for the tracking and dismissing any nested modals.\n const [nestedDismissers] = useState(() => new Set());\n\n // Updates the stack tracking open modals at this level and calls\n // onRequestClose for any prior and/or nested modals as applicable.\n useEffect(() => {\n // add this modal instance to the dismissers set\n dismissers.add(onRequestCloseRef);\n // request that all the other modals close themselves\n for (const dismisser of dismissers) {\n if (dismisser !== onRequestCloseRef) {\n dismisser.current?.();\n }\n }\n return () => {\n // request that all the nested modals close themselves\n for (const dismisser of nestedDismissers) {\n dismisser.current?.();\n }\n // remove this modal instance from the dismissers set\n dismissers.delete(onRequestCloseRef);\n };\n }, [dismissers, nestedDismissers]);\n\n // Adds/removes the value of bodyOpenClassName to body element.\n useEffect(() => {\n const theClass = bodyOpenClassName;\n const oneMore = 1 + (bodyOpenClasses.get(theClass) ?? 0);\n bodyOpenClasses.set(theClass, oneMore);\n document.body.classList.add(bodyOpenClassName);\n return () => {\n const oneLess = bodyOpenClasses.get(theClass) - 1;\n if (oneLess === 0) {\n document.body.classList.remove(theClass);\n bodyOpenClasses.delete(theClass);\n } else {\n bodyOpenClasses.set(theClass, oneLess);\n }\n };\n }, [bodyOpenClassName]);\n const {\n closeModal,\n frameRef,\n frameStyle,\n overlayClassname\n } = useModalExitAnimation();\n\n // Calls the isContentScrollable callback when the Modal children container resizes.\n useLayoutEffect(() => {\n if (!window.ResizeObserver || !childrenContainerRef.current) {\n return;\n }\n const resizeObserver = new ResizeObserver(isContentScrollable);\n resizeObserver.observe(childrenContainerRef.current);\n isContentScrollable();\n return () => {\n resizeObserver.disconnect();\n };\n }, [isContentScrollable, childrenContainerRef]);\n function handleEscapeKeyDown(event) {\n if (shouldCloseOnEsc && (event.code === 'Escape' || event.key === 'Escape') && !event.defaultPrevented) {\n event.preventDefault();\n closeModal().then(() => onRequestClose(event));\n }\n }\n const onContentContainerScroll = useCallback(e => {\n const scrollY = e?.currentTarget?.scrollTop ?? -1;\n if (!hasScrolledContent && scrollY > 0) {\n setHasScrolledContent(true);\n } else if (hasScrolledContent && scrollY <= 0) {\n setHasScrolledContent(false);\n }\n }, [hasScrolledContent]);\n let pressTarget = null;\n const overlayPressHandlers = {\n onPointerDown: event => {\n if (event.target === event.currentTarget) {\n pressTarget = event.target;\n // Avoids focus changing so that focus return works as expected.\n event.preventDefault();\n }\n },\n // Closes the modal with two exceptions. 1. Opening the context menu on\n // the overlay. 2. Pressing on the overlay then dragging the pointer\n // over the modal and releasing. Due to the modal being a child of the\n // overlay, such a gesture is a `click` on the overlay and cannot be\n // excepted by a `click` handler. Thus the tactic of handling\n // `pointerup` and comparing its target to that of the `pointerdown`.\n onPointerUp: ({\n target,\n button\n }) => {\n const isSameTarget = target === pressTarget;\n pressTarget = null;\n if (button === 0 && isSameTarget) {\n closeModal().then(() => onRequestClose());\n }\n }\n };\n const modal =\n /*#__PURE__*/\n // eslint-disable-next-line jsx-a11y/no-static-element-interactions\n _jsx(\"div\", {\n ref: useMergeRefs([ref, forwardedRef]),\n className: clsx('components-modal__screen-overlay', overlayClassname, overlayClassnameProp),\n onKeyDown: withIgnoreIMEEvents(handleEscapeKeyDown),\n ...(shouldCloseOnClickOutside ? overlayPressHandlers : {}),\n children: /*#__PURE__*/_jsx(StyleProvider, {\n document: document,\n children: /*#__PURE__*/_jsx(\"div\", {\n className: clsx('components-modal__frame', sizeClass, className),\n style: {\n ...frameStyle,\n ...style\n },\n ref: useMergeRefs([frameRef, constrainedTabbingRef, focusReturnRef, focusOnMount !== 'firstContentElement' ? focusOnMountRef : null]),\n role: role,\n \"aria-label\": contentLabel,\n \"aria-labelledby\": contentLabel ? undefined : headingId,\n \"aria-describedby\": aria.describedby,\n tabIndex: -1,\n onKeyDown: onKeyDown,\n children: /*#__PURE__*/_jsxs(\"div\", {\n className: clsx('components-modal__content', {\n 'hide-header': __experimentalHideHeader,\n 'is-scrollable': hasScrollableContent,\n 'has-scrolled-content': hasScrolledContent\n }),\n role: \"document\",\n onScroll: onContentContainerScroll,\n ref: contentRef,\n \"aria-label\": hasScrollableContent ? __('Scrollable section') : undefined,\n tabIndex: hasScrollableContent ? 0 : undefined,\n children: [!__experimentalHideHeader && /*#__PURE__*/_jsxs(\"div\", {\n className: \"components-modal__header\",\n children: [/*#__PURE__*/_jsxs(\"div\", {\n className: \"components-modal__header-heading-container\",\n children: [icon && /*#__PURE__*/_jsx(\"span\", {\n className: \"components-modal__icon-container\",\n \"aria-hidden\": true,\n children: icon\n }), title && /*#__PURE__*/_jsx(\"h1\", {\n id: headingId,\n className: \"components-modal__header-heading\",\n children: title\n })]\n }), headerActions, isDismissible && /*#__PURE__*/_jsxs(_Fragment, {\n children: [/*#__PURE__*/_jsx(Spacer, {\n marginBottom: 0,\n marginLeft: 2\n }), /*#__PURE__*/_jsx(Button, {\n size: \"compact\",\n onClick: event => closeModal().then(() => onRequestClose(event)),\n icon: close,\n label: closeButtonLabel || __('Close')\n })]\n })]\n }), /*#__PURE__*/_jsx(\"div\", {\n ref: useMergeRefs([childrenContainerRef, focusOnMount === 'firstContentElement' ? focusOnMountRef : null]),\n className: \"components-modal__children-container\",\n children: children\n })]\n })\n })\n })\n });\n return createPortal(/*#__PURE__*/_jsx(ModalContext.Provider, {\n value: nestedDismissers,\n children: modal\n }), document.body);\n}\n\n/**\n * Modals give users information and choices related to a task they\u2019re trying to\n * accomplish. They can contain critical information, require decisions, or\n * involve multiple tasks.\n *\n * ```jsx\n * import { Button, Modal } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyModal = () => {\n * const [ isOpen, setOpen ] = useState( false );\n * const openModal = () => setOpen( true );\n * const closeModal = () => setOpen( false );\n *\n * return (\n * <>\n * <Button variant=\"secondary\" onClick={ openModal }>\n * Open Modal\n * </Button>\n * { isOpen && (\n * <Modal title=\"This is my modal\" onRequestClose={ closeModal }>\n * <Button variant=\"secondary\" onClick={ closeModal }>\n * My custom close button\n * </Button>\n * </Modal>\n * ) }\n * </>\n * );\n * };\n * ```\n */\nexport const Modal = forwardRef(UnforwardedModal);\nModal.displayName = 'Modal';\nexport default Modal;"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,qBAA+H;AAC/H,qBAAoG;AACpG,kBAAmB;AACnB,mBAAsB;AACtB,iBAAmC;AAKnC,iBAA4B;AAC5B,oBAAmB;AACnB,4BAA0B;AAC1B,oCAAoC;AACpC,oBAAuB;AACvB,sCAAsC;AAGtC,yBAAkE;AAClE,IAAM,mBAAe,8BAAc,oBAAI,IAAI,CAAC;AAC5C,aAAa,cAAc;AAG3B,IAAM,kBAAkB,oBAAI,IAAI;AAChC,SAAS,iBAAiB,OAAO,cAAc;AAC7C,QAAM;AAAA,IACJ,oBAAoB;AAAA,IACpB,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,eAAe;AAAA,IACf,mBAAmB;AAAA,IACnB,4BAA4B;AAAA,IAC5B,gBAAgB;AAAA;AAAA,IAEhB,OAAO;AAAA,MACL,YAAY;AAAA,MACZ,aAAa;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,kBAAkB;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA,gBAAgB;AAAA,IAChB,2BAA2B;AAAA,EAC7B,IAAI;AACJ,QAAM,UAAM,uBAAO;AACnB,QAAM,iBAAa,8BAAc,KAAK;AACtC,QAAM,YAAY,QAAQ,2BAA2B,UAAU,KAAK,KAAK;AAUzE,QAAM,sBAAkB,gCAAgB,iBAAiB,wBAAwB,iBAAiB,YAAY;AAC9G,QAAM,4BAAwB,sCAAsB;AACpD,QAAM,qBAAiB,+BAAe;AACtC,QAAM,iBAAa,uBA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IAAO,gBAAQ;",
|
|
6
6
|
"names": ["_jsx", "clsx", "StyleProvider", "_jsxs", "_Fragment", "Button"]
|
|
7
7
|
}
|
|
@@ -60,7 +60,6 @@ function removeScreen({
|
|
|
60
60
|
return screens.filter((s) => s.id !== screen.id);
|
|
61
61
|
}
|
|
62
62
|
function goTo(state, path, options = {}) {
|
|
63
|
-
var _focusSelectorsCopy2;
|
|
64
63
|
const {
|
|
65
64
|
focusSelectors
|
|
66
65
|
} = state;
|
|
@@ -85,8 +84,7 @@ function goTo(state, path, options = {}) {
|
|
|
85
84
|
}
|
|
86
85
|
let focusSelectorsCopy;
|
|
87
86
|
function getFocusSelectorsCopy() {
|
|
88
|
-
|
|
89
|
-
focusSelectorsCopy = (_focusSelectorsCopy = focusSelectorsCopy) !== null && _focusSelectorsCopy !== void 0 ? _focusSelectorsCopy : new Map(state.focusSelectors);
|
|
87
|
+
focusSelectorsCopy = focusSelectorsCopy ?? new Map(state.focusSelectors);
|
|
90
88
|
return focusSelectorsCopy;
|
|
91
89
|
}
|
|
92
90
|
if (focusTargetSelector && currentLocation.path) {
|
|
@@ -109,7 +107,7 @@ function goTo(state, path, options = {}) {
|
|
|
109
107
|
focusTargetSelector: currentFocusSelector,
|
|
110
108
|
skipFocus
|
|
111
109
|
},
|
|
112
|
-
focusSelectors:
|
|
110
|
+
focusSelectors: focusSelectorsCopy ?? focusSelectors
|
|
113
111
|
};
|
|
114
112
|
}
|
|
115
113
|
function goToParent(state, options = {}) {
|
|
@@ -236,15 +234,12 @@ function UnconnectedNavigator(props, forwardedRef) {
|
|
|
236
234
|
currentLocation,
|
|
237
235
|
matchedPath
|
|
238
236
|
} = routerState;
|
|
239
|
-
const navigatorContextValue = (0, import_element.useMemo)(() => {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
...methods
|
|
246
|
-
};
|
|
247
|
-
}, [currentLocation, matchedPath, methods]);
|
|
237
|
+
const navigatorContextValue = (0, import_element.useMemo)(() => ({
|
|
238
|
+
location: currentLocation,
|
|
239
|
+
params: matchedPath?.params ?? {},
|
|
240
|
+
match: matchedPath?.id,
|
|
241
|
+
...methods
|
|
242
|
+
}), [currentLocation, matchedPath, methods]);
|
|
248
243
|
const cx = (0, import_use_cx.useCx)();
|
|
249
244
|
const classes = (0, import_element.useMemo)(() => cx(styles.navigatorWrapper, className), [className, cx]);
|
|
250
245
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_view.View, {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/navigator/navigator/component.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\n\n/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport { useMemo, useReducer } from '@wordpress/element';\nimport { isShallowEqual } from '@wordpress/is-shallow-equal';\nimport warning from '@wordpress/warning';\n\n/**\n * Internal dependencies\n */\n\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 { jsx as _jsx } from \"react/jsx-runtime\";\nfunction addScreen({\n screens\n}, screen) {\n if (screens.some(s => s.path === screen.path)) {\n globalThis.SCRIPT_DEBUG === true ? warning(`Navigator: a screen with path ${screen.path} already exists.\nThe screen with id ${screen.id} will not be added.`) : void 0;\n return screens;\n }\n return [...screens, screen];\n}\nfunction removeScreen({\n screens\n}, screen) {\n return screens.filter(s => s.id !== screen.id);\n}\nfunction goTo(state, path, options = {}) {\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,wBAAuB;AACvB,qBAAoC;AACpC,8BAA+B;AAC/B,qBAAoB;AAMpB,qBAAiD;AACjD,oBAAsB;AACtB,oBAAyC;AACzC,kBAAqB;AACrB,IAAAA,kBAAiC;AACjC,aAAwB;AACxB,yBAA4B;AAC5B,SAAS,UAAU;AAAA,EACjB;AACF,GAAG,QAAQ;AACT,MAAI,QAAQ,KAAK,OAAK,EAAE,SAAS,OAAO,IAAI,GAAG;AAC7C,eAAW,iBAAiB,WAAO,eAAAC,SAAQ,iCAAiC,OAAO,IAAI;AAAA,qBACtE,OAAO,EAAE,qBAAqB,IAAI;AACnD,WAAO;AAAA,EACT;AACA,SAAO,CAAC,GAAG,SAAS,MAAM;AAC5B;AACA,SAAS,aAAa;AAAA,EACpB;AACF,GAAG,QAAQ;AACT,SAAO,QAAQ,OAAO,OAAK,EAAE,OAAO,OAAO,EAAE;AAC/C;AACA,SAAS,KAAK,OAAO,MAAM,UAAU,CAAC,GAAG;AACvC,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\n\n/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport { useMemo, useReducer } from '@wordpress/element';\nimport { isShallowEqual } from '@wordpress/is-shallow-equal';\nimport warning from '@wordpress/warning';\n\n/**\n * Internal dependencies\n */\n\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 { jsx as _jsx } from \"react/jsx-runtime\";\nfunction addScreen({\n screens\n}, screen) {\n if (screens.some(s => s.path === screen.path)) {\n globalThis.SCRIPT_DEBUG === true ? warning(`Navigator: a screen with path ${screen.path} already exists.\nThe screen with id ${screen.id} will not be added.`) : void 0;\n return screens;\n }\n return [...screens, screen];\n}\nfunction removeScreen({\n screens\n}, screen) {\n return screens.filter(s => s.id !== screen.id);\n}\nfunction goTo(state, path, options = {}) {\n const {\n focusSelectors\n } = state;\n const currentLocation = {\n ...state.currentLocation\n };\n const {\n // Default assignments\n isBack = false,\n skipFocus = false,\n // Extract to avoid forwarding\n replace,\n focusTargetSelector,\n // Rest\n ...restOptions\n } = options;\n if (currentLocation.path === path) {\n return {\n currentLocation,\n focusSelectors\n };\n }\n let focusSelectorsCopy;\n function getFocusSelectorsCopy() {\n focusSelectorsCopy = focusSelectorsCopy ?? new Map(state.focusSelectors);\n return focusSelectorsCopy;\n }\n\n // Set a focus selector that will be used when navigating\n // back to the current location.\n if (focusTargetSelector && currentLocation.path) {\n getFocusSelectorsCopy().set(currentLocation.path, focusTargetSelector);\n }\n\n // Get the focus selector for the new location.\n let currentFocusSelector;\n if (focusSelectors.get(path)) {\n if (isBack) {\n // Use the found focus selector only when navigating back.\n currentFocusSelector = focusSelectors.get(path);\n }\n // Make a copy of the focusSelectors map to remove the focus selector\n // only if necessary (ie. a focus selector was found).\n getFocusSelectorsCopy().delete(path);\n }\n return {\n currentLocation: {\n ...restOptions,\n isInitial: false,\n path,\n isBack,\n hasRestoredFocus: false,\n focusTargetSelector: currentFocusSelector,\n skipFocus\n },\n focusSelectors: focusSelectorsCopy ?? focusSelectors\n };\n}\nfunction goToParent(state, options = {}) {\n const {\n screens,\n focusSelectors\n } = state;\n const currentLocation = {\n ...state.currentLocation\n };\n const currentPath = currentLocation.path;\n if (currentPath === undefined) {\n return {\n currentLocation,\n focusSelectors\n };\n }\n const parentPath = findParent(currentPath, screens);\n if (parentPath === undefined) {\n return {\n currentLocation,\n focusSelectors\n };\n }\n return goTo(state, parentPath, {\n ...options,\n isBack: true\n });\n}\nfunction routerReducer(state, action) {\n let {\n screens,\n currentLocation,\n matchedPath,\n focusSelectors,\n ...restState\n } = state;\n switch (action.type) {\n case 'add':\n screens = addScreen(state, action.screen);\n break;\n case 'remove':\n screens = removeScreen(state, action.screen);\n break;\n case 'goto':\n ({\n currentLocation,\n focusSelectors\n } = goTo(state, action.path, action.options));\n break;\n case 'gotoparent':\n ({\n currentLocation,\n focusSelectors\n } = goToParent(state, action.options));\n break;\n }\n\n // Return early in case there is no change\n if (screens === state.screens && currentLocation === state.currentLocation) {\n return state;\n }\n\n // Compute the matchedPath\n const currentPath = currentLocation.path;\n matchedPath = currentPath !== undefined ? patternMatch(currentPath, screens) : undefined;\n\n // If the new match is the same as the previous match,\n // return the previous one to keep immutability.\n if (matchedPath && state.matchedPath && matchedPath.id === state.matchedPath.id && isShallowEqual(matchedPath.params, state.matchedPath.params)) {\n matchedPath = state.matchedPath;\n }\n return {\n ...restState,\n screens,\n currentLocation,\n matchedPath,\n focusSelectors\n };\n}\nfunction UnconnectedNavigator(props, forwardedRef) {\n const {\n initialPath: initialPathProp,\n children,\n className,\n ...otherProps\n } = useContextSystem(props, 'Navigator');\n const [routerState, dispatch] = useReducer(routerReducer, initialPathProp, path => ({\n screens: [],\n currentLocation: {\n path,\n isInitial: true\n },\n matchedPath: undefined,\n focusSelectors: new Map(),\n initialPath: initialPathProp\n }));\n\n // The methods are constant forever, create stable references to them.\n const methods = useMemo(() => ({\n // Note: calling goBack calls `goToParent` internally, as it was established\n // that `goBack` should behave like `goToParent`, and `goToParent` should\n // be marked as deprecated.\n goBack: options => dispatch({\n type: 'gotoparent',\n options\n }),\n goTo: (path, options) => dispatch({\n type: 'goto',\n path,\n options\n }),\n goToParent: options => {\n deprecated(`wp.components.useNavigator().goToParent`, {\n since: '6.7',\n alternative: 'wp.components.useNavigator().goBack'\n });\n dispatch({\n type: 'gotoparent',\n options\n });\n },\n addScreen: screen => dispatch({\n type: 'add',\n screen\n }),\n removeScreen: screen => dispatch({\n type: 'remove',\n screen\n })\n }), []);\n const {\n currentLocation,\n matchedPath\n } = routerState;\n const navigatorContextValue = useMemo(() => ({\n location: currentLocation,\n params: matchedPath?.params ?? {},\n match: matchedPath?.id,\n ...methods\n }), [currentLocation, matchedPath, methods]);\n const cx = useCx();\n const classes = useMemo(() => cx(styles.navigatorWrapper, className), [className, cx]);\n return /*#__PURE__*/_jsx(View, {\n ref: forwardedRef,\n className: classes,\n ...otherProps,\n children: /*#__PURE__*/_jsx(NavigatorContext.Provider, {\n value: navigatorContextValue,\n children: children\n })\n });\n}\nexport const Navigator = contextConnect(UnconnectedNavigator, 'Navigator');"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,wBAAuB;AACvB,qBAAoC;AACpC,8BAA+B;AAC/B,qBAAoB;AAMpB,qBAAiD;AACjD,oBAAsB;AACtB,oBAAyC;AACzC,kBAAqB;AACrB,IAAAA,kBAAiC;AACjC,aAAwB;AACxB,yBAA4B;AAC5B,SAAS,UAAU;AAAA,EACjB;AACF,GAAG,QAAQ;AACT,MAAI,QAAQ,KAAK,OAAK,EAAE,SAAS,OAAO,IAAI,GAAG;AAC7C,eAAW,iBAAiB,WAAO,eAAAC,SAAQ,iCAAiC,OAAO,IAAI;AAAA,qBACtE,OAAO,EAAE,qBAAqB,IAAI;AACnD,WAAO;AAAA,EACT;AACA,SAAO,CAAC,GAAG,SAAS,MAAM;AAC5B;AACA,SAAS,aAAa;AAAA,EACpB;AACF,GAAG,QAAQ;AACT,SAAO,QAAQ,OAAO,OAAK,EAAE,OAAO,OAAO,EAAE;AAC/C;AACA,SAAS,KAAK,OAAO,MAAM,UAAU,CAAC,GAAG;AACvC,QAAM;AAAA,IACJ;AAAA,EACF,IAAI;AACJ,QAAM,kBAAkB;AAAA,IACtB,GAAG,MAAM;AAAA,EACX;AACA,QAAM;AAAA;AAAA,IAEJ,SAAS;AAAA,IACT,YAAY;AAAA;AAAA,IAEZ;AAAA,IACA;AAAA;AAAA,IAEA,GAAG;AAAA,EACL,IAAI;AACJ,MAAI,gBAAgB,SAAS,MAAM;AACjC,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACA,MAAI;AACJ,WAAS,wBAAwB;AAC/B,yBAAqB,sBAAsB,IAAI,IAAI,MAAM,cAAc;AACvE,WAAO;AAAA,EACT;AAIA,MAAI,uBAAuB,gBAAgB,MAAM;AAC/C,0BAAsB,EAAE,IAAI,gBAAgB,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ACH;AAAA,IACA,WAAW,YAAU,SAAS;AAAA,MAC5B,MAAM;AAAA,MACN;AAAA,IACF,CAAC;AAAA,IACD,cAAc,YAAU,SAAS;AAAA,MAC/B,MAAM;AAAA,MACN;AAAA,IACF,CAAC;AAAA,EACH,IAAI,CAAC,CAAC;AACN,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,EACF,IAAI;AACJ,QAAM,4BAAwB,wBAAQ,OAAO;AAAA,IAC3C,UAAU;AAAA,IACV,QAAQ,aAAa,UAAU,CAAC;AAAA,IAChC,OAAO,aAAa;AAAA,IACpB,GAAG;AAAA,EACL,IAAI,CAAC,iBAAiB,aAAa,OAAO,CAAC;AAC3C,QAAM,SAAK,qBAAM;AACjB,QAAM,cAAU,wBAAQ,MAAM,GAAU,yBAAkB,SAAS,GAAG,CAAC,WAAW,EAAE,CAAC;AACrF,SAAoB,uCAAAC,KAAK,kBAAM;AAAA,IAC7B,KAAK;AAAA,IACL,WAAW;AAAA,IACX,GAAG;AAAA,IACH,UAAuB,uCAAAA,KAAK,iCAAiB,UAAU;AAAA,MACrD,OAAO;AAAA,MACP;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;AACO,IAAM,gBAAY,+BAAe,sBAAsB,WAAW;",
|
|
6
6
|
"names": ["import_context", "warning", "deprecated", "_jsx"]
|
|
7
7
|
}
|
|
@@ -111,7 +111,7 @@ function UnconnectedNavigatorScreen(props, forwardedRef) {
|
|
|
111
111
|
}
|
|
112
112
|
if (!elementToFocus) {
|
|
113
113
|
const [firstTabbable] = import_dom.focus.tabbable.find(wrapperEl);
|
|
114
|
-
elementToFocus = firstTabbable
|
|
114
|
+
elementToFocus = firstTabbable ?? wrapperEl;
|
|
115
115
|
}
|
|
116
116
|
locationRef.current.hasRestoredFocus = true;
|
|
117
117
|
elementToFocus.focus();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/navigator/navigator-screen/component.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\n\n/**\n * WordPress dependencies\n */\nimport { focus } from '@wordpress/dom';\nimport { useContext, useEffect, useMemo, useRef, useId } from '@wordpress/element';\nimport { useMergeRefs } from '@wordpress/compose';\nimport { escapeAttribute } from '@wordpress/escape-html';\nimport warning from '@wordpress/warning';\n\n/**\n * Internal dependencies\n */\n\nimport { contextConnect, useContextSystem } from '../../context';\nimport { useCx } from '../../utils/hooks/use-cx';\nimport { View } from '../../view';\nimport { NavigatorContext } from '../context';\nimport * as styles from '../styles';\nimport { useScreenAnimatePresence } from './use-screen-animate-presence';\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nfunction UnconnectedNavigatorScreen(props, forwardedRef) {\n if (!/^\\//.test(props.path)) {\n globalThis.SCRIPT_DEBUG === true ? warning('wp.components.Navigator.Screen: the `path` should follow a URL-like scheme; it should start with and be separated by the `/` character.') : void 0;\n }\n const screenId = useId();\n const {\n children,\n className,\n path,\n onAnimationEnd: onAnimationEndProp,\n ...otherProps\n } = useContextSystem(props, 'Navigator.Screen');\n const {\n location,\n match,\n addScreen,\n removeScreen\n } = useContext(NavigatorContext);\n const {\n isInitial,\n isBack,\n focusTargetSelector,\n skipFocus\n } = location;\n const isMatch = match === screenId;\n const wrapperRef = useRef(null);\n const skipAnimationAndFocusRestoration = !!isInitial && !isBack;\n\n // Register / unregister screen with the navigator context.\n useEffect(() => {\n const screen = {\n id: screenId,\n path: escapeAttribute(path)\n };\n addScreen(screen);\n return () => removeScreen(screen);\n }, [screenId, path, addScreen, removeScreen]);\n\n // Animation.\n const {\n animationStyles,\n shouldRenderScreen,\n screenProps\n } = useScreenAnimatePresence({\n isMatch,\n isBack,\n onAnimationEnd: onAnimationEndProp,\n skipAnimation: skipAnimationAndFocusRestoration\n });\n const cx = useCx();\n const classes = useMemo(() => cx(styles.navigatorScreen, animationStyles, className), [className, cx, animationStyles]);\n\n // Focus restoration\n const locationRef = useRef(location);\n useEffect(() => {\n locationRef.current = location;\n }, [location]);\n useEffect(() => {\n const wrapperEl = wrapperRef.current;\n // Only attempt to restore focus:\n // - if the current location is not the initial one (to avoid moving focus on page load)\n // - when the screen becomes visible\n // - if the wrapper ref has been assigned\n // - if focus hasn't already been restored for the current location\n // - if the `skipFocus` option is not set to `true`. This is useful when we trigger the navigation outside of NavigatorScreen.\n if (skipAnimationAndFocusRestoration || !isMatch || !wrapperEl || locationRef.current.hasRestoredFocus || skipFocus) {\n return;\n }\n const activeElement = wrapperEl.ownerDocument.activeElement;\n\n // If an element is already focused within the wrapper do not focus the\n // element. This prevents inputs or buttons from losing focus unnecessarily.\n if (wrapperEl.contains(activeElement)) {\n return;\n }\n let elementToFocus = null;\n\n // When navigating back, if a selector is provided, use it to look for the\n // target element (assumed to be a node inside the current NavigatorScreen)\n if (isBack && focusTargetSelector) {\n elementToFocus = wrapperEl.querySelector(focusTargetSelector);\n }\n\n // If the previous query didn't run or find any element to focus, fallback\n // to the first tabbable element in the screen (or the screen itself).\n if (!elementToFocus) {\n const [firstTabbable] = focus.tabbable.find(wrapperEl);\n elementToFocus = firstTabbable
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,iBAAsB;AACtB,qBAA8D;AAC9D,qBAA6B;AAC7B,yBAAgC;AAChC,qBAAoB;AAMpB,qBAAiD;AACjD,oBAAsB;AACtB,kBAAqB;AACrB,IAAAA,kBAAiC;AACjC,aAAwB;AACxB,yCAAyC;AACzC,yBAA4B;AAC5B,SAAS,2BAA2B,OAAO,cAAc;AACvD,MAAI,CAAC,MAAM,KAAK,MAAM,IAAI,GAAG;AAC3B,eAAW,iBAAiB,WAAO,eAAAC,SAAQ,yIAAyI,IAAI;AAAA,EAC1L;AACA,QAAM,eAAW,sBAAM;AACvB,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB;AAAA,IAChB,GAAG;AAAA,EACL,QAAI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aAAa,IAAI,iBAAM,SAAS,KAAK,SAAS;AACrD,uBAAiB,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\n\n/**\n * WordPress dependencies\n */\nimport { focus } from '@wordpress/dom';\nimport { useContext, useEffect, useMemo, useRef, useId } from '@wordpress/element';\nimport { useMergeRefs } from '@wordpress/compose';\nimport { escapeAttribute } from '@wordpress/escape-html';\nimport warning from '@wordpress/warning';\n\n/**\n * Internal dependencies\n */\n\nimport { contextConnect, useContextSystem } from '../../context';\nimport { useCx } from '../../utils/hooks/use-cx';\nimport { View } from '../../view';\nimport { NavigatorContext } from '../context';\nimport * as styles from '../styles';\nimport { useScreenAnimatePresence } from './use-screen-animate-presence';\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nfunction UnconnectedNavigatorScreen(props, forwardedRef) {\n if (!/^\\//.test(props.path)) {\n globalThis.SCRIPT_DEBUG === true ? warning('wp.components.Navigator.Screen: the `path` should follow a URL-like scheme; it should start with and be separated by the `/` character.') : void 0;\n }\n const screenId = useId();\n const {\n children,\n className,\n path,\n onAnimationEnd: onAnimationEndProp,\n ...otherProps\n } = useContextSystem(props, 'Navigator.Screen');\n const {\n location,\n match,\n addScreen,\n removeScreen\n } = useContext(NavigatorContext);\n const {\n isInitial,\n isBack,\n focusTargetSelector,\n skipFocus\n } = location;\n const isMatch = match === screenId;\n const wrapperRef = useRef(null);\n const skipAnimationAndFocusRestoration = !!isInitial && !isBack;\n\n // Register / unregister screen with the navigator context.\n useEffect(() => {\n const screen = {\n id: screenId,\n path: escapeAttribute(path)\n };\n addScreen(screen);\n return () => removeScreen(screen);\n }, [screenId, path, addScreen, removeScreen]);\n\n // Animation.\n const {\n animationStyles,\n shouldRenderScreen,\n screenProps\n } = useScreenAnimatePresence({\n isMatch,\n isBack,\n onAnimationEnd: onAnimationEndProp,\n skipAnimation: skipAnimationAndFocusRestoration\n });\n const cx = useCx();\n const classes = useMemo(() => cx(styles.navigatorScreen, animationStyles, className), [className, cx, animationStyles]);\n\n // Focus restoration\n const locationRef = useRef(location);\n useEffect(() => {\n locationRef.current = location;\n }, [location]);\n useEffect(() => {\n const wrapperEl = wrapperRef.current;\n // Only attempt to restore focus:\n // - if the current location is not the initial one (to avoid moving focus on page load)\n // - when the screen becomes visible\n // - if the wrapper ref has been assigned\n // - if focus hasn't already been restored for the current location\n // - if the `skipFocus` option is not set to `true`. This is useful when we trigger the navigation outside of NavigatorScreen.\n if (skipAnimationAndFocusRestoration || !isMatch || !wrapperEl || locationRef.current.hasRestoredFocus || skipFocus) {\n return;\n }\n const activeElement = wrapperEl.ownerDocument.activeElement;\n\n // If an element is already focused within the wrapper do not focus the\n // element. This prevents inputs or buttons from losing focus unnecessarily.\n if (wrapperEl.contains(activeElement)) {\n return;\n }\n let elementToFocus = null;\n\n // When navigating back, if a selector is provided, use it to look for the\n // target element (assumed to be a node inside the current NavigatorScreen)\n if (isBack && focusTargetSelector) {\n elementToFocus = wrapperEl.querySelector(focusTargetSelector);\n }\n\n // If the previous query didn't run or find any element to focus, fallback\n // to the first tabbable element in the screen (or the screen itself).\n if (!elementToFocus) {\n const [firstTabbable] = focus.tabbable.find(wrapperEl);\n elementToFocus = firstTabbable ?? wrapperEl;\n }\n locationRef.current.hasRestoredFocus = true;\n elementToFocus.focus();\n }, [skipAnimationAndFocusRestoration, isMatch, isBack, focusTargetSelector, skipFocus]);\n const mergedWrapperRef = useMergeRefs([forwardedRef, wrapperRef]);\n return shouldRenderScreen ? /*#__PURE__*/_jsx(View, {\n ref: mergedWrapperRef,\n className: classes,\n ...screenProps,\n ...otherProps,\n children: children\n }) : null;\n}\nexport const NavigatorScreen = contextConnect(UnconnectedNavigatorScreen, 'Navigator.Screen');"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,iBAAsB;AACtB,qBAA8D;AAC9D,qBAA6B;AAC7B,yBAAgC;AAChC,qBAAoB;AAMpB,qBAAiD;A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Q,CAAC;AACb,gCAAU,MAAM;AACd,UAAM,YAAY,WAAW;AAO7B,QAAI,oCAAoC,CAAC,WAAW,CAAC,aAAa,YAAY,QAAQ,oBAAoB,WAAW;AACnH;AAAA,IACF;AACA,UAAM,gBAAgB,UAAU,cAAc;AAI9C,QAAI,UAAU,SAAS,aAAa,GAAG;AACrC;AAAA,IACF;AACA,QAAI,iBAAiB;AAIrB,QAAI,UAAU,qBAAqB;AACjC,uBAAiB,UAAU,cAAc,mBAAmB;AAAA,IAC9D;AAIA,QAAI,CAAC,gBAAgB;AACnB,YAAM,CAAC,aAAa,IAAI,iBAAM,SAAS,KAAK,SAAS;AACrD,uBAAiB,iBAAiB;AAAA,IACpC;AACA,gBAAY,QAAQ,mBAAmB;AACvC,mBAAe,MAAM;AAAA,EACvB,GAAG,CAAC,kCAAkC,SAAS,QAAQ,qBAAqB,SAAS,CAAC;AACtF,QAAM,uBAAmB,6BAAa,CAAC,cAAc,UAAU,CAAC;AAChE,SAAO,qBAAkC,uCAAAC,KAAK,kBAAM;AAAA,IAClD,KAAK;AAAA,IACL,WAAW;AAAA,IACX,GAAG;AAAA,IACH,GAAG;AAAA,IACH;AAAA,EACF,CAAC,IAAI;AACP;AACO,IAAM,sBAAkB,+BAAe,4BAA4B,kBAAkB;",
|
|
6
6
|
"names": ["import_context", "warning", "_jsx"]
|
|
7
7
|
}
|
|
@@ -96,7 +96,7 @@ function UnforwardedNumberControl(props, forwardedRef) {
|
|
|
96
96
|
const baseSpin = (0, import_values.ensureNumber)(spinFactor) * baseStep;
|
|
97
97
|
const constrainValue = (value, stepOverride) => {
|
|
98
98
|
if (!isStepAny) {
|
|
99
|
-
value = (0, import_math.ensureValidStep)(value, min, stepOverride
|
|
99
|
+
value = (0, import_math.ensureValidStep)(value, min, stepOverride ?? baseStep);
|
|
100
100
|
}
|
|
101
101
|
return `${(0, import_math.clamp)(value, min, max)}`;
|
|
102
102
|
};
|
|
@@ -198,9 +198,8 @@ function UnforwardedNumberControl(props, forwardedRef) {
|
|
|
198
198
|
type: typeProp,
|
|
199
199
|
value: valueProp,
|
|
200
200
|
__unstableStateReducer: (state, action) => {
|
|
201
|
-
var _stateReducerProp;
|
|
202
201
|
const baseState = numberControlStateReducer(state, action);
|
|
203
|
-
return
|
|
202
|
+
return stateReducerProp?.(baseState, action) ?? baseState;
|
|
204
203
|
},
|
|
205
204
|
size,
|
|
206
205
|
__shouldNotWarnDeprecated36pxSize: true,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/number-control/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n/**\n * WordPress dependencies\n */\nimport { useRef, forwardRef } from '@wordpress/element';\nimport { isRTL, __ } from '@wordpress/i18n';\nimport { plus as plusIcon, reset as resetIcon } from '@wordpress/icons';\nimport { useMergeRefs } from '@wordpress/compose';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { Input, SpinButton, styles } from './styles/number-control-styles';\nimport * as inputControlActionTypes from '../input-control/reducer/actions';\nimport { add, subtract, clamp, ensureValidStep } from '../utils/math';\nimport { ensureNumber, isValueEmpty } from '../utils/values';\nimport { HStack } from '../h-stack';\nimport { Spacer } from '../spacer';\nimport { useCx } from '../utils';\nimport { useDeprecated36pxDefaultSizeProp } from '../utils/use-deprecated-props';\nimport { maybeWarnDeprecated36pxSize } from '../utils/deprecated-36px-size';\nimport { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from \"react/jsx-runtime\";\nconst noop = () => {};\nfunction UnforwardedNumberControl(props, forwardedRef) {\n const {\n __unstableStateReducer: stateReducerProp,\n className,\n dragDirection = 'n',\n hideHTMLArrows = false,\n spinControls = hideHTMLArrows ? 'none' : 'native',\n isDragEnabled = true,\n isShiftStepEnabled = true,\n label,\n max = Infinity,\n min = -Infinity,\n required = false,\n shiftStep = 10,\n step = 1,\n spinFactor = 1,\n type: typeProp = 'number',\n value: valueProp,\n size = 'default',\n suffix,\n onChange = noop,\n __shouldNotWarnDeprecated36pxSize,\n ...restProps\n } = useDeprecated36pxDefaultSizeProp(props);\n maybeWarnDeprecated36pxSize({\n componentName: 'NumberControl',\n size,\n __next40pxDefaultSize: restProps.__next40pxDefaultSize,\n __shouldNotWarnDeprecated36pxSize\n });\n if (hideHTMLArrows) {\n deprecated('wp.components.NumberControl hideHTMLArrows prop ', {\n alternative: 'spinControls=\"none\"',\n since: '6.2',\n version: '6.3'\n });\n }\n const inputRef = useRef();\n const mergedRef = useMergeRefs([inputRef, forwardedRef]);\n const isStepAny = step === 'any';\n const baseStep = isStepAny ? 1 : ensureNumber(step);\n const baseSpin = ensureNumber(spinFactor) * baseStep;\n const constrainValue = (value, stepOverride) => {\n // When step is not \"any\" the value must be a valid step.\n if (!isStepAny) {\n value = ensureValidStep(value, min, stepOverride
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAIjB,qBAAmC;AACnC,kBAA0B;AAC1B,mBAAqD;AACrD,qBAA6B;AAC7B,wBAAuB;AAKvB,mCAA0C;AAC1C,8BAAyC;AACzC,kBAAsD;AACtD,oBAA2C;AAC3C,qBAAuB;AACvB,oBAAuB;AACvB,mBAAsB;AACtB,kCAAiD;AACjD,kCAA4C;AAC5C,yBAAkE;AAClE,IAAM,OAAO,MAAM;AAAC;AACpB,SAAS,yBAAyB,OAAO,cAAc;AACrD,QAAM;AAAA,IACJ,wBAAwB;AAAA,IACxB;AAAA,IACA,gBAAgB;AAAA,IAChB,iBAAiB;AAAA,IACjB,eAAe,iBAAiB,SAAS;AAAA,IACzC,gBAAgB;AAAA,IAChB,qBAAqB;AAAA,IACrB;AAAA,IACA,MAAM;AAAA,IACN,MAAM;AAAA,IACN,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,OAAO;AAAA,IACP,aAAa;AAAA,IACb,MAAM,WAAW;AAAA,IACjB,OAAO;AAAA,IACP,OAAO;AAAA,IACP;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA,GAAG;AAAA,EACL,QAAI,8DAAiC,KAAK;AAC1C,+DAA4B;AAAA,IAC1B,eAAe;AAAA,IACf;AAAA,IACA,uBAAuB,UAAU;AAAA,IACjC;AAAA,EACF,CAAC;AACD,MAAI,gBAAgB;AAClB,0BAAAA,SAAW,oDAAoD;AAAA,MAC7D,aAAa;AAAA,MACb,OAAO;AAAA,MACP,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AACA,QAAM,eAAW,uBAAO;AACxB,QAAM,gBAAY,6BAAa,CAAC,UAAU,YAAY,CAAC;AACvD,QAAM,YAAY,SAAS;AAC3B,QAAM,WAAW,YAAY,QAAI,4BAAa,IAAI;AAClD,QAAM,eAAW,4BAAa,UAAU,IAAI;AAC5C,QAAM,iBAAiB,CAAC,OAAO,iBAAiB;AAE9C,QAAI,CAAC,WAAW;AACd,kBAAQ,6BAAgB,OAAO,KAAK,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n/**\n * WordPress dependencies\n */\nimport { useRef, forwardRef } from '@wordpress/element';\nimport { isRTL, __ } from '@wordpress/i18n';\nimport { plus as plusIcon, reset as resetIcon } from '@wordpress/icons';\nimport { useMergeRefs } from '@wordpress/compose';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { Input, SpinButton, styles } from './styles/number-control-styles';\nimport * as inputControlActionTypes from '../input-control/reducer/actions';\nimport { add, subtract, clamp, ensureValidStep } from '../utils/math';\nimport { ensureNumber, isValueEmpty } from '../utils/values';\nimport { HStack } from '../h-stack';\nimport { Spacer } from '../spacer';\nimport { useCx } from '../utils';\nimport { useDeprecated36pxDefaultSizeProp } from '../utils/use-deprecated-props';\nimport { maybeWarnDeprecated36pxSize } from '../utils/deprecated-36px-size';\nimport { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from \"react/jsx-runtime\";\nconst noop = () => {};\nfunction UnforwardedNumberControl(props, forwardedRef) {\n const {\n __unstableStateReducer: stateReducerProp,\n className,\n dragDirection = 'n',\n hideHTMLArrows = false,\n spinControls = hideHTMLArrows ? 'none' : 'native',\n isDragEnabled = true,\n isShiftStepEnabled = true,\n label,\n max = Infinity,\n min = -Infinity,\n required = false,\n shiftStep = 10,\n step = 1,\n spinFactor = 1,\n type: typeProp = 'number',\n value: valueProp,\n size = 'default',\n suffix,\n onChange = noop,\n __shouldNotWarnDeprecated36pxSize,\n ...restProps\n } = useDeprecated36pxDefaultSizeProp(props);\n maybeWarnDeprecated36pxSize({\n componentName: 'NumberControl',\n size,\n __next40pxDefaultSize: restProps.__next40pxDefaultSize,\n __shouldNotWarnDeprecated36pxSize\n });\n if (hideHTMLArrows) {\n deprecated('wp.components.NumberControl hideHTMLArrows prop ', {\n alternative: 'spinControls=\"none\"',\n since: '6.2',\n version: '6.3'\n });\n }\n const inputRef = useRef();\n const mergedRef = useMergeRefs([inputRef, forwardedRef]);\n const isStepAny = step === 'any';\n const baseStep = isStepAny ? 1 : ensureNumber(step);\n const baseSpin = ensureNumber(spinFactor) * baseStep;\n const constrainValue = (value, stepOverride) => {\n // When step is not \"any\" the value must be a valid step.\n if (!isStepAny) {\n value = ensureValidStep(value, min, stepOverride ?? baseStep);\n }\n return `${clamp(value, min, max)}`;\n };\n const baseValue = constrainValue(0);\n const autoComplete = typeProp === 'number' ? 'off' : undefined;\n const classes = clsx('components-number-control', className);\n const cx = useCx();\n const spinButtonClasses = cx(size === 'small' && styles.smallSpinButtons);\n const spinValue = (value, direction, event) => {\n event?.preventDefault();\n const shift = event?.shiftKey && isShiftStepEnabled;\n const delta = shift ? ensureNumber(shiftStep) * baseSpin : baseSpin;\n let nextValue = isValueEmpty(value) ? baseValue : value;\n if (direction === 'up') {\n nextValue = add(nextValue, delta);\n } else if (direction === 'down') {\n nextValue = subtract(nextValue, delta);\n }\n return constrainValue(nextValue, shift ? delta : undefined);\n };\n\n /**\n * \"Middleware\" function that intercepts updates from InputControl.\n * This allows us to tap into actions to transform the (next) state for\n * InputControl.\n *\n * @return The updated state to apply to InputControl\n */\n const numberControlStateReducer = (state, action) => {\n const nextState = {\n ...state\n };\n const {\n type,\n payload\n } = action;\n const event = payload.event;\n const currentValue = nextState.value;\n\n /**\n * Handles custom UP and DOWN Keyboard events\n */\n if (type === inputControlActionTypes.PRESS_UP || type === inputControlActionTypes.PRESS_DOWN) {\n nextState.value = spinValue(currentValue, type === inputControlActionTypes.PRESS_UP ? 'up' : 'down', event);\n }\n\n /**\n * Handles drag to update events\n */\n if (type === inputControlActionTypes.DRAG && isDragEnabled) {\n const [x, y] = payload.delta;\n const enableShift = payload.shiftKey && isShiftStepEnabled;\n const modifier = enableShift ? ensureNumber(shiftStep) * baseSpin : baseSpin;\n let directionModifier;\n let delta;\n switch (dragDirection) {\n case 'n':\n delta = y;\n directionModifier = -1;\n break;\n case 'e':\n delta = x;\n directionModifier = isRTL() ? -1 : 1;\n break;\n case 's':\n delta = y;\n directionModifier = 1;\n break;\n case 'w':\n delta = x;\n directionModifier = isRTL() ? 1 : -1;\n break;\n }\n if (delta !== 0) {\n delta = Math.ceil(Math.abs(delta)) * Math.sign(delta);\n const distance = delta * modifier * directionModifier;\n nextState.value = constrainValue(\n // @ts-expect-error TODO: Investigate if it's ok for currentValue to be undefined\n add(currentValue, distance), enableShift ? modifier : undefined);\n }\n }\n\n /**\n * Handles commit (ENTER key press or blur)\n */\n if (type === inputControlActionTypes.PRESS_ENTER || type === inputControlActionTypes.COMMIT) {\n const applyEmptyValue = required === false && currentValue === '';\n nextState.value = applyEmptyValue ? currentValue :\n // @ts-expect-error TODO: Investigate if it's ok for currentValue to be undefined\n constrainValue(currentValue);\n }\n return nextState;\n };\n const buildSpinButtonClickHandler = direction => event => onChange(String(spinValue(valueProp, direction, event)), {\n // Set event.target to the <input> so that consumers can use\n // e.g. event.target.validity.\n event: {\n ...event,\n target: inputRef.current\n }\n });\n return /*#__PURE__*/_jsx(Input, {\n autoComplete: autoComplete,\n inputMode: \"numeric\",\n ...restProps,\n className: classes,\n dragDirection: dragDirection,\n hideHTMLArrows: spinControls !== 'native',\n isDragEnabled: isDragEnabled,\n label: label,\n max: max === Infinity ? undefined : max,\n min: min === -Infinity ? undefined : min,\n ref: mergedRef,\n required: required,\n step: step,\n type: typeProp\n // @ts-expect-error TODO: Resolve discrepancy between `value` types in InputControl based components\n ,\n value: valueProp,\n __unstableStateReducer: (state, action) => {\n const baseState = numberControlStateReducer(state, action);\n return stateReducerProp?.(baseState, action) ?? baseState;\n },\n size: size,\n __shouldNotWarnDeprecated36pxSize: true,\n suffix: spinControls === 'custom' ? /*#__PURE__*/_jsxs(_Fragment, {\n children: [suffix, /*#__PURE__*/_jsx(Spacer, {\n marginBottom: 0,\n marginRight: 2,\n children: /*#__PURE__*/_jsxs(HStack, {\n spacing: 1,\n children: [/*#__PURE__*/_jsx(SpinButton, {\n className: spinButtonClasses,\n icon: plusIcon,\n size: \"small\",\n label: __('Increment'),\n onClick: buildSpinButtonClickHandler('up')\n }), /*#__PURE__*/_jsx(SpinButton, {\n className: spinButtonClasses,\n icon: resetIcon,\n size: \"small\",\n label: __('Decrement'),\n onClick: buildSpinButtonClickHandler('down')\n })]\n })\n })]\n }) : suffix,\n onChange: onChange\n });\n}\nexport const NumberControl = forwardRef(UnforwardedNumberControl);\nNumberControl.displayName = 'NumberControl';\nexport default NumberControl;"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAIjB,qBAAmC;AACnC,kBAA0B;AAC1B,mBAAqD;AACrD,qBAA6B;AAC7B,wBAAuB;AAKvB,mCAA0C;AAC1C,8BAAyC;AACzC,kBAAsD;AACtD,oBAA2C;AAC3C,qBAAuB;AACvB,oBAAuB;AACvB,mBAAsB;AACtB,kCAAiD;AACjD,kCA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AAQ;AAAA,UACnC,SAAS;AAAA,UACT,UAAU,CAAc,uCAAAD,KAAK,yCAAY;AAAA,YACvC,WAAW;AAAA,YACX,MAAM,aAAAG;AAAA,YACN,MAAM;AAAA,YACN,WAAO,gBAAG,WAAW;AAAA,YACrB,SAAS,4BAA4B,IAAI;AAAA,UAC3C,CAAC,GAAgB,uCAAAH,KAAK,yCAAY;AAAA,YAChC,WAAW;AAAA,YACX,MAAM,aAAAI;AAAA,YACN,MAAM;AAAA,YACN,WAAO,gBAAG,WAAW;AAAA,YACrB,SAAS,4BAA4B,MAAM;AAAA,UAC7C,CAAC,CAAC;AAAA,QACJ,CAAC;AAAA,MACH,CAAC,CAAC;AAAA,IACJ,CAAC,IAAI;AAAA,IACL;AAAA,EACF,CAAC;AACH;AACO,IAAM,oBAAgB,2BAAW,wBAAwB;AAChE,cAAc,cAAc;AAC5B,IAAO,yBAAQ;",
|
|
6
6
|
"names": ["deprecated", "clsx", "_jsx", "_jsxs", "_Fragment", "plusIcon", "resetIcon"]
|
|
7
7
|
}
|
|
@@ -74,7 +74,6 @@ function NameInput({
|
|
|
74
74
|
function deduplicateElementSlugs(elements) {
|
|
75
75
|
const slugCounts = {};
|
|
76
76
|
return elements.map((element) => {
|
|
77
|
-
var _newSlug;
|
|
78
77
|
let newSlug;
|
|
79
78
|
const {
|
|
80
79
|
slug
|
|
@@ -85,7 +84,7 @@ function deduplicateElementSlugs(elements) {
|
|
|
85
84
|
}
|
|
86
85
|
return {
|
|
87
86
|
...element,
|
|
88
|
-
slug:
|
|
87
|
+
slug: newSlug ?? slug
|
|
89
88
|
};
|
|
90
89
|
});
|
|
91
90
|
}
|
|
@@ -203,7 +202,7 @@ function Option({
|
|
|
203
202
|
onChange: (nextName) => onChange({
|
|
204
203
|
...element,
|
|
205
204
|
name: nextName,
|
|
206
|
-
slug: slugPrefix + (0, import_strings.kebabCase)(nextName
|
|
205
|
+
slug: slugPrefix + (0, import_strings.kebabCase)(nextName ?? "")
|
|
207
206
|
})
|
|
208
207
|
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_styles.NameContainer, {
|
|
209
208
|
children: element.name.trim().length ? element.name : (
|
|
@@ -420,7 +419,7 @@ function PaletteEdit({
|
|
|
420
419
|
})
|
|
421
420
|
);
|
|
422
421
|
},
|
|
423
|
-
element: elements[editingElement
|
|
422
|
+
element: elements[editingElement ?? -1],
|
|
424
423
|
popoverProps
|
|
425
424
|
}), !isEditing && (isGradient ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_gradient_picker.default, {
|
|
426
425
|
gradients,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/palette-edit/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useState, useRef, useEffect, useCallback, useMemo } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { lineSolid, moreVertical, plus } from '@wordpress/icons';\nimport { useDebounce } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport Button from '../button';\nimport { ColorPicker } from '../color-picker';\nimport { FlexBlock, FlexItem } from '../flex';\nimport { HStack } from '../h-stack';\nimport { Item, ItemGroup } from '../item-group';\nimport { VStack } from '../v-stack';\nimport GradientPicker from '../gradient-picker';\nimport ColorPalette from '../color-palette';\nimport DropdownMenu from '../dropdown-menu';\nimport Popover from '../popover';\nimport { PaletteActionsContainer, PaletteEditStyles, PaletteHeading, IndicatorStyled, NameContainer, NameInputControl, DoneButton, RemoveButton, PaletteEditContents } from './styles';\nimport { NavigableMenu } from '../navigable-container';\nimport { DEFAULT_GRADIENT } from '../custom-gradient-picker/constants';\nimport CustomGradientPicker from '../custom-gradient-picker';\nimport { kebabCase } from '../utils/strings';\nimport { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from \"react/jsx-runtime\";\nconst DEFAULT_COLOR = '#000';\nfunction NameInput({\n value,\n onChange,\n label\n}) {\n return /*#__PURE__*/_jsx(NameInputControl, {\n size: \"compact\",\n label: label,\n hideLabelFromVision: true,\n value: value,\n onChange: onChange\n });\n}\n\n/*\n * Deduplicates the slugs of the provided elements.\n */\nexport function deduplicateElementSlugs(elements) {\n const slugCounts = {};\n return elements.map(element => {\n var _newSlug;\n let newSlug;\n const {\n slug\n } = element;\n slugCounts[slug] = (slugCounts[slug] || 0) + 1;\n if (slugCounts[slug] > 1) {\n newSlug = `${slug}-${slugCounts[slug] - 1}`;\n }\n return {\n ...element,\n slug: (_newSlug = newSlug) !== null && _newSlug !== void 0 ? _newSlug : slug\n };\n });\n}\n\n/**\n * Returns a name and slug for a palette item. The name takes the format \"Color + id\".\n * To ensure there are no duplicate ids, this function checks all slugs.\n * It expects slugs to be in the format: slugPrefix + color- + number.\n * It then sets the id component of the new name based on the incremented id of the highest existing slug id.\n *\n * @param elements An array of color palette items.\n * @param slugPrefix The slug prefix used to match the element slug.\n *\n * @return A name and slug for the new palette item.\n */\nexport function getNameAndSlugForPosition(elements, slugPrefix) {\n const nameRegex = new RegExp(`^${slugPrefix}color-([\\\\d]+)$`);\n const position = elements.reduce((previousValue, currentValue) => {\n if (typeof currentValue?.slug === 'string') {\n const matches = currentValue?.slug.match(nameRegex);\n if (matches) {\n const id = parseInt(matches[1], 10);\n if (id >= previousValue) {\n return id + 1;\n }\n }\n }\n return previousValue;\n }, 1);\n return {\n name: sprintf(/* translators: %d: is an id for a custom color */\n __('Color %d'), position),\n slug: `${slugPrefix}color-${position}`\n };\n}\nfunction ColorPickerPopover({\n isGradient,\n element,\n onChange,\n popoverProps: receivedPopoverProps,\n onClose = () => {}\n}) {\n const popoverProps = useMemo(() => ({\n shift: true,\n offset: 20,\n // Disabling resize as it would otherwise cause the popover to show\n // scrollbars while dragging the color picker's handle close to the\n // popover edge.\n resize: false,\n placement: 'left-start',\n ...receivedPopoverProps,\n className: clsx('components-palette-edit__popover', receivedPopoverProps?.className)\n }), [receivedPopoverProps]);\n return /*#__PURE__*/_jsxs(Popover, {\n ...popoverProps,\n onClose: onClose,\n children: [!isGradient && /*#__PURE__*/_jsx(ColorPicker, {\n color: element.color,\n enableAlpha: true,\n onChange: newColor => {\n onChange({\n ...element,\n color: newColor\n });\n }\n }), isGradient && /*#__PURE__*/_jsx(\"div\", {\n className: \"components-palette-edit__popover-gradient-picker\",\n children: /*#__PURE__*/_jsx(CustomGradientPicker, {\n __experimentalIsRenderedInSidebar: true,\n value: element.gradient,\n onChange: newGradient => {\n onChange({\n ...element,\n gradient: newGradient\n });\n }\n })\n })]\n });\n}\nfunction Option({\n canOnlyChangeValues,\n element,\n onChange,\n onRemove,\n popoverProps: receivedPopoverProps,\n slugPrefix,\n isGradient\n}) {\n const value = isGradient ? element.gradient : element.color;\n const [isEditingColor, setIsEditingColor] = useState(false);\n\n // Use internal state instead of a ref to make sure that the component\n // re-renders when the popover's anchor updates.\n const [popoverAnchor, setPopoverAnchor] = useState(null);\n const popoverProps = useMemo(() => ({\n ...receivedPopoverProps,\n // Use the custom palette color item as the popover anchor.\n anchor: popoverAnchor\n }), [popoverAnchor, receivedPopoverProps]);\n return /*#__PURE__*/_jsxs(Item, {\n ref: setPopoverAnchor,\n size: \"small\",\n children: [/*#__PURE__*/_jsxs(HStack, {\n justify: \"flex-start\",\n children: [/*#__PURE__*/_jsx(Button, {\n size: \"small\",\n onClick: () => {\n setIsEditingColor(true);\n },\n \"aria-label\": sprintf(\n // translators: %s is a color or gradient name, e.g. \"Red\".\n __('Edit: %s'), element.name.trim().length ? element.name : value || ''),\n style: {\n padding: 0\n },\n children: /*#__PURE__*/_jsx(IndicatorStyled, {\n colorValue: value\n })\n }), /*#__PURE__*/_jsx(FlexBlock, {\n children: !canOnlyChangeValues ? /*#__PURE__*/_jsx(NameInput, {\n label: isGradient ? __('Gradient name') : __('Color name'),\n value: element.name,\n onChange: nextName => onChange({\n ...element,\n name: nextName,\n slug: slugPrefix + kebabCase(nextName !== null && nextName !== void 0 ? nextName : '')\n })\n }) : /*#__PURE__*/_jsx(NameContainer, {\n children: element.name.trim().length ? element.name : /* Fall back to non-breaking space to maintain height */\n '\\u00A0'\n })\n }), !canOnlyChangeValues && /*#__PURE__*/_jsx(FlexItem, {\n children: /*#__PURE__*/_jsx(RemoveButton, {\n size: \"small\",\n icon: lineSolid,\n label: sprintf(\n // translators: %s is a color or gradient name, e.g. \"Red\".\n __('Remove color: %s'), element.name.trim().length ? element.name : value || ''),\n onClick: onRemove\n })\n })]\n }), isEditingColor && /*#__PURE__*/_jsx(ColorPickerPopover, {\n isGradient: isGradient,\n onChange: onChange,\n element: element,\n popoverProps: popoverProps,\n onClose: () => setIsEditingColor(false)\n })]\n });\n}\nfunction PaletteEditListView({\n elements,\n onChange,\n canOnlyChangeValues,\n slugPrefix,\n isGradient,\n popoverProps,\n addColorRef\n}) {\n // When unmounting the component if there are empty elements (the user did not complete the insertion) clean them.\n const elementsReferenceRef = useRef();\n useEffect(() => {\n elementsReferenceRef.current = elements;\n }, [elements]);\n const debounceOnChange = useDebounce(updatedElements => onChange(deduplicateElementSlugs(updatedElements)), 100);\n return /*#__PURE__*/_jsx(VStack, {\n spacing: 3,\n children: /*#__PURE__*/_jsx(ItemGroup, {\n isRounded: true,\n isBordered: true,\n isSeparated: true,\n children: elements.map((element, index) => /*#__PURE__*/_jsx(Option, {\n isGradient: isGradient,\n canOnlyChangeValues: canOnlyChangeValues,\n element: element,\n onChange: newElement => {\n debounceOnChange(elements.map((currentElement, currentIndex) => {\n if (currentIndex === index) {\n return newElement;\n }\n return currentElement;\n }));\n },\n onRemove: () => {\n const newElements = elements.filter((_currentElement, currentIndex) => {\n if (currentIndex === index) {\n return false;\n }\n return true;\n });\n onChange(newElements.length ? newElements : undefined);\n addColorRef.current?.focus();\n },\n slugPrefix: slugPrefix,\n popoverProps: popoverProps\n }, index))\n })\n });\n}\nconst EMPTY_ARRAY = [];\n\n/**\n * Allows editing a palette of colors or gradients.\n *\n * ```jsx\n * import { PaletteEdit } from '@wordpress/components';\n * const MyPaletteEdit = () => {\n * const [ controlledColors, setControlledColors ] = useState( colors );\n *\n * return (\n * <PaletteEdit\n * colors={ controlledColors }\n * onChange={ ( newColors?: Color[] ) => {\n * setControlledColors( newColors );\n * } }\n * paletteLabel=\"Here is a label\"\n * />\n * );\n * };\n * ```\n */\nexport function PaletteEdit({\n gradients,\n colors = EMPTY_ARRAY,\n onChange,\n paletteLabel,\n paletteLabelHeadingLevel = 2,\n emptyMessage,\n canOnlyChangeValues,\n canReset,\n slugPrefix = '',\n popoverProps\n}) {\n const isGradient = !!gradients;\n const elements = isGradient ? gradients : colors;\n const [isEditing, setIsEditing] = useState(false);\n const [editingElement, setEditingElement] = useState(null);\n const isAdding = isEditing && !!editingElement && elements[editingElement] && !elements[editingElement].slug;\n const elementsLength = elements.length;\n const hasElements = elementsLength > 0;\n const debounceOnChange = useDebounce(onChange, 100);\n const onSelectPaletteItem = useCallback((value, newEditingElementIndex) => {\n const selectedElement = newEditingElementIndex === undefined ? undefined : elements[newEditingElementIndex];\n const key = isGradient ? 'gradient' : 'color';\n // Ensures that the index returned matches a known element value.\n if (!!selectedElement && selectedElement[key] === value) {\n setEditingElement(newEditingElementIndex);\n } else {\n setIsEditing(true);\n }\n }, [isGradient, elements]);\n const addColorRef = useRef(null);\n return /*#__PURE__*/_jsxs(PaletteEditStyles, {\n children: [/*#__PURE__*/_jsxs(HStack, {\n children: [/*#__PURE__*/_jsx(PaletteHeading, {\n level: paletteLabelHeadingLevel,\n children: paletteLabel\n }), /*#__PURE__*/_jsxs(PaletteActionsContainer, {\n children: [hasElements && isEditing && /*#__PURE__*/_jsx(DoneButton, {\n size: \"small\",\n onClick: () => {\n setIsEditing(false);\n setEditingElement(null);\n },\n children: __('Done')\n }), !canOnlyChangeValues && /*#__PURE__*/_jsx(Button, {\n ref: addColorRef,\n size: \"small\",\n isPressed: isAdding,\n icon: plus,\n label: isGradient ? __('Add gradient') : __('Add color'),\n onClick: () => {\n const {\n name,\n slug\n } = getNameAndSlugForPosition(elements, slugPrefix);\n if (!!gradients) {\n onChange([...gradients, {\n gradient: DEFAULT_GRADIENT,\n name,\n slug\n }]);\n } else {\n onChange([...colors, {\n color: DEFAULT_COLOR,\n name,\n slug\n }]);\n }\n setIsEditing(true);\n setEditingElement(elements.length);\n }\n }), hasElements && (!isEditing || !canOnlyChangeValues || canReset) && /*#__PURE__*/_jsx(DropdownMenu, {\n icon: moreVertical,\n label: isGradient ? __('Gradient options') : __('Color options'),\n toggleProps: {\n size: 'small'\n },\n children: ({\n onClose\n }) => /*#__PURE__*/_jsx(_Fragment, {\n children: /*#__PURE__*/_jsxs(NavigableMenu, {\n role: \"menu\",\n children: [!isEditing && /*#__PURE__*/_jsx(Button, {\n __next40pxDefaultSize: true,\n variant: \"tertiary\",\n onClick: () => {\n setIsEditing(true);\n onClose();\n },\n className: \"components-palette-edit__menu-button\",\n children: __('Show details')\n }), !canOnlyChangeValues && /*#__PURE__*/_jsx(Button, {\n __next40pxDefaultSize: true,\n variant: \"tertiary\",\n onClick: () => {\n setEditingElement(null);\n setIsEditing(false);\n onChange();\n onClose();\n },\n className: \"components-palette-edit__menu-button\",\n children: isGradient ? __('Remove all gradients') : __('Remove all colors')\n }), canReset && /*#__PURE__*/_jsx(Button, {\n __next40pxDefaultSize: true,\n className: \"components-palette-edit__menu-button\",\n variant: \"tertiary\",\n onClick: () => {\n setEditingElement(null);\n onChange();\n onClose();\n },\n children: isGradient ? __('Reset gradient') : __('Reset colors')\n })]\n })\n })\n })]\n })]\n }), hasElements && /*#__PURE__*/_jsxs(PaletteEditContents, {\n children: [isEditing && /*#__PURE__*/_jsx(PaletteEditListView, {\n canOnlyChangeValues: canOnlyChangeValues,\n elements: elements\n // @ts-expect-error TODO: Don't know how to resolve\n ,\n onChange: onChange,\n slugPrefix: slugPrefix,\n isGradient: isGradient,\n popoverProps: popoverProps,\n addColorRef: addColorRef\n }), !isEditing && editingElement !== null && /*#__PURE__*/_jsx(ColorPickerPopover, {\n isGradient: isGradient,\n onClose: () => setEditingElement(null),\n onChange: newElement => {\n debounceOnChange(\n // @ts-expect-error TODO: Don't know how to resolve\n elements.map((currentElement, currentIndex) => {\n if (currentIndex === editingElement) {\n return newElement;\n }\n return currentElement;\n }));\n },\n element: elements[editingElement !== null && editingElement !== void 0 ? editingElement : -1],\n popoverProps: popoverProps\n }), !isEditing && (isGradient ? /*#__PURE__*/_jsx(GradientPicker, {\n gradients: gradients,\n onChange: onSelectPaletteItem,\n clearable: false,\n disableCustomGradients: true\n }) : /*#__PURE__*/_jsx(ColorPalette, {\n colors: colors,\n onChange: onSelectPaletteItem,\n clearable: false,\n disableCustomColors: true\n }))]\n }), !hasElements && emptyMessage && /*#__PURE__*/_jsx(PaletteEditContents, {\n children: emptyMessage\n })]\n });\n}\nexport default PaletteEdit;"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,qBAAkE;AAClE,kBAA4B;AAC5B,mBAA8C;AAC9C,qBAA4B;AAK5B,oBAAmB;AACnB,0BAA4B;AAC5B,kBAAoC;AACpC,qBAAuB;AACvB,wBAAgC;AAChC,qBAAuB;AACvB,6BAA2B;AAC3B,2BAAyB;AACzB,2BAAyB;AACzB,qBAAoB;AACpB,oBAA4K;AAC5K,iCAA8B;AAC9B,uBAAiC;AACjC,oCAAiC;AACjC,qBAA0B;AAC1B,yBAAkE;AAClE,IAAM,gBAAgB;AACtB,SAAS,UAAU;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AACF,GAAG;AACD,SAAoB,uCAAAA,KAAK,gCAAkB;AAAA,IACzC,MAAM;AAAA,IACN;AAAA,IACA,qBAAqB;AAAA,IACrB;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAKO,SAAS,wBAAwB,UAAU;AAChD,QAAM,aAAa,CAAC;AACpB,SAAO,SAAS,IAAI,aAAW;AAC7B,QAAI;AACJ,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useState, useRef, useEffect, useCallback, useMemo } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { lineSolid, moreVertical, plus } from '@wordpress/icons';\nimport { useDebounce } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport Button from '../button';\nimport { ColorPicker } from '../color-picker';\nimport { FlexBlock, FlexItem } from '../flex';\nimport { HStack } from '../h-stack';\nimport { Item, ItemGroup } from '../item-group';\nimport { VStack } from '../v-stack';\nimport GradientPicker from '../gradient-picker';\nimport ColorPalette from '../color-palette';\nimport DropdownMenu from '../dropdown-menu';\nimport Popover from '../popover';\nimport { PaletteActionsContainer, PaletteEditStyles, PaletteHeading, IndicatorStyled, NameContainer, NameInputControl, DoneButton, RemoveButton, PaletteEditContents } from './styles';\nimport { NavigableMenu } from '../navigable-container';\nimport { DEFAULT_GRADIENT } from '../custom-gradient-picker/constants';\nimport CustomGradientPicker from '../custom-gradient-picker';\nimport { kebabCase } from '../utils/strings';\nimport { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from \"react/jsx-runtime\";\nconst DEFAULT_COLOR = '#000';\nfunction NameInput({\n value,\n onChange,\n label\n}) {\n return /*#__PURE__*/_jsx(NameInputControl, {\n size: \"compact\",\n label: label,\n hideLabelFromVision: true,\n value: value,\n onChange: onChange\n });\n}\n\n/*\n * Deduplicates the slugs of the provided elements.\n */\nexport function deduplicateElementSlugs(elements) {\n const slugCounts = {};\n return elements.map(element => {\n let newSlug;\n const {\n slug\n } = element;\n slugCounts[slug] = (slugCounts[slug] || 0) + 1;\n if (slugCounts[slug] > 1) {\n newSlug = `${slug}-${slugCounts[slug] - 1}`;\n }\n return {\n ...element,\n slug: newSlug ?? slug\n };\n });\n}\n\n/**\n * Returns a name and slug for a palette item. The name takes the format \"Color + id\".\n * To ensure there are no duplicate ids, this function checks all slugs.\n * It expects slugs to be in the format: slugPrefix + color- + number.\n * It then sets the id component of the new name based on the incremented id of the highest existing slug id.\n *\n * @param elements An array of color palette items.\n * @param slugPrefix The slug prefix used to match the element slug.\n *\n * @return A name and slug for the new palette item.\n */\nexport function getNameAndSlugForPosition(elements, slugPrefix) {\n const nameRegex = new RegExp(`^${slugPrefix}color-([\\\\d]+)$`);\n const position = elements.reduce((previousValue, currentValue) => {\n if (typeof currentValue?.slug === 'string') {\n const matches = currentValue?.slug.match(nameRegex);\n if (matches) {\n const id = parseInt(matches[1], 10);\n if (id >= previousValue) {\n return id + 1;\n }\n }\n }\n return previousValue;\n }, 1);\n return {\n name: sprintf(/* translators: %d: is an id for a custom color */\n __('Color %d'), position),\n slug: `${slugPrefix}color-${position}`\n };\n}\nfunction ColorPickerPopover({\n isGradient,\n element,\n onChange,\n popoverProps: receivedPopoverProps,\n onClose = () => {}\n}) {\n const popoverProps = useMemo(() => ({\n shift: true,\n offset: 20,\n // Disabling resize as it would otherwise cause the popover to show\n // scrollbars while dragging the color picker's handle close to the\n // popover edge.\n resize: false,\n placement: 'left-start',\n ...receivedPopoverProps,\n className: clsx('components-palette-edit__popover', receivedPopoverProps?.className)\n }), [receivedPopoverProps]);\n return /*#__PURE__*/_jsxs(Popover, {\n ...popoverProps,\n onClose: onClose,\n children: [!isGradient && /*#__PURE__*/_jsx(ColorPicker, {\n color: element.color,\n enableAlpha: true,\n onChange: newColor => {\n onChange({\n ...element,\n color: newColor\n });\n }\n }), isGradient && /*#__PURE__*/_jsx(\"div\", {\n className: \"components-palette-edit__popover-gradient-picker\",\n children: /*#__PURE__*/_jsx(CustomGradientPicker, {\n __experimentalIsRenderedInSidebar: true,\n value: element.gradient,\n onChange: newGradient => {\n onChange({\n ...element,\n gradient: newGradient\n });\n }\n })\n })]\n });\n}\nfunction Option({\n canOnlyChangeValues,\n element,\n onChange,\n onRemove,\n popoverProps: receivedPopoverProps,\n slugPrefix,\n isGradient\n}) {\n const value = isGradient ? element.gradient : element.color;\n const [isEditingColor, setIsEditingColor] = useState(false);\n\n // Use internal state instead of a ref to make sure that the component\n // re-renders when the popover's anchor updates.\n const [popoverAnchor, setPopoverAnchor] = useState(null);\n const popoverProps = useMemo(() => ({\n ...receivedPopoverProps,\n // Use the custom palette color item as the popover anchor.\n anchor: popoverAnchor\n }), [popoverAnchor, receivedPopoverProps]);\n return /*#__PURE__*/_jsxs(Item, {\n ref: setPopoverAnchor,\n size: \"small\",\n children: [/*#__PURE__*/_jsxs(HStack, {\n justify: \"flex-start\",\n children: [/*#__PURE__*/_jsx(Button, {\n size: \"small\",\n onClick: () => {\n setIsEditingColor(true);\n },\n \"aria-label\": sprintf(\n // translators: %s is a color or gradient name, e.g. \"Red\".\n __('Edit: %s'), element.name.trim().length ? element.name : value || ''),\n style: {\n padding: 0\n },\n children: /*#__PURE__*/_jsx(IndicatorStyled, {\n colorValue: value\n })\n }), /*#__PURE__*/_jsx(FlexBlock, {\n children: !canOnlyChangeValues ? /*#__PURE__*/_jsx(NameInput, {\n label: isGradient ? __('Gradient name') : __('Color name'),\n value: element.name,\n onChange: nextName => onChange({\n ...element,\n name: nextName,\n slug: slugPrefix + kebabCase(nextName ?? '')\n })\n }) : /*#__PURE__*/_jsx(NameContainer, {\n children: element.name.trim().length ? element.name : /* Fall back to non-breaking space to maintain height */\n '\\u00A0'\n })\n }), !canOnlyChangeValues && /*#__PURE__*/_jsx(FlexItem, {\n children: /*#__PURE__*/_jsx(RemoveButton, {\n size: \"small\",\n icon: lineSolid,\n label: sprintf(\n // translators: %s is a color or gradient name, e.g. \"Red\".\n __('Remove color: %s'), element.name.trim().length ? element.name : value || ''),\n onClick: onRemove\n })\n })]\n }), isEditingColor && /*#__PURE__*/_jsx(ColorPickerPopover, {\n isGradient: isGradient,\n onChange: onChange,\n element: element,\n popoverProps: popoverProps,\n onClose: () => setIsEditingColor(false)\n })]\n });\n}\nfunction PaletteEditListView({\n elements,\n onChange,\n canOnlyChangeValues,\n slugPrefix,\n isGradient,\n popoverProps,\n addColorRef\n}) {\n // When unmounting the component if there are empty elements (the user did not complete the insertion) clean them.\n const elementsReferenceRef = useRef();\n useEffect(() => {\n elementsReferenceRef.current = elements;\n }, [elements]);\n const debounceOnChange = useDebounce(updatedElements => onChange(deduplicateElementSlugs(updatedElements)), 100);\n return /*#__PURE__*/_jsx(VStack, {\n spacing: 3,\n children: /*#__PURE__*/_jsx(ItemGroup, {\n isRounded: true,\n isBordered: true,\n isSeparated: true,\n children: elements.map((element, index) => /*#__PURE__*/_jsx(Option, {\n isGradient: isGradient,\n canOnlyChangeValues: canOnlyChangeValues,\n element: element,\n onChange: newElement => {\n debounceOnChange(elements.map((currentElement, currentIndex) => {\n if (currentIndex === index) {\n return newElement;\n }\n return currentElement;\n }));\n },\n onRemove: () => {\n const newElements = elements.filter((_currentElement, currentIndex) => {\n if (currentIndex === index) {\n return false;\n }\n return true;\n });\n onChange(newElements.length ? newElements : undefined);\n addColorRef.current?.focus();\n },\n slugPrefix: slugPrefix,\n popoverProps: popoverProps\n }, index))\n })\n });\n}\nconst EMPTY_ARRAY = [];\n\n/**\n * Allows editing a palette of colors or gradients.\n *\n * ```jsx\n * import { PaletteEdit } from '@wordpress/components';\n * const MyPaletteEdit = () => {\n * const [ controlledColors, setControlledColors ] = useState( colors );\n *\n * return (\n * <PaletteEdit\n * colors={ controlledColors }\n * onChange={ ( newColors?: Color[] ) => {\n * setControlledColors( newColors );\n * } }\n * paletteLabel=\"Here is a label\"\n * />\n * );\n * };\n * ```\n */\nexport function PaletteEdit({\n gradients,\n colors = EMPTY_ARRAY,\n onChange,\n paletteLabel,\n paletteLabelHeadingLevel = 2,\n emptyMessage,\n canOnlyChangeValues,\n canReset,\n slugPrefix = '',\n popoverProps\n}) {\n const isGradient = !!gradients;\n const elements = isGradient ? gradients : colors;\n const [isEditing, setIsEditing] = useState(false);\n const [editingElement, setEditingElement] = useState(null);\n const isAdding = isEditing && !!editingElement && elements[editingElement] && !elements[editingElement].slug;\n const elementsLength = elements.length;\n const hasElements = elementsLength > 0;\n const debounceOnChange = useDebounce(onChange, 100);\n const onSelectPaletteItem = useCallback((value, newEditingElementIndex) => {\n const selectedElement = newEditingElementIndex === undefined ? undefined : elements[newEditingElementIndex];\n const key = isGradient ? 'gradient' : 'color';\n // Ensures that the index returned matches a known element value.\n if (!!selectedElement && selectedElement[key] === value) {\n setEditingElement(newEditingElementIndex);\n } else {\n setIsEditing(true);\n }\n }, [isGradient, elements]);\n const addColorRef = useRef(null);\n return /*#__PURE__*/_jsxs(PaletteEditStyles, {\n children: [/*#__PURE__*/_jsxs(HStack, {\n children: [/*#__PURE__*/_jsx(PaletteHeading, {\n level: paletteLabelHeadingLevel,\n children: paletteLabel\n }), /*#__PURE__*/_jsxs(PaletteActionsContainer, {\n children: [hasElements && isEditing && /*#__PURE__*/_jsx(DoneButton, {\n size: \"small\",\n onClick: () => {\n setIsEditing(false);\n setEditingElement(null);\n },\n children: __('Done')\n }), !canOnlyChangeValues && /*#__PURE__*/_jsx(Button, {\n ref: addColorRef,\n size: \"small\",\n isPressed: isAdding,\n icon: plus,\n label: isGradient ? __('Add gradient') : __('Add color'),\n onClick: () => {\n const {\n name,\n slug\n } = getNameAndSlugForPosition(elements, slugPrefix);\n if (!!gradients) {\n onChange([...gradients, {\n gradient: DEFAULT_GRADIENT,\n name,\n slug\n }]);\n } else {\n onChange([...colors, {\n color: DEFAULT_COLOR,\n name,\n slug\n }]);\n }\n setIsEditing(true);\n setEditingElement(elements.length);\n }\n }), hasElements && (!isEditing || !canOnlyChangeValues || canReset) && /*#__PURE__*/_jsx(DropdownMenu, {\n icon: moreVertical,\n label: isGradient ? __('Gradient options') : __('Color options'),\n toggleProps: {\n size: 'small'\n },\n children: ({\n onClose\n }) => /*#__PURE__*/_jsx(_Fragment, {\n children: /*#__PURE__*/_jsxs(NavigableMenu, {\n role: \"menu\",\n children: [!isEditing && /*#__PURE__*/_jsx(Button, {\n __next40pxDefaultSize: true,\n variant: \"tertiary\",\n onClick: () => {\n setIsEditing(true);\n onClose();\n },\n className: \"components-palette-edit__menu-button\",\n children: __('Show details')\n }), !canOnlyChangeValues && /*#__PURE__*/_jsx(Button, {\n __next40pxDefaultSize: true,\n variant: \"tertiary\",\n onClick: () => {\n setEditingElement(null);\n setIsEditing(false);\n onChange();\n onClose();\n },\n className: \"components-palette-edit__menu-button\",\n children: isGradient ? __('Remove all gradients') : __('Remove all colors')\n }), canReset && /*#__PURE__*/_jsx(Button, {\n __next40pxDefaultSize: true,\n className: \"components-palette-edit__menu-button\",\n variant: \"tertiary\",\n onClick: () => {\n setEditingElement(null);\n onChange();\n onClose();\n },\n children: isGradient ? __('Reset gradient') : __('Reset colors')\n })]\n })\n })\n })]\n })]\n }), hasElements && /*#__PURE__*/_jsxs(PaletteEditContents, {\n children: [isEditing && /*#__PURE__*/_jsx(PaletteEditListView, {\n canOnlyChangeValues: canOnlyChangeValues,\n elements: elements\n // @ts-expect-error TODO: Don't know how to resolve\n ,\n onChange: onChange,\n slugPrefix: slugPrefix,\n isGradient: isGradient,\n popoverProps: popoverProps,\n addColorRef: addColorRef\n }), !isEditing && editingElement !== null && /*#__PURE__*/_jsx(ColorPickerPopover, {\n isGradient: isGradient,\n onClose: () => setEditingElement(null),\n onChange: newElement => {\n debounceOnChange(\n // @ts-expect-error TODO: Don't know how to resolve\n elements.map((currentElement, currentIndex) => {\n if (currentIndex === editingElement) {\n return newElement;\n }\n return currentElement;\n }));\n },\n element: elements[editingElement ?? -1],\n popoverProps: popoverProps\n }), !isEditing && (isGradient ? /*#__PURE__*/_jsx(GradientPicker, {\n gradients: gradients,\n onChange: onSelectPaletteItem,\n clearable: false,\n disableCustomGradients: true\n }) : /*#__PURE__*/_jsx(ColorPalette, {\n colors: colors,\n onChange: onSelectPaletteItem,\n clearable: false,\n disableCustomColors: true\n }))]\n }), !hasElements && emptyMessage && /*#__PURE__*/_jsx(PaletteEditContents, {\n children: emptyMessage\n })]\n });\n}\nexport default PaletteEdit;"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ACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC,GAAG,CAAC,aAAa,mBAAmB,QAAqB,uCAAAA,KAAK,oBAAoB;AAAA,QACjF;AAAA,QACA,SAAS,MAAM,kBAAkB,IAAI;AAAA,QACrC,UAAU,gBAAc;AACtB;AAAA;AAAA,YAEA,SAAS,IAAI,CAAC,gBAAgB,iBAAiB;AAC7C,kBAAI,iBAAiB,gBAAgB;AACnC,uBAAO;AAAA,cACT;AACA,qBAAO;AAAA,YACT,CAAC;AAAA,UAAC;AAAA,QACJ;AAAA,QACA,SAAS,SAAS,kBAAkB,EAAE;AAAA,QACtC;AAAA,MACF,CAAC,GAAG,CAAC,cAAc,aAA0B,uCAAAA,KAAK,uBAAAQ,SAAgB;AAAA,QAChE;AAAA,QACA,UAAU;AAAA,QACV,WAAW;AAAA,QACX,wBAAwB;AAAA,MAC1B,CAAC,IAAiB,uCAAAR,KAAK,qBAAAS,SAAc;AAAA,QACnC;AAAA,QACA,UAAU;AAAA,QACV,WAAW;AAAA,QACX,qBAAqB;AAAA,MACvB,CAAC,EAAE;AAAA,IACL,CAAC,GAAG,CAAC,eAAe,gBAA6B,uCAAAT,KAAK,mCAAqB;AAAA,MACzE,UAAU;AAAA,IACZ,CAAC,CAAC;AAAA,EACJ,CAAC;AACH;AACA,IAAO,uBAAQ;",
|
|
6
6
|
"names": ["_jsx", "clsx", "_jsxs", "Popover", "CustomGradientPicker", "Button", "DropdownMenu", "_Fragment", "GradientPicker", "ColorPalette"]
|
|
7
7
|
}
|
package/build/popover/index.cjs
CHANGED
|
@@ -161,10 +161,9 @@ var UnforwardedPopover = (props, forwardedRef) => {
|
|
|
161
161
|
const middleware = [...placementProp === "overlay" ? (0, import_overlay_middlewares.overlayMiddlewares)() : [], (0, import_react_dom.offset)(offsetProp), computedFlipProp && (0, import_react_dom.flip)(), computedResizeProp && (0, import_react_dom.size)({
|
|
162
162
|
padding: OVERFLOW_PADDING,
|
|
163
163
|
apply(sizeProps) {
|
|
164
|
-
var _refs$floating$curren;
|
|
165
164
|
const {
|
|
166
165
|
firstElementChild
|
|
167
|
-
} =
|
|
166
|
+
} = refs.floating.current ?? {};
|
|
168
167
|
if (!(firstElementChild instanceof HTMLElement)) {
|
|
169
168
|
return;
|
|
170
169
|
}
|