@diplodoc/transform 4.63.0 → 4.63.1

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.
@@ -1,3 +1,28 @@
1
+ import type {Lang} from 'src/transform/typings';
2
+
1
3
  export const INLINE_CODE = '.yfm-clipboard-inline-code';
2
4
 
5
+ export const INLINE_CODE_ID = 'tooltip_inline_clipboard_dialog';
6
+
7
+ export const INLINE_CODE_CLASS = 'yfm inline_code_tooltip';
8
+
3
9
  export const OPEN_CLASS = 'open';
10
+
11
+ export const LANG_TOKEN: Record<Lang, string> = {
12
+ ru: 'Скопировано',
13
+ en: 'Copied',
14
+ ar: 'تم النسخ',
15
+ cs: 'Zkopírováno',
16
+ fr: 'Copié',
17
+ es: 'Copiado',
18
+ he: 'הועתק',
19
+ bg: 'Копирано',
20
+ et: 'Kopeeritud',
21
+ el: 'Αντιγράφηκε',
22
+ pt: 'Copiado',
23
+ zh: '已复制',
24
+ 'zh-tw': '已複製',
25
+ kk: 'Көшірілді',
26
+ tr: 'Kopyalandı',
27
+ uz: 'Nusxalandi',
28
+ };
@@ -1,13 +1,15 @@
1
+ import type {Lang} from 'src/transform/typings';
2
+
1
3
  import {getCoords} from '../term/utils';
2
4
 
3
- import {OPEN_CLASS} from './constant';
5
+ import {INLINE_CODE, INLINE_CODE_CLASS, INLINE_CODE_ID, LANG_TOKEN, OPEN_CLASS} from './constant';
4
6
 
5
7
  export let timer: ReturnType<typeof setTimeout> | null = null;
6
8
 
7
9
  let isListenerNeeded = true;
8
10
 
9
11
  export function getTooltipElement(): HTMLElement | null {
10
- return document.querySelector('.yfm-inline-code-tooltip');
12
+ return document.getElementById(INLINE_CODE_ID);
11
13
  }
12
14
 
13
15
  function setTooltipAriaAttributes(tooltipElement: HTMLElement, targetElement: HTMLElement): void {
@@ -135,40 +137,65 @@ export function getInlineCodeByTooltip(definition: HTMLElement) {
135
137
  function closeTooltipFn(definition: HTMLElement) {
136
138
  definition.classList.remove(OPEN_CLASS);
137
139
  const inline = getInlineCodeByTooltip(definition);
138
- const tooltipParent = tooltipParentElement(inline);
140
+ const inlineCodepParent = tooltipParentElement(inline);
141
+ const tooltipParent = tooltipParentElement(definition);
139
142
 
140
143
  definition.removeAttribute('inline-id');
141
144
 
142
- if (!tooltipParent) {
145
+ if (!inlineCodepParent || !tooltipParent) {
143
146
  return;
144
147
  }
145
148
 
146
- tooltipParent.removeEventListener('scroll', tooltipOnResize);
149
+ tooltipParent.removeChild(definition);
150
+ inlineCodepParent.removeEventListener('scroll', tooltipOnResize);
147
151
  isListenerNeeded = true;
148
152
  }
149
153
 
154
+ function createTooltip() {
155
+ let tooltip = getTooltipElement();
156
+
157
+ if (!tooltip) {
158
+ const pageContent = document.querySelector('.dc-doc-page__content') || document.body;
159
+ const lang = document.documentElement.lang || 'en';
160
+ const tooltipText = LANG_TOKEN[lang as Lang] ?? LANG_TOKEN.en;
161
+ const host = document.createElement('div');
162
+
163
+ host.innerHTML = `
164
+ <div id="${INLINE_CODE_ID}" class="${INLINE_CODE_CLASS}"
165
+ role="dialog" aria-live="polite" aria-modal="true">
166
+ ${tooltipText}
167
+ </div>
168
+ `;
169
+
170
+ tooltip = host.firstElementChild as HTMLElement;
171
+ pageContent.appendChild(tooltip);
172
+ }
173
+
174
+ return tooltip;
175
+ }
176
+
150
177
  export function openTooltip(target: HTMLElement) {
151
- const tooltipElement = document.getElementById('tooltip_inline_clipboard_dialog');
178
+ const tooltip = createTooltip();
152
179
 
153
- if (!target.matches('.yfm-clipboard-inline-code') || !tooltipElement) {
180
+ if (!target.matches(INLINE_CODE) || !tooltip) {
154
181
  return;
155
182
  }
156
183
 
157
- tooltipElement.setAttribute('inline-id', target.getAttribute('id') || '');
158
- setTooltipAriaAttributes(tooltipElement, target);
159
- setTooltipPosition(tooltipElement, target);
184
+ tooltip.setAttribute('inline-id', target.getAttribute('id') || '');
185
+ setTooltipAriaAttributes(tooltip, target);
186
+ setTooltipPosition(tooltip, target);
160
187
 
161
188
  // In order not to get rid of the smooth appearance effect, I had to do this
162
- if (tooltipElement.classList.contains(OPEN_CLASS)) {
163
- tooltipElement.classList.remove(OPEN_CLASS);
189
+ if (tooltip.classList.contains(OPEN_CLASS)) {
190
+ tooltip.classList.remove(OPEN_CLASS);
164
191
  requestAnimationFrame(() => {
165
- tooltipElement.classList.add(OPEN_CLASS);
192
+ tooltip.classList.add(OPEN_CLASS);
166
193
  });
167
194
  } else {
168
- tooltipElement.classList.add(OPEN_CLASS);
195
+ tooltip.classList.add(OPEN_CLASS);
169
196
  }
170
197
 
171
- return tooltipElement;
198
+ return tooltip;
172
199
  }
173
200
 
174
201
  export function closeTooltip(target: HTMLElement) {
@@ -2,7 +2,7 @@
2
2
  position: absolute;
3
3
  z-index: 100;
4
4
 
5
- visibility: hidden;
5
+ display: none;
6
6
  opacity: 0;
7
7
 
8
8
  padding: 10px;
@@ -38,7 +38,7 @@
38
38
  }
39
39
 
40
40
  &.open {
41
- visibility: visible;
41
+ display: block;
42
42
 
43
43
  animation-name: popup;
44
44
  animation-duration: 0.1s;
@@ -177,13 +177,13 @@ function liquidDocument<
177
177
  const liquidedContent =
178
178
  typeof liquidedResult === 'object' ? liquidedResult.output : liquidedResult;
179
179
 
180
- const output = composeFrontMatter(liquidedFrontMatter, liquidedContent);
180
+ const output = composeFrontMatter(liquidedFrontMatter, liquidedContent as string);
181
181
 
182
182
  if (typeof liquidedResult === 'object') {
183
183
  const inputLinesCount = linesCount(input);
184
184
  const outputLinesCount = linesCount(output);
185
185
  const contentLinesCount = linesCount(strippedContent);
186
- const contentLinesDiff = linesCount(liquidedContent) - contentLinesCount;
186
+ const contentLinesDiff = linesCount(liquidedContent as string) - contentLinesCount;
187
187
 
188
188
  const fullLinesDiff = outputLinesCount - inputLinesCount;
189
189
 
@@ -1,24 +1,5 @@
1
1
  import type {Lang} from '../typings';
2
2
 
3
- export const LANG_TOKEN: Record<Lang, string> = {
4
- ru: 'Скопировано',
5
- en: 'Copied',
6
- ar: 'تم النسخ',
7
- cs: 'Zkopírováno',
8
- fr: 'Copié',
9
- es: 'Copiado',
10
- he: 'הועתק',
11
- bg: 'Копирано',
12
- et: 'Kopeeritud',
13
- el: 'Αντιγράφηκε',
14
- pt: 'Copiado',
15
- zh: '已复制',
16
- 'zh-tw': '已複製',
17
- kk: 'Көшірілді',
18
- tr: 'Kopyalandı',
19
- uz: 'Nusxalandi',
20
- };
21
-
22
3
  export const LANG_TOKEN_DESCRIPTION: Record<Lang, string> = {
23
4
  ru: 'Чтобы скопировать текст внутри блока нажмите на блок',
24
5
  en: 'To copy the text inside the block, click on the block',
@@ -1,10 +1,10 @@
1
- import type {MarkdownItPluginCb, StateCore} from '../../typings';
1
+ import type {MarkdownItPluginCb} from '../../typings';
2
2
 
3
3
  import {escapeHtml} from 'markdown-it/lib/common/utils';
4
4
 
5
5
  import {generateID} from '../utils';
6
6
 
7
- import {LANG_TOKEN, LANG_TOKEN_DESCRIPTION, LANG_TOKEN_LABEL} from './constant';
7
+ import {LANG_TOKEN_DESCRIPTION, LANG_TOKEN_LABEL} from './constant';
8
8
 
9
9
  const inlineCode: MarkdownItPluginCb = (md, options) => {
10
10
  const lang = options.lang;
@@ -17,45 +17,6 @@ const inlineCode: MarkdownItPluginCb = (md, options) => {
17
17
 
18
18
  return `<code class="yfm-clipboard-inline-code" role="button" aria-label="${label}" aria-description="${description}" tabindex='0' id="inline-code-id-${id}">${escapeHtml(tokens[idx].content)}</code>`;
19
19
  };
20
-
21
- md.core.ruler.after('inline', 'tooltip_code_inline', (state: StateCore) => {
22
- const tokens = state.tokens;
23
-
24
- for (let i = 0; i !== tokens.length; i++) {
25
- const token = tokens[i];
26
-
27
- if (token.type !== 'inline') {
28
- continue;
29
- }
30
-
31
- if (!token.children || token.children.every((e) => e.type !== 'code_inline')) {
32
- continue;
33
- }
34
-
35
- const child = token.children.find((e) => e.type === 'code_inline');
36
-
37
- if (!child) {
38
- return;
39
- }
40
-
41
- const dialog = new state.Token('tooltip_open', 'div', 1);
42
- dialog.attrSet('class', 'yfm inline_code_tooltip');
43
- dialog.attrSet('id', `tooltip_inline_clipboard_dialog`);
44
- dialog.attrSet('role', 'dialog');
45
- dialog.attrSet('aria-live', 'polite');
46
- dialog.attrSet('aria-modal', 'true');
47
-
48
- tokens.push(dialog);
49
-
50
- const text = new state.Token('text', '', 0);
51
- text.content = LANG_TOKEN[lang] ?? LANG_TOKEN.en;
52
- tokens.push(text);
53
-
54
- const closeDialog = new state.Token('tooltip_close', 'div', -1);
55
- tokens.push(closeDialog);
56
- break;
57
- }
58
- });
59
20
  };
60
21
 
61
22
  export = inlineCode;