bestax-migrate 2.36.2 → 2.36.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.
@@ -1 +1 @@
1
- {"version":3,"file":"specials.d.ts","sourceRoot":"","sources":["../../../src/sources/rbx/specials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAQ3C,OAAO,EAYL,KAAK,gBAAgB,EACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAcL,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;AAEtC,YAAY,EAAE,aAAa,EAAE,CAAC;AAq8B9B,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,gBAAgB,EACrB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,EAClB,OAAO,EAAE,GAAG,GACX,aAAa,CAIf"}
1
+ {"version":3,"file":"specials.d.ts","sourceRoot":"","sources":["../../../src/sources/rbx/specials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAQ3C,OAAO,EAYL,KAAK,gBAAgB,EACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAeL,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;AAEtC,YAAY,EAAE,aAAa,EAAE,CAAC;AA28B9B,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,gBAAgB,EACrB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,EAClB,OAAO,EAAE,GAAG,GACX,aAAa,CAIf"}
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import { BADGE_PROPS, RESPONSIVE_BREAKPOINTS, resolveMapping, TOOLTIP_PROPS, UNIVERSAL_PROPS, } from './mapping.js';
17
17
  import { addAttr, addTodo, buildJsxName, attributesOf, findAttr, jsxNameParts, literalValueOf, makeAttr, plainElement, removeAttr, resolveBooleanish, } from '../_shared/jsx-utils.js';
18
- import { alignTarget, applyIconProps, FIELD_SCOPED, flagDroppedHeading, keepTitleLevel, makeStripModifierProps, makeStructuralHelpers, mergeClassName, modifierClass, parseIconClasses, plainTag, restrictAsToTargets, } from '../_shared/specials-utils.js';
18
+ import { alignTarget, applyIconProps, dropLinkAttrsForPlainTag, FIELD_SCOPED, flagDroppedHeading, keepTitleLevel, makeStripModifierProps, makeStructuralHelpers, mergeClassName, modifierClass, parseIconClasses, plainTag, restrictAsToTargets, } from '../_shared/specials-utils.js';
19
19
  /* eslint-disable @typescript-eslint/no-explicit-any */
20
20
  const stripModifierProps = makeStripModifierProps(UNIVERSAL_PROPS, RESPONSIVE_BREAKPOINTS, 'innerRef');
21
21
  /**
@@ -240,10 +240,12 @@ const SPECIALS = {
240
240
  /**
241
241
  * rbx's `Loader` is Bulma's plain `.loader` spinner, which always renders.
242
242
  * bestax's `Loading` is a different thing — a dismissible overlay that
243
- * returns null unless `active` — so this emits the element rbx did.
243
+ * returns null unless `active` — so this emits the element rbx did, a
244
+ * <div> unless `as` names another.
244
245
  */
245
246
  loader(ctx, path, element) {
246
- return replaceWithPlain(ctx, path, element, 'div', 'loader', 'Loader');
247
+ const tag = plainTag(ctx, path, element, 'as', 'div', 'Loader');
248
+ return replaceWithPlain(ctx, path, element, tag, 'loader', 'Loader');
247
249
  },
248
250
  /**
249
251
  * rbx's Fieldset is a bare <fieldset>, which Bulma's base styles strip of
@@ -266,7 +268,8 @@ const SPECIALS = {
266
268
  */
267
269
  fieldset(ctx, path, element) {
268
270
  if (insideFormScope(ctx, path)) {
269
- return replaceWithPlain(ctx, path, element, 'fieldset', undefined, 'Fieldset');
271
+ const tag = plainTag(ctx, path, element, 'as', 'fieldset', 'Fieldset');
272
+ return replaceWithPlain(ctx, path, element, tag, undefined, 'Fieldset');
270
273
  }
271
274
  if (!findAttr(element, 'variant')) {
272
275
  // Before any spread, so a `variant` the spread carries still wins.
@@ -338,13 +341,21 @@ const SPECIALS = {
338
341
  ctx.dirty = true;
339
342
  return { handledProps: ['multiline'] };
340
343
  },
341
- /** bestax has no Help component; Bulma's markup is a plain <p class="help">. */
344
+ /**
345
+ * bestax has no Help component; Bulma's markup is a plain <p class="help">,
346
+ * or the element `as` names.
347
+ */
342
348
  help(ctx, path, element) {
349
+ const tag = plainTag(ctx, path, element, 'as', 'p', 'Help');
343
350
  const className = modifierClass(ctx, path, element, 'color', 'help', 'Help');
344
- return replaceWithPlain(ctx, path, element, 'p', className, 'Help');
351
+ return replaceWithPlain(ctx, path, element, tag, className, 'Help');
345
352
  },
346
- /** bestax has no standalone Label; Bulma's markup is <label class="label">. */
353
+ /**
354
+ * bestax has no standalone Label; Bulma's markup is <label class="label">,
355
+ * or the element `as` names.
356
+ */
347
357
  label(ctx, path, element) {
358
+ const tag = plainTag(ctx, path, element, 'as', 'label', 'Label');
348
359
  let className = modifierClass(ctx, path, element, 'size', 'label', 'Label');
349
360
  const disabledAttr = findAttr(element, 'disabled');
350
361
  if (disabledAttr) {
@@ -361,7 +372,7 @@ const SPECIALS = {
361
372
  }
362
373
  ctx.dirty = true;
363
374
  }
364
- return replaceWithPlain(ctx, path, element, 'label', className, 'Label');
375
+ return replaceWithPlain(ctx, path, element, tag, className, 'Label');
365
376
  },
366
377
  /**
367
378
  * rbx wraps <Select> in <Select.Container>, which owns the modifiers; the
@@ -400,7 +411,8 @@ const SPECIALS = {
400
411
  ctx.dirty = true;
401
412
  }
402
413
  addTodo(ctx, path, 'component:Select.Container', "bestax's `Select` renders a single `<select>`, so a container holding more than one has no direct equivalent; emitted the plain Bulma wrapper instead");
403
- return replaceWithPlain(ctx, path, element, 'div', cls, 'Select.Container');
414
+ const tag = plainTag(ctx, path, element, 'as', 'div', 'Select.Container');
415
+ return replaceWithPlain(ctx, path, element, tag, cls, 'Select.Container');
404
416
  }
405
417
  // A dynamic value must not simply disappear: rename it so the condition
406
418
  // survives, rather than dropping the modifier along with its expression.
@@ -473,11 +485,15 @@ const SPECIALS = {
473
485
  handledProps: ['fullwidth', 'rounded', 'state'],
474
486
  };
475
487
  },
476
- /** rbx's Select.Option is a plain <option>. */
488
+ /** rbx's Select.Option is a plain <option>, or the element `as` names. */
477
489
  'plain-option'(ctx, path, element) {
478
- return replaceWithPlain(ctx, path, element, 'option', undefined, 'Select.Option');
490
+ const tag = plainTag(ctx, path, element, 'as', 'option', 'Select.Option');
491
+ return replaceWithPlain(ctx, path, element, tag, undefined, 'Select.Option');
479
492
  },
480
- /** bestax Breadcrumb renders <ul>{children}</ul>; items are plain <li><a>. */
493
+ /**
494
+ * bestax Breadcrumb renders <ul>{children}</ul>; items are plain <li><a>.
495
+ * rbx's `as` named the element inside the <li>, an <a> by default.
496
+ */
481
497
  'breadcrumb-item'(ctx, path, element) {
482
498
  const j = ctx.j;
483
499
  const activeAttr = findAttr(element, 'active');
@@ -492,12 +508,14 @@ const SPECIALS = {
492
508
  removeAttr(element, activeAttr);
493
509
  }
494
510
  liClass = mergeClassName(ctx, path, element, liClass, 'Breadcrumb.Item');
495
- // This handler builds its <a> by hand rather than going through
511
+ const tag = plainTag(ctx, path, element, 'as', 'a', 'Breadcrumb.Item');
512
+ dropLinkAttrsForPlainTag(ctx, path, element, tag, 'Breadcrumb.Item');
513
+ // This handler builds its inner element by hand rather than going through
496
514
  // replaceWithPlain, so it has to layer the helper-prop strip itself —
497
- // otherwise rbx's badge*/tooltip* ride onto the intrinsic <a>.
515
+ // otherwise rbx's badge*/tooltip* ride onto the intrinsic element.
498
516
  const anchorAttrs = stripHelperComponentProps(ctx, path, stripModifierProps(ctx, path, attributesOf(element), 'Breadcrumb.Item'), 'Breadcrumb.Item');
499
517
  const children = element.children ?? [];
500
- const anchor = plainElement(j, 'a', undefined, anchorAttrs, children);
518
+ const anchor = plainElement(j, tag, undefined, anchorAttrs, children);
501
519
  path.replace(plainElement(j, 'li', liClass, [], [anchor]));
502
520
  ctx.dirty = true;
503
521
  return { replaced: true };
@@ -663,9 +681,11 @@ const SPECIALS = {
663
681
  },
664
682
  /**
665
683
  * rbx's Panel.Tab is one tab inside a Panel.Tab.Group; bestax's Panel.Tabs
666
- * is the group and its children are plain anchors.
684
+ * is the group and its children are plain elements, an <a> unless `as`
685
+ * names another.
667
686
  */
668
687
  'panel-tab'(ctx, path, element) {
688
+ const tag = plainTag(ctx, path, element, 'as', 'a', 'Panel.Tab');
669
689
  const activeAttr = findAttr(element, 'active');
670
690
  let className;
671
691
  if (activeAttr) {
@@ -677,7 +697,7 @@ const SPECIALS = {
677
697
  }
678
698
  removeAttr(element, activeAttr);
679
699
  }
680
- return replaceWithPlain(ctx, path, element, 'a', className, 'Panel.Tab');
700
+ return replaceWithPlain(ctx, path, element, tag, className, 'Panel.Tab');
681
701
  },
682
702
  /**
683
703
  * rbx's `Tab.Group` renders `div.tabs > ul > li`; bestax's `Tabs` renders
@@ -1 +1 @@
1
- {"version":3,"file":"specials.d.ts","sourceRoot":"","sources":["../../../src/sources/react-bulma-components/specials.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAWL,KAAK,gBAAgB,EACtB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAYL,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;AAEtC,YAAY,EAAE,aAAa,EAAE,CAAC;AA+4B9B,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,gBAAgB,EACrB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,EAClB,OAAO,EAAE,GAAG,GACX,aAAa,CAIf;AAED,kEAAkE;AAClE,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,CAGjE,CAAC"}
1
+ {"version":3,"file":"specials.d.ts","sourceRoot":"","sources":["../../../src/sources/react-bulma-components/specials.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAWL,KAAK,gBAAgB,EACtB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAYL,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;AAEtC,YAAY,EAAE,aAAa,EAAE,CAAC;AAm7B9B,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,gBAAgB,EACrB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,EAClB,OAAO,EAAE,GAAG,GACX,aAAa,CAIf;AAED,kEAAkE;AAClE,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,CAGjE,CAAC"}
@@ -351,8 +351,9 @@ const SPECIALS = {
351
351
  }
352
352
  return { handledProps: ['multiline'] };
353
353
  },
354
- /** Form.Label → plain <label className="label">. */
354
+ /** Form.Label → plain <label className="label">, or its `renderAs`. */
355
355
  'plain-label'(ctx, path, element) {
356
+ const tag = plainTag(ctx, path, element, 'renderAs', 'label', 'Form.Label');
356
357
  const sizeAttr = findAttr(element, 'size');
357
358
  let className = 'label';
358
359
  if (sizeAttr) {
@@ -367,13 +368,14 @@ const SPECIALS = {
367
368
  }
368
369
  }
369
370
  className = mergeClassName(ctx, path, element, className, 'Form.Label');
370
- const rest = keptAttrs(ctx, path, element, 'Form.Label', 'label');
371
- path.replace(plainElement(ctx.j, 'label', className, rest, element.children ?? []));
371
+ const rest = keptAttrs(ctx, path, element, 'Form.Label', tag);
372
+ path.replace(plainElement(ctx.j, tag, className, rest, element.children ?? []));
372
373
  ctx.dirty = true;
373
374
  return { replaced: true };
374
375
  },
375
- /** Form.Help → plain <p className="help is-{color}">. */
376
+ /** Form.Help → plain <p className="help is-{color}">, or its `renderAs`. */
376
377
  'plain-help'(ctx, path, element) {
378
+ const tag = plainTag(ctx, path, element, 'renderAs', 'p', 'Form.Help');
377
379
  const colorAttr = findAttr(element, 'color');
378
380
  let className = 'help';
379
381
  if (colorAttr) {
@@ -388,8 +390,8 @@ const SPECIALS = {
388
390
  }
389
391
  }
390
392
  className = mergeClassName(ctx, path, element, className, 'Form.Help');
391
- const rest = keptAttrs(ctx, path, element, 'Form.Help', 'p');
392
- path.replace(plainElement(ctx.j, 'p', className, rest, element.children ?? []));
393
+ const rest = keptAttrs(ctx, path, element, 'Form.Help', tag);
394
+ path.replace(plainElement(ctx.j, tag, className, rest, element.children ?? []));
393
395
  ctx.dirty = true;
394
396
  return { replaced: true };
395
397
  },
@@ -439,11 +441,12 @@ const SPECIALS = {
439
441
  ctx.dirty = true;
440
442
  return {};
441
443
  },
442
- /** RBC Loader is a plain <div class="loader"> — keep exactly that. */
444
+ /** RBC Loader is a plain <div class="loader">, or its `renderAs`. */
443
445
  'plain-loader'(ctx, path, element) {
446
+ const tag = plainTag(ctx, path, element, 'renderAs', 'div', 'Loader');
444
447
  const className = mergeClassName(ctx, path, element, 'loader', 'Loader');
445
- const rest = keptAttrs(ctx, path, element, 'Loader', 'div');
446
- path.replace(plainElement(ctx.j, 'div', className, rest, element.children ?? []));
448
+ const rest = keptAttrs(ctx, path, element, 'Loader', tag);
449
+ path.replace(plainElement(ctx.j, tag, className, rest, element.children ?? []));
447
450
  ctx.dirty = true;
448
451
  return { replaced: true };
449
452
  },
@@ -474,8 +477,12 @@ const SPECIALS = {
474
477
  ctx.dirty = true;
475
478
  return {};
476
479
  },
477
- /** Panel.Tabs.Tab → plain <a> (bestax Panel.Tabs children are anchors). */
480
+ /**
481
+ * Panel.Tabs.Tab → plain <a>, or its `renderAs` (bestax Panel.Tabs
482
+ * children are plain elements).
483
+ */
478
484
  'panel-tab'(ctx, path, element) {
485
+ const tag = plainTag(ctx, path, element, 'renderAs', 'a', 'Panel.Tabs.Tab');
479
486
  const activeAttr = findAttr(element, 'active');
480
487
  let className;
481
488
  if (activeAttr) {
@@ -489,12 +496,17 @@ const SPECIALS = {
489
496
  removeAttr(element, activeAttr);
490
497
  }
491
498
  className = mergeClassName(ctx, path, element, className, 'Panel.Tabs.Tab');
492
- const rest = keptAttrs(ctx, path, element, 'Panel.Tabs.Tab', 'a');
493
- path.replace(plainElement(ctx.j, 'a', className, rest, element.children ?? []));
499
+ const rest = keptAttrs(ctx, path, element, 'Panel.Tabs.Tab', tag);
500
+ path.replace(plainElement(ctx.j, tag, className, rest, element.children ?? []));
494
501
  ctx.dirty = true;
495
502
  return { replaced: true };
496
503
  },
497
- /** Breadcrumb.Item → <li className="is-active"><a href>…</a></li>. */
504
+ /**
505
+ * Breadcrumb.Item → <li className="is-active"><a href>…</a></li>. RBC
506
+ * rendered the item as its `renderAs`, an <li> by default, with the
507
+ * children inside. The <li> gets the anchor of Bulma's breadcrumb markup;
508
+ * an item that rendered another element is written as that element.
509
+ */
498
510
  'breadcrumb-item'(ctx, path, element) {
499
511
  const j = ctx.j;
500
512
  const activeAttr = findAttr(element, 'active');
@@ -510,6 +522,13 @@ const SPECIALS = {
510
522
  }
511
523
  liClass = mergeClassName(ctx, path, element, liClass, 'Breadcrumb.Item');
512
524
  const children = element.children ?? [];
525
+ const tag = plainTag(ctx, path, element, 'renderAs', 'li', 'Breadcrumb.Item');
526
+ if (tag !== 'li') {
527
+ const rest = keptAttrs(ctx, path, element, 'Breadcrumb.Item', tag);
528
+ path.replace(plainElement(j, tag, liClass, rest, children));
529
+ ctx.dirty = true;
530
+ return { replaced: true };
531
+ }
513
532
  const solidChildren = children.filter((c) => !(c.type === 'JSXText' && c.value.trim() === ''));
514
533
  // `<Breadcrumb.Item><a href>…</a></Breadcrumb.Item>` already carries its
515
534
  // own anchor — wrap it in the <li> directly instead of nesting anchors.
@@ -582,16 +601,17 @@ const SPECIALS = {
582
601
  ctx.dirty = true;
583
602
  return { replaced: true };
584
603
  }
604
+ const tag = plainTag(ctx, path, element, 'renderAs', 'div', 'Table.Container');
585
605
  const className = mergeClassName(ctx, path, element, 'table-container', 'Table.Container');
586
- const rest = keptAttrs(ctx, path, element, 'Table.Container', 'div');
587
- path.replace(plainElement(ctx.j, 'div', className, rest, element.children ?? []));
606
+ const rest = keptAttrs(ctx, path, element, 'Table.Container', tag);
607
+ path.replace(plainElement(ctx.j, tag, className, rest, element.children ?? []));
588
608
  ctx.dirty = true;
589
609
  return { replaced: true };
590
610
  },
591
611
  /**
592
- * RBC Tabs.Tab renders its own anchor; bestax Tabs.Item is the bare <li>
593
- * and Bulma styles `.tabs li a` — wrap the children in an <a> unless one
594
- * is already there.
612
+ * RBC Tabs.Tab renders its own anchor, its `renderAs`; bestax Tabs.Item is
613
+ * the bare <li> and Bulma styles `.tabs li a` — wrap the children in that
614
+ * element unless an <a> is already there.
595
615
  */
596
616
  'tab-item'(ctx, path, element) {
597
617
  const children = element.children ?? [];
@@ -604,6 +624,8 @@ const SPECIALS = {
604
624
  solid[0].openingElement.name.name === 'a';
605
625
  if (alreadyAnchor)
606
626
  return {};
627
+ const tag = plainTag(ctx, path, element, 'renderAs', 'a', 'Tabs.Tab');
628
+ dropLinkAttrsForPlainTag(ctx, path, element, tag, 'Tabs.Tab');
607
629
  const anchorKept = new Set(stripModifierProps(ctx, path, attributesOf(element).filter(a => !['active', 'className'].includes(a.name.name)), 'Tabs.Tab'));
608
630
  // The anchor takes everything that is not the tab's own state, spreads
609
631
  // included: they were the caller's props on the element that becomes the
@@ -616,7 +638,7 @@ const SPECIALS = {
616
638
  }
617
639
  }
618
640
  element.children = [
619
- plainElement(ctx.j, 'a', undefined, anchorAttrs, children),
641
+ plainElement(ctx.j, tag, undefined, anchorAttrs, children),
620
642
  ];
621
643
  ctx.dirty = true;
622
644
  return {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bestax-migrate",
3
- "version": "2.36.2",
3
+ "version": "2.36.3",
4
4
  "description": "Codemods for migrating existing React apps from other Bulma libraries to @allxsmith/bestax-bulma",
5
5
  "type": "module",
6
6
  "bin": {
@@ -40,7 +40,7 @@
40
40
  "jscodeshift": "^17.3.0",
41
41
  "parse5": "^8.1.0",
42
42
  "property-information": "^7.2.0",
43
- "@allxsmith/bestax-bulma": "^5.67.6"
43
+ "@allxsmith/bestax-bulma": "^5.67.7"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/jscodeshift": "^17.3.0",