@schematichq/schematic-components 2.36.1 → 2.38.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.
@@ -124,7 +124,8 @@ var PaymentMethodForm_exports = {};
124
124
  __export(PaymentMethodForm_exports, {
125
125
  PaymentMethodForm: () => PaymentMethodForm,
126
126
  default: () => PaymentMethodForm_default,
127
- resolveAppearance: () => resolveAppearance
127
+ resolveAppearance: () => resolveAppearance,
128
+ resolved: () => resolved
128
129
  });
129
130
  import { useSetupIntent } from "@schematichq/schematic-react";
130
131
  import { useEffect as useEffect2, useId as useId2, useRef as useRef2, useState } from "react";
@@ -1868,7 +1869,7 @@ function prorationBlock(detail, input) {
1868
1869
  return {
1869
1870
  key: `${line.kind}:${line.planId ?? line.priceId ?? ""}:${index}`,
1870
1871
  kind: line.kind,
1871
- name: catalogName(catalog, line.planId) ?? catalogPriceName(catalog, line.priceId) ?? (line.planId != null && current !== void 0 && current.id === line.planId ? current.name : null),
1872
+ name: catalogName(catalog, line.planId) ?? catalogPriceName(catalog, line.priceId) ?? (line.planId != null && current != null && current.id === line.planId ? current.name : null),
1872
1873
  periodText: start !== void 0 && end !== void 0 ? formatShortDateRange(start, end, locale) : null,
1873
1874
  amountText: money(line.amount)
1874
1875
  };
@@ -1885,7 +1886,7 @@ function prorationBlock(detail, input) {
1885
1886
  }
1886
1887
  function customPlanOf(catalog) {
1887
1888
  const cta = catalog.customPlanCta;
1888
- if (cta === void 0) {
1889
+ if (cta == null) {
1889
1890
  return null;
1890
1891
  }
1891
1892
  const custom = {
@@ -2091,7 +2092,7 @@ function deriveCheckout(input) {
2091
2092
  enabled: choice.enabled ?? topup.companyEnabled ?? topup.enabled,
2092
2093
  thresholdCredits: choice.thresholdCredits ?? topup.companyThresholdCredits ?? topup.thresholdCredits ?? null,
2093
2094
  amount,
2094
- costText: amount === null || unit === void 0 ? null : priceText(unit, locale, amount)
2095
+ costText: amount === null || unit == null ? null : priceText(unit, locale, amount)
2095
2096
  };
2096
2097
  }),
2097
2098
  lines,
@@ -2237,7 +2238,7 @@ function isEnglish2(locale) {
2237
2238
 
2238
2239
  // src/elements/model/featureUsage.ts
2239
2240
  function pricePeriod(price) {
2240
- if (price === void 0) {
2241
+ if (price == null) {
2241
2242
  return null;
2242
2243
  }
2243
2244
  if (price.interval === "month" && price.intervalCount === 3) {
@@ -2246,7 +2247,7 @@ function pricePeriod(price) {
2246
2247
  return price.interval;
2247
2248
  }
2248
2249
  function isTieredPrice(price) {
2249
- return price !== void 0 && (price.priceTiers.length > 1 || price.tiersMode !== void 0 && price.tiersMode !== null);
2250
+ return price != null && (price.priceTiers.length > 1 || price.tiersMode !== void 0 && price.tiersMode !== null);
2250
2251
  }
2251
2252
  function unitPrice(price) {
2252
2253
  return decimalOr(price.priceDecimal, price.price);
@@ -2351,7 +2352,7 @@ function includedFeatureRow(row, options) {
2351
2352
  amount: formatNumber(row.allocation, locale),
2352
2353
  units: featureName(feature, row.allocation, locale)
2353
2354
  } : null,
2354
- tiers: (row.priceBehavior === "tier" || tiered) && row.price !== void 0 ? {
2355
+ tiers: (row.priceBehavior === "tier" || tiered) && row.price != null ? {
2355
2356
  ranges: tierRanges(row.price),
2356
2357
  currency: row.price.currency,
2357
2358
  mode: row.price.tiersMode ?? null,
@@ -2381,7 +2382,7 @@ function entitlementText(row, options) {
2381
2382
  case "pay_in_advance":
2382
2383
  return typeof row.allocation === "number" ? { kind: "units", ...units(row.allocation) } : null;
2383
2384
  case "pay_as_you_go": {
2384
- if (row.price === void 0) {
2385
+ if (row.price == null) {
2385
2386
  return null;
2386
2387
  }
2387
2388
  const cost = formatCurrency(
@@ -2449,7 +2450,7 @@ function usageSegments(row, locale, tiered, period) {
2449
2450
  pluralName: row.featurePluralName
2450
2451
  };
2451
2452
  const segments = [];
2452
- if (row.priceBehavior === "pay_in_advance" && !tiered && period !== null && row.price !== void 0) {
2453
+ if (row.priceBehavior === "pay_in_advance" && !tiered && period !== null && row.price != null) {
2453
2454
  const size = row.price.packageSize;
2454
2455
  segments.push({
2455
2456
  kind: "unitPricePerPeriod",
@@ -2465,7 +2466,7 @@ function usageSegments(row, locale, tiered, period) {
2465
2466
  units: featureName(feature, row.usage, locale)
2466
2467
  });
2467
2468
  }
2468
- if (typeof row.currentCost === "number" && row.currentCost > 0 && row.price !== void 0) {
2469
+ if (typeof row.currentCost === "number" && row.currentCost > 0 && row.price != null) {
2469
2470
  segments.push({
2470
2471
  kind: "cost",
2471
2472
  cost: formatCurrency(row.currentCost, row.price.currency, locale),
@@ -2589,7 +2590,7 @@ function limitLine(row, limit, unit, options) {
2589
2590
  }
2590
2591
  break;
2591
2592
  case "pay_as_you_go":
2592
- if (typeof row.currentCost === "number" && row.price !== void 0) {
2593
+ if (typeof row.currentCost === "number" && row.price != null) {
2593
2594
  return {
2594
2595
  kind: "cost",
2595
2596
  cost: formatCurrency(row.currentCost, row.price.currency, locale)
@@ -2643,7 +2644,7 @@ function meter(row, options) {
2643
2644
  }
2644
2645
  function priceDetails(row, unit, locale) {
2645
2646
  const price = row.price;
2646
- if (price === void 0) {
2647
+ if (price == null) {
2647
2648
  return null;
2648
2649
  }
2649
2650
  const tier = currentTier(row);
@@ -3070,11 +3071,7 @@ function derivePricingTable(view, options) {
3070
3071
  const { catalog } = view;
3071
3072
  const plans = catalog.plans;
3072
3073
  const addOns = catalog.addOns;
3073
- const currencies = unique(
3074
- [...plans, ...addOns].flatMap(
3075
- (plan) => plan.currencyPrices.map((prices) => prices.currency.toLowerCase())
3076
- )
3077
- );
3074
+ const currencies = unique([...plans, ...addOns].flatMap(currenciesOf));
3078
3075
  const defaultCurrency = catalog.defaultCurrency?.toLowerCase();
3079
3076
  const currency = pick(currencies, options.currency?.toLowerCase(), [defaultCurrency]) ?? defaultCurrency ?? "usd";
3080
3077
  const priced = (plan) => supportsCurrency(plan, currency);
@@ -3173,6 +3170,7 @@ function card(plan, context, role) {
3173
3170
  const oneTime = isOneTime2(plan);
3174
3171
  const period = oneTime || periodsOf(plan).length === 0 ? null : context.period;
3175
3172
  const price = planPrice3(plan, currency, oneTime ? "oneTime" : period);
3173
+ const custom = customPlanOf2(plan);
3176
3174
  const entitlements = plan.entitlements;
3177
3175
  const amount = price === void 0 ? 0 : amountOf2(price);
3178
3176
  const usageBased = entitlements.some(
@@ -3183,15 +3181,25 @@ function card(plan, context, role) {
3183
3181
  );
3184
3182
  const { current } = standing(plan);
3185
3183
  const active = current && (period === null || context.currentPeriod === null || period === context.currentPeriod);
3184
+ let shownPrice;
3185
+ if (custom !== null) {
3186
+ shownPrice = { kind: "custom", text: custom.priceText };
3187
+ } else if (amount === 0 && usageBased) {
3188
+ shownPrice = { kind: "usageBased" };
3189
+ } else if (amount === 0 && options.showZeroPriceAsFree === true) {
3190
+ shownPrice = { kind: "free" };
3191
+ } else {
3192
+ shownPrice = {
3193
+ kind: "amount",
3194
+ amount: formatCurrency(amount, currency, locale),
3195
+ period
3196
+ };
3197
+ }
3186
3198
  return {
3187
3199
  id: plan.id,
3188
3200
  name: plan.name,
3189
3201
  description: nonEmpty2(plan.description),
3190
- price: amount === 0 && usageBased ? { kind: "usageBased" } : amount === 0 && options.showZeroPriceAsFree === true ? { kind: "free" } : {
3191
- kind: "amount",
3192
- amount: formatCurrency(amount, currency, locale),
3193
- period
3194
- },
3202
+ price: shownPrice,
3195
3203
  priceId: price?.id ?? null,
3196
3204
  period,
3197
3205
  credits: options.showCredits === false ? [] : creditLines(grants, entitlements, locale),
@@ -3199,6 +3207,7 @@ function card(plan, context, role) {
3199
3207
  (entitlement) => entitlementRow(entitlement, context, period, grants)
3200
3208
  ),
3201
3209
  action: context.view.source === "public" ? null : action(plan, context, role, active),
3210
+ custom,
3202
3211
  active,
3203
3212
  trialDays: plan.isTrialable && typeof plan.trialDays === "number" ? plan.trialDays : null,
3204
3213
  source: plan
@@ -3429,11 +3438,15 @@ function planPrice3(plan, currency, period) {
3429
3438
  if (period === null) {
3430
3439
  return void 0;
3431
3440
  }
3432
- const prices = plan.currencyPrices.find(
3433
- (candidate) => candidate.currency.toLowerCase() === currency
3434
- );
3435
3441
  const key = PRICE_KEY[period];
3436
- return prices?.[key] ?? void 0;
3442
+ if (plan.currencyPrices.length > 0) {
3443
+ const row = plan.currencyPrices.find(
3444
+ (candidate) => candidate.currency.toLowerCase() === currency
3445
+ );
3446
+ return row?.[key] ?? void 0;
3447
+ }
3448
+ const field = plan[key];
3449
+ return field !== void 0 && field.currency.toLowerCase() === currency ? field : void 0;
3437
3450
  }
3438
3451
  var PRICE_KEY = {
3439
3452
  month: "monthlyPrice",
@@ -3475,11 +3488,34 @@ function periodsOf(plan) {
3475
3488
  return period === void 0 ? [] : [period];
3476
3489
  });
3477
3490
  }
3478
- function supportsCurrency(plan, currency) {
3479
- return plan.currencyPrices.length === 0 || plan.currencyPrices.some(
3480
- (prices) => prices.currency.toLowerCase() === currency
3491
+ function currenciesOf(plan) {
3492
+ if (plan.currencyPrices.length > 0) {
3493
+ return unique(
3494
+ plan.currencyPrices.map((prices) => prices.currency.toLowerCase())
3495
+ );
3496
+ }
3497
+ return unique(
3498
+ Object.values(PRICE_KEY).flatMap((key) => {
3499
+ const field = plan[key];
3500
+ return field === void 0 ? [] : [field.currency.toLowerCase()];
3501
+ })
3481
3502
  );
3482
3503
  }
3504
+ function supportsCurrency(plan, currency) {
3505
+ const currencies = currenciesOf(plan);
3506
+ return currencies.length === 0 || currencies.includes(currency);
3507
+ }
3508
+ function customPlanOf2(plan) {
3509
+ if (!plan.custom) {
3510
+ return null;
3511
+ }
3512
+ const cta = plan.customPlanCta;
3513
+ return {
3514
+ priceText: nonEmpty2(cta?.priceText),
3515
+ ctaText: nonEmpty2(cta?.ctaText),
3516
+ ctaUrl: nonEmpty2(cta?.ctaUrl)
3517
+ };
3518
+ }
3483
3519
  function asPeriod(value) {
3484
3520
  return value === "month" || value === "quarter" || value === "year" ? value : null;
3485
3521
  }
@@ -4734,7 +4770,7 @@ var dialogCss = `
4734
4770
  }
4735
4771
  `;
4736
4772
 
4737
- // node_modules/.pnpm/@schematichq+schematic-icons@0.8.0_react-dom@19.3.0_react@19.3.0__react@19.3.0/node_modules/@schematichq/schematic-icons/dist/types.js
4773
+ // node_modules/.pnpm/@schematichq+schematic-icons@0.8.0_react-dom@19.3.1_react@19.3.1__react@19.3.1/node_modules/@schematichq/schematic-icons/dist/types.js
4738
4774
  var iconsList = {
4739
4775
  "workos": 61697,
4740
4776
  "wind": 61698,
@@ -8272,6 +8308,7 @@ function PeriodToggle({
8272
8308
  "button",
8273
8309
  {
8274
8310
  "aria-pressed": period === model.period.value,
8311
+ className: "schematic-toggle__option",
8275
8312
  type: "button",
8276
8313
  onClick: () => dispatch({ type: "period", period }),
8277
8314
  children: periodName(period, t)
@@ -9885,6 +9922,27 @@ IncludedFeatures.resources = ["featureUsage"];
9885
9922
  // src/elements/Invoices.tsx
9886
9923
  import { useInvoices } from "@schematichq/schematic-react";
9887
9924
  import { useId as useId6, useMemo as useMemo7, useState as useState11 } from "react";
9925
+
9926
+ // src/utils/invoiceLink.ts
9927
+ function openInvoiceLink(event, storedUrl, fetchUrl) {
9928
+ if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
9929
+ return Promise.resolve();
9930
+ }
9931
+ const tab = window.open("", "_blank");
9932
+ if (tab === null) {
9933
+ return Promise.resolve();
9934
+ }
9935
+ event.preventDefault();
9936
+ tab.opener = null;
9937
+ return fetchUrl().then(
9938
+ (url) => url || storedUrl,
9939
+ () => storedUrl
9940
+ ).then((url) => {
9941
+ tab.location.href = url;
9942
+ });
9943
+ }
9944
+
9945
+ // src/elements/Invoices.tsx
9888
9946
  import { Fragment as Fragment7, jsx as jsx13, jsxs as jsxs13 } from "react/jsx-runtime";
9889
9947
  var SKELETON_ROWS = 4;
9890
9948
  function Invoices({
@@ -9902,6 +9960,7 @@ function Invoices({
9902
9960
  const {
9903
9961
  data: page,
9904
9962
  error,
9963
+ fetchLink,
9905
9964
  isPending,
9906
9965
  loadMore,
9907
9966
  refetch
@@ -9958,7 +10017,7 @@ function Invoices({
9958
10017
  className: "schematic-invoices__row",
9959
10018
  "data-testid": "schematic-invoice",
9960
10019
  children: [
9961
- showDate && /* @__PURE__ */ jsx13("span", { className: "schematic-invoices__date", children: /* @__PURE__ */ jsx13(InvoiceDate, { row, t }) }),
10020
+ showDate && /* @__PURE__ */ jsx13("span", { className: "schematic-invoices__date", children: /* @__PURE__ */ jsx13(InvoiceDate, { row, t, fetchLink }) }),
9962
10021
  showAmount && /* @__PURE__ */ jsx13(
9963
10022
  "span",
9964
10023
  {
@@ -10036,8 +10095,13 @@ function InvoicesSkeleton({
10036
10095
  )) }, row))
10037
10096
  ] });
10038
10097
  }
10039
- function InvoiceDate({ row, t }) {
10040
- if (row.url === null) {
10098
+ function InvoiceDate({
10099
+ fetchLink,
10100
+ row,
10101
+ t
10102
+ }) {
10103
+ const { url } = row;
10104
+ if (url === null) {
10041
10105
  return /* @__PURE__ */ jsx13("span", { className: "schematic-invoices__date-text", children: row.dateText });
10042
10106
  }
10043
10107
  const label = row.dateText === "" ? t("invoicesUndated") : row.dateText;
@@ -10045,9 +10109,12 @@ function InvoiceDate({ row, t }) {
10045
10109
  "a",
10046
10110
  {
10047
10111
  className: "schematic-invoices__link",
10048
- href: row.url,
10112
+ href: url,
10049
10113
  rel: "noreferrer",
10050
10114
  target: "_blank",
10115
+ onClick: (event) => {
10116
+ void openInvoiceLink(event, url, () => fetchLink(row.id));
10117
+ },
10051
10118
  children: label
10052
10119
  }
10053
10120
  );
@@ -11279,7 +11346,8 @@ function Card2({
11279
11346
  {
11280
11347
  className: cx(
11281
11348
  "schematic-card schematic-plan-card",
11282
- card2.active && "schematic-plan-card--active"
11349
+ card2.active && "schematic-plan-card--active",
11350
+ card2.custom !== null && "schematic-plan-card--custom"
11283
11351
  ),
11284
11352
  "data-plan-id": card2.id,
11285
11353
  children: [
@@ -11344,13 +11412,25 @@ function Card2({
11344
11412
  function Price3({ price, t }) {
11345
11413
  const per = price.kind === "amount" && price.period !== null ? periodWord2(price.period, t) : void 0;
11346
11414
  return /* @__PURE__ */ jsxs16("div", { className: "schematic-plan-card__price", children: [
11347
- price.kind === "usageBased" ? t("pricingTableUsageBased") : price.kind === "free" ? t("pricingTableFree") : price.amount,
11415
+ priceText2(price, t),
11348
11416
  per !== void 0 && /* @__PURE__ */ jsxs16("sub", { className: "schematic-plan-card__period", children: [
11349
11417
  "/",
11350
11418
  per
11351
11419
  ] })
11352
11420
  ] });
11353
11421
  }
11422
+ function priceText2(price, t) {
11423
+ switch (price.kind) {
11424
+ case "usageBased":
11425
+ return t("pricingTableUsageBased");
11426
+ case "free":
11427
+ return t("pricingTableFree");
11428
+ case "custom":
11429
+ return price.text ?? t("pricingTableCustomPrice");
11430
+ case "amount":
11431
+ return price.amount;
11432
+ }
11433
+ }
11354
11434
  function CreditItem({
11355
11435
  credit,
11356
11436
  showIcon,
@@ -11498,27 +11578,29 @@ function Action({
11498
11578
  t("pricingTableCurrentPlan")
11499
11579
  ] });
11500
11580
  }
11501
- if (action2.kind === "downgradeBlocked") {
11502
- const text = action2.text ?? t("pricingTableTalkToSupport");
11503
- const link = action2.url !== null ? { href: action2.url, target: "_blank" } : shared.callToActionUrl !== void 0 ? { href: shared.callToActionUrl, target: shared.callToActionTarget } : void 0;
11504
- return /* @__PURE__ */ jsx16("div", { className: "schematic-plan-card__action", children: link === void 0 ? /* @__PURE__ */ jsx16(
11505
- "button",
11581
+ if (card2.custom !== null) {
11582
+ const link = hostedLink(card2.custom.ctaUrl, shared);
11583
+ if (link === void 0 && shared.onSelectPlan === void 0) {
11584
+ return null;
11585
+ }
11586
+ return /* @__PURE__ */ jsx16(
11587
+ CallToAction,
11506
11588
  {
11507
- className: "schematic-cta schematic-cta--outline",
11508
- disabled: true,
11509
- type: "button",
11510
- children: text
11589
+ className: "schematic-cta",
11590
+ link,
11591
+ text: card2.custom.ctaText ?? t("pricingTableTalkToSupport")
11511
11592
  }
11512
- ) : /* @__PURE__ */ jsx16(
11513
- "a",
11593
+ );
11594
+ }
11595
+ if (action2.kind === "downgradeBlocked") {
11596
+ return /* @__PURE__ */ jsx16(
11597
+ CallToAction,
11514
11598
  {
11515
11599
  className: "schematic-cta schematic-cta--outline",
11516
- href: link.href,
11517
- rel: "noreferrer",
11518
- target: link.target,
11519
- children: text
11600
+ link: hostedLink(action2.url, shared),
11601
+ text: action2.text ?? t("pricingTableTalkToSupport")
11520
11602
  }
11521
- ) });
11603
+ );
11522
11604
  }
11523
11605
  const select = () => shared.onSelectPlan?.({
11524
11606
  kind,
@@ -11568,6 +11650,31 @@ function Action({
11568
11650
  }) })
11569
11651
  ] });
11570
11652
  }
11653
+ function hostedLink(url, shared) {
11654
+ if (url !== null) {
11655
+ return { href: url, target: "_blank" };
11656
+ }
11657
+ if (shared.callToActionUrl !== void 0) {
11658
+ return { href: shared.callToActionUrl, target: shared.callToActionTarget };
11659
+ }
11660
+ return void 0;
11661
+ }
11662
+ function CallToAction({
11663
+ className,
11664
+ link,
11665
+ text
11666
+ }) {
11667
+ return /* @__PURE__ */ jsx16("div", { className: "schematic-plan-card__action", children: link === void 0 ? /* @__PURE__ */ jsx16("button", { className, disabled: true, type: "button", children: text }) : /* @__PURE__ */ jsx16(
11668
+ "a",
11669
+ {
11670
+ className,
11671
+ href: link.href,
11672
+ rel: "noreferrer",
11673
+ target: link.target,
11674
+ children: text
11675
+ }
11676
+ ) });
11677
+ }
11571
11678
  function CustomPlanCard2({
11572
11679
  customPlan,
11573
11680
  shared