@takeshape/util 10.1.0 → 10.2.4

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/draftjs.js CHANGED
@@ -182,8 +182,7 @@ function fromDraftjs(draftjs, styleItems, entityItems) {
182
182
  },
183
183
  'code-block': {
184
184
  open(entity) {
185
- var _entity$data;
186
- const lang = (entity === null || entity === void 0 ? void 0 : (_entity$data = entity.data) === null || _entity$data === void 0 ? void 0 : _entity$data.lang) ?? '';
185
+ const lang = entity?.data?.lang ?? '';
187
186
  return `\`\`\`${lang}\n`;
188
187
  },
189
188
  close() {
@@ -195,20 +194,17 @@ function fromDraftjs(draftjs, styleItems, entityItems) {
195
194
  entityItems: {
196
195
  LINK: {
197
196
  open(entity) {
198
- var _entity$data2;
199
- if ((entity === null || entity === void 0 ? void 0 : (_entity$data2 = entity.data) === null || _entity$data2 === void 0 ? void 0 : _entity$data2.target) === '_blank') {
200
- var _entity$data3, _entity$data4;
201
- const url = (0, _escape.default)((entity === null || entity === void 0 ? void 0 : (_entity$data3 = entity.data) === null || _entity$data3 === void 0 ? void 0 : _entity$data3.url) || (entity === null || entity === void 0 ? void 0 : (_entity$data4 = entity.data) === null || _entity$data4 === void 0 ? void 0 : _entity$data4.href) || '');
197
+ if (entity?.data?.target === '_blank') {
198
+ const url = (0, _escape.default)(entity?.data?.url || entity?.data?.href || '');
202
199
  return `<TSExternalLink text="${EXTERNAL_LINK_MARKER}" href="${url}">`;
203
200
  }
204
201
  return '[';
205
202
  },
206
203
  close(entity) {
207
- var _entity$data5, _entity$data6, _entity$data7;
208
- if ((entity === null || entity === void 0 ? void 0 : (_entity$data5 = entity.data) === null || _entity$data5 === void 0 ? void 0 : _entity$data5.target) === '_blank') {
204
+ if (entity?.data?.target === '_blank') {
209
205
  return '</TSExternalLink>';
210
206
  }
211
- return ']('.concat((entity === null || entity === void 0 ? void 0 : (_entity$data6 = entity.data) === null || _entity$data6 === void 0 ? void 0 : _entity$data6.url) || (entity === null || entity === void 0 ? void 0 : (_entity$data7 = entity.data) === null || _entity$data7 === void 0 ? void 0 : _entity$data7.href) || '', ')');
207
+ return ']('.concat(entity?.data?.url || entity?.data?.href || '', ')');
212
208
  }
213
209
  },
214
210
  ...entityItems
@@ -237,7 +233,7 @@ function draftjsToMd(draftjs, assets) {
237
233
  return '';
238
234
  },
239
235
  close(entity) {
240
- if (!(entity !== null && entity !== void 0 && entity.data)) {
236
+ if (!entity?.data) {
241
237
  return '';
242
238
  }
243
239
  const {
@@ -251,7 +247,7 @@ function draftjsToMd(draftjs, assets) {
251
247
  return '';
252
248
  },
253
249
  close(entity) {
254
- if (!(entity !== null && entity !== void 0 && entity.data)) {
250
+ if (!entity?.data) {
255
251
  return '';
256
252
  }
257
253
  const {
@@ -276,8 +272,7 @@ function draftjsToMd(draftjs, assets) {
276
272
  });
277
273
  }
278
274
  function getTextFromDraftjs(draftjs) {
279
- var _draftjs$blocks, _draftjs$blocks$;
280
- return draftjs === null || draftjs === void 0 ? void 0 : (_draftjs$blocks = draftjs.blocks) === null || _draftjs$blocks === void 0 ? void 0 : (_draftjs$blocks$ = _draftjs$blocks[0]) === null || _draftjs$blocks$ === void 0 ? void 0 : _draftjs$blocks$.text;
275
+ return draftjs?.blocks?.[0]?.text;
281
276
  }
282
277
  function getAssetField(data, asset, field) {
283
278
  const dataText = getTextFromDraftjs(data[field]);
@@ -305,7 +300,7 @@ function draftjsToMdx(draftjs, assets, prefix = mdxShortcodePrefix) {
305
300
  return '';
306
301
  },
307
302
  close(entity) {
308
- if (!(entity !== null && entity !== void 0 && entity.data)) {
303
+ if (!entity?.data) {
309
304
  return '';
310
305
  }
311
306
  const {
@@ -319,9 +314,8 @@ function draftjsToMdx(draftjs, assets, prefix = mdxShortcodePrefix) {
319
314
  return '';
320
315
  },
321
316
  close(entity) {
322
- var _entity$data8, _data$link, _data$link2;
323
- const asset = assets[entity === null || entity === void 0 ? void 0 : (_entity$data8 = entity.data) === null || _entity$data8 === void 0 ? void 0 : _entity$data8.id];
324
- if (!(entity !== null && entity !== void 0 && entity.data) || asset === undefined) {
317
+ const asset = assets[entity?.data?.id];
318
+ if (!entity?.data || asset === undefined) {
325
319
  return '';
326
320
  }
327
321
  const {
@@ -336,8 +330,8 @@ function draftjsToMdx(draftjs, assets, prefix = mdxShortcodePrefix) {
336
330
  assetPath: asset.path,
337
331
  credit: getAssetField(data, asset, 'credit'),
338
332
  caption: getAssetField(data, asset, 'caption'),
339
- link: (_data$link = data.link) === null || _data$link === void 0 ? void 0 : _data$link.url,
340
- linkisexternal: (_data$link2 = data.link) !== null && _data$link2 !== void 0 && _data$link2.external ? 'true' : 'false',
333
+ link: data.link?.url,
334
+ linkisexternal: data.link?.external ? 'true' : 'false',
341
335
  src: (0, _routing.getImageUrl)(asset.path, data.imageParams, imageUrlOptions)
342
336
  });
343
337
  }
@@ -365,31 +359,30 @@ function parseFigureClass(className) {
365
359
  function htmlDomToDraftjsImage(dom, item, entityKeyGenerator) {
366
360
  for (const figure of dom) {
367
361
  if (figure.type === 'tag' && figure.name === 'figure') {
368
- var _figure$children, _figure$children2, _figcaption, _figcaption2, _caption, _credit, _link, _link2;
369
362
  let link;
370
- const figureChildOne = (_figure$children = figure.children) === null || _figure$children === void 0 ? void 0 : _figure$children[0];
371
- const figureChildTwo = (_figure$children2 = figure.children) === null || _figure$children2 === void 0 ? void 0 : _figure$children2[1];
372
- if ((figureChildOne === null || figureChildOne === void 0 ? void 0 : figureChildOne.type) === 'tag' && (figureChildOne === null || figureChildOne === void 0 ? void 0 : figureChildOne.name) === 'a') {
363
+ const figureChildOne = figure.children?.[0];
364
+ const figureChildTwo = figure.children?.[1];
365
+ if (figureChildOne?.type === 'tag' && figureChildOne?.name === 'a') {
373
366
  link = figureChildOne;
374
367
  }
375
368
  let figcaption;
376
- if ((figureChildOne === null || figureChildOne === void 0 ? void 0 : figureChildOne.type) === 'tag' && (figureChildOne === null || figureChildOne === void 0 ? void 0 : figureChildOne.name) === 'figcaption') {
369
+ if (figureChildOne?.type === 'tag' && figureChildOne?.name === 'figcaption') {
377
370
  figcaption = figureChildOne;
378
- } else if ((figureChildTwo === null || figureChildTwo === void 0 ? void 0 : figureChildTwo.type) === 'tag' && (figureChildTwo === null || figureChildTwo === void 0 ? void 0 : figureChildTwo.name) === 'figcaption') {
371
+ } else if (figureChildTwo?.type === 'tag' && figureChildTwo?.name === 'figcaption') {
379
372
  figcaption = figure.children[1];
380
373
  }
381
374
  const img = link ? link.children[0] : figure.children[0];
382
- if ((img === null || img === void 0 ? void 0 : img.type) !== 'tag' || (img === null || img === void 0 ? void 0 : img.name) !== 'img') {
375
+ if (img?.type !== 'tag' || img?.name !== 'img') {
383
376
  return;
384
377
  }
385
- const figcaptionChild = (_figcaption = figcaption) === null || _figcaption === void 0 ? void 0 : _figcaption.children[0];
378
+ const figcaptionChild = figcaption?.children[0];
386
379
  let caption;
387
- if ((figcaptionChild === null || figcaptionChild === void 0 ? void 0 : figcaptionChild.type) === 'tag' && (figcaptionChild === null || figcaptionChild === void 0 ? void 0 : figcaptionChild.name) === 'span' && (figcaptionChild === null || figcaptionChild === void 0 ? void 0 : figcaptionChild.attribs.class) === 'caption') {
380
+ if (figcaptionChild?.type === 'tag' && figcaptionChild?.name === 'span' && figcaptionChild?.attribs.class === 'caption') {
388
381
  caption = figcaptionChild;
389
382
  }
390
- const captionChildThree = (_figcaption2 = figcaption) === null || _figcaption2 === void 0 ? void 0 : _figcaption2.children[2];
383
+ const captionChildThree = figcaption?.children[2];
391
384
  let credit;
392
- if ((captionChildThree === null || captionChildThree === void 0 ? void 0 : captionChildThree.type) === 'tag' && (captionChildThree === null || captionChildThree === void 0 ? void 0 : captionChildThree.name) === 'span' && (captionChildThree === null || captionChildThree === void 0 ? void 0 : captionChildThree.attribs.class) === 'credit') {
385
+ if (captionChildThree?.type === 'tag' && captionChildThree?.name === 'span' && captionChildThree?.attribs.class === 'credit') {
393
386
  credit = captionChildThree;
394
387
  }
395
388
  const {
@@ -397,13 +390,13 @@ function htmlDomToDraftjsImage(dom, item, entityKeyGenerator) {
397
390
  size
398
391
  } = parseFigureClass(figure.attribs.class);
399
392
  return (0, _draftjsTemplates.getDraftjsImage)({
400
- captionText: ((_caption = caption) === null || _caption === void 0 ? void 0 : _caption.children[0].data) ?? '',
401
- creditText: ((_credit = credit) === null || _credit === void 0 ? void 0 : _credit.children[0].data) ?? '',
393
+ captionText: caption?.children[0].data ?? '',
394
+ creditText: credit?.children[0].data ?? '',
402
395
  alignment,
403
396
  size,
404
397
  assetId: getAssetIdFromImageSrc(img.attribs.src),
405
- linkUrl: (_link = link) === null || _link === void 0 ? void 0 : _link.attribs.href,
406
- linkIsExternal: ((_link2 = link) === null || _link2 === void 0 ? void 0 : _link2.attribs.target) === '_blank',
398
+ linkUrl: link?.attribs.href,
399
+ linkIsExternal: link?.attribs.target === '_blank',
407
400
  key: entityKeyGenerator(),
408
401
  depth: item.level,
409
402
  path: getImagePathFromUrl(img.attribs.src)
@@ -415,11 +408,11 @@ function htmlDomToOembed(dom, item, entityKeyGenerator) {
415
408
  for (const oembedDiv of dom) {
416
409
  if (oembedDiv.type === 'tag' && oembedDiv.name === 'div' && oembedDiv.attribs.class === 'oembed') {
417
410
  const blockquote = oembedDiv.children[0];
418
- if ((blockquote === null || blockquote === void 0 ? void 0 : blockquote.type) !== 'tag' || (blockquote === null || blockquote === void 0 ? void 0 : blockquote.name) !== 'blockquote') {
411
+ if (blockquote?.type !== 'tag' || blockquote?.name !== 'blockquote') {
419
412
  return;
420
413
  }
421
414
  const script = oembedDiv.children[2];
422
- if ((script === null || script === void 0 ? void 0 : script.type) !== 'script' || (script === null || script === void 0 ? void 0 : script.name) !== 'script') {
415
+ if (script?.type !== 'script' || script?.name !== 'script') {
423
416
  return;
424
417
  }
425
418
  return (0, _draftjsTemplates.getDraftjsOembed)({
@@ -454,7 +447,7 @@ function htmlDomToPullquote(dom, item) {
454
447
  for (const pullquote of dom) {
455
448
  if (pullquote.type === 'tag' && pullquote.name === 'aside' && pullquote.attribs.style === pullquoteStyle) {
456
449
  const text = pullquote.children[0];
457
- if ((text === null || text === void 0 ? void 0 : text.type) !== 'text') {
450
+ if (text?.type !== 'text') {
458
451
  return;
459
452
  }
460
453
  return (0, _draftjsTemplates.getDraftjsPullquote)({
@@ -611,12 +604,11 @@ function addLinks(state, links) {
611
604
  for (const block of state.blocks) {
612
605
  let blockIsCustom = false;
613
606
  for (const [i, entityRange] of block.entityRanges.entries()) {
614
- var _entity$data9;
615
607
  const entity = state.entityMap[entityRange.key];
616
608
  if (entity === undefined) {
617
609
  throw new Error('Missing entity');
618
610
  }
619
- if (i === 0 && (_entity$data9 = entity.data) !== null && _entity$data9 !== void 0 && _entity$data9.marker) {
611
+ if (i === 0 && entity.data?.marker) {
620
612
  blockIsCustom = true;
621
613
  continue;
622
614
  }
@@ -655,9 +647,8 @@ function replaceBlocks(state, replacementBlocks) {
655
647
  let removeBlockEntityKeys = false;
656
648
  const blockEntityKeys = block.entityRanges.map(range => range.key);
657
649
  if (blockEntityKeys.includes(Number(entityKey))) {
658
- var _entity$data10;
659
650
  const entity = state.entityMap[entityKey];
660
- const markerKey = (_entity$data10 = entity.data) === null || _entity$data10 === void 0 ? void 0 : _entity$data10.marker;
651
+ const markerKey = entity.data?.marker;
661
652
  const replacementBlock = replacementBlocks[markerKey];
662
653
  if (replacementBlock && !removeBlockEntityKeys) {
663
654
  const originalBlock = state.blocks[i];
@@ -667,10 +658,7 @@ function replaceBlocks(state, replacementBlocks) {
667
658
  const removeBlockEntities = entity.data.type === 'image' || entity.data.type === 'oembed';
668
659
  // eslint-disable-next-line max-depth
669
660
  if (!removeBlockEntities) {
670
- replacementBlock.entityRanges = originalBlock.entityRanges.filter(entityRange => {
671
- var _state$entityMap$enti;
672
- return ((_state$entityMap$enti = state.entityMap[entityRange.key].data) === null || _state$entityMap$enti === void 0 ? void 0 : _state$entityMap$enti.marker) === undefined;
673
- });
661
+ replacementBlock.entityRanges = originalBlock.entityRanges.filter(entityRange => state.entityMap[entityRange.key].data?.marker === undefined);
674
662
  }
675
663
  state.blocks[i] = replacementBlock;
676
664
  // eslint-disable-next-line max-depth
@@ -827,9 +815,6 @@ function mdxToDraftjs(mdx) {
827
815
  result.entityMap = (0, _pickBy.default)({
828
816
  ...result.entityMap,
829
817
  ...entities
830
- }, (entity, key) => {
831
- var _entity$data11;
832
- return ((_entity$data11 = entity.data) === null || _entity$data11 === void 0 ? void 0 : _entity$data11.marker) === undefined && !entityKeysToExclude.includes(Number(key));
833
- });
818
+ }, (entity, key) => entity.data?.marker === undefined && !entityKeysToExclude.includes(Number(key)));
834
819
  return result;
835
820
  }
@@ -12,7 +12,7 @@ function toSearchParamsEntries(obj) {
12
12
  return [...obj.entries()];
13
13
  }
14
14
  if (typeof obj === 'object' && !Array.isArray(obj)) {
15
- return Object.entries(obj).map(([k, v]) => [k, (v === null || v === void 0 ? void 0 : v.toString()) ?? '']);
15
+ return Object.entries(obj).map(([k, v]) => [k, v?.toString() ?? '']);
16
16
  }
17
17
  return [...new _url.URLSearchParams(obj).entries()];
18
18
  }
package/dist/strings.js CHANGED
@@ -23,7 +23,7 @@ const camelCase = _camelCase2.default;
23
23
  exports.camelCase = camelCase;
24
24
  function formatShapeName(str, options) {
25
25
  const strings = (0, _arrays.ensureArray)(str);
26
- const shapeNameIndex = (options === null || options === void 0 ? void 0 : options.shapeNameIndex) ?? 0;
26
+ const shapeNameIndex = options?.shapeNameIndex ?? 0;
27
27
  const shapeName = strings.at(shapeNameIndex);
28
28
 
29
29
  // If the shapeNameIndex is incorrect, behave as normal
package/dist/templates.js CHANGED
@@ -36,7 +36,6 @@ function attrs(obj) {
36
36
  return attrStrings.length ? ' ' + attrStrings.join(' ') : '';
37
37
  }
38
38
  function imageTemplate(applyPrefix, data) {
39
- var _data$link;
40
39
  const {
41
40
  caption,
42
41
  credit,
@@ -62,7 +61,7 @@ function imageTemplate(applyPrefix, data) {
62
61
  title: asset.title
63
62
  });
64
63
  let image = `<img${imgAttrs} src="${imageUrl}"/>`;
65
- if ((_data$link = data.link) !== null && _data$link !== void 0 && _data$link.url) {
64
+ if (data.link?.url) {
66
65
  const target = data.link.external ? ' target="blank" rel="noopener noreferrer"' : '';
67
66
  image = `<a href="${data.link.url}"${target}>${image}</a>`;
68
67
  }
package/es/draftjs.js CHANGED
@@ -165,8 +165,7 @@ export function fromDraftjs(draftjs, styleItems, entityItems) {
165
165
  },
166
166
  'code-block': {
167
167
  open(entity) {
168
- var _entity$data;
169
- const lang = (entity === null || entity === void 0 ? void 0 : (_entity$data = entity.data) === null || _entity$data === void 0 ? void 0 : _entity$data.lang) ?? '';
168
+ const lang = entity?.data?.lang ?? '';
170
169
  return `\`\`\`${lang}\n`;
171
170
  },
172
171
  close() {
@@ -178,20 +177,17 @@ export function fromDraftjs(draftjs, styleItems, entityItems) {
178
177
  entityItems: {
179
178
  LINK: {
180
179
  open(entity) {
181
- var _entity$data2;
182
- if ((entity === null || entity === void 0 ? void 0 : (_entity$data2 = entity.data) === null || _entity$data2 === void 0 ? void 0 : _entity$data2.target) === '_blank') {
183
- var _entity$data3, _entity$data4;
184
- const url = escape((entity === null || entity === void 0 ? void 0 : (_entity$data3 = entity.data) === null || _entity$data3 === void 0 ? void 0 : _entity$data3.url) || (entity === null || entity === void 0 ? void 0 : (_entity$data4 = entity.data) === null || _entity$data4 === void 0 ? void 0 : _entity$data4.href) || '');
180
+ if (entity?.data?.target === '_blank') {
181
+ const url = escape(entity?.data?.url || entity?.data?.href || '');
185
182
  return `<TSExternalLink text="${EXTERNAL_LINK_MARKER}" href="${url}">`;
186
183
  }
187
184
  return '[';
188
185
  },
189
186
  close(entity) {
190
- var _entity$data5, _entity$data6, _entity$data7;
191
- if ((entity === null || entity === void 0 ? void 0 : (_entity$data5 = entity.data) === null || _entity$data5 === void 0 ? void 0 : _entity$data5.target) === '_blank') {
187
+ if (entity?.data?.target === '_blank') {
192
188
  return '</TSExternalLink>';
193
189
  }
194
- return ']('.concat((entity === null || entity === void 0 ? void 0 : (_entity$data6 = entity.data) === null || _entity$data6 === void 0 ? void 0 : _entity$data6.url) || (entity === null || entity === void 0 ? void 0 : (_entity$data7 = entity.data) === null || _entity$data7 === void 0 ? void 0 : _entity$data7.href) || '', ')');
190
+ return ']('.concat(entity?.data?.url || entity?.data?.href || '', ')');
195
191
  }
196
192
  },
197
193
  ...entityItems
@@ -220,7 +216,7 @@ export function draftjsToMd(draftjs, assets) {
220
216
  return '';
221
217
  },
222
218
  close(entity) {
223
- if (!(entity !== null && entity !== void 0 && entity.data)) {
219
+ if (!entity?.data) {
224
220
  return '';
225
221
  }
226
222
  const {
@@ -234,7 +230,7 @@ export function draftjsToMd(draftjs, assets) {
234
230
  return '';
235
231
  },
236
232
  close(entity) {
237
- if (!(entity !== null && entity !== void 0 && entity.data)) {
233
+ if (!entity?.data) {
238
234
  return '';
239
235
  }
240
236
  const {
@@ -259,8 +255,7 @@ export function draftjsToMd(draftjs, assets) {
259
255
  });
260
256
  }
261
257
  function getTextFromDraftjs(draftjs) {
262
- var _draftjs$blocks, _draftjs$blocks$;
263
- return draftjs === null || draftjs === void 0 ? void 0 : (_draftjs$blocks = draftjs.blocks) === null || _draftjs$blocks === void 0 ? void 0 : (_draftjs$blocks$ = _draftjs$blocks[0]) === null || _draftjs$blocks$ === void 0 ? void 0 : _draftjs$blocks$.text;
258
+ return draftjs?.blocks?.[0]?.text;
264
259
  }
265
260
  function getAssetField(data, asset, field) {
266
261
  const dataText = getTextFromDraftjs(data[field]);
@@ -288,7 +283,7 @@ export function draftjsToMdx(draftjs, assets, prefix = mdxShortcodePrefix) {
288
283
  return '';
289
284
  },
290
285
  close(entity) {
291
- if (!(entity !== null && entity !== void 0 && entity.data)) {
286
+ if (!entity?.data) {
292
287
  return '';
293
288
  }
294
289
  const {
@@ -302,9 +297,8 @@ export function draftjsToMdx(draftjs, assets, prefix = mdxShortcodePrefix) {
302
297
  return '';
303
298
  },
304
299
  close(entity) {
305
- var _entity$data8, _data$link, _data$link2;
306
- const asset = assets[entity === null || entity === void 0 ? void 0 : (_entity$data8 = entity.data) === null || _entity$data8 === void 0 ? void 0 : _entity$data8.id];
307
- if (!(entity !== null && entity !== void 0 && entity.data) || asset === undefined) {
300
+ const asset = assets[entity?.data?.id];
301
+ if (!entity?.data || asset === undefined) {
308
302
  return '';
309
303
  }
310
304
  const {
@@ -319,8 +313,8 @@ export function draftjsToMdx(draftjs, assets, prefix = mdxShortcodePrefix) {
319
313
  assetPath: asset.path,
320
314
  credit: getAssetField(data, asset, 'credit'),
321
315
  caption: getAssetField(data, asset, 'caption'),
322
- link: (_data$link = data.link) === null || _data$link === void 0 ? void 0 : _data$link.url,
323
- linkisexternal: (_data$link2 = data.link) !== null && _data$link2 !== void 0 && _data$link2.external ? 'true' : 'false',
316
+ link: data.link?.url,
317
+ linkisexternal: data.link?.external ? 'true' : 'false',
324
318
  src: getImageUrl(asset.path, data.imageParams, imageUrlOptions)
325
319
  });
326
320
  }
@@ -348,31 +342,30 @@ function parseFigureClass(className) {
348
342
  function htmlDomToDraftjsImage(dom, item, entityKeyGenerator) {
349
343
  for (const figure of dom) {
350
344
  if (figure.type === 'tag' && figure.name === 'figure') {
351
- var _figure$children, _figure$children2, _figcaption, _figcaption2, _caption, _credit, _link, _link2;
352
345
  let link;
353
- const figureChildOne = (_figure$children = figure.children) === null || _figure$children === void 0 ? void 0 : _figure$children[0];
354
- const figureChildTwo = (_figure$children2 = figure.children) === null || _figure$children2 === void 0 ? void 0 : _figure$children2[1];
355
- if ((figureChildOne === null || figureChildOne === void 0 ? void 0 : figureChildOne.type) === 'tag' && (figureChildOne === null || figureChildOne === void 0 ? void 0 : figureChildOne.name) === 'a') {
346
+ const figureChildOne = figure.children?.[0];
347
+ const figureChildTwo = figure.children?.[1];
348
+ if (figureChildOne?.type === 'tag' && figureChildOne?.name === 'a') {
356
349
  link = figureChildOne;
357
350
  }
358
351
  let figcaption;
359
- if ((figureChildOne === null || figureChildOne === void 0 ? void 0 : figureChildOne.type) === 'tag' && (figureChildOne === null || figureChildOne === void 0 ? void 0 : figureChildOne.name) === 'figcaption') {
352
+ if (figureChildOne?.type === 'tag' && figureChildOne?.name === 'figcaption') {
360
353
  figcaption = figureChildOne;
361
- } else if ((figureChildTwo === null || figureChildTwo === void 0 ? void 0 : figureChildTwo.type) === 'tag' && (figureChildTwo === null || figureChildTwo === void 0 ? void 0 : figureChildTwo.name) === 'figcaption') {
354
+ } else if (figureChildTwo?.type === 'tag' && figureChildTwo?.name === 'figcaption') {
362
355
  figcaption = figure.children[1];
363
356
  }
364
357
  const img = link ? link.children[0] : figure.children[0];
365
- if ((img === null || img === void 0 ? void 0 : img.type) !== 'tag' || (img === null || img === void 0 ? void 0 : img.name) !== 'img') {
358
+ if (img?.type !== 'tag' || img?.name !== 'img') {
366
359
  return;
367
360
  }
368
- const figcaptionChild = (_figcaption = figcaption) === null || _figcaption === void 0 ? void 0 : _figcaption.children[0];
361
+ const figcaptionChild = figcaption?.children[0];
369
362
  let caption;
370
- if ((figcaptionChild === null || figcaptionChild === void 0 ? void 0 : figcaptionChild.type) === 'tag' && (figcaptionChild === null || figcaptionChild === void 0 ? void 0 : figcaptionChild.name) === 'span' && (figcaptionChild === null || figcaptionChild === void 0 ? void 0 : figcaptionChild.attribs.class) === 'caption') {
363
+ if (figcaptionChild?.type === 'tag' && figcaptionChild?.name === 'span' && figcaptionChild?.attribs.class === 'caption') {
371
364
  caption = figcaptionChild;
372
365
  }
373
- const captionChildThree = (_figcaption2 = figcaption) === null || _figcaption2 === void 0 ? void 0 : _figcaption2.children[2];
366
+ const captionChildThree = figcaption?.children[2];
374
367
  let credit;
375
- if ((captionChildThree === null || captionChildThree === void 0 ? void 0 : captionChildThree.type) === 'tag' && (captionChildThree === null || captionChildThree === void 0 ? void 0 : captionChildThree.name) === 'span' && (captionChildThree === null || captionChildThree === void 0 ? void 0 : captionChildThree.attribs.class) === 'credit') {
368
+ if (captionChildThree?.type === 'tag' && captionChildThree?.name === 'span' && captionChildThree?.attribs.class === 'credit') {
376
369
  credit = captionChildThree;
377
370
  }
378
371
  const {
@@ -380,13 +373,13 @@ function htmlDomToDraftjsImage(dom, item, entityKeyGenerator) {
380
373
  size
381
374
  } = parseFigureClass(figure.attribs.class);
382
375
  return getDraftjsImage({
383
- captionText: ((_caption = caption) === null || _caption === void 0 ? void 0 : _caption.children[0].data) ?? '',
384
- creditText: ((_credit = credit) === null || _credit === void 0 ? void 0 : _credit.children[0].data) ?? '',
376
+ captionText: caption?.children[0].data ?? '',
377
+ creditText: credit?.children[0].data ?? '',
385
378
  alignment,
386
379
  size,
387
380
  assetId: getAssetIdFromImageSrc(img.attribs.src),
388
- linkUrl: (_link = link) === null || _link === void 0 ? void 0 : _link.attribs.href,
389
- linkIsExternal: ((_link2 = link) === null || _link2 === void 0 ? void 0 : _link2.attribs.target) === '_blank',
381
+ linkUrl: link?.attribs.href,
382
+ linkIsExternal: link?.attribs.target === '_blank',
390
383
  key: entityKeyGenerator(),
391
384
  depth: item.level,
392
385
  path: getImagePathFromUrl(img.attribs.src)
@@ -398,11 +391,11 @@ function htmlDomToOembed(dom, item, entityKeyGenerator) {
398
391
  for (const oembedDiv of dom) {
399
392
  if (oembedDiv.type === 'tag' && oembedDiv.name === 'div' && oembedDiv.attribs.class === 'oembed') {
400
393
  const blockquote = oembedDiv.children[0];
401
- if ((blockquote === null || blockquote === void 0 ? void 0 : blockquote.type) !== 'tag' || (blockquote === null || blockquote === void 0 ? void 0 : blockquote.name) !== 'blockquote') {
394
+ if (blockquote?.type !== 'tag' || blockquote?.name !== 'blockquote') {
402
395
  return;
403
396
  }
404
397
  const script = oembedDiv.children[2];
405
- if ((script === null || script === void 0 ? void 0 : script.type) !== 'script' || (script === null || script === void 0 ? void 0 : script.name) !== 'script') {
398
+ if (script?.type !== 'script' || script?.name !== 'script') {
406
399
  return;
407
400
  }
408
401
  return getDraftjsOembed({
@@ -437,7 +430,7 @@ function htmlDomToPullquote(dom, item) {
437
430
  for (const pullquote of dom) {
438
431
  if (pullquote.type === 'tag' && pullquote.name === 'aside' && pullquote.attribs.style === pullquoteStyle) {
439
432
  const text = pullquote.children[0];
440
- if ((text === null || text === void 0 ? void 0 : text.type) !== 'text') {
433
+ if (text?.type !== 'text') {
441
434
  return;
442
435
  }
443
436
  return getDraftjsPullquote({
@@ -594,12 +587,11 @@ function addLinks(state, links) {
594
587
  for (const block of state.blocks) {
595
588
  let blockIsCustom = false;
596
589
  for (const [i, entityRange] of block.entityRanges.entries()) {
597
- var _entity$data9;
598
590
  const entity = state.entityMap[entityRange.key];
599
591
  if (entity === undefined) {
600
592
  throw new Error('Missing entity');
601
593
  }
602
- if (i === 0 && (_entity$data9 = entity.data) !== null && _entity$data9 !== void 0 && _entity$data9.marker) {
594
+ if (i === 0 && entity.data?.marker) {
603
595
  blockIsCustom = true;
604
596
  continue;
605
597
  }
@@ -638,9 +630,8 @@ function replaceBlocks(state, replacementBlocks) {
638
630
  let removeBlockEntityKeys = false;
639
631
  const blockEntityKeys = block.entityRanges.map(range => range.key);
640
632
  if (blockEntityKeys.includes(Number(entityKey))) {
641
- var _entity$data10;
642
633
  const entity = state.entityMap[entityKey];
643
- const markerKey = (_entity$data10 = entity.data) === null || _entity$data10 === void 0 ? void 0 : _entity$data10.marker;
634
+ const markerKey = entity.data?.marker;
644
635
  const replacementBlock = replacementBlocks[markerKey];
645
636
  if (replacementBlock && !removeBlockEntityKeys) {
646
637
  const originalBlock = state.blocks[i];
@@ -650,10 +641,7 @@ function replaceBlocks(state, replacementBlocks) {
650
641
  const removeBlockEntities = entity.data.type === 'image' || entity.data.type === 'oembed';
651
642
  // eslint-disable-next-line max-depth
652
643
  if (!removeBlockEntities) {
653
- replacementBlock.entityRanges = originalBlock.entityRanges.filter(entityRange => {
654
- var _state$entityMap$enti;
655
- return ((_state$entityMap$enti = state.entityMap[entityRange.key].data) === null || _state$entityMap$enti === void 0 ? void 0 : _state$entityMap$enti.marker) === undefined;
656
- });
644
+ replacementBlock.entityRanges = originalBlock.entityRanges.filter(entityRange => state.entityMap[entityRange.key].data?.marker === undefined);
657
645
  }
658
646
  state.blocks[i] = replacementBlock;
659
647
  // eslint-disable-next-line max-depth
@@ -810,9 +798,6 @@ export function mdxToDraftjs(mdx) {
810
798
  result.entityMap = pickBy({
811
799
  ...result.entityMap,
812
800
  ...entities
813
- }, (entity, key) => {
814
- var _entity$data11;
815
- return ((_entity$data11 = entity.data) === null || _entity$data11 === void 0 ? void 0 : _entity$data11.marker) === undefined && !entityKeysToExclude.includes(Number(key));
816
- });
801
+ }, (entity, key) => entity.data?.marker === undefined && !entityKeysToExclude.includes(Number(key)));
817
802
  return result;
818
803
  }
@@ -4,7 +4,7 @@ export function toSearchParamsEntries(obj) {
4
4
  return [...obj.entries()];
5
5
  }
6
6
  if (typeof obj === 'object' && !Array.isArray(obj)) {
7
- return Object.entries(obj).map(([k, v]) => [k, (v === null || v === void 0 ? void 0 : v.toString()) ?? '']);
7
+ return Object.entries(obj).map(([k, v]) => [k, v?.toString() ?? '']);
8
8
  }
9
9
  return [...new URLSearchParams(obj).entries()];
10
10
  }
package/es/strings.js CHANGED
@@ -11,7 +11,7 @@ export const camelCase = _camelCase;
11
11
 
12
12
  export function formatShapeName(str, options) {
13
13
  const strings = ensureArray(str);
14
- const shapeNameIndex = (options === null || options === void 0 ? void 0 : options.shapeNameIndex) ?? 0;
14
+ const shapeNameIndex = options?.shapeNameIndex ?? 0;
15
15
  const shapeName = strings.at(shapeNameIndex);
16
16
 
17
17
  // If the shapeNameIndex is incorrect, behave as normal
package/es/templates.js CHANGED
@@ -22,7 +22,6 @@ export function attrs(obj) {
22
22
  return attrStrings.length ? ' ' + attrStrings.join(' ') : '';
23
23
  }
24
24
  export function imageTemplate(applyPrefix, data) {
25
- var _data$link;
26
25
  const {
27
26
  caption,
28
27
  credit,
@@ -48,7 +47,7 @@ export function imageTemplate(applyPrefix, data) {
48
47
  title: asset.title
49
48
  });
50
49
  let image = `<img${imgAttrs} src="${imageUrl}"/>`;
51
- if ((_data$link = data.link) !== null && _data$link !== void 0 && _data$link.url) {
50
+ if (data.link?.url) {
52
51
  const target = data.link.external ? ' target="blank" rel="noopener noreferrer"' : '';
53
52
  image = `<a href="${data.link.url}"${target}>${image}</a>`;
54
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takeshape/util",
3
- "version": "10.1.0",
3
+ "version": "10.2.4",
4
4
  "description": "Shared utilities",
5
5
  "homepage": "https://www.takeshape.io",
6
6
  "repository": {
@@ -33,7 +33,7 @@
33
33
  "shortid": "^2.2.16",
34
34
  "tiny-invariant": "^1.2.0",
35
35
  "url-parse": "^1.5.3",
36
- "@takeshape/routing": "10.1.0"
36
+ "@takeshape/routing": "10.2.4"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/classnames": "^2.2.9",
@@ -46,10 +46,10 @@
46
46
  "@types/prismjs": "^1.16.2",
47
47
  "@types/shortid": "^0.0.29",
48
48
  "stripe": "13.8.0",
49
- "@takeshape/typescript-jest-junit-reporter": "10.1.0"
49
+ "@takeshape/typescript-jest-junit-reporter": "10.2.4"
50
50
  },
51
51
  "engines": {
52
- "node": ">=16"
52
+ "node": ">=18"
53
53
  },
54
54
  "scripts": {
55
55
  "build": "pnpm build:js && pnpm build:es && pnpm build:types && pnpm build:copy",