sanity
Version:
Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches
127 lines (126 loc) • 5.43 kB
JavaScript
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
import { c } from "react/compiler-runtime";
import { CalendarIcon } from "@sanity/icons/Calendar";
import { WarningOutlineIcon } from "@sanity/icons/WarningOutline";
import { Box, Inline, Text, Flex, Badge, Card, Stack } from "@sanity/ui";
import { format } from "date-fns/format";
import { usePublishedId, useValidationState, usePollSchedules, useScheduledPublishingEnabled, DATE_FORMAT, DOCUMENT_HAS_ERRORS_TEXT } from "./index2.js";
function ScheduleBanner(props) {
const $ = c(24), {
id,
markers
} = props, publishedId = usePublishedId(id), {
hasError
} = useValidationState(markers);
let t0;
$[0] !== publishedId ? (t0 = {
documentId: publishedId,
state: "scheduled"
}, $[0] = publishedId, $[1] = t0) : t0 = $[1];
const {
schedules
} = usePollSchedules(t0), {
mode
} = useScheduledPublishingEnabled();
if (!(schedules.length > 0))
return null;
let t1;
$[2] !== mode ? (t1 = mode === "upsell" && /* @__PURE__ */ jsx(Card, { tone: "caution", padding: 3, radius: 3, shadow: 1, marginBottom: 3, children: /* @__PURE__ */ jsxs(Flex, { align: "center", gap: 3, padding: 1, children: [
/* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: /* @__PURE__ */ jsx(WarningOutlineIcon, {}) }),
/* @__PURE__ */ jsx(Text, { muted: !0, size: 1, weight: "medium", children: "Scheduled publishing is not available on your current plan" })
] }) }), $[2] = mode, $[3] = t1) : t1 = $[3];
const t2 = hasError ? "critical" : "primary";
let t3;
$[4] !== mode ? (t3 = mode === "upsell" ? {
opacity: 0.7
} : void 0, $[4] = mode, $[5] = t3) : t3 = $[5];
let t4;
$[6] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t4 = /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: /* @__PURE__ */ jsx(CalendarIcon, {}) }), $[6] = t4) : t4 = $[6];
let t5;
$[7] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t5 = /* @__PURE__ */ jsxs(Flex, { align: "center", gap: 3, marginBottom: 1, padding: 1, children: [
t4,
/* @__PURE__ */ jsxs(Text, { muted: !0, size: 1, children: [
/* @__PURE__ */ jsx("span", { style: {
fontWeight: 600
}, children: "Upcoming schedule" }),
" (local time)"
] })
] }), $[7] = t5) : t5 = $[7];
let t6;
$[8] !== schedules ? (t6 = schedules.map(_temp$1), $[8] = schedules, $[9] = t6) : t6 = $[9];
let t7;
$[10] !== t6 ? (t7 = /* @__PURE__ */ jsx(Stack, { space: 2, children: t6 }), $[10] = t6, $[11] = t7) : t7 = $[11];
let t8;
$[12] !== hasError ? (t8 = hasError && /* @__PURE__ */ jsx(Box, { marginTop: 3, children: /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, weight: "regular", children: DOCUMENT_HAS_ERRORS_TEXT }) }), $[12] = hasError, $[13] = t8) : t8 = $[13];
let t9;
$[14] !== t7 || $[15] !== t8 ? (t9 = /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
t5,
t7,
t8
] }), $[14] = t7, $[15] = t8, $[16] = t9) : t9 = $[16];
let t10;
$[17] !== t2 || $[18] !== t3 || $[19] !== t9 ? (t10 = /* @__PURE__ */ jsx(Card, { padding: 3, radius: 1, shadow: 1, tone: t2, style: t3, children: t9 }), $[17] = t2, $[18] = t3, $[19] = t9, $[20] = t10) : t10 = $[20];
let t11;
return $[21] !== t1 || $[22] !== t10 ? (t11 = /* @__PURE__ */ jsxs(Box, { marginBottom: 4, children: [
t1,
t10
] }), $[21] = t1, $[22] = t10, $[23] = t11) : t11 = $[23], t11;
}
function _temp$1(schedule) {
if (!schedule.executeAt)
return null;
const formattedDateTime = format(new Date(schedule.executeAt), DATE_FORMAT.LARGE);
return /* @__PURE__ */ jsxs(Inline, { space: 2, children: [
/* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: formattedDateTime }),
/* @__PURE__ */ jsx(Flex, { style: {
opacity: schedule.action === "unpublish" ? 1 : 0
}, children: /* @__PURE__ */ jsx(Badge, { fontSize: 0, mode: "outline", children: schedule.action }) })
] }, schedule.id);
}
function ScheduledDocumentInput(props) {
const $ = c(8), {
value,
validation,
children
} = props, doc = value;
let t0;
$[0] !== validation ? (t0 = validation.map(_temp), $[0] = validation, $[1] = t0) : t0 = $[1];
const markers = t0;
let t1;
$[2] !== doc || $[3] !== markers ? (t1 = doc?._id ? /* @__PURE__ */ jsx(ScheduleBanner, { id: doc._id, markers }) : null, $[2] = doc, $[3] = markers, $[4] = t1) : t1 = $[4];
let t2;
return $[5] !== children || $[6] !== t1 ? (t2 = /* @__PURE__ */ jsxs(Fragment, { children: [
t1,
children
] }), $[5] = children, $[6] = t1, $[7] = t2) : t2 = $[7], t2;
}
function _temp(v) {
return {
level: v.level,
path: v.path,
item: {
message: v.message
},
message: v.message
};
}
const DocumentBannerInput = (props) => {
const $ = c(7), {
schemaType
} = props;
if (getRootType(schemaType).name === "document") {
let t02;
$[0] !== props ? (t02 = props.renderDefault(props), $[0] = props, $[1] = t02) : t02 = $[1];
let t1;
return $[2] !== props || $[3] !== t02 ? (t1 = /* @__PURE__ */ jsx(ScheduledDocumentInput, { ...props, children: t02 }), $[2] = props, $[3] = t02, $[4] = t1) : t1 = $[4], t1;
}
let t0;
return $[5] !== props ? (t0 = props.renderDefault(props), $[5] = props, $[6] = t0) : t0 = $[6], t0;
};
function getRootType(type) {
return type.type ? getRootType(type.type) : type;
}
export {
DocumentBannerInput
};
//# sourceMappingURL=inputResolver.js.map