sanity-plugin-recurring-dates 1.2.0 → 1.3.0

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/dist/index.d.ts CHANGED
@@ -16,9 +16,9 @@ export declare interface PluginConfig {
16
16
  }
17
17
 
18
18
  export declare interface RecurringDate {
19
- rrule: string
20
- startDate: string
21
- endDate: string
19
+ rrule?: string
20
+ startDate?: string
21
+ endDate?: string
22
22
  }
23
23
 
24
24
  export declare type RecurringDateFieldOptions = Omit<ObjectDefinition, 'type' | 'fields'> & {
package/dist/index.esm.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { set, unset, ObjectInputMember, defineField, definePlugin } from 'sanity';
2
+ import { ChevronLeftIcon, ChevronRightIcon, CalendarIcon, WarningOutlineIcon, TrashIcon } from '@sanity/icons';
2
3
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
4
  import { Card, Text, Box, Grid, TextInput, useForwardedRef, Flex, Select, Button, useClickOutside, LayerProvider, Popover, Stack, Dialog, Radio } from '@sanity/ui';
4
5
  import { range, upperFirst } from 'lodash';
@@ -6,8 +7,7 @@ import * as React from 'react';
6
7
  import React__default, { useState, useEffect, PureComponent, useCallback, forwardRef, useRef, useMemo } from 'react';
7
8
  import { rrulestr, Weekday, RRule } from 'rrule';
8
9
  import { Feedback } from 'sanity-plugin-utils';
9
- import { format, parse } from '@sanity/util/legacyDateFormat';
10
- import { ChevronLeftIcon, ChevronRightIcon, CalendarIcon, WarningOutlineIcon, TrashIcon } from '@sanity/icons';
10
+ import { format, parse, DEFAULT_DATE_FORMAT as DEFAULT_DATE_FORMAT$1, DEFAULT_TIME_FORMAT } from '@sanity/util/legacyDateFormat';
11
11
  const DEFAULT_RECURRENCES = ["RRULE:FREQ=DAILY;INTERVAL=1", "RRULE:FREQ=WEEKLY;INTERVAL=1", "RRULE:FREQ=MONTHLY;INTERVAL=1", "RRULE:FREQ=YEARLY;INTERVAL=1"];
12
12
  const DEFAULT_CONFIG = {
13
13
  defaultRecurrences: DEFAULT_RECURRENCES
@@ -4664,6 +4664,49 @@ function RecurringDates(props) {
4664
4664
  })]
4665
4665
  });
4666
4666
  }
4667
+ function RecurringDatesPreview(props) {
4668
+ const {
4669
+ startDate,
4670
+ endDate,
4671
+ rrule,
4672
+ schemaType,
4673
+ pluginConfig
4674
+ } = props;
4675
+ const options = schemaType?.options;
4676
+ const {
4677
+ dateTimeOptions,
4678
+ dateOnly
4679
+ } = {
4680
+ ...pluginConfig,
4681
+ ...options
4682
+ };
4683
+ const rule = rrule && rrulestr(rrule);
4684
+ const dateFormat = dateTimeOptions?.dateFormat || DEFAULT_DATE_FORMAT$1;
4685
+ const timeFormat = dateTimeOptions?.timeFormat || DEFAULT_TIME_FORMAT;
4686
+ const start = startDate ? new Date(startDate) : void 0;
4687
+ const end = endDate ? new Date(endDate) : void 0;
4688
+ const sameDay = start && end && start.toDateString() === end.toDateString();
4689
+ let title = "No start date";
4690
+ if (dateOnly) {
4691
+ title = start ? format(start, dateFormat) : "No start date";
4692
+ if (end && !sameDay) {
4693
+ title += ` - ${format(end, dateFormat)}`;
4694
+ }
4695
+ } else {
4696
+ title = start ? format(start, `${dateFormat} ${timeFormat}`) : "No start date";
4697
+ if (end) {
4698
+ title += ` - ${format(end, sameDay ? timeFormat : `${dateFormat} ${timeFormat}`)}`;
4699
+ }
4700
+ }
4701
+ const previewProps = {
4702
+ title,
4703
+ subtitle: rule && upperFirst(rule.toText())
4704
+ };
4705
+ return props.renderDefault({
4706
+ ...previewProps,
4707
+ ...props
4708
+ });
4709
+ }
4667
4710
  var recurringDateSchema = config => {
4668
4711
  const {
4669
4712
  dateTimeOptions,
@@ -4674,6 +4717,7 @@ var recurringDateSchema = config => {
4674
4717
  name: "recurringDates",
4675
4718
  title: "Dates",
4676
4719
  type: "object",
4720
+ icon: CalendarIcon,
4677
4721
  fields: [defineField({
4678
4722
  title: "Start Date",
4679
4723
  name: "startDate",
@@ -4700,7 +4744,18 @@ var recurringDateSchema = config => {
4700
4744
  input: props => RecurringDates({
4701
4745
  ...props,
4702
4746
  pluginConfig: config
4747
+ }),
4748
+ preview: props => RecurringDatesPreview({
4749
+ ...props,
4750
+ pluginConfig: config
4703
4751
  })
4752
+ },
4753
+ preview: {
4754
+ select: {
4755
+ startDate: "startDate",
4756
+ endDate: "endDate",
4757
+ rrule: "rrule"
4758
+ }
4704
4759
  }
4705
4760
  });
4706
4761
  };