UNPKG

@wordpress/editor

Version:
165 lines (163 loc) 6.44 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/editor/src/components/post-revisions-panel/index.js var post_revisions_panel_exports = {}; __export(post_revisions_panel_exports, { default: () => PostRevisionsPanel }); module.exports = __toCommonJS(post_revisions_panel_exports); var import_components = require("@wordpress/components"); var import_core_data = require("@wordpress/core-data"); var import_dataviews = require("@wordpress/dataviews"); var import_date = require("@wordpress/date"); var import_data = require("@wordpress/data"); var import_i18n = require("@wordpress/i18n"); var import_fields = require("@wordpress/fields"); var import_check = __toESM(require("../post-last-revision/check.cjs")); var import_store = require("../../store/index.cjs"); var import_lock_unlock = require("../../lock-unlock.cjs"); var import_jsx_runtime = require("react/jsx-runtime"); var { Badge } = (0, import_lock_unlock.unlock)(import_components.privateApis); var DAY_IN_MILLISECONDS = 864e5; var EMPTY_ARRAY = []; var REVISIONS_QUERY = { per_page: 3, orderby: "date", order: "desc", context: "embed", _fields: "id,date,author" }; var defaultLayouts = { activity: {} }; var view = { type: "activity", titleField: "date", fields: ["author"], layout: { density: "compact" } }; var fields = [ { id: "date", label: (0, import_i18n.__)("Date"), render: ({ item }) => { const dateNowInMs = (0, import_date.getDate)(null).getTime(); const date = (0, import_date.getDate)(item.date ?? null); const displayDate = dateNowInMs - date.getTime() > DAY_IN_MILLISECONDS ? (0, import_date.dateI18n)( (0, import_date.getSettings)().formats.datetimeAbbreviated, date ) : (0, import_date.humanTimeDiff)(date); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "time", { className: "editor-post-revisions-panel__revision-date", dateTime: item.date, children: displayDate } ); }, enableSorting: false, enableHiding: false }, import_fields.authorField ]; var noop = () => { }; var paginationInfo = {}; function PostRevisionsPanelContent() { const { setCurrentRevisionId } = (0, import_lock_unlock.unlock)((0, import_data.useDispatch)(import_store.store)); const { revisionsCount, revisions, isLoading, lastRevisionId } = (0, import_data.useSelect)( (select) => { const { getCurrentPostId, getCurrentPostType } = select(import_store.store); const { getCurrentPostRevisionsCount, getCurrentPostLastRevisionId } = select(import_store.store); const { getRevisions, isResolving } = select(import_core_data.store); const query = [ "postType", getCurrentPostType(), getCurrentPostId(), REVISIONS_QUERY ]; const _revisions = getRevisions(...query); return { revisionsCount: getCurrentPostRevisionsCount(), lastRevisionId: getCurrentPostLastRevisionId(), revisions: _revisions, isLoading: isResolving("getRevisions", query) }; }, [] ); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.PanelBody, { title: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalHStack, { justify: "space-between", align: "center", as: "span", children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: (0, import_i18n.__)("Revisions") }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Badge, { className: "editor-post-revisions-panel__revisions-count", children: revisionsCount }) ] }), initialOpen: false, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { className: "editor-post-revisions-panel", children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_dataviews.DataViews, { view, onChangeView: noop, fields, data: revisions || EMPTY_ARRAY, isLoading, paginationInfo, defaultLayouts, getItemId: (item) => item.id, isItemClickable: () => true, onClickItem: (item) => { setCurrentRevisionId(item.id); }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dataviews.DataViews.Layout, {}) } ), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.Button, { className: "editor-post-revisions-panel__view-all", __next40pxDefaultSize: true, variant: "secondary", onClick: () => setCurrentRevisionId(lastRevisionId), children: (0, import_i18n.__)("View all revisions") } ) ] }) } ); } function PostRevisionsPanel() { return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_check.default, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PostRevisionsPanelContent, {}) }); } //# sourceMappingURL=index.cjs.map