PluginProbe
Extendify / 3.2.1
Extendify v3.2.1
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.2.1, at src/QuickEdit/state/edit-mode.js

42 lines 1.2 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 { track } from '@shared/lib/track';
3 import { create } from 'zustand';
4 import { persist } from 'zustand/middleware';
5
6 const HTML_CLASS = 'extendify-quick-edit-on';
7
8 const DEFAULT_ON = !!window.extQuickEditData?.defaultOn;
9
10 // One origin serves many sites over its life.
11 export const STORAGE_KEY = `extendify-quick-edit-mode-${window.extSharedData?.siteId}`;
12
13 export const useEditModeStore = create()(
14 persist(
15 (set, get) => ({
16 on: DEFAULT_ON,
17 setOn: (on) => {
18 const next = !!on;
19 if (get().on === next) return;
20 set({ on: next });
21 },
22 toggle: () => set({ on: !get().on }),
23 }),
24 {
25 name: STORAGE_KEY,
26 partialize: ({ on }) => ({ on }),
27 },
28 ),
29 );
30
31 // This chunk also ships in the Agent bundle, so guarding the class here keeps
32 // the page from ever looking edit-on inside another tool's iframe (Customizer
33 // preview, page-builder previews) regardless of which bundle loaded it.
34 const applyHtmlClass = (on) =>
35 document.documentElement.classList.toggle(HTML_CLASS, on && !isEmbedded());
36
37 useEditModeStore.subscribe((state) => {
38 applyHtmlClass(state.on);
39 track('quick_edit_status', { value: state.on ? 'on' : 'off' });
40 });
41 applyHtmlClass(useEditModeStore.getState().on);
42