{"version":3,"file":"revisions-list.cjs","names":["getDate","dateI18n","getSettings","humanTimeDiff","getGlobalStylesChanges","__","sprintf","useSelect","coreStore","useMemo","Badge","DataViewsPicker"],"sources":["../../src/screen-revisions/revisions-list.tsx"],"sourcesContent":["import { __, sprintf } from '@wordpress/i18n';\nimport { dateI18n, getDate, humanTimeDiff, getSettings } from '@wordpress/date';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\nimport { useMemo } from '@wordpress/element';\nimport { getGlobalStylesChanges } from '@wordpress/global-styles-engine';\nimport { DataViewsPicker } from '@wordpress/dataviews';\nimport type {\n\tActionButton,\n\tField,\n\tSupportedLayouts,\n\tView,\n} from '@wordpress/dataviews';\nimport { Badge } from '@wordpress/ui';\nimport type { Revision } from './types';\n\nconst DAY_IN_MILLISECONDS = 60 * 60 * 1000 * 24;\nconst DEFAULT_LAYOUTS: SupportedLayouts = { pickerActivity: true };\n\nconst getItemId = ( item: Revision ) => String( item.id );\n\nfunction normalizeModified(\n\tmodified: Revision[ 'modified' ]\n): string | undefined {\n\t// Convert modified to string if it's a Date, for type compatibility.\n\treturn modified instanceof Date ? modified.toISOString() : modified;\n}\n\nfunction getDisplayDate( modified: Revision[ 'modified' ] ): string {\n\tconst modifiedString = normalizeModified( modified );\n\tconst modifiedDate = getDate( modifiedString ?? null );\n\tconst dateNowInMs = getDate( null ).getTime();\n\treturn modifiedString &&\n\t\tdateNowInMs - modifiedDate.getTime() > DAY_IN_MILLISECONDS\n\t\t? dateI18n( getSettings().formats.datetimeAbbreviated, modifiedDate )\n\t\t: humanTimeDiff( modifiedString ?? modifiedDate, undefined );\n}\n\ninterface ChangesSummaryProps {\n\trevision: Revision;\n\tpreviousRevision?: Revision;\n}\n\nfunction ChangesSummary( { revision, previousRevision }: ChangesSummaryProps ) {\n\tconst changes: string[] = getGlobalStylesChanges(\n\t\trevision,\n\t\tpreviousRevision,\n\t\t{\n\t\t\tmaxResults: 7,\n\t\t}\n\t);\n\n\tif ( ! changes.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<ul\n\t\t\tdata-testid=\"global-styles-revision-changes\"\n\t\t\tclassName=\"global-styles-ui-screen-revisions__changes\"\n\t\t>\n\t\t\t{ changes.map( ( change ) => (\n\t\t\t\t<li key={ change }>{ change }</li>\n\t\t\t) ) }\n\t\t</ul>\n\t);\n}\n\n/**\n * Returns a label for the revision, also used as the option's accessible name.\n * @param id\n * @param authorDisplayName\n * @param formattedModifiedDate\n * @param areStylesEqual\n */\nfunction getRevisionLabel(\n\tid: string | number,\n\tauthorDisplayName: string,\n\tformattedModifiedDate: string,\n\tareStylesEqual: boolean\n): string {\n\tif ( 'parent' === id ) {\n\t\treturn __( 'Reset the styles to the theme defaults' );\n\t}\n\n\tif ( 'unsaved' === id ) {\n\t\treturn sprintf(\n\t\t\t/* translators: %s: author display name */\n\t\t\t__( 'Unsaved changes by %s' ),\n\t\t\tauthorDisplayName\n\t\t);\n\t}\n\n\treturn areStylesEqual\n\t\t? sprintf(\n\t\t\t\t// translators: 1: author display name. 2: revision creation date.\n\t\t\t\t__(\n\t\t\t\t\t'Changes saved by %1$s on %2$s. This revision matches current editor styles.'\n\t\t\t\t),\n\t\t\t\tauthorDisplayName,\n\t\t\t\tformattedModifiedDate\n\t\t\t)\n\t\t: sprintf(\n\t\t\t\t// translators: 1: author display name. 2: revision creation date.\n\t\t\t\t__( 'Changes saved by %1$s on %2$s' ),\n\t\t\t\tauthorDisplayName,\n\t\t\t\tformattedModifiedDate\n\t\t\t);\n}\n\ninterface RevisionsListProps {\n\trevisions: Revision[];\n\tview: View;\n\tonChangeView: ( view: View ) => void;\n\tselection: string[];\n\tonChangeSelection: ( selection: string[] ) => void;\n\tisLoading?: boolean;\n\tpaginationInfo: { totalItems: number; totalPages: number };\n\tcanApplyRevision?: boolean;\n\tactions?: ActionButton< Revision >[];\n}\n\n/**\n * Renders the revisions timeline using the DataViews picker activity layout.\n * @param root0\n * @param root0.revisions\n * @param root0.view\n * @param root0.onChangeView\n * @param root0.selection\n * @param root0.onChangeSelection\n * @param root0.isLoading\n * @param root0.paginationInfo\n * @param root0.canApplyRevision\n * @param root0.actions\n */\nfunction RevisionsList( {\n\trevisions,\n\tview,\n\tonChangeView,\n\tselection,\n\tonChangeSelection,\n\tisLoading,\n\tpaginationInfo,\n\tcanApplyRevision,\n\tactions,\n}: RevisionsListProps ) {\n\tconst { currentThemeName, currentUser } = useSelect( ( select ) => {\n\t\tconst { getCurrentTheme, getCurrentUser } = select( coreStore );\n\t\tconst currentTheme = getCurrentTheme();\n\t\treturn {\n\t\t\tcurrentThemeName:\n\t\t\t\tcurrentTheme?.name?.rendered || currentTheme?.stylesheet,\n\t\t\tcurrentUser: getCurrentUser(),\n\t\t};\n\t}, [] );\n\n\tconst fields: Field< Revision >[] = useMemo( () => {\n\t\tconst getAuthor = ( revision: Revision ) =>\n\t\t\t// Unsaved changes are created by the current user.\n\t\t\t'unsaved' === revision.id ? currentUser : revision.author;\n\t\tconst getAuthorDisplayName = ( revision: Revision ) =>\n\t\t\tgetAuthor( revision )?.name || __( 'User' );\n\t\tconst isSelected = ( revision: Revision ) =>\n\t\t\tselection.includes( String( revision.id ) );\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tid: 'date',\n\t\t\t\tlabel: __( 'Date' ),\n\t\t\t\t// The value is used as the option's accessible name, so it\n\t\t\t\t// carries the full revision description rather than the\n\t\t\t\t// shorter date the row renders.\n\t\t\t\tgetValue: ( { item } ) => {\n\t\t\t\t\tconst formattedModifiedDate =\n\t\t\t\t\t\t'parent' === item.id || 'unsaved' === item.id\n\t\t\t\t\t\t\t? ''\n\t\t\t\t\t\t\t: dateI18n(\n\t\t\t\t\t\t\t\t\tgetSettings().formats.datetimeAbbreviated,\n\t\t\t\t\t\t\t\t\tgetDate(\n\t\t\t\t\t\t\t\t\t\tnormalizeModified( item.modified ) ??\n\t\t\t\t\t\t\t\t\t\t\tnull\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\treturn getRevisionLabel(\n\t\t\t\t\t\titem.id,\n\t\t\t\t\t\tgetAuthorDisplayName( item ),\n\t\t\t\t\t\tformattedModifiedDate,\n\t\t\t\t\t\t! canApplyRevision && isSelected( item )\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\trender: ( { item } ) => {\n\t\t\t\t\tif ( 'parent' === item.id ) {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<span className=\"global-styles-ui-screen-revisions__date\">\n\t\t\t\t\t\t\t\t{ __( 'Default styles' ) }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif ( 'unsaved' === item.id ) {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<span className=\"global-styles-ui-screen-revisions__date\">\n\t\t\t\t\t\t\t\t{ __( '(Unsaved)' ) }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<time\n\t\t\t\t\t\t\tclassName=\"global-styles-ui-screen-revisions__date\"\n\t\t\t\t\t\t\tdateTime={ normalizeModified( item.modified ) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ getDisplayDate( item.modified ) }\n\t\t\t\t\t\t</time>\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tenableSorting: false,\n\t\t\t\tenableHiding: false,\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: 'details',\n\t\t\t\tlabel: __( 'Details' ),\n\t\t\t\trender: ( { item } ) => {\n\t\t\t\t\tconst authorDisplayName = getAuthorDisplayName( item );\n\t\t\t\t\tconst isReset = 'parent' === item.id;\n\t\t\t\t\t// The reset entry shows the theme name in the meta slot.\n\t\t\t\t\tconst meta = isReset ? (\n\t\t\t\t\t\t<span className=\"global-styles-ui-screen-revisions__meta\">\n\t\t\t\t\t\t\t{ currentThemeName }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<span className=\"global-styles-ui-screen-revisions__meta\">\n\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\talt={ authorDisplayName }\n\t\t\t\t\t\t\t\tsrc={ getAuthor( item )?.avatar_urls?.[ '48' ] }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t{ authorDisplayName }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t);\n\n\t\t\t\t\tif ( ! isSelected( item ) ) {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<span className=\"global-styles-ui-screen-revisions__description\">\n\t\t\t\t\t\t\t\t{ meta }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\t// DataViews clones items, so the previous revision must be\n\t\t\t\t\t// resolved by id against the fetched page.\n\t\t\t\t\tconst index = revisions.findIndex(\n\t\t\t\t\t\t( revision ) =>\n\t\t\t\t\t\t\tString( revision.id ) === String( item.id )\n\t\t\t\t\t);\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<span className=\"global-styles-ui-screen-revisions__description\">\n\t\t\t\t\t\t\t{ meta }\n\t\t\t\t\t\t\t{ ! isReset && (\n\t\t\t\t\t\t\t\t<ChangesSummary\n\t\t\t\t\t\t\t\t\trevision={ revisions[ index ] ?? item }\n\t\t\t\t\t\t\t\t\tpreviousRevision={\n\t\t\t\t\t\t\t\t\t\tindex >= 0\n\t\t\t\t\t\t\t\t\t\t\t? revisions[ index + 1 ]\n\t\t\t\t\t\t\t\t\t\t\t: undefined\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{ ! canApplyRevision && (\n\t\t\t\t\t\t\t\t<Badge intent=\"informational\">\n\t\t\t\t\t\t\t\t\t{ __( 'Active' ) }\n\t\t\t\t\t\t\t\t</Badge>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tenableSorting: false,\n\t\t\t\tenableHiding: false,\n\t\t\t},\n\t\t];\n\t}, [\n\t\tselection,\n\t\tcanApplyRevision,\n\t\tcurrentUser,\n\t\tcurrentThemeName,\n\t\trevisions,\n\t] );\n\n\treturn (\n\t\t<div className=\"global-styles-ui-screen-revisions\">\n\t\t\t<DataViewsPicker\n\t\t\t\tview={ view }\n\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\tfields={ fields }\n\t\t\t\tdata={ revisions }\n\t\t\t\tisLoading={ isLoading }\n\t\t\t\tpaginationInfo={ paginationInfo }\n\t\t\t\tdefaultLayouts={ DEFAULT_LAYOUTS }\n\t\t\t\tgetItemId={ getItemId }\n\t\t\t\tselection={ selection }\n\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\titemListLabel={ __( 'Global styles revisions list' ) }\n\t\t\t\tactions={ actions }\n\t\t\t>\n\t\t\t\t<DataViewsPicker.Layout />\n\t\t\t\t{ /* The sidebar has no room for both pagination controls next\n\t\t\t\t     to the action, so the footer holds the page select alone. */ }\n\t\t\t\t<DataViewsPicker.Footer>\n\t\t\t\t\t<DataViewsPicker.Pagination>\n\t\t\t\t\t\t<DataViewsPicker.PageSelect />\n\t\t\t\t\t</DataViewsPicker.Pagination>\n\t\t\t\t\t<DataViewsPicker.Actions className=\"global-styles-ui-screen-revisions__actions\" />\n\t\t\t\t</DataViewsPicker.Footer>\n\t\t\t</DataViewsPicker>\n\t\t</div>\n\t);\n}\n\nexport default RevisionsList;\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,MAAM,sBAAsB;AAC5B,MAAM,kBAAoC,EAAE,gBAAgB,KAAK;AAEjE,MAAM,aAAc,SAAoB,OAAQ,KAAK,EAAG;AAExD,SAAS,kBACR,UACqB;CAErB,OAAO,oBAAoB,OAAO,SAAS,YAAY,IAAI;AAC5D;AAEA,SAAS,eAAgB,UAA2C;CACnE,MAAM,iBAAiB,kBAAmB,QAAS;CACnD,MA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