@sevenfold/setto-client 0.3.3 → 0.3.4
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/guest-edit.d.ts +16 -0
- package/dist/index.d.ts +1 -0
- package/dist/setto-client.js +31 -2
- package/dist/setto-client.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
interface GuestEditContextValue {
|
|
3
|
+
active: boolean;
|
|
4
|
+
start: () => void;
|
|
5
|
+
stop: () => void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Lets visitors inline-edit copy on a marketing site (e.g. setto.no) without
|
|
9
|
+
* auth. Changes are session-only and never published. Real Setto edit mode
|
|
10
|
+
* always takes precedence.
|
|
11
|
+
*/
|
|
12
|
+
export declare function GuestEditProvider({ children }: {
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
export declare function useGuestEdit(): GuestEditContextValue;
|
|
16
|
+
export {};
|
package/dist/index.d.ts
CHANGED
package/dist/setto-client.js
CHANGED
|
@@ -22697,6 +22697,30 @@ function useSetto() {
|
|
|
22697
22697
|
}
|
|
22698
22698
|
return ctx;
|
|
22699
22699
|
}
|
|
22700
|
+
const GuestEditContext = createContext(null);
|
|
22701
|
+
function GuestEditProvider({ children }) {
|
|
22702
|
+
const { editMode } = useSetto();
|
|
22703
|
+
const [active, setActive] = useState(false);
|
|
22704
|
+
useEffect(() => {
|
|
22705
|
+
if (editMode && active) setActive(false);
|
|
22706
|
+
}, [editMode, active]);
|
|
22707
|
+
useEffect(() => {
|
|
22708
|
+
document.documentElement.classList.toggle("setto-guest-editing", active);
|
|
22709
|
+
return () => document.documentElement.classList.remove("setto-guest-editing");
|
|
22710
|
+
}, [active]);
|
|
22711
|
+
const start = useCallback(() => setActive(true), []);
|
|
22712
|
+
const stop = useCallback(() => setActive(false), []);
|
|
22713
|
+
return /* @__PURE__ */ jsx(GuestEditContext.Provider, { value: { active, start, stop }, children });
|
|
22714
|
+
}
|
|
22715
|
+
function useGuestEdit() {
|
|
22716
|
+
const ctx = useContext(GuestEditContext);
|
|
22717
|
+
if (!ctx) {
|
|
22718
|
+
return { active: false, start: () => {
|
|
22719
|
+
}, stop: () => {
|
|
22720
|
+
} };
|
|
22721
|
+
}
|
|
22722
|
+
return ctx;
|
|
22723
|
+
}
|
|
22700
22724
|
const MARGIN = 10;
|
|
22701
22725
|
const OFFSET = 8;
|
|
22702
22726
|
const MIN_TOUCH = 44;
|
|
@@ -22814,6 +22838,8 @@ function rangeFromPoint(doc, x, y) {
|
|
|
22814
22838
|
function T({ k }) {
|
|
22815
22839
|
const { t, i18n } = useTranslation();
|
|
22816
22840
|
const { editMode, store } = useSetto();
|
|
22841
|
+
const guestEdit = useGuestEdit();
|
|
22842
|
+
const editable = editMode || guestEdit.active;
|
|
22817
22843
|
const ref = useRef(null);
|
|
22818
22844
|
const [focused, setFocused] = useState(false);
|
|
22819
22845
|
const [linkContext, setLinkContext] = useState(false);
|
|
@@ -22829,7 +22855,7 @@ function T({ k }) {
|
|
|
22829
22855
|
if (!el || focused || !editMode) return;
|
|
22830
22856
|
if (el.textContent !== value) el.textContent = value;
|
|
22831
22857
|
}, [value, focused, editMode]);
|
|
22832
|
-
if (!
|
|
22858
|
+
if (!editable) return /* @__PURE__ */ jsx(Fragment, { children: value });
|
|
22833
22859
|
const handleMouseDown = (e) => {
|
|
22834
22860
|
e.stopPropagation();
|
|
22835
22861
|
const el = e.currentTarget;
|
|
@@ -22875,6 +22901,7 @@ function T({ k }) {
|
|
|
22875
22901
|
commit(e.currentTarget);
|
|
22876
22902
|
};
|
|
22877
22903
|
const handleInput = (e) => {
|
|
22904
|
+
if (!editMode) return;
|
|
22878
22905
|
store?.set(k, i18n.language, e.currentTarget.textContent ?? "");
|
|
22879
22906
|
};
|
|
22880
22907
|
const handlePaste = (e) => {
|
|
@@ -22915,7 +22942,7 @@ function T({ k }) {
|
|
|
22915
22942
|
style: {
|
|
22916
22943
|
cursor: "text",
|
|
22917
22944
|
color: "inherit",
|
|
22918
|
-
outline: focused ? "2px solid #640AFF" : void 0,
|
|
22945
|
+
outline: focused ? editMode ? "2px solid #640AFF" : "2px solid #C4502A" : void 0,
|
|
22919
22946
|
outlineOffset: 2,
|
|
22920
22947
|
borderRadius: 2,
|
|
22921
22948
|
transition: "outline-color 120ms"
|
|
@@ -24185,6 +24212,7 @@ function depDotStyle(status) {
|
|
|
24185
24212
|
}
|
|
24186
24213
|
export {
|
|
24187
24214
|
AuthGate,
|
|
24215
|
+
GuestEditProvider,
|
|
24188
24216
|
SettoAdminApp,
|
|
24189
24217
|
SettoBlock,
|
|
24190
24218
|
SettoIcon,
|
|
@@ -24193,6 +24221,7 @@ export {
|
|
|
24193
24221
|
SettoRepeater,
|
|
24194
24222
|
SettoSection,
|
|
24195
24223
|
T,
|
|
24224
|
+
useGuestEdit,
|
|
24196
24225
|
useSectionTheme,
|
|
24197
24226
|
useSetto
|
|
24198
24227
|
};
|