@select-org/select-post-builder 1.1.25 → 1.1.27

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.
@@ -23227,6 +23227,12 @@ const useHostAnalyticsBridge = () => {
23227
23227
  };
23228
23228
  }, [sessionId, editorType, placement, trackPublish, deleteSession, createSession]);
23229
23229
  };
23230
+ const generateDraftKey = (editorType, placement) => {
23231
+ if (placement) {
23232
+ return `${editorType}:${placement}-draft`;
23233
+ }
23234
+ return `${editorType}-draft`;
23235
+ };
23230
23236
  const extractTextContent = (json) => {
23231
23237
  if (!json) return "";
23232
23238
  let text2 = "";
@@ -23314,25 +23320,27 @@ const createPollContentFromNodes = (paragraphs, existingPollNode) => {
23314
23320
  content
23315
23321
  };
23316
23322
  };
23317
- const syncFromPostToOtherTabs = (postJson) => {
23323
+ const syncFromPostToOtherTabs = (postJson, placement) => {
23318
23324
  if (typeof window === "undefined" || typeof localStorage === "undefined") return;
23319
23325
  const postText = extractTextContent(postJson);
23320
23326
  if (!postText) {
23321
23327
  return;
23322
23328
  }
23323
- const blogDraftString = localStorage.getItem(`${EditorTypes.Blog}-draft`);
23329
+ const blogDraftKey = generateDraftKey(EditorTypes.Blog, placement);
23330
+ const blogDraftString = localStorage.getItem(blogDraftKey);
23324
23331
  if (!blogDraftString) {
23325
- localStorage.setItem(`${EditorTypes.Blog}-draft`, JSON.stringify(postJson));
23332
+ localStorage.setItem(blogDraftKey, JSON.stringify(postJson));
23326
23333
  }
23327
- const pollDraftString = localStorage.getItem(`${EditorTypes.Poll}-draft`);
23334
+ const pollDraftKey = generateDraftKey(EditorTypes.Poll, placement);
23335
+ const pollDraftString = localStorage.getItem(pollDraftKey);
23328
23336
  if (!pollDraftString) {
23329
23337
  let postParagraphs = extractParagraphNodes(postJson);
23330
23338
  postParagraphs = removeLinksForPollSync(postParagraphs);
23331
23339
  const pollContent = createPollContentFromNodes(postParagraphs);
23332
- localStorage.setItem(`${EditorTypes.Poll}-draft`, JSON.stringify(pollContent));
23340
+ localStorage.setItem(pollDraftKey, JSON.stringify(pollContent));
23333
23341
  }
23334
23342
  };
23335
- const usePersistence = () => {
23343
+ const usePersistence = (placement) => {
23336
23344
  const saveCurrentTabContent = (editorType, editor) => {
23337
23345
  if (typeof window === "undefined" || typeof localStorage === "undefined" || !editor) return;
23338
23346
  const hasContent = !!getTabContent(editorType);
@@ -23342,18 +23350,23 @@ const usePersistence = () => {
23342
23350
  const filteredJson = filterNodes(json, (node) => !node?.attrs?.uploading);
23343
23351
  if (editorType === EditorTypes.Poll && isPollEmpty(filteredJson)) return;
23344
23352
  if (!shouldSaveContent || !filteredJson) return;
23345
- localStorage.setItem(`${editorType}-draft`, JSON.stringify(filteredJson));
23353
+ const draftKey = generateDraftKey(editorType, placement);
23354
+ localStorage.setItem(draftKey, JSON.stringify(filteredJson));
23346
23355
  if (editorType === EditorTypes.Media) {
23347
- syncFromPostToOtherTabs(filteredJson);
23356
+ syncFromPostToOtherTabs(filteredJson, placement);
23348
23357
  }
23349
23358
  };
23350
23359
  const getTabContent = React.useCallback((editorType) => {
23351
- const jsonString = localStorage.getItem(`${editorType}-draft`);
23360
+ const draftKey = generateDraftKey(editorType, placement);
23361
+ const jsonString = localStorage.getItem(draftKey);
23352
23362
  return jsonString ? JSON.parse(jsonString) : null;
23353
- }, []);
23363
+ }, [placement]);
23354
23364
  const clearContent = () => {
23355
23365
  const editorTypes2 = enumToOptions(EditorTypes);
23356
- editorTypes2.forEach((type) => localStorage.removeItem(`${type.value}-draft`));
23366
+ editorTypes2.forEach((type) => {
23367
+ const draftKey = generateDraftKey(type.value, placement);
23368
+ localStorage.removeItem(draftKey);
23369
+ });
23357
23370
  };
23358
23371
  return { saveCurrentTabContent, getTabContent, clearContent };
23359
23372
  };
@@ -33477,12 +33490,12 @@ const initializePollEditor = (editor) => {
33477
33490
  return true;
33478
33491
  }).run();
33479
33492
  };
33480
- const usePostBuilderEditor = ({ editorType, groupId, postId, user }) => {
33493
+ const usePostBuilderEditor = ({ editorType, placement, groupId, postId, user }) => {
33481
33494
  const [, setForceRender] = React.useState(0);
33482
33495
  const [isMounted, setIsMounted] = React.useState(false);
33483
33496
  const api = useApi();
33484
33497
  const store = React.useMemo(() => createPostBuilderStore({ groupId, postId }), [groupId, postId]);
33485
- const { getTabContent, saveCurrentTabContent } = usePersistence();
33498
+ const { getTabContent, saveCurrentTabContent } = usePersistence(placement);
33486
33499
  React.useEffect(() => {
33487
33500
  setIsMounted(true);
33488
33501
  setForceRender((prev) => prev + 1);
@@ -33504,8 +33517,8 @@ const usePostBuilderEditor = ({ editorType, groupId, postId, user }) => {
33504
33517
  // Important: Only render after mount to avoid SSR issues
33505
33518
  shouldRerenderOnTransaction: false
33506
33519
  },
33507
- [editorType, isMounted]
33508
- // Add isMounted to dependencies
33520
+ [editorType, placement, isMounted]
33521
+ // Add isMounted and placement to dependencies
33509
33522
  );
33510
33523
  React.useEffect(() => {
33511
33524
  let timerId;
@@ -33517,7 +33530,7 @@ const usePostBuilderEditor = ({ editorType, groupId, postId, user }) => {
33517
33530
  return () => {
33518
33531
  if (timerId) clearTimeout(timerId);
33519
33532
  };
33520
- }, [editor, editorType, getTabContent, isMounted]);
33533
+ }, [editor, editorType, placement, getTabContent, isMounted]);
33521
33534
  const actions = React.useMemo(() => {
33522
33535
  return editor ? createEditorActions(editor) : null;
33523
33536
  }, [editor]);
@@ -33672,11 +33685,12 @@ const PostBuilderEditorInstance = ({
33672
33685
  clearOnSuccess,
33673
33686
  onCreatePost,
33674
33687
  className,
33675
- store
33688
+ store,
33689
+ placement
33676
33690
  }) => {
33677
33691
  const [isDragging, setIsDragging] = React.useState(false);
33678
33692
  const { trackPublish } = useAnalyticsTracking();
33679
- const { clearContent } = usePersistence();
33693
+ const { clearContent } = usePersistence(placement);
33680
33694
  useHostAnalyticsBridge();
33681
33695
  useEditorTracking({ editor, editorType: editorTab });
33682
33696
  const handleDragOver = (e2) => {
@@ -33738,11 +33752,12 @@ const PostBuilderEditorInstance = ({
33738
33752
  "div",
33739
33753
  {
33740
33754
  className: cn(
33741
- "post-builder-editor bg-background border rounded-md overflow-hidden min-h-60 max-h-full grow flex flex-col overflow-y-auto transition-all duration-300 ease-in-out",
33755
+ "post-builder-editor bg-background border rounded-md overflow-hidden max-h-full grow flex flex-col overflow-y-auto transition-all duration-300 ease-in-out",
33756
+ placement === EditorPlacement.Comment ? "min-h-32" : "min-h-60",
33742
33757
  className
33743
33758
  ),
33744
33759
  children: [
33745
- /* @__PURE__ */ jsxRuntime.jsx(EditorTypeTabs, { editorTab, onSwitchEditorTab: onSwitchEditor }),
33760
+ placement !== EditorPlacement.Comment && /* @__PURE__ */ jsxRuntime.jsx(EditorTypeTabs, { editorTab, onSwitchEditorTab: onSwitchEditor }),
33746
33761
  /* @__PURE__ */ jsxRuntime.jsx(
33747
33762
  Toolbar,
33748
33763
  {
@@ -33797,6 +33812,7 @@ const PostBuilderEditorInstanceWithDialog = ({
33797
33812
  open,
33798
33813
  onOpenChange,
33799
33814
  onGroupSelect,
33815
+ placement,
33800
33816
  ...rest
33801
33817
  }) => {
33802
33818
  const { trackAbandon } = useAnalyticsTracking();
@@ -33824,7 +33840,7 @@ const PostBuilderEditorInstanceWithDialog = ({
33824
33840
  /* @__PURE__ */ jsxRuntime.jsx(DialogClose, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "outline", size: "icon", children: /* @__PURE__ */ jsxRuntime.jsx(X, {}) }) })
33825
33841
  ] })
33826
33842
  ] }),
33827
- /* @__PURE__ */ jsxRuntime.jsx(PostBuilderEditorInstance, { ...rest, store })
33843
+ /* @__PURE__ */ jsxRuntime.jsx(PostBuilderEditorInstance, { ...rest, store, placement })
33828
33844
  ]
33829
33845
  }
33830
33846
  ) });
@@ -33903,6 +33919,7 @@ const PostBuilderEditor = ({
33903
33919
  const trackEditorFocus = useAnalyticsStore((s2) => s2.trackEditorFocus);
33904
33920
  const { editor, actions, store, isMounted } = usePostBuilderEditor({
33905
33921
  editorType: editorTab,
33922
+ placement,
33906
33923
  groupId,
33907
33924
  postId,
33908
33925
  user
@@ -33950,7 +33967,7 @@ const PostBuilderEditor = ({
33950
33967
  /* @__PURE__ */ jsxRuntime.jsx(react.EditorContext.Provider, { value: providerValue, children: openModal ? /* @__PURE__ */ jsxRuntime.jsx(
33951
33968
  PostBuilderEditorInstanceWithDialog,
33952
33969
  {
33953
- placement: EditorPlacement.Modal,
33970
+ placement,
33954
33971
  hideGroupSelector,
33955
33972
  user,
33956
33973
  editor,
@@ -33977,7 +33994,8 @@ const PostBuilderEditor = ({
33977
33994
  store,
33978
33995
  isSubmitting,
33979
33996
  onCreatePost,
33980
- clearOnSuccess
33997
+ clearOnSuccess,
33998
+ placement
33981
33999
  }
33982
34000
  )
33983
34001
  ] }) }),
@@ -1648,6 +1648,10 @@ body {
1648
1648
  min-height: calc(var(--spacing) * 16);
1649
1649
  }
1650
1650
 
1651
+ [data-theme="select-post-builder"] .min-h-32 {
1652
+ min-height: calc(var(--spacing) * 32);
1653
+ }
1654
+
1651
1655
  [data-theme="select-post-builder"] .min-h-44 {
1652
1656
  min-height: calc(var(--spacing) * 44);
1653
1657
  }
@@ -23197,6 +23197,12 @@ const useHostAnalyticsBridge = () => {
23197
23197
  };
23198
23198
  }, [sessionId, editorType, placement, trackPublish, deleteSession, createSession]);
23199
23199
  };
23200
+ const generateDraftKey = (editorType, placement) => {
23201
+ if (placement) {
23202
+ return `${editorType}:${placement}-draft`;
23203
+ }
23204
+ return `${editorType}-draft`;
23205
+ };
23200
23206
  const extractTextContent = (json) => {
23201
23207
  if (!json) return "";
23202
23208
  let text2 = "";
@@ -23284,25 +23290,27 @@ const createPollContentFromNodes = (paragraphs, existingPollNode) => {
23284
23290
  content
23285
23291
  };
23286
23292
  };
23287
- const syncFromPostToOtherTabs = (postJson) => {
23293
+ const syncFromPostToOtherTabs = (postJson, placement) => {
23288
23294
  if (typeof window === "undefined" || typeof localStorage === "undefined") return;
23289
23295
  const postText = extractTextContent(postJson);
23290
23296
  if (!postText) {
23291
23297
  return;
23292
23298
  }
23293
- const blogDraftString = localStorage.getItem(`${EditorTypes.Blog}-draft`);
23299
+ const blogDraftKey = generateDraftKey(EditorTypes.Blog, placement);
23300
+ const blogDraftString = localStorage.getItem(blogDraftKey);
23294
23301
  if (!blogDraftString) {
23295
- localStorage.setItem(`${EditorTypes.Blog}-draft`, JSON.stringify(postJson));
23302
+ localStorage.setItem(blogDraftKey, JSON.stringify(postJson));
23296
23303
  }
23297
- const pollDraftString = localStorage.getItem(`${EditorTypes.Poll}-draft`);
23304
+ const pollDraftKey = generateDraftKey(EditorTypes.Poll, placement);
23305
+ const pollDraftString = localStorage.getItem(pollDraftKey);
23298
23306
  if (!pollDraftString) {
23299
23307
  let postParagraphs = extractParagraphNodes(postJson);
23300
23308
  postParagraphs = removeLinksForPollSync(postParagraphs);
23301
23309
  const pollContent = createPollContentFromNodes(postParagraphs);
23302
- localStorage.setItem(`${EditorTypes.Poll}-draft`, JSON.stringify(pollContent));
23310
+ localStorage.setItem(pollDraftKey, JSON.stringify(pollContent));
23303
23311
  }
23304
23312
  };
23305
- const usePersistence = () => {
23313
+ const usePersistence = (placement) => {
23306
23314
  const saveCurrentTabContent = (editorType, editor) => {
23307
23315
  if (typeof window === "undefined" || typeof localStorage === "undefined" || !editor) return;
23308
23316
  const hasContent = !!getTabContent(editorType);
@@ -23312,18 +23320,23 @@ const usePersistence = () => {
23312
23320
  const filteredJson = filterNodes(json, (node) => !node?.attrs?.uploading);
23313
23321
  if (editorType === EditorTypes.Poll && isPollEmpty(filteredJson)) return;
23314
23322
  if (!shouldSaveContent || !filteredJson) return;
23315
- localStorage.setItem(`${editorType}-draft`, JSON.stringify(filteredJson));
23323
+ const draftKey = generateDraftKey(editorType, placement);
23324
+ localStorage.setItem(draftKey, JSON.stringify(filteredJson));
23316
23325
  if (editorType === EditorTypes.Media) {
23317
- syncFromPostToOtherTabs(filteredJson);
23326
+ syncFromPostToOtherTabs(filteredJson, placement);
23318
23327
  }
23319
23328
  };
23320
23329
  const getTabContent = useCallback((editorType) => {
23321
- const jsonString = localStorage.getItem(`${editorType}-draft`);
23330
+ const draftKey = generateDraftKey(editorType, placement);
23331
+ const jsonString = localStorage.getItem(draftKey);
23322
23332
  return jsonString ? JSON.parse(jsonString) : null;
23323
- }, []);
23333
+ }, [placement]);
23324
23334
  const clearContent = () => {
23325
23335
  const editorTypes2 = enumToOptions(EditorTypes);
23326
- editorTypes2.forEach((type) => localStorage.removeItem(`${type.value}-draft`));
23336
+ editorTypes2.forEach((type) => {
23337
+ const draftKey = generateDraftKey(type.value, placement);
23338
+ localStorage.removeItem(draftKey);
23339
+ });
23327
23340
  };
23328
23341
  return { saveCurrentTabContent, getTabContent, clearContent };
23329
23342
  };
@@ -33447,12 +33460,12 @@ const initializePollEditor = (editor) => {
33447
33460
  return true;
33448
33461
  }).run();
33449
33462
  };
33450
- const usePostBuilderEditor = ({ editorType, groupId, postId, user }) => {
33463
+ const usePostBuilderEditor = ({ editorType, placement, groupId, postId, user }) => {
33451
33464
  const [, setForceRender] = useState(0);
33452
33465
  const [isMounted, setIsMounted] = useState(false);
33453
33466
  const api = useApi();
33454
33467
  const store = useMemo(() => createPostBuilderStore({ groupId, postId }), [groupId, postId]);
33455
- const { getTabContent, saveCurrentTabContent } = usePersistence();
33468
+ const { getTabContent, saveCurrentTabContent } = usePersistence(placement);
33456
33469
  useEffect(() => {
33457
33470
  setIsMounted(true);
33458
33471
  setForceRender((prev) => prev + 1);
@@ -33474,8 +33487,8 @@ const usePostBuilderEditor = ({ editorType, groupId, postId, user }) => {
33474
33487
  // Important: Only render after mount to avoid SSR issues
33475
33488
  shouldRerenderOnTransaction: false
33476
33489
  },
33477
- [editorType, isMounted]
33478
- // Add isMounted to dependencies
33490
+ [editorType, placement, isMounted]
33491
+ // Add isMounted and placement to dependencies
33479
33492
  );
33480
33493
  useEffect(() => {
33481
33494
  let timerId;
@@ -33487,7 +33500,7 @@ const usePostBuilderEditor = ({ editorType, groupId, postId, user }) => {
33487
33500
  return () => {
33488
33501
  if (timerId) clearTimeout(timerId);
33489
33502
  };
33490
- }, [editor, editorType, getTabContent, isMounted]);
33503
+ }, [editor, editorType, placement, getTabContent, isMounted]);
33491
33504
  const actions = useMemo(() => {
33492
33505
  return editor ? createEditorActions(editor) : null;
33493
33506
  }, [editor]);
@@ -33642,11 +33655,12 @@ const PostBuilderEditorInstance = ({
33642
33655
  clearOnSuccess,
33643
33656
  onCreatePost,
33644
33657
  className,
33645
- store
33658
+ store,
33659
+ placement
33646
33660
  }) => {
33647
33661
  const [isDragging, setIsDragging] = useState(false);
33648
33662
  const { trackPublish } = useAnalyticsTracking();
33649
- const { clearContent } = usePersistence();
33663
+ const { clearContent } = usePersistence(placement);
33650
33664
  useHostAnalyticsBridge();
33651
33665
  useEditorTracking({ editor, editorType: editorTab });
33652
33666
  const handleDragOver = (e2) => {
@@ -33708,11 +33722,12 @@ const PostBuilderEditorInstance = ({
33708
33722
  "div",
33709
33723
  {
33710
33724
  className: cn(
33711
- "post-builder-editor bg-background border rounded-md overflow-hidden min-h-60 max-h-full grow flex flex-col overflow-y-auto transition-all duration-300 ease-in-out",
33725
+ "post-builder-editor bg-background border rounded-md overflow-hidden max-h-full grow flex flex-col overflow-y-auto transition-all duration-300 ease-in-out",
33726
+ placement === EditorPlacement.Comment ? "min-h-32" : "min-h-60",
33712
33727
  className
33713
33728
  ),
33714
33729
  children: [
33715
- /* @__PURE__ */ jsx(EditorTypeTabs, { editorTab, onSwitchEditorTab: onSwitchEditor }),
33730
+ placement !== EditorPlacement.Comment && /* @__PURE__ */ jsx(EditorTypeTabs, { editorTab, onSwitchEditorTab: onSwitchEditor }),
33716
33731
  /* @__PURE__ */ jsx(
33717
33732
  Toolbar,
33718
33733
  {
@@ -33767,6 +33782,7 @@ const PostBuilderEditorInstanceWithDialog = ({
33767
33782
  open,
33768
33783
  onOpenChange,
33769
33784
  onGroupSelect,
33785
+ placement,
33770
33786
  ...rest
33771
33787
  }) => {
33772
33788
  const { trackAbandon } = useAnalyticsTracking();
@@ -33794,7 +33810,7 @@ const PostBuilderEditorInstanceWithDialog = ({
33794
33810
  /* @__PURE__ */ jsx(DialogClose, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "outline", size: "icon", children: /* @__PURE__ */ jsx(X, {}) }) })
33795
33811
  ] })
33796
33812
  ] }),
33797
- /* @__PURE__ */ jsx(PostBuilderEditorInstance, { ...rest, store })
33813
+ /* @__PURE__ */ jsx(PostBuilderEditorInstance, { ...rest, store, placement })
33798
33814
  ]
33799
33815
  }
33800
33816
  ) });
@@ -33873,6 +33889,7 @@ const PostBuilderEditor = ({
33873
33889
  const trackEditorFocus = useAnalyticsStore((s2) => s2.trackEditorFocus);
33874
33890
  const { editor, actions, store, isMounted } = usePostBuilderEditor({
33875
33891
  editorType: editorTab,
33892
+ placement,
33876
33893
  groupId,
33877
33894
  postId,
33878
33895
  user
@@ -33920,7 +33937,7 @@ const PostBuilderEditor = ({
33920
33937
  /* @__PURE__ */ jsx(EditorContext.Provider, { value: providerValue, children: openModal ? /* @__PURE__ */ jsx(
33921
33938
  PostBuilderEditorInstanceWithDialog,
33922
33939
  {
33923
- placement: EditorPlacement.Modal,
33940
+ placement,
33924
33941
  hideGroupSelector,
33925
33942
  user,
33926
33943
  editor,
@@ -33947,7 +33964,8 @@ const PostBuilderEditor = ({
33947
33964
  store,
33948
33965
  isSubmitting,
33949
33966
  onCreatePost,
33950
- clearOnSuccess
33967
+ clearOnSuccess,
33968
+ placement
33951
33969
  }
33952
33970
  )
33953
33971
  ] }) }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@select-org/select-post-builder",
3
- "version": "1.1.25",
3
+ "version": "1.1.27",
4
4
  "description": "A reusable, extensible Post Builder widget for the Select platform and beyond.",
5
5
  "main": "./dist/post-builder.cjs.js",
6
6
  "module": "./dist/post-builder.js",