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