@wordpress/components 40.0.0 → 40.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 +40 -0
- package/CONTRIBUTING.md +2 -0
- package/build/border-box-control/border-box-control/component.cjs +37 -5
- package/build/border-box-control/border-box-control/component.cjs.map +3 -3
- package/build/border-box-control/border-box-control/hook.cjs +24 -3
- package/build/border-box-control/border-box-control/hook.cjs.map +3 -3
- package/build/border-box-control/border-box-control-linked-button/hook.cjs +2 -2
- package/build/border-box-control/border-box-control-linked-button/hook.cjs.map +2 -2
- package/build/border-box-control/border-box-control-split-controls/hook.cjs +2 -2
- package/build/border-box-control/border-box-control-split-controls/hook.cjs.map +2 -2
- package/build/border-box-control/border-box-control-visualizer/hook.cjs +2 -2
- package/build/border-box-control/border-box-control-visualizer/hook.cjs.map +2 -2
- package/build/color-palette/index.cjs +1 -1
- package/build/color-palette/index.cjs.map +2 -2
- package/build/composite/context.cjs +9 -2
- package/build/composite/context.cjs.map +2 -2
- package/build/composite/group-label.cjs +4 -0
- package/build/composite/group-label.cjs.map +2 -2
- package/build/composite/group.cjs +10 -2
- package/build/composite/group.cjs.map +2 -2
- package/build/composite/item.cjs +4 -0
- package/build/composite/item.cjs.map +3 -3
- package/build/context/context-system-provider.cjs +2 -5
- package/build/context/context-system-provider.cjs.map +3 -3
- package/build/context/use-context-system.cjs +7 -2
- package/build/context/use-context-system.cjs.map +2 -2
- package/build/disabled/index.cjs +1 -1
- package/build/disabled/index.cjs.map +2 -2
- package/build/draggable/index.cjs.map +1 -1
- package/build/form-token-field/index.cjs +1 -1
- package/build/form-token-field/index.cjs.map +2 -2
- package/build/icon/index.cjs +30 -12
- package/build/icon/index.cjs.map +2 -2
- package/build/input-control/styles/input-control-styles.cjs +42 -27
- package/build/input-control/styles/input-control-styles.cjs.map +2 -2
- package/build/item-group/context.cjs +1 -0
- package/build/item-group/context.cjs.map +2 -2
- package/build/item-group/item/component.cjs +12 -0
- package/build/item-group/item/component.cjs.map +3 -3
- package/build/item-group/item/hook.cjs +7 -6
- package/build/item-group/item/hook.cjs.map +2 -2
- package/build/item-group/item-group/component.cjs +1 -0
- package/build/item-group/item-group/component.cjs.map +2 -2
- package/build/item-group/item-group/hook.cjs +1 -1
- package/build/item-group/item-group/hook.cjs.map +2 -2
- package/build/progress-bar/index.cjs +1 -1
- package/build/progress-bar/index.cjs.map +2 -2
- package/build/resizable-box/index.cjs.map +1 -1
- package/build/snackbar/index.cjs +8 -5
- package/build/snackbar/index.cjs.map +2 -2
- package/build/textarea-control/index.cjs +1 -1
- package/build/textarea-control/index.cjs.map +2 -2
- package/build/toggle-group-control/context.cjs +8 -2
- package/build/toggle-group-control/context.cjs.map +2 -2
- package/build/toggle-group-control/toggle-group-control/as-button-group.cjs +5 -2
- package/build/toggle-group-control/toggle-group-control/as-button-group.cjs.map +2 -2
- package/build/toggle-group-control/toggle-group-control/as-radio-group.cjs +5 -2
- package/build/toggle-group-control/toggle-group-control/as-radio-group.cjs.map +2 -2
- package/build/toggle-group-control/toggle-group-control/component.cjs +3 -1
- package/build/toggle-group-control/toggle-group-control/component.cjs.map +2 -2
- package/build/toggle-group-control/toggle-group-control-option/component.cjs +2 -0
- package/build/toggle-group-control/toggle-group-control-option/component.cjs.map +2 -2
- package/build/toggle-group-control/toggle-group-control-option-base/component.cjs +2 -1
- package/build/toggle-group-control/toggle-group-control-option-base/component.cjs.map +2 -2
- package/build/toggle-group-control/toggle-group-control-option-icon/component.cjs +2 -0
- package/build/toggle-group-control/toggle-group-control-option-icon/component.cjs.map +2 -2
- package/build/tools-panel/tools-panel/hook.cjs +102 -106
- package/build/tools-panel/tools-panel/hook.cjs.map +2 -2
- package/build/tools-panel/tools-panel-item/hook.cjs +33 -33
- package/build/tools-panel/tools-panel-item/hook.cjs.map +2 -2
- package/build/tree-grid/cell.cjs +4 -0
- package/build/tree-grid/cell.cjs.map +2 -2
- package/build/tree-grid/roving-tab-index-item.cjs +5 -1
- package/build/tree-grid/roving-tab-index-item.cjs.map +2 -2
- package/build/tree-grid/row.cjs +6 -1
- package/build/tree-grid/row.cjs.map +2 -2
- package/build/tree-grid/use-validate-tree-grid-structure.cjs +81 -0
- package/build/tree-grid/use-validate-tree-grid-structure.cjs.map +7 -0
- package/build/utils/colors-values.cjs +3 -2
- package/build/utils/colors-values.cjs.map +2 -2
- package/build-module/border-box-control/border-box-control/component.mjs +38 -6
- package/build-module/border-box-control/border-box-control/component.mjs.map +2 -2
- package/build-module/border-box-control/border-box-control/hook.mjs +14 -3
- package/build-module/border-box-control/border-box-control/hook.mjs.map +2 -2
- package/build-module/border-box-control/border-box-control-linked-button/hook.mjs +2 -2
- package/build-module/border-box-control/border-box-control-linked-button/hook.mjs.map +2 -2
- package/build-module/border-box-control/border-box-control-split-controls/hook.mjs +2 -2
- package/build-module/border-box-control/border-box-control-split-controls/hook.mjs.map +2 -2
- package/build-module/border-box-control/border-box-control-visualizer/hook.mjs +2 -2
- package/build-module/border-box-control/border-box-control-visualizer/hook.mjs.map +2 -2
- package/build-module/color-palette/index.mjs +1 -1
- package/build-module/color-palette/index.mjs.map +2 -2
- package/build-module/composite/context.mjs +6 -1
- package/build-module/composite/context.mjs.map +2 -2
- package/build-module/composite/group-label.mjs +5 -1
- package/build-module/composite/group-label.mjs.map +2 -2
- package/build-module/composite/group.mjs +11 -3
- package/build-module/composite/group.mjs.map +2 -2
- package/build-module/composite/item.mjs +4 -0
- package/build-module/composite/item.mjs.map +2 -2
- package/build-module/context/context-system-provider.mjs +2 -5
- package/build-module/context/context-system-provider.mjs.map +3 -3
- package/build-module/context/use-context-system.mjs +7 -2
- package/build-module/context/use-context-system.mjs.map +2 -2
- package/build-module/disabled/index.mjs +1 -1
- package/build-module/disabled/index.mjs.map +2 -2
- package/build-module/draggable/index.mjs.map +1 -1
- package/build-module/form-token-field/index.mjs +1 -1
- package/build-module/form-token-field/index.mjs.map +2 -2
- package/build-module/icon/index.mjs +30 -12
- package/build-module/icon/index.mjs.map +2 -2
- package/build-module/input-control/styles/input-control-styles.mjs +42 -27
- package/build-module/input-control/styles/input-control-styles.mjs.map +2 -2
- package/build-module/item-group/context.mjs +1 -0
- package/build-module/item-group/context.mjs.map +2 -2
- package/build-module/item-group/item/component.mjs +12 -0
- package/build-module/item-group/item/component.mjs.map +2 -2
- package/build-module/item-group/item/hook.mjs +7 -6
- package/build-module/item-group/item/hook.mjs.map +2 -2
- package/build-module/item-group/item-group/component.mjs +1 -0
- package/build-module/item-group/item-group/component.mjs.map +2 -2
- package/build-module/item-group/item-group/hook.mjs +1 -1
- package/build-module/item-group/item-group/hook.mjs.map +2 -2
- package/build-module/progress-bar/index.mjs +1 -1
- package/build-module/progress-bar/index.mjs.map +2 -2
- package/build-module/resizable-box/index.mjs.map +1 -1
- package/build-module/snackbar/index.mjs +8 -5
- package/build-module/snackbar/index.mjs.map +2 -2
- package/build-module/textarea-control/index.mjs +1 -1
- package/build-module/textarea-control/index.mjs.map +2 -2
- package/build-module/toggle-group-control/context.mjs +8 -2
- package/build-module/toggle-group-control/context.mjs.map +2 -2
- package/build-module/toggle-group-control/toggle-group-control/as-button-group.mjs +5 -2
- package/build-module/toggle-group-control/toggle-group-control/as-button-group.mjs.map +2 -2
- package/build-module/toggle-group-control/toggle-group-control/as-radio-group.mjs +5 -2
- 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/component.mjs +3 -1
- package/build-module/toggle-group-control/toggle-group-control/component.mjs.map +2 -2
- package/build-module/toggle-group-control/toggle-group-control-option/component.mjs +2 -0
- package/build-module/toggle-group-control/toggle-group-control-option/component.mjs.map +2 -2
- package/build-module/toggle-group-control/toggle-group-control-option-base/component.mjs +2 -1
- package/build-module/toggle-group-control/toggle-group-control-option-base/component.mjs.map +2 -2
- package/build-module/toggle-group-control/toggle-group-control-option-icon/component.mjs +2 -0
- package/build-module/toggle-group-control/toggle-group-control-option-icon/component.mjs.map +2 -2
- package/build-module/tools-panel/tools-panel/hook.mjs +103 -107
- package/build-module/tools-panel/tools-panel/hook.mjs.map +2 -2
- package/build-module/tools-panel/tools-panel-item/hook.mjs +35 -35
- package/build-module/tools-panel/tools-panel-item/hook.mjs.map +2 -2
- package/build-module/tree-grid/cell.mjs +5 -1
- package/build-module/tree-grid/cell.mjs.map +2 -2
- package/build-module/tree-grid/roving-tab-index-item.mjs +5 -1
- package/build-module/tree-grid/roving-tab-index-item.mjs.map +2 -2
- package/build-module/tree-grid/row.mjs +7 -2
- package/build-module/tree-grid/row.mjs.map +2 -2
- package/build-module/tree-grid/use-validate-tree-grid-structure.mjs +56 -0
- package/build-module/tree-grid/use-validate-tree-grid-structure.mjs.map +7 -0
- package/build-module/utils/colors-values.mjs +3 -2
- package/build-module/utils/colors-values.mjs.map +2 -2
- package/build-style/style-rtl.css +27 -85
- package/build-style/style.css +27 -85
- package/build-types/border-box-control/border-box-control/component.d.ts +4 -0
- package/build-types/border-box-control/border-box-control/component.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control/hook.d.ts +4 -2
- package/build-types/border-box-control/border-box-control/hook.d.ts.map +1 -1
- package/build-types/border-box-control/types.d.ts +6 -2
- package/build-types/border-box-control/types.d.ts.map +1 -1
- package/build-types/composite/context.d.ts +2 -0
- package/build-types/composite/context.d.ts.map +1 -1
- package/build-types/composite/group-label.d.ts.map +1 -1
- package/build-types/composite/group.d.ts.map +1 -1
- package/build-types/composite/item.d.ts.map +1 -1
- package/build-types/composite/types.d.ts +1 -1
- package/build-types/context/context-system-provider.d.ts +8 -6
- package/build-types/context/context-system-provider.d.ts.map +1 -1
- package/build-types/context/use-context-system.d.ts.map +1 -1
- package/build-types/icon/index.d.ts.map +1 -1
- package/build-types/input-control/styles/input-control-styles.d.ts.map +1 -1
- package/build-types/item-group/context.d.ts.map +1 -1
- package/build-types/item-group/item/component.d.ts.map +1 -1
- package/build-types/item-group/item/hook.d.ts +1 -1
- package/build-types/item-group/item/hook.d.ts.map +1 -1
- package/build-types/item-group/item-group/component.d.ts.map +1 -1
- package/build-types/item-group/types.d.ts +4 -0
- package/build-types/item-group/types.d.ts.map +1 -1
- package/build-types/popover/types.d.ts +6 -2
- package/build-types/popover/types.d.ts.map +1 -1
- package/build-types/snackbar/index.d.ts.map +1 -1
- package/build-types/toggle-group-control/context.d.ts +2 -2
- package/build-types/toggle-group-control/context.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control/as-button-group.d.ts +1 -1
- package/build-types/toggle-group-control/toggle-group-control/as-button-group.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control/as-radio-group.d.ts +1 -1
- package/build-types/toggle-group-control/toggle-group-control/as-radio-group.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control/component.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control-option/component.d.ts +2 -2
- package/build-types/toggle-group-control/toggle-group-control-option/component.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control-option-base/component.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control-option-icon/component.d.ts +2 -2
- package/build-types/toggle-group-control/toggle-group-control-option-icon/component.d.ts.map +1 -1
- package/build-types/toggle-group-control/types.d.ts +12 -3
- package/build-types/toggle-group-control/types.d.ts.map +1 -1
- package/build-types/tools-panel/tools-panel/hook.d.ts +4 -4
- package/build-types/tools-panel/tools-panel/hook.d.ts.map +1 -1
- package/build-types/tools-panel/tools-panel-item/hook.d.ts.map +1 -1
- package/build-types/tools-panel/types.d.ts +52 -9
- package/build-types/tools-panel/types.d.ts.map +1 -1
- package/build-types/tree-grid/cell.d.ts.map +1 -1
- package/build-types/tree-grid/roving-tab-index-item.d.ts.map +1 -1
- package/build-types/tree-grid/row.d.ts.map +1 -1
- package/build-types/tree-grid/use-validate-tree-grid-structure.d.ts +2 -0
- package/build-types/tree-grid/use-validate-tree-grid-structure.d.ts.map +1 -0
- package/build-types/utils/colors-values.d.ts.map +1 -1
- package/emotion-to-scss-modules.md +149 -0
- package/package.json +28 -27
- package/src/alignment-matrix-control/test/{index.tsx → index.jsdom.test.tsx} +5 -4
- package/src/angle-picker-control/style.module.scss +1 -1
- package/src/autocomplete/test/get-autocomplete-match.ts +2 -1
- package/src/autocomplete/test/{index.tsx → index.jsdom.test.tsx} +2 -1
- package/src/badge/test/{index.tsx → index.jsdom.test.tsx} +1 -0
- package/src/base-control/stories/index.story.tsx +2 -2
- package/src/base-control/test/{index.tsx → index.jsdom.test.tsx} +1 -0
- package/src/border-box-control/border-box-control/README.md +5 -3
- package/src/border-box-control/border-box-control/component.tsx +83 -15
- package/src/border-box-control/border-box-control/hook.ts +19 -1
- package/src/border-box-control/stories/index.story.tsx +10 -0
- package/src/border-box-control/style.module.scss +34 -3
- package/src/border-box-control/test/{index.tsx → index.jsdom.test.tsx} +138 -2
- package/src/border-box-control/test/utils.ts +11 -0
- package/src/border-box-control/types.ts +6 -2
- package/src/border-control/test/{index.js → index.jsdom.test.tsx} +44 -24
- package/src/box-control/test/{index.tsx → index.jsdom.test.tsx} +6 -3
- package/src/button/style.scss +0 -6
- package/src/button/test/{index.tsx → index.jsdom.test.tsx} +6 -2
- package/src/checkbox-control/stories/index.story.tsx +1 -1
- package/src/checkbox-control/style.scss +2 -2
- package/src/checkbox-control/test/__snapshots__/{index.tsx.snap → index.jsdom.test.tsx.snap} +10 -7
- package/src/checkbox-control/test/{index.tsx → index.jsdom.test.tsx} +4 -1
- package/src/circular-option-picker/test/{index.tsx → index.jsdom.test.tsx} +1 -0
- package/src/color-indicator/test/__snapshots__/{index.tsx.snap → index.jsdom.test.tsx.snap} +2 -2
- package/src/color-indicator/test/{index.tsx → index.jsdom.test.tsx} +1 -0
- package/src/color-palette/index.tsx +1 -1
- package/src/color-palette/test/{index.tsx → index.jsdom.test.tsx} +25 -22
- package/src/color-palette/test/{utils.ts → utils.jsdom.test.ts} +1 -0
- package/src/combobox-control/test/{index.tsx → index.jsdom.test.tsx} +12 -7
- package/src/composite/README.md +1 -1
- package/src/composite/context.tsx +6 -0
- package/src/composite/group-label.tsx +8 -1
- package/src/composite/group.tsx +9 -2
- package/src/composite/item.tsx +6 -0
- package/src/composite/legacy/test/{index.tsx → index.jsdom.test.tsx} +6 -13
- package/src/composite/test/{index.tsx → index.jsdom.test.tsx} +60 -17
- package/src/composite/types.ts +1 -1
- package/src/confirm-dialog/test/{index.tsx → index.jsdom.test.tsx} +16 -14
- package/src/content-editable-control/test/{index.tsx → index.jsdom.test.tsx} +4 -3
- package/src/context/{context-system-provider.js → context-system-provider.tsx} +19 -5
- package/src/context/stories/{ComponentsProvider.stories.jsx → ComponentsProvider.stories.tsx} +2 -2
- package/src/context/test/context-connect.tsx +1 -2
- package/src/context/test/{context-system-provider.js → context-system-provider.jsdom.test.tsx} +93 -51
- package/src/context/test/wordpress-component.tsx +1 -2
- package/src/context/use-context-system.js +13 -4
- package/src/custom-gradient-picker/gradient-bar/test/{utils.ts → utils.jsdom.test.ts} +6 -5
- package/src/custom-gradient-picker/test/serializer.ts +1 -0
- package/src/custom-select-control-v2/test/{index.tsx → index.jsdom.test.tsx} +4 -1
- package/src/date-time/date-picker/test/{index.tsx → index.jsdom.test.tsx} +6 -3
- package/src/date-time/date-picker/test/{use-lilius.ts → use-lilius.jsdom.test.ts} +1 -0
- package/src/date-time/date-time/test/{index.tsx → index.jsdom.test.tsx} +20 -11
- package/src/date-time/test/utils.test.ts +9 -0
- package/src/date-time/time-picker/test/{index.tsx → index.jsdom.test.tsx} +37 -27
- package/src/date-time/time-picker/time-input/test/{index.tsx → index.jsdom.test.tsx} +8 -3
- package/src/disabled/index.tsx +7 -7
- package/src/disabled/test/{index.tsx → index.jsdom.test.tsx} +26 -0
- package/src/draggable/index.tsx +1 -1
- package/src/draggable/style.module.scss +1 -1
- package/src/dropdown/style.module.scss +2 -2
- package/src/dropdown/test/{index.tsx → index.jsdom.test.tsx} +1 -0
- package/src/dropdown-menu/test/{index.tsx → index.jsdom.test.tsx} +5 -4
- package/src/duotone-picker/test/{custom-duotone-bar.tsx → custom-duotone-bar.jsdom.test.tsx} +11 -8
- package/src/duotone-picker/test/{index.tsx → index.jsdom.test.tsx} +11 -10
- package/src/external-link/test/{index.tsx → index.jsdom.test.tsx} +5 -4
- package/src/focal-point-picker/test/{index.tsx → index.jsdom.test.tsx} +12 -9
- package/src/focal-point-picker/test/{media.tsx → media.jsdom.test.tsx} +1 -0
- package/src/font-size-picker/test/{font-size-picker-select.tsx → font-size-picker-select.jsdom.test.tsx} +19 -16
- package/src/font-size-picker/test/{font-size-picker-toggle-group.tsx → font-size-picker-toggle-group.jsdom.test.tsx} +13 -11
- package/src/font-size-picker/test/{index.tsx → index.jsdom.test.tsx} +19 -14
- package/src/font-size-picker/test/utils.ts +1 -0
- package/src/form-toggle/style.scss +1 -1
- package/src/form-toggle/test/__snapshots__/{index.tsx.snap → index.jsdom.test.tsx.snap} +4 -4
- package/src/form-toggle/test/{index.tsx → index.jsdom.test.tsx} +2 -1
- package/src/form-token-field/index.tsx +1 -1
- package/src/form-token-field/test/{index.tsx → index.jsdom.test.tsx} +86 -44
- package/src/gradient-picker/test/{index.tsx → index.jsdom.test.tsx} +12 -9
- package/src/guide/test/{index.tsx → index.jsdom.test.tsx} +4 -2
- package/src/h-stack/test/__snapshots__/{index.tsx.snap → index.jsdom.test.tsx.snap} +4 -4
- package/src/h-stack/test/{index.tsx → index.jsdom.test.tsx} +3 -0
- package/src/higher-order/with-fallback-styles/test/{index.tsx → index.jsdom.test.tsx} +3 -2
- package/src/higher-order/with-filters/test/__snapshots__/index.jsdom.test.tsx.snap +87 -0
- package/src/higher-order/with-filters/test/{index.tsx → index.jsdom.test.tsx} +6 -5
- package/src/higher-order/with-focus-outside/test/{index.tsx → index.jsdom.test.tsx} +2 -1
- package/src/higher-order/with-focus-return/test/{index.tsx → index.jsdom.test.tsx} +1 -0
- package/src/higher-order/with-notices/test/{index.tsx → index.jsdom.test.tsx} +1 -0
- package/src/higher-order/with-spoken-messages/test/{index.tsx → index.jsdom.test.tsx} +3 -2
- package/src/icon/index.tsx +28 -12
- package/src/icon/test/{index.tsx → index.jsdom.test.tsx} +66 -0
- package/src/input-control/styles/input-control-styles.tsx +38 -7
- package/src/input-control/test/{index.js → index.jsdom.test.tsx} +16 -10
- package/src/isolated-event-container/test/{index.tsx → index.jsdom.test.tsx} +4 -3
- package/src/item-group/context.ts +1 -0
- package/src/item-group/item/component.tsx +19 -1
- package/src/item-group/item/hook.ts +2 -3
- package/src/item-group/item-group/component.tsx +1 -0
- package/src/item-group/style.module.scss +1 -2
- package/src/item-group/test/__snapshots__/{index.js.snap → index.jsdom.test.tsx.snap} +9 -9
- package/src/item-group/test/{index.js → index.jsdom.test.tsx} +99 -2
- package/src/item-group/types.ts +4 -0
- package/src/keyboard-shortcuts/test/{index.tsx → index.jsdom.test.tsx} +5 -4
- package/src/menu/test/{index.tsx → index.jsdom.test.tsx} +67 -23
- package/src/menu-group/test/{index.tsx → index.jsdom.test.tsx} +1 -0
- package/src/menu-item/test/__snapshots__/{index.js.snap → index.jsdom.test.tsx.snap} +5 -5
- package/src/menu-item/test/{index.js → index.jsdom.test.tsx} +1 -0
- package/src/modal/test/{aria-helper.ts → aria-helper.jsdom.test.ts} +1 -0
- package/src/modal/test/{index.tsx → index.jsdom.test.tsx} +9 -5
- package/src/navigable-container/test/{navigable-menu.tsx → navigable-menu.jsdom.test.tsx} +7 -5
- package/src/navigable-container/test/{tababble-container.tsx → tababble-container.jsdom.test.tsx} +5 -3
- package/src/navigator/test/{index.tsx → index.jsdom.test.tsx} +5 -2
- package/src/navigator/test/router.ts +1 -0
- package/src/notice/test/__snapshots__/{index.tsx.snap → index.jsdom.test.tsx.snap} +7 -4
- package/src/notice/test/{index.tsx → index.jsdom.test.tsx} +8 -4
- package/src/notice/test/{list.tsx → list.jsdom.test.tsx} +1 -0
- package/src/number-control/test/{index.tsx → index.jsdom.test.tsx} +9 -6
- package/src/palette-edit/test/{index.tsx → index.jsdom.test.tsx} +16 -13
- package/src/panel/test/__snapshots__/body.jsdom.test.tsx.snap +9 -0
- package/src/panel/test/__snapshots__/header.jsdom.test.tsx.snap +9 -0
- package/src/panel/test/__snapshots__/index.jsdom.test.tsx.snap +17 -0
- package/src/panel/test/__snapshots__/row.jsdom.test.tsx.snap +17 -0
- package/src/panel/test/{body.tsx → body.jsdom.test.tsx} +2 -1
- package/src/panel/test/{header.tsx → header.jsdom.test.tsx} +1 -0
- package/src/panel/test/{index.tsx → index.jsdom.test.tsx} +1 -0
- package/src/panel/test/{row.tsx → row.jsdom.test.tsx} +1 -0
- package/src/placeholder/style.scss +0 -5
- package/src/placeholder/test/{index.tsx → index.jsdom.test.tsx} +19 -14
- package/src/popover/README.md +2 -2
- package/src/popover/test/{index.tsx → index.jsdom.test.tsx} +23 -0
- package/src/popover/types.ts +9 -3
- package/src/progress-bar/style.module.scss +9 -1
- package/src/query-controls/test/terms.ts +1 -0
- package/src/radio-control/test/{index.tsx → index.jsdom.test.tsx} +14 -11
- package/src/range-control/test/{index.tsx → index.jsdom.test.tsx} +10 -7
- package/src/resizable-box/index.tsx +1 -1
- package/src/sandbox/test/{index.tsx → index.jsdom.test.tsx} +1 -0
- package/src/scroll-lock/test/{index.tsx → index.jsdom.test.tsx} +1 -0
- package/src/shortcut/test/__snapshots__/index.jsdom.test.tsx.snap +15 -0
- package/src/shortcut/test/{index.tsx → index.jsdom.test.tsx} +1 -0
- package/src/slot-fill/test/{index.js → index.jsdom.test.tsx} +4 -3
- package/src/slot-fill/test/{slot.js → slot.jsdom.test.tsx} +17 -9
- package/src/snackbar/index.tsx +10 -6
- package/src/snackbar/test/{index.tsx → index.jsdom.test.tsx} +41 -11
- package/src/snackbar/test/list.jsdom.test.tsx +100 -0
- package/src/style-provider/test/{index.tsx → index.jsdom.test.tsx} +1 -0
- package/src/surface/style.module.scss +2 -2
- package/src/surface/test/{index.tsx → index.jsdom.test.tsx} +1 -0
- package/src/tab-panel/style.scss +4 -23
- package/src/tab-panel/test/{index.tsx → index.jsdom.test.tsx} +22 -21
- package/src/tabs/test/{index.tsx → index.jsdom.test.tsx} +21 -19
- package/src/text-control/test/{text-control.tsx → text-control.jsdom.test.tsx} +1 -0
- package/src/text-highlight/test/{index.tsx → index.jsdom.test.tsx} +1 -0
- package/src/textarea-control/style.module.scss +9 -4
- package/src/tip/style.scss +1 -1
- package/src/toggle-control/test/{index.tsx → index.jsdom.test.tsx} +4 -1
- package/src/toggle-group-control/context.ts +14 -5
- package/src/toggle-group-control/stories/index.story.tsx +15 -2
- package/src/toggle-group-control/test/{index.tsx → index.jsdom.test.tsx} +283 -9
- package/src/toggle-group-control/toggle-group-control/README.md +8 -5
- package/src/toggle-group-control/toggle-group-control/as-button-group.tsx +4 -0
- package/src/toggle-group-control/toggle-group-control/as-radio-group.tsx +4 -0
- package/src/toggle-group-control/toggle-group-control/component.tsx +2 -0
- package/src/toggle-group-control/toggle-group-control/style.module.scss +8 -2
- package/src/toggle-group-control/toggle-group-control-option/README.md +8 -5
- package/src/toggle-group-control/toggle-group-control-option/component.tsx +2 -0
- package/src/toggle-group-control/toggle-group-control-option-base/component.tsx +4 -1
- package/src/toggle-group-control/toggle-group-control-option-icon/README.md +7 -0
- package/src/toggle-group-control/toggle-group-control-option-icon/component.tsx +2 -0
- package/src/toggle-group-control/types.ts +12 -3
- package/src/toolbar/test/{index.tsx → index.jsdom.test.tsx} +1 -0
- package/src/toolbar/test/{toolbar-group.tsx → toolbar-group.jsdom.test.tsx} +2 -1
- package/src/tools-panel/test/{index.tsx → index.jsdom.test.tsx} +595 -47
- package/src/tools-panel/tools-panel/hook.ts +195 -180
- package/src/tools-panel/tools-panel-item/README.md +42 -1
- package/src/tools-panel/tools-panel-item/hook.ts +97 -69
- package/src/tools-panel/types.ts +54 -9
- package/src/tooltip/test/{index.tsx → index.jsdom.test.tsx} +5 -3
- package/src/tree-grid/cell.tsx +6 -2
- package/src/tree-grid/roving-tab-index-item.tsx +7 -3
- package/src/tree-grid/row.tsx +8 -2
- package/src/tree-grid/test/__snapshots__/{cell.tsx.snap → cell.jsdom.test.tsx.snap} +2 -2
- package/src/tree-grid/test/__snapshots__/index.jsdom.test.tsx.snap +3 -0
- package/src/tree-grid/test/__snapshots__/roving-tab-index-item.jsdom.test.tsx.snap +27 -0
- package/src/tree-grid/test/__snapshots__/roving-tab-index.jsdom.test.tsx.snap +9 -0
- package/src/tree-grid/test/__snapshots__/{row.tsx.snap → row.jsdom.test.tsx.snap} +9 -5
- package/src/tree-grid/test/cell.jsdom.test.tsx +149 -0
- package/src/tree-grid/test/{index.tsx → index.jsdom.test.tsx} +9 -7
- package/src/tree-grid/test/{roving-tab-index-item.tsx → roving-tab-index-item.jsdom.test.tsx} +4 -1
- package/src/tree-grid/test/{roving-tab-index.tsx → roving-tab-index.jsdom.test.tsx} +1 -0
- package/src/tree-grid/test/row.jsdom.test.tsx +132 -0
- package/src/tree-grid/use-validate-tree-grid-structure.ts +104 -0
- package/src/truncate/style.module.scss +0 -1
- package/src/truncate/test/{index.tsx → index.jsdom.test.tsx} +1 -0
- package/src/unit-control/test/{index.tsx → index.jsdom.test.tsx} +22 -19
- package/src/unit-control/test/utils.ts +1 -0
- package/src/utils/colors-values.js +5 -4
- package/src/utils/hooks/test/{use-controlled-state.js → use-controlled-state.jsdom.test.tsx} +22 -7
- package/src/utils/hooks/test/{use-controlled-value.js → use-controlled-value.jsdom.test.tsx} +6 -3
- package/src/utils/hooks/test/{use-cx.js → use-cx.jsdom.test.tsx} +8 -5
- package/src/utils/test/colors.js +1 -0
- package/src/utils/test/{get-node-text.js → get-node-text.tsx} +1 -0
- package/src/utils/test/math.js +1 -0
- package/src/utils/test/rtl.js +1 -0
- package/src/utils/test/space.js +1 -0
- package/src/utils/test/strings.js +1 -0
- package/src/utils/test/unit-values.js +1 -0
- package/src/v-stack/test/__snapshots__/{index.tsx.snap → index.jsdom.test.tsx.snap} +4 -4
- package/src/v-stack/test/{index.tsx → index.jsdom.test.tsx} +3 -0
- package/src/validated-form-controls/style.scss +11 -15
- package/src/validated-form-controls/test/{content-editable-control.tsx → content-editable-control.jsdom.test.tsx} +1 -1
- package/src/validated-form-controls/test/{custom-select-control.tsx → custom-select-control.jsdom.test.tsx} +3 -0
- package/src/validated-form-controls/test/{input-control.tsx → input-control.jsdom.test.tsx} +3 -0
- package/src/validated-form-controls/test/{range-control.tsx → range-control.jsdom.test.tsx} +3 -0
- package/src/validated-form-controls/test/{textarea-control.tsx → textarea-control.jsdom.test.tsx} +1 -0
- package/src/view/test/__snapshots__/{index.js.snap → index.jsdom.test.tsx.snap} +7 -7
- package/src/view/test/{index.js → index.jsdom.test.tsx} +7 -2
- package/src/context/test/__snapshots__/context-system-provider.js.snap +0 -35
- package/src/higher-order/with-filters/test/__snapshots__/index.tsx.snap +0 -87
- package/src/panel/test/__snapshots__/body.tsx.snap +0 -9
- package/src/panel/test/__snapshots__/header.tsx.snap +0 -9
- package/src/panel/test/__snapshots__/index.tsx.snap +0 -17
- package/src/panel/test/__snapshots__/row.tsx.snap +0 -17
- package/src/shortcut/test/__snapshots__/index.tsx.snap +0 -15
- package/src/snackbar/test/list.tsx +0 -39
- package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +0 -359
- package/src/tree-grid/test/__snapshots__/index.tsx.snap +0 -3
- package/src/tree-grid/test/__snapshots__/roving-tab-index-item.tsx.snap +0 -27
- package/src/tree-grid/test/__snapshots__/roving-tab-index.tsx.snap +0 -9
- package/src/tree-grid/test/cell.tsx +0 -46
- package/src/tree-grid/test/row.tsx +0 -37
- /package/src/card/test/__snapshots__/{index.tsx.snap → index.jsdom.test.tsx.snap} +0 -0
- /package/src/card/test/{index.tsx → index.jsdom.test.tsx} +0 -0
- /package/src/color-picker/test/{index.tsx → index.jsdom.test.tsx} +0 -0
- /package/src/custom-gradient-picker/test/{index.tsx → index.jsdom.test.tsx} +0 -0
- /package/src/custom-select-control/test/__snapshots__/{index.tsx.snap → index.jsdom.test.tsx.snap} +0 -0
- /package/src/custom-select-control/test/{index.tsx → index.jsdom.test.tsx} +0 -0
- /package/src/divider/test/{index.tsx → index.jsdom.test.tsx} +0 -0
- /package/src/elevation/test/__snapshots__/{index.tsx.snap → index.jsdom.test.tsx.snap} +0 -0
- /package/src/elevation/test/{index.tsx → index.jsdom.test.tsx} +0 -0
- /package/src/flex/test/__snapshots__/{index.tsx.snap → index.jsdom.test.tsx.snap} +0 -0
- /package/src/flex/test/{index.tsx → index.jsdom.test.tsx} +0 -0
- /package/src/form-file-upload/test/{index.tsx → index.jsdom.test.tsx} +0 -0
- /package/src/grid/test/{grid.tsx → grid.jsdom.test.tsx} +0 -0
- /package/src/heading/test/__snapshots__/{index.tsx.snap → index.jsdom.test.tsx.snap} +0 -0
- /package/src/heading/test/{index.tsx → index.jsdom.test.tsx} +0 -0
- /package/src/input-control/test/__snapshots__/{index.js.snap → index.jsdom.test.tsx.snap} +0 -0
- /package/src/progress-bar/test/{index.tsx → index.jsdom.test.tsx} +0 -0
- /package/src/resizable-box/resize-tooltip/test/{index.tsx → index.jsdom.test.tsx} +0 -0
- /package/src/resizable-box/resize-tooltip/test/{label.tsx → label.jsdom.test.tsx} +0 -0
- /package/src/scrollable/test/{index.tsx → index.jsdom.test.tsx} +0 -0
- /package/src/search-control/test/{index.tsx → index.jsdom.test.tsx} +0 -0
- /package/src/select-control/test/__snapshots__/{select-control.tsx.snap → select-control.jsdom.test.tsx.snap} +0 -0
- /package/src/select-control/test/{select-control.tsx → select-control.jsdom.test.tsx} +0 -0
- /package/src/slot-fill/test/__snapshots__/{slot.js.snap → slot.jsdom.test.tsx.snap} +0 -0
- /package/src/spacer/test/__snapshots__/{index.tsx.snap → index.jsdom.test.tsx.snap} +0 -0
- /package/src/spacer/test/{index.tsx → index.jsdom.test.tsx} +0 -0
- /package/src/text/test/__snapshots__/{index.tsx.snap → index.jsdom.test.tsx.snap} +0 -0
- /package/src/text/test/{index.tsx → index.jsdom.test.tsx} +0 -0
- /package/src/utils/test/{polymorphic-element.tsx → polymorphic-element.jsdom.test.tsx} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// packages/components/src/tools-panel/tools-panel/hook.ts
|
|
2
2
|
import clsx from "clsx";
|
|
3
|
-
import { useCallback, useEffect, useMemo, useReducer,
|
|
3
|
+
import { useCallback, useEffect, useMemo, useReducer, useState } from "@wordpress/element";
|
|
4
4
|
|
|
5
5
|
// packages/style-runtime/src/index.ts
|
|
6
6
|
var STYLE_HASH_ATTRIBUTE = "data-wp-hash";
|
|
@@ -87,62 +87,20 @@ var style_module_default = { "tools-panel": "_62d714739f4dc308__tools-panel", "t
|
|
|
87
87
|
|
|
88
88
|
// packages/components/src/tools-panel/tools-panel/hook.ts
|
|
89
89
|
import { useContextSystem } from "../../context/index.mjs";
|
|
90
|
-
function emptyMenuItems() {
|
|
91
|
-
return {
|
|
92
|
-
default: {},
|
|
93
|
-
optional: {}
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
90
|
function emptyState() {
|
|
97
91
|
return {
|
|
98
92
|
panelItems: [],
|
|
99
93
|
menuItemOrder: [],
|
|
100
|
-
|
|
94
|
+
menuItemValues: {}
|
|
101
95
|
};
|
|
102
96
|
}
|
|
103
|
-
var
|
|
104
|
-
|
|
105
|
-
shouldReset,
|
|
106
|
-
currentMenuItems,
|
|
107
|
-
menuItemOrder
|
|
108
|
-
}) => {
|
|
109
|
-
const newMenuItems = emptyMenuItems();
|
|
110
|
-
const menuItems = emptyMenuItems();
|
|
111
|
-
panelItems.forEach(({
|
|
112
|
-
hasValue,
|
|
113
|
-
isShownByDefault,
|
|
114
|
-
label
|
|
115
|
-
}) => {
|
|
116
|
-
const group = isShownByDefault ? "default" : "optional";
|
|
117
|
-
const existingItemValue = currentMenuItems?.[group]?.[label];
|
|
118
|
-
const value = existingItemValue ? existingItemValue : hasValue();
|
|
119
|
-
newMenuItems[group][label] = shouldReset ? false : value;
|
|
120
|
-
});
|
|
121
|
-
menuItemOrder.forEach((key) => {
|
|
122
|
-
if (newMenuItems.default.hasOwnProperty(key)) {
|
|
123
|
-
menuItems.default[key] = newMenuItems.default[key];
|
|
124
|
-
}
|
|
125
|
-
if (newMenuItems.optional.hasOwnProperty(key)) {
|
|
126
|
-
menuItems.optional[key] = newMenuItems.optional[key];
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
Object.keys(newMenuItems.default).forEach((key) => {
|
|
130
|
-
if (!menuItems.default.hasOwnProperty(key)) {
|
|
131
|
-
menuItems.default[key] = newMenuItems.default[key];
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
Object.keys(newMenuItems.optional).forEach((key) => {
|
|
135
|
-
if (!menuItems.optional.hasOwnProperty(key)) {
|
|
136
|
-
menuItems.optional[key] = newMenuItems.optional[key];
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
return menuItems;
|
|
140
|
-
};
|
|
97
|
+
var getSeedValue = (item) => item.hasValue() || !item.isShownByDefault && !!item.defaultShown;
|
|
98
|
+
var getMenuGroup = (item) => item.isShownByDefault ? "default" : "optional";
|
|
141
99
|
function panelItemsReducer(panelItems, action) {
|
|
142
100
|
switch (action.type) {
|
|
143
101
|
case "REGISTER_PANEL": {
|
|
102
|
+
const existingIndex = panelItems.findIndex((item) => item.label === action.item.label);
|
|
144
103
|
const newItems = [...panelItems];
|
|
145
|
-
const existingIndex = newItems.findIndex((oldItem) => oldItem.label === action.item.label);
|
|
146
104
|
if (existingIndex !== -1) {
|
|
147
105
|
newItems.splice(existingIndex, 1);
|
|
148
106
|
}
|
|
@@ -151,12 +109,15 @@ function panelItemsReducer(panelItems, action) {
|
|
|
151
109
|
}
|
|
152
110
|
case "UNREGISTER_PANEL": {
|
|
153
111
|
const index = panelItems.findIndex((item) => item.label === action.label);
|
|
154
|
-
if (index
|
|
155
|
-
|
|
156
|
-
newItems.splice(index, 1);
|
|
157
|
-
return newItems;
|
|
112
|
+
if (index === -1) {
|
|
113
|
+
return panelItems;
|
|
158
114
|
}
|
|
159
|
-
|
|
115
|
+
if (action.item && panelItems[index] !== action.item) {
|
|
116
|
+
return panelItems;
|
|
117
|
+
}
|
|
118
|
+
const newItems = [...panelItems];
|
|
119
|
+
newItems.splice(index, 1);
|
|
120
|
+
return newItems;
|
|
160
121
|
}
|
|
161
122
|
default:
|
|
162
123
|
return panelItems;
|
|
@@ -174,66 +135,74 @@ function menuItemOrderReducer(menuItemOrder, action) {
|
|
|
174
135
|
return menuItemOrder;
|
|
175
136
|
}
|
|
176
137
|
}
|
|
177
|
-
function
|
|
138
|
+
function menuItemValuesReducer(state, action) {
|
|
139
|
+
const values = state.menuItemValues;
|
|
178
140
|
switch (action.type) {
|
|
179
|
-
case "REGISTER_PANEL":
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
panelItems: state.panelItems,
|
|
190
|
-
menuItemOrder: state.menuItemOrder,
|
|
191
|
-
shouldReset: true
|
|
192
|
-
});
|
|
141
|
+
case "REGISTER_PANEL": {
|
|
142
|
+
if (!values.hasOwnProperty(action.item.label)) {
|
|
143
|
+
return values;
|
|
144
|
+
}
|
|
145
|
+
const {
|
|
146
|
+
[action.item.label]: unusedValue,
|
|
147
|
+
...rest
|
|
148
|
+
} = values;
|
|
149
|
+
return rest;
|
|
150
|
+
}
|
|
193
151
|
case "UPDATE_VALUE": {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
return state.menuItems;
|
|
152
|
+
if (values[action.label] === action.value) {
|
|
153
|
+
return values;
|
|
197
154
|
}
|
|
198
155
|
return {
|
|
199
|
-
...
|
|
200
|
-
[action.
|
|
201
|
-
...state.menuItems[action.group],
|
|
202
|
-
[action.label]: action.value
|
|
203
|
-
}
|
|
156
|
+
...values,
|
|
157
|
+
[action.label]: action.value
|
|
204
158
|
};
|
|
205
159
|
}
|
|
206
160
|
case "TOGGLE_VALUE": {
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
161
|
+
const item = state.panelItems.find(({
|
|
162
|
+
label
|
|
163
|
+
}) => label === action.label);
|
|
164
|
+
if (!item) {
|
|
165
|
+
return values;
|
|
166
|
+
}
|
|
167
|
+
const current = values[action.label] ?? getSeedValue(item);
|
|
168
|
+
return {
|
|
169
|
+
...values,
|
|
170
|
+
[action.label]: !current
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
case "RESET_ALL": {
|
|
174
|
+
const hidden = state.panelItems.filter((item) => !item.isShownByDefault && values[item.label] !== false);
|
|
175
|
+
if (!hidden.length) {
|
|
176
|
+
return values;
|
|
210
177
|
}
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
...state.menuItems,
|
|
214
|
-
[menuGroup]: {
|
|
215
|
-
...state.menuItems[menuGroup],
|
|
216
|
-
[action.label]: !state.menuItems[menuGroup][action.label]
|
|
217
|
-
}
|
|
178
|
+
const next = {
|
|
179
|
+
...values
|
|
218
180
|
};
|
|
219
|
-
|
|
181
|
+
hidden.forEach(({
|
|
182
|
+
label
|
|
183
|
+
}) => {
|
|
184
|
+
next[label] = false;
|
|
185
|
+
});
|
|
186
|
+
return next;
|
|
220
187
|
}
|
|
221
188
|
default:
|
|
222
|
-
return
|
|
189
|
+
return values;
|
|
223
190
|
}
|
|
224
191
|
}
|
|
225
192
|
function panelReducer(state, action) {
|
|
226
193
|
const panelItems = panelItemsReducer(state.panelItems, action);
|
|
227
194
|
const menuItemOrder = menuItemOrderReducer(state.menuItemOrder, action);
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
menuItems: state.menuItems
|
|
195
|
+
const menuItemValues = menuItemValuesReducer({
|
|
196
|
+
...state,
|
|
197
|
+
panelItems
|
|
232
198
|
}, action);
|
|
199
|
+
if (panelItems === state.panelItems && menuItemOrder === state.menuItemOrder && menuItemValues === state.menuItemValues) {
|
|
200
|
+
return state;
|
|
201
|
+
}
|
|
233
202
|
return {
|
|
234
203
|
panelItems,
|
|
235
204
|
menuItemOrder,
|
|
236
|
-
|
|
205
|
+
menuItemValues
|
|
237
206
|
};
|
|
238
207
|
}
|
|
239
208
|
function resetAllFiltersReducer(filters, action) {
|
|
@@ -259,28 +228,29 @@ function useToolsPanel(props) {
|
|
|
259
228
|
__experimentalLastVisibleItemClass,
|
|
260
229
|
...otherProps
|
|
261
230
|
} = useContextSystem(props, "ToolsPanel");
|
|
262
|
-
const
|
|
263
|
-
const wasResetting = isResettingRef.current;
|
|
231
|
+
const [isResetting, setIsResetting] = useState(false);
|
|
264
232
|
useEffect(() => {
|
|
265
|
-
if (
|
|
266
|
-
|
|
233
|
+
if (isResetting) {
|
|
234
|
+
setIsResetting(false);
|
|
267
235
|
}
|
|
268
|
-
}, [
|
|
236
|
+
}, [isResetting]);
|
|
269
237
|
const [{
|
|
270
238
|
panelItems,
|
|
271
|
-
|
|
239
|
+
menuItemOrder,
|
|
240
|
+
menuItemValues
|
|
272
241
|
}, panelDispatch] = useReducer(panelReducer, void 0, emptyState);
|
|
273
|
-
const [
|
|
242
|
+
const [externalResetAllFilters, dispatchResetAllFilters] = useReducer(resetAllFiltersReducer, []);
|
|
274
243
|
const registerPanelItem = useCallback((item) => {
|
|
275
244
|
panelDispatch({
|
|
276
245
|
type: "REGISTER_PANEL",
|
|
277
246
|
item
|
|
278
247
|
});
|
|
279
248
|
}, []);
|
|
280
|
-
const deregisterPanelItem = useCallback((label) => {
|
|
249
|
+
const deregisterPanelItem = useCallback((label, item) => {
|
|
281
250
|
panelDispatch({
|
|
282
251
|
type: "UNREGISTER_PANEL",
|
|
283
|
-
label
|
|
252
|
+
label,
|
|
253
|
+
item
|
|
284
254
|
});
|
|
285
255
|
}, []);
|
|
286
256
|
const registerResetAllFilter = useCallback((filter) => {
|
|
@@ -295,27 +265,53 @@ function useToolsPanel(props) {
|
|
|
295
265
|
filter
|
|
296
266
|
});
|
|
297
267
|
}, []);
|
|
298
|
-
const flagItemCustomization = useCallback((value, label
|
|
268
|
+
const flagItemCustomization = useCallback((value, label) => {
|
|
299
269
|
panelDispatch({
|
|
300
270
|
type: "UPDATE_VALUE",
|
|
301
|
-
group,
|
|
302
271
|
label,
|
|
303
272
|
value
|
|
304
273
|
});
|
|
305
274
|
}, []);
|
|
275
|
+
const menuItems = useMemo(() => {
|
|
276
|
+
const result = {
|
|
277
|
+
default: {},
|
|
278
|
+
optional: {}
|
|
279
|
+
};
|
|
280
|
+
const byLabel = new Map(panelItems.map((item) => [item.label, item]));
|
|
281
|
+
menuItemOrder.forEach((label) => {
|
|
282
|
+
const item = byLabel.get(label);
|
|
283
|
+
if (!item) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
result[getMenuGroup(item)][label] = menuItemValues[label] ?? getSeedValue(item);
|
|
287
|
+
});
|
|
288
|
+
return result;
|
|
289
|
+
}, [panelItems, menuItemOrder, menuItemValues]);
|
|
306
290
|
const areAllOptionalControlsHidden = useMemo(() => {
|
|
307
291
|
return isMenuItemTypeEmpty(menuItems.default) && !isMenuItemTypeEmpty(menuItems.optional) && Object.values(menuItems.optional).every((isSelected) => !isSelected);
|
|
308
292
|
}, [menuItems]);
|
|
309
293
|
const classes = clsx(style_module_default["tools-panel"], hasInnerWrapper && style_module_default["tools-panel-with-inner-wrapper"], areAllOptionalControlsHidden && style_module_default["tools-panel-hidden-inner-wrapper"], className);
|
|
310
294
|
const toggleItem = useCallback((label) => {
|
|
295
|
+
const currentItem = panelItems.find((item) => item.label === label);
|
|
296
|
+
if (!currentItem) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
311
299
|
panelDispatch({
|
|
312
300
|
type: "TOGGLE_VALUE",
|
|
313
301
|
label
|
|
314
302
|
});
|
|
315
|
-
|
|
303
|
+
if (currentItem.isShownByDefault) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
currentItem.onShownChange?.(!menuItems.optional[label]);
|
|
307
|
+
}, [menuItems, panelItems]);
|
|
308
|
+
const resetAllFilters = useMemo(() => {
|
|
309
|
+
const itemFilters = panelItems.map((item) => item.resetAllFilter).filter((filter) => !!filter);
|
|
310
|
+
return [...itemFilters, ...externalResetAllFilters];
|
|
311
|
+
}, [panelItems, externalResetAllFilters]);
|
|
316
312
|
const resetAllItems = useCallback(() => {
|
|
317
313
|
if (typeof resetAll === "function") {
|
|
318
|
-
|
|
314
|
+
setIsResetting(true);
|
|
319
315
|
resetAll(resetAllFilters);
|
|
320
316
|
}
|
|
321
317
|
panelDispatch({
|
|
@@ -337,7 +333,7 @@ function useToolsPanel(props) {
|
|
|
337
333
|
firstDisplayedItem,
|
|
338
334
|
flagItemCustomization,
|
|
339
335
|
hasMenuItems,
|
|
340
|
-
isResetting
|
|
336
|
+
isResetting,
|
|
341
337
|
lastDisplayedItem,
|
|
342
338
|
menuItems,
|
|
343
339
|
panelId,
|
|
@@ -346,7 +342,7 @@ function useToolsPanel(props) {
|
|
|
346
342
|
shouldRenderPlaceholderItems,
|
|
347
343
|
__experimentalFirstVisibleItemClass,
|
|
348
344
|
__experimentalLastVisibleItemClass
|
|
349
|
-
}), [areAllOptionalControlsHidden, deregisterPanelItem, deregisterResetAllFilter, firstDisplayedItem, flagItemCustomization, lastDisplayedItem, menuItems, panelId, hasMenuItems, registerResetAllFilter, registerPanelItem, shouldRenderPlaceholderItems, __experimentalFirstVisibleItemClass, __experimentalLastVisibleItemClass]);
|
|
345
|
+
}), [areAllOptionalControlsHidden, deregisterPanelItem, deregisterResetAllFilter, firstDisplayedItem, flagItemCustomization, isResetting, lastDisplayedItem, menuItems, panelId, hasMenuItems, registerResetAllFilter, registerPanelItem, shouldRenderPlaceholderItems, __experimentalFirstVisibleItemClass, __experimentalLastVisibleItemClass]);
|
|
350
346
|
return {
|
|
351
347
|
...otherProps,
|
|
352
348
|
headingLevel,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/tools-panel/tools-panel/hook.ts", "../../../../style-runtime/src/index.ts", "../../../src/tools-panel/style.module.scss"],
|
|
4
|
-
"sourcesContent": ["import clsx from 'clsx';\nimport { useCallback, useEffect, useMemo, useReducer, useRef } from '@wordpress/element';\nimport styles from '../style.module.scss';\nimport { useContextSystem } from '../../context';\nfunction emptyMenuItems() {\n return {\n default: {},\n optional: {}\n };\n}\nfunction emptyState() {\n return {\n panelItems: [],\n menuItemOrder: [],\n menuItems: emptyMenuItems()\n };\n}\nconst generateMenuItems = ({\n panelItems,\n shouldReset,\n currentMenuItems,\n menuItemOrder\n}) => {\n const newMenuItems = emptyMenuItems();\n const menuItems = emptyMenuItems();\n panelItems.forEach(({\n hasValue,\n isShownByDefault,\n label\n }) => {\n const group = isShownByDefault ? 'default' : 'optional';\n\n // If a menu item for this label has already been flagged as customized\n // (for default controls), or toggled on (for optional controls), do not\n // overwrite its value as those controls would lose that state.\n const existingItemValue = currentMenuItems?.[group]?.[label];\n const value = existingItemValue ? existingItemValue : hasValue();\n newMenuItems[group][label] = shouldReset ? false : value;\n });\n\n // Loop the known, previously registered items first to maintain menu order.\n menuItemOrder.forEach(key => {\n if (newMenuItems.default.hasOwnProperty(key)) {\n menuItems.default[key] = newMenuItems.default[key];\n }\n if (newMenuItems.optional.hasOwnProperty(key)) {\n menuItems.optional[key] = newMenuItems.optional[key];\n }\n });\n\n // Loop newMenuItems object adding any that aren't in the known items order.\n Object.keys(newMenuItems.default).forEach(key => {\n if (!menuItems.default.hasOwnProperty(key)) {\n menuItems.default[key] = newMenuItems.default[key];\n }\n });\n Object.keys(newMenuItems.optional).forEach(key => {\n if (!menuItems.optional.hasOwnProperty(key)) {\n menuItems.optional[key] = newMenuItems.optional[key];\n }\n });\n return menuItems;\n};\nfunction panelItemsReducer(panelItems, action) {\n switch (action.type) {\n case 'REGISTER_PANEL':\n {\n const newItems = [...panelItems];\n // If an item with this label has already been registered, remove it\n // first. This can happen when an item is moved between the default\n // and optional groups.\n const existingIndex = newItems.findIndex(oldItem => oldItem.label === action.item.label);\n if (existingIndex !== -1) {\n newItems.splice(existingIndex, 1);\n }\n newItems.push(action.item);\n return newItems;\n }\n case 'UNREGISTER_PANEL':\n {\n const index = panelItems.findIndex(item => item.label === action.label);\n if (index !== -1) {\n const newItems = [...panelItems];\n newItems.splice(index, 1);\n return newItems;\n }\n return panelItems;\n }\n default:\n return panelItems;\n }\n}\nfunction menuItemOrderReducer(menuItemOrder, action) {\n switch (action.type) {\n case 'REGISTER_PANEL':\n {\n // Track the initial order of item registration. This is used for\n // maintaining menu item order later.\n if (menuItemOrder.includes(action.item.label)) {\n return menuItemOrder;\n }\n return [...menuItemOrder, action.item.label];\n }\n default:\n return menuItemOrder;\n }\n}\nfunction menuItemsReducer(state, action) {\n switch (action.type) {\n case 'REGISTER_PANEL':\n case 'UNREGISTER_PANEL':\n // generate new menu items from original `menuItems` and updated `panelItems` and `menuItemOrder`\n return generateMenuItems({\n currentMenuItems: state.menuItems,\n panelItems: state.panelItems,\n menuItemOrder: state.menuItemOrder,\n shouldReset: false\n });\n case 'RESET_ALL':\n return generateMenuItems({\n panelItems: state.panelItems,\n menuItemOrder: state.menuItemOrder,\n shouldReset: true\n });\n case 'UPDATE_VALUE':\n {\n const oldValue = state.menuItems[action.group][action.label];\n if (action.value === oldValue) {\n return state.menuItems;\n }\n return {\n ...state.menuItems,\n [action.group]: {\n ...state.menuItems[action.group],\n [action.label]: action.value\n }\n };\n }\n case 'TOGGLE_VALUE':\n {\n const currentItem = state.panelItems.find(item => item.label === action.label);\n if (!currentItem) {\n return state.menuItems;\n }\n const menuGroup = currentItem.isShownByDefault ? 'default' : 'optional';\n const newMenuItems = {\n ...state.menuItems,\n [menuGroup]: {\n ...state.menuItems[menuGroup],\n [action.label]: !state.menuItems[menuGroup][action.label]\n }\n };\n return newMenuItems;\n }\n default:\n return state.menuItems;\n }\n}\nfunction panelReducer(state, action) {\n const panelItems = panelItemsReducer(state.panelItems, action);\n const menuItemOrder = menuItemOrderReducer(state.menuItemOrder, action);\n // `menuItemsReducer` is a bit unusual because it generates new state from original `menuItems`\n // and the updated `panelItems` and `menuItemOrder`.\n const menuItems = menuItemsReducer({\n panelItems,\n menuItemOrder,\n menuItems: state.menuItems\n }, action);\n return {\n panelItems,\n menuItemOrder,\n menuItems\n };\n}\nfunction resetAllFiltersReducer(filters, action) {\n switch (action.type) {\n case 'REGISTER':\n return [...filters, action.filter];\n case 'UNREGISTER':\n return filters.filter(f => f !== action.filter);\n default:\n return filters;\n }\n}\nconst isMenuItemTypeEmpty = obj => Object.keys(obj).length === 0;\nexport function useToolsPanel(props) {\n const {\n className,\n headingLevel = 2,\n resetAll,\n panelId,\n hasInnerWrapper = false,\n shouldRenderPlaceholderItems = false,\n __experimentalFirstVisibleItemClass,\n __experimentalLastVisibleItemClass,\n ...otherProps\n } = useContextSystem(props, 'ToolsPanel');\n const isResettingRef = useRef(false);\n const wasResetting = isResettingRef.current;\n\n // `isResettingRef` is cleared via this hook to effectively batch together\n // the resetAll task. Without this, the flag is cleared after the first\n // control updates and forces a rerender with subsequent controls then\n // believing they need to reset, unfortunately using stale data.\n useEffect(() => {\n if (wasResetting) {\n isResettingRef.current = false;\n }\n }, [wasResetting]);\n\n // Allow panel items to register themselves.\n const [{\n panelItems,\n menuItems\n }, panelDispatch] = useReducer(panelReducer, undefined, emptyState);\n const [resetAllFilters, dispatchResetAllFilters] = useReducer(resetAllFiltersReducer, []);\n const registerPanelItem = useCallback(item => {\n // Add item to panel items.\n panelDispatch({\n type: 'REGISTER_PANEL',\n item\n });\n }, []);\n\n // Panels need to deregister on unmount to avoid orphans in menu state.\n // This is an issue when panel items are being injected via SlotFills.\n const deregisterPanelItem = useCallback(label => {\n // When switching selections between components injecting matching\n // controls, e.g. both panels have a \"padding\" control, the\n // deregistration of the first panel doesn't occur until after the\n // registration of the next.\n panelDispatch({\n type: 'UNREGISTER_PANEL',\n label\n });\n }, []);\n const registerResetAllFilter = useCallback(filter => {\n dispatchResetAllFilters({\n type: 'REGISTER',\n filter\n });\n }, []);\n const deregisterResetAllFilter = useCallback(filter => {\n dispatchResetAllFilters({\n type: 'UNREGISTER',\n filter\n });\n }, []);\n\n // Updates the status of the panel’s menu items. For default items the\n // value represents whether it differs from the default and for optional\n // items whether the item is shown.\n const flagItemCustomization = useCallback((value, label, group = 'default') => {\n panelDispatch({\n type: 'UPDATE_VALUE',\n group,\n label,\n value\n });\n }, []);\n\n // Whether all optional menu items are hidden or not must be tracked\n // in order to later determine if the panel display is empty and handle\n // conditional display of a plus icon to indicate the presence of further\n // menu items.\n const areAllOptionalControlsHidden = useMemo(() => {\n return isMenuItemTypeEmpty(menuItems.default) && !isMenuItemTypeEmpty(menuItems.optional) && Object.values(menuItems.optional).every(isSelected => !isSelected);\n }, [menuItems]);\n const classes = clsx(styles['tools-panel'], hasInnerWrapper && styles['tools-panel-with-inner-wrapper'], areAllOptionalControlsHidden && styles['tools-panel-hidden-inner-wrapper'], className);\n\n // Toggle the checked state of a menu item which is then used to determine\n // display of the item within the panel.\n const toggleItem = useCallback(label => {\n panelDispatch({\n type: 'TOGGLE_VALUE',\n label\n });\n }, []);\n\n // Resets display of children and executes resetAll callback if available.\n const resetAllItems = useCallback(() => {\n if (typeof resetAll === 'function') {\n isResettingRef.current = true;\n resetAll(resetAllFilters);\n }\n\n // Turn off display of all non-default items.\n panelDispatch({\n type: 'RESET_ALL'\n });\n }, [resetAllFilters, resetAll]);\n\n // Assist ItemGroup styling when there are potentially hidden placeholder\n // items by identifying first & last items that are toggled on for display.\n const getFirstVisibleItemLabel = items => {\n const optionalItems = menuItems.optional || {};\n const firstItem = items.find(item => item.isShownByDefault || optionalItems[item.label]);\n return firstItem?.label;\n };\n const firstDisplayedItem = getFirstVisibleItemLabel(panelItems);\n const lastDisplayedItem = getFirstVisibleItemLabel([...panelItems].reverse());\n const hasMenuItems = panelItems.length > 0;\n const panelContext = useMemo(() => ({\n areAllOptionalControlsHidden,\n deregisterPanelItem,\n deregisterResetAllFilter,\n firstDisplayedItem,\n flagItemCustomization,\n hasMenuItems,\n isResetting: isResettingRef.current,\n lastDisplayedItem,\n menuItems,\n panelId,\n registerPanelItem,\n registerResetAllFilter,\n shouldRenderPlaceholderItems,\n __experimentalFirstVisibleItemClass,\n __experimentalLastVisibleItemClass\n }), [areAllOptionalControlsHidden, deregisterPanelItem, deregisterResetAllFilter, firstDisplayedItem, flagItemCustomization, lastDisplayedItem, menuItems, panelId, hasMenuItems, registerResetAllFilter, registerPanelItem, shouldRenderPlaceholderItems, __experimentalFirstVisibleItemClass, __experimentalLastVisibleItemClass]);\n return {\n ...otherProps,\n headingLevel,\n panelContext,\n resetAllItems,\n toggleItem,\n className: classes\n };\n}", "const STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n const globalScope = globalThis;\n if (globalScope.__wpStyleRuntime) {\n return globalScope.__wpStyleRuntime;\n }\n globalScope.__wpStyleRuntime = {\n documents: new Map(),\n styles: new Map(),\n injectedStyles: new WeakMap()\n };\n if (typeof document !== 'undefined') {\n registerDocument(document);\n }\n return globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(targetDocument, hash) {\n if (!targetDocument.head) {\n return false;\n }\n for (const style of targetDocument.head.querySelectorAll(`style[${STYLE_HASH_ATTRIBUTE}]`)) {\n if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle(targetDocument, hash, css) {\n if (!targetDocument.head) {\n return;\n }\n const runtime = getRuntime();\n let injectedStyles = runtime.injectedStyles.get(targetDocument);\n if (!injectedStyles) {\n injectedStyles = new Set();\n runtime.injectedStyles.set(targetDocument, injectedStyles);\n }\n if (injectedStyles.has(hash)) {\n return;\n }\n\n // Older generated CSS module output can still inject matching style tags\n // after this document's cache is created, so keep the DOM as the fallback\n // source of truth on cache misses.\n if (documentContainsStyleHash(targetDocument, hash)) {\n injectedStyles.add(hash);\n return;\n }\n const style = targetDocument.createElement('style');\n style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);\n style.appendChild(targetDocument.createTextNode(css));\n targetDocument.head.appendChild(style);\n injectedStyles.add(hash);\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument(targetDocument) {\n const runtime = getRuntime();\n runtime.documents.set(targetDocument, (runtime.documents.get(targetDocument) ?? 0) + 1);\n for (const [hash, css] of runtime.styles) {\n injectStyle(targetDocument, hash, css);\n }\n return () => {\n const count = runtime.documents.get(targetDocument);\n if (count === undefined) {\n return;\n }\n if (count <= 1) {\n runtime.documents.delete(targetDocument);\n return;\n }\n runtime.documents.set(targetDocument, count - 1);\n };\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle(hash, css) {\n const runtime = getRuntime();\n runtime.styles.set(hash, css);\n for (const targetDocument of runtime.documents.keys()) {\n injectStyle(targetDocument, hash, css);\n }\n}", "import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"29b739f451\", \"._62d714739f4dc308__tools-panel{border-top:1px solid #ddd;margin-top:-1px;padding:16px}._40db7f4f897b683d__tools-panel-with-inner-wrapper>div:not(:first-of-type){column-gap:16px;display:grid;grid-column:1/-1;grid-template-columns:repeat(2,minmax(0,1fr));row-gap:16px}._95a15674966f30a3__tools-panel-hidden-inner-wrapper>div:not(:first-of-type){display:none}._322a049b9b7d8674__tools-panel-header{gap:8px;grid-column:1/-1}._322a049b9b7d8674__tools-panel-header .components-dropdown-menu{line-height:0;margin:-4px 0}._322a049b9b7d8674__tools-panel-header._322a049b9b7d8674__tools-panel-header._322a049b9b7d8674__tools-panel-header._322a049b9b7d8674__tools-panel-header .components-dropdown-menu__toggle{min-width:24px;padding:0}.b92a382d3b30104d__tools-panel-heading.b92a382d3b30104d__tools-panel-heading{font-size:inherit;line-height:normal;margin:0}._8005d68fffa9db91__tools-panel-item{grid-column:1/-1}._8005d68fffa9db91__tools-panel-item>div,._8005d68fffa9db91__tools-panel-item>fieldset{margin-bottom:0;max-width:100%;padding-bottom:0}._8005d68fffa9db91__tools-panel-item .components-base-control__help,._8005d68fffa9db91__tools-panel-item._8005d68fffa9db91__tools-panel-item .components-base-control,._8005d68fffa9db91__tools-panel-item._8005d68fffa9db91__tools-panel-item .components-base-control .components-base-control__field:last-child{margin-bottom:0}._4f55e1a6e373746e__tools-panel-item-placeholder{display:none}.d40032517bff9e12__dropdown-menu{min-width:200px}.f135b96aa96ca6bb__reset-label{color:var(--wp-components-color-accent-darker-10,var(--wp-admin-theme-color-darker-10,#2145e6));font-size:var(--wpds-typography-font-size-xs,11px);font-weight:var(--wpds-typography-font-weight-emphasis,600);line-height:1.4;margin-inline-start:12px;text-transform:uppercase}._69b138dfa5570d9c__default-controls-item{color:#1e1e1e}._69b138dfa5570d9c__default-controls-item._69b138dfa5570d9c__default-controls-item[aria-disabled=true]{color:#757575;opacity:1}._69b138dfa5570d9c__default-controls-item._69b138dfa5570d9c__default-controls-item[aria-disabled=true]:hover{color:#757575}._69b138dfa5570d9c__default-controls-item._69b138dfa5570d9c__default-controls-item[aria-disabled=true] .f135b96aa96ca6bb__reset-label{opacity:.3}\");\n}\nexport default {\"tools-panel\":\"_62d714739f4dc308__tools-panel\",\"tools-panel-with-inner-wrapper\":\"_40db7f4f897b683d__tools-panel-with-inner-wrapper\",\"tools-panel-hidden-inner-wrapper\":\"_95a15674966f30a3__tools-panel-hidden-inner-wrapper\",\"tools-panel-header\":\"_322a049b9b7d8674__tools-panel-header\",\"tools-panel-heading\":\"b92a382d3b30104d__tools-panel-heading\",\"tools-panel-item\":\"_8005d68fffa9db91__tools-panel-item\",\"tools-panel-item-placeholder\":\"_4f55e1a6e373746e__tools-panel-item-placeholder\",\"dropdown-menu\":\"d40032517bff9e12__dropdown-menu\",\"reset-label\":\"f135b96aa96ca6bb__reset-label\",\"default-controls-item\":\"_69b138dfa5570d9c__default-controls-item\"};\n"],
|
|
5
|
-
"mappings": ";AAAA,OAAO,UAAU;AACjB,SAAS,aAAa,WAAW,SAAS,YAAY,
|
|
4
|
+
"sourcesContent": ["import clsx from 'clsx';\nimport { useCallback, useEffect, useMemo, useReducer, useState } from '@wordpress/element';\nimport styles from '../style.module.scss';\nimport { useContextSystem } from '../../context';\nfunction emptyState() {\n return {\n panelItems: [],\n menuItemOrder: [],\n menuItemValues: {}\n };\n}\n\n// An item is always shown while it has a value. `defaultShown` only opts an\n// optional item in when it has none.\nconst getSeedValue = item => item.hasValue() || !item.isShownByDefault && !!item.defaultShown;\nconst getMenuGroup = item => item.isShownByDefault ? 'default' : 'optional';\nfunction panelItemsReducer(panelItems, action) {\n switch (action.type) {\n case 'REGISTER_PANEL':\n {\n // An existing registration is replaced rather than appended, so\n // that an item moving between the default and optional groups\n // doesn't end up in the list twice.\n const existingIndex = panelItems.findIndex(item => item.label === action.item.label);\n const newItems = [...panelItems];\n if (existingIndex !== -1) {\n newItems.splice(existingIndex, 1);\n }\n newItems.push(action.item);\n return newItems;\n }\n case 'UNREGISTER_PANEL':\n {\n const index = panelItems.findIndex(item => item.label === action.label);\n if (index === -1) {\n return panelItems;\n }\n // A replacement may already hold this label, in which case this is\n // a late cleanup for a registration that is no longer current.\n if (action.item && panelItems[index] !== action.item) {\n return panelItems;\n }\n const newItems = [...panelItems];\n newItems.splice(index, 1);\n return newItems;\n }\n default:\n return panelItems;\n }\n}\nfunction menuItemOrderReducer(menuItemOrder, action) {\n switch (action.type) {\n case 'REGISTER_PANEL':\n {\n // Append-only: an item that unregisters and comes back keeps its\n // original place in the menu.\n if (menuItemOrder.includes(action.item.label)) {\n return menuItemOrder;\n }\n return [...menuItemOrder, action.item.label];\n }\n default:\n return menuItemOrder;\n }\n}\nfunction menuItemValuesReducer(state, action) {\n const values = state.menuItemValues;\n switch (action.type) {\n case 'REGISTER_PANEL':\n {\n // A new registration starts from its own value rather than\n // inheriting what an item it replaces recorded under the same\n // label. Clearing here rather than on deregistration covers both\n // orderings, since the two are not guaranteed to arrive in one.\n // Relies on re-registering also re-reporting the value.\n if (!values.hasOwnProperty(action.item.label)) {\n return values;\n }\n const {\n [action.item.label]: unusedValue,\n ...rest\n } = values;\n return rest;\n }\n case 'UPDATE_VALUE':\n {\n if (values[action.label] === action.value) {\n return values;\n }\n return {\n ...values,\n [action.label]: action.value\n };\n }\n case 'TOGGLE_VALUE':\n {\n const item = state.panelItems.find(({\n label\n }) => label === action.label);\n if (!item) {\n return values;\n }\n const current = values[action.label] ?? getSeedValue(item);\n return {\n ...values,\n [action.label]: !current\n };\n }\n case 'RESET_ALL':\n {\n // Optional items are set to false so they hide right away.\n // Default items are left alone: a reset can leave a value in\n // place, since `onDeselect` and `resetAllFilter` are optional and\n // `resetAll` need not cover every attribute. Each item reports its\n // value again if the reset changed it.\n const hidden = state.panelItems.filter(item => !item.isShownByDefault && values[item.label] !== false);\n if (!hidden.length) {\n return values;\n }\n const next = {\n ...values\n };\n hidden.forEach(({\n label\n }) => {\n next[label] = false;\n });\n return next;\n }\n default:\n return values;\n }\n}\nfunction panelReducer(state, action) {\n const panelItems = panelItemsReducer(state.panelItems, action);\n const menuItemOrder = menuItemOrderReducer(state.menuItemOrder, action);\n const menuItemValues = menuItemValuesReducer({\n ...state,\n panelItems\n }, action);\n\n // Items dispatch far more often than they change anything. Holding onto\n // the existing state lets React skip the render.\n if (panelItems === state.panelItems && menuItemOrder === state.menuItemOrder && menuItemValues === state.menuItemValues) {\n return state;\n }\n return {\n panelItems,\n menuItemOrder,\n menuItemValues\n };\n}\nfunction resetAllFiltersReducer(filters, action) {\n switch (action.type) {\n case 'REGISTER':\n return [...filters, action.filter];\n case 'UNREGISTER':\n return filters.filter(f => f !== action.filter);\n default:\n return filters;\n }\n}\nconst isMenuItemTypeEmpty = obj => Object.keys(obj).length === 0;\nexport function useToolsPanel(props) {\n const {\n className,\n headingLevel = 2,\n resetAll,\n panelId,\n hasInnerWrapper = false,\n shouldRenderPlaceholderItems = false,\n __experimentalFirstVisibleItemClass,\n __experimentalLastVisibleItemClass,\n ...otherProps\n } = useContextSystem(props, 'ToolsPanel');\n\n // Marks the render that follows a reset so items can tell a reset apart\n // from the user switching them off. Clearing it from an effect rather than\n // as each control updates keeps the whole reset within one pass; otherwise\n // later controls see it already cleared and reset themselves again from\n // stale data.\n const [isResetting, setIsResetting] = useState(false);\n useEffect(() => {\n if (isResetting) {\n setIsResetting(false);\n }\n }, [isResetting]);\n const [{\n panelItems,\n menuItemOrder,\n menuItemValues\n }, panelDispatch] = useReducer(panelReducer, undefined, emptyState);\n\n // Reset all filters registered against the context directly, by consumers\n // that aren't themselves a panel item. Items supply theirs when they\n // register.\n const [externalResetAllFilters, dispatchResetAllFilters] = useReducer(resetAllFiltersReducer, []);\n const registerPanelItem = useCallback(item => {\n panelDispatch({\n type: 'REGISTER_PANEL',\n item\n });\n }, []);\n const deregisterPanelItem = useCallback((label, item) => {\n panelDispatch({\n type: 'UNREGISTER_PANEL',\n label,\n item\n });\n }, []);\n const registerResetAllFilter = useCallback(filter => {\n dispatchResetAllFilters({\n type: 'REGISTER',\n filter\n });\n }, []);\n const deregisterResetAllFilter = useCallback(filter => {\n dispatchResetAllFilters({\n type: 'UNREGISTER',\n filter\n });\n }, []);\n\n // Argument order is unchanged from before this hook derived the menu; only\n // the group argument is gone, since it follows from `isShownByDefault`.\n const flagItemCustomization = useCallback((value, label) => {\n panelDispatch({\n type: 'UPDATE_VALUE',\n label,\n value\n });\n }, []);\n\n // Derived during render so the panel can never paint a half-built menu.\n // See: https://github.com/WordPress/gutenberg/pull/65564\n const menuItems = useMemo(() => {\n const result = {\n default: {},\n optional: {}\n };\n const byLabel = new Map(panelItems.map(item => [item.label, item]));\n\n // `menuItemOrder` holds every registered label, so it alone drives\n // the menu.\n menuItemOrder.forEach(label => {\n const item = byLabel.get(label);\n if (!item) {\n return;\n }\n result[getMenuGroup(item)][label] = menuItemValues[label] ?? getSeedValue(item);\n });\n return result;\n }, [panelItems, menuItemOrder, menuItemValues]);\n\n // Drives the plus icon and the empty panel styling.\n const areAllOptionalControlsHidden = useMemo(() => {\n return isMenuItemTypeEmpty(menuItems.default) && !isMenuItemTypeEmpty(menuItems.optional) && Object.values(menuItems.optional).every(isSelected => !isSelected);\n }, [menuItems]);\n const classes = clsx(styles['tools-panel'], hasInnerWrapper && styles['tools-panel-with-inner-wrapper'], areAllOptionalControlsHidden && styles['tools-panel-hidden-inner-wrapper'], className);\n\n // `onShownChange` is invoked from here rather than in response to the\n // resulting state change, so that it only ever reports an explicit menu\n // action by the user.\n const toggleItem = useCallback(label => {\n const currentItem = panelItems.find(item => item.label === label);\n if (!currentItem) {\n return;\n }\n panelDispatch({\n type: 'TOGGLE_VALUE',\n label\n });\n\n // Default items stay visible when toggled off, which resets them\n // instead of hiding them. Only optional items have a show or hide\n // transition to report.\n if (currentItem.isShownByDefault) {\n return;\n }\n currentItem.onShownChange?.(!menuItems.optional[label]);\n }, [menuItems, panelItems]);\n const resetAllFilters = useMemo(() => {\n const itemFilters = panelItems.map(item => item.resetAllFilter).filter(filter => !!filter);\n return [...itemFilters, ...externalResetAllFilters];\n }, [panelItems, externalResetAllFilters]);\n const resetAllItems = useCallback(() => {\n if (typeof resetAll === 'function') {\n setIsResetting(true);\n resetAll(resetAllFilters);\n }\n panelDispatch({\n type: 'RESET_ALL'\n });\n }, [resetAllFilters, resetAll]);\n\n // Lets `ItemGroup` style the visible ends of the panel when hidden\n // placeholder items sit among the children.\n const getFirstVisibleItemLabel = items => {\n const optionalItems = menuItems.optional || {};\n const firstItem = items.find(item => item.isShownByDefault || optionalItems[item.label]);\n return firstItem?.label;\n };\n const firstDisplayedItem = getFirstVisibleItemLabel(panelItems);\n const lastDisplayedItem = getFirstVisibleItemLabel([...panelItems].reverse());\n const hasMenuItems = panelItems.length > 0;\n const panelContext = useMemo(() => ({\n areAllOptionalControlsHidden,\n deregisterPanelItem,\n deregisterResetAllFilter,\n firstDisplayedItem,\n flagItemCustomization,\n hasMenuItems,\n isResetting,\n lastDisplayedItem,\n menuItems,\n panelId,\n registerPanelItem,\n registerResetAllFilter,\n shouldRenderPlaceholderItems,\n __experimentalFirstVisibleItemClass,\n __experimentalLastVisibleItemClass\n }), [areAllOptionalControlsHidden, deregisterPanelItem, deregisterResetAllFilter, firstDisplayedItem, flagItemCustomization, isResetting, lastDisplayedItem, menuItems, panelId, hasMenuItems, registerResetAllFilter, registerPanelItem, shouldRenderPlaceholderItems, __experimentalFirstVisibleItemClass, __experimentalLastVisibleItemClass]);\n return {\n ...otherProps,\n headingLevel,\n panelContext,\n resetAllItems,\n toggleItem,\n className: classes\n };\n}", "const STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n const globalScope = globalThis;\n if (globalScope.__wpStyleRuntime) {\n return globalScope.__wpStyleRuntime;\n }\n globalScope.__wpStyleRuntime = {\n documents: new Map(),\n styles: new Map(),\n injectedStyles: new WeakMap()\n };\n if (typeof document !== 'undefined') {\n registerDocument(document);\n }\n return globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(targetDocument, hash) {\n if (!targetDocument.head) {\n return false;\n }\n for (const style of targetDocument.head.querySelectorAll(`style[${STYLE_HASH_ATTRIBUTE}]`)) {\n if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle(targetDocument, hash, css) {\n if (!targetDocument.head) {\n return;\n }\n const runtime = getRuntime();\n let injectedStyles = runtime.injectedStyles.get(targetDocument);\n if (!injectedStyles) {\n injectedStyles = new Set();\n runtime.injectedStyles.set(targetDocument, injectedStyles);\n }\n if (injectedStyles.has(hash)) {\n return;\n }\n\n // Older generated CSS module output can still inject matching style tags\n // after this document's cache is created, so keep the DOM as the fallback\n // source of truth on cache misses.\n if (documentContainsStyleHash(targetDocument, hash)) {\n injectedStyles.add(hash);\n return;\n }\n const style = targetDocument.createElement('style');\n style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);\n style.appendChild(targetDocument.createTextNode(css));\n targetDocument.head.appendChild(style);\n injectedStyles.add(hash);\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument(targetDocument) {\n const runtime = getRuntime();\n runtime.documents.set(targetDocument, (runtime.documents.get(targetDocument) ?? 0) + 1);\n for (const [hash, css] of runtime.styles) {\n injectStyle(targetDocument, hash, css);\n }\n return () => {\n const count = runtime.documents.get(targetDocument);\n if (count === undefined) {\n return;\n }\n if (count <= 1) {\n runtime.documents.delete(targetDocument);\n return;\n }\n runtime.documents.set(targetDocument, count - 1);\n };\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle(hash, css) {\n const runtime = getRuntime();\n runtime.styles.set(hash, css);\n for (const targetDocument of runtime.documents.keys()) {\n injectStyle(targetDocument, hash, css);\n }\n}", "import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"29b739f451\", \"._62d714739f4dc308__tools-panel{border-top:1px solid #ddd;margin-top:-1px;padding:16px}._40db7f4f897b683d__tools-panel-with-inner-wrapper>div:not(:first-of-type){column-gap:16px;display:grid;grid-column:1/-1;grid-template-columns:repeat(2,minmax(0,1fr));row-gap:16px}._95a15674966f30a3__tools-panel-hidden-inner-wrapper>div:not(:first-of-type){display:none}._322a049b9b7d8674__tools-panel-header{gap:8px;grid-column:1/-1}._322a049b9b7d8674__tools-panel-header .components-dropdown-menu{line-height:0;margin:-4px 0}._322a049b9b7d8674__tools-panel-header._322a049b9b7d8674__tools-panel-header._322a049b9b7d8674__tools-panel-header._322a049b9b7d8674__tools-panel-header .components-dropdown-menu__toggle{min-width:24px;padding:0}.b92a382d3b30104d__tools-panel-heading.b92a382d3b30104d__tools-panel-heading{font-size:inherit;line-height:normal;margin:0}._8005d68fffa9db91__tools-panel-item{grid-column:1/-1}._8005d68fffa9db91__tools-panel-item>div,._8005d68fffa9db91__tools-panel-item>fieldset{margin-bottom:0;max-width:100%;padding-bottom:0}._8005d68fffa9db91__tools-panel-item .components-base-control__help,._8005d68fffa9db91__tools-panel-item._8005d68fffa9db91__tools-panel-item .components-base-control,._8005d68fffa9db91__tools-panel-item._8005d68fffa9db91__tools-panel-item .components-base-control .components-base-control__field:last-child{margin-bottom:0}._4f55e1a6e373746e__tools-panel-item-placeholder{display:none}.d40032517bff9e12__dropdown-menu{min-width:200px}.f135b96aa96ca6bb__reset-label{color:var(--wp-components-color-accent-darker-10,var(--wp-admin-theme-color-darker-10,#2145e6));font-size:var(--wpds-typography-font-size-xs,11px);font-weight:var(--wpds-typography-font-weight-emphasis,600);line-height:1.4;margin-inline-start:12px;text-transform:uppercase}._69b138dfa5570d9c__default-controls-item{color:#1e1e1e}._69b138dfa5570d9c__default-controls-item._69b138dfa5570d9c__default-controls-item[aria-disabled=true]{color:#757575;opacity:1}._69b138dfa5570d9c__default-controls-item._69b138dfa5570d9c__default-controls-item[aria-disabled=true]:hover{color:#757575}._69b138dfa5570d9c__default-controls-item._69b138dfa5570d9c__default-controls-item[aria-disabled=true] .f135b96aa96ca6bb__reset-label{opacity:.3}\");\n}\nexport default {\"tools-panel\":\"_62d714739f4dc308__tools-panel\",\"tools-panel-with-inner-wrapper\":\"_40db7f4f897b683d__tools-panel-with-inner-wrapper\",\"tools-panel-hidden-inner-wrapper\":\"_95a15674966f30a3__tools-panel-hidden-inner-wrapper\",\"tools-panel-header\":\"_322a049b9b7d8674__tools-panel-header\",\"tools-panel-heading\":\"b92a382d3b30104d__tools-panel-heading\",\"tools-panel-item\":\"_8005d68fffa9db91__tools-panel-item\",\"tools-panel-item-placeholder\":\"_4f55e1a6e373746e__tools-panel-item-placeholder\",\"dropdown-menu\":\"d40032517bff9e12__dropdown-menu\",\"reset-label\":\"f135b96aa96ca6bb__reset-label\",\"default-controls-item\":\"_69b138dfa5570d9c__default-controls-item\"};\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,UAAU;AACjB,SAAS,aAAa,WAAW,SAAS,YAAY,gBAAgB;;;ACDtE,IAAM,uBAAuB;AAU7B,SAAS,aAAa;AACpB,QAAM,cAAc;AACpB,MAAI,YAAY,kBAAkB;AAChC,WAAO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,CAAC,YAAY,uBAAuB,CAAC;AACxC,QAAM,gBAAgB,YAAY,MAAM;AACtC,QAAI,OAAO,aAAa,YAAY;AAClC,qBAAe,IAAI;AACnB,eAAS,eAAe;AAAA,IAC1B;AACA,kBAAc;AAAA,MACZ,MAAM;AAAA,IACR,CAAC;AAAA,EACH,GAAG,CAAC,iBAAiB,QAAQ,CAAC;AAI9B,QAAM,2BAA2B,WAAS;AACxC,UAAM,gBAAgB,UAAU,YAAY,CAAC;AAC7C,UAAM,YAAY,MAAM,KAAK,UAAQ,KAAK,oBAAoB,cAAc,KAAK,KAAK,CAAC;AACvF,WAAO,WAAW;AAAA,EACpB;AACA,QAAM,qBAAqB,yBAAyB,UAAU;AAC9D,QAAM,oBAAoB,yBAAyB,CAAC,GAAG,UAAU,EAAE,QAAQ,CAAC;AAC5E,QAAM,eAAe,WAAW,SAAS;AACzC,QAAM,eAAe,QAAQ,OAAO;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,CAAC,8BAA8B,qBAAqB,0BAA0B,oBAAoB,uBAAuB,aAAa,mBAAmB,WAAW,SAAS,cAAc,wBAAwB,mBAAmB,8BAA8B,qCAAqC,kCAAkC,CAAC;AAChV,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,EACb;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// packages/components/src/tools-panel/tools-panel-item/hook.ts
|
|
2
2
|
import clsx from "clsx";
|
|
3
|
-
import {
|
|
4
|
-
import { useCallback, useEffect, useLayoutEffect } from "@wordpress/element";
|
|
3
|
+
import { useEvent } from "@wordpress/compose";
|
|
4
|
+
import { useCallback, useEffect, useLayoutEffect, useRef } from "@wordpress/element";
|
|
5
5
|
|
|
6
6
|
// packages/style-runtime/src/index.ts
|
|
7
7
|
var STYLE_HASH_ATTRIBUTE = "data-wp-hash";
|
|
@@ -94,6 +94,7 @@ var noop = () => {
|
|
|
94
94
|
function useToolsPanelItem(props) {
|
|
95
95
|
const {
|
|
96
96
|
className,
|
|
97
|
+
defaultShown,
|
|
97
98
|
hasValue,
|
|
98
99
|
isShownByDefault = false,
|
|
99
100
|
label,
|
|
@@ -101,13 +102,12 @@ function useToolsPanelItem(props) {
|
|
|
101
102
|
resetAllFilter = noop,
|
|
102
103
|
onDeselect,
|
|
103
104
|
onSelect,
|
|
105
|
+
onShownChange,
|
|
104
106
|
...otherProps
|
|
105
107
|
} = useContextSystem(props, "ToolsPanelItem");
|
|
106
108
|
const {
|
|
107
109
|
panelId: currentPanelId,
|
|
108
110
|
menuItems,
|
|
109
|
-
registerResetAllFilter,
|
|
110
|
-
deregisterResetAllFilter,
|
|
111
111
|
registerPanelItem,
|
|
112
112
|
deregisterPanelItem,
|
|
113
113
|
flagItemCustomization,
|
|
@@ -119,47 +119,47 @@ function useToolsPanelItem(props) {
|
|
|
119
119
|
__experimentalLastVisibleItemClass
|
|
120
120
|
} = useToolsPanelContext();
|
|
121
121
|
const hasValueCallback = useCallback(hasValue, [panelId]);
|
|
122
|
-
const resetAllFilterCallback =
|
|
123
|
-
const
|
|
122
|
+
const resetAllFilterCallback = useEvent(resetAllFilter);
|
|
123
|
+
const defaultShownRef = useRef(defaultShown);
|
|
124
|
+
useLayoutEffect(() => {
|
|
125
|
+
defaultShownRef.current = defaultShown;
|
|
126
|
+
});
|
|
127
|
+
const onShownChangeCallback = useEvent(onShownChange);
|
|
124
128
|
const hasMatchingPanel = currentPanelId === panelId || currentPanelId === null;
|
|
125
129
|
useLayoutEffect(() => {
|
|
126
|
-
if (hasMatchingPanel
|
|
127
|
-
|
|
128
|
-
hasValue: hasValueCallback,
|
|
129
|
-
isShownByDefault,
|
|
130
|
-
label,
|
|
131
|
-
panelId
|
|
132
|
-
});
|
|
130
|
+
if (!hasMatchingPanel) {
|
|
131
|
+
return;
|
|
133
132
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
133
|
+
const item = {
|
|
134
|
+
defaultShown: defaultShownRef.current,
|
|
135
|
+
hasValue: hasValueCallback,
|
|
136
|
+
isShownByDefault,
|
|
137
|
+
label,
|
|
138
|
+
onShownChange: onShownChangeCallback,
|
|
139
|
+
panelId,
|
|
140
|
+
resetAllFilter: resetAllFilterCallback
|
|
138
141
|
};
|
|
139
|
-
|
|
140
|
-
useEffect(() => {
|
|
141
|
-
if (hasMatchingPanel) {
|
|
142
|
-
registerResetAllFilter(resetAllFilterCallback);
|
|
143
|
-
}
|
|
142
|
+
registerPanelItem(item);
|
|
144
143
|
return () => {
|
|
145
|
-
|
|
146
|
-
deregisterResetAllFilter(resetAllFilterCallback);
|
|
147
|
-
}
|
|
144
|
+
deregisterPanelItem(label, item);
|
|
148
145
|
};
|
|
149
|
-
}, [
|
|
146
|
+
}, [deregisterPanelItem, hasMatchingPanel, hasValueCallback, isShownByDefault, label, onShownChangeCallback, panelId, registerPanelItem, resetAllFilterCallback]);
|
|
150
147
|
const menuGroup = isShownByDefault ? "default" : "optional";
|
|
151
148
|
const isMenuItemChecked = menuItems?.[menuGroup]?.[label];
|
|
152
|
-
const
|
|
153
|
-
const
|
|
149
|
+
const isRegistered = isMenuItemChecked !== void 0;
|
|
150
|
+
const wasMenuItemCheckedRef = useRef(void 0);
|
|
154
151
|
const isValueSet = hasValue();
|
|
155
|
-
|
|
156
|
-
if (!isShownByDefault && !isValueSet) {
|
|
152
|
+
useLayoutEffect(() => {
|
|
153
|
+
if (!hasMatchingPanel || !isShownByDefault && !isValueSet) {
|
|
157
154
|
return;
|
|
158
155
|
}
|
|
159
|
-
flagItemCustomization(isValueSet, label
|
|
160
|
-
}, [
|
|
156
|
+
flagItemCustomization(isValueSet, label);
|
|
157
|
+
}, [hasMatchingPanel, isValueSet, label, flagItemCustomization, isShownByDefault]);
|
|
161
158
|
useEffect(() => {
|
|
162
|
-
|
|
159
|
+
const wasMenuItemChecked = wasMenuItemCheckedRef.current;
|
|
160
|
+
wasMenuItemCheckedRef.current = isMenuItemChecked;
|
|
161
|
+
const wasRegistered = wasMenuItemChecked !== void 0;
|
|
162
|
+
if (!isRegistered || !wasRegistered || isResetting || !hasMatchingPanel) {
|
|
163
163
|
return;
|
|
164
164
|
}
|
|
165
165
|
if (isMenuItemChecked && !isValueSet && !wasMenuItemChecked) {
|
|
@@ -168,8 +168,8 @@ function useToolsPanelItem(props) {
|
|
|
168
168
|
if (!isMenuItemChecked && isValueSet && wasMenuItemChecked) {
|
|
169
169
|
onDeselect?.();
|
|
170
170
|
}
|
|
171
|
-
}, [hasMatchingPanel, isMenuItemChecked, isRegistered, isResetting, isValueSet,
|
|
172
|
-
const isShown = isShownByDefault ?
|
|
171
|
+
}, [hasMatchingPanel, isMenuItemChecked, isRegistered, isResetting, isValueSet, onSelect, onDeselect]);
|
|
172
|
+
const isShown = isShownByDefault ? isRegistered : isMenuItemChecked;
|
|
173
173
|
const shouldApplyPlaceholderStyles = shouldRenderPlaceholder && !isShown;
|
|
174
174
|
const classes = clsx(style_module_default["tools-panel-item"], shouldApplyPlaceholderStyles && style_module_default["tools-panel-item-placeholder"], !shouldApplyPlaceholderStyles && className, firstDisplayedItem === label && __experimentalFirstVisibleItemClass, lastDisplayedItem === label && __experimentalLastVisibleItemClass);
|
|
175
175
|
return {
|