@diplodoc/transform 4.76.4 → 4.76.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/js/code.ts CHANGED
@@ -2,6 +2,7 @@ import {copyToClipboard, getEventTarget, isCustom} from './utils';
2
2
 
3
3
  const COPY_BUTTON_SELECTOR = '.yfm-clipboard-button';
4
4
  const WRAP_BUTTON_SELECTOR = '.yfm-wrapping-button';
5
+ const FLOATING_CONTAINER_SELECTOR = '.yfm-code-floating-container';
5
6
 
6
7
  function notifySuccess(svgButton: HTMLElement | null) {
7
8
  if (!svgButton) {
@@ -21,9 +22,11 @@ function notifySuccess(svgButton: HTMLElement | null) {
21
22
  }
22
23
 
23
24
  function buttonCopyFn(target: HTMLElement) {
24
- const container = target.parentNode?.parentNode;
25
+ const button = target.closest<HTMLElement>(COPY_BUTTON_SELECTOR);
26
+ const container = button?.closest<HTMLElement>(FLOATING_CONTAINER_SELECTOR);
25
27
  const code = container?.querySelector<HTMLElement>('pre code');
26
- if (!container || !code) {
28
+
29
+ if (!button || !container || !code) {
27
30
  return;
28
31
  }
29
32
 
@@ -47,13 +50,14 @@ function buttonCopyFn(target: HTMLElement) {
47
50
  }
48
51
 
49
52
  function buttonWrapFn(target: HTMLElement) {
50
- const container = target.parentNode?.parentNode;
53
+ const button = target.closest<HTMLElement>(WRAP_BUTTON_SELECTOR);
54
+ const container = button?.closest<HTMLElement>(FLOATING_CONTAINER_SELECTOR);
51
55
  const code = container?.querySelector<HTMLElement>('pre code');
52
- if (!container || !code) {
56
+ if (!button || !container || !code) {
53
57
  return;
54
58
  }
55
-
56
59
  code.classList.toggle('wrap');
60
+ button.setAttribute('aria-pressed', String(code.classList.contains('wrap')));
57
61
 
58
62
  setTimeout(() => target.blur(), 500);
59
63
  }
@@ -66,9 +70,9 @@ if (typeof document !== 'undefined') {
66
70
 
67
71
  const target = getEventTarget(event) as HTMLElement;
68
72
 
69
- if (target.matches(COPY_BUTTON_SELECTOR)) {
73
+ if (target.closest(COPY_BUTTON_SELECTOR)) {
70
74
  buttonCopyFn(target);
71
- } else if (target.matches(WRAP_BUTTON_SELECTOR)) {
75
+ } else if (target.closest(WRAP_BUTTON_SELECTOR)) {
72
76
  buttonWrapFn(target);
73
77
  }
74
78
  });