From cfe2cc0c245c63008c778bf5389ae287e84ec118 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Mon, 16 Dec 2024 18:07:02 +0000 Subject: [PATCH 01/10] Add: Media field changing ui to Dataviews and content preview field to posts and pages. --- .../dataviews-view-config/index.tsx | 204 ++++++++++++++++-- .../dataviews-view-config/style.scss | 17 +- packages/dataviews/src/types.ts | 5 + packages/editor/README.md | 2 +- .../editor/src/components/provider/index.js | 2 +- .../content-preview/content-preview-view.tsx | 108 ++++++++++ .../fields/content-preview/index.tsx | 22 ++ .../fields/content-preview/style.scss | 21 ++ .../src/dataviews/store/private-actions.ts | 2 + packages/editor/src/style.scss | 1 + packages/fields/README.md | 4 + .../fields/src/fields/featured-image/index.ts | 1 + packages/fields/src/index.ts | 2 +- 13 files changed, 364 insertions(+), 27 deletions(-) create mode 100644 packages/editor/src/dataviews/fields/content-preview/content-preview-view.tsx create mode 100644 packages/editor/src/dataviews/fields/content-preview/index.tsx create mode 100644 packages/editor/src/dataviews/fields/content-preview/style.scss diff --git a/packages/dataviews/src/components/dataviews-view-config/index.tsx b/packages/dataviews/src/components/dataviews-view-config/index.tsx index 0b3512714e14a4..c1fe6b130a1610 100644 --- a/packages/dataviews/src/components/dataviews-view-config/index.tsx +++ b/packages/dataviews/src/components/dataviews-view-config/index.tsx @@ -1,7 +1,8 @@ /** * External dependencies */ -import type { ChangeEvent } from 'react'; +import type { ChangeEvent, ReactNode } from 'react'; +import clsx from 'clsx'; /** * WordPress dependencies @@ -26,7 +27,7 @@ import { Icon, } from '@wordpress/components'; import { __, _x, sprintf } from '@wordpress/i18n'; -import { memo, useContext, useMemo } from '@wordpress/element'; +import { memo, useContext, useMemo, useState } from '@wordpress/element'; import { chevronDown, chevronUp, @@ -34,6 +35,7 @@ import { seen, unseen, lock, + moreVertical, } from '@wordpress/icons'; import warning from '@wordpress/warning'; import { useInstanceId } from '@wordpress/compose'; @@ -253,24 +255,34 @@ function ItemsPerPageControl() { ); } -function FieldItem( { - field, +function BaseFieldItem( { + fieldId, + label, + subLabel, isVisible, isFirst, isLast, canMove = true, + canHide = true, + isInteracting = false, onToggleVisibility, onMoveUp, onMoveDown, + additionalActions, }: { - field: NormalizedField< any >; + fieldId: string; + label: string; + subLabel?: string; isVisible: boolean; isFirst?: boolean; isLast?: boolean; canMove?: boolean; + canHide?: boolean; + isInteracting?: boolean; onToggleVisibility?: () => void; onMoveUp?: () => void; onMoveDown?: () => void; + additionalActions?: ReactNode; } ) { const focusVisibilityField = () => { // Focus the visibility button to avoid focus loss. @@ -278,7 +290,7 @@ function FieldItem( { // eslint-disable-next-line @wordpress/react-no-unsafe-timeout setTimeout( () => { const element = document.querySelector( - `.dataviews-field-control__field-${ field.id } .dataviews-field-control__field-visibility-button` + `.dataviews-field-control__field-${ fieldId } .dataviews-field-control__field-visibility-button` ); if ( element instanceof HTMLElement ) { element.focus(); @@ -290,16 +302,25 @@ function FieldItem( { - { ! canMove && ! field.enableHiding && ( - - ) } + { ! canMove && ! canHide && } + - { field.label } + { label } + + { subLabel && ( + + { subLabel } + + ) } @@ -336,7 +357,7 @@ function FieldItem( { : sprintf( /* translators: %s: field label */ __( 'Move %s down' ), - field.label + label ) } /> @@ -345,7 +366,7 @@ function FieldItem( { { onToggleVisibility && (