@yoamigo.com/core 0.4.7 → 0.4.8

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 (2) hide show
  1. package/dist/index.js +42 -11
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1124,7 +1124,7 @@ function ContentStoreProvider({
1124
1124
  const defaultContent = initialContent ?? getAllContent2();
1125
1125
  const defaultMode = initialMode ?? (isBuilderPreview() ? "inline-edit" : "read-only");
1126
1126
  const [content, setContent] = useState(
1127
- new Map(Object.entries(defaultContent))
1127
+ () => new Map(Object.entries(defaultContent))
1128
1128
  );
1129
1129
  const [mode, setModeState] = useState(defaultMode);
1130
1130
  const [listeners, setListeners] = useState(/* @__PURE__ */ new Set());
@@ -1264,21 +1264,49 @@ function ContentStoreProvider({
1264
1264
  document.removeEventListener("mousedown", handleClickOutside);
1265
1265
  };
1266
1266
  }, [activeFieldId]);
1267
+ const getValueRef = useRef(getValue);
1268
+ const setValueRef = useRef(setValue);
1269
+ const getChangeSourceRef = useRef(getChangeSource);
1270
+ const setModeRef = useRef(setMode);
1271
+ const subscribeRef = useRef(subscribe);
1272
+ const saveToWorkerRef = useRef(saveToWorker);
1273
+ const modeRef = useRef(mode);
1274
+ useEffect(() => {
1275
+ getValueRef.current = getValue;
1276
+ }, [getValue]);
1277
+ useEffect(() => {
1278
+ setValueRef.current = setValue;
1279
+ }, [setValue]);
1280
+ useEffect(() => {
1281
+ getChangeSourceRef.current = getChangeSource;
1282
+ }, [getChangeSource]);
1283
+ useEffect(() => {
1284
+ setModeRef.current = setMode;
1285
+ }, [setMode]);
1286
+ useEffect(() => {
1287
+ subscribeRef.current = subscribe;
1288
+ }, [subscribe]);
1289
+ useEffect(() => {
1290
+ saveToWorkerRef.current = saveToWorker;
1291
+ }, [saveToWorker]);
1292
+ useEffect(() => {
1293
+ modeRef.current = mode;
1294
+ }, [mode]);
1267
1295
  useEffect(() => {
1268
1296
  ;
1269
- window.mpContentStore = {
1270
- getValue,
1271
- setValue,
1272
- getChangeSource,
1273
- getMode: () => mode,
1274
- setMode,
1275
- subscribe,
1276
- saveToWorker
1297
+ window.yaContentStore = {
1298
+ getValue: (fieldId) => getValueRef.current(fieldId),
1299
+ setValue: (fieldId, value2, source) => setValueRef.current(fieldId, value2, source),
1300
+ getChangeSource: (fieldId) => getChangeSourceRef.current(fieldId),
1301
+ getMode: () => modeRef.current,
1302
+ setMode: (mode2) => setModeRef.current(mode2),
1303
+ subscribe: (listener) => subscribeRef.current(listener),
1304
+ saveToWorker: saveToWorkerRef.current ? (fieldId, value2) => saveToWorkerRef.current?.(fieldId, value2) : void 0
1277
1305
  };
1278
1306
  return () => {
1279
- delete window.mpContentStore;
1307
+ delete window.yaContentStore;
1280
1308
  };
1281
- }, [getValue, setValue, getChangeSource, mode, setMode, subscribe, saveToWorker]);
1309
+ }, []);
1282
1310
  const getPages = useCallback(() => pages, [pages]);
1283
1311
  const value = {
1284
1312
  getValue,
@@ -1902,6 +1930,9 @@ function useAIEditAnimation(fieldId, value, options) {
1902
1930
  if (!strategy.canAnimate(oldValue, newValue)) {
1903
1931
  setDisplayValue(newValue);
1904
1932
  previousValueRef.current = newValue;
1933
+ if (phase === "animating") {
1934
+ setPhase("idle");
1935
+ }
1905
1936
  return;
1906
1937
  }
1907
1938
  if (animationFrameRef.current !== null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yoamigo.com/core",
3
- "version": "0.4.7",
3
+ "version": "0.4.8",
4
4
  "description": "Core components, router, and utilities for YoAmigo templates",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",