strapi-plugin-bulk-updater 1.6.2 → 1.6.3

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.
@@ -4200,6 +4200,144 @@ function serializeGridTargets(gridEdits, selectedEntries, collectionPages = {},
4200
4200
  }
4201
4201
  return { targets, totalEditCount, hasValidationErrors };
4202
4202
  }
4203
+ function parseDynamicZonePath(path) {
4204
+ if (!path) return { cleanPath: "", rootKey: "", subPath: "" };
4205
+ const bracketMatch = path.match(/^([^.[]+)\[([^\]]+)\]\.(.+)$/);
4206
+ if (bracketMatch) {
4207
+ const rootKey = bracketMatch[1];
4208
+ const selector = bracketMatch[2];
4209
+ const subPath = bracketMatch[3];
4210
+ const cleanPath = `${rootKey}.${subPath}`;
4211
+ if (/^\d+$/.test(selector)) {
4212
+ return { cleanPath, rootKey, subPath, targetIndex: parseInt(selector, 10) };
4213
+ }
4214
+ return { cleanPath, rootKey, subPath, targetComponentUid: selector };
4215
+ }
4216
+ const parts = path.split(".");
4217
+ return {
4218
+ cleanPath: path,
4219
+ rootKey: parts[0] || "",
4220
+ subPath: parts.slice(1).join(".")
4221
+ };
4222
+ }
4223
+ function formatComponentName(compUid) {
4224
+ if (!compUid) return "Component";
4225
+ const name = compUid.includes(".") ? compUid.split(".")[1] : compUid;
4226
+ return name.split(/[-_]/).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
4227
+ }
4228
+ function getPropertyValue(target, key) {
4229
+ if (!target || typeof target !== "object" || !key) return void 0;
4230
+ if (target[key] !== void 0 && target[key] !== null) return target[key];
4231
+ const camelKey = key.replace(/_([a-z0-9])/g, (_, letter) => letter.toUpperCase());
4232
+ if (target[camelKey] !== void 0 && target[camelKey] !== null) return target[camelKey];
4233
+ const snakeKey = key.replace(/([A-Z])/g, "_$1").toLowerCase();
4234
+ if (target[snakeKey] !== void 0 && target[snakeKey] !== null) return target[snakeKey];
4235
+ const lowerKey = key.toLowerCase();
4236
+ const lowerNoUnderscore = lowerKey.replace(/_/g, "");
4237
+ const matchedKey = Object.keys(target).find((k) => {
4238
+ const kLower = k.toLowerCase();
4239
+ return kLower === lowerKey || kLower.replace(/_/g, "") === lowerNoUnderscore;
4240
+ });
4241
+ if (matchedKey && target[matchedKey] !== void 0 && target[matchedKey] !== null) {
4242
+ return target[matchedKey];
4243
+ }
4244
+ if (key in target) return target[key];
4245
+ if (camelKey in target) return target[camelKey];
4246
+ if (snakeKey in target) return target[snakeKey];
4247
+ return void 0;
4248
+ }
4249
+ function getNestedValue(obj, path) {
4250
+ if (!obj || !path) return void 0;
4251
+ const parsed = parseDynamicZonePath(path);
4252
+ const parts = parsed.cleanPath.split(".");
4253
+ function extract(current, remainingParts) {
4254
+ if (current === void 0 || current === null) return void 0;
4255
+ if (remainingParts.length === 0) return current;
4256
+ const [head, ...tail] = remainingParts;
4257
+ if (Array.isArray(current)) {
4258
+ if (/^\d+$/.test(head)) {
4259
+ return extract(current[parseInt(head, 10)], tail);
4260
+ }
4261
+ for (let idx = 0; idx < current.length; idx++) {
4262
+ const item = current[idx];
4263
+ if (parsed.targetIndex !== void 0 && idx !== parsed.targetIndex) continue;
4264
+ if (parsed.targetComponentUid && item?.__component !== parsed.targetComponentUid) continue;
4265
+ const found = extract(getPropertyValue(item, head), tail);
4266
+ if (found !== void 0 && found !== null) return found;
4267
+ }
4268
+ return void 0;
4269
+ }
4270
+ return extract(getPropertyValue(current, head), tail);
4271
+ }
4272
+ return extract(obj, parts);
4273
+ }
4274
+ function getAllNestedValues(obj, path, availableAttributes) {
4275
+ if (!obj || !path) return [];
4276
+ const parsed = parseDynamicZonePath(path);
4277
+ const parts = parsed.cleanPath.split(".");
4278
+ const [head, ...tail] = parts;
4279
+ const rootTarget = getPropertyValue(obj, head);
4280
+ if (rootTarget === void 0 || rootTarget === null) return [];
4281
+ if (Array.isArray(rootTarget)) {
4282
+ const results = [];
4283
+ rootTarget.forEach((item, idx) => {
4284
+ if (!item || typeof item !== "object") return;
4285
+ if (parsed.targetIndex !== void 0 && idx !== parsed.targetIndex) return;
4286
+ if (parsed.targetComponentUid && item.__component !== parsed.targetComponentUid) return;
4287
+ const subPath = tail.join(".");
4288
+ const scopedPath = item.__component ? `${head}[${item.__component}].${subPath}` : "";
4289
+ const isSupported = availableAttributes ? availableAttributes.includes(scopedPath) : false;
4290
+ if (tail.length > 0) {
4291
+ const subMatches = getAllNestedValues(item, subPath, availableAttributes);
4292
+ if (subMatches.length > 0) {
4293
+ subMatches.forEach((sm) => {
4294
+ results.push({
4295
+ index: idx,
4296
+ componentUid: item.__component || sm.componentUid,
4297
+ componentName: item.__component ? formatComponentName(item.__component) : sm.componentName,
4298
+ componentId: item.id !== void 0 && item.id !== null ? item.id : sm.componentId,
4299
+ value: sm.value,
4300
+ path: `${head}[#${idx}${item.__component ? ` ${formatComponentName(item.__component)}` : ""}].${sm.path}`
4301
+ });
4302
+ });
4303
+ return;
4304
+ }
4305
+ }
4306
+ const subVal = tail.length > 0 ? getNestedValue(item, subPath) : item;
4307
+ if (subVal !== void 0 || isSupported) {
4308
+ results.push({
4309
+ index: idx,
4310
+ componentUid: item.__component,
4311
+ componentName: formatComponentName(item.__component),
4312
+ componentId: item.id !== void 0 && item.id !== null ? item.id : void 0,
4313
+ value: subVal !== void 0 ? subVal : null,
4314
+ path: `${head}[#${idx}${item.__component ? ` ${formatComponentName(item.__component)}` : ""}].${subPath}`
4315
+ });
4316
+ }
4317
+ });
4318
+ return results;
4319
+ }
4320
+ if (typeof rootTarget === "object" && tail.length > 0) {
4321
+ const subMatches = getAllNestedValues(rootTarget, tail.join("."), availableAttributes);
4322
+ if (subMatches.length > 0) {
4323
+ return subMatches.map((sm) => ({
4324
+ ...sm,
4325
+ path: `${head}.${sm.path}`
4326
+ }));
4327
+ }
4328
+ }
4329
+ const singleVal = getNestedValue(obj, parsed.cleanPath);
4330
+ if (singleVal !== void 0) {
4331
+ return [
4332
+ {
4333
+ index: 0,
4334
+ value: singleVal,
4335
+ path: parsed.cleanPath
4336
+ }
4337
+ ];
4338
+ }
4339
+ return [];
4340
+ }
4203
4341
  const DEFAULT_HEADING_ITEMS = [
4204
4342
  { value: "h1", label: "H1 - Main Page Title", maxAllowed: 1 },
4205
4343
  { value: "h2", label: "H2 - Primary Section Heading", maxAllowed: 3 },
@@ -5076,117 +5214,6 @@ const ComponentOccurrencesDrawer = React__default.memo(
5076
5214
  );
5077
5215
  }
5078
5216
  );
5079
- function parseDynamicZonePath(path) {
5080
- if (!path) return { cleanPath: "", rootKey: "", subPath: "" };
5081
- const bracketMatch = path.match(/^([^.[]+)\[([^\]]+)\]\.(.+)$/);
5082
- if (bracketMatch) {
5083
- const rootKey = bracketMatch[1];
5084
- const selector = bracketMatch[2];
5085
- const subPath = bracketMatch[3];
5086
- const cleanPath = `${rootKey}.${subPath}`;
5087
- if (/^\d+$/.test(selector)) {
5088
- return { cleanPath, rootKey, subPath, targetIndex: parseInt(selector, 10) };
5089
- }
5090
- return { cleanPath, rootKey, subPath, targetComponentUid: selector };
5091
- }
5092
- const parts = path.split(".");
5093
- return {
5094
- cleanPath: path,
5095
- rootKey: parts[0] || "",
5096
- subPath: parts.slice(1).join(".")
5097
- };
5098
- }
5099
- function formatComponentName(compUid) {
5100
- if (!compUid) return "Component";
5101
- const name = compUid.includes(".") ? compUid.split(".")[1] : compUid;
5102
- return name.split(/[-_]/).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
5103
- }
5104
- function getAllNestedValues(obj, path, availableAttributes) {
5105
- if (!obj || !path) return [];
5106
- const parsed = parseDynamicZonePath(path);
5107
- const parts = parsed.cleanPath.split(".");
5108
- const [head, ...tail] = parts;
5109
- const rootTarget = getPropertyValue(obj, head);
5110
- if (Array.isArray(rootTarget)) {
5111
- const results = [];
5112
- rootTarget.forEach((item, idx) => {
5113
- if (!item || typeof item !== "object") return;
5114
- if (parsed.targetIndex !== void 0 && idx !== parsed.targetIndex) return;
5115
- if (parsed.targetComponentUid && item.__component !== parsed.targetComponentUid) return;
5116
- const subPath = tail.join(".");
5117
- const scopedPath = item.__component ? `${head}[${item.__component}].${subPath}` : "";
5118
- const isSupported = availableAttributes ? availableAttributes.includes(scopedPath) : false;
5119
- const subVal = tail.length > 0 ? getNestedValue(item, subPath) : item;
5120
- if (subVal !== void 0 || isSupported) {
5121
- results.push({
5122
- index: idx,
5123
- componentUid: item.__component,
5124
- componentName: formatComponentName(item.__component),
5125
- value: subVal !== void 0 ? subVal : null,
5126
- path: `${head}[#${idx}${item.__component ? ` ${formatComponentName(item.__component)}` : ""}].${subPath}`
5127
- });
5128
- }
5129
- });
5130
- return results;
5131
- }
5132
- const singleVal = getNestedValue(obj, parsed.cleanPath);
5133
- if (singleVal !== void 0) {
5134
- return [
5135
- {
5136
- index: 0,
5137
- value: singleVal,
5138
- path: parsed.cleanPath
5139
- }
5140
- ];
5141
- }
5142
- return [];
5143
- }
5144
- function getPropertyValue(target, key) {
5145
- if (!target || typeof target !== "object" || !key) return void 0;
5146
- if (target[key] !== void 0 && target[key] !== null) return target[key];
5147
- const camelKey = key.replace(/_([a-z0-9])/g, (_, letter) => letter.toUpperCase());
5148
- if (target[camelKey] !== void 0 && target[camelKey] !== null) return target[camelKey];
5149
- const snakeKey = key.replace(/([A-Z])/g, "_$1").toLowerCase();
5150
- if (target[snakeKey] !== void 0 && target[snakeKey] !== null) return target[snakeKey];
5151
- const lowerKey = key.toLowerCase();
5152
- const lowerNoUnderscore = lowerKey.replace(/_/g, "");
5153
- const matchedKey = Object.keys(target).find((k) => {
5154
- const kLower = k.toLowerCase();
5155
- return kLower === lowerKey || kLower.replace(/_/g, "") === lowerNoUnderscore;
5156
- });
5157
- if (matchedKey && target[matchedKey] !== void 0 && target[matchedKey] !== null) {
5158
- return target[matchedKey];
5159
- }
5160
- if (key in target) return target[key];
5161
- if (camelKey in target) return target[camelKey];
5162
- if (snakeKey in target) return target[snakeKey];
5163
- return void 0;
5164
- }
5165
- function getNestedValue(obj, path) {
5166
- if (!obj || !path) return void 0;
5167
- const parsed = parseDynamicZonePath(path);
5168
- const parts = parsed.cleanPath.split(".");
5169
- function extract(current, remainingParts) {
5170
- if (current === void 0 || current === null) return void 0;
5171
- if (remainingParts.length === 0) return current;
5172
- const [head, ...tail] = remainingParts;
5173
- if (Array.isArray(current)) {
5174
- if (/^\d+$/.test(head)) {
5175
- return extract(current[parseInt(head, 10)], tail);
5176
- }
5177
- for (let idx = 0; idx < current.length; idx++) {
5178
- const item = current[idx];
5179
- if (parsed.targetIndex !== void 0 && idx !== parsed.targetIndex) continue;
5180
- if (parsed.targetComponentUid && item?.__component !== parsed.targetComponentUid) continue;
5181
- const found = extract(getPropertyValue(item, head), tail);
5182
- if (found !== void 0 && found !== null) return found;
5183
- }
5184
- return void 0;
5185
- }
5186
- return extract(getPropertyValue(current, head), tail);
5187
- }
5188
- return extract(obj, parts);
5189
- }
5190
5217
  function getAvailableColumnsForCollection(col, selectedAttribute, searchAttribute) {
5191
5218
  const cols = [
5192
5219
  {
@@ -5754,16 +5781,63 @@ function renderCellContent(colDef, entry, col, selectedAttribute, searchAttribut
5754
5781
  }
5755
5782
  default: {
5756
5783
  const attrName = colDef.key.replace("attr_", "");
5757
- const rawVal = getNestedValue(entry, attrName);
5758
- const displayStr = formatDisplayValue(rawVal);
5759
- return /* @__PURE__ */ jsx(
5760
- Typography,
5761
- {
5762
- textColor: "neutral700",
5763
- style: { maxWidth: 200, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },
5764
- children: displayStr === "(empty / not set)" ? "-" : displayStr
5765
- }
5766
- );
5784
+ const matches = getAllNestedValues(entry, attrName, col?.attributes);
5785
+ if (matches.length === 0) {
5786
+ return /* @__PURE__ */ jsx(Typography, { textColor: "neutral500", style: { fontStyle: "italic" }, children: "-" });
5787
+ }
5788
+ if (matches.length === 1 && !matches[0].componentUid && !matches[0].path.includes("[#")) {
5789
+ const displayStr = formatDisplayValue(matches[0].value);
5790
+ return /* @__PURE__ */ jsx(
5791
+ Typography,
5792
+ {
5793
+ textColor: "neutral700",
5794
+ style: { maxWidth: 200, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },
5795
+ children: displayStr === "(empty / not set)" ? "-" : displayStr
5796
+ }
5797
+ );
5798
+ }
5799
+ return /* @__PURE__ */ jsx(Flex, { direction: "column", gap: 1, alignItems: "flex-start", style: { maxWidth: 320 }, children: matches.map((m, mIdx) => {
5800
+ const displayStr = formatDisplayValue(m.value);
5801
+ return /* @__PURE__ */ jsxs(
5802
+ Flex,
5803
+ {
5804
+ gap: 1,
5805
+ alignItems: "center",
5806
+ style: {
5807
+ backgroundColor: "rgba(0, 0, 0, 0.03)",
5808
+ padding: "2px 6px",
5809
+ borderRadius: 4
5810
+ },
5811
+ children: [
5812
+ /* @__PURE__ */ jsxs(Badge, { size: "S", backgroundColor: "neutral200", textColor: "neutral800", children: [
5813
+ "#",
5814
+ m.index,
5815
+ " ",
5816
+ m.componentName || "Item"
5817
+ ] }),
5818
+ m.componentId !== void 0 && /* @__PURE__ */ jsxs(Typography, { variant: "pi", textColor: "neutral500", style: { fontSize: "0.68rem" }, children: [
5819
+ "id:",
5820
+ m.componentId
5821
+ ] }),
5822
+ /* @__PURE__ */ jsx(
5823
+ Typography,
5824
+ {
5825
+ variant: "pi",
5826
+ textColor: "neutral800",
5827
+ style: {
5828
+ maxWidth: 200,
5829
+ overflow: "hidden",
5830
+ textOverflow: "ellipsis",
5831
+ whiteSpace: "nowrap"
5832
+ },
5833
+ children: displayStr
5834
+ }
5835
+ )
5836
+ ]
5837
+ },
5838
+ `${m.index}_${m.componentId ?? mIdx}_${m.componentUid ?? ""}`
5839
+ );
5840
+ }) });
5767
5841
  }
5768
5842
  }
5769
5843
  }
@@ -7180,7 +7254,31 @@ const BulkUpdater = () => {
7180
7254
  }
7181
7255
  try {
7182
7256
  setBulkExporting(true);
7183
- const res = await post("/bulk-updater/csv/export-bulk", { selectedEntries: targets });
7257
+ const targetUids = Array.from(new Set(targets.map((t) => t.uid)));
7258
+ let bulkSelectedCols;
7259
+ if (targetUids.length === 1 && selectedCol && selectedCol.uid === targetUids[0]) {
7260
+ const availCols = getAvailableColumnsForCollection(selectedCol, selectedAttribute, searchAttribute);
7261
+ const savedKeys = collectionColumnVisibility[selectedCol.uid];
7262
+ const activeCols = savedKeys ? availCols.filter((c) => c.isPermanent || savedKeys.includes(c.key)) : availCols.filter((c) => c.defaultVisible);
7263
+ const selectedDataAttrs = [];
7264
+ for (const c of activeCols) {
7265
+ if (c.key.startsWith("attr_")) {
7266
+ const attr = c.key.slice(5);
7267
+ if (!selectedDataAttrs.includes(attr)) selectedDataAttrs.push(attr);
7268
+ } else if (c.key === "target_attr" && selectedAttribute) {
7269
+ if (!selectedDataAttrs.includes(selectedAttribute)) selectedDataAttrs.push(selectedAttribute);
7270
+ } else if (c.key === "search_attr" && searchAttribute) {
7271
+ if (!selectedDataAttrs.includes(searchAttribute)) selectedDataAttrs.push(searchAttribute);
7272
+ }
7273
+ }
7274
+ if (selectedDataAttrs.length > 0) {
7275
+ bulkSelectedCols = selectedDataAttrs;
7276
+ }
7277
+ }
7278
+ const res = await post("/bulk-updater/csv/export-bulk", {
7279
+ selectedEntries: targets,
7280
+ selectedColumns: bulkSelectedCols
7281
+ });
7184
7282
  const csvStr = res.data?.csvContent || (typeof res.data === "string" ? res.data : "");
7185
7283
  if (!csvStr) {
7186
7284
  toggleNotification({
@@ -8386,6 +8484,21 @@ const BulkUpdater = () => {
8386
8484
  if (colSelectedDocIds.length > 0) {
8387
8485
  params.set("documentIds", colSelectedDocIds.join(","));
8388
8486
  }
8487
+ const selectedDataAttrs = [];
8488
+ for (const c of activeColumns) {
8489
+ if (c.key.startsWith("attr_")) {
8490
+ const attr = c.key.slice(5);
8491
+ if (!selectedDataAttrs.includes(attr)) selectedDataAttrs.push(attr);
8492
+ } else if (c.key === "target_attr" && selectedAttribute) {
8493
+ if (!selectedDataAttrs.includes(selectedAttribute)) selectedDataAttrs.push(selectedAttribute);
8494
+ } else if (c.key === "search_attr" && searchAttribute) {
8495
+ if (!selectedDataAttrs.includes(searchAttribute)) selectedDataAttrs.push(searchAttribute);
8496
+ }
8497
+ }
8498
+ if (selectedDataAttrs.length > 0) {
8499
+ params.set("selectedColumns", selectedDataAttrs.join(","));
8500
+ params.set("exportMode", "selective");
8501
+ }
8389
8502
  const res = await get(`/bulk-updater/csv/export/${col.uid}?${params.toString()}`);
8390
8503
  const csvStr = res.data?.csvContent || (typeof res.data === "string" ? res.data : "");
8391
8504
  if (!csvStr) {
@@ -10166,4 +10279,4 @@ export {
10166
10279
  getSortOptionsForCollection,
10167
10280
  parseDynamicZonePath
10168
10281
  };
10169
- //# sourceMappingURL=BulkUpdater-e7N4vMse.mjs.map
10282
+ //# sourceMappingURL=BulkUpdater-B7XefFd9.mjs.map