@codedoc/core
Version:
Create beautiful modern documentation websites.
45 lines • 2.58 kB
JavaScript
import { funcTransport, onReady } from '@connectv/sdh/transport';
import { getRenderer } from '../../../transport/renderer';
import { copyToClipboard } from '../../../transport/clipboard';
import { Toast } from '../../util/toast';
import { lineLink, linkedLines } from './line-link';
export function copyLineLinks() {
const renderer = getRenderer();
onReady(() => {
const _exec = () => {
document.querySelectorAll('pre>code>.-codedoc-code-line').forEach(line$ => {
const counter$ = line$.querySelector('.-codedoc-line-counter');
counter$ === null || counter$ === void 0 ? void 0 : counter$.addEventListener('click', event => {
event.stopPropagation();
const link = lineLink(line$);
copyToClipboard(link, () => renderer.render(renderer.create(Toast, null,
"Link Copied to Clipboard!",
renderer.create("br", null),
renderer.create("a", { href: link, style: "font-size: 12px; color: white" }, link))).on(document.body));
});
counter$ === null || counter$ === void 0 ? void 0 : counter$.addEventListener('mousedown', event => event.stopPropagation());
counter$ === null || counter$ === void 0 ? void 0 : counter$.addEventListener('mouseup', event => event.stopPropagation());
});
};
const _detect = () => {
var _a;
const linked = linkedLines();
if (linked.length > 0) {
(_a = linked[0].parentElement) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.selected').forEach(el => el.classList.remove('selected'));
}
linked.forEach(line$ => {
var _a;
line$ === null || line$ === void 0 ? void 0 : line$.classList.add('selected');
(_a = line$ === null || line$ === void 0 ? void 0 : line$.parentElement) === null || _a === void 0 ? void 0 : _a.classList.add('has-selection');
});
if (linked.length > 0)
setTimeout(() => { var _a; return (_a = linked[0]) === null || _a === void 0 ? void 0 : _a.scrollIntoView({ block: 'center' }); }, 300);
};
_exec();
_detect();
window.addEventListener('navigation', () => { _exec(); _detect(); });
window.addEventListener('hashchange', _detect);
});
}
export const copyLineLiks$ = /*#__PURE__*/ funcTransport(copyLineLinks);
//# sourceMappingURL=copy-line-link.js.map