@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.
- package/dist/bridge/cart-drawer.js +152 -0
- package/dist/bridge/cart-drawer.mjs +123 -0
- package/dist/bridge/fields.js +278 -0
- package/dist/bridge/fields.mjs +276 -1
- package/dist/bridge/form-subdomain-checkout.js +687 -0
- package/dist/bridge/form-subdomain-checkout.mjs +665 -0
- package/dist/bridge/form-subdomain-shop-modal.js +234 -274
- package/dist/bridge/form-subdomain-shop-modal.mjs +233 -275
- package/dist/bridge/form-subdomain.js +1 -0
- package/dist/bridge/form-subdomain.mjs +2 -1
- package/dist/bridge/lib/age-gate.js +12 -0
- package/dist/bridge/lib/age-gate.mjs +11 -0
- package/dist/bridge/lib/cart.js +79 -0
- package/dist/bridge/lib/cart.mjs +48 -0
- package/dist/bridge/lib/checkout-kit.js +2 -32
- package/dist/bridge/lib/checkout-kit.mjs +2 -32
- package/dist/bridge/product-tile.js +9 -6
- package/dist/bridge/product-tile.mjs +9 -6
- package/dist/bridge/template-layout.js +237 -122
- package/dist/bridge/template-layout.mjs +237 -122
- package/dist/bridge/template-modal.js +28 -73
- package/dist/bridge/template-modal.mjs +29 -74
- package/dist/dashboard/buttons-subscription.js +1 -1
- package/dist/dashboard/buttons-subscription.mjs +1 -1
- package/dist/dashboard/campaign-form.js +7 -2
- package/dist/dashboard/campaign-form.mjs +7 -2
- package/dist/dashboard/card-order.js +22 -4
- package/dist/dashboard/card-order.mjs +22 -4
- package/dist/dashboard/embed-stripe.js +145 -0
- package/dist/dashboard/embed-stripe.mjs +116 -0
- package/dist/dashboard/form-admin-provider.js +71 -17
- package/dist/dashboard/form-admin-provider.mjs +71 -17
- package/dist/dashboard/form-file-upload.js +3 -2
- package/dist/dashboard/form-file-upload.mjs +4 -3
- package/dist/dashboard/form-organization-campaign-advertisements.js +47 -6
- package/dist/dashboard/form-organization-campaign-advertisements.mjs +47 -6
- package/dist/dashboard/form-organization-campaign-field-birthday.js +193 -0
- package/dist/dashboard/form-organization-campaign-field-birthday.mjs +164 -0
- package/dist/dashboard/form-organization-campaign-field-rating.js +246 -0
- package/dist/dashboard/form-organization-campaign-field-rating.mjs +217 -0
- package/dist/dashboard/form-organization-campaign.js +82 -0
- package/dist/dashboard/form-organization-campaign.mjs +81 -0
- package/dist/dashboard/form-organization-connection.js +48 -6
- package/dist/dashboard/form-organization-connection.mjs +48 -7
- package/dist/dashboard/form-organization-product.js +1461 -0
- package/dist/dashboard/form-organization-product.mjs +1425 -0
- package/dist/dashboard/form-organization-workflow.js +72 -1
- package/dist/dashboard/form-organization-workflow.mjs +69 -1
- package/dist/dashboard/form-otc.js +4 -5
- package/dist/dashboard/form-otc.mjs +4 -5
- package/dist/dashboard/form-stripe.js +12 -5
- package/dist/dashboard/form-stripe.mjs +12 -5
- package/dist/dashboard/input-fields.js +11 -158
- package/dist/dashboard/input-fields.mjs +11 -158
- package/dist/dashboard/input-file.js +21 -4
- package/dist/dashboard/input-file.mjs +21 -4
- package/dist/dashboard/input-gallery.js +201 -0
- package/dist/dashboard/input-gallery.mjs +172 -0
- package/dist/dashboard/lib/connection-controls.js +5 -2
- package/dist/dashboard/lib/connection-controls.mjs +3 -1
- package/dist/dashboard/lib/form-page.js +1 -1
- package/dist/dashboard/lib/form-page.mjs +1 -1
- package/dist/dashboard/lib/products.js +169 -0
- package/dist/dashboard/lib/products.mjs +135 -0
- package/dist/dashboard/lib/settings-paths.js +35 -0
- package/dist/dashboard/lib/settings-paths.mjs +11 -0
- package/dist/dashboard/lib/uppy.js +10 -1
- package/dist/dashboard/lib/uppy.mjs +11 -2
- package/dist/dashboard/order-sections.js +456 -6
- package/dist/dashboard/order-sections.mjs +453 -7
- package/dist/dashboard/provider-ui.js +9 -7
- package/dist/dashboard/provider-ui.mjs +9 -7
- package/dist/dashboard/shipping-rates.js +404 -0
- package/dist/dashboard/shipping-rates.mjs +371 -0
- package/dist/dashboard/template-buyer.js +301 -0
- package/dist/dashboard/template-buyer.mjs +267 -0
- package/dist/input-checkbox.js +28 -10
- package/dist/input-checkbox.mjs +28 -10
- package/dist/product.js +96 -24
- package/dist/product.mjs +97 -25
- package/dist/shared/lib/helpers.js +54 -6
- package/dist/shared/lib/helpers.mjs +53 -8
- package/dist/shared/order-summary.js +139 -0
- package/dist/shared/order-summary.mjs +110 -0
- package/package.json +74 -4
- package/types/bridge/cart-drawer.d.ts +31 -0
- package/types/bridge/fields.d.ts +14 -2
- package/types/bridge/form-subdomain-checkout.d.ts +20 -0
- package/types/bridge/form-subdomain-shop-modal.d.ts +27 -3
- package/types/bridge/lib/age-gate.d.ts +5 -0
- package/types/bridge/lib/cart.d.ts +44 -0
- package/types/bridge/lib/checkout-kit.d.ts +2 -10
- package/types/dashboard/card-order.d.ts +6 -0
- package/types/dashboard/embed-stripe.d.ts +25 -0
- package/types/dashboard/form-admin-provider.d.ts +9 -2
- package/types/dashboard/form-file-upload.d.ts +2 -1
- package/types/dashboard/form-organization-campaign-advertisements.d.ts +3 -0
- package/types/dashboard/form-organization-campaign-field-birthday.d.ts +31 -0
- package/types/dashboard/form-organization-campaign-field-rating.d.ts +33 -0
- package/types/dashboard/form-organization-campaign.d.ts +3 -0
- package/types/dashboard/form-organization-connection.d.ts +11 -0
- package/types/dashboard/form-organization-product.d.ts +24 -0
- package/types/dashboard/form-otc.d.ts +5 -1
- package/types/dashboard/form-stripe.d.ts +3 -2
- package/types/dashboard/input-file.d.ts +2 -0
- package/types/dashboard/input-gallery.d.ts +14 -0
- package/types/dashboard/lib/products.d.ts +14 -0
- package/types/dashboard/lib/settings-paths.d.ts +5 -0
- package/types/dashboard/order-sections.d.ts +24 -1
- package/types/dashboard/shipping-rates.d.ts +26 -0
- package/types/dashboard/template-buyer.d.ts +50 -0
- package/types/input-checkbox.d.ts +2 -0
- package/types/shared/lib/helpers.d.ts +4 -0
- package/types/shared/order-summary.d.ts +19 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment } from "react";
|
|
3
|
+
import { useFormContext, useWatch } from "react-hook-form";
|
|
4
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
5
|
+
import dynamic from "next/dynamic";
|
|
6
|
+
import InputGroup from "../input-group.mjs";
|
|
7
|
+
import { InputArrayControl, InputArraySortable } from "./input-array.mjs";
|
|
8
|
+
import InputFile from "./input-file.mjs";
|
|
9
|
+
import { useModal } from "./lib/hooks.mjs";
|
|
10
|
+
import { LoaderDynamic } from "../shared/loader.mjs";
|
|
11
|
+
import Plus from "../icons/plus.mjs";
|
|
12
|
+
import Trash from "../icons/trash.mjs";
|
|
13
|
+
const FormReposition = dynamic(() => import("./form-reposition.mjs"), { loading: () => /* @__PURE__ */ jsx(LoaderDynamic, {}), ssr: false });
|
|
14
|
+
const InputGallery = ({ endpoint, label = "Gallery", name = "gallery", onUpdate, organization, reposition: repositions = false }) => {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
const queryClient = useQueryClient();
|
|
17
|
+
const modal = useModal({ queryClient });
|
|
18
|
+
const { control, formState, getValues, setValue } = useFormContext();
|
|
19
|
+
const gallery = useWatch({ control, name }) || [];
|
|
20
|
+
const taken = () => (getValues(name) || []).map((item) => {
|
|
21
|
+
var _a2;
|
|
22
|
+
return (_a2 = item == null ? void 0 : item.file) == null ? void 0 : _a2.id;
|
|
23
|
+
}).filter(Boolean);
|
|
24
|
+
const change = (path, value) => {
|
|
25
|
+
setValue(path, value, { shouldDirty: true });
|
|
26
|
+
onUpdate == null ? void 0 : onUpdate(getValues());
|
|
27
|
+
};
|
|
28
|
+
const reposition = (index) => {
|
|
29
|
+
var _a2, _b2;
|
|
30
|
+
const item = getValues(name + "." + index);
|
|
31
|
+
modal.open({
|
|
32
|
+
message: /* @__PURE__ */ jsx(
|
|
33
|
+
FormReposition,
|
|
34
|
+
{
|
|
35
|
+
...{
|
|
36
|
+
file: item == null ? void 0 : item.file,
|
|
37
|
+
onDone: (position) => {
|
|
38
|
+
change(name + "." + index + ".position", position);
|
|
39
|
+
modal.close();
|
|
40
|
+
},
|
|
41
|
+
page: getValues(),
|
|
42
|
+
position: item == null ? void 0 : item.position
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
),
|
|
46
|
+
title: ((_b2 = (_a2 = item == null ? void 0 : item.file) == null ? void 0 : _a2.mimetype) == null ? void 0 : _b2.includes("video")) ? "Reposition video" : "Reposition photo"
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
|
|
50
|
+
InputGroup,
|
|
51
|
+
{
|
|
52
|
+
...{
|
|
53
|
+
error: (_b = (_a = formState == null ? void 0 : formState.errors) == null ? void 0 : _a[name]) == null ? void 0 : _b.message,
|
|
54
|
+
input: /* @__PURE__ */ jsx(
|
|
55
|
+
InputArraySortable,
|
|
56
|
+
{
|
|
57
|
+
...{
|
|
58
|
+
control,
|
|
59
|
+
"data-guide": "form-input-gallery",
|
|
60
|
+
empty: "Gallery is empty",
|
|
61
|
+
name,
|
|
62
|
+
onSort: () => onUpdate == null ? void 0 : onUpdate(getValues()),
|
|
63
|
+
renderButton: (append) => /* @__PURE__ */ jsx(
|
|
64
|
+
InputFile,
|
|
65
|
+
{
|
|
66
|
+
...{
|
|
67
|
+
button: {
|
|
68
|
+
icon: Plus,
|
|
69
|
+
text: "Add gallery item"
|
|
70
|
+
},
|
|
71
|
+
endpoint,
|
|
72
|
+
filters: {
|
|
73
|
+
id: {
|
|
74
|
+
$nin: taken()
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
onChange: (response) => {
|
|
78
|
+
append({ file: response });
|
|
79
|
+
onUpdate == null ? void 0 : onUpdate(getValues());
|
|
80
|
+
},
|
|
81
|
+
organization,
|
|
82
|
+
nullable: false,
|
|
83
|
+
value: null,
|
|
84
|
+
type: "media"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
),
|
|
88
|
+
renderControls: ({ index, remove }) => [
|
|
89
|
+
/* @__PURE__ */ jsx(
|
|
90
|
+
InputArrayControl,
|
|
91
|
+
{
|
|
92
|
+
...{
|
|
93
|
+
onClick: () => {
|
|
94
|
+
remove(index);
|
|
95
|
+
onUpdate == null ? void 0 : onUpdate(getValues());
|
|
96
|
+
},
|
|
97
|
+
icon: Trash
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
"gallery-control-remove-" + index
|
|
101
|
+
)
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
children: ({ field, handle, index, update }) => {
|
|
105
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
|
|
106
|
+
const item = gallery[index] || field;
|
|
107
|
+
const editable = /^(image|video)\//.test(((_a2 = item == null ? void 0 : item.file) == null ? void 0 : _a2.mimetype) || "");
|
|
108
|
+
return /* @__PURE__ */ jsxs(
|
|
109
|
+
"div",
|
|
110
|
+
{
|
|
111
|
+
...{
|
|
112
|
+
className: "flex items-center min-w-0 flex-1 space-x-3"
|
|
113
|
+
},
|
|
114
|
+
children: [
|
|
115
|
+
handle,
|
|
116
|
+
/* @__PURE__ */ jsx(
|
|
117
|
+
InputGroup,
|
|
118
|
+
{
|
|
119
|
+
...{
|
|
120
|
+
error: ((_e = (_d = (_c = (_b2 = formState == null ? void 0 : formState.errors) == null ? void 0 : _b2[name]) == null ? void 0 : _c[index]) == null ? void 0 : _d.file) == null ? void 0 : _e.message) || ((_i = (_h = (_g = (_f = formState == null ? void 0 : formState.errors) == null ? void 0 : _f[name]) == null ? void 0 : _g[index]) == null ? void 0 : _h.description) == null ? void 0 : _i.message),
|
|
121
|
+
input: /* @__PURE__ */ jsx(
|
|
122
|
+
InputFile,
|
|
123
|
+
{
|
|
124
|
+
...{
|
|
125
|
+
// The item's own description and crop.
|
|
126
|
+
description: item == null ? void 0 : item.description,
|
|
127
|
+
edited: Boolean(item == null ? void 0 : item.position),
|
|
128
|
+
endpoint,
|
|
129
|
+
filters: {
|
|
130
|
+
id: {
|
|
131
|
+
$nin: taken()
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
// Another file is another item: no description, no crop.
|
|
135
|
+
onChange: (response) => {
|
|
136
|
+
update(
|
|
137
|
+
index,
|
|
138
|
+
{
|
|
139
|
+
file: response
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
onUpdate == null ? void 0 : onUpdate(getValues());
|
|
143
|
+
},
|
|
144
|
+
onDescription: (text) => change(name + "." + index + ".description", text),
|
|
145
|
+
...repositions && editable && {
|
|
146
|
+
onEdit: () => reposition(index)
|
|
147
|
+
},
|
|
148
|
+
organization,
|
|
149
|
+
nullable: false,
|
|
150
|
+
value: item == null ? void 0 : item.file,
|
|
151
|
+
type: "media"
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
)
|
|
158
|
+
]
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
),
|
|
164
|
+
label
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
) });
|
|
168
|
+
};
|
|
169
|
+
var input_gallery_default = InputGallery;
|
|
170
|
+
export {
|
|
171
|
+
input_gallery_default as default
|
|
172
|
+
};
|
|
@@ -18,7 +18,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
18
18
|
var connection_controls_exports = {};
|
|
19
19
|
__export(connection_controls_exports, {
|
|
20
20
|
connectionControls: () => connectionControls,
|
|
21
|
-
isConnected: () => isConnected
|
|
21
|
+
isConnected: () => isConnected,
|
|
22
|
+
savable: () => savable
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(connection_controls_exports);
|
|
24
25
|
var import_reconnect = require("@drawbridge/drawbridge-utils/connections/reconnect");
|
|
@@ -31,8 +32,10 @@ const connectionControls = (connection) => {
|
|
|
31
32
|
remove: (connection == null ? void 0 : connection.id) ? ((_a = connection == null ? void 0 : connection.connect) == null ? void 0 : _a.manage) && !paused ? "manage" : "disconnect" : null
|
|
32
33
|
};
|
|
33
34
|
};
|
|
35
|
+
const savable = ({ actions, connected, inputs }) => !connected || (inputs || []).length > 0 || Boolean(actions == null ? void 0 : actions.update);
|
|
34
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
35
37
|
0 && (module.exports = {
|
|
36
38
|
connectionControls,
|
|
37
|
-
isConnected
|
|
39
|
+
isConnected,
|
|
40
|
+
savable
|
|
38
41
|
});
|
|
@@ -8,7 +8,9 @@ const connectionControls = (connection) => {
|
|
|
8
8
|
remove: (connection == null ? void 0 : connection.id) ? ((_a = connection == null ? void 0 : connection.connect) == null ? void 0 : _a.manage) && !paused ? "manage" : "disconnect" : null
|
|
9
9
|
};
|
|
10
10
|
};
|
|
11
|
+
const savable = ({ actions, connected, inputs }) => !connected || (inputs || []).length > 0 || Boolean(actions == null ? void 0 : actions.update);
|
|
11
12
|
export {
|
|
12
13
|
connectionControls,
|
|
13
|
-
isConnected
|
|
14
|
+
isConnected,
|
|
15
|
+
savable
|
|
14
16
|
};
|
|
@@ -51,7 +51,7 @@ const MAX_ADS = 5;
|
|
|
51
51
|
const adsLimit = (count) => count >= MAX_ADS ? "A campaign can have up to " + MAX_ADS + " advertisements." : null;
|
|
52
52
|
const advertisementsKey = (params) => ["campaign-advertisements", params == null ? void 0 : params.organization, params == null ? void 0 : params.campaign];
|
|
53
53
|
const AFTER = ["message", "missions", "advertisements"];
|
|
54
|
-
const once = ["email", "name", "note", "phone", "pickup"];
|
|
54
|
+
const once = ["birthday", "email", "name", "note", "phone", "pickup"];
|
|
55
55
|
const addedOnce = (slug, keys = []) => once.includes(slug) && (keys || []).includes(slug);
|
|
56
56
|
const planLocked = (section) => Boolean(section == null ? void 0 : section.task) && Boolean((section == null ? void 0 : section.locked) || (section == null ? void 0 : section.disabled));
|
|
57
57
|
const giveawayLocked = (section) => (section == null ? void 0 : section.type) === "order" && Boolean(section == null ? void 0 : section.giveaway);
|
|
@@ -4,7 +4,7 @@ const MAX_ADS = 5;
|
|
|
4
4
|
const adsLimit = (count) => count >= MAX_ADS ? "A campaign can have up to " + MAX_ADS + " advertisements." : null;
|
|
5
5
|
const advertisementsKey = (params) => ["campaign-advertisements", params == null ? void 0 : params.organization, params == null ? void 0 : params.campaign];
|
|
6
6
|
const AFTER = ["message", "missions", "advertisements"];
|
|
7
|
-
const once = ["email", "name", "note", "phone", "pickup"];
|
|
7
|
+
const once = ["birthday", "email", "name", "note", "phone", "pickup"];
|
|
8
8
|
const addedOnce = (slug, keys = []) => once.includes(slug) && (keys || []).includes(slug);
|
|
9
9
|
const planLocked = (section) => Boolean(section == null ? void 0 : section.task) && Boolean((section == null ? void 0 : section.locked) || (section == null ? void 0 : section.disabled));
|
|
10
10
|
const giveawayLocked = (section) => (section == null ? void 0 : section.type) === "order" && Boolean(section == null ? void 0 : section.giveaway);
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var products_exports = {};
|
|
19
|
+
__export(products_exports, {
|
|
20
|
+
CHECKOUT_LABELS: () => CHECKOUT_LABELS,
|
|
21
|
+
VARIANT_DEFAULTS: () => VARIANT_DEFAULTS,
|
|
22
|
+
checkoutChange: () => checkoutChange,
|
|
23
|
+
downloadsText: () => downloadsText,
|
|
24
|
+
moneyOf: () => moneyOf,
|
|
25
|
+
priceText: () => priceText,
|
|
26
|
+
productBody: () => productBody,
|
|
27
|
+
sellingWarning: () => sellingWarning,
|
|
28
|
+
totalQuantity: () => totalQuantity,
|
|
29
|
+
variantCount: () => variantCount,
|
|
30
|
+
variantRows: () => variantRows,
|
|
31
|
+
variantsFor: () => variantsFor
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(products_exports);
|
|
34
|
+
var import_products = require("@drawbridge/drawbridge-utils/products");
|
|
35
|
+
var import_drawbridge_utils = require("@drawbridge/drawbridge-utils");
|
|
36
|
+
const CHECKOUT_LABELS = Object.freeze({
|
|
37
|
+
shopify: "Shopify",
|
|
38
|
+
stripe: "Stripe"
|
|
39
|
+
});
|
|
40
|
+
const VARIANT_DEFAULTS = Object.freeze({
|
|
41
|
+
inventoryQuantity: null,
|
|
42
|
+
price: null,
|
|
43
|
+
requiresShipping: true,
|
|
44
|
+
sale: null,
|
|
45
|
+
sku: null,
|
|
46
|
+
taxable: true
|
|
47
|
+
});
|
|
48
|
+
const variantsFor = (options, variants) => (0, import_products.buildVariants)({
|
|
49
|
+
defaults: VARIANT_DEFAULTS,
|
|
50
|
+
mintId: () => void 0,
|
|
51
|
+
options,
|
|
52
|
+
variants
|
|
53
|
+
});
|
|
54
|
+
const moneyOf = (value, currency) => (0, import_drawbridge_utils.formatCurrency)({
|
|
55
|
+
code: currency || "USD",
|
|
56
|
+
value
|
|
57
|
+
});
|
|
58
|
+
const priceText = (variants = []) => {
|
|
59
|
+
var _a;
|
|
60
|
+
const range = (0, import_products.priceRange)(variants);
|
|
61
|
+
if (!range) return "\u2014";
|
|
62
|
+
const currency = (_a = variants[0]) == null ? void 0 : _a.currency;
|
|
63
|
+
return range.min === range.max ? moneyOf(range.min, currency) : moneyOf(range.min, currency) + " \u2013 " + moneyOf(range.max, currency);
|
|
64
|
+
};
|
|
65
|
+
const variantRows = ({ expanded = [], group, options = [], variants = [] }) => {
|
|
66
|
+
const indexed = variants.map((variant, index) => ({
|
|
67
|
+
...variant,
|
|
68
|
+
index
|
|
69
|
+
}));
|
|
70
|
+
if (options.length < 2) return indexed;
|
|
71
|
+
const position = Math.max(0, options.findIndex((option) => option.name === group));
|
|
72
|
+
return options[position].values.flatMap((value) => {
|
|
73
|
+
const children = indexed.filter((variant) => {
|
|
74
|
+
var _a, _b;
|
|
75
|
+
return ((_b = (_a = variant.selectedOptions) == null ? void 0 : _a[position]) == null ? void 0 : _b.value) === value;
|
|
76
|
+
});
|
|
77
|
+
if (!children.length) return [];
|
|
78
|
+
const prices = children.map((variant) => variant.price);
|
|
79
|
+
const same = prices.every((price) => price === prices[0]);
|
|
80
|
+
return [
|
|
81
|
+
{
|
|
82
|
+
children: children.map((variant) => variant.index),
|
|
83
|
+
group: true,
|
|
84
|
+
id: "group-" + value,
|
|
85
|
+
inventoryQuantity: children.reduce((sum, variant) => sum + (variant.inventoryQuantity || 0), 0),
|
|
86
|
+
price: same ? prices[0] : null,
|
|
87
|
+
range: same ? null : priceText(children),
|
|
88
|
+
title: value,
|
|
89
|
+
variants: children.length
|
|
90
|
+
},
|
|
91
|
+
...expanded.includes(value) ? children.map((variant) => ({
|
|
92
|
+
...variant,
|
|
93
|
+
child: true,
|
|
94
|
+
title: (variant.selectedOptions || []).filter((item, key) => key !== position).map((item) => item.value).join(" / ")
|
|
95
|
+
})) : []
|
|
96
|
+
];
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
const totalQuantity = (variants = []) => variants.reduce((sum, variant) => sum + ((variant == null ? void 0 : variant.inventoryQuantity) || 0), 0);
|
|
100
|
+
const variantCount = (options = []) => options.reduce((total, option) => total * Math.max(1, ((option == null ? void 0 : option.values) || []).length), 1);
|
|
101
|
+
const stock = (value) => Number.isFinite(value) ? value : null;
|
|
102
|
+
const stockChanged = (variant, loaded) => {
|
|
103
|
+
const was = variant.id ? (loaded || []).find((item) => (item == null ? void 0 : item.id) === variant.id) : null;
|
|
104
|
+
return !was || stock(was.inventoryQuantity) !== stock(variant.inventoryQuantity);
|
|
105
|
+
};
|
|
106
|
+
const productBody = ({ description, gallery = [], options, recommendations = [], status, title, variants }, loaded = []) => ({
|
|
107
|
+
description: description || null,
|
|
108
|
+
images: gallery.filter((item) => {
|
|
109
|
+
var _a;
|
|
110
|
+
return ((_a = item == null ? void 0 : item.file) == null ? void 0 : _a.id) || typeof (item == null ? void 0 : item.file) === "string";
|
|
111
|
+
}).map((item) => {
|
|
112
|
+
var _a;
|
|
113
|
+
return {
|
|
114
|
+
description: item.description || null,
|
|
115
|
+
file: ((_a = item.file) == null ? void 0 : _a.id) || item.file
|
|
116
|
+
};
|
|
117
|
+
}),
|
|
118
|
+
options,
|
|
119
|
+
// @story products/recommended
|
|
120
|
+
// The recommended products' ids, in the merchant's order.
|
|
121
|
+
recommendations: (recommendations || []).map((item) => item == null ? void 0 : item.id).filter(Boolean),
|
|
122
|
+
status,
|
|
123
|
+
title,
|
|
124
|
+
variants: variants.map((variant) => {
|
|
125
|
+
var _a;
|
|
126
|
+
return {
|
|
127
|
+
// @story products/digital-file
|
|
128
|
+
// The variant's digital file by its id, or null once removed.
|
|
129
|
+
file: ((_a = variant.file) == null ? void 0 : _a.id) || (typeof variant.file === "string" ? variant.file : null),
|
|
130
|
+
id: variant.id || null,
|
|
131
|
+
...stockChanged(variant, loaded) && {
|
|
132
|
+
inventoryQuantity: Number.isFinite(variant.inventoryQuantity) ? variant.inventoryQuantity : null
|
|
133
|
+
},
|
|
134
|
+
price: Number.isFinite(variant.price) ? variant.price : null,
|
|
135
|
+
requiresShipping: variant.requiresShipping !== false,
|
|
136
|
+
sale: Number.isFinite(variant.sale) ? variant.sale : null,
|
|
137
|
+
selectedOptions: variant.selectedOptions || [],
|
|
138
|
+
sku: variant.sku || null,
|
|
139
|
+
taxable: variant.taxable !== false
|
|
140
|
+
};
|
|
141
|
+
})
|
|
142
|
+
});
|
|
143
|
+
const downloadsText = (count) => count > 0 ? (0, import_drawbridge_utils.formatNumber)(count) + (count === 1 ? " download" : " downloads") : "Not downloaded yet";
|
|
144
|
+
const checkoutChange = ({ ads = 0, from, products = 0, to }) => ({
|
|
145
|
+
message: "This campaign will sell from " + CHECKOUT_LABELS[to] + ". Only " + CHECKOUT_LABELS[to] + " products can be added to it after this.",
|
|
146
|
+
warnings: [
|
|
147
|
+
products > 0 && "Its " + products + " " + CHECKOUT_LABELS[from] + " product" + (products === 1 ? "" : "s") + " will be removed from this campaign, and any open carts on it will be emptied.",
|
|
148
|
+
// Sync locks every unlocked ad made from the checkout left, attached or
|
|
149
|
+
// not, so the card names the checkout's products, never "those" ( 2026-11-20
|
|
150
|
+
// review ).
|
|
151
|
+
ads > 0 && "Its " + ads + " advertisement" + (ads === 1 ? "" : "s") + " made from " + CHECKOUT_LABELS[from] + " products will be drafted, and can't be edited."
|
|
152
|
+
].filter(Boolean)
|
|
153
|
+
});
|
|
154
|
+
const sellingWarning = ({ selling = 0, slug }) => selling > 0 ? selling + (selling === 1 ? " campaign sells" : " campaigns sell") + " through " + CHECKOUT_LABELS[slug] + ". " + (selling === 1 ? "Its shop stops" : "Their shops stop") + " selling until you connect again." : null;
|
|
155
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
156
|
+
0 && (module.exports = {
|
|
157
|
+
CHECKOUT_LABELS,
|
|
158
|
+
VARIANT_DEFAULTS,
|
|
159
|
+
checkoutChange,
|
|
160
|
+
downloadsText,
|
|
161
|
+
moneyOf,
|
|
162
|
+
priceText,
|
|
163
|
+
productBody,
|
|
164
|
+
sellingWarning,
|
|
165
|
+
totalQuantity,
|
|
166
|
+
variantCount,
|
|
167
|
+
variantRows,
|
|
168
|
+
variantsFor
|
|
169
|
+
});
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { buildVariants, priceRange } from "@drawbridge/drawbridge-utils/products";
|
|
2
|
+
import { formatCurrency, formatNumber } from "@drawbridge/drawbridge-utils";
|
|
3
|
+
const CHECKOUT_LABELS = Object.freeze({
|
|
4
|
+
shopify: "Shopify",
|
|
5
|
+
stripe: "Stripe"
|
|
6
|
+
});
|
|
7
|
+
const VARIANT_DEFAULTS = Object.freeze({
|
|
8
|
+
inventoryQuantity: null,
|
|
9
|
+
price: null,
|
|
10
|
+
requiresShipping: true,
|
|
11
|
+
sale: null,
|
|
12
|
+
sku: null,
|
|
13
|
+
taxable: true
|
|
14
|
+
});
|
|
15
|
+
const variantsFor = (options, variants) => buildVariants({
|
|
16
|
+
defaults: VARIANT_DEFAULTS,
|
|
17
|
+
mintId: () => void 0,
|
|
18
|
+
options,
|
|
19
|
+
variants
|
|
20
|
+
});
|
|
21
|
+
const moneyOf = (value, currency) => formatCurrency({
|
|
22
|
+
code: currency || "USD",
|
|
23
|
+
value
|
|
24
|
+
});
|
|
25
|
+
const priceText = (variants = []) => {
|
|
26
|
+
var _a;
|
|
27
|
+
const range = priceRange(variants);
|
|
28
|
+
if (!range) return "\u2014";
|
|
29
|
+
const currency = (_a = variants[0]) == null ? void 0 : _a.currency;
|
|
30
|
+
return range.min === range.max ? moneyOf(range.min, currency) : moneyOf(range.min, currency) + " \u2013 " + moneyOf(range.max, currency);
|
|
31
|
+
};
|
|
32
|
+
const variantRows = ({ expanded = [], group, options = [], variants = [] }) => {
|
|
33
|
+
const indexed = variants.map((variant, index) => ({
|
|
34
|
+
...variant,
|
|
35
|
+
index
|
|
36
|
+
}));
|
|
37
|
+
if (options.length < 2) return indexed;
|
|
38
|
+
const position = Math.max(0, options.findIndex((option) => option.name === group));
|
|
39
|
+
return options[position].values.flatMap((value) => {
|
|
40
|
+
const children = indexed.filter((variant) => {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
return ((_b = (_a = variant.selectedOptions) == null ? void 0 : _a[position]) == null ? void 0 : _b.value) === value;
|
|
43
|
+
});
|
|
44
|
+
if (!children.length) return [];
|
|
45
|
+
const prices = children.map((variant) => variant.price);
|
|
46
|
+
const same = prices.every((price) => price === prices[0]);
|
|
47
|
+
return [
|
|
48
|
+
{
|
|
49
|
+
children: children.map((variant) => variant.index),
|
|
50
|
+
group: true,
|
|
51
|
+
id: "group-" + value,
|
|
52
|
+
inventoryQuantity: children.reduce((sum, variant) => sum + (variant.inventoryQuantity || 0), 0),
|
|
53
|
+
price: same ? prices[0] : null,
|
|
54
|
+
range: same ? null : priceText(children),
|
|
55
|
+
title: value,
|
|
56
|
+
variants: children.length
|
|
57
|
+
},
|
|
58
|
+
...expanded.includes(value) ? children.map((variant) => ({
|
|
59
|
+
...variant,
|
|
60
|
+
child: true,
|
|
61
|
+
title: (variant.selectedOptions || []).filter((item, key) => key !== position).map((item) => item.value).join(" / ")
|
|
62
|
+
})) : []
|
|
63
|
+
];
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
const totalQuantity = (variants = []) => variants.reduce((sum, variant) => sum + ((variant == null ? void 0 : variant.inventoryQuantity) || 0), 0);
|
|
67
|
+
const variantCount = (options = []) => options.reduce((total, option) => total * Math.max(1, ((option == null ? void 0 : option.values) || []).length), 1);
|
|
68
|
+
const stock = (value) => Number.isFinite(value) ? value : null;
|
|
69
|
+
const stockChanged = (variant, loaded) => {
|
|
70
|
+
const was = variant.id ? (loaded || []).find((item) => (item == null ? void 0 : item.id) === variant.id) : null;
|
|
71
|
+
return !was || stock(was.inventoryQuantity) !== stock(variant.inventoryQuantity);
|
|
72
|
+
};
|
|
73
|
+
const productBody = ({ description, gallery = [], options, recommendations = [], status, title, variants }, loaded = []) => ({
|
|
74
|
+
description: description || null,
|
|
75
|
+
images: gallery.filter((item) => {
|
|
76
|
+
var _a;
|
|
77
|
+
return ((_a = item == null ? void 0 : item.file) == null ? void 0 : _a.id) || typeof (item == null ? void 0 : item.file) === "string";
|
|
78
|
+
}).map((item) => {
|
|
79
|
+
var _a;
|
|
80
|
+
return {
|
|
81
|
+
description: item.description || null,
|
|
82
|
+
file: ((_a = item.file) == null ? void 0 : _a.id) || item.file
|
|
83
|
+
};
|
|
84
|
+
}),
|
|
85
|
+
options,
|
|
86
|
+
// @story products/recommended
|
|
87
|
+
// The recommended products' ids, in the merchant's order.
|
|
88
|
+
recommendations: (recommendations || []).map((item) => item == null ? void 0 : item.id).filter(Boolean),
|
|
89
|
+
status,
|
|
90
|
+
title,
|
|
91
|
+
variants: variants.map((variant) => {
|
|
92
|
+
var _a;
|
|
93
|
+
return {
|
|
94
|
+
// @story products/digital-file
|
|
95
|
+
// The variant's digital file by its id, or null once removed.
|
|
96
|
+
file: ((_a = variant.file) == null ? void 0 : _a.id) || (typeof variant.file === "string" ? variant.file : null),
|
|
97
|
+
id: variant.id || null,
|
|
98
|
+
...stockChanged(variant, loaded) && {
|
|
99
|
+
inventoryQuantity: Number.isFinite(variant.inventoryQuantity) ? variant.inventoryQuantity : null
|
|
100
|
+
},
|
|
101
|
+
price: Number.isFinite(variant.price) ? variant.price : null,
|
|
102
|
+
requiresShipping: variant.requiresShipping !== false,
|
|
103
|
+
sale: Number.isFinite(variant.sale) ? variant.sale : null,
|
|
104
|
+
selectedOptions: variant.selectedOptions || [],
|
|
105
|
+
sku: variant.sku || null,
|
|
106
|
+
taxable: variant.taxable !== false
|
|
107
|
+
};
|
|
108
|
+
})
|
|
109
|
+
});
|
|
110
|
+
const downloadsText = (count) => count > 0 ? formatNumber(count) + (count === 1 ? " download" : " downloads") : "Not downloaded yet";
|
|
111
|
+
const checkoutChange = ({ ads = 0, from, products = 0, to }) => ({
|
|
112
|
+
message: "This campaign will sell from " + CHECKOUT_LABELS[to] + ". Only " + CHECKOUT_LABELS[to] + " products can be added to it after this.",
|
|
113
|
+
warnings: [
|
|
114
|
+
products > 0 && "Its " + products + " " + CHECKOUT_LABELS[from] + " product" + (products === 1 ? "" : "s") + " will be removed from this campaign, and any open carts on it will be emptied.",
|
|
115
|
+
// Sync locks every unlocked ad made from the checkout left, attached or
|
|
116
|
+
// not, so the card names the checkout's products, never "those" ( 2026-11-20
|
|
117
|
+
// review ).
|
|
118
|
+
ads > 0 && "Its " + ads + " advertisement" + (ads === 1 ? "" : "s") + " made from " + CHECKOUT_LABELS[from] + " products will be drafted, and can't be edited."
|
|
119
|
+
].filter(Boolean)
|
|
120
|
+
});
|
|
121
|
+
const sellingWarning = ({ selling = 0, slug }) => selling > 0 ? selling + (selling === 1 ? " campaign sells" : " campaigns sell") + " through " + CHECKOUT_LABELS[slug] + ". " + (selling === 1 ? "Its shop stops" : "Their shops stop") + " selling until you connect again." : null;
|
|
122
|
+
export {
|
|
123
|
+
CHECKOUT_LABELS,
|
|
124
|
+
VARIANT_DEFAULTS,
|
|
125
|
+
checkoutChange,
|
|
126
|
+
downloadsText,
|
|
127
|
+
moneyOf,
|
|
128
|
+
priceText,
|
|
129
|
+
productBody,
|
|
130
|
+
sellingWarning,
|
|
131
|
+
totalQuantity,
|
|
132
|
+
variantCount,
|
|
133
|
+
variantRows,
|
|
134
|
+
variantsFor
|
|
135
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var settings_paths_exports = {};
|
|
19
|
+
__export(settings_paths_exports, {
|
|
20
|
+
nestPaths: () => nestPaths,
|
|
21
|
+
readPath: () => readPath
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(settings_paths_exports);
|
|
24
|
+
const readPath = (object, key) => String(key).split(".").reduce((node, part) => node == null ? void 0 : node[part], object);
|
|
25
|
+
const nestPaths = (pairs) => pairs.reduce((tree, [key, value]) => {
|
|
26
|
+
const parts = String(key).split(".");
|
|
27
|
+
const last = parts.pop();
|
|
28
|
+
parts.reduce((branch, part) => branch[part] ??= {}, tree)[last] = value;
|
|
29
|
+
return tree;
|
|
30
|
+
}, {});
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
nestPaths,
|
|
34
|
+
readPath
|
|
35
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const readPath = (object, key) => String(key).split(".").reduce((node, part) => node == null ? void 0 : node[part], object);
|
|
2
|
+
const nestPaths = (pairs) => pairs.reduce((tree, [key, value]) => {
|
|
3
|
+
const parts = String(key).split(".");
|
|
4
|
+
const last = parts.pop();
|
|
5
|
+
parts.reduce((branch, part) => branch[part] ??= {}, tree)[last] = value;
|
|
6
|
+
return tree;
|
|
7
|
+
}, {});
|
|
8
|
+
export {
|
|
9
|
+
nestPaths,
|
|
10
|
+
readPath
|
|
11
|
+
};
|
|
@@ -65,7 +65,11 @@ const create = async ({
|
|
|
65
65
|
// Derived from the allowlist the api validates against, so a wrong
|
|
66
66
|
// type is refused here for the same reason it would be refused
|
|
67
67
|
// there — before two gigabytes move rather than after.
|
|
68
|
-
|
|
68
|
+
//
|
|
69
|
+
// @story products/digital-file
|
|
70
|
+
// A digital file by its extension: a zip's mime differs by system
|
|
71
|
+
// ( application/x-zip-compressed on Windows ).
|
|
72
|
+
allowedFileTypes: type === "digital" ? (0, import_helpers.fileTypes)(type).map((extension) => "." + extension) : (0, import_helpers.fileMimes)(type),
|
|
69
73
|
// One number for every type: only a video is large enough to reach
|
|
70
74
|
// this path, and lib/yup.js enforces the per-type cap before a file
|
|
71
75
|
// gets here. Defaults to the shared ceiling the api enforces; an
|
|
@@ -108,6 +112,11 @@ const create = async ({
|
|
|
108
112
|
bytes: file == null ? void 0 : file.size,
|
|
109
113
|
extension,
|
|
110
114
|
filename: file == null ? void 0 : file.name,
|
|
115
|
+
// @story products/digital-file
|
|
116
|
+
// A digital file is stored private, out of the Library.
|
|
117
|
+
...type === "digital" && {
|
|
118
|
+
private: true
|
|
119
|
+
},
|
|
111
120
|
type: primary
|
|
112
121
|
},
|
|
113
122
|
endpoint: url(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { megabyte } from "@drawbridge/drawbridge-utils";
|
|
2
2
|
import { uploadPartSize } from "@drawbridge/drawbridge-utils/upload";
|
|
3
3
|
import { request } from "@drawbridge/drawbridge-utils/fetch";
|
|
4
|
-
import { fileMimes, fileParts, fileSizeLimits } from "../../shared/lib/helpers.mjs";
|
|
4
|
+
import { fileMimes, fileParts, fileSizeLimits, fileTypes } from "../../shared/lib/helpers.mjs";
|
|
5
5
|
const partSizeFor = uploadPartSize;
|
|
6
6
|
const guard = (event) => {
|
|
7
7
|
if (!isUploading(instance)) return;
|
|
@@ -30,7 +30,11 @@ const create = async ({
|
|
|
30
30
|
// Derived from the allowlist the api validates against, so a wrong
|
|
31
31
|
// type is refused here for the same reason it would be refused
|
|
32
32
|
// there — before two gigabytes move rather than after.
|
|
33
|
-
|
|
33
|
+
//
|
|
34
|
+
// @story products/digital-file
|
|
35
|
+
// A digital file by its extension: a zip's mime differs by system
|
|
36
|
+
// ( application/x-zip-compressed on Windows ).
|
|
37
|
+
allowedFileTypes: type === "digital" ? fileTypes(type).map((extension) => "." + extension) : fileMimes(type),
|
|
34
38
|
// One number for every type: only a video is large enough to reach
|
|
35
39
|
// this path, and lib/yup.js enforces the per-type cap before a file
|
|
36
40
|
// gets here. Defaults to the shared ceiling the api enforces; an
|
|
@@ -73,6 +77,11 @@ const create = async ({
|
|
|
73
77
|
bytes: file == null ? void 0 : file.size,
|
|
74
78
|
extension,
|
|
75
79
|
filename: file == null ? void 0 : file.name,
|
|
80
|
+
// @story products/digital-file
|
|
81
|
+
// A digital file is stored private, out of the Library.
|
|
82
|
+
...type === "digital" && {
|
|
83
|
+
private: true
|
|
84
|
+
},
|
|
76
85
|
type: primary
|
|
77
86
|
},
|
|
78
87
|
endpoint: url(),
|