@select-org/select-post-builder 1.1.47 → 1.1.48

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.
@@ -60536,7 +60536,7 @@ const PostBuilderEditor = ({
60536
60536
  clearOnSuccess: g,
60537
60537
  onGroupSelect: A
60538
60538
  }
60539
- ) : /* @__PURE__ */ jsxs("div", { className: "prose-blockquote: flex-1 flex flex-col space-y-3 max-w-full max-h-[calc(100dvh-7rem)]", children: [
60539
+ ) : /* @__PURE__ */ jsxs("div", { className: "prose-blockquote: flex-1 flex flex-col space-y-3 max-w-full max-h-[calc(100dvh-7rem)] bg-transparent", children: [
60540
60540
  !m && /* @__PURE__ */ jsx(GroupSelector, { user: p, store: J, onGroupSelect: A }),
60541
60541
  /* @__PURE__ */ jsx(
60542
60542
  PostBuilderEditorInstance,
@@ -60746,10 +60746,84 @@ const PostBuilderEditor = ({
60746
60746
  }), [d, S, m, E, g, y]);
60747
60747
  return /* @__PURE__ */ jsx(PostBuilderContext.Provider, { value: T, children: u });
60748
60748
  };
60749
+ function applyResolvedMediaItem(u, n, d) {
60750
+ return u && transformMediaNodes(u, (p) => {
60751
+ if (p.attrs?.uid !== n) return p;
60752
+ const m = d.sources?.original?.url ?? p.attrs.src;
60753
+ return {
60754
+ ...p,
60755
+ attrs: {
60756
+ ...p.attrs,
60757
+ src: m,
60758
+ uploading: !1,
60759
+ progress: 100,
60760
+ payload: d
60761
+ }
60762
+ };
60763
+ });
60764
+ }
60765
+ function stripPendingMediaFromJsonBody(u) {
60766
+ return u && pruneMediaNodes(u, isPendingMediaNode);
60767
+ }
60768
+ function isPendingMediaNode(u) {
60769
+ if (u.type !== "media") return !1;
60770
+ const n = u.attrs ?? {};
60771
+ return n.uploading === !0 || typeof n.src == "string" && n.src.startsWith("blob:");
60772
+ }
60773
+ function transformMediaNodes(u, n) {
60774
+ return u.type === "media" ? n(u) : u.content ? { ...u, content: u.content.map((d) => transformMediaNodes(d, n)) } : u;
60775
+ }
60776
+ function pruneMediaNodes(u, n) {
60777
+ return walkPrune(u, n) ?? u;
60778
+ }
60779
+ function walkPrune(u, n) {
60780
+ if (u.type === "media" && n(u)) return null;
60781
+ if (!u.content) return u;
60782
+ const d = [];
60783
+ for (const p of u.content) {
60784
+ const m = walkPrune(p, n);
60785
+ m !== null && d.push(m);
60786
+ }
60787
+ return u.type === "mediaGroup" && d.length === 0 ? null : { ...u, content: d };
60788
+ }
60789
+ function applyResolvedMediaItemToHtml(u, n, d) {
60790
+ if (!u) return u;
60791
+ const p = parseHtml(u), m = p.body.querySelector(
60792
+ `div[data-media][data-uid="${cssEscape(n)}"]`
60793
+ );
60794
+ if (!m) return u;
60795
+ const g = d.sources?.original?.url ?? m.getAttribute("data-src") ?? "";
60796
+ m.setAttribute("data-src", g), m.setAttribute("data-payload", JSON.stringify(d));
60797
+ const y = m.querySelector("img, video, audio");
60798
+ return y && y.setAttribute("src", g), p.body.innerHTML;
60799
+ }
60800
+ function stripPendingMediaFromHtml(u) {
60801
+ if (!u) return u;
60802
+ const n = parseHtml(u);
60803
+ return n.body.querySelectorAll("div[data-media]").forEach((d) => {
60804
+ isPendingMediaElement(d) && d.remove();
60805
+ }), n.body.querySelectorAll("div[data-media-group]").forEach((d) => {
60806
+ d.querySelector("div[data-media]") === null && d.remove();
60807
+ }), n.body.innerHTML;
60808
+ }
60809
+ function isPendingMediaElement(u) {
60810
+ const n = u.getAttribute("data-src") ?? "";
60811
+ return !n || n.startsWith("blob:") ? !0 : (u.querySelector("img, video, audio")?.getAttribute("src") ?? "").startsWith("blob:");
60812
+ }
60813
+ function parseHtml(u) {
60814
+ return new DOMParser().parseFromString(`<body>${u}</body>`, "text/html");
60815
+ }
60816
+ function cssEscape(u) {
60817
+ return u.replace(/(["\\])/g, "\\$1");
60818
+ }
60749
60819
  export {
60750
60820
  EditorPlacement,
60751
60821
  EditorTypes,
60752
60822
  PostBuilderEditor,
60753
60823
  PostBuilderEvents,
60754
- PostBuilderProvider
60824
+ PostBuilderProvider,
60825
+ applyResolvedMediaItem,
60826
+ applyResolvedMediaItemToHtml,
60827
+ stripPendingMediaFromHtml,
60828
+ stripPendingMediaFromJsonBody
60755
60829
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@select-org/select-post-builder",
3
- "version": "1.1.47",
3
+ "version": "1.1.48",
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",