@studiometa/ui 0.1.1 → 0.2.0

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.
Files changed (54) hide show
  1. package/README.md +37 -1
  2. package/atoms/Cursor/Cursor.cjs +129 -0
  3. package/{Cursor.d.ts → atoms/Cursor/Cursor.d.ts} +0 -0
  4. package/atoms/Cursor/Cursor.js +103 -0
  5. package/atoms/Figure/Figure.cjs +53 -0
  6. package/atoms/Figure/Figure.d.ts +31 -0
  7. package/atoms/Figure/Figure.js +27 -0
  8. package/atoms/index.cjs +38 -0
  9. package/atoms/index.d.ts +2 -0
  10. package/atoms/index.js +6 -0
  11. package/index.cjs +26 -0
  12. package/index.d.ts +3 -6
  13. package/index.js +3 -6
  14. package/molecules/Accordion/Accordion.cjs +65 -0
  15. package/{Accordion/index.d.ts → molecules/Accordion/Accordion.d.ts} +5 -6
  16. package/molecules/Accordion/Accordion.js +35 -0
  17. package/molecules/Accordion/AccordionCore.cjs +60 -0
  18. package/{Accordion/Accordion.d.ts → molecules/Accordion/AccordionCore.d.ts} +0 -0
  19. package/molecules/Accordion/AccordionCore.js +34 -0
  20. package/molecules/Accordion/AccordionItem.cjs +208 -0
  21. package/{Accordion → molecules/Accordion}/AccordionItem.d.ts +3 -3
  22. package/molecules/Accordion/AccordionItem.js +178 -0
  23. package/molecules/Modal/Modal.cjs +177 -0
  24. package/{Modal.d.ts → molecules/Modal/Modal.d.ts} +0 -0
  25. package/molecules/Modal/Modal.js +151 -0
  26. package/molecules/Sticky/Sticky.cjs +133 -0
  27. package/molecules/Sticky/Sticky.d.ts +141 -0
  28. package/molecules/Sticky/Sticky.js +107 -0
  29. package/molecules/Tabs/Tabs.cjs +152 -0
  30. package/{Tabs.d.ts → molecules/Tabs/Tabs.d.ts} +0 -0
  31. package/molecules/Tabs/Tabs.js +126 -0
  32. package/molecules/index.cjs +44 -0
  33. package/molecules/index.d.ts +5 -0
  34. package/molecules/index.js +12 -0
  35. package/organisms/index.cjs +23 -0
  36. package/organisms/index.d.ts +1 -0
  37. package/organisms/index.js +0 -0
  38. package/package.json +2 -2
  39. package/primitives/Draggable/Draggable.cjs +64 -0
  40. package/{Draggable.d.ts → primitives/Draggable/Draggable.d.ts} +0 -0
  41. package/primitives/Draggable/Draggable.js +38 -0
  42. package/primitives/Sentinel/Sentinel.cjs +41 -0
  43. package/primitives/Sentinel/Sentinel.d.ts +12 -0
  44. package/primitives/Sentinel/Sentinel.js +15 -0
  45. package/primitives/index.cjs +38 -0
  46. package/primitives/index.d.ts +2 -0
  47. package/primitives/index.js +6 -0
  48. package/Accordion/Accordion.js +0 -29
  49. package/Accordion/AccordionItem.js +0 -197
  50. package/Accordion/index.js +0 -12
  51. package/Cursor.js +0 -121
  52. package/Draggable.js +0 -31
  53. package/Modal.js +0 -167
  54. package/Tabs.js +0 -106
@@ -0,0 +1,151 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ var __async = (__this, __arguments, generator) => {
8
+ return new Promise((resolve, reject) => {
9
+ var fulfilled = (value) => {
10
+ try {
11
+ step(generator.next(value));
12
+ } catch (e) {
13
+ reject(e);
14
+ }
15
+ };
16
+ var rejected = (value) => {
17
+ try {
18
+ step(generator.throw(value));
19
+ } catch (e) {
20
+ reject(e);
21
+ }
22
+ };
23
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
24
+ step((generator = generator.apply(__this, __arguments)).next());
25
+ });
26
+ };
27
+ import { Base } from "@studiometa/js-toolkit";
28
+ import { transition, focusTrap } from "@studiometa/js-toolkit/utils";
29
+ const { trap, untrap, saveActiveElement } = focusTrap();
30
+ class Modal extends Base {
31
+ get onOpenClick() {
32
+ return this.open;
33
+ }
34
+ get onCloseClick() {
35
+ return this.close;
36
+ }
37
+ get onOverlayClick() {
38
+ return this.close;
39
+ }
40
+ mounted() {
41
+ this.isOpen = false;
42
+ this.close();
43
+ if (this.$options.move) {
44
+ const target = document.querySelector(this.$options.move) || document.body;
45
+ this.__refsBackup = this.$refs;
46
+ this.__refModalPlaceholder = document.createComment("");
47
+ this.__refModalParentBackup = this.$refs.modal.parentElement || this.$el;
48
+ this.__refModalParentBackup.insertBefore(this.__refModalPlaceholder, this.$refs.modal);
49
+ target.appendChild(this.$refs.modal);
50
+ }
51
+ return this;
52
+ }
53
+ get $refs() {
54
+ const $refs = super.$refs;
55
+ if (this.$options.move && this.__refsBackup) {
56
+ Object.entries(this.__refsBackup).forEach(([key, ref]) => {
57
+ if (!$refs[key]) {
58
+ $refs[key] = ref;
59
+ }
60
+ });
61
+ }
62
+ return $refs;
63
+ }
64
+ destroyed() {
65
+ this.close();
66
+ if (this.$options.move && this.__refModalParentBackup) {
67
+ this.__refModalParentBackup.insertBefore(this.$refs.modal, this.__refModalPlaceholder);
68
+ this.__refModalPlaceholder.remove();
69
+ delete this.__refModalPlaceholder;
70
+ delete this.__refModalParentBackup;
71
+ }
72
+ return this;
73
+ }
74
+ keyed({ event, isUp, isDown, ESC }) {
75
+ if (!this.isOpen) {
76
+ return;
77
+ }
78
+ if (isDown) {
79
+ trap(this.$refs.modal, event);
80
+ }
81
+ if (ESC && isUp) {
82
+ this.close();
83
+ }
84
+ }
85
+ open() {
86
+ return __async(this, null, function* () {
87
+ if (this.isOpen) {
88
+ return Promise.resolve(this);
89
+ }
90
+ this.$refs.modal.setAttribute("aria-hidden", "false");
91
+ document.documentElement.style.overflow = "hidden";
92
+ this.isOpen = true;
93
+ this.$emit("open");
94
+ const refs = this.$refs;
95
+ return Promise.all(Object.entries(this.$options.styles).map(([refName, { open, active, closed } = { open: "", active: "", closed: "" }]) => transition(refs[refName], {
96
+ from: closed,
97
+ active,
98
+ to: open
99
+ }, "keep"))).then(() => {
100
+ if (this.$options.autofocus && this.$refs.modal.querySelector(this.$options.autofocus)) {
101
+ saveActiveElement();
102
+ const autofocusElement = this.$refs.modal.querySelector(this.$options.autofocus);
103
+ autofocusElement.focus();
104
+ }
105
+ return Promise.resolve(this);
106
+ });
107
+ });
108
+ }
109
+ close() {
110
+ return __async(this, null, function* () {
111
+ if (!this.isOpen) {
112
+ return Promise.resolve(this);
113
+ }
114
+ this.$refs.modal.setAttribute("aria-hidden", "true");
115
+ document.documentElement.style.overflow = "";
116
+ this.isOpen = false;
117
+ untrap();
118
+ this.$emit("close");
119
+ const refs = this.$refs;
120
+ return Promise.all(Object.entries(this.$options.styles).map(([refName, { open, active, closed } = { open: "", active: "", closed: "" }]) => transition(refs[refName], {
121
+ from: open,
122
+ active,
123
+ to: closed
124
+ }, "keep"))).then(() => Promise.resolve(this));
125
+ });
126
+ }
127
+ }
128
+ __publicField(Modal, "config", {
129
+ name: "Modal",
130
+ refs: ["close", "container", "content", "modal", "open", "overlay"],
131
+ emits: ["open", "close"],
132
+ options: {
133
+ move: String,
134
+ autofocus: { type: String, default: "[autofocus]" },
135
+ styles: {
136
+ type: Object,
137
+ default: () => ({
138
+ modal: {
139
+ closed: {
140
+ opacity: "0",
141
+ pointerEvents: "none",
142
+ visibility: "hidden"
143
+ }
144
+ }
145
+ })
146
+ }
147
+ }
148
+ });
149
+ export {
150
+ Modal as default
151
+ };
@@ -0,0 +1,133 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __reExport = (target, module2, copyDefault, desc) => {
12
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
13
+ for (let key of __getOwnPropNames(module2))
14
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
15
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
16
+ }
17
+ return target;
18
+ };
19
+ var __toCommonJS = /* @__PURE__ */ ((cache) => {
20
+ return (module2, temp) => {
21
+ return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
22
+ };
23
+ })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
24
+ var __publicField = (obj, key, value) => {
25
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
26
+ return value;
27
+ };
28
+
29
+ // packages/ui/molecules/Sticky/Sticky.js
30
+ var Sticky_exports = {};
31
+ __export(Sticky_exports, {
32
+ default: () => Sticky
33
+ });
34
+ var import_js_toolkit = require("@studiometa/js-toolkit");
35
+ var import_primitives = require("../../primitives/index.cjs");
36
+ var _Sticky = class extends import_js_toolkit.Base {
37
+ constructor() {
38
+ super(...arguments);
39
+ __publicField(this, "isSticky", false);
40
+ __publicField(this, "isVisible", true);
41
+ }
42
+ set y(value) {
43
+ this.$refs.inner.style.transform = `translateY(${value}px) translateZ(0px)`;
44
+ }
45
+ get instances() {
46
+ return Array.from(_Sticky.instances);
47
+ }
48
+ mounted() {
49
+ _Sticky.instances.add(this);
50
+ this.setSentinelSize();
51
+ }
52
+ resized() {
53
+ this.setSentinelSize();
54
+ }
55
+ destroyed() {
56
+ _Sticky.instances.delete(this);
57
+ }
58
+ scrolled(props) {
59
+ if (!this.isSticky || props.y === props.last.y) {
60
+ return;
61
+ }
62
+ if (props.direction.y === "DOWN" && this.$options.hideWhenDown || props.direction.y === "UP" && this.$options.hideWhenUp) {
63
+ this.hide();
64
+ } else {
65
+ this.show();
66
+ }
67
+ }
68
+ onSentinelIntersected([entry]) {
69
+ this.isSticky = entry.isIntersecting && entry.boundingClientRect.y < 0;
70
+ this.setPosition();
71
+ }
72
+ hide() {
73
+ if (!this.isVisible) {
74
+ return;
75
+ }
76
+ this.isVisible = false;
77
+ this.$el.classList.add("pointer-events-none");
78
+ this.instances.forEach((instance, index) => instance.setPosition(index));
79
+ }
80
+ show() {
81
+ if (this.isVisible) {
82
+ return;
83
+ }
84
+ this.isVisible = true;
85
+ this.$el.classList.remove("pointer-events-none");
86
+ this.instances.forEach((instance, index) => instance.setPosition(index));
87
+ }
88
+ setSentinelSize() {
89
+ const { instances } = this;
90
+ const index = instances.findIndex((instance) => instance === this);
91
+ const height = instances.slice(0, index).filter((instance) => this.closestRelativeElement(instance.$el).contains(this.$el)).reduce((acc, instance) => acc + instance.$el.offsetHeight, 0);
92
+ this.$refs.sentinelRef.style.height = `${height + 1}px`;
93
+ this.$el.style.top = `${height}px`;
94
+ this.$el.style.zIndex = String(this.$options.zIndex - index);
95
+ }
96
+ setPosition(index) {
97
+ if (!this.isSticky) {
98
+ this.y = 0;
99
+ return;
100
+ }
101
+ const { instances } = this;
102
+ index = index != null ? index : instances.findIndex((instance) => instance === this);
103
+ this.y = instances.slice(0, index).filter((instance) => instance.isSticky && !instance.isVisible).reduce((y, instance) => {
104
+ return y - instance.$refs.inner.offsetHeight;
105
+ }, this.isVisible ? 0 : this.$refs.inner.offsetHeight * -1);
106
+ }
107
+ closestRelativeElement(element) {
108
+ let parent = element.parentElement;
109
+ while (getComputedStyle(parent).position !== "relative" && parent.parentElement) {
110
+ parent = parent.parentElement;
111
+ }
112
+ return parent;
113
+ }
114
+ };
115
+ var Sticky = _Sticky;
116
+ __publicField(Sticky, "config", {
117
+ name: "Sticky",
118
+ refs: ["inner", "sentinelRef"],
119
+ components: {
120
+ Sentinel: import_primitives.Sentinel
121
+ },
122
+ options: {
123
+ zIndex: {
124
+ type: Number,
125
+ default: 100
126
+ },
127
+ hideWhenUp: Boolean,
128
+ hideWhenDown: Boolean
129
+ }
130
+ });
131
+ __publicField(Sticky, "instances", /* @__PURE__ */ new Set());
132
+ module.exports = __toCommonJS(Sticky_exports);
133
+ if (module.exports.default) module.exports = module.exports.default;
@@ -0,0 +1,141 @@
1
+ /**
2
+ * @typedef {Object} StickyRefs
3
+ * @property {HTMLElement} inner
4
+ * @property {HTMLElement} sentinelRef
5
+ */
6
+ /**
7
+ * @typedef {Object} StickyPrivateInterface
8
+ * @property {StickyRefs} $refs
9
+ * @property {{ zIndex: number, hideWhenUp: boolean, hideWhenDown: boolean }} $options
10
+ * @property {{ Sentinel: Sentinel[] }} $children
11
+ */
12
+ /**
13
+ * @typedef {Sticky & StickyPrivateInterface} StickyInterface
14
+ */
15
+ /**
16
+ * Sticky class.
17
+ */
18
+ export default class Sticky extends Base {
19
+ /**
20
+ * Config.
21
+ */
22
+ static config: {
23
+ name: string;
24
+ refs: string[];
25
+ components: {
26
+ Sentinel: typeof Sentinel;
27
+ };
28
+ options: {
29
+ zIndex: {
30
+ type: NumberConstructor;
31
+ default: number;
32
+ };
33
+ hideWhenUp: BooleanConstructor;
34
+ hideWhenDown: BooleanConstructor;
35
+ };
36
+ };
37
+ /**
38
+ * Holder for all instances.
39
+ * @type {Set<StickyInterface>}
40
+ */
41
+ static instances: Set<StickyInterface>;
42
+ /**
43
+ * Is the component sticky?
44
+ * @type {boolean}
45
+ */
46
+ isSticky: boolean;
47
+ /**
48
+ * Is the component visible?
49
+ * @type {Boolean}
50
+ */
51
+ isVisible: boolean;
52
+ /**
53
+ * Set the Y value.
54
+ *
55
+ * @this {StickyInterface}
56
+ * @param {number} value
57
+ * @returns {void}
58
+ */
59
+ set y(arg: number);
60
+ /**
61
+ * Get instances as array.
62
+ * @return {Array<StickyInterface>}
63
+ */
64
+ get instances(): StickyInterface[];
65
+ /**
66
+ * Mounted hook.
67
+ * @this {StickyInterface}
68
+ */
69
+ mounted(): void;
70
+ /**
71
+ * Resized hook.
72
+ * @this {StickyInterface}
73
+ * @returns {void}
74
+ */
75
+ resized(): void;
76
+ /**
77
+ * Destroyed hook.
78
+ * @this {StickyInterface}
79
+ */
80
+ destroyed(): void;
81
+ /**
82
+ * Scrolled hook.
83
+ * @this {StickyInterface}
84
+ */
85
+ scrolled(props: any): void;
86
+ /**
87
+ * Listen to the sentinel's `intersected` event to set the `isSticky` value.
88
+ *
89
+ * @param {IntersectionObserverEntry[]} entries
90
+ * @returns {void}
91
+ */
92
+ onSentinelIntersected([entry]: IntersectionObserverEntry[]): void;
93
+ /**
94
+ * Hide the sticky component when another one is sticky.
95
+ * @this {StickyInterface}
96
+ */
97
+ hide(): void;
98
+ /**
99
+ * Show the sticky component when the other one is not sticky anymore.
100
+ * @this {StickyInterface}
101
+ */
102
+ show(): void;
103
+ /**
104
+ * Set the sentinel height based on the previous instances.
105
+ * @this {StickyInterface}
106
+ */
107
+ setSentinelSize(): void;
108
+ /**
109
+ * Set the component's position.
110
+ *
111
+ * @this {StickyInterface}
112
+ * @param {number} [index] The instance index in all the pages' instances.
113
+ * @returns {void}
114
+ */
115
+ setPosition(index?: number): void;
116
+ /**
117
+ * Find the first parent which has a relative position.
118
+ *
119
+ * @param {HTMLElement} element
120
+ * @returns {HTMLElement}
121
+ */
122
+ closestRelativeElement(element: HTMLElement): HTMLElement;
123
+ }
124
+ export type StickyRefs = {
125
+ inner: HTMLElement;
126
+ sentinelRef: HTMLElement;
127
+ };
128
+ export type StickyPrivateInterface = {
129
+ $refs: StickyRefs;
130
+ $options: {
131
+ zIndex: number;
132
+ hideWhenUp: boolean;
133
+ hideWhenDown: boolean;
134
+ };
135
+ $children: {
136
+ Sentinel: Sentinel[];
137
+ };
138
+ };
139
+ export type StickyInterface = Sticky & StickyPrivateInterface;
140
+ import { Base } from "@studiometa/js-toolkit";
141
+ import { Sentinel } from "../../primitives/index.js";
@@ -0,0 +1,107 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import { Base } from "@studiometa/js-toolkit";
8
+ import { Sentinel } from "../../primitives/index.js";
9
+ const _Sticky = class extends Base {
10
+ constructor() {
11
+ super(...arguments);
12
+ __publicField(this, "isSticky", false);
13
+ __publicField(this, "isVisible", true);
14
+ }
15
+ set y(value) {
16
+ this.$refs.inner.style.transform = `translateY(${value}px) translateZ(0px)`;
17
+ }
18
+ get instances() {
19
+ return Array.from(_Sticky.instances);
20
+ }
21
+ mounted() {
22
+ _Sticky.instances.add(this);
23
+ this.setSentinelSize();
24
+ }
25
+ resized() {
26
+ this.setSentinelSize();
27
+ }
28
+ destroyed() {
29
+ _Sticky.instances.delete(this);
30
+ }
31
+ scrolled(props) {
32
+ if (!this.isSticky || props.y === props.last.y) {
33
+ return;
34
+ }
35
+ if (props.direction.y === "DOWN" && this.$options.hideWhenDown || props.direction.y === "UP" && this.$options.hideWhenUp) {
36
+ this.hide();
37
+ } else {
38
+ this.show();
39
+ }
40
+ }
41
+ onSentinelIntersected([entry]) {
42
+ this.isSticky = entry.isIntersecting && entry.boundingClientRect.y < 0;
43
+ this.setPosition();
44
+ }
45
+ hide() {
46
+ if (!this.isVisible) {
47
+ return;
48
+ }
49
+ this.isVisible = false;
50
+ this.$el.classList.add("pointer-events-none");
51
+ this.instances.forEach((instance, index) => instance.setPosition(index));
52
+ }
53
+ show() {
54
+ if (this.isVisible) {
55
+ return;
56
+ }
57
+ this.isVisible = true;
58
+ this.$el.classList.remove("pointer-events-none");
59
+ this.instances.forEach((instance, index) => instance.setPosition(index));
60
+ }
61
+ setSentinelSize() {
62
+ const { instances } = this;
63
+ const index = instances.findIndex((instance) => instance === this);
64
+ const height = instances.slice(0, index).filter((instance) => this.closestRelativeElement(instance.$el).contains(this.$el)).reduce((acc, instance) => acc + instance.$el.offsetHeight, 0);
65
+ this.$refs.sentinelRef.style.height = `${height + 1}px`;
66
+ this.$el.style.top = `${height}px`;
67
+ this.$el.style.zIndex = String(this.$options.zIndex - index);
68
+ }
69
+ setPosition(index) {
70
+ if (!this.isSticky) {
71
+ this.y = 0;
72
+ return;
73
+ }
74
+ const { instances } = this;
75
+ index = index != null ? index : instances.findIndex((instance) => instance === this);
76
+ this.y = instances.slice(0, index).filter((instance) => instance.isSticky && !instance.isVisible).reduce((y, instance) => {
77
+ return y - instance.$refs.inner.offsetHeight;
78
+ }, this.isVisible ? 0 : this.$refs.inner.offsetHeight * -1);
79
+ }
80
+ closestRelativeElement(element) {
81
+ let parent = element.parentElement;
82
+ while (getComputedStyle(parent).position !== "relative" && parent.parentElement) {
83
+ parent = parent.parentElement;
84
+ }
85
+ return parent;
86
+ }
87
+ };
88
+ let Sticky = _Sticky;
89
+ __publicField(Sticky, "config", {
90
+ name: "Sticky",
91
+ refs: ["inner", "sentinelRef"],
92
+ components: {
93
+ Sentinel
94
+ },
95
+ options: {
96
+ zIndex: {
97
+ type: Number,
98
+ default: 100
99
+ },
100
+ hideWhenUp: Boolean,
101
+ hideWhenDown: Boolean
102
+ }
103
+ });
104
+ __publicField(Sticky, "instances", /* @__PURE__ */ new Set());
105
+ export {
106
+ Sticky as default
107
+ };
@@ -0,0 +1,152 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __reExport = (target, module2, copyDefault, desc) => {
12
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
13
+ for (let key of __getOwnPropNames(module2))
14
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
15
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
16
+ }
17
+ return target;
18
+ };
19
+ var __toCommonJS = /* @__PURE__ */ ((cache) => {
20
+ return (module2, temp) => {
21
+ return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
22
+ };
23
+ })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
24
+ var __publicField = (obj, key, value) => {
25
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
26
+ return value;
27
+ };
28
+ var __async = (__this, __arguments, generator) => {
29
+ return new Promise((resolve, reject) => {
30
+ var fulfilled = (value) => {
31
+ try {
32
+ step(generator.next(value));
33
+ } catch (e) {
34
+ reject(e);
35
+ }
36
+ };
37
+ var rejected = (value) => {
38
+ try {
39
+ step(generator.throw(value));
40
+ } catch (e) {
41
+ reject(e);
42
+ }
43
+ };
44
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
45
+ step((generator = generator.apply(__this, __arguments)).next());
46
+ });
47
+ };
48
+
49
+ // packages/ui/molecules/Tabs/Tabs.js
50
+ var Tabs_exports = {};
51
+ __export(Tabs_exports, {
52
+ default: () => Tabs
53
+ });
54
+ var import_js_toolkit = require("@studiometa/js-toolkit");
55
+ var import_utils = require("@studiometa/js-toolkit/utils");
56
+ var Tabs = class extends import_js_toolkit.Base {
57
+ mounted() {
58
+ this.items = this.$refs.btn.map((btn, index) => {
59
+ const id = `${this.$id}-${index}`;
60
+ const content = this.$refs.content[index];
61
+ btn.setAttribute("id", id);
62
+ content.setAttribute("aria-labelledby", id);
63
+ const item = { btn, content, isEnabled: index > 0 };
64
+ if (index > 0) {
65
+ this.disableItem(item);
66
+ } else {
67
+ this.enableItem(item);
68
+ }
69
+ return item;
70
+ });
71
+ }
72
+ onBtnClick(event, index) {
73
+ this.items.forEach((item, i) => {
74
+ if (i !== index) {
75
+ this.disableItem(item);
76
+ }
77
+ });
78
+ this.enableItem(this.items[index]);
79
+ }
80
+ enableItem(item) {
81
+ return __async(this, null, function* () {
82
+ if (!item || item.isEnabled) {
83
+ return Promise.resolve(this);
84
+ }
85
+ item.isEnabled = true;
86
+ const { btn, content } = item;
87
+ const btnStyles = this.$options.styles.btn || {};
88
+ const contentStyles = this.$options.styles.content || {};
89
+ content.setAttribute("aria-hidden", "false");
90
+ this.$emit("enable", item);
91
+ return Promise.all([
92
+ (0, import_utils.transition)(btn, {
93
+ from: btnStyles.closed,
94
+ active: btnStyles.active,
95
+ to: btnStyles.open
96
+ }, "keep"),
97
+ (0, import_utils.transition)(content, {
98
+ from: contentStyles.closed,
99
+ active: contentStyles.active,
100
+ to: contentStyles.open
101
+ }, "keep")
102
+ ]).then(() => Promise.resolve(this));
103
+ });
104
+ }
105
+ disableItem(item) {
106
+ return __async(this, null, function* () {
107
+ if (!item || !item.isEnabled) {
108
+ return Promise.resolve(this);
109
+ }
110
+ item.isEnabled = false;
111
+ const { btn, content } = item;
112
+ const btnStyles = this.$options.styles.btn || {};
113
+ const contentStyles = this.$options.styles.content || {};
114
+ content.setAttribute("aria-hidden", "true");
115
+ this.$emit("disable", item);
116
+ return Promise.all([
117
+ (0, import_utils.transition)(btn, {
118
+ from: btnStyles.open,
119
+ active: btnStyles.active,
120
+ to: btnStyles.closed
121
+ }, "keep"),
122
+ (0, import_utils.transition)(content, {
123
+ from: contentStyles.open,
124
+ active: contentStyles.active,
125
+ to: contentStyles.closed
126
+ }, "keep")
127
+ ]).then(() => Promise.resolve(this));
128
+ });
129
+ }
130
+ };
131
+ __publicField(Tabs, "config", {
132
+ name: "Tabs",
133
+ refs: ["btn[]", "content[]"],
134
+ emits: ["enable", "disable"],
135
+ options: {
136
+ styles: {
137
+ type: Object,
138
+ default: () => ({
139
+ content: {
140
+ closed: {
141
+ position: "absolute",
142
+ opacity: "0",
143
+ pointerEvents: "none",
144
+ visibility: "hidden"
145
+ }
146
+ }
147
+ })
148
+ }
149
+ }
150
+ });
151
+ module.exports = __toCommonJS(Tabs_exports);
152
+ if (module.exports.default) module.exports = module.exports.default;
File without changes