Repository URL to install this package:
Version:
0.9.7 ▾
|
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @file @todo there is a bug open for missing @description
* should pass `product` not `name`
*/
const router_1 = __importDefault(require("@skava/modules/___dist/router"));
const exotic_1 = require("exotic");
const Copy_1 = require("./Copy");
// import { FACEBOOK_APP_ID } from '@skava/modules/___dist/api/config'
// For temporary fix.. Needs to move this in @skava/modules/___dist config
const FACEBOOK_APP_ID = '174209059840584';
// export function copyToClipboard(urlToCopy: string): void {
// const listener = event => {
// event.clipboardData.setData('text/plain', urlToCopy)
// // alert('Hurray! Url copied to clipboard:\r\n' + urlToCopy)
// event.preventDefault()
// }
// document.addEventListener('copy', listener)
// document.execCommand('copy')
// document.removeEventListener('copy', listener)
// }
const pluginsList = [
{
label: 'Facebook',
isSatisfiedBy(label) {
return label === 'Facebook';
},
fromPropsToUrl(props) {
const { productName, item } = props;
const fromUrl = item.url;
const appid = FACEBOOK_APP_ID;
const url = 'https://www.facebook.com/dialog/share?' +
'app_id=' +
encodeURIComponent(appid) +
'&display=popup&caption=' +
encodeURIComponent(productName) +
'&href=' +
encodeURIComponent(fromUrl) +
'&redirect_uri=' +
encodeURIComponent('https://www.facebook.com/');
return url;
},
bgcolor: '#3A559F',
color: '#fff',
},
{
label: 'Pinterest',
isSatisfiedBy(label) {
return label === 'Pinterest';
},
fromPropsToUrl(props) {
const { media, productName, item } = props;
const fromUrl = item.url;
const url = 'https://pinterest.com/pin/create/button/?url='
+ encodeURIComponent(fromUrl) + '&description='
+ encodeURIComponent(productName);
return url;
},
bgcolor: '#BD091D',
color: '#fff',
},
{
label: 'Twitter',
isSatisfiedBy(label) {
return label === 'Twitter';
},
fromPropsToUrl(props) {
const { productName, item } = props;
const fromUrl = item.url;
const url = 'https://twitter.com/share?url=' + fromUrl + '&text=' + encodeURIComponent(productName);
return url;
},
bgcolor: '#50ABF1',
color: '#fff',
},
{
label: 'social-link',
isSatisfiedBy(label) {
return label === 'social-link';
},
fromPropsToUrl(props) {
const { productName, item } = props;
item.onClick = (args) => {
const currentUrl = router_1.default.get('href');
if (currentUrl) {
Copy_1.copy(currentUrl);
}
if (exotic_1.isFunction(props.onClick)) {
props.onClick(event, item);
}
};
return '';
},
bgcolor: '#5F6C88',
color: '#fff',
},
];
function fromListOfTemplateStringsToRendered(list, props) {
const toLinkAttributes = args => {
const { item, found } = args;
item.url = router_1.default.get('href');
const mergedProps = Object.assign({}, props, item, { item });
const url = found.fromPropsToUrl(mergedProps);
const attributes = Object.assign({}, found, { url });
return attributes;
};
const toAttributes = args => {
const { found, item } = args;
if (exotic_1.isFunction(found.fromPropsToUrl) === true) {
const _a = toLinkAttributes(args), { isSatisfiedBy } = _a, remainingAttributes = __rest(_a, ["isSatisfiedBy"]);
return remainingAttributes;
}
else {
const { isSatisfiedBy } = found, remainingAttributes = __rest(found, ["isSatisfiedBy"]);
return remainingAttributes;
}
};
const updated = (item, index) => {
const isSatisfiedBy = plugin => plugin.isSatisfiedBy(item.label);
const found = pluginsList.find(isSatisfiedBy);
const attributes = toAttributes({ found, item });
return attributes;
};
const updatedList = pluginsList.map(updated);
return updatedList;
}
exports.fromListOfTemplateStringsToRendered = fromListOfTemplateStringsToRendered;
exports.isNonEmptyString = (x) => exotic_1.isString(x) && x.length > 0;
//# sourceMappingURL=deps.js.map