@memori.ai/memori-react
Version:
[](https://www.npmjs.com/package/@memori.ai/memori-react)  ;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const react_i18next_1 = require("react-i18next");
const LinkItemWidget_1 = require("../MediaWidget/LinkItemWidget");
const Button_1 = tslib_1.__importDefault(require("../ui/Button"));
const Modal_1 = tslib_1.__importDefault(require("../ui/Modal"));
const AttachmentLinkModal = ({ visible, onCancel, onOk }) => {
var _a, _b, _c;
const { t } = (0, react_i18next_1.useTranslation)();
const [newLink, setNewLink] = (0, react_1.useState)({
url: '',
title: '',
});
const onKeyPress = (e) => {
if (e.key === 'Enter') {
if ((newLink === null || newLink === void 0 ? void 0 : newLink.url.length) === 0 || (newLink === null || newLink === void 0 ? void 0 : newLink.title.length) === 0)
return;
let saveButton = document.getElementById('save-link-button');
if (saveButton) {
saveButton.click();
}
}
};
return ((0, jsx_runtime_1.jsx)(Modal_1.default, { open: visible, title: t('media.addLinkLabel'), className: "attachment-link-modal", closable: true, width: "100%", widthMd: "80%", onClose: () => {
if (onCancel)
onCancel();
}, footer: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Button_1.default, { onClick: onCancel, children: t('cancel') }), (0, jsx_runtime_1.jsx)(Button_1.default, { id: "save-link-button", primary: true, onClick: () => {
if ((newLink === null || newLink === void 0 ? void 0 : newLink.url.length) === 0 || (newLink === null || newLink === void 0 ? void 0 : newLink.title.length) === 0)
return;
onOk(newLink);
setNewLink({ url: '', title: '' });
}, disabled: (newLink === null || newLink === void 0 ? void 0 : newLink.url.length) === 0 || (newLink === null || newLink === void 0 ? void 0 : newLink.title.length) === 0, children: t('confirm') })] }), children: (0, jsx_runtime_1.jsxs)("div", { className: "attachment-link-modal--row", children: [(0, jsx_runtime_1.jsxs)("div", { className: "attachment-link-modal--column", children: [(0, jsx_runtime_1.jsxs)("label", { htmlFor: "new-link-url", className: "attachment-link-modal--label", children: [t('media.linkKey'), ":"] }), (0, jsx_runtime_1.jsx)("input", { type: "url", className: "attachment-link-modal--input ", onChange: e => {
let value = e.target.value.startsWith('http') || e.target.value.length === 0
? e.target.value
: `https://${e.target.value}`;
setNewLink(l => { var _a; return ({ title: (_a = l === null || l === void 0 ? void 0 : l.title) !== null && _a !== void 0 ? _a : '', url: value }); });
}, placeholder: "https://memori.ai/...", value: newLink === null || newLink === void 0 ? void 0 : newLink.url, name: "url", onKeyDown: onKeyPress }), (0, jsx_runtime_1.jsxs)("label", { htmlFor: "new-link-title", className: "attachment-link-modal--label", children: [t('media.linkValue'), ":"] }), (0, jsx_runtime_1.jsx)("input", { type: "text", className: "attachment-link-modal--input ", onChange: e => setNewLink(l => { var _a; return ({ url: (_a = l === null || l === void 0 ? void 0 : l.url) !== null && _a !== void 0 ? _a : '', title: e.target.value }); }), value: newLink === null || newLink === void 0 ? void 0 : newLink.title, name: "title", onKeyDown: onKeyPress })] }), (0, jsx_runtime_1.jsx)("div", { className: "attachment-link-modal--column", children: (0, jsx_runtime_1.jsx)("div", { className: "attachment-link-modal--centered", children: (0, jsx_runtime_1.jsx)(LinkItemWidget_1.RenderLinkItem, { item: {
title: (_a = newLink === null || newLink === void 0 ? void 0 : newLink.title) !== null && _a !== void 0 ? _a : '',
url: (_b = newLink === null || newLink === void 0 ? void 0 : newLink.url) !== null && _b !== void 0 ? _b : '',
mediumID: '',
mimeType: 'text/html',
}, onLinkPreviewInfo: data => {
var _a;
if (!((_a = newLink === null || newLink === void 0 ? void 0 : newLink.title) === null || _a === void 0 ? void 0 : _a.length)) {
setNewLink(l => {
var _a;
return ({
...l,
title: (_a = data === null || data === void 0 ? void 0 : data.title) !== null && _a !== void 0 ? _a : '',
});
});
}
} }, (_c = newLink === null || newLink === void 0 ? void 0 : newLink.url) !== null && _c !== void 0 ? _c : '') }) })] }) }));
};
exports.default = AttachmentLinkModal;
//# sourceMappingURL=AttachmentLinkModal.js.map