@foxpixel/react 0.2.1 → 0.2.2

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/index.js CHANGED
@@ -435,6 +435,28 @@ var import_react8 = require("react");
435
435
  // src/hooks/useEditMode.ts
436
436
  var import_react6 = require("react");
437
437
  var SITE_CONTENT_QUERY_KEY = "siteContent";
438
+ var contentKeysOnPage = /* @__PURE__ */ new Set();
439
+ var flushTimer = null;
440
+ function scheduleFlushContentKeys() {
441
+ if (flushTimer) return;
442
+ flushTimer = setTimeout(() => {
443
+ flushTimer = null;
444
+ if (typeof window !== "undefined" && window.parent !== window) {
445
+ window.parent.postMessage(
446
+ { type: "FOXPIXEL_READY", payload: { contentKeys: Array.from(contentKeysOnPage) } },
447
+ "*"
448
+ );
449
+ }
450
+ }, 150);
451
+ }
452
+ function registerContentKey(key) {
453
+ contentKeysOnPage.add(key);
454
+ scheduleFlushContentKeys();
455
+ }
456
+ function unregisterContentKey(key) {
457
+ contentKeysOnPage.delete(key);
458
+ scheduleFlushContentKeys();
459
+ }
438
460
  function useEditMode() {
439
461
  const [isEditMode, setIsEditMode] = (0, import_react6.useState)(false);
440
462
  (0, import_react6.useEffect)(() => {
@@ -666,6 +688,12 @@ function Editable({
666
688
  defaultValue
667
689
  });
668
690
  const section = contentKey.includes(".") ? contentKey.split(".")[0] : void 0;
691
+ (0, import_react8.useEffect)(() => {
692
+ if (isEditMode) {
693
+ registerContentKey(contentKey);
694
+ return () => unregisterContentKey(contentKey);
695
+ }
696
+ }, [isEditMode, contentKey]);
669
697
  const handleClick = (0, import_react8.useCallback)(
670
698
  (e) => {
671
699
  if (isEditMode) {
@@ -761,6 +789,12 @@ function EditableHTML({
761
789
  defaultValue
762
790
  });
763
791
  const section = contentKey.includes(".") ? contentKey.split(".")[0] : void 0;
792
+ (0, import_react8.useEffect)(() => {
793
+ if (isEditMode) {
794
+ registerContentKey(contentKey);
795
+ return () => unregisterContentKey(contentKey);
796
+ }
797
+ }, [isEditMode, contentKey]);
764
798
  const handleClick = (0, import_react8.useCallback)(
765
799
  (e) => {
766
800
  if (isEditMode) {
@@ -827,6 +861,12 @@ function EditableImage({
827
861
  defaultValue
828
862
  });
829
863
  const section = contentKey.includes(".") ? contentKey.split(".")[0] : void 0;
864
+ (0, import_react8.useEffect)(() => {
865
+ if (isEditMode) {
866
+ registerContentKey(contentKey);
867
+ return () => unregisterContentKey(contentKey);
868
+ }
869
+ }, [isEditMode, contentKey]);
830
870
  const handleClick = (0, import_react8.useCallback)(
831
871
  (e) => {
832
872
  if (isEditMode) {