sanity-plugin-recurring-dates 1.0.0 → 1.0.2
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/README.md +7 -9
- package/dist/index.d.ts +7 -1
- package/dist/index.esm.js +58 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +55 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/RecurringDate.tsx +11 -4
- package/src/components/RemoveEndDate.tsx +48 -0
- package/src/plugin.tsx +1 -1
- package/src/schema/recurringDates.tsx +2 -2
- package/src/types.ts +6 -0
package/README.md
CHANGED
|
@@ -135,13 +135,16 @@ import {formatInTimeZone, getTimezoneOffset} from 'date-fns-tz'
|
|
|
135
135
|
// your desired timezone
|
|
136
136
|
const timezone = 'Europe/London'
|
|
137
137
|
|
|
138
|
+
// Start date as a date
|
|
139
|
+
const startDate = new Date(recurringDate.startDate)
|
|
140
|
+
|
|
138
141
|
// Pass your rrule and startDate to the `rrulestr` function
|
|
139
|
-
const upcomingRule = rrulestr(rrule, {
|
|
142
|
+
const upcomingRule = rrulestr(recurringDate.rrule, {
|
|
140
143
|
dtstart: startDate,
|
|
141
144
|
})
|
|
142
145
|
|
|
143
146
|
// Calculate the offset from UTC for your timezone at the start date
|
|
144
|
-
const initialOffset = getTimezoneOffset(timezone,
|
|
147
|
+
const initialOffset = getTimezoneOffset(timezone, startDate)
|
|
145
148
|
|
|
146
149
|
// Map through all the rules, returning an array of dates in the correct timezone
|
|
147
150
|
// with consideration for changes in timezone offset as a result of DST
|
|
@@ -157,11 +160,7 @@ const allDates = rule.all().map((date) => {
|
|
|
157
160
|
|
|
158
161
|
// Return a formatted date from the date needed, with the format we pass
|
|
159
162
|
// in the third parameter
|
|
160
|
-
return formatInTimeZone(
|
|
161
|
-
date.setTime(date.getTime() + diff),
|
|
162
|
-
timezone,
|
|
163
|
-
'EEEE, MMMM d, yyyy h:mm aaaa',
|
|
164
|
-
)
|
|
163
|
+
return formatInTimeZone(date, timezone, 'EEEE, MMMM d, yyyy h:mm aaaa')
|
|
165
164
|
})
|
|
166
165
|
```
|
|
167
166
|
|
|
@@ -177,10 +176,9 @@ with default configuration for build & watch scripts.
|
|
|
177
176
|
See [Testing a plugin in Sanity Studio](https://github.com/sanity-io/plugin-kit#testing-a-plugin-in-sanity-studio)
|
|
178
177
|
on how to run this plugin with hotreload in the studio.
|
|
179
178
|
|
|
180
|
-
|
|
181
179
|
### Release new version
|
|
182
180
|
|
|
183
181
|
Run ["CI & Release" workflow](https://github.com/thebiggianthead/sanity-plugin-recurring-dates/actions/workflows/main.yml).
|
|
184
182
|
Make sure to select the main branch and check "Release new version".
|
|
185
183
|
|
|
186
|
-
Semantic release will only release on configured branches, so it is safe to run release on any branch.
|
|
184
|
+
Semantic release will only release on configured branches, so it is safe to run release on any branch.
|
package/dist/index.d.ts
CHANGED
|
@@ -9,12 +9,18 @@ export declare interface PluginConfig {
|
|
|
9
9
|
dateTimeOptions?: DatetimeOptions
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
export declare interface RecurringDate {
|
|
13
|
+
rrule: string
|
|
14
|
+
startDate: string
|
|
15
|
+
endDate: String
|
|
16
|
+
}
|
|
17
|
+
|
|
12
18
|
export declare type RecurringDateFieldOptions = Omit<ObjectDefinition, 'type' | 'fields'> & {
|
|
13
19
|
type: 'recurringDates'
|
|
14
20
|
options?: PluginConfig
|
|
15
21
|
}
|
|
16
22
|
|
|
17
|
-
export declare const recurringDates: Plugin_2<PluginConfig>
|
|
23
|
+
export declare const recurringDates: Plugin_2<void | PluginConfig>
|
|
18
24
|
|
|
19
25
|
export declare type WithRequiredProperty<Type, Key extends keyof Type> = Type & {
|
|
20
26
|
[Property in Key]-?: Type[Property]
|
package/dist/index.esm.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { set, ObjectInputMember, defineField, definePlugin } from 'sanity';
|
|
2
|
-
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
1
|
+
import { set, unset, ObjectInputMember, defineField, definePlugin } from 'sanity';
|
|
2
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
3
|
import { Card, Text, Box, Grid, TextInput, useForwardedRef, Flex, Select, Button, useClickOutside, LayerProvider, Popover, Stack, Dialog, Radio } from '@sanity/ui';
|
|
4
4
|
import { range, upperFirst } from 'lodash';
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import React__default, { useState, useEffect, PureComponent, useCallback, forwardRef, useRef, useMemo } from 'react';
|
|
7
7
|
import { rrulestr, Weekday, RRule } from 'rrule';
|
|
8
8
|
import { Feedback } from 'sanity-plugin-utils';
|
|
9
|
-
import { ChevronLeftIcon, ChevronRightIcon, CalendarIcon } from '@sanity/icons';
|
|
9
|
+
import { ChevronLeftIcon, ChevronRightIcon, CalendarIcon, WarningOutlineIcon, TrashIcon } from '@sanity/icons';
|
|
10
10
|
const DEFAULT_RECURRENCES = ["RRULE:FREQ=DAILY;INTERVAL=1", "RRULE:FREQ=WEEKLY;INTERVAL=1", "RRULE:FREQ=MONTHLY;INTERVAL=1", "RRULE:FREQ=YEARLY;INTERVAL=1"];
|
|
11
11
|
const DEFAULT_CONFIG = {
|
|
12
12
|
defaultRecurrences: DEFAULT_RECURRENCES
|
|
@@ -8990,6 +8990,53 @@ function CustomRule(_ref8) {
|
|
|
8990
8990
|
})
|
|
8991
8991
|
});
|
|
8992
8992
|
}
|
|
8993
|
+
function RemoveEndDate(_ref9) {
|
|
8994
|
+
let {
|
|
8995
|
+
title,
|
|
8996
|
+
onChange
|
|
8997
|
+
} = _ref9;
|
|
8998
|
+
const handleUnsetClick = useCallback(() => {
|
|
8999
|
+
onChange(unset(["endDate"]));
|
|
9000
|
+
}, [onChange]);
|
|
9001
|
+
return /* @__PURE__ */jsx(Card, {
|
|
9002
|
+
padding: 4,
|
|
9003
|
+
radius: 2,
|
|
9004
|
+
tone: "caution",
|
|
9005
|
+
"data-ui": "Alert",
|
|
9006
|
+
children: /* @__PURE__ */jsxs(Flex, {
|
|
9007
|
+
children: [/* @__PURE__ */jsx(Box, {
|
|
9008
|
+
children: /* @__PURE__ */jsx(Text, {
|
|
9009
|
+
size: 1,
|
|
9010
|
+
children: /* @__PURE__ */jsx(WarningOutlineIcon, {})
|
|
9011
|
+
})
|
|
9012
|
+
}), /* @__PURE__ */jsxs(Stack, {
|
|
9013
|
+
space: 3,
|
|
9014
|
+
flex: 1,
|
|
9015
|
+
marginLeft: 3,
|
|
9016
|
+
children: [/* @__PURE__ */jsxs(Text, {
|
|
9017
|
+
size: 1,
|
|
9018
|
+
weight: "semibold",
|
|
9019
|
+
children: ["The ", title ? upperFirst(title) : "current", " field has an end date"]
|
|
9020
|
+
}), /* @__PURE__ */jsx(Box, {
|
|
9021
|
+
children: /* @__PURE__ */jsx(Text, {
|
|
9022
|
+
as: "p",
|
|
9023
|
+
muted: true,
|
|
9024
|
+
size: 1,
|
|
9025
|
+
children: "This field has an end date value, but the end date is currently disabled for this field."
|
|
9026
|
+
})
|
|
9027
|
+
}), /* @__PURE__ */jsx(Button, {
|
|
9028
|
+
icon: TrashIcon,
|
|
9029
|
+
tone: "critical",
|
|
9030
|
+
text: /* @__PURE__ */jsx(Fragment, {
|
|
9031
|
+
children: "Remove end date"
|
|
9032
|
+
}),
|
|
9033
|
+
onClick: handleUnsetClick,
|
|
9034
|
+
width: "100%"
|
|
9035
|
+
})]
|
|
9036
|
+
})]
|
|
9037
|
+
})
|
|
9038
|
+
});
|
|
9039
|
+
}
|
|
8993
9040
|
function RecurringDates(props) {
|
|
8994
9041
|
var _a, _b, _c;
|
|
8995
9042
|
const {
|
|
@@ -9000,7 +9047,8 @@ function RecurringDates(props) {
|
|
|
9000
9047
|
pluginConfig
|
|
9001
9048
|
} = props;
|
|
9002
9049
|
const {
|
|
9003
|
-
options
|
|
9050
|
+
options,
|
|
9051
|
+
title
|
|
9004
9052
|
} = schemaType;
|
|
9005
9053
|
const {
|
|
9006
9054
|
defaultRecurrences,
|
|
@@ -9050,12 +9098,16 @@ function RecurringDates(props) {
|
|
|
9050
9098
|
...dateTimeOptions
|
|
9051
9099
|
};
|
|
9052
9100
|
}
|
|
9101
|
+
const hasEndDate = currentValue && currentValue.endDate;
|
|
9053
9102
|
return /* @__PURE__ */jsxs(Stack, {
|
|
9054
9103
|
space: 3,
|
|
9055
9104
|
children: [/* @__PURE__ */jsxs(Grid, {
|
|
9056
9105
|
columns: hideEndDate ? 1 : 2,
|
|
9057
9106
|
gap: 3,
|
|
9058
|
-
children: [/* @__PURE__ */jsx(
|
|
9107
|
+
children: [hasEndDate && hideEndDate && /* @__PURE__ */jsx(RemoveEndDate, {
|
|
9108
|
+
title,
|
|
9109
|
+
onChange
|
|
9110
|
+
}), /* @__PURE__ */jsx(Flex, {
|
|
9059
9111
|
align: "flex-end",
|
|
9060
9112
|
gap: 2,
|
|
9061
9113
|
children: /* @__PURE__ */jsx(Box, {
|
|
@@ -9120,7 +9172,6 @@ function RecurringDates(props) {
|
|
|
9120
9172
|
}
|
|
9121
9173
|
var recurringDateSchema = config => {
|
|
9122
9174
|
const {
|
|
9123
|
-
hideEndDate,
|
|
9124
9175
|
dateTimeOptions
|
|
9125
9176
|
} = config;
|
|
9126
9177
|
return defineField({
|
|
@@ -9148,7 +9199,7 @@ var recurringDateSchema = config => {
|
|
|
9148
9199
|
name: "rrule",
|
|
9149
9200
|
type: "string",
|
|
9150
9201
|
hidden: true
|
|
9151
|
-
})]
|
|
9202
|
+
})],
|
|
9152
9203
|
components: {
|
|
9153
9204
|
input: props => RecurringDates({
|
|
9154
9205
|
...props,
|