PluginProbe
Extendify / 3.1.0
Extendify v3.1.0
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / QuickEdit / state / edit-mode.js

edit-mode.js in Extendify 3.1.0, at src/QuickEdit/state/edit-mode.js

39 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { isEmbedded } from '@shared/lib/embedded-guard';
2 import { create } from 'zustand';
3 import { persist } from 'zustand/middleware';
4 import { track } from '../lib/insights';
5
6 const HTML_CLASS = 'extendify-quick-edit-on';
7
8 const DEFAULT_ON = !!window.extQuickEditData?.defaultOn;
9
10 export const useEditModeStore = create()(
11 persist(
12 (set, get) => ({
13 on: DEFAULT_ON,
14 setOn: (on) => {
15 const next = !!on;
16 if (get().on === next) return;
17 set({ on: next });
18 },
19 toggle: () => set({ on: !get().on }),
20 }),
21 {
22 name: 'extendify-quick-edit-mode',
23 partialize: ({ on }) => ({ on }),
24 },
25 ),
26 );
27
28 // This chunk also ships in the Agent bundle, so guarding the class here keeps
29 // the page from ever looking edit-on inside another tool's iframe (Customizer
30 // preview, page-builder previews) regardless of which bundle loaded it.
31 const applyHtmlClass = (on) =>
32 document.documentElement.classList.toggle(HTML_CLASS, on && !isEmbedded());
33
34 useEditModeStore.subscribe((state) => {
35 applyHtmlClass(state.on);
36 track(state.on ? 'edit_mode_on' : 'edit_mode_off');
37 });
38 applyHtmlClass(useEditModeStore.getState().on);
39