Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@culturehq/add-to-calendar

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@culturehq/add-to-calendar - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

dist/AddToCalendar.d.ts

10

CHANGELOG.md

@@ -9,2 +9,12 @@ # Changelog

## [1.0.3] - 2019-08-22
### Added
- Type definitions shipped along with the main bundle.
### Changed
- Switched over to TypeScript for development.
## [1.0.2] - 2019-06-13

@@ -11,0 +21,0 @@

195

dist/AddToCalendar.js
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _makeUrls = _interopRequireDefault(require("./makeUrls"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var useAutoFocus = function useAutoFocus() {
var ref = (0, _react.useRef)(null);
(0, _react.useEffect)(function () {
var _document = document,
activeElement = _document.activeElement;
ref.current.focus();
return function () {
return activeElement.focus();
};
}, []);
return ref;
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var makeUrls_1 = require("./makeUrls");
var useAutoFocus = function () {
var elementRef = React.useRef(null);
React.useEffect(function () {
var previous = document.activeElement;
var element = elementRef.current;
if (element) {
element.focus();
}
if (previous instanceof HTMLElement) {
return function () { return previous.focus(); };
}
return undefined;
}, []);
return elementRef;
};
var useOpenState = function useOpenState(initialOpen) {
var _useState = (0, _react.useState)(initialOpen),
_useState2 = _slicedToArray(_useState, 2),
open = _useState2[0],
setOpen = _useState2[1];
var onToggle = (0, _react.useCallback)(function () {
return setOpen(function (current) {
return !current;
});
}, [setOpen]);
(0, _react.useEffect)(function () {
if (open) {
var onClose = function onClose() {
return setOpen(false);
};
document.addEventListener("click", onClose);
return function () {
return document.removeEventListener("click", onClose);
};
}
return undefined;
}, [open, setOpen]);
return [open, onToggle];
var useOpenState = function (initialOpen) {
var _a = React.useState(initialOpen), open = _a[0], setOpen = _a[1];
var onToggle = function () { return setOpen(function (current) { return !current; }); };
React.useEffect(function () {
if (open) {
var onClose_1 = function () { return setOpen(false); };
document.addEventListener("click", onClose_1);
return function () { return document.removeEventListener("click", onClose_1); };
}
return undefined;
}, [open, setOpen]);
return [open, onToggle];
};
var Calendar = _react["default"].forwardRef(function (_ref, ref) {
var children = _ref.children,
_ref$download = _ref.download,
download = _ref$download === void 0 ? false : _ref$download,
href = _ref.href;
return _react["default"].createElement("a", {
ref: ref,
download: download,
href: href,
target: "_blank",
rel: "noopener noreferrer"
}, children);
var Calendar = React.forwardRef(function (_a, ref) {
var children = _a.children, _b = _a.download, download = _b === void 0 ? false : _b, href = _a.href;
return (React.createElement("a", { ref: ref, download: download, href: href, target: "_blank", rel: "noopener noreferrer" }, children));
});
var Dropdown = function Dropdown(_ref2) {
var onToggle = _ref2.onToggle,
urls = _ref2.urls;
var ref = useAutoFocus();
var onKeyDown = (0, _react.useCallback)(function (_ref3) {
var key = _ref3.key;
if (key === "Escape") {
onToggle();
}
}, [onToggle]);
return _react["default"].createElement("div", {
className: "chq-atc--dropdown",
onKeyDown: onKeyDown,
role: "presentation"
}, _react["default"].createElement(Calendar, {
href: urls.ics,
download: true,
ref: ref
}, "Apple Calendar"), _react["default"].createElement(Calendar, {
href: urls.google
}, "Google"), _react["default"].createElement(Calendar, {
href: urls.ics,
download: true
}, "Outlook"), _react["default"].createElement(Calendar, {
href: urls.outlook
}, "Outlook Web App"), _react["default"].createElement(Calendar, {
href: urls.yahoo
}, "Yahoo"));
var Dropdown = function (_a) {
var onToggle = _a.onToggle, urls = _a.urls;
var ref = useAutoFocus();
var onKeyDown = function (event) {
if (event.key === "Escape") {
onToggle();
}
};
return (React.createElement("div", { className: "chq-atc--dropdown", onKeyDown: onKeyDown, role: "presentation" },
React.createElement(Calendar, { href: urls.ics, download: true, ref: ref }, "Apple Calendar"),
React.createElement(Calendar, { href: urls.google }, "Google"),
React.createElement(Calendar, { href: urls.ics, download: true }, "Outlook"),
React.createElement(Calendar, { href: urls.outlook }, "Outlook Web App"),
React.createElement(Calendar, { href: urls.yahoo }, "Yahoo")));
};
var AddToCalendar = function AddToCalendar(_ref4) {
var _ref4$children = _ref4.children,
children = _ref4$children === void 0 ? "Add to My Calendar" : _ref4$children,
event = _ref4.event,
initialOpen = _ref4.open;
var _useOpenState = useOpenState(initialOpen),
_useOpenState2 = _slicedToArray(_useOpenState, 2),
open = _useOpenState2[0],
onToggle = _useOpenState2[1];
var urls = (0, _react.useMemo)(function () {
return (0, _makeUrls["default"])(event);
}, [event]);
return _react["default"].createElement("div", {
className: "chq-atc"
}, event && _react["default"].createElement("button", {
type: "button",
className: "chq-atc--button",
onClick: onToggle
}, _react["default"].createElement("svg", {
width: "20px",
height: "20px",
viewBox: "0 0 1024 1024"
}, _react["default"].createElement("path", {
d: "M704 192v-64h-32v64h-320v-64h-32v64h-192v704h768v-704h-192z M864 864h-704v-480h704v480z M864 352h-704v-128h160v64h32v-64h320v64h32v-64h160v128z"
})), " ", children), open && _react["default"].createElement(Dropdown, {
onToggle: onToggle,
urls: urls
}));
var AddToCalendar = function (_a) {
var _b = _a.children, children = _b === void 0 ? "Add to My Calendar" : _b, event = _a.event, _c = _a.open, initialOpen = _c === void 0 ? false : _c;
var _d = useOpenState(initialOpen), open = _d[0], onToggle = _d[1];
var urls = React.useMemo(function () { return makeUrls_1.default(event); }, [event]);
return (React.createElement("div", { className: "chq-atc" },
event && (React.createElement("button", { type: "button", className: "chq-atc--button", onClick: onToggle },
React.createElement("svg", { width: "20px", height: "20px", viewBox: "0 0 1024 1024" },
React.createElement("path", { d: "M704 192v-64h-32v64h-320v-64h-32v64h-192v704h768v-704h-192z M864 864h-704v-480h704v480z M864 352h-704v-128h160v64h32v-64h320v64h32v-64h160v128z" })),
" ",
children)),
open && React.createElement(Dropdown, { onToggle: onToggle, urls: urls })));
};
var _default = AddToCalendar;
exports["default"] = _default;
exports.default = AddToCalendar;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var makeDuration = function makeDuration(event) {
var minutes = Math.floor((+new Date(event.endsAt) - +new Date(event.startsAt)) / 60 / 1000);
return "".concat(Math.floor(minutes / 60), ":").concat("0".concat(minutes % 60).slice(-2));
Object.defineProperty(exports, "__esModule", { value: true });
var makeDuration = function (event) {
var minutes = Math.floor((+new Date(event.endsAt) - +new Date(event.startsAt)) / 60 / 1000);
return Math.floor(minutes / 60) + ":" + ("0" + minutes % 60).slice(-2);
};
var makeTime = function makeTime(time) {
return new Date(time).toISOString().replace(/[-:]|\.\d{3}/g, "");
};
var makeUrl = function makeUrl(base, query) {
return Object.keys(query).reduce(function (accum, key, index) {
return "".concat(accum).concat(index === 0 ? "?" : "&").concat(key, "=").concat(encodeURIComponent(query[key]));
}, base);
};
var makeGoogleCalendarUrl = function makeGoogleCalendarUrl(event) {
return makeUrl("https://calendar.google.com/calendar/render", {
var makeTime = function (time) { return new Date(time).toISOString().replace(/[-:]|\.\d{3}/g, ""); };
var makeUrl = function (base, query) { return Object.keys(query).reduce(function (accum, key, index) {
var value = query[key];
if (value !== null) {
return "" + accum + (index === 0 ? "?" : "&") + key + "=" + encodeURIComponent(value);
}
return accum;
}, base); };
var makeGoogleCalendarUrl = function (event) { return makeUrl("https://calendar.google.com/calendar/render", {
action: "TEMPLATE",
dates: "".concat(makeTime(event.startsAt), "/").concat(makeTime(event.endsAt)),
dates: makeTime(event.startsAt) + "/" + makeTime(event.endsAt),
location: event.location,
text: event.name,
details: event.details
});
};
var makeOutlookCalendarUrl = function makeOutlookCalendarUrl(event) {
return makeUrl("https://outlook.live.com/owa", {
}); };
var makeOutlookCalendarUrl = function (event) { return makeUrl("https://outlook.live.com/owa", {
rru: "addevent",

@@ -44,7 +32,4 @@ startdt: makeTime(event.startsAt),

path: "/calendar/view/Month"
});
};
var makeYahooCalendarUrl = function makeYahooCalendarUrl(event) {
return makeUrl("https://calendar.yahoo.com", {
}); };
var makeYahooCalendarUrl = function (event) { return makeUrl("https://calendar.yahoo.com", {
v: 60,

@@ -58,12 +43,20 @@ view: "d",

in_loc: event.location
});
}); };
var makeICSCalendarUrl = function (event) {
var components = [
"BEGIN:VCALENDAR",
"VERSION:2.0",
"BEGIN:VEVENT",
"URL:" + document.URL,
"DTSTART:" + makeTime(event.startsAt),
"DTEND:" + makeTime(event.endsAt),
"SUMMARY:" + event.name,
"DESCRIPTION:" + event.details,
"LOCATION:" + event.location,
"END:VEVENT",
"END:VCALENDAR"
];
return encodeURI("data:text/calendar;charset=utf8," + components.join("\n"));
};
var makeICSCalendarUrl = function makeICSCalendarUrl(event) {
var components = ["BEGIN:VCALENDAR", "VERSION:2.0", "BEGIN:VEVENT", "URL:".concat(document.URL), "DTSTART:".concat(makeTime(event.startsAt)), "DTEND:".concat(makeTime(event.endsAt)), "SUMMARY:".concat(event.name), "DESCRIPTION:".concat(event.details), "LOCATION:".concat(event.location), "END:VEVENT", "END:VCALENDAR"];
return encodeURI("data:text/calendar;charset=utf8,".concat(components.join("\n")));
};
var makeUrls = function makeUrls(event) {
return {
var makeUrls = function (event) { return ({
google: makeGoogleCalendarUrl(event),

@@ -73,6 +66,3 @@ outlook: makeOutlookCalendarUrl(event),

ics: makeICSCalendarUrl(event)
};
};
var _default = makeUrls;
exports["default"] = _default;
}); };
exports.default = makeUrls;
{
"name": "@culturehq/add-to-calendar",
"version": "1.0.2",
"version": "1.0.3",
"description": "A small package for adding an event to a calendar.",
"main": "dist/AddToCalendar.js",
"types": "dist/AddToCalendar.d.ts",
"scripts": {
"build": "tsc",
"docs": "webpack --mode production",
"lint": "chq-scripts lint",
"prepublishOnly": "rm -f dist/* && babel src --out-dir ./dist --ignore '**/__tests__' && cp src/styles.css dist",
"lint": "chq-scripts lint --ext .js,.ts,.tsx",
"prepublishOnly": "rm -f dist/* && yarn build --declaration && cp src/styles.css dist",
"start": "webpack-dev-server --mode development --hot",

@@ -28,17 +30,43 @@ "test": "chq-scripts test"

"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/preset-react": "^7.0.0",
"@culturehq/scripts": "^1.0.0",
"@testing-library/react": "^8.0.1",
"@babel/preset-typescript": "^7.3.3",
"@babel/register": "^7.5.5",
"@culturehq/scripts": "^3.0.1",
"@testing-library/react": "^9.1.0",
"@types/jest": "^24.0.18",
"@types/react": "^16.9.2",
"@types/react-dom": "^16.9.0",
"@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"awesome-typescript-loader": "^5.2.1",
"babel-loader": "^8.0.6",
"css-loader": "^3.0.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"style-loader": "^0.23.0",
"webpack": "^4.33.0",
"css-loader": "^3.1.0",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"style-loader": "^1.0.0",
"typescript": "^3.5.3",
"webpack": "^4.37.0",
"webpack-cli": "^3.3.3",
"webpack-dev-server": "^3.7.1"
"webpack-dev-server": "^3.8.0"
},
"resolutions": {
"@types/react": "^16.9.2",
"@types/react-dom": "^16.9.0"
},
"eslintConfig": {
"extends": [
"@culturehq",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
]
},
"jest": {
"testRegex": "\\.test\\.(j|t)sx?$"
}
}
# @culturehq/add-to-calendar
[![Build Status](https://github.com/CultureHQ/add-to-calendar/workflows/Push/badge.svg)](https://github.com/CultureHQ/add-to-calendar/actions)
[![Package Version](https://img.shields.io/npm/v/@culturehq/add-to-calendar.svg)](https://www.npmjs.com/package/@culturehq/add-to-calendar)

@@ -53,2 +54,2 @@

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
The code is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc