Skip to content

Commit

Permalink
unify return structure of range callback
Browse files Browse the repository at this point in the history
  • Loading branch information
rinick committed May 14, 2024
1 parent a1f8e48 commit 4e2b922
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 449 deletions.
5 changes: 4 additions & 1 deletion es/Week.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ Week.range = function (date, _ref2) {
var firstOfWeek = localizer.startOfWeek();
var start = localizer.startOf(date, 'week', firstOfWeek);
var end = localizer.endOf(date, 'week', firstOfWeek);
return localizer.range(start, end);
var r = localizer.range(start, end);
r.start = start;
r.end = end;
return r;
};
Week.title = function (date, _ref3) {
var localizer = _ref3.localizer;
Expand Down
5 changes: 4 additions & 1 deletion es/WorkWeek.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ var _Week = _interopRequireDefault(require("./Week"));
var _TimeGrid = _interopRequireDefault(require("./TimeGrid"));
var _excluded = ["date", "localizer", "min", "max", "scrollToTime", "enableAutoScroll"];
function workWeekRange(date, options) {
return _Week.default.range(date, options).filter(function (d) {
var r = _Week.default.range(date, options).filter(function (d) {
return [6, 0].indexOf(d.getDay()) === -1;
});
r.start = r[0];
r.end = r.at(-1).setHours(23, 59, 59, 999);
return r;
}
var WorkWeek = /*#__PURE__*/function (_React$Component) {
(0, _inherits2.default)(WorkWeek, _React$Component);
Expand Down
4 changes: 1 addition & 3 deletions es/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ export interface Messages {
yesterday?: string | undefined;
tomorrow?: string | undefined;
today?: string | undefined;
agenda?: string | undefined;
showMore?: ((count: number) => string) | undefined;
noEventsInRange?: string | undefined;
}
Expand Down Expand Up @@ -426,7 +425,7 @@ export interface CalendarProps<TEvent extends object = Event, TResource extends
onKeyPressEvent?: ((event: TEvent, e: React.SyntheticEvent<HTMLElement>) => void) | undefined;
onSelecting?: (range: { start: Date; end: Date }) => boolean | undefined;
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
onRangeChange?: (range: Date[] | { start: Date; end: Date }, view?: View) => void | undefined;
onRangeChange?: (range: { start: Date; end: Date }, view?: View) => void | undefined;
showAllEvents?: boolean | undefined;
selected?: any;
views?: ViewsProps<TEvent, TResource> | undefined;
Expand Down Expand Up @@ -530,7 +529,6 @@ export const Views: {
WEEK: "week";
WORK_WEEK: "work_week";
DAY: "day";
AGENDA: "agenda";
};
export function move(View: ViewStatic | ViewKey, options: MoveOptions): Date;

Expand Down
59 changes: 25 additions & 34 deletions es/localizers/luxon.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,17 @@ var weekRangeFormat = function weekRangeFormat(_ref, culture, local) {
// updated to use this localizer 'eq()' method
local.format(end, local.eq(start, end, 'month') ? 'dd' : 'LLLL dd', culture);
};
var dateRangeFormat = function dateRangeFormat(_ref2, culture, local) {
var timeRangeFormat = function timeRangeFormat(_ref2, culture, local) {
var start = _ref2.start,
end = _ref2.end;
return local.format(start, 'D', culture) + ' – ' + local.format(end, 'D', culture);
};
var timeRangeFormat = function timeRangeFormat(_ref3, culture, local) {
var start = _ref3.start,
end = _ref3.end;
return local.format(start, 't', culture) + ' – ' + local.format(end, 't', culture);
};
var timeRangeStartFormat = function timeRangeStartFormat(_ref4, culture, local) {
var start = _ref4.start;
var timeRangeStartFormat = function timeRangeStartFormat(_ref3, culture, local) {
var start = _ref3.start;
return local.format(start, 't', culture) + ' – ';
};
var timeRangeEndFormat = function timeRangeEndFormat(_ref5, culture, local) {
var end = _ref5.end;
var timeRangeEndFormat = function timeRangeEndFormat(_ref4, culture, local) {
var end = _ref4.end;
return ' – ' + local.format(end, 't', culture);
};
var formats = exports.formats = {
Expand All @@ -48,11 +43,7 @@ var formats = exports.formats = {
timeGutterFormat: 't',
monthHeaderFormat: 'LLLL yyyy',
dayHeaderFormat: 'EEEE LLL dd',
dayRangeHeaderFormat: weekRangeFormat,
agendaHeaderFormat: dateRangeFormat,
agendaDateFormat: 'EEE LLL dd',
agendaTimeFormat: 't',
agendaTimeRangeFormat: timeRangeFormat
dayRangeHeaderFormat: weekRangeFormat
};
function fixUnit(unit) {
var datePart = unit ? pluralizeUnit(unit.toLowerCase()) : unit;
Expand All @@ -68,9 +59,9 @@ function fixUnit(unit) {
// Luxon uses 1 based values for month and weekday
// So we default to Sunday (7)
function _default(DateTime) {
var _ref6 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref6$firstDayOfWeek = _ref6.firstDayOfWeek,
firstDayOfWeek = _ref6$firstDayOfWeek === void 0 ? 7 : _ref6$firstDayOfWeek;
var _ref5 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref5$firstDayOfWeek = _ref5.firstDayOfWeek,
firstDayOfWeek = _ref5$firstDayOfWeek === void 0 ? 7 : _ref5$firstDayOfWeek;
function formatDate(value, format) {
return DateTime.fromJSDate(value).toFormat(format);
}
Expand Down Expand Up @@ -315,15 +306,15 @@ function _default(DateTime) {
}

// These two are used by eventLevels
function sortEvents(_ref7) {
var _ref7$evtA = _ref7.evtA,
aStart = _ref7$evtA.start,
aEnd = _ref7$evtA.end,
aAllDay = _ref7$evtA.allDay,
_ref7$evtB = _ref7.evtB,
bStart = _ref7$evtB.start,
bEnd = _ref7$evtB.end,
bAllDay = _ref7$evtB.allDay;
function sortEvents(_ref6) {
var _ref6$evtA = _ref6.evtA,
aStart = _ref6$evtA.start,
aEnd = _ref6$evtA.end,
aAllDay = _ref6$evtA.allDay,
_ref6$evtB = _ref6.evtB,
bStart = _ref6$evtB.start,
bEnd = _ref6$evtB.end,
bAllDay = _ref6$evtB.allDay;
var startSort = +startOf(aStart, 'day') - +startOf(bStart, 'day');
var durA = daySpan(aStart, aEnd);
var durB = daySpan(bStart, bEnd);
Expand All @@ -338,13 +329,13 @@ function _default(DateTime) {
+aEnd - +bEnd // then sort by end time *don't need moment conversion here either
;
}
function inEventRange(_ref8) {
var _ref8$event = _ref8.event,
start = _ref8$event.start,
end = _ref8$event.end,
_ref8$range = _ref8.range,
rangeStart = _ref8$range.start,
rangeEnd = _ref8$range.end;
function inEventRange(_ref7) {
var _ref7$event = _ref7.event,
start = _ref7$event.start,
end = _ref7$event.end,
_ref7$range = _ref7.range,
rangeStart = _ref7$range.start,
rangeEnd = _ref7$range.end;
var eStart = startOf(start, 'day');
var startsBeforeEnd = lte(eStart, rangeEnd, 'day');
// when the event is zero duration we need to handle a bit differently
Expand Down
7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ticlo-big-calendar",
"version": "1.12.1",
"version": "1.12.2",
"description": "Calendar! with events",
"repository": {
"type": "git",
Expand All @@ -24,12 +24,9 @@
"full calendar"
],
"scripts": {
"build": "zx .scripts/build.mjs",
"build-es": "cross-env NODE_ENV=production babel src --out-dir es",
"build-storybook": "build-storybook",
"lint": "NODE_ENV=development eslint src test",
"prepare": "is-ci || husky install",
"prepublishOnly": "yarn build",
"prettier": "prettier '**/*js' '!lib/**' --write ",
"storybook": "start-storybook -p 9002"
},
Expand All @@ -46,8 +43,6 @@
"@babel/plugin-proposal-private-property-in-object": "^7.18.6",
"@babel/plugin-transform-runtime": "^7.19.6",
"@babel/preset-env": "^7.20.2",
"@commitlint/cli": "^17.4.2",
"@commitlint/config-conventional": "^17.4.2",
"@rollup/plugin-babel": "6.0.3",
"@rollup/plugin-commonjs": "24.0.0",
"@rollup/plugin-node-resolve": "15.0.1",
Expand Down
5 changes: 4 additions & 1 deletion src/Week.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ Week.range = (date, { localizer }) => {
let start = localizer.startOf(date, 'week', firstOfWeek)
let end = localizer.endOf(date, 'week', firstOfWeek)

return localizer.range(start, end)
let r = localizer.range(start, end)
r.start = start;
r.end = end;
return r;
}

Week.title = (date, { localizer }) => {
Expand Down
5 changes: 4 additions & 1 deletion src/WorkWeek.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import Week from './Week'
import TimeGrid from './TimeGrid'

function workWeekRange(date, options) {
return Week.range(date, options).filter(
let r = Week.range(date, options).filter(
(d) => [6, 0].indexOf(d.getDay()) === -1
)
r.start = r[0];
r.end = r.at(-1).setHours(23, 59, 59, 999);
return r;
}

class WorkWeek extends React.Component {
Expand Down
5 changes: 0 additions & 5 deletions src/localizers/luxon.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ export const formats = {
monthHeaderFormat: 'LLLL yyyy',
dayHeaderFormat: 'EEEE LLL dd',
dayRangeHeaderFormat: weekRangeFormat,
agendaHeaderFormat: dateRangeFormat,

agendaDateFormat: 'EEE LLL dd',
agendaTimeFormat: 't',
agendaTimeRangeFormat: timeRangeFormat,
}

function fixUnit(unit) {
Expand Down
Loading

0 comments on commit 4e2b922

Please sign in to comment.