@astryxdesign/cli 0.7.9-canary.7eee905 → 0.7.9-canary.7fb5cab
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/component/__fixtures__/resolutions/modules.txt +2 -2
- package/api/discover/_adapter.d.mts +1 -1
- package/api/docs/_adapter.d.mts +8 -2
- package/api/docs/_adapter.mjs +10 -4
- package/api/docs/detail/section/section.d.mts +5 -2
- package/api/docs/detail/section/section.mjs +6 -2
- package/api/docs/docs.mjs +7 -1
- package/api/search/_candidate-score.mjs +25 -23
- package/api/search/_main-searcher.mjs +1 -1
- package/api/search/_result.d.mts +5 -5
- package/api/search/_words.d.mts +44 -7
- package/api/search/_words.mjs +113 -21
- package/api/search/search.d.mts +1 -1
- package/api/swizzle/_adapter.d.mts +10 -0
- package/api/swizzle/_adapter.mjs +24 -1
- package/api/swizzle/copy/copy.d.mts +17 -1
- package/api/swizzle/copy/copy.mjs +249 -9
- package/api/swizzle/swizzle.doc.mjs +1 -1
- package/api/swizzle/swizzle.type.mjs +1 -1
- package/api/theme/build/build.mjs +278 -38
- package/api/theme/build/icon-imports.d.mts +35 -4
- package/api/theme/build/icon-imports.mjs +299 -38
- package/assets/discover/official-packages.json +4 -0
- package/assets/docs/author-a-theme.doc.mjs +3 -1
- package/assets/docs/icons.doc.mjs +29 -0
- package/assets/docs/motion.doc.mjs +1 -1
- package/assets/docs/tree/calendar-systems.doc.mjs +146 -0
- package/assets/docs/tree/calendars.doc.mjs +46 -0
- package/assets/docs/tree/i18n-calendars.doc.mjs +51 -0
- package/assets/docs/tree/internationalization.doc.mjs +3 -3
- package/assets/templates/blocks/components/Hooks/useMergedRefsHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useMergedRefsHookUsage.tsx +78 -0
- package/assets/templates/blocks/components/Hooks/useScrollOverflowHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useScrollOverflowHookUsage.tsx +94 -0
- package/assets/templates/blocks/components/Icon/useIconHookUsage.doc.mjs +19 -0
- package/assets/templates/blocks/components/Icon/useIconHookUsage.tsx +68 -0
- package/assets/templates/blocks/components/Link/useLinkComponentHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Link/useLinkComponentHookUsage.tsx +89 -0
- package/assets/templates/blocks/components/PowerSearch/PowerSearchContentSearch.tsx +8 -7
- package/assets/templates/blocks/components/PowerSearch/PowerSearchFullFeatured.tsx +8 -7
- package/assets/templates/blocks/components/PowerSearch/PowerSearchPresetFilters.tsx +8 -7
- package/assets/templates/blocks/components/PowerSearch/PowerSearchSearchWithTable.tsx +12 -10
- package/assets/templates/blocks/components/PowerSearch/PowerSearchShowcase.tsx +8 -7
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.doc.mjs +2 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +2 -2
- package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +0 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +0 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.doc.mjs +2 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +0 -2
- package/assets/templates/blocks/components/usePanGesture/PanDraggableBox.doc.mjs +15 -0
- package/assets/templates/blocks/components/usePanGesture/PanDraggableBox.tsx +98 -0
- package/assets/templates/blocks/components/usePanGesture/PanPlayingCard.doc.mjs +14 -0
- package/assets/templates/blocks/components/usePanGesture/PanPlayingCard.tsx +147 -0
- package/assets/templates/pages/table-inbox/page.tsx +11 -8
- package/assets/templates/pages/work-item-detail/page.tsx +6 -2
- package/assets/theme.template.ts +14 -2
- package/authoring/debug/parse.d.mts +2 -2
- package/authoring/doctypes/base/type.ts +41 -0
- package/authoring/doctypes/component/component.doc.mjs +7 -1
- package/authoring/doctypes/component/type.ts +5 -0
- package/authoring/index.d.ts +2 -0
- package/clients/cli/commands/ensure-core-built.mjs +399 -43
- package/clients/cli/commands/swizzle.mjs +10 -0
- package/clients/cli/index.mjs +11 -6
- package/clients/cli/lib/component-format.mjs +49 -0
- package/foundation/agent-docs/agent-docs-target.d.mts +49 -0
- package/foundation/agent-docs/agent-docs-target.mjs +201 -0
- package/foundation/agent-docs/agent-docs.d.mts +1 -38
- package/foundation/agent-docs/agent-docs.mjs +16 -181
- package/foundation/config/config-path.d.mts +13 -0
- package/foundation/config/config-path.mjs +42 -0
- package/foundation/config/project.d.mts +1 -10
- package/foundation/config/project.mjs +31 -35
- package/foundation/discovery/component-discovery.mjs +56 -10
- package/foundation/discovery/component-loader.d.mts +1 -1
- package/foundation/discovery/icon-set-paths.d.mts +18 -0
- package/foundation/discovery/icon-set-paths.mjs +23 -0
- package/foundation/discovery/icon-set-writer.d.mts +2 -7
- package/foundation/discovery/icon-set-writer.mjs +3 -12
- package/foundation/env/search-path.d.mts +12 -0
- package/foundation/env/search-path.mjs +71 -43
- package/foundation/fs/module-loader.d.mts +2 -8
- package/foundation/fs/module-loader.mjs +3 -12
- package/foundation/fs/present-files.d.mts +11 -0
- package/foundation/fs/present-files.mjs +25 -0
- package/foundation/integrations/autolink.d.mts +2 -21
- package/foundation/integrations/autolink.mjs +6 -42
- package/foundation/integrations/contribution-fixes.mjs +26 -3
- package/foundation/integrations/contribution-inventory.mjs +1 -1
- package/foundation/integrations/installed-package.d.mts +36 -0
- package/foundation/integrations/installed-package.mjs +57 -0
- package/foundation/integrations/integrations.d.mts +3 -75
- package/foundation/integrations/integrations.mjs +3 -16
- package/foundation/integrations/manifest-paths.d.mts +13 -0
- package/foundation/integrations/manifest-paths.mjs +31 -0
- package/foundation/integrations/manifest-writer.d.mts +3 -4
- package/foundation/integrations/manifest-writer.mjs +5 -3
- package/foundation/release/cache.d.mts +11 -4
- package/foundation/release/cache.mjs +15 -7
- package/foundation/response/response-types.doc.mjs +1 -1
- package/foundation/runtime/locked-versions.mjs +1 -1
- package/foundation/runtime/package-set.mjs +1 -1
- package/foundation/text/levenshtein.d.mts +4 -1
- package/foundation/text/levenshtein.mjs +44 -1
- package/package.json +9 -9
- package/api/swizzle/_github.d.mts +0 -8
- package/api/swizzle/_github.mjs +0 -22
package/README.md
CHANGED
|
@@ -499,7 +499,7 @@ Every response has a `type` discriminant. The full set is below (generated from
|
|
|
499
499
|
| `build.help` | The how-to-build-a-page playbook, emitted when no query is given: `playbook: true`, a title, the ordered steps (title, commands, optional returns), the on-system rules, and related lookups. Commands are bare subcommands for the caller to render with its own invocation. |
|
|
500
500
|
| `build.kit` | The template to start from and its kit: query, hasResults, matchCount (never a cap), directMatch, start {name, package, command, basis, reason, alternatives, ...} (the start and each alternative name the package that owns the template), pages (search's closest templates), blocks and domain as SearchResultEntry[] (each naming its package), frame and foundation (Core component names), and hint {reason, commands} when thin. |
|
|
501
501
|
| `swizzle.list` | The names of swizzlable components discoverable from cwd's @astryxdesign/core. The envelope's package is @astryxdesign/core. |
|
|
502
|
-
| `swizzle.copy` | An eject receipt: component name, owning package, output directory, files-copied count, the
|
|
502
|
+
| `swizzle.copy` | An eject receipt: component name, owning package, output directory, files-copied count, the copied file names (relative to the component folder; owner modules copied beside it start with ../), whether any file uses StyleX, and, when the owner has an issues URL, feedback ({issuesUrl, ghCommand?}): where to report the gap that led to swizzling. The envelope's package names the same owning package. |
|
|
503
503
|
| `gap-report.categories` | The fixed gap category values and human-readable labels; when a loaded integration names its own issues URL, meta.destinations lists every destination ({to, default, issuesUrl}) and meta.ask tells an agent to ask the person. |
|
|
504
504
|
| `gap-report.file` | An aggregate receipt: overall status, the selected package, issuesUrl (or null), deliveries in handler order, each {handlerType: project \| integration \| fallback, handler, audience, status, url, message}, and filedCount/routedOnlyCount totals; without --to, when a loaded integration names its own issues URL, destinations and ask as on gap-report.categories. |
|
|
505
505
|
| `template.list` | The effective discovered TemplateListEntry[] for pages and blocks. A winning replacement entry includes optional `replaces`, naming the Core id omitted from the default list. |
|
|
@@ -264,14 +264,14 @@ useEndLaneReserve useEndLaneReserve Tokenizer/Tokenizer.doc.mjs Tokenizer/useEnd
|
|
|
264
264
|
useFieldStatusAnnouncement useFieldStatusAnnouncement FieldStatus/FieldStatus.doc.mjs FieldStatus/useFieldStatusAnnouncement.ts
|
|
265
265
|
useFocusReturnVisibility useFocusReturnVisibility hooks/useAnimatedLayout.doc.mjs hooks/useFocusReturnVisibility.ts
|
|
266
266
|
useHighlightedOptionScroll useHighlightedOptionScroll hooks/useAnimatedLayout.doc.mjs hooks/useHighlightedOptionScroll.ts
|
|
267
|
-
useIcon useIcon Icon/
|
|
267
|
+
useIcon useIcon Icon/useIcon.doc.mjs Icon/useIcon.ts
|
|
268
268
|
useIndicator useIndicator Indicator/Indicator.doc.mjs Indicator/useIndicator.ts
|
|
269
269
|
useInternalConfig useInternalConfig PowerSearch/PowerSearch.doc.mjs PowerSearch/useInternalConfig.ts
|
|
270
270
|
useIsHydrating useIsHydrating hooks/useAnimatedLayout.doc.mjs hooks/useIsHydrating.ts
|
|
271
271
|
useIsomorphicLayoutEffect useIsomorphicLayoutEffect hooks/useAnimatedLayout.doc.mjs hooks/useIsomorphicLayoutEffect.ts
|
|
272
272
|
useLayerDismissal useLayerDismissal Layer/Layer.doc.mjs Layer/useLayerDismissal.ts
|
|
273
273
|
useLightbox useLightbox Lightbox/useLightbox.doc.mjs Lightbox/useLightbox.tsx
|
|
274
|
-
useLinkComponent useLinkComponent Link/
|
|
274
|
+
useLinkComponent useLinkComponent Link/useLinkComponent.doc.mjs Link/useLinkComponent.ts
|
|
275
275
|
useLinkify useLinkify Link/Link.doc.mjs Link/useLinkify.tsx
|
|
276
276
|
useListFormatter useListFormatter i18n/InternationalizationProvider.doc.mjs i18n/useListFormatter.ts
|
|
277
277
|
useMenuDrillIn useMenuDrillIn DropdownMenu/DropdownMenu.doc.mjs DropdownMenu/useMenuDrillIn.tsx
|
|
@@ -216,7 +216,7 @@ export const OFFICIAL_LIST_FILE: string;
|
|
|
216
216
|
*/
|
|
217
217
|
export const EXPERIMENTAL_KINDS: readonly ["icon-set"];
|
|
218
218
|
/** The item kinds every project reads: the catalog kinds, less experimental ones. */
|
|
219
|
-
export const STABLE_KINDS: ("template" | "component" | "
|
|
219
|
+
export const STABLE_KINDS: ("template" | "component" | "doc" | "theme" | "codemod" | "agent-doc" | "icon-set")[];
|
|
220
220
|
/** The list and detail entry fields for each item kind, in display order. */
|
|
221
221
|
export const KIND_FIELDS: readonly [readonly ["component", "components"], readonly ["template", "templates"], readonly ["doc", "docs"], readonly ["theme", "themes"], readonly ["codemod", "codemods"], readonly ["agent-doc", "agentDocs"], readonly ["icon-set", "iconSets"]];
|
|
222
222
|
export type ScannedPackage = import("./_package-scanner.mjs").ScannedPackage;
|
package/api/docs/_adapter.d.mts
CHANGED
|
@@ -274,6 +274,11 @@ export function topicLinks(catalog: DocsCatalog, entry: import("../../foundation
|
|
|
274
274
|
* decides.
|
|
275
275
|
* @param {unknown} topic
|
|
276
276
|
* @param {{cwd?: string}} [options]
|
|
277
|
+
* @param {DocsCatalog} [loaded] internal: a catalog the read already loaded,
|
|
278
|
+
* so the read and every part of it share one snapshot of the project's docs
|
|
279
|
+
* (and its memoized lowering) instead of loading the project again for each
|
|
280
|
+
* part. It is a separate argument, never an option, so no caller of the
|
|
281
|
+
* public `docs()` can set it
|
|
277
282
|
* @returns {Promise<
|
|
278
283
|
* | {kind: 'topic', catalog: DocsCatalog, entry: import('../../foundation/discovery/docs-discovery.mjs').DocsTopicEntry}
|
|
279
284
|
* | {kind: 'node', catalog: DocsCatalog, tree: import('../../foundation/doc-compiler/tree.mjs').DocsTree, node: import('../../foundation/doc-compiler/tree.mjs').TreeNode}
|
|
@@ -282,7 +287,7 @@ export function topicLinks(catalog: DocsCatalog, entry: import("../../foundation
|
|
|
282
287
|
*/
|
|
283
288
|
export function resolveDocsArgument(topic: unknown, { cwd }?: {
|
|
284
289
|
cwd?: string;
|
|
285
|
-
}): Promise<{
|
|
290
|
+
}, loaded?: DocsCatalog): Promise<{
|
|
286
291
|
kind: "topic";
|
|
287
292
|
catalog: DocsCatalog;
|
|
288
293
|
entry: import("../../foundation/discovery/docs-discovery.mjs").DocsTopicEntry;
|
|
@@ -358,13 +363,14 @@ export function notLoaded(catalog: DocsCatalog): string;
|
|
|
358
363
|
* and lower it for the topic readers.
|
|
359
364
|
* @param {unknown} topic
|
|
360
365
|
* @param {{lang?: string | null, zh?: boolean, dense?: boolean, cwd?: string}} [options]
|
|
366
|
+
* @param {DocsCatalog} [loaded] internal, as {@link resolveDocsArgument}
|
|
361
367
|
*/
|
|
362
368
|
export function resolveTopicDocs(topic: unknown, options?: {
|
|
363
369
|
lang?: string | null;
|
|
364
370
|
zh?: boolean;
|
|
365
371
|
dense?: boolean;
|
|
366
372
|
cwd?: string;
|
|
367
|
-
}): Promise<{
|
|
373
|
+
}, loaded?: DocsCatalog): Promise<{
|
|
368
374
|
catalog: DocsCatalog;
|
|
369
375
|
node: import("../../foundation/doc-compiler/compile.mjs").CompiledReferenceNode;
|
|
370
376
|
lang: string | null;
|
package/api/docs/_adapter.mjs
CHANGED
|
@@ -1721,14 +1721,19 @@ export async function topicLinks(catalog, entry) {
|
|
|
1721
1721
|
* decides.
|
|
1722
1722
|
* @param {unknown} topic
|
|
1723
1723
|
* @param {{cwd?: string}} [options]
|
|
1724
|
+
* @param {DocsCatalog} [loaded] internal: a catalog the read already loaded,
|
|
1725
|
+
* so the read and every part of it share one snapshot of the project's docs
|
|
1726
|
+
* (and its memoized lowering) instead of loading the project again for each
|
|
1727
|
+
* part. It is a separate argument, never an option, so no caller of the
|
|
1728
|
+
* public `docs()` can set it
|
|
1724
1729
|
* @returns {Promise<
|
|
1725
1730
|
* | {kind: 'topic', catalog: DocsCatalog, entry: import('../../foundation/discovery/docs-discovery.mjs').DocsTopicEntry}
|
|
1726
1731
|
* | {kind: 'node', catalog: DocsCatalog, tree: import('../../foundation/doc-compiler/tree.mjs').DocsTree, node: import('../../foundation/doc-compiler/tree.mjs').TreeNode}
|
|
1727
1732
|
* | {kind: 'unknown', catalog: DocsCatalog}
|
|
1728
1733
|
* >}
|
|
1729
1734
|
*/
|
|
1730
|
-
export async function resolveDocsArgument(topic, {cwd} = {}) {
|
|
1731
|
-
const catalog = await loadDocsCatalog(cwd);
|
|
1735
|
+
export async function resolveDocsArgument(topic, {cwd} = {}, loaded) {
|
|
1736
|
+
const catalog = loaded ?? (await loadDocsCatalog(cwd));
|
|
1732
1737
|
if (typeof topic !== 'string' || topic === '')
|
|
1733
1738
|
return {kind: 'unknown', catalog};
|
|
1734
1739
|
const tree = await projectTree(catalog);
|
|
@@ -1942,13 +1947,14 @@ export function notLoaded(catalog) {
|
|
|
1942
1947
|
* and lower it for the topic readers.
|
|
1943
1948
|
* @param {unknown} topic
|
|
1944
1949
|
* @param {{lang?: string | null, zh?: boolean, dense?: boolean, cwd?: string}} [options]
|
|
1950
|
+
* @param {DocsCatalog} [loaded] internal, as {@link resolveDocsArgument}
|
|
1945
1951
|
*/
|
|
1946
|
-
export async function resolveTopicDocs(topic, options = {}) {
|
|
1952
|
+
export async function resolveTopicDocs(topic, options = {}, loaded) {
|
|
1947
1953
|
const {lang = null, zh = false, dense = false, cwd} = options;
|
|
1948
1954
|
const effectiveLang = lang || (dense ? 'dense' : zh ? 'zh' : null);
|
|
1949
1955
|
// A public API caller could pass a non-string topic; it lands on the same
|
|
1950
1956
|
// stable code as an unknown name rather than a raw TypeError.
|
|
1951
|
-
const found = await resolveDocsArgument(topic, {cwd});
|
|
1957
|
+
const found = await resolveDocsArgument(topic, {cwd}, loaded);
|
|
1952
1958
|
if (found.kind !== 'topic') {
|
|
1953
1959
|
throw found.kind === 'node'
|
|
1954
1960
|
? new AstryxError(
|
|
@@ -30,14 +30,17 @@ export function section(topic: string, sectionName: string, options?: {
|
|
|
30
30
|
* with the section its own section read returns for the query; when that
|
|
31
31
|
* section's key (its `id`, else the key its title derives) is the query in
|
|
32
32
|
* some guides, those guides answer first. No guide, or several, fail with ERR_UNKNOWN_SECTION, naming
|
|
33
|
-
* the guides to read instead.
|
|
33
|
+
* the guides to read instead. Every guide is read from `catalog`, the one the
|
|
34
|
+
* namespace read loaded, so the read loads the project once, not once per
|
|
35
|
+
* guide below the namespace.
|
|
36
|
+
* @param {import('../../../../foundation/discovery/docs-discovery.mjs').DocsCatalog} catalog
|
|
34
37
|
* @param {import('../../../../foundation/doc-compiler/tree.mjs').DocsTree} tree
|
|
35
38
|
* @param {import('../../../../foundation/doc-compiler/tree.mjs').TreeNode} namespace
|
|
36
39
|
* @param {string} sectionName
|
|
37
40
|
* @param {object} [options] as {@link section}
|
|
38
41
|
* @returns {Promise<import('../../docs.type.mjs').DocsDetailSectionResponse>}
|
|
39
42
|
*/
|
|
40
|
-
export function namespaceSection(tree: import("../../../../foundation/doc-compiler/tree.mjs").DocsTree, namespace: import("../../../../foundation/doc-compiler/tree.mjs").TreeNode, sectionName: string, options?: object): Promise<import("../../docs.type.mjs").DocsDetailSectionResponse>;
|
|
43
|
+
export function namespaceSection(catalog: import("../../../../foundation/discovery/docs-discovery.mjs").DocsCatalog, tree: import("../../../../foundation/doc-compiler/tree.mjs").DocsTree, namespace: import("../../../../foundation/doc-compiler/tree.mjs").TreeNode, sectionName: string, options?: object): Promise<import("../../docs.type.mjs").DocsDetailSectionResponse>;
|
|
41
44
|
/**
|
|
42
45
|
* The guide a namespace section read answers from, or null to ask. When the
|
|
43
46
|
* query matches sections in several guides, the read asks the reader which
|
|
@@ -130,7 +130,10 @@ async function sectionResponse({catalog, node, lang, entry}, sections, match) {
|
|
|
130
130
|
* with the section its own section read returns for the query; when that
|
|
131
131
|
* section's key (its `id`, else the key its title derives) is the query in
|
|
132
132
|
* some guides, those guides answer first. No guide, or several, fail with ERR_UNKNOWN_SECTION, naming
|
|
133
|
-
* the guides to read instead.
|
|
133
|
+
* the guides to read instead. Every guide is read from `catalog`, the one the
|
|
134
|
+
* namespace read loaded, so the read loads the project once, not once per
|
|
135
|
+
* guide below the namespace.
|
|
136
|
+
* @param {import('../../../../foundation/discovery/docs-discovery.mjs').DocsCatalog} catalog
|
|
134
137
|
* @param {import('../../../../foundation/doc-compiler/tree.mjs').DocsTree} tree
|
|
135
138
|
* @param {import('../../../../foundation/doc-compiler/tree.mjs').TreeNode} namespace
|
|
136
139
|
* @param {string} sectionName
|
|
@@ -138,6 +141,7 @@ async function sectionResponse({catalog, node, lang, entry}, sections, match) {
|
|
|
138
141
|
* @returns {Promise<import('../../docs.type.mjs').DocsDetailSectionResponse>}
|
|
139
142
|
*/
|
|
140
143
|
export async function namespaceSection(
|
|
144
|
+
catalog,
|
|
141
145
|
tree,
|
|
142
146
|
namespace,
|
|
143
147
|
sectionName,
|
|
@@ -148,7 +152,7 @@ export async function namespaceSection(
|
|
|
148
152
|
/** @type {Omit<GuideMatch, 'match'>[]} */
|
|
149
153
|
const reads = [];
|
|
150
154
|
for (const guide of guides) {
|
|
151
|
-
const resolved = await resolveTopicDocs(guide.route, options);
|
|
155
|
+
const resolved = await resolveTopicDocs(guide.route, options, catalog);
|
|
152
156
|
reads.push({guide, resolved, sections: readerSections(resolved.node)});
|
|
153
157
|
}
|
|
154
158
|
|
package/api/docs/docs.mjs
CHANGED
|
@@ -155,7 +155,13 @@ async function docsRead(topic, section, options = {}) {
|
|
|
155
155
|
// A namespace answers a section read from the one guide below it that
|
|
156
156
|
// has the section (spec:AST-046 FR6). A typed doc is one read.
|
|
157
157
|
if (found.node.kind === 'namespace') {
|
|
158
|
-
return namespaceSection(
|
|
158
|
+
return namespaceSection(
|
|
159
|
+
found.catalog,
|
|
160
|
+
found.tree,
|
|
161
|
+
found.node,
|
|
162
|
+
section,
|
|
163
|
+
options,
|
|
164
|
+
);
|
|
159
165
|
}
|
|
160
166
|
throw new AstryxError(
|
|
161
167
|
`"${found.node.route}" has no sections. Read it whole: ${formatCliCommand(`docs ${found.node.route}`)}.`,
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
* "cable" is not "table".
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
|
-
import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
|
|
39
38
|
import {
|
|
40
39
|
stem,
|
|
41
|
-
wordForms,
|
|
42
40
|
sameWord,
|
|
43
|
-
|
|
41
|
+
sameTermWord,
|
|
42
|
+
startsATermWordOf,
|
|
43
|
+
termWords,
|
|
44
44
|
wordsOf,
|
|
45
45
|
joined,
|
|
46
|
-
|
|
46
|
+
typoDistance,
|
|
47
47
|
} from './_words.mjs';
|
|
48
48
|
import {pluralOf} from './_query.mjs';
|
|
49
49
|
|
|
@@ -79,14 +79,14 @@ function spellsOut(term, name, description) {
|
|
|
79
79
|
/**
|
|
80
80
|
* Whether a one-word term is a name's last word and every word before it is a
|
|
81
81
|
* single letter: Stack in VStack and HStack.
|
|
82
|
-
* @param {
|
|
82
|
+
* @param {import('./_words.mjs').TermWords} t
|
|
83
83
|
* @param {string} name
|
|
84
84
|
*/
|
|
85
|
-
function headOfLetters(
|
|
85
|
+
function headOfLetters(t, name) {
|
|
86
86
|
const parts = wordsOf(name);
|
|
87
87
|
return (
|
|
88
88
|
parts.length >= 2 &&
|
|
89
|
-
|
|
89
|
+
sameTermWord(t, parts[parts.length - 1]) &&
|
|
90
90
|
parts.slice(0, -1).every(p => p.length === 1)
|
|
91
91
|
);
|
|
92
92
|
}
|
|
@@ -97,14 +97,14 @@ const FAMILY_MEMBERS = 3;
|
|
|
97
97
|
/**
|
|
98
98
|
* A derived name's score for a term: 60 for the same word, 40 for a word the
|
|
99
99
|
* term starts, else 0.
|
|
100
|
-
* @param {
|
|
100
|
+
* @param {import('./_words.mjs').TermWords} t - The lowercased search term.
|
|
101
101
|
* @param {string} kw - The derived name as authored.
|
|
102
102
|
* @returns {number}
|
|
103
103
|
*/
|
|
104
|
-
function weakKeywordScore(
|
|
104
|
+
function weakKeywordScore(t, kw) {
|
|
105
105
|
const kwLower = String(kw).toLowerCase();
|
|
106
|
-
if (kwLower === term ||
|
|
107
|
-
return
|
|
106
|
+
if (kwLower === t.term || sameTermWord(t, kwLower)) return 60;
|
|
107
|
+
return startsATermWordOf(t, kw) ? 40 : 0;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/**
|
|
@@ -147,6 +147,8 @@ export function scoreCandidate(
|
|
|
147
147
|
_family,
|
|
148
148
|
_familyIndex,
|
|
149
149
|
} = candidate;
|
|
150
|
+
// The term's forms, worked out once for every word below.
|
|
151
|
+
const t = termWords(term);
|
|
150
152
|
let best = 0;
|
|
151
153
|
let reason = '';
|
|
152
154
|
/** @type {'partial' | 'keyword' | false} */
|
|
@@ -209,23 +211,23 @@ export function scoreCandidate(
|
|
|
209
211
|
// outranks the Token component for `tokens`.
|
|
210
212
|
consider(99, 'plural of the name');
|
|
211
213
|
} else {
|
|
212
|
-
if (
|
|
214
|
+
if (sameTermWord(t, nameLower)) consider(95, `name "${candidateName}"`);
|
|
213
215
|
// The term is a word of the name, or starts one: "input" in TextInput.
|
|
214
216
|
else if (
|
|
215
217
|
!part &&
|
|
216
218
|
domain !== 'doc' &&
|
|
217
219
|
domain !== 'theme' &&
|
|
218
|
-
headOfLetters(
|
|
220
|
+
headOfLetters(t, candidateName)
|
|
219
221
|
) {
|
|
220
222
|
// The whole query is the name's head word after single letters (Stack
|
|
221
223
|
// in VStack, HStack): a variant named by its head, as a keyword is.
|
|
222
224
|
consider(90, `name "${candidateName}" ends in "${term}"`);
|
|
223
|
-
} else if (
|
|
225
|
+
} else if (startsATermWordOf(t, candidateName)) {
|
|
224
226
|
consider(60, `name contains "${term}"`);
|
|
225
227
|
}
|
|
226
228
|
if (fuzzy) {
|
|
227
|
-
const dist =
|
|
228
|
-
if (
|
|
229
|
+
const dist = typoDistance(term, nameLower);
|
|
230
|
+
if (dist != null) {
|
|
229
231
|
consider(
|
|
230
232
|
dist === 1 ? 80 : dist === 2 ? 40 : 20,
|
|
231
233
|
`similar name (distance ${dist})`,
|
|
@@ -274,14 +276,14 @@ export function scoreCandidate(
|
|
|
274
276
|
consider(90, `keyword "${kw}"`, 'keyword');
|
|
275
277
|
continue;
|
|
276
278
|
}
|
|
277
|
-
if (
|
|
279
|
+
if (sameTermWord(t, kwLower)) {
|
|
278
280
|
consider(88, `keyword "${kw}"`);
|
|
279
281
|
continue;
|
|
280
282
|
}
|
|
281
|
-
if (
|
|
283
|
+
if (startsATermWordOf(t, kw)) consider(70, `keyword "${kw}"`);
|
|
282
284
|
if (fuzzy) {
|
|
283
|
-
const dist =
|
|
284
|
-
if (
|
|
285
|
+
const dist = typoDistance(term, kwLower);
|
|
286
|
+
if (dist != null && dist <= 2) {
|
|
285
287
|
consider(dist === 1 ? 70 : 30, `keyword "${kw}" (distance ${dist})`);
|
|
286
288
|
}
|
|
287
289
|
}
|
|
@@ -295,9 +297,9 @@ export function scoreCandidate(
|
|
|
295
297
|
// A bound skips the read when no name the page can yield matches the term,
|
|
296
298
|
// and then no weak keyword can match it either.
|
|
297
299
|
const bound = candidate.weakKeywordBound;
|
|
298
|
-
if (!bound || bound.some(kw => weakKeywordScore(
|
|
300
|
+
if (!bound || bound.some(kw => weakKeywordScore(t, kw) > 0)) {
|
|
299
301
|
for (const kw of candidate.weakKeywords ?? []) {
|
|
300
|
-
const score = weakKeywordScore(
|
|
302
|
+
const score = weakKeywordScore(t, kw);
|
|
301
303
|
if (score > 0) consider(score, `renders ${kw}`);
|
|
302
304
|
}
|
|
303
305
|
}
|
|
@@ -308,7 +310,7 @@ export function scoreCandidate(
|
|
|
308
310
|
if (term.length >= 3) {
|
|
309
311
|
// Any form of the term, with any common suffix: `spacing` finds
|
|
310
312
|
// "space" and "spaces", `tables` finds "table".
|
|
311
|
-
const roots = [...new Set([stem(term), ...
|
|
313
|
+
const roots = [...new Set([stem(term), ...t.forms])]
|
|
312
314
|
.filter(f => f.length >= 3)
|
|
313
315
|
.map(f => f.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
|
314
316
|
const re = new RegExp(`\\b(?:${roots.join('|')})(s|es|ing|ed|ies)?\\b`);
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* domain the query wants. Its weights are static numbers in
|
|
9
9
|
* _main-searcher.weights.json.
|
|
10
10
|
* @input {query, options} and the gathered catalog with its static data
|
|
11
|
-
* @output the search response, the lexical response's shape and
|
|
11
|
+
* @output the search response, the lexical response's shape and count
|
|
12
12
|
* @position api/search; a child of the root dispatcher in tree.mjs
|
|
13
13
|
*/
|
|
14
14
|
|
package/api/search/_result.d.mts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* (spec AST-081 FR3).
|
|
18
18
|
*/
|
|
19
19
|
export function toResult(c: Candidate, score: number, reason: string, matchedTerms: number, queryTerms: number, outside?: boolean): {
|
|
20
|
-
domain: "template" | "component" | "
|
|
20
|
+
domain: "template" | "component" | "doc" | "theme" | "hook";
|
|
21
21
|
name: string;
|
|
22
22
|
package: string | undefined;
|
|
23
23
|
score: number;
|
|
@@ -27,7 +27,7 @@ export function toResult(c: Candidate, score: number, reason: string, matchedTer
|
|
|
27
27
|
deprecated?: import("../../authoring/index.js").ComponentDeprecation | undefined;
|
|
28
28
|
import: string | undefined;
|
|
29
29
|
command: string;
|
|
30
|
-
domain: "template" | "component" | "
|
|
30
|
+
domain: "template" | "component" | "doc" | "theme" | "hook";
|
|
31
31
|
name: string;
|
|
32
32
|
package: string | undefined;
|
|
33
33
|
score: number;
|
|
@@ -39,7 +39,7 @@ export function toResult(c: Candidate, score: number, reason: string, matchedTer
|
|
|
39
39
|
command: string;
|
|
40
40
|
section?: string | undefined;
|
|
41
41
|
name: string;
|
|
42
|
-
domain: "template" | "component" | "
|
|
42
|
+
domain: "template" | "component" | "doc" | "theme" | "hook";
|
|
43
43
|
package: string | undefined;
|
|
44
44
|
score: number;
|
|
45
45
|
reason: string;
|
|
@@ -48,7 +48,7 @@ export function toResult(c: Candidate, score: number, reason: string, matchedTer
|
|
|
48
48
|
displayName: string | undefined;
|
|
49
49
|
kind: "page" | "block" | undefined;
|
|
50
50
|
command: string;
|
|
51
|
-
domain: "template" | "component" | "
|
|
51
|
+
domain: "template" | "component" | "doc" | "theme" | "hook";
|
|
52
52
|
name: string;
|
|
53
53
|
package: string | undefined;
|
|
54
54
|
score: number;
|
|
@@ -57,7 +57,7 @@ export function toResult(c: Candidate, score: number, reason: string, matchedTer
|
|
|
57
57
|
} | {
|
|
58
58
|
displayName: string | undefined;
|
|
59
59
|
command: string;
|
|
60
|
-
domain: "template" | "component" | "
|
|
60
|
+
domain: "template" | "component" | "doc" | "theme" | "hook";
|
|
61
61
|
name: string;
|
|
62
62
|
package: string | undefined;
|
|
63
63
|
score: number;
|
package/api/search/_words.d.mts
CHANGED
|
@@ -1,10 +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
|
-
/**
|
|
5
|
-
* @file Word matching for search: stems and word forms, word starts,
|
|
6
|
-
* identifier spelling, joined names, and typo tolerance.
|
|
7
|
-
*/
|
|
8
4
|
/**
|
|
9
5
|
* Light stemmer: strips common English suffixes so "charts"/"charting" and
|
|
10
6
|
* "chart" share a root. Deliberately crude (no Porter) — good enough to bridge
|
|
@@ -14,9 +10,7 @@
|
|
|
14
10
|
*/
|
|
15
11
|
export function stem(w: string): string;
|
|
16
12
|
/**
|
|
17
|
-
* The forms of a word that count as the same word
|
|
18
|
-
* singular when it ends in a plural suffix — so "tables" is "table",
|
|
19
|
-
* "statuses" is "status", and "filtering" is "filter".
|
|
13
|
+
* The forms of a word that count as the same word (see someForm).
|
|
20
14
|
* @param {string} w - Lowercase word.
|
|
21
15
|
* @returns {Set<string>}
|
|
22
16
|
*/
|
|
@@ -28,6 +22,23 @@ export function wordForms(w: string): Set<string>;
|
|
|
28
22
|
* @returns {boolean}
|
|
29
23
|
*/
|
|
30
24
|
export function sameWord(a: string, b: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* A search term's forms and the word starts it matches, worked out once for
|
|
27
|
+
* every word the term is compared with.
|
|
28
|
+
* @typedef {{term: string, forms: Set<string>, starts: string[]}} TermWords
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* @param {string} term - Lowercase term.
|
|
32
|
+
* @returns {TermWords}
|
|
33
|
+
*/
|
|
34
|
+
export function termWords(term: string): TermWords;
|
|
35
|
+
/**
|
|
36
|
+
* Whether a lowercase word is the term's word, as sameWord answers.
|
|
37
|
+
* @param {TermWords} t
|
|
38
|
+
* @param {string} w
|
|
39
|
+
* @returns {boolean}
|
|
40
|
+
*/
|
|
41
|
+
export function sameTermWord(t: TermWords, w: string): boolean;
|
|
31
42
|
/**
|
|
32
43
|
* The lowercase words of a name or keyword: split at non-alphanumerics and at
|
|
33
44
|
* camelCase boundaries, so "TextInput" is ["text", "input"] and
|
|
@@ -45,6 +56,13 @@ export function wordsOf(text: string): string[];
|
|
|
45
56
|
* @returns {boolean}
|
|
46
57
|
*/
|
|
47
58
|
export function startsAWordOf(term: string, text: string): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* startsAWordOf for a term whose words are already worked out.
|
|
61
|
+
* @param {TermWords} t
|
|
62
|
+
* @param {string} text - The name or keyword as authored.
|
|
63
|
+
* @returns {boolean}
|
|
64
|
+
*/
|
|
65
|
+
export function startsATermWordOf(t: TermWords, text: string): boolean;
|
|
48
66
|
/**
|
|
49
67
|
* A query with its camelCase and PascalCase identifiers spelled as words, so
|
|
50
68
|
* `SidebarToggle` reads "sidebar toggle" and `useTablePaginationState` "use
|
|
@@ -61,4 +79,23 @@ export function spellIdentifiers(query: string): string;
|
|
|
61
79
|
* @returns {string}
|
|
62
80
|
*/
|
|
63
81
|
export function joined(text: string): string;
|
|
82
|
+
/**
|
|
83
|
+
* The edit distance between two words when it counts as a typo (isTypo), or
|
|
84
|
+
* null. The shorter word's length caps the distance that can count. A pair
|
|
85
|
+
* the cap rules out needs no distance table, and the others compute only the
|
|
86
|
+
* cells within the cap.
|
|
87
|
+
* @param {string} a
|
|
88
|
+
* @param {string} b
|
|
89
|
+
* @returns {1 | 2 | 3 | null}
|
|
90
|
+
*/
|
|
91
|
+
export function typoDistance(a: string, b: string): 1 | 2 | 3 | null;
|
|
64
92
|
export function isTypo(a: string, b: string, dist: number): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* A search term's forms and the word starts it matches, worked out once for
|
|
95
|
+
* every word the term is compared with.
|
|
96
|
+
*/
|
|
97
|
+
export type TermWords = {
|
|
98
|
+
term: string;
|
|
99
|
+
forms: Set<string>;
|
|
100
|
+
starts: string[];
|
|
101
|
+
};
|