@myparcel-dev/pdk-admin-js 1.13.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.
@@ -0,0 +1,258 @@
1
+ import { r as ref, c as computed, w as watch, d as defineComponent, k as toRefs, h as useAdminConfig, l as useLocalizedFormatter, n as useQueryStore, p as useShipmentData, q as useVModel, F as Format, s as resolveComponent, o as openBlock, a as createBlock, v as withCtx, x as createVNode, b as unref, y as isRef, z as _sfc_main$3, B as _sfc_main$4, C as createBaseVNode, D as toDisplayString, E as normalizeClass, G as useOrderData, t as toValue, H as useLanguage, I as _sfc_main$5, J as createTextVNode, K as createElementBlock, L as Fragment, M as renderList, O as instantiateActions, P as toRaw, Q as shipmentActions, R as AdminIcon, e as createCommentVNode, S as isDef } from "./index-Btt7GCnO.js";
2
+ const useBulkSelectCheckbox = (options, emit) => {
3
+ const selected = ref({});
4
+ const bulkModel = computed({
5
+ get() {
6
+ return selected.value;
7
+ },
8
+ set(values) {
9
+ selected.value = values;
10
+ }
11
+ });
12
+ watch(
13
+ bulkModel,
14
+ (value) => {
15
+ emit("select", value);
16
+ },
17
+ { deep: true }
18
+ );
19
+ return {
20
+ bulkModel,
21
+ bulkOptions: options
22
+ };
23
+ };
24
+ const createClasses = (param) => {
25
+ return param.reduce((acc, { key, value }) => {
26
+ if (key && value) {
27
+ acc[key] = value;
28
+ }
29
+ return acc;
30
+ }, {});
31
+ };
32
+ const _hoisted_1 = ["title", "textContent"];
33
+ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
34
+ __name: "OrderShipmentsTableRow",
35
+ props: {
36
+ shipmentId: {},
37
+ modelValue: { type: Boolean }
38
+ },
39
+ emits: ["update:modelValue"],
40
+ setup(__props, { emit: __emit }) {
41
+ const props = __props;
42
+ const { shipmentId } = toRefs(props);
43
+ const emit = __emit;
44
+ const config = useAdminConfig();
45
+ const formatter = useLocalizedFormatter();
46
+ const queryStore = useQueryStore();
47
+ queryStore.registerShipmentQueries(shipmentId);
48
+ const { loading, actions, shipment } = useShipmentData(shipmentId);
49
+ const selected = useVModel(props, void 0, emit);
50
+ const checkboxElement = {
51
+ id: `shipment_${shipmentId.value}`,
52
+ ref: selected,
53
+ form: {
54
+ name: `shipment-${shipmentId.value}`
55
+ }
56
+ };
57
+ const shipmentUpdatedAt = computed(() => {
58
+ return shipment.value.updated ? formatter.format(Format.DateRelative, shipment.value.updated) : "–";
59
+ });
60
+ const classes = computed(() => {
61
+ var _a;
62
+ return createClasses([
63
+ {
64
+ key: (_a = config == null ? void 0 : config.cssUtilities) == null ? void 0 : _a.animationLoading,
65
+ value: loading.value
66
+ }
67
+ ]);
68
+ });
69
+ return (_ctx, _cache) => {
70
+ const _component_PdkCheckboxInput = resolveComponent("PdkCheckboxInput");
71
+ const _component_PdkTableCol = resolveComponent("PdkTableCol");
72
+ const _component_PdkDropdownButton = resolveComponent("PdkDropdownButton");
73
+ const _component_PdkTableRow = resolveComponent("PdkTableRow");
74
+ return openBlock(), createBlock(_component_PdkTableRow, {
75
+ class: normalizeClass(classes.value)
76
+ }, {
77
+ default: withCtx(() => [
78
+ createVNode(_component_PdkTableCol, null, {
79
+ default: withCtx(() => [
80
+ createVNode(_component_PdkCheckboxInput, {
81
+ modelValue: unref(selected),
82
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(selected) ? selected.value = $event : null),
83
+ element: checkboxElement,
84
+ value: unref(shipmentId)
85
+ }, null, 8, ["modelValue", "value"])
86
+ ]),
87
+ _: 1
88
+ }),
89
+ createVNode(_component_PdkTableCol, null, {
90
+ default: withCtx(() => [
91
+ createVNode(unref(_sfc_main$3), { "shipment-id": unref(shipmentId) }, null, 8, ["shipment-id"])
92
+ ]),
93
+ _: 1
94
+ }),
95
+ createVNode(_component_PdkTableCol, null, {
96
+ default: withCtx(() => [
97
+ createVNode(unref(_sfc_main$4), { "shipment-id": unref(shipmentId) }, null, 8, ["shipment-id"])
98
+ ]),
99
+ _: 1
100
+ }),
101
+ createVNode(_component_PdkTableCol, null, {
102
+ default: withCtx(() => {
103
+ var _a;
104
+ return [
105
+ createBaseVNode("span", {
106
+ title: (_a = unref(shipment).updated) == null ? void 0 : _a.date,
107
+ textContent: toDisplayString(shipmentUpdatedAt.value)
108
+ }, null, 8, _hoisted_1)
109
+ ];
110
+ }),
111
+ _: 1
112
+ }),
113
+ createVNode(_component_PdkTableCol, { align: "right" }, {
114
+ default: withCtx(() => [
115
+ createVNode(_component_PdkDropdownButton, { actions: unref(actions) }, null, 8, ["actions"])
116
+ ]),
117
+ _: 1
118
+ })
119
+ ]),
120
+ _: 1
121
+ }, 8, ["class"]);
122
+ };
123
+ }
124
+ });
125
+ const translationPrefix = "order_labels_column_";
126
+ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
127
+ __name: "OrderShipmentsTable",
128
+ emits: ["select"],
129
+ setup(__props, { emit: __emit }) {
130
+ var _a, _b;
131
+ const emit = __emit;
132
+ const { query } = useOrderData();
133
+ const data = computed(() => toValue(query.data));
134
+ const { bulkModel, bulkOptions } = useBulkSelectCheckbox(((_b = (_a = query.data.value) == null ? void 0 : _a.shipments) == null ? void 0 : _b.map(({ id }) => id)) ?? [], emit);
135
+ const { translate } = useLanguage();
136
+ return (_ctx, _cache) => {
137
+ const _component_PdkTableCol = resolveComponent("PdkTableCol");
138
+ const _component_PdkTableRow = resolveComponent("PdkTableRow");
139
+ const _component_PdkTable = resolveComponent("PdkTable");
140
+ return openBlock(), createBlock(_component_PdkTable, { class: "mb-0" }, {
141
+ header: withCtx(() => [
142
+ createVNode(_component_PdkTableRow, null, {
143
+ default: withCtx(() => [
144
+ createVNode(_component_PdkTableCol, { component: "th" }, {
145
+ default: withCtx(() => [
146
+ createVNode(unref(_sfc_main$5), {
147
+ modelValue: unref(bulkModel),
148
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(bulkModel) ? bulkModel.value = $event : null),
149
+ options: unref(bulkOptions)
150
+ }, null, 8, ["modelValue", "options"])
151
+ ]),
152
+ _: 1
153
+ }),
154
+ createVNode(_component_PdkTableCol, { component: "th" }, {
155
+ default: withCtx(() => [
156
+ createTextVNode(toDisplayString(unref(translate)(`${translationPrefix}track_trace`)), 1)
157
+ ]),
158
+ _: 1
159
+ }),
160
+ createVNode(_component_PdkTableCol, { component: "th" }, {
161
+ default: withCtx(() => [
162
+ createTextVNode(toDisplayString(unref(translate)(`${translationPrefix}status`)), 1)
163
+ ]),
164
+ _: 1
165
+ }),
166
+ createVNode(_component_PdkTableCol, { component: "th" }, {
167
+ default: withCtx(() => [
168
+ createTextVNode(toDisplayString(unref(translate)(`${translationPrefix}last_update`)), 1)
169
+ ]),
170
+ _: 1
171
+ }),
172
+ createVNode(_component_PdkTableCol, {
173
+ align: "right",
174
+ component: "th"
175
+ }, {
176
+ default: withCtx(() => [
177
+ createTextVNode(toDisplayString(unref(translate)(`${translationPrefix}actions`)), 1)
178
+ ]),
179
+ _: 1
180
+ })
181
+ ]),
182
+ _: 1
183
+ })
184
+ ]),
185
+ default: withCtx(() => {
186
+ var _a2;
187
+ return [
188
+ (openBlock(true), createElementBlock(Fragment, null, renderList((_a2 = data.value) == null ? void 0 : _a2.shipments, (shipment) => {
189
+ return openBlock(), createBlock(_sfc_main$2, {
190
+ key: `row_${shipment.id}_${shipment.updated}`,
191
+ modelValue: unref(bulkModel)[shipment.id],
192
+ "onUpdate:modelValue": ($event) => unref(bulkModel)[shipment.id] = $event,
193
+ "shipment-id": shipment.id
194
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "shipment-id"]);
195
+ }), 128))
196
+ ];
197
+ }),
198
+ _: 1
199
+ });
200
+ };
201
+ }
202
+ });
203
+ const _sfc_main = /* @__PURE__ */ defineComponent({
204
+ __name: "ShipmentTableBox",
205
+ setup(__props) {
206
+ const { order } = useOrderData();
207
+ const selectedLabels = ref([]);
208
+ const bulkActions = computed(() => {
209
+ var _a;
210
+ return instantiateActions(shipmentActions, {
211
+ orderIds: (_a = toValue(order)) == null ? void 0 : _a.externalIdentifier,
212
+ shipmentIds: toRaw(selectedLabels.value)
213
+ });
214
+ });
215
+ const setSelectedLabels = (labels) => {
216
+ selectedLabels.value = Object.keys(labels).filter((id) => isDef(labels[id]));
217
+ };
218
+ const { translate } = useLanguage();
219
+ return (_ctx, _cache) => {
220
+ const _component_PdkIcon = resolveComponent("PdkIcon");
221
+ const _component_PdkBadge = resolveComponent("PdkBadge");
222
+ const _component_PdkDropdownButton = resolveComponent("PdkDropdownButton");
223
+ const _component_PdkBox = resolveComponent("PdkBox");
224
+ return openBlock(), createBlock(_component_PdkBox, null, {
225
+ header: withCtx(() => [
226
+ createVNode(_component_PdkIcon, {
227
+ icon: unref(AdminIcon).Shipment
228
+ }, null, 8, ["icon"]),
229
+ createTextVNode(" " + toDisplayString(unref(translate)("order_labels_header")), 1)
230
+ ]),
231
+ default: withCtx(() => [
232
+ createVNode(_sfc_main$1, { onSelect: setSelectedLabels })
233
+ ]),
234
+ footer: withCtx(() => [
235
+ createVNode(_component_PdkDropdownButton, {
236
+ actions: bulkActions.value,
237
+ disabled: !selectedLabels.value.length
238
+ }, {
239
+ default: withCtx(() => [
240
+ createTextVNode(toDisplayString(unref(translate)("bulk_actions")) + " ", 1),
241
+ selectedLabels.value.length ? (openBlock(), createBlock(_component_PdkBadge, { key: 0 }, {
242
+ default: withCtx(() => [
243
+ createTextVNode(toDisplayString(selectedLabels.value.length), 1)
244
+ ]),
245
+ _: 1
246
+ })) : createCommentVNode("", true)
247
+ ]),
248
+ _: 1
249
+ }, 8, ["actions", "disabled"])
250
+ ]),
251
+ _: 1
252
+ });
253
+ };
254
+ }
255
+ });
256
+ export {
257
+ _sfc_main as default
258
+ };