@diplodoc/transform 4.32.2 → 4.34.2-beta1

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/dist/js/yfm.js CHANGED
@@ -108,55 +108,62 @@
108
108
 
109
109
  // node_modules/@diplodoc/tabs-extension/build/runtime/index.js
110
110
  (() => {
111
- var X = "yfm-tabs", V = "yfm-tabs-vertical", Q = "yfm-tab-list", R = "yfm-tab", f = "yfm-tab-panel", G = "active";
112
- var h = "data-diplodoc-radio-forced", y = "data-diplodoc-group", L = "data-diplodoc-key", S = "data-diplodoc-id";
113
- var v = "defaultTabsGroup-";
114
- var x = Symbol.for("diplodocTabs");
115
- var u = (r) => {
116
- let t = r.composedPath();
117
- return Array.isArray(t) && t.length > 0 ? t[0] : r.target;
118
- }, O = (r) => {
119
- let t = u(r);
111
+ var v = "yfm-tabs", W = "yfm-tab", O = "yfm-tab-panel", Q = "yfm-tab-list", m = "active";
112
+ var G = "data-diplodoc-group", T = "data-diplodoc-key", y = "data-diplodoc-variant", H = "data-diplodoc-id", L = "defaultTabsGroup-";
113
+ var X = "data-diplodoc-forced";
114
+ var U = "yfm-tabs-dropdown-select";
115
+ var N = "yfm-tabs-vertical";
116
+ var h = Symbol.for("diplodocTabs");
117
+ var f = (d) => {
118
+ let t = d.composedPath();
119
+ return Array.isArray(t) && t.length > 0 ? t[0] : d.target;
120
+ }, Z = (d) => {
121
+ let t = f(d);
120
122
  return !t || !t.matches;
121
- }, E = (r) => Math.abs(r.scrollHeight - r.clientHeight) > 1 ? r : r.parentElement ? E(r.parentElement) : void 0, F = (r, t) => {
122
- let e = r.getBoundingClientRect(), i = t.getBoundingClientRect();
123
- return { top: e.top - i.top, left: e.left - i.left, scrollTop: t.scrollTop, scrollLeft: t.scrollLeft };
123
+ }, F = (d) => Math.abs(d.scrollHeight - d.clientHeight) > 1 ? d : d.parentElement ? F(d.parentElement) : void 0, R = (d, t) => {
124
+ let e = d.getBoundingClientRect(), g = t.getBoundingClientRect();
125
+ return { top: e.top - g.top, left: e.left - g.left, scrollTop: t.scrollTop, scrollLeft: t.scrollLeft };
124
126
  };
125
- var s = { TABS: `.${X}`, TAB_LIST: `.${Q}`, TAB: `.${R}`, TAB_PANEL: `.${f}`, VERTICAL_TABS: `.${V}` }, T = class {
127
+ var C = { TABS: `.${v}`, TAB_LIST: `.${Q}`, TAB: `.${W}`, TAB_PANEL: `.${O}`, VERTICAL_TABS: `.${N}` }, x = class {
126
128
  constructor(t) {
127
129
  this._onSelectTabHandlers = /* @__PURE__ */ new Set();
128
130
  this._document = t, this._document.addEventListener("click", (e) => {
129
- let i = u(e), o = this.areTabsVertical(i);
130
- if (O(e) || !(this.isValidTabElement(i) || o)) return;
131
- let c = this.getTabDataFromHTMLElement(i);
132
- c && this._selectTab(c, i);
131
+ let g = f(e);
132
+ if (e.target && this.hideAllDropdown(e.target), Z(e)) return;
133
+ if (this.isElementDropdownSelect(g)) {
134
+ g.classList.toggle(m);
135
+ return;
136
+ }
137
+ if (!this.isValidTabElement(g)) return;
138
+ let I = this.getTabDataFromHTMLElement(g);
139
+ I && this._selectTab(I, g);
133
140
  }), this._document.addEventListener("keydown", (e) => {
134
- let i = null;
141
+ let g = null;
135
142
  switch (e.key) {
136
143
  case "ArrowLeft": {
137
- i = "left";
144
+ g = "left";
138
145
  break;
139
146
  }
140
147
  case "ArrowRight": {
141
- i = "right";
148
+ g = "right";
142
149
  break;
143
150
  }
144
151
  case "ArrowUp": {
145
- i = "left";
152
+ g = "left";
146
153
  break;
147
154
  }
148
155
  case "ArrowDown": {
149
- i = "right";
156
+ g = "right";
150
157
  break;
151
158
  }
152
159
  }
153
- if (!i) return;
154
- let o = u(e);
155
- if (O(e) || !this.isValidTabElement(o)) return;
156
- let { tabs: c, nodes: a } = this.getTabs(o), l = this.getTabDataFromHTMLElement(o), n = c.findIndex(({ key: d }) => (l == null ? void 0 : l.key) && d === l.key);
157
- if (!l || c.length <= 1 || n === -1) return;
158
- let g = (n + (i === "left" ? -1 : 1) + c.length) % c.length;
159
- this.selectTab(c[g]), a[g].focus();
160
+ if (!g) return;
161
+ let I = f(e);
162
+ if (Z(e) || !this.isValidTabElement(I)) return;
163
+ let { tabs: A, nodes: l } = this.getTabs(I), o = this.getTabDataFromHTMLElement(I), i = A.findIndex(({ key: n }) => (o == null ? void 0 : o.key) && n === o.key);
164
+ if (!o || A.length <= 1 || i === -1) return;
165
+ let c = (i + (g === "left" ? -1 : 1) + A.length) % A.length;
166
+ this.selectTab(A[c]), l[c].focus();
160
167
  });
161
168
  }
162
169
  onSelectTab(t) {
@@ -165,100 +172,155 @@
165
172
  };
166
173
  }
167
174
  selectTabById(t, e) {
168
- let i = this._document.querySelector(`${s.TAB}[${S}="${t}"]`);
169
- if (!i || !this.isValidTabElement(i)) return;
170
- let o = this.getTabDataFromHTMLElement(i);
171
- o && this._selectTab(o, i), e != null && e.scrollToElement && i.scrollIntoView();
175
+ let g = this._document.querySelector(`${C.TAB}[${H}="${t}"]`);
176
+ if (!g || !this.isValidTabElement(g)) return;
177
+ let I = this.getTabDataFromHTMLElement(g);
178
+ I && this._selectTab(I, g), e != null && e.scrollToElement && g.scrollIntoView();
172
179
  }
173
180
  selectTab(t) {
174
181
  this._selectTab(t);
175
182
  }
176
183
  _selectTab(t, e) {
177
- let { group: i, key: o, align: c } = t;
178
- if (!i) return;
179
- let a = e && E(e), l = a && F(e, a);
180
- this.updateHTML({ group: i, key: o, align: c }, e, c) > 0 && (this.fireSelectTabEvent({ group: i, key: o, align: c }, e == null ? void 0 : e.dataset.diplodocId), l && this.resetScroll(e, a, l));
184
+ let { group: g, key: I, variant: A } = t;
185
+ if (!g) return;
186
+ let l = e && F(e), o = l && R(e, l);
187
+ this.updateHTML({ group: g, key: I, variant: A }, e, A) > 0 && (this.fireSelectTabEvent({ group: g, key: I, variant: A }, e == null ? void 0 : e.dataset.diplodocId), o && this.resetScroll(e, l, o));
181
188
  }
182
- updateHTML(t, e, i) {
183
- switch (i) {
189
+ updateHTML(t, e, g) {
190
+ switch (g) {
184
191
  case "radio":
185
- return this.updateHTMLVertical(t, e);
186
- case "horizontal":
187
- return this.updateHTMLHorizontal(t);
192
+ return this.updateHTMLRadio(t, e);
193
+ case "accordion":
194
+ return this.updateHTMLAccordion(t, e);
195
+ case "regular":
196
+ return this.updateHTMLRegular(t);
197
+ case "dropdown":
198
+ return this.updateHTMLDropdown(t);
188
199
  }
189
200
  return 0;
190
201
  }
191
- updateHTMLVertical(t, e) {
192
- let { group: i, key: o } = t, { isForced: c, root: a } = this.didTabOpenForce(e), l = c ? `.yfm-vertical-tab[${h}="true"]` : "", n = this._document.querySelectorAll(`${s.TABS}[${y}="${i}"] ${s.TAB}[${L}="${o}"]${l}`);
193
- c && (a == null || a.removeAttribute(h));
194
- let g = 0;
195
- return n.forEach((d) => {
196
- let p = d.parentNode.children;
197
- for (let C = 0; C < p.length; C += 2) {
198
- let [A, I] = [p.item(C), p.item(C + 1)], b = A.children.item(0);
199
- if (A === d) {
200
- b.checked ? (A.classList.remove("active"), I == null || I.classList.remove("active"), b.removeAttribute("checked")) : (A.classList.add("active"), I == null || I.classList.add("active"), b.setAttribute("checked", "true"));
202
+ updateHTMLRadio(t, e) {
203
+ let { group: g, key: I } = t, { isForced: A, root: l } = this.didTabOpenForce(e), o = A ? `.yfm-vertical-tab[${X}="true"]` : "", i = this._document.querySelectorAll(`${C.TABS}[${G}="${g}"] ${C.TAB}[${T}="${I}"]${o}`);
204
+ A && (l == null || l.removeAttribute(X));
205
+ let c = 0;
206
+ return i.forEach((n) => {
207
+ let r = n.parentNode.children;
208
+ for (let p = 0; p < r.length; p += 2) {
209
+ let [s, b] = [r.item(p), r.item(p + 1)], u = s.children.item(0);
210
+ if (s === n) {
211
+ u.checked ? (s.classList.remove("active"), b == null || b.classList.remove("active"), u.removeAttribute("checked")) : (s.classList.add("active"), b == null || b.classList.add("active"), u.setAttribute("checked", "true"));
201
212
  continue;
202
213
  }
203
- b.hasAttribute("checked") && (A.classList.remove("active"), I == null || I.classList.remove("active"), b.removeAttribute("checked")), g++;
214
+ u.hasAttribute("checked") && (s.classList.remove("active"), b == null || b.classList.remove("active"), u.removeAttribute("checked")), c++;
204
215
  }
205
- }), g;
206
- }
207
- updateHTMLHorizontal(t) {
208
- let { group: e, key: i } = t, o = this._document.querySelectorAll(`${s.TABS}[${y}="${e}"] ${s.TAB}[${L}="${i}"]`), c = 0;
209
- return o.forEach((a) => {
210
- let l = a;
211
- if (!this.isValidTabElement(l) || l.dataset.diplodocIsActive === "true") return;
212
- c++;
213
- let n = a, g = n.parentNode, d = g == null ? void 0 : g.parentNode, B = Array.from((g == null ? void 0 : g.querySelectorAll(s.TAB)) || []), p = Array.from((d == null ? void 0 : d.children) || []).filter((A) => A.classList.contains(f)), C = B.indexOf(n);
214
- B.forEach((A, I) => {
215
- let b = p[I], m = I === C, H = A;
216
- H.dataset.diplodocIsActive = m ? "true" : "false", A.classList.toggle(G, m), A.setAttribute("aria-selected", m.toString()), A.setAttribute("tabindex", m ? "0" : "-1"), b.classList.toggle(G, m);
217
- });
218
216
  }), c;
219
217
  }
220
- resetScroll(t, e, i) {
221
- let o = F(t, e), c = o.top - i.top, a = o.left - i.left, l = o.scrollTop - i.scrollTop, n = o.scrollLeft - i.scrollLeft;
222
- e.scrollTo(e.scrollLeft + a - n, e.scrollTop + c - l);
218
+ updateHTMLRegular(t) {
219
+ let { group: e, key: g } = t, I = this._document.querySelectorAll(`${C.TABS}[${G}="${e}"] ${C.TAB}[${T}="${g}"]`), A = 0;
220
+ return I.forEach((l) => {
221
+ let o = l;
222
+ if (!this.isValidTabElement(o) || o.dataset.diplodocIsActive === "true") return;
223
+ A++;
224
+ let i = l, c = i.parentNode, n = c == null ? void 0 : c.parentNode, a = Array.from((c == null ? void 0 : c.querySelectorAll(C.TAB)) || []), r = Array.from((n == null ? void 0 : n.children) || []).filter((s) => s.classList.contains(O)), p = a.indexOf(i);
225
+ a.forEach((s, b) => {
226
+ let u = r[b], B = b === p, D = s;
227
+ D.dataset.diplodocIsActive = B ? "true" : "false", s.classList.toggle(m, B), s.setAttribute("aria-selected", B.toString()), s.setAttribute("tabindex", B ? "0" : "-1"), u.classList.toggle(m, B);
228
+ });
229
+ }), A;
230
+ }
231
+ updateHTMLDropdown(t) {
232
+ let { group: e, key: g } = t, I = this._document.querySelectorAll(`${C.TABS}[${G}="${e}"] ${C.TAB}[${T}="${g}"]`), A = 0;
233
+ return I.forEach((l) => {
234
+ let o = l.closest(`[${y}=dropdown]`);
235
+ if (!(o != null && o.children)) return;
236
+ let i = o.children.item(0), c = o.children.item(1);
237
+ i == null || i.classList.remove(m);
238
+ let n = Array.from((c == null ? void 0 : c.children) || []).indexOf(l) + 2;
239
+ for (let a = 2; a < o.children.length; a++) {
240
+ let r = o.children.item(a), p = c == null ? void 0 : c.children.item(a - 2);
241
+ if (A++, n === a) {
242
+ r == null || r.classList.add(m), i.innerHTML = l.innerHTML, p.style.fontWeight = "700";
243
+ continue;
244
+ }
245
+ p.style.fontWeight = "500", r == null || r.classList.remove(m);
246
+ }
247
+ }), A;
248
+ }
249
+ updateHTMLAccordion(t, e) {
250
+ let { group: g, key: I } = t, A = this._document.querySelectorAll(`${C.TABS}[${G}="${g}"] ${C.TAB}[${T}="${I}"]`), l = 0;
251
+ return A.forEach((o) => {
252
+ let i = o.closest(`[${y}=accordion]`);
253
+ if (i != null && i.children) for (let c = 0; c < i.children.length; c += 2) {
254
+ let n = i.children.item(c), a = i.children.item(c + 1);
255
+ if (l++, o === n) {
256
+ n == null || n.classList.toggle(m), a == null || a.classList.toggle(m);
257
+ continue;
258
+ }
259
+ n == null || n.classList.remove(m), a == null || a.classList.remove(m);
260
+ }
261
+ }), e && !this.checkVisible(e) && setTimeout(() => {
262
+ e.scrollIntoView({ block: "nearest" });
263
+ }), l;
264
+ }
265
+ checkVisible(t) {
266
+ let e = t.getBoundingClientRect(), g = Math.max(document.documentElement.clientHeight, window.innerHeight);
267
+ return !(e.bottom < 0 || e.top - g >= 0);
268
+ }
269
+ hideAllDropdown(t) {
270
+ this._document.querySelectorAll(".yfm-tabs-dropdown-select.active").forEach((g) => {
271
+ g.contains(t) || g.classList.remove(m);
272
+ });
273
+ }
274
+ resetScroll(t, e, g) {
275
+ let I = R(t, e), A = I.top - g.top, l = I.left - g.left, o = I.scrollTop - g.scrollTop, i = I.scrollLeft - g.scrollLeft;
276
+ e.scrollTo(e.scrollLeft + l - i, e.scrollTop + A - o);
223
277
  }
224
278
  didTabOpenForce(t) {
225
279
  if (!t) return {};
226
- let e = t.dataset.diplodocVerticalTab ? t : t.parentElement, i = typeof (e == null ? void 0 : e.dataset.diplodocRadioForced) != "undefined";
227
- return { root: e, isForced: i };
280
+ if (t.dataset.diplodocForced) return { root: t, isForced: true };
281
+ let e = t.dataset.diplodocVerticalTab ? t : t.parentElement, g = typeof (e == null ? void 0 : e.dataset.diplodocForced) != "undefined";
282
+ return { root: e, isForced: g };
228
283
  }
229
284
  fireSelectTabEvent(t, e) {
230
- let { group: i, key: o, align: c } = t, a = i.startsWith(v) ? { key: o, align: c } : t;
231
- this._onSelectTabHandlers.forEach((l) => {
232
- l({ tab: a, currentTabId: e });
285
+ let { group: g, key: I, variant: A } = t, l = g.startsWith(L) ? { key: I, variant: A } : t;
286
+ this._onSelectTabHandlers.forEach((o) => {
287
+ o({ tab: l, currentTabId: e });
233
288
  });
234
289
  }
290
+ getTabsType(t) {
291
+ let e = t.closest(`[${y}]`);
292
+ if (e) return e.dataset.diplodocVariant;
293
+ }
235
294
  isValidTabElement(t) {
236
- let e = t.matches(s.TAB) && t.dataset.diplodocId ? t.closest(s.TAB_LIST) : null;
237
- return e == null ? void 0 : e.closest(s.TABS);
295
+ return !!this.getTabsType(t);
238
296
  }
239
- areTabsVertical(t) {
240
- let e = t.parentElement;
241
- return t.dataset.diplodocVerticalTab || !!(e != null && e.dataset.diplodocVerticalTab);
297
+ isElementDropdownSelect(t) {
298
+ return t.classList.contains(U);
242
299
  }
243
300
  getTabDataFromHTMLElement(t) {
244
- var o, c;
245
- if (this.areTabsVertical(t)) {
246
- let a = t.dataset.diplodocVerticalTab ? t : t.parentElement, l = a.dataset.diplodocKey, n = (o = a.closest(s.TABS)) == null ? void 0 : o.dataset.diplodocGroup;
247
- return l && n ? { group: n, key: l, align: "radio" } : null;
301
+ var A, l, o;
302
+ let e = this.getTabsType(t);
303
+ if (e === "radio") {
304
+ let i = t.dataset.diplodocVerticalTab ? t : t.parentElement, c = i.dataset.diplodocKey, n = (A = i.closest(C.TABS)) == null ? void 0 : A.dataset.diplodocGroup;
305
+ return c && n ? { group: n, key: c, variant: "radio" } : null;
306
+ }
307
+ if (e === "dropdown" || e === "accordion") {
308
+ let i = t.dataset.diplodocKey, c = (l = t.closest(C.TABS)) == null ? void 0 : l.dataset.diplodocGroup;
309
+ return i && c ? { group: c, key: i, variant: e } : null;
248
310
  }
249
- let e = t.dataset.diplodocKey, i = (c = t.closest(s.TABS)) == null ? void 0 : c.dataset.diplodocGroup;
250
- return e && i ? { group: i, key: e, align: "horizontal" } : null;
311
+ let g = t.dataset.diplodocKey, I = (o = t.closest(C.TABS)) == null ? void 0 : o.dataset.diplodocGroup;
312
+ return g && I ? { group: I, key: g, variant: "regular" } : null;
251
313
  }
252
314
  getTabs(t) {
253
- var c, a;
254
- let e = (c = t.closest(s.TABS)) == null ? void 0 : c.dataset.diplodocGroup, i = (a = t.closest(s.TAB_LIST)) == null ? void 0 : a.querySelectorAll(s.TAB), o = [];
255
- return i.forEach((l) => {
256
- let n = l == null ? void 0 : l.dataset.diplodocKey;
257
- n && o.push({ group: e, key: n, align: "horizontal" });
258
- }), { tabs: o, nodes: i };
315
+ var A, l;
316
+ let e = (A = t.closest(C.TABS)) == null ? void 0 : A.dataset.diplodocGroup, g = (l = t.closest(C.TAB_LIST)) == null ? void 0 : l.querySelectorAll(C.TAB), I = [];
317
+ return g.forEach((o) => {
318
+ let i = o == null ? void 0 : o.dataset.diplodocKey;
319
+ i && I.push({ group: e, key: i, variant: "regular" });
320
+ }), { tabs: I, nodes: g };
259
321
  }
260
322
  };
261
- typeof window != "undefined" && typeof document != "undefined" && !window[x] && (window[x] = new T(document));
323
+ typeof window != "undefined" && typeof document != "undefined" && !window[h] && (window[h] = new x(document));
262
324
  })();
263
325
 
264
326
  // src/js/polyfill.js