PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.1
Elementor Website Builder – more than just a page builder v4.3.1
4.3.2 4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 All 455 releases
elementor / modules / atomic-widgets / elements / atomic-tabs / handlers / editor-tabs-state.js

editor-tabs-state.js in Elementor Website Builder – more than just a page builder 4.3.1, at modules/atomic-widgets/elements/atomic-tabs/handlers/editor-tabs-state.js

46 lines 1004 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Alpine } from '@elementor/alpinejs';
2 import { getTabId } from './utils';
3
4 /**
5 * @typedef {Record<string, number>} TabsState - Maps tabsId to the selected tab index.
6 */
7 const STORE_NAME = 'editor-atomic-tabs-state';
8
9 function ensureStore() {
10 if ( ! Alpine.store( STORE_NAME ) ) {
11 Alpine.store( STORE_NAME, /** @type {TabsState} */ ( {} ) );
12 }
13
14 return /** @type {TabsState} */ ( Alpine.store( STORE_NAME ) );
15 }
16
17 export function getActiveTabId( tabsId, fallback ) {
18 const store = ensureStore();
19 const storedIndex = store[ tabsId ];
20
21 if ( storedIndex === undefined ) {
22 return fallback;
23 }
24
25 return getTabId( tabsId, storedIndex );
26 }
27
28 export function setActiveTabIndex( tabsId, index ) {
29 const store = ensureStore();
30
31 store[ tabsId ] = index;
32 }
33
34 export function validateActiveTab( tabsId, tabCount ) {
35 const store = ensureStore();
36 const storedIndex = store[ tabsId ];
37
38 if ( storedIndex === undefined ) {
39 return;
40 }
41
42 if ( storedIndex >= tabCount ) {
43 delete store[ tabsId ];
44 }
45 }
46