@astryxdesign/cli 0.7.17-canary.gffd1c8e → 0.7.17
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/CHANGELOG.md +1877 -0
- package/README.md +90 -85
- package/api/build/_adapter.d.mts +51 -0
- package/api/build/_adapter.mjs +133 -8
- package/api/build/build.doc.mjs +3 -3
- package/api/build/build.mjs +1 -1
- package/api/build/build.type.d.mts +1 -1
- package/api/build/build.type.mjs +2 -2
- package/api/build/help/help.d.mts +15 -14
- package/api/build/help/help.mjs +65 -6
- package/api/build/kit/kit.mjs +1 -1
- package/api/build/kit/start.mjs +1 -1
- package/api/component/_adapter.d.mts +28 -4
- package/api/component/_adapter.mjs +79 -45
- package/api/component/component.d.mts +1 -1
- package/api/component/component.mjs +18 -7
- package/api/component/detail/blocks/blocks.mjs +1 -2
- package/api/component/detail/showcase/showcase.mjs +19 -8
- package/api/discover/_adapter.d.mts +68 -5
- package/api/discover/_adapter.mjs +311 -63
- package/api/discover/_catalog-view.d.mts +22 -0
- package/api/discover/_catalog-view.mjs +30 -1
- package/api/discover/_icon-set-coverage.d.mts +22 -0
- package/api/discover/_icon-set-coverage.mjs +32 -0
- package/api/discover/detail/detail.d.mts +6 -3
- package/api/discover/detail/detail.mjs +14 -6
- package/api/discover/detail/doc/doc.mjs +1 -1
- package/api/discover/detail/item/item.d.mts +11 -1
- package/api/discover/detail/item/item.mjs +29 -8
- package/api/discover/discover.d.mts +36 -0
- package/api/discover/discover.doc.mjs +1 -1
- package/api/discover/discover.mjs +205 -28
- package/api/discover/discover.type.d.mts +33 -7
- package/api/discover/discover.type.mjs +21 -7
- package/api/discover/search/search.d.mts +22 -0
- package/api/discover/search/search.mjs +293 -70
- package/api/docs/_adapter.d.mts +92 -1
- package/api/docs/_adapter.mjs +264 -14
- package/api/docs/docs.d.mts +4 -2
- package/api/docs/docs.doc.mjs +10 -0
- package/api/docs/docs.mjs +25 -5
- package/api/docs/docs.type.d.mts +48 -0
- package/api/docs/docs.type.mjs +26 -0
- package/api/docs/skills/skills.d.mts +51 -0
- package/api/docs/skills/skills.mjs +216 -0
- package/api/doctor/_adapter.d.mts +254 -9
- package/api/doctor/_adapter.mjs +1228 -50
- package/api/doctor/built-checks.d.mts +39 -3
- package/api/doctor/built-checks.mjs +203 -7
- package/api/doctor/doctor.d.mts +205 -4
- package/api/doctor/doctor.doc.mjs +4 -4
- package/api/doctor/doctor.mjs +962 -22
- package/api/doctor/doctor.type.d.mts +6 -1
- package/api/doctor/doctor.type.mjs +3 -1
- package/api/doctor/theme-checks.d.mts +20 -1
- package/api/doctor/theme-checks.mjs +280 -8
- package/api/error.d.mts +12 -1
- package/api/error.mjs +18 -6
- package/api/icon/_adapter.d.mts +11 -1
- package/api/icon/_adapter.mjs +22 -1
- package/api/icon/_authoring.mjs +21 -7
- package/api/icon/add/add.mjs +1 -1
- package/api/icon/definitions/definitions.mjs +19 -8
- package/api/icon/icon.doc.mjs +3 -3
- package/api/icon/icon.type.d.mts +49 -2
- package/api/icon/icon.type.mjs +23 -4
- package/api/icon/iconMap.doc.mjs +2 -2
- package/api/icon/list/list.mjs +4 -5
- package/api/icon/map/map.mjs +13 -4
- package/api/icon/search/icon-index.mjs +4 -1
- package/api/icon/search/search.d.mts +28 -7
- package/api/icon/search/search.mjs +177 -26
- package/api/init/_adapter.d.mts +87 -3
- package/api/init/_adapter.mjs +264 -16
- package/api/init/init.d.mts +2 -2
- package/api/init/init.doc.mjs +29 -5
- package/api/init/init.mjs +149 -10
- package/api/init/init.type.d.mts +75 -9
- package/api/init/init.type.mjs +32 -4
- package/api/init/remove/remove.d.mts +7 -4
- package/api/init/remove/remove.mjs +124 -26
- package/api/init/run/run.d.mts +38 -3
- package/api/init/run/run.mjs +366 -39
- package/api/integration/_adapter.d.mts +16 -0
- package/api/integration/_adapter.mjs +45 -1
- package/api/integration/integrationCheck.doc.mjs +1 -1
- package/api/integration/pack-check.d.mts +2 -1
- package/api/integration/pack-check.mjs +10 -18
- package/api/integration/validate-integration.d.mts +5 -2
- package/api/integration/validate-integration.mjs +81 -14
- package/api/integration/validate-integration.type.d.mts +9 -4
- package/api/integration/validate-integration.type.mjs +9 -4
- package/api/integration/validateIntegration.doc.mjs +4 -2
- package/api/render/_adapter.d.mts +6 -2
- package/api/render/_adapter.mjs +301 -51
- package/api/render/render.doc.d.mts +1 -1
- package/api/render/render.doc.mjs +20 -10
- package/api/render/render.mjs +16 -13
- package/api/render/render.type.d.mts +57 -10
- package/api/render/render.type.mjs +26 -13
- package/api/search/ORDERING.md +3 -3
- package/api/search/_adapter.d.mts +31 -0
- package/api/search/_adapter.mjs +107 -15
- package/api/search/_candidate-score.d.mts +12 -4
- package/api/search/_candidate-score.mjs +94 -16
- package/api/search/_cards.json +4 -1
- package/api/search/_entries.d.mts +8 -3
- package/api/search/_entries.mjs +109 -12
- package/api/search/_fit-order.d.mts +8 -4
- package/api/search/_fit-order.mjs +35 -7
- package/api/search/_gather-docs.mjs +71 -28
- package/api/search/_gather-templates.mjs +7 -2
- package/api/search/_icons.d.mts +50 -0
- package/api/search/_icons.mjs +85 -0
- package/api/search/_lexical.d.mts +14 -1
- package/api/search/_lexical.mjs +240 -12
- package/api/search/_main-searcher.mjs +1 -1
- package/api/search/_named-keywords.d.mts +6 -3
- package/api/search/_named-keywords.mjs +70 -19
- package/api/search/_order.d.mts +27 -12
- package/api/search/_order.mjs +132 -51
- package/api/search/_result.d.mts +30 -0
- package/api/search/_result.mjs +38 -0
- package/api/search/_score.d.mts +20 -6
- package/api/search/_score.mjs +96 -16
- package/api/search/_titles.d.mts +14 -0
- package/api/search/_titles.mjs +16 -3
- package/api/search/_words.d.mts +8 -0
- package/api/search/_words.mjs +26 -1
- package/api/search/search-index.mjs +23 -12
- package/api/search/search.d.mts +3 -1
- package/api/search/search.doc.mjs +5 -4
- package/api/search/search.mjs +69 -26
- package/api/search/search.type.d.mts +55 -1
- package/api/search/search.type.mjs +35 -1
- package/api/swizzle/_adapter.d.mts +1 -1
- package/api/swizzle/_adapter.mjs +1 -5
- package/api/swizzle/_moduleGraph.d.mts +0 -6
- package/api/swizzle/_moduleGraph.mjs +0 -12
- package/api/swizzle/copy/copy.mjs +1 -1
- package/api/template/_adapter.d.mts +46 -0
- package/api/template/_adapter.mjs +198 -2
- package/api/template/cdn/cdn.mjs +5 -3
- package/api/template/copy/copy.d.mts +12 -2
- package/api/template/copy/copy.mjs +95 -21
- package/api/template/list/list.mjs +1 -2
- package/api/template/show/show.d.mts +10 -3
- package/api/template/show/show.mjs +17 -6
- package/api/template/skeleton/skeleton.mjs +1 -2
- package/api/template/template.doc.mjs +3 -3
- package/api/template/template.mjs +37 -7
- package/api/template/template.type.d.mts +3 -0
- package/api/template/template.type.mjs +5 -2
- package/api/theme/_adapter.d.mts +28 -2
- package/api/theme/_adapter.mjs +675 -17
- package/api/theme/_app-provider.d.mts +42 -0
- package/api/theme/_app-provider.mjs +61 -27
- package/api/theme/_shared-source.d.mts +33 -0
- package/api/theme/_shared-source.mjs +348 -0
- package/api/theme/add/add.d.mts +3 -0
- package/api/theme/add/add.mjs +21 -4
- package/api/theme/build/build.d.mts +57 -30
- package/api/theme/build/build.mjs +403 -441
- package/api/theme/build/core-interception.d.mts +10 -0
- package/api/theme/build/core-interception.mjs +24 -0
- package/api/theme/build/family.mjs +4 -2
- package/api/theme/build/import-specifier.d.mts +14 -0
- package/api/theme/build/import-specifier.mjs +36 -0
- package/api/theme/build/null-values.d.mts +22 -0
- package/api/theme/build/null-values.mjs +110 -21
- package/api/theme/build/self-contained.mjs +32 -11
- package/api/theme/build/setting-effects.d.mts +254 -0
- package/api/theme/build/setting-effects.mjs +1065 -0
- package/api/theme/build/style-keys.d.mts +33 -0
- package/api/theme/build/style-keys.mjs +154 -0
- package/api/theme/build/theme-object.d.mts +47 -0
- package/api/theme/build/theme-object.mjs +144 -0
- package/api/theme/eject/eject.mjs +6 -1
- package/api/theme/palette/generate/color.d.mts +41 -9
- package/api/theme/palette/generate/color.mjs +108 -39
- package/api/theme/palette/generate/generate.mjs +10 -0
- package/api/theme/palette/generate/generator.d.mts +45 -27
- package/api/theme/palette/generate/generator.mjs +330 -156
- package/api/theme/palette/generate/mapping.d.mts +456 -0
- package/api/theme/palette/generate/mapping.mjs +1903 -0
- package/api/theme/palette/generate/newer-recipe.d.mts +28 -0
- package/api/theme/palette/generate/newer-recipe.mjs +87 -0
- package/api/theme/palette/generate/types.d.mts +270 -0
- package/api/theme/palette/generate/types.mjs +123 -0
- package/api/theme/theme.d.mts +25 -4
- package/api/theme/theme.mjs +55 -5
- package/api/theme/theme.type.d.mts +71 -2
- package/api/theme/theme.type.mjs +37 -5
- package/api/theme/themeAdd.doc.mjs +3 -2
- package/api/theme/themeBuild.doc.mjs +3 -3
- package/api/theme/themeEject.doc.mjs +1 -1
- package/api/theme/themeRemove.doc.mjs +1 -1
- package/api/theme/themeTargets.doc.mjs +1 -1
- package/api/theme-edit/_catalog.mjs +1 -1
- package/api/theme-edit/_check.mjs +129 -45
- package/api/theme-edit/_color.d.mts +2 -74
- package/api/theme-edit/_color.mjs +33 -869
- package/api/theme-edit/_context.d.mts +3 -1
- package/api/theme-edit/_context.mjs +16 -3
- package/api/theme-edit/_css.d.mts +4 -35
- package/api/theme-edit/_css.mjs +10 -91
- package/api/theme-edit/_edit.mjs +244 -32
- package/api/theme-edit/_how-question.d.mts +1 -0
- package/api/theme-edit/_how-question.mjs +1188 -52
- package/api/theme-edit/_how.mjs +19 -3
- package/api/theme-edit/_missed.d.mts +2 -1
- package/api/theme-edit/_missed.mjs +21 -2
- package/api/theme-edit/_normal.d.mts +5 -2
- package/api/theme-edit/_normal.mjs +11 -1
- package/api/theme-edit/_palette.d.mts +26 -75
- package/api/theme-edit/_palette.mjs +242 -1384
- package/api/theme-edit/_part-words.mjs +13 -3
- package/api/theme-edit/_parts.d.mts +8 -2
- package/api/theme-edit/_parts.mjs +56 -11
- package/api/theme-edit/_preview-app.d.mts +16 -0
- package/api/theme-edit/_preview-app.mjs +47 -15
- package/api/theme-edit/_preview.mjs +49 -22
- package/api/theme-edit/_project.d.mts +14 -2
- package/api/theme-edit/_project.mjs +25 -3
- package/api/theme-edit/_settings.d.mts +3 -2
- package/api/theme-edit/_settings.mjs +166 -45
- package/api/theme-edit/_tables.d.mts +3 -11
- package/api/theme-edit/_tables.mjs +21 -33
- package/api/theme-edit/theme-edit.type.d.mts +7 -1
- package/api/theme-edit/theme-edit.type.mjs +3 -2
- package/api/upgrade/_adapter.d.mts +38 -0
- package/api/upgrade/_adapter.mjs +274 -3
- package/api/upgrade/run/run.mjs +4 -0
- package/api/upgrade/upgrade.mjs +1 -1
- package/api/upgrade/upgrade.type.d.mts +46 -7
- package/api/upgrade/upgrade.type.mjs +24 -9
- package/assets/codemods/registry.mjs +1 -0
- package/assets/codemods/transforms/next/index.mjs +1 -11
- package/assets/codemods/transforms/v0.7.17/index.mjs +28 -0
- package/assets/codemods/transforms/v0.7.17/migrate-item-swipe-actions-to-swipe.mjs +2160 -0
- package/assets/codemods/transforms/v0.7.17/preserve-chat-radius.mjs +515 -0
- package/assets/component-list.generated.json +1 -1
- package/assets/discover/official-packages.json +72 -0
- package/assets/docs/author-a-theme.doc.mjs +7 -4
- package/assets/docs/getting-started.doc.mjs +1 -1
- package/assets/docs/principles.doc.dense.mjs +1 -1
- package/assets/docs/principles.doc.mjs +1 -1
- package/assets/docs/principles.doc.zh.mjs +1 -1
- package/assets/docs/styling-overview.doc.mjs +5 -1
- package/assets/docs/tree/agent-guidance.doc.mjs +33 -2
- package/assets/docs/tree/check-the-props.doc.mjs +1 -1
- package/assets/docs/tree/checks.doc.mjs +1 -1
- package/assets/docs/tree/computer-integrations.doc.mjs +1 -1
- package/assets/docs/tree/doc-syntax.doc.mjs +1 -1
- package/assets/docs/tree/export-pages.doc.mjs +164 -0
- package/assets/docs/tree/fonts-and-assets.doc.mjs +1 -1
- package/assets/docs/tree/host-entry.doc.mjs +4 -0
- package/assets/docs/tree/i18n-library-integration.doc.mjs +7 -3
- package/assets/docs/tree/icon-sets.doc.mjs +85 -9
- package/assets/docs/tree/layout.doc.mjs +16 -5
- package/assets/docs/tree/problems.doc.mjs +2 -2
- package/assets/docs/tree/responsive.doc.mjs +2 -2
- package/assets/docs/tree/scaffold.doc.mjs +1 -0
- package/assets/docs/tree/share-a-page.doc.mjs +14 -16
- package/assets/docs/tree/skill-places.doc.mjs +91 -0
- package/assets/docs/tree/styling.doc.mjs +41 -3
- package/assets/docs/tree/template-grading-rubric.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
- package/assets/docs/tree/tokens-and-setup.doc.mjs +2 -4
- package/assets/docs/tree/tokens-color.doc.mjs +2 -2
- package/assets/docs/tree/tokens-radius.doc.mjs +1 -1
- package/assets/docs/tree/tokens.doc.mjs +32 -0
- package/assets/docs/tree/troubleshooting.doc.mjs +8 -0
- package/assets/docs/tree/typography.doc.mjs +31 -2
- package/assets/docs/use-a-theme.doc.mjs +4 -0
- package/assets/docs/working-with-ai.doc.mjs +4 -4
- package/assets/docs-routes.generated.json +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/icons/definitions/alert.doc.mjs +9 -0
- package/assets/icons/definitions/alignBottom.doc.mjs +1 -0
- package/assets/icons/definitions/alignCenter.doc.mjs +1 -0
- package/assets/icons/definitions/alignEnd.doc.mjs +1 -0
- package/assets/icons/definitions/alignJustify.doc.mjs +1 -0
- package/assets/icons/definitions/alignMiddle.doc.mjs +1 -0
- package/assets/icons/definitions/alignStart.doc.mjs +1 -0
- package/assets/icons/definitions/alignTop.doc.mjs +1 -0
- package/assets/icons/definitions/arrowDown.doc.mjs +1 -0
- package/assets/icons/definitions/arrowLeft.doc.mjs +1 -0
- package/assets/icons/definitions/arrowRight.doc.mjs +1 -0
- package/assets/icons/definitions/arrowUp.doc.mjs +1 -0
- package/assets/icons/definitions/arrowsUpDown.doc.mjs +1 -0
- package/assets/icons/definitions/bank.doc.mjs +1 -0
- package/assets/icons/definitions/block.doc.mjs +9 -0
- package/assets/icons/definitions/bold.doc.mjs +1 -0
- package/assets/icons/definitions/bookmark.doc.mjs +1 -0
- package/assets/icons/definitions/bookmarkAdd.doc.mjs +1 -0
- package/assets/icons/definitions/cart.doc.mjs +1 -0
- package/assets/icons/definitions/channel.doc.mjs +9 -0
- package/assets/icons/definitions/check.doc.mjs +1 -0
- package/assets/icons/definitions/checkDouble.doc.mjs +1 -0
- package/assets/icons/definitions/checklist.doc.mjs +9 -0
- package/assets/icons/definitions/chevronDown.doc.mjs +1 -0
- package/assets/icons/definitions/chevronLeft.doc.mjs +1 -0
- package/assets/icons/definitions/chevronRight.doc.mjs +1 -0
- package/assets/icons/definitions/chevronUp.doc.mjs +1 -0
- package/assets/icons/definitions/chevronsLeft.doc.mjs +1 -0
- package/assets/icons/definitions/chevronsRight.doc.mjs +1 -0
- package/assets/icons/definitions/clipboard.doc.mjs +1 -0
- package/assets/icons/definitions/cloud.doc.mjs +1 -1
- package/assets/icons/definitions/collapse.doc.mjs +1 -0
- package/assets/icons/definitions/columnSettings.doc.mjs +9 -0
- package/assets/icons/definitions/compose.doc.mjs +1 -0
- package/assets/icons/definitions/conversation.doc.mjs +1 -0
- package/assets/icons/definitions/copy.doc.mjs +1 -0
- package/assets/icons/definitions/copyText.doc.mjs +9 -0
- package/assets/icons/definitions/cornerRadius.doc.mjs +1 -0
- package/assets/icons/definitions/create.doc.mjs +9 -0
- package/assets/icons/definitions/creditCard.doc.mjs +1 -0
- package/assets/icons/definitions/currency.doc.mjs +9 -0
- package/assets/icons/definitions/cut.doc.mjs +1 -0
- package/assets/icons/definitions/desktop.doc.mjs +1 -0
- package/assets/icons/definitions/discount.doc.mjs +1 -0
- package/assets/icons/definitions/document.doc.mjs +1 -0
- package/assets/icons/definitions/documentSearch.doc.mjs +1 -0
- package/assets/icons/definitions/download.doc.mjs +1 -0
- package/assets/icons/definitions/error.doc.mjs +1 -0
- package/assets/icons/definitions/exitFullScreen.doc.mjs +16 -0
- package/assets/icons/definitions/expand.doc.mjs +1 -0
- package/assets/icons/definitions/eye.doc.mjs +1 -0
- package/assets/icons/definitions/eyeSlash.doc.mjs +1 -0
- package/assets/icons/definitions/file.doc.mjs +1 -0
- package/assets/icons/definitions/flipHorizontal.doc.mjs +1 -0
- package/assets/icons/definitions/flipVertical.doc.mjs +1 -0
- package/assets/icons/definitions/folder.doc.mjs +1 -0
- package/assets/icons/definitions/folderAdd.doc.mjs +1 -0
- package/assets/icons/definitions/fullScreen.doc.mjs +16 -0
- package/assets/icons/definitions/globe.doc.mjs +1 -1
- package/assets/icons/definitions/groupRows.doc.mjs +9 -0
- package/assets/icons/definitions/halftone.doc.mjs +9 -0
- package/assets/icons/definitions/help.doc.mjs +9 -0
- package/assets/icons/definitions/house.doc.mjs +9 -0
- package/assets/icons/definitions/info.doc.mjs +1 -0
- package/assets/icons/definitions/italic.doc.mjs +1 -0
- package/assets/icons/definitions/listView.doc.mjs +9 -0
- package/assets/icons/definitions/lock.doc.mjs +1 -0
- package/assets/icons/definitions/lowercase.doc.mjs +1 -0
- package/assets/icons/definitions/mail.doc.mjs +1 -1
- package/assets/icons/definitions/media.doc.mjs +9 -0
- package/assets/icons/definitions/message.doc.mjs +2 -1
- package/assets/icons/definitions/mobile.doc.mjs +1 -0
- package/assets/icons/definitions/money.doc.mjs +1 -0
- package/assets/icons/definitions/moon.doc.mjs +1 -0
- package/assets/icons/definitions/moveToFolder.doc.mjs +9 -0
- package/assets/icons/definitions/notification.doc.mjs +1 -0
- package/assets/icons/definitions/notificationActive.doc.mjs +1 -0
- package/assets/icons/definitions/notificationOff.doc.mjs +1 -0
- package/assets/icons/definitions/paddingHorizontal.doc.mjs +1 -0
- package/assets/icons/definitions/paddingPerSide.doc.mjs +1 -0
- package/assets/icons/definitions/paddingVertical.doc.mjs +1 -0
- package/assets/icons/definitions/panelBottom.doc.mjs +1 -0
- package/assets/icons/definitions/panelLeft.doc.mjs +1 -0
- package/assets/icons/definitions/panelRight.doc.mjs +1 -0
- package/assets/icons/definitions/paste.doc.mjs +9 -0
- package/assets/icons/definitions/pause.doc.mjs +1 -0
- package/assets/icons/definitions/play.doc.mjs +1 -0
- package/assets/icons/definitions/radiusPerCorner.doc.mjs +1 -0
- package/assets/icons/definitions/redo.doc.mjs +1 -0
- package/assets/icons/definitions/review.doc.mjs +9 -0
- package/assets/icons/definitions/rotate.doc.mjs +1 -0
- package/assets/icons/definitions/rotateCounterclockwise.doc.mjs +1 -0
- package/assets/icons/definitions/scale.doc.mjs +1 -2
- package/assets/icons/definitions/schedule.doc.mjs +9 -0
- package/assets/icons/definitions/search.doc.mjs +1 -0
- package/assets/icons/definitions/send.doc.mjs +1 -0
- package/assets/icons/definitions/shoppingBag.doc.mjs +1 -0
- package/assets/icons/definitions/signal.doc.mjs +9 -0
- package/assets/icons/definitions/stop.doc.mjs +1 -0
- package/assets/icons/definitions/strikethrough.doc.mjs +1 -0
- package/assets/icons/definitions/success.doc.mjs +1 -0
- package/assets/icons/definitions/sun.doc.mjs +1 -0
- package/assets/icons/definitions/tablet.doc.mjs +1 -0
- package/assets/icons/definitions/team.doc.mjs +9 -0
- package/assets/icons/definitions/textCase.doc.mjs +2 -1
- package/assets/icons/definitions/textRegular.doc.mjs +1 -0
- package/assets/icons/definitions/thumbsDown.doc.mjs +1 -0
- package/assets/icons/definitions/thumbsUp.doc.mjs +1 -0
- package/assets/icons/definitions/transfer.doc.mjs +1 -0
- package/assets/icons/definitions/trendDown.doc.mjs +1 -0
- package/assets/icons/definitions/trendUp.doc.mjs +1 -0
- package/assets/icons/definitions/underline.doc.mjs +1 -0
- package/assets/icons/definitions/undo.doc.mjs +1 -0
- package/assets/icons/definitions/unlock.doc.mjs +1 -0
- package/assets/icons/definitions/upload.doc.mjs +1 -0
- package/assets/icons/definitions/uppercase.doc.mjs +1 -0
- package/assets/icons/definitions/user.doc.mjs +1 -0
- package/assets/icons/definitions/userAdd.doc.mjs +1 -0
- package/assets/icons/definitions/userCircle.doc.mjs +1 -0
- package/assets/icons/definitions/userRemove.doc.mjs +1 -0
- package/assets/icons/definitions/users.doc.mjs +1 -0
- package/assets/icons/definitions/verified.doc.mjs +9 -0
- package/assets/icons/definitions/wallet.doc.mjs +1 -0
- package/assets/icons/definitions/warning.doc.mjs +1 -0
- package/assets/icons/definitions/wrench.doc.mjs +1 -1
- package/assets/icons/template-icons.json +661 -0
- package/assets/search-catalog.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/AppShell/AppShellShowcase.doc.mjs +0 -7
- package/assets/templates/blocks/components/AppShell/AppShellShowcase.tsx +8 -10
- package/assets/templates/blocks/components/AppShell/AppShellSideNavOnly.doc.mjs +0 -8
- package/assets/templates/blocks/components/AppShell/AppShellSideNavOnly.tsx +10 -8
- package/assets/templates/blocks/components/AppShell/AppShellTopNavOnly.doc.mjs +0 -1
- package/assets/templates/blocks/components/AppShell/AppShellTopNavOnly.tsx +4 -2
- package/assets/templates/blocks/components/AppShell/AppShellTopNavWithSideNav.doc.mjs +0 -8
- package/assets/templates/blocks/components/AppShell/AppShellTopNavWithSideNav.tsx +10 -8
- package/assets/templates/blocks/components/AppShell/AppShellWithBanner.doc.mjs +0 -8
- package/assets/templates/blocks/components/AppShell/AppShellWithBanner.tsx +10 -8
- package/assets/templates/blocks/components/AspectRatio/AspectRatioImageGallery.tsx +1 -1
- package/assets/templates/blocks/components/AspectRatio/AspectRatioWidescreen.tsx +1 -1
- package/assets/templates/blocks/components/AspectRatio/AspectRatioWithSkeleton.tsx +1 -1
- package/assets/templates/blocks/components/Avatar/AvatarInteractive.tsx +6 -1
- package/assets/templates/blocks/components/Avatar/AvatarShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Avatar/AvatarTooltip.tsx +1 -1
- package/assets/templates/blocks/components/Avatar/AvatarWithStatus.tsx +1 -1
- package/assets/templates/blocks/components/AvatarStatusDot/AvatarStatusDotShowcase.tsx +1 -1
- package/assets/templates/blocks/components/AvatarStatusDot/AvatarStatusDotVariants.tsx +1 -1
- package/assets/templates/blocks/components/Badge/BadgeShowcase.tsx +2 -2
- package/assets/templates/blocks/components/Banner/BannerCollapsibleContent.tsx +14 -1
- package/assets/templates/blocks/components/Banner/BannerSectionVariant.tsx +10 -1
- package/assets/templates/blocks/components/Banner/BannerWithActionButton.tsx +25 -3
- package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.doc.mjs +0 -1
- package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.tsx +2 -2
- package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadMenu.doc.mjs +0 -1
- package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadMenu.tsx +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSnapPoints.doc.mjs +0 -8
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSnapPoints.tsx +5 -5
- package/assets/templates/blocks/components/BreadcrumbItem/BreadcrumbItemShowcase.doc.mjs +0 -1
- package/assets/templates/blocks/components/BreadcrumbItem/BreadcrumbItemShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Breadcrumbs/BreadcrumbsDeepHierarchy.doc.mjs +0 -1
- package/assets/templates/blocks/components/Breadcrumbs/BreadcrumbsDeepHierarchy.tsx +1 -1
- package/assets/templates/blocks/components/Breadcrumbs/BreadcrumbsWithIcons.doc.mjs +0 -1
- package/assets/templates/blocks/components/Breadcrumbs/BreadcrumbsWithIcons.tsx +2 -2
- package/assets/templates/blocks/components/Button/ButtonFloating.doc.mjs +0 -1
- package/assets/templates/blocks/components/Button/ButtonFloating.tsx +25 -2
- package/assets/templates/blocks/components/Button/ButtonShowcase.tsx +42 -4
- package/assets/templates/blocks/components/Button/ButtonSizeVariants.tsx +24 -2
- package/assets/templates/blocks/components/Button/ButtonVariants.tsx +28 -1
- package/assets/templates/blocks/components/Button/ButtonWithEndSlot.tsx +9 -0
- package/assets/templates/blocks/components/Button/ButtonWithIcon.doc.mjs +0 -6
- package/assets/templates/blocks/components/Button/ButtonWithIcon.tsx +35 -9
- package/assets/templates/blocks/components/ButtonGroup/ButtonGroupBasic.tsx +20 -3
- package/assets/templates/blocks/components/ButtonGroup/ButtonGroupFloating.tsx +16 -3
- package/assets/templates/blocks/components/ButtonGroup/ButtonGroupShowcase.doc.mjs +0 -6
- package/assets/templates/blocks/components/ButtonGroup/ButtonGroupShowcase.tsx +37 -8
- package/assets/templates/blocks/components/Center/CenterHorizontal.doc.mjs +0 -8
- package/assets/templates/blocks/components/Center/CenterHorizontal.tsx +23 -5
- package/assets/templates/blocks/components/Center/CenterInsideACard.doc.mjs +0 -1
- package/assets/templates/blocks/components/Center/CenterInsideACard.tsx +1 -1
- package/assets/templates/blocks/components/ChatComposer/ChatComposerFlat.doc.mjs +0 -5
- package/assets/templates/blocks/components/ChatComposer/ChatComposerFlat.tsx +8 -3
- package/assets/templates/blocks/components/ChatComposer/ChatComposerFooterActions.doc.mjs +0 -5
- package/assets/templates/blocks/components/ChatComposer/ChatComposerFooterActions.tsx +8 -3
- package/assets/templates/blocks/components/ChatComposer/ChatComposerFullFeatured.doc.mjs +0 -7
- package/assets/templates/blocks/components/ChatComposer/ChatComposerFullFeatured.tsx +10 -7
- package/assets/templates/blocks/components/ChatComposerDrawer/ChatComposerDrawerShowcase.doc.mjs +0 -1
- package/assets/templates/blocks/components/ChatComposerDrawer/ChatComposerDrawerShowcase.tsx +2 -2
- package/assets/templates/blocks/components/ChatComposerDrawer/ChatComposerDrawerWithProgress.doc.mjs +0 -1
- package/assets/templates/blocks/components/ChatComposerDrawer/ChatComposerDrawerWithProgress.tsx +3 -3
- package/assets/templates/blocks/components/ChatMessageMetadata/ChatMessageMetadataFooter.doc.mjs +0 -6
- package/assets/templates/blocks/components/ChatMessageMetadata/ChatMessageMetadataFooter.tsx +9 -9
- package/assets/templates/blocks/components/ChatMessageMetadata/ChatMessageMetadataShowcase.doc.mjs +0 -6
- package/assets/templates/blocks/components/ChatMessageMetadata/ChatMessageMetadataShowcase.tsx +10 -10
- package/assets/templates/blocks/components/ChatSendButton/ChatSendButtonCustomIcon.doc.mjs +0 -6
- package/assets/templates/blocks/components/ChatSendButton/ChatSendButtonCustomIcon.tsx +8 -5
- package/assets/templates/blocks/components/ChatSendButton/ChatSendButtonShowcase.doc.mjs +0 -1
- package/assets/templates/blocks/components/ChatSendButton/ChatSendButtonShowcase.tsx +1 -1
- package/assets/templates/blocks/components/ChatSystemMessage/ChatSystemMessageStatusUpdates.doc.mjs +0 -5
- package/assets/templates/blocks/components/ChatSystemMessage/ChatSystemMessageStatusUpdates.tsx +7 -7
- package/assets/templates/blocks/components/ChatSystemMessage/ChatSystemMessageWithIcon.doc.mjs +0 -6
- package/assets/templates/blocks/components/ChatSystemMessage/ChatSystemMessageWithIcon.tsx +7 -7
- package/assets/templates/blocks/components/ContextMenu/ContextMenuBottomSheet.doc.mjs +0 -6
- package/assets/templates/blocks/components/ContextMenu/ContextMenuBottomSheet.tsx +7 -7
- package/assets/templates/blocks/components/DropdownMenu/DropdownMenuBottomSheet.doc.mjs +0 -6
- package/assets/templates/blocks/components/DropdownMenu/DropdownMenuBottomSheet.tsx +7 -7
- package/assets/templates/blocks/components/DropdownMenu/DropdownMenuNoChevron.doc.mjs +0 -1
- package/assets/templates/blocks/components/DropdownMenu/DropdownMenuNoChevron.tsx +2 -2
- package/assets/templates/blocks/components/EmptyState/EmptyStateActions.doc.mjs +0 -1
- package/assets/templates/blocks/components/EmptyState/EmptyStateActions.tsx +2 -2
- package/assets/templates/blocks/components/EmptyState/EmptyStateCompact.doc.mjs +0 -1
- package/assets/templates/blocks/components/EmptyState/EmptyStateCompact.tsx +1 -1
- package/assets/templates/blocks/components/EmptyState/EmptyStateContainer.doc.mjs +0 -1
- package/assets/templates/blocks/components/EmptyState/EmptyStateContainer.tsx +2 -2
- package/assets/templates/blocks/components/EmptyState/EmptyStateShowcase.doc.mjs +0 -1
- package/assets/templates/blocks/components/EmptyState/EmptyStateShowcase.tsx +2 -2
- package/assets/templates/blocks/components/Grid/GridShowcase.tsx +1 -1
- package/assets/templates/blocks/components/GridSpan/GridSpanColumns.tsx +1 -1
- package/assets/templates/blocks/components/GridSpan/GridSpanShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Heading/HeadingTruncation.tsx +3 -2
- package/assets/templates/blocks/components/Hooks/useClipboardHookUsage.tsx +1 -1
- package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.doc.mjs +0 -1
- package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +38 -19
- package/assets/templates/blocks/components/Hooks/useGridFocusHookUsage.tsx +6 -6
- package/assets/templates/blocks/components/Hooks/useHotkeysHookUsage.tsx +1 -1
- package/assets/templates/blocks/components/Hooks/useInputContainerHookUsage.doc.mjs +0 -1
- package/assets/templates/blocks/components/Hooks/useInputContainerHookUsage.tsx +2 -2
- package/assets/templates/blocks/components/Hooks/useKeyboardHintHookUsage.doc.mjs +0 -1
- package/assets/templates/blocks/components/Hooks/useKeyboardHintHookUsage.tsx +2 -2
- package/assets/templates/blocks/components/Hooks/useListFocusHookUsage.tsx +8 -1
- package/assets/templates/blocks/components/Hooks/useOverflowHookUsage.tsx +17 -6
- package/assets/templates/blocks/components/Hooks/useStreamingTextHookUsage.tsx +1 -1
- package/assets/templates/blocks/components/Hooks/useTreeFocusHookUsage.doc.mjs +0 -1
- package/assets/templates/blocks/components/Hooks/useTreeFocusHookUsage.tsx +1 -1
- package/assets/templates/blocks/components/HoverCard/HoverCardInteractiveContent.doc.mjs +0 -1
- package/assets/templates/blocks/components/HoverCard/HoverCardInteractiveContent.tsx +1 -1
- package/assets/templates/blocks/components/HoverCard/HoverCardProfileHoverCard.doc.mjs +0 -1
- package/assets/templates/blocks/components/HoverCard/HoverCardProfileHoverCard.tsx +1 -1
- package/assets/templates/blocks/components/Icon/useIconHookUsage.doc.mjs +0 -5
- package/assets/templates/blocks/components/Icon/useIconHookUsage.tsx +7 -7
- package/assets/templates/blocks/components/IconButton/IconButtonActionBar.tsx +11 -0
- package/assets/templates/blocks/components/IconButton/IconButtonFloating.doc.mjs +0 -1
- package/assets/templates/blocks/components/IconButton/IconButtonFloating.tsx +25 -2
- package/assets/templates/blocks/components/IconButton/IconButtonShowcase.tsx +3 -0
- package/assets/templates/blocks/components/IconButton/IconButtonTooltipIconButton.tsx +5 -0
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider02Overrides.doc.mjs +3 -3
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider02Overrides.tsx +36 -13
- package/assets/templates/blocks/components/Item/ItemDocumentTabs.doc.mjs +0 -1
- package/assets/templates/blocks/components/Item/ItemDocumentTabs.tsx +4 -4
- package/assets/templates/blocks/components/Item/ItemShowcase.doc.mjs +0 -1
- package/assets/templates/blocks/components/Item/ItemShowcase.tsx +7 -3
- package/assets/templates/blocks/components/Layout/LayoutBasicCardLayout.tsx +14 -2
- package/assets/templates/blocks/components/Layout/LayoutContentWidth.tsx +14 -2
- package/assets/templates/blocks/components/Layout/LayoutFullBleedContent.tsx +8 -1
- package/assets/templates/blocks/components/Layout/LayoutShowcase.tsx +8 -1
- package/assets/templates/blocks/components/Layout/LayoutSidebarLayout.tsx +14 -2
- package/assets/templates/blocks/components/LinkProvider/LinkProviderCustomLink.tsx +3 -1
- package/assets/templates/blocks/components/Markdown/MarkdownShowcase.tsx +1 -1
- package/assets/templates/blocks/components/MediaTheme/MediaThemeImageOverlay.tsx +18 -4
- package/assets/templates/blocks/components/MediaTheme/MediaThemeLightScrim.tsx +11 -3
- package/assets/templates/blocks/components/MediaTheme/MediaThemeShowcase.tsx +27 -5
- package/assets/templates/blocks/components/MobileNav/MobileNavBasicMobileNav.doc.mjs +0 -7
- package/assets/templates/blocks/components/MobileNav/MobileNavBasicMobileNav.tsx +5 -9
- package/assets/templates/blocks/components/MobileNav/MobileNavEndSideMobileNav.doc.mjs +0 -1
- package/assets/templates/blocks/components/MobileNav/MobileNavEndSideMobileNav.tsx +2 -2
- package/assets/templates/blocks/components/MobileNav/MobileNavWithoutTitleMobileNav.doc.mjs +0 -1
- package/assets/templates/blocks/components/MobileNav/MobileNavWithoutTitleMobileNav.tsx +1 -1
- package/assets/templates/blocks/components/MoreMenu/MoreMenuBottomSheet.doc.mjs +0 -6
- package/assets/templates/blocks/components/MoreMenu/MoreMenuBottomSheet.tsx +15 -15
- package/assets/templates/blocks/components/MoreMenu/MoreMenuWithDividers.doc.mjs +0 -5
- package/assets/templates/blocks/components/MoreMenu/MoreMenuWithDividers.tsx +4 -8
- package/assets/templates/blocks/components/MoreMenu/MoreMenuWithSections.doc.mjs +0 -5
- package/assets/templates/blocks/components/MoreMenu/MoreMenuWithSections.tsx +4 -8
- package/assets/templates/blocks/components/MultiSelector/useMultiComboboxHookUsage.doc.mjs +0 -1
- package/assets/templates/blocks/components/MultiSelector/useMultiComboboxHookUsage.tsx +1 -1
- package/assets/templates/blocks/components/OverflowList/OverflowListCappedToolbar.tsx +38 -2
- package/assets/templates/blocks/components/OverflowList/OverflowListCollapseFromStartList.tsx +17 -5
- package/assets/templates/blocks/components/OverflowList/OverflowListOverflowDropdownActions.tsx +46 -7
- package/assets/templates/blocks/components/OverflowList/OverflowListShowcase.tsx +45 -5
- package/assets/templates/blocks/components/Overlay/OverlayHoverReveal.tsx +14 -1
- package/assets/templates/blocks/components/Overlay/OverlayShowcase.tsx +10 -1
- package/assets/templates/blocks/components/Overlay/useOverlayHookUsage.tsx +12 -1
- package/assets/templates/blocks/components/Pagination/PaginationDotsCarousel.doc.mjs +0 -1
- package/assets/templates/blocks/components/Pagination/PaginationDotsCarousel.tsx +1 -1
- package/assets/templates/blocks/components/Popover/PopoverBottomSheetAlternative.doc.mjs +0 -1
- package/assets/templates/blocks/components/Popover/PopoverBottomSheetAlternative.tsx +1 -1
- package/assets/templates/blocks/components/Resizable/ResizableShowcase.tsx +12 -2
- package/assets/templates/blocks/components/Resizable/ResizableSidebar.tsx +1 -1
- package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaInlineRail.tsx +1 -1
- package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaOverscrollChaining.tsx +1 -1
- package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaShowcase.tsx +1 -1
- package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaStickyGroupHeaders.tsx +1 -1
- package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaStickyPassthrough.tsx +1 -1
- package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaTwoAxisBoard.tsx +1 -1
- package/assets/templates/blocks/components/Section/SectionWashHighlight.doc.mjs +0 -1
- package/assets/templates/blocks/components/Section/SectionWashHighlight.tsx +10 -2
- package/assets/templates/blocks/components/Selector/SelectorOptionDescriptions.doc.mjs +0 -1
- package/assets/templates/blocks/components/Selector/SelectorOptionDescriptions.tsx +3 -3
- package/assets/templates/blocks/components/SelectorOption/SelectorOptionShowcase.doc.mjs +0 -1
- package/assets/templates/blocks/components/SelectorOption/SelectorOptionShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Stack/StackAlignment.tsx +50 -6
- package/assets/templates/blocks/components/Stack/StackDirections.tsx +1 -1
- package/assets/templates/blocks/components/Stack/StackFillItem.tsx +10 -1
- package/assets/templates/blocks/components/Step/StepContent.tsx +13 -4
- package/assets/templates/blocks/components/Step/StepIndicator.tsx +3 -2
- package/assets/templates/blocks/components/Step/StepShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Step/StepStates.tsx +3 -2
- package/assets/templates/blocks/components/Stepper/StepperCustomContent.tsx +18 -14
- package/assets/templates/blocks/components/Stepper/StepperOnTrackHorizontal.tsx +1 -1
- package/assets/templates/blocks/components/Table/TableInCard.tsx +1 -1
- package/assets/templates/blocks/components/Table/TableShowcase.tsx +1 -1
- package/assets/templates/blocks/components/TextArea/TextAreaWithIcon.doc.mjs +0 -1
- package/assets/templates/blocks/components/TextArea/TextAreaWithIcon.tsx +2 -2
- package/assets/templates/blocks/components/TextInput/TextInputIcon.doc.mjs +0 -1
- package/assets/templates/blocks/components/TextInput/TextInputIcon.tsx +3 -7
- package/assets/templates/blocks/components/TextInput/TextInputSearch.doc.mjs +0 -1
- package/assets/templates/blocks/components/TextInput/TextInputSearch.tsx +3 -3
- package/assets/templates/blocks/components/Theme/ThemeApply.tsx +8 -1
- package/assets/templates/blocks/components/Theme/ThemeNested.tsx +11 -1
- package/assets/templates/blocks/components/Theme/ThemeShowcase.tsx +26 -3
- package/assets/templates/blocks/components/Theme/ThemeSwitcher.tsx +8 -1
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonColor.doc.mjs +0 -11
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonColor.tsx +5 -5
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonGroup.doc.mjs +0 -9
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonGroup.tsx +5 -9
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonIconSwap.doc.mjs +0 -6
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonIconSwap.tsx +6 -6
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonLabel.doc.mjs +0 -6
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonLabel.tsx +3 -3
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonShowcase.doc.mjs +0 -6
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonShowcase.tsx +6 -6
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonStates.doc.mjs +0 -1
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonStates.tsx +2 -2
- package/assets/templates/blocks/components/Token/TokenIcon.doc.mjs +0 -6
- package/assets/templates/blocks/components/Token/TokenIcon.tsx +3 -3
- package/assets/templates/blocks/components/Token/TokenShowcase.doc.mjs +0 -1
- package/assets/templates/blocks/components/Token/TokenShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +14 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.doc.mjs +0 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +2 -2
- package/assets/templates/blocks/components/Toolbar/ToolbarBulkActions.doc.mjs +0 -1
- package/assets/templates/blocks/components/Toolbar/ToolbarBulkActions.tsx +36 -3
- package/assets/templates/blocks/components/Toolbar/ToolbarCardHeader.doc.mjs +0 -1
- package/assets/templates/blocks/components/Toolbar/ToolbarCardHeader.tsx +4 -3
- package/assets/templates/blocks/components/Toolbar/ToolbarSizes.doc.mjs +0 -1
- package/assets/templates/blocks/components/Toolbar/ToolbarSizes.tsx +3 -3
- package/assets/templates/blocks/components/Toolbar/ToolbarTableFilter.doc.mjs +0 -1
- package/assets/templates/blocks/components/Toolbar/ToolbarTableFilter.tsx +8 -3
- package/assets/templates/blocks/components/Toolbar/ToolbarThreeSlot.doc.mjs +0 -1
- package/assets/templates/blocks/components/Toolbar/ToolbarThreeSlot.tsx +6 -2
- package/assets/templates/blocks/components/Toolbar/ToolbarWithTabs.doc.mjs +0 -1
- package/assets/templates/blocks/components/Toolbar/ToolbarWithTabs.tsx +11 -2
- package/assets/templates/blocks/components/Tooltip/TooltipActionBarTooltips.tsx +33 -3
- package/assets/templates/blocks/components/TopNav/TopNavCenteredNavigation.doc.mjs +0 -1
- package/assets/templates/blocks/components/TopNav/TopNavCenteredNavigation.tsx +2 -2
- package/assets/templates/blocks/components/TopNav/TopNavEnterpriseDashboard.doc.mjs +0 -6
- package/assets/templates/blocks/components/TopNav/TopNavEnterpriseDashboard.tsx +7 -7
- package/assets/templates/blocks/components/TopNav/TopNavHoverMenu.doc.mjs +0 -8
- package/assets/templates/blocks/components/TopNav/TopNavHoverMenu.tsx +14 -9
- package/assets/templates/blocks/components/TopNav/TopNavMegaMenu.doc.mjs +0 -8
- package/assets/templates/blocks/components/TopNav/TopNavMegaMenu.tsx +11 -11
- package/assets/templates/blocks/components/TopNav/TopNavMultipleDropdowns.doc.mjs +0 -5
- package/assets/templates/blocks/components/TopNav/TopNavMultipleDropdowns.tsx +4 -8
- package/assets/templates/blocks/components/TopNav/TopNavShowcase.doc.mjs +0 -5
- package/assets/templates/blocks/components/TopNav/TopNavShowcase.tsx +8 -4
- package/assets/templates/blocks/components/TopNav/TopNavWithLogo.doc.mjs +0 -1
- package/assets/templates/blocks/components/TopNav/TopNavWithLogo.tsx +7 -2
- package/assets/templates/blocks/components/TopNavItem/TopNavItemShowcase.tsx +1 -1
- package/assets/templates/blocks/components/TopNavMegaMenu/TopNavMegaMenuBasic.doc.mjs +0 -1
- package/assets/templates/blocks/components/TopNavMegaMenu/TopNavMegaMenuBasic.tsx +4 -4
- package/assets/templates/blocks/components/TopNavMegaMenu/TopNavMegaMenuShowcase.doc.mjs +0 -7
- package/assets/templates/blocks/components/TopNavMegaMenu/TopNavMegaMenuShowcase.tsx +12 -12
- package/assets/templates/blocks/components/TopNavMegaMenuItem/TopNavMegaMenuItemBasic.doc.mjs +0 -1
- package/assets/templates/blocks/components/TopNavMegaMenuItem/TopNavMegaMenuItemBasic.tsx +2 -2
- package/assets/templates/blocks/components/TopNavMenu/TopNavMenuBasic.doc.mjs +0 -1
- package/assets/templates/blocks/components/TopNavMenu/TopNavMenuBasic.tsx +4 -4
- package/assets/templates/blocks/components/TopNavMenu/TopNavMenuShowcase.doc.mjs +0 -6
- package/assets/templates/blocks/components/TopNavMenu/TopNavMenuShowcase.tsx +11 -8
- package/assets/templates/blocks/components/TreeList/TreeListFileTreeWithIcons.doc.mjs +0 -1
- package/assets/templates/blocks/components/TreeList/TreeListFileTreeWithIcons.tsx +4 -4
- package/assets/templates/blocks/components/TreeList/TreeListInteractiveSettings.doc.mjs +0 -1
- package/assets/templates/blocks/components/TreeList/TreeListInteractiveSettings.tsx +6 -3
- package/assets/templates/blocks/components/Typeahead/TypeaheadSearchField.doc.mjs +0 -1
- package/assets/templates/blocks/components/Typeahead/TypeaheadSearchField.tsx +2 -2
- package/assets/templates/blocks/components/VisuallyHidden/VisuallyHiddenShowcase.doc.mjs +0 -6
- package/assets/templates/blocks/components/VisuallyHidden/VisuallyHiddenShowcase.tsx +30 -7
- package/assets/templates/blocks/components/VisuallyHidden/VisuallyHiddenSupplementaryContext.doc.mjs +0 -1
- package/assets/templates/blocks/components/VisuallyHidden/VisuallyHiddenSupplementaryContext.tsx +4 -1
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/page.tsx +19 -15
- package/assets/templates/pages/ai-chat/template.doc.mjs +0 -9
- package/assets/templates/pages/ai-chat-landing/page.tsx +16 -16
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +0 -11
- package/assets/templates/pages/blank/page.tsx +4 -2
- package/assets/templates/pages/canvas-editor/page.tsx +200 -110
- package/assets/templates/pages/canvas-editor/template.doc.mjs +0 -46
- package/assets/templates/pages/centered-hero/page.tsx +2 -2
- package/assets/templates/pages/centered-hero/template.doc.mjs +0 -1
- package/assets/templates/pages/checkout-wizard/page.tsx +31 -18
- package/assets/templates/pages/checkout-wizard/template.doc.mjs +0 -7
- package/assets/templates/pages/classic-gallery/page.tsx +1 -1
- package/assets/templates/pages/contact-form/page.tsx +15 -10
- package/assets/templates/pages/contact-form/template.doc.mjs +0 -5
- package/assets/templates/pages/course-detail/page.tsx +10 -10
- package/assets/templates/pages/course-detail/template.doc.mjs +0 -11
- package/assets/templates/pages/dashboard/page.tsx +13 -11
- package/assets/templates/pages/dashboard/template.doc.mjs +0 -6
- package/assets/templates/pages/dashboard-alert-rail/page.tsx +12 -12
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +0 -8
- package/assets/templates/pages/dashboard-cohort-funnel/page.tsx +7 -13
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +0 -7
- package/assets/templates/pages/dashboard-comparison/page.tsx +12 -10
- package/assets/templates/pages/dashboard-comparison/template.doc.mjs +0 -8
- package/assets/templates/pages/dashboard-composition/page.tsx +30 -19
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +0 -1
- package/assets/templates/pages/dashboard-progress/page.tsx +101 -108
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +0 -7
- package/assets/templates/pages/dashboard-scorecard/page.tsx +61 -33
- package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +0 -7
- package/assets/templates/pages/detail-page/page.tsx +28 -11
- package/assets/templates/pages/detail-page/template.doc.mjs +0 -10
- package/assets/templates/pages/documentation/page.tsx +11 -4
- package/assets/templates/pages/documentation-design/page.tsx +39 -12
- package/assets/templates/pages/documentation-design/template.doc.mjs +0 -5
- package/assets/templates/pages/documentation-technical/page.tsx +8 -6
- package/assets/templates/pages/documentation-technical/template.doc.mjs +0 -5
- package/assets/templates/pages/editor/page.tsx +70 -48
- package/assets/templates/pages/editor/template.doc.mjs +0 -26
- package/assets/templates/pages/file-explorer/page.tsx +19 -19
- package/assets/templates/pages/file-explorer/template.doc.mjs +0 -15
- package/assets/templates/pages/form-two-column/page.tsx +1 -1
- package/assets/templates/pages/form-wizard/page.tsx +12 -5
- package/assets/templates/pages/form-wizard-dialog/page.tsx +6 -2
- package/assets/templates/pages/form-wizard-inline/page.tsx +16 -12
- package/assets/templates/pages/form-wizard-inline/template.doc.mjs +0 -6
- package/assets/templates/pages/form-wizard-vertical/page.tsx +21 -24
- package/assets/templates/pages/form-wizard-vertical/template.doc.mjs +0 -13
- package/assets/templates/pages/gallery-hero/page.tsx +2 -2
- package/assets/templates/pages/gallery-hero/template.doc.mjs +0 -1
- package/assets/templates/pages/ide/page.tsx +12 -7
- package/assets/templates/pages/ide/template.doc.mjs +0 -5
- package/assets/templates/pages/incident-console/page.tsx +4 -4
- package/assets/templates/pages/incident-console/template.doc.mjs +0 -1
- package/assets/templates/pages/kanban-board/page.tsx +128 -47
- package/assets/templates/pages/kanban-board/template.doc.mjs +0 -11
- package/assets/templates/pages/library/page.tsx +34 -64
- package/assets/templates/pages/library/template.doc.mjs +0 -1
- package/assets/templates/pages/login/page.tsx +6 -4
- package/assets/templates/pages/login/template.doc.mjs +0 -1
- package/assets/templates/pages/login-card/page.tsx +6 -4
- package/assets/templates/pages/login-card/template.doc.mjs +0 -1
- package/assets/templates/pages/login-split/page.tsx +6 -5
- package/assets/templates/pages/login-split/template.doc.mjs +0 -1
- package/assets/templates/pages/login-sso/page.tsx +6 -6
- package/assets/templates/pages/login-sso/template.doc.mjs +0 -1
- package/assets/templates/pages/messaging-shell/page.tsx +14 -14
- package/assets/templates/pages/messaging-shell/template.doc.mjs +0 -9
- package/assets/templates/pages/mixed-gallery/page.tsx +1 -1
- package/assets/templates/pages/payment-form/page.tsx +50 -29
- package/assets/templates/pages/payment-form/template.doc.mjs +0 -6
- package/assets/templates/pages/product-detail/page.tsx +21 -9
- package/assets/templates/pages/product-detail/template.doc.mjs +0 -1
- package/assets/templates/pages/product-gallery/page.tsx +3 -3
- package/assets/templates/pages/product-gallery/template.doc.mjs +0 -1
- package/assets/templates/pages/settings/page.tsx +35 -14
- package/assets/templates/pages/settings/template.doc.mjs +0 -1
- package/assets/templates/pages/settings-dialog/page.tsx +96 -93
- package/assets/templates/pages/settings-dialog/template.doc.mjs +0 -53
- package/assets/templates/pages/settings-sidebar/page.tsx +74 -36
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +0 -16
- package/assets/templates/pages/shell-nav/page.tsx +32 -20
- package/assets/templates/pages/shell-nav/template.doc.mjs +0 -6
- package/assets/templates/pages/shell-side-nav/page.tsx +23 -22
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +0 -11
- package/assets/templates/pages/shell-top-nav/page.tsx +13 -13
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +0 -19
- package/assets/templates/pages/side-gallery/page.tsx +5 -2
- package/assets/templates/pages/table/page.tsx +21 -21
- package/assets/templates/pages/table/template.doc.mjs +0 -10
- package/assets/templates/pages/table-collapsible/page.tsx +8 -8
- package/assets/templates/pages/table-collapsible/template.doc.mjs +0 -6
- package/assets/templates/pages/table-comparison/page.tsx +23 -23
- package/assets/templates/pages/table-comparison/template.doc.mjs +0 -14
- package/assets/templates/pages/table-filter/page.tsx +75 -47
- package/assets/templates/pages/table-filter/template.doc.mjs +0 -19
- package/assets/templates/pages/table-grouped/page.tsx +16 -15
- package/assets/templates/pages/table-grouped/template.doc.mjs +0 -11
- package/assets/templates/pages/table-inbox/page.tsx +65 -33
- package/assets/templates/pages/table-inbox/template.doc.mjs +0 -17
- package/assets/templates/pages/table-page/page.tsx +3 -6
- package/assets/templates/pages/table-page/template.doc.mjs +0 -1
- package/assets/templates/pages/table-tree/page.tsx +35 -35
- package/assets/templates/pages/table-tree/template.doc.mjs +0 -15
- package/assets/templates/pages/theme-showcase/page.tsx +48 -43
- package/assets/templates/pages/theme-showcase/template.doc.mjs +0 -19
- package/assets/templates/pages/work-item-detail/page.tsx +60 -33
- package/assets/templates/pages/work-item-detail/template.doc.mjs +0 -12
- package/assets/templates/themes/butter/butterTheme.ts +50 -9
- package/assets/templates/themes/chocolate/chocolateTheme.ts +13 -6
- package/assets/templates/themes/gothic/gothicTheme.ts +14 -2
- package/assets/templates/themes/matcha/matchaTheme.ts +10 -2
- package/assets/templates/themes/neutral/neutralTheme.ts +16 -0
- package/assets/templates/themes/stone/stonePaletteRefs.generated.ts +1 -1
- package/assets/templates/themes/stone/stoneTheme.ts +32 -10
- package/assets/templates/themes/y2k/y2kTheme.ts +11 -3
- package/assets/theme.template.ts +17 -7
- package/authoring/config/config.doc.mjs +8 -1
- package/authoring/config/parse.mjs +15 -0
- package/authoring/config/skill-places.d.mts +23 -0
- package/authoring/config/skill-places.mjs +35 -0
- package/authoring/config/type.ts +16 -0
- package/authoring/debug/parse.d.mts +1 -1
- package/authoring/debug/type.ts +4 -0
- package/authoring/discover/parse.d.mts +2 -1
- package/authoring/discover/parse.mjs +73 -38
- package/authoring/discover/type.ts +9 -2
- package/authoring/doctypes/_schema.d.mts +36 -16
- package/authoring/doctypes/_schema.mjs +29 -0
- package/authoring/doctypes/base/type.ts +19 -0
- package/authoring/doctypes/command/command.doc.mjs +6 -0
- package/authoring/doctypes/command/type.ts +7 -0
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/authoring/doctypes/icon-definition/icon-definition.doc.mjs +16 -0
- package/authoring/doctypes/icon-definition/parse.mjs +12 -0
- package/authoring/doctypes/icon-definition/type.ts +18 -0
- package/authoring/doctypes/reference/reference.doc.mjs +13 -0
- package/authoring/doctypes/reference/skill.d.mts +29 -0
- package/authoring/doctypes/reference/skill.mjs +56 -0
- package/authoring/doctypes/reference/type.ts +19 -0
- package/authoring/gap-report/parse.d.mts +1 -1
- package/authoring/integration/integration.doc.mjs +8 -0
- package/authoring/integration/schema.d.mts +21 -3
- package/authoring/integration/schema.mjs +25 -5
- package/authoring/integration/type.ts +14 -0
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/build.doc.mjs +1 -1
- package/clients/cli/commands/build.mjs +11 -11
- package/clients/cli/commands/component.doc.mjs +3 -1
- package/clients/cli/commands/component.mjs +7 -3
- package/clients/cli/commands/discover.doc.mjs +2 -2
- package/clients/cli/commands/discover.mjs +108 -8
- package/clients/cli/commands/docs.doc.mjs +7 -2
- package/clients/cli/commands/docs.mjs +64 -172
- package/clients/cli/commands/doctor-integration-validate.doc.mjs +4 -2
- package/clients/cli/commands/doctor.doc.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +16 -3
- package/clients/cli/commands/experimental/export.mjs +64 -0
- package/clients/cli/commands/experimental/icon.mjs +67 -12
- package/clients/cli/commands/experimental/import.mjs +70 -0
- package/clients/cli/commands/experimental/index.mjs +152 -13
- package/clients/cli/commands/experimental/render-output.mjs +242 -0
- package/clients/cli/commands/experimental/theme.mjs +34 -13
- package/clients/cli/commands/experimental-export.doc.mjs +73 -0
- package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
- package/clients/cli/commands/experimental-import.doc.mjs +53 -0
- package/clients/cli/commands/experimental-theme-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +6 -1
- package/clients/cli/commands/experimental-theme.doc.mjs +1 -1
- package/clients/cli/commands/experimental.doc.mjs +4 -4
- package/clients/cli/commands/init.doc.mjs +34 -14
- package/clients/cli/commands/integration-check.doc.mjs +1 -1
- package/clients/cli/commands/mcp.doc.mjs +5 -1
- package/clients/cli/commands/search.mjs +68 -7
- package/clients/cli/commands/template.doc.mjs +14 -5
- package/clients/cli/commands/template.mjs +18 -0
- package/clients/cli/commands/theme-add.doc.mjs +6 -2
- package/clients/cli/commands/theme-remove.doc.mjs +1 -1
- package/clients/cli/commands/theme-targets.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +76 -5
- package/clients/cli/commands/upgrade.doc.mjs +2 -1
- package/clients/cli/commands.generated.json +1 -1
- package/clients/cli/index.mjs +30 -31
- package/clients/cli/lib/cli-error.mjs +20 -10
- package/clients/cli/lib/component-format.mjs +167 -74
- package/clients/cli/lib/define-command.mjs +10 -0
- package/clients/cli/lib/hook-format.mjs +28 -24
- package/clients/cli/lib/json-shim.mjs +9 -3
- package/clients/cli/lib/mcp-tools.mjs +8 -2
- package/clients/cli/lib/other-cli-words.mjs +99 -0
- package/clients/cli/lib/renamed-commands.mjs +21 -0
- package/clients/cli/lib/root-args.mjs +10 -3
- package/clients/cli/lib/stray-option.mjs +79 -1
- package/clients/cli/lib/unknown-command.mjs +406 -13
- package/clients/cli/manifest.generated.json +1 -1
- package/clients/cli/run.mjs +27 -0
- package/foundation/agent-docs/agent-doc-state.d.mts +20 -2
- package/foundation/agent-docs/agent-doc-state.mjs +71 -4
- package/foundation/agent-docs/agent-docs.d.mts +43 -4
- package/foundation/agent-docs/agent-docs.mjs +54 -5
- package/foundation/agent-docs/computer-agent-text.d.mts +28 -14
- package/foundation/agent-docs/computer-agent-text.mjs +85 -172
- package/foundation/agent-docs/folder-scope.d.mts +51 -0
- package/foundation/agent-docs/folder-scope.mjs +86 -0
- package/foundation/agent-docs/managed-skill-file.d.mts +115 -0
- package/foundation/agent-docs/managed-skill-file.mjs +224 -0
- package/foundation/agent-docs/skill-place-files.d.mts +119 -0
- package/foundation/agent-docs/skill-place-files.mjs +374 -0
- package/foundation/agent-docs/skill-places.d.mts +139 -0
- package/foundation/agent-docs/skill-places.mjs +321 -0
- package/foundation/color/css-color.d.mts +150 -0
- package/foundation/color/css-color.mjs +960 -0
- package/foundation/config/config-path.d.mts +2 -2
- package/foundation/config/config-path.mjs +5 -6
- package/foundation/config/config-writer.d.mts +5 -1
- package/foundation/config/config-writer.mjs +20 -4
- package/foundation/config/project.d.mts +3 -1
- package/foundation/config/project.mjs +8 -5
- package/foundation/config/theme-state.d.mts +13 -0
- package/foundation/config/theme-state.mjs +28 -0
- package/foundation/debug/event.d.mts +2 -1
- package/foundation/debug/event.mjs +2 -1
- package/foundation/discovery/button-actions.d.mts +220 -0
- package/foundation/discovery/button-actions.mjs +1527 -0
- package/foundation/discovery/cli-self-docs.d.mts +7 -0
- package/foundation/discovery/cli-self-docs.mjs +67 -6
- package/foundation/discovery/color-modes.d.mts +14 -0
- package/foundation/discovery/color-modes.mjs +53 -0
- package/foundation/discovery/command-pointers.d.mts +21 -4
- package/foundation/discovery/command-pointers.mjs +25 -4
- package/foundation/discovery/component-discovery.d.mts +10 -0
- package/foundation/discovery/component-discovery.mjs +99 -43
- package/foundation/discovery/component-replacement.d.mts +8 -0
- package/foundation/discovery/component-replacement.mjs +13 -0
- package/foundation/discovery/core-augmentation-points.d.mts +90 -0
- package/foundation/discovery/core-augmentation-points.mjs +1030 -0
- package/foundation/discovery/core-component-views.d.mts +15 -0
- package/foundation/discovery/core-component-views.mjs +176 -0
- package/foundation/discovery/core-elements.d.mts +29 -0
- package/foundation/discovery/core-elements.mjs +57 -0
- package/foundation/discovery/core-prop-types.d.mts +65 -0
- package/foundation/discovery/core-prop-types.mjs +221 -0
- package/foundation/discovery/core-props.d.mts +33 -0
- package/foundation/discovery/core-props.mjs +64 -0
- package/foundation/discovery/doc-types.d.mts +10 -42
- package/foundation/discovery/doc-types.mjs +26 -7
- package/foundation/discovery/docs-discovery.d.mts +33 -2
- package/foundation/discovery/docs-discovery.mjs +149 -72
- package/foundation/discovery/docs-section-key.d.mts +21 -1
- package/foundation/discovery/docs-section-key.mjs +57 -19
- package/foundation/discovery/hook-discovery.d.mts +2 -0
- package/foundation/discovery/hook-discovery.mjs +6 -5
- package/foundation/discovery/icon-definition-discovery.d.mts +155 -3
- package/foundation/discovery/icon-definition-discovery.mjs +197 -5
- package/foundation/discovery/icon-imports.d.mts +66 -0
- package/foundation/discovery/icon-imports.mjs +225 -0
- package/foundation/discovery/icon-ranking.d.mts +108 -4
- package/foundation/discovery/icon-ranking.mjs +277 -70
- package/foundation/discovery/icon-set-checks.d.mts +2 -0
- package/foundation/discovery/icon-set-checks.mjs +16 -2
- package/foundation/discovery/icon-set-discovery.d.mts +42 -2
- package/foundation/discovery/icon-set-discovery.mjs +85 -23
- package/foundation/discovery/icon-set-writer.d.mts +7 -2
- package/foundation/discovery/icon-set-writer.mjs +86 -7
- package/foundation/discovery/integration-skills.d.mts +62 -0
- package/foundation/discovery/integration-skills.mjs +116 -0
- package/foundation/discovery/module-exports.d.mts +8 -0
- package/foundation/discovery/module-exports.mjs +20 -21
- package/foundation/discovery/package-exports.d.mts +22 -0
- package/foundation/discovery/package-exports.mjs +44 -3
- package/foundation/discovery/project-typescript.d.mts +5 -1
- package/foundation/discovery/project-typescript.mjs +8 -2
- package/foundation/discovery/prop-drift.d.mts +16 -0
- package/foundation/discovery/prop-drift.mjs +154 -3
- package/foundation/discovery/replacement-aliases.d.mts +51 -0
- package/foundation/discovery/replacement-aliases.mjs +95 -0
- package/foundation/discovery/runner-allowlist.d.mts +1 -1
- package/foundation/discovery/runner-allowlist.mjs +1 -1
- package/foundation/discovery/stored-component-list.mjs +34 -2
- package/foundation/discovery/template-adapter.d.mts +26 -0
- package/foundation/discovery/template-adapter.mjs +221 -10
- package/foundation/discovery/template-destination.d.mts +14 -6
- package/foundation/discovery/template-destination.mjs +42 -8
- package/foundation/discovery/template-icon-meanings.d.mts +7 -2
- package/foundation/discovery/template-icon-meanings.mjs +52 -12
- package/foundation/discovery/template-icons.d.mts +44 -1
- package/foundation/discovery/template-icons.mjs +60 -63
- package/foundation/discovery/template-needs.d.mts +17 -8
- package/foundation/discovery/template-needs.mjs +119 -31
- package/foundation/discovery/template-placeholders.d.mts +149 -0
- package/foundation/discovery/template-placeholders.mjs +463 -0
- package/foundation/discovery/template-source-tree.d.mts +6 -3
- package/foundation/discovery/template-source-tree.mjs +8 -5
- package/foundation/discovery/theme-discovery.d.mts +8 -0
- package/foundation/discovery/theme-discovery.mjs +23 -6
- package/foundation/discovery/theme-imports.d.mts +1 -3
- package/foundation/discovery/theme-imports.mjs +5 -30
- package/foundation/doc-compiler/compile.mjs +6 -8
- package/foundation/doc-compiler/doc-syntax.d.mts +25 -1
- package/foundation/doc-compiler/doc-syntax.mjs +85 -10
- package/foundation/doc-compiler/doc-text.d.mts +52 -0
- package/foundation/doc-compiler/doc-text.mjs +176 -0
- package/foundation/doc-compiler/links.d.mts +8 -2
- package/foundation/doc-compiler/links.mjs +27 -6
- package/foundation/doc-compiler/read.d.mts +1 -1
- package/foundation/doc-compiler/stored-docs.d.mts +14 -3
- package/foundation/doc-compiler/stored-docs.mjs +12 -6
- package/foundation/env/cli-command.d.mts +68 -10
- package/foundation/env/cli-command.mjs +116 -22
- package/foundation/env/package-manager.d.mts +33 -2
- package/foundation/env/package-manager.mjs +68 -6
- package/foundation/env/user-dirs.d.mts +14 -0
- package/foundation/env/user-dirs.mjs +34 -1
- package/foundation/env/user-settings.d.mts +15 -0
- package/foundation/env/user-settings.mjs +56 -2
- package/foundation/fonts/font-stylesheet.d.mts +11 -0
- package/foundation/fonts/font-stylesheet.mjs +62 -7
- package/foundation/fs/cache-eviction.d.mts +7 -5
- package/foundation/fs/cache-eviction.mjs +20 -13
- package/foundation/fs/empty-folder.d.mts +12 -0
- package/foundation/fs/empty-folder.mjs +30 -0
- package/foundation/fs/file-protection.d.mts +11 -0
- package/foundation/fs/file-protection.mjs +49 -3
- package/foundation/fs/gather-cache.d.mts +14 -7
- package/foundation/fs/gather-cache.mjs +163 -67
- package/foundation/fs/import-url.d.mts +7 -5
- package/foundation/fs/import-url.mjs +7 -5
- package/foundation/fs/jiti-cache.d.mts +47 -26
- package/foundation/fs/jiti-cache.mjs +222 -130
- package/foundation/fs/loaded-files.d.mts +15 -1
- package/foundation/fs/loaded-files.mjs +40 -3
- package/foundation/fs/module-loader.d.mts +3 -1
- package/foundation/fs/module-loader.mjs +85 -5
- package/foundation/fs/path-safety.d.mts +1 -0
- package/foundation/fs/path-safety.mjs +2 -0
- package/foundation/fs/relative-specifier.d.mts +10 -0
- package/foundation/fs/relative-specifier.mjs +28 -0
- package/foundation/integrations/computer-integrations.mjs +11 -10
- package/foundation/integrations/icon-features.d.mts +1 -1
- package/foundation/integrations/icon-features.mjs +1 -1
- package/foundation/integrations/integration-warnings.d.mts +10 -0
- package/foundation/integrations/integration-warnings.mjs +12 -3
- package/foundation/integrations/integrations.d.mts +16 -2
- package/foundation/integrations/integrations.mjs +50 -8
- package/foundation/integrations/may-have-integrations.mjs +7 -6
- package/foundation/integrations/provider-resolution.mjs +19 -2
- package/foundation/integrations/validate-contributions.d.mts +4 -0
- package/foundation/integrations/validate-contributions.mjs +24 -0
- package/foundation/release/agent-text-worker.mjs +33 -1
- package/foundation/release/cache.d.mts +48 -3
- package/foundation/release/cache.mjs +196 -20
- package/foundation/release/choose.d.mts +5 -2
- package/foundation/release/choose.mjs +54 -4
- package/foundation/release/global-state.mjs +10 -2
- package/foundation/release/handoff.mjs +7 -1
- package/foundation/release/notices.d.mts +97 -9
- package/foundation/release/notices.mjs +381 -56
- package/foundation/release/project.d.mts +21 -4
- package/foundation/release/project.mjs +74 -42
- package/foundation/release/run-context.d.mts +6 -0
- package/foundation/release/run-context.mjs +9 -0
- package/foundation/render/assets.d.mts +7 -0
- package/foundation/render/assets.mjs +30 -17
- package/foundation/render/charts.d.mts +11 -10
- package/foundation/render/charts.mjs +112 -1
- package/foundation/render/class-alias.d.mts +23 -0
- package/foundation/render/class-alias.mjs +333 -0
- package/foundation/render/client-bundle.d.mts +183 -0
- package/foundation/render/client-bundle.mjs +1026 -0
- package/foundation/render/component-map.mjs +1 -1
- package/foundation/render/css-cut.d.mts +26 -0
- package/foundation/render/css-cut.mjs +344 -2
- package/foundation/render/dropped-text.d.mts +43 -0
- package/foundation/render/dropped-text.mjs +90 -0
- package/foundation/render/embedded-files.d.mts +24 -1
- package/foundation/render/embedded-files.mjs +41 -4
- package/foundation/render/embedded-imports.d.mts +72 -12
- package/foundation/render/embedded-imports.mjs +206 -70
- package/foundation/render/esbuild-dependency.d.mts +14 -0
- package/foundation/render/esbuild-dependency.mjs +41 -0
- package/foundation/render/file-header.d.mts +7 -2
- package/foundation/render/file-header.mjs +19 -10
- package/foundation/render/html-reader.d.mts +36 -17
- package/foundation/render/html-reader.mjs +239 -32
- package/foundation/render/image-attributes.d.mts +25 -0
- package/foundation/render/image-attributes.mjs +33 -0
- package/foundation/render/markup-edits.mjs +1 -1
- package/foundation/render/package-resolve-hooks.d.mts +54 -0
- package/foundation/render/package-resolve-hooks.mjs +144 -0
- package/foundation/render/page-host.mjs +1 -1
- package/foundation/render/page-worker.mjs +1307 -107
- package/foundation/render/picture-chrome.mjs +13 -1
- package/foundation/render/picture-playwright.mjs +13 -0
- package/foundation/render/picture-window.d.mts +18 -5
- package/foundation/render/picture-window.mjs +211 -19
- package/foundation/render/rebuild.mjs +2 -2
- package/foundation/render/remote-images.d.mts +83 -0
- package/foundation/render/remote-images.mjs +384 -0
- package/foundation/render/render-page.d.mts +214 -6
- package/foundation/render/render-page.mjs +1673 -163
- package/foundation/render/restore-folder.d.mts +13 -0
- package/foundation/render/restore-folder.mjs +30 -0
- package/foundation/render/served-packages.d.mts +14 -1
- package/foundation/render/served-packages.mjs +50 -6
- package/foundation/render/share-checks.d.mts +35 -0
- package/foundation/render/share-checks.mjs +95 -0
- package/foundation/render/source-block.d.mts +14 -3
- package/foundation/render/source-block.mjs +44 -9
- package/foundation/render/srcset.d.mts +32 -0
- package/foundation/render/srcset.mjs +64 -0
- package/foundation/render/ts-paths.d.mts +52 -1
- package/foundation/render/ts-paths.mjs +114 -4
- package/foundation/render/value-uses.d.mts +43 -0
- package/foundation/render/value-uses.mjs +110 -0
- package/foundation/response/error-codes.d.mts +2 -1
- package/foundation/response/error-codes.doc.mjs +16 -10
- package/foundation/response/error-codes.mjs +19 -8
- package/foundation/response/json.d.mts +0 -15
- package/foundation/response/json.mjs +1 -51
- package/foundation/response/response-types.doc.mjs +24 -13
- package/foundation/runtime/css-tree.d.mts +16 -0
- package/foundation/runtime/css-tree.mjs +46 -3
- package/foundation/runtime/lazy-dependencies.d.mts +7 -0
- package/foundation/runtime/lazy-dependencies.mjs +25 -3
- package/foundation/runtime/locked-versions.d.mts +4 -2
- package/foundation/runtime/locked-versions.mjs +18 -10
- package/foundation/runtime/package-root.d.mts +25 -0
- package/foundation/runtime/package-root.mjs +48 -0
- package/foundation/runtime/word-table.d.mts +18 -0
- package/foundation/runtime/word-table.mjs +33 -0
- package/foundation/suggest/other-command.d.mts +23 -0
- package/foundation/suggest/other-command.mjs +49 -5
- package/foundation/text/default-variant.d.mts +20 -0
- package/foundation/text/default-variant.mjs +24 -0
- package/foundation/text/definition-coverage.d.mts +21 -0
- package/foundation/text/definition-coverage.mjs +20 -0
- package/foundation/text/icon-set-next.d.mts +11 -10
- package/foundation/text/icon-set-next.mjs +19 -11
- package/foundation/text/string-utils.mjs +14 -41
- package/foundation/text/suggest-order.d.mts +10 -4
- package/foundation/text/suggest-order.mjs +20 -13
- package/package.json +8 -6
- package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +0 -394
- package/assets/docs/tree/render-pages.doc.mjs +0 -135
- package/clients/cli/commands/experimental/render.mjs +0 -154
- package/clients/cli/commands/experimental-render.doc.mjs +0 -73
|
@@ -0,0 +1,2160 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Codemod: migrate Item and ListItem swipe actions to createSwipe
|
|
5
|
+
*
|
|
6
|
+
* `swipeActions={X}` on `Item` and `ListItem` becomes `swipe={NAME}`, with
|
|
7
|
+
* `const NAME = createSwipe(X)` defined once. `X` is an object literal whose
|
|
8
|
+
* `leading` and `trailing` are array literals of object literals, or a
|
|
9
|
+
* conditional whose branches are such objects or nullish. The definition goes
|
|
10
|
+
* to module scope when every value outside a handler is fixed at import: a
|
|
11
|
+
* literal, a JSX element, an import or a module `const`. It goes into
|
|
12
|
+
* `useMemo` in the enclosing component or hook when they read its props or
|
|
13
|
+
* state. A `useState` or `useReducer` setter and a ref are stable, so they stay
|
|
14
|
+
* out of the dependencies. On a `ListItem`, a handler that compares the row's
|
|
15
|
+
* own `itemKey` value with `===` or `!==` takes `itemKey` from `onActivate`
|
|
16
|
+
* instead. Where it cannot move the options, `createSwipe` stays on the row
|
|
17
|
+
* with a TODO. Each entry
|
|
18
|
+
* with no `id` takes one from its static label, then its handler's name, then
|
|
19
|
+
* its side and place with a TODO. A conditional migrates only when the
|
|
20
|
+
* codemod can read every id in both branches. Its two swipes must then key
|
|
21
|
+
* alike exactly where the deprecated props did. Where those keys match, the
|
|
22
|
+
* places with no id share one id. Otherwise the props stay, with a TODO, as
|
|
23
|
+
* with an entry that spreads, or one entry against none on a side. Rows with
|
|
24
|
+
* the same options in one place share one definition. A
|
|
25
|
+
* `swipeBehavior={B}` joins the options; a static `'reveal'`, the default, is
|
|
26
|
+
* dropped. On a row that already sets `swipe`, the deprecated props do
|
|
27
|
+
* nothing, so they are removed, and so is a lone `swipeBehavior`. The
|
|
28
|
+
* `ItemSwipe*` types stay as they are.
|
|
29
|
+
*
|
|
30
|
+
* It does not follow helpers, wrappers, or types. Where it cannot see every
|
|
31
|
+
* entry, it keeps the old props and leaves a TODO instead of guessing. That
|
|
32
|
+
* covers a name, a property, a computed value, an object with a spread, an
|
|
33
|
+
* entry that is not an object literal, and a row that spreads props it cannot
|
|
34
|
+
* prove free of the deprecated props. Comments are the codemod's only report
|
|
35
|
+
* channel. Each is added once, so a second run changes nothing.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
import {
|
|
39
|
+
importedComponents,
|
|
40
|
+
resolveImportedComponent,
|
|
41
|
+
} from '../../transform-prop.mjs';
|
|
42
|
+
|
|
43
|
+
export const meta = {
|
|
44
|
+
title: 'Migrate Item and ListItem swipe actions to createSwipe',
|
|
45
|
+
description:
|
|
46
|
+
'Replaces `swipeActions={X}` and `swipeBehavior` on Item and ListItem with ' +
|
|
47
|
+
'`swipe={NAME}`, defining `NAME = createSwipe({...X, swipeBehavior})` ' +
|
|
48
|
+
'once at module scope or in useMemo, with ids named after each label or ' +
|
|
49
|
+
'handler. Keeps the old props with a TODO where it cannot see every entry ' +
|
|
50
|
+
'and where the row spreads props that may carry them.',
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const CORE_IMPORT_RE = /^@(astryxdesign|xds)\/core(?:\/|$)/;
|
|
54
|
+
const SWIPE_SOURCE = '@astryxdesign/core/Swipe';
|
|
55
|
+
const OLD_PROPS = new Set(['swipeActions', 'swipeBehavior']);
|
|
56
|
+
const COMPONENTS = new Map([
|
|
57
|
+
['Item', OLD_PROPS],
|
|
58
|
+
['ListItem', OLD_PROPS],
|
|
59
|
+
]);
|
|
60
|
+
const VALUE_COMMENT =
|
|
61
|
+
' TODO(astryx upgrade): swipeActions and swipeBehavior are deprecated ' +
|
|
62
|
+
'(DEP-0017). Pass swipe={createSwipe({leading, trailing, ' +
|
|
63
|
+
'swipeBehavior})} instead, with an id on each action; this swipeActions ' +
|
|
64
|
+
'value does not show every entry as an object literal, so it was left ' +
|
|
65
|
+
'unchanged. ';
|
|
66
|
+
const SPREAD_COMMENT =
|
|
67
|
+
' TODO(astryx upgrade): swipeActions and swipeBehavior are deprecated ' +
|
|
68
|
+
'(DEP-0017), and this row spreads props that may carry them, so it was ' +
|
|
69
|
+
'left unchanged. Pass swipe={createSwipe({leading, trailing, ' +
|
|
70
|
+
'swipeBehavior})} by hand. ';
|
|
71
|
+
|
|
72
|
+
const NAME_COMMENT =
|
|
73
|
+
' TODO(astryx upgrade): give each action here an id of its own instead ' +
|
|
74
|
+
"of its side and place, such as 'trailing-0': a row keys its swipe on the " +
|
|
75
|
+
'ids (AST-057 DEC-10). ';
|
|
76
|
+
const BRANCH_NAME_COMMENT =
|
|
77
|
+
' TODO(astryx upgrade): give each action here an id of its own instead ' +
|
|
78
|
+
"of its side and place, such as 'leading-0'. Give it the same id at the " +
|
|
79
|
+
'same side and place in both branches of the condition. A row keys its ' +
|
|
80
|
+
'swipe on the ids, and an open row closes when they change (AST-057 ' +
|
|
81
|
+
'DEC-10). ';
|
|
82
|
+
const BRANCH_KEY_COMMENT =
|
|
83
|
+
' TODO(astryx upgrade): swipeActions and swipeBehavior are deprecated ' +
|
|
84
|
+
'(DEP-0017). A row keys its actions by their ids, and an open row closes ' +
|
|
85
|
+
'when the key changes. This codemod migrates a condition only when it can ' +
|
|
86
|
+
'read every id in both branches. The two keys must then stay equal, or ' +
|
|
87
|
+
'apart, as they are now. It could not prove that here, so it left this ' +
|
|
88
|
+
'unchanged: migrate it by hand (AST-057 DEC-10). ';
|
|
89
|
+
const PLACE_COMMENT =
|
|
90
|
+
' TODO(astryx upgrade): define this swipe once, at module scope or in ' +
|
|
91
|
+
'useMemo, and read the row from the itemKey that onActivate receives ' +
|
|
92
|
+
'(AST-057 DEC-10). Its actions read values this codemod cannot move. ';
|
|
93
|
+
const ITEM_PLACE_COMMENT =
|
|
94
|
+
' TODO(astryx upgrade): define this swipe once, at module scope or in ' +
|
|
95
|
+
'useMemo (AST-057 DEC-10). Its actions read values this codemod cannot ' +
|
|
96
|
+
'move, and an Item passes no itemKey to onActivate. So define it where ' +
|
|
97
|
+
'those values live: move the row into a component of its own, or use a ' +
|
|
98
|
+
'ListItem with an itemKey. ';
|
|
99
|
+
const SWIPE_PROPS = new Set(['swipe', 'swipeActions', 'swipeBehavior']);
|
|
100
|
+
const FUNCTION_TYPES = new Set([
|
|
101
|
+
'FunctionDeclaration',
|
|
102
|
+
'FunctionExpression',
|
|
103
|
+
'ArrowFunctionExpression',
|
|
104
|
+
]);
|
|
105
|
+
const SKIPPED_KEYS = new Set([
|
|
106
|
+
'loc',
|
|
107
|
+
'start',
|
|
108
|
+
'end',
|
|
109
|
+
'range',
|
|
110
|
+
'extra',
|
|
111
|
+
'tokens',
|
|
112
|
+
'comments',
|
|
113
|
+
'leadingComments',
|
|
114
|
+
'trailingComments',
|
|
115
|
+
'original',
|
|
116
|
+
]);
|
|
117
|
+
|
|
118
|
+
const TYPE_WRAPPERS = new Set([
|
|
119
|
+
'TSAsExpression',
|
|
120
|
+
'TSSatisfiesExpression',
|
|
121
|
+
'TSTypeAssertion',
|
|
122
|
+
'TSNonNullExpression',
|
|
123
|
+
'TypeCastExpression',
|
|
124
|
+
'ParenthesizedExpression',
|
|
125
|
+
]);
|
|
126
|
+
|
|
127
|
+
/** @param {any} node */
|
|
128
|
+
function unwrap(node) {
|
|
129
|
+
let current = node;
|
|
130
|
+
while (current && TYPE_WRAPPERS.has(current.type)) {
|
|
131
|
+
current = current.expression;
|
|
132
|
+
}
|
|
133
|
+
return current;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** @param {any} attribute */
|
|
137
|
+
function attributeValue(attribute) {
|
|
138
|
+
return attribute.value?.type === 'JSXExpressionContainer'
|
|
139
|
+
? attribute.value.expression
|
|
140
|
+
: attribute.value;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** The static string of a node, or null. @param {any} node */
|
|
144
|
+
function staticString(node) {
|
|
145
|
+
const value = unwrap(node);
|
|
146
|
+
if (
|
|
147
|
+
value != null &&
|
|
148
|
+
(value.type === 'StringLiteral' || value.type === 'Literal') &&
|
|
149
|
+
typeof value.value === 'string'
|
|
150
|
+
) {
|
|
151
|
+
return value.value;
|
|
152
|
+
}
|
|
153
|
+
if (
|
|
154
|
+
value?.type === 'TemplateLiteral' &&
|
|
155
|
+
value.expressions.length === 0 &&
|
|
156
|
+
value.quasis.length === 1
|
|
157
|
+
) {
|
|
158
|
+
return value.quasis[0].value.cooked;
|
|
159
|
+
}
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** @param {any} j @param {any} node @param {string} text */
|
|
164
|
+
function addComment(j, node, text) {
|
|
165
|
+
node.comments ??= [];
|
|
166
|
+
if (node.comments.some((/** @type {any} */ c) => c.value === text)) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
node.comments.push(j.commentBlock(text, true, false));
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* `preferred`, or `preferred` with a numeric suffix, whichever no binding or
|
|
175
|
+
* reference in the file already uses.
|
|
176
|
+
* @param {any} j @param {any} root @param {string} preferred
|
|
177
|
+
*/
|
|
178
|
+
function freeName(j, root, preferred) {
|
|
179
|
+
const used = new Set();
|
|
180
|
+
root.find(j.Identifier).forEach((/** @type {any} */ p) => {
|
|
181
|
+
used.add(p.node.name);
|
|
182
|
+
});
|
|
183
|
+
if (!used.has(preferred)) {
|
|
184
|
+
return preferred;
|
|
185
|
+
}
|
|
186
|
+
let n = 2;
|
|
187
|
+
while (used.has(`${preferred}${n}`)) {
|
|
188
|
+
n++;
|
|
189
|
+
}
|
|
190
|
+
return `${preferred}${n}`;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* The value import declaration of `@astryxdesign/core/Swipe` a named
|
|
195
|
+
* specifier can join, adding one after the last import when there is none.
|
|
196
|
+
* @param {any} j @param {any} root
|
|
197
|
+
*/
|
|
198
|
+
function swipeImport(j, root) {
|
|
199
|
+
const existing = root
|
|
200
|
+
.find(j.ImportDeclaration)
|
|
201
|
+
.filter(
|
|
202
|
+
(/** @type {any} */ p) =>
|
|
203
|
+
p.node.source.value === SWIPE_SOURCE &&
|
|
204
|
+
p.node.importKind !== 'type' &&
|
|
205
|
+
!(p.node.specifiers ?? []).some(
|
|
206
|
+
(/** @type {any} */ s) => s.type === 'ImportNamespaceSpecifier',
|
|
207
|
+
),
|
|
208
|
+
);
|
|
209
|
+
if (existing.size() > 0) {
|
|
210
|
+
return existing.get().node;
|
|
211
|
+
}
|
|
212
|
+
const declaration = j.importDeclaration([], j.stringLiteral(SWIPE_SOURCE));
|
|
213
|
+
const imports = root.find(j.ImportDeclaration);
|
|
214
|
+
if (imports.size() > 0) {
|
|
215
|
+
imports.at(imports.size() - 1).insertAfter(declaration);
|
|
216
|
+
} else {
|
|
217
|
+
root.get().node.program.body.unshift(declaration);
|
|
218
|
+
}
|
|
219
|
+
return declaration;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* The local name `createSwipe` is imported under, adding the import
|
|
224
|
+
* when the file has none.
|
|
225
|
+
* @param {any} j @param {any} root
|
|
226
|
+
*/
|
|
227
|
+
function ensureCreateImport(j, root) {
|
|
228
|
+
let local = null;
|
|
229
|
+
root
|
|
230
|
+
.find(j.ImportDeclaration)
|
|
231
|
+
.filter(
|
|
232
|
+
(/** @type {any} */ p) =>
|
|
233
|
+
CORE_IMPORT_RE.test(p.node.source.value) &&
|
|
234
|
+
p.node.importKind !== 'type',
|
|
235
|
+
)
|
|
236
|
+
.forEach((/** @type {any} */ p) => {
|
|
237
|
+
for (const specifier of p.node.specifiers ?? []) {
|
|
238
|
+
if (
|
|
239
|
+
specifier.type === 'ImportSpecifier' &&
|
|
240
|
+
specifier.importKind !== 'type' &&
|
|
241
|
+
specifier.imported.name === 'createSwipe'
|
|
242
|
+
) {
|
|
243
|
+
local = specifier.local?.name ?? 'createSwipe';
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
if (local != null) {
|
|
248
|
+
return local;
|
|
249
|
+
}
|
|
250
|
+
const name = freeName(j, root, 'createSwipe');
|
|
251
|
+
swipeImport(j, root).specifiers.push(
|
|
252
|
+
name === 'createSwipe'
|
|
253
|
+
? j.importSpecifier(j.identifier('createSwipe'))
|
|
254
|
+
: j.importSpecifier(j.identifier('createSwipe'), j.identifier(name)),
|
|
255
|
+
);
|
|
256
|
+
return name;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* The options `swipeActions={value}` and `swipeBehavior` give: the value
|
|
261
|
+
* itself, or an object with the behavior merged in.
|
|
262
|
+
* @param {any} j @param {any} value @param {any} behavior
|
|
263
|
+
*/
|
|
264
|
+
function optionsOf(j, value, behavior) {
|
|
265
|
+
if (behavior == null) {
|
|
266
|
+
return value;
|
|
267
|
+
}
|
|
268
|
+
const property = j.objectProperty(j.identifier('swipeBehavior'), behavior);
|
|
269
|
+
const object = unwrap(value);
|
|
270
|
+
object.properties = object.properties.filter(
|
|
271
|
+
(/** @type {any} */ p) =>
|
|
272
|
+
!(
|
|
273
|
+
(p.type === 'ObjectProperty' || p.type === 'Property') &&
|
|
274
|
+
!p.computed &&
|
|
275
|
+
(p.key?.name ?? p.key?.value) === 'swipeBehavior'
|
|
276
|
+
),
|
|
277
|
+
);
|
|
278
|
+
object.properties.push(property);
|
|
279
|
+
return object;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** A property's own name, or null for a computed key or a spread. */
|
|
283
|
+
function keyOf(/** @type {any} */ property) {
|
|
284
|
+
if (
|
|
285
|
+
(property.type !== 'ObjectProperty' && property.type !== 'Property') ||
|
|
286
|
+
property.computed
|
|
287
|
+
) {
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
return property.key?.name ?? property.key?.value ?? null;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* The entries of an inline swipeActions object, by side. Null when it hides
|
|
295
|
+
* one: a spread, a side that is no array literal, or an entry that is no
|
|
296
|
+
* object literal.
|
|
297
|
+
* @param {any} object
|
|
298
|
+
*/
|
|
299
|
+
function visibleEntries(object) {
|
|
300
|
+
/** @type {Array<[string, any[]]>} */
|
|
301
|
+
const sides = [];
|
|
302
|
+
for (const property of object.properties) {
|
|
303
|
+
const key = keyOf(property);
|
|
304
|
+
if (key == null) {
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
if (key !== 'leading' && key !== 'trailing') {
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
const array = unwrap(property.value);
|
|
311
|
+
if (
|
|
312
|
+
array?.type !== 'ArrayExpression' ||
|
|
313
|
+
array.elements.some(
|
|
314
|
+
(/** @type {any} */ e) => unwrap(e)?.type !== 'ObjectExpression',
|
|
315
|
+
)
|
|
316
|
+
) {
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
sides.push([key, array.elements.map(unwrap)]);
|
|
320
|
+
}
|
|
321
|
+
return sides;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** Whether a node is `undefined` or `null`. @param {any} node */
|
|
325
|
+
function isNullish(node) {
|
|
326
|
+
const value = unwrap(node);
|
|
327
|
+
return (
|
|
328
|
+
(value?.type === 'Identifier' && value.name === 'undefined') ||
|
|
329
|
+
value?.type === 'NullLiteral' ||
|
|
330
|
+
(value?.type === 'Literal' && value.value === null)
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* The object literals a swipeActions value gives, each with its entries by
|
|
336
|
+
* side: the value itself, or each branch of a conditional that is not
|
|
337
|
+
* nullish. Null when any of them hides an entry.
|
|
338
|
+
* @param {any} value
|
|
339
|
+
* @returns {Array<{object: any, sides: Array<[string, any[]]>, replace: ((expression: any) => void) | null}> | null}
|
|
340
|
+
*/
|
|
341
|
+
function swipeObjects(value) {
|
|
342
|
+
const node = unwrap(value);
|
|
343
|
+
if (node?.type === 'ObjectExpression') {
|
|
344
|
+
const sides = visibleEntries(node);
|
|
345
|
+
return sides == null ? null : [{object: node, sides, replace: null}];
|
|
346
|
+
}
|
|
347
|
+
if (node?.type !== 'ConditionalExpression') {
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
const objects = [];
|
|
351
|
+
for (const branch of ['consequent', 'alternate']) {
|
|
352
|
+
const branchNode = unwrap(node[branch]);
|
|
353
|
+
if (isNullish(branchNode)) {
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
const sides =
|
|
357
|
+
branchNode?.type === 'ObjectExpression'
|
|
358
|
+
? visibleEntries(branchNode)
|
|
359
|
+
: null;
|
|
360
|
+
if (sides == null) {
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
objects.push({
|
|
364
|
+
object: branchNode,
|
|
365
|
+
sides,
|
|
366
|
+
replace: (/** @type {any} */ expression) => {
|
|
367
|
+
node[branch] = expression;
|
|
368
|
+
},
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
return objects.length === 0 ? null : objects;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/** A kebab-case id from text, or null when none fits. @param {string} text */
|
|
375
|
+
function slug(text) {
|
|
376
|
+
const id = text
|
|
377
|
+
.toLowerCase()
|
|
378
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
379
|
+
.replace(/^-+|-+$/g, '');
|
|
380
|
+
return /^[a-z]/.test(id) ? id : null;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* An id from a handler: its name, or the name of the one function it calls,
|
|
385
|
+
* without a `handle` or `on` prefix. Null when it names nothing.
|
|
386
|
+
* @param {any} node
|
|
387
|
+
*/
|
|
388
|
+
function handlerId(node) {
|
|
389
|
+
let callee = unwrap(node);
|
|
390
|
+
if (
|
|
391
|
+
callee?.type === 'ArrowFunctionExpression' ||
|
|
392
|
+
callee?.type === 'FunctionExpression'
|
|
393
|
+
) {
|
|
394
|
+
let body = callee.body;
|
|
395
|
+
if (body?.type === 'BlockStatement') {
|
|
396
|
+
if (
|
|
397
|
+
body.body.length !== 1 ||
|
|
398
|
+
body.body[0].type !== 'ExpressionStatement'
|
|
399
|
+
) {
|
|
400
|
+
return null;
|
|
401
|
+
}
|
|
402
|
+
body = body.body[0].expression;
|
|
403
|
+
}
|
|
404
|
+
body = unwrap(body);
|
|
405
|
+
if (body?.type !== 'CallExpression') {
|
|
406
|
+
return null;
|
|
407
|
+
}
|
|
408
|
+
callee = unwrap(body.callee);
|
|
409
|
+
}
|
|
410
|
+
const name =
|
|
411
|
+
callee?.type === 'Identifier'
|
|
412
|
+
? callee.name
|
|
413
|
+
: (callee?.type === 'MemberExpression' ||
|
|
414
|
+
callee?.type === 'OptionalMemberExpression') &&
|
|
415
|
+
!callee.computed &&
|
|
416
|
+
callee.property?.type === 'Identifier'
|
|
417
|
+
? callee.property.name
|
|
418
|
+
: null;
|
|
419
|
+
if (name == null) {
|
|
420
|
+
return null;
|
|
421
|
+
}
|
|
422
|
+
const verb = name.replace(/^(?:handle|on)(?=[A-Z])/, '');
|
|
423
|
+
return slug(verb.replace(/([a-z0-9])([A-Z])/g, '$1 $2'));
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** An entry's `id` property, or undefined. @param {any} entry */
|
|
427
|
+
function idPropertyOf(entry) {
|
|
428
|
+
return entry.properties.find((/** @type {any} */ p) => keyOf(p) === 'id');
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* The id an entry's label gives, else the one its handler gives, or null.
|
|
433
|
+
* @param {any} entry @param {'label' | 'onActivate'} from
|
|
434
|
+
*/
|
|
435
|
+
function derivedId(entry, from) {
|
|
436
|
+
const value = entry.properties.find(
|
|
437
|
+
(/** @type {any} */ p) => keyOf(p) === from,
|
|
438
|
+
)?.value;
|
|
439
|
+
if (from === 'onActivate') {
|
|
440
|
+
return handlerId(value);
|
|
441
|
+
}
|
|
442
|
+
const label = staticString(value);
|
|
443
|
+
return label == null ? null : slug(label);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* A side's entries, as the deprecated props give them to the swipe layer:
|
|
448
|
+
* its array, or none. A later property of the same name wins, as in JS.
|
|
449
|
+
* @param {Array<[string, any[]]>} sides @param {string} name
|
|
450
|
+
* @returns {any[]}
|
|
451
|
+
*/
|
|
452
|
+
function sideEntries(sides, name) {
|
|
453
|
+
let entries = /** @type {any[]} */ ([]);
|
|
454
|
+
for (const [key, list] of sides) {
|
|
455
|
+
if (key === name) {
|
|
456
|
+
entries = list;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return entries;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* The id an entry gives when the codemod can read it: the entry's `id` text,
|
|
464
|
+
* or '' with no `id`. Undefined when it cannot be sure: an entry with a
|
|
465
|
+
* spread, a computed key, a method or accessor, or two `id`s. So is one whose
|
|
466
|
+
* `id` is not a non-empty string literal.
|
|
467
|
+
* @param {any} entry
|
|
468
|
+
* @returns {string | undefined}
|
|
469
|
+
*/
|
|
470
|
+
function readableId(entry) {
|
|
471
|
+
let id = '';
|
|
472
|
+
let ids = 0;
|
|
473
|
+
for (const property of entry.properties) {
|
|
474
|
+
const key = keyOf(property);
|
|
475
|
+
if (key == null || property.kind === 'get' || property.kind === 'set') {
|
|
476
|
+
return undefined;
|
|
477
|
+
}
|
|
478
|
+
if (key === 'id') {
|
|
479
|
+
ids++;
|
|
480
|
+
id = staticString(property.value) ?? '';
|
|
481
|
+
if (ids > 1 || id === '') {
|
|
482
|
+
return undefined;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return id;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* The key a row compares when its swipe changes, as `idsKeyOf` in
|
|
491
|
+
* `SwipeActionsLayer.tsx` builds it. Item renders that layer for the
|
|
492
|
+
* deprecated props too, with their `leading` and `trailing`, or `[]`. Each
|
|
493
|
+
* entry gives its id, or '' with none, and each side joins them. `assigned`
|
|
494
|
+
* gives the ids a plan writes. Undefined when an entry's id is unreadable
|
|
495
|
+
* (`readableId`).
|
|
496
|
+
* @param {Array<[string, any[]]>} sides @param {Map<any, string>} [assigned]
|
|
497
|
+
* @returns {string | undefined}
|
|
498
|
+
*/
|
|
499
|
+
function branchKey(sides, assigned = new Map()) {
|
|
500
|
+
const parts = [];
|
|
501
|
+
for (const side of ['leading', 'trailing']) {
|
|
502
|
+
const ids = [];
|
|
503
|
+
for (const entry of sideEntries(sides, side)) {
|
|
504
|
+
const id = assigned.get(entry) ?? readableId(entry);
|
|
505
|
+
if (id === undefined) {
|
|
506
|
+
return undefined;
|
|
507
|
+
}
|
|
508
|
+
ids.push(id);
|
|
509
|
+
}
|
|
510
|
+
parts.push(ids.join('\u0000'));
|
|
511
|
+
}
|
|
512
|
+
return parts.join('\u0001');
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* The ids the entries of both branches set.
|
|
517
|
+
* @param {Array<{sides: Array<[string, any[]]>}>} objects
|
|
518
|
+
*/
|
|
519
|
+
function literalIds(objects) {
|
|
520
|
+
const ids = new Set();
|
|
521
|
+
for (const {sides} of objects) {
|
|
522
|
+
for (const [, entries] of sides) {
|
|
523
|
+
for (const entry of entries) {
|
|
524
|
+
const id = readableId(entry);
|
|
525
|
+
if (id) {
|
|
526
|
+
ids.add(id);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
return ids;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* The ids a conditional's two branches share at each place with no id in
|
|
536
|
+
* both, where a side has as many entries in both. It is their label's when
|
|
537
|
+
* the labels give the same one, else their handler's, else their side and
|
|
538
|
+
* place.
|
|
539
|
+
* @param {Array<{sides: Array<[string, any[]]>}>} objects
|
|
540
|
+
* @param {Set<string>} reserved
|
|
541
|
+
* @returns {Map<any, {id: string, positional: boolean}>}
|
|
542
|
+
*/
|
|
543
|
+
function sharedIds(objects, reserved) {
|
|
544
|
+
/** @type {Map<any, {id: string, positional: boolean}>} */
|
|
545
|
+
const shared = new Map();
|
|
546
|
+
const [first, second] = objects;
|
|
547
|
+
const taken = new Set(reserved);
|
|
548
|
+
for (const side of ['leading', 'trailing']) {
|
|
549
|
+
const entries = sideEntries(first.sides, side);
|
|
550
|
+
const others = sideEntries(second.sides, side);
|
|
551
|
+
if (entries.length !== others.length) {
|
|
552
|
+
continue;
|
|
553
|
+
}
|
|
554
|
+
entries.forEach((entry, index) => {
|
|
555
|
+
const other = others[index];
|
|
556
|
+
if (idPropertyOf(entry) != null || idPropertyOf(other) != null) {
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
const same = (/** @type {'label' | 'onActivate'} */ from) => {
|
|
560
|
+
const id = derivedId(entry, from);
|
|
561
|
+
return id != null && id === derivedId(other, from) ? id : null;
|
|
562
|
+
};
|
|
563
|
+
const common = same('label') ?? same('onActivate');
|
|
564
|
+
const id = common ?? `${side}-${index}`;
|
|
565
|
+
let unique = id;
|
|
566
|
+
for (let n = 2; taken.has(unique); n++) {
|
|
567
|
+
unique = `${id}-${n}`;
|
|
568
|
+
}
|
|
569
|
+
taken.add(unique);
|
|
570
|
+
const assigned = {id: unique, positional: common == null};
|
|
571
|
+
shared.set(entry, assigned);
|
|
572
|
+
shared.set(other, assigned);
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
return shared;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* @typedef {{
|
|
580
|
+
* ids: Array<string | null>,
|
|
581
|
+
* positional: boolean,
|
|
582
|
+
* branchPositional: boolean,
|
|
583
|
+
* assigned: Array<[any, string]>,
|
|
584
|
+
* }} IdPlan
|
|
585
|
+
*/
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* The id each entry with no `id` takes: from its static label, then from its
|
|
589
|
+
* handler, then from its side and place. `createSwipe` needs an `id` on every
|
|
590
|
+
* action, and the ids stay unique in the swipe. An entry in `shared` takes
|
|
591
|
+
* the id its conditional's branches share (`sharedIds`); `branchPositional`
|
|
592
|
+
* says one of those is its side and place. No id it plans is in
|
|
593
|
+
* `reserved`. It writes nothing (`applyIds`).
|
|
594
|
+
* @param {Array<[string, any[]]>} sides
|
|
595
|
+
* @param {Map<any, {id: string, positional: boolean}>} [shared]
|
|
596
|
+
* @param {Set<string>} [reserved]
|
|
597
|
+
* @returns {IdPlan}
|
|
598
|
+
*/
|
|
599
|
+
function planIds(sides, shared = new Map(), reserved = new Set()) {
|
|
600
|
+
const taken = new Set(reserved);
|
|
601
|
+
for (const [, entries] of sides) {
|
|
602
|
+
for (const entry of entries) {
|
|
603
|
+
const id = idPropertyOf(entry);
|
|
604
|
+
if (id != null && staticString(id.value) != null) {
|
|
605
|
+
taken.add(staticString(id.value));
|
|
606
|
+
}
|
|
607
|
+
const preset = shared.get(entry);
|
|
608
|
+
if (preset != null) {
|
|
609
|
+
taken.add(preset.id);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
/** @type {Array<string | null>} */
|
|
614
|
+
const ids = [];
|
|
615
|
+
/** @type {Array<[any, string]>} */
|
|
616
|
+
const assigned = [];
|
|
617
|
+
let positional = false;
|
|
618
|
+
let branchPositional = false;
|
|
619
|
+
for (const [side, entries] of sides) {
|
|
620
|
+
entries.forEach((entry, index) => {
|
|
621
|
+
const existing = idPropertyOf(entry);
|
|
622
|
+
if (existing != null) {
|
|
623
|
+
ids.push(staticString(existing.value));
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
const preset = shared.get(entry);
|
|
627
|
+
if (preset != null) {
|
|
628
|
+
positional ||= preset.positional;
|
|
629
|
+
branchPositional ||= preset.positional;
|
|
630
|
+
ids.push(preset.id);
|
|
631
|
+
assigned.push([entry, preset.id]);
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
let id = derivedId(entry, 'label') ?? derivedId(entry, 'onActivate');
|
|
635
|
+
if (id == null) {
|
|
636
|
+
positional = true;
|
|
637
|
+
id = `${side}-${index}`;
|
|
638
|
+
}
|
|
639
|
+
let unique = id;
|
|
640
|
+
for (let n = 2; taken.has(unique); n++) {
|
|
641
|
+
unique = `${id}-${n}`;
|
|
642
|
+
}
|
|
643
|
+
taken.add(unique);
|
|
644
|
+
ids.push(unique);
|
|
645
|
+
assigned.push([entry, unique]);
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
return {ids, positional, branchPositional, assigned};
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Writes a plan's ids into its entries (`planIds`), and returns the plan.
|
|
653
|
+
* @param {any} j @param {IdPlan} plan
|
|
654
|
+
*/
|
|
655
|
+
function applyIds(j, plan) {
|
|
656
|
+
for (const [entry, id] of plan.assigned) {
|
|
657
|
+
entry.properties.unshift(
|
|
658
|
+
j.objectProperty(j.identifier('id'), j.stringLiteral(id)),
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
return plan;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* Gives each entry with no `id` one (`planIds`), and returns the plan.
|
|
666
|
+
* @param {any} j @param {Array<[string, any[]]>} sides
|
|
667
|
+
*/
|
|
668
|
+
function entryIds(j, sides) {
|
|
669
|
+
return applyIds(j, planIds(sides));
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* The ids each branch of a conditional takes, planned before any is written.
|
|
674
|
+
* A condition migrates only when the codemod can read every id in both
|
|
675
|
+
* branches. The planned ids must then keep the two keys alike exactly where
|
|
676
|
+
* the deprecated props did (`branchKey`). That check is the only gate. Where
|
|
677
|
+
* the keys match, the places with no id share ids. Else each branch takes its
|
|
678
|
+
* own, and none matches an id either branch sets. Null when the check fails.
|
|
679
|
+
* @param {Array<{sides: Array<[string, any[]]>}>} objects
|
|
680
|
+
* @returns {IdPlan[] | null}
|
|
681
|
+
*/
|
|
682
|
+
function branchPlans(objects) {
|
|
683
|
+
const before = objects.map(({sides}) => branchKey(sides));
|
|
684
|
+
if (before.some(key => key === undefined)) {
|
|
685
|
+
return null;
|
|
686
|
+
}
|
|
687
|
+
const alike = before[0] === before[1];
|
|
688
|
+
const reserved = literalIds(objects);
|
|
689
|
+
const shared = alike ? sharedIds(objects, reserved) : new Map();
|
|
690
|
+
const plans = objects.map(({sides}) => planIds(sides, shared, reserved));
|
|
691
|
+
const after = objects.map(({sides}, index) =>
|
|
692
|
+
branchKey(sides, new Map(plans[index].assigned)),
|
|
693
|
+
);
|
|
694
|
+
return (after[0] === after[1]) === alike ? plans : null;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* The name for a swipe: its ids in camelCase, or `rowSwipe` when they are
|
|
699
|
+
* many, positional, or not static.
|
|
700
|
+
* @param {Array<string | null>} ids @param {boolean} positional
|
|
701
|
+
*/
|
|
702
|
+
function swipeName(ids, positional) {
|
|
703
|
+
if (positional || ids.length === 0 || ids.length > 3) {
|
|
704
|
+
return 'rowSwipe';
|
|
705
|
+
}
|
|
706
|
+
const words = [];
|
|
707
|
+
for (const id of ids) {
|
|
708
|
+
if (id == null || !/^[a-z][a-z0-9-]*$/.test(id)) {
|
|
709
|
+
return 'rowSwipe';
|
|
710
|
+
}
|
|
711
|
+
words.push(...id.split('-').filter(Boolean));
|
|
712
|
+
}
|
|
713
|
+
return (
|
|
714
|
+
words
|
|
715
|
+
.map((word, index) =>
|
|
716
|
+
index === 0 ? word : word[0].toUpperCase() + word.slice(1),
|
|
717
|
+
)
|
|
718
|
+
.join('') + 'Swipe'
|
|
719
|
+
);
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/** Whether `node` lies inside `outer` in the source. @param {any} node @param {any} outer */
|
|
723
|
+
function within(node, outer) {
|
|
724
|
+
return (
|
|
725
|
+
typeof node?.start === 'number' &&
|
|
726
|
+
typeof outer?.start === 'number' &&
|
|
727
|
+
node.start >= outer.start &&
|
|
728
|
+
node.end <= outer.end
|
|
729
|
+
);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* Whether an identifier reads a variable. A property key, a member name, and
|
|
734
|
+
* a binding do not.
|
|
735
|
+
* @param {any} path
|
|
736
|
+
*/
|
|
737
|
+
function isReference(path) {
|
|
738
|
+
const node = path.node;
|
|
739
|
+
const parentPath = path.parent;
|
|
740
|
+
const parent = parentPath?.node;
|
|
741
|
+
if (parent == null) {
|
|
742
|
+
return true;
|
|
743
|
+
}
|
|
744
|
+
switch (parent.type) {
|
|
745
|
+
case 'MemberExpression':
|
|
746
|
+
case 'OptionalMemberExpression':
|
|
747
|
+
return parent.object === node || parent.computed === true;
|
|
748
|
+
case 'ObjectProperty':
|
|
749
|
+
case 'Property':
|
|
750
|
+
if (parentPath.parent?.node?.type === 'ObjectPattern') {
|
|
751
|
+
return false;
|
|
752
|
+
}
|
|
753
|
+
return parent.computed === true || parent.value === node;
|
|
754
|
+
case 'ObjectMethod':
|
|
755
|
+
case 'ClassMethod':
|
|
756
|
+
case 'ClassPrivateMethod':
|
|
757
|
+
case 'ClassProperty':
|
|
758
|
+
case 'ClassPrivateProperty':
|
|
759
|
+
return (
|
|
760
|
+
(parent.computed === true && parent.key === node) ||
|
|
761
|
+
parent.value === node
|
|
762
|
+
);
|
|
763
|
+
case 'VariableDeclarator':
|
|
764
|
+
return parent.init === node;
|
|
765
|
+
case 'FunctionDeclaration':
|
|
766
|
+
case 'FunctionExpression':
|
|
767
|
+
case 'ArrowFunctionExpression':
|
|
768
|
+
return parent.body === node;
|
|
769
|
+
case 'ClassDeclaration':
|
|
770
|
+
case 'ClassExpression':
|
|
771
|
+
return parent.superClass === node;
|
|
772
|
+
case 'AssignmentPattern':
|
|
773
|
+
return parent.right === node;
|
|
774
|
+
case 'ArrayPattern':
|
|
775
|
+
case 'ObjectPattern':
|
|
776
|
+
case 'RestElement':
|
|
777
|
+
case 'LabeledStatement':
|
|
778
|
+
case 'BreakStatement':
|
|
779
|
+
case 'ContinueStatement':
|
|
780
|
+
case 'ImportSpecifier':
|
|
781
|
+
case 'ImportDefaultSpecifier':
|
|
782
|
+
case 'ImportNamespaceSpecifier':
|
|
783
|
+
case 'ExportSpecifier':
|
|
784
|
+
case 'CatchClause':
|
|
785
|
+
return false;
|
|
786
|
+
default:
|
|
787
|
+
return true;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
/** Whether a path sits in a type, up to `stop`. @param {any} path @param {any} stop */
|
|
792
|
+
function inType(path, stop) {
|
|
793
|
+
for (let p = path.parent; p != null && p.node !== stop; p = p.parent) {
|
|
794
|
+
const type = p.node.type;
|
|
795
|
+
if (
|
|
796
|
+
(type.startsWith('TS') && !TYPE_WRAPPERS.has(type)) ||
|
|
797
|
+
type === 'TypeAnnotation'
|
|
798
|
+
) {
|
|
799
|
+
return true;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
return false;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
/** Whether a function between a path and `stop` gives it its own `this`. */
|
|
806
|
+
function hasOwnThis(/** @type {any} */ path, /** @type {any} */ stop) {
|
|
807
|
+
for (let p = path.parent; p != null && p.node !== stop; p = p.parent) {
|
|
808
|
+
const type = p.node.type;
|
|
809
|
+
if (
|
|
810
|
+
type === 'FunctionExpression' ||
|
|
811
|
+
type === 'FunctionDeclaration' ||
|
|
812
|
+
type === 'ObjectMethod' ||
|
|
813
|
+
type === 'ClassMethod' ||
|
|
814
|
+
type === 'ClassPrivateMethod'
|
|
815
|
+
) {
|
|
816
|
+
return true;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
return false;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
/** The statement of `body` that holds a path, or null. @param {any[]} body @param {any} path */
|
|
823
|
+
function statementIn(body, path) {
|
|
824
|
+
for (let p = path; p != null; p = p.parentPath) {
|
|
825
|
+
if (body.includes(p.node)) {
|
|
826
|
+
return p.node;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
return null;
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* The statement of `body` that holds a row. A body this codemod wrapped in a
|
|
834
|
+
* block holds the row in a new `return`, which the row's path predates, so
|
|
835
|
+
* the row is then found by its node.
|
|
836
|
+
* @param {any} j @param {any[]} body @param {any} path
|
|
837
|
+
*/
|
|
838
|
+
function statementHolding(j, body, path) {
|
|
839
|
+
return (
|
|
840
|
+
statementIn(body, path) ??
|
|
841
|
+
body.find(
|
|
842
|
+
(/** @type {any} */ statement) =>
|
|
843
|
+
j(statement)
|
|
844
|
+
.find(j.Node)
|
|
845
|
+
.filter((/** @type {any} */ p) => p.node === path.node)
|
|
846
|
+
.size() > 0,
|
|
847
|
+
) ??
|
|
848
|
+
null
|
|
849
|
+
);
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
/** Nodes that run code where they are evaluated. */
|
|
853
|
+
const RUNS_CODE = new Set([
|
|
854
|
+
'CallExpression',
|
|
855
|
+
'OptionalCallExpression',
|
|
856
|
+
'NewExpression',
|
|
857
|
+
'TaggedTemplateExpression',
|
|
858
|
+
'AwaitExpression',
|
|
859
|
+
'YieldExpression',
|
|
860
|
+
'AssignmentExpression',
|
|
861
|
+
'UpdateExpression',
|
|
862
|
+
'ImportExpression',
|
|
863
|
+
'MemberExpression',
|
|
864
|
+
'OptionalMemberExpression',
|
|
865
|
+
]);
|
|
866
|
+
|
|
867
|
+
/** Globals whose value never changes. */
|
|
868
|
+
const FIXED_GLOBALS = new Set(['undefined', 'NaN', 'Infinity']);
|
|
869
|
+
|
|
870
|
+
/**
|
|
871
|
+
* Whether `path` lies inside an entry's `onActivate` function in `object`.
|
|
872
|
+
* It is the only code in a swipe's options that runs when an action fires.
|
|
873
|
+
* Any other function there, such as a `map` callback that builds a label,
|
|
874
|
+
* runs at render.
|
|
875
|
+
* @param {any} path @param {any} object
|
|
876
|
+
*/
|
|
877
|
+
function inActivate(path, object) {
|
|
878
|
+
for (let q = path.parent; q != null && q.node !== object; q = q.parent) {
|
|
879
|
+
const node = q.node;
|
|
880
|
+
if (node.type === 'ObjectMethod') {
|
|
881
|
+
if (keyOf(node) === 'onActivate') {
|
|
882
|
+
return true;
|
|
883
|
+
}
|
|
884
|
+
continue;
|
|
885
|
+
}
|
|
886
|
+
const property = q.parent?.node;
|
|
887
|
+
if (
|
|
888
|
+
FUNCTION_TYPES.has(node.type) &&
|
|
889
|
+
(property?.type === 'ObjectProperty' || property?.type === 'Property') &&
|
|
890
|
+
property.value === node &&
|
|
891
|
+
keyOf(property) === 'onActivate'
|
|
892
|
+
) {
|
|
893
|
+
return true;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
return false;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
/**
|
|
900
|
+
* Whether a swipe's options hold only values that stay the same where its
|
|
901
|
+
* definition goes. At module scope (`owner` null), each value outside a
|
|
902
|
+
* handler is a literal, a JSX element, or a name bound by an import, a module
|
|
903
|
+
* `const`, or a function or class declaration. In `useMemo` in `owner`, the
|
|
904
|
+
* owner's locals count too, since each becomes a dependency, and so does a
|
|
905
|
+
* call or a property read on one, such as `t('archive')` with a `t` from
|
|
906
|
+
* `useTranslation()`. A ref or a setter stays out of the dependencies, so a
|
|
907
|
+
* read or call on one does not count. Any other call, construction, property
|
|
908
|
+
* read or global
|
|
909
|
+
* such as `window` runs or reads at render, so a definition would freeze it:
|
|
910
|
+
* at module scope once, at import; in `useMemo` until a dependency changes.
|
|
911
|
+
* Only an entry's `onActivate` is a handler: its body runs when the action
|
|
912
|
+
* fires, so it may read anything.
|
|
913
|
+
* @param {any} j @param {any} objectPath @param {Set<any>} created @param {any} owner
|
|
914
|
+
*/
|
|
915
|
+
function fixedWhereDefined(j, objectPath, created, owner = null) {
|
|
916
|
+
const object = objectPath.node;
|
|
917
|
+
const inHandler = (/** @type {any} */ p) => inActivate(p, object);
|
|
918
|
+
let fixed = true;
|
|
919
|
+
/** Whether a member read reads a namespace import, which never changes. */
|
|
920
|
+
const readsNamespace = (/** @type {any} */ p) => {
|
|
921
|
+
let node = p.node;
|
|
922
|
+
while (
|
|
923
|
+
(node.type === 'MemberExpression' ||
|
|
924
|
+
node.type === 'OptionalMemberExpression') &&
|
|
925
|
+
!node.computed
|
|
926
|
+
) {
|
|
927
|
+
node = unwrap(node.object);
|
|
928
|
+
}
|
|
929
|
+
if (node?.type !== 'Identifier') {
|
|
930
|
+
return false;
|
|
931
|
+
}
|
|
932
|
+
const bindings = p.scope?.lookup(node.name)?.getBindings()[node.name] ?? [];
|
|
933
|
+
return (
|
|
934
|
+
bindings.length > 0 &&
|
|
935
|
+
bindings.every(
|
|
936
|
+
(/** @type {any} */ b) =>
|
|
937
|
+
b.parent?.node?.type === 'ImportNamespaceSpecifier',
|
|
938
|
+
)
|
|
939
|
+
);
|
|
940
|
+
};
|
|
941
|
+
/** Whether a name is one of the owner's locals: a dependency of its memo. */
|
|
942
|
+
const ownerLocal = (/** @type {any} */ p, /** @type {string} */ name) =>
|
|
943
|
+
owner != null && p.scope?.lookup(name)?.path.node === owner;
|
|
944
|
+
/**
|
|
945
|
+
* Whether an owner's local can change between renders, so its memo
|
|
946
|
+
* depends on it. A ref or a setter is stable and stays out of the
|
|
947
|
+
* dependencies: a ref's `current` read at render would freeze.
|
|
948
|
+
*/
|
|
949
|
+
const changingLocal = (/** @type {any} */ p, /** @type {string} */ name) =>
|
|
950
|
+
ownerLocal(p, name) && !isStable(p.scope.lookup(name), name);
|
|
951
|
+
/** Whether a name is bound inside the options, as a callback's parameter. */
|
|
952
|
+
const ownBinding = (/** @type {any} */ p, /** @type {string} */ name) => {
|
|
953
|
+
const scope = p.scope?.lookup(name);
|
|
954
|
+
return scope != null && within(scope.path.node, object);
|
|
955
|
+
};
|
|
956
|
+
/** The identifier a chain of member reads and calls starts from, or null. */
|
|
957
|
+
const chainStart = (/** @type {any} */ node) => {
|
|
958
|
+
let current = unwrap(node);
|
|
959
|
+
while (
|
|
960
|
+
current?.type === 'MemberExpression' ||
|
|
961
|
+
current?.type === 'OptionalMemberExpression' ||
|
|
962
|
+
current?.type === 'CallExpression' ||
|
|
963
|
+
current?.type === 'OptionalCallExpression'
|
|
964
|
+
) {
|
|
965
|
+
current = unwrap(
|
|
966
|
+
current.type === 'CallExpression' ||
|
|
967
|
+
current.type === 'OptionalCallExpression'
|
|
968
|
+
? current.callee
|
|
969
|
+
: current.object,
|
|
970
|
+
);
|
|
971
|
+
}
|
|
972
|
+
return current?.type === 'Identifier' ? current : null;
|
|
973
|
+
};
|
|
974
|
+
j(objectPath)
|
|
975
|
+
.find(j.Node)
|
|
976
|
+
.forEach((/** @type {any} */ p) => {
|
|
977
|
+
if (!fixed || created.has(p.node) || inHandler(p) || inType(p, object)) {
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
if (RUNS_CODE.has(p.node.type)) {
|
|
981
|
+
const isRead =
|
|
982
|
+
p.node.type === 'MemberExpression' ||
|
|
983
|
+
p.node.type === 'OptionalMemberExpression';
|
|
984
|
+
const isCall =
|
|
985
|
+
p.node.type === 'CallExpression' ||
|
|
986
|
+
p.node.type === 'OptionalCallExpression';
|
|
987
|
+
const start = isRead || isCall ? chainStart(p.node) : null;
|
|
988
|
+
fixed =
|
|
989
|
+
(isRead && readsNamespace(p)) ||
|
|
990
|
+
(start != null &&
|
|
991
|
+
(ownBinding(p, start.name) || changingLocal(p, start.name)));
|
|
992
|
+
return;
|
|
993
|
+
}
|
|
994
|
+
if (p.node.type !== 'Identifier' || !isReference(p)) {
|
|
995
|
+
return;
|
|
996
|
+
}
|
|
997
|
+
if (ownerLocal(p, p.node.name) || ownBinding(p, p.node.name)) {
|
|
998
|
+
return;
|
|
999
|
+
}
|
|
1000
|
+
const scope = p.scope?.lookup(p.node.name);
|
|
1001
|
+
if (scope == null) {
|
|
1002
|
+
fixed = FIXED_GLOBALS.has(p.node.name);
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
1005
|
+
fixed = (scope.getBindings()[p.node.name] ?? []).every(
|
|
1006
|
+
(/** @type {any} */ binding) => {
|
|
1007
|
+
const declarator = binding.parent?.node;
|
|
1008
|
+
const statement = binding.parent?.parent?.node;
|
|
1009
|
+
return (
|
|
1010
|
+
declarator?.type === 'ImportSpecifier' ||
|
|
1011
|
+
declarator?.type === 'ImportDefaultSpecifier' ||
|
|
1012
|
+
declarator?.type === 'ImportNamespaceSpecifier' ||
|
|
1013
|
+
declarator?.type === 'FunctionDeclaration' ||
|
|
1014
|
+
declarator?.type === 'ClassDeclaration' ||
|
|
1015
|
+
(declarator?.type === 'VariableDeclarator' &&
|
|
1016
|
+
declarator.id === binding.node &&
|
|
1017
|
+
statement?.type === 'VariableDeclaration' &&
|
|
1018
|
+
statement.kind === 'const')
|
|
1019
|
+
);
|
|
1020
|
+
},
|
|
1021
|
+
);
|
|
1022
|
+
});
|
|
1023
|
+
return fixed;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
/**
|
|
1027
|
+
* Whether a statement returns from its function.
|
|
1028
|
+
* @param {any} node
|
|
1029
|
+
* @returns {boolean}
|
|
1030
|
+
*/
|
|
1031
|
+
function returns(node) {
|
|
1032
|
+
if (node == null || typeof node !== 'object') {
|
|
1033
|
+
return false;
|
|
1034
|
+
}
|
|
1035
|
+
if (Array.isArray(node)) {
|
|
1036
|
+
return node.some(returns);
|
|
1037
|
+
}
|
|
1038
|
+
if (node.type === 'ReturnStatement') {
|
|
1039
|
+
return true;
|
|
1040
|
+
}
|
|
1041
|
+
if (
|
|
1042
|
+
FUNCTION_TYPES.has(node.type) ||
|
|
1043
|
+
node.type === 'ObjectMethod' ||
|
|
1044
|
+
node.type === 'ClassMethod' ||
|
|
1045
|
+
node.type === 'ClassDeclaration' ||
|
|
1046
|
+
node.type === 'ClassExpression'
|
|
1047
|
+
) {
|
|
1048
|
+
return false;
|
|
1049
|
+
}
|
|
1050
|
+
return Object.keys(node).some(
|
|
1051
|
+
key =>
|
|
1052
|
+
!SKIPPED_KEYS.has(key) &&
|
|
1053
|
+
node[key] != null &&
|
|
1054
|
+
typeof node[key] === 'object' &&
|
|
1055
|
+
returns(node[key]),
|
|
1056
|
+
);
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
/**
|
|
1060
|
+
* Whether a call wraps `fn` as a component: `memo(fn)` or `forwardRef(fn)`,
|
|
1061
|
+
* named or on a namespace, with `fn` as its first argument. A callback of any
|
|
1062
|
+
* other call, such as `rows.map(…)` or `useCallback(…)`, is not a component.
|
|
1063
|
+
* @param {any} call @param {any} fn
|
|
1064
|
+
*/
|
|
1065
|
+
function wrapsComponent(call, fn) {
|
|
1066
|
+
const callee = unwrap(call.callee);
|
|
1067
|
+
const name =
|
|
1068
|
+
callee?.type === 'Identifier'
|
|
1069
|
+
? callee.name
|
|
1070
|
+
: callee?.type === 'MemberExpression' && !callee.computed
|
|
1071
|
+
? callee.property?.name
|
|
1072
|
+
: null;
|
|
1073
|
+
return (
|
|
1074
|
+
(name === 'memo' || name === 'forwardRef') &&
|
|
1075
|
+
unwrap(call.arguments?.[0]) === fn
|
|
1076
|
+
);
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
/** A function's name, or the name of the variable it is assigned to. */
|
|
1080
|
+
function functionName(/** @type {any} */ path) {
|
|
1081
|
+
if (path.node.id?.name) {
|
|
1082
|
+
return path.node.id.name;
|
|
1083
|
+
}
|
|
1084
|
+
let node = path.node;
|
|
1085
|
+
let parent = path.parent;
|
|
1086
|
+
while (
|
|
1087
|
+
parent?.node.type === 'CallExpression' &&
|
|
1088
|
+
wrapsComponent(parent.node, node)
|
|
1089
|
+
) {
|
|
1090
|
+
node = parent.node;
|
|
1091
|
+
parent = parent.parent;
|
|
1092
|
+
}
|
|
1093
|
+
return parent?.node.type === 'VariableDeclarator' &&
|
|
1094
|
+
parent.node.id?.type === 'Identifier'
|
|
1095
|
+
? parent.node.id.name
|
|
1096
|
+
: null;
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
/** Whether a call is one of the named React hooks. @param {any} node @param {string[]} names */
|
|
1100
|
+
function isHookCall(node, names) {
|
|
1101
|
+
const call = unwrap(node);
|
|
1102
|
+
if (call?.type !== 'CallExpression') {
|
|
1103
|
+
return false;
|
|
1104
|
+
}
|
|
1105
|
+
const callee = unwrap(call.callee);
|
|
1106
|
+
const name =
|
|
1107
|
+
callee?.type === 'Identifier'
|
|
1108
|
+
? callee.name
|
|
1109
|
+
: callee?.type === 'MemberExpression' && !callee.computed
|
|
1110
|
+
? callee.property?.name
|
|
1111
|
+
: null;
|
|
1112
|
+
return names.includes(name);
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
/**
|
|
1116
|
+
* Whether a binding never changes between renders: a `useState` or
|
|
1117
|
+
* `useReducer` setter, or a `useRef` result.
|
|
1118
|
+
* @param {any} scope @param {string} name
|
|
1119
|
+
*/
|
|
1120
|
+
function isStable(scope, name) {
|
|
1121
|
+
const bindings = scope.getBindings()[name] ?? [];
|
|
1122
|
+
return (
|
|
1123
|
+
bindings.length > 0 &&
|
|
1124
|
+
bindings.every((/** @type {any} */ binding) => {
|
|
1125
|
+
const parent = binding.parent?.node;
|
|
1126
|
+
if (parent?.type === 'ArrayPattern') {
|
|
1127
|
+
const declarator = binding.parent.parent?.node;
|
|
1128
|
+
return (
|
|
1129
|
+
parent.elements[1] === binding.node &&
|
|
1130
|
+
declarator?.type === 'VariableDeclarator' &&
|
|
1131
|
+
isHookCall(declarator.init, ['useState', 'useReducer'])
|
|
1132
|
+
);
|
|
1133
|
+
}
|
|
1134
|
+
return (
|
|
1135
|
+
parent?.type === 'VariableDeclarator' &&
|
|
1136
|
+
parent.id === binding.node &&
|
|
1137
|
+
isHookCall(parent.init, ['useRef'])
|
|
1138
|
+
);
|
|
1139
|
+
})
|
|
1140
|
+
);
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
/**
|
|
1144
|
+
* Where a swipe's options can be built once: at module scope when they read
|
|
1145
|
+
* only module bindings declared before the row's statement, or in `useMemo` in
|
|
1146
|
+
* the component or hook whose bindings they read. Either way, they hold only
|
|
1147
|
+
* values that stay the same there (`fixedWhereDefined`). Null when neither
|
|
1148
|
+
* works: a `this`, a binding of an inner function such as a map callback, or
|
|
1149
|
+
* a value read at render. Null too for a binding written after its
|
|
1150
|
+
* declaration, or declared after the row's statement or after an early
|
|
1151
|
+
* return. Null too for a binding the options read at render that code writes
|
|
1152
|
+
* through or hands on.
|
|
1153
|
+
* @param {any} j @param {any} root @param {any} rowPath @param {any} objectPath @param {Set<any>} created @param {Set<any>} swipeOptions
|
|
1154
|
+
* @returns {{kind: 'module', after: any} | {kind: 'memo', owner: any, deps: string[], after: any} | null}
|
|
1155
|
+
*/
|
|
1156
|
+
function placementOf(j, root, rowPath, objectPath, created, swipeOptions) {
|
|
1157
|
+
const object = objectPath.node;
|
|
1158
|
+
let movable = true;
|
|
1159
|
+
j(objectPath)
|
|
1160
|
+
.find(j.ThisExpression)
|
|
1161
|
+
.forEach((/** @type {any} */ p) => {
|
|
1162
|
+
movable = movable && hasOwnThis(p, object);
|
|
1163
|
+
});
|
|
1164
|
+
/** @type {Array<{name: string, scope: any, inHandler: boolean}>} */
|
|
1165
|
+
const outer = [];
|
|
1166
|
+
const read = (/** @type {any} */ p) => {
|
|
1167
|
+
if (created.has(p.node) || !isReference(p) || inType(p, object)) {
|
|
1168
|
+
return;
|
|
1169
|
+
}
|
|
1170
|
+
if (p.node.name === 'arguments') {
|
|
1171
|
+
movable = false;
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1174
|
+
const scope = p.scope?.lookup(p.node.name);
|
|
1175
|
+
if (scope != null && !within(scope.path.node, object)) {
|
|
1176
|
+
outer.push({
|
|
1177
|
+
name: p.node.name,
|
|
1178
|
+
scope,
|
|
1179
|
+
inHandler: inActivate(p, object),
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
};
|
|
1183
|
+
j(objectPath).find(j.Identifier).forEach(read);
|
|
1184
|
+
j(objectPath)
|
|
1185
|
+
.find(j.JSXIdentifier)
|
|
1186
|
+
.forEach((/** @type {any} */ p) => {
|
|
1187
|
+
const parent = p.parent?.node;
|
|
1188
|
+
if (
|
|
1189
|
+
((parent?.type === 'JSXOpeningElement' ||
|
|
1190
|
+
parent?.type === 'JSXClosingElement') &&
|
|
1191
|
+
parent.name === p.node &&
|
|
1192
|
+
/^[A-Z_$]/.test(p.node.name)) ||
|
|
1193
|
+
(parent?.type === 'JSXMemberExpression' && parent.object === p.node)
|
|
1194
|
+
) {
|
|
1195
|
+
read(p);
|
|
1196
|
+
}
|
|
1197
|
+
});
|
|
1198
|
+
if (!movable) {
|
|
1199
|
+
return null;
|
|
1200
|
+
}
|
|
1201
|
+
// A binding written after its declaration can hold another value at each
|
|
1202
|
+
// row, or by the time the row renders, where a definition keeps one. So can
|
|
1203
|
+
// one the options read at render that code writes through or hands on. A
|
|
1204
|
+
// handler reads its bindings when its action fires.
|
|
1205
|
+
const changes = new Map();
|
|
1206
|
+
for (const r of outer) {
|
|
1207
|
+
const through = !r.inHandler;
|
|
1208
|
+
const key = `${r.name}\u0000${through}`;
|
|
1209
|
+
if (!changes.has(key)) {
|
|
1210
|
+
changes.set(
|
|
1211
|
+
key,
|
|
1212
|
+
reassigned(j, r.scope, r.name, through, swipeOptions, created),
|
|
1213
|
+
);
|
|
1214
|
+
}
|
|
1215
|
+
if (changes.get(key)) {
|
|
1216
|
+
return null;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
const local = outer.filter(r => r.scope.path.node.type !== 'Program');
|
|
1220
|
+
if (local.length === 0) {
|
|
1221
|
+
const body = root.get().node.program.body;
|
|
1222
|
+
const row = statementIn(body, rowPath);
|
|
1223
|
+
// A handler reads a module binding only when its action fires, so only
|
|
1224
|
+
// reads outside one decide how early the definition can run.
|
|
1225
|
+
let lastDependency = -1;
|
|
1226
|
+
for (const {name, scope, inHandler} of outer) {
|
|
1227
|
+
for (const binding of scope.getBindings()[name] ?? []) {
|
|
1228
|
+
const declared = statementIn(body, binding);
|
|
1229
|
+
const hoisted =
|
|
1230
|
+
declared?.type === 'ImportDeclaration' ||
|
|
1231
|
+
declared?.type === 'FunctionDeclaration' ||
|
|
1232
|
+
declared?.declaration?.type === 'FunctionDeclaration';
|
|
1233
|
+
if (
|
|
1234
|
+
declared == null ||
|
|
1235
|
+
(!hoisted && body.indexOf(declared) >= body.indexOf(row))
|
|
1236
|
+
) {
|
|
1237
|
+
return null;
|
|
1238
|
+
}
|
|
1239
|
+
if (!hoisted && !inHandler) {
|
|
1240
|
+
lastDependency = Math.max(lastDependency, body.indexOf(declared));
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
if (row == null || !fixedWhereDefined(j, objectPath, created)) {
|
|
1245
|
+
return null;
|
|
1246
|
+
}
|
|
1247
|
+
const after = afterFor(row, body, lastDependency);
|
|
1248
|
+
if (
|
|
1249
|
+
after !== undefined &&
|
|
1250
|
+
reachedAbove(j, body, indexFor(body, after, body.indexOf(row), true), row)
|
|
1251
|
+
) {
|
|
1252
|
+
return null;
|
|
1253
|
+
}
|
|
1254
|
+
return {kind: 'module', after};
|
|
1255
|
+
}
|
|
1256
|
+
const owner = local[0].scope.path;
|
|
1257
|
+
const fn = owner.node;
|
|
1258
|
+
const name = FUNCTION_TYPES.has(fn.type) ? functionName(owner) : null;
|
|
1259
|
+
if (
|
|
1260
|
+
name == null ||
|
|
1261
|
+
!/^(?:[A-Z]|use[A-Z0-9])/.test(name) ||
|
|
1262
|
+
local.some(r => r.scope.path.node !== fn)
|
|
1263
|
+
) {
|
|
1264
|
+
return null;
|
|
1265
|
+
}
|
|
1266
|
+
const isParam = (/** @type {string} */ name) =>
|
|
1267
|
+
(owner.scope.getBindings()[name] ?? []).every((/** @type {any} */ b) =>
|
|
1268
|
+
fn.params.some((/** @type {any} */ param) => within(b.node, param)),
|
|
1269
|
+
);
|
|
1270
|
+
const statements = fn.body.type === 'BlockStatement' ? fn.body.body : null;
|
|
1271
|
+
const row =
|
|
1272
|
+
statements == null ? null : statementHolding(j, statements, rowPath);
|
|
1273
|
+
let lastDependency = -1;
|
|
1274
|
+
if (statements != null) {
|
|
1275
|
+
const index = statements.indexOf(row);
|
|
1276
|
+
if (row == null || statements.slice(0, index).some(returns)) {
|
|
1277
|
+
return null;
|
|
1278
|
+
}
|
|
1279
|
+
for (const r of local) {
|
|
1280
|
+
if (isParam(r.name)) {
|
|
1281
|
+
continue;
|
|
1282
|
+
}
|
|
1283
|
+
for (const binding of owner.scope.getBindings()[r.name] ?? []) {
|
|
1284
|
+
const declared = statementIn(statements, binding);
|
|
1285
|
+
if (declared == null || statements.indexOf(declared) >= index) {
|
|
1286
|
+
return null;
|
|
1287
|
+
}
|
|
1288
|
+
lastDependency = Math.max(lastDependency, statements.indexOf(declared));
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
} else if (!local.every(r => isParam(r.name))) {
|
|
1292
|
+
return null;
|
|
1293
|
+
}
|
|
1294
|
+
/** @type {string[]} */
|
|
1295
|
+
const deps = [];
|
|
1296
|
+
for (const r of local) {
|
|
1297
|
+
if (!deps.includes(r.name) && !isStable(owner.scope, r.name)) {
|
|
1298
|
+
deps.push(r.name);
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
if (!fixedWhereDefined(j, objectPath, created, fn)) {
|
|
1302
|
+
return null;
|
|
1303
|
+
}
|
|
1304
|
+
// `useMemo` reads its dependencies when it runs, handler reads included.
|
|
1305
|
+
const after =
|
|
1306
|
+
statements == null ? undefined : afterFor(row, statements, lastDependency);
|
|
1307
|
+
if (
|
|
1308
|
+
after !== undefined &&
|
|
1309
|
+
reachedAbove(
|
|
1310
|
+
j,
|
|
1311
|
+
statements,
|
|
1312
|
+
indexFor(statements, after, statements.indexOf(row), false),
|
|
1313
|
+
row,
|
|
1314
|
+
)
|
|
1315
|
+
) {
|
|
1316
|
+
return null;
|
|
1317
|
+
}
|
|
1318
|
+
return {kind: 'memo', owner: fn, deps, after};
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
/**
|
|
1322
|
+
* Whether code in `body` above `index` can call the hoisted function that
|
|
1323
|
+
* `row` declares before a definition placed at `index` runs. A statement
|
|
1324
|
+
* there names it, or names a function declaration whose body names it, and
|
|
1325
|
+
* so on.
|
|
1326
|
+
* @param {any} j @param {any[]} body @param {number} index @param {any} row
|
|
1327
|
+
*/
|
|
1328
|
+
function reachedAbove(j, body, index, row) {
|
|
1329
|
+
const declared = (/** @type {any} */ statement) =>
|
|
1330
|
+
statement.type === 'FunctionDeclaration'
|
|
1331
|
+
? statement
|
|
1332
|
+
: statement.declaration?.type === 'FunctionDeclaration'
|
|
1333
|
+
? statement.declaration
|
|
1334
|
+
: null;
|
|
1335
|
+
const name = declared(row)?.id?.name;
|
|
1336
|
+
if (name == null) {
|
|
1337
|
+
return false;
|
|
1338
|
+
}
|
|
1339
|
+
const callers = new Set([name]);
|
|
1340
|
+
const names = (/** @type {any} */ node) =>
|
|
1341
|
+
j(node)
|
|
1342
|
+
.find(j.Node)
|
|
1343
|
+
.filter(
|
|
1344
|
+
(/** @type {any} */ p) =>
|
|
1345
|
+
(p.node.type === 'JSXIdentifier' ||
|
|
1346
|
+
(p.node.type === 'Identifier' && isReference(p))) &&
|
|
1347
|
+
callers.has(p.node.name),
|
|
1348
|
+
)
|
|
1349
|
+
.size() > 0;
|
|
1350
|
+
for (let grew = true; grew;) {
|
|
1351
|
+
grew = false;
|
|
1352
|
+
for (const statement of body) {
|
|
1353
|
+
const fn = declared(statement);
|
|
1354
|
+
if (fn?.id != null && !callers.has(fn.id.name) && names(fn.body)) {
|
|
1355
|
+
callers.add(fn.id.name);
|
|
1356
|
+
grew = true;
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
return body.slice(0, index).some(names);
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
/**
|
|
1364
|
+
* Whether a binding takes another value after its declaration. Something
|
|
1365
|
+
* writes it (`written`), or it is declared more than once. With `through`, a
|
|
1366
|
+
* write through it counts too, and so does handing it on (`escapes`). A node
|
|
1367
|
+
* in `created` is the codemod's own and counts for nothing.
|
|
1368
|
+
* @param {any} j @param {any} scope @param {string} name @param {boolean} through @param {Set<any>} options @param {Set<any>} created
|
|
1369
|
+
*/
|
|
1370
|
+
function reassigned(j, scope, name, through, options, created) {
|
|
1371
|
+
if ((scope.getBindings()[name] ?? []).length > 1) {
|
|
1372
|
+
return true;
|
|
1373
|
+
}
|
|
1374
|
+
return (
|
|
1375
|
+
j(scope.path)
|
|
1376
|
+
.find(j.Identifier, {name})
|
|
1377
|
+
.filter(
|
|
1378
|
+
(/** @type {any} */ p) =>
|
|
1379
|
+
!created.has(p.node) &&
|
|
1380
|
+
p.scope?.lookup(name)?.path.node === scope.path.node &&
|
|
1381
|
+
written(p, through, options),
|
|
1382
|
+
)
|
|
1383
|
+
.size() > 0
|
|
1384
|
+
);
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
/**
|
|
1388
|
+
* Whether an identifier is written. A write is the target of an assignment,
|
|
1389
|
+
* an update, or a `for…in` or `for…of` loop, directly or inside a
|
|
1390
|
+
* destructuring pattern. With `through`, a write through it counts too. It
|
|
1391
|
+
* assigns, updates or deletes a property read from it, or calls a method read
|
|
1392
|
+
* from it. Handing on it or a property read from it counts as well
|
|
1393
|
+
* (`escapes`).
|
|
1394
|
+
* @param {any} path @param {boolean} through @param {Set<any>} options
|
|
1395
|
+
*/
|
|
1396
|
+
function written(path, through, options) {
|
|
1397
|
+
let child = path;
|
|
1398
|
+
let parent = path.parent;
|
|
1399
|
+
// A property read from it, such as `labels.remove` or `words.push`, through
|
|
1400
|
+
// any TypeScript wrapper. A choice between values, such as
|
|
1401
|
+
// `(isAlt ? labels : other).remove`, may still yield it.
|
|
1402
|
+
let member = false;
|
|
1403
|
+
while (parent != null) {
|
|
1404
|
+
const node = parent.node;
|
|
1405
|
+
const reads =
|
|
1406
|
+
through &&
|
|
1407
|
+
(node.type === 'MemberExpression' ||
|
|
1408
|
+
node.type === 'OptionalMemberExpression') &&
|
|
1409
|
+
node.object === child.node;
|
|
1410
|
+
const wraps =
|
|
1411
|
+
(node.type === 'TSNonNullExpression' ||
|
|
1412
|
+
node.type === 'TSAsExpression' ||
|
|
1413
|
+
node.type === 'TSSatisfiesExpression' ||
|
|
1414
|
+
node.type === 'TSTypeAssertion' ||
|
|
1415
|
+
node.type === 'ParenthesizedExpression') &&
|
|
1416
|
+
node.expression === child.node;
|
|
1417
|
+
const chooses =
|
|
1418
|
+
through &&
|
|
1419
|
+
((node.type === 'ConditionalExpression' && node.test !== child.node) ||
|
|
1420
|
+
node.type === 'LogicalExpression' ||
|
|
1421
|
+
(node.type === 'SequenceExpression' &&
|
|
1422
|
+
node.expressions.at(-1) === child.node));
|
|
1423
|
+
if (!reads && !wraps && !chooses) {
|
|
1424
|
+
break;
|
|
1425
|
+
}
|
|
1426
|
+
member = member || reads;
|
|
1427
|
+
child = parent;
|
|
1428
|
+
parent = parent.parent;
|
|
1429
|
+
}
|
|
1430
|
+
const called = parent?.node;
|
|
1431
|
+
if (
|
|
1432
|
+
member &&
|
|
1433
|
+
(((called?.type === 'CallExpression' ||
|
|
1434
|
+
called?.type === 'OptionalCallExpression') &&
|
|
1435
|
+
called.callee === child.node) ||
|
|
1436
|
+
(called?.type === 'UnaryExpression' &&
|
|
1437
|
+
called.operator === 'delete' &&
|
|
1438
|
+
called.argument === child.node))
|
|
1439
|
+
) {
|
|
1440
|
+
return true;
|
|
1441
|
+
}
|
|
1442
|
+
if (through && escapes(child, options)) {
|
|
1443
|
+
return true;
|
|
1444
|
+
}
|
|
1445
|
+
while (parent != null) {
|
|
1446
|
+
const node = parent.node;
|
|
1447
|
+
const nests =
|
|
1448
|
+
node.type === 'ArrayPattern' ||
|
|
1449
|
+
node.type === 'ObjectPattern' ||
|
|
1450
|
+
node.type === 'RestElement' ||
|
|
1451
|
+
(node.type === 'AssignmentPattern' && node.left === child.node) ||
|
|
1452
|
+
((node.type === 'ObjectProperty' || node.type === 'Property') &&
|
|
1453
|
+
node.value === child.node &&
|
|
1454
|
+
parent.parent?.node?.type === 'ObjectPattern');
|
|
1455
|
+
if (!nests) {
|
|
1456
|
+
break;
|
|
1457
|
+
}
|
|
1458
|
+
child = parent;
|
|
1459
|
+
parent = parent.parent;
|
|
1460
|
+
}
|
|
1461
|
+
const node = parent?.node;
|
|
1462
|
+
return (
|
|
1463
|
+
(node?.type === 'AssignmentExpression' && node.left === child.node) ||
|
|
1464
|
+
node?.type === 'UpdateExpression' ||
|
|
1465
|
+
((node?.type === 'ForInStatement' || node?.type === 'ForOfStatement') &&
|
|
1466
|
+
node.left === child.node)
|
|
1467
|
+
);
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
/**
|
|
1471
|
+
* Whether a value read here is handed on, so that code can change it under
|
|
1472
|
+
* another name. A call or `new` that takes it counts anywhere. Outside every
|
|
1473
|
+
* row's options (`options`), so does a binding that takes it as an alias. So
|
|
1474
|
+
* do an object or array that stores it, and a return that yields it.
|
|
1475
|
+
* @param {any} path @param {Set<any>} options
|
|
1476
|
+
*/
|
|
1477
|
+
function escapes(path, options) {
|
|
1478
|
+
let child = path;
|
|
1479
|
+
let parent = path.parent;
|
|
1480
|
+
// A choice between values may still yield this one.
|
|
1481
|
+
while (parent != null) {
|
|
1482
|
+
const node = parent.node;
|
|
1483
|
+
const chooses =
|
|
1484
|
+
(node.type === 'ConditionalExpression' && node.test !== child.node) ||
|
|
1485
|
+
node.type === 'LogicalExpression' ||
|
|
1486
|
+
(node.type === 'SequenceExpression' &&
|
|
1487
|
+
node.expressions.at(-1) === child.node) ||
|
|
1488
|
+
((node.type === 'TSNonNullExpression' ||
|
|
1489
|
+
node.type === 'TSAsExpression' ||
|
|
1490
|
+
node.type === 'TSSatisfiesExpression' ||
|
|
1491
|
+
node.type === 'TSTypeAssertion' ||
|
|
1492
|
+
node.type === 'ParenthesizedExpression') &&
|
|
1493
|
+
node.expression === child.node);
|
|
1494
|
+
if (!chooses) {
|
|
1495
|
+
break;
|
|
1496
|
+
}
|
|
1497
|
+
child = parent;
|
|
1498
|
+
parent = parent.parent;
|
|
1499
|
+
}
|
|
1500
|
+
const node = parent?.node;
|
|
1501
|
+
if (node == null) {
|
|
1502
|
+
return false;
|
|
1503
|
+
}
|
|
1504
|
+
if (
|
|
1505
|
+
(node.type === 'CallExpression' ||
|
|
1506
|
+
node.type === 'OptionalCallExpression' ||
|
|
1507
|
+
node.type === 'NewExpression') &&
|
|
1508
|
+
node.arguments.includes(child.node)
|
|
1509
|
+
) {
|
|
1510
|
+
return true;
|
|
1511
|
+
}
|
|
1512
|
+
// A value stored in a row's options is that row's own. The codemod moves
|
|
1513
|
+
// those objects and merges into them, so their identity decides.
|
|
1514
|
+
for (let q = parent; q != null; q = q.parent) {
|
|
1515
|
+
if (options.has(q.node)) {
|
|
1516
|
+
return false;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
return (
|
|
1520
|
+
(node.type === 'VariableDeclarator' && node.init === child.node) ||
|
|
1521
|
+
(node.type === 'AssignmentExpression' && node.right === child.node) ||
|
|
1522
|
+
((node.type === 'ObjectProperty' || node.type === 'Property') &&
|
|
1523
|
+
node.value === child.node &&
|
|
1524
|
+
parent.parent?.node?.type === 'ObjectExpression') ||
|
|
1525
|
+
(node.type === 'ArrayExpression' && !dependencyList(parent)) ||
|
|
1526
|
+
node.type === 'SpreadElement' ||
|
|
1527
|
+
node.type === 'ReturnStatement' ||
|
|
1528
|
+
(node.type === 'ArrowFunctionExpression' && node.body === child.node)
|
|
1529
|
+
);
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
/** Where each React hook takes its dependency list. */
|
|
1533
|
+
const DEPENDENCY_ARGUMENT = new Map([
|
|
1534
|
+
['useCallback', 1],
|
|
1535
|
+
['useEffect', 1],
|
|
1536
|
+
['useImperativeHandle', 2],
|
|
1537
|
+
['useInsertionEffect', 1],
|
|
1538
|
+
['useLayoutEffect', 1],
|
|
1539
|
+
['useMemo', 1],
|
|
1540
|
+
]);
|
|
1541
|
+
|
|
1542
|
+
/**
|
|
1543
|
+
* Whether an array is a React hook's dependency list. The hook only compares
|
|
1544
|
+
* the values in it, so it hands none of them on.
|
|
1545
|
+
* @param {any} path
|
|
1546
|
+
*/
|
|
1547
|
+
function dependencyList(path) {
|
|
1548
|
+
const call = path.parent?.node;
|
|
1549
|
+
if (call?.type !== 'CallExpression') {
|
|
1550
|
+
return false;
|
|
1551
|
+
}
|
|
1552
|
+
const callee = call.callee;
|
|
1553
|
+
const name =
|
|
1554
|
+
callee.type === 'Identifier'
|
|
1555
|
+
? callee.name
|
|
1556
|
+
: callee.type === 'MemberExpression' && !callee.computed
|
|
1557
|
+
? callee.property.name
|
|
1558
|
+
: null;
|
|
1559
|
+
const index = DEPENDENCY_ARGUMENT.get(name);
|
|
1560
|
+
return index != null && call.arguments[index] === path.node;
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
/**
|
|
1564
|
+
* Where a definition goes when the row's statement is a hoisted function
|
|
1565
|
+
* declaration: code above it may call it before a `const` placed just before
|
|
1566
|
+
* it initializes. So the definition goes right after the last statement that
|
|
1567
|
+
* declares a binding it reads when it runs, or at the top (after the imports)
|
|
1568
|
+
* when it reads none. When code above that point can still reach the
|
|
1569
|
+
* function, `placementOf` keeps `createSwipe` on the row. Undefined
|
|
1570
|
+
* otherwise: the definition goes just before the row's statement.
|
|
1571
|
+
* @param {any} row @param {any[]} body @param {number} lastDependency
|
|
1572
|
+
* @returns {any}
|
|
1573
|
+
*/
|
|
1574
|
+
function afterFor(row, body, lastDependency) {
|
|
1575
|
+
const hoisted =
|
|
1576
|
+
row?.type === 'FunctionDeclaration' ||
|
|
1577
|
+
((row?.type === 'ExportNamedDeclaration' ||
|
|
1578
|
+
row?.type === 'ExportDefaultDeclaration') &&
|
|
1579
|
+
row.declaration?.type === 'FunctionDeclaration');
|
|
1580
|
+
if (!hoisted) {
|
|
1581
|
+
return undefined;
|
|
1582
|
+
}
|
|
1583
|
+
return lastDependency >= 0 ? body[lastDependency] : null;
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
/**
|
|
1587
|
+
* The index in `body` a definition goes to: `before`, the row statement's
|
|
1588
|
+
* index, unless `afterFor` gave a point (`after`): right after that
|
|
1589
|
+
* statement, or at the top, after the imports at module scope.
|
|
1590
|
+
* @param {any[]} body @param {any} after @param {number} before @param {boolean} isModule
|
|
1591
|
+
*/
|
|
1592
|
+
function indexFor(body, after, before, isModule) {
|
|
1593
|
+
if (after === undefined) {
|
|
1594
|
+
return before;
|
|
1595
|
+
}
|
|
1596
|
+
if (after != null) {
|
|
1597
|
+
return body.indexOf(after) + 1;
|
|
1598
|
+
}
|
|
1599
|
+
let afterImports = 0;
|
|
1600
|
+
if (isModule) {
|
|
1601
|
+
body.forEach((statement, i) => {
|
|
1602
|
+
if (statement.type === 'ImportDeclaration') {
|
|
1603
|
+
afterImports = i + 1;
|
|
1604
|
+
}
|
|
1605
|
+
});
|
|
1606
|
+
}
|
|
1607
|
+
return afterImports;
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
/**
|
|
1611
|
+
* Where a swipe's definition goes: the statement list and its index, at
|
|
1612
|
+
* module scope or at the top level of the owner's body. Null for an owner
|
|
1613
|
+
* whose body is an expression, which `insertDefinition` wraps in a block.
|
|
1614
|
+
* @param {any} j @param {any} root @param {any} placement @param {any} rowPath
|
|
1615
|
+
* @returns {{body: any[], index: number} | null}
|
|
1616
|
+
*/
|
|
1617
|
+
function insertionPoint(j, root, placement, rowPath) {
|
|
1618
|
+
if (placement.kind === 'module') {
|
|
1619
|
+
const body = root.get().node.program.body;
|
|
1620
|
+
const before = body.indexOf(statementIn(body, rowPath));
|
|
1621
|
+
return {body, index: indexFor(body, placement.after, before, true)};
|
|
1622
|
+
}
|
|
1623
|
+
if (placement.owner.body.type !== 'BlockStatement') {
|
|
1624
|
+
return null;
|
|
1625
|
+
}
|
|
1626
|
+
const body = placement.owner.body.body;
|
|
1627
|
+
const row = statementHolding(j, body, rowPath);
|
|
1628
|
+
const before = row == null ? body.length - 1 : body.indexOf(row);
|
|
1629
|
+
return {body, index: indexFor(body, placement.after, before, false)};
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
/**
|
|
1633
|
+
* Inserts a swipe's definition where `insertionPoint` says.
|
|
1634
|
+
* @param {any} j @param {any} root @param {any} placement @param {any} rowPath @param {any} declaration
|
|
1635
|
+
*/
|
|
1636
|
+
function insertDefinition(j, root, placement, rowPath, declaration) {
|
|
1637
|
+
const point = insertionPoint(j, root, placement, rowPath);
|
|
1638
|
+
if (point == null) {
|
|
1639
|
+
const owner = placement.owner;
|
|
1640
|
+
owner.body = j.blockStatement([declaration, j.returnStatement(owner.body)]);
|
|
1641
|
+
return;
|
|
1642
|
+
}
|
|
1643
|
+
point.body.splice(point.index, 0, declaration);
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
/**
|
|
1647
|
+
* The expression `useMemo` is called by, adding it to a `react` import when
|
|
1648
|
+
* the file has none.
|
|
1649
|
+
* @param {any} j @param {any} root
|
|
1650
|
+
*/
|
|
1651
|
+
function ensureUseMemo(j, root) {
|
|
1652
|
+
/** @type {string | null} */
|
|
1653
|
+
let local = null;
|
|
1654
|
+
/** @type {any} */
|
|
1655
|
+
let named = null;
|
|
1656
|
+
/** @type {string | null} */
|
|
1657
|
+
let namespace = null;
|
|
1658
|
+
root
|
|
1659
|
+
.find(j.ImportDeclaration)
|
|
1660
|
+
.filter(
|
|
1661
|
+
(/** @type {any} */ p) =>
|
|
1662
|
+
p.node.source.value === 'react' && p.node.importKind !== 'type',
|
|
1663
|
+
)
|
|
1664
|
+
.forEach((/** @type {any} */ p) => {
|
|
1665
|
+
for (const specifier of p.node.specifiers ?? []) {
|
|
1666
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
1667
|
+
if (specifier.importKind === 'type') {
|
|
1668
|
+
continue;
|
|
1669
|
+
}
|
|
1670
|
+
named ??= p.node;
|
|
1671
|
+
if (
|
|
1672
|
+
(specifier.imported.name ?? specifier.imported.value) === 'useMemo'
|
|
1673
|
+
) {
|
|
1674
|
+
local = specifier.local?.name ?? 'useMemo';
|
|
1675
|
+
}
|
|
1676
|
+
} else {
|
|
1677
|
+
namespace ??= specifier.local.name;
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
});
|
|
1681
|
+
if (local != null) {
|
|
1682
|
+
return j.identifier(local);
|
|
1683
|
+
}
|
|
1684
|
+
if (named == null && namespace != null) {
|
|
1685
|
+
return j.memberExpression(j.identifier(namespace), j.identifier('useMemo'));
|
|
1686
|
+
}
|
|
1687
|
+
const name = freeName(j, root, 'useMemo');
|
|
1688
|
+
const specifier =
|
|
1689
|
+
name === 'useMemo'
|
|
1690
|
+
? j.importSpecifier(j.identifier('useMemo'))
|
|
1691
|
+
: j.importSpecifier(j.identifier('useMemo'), j.identifier(name));
|
|
1692
|
+
if (named != null) {
|
|
1693
|
+
named.specifiers.push(specifier);
|
|
1694
|
+
} else {
|
|
1695
|
+
const declaration = j.importDeclaration(
|
|
1696
|
+
[specifier],
|
|
1697
|
+
j.stringLiteral('react'),
|
|
1698
|
+
);
|
|
1699
|
+
const imports = root.find(j.ImportDeclaration);
|
|
1700
|
+
if (imports.size() > 0) {
|
|
1701
|
+
imports.at(imports.size() - 1).insertAfter(declaration);
|
|
1702
|
+
} else {
|
|
1703
|
+
root.get().node.program.body.unshift(declaration);
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
return j.identifier(name);
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
/**
|
|
1710
|
+
* Whether a spread provably carries no swipe prop: it spreads a `const` bound
|
|
1711
|
+
* to such an object literal, or what an array literal's `map` callback takes
|
|
1712
|
+
* when every element gives it one.
|
|
1713
|
+
* @param {any} spread @param {any} rowPath
|
|
1714
|
+
*/
|
|
1715
|
+
function carriesNoSwipeProps(spread, rowPath) {
|
|
1716
|
+
const argument = unwrap(spread.argument);
|
|
1717
|
+
if (argument?.type !== 'Identifier') {
|
|
1718
|
+
return false;
|
|
1719
|
+
}
|
|
1720
|
+
const bindings =
|
|
1721
|
+
rowPath.scope?.lookup(argument.name)?.getBindings()[argument.name] ?? [];
|
|
1722
|
+
if (bindings.length !== 1) {
|
|
1723
|
+
return false;
|
|
1724
|
+
}
|
|
1725
|
+
const declarator = bindings[0].parent?.node;
|
|
1726
|
+
if (declarator?.type !== 'VariableDeclarator') {
|
|
1727
|
+
return mappedValuesHaveNoSwipeKey(bindings[0]);
|
|
1728
|
+
}
|
|
1729
|
+
return (
|
|
1730
|
+
declarator.id === bindings[0].node &&
|
|
1731
|
+
bindings[0].parent.parent?.node?.kind === 'const' &&
|
|
1732
|
+
hasNoSwipeKey(declarator.init)
|
|
1733
|
+
);
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1736
|
+
/**
|
|
1737
|
+
* Whether a node is an object literal with no spread and no swipe key.
|
|
1738
|
+
* @param {any} node
|
|
1739
|
+
*/
|
|
1740
|
+
function hasNoSwipeKey(node) {
|
|
1741
|
+
const object = unwrap(node);
|
|
1742
|
+
return (
|
|
1743
|
+
object?.type === 'ObjectExpression' &&
|
|
1744
|
+
object.properties.every((/** @type {any} */ p) => {
|
|
1745
|
+
const key =
|
|
1746
|
+
keyOf(p) ??
|
|
1747
|
+
(p.type === 'ObjectMethod' && !p.computed ? p.key?.name : null);
|
|
1748
|
+
return key != null && !SWIPE_PROPS.has(key);
|
|
1749
|
+
})
|
|
1750
|
+
);
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
/**
|
|
1754
|
+
* Whether a `map` callback's first parameter, or one place in its array
|
|
1755
|
+
* pattern, is such an object literal in every element of the array literal it
|
|
1756
|
+
* maps.
|
|
1757
|
+
* @param {any} binding
|
|
1758
|
+
*/
|
|
1759
|
+
function mappedValuesHaveNoSwipeKey(binding) {
|
|
1760
|
+
const pattern = binding.parent?.node;
|
|
1761
|
+
const place =
|
|
1762
|
+
pattern?.type === 'ArrayPattern'
|
|
1763
|
+
? pattern.elements.indexOf(binding.node)
|
|
1764
|
+
: -1;
|
|
1765
|
+
const param = place >= 0 ? binding.parent : binding;
|
|
1766
|
+
const callback = param.parent?.node;
|
|
1767
|
+
const call = param.parent?.parent?.node;
|
|
1768
|
+
const callee = call?.callee;
|
|
1769
|
+
const array = unwrap(callee?.object);
|
|
1770
|
+
if (
|
|
1771
|
+
!['ArrowFunctionExpression', 'FunctionExpression'].includes(
|
|
1772
|
+
callback?.type,
|
|
1773
|
+
) ||
|
|
1774
|
+
callback.params[0] !== param.node ||
|
|
1775
|
+
call?.type !== 'CallExpression' ||
|
|
1776
|
+
call.arguments[0] !== callback ||
|
|
1777
|
+
callee?.type !== 'MemberExpression' ||
|
|
1778
|
+
callee.computed ||
|
|
1779
|
+
callee.property?.name !== 'map' ||
|
|
1780
|
+
array?.type !== 'ArrayExpression'
|
|
1781
|
+
) {
|
|
1782
|
+
return false;
|
|
1783
|
+
}
|
|
1784
|
+
return array.elements.every((/** @type {any} */ element) => {
|
|
1785
|
+
if (place < 0) {
|
|
1786
|
+
return hasNoSwipeKey(element);
|
|
1787
|
+
}
|
|
1788
|
+
const entry = unwrap(element);
|
|
1789
|
+
return (
|
|
1790
|
+
entry?.type === 'ArrayExpression' && hasNoSwipeKey(entry.elements[place])
|
|
1791
|
+
);
|
|
1792
|
+
});
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1795
|
+
/**
|
|
1796
|
+
* The identifier or member chain `a.b.c` a node is, unwrapped, or null.
|
|
1797
|
+
* @param {any} node
|
|
1798
|
+
* @returns {any}
|
|
1799
|
+
*/
|
|
1800
|
+
function chain(node) {
|
|
1801
|
+
const value = unwrap(node);
|
|
1802
|
+
if (value?.type === 'Identifier') {
|
|
1803
|
+
return value;
|
|
1804
|
+
}
|
|
1805
|
+
return value?.type === 'MemberExpression' &&
|
|
1806
|
+
!value.computed &&
|
|
1807
|
+
value.property?.type === 'Identifier' &&
|
|
1808
|
+
chain(value.object) != null
|
|
1809
|
+
? value
|
|
1810
|
+
: null;
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
/**
|
|
1814
|
+
* Whether two chains name the same path.
|
|
1815
|
+
* @param {any} a @param {any} b
|
|
1816
|
+
* @returns {boolean}
|
|
1817
|
+
*/
|
|
1818
|
+
function sameChain(a, b) {
|
|
1819
|
+
const left = chain(a);
|
|
1820
|
+
const right = chain(b);
|
|
1821
|
+
if (left?.type === 'Identifier' || right?.type === 'Identifier') {
|
|
1822
|
+
return left?.type === right?.type && left?.name === right?.name;
|
|
1823
|
+
}
|
|
1824
|
+
return (
|
|
1825
|
+
left != null &&
|
|
1826
|
+
right != null &&
|
|
1827
|
+
left.property.name === right.property.name &&
|
|
1828
|
+
sameChain(left.object, right.object)
|
|
1829
|
+
);
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1832
|
+
/** The identifier a chain starts from. @param {any} node */
|
|
1833
|
+
function chainRoot(node) {
|
|
1834
|
+
let value = chain(node);
|
|
1835
|
+
while (value?.type === 'MemberExpression') {
|
|
1836
|
+
value = chain(value.object);
|
|
1837
|
+
}
|
|
1838
|
+
return value;
|
|
1839
|
+
}
|
|
1840
|
+
|
|
1841
|
+
/**
|
|
1842
|
+
* Makes each handler that takes nothing and compares the row's own `itemKey`
|
|
1843
|
+
* value with `===` or `!==` take `itemKey` from `onActivate` instead. A
|
|
1844
|
+
* `ListItem` passes its `itemKey` to `onActivate`, so the swipe no longer
|
|
1845
|
+
* closes over the row.
|
|
1846
|
+
* @param {any} j @param {any} rowPath @param {any} objectPath
|
|
1847
|
+
* @param {Array<[string, any[]]>} sides @param {any} keyAttribute @param {Set<any>} created
|
|
1848
|
+
*/
|
|
1849
|
+
function readItemKey(j, rowPath, objectPath, sides, keyAttribute, created) {
|
|
1850
|
+
const key = chain(attributeValue(keyAttribute));
|
|
1851
|
+
const keyRoot = chainRoot(key);
|
|
1852
|
+
const keyScope = keyRoot == null ? null : rowPath.scope?.lookup(keyRoot.name);
|
|
1853
|
+
if (keyScope == null || keyScope.path.node.type === 'Program') {
|
|
1854
|
+
return;
|
|
1855
|
+
}
|
|
1856
|
+
for (const [, entries] of sides) {
|
|
1857
|
+
for (const entry of entries) {
|
|
1858
|
+
const handler = unwrap(
|
|
1859
|
+
entry.properties.find(
|
|
1860
|
+
(/** @type {any} */ p) => keyOf(p) === 'onActivate',
|
|
1861
|
+
)?.value,
|
|
1862
|
+
);
|
|
1863
|
+
if (
|
|
1864
|
+
(handler?.type !== 'ArrowFunctionExpression' &&
|
|
1865
|
+
handler?.type !== 'FunctionExpression') ||
|
|
1866
|
+
handler.params.length > 0
|
|
1867
|
+
) {
|
|
1868
|
+
continue;
|
|
1869
|
+
}
|
|
1870
|
+
const handlerPath = j(objectPath)
|
|
1871
|
+
.find(j.Node)
|
|
1872
|
+
.filter((/** @type {any} */ p) => p.node === handler)
|
|
1873
|
+
.paths()[0];
|
|
1874
|
+
if (
|
|
1875
|
+
handlerPath == null ||
|
|
1876
|
+
j(handlerPath).find(j.Identifier, {name: 'itemKey'}).size() > 0
|
|
1877
|
+
) {
|
|
1878
|
+
continue;
|
|
1879
|
+
}
|
|
1880
|
+
const reads = j(handlerPath)
|
|
1881
|
+
.find(key.type === 'Identifier' ? j.Identifier : j.MemberExpression)
|
|
1882
|
+
.filter(
|
|
1883
|
+
(/** @type {any} */ p) =>
|
|
1884
|
+
sameChain(p.node, key) &&
|
|
1885
|
+
(key.type !== 'Identifier' || isReference(p)) &&
|
|
1886
|
+
p.scope?.lookup(keyRoot.name)?.path.node === keyScope.path.node,
|
|
1887
|
+
)
|
|
1888
|
+
.paths();
|
|
1889
|
+
if (reads.length === 0) {
|
|
1890
|
+
continue;
|
|
1891
|
+
}
|
|
1892
|
+
// `itemKey` is `string | number | undefined`. Compared with `===` or
|
|
1893
|
+
// `!==` it type-checks wherever the row's own key did; passed on, as in
|
|
1894
|
+
// `remove(itemKey)`, it can fail where the key's own type passed. So a
|
|
1895
|
+
// handler that reads the key any other way keeps its closure, and the
|
|
1896
|
+
// row keeps `createSwipe` with a TODO.
|
|
1897
|
+
const compared = reads.every((/** @type {any} */ p) => {
|
|
1898
|
+
const parent = p.parent?.node;
|
|
1899
|
+
return (
|
|
1900
|
+
parent?.type === 'BinaryExpression' &&
|
|
1901
|
+
(parent.operator === '===' || parent.operator === '!==')
|
|
1902
|
+
);
|
|
1903
|
+
});
|
|
1904
|
+
if (!compared) {
|
|
1905
|
+
continue;
|
|
1906
|
+
}
|
|
1907
|
+
for (const p of reads) {
|
|
1908
|
+
const replacement = j.identifier('itemKey');
|
|
1909
|
+
created.add(replacement);
|
|
1910
|
+
p.replace(replacement);
|
|
1911
|
+
}
|
|
1912
|
+
// A parsed pattern keeps its one-line source when printed.
|
|
1913
|
+
const pattern = j('({itemKey}) => {}')
|
|
1914
|
+
.find(j.ArrowFunctionExpression)
|
|
1915
|
+
.get().node.params[0];
|
|
1916
|
+
created.add(pattern.properties[0].key).add(pattern.properties[0].value);
|
|
1917
|
+
handler.params = [pattern];
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
/** A key for a node's shape that ignores source positions. @param {any} node */
|
|
1923
|
+
function shapeOf(node) {
|
|
1924
|
+
return JSON.stringify(node, (key, value) =>
|
|
1925
|
+
SKIPPED_KEYS.has(key) ? undefined : value,
|
|
1926
|
+
);
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
/**
|
|
1930
|
+
* @param {import('../../../../authoring/codemod/type').AstryxCodemodFile} file
|
|
1931
|
+
* @param {import('../../../../authoring/codemod/type').CodemodTransformApi} api
|
|
1932
|
+
* @returns {string | null | undefined}
|
|
1933
|
+
*/
|
|
1934
|
+
export default function transformer(file, api) {
|
|
1935
|
+
const j = api.jscodeshift;
|
|
1936
|
+
const root = j(file.source);
|
|
1937
|
+
let hasChanges = false;
|
|
1938
|
+
/** @type {Array<() => void>} */
|
|
1939
|
+
const rewrites = [];
|
|
1940
|
+
/** Nodes this codemod made, which read nothing from the file. */
|
|
1941
|
+
const created = new Set();
|
|
1942
|
+
/**
|
|
1943
|
+
* Every object a row's `swipeActions` holds. A value stored in one is that
|
|
1944
|
+
* row's own, not one handed on.
|
|
1945
|
+
*/
|
|
1946
|
+
const swipeOptions = new Set();
|
|
1947
|
+
root
|
|
1948
|
+
.find(j.JSXAttribute, {name: {name: 'swipeActions'}})
|
|
1949
|
+
.forEach((/** @type {any} */ p) => {
|
|
1950
|
+
const collect = (/** @type {any} */ node) => {
|
|
1951
|
+
const value = unwrap(node);
|
|
1952
|
+
if (value?.type === 'ObjectExpression') {
|
|
1953
|
+
swipeOptions.add(value);
|
|
1954
|
+
} else if (value?.type === 'ConditionalExpression') {
|
|
1955
|
+
collect(value.consequent);
|
|
1956
|
+
collect(value.alternate);
|
|
1957
|
+
} else if (value?.type === 'LogicalExpression') {
|
|
1958
|
+
collect(value.left);
|
|
1959
|
+
collect(value.right);
|
|
1960
|
+
}
|
|
1961
|
+
};
|
|
1962
|
+
collect(p.node.value?.expression);
|
|
1963
|
+
});
|
|
1964
|
+
/** @type {Map<string, string>} */
|
|
1965
|
+
const definitions = new Map();
|
|
1966
|
+
/** Each definition's declaration, by the name it defines. */
|
|
1967
|
+
/** @type {Map<string, any>} */
|
|
1968
|
+
const definitionNodes = new Map();
|
|
1969
|
+
/** @type {Map<any, string>} */
|
|
1970
|
+
const owners = new Map();
|
|
1971
|
+
const ownerKey = (/** @type {any} */ placement) => {
|
|
1972
|
+
if (placement.kind === 'module') {
|
|
1973
|
+
return 'module';
|
|
1974
|
+
}
|
|
1975
|
+
if (!owners.has(placement.owner)) {
|
|
1976
|
+
owners.set(placement.owner, `owner-${owners.size}`);
|
|
1977
|
+
}
|
|
1978
|
+
return owners.get(placement.owner);
|
|
1979
|
+
};
|
|
1980
|
+
|
|
1981
|
+
const imports = importedComponents(root, j, {
|
|
1982
|
+
matchesImport: source => CORE_IMPORT_RE.test(source),
|
|
1983
|
+
components: COMPONENTS,
|
|
1984
|
+
});
|
|
1985
|
+
if (imports.direct.size > 0 || imports.namespaces.size > 0) {
|
|
1986
|
+
root.find(j.JSXOpeningElement).forEach((/** @type {any} */ rowPath) => {
|
|
1987
|
+
const resolved = resolveImportedComponent(
|
|
1988
|
+
rowPath.node.name,
|
|
1989
|
+
rowPath,
|
|
1990
|
+
imports,
|
|
1991
|
+
);
|
|
1992
|
+
if (!resolved) {
|
|
1993
|
+
return;
|
|
1994
|
+
}
|
|
1995
|
+
const opening = rowPath.node;
|
|
1996
|
+
const attributes = opening.attributes ?? [];
|
|
1997
|
+
const named = (/** @type {string} */ name) =>
|
|
1998
|
+
attributes.find(
|
|
1999
|
+
(/** @type {any} */ a) =>
|
|
2000
|
+
a.type === 'JSXAttribute' && a.name?.name === name,
|
|
2001
|
+
);
|
|
2002
|
+
const actions = named('swipeActions');
|
|
2003
|
+
const behavior = named('swipeBehavior');
|
|
2004
|
+
const swipe = named('swipe');
|
|
2005
|
+
const spreads = attributes.filter(
|
|
2006
|
+
(/** @type {any} */ a) => a.type === 'JSXSpreadAttribute',
|
|
2007
|
+
);
|
|
2008
|
+
if (swipe != null) {
|
|
2009
|
+
// `swipe` wins at run time: the deprecated props do nothing here.
|
|
2010
|
+
if (actions != null || behavior != null) {
|
|
2011
|
+
rewrites.push(() => {
|
|
2012
|
+
opening.attributes = opening.attributes.filter(
|
|
2013
|
+
(/** @type {any} */ a) => a !== actions && a !== behavior,
|
|
2014
|
+
);
|
|
2015
|
+
});
|
|
2016
|
+
}
|
|
2017
|
+
return;
|
|
2018
|
+
}
|
|
2019
|
+
if (
|
|
2020
|
+
spreads.some((/** @type {any} */ s) => !carriesNoSwipeProps(s, rowPath))
|
|
2021
|
+
) {
|
|
2022
|
+
hasChanges =
|
|
2023
|
+
addComment(j, actions ?? behavior ?? spreads[0], SPREAD_COMMENT) ||
|
|
2024
|
+
hasChanges;
|
|
2025
|
+
return;
|
|
2026
|
+
}
|
|
2027
|
+
if (actions == null) {
|
|
2028
|
+
// A lone swipeBehavior does nothing without swipe actions.
|
|
2029
|
+
if (behavior != null) {
|
|
2030
|
+
rewrites.push(() => {
|
|
2031
|
+
opening.attributes = opening.attributes.filter(
|
|
2032
|
+
(/** @type {any} */ a) => a !== behavior,
|
|
2033
|
+
);
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
return;
|
|
2037
|
+
}
|
|
2038
|
+
const value = attributeValue(actions);
|
|
2039
|
+
const objects = swipeObjects(value);
|
|
2040
|
+
if (objects == null) {
|
|
2041
|
+
hasChanges = addComment(j, actions, VALUE_COMMENT) || hasChanges;
|
|
2042
|
+
return;
|
|
2043
|
+
}
|
|
2044
|
+
// A condition's swipes key alike exactly where the deprecated props
|
|
2045
|
+
// did, or the props stay (`branchPlans`).
|
|
2046
|
+
const plans = objects.length === 2 ? branchPlans(objects) : undefined;
|
|
2047
|
+
if (plans === null) {
|
|
2048
|
+
hasChanges = addComment(j, actions, BRANCH_KEY_COMMENT) || hasChanges;
|
|
2049
|
+
return;
|
|
2050
|
+
}
|
|
2051
|
+
const behaviorValue = behavior == null ? null : attributeValue(behavior);
|
|
2052
|
+
const behaviorText =
|
|
2053
|
+
behaviorValue == null ? null : staticString(behaviorValue);
|
|
2054
|
+
const keyAttribute =
|
|
2055
|
+
resolved.component === 'ListItem' ? named('itemKey') : null;
|
|
2056
|
+
const placeComment =
|
|
2057
|
+
resolved.component === 'ListItem' ? PLACE_COMMENT : ITEM_PLACE_COMMENT;
|
|
2058
|
+
rewrites.push(() => {
|
|
2059
|
+
const create = ensureCreateImport(j, root);
|
|
2060
|
+
let expression = unwrap(value);
|
|
2061
|
+
for (const [index, {object, sides, replace}] of objects.entries()) {
|
|
2062
|
+
const objectPath = j(rowPath)
|
|
2063
|
+
.find(j.ObjectExpression)
|
|
2064
|
+
.filter((/** @type {any} */ p) => p.node === object)
|
|
2065
|
+
.paths()[0];
|
|
2066
|
+
if (keyAttribute != null) {
|
|
2067
|
+
readItemKey(j, rowPath, objectPath, sides, keyAttribute, created);
|
|
2068
|
+
}
|
|
2069
|
+
const {ids, positional, branchPositional} =
|
|
2070
|
+
plans == null ? entryIds(j, sides) : applyIds(j, plans[index]);
|
|
2071
|
+
const nameComment = branchPositional
|
|
2072
|
+
? BRANCH_NAME_COMMENT
|
|
2073
|
+
: NAME_COMMENT;
|
|
2074
|
+
if (behaviorValue != null && behaviorText !== 'reveal') {
|
|
2075
|
+
optionsOf(
|
|
2076
|
+
j,
|
|
2077
|
+
object,
|
|
2078
|
+
behaviorText == null
|
|
2079
|
+
? behaviorValue
|
|
2080
|
+
: j.stringLiteral(behaviorText),
|
|
2081
|
+
);
|
|
2082
|
+
}
|
|
2083
|
+
const placement = placementOf(
|
|
2084
|
+
j,
|
|
2085
|
+
root,
|
|
2086
|
+
rowPath,
|
|
2087
|
+
objectPath,
|
|
2088
|
+
created,
|
|
2089
|
+
swipeOptions,
|
|
2090
|
+
);
|
|
2091
|
+
let replacement;
|
|
2092
|
+
if (placement == null) {
|
|
2093
|
+
replacement = j.callExpression(j.identifier(create), [object]);
|
|
2094
|
+
addComment(j, actions, placeComment);
|
|
2095
|
+
if (positional) {
|
|
2096
|
+
addComment(j, actions, nameComment);
|
|
2097
|
+
}
|
|
2098
|
+
} else {
|
|
2099
|
+
const key = `${ownerKey(placement)}\u0000${shapeOf(object)}`;
|
|
2100
|
+
let name = definitions.get(key);
|
|
2101
|
+
// A hoisted row's definition must run before any call to it, so
|
|
2102
|
+
// it reuses one only where that one already sits early enough.
|
|
2103
|
+
if (name != null && placement.after !== undefined) {
|
|
2104
|
+
const point = insertionPoint(j, root, placement, rowPath);
|
|
2105
|
+
const at = point?.body.indexOf(definitionNodes.get(name)) ?? -1;
|
|
2106
|
+
if (point == null || at === -1 || at > point.index) {
|
|
2107
|
+
name = undefined;
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
if (name == null) {
|
|
2111
|
+
name = freeName(j, root, swipeName(ids, positional));
|
|
2112
|
+
const call = j.callExpression(j.identifier(create), [object]);
|
|
2113
|
+
const declaration = j.variableDeclaration('const', [
|
|
2114
|
+
j.variableDeclarator(
|
|
2115
|
+
j.identifier(name),
|
|
2116
|
+
placement.kind === 'module'
|
|
2117
|
+
? call
|
|
2118
|
+
: j.callExpression(ensureUseMemo(j, root), [
|
|
2119
|
+
j.arrowFunctionExpression([], call),
|
|
2120
|
+
j.arrayExpression(
|
|
2121
|
+
placement.deps.map(dep => {
|
|
2122
|
+
const dependency = j.identifier(dep);
|
|
2123
|
+
created.add(dependency);
|
|
2124
|
+
return dependency;
|
|
2125
|
+
}),
|
|
2126
|
+
),
|
|
2127
|
+
]),
|
|
2128
|
+
),
|
|
2129
|
+
]);
|
|
2130
|
+
if (positional) {
|
|
2131
|
+
addComment(j, declaration, nameComment);
|
|
2132
|
+
}
|
|
2133
|
+
insertDefinition(j, root, placement, rowPath, declaration);
|
|
2134
|
+
definitionNodes.set(name, declaration);
|
|
2135
|
+
definitions.set(key, name);
|
|
2136
|
+
}
|
|
2137
|
+
replacement = j.identifier(name);
|
|
2138
|
+
}
|
|
2139
|
+
if (replace == null) {
|
|
2140
|
+
expression = replacement;
|
|
2141
|
+
} else {
|
|
2142
|
+
replace(replacement);
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
actions.name = j.jsxIdentifier('swipe');
|
|
2146
|
+
actions.value = j.jsxExpressionContainer(expression);
|
|
2147
|
+
opening.attributes = opening.attributes.filter(
|
|
2148
|
+
(/** @type {any} */ a) => a !== behavior,
|
|
2149
|
+
);
|
|
2150
|
+
});
|
|
2151
|
+
});
|
|
2152
|
+
}
|
|
2153
|
+
|
|
2154
|
+
for (const rewrite of rewrites) {
|
|
2155
|
+
rewrite();
|
|
2156
|
+
hasChanges = true;
|
|
2157
|
+
}
|
|
2158
|
+
if (!hasChanges) return undefined;
|
|
2159
|
+
return root.toSource({quote: 'single'});
|
|
2160
|
+
}
|