@astryxdesign/cli 0.7.17 → 0.7.18-canary.g170df15
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/README.md +1 -1
- package/api/discover/_adapter.d.mts +7 -5
- package/api/discover/_adapter.mjs +12 -11
- package/api/docs/_adapter.d.mts +19 -2
- package/api/docs/_adapter.mjs +66 -5
- package/api/doctor/_adapter.d.mts +11 -62
- package/api/doctor/_adapter.mjs +242 -472
- package/api/doctor/doctor.d.mts +1 -1
- package/api/doctor/doctor.mjs +3 -3
- package/api/doctor/theme-checks.mjs +37 -45
- package/api/error.d.mts +21 -0
- package/api/error.mjs +89 -0
- package/api/hook/list/list.d.mts +1 -1
- package/api/icon/_adapter.d.mts +8 -0
- package/api/icon/_adapter.mjs +17 -0
- package/api/icon/_authoring.mjs +6 -6
- package/api/icon/_default-look.mjs +16 -16
- package/api/icon/add/add.mjs +3 -3
- package/api/icon/exportIconIndex.doc.mjs +2 -2
- package/api/icon/icon.doc.mjs +2 -2
- package/api/icon/icon.type.d.mts +4 -0
- package/api/icon/icon.type.mjs +2 -1
- package/api/icon/search/icon-index.mjs +16 -3
- package/api/icon/search/search.d.mts +15 -5
- package/api/icon/search/search.mjs +74 -16
- package/api/icon/use/use.mjs +4 -4
- package/api/render/_adapter.mjs +233 -40
- package/api/render/render.type.d.mts +1 -1
- package/api/render/render.type.mjs +1 -1
- package/api/search/ORDERING.md +2 -2
- package/api/search/_adapter.mjs +4 -0
- package/api/search/_candidate-score.mjs +32 -8
- package/api/search/_cards.json +1 -1
- package/api/search/_compound.d.mts +0 -1
- package/api/search/_compound.mjs +93 -2
- package/api/search/_icons.d.mts +4 -2
- package/api/search/_icons.mjs +4 -2
- package/api/search/_lexical.mjs +177 -17
- package/api/search/_order.d.mts +3 -1
- package/api/search/_order.mjs +16 -5
- package/api/search/_result.d.mts +9 -0
- package/api/search/_result.mjs +10 -0
- package/api/search/_score.mjs +21 -3
- package/api/swizzle/_moduleGraph.d.mts +8 -0
- package/api/swizzle/_moduleGraph.mjs +61 -3
- package/api/template/copy/copy.mjs +5 -3
- package/api/template/template.type.d.mts +3 -3
- package/api/template/template.type.mjs +3 -3
- package/api/theme/_adapter.mjs +48 -12
- package/api/theme/build/build.d.mts +4 -0
- package/api/theme/build/build.mjs +69 -18
- package/api/theme/build/style-keys.mjs +4 -5
- package/api/theme/build/theme-object.mjs +5 -0
- package/api/theme/palette/generate/color.d.mts +47 -0
- package/api/theme/palette/generate/color.mjs +58 -1
- package/api/theme/palette/generate/derive-look.d.mts +293 -0
- package/api/theme/palette/generate/derive-look.mjs +1362 -0
- package/api/theme/palette/generate/editor-look.d.mts +62 -0
- package/api/theme/palette/generate/editor-look.mjs +550 -0
- package/api/theme/palette/generate/mapping.d.mts +94 -9
- package/api/theme/palette/generate/mapping.mjs +94 -22
- package/api/theme-edit/_adapter.mjs +13 -2
- package/api/theme-edit/_catalog.d.mts +13 -13
- package/api/theme-edit/_catalog.mjs +66 -28
- package/api/theme-edit/_check.d.mts +82 -6
- package/api/theme-edit/_check.mjs +1270 -238
- package/api/theme-edit/_color.d.mts +74 -0
- package/api/theme-edit/_color.mjs +168 -3
- package/api/theme-edit/_compiler.d.mts +3 -5
- package/api/theme-edit/_compiler.mjs +122 -23
- package/api/theme-edit/_context.d.mts +55 -12
- package/api/theme-edit/_context.mjs +114 -60
- package/api/theme-edit/_css.d.mts +11 -0
- package/api/theme-edit/_css.mjs +40 -0
- package/api/theme-edit/_edit.d.mts +15 -2
- package/api/theme-edit/_edit.mjs +1469 -133
- package/api/theme-edit/_how-commands.d.mts +116 -0
- package/api/theme-edit/_how-commands.mjs +227 -115
- package/api/theme-edit/_how-question.d.mts +74 -29
- package/api/theme-edit/_how-question.mjs +8514 -1256
- package/api/theme-edit/_how-sides.d.mts +22 -0
- package/api/theme-edit/_how-sides.mjs +173 -0
- package/api/theme-edit/_how-steps.d.mts +42 -0
- package/api/theme-edit/_how-steps.mjs +208 -0
- package/api/theme-edit/_how-values.d.mts +29 -0
- package/api/theme-edit/_how-values.mjs +111 -0
- package/api/theme-edit/_how-words.d.mts +15 -0
- package/api/theme-edit/_how-words.mjs +239 -0
- package/api/theme-edit/_how.d.mts +1 -1
- package/api/theme-edit/_how.mjs +422 -37
- package/api/theme-edit/_missed.d.mts +2 -1
- package/api/theme-edit/_missed.mjs +125 -13
- package/api/theme-edit/_normal.d.mts +5 -3
- package/api/theme-edit/_normal.mjs +54 -14
- package/api/theme-edit/_palette.d.mts +204 -4
- package/api/theme-edit/_palette.mjs +901 -25
- package/api/theme-edit/_part-pieces.d.mts +54 -0
- package/api/theme-edit/_part-pieces.mjs +179 -0
- package/api/theme-edit/_part-words.mjs +33 -5
- package/api/theme-edit/_parts.d.mts +133 -0
- package/api/theme-edit/_parts.mjs +599 -10
- package/api/theme-edit/_picture-traits.d.mts +259 -0
- package/api/theme-edit/_picture-traits.mjs +1030 -0
- package/api/theme-edit/_preview.d.mts +95 -4
- package/api/theme-edit/_preview.mjs +284 -31
- package/api/theme-edit/_project.d.mts +14 -4
- package/api/theme-edit/_project.mjs +95 -26
- package/api/theme-edit/_resolved.d.mts +46 -0
- package/api/theme-edit/_resolved.mjs +800 -0
- package/api/theme-edit/_set-line.d.mts +29 -0
- package/api/theme-edit/_set-line.mjs +100 -0
- package/api/theme-edit/_settings.d.mts +625 -28
- package/api/theme-edit/_settings.mjs +4867 -888
- package/api/theme-edit/_tables.d.mts +25 -1
- package/api/theme-edit/_tables.mjs +115 -11
- package/api/theme-edit/_text-looks.d.mts +78 -0
- package/api/theme-edit/_text-looks.mjs +376 -0
- package/api/theme-edit/_vet.d.mts +3 -26
- package/api/theme-edit/_vet.mjs +5 -89
- package/api/theme-edit/how/how.d.mts +1 -1
- package/api/theme-edit/how/how.mjs +1 -1
- package/api/theme-edit/show/show.d.mts +4 -3
- package/api/theme-edit/show/show.mjs +3 -2
- package/api/theme-edit/theme-edit.type.d.mts +117 -1
- package/api/theme-edit/theme-edit.type.mjs +46 -3
- package/api/theme-edit/themeEditHow.doc.mjs +3 -3
- package/api/theme-edit/themeEditNew.doc.mjs +4 -0
- package/api/theme-edit/themeEditSet.doc.mjs +6 -2
- package/api/theme-edit/themeEditShow.doc.mjs +22 -3
- package/api/theme-edit/themeEditUndo.doc.mjs +4 -0
- package/assets/component-list.generated.json +1 -1
- package/assets/docs/author-a-theme.doc.mjs +7 -4
- package/assets/docs/icons.doc.mjs +7 -6
- package/assets/docs/theme.doc.dense.mjs +10 -0
- package/assets/docs/theme.doc.mjs +10 -0
- package/assets/docs/theme.doc.zh.mjs +10 -0
- package/assets/docs/tree/export-pages.doc.mjs +1 -1
- package/assets/docs/tree/icon-sets.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +89 -17
- package/assets/docs-routes.generated.json +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/icons/definitions/article.doc.mjs +9 -0
- package/assets/icons/template-icons.json +5 -0
- package/assets/search-catalog.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Citation/CitationInlineText.doc.mjs +1 -1
- package/assets/templates/blocks/components/Citation/CitationInlineText.tsx +3 -1
- package/assets/templates/blocks/components/Citation/CitationShowcase.doc.mjs +1 -1
- package/assets/templates/blocks/components/Citation/CitationShowcase.tsx +3 -1
- package/assets/templates/blocks/components/Citation/CitationSourceList.doc.mjs +1 -1
- package/assets/templates/blocks/components/Citation/CitationSourceList.tsx +7 -3
- package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.doc.mjs +1 -1
- package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.tsx +5 -2
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ide/page.tsx +5 -10
- package/assets/templates/pages/payment-form/page.tsx +16 -60
- package/assets/templates/themes/neutral/neutralTheme.ts +4 -3
- package/authoring/config/parse.mjs +1 -1
- package/authoring/debug/parse.d.mts +1 -1
- package/authoring/doctypes/_schema.d.mts +13 -13
- package/authoring/doctypes/icon-definition/parse.mjs +2 -2
- package/authoring/doctypes/icon-set/parse.mjs +1 -1
- package/authoring/doctypes/template/parse.mjs +1 -4
- package/authoring/gap-report/parse.d.mts +1 -1
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/ensure-core-built.mjs +17 -10
- package/clients/cli/commands/experimental/icon.mjs +7 -7
- package/clients/cli/commands/experimental/theme.mjs +175 -13
- package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +11 -3
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +15 -5
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/hook.mjs +7 -0
- package/clients/cli/commands/template.mjs +1 -1
- package/clients/cli/commands/theme-build.doc.mjs +1 -1
- package/clients/cli/index.mjs +6 -2
- package/clients/cli/lib/hook-format.mjs +41 -1
- package/clients/cli/lib/json-shim.mjs +34 -14
- package/clients/cli/lib/other-cli-words.mjs +7 -0
- package/clients/cli/lib/unknown-command.mjs +345 -46
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.d.mts +11 -2
- package/foundation/agent-docs/agent-docs.mjs +51 -8
- package/foundation/config/project.d.mts +11 -1
- package/foundation/config/project.mjs +11 -2
- package/foundation/discovery/component-replacement.d.mts +5 -8
- package/foundation/discovery/component-replacement.mjs +12 -14
- package/foundation/discovery/core-augmentation-points.d.mts +35 -0
- package/foundation/discovery/core-augmentation-points.mjs +410 -9
- package/foundation/discovery/core-elements.d.mts +6 -0
- package/foundation/discovery/core-elements.mjs +10 -2
- package/foundation/discovery/core-prop-types.d.mts +5 -0
- package/foundation/discovery/core-prop-types.mjs +10 -3
- package/foundation/discovery/core-props.d.mts +8 -0
- package/foundation/discovery/core-props.mjs +29 -13
- package/foundation/discovery/icon-ranking.d.mts +5 -2
- package/foundation/discovery/icon-ranking.mjs +101 -18
- package/foundation/discovery/icon-set-checks.mjs +1 -1
- package/foundation/discovery/icon-set-writer.mjs +1 -1
- package/foundation/discovery/official-list.d.mts +17 -0
- package/foundation/discovery/official-list.mjs +77 -0
- package/foundation/discovery/template-icon-notes.mjs +3 -3
- package/foundation/discovery/template-icons.mjs +2 -2
- package/foundation/discovery/template-placeholders.mjs +1 -1
- package/foundation/discovery/unknown-core-props.d.mts +130 -0
- package/foundation/discovery/unknown-core-props.mjs +601 -0
- package/foundation/discovery/written-prop-values.d.mts +35 -0
- package/foundation/discovery/written-prop-values.mjs +258 -0
- package/foundation/fonts/fontsource-families.generated.d.mts +5 -0
- package/foundation/fonts/fontsource-families.generated.mjs +2110 -0
- package/foundation/fs/package-name.d.mts +10 -0
- package/foundation/fs/package-name.mjs +37 -0
- package/foundation/fs/project-source-files.d.mts +27 -0
- package/foundation/fs/project-source-files.mjs +115 -0
- package/foundation/fs/project-sources.d.mts +25 -0
- package/foundation/fs/project-sources.mjs +83 -0
- package/foundation/fs/read-record.d.mts +18 -0
- package/foundation/fs/read-record.mjs +36 -2
- package/foundation/integrations/integration-warnings.d.mts +39 -7
- package/foundation/integrations/integration-warnings.mjs +141 -19
- package/foundation/integrations/missing-dependency.d.mts +11 -0
- package/foundation/integrations/missing-dependency.mjs +20 -5
- package/foundation/release/folder-lock.d.mts +5 -2
- package/foundation/release/folder-lock.mjs +9 -3
- package/foundation/release/notices.mjs +2 -8
- package/foundation/render/cut-short.d.mts +8 -2
- package/foundation/render/cut-short.mjs +50 -5
- package/foundation/render/drawn-contrast.d.mts +40 -0
- package/foundation/render/drawn-contrast.mjs +355 -0
- package/foundation/render/file-header.mjs +4 -0
- package/foundation/render/layers.d.mts +2 -1
- package/foundation/render/layers.mjs +22 -1
- package/foundation/render/package-resolve-hooks.d.mts +38 -9
- package/foundation/render/package-resolve-hooks.mjs +124 -32
- package/foundation/render/page-worker.mjs +95 -23
- package/foundation/render/part-boxes.d.mts +27 -0
- package/foundation/render/part-boxes.mjs +45 -0
- package/foundation/render/picture-chrome.mjs +36 -4
- package/foundation/render/picture-playwright.mjs +26 -2
- package/foundation/render/picture-window.d.mts +29 -2
- package/foundation/render/picture-window.mjs +99 -1
- package/foundation/render/render-page.d.mts +39 -6
- package/foundation/render/render-page.mjs +26 -10
- package/foundation/render/ts-paths.mjs +2 -1
- package/foundation/response/error-codes.doc.mjs +1 -1
- package/foundation/response/error-codes.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +9 -5
- package/foundation/suggest/other-command.mjs +25 -1
- package/foundation/text/icon-set-next.d.mts +1 -1
- package/foundation/text/icon-set-next.mjs +2 -2
- package/foundation/text/written-string.d.mts +4 -1
- package/foundation/text/written-string.mjs +4 -1
- package/package.json +8 -7
package/api/render/_adapter.mjs
CHANGED
|
@@ -18,7 +18,9 @@ import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
|
18
18
|
import {
|
|
19
19
|
MODULE_EXTENSIONS,
|
|
20
20
|
PAGE_EXTENSIONS,
|
|
21
|
+
REACT_UNKNOWN_PROP,
|
|
21
22
|
RenderError,
|
|
23
|
+
pageOutputWarnings,
|
|
22
24
|
renderPage,
|
|
23
25
|
} from '../../foundation/render/render-page.mjs';
|
|
24
26
|
import {
|
|
@@ -35,6 +37,7 @@ import {clip, locate, textEdits, textRuns} from '../../foundation/render/markup-
|
|
|
35
37
|
import {isPackageName} from '../../foundation/identity/provider-identity.mjs';
|
|
36
38
|
import {cliCommand} from '../../foundation/render/file-header.mjs';
|
|
37
39
|
import {shellArg} from '../../foundation/text/shell-arg.mjs';
|
|
40
|
+
import {getCliInvocation} from '../../foundation/env/package-manager.mjs';
|
|
38
41
|
import {isValidSemver} from '../../foundation/env/semver.mjs';
|
|
39
42
|
import {embeddedPathProblem, runnerPicksUp} from '../../foundation/render/embedded-files.mjs';
|
|
40
43
|
import {isAssetBytes, isAssetPath} from '../../foundation/render/assets.mjs';
|
|
@@ -48,14 +51,15 @@ import {rebuildPage} from '../../foundation/render/rebuild.mjs';
|
|
|
48
51
|
import {cliVersion} from '../../foundation/integrations/cli-peer-version.mjs';
|
|
49
52
|
import {assertWithin, PathSafetyError} from '../../foundation/fs/path-safety.mjs';
|
|
50
53
|
import {climbsOut, findCoreDir, findPackageRoot, isInside as liesInside, requireCoreDir} from '../../foundation/fs/paths.mjs';
|
|
54
|
+
import {judgeCoreProps, projectTypeScript, propNamesOf, readCoreDocs} from '../../foundation/discovery/unknown-core-props.mjs';
|
|
51
55
|
import {runChoice} from '../../foundation/release/run-context.mjs';
|
|
52
56
|
import {isAlive, pidSpace} from '../../foundation/release/cache.mjs';
|
|
53
57
|
import {isServedPackage} from '../../foundation/render/served-packages.mjs';
|
|
54
58
|
import {outsideRequests, roundTrip} from '../../foundation/render/share-checks.mjs';
|
|
55
59
|
import {hostedPagePackages, recordResolved} from '../../foundation/runtime/package-root.mjs';
|
|
56
60
|
import {installCommandFor} from '../../foundation/discovery/template-needs.mjs';
|
|
57
|
-
import {component} from '../component/component.mjs';
|
|
58
|
-
import {projectAugmentations, propWideningInterfaces} from '../../foundation/discovery/core-augmentation-points.mjs';
|
|
61
|
+
import {COMPONENT_BATCH_SELECTOR_LIMIT, component} from '../component/component.mjs';
|
|
62
|
+
import {projectAugmentations, propValueKinds, propWideningInterfaces, unacceptedKind} from '../../foundation/discovery/core-augmentation-points.mjs';
|
|
59
63
|
|
|
60
64
|
export {PAGE_EXTENSIONS, embeddedPathProblem};
|
|
61
65
|
|
|
@@ -494,54 +498,119 @@ function servedSet(input) {
|
|
|
494
498
|
}
|
|
495
499
|
}
|
|
496
500
|
|
|
497
|
-
const CORE_PACKAGE = '@astryxdesign/core';
|
|
498
|
-
|
|
499
501
|
/** A prop type that is a closed union of string literals, as a doc writes it: `'sm' | 'md'`. */
|
|
500
502
|
const CLOSED_UNION = /^\s*'[^']*'(?:\s*\|\s*'[^']*')*\s*$/;
|
|
501
503
|
|
|
504
|
+
/** A documented type that is only string literals, or `string` itself. */
|
|
505
|
+
const STRING_TYPE = /^\s*(?:string|'[^']*'(?:\s*\|\s*'[^']*')*)\s*$/;
|
|
506
|
+
|
|
502
507
|
/**
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
508
|
+
* Whether a prop's documented type (as `astryx component` shows it) plainly
|
|
509
|
+
* takes every written kind: strings for a string union or `string`, numbers
|
|
510
|
+
* for `number`, true or false for `boolean`. Only a yes skips the read of
|
|
511
|
+
* Core's source; any other type is read there.
|
|
512
|
+
* @param {unknown} docType
|
|
513
|
+
* @param {string[]} kinds
|
|
514
|
+
* @returns {boolean}
|
|
515
|
+
*/
|
|
516
|
+
function docTypeTakes(docType, kinds) {
|
|
517
|
+
if (typeof docType !== 'string') return false;
|
|
518
|
+
const type = docType.trim();
|
|
519
|
+
return kinds.every(kind =>
|
|
520
|
+
kind === 'string' ? STRING_TYPE.test(type) : kind === 'number' ? type === 'number' : kind === 'boolean' && type === 'boolean',
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/** How a warning names each kind of value. */
|
|
525
|
+
const KIND_WORDS = /** @type {Record<import('../../foundation/discovery/core-augmentation-points.mjs').ValueKind, string>} */ ({
|
|
526
|
+
string: 'a string',
|
|
527
|
+
number: 'a number',
|
|
528
|
+
boolean: 'true or false',
|
|
529
|
+
object: 'an object',
|
|
530
|
+
array: 'an array',
|
|
531
|
+
Date: 'a Date',
|
|
532
|
+
function: 'a function',
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* A warning for each value a page certainly gives a Core component's prop
|
|
537
|
+
* that the prop does not take.
|
|
538
|
+
* - A value of the wrong kind for the prop's declared type in the page's
|
|
539
|
+
* Core (`<TextInput status="error">`, where status takes an object): both
|
|
540
|
+
* the written value and the declared type must be certain, else the prop
|
|
541
|
+
* is not checked.
|
|
542
|
+
* - A string the prop's closed union does not hold (`<Button
|
|
543
|
+
* variant="danger">`), each branch of a literal-only conditional included:
|
|
544
|
+
* the component draws no look for it, and nothing else says so. The union
|
|
545
|
+
* comes from Core's own docs for the component in the page's Core, the
|
|
546
|
+
* props `astryx component <Name> --package @astryxdesign/core` reads, so an
|
|
547
|
+
* integration that replaces the component does not change it. Where the
|
|
548
|
+
* prop's type takes the keys of an interface a theme can widen by
|
|
549
|
+
* declaration merging (`interface ButtonVariantMap`, `interface
|
|
550
|
+
* TextColorMap` for Link's `color`), the keys the page's project adds to it
|
|
551
|
+
* are values the prop has too; when the project cannot be read in full, or
|
|
552
|
+
* the prop's type cannot be followed, such a prop is not checked. A
|
|
553
|
+
* component or prop with no doc entry, and a prop whose type is not a
|
|
554
|
+
* closed union, are not checked.
|
|
555
|
+
* @param {NonNullable<import('../../foundation/render/render-page.mjs').RenderedPage['propValues']>} values
|
|
516
556
|
* @param {string} page the page file; its folder's Core gives the docs
|
|
557
|
+
* @param {(name: string) => Promise<any[] | null>} docsOf the documented
|
|
558
|
+
* props of a Core component, read once for both prop checks
|
|
517
559
|
* @returns {Promise<import('../../foundation/render/render-page.mjs').RenderWarning[]>}
|
|
518
560
|
*/
|
|
519
|
-
async function propValueWarnings(values, page) {
|
|
561
|
+
async function propValueWarnings(values, page, docsOf) {
|
|
520
562
|
const dir = path.dirname(page);
|
|
521
|
-
/** @type {Map<string, any[] | null>} */
|
|
522
|
-
const docs = new Map();
|
|
523
563
|
/** @type {import('../../foundation/render/render-page.mjs').RenderWarning[]} */
|
|
524
564
|
const warnings = [];
|
|
525
565
|
const seen = new Set();
|
|
566
|
+
/** @param {string} key @param {string} message */
|
|
567
|
+
const warn = (key, message) => {
|
|
568
|
+
if (seen.has(key)) return;
|
|
569
|
+
seen.add(key);
|
|
570
|
+
warnings.push({code: 'unknown-prop-value', message});
|
|
571
|
+
};
|
|
526
572
|
const coreDir = values.length ? findCoreDir(dir) : null;
|
|
527
573
|
/** @type {ReturnType<typeof projectAugmentations> | undefined} */
|
|
528
574
|
let added;
|
|
575
|
+
/** @type {Map<string, ReturnType<typeof propValueKinds>>} */
|
|
576
|
+
const declaredKinds = new Map();
|
|
577
|
+
// The same wrong kind for one prop on several lines of a file is one
|
|
578
|
+
// warning that names every line.
|
|
579
|
+
/** @type {Map<string, {file: string, said: string, lines: number[], at: number}>} */
|
|
580
|
+
const kindGroups = new Map();
|
|
529
581
|
for (const v of values) {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
582
|
+
const docType = (await docsOf(v.component))?.find(p => p?.name === v.prop)?.type;
|
|
583
|
+
const kindKey = `${v.component}.${v.prop}`;
|
|
584
|
+
// A documented string union, `string`, `number` or `boolean` that takes
|
|
585
|
+
// every written kind decides the prop without Core's source, which costs
|
|
586
|
+
// a parse per component.
|
|
587
|
+
if (!declaredKinds.has(kindKey) && !docTypeTakes(docType, v.kinds)) {
|
|
588
|
+
declaredKinds.set(kindKey, propValueKinds(coreDir, v.component, v.prop));
|
|
589
|
+
}
|
|
590
|
+
const declared = declaredKinds.get(kindKey) ?? null;
|
|
591
|
+
const wrong = declared ? unacceptedKind(v.kinds, declared) : null;
|
|
592
|
+
if (declared && wrong) {
|
|
593
|
+
const fields = declared.fields ? ` {${declared.fields.join(', ')}}` : '';
|
|
594
|
+
const numbers =
|
|
595
|
+
!declared.anyNumber && declared.numbers.size > 0 ? `one of ${[...declared.numbers].join(', ')}` : null;
|
|
596
|
+
const expected = [...declared.kinds].map(kind =>
|
|
597
|
+
kind === 'object' ? KIND_WORDS.object + fields : kind === 'number' && numbers ? numbers : KIND_WORDS[kind],
|
|
598
|
+
);
|
|
599
|
+
const said = `${v.component} ${v.prop} expects ${expected.join(' or ')}; got ${KIND_WORDS[wrong]}`;
|
|
600
|
+
const group = kindGroups.get(`${v.file}\0${said}`) ?? {file: v.file, said, lines: [], at: warnings.length};
|
|
601
|
+
if (group.lines.length === 0) {
|
|
602
|
+
kindGroups.set(`${v.file}\0${said}`, group);
|
|
603
|
+
warnings.push({code: 'unknown-prop-value', message: ''});
|
|
538
604
|
}
|
|
539
|
-
|
|
605
|
+
if (!group.lines.includes(v.line)) group.lines.push(v.line);
|
|
606
|
+
continue;
|
|
540
607
|
}
|
|
541
|
-
|
|
608
|
+
if (!v.strings || v.strings.length === 0) continue;
|
|
609
|
+
const prop = (await docsOf(v.component))?.find(p => p?.name === v.prop);
|
|
542
610
|
if (typeof prop?.type !== 'string' || !CLOSED_UNION.test(prop.type)) continue;
|
|
543
611
|
const allowed = [...prop.type.matchAll(/'([^']*)'/g)].map(m => m[1]);
|
|
544
|
-
|
|
612
|
+
const unknown = v.strings.filter(value => !allowed.includes(value));
|
|
613
|
+
if (unknown.length === 0) continue;
|
|
545
614
|
// The project read can walk a large tree; only a value the docs lack needs it.
|
|
546
615
|
const widening = await propWideningInterfaces(coreDir, v.component, v.prop);
|
|
547
616
|
if (widening === null) continue;
|
|
@@ -552,19 +621,123 @@ async function propValueWarnings(values, page) {
|
|
|
552
621
|
for (const key of added.keys.get(name) ?? []) if (!allowed.includes(key)) allowed.push(key);
|
|
553
622
|
}
|
|
554
623
|
}
|
|
555
|
-
if (allowed.includes(v.value)) continue;
|
|
556
|
-
const key = `${v.file}:${v.line}:${v.component}:${v.prop}:${v.value}`;
|
|
557
|
-
if (seen.has(key)) continue;
|
|
558
|
-
seen.add(key);
|
|
559
624
|
const kinds = v.prop.endsWith('s') ? `${v.prop} values` : `${v.prop}s`;
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
625
|
+
for (const value of unknown) {
|
|
626
|
+
if (allowed.includes(value)) continue;
|
|
627
|
+
warn(
|
|
628
|
+
`${v.file}:${v.line}:${v.component}:${v.prop}:${value}`,
|
|
629
|
+
`${v.file}:${v.line}: ${v.component} has no ${v.prop} "${value}"; its ${kinds} are ${allowed.join(', ')}.`,
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
for (const {file, said, lines, at} of kindGroups.values()) {
|
|
634
|
+
warnings[at].message =
|
|
635
|
+
lines.length === 1 ? `${file}:${lines[0]}: ${said}.` : `${file}: ${said} on ${lines.length} lines (${lines.join(', ')}).`;
|
|
564
636
|
}
|
|
565
637
|
return warnings;
|
|
566
638
|
}
|
|
567
639
|
|
|
640
|
+
/**
|
|
641
|
+
* The documented props of each Core component, read from the Core of the
|
|
642
|
+
* folder `dir` with doctor's reader (`readCoreDocs`); null for a component
|
|
643
|
+
* the docs do not describe. `load` reads the components it is given in
|
|
644
|
+
* batches; `of` reads one component that was not loaded. Each component is
|
|
645
|
+
* read once.
|
|
646
|
+
* @param {string} dir
|
|
647
|
+
*/
|
|
648
|
+
function coreDocsReader(dir) {
|
|
649
|
+
/** @type {Map<string, any[] | null>} */
|
|
650
|
+
const docs = new Map();
|
|
651
|
+
/** @param {string[]} names */
|
|
652
|
+
const load = async names => {
|
|
653
|
+
const missing = [...new Set(names)].filter(name => !docs.has(name));
|
|
654
|
+
for (const name of missing) docs.set(name, null);
|
|
655
|
+
try {
|
|
656
|
+
for (const [name, props] of await readCoreDocs(component, missing, dir, COMPONENT_BATCH_SELECTOR_LIMIT)) docs.set(name, props);
|
|
657
|
+
} catch {
|
|
658
|
+
// A component the docs do not describe is not checked.
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
/** @param {string} name */
|
|
662
|
+
const of = async name => {
|
|
663
|
+
await load([name]);
|
|
664
|
+
return docs.get(name) ?? null;
|
|
665
|
+
};
|
|
666
|
+
return {load, of};
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/** How many of a component's props a warning names before it counts the rest. */
|
|
670
|
+
const PROPS_LISTED = 12;
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* A warning for each Core component element a page's file gives props it
|
|
674
|
+
* does not take (`<AlertDialog onConfirm={…}>`), judged as `astryx doctor`
|
|
675
|
+
* judges them (`judgeCoreProps`): the prop does nothing, and a callback the
|
|
676
|
+
* page passes is never called. Each prop gets the documented prop with the
|
|
677
|
+
* same words, when there is one; when a prop has none, the warning lists the
|
|
678
|
+
* props the component takes. Core's types are read with the project's
|
|
679
|
+
* TypeScript and React's types, as the page finds them; without them, the
|
|
680
|
+
* props are not judged. Only the docs are read while every prop is
|
|
681
|
+
* documented.
|
|
682
|
+
* @param {Array<import('../../foundation/discovery/core-props.mjs').CorePropUse & {file: string, element: {line: number, column: number}}>} names
|
|
683
|
+
* each with the file's absolute path and where its element opens
|
|
684
|
+
* @param {string} page the page file
|
|
685
|
+
* @param {(name: string) => Promise<any[] | null>} docsOf
|
|
686
|
+
* @returns {Promise<{warnings: import('../../foundation/render/render-page.mjs').RenderWarning[], props: Set<string>}>}
|
|
687
|
+
* the warnings, and the props they name
|
|
688
|
+
*/
|
|
689
|
+
async function propNameWarnings(names, page, docsOf) {
|
|
690
|
+
if (names.length === 0) return {warnings: [], props: new Set()};
|
|
691
|
+
const dir = path.dirname(page);
|
|
692
|
+
const projectDir = runChoice(dir).inProject ? (findPackageRoot(dir) ?? dir) : dir;
|
|
693
|
+
const shown = (/** @type {string} */ file) => path.relative(dir, file).split(path.sep).join('/');
|
|
694
|
+
const {found, skipped, reason} = await judgeCoreProps({
|
|
695
|
+
projectDir,
|
|
696
|
+
uses: names.map(use => ({...use, file: shown(use.file), path: use.file})),
|
|
697
|
+
pages: [...new Set(names.map(use => use.file))],
|
|
698
|
+
readDocs: async components => {
|
|
699
|
+
/** @type {Map<string, any[]>} */
|
|
700
|
+
const documented = new Map();
|
|
701
|
+
for (const name of components) {
|
|
702
|
+
const props = await docsOf(name);
|
|
703
|
+
if (props) documented.set(name, props);
|
|
704
|
+
}
|
|
705
|
+
return documented;
|
|
706
|
+
},
|
|
707
|
+
typescript: () => projectTypeScript([projectDir]),
|
|
708
|
+
});
|
|
709
|
+
/** @type {Map<string, {line: number, column: number}>} */
|
|
710
|
+
const elementOf = new Map(names.map(use => [`${shown(use.file)}\0${use.line}\0${use.column}`, use.element]));
|
|
711
|
+
/** @type {Map<string, typeof found>} */
|
|
712
|
+
const byElement = new Map();
|
|
713
|
+
for (const use of found) {
|
|
714
|
+
const element = elementOf.get(`${use.file}\0${use.line}\0${use.column}`);
|
|
715
|
+
const key = `${use.file}\0${element?.line}\0${element?.column}`;
|
|
716
|
+
(byElement.get(key) ?? byElement.set(key, []).get(key))?.push(use);
|
|
717
|
+
}
|
|
718
|
+
/** @type {import('../../foundation/render/render-page.mjs').RenderWarning[]} */
|
|
719
|
+
const warnings = [];
|
|
720
|
+
for (const uses of byElement.values()) {
|
|
721
|
+
const {file, line, component: name} = uses[0];
|
|
722
|
+
/** @type {Map<string, string | null>} */
|
|
723
|
+
const props = new Map(uses.map(use => [use.prop, use.suggestion]));
|
|
724
|
+
const named = [...props].map(([prop, suggestion]) => (suggestion ? `${prop} (did you mean ${suggestion}?)` : prop));
|
|
725
|
+
let message = `${file}:${line}: ${name} has no ${named.join(', ')}`;
|
|
726
|
+
if ([...props.values()].some(suggestion => suggestion === null)) {
|
|
727
|
+
const takes = propNamesOf((await docsOf(name)) ?? []);
|
|
728
|
+
const rest = takes.length - PROPS_LISTED;
|
|
729
|
+
message += `; it takes ${takes.slice(0, PROPS_LISTED).join(', ')}${rest > 0 ? `, and ${rest} more (\`${getCliInvocation(dir)} component ${name} --package @astryxdesign/core\` lists them)` : ''}`;
|
|
730
|
+
}
|
|
731
|
+
warnings.push({code: 'unknown-prop', message: `${message}.`});
|
|
732
|
+
}
|
|
733
|
+
// A check that could not run says so once, with doctor's reason and what
|
|
734
|
+
// to install: silence would read as every prop being right.
|
|
735
|
+
// Outside a project a step that installs into a project does not apply.
|
|
736
|
+
const why = runChoice(dir).inProject ? skipped : (reason ?? skipped);
|
|
737
|
+
if (why) warnings.push({code: 'props-not-checked', message: `Core prop names: ${why}`});
|
|
738
|
+
return {warnings, props: new Set(found.map(use => use.prop))};
|
|
739
|
+
}
|
|
740
|
+
|
|
568
741
|
/**
|
|
569
742
|
* Render a page module to one HTML file and write it.
|
|
570
743
|
* @param {{cwd: string, input: string, output: string, title?: string, keepClassNames?: boolean, absolute?: boolean}} args absolute paths;
|
|
@@ -599,7 +772,27 @@ export async function renderToFile({cwd, input, output, title, keepClassNames =
|
|
|
599
772
|
} catch (e) {
|
|
600
773
|
throw asAstryxError(e, path.dirname(input), cwd);
|
|
601
774
|
}
|
|
602
|
-
|
|
775
|
+
const docs = coreDocsReader(path.dirname(input));
|
|
776
|
+
await docs.load([...(page.propValues ?? []), ...(page.propNames ?? [])].map(use => use.component));
|
|
777
|
+
const docsOf = docs.of;
|
|
778
|
+
/** @type {Awaited<ReturnType<typeof propNameWarnings>>} */
|
|
779
|
+
let named = {warnings: [], props: new Set()};
|
|
780
|
+
try {
|
|
781
|
+
named = await propNameWarnings(page.propNames ?? [], input, docsOf);
|
|
782
|
+
} catch {
|
|
783
|
+
// The check only warns: a project whose types cannot be read still exports.
|
|
784
|
+
}
|
|
785
|
+
// React's own console line for a prop the warning names says less, cut
|
|
786
|
+
// short, so it goes, before the page output is capped: it never hides a
|
|
787
|
+
// line the page printed itself.
|
|
788
|
+
const kept = (page.logs ?? []).filter(log => {
|
|
789
|
+
const prop = REACT_UNKNOWN_PROP.exec(log.text);
|
|
790
|
+
return !prop || !named.props.has(prop[1] ?? prop[2]);
|
|
791
|
+
});
|
|
792
|
+
const at = page.warnings.findIndex(warning => warning.code === 'page-output');
|
|
793
|
+
page.warnings = page.warnings.filter(warning => warning.code !== 'page-output');
|
|
794
|
+
page.warnings.splice(at === -1 ? page.warnings.length : at, 0, ...pageOutputWarnings(kept));
|
|
795
|
+
page.warnings.push(...(await propValueWarnings(page.propValues ?? [], input, docsOf)), ...named.warnings);
|
|
603
796
|
for (const {name, dir} of page.fromSet) {
|
|
604
797
|
let version = null;
|
|
605
798
|
try {
|
|
@@ -35,7 +35,7 @@ export type RenderWarning = {
|
|
|
35
35
|
/**
|
|
36
36
|
* - What kind of problem.
|
|
37
37
|
*/
|
|
38
|
-
code: "dropped-children" | "unknown-prop-value" | "remote-asset" | "missing-asset" | "page-output" | "page-script" | "no-astryx-styles" | "chart-size" | "screen-query" | "not-embedded" | "not-carried" | "node-crash";
|
|
38
|
+
code: "dropped-children" | "unknown-prop" | "props-not-checked" | "unknown-prop-value" | "remote-asset" | "missing-asset" | "page-output" | "page-script" | "no-astryx-styles" | "chart-size" | "screen-query" | "not-embedded" | "not-carried" | "node-crash";
|
|
39
39
|
/**
|
|
40
40
|
* - What happened and what to do, in one sentence.
|
|
41
41
|
*/
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* author meant.
|
|
24
24
|
* @experimental May change or be removed in a patch release.
|
|
25
25
|
* @typedef {object} RenderWarning
|
|
26
|
-
* @property {'dropped-children' | 'unknown-prop-value' | 'remote-asset' | 'missing-asset' | 'page-output' | 'page-script' | 'no-astryx-styles' | 'chart-size' | 'screen-query' | 'not-embedded' | 'not-carried' | 'node-crash'} code - What kind of problem.
|
|
26
|
+
* @property {'dropped-children' | 'unknown-prop' | 'props-not-checked' | 'unknown-prop-value' | 'remote-asset' | 'missing-asset' | 'page-output' | 'page-script' | 'no-astryx-styles' | 'chart-size' | 'screen-query' | 'not-embedded' | 'not-carried' | 'node-crash'} code - What kind of problem.
|
|
27
27
|
* @property {string} message - What happened and what to do, in one sentence.
|
|
28
28
|
*/
|
|
29
29
|
|
package/api/search/ORDERING.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Search ordering data
|
|
2
2
|
|
|
3
|
-
`astryx search` decides **what matches**, and each match's score and reason, with the lexical ranker (`_lexical.mjs` and the files it imports). The files in this folder only decide **the order of matches inside one score band**: they never add or drop a match, change a score, or move a match past one of another band or kind (doc or not), except a family root the lexical ranker marks, which moves directly before its part (below). The bands are scores 195 and up, 188–194, 170–187, 160–169, 151–159, 100–150, 55–99, and under 55. A band can be wide (55–99 holds keyword matches beside one-word description hits), so inside a band a lower score can lead a higher one. In search's own reading of the catalog (`searchView` in `_named-keywords.mjs`), another entry's name is that entry's evidence: a component a block uses (its doc's `componentsUsed`) can make the block's answer to a query word stronger but never answers a word alone, so it never lifts the block into the every-word tier (`_score.mjs`), while the order files here still read it as the block's docs text (`_entries.mjs`, `_fit-order.mjs`); a title inside the query takes the title tier only when every query word it leaves unanswered names no component or hook, or also names a doc; and a match whose name of two or more words the query writes as one whole word (`TableSortableTable`, `table-sortable-table`, a doc's `tokens-color`) leads the answer, alone or inside a longer query, unless a longer named run of the query, or a block's display name or a doc's title or heading that the query holds (`heldTitle` in `_titles.mjs`, as the title tier reads it), contains it (`_lexical.mjs`). The order files keep such an entry first in its run. In that reading, a doc that opens a level (a docs-tree namespace, holding the docs under its route as `_summarizes`) does not answer a query word through its text (its prose, or a code term or table cell its keywords gather) when a doc beneath it answers that word at least as strongly (`_candidate-score.mjs`); its name, title, description and declared keywords stay its own. `searchCore`, which build reads, keeps the gathered reading.
|
|
3
|
+
`astryx search` decides **what matches**, and each match's score and reason, with the lexical ranker (`_lexical.mjs` and the files it imports). The files in this folder only decide **the order of matches inside one score band**: they never add or drop a match, change a score, or move a match past one of another band or kind (doc or not), except a family root the lexical ranker marks, which moves directly before its part (below). The bands are scores 195 and up, 188–194, 170–187, 160–169, 151–159, 100–150, 55–99, and under 55. A band can be wide (55–99 holds keyword matches beside one-word description hits), so inside a band a lower score can lead a higher one. In search's own reading of the catalog (`searchView` in `_named-keywords.mjs`), another entry's name is that entry's evidence: a component a block uses (its doc's `componentsUsed`) can make the block's answer to a query word stronger but never answers a word alone, so it never lifts the block into the every-word tier (`_score.mjs`), while the order files here still read it as the block's docs text (`_entries.mjs`, `_fit-order.mjs`); an entry that is not a doc takes that tier only with two strong query words, each a keyword-strength hit or a word of its own name, display name or title, or the start of one, since one strong word and a mention of the others matches that word, not the ask, while a doc, which answers in prose, needs one (`_score.mjs`); a title inside the query takes the title tier only when every query word it leaves unanswered names no component or hook, or also names a doc; and a match whose name of two or more words the query writes as one whole word (`TableSortableTable`, `table-sortable-table`, a doc's `tokens-color`) leads the answer, alone or inside a longer query, unless a longer named run of the query, or a block's display name or a doc's title or heading that the query holds (`heldTitle` in `_titles.mjs`, as the title tier reads it), contains it (`_lexical.mjs`). An entry whose name of three or more words the query spells out as words apart, every word in order and at most one word misspelled with its first letter kept, as the lexical scorer reads a misspelled name (`pagination dots carousle`), leads its band, also ahead of its family's root, unless a longer name the query names, or another entry's display name or title the query holds, contains it; two words apart stay plain language (`_lexical.mjs`). The order files keep such an entry first in its run. In that reading, a doc that opens a level (a docs-tree namespace, holding the docs under its route as `_summarizes`) does not answer a query word through its text (its prose, or a code term or table cell its keywords gather) when a doc beneath it answers that word at least as strongly (`_candidate-score.mjs`); its name, title, description and declared keywords stay its own. `searchCore`, which build reads, keeps the gathered reading.
|
|
4
4
|
|
|
5
5
|
## Rule
|
|
6
6
|
|
|
7
|
-
`spec:AST-083` owns search's result order; this file describes the data that implements it. Inside one score band, a searcher's static weights decide the order. Matches with the same score move together as one block, placed by the learned position of the block's first match: moving each one on its own breaks search's existing rules for tied matches. Then a family's root leads a part of its own family (same domain, families from each member's doc) when the root answers every query word the part answers, no query word is, in any plural or stem form, a word of the part's name that does not start a word of the root's name, and the query does not write the part's name of two or more words as one word, as the paragraph above reads such a name or misspelled as the scorer reads a misspelled name. The lexical ranker decides this and names each such root (`rootLeadsOf` in `_lexical.mjs`); after the ties below are ordered, a root that sits below its part moves directly before the part, whatever its band (`rootsFirst`), so nothing else moves and the part's tie keeps its own order behind it: `tabs` puts TabList before its Tab, and `code sample` puts CodeBlock before its Code even though Code's name hit scores a band higher, while a query holding "item" keeps ListItem before List, one holding "statuses" keeps FieldStatus before Field, and `breadcrumbitm` keeps BreadcrumbItem first. Nothing else moves, except that when the root moves to first place, the tie below it puts the root's parts first (below). Then the first result's tie can go to another match (`tieByOwnName`): among matches of the first result's domain that scored the same as it and matched the same query words (the terms their reasons list), a match whose name words hold more of the query's words than the first result's name moves first. A first result whose reason lists no terms keeps its place: one that matched the whole query (a name, keyword, or title hit) or whose title the query holds (`how do i generate a palette` keeps `author-a-theme` ahead of the tied `generate-a-palette` doc); a part of the first result (in its family, or its name words start with the first result's) never takes its place this way; and an entry the query names keeps it. Without this, a tie for first place goes to the first name alphabetically. Inside a block, the lexical ranker's order holds, except below the first result: there a block of one domain puts a part of the first result first (its name words start with the first result's; at most two parts lead across an answer; the first result is the root when a root leads the part that comes first), then the match whose matched words are rarer in the catalog. Matches never cross bands or kinds, apart from a family root the lexical ranker marks as leading its part, which moves directly before the part. There is no model runtime: every number is a plain static value read at load time. A one-word PascalCase query that only doc text mentions is read as its words too (`identifierReading` in `_lexical.mjs`): the lexical ranker puts the entries that mention it, and those its words name outright, before the entries its words only match, and the learned order and fit pass then apply to that order as to any other.
|
|
7
|
+
`spec:AST-083` owns search's result order; this file describes the data that implements it. Inside one score band, a searcher's static weights decide the order. Matches with the same score move together as one block, placed by the learned position of the block's first match: moving each one on its own breaks search's existing rules for tied matches. Then a family's root leads a part of its own family (same domain, families from each member's doc) when the root answers every query word the part answers, no query word is, in any plural or stem form, a word of the part's name that does not start a word of the root's name, and the query does not write the part's name of two or more words as one word, as the paragraph above reads such a name or misspelled as the scorer reads a misspelled name (a typed word that is the root's own name or its plural, `stack` beside HStack, is no misspelling). A root leads its part from another run only when its own hits on the words the part answers have keyword strength (the whole name, the name's head word, or a keyword, also one edit away), not a word inside its name or a mention in its text (`weakRootsOf` holds the rest): `router` and `react router` keep LinkProvider, whose keyword is `router`, above Link, whose description only mentions it. The lexical ranker decides this and names each such root (`rootLeadsOf` in `_lexical.mjs`); after the ties below are ordered, a root that sits below its part moves directly before the part, whatever its band (`rootsFirst`), so nothing else moves and the part's tie keeps its own order behind it: `tabs` puts TabList before its Tab, and `code sample` puts CodeBlock before its Code even though Code's name hit scores a band higher, while a query holding "item" keeps ListItem before List, one holding "statuses" keeps FieldStatus before Field, and `breadcrumbitm` keeps BreadcrumbItem first. Nothing else moves, except that when the root moves to first place, the tie below it puts the root's parts first (below). Then the first result's tie can go to another match (`tieByOwnName`): among matches of the first result's domain that scored the same as it and matched the same query words (the terms their reasons list), a match whose name words hold more of the query's words than the first result's name moves first. A first result whose reason lists no terms keeps its place: one that matched the whole query (a name, keyword, or title hit) or whose title the query holds (`how do i generate a palette` keeps `author-a-theme` ahead of the tied `generate-a-palette` doc); a part of the first result (in its family, or its name words start with the first result's) never takes its place this way; and an entry the query names keeps it. Without this, a tie for first place goes to the first name alphabetically. Inside a block, the lexical ranker's order holds, except below the first result: there a block of one domain puts a part of the first result first (its name words start with the first result's; at most two parts lead across an answer; the first result is the root when a root leads the part that comes first), then the match whose matched words are rarer in the catalog. Matches never cross bands or kinds, apart from a family root the lexical ranker marks as leading its part with hits of keyword strength, which moves directly before the part. There is no model runtime: every number is a plain static value read at load time. A one-word PascalCase query that only doc text mentions is read as its words too (`identifierReading` in `_lexical.mjs`): the lexical ranker puts the entries that mention it, and those its words name outright, before the entries its words only match, and the learned order and fit pass then apply to that order as to any other.
|
|
8
8
|
|
|
9
9
|
After that order, one fit pass reads the first ten results (`_fit-order.mjs`). The first result stays. The others split into runs of one band and kind. Inside a run, each match gets a fit to the whole query from the block picker's `matchOf` (`../build/blocks/blocks.mjs` with `blocks.weights.json`, over the weights' vocabulary) over the match's own docs: its name words, display name or title, description, and keywords. A match whose fit is under 1.7 times the run's median fit moves, in order, after the others in its run, unless its name spells two or more of the query's words, or it is a family root the order moved directly before its part, or that part (a root that already sat above its part is not held); such a part counts in its root's run, so nothing comes between the two. Such a match never moves down; it can still move up when others move after it. A run whose median fit is zero or less keeps its order. A query that is an entry's whole name skips the pass, as it skips the learned order. The pass always reads ten places before the limit cuts the answer. At the default limit, and at any limit of 10 or more, the set of results stays the same. A smaller limit shows the top of the new order, so it can show a different result. Build's loader (`loadBlockPicker` in `../build/_adapter.mjs`) reads and checks the block-picker weights for both commands. When the file is missing, unreadable, or not the picker's shape, the loader returns null and the pass keeps the order. The pass reads the weights only when a run holds two or more matches, and it decodes only the matrix rows that the query's words and those matches' docs use, so a search does not pay for the whole catalog.
|
|
10
10
|
|
package/api/search/_adapter.mjs
CHANGED
|
@@ -68,6 +68,9 @@ export async function searchIconSection(
|
|
|
68
68
|
if (!iconFeatureGate(project).on) return null;
|
|
69
69
|
const loaded = /** @type {Project} */ (project);
|
|
70
70
|
const {iconSection} = await import('./_icons.mjs');
|
|
71
|
+
const {coreComponentNames} = await import('../icon/_adapter.mjs');
|
|
72
|
+
/** @type {string[] | undefined} */
|
|
73
|
+
let names;
|
|
71
74
|
return iconSection(
|
|
72
75
|
query,
|
|
73
76
|
{
|
|
@@ -87,6 +90,7 @@ export async function searchIconSection(
|
|
|
87
90
|
};
|
|
88
91
|
}
|
|
89
92
|
},
|
|
93
|
+
componentNames: () => (names ??= coreComponentNames(cwd)),
|
|
90
94
|
},
|
|
91
95
|
{declaredNames, resultDomains, limit},
|
|
92
96
|
);
|
|
@@ -108,6 +108,25 @@ const mentionPatterns = new Map();
|
|
|
108
108
|
*/
|
|
109
109
|
const MENTION_LIMIT = 1_000;
|
|
110
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Each term's forms (see termWords), worked out once per term, not once for
|
|
113
|
+
* every candidate: a search scores every candidate for every term and
|
|
114
|
+
* synonym. The cache starts over at MENTION_LIMIT terms, as the patterns do.
|
|
115
|
+
* @type {Map<string, import('./_words.mjs').TermWords>}
|
|
116
|
+
*/
|
|
117
|
+
const termForms = new Map();
|
|
118
|
+
|
|
119
|
+
/** @param {string} term */
|
|
120
|
+
function formsOf(term) {
|
|
121
|
+
let t = termForms.get(term);
|
|
122
|
+
if (!t) {
|
|
123
|
+
if (termForms.size >= MENTION_LIMIT) termForms.clear();
|
|
124
|
+
t = termWords(term);
|
|
125
|
+
termForms.set(term, t);
|
|
126
|
+
}
|
|
127
|
+
return t;
|
|
128
|
+
}
|
|
129
|
+
|
|
111
130
|
/**
|
|
112
131
|
* @param {string} term
|
|
113
132
|
* @param {ReturnType<typeof termWords>} t - the term's words
|
|
@@ -271,8 +290,12 @@ export function scoreCandidate(
|
|
|
271
290
|
_familyIndex,
|
|
272
291
|
} = candidate;
|
|
273
292
|
// The term's forms, worked out once for every word below.
|
|
274
|
-
const t =
|
|
293
|
+
const t = formsOf(term);
|
|
275
294
|
const p = prepare(candidate);
|
|
295
|
+
// Whether the term has a space, and the term with its spaces removed:
|
|
296
|
+
// the same for every name and keyword below.
|
|
297
|
+
const spaced = /\s/.test(term);
|
|
298
|
+
const termNoSpace = spaced ? term.replace(/\s+/g, '') : term;
|
|
276
299
|
let best = 0;
|
|
277
300
|
let reason = '';
|
|
278
301
|
/** @type {'partial' | 'keyword' | false} */
|
|
@@ -345,15 +368,15 @@ export function scoreCandidate(
|
|
|
345
368
|
const spelled =
|
|
346
369
|
domain !== 'doc' &&
|
|
347
370
|
!/[\s_-]/.test(nameLower) &&
|
|
348
|
-
nameLower ===
|
|
371
|
+
nameLower === termNoSpace;
|
|
349
372
|
if (nameLower === term || leafLower === term || spelled) {
|
|
350
373
|
consider(100, 'exact name');
|
|
351
374
|
} else if (
|
|
352
375
|
joins &&
|
|
353
376
|
(domain === 'component' || domain === 'hook') &&
|
|
354
|
-
|
|
355
|
-
nameLower.startsWith(
|
|
356
|
-
|
|
377
|
+
spaced &&
|
|
378
|
+
nameLower.startsWith(termNoSpace) &&
|
|
379
|
+
termNoSpace.length / nameLower.length >= 0.75
|
|
357
380
|
) {
|
|
358
381
|
// Most of the name typed as words, cut short: `complex select` is
|
|
359
382
|
// ComplexSelector, ahead of a one-word keyword elsewhere.
|
|
@@ -361,6 +384,7 @@ export function scoreCandidate(
|
|
|
361
384
|
} else if (
|
|
362
385
|
domain !== 'doc' &&
|
|
363
386
|
domain !== 'theme' &&
|
|
387
|
+
spaced &&
|
|
364
388
|
spellsOut(term, candidateName, description)
|
|
365
389
|
) {
|
|
366
390
|
// The name's short words spelled out, in order, as the entry's own
|
|
@@ -410,7 +434,7 @@ export function scoreCandidate(
|
|
|
410
434
|
(_familyIndex ?? Infinity) < FAMILY_MEMBERS &&
|
|
411
435
|
(term === _family.toLowerCase() ||
|
|
412
436
|
term === wordsOf(_family).join(' ') ||
|
|
413
|
-
|
|
437
|
+
termNoSpace === _family.toLowerCase())
|
|
414
438
|
) {
|
|
415
439
|
consider(90, `member of ${_family}`);
|
|
416
440
|
}
|
|
@@ -419,7 +443,7 @@ export function scoreCandidate(
|
|
|
419
443
|
// In search's reading (`ownEvidence`), a template's used components match
|
|
420
444
|
// as its keywords do, after its own keywords, and the hit says it came from
|
|
421
445
|
// one.
|
|
422
|
-
const termJoined = joined(term);
|
|
446
|
+
const termJoined = spaced ? joined(term) : '';
|
|
423
447
|
/** Whether a keyword is one the page's text gathers (see `consider`). */
|
|
424
448
|
const byText = (/** @type {string} */ lower) =>
|
|
425
449
|
summarized != null && mentionKeyword(candidate, lower);
|
|
@@ -452,7 +476,7 @@ export function scoreCandidate(
|
|
|
452
476
|
);
|
|
453
477
|
continue;
|
|
454
478
|
}
|
|
455
|
-
if (joins && domain !== 'doc' &&
|
|
479
|
+
if (joins && domain !== 'doc' && spaced && kwText === termJoined) {
|
|
456
480
|
consider(
|
|
457
481
|
90,
|
|
458
482
|
`keyword "${kw}"`,
|
package/api/search/_cards.json
CHANGED
|
@@ -2811,7 +2811,7 @@
|
|
|
2811
2811
|
]
|
|
2812
2812
|
},
|
|
2813
2813
|
"NavIcon":{
|
|
2814
|
-
"what":"A small circular, accent-colored icon container used as a logo/brand mark inside
|
|
2814
|
+
"what":"A small circular, accent-colored icon container used as a logo/brand mark inside TopNavHeading or SideNavHeading.",
|
|
2815
2815
|
"synonyms":[
|
|
2816
2816
|
"logo badge",
|
|
2817
2817
|
"app icon circle",
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
-
/** @typedef {import('./_lexical.mjs').Candidate} Candidate */
|
|
5
4
|
/**
|
|
6
5
|
* The strongest hit a run of two or more adjacent query words has when it is
|
|
7
6
|
* read as one joined word, and the query words it covers. Readers type a
|