UNPKG

@atlaskit/editor-plugin-block-menu

Version:

BlockMenu plugin for @atlaskit/editor-core

57 lines 2.57 kB
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _regeneratorRuntime from "@babel/runtime/regenerator"; import { createBlockLinkHashValue, DEFAULT_BLOCK_LINK_HASH_PREFIX } from '@atlaskit/editor-common/block-menu'; import { copyToClipboard } from '@atlaskit/editor-common/clipboard'; import { logException } from '@atlaskit/editor-common/monitoring'; import { expandSelectionToBlockRange } from '@atlaskit/editor-common/selection'; export var copyLink = /*#__PURE__*/function () { var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) { var getLinkPath, _ref$blockLinkHashPre, blockLinkHashPrefix, selection, blockRange, node, path, url, href; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: getLinkPath = _ref.getLinkPath, _ref$blockLinkHashPre = _ref.blockLinkHashPrefix, blockLinkHashPrefix = _ref$blockLinkHashPre === void 0 ? DEFAULT_BLOCK_LINK_HASH_PREFIX : _ref$blockLinkHashPre, selection = _ref.selection; blockRange = expandSelectionToBlockRange(selection); if (blockRange) { _context.next = 4; break; } return _context.abrupt("return", false); case 4: // get the link to the first node in the selection node = blockRange.$from.nodeAfter; if (!(!node || !node.attrs || !node.attrs.localId)) { _context.next = 7; break; } return _context.abrupt("return", false); case 7: path = (getLinkPath === null || getLinkPath === void 0 ? void 0 : getLinkPath()) || location.pathname; _context.prev = 8; url = new URL(location.origin + path); url.hash = createBlockLinkHashValue(node.attrs.localId, blockLinkHashPrefix); href = url.toString(); _context.next = 14; return copyToClipboard(href); case 14: _context.next = 20; break; case 16: _context.prev = 16; _context.t0 = _context["catch"](8); logException(_context.t0, { location: 'editor-plugin-block-menu' }); return _context.abrupt("return", false); case 20: return _context.abrupt("return", true); case 21: case "end": return _context.stop(); } }, _callee, null, [[8, 16]]); })); return function copyLink(_x) { return _ref2.apply(this, arguments); }; }();