@wordpress/components 19.11.0 → 19.12.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 +36 -0
- package/README.md +1 -1
- package/build/alignment-matrix-control/index.js +5 -2
- package/build/alignment-matrix-control/index.js.map +1 -1
- package/build/autocomplete/autocompleter-ui.js +1 -1
- package/build/autocomplete/autocompleter-ui.js.map +1 -1
- package/build/autocomplete/autocompleter-ui.native.js +2 -2
- package/build/autocomplete/autocompleter-ui.native.js.map +1 -1
- package/build/autocomplete/index.js +12 -10
- package/build/autocomplete/index.js.map +1 -1
- package/build/border-box-control/border-box-control/hook.js +2 -2
- package/build/border-box-control/border-box-control/hook.js.map +1 -1
- package/build/border-box-control/border-box-control-split-controls/component.js +2 -0
- package/build/border-box-control/border-box-control-split-controls/component.js.map +1 -1
- package/build/border-box-control/border-box-control-split-controls/hook.js +13 -4
- package/build/border-box-control/border-box-control-split-controls/hook.js.map +1 -1
- package/build/border-box-control/border-box-control-visualizer/hook.js +6 -2
- package/build/border-box-control/border-box-control-visualizer/hook.js.map +1 -1
- package/build/border-box-control/styles.js +21 -11
- package/build/border-box-control/styles.js.map +1 -1
- package/build/border-control/border-control/hook.js +2 -2
- package/build/border-control/border-control/hook.js.map +1 -1
- package/build/color-palette/index.js +9 -2
- package/build/color-palette/index.js.map +1 -1
- package/build/color-palette/index.native.js +4 -1
- package/build/color-palette/index.native.js.map +1 -1
- package/build/color-picker/color-copy-button.js +87 -0
- package/build/color-picker/color-copy-button.js.map +1 -0
- package/build/color-picker/component.js +5 -15
- package/build/color-picker/component.js.map +1 -1
- package/build/color-picker/hex-input.js +18 -1
- package/build/color-picker/hex-input.js.map +1 -1
- package/build/color-picker/styles.js +11 -11
- package/build/color-picker/styles.js.map +1 -1
- package/build/custom-gradient-picker/utils.js +1 -1
- package/build/custom-gradient-picker/utils.js.map +1 -1
- package/build/date-time/{date.js → date/index.js} +51 -12
- package/build/date-time/date/index.js.map +1 -0
- package/build/date-time/date/styles.js +70 -0
- package/build/date-time/date/styles.js.map +1 -0
- package/build/date-time/{utils.js → date/utils.js} +0 -0
- package/build/date-time/date/utils.js.map +1 -0
- package/build/date-time/date-time/index.js +175 -0
- package/build/date-time/date-time/index.js.map +1 -0
- package/build/date-time/date-time/styles.js +32 -0
- package/build/date-time/date-time/styles.js.map +1 -0
- package/build/date-time/index.js +2 -109
- package/build/date-time/index.js.map +1 -1
- package/build/date-time/time/index.js +322 -0
- package/build/date-time/time/index.js.map +1 -0
- package/build/date-time/time/styles.js +139 -0
- package/build/date-time/time/styles.js.map +1 -0
- package/build/date-time/{timezone.js → time/timezone.js} +4 -2
- package/build/date-time/time/timezone.js.map +1 -0
- package/build/draggable/index.native.js +10 -5
- package/build/draggable/index.native.js.map +1 -1
- package/build/dropdown/index.js +4 -1
- package/build/dropdown/index.js.map +1 -1
- package/build/input-control/index.js +9 -4
- package/build/input-control/index.js.map +1 -1
- package/build/input-control/input-field.js +1 -26
- package/build/input-control/input-field.js.map +1 -1
- package/build/input-control/reducer/reducer.js +36 -24
- package/build/input-control/reducer/reducer.js.map +1 -1
- package/build/input-control/reducer/state.js +0 -1
- package/build/input-control/reducer/state.js.map +1 -1
- package/build/input-control/utils.js +45 -0
- package/build/input-control/utils.js.map +1 -1
- package/build/popover/index.js +40 -33
- package/build/popover/index.js.map +1 -1
- package/build/search-control/index.js +4 -6
- package/build/search-control/index.js.map +1 -1
- package/build/select-control/index.js +3 -1
- package/build/select-control/index.js.map +1 -1
- package/build/spacer/hook.js +11 -3
- package/build/spacer/hook.js.map +1 -1
- package/build/surface/component.js +7 -7
- package/build/surface/component.js.map +1 -1
- package/build/surface/hook.js +8 -11
- package/build/surface/hook.js.map +1 -1
- package/build/surface/index.js.map +1 -1
- package/build/surface/styles.js +8 -48
- package/build/surface/styles.js.map +1 -1
- package/build/textarea-control/index.js +40 -6
- package/build/textarea-control/index.js.map +1 -1
- package/build/textarea-control/styles/textarea-control-styles.js +3 -3
- package/build/textarea-control/styles/textarea-control-styles.js.map +1 -1
- package/build/textarea-control/types.js +6 -0
- package/build/textarea-control/types.js.map +1 -0
- package/build/utils/hooks/index.js +0 -8
- package/build/utils/hooks/index.js.map +1 -1
- package/build-module/alignment-matrix-control/index.js +5 -2
- package/build-module/alignment-matrix-control/index.js.map +1 -1
- package/build-module/autocomplete/autocompleter-ui.js +1 -1
- package/build-module/autocomplete/autocompleter-ui.js.map +1 -1
- package/build-module/autocomplete/autocompleter-ui.native.js +2 -2
- package/build-module/autocomplete/autocompleter-ui.native.js.map +1 -1
- package/build-module/autocomplete/index.js +13 -11
- package/build-module/autocomplete/index.js.map +1 -1
- package/build-module/border-box-control/border-box-control/hook.js +2 -2
- package/build-module/border-box-control/border-box-control/hook.js.map +1 -1
- package/build-module/border-box-control/border-box-control-split-controls/component.js +2 -0
- package/build-module/border-box-control/border-box-control-split-controls/component.js.map +1 -1
- package/build-module/border-box-control/border-box-control-split-controls/hook.js +11 -4
- package/build-module/border-box-control/border-box-control-split-controls/hook.js.map +1 -1
- package/build-module/border-box-control/border-box-control-visualizer/hook.js +4 -2
- package/build-module/border-box-control/border-box-control-visualizer/hook.js.map +1 -1
- package/build-module/border-box-control/styles.js +13 -8
- package/build-module/border-box-control/styles.js.map +1 -1
- package/build-module/border-control/border-control/hook.js +2 -2
- package/build-module/border-control/border-control/hook.js.map +1 -1
- package/build-module/color-palette/index.js +7 -5
- package/build-module/color-palette/index.js.map +1 -1
- package/build-module/color-palette/index.native.js +4 -1
- package/build-module/color-palette/index.native.js.map +1 -1
- package/build-module/color-picker/color-copy-button.js +73 -0
- package/build-module/color-picker/color-copy-button.js.map +1 -0
- package/build-module/color-picker/component.js +6 -15
- package/build-module/color-picker/component.js.map +1 -1
- package/build-module/color-picker/hex-input.js +18 -1
- package/build-module/color-picker/hex-input.js.map +1 -1
- package/build-module/color-picker/styles.js +9 -9
- package/build-module/color-picker/styles.js.map +1 -1
- package/build-module/custom-gradient-picker/utils.js +1 -1
- package/build-module/custom-gradient-picker/utils.js.map +1 -1
- package/build-module/date-time/{date.js → date/index.js} +46 -14
- package/build-module/date-time/date/index.js.map +1 -0
- package/build-module/date-time/date/styles.js +61 -0
- package/build-module/date-time/date/styles.js.map +1 -0
- package/build-module/date-time/{utils.js → date/utils.js} +0 -0
- package/build-module/date-time/date/utils.js.map +1 -0
- package/build-module/date-time/date-time/index.js +144 -0
- package/build-module/date-time/date-time/index.js.map +1 -0
- package/build-module/date-time/date-time/styles.js +22 -0
- package/build-module/date-time/date-time/styles.js.map +1 -0
- package/build-module/date-time/index.js +1 -105
- package/build-module/date-time/index.js.map +1 -1
- package/build-module/date-time/time/index.js +302 -0
- package/build-module/date-time/time/index.js.map +1 -0
- package/build-module/date-time/time/styles.js +118 -0
- package/build-module/date-time/time/styles.js.map +1 -0
- package/build-module/date-time/{timezone.js → time/timezone.js} +3 -2
- package/build-module/date-time/time/timezone.js.map +1 -0
- package/build-module/draggable/index.native.js +10 -5
- package/build-module/draggable/index.native.js.map +1 -1
- package/build-module/dropdown/index.js +4 -1
- package/build-module/dropdown/index.js.map +1 -1
- package/build-module/input-control/index.js +8 -4
- package/build-module/input-control/index.js.map +1 -1
- package/build-module/input-control/input-field.js +1 -25
- package/build-module/input-control/input-field.js.map +1 -1
- package/build-module/input-control/reducer/reducer.js +38 -26
- package/build-module/input-control/reducer/reducer.js.map +1 -1
- package/build-module/input-control/reducer/state.js +0 -1
- package/build-module/input-control/reducer/state.js.map +1 -1
- package/build-module/input-control/utils.js +48 -2
- package/build-module/input-control/utils.js.map +1 -1
- package/build-module/popover/index.js +40 -33
- package/build-module/popover/index.js.map +1 -1
- package/build-module/search-control/index.js +6 -7
- package/build-module/search-control/index.js.map +1 -1
- package/build-module/select-control/index.js +3 -1
- package/build-module/select-control/index.js.map +1 -1
- package/build-module/spacer/hook.js +10 -2
- package/build-module/spacer/hook.js.map +1 -1
- package/build-module/surface/component.js +7 -7
- package/build-module/surface/component.js.map +1 -1
- package/build-module/surface/hook.js +8 -11
- package/build-module/surface/hook.js.map +1 -1
- package/build-module/surface/index.js.map +1 -1
- package/build-module/surface/styles.js +8 -48
- package/build-module/surface/styles.js.map +1 -1
- package/build-module/textarea-control/index.js +36 -5
- package/build-module/textarea-control/index.js.map +1 -1
- package/build-module/textarea-control/styles/textarea-control-styles.js +3 -3
- package/build-module/textarea-control/styles/textarea-control-styles.js.map +1 -1
- package/build-module/textarea-control/types.js +2 -0
- package/build-module/textarea-control/types.js.map +1 -0
- package/build-module/utils/hooks/index.js +0 -1
- package/build-module/utils/hooks/index.js.map +1 -1
- package/build-style/style-rtl.css +13 -188
- package/build-style/style.css +13 -191
- package/build-types/border-box-control/border-box-control-split-controls/component.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control-split-controls/hook.d.ts +1 -0
- package/build-types/border-box-control/border-box-control-split-controls/hook.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control-visualizer/hook.d.ts.map +1 -1
- package/build-types/border-box-control/styles.d.ts +3 -2
- package/build-types/border-box-control/styles.d.ts.map +1 -1
- package/build-types/border-control/border-control/hook.d.ts.map +1 -1
- package/build-types/card/types.d.ts +1 -1
- package/build-types/card/types.d.ts.map +1 -1
- package/build-types/checkbox-control/test/index.d.ts +2 -0
- package/build-types/checkbox-control/test/index.d.ts.map +1 -0
- package/build-types/color-palette/index.d.ts +1 -0
- package/build-types/color-palette/index.d.ts.map +1 -1
- package/build-types/{date-time → color-palette}/test/utils.d.ts +0 -0
- package/build-types/color-palette/test/utils.d.ts.map +1 -0
- package/build-types/color-picker/color-copy-button.d.ts +4 -0
- package/build-types/color-picker/color-copy-button.d.ts.map +1 -0
- package/build-types/color-picker/component.d.ts.map +1 -1
- package/build-types/color-picker/hex-input.d.ts.map +1 -1
- package/build-types/color-picker/styles.d.ts +1 -1
- package/build-types/color-picker/styles.d.ts.map +1 -1
- package/build-types/color-picker/types.d.ts +8 -0
- package/build-types/color-picker/types.d.ts.map +1 -1
- package/build-types/date-time/{date.d.ts → date/index.d.ts} +3 -2
- package/build-types/date-time/date/index.d.ts.map +1 -0
- package/build-types/date-time/date/styles.d.ts +23 -0
- package/build-types/date-time/date/styles.d.ts.map +1 -0
- package/build-types/date-time/date/test/index.d.ts +2 -0
- package/build-types/date-time/date/test/index.d.ts.map +1 -0
- package/build-types/date-time/date/test/utils.d.ts +2 -0
- package/build-types/date-time/date/test/utils.d.ts.map +1 -0
- package/build-types/date-time/{utils.d.ts → date/utils.d.ts} +0 -0
- package/build-types/date-time/date/utils.d.ts.map +1 -0
- package/build-types/date-time/date-time/index.d.ts +33 -0
- package/build-types/date-time/date-time/index.d.ts.map +1 -0
- package/build-types/date-time/date-time/styles.d.ts +6 -0
- package/build-types/date-time/date-time/styles.d.ts.map +1 -0
- package/build-types/date-time/index.d.ts +2 -28
- package/build-types/date-time/index.d.ts.map +1 -1
- package/build-types/date-time/stories/{index.d.ts → date-time.d.ts} +2 -2
- package/build-types/date-time/stories/date-time.d.ts.map +1 -0
- package/build-types/date-time/{time.d.ts → time/index.d.ts} +2 -2
- package/build-types/date-time/time/index.d.ts.map +1 -0
- package/build-types/date-time/time/styles.d.ts +111 -0
- package/build-types/date-time/time/styles.d.ts.map +1 -0
- package/build-types/date-time/time/test/index.d.ts +2 -0
- package/build-types/date-time/time/test/index.d.ts.map +1 -0
- package/build-types/date-time/{timezone.d.ts → time/timezone.d.ts} +0 -0
- package/build-types/date-time/time/timezone.d.ts.map +1 -0
- package/build-types/date-time/types.d.ts +14 -15
- package/build-types/date-time/types.d.ts.map +1 -1
- package/build-types/dropdown/index.d.ts.map +1 -1
- package/build-types/input-control/index.d.ts.map +1 -1
- package/build-types/input-control/input-field.d.ts.map +1 -1
- package/build-types/input-control/reducer/reducer.d.ts +5 -3
- package/build-types/input-control/reducer/reducer.d.ts.map +1 -1
- package/build-types/input-control/reducer/state.d.ts +2 -2
- package/build-types/input-control/reducer/state.d.ts.map +1 -1
- package/build-types/input-control/utils.d.ts +17 -0
- package/build-types/input-control/utils.d.ts.map +1 -1
- package/build-types/popover/index.d.ts +1 -0
- package/build-types/popover/index.d.ts.map +1 -1
- package/build-types/select-control/index.d.ts.map +1 -1
- package/build-types/select-control/types.d.ts +1 -1
- package/build-types/select-control/types.d.ts.map +1 -1
- package/build-types/surface/component.d.ts +3 -2
- package/build-types/surface/component.d.ts.map +1 -1
- package/build-types/surface/hook.d.ts +4 -4
- package/build-types/surface/hook.d.ts.map +1 -1
- package/build-types/surface/index.d.ts +2 -2
- package/build-types/surface/index.d.ts.map +1 -1
- package/build-types/surface/stories/index.d.ts +12 -0
- package/build-types/surface/stories/index.d.ts.map +1 -0
- package/build-types/surface/styles.d.ts +10 -21
- package/build-types/surface/styles.d.ts.map +1 -1
- package/build-types/surface/test/index.d.ts +2 -0
- package/build-types/surface/test/index.d.ts.map +1 -0
- package/build-types/surface/types.d.ts +1 -1
- package/build-types/surface/types.d.ts.map +1 -1
- package/build-types/textarea-control/index.d.ts +29 -0
- package/build-types/textarea-control/index.d.ts.map +1 -0
- package/build-types/textarea-control/stories/index.d.ts +12 -0
- package/build-types/textarea-control/stories/index.d.ts.map +1 -0
- package/build-types/textarea-control/styles/textarea-control-styles.d.ts +6 -0
- package/build-types/textarea-control/styles/textarea-control-styles.d.ts.map +1 -0
- package/build-types/textarea-control/types.d.ts +26 -0
- package/build-types/textarea-control/types.d.ts.map +1 -0
- package/build-types/utils/hooks/index.d.ts +0 -1
- package/package.json +18 -18
- package/src/alignment-matrix-control/index.js +4 -2
- package/src/autocomplete/autocompleter-ui.js +1 -1
- package/src/autocomplete/autocompleter-ui.native.js +2 -2
- package/src/autocomplete/index.js +21 -9
- package/src/border-box-control/border-box-control/hook.ts +2 -2
- package/src/border-box-control/border-box-control-split-controls/component.tsx +2 -0
- package/src/border-box-control/border-box-control-split-controls/hook.ts +18 -4
- package/src/border-box-control/border-box-control-visualizer/hook.ts +5 -2
- package/src/border-box-control/styles.ts +6 -2
- package/src/border-control/border-control/hook.ts +8 -2
- package/src/box-control/test/index.js +120 -109
- package/src/card/types.ts +1 -1
- package/src/checkbox-control/test/__snapshots__/index.tsx.snap +42 -0
- package/src/checkbox-control/test/index.tsx +109 -0
- package/src/color-palette/index.js +11 -4
- package/src/color-palette/index.native.js +3 -0
- package/src/color-palette/stories/index.js +25 -1
- package/src/color-palette/test/utils.ts +24 -0
- package/src/color-picker/color-copy-button.tsx +76 -0
- package/src/color-picker/component.tsx +18 -38
- package/src/color-picker/hex-input.tsx +16 -0
- package/src/color-picker/styles.ts +5 -1
- package/src/color-picker/types.ts +9 -0
- package/src/custom-gradient-picker/utils.js +1 -1
- package/src/date-time/README.md +16 -0
- package/src/date-time/{datepicker.scss → date/datepicker.scss} +0 -0
- package/src/date-time/{date.tsx → date/index.tsx} +38 -15
- package/src/date-time/date/style.scss +75 -0
- package/src/date-time/date/styles.ts +55 -0
- package/src/date-time/{test/date.tsx → date/test/index.tsx} +1 -1
- package/src/date-time/{test → date/test}/utils.ts +0 -0
- package/src/date-time/{utils.ts → date/utils.ts} +0 -0
- package/src/date-time/date-time/index.tsx +217 -0
- package/src/date-time/date-time/styles.ts +8 -0
- package/src/date-time/index.ts +9 -0
- package/src/date-time/stories/{index.tsx → date-time.tsx} +1 -1
- package/src/date-time/style.scss +1 -262
- package/src/date-time/time/index.tsx +356 -0
- package/src/date-time/time/styles.ts +119 -0
- package/src/date-time/{test/time.tsx → time/test/index.tsx} +85 -38
- package/src/date-time/{timezone.tsx → time/timezone.tsx} +5 -2
- package/src/date-time/types.ts +16 -18
- package/src/draggable/index.native.js +14 -3
- package/src/draggable/test/index.native.js +130 -0
- package/src/dropdown/index.js +5 -1
- package/src/input-control/index.tsx +8 -2
- package/src/input-control/input-field.tsx +10 -30
- package/src/input-control/reducer/reducer.ts +40 -26
- package/src/input-control/reducer/state.ts +2 -3
- package/src/input-control/utils.ts +55 -1
- package/src/popover/index.js +42 -27
- package/src/query-controls/README.md +1 -1
- package/src/search-control/index.js +6 -7
- package/src/select-control/README.md +11 -0
- package/src/select-control/index.tsx +6 -1
- package/src/select-control/types.ts +1 -1
- package/src/slot-fill/README.md +1 -1
- package/src/spacer/hook.ts +13 -13
- package/src/surface/README.md +15 -15
- package/src/surface/{component.js → component.tsx} +13 -7
- package/src/surface/{hook.js → hook.ts} +13 -12
- package/src/surface/{index.js → index.ts} +0 -0
- package/src/surface/stories/index.tsx +40 -0
- package/src/surface/{styles.js → styles.ts} +15 -44
- package/src/surface/test/__snapshots__/{index.js.snap → index.tsx.snap} +0 -0
- package/src/surface/test/{index.js → index.tsx} +2 -1
- package/src/surface/types.ts +1 -1
- package/src/textarea-control/README.md +14 -20
- package/src/textarea-control/index.tsx +86 -0
- package/src/textarea-control/stories/index.tsx +58 -0
- package/src/textarea-control/styles/{textarea-control-styles.js → textarea-control-styles.ts} +0 -0
- package/src/textarea-control/types.ts +30 -0
- package/src/utils/hooks/index.js +0 -1
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/color-picker/color-display.js +0 -184
- package/build/color-picker/color-display.js.map +0 -1
- package/build/date-time/date.js.map +0 -1
- package/build/date-time/time.js +0 -289
- package/build/date-time/time.js.map +0 -1
- package/build/date-time/timezone.js.map +0 -1
- package/build/date-time/utils.js.map +0 -1
- package/build/utils/hooks/use-combined-ref.js +0 -32
- package/build/utils/hooks/use-combined-ref.js.map +0 -1
- package/build-module/color-picker/color-display.js +0 -170
- package/build-module/color-picker/color-display.js.map +0 -1
- package/build-module/date-time/date.js.map +0 -1
- package/build-module/date-time/time.js +0 -271
- package/build-module/date-time/time.js.map +0 -1
- package/build-module/date-time/timezone.js.map +0 -1
- package/build-module/date-time/utils.js.map +0 -1
- package/build-module/utils/hooks/use-combined-ref.js +0 -28
- package/build-module/utils/hooks/use-combined-ref.js.map +0 -1
- package/build-types/color-picker/color-display.d.ts +0 -14
- package/build-types/color-picker/color-display.d.ts.map +0 -1
- package/build-types/date-time/date.d.ts.map +0 -1
- package/build-types/date-time/stories/index.d.ts.map +0 -1
- package/build-types/date-time/test/date.d.ts +0 -2
- package/build-types/date-time/test/date.d.ts.map +0 -1
- package/build-types/date-time/test/time.d.ts +0 -2
- package/build-types/date-time/test/time.d.ts.map +0 -1
- package/build-types/date-time/test/utils.d.ts.map +0 -1
- package/build-types/date-time/time.d.ts.map +0 -1
- package/build-types/date-time/timezone.d.ts.map +0 -1
- package/build-types/date-time/utils.d.ts.map +0 -1
- package/build-types/utils/hooks/use-combined-ref.d.ts +0 -8
- package/build-types/utils/hooks/use-combined-ref.d.ts.map +0 -1
- package/src/color-picker/color-display.tsx +0 -169
- package/src/date-time/index.tsx +0 -196
- package/src/date-time/time.tsx +0 -321
- package/src/surface/stories/index.js +0 -46
- package/src/textarea-control/index.js +0 -45
- package/src/textarea-control/stories/index.js +0 -48
- package/src/utils/hooks/use-combined-ref.ts +0 -28
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/input-control/input-field.tsx"],"names":["noop","useDrag","forwardRef","useRef","useDragCursor","Input","useInputControlStateReducer","useUpdateEffect","InputField","ref","disabled","dragDirection","dragThreshold","id","isDragEnabled","isFocused","isPressEnterToChange","onBlur","onChange","onDrag","onDragEnd","onDragStart","onFocus","onKeyDown","onValidate","size","setIsFocused","stateReducer","state","value","valueProp","type","props","change","commit","drag","dragEnd","dragStart","invalidate","pressDown","pressEnter","pressUp","reset","_event","isDragging","isDirty","wasDirtyOnBlur","dragCursor","current","event","handleOnBlur","target","validity","valid","handleOnCommit","handleOnFocus","handleOnChange","nextValue","currentTarget","err","handleOnKeyDown","key","preventDefault","dragGestureProps","dragProps","distance","dragging","stopPropagation","axis","threshold","enabled","pointer","capture","handleOnMouseDown","onMouseDown","ownerDocument","activeElement","focus","ForwardedComponent"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,IAAT,QAAqB,QAArB;AACA,SAASC,OAAT,QAAwB,oBAAxB;;AAWA;AACA;AACA;AACA,SAASC,UAAT,EAAqBC,MAArB,QAAmC,oBAAnC;AACA;A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AN,+EAAA1C,KAAK,EAAgBiB,KAAhB,CAAL;;AACA,UACCA,KAAK,CAACS,aAAN,KACAT,KAAK,CAACS,aAAN,CAAoBiB,aAApB,CAAkCC,aAFnC,EAGE;AACD3B,QAAAA,KAAK,CAACS,aAAN,CAAoBmB,KAApB;AACA;AACD,KARD;AASA;;AAED,SACC,cAAC,KAAD,eACM7C,KADN,EAEMgC,SAFN;AAGC,IAAA,SAAS,EAAC,iCAHX;AAIC,IAAA,QAAQ,EAAGtD,QAJZ;AAKC,IAAA,UAAU,EAAGqC,UALd;AAMC,IAAA,UAAU,EAAGH,UANd;AAOC,IAAA,EAAE,EAAG/B,EAPN;AAQC,IAAA,MAAM,EAAGqC,YARV;AASC,IAAA,QAAQ,EAAGM,cATZ;AAUC,IAAA,OAAO,EAAGD,aAVX;AAWC,IAAA,SAAS,EAAGK,eAXb;AAYC,IAAA,WAAW,EAAGa,iBAZf;AAaC,IAAA,GAAG,EAAGhE,GAbP;AAcC,IAAA,SAAS,EAAGgB,IAdb;AAeC,IAAA,KAAK,EAAGI,KAfT;AAgBC,IAAA,IAAI,EAAGE;AAhBR,KADD;AAoBA;;AAED,MAAM+C,kBAAkB,GAAG5E,UAAU,CAAEM,UAAF,CAArC;AAEA,eAAesE,kBAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { noop } from 'lodash';\nimport { useDrag } from '@use-gesture/react';\nimport type {\n\tSyntheticEvent,\n\tChangeEvent,\n\tKeyboardEvent,\n\tPointerEvent,\n\tFocusEvent,\n\tForwardedRef,\n\tMouseEvent,\n} from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { forwardRef, useRef } from '@wordpress/element';\n/**\n * Internal dependencies\n */\nimport type { WordPressComponentProps } from '../ui/context';\nimport { useDragCursor } from './utils';\nimport { Input } from './styles/input-control-styles';\nimport { useInputControlStateReducer } from './reducer/reducer';\nimport { useUpdateEffect } from '../utils';\nimport type { InputFieldProps } from './types';\n\nfunction InputField(\n\t{\n\t\tdisabled = false,\n\t\tdragDirection = 'n',\n\t\tdragThreshold = 10,\n\t\tid,\n\t\tisDragEnabled = false,\n\t\tisFocused,\n\t\tisPressEnterToChange = false,\n\t\tonBlur = noop,\n\t\tonChange = noop,\n\t\tonDrag = noop,\n\t\tonDragEnd = noop,\n\t\tonDragStart = noop,\n\t\tonFocus = noop,\n\t\tonKeyDown = noop,\n\t\tonValidate = noop,\n\t\tsize = 'default',\n\t\tsetIsFocused,\n\t\tstateReducer = ( state: any ) => state,\n\t\tvalue: valueProp,\n\t\ttype,\n\t\t...props\n\t}: WordPressComponentProps< InputFieldProps, 'input', false >,\n\tref: ForwardedRef< HTMLInputElement >\n) {\n\tconst {\n\t\t// State.\n\t\tstate,\n\t\t// Actions.\n\t\tchange,\n\t\tcommit,\n\t\tdrag,\n\t\tdragEnd,\n\t\tdragStart,\n\t\tinvalidate,\n\t\tpressDown,\n\t\tpressEnter,\n\t\tpressUp,\n\t\treset,\n\t} = useInputControlStateReducer( stateReducer, {\n\t\tisDragEnabled,\n\t\tvalue: valueProp,\n\t\tisPressEnterToChange,\n\t} );\n\n\tconst { _event, value, isDragging, isDirty } = state;\n\tconst wasDirtyOnBlur = useRef( false );\n\n\tconst dragCursor = useDragCursor( isDragging, dragDirection );\n\n\t/*\n\t * Handles synchronization of external and internal value state.\n\t * If not focused and did not hold a dirty value[1] on blur\n\t * updates the value from the props. Otherwise if not holding\n\t * a dirty value[1] propagates the value and event through onChange.\n\t * [1] value is only made dirty if isPressEnterToChange is true\n\t */\n\tuseUpdateEffect( () => {\n\t\tif ( valueProp === value ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( ! isFocused && ! wasDirtyOnBlur.current ) {\n\t\t\tcommit( valueProp, _event as SyntheticEvent );\n\t\t} else if ( ! isDirty ) {\n\t\t\tonChange( value, {\n\t\t\t\tevent: _event as\n\t\t\t\t\t| ChangeEvent< HTMLInputElement >\n\t\t\t\t\t| PointerEvent< HTMLInputElement >,\n\t\t\t} );\n\t\t\twasDirtyOnBlur.current = false;\n\t\t}\n\t}, [ value, isDirty, isFocused, valueProp ] );\n\n\tconst handleOnBlur = ( event: FocusEvent< HTMLInputElement > ) => {\n\t\tonBlur( event );\n\t\tsetIsFocused?.( false );\n\n\t\t/**\n\t\t * If isPressEnterToChange is set, this commits the value to\n\t\t * the onChange callback.\n\t\t */\n\t\tif ( isDirty || ! event.target.validity.valid ) {\n\t\t\twasDirtyOnBlur.current = true;\n\t\t\thandleOnCommit( event );\n\t\t}\n\t};\n\n\tconst handleOnFocus = ( event: FocusEvent< HTMLInputElement > ) => {\n\t\tonFocus( event );\n\t\tsetIsFocused?.( true );\n\t};\n\n\tconst handleOnChange = ( event: ChangeEvent< HTMLInputElement > ) => {\n\t\tconst nextValue = event.target.value;\n\t\tchange( nextValue, event );\n\t};\n\n\tconst handleOnCommit = ( event: SyntheticEvent< HTMLInputElement > ) => {\n\t\tconst nextValue = event.currentTarget.value;\n\n\t\ttry {\n\t\t\tonValidate( nextValue );\n\t\t\tcommit( nextValue, event );\n\t\t} catch ( err ) {\n\t\t\tinvalidate( err, event );\n\t\t}\n\t};\n\n\tconst handleOnKeyDown = ( event: KeyboardEvent< HTMLInputElement > ) => {\n\t\tconst { key } = event;\n\t\tonKeyDown( event );\n\n\t\tswitch ( key ) {\n\t\t\tcase 'ArrowUp':\n\t\t\t\tpressUp( event );\n\t\t\t\tbreak;\n\n\t\t\tcase 'ArrowDown':\n\t\t\t\tpressDown( event );\n\t\t\t\tbreak;\n\n\t\t\tcase 'Enter':\n\t\t\t\tpressEnter( event );\n\n\t\t\t\tif ( isPressEnterToChange ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\thandleOnCommit( event );\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase 'Escape':\n\t\t\t\tif ( isPressEnterToChange && isDirty ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\treset( valueProp, event );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\tconst dragGestureProps = useDrag< PointerEvent< HTMLInputElement > >(\n\t\t( dragProps ) => {\n\t\t\tconst { distance, dragging, event, target } = dragProps;\n\n\t\t\t// The `target` prop always references the `input` element while, by\n\t\t\t// default, the `dragProps.event.target` property would reference the real\n\t\t\t// event target (i.e. any DOM element that the pointer is hovering while\n\t\t\t// dragging). Ensuring that the `target` is always the `input` element\n\t\t\t// allows consumers of `InputControl` (or any higher-level control) to\n\t\t\t// check the input's validity by accessing `event.target.validity.valid`.\n\t\t\tdragProps.event = {\n\t\t\t\t...dragProps.event,\n\t\t\t\ttarget,\n\t\t\t};\n\n\t\t\tif ( ! distance ) return;\n\t\t\tevent.stopPropagation();\n\n\t\t\t/**\n\t\t\t * Quick return if no longer dragging.\n\t\t\t * This prevents unnecessary value calculations.\n\t\t\t */\n\t\t\tif ( ! dragging ) {\n\t\t\t\tonDragEnd( dragProps );\n\t\t\t\tdragEnd( dragProps );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tonDrag( dragProps );\n\t\t\tdrag( dragProps );\n\n\t\t\tif ( ! isDragging ) {\n\t\t\t\tonDragStart( dragProps );\n\t\t\t\tdragStart( dragProps );\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\taxis: dragDirection === 'e' || dragDirection === 'w' ? 'x' : 'y',\n\t\t\tthreshold: dragThreshold,\n\t\t\tenabled: isDragEnabled,\n\t\t\tpointer: { capture: false },\n\t\t}\n\t);\n\n\tconst dragProps = isDragEnabled ? dragGestureProps() : {};\n\t/*\n\t * Works around the odd UA (e.g. Firefox) that does not focus inputs of\n\t * type=number when their spinner arrows are pressed.\n\t */\n\tlet handleOnMouseDown;\n\tif ( type === 'number' ) {\n\t\thandleOnMouseDown = ( event: MouseEvent< HTMLInputElement > ) => {\n\t\t\tprops.onMouseDown?.( event );\n\t\t\tif (\n\t\t\t\tevent.currentTarget !==\n\t\t\t\tevent.currentTarget.ownerDocument.activeElement\n\t\t\t) {\n\t\t\t\tevent.currentTarget.focus();\n\t\t\t}\n\t\t};\n\t}\n\n\treturn (\n\t\t<Input\n\t\t\t{ ...props }\n\t\t\t{ ...dragProps }\n\t\t\tclassName=\"components-input-control__input\"\n\t\t\tdisabled={ disabled }\n\t\t\tdragCursor={ dragCursor }\n\t\t\tisDragging={ isDragging }\n\t\t\tid={ id }\n\t\t\tonBlur={ handleOnBlur }\n\t\t\tonChange={ handleOnChange }\n\t\t\tonFocus={ handleOnFocus }\n\t\t\tonKeyDown={ handleOnKeyDown }\n\t\t\tonMouseDown={ handleOnMouseDown }\n\t\t\tref={ ref }\n\t\t\tinputSize={ size }\n\t\t\tvalue={ value }\n\t\t\ttype={ type }\n\t\t/>\n\t);\n}\n\nconst ForwardedComponent = forwardRef( InputField );\n\nexport default ForwardedComponent;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/input-control/input-field.tsx"],"names":["noop","useDrag","forwardRef","useRef","useDragCursor","Input","useInputControlStateReducer","InputField","ref","disabled","dragDirection","dragThreshold","id","isDragEnabled","isFocused","isPressEnterToChange","onBlur","onChange","onDrag","onDragEnd","onDragStart","onFocus","onKeyDown","onValidate","size","setIsFocused","stateReducer","state","value","valueProp","type","props","change","commit","drag","dragEnd","dragStart","invalidate","pressDown","pressEnter","pressUp","reset","isDragging","isDirty","wasDirtyOnBlur","dragCursor","handleOnBlur","event","target","validity","valid","current","handleOnCommit","handleOnFocus","handleOnChange","nextValue","currentTarget","err","handleOnKeyDown","key","preventDefault","dragGestureProps","dragProps","distance","dragging","stopPropagation","axis","threshold","enabled","pointer","capture","handleOnMouseDown","onMouseDown","ownerDocument","activeElement","focus","ForwardedComponent"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,IAAT,QAAqB,QAArB;AACA,SAASC,OAAT,QAAwB,oBAAxB;;AAWA;AACA;AACA;AACA,SAASC,UAAT,EAAqBC,MAArB,QAAmC,oBAAnC;AACA;AACA;AACA;;AAEA,SAASC,aAAT,QAA8B,SAA9B;AACA,SAASC,KAAT,QAAsB,+BAAtB;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AAGI,KAfT;AAgBC,IAAA,IAAI,EAAGE;AAhBR,KADD;AAoBA;;AAED,MAAM8C,kBAAkB,GAAG1E,UAAU,CAAEK,UAAF,CAArC;AAEA,eAAeqE,kBAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { noop } from 'lodash';\nimport { useDrag } from '@use-gesture/react';\nimport type {\n\tSyntheticEvent,\n\tChangeEvent,\n\tKeyboardEvent,\n\tPointerEvent,\n\tFocusEvent,\n\tForwardedRef,\n\tMouseEvent,\n} from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { forwardRef, useRef } from '@wordpress/element';\n/**\n * Internal dependencies\n */\nimport type { WordPressComponentProps } from '../ui/context';\nimport { useDragCursor } from './utils';\nimport { Input } from './styles/input-control-styles';\nimport { useInputControlStateReducer } from './reducer/reducer';\nimport type { InputFieldProps } from './types';\n\nfunction InputField(\n\t{\n\t\tdisabled = false,\n\t\tdragDirection = 'n',\n\t\tdragThreshold = 10,\n\t\tid,\n\t\tisDragEnabled = false,\n\t\tisFocused,\n\t\tisPressEnterToChange = false,\n\t\tonBlur = noop,\n\t\tonChange = noop,\n\t\tonDrag = noop,\n\t\tonDragEnd = noop,\n\t\tonDragStart = noop,\n\t\tonFocus = noop,\n\t\tonKeyDown = noop,\n\t\tonValidate = noop,\n\t\tsize = 'default',\n\t\tsetIsFocused,\n\t\tstateReducer = ( state: any ) => state,\n\t\tvalue: valueProp,\n\t\ttype,\n\t\t...props\n\t}: WordPressComponentProps< InputFieldProps, 'input', false >,\n\tref: ForwardedRef< HTMLInputElement >\n) {\n\tconst {\n\t\t// State.\n\t\tstate,\n\t\t// Actions.\n\t\tchange,\n\t\tcommit,\n\t\tdrag,\n\t\tdragEnd,\n\t\tdragStart,\n\t\tinvalidate,\n\t\tpressDown,\n\t\tpressEnter,\n\t\tpressUp,\n\t\treset,\n\t} = useInputControlStateReducer(\n\t\tstateReducer,\n\t\t{\n\t\t\tisDragEnabled,\n\t\t\tvalue: valueProp,\n\t\t\tisPressEnterToChange,\n\t\t},\n\t\tonChange\n\t);\n\n\tconst { value, isDragging, isDirty } = state;\n\tconst wasDirtyOnBlur = useRef( false );\n\n\tconst dragCursor = useDragCursor( isDragging, dragDirection );\n\n\tconst handleOnBlur = ( event: FocusEvent< HTMLInputElement > ) => {\n\t\tonBlur( event );\n\t\tsetIsFocused?.( false );\n\n\t\t/**\n\t\t * If isPressEnterToChange is set, this commits the value to\n\t\t * the onChange callback.\n\t\t */\n\t\tif ( isDirty || ! event.target.validity.valid ) {\n\t\t\twasDirtyOnBlur.current = true;\n\t\t\thandleOnCommit( event );\n\t\t}\n\t};\n\n\tconst handleOnFocus = ( event: FocusEvent< HTMLInputElement > ) => {\n\t\tonFocus( event );\n\t\tsetIsFocused?.( true );\n\t};\n\n\tconst handleOnChange = ( event: ChangeEvent< HTMLInputElement > ) => {\n\t\tconst nextValue = event.target.value;\n\t\tchange( nextValue, event );\n\t};\n\n\tconst handleOnCommit = ( event: SyntheticEvent< HTMLInputElement > ) => {\n\t\tconst nextValue = event.currentTarget.value;\n\n\t\ttry {\n\t\t\tonValidate( nextValue );\n\t\t\tcommit( nextValue, event );\n\t\t} catch ( err ) {\n\t\t\tinvalidate( err, event );\n\t\t}\n\t};\n\n\tconst handleOnKeyDown = ( event: KeyboardEvent< HTMLInputElement > ) => {\n\t\tconst { key } = event;\n\t\tonKeyDown( event );\n\n\t\tswitch ( key ) {\n\t\t\tcase 'ArrowUp':\n\t\t\t\tpressUp( event );\n\t\t\t\tbreak;\n\n\t\t\tcase 'ArrowDown':\n\t\t\t\tpressDown( event );\n\t\t\t\tbreak;\n\n\t\t\tcase 'Enter':\n\t\t\t\tpressEnter( event );\n\n\t\t\t\tif ( isPressEnterToChange ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\thandleOnCommit( event );\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase 'Escape':\n\t\t\t\tif ( isPressEnterToChange && isDirty ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\treset( valueProp, event );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\tconst dragGestureProps = useDrag< PointerEvent< HTMLInputElement > >(\n\t\t( dragProps ) => {\n\t\t\tconst { distance, dragging, event, target } = dragProps;\n\n\t\t\t// The `target` prop always references the `input` element while, by\n\t\t\t// default, the `dragProps.event.target` property would reference the real\n\t\t\t// event target (i.e. any DOM element that the pointer is hovering while\n\t\t\t// dragging). Ensuring that the `target` is always the `input` element\n\t\t\t// allows consumers of `InputControl` (or any higher-level control) to\n\t\t\t// check the input's validity by accessing `event.target.validity.valid`.\n\t\t\tdragProps.event = {\n\t\t\t\t...dragProps.event,\n\t\t\t\ttarget,\n\t\t\t};\n\n\t\t\tif ( ! distance ) return;\n\t\t\tevent.stopPropagation();\n\n\t\t\t/**\n\t\t\t * Quick return if no longer dragging.\n\t\t\t * This prevents unnecessary value calculations.\n\t\t\t */\n\t\t\tif ( ! dragging ) {\n\t\t\t\tonDragEnd( dragProps );\n\t\t\t\tdragEnd( dragProps );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tonDrag( dragProps );\n\t\t\tdrag( dragProps );\n\n\t\t\tif ( ! isDragging ) {\n\t\t\t\tonDragStart( dragProps );\n\t\t\t\tdragStart( dragProps );\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\taxis: dragDirection === 'e' || dragDirection === 'w' ? 'x' : 'y',\n\t\t\tthreshold: dragThreshold,\n\t\t\tenabled: isDragEnabled,\n\t\t\tpointer: { capture: false },\n\t\t}\n\t);\n\n\tconst dragProps = isDragEnabled ? dragGestureProps() : {};\n\t/*\n\t * Works around the odd UA (e.g. Firefox) that does not focus inputs of\n\t * type=number when their spinner arrows are pressed.\n\t */\n\tlet handleOnMouseDown;\n\tif ( type === 'number' ) {\n\t\thandleOnMouseDown = ( event: MouseEvent< HTMLInputElement > ) => {\n\t\t\tprops.onMouseDown?.( event );\n\t\t\tif (\n\t\t\t\tevent.currentTarget !==\n\t\t\t\tevent.currentTarget.ownerDocument.activeElement\n\t\t\t) {\n\t\t\t\tevent.currentTarget.focus();\n\t\t\t}\n\t\t};\n\t}\n\n\treturn (\n\t\t<Input\n\t\t\t{ ...props }\n\t\t\t{ ...dragProps }\n\t\t\tclassName=\"components-input-control__input\"\n\t\t\tdisabled={ disabled }\n\t\t\tdragCursor={ dragCursor }\n\t\t\tisDragging={ isDragging }\n\t\t\tid={ id }\n\t\t\tonBlur={ handleOnBlur }\n\t\t\tonChange={ handleOnChange }\n\t\t\tonFocus={ handleOnFocus }\n\t\t\tonKeyDown={ handleOnKeyDown }\n\t\t\tonMouseDown={ handleOnMouseDown }\n\t\t\tref={ ref }\n\t\t\tinputSize={ size }\n\t\t\tvalue={ value }\n\t\t\ttype={ type }\n\t\t/>\n\t);\n}\n\nconst ForwardedComponent = forwardRef( InputField );\n\nexport default ForwardedComponent;\n"]}
|
|
@@ -5,20 +5,20 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* WordPress dependencies
|
|
7
7
|
*/
|
|
8
|
-
import { useReducer } from '@wordpress/element';
|
|
8
|
+
import { useReducer, useLayoutEffect, useRef } from '@wordpress/element';
|
|
9
9
|
/**
|
|
10
10
|
* Internal dependencies
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { initialInputControlState, initialStateReducer } from './state';
|
|
14
14
|
import * as actions from './actions';
|
|
15
|
+
|
|
15
16
|
/**
|
|
16
17
|
* Prepares initialState for the reducer.
|
|
17
18
|
*
|
|
18
19
|
* @param initialState The initial state.
|
|
19
20
|
* @return Prepared initialState for the reducer
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
22
|
function mergeInitialState() {
|
|
23
23
|
let initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialInputControlState;
|
|
24
24
|
const {
|
|
@@ -104,16 +104,13 @@ function inputControlStateReducer(composedStateReducers) {
|
|
|
104
104
|
break;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
|
|
108
|
-
nextState._event = action.payload.event;
|
|
109
|
-
}
|
|
107
|
+
nextState._event = action.payload.event;
|
|
110
108
|
/**
|
|
111
109
|
* Send the nextState + action to the composedReducers via
|
|
112
110
|
* this "bridge" mechanism. This allows external stateReducers
|
|
113
111
|
* to hook into actions, and modify state if needed.
|
|
114
112
|
*/
|
|
115
113
|
|
|
116
|
-
|
|
117
114
|
return composedStateReducers(nextState, action);
|
|
118
115
|
};
|
|
119
116
|
}
|
|
@@ -127,8 +124,9 @@ function inputControlStateReducer(composedStateReducers) {
|
|
|
127
124
|
* This technique uses the "stateReducer" design pattern:
|
|
128
125
|
* https://kentcdodds.com/blog/the-state-reducer-pattern/
|
|
129
126
|
*
|
|
130
|
-
* @param stateReducer
|
|
131
|
-
* @param initialState
|
|
127
|
+
* @param stateReducer An external state reducer.
|
|
128
|
+
* @param initialState The initial state for the reducer.
|
|
129
|
+
* @param onChangeHandler A handler for the onChange event.
|
|
132
130
|
* @return State, dispatch, and a collection of actions.
|
|
133
131
|
*/
|
|
134
132
|
|
|
@@ -136,18 +134,10 @@ function inputControlStateReducer(composedStateReducers) {
|
|
|
136
134
|
export function useInputControlStateReducer() {
|
|
137
135
|
let stateReducer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialStateReducer;
|
|
138
136
|
let initialState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : initialInputControlState;
|
|
137
|
+
let onChangeHandler = arguments.length > 2 ? arguments[2] : undefined;
|
|
139
138
|
const [state, dispatch] = useReducer(inputControlStateReducer(stateReducer), mergeInitialState(initialState));
|
|
140
139
|
|
|
141
140
|
const createChangeEvent = type => (nextValue, event) => {
|
|
142
|
-
/**
|
|
143
|
-
* Persist allows for the (Synthetic) event to be used outside of
|
|
144
|
-
* this function call.
|
|
145
|
-
* https://reactjs.org/docs/events.html#event-pooling
|
|
146
|
-
*/
|
|
147
|
-
if (event && event.persist) {
|
|
148
|
-
event.persist();
|
|
149
|
-
}
|
|
150
|
-
|
|
151
141
|
dispatch({
|
|
152
142
|
type,
|
|
153
143
|
payload: {
|
|
@@ -158,15 +148,6 @@ export function useInputControlStateReducer() {
|
|
|
158
148
|
};
|
|
159
149
|
|
|
160
150
|
const createKeyEvent = type => event => {
|
|
161
|
-
/**
|
|
162
|
-
* Persist allows for the (Synthetic) event to be used outside of
|
|
163
|
-
* this function call.
|
|
164
|
-
* https://reactjs.org/docs/events.html#event-pooling
|
|
165
|
-
*/
|
|
166
|
-
if (event && event.persist) {
|
|
167
|
-
event.persist();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
151
|
dispatch({
|
|
171
152
|
type,
|
|
172
153
|
payload: {
|
|
@@ -204,6 +185,37 @@ export function useInputControlStateReducer() {
|
|
|
204
185
|
const pressUp = createKeyEvent(actions.PRESS_UP);
|
|
205
186
|
const pressDown = createKeyEvent(actions.PRESS_DOWN);
|
|
206
187
|
const pressEnter = createKeyEvent(actions.PRESS_ENTER);
|
|
188
|
+
const currentState = useRef(state);
|
|
189
|
+
const refProps = useRef({
|
|
190
|
+
value: initialState.value,
|
|
191
|
+
onChangeHandler
|
|
192
|
+
});
|
|
193
|
+
useLayoutEffect(() => {
|
|
194
|
+
currentState.current = state;
|
|
195
|
+
refProps.current = {
|
|
196
|
+
value: initialState.value,
|
|
197
|
+
onChangeHandler
|
|
198
|
+
};
|
|
199
|
+
});
|
|
200
|
+
useLayoutEffect(() => {
|
|
201
|
+
if (currentState.current._event !== undefined && state.value !== refProps.current.value && !state.isDirty) {
|
|
202
|
+
var _state$value;
|
|
203
|
+
|
|
204
|
+
refProps.current.onChangeHandler((_state$value = state.value) !== null && _state$value !== void 0 ? _state$value : '', {
|
|
205
|
+
event: currentState.current._event
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}, [state.value, state.isDirty]);
|
|
209
|
+
useLayoutEffect(() => {
|
|
210
|
+
if (initialState.value !== currentState.current.value && !currentState.current.isDirty) {
|
|
211
|
+
dispatch({
|
|
212
|
+
type: actions.RESET,
|
|
213
|
+
payload: {
|
|
214
|
+
value: initialState.value
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}, [initialState.value]);
|
|
207
219
|
return {
|
|
208
220
|
change,
|
|
209
221
|
commit,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/input-control/reducer/reducer.ts"],"names":["useReducer","initialInputControlState","initialStateReducer","actions","mergeInitialState","initialState","value","initialValue","inputControlStateReducer","composedStateReducers","state","action","nextState","type","PRESS_UP","isDirty","PRESS_DOWN","DRAG_START","isDragging","DRAG_END","CHANGE","error","payload","isPressEnterToChange","COMMIT","RESET","INVALIDATE","event","_event","useInputControlStateReducer","stateReducer","dispatch","createChangeEvent","nextValue","persist","createKeyEvent","createDragEvent","change","invalidate","reset","commit","dragStart","drag","DRAG","dragEnd","pressUp","pressDown","pressEnter","PRESS_ENTER"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,UAAT,QAA2B,oBAA3B;AAEA;AACA;AACA;;AACA,SAGCC,wBAHD,EAICC,mBAJD,QAKO,SALP;AAMA,OAAO,KAAKC,OAAZ,MAAyB,WAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,iBAAT,GAEc;AAAA,MADbC,YACa,uEADyBJ,wBACzB;AACb,QAAM;AAAEK,IAAAA;AAAF,MAAYD,YAAlB;AAEA,SAAO,EACN,GAAGJ,wBADG;AAEN,OAAGI,YAFG;AAGNE,IAAAA,YAAY,EAAED;AAHR,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASE,wBAAT,CACCC,qBADD,EAEgB;AACf,SAAO,CAAEC,KAAF,EAASC,MAAT,KAAqB;AAC3B,UAAMC,SAAS,GAAG,EAAE,GAAGF;AAAL,KAAlB;;AAEA,YAASC,MAAM,CAACE,IAAhB;AACC;AACH;AACA;AACG,WAAKV,OAAO,CAACW,QAAb;AACCF,QAAAA,SAAS,C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BAAiB,CAAE7B,OAAO,CAACiB,MAAV,CAAhC;;AACA,QAAMkB,UAAU,GAAG,CAAEjB,KAAF,EAAkBM,KAAlB,KAClBI,QAAQ,CAAE;AAAElB,IAAAA,IAAI,EAAEV,OAAO,CAACuB,UAAhB;AAA4BJ,IAAAA,OAAO,EAAE;AAAED,MAAAA,KAAF;AAASM,MAAAA;AAAT;AAArC,GAAF,CADT;;AAEA,QAAMY,KAAK,GAAGP,iBAAiB,CAAE7B,OAAO,CAACsB,KAAV,CAA/B;AACA,QAAMe,MAAM,GAAGR,iBAAiB,CAAE7B,OAAO,CAACqB,MAAV,CAAhC;AAEA,QAAMiB,SAAS,GAAGL,eAAe,CAAEjC,OAAO,CAACc,UAAV,CAAjC;AACA,QAAMyB,IAAI,GAAGN,eAAe,CAAEjC,OAAO,CAACwC,IAAV,CAA5B;AACA,QAAMC,OAAO,GAAGR,eAAe,CAAEjC,OAAO,CAACgB,QAAV,CAA/B;AAEA,QAAM0B,OAAO,GAAGV,cAAc,CAAEhC,OAAO,CAACW,QAAV,CAA9B;AACA,QAAMgC,SAAS,GAAGX,cAAc,CAAEhC,OAAO,CAACa,UAAV,CAAhC;AACA,QAAM+B,UAAU,GAAGZ,cAAc,CAAEhC,OAAO,CAAC6C,WAAV,CAAjC;AAEA,SAAO;AACNX,IAAAA,MADM;AAENG,IAAAA,MAFM;AAGNT,IAAAA,QAHM;AAINW,IAAAA,IAJM;AAKNE,IAAAA,OALM;AAMNH,IAAAA,SANM;AAONH,IAAAA,UAPM;AAQNQ,IAAAA,SARM;AASNC,IAAAA,UATM;AAUNF,IAAAA,OAVM;AAWNN,IAAAA,KAXM;AAYN7B,IAAAA;AAZM,GAAP;AAcA","sourcesContent":["/**\n * External dependencies\n */\nimport type { SyntheticEvent } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useReducer } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport {\n\tInputState,\n\tStateReducer,\n\tinitialInputControlState,\n\tinitialStateReducer,\n} from './state';\nimport * as actions from './actions';\n\n/**\n * Prepares initialState for the reducer.\n *\n * @param initialState The initial state.\n * @return Prepared initialState for the reducer\n */\nfunction mergeInitialState(\n\tinitialState: Partial< InputState > = initialInputControlState\n): InputState {\n\tconst { value } = initialState;\n\n\treturn {\n\t\t...initialInputControlState,\n\t\t...initialState,\n\t\tinitialValue: value,\n\t} as InputState;\n}\n\n/**\n * Creates a reducer that opens the channel for external state subscription\n * and modification.\n *\n * This technique uses the \"stateReducer\" design pattern:\n * https://kentcdodds.com/blog/the-state-reducer-pattern/\n *\n * @param composedStateReducers A custom reducer that can subscribe and modify state.\n * @return The reducer.\n */\nfunction inputControlStateReducer(\n\tcomposedStateReducers: StateReducer\n): StateReducer {\n\treturn ( state, action ) => {\n\t\tconst nextState = { ...state };\n\n\t\tswitch ( action.type ) {\n\t\t\t/**\n\t\t\t * Keyboard events\n\t\t\t */\n\t\t\tcase actions.PRESS_UP:\n\t\t\t\tnextState.isDirty = false;\n\t\t\t\tbreak;\n\n\t\t\tcase actions.PRESS_DOWN:\n\t\t\t\tnextState.isDirty = false;\n\t\t\t\tbreak;\n\n\t\t\t/**\n\t\t\t * Drag events\n\t\t\t */\n\t\t\tcase actions.DRAG_START:\n\t\t\t\tnextState.isDragging = true;\n\t\t\t\tbreak;\n\n\t\t\tcase actions.DRAG_END:\n\t\t\t\tnextState.isDragging = false;\n\t\t\t\tbreak;\n\n\t\t\t/**\n\t\t\t * Input events\n\t\t\t */\n\t\t\tcase actions.CHANGE:\n\t\t\t\tnextState.error = null;\n\t\t\t\tnextState.value = action.payload.value;\n\n\t\t\t\tif ( state.isPressEnterToChange ) {\n\t\t\t\t\tnextState.isDirty = true;\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\n\t\t\tcase actions.COMMIT:\n\t\t\t\tnextState.value = action.payload.value;\n\t\t\t\tnextState.isDirty = false;\n\t\t\t\tbreak;\n\n\t\t\tcase actions.RESET:\n\t\t\t\tnextState.error = null;\n\t\t\t\tnextState.isDirty = false;\n\t\t\t\tnextState.value = action.payload.value || state.initialValue;\n\t\t\t\tbreak;\n\n\t\t\t/**\n\t\t\t * Validation\n\t\t\t */\n\t\t\tcase actions.INVALIDATE:\n\t\t\t\tnextState.error = action.payload.error;\n\t\t\t\tbreak;\n\t\t}\n\n\t\tif ( action.payload.event ) {\n\t\t\tnextState._event = action.payload.event;\n\t\t}\n\n\t\t/**\n\t\t * Send the nextState + action to the composedReducers via\n\t\t * this \"bridge\" mechanism. This allows external stateReducers\n\t\t * to hook into actions, and modify state if needed.\n\t\t */\n\t\treturn composedStateReducers( nextState, action );\n\t};\n}\n\n/**\n * A custom hook that connects and external stateReducer with an internal\n * reducer. This hook manages the internal state of InputControl.\n * However, by connecting an external stateReducer function, other\n * components can react to actions as well as modify state before it is\n * applied.\n *\n * This technique uses the \"stateReducer\" design pattern:\n * https://kentcdodds.com/blog/the-state-reducer-pattern/\n *\n * @param stateReducer An external state reducer.\n * @param initialState The initial state for the reducer.\n * @return State, dispatch, and a collection of actions.\n */\nexport function useInputControlStateReducer(\n\tstateReducer: StateReducer = initialStateReducer,\n\tinitialState: Partial< InputState > = initialInputControlState\n) {\n\tconst [ state, dispatch ] = useReducer< StateReducer >(\n\t\tinputControlStateReducer( stateReducer ),\n\t\tmergeInitialState( initialState )\n\t);\n\n\tconst createChangeEvent = ( type: actions.ChangeEventAction[ 'type' ] ) => (\n\t\tnextValue: actions.ChangeEventAction[ 'payload' ][ 'value' ],\n\t\tevent: actions.ChangeEventAction[ 'payload' ][ 'event' ]\n\t) => {\n\t\t/**\n\t\t * Persist allows for the (Synthetic) event to be used outside of\n\t\t * this function call.\n\t\t * https://reactjs.org/docs/events.html#event-pooling\n\t\t */\n\t\tif ( event && event.persist ) {\n\t\t\tevent.persist();\n\t\t}\n\n\t\tdispatch( {\n\t\t\ttype,\n\t\t\tpayload: { value: nextValue, event },\n\t\t} as actions.InputAction );\n\t};\n\n\tconst createKeyEvent = ( type: actions.KeyEventAction[ 'type' ] ) => (\n\t\tevent: actions.KeyEventAction[ 'payload' ][ 'event' ]\n\t) => {\n\t\t/**\n\t\t * Persist allows for the (Synthetic) event to be used outside of\n\t\t * this function call.\n\t\t * https://reactjs.org/docs/events.html#event-pooling\n\t\t */\n\t\tif ( event && event.persist ) {\n\t\t\tevent.persist();\n\t\t}\n\n\t\tdispatch( { type, payload: { event } } );\n\t};\n\n\tconst createDragEvent = ( type: actions.DragEventAction[ 'type' ] ) => (\n\t\tpayload: actions.DragEventAction[ 'payload' ]\n\t) => {\n\t\tdispatch( { type, payload } );\n\t};\n\n\t/**\n\t * Actions for the reducer\n\t */\n\tconst change = createChangeEvent( actions.CHANGE );\n\tconst invalidate = ( error: unknown, event: SyntheticEvent ) =>\n\t\tdispatch( { type: actions.INVALIDATE, payload: { error, event } } );\n\tconst reset = createChangeEvent( actions.RESET );\n\tconst commit = createChangeEvent( actions.COMMIT );\n\n\tconst dragStart = createDragEvent( actions.DRAG_START );\n\tconst drag = createDragEvent( actions.DRAG );\n\tconst dragEnd = createDragEvent( actions.DRAG_END );\n\n\tconst pressUp = createKeyEvent( actions.PRESS_UP );\n\tconst pressDown = createKeyEvent( actions.PRESS_DOWN );\n\tconst pressEnter = createKeyEvent( actions.PRESS_ENTER );\n\n\treturn {\n\t\tchange,\n\t\tcommit,\n\t\tdispatch,\n\t\tdrag,\n\t\tdragEnd,\n\t\tdragStart,\n\t\tinvalidate,\n\t\tpressDown,\n\t\tpressEnter,\n\t\tpressUp,\n\t\treset,\n\t\tstate,\n\t} as const;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/input-control/reducer/reducer.ts"],"names":["useReducer","useLayoutEffect","useRef","initialInputControlState","initialStateReducer","actions","mergeInitialState","initialState","value","initialValue","inputControlStateReducer","composedStateReducers","state","action","nextState","type","PRESS_UP","isDirty","PRESS_DOWN","DRAG_START","isDragging","DRAG_END","CHANGE","error","payload","isPressEnterToChange","COMMIT","RESET","INVALIDATE","_event","event","useInputControlStateReducer","stateReducer","onChangeHandler","dispatch","createChangeEvent","nextValue","createKeyEvent","createDragEvent","change","invalidate","reset","commit","dragStart","drag","DRAG","dragEnd","pressUp","pressDown","pressEnter","PRESS_ENTER","currentState","refProps","current","undefined"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,UAAT,EAAqBC,eAArB,EAAsCC,MAAtC,QAAoD,oBAApD;AAEA;AACA;AACA;;AACA,SAGCC,wBAHD,EAICC,mBAJD,QAKO,SALP;AAMA,OAAO,KAAKC,OAAZ,MAAyB,WAAzB;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,iBAAT,GAEc;AAAA,MADbC,YACa,uEADyBJ,wBACzB;AACb,QAAM;AAAEK,IAAAA;AAAF,MAAYD,YAAlB;AAEA,SAAO,EACN,GAAGJ,wBADG;AAEN,OAAGI,YAFG;AAGNE,IAAAA,YAAY,EAAED;AAHR,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASE,wBAAT,CACCC,qBADD,EAEgB;AACf,SAAO,CAAEC,KAAF,EAASC,MAAT,KAAqB;AAC3B,UAAMC,SAAS,GAAG,EAAE,GAAGF;AAAL,KAAlB;;AAEA,YAASC,MAAM,CAACE,IAAhB;AACC;AACH;AACA;AACG,WAAKV,OAAO,CAACW,QAAb;AACCF,QAAAA,SAAS,CAACG,OAAV,GAAoB,KAApB;AACA;;AAED,WAAKZ,OAAO,CAACa,UAAb;AACCJ,QAAAA,SAAS,CAACG,OAAV,GAAoB,KAApB;AACA;;AAED;AACH;AACA;;AACG,WAAKZ,OAAO,CAACc,UAAb;AACCL,QAAAA,SAAS,CAACM,UAAV,GAAuB,IAAvB;AACA;;AAED,WAAKf,OAAO,CAACgB,QAAb;AACCP,QAAAA,SAAS,CAACM,UAAV,GAAuB,KAAvB;AACA;;AAED;AACH;AACA;;AACG,WAAKf,OAAO,CAACiB,MAAb;AACCR,QAAAA,SAAS,CAACS,K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,QAAAA,IAAI,EAAEV,OAAO,CAACsB,KADL;AAETH,QAAAA,OAAO,EAAE;AAAEhB,UAAAA,KAAK,EAAED,YAAY,CAACC;AAAtB;AAFA,OAAF,CAAR;AAIA;AACD,GAVc,EAUZ,CAAED,YAAY,CAACC,KAAf,CAVY,CAAf;AAYA,SAAO;AACN+B,IAAAA,MADM;AAENG,IAAAA,MAFM;AAGNR,IAAAA,QAHM;AAINU,IAAAA,IAJM;AAKNE,IAAAA,OALM;AAMNH,IAAAA,SANM;AAONH,IAAAA,UAPM;AAQNQ,IAAAA,SARM;AASNC,IAAAA,UATM;AAUNF,IAAAA,OAVM;AAWNN,IAAAA,KAXM;AAYN7B,IAAAA;AAZM,GAAP;AAcA","sourcesContent":["/**\n * External dependencies\n */\nimport type { SyntheticEvent, ChangeEvent, PointerEvent } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useReducer, useLayoutEffect, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport {\n\tInputState,\n\tStateReducer,\n\tinitialInputControlState,\n\tinitialStateReducer,\n} from './state';\nimport * as actions from './actions';\nimport type { InputChangeCallback } from '../types';\n\n/**\n * Prepares initialState for the reducer.\n *\n * @param initialState The initial state.\n * @return Prepared initialState for the reducer\n */\nfunction mergeInitialState(\n\tinitialState: Partial< InputState > = initialInputControlState\n): InputState {\n\tconst { value } = initialState;\n\n\treturn {\n\t\t...initialInputControlState,\n\t\t...initialState,\n\t\tinitialValue: value,\n\t} as InputState;\n}\n\n/**\n * Creates a reducer that opens the channel for external state subscription\n * and modification.\n *\n * This technique uses the \"stateReducer\" design pattern:\n * https://kentcdodds.com/blog/the-state-reducer-pattern/\n *\n * @param composedStateReducers A custom reducer that can subscribe and modify state.\n * @return The reducer.\n */\nfunction inputControlStateReducer(\n\tcomposedStateReducers: StateReducer\n): StateReducer {\n\treturn ( state, action ) => {\n\t\tconst nextState = { ...state };\n\n\t\tswitch ( action.type ) {\n\t\t\t/**\n\t\t\t * Keyboard events\n\t\t\t */\n\t\t\tcase actions.PRESS_UP:\n\t\t\t\tnextState.isDirty = false;\n\t\t\t\tbreak;\n\n\t\t\tcase actions.PRESS_DOWN:\n\t\t\t\tnextState.isDirty = false;\n\t\t\t\tbreak;\n\n\t\t\t/**\n\t\t\t * Drag events\n\t\t\t */\n\t\t\tcase actions.DRAG_START:\n\t\t\t\tnextState.isDragging = true;\n\t\t\t\tbreak;\n\n\t\t\tcase actions.DRAG_END:\n\t\t\t\tnextState.isDragging = false;\n\t\t\t\tbreak;\n\n\t\t\t/**\n\t\t\t * Input events\n\t\t\t */\n\t\t\tcase actions.CHANGE:\n\t\t\t\tnextState.error = null;\n\t\t\t\tnextState.value = action.payload.value;\n\n\t\t\t\tif ( state.isPressEnterToChange ) {\n\t\t\t\t\tnextState.isDirty = true;\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\n\t\t\tcase actions.COMMIT:\n\t\t\t\tnextState.value = action.payload.value;\n\t\t\t\tnextState.isDirty = false;\n\t\t\t\tbreak;\n\n\t\t\tcase actions.RESET:\n\t\t\t\tnextState.error = null;\n\t\t\t\tnextState.isDirty = false;\n\t\t\t\tnextState.value = action.payload.value || state.initialValue;\n\t\t\t\tbreak;\n\n\t\t\t/**\n\t\t\t * Validation\n\t\t\t */\n\t\t\tcase actions.INVALIDATE:\n\t\t\t\tnextState.error = action.payload.error;\n\t\t\t\tbreak;\n\t\t}\n\n\t\tnextState._event = action.payload.event;\n\n\t\t/**\n\t\t * Send the nextState + action to the composedReducers via\n\t\t * this \"bridge\" mechanism. This allows external stateReducers\n\t\t * to hook into actions, and modify state if needed.\n\t\t */\n\t\treturn composedStateReducers( nextState, action );\n\t};\n}\n\n/**\n * A custom hook that connects and external stateReducer with an internal\n * reducer. This hook manages the internal state of InputControl.\n * However, by connecting an external stateReducer function, other\n * components can react to actions as well as modify state before it is\n * applied.\n *\n * This technique uses the \"stateReducer\" design pattern:\n * https://kentcdodds.com/blog/the-state-reducer-pattern/\n *\n * @param stateReducer An external state reducer.\n * @param initialState The initial state for the reducer.\n * @param onChangeHandler A handler for the onChange event.\n * @return State, dispatch, and a collection of actions.\n */\nexport function useInputControlStateReducer(\n\tstateReducer: StateReducer = initialStateReducer,\n\tinitialState: Partial< InputState > = initialInputControlState,\n\tonChangeHandler: InputChangeCallback\n) {\n\tconst [ state, dispatch ] = useReducer< StateReducer >(\n\t\tinputControlStateReducer( stateReducer ),\n\t\tmergeInitialState( initialState )\n\t);\n\n\tconst createChangeEvent = ( type: actions.ChangeEventAction[ 'type' ] ) => (\n\t\tnextValue: actions.ChangeEventAction[ 'payload' ][ 'value' ],\n\t\tevent: actions.ChangeEventAction[ 'payload' ][ 'event' ]\n\t) => {\n\t\tdispatch( {\n\t\t\ttype,\n\t\t\tpayload: { value: nextValue, event },\n\t\t} as actions.InputAction );\n\t};\n\n\tconst createKeyEvent = ( type: actions.KeyEventAction[ 'type' ] ) => (\n\t\tevent: actions.KeyEventAction[ 'payload' ][ 'event' ]\n\t) => {\n\t\tdispatch( { type, payload: { event } } );\n\t};\n\n\tconst createDragEvent = ( type: actions.DragEventAction[ 'type' ] ) => (\n\t\tpayload: actions.DragEventAction[ 'payload' ]\n\t) => {\n\t\tdispatch( { type, payload } );\n\t};\n\n\t/**\n\t * Actions for the reducer\n\t */\n\tconst change = createChangeEvent( actions.CHANGE );\n\tconst invalidate = ( error: unknown, event: SyntheticEvent ) =>\n\t\tdispatch( { type: actions.INVALIDATE, payload: { error, event } } );\n\tconst reset = createChangeEvent( actions.RESET );\n\tconst commit = createChangeEvent( actions.COMMIT );\n\n\tconst dragStart = createDragEvent( actions.DRAG_START );\n\tconst drag = createDragEvent( actions.DRAG );\n\tconst dragEnd = createDragEvent( actions.DRAG_END );\n\n\tconst pressUp = createKeyEvent( actions.PRESS_UP );\n\tconst pressDown = createKeyEvent( actions.PRESS_DOWN );\n\tconst pressEnter = createKeyEvent( actions.PRESS_ENTER );\n\n\tconst currentState = useRef( state );\n\tconst refProps = useRef( { value: initialState.value, onChangeHandler } );\n\tuseLayoutEffect( () => {\n\t\tcurrentState.current = state;\n\t\trefProps.current = { value: initialState.value, onChangeHandler };\n\t} );\n\tuseLayoutEffect( () => {\n\t\tif (\n\t\t\tcurrentState.current._event !== undefined &&\n\t\t\tstate.value !== refProps.current.value &&\n\t\t\t! state.isDirty\n\t\t) {\n\t\t\trefProps.current.onChangeHandler( state.value ?? '', {\n\t\t\t\tevent: currentState.current._event as\n\t\t\t\t\t| ChangeEvent< HTMLInputElement >\n\t\t\t\t\t| PointerEvent< HTMLInputElement >,\n\t\t\t} );\n\t\t}\n\t}, [ state.value, state.isDirty ] );\n\tuseLayoutEffect( () => {\n\t\tif (\n\t\t\tinitialState.value !== currentState.current.value &&\n\t\t\t! currentState.current.isDirty\n\t\t) {\n\t\t\tdispatch( {\n\t\t\t\ttype: actions.RESET,\n\t\t\t\tpayload: { value: initialState.value },\n\t\t\t} );\n\t\t}\n\t}, [ initialState.value ] );\n\n\treturn {\n\t\tchange,\n\t\tcommit,\n\t\tdispatch,\n\t\tdrag,\n\t\tdragEnd,\n\t\tdragStart,\n\t\tinvalidate,\n\t\tpressDown,\n\t\tpressEnter,\n\t\tpressUp,\n\t\treset,\n\t\tstate,\n\t} as const;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/input-control/reducer/state.ts"],"names":["initialStateReducer","state","initialInputControlState","
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/input-control/reducer/state.ts"],"names":["initialStateReducer","state","initialInputControlState","error","initialValue","isDirty","isDragEnabled","isDragging","isPressEnterToChange","value"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AAgBA,OAAO,MAAMA,mBAAiC,GAAKC,KAAF,IAAyBA,KAAnE;AAEP,OAAO,MAAMC,wBAAoC,GAAG;AACnDC,EAAAA,KAAK,EAAE,IAD4C;AAEnDC,EAAAA,YAAY,EAAE,EAFqC;AAGnDC,EAAAA,OAAO,EAAE,KAH0C;AAInDC,EAAAA,aAAa,EAAE,KAJoC;AAKnDC,EAAAA,UAAU,EAAE,KALuC;AAMnDC,EAAAA,oBAAoB,EAAE,KAN6B;AAOnDC,EAAAA,KAAK,EAAE;AAP4C,CAA7C","sourcesContent":["/**\n * External dependencies\n */\nimport type { Reducer, SyntheticEvent } from 'react';\n\n/**\n * Internal dependencies\n */\nimport type { InputAction } from './actions';\n\nexport interface InputState {\n\t_event?: SyntheticEvent;\n\terror: unknown;\n\tinitialValue?: string;\n\tisDirty: boolean;\n\tisDragEnabled: boolean;\n\tisDragging: boolean;\n\tisPressEnterToChange: boolean;\n\tvalue?: string;\n}\n\nexport type StateReducer = Reducer< InputState, InputAction >;\n\nexport const initialStateReducer: StateReducer = ( state: InputState ) => state;\n\nexport const initialInputControlState: InputState = {\n\terror: null,\n\tinitialValue: '',\n\tisDirty: false,\n\tisDragEnabled: false,\n\tisDragging: false,\n\tisPressEnterToChange: false,\n\tvalue: '',\n};\n"]}
|
|
@@ -1,14 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* WordPress dependencies
|
|
3
7
|
*/
|
|
4
|
-
import { useEffect } from '@wordpress/element';
|
|
8
|
+
import { useEffect, useLayoutEffect, useRef, useState } from '@wordpress/element';
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
|
|
5
13
|
/**
|
|
6
14
|
* Gets a CSS cursor value based on a drag direction.
|
|
7
15
|
*
|
|
8
16
|
* @param dragDirection The drag direction.
|
|
9
17
|
* @return The CSS cursor value.
|
|
10
18
|
*/
|
|
11
|
-
|
|
12
19
|
export function getDragCursor(dragDirection) {
|
|
13
20
|
let dragCursor = 'ns-resize';
|
|
14
21
|
|
|
@@ -47,4 +54,43 @@ export function useDragCursor(isDragging, dragDirection) {
|
|
|
47
54
|
}, [isDragging]);
|
|
48
55
|
return dragCursor;
|
|
49
56
|
}
|
|
57
|
+
export function useDraft(props) {
|
|
58
|
+
const refPreviousValue = useRef(props.value);
|
|
59
|
+
const [draft, setDraft] = useState({});
|
|
60
|
+
const value = draft.value !== undefined ? draft.value : props.value; // Determines when to discard the draft value to restore controlled status.
|
|
61
|
+
// To do so, it tracks the previous value and marks the draft value as stale
|
|
62
|
+
// after each render.
|
|
63
|
+
|
|
64
|
+
useLayoutEffect(() => {
|
|
65
|
+
const {
|
|
66
|
+
current: previousValue
|
|
67
|
+
} = refPreviousValue;
|
|
68
|
+
refPreviousValue.current = props.value;
|
|
69
|
+
if (draft.value !== undefined && !draft.isStale) setDraft({ ...draft,
|
|
70
|
+
isStale: true
|
|
71
|
+
});else if (draft.isStale && props.value !== previousValue) setDraft({});
|
|
72
|
+
}, [props.value, draft]);
|
|
73
|
+
|
|
74
|
+
const onChange = (nextValue, extra) => {
|
|
75
|
+
// Mutates the draft value to avoid an extra effect run.
|
|
76
|
+
setDraft(current => Object.assign(current, {
|
|
77
|
+
value: nextValue,
|
|
78
|
+
isStale: false
|
|
79
|
+
}));
|
|
80
|
+
props.onChange(nextValue, extra);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const onBlur = event => {
|
|
84
|
+
var _props$onBlur;
|
|
85
|
+
|
|
86
|
+
setDraft({});
|
|
87
|
+
(_props$onBlur = props.onBlur) === null || _props$onBlur === void 0 ? void 0 : _props$onBlur.call(props, event);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
value,
|
|
92
|
+
onBlur,
|
|
93
|
+
onChange
|
|
94
|
+
};
|
|
95
|
+
}
|
|
50
96
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/input-control/utils.ts"],"names":["useEffect","getDragCursor","dragDirection","dragCursor","useDragCursor","isDragging","document","documentElement","style","cursor"],"mappings":"AAAA;AACA;AACA;AACA,
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/input-control/utils.ts"],"names":["useEffect","useLayoutEffect","useRef","useState","getDragCursor","dragDirection","dragCursor","useDragCursor","isDragging","document","documentElement","style","cursor","useDraft","props","refPreviousValue","value","draft","setDraft","undefined","current","previousValue","isStale","onChange","nextValue","extra","Object","assign","onBlur","event"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SACCA,SADD,EAECC,eAFD,EAGCC,MAHD,EAICC,QAJD,QAKO,oBALP;AAOA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAT,CAAwBC,aAAxB,EAAwD;AAC9D,MAAIC,UAAU,GAAG,WAAjB;;AAEA,UAASD,aAAT;AACC,SAAK,GAAL;AACA,SAAK,GAAL;AACCC,MAAAA,UAAU,GAAG,WAAb;AACA;;AAED,SAAK,GAAL;AACA,SAAK,GAAL;AACCA,MAAAA,UAAU,GAAG,WAAb;AACA;AATF;;AAYA,SAAOA,UAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,aAAT,CACNC,UADM,EAENH,aAFM,EAGG;AACT,QAAMC,UAAU,GAAGF,aAAa,CAAEC,aAAF,CAAhC;AAEAL,EAAAA,SAAS,CAAE,MAAM;AAChB,QAAKQ,UAAL,EAAkB;AACjBC,MAAAA,QAAQ,CAACC,eAAT,CAAyBC,KAAzB,CAA+BC,MAA/B,GAAwCN,UAAxC;AACA,KAFD,MAEO;AACN;AACAG,MAAAA,QAAQ,CAACC,eAAT,CAAyBC,KAAzB,CAA+BC,MAA/B,GAAwC,IAAxC;AACA;AACD,GAPQ,EAON,CAAEJ,UAAF,CAPM,CAAT;AASA,SAAOF,UAAP;AACA;AAED,OAAO,SAASO,QAAT,CAAmBC,KAAnB,EAIH;AACH,QAAMC,gBAAgB,GAAGb,MAAM,CAAEY,KAAK,CAACE,KAAR,CAA/B;AACA,QAAM,CAAEC,KAAF,EAASC,QAAT,IAAsBf,QAAQ,C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* External dependencies\n */\nimport type { FocusEventHandler } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { InputChangeCallback } from './types';\n\n/**\n * Gets a CSS cursor value based on a drag direction.\n *\n * @param dragDirection The drag direction.\n * @return The CSS cursor value.\n */\nexport function getDragCursor( dragDirection: string ): string {\n\tlet dragCursor = 'ns-resize';\n\n\tswitch ( dragDirection ) {\n\t\tcase 'n':\n\t\tcase 's':\n\t\t\tdragCursor = 'ns-resize';\n\t\t\tbreak;\n\n\t\tcase 'e':\n\t\tcase 'w':\n\t\t\tdragCursor = 'ew-resize';\n\t\t\tbreak;\n\t}\n\n\treturn dragCursor;\n}\n\n/**\n * Custom hook that renders a drag cursor when dragging.\n *\n * @param {boolean} isDragging The dragging state.\n * @param {string} dragDirection The drag direction.\n *\n * @return {string} The CSS cursor value.\n */\nexport function useDragCursor(\n\tisDragging: boolean,\n\tdragDirection: string\n): string {\n\tconst dragCursor = getDragCursor( dragDirection );\n\n\tuseEffect( () => {\n\t\tif ( isDragging ) {\n\t\t\tdocument.documentElement.style.cursor = dragCursor;\n\t\t} else {\n\t\t\t// @ts-expect-error\n\t\t\tdocument.documentElement.style.cursor = null;\n\t\t}\n\t}, [ isDragging ] );\n\n\treturn dragCursor;\n}\n\nexport function useDraft( props: {\n\tvalue: string | undefined;\n\tonBlur?: FocusEventHandler;\n\tonChange: InputChangeCallback;\n} ) {\n\tconst refPreviousValue = useRef( props.value );\n\tconst [ draft, setDraft ] = useState< {\n\t\tvalue?: string;\n\t\tisStale?: boolean;\n\t} >( {} );\n\tconst value = draft.value !== undefined ? draft.value : props.value;\n\n\t// Determines when to discard the draft value to restore controlled status.\n\t// To do so, it tracks the previous value and marks the draft value as stale\n\t// after each render.\n\tuseLayoutEffect( () => {\n\t\tconst { current: previousValue } = refPreviousValue;\n\t\trefPreviousValue.current = props.value;\n\t\tif ( draft.value !== undefined && ! draft.isStale )\n\t\t\tsetDraft( { ...draft, isStale: true } );\n\t\telse if ( draft.isStale && props.value !== previousValue )\n\t\t\tsetDraft( {} );\n\t}, [ props.value, draft ] );\n\n\tconst onChange: InputChangeCallback = ( nextValue, extra ) => {\n\t\t// Mutates the draft value to avoid an extra effect run.\n\t\tsetDraft( ( current ) =>\n\t\t\tObject.assign( current, { value: nextValue, isStale: false } )\n\t\t);\n\t\tprops.onChange( nextValue, extra );\n\t};\n\tconst onBlur: FocusEventHandler = ( event ) => {\n\t\tsetDraft( {} );\n\t\tprops.onBlur?.( event );\n\t};\n\n\treturn { value, onBlur, onChange };\n}\n"]}
|
|
@@ -101,6 +101,7 @@ const Popover = (_ref, ref) => {
|
|
|
101
101
|
__unstableSlotName = SLOT_NAME,
|
|
102
102
|
__unstableObserveElement,
|
|
103
103
|
__unstableForcePosition,
|
|
104
|
+
__unstableShift = false,
|
|
104
105
|
...contentProps
|
|
105
106
|
} = _ref;
|
|
106
107
|
|
|
@@ -116,30 +117,31 @@ const Popover = (_ref, ref) => {
|
|
|
116
117
|
const isExpanded = expandOnMobile && isMobileViewport;
|
|
117
118
|
const hasArrow = !isExpanded && !noArrow;
|
|
118
119
|
const usedPlacement = position ? positionToPlacement(position) : placement;
|
|
119
|
-
|
|
120
|
-
* Offsets the the position of the popover when the anchor is inside an iframe.
|
|
121
|
-
*/
|
|
122
|
-
|
|
123
|
-
const frameOffset = useMemo(() => {
|
|
124
|
-
let ownerDocument = document;
|
|
125
|
-
|
|
120
|
+
const ownerDocument = useMemo(() => {
|
|
126
121
|
if (anchorRef !== null && anchorRef !== void 0 && anchorRef.top) {
|
|
127
|
-
|
|
122
|
+
return anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.top.ownerDocument;
|
|
128
123
|
} else if (anchorRef !== null && anchorRef !== void 0 && anchorRef.startContainer) {
|
|
129
|
-
|
|
124
|
+
return anchorRef.startContainer.ownerDocument;
|
|
130
125
|
} else if (anchorRef !== null && anchorRef !== void 0 && anchorRef.current) {
|
|
131
|
-
|
|
126
|
+
return anchorRef.current.ownerDocument;
|
|
132
127
|
} else if (anchorRef) {
|
|
133
128
|
// This one should be deprecated.
|
|
134
|
-
|
|
129
|
+
return anchorRef.ownerDocument;
|
|
135
130
|
} else if (anchorRect && anchorRect !== null && anchorRect !== void 0 && anchorRect.ownerDocument) {
|
|
136
|
-
|
|
131
|
+
return anchorRect.ownerDocument;
|
|
137
132
|
} else if (getAnchorRect) {
|
|
138
133
|
var _getAnchorRect$ownerD, _getAnchorRect;
|
|
139
134
|
|
|
140
|
-
|
|
135
|
+
return (_getAnchorRect$ownerD = (_getAnchorRect = getAnchorRect()) === null || _getAnchorRect === void 0 ? void 0 : _getAnchorRect.ownerDocument) !== null && _getAnchorRect$ownerD !== void 0 ? _getAnchorRect$ownerD : document;
|
|
141
136
|
}
|
|
142
137
|
|
|
138
|
+
return document;
|
|
139
|
+
}, [anchorRef, anchorRect, getAnchorRect]);
|
|
140
|
+
/**
|
|
141
|
+
* Offsets the the position of the popover when the anchor is inside an iframe.
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
const frameOffset = useMemo(() => {
|
|
143
145
|
const {
|
|
144
146
|
defaultView
|
|
145
147
|
} = ownerDocument;
|
|
@@ -167,25 +169,26 @@ const Popover = (_ref, ref) => {
|
|
|
167
169
|
}
|
|
168
170
|
|
|
169
171
|
};
|
|
170
|
-
}, [
|
|
172
|
+
}, [ownerDocument]);
|
|
171
173
|
const middlewares = [frameOffset, offset ? offsetMiddleware(offset) : undefined, __unstableForcePosition ? undefined : flip(), __unstableForcePosition ? undefined : size({
|
|
172
|
-
apply(
|
|
173
|
-
|
|
174
|
-
width,
|
|
174
|
+
apply(sizeProps) {
|
|
175
|
+
const {
|
|
175
176
|
height
|
|
176
|
-
} =
|
|
177
|
-
if (!refs.floating.current) return;
|
|
177
|
+
} = sizeProps;
|
|
178
|
+
if (!refs.floating.current) return; // Reduce the height of the popover to the available space.
|
|
179
|
+
|
|
178
180
|
Object.assign(refs.floating.current.firstChild.style, {
|
|
179
|
-
maxWidth: `${width}px`,
|
|
180
181
|
maxHeight: `${height}px`,
|
|
181
182
|
overflow: 'auto'
|
|
182
183
|
});
|
|
183
184
|
}
|
|
184
185
|
|
|
185
|
-
})
|
|
186
|
+
}), __unstableShift ? shift({
|
|
186
187
|
crossAxis: true,
|
|
187
|
-
limiter: limitShift()
|
|
188
|
-
|
|
188
|
+
limiter: limitShift(),
|
|
189
|
+
padding: 1 // Necessary to avoid flickering at the edge of the viewport.
|
|
190
|
+
|
|
191
|
+
}) : undefined, hasArrow ? arrow({
|
|
189
192
|
element: arrowRef
|
|
190
193
|
}) : undefined].filter(m => !!m);
|
|
191
194
|
const anchorRefFallback = useRef(null);
|
|
@@ -260,15 +263,10 @@ const Popover = (_ref, ref) => {
|
|
|
260
263
|
} else if (getAnchorRect) {
|
|
261
264
|
usedRef = {
|
|
262
265
|
getBoundingClientRect() {
|
|
263
|
-
var _rect$x, _rect$y, _rect$
|
|
266
|
+
var _rect$x, _rect$y, _rect$width, _rect$height;
|
|
264
267
|
|
|
265
268
|
const rect = getAnchorRect();
|
|
266
|
-
return
|
|
267
|
-
x: (_rect$x = rect.x) !== null && _rect$x !== void 0 ? _rect$x : rect.left,
|
|
268
|
-
y: (_rect$y = rect.y) !== null && _rect$y !== void 0 ? _rect$y : rect.top,
|
|
269
|
-
height: (_rect$height = rect.height) !== null && _rect$height !== void 0 ? _rect$height : rect.bottom - rect.top,
|
|
270
|
-
width: (_rect$width = rect.width) !== null && _rect$width !== void 0 ? _rect$width : rect.right - rect.left
|
|
271
|
-
};
|
|
269
|
+
return new window.DOMRect((_rect$x = rect.x) !== null && _rect$x !== void 0 ? _rect$x : rect.left, (_rect$y = rect.y) !== null && _rect$y !== void 0 ? _rect$y : rect.top, (_rect$width = rect.width) !== null && _rect$width !== void 0 ? _rect$width : rect.right - rect.left, (_rect$height = rect.height) !== null && _rect$height !== void 0 ? _rect$height : rect.bottom - rect.top);
|
|
272
270
|
}
|
|
273
271
|
|
|
274
272
|
};
|
|
@@ -301,7 +299,16 @@ const Popover = (_ref, ref) => {
|
|
|
301
299
|
return () => {
|
|
302
300
|
observer.disconnect();
|
|
303
301
|
};
|
|
304
|
-
}, [__unstableObserveElement]);
|
|
302
|
+
}, [__unstableObserveElement]); // If we're using getAnchorRect, we need to update the position as we scroll the iframe.
|
|
303
|
+
|
|
304
|
+
useLayoutEffect(() => {
|
|
305
|
+
if (ownerDocument === document) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
ownerDocument.addEventListener('scroll', update);
|
|
310
|
+
return () => ownerDocument.removeEventListener('scroll', update);
|
|
311
|
+
}, [ownerDocument]);
|
|
305
312
|
/** @type {false | string} */
|
|
306
313
|
|
|
307
314
|
const animateClassName = !!animate && getAnimateClassName({
|
|
@@ -365,10 +372,10 @@ const Popover = (_ref, ref) => {
|
|
|
365
372
|
|
|
366
373
|
const PopoverContainer = forwardRef(Popover);
|
|
367
374
|
|
|
368
|
-
function PopoverSlot(
|
|
375
|
+
function PopoverSlot(_ref3, ref) {
|
|
369
376
|
let {
|
|
370
377
|
name = SLOT_NAME
|
|
371
|
-
} =
|
|
378
|
+
} = _ref3;
|
|
372
379
|
return createElement(Slot, {
|
|
373
380
|
bubblesVirtually: true,
|
|
374
381
|
name: name,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/popover/index.js"],"names":["classnames","useFloating","flip","shift","autoUpdate","arrow","offset","offsetMiddleware","limitShift","size","useRef","useLayoutEffect","forwardRef","createContext","useContext","useMemo","useViewportMatch","useMergeRefs","__experimentalUseDialog","useDialog","close","deprecated","Button","ScrollLock","Slot","Fill","useSlot","getAnimateClassName","SLOT_NAME","slotNameContext","positionToPlacement","position","x","y","z","split","includes","suffix","placementToAnimationOrigin","placement","a","b","Popover","ref","range","animate","headerTitle","onClose","children","className","noArrow","isAlternate","focusOnMount","anchorRef","anchorRect","getAnchorRect","expandOnMobile","onFocusOutside","__unstableSlotName","__unstableObserveElement","__unstableForcePosition","contentProps","since","version","arrowRef","isMobileViewport","isExpanded","hasArrow","usedPlacement","frameOffset","ownerDocument","document","top","startContainer","current","defaultView","frameElement","undefined","iframeRect","getBoundingClientRect","name","fn","left","middlewares","apply","width","height","refs","floating","Object","assign","firstChild","style","maxWidth","maxHeight","overflow","crossAxis","limiter","element","filter","m","anchorRefFallback","slotName","slot","onDialogClose","type","event","dialogRef","dialogProps","__unstableOnClose","reference","strategy","update","placementData","middlewareData","arrowData","middleware","staticSide","right","bottom","mergedRefs","usedRef","topRect","bottomRect","window","DOMRect","rect","observer","MutationObserver","observe","attributes","disconnect","animateClassName","origin","content","Number","isNaN","PopoverContainer","PopoverSlot","__unstableSlotNameProvider","Provider"],"mappings":";;AAAA;;AACA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AACA,SACCC,WADD,EAECC,IAFD,EAGCC,KAHD,EAICC,UAJD,EAKCC,KALD,EAMCC,MAAM,IAAIC,gBANX,EAOCC,UAPD,EAQCC,IARD,QASO,wBATP;AAWA;AACA;AACA;;AACA,SACCC,MADD,EAECC,eAFD,EAGCC,UAHD,EAICC,aAJD,EAKCC,UALD,EAMCC,OAND,QAOO,oBAPP;AAQA,SACCC,gBADD,EAECC,YAFD,EAGCC,uBAAuB,IAAIC,SAH5B,QAIO,oBAJP;AAKA,SAASC,KAAT,QAAsB,kBAAtB;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,OAAOC,MAAP,MAAmB,WAAnB;AACA,OAAOC,UAAP,MAAuB,gBAAvB;AACA,SAASC,IAAT,EAAeC,IAAf,EAAqBC,OAArB,QAAoC,cAApC;AACA,SAASC,mBAAT,QAAoC,YAApC;AAEA;AACA;AACA;AACA;AACA;;AACA,MAAMC,SAAS,GAAG,SAAlB;AAEA,MAAMC,eAAe,GAAGhB,aAAa,EAArC;;AAEA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 'classnames';\nimport {\n\tuseFloating,\n\tflip,\n\tshift,\n\tautoUpdate,\n\tarrow,\n\toffset as offsetMiddleware,\n\tlimitShift,\n\tsize,\n} from '@floating-ui/react-dom';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseRef,\n\tuseLayoutEffect,\n\tforwardRef,\n\tcreateContext,\n\tuseContext,\n\tuseMemo,\n} from '@wordpress/element';\nimport {\n\tuseViewportMatch,\n\tuseMergeRefs,\n\t__experimentalUseDialog as useDialog,\n} from '@wordpress/compose';\nimport { close } from '@wordpress/icons';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport Button from '../button';\nimport ScrollLock from '../scroll-lock';\nimport { Slot, Fill, useSlot } from '../slot-fill';\nimport { getAnimateClassName } from '../animate';\n\n/**\n * Name of slot in which popover should fill.\n *\n * @type {string}\n */\nconst SLOT_NAME = 'Popover';\n\nconst slotNameContext = createContext();\n\nconst positionToPlacement = ( position ) => {\n\tconst [ x, y, z ] = position.split( ' ' );\n\n\tif ( [ 'top', 'bottom' ].includes( x ) ) {\n\t\tlet suffix = '';\n\t\tif ( ( !! z && z === 'left' ) || y === 'right' ) {\n\t\t\tsuffix = '-start';\n\t\t} else if ( ( !! z && z === 'right' ) || y === 'left' ) {\n\t\t\tsuffix = '-end';\n\t\t}\n\t\treturn x + suffix;\n\t}\n\n\treturn y;\n};\n\nconst placementToAnimationOrigin = ( placement ) => {\n\tconst [ a, b ] = placement.split( '-' );\n\n\tlet x, y;\n\tif ( a === 'top' || a === 'bottom' ) {\n\t\tx = a === 'top' ? 'bottom' : 'top';\n\t\ty = 'middle';\n\t\tif ( b === 'start' ) {\n\t\t\ty = 'left';\n\t\t} else if ( b === 'end' ) {\n\t\t\ty = 'right';\n\t\t}\n\t}\n\n\tif ( a === 'left' || a === 'right' ) {\n\t\tx = 'center';\n\t\ty = a === 'left' ? 'right' : 'left';\n\t\tif ( b === 'start' ) {\n\t\t\tx = 'top';\n\t\t} else if ( b === 'end' ) {\n\t\t\tx = 'bottom';\n\t\t}\n\t}\n\n\treturn x + ' ' + y;\n};\n\nconst Popover = (\n\t{\n\t\trange,\n\t\tanimate = true,\n\t\theaderTitle,\n\t\tonClose,\n\t\tchildren,\n\t\tclassName,\n\t\tnoArrow = true,\n\t\tisAlternate,\n\t\tposition,\n\t\tplacement = 'bottom-start',\n\t\toffset,\n\t\tfocusOnMount = 'firstElement',\n\t\tanchorRef,\n\t\tanchorRect,\n\t\tgetAnchorRect,\n\t\texpandOnMobile,\n\t\tonFocusOutside,\n\t\t__unstableSlotName = SLOT_NAME,\n\t\t__unstableObserveElement,\n\t\t__unstableForcePosition,\n\t\t...contentProps\n\t},\n\tref\n) => {\n\tif ( range ) {\n\t\tdeprecated( 'range prop in Popover component', {\n\t\t\tsince: '6.1',\n\t\t\tversion: '6.3',\n\t\t} );\n\t}\n\n\tconst arrowRef = useRef( null );\n\tconst isMobileViewport = useViewportMatch( 'medium', '<' );\n\tconst isExpanded = expandOnMobile && isMobileViewport;\n\tconst hasArrow = ! isExpanded && ! noArrow;\n\tconst usedPlacement = position\n\t\t? positionToPlacement( position )\n\t\t: placement;\n\n\t/**\n\t * Offsets the the position of the popover when the anchor is inside an iframe.\n\t */\n\tconst frameOffset = useMemo( () => {\n\t\tlet ownerDocument = document;\n\t\tif ( anchorRef?.top ) {\n\t\t\townerDocument = anchorRef?.top.ownerDocument;\n\t\t} else if ( anchorRef?.startContainer ) {\n\t\t\townerDocument = anchorRef.startContainer.ownerDocument;\n\t\t} else if ( anchorRef?.current ) {\n\t\t\townerDocument = anchorRef.current.ownerDocument;\n\t\t} else if ( anchorRef ) {\n\t\t\t// This one should be deprecated.\n\t\t\townerDocument = anchorRef.ownerDocument;\n\t\t} else if ( anchorRect && anchorRect?.ownerDocument ) {\n\t\t\townerDocument = anchorRect.ownerDocument;\n\t\t} else if ( getAnchorRect ) {\n\t\t\townerDocument = getAnchorRect()?.ownerDocument ?? document;\n\t\t}\n\n\t\tconst { defaultView } = ownerDocument;\n\t\tconst { frameElement } = defaultView;\n\n\t\tif ( ! frameElement || ownerDocument === document ) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst iframeRect = frameElement.getBoundingClientRect();\n\t\treturn {\n\t\t\tname: 'iframeOffset',\n\t\t\tfn( { x, y } ) {\n\t\t\t\treturn {\n\t\t\t\t\tx: x + iframeRect.left,\n\t\t\t\t\ty: y + iframeRect.top,\n\t\t\t\t};\n\t\t\t},\n\t\t};\n\t}, [ anchorRef, anchorRect, getAnchorRect ] );\n\n\tconst middlewares = [\n\t\tframeOffset,\n\t\toffset ? offsetMiddleware( offset ) : undefined,\n\t\t__unstableForcePosition ? undefined : flip(),\n\t\t__unstableForcePosition\n\t\t\t? undefined\n\t\t\t: size( {\n\t\t\t\t\tapply( { width, height } ) {\n\t\t\t\t\t\tif ( ! refs.floating.current ) return;\n\n\t\t\t\t\t\tObject.assign( refs.floating.current.firstChild.style, {\n\t\t\t\t\t\t\tmaxWidth: `${ width }px`,\n\t\t\t\t\t\t\tmaxHeight: `${ height }px`,\n\t\t\t\t\t\t\toverflow: 'auto',\n\t\t\t\t\t\t} );\n\t\t\t\t\t},\n\t\t\t } ),\n\t\t,\n\t\tshift( {\n\t\t\tcrossAxis: true,\n\t\t\tlimiter: limitShift(),\n\t\t} ),\n\t\thasArrow ? arrow( { element: arrowRef } ) : undefined,\n\t].filter( ( m ) => !! m );\n\tconst anchorRefFallback = useRef( null );\n\tconst slotName = useContext( slotNameContext ) || __unstableSlotName;\n\tconst slot = useSlot( slotName );\n\n\tconst onDialogClose = ( type, event ) => {\n\t\t// Ideally the popover should have just a single onClose prop and\n\t\t// not three props that potentially do the same thing.\n\t\tif ( type === 'focus-outside' && onFocusOutside ) {\n\t\t\tonFocusOutside( event );\n\t\t} else if ( onClose ) {\n\t\t\tonClose();\n\t\t}\n\t};\n\n\tconst [ dialogRef, dialogProps ] = useDialog( {\n\t\tfocusOnMount,\n\t\t__unstableOnClose: onDialogClose,\n\t\tonClose: onDialogClose,\n\t} );\n\n\tconst {\n\t\tx,\n\t\ty,\n\t\treference,\n\t\tfloating,\n\t\tstrategy,\n\t\trefs,\n\t\tupdate,\n\t\tplacement: placementData,\n\t\tmiddlewareData: { arrow: arrowData = {} },\n\t} = useFloating( {\n\t\tplacement: usedPlacement,\n\t\tmiddleware: middlewares,\n\t} );\n\tconst staticSide = {\n\t\ttop: 'bottom',\n\t\tright: 'left',\n\t\tbottom: 'top',\n\t\tleft: 'right',\n\t}[ placementData.split( '-' )[ 0 ] ];\n\tconst mergedRefs = useMergeRefs( [ floating, dialogRef, ref ] );\n\n\t// Updates references\n\tuseLayoutEffect( () => {\n\t\t// No ref or position have been passed\n\t\tlet usedRef;\n\t\tif ( anchorRef?.top ) {\n\t\t\tusedRef = {\n\t\t\t\tgetBoundingClientRect() {\n\t\t\t\t\tconst topRect = anchorRef.top.getBoundingClientRect();\n\t\t\t\t\tconst bottomRect = anchorRef.bottom.getBoundingClientRect();\n\t\t\t\t\treturn new window.DOMRect(\n\t\t\t\t\t\ttopRect.x,\n\t\t\t\t\t\ttopRect.y,\n\t\t\t\t\t\ttopRect.width,\n\t\t\t\t\t\tbottomRect.bottom - topRect.top\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t};\n\t\t} else if ( anchorRef?.current ) {\n\t\t\tusedRef = anchorRef.current;\n\t\t} else if ( anchorRef ) {\n\t\t\tusedRef = anchorRef;\n\t\t} else if ( anchorRect ) {\n\t\t\tusedRef = {\n\t\t\t\tgetBoundingClientRect() {\n\t\t\t\t\treturn anchorRect;\n\t\t\t\t},\n\t\t\t};\n\t\t} else if ( getAnchorRect ) {\n\t\t\tusedRef = {\n\t\t\t\tgetBoundingClientRect() {\n\t\t\t\t\tconst rect = getAnchorRect();\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...rect,\n\t\t\t\t\t\tx: rect.x ?? rect.left,\n\t\t\t\t\t\ty: rect.y ?? rect.top,\n\t\t\t\t\t\theight: rect.height ?? rect.bottom - rect.top,\n\t\t\t\t\t\twidth: rect.width ?? rect.right - rect.left,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t};\n\t\t} else if ( anchorRefFallback.current ) {\n\t\t\tusedRef = anchorRefFallback.current;\n\t\t}\n\n\t\tif ( ! usedRef ) {\n\t\t\treturn;\n\t\t}\n\n\t\treference( usedRef );\n\n\t\tif ( ! refs.floating.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn autoUpdate( usedRef, refs.floating.current, update );\n\t}, [ anchorRef, anchorRect, getAnchorRect ] );\n\n\t// This is only needed for a smoth transition when moving blocks.\n\tuseLayoutEffect( () => {\n\t\tif ( ! __unstableObserveElement ) {\n\t\t\treturn;\n\t\t}\n\t\tconst observer = new window.MutationObserver( update );\n\t\tobserver.observe( __unstableObserveElement, { attributes: true } );\n\n\t\treturn () => {\n\t\t\tobserver.disconnect();\n\t\t};\n\t}, [ __unstableObserveElement ] );\n\n\t/** @type {false | string} */\n\tconst animateClassName =\n\t\t!! animate &&\n\t\tgetAnimateClassName( {\n\t\t\ttype: 'appear',\n\t\t\torigin: placementToAnimationOrigin( placementData ),\n\t\t} );\n\n\t// Disable reason: We care to capture the _bubbled_ events from inputs\n\t// within popover as inferring close intent.\n\n\tlet content = (\n\t\t// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions\n\t\t// eslint-disable-next-line jsx-a11y/no-static-element-interactions\n\t\t<div\n\t\t\tclassName={ classnames(\n\t\t\t\t'components-popover',\n\t\t\t\tclassName,\n\t\t\t\tanimateClassName,\n\t\t\t\t{\n\t\t\t\t\t'is-expanded': isExpanded,\n\t\t\t\t\t'is-alternate': isAlternate,\n\t\t\t\t}\n\t\t\t) }\n\t\t\t{ ...contentProps }\n\t\t\tref={ mergedRefs }\n\t\t\t{ ...dialogProps }\n\t\t\ttabIndex=\"-1\"\n\t\t\tstyle={\n\t\t\t\tisExpanded\n\t\t\t\t\t? undefined\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tposition: strategy,\n\t\t\t\t\t\t\tleft: Number.isNaN( x ) ? 0 : x,\n\t\t\t\t\t\t\ttop: Number.isNaN( y ) ? 0 : y,\n\t\t\t\t\t }\n\t\t\t}\n\t\t>\n\t\t\t{ isExpanded && <ScrollLock /> }\n\t\t\t{ isExpanded && (\n\t\t\t\t<div className=\"components-popover__header\">\n\t\t\t\t\t<span className=\"components-popover__header-title\">\n\t\t\t\t\t\t{ headerTitle }\n\t\t\t\t\t</span>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tclassName=\"components-popover__close\"\n\t\t\t\t\t\ticon={ close }\n\t\t\t\t\t\tonClick={ onClose }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<div className=\"components-popover__content\">{ children }</div>\n\t\t\t{ hasArrow && (\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"components-popover__arrow\"\n\t\t\t\t\tref={ arrowRef }\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tleft:\n\t\t\t\t\t\t\t! arrowData?.x || Number.isNaN( arrowData?.x )\n\t\t\t\t\t\t\t\t? 0\n\t\t\t\t\t\t\t\t: arrowData.x,\n\t\t\t\t\t\ttop:\n\t\t\t\t\t\t\t! arrowData?.y || Number.isNaN( arrowData?.y )\n\t\t\t\t\t\t\t\t? 0\n\t\t\t\t\t\t\t\t: arrowData.y,\n\t\t\t\t\t\tright: undefined,\n\t\t\t\t\t\tbottom: undefined,\n\t\t\t\t\t\t[ staticSide ]: '-4px',\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</div>\n\t);\n\n\tif ( slot.ref ) {\n\t\tcontent = <Fill name={ slotName }>{ content }</Fill>;\n\t}\n\n\tif ( anchorRef || anchorRect ) {\n\t\treturn content;\n\t}\n\n\treturn <span ref={ anchorRefFallback }>{ content }</span>;\n};\n\nconst PopoverContainer = forwardRef( Popover );\n\nfunction PopoverSlot( { name = SLOT_NAME }, ref ) {\n\treturn (\n\t\t<Slot\n\t\t\tbubblesVirtually\n\t\t\tname={ name }\n\t\t\tclassName=\"popover-slot\"\n\t\t\tref={ ref }\n\t\t/>\n\t);\n}\n\nPopoverContainer.Slot = forwardRef( PopoverSlot );\nPopoverContainer.__unstableSlotNameProvider = slotNameContext.Provider;\n\nexport default PopoverContainer;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/popover/index.js"],"names":["classnames","useFloating","flip","shift","autoUpdate","arrow","offset","offsetMiddleware","limitShift","size","useRef","useLayoutEffect","forwardRef","createContext","useContext","useMemo","useViewportMatch","useMergeRefs","__experimentalUseDialog","useDialog","close","deprecated","Button","ScrollLock","Slot","Fill","useSlot","getAnimateClassName","SLOT_NAME","slotNameContext","positionToPlacement","position","x","y","z","split","includes","suffix","placementToAnimationOrigin","placement","a","b","Popover","ref","range","animate","headerTitle","onClose","children","className","noArrow","isAlternate","focusOnMount","anchorRef","anchorRect","getAnchorRect","expandOnMobile","onFocusOutside","__unstableSlotName","__unstableObserveElement","__unstableForcePosition","__unstableShift","contentProps","since","version","arrowRef","isMobileViewport","isExpanded","hasArrow","usedPlacement","ownerDocument","top","startContainer","current","document","frameOffset","defaultView","frameElement","undefined","iframeRect","getBoundingClientRect","name","fn","left","middlewares","apply","sizeProps","height","refs","floating","Object","assign","firstChild","style","maxHeight","overflow","crossAxis","limiter","padding","element","filter","m","anchorRefFallback","slotName","slot","onDialogClose","type","event","dialogRef","dialogProps","__unstableOnClose","reference","strategy","update","placementData","middlewareData","arrowData","middleware","staticSide","right","bottom","mergedRefs","usedRef","topRect","bottomRect","window","DOMRect","width","rect","observer","MutationObserver","observe","attributes","disconnect","addEventListener","removeEventListener","animateClassName","origin","content","Number","isNaN","PopoverContainer","PopoverSlot","__unstableSlotNameProvider","Provider"],"mappings":";;AAAA;;AACA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AACA,SACCC,WADD,EAECC,IAFD,EAGCC,KAHD,EAICC,UAJD,EAKCC,KALD,EAMCC,MAAM,IAAIC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AAF,GAAgB;AAXT;AAHT,IAvCF,CAHD;;AA+DA,MAAKd,IAAI,CAAC7D,GAAV,EAAgB;AACf+F,IAAAA,OAAO,GAAG,cAAC,IAAD;AAAM,MAAA,IAAI,EAAGnC;AAAb,OAA0BmC,OAA1B,CAAV;AACA;;AAED,MAAKrF,SAAS,IAAIC,UAAlB,EAA+B;AAC9B,WAAOoF,OAAP;AACA;;AAED,SAAO;AAAM,IAAA,GAAG,EAAGpC;AAAZ,KAAkCoC,OAAlC,CAAP;AACA,CA1TD;;AA4TA,MAAMG,gBAAgB,GAAGjI,UAAU,CAAE8B,OAAF,CAAnC;;AAEA,SAASoG,WAAT,QAA4CnG,GAA5C,EAAkD;AAAA,MAA5B;AAAEsC,IAAAA,IAAI,GAAGrD;AAAT,GAA4B;AACjD,SACC,cAAC,IAAD;AACC,IAAA,gBAAgB,MADjB;AAEC,IAAA,IAAI,EAAGqD,IAFR;AAGC,IAAA,SAAS,EAAC,cAHX;AAIC,IAAA,GAAG,EAAGtC;AAJP,IADD;AAQA;;AAEDkG,gBAAgB,CAACrH,IAAjB,GAAwBZ,UAAU,CAAEkI,WAAF,CAAlC;AACAD,gBAAgB,CAACE,0BAAjB,GAA8ClH,eAAe,CAACmH,QAA9D;AAEA,eAAeH,gBAAf","sourcesContent":["// @ts-nocheck\n/**\n * External dependencies\n */\nimport classnames from 'classnames';\nimport {\n\tuseFloating,\n\tflip,\n\tshift,\n\tautoUpdate,\n\tarrow,\n\toffset as offsetMiddleware,\n\tlimitShift,\n\tsize,\n} from '@floating-ui/react-dom';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseRef,\n\tuseLayoutEffect,\n\tforwardRef,\n\tcreateContext,\n\tuseContext,\n\tuseMemo,\n} from '@wordpress/element';\nimport {\n\tuseViewportMatch,\n\tuseMergeRefs,\n\t__experimentalUseDialog as useDialog,\n} from '@wordpress/compose';\nimport { close } from '@wordpress/icons';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport Button from '../button';\nimport ScrollLock from '../scroll-lock';\nimport { Slot, Fill, useSlot } from '../slot-fill';\nimport { getAnimateClassName } from '../animate';\n\n/**\n * Name of slot in which popover should fill.\n *\n * @type {string}\n */\nconst SLOT_NAME = 'Popover';\n\nconst slotNameContext = createContext();\n\nconst positionToPlacement = ( position ) => {\n\tconst [ x, y, z ] = position.split( ' ' );\n\n\tif ( [ 'top', 'bottom' ].includes( x ) ) {\n\t\tlet suffix = '';\n\t\tif ( ( !! z && z === 'left' ) || y === 'right' ) {\n\t\t\tsuffix = '-start';\n\t\t} else if ( ( !! z && z === 'right' ) || y === 'left' ) {\n\t\t\tsuffix = '-end';\n\t\t}\n\t\treturn x + suffix;\n\t}\n\n\treturn y;\n};\n\nconst placementToAnimationOrigin = ( placement ) => {\n\tconst [ a, b ] = placement.split( '-' );\n\n\tlet x, y;\n\tif ( a === 'top' || a === 'bottom' ) {\n\t\tx = a === 'top' ? 'bottom' : 'top';\n\t\ty = 'middle';\n\t\tif ( b === 'start' ) {\n\t\t\ty = 'left';\n\t\t} else if ( b === 'end' ) {\n\t\t\ty = 'right';\n\t\t}\n\t}\n\n\tif ( a === 'left' || a === 'right' ) {\n\t\tx = 'center';\n\t\ty = a === 'left' ? 'right' : 'left';\n\t\tif ( b === 'start' ) {\n\t\t\tx = 'top';\n\t\t} else if ( b === 'end' ) {\n\t\t\tx = 'bottom';\n\t\t}\n\t}\n\n\treturn x + ' ' + y;\n};\n\nconst Popover = (\n\t{\n\t\trange,\n\t\tanimate = true,\n\t\theaderTitle,\n\t\tonClose,\n\t\tchildren,\n\t\tclassName,\n\t\tnoArrow = true,\n\t\tisAlternate,\n\t\tposition,\n\t\tplacement = 'bottom-start',\n\t\toffset,\n\t\tfocusOnMount = 'firstElement',\n\t\tanchorRef,\n\t\tanchorRect,\n\t\tgetAnchorRect,\n\t\texpandOnMobile,\n\t\tonFocusOutside,\n\t\t__unstableSlotName = SLOT_NAME,\n\t\t__unstableObserveElement,\n\t\t__unstableForcePosition,\n\t\t__unstableShift = false,\n\t\t...contentProps\n\t},\n\tref\n) => {\n\tif ( range ) {\n\t\tdeprecated( 'range prop in Popover component', {\n\t\t\tsince: '6.1',\n\t\t\tversion: '6.3',\n\t\t} );\n\t}\n\n\tconst arrowRef = useRef( null );\n\tconst isMobileViewport = useViewportMatch( 'medium', '<' );\n\tconst isExpanded = expandOnMobile && isMobileViewport;\n\tconst hasArrow = ! isExpanded && ! noArrow;\n\tconst usedPlacement = position\n\t\t? positionToPlacement( position )\n\t\t: placement;\n\n\tconst ownerDocument = useMemo( () => {\n\t\tif ( anchorRef?.top ) {\n\t\t\treturn anchorRef?.top.ownerDocument;\n\t\t} else if ( anchorRef?.startContainer ) {\n\t\t\treturn anchorRef.startContainer.ownerDocument;\n\t\t} else if ( anchorRef?.current ) {\n\t\t\treturn anchorRef.current.ownerDocument;\n\t\t} else if ( anchorRef ) {\n\t\t\t// This one should be deprecated.\n\t\t\treturn anchorRef.ownerDocument;\n\t\t} else if ( anchorRect && anchorRect?.ownerDocument ) {\n\t\t\treturn anchorRect.ownerDocument;\n\t\t} else if ( getAnchorRect ) {\n\t\t\treturn getAnchorRect()?.ownerDocument ?? document;\n\t\t}\n\n\t\treturn document;\n\t}, [ anchorRef, anchorRect, getAnchorRect ] );\n\n\t/**\n\t * Offsets the the position of the popover when the anchor is inside an iframe.\n\t */\n\tconst frameOffset = useMemo( () => {\n\t\tconst { defaultView } = ownerDocument;\n\t\tconst { frameElement } = defaultView;\n\n\t\tif ( ! frameElement || ownerDocument === document ) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst iframeRect = frameElement.getBoundingClientRect();\n\t\treturn {\n\t\t\tname: 'iframeOffset',\n\t\t\tfn( { x, y } ) {\n\t\t\t\treturn {\n\t\t\t\t\tx: x + iframeRect.left,\n\t\t\t\t\ty: y + iframeRect.top,\n\t\t\t\t};\n\t\t\t},\n\t\t};\n\t}, [ ownerDocument ] );\n\n\tconst middlewares = [\n\t\tframeOffset,\n\t\toffset ? offsetMiddleware( offset ) : undefined,\n\t\t__unstableForcePosition ? undefined : flip(),\n\t\t__unstableForcePosition\n\t\t\t? undefined\n\t\t\t: size( {\n\t\t\t\t\tapply( sizeProps ) {\n\t\t\t\t\t\tconst { height } = sizeProps;\n\t\t\t\t\t\tif ( ! refs.floating.current ) return;\n\t\t\t\t\t\t// Reduce the height of the popover to the available space.\n\t\t\t\t\t\tObject.assign( refs.floating.current.firstChild.style, {\n\t\t\t\t\t\t\tmaxHeight: `${ height }px`,\n\t\t\t\t\t\t\toverflow: 'auto',\n\t\t\t\t\t\t} );\n\t\t\t\t\t},\n\t\t\t } ),\n\t\t__unstableShift\n\t\t\t? shift( {\n\t\t\t\t\tcrossAxis: true,\n\t\t\t\t\tlimiter: limitShift(),\n\t\t\t\t\tpadding: 1, // Necessary to avoid flickering at the edge of the viewport.\n\t\t\t } )\n\t\t\t: undefined,\n\t\thasArrow ? arrow( { element: arrowRef } ) : undefined,\n\t].filter( ( m ) => !! m );\n\tconst anchorRefFallback = useRef( null );\n\tconst slotName = useContext( slotNameContext ) || __unstableSlotName;\n\tconst slot = useSlot( slotName );\n\n\tconst onDialogClose = ( type, event ) => {\n\t\t// Ideally the popover should have just a single onClose prop and\n\t\t// not three props that potentially do the same thing.\n\t\tif ( type === 'focus-outside' && onFocusOutside ) {\n\t\t\tonFocusOutside( event );\n\t\t} else if ( onClose ) {\n\t\t\tonClose();\n\t\t}\n\t};\n\n\tconst [ dialogRef, dialogProps ] = useDialog( {\n\t\tfocusOnMount,\n\t\t__unstableOnClose: onDialogClose,\n\t\tonClose: onDialogClose,\n\t} );\n\n\tconst {\n\t\tx,\n\t\ty,\n\t\treference,\n\t\tfloating,\n\t\tstrategy,\n\t\trefs,\n\t\tupdate,\n\t\tplacement: placementData,\n\t\tmiddlewareData: { arrow: arrowData = {} },\n\t} = useFloating( {\n\t\tplacement: usedPlacement,\n\t\tmiddleware: middlewares,\n\t} );\n\tconst staticSide = {\n\t\ttop: 'bottom',\n\t\tright: 'left',\n\t\tbottom: 'top',\n\t\tleft: 'right',\n\t}[ placementData.split( '-' )[ 0 ] ];\n\tconst mergedRefs = useMergeRefs( [ floating, dialogRef, ref ] );\n\n\t// Updates references\n\tuseLayoutEffect( () => {\n\t\t// No ref or position have been passed\n\t\tlet usedRef;\n\t\tif ( anchorRef?.top ) {\n\t\t\tusedRef = {\n\t\t\t\tgetBoundingClientRect() {\n\t\t\t\t\tconst topRect = anchorRef.top.getBoundingClientRect();\n\t\t\t\t\tconst bottomRect = anchorRef.bottom.getBoundingClientRect();\n\t\t\t\t\treturn new window.DOMRect(\n\t\t\t\t\t\ttopRect.x,\n\t\t\t\t\t\ttopRect.y,\n\t\t\t\t\t\ttopRect.width,\n\t\t\t\t\t\tbottomRect.bottom - topRect.top\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t};\n\t\t} else if ( anchorRef?.current ) {\n\t\t\tusedRef = anchorRef.current;\n\t\t} else if ( anchorRef ) {\n\t\t\tusedRef = anchorRef;\n\t\t} else if ( anchorRect ) {\n\t\t\tusedRef = {\n\t\t\t\tgetBoundingClientRect() {\n\t\t\t\t\treturn anchorRect;\n\t\t\t\t},\n\t\t\t};\n\t\t} else if ( getAnchorRect ) {\n\t\t\tusedRef = {\n\t\t\t\tgetBoundingClientRect() {\n\t\t\t\t\tconst rect = getAnchorRect();\n\t\t\t\t\treturn new window.DOMRect(\n\t\t\t\t\t\trect.x ?? rect.left,\n\t\t\t\t\t\trect.y ?? rect.top,\n\t\t\t\t\t\trect.width ?? rect.right - rect.left,\n\t\t\t\t\t\trect.height ?? rect.bottom - rect.top\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t};\n\t\t} else if ( anchorRefFallback.current ) {\n\t\t\tusedRef = anchorRefFallback.current;\n\t\t}\n\n\t\tif ( ! usedRef ) {\n\t\t\treturn;\n\t\t}\n\n\t\treference( usedRef );\n\n\t\tif ( ! refs.floating.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn autoUpdate( usedRef, refs.floating.current, update );\n\t}, [ anchorRef, anchorRect, getAnchorRect ] );\n\n\t// This is only needed for a smoth transition when moving blocks.\n\tuseLayoutEffect( () => {\n\t\tif ( ! __unstableObserveElement ) {\n\t\t\treturn;\n\t\t}\n\t\tconst observer = new window.MutationObserver( update );\n\t\tobserver.observe( __unstableObserveElement, { attributes: true } );\n\n\t\treturn () => {\n\t\t\tobserver.disconnect();\n\t\t};\n\t}, [ __unstableObserveElement ] );\n\n\t// If we're using getAnchorRect, we need to update the position as we scroll the iframe.\n\tuseLayoutEffect( () => {\n\t\tif ( ownerDocument === document ) {\n\t\t\treturn;\n\t\t}\n\n\t\townerDocument.addEventListener( 'scroll', update );\n\t\treturn () => ownerDocument.removeEventListener( 'scroll', update );\n\t}, [ ownerDocument ] );\n\n\t/** @type {false | string} */\n\tconst animateClassName =\n\t\t!! animate &&\n\t\tgetAnimateClassName( {\n\t\t\ttype: 'appear',\n\t\t\torigin: placementToAnimationOrigin( placementData ),\n\t\t} );\n\n\t// Disable reason: We care to capture the _bubbled_ events from inputs\n\t// within popover as inferring close intent.\n\n\tlet content = (\n\t\t// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions\n\t\t// eslint-disable-next-line jsx-a11y/no-static-element-interactions\n\t\t<div\n\t\t\tclassName={ classnames(\n\t\t\t\t'components-popover',\n\t\t\t\tclassName,\n\t\t\t\tanimateClassName,\n\t\t\t\t{\n\t\t\t\t\t'is-expanded': isExpanded,\n\t\t\t\t\t'is-alternate': isAlternate,\n\t\t\t\t}\n\t\t\t) }\n\t\t\t{ ...contentProps }\n\t\t\tref={ mergedRefs }\n\t\t\t{ ...dialogProps }\n\t\t\ttabIndex=\"-1\"\n\t\t\tstyle={\n\t\t\t\tisExpanded\n\t\t\t\t\t? undefined\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tposition: strategy,\n\t\t\t\t\t\t\tleft: Number.isNaN( x ) ? 0 : x,\n\t\t\t\t\t\t\ttop: Number.isNaN( y ) ? 0 : y,\n\t\t\t\t\t }\n\t\t\t}\n\t\t>\n\t\t\t{ isExpanded && <ScrollLock /> }\n\t\t\t{ isExpanded && (\n\t\t\t\t<div className=\"components-popover__header\">\n\t\t\t\t\t<span className=\"components-popover__header-title\">\n\t\t\t\t\t\t{ headerTitle }\n\t\t\t\t\t</span>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tclassName=\"components-popover__close\"\n\t\t\t\t\t\ticon={ close }\n\t\t\t\t\t\tonClick={ onClose }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<div className=\"components-popover__content\">{ children }</div>\n\t\t\t{ hasArrow && (\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"components-popover__arrow\"\n\t\t\t\t\tref={ arrowRef }\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tleft:\n\t\t\t\t\t\t\t! arrowData?.x || Number.isNaN( arrowData?.x )\n\t\t\t\t\t\t\t\t? 0\n\t\t\t\t\t\t\t\t: arrowData.x,\n\t\t\t\t\t\ttop:\n\t\t\t\t\t\t\t! arrowData?.y || Number.isNaN( arrowData?.y )\n\t\t\t\t\t\t\t\t? 0\n\t\t\t\t\t\t\t\t: arrowData.y,\n\t\t\t\t\t\tright: undefined,\n\t\t\t\t\t\tbottom: undefined,\n\t\t\t\t\t\t[ staticSide ]: '-4px',\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</div>\n\t);\n\n\tif ( slot.ref ) {\n\t\tcontent = <Fill name={ slotName }>{ content }</Fill>;\n\t}\n\n\tif ( anchorRef || anchorRect ) {\n\t\treturn content;\n\t}\n\n\treturn <span ref={ anchorRefFallback }>{ content }</span>;\n};\n\nconst PopoverContainer = forwardRef( Popover );\n\nfunction PopoverSlot( { name = SLOT_NAME }, ref ) {\n\treturn (\n\t\t<Slot\n\t\t\tbubblesVirtually\n\t\t\tname={ name }\n\t\t\tclassName=\"popover-slot\"\n\t\t\tref={ ref }\n\t\t/>\n\t);\n}\n\nPopoverContainer.Slot = forwardRef( PopoverSlot );\nPopoverContainer.__unstableSlotNameProvider = slotNameContext.Provider;\n\nexport default PopoverContainer;\n"]}
|