@unlayer/react-elements 0.1.6 → 0.1.7

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/index.js CHANGED
@@ -227,15 +227,13 @@ function mapSemanticProps(props, defaultValues, componentType) {
227
227
  delete userProps.html;
228
228
  delete result.html;
229
229
  }
230
- const href = userProps.href;
231
- if (href !== void 0) {
232
- if (typeof href === "string") {
233
- userProps.href = {
230
+ for (const key of ["href", "action"]) {
231
+ const v = userProps[key];
232
+ if (typeof v === "string") {
233
+ userProps[key] = {
234
234
  name: "web",
235
- values: { href, target: "_blank" }
235
+ values: { href: v, target: "_blank" }
236
236
  };
237
- } else {
238
- userProps.href = href;
239
237
  }
240
238
  }
241
239
  const nestedGroups = analyzeNestedStructure(defaultValues);
@@ -274,6 +272,46 @@ function mapSemanticProps(props, defaultValues, componentType) {
274
272
  }
275
273
  return final;
276
274
  }
275
+ function normalizeLinkValue(value) {
276
+ if (value == null) return void 0;
277
+ if (typeof value === "string") {
278
+ return { url: value, target: "_blank" };
279
+ }
280
+ if (typeof value !== "object") return void 0;
281
+ const v = value;
282
+ if ("url" in v) return v;
283
+ if ("name" in v && v.values && typeof v.values === "object") {
284
+ const inner = v.values;
285
+ return {
286
+ url: inner.href ?? "",
287
+ target: inner.target ?? "_blank",
288
+ ...v.attrs ?? {}
289
+ };
290
+ }
291
+ return void 0;
292
+ }
293
+ function normalizeValuesForExporter(values, componentName) {
294
+ if (values == null || typeof values !== "object") return values;
295
+ const out = { ...values };
296
+ for (const key of ["href", "action"]) {
297
+ if (out[key] !== void 0) {
298
+ const normalized = normalizeLinkValue(out[key]);
299
+ if (normalized !== void 0) out[key] = normalized;
300
+ }
301
+ }
302
+ if (componentName === "Menu" && out.menu && Array.isArray(out.menu.items)) {
303
+ out.menu = {
304
+ ...out.menu,
305
+ items: out.menu.items.map((item) => {
306
+ if (!item || item.link === void 0) return item;
307
+ const normalized = normalizeLinkValue(item.link);
308
+ if (normalized === void 0) return item;
309
+ return { ...item, link: normalized };
310
+ })
311
+ };
312
+ }
313
+ return out;
314
+ }
277
315
  var HTML_ENTITIES = {
278
316
  "&": "&",
279
317
  "&lt;": "<",
@@ -463,10 +501,14 @@ function createItemComponent(config) {
463
501
  contentWidth: 600,
464
502
  ...bodyValues
465
503
  };
504
+ const valuesForExporter = normalizeValuesForExporter(
505
+ valuesWithMeta,
506
+ config.name
507
+ );
466
508
  const exporter = config.exporters[mode] || config.exporters.web;
467
509
  return renderComponent({
468
510
  type: config.name,
469
- values: valuesWithMeta,
511
+ values: valuesForExporter,
470
512
  className,
471
513
  style,
472
514
  args: [index, colIndex, cells, safeBodyValues, rowValues],