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

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.d.ts CHANGED
@@ -47,6 +47,7 @@ declare type BaseProps = {
47
47
  json: JSONContent;
48
48
  text: string;
49
49
  }) => void;
50
+ onGroupSelect?: (groupId: string) => void;
50
51
  };
51
52
 
52
53
  export declare enum EditorPlacement {
@@ -16351,7 +16351,7 @@ function AvatarFallback({ className, ...props }) {
16351
16351
  }
16352
16352
  );
16353
16353
  }
16354
- const GroupSelector = ({ store }) => {
16354
+ const GroupSelector = ({ store, onGroupSelect }) => {
16355
16355
  const { core: core2 } = useApi();
16356
16356
  const [groups, setGroups] = React.useState([]);
16357
16357
  const [isLoading, setIsLoading] = React.useState(false);
@@ -16388,6 +16388,7 @@ const GroupSelector = ({ store }) => {
16388
16388
  }, [core2]);
16389
16389
  const handleValueChange = (value) => {
16390
16390
  store.getState().selectGroup(value);
16391
+ onGroupSelect?.(value);
16391
16392
  };
16392
16393
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "not-prose flex items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs(Select, { value: currentValue, onValueChange: handleValueChange, disabled: isLoading, children: [
16393
16394
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -25671,8 +25672,23 @@ const PollCreator = ({ choices, onChange }) => {
25671
25672
  };
25672
25673
  const handleFileUpload = async (files) => {
25673
25674
  if (!files || !canAddMore) return;
25674
- const filesArray = files.slice(0, remainingSlots);
25675
+ let filesArray = files.slice(0, remainingSlots);
25675
25676
  const startIndex = internalChoices.length;
25677
+ filesArray = await Promise.all(
25678
+ filesArray.map(async (file) => {
25679
+ if (file.type.startsWith("image/")) {
25680
+ try {
25681
+ const compressed = await imageCompression(file, {
25682
+ maxSizeMB: 10
25683
+ });
25684
+ return compressed;
25685
+ } catch (error) {
25686
+ return file;
25687
+ }
25688
+ }
25689
+ return file;
25690
+ })
25691
+ );
25676
25692
  const placeholders = filesArray.map((_, i2) => ({
25677
25693
  type: "placeholder",
25678
25694
  key: `placeholder-${Date.now()}-${i2}`
@@ -32465,7 +32481,7 @@ const MentionList = React.forwardRef((props, ref) => {
32465
32481
  });
32466
32482
  MentionList.displayName = "MentionList";
32467
32483
  const isReactNativeWebView = () => typeof window !== "undefined" && window.ReactNativeWebView !== void 0;
32468
- const mentionService = (api, mfs, store) => {
32484
+ const mentionService = (api, mfs, store, user) => {
32469
32485
  const fetchMentions = async () => {
32470
32486
  const params = store.getState().getMentionParams();
32471
32487
  if (!params) {
@@ -32473,7 +32489,7 @@ const mentionService = (api, mfs, store) => {
32473
32489
  }
32474
32490
  const { groupId, postId } = params;
32475
32491
  const response = postId ? await mfs.getRecommendationPost(groupId, postId, 0, 999) : await mfs.getRecommendationGroup(groupId, 0, 999);
32476
- return response.entries?.filter((item) => Boolean(item?.user_data))?.map(
32492
+ const apiResults = response.entries?.filter((item) => Boolean(item?.user_data))?.map(
32477
32493
  (item) => ({
32478
32494
  id: item?.user_data?.id,
32479
32495
  label: item?.user_data?.name,
@@ -32484,7 +32500,22 @@ const mentionService = (api, mfs, store) => {
32484
32500
  type: MentionType.User,
32485
32501
  from: PostType.Post
32486
32502
  })
32487
- );
32503
+ ) ?? [];
32504
+ if (user) {
32505
+ const loggedInUserMention = {
32506
+ id: user.id,
32507
+ label: user.name,
32508
+ avatar: user.avatar,
32509
+ inThisThread: 1,
32510
+ name: user.name,
32511
+ selectId: user.username,
32512
+ type: MentionType.User,
32513
+ from: PostType.Post
32514
+ };
32515
+ const filteredResults = apiResults.filter((item) => item.id !== user.id);
32516
+ return [loggedInUserMention, ...filteredResults];
32517
+ }
32518
+ return apiResults;
32488
32519
  };
32489
32520
  const fetchHashtags = async () => {
32490
32521
  const { selectedGroupId, groupId } = store.getState();
@@ -32556,8 +32587,8 @@ function createSuggestion(char, fetchItems) {
32556
32587
  }
32557
32588
  };
32558
32589
  }
32559
- const configureMentionExtension = (api, mfs, store) => {
32560
- const service = mentionService(api, mfs, store);
32590
+ const configureMentionExtension = (api, mfs, store, user) => {
32591
+ const service = mentionService(api, mfs, store, user);
32561
32592
  return Mention.configure({
32562
32593
  HTMLAttributes: {
32563
32594
  class: "inline-block px-1.5 py-0.5 rounded font-medium no-underline cursor-pointer transition-all duration-200"
@@ -33298,7 +33329,7 @@ const getPlaceholderExtension = (placeholder) => extensions.Placeholder.configur
33298
33329
  // emptyEditorClass:
33299
33330
  // 'first:before:content-[attr(data-placeholder)] before:text-muted-foreground before:float-left before:h-0 before:pointer-events-none',
33300
33331
  });
33301
- const getMentionExtension = (core2, mfs, store) => configureMentionExtension(core2, mfs, store);
33332
+ const getMentionExtension = (core2, mfs, store, user) => configureMentionExtension(core2, mfs, store, user);
33302
33333
  const getExtensions = ({ editorType, api, store, user }) => {
33303
33334
  const extensionMap = {
33304
33335
  [EditorTypes.Blog]: getDefaultExtensions,
@@ -33330,12 +33361,12 @@ const getDefaultExtensions = ({ api, store, user }) => {
33330
33361
  api: core2
33331
33362
  }),
33332
33363
  LinkPreview,
33333
- getMentionExtension(core2, mfs, store),
33364
+ getMentionExtension(core2, mfs, store, user),
33334
33365
  SmartMediaUpload.configure({ api: fileStore }),
33335
33366
  SmartLinkPaste.configure({ api: core2 })
33336
33367
  ];
33337
33368
  };
33338
- const getPollExtensions = ({ api, store }) => {
33369
+ const getPollExtensions = ({ api, store, user }) => {
33339
33370
  const { core: core2, mfs } = api;
33340
33371
  return [
33341
33372
  PollDoc,
@@ -33346,7 +33377,7 @@ const getPollExtensions = ({ api, store }) => {
33346
33377
  getPlaceholderExtension("Ask a Question"),
33347
33378
  EnterHardBreak,
33348
33379
  Poll,
33349
- getMentionExtension(core2, mfs, store)
33380
+ getMentionExtension(core2, mfs, store, user)
33350
33381
  ];
33351
33382
  };
33352
33383
  const getMediaExtensions = ({ api, store, user }) => {
@@ -33374,7 +33405,7 @@ const getMediaExtensions = ({ api, store, user }) => {
33374
33405
  // selectable: false,
33375
33406
  draggable: false
33376
33407
  }),
33377
- getMentionExtension(core2, mfs, store),
33408
+ getMentionExtension(core2, mfs, store, user),
33378
33409
  SmartMediaUpload.configure({ api: fileStore }),
33379
33410
  SmartLinkPaste.configure({ api: core2, autoEmbed: false, autoLinkSelection: false })
33380
33411
  ];
@@ -33765,6 +33796,7 @@ const PostBuilderEditorInstanceWithDialog = ({
33765
33796
  hideGroupSelector,
33766
33797
  open,
33767
33798
  onOpenChange,
33799
+ onGroupSelect,
33768
33800
  ...rest
33769
33801
  }) => {
33770
33802
  const { trackAbandon } = useAnalyticsTracking();
@@ -33788,7 +33820,7 @@ const PostBuilderEditorInstanceWithDialog = ({
33788
33820
  /* @__PURE__ */ jsxRuntime.jsxs(DialogHeader, { children: [
33789
33821
  /* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { className: "sr-only", children: "Post Builder Modal" }),
33790
33822
  !hideGroupSelector && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-3", children: [
33791
- /* @__PURE__ */ jsxRuntime.jsx(GroupSelector, { user, store }),
33823
+ /* @__PURE__ */ jsxRuntime.jsx(GroupSelector, { user, store, onGroupSelect }),
33792
33824
  /* @__PURE__ */ jsxRuntime.jsx(DialogClose, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "outline", size: "icon", children: /* @__PURE__ */ jsxRuntime.jsx(X, {}) }) })
33793
33825
  ] })
33794
33826
  ] }),
@@ -33861,7 +33893,8 @@ const PostBuilderEditor = ({
33861
33893
  openModal,
33862
33894
  onModalOpenChange,
33863
33895
  isSubmitting,
33864
- onCreatePost
33896
+ onCreatePost,
33897
+ onGroupSelect
33865
33898
  }) => {
33866
33899
  const [editorTab, setEditorTab] = React.useState(EditorTypes.Media);
33867
33900
  const [sessionId, setSessionId] = React.useState("");
@@ -33929,10 +33962,11 @@ const PostBuilderEditor = ({
33929
33962
  onOpenChange: onModalOpenChange,
33930
33963
  onCreatePost,
33931
33964
  isSubmitting,
33932
- clearOnSuccess
33965
+ clearOnSuccess,
33966
+ onGroupSelect
33933
33967
  }
33934
33968
  ) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "prose-blockquote: flex-1 flex flex-col space-y-3 max-w-full max-h-[calc(100dvh-7rem)]", children: [
33935
- !hideGroupSelector && /* @__PURE__ */ jsxRuntime.jsx(GroupSelector, { user, store }),
33969
+ !hideGroupSelector && /* @__PURE__ */ jsxRuntime.jsx(GroupSelector, { user, store, onGroupSelect }),
33936
33970
  /* @__PURE__ */ jsxRuntime.jsx(
33937
33971
  PostBuilderEditorInstance,
33938
33972
  {
@@ -16321,7 +16321,7 @@ function AvatarFallback({ className, ...props }) {
16321
16321
  }
16322
16322
  );
16323
16323
  }
16324
- const GroupSelector = ({ store }) => {
16324
+ const GroupSelector = ({ store, onGroupSelect }) => {
16325
16325
  const { core } = useApi();
16326
16326
  const [groups, setGroups] = useState([]);
16327
16327
  const [isLoading, setIsLoading] = useState(false);
@@ -16358,6 +16358,7 @@ const GroupSelector = ({ store }) => {
16358
16358
  }, [core]);
16359
16359
  const handleValueChange = (value) => {
16360
16360
  store.getState().selectGroup(value);
16361
+ onGroupSelect?.(value);
16361
16362
  };
16362
16363
  return /* @__PURE__ */ jsx("div", { className: "not-prose flex items-center gap-3", children: /* @__PURE__ */ jsxs(Select, { value: currentValue, onValueChange: handleValueChange, disabled: isLoading, children: [
16363
16364
  /* @__PURE__ */ jsx(
@@ -25641,8 +25642,23 @@ const PollCreator = ({ choices, onChange }) => {
25641
25642
  };
25642
25643
  const handleFileUpload = async (files) => {
25643
25644
  if (!files || !canAddMore) return;
25644
- const filesArray = files.slice(0, remainingSlots);
25645
+ let filesArray = files.slice(0, remainingSlots);
25645
25646
  const startIndex = internalChoices.length;
25647
+ filesArray = await Promise.all(
25648
+ filesArray.map(async (file) => {
25649
+ if (file.type.startsWith("image/")) {
25650
+ try {
25651
+ const compressed = await imageCompression(file, {
25652
+ maxSizeMB: 10
25653
+ });
25654
+ return compressed;
25655
+ } catch (error) {
25656
+ return file;
25657
+ }
25658
+ }
25659
+ return file;
25660
+ })
25661
+ );
25646
25662
  const placeholders = filesArray.map((_, i2) => ({
25647
25663
  type: "placeholder",
25648
25664
  key: `placeholder-${Date.now()}-${i2}`
@@ -32435,7 +32451,7 @@ const MentionList = forwardRef((props, ref) => {
32435
32451
  });
32436
32452
  MentionList.displayName = "MentionList";
32437
32453
  const isReactNativeWebView = () => typeof window !== "undefined" && window.ReactNativeWebView !== void 0;
32438
- const mentionService = (api, mfs, store) => {
32454
+ const mentionService = (api, mfs, store, user) => {
32439
32455
  const fetchMentions = async () => {
32440
32456
  const params = store.getState().getMentionParams();
32441
32457
  if (!params) {
@@ -32443,7 +32459,7 @@ const mentionService = (api, mfs, store) => {
32443
32459
  }
32444
32460
  const { groupId, postId } = params;
32445
32461
  const response = postId ? await mfs.getRecommendationPost(groupId, postId, 0, 999) : await mfs.getRecommendationGroup(groupId, 0, 999);
32446
- return response.entries?.filter((item) => Boolean(item?.user_data))?.map(
32462
+ const apiResults = response.entries?.filter((item) => Boolean(item?.user_data))?.map(
32447
32463
  (item) => ({
32448
32464
  id: item?.user_data?.id,
32449
32465
  label: item?.user_data?.name,
@@ -32454,7 +32470,22 @@ const mentionService = (api, mfs, store) => {
32454
32470
  type: MentionType.User,
32455
32471
  from: PostType.Post
32456
32472
  })
32457
- );
32473
+ ) ?? [];
32474
+ if (user) {
32475
+ const loggedInUserMention = {
32476
+ id: user.id,
32477
+ label: user.name,
32478
+ avatar: user.avatar,
32479
+ inThisThread: 1,
32480
+ name: user.name,
32481
+ selectId: user.username,
32482
+ type: MentionType.User,
32483
+ from: PostType.Post
32484
+ };
32485
+ const filteredResults = apiResults.filter((item) => item.id !== user.id);
32486
+ return [loggedInUserMention, ...filteredResults];
32487
+ }
32488
+ return apiResults;
32458
32489
  };
32459
32490
  const fetchHashtags = async () => {
32460
32491
  const { selectedGroupId, groupId } = store.getState();
@@ -32526,8 +32557,8 @@ function createSuggestion(char, fetchItems) {
32526
32557
  }
32527
32558
  };
32528
32559
  }
32529
- const configureMentionExtension = (api, mfs, store) => {
32530
- const service = mentionService(api, mfs, store);
32560
+ const configureMentionExtension = (api, mfs, store, user) => {
32561
+ const service = mentionService(api, mfs, store, user);
32531
32562
  return Mention.configure({
32532
32563
  HTMLAttributes: {
32533
32564
  class: "inline-block px-1.5 py-0.5 rounded font-medium no-underline cursor-pointer transition-all duration-200"
@@ -33268,7 +33299,7 @@ const getPlaceholderExtension = (placeholder) => Placeholder.configure({
33268
33299
  // emptyEditorClass:
33269
33300
  // 'first:before:content-[attr(data-placeholder)] before:text-muted-foreground before:float-left before:h-0 before:pointer-events-none',
33270
33301
  });
33271
- const getMentionExtension = (core, mfs, store) => configureMentionExtension(core, mfs, store);
33302
+ const getMentionExtension = (core, mfs, store, user) => configureMentionExtension(core, mfs, store, user);
33272
33303
  const getExtensions = ({ editorType, api, store, user }) => {
33273
33304
  const extensionMap = {
33274
33305
  [EditorTypes.Blog]: getDefaultExtensions,
@@ -33300,12 +33331,12 @@ const getDefaultExtensions = ({ api, store, user }) => {
33300
33331
  api: core
33301
33332
  }),
33302
33333
  LinkPreview,
33303
- getMentionExtension(core, mfs, store),
33334
+ getMentionExtension(core, mfs, store, user),
33304
33335
  SmartMediaUpload.configure({ api: fileStore }),
33305
33336
  SmartLinkPaste.configure({ api: core })
33306
33337
  ];
33307
33338
  };
33308
- const getPollExtensions = ({ api, store }) => {
33339
+ const getPollExtensions = ({ api, store, user }) => {
33309
33340
  const { core, mfs } = api;
33310
33341
  return [
33311
33342
  PollDoc,
@@ -33316,7 +33347,7 @@ const getPollExtensions = ({ api, store }) => {
33316
33347
  getPlaceholderExtension("Ask a Question"),
33317
33348
  EnterHardBreak,
33318
33349
  Poll,
33319
- getMentionExtension(core, mfs, store)
33350
+ getMentionExtension(core, mfs, store, user)
33320
33351
  ];
33321
33352
  };
33322
33353
  const getMediaExtensions = ({ api, store, user }) => {
@@ -33344,7 +33375,7 @@ const getMediaExtensions = ({ api, store, user }) => {
33344
33375
  // selectable: false,
33345
33376
  draggable: false
33346
33377
  }),
33347
- getMentionExtension(core, mfs, store),
33378
+ getMentionExtension(core, mfs, store, user),
33348
33379
  SmartMediaUpload.configure({ api: fileStore }),
33349
33380
  SmartLinkPaste.configure({ api: core, autoEmbed: false, autoLinkSelection: false })
33350
33381
  ];
@@ -33735,6 +33766,7 @@ const PostBuilderEditorInstanceWithDialog = ({
33735
33766
  hideGroupSelector,
33736
33767
  open,
33737
33768
  onOpenChange,
33769
+ onGroupSelect,
33738
33770
  ...rest
33739
33771
  }) => {
33740
33772
  const { trackAbandon } = useAnalyticsTracking();
@@ -33758,7 +33790,7 @@ const PostBuilderEditorInstanceWithDialog = ({
33758
33790
  /* @__PURE__ */ jsxs(DialogHeader, { children: [
33759
33791
  /* @__PURE__ */ jsx(DialogTitle, { className: "sr-only", children: "Post Builder Modal" }),
33760
33792
  !hideGroupSelector && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3", children: [
33761
- /* @__PURE__ */ jsx(GroupSelector, { user, store }),
33793
+ /* @__PURE__ */ jsx(GroupSelector, { user, store, onGroupSelect }),
33762
33794
  /* @__PURE__ */ jsx(DialogClose, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "outline", size: "icon", children: /* @__PURE__ */ jsx(X, {}) }) })
33763
33795
  ] })
33764
33796
  ] }),
@@ -33831,7 +33863,8 @@ const PostBuilderEditor = ({
33831
33863
  openModal,
33832
33864
  onModalOpenChange,
33833
33865
  isSubmitting,
33834
- onCreatePost
33866
+ onCreatePost,
33867
+ onGroupSelect
33835
33868
  }) => {
33836
33869
  const [editorTab, setEditorTab] = useState(EditorTypes.Media);
33837
33870
  const [sessionId, setSessionId] = useState("");
@@ -33899,10 +33932,11 @@ const PostBuilderEditor = ({
33899
33932
  onOpenChange: onModalOpenChange,
33900
33933
  onCreatePost,
33901
33934
  isSubmitting,
33902
- clearOnSuccess
33935
+ clearOnSuccess,
33936
+ onGroupSelect
33903
33937
  }
33904
33938
  ) : /* @__PURE__ */ jsxs("div", { className: "prose-blockquote: flex-1 flex flex-col space-y-3 max-w-full max-h-[calc(100dvh-7rem)]", children: [
33905
- !hideGroupSelector && /* @__PURE__ */ jsx(GroupSelector, { user, store }),
33939
+ !hideGroupSelector && /* @__PURE__ */ jsx(GroupSelector, { user, store, onGroupSelect }),
33906
33940
  /* @__PURE__ */ jsx(
33907
33941
  PostBuilderEditorInstance,
33908
33942
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@select-org/select-post-builder",
3
- "version": "1.1.24",
3
+ "version": "1.1.25",
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",