@drawbridge/components 0.1.47 → 0.1.48

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.
Files changed (114) hide show
  1. package/dist/bridge/cart-drawer.js +152 -0
  2. package/dist/bridge/cart-drawer.mjs +123 -0
  3. package/dist/bridge/fields.js +278 -0
  4. package/dist/bridge/fields.mjs +276 -1
  5. package/dist/bridge/form-subdomain-checkout.js +687 -0
  6. package/dist/bridge/form-subdomain-checkout.mjs +665 -0
  7. package/dist/bridge/form-subdomain-shop-modal.js +234 -274
  8. package/dist/bridge/form-subdomain-shop-modal.mjs +233 -275
  9. package/dist/bridge/form-subdomain.js +1 -0
  10. package/dist/bridge/form-subdomain.mjs +2 -1
  11. package/dist/bridge/lib/age-gate.js +12 -0
  12. package/dist/bridge/lib/age-gate.mjs +11 -0
  13. package/dist/bridge/lib/cart.js +79 -0
  14. package/dist/bridge/lib/cart.mjs +48 -0
  15. package/dist/bridge/lib/checkout-kit.js +2 -32
  16. package/dist/bridge/lib/checkout-kit.mjs +2 -32
  17. package/dist/bridge/product-tile.js +9 -6
  18. package/dist/bridge/product-tile.mjs +9 -6
  19. package/dist/bridge/template-layout.js +237 -122
  20. package/dist/bridge/template-layout.mjs +237 -122
  21. package/dist/bridge/template-modal.js +28 -73
  22. package/dist/bridge/template-modal.mjs +29 -74
  23. package/dist/dashboard/buttons-subscription.js +1 -1
  24. package/dist/dashboard/buttons-subscription.mjs +1 -1
  25. package/dist/dashboard/campaign-form.js +7 -2
  26. package/dist/dashboard/campaign-form.mjs +7 -2
  27. package/dist/dashboard/card-order.js +22 -4
  28. package/dist/dashboard/card-order.mjs +22 -4
  29. package/dist/dashboard/embed-stripe.js +145 -0
  30. package/dist/dashboard/embed-stripe.mjs +116 -0
  31. package/dist/dashboard/form-admin-provider.js +71 -17
  32. package/dist/dashboard/form-admin-provider.mjs +71 -17
  33. package/dist/dashboard/form-file-upload.js +3 -2
  34. package/dist/dashboard/form-file-upload.mjs +4 -3
  35. package/dist/dashboard/form-organization-campaign-advertisements.js +47 -6
  36. package/dist/dashboard/form-organization-campaign-advertisements.mjs +47 -6
  37. package/dist/dashboard/form-organization-campaign-field-birthday.js +193 -0
  38. package/dist/dashboard/form-organization-campaign-field-birthday.mjs +164 -0
  39. package/dist/dashboard/form-organization-campaign-field-rating.js +246 -0
  40. package/dist/dashboard/form-organization-campaign-field-rating.mjs +217 -0
  41. package/dist/dashboard/form-organization-campaign.js +82 -0
  42. package/dist/dashboard/form-organization-campaign.mjs +81 -0
  43. package/dist/dashboard/form-organization-connection.js +48 -6
  44. package/dist/dashboard/form-organization-connection.mjs +48 -7
  45. package/dist/dashboard/form-organization-product.js +1461 -0
  46. package/dist/dashboard/form-organization-product.mjs +1425 -0
  47. package/dist/dashboard/form-organization-workflow.js +72 -1
  48. package/dist/dashboard/form-organization-workflow.mjs +69 -1
  49. package/dist/dashboard/form-otc.js +4 -5
  50. package/dist/dashboard/form-otc.mjs +4 -5
  51. package/dist/dashboard/form-stripe.js +12 -5
  52. package/dist/dashboard/form-stripe.mjs +12 -5
  53. package/dist/dashboard/input-fields.js +11 -158
  54. package/dist/dashboard/input-fields.mjs +11 -158
  55. package/dist/dashboard/input-file.js +21 -4
  56. package/dist/dashboard/input-file.mjs +21 -4
  57. package/dist/dashboard/input-gallery.js +201 -0
  58. package/dist/dashboard/input-gallery.mjs +172 -0
  59. package/dist/dashboard/lib/connection-controls.js +5 -2
  60. package/dist/dashboard/lib/connection-controls.mjs +3 -1
  61. package/dist/dashboard/lib/form-page.js +1 -1
  62. package/dist/dashboard/lib/form-page.mjs +1 -1
  63. package/dist/dashboard/lib/products.js +169 -0
  64. package/dist/dashboard/lib/products.mjs +135 -0
  65. package/dist/dashboard/lib/settings-paths.js +35 -0
  66. package/dist/dashboard/lib/settings-paths.mjs +11 -0
  67. package/dist/dashboard/lib/uppy.js +10 -1
  68. package/dist/dashboard/lib/uppy.mjs +11 -2
  69. package/dist/dashboard/order-sections.js +456 -6
  70. package/dist/dashboard/order-sections.mjs +453 -7
  71. package/dist/dashboard/provider-ui.js +9 -7
  72. package/dist/dashboard/provider-ui.mjs +9 -7
  73. package/dist/dashboard/shipping-rates.js +404 -0
  74. package/dist/dashboard/shipping-rates.mjs +371 -0
  75. package/dist/dashboard/template-buyer.js +301 -0
  76. package/dist/dashboard/template-buyer.mjs +267 -0
  77. package/dist/input-checkbox.js +28 -10
  78. package/dist/input-checkbox.mjs +28 -10
  79. package/dist/product.js +96 -24
  80. package/dist/product.mjs +97 -25
  81. package/dist/shared/lib/helpers.js +54 -6
  82. package/dist/shared/lib/helpers.mjs +53 -8
  83. package/dist/shared/order-summary.js +139 -0
  84. package/dist/shared/order-summary.mjs +110 -0
  85. package/package.json +74 -4
  86. package/types/bridge/cart-drawer.d.ts +31 -0
  87. package/types/bridge/fields.d.ts +14 -2
  88. package/types/bridge/form-subdomain-checkout.d.ts +20 -0
  89. package/types/bridge/form-subdomain-shop-modal.d.ts +27 -3
  90. package/types/bridge/lib/age-gate.d.ts +5 -0
  91. package/types/bridge/lib/cart.d.ts +44 -0
  92. package/types/bridge/lib/checkout-kit.d.ts +2 -10
  93. package/types/dashboard/card-order.d.ts +6 -0
  94. package/types/dashboard/embed-stripe.d.ts +25 -0
  95. package/types/dashboard/form-admin-provider.d.ts +9 -2
  96. package/types/dashboard/form-file-upload.d.ts +2 -1
  97. package/types/dashboard/form-organization-campaign-advertisements.d.ts +3 -0
  98. package/types/dashboard/form-organization-campaign-field-birthday.d.ts +31 -0
  99. package/types/dashboard/form-organization-campaign-field-rating.d.ts +33 -0
  100. package/types/dashboard/form-organization-campaign.d.ts +3 -0
  101. package/types/dashboard/form-organization-connection.d.ts +11 -0
  102. package/types/dashboard/form-organization-product.d.ts +24 -0
  103. package/types/dashboard/form-otc.d.ts +5 -1
  104. package/types/dashboard/form-stripe.d.ts +3 -2
  105. package/types/dashboard/input-file.d.ts +2 -0
  106. package/types/dashboard/input-gallery.d.ts +14 -0
  107. package/types/dashboard/lib/products.d.ts +14 -0
  108. package/types/dashboard/lib/settings-paths.d.ts +5 -0
  109. package/types/dashboard/order-sections.d.ts +24 -1
  110. package/types/dashboard/shipping-rates.d.ts +26 -0
  111. package/types/dashboard/template-buyer.d.ts +50 -0
  112. package/types/input-checkbox.d.ts +2 -0
  113. package/types/shared/lib/helpers.d.ts +4 -0
  114. package/types/shared/order-summary.d.ts +19 -0
@@ -0,0 +1,404 @@
1
+ "use client";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var shipping_rates_exports = {};
30
+ __export(shipping_rates_exports, {
31
+ FormRate: () => FormRate,
32
+ default: () => shipping_rates_default
33
+ });
34
+ module.exports = __toCommonJS(shipping_rates_exports);
35
+ var import_jsx_runtime = require("react/jsx-runtime");
36
+ var import_react_query = require("@tanstack/react-query");
37
+ var import_drawbridge_utils = require("@drawbridge/drawbridge-utils");
38
+ var import_fetch = require("@drawbridge/drawbridge-utils/fetch");
39
+ var import_products = require("@drawbridge/drawbridge-utils/products");
40
+ var import_form = require("../shared/lib/form");
41
+ var import_yup = __toESM(require("../shared/lib/yup"));
42
+ var import_hooks = require("./lib/hooks");
43
+ var import_order_sections = require("./order-sections");
44
+ var import_card_section = __toESM(require("./card-section"));
45
+ var import_paged = __toESM(require("./paged"));
46
+ var import_table = __toESM(require("./table"));
47
+ var import_table_cell_title = __toESM(require("./table-cell-title"));
48
+ var import_button = __toESM(require("../shared/button"));
49
+ var import_fieldset = __toESM(require("../shared/fieldset"));
50
+ var import_form2 = __toESM(require("../shared/form"));
51
+ var import_input_switch = __toESM(require("../shared/input-switch"));
52
+ var import_input_group = __toESM(require("../input-group"));
53
+ var import_input_number = __toESM(require("../input-number"));
54
+ var import_input_select = __toESM(require("../input-select"));
55
+ var import_input_text = __toESM(require("../input-text"));
56
+ var import_pencil = __toESM(require("../icons/pencil"));
57
+ var import_plus = __toESM(require("../icons/plus"));
58
+ var import_trash = __toESM(require("../icons/trash"));
59
+ const COUNTRIES = [
60
+ {
61
+ label: "Canada",
62
+ value: "CA"
63
+ },
64
+ {
65
+ label: "United States",
66
+ value: "US"
67
+ }
68
+ ];
69
+ const countryName = (code) => {
70
+ var _a;
71
+ return ((_a = COUNTRIES.find((item) => item.value === code)) == null ? void 0 : _a.label) || code;
72
+ };
73
+ const keyOf = (delivery) => delivery ? delivery.minimum + "-" + delivery.maximum : "";
74
+ const FormRate = ({ currency, endpoint, onError, onSuccess, values }) => {
75
+ const { control, formState, handleSubmit, watch } = (0, import_form.useForm)({
76
+ resolver: (0, import_yup.resolver)(
77
+ import_yup.default.object({
78
+ free: import_yup.default.number().label("Free over").nullable().when("freeOver", ([on], schema) => on ? schema.required().min(0) : schema),
79
+ name: import_yup.default.string().label("Name").trim().required().max(100),
80
+ price: import_yup.default.number().label("Price").typeError("Price is a required field").required().min(0)
81
+ })
82
+ ),
83
+ values: {
84
+ country: (values == null ? void 0 : values.country) || COUNTRIES[0].value,
85
+ delivery: keyOf((values == null ? void 0 : values.delivery) || import_products.DELIVERY[2]),
86
+ free: (values == null ? void 0 : values.free) ?? null,
87
+ freeOver: Number.isFinite(values == null ? void 0 : values.free),
88
+ name: (values == null ? void 0 : values.name) || "",
89
+ price: (values == null ? void 0 : values.price) ?? null
90
+ }
91
+ });
92
+ const onSubmit = async ({ country, delivery, free, freeOver, name, price }) => {
93
+ try {
94
+ const [minimum, maximum] = delivery.split("-").map(Number);
95
+ onSuccess(await (0, import_fetch.request)({
96
+ body: {
97
+ country,
98
+ delivery: {
99
+ maximum,
100
+ minimum
101
+ },
102
+ free: freeOver ? Number(free) : null,
103
+ name: name.trim(),
104
+ price: Number(price)
105
+ },
106
+ endpoint,
107
+ method: (values == null ? void 0 : values.id) ? "PUT" : "POST"
108
+ }));
109
+ } catch (error) {
110
+ onError == null ? void 0 : onError(error);
111
+ }
112
+ };
113
+ const field = (name, label, input, extra = {}) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
114
+ import_form.Controller,
115
+ {
116
+ ...{
117
+ control,
118
+ name,
119
+ render: ({ field: { onChange, value } }) => {
120
+ var _a, _b;
121
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
122
+ import_input_group.default,
123
+ {
124
+ ...{
125
+ ...extra,
126
+ error: (_b = (_a = formState == null ? void 0 : formState.errors) == null ? void 0 : _a[name]) == null ? void 0 : _b.message,
127
+ input: input({ onChange, value }),
128
+ label
129
+ }
130
+ }
131
+ );
132
+ }
133
+ }
134
+ },
135
+ name
136
+ );
137
+ const symbol = { before: (0, import_drawbridge_utils.formatCurrency)({ code: (currency || "usd").toUpperCase(), value: 0 }).replace(/[\d.,\s]/g, "") };
138
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
139
+ import_form2.default,
140
+ {
141
+ ...{
142
+ className: "relative w-full space-y-6",
143
+ onSubmit: handleSubmit(onSubmit)
144
+ },
145
+ children: [
146
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
147
+ import_fieldset.default,
148
+ {
149
+ ...{
150
+ className: "space-y-6",
151
+ disabled: formState == null ? void 0 : formState.isSubmitting
152
+ },
153
+ children: [
154
+ field("name", "Name", ({ onChange, value }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
155
+ import_input_text.default,
156
+ {
157
+ ...{
158
+ onChange,
159
+ placeholder: "Standard",
160
+ value: value || ""
161
+ }
162
+ }
163
+ )),
164
+ field("price", "Price", ({ onChange, value }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
165
+ import_input_number.default,
166
+ {
167
+ ...{
168
+ min: 0,
169
+ onChange,
170
+ step: 0.01,
171
+ value: value ?? ""
172
+ }
173
+ }
174
+ ), symbol),
175
+ field("country", "Country", ({ onChange, value }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
176
+ import_input_select.default,
177
+ {
178
+ ...{
179
+ onChange,
180
+ options: COUNTRIES,
181
+ value
182
+ }
183
+ }
184
+ )),
185
+ field("delivery", "Delivery", ({ onChange, value }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
186
+ import_input_select.default,
187
+ {
188
+ ...{
189
+ onChange,
190
+ options: import_products.DELIVERY.map((item) => ({
191
+ label: (0, import_products.deliveryText)(item),
192
+ value: keyOf(item)
193
+ })),
194
+ value
195
+ }
196
+ }
197
+ )),
198
+ field("freeOver", "Free over", ({ onChange, value }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
199
+ import_input_switch.default,
200
+ {
201
+ ...{
202
+ "aria-label": "Free over",
203
+ onChange,
204
+ value: Boolean(value)
205
+ }
206
+ }
207
+ )),
208
+ watch("freeOver") && field("free", "Order amount", ({ onChange, value }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
209
+ import_input_number.default,
210
+ {
211
+ ...{
212
+ min: 0,
213
+ onChange,
214
+ step: 0.01,
215
+ value: value ?? ""
216
+ }
217
+ }
218
+ ), symbol)
219
+ ]
220
+ }
221
+ ),
222
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
223
+ import_fieldset.default,
224
+ {
225
+ ...{
226
+ disabled: formState == null ? void 0 : formState.isSubmitting
227
+ },
228
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
229
+ import_button.default,
230
+ {
231
+ ...{
232
+ loading: formState == null ? void 0 : formState.isSubmitting,
233
+ type: "submit"
234
+ },
235
+ children: "Submit"
236
+ }
237
+ )
238
+ }
239
+ )
240
+ ]
241
+ }
242
+ );
243
+ };
244
+ const ShippingRates = ({ currency, manage, organization }) => {
245
+ var _a, _b, _c, _d;
246
+ const queryClient = (0, import_react_query.useQueryClient)();
247
+ const modal = (0, import_hooks.useModal)({
248
+ queryClient
249
+ });
250
+ const { onError, onSuccess } = (0, import_hooks.useCallbacks)({
251
+ queryClient
252
+ });
253
+ const confirm = (0, import_order_sections.useConfirm)();
254
+ const queryKey = ["rates", organization];
255
+ const base = "/organization/" + organization;
256
+ const listed = (0, import_react_query.useQuery)({
257
+ enabled: false,
258
+ queryKey: [...queryKey, 0]
259
+ });
260
+ const count = ((_b = (_a = listed.data) == null ? void 0 : _a.pageInfo) == null ? void 0 : _b.total) ?? ((_d = (_c = listed.data) == null ? void 0 : _c.items) == null ? void 0 : _d.length) ?? 0;
261
+ const saved = (response) => onSuccess(response, {
262
+ invalidate: [
263
+ {
264
+ queryKey
265
+ }
266
+ ]
267
+ });
268
+ const money = (value) => (0, import_drawbridge_utils.formatCurrency)({ code: (currency || "usd").toUpperCase(), value });
269
+ const open = (rate) => modal.open({
270
+ message: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
271
+ FormRate,
272
+ {
273
+ ...{
274
+ currency,
275
+ endpoint: (rate == null ? void 0 : rate.id) ? base + "/rate/" + rate.id : base + "/rates",
276
+ onError,
277
+ onSuccess: saved,
278
+ values: rate
279
+ }
280
+ }
281
+ ),
282
+ title: (rate == null ? void 0 : rate.id) ? "Edit rate" : "New rate"
283
+ });
284
+ const remove = (rate) => confirm({
285
+ action: "Remove",
286
+ endpoint: base + "/rate/" + rate.id,
287
+ message: "Orders already placed keep the price they recorded.",
288
+ method: "DELETE",
289
+ onSuccess: saved,
290
+ title: "Remove shipping price"
291
+ });
292
+ const cta = count < import_products.MAX_RATES && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
293
+ import_button.default,
294
+ {
295
+ ...{
296
+ "aria-label": "New rate",
297
+ disabled: !manage,
298
+ icon: import_plus.default,
299
+ inline: true,
300
+ onClick: () => open(),
301
+ size: "small",
302
+ variant: "secondary"
303
+ }
304
+ }
305
+ );
306
+ const columns = [
307
+ {
308
+ id: "name",
309
+ header: "Rate",
310
+ cell: ({ row }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
311
+ import_table_cell_title.default,
312
+ {
313
+ ...{
314
+ subtitle: (0, import_products.deliveryText)(row.original.delivery),
315
+ title: row.original.name
316
+ }
317
+ }
318
+ ),
319
+ sortable: false
320
+ },
321
+ {
322
+ id: "country",
323
+ header: "Country",
324
+ cell: ({ row }) => countryName(row.original.country),
325
+ sortable: false
326
+ },
327
+ {
328
+ id: "price",
329
+ header: "Price",
330
+ cell: ({ row }) => row.original.price ? money(row.original.price) : "Free",
331
+ sortable: false
332
+ },
333
+ {
334
+ id: "free",
335
+ header: "Free over",
336
+ cell: ({ row }) => Number.isFinite(row.original.free) ? money(row.original.free) : "\u2014",
337
+ sortable: false
338
+ }
339
+ ];
340
+ const actions = (row) => ({
341
+ controls: [
342
+ {
343
+ "aria-label": "Edit " + row.name,
344
+ disabled: !manage,
345
+ element: "button",
346
+ icon: import_pencil.default,
347
+ onClick: () => open(row),
348
+ type: "button"
349
+ },
350
+ {
351
+ "aria-label": "Remove " + row.name,
352
+ disabled: !manage,
353
+ element: "button",
354
+ icon: import_trash.default,
355
+ onClick: () => remove(row),
356
+ type: "button"
357
+ }
358
+ ]
359
+ });
360
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
361
+ import_card_section.default,
362
+ {
363
+ ...{
364
+ className: "shrink-0",
365
+ cta,
366
+ title: "Shipping"
367
+ },
368
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
369
+ import_paged.default,
370
+ {
371
+ ...{
372
+ empty: {
373
+ message: "No shipping prices",
374
+ variant: "secondary"
375
+ },
376
+ endpoint: base + "/rates",
377
+ params: {
378
+ limit: import_products.MAX_RATES,
379
+ sort: {
380
+ createdAt: 1
381
+ }
382
+ },
383
+ queryKey
384
+ },
385
+ children: ({ items }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
386
+ import_table.default,
387
+ {
388
+ ...{
389
+ actions,
390
+ columns,
391
+ data: items
392
+ }
393
+ }
394
+ )
395
+ }
396
+ )
397
+ }
398
+ );
399
+ };
400
+ var shipping_rates_default = ShippingRates;
401
+ // Annotate the CommonJS export names for ESM import in node:
402
+ 0 && (module.exports = {
403
+ FormRate
404
+ });