@select-org/select-post-builder 1.1.26 → 1.1.28
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/post-builder.cjs.js +53 -34
- package/dist/post-builder.js +53 -34
- package/package.json +1 -1
package/dist/post-builder.cjs.js
CHANGED
|
@@ -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
|
|
23329
|
+
const blogDraftKey = generateDraftKey(EditorTypes.Blog, placement);
|
|
23330
|
+
const blogDraftString = localStorage.getItem(blogDraftKey);
|
|
23324
23331
|
if (!blogDraftString) {
|
|
23325
|
-
localStorage.setItem(
|
|
23332
|
+
localStorage.setItem(blogDraftKey, JSON.stringify(postJson));
|
|
23326
23333
|
}
|
|
23327
|
-
const
|
|
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(
|
|
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
|
-
|
|
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
|
|
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) =>
|
|
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]);
|
|
@@ -33677,7 +33690,7 @@ const PostBuilderEditorInstance = ({
|
|
|
33677
33690
|
}) => {
|
|
33678
33691
|
const [isDragging, setIsDragging] = React.useState(false);
|
|
33679
33692
|
const { trackPublish } = useAnalyticsTracking();
|
|
33680
|
-
const { clearContent } = usePersistence();
|
|
33693
|
+
const { clearContent } = usePersistence(placement);
|
|
33681
33694
|
useHostAnalyticsBridge();
|
|
33682
33695
|
useEditorTracking({ editor, editorType: editorTab });
|
|
33683
33696
|
const handleDragOver = (e2) => {
|
|
@@ -33814,23 +33827,28 @@ const PostBuilderEditorInstanceWithDialog = ({
|
|
|
33814
33827
|
hasUnsavedChanges: metrics?.hasUnsavedChanges ?? false
|
|
33815
33828
|
});
|
|
33816
33829
|
};
|
|
33817
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
33818
|
-
|
|
33819
|
-
|
|
33820
|
-
|
|
33821
|
-
|
|
33822
|
-
|
|
33823
|
-
|
|
33824
|
-
|
|
33825
|
-
|
|
33826
|
-
|
|
33827
|
-
|
|
33828
|
-
|
|
33829
|
-
|
|
33830
|
-
|
|
33831
|
-
|
|
33832
|
-
|
|
33833
|
-
|
|
33830
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Dialog, { modal: false, open, onOpenChange: handleOpenChange, children: [
|
|
33831
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "fixed inset-0 bg-black/50", onClick: () => handleOpenChange(false) }),
|
|
33832
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
33833
|
+
DialogContent,
|
|
33834
|
+
{
|
|
33835
|
+
onInteractOutside: (e2) => e2.preventDefault(),
|
|
33836
|
+
onOpenAutoFocus: (e2) => e2.preventDefault(),
|
|
33837
|
+
className: "bg-transparent shadow-none border-0 p-3 lg:max-w-4xl shrink-0 max-h-[calc(100dvh-7rem)]! flex flex-col overflow-y-auto -translate-1/2",
|
|
33838
|
+
showCloseButton: false,
|
|
33839
|
+
children: [
|
|
33840
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DialogHeader, { children: [
|
|
33841
|
+
/* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { className: "sr-only", children: "Post Builder Modal" }),
|
|
33842
|
+
!hideGroupSelector && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-3", children: [
|
|
33843
|
+
/* @__PURE__ */ jsxRuntime.jsx(GroupSelector, { user, store, onGroupSelect }),
|
|
33844
|
+
/* @__PURE__ */ jsxRuntime.jsx(DialogClose, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "outline", size: "icon", children: /* @__PURE__ */ jsxRuntime.jsx(X, {}) }) })
|
|
33845
|
+
] })
|
|
33846
|
+
] }),
|
|
33847
|
+
/* @__PURE__ */ jsxRuntime.jsx(PostBuilderEditorInstance, { ...rest, store, placement })
|
|
33848
|
+
]
|
|
33849
|
+
}
|
|
33850
|
+
)
|
|
33851
|
+
] });
|
|
33834
33852
|
};
|
|
33835
33853
|
var M = (e2, i2, s2, u, m, a2, l2, h) => {
|
|
33836
33854
|
let d = document.documentElement, w = ["light", "dark"];
|
|
@@ -33906,6 +33924,7 @@ const PostBuilderEditor = ({
|
|
|
33906
33924
|
const trackEditorFocus = useAnalyticsStore((s2) => s2.trackEditorFocus);
|
|
33907
33925
|
const { editor, actions, store, isMounted } = usePostBuilderEditor({
|
|
33908
33926
|
editorType: editorTab,
|
|
33927
|
+
placement,
|
|
33909
33928
|
groupId,
|
|
33910
33929
|
postId,
|
|
33911
33930
|
user
|
package/dist/post-builder.js
CHANGED
|
@@ -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
|
|
23299
|
+
const blogDraftKey = generateDraftKey(EditorTypes.Blog, placement);
|
|
23300
|
+
const blogDraftString = localStorage.getItem(blogDraftKey);
|
|
23294
23301
|
if (!blogDraftString) {
|
|
23295
|
-
localStorage.setItem(
|
|
23302
|
+
localStorage.setItem(blogDraftKey, JSON.stringify(postJson));
|
|
23296
23303
|
}
|
|
23297
|
-
const
|
|
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(
|
|
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
|
-
|
|
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
|
|
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) =>
|
|
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]);
|
|
@@ -33647,7 +33660,7 @@ const PostBuilderEditorInstance = ({
|
|
|
33647
33660
|
}) => {
|
|
33648
33661
|
const [isDragging, setIsDragging] = useState(false);
|
|
33649
33662
|
const { trackPublish } = useAnalyticsTracking();
|
|
33650
|
-
const { clearContent } = usePersistence();
|
|
33663
|
+
const { clearContent } = usePersistence(placement);
|
|
33651
33664
|
useHostAnalyticsBridge();
|
|
33652
33665
|
useEditorTracking({ editor, editorType: editorTab });
|
|
33653
33666
|
const handleDragOver = (e2) => {
|
|
@@ -33784,23 +33797,28 @@ const PostBuilderEditorInstanceWithDialog = ({
|
|
|
33784
33797
|
hasUnsavedChanges: metrics?.hasUnsavedChanges ?? false
|
|
33785
33798
|
});
|
|
33786
33799
|
};
|
|
33787
|
-
return /* @__PURE__ */
|
|
33788
|
-
|
|
33789
|
-
|
|
33790
|
-
|
|
33791
|
-
|
|
33792
|
-
|
|
33793
|
-
|
|
33794
|
-
|
|
33795
|
-
|
|
33796
|
-
|
|
33797
|
-
|
|
33798
|
-
|
|
33799
|
-
|
|
33800
|
-
|
|
33801
|
-
|
|
33802
|
-
|
|
33803
|
-
|
|
33800
|
+
return /* @__PURE__ */ jsxs(Dialog, { modal: false, open, onOpenChange: handleOpenChange, children: [
|
|
33801
|
+
/* @__PURE__ */ jsx("div", { className: "fixed inset-0 bg-black/50", onClick: () => handleOpenChange(false) }),
|
|
33802
|
+
/* @__PURE__ */ jsxs(
|
|
33803
|
+
DialogContent,
|
|
33804
|
+
{
|
|
33805
|
+
onInteractOutside: (e2) => e2.preventDefault(),
|
|
33806
|
+
onOpenAutoFocus: (e2) => e2.preventDefault(),
|
|
33807
|
+
className: "bg-transparent shadow-none border-0 p-3 lg:max-w-4xl shrink-0 max-h-[calc(100dvh-7rem)]! flex flex-col overflow-y-auto -translate-1/2",
|
|
33808
|
+
showCloseButton: false,
|
|
33809
|
+
children: [
|
|
33810
|
+
/* @__PURE__ */ jsxs(DialogHeader, { children: [
|
|
33811
|
+
/* @__PURE__ */ jsx(DialogTitle, { className: "sr-only", children: "Post Builder Modal" }),
|
|
33812
|
+
!hideGroupSelector && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3", children: [
|
|
33813
|
+
/* @__PURE__ */ jsx(GroupSelector, { user, store, onGroupSelect }),
|
|
33814
|
+
/* @__PURE__ */ jsx(DialogClose, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "outline", size: "icon", children: /* @__PURE__ */ jsx(X, {}) }) })
|
|
33815
|
+
] })
|
|
33816
|
+
] }),
|
|
33817
|
+
/* @__PURE__ */ jsx(PostBuilderEditorInstance, { ...rest, store, placement })
|
|
33818
|
+
]
|
|
33819
|
+
}
|
|
33820
|
+
)
|
|
33821
|
+
] });
|
|
33804
33822
|
};
|
|
33805
33823
|
var M = (e2, i2, s2, u, m, a2, l2, h) => {
|
|
33806
33824
|
let d = document.documentElement, w = ["light", "dark"];
|
|
@@ -33876,6 +33894,7 @@ const PostBuilderEditor = ({
|
|
|
33876
33894
|
const trackEditorFocus = useAnalyticsStore((s2) => s2.trackEditorFocus);
|
|
33877
33895
|
const { editor, actions, store, isMounted } = usePostBuilderEditor({
|
|
33878
33896
|
editorType: editorTab,
|
|
33897
|
+
placement,
|
|
33879
33898
|
groupId,
|
|
33880
33899
|
postId,
|
|
33881
33900
|
user
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@select-org/select-post-builder",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.28",
|
|
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",
|