@wordpress/dataviews 12.0.1-next.v.202602091733.0 → 12.0.1
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 +39 -1
- package/README.md +3 -1
- package/build/components/dataform-controls/color.cjs +19 -30
- package/build/components/dataform-controls/color.cjs.map +3 -3
- package/build/components/dataform-controls/date.cjs.map +1 -1
- package/build/components/dataform-controls/datetime.cjs +12 -21
- package/build/components/dataform-controls/datetime.cjs.map +2 -2
- package/build/components/dataform-layouts/card/index.cjs +112 -164
- package/build/components/dataform-layouts/card/index.cjs.map +3 -3
- package/build/components/dataform-layouts/index.cjs +1 -1
- package/build/components/dataform-layouts/index.cjs.map +1 -1
- package/build/components/dataform-layouts/normalize-form.cjs +2 -1
- package/build/components/dataform-layouts/normalize-form.cjs.map +2 -2
- package/build/components/dataform-layouts/panel/dropdown.cjs +79 -65
- package/build/components/dataform-layouts/panel/dropdown.cjs.map +3 -3
- package/build/components/dataform-layouts/panel/index.cjs +13 -177
- package/build/components/dataform-layouts/panel/index.cjs.map +3 -3
- package/build/components/dataform-layouts/panel/modal.cjs +12 -9
- package/build/components/dataform-layouts/panel/modal.cjs.map +3 -3
- package/build/components/dataform-layouts/panel/summary-button.cjs +125 -56
- package/build/components/dataform-layouts/panel/summary-button.cjs.map +3 -3
- package/build/components/dataform-layouts/panel/utils/get-first-validation-error.cjs +59 -0
- package/build/components/dataform-layouts/panel/utils/get-first-validation-error.cjs.map +7 -0
- package/build/components/dataform-layouts/panel/utils/get-label-classname.cjs +45 -0
- package/build/components/dataform-layouts/panel/utils/get-label-classname.cjs.map +7 -0
- package/build/components/dataform-layouts/panel/utils/get-label-content.cjs +36 -0
- package/build/components/dataform-layouts/panel/utils/get-label-content.cjs.map +7 -0
- package/build/components/dataform-layouts/panel/utils/use-field-from-form-field.cjs +77 -0
- package/build/components/dataform-layouts/panel/utils/use-field-from-form-field.cjs.map +7 -0
- package/build/components/dataviews-bulk-actions/index.cjs +2 -2
- package/build/components/dataviews-bulk-actions/index.cjs.map +2 -2
- package/build/components/dataviews-context/index.cjs +1 -0
- package/build/components/dataviews-context/index.cjs.map +2 -2
- package/build/components/dataviews-filters/filter.cjs.map +1 -1
- package/build/components/dataviews-filters/search-widget.cjs +25 -11
- package/build/components/dataviews-filters/search-widget.cjs.map +2 -2
- package/build/components/dataviews-filters/toggle.cjs +6 -2
- package/build/components/dataviews-filters/toggle.cjs.map +2 -2
- package/build/components/dataviews-footer/index.cjs +28 -12
- package/build/components/dataviews-footer/index.cjs.map +3 -3
- package/build/components/dataviews-item-actions/index.cjs +0 -1
- package/build/components/dataviews-item-actions/index.cjs.map +2 -2
- package/build/components/dataviews-layout/index.cjs +12 -0
- package/build/components/dataviews-layout/index.cjs.map +2 -2
- package/build/components/dataviews-layouts/activity/index.cjs +41 -26
- package/build/components/dataviews-layouts/activity/index.cjs.map +3 -3
- package/build/components/dataviews-layouts/grid/composite-grid.cjs +2 -0
- package/build/components/dataviews-layouts/grid/composite-grid.cjs.map +2 -2
- package/build/components/dataviews-layouts/grid/index.cjs +19 -14
- package/build/components/dataviews-layouts/grid/index.cjs.map +3 -3
- package/build/components/dataviews-layouts/list/index.cjs +13 -9
- package/build/components/dataviews-layouts/list/index.cjs.map +2 -2
- package/build/components/dataviews-layouts/picker-table/index.cjs +1 -1
- package/build/components/dataviews-layouts/picker-table/index.cjs.map +2 -2
- package/build/components/dataviews-layouts/table/index.cjs +40 -19
- package/build/components/dataviews-layouts/table/index.cjs.map +2 -2
- package/build/dataviews/index.cjs +9 -2
- package/build/dataviews/index.cjs.map +3 -3
- package/build/dataviews-picker/index.cjs +1 -0
- package/build/dataviews-picker/index.cjs.map +2 -2
- package/build/hooks/use-data.cjs +46 -0
- package/build/hooks/use-data.cjs.map +7 -0
- package/build/hooks/use-delayed-loading.cjs +47 -0
- package/build/hooks/use-delayed-loading.cjs.map +7 -0
- package/build/types/dataform.cjs.map +1 -1
- package/build-module/components/dataform-controls/color.mjs +24 -31
- package/build-module/components/dataform-controls/color.mjs.map +2 -2
- package/build-module/components/dataform-controls/date.mjs.map +1 -1
- package/build-module/components/dataform-controls/datetime.mjs +13 -22
- package/build-module/components/dataform-controls/datetime.mjs.map +2 -2
- package/build-module/components/dataform-layouts/card/index.mjs +113 -161
- package/build-module/components/dataform-layouts/card/index.mjs.map +3 -3
- package/build-module/components/dataform-layouts/index.mjs +1 -1
- package/build-module/components/dataform-layouts/index.mjs.map +1 -1
- package/build-module/components/dataform-layouts/normalize-form.mjs +2 -1
- package/build-module/components/dataform-layouts/normalize-form.mjs.map +2 -2
- package/build-module/components/dataform-layouts/panel/dropdown.mjs +81 -67
- package/build-module/components/dataform-layouts/panel/dropdown.mjs.map +2 -2
- package/build-module/components/dataform-layouts/panel/index.mjs +14 -178
- package/build-module/components/dataform-layouts/panel/index.mjs.map +2 -2
- package/build-module/components/dataform-layouts/panel/modal.mjs +12 -9
- package/build-module/components/dataform-layouts/panel/modal.mjs.map +2 -2
- package/build-module/components/dataform-layouts/panel/summary-button.mjs +117 -58
- package/build-module/components/dataform-layouts/panel/summary-button.mjs.map +2 -2
- package/build-module/components/dataform-layouts/panel/utils/get-first-validation-error.mjs +38 -0
- package/build-module/components/dataform-layouts/panel/utils/get-first-validation-error.mjs.map +7 -0
- package/build-module/components/dataform-layouts/panel/utils/get-label-classname.mjs +14 -0
- package/build-module/components/dataform-layouts/panel/utils/get-label-classname.mjs.map +7 -0
- package/build-module/components/dataform-layouts/panel/utils/get-label-content.mjs +15 -0
- package/build-module/components/dataform-layouts/panel/utils/get-label-content.mjs.map +7 -0
- package/build-module/components/dataform-layouts/panel/utils/use-field-from-form-field.mjs +46 -0
- package/build-module/components/dataform-layouts/panel/utils/use-field-from-form-field.mjs.map +7 -0
- package/build-module/components/dataviews-bulk-actions/index.mjs +2 -2
- package/build-module/components/dataviews-bulk-actions/index.mjs.map +2 -2
- package/build-module/components/dataviews-context/index.mjs +1 -0
- package/build-module/components/dataviews-context/index.mjs.map +2 -2
- package/build-module/components/dataviews-filters/filter.mjs.map +1 -1
- package/build-module/components/dataviews-filters/search-widget.mjs +25 -11
- package/build-module/components/dataviews-filters/search-widget.mjs.map +2 -2
- package/build-module/components/dataviews-filters/toggle.mjs +6 -2
- package/build-module/components/dataviews-filters/toggle.mjs.map +2 -2
- package/build-module/components/dataviews-footer/index.mjs +28 -12
- package/build-module/components/dataviews-footer/index.mjs.map +2 -2
- package/build-module/components/dataviews-item-actions/index.mjs +0 -1
- package/build-module/components/dataviews-item-actions/index.mjs.map +2 -2
- package/build-module/components/dataviews-layout/index.mjs +12 -0
- package/build-module/components/dataviews-layout/index.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/activity/index.mjs +41 -26
- package/build-module/components/dataviews-layouts/activity/index.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/grid/composite-grid.mjs +2 -0
- package/build-module/components/dataviews-layouts/grid/composite-grid.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/grid/index.mjs +19 -14
- package/build-module/components/dataviews-layouts/grid/index.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/list/index.mjs +13 -9
- package/build-module/components/dataviews-layouts/list/index.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/picker-table/index.mjs +1 -1
- package/build-module/components/dataviews-layouts/picker-table/index.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/table/index.mjs +40 -19
- package/build-module/components/dataviews-layouts/table/index.mjs.map +2 -2
- package/build-module/dataviews/index.mjs +9 -2
- package/build-module/dataviews/index.mjs.map +2 -2
- package/build-module/dataviews-picker/index.mjs +1 -0
- package/build-module/dataviews-picker/index.mjs.map +2 -2
- package/build-module/hooks/use-data.mjs +25 -0
- package/build-module/hooks/use-data.mjs.map +7 -0
- package/build-module/hooks/use-delayed-loading.mjs +22 -0
- package/build-module/hooks/use-delayed-loading.mjs.map +7 -0
- package/build-style/style-rtl.css +190 -31
- package/build-style/style.css +190 -31
- package/build-types/components/dataform-controls/color.d.ts.map +1 -1
- package/build-types/components/dataform-controls/datetime.d.ts.map +1 -1
- package/build-types/components/dataform-controls/utils/use-disabled-date-matchers.d.ts +16 -0
- package/build-types/components/dataform-controls/utils/use-disabled-date-matchers.d.ts.map +1 -0
- package/build-types/components/dataform-layouts/card/index.d.ts +1 -10
- package/build-types/components/dataform-layouts/card/index.d.ts.map +1 -1
- package/build-types/components/dataform-layouts/normalize-form.d.ts.map +1 -1
- package/build-types/components/dataform-layouts/panel/dropdown.d.ts +2 -13
- package/build-types/components/dataform-layouts/panel/dropdown.d.ts.map +1 -1
- package/build-types/components/dataform-layouts/panel/index.d.ts +1 -1
- package/build-types/components/dataform-layouts/panel/index.d.ts.map +1 -1
- package/build-types/components/dataform-layouts/panel/modal.d.ts +2 -11
- package/build-types/components/dataform-layouts/panel/modal.d.ts.map +1 -1
- package/build-types/components/dataform-layouts/panel/summary-button.d.ts +6 -5
- package/build-types/components/dataform-layouts/panel/summary-button.d.ts.map +1 -1
- package/build-types/components/dataform-layouts/panel/utils/get-first-validation-error.d.ts +4 -0
- package/build-types/components/dataform-layouts/panel/utils/get-first-validation-error.d.ts.map +1 -0
- package/build-types/components/dataform-layouts/panel/utils/get-label-classname.d.ts +4 -0
- package/build-types/components/dataform-layouts/panel/utils/get-label-classname.d.ts.map +1 -0
- package/build-types/components/dataform-layouts/panel/utils/get-label-content.d.ts +3 -0
- package/build-types/components/dataform-layouts/panel/utils/get-label-content.d.ts.map +1 -0
- package/build-types/components/dataform-layouts/panel/utils/use-field-from-form-field.d.ts +23 -0
- package/build-types/components/dataform-layouts/panel/utils/use-field-from-form-field.d.ts.map +1 -0
- package/build-types/components/dataviews-context/index.d.ts +1 -0
- package/build-types/components/dataviews-context/index.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/filter.d.ts +1 -1
- package/build-types/components/dataviews-filters/filter.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/search-widget.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/toggle.d.ts.map +1 -1
- package/build-types/components/dataviews-footer/index.d.ts +1 -1
- package/build-types/components/dataviews-footer/index.d.ts.map +1 -1
- package/build-types/components/dataviews-item-actions/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layout/index.d.ts +1 -1
- package/build-types/components/dataviews-layout/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/activity/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/grid/composite-grid.d.ts +2 -1
- package/build-types/components/dataviews-layouts/grid/composite-grid.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/grid/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/list/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/picker-activity/index.d.ts +3 -0
- package/build-types/components/dataviews-layouts/picker-activity/index.d.ts.map +1 -0
- package/build-types/components/dataviews-layouts/table/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/table/use-scroll-state.d.ts +25 -0
- package/build-types/components/dataviews-layouts/table/use-scroll-state.d.ts.map +1 -0
- package/build-types/components/dataviews-layouts/utils/grid-config-options.d.ts +2 -0
- package/build-types/components/dataviews-layouts/utils/grid-config-options.d.ts.map +1 -0
- package/build-types/components/dataviews-layouts/utils/use-infinite-scroll.d.ts +22 -0
- package/build-types/components/dataviews-layouts/utils/use-infinite-scroll.d.ts.map +1 -0
- package/build-types/dataform/stories/index.story.d.ts +9 -1
- package/build-types/dataform/stories/index.story.d.ts.map +1 -1
- package/build-types/dataform/stories/layout-panel.d.ts +3 -1
- package/build-types/dataform/stories/layout-panel.d.ts.map +1 -1
- package/build-types/dataviews/index.d.ts.map +1 -1
- package/build-types/dataviews/stories/empty.d.ts.map +1 -1
- package/build-types/dataviews/stories/fixtures.d.ts +1 -0
- package/build-types/dataviews/stories/fixtures.d.ts.map +1 -1
- package/build-types/dataviews/stories/free-composition.d.ts.map +1 -1
- package/build-types/dataviews/stories/layout-table.d.ts.map +1 -1
- package/build-types/dataviews/stories/minimal-ui.d.ts.map +1 -1
- package/build-types/dataviews/stories/with-card.d.ts.map +1 -1
- package/build-types/dataviews-picker/index.d.ts.map +1 -1
- package/build-types/field-types/utils/is-valid-date-boundary.d.ts +7 -0
- package/build-types/field-types/utils/is-valid-date-boundary.d.ts.map +1 -0
- package/build-types/hooks/test/use-data.d.ts +2 -0
- package/build-types/hooks/test/use-data.d.ts.map +1 -0
- package/build-types/hooks/use-data.d.ts +12 -0
- package/build-types/hooks/use-data.d.ts.map +1 -0
- package/build-types/hooks/use-delayed-loading.d.ts +4 -0
- package/build-types/hooks/use-delayed-loading.d.ts.map +1 -0
- package/build-types/hooks/use-infinite-scroll.d.ts +21 -0
- package/build-types/hooks/use-infinite-scroll.d.ts.map +1 -0
- package/build-types/hooks/use-selected-items.d.ts +19 -0
- package/build-types/hooks/use-selected-items.d.ts.map +1 -0
- package/build-types/types/dataform.d.ts +3 -0
- package/build-types/types/dataform.d.ts.map +1 -1
- package/build-wp/index.js +2898 -2198
- package/package.json +21 -21
- package/src/components/dataform-controls/color.tsx +29 -36
- package/src/components/dataform-controls/date.tsx +2 -2
- package/src/components/dataform-controls/datetime.tsx +19 -34
- package/src/components/dataform-controls/style.scss +4 -0
- package/src/components/dataform-layouts/card/index.tsx +118 -185
- package/src/components/dataform-layouts/index.tsx +1 -1
- package/src/components/dataform-layouts/normalize-form.ts +1 -0
- package/src/components/dataform-layouts/panel/dropdown.tsx +95 -96
- package/src/components/dataform-layouts/panel/index.tsx +10 -245
- package/src/components/dataform-layouts/panel/modal.tsx +16 -20
- package/src/components/dataform-layouts/panel/style.scss +110 -27
- package/src/components/dataform-layouts/panel/summary-button.tsx +140 -62
- package/src/components/dataform-layouts/panel/utils/get-first-validation-error.ts +47 -0
- package/src/components/dataform-layouts/panel/utils/get-label-classname.ts +18 -0
- package/src/components/dataform-layouts/panel/utils/get-label-content.tsx +24 -0
- package/src/components/dataform-layouts/panel/utils/use-field-from-form-field.ts +78 -0
- package/src/components/dataform-layouts/regular/style.scss +7 -0
- package/src/components/dataform-layouts/test/normalize-form.ts +5 -0
- package/src/components/dataviews-bulk-actions/index.tsx +2 -2
- package/src/components/dataviews-context/index.ts +2 -0
- package/src/components/dataviews-filters/filter.tsx +1 -1
- package/src/components/dataviews-filters/search-widget.tsx +10 -2
- package/src/components/dataviews-filters/style.scss +8 -0
- package/src/components/dataviews-filters/toggle.tsx +10 -3
- package/src/components/dataviews-footer/index.tsx +39 -12
- package/src/components/dataviews-footer/style.scss +6 -1
- package/src/components/dataviews-item-actions/index.tsx +0 -3
- package/src/components/dataviews-item-actions/style.scss +7 -0
- package/src/components/dataviews-layout/index.tsx +24 -0
- package/src/components/dataviews-layouts/activity/index.tsx +29 -22
- package/src/components/dataviews-layouts/activity/style.scss +5 -0
- package/src/components/dataviews-layouts/grid/composite-grid.tsx +5 -1
- package/src/components/dataviews-layouts/grid/index.tsx +19 -22
- package/src/components/dataviews-layouts/grid/style.scss +5 -0
- package/src/components/dataviews-layouts/list/index.tsx +18 -18
- package/src/components/dataviews-layouts/list/style.scss +5 -0
- package/src/components/dataviews-layouts/picker-table/index.tsx +1 -1
- package/src/components/dataviews-layouts/table/index.tsx +48 -22
- package/src/components/dataviews-layouts/table/style.scss +8 -2
- package/src/dataform/stories/index.story.tsx +5 -0
- package/src/dataform/stories/layout-panel.tsx +19 -2
- package/src/dataform/test/dataform.tsx +2 -2
- package/src/dataviews/index.tsx +11 -3
- package/src/dataviews/stories/empty.tsx +1 -7
- package/src/dataviews/stories/fixtures.tsx +89 -0
- package/src/dataviews/stories/free-composition.tsx +0 -5
- package/src/dataviews/stories/layout-table.tsx +1 -7
- package/src/dataviews/stories/minimal-ui.tsx +0 -5
- package/src/dataviews/stories/with-card.tsx +1 -7
- package/src/dataviews/style.scss +25 -0
- package/src/dataviews-picker/index.tsx +2 -1
- package/src/hooks/use-data.ts +45 -0
- package/src/hooks/use-delayed-loading.ts +21 -0
- package/src/types/dataform.ts +4 -0
|
@@ -1,74 +1,133 @@
|
|
|
1
1
|
// packages/dataviews/src/components/dataform-layouts/panel/summary-button.tsx
|
|
2
|
-
import
|
|
2
|
+
import clsx from "clsx";
|
|
3
|
+
import { Button, Icon, Tooltip } from "@wordpress/components";
|
|
3
4
|
import { sprintf, _x } from "@wordpress/i18n";
|
|
4
|
-
import {
|
|
5
|
+
import { error as errorIcon, pencil } from "@wordpress/icons";
|
|
6
|
+
import { useInstanceId } from "@wordpress/compose";
|
|
7
|
+
import { useRef } from "@wordpress/element";
|
|
8
|
+
import getLabelClassName from "./utils/get-label-classname.mjs";
|
|
9
|
+
import getLabelContent from "./utils/get-label-content.mjs";
|
|
10
|
+
import getFirstValidationError from "./utils/get-first-validation-error.mjs";
|
|
11
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
12
|
function SummaryButton({
|
|
6
|
-
summaryFields,
|
|
7
13
|
data,
|
|
8
|
-
|
|
14
|
+
field,
|
|
9
15
|
fieldLabel,
|
|
16
|
+
summaryFields,
|
|
17
|
+
validity,
|
|
18
|
+
touched,
|
|
10
19
|
disabled,
|
|
11
20
|
onClick,
|
|
12
21
|
"aria-expanded": ariaExpanded
|
|
13
22
|
}) {
|
|
14
|
-
|
|
15
|
-
|
|
23
|
+
const { labelPosition, editVisibility } = field.layout;
|
|
24
|
+
const errorMessage = getFirstValidationError(validity);
|
|
25
|
+
const showError = touched && !!errorMessage;
|
|
26
|
+
const labelClassName = getLabelClassName(labelPosition, showError);
|
|
27
|
+
const labelContent = getLabelContent(showError, errorMessage, fieldLabel);
|
|
28
|
+
const className = clsx(
|
|
29
|
+
"dataforms-layouts-panel__field-trigger",
|
|
30
|
+
`dataforms-layouts-panel__field-trigger--label-${labelPosition}`,
|
|
31
|
+
{
|
|
32
|
+
"is-disabled": disabled,
|
|
33
|
+
"dataforms-layouts-panel__field-trigger--edit-always": editVisibility === "always"
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
const controlId = useInstanceId(
|
|
37
|
+
SummaryButton,
|
|
38
|
+
"dataforms-layouts-panel__field-control"
|
|
39
|
+
);
|
|
40
|
+
const ariaLabel = showError ? sprintf(
|
|
41
|
+
// translators: %s: Field name.
|
|
42
|
+
_x("Edit %s (has errors)", "field"),
|
|
43
|
+
fieldLabel || ""
|
|
44
|
+
) : sprintf(
|
|
45
|
+
// translators: %s: Field name.
|
|
46
|
+
_x("Edit %s", "field"),
|
|
47
|
+
fieldLabel || ""
|
|
48
|
+
);
|
|
49
|
+
const rowRef = useRef(null);
|
|
50
|
+
const handleRowClick = () => {
|
|
51
|
+
const selection = rowRef.current?.ownerDocument.defaultView?.getSelection();
|
|
52
|
+
if (selection && selection.toString().length > 0) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
onClick();
|
|
56
|
+
};
|
|
57
|
+
const handleKeyDown = (event) => {
|
|
58
|
+
if (event.target === event.currentTarget && (event.key === "Enter" || event.key === " ")) {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
onClick();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
return /* @__PURE__ */ jsxs(
|
|
64
|
+
"div",
|
|
16
65
|
{
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
ref: rowRef,
|
|
67
|
+
className,
|
|
68
|
+
onClick: !disabled ? handleRowClick : void 0,
|
|
69
|
+
onKeyDown: !disabled ? handleKeyDown : void 0,
|
|
70
|
+
children: [
|
|
71
|
+
labelPosition !== "none" && /* @__PURE__ */ jsx("span", { className: labelClassName, children: labelContent }),
|
|
72
|
+
labelPosition === "none" && showError && /* @__PURE__ */ jsx(Tooltip, { text: errorMessage, placement: "top", children: /* @__PURE__ */ jsx("span", { className: "dataforms-layouts-panel__field-label-error-content", children: /* @__PURE__ */ jsx(Icon, { icon: errorIcon, size: 16 }) }) }),
|
|
73
|
+
/* @__PURE__ */ jsx(
|
|
74
|
+
"span",
|
|
75
|
+
{
|
|
76
|
+
id: `${controlId}`,
|
|
77
|
+
className: "dataforms-layouts-panel__field-control",
|
|
78
|
+
children: summaryFields.length > 1 ? /* @__PURE__ */ jsx(
|
|
79
|
+
"span",
|
|
80
|
+
{
|
|
81
|
+
style: {
|
|
82
|
+
display: "flex",
|
|
83
|
+
flexDirection: "column",
|
|
84
|
+
alignItems: "flex-start",
|
|
85
|
+
width: "100%",
|
|
86
|
+
gap: "2px"
|
|
87
|
+
},
|
|
88
|
+
children: summaryFields.map((summaryField) => /* @__PURE__ */ jsx(
|
|
89
|
+
"span",
|
|
90
|
+
{
|
|
91
|
+
style: { width: "100%" },
|
|
92
|
+
children: /* @__PURE__ */ jsx(
|
|
93
|
+
summaryField.render,
|
|
94
|
+
{
|
|
95
|
+
item: data,
|
|
96
|
+
field: summaryField
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
},
|
|
100
|
+
summaryField.id
|
|
101
|
+
))
|
|
102
|
+
}
|
|
103
|
+
) : summaryFields.map((summaryField) => /* @__PURE__ */ jsx(
|
|
104
|
+
summaryField.render,
|
|
105
|
+
{
|
|
106
|
+
item: data,
|
|
107
|
+
field: summaryField
|
|
108
|
+
},
|
|
109
|
+
summaryField.id
|
|
110
|
+
))
|
|
111
|
+
}
|
|
112
|
+
),
|
|
113
|
+
!disabled && /* @__PURE__ */ jsx(
|
|
114
|
+
Button,
|
|
115
|
+
{
|
|
116
|
+
className: "dataforms-layouts-panel__field-trigger-icon",
|
|
117
|
+
label: ariaLabel,
|
|
118
|
+
showTooltip: false,
|
|
119
|
+
icon: pencil,
|
|
120
|
+
size: "small",
|
|
121
|
+
"aria-expanded": ariaExpanded,
|
|
122
|
+
"aria-haspopup": "dialog",
|
|
123
|
+
"aria-describedby": `${controlId}`
|
|
124
|
+
}
|
|
125
|
+
)
|
|
126
|
+
]
|
|
67
127
|
}
|
|
68
128
|
);
|
|
69
129
|
}
|
|
70
|
-
var summary_button_default = SummaryButton;
|
|
71
130
|
export {
|
|
72
|
-
|
|
131
|
+
SummaryButton as default
|
|
73
132
|
};
|
|
74
133
|
//# sourceMappingURL=summary-button.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/dataform-layouts/panel/summary-button.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Button } from '@wordpress/components';\nimport { sprintf, _x } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type {
|
|
5
|
-
"mappings": ";AAGA,SAAS,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { Button, Icon, Tooltip } from '@wordpress/components';\nimport { sprintf, _x } from '@wordpress/i18n';\nimport { error as errorIcon, pencil } from '@wordpress/icons';\nimport { useInstanceId } from '@wordpress/compose';\nimport { useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tFieldValidity,\n\tNormalizedField,\n\tNormalizedFormField,\n\tNormalizedPanelLayout,\n} from '../../../types';\nimport getLabelClassName from './utils/get-label-classname';\nimport getLabelContent from './utils/get-label-content';\nimport getFirstValidationError from './utils/get-first-validation-error';\n\nexport default function SummaryButton< Item >( {\n\tdata,\n\tfield,\n\tfieldLabel,\n\tsummaryFields,\n\tvalidity,\n\ttouched,\n\tdisabled,\n\tonClick,\n\t'aria-expanded': ariaExpanded,\n}: {\n\tdata: Item;\n\tfield: NormalizedFormField;\n\tfieldLabel?: string;\n\tsummaryFields: NormalizedField< Item >[];\n\tvalidity?: FieldValidity;\n\ttouched: boolean;\n\tdisabled?: boolean;\n\tonClick: () => void;\n\t'aria-expanded'?: boolean;\n} ) {\n\tconst { labelPosition, editVisibility } =\n\t\tfield.layout as NormalizedPanelLayout;\n\tconst errorMessage = getFirstValidationError( validity );\n\tconst showError = touched && !! errorMessage;\n\tconst labelClassName = getLabelClassName( labelPosition, showError );\n\tconst labelContent = getLabelContent( showError, errorMessage, fieldLabel );\n\tconst className = clsx(\n\t\t'dataforms-layouts-panel__field-trigger',\n\t\t`dataforms-layouts-panel__field-trigger--label-${ labelPosition }`,\n\t\t{\n\t\t\t'is-disabled': disabled,\n\t\t\t'dataforms-layouts-panel__field-trigger--edit-always':\n\t\t\t\teditVisibility === 'always',\n\t\t}\n\t);\n\n\tconst controlId = useInstanceId(\n\t\tSummaryButton,\n\t\t'dataforms-layouts-panel__field-control'\n\t);\n\n\tconst ariaLabel = showError\n\t\t? sprintf(\n\t\t\t\t// translators: %s: Field name.\n\t\t\t\t_x( 'Edit %s (has errors)', 'field' ),\n\t\t\t\tfieldLabel || ''\n\t\t )\n\t\t: sprintf(\n\t\t\t\t// translators: %s: Field name.\n\t\t\t\t_x( 'Edit %s', 'field' ),\n\t\t\t\tfieldLabel || ''\n\t\t );\n\n\tconst rowRef = useRef< HTMLDivElement >( null );\n\n\tconst handleRowClick = () => {\n\t\tconst selection =\n\t\t\trowRef.current?.ownerDocument.defaultView?.getSelection();\n\t\tif ( selection && selection.toString().length > 0 ) {\n\t\t\treturn;\n\t\t}\n\t\tonClick();\n\t};\n\n\tconst handleKeyDown = ( event: React.KeyboardEvent ) => {\n\t\tif (\n\t\t\tevent.target === event.currentTarget &&\n\t\t\t( event.key === 'Enter' || event.key === ' ' )\n\t\t) {\n\t\t\tevent.preventDefault();\n\t\t\tonClick();\n\t\t}\n\t};\n\n\treturn (\n\t\t<div\n\t\t\tref={ rowRef }\n\t\t\tclassName={ className }\n\t\t\tonClick={ ! disabled ? handleRowClick : undefined }\n\t\t\tonKeyDown={ ! disabled ? handleKeyDown : undefined }\n\t\t>\n\t\t\t{ labelPosition !== 'none' && (\n\t\t\t\t<span className={ labelClassName }>{ labelContent }</span>\n\t\t\t) }\n\t\t\t{ labelPosition === 'none' && showError && (\n\t\t\t\t<Tooltip text={ errorMessage } placement=\"top\">\n\t\t\t\t\t<span className=\"dataforms-layouts-panel__field-label-error-content\">\n\t\t\t\t\t\t<Icon icon={ errorIcon } size={ 16 } />\n\t\t\t\t\t</span>\n\t\t\t\t</Tooltip>\n\t\t\t) }\n\t\t\t<span\n\t\t\t\tid={ `${ controlId }` }\n\t\t\t\tclassName=\"dataforms-layouts-panel__field-control\"\n\t\t\t>\n\t\t\t\t{ summaryFields.length > 1 ? (\n\t\t\t\t\t<span\n\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\tdisplay: 'flex',\n\t\t\t\t\t\t\tflexDirection: 'column',\n\t\t\t\t\t\t\talignItems: 'flex-start',\n\t\t\t\t\t\t\twidth: '100%',\n\t\t\t\t\t\t\tgap: '2px',\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ summaryFields.map( ( summaryField ) => (\n\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\tkey={ summaryField.id }\n\t\t\t\t\t\t\t\tstyle={ { width: '100%' } }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<summaryField.render\n\t\t\t\t\t\t\t\t\titem={ data }\n\t\t\t\t\t\t\t\t\tfield={ summaryField }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t) ) }\n\t\t\t\t\t</span>\n\t\t\t\t) : (\n\t\t\t\t\tsummaryFields.map( ( summaryField ) => (\n\t\t\t\t\t\t<summaryField.render\n\t\t\t\t\t\t\tkey={ summaryField.id }\n\t\t\t\t\t\t\titem={ data }\n\t\t\t\t\t\t\tfield={ summaryField }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) )\n\t\t\t\t) }\n\t\t\t</span>\n\t\t\t{ ! disabled && (\n\t\t\t\t<Button\n\t\t\t\t\tclassName=\"dataforms-layouts-panel__field-trigger-icon\"\n\t\t\t\t\tlabel={ ariaLabel }\n\t\t\t\t\tshowTooltip={ false }\n\t\t\t\t\ticon={ pencil }\n\t\t\t\t\tsize=\"small\"\n\t\t\t\t\taria-expanded={ ariaExpanded }\n\t\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t\t\taria-describedby={ `${ controlId }` }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,QAAQ,MAAM,eAAe;AACtC,SAAS,SAAS,UAAU;AAC5B,SAAS,SAAS,WAAW,cAAc;AAC3C,SAAS,qBAAqB;AAC9B,SAAS,cAAc;AAWvB,OAAO,uBAAuB;AAC9B,OAAO,qBAAqB;AAC5B,OAAO,6BAA6B;AA8ElC,SAOE,KAPF;AA5Ea,SAAR,cAAwC;AAAA,EAC9C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,iBAAiB;AAClB,GAUI;AACH,QAAM,EAAE,eAAe,eAAe,IACrC,MAAM;AACP,QAAM,eAAe,wBAAyB,QAAS;AACvD,QAAM,YAAY,WAAW,CAAC,CAAE;AAChC,QAAM,iBAAiB,kBAAmB,eAAe,SAAU;AACnE,QAAM,eAAe,gBAAiB,WAAW,cAAc,UAAW;AAC1E,QAAM,YAAY;AAAA,IACjB;AAAA,IACA,iDAAkD,aAAc;AAAA,IAChE;A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gBAEE,wBAAc,IAAK,CAAE,iBACtB;AAAA,kBAAC;AAAA;AAAA,oBAEA,OAAQ,EAAE,OAAO,OAAO;AAAA,oBAExB;AAAA,sBAAC,aAAa;AAAA,sBAAb;AAAA,wBACA,MAAO;AAAA,wBACP,OAAQ;AAAA;AAAA,oBACT;AAAA;AAAA,kBANM,aAAa;AAAA,gBAOpB,CACC;AAAA;AAAA,YACH,IAEA,cAAc,IAAK,CAAE,iBACpB;AAAA,cAAC,aAAa;AAAA,cAAb;AAAA,gBAEA,MAAO;AAAA,gBACP,OAAQ;AAAA;AAAA,cAFF,aAAa;AAAA,YAGpB,CACC;AAAA;AAAA,QAEJ;AAAA,QACE,CAAE,YACH;AAAA,UAAC;AAAA;AAAA,YACA,WAAU;AAAA,YACV,OAAQ;AAAA,YACR,aAAc;AAAA,YACd,MAAO;AAAA,YACP,MAAK;AAAA,YACL,iBAAgB;AAAA,YAChB,iBAAc;AAAA,YACd,oBAAmB,GAAI,SAAU;AAAA;AAAA,QAClC;AAAA;AAAA;AAAA,EAEF;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// packages/dataviews/src/components/dataform-layouts/panel/utils/get-first-validation-error.ts
|
|
2
|
+
function getFirstValidationError(validity) {
|
|
3
|
+
if (!validity) {
|
|
4
|
+
return void 0;
|
|
5
|
+
}
|
|
6
|
+
const validityRules = Object.keys(validity).filter(
|
|
7
|
+
(key) => key !== "children"
|
|
8
|
+
);
|
|
9
|
+
for (const key of validityRules) {
|
|
10
|
+
const rule = validity[key];
|
|
11
|
+
if (rule === void 0) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if (rule.type === "invalid") {
|
|
15
|
+
if (rule.message) {
|
|
16
|
+
return rule.message;
|
|
17
|
+
}
|
|
18
|
+
if (key === "required") {
|
|
19
|
+
return "A required field is empty";
|
|
20
|
+
}
|
|
21
|
+
return "Unidentified validation error";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (validity.children) {
|
|
25
|
+
for (const childValidity of Object.values(validity.children)) {
|
|
26
|
+
const childError = getFirstValidationError(childValidity);
|
|
27
|
+
if (childError) {
|
|
28
|
+
return childError;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return void 0;
|
|
33
|
+
}
|
|
34
|
+
var get_first_validation_error_default = getFirstValidationError;
|
|
35
|
+
export {
|
|
36
|
+
get_first_validation_error_default as default
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=get-first-validation-error.mjs.map
|
package/build-module/components/dataform-layouts/panel/utils/get-first-validation-error.mjs.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/components/dataform-layouts/panel/utils/get-first-validation-error.ts"],
|
|
4
|
+
"sourcesContent": ["import type { FieldValidity } from '../../../../types';\n\nfunction getFirstValidationError(\n\tvalidity: FieldValidity | undefined\n): string | undefined {\n\tif ( ! validity ) {\n\t\treturn undefined;\n\t}\n\n\tconst validityRules = Object.keys( validity ).filter(\n\t\t( key ) => key !== 'children'\n\t);\n\n\tfor ( const key of validityRules ) {\n\t\tconst rule = validity[ key as keyof Omit< FieldValidity, 'children' > ];\n\t\tif ( rule === undefined ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif ( rule.type === 'invalid' ) {\n\t\t\tif ( rule.message ) {\n\t\t\t\treturn rule.message;\n\t\t\t}\n\n\t\t\t// Provide default message for required validation (message is optional)\n\t\t\tif ( key === 'required' ) {\n\t\t\t\treturn 'A required field is empty';\n\t\t\t}\n\n\t\t\treturn 'Unidentified validation error';\n\t\t}\n\t}\n\n\t// Check children recursively\n\tif ( validity.children ) {\n\t\tfor ( const childValidity of Object.values( validity.children ) ) {\n\t\t\tconst childError = getFirstValidationError( childValidity );\n\t\t\tif ( childError ) {\n\t\t\t\treturn childError;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\nexport default getFirstValidationError;\n"],
|
|
5
|
+
"mappings": ";AAEA,SAAS,wBACR,UACqB;AACrB,MAAK,CAAE,UAAW;AACjB,WAAO;AAAA,EACR;AAEA,QAAM,gBAAgB,OAAO,KAAM,QAAS,EAAE;AAAA,IAC7C,CAAE,QAAS,QAAQ;AAAA,EACpB;AAEA,aAAY,OAAO,eAAgB;AAClC,UAAM,OAAO,SAAU,GAA+C;AACtE,QAAK,SAAS,QAAY;AACzB;AAAA,IACD;AAEA,QAAK,KAAK,SAAS,WAAY;AAC9B,UAAK,KAAK,SAAU;AACnB,eAAO,KAAK;AAAA,MACb;AAGA,UAAK,QAAQ,YAAa;AACzB,eAAO;AAAA,MACR;AAEA,aAAO;AAAA,IACR;AAAA,EACD;AAGA,MAAK,SAAS,UAAW;AACxB,eAAY,iBAAiB,OAAO,OAAQ,SAAS,QAAS,GAAI;AACjE,YAAM,aAAa,wBAAyB,aAAc;AAC1D,UAAK,YAAa;AACjB,eAAO;AAAA,MACR;AAAA,IACD;AAAA,EACD;AAEA,SAAO;AACR;AAEA,IAAO,qCAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// packages/dataviews/src/components/dataform-layouts/panel/utils/get-label-classname.ts
|
|
2
|
+
import clsx from "clsx";
|
|
3
|
+
function getLabelClassName(labelPosition, showError) {
|
|
4
|
+
return clsx(
|
|
5
|
+
"dataforms-layouts-panel__field-label",
|
|
6
|
+
`dataforms-layouts-panel__field-label--label-position-${labelPosition}`,
|
|
7
|
+
{ "has-error": showError }
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
var get_label_classname_default = getLabelClassName;
|
|
11
|
+
export {
|
|
12
|
+
get_label_classname_default as default
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=get-label-classname.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/components/dataform-layouts/panel/utils/get-label-classname.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport type { LabelPosition } from '../../../../types';\n\nfunction getLabelClassName(\n\tlabelPosition: LabelPosition,\n\tshowError?: boolean\n) {\n\treturn clsx(\n\t\t'dataforms-layouts-panel__field-label',\n\t\t`dataforms-layouts-panel__field-label--label-position-${ labelPosition }`,\n\t\t{ 'has-error': showError }\n\t);\n}\n\nexport default getLabelClassName;\n"],
|
|
5
|
+
"mappings": ";AAGA,OAAO,UAAU;AAGjB,SAAS,kBACR,eACA,WACC;AACD,SAAO;AAAA,IACN;AAAA,IACA,wDAAyD,aAAc;AAAA,IACvE,EAAE,aAAa,UAAU;AAAA,EAC1B;AACD;AAEA,IAAO,8BAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// packages/dataviews/src/components/dataform-layouts/panel/utils/get-label-content.tsx
|
|
2
|
+
import { Icon, Tooltip } from "@wordpress/components";
|
|
3
|
+
import { error as errorIcon } from "@wordpress/icons";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
function getLabelContent(showError, errorMessage, fieldLabel) {
|
|
6
|
+
return showError ? /* @__PURE__ */ jsx(Tooltip, { text: errorMessage, placement: "top", children: /* @__PURE__ */ jsxs("span", { className: "dataforms-layouts-panel__field-label-error-content", children: [
|
|
7
|
+
/* @__PURE__ */ jsx(Icon, { icon: errorIcon, size: 16 }),
|
|
8
|
+
fieldLabel
|
|
9
|
+
] }) }) : fieldLabel;
|
|
10
|
+
}
|
|
11
|
+
var get_label_content_default = getLabelContent;
|
|
12
|
+
export {
|
|
13
|
+
get_label_content_default as default
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=get-label-content.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/components/dataform-layouts/panel/utils/get-label-content.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Icon, Tooltip } from '@wordpress/components';\nimport { error as errorIcon } from '@wordpress/icons';\n\nfunction getLabelContent(\n\tshowError?: boolean,\n\terrorMessage?: string,\n\tfieldLabel?: string\n) {\n\treturn showError ? (\n\t\t<Tooltip text={ errorMessage } placement=\"top\">\n\t\t\t<span className=\"dataforms-layouts-panel__field-label-error-content\">\n\t\t\t\t<Icon icon={ errorIcon } size={ 16 } />\n\t\t\t\t{ fieldLabel }\n\t\t\t</span>\n\t\t</Tooltip>\n\t) : (\n\t\tfieldLabel\n\t);\n}\n\nexport default getLabelContent;\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,MAAM,eAAe;AAC9B,SAAS,SAAS,iBAAiB;AAShC,SACC,KADD;AAPH,SAAS,gBACR,WACA,cACA,YACC;AACD,SAAO,YACN,oBAAC,WAAQ,MAAO,cAAe,WAAU,OACxC,+BAAC,UAAK,WAAU,sDACf;AAAA,wBAAC,QAAK,MAAO,WAAY,MAAO,IAAK;AAAA,IACnC;AAAA,KACH,GACD,IAEA;AAEF;AAEA,IAAO,4BAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// packages/dataviews/src/components/dataform-layouts/panel/utils/use-field-from-form-field.ts
|
|
2
|
+
import { useContext } from "@wordpress/element";
|
|
3
|
+
import { getSummaryFields } from "../../get-summary-fields.mjs";
|
|
4
|
+
import DataFormContext from "../../../dataform-context/index.mjs";
|
|
5
|
+
var getFieldDefinition = (field, fields) => {
|
|
6
|
+
const fieldDefinition = fields.find((_field) => _field.id === field.id);
|
|
7
|
+
if (!fieldDefinition) {
|
|
8
|
+
return fields.find((_field) => {
|
|
9
|
+
if (!!field.children) {
|
|
10
|
+
const simpleChildren = field.children.filter(
|
|
11
|
+
(child) => !child.children
|
|
12
|
+
);
|
|
13
|
+
if (simpleChildren.length === 0) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return _field.id === simpleChildren[0].id;
|
|
17
|
+
}
|
|
18
|
+
return _field.id === field.id;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return fieldDefinition;
|
|
22
|
+
};
|
|
23
|
+
function useFieldFromFormField(field) {
|
|
24
|
+
const { fields } = useContext(DataFormContext);
|
|
25
|
+
const layout = field.layout;
|
|
26
|
+
const summaryFields = getSummaryFields(layout.summary, fields);
|
|
27
|
+
const fieldDefinition = getFieldDefinition(field, fields);
|
|
28
|
+
const fieldLabel = !!field.children ? field.label : fieldDefinition?.label;
|
|
29
|
+
if (summaryFields.length === 0) {
|
|
30
|
+
return {
|
|
31
|
+
summaryFields: fieldDefinition ? [fieldDefinition] : [],
|
|
32
|
+
fieldDefinition,
|
|
33
|
+
fieldLabel
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
summaryFields,
|
|
38
|
+
fieldDefinition,
|
|
39
|
+
fieldLabel
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
var use_field_from_form_field_default = useFieldFromFormField;
|
|
43
|
+
export {
|
|
44
|
+
use_field_from_form_field_default as default
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=use-field-from-form-field.mjs.map
|
package/build-module/components/dataform-layouts/panel/utils/use-field-from-form-field.mjs.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/components/dataform-layouts/panel/utils/use-field-from-form-field.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tNormalizedFormField,\n\tNormalizedField,\n\tNormalizedPanelLayout,\n} from '../../../../types';\nimport { getSummaryFields } from '../../get-summary-fields';\nimport DataFormContext from '../../../dataform-context';\n\nconst getFieldDefinition = < Item >(\n\tfield: NormalizedFormField,\n\tfields: NormalizedField< Item >[]\n) => {\n\tconst fieldDefinition = fields.find( ( _field ) => _field.id === field.id );\n\n\tif ( ! fieldDefinition ) {\n\t\treturn fields.find( ( _field ) => {\n\t\t\tif ( !! field.children ) {\n\t\t\t\tconst simpleChildren = field.children.filter(\n\t\t\t\t\t( child ) => ! child.children\n\t\t\t\t);\n\n\t\t\t\tif ( simpleChildren.length === 0 ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\treturn _field.id === simpleChildren[ 0 ].id;\n\t\t\t}\n\n\t\t\treturn _field.id === field.id;\n\t\t} );\n\t}\n\n\treturn fieldDefinition;\n};\n\n/**\n * Determines the field definition and summary fields for a panel layout.\n *\n * Summary fields are determined with the following priority:\n * 1. Use layout.summary fields if they exist\n * 2. Fall back to the field definition that matches the form field's id\n * 3. If the form field id doesn't exist, pick the first child field\n * 4. If no field definition is found, return empty summary fields\n *\n * @param field The form field to get definition for\n * @return Object containing fieldDefinition, fieldLabel, and summaryFields\n */\nfunction useFieldFromFormField( field: NormalizedFormField ) {\n\tconst { fields } = useContext( DataFormContext );\n\tconst layout = field.layout as NormalizedPanelLayout;\n\tconst summaryFields = getSummaryFields( layout.summary, fields );\n\tconst fieldDefinition = getFieldDefinition( field, fields );\n\tconst fieldLabel = !! field.children ? field.label : fieldDefinition?.label;\n\n\tif ( summaryFields.length === 0 ) {\n\t\treturn {\n\t\t\tsummaryFields: fieldDefinition ? [ fieldDefinition ] : [],\n\t\t\tfieldDefinition,\n\t\t\tfieldLabel,\n\t\t};\n\t}\n\n\treturn {\n\t\tsummaryFields,\n\t\tfieldDefinition,\n\t\tfieldLabel,\n\t};\n}\n\nexport default useFieldFromFormField;\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,kBAAkB;AAU3B,SAAS,wBAAwB;AACjC,OAAO,qBAAqB;AAE5B,IAAM,qBAAqB,CAC1B,OACA,WACI;AACJ,QAAM,kBAAkB,OAAO,KAAM,CAAE,WAAY,OAAO,OAAO,MAAM,EAAG;AAE1E,MAAK,CAAE,iBAAkB;AACxB,WAAO,OAAO,KAAM,CAAE,WAAY;AACjC,UAAK,CAAC,CAAE,MAAM,UAAW;AACxB,cAAM,iBAAiB,MAAM,SAAS;AAAA,UACrC,CAAE,UAAW,CAAE,MAAM;AAAA,QACtB;AAEA,YAAK,eAAe,WAAW,GAAI;AAClC,iBAAO;AAAA,QACR;AAEA,eAAO,OAAO,OAAO,eAAgB,CAAE,EAAE;AAAA,MAC1C;AAEA,aAAO,OAAO,OAAO,MAAM;AAAA,IAC5B,CAAE;AAAA,EACH;AAEA,SAAO;AACR;AAcA,SAAS,sBAAuB,OAA6B;AAC5D,QAAM,EAAE,OAAO,IAAI,WAAY,eAAgB;AAC/C,QAAM,SAAS,MAAM;AACrB,QAAM,gBAAgB,iBAAkB,OAAO,SAAS,MAAO;AAC/D,QAAM,kBAAkB,mBAAoB,OAAO,MAAO;AAC1D,QAAM,aAAa,CAAC,CAAE,MAAM,WAAW,MAAM,QAAQ,iBAAiB;AAEtE,MAAK,cAAc,WAAW,GAAI;AACjC,WAAO;AAAA,MACN,eAAe,kBAAkB,CAAE,eAAgB,IAAI,CAAC;AAAA,MACxD;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEA,IAAO,oCAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -240,7 +240,7 @@ function FooterContent({
|
|
|
240
240
|
const [actionInProgress, setActionInProgress] = useState(
|
|
241
241
|
null
|
|
242
242
|
);
|
|
243
|
-
const footerContentRef = useRef(
|
|
243
|
+
const footerContentRef = useRef(void 0);
|
|
244
244
|
const isMobile = useViewportMatch("medium", "<");
|
|
245
245
|
const bulkActions = useMemo(
|
|
246
246
|
() => actions.filter((action) => action.supportsBulk),
|
|
@@ -268,7 +268,7 @@ function FooterContent({
|
|
|
268
268
|
);
|
|
269
269
|
if (!actionInProgress) {
|
|
270
270
|
if (footerContentRef.current) {
|
|
271
|
-
footerContentRef.current =
|
|
271
|
+
footerContentRef.current = void 0;
|
|
272
272
|
}
|
|
273
273
|
return renderFooterContent(
|
|
274
274
|
data,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/dataviews-bulk-actions/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { ReactElement } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { Button, CheckboxControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useMemo, useState, useRef, useContext } from '@wordpress/element';\nimport { useRegistry } from '@wordpress/data';\nimport { closeSmall } from '@wordpress/icons';\nimport { useViewportMatch } from '@wordpress/compose';\nimport { Stack } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport DataViewsContext from '../dataviews-context';\nimport { ActionModal } from '../dataviews-item-actions';\nimport type { Action, ActionModal as ActionModalType } from '../../types';\nimport type { SetSelection } from '../../types/private';\nimport type { ActionTriggerProps } from '../dataviews-item-actions';\nimport getFooterMessage from '../../utils/get-footer-message';\n\ninterface ActionWithModalProps< Item > {\n\taction: ActionModalType< Item >;\n\titems: Item[];\n\tActionTriggerComponent: (\n\t\tprops: ActionTriggerProps< Item >\n\t) => ReactElement;\n}\n\nfunction ActionWithModal< Item >( {\n\taction,\n\titems,\n\tActionTriggerComponent,\n}: ActionWithModalProps< Item > ) {\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst actionTriggerProps = {\n\t\taction,\n\t\tonClick: () => {\n\t\t\tsetIsModalOpen( true );\n\t\t},\n\t\titems,\n\t};\n\treturn (\n\t\t<>\n\t\t\t<ActionTriggerComponent { ...actionTriggerProps } />\n\t\t\t{ isModalOpen && (\n\t\t\t\t<ActionModal\n\t\t\t\t\taction={ action }\n\t\t\t\t\titems={ items }\n\t\t\t\t\tcloseModal={ () => setIsModalOpen( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport function useHasAPossibleBulkAction< Item >(\n\tactions: Action< Item >[],\n\titem: Item\n) {\n\treturn useMemo( () => {\n\t\treturn actions.some( ( action ) => {\n\t\t\treturn (\n\t\t\t\taction.supportsBulk &&\n\t\t\t\t( ! action.isEligible || action.isEligible( item ) )\n\t\t\t);\n\t\t} );\n\t}, [ actions, item ] );\n}\n\nexport function useSomeItemHasAPossibleBulkAction< Item >(\n\tactions: Action< Item >[],\n\tdata: Item[]\n) {\n\treturn useMemo( () => {\n\t\treturn data.some( ( item ) => {\n\t\t\treturn actions.some( ( action ) => {\n\t\t\t\treturn (\n\t\t\t\t\taction.supportsBulk &&\n\t\t\t\t\t( ! action.isEligible || action.isEligible( item ) )\n\t\t\t\t);\n\t\t\t} );\n\t\t} );\n\t}, [ actions, data ] );\n}\n\ninterface BulkSelectionCheckboxProps< Item > {\n\tselection: string[];\n\tonChangeSelection: SetSelection;\n\tdata: Item[];\n\tactions: Action< Item >[];\n\tgetItemId: ( item: Item ) => string;\n}\n\nexport function BulkSelectionCheckbox< Item >( {\n\tselection,\n\tonChangeSelection,\n\tdata,\n\tactions,\n\tgetItemId,\n}: BulkSelectionCheckboxProps< Item > ) {\n\tconst selectableItems = useMemo( () => {\n\t\treturn data.filter( ( item ) => {\n\t\t\treturn actions.some(\n\t\t\t\t( action ) =>\n\t\t\t\t\taction.supportsBulk &&\n\t\t\t\t\t( ! action.isEligible || action.isEligible( item ) )\n\t\t\t);\n\t\t} );\n\t}, [ data, actions ] );\n\tconst selectedItems = data.filter(\n\t\t( item ) =>\n\t\t\tselection.includes( getItemId( item ) ) &&\n\t\t\tselectableItems.includes( item )\n\t);\n\tconst areAllSelected = selectedItems.length === selectableItems.length;\n\treturn (\n\t\t<CheckboxControl\n\t\t\tclassName=\"dataviews-view-table-selection-checkbox\"\n\t\t\tchecked={ areAllSelected }\n\t\t\tindeterminate={ ! areAllSelected && !! selectedItems.length }\n\t\t\tonChange={ () => {\n\t\t\t\tif ( areAllSelected ) {\n\t\t\t\t\tonChangeSelection( [] );\n\t\t\t\t} else {\n\t\t\t\t\tonChangeSelection(\n\t\t\t\t\t\tselectableItems.map( ( item ) => getItemId( item ) )\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} }\n\t\t\taria-label={\n\t\t\t\tareAllSelected ? __( 'Deselect all' ) : __( 'Select all' )\n\t\t\t}\n\t\t/>\n\t);\n}\n\ninterface ActionButtonProps< Item > {\n\taction: Action< Item >;\n\tselectedItems: Item[];\n\tactionInProgress: string | null;\n\tsetActionInProgress: ( actionId: string | null ) => void;\n}\n\ninterface ToolbarContentProps< Item > {\n\tselection: string[];\n\tonChangeSelection: SetSelection;\n\tdata: Item[];\n\tactions: Action< Item >[];\n\tgetItemId: ( item: Item ) => string;\n\tpaginationInfo: {\n\t\ttotalItems: number;\n\t\ttotalPages: number;\n\t};\n}\n\nfunction ActionTrigger< Item >( {\n\taction,\n\tonClick,\n\tisBusy,\n\titems,\n}: ActionTriggerProps< Item > ) {\n\tconst label =\n\t\ttypeof action.label === 'string' ? action.label : action.label( items );\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\n\tif ( isMobile ) {\n\t\treturn (\n\t\t\t<Button\n\t\t\t\tdisabled={ isBusy }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tlabel={ label }\n\t\t\t\ticon={ action.icon }\n\t\t\t\tsize=\"compact\"\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisBusy={ isBusy }\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn (\n\t\t<Button\n\t\t\tdisabled={ isBusy }\n\t\t\taccessibleWhenDisabled\n\t\t\tsize=\"compact\"\n\t\t\tonClick={ onClick }\n\t\t\tisBusy={ isBusy }\n\t\t>\n\t\t\t{ label }\n\t\t</Button>\n\t);\n}\n\nconst EMPTY_ARRAY: [] = [];\n\nfunction ActionButton< Item >( {\n\taction,\n\tselectedItems,\n\tactionInProgress,\n\tsetActionInProgress,\n}: ActionButtonProps< Item > ) {\n\tconst registry = useRegistry();\n\tconst selectedEligibleItems = useMemo( () => {\n\t\treturn selectedItems.filter( ( item ) => {\n\t\t\treturn ! action.isEligible || action.isEligible( item );\n\t\t} );\n\t}, [ action, selectedItems ] );\n\tif ( 'RenderModal' in action ) {\n\t\treturn (\n\t\t\t<ActionWithModal\n\t\t\t\tkey={ action.id }\n\t\t\t\taction={ action }\n\t\t\t\titems={ selectedEligibleItems }\n\t\t\t\tActionTriggerComponent={ ActionTrigger }\n\t\t\t/>\n\t\t);\n\t}\n\treturn (\n\t\t<ActionTrigger\n\t\t\tkey={ action.id }\n\t\t\taction={ action }\n\t\t\tonClick={ async () => {\n\t\t\t\tsetActionInProgress( action.id );\n\t\t\t\tawait action.callback( selectedItems, {\n\t\t\t\t\tregistry,\n\t\t\t\t} );\n\t\t\t\tsetActionInProgress( null );\n\t\t\t} }\n\t\t\titems={ selectedEligibleItems }\n\t\t\tisBusy={ actionInProgress === action.id }\n\t\t/>\n\t);\n}\n\nfunction renderFooterContent< Item >(\n\tdata: Item[],\n\tactions: Action< Item >[],\n\tgetItemId: ( item: Item ) => string,\n\tselection: string[],\n\tactionsToShow: Action< Item >[],\n\tselectedItems: Item[],\n\tactionInProgress: string | null,\n\tsetActionInProgress: ( actionId: string | null ) => void,\n\tonChangeSelection: SetSelection,\n\tpaginationInfo: {\n\t\ttotalItems: number;\n\t\ttotalPages: number;\n\t}\n) {\n\tconst message = getFooterMessage(\n\t\tselection.length,\n\t\tdata.length,\n\t\tpaginationInfo.totalItems\n\t);\n\treturn (\n\t\t<Stack\n\t\t\tdirection=\"row\"\n\t\t\tclassName=\"dataviews-bulk-actions-footer__container\"\n\t\t\tgap=\"md\"\n\t\t\talign=\"center\"\n\t\t>\n\t\t\t<BulkSelectionCheckbox\n\t\t\t\tselection={ selection }\n\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\tdata={ data }\n\t\t\t\tactions={ actions }\n\t\t\t\tgetItemId={ getItemId }\n\t\t\t/>\n\t\t\t<span className=\"dataviews-bulk-actions-footer__item-count\">\n\t\t\t\t{ message }\n\t\t\t</span>\n\t\t\t<Stack\n\t\t\t\tdirection=\"row\"\n\t\t\t\tclassName=\"dataviews-bulk-actions-footer__action-buttons\"\n\t\t\t\tgap=\"xs\"\n\t\t\t>\n\t\t\t\t{ actionsToShow.map( ( action ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<ActionButton\n\t\t\t\t\t\t\tkey={ action.id }\n\t\t\t\t\t\t\taction={ action }\n\t\t\t\t\t\t\tselectedItems={ selectedItems }\n\t\t\t\t\t\t\tactionInProgress={ actionInProgress }\n\t\t\t\t\t\t\tsetActionInProgress={ setActionInProgress }\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t\t{ selectedItems.length > 0 && (\n\t\t\t\t\t<Button\n\t\t\t\t\t\ticon={ closeSmall }\n\t\t\t\t\t\tshowTooltip\n\t\t\t\t\t\ttooltipPosition=\"top\"\n\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\tlabel={ __( 'Cancel' ) }\n\t\t\t\t\t\tdisabled={ !! actionInProgress }\n\t\t\t\t\t\taccessibleWhenDisabled={ false }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tonChangeSelection( EMPTY_ARRAY );\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</Stack>\n\t\t</Stack>\n\t);\n}\n\nfunction FooterContent< Item >( {\n\tselection,\n\tactions,\n\tonChangeSelection,\n\tdata,\n\tgetItemId,\n\tpaginationInfo,\n}: ToolbarContentProps< Item > ) {\n\tconst [ actionInProgress, setActionInProgress ] = useState< string | null >(\n\t\tnull\n\t);\n\tconst footerContentRef = useRef< JSX.Element | null >( null );\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\n\tconst bulkActions = useMemo(\n\t\t() => actions.filter( ( action ) => action.supportsBulk ),\n\t\t[ actions ]\n\t);\n\tconst selectableItems = useMemo( () => {\n\t\treturn data.filter( ( item ) => {\n\t\t\treturn bulkActions.some(\n\t\t\t\t( action ) => ! action.isEligible || action.isEligible( item )\n\t\t\t);\n\t\t} );\n\t}, [ data, bulkActions ] );\n\n\tconst selectedItems = useMemo( () => {\n\t\treturn data.filter(\n\t\t\t( item ) =>\n\t\t\t\tselection.includes( getItemId( item ) ) &&\n\t\t\t\tselectableItems.includes( item )\n\t\t);\n\t}, [ selection, data, getItemId, selectableItems ] );\n\n\tconst actionsToShow = useMemo(\n\t\t() =>\n\t\t\tactions.filter( ( action ) => {\n\t\t\t\treturn (\n\t\t\t\t\taction.supportsBulk &&\n\t\t\t\t\t( ! isMobile || action.icon ) &&\n\t\t\t\t\tselectedItems.some(\n\t\t\t\t\t\t( item ) =>\n\t\t\t\t\t\t\t! action.isEligible || action.isEligible( item )\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t} ),\n\t\t[ actions, selectedItems, isMobile ]\n\t);\n\tif ( ! actionInProgress ) {\n\t\tif ( footerContentRef.current ) {\n\t\t\tfooterContentRef.current = null;\n\t\t}\n\t\treturn renderFooterContent(\n\t\t\tdata,\n\t\t\tactions,\n\t\t\tgetItemId,\n\t\t\tselection,\n\t\t\tactionsToShow,\n\t\t\tselectedItems,\n\t\t\tactionInProgress,\n\t\t\tsetActionInProgress,\n\t\t\tonChangeSelection,\n\t\t\tpaginationInfo\n\t\t);\n\t} else if ( ! footerContentRef.current ) {\n\t\tfooterContentRef.current = renderFooterContent(\n\t\t\tdata,\n\t\t\tactions,\n\t\t\tgetItemId,\n\t\t\tselection,\n\t\t\tactionsToShow,\n\t\t\tselectedItems,\n\t\t\tactionInProgress,\n\t\t\tsetActionInProgress,\n\t\t\tonChangeSelection,\n\t\t\tpaginationInfo\n\t\t);\n\t}\n\treturn footerContentRef.current;\n}\n\nexport function BulkActionsFooter() {\n\tconst {\n\t\tdata,\n\t\tselection,\n\t\tactions = EMPTY_ARRAY,\n\t\tonChangeSelection,\n\t\tgetItemId,\n\t\tpaginationInfo,\n\t} = useContext( DataViewsContext );\n\treturn (\n\t\t<FooterContent\n\t\t\tselection={ selection }\n\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\tdata={ data }\n\t\t\tactions={ actions }\n\t\t\tgetItemId={ getItemId }\n\t\t\tpaginationInfo={ paginationInfo }\n\t\t/>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";AAQA,SAAS,QAAQ,uBAAuB;AACxC,SAAS,UAAU;AACnB,SAAS,SAAS,UAAU,QAAQ,kBAAkB;AACtD,SAAS,mBAAmB;AAC5B,SAAS,kBAAkB;AAC3B,SAAS,wBAAwB;AACjC,SAAS,aAAa;AAKtB,OAAO,sBAAsB;AAC7B,SAAS,mBAAmB;AAI5B,OAAO,sBAAsB;AAwB3B,mBACC,KADD;AAdF,SAAS,gBAAyB;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AACD,GAAkC;AACjC,QAAM,CAAE,aAAa,cAAe,IAAI,SAAU,KAAM;AACxD,QAAM,qBAAqB;AAAA,IAC1B;AAAA,IACA,SAAS,MAAM;AACd,qBAAgB,IAAK;AAAA,IACtB;AAAA,IACA;AAAA,EACD;AACA,SACC,iCACC;AAAA,wBAAC,0BAAyB,GAAG,oBAAqB;AAAA,IAChD,eACD;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA;AAAA,QACA,YAAa,MAAM,eAAgB,KAAM;AAAA;AAAA,IAC1C;AAAA,KAEF;AAEF;AAEO,SAAS,0BACf,SACA,MACC;AACD,SAAO,QAAS,MAAM;AACrB,WAAO,QAAQ,KAAM,CAAE,WAAY;AAClC,aACC,OAAO,iBACL,CAAE,OAAO,cAAc,OAAO,WAAY,IAAK;AAAA,IAEnD,CAAE;AAAA,EACH,GAAG,CAAE,SAAS,IAAK,CAAE;AACtB;AAEO,SAAS,kCACf,SACA,MACC;AACD,SAAO,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,IACL,eAAe;AAAA,EAChB;AACA,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,WAAU;AAAA,MACV,KAAI;AAAA,MACJ,OAAM;AAAA,MAEN;AAAA;AAAA,UAAC;AAAA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA;AAAA,QACD;AAAA,QACA,oBAAC,UAAK,WAAU,6CACb,mBACH;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACA,WAAU;AAAA,YACV,WAAU;AAAA,YACV,KAAI;AAAA,YAEF;AAAA,4BAAc,IAAK,CAAE,WAAY;AAClC,uBACC;AAAA,kBAAC;AAAA;AAAA,oBAEA;AAAA,oBACA;AAAA,oBACA;AAAA,oBACA;AAAA;AAAA,kBAJM,OAAO;AAAA,gBAKd;AAAA,cAEF,CAAE;AAAA,cACA,cAAc,SAAS,KACxB;AAAA,gBAAC;AAAA;AAAA,kBACA,MAAO;AAAA,kBACP,aAAW;AAAA,kBACX,iBAAgB;AAAA,kBAChB,MAAK;AAAA,kBACL,OAAQ,GAAI,QAAS;AAAA,kBACrB,UAAW,CAAC,CAAE;AAAA,kBACd,wBAAyB;AAAA,kBACzB,SAAU,MAAM;AACf,sCAAmB,WAAY;AAAA,kBAChC;AAAA;AAAA,cACD;AAAA;AAAA;AAAA,QAEF;AAAA;AAAA;AAAA,EACD;AAEF;AAEA,SAAS,cAAuB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAiC;AAChC,QAAM,CAAE,kBAAkB,mBAAoB,IAAI;AAAA,IACjD;AAAA,EACD;AACA,QAAM,mBAAmB,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { ReactElement } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { Button, CheckboxControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useMemo, useState, useRef, useContext } from '@wordpress/element';\nimport { useRegistry } from '@wordpress/data';\nimport { closeSmall } from '@wordpress/icons';\nimport { useViewportMatch } from '@wordpress/compose';\nimport { Stack } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport DataViewsContext from '../dataviews-context';\nimport { ActionModal } from '../dataviews-item-actions';\nimport type { Action, ActionModal as ActionModalType } from '../../types';\nimport type { SetSelection } from '../../types/private';\nimport type { ActionTriggerProps } from '../dataviews-item-actions';\nimport getFooterMessage from '../../utils/get-footer-message';\n\ninterface ActionWithModalProps< Item > {\n\taction: ActionModalType< Item >;\n\titems: Item[];\n\tActionTriggerComponent: (\n\t\tprops: ActionTriggerProps< Item >\n\t) => ReactElement;\n}\n\nfunction ActionWithModal< Item >( {\n\taction,\n\titems,\n\tActionTriggerComponent,\n}: ActionWithModalProps< Item > ) {\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst actionTriggerProps = {\n\t\taction,\n\t\tonClick: () => {\n\t\t\tsetIsModalOpen( true );\n\t\t},\n\t\titems,\n\t};\n\treturn (\n\t\t<>\n\t\t\t<ActionTriggerComponent { ...actionTriggerProps } />\n\t\t\t{ isModalOpen && (\n\t\t\t\t<ActionModal\n\t\t\t\t\taction={ action }\n\t\t\t\t\titems={ items }\n\t\t\t\t\tcloseModal={ () => setIsModalOpen( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport function useHasAPossibleBulkAction< Item >(\n\tactions: Action< Item >[],\n\titem: Item\n) {\n\treturn useMemo( () => {\n\t\treturn actions.some( ( action ) => {\n\t\t\treturn (\n\t\t\t\taction.supportsBulk &&\n\t\t\t\t( ! action.isEligible || action.isEligible( item ) )\n\t\t\t);\n\t\t} );\n\t}, [ actions, item ] );\n}\n\nexport function useSomeItemHasAPossibleBulkAction< Item >(\n\tactions: Action< Item >[],\n\tdata: Item[]\n) {\n\treturn useMemo( () => {\n\t\treturn data.some( ( item ) => {\n\t\t\treturn actions.some( ( action ) => {\n\t\t\t\treturn (\n\t\t\t\t\taction.supportsBulk &&\n\t\t\t\t\t( ! action.isEligible || action.isEligible( item ) )\n\t\t\t\t);\n\t\t\t} );\n\t\t} );\n\t}, [ actions, data ] );\n}\n\ninterface BulkSelectionCheckboxProps< Item > {\n\tselection: string[];\n\tonChangeSelection: SetSelection;\n\tdata: Item[];\n\tactions: Action< Item >[];\n\tgetItemId: ( item: Item ) => string;\n}\n\nexport function BulkSelectionCheckbox< Item >( {\n\tselection,\n\tonChangeSelection,\n\tdata,\n\tactions,\n\tgetItemId,\n}: BulkSelectionCheckboxProps< Item > ) {\n\tconst selectableItems = useMemo( () => {\n\t\treturn data.filter( ( item ) => {\n\t\t\treturn actions.some(\n\t\t\t\t( action ) =>\n\t\t\t\t\taction.supportsBulk &&\n\t\t\t\t\t( ! action.isEligible || action.isEligible( item ) )\n\t\t\t);\n\t\t} );\n\t}, [ data, actions ] );\n\tconst selectedItems = data.filter(\n\t\t( item ) =>\n\t\t\tselection.includes( getItemId( item ) ) &&\n\t\t\tselectableItems.includes( item )\n\t);\n\tconst areAllSelected = selectedItems.length === selectableItems.length;\n\treturn (\n\t\t<CheckboxControl\n\t\t\tclassName=\"dataviews-view-table-selection-checkbox\"\n\t\t\tchecked={ areAllSelected }\n\t\t\tindeterminate={ ! areAllSelected && !! selectedItems.length }\n\t\t\tonChange={ () => {\n\t\t\t\tif ( areAllSelected ) {\n\t\t\t\t\tonChangeSelection( [] );\n\t\t\t\t} else {\n\t\t\t\t\tonChangeSelection(\n\t\t\t\t\t\tselectableItems.map( ( item ) => getItemId( item ) )\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} }\n\t\t\taria-label={\n\t\t\t\tareAllSelected ? __( 'Deselect all' ) : __( 'Select all' )\n\t\t\t}\n\t\t/>\n\t);\n}\n\ninterface ActionButtonProps< Item > {\n\taction: Action< Item >;\n\tselectedItems: Item[];\n\tactionInProgress: string | null;\n\tsetActionInProgress: ( actionId: string | null ) => void;\n}\n\ninterface ToolbarContentProps< Item > {\n\tselection: string[];\n\tonChangeSelection: SetSelection;\n\tdata: Item[];\n\tactions: Action< Item >[];\n\tgetItemId: ( item: Item ) => string;\n\tpaginationInfo: {\n\t\ttotalItems: number;\n\t\ttotalPages: number;\n\t};\n}\n\nfunction ActionTrigger< Item >( {\n\taction,\n\tonClick,\n\tisBusy,\n\titems,\n}: ActionTriggerProps< Item > ) {\n\tconst label =\n\t\ttypeof action.label === 'string' ? action.label : action.label( items );\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\n\tif ( isMobile ) {\n\t\treturn (\n\t\t\t<Button\n\t\t\t\tdisabled={ isBusy }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tlabel={ label }\n\t\t\t\ticon={ action.icon }\n\t\t\t\tsize=\"compact\"\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisBusy={ isBusy }\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn (\n\t\t<Button\n\t\t\tdisabled={ isBusy }\n\t\t\taccessibleWhenDisabled\n\t\t\tsize=\"compact\"\n\t\t\tonClick={ onClick }\n\t\t\tisBusy={ isBusy }\n\t\t>\n\t\t\t{ label }\n\t\t</Button>\n\t);\n}\n\nconst EMPTY_ARRAY: [] = [];\n\nfunction ActionButton< Item >( {\n\taction,\n\tselectedItems,\n\tactionInProgress,\n\tsetActionInProgress,\n}: ActionButtonProps< Item > ) {\n\tconst registry = useRegistry();\n\tconst selectedEligibleItems = useMemo( () => {\n\t\treturn selectedItems.filter( ( item ) => {\n\t\t\treturn ! action.isEligible || action.isEligible( item );\n\t\t} );\n\t}, [ action, selectedItems ] );\n\tif ( 'RenderModal' in action ) {\n\t\treturn (\n\t\t\t<ActionWithModal\n\t\t\t\tkey={ action.id }\n\t\t\t\taction={ action }\n\t\t\t\titems={ selectedEligibleItems }\n\t\t\t\tActionTriggerComponent={ ActionTrigger }\n\t\t\t/>\n\t\t);\n\t}\n\treturn (\n\t\t<ActionTrigger\n\t\t\tkey={ action.id }\n\t\t\taction={ action }\n\t\t\tonClick={ async () => {\n\t\t\t\tsetActionInProgress( action.id );\n\t\t\t\tawait action.callback( selectedItems, {\n\t\t\t\t\tregistry,\n\t\t\t\t} );\n\t\t\t\tsetActionInProgress( null );\n\t\t\t} }\n\t\t\titems={ selectedEligibleItems }\n\t\t\tisBusy={ actionInProgress === action.id }\n\t\t/>\n\t);\n}\n\nfunction renderFooterContent< Item >(\n\tdata: Item[],\n\tactions: Action< Item >[],\n\tgetItemId: ( item: Item ) => string,\n\tselection: string[],\n\tactionsToShow: Action< Item >[],\n\tselectedItems: Item[],\n\tactionInProgress: string | null,\n\tsetActionInProgress: ( actionId: string | null ) => void,\n\tonChangeSelection: SetSelection,\n\tpaginationInfo: {\n\t\ttotalItems: number;\n\t\ttotalPages: number;\n\t}\n) {\n\tconst message = getFooterMessage(\n\t\tselection.length,\n\t\tdata.length,\n\t\tpaginationInfo.totalItems\n\t);\n\treturn (\n\t\t<Stack\n\t\t\tdirection=\"row\"\n\t\t\tclassName=\"dataviews-bulk-actions-footer__container\"\n\t\t\tgap=\"md\"\n\t\t\talign=\"center\"\n\t\t>\n\t\t\t<BulkSelectionCheckbox\n\t\t\t\tselection={ selection }\n\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\tdata={ data }\n\t\t\t\tactions={ actions }\n\t\t\t\tgetItemId={ getItemId }\n\t\t\t/>\n\t\t\t<span className=\"dataviews-bulk-actions-footer__item-count\">\n\t\t\t\t{ message }\n\t\t\t</span>\n\t\t\t<Stack\n\t\t\t\tdirection=\"row\"\n\t\t\t\tclassName=\"dataviews-bulk-actions-footer__action-buttons\"\n\t\t\t\tgap=\"xs\"\n\t\t\t>\n\t\t\t\t{ actionsToShow.map( ( action ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<ActionButton\n\t\t\t\t\t\t\tkey={ action.id }\n\t\t\t\t\t\t\taction={ action }\n\t\t\t\t\t\t\tselectedItems={ selectedItems }\n\t\t\t\t\t\t\tactionInProgress={ actionInProgress }\n\t\t\t\t\t\t\tsetActionInProgress={ setActionInProgress }\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t\t{ selectedItems.length > 0 && (\n\t\t\t\t\t<Button\n\t\t\t\t\t\ticon={ closeSmall }\n\t\t\t\t\t\tshowTooltip\n\t\t\t\t\t\ttooltipPosition=\"top\"\n\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\tlabel={ __( 'Cancel' ) }\n\t\t\t\t\t\tdisabled={ !! actionInProgress }\n\t\t\t\t\t\taccessibleWhenDisabled={ false }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tonChangeSelection( EMPTY_ARRAY );\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</Stack>\n\t\t</Stack>\n\t);\n}\n\nfunction FooterContent< Item >( {\n\tselection,\n\tactions,\n\tonChangeSelection,\n\tdata,\n\tgetItemId,\n\tpaginationInfo,\n}: ToolbarContentProps< Item > ) {\n\tconst [ actionInProgress, setActionInProgress ] = useState< string | null >(\n\t\tnull\n\t);\n\tconst footerContentRef = useRef< React.JSX.Element >( undefined );\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\n\tconst bulkActions = useMemo(\n\t\t() => actions.filter( ( action ) => action.supportsBulk ),\n\t\t[ actions ]\n\t);\n\tconst selectableItems = useMemo( () => {\n\t\treturn data.filter( ( item ) => {\n\t\t\treturn bulkActions.some(\n\t\t\t\t( action ) => ! action.isEligible || action.isEligible( item )\n\t\t\t);\n\t\t} );\n\t}, [ data, bulkActions ] );\n\n\tconst selectedItems = useMemo( () => {\n\t\treturn data.filter(\n\t\t\t( item ) =>\n\t\t\t\tselection.includes( getItemId( item ) ) &&\n\t\t\t\tselectableItems.includes( item )\n\t\t);\n\t}, [ selection, data, getItemId, selectableItems ] );\n\n\tconst actionsToShow = useMemo(\n\t\t() =>\n\t\t\tactions.filter( ( action ) => {\n\t\t\t\treturn (\n\t\t\t\t\taction.supportsBulk &&\n\t\t\t\t\t( ! isMobile || action.icon ) &&\n\t\t\t\t\tselectedItems.some(\n\t\t\t\t\t\t( item ) =>\n\t\t\t\t\t\t\t! action.isEligible || action.isEligible( item )\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t} ),\n\t\t[ actions, selectedItems, isMobile ]\n\t);\n\tif ( ! actionInProgress ) {\n\t\tif ( footerContentRef.current ) {\n\t\t\tfooterContentRef.current = undefined;\n\t\t}\n\t\treturn renderFooterContent(\n\t\t\tdata,\n\t\t\tactions,\n\t\t\tgetItemId,\n\t\t\tselection,\n\t\t\tactionsToShow,\n\t\t\tselectedItems,\n\t\t\tactionInProgress,\n\t\t\tsetActionInProgress,\n\t\t\tonChangeSelection,\n\t\t\tpaginationInfo\n\t\t);\n\t} else if ( ! footerContentRef.current ) {\n\t\tfooterContentRef.current = renderFooterContent(\n\t\t\tdata,\n\t\t\tactions,\n\t\t\tgetItemId,\n\t\t\tselection,\n\t\t\tactionsToShow,\n\t\t\tselectedItems,\n\t\t\tactionInProgress,\n\t\t\tsetActionInProgress,\n\t\t\tonChangeSelection,\n\t\t\tpaginationInfo\n\t\t);\n\t}\n\treturn footerContentRef.current;\n}\n\nexport function BulkActionsFooter() {\n\tconst {\n\t\tdata,\n\t\tselection,\n\t\tactions = EMPTY_ARRAY,\n\t\tonChangeSelection,\n\t\tgetItemId,\n\t\tpaginationInfo,\n\t} = useContext( DataViewsContext );\n\treturn (\n\t\t<FooterContent\n\t\t\tselection={ selection }\n\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\tdata={ data }\n\t\t\tactions={ actions }\n\t\t\tgetItemId={ getItemId }\n\t\t\tpaginationInfo={ paginationInfo }\n\t\t/>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAQA,SAAS,QAAQ,uBAAuB;AACxC,SAAS,UAAU;AACnB,SAAS,SAAS,UAAU,QAAQ,kBAAkB;AACtD,SAAS,mBAAmB;AAC5B,SAAS,kBAAkB;AAC3B,SAAS,wB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C,OAAO,iBACL,CAAE,YAAY,OAAO,SACvB,cAAc;AAAA,QACb,CAAE,SACD,CAAE,OAAO,cAAc,OAAO,WAAY,IAAK;AAAA,MACjD;AAAA,IAEF,CAAE;AAAA,IACH,CAAE,SAAS,eAAe,QAAS;AAAA,EACpC;AACA,MAAK,CAAE,kBAAmB;AACzB,QAAK,iBAAiB,SAAU;AAC/B,uBAAiB,UAAU;AAAA,IAC5B;AACA,WAAO;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD,WAAY,CAAE,iBAAiB,SAAU;AACxC,qBAAiB,UAAU;AAAA,MAC1B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACA,SAAO,iBAAiB;AACzB;AAEO,SAAS,oBAAoB;AACnC,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACD,IAAI,WAAY,gBAAiB;AACjC,SACC;AAAA,IAAC;AAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,EACD;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/dataviews-context/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { ComponentProps, ReactElement, ReactNode } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { createContext, createRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tView,\n\tAction,\n\tNormalizedField,\n\tSupportedLayouts,\n\tNormalizedFilter,\n} from '../../types';\nimport type { SetSelection } from '../../types/private';\nimport { LAYOUT_TABLE } from '../../constants';\n\ntype DataViewsContextType< Item > = {\n\tview: View;\n\tonChangeView: ( view: View ) => void;\n\tfields: NormalizedField< Item >[];\n\tactions?: Action< Item >[];\n\tdata: Item[];\n\tisLoading?: boolean;\n\tpaginationInfo: {\n\t\ttotalItems: number;\n\t\ttotalPages: number;\n\t};\n\tselection: string[];\n\tonChangeSelection: SetSelection;\n\topenedFilter: string | null;\n\tsetOpenedFilter: ( openedFilter: string | null ) => void;\n\tgetItemId: ( item: Item ) => string;\n\tgetItemLevel?: ( item: Item ) => number;\n\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tisItemClickable: ( item: Item ) => boolean;\n\tcontainerWidth: number;\n\tcontainerRef: React.MutableRefObject< HTMLDivElement | null >;\n\tresizeObserverRef:\n\t\t| ( ( element?: HTMLDivElement | null ) => void )\n\t\t| React.RefObject< HTMLDivElement >;\n\tdefaultLayouts: SupportedLayouts;\n\tfilters: NormalizedFilter[];\n\tisShowingFilter: boolean;\n\tsetIsShowingFilter: ( value: boolean ) => void;\n\tconfig: { perPageSizes: number[] };\n\tempty?: ReactNode;\n\thasInfiniteScrollHandler: boolean;\n\titemListLabel?: string;\n\tonReset?: ( () => void ) | false;\n};\n\nconst DataViewsContext = createContext< DataViewsContextType< any > >( {\n\tview: { type: LAYOUT_TABLE },\n\tonChangeView: () => {},\n\tfields: [],\n\tdata: [],\n\tpaginationInfo: {\n\t\ttotalItems: 0,\n\t\ttotalPages: 0,\n\t},\n\tselection: [],\n\tonChangeSelection: () => {},\n\tsetOpenedFilter: () => {},\n\topenedFilter: null,\n\tgetItemId: ( item ) => item.id,\n\tisItemClickable: () => true,\n\trenderItemLink: undefined,\n\tcontainerWidth: 0,\n\tcontainerRef: createRef(),\n\tresizeObserverRef: () => {},\n\tdefaultLayouts: { list: {}, grid: {}, table: {} },\n\tfilters: [],\n\tisShowingFilter: false,\n\tsetIsShowingFilter: () => {},\n\thasInfiniteScrollHandler: false,\n\tconfig: {\n\t\tperPageSizes: [],\n\t},\n} );\n\nDataViewsContext.displayName = 'DataViewsContext';\n\nexport default DataViewsContext;\n"],
|
|
5
|
-
"mappings": ";AAQA,SAAS,eAAe,iBAAiB;AAazC,SAAS,oBAAoB;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { ComponentProps, ReactElement, ReactNode } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { createContext, createRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tView,\n\tAction,\n\tNormalizedField,\n\tSupportedLayouts,\n\tNormalizedFilter,\n} from '../../types';\nimport type { SetSelection } from '../../types/private';\nimport { LAYOUT_TABLE } from '../../constants';\n\ntype DataViewsContextType< Item > = {\n\tview: View;\n\tonChangeView: ( view: View ) => void;\n\tfields: NormalizedField< Item >[];\n\tactions?: Action< Item >[];\n\tdata: Item[];\n\tisLoading?: boolean;\n\tpaginationInfo: {\n\t\ttotalItems: number;\n\t\ttotalPages: number;\n\t};\n\tselection: string[];\n\tonChangeSelection: SetSelection;\n\topenedFilter: string | null;\n\tsetOpenedFilter: ( openedFilter: string | null ) => void;\n\tgetItemId: ( item: Item ) => string;\n\tgetItemLevel?: ( item: Item ) => number;\n\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tisItemClickable: ( item: Item ) => boolean;\n\tcontainerWidth: number;\n\tcontainerRef: React.MutableRefObject< HTMLDivElement | null >;\n\tresizeObserverRef:\n\t\t| ( ( element?: HTMLDivElement | null ) => void )\n\t\t| React.RefObject< HTMLDivElement >;\n\tdefaultLayouts: SupportedLayouts;\n\tfilters: NormalizedFilter[];\n\tisShowingFilter: boolean;\n\tsetIsShowingFilter: ( value: boolean ) => void;\n\tconfig: { perPageSizes: number[] };\n\tempty?: ReactNode;\n\thasInitiallyLoaded?: boolean;\n\thasInfiniteScrollHandler: boolean;\n\titemListLabel?: string;\n\tonReset?: ( () => void ) | false;\n};\n\nconst DataViewsContext = createContext< DataViewsContextType< any > >( {\n\tview: { type: LAYOUT_TABLE },\n\tonChangeView: () => {},\n\tfields: [],\n\tdata: [],\n\tpaginationInfo: {\n\t\ttotalItems: 0,\n\t\ttotalPages: 0,\n\t},\n\tselection: [],\n\tonChangeSelection: () => {},\n\tsetOpenedFilter: () => {},\n\topenedFilter: null,\n\tgetItemId: ( item ) => item.id,\n\tisItemClickable: () => true,\n\trenderItemLink: undefined,\n\tcontainerWidth: 0,\n\tcontainerRef: createRef(),\n\tresizeObserverRef: () => {},\n\tdefaultLayouts: { list: {}, grid: {}, table: {} },\n\tfilters: [],\n\tisShowingFilter: false,\n\tsetIsShowingFilter: () => {},\n\thasInitiallyLoaded: false,\n\thasInfiniteScrollHandler: false,\n\tconfig: {\n\t\tperPageSizes: [],\n\t},\n} );\n\nDataViewsContext.displayName = 'DataViewsContext';\n\nexport default DataViewsContext;\n"],
|
|
5
|
+
"mappings": ";AAQA,SAAS,eAAe,iBAAiB;AAazC,SAAS,oBAAoB;AA2C7B,IAAM,mBAAmB,cAA8C;AAAA,EACtE,MAAM,EAAE,MAAM,aAAa;AAAA,EAC3B,cAAc,MAAM;AAAA,EAAC;AAAA,EACrB,QAAQ,CAAC;AAAA,EACT,MAAM,CAAC;AAAA,EACP,gBAAgB;AAAA,IACf,YAAY;AAAA,IACZ,YAAY;AAAA,EACb;AAAA,EACA,WAAW,CAAC;AAAA,EACZ,mBAAmB,MAAM;AAAA,EAAC;AAAA,EAC1B,iBAAiB,MAAM;AAAA,EAAC;AAAA,EACxB,cAAc;AAAA,EACd,WAAW,CAAE,SAAU,KAAK;AAAA,EAC5B,iBAAiB,MAAM;AAAA,EACvB,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,cAAc,UAAU;AAAA,EACxB,mBAAmB,MAAM;AAAA,EAAC;AAAA,EAC1B,gBAAgB,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,OAAO,CAAC,EAAE;AAAA,EAChD,SAAS,CAAC;AAAA,EACV,iBAAiB;AAAA,EACjB,oBAAoB,MAAM;AAAA,EAAC;AAAA,EAC3B,oBAAoB;AAAA,EACpB,0BAA0B;AAAA,EAC1B,QAAQ;AAAA,IACP,cAAc,CAAC;AAAA,EAChB;AACD,CAAE;AAEF,iBAAiB,cAAc;AAE/B,IAAO,4BAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/dataviews-filters/filter.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport type { RefObject } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tDropdown,\n\tFlexItem,\n\tSelectControl,\n\tTooltip,\n\tIcon,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useMemo, useRef } from '@wordpress/element';\nimport { closeSmall } from '@wordpress/icons';\nimport { Stack } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport SearchWidget from './search-widget';\nimport InputWidget from './input-widget';\nimport { getOperatorByName } from '../../utils/operators';\nimport type {\n\tFilter,\n\tNormalizedField,\n\tNormalizedFilter,\n\tOperator,\n\tOption,\n\tView,\n} from '../../types';\nimport useElements from '../../hooks/use-elements';\n\nconst ENTER = 'Enter';\nconst SPACE = ' ';\n\ninterface FilterTextProps {\n\tactiveElements: Option[];\n\tfilterInView?: Filter;\n\tfilter: NormalizedFilter;\n}\n\ninterface OperatorSelectorProps {\n\tfilter: NormalizedFilter;\n\tview: View;\n\tonChangeView: ( view: View ) => void;\n}\n\ninterface FilterProps extends OperatorSelectorProps {\n\taddFilterRef: RefObject< HTMLButtonElement >;\n\topenedFilter: string | null;\n\tfields: NormalizedField< any >[];\n}\n\nconst FilterText = ( {\n\tactiveElements,\n\tfilterInView,\n\tfilter,\n}: FilterTextProps ) => {\n\tif ( activeElements === undefined || activeElements.length === 0 ) {\n\t\treturn filter.name;\n\t}\n\n\tconst operator = getOperatorByName( filterInView?.operator );\n\tif ( operator !== undefined ) {\n\t\treturn operator.filterText( filter, activeElements );\n\t}\n\n\treturn sprintf(\n\t\t/* translators: 1: Filter name e.g.: \"Unknown status for Author\". */\n\t\t__( 'Unknown status for %1$s' ),\n\t\tfilter.name\n\t);\n};\n\nfunction OperatorSelector( {\n\tfilter,\n\tview,\n\tonChangeView,\n}: OperatorSelectorProps ) {\n\tconst operatorOptions = filter.operators?.map( ( operator ) => ( {\n\t\tvalue: operator,\n\t\tlabel: getOperatorByName( operator )?.label || operator,\n\t} ) );\n\tconst currentFilter = view.filters?.find(\n\t\t( _filter ) => _filter.field === filter.field\n\t);\n\tconst value = currentFilter?.operator || filter.operators[ 0 ];\n\treturn (\n\t\toperatorOptions.length > 1 && (\n\t\t\t<Stack\n\t\t\t\tdirection=\"row\"\n\t\t\t\tgap=\"sm\"\n\t\t\t\tjustify=\"flex-start\"\n\t\t\t\tclassName=\"dataviews-filters__summary-operators-container\"\n\t\t\t\talign=\"center\"\n\t\t\t>\n\t\t\t\t<FlexItem className=\"dataviews-filters__summary-operators-filter-name\">\n\t\t\t\t\t{ filter.name }\n\t\t\t\t</FlexItem>\n\n\t\t\t\t<SelectControl\n\t\t\t\t\tclassName=\"dataviews-filters__summary-operators-filter-select\"\n\t\t\t\t\tlabel={ __( 'Conditions' ) }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\toptions={ operatorOptions }\n\t\t\t\t\tonChange={ ( newValue ) => {\n\t\t\t\t\t\tconst newOperator = newValue as Operator;\n\t\t\t\t\t\tconst currentOperator = currentFilter?.operator;\n\t\t\t\t\t\tconst newFilters = currentFilter\n\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t...( view.filters ?? [] ).map(\n\t\t\t\t\t\t\t\t\t\t( _filter ) => {\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t_filter.field === filter.field\n\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\tconst currentOpSelectionModel =\n\t\t\t\t\t\t\t\t\t\t\t\t\tgetOperatorByName(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentOperator\n\t\t\t\t\t\t\t\t\t\t\t\t\t)?.selection;\n\t\t\t\t\t\t\t\t\t\t\t\tconst newOpSelectionModel =\n\t\t\t\t\t\t\t\t\t\t\t\t\tgetOperatorByName(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnewOperator\n\t\t\t\t\t\t\t\t\t\t\t\t\t)?.selection;\n\n\t\t\t\t\t\t\t\t\t\t\t\tconst shouldResetValue =\n\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentOpSelectionModel !==\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnewOpSelectionModel ||\n\t\t\t\t\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentOpSelectionModel,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnewOpSelectionModel,\n\t\t\t\t\t\t\t\t\t\t\t\t\t].includes( 'custom' );\n\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\t..._filter,\n\t\t\t\t\t\t\t\t\t\t\t\t\tvalue: shouldResetValue\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t: _filter.value,\n\t\t\t\t\t\t\t\t\t\t\t\t\toperator: newOperator,\n\t\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\treturn _filter;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t...( view.filters ?? [] ),\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tfield: filter.field,\n\t\t\t\t\t\t\t\t\t\toperator: newOperator,\n\t\t\t\t\t\t\t\t\t\tvalue: undefined,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t ];\n\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\tpage: 1,\n\t\t\t\t\t\t\tfilters: newFilters,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tsize=\"small\"\n\t\t\t\t\tvariant=\"minimal\"\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t/>\n\t\t\t</Stack>\n\t\t)\n\t);\n}\n\nexport default function Filter( {\n\taddFilterRef,\n\topenedFilter,\n\tfields,\n\t...commonProps\n}: FilterProps ) {\n\tconst toggleRef = useRef< HTMLDivElement >( null );\n\tconst { filter, view, onChangeView } = commonProps;\n\tconst filterInView = view.filters?.find(\n\t\t( f ) => f.field === filter.field\n\t);\n\n\tlet activeElements: Option[] = [];\n\tconst field = useMemo( () => {\n\t\tconst currentField = fields.find( ( f ) => f.id === filter.field );\n\t\tif ( currentField ) {\n\t\t\treturn {\n\t\t\t\t...currentField,\n\t\t\t\t// Configure getValue as if Item was a plain object.\n\t\t\t\t// See related input-widget.tsx\n\t\t\t\tgetValue: ( { item }: { item: any } ) =>\n\t\t\t\t\titem[ currentField.id ],\n\t\t\t};\n\t\t}\n\n\t\treturn currentField;\n\t}, [ fields, filter.field ] );\n\n\tconst { elements } = useElements( {\n\t\telements: filter.elements,\n\t\tgetElements: filter.getElements,\n\t} );\n\n\tif ( elements.length > 0 ) {\n\t\t// When there are elements, we favor those\n\t\tactiveElements = elements.filter( ( element ) => {\n\t\t\tif ( filter.singleSelection ) {\n\t\t\t\treturn element.value === filterInView?.value;\n\t\t\t}\n\t\t\treturn filterInView?.value?.includes( element.value );\n\t\t} );\n\t} else if ( Array.isArray( filterInView?.value ) ) {\n\t\t// or, filterInView.value can also be array\n\t\t// for the between operator, as in [ 1, 2 ]\n\t\tconst label = filterInView.value.map( ( v ) => {\n\t\t\tconst formattedValue = field?.getValueFormatted( {\n\t\t\t\titem: { [ field.id ]: v },\n\t\t\t\tfield,\n\t\t\t} );\n\t\t\treturn formattedValue || String( v );\n\t\t} );\n\n\t\tactiveElements = [\n\t\t\t{\n\t\t\t\tvalue: filterInView.value,\n\t\t\t\t// @ts-ignore\n\t\t\t\tlabel,\n\t\t\t},\n\t\t];\n\t} else if ( typeof filterInView?.value === 'object' ) {\n\t\t// or, it can also be object for the inThePast/over operators,\n\t\t// as in { value: '1', units: 'days' }\n\t\tactiveElements = [\n\t\t\t{ value: filterInView.value, label: filterInView.value },\n\t\t];\n\t} else if ( filterInView?.value !== undefined ) {\n\t\t// otherwise, filterInView.value is a single value\n\t\tconst label =\n\t\t\tfield !== undefined\n\t\t\t\t? field.getValueFormatted( {\n\t\t\t\t\t\titem: { [ field.id ]: filterInView.value },\n\t\t\t\t\t\tfield,\n\t\t\t\t } )\n\t\t\t\t: String( filterInView.value );\n\n\t\tactiveElements = [\n\t\t\t{\n\t\t\t\tvalue: filterInView.value,\n\t\t\t\tlabel,\n\t\t\t},\n\t\t];\n\t}\n\n\tconst isPrimary = filter.isPrimary;\n\tconst isLocked = filterInView?.isLocked;\n\tconst hasValues = ! isLocked && filterInView?.value !== undefined;\n\tconst canResetOrRemove = ! isLocked && ( ! isPrimary || hasValues );\n\treturn (\n\t\t<Dropdown\n\t\t\tdefaultOpen={ openedFilter === filter.field }\n\t\t\tcontentClassName=\"dataviews-filters__summary-popover\"\n\t\t\tpopoverProps={ { placement: 'bottom-start', role: 'dialog' } }\n\t\t\tonClose={ () => {\n\t\t\t\ttoggleRef.current?.focus();\n\t\t\t} }\n\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t<div className=\"dataviews-filters__summary-chip-container\">\n\t\t\t\t\t<Tooltip\n\t\t\t\t\t\ttext={ sprintf(\n\t\t\t\t\t\t\t/* translators: 1: Filter name. */\n\t\t\t\t\t\t\t__( 'Filter by: %1$s' ),\n\t\t\t\t\t\t\tfilter.name.toLowerCase()\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tplacement=\"top\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t'dataviews-filters__summary-chip',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t'has-reset': canResetOrRemove,\n\t\t\t\t\t\t\t\t\t'has-values': hasValues,\n\t\t\t\t\t\t\t\t\t'is-not-clickable': isLocked,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\trole=\"button\"\n\t\t\t\t\t\t\ttabIndex={ isLocked ? -1 : 0 }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tif ( ! isLocked ) {\n\t\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tonKeyDown={ ( event ) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t! isLocked &&\n\t\t\t\t\t\t\t\t\t[ ENTER, SPACE ].includes( event.key )\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\taria-disabled={ isLocked }\n\t\t\t\t\t\t\taria-pressed={ isOpen }\n\t\t\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t\t\t\tref={ toggleRef }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<FilterText\n\t\t\t\t\t\t\t\tactiveElements={ activeElements }\n\t\t\t\t\t\t\t\tfilterInView={ filterInView }\n\t\t\t\t\t\t\t\tfilter={ filter }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</Tooltip>\n\t\t\t\t\t{ canResetOrRemove && (\n\t\t\t\t\t\t<Tooltip\n\t\t\t\t\t\t\ttext={ isPrimary ? __( 'Reset' ) : __( 'Remove' ) }\n\t\t\t\t\t\t\tplacement=\"top\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t\t'dataviews-filters__summary-chip-remove',\n\t\t\t\t\t\t\t\t\t{ 'has-values': hasValues }\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\t\t\t\tpage: 1,\n\t\t\t\t\t\t\t\t\t\tfilters: view.filters?.filter(\n\t\t\t\t\t\t\t\t\t\t\t( _filter ) =>\n\t\t\t\t\t\t\t\t\t\t\t\t_filter.field !== filter.field\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t\t// If the filter is not primary and can be removed, it will be added\n\t\t\t\t\t\t\t\t\t// back to the available filters from `Add filter` component.\n\t\t\t\t\t\t\t\t\tif ( ! isPrimary ) {\n\t\t\t\t\t\t\t\t\t\taddFilterRef.current?.focus();\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t// If is primary, focus the toggle button.\n\t\t\t\t\t\t\t\t\t\ttoggleRef.current?.focus();\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<Icon icon={ closeSmall } />\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\trenderContent={ () => {\n\t\t\t\treturn (\n\t\t\t\t\t<Stack direction=\"column\" justify=\"flex-start\">\n\t\t\t\t\t\t<OperatorSelector { ...commonProps } />\n\t\t\t\t\t\t{ commonProps.filter.hasElements ? (\n\t\t\t\t\t\t\t<SearchWidget\n\t\t\t\t\t\t\t\t{ ...commonProps }\n\t\t\t\t\t\t\t\tfilter={ {\n\t\t\t\t\t\t\t\t\t...commonProps.filter,\n\t\t\t\t\t\t\t\t\telements,\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t<InputWidget { ...commonProps } fields={ fields } />\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Stack>\n\t\t\t\t);\n\t\t\t} }\n\t\t/>\n\t);\n}\n"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport type { RefObject } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tDropdown,\n\tFlexItem,\n\tSelectControl,\n\tTooltip,\n\tIcon,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useMemo, useRef } from '@wordpress/element';\nimport { closeSmall } from '@wordpress/icons';\nimport { Stack } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport SearchWidget from './search-widget';\nimport InputWidget from './input-widget';\nimport { getOperatorByName } from '../../utils/operators';\nimport type {\n\tFilter,\n\tNormalizedField,\n\tNormalizedFilter,\n\tOperator,\n\tOption,\n\tView,\n} from '../../types';\nimport useElements from '../../hooks/use-elements';\n\nconst ENTER = 'Enter';\nconst SPACE = ' ';\n\ninterface FilterTextProps {\n\tactiveElements: Option[];\n\tfilterInView?: Filter;\n\tfilter: NormalizedFilter;\n}\n\ninterface OperatorSelectorProps {\n\tfilter: NormalizedFilter;\n\tview: View;\n\tonChangeView: ( view: View ) => void;\n}\n\ninterface FilterProps extends OperatorSelectorProps {\n\taddFilterRef: RefObject< HTMLButtonElement | null >;\n\topenedFilter: string | null;\n\tfields: NormalizedField< any >[];\n}\n\nconst FilterText = ( {\n\tactiveElements,\n\tfilterInView,\n\tfilter,\n}: FilterTextProps ) => {\n\tif ( activeElements === undefined || activeElements.length === 0 ) {\n\t\treturn filter.name;\n\t}\n\n\tconst operator = getOperatorByName( filterInView?.operator );\n\tif ( operator !== undefined ) {\n\t\treturn operator.filterText( filter, activeElements );\n\t}\n\n\treturn sprintf(\n\t\t/* translators: 1: Filter name e.g.: \"Unknown status for Author\". */\n\t\t__( 'Unknown status for %1$s' ),\n\t\tfilter.name\n\t);\n};\n\nfunction OperatorSelector( {\n\tfilter,\n\tview,\n\tonChangeView,\n}: OperatorSelectorProps ) {\n\tconst operatorOptions = filter.operators?.map( ( operator ) => ( {\n\t\tvalue: operator,\n\t\tlabel: getOperatorByName( operator )?.label || operator,\n\t} ) );\n\tconst currentFilter = view.filters?.find(\n\t\t( _filter ) => _filter.field === filter.field\n\t);\n\tconst value = currentFilter?.operator || filter.operators[ 0 ];\n\treturn (\n\t\toperatorOptions.length > 1 && (\n\t\t\t<Stack\n\t\t\t\tdirection=\"row\"\n\t\t\t\tgap=\"sm\"\n\t\t\t\tjustify=\"flex-start\"\n\t\t\t\tclassName=\"dataviews-filters__summary-operators-container\"\n\t\t\t\talign=\"center\"\n\t\t\t>\n\t\t\t\t<FlexItem className=\"dataviews-filters__summary-operators-filter-name\">\n\t\t\t\t\t{ filter.name }\n\t\t\t\t</FlexItem>\n\n\t\t\t\t<SelectControl\n\t\t\t\t\tclassName=\"dataviews-filters__summary-operators-filter-select\"\n\t\t\t\t\tlabel={ __( 'Conditions' ) }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\toptions={ operatorOptions }\n\t\t\t\t\tonChange={ ( newValue ) => {\n\t\t\t\t\t\tconst newOperator = newValue as Operator;\n\t\t\t\t\t\tconst currentOperator = currentFilter?.operator;\n\t\t\t\t\t\tconst newFilters = currentFilter\n\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t...( view.filters ?? [] ).map(\n\t\t\t\t\t\t\t\t\t\t( _filter ) => {\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t_filter.field === filter.field\n\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\tconst currentOpSelectionModel =\n\t\t\t\t\t\t\t\t\t\t\t\t\tgetOperatorByName(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentOperator\n\t\t\t\t\t\t\t\t\t\t\t\t\t)?.selection;\n\t\t\t\t\t\t\t\t\t\t\t\tconst newOpSelectionModel =\n\t\t\t\t\t\t\t\t\t\t\t\t\tgetOperatorByName(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnewOperator\n\t\t\t\t\t\t\t\t\t\t\t\t\t)?.selection;\n\n\t\t\t\t\t\t\t\t\t\t\t\tconst shouldResetValue =\n\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentOpSelectionModel !==\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnewOpSelectionModel ||\n\t\t\t\t\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentOpSelectionModel,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnewOpSelectionModel,\n\t\t\t\t\t\t\t\t\t\t\t\t\t].includes( 'custom' );\n\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\t..._filter,\n\t\t\t\t\t\t\t\t\t\t\t\t\tvalue: shouldResetValue\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t: _filter.value,\n\t\t\t\t\t\t\t\t\t\t\t\t\toperator: newOperator,\n\t\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\treturn _filter;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t...( view.filters ?? [] ),\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tfield: filter.field,\n\t\t\t\t\t\t\t\t\t\toperator: newOperator,\n\t\t\t\t\t\t\t\t\t\tvalue: undefined,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t ];\n\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\tpage: 1,\n\t\t\t\t\t\t\tfilters: newFilters,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tsize=\"small\"\n\t\t\t\t\tvariant=\"minimal\"\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t/>\n\t\t\t</Stack>\n\t\t)\n\t);\n}\n\nexport default function Filter( {\n\taddFilterRef,\n\topenedFilter,\n\tfields,\n\t...commonProps\n}: FilterProps ) {\n\tconst toggleRef = useRef< HTMLDivElement >( null );\n\tconst { filter, view, onChangeView } = commonProps;\n\tconst filterInView = view.filters?.find(\n\t\t( f ) => f.field === filter.field\n\t);\n\n\tlet activeElements: Option[] = [];\n\tconst field = useMemo( () => {\n\t\tconst currentField = fields.find( ( f ) => f.id === filter.field );\n\t\tif ( currentField ) {\n\t\t\treturn {\n\t\t\t\t...currentField,\n\t\t\t\t// Configure getValue as if Item was a plain object.\n\t\t\t\t// See related input-widget.tsx\n\t\t\t\tgetValue: ( { item }: { item: any } ) =>\n\t\t\t\t\titem[ currentField.id ],\n\t\t\t};\n\t\t}\n\n\t\treturn currentField;\n\t}, [ fields, filter.field ] );\n\n\tconst { elements } = useElements( {\n\t\telements: filter.elements,\n\t\tgetElements: filter.getElements,\n\t} );\n\n\tif ( elements.length > 0 ) {\n\t\t// When there are elements, we favor those\n\t\tactiveElements = elements.filter( ( element ) => {\n\t\t\tif ( filter.singleSelection ) {\n\t\t\t\treturn element.value === filterInView?.value;\n\t\t\t}\n\t\t\treturn filterInView?.value?.includes( element.value );\n\t\t} );\n\t} else if ( Array.isArray( filterInView?.value ) ) {\n\t\t// or, filterInView.value can also be array\n\t\t// for the between operator, as in [ 1, 2 ]\n\t\tconst label = filterInView.value.map( ( v ) => {\n\t\t\tconst formattedValue = field?.getValueFormatted( {\n\t\t\t\titem: { [ field.id ]: v },\n\t\t\t\tfield,\n\t\t\t} );\n\t\t\treturn formattedValue || String( v );\n\t\t} );\n\n\t\tactiveElements = [\n\t\t\t{\n\t\t\t\tvalue: filterInView.value,\n\t\t\t\t// @ts-ignore\n\t\t\t\tlabel,\n\t\t\t},\n\t\t];\n\t} else if ( typeof filterInView?.value === 'object' ) {\n\t\t// or, it can also be object for the inThePast/over operators,\n\t\t// as in { value: '1', units: 'days' }\n\t\tactiveElements = [\n\t\t\t{ value: filterInView.value, label: filterInView.value },\n\t\t];\n\t} else if ( filterInView?.value !== undefined ) {\n\t\t// otherwise, filterInView.value is a single value\n\t\tconst label =\n\t\t\tfield !== undefined\n\t\t\t\t? field.getValueFormatted( {\n\t\t\t\t\t\titem: { [ field.id ]: filterInView.value },\n\t\t\t\t\t\tfield,\n\t\t\t\t } )\n\t\t\t\t: String( filterInView.value );\n\n\t\tactiveElements = [\n\t\t\t{\n\t\t\t\tvalue: filterInView.value,\n\t\t\t\tlabel,\n\t\t\t},\n\t\t];\n\t}\n\n\tconst isPrimary = filter.isPrimary;\n\tconst isLocked = filterInView?.isLocked;\n\tconst hasValues = ! isLocked && filterInView?.value !== undefined;\n\tconst canResetOrRemove = ! isLocked && ( ! isPrimary || hasValues );\n\treturn (\n\t\t<Dropdown\n\t\t\tdefaultOpen={ openedFilter === filter.field }\n\t\t\tcontentClassName=\"dataviews-filters__summary-popover\"\n\t\t\tpopoverProps={ { placement: 'bottom-start', role: 'dialog' } }\n\t\t\tonClose={ () => {\n\t\t\t\ttoggleRef.current?.focus();\n\t\t\t} }\n\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t<div className=\"dataviews-filters__summary-chip-container\">\n\t\t\t\t\t<Tooltip\n\t\t\t\t\t\ttext={ sprintf(\n\t\t\t\t\t\t\t/* translators: 1: Filter name. */\n\t\t\t\t\t\t\t__( 'Filter by: %1$s' ),\n\t\t\t\t\t\t\tfilter.name.toLowerCase()\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tplacement=\"top\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t'dataviews-filters__summary-chip',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t'has-reset': canResetOrRemove,\n\t\t\t\t\t\t\t\t\t'has-values': hasValues,\n\t\t\t\t\t\t\t\t\t'is-not-clickable': isLocked,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\trole=\"button\"\n\t\t\t\t\t\t\ttabIndex={ isLocked ? -1 : 0 }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tif ( ! isLocked ) {\n\t\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tonKeyDown={ ( event ) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t! isLocked &&\n\t\t\t\t\t\t\t\t\t[ ENTER, SPACE ].includes( event.key )\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\taria-disabled={ isLocked }\n\t\t\t\t\t\t\taria-pressed={ isOpen }\n\t\t\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t\t\t\tref={ toggleRef }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<FilterText\n\t\t\t\t\t\t\t\tactiveElements={ activeElements }\n\t\t\t\t\t\t\t\tfilterInView={ filterInView }\n\t\t\t\t\t\t\t\tfilter={ filter }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</Tooltip>\n\t\t\t\t\t{ canResetOrRemove && (\n\t\t\t\t\t\t<Tooltip\n\t\t\t\t\t\t\ttext={ isPrimary ? __( 'Reset' ) : __( 'Remove' ) }\n\t\t\t\t\t\t\tplacement=\"top\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t\t'dataviews-filters__summary-chip-remove',\n\t\t\t\t\t\t\t\t\t{ 'has-values': hasValues }\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\t\t\t\tpage: 1,\n\t\t\t\t\t\t\t\t\t\tfilters: view.filters?.filter(\n\t\t\t\t\t\t\t\t\t\t\t( _filter ) =>\n\t\t\t\t\t\t\t\t\t\t\t\t_filter.field !== filter.field\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t\t// If the filter is not primary and can be removed, it will be added\n\t\t\t\t\t\t\t\t\t// back to the available filters from `Add filter` component.\n\t\t\t\t\t\t\t\t\tif ( ! isPrimary ) {\n\t\t\t\t\t\t\t\t\t\taddFilterRef.current?.focus();\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t// If is primary, focus the toggle button.\n\t\t\t\t\t\t\t\t\t\ttoggleRef.current?.focus();\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<Icon icon={ closeSmall } />\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\trenderContent={ () => {\n\t\t\t\treturn (\n\t\t\t\t\t<Stack direction=\"column\" justify=\"flex-start\">\n\t\t\t\t\t\t<OperatorSelector { ...commonProps } />\n\t\t\t\t\t\t{ commonProps.filter.hasElements ? (\n\t\t\t\t\t\t\t<SearchWidget\n\t\t\t\t\t\t\t\t{ ...commonProps }\n\t\t\t\t\t\t\t\tfilter={ {\n\t\t\t\t\t\t\t\t\t...commonProps.filter,\n\t\t\t\t\t\t\t\t\telements,\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t<InputWidget { ...commonProps } fields={ fields } />\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Stack>\n\t\t\t\t);\n\t\t\t} }\n\t\t/>\n\t);\n}\n"],
|
|
5
5
|
"mappings": ";AAGA,OAAO,UAAU;AAMjB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,IAAI,eAAe;AAC5B,SAAS,SAAS,cAAc;AAChC,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AAKtB,OAAO,kBAAkB;AACzB,OAAO,iBAAiB;AACxB,SAAS,yBAAyB;AASlC,OAAO,iBAAiB;AA2DrB,SAOC,KAPD;AAzDH,IAAM,QAAQ;AACd,IAAM,QAAQ;AAoBd,IAAM,aAAa,CAAE;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AACD,MAAwB;AACvB,MAAK,mBAAmB,UAAa,eAAe,WAAW,GAAI;AAClE,WAAO,OAAO;AAAA,EACf;AAEA,QAAM,WAAW,kBAAmB,cAAc,QAAS;AAC3D,MAAK,aAAa,QAAY;AAC7B,WAAO,SAAS,WAAY,QAAQ,cAAe;AAAA,EACpD;AAEA,SAAO;AAAA;AAAA,IAEN,GAAI,yBAA0B;AAAA,IAC9B,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