Skip to content

Commit f18fd94

Browse files
authored
breaking: rename mrq to aubade (#148)
1 parent a9d9f70 commit f18fd94

File tree

15 files changed

+365
-307
lines changed

15 files changed

+365
-307
lines changed

workspace/aubade/src/artisan/palette/index.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,28 @@ export function transform(source: string, dataset: Dataset): string {
3333
([k, v]) => `data-${k.toLowerCase().replace(/[^a-z\-]/g, '')}="${escape(v || '')}"`,
3434
);
3535

36-
// @TODO: rename `data-mrq` to `data-aubade`
3736
// needs to be /^<pre/ to prevent added wrapper from markdown-it
38-
return `<pre data-mrq="block" class="mrq">
37+
return `<pre data-aubade="block">
3938
<header
40-
data-mrq="header"
39+
data-aubade="header"
4140
${attrs.join('\n\t\t')}
42-
class="mrq ${file ? '' : 'empty'}"
41+
class="aubade ${file ? '' : 'empty'}"
4342
>${file ? `<span>${file}</span>` : ''}
44-
<div data-mrq="toolbar" class="mrq">
43+
<div data-aubade="toolbar">
4544
${icon('list', 'Toggle\nNumbering')}
4645
${icon('clipboard', 'Copy')}
4746
</div>
4847
</header>
4948
5049
<div
51-
data-mrq="pre"
50+
data-aubade="pre"
5251
${attrs.join('\n\t\t')}
53-
class="mrq language-${rest.language || 'none'}"
52+
class="aubade language-${rest.language || 'none'}"
5453
>${highlighted.trim()}</div>
5554
</pre>`;
5655
}
5756

5857
function icon(name: 'clipboard' | 'list', tooltip: string) {
59-
const span = `<span data-mrq="tooltip" class="mrq">${tooltip}</span>`;
60-
return `<button data-mrq-toolbar="${name}" class="mrq">${span}</button>`;
58+
const span = `<span data-aubade="tooltip">${tooltip}</span>`;
59+
return `<button data-aubade-toolbar="${name}">${span}</button>`;
6160
}
Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,48 @@
11
import { clipboard } from 'mauss/web';
22

3-
export function listen(node: HTMLElement) {
4-
for (const block of node.querySelectorAll('.mrq[data-mrq="block"]')) {
5-
const actions = block.querySelectorAll('.mrq[data-mrq-toolbar]');
6-
const source = block.querySelector('.mrq[data-mrq="pre"]');
7-
if (!actions.length || !source) continue;
3+
export function hydrate(signal?: any) {
4+
signal; // listen to signal changes and re-run the function if needed
5+
return (node: HTMLElement) => {
6+
const active: Array<() => void> = [];
7+
for (const block of node.querySelectorAll('[data-aubade="block"]')) {
8+
const actions = block.querySelectorAll('[data-aubade-toolbar]');
9+
const source = block.querySelector('[data-aubade="pre"]');
10+
if (!actions.length || !source) continue;
811

9-
for (const item of actions) {
10-
const action = item.getAttribute('data-mrq-toolbar');
11-
if (action === 'clipboard') {
12-
item.addEventListener('click', () => {
13-
const tooltip = item.querySelector('.mrq[data-mrq="tooltip"]');
14-
if (!tooltip) return;
15-
const text = tooltip.textContent;
16-
clipboard.copy(source.textContent || '', {
17-
accept() {
18-
tooltip.textContent = 'Copied to clipboard!';
19-
},
20-
reject() {
21-
tooltip.textContent = `Failed to copy code`;
22-
},
23-
});
12+
for (const item of actions) {
13+
const action = item.getAttribute('data-aubade-toolbar');
14+
if (action === 'clipboard') {
15+
const tooltip = item.querySelector('[data-aubade="tooltip"]');
16+
if (!tooltip) continue;
17+
const original = tooltip.textContent;
2418

25-
setTimeout(() => {
26-
tooltip.textContent = text;
27-
}, 5000);
28-
});
29-
} else if (action === 'list') {
30-
item.addEventListener('click', () => {
31-
source.classList.toggle('numbered');
32-
});
19+
const handler = () => {
20+
clipboard.copy(source.textContent || '', {
21+
accept() {
22+
tooltip.textContent = 'Copied to clipboard!';
23+
},
24+
reject() {
25+
tooltip.textContent = `Failed to copy code`;
26+
},
27+
});
28+
29+
setTimeout(() => {
30+
tooltip.textContent = original;
31+
}, 5000);
32+
};
33+
34+
item.addEventListener('click', handler);
35+
active.push(() => item.removeEventListener('click', handler));
36+
} else if (action === 'list') {
37+
const handler = () => source.classList.toggle('numbered');
38+
item.addEventListener('click', handler);
39+
active.push(() => item.removeEventListener('click', handler));
40+
}
3341
}
3442
}
35-
}
36-
}
37-
38-
export function hydrate(node: HTMLElement, _: any) {
39-
listen(node);
40-
return {
41-
update: () => listen(node),
43+
return () => {
44+
active.forEach((fn) => fn());
45+
active.length = 0;
46+
};
4247
};
4348
}

0 commit comments

Comments
 (0)