@diplodoc/transform 4.32.2 → 4.32.3

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 W = "yfm-tabs", R = "yfm-tab", O = "yfm-tab-panel", L = "yfm-tab-list", r = "active";
112
+ var T = "data-diplodoc-group", G = "data-diplodoc-key", x = "data-diplodoc-variant", v = "data-diplodoc-id", H = "defaultTabsGroup-";
113
+ var h = "data-diplodoc-forced";
114
+ var N = "yfm-tabs-dropdown-select";
115
+ var U = "yfm-tabs-vertical";
116
+ var F = Symbol.for("diplodocTabs");
117
+ var y = (s) => {
118
+ let t = s.composedPath();
119
+ return Array.isArray(t) && t.length > 0 ? t[0] : s.target;
120
+ }, Z = (s) => {
121
+ let t = y(s);
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
+ }, Q = (s) => Math.abs(s.scrollHeight - s.clientHeight) > 1 ? s : s.parentElement ? Q(s.parentElement) : void 0, X = (s, t) => {
124
+ let e = s.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 n = { TABS: `.${W}`, TAB_LIST: `.${L}`, TAB: `.${R}`, TAB_PANEL: `.${O}`, VERTICAL_TABS: `.${U}` }, f = 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 = y(e);
132
+ if (e.target && this.hideAllDropdown(e.target), Z(e)) return;
133
+ if (this.isElementDropdownSelect(g)) {
134
+ g.classList.toggle(r);
135
+ return;
136
+ }
137
+ if (!this.isValidTabElement(g)) return;
138
+ let o = this.getTabDataFromHTMLElement(g);
139
+ o && this._selectTab(o, 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 o = y(e);
162
+ if (Z(e) || !this.isValidTabElement(o)) return;
163
+ let { tabs: c, nodes: a } = this.getTabs(o), I = this.getTabDataFromHTMLElement(o), A = c.findIndex(({ key: C }) => (I == null ? void 0 : I.key) && C === I.key);
164
+ if (!I || c.length <= 1 || A === -1) return;
165
+ let i = (A + (g === "left" ? -1 : 1) + c.length) % c.length;
166
+ this.selectTab(c[i]), a[i].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(`${n.TAB}[${v}="${t}"]`);
176
+ if (!g || !this.isValidTabElement(g)) return;
177
+ let o = this.getTabDataFromHTMLElement(g);
178
+ o && this._selectTab(o, 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: o, variant: c } = t;
185
+ if (!g) return;
186
+ let a = e && Q(e), I = a && X(e, a);
187
+ this.updateHTML({ group: g, key: o, variant: c }, e, c) > 0 && (this.fireSelectTabEvent({ group: g, key: o, variant: c }, e == null ? void 0 : e.dataset.diplodocId), I && this.resetScroll(e, a, I));
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}`);
202
+ updateHTMLRadio(t, e) {
203
+ let { group: g, key: o } = t, { isForced: c, root: a } = this.didTabOpenForce(e), I = c ? `.yfm-vertical-tab[${h}="true"]` : "", A = this._document.querySelectorAll(`${n.TABS}[${T}="${g}"] ${n.TAB}[${G}="${o}"]${I}`);
193
204
  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"));
205
+ let i = 0;
206
+ return A.forEach((C) => {
207
+ let m = C.parentNode.children;
208
+ for (let p = 0; p < m.length; p += 2) {
209
+ let [d, b] = [m.item(p), m.item(p + 1)], u = d.children.item(0);
210
+ if (d === C) {
211
+ u.checked ? (d.classList.remove("active"), b == null || b.classList.remove("active"), u.removeAttribute("checked")) : (d.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") && (d.classList.remove("active"), b == null || b.classList.remove("active"), u.removeAttribute("checked")), i++;
204
215
  }
205
- }), g;
216
+ }), i;
206
217
  }
207
- updateHTMLHorizontal(t) {
208
- let { group: e, key: i } = t, o = this._document.querySelectorAll(`${s.TABS}[${y}="${e}"] ${s.TAB}[${L}="${i}"]`), c = 0;
218
+ updateHTMLRegular(t) {
219
+ let { group: e, key: g } = t, o = this._document.querySelectorAll(`${n.TABS}[${T}="${e}"] ${n.TAB}[${G}="${g}"]`), c = 0;
209
220
  return o.forEach((a) => {
210
- let l = a;
211
- if (!this.isValidTabElement(l) || l.dataset.diplodocIsActive === "true") return;
221
+ let I = a;
222
+ if (!this.isValidTabElement(I) || I.dataset.diplodocIsActive === "true") return;
212
223
  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);
224
+ let A = a, i = A.parentNode, C = i == null ? void 0 : i.parentNode, l = Array.from((i == null ? void 0 : i.querySelectorAll(n.TAB)) || []), m = Array.from((C == null ? void 0 : C.children) || []).filter((d) => d.classList.contains(O)), p = l.indexOf(A);
225
+ l.forEach((d, b) => {
226
+ let u = m[b], B = b === p, D = d;
227
+ D.dataset.diplodocIsActive = B ? "true" : "false", d.classList.toggle(r, B), d.setAttribute("aria-selected", B.toString()), d.setAttribute("tabindex", B ? "0" : "-1"), u.classList.toggle(r, B);
217
228
  });
218
229
  }), c;
219
230
  }
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);
231
+ updateHTMLDropdown(t) {
232
+ let { group: e, key: g } = t, o = this._document.querySelectorAll(`${n.TABS}[${T}="${e}"] ${n.TAB}[${G}="${g}"]`), c = 0;
233
+ return o.forEach((a) => {
234
+ let I = a.closest(`[${x}=dropdown]`);
235
+ if (!(I != null && I.children)) return;
236
+ let A = I.children.item(0), i = I.children.item(1);
237
+ A == null || A.classList.remove(r);
238
+ let C = Array.from((i == null ? void 0 : i.children) || []).indexOf(a) + 2;
239
+ for (let l = 2; l < I.children.length; l++) {
240
+ let m = I.children.item(l), p = i == null ? void 0 : i.children.item(l - 2);
241
+ if (c++, C === l) {
242
+ m == null || m.classList.add(r), p.classList.add(r), A.innerHTML = a.innerHTML, A.classList.add("filled");
243
+ continue;
244
+ }
245
+ p.classList.remove(r), m.classList.remove(r);
246
+ }
247
+ }), c;
248
+ }
249
+ updateHTMLAccordion(t, e) {
250
+ let { group: g, key: o } = t, c = this._document.querySelectorAll(`${n.TABS}[${T}="${g}"] ${n.TAB}[${G}="${o}"]`), a = 0;
251
+ return c.forEach((I) => {
252
+ let A = I.closest(`[${x}=accordion]`);
253
+ if (A != null && A.children) for (let i = 0; i < A.children.length; i += 2) {
254
+ let C = A.children.item(i), l = A.children.item(i + 1);
255
+ if (a++, I === C) {
256
+ C == null || C.classList.toggle(r), l == null || l.classList.toggle(r);
257
+ continue;
258
+ }
259
+ C == null || C.classList.remove(r), l == null || l.classList.remove(r);
260
+ }
261
+ }), e && !this.checkVisible(e) && setTimeout(() => {
262
+ e.scrollIntoView({ block: "nearest" });
263
+ }), a;
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(r);
272
+ });
273
+ }
274
+ resetScroll(t, e, g) {
275
+ let o = X(t, e), c = o.top - g.top, a = o.left - g.left, I = o.scrollTop - g.scrollTop, A = o.scrollLeft - g.scrollLeft;
276
+ e.scrollTo(e.scrollLeft + a - A, e.scrollTop + c - I);
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: o, variant: c } = t, a = g.startsWith(H) ? { key: o, variant: c } : t;
286
+ this._onSelectTabHandlers.forEach((I) => {
287
+ I({ tab: a, currentTabId: e });
233
288
  });
234
289
  }
290
+ getTabsType(t) {
291
+ let e = t.closest(`[${x}]`);
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(N);
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 c, a, I;
302
+ let e = this.getTabsType(t);
303
+ if (e === "radio") {
304
+ let A = t.dataset.diplodocVerticalTab ? t : t.parentElement, i = A.dataset.diplodocKey, C = (c = A.closest(n.TABS)) == null ? void 0 : c.dataset.diplodocGroup;
305
+ return i && C ? { group: C, key: i, variant: "radio" } : null;
306
+ }
307
+ if (e === "dropdown" || e === "accordion") {
308
+ let A = t.dataset.diplodocKey, i = (a = t.closest(n.TABS)) == null ? void 0 : a.dataset.diplodocGroup;
309
+ return A && i ? { group: i, key: A, 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, o = (I = t.closest(n.TABS)) == null ? void 0 : I.dataset.diplodocGroup;
312
+ return g && o ? { group: o, key: g, variant: "regular" } : null;
251
313
  }
252
314
  getTabs(t) {
253
315
  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 };
316
+ let e = (c = t.closest(n.TABS)) == null ? void 0 : c.dataset.diplodocGroup, g = (a = t.closest(n.TAB_LIST)) == null ? void 0 : a.querySelectorAll(n.TAB), o = [];
317
+ return g.forEach((I) => {
318
+ let A = I == null ? void 0 : I.dataset.diplodocKey;
319
+ A && o.push({ group: e, key: A, variant: "regular" });
320
+ }), { tabs: o, 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[F] && (window[F] = new f(document));
262
324
  })();
263
325
 
264
326
  // src/js/polyfill.js