@wordpress/components 23.6.0 → 23.7.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 +32 -4
- package/build/angle-picker-control/angle-circle.js +1 -4
- package/build/angle-picker-control/angle-circle.js.map +1 -1
- package/build/angle-picker-control/index.js +10 -22
- package/build/angle-picker-control/index.js.map +1 -1
- package/build/angle-picker-control/styles/angle-picker-control-styles.js +24 -15
- package/build/angle-picker-control/styles/angle-picker-control-styles.js.map +1 -1
- package/build/animate/index.js +27 -19
- package/build/animate/index.js.map +1 -1
- package/build/animate/types.js.map +1 -0
- package/build/box-control/axial-input-controls.js.map +1 -1
- package/build/color-picker/color-input.js +0 -4
- package/build/color-picker/color-input.js.map +1 -1
- package/build/color-picker/component.js +5 -4
- package/build/color-picker/component.js.map +1 -1
- package/build/color-picker/hex-input.js.map +1 -1
- package/build/color-picker/hsl-input.js.map +1 -1
- package/build/color-picker/input-with-slider.js.map +1 -1
- package/build/color-picker/legacy-adapter.js.map +1 -1
- package/build/color-picker/picker.js.map +1 -1
- package/build/color-picker/rgb-input.js.map +1 -1
- package/build/color-picker/use-deprecated-props.js.map +1 -1
- package/build/custom-gradient-picker/constants.js +1 -1
- package/build/custom-gradient-picker/constants.js.map +1 -1
- package/build/custom-gradient-picker/gradient-bar/constants.js.map +1 -1
- package/build/custom-gradient-picker/gradient-bar/control-points.js +9 -5
- package/build/custom-gradient-picker/gradient-bar/control-points.js.map +1 -1
- package/build/custom-gradient-picker/gradient-bar/index.js +14 -9
- package/build/custom-gradient-picker/gradient-bar/index.js.map +1 -1
- package/build/custom-gradient-picker/gradient-bar/utils.js +34 -54
- package/build/custom-gradient-picker/gradient-bar/utils.js.map +1 -1
- package/build/custom-gradient-picker/index.js +45 -16
- package/build/custom-gradient-picker/index.js.map +1 -1
- package/build/custom-gradient-picker/serializer.js +14 -4
- package/build/custom-gradient-picker/serializer.js.map +1 -1
- package/build/custom-gradient-picker/styles/custom-gradient-picker-styles.js +6 -6
- package/build/custom-gradient-picker/styles/custom-gradient-picker-styles.js.map +1 -1
- package/build/custom-gradient-picker/types.js +6 -0
- package/build/custom-gradient-picker/types.js.map +1 -0
- package/build/custom-gradient-picker/utils.js +17 -12
- package/build/custom-gradient-picker/utils.js.map +1 -1
- package/build/{color-list-picker → duotone-picker/color-list-picker}/index.js +5 -5
- package/build/duotone-picker/color-list-picker/index.js.map +1 -0
- package/build/duotone-picker/color-list-picker/types.js +6 -0
- package/build/duotone-picker/color-list-picker/types.js.map +1 -0
- package/build/duotone-picker/custom-duotone-bar.js.map +1 -1
- package/build/duotone-picker/duotone-picker.js +39 -2
- package/build/duotone-picker/duotone-picker.js.map +1 -1
- package/build/duotone-picker/duotone-swatch.js.map +1 -1
- package/build/duotone-picker/index.js.map +1 -1
- package/build/duotone-picker/types.js +6 -0
- package/build/duotone-picker/types.js.map +1 -0
- package/build/duotone-picker/utils.js +13 -11
- package/build/duotone-picker/utils.js.map +1 -1
- package/build/form-token-field/index.js +9 -3
- package/build/form-token-field/index.js.map +1 -1
- package/build/gradient-picker/index.js +61 -9
- package/build/gradient-picker/index.js.map +1 -1
- package/build/gradient-picker/types.js +6 -0
- package/build/gradient-picker/types.js.map +1 -0
- package/build/palette-edit/index.js +1 -2
- package/build/palette-edit/index.js.map +1 -1
- package/build/resizable-box/resize-tooltip/utils.js.map +1 -1
- package/build/sandbox/index.native.js +80 -67
- package/build/sandbox/index.native.js.map +1 -1
- package/build/tab-panel/index.js +1 -1
- package/build/tab-panel/index.js.map +1 -1
- package/build/tools-panel/tools-panel/hook.js +45 -6
- package/build/tools-panel/tools-panel/hook.js.map +1 -1
- package/build/utils/input/input-control.js +1 -1
- package/build/utils/input/input-control.js.map +1 -1
- package/build-module/angle-picker-control/angle-circle.js +1 -4
- package/build-module/angle-picker-control/angle-circle.js.map +1 -1
- package/build-module/angle-picker-control/index.js +12 -21
- package/build-module/angle-picker-control/index.js.map +1 -1
- package/build-module/angle-picker-control/styles/angle-picker-control-styles.js +20 -13
- package/build-module/angle-picker-control/styles/angle-picker-control-styles.js.map +1 -1
- package/build-module/animate/index.js +25 -17
- package/build-module/animate/index.js.map +1 -1
- package/build-module/box-control/axial-input-controls.js.map +1 -1
- package/build-module/color-picker/color-input.js +0 -4
- package/build-module/color-picker/color-input.js.map +1 -1
- package/build-module/color-picker/component.js +3 -3
- package/build-module/color-picker/component.js.map +1 -1
- package/build-module/color-picker/hex-input.js.map +1 -1
- package/build-module/color-picker/hsl-input.js.map +1 -1
- package/build-module/color-picker/input-with-slider.js.map +1 -1
- package/build-module/color-picker/legacy-adapter.js.map +1 -1
- package/build-module/color-picker/picker.js +4 -0
- package/build-module/color-picker/picker.js.map +1 -1
- package/build-module/color-picker/rgb-input.js.map +1 -1
- package/build-module/color-picker/use-deprecated-props.js.map +1 -1
- package/build-module/custom-gradient-picker/constants.js +1 -1
- package/build-module/custom-gradient-picker/constants.js.map +1 -1
- package/build-module/custom-gradient-picker/gradient-bar/constants.js.map +1 -1
- package/build-module/custom-gradient-picker/gradient-bar/control-points.js +9 -4
- package/build-module/custom-gradient-picker/gradient-bar/control-points.js.map +1 -1
- package/build-module/custom-gradient-picker/gradient-bar/index.js +14 -8
- package/build-module/custom-gradient-picker/gradient-bar/index.js.map +1 -1
- package/build-module/custom-gradient-picker/gradient-bar/utils.js +34 -54
- package/build-module/custom-gradient-picker/gradient-bar/utils.js.map +1 -1
- package/build-module/custom-gradient-picker/index.js +44 -17
- package/build-module/custom-gradient-picker/index.js.map +1 -1
- package/build-module/custom-gradient-picker/serializer.js +14 -4
- package/build-module/custom-gradient-picker/serializer.js.map +1 -1
- package/build-module/custom-gradient-picker/styles/custom-gradient-picker-styles.js +6 -6
- package/build-module/custom-gradient-picker/styles/custom-gradient-picker-styles.js.map +1 -1
- package/build-module/custom-gradient-picker/types.js +2 -0
- package/build-module/custom-gradient-picker/utils.js +17 -12
- package/build-module/custom-gradient-picker/utils.js.map +1 -1
- package/build-module/{color-list-picker → duotone-picker/color-list-picker}/index.js +5 -5
- package/build-module/duotone-picker/color-list-picker/index.js.map +1 -0
- package/build-module/duotone-picker/color-list-picker/types.js +2 -0
- package/build-module/duotone-picker/color-list-picker/types.js.map +1 -0
- package/build-module/duotone-picker/custom-duotone-bar.js.map +1 -1
- package/build-module/duotone-picker/duotone-picker.js +38 -2
- package/build-module/duotone-picker/duotone-picker.js.map +1 -1
- package/build-module/duotone-picker/duotone-swatch.js.map +1 -1
- package/build-module/duotone-picker/index.js.map +1 -1
- package/build-module/duotone-picker/types.js +2 -0
- package/build-module/duotone-picker/types.js.map +1 -0
- package/build-module/duotone-picker/utils.js +17 -11
- package/build-module/duotone-picker/utils.js.map +1 -1
- package/build-module/form-token-field/index.js +9 -4
- package/build-module/form-token-field/index.js.map +1 -1
- package/build-module/gradient-picker/index.js +61 -10
- package/build-module/gradient-picker/index.js.map +1 -1
- package/build-module/gradient-picker/types.js +2 -0
- package/build-module/gradient-picker/types.js.map +1 -0
- package/build-module/palette-edit/index.js +1 -2
- package/build-module/palette-edit/index.js.map +1 -1
- package/build-module/resizable-box/resize-tooltip/utils.js.map +1 -1
- package/build-module/sandbox/index.native.js +70 -58
- package/build-module/sandbox/index.native.js.map +1 -1
- package/build-module/tab-panel/index.js +2 -2
- package/build-module/tab-panel/index.js.map +1 -1
- package/build-module/tools-panel/tools-panel/hook.js +45 -6
- package/build-module/tools-panel/tools-panel/hook.js.map +1 -1
- package/build-module/utils/input/input-control.js +1 -1
- package/build-module/utils/input/input-control.js.map +1 -1
- package/build-style/style-rtl.css +40 -28
- package/build-style/style.css +42 -28
- package/build-types/angle-picker-control/angle-circle.d.ts.map +1 -1
- package/build-types/angle-picker-control/index.d.ts.map +1 -1
- package/build-types/angle-picker-control/styles/angle-picker-control-styles.d.ts +5 -0
- package/build-types/angle-picker-control/styles/angle-picker-control-styles.d.ts.map +1 -1
- package/build-types/animate/index.d.ts +27 -22
- package/build-types/animate/index.d.ts.map +1 -1
- package/build-types/animate/stories/index.d.ts +18 -0
- package/build-types/animate/stories/index.d.ts.map +1 -0
- package/build-types/animate/types.d.ts +30 -0
- package/build-types/animate/types.d.ts.map +1 -0
- package/build-types/color-picker/color-input.d.ts +1 -11
- package/build-types/color-picker/color-input.d.ts.map +1 -1
- package/build-types/color-picker/component.d.ts +8 -9
- package/build-types/color-picker/component.d.ts.map +1 -1
- package/build-types/color-picker/hex-input.d.ts +1 -10
- package/build-types/color-picker/hex-input.d.ts.map +1 -1
- package/build-types/color-picker/hsl-input.d.ts +1 -10
- package/build-types/color-picker/hsl-input.d.ts.map +1 -1
- package/build-types/color-picker/input-with-slider.d.ts +1 -9
- package/build-types/color-picker/input-with-slider.d.ts.map +1 -1
- package/build-types/color-picker/legacy-adapter.d.ts +1 -3
- package/build-types/color-picker/legacy-adapter.d.ts.map +1 -1
- package/build-types/color-picker/picker.d.ts +4 -7
- package/build-types/color-picker/picker.d.ts.map +1 -1
- package/build-types/color-picker/rgb-input.d.ts +1 -10
- package/build-types/color-picker/rgb-input.d.ts.map +1 -1
- package/build-types/color-picker/stories/index.d.ts +19 -0
- package/build-types/color-picker/stories/index.d.ts.map +1 -0
- package/build-types/color-picker/test/index.d.ts +2 -0
- package/build-types/color-picker/test/index.d.ts.map +1 -0
- package/build-types/color-picker/types.d.ts +105 -1
- package/build-types/color-picker/types.d.ts.map +1 -1
- package/build-types/color-picker/use-deprecated-props.d.ts +1 -44
- package/build-types/color-picker/use-deprecated-props.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/constants.d.ts +8 -8
- package/build-types/custom-gradient-picker/constants.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/gradient-bar/constants.d.ts +7 -7
- package/build-types/custom-gradient-picker/gradient-bar/constants.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/gradient-bar/control-points.d.ts +5 -22
- package/build-types/custom-gradient-picker/gradient-bar/control-points.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/gradient-bar/index.d.ts +3 -9
- package/build-types/custom-gradient-picker/gradient-bar/index.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/gradient-bar/test/utils.d.ts +2 -0
- package/build-types/custom-gradient-picker/gradient-bar/test/utils.d.ts.map +1 -0
- package/build-types/custom-gradient-picker/gradient-bar/utils.d.ts +44 -92
- package/build-types/custom-gradient-picker/gradient-bar/utils.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/index.d.ts +27 -6
- package/build-types/custom-gradient-picker/index.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/serializer.d.ts +13 -16
- package/build-types/custom-gradient-picker/serializer.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/stories/index.d.ts +12 -0
- package/build-types/custom-gradient-picker/stories/index.d.ts.map +1 -0
- package/build-types/custom-gradient-picker/styles/custom-gradient-picker-styles.d.ts +3 -2
- package/build-types/custom-gradient-picker/styles/custom-gradient-picker-styles.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/test/serializer.d.ts +2 -0
- package/build-types/custom-gradient-picker/test/serializer.d.ts.map +1 -0
- package/build-types/custom-gradient-picker/types.d.ts +120 -0
- package/build-types/custom-gradient-picker/types.d.ts.map +1 -0
- package/build-types/custom-gradient-picker/utils.d.ts +12 -4
- package/build-types/custom-gradient-picker/utils.d.ts.map +1 -1
- package/build-types/duotone-picker/color-list-picker/index.d.ts.map +1 -0
- package/build-types/{color-list-picker → duotone-picker/color-list-picker}/types.d.ts +2 -2
- package/build-types/duotone-picker/color-list-picker/types.d.ts.map +1 -0
- package/build-types/duotone-picker/custom-duotone-bar.d.ts +6 -0
- package/build-types/duotone-picker/custom-duotone-bar.d.ts.map +1 -0
- package/build-types/duotone-picker/duotone-picker.d.ts +38 -0
- package/build-types/duotone-picker/duotone-picker.d.ts.map +1 -0
- package/build-types/duotone-picker/duotone-swatch.d.ts +5 -0
- package/build-types/duotone-picker/duotone-swatch.d.ts.map +1 -0
- package/build-types/duotone-picker/index.d.ts +3 -0
- package/build-types/duotone-picker/index.d.ts.map +1 -0
- package/build-types/duotone-picker/stories/duotone-picker.d.ts +12 -0
- package/build-types/duotone-picker/stories/duotone-picker.d.ts.map +1 -0
- package/build-types/duotone-picker/stories/duotone-swatch.d.ts +14 -0
- package/build-types/duotone-picker/stories/duotone-swatch.d.ts.map +1 -0
- package/build-types/duotone-picker/types.d.ts +60 -0
- package/build-types/duotone-picker/types.d.ts.map +1 -0
- package/build-types/duotone-picker/utils.d.ts +52 -0
- package/build-types/duotone-picker/utils.d.ts.map +1 -0
- package/build-types/form-token-field/index.d.ts.map +1 -1
- package/build-types/form-token-field/types.d.ts +6 -0
- package/build-types/form-token-field/types.d.ts.map +1 -1
- package/build-types/gradient-picker/index.d.ts +49 -11
- package/build-types/gradient-picker/index.d.ts.map +1 -1
- package/build-types/gradient-picker/stories/index.d.ts +14 -0
- package/build-types/gradient-picker/stories/index.d.ts.map +1 -0
- package/build-types/gradient-picker/types.d.ts +87 -0
- package/build-types/gradient-picker/types.d.ts.map +1 -0
- package/build-types/palette-edit/index.d.ts.map +1 -1
- package/build-types/resizable-box/resize-tooltip/utils.d.ts +1 -1
- package/build-types/resizable-box/resize-tooltip/utils.d.ts.map +1 -1
- package/build-types/tab-panel/index.d.ts.map +1 -1
- package/build-types/tools-panel/tools-panel/hook.d.ts.map +1 -1
- package/build-types/tools-panel/types.d.ts +1 -0
- package/build-types/tools-panel/types.d.ts.map +1 -1
- package/build-types/utils/input/input-control.d.ts.map +1 -1
- package/package.json +19 -19
- package/src/angle-picker-control/angle-circle.tsx +0 -1
- package/src/angle-picker-control/index.tsx +14 -27
- package/src/angle-picker-control/styles/angle-picker-control-styles.tsx +16 -9
- package/src/animate/index.tsx +75 -0
- package/src/animate/stories/index.tsx +102 -0
- package/src/animate/types.ts +32 -0
- package/src/border-box-control/stories/index.tsx +1 -1
- package/src/box-control/axial-input-controls.tsx +1 -1
- package/src/circular-option-picker/style.scss +10 -0
- package/src/color-indicator/style.scss +1 -0
- package/src/color-picker/README.md +2 -2
- package/src/color-picker/color-input.tsx +1 -12
- package/src/color-picker/component.tsx +9 -18
- package/src/color-picker/hex-input.tsx +2 -7
- package/src/color-picker/hsl-input.tsx +2 -7
- package/src/color-picker/input-with-slider.tsx +1 -9
- package/src/color-picker/legacy-adapter.tsx +1 -2
- package/src/color-picker/picker.tsx +5 -6
- package/src/color-picker/rgb-input.tsx +2 -7
- package/src/color-picker/stories/index.tsx +51 -0
- package/src/color-picker/test/{index.js → index.tsx} +36 -18
- package/src/color-picker/types.ts +128 -1
- package/src/color-picker/use-deprecated-props.ts +2 -53
- package/src/combobox-control/stories/index.tsx +1 -1
- package/src/custom-gradient-picker/{constants.js → constants.ts} +2 -2
- package/src/custom-gradient-picker/gradient-bar/{control-points.js → control-points.tsx} +171 -134
- package/src/custom-gradient-picker/gradient-bar/{index.js → index.tsx} +32 -10
- package/src/custom-gradient-picker/gradient-bar/test/{utils.js → utils.ts} +58 -31
- package/src/custom-gradient-picker/gradient-bar/utils.ts +193 -0
- package/src/custom-gradient-picker/{index.js → index.tsx} +63 -22
- package/src/custom-gradient-picker/serializer.ts +82 -0
- package/src/custom-gradient-picker/stories/index.tsx +45 -0
- package/src/custom-gradient-picker/style.scss +25 -4
- package/src/custom-gradient-picker/test/{serializer.js → serializer.ts} +39 -33
- package/src/custom-gradient-picker/types.ts +137 -0
- package/src/custom-gradient-picker/{utils.js → utils.ts} +37 -22
- package/src/custom-select-control/test/index.js +6 -4
- package/src/{color-list-picker → duotone-picker/color-list-picker}/index.tsx +7 -6
- package/src/{color-list-picker → duotone-picker/color-list-picker}/types.ts +2 -2
- package/src/duotone-picker/{custom-duotone-bar.js → custom-duotone-bar.tsx} +7 -1
- package/src/duotone-picker/{duotone-picker.js → duotone-picker.tsx} +39 -2
- package/src/duotone-picker/{duotone-swatch.js → duotone-swatch.tsx} +2 -1
- package/src/duotone-picker/stories/{duotone-picker.js → duotone-picker.tsx} +15 -8
- package/src/duotone-picker/stories/{duotone-swatch.js → duotone-swatch.tsx} +9 -3
- package/src/duotone-picker/types.ts +61 -0
- package/src/duotone-picker/{utils.js → utils.ts} +29 -14
- package/src/flex/flex-item/README.md +1 -1
- package/src/form-token-field/README.md +1 -0
- package/src/form-token-field/index.tsx +10 -3
- package/src/form-token-field/style.scss +0 -7
- package/src/form-token-field/test/index.tsx +1 -0
- package/src/form-token-field/types.ts +6 -0
- package/src/gradient-picker/README.md +16 -23
- package/src/gradient-picker/{index.js → index.tsx} +70 -16
- package/src/gradient-picker/stories/{index.js → index.tsx} +19 -8
- package/src/gradient-picker/types.ts +89 -0
- package/src/item-group/test/index.js +5 -3
- package/src/palette-edit/index.tsx +4 -5
- package/src/resizable-box/resize-tooltip/utils.ts +1 -1
- package/src/sandbox/index.native.js +71 -78
- package/src/slot-fill/test/slot.js +8 -6
- package/src/style.scss +1 -1
- package/src/tab-panel/index.tsx +7 -2
- package/src/tools-panel/test/index.tsx +86 -0
- package/src/tools-panel/tools-panel/hook.ts +44 -4
- package/src/tools-panel/types.ts +1 -0
- package/src/tooltip/test/index.js +251 -301
- package/src/utils/input/input-control.js +1 -0
- package/tsconfig.json +1 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/build/color-list-picker/index.js.map +0 -1
- package/build-module/color-list-picker/index.js.map +0 -1
- package/build-types/color-list-picker/index.d.ts.map +0 -1
- package/build-types/color-list-picker/types.d.ts.map +0 -1
- package/src/animate/index.js +0 -60
- package/src/animate/stories/index.js +0 -53
- package/src/color-picker/stories/index.js +0 -41
- package/src/custom-gradient-picker/gradient-bar/utils.js +0 -189
- package/src/custom-gradient-picker/serializer.js +0 -48
- package/src/custom-gradient-picker/stories/index.js +0 -33
- /package/build/{color-list-picker → animate}/types.js +0 -0
- /package/build-module/{color-list-picker → animate}/types.js +0 -0
- /package/build-module/{color-list-picker → animate}/types.js.map +0 -0
- /package/{build/color-list-picker → build-module/custom-gradient-picker}/types.js.map +0 -0
- /package/build-types/{color-list-picker → duotone-picker/color-list-picker}/index.d.ts +0 -0
- /package/src/custom-gradient-picker/gradient-bar/{constants.js → constants.ts} +0 -0
- /package/src/custom-gradient-picker/styles/{custom-gradient-picker-styles.js → custom-gradient-picker-styles.tsx} +0 -0
- /package/src/{color-list-picker → duotone-picker/color-list-picker}/style.scss +0 -0
- /package/src/duotone-picker/{index.js → index.ts} +0 -0
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* External dependencies
|
|
5
3
|
*/
|
|
@@ -36,8 +34,21 @@ import {
|
|
|
36
34
|
MINIMUM_SIGNIFICANT_MOVE,
|
|
37
35
|
KEYBOARD_CONTROL_POINT_VARIATION,
|
|
38
36
|
} from './constants';
|
|
37
|
+
import type { WordPressComponentProps } from '../../ui/context';
|
|
38
|
+
import type {
|
|
39
|
+
ControlPointButtonProps,
|
|
40
|
+
ControlPointMoveState,
|
|
41
|
+
ControlPointsProps,
|
|
42
|
+
InsertPointProps,
|
|
43
|
+
} from '../types';
|
|
44
|
+
import type { CustomColorPickerDropdownProps } from '../../color-palette/types';
|
|
39
45
|
|
|
40
|
-
function ControlPointButton( {
|
|
46
|
+
function ControlPointButton( {
|
|
47
|
+
isOpen,
|
|
48
|
+
position,
|
|
49
|
+
color,
|
|
50
|
+
...additionalProps
|
|
51
|
+
}: WordPressComponentProps< ControlPointButtonProps, 'button', true > ) {
|
|
41
52
|
const instanceId = useInstanceId( ControlPointButton );
|
|
42
53
|
const descriptionId = `components-custom-gradient-picker__control-point-button-description-${ instanceId }`;
|
|
43
54
|
return (
|
|
@@ -75,13 +86,14 @@ function GradientColorPickerDropdown( {
|
|
|
75
86
|
isRenderedInSidebar,
|
|
76
87
|
className,
|
|
77
88
|
...props
|
|
78
|
-
} ) {
|
|
89
|
+
}: CustomColorPickerDropdownProps ) {
|
|
79
90
|
// Open the popover below the gradient control/insertion point
|
|
80
91
|
const popoverProps = useMemo(
|
|
81
|
-
() =>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
92
|
+
() =>
|
|
93
|
+
( {
|
|
94
|
+
placement: 'bottom',
|
|
95
|
+
offset: 8,
|
|
96
|
+
} as const ),
|
|
85
97
|
[]
|
|
86
98
|
);
|
|
87
99
|
|
|
@@ -110,16 +122,25 @@ function ControlPoints( {
|
|
|
110
122
|
onStartControlPointChange,
|
|
111
123
|
onStopControlPointChange,
|
|
112
124
|
__experimentalIsRenderedInSidebar,
|
|
113
|
-
} ) {
|
|
114
|
-
const controlPointMoveState = useRef();
|
|
125
|
+
}: ControlPointsProps ) {
|
|
126
|
+
const controlPointMoveState = useRef< ControlPointMoveState >();
|
|
127
|
+
|
|
128
|
+
const onMouseMove = ( event: MouseEvent ) => {
|
|
129
|
+
if (
|
|
130
|
+
controlPointMoveState.current === undefined ||
|
|
131
|
+
gradientPickerDomRef.current === null
|
|
132
|
+
) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
115
135
|
|
|
116
|
-
const onMouseMove = ( event ) => {
|
|
117
136
|
const relativePosition = getHorizontalRelativeGradientPosition(
|
|
118
137
|
event.clientX,
|
|
119
138
|
gradientPickerDomRef.current
|
|
120
139
|
);
|
|
140
|
+
|
|
121
141
|
const { initialPosition, index, significantMoveHappened } =
|
|
122
142
|
controlPointMoveState.current;
|
|
143
|
+
|
|
123
144
|
if (
|
|
124
145
|
! significantMoveHappened &&
|
|
125
146
|
Math.abs( initialPosition - relativePosition ) >=
|
|
@@ -150,142 +171,158 @@ function ControlPoints( {
|
|
|
150
171
|
// Adding `cleanEventListeners` to the dependency array below requires the function itself to be wrapped in a `useCallback`
|
|
151
172
|
// This memoization would prevent the event listeners from being properly cleaned.
|
|
152
173
|
// Instead, we'll pass a ref to the function in our `useEffect` so `cleanEventListeners` itself is no longer a dependency.
|
|
153
|
-
const cleanEventListenersRef = useRef();
|
|
174
|
+
const cleanEventListenersRef = useRef< () => void >();
|
|
154
175
|
cleanEventListenersRef.current = cleanEventListeners;
|
|
155
176
|
|
|
156
177
|
useEffect( () => {
|
|
157
178
|
return () => {
|
|
158
|
-
cleanEventListenersRef.current();
|
|
179
|
+
cleanEventListenersRef.current?.();
|
|
159
180
|
};
|
|
160
181
|
}, [] );
|
|
161
182
|
|
|
162
|
-
return
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
183
|
+
return (
|
|
184
|
+
<>
|
|
185
|
+
{ controlPoints.map( ( point, index ) => {
|
|
186
|
+
const initialPosition = point?.position;
|
|
187
|
+
return (
|
|
188
|
+
ignoreMarkerPosition !== initialPosition && (
|
|
189
|
+
<GradientColorPickerDropdown
|
|
190
|
+
isRenderedInSidebar={
|
|
191
|
+
__experimentalIsRenderedInSidebar
|
|
192
|
+
}
|
|
172
193
|
key={ index }
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
)
|
|
220
|
-
)
|
|
221
|
-
);
|
|
222
|
-
} else if ( event.code === 'ArrowRight' ) {
|
|
223
|
-
// Stop propagation of the key press event to avoid focus moving
|
|
224
|
-
// to another editor area.
|
|
225
|
-
event.stopPropagation();
|
|
226
|
-
onChange(
|
|
227
|
-
updateControlPointPosition(
|
|
228
|
-
controlPoints,
|
|
229
|
-
index,
|
|
230
|
-
clampPercent(
|
|
231
|
-
point.position +
|
|
232
|
-
KEYBOARD_CONTROL_POINT_VARIATION
|
|
233
|
-
)
|
|
234
|
-
)
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
} }
|
|
238
|
-
isOpen={ isOpen }
|
|
239
|
-
position={ point.position }
|
|
240
|
-
color={ point.color }
|
|
241
|
-
/>
|
|
242
|
-
) }
|
|
243
|
-
renderContent={ ( { onClose } ) => (
|
|
244
|
-
<>
|
|
245
|
-
<ColorPicker
|
|
246
|
-
enableAlpha={ ! disableAlpha }
|
|
247
|
-
color={ point.color }
|
|
248
|
-
onChange={ ( color ) => {
|
|
249
|
-
onChange(
|
|
250
|
-
updateControlPointColor(
|
|
251
|
-
controlPoints,
|
|
252
|
-
index,
|
|
253
|
-
colord( color ).toRgbString()
|
|
254
|
-
)
|
|
255
|
-
);
|
|
256
|
-
} }
|
|
257
|
-
/>
|
|
258
|
-
{ ! disableRemove && controlPoints.length > 2 && (
|
|
259
|
-
<HStack
|
|
260
|
-
className="components-custom-gradient-picker__remove-control-point-wrapper"
|
|
261
|
-
alignment="center"
|
|
262
|
-
>
|
|
263
|
-
<Button
|
|
264
|
-
onClick={ () => {
|
|
194
|
+
onClose={ onStopControlPointChange }
|
|
195
|
+
renderToggle={ ( { isOpen, onToggle } ) => (
|
|
196
|
+
<ControlPointButton
|
|
197
|
+
key={ index }
|
|
198
|
+
onClick={ () => {
|
|
199
|
+
if (
|
|
200
|
+
controlPointMoveState.current &&
|
|
201
|
+
controlPointMoveState.current
|
|
202
|
+
.significantMoveHappened
|
|
203
|
+
) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if ( isOpen ) {
|
|
207
|
+
onStopControlPointChange();
|
|
208
|
+
} else {
|
|
209
|
+
onStartControlPointChange();
|
|
210
|
+
}
|
|
211
|
+
onToggle();
|
|
212
|
+
} }
|
|
213
|
+
onMouseDown={ () => {
|
|
214
|
+
if (
|
|
215
|
+
window &&
|
|
216
|
+
window.addEventListener
|
|
217
|
+
) {
|
|
218
|
+
controlPointMoveState.current = {
|
|
219
|
+
initialPosition,
|
|
220
|
+
index,
|
|
221
|
+
significantMoveHappened: false,
|
|
222
|
+
listenersActivated: true,
|
|
223
|
+
};
|
|
224
|
+
onStartControlPointChange();
|
|
225
|
+
window.addEventListener(
|
|
226
|
+
'mousemove',
|
|
227
|
+
onMouseMove
|
|
228
|
+
);
|
|
229
|
+
window.addEventListener(
|
|
230
|
+
'mouseup',
|
|
231
|
+
cleanEventListeners
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
} }
|
|
235
|
+
onKeyDown={ ( event ) => {
|
|
236
|
+
if ( event.code === 'ArrowLeft' ) {
|
|
237
|
+
// Stop propagation of the key press event to avoid focus moving
|
|
238
|
+
// to another editor area.
|
|
239
|
+
event.stopPropagation();
|
|
265
240
|
onChange(
|
|
266
|
-
|
|
241
|
+
updateControlPointPosition(
|
|
267
242
|
controlPoints,
|
|
268
|
-
index
|
|
243
|
+
index,
|
|
244
|
+
clampPercent(
|
|
245
|
+
point.position -
|
|
246
|
+
KEYBOARD_CONTROL_POINT_VARIATION
|
|
247
|
+
)
|
|
248
|
+
)
|
|
249
|
+
);
|
|
250
|
+
} else if (
|
|
251
|
+
event.code === 'ArrowRight'
|
|
252
|
+
) {
|
|
253
|
+
// Stop propagation of the key press event to avoid focus moving
|
|
254
|
+
// to another editor area.
|
|
255
|
+
event.stopPropagation();
|
|
256
|
+
onChange(
|
|
257
|
+
updateControlPointPosition(
|
|
258
|
+
controlPoints,
|
|
259
|
+
index,
|
|
260
|
+
clampPercent(
|
|
261
|
+
point.position +
|
|
262
|
+
KEYBOARD_CONTROL_POINT_VARIATION
|
|
263
|
+
)
|
|
264
|
+
)
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
} }
|
|
268
|
+
isOpen={ isOpen }
|
|
269
|
+
position={ point.position }
|
|
270
|
+
color={ point.color }
|
|
271
|
+
/>
|
|
272
|
+
) }
|
|
273
|
+
renderContent={ ( { onClose } ) => (
|
|
274
|
+
<>
|
|
275
|
+
<ColorPicker
|
|
276
|
+
enableAlpha={ ! disableAlpha }
|
|
277
|
+
color={ point.color }
|
|
278
|
+
onChange={ ( color ) => {
|
|
279
|
+
onChange(
|
|
280
|
+
updateControlPointColor(
|
|
281
|
+
controlPoints,
|
|
282
|
+
index,
|
|
283
|
+
colord(
|
|
284
|
+
color
|
|
285
|
+
).toRgbString()
|
|
269
286
|
)
|
|
270
287
|
);
|
|
271
|
-
onClose();
|
|
272
288
|
} }
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
289
|
+
/>
|
|
290
|
+
{ ! disableRemove &&
|
|
291
|
+
controlPoints.length > 2 && (
|
|
292
|
+
<HStack
|
|
293
|
+
className="components-custom-gradient-picker__remove-control-point-wrapper"
|
|
294
|
+
alignment="center"
|
|
295
|
+
>
|
|
296
|
+
<Button
|
|
297
|
+
onClick={ () => {
|
|
298
|
+
onChange(
|
|
299
|
+
removeControlPoint(
|
|
300
|
+
controlPoints,
|
|
301
|
+
index
|
|
302
|
+
)
|
|
303
|
+
);
|
|
304
|
+
onClose();
|
|
305
|
+
} }
|
|
306
|
+
variant="link"
|
|
307
|
+
>
|
|
308
|
+
{ __(
|
|
309
|
+
'Remove Control Point'
|
|
310
|
+
) }
|
|
311
|
+
</Button>
|
|
312
|
+
</HStack>
|
|
313
|
+
) }
|
|
314
|
+
</>
|
|
278
315
|
) }
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
)
|
|
287
|
-
|
|
288
|
-
|
|
316
|
+
style={ {
|
|
317
|
+
left: `${ point.position }%`,
|
|
318
|
+
transform: 'translateX( -50% )',
|
|
319
|
+
} }
|
|
320
|
+
/>
|
|
321
|
+
)
|
|
322
|
+
);
|
|
323
|
+
} ) }
|
|
324
|
+
</>
|
|
325
|
+
);
|
|
289
326
|
}
|
|
290
327
|
|
|
291
328
|
function InsertPoint( {
|
|
@@ -296,7 +333,7 @@ function InsertPoint( {
|
|
|
296
333
|
insertPosition,
|
|
297
334
|
disableAlpha,
|
|
298
335
|
__experimentalIsRenderedInSidebar,
|
|
299
|
-
} ) {
|
|
336
|
+
}: InsertPointProps ) {
|
|
300
337
|
const [ alreadyInsertedPoint, setAlreadyInsertedPoint ] = useState( false );
|
|
301
338
|
return (
|
|
302
339
|
<GradientColorPickerDropdown
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* External dependencies
|
|
5
3
|
*/
|
|
@@ -16,8 +14,18 @@ import { useRef, useReducer } from '@wordpress/element';
|
|
|
16
14
|
import ControlPoints from './control-points';
|
|
17
15
|
import { getHorizontalRelativeGradientPosition } from './utils';
|
|
18
16
|
import { MINIMUM_DISTANCE_BETWEEN_INSERTER_AND_POINT } from './constants';
|
|
17
|
+
import type {
|
|
18
|
+
CustomGradientBarProps,
|
|
19
|
+
CustomGradientBarReducerState,
|
|
20
|
+
CustomGradientBarReducerAction,
|
|
21
|
+
CustomGradientBarIdleState,
|
|
22
|
+
} from '../types';
|
|
23
|
+
import type { MouseEventHandler } from 'react';
|
|
19
24
|
|
|
20
|
-
|
|
25
|
+
const customGradientBarReducer = (
|
|
26
|
+
state: CustomGradientBarReducerState,
|
|
27
|
+
action: CustomGradientBarReducerAction
|
|
28
|
+
): CustomGradientBarReducerState => {
|
|
21
29
|
switch ( action.type ) {
|
|
22
30
|
case 'MOVE_INSERTER':
|
|
23
31
|
if ( state.id === 'IDLE' || state.id === 'MOVING_INSERTER' ) {
|
|
@@ -65,8 +73,10 @@ function customGradientBarReducer( state, action ) {
|
|
|
65
73
|
break;
|
|
66
74
|
}
|
|
67
75
|
return state;
|
|
68
|
-
}
|
|
69
|
-
const customGradientBarReducerInitialState = {
|
|
76
|
+
};
|
|
77
|
+
const customGradientBarReducerInitialState: CustomGradientBarIdleState = {
|
|
78
|
+
id: 'IDLE',
|
|
79
|
+
};
|
|
70
80
|
|
|
71
81
|
export default function CustomGradientBar( {
|
|
72
82
|
background,
|
|
@@ -75,15 +85,21 @@ export default function CustomGradientBar( {
|
|
|
75
85
|
onChange,
|
|
76
86
|
disableInserter = false,
|
|
77
87
|
disableAlpha = false,
|
|
78
|
-
__experimentalIsRenderedInSidebar,
|
|
79
|
-
} ) {
|
|
80
|
-
const gradientMarkersContainerDomRef = useRef();
|
|
88
|
+
__experimentalIsRenderedInSidebar = false,
|
|
89
|
+
}: CustomGradientBarProps ) {
|
|
90
|
+
const gradientMarkersContainerDomRef = useRef< HTMLDivElement >( null );
|
|
81
91
|
|
|
82
92
|
const [ gradientBarState, gradientBarStateDispatch ] = useReducer(
|
|
83
93
|
customGradientBarReducer,
|
|
84
94
|
customGradientBarReducerInitialState
|
|
85
95
|
);
|
|
86
|
-
const onMouseEnterAndMove
|
|
96
|
+
const onMouseEnterAndMove: MouseEventHandler< HTMLDivElement > = (
|
|
97
|
+
event
|
|
98
|
+
) => {
|
|
99
|
+
if ( ! gradientMarkersContainerDomRef.current ) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
87
103
|
const insertPosition = getHorizontalRelativeGradientPosition(
|
|
88
104
|
event.clientX,
|
|
89
105
|
gradientMarkersContainerDomRef.current
|
|
@@ -123,9 +139,15 @@ export default function CustomGradientBar( {
|
|
|
123
139
|
) }
|
|
124
140
|
onMouseEnter={ onMouseEnterAndMove }
|
|
125
141
|
onMouseMove={ onMouseEnterAndMove }
|
|
126
|
-
style={ { background } }
|
|
127
142
|
onMouseLeave={ onMouseLeave }
|
|
128
143
|
>
|
|
144
|
+
<div
|
|
145
|
+
className="components-custom-gradient-picker__gradient-bar-background"
|
|
146
|
+
style={ {
|
|
147
|
+
background,
|
|
148
|
+
opacity: hasGradient ? 1 : 0.4,
|
|
149
|
+
} }
|
|
150
|
+
/>
|
|
129
151
|
<div
|
|
130
152
|
ref={ gradientMarkersContainerDomRef }
|
|
131
153
|
className="components-custom-gradient-picker__markers-container"
|
|
@@ -5,38 +5,54 @@ import { getHorizontalRelativeGradientPosition } from '../utils';
|
|
|
5
5
|
|
|
6
6
|
describe( 'getHorizontalRelativeGradientPosition', () => {
|
|
7
7
|
it( 'should return relative percentage position', () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
jest.spyOn(
|
|
9
|
+
window.HTMLElement.prototype,
|
|
10
|
+
'getBoundingClientRect'
|
|
11
|
+
).mockImplementationOnce(
|
|
12
|
+
() =>
|
|
13
|
+
( {
|
|
14
|
+
x: 0,
|
|
15
|
+
width: 1000,
|
|
16
|
+
} as DOMRect )
|
|
17
|
+
);
|
|
14
18
|
|
|
19
|
+
const containerElement = document.createElement( 'div' );
|
|
15
20
|
expect(
|
|
16
21
|
getHorizontalRelativeGradientPosition( 500, containerElement )
|
|
17
22
|
).toBe( 50 );
|
|
18
23
|
} );
|
|
19
24
|
|
|
20
25
|
it( 'should subtract the x position of the container from the mouse position', () => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
jest.spyOn(
|
|
27
|
+
window.HTMLElement.prototype,
|
|
28
|
+
'getBoundingClientRect'
|
|
29
|
+
).mockImplementationOnce(
|
|
30
|
+
() =>
|
|
31
|
+
( {
|
|
32
|
+
x: 50,
|
|
33
|
+
width: 1000,
|
|
34
|
+
} as DOMRect )
|
|
35
|
+
);
|
|
27
36
|
|
|
37
|
+
const containerElement = document.createElement( 'div' );
|
|
28
38
|
expect(
|
|
29
39
|
getHorizontalRelativeGradientPosition( 550, containerElement )
|
|
30
40
|
).toBe( 50 );
|
|
31
41
|
} );
|
|
32
42
|
|
|
33
43
|
it( 'should clamp to a whole percentage number', () => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
jest.spyOn(
|
|
45
|
+
window.HTMLElement.prototype,
|
|
46
|
+
'getBoundingClientRect'
|
|
47
|
+
).mockImplementationOnce(
|
|
48
|
+
() =>
|
|
49
|
+
( {
|
|
50
|
+
x: 0,
|
|
51
|
+
width: 1000,
|
|
52
|
+
} as DOMRect )
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const containerElement = document.createElement( 'div' );
|
|
40
56
|
|
|
41
57
|
expect(
|
|
42
58
|
getHorizontalRelativeGradientPosition( 333, containerElement )
|
|
@@ -44,12 +60,17 @@ describe( 'getHorizontalRelativeGradientPosition', () => {
|
|
|
44
60
|
} );
|
|
45
61
|
|
|
46
62
|
it( 'should clamp to zero when mouse position is less the x position', () => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
63
|
+
jest.spyOn(
|
|
64
|
+
window.HTMLElement.prototype,
|
|
65
|
+
'getBoundingClientRect'
|
|
66
|
+
).mockImplementationOnce(
|
|
67
|
+
() =>
|
|
68
|
+
( {
|
|
69
|
+
x: 50,
|
|
70
|
+
width: 1000,
|
|
71
|
+
} as DOMRect )
|
|
72
|
+
);
|
|
73
|
+
const containerElement = document.createElement( 'div' );
|
|
53
74
|
|
|
54
75
|
expect(
|
|
55
76
|
getHorizontalRelativeGradientPosition( 2, containerElement )
|
|
@@ -57,12 +78,18 @@ describe( 'getHorizontalRelativeGradientPosition', () => {
|
|
|
57
78
|
} );
|
|
58
79
|
|
|
59
80
|
it( 'should clamp to 100 when mouse position is greater than width', () => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
81
|
+
jest.spyOn(
|
|
82
|
+
window.HTMLElement.prototype,
|
|
83
|
+
'getBoundingClientRect'
|
|
84
|
+
).mockImplementationOnce(
|
|
85
|
+
() =>
|
|
86
|
+
( {
|
|
87
|
+
x: 50,
|
|
88
|
+
width: 1000,
|
|
89
|
+
} as DOMRect )
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const containerElement = document.createElement( 'div' );
|
|
66
93
|
|
|
67
94
|
expect(
|
|
68
95
|
getHorizontalRelativeGradientPosition( 1500, containerElement )
|
|
@@ -70,7 +97,7 @@ describe( 'getHorizontalRelativeGradientPosition', () => {
|
|
|
70
97
|
} );
|
|
71
98
|
|
|
72
99
|
it( 'should return undefined if no containerElement is provided', () => {
|
|
73
|
-
const containerElement =
|
|
100
|
+
const containerElement = null;
|
|
74
101
|
|
|
75
102
|
expect(
|
|
76
103
|
getHorizontalRelativeGradientPosition( 1500, containerElement )
|