@schematichq/schematic-components 2.37.0 → 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);
@@ -9971,6 +9972,27 @@ IncludedFeatures.resources = ["featureUsage"];
9971
9972
  // src/elements/Invoices.tsx
9972
9973
  var import_schematic_react8 = require("@schematichq/schematic-react");
9973
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
9974
9996
  var import_jsx_runtime14 = require("react/jsx-runtime");
9975
9997
  var SKELETON_ROWS = 4;
9976
9998
  function Invoices({
@@ -9988,6 +10010,7 @@ function Invoices({
9988
10010
  const {
9989
10011
  data: page,
9990
10012
  error,
10013
+ fetchLink,
9991
10014
  isPending,
9992
10015
  loadMore,
9993
10016
  refetch
@@ -10044,7 +10067,7 @@ function Invoices({
10044
10067
  className: "schematic-invoices__row",
10045
10068
  "data-testid": "schematic-invoice",
10046
10069
  children: [
10047
- 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 }) }),
10048
10071
  showAmount && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
10049
10072
  "span",
10050
10073
  {
@@ -10122,8 +10145,13 @@ function InvoicesSkeleton({
10122
10145
  )) }, row))
10123
10146
  ] });
10124
10147
  }
10125
- function InvoiceDate({ row, t }) {
10126
- if (row.url === null) {
10148
+ function InvoiceDate({
10149
+ fetchLink,
10150
+ row,
10151
+ t
10152
+ }) {
10153
+ const { url } = row;
10154
+ if (url === null) {
10127
10155
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "schematic-invoices__date-text", children: row.dateText });
10128
10156
  }
10129
10157
  const label = row.dateText === "" ? t("invoicesUndated") : row.dateText;
@@ -10131,9 +10159,12 @@ function InvoiceDate({ row, t }) {
10131
10159
  "a",
10132
10160
  {
10133
10161
  className: "schematic-invoices__link",
10134
- href: row.url,
10162
+ href: url,
10135
10163
  rel: "noreferrer",
10136
10164
  target: "_blank",
10165
+ onClick: (event) => {
10166
+ void openInvoiceLink(event, url, () => fetchLink(row.id));
10167
+ },
10137
10168
  children: label
10138
10169
  }
10139
10170
  );
@@ -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
@@ -2674,7 +2674,7 @@ export declare interface TierRange {
2674
2674
  }
2675
2675
 
2676
2676
  /** Every tier of the price, the first starting at one unit. */
2677
- export declare function tierRanges(price: MeteredPrice | undefined): TierRange[];
2677
+ export declare function tierRanges(price: MeteredPrice | null | undefined): TierRange[];
2678
2678
 
2679
2679
  /**
2680
2680
  * An info glyph that shows `children` while hovered or focused. The trigger
@@ -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);
@@ -9921,6 +9922,27 @@ IncludedFeatures.resources = ["featureUsage"];
9921
9922
  // src/elements/Invoices.tsx
9922
9923
  import { useInvoices } from "@schematichq/schematic-react";
9923
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
9924
9946
  import { Fragment as Fragment7, jsx as jsx13, jsxs as jsxs13 } from "react/jsx-runtime";
9925
9947
  var SKELETON_ROWS = 4;
9926
9948
  function Invoices({
@@ -9938,6 +9960,7 @@ function Invoices({
9938
9960
  const {
9939
9961
  data: page,
9940
9962
  error,
9963
+ fetchLink,
9941
9964
  isPending,
9942
9965
  loadMore,
9943
9966
  refetch
@@ -9994,7 +10017,7 @@ function Invoices({
9994
10017
  className: "schematic-invoices__row",
9995
10018
  "data-testid": "schematic-invoice",
9996
10019
  children: [
9997
- 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 }) }),
9998
10021
  showAmount && /* @__PURE__ */ jsx13(
9999
10022
  "span",
10000
10023
  {
@@ -10072,8 +10095,13 @@ function InvoicesSkeleton({
10072
10095
  )) }, row))
10073
10096
  ] });
10074
10097
  }
10075
- function InvoiceDate({ row, t }) {
10076
- if (row.url === null) {
10098
+ function InvoiceDate({
10099
+ fetchLink,
10100
+ row,
10101
+ t
10102
+ }) {
10103
+ const { url } = row;
10104
+ if (url === null) {
10077
10105
  return /* @__PURE__ */ jsx13("span", { className: "schematic-invoices__date-text", children: row.dateText });
10078
10106
  }
10079
10107
  const label = row.dateText === "" ? t("invoicesUndated") : row.dateText;
@@ -10081,9 +10109,12 @@ function InvoiceDate({ row, t }) {
10081
10109
  "a",
10082
10110
  {
10083
10111
  className: "schematic-invoices__link",
10084
- href: row.url,
10112
+ href: url,
10085
10113
  rel: "noreferrer",
10086
10114
  target: "_blank",
10115
+ onClick: (event) => {
10116
+ void openInvoiceLink(event, url, () => fetchLink(row.id));
10117
+ },
10087
10118
  children: label
10088
10119
  }
10089
10120
  );