@wix/validation-infra 0.0.0-stage → 0.5.1
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 +192 -2
- package/dist/constants.d.ts +29 -0
- package/dist/constants.js +45 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +13 -0
- package/dist/package-readers/constants.d.ts +6 -0
- package/dist/package-readers/constants.js +6 -0
- package/dist/package-readers/index.d.ts +1 -0
- package/dist/package-readers/index.js +1 -0
- package/dist/package-readers/read-from-files.d.ts +6 -0
- package/dist/package-readers/read-from-files.js +76 -0
- package/dist/package-readers/types.d.ts +7 -0
- package/dist/package-readers/types.js +1 -0
- package/dist/package-readers/utils.d.ts +4 -0
- package/dist/package-readers/utils.js +15 -0
- package/dist/page-model/build-page-model.d.ts +3 -0
- package/dist/page-model/build-page-model.js +12 -0
- package/dist/page-model/connect-css.d.ts +3 -0
- package/dist/page-model/connect-css.js +43 -0
- package/dist/page-model/constants.d.ts +17 -0
- package/dist/page-model/constants.js +17 -0
- package/dist/page-model/css-selectors.d.ts +2 -0
- package/dist/page-model/css-selectors.js +7 -0
- package/dist/page-model/index.d.ts +4 -0
- package/dist/page-model/index.js +4 -0
- package/dist/page-model/pages.d.ts +2 -0
- package/dist/page-model/pages.js +18 -0
- package/dist/page-model/read-css.d.ts +4 -0
- package/dist/page-model/read-css.js +98 -0
- package/dist/page-model/read-structure.d.ts +3 -0
- package/dist/page-model/read-structure.js +59 -0
- package/dist/page-model/read-theme.d.ts +6 -0
- package/dist/page-model/read-theme.js +14 -0
- package/dist/page-model/types.d.ts +92 -0
- package/dist/page-model/types.js +1 -0
- package/dist/page-model/utils.d.ts +16 -0
- package/dist/page-model/utils.js +29 -0
- package/dist/project-model/index.d.ts +5 -0
- package/dist/project-model/index.js +5 -0
- package/dist/project-model/menu-files.d.ts +4 -0
- package/dist/project-model/menu-files.js +14 -0
- package/dist/project-model/package-json.d.ts +5 -0
- package/dist/project-model/package-json.js +27 -0
- package/dist/project-model/popups.d.ts +4 -0
- package/dist/project-model/popups.js +12 -0
- package/dist/project-model/project-model.d.ts +4 -0
- package/dist/project-model/project-model.js +14 -0
- package/dist/project-model/types.d.ts +20 -0
- package/dist/project-model/types.js +2 -0
- package/dist/rules/index.d.ts +4 -0
- package/dist/rules/index.js +5 -0
- package/dist/rules/project/define-project-rule.d.ts +5 -0
- package/dist/rules/project/define-project-rule.js +4 -0
- package/dist/rules/project/index.d.ts +2 -0
- package/dist/rules/project/index.js +2 -0
- package/dist/rules/project/types.d.ts +16 -0
- package/dist/rules/project/types.js +1 -0
- package/dist/rules/site-app/define-rule.d.ts +5 -0
- package/dist/rules/site-app/define-rule.js +4 -0
- package/dist/rules/site-app/index.d.ts +2 -0
- package/dist/rules/site-app/index.js +1 -0
- package/dist/rules/site-app/types.d.ts +26 -0
- package/dist/rules/site-app/types.js +1 -0
- package/dist/rules/site-code/define-site-code-rule.d.ts +5 -0
- package/dist/rules/site-code/define-site-code-rule.js +4 -0
- package/dist/rules/site-code/index.d.ts +2 -0
- package/dist/rules/site-code/index.js +2 -0
- package/dist/rules/site-code/types.d.ts +11 -0
- package/dist/rules/site-code/types.js +1 -0
- package/dist/rules/types.d.ts +13 -0
- package/dist/rules/types.js +3 -0
- package/dist/rules-adapter/eslint/index.d.ts +1 -0
- package/dist/rules-adapter/eslint/index.js +1 -0
- package/dist/rules-adapter/eslint/types.d.ts +5 -0
- package/dist/rules-adapter/eslint/types.js +1 -0
- package/dist/rules-adapter/index.d.ts +2 -0
- package/dist/rules-adapter/index.js +2 -0
- package/dist/rules-adapter/types.d.ts +16 -0
- package/dist/rules-adapter/types.js +1 -0
- package/dist/rules-adapter/utils.d.ts +7 -0
- package/dist/rules-adapter/utils.js +20 -0
- package/dist/rules-api/component-catalog.d.ts +8 -0
- package/dist/rules-api/component-catalog.js +28 -0
- package/dist/rules-api/constants.d.ts +7 -0
- package/dist/rules-api/constants.js +7 -0
- package/dist/rules-api/index.d.ts +18 -0
- package/dist/rules-api/index.js +14 -0
- package/dist/rules-api/report.d.ts +8 -0
- package/dist/rules-api/report.js +13 -0
- package/dist/rules-api/rules-api.d.ts +13 -0
- package/dist/rules-api/rules-api.js +139 -0
- package/dist/rules-api/types.d.ts +141 -0
- package/dist/rules-api/types.js +1 -0
- package/dist/rules-api/utils.d.ts +14 -0
- package/dist/rules-api/utils.js +27 -0
- package/dist/shared/constants.d.ts +188 -0
- package/dist/shared/constants.js +242 -0
- package/dist/shared/css-variables.d.ts +9 -0
- package/dist/shared/css-variables.js +38 -0
- package/dist/shared/css.d.ts +78 -0
- package/dist/shared/css.js +426 -0
- package/dist/shared/element-match.d.ts +16 -0
- package/dist/shared/element-match.js +72 -0
- package/dist/shared/font-weights.d.ts +2 -0
- package/dist/shared/font-weights.js +551 -0
- package/dist/shared/index.d.ts +16 -0
- package/dist/shared/index.js +15 -0
- package/dist/shared/interactions-config.d.ts +15 -0
- package/dist/shared/interactions-config.js +120 -0
- package/dist/shared/links.d.ts +21 -0
- package/dist/shared/links.js +93 -0
- package/dist/shared/posix-path.d.ts +8 -0
- package/dist/shared/posix-path.js +27 -0
- package/dist/shared/site-files-tree-mapping.d.ts +40 -0
- package/dist/shared/site-files-tree-mapping.js +41 -0
- package/dist/shared/site-folders.d.ts +3 -0
- package/dist/shared/site-folders.js +17 -0
- package/dist/shared/site-media.d.ts +3 -0
- package/dist/shared/site-media.js +11 -0
- package/dist/shared/syntax-tree.d.ts +4 -0
- package/dist/shared/syntax-tree.js +30 -0
- package/dist/shared/transformation-values.d.ts +22 -0
- package/dist/shared/transformation-values.js +74 -0
- package/dist/shared/types.d.ts +477 -0
- package/dist/shared/types.js +1 -0
- package/dist/shared/utils.d.ts +155 -0
- package/dist/shared/utils.js +553 -0
- package/dist/shared/wrapper-contract.d.ts +31 -0
- package/dist/shared/wrapper-contract.js +157 -0
- package/dist/shared/wrapper-image-props.d.ts +3 -0
- package/dist/shared/wrapper-image-props.js +75 -0
- package/dist/site-code-model/constants.d.ts +107 -0
- package/dist/site-code-model/constants.js +102 -0
- package/dist/site-code-model/index.d.ts +3 -0
- package/dist/site-code-model/index.js +4 -0
- package/dist/site-code-model/manifest-values.d.ts +15 -0
- package/dist/site-code-model/manifest-values.js +88 -0
- package/dist/site-code-model/read-module.d.ts +4 -0
- package/dist/site-code-model/read-module.js +267 -0
- package/dist/site-code-model/read-site-code-model.d.ts +9 -0
- package/dist/site-code-model/read-site-code-model.js +42 -0
- package/dist/site-code-model/source-locations.d.ts +5 -0
- package/dist/site-code-model/source-locations.js +95 -0
- package/dist/site-code-model/types.d.ts +102 -0
- package/dist/site-code-model/types.js +1 -0
- package/dist/testing.d.ts +24 -0
- package/dist/testing.js +61 -0
- package/dist/types.d.ts +95 -0
- package/dist/types.js +1 -0
- package/dist/validate.d.ts +7 -0
- package/dist/validate.js +180 -0
- package/package.json +59 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { ToolCallbacks, ToolContext } from './types.ts';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
2
|
+
/** Callback name (a node type, or the node type + ':exit') → the callback, as the tool calls it. */
|
|
3
|
+
export type ToolCallbacks = TSESLint.RuleListener;
|
|
4
|
+
/** What the tool gives a rule for one file: filename, cwd, sourceCode, options, report. Every problem is the one message, `{{message}}`. */
|
|
5
|
+
export type ToolContext = TSESLint.RuleContext<'problem', []>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Report, RulesApi } from '../rules-api/index.ts';
|
|
2
|
+
import type { RuleContext } from '../rules/index.ts';
|
|
3
|
+
import type { ToolCallbacks, ToolContext } from './eslint/index.ts';
|
|
4
|
+
export type { ToolContext };
|
|
5
|
+
/** The tool's node types and their ':exit' versions. Not an esquery selector: a typo is a compile error. */
|
|
6
|
+
export type CallbackName = keyof {
|
|
7
|
+
[K in keyof ToolCallbacks as string extends K ? never : K]: 1;
|
|
8
|
+
};
|
|
9
|
+
/** The node a callback gets: CallbackNode<'JSXElement'> is the tool's JSXElement. */
|
|
10
|
+
export type CallbackNode<K extends CallbackName> = Parameters<NonNullable<ToolCallbacks[K]>>[0];
|
|
11
|
+
/** What a rule's callbacks get on one file. rulesApi: built on first use, so a file no rule asks about is never read. */
|
|
12
|
+
export interface FileInput<Check extends string> {
|
|
13
|
+
rulesApi: () => RulesApi;
|
|
14
|
+
report: Report<Check>;
|
|
15
|
+
context: RuleContext;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Problem, Report } from '../rules-api/index.ts';
|
|
2
|
+
import type { Rule } from '../rules/index.ts';
|
|
3
|
+
import type { FileInput } from './types.ts';
|
|
4
|
+
/** The report a rule gets on a file: a violation found from both sides (parent and child) is reported once. ESLint doesn't do that. */
|
|
5
|
+
export declare function createReport<Check extends string>(send: (problem: Problem<Check>) => void): Report<Check>;
|
|
6
|
+
/** A rule's callbacks as the tool calls them, with the node only: every entry of rule.callbacks, so there's no list of names to keep. */
|
|
7
|
+
export declare function createToolCallbacks<Check extends string>(rule: Rule<Check>, { rulesApi, report, context }: FileInput<Check>): Record<string, (node: unknown) => void>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** The report a rule gets on a file: a violation found from both sides (parent and child) is reported once. ESLint doesn't do that. */
|
|
2
|
+
export function createReport(send) {
|
|
3
|
+
const reported = new Set();
|
|
4
|
+
return (problem) => {
|
|
5
|
+
const { start, end } = problem.loc;
|
|
6
|
+
const key = `${start.line}:${start.column}-${end.line}:${end.column} ${problem.message}`;
|
|
7
|
+
if (reported.has(key))
|
|
8
|
+
return;
|
|
9
|
+
reported.add(key);
|
|
10
|
+
send(problem);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** A rule's callbacks as the tool calls them, with the node only: every entry of rule.callbacks, so there's no list of names to keep. */
|
|
14
|
+
export function createToolCallbacks(rule, { rulesApi, report, context }) {
|
|
15
|
+
return Object.fromEntries(Object.entries(rule.callbacks).map(([name, callback]) => {
|
|
16
|
+
// The tool calls each callback with the node its name is for, as Callbacks types it.
|
|
17
|
+
const check = callback;
|
|
18
|
+
return [name, (node) => check({ node, get rulesApi() { return rulesApi(); }, report, context })];
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CatalogEntry, CatalogProvider, ComponentCatalog } from './types.ts';
|
|
2
|
+
/** The catalog's entry of a name imported from an app's wrapper, by its app and the name it's imported under:
|
|
3
|
+
* `import { CmsProvider_books } from '@origami-wrappers/WixCMS/cmsprovider_books'` → WixCMS's contextProviders.CmsProvider_books.
|
|
4
|
+
* null for an import from anywhere else, or a name the catalog doesn't list. */
|
|
5
|
+
export declare function getCatalogEntry(catalog: ComponentCatalog | undefined, source: string, imported: string): CatalogEntry | null;
|
|
6
|
+
/** An app's context providers, in the catalog's order: WixCMS → [{ name: 'CmsProvider_books', hook: 'useCmsContext',
|
|
7
|
+
* source: '@origami-wrappers/WixCMS/cmsprovider_books' }]. null for an app the catalog doesn't list. */
|
|
8
|
+
export declare function getContextProviders(catalog: ComponentCatalog | undefined, app: string): CatalogProvider[] | null;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// The site component catalog the export writes (site-component-catalog.json): the site's apps, and the components, context
|
|
2
|
+
// providers and function libraries each one has. The caller parses it and hands it in; rulesApi.getComponentCatalogEntry asks
|
|
3
|
+
// about one tag at a time, and getCatalogEntry looks that tag up in it.
|
|
4
|
+
import { WRAPPER_IMPORT } from "./constants.js";
|
|
5
|
+
/** The catalog's entry of a name imported from an app's wrapper, by its app and the name it's imported under:
|
|
6
|
+
* `import { CmsProvider_books } from '@origami-wrappers/WixCMS/cmsprovider_books'` → WixCMS's contextProviders.CmsProvider_books.
|
|
7
|
+
* null for an import from anywhere else, or a name the catalog doesn't list. */
|
|
8
|
+
export function getCatalogEntry(catalog, source, imported) {
|
|
9
|
+
const app = WRAPPER_IMPORT.exec(source)?.[1];
|
|
10
|
+
const entries = app === undefined ? undefined : catalog?.[app]?.entries;
|
|
11
|
+
if (app === undefined || !entries)
|
|
12
|
+
return null;
|
|
13
|
+
if (Object.hasOwn(entries.components ?? {}, imported))
|
|
14
|
+
return { app, name: imported, kind: 'component' };
|
|
15
|
+
if (Object.hasOwn(entries.contextProviders ?? {}, imported))
|
|
16
|
+
return { app, name: imported, kind: 'contextProvider' };
|
|
17
|
+
if (Object.hasOwn(entries.functionLibraries ?? {}, imported))
|
|
18
|
+
return { app, name: imported, kind: 'functionLibrary' };
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
/** An app's context providers, in the catalog's order: WixCMS → [{ name: 'CmsProvider_books', hook: 'useCmsContext',
|
|
22
|
+
* source: '@origami-wrappers/WixCMS/cmsprovider_books' }]. null for an app the catalog doesn't list. */
|
|
23
|
+
export function getContextProviders(catalog, app) {
|
|
24
|
+
const providers = catalog && Object.hasOwn(catalog, app) ? catalog[app].entries?.contextProviders : undefined;
|
|
25
|
+
if (!providers)
|
|
26
|
+
return null;
|
|
27
|
+
return Object.entries(providers).map(([name, item]) => ({ name, hook: item.hook, source: `@origami-wrappers/${app}/${name.toLowerCase()}` }));
|
|
28
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CssKind } from '../page-model/index.ts';
|
|
2
|
+
/** Theme lines come from @apply inside style.css, so style.css's own lines usually come after them. */
|
|
3
|
+
export declare const CASCADE_ORDER: readonly CssKind[];
|
|
4
|
+
/** An app's wrapper, as the export imports it: `@origami-wrappers/<app>/<folder>`, the folder its name lowercased (wrapperImport, origami-transforms). */
|
|
5
|
+
export declare const WRAPPER_IMPORT: RegExp;
|
|
6
|
+
/** The companion app: the site code's registrations are `companionApp.<name>` (origami-transforms wrapperSideEffects.ts COMPANION_APP). */
|
|
7
|
+
export declare const COMPANION_APP = "companionApp";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { WRAPPERS_SCOPE } from "../shared/index.js";
|
|
2
|
+
/** Theme lines come from @apply inside style.css, so style.css's own lines usually come after them. */
|
|
3
|
+
export const CASCADE_ORDER = ['layout', 'theme', 'style'];
|
|
4
|
+
/** An app's wrapper, as the export imports it: `@origami-wrappers/<app>/<folder>`, the folder its name lowercased (wrapperImport, origami-transforms). */
|
|
5
|
+
export const WRAPPER_IMPORT = new RegExp(`^${WRAPPERS_SCOPE}/([^/]+)/[^/]+$`);
|
|
6
|
+
/** The companion app: the site code's registrations are `companionApp.<name>` (origami-transforms wrapperSideEffects.ts COMPANION_APP). */
|
|
7
|
+
export const COMPANION_APP = 'companionApp';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { createRulesApi } from './rules-api.ts';
|
|
2
|
+
export { createCssFileReporter, describeAtRule, reportCssProblem } from './report.ts';
|
|
3
|
+
export { isElementDeclaration, readOnce } from './utils.ts';
|
|
4
|
+
export type { CatalogEntry, CatalogKind, CatalogProvider, CompanionKinds, ComponentCatalog, Problem, Report, ReportInCssFile, RulesApi, ValueOrReader } from './types.ts';
|
|
5
|
+
export { bare, getAttribute, getClassNameTerms, getComponentClass, getElementPropsEntries, getInnerElementStates, getExpression, getKey, getName, getObject, getArrayItems, getProperties, getCallbackKind, getAudioIdentifier, getDataValue, getDocumentIdentifier, getNonLiteral, getNonLiteralInElementProps, getNonLiteralInObject, getParamReadKind, getObjectValue, getProperty, getPropertyValues, getReservedNearMiss, isBound, isFallback, getStoredData, isPlaceholderOptions, isDataName, isExcludedDataKey, isImageCall, isMediaCall, isOneEditAway, isRecord, getLiteralString, isReservedAttribute, isStructure, findDeclaration, isReadByImport, ownerOf, } from '../shared/index.ts';
|
|
6
|
+
export { createVariableCheck, getRichTextStyleVariables, isRuntimeVariable, readDeclaredVariables, readRootVariables, unescapeHtml } from '../shared/index.ts';
|
|
7
|
+
export { getCssChildren, getDashedId, getLayoutLiteral, getMixinId, getSegmentClass, getSelectorSegments, hasComponentClass, hasScopeOwner, isCssIdentifier, isInPreamble, isInsideRule, isPresetProperty, isSafeCssIdentifier, mergeLayoutScopes, readAmpersands, readFontShorthand, readLayoutRuleBlocks, readLayoutVariable, readSegment, splitAtCombinators } from '../shared/index.ts';
|
|
8
|
+
export { AUDIO_PREFIX, BREAKPOINT_AT_RULES, BUILDERS, CALLBACK_PROP, CONTENT_TARGET, DATA_KEY, DOCUMENT_PREFIX, ELEMENT_PROPS, EXCLUDED_DATA_KEYS, EVENT_ATTRIBUTE, GLOBAL_SECTIONS, IMAGE_PREFIX, INSTANCE_PROPS, INTERACTIONS_PACKAGES, LAYER_ATTRIBUTES, NOT_A_VALUE, ORIGAMI_TARGETS, OVERFLOW_TARGET, PAGE_BACKGROUND_DEVICES, PREAMBLE_LAYER, QUOTED_STRING, RESERVED_ATTRIBUTES, RESERVED_DATA_ATTRIBUTES, RESERVED_ENTRY_KEYS, RESERVED_VARIABLE_NAMES, RUNTIME_ONLY_BUILDERS, RUNTIME_PACKAGE, RUNTIME_VARIABLE, SECTIONS, SHARED_COMP_ID, SPX_PROPS, SPX_RESOLVER_TYPES, STRUCTURE, SYSTEM_PACKAGE, TRANSFORM_BUILDERS, TYPED_BUILDERS, LANDMARKS, VISIBILITY_PREFIX, ANGLE_UNITS, FILTER_UNITS, LENGTH_UNITS, Z_INDEXES, WRAPPERS, } from '../shared/index.ts';
|
|
9
|
+
export type { Argument, CssFunction, ElementPropsEntry, PackageFile, Quantity, ReadPackageFile, StateStyleProperty, StateTransition, StyleRule, WrapperContract, ContractVar, CustomEnum, CustomPropertyType, CallExpression, CssNode, CustomMedia, ElementType, Expression, GetText, Import, ImportKind, JSXAttribute, JSXElement, LayoutRuleBlock, LogicalExpression, LayoutScope, Node, NonLiteral, ObjectExpression, PathStep, Property, ReadValue, RichTextStyleVariable, SelectorSegment, ThemeToken, } from '../shared/index.ts';
|
|
10
|
+
export { getCssFunctions, getQuantity, isFilter, isOpacity, isTransform, isTransformOrigin, isVisibility, isZIndex, restoreSpx } from '../shared/index.ts';
|
|
11
|
+
export { getStateOwner, getStateTransitions, isInteractionsConfig, readStateTransitions, COMPONENT_SELECTOR, DESCENDANT_SELECTOR, TRANSFORMATION_PROPERTIES } from '../shared/index.ts';
|
|
12
|
+
export type { ComponentFields, TransformationProperty } from '../shared/index.ts';
|
|
13
|
+
export { blockKey, COMBINATOR, createContractReader, getNestedElement, getNestedSelector, getWrittenPart, isBlockVar, splitCompound } from '../shared/index.ts';
|
|
14
|
+
export { readStyleRules } from '../shared/index.ts';
|
|
15
|
+
export { findDataLinks, getAnchorLink, getAnchorHref, readAnchorLinks, getRebuiltLinks, isRichTextObject, parseJson, getDataAttributes, getDataItemArguments, getEntryDataKeys, getJSXAttributes, LINK_KEYS, RICH_TEXT_TYPE, A_TAG, LINK_HTML_ATTRIBUTE, LINK_HTML_ENTITIES } from '../shared/index.ts';
|
|
16
|
+
export type { AnchorLink, DataLink, RebuiltLink, DataValuesReader } from '../shared/index.ts';
|
|
17
|
+
export { parseComponentSelector, unescapeName } from '../shared/index.ts';
|
|
18
|
+
export type { ImagePath } from '../shared/index.ts';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Part 3 — rules API: one linted file's page and the functions over it, and how a rule reports.
|
|
2
|
+
export { createRulesApi } from "./rules-api.js";
|
|
3
|
+
export { createCssFileReporter, describeAtRule, reportCssProblem } from "./report.js";
|
|
4
|
+
export { isElementDeclaration, readOnce } from "./utils.js";
|
|
5
|
+
export { bare, getAttribute, getClassNameTerms, getComponentClass, getElementPropsEntries, getInnerElementStates, getExpression, getKey, getName, getObject, getArrayItems, getProperties, getCallbackKind, getAudioIdentifier, getDataValue, getDocumentIdentifier, getNonLiteral, getNonLiteralInElementProps, getNonLiteralInObject, getParamReadKind, getObjectValue, getProperty, getPropertyValues, getReservedNearMiss, isBound, isFallback, getStoredData, isPlaceholderOptions, isDataName, isExcludedDataKey, isImageCall, isMediaCall, isOneEditAway, isRecord, getLiteralString, isReservedAttribute, isStructure, findDeclaration, isReadByImport, ownerOf, } from "../shared/index.js";
|
|
6
|
+
export { createVariableCheck, getRichTextStyleVariables, isRuntimeVariable, readDeclaredVariables, readRootVariables, unescapeHtml } from "../shared/index.js";
|
|
7
|
+
export { getCssChildren, getDashedId, getLayoutLiteral, getMixinId, getSegmentClass, getSelectorSegments, hasComponentClass, hasScopeOwner, isCssIdentifier, isInPreamble, isInsideRule, isPresetProperty, isSafeCssIdentifier, mergeLayoutScopes, readAmpersands, readFontShorthand, readLayoutRuleBlocks, readLayoutVariable, readSegment, splitAtCombinators } from "../shared/index.js";
|
|
8
|
+
export { AUDIO_PREFIX, BREAKPOINT_AT_RULES, BUILDERS, CALLBACK_PROP, CONTENT_TARGET, DATA_KEY, DOCUMENT_PREFIX, ELEMENT_PROPS, EXCLUDED_DATA_KEYS, EVENT_ATTRIBUTE, GLOBAL_SECTIONS, IMAGE_PREFIX, INSTANCE_PROPS, INTERACTIONS_PACKAGES, LAYER_ATTRIBUTES, NOT_A_VALUE, ORIGAMI_TARGETS, OVERFLOW_TARGET, PAGE_BACKGROUND_DEVICES, PREAMBLE_LAYER, QUOTED_STRING, RESERVED_ATTRIBUTES, RESERVED_DATA_ATTRIBUTES, RESERVED_ENTRY_KEYS, RESERVED_VARIABLE_NAMES, RUNTIME_ONLY_BUILDERS, RUNTIME_PACKAGE, RUNTIME_VARIABLE, SECTIONS, SHARED_COMP_ID, SPX_PROPS, SPX_RESOLVER_TYPES, STRUCTURE, SYSTEM_PACKAGE, TRANSFORM_BUILDERS, TYPED_BUILDERS, LANDMARKS, VISIBILITY_PREFIX, ANGLE_UNITS, FILTER_UNITS, LENGTH_UNITS, Z_INDEXES, WRAPPERS, } from "../shared/index.js";
|
|
9
|
+
export { getCssFunctions, getQuantity, isFilter, isOpacity, isTransform, isTransformOrigin, isVisibility, isZIndex, restoreSpx } from "../shared/index.js";
|
|
10
|
+
export { getStateOwner, getStateTransitions, isInteractionsConfig, readStateTransitions, COMPONENT_SELECTOR, DESCENDANT_SELECTOR, TRANSFORMATION_PROPERTIES } from "../shared/index.js";
|
|
11
|
+
export { blockKey, COMBINATOR, createContractReader, getNestedElement, getNestedSelector, getWrittenPart, isBlockVar, splitCompound } from "../shared/index.js";
|
|
12
|
+
export { readStyleRules } from "../shared/index.js";
|
|
13
|
+
export { findDataLinks, getAnchorLink, getAnchorHref, readAnchorLinks, getRebuiltLinks, isRichTextObject, parseJson, getDataAttributes, getDataItemArguments, getEntryDataKeys, getJSXAttributes, LINK_KEYS, RICH_TEXT_TYPE, A_TAG, LINK_HTML_ATTRIBUTE, LINK_HTML_ENTITIES } from "../shared/index.js";
|
|
14
|
+
export { parseComponentSelector, unescapeName } from "../shared/index.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AtRule } from 'postcss';
|
|
2
|
+
import type { Report, ReportInCssFile } from './types.ts';
|
|
3
|
+
/** Reports a problem on a line of a CSS file: at the page's start (CSS isn't a file the lint tool lints), the message led by `file:line: `. */
|
|
4
|
+
export declare function reportCssProblem<Check extends string>(report: Report<Check>, file: string, line: number, check: NoInfer<Check>, message: string): void;
|
|
5
|
+
/** A reporter for one CSS file: each problem at the page's start, led by `file:line: ` with the node's line (reportCssProblem). */
|
|
6
|
+
export declare function createCssFileReporter<Check extends string>(file: string, report: Report<Check>): ReportInCssFile<Check>;
|
|
7
|
+
/** An at-rule as a message writes it: '@media (max-width: 1px)', or '@media' with no params. */
|
|
8
|
+
export declare function describeAtRule({ name, params }: Pick<AtRule, 'name' | 'params'>): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FILE_START } from "../page-model/index.js";
|
|
2
|
+
/** Reports a problem on a line of a CSS file: at the page's start (CSS isn't a file the lint tool lints), the message led by `file:line: `. */
|
|
3
|
+
export function reportCssProblem(report, file, line, check, message) {
|
|
4
|
+
report({ check, loc: FILE_START, message: `${file}:${line}: ${message}` });
|
|
5
|
+
}
|
|
6
|
+
/** A reporter for one CSS file: each problem at the page's start, led by `file:line: ` with the node's line (reportCssProblem). */
|
|
7
|
+
export function createCssFileReporter(file, report) {
|
|
8
|
+
return (node, check, message) => reportCssProblem(report, file, node.source?.start?.line ?? 1, check, message);
|
|
9
|
+
}
|
|
10
|
+
/** An at-rule as a message writes it: '@media (max-width: 1px)', or '@media' with no params. */
|
|
11
|
+
export function describeAtRule({ name, params }) {
|
|
12
|
+
return params.trim() ? `@${name} ${params.trim()}` : `@${name}`;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CompanionKinds, ComponentCatalog, RulesApi, ValueOrReader } from './types.ts';
|
|
2
|
+
import type { PageModel } from '../page-model/index.ts';
|
|
3
|
+
import { type FontCatalog, type ReadFile, type ReadPackageFile, type WrapperContract } from '../shared/index.ts';
|
|
4
|
+
/** The rules API over a page already built. catalog: the site's component catalog, parsed, when the site has one; or what reads it, when a
|
|
5
|
+
* rule first asks about a tag from an app's wrapper (a broken catalog throws only then).
|
|
6
|
+
* `readContract`: a wrapper's or system component's contract (createContractReader's, from the page), read when a rule first asks about a tag from it. Default: none.
|
|
7
|
+
* `companions`: the kinds of the site code's companion registrations, by module name; or what reads them, when a rule first asks about a
|
|
8
|
+
* tag from the site code. Default: none.
|
|
9
|
+
* `readFile`: the site's files by path from the root, for the rules that ask whether a file exists (an image next to the page), and the page's
|
|
10
|
+
* servicesConfigs/interactions.ts (getStateTransitions). Default: no file.
|
|
11
|
+
* `readPackageFile`: the caller's package reader, used to check installation through package manifests. Default: no package resolves.
|
|
12
|
+
* `fonts`: the Wix font catalog. Default: the copy in this package (font-weights.ts). */
|
|
13
|
+
export declare function createRulesApi(page: PageModel, catalog?: ValueOrReader<ComponentCatalog | undefined>, readFile?: ReadFile, fonts?: FontCatalog, readContract?: (source: string) => WrapperContract | null, companions?: ValueOrReader<CompanionKinds>, readPackageFile?: ReadPackageFile): RulesApi;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// The rules API of one linted file: its page, and the functions over it that the lint tool can't provide (mostly CSS),
|
|
2
|
+
// and reading the file's own code that more than one rule needs (what type a tag is, its name, its id, its children, the elements in its attributes, where a name is imported from, the name an import is exported under, what is TypeScript, the props an arrow destructures).
|
|
3
|
+
// One per file, shared by every rule on it. Nothing here reads a disk: the caller builds the page (buildPageModel) and hands in the catalog
|
|
4
|
+
// and the companions, or what reads them: each read when a rule first asks about a tag from an app's wrapper, or from the site code.
|
|
5
|
+
import { getCatalogEntry, getContextProviders } from "./component-catalog.js";
|
|
6
|
+
import { CASCADE_ORDER, COMPANION_APP } from "./constants.js";
|
|
7
|
+
import { getEnclosingAtRules, getPageDeclaredVariables, isBaseDeclaration, readOnce } from "./utils.js";
|
|
8
|
+
import { BUILDERS, CONTENT_TARGET, INTERACTIONS_CONFIG, LAYER_ATTRIBUTES, SYSTEM_PACKAGE, WRAPPERS, getStateTransitions, posixPath, readBreakpointName, readCustomMedia, readStyleRules, readThemeFontTokens, readThemeTokens, createVariableCheck, FONT_WEIGHTS, readImagePaths, isOutsideWixMedia, getAttributeElements as getHeldElements, getAttributeValue, getChildren, getGlobalSectionModule, getId, getImport, getImportKind, getImportedName, getPropNames, getTagImport, getTagName, getType, hasDataAttributes, isTypeScript } from "../shared/index.js";
|
|
9
|
+
/** The rules API over a page already built. catalog: the site's component catalog, parsed, when the site has one; or what reads it, when a
|
|
10
|
+
* rule first asks about a tag from an app's wrapper (a broken catalog throws only then).
|
|
11
|
+
* `readContract`: a wrapper's or system component's contract (createContractReader's, from the page), read when a rule first asks about a tag from it. Default: none.
|
|
12
|
+
* `companions`: the kinds of the site code's companion registrations, by module name; or what reads them, when a rule first asks about a
|
|
13
|
+
* tag from the site code. Default: none.
|
|
14
|
+
* `readFile`: the site's files by path from the root, for the rules that ask whether a file exists (an image next to the page), and the page's
|
|
15
|
+
* servicesConfigs/interactions.ts (getStateTransitions). Default: no file.
|
|
16
|
+
* `readPackageFile`: the caller's package reader, used to check installation through package manifests. Default: no package resolves.
|
|
17
|
+
* `fonts`: the Wix font catalog. Default: the copy in this package (font-weights.ts). */
|
|
18
|
+
export function createRulesApi(page, catalog, readFile = () => undefined, fonts = FONT_WEIGHTS, readContract = () => null, companions = new Map(), readPackageFile = () => null) {
|
|
19
|
+
const readCatalog = readOnce(catalog);
|
|
20
|
+
const readCompanions = readOnce(companions);
|
|
21
|
+
const componentsBySourceStart = new Map(Object.values(page.components).map((component) => [component.sourceStart, component]));
|
|
22
|
+
const installedPackages = new Map();
|
|
23
|
+
const imagePathsBySource = new Map();
|
|
24
|
+
const getImagePaths = (node) => {
|
|
25
|
+
const found = getTagImport(node, getProgram(node));
|
|
26
|
+
if (found?.kind !== 'wrapper')
|
|
27
|
+
return [];
|
|
28
|
+
if (!imagePathsBySource.has(found.source)) {
|
|
29
|
+
const definition = readPackageFile(`${found.source}/definition.ts`, page.jsxFile);
|
|
30
|
+
imagePathsBySource.set(found.source, definition ? readImagePaths(definition.text) : []);
|
|
31
|
+
}
|
|
32
|
+
return imagePathsBySource.get(found.source);
|
|
33
|
+
};
|
|
34
|
+
const isPackageInstalled = (name) => {
|
|
35
|
+
if (!installedPackages.has(name))
|
|
36
|
+
installedPackages.set(name, readPackageFile(`${name}/package.json`, page.jsxFile) !== null);
|
|
37
|
+
return installedPackages.get(name);
|
|
38
|
+
};
|
|
39
|
+
const getParent = (component) => (component.parentKey ? (page.components[component.parentKey] ?? null) : null);
|
|
40
|
+
const getCss = (component, property) => CASCADE_ORDER.flatMap((kind) => component.css[kind][property] ?? []);
|
|
41
|
+
const getComponentCatalogEntry = (element) => {
|
|
42
|
+
const found = getTagImport(element, getProgram(element));
|
|
43
|
+
if (found?.kind === 'wrapper')
|
|
44
|
+
return getCatalogEntry(readCatalog(), found.source, found.imported);
|
|
45
|
+
if (found?.kind !== 'siteCode')
|
|
46
|
+
return null;
|
|
47
|
+
// the site code's module, by its name (`@site/site-code/myData`), as import-site reads it back whatever the specifier
|
|
48
|
+
const name = found.source.slice(found.source.lastIndexOf('/') + 1);
|
|
49
|
+
const kind = readCompanions().get(name);
|
|
50
|
+
return kind ? { app: COMPANION_APP, name, kind } : null;
|
|
51
|
+
};
|
|
52
|
+
const getComponentContract = (element) => {
|
|
53
|
+
const found = getTagImport(element, getProgram(element));
|
|
54
|
+
return found?.kind === 'wrapper' || found?.source.startsWith(`${SYSTEM_PACKAGE}/`) ? readContract(found.source) : null;
|
|
55
|
+
};
|
|
56
|
+
const getElementType = (element) => getType(element, getProgram(element)) ?? (getComponentCatalogEntry(element)?.kind === 'contextProvider' ? 'provider' : null);
|
|
57
|
+
const isWrapper = (element) => {
|
|
58
|
+
const type = getElementType(element);
|
|
59
|
+
return type !== null && WRAPPERS.includes(type);
|
|
60
|
+
};
|
|
61
|
+
const getChildElements = (node) => getChildren(node).flatMap((child) => {
|
|
62
|
+
if (child.type !== 'JSXElement')
|
|
63
|
+
return [];
|
|
64
|
+
return isWrapper(child) ? getChildElements(child) : [child];
|
|
65
|
+
});
|
|
66
|
+
const getAttributeElements = (node) => getHeldElements(node).flatMap((held) => (isWrapper(held.element) ? getChildElements(held.element).map((inner) => ({ ...held, element: inner })) : [held]));
|
|
67
|
+
// the page's defined variables, read once, on first use
|
|
68
|
+
const isVariableDefined = readOnce(() => createVariableCheck(page.css.files.theme, getPageDeclaredVariables(page.css)));
|
|
69
|
+
// the page's servicesConfigs/interactions.ts, read once, on first use
|
|
70
|
+
let stateTransitions;
|
|
71
|
+
// style.css walked once, on first use
|
|
72
|
+
let styleRules;
|
|
73
|
+
const getStyleRules = (className) => (styleRules ??= readStyleRules(page.css.files.style)).get(className) ?? [];
|
|
74
|
+
const getLayoutCss = (component, property, media) => {
|
|
75
|
+
const lines = (component.css.layout[property] ?? []).filter((line) => line.selector === '&' || line.selector === `& @origami-target ${CONTENT_TARGET}`);
|
|
76
|
+
return lines.filter((line) => line.media === media).at(-1) ?? (media === null ? undefined : lines.filter((line) => line.media === null).at(-1));
|
|
77
|
+
};
|
|
78
|
+
return {
|
|
79
|
+
page,
|
|
80
|
+
// A JSX element starts where its component starts.
|
|
81
|
+
getComponent: (node) => componentsBySourceStart.get(node.range[0]) ?? null,
|
|
82
|
+
getParent,
|
|
83
|
+
getRoot: () => Object.values(page.components).find((component) => !getParent(component)) ?? null,
|
|
84
|
+
getCss,
|
|
85
|
+
getBaseCss: (component, property) => getCss(component, property).filter(isBaseDeclaration).at(-1),
|
|
86
|
+
getLayoutCss,
|
|
87
|
+
getThemeTokens: () => readThemeTokens(page.css.files.theme),
|
|
88
|
+
getThemeFontTokens: () => readThemeFontTokens(page.css.files.theme),
|
|
89
|
+
isVariableDefined: (name) => isVariableDefined()(name),
|
|
90
|
+
getStateTransitions: () => (stateTransitions ??= getStateTransitions(readFile(`${posixPath.dirname(page.jsxFile)}/${INTERACTIONS_CONFIG}`))),
|
|
91
|
+
// Own keys only: a family `constructor` is no font.
|
|
92
|
+
getFontWeights: (family) => (Object.hasOwn(fonts, family) ? fonts[family] : null),
|
|
93
|
+
getCustomMedia: (kind) => readCustomMedia(page.css.files[kind]),
|
|
94
|
+
getBreakpointName: readBreakpointName,
|
|
95
|
+
getStyleRules,
|
|
96
|
+
getEnclosingAtRules,
|
|
97
|
+
getType: getElementType,
|
|
98
|
+
getGlobalSectionModule: (node) => getGlobalSectionModule(node, getProgram(node)),
|
|
99
|
+
isWrapper,
|
|
100
|
+
getComponentCatalogEntry,
|
|
101
|
+
getComponentContract,
|
|
102
|
+
isPackageInstalled,
|
|
103
|
+
getImagePaths,
|
|
104
|
+
isOutsideWixMedia: uri => isOutsideWixMedia(uri, page.jsxFile, readFile),
|
|
105
|
+
getContextProviders: (app) => getContextProviders(readCatalog(), app),
|
|
106
|
+
getTagName,
|
|
107
|
+
hasFile: (file) => readFile(file) !== undefined,
|
|
108
|
+
getId,
|
|
109
|
+
getChildren,
|
|
110
|
+
getChildElements,
|
|
111
|
+
getAttributeElements,
|
|
112
|
+
getItemElements: (node) => [...getChildElements(node), ...getAttributeElements(node).filter(({ name }) => !LAYER_ATTRIBUTES.includes(name)).map(({ element }) => element)],
|
|
113
|
+
getAttributeValue,
|
|
114
|
+
getImport: (node) => (node.type === 'JSXElement' ? getTagImport(node, getProgram(node)) : getImport(node.name, getProgram(node))),
|
|
115
|
+
hasDataAttributes: (node) => hasDataAttributes(node, getProgram(node)),
|
|
116
|
+
getBuilder,
|
|
117
|
+
getImportKind,
|
|
118
|
+
getImportedName,
|
|
119
|
+
isTypeScript,
|
|
120
|
+
getPropNames,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/** The runtime builder a call is, by its import (`fn(…)` → 'fn'); null for any other node. */
|
|
124
|
+
function getBuilder(node) {
|
|
125
|
+
if (node.type !== 'CallExpression')
|
|
126
|
+
return null;
|
|
127
|
+
const { callee } = node;
|
|
128
|
+
if (callee.type !== 'Identifier')
|
|
129
|
+
return null;
|
|
130
|
+
const found = getImport(callee.name, getProgram(callee));
|
|
131
|
+
return found?.kind === 'runtime' && BUILDERS.includes(found.imported) ? found.imported : null;
|
|
132
|
+
}
|
|
133
|
+
/** The file a node is in: the top of its parents. */
|
|
134
|
+
function getProgram(node) {
|
|
135
|
+
let top = node.parent;
|
|
136
|
+
while (top.type !== 'Program')
|
|
137
|
+
top = top.parent;
|
|
138
|
+
return top;
|
|
139
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { AtRule, ChildNode } from 'postcss';
|
|
2
|
+
import type { Component, CssDeclaration, PageModel } from '../page-model/index.ts';
|
|
3
|
+
import type { CallbackNode } from '../rules-adapter/index.ts';
|
|
4
|
+
import type { AttributeElement, CustomMedia, ElementType, GlobalSectionModule, ImagePath, Import, ImportKind, JSXElement, Loc, StateTransition, StyleRule, ThemeToken, TypedNode, WrapperContract } from '../shared/index.ts';
|
|
5
|
+
export interface RulesApi {
|
|
6
|
+
readonly page: PageModel;
|
|
7
|
+
/** The component this JSX element is; null for JSX outside Structure. */
|
|
8
|
+
getComponent(node: JSXElement): Component | null;
|
|
9
|
+
getParent(component: Component): Component | null;
|
|
10
|
+
/** The page's root: the first element Structure returns (the first component without a parent). null when it returns none. */
|
|
11
|
+
getRoot(): Component | null;
|
|
12
|
+
/** Every line for this property: layout.css, then the theme's, then style.css. */
|
|
13
|
+
getCss(component: Component, property: string): CssDeclaration[];
|
|
14
|
+
/** The last line on the component itself (`&`), outside @media and @origami-target. */
|
|
15
|
+
getBaseCss(component: Component, property: string): CssDeclaration | undefined;
|
|
16
|
+
/** The layout.css line of a property that applies to the component at a breakpoint (null: by default), as the import merges the element's scope:
|
|
17
|
+
* the last line at that `@media` on the element itself or in its content block (`@origami-target internal-container-content-wrapper`, where the import
|
|
18
|
+
* reads `display` and the container properties), else the default's; undefined without one. */
|
|
19
|
+
getLayoutCss(component: Component, property: string, media: string | null): CssDeclaration | undefined;
|
|
20
|
+
/** theme.css's custom properties (`--wst-heading-1-font: …`), as written, with their lines, in order; none without a theme.css. */
|
|
21
|
+
getThemeTokens(): ThemeToken[];
|
|
22
|
+
/** theme.css's font tokens (`--wst-…-font`), as getThemeTokens gives them. */
|
|
23
|
+
getThemeFontTokens(): ThemeToken[];
|
|
24
|
+
/** Whether a custom property (`--brand`) is defined for the page: a variable of theme.css's `:root`, a runtime name, or one the page's layout.css, style.css or an applied mixin declares; always, with no theme.css (createVariableCheck). */
|
|
25
|
+
isVariableDefined(name: string): boolean;
|
|
26
|
+
/** The state transitions of the page's servicesConfigs/interactions.ts, each with the components it styles by their `key`
|
|
27
|
+
* (readStateTransitions); none when the page has no such file, or it doesn't parse. */
|
|
28
|
+
getStateTransitions(): StateTransition[];
|
|
29
|
+
/** A Wix font id's weights in the font catalog, legacy fonts too; null for an id the catalog doesn't have (another case, a quoted name, a list). */
|
|
30
|
+
getFontWeights(family: string): readonly number[] | null;
|
|
31
|
+
/** A CSS file's `@custom-media` declarations at its top level, as the import reads them; `getCustomMedia('theme')` is the site's breakpoints. None for a file the site doesn't have. */
|
|
32
|
+
getCustomMedia(kind: keyof PageModel['css']['files']): CustomMedia[];
|
|
33
|
+
/** The breakpoint name a `@media` query uses: '(--tablet)' → '--tablet'; null for a range like '(max-width: 1023px)'. */
|
|
34
|
+
getBreakpointName(query: string): string | null;
|
|
35
|
+
/** The at-rules around a node of a parsed CSS file (`page.css.files`), outer to inner; [] at the top level. */
|
|
36
|
+
/** style.css's rules whose selector starts with `.<className>`, as `readStyleRules` reads them: each once, an empty or `@apply`-only one too. */
|
|
37
|
+
getStyleRules(className: string): StyleRule[];
|
|
38
|
+
getEnclosingAtRules(node: ChildNode): AtRule[];
|
|
39
|
+
/** What the tag is, by its import: 'section', 'globalHeader'…; 'provider' for a context provider, by the site's component catalog or the site code's registrations. null for anything else. */
|
|
40
|
+
getType(node: JSXElement): ElementType | null;
|
|
41
|
+
/** 'Header' / 'Footer' for a page's reference to the global header / footer (`<Header_mb7ogqqn>`, imported from its global/components folder), the one a <Page> takes in its header / footer attribute; null for anything else, a `HeaderSection_<id>` reference too. */
|
|
42
|
+
getGlobalSectionModule(node: JSXElement): GlobalSectionModule | null;
|
|
43
|
+
/** <Remove>, <Interaction>, <PinnedToScreen> (by its import), a context provider (by the catalog, or the site code's registrations): a tag that wraps one component and isn't one. */
|
|
44
|
+
isWrapper(node: JSXElement): boolean;
|
|
45
|
+
/** The tag's entry in the site's component catalog (site-component-catalog.json), by its app (`@origami-wrappers/<app>/…`) and the name it's
|
|
46
|
+
* imported by: its kind ('component', 'contextProvider', 'functionLibrary') and the fields the catalog keeps for it; for the site's code
|
|
47
|
+
* (`@site/site-code/<name>`), the kind of the companion app's registration by that name, which the next export lists. null for a tag neither has. */
|
|
48
|
+
getComponentCatalogEntry(node: JSXElement): CatalogEntry | null;
|
|
49
|
+
/** What the tag's wrapper allows, from its installed package (`@origami-wrappers/<app>/<name>`): its component-contract.json, or an older
|
|
50
|
+
* wrapper's defaults.css: each element's selector, its properties, its states, and the nested components. A system component's
|
|
51
|
+
* (`@wix/origami-system-components/InternalContainer`) is its package's component-contract.json, when its version has one. null for any
|
|
52
|
+
* other tag, or one without a contract. */
|
|
53
|
+
getComponentContract(node: JSXElement): WrapperContract | null;
|
|
54
|
+
/** Whether the caller resolves this package's package.json from the page; false without a package reader. Cached per page. */
|
|
55
|
+
isPackageInstalled(name: string): boolean;
|
|
56
|
+
/** Image locations in the wrapper's definition.ts; none without an installed definition. */
|
|
57
|
+
getImagePaths(node: JSXElement): readonly ImagePath[];
|
|
58
|
+
/** Whether this media value is a remote URL or a file beside the page or in the site's public folder. */
|
|
59
|
+
isOutsideWixMedia(uri: string): boolean;
|
|
60
|
+
/** The app's catalog providers, each with its hook and wrapper import path; null when the app has none. */
|
|
61
|
+
getContextProviders(app: string): CatalogProvider[] | null;
|
|
62
|
+
/** 'Section', 'Band.Item', 'svg:rect'. */
|
|
63
|
+
getTagName(node: JSXElement): string;
|
|
64
|
+
/** Whether the site has this file, by its path from the site root (`packages/site-app/public/a.png`). */
|
|
65
|
+
hasFile(file: string): boolean;
|
|
66
|
+
/** Its literal id, id="a" or id={'a'}; null without one, or for id={variable}. */
|
|
67
|
+
getId(node: JSXElement): string | null;
|
|
68
|
+
/** Elements, text and {expressions}, in order; whitespace and JSX comments skipped. */
|
|
69
|
+
getChildren(node: JSXElement): JSXElement['children'];
|
|
70
|
+
/** The element children, with each wrapper (<Remove>, <Interaction>, by its import) replaced by the elements it holds. */
|
|
71
|
+
getChildElements(node: JSXElement): JSXElement[];
|
|
72
|
+
/** The elements it holds in its attributes (`content={<X />}`, inside an attribute's object or array), each with its attribute, its name and its path (the name, then a step per object key, with an array item's position on the key that holds the array; null when the way has no such spelling); a wrapper is replaced by the element it holds, at the wrapper's path. Layers included. */
|
|
73
|
+
getAttributeElements(node: JSXElement): Array<AttributeElement<JSXElement>>;
|
|
74
|
+
/** The elements this one lays out, as the import reads structure.jsx: its child elements, then the elements in its attributes, through wrappers; not its layers (a layer lays out its own). */
|
|
75
|
+
getItemElements(node: JSXElement): JSXElement[];
|
|
76
|
+
/** An attribute's value as plain data (literals, objects, arrays); undefined when it has none, or the value is an element, a variable or a call (inside an object or array such a value stays as undefined in its place; a computed key and a spread are left out). */
|
|
77
|
+
getAttributeValue(node: JSXElement, name: string): unknown;
|
|
78
|
+
/** Are its attributes saved as its component's data (`<Image src="a.png">`)? Not on `Page`, the sections or a global component's reference. */
|
|
79
|
+
hasDataAttributes(node: JSXElement): boolean;
|
|
80
|
+
/** The import of a tag (of `Band` for <Band.Item>) or of a name in the code; null when nothing imports it. */
|
|
81
|
+
getImport(node: JSXElement | CallbackNode<'Identifier'>): Import | null;
|
|
82
|
+
/** The runtime builder a call is, by its import (`fn(…)` → 'fn'); null for any other node, and for a call of a name that isn't the runtime's. */
|
|
83
|
+
getBuilder(node: TypedNode): string | null;
|
|
84
|
+
/** What an import's source is (`'interactReact'` for '@wix/interact/react', `'menu'` for global/menus/…); null for any other source. */
|
|
85
|
+
getImportKind(source: string): ImportKind | null;
|
|
86
|
+
/** The name an import specifier is exported under: 'default', '*', or the named export (`import { Remove as Hide }` → 'Remove'). */
|
|
87
|
+
getImportedName(specifier: CallbackNode<'ImportDeclaration'>['specifiers'][number]): string;
|
|
88
|
+
/** A TypeScript node, or an `import type` / `export type` / `{ type Y }`. null and undefined: false. */
|
|
89
|
+
isTypeScript(node: TypedNode | null | undefined): boolean;
|
|
90
|
+
/** The names an arrow destructures from its one parameter: `({ id, className })` → ['id', 'className']; a default, a new name or `...rest` is null. `()` and `({})` → []; other parameters → null. */
|
|
91
|
+
getPropNames(fn: CallbackNode<'ArrowFunctionExpression'>): Array<string | null> | null;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* loc: a node's `loc`, a component's `loc` (its id attribute, or its tag name), FILE_START for the page as a whole.
|
|
95
|
+
* It can only point into the linted file (structure.jsx): a CSS problem is marked on its component, and the message names the CSS.
|
|
96
|
+
*/
|
|
97
|
+
export interface Problem<Check extends string> {
|
|
98
|
+
check: Check;
|
|
99
|
+
loc: Loc;
|
|
100
|
+
message: string;
|
|
101
|
+
}
|
|
102
|
+
export type Report<Check extends string> = (problem: Problem<Check>) => void;
|
|
103
|
+
/** Reports a problem on a node of one CSS file, with the file and the node's line. */
|
|
104
|
+
export type ReportInCssFile<Check extends string> = (node: ChildNode, check: Check, message: string) => void;
|
|
105
|
+
/** The catalog: the site's apps, by the app name a structure file imports from (`WixCMS`). */
|
|
106
|
+
export type ComponentCatalog = Record<string, CatalogApp>;
|
|
107
|
+
/** One app: its entries by kind, each by the name a structure file imports it by (`CmsTemplateProvider$AIFeaturelist`). */
|
|
108
|
+
interface CatalogApp {
|
|
109
|
+
appDefId: string;
|
|
110
|
+
entries: {
|
|
111
|
+
components: Record<string, CatalogItem>;
|
|
112
|
+
contextProviders: Record<string, CatalogItem>;
|
|
113
|
+
functionLibraries?: Record<string, CatalogItem>;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/** What the catalog keeps about one entry. */
|
|
117
|
+
interface CatalogItem {
|
|
118
|
+
displayName?: string;
|
|
119
|
+
description?: string;
|
|
120
|
+
/** A context provider's hook: `useCmsTemplate`. */
|
|
121
|
+
hook?: string;
|
|
122
|
+
}
|
|
123
|
+
/** A context provider of an app, as the catalog lists it: its name, its hook, and the wrapper path the export imports both from. */
|
|
124
|
+
export interface CatalogProvider {
|
|
125
|
+
name: string;
|
|
126
|
+
hook?: string;
|
|
127
|
+
source: string;
|
|
128
|
+
}
|
|
129
|
+
/** What a catalog entry is: the group the catalog lists it in. */
|
|
130
|
+
export type CatalogKind = 'component' | 'contextProvider' | 'functionLibrary';
|
|
131
|
+
/** A tag's entry in the catalog: its app, the name it's imported by, and its kind. */
|
|
132
|
+
export interface CatalogEntry {
|
|
133
|
+
app: string;
|
|
134
|
+
name: string;
|
|
135
|
+
kind: CatalogKind;
|
|
136
|
+
}
|
|
137
|
+
/** Each companion module's kind, by the name a page imports it from: `@site/site-code/myData` → 'contextProvider'. */
|
|
138
|
+
export type CompanionKinds = ReadonlyMap<string, CatalogKind>;
|
|
139
|
+
/** What the site gives the rules API: the value itself, or what reads it when a rule first asks (readOnce). */
|
|
140
|
+
export type ValueOrReader<T> = T | (() => T);
|
|
141
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AtRule, ChildNode } from 'postcss';
|
|
2
|
+
import type { CssDeclaration, PageModel } from '../page-model/index.ts';
|
|
3
|
+
import type { ValueOrReader } from './types.ts';
|
|
4
|
+
/** On the component itself, outside any @media and @origami-target: applies by default. */
|
|
5
|
+
export declare const isBaseDeclaration: (decl: CssDeclaration) => boolean;
|
|
6
|
+
/** On the component itself (`&`) or in one of its `@origami-target` blocks, at any breakpoint: the lines the import merges into the element's layout scope; not a state's or an inner part's. */
|
|
7
|
+
export declare const isElementDeclaration: (decl: CssDeclaration) => boolean;
|
|
8
|
+
/** The at-rules around a CSS node, outer to inner (`@media`, `@scope`, `@layer`, `@mixin`…); [] at the file's top level. */
|
|
9
|
+
export declare function getEnclosingAtRules(node: ChildNode): AtRule[];
|
|
10
|
+
/** A value given as it is, or by what reads it: read on the first call, then kept. A read that throws throws again on the next call, as
|
|
11
|
+
* origami-lint master's read of a broken catalog did. */
|
|
12
|
+
export declare function readOnce<T>(given: ValueOrReader<T>): () => T;
|
|
13
|
+
/** The names the page's own CSS declares (layout.css, style.css) and the ones a mixin it applies puts in (the page model's 'theme' CSS). */
|
|
14
|
+
export declare function getPageDeclaredVariables({ files, byClassName, unconnectedCss, globalCss }: PageModel['css']): string[];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { readDeclaredVariables } from "../shared/index.js";
|
|
2
|
+
/** On the component itself, outside any @media and @origami-target: applies by default. */
|
|
3
|
+
export const isBaseDeclaration = (decl) => !decl.media && decl.selector === '&';
|
|
4
|
+
/** On the component itself (`&`) or in one of its `@origami-target` blocks, at any breakpoint: the lines the import merges into the element's layout scope; not a state's or an inner part's. */
|
|
5
|
+
export const isElementDeclaration = (decl) => decl.selector === '&' || decl.selector.startsWith('& @origami-target ');
|
|
6
|
+
/** The at-rules around a CSS node, outer to inner (`@media`, `@scope`, `@layer`, `@mixin`…); [] at the file's top level. */
|
|
7
|
+
export function getEnclosingAtRules(node) {
|
|
8
|
+
const atRules = [];
|
|
9
|
+
for (let parent = node.parent; parent && parent.type !== 'root'; parent = parent.parent) {
|
|
10
|
+
if (parent.type === 'atrule')
|
|
11
|
+
atRules.unshift(parent);
|
|
12
|
+
}
|
|
13
|
+
return atRules;
|
|
14
|
+
}
|
|
15
|
+
/** A value given as it is, or by what reads it: read on the first call, then kept. A read that throws throws again on the next call, as
|
|
16
|
+
* origami-lint master's read of a broken catalog did. */
|
|
17
|
+
export function readOnce(given) {
|
|
18
|
+
if (typeof given !== 'function')
|
|
19
|
+
return () => given;
|
|
20
|
+
let read;
|
|
21
|
+
return () => (read ??= { value: given() }).value;
|
|
22
|
+
}
|
|
23
|
+
/** The names the page's own CSS declares (layout.css, style.css) and the ones a mixin it applies puts in (the page model's 'theme' CSS). */
|
|
24
|
+
export function getPageDeclaredVariables({ files, byClassName, unconnectedCss, globalCss }) {
|
|
25
|
+
const applied = [...Object.values(byClassName), ...Object.values(unconnectedCss), globalCss].flatMap((css) => Object.keys(css.theme).filter((prop) => prop.startsWith('--')));
|
|
26
|
+
return [...readDeclaredVariables(files.layout), ...readDeclaredVariables(files.style), ...applied];
|
|
27
|
+
}
|