@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.
@@ -146,7 +146,8 @@ var PaymentMethodForm_exports = {};
146
146
  __export(PaymentMethodForm_exports, {
147
147
  PaymentMethodForm: () => PaymentMethodForm,
148
148
  default: () => PaymentMethodForm_default,
149
- resolveAppearance: () => resolveAppearance
149
+ resolveAppearance: () => resolveAppearance,
150
+ resolved: () => resolved
150
151
  });
151
152
  function orUndefined(value) {
152
153
  return value === void 0 || value === "" ? void 0 : value;
@@ -1955,7 +1956,7 @@ function prorationBlock(detail, input) {
1955
1956
  return {
1956
1957
  key: `${line.kind}:${line.planId ?? line.priceId ?? ""}:${index}`,
1957
1958
  kind: line.kind,
1958
- name: catalogName(catalog, line.planId) ?? catalogPriceName(catalog, line.priceId) ?? (line.planId != null && current !== void 0 && current.id === line.planId ? current.name : null),
1959
+ name: catalogName(catalog, line.planId) ?? catalogPriceName(catalog, line.priceId) ?? (line.planId != null && current != null && current.id === line.planId ? current.name : null),
1959
1960
  periodText: start !== void 0 && end !== void 0 ? formatShortDateRange(start, end, locale) : null,
1960
1961
  amountText: money(line.amount)
1961
1962
  };
@@ -1972,7 +1973,7 @@ function prorationBlock(detail, input) {
1972
1973
  }
1973
1974
  function customPlanOf(catalog) {
1974
1975
  const cta = catalog.customPlanCta;
1975
- if (cta === void 0) {
1976
+ if (cta == null) {
1976
1977
  return null;
1977
1978
  }
1978
1979
  const custom = {
@@ -2178,7 +2179,7 @@ function deriveCheckout(input) {
2178
2179
  enabled: choice.enabled ?? topup.companyEnabled ?? topup.enabled,
2179
2180
  thresholdCredits: choice.thresholdCredits ?? topup.companyThresholdCredits ?? topup.thresholdCredits ?? null,
2180
2181
  amount,
2181
- costText: amount === null || unit === void 0 ? null : priceText(unit, locale, amount)
2182
+ costText: amount === null || unit == null ? null : priceText(unit, locale, amount)
2182
2183
  };
2183
2184
  }),
2184
2185
  lines,
@@ -2324,7 +2325,7 @@ function isEnglish2(locale) {
2324
2325
 
2325
2326
  // src/elements/model/featureUsage.ts
2326
2327
  function pricePeriod(price) {
2327
- if (price === void 0) {
2328
+ if (price == null) {
2328
2329
  return null;
2329
2330
  }
2330
2331
  if (price.interval === "month" && price.intervalCount === 3) {
@@ -2333,7 +2334,7 @@ function pricePeriod(price) {
2333
2334
  return price.interval;
2334
2335
  }
2335
2336
  function isTieredPrice(price) {
2336
- return price !== void 0 && (price.priceTiers.length > 1 || price.tiersMode !== void 0 && price.tiersMode !== null);
2337
+ return price != null && (price.priceTiers.length > 1 || price.tiersMode !== void 0 && price.tiersMode !== null);
2337
2338
  }
2338
2339
  function unitPrice(price) {
2339
2340
  return decimalOr(price.priceDecimal, price.price);
@@ -2438,7 +2439,7 @@ function includedFeatureRow(row, options) {
2438
2439
  amount: formatNumber(row.allocation, locale),
2439
2440
  units: featureName(feature, row.allocation, locale)
2440
2441
  } : null,
2441
- tiers: (row.priceBehavior === "tier" || tiered) && row.price !== void 0 ? {
2442
+ tiers: (row.priceBehavior === "tier" || tiered) && row.price != null ? {
2442
2443
  ranges: tierRanges(row.price),
2443
2444
  currency: row.price.currency,
2444
2445
  mode: row.price.tiersMode ?? null,
@@ -2468,7 +2469,7 @@ function entitlementText(row, options) {
2468
2469
  case "pay_in_advance":
2469
2470
  return typeof row.allocation === "number" ? { kind: "units", ...units(row.allocation) } : null;
2470
2471
  case "pay_as_you_go": {
2471
- if (row.price === void 0) {
2472
+ if (row.price == null) {
2472
2473
  return null;
2473
2474
  }
2474
2475
  const cost = formatCurrency(
@@ -2536,7 +2537,7 @@ function usageSegments(row, locale, tiered, period) {
2536
2537
  pluralName: row.featurePluralName
2537
2538
  };
2538
2539
  const segments = [];
2539
- if (row.priceBehavior === "pay_in_advance" && !tiered && period !== null && row.price !== void 0) {
2540
+ if (row.priceBehavior === "pay_in_advance" && !tiered && period !== null && row.price != null) {
2540
2541
  const size = row.price.packageSize;
2541
2542
  segments.push({
2542
2543
  kind: "unitPricePerPeriod",
@@ -2552,7 +2553,7 @@ function usageSegments(row, locale, tiered, period) {
2552
2553
  units: featureName(feature, row.usage, locale)
2553
2554
  });
2554
2555
  }
2555
- if (typeof row.currentCost === "number" && row.currentCost > 0 && row.price !== void 0) {
2556
+ if (typeof row.currentCost === "number" && row.currentCost > 0 && row.price != null) {
2556
2557
  segments.push({
2557
2558
  kind: "cost",
2558
2559
  cost: formatCurrency(row.currentCost, row.price.currency, locale),
@@ -2676,7 +2677,7 @@ function limitLine(row, limit, unit, options) {
2676
2677
  }
2677
2678
  break;
2678
2679
  case "pay_as_you_go":
2679
- if (typeof row.currentCost === "number" && row.price !== void 0) {
2680
+ if (typeof row.currentCost === "number" && row.price != null) {
2680
2681
  return {
2681
2682
  kind: "cost",
2682
2683
  cost: formatCurrency(row.currentCost, row.price.currency, locale)
@@ -2730,7 +2731,7 @@ function meter(row, options) {
2730
2731
  }
2731
2732
  function priceDetails(row, unit, locale) {
2732
2733
  const price = row.price;
2733
- if (price === void 0) {
2734
+ if (price == null) {
2734
2735
  return null;
2735
2736
  }
2736
2737
  const tier = currentTier(row);
@@ -3157,11 +3158,7 @@ function derivePricingTable(view, options) {
3157
3158
  const { catalog } = view;
3158
3159
  const plans = catalog.plans;
3159
3160
  const addOns = catalog.addOns;
3160
- const currencies = unique(
3161
- [...plans, ...addOns].flatMap(
3162
- (plan) => plan.currencyPrices.map((prices) => prices.currency.toLowerCase())
3163
- )
3164
- );
3161
+ const currencies = unique([...plans, ...addOns].flatMap(currenciesOf));
3165
3162
  const defaultCurrency = catalog.defaultCurrency?.toLowerCase();
3166
3163
  const currency = pick(currencies, options.currency?.toLowerCase(), [defaultCurrency]) ?? defaultCurrency ?? "usd";
3167
3164
  const priced = (plan) => supportsCurrency(plan, currency);
@@ -3260,6 +3257,7 @@ function card(plan, context, role) {
3260
3257
  const oneTime = isOneTime2(plan);
3261
3258
  const period = oneTime || periodsOf(plan).length === 0 ? null : context.period;
3262
3259
  const price = planPrice3(plan, currency, oneTime ? "oneTime" : period);
3260
+ const custom = customPlanOf2(plan);
3263
3261
  const entitlements = plan.entitlements;
3264
3262
  const amount = price === void 0 ? 0 : amountOf2(price);
3265
3263
  const usageBased = entitlements.some(
@@ -3270,15 +3268,25 @@ function card(plan, context, role) {
3270
3268
  );
3271
3269
  const { current } = standing(plan);
3272
3270
  const active = current && (period === null || context.currentPeriod === null || period === context.currentPeriod);
3271
+ let shownPrice;
3272
+ if (custom !== null) {
3273
+ shownPrice = { kind: "custom", text: custom.priceText };
3274
+ } else if (amount === 0 && usageBased) {
3275
+ shownPrice = { kind: "usageBased" };
3276
+ } else if (amount === 0 && options.showZeroPriceAsFree === true) {
3277
+ shownPrice = { kind: "free" };
3278
+ } else {
3279
+ shownPrice = {
3280
+ kind: "amount",
3281
+ amount: formatCurrency(amount, currency, locale),
3282
+ period
3283
+ };
3284
+ }
3273
3285
  return {
3274
3286
  id: plan.id,
3275
3287
  name: plan.name,
3276
3288
  description: nonEmpty2(plan.description),
3277
- price: amount === 0 && usageBased ? { kind: "usageBased" } : amount === 0 && options.showZeroPriceAsFree === true ? { kind: "free" } : {
3278
- kind: "amount",
3279
- amount: formatCurrency(amount, currency, locale),
3280
- period
3281
- },
3289
+ price: shownPrice,
3282
3290
  priceId: price?.id ?? null,
3283
3291
  period,
3284
3292
  credits: options.showCredits === false ? [] : creditLines(grants, entitlements, locale),
@@ -3286,6 +3294,7 @@ function card(plan, context, role) {
3286
3294
  (entitlement) => entitlementRow(entitlement, context, period, grants)
3287
3295
  ),
3288
3296
  action: context.view.source === "public" ? null : action(plan, context, role, active),
3297
+ custom,
3289
3298
  active,
3290
3299
  trialDays: plan.isTrialable && typeof plan.trialDays === "number" ? plan.trialDays : null,
3291
3300
  source: plan
@@ -3516,11 +3525,15 @@ function planPrice3(plan, currency, period) {
3516
3525
  if (period === null) {
3517
3526
  return void 0;
3518
3527
  }
3519
- const prices = plan.currencyPrices.find(
3520
- (candidate) => candidate.currency.toLowerCase() === currency
3521
- );
3522
3528
  const key = PRICE_KEY[period];
3523
- return prices?.[key] ?? void 0;
3529
+ if (plan.currencyPrices.length > 0) {
3530
+ const row = plan.currencyPrices.find(
3531
+ (candidate) => candidate.currency.toLowerCase() === currency
3532
+ );
3533
+ return row?.[key] ?? void 0;
3534
+ }
3535
+ const field = plan[key];
3536
+ return field !== void 0 && field.currency.toLowerCase() === currency ? field : void 0;
3524
3537
  }
3525
3538
  var PRICE_KEY = {
3526
3539
  month: "monthlyPrice",
@@ -3562,11 +3575,34 @@ function periodsOf(plan) {
3562
3575
  return period === void 0 ? [] : [period];
3563
3576
  });
3564
3577
  }
3565
- function supportsCurrency(plan, currency) {
3566
- return plan.currencyPrices.length === 0 || plan.currencyPrices.some(
3567
- (prices) => prices.currency.toLowerCase() === currency
3578
+ function currenciesOf(plan) {
3579
+ if (plan.currencyPrices.length > 0) {
3580
+ return unique(
3581
+ plan.currencyPrices.map((prices) => prices.currency.toLowerCase())
3582
+ );
3583
+ }
3584
+ return unique(
3585
+ Object.values(PRICE_KEY).flatMap((key) => {
3586
+ const field = plan[key];
3587
+ return field === void 0 ? [] : [field.currency.toLowerCase()];
3588
+ })
3568
3589
  );
3569
3590
  }
3591
+ function supportsCurrency(plan, currency) {
3592
+ const currencies = currenciesOf(plan);
3593
+ return currencies.length === 0 || currencies.includes(currency);
3594
+ }
3595
+ function customPlanOf2(plan) {
3596
+ if (!plan.custom) {
3597
+ return null;
3598
+ }
3599
+ const cta = plan.customPlanCta;
3600
+ return {
3601
+ priceText: nonEmpty2(cta?.priceText),
3602
+ ctaText: nonEmpty2(cta?.ctaText),
3603
+ ctaUrl: nonEmpty2(cta?.ctaUrl)
3604
+ };
3605
+ }
3570
3606
  function asPeriod(value) {
3571
3607
  return value === "month" || value === "quarter" || value === "year" ? value : null;
3572
3608
  }
@@ -4821,7 +4857,7 @@ var dialogCss = `
4821
4857
  }
4822
4858
  `;
4823
4859
 
4824
- // 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
4860
+ // 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
4825
4861
  var iconsList = {
4826
4862
  "workos": 61697,
4827
4863
  "wind": 61698,
@@ -8331,6 +8367,7 @@ function PeriodToggle({
8331
8367
  "button",
8332
8368
  {
8333
8369
  "aria-pressed": period === model.period.value,
8370
+ className: "schematic-toggle__option",
8334
8371
  type: "button",
8335
8372
  onClick: () => dispatch({ type: "period", period }),
8336
8373
  children: periodName(period, t)
@@ -9935,6 +9972,27 @@ IncludedFeatures.resources = ["featureUsage"];
9935
9972
  // src/elements/Invoices.tsx
9936
9973
  var import_schematic_react8 = require("@schematichq/schematic-react");
9937
9974
  var import_react13 = require("react");
9975
+
9976
+ // src/utils/invoiceLink.ts
9977
+ function openInvoiceLink(event, storedUrl, fetchUrl) {
9978
+ if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
9979
+ return Promise.resolve();
9980
+ }
9981
+ const tab = window.open("", "_blank");
9982
+ if (tab === null) {
9983
+ return Promise.resolve();
9984
+ }
9985
+ event.preventDefault();
9986
+ tab.opener = null;
9987
+ return fetchUrl().then(
9988
+ (url) => url || storedUrl,
9989
+ () => storedUrl
9990
+ ).then((url) => {
9991
+ tab.location.href = url;
9992
+ });
9993
+ }
9994
+
9995
+ // src/elements/Invoices.tsx
9938
9996
  var import_jsx_runtime14 = require("react/jsx-runtime");
9939
9997
  var SKELETON_ROWS = 4;
9940
9998
  function Invoices({
@@ -9952,6 +10010,7 @@ function Invoices({
9952
10010
  const {
9953
10011
  data: page,
9954
10012
  error,
10013
+ fetchLink,
9955
10014
  isPending,
9956
10015
  loadMore,
9957
10016
  refetch
@@ -10008,7 +10067,7 @@ function Invoices({
10008
10067
  className: "schematic-invoices__row",
10009
10068
  "data-testid": "schematic-invoice",
10010
10069
  children: [
10011
- showDate && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "schematic-invoices__date", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(InvoiceDate, { row, t }) }),
10070
+ showDate && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "schematic-invoices__date", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(InvoiceDate, { row, t, fetchLink }) }),
10012
10071
  showAmount && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
10013
10072
  "span",
10014
10073
  {
@@ -10086,8 +10145,13 @@ function InvoicesSkeleton({
10086
10145
  )) }, row))
10087
10146
  ] });
10088
10147
  }
10089
- function InvoiceDate({ row, t }) {
10090
- if (row.url === null) {
10148
+ function InvoiceDate({
10149
+ fetchLink,
10150
+ row,
10151
+ t
10152
+ }) {
10153
+ const { url } = row;
10154
+ if (url === null) {
10091
10155
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "schematic-invoices__date-text", children: row.dateText });
10092
10156
  }
10093
10157
  const label = row.dateText === "" ? t("invoicesUndated") : row.dateText;
@@ -10095,9 +10159,12 @@ function InvoiceDate({ row, t }) {
10095
10159
  "a",
10096
10160
  {
10097
10161
  className: "schematic-invoices__link",
10098
- href: row.url,
10162
+ href: url,
10099
10163
  rel: "noreferrer",
10100
10164
  target: "_blank",
10165
+ onClick: (event) => {
10166
+ void openInvoiceLink(event, url, () => fetchLink(row.id));
10167
+ },
10101
10168
  children: label
10102
10169
  }
10103
10170
  );
@@ -11322,7 +11389,8 @@ function Card2({
11322
11389
  {
11323
11390
  className: cx(
11324
11391
  "schematic-card schematic-plan-card",
11325
- card2.active && "schematic-plan-card--active"
11392
+ card2.active && "schematic-plan-card--active",
11393
+ card2.custom !== null && "schematic-plan-card--custom"
11326
11394
  ),
11327
11395
  "data-plan-id": card2.id,
11328
11396
  children: [
@@ -11387,13 +11455,25 @@ function Card2({
11387
11455
  function Price3({ price, t }) {
11388
11456
  const per = price.kind === "amount" && price.period !== null ? periodWord2(price.period, t) : void 0;
11389
11457
  return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "schematic-plan-card__price", children: [
11390
- price.kind === "usageBased" ? t("pricingTableUsageBased") : price.kind === "free" ? t("pricingTableFree") : price.amount,
11458
+ priceText2(price, t),
11391
11459
  per !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("sub", { className: "schematic-plan-card__period", children: [
11392
11460
  "/",
11393
11461
  per
11394
11462
  ] })
11395
11463
  ] });
11396
11464
  }
11465
+ function priceText2(price, t) {
11466
+ switch (price.kind) {
11467
+ case "usageBased":
11468
+ return t("pricingTableUsageBased");
11469
+ case "free":
11470
+ return t("pricingTableFree");
11471
+ case "custom":
11472
+ return price.text ?? t("pricingTableCustomPrice");
11473
+ case "amount":
11474
+ return price.amount;
11475
+ }
11476
+ }
11397
11477
  function CreditItem({
11398
11478
  credit,
11399
11479
  showIcon,
@@ -11541,27 +11621,29 @@ function Action({
11541
11621
  t("pricingTableCurrentPlan")
11542
11622
  ] });
11543
11623
  }
11544
- if (action2.kind === "downgradeBlocked") {
11545
- const text = action2.text ?? t("pricingTableTalkToSupport");
11546
- const link = action2.url !== null ? { href: action2.url, target: "_blank" } : shared.callToActionUrl !== void 0 ? { href: shared.callToActionUrl, target: shared.callToActionTarget } : void 0;
11547
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "schematic-plan-card__action", children: link === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
11548
- "button",
11624
+ if (card2.custom !== null) {
11625
+ const link = hostedLink(card2.custom.ctaUrl, shared);
11626
+ if (link === void 0 && shared.onSelectPlan === void 0) {
11627
+ return null;
11628
+ }
11629
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
11630
+ CallToAction,
11549
11631
  {
11550
- className: "schematic-cta schematic-cta--outline",
11551
- disabled: true,
11552
- type: "button",
11553
- children: text
11632
+ className: "schematic-cta",
11633
+ link,
11634
+ text: card2.custom.ctaText ?? t("pricingTableTalkToSupport")
11554
11635
  }
11555
- ) : /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
11556
- "a",
11636
+ );
11637
+ }
11638
+ if (action2.kind === "downgradeBlocked") {
11639
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
11640
+ CallToAction,
11557
11641
  {
11558
11642
  className: "schematic-cta schematic-cta--outline",
11559
- href: link.href,
11560
- rel: "noreferrer",
11561
- target: link.target,
11562
- children: text
11643
+ link: hostedLink(action2.url, shared),
11644
+ text: action2.text ?? t("pricingTableTalkToSupport")
11563
11645
  }
11564
- ) });
11646
+ );
11565
11647
  }
11566
11648
  const select = () => shared.onSelectPlan?.({
11567
11649
  kind,
@@ -11611,6 +11693,31 @@ function Action({
11611
11693
  }) })
11612
11694
  ] });
11613
11695
  }
11696
+ function hostedLink(url, shared) {
11697
+ if (url !== null) {
11698
+ return { href: url, target: "_blank" };
11699
+ }
11700
+ if (shared.callToActionUrl !== void 0) {
11701
+ return { href: shared.callToActionUrl, target: shared.callToActionTarget };
11702
+ }
11703
+ return void 0;
11704
+ }
11705
+ function CallToAction({
11706
+ className,
11707
+ link,
11708
+ text
11709
+ }) {
11710
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "schematic-plan-card__action", children: link === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("button", { className, disabled: true, type: "button", children: text }) : /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
11711
+ "a",
11712
+ {
11713
+ className,
11714
+ href: link.href,
11715
+ rel: "noreferrer",
11716
+ target: link.target,
11717
+ children: text
11718
+ }
11719
+ ) });
11720
+ }
11614
11721
  function CustomPlanCard2({
11615
11722
  customPlan,
11616
11723
  shared
@@ -1584,7 +1584,7 @@ export declare interface InvoicesProps extends ElementProps {
1584
1584
  }
1585
1585
 
1586
1586
  /** Tiered when it has more than one tier, or a tiers mode says so. */
1587
- export declare function isTieredPrice(price: MeteredPrice | undefined): boolean;
1587
+ export declare function isTieredPrice(price: MeteredPrice | null | undefined): boolean;
1588
1588
 
1589
1589
  /**
1590
1590
  * `locale` is the language the catalogue is written in, since that decides
@@ -2162,7 +2162,7 @@ declare type PluralSuffix = "zero" | "one" | "two" | "few" | "many" | "other";
2162
2162
  * interval and interval count (a quarter is three months). `null` without a
2163
2163
  * price.
2164
2164
  */
2165
- export declare function pricePeriod(price: MeteredPrice | undefined): string | null;
2165
+ export declare function pricePeriod(price: MeteredPrice | null | undefined): string | null;
2166
2166
 
2167
2167
  /**
2168
2168
  * What IncludedFeatures and MeteredFeatures both read off a usage row: its
@@ -2219,6 +2219,11 @@ export declare interface PricingCard {
2219
2219
  entitlements: PricingEntitlementRow[];
2220
2220
  /** `null` in the public catalog, where there is no company. */
2221
2221
  action: PricingAction | null;
2222
+ /**
2223
+ * The catalog's custom plan, sold by quote, whose call to action and price
2224
+ * text stand in for the card's action and price; `null` for every other card.
2225
+ */
2226
+ custom: PricingCustomPlan | null;
2222
2227
  /** The company's plan in the chosen period, for the card's outline. */
2223
2228
  active: boolean;
2224
2229
  trialDays: number | null;
@@ -2355,6 +2360,11 @@ export declare type PricingPrice =
2355
2360
  /** Priced at zero, and billed by what it is used. */
2356
2361
  | {
2357
2362
  kind: "usageBased";
2363
+ }
2364
+ /** Sold by quote: the custom plan's price text, or "Custom price". */
2365
+ | {
2366
+ kind: "custom";
2367
+ text: string | null;
2358
2368
  };
2359
2369
 
2360
2370
  /** What a card's action does: `remove` and `change` are for a held add-on. */
@@ -2664,7 +2674,7 @@ export declare interface TierRange {
2664
2674
  }
2665
2675
 
2666
2676
  /** Every tier of the price, the first starting at one unit. */
2667
- export declare function tierRanges(price: MeteredPrice | undefined): TierRange[];
2677
+ export declare function tierRanges(price: MeteredPrice | null | undefined): TierRange[];
2668
2678
 
2669
2679
  /**
2670
2680
  * An info glyph that shows `children` while hovered or focused. The trigger