@postrun/react 3.2.0 → 4.0.0

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.cjs CHANGED
@@ -92,7 +92,6 @@ __export(index_exports, {
92
92
  profileKeys: () => profileKeys,
93
93
  resolveVariantMedia: () => resolveVariantMedia,
94
94
  tiktokKeys: () => tiktokKeys,
95
- useAdTree: () => useAdTree,
96
95
  useCalendar: () => useCalendar,
97
96
  useConnect: () => useConnect,
98
97
  useConnection: () => useConnection,
@@ -1011,76 +1010,6 @@ function useTikTokCreatorInfo(connectionId) {
1011
1010
  queryClient
1012
1011
  );
1013
1012
  }
1014
- function useAdTree(params) {
1015
- const { connectionId, since, until, metrics, expanded = [] } = params;
1016
- const { client, queryClient } = usePostrun();
1017
- const enabled = Boolean(connectionId && since && until);
1018
- const path = { connection_id: connectionId };
1019
- const baseQuery = { since, until, metrics };
1020
- const campaign = reactQuery.useQuery(
1021
- {
1022
- ...query_star.googleGetAdTreeOptions({ client, path, query: baseQuery }),
1023
- enabled
1024
- },
1025
- queryClient
1026
- );
1027
- const combine = react.useCallback(
1028
- (results) => {
1029
- const nodes = results.flatMap((q) => q.data?.data ?? []);
1030
- const loadingById2 = new Map(
1031
- expanded.map((id, i) => [id, results[i]?.isLoading ?? false])
1032
- );
1033
- return { nodes, loadingById: loadingById2 };
1034
- },
1035
- // eslint-disable-next-line react-hooks/exhaustive-deps -- expanded is an array; join gives a stable string dep
1036
- // biome-ignore lint/correctness/useExhaustiveDependencies: intentional string-join dep for array stability
1037
- [expanded.join(",")]
1038
- );
1039
- const { nodes: subtreeNodes, loadingById } = reactQuery.useQueries(
1040
- {
1041
- queries: expanded.map((campaignId) => ({
1042
- ...query_star.googleGetAdTreeOptions({
1043
- client,
1044
- path,
1045
- query: { ...baseQuery, campaign_id: campaignId }
1046
- }),
1047
- enabled
1048
- })),
1049
- combine
1050
- },
1051
- queryClient
1052
- );
1053
- const tree = react.useMemo(
1054
- () => js.groupAdTree([...campaign.data?.data ?? [], ...subtreeNodes]),
1055
- [campaign.data, subtreeNodes]
1056
- );
1057
- const isExpanding = react.useCallback(
1058
- (campaignId) => loadingById.get(campaignId) ?? false,
1059
- [loadingById]
1060
- );
1061
- const refetch = react.useCallback(
1062
- (...args) => campaign.refetch(...args),
1063
- [campaign.refetch]
1064
- );
1065
- return react.useMemo(
1066
- () => ({
1067
- tree,
1068
- isLoading: campaign.isLoading,
1069
- isError: campaign.isError,
1070
- error: campaign.error,
1071
- isExpanding,
1072
- refetch
1073
- }),
1074
- [
1075
- tree,
1076
- campaign.isLoading,
1077
- campaign.isError,
1078
- campaign.error,
1079
- isExpanding,
1080
- refetch
1081
- ]
1082
- );
1083
- }
1084
1013
 
1085
1014
  // src/query.ts
1086
1015
  var query_exports = {};
@@ -2815,10 +2744,10 @@ var ShareIcon = (p) => /* @__PURE__ */ jsxRuntime.jsx(Icon, { viewBox: "0 0 20 2
2815
2744
  var PlusIcon = (p) => /* @__PURE__ */ jsxRuntime.jsx(Icon, { viewBox: "0 0 48 48", ...p, children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M26 7a1 1 0 0 0-1-1h-2a1 1 0 0 0-1 1v15H7a1 1 0 0 0-1 1v2a1 1 0 0 0 1 1h15v15a1 1 0 0 0 1 1h2a1 1 0 0 0 1-1V26h15a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1H26V7Z" }) });
2816
2745
  var DASH = "\u2011\u2011\u2011";
2817
2746
  function commercialLabel(settings) {
2818
- if (settings?.brand_content_toggle) {
2747
+ if (settings?.is_branded_content) {
2819
2748
  return "Paid partnership";
2820
2749
  }
2821
- if (settings?.brand_organic_toggle) {
2750
+ if (settings?.is_brand_organic) {
2822
2751
  return "Promotional content";
2823
2752
  }
2824
2753
  return null;
@@ -2838,7 +2767,7 @@ function TikTokPostPreviewImpl({
2838
2767
  const { creator } = creatorInfo;
2839
2768
  const handle = creator.username || creator.nickname;
2840
2769
  const label = commercialLabel(variant.settings);
2841
- const isAigc = Boolean(variant.settings?.is_aigc);
2770
+ const isAigc = Boolean(variant.settings?.is_ai_generated);
2842
2771
  const pending = resolved.length > 0 && readyMedia.length === 0;
2843
2772
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, style: { ...cardStyle4, ...style }, children: [
2844
2773
  /* @__PURE__ */ jsxRuntime.jsx("style", { children: KEYFRAMES }),
@@ -3116,7 +3045,8 @@ function Notice({ children }) {
3116
3045
  function CheckRow({
3117
3046
  label,
3118
3047
  checked,
3119
- onChange
3048
+ onChange,
3049
+ disabledReason
3120
3050
  }) {
3121
3051
  const id = react.useId();
3122
3052
  return /* @__PURE__ */ jsxRuntime.jsxs("label", { htmlFor: id, style: checkRowStyle, children: [
@@ -3126,11 +3056,13 @@ function CheckRow({
3126
3056
  id,
3127
3057
  type: "checkbox",
3128
3058
  checked,
3059
+ disabled: disabledReason !== void 0,
3129
3060
  onChange: (e) => onChange(e.target.checked),
3130
3061
  style: { accentColor: ACCENT, width: 16, height: 16 }
3131
3062
  }
3132
3063
  ),
3133
- /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontSize: 14 }, children: label })
3064
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontSize: 14 }, children: label }),
3065
+ disabledReason ? /* @__PURE__ */ jsxRuntime.jsx(Hint, { children: disabledReason }) : null
3134
3066
  ] });
3135
3067
  }
3136
3068
  var rowStyle3 = {
@@ -3187,8 +3119,10 @@ function AudienceSelect({
3187
3119
  value,
3188
3120
  onChange
3189
3121
  }) {
3190
- const options = js.audiencePrivacyOptions(creatorInfo.privacy_options, value);
3191
- const unselected = js.audienceUnselected(value);
3122
+ const choices = js.audiencePrivacyOptions(creatorInfo.privacy_options, value);
3123
+ const enabled = choices.flatMap((c) => c.disabled ? [] : [c.level]);
3124
+ const reason = choices.find((c) => c.disabled)?.disabledReason;
3125
+ const unselected = js.audienceUnselected(value, false);
3192
3126
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 8 }, children: [
3193
3127
  /* @__PURE__ */ jsxRuntime.jsx(SectionLabel, { children: "Who can view this post" }),
3194
3128
  /* @__PURE__ */ jsxRuntime.jsxs(
@@ -3198,17 +3132,27 @@ function AudienceSelect({
3198
3132
  value: value.privacy_level ?? "",
3199
3133
  onChange: (e) => onChange({
3200
3134
  ...value,
3201
- // Validate against the OFFERED (filtered) options, not the full set —
3202
- // so a manipulated value (e.g. SELF_ONLY while branded) can't slip in.
3203
- privacy_level: js.parsePrivacyLevel(e.target.value, options)
3135
+ // Validate against the ENABLED options so a manipulated value
3136
+ // (e.g. SELF_ONLY while branded) can't slip in.
3137
+ privacy_level: js.parsePrivacyLevel(e.target.value, enabled)
3204
3138
  }),
3205
3139
  style: selectStyle,
3206
3140
  children: [
3207
3141
  /* @__PURE__ */ jsxRuntime.jsx("option", { value: "", disabled: true, children: "Select who can view this post" }),
3208
- options.map((level) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: level, children: js.tiktokPrivacyLabel(level) }, level))
3142
+ choices.map((choice) => /* @__PURE__ */ jsxRuntime.jsx(
3143
+ "option",
3144
+ {
3145
+ value: choice.level,
3146
+ disabled: choice.disabled,
3147
+ title: choice.disabledReason,
3148
+ children: choice.label
3149
+ },
3150
+ choice.level
3151
+ ))
3209
3152
  ]
3210
3153
  }
3211
3154
  ),
3155
+ reason ? /* @__PURE__ */ jsxRuntime.jsx(Hint, { children: reason }) : null,
3212
3156
  unselected ? /* @__PURE__ */ jsxRuntime.jsx(Hint, { children: js.TIKTOK_AUDIENCE_REQUIRED_HINT }) : null
3213
3157
  ] });
3214
3158
  }
@@ -3307,10 +3251,12 @@ var textareaStyle = {
3307
3251
  };
3308
3252
  function CommercialDisclosure({
3309
3253
  value,
3310
- onChange
3254
+ onChange,
3255
+ isVideo
3311
3256
  }) {
3312
3257
  const labelNotice = js.commercialLabelNotice(value);
3313
3258
  const incomplete = js.commercialDisclosureIncomplete(value);
3259
+ const brandedLocked = isVideo ? void 0 : js.brandedContentDisabledReason(value);
3314
3260
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 8 }, children: [
3315
3261
  /* @__PURE__ */ jsxRuntime.jsx(SectionLabel, { children: "Disclose post content" }),
3316
3262
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -3342,6 +3288,7 @@ function CommercialDisclosure({
3342
3288
  {
3343
3289
  label: "Branded content",
3344
3290
  checked: value.branded_content,
3291
+ disabledReason: brandedLocked,
3345
3292
  onChange: (next) => onChange(js.setBrandKind(value, "branded_content", next))
3346
3293
  }
3347
3294
  ),
@@ -3431,7 +3378,7 @@ function TikTokPublishPanel({
3431
3378
  const isVideo = postType === "video";
3432
3379
  const captionOver = caption.length > js.captionMaxFor(postType);
3433
3380
  const mediaOk = mediaCountValid(postType, variant.media?.length ?? 0);
3434
- const ready = !captionOver && mediaOk && js.tiktokOptionsReady(options);
3381
+ const ready = !captionOver && mediaOk && js.tiktokOptionsReady(options, isVideo);
3435
3382
  return /* @__PURE__ */ jsxRuntime.jsxs(
3436
3383
  "div",
3437
3384
  {
@@ -3452,8 +3399,17 @@ function TikTokPublishPanel({
3452
3399
  postType
3453
3400
  }
3454
3401
  ),
3455
- /* @__PURE__ */ jsxRuntime.jsx(Divider, {}),
3456
- /* @__PURE__ */ jsxRuntime.jsx(AudienceSelect, { creatorInfo, value: options, onChange: onOptionsChange }),
3402
+ isVideo ? null : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3403
+ /* @__PURE__ */ jsxRuntime.jsx(Divider, {}),
3404
+ /* @__PURE__ */ jsxRuntime.jsx(
3405
+ AudienceSelect,
3406
+ {
3407
+ creatorInfo,
3408
+ value: options,
3409
+ onChange: onOptionsChange
3410
+ }
3411
+ )
3412
+ ] }),
3457
3413
  /* @__PURE__ */ jsxRuntime.jsx(Divider, {}),
3458
3414
  /* @__PURE__ */ jsxRuntime.jsx(
3459
3415
  InteractionToggles,
@@ -3465,7 +3421,14 @@ function TikTokPublishPanel({
3465
3421
  }
3466
3422
  ),
3467
3423
  /* @__PURE__ */ jsxRuntime.jsx(Divider, {}),
3468
- /* @__PURE__ */ jsxRuntime.jsx(CommercialDisclosure, { value: options, onChange: onOptionsChange }),
3424
+ /* @__PURE__ */ jsxRuntime.jsx(
3425
+ CommercialDisclosure,
3426
+ {
3427
+ value: options,
3428
+ onChange: onOptionsChange,
3429
+ isVideo
3430
+ }
3431
+ ),
3469
3432
  isVideo ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3470
3433
  /* @__PURE__ */ jsxRuntime.jsx(Divider, {}),
3471
3434
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -3476,9 +3439,9 @@ function TikTokPublishPanel({
3476
3439
  control: /* @__PURE__ */ jsxRuntime.jsx(
3477
3440
  Switch,
3478
3441
  {
3479
- checked: options.aigc,
3442
+ checked: options.ai_generated,
3480
3443
  ariaLabel: "AI-generated content",
3481
- onChange: (next) => onOptionsChange({ ...options, aigc: next })
3444
+ onChange: (next) => onOptionsChange({ ...options, ai_generated: next })
3482
3445
  }
3483
3446
  )
3484
3447
  }
@@ -3567,7 +3530,6 @@ exports.postKeys = postKeys;
3567
3530
  exports.profileKeys = profileKeys;
3568
3531
  exports.resolveVariantMedia = resolveVariantMedia;
3569
3532
  exports.tiktokKeys = tiktokKeys;
3570
- exports.useAdTree = useAdTree;
3571
3533
  exports.useCalendar = useCalendar;
3572
3534
  exports.useConnect = useConnect;
3573
3535
  exports.useConnection = useConnection;