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 +3 -3
- package/dist/index.esm.js +57 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +56 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/RecurringDatesPreview.tsx +55 -0
- package/src/schema/recurringDates.tsx +11 -0
- package/src/types.ts +3 -3
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
var sanity = require('sanity');
|
|
7
|
+
var icons = require('@sanity/icons');
|
|
7
8
|
var jsxRuntime = require('react/jsx-runtime');
|
|
8
9
|
var ui = require('@sanity/ui');
|
|
9
10
|
var lodash = require('lodash');
|
|
@@ -11,7 +12,6 @@ var React = require('react');
|
|
|
11
12
|
var rrule = require('rrule');
|
|
12
13
|
var sanityPluginUtils = require('sanity-plugin-utils');
|
|
13
14
|
var legacyDateFormat = require('@sanity/util/legacyDateFormat');
|
|
14
|
-
var icons = require('@sanity/icons');
|
|
15
15
|
function _interopNamespaceCompat(e) {
|
|
16
16
|
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
17
17
|
var n = Object.create(null);
|
|
@@ -4688,6 +4688,49 @@ function RecurringDates(props) {
|
|
|
4688
4688
|
})]
|
|
4689
4689
|
});
|
|
4690
4690
|
}
|
|
4691
|
+
function RecurringDatesPreview(props) {
|
|
4692
|
+
const {
|
|
4693
|
+
startDate,
|
|
4694
|
+
endDate,
|
|
4695
|
+
rrule: rrule$1,
|
|
4696
|
+
schemaType,
|
|
4697
|
+
pluginConfig
|
|
4698
|
+
} = props;
|
|
4699
|
+
const options = schemaType?.options;
|
|
4700
|
+
const {
|
|
4701
|
+
dateTimeOptions,
|
|
4702
|
+
dateOnly
|
|
4703
|
+
} = {
|
|
4704
|
+
...pluginConfig,
|
|
4705
|
+
...options
|
|
4706
|
+
};
|
|
4707
|
+
const rule = rrule$1 && rrule.rrulestr(rrule$1);
|
|
4708
|
+
const dateFormat = dateTimeOptions?.dateFormat || legacyDateFormat.DEFAULT_DATE_FORMAT;
|
|
4709
|
+
const timeFormat = dateTimeOptions?.timeFormat || legacyDateFormat.DEFAULT_TIME_FORMAT;
|
|
4710
|
+
const start = startDate ? new Date(startDate) : void 0;
|
|
4711
|
+
const end = endDate ? new Date(endDate) : void 0;
|
|
4712
|
+
const sameDay = start && end && start.toDateString() === end.toDateString();
|
|
4713
|
+
let title = "No start date";
|
|
4714
|
+
if (dateOnly) {
|
|
4715
|
+
title = start ? legacyDateFormat.format(start, dateFormat) : "No start date";
|
|
4716
|
+
if (end && !sameDay) {
|
|
4717
|
+
title += ` - ${legacyDateFormat.format(end, dateFormat)}`;
|
|
4718
|
+
}
|
|
4719
|
+
} else {
|
|
4720
|
+
title = start ? legacyDateFormat.format(start, `${dateFormat} ${timeFormat}`) : "No start date";
|
|
4721
|
+
if (end) {
|
|
4722
|
+
title += ` - ${legacyDateFormat.format(end, sameDay ? timeFormat : `${dateFormat} ${timeFormat}`)}`;
|
|
4723
|
+
}
|
|
4724
|
+
}
|
|
4725
|
+
const previewProps = {
|
|
4726
|
+
title,
|
|
4727
|
+
subtitle: rule && lodash.upperFirst(rule.toText())
|
|
4728
|
+
};
|
|
4729
|
+
return props.renderDefault({
|
|
4730
|
+
...previewProps,
|
|
4731
|
+
...props
|
|
4732
|
+
});
|
|
4733
|
+
}
|
|
4691
4734
|
var recurringDateSchema = config => {
|
|
4692
4735
|
const {
|
|
4693
4736
|
dateTimeOptions,
|
|
@@ -4698,6 +4741,7 @@ var recurringDateSchema = config => {
|
|
|
4698
4741
|
name: "recurringDates",
|
|
4699
4742
|
title: "Dates",
|
|
4700
4743
|
type: "object",
|
|
4744
|
+
icon: icons.CalendarIcon,
|
|
4701
4745
|
fields: [sanity.defineField({
|
|
4702
4746
|
title: "Start Date",
|
|
4703
4747
|
name: "startDate",
|
|
@@ -4724,7 +4768,18 @@ var recurringDateSchema = config => {
|
|
|
4724
4768
|
input: props => RecurringDates({
|
|
4725
4769
|
...props,
|
|
4726
4770
|
pluginConfig: config
|
|
4771
|
+
}),
|
|
4772
|
+
preview: props => RecurringDatesPreview({
|
|
4773
|
+
...props,
|
|
4774
|
+
pluginConfig: config
|
|
4727
4775
|
})
|
|
4776
|
+
},
|
|
4777
|
+
preview: {
|
|
4778
|
+
select: {
|
|
4779
|
+
startDate: "startDate",
|
|
4780
|
+
endDate: "endDate",
|
|
4781
|
+
rrule: "rrule"
|
|
4782
|
+
}
|
|
4728
4783
|
}
|
|
4729
4784
|
});
|
|
4730
4785
|
};
|