sanity-plugin-recurring-dates 1.3.2 → 1.4.1

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Tom Smith
3
+ Copyright (c) 2025 Tom Smith
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -71,6 +71,17 @@ export default defineConfig({
71
71
 
72
72
  // Changes the date picker to date only, no time
73
73
  dateOnly: true, // defaults to false
74
+
75
+ // Change the field titles and descriptions
76
+ // field names will remain "startDate" and "endDate"
77
+ fieldTitles: {
78
+ startDate: 'Event starts',
79
+ endDate: 'Event ends',
80
+ },
81
+ fieldDescriptions: {
82
+ startDate: 'This is the date the event starts',
83
+ endDate: 'This is the date the event ends',
84
+ },
74
85
  }),
75
86
  ],
76
87
  })
@@ -114,6 +125,17 @@ defineField({
114
125
  startDate: (Rule) => Rule.required() // defaults to (Rule) => Rule.required()
115
126
  endDate: (Rule) => Rule.min(Rule.valueOfField('startDate')) // defaults to (Rule) => Rule.min(Rule.valueOfField('startDate'))
116
127
  }
128
+
129
+ // Change the field titles and descriptions
130
+ // field names will remain "startDate" and "endDate"
131
+ fieldTitles: {
132
+ startDate: 'Event starts',
133
+ endDate: 'Event ends',
134
+ },
135
+ fieldDescriptions: {
136
+ startDate: 'This is the date the event starts',
137
+ endDate: 'This is the date the event ends',
138
+ },
117
139
  },
118
140
  })
119
141
  ```
package/dist/index.d.ts CHANGED
@@ -13,6 +13,14 @@ export declare interface PluginConfig {
13
13
  startDate?: (Rule: DateRule) => DateRule
14
14
  endDate?: (Rule: DateRule) => DateRule
15
15
  }
16
+ fieldTitles?: {
17
+ startDate?: string
18
+ endDate?: string
19
+ }
20
+ fieldDescriptions?: {
21
+ startDate?: string
22
+ endDate?: string
23
+ }
16
24
  }
17
25
 
18
26
  export declare interface RecurringDate {
package/dist/index.esm.js CHANGED
@@ -4254,6 +4254,11 @@ function Monthly(props) {
4254
4254
  setByweekday([newWeekday]);
4255
4255
  }
4256
4256
  }, [dayNo, setByweekday, weekNo]);
4257
+ useEffect(() => {
4258
+ if (!weekNo) {
4259
+ setByweekday(null);
4260
+ }
4261
+ }, []);
4257
4262
  return /* @__PURE__ */jsxs(Flex, {
4258
4263
  gap: 2,
4259
4264
  align: "center",
@@ -4357,6 +4362,7 @@ function CustomRule(_ref8) {
4357
4362
  onChange,
4358
4363
  initialValue,
4359
4364
  startDate,
4365
+ endDate,
4360
4366
  dateTimeOptions
4361
4367
  } = _ref8;
4362
4368
  const initialRule = useMemo(() => {
@@ -4367,6 +4373,7 @@ function CustomRule(_ref8) {
4367
4373
  const [count, setCount] = useState(initialRule.origOptions.count || null);
4368
4374
  const [until, setUntil] = useState(initialRule.origOptions.until || null);
4369
4375
  const [byweekday, setByweekday] = useState(initialRule.origOptions.byweekday || null);
4376
+ const [untilValid, setUntilValid] = useState(true);
4370
4377
  const handleChange = useCallback(event => {
4371
4378
  const {
4372
4379
  name,
@@ -4396,9 +4403,15 @@ function CustomRule(_ref8) {
4396
4403
  }, [frequency, startDate]);
4397
4404
  const handleUntilChange = useCallback(date => {
4398
4405
  if (date) {
4399
- setUntil(toDate$1(`${date}T23:59:59`));
4406
+ const untilDate = toDate$1(`${date}T23:59:59`);
4407
+ if (endDate && untilDate < toDate$1(endDate) || startDate && untilDate < toDate$1(startDate)) {
4408
+ setUntilValid(false);
4409
+ } else {
4410
+ setUntilValid(true);
4411
+ }
4412
+ setUntil(untilDate);
4400
4413
  }
4401
- }, []);
4414
+ }, [endDate, startDate]);
4402
4415
  const handleEndChange = useCallback(event => {
4403
4416
  const {
4404
4417
  value
@@ -4421,7 +4434,7 @@ function CustomRule(_ref8) {
4421
4434
  interval,
4422
4435
  count: count || null,
4423
4436
  until: until ? until : null,
4424
- byweekday
4437
+ byweekday: frequency === RRule.WEEKLY || frequency === RRule.MONTHLY ? byweekday : null
4425
4438
  };
4426
4439
  const newRule = new RRule(newOptions);
4427
4440
  onClose();
@@ -4537,6 +4550,12 @@ function CustomRule(_ref8) {
4537
4550
  value: until ? formatUntilValue(new Date(until)) : formatUntilValue(getUntilDate()),
4538
4551
  readOnly: !until
4539
4552
  })
4553
+ }), !untilValid && /* @__PURE__ */jsx(Feedback, {
4554
+ tone: "critical",
4555
+ children: /* @__PURE__ */jsx(Text, {
4556
+ size: 1,
4557
+ children: "Until date must be after event ends"
4558
+ })
4540
4559
  })]
4541
4560
  }), /* @__PURE__ */jsxs(Flex, {
4542
4561
  gap: 2,
@@ -4590,7 +4609,8 @@ function CustomRule(_ref8) {
4590
4609
  }), /* @__PURE__ */jsx(Button, {
4591
4610
  text: "Done",
4592
4611
  tone: "positive",
4593
- onClick: handleConfirm
4612
+ onClick: handleConfirm,
4613
+ disabled: !untilValid
4594
4614
  })]
4595
4615
  })
4596
4616
  })]
@@ -4699,33 +4719,44 @@ function RecurringDates(props) {
4699
4719
  ...startDateMember?.field?.schemaType.options,
4700
4720
  ...dateTimeOptions
4701
4721
  };
4722
+ if (dateOnly === true) {
4723
+ startDateMember.field.schemaType.name = "date";
4724
+ } else {
4725
+ startDateMember.field.schemaType.name = "datetime";
4726
+ }
4727
+ if (validation?.startDate) {
4728
+ startDateMember.field.schemaType.validation = CustomValidation => validation?.startDate?.(CustomValidation);
4729
+ } else {
4730
+ startDateMember.field.schemaType.validation = DefaultRule => DefaultRule.required();
4731
+ }
4732
+ if (options?.fieldTitles?.startDate) {
4733
+ startDateMember.field.schemaType.title = options.fieldTitles.startDate;
4734
+ }
4735
+ if (options?.fieldDescriptions?.startDate) {
4736
+ startDateMember.field.schemaType.description = options.fieldDescriptions.startDate;
4737
+ }
4702
4738
  }
4703
4739
  if (endDateMember?.kind == "field") {
4704
4740
  endDateMember.field.schemaType.options = {
4705
4741
  ...endDateMember?.field?.schemaType.options,
4706
4742
  ...dateTimeOptions
4707
4743
  };
4708
- }
4709
- if (dateOnly === true) {
4710
- if (startDateMember?.kind == "field") {
4711
- startDateMember.field.schemaType.name = "date";
4712
- }
4713
- if (endDateMember?.kind == "field") {
4744
+ if (dateOnly === true) {
4714
4745
  endDateMember.field.schemaType.name = "date";
4746
+ } else {
4747
+ endDateMember.field.schemaType.name = "datetime";
4715
4748
  }
4716
- } else {
4717
- if (startDateMember?.kind == "field") {
4718
- startDateMember.field.schemaType.name = "datetime";
4749
+ if (validation?.endDate) {
4750
+ endDateMember.field.schemaType.validation = CustomValidation => validation?.endDate?.(CustomValidation);
4751
+ } else {
4752
+ endDateMember.field.schemaType.validation = DefaultRule => DefaultRule.min(DefaultRule.valueOfField("startDate"));
4719
4753
  }
4720
- if (endDateMember?.kind == "field") {
4721
- endDateMember.field.schemaType.name = "datetime";
4754
+ if (options?.fieldTitles?.endDate) {
4755
+ endDateMember.field.schemaType.title = options.fieldTitles.endDate;
4756
+ }
4757
+ if (options?.fieldDescriptions?.endDate) {
4758
+ endDateMember.field.schemaType.description = options.fieldDescriptions.endDate;
4722
4759
  }
4723
- }
4724
- if (validation?.startDate && startDateMember?.kind == "field") {
4725
- startDateMember.field.schemaType.validation = CustomValidation => validation?.startDate?.(CustomValidation);
4726
- }
4727
- if (validation?.endDate && endDateMember?.kind == "field") {
4728
- endDateMember.field.schemaType.validation = CustomValidation => validation?.endDate?.(CustomValidation);
4729
4760
  }
4730
4761
  const hasEndDate = currentValue?.endDate;
4731
4762
  return /* @__PURE__ */jsxs(Stack, {
@@ -4796,6 +4827,7 @@ function RecurringDates(props) {
4796
4827
  onChange,
4797
4828
  initialValue: currentValue?.rrule,
4798
4829
  startDate: startDateMember?.kind == "field" ? startDateMember?.field?.value : void 0,
4830
+ endDate: endDateMember?.kind == "field" ? endDateMember?.field?.value : void 0,
4799
4831
  dateTimeOptions
4800
4832
  })]
4801
4833
  });
@@ -4850,7 +4882,9 @@ var recurringDateSchema = config => {
4850
4882
  const {
4851
4883
  dateTimeOptions,
4852
4884
  dateOnly,
4853
- validation
4885
+ validation,
4886
+ fieldTitles,
4887
+ fieldDescriptions
4854
4888
  } = config;
4855
4889
  return defineField({
4856
4890
  name: "recurringDates",
@@ -4858,13 +4892,15 @@ var recurringDateSchema = config => {
4858
4892
  type: "object",
4859
4893
  icon: CalendarIcon,
4860
4894
  fields: [defineField({
4861
- title: "Start Date",
4895
+ title: fieldTitles?.startDate || "Start Date",
4896
+ description: fieldDescriptions?.startDate || "",
4862
4897
  name: "startDate",
4863
4898
  type: dateOnly ? "date" : "datetime",
4864
4899
  options: dateTimeOptions,
4865
4900
  validation: Rule => validation?.startDate ? validation.startDate(Rule) : Rule.required()
4866
4901
  }), defineField({
4867
- title: "End Date",
4902
+ title: fieldTitles?.endDate || "End Date",
4903
+ description: fieldDescriptions?.endDate || "",
4868
4904
  name: "endDate",
4869
4905
  type: dateOnly ? "date" : "datetime",
4870
4906
  options: dateTimeOptions,