@design.estate/wcctools 6.0.0 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +33 -0
- package/dist_shell/bundle.js +405 -368
- package/dist_shell/bundle.js.map +1 -1
- package/dist_shell/bundle.js.third-party-notices.json +52 -0
- package/dist_shell/bundle.js.third-party-notices.txt +107 -1
- package/dist_shell/index.html +1 -1
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/classes.bundlestatus.d.ts +36 -0
- package/dist_ts/classes.bundlestatus.js +110 -0
- package/dist_ts/classes.devapi.d.ts +3 -0
- package/dist_ts/classes.devapi.js +8 -1
- package/dist_ts/classes.devserver.d.ts +45 -10
- package/dist_ts/classes.devserver.js +123 -49
- package/dist_ts/cli.js +12 -3
- package/dist_ts/index.d.ts +0 -2
- package/dist_ts/index.js +1 -3
- package/dist_ts/plugins.d.ts +7 -2
- package/dist_ts/plugins.js +9 -3
- package/dist_ts/standards/baselines.d.ts +27 -0
- package/dist_ts/standards/baselines.js +83 -0
- package/dist_ts/standards/checker.d.ts +21 -0
- package/dist_ts/standards/checker.js +88 -0
- package/dist_ts/standards/classes.gitrepo.d.ts +13 -0
- package/dist_ts/standards/classes.gitrepo.js +43 -0
- package/dist_ts/standards/classes.sourceedits.d.ts +15 -0
- package/dist_ts/standards/classes.sourceedits.js +54 -0
- package/dist_ts/standards/classes.standardfixer.d.ts +40 -0
- package/dist_ts/standards/classes.standardfixer.js +210 -0
- package/dist_ts/standards/classes.standardproject.d.ts +80 -0
- package/dist_ts/standards/classes.standardproject.js +195 -0
- package/dist_ts/standards/classes.standardtree.d.ts +56 -0
- package/dist_ts/standards/classes.standardtree.js +207 -0
- package/dist_ts/standards/cli.d.ts +7 -0
- package/dist_ts/standards/cli.js +89 -0
- package/dist_ts/standards/config.d.ts +33 -0
- package/dist_ts/standards/config.js +139 -0
- package/dist_ts/standards/errors.d.ts +9 -0
- package/dist_ts/standards/errors.js +17 -0
- package/dist_ts/standards/helpers.ast.d.ts +56 -0
- package/dist_ts/standards/helpers.ast.js +172 -0
- package/dist_ts/standards/helpers.paths.d.ts +36 -0
- package/dist_ts/standards/helpers.paths.js +86 -0
- package/dist_ts/standards/index.d.ts +14 -0
- package/dist_ts/standards/index.js +15 -0
- package/dist_ts/standards/output.d.ts +7 -0
- package/dist_ts/standards/output.js +57 -0
- package/dist_ts/standards/ratchet.d.ts +15 -0
- package/dist_ts/standards/ratchet.js +45 -0
- package/dist_ts/standards/rule.d.ts +50 -0
- package/dist_ts/standards/rule.js +9 -0
- package/dist_ts/standards/rules/barrel.element-index.d.ts +7 -0
- package/dist_ts/standards/rules/barrel.element-index.js +108 -0
- package/dist_ts/standards/rules/barrel.no-demo-export.d.ts +3 -0
- package/dist_ts/standards/rules/barrel.no-demo-export.js +29 -0
- package/dist_ts/standards/rules/demo.fixture-not-exported.d.ts +3 -0
- package/dist_ts/standards/rules/demo.fixture-not-exported.js +29 -0
- package/dist_ts/standards/rules/demo.groups.d.ts +6 -0
- package/dist_ts/standards/rules/demo.groups.js +72 -0
- package/dist_ts/standards/rules/demo.required.d.ts +3 -0
- package/dist_ts/standards/rules/demo.required.js +48 -0
- package/dist_ts/standards/rules/demo.separate-file.d.ts +3 -0
- package/dist_ts/standards/rules/demo.separate-file.js +38 -0
- package/dist_ts/standards/rules/demo.shape.d.ts +3 -0
- package/dist_ts/standards/rules/demo.shape.js +38 -0
- package/dist_ts/standards/rules/docs.component-index.d.ts +8 -0
- package/dist_ts/standards/rules/docs.component-index.js +84 -0
- package/dist_ts/standards/rules/element.exported.d.ts +3 -0
- package/dist_ts/standards/rules/element.exported.js +33 -0
- package/dist_ts/standards/rules/element.literal-tag.d.ts +3 -0
- package/dist_ts/standards/rules/element.literal-tag.js +30 -0
- package/dist_ts/standards/rules/element.reachable.d.ts +3 -0
- package/dist_ts/standards/rules/element.reachable.js +48 -0
- package/dist_ts/standards/rules/element.tag-map.d.ts +3 -0
- package/dist_ts/standards/rules/element.tag-map.js +83 -0
- package/dist_ts/standards/rules/i18n.literals.d.ts +3 -0
- package/dist_ts/standards/rules/i18n.literals.js +52 -0
- package/dist_ts/standards/rules/index.d.ts +12 -0
- package/dist_ts/standards/rules/index.js +83 -0
- package/dist_ts/standards/rules/layout.element-folder.d.ts +3 -0
- package/dist_ts/standards/rules/layout.element-folder.js +47 -0
- package/dist_ts/standards/rules/layout.entry-file-name.d.ts +3 -0
- package/dist_ts/standards/rules/layout.entry-file-name.js +71 -0
- package/dist_ts/standards/rules/layout.entry.d.ts +3 -0
- package/dist_ts/standards/rules/layout.entry.js +38 -0
- package/dist_ts/standards/rules/layout.group-folder.d.ts +3 -0
- package/dist_ts/standards/rules/layout.group-folder.js +22 -0
- package/dist_ts/standards/rules/layout.shared-00.d.ts +3 -0
- package/dist_ts/standards/rules/layout.shared-00.js +36 -0
- package/dist_ts/standards/rules/naming.class-matches-tag.d.ts +3 -0
- package/dist_ts/standards/rules/naming.class-matches-tag.js +26 -0
- package/dist_ts/standards/rules/naming.lowercase-files.d.ts +3 -0
- package/dist_ts/standards/rules/naming.lowercase-files.js +26 -0
- package/dist_ts/standards/rules/naming.tag-prefix.d.ts +3 -0
- package/dist_ts/standards/rules/naming.tag-prefix.js +23 -0
- package/dist_ts/standards/rules/props.accessor.d.ts +3 -0
- package/dist_ts/standards/rules/props.accessor.js +35 -0
- package/dist_ts/standards/rules/props.object-no-attribute.d.ts +3 -0
- package/dist_ts/standards/rules/props.object-no-attribute.js +42 -0
- package/dist_ts/standards/rules/props.reflect-primitive.d.ts +5 -0
- package/dist_ts/standards/rules/props.reflect-primitive.js +41 -0
- package/dist_ts/standards/rules/props.typed.d.ts +6 -0
- package/dist_ts/standards/rules/props.typed.js +64 -0
- package/dist_ts/standards/rules/shared.d.ts +38 -0
- package/dist_ts/standards/rules/shared.js +103 -0
- package/dist_ts/standards/rules/style.bdtheme.d.ts +5 -0
- package/dist_ts/standards/rules/style.bdtheme.js +28 -0
- package/dist_ts_interfaces/index.d.ts +1 -0
- package/dist_ts_interfaces/index.js +2 -1
- package/dist_ts_interfaces/requests.d.ts +35 -0
- package/dist_ts_interfaces/standard.d.ts +93 -0
- package/dist_ts_interfaces/standard.js +6 -0
- package/dist_ts_shell/bundlestatus.d.ts +15 -0
- package/dist_ts_shell/bundlestatus.js +64 -0
- package/dist_ts_shell/elements/wcc-contextmenu.d.ts +3 -0
- package/dist_ts_shell/elements/wcc-contextmenu.js +18 -3
- package/dist_ts_shell/elements/wcc-preview-frame.d.ts +6 -0
- package/dist_ts_shell/elements/wcc-preview-frame.js +50 -2
- package/dist_ts_shell/elements/wcc-shell.d.ts +15 -0
- package/dist_ts_shell/elements/wcc-shell.js +45 -3
- package/dist_ts_shell/plugins.d.ts +2 -1
- package/dist_ts_shell/plugins.js +3 -2
- package/dist_ts_web/00_commitinfo_data.js +1 -1
- package/package.json +8 -3
- package/readme.md +40 -3
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/classes.bundlestatus.ts +123 -0
- package/ts/classes.devapi.ts +9 -0
- package/ts/classes.devserver.ts +127 -47
- package/ts/cli.ts +12 -2
- package/ts/index.ts +0 -2
- package/ts/plugins.ts +10 -2
- package/ts/standards/baselines.ts +100 -0
- package/ts/standards/checker.ts +114 -0
- package/ts/standards/classes.gitrepo.ts +48 -0
- package/ts/standards/classes.sourceedits.ts +58 -0
- package/ts/standards/classes.standardfixer.ts +234 -0
- package/ts/standards/classes.standardproject.ts +250 -0
- package/ts/standards/classes.standardtree.ts +220 -0
- package/ts/standards/cli.ts +86 -0
- package/ts/standards/config.ts +160 -0
- package/ts/standards/errors.ts +18 -0
- package/ts/standards/helpers.ast.ts +208 -0
- package/ts/standards/helpers.paths.ts +119 -0
- package/ts/standards/index.ts +22 -0
- package/ts/standards/output.ts +65 -0
- package/ts/standards/ratchet.ts +63 -0
- package/ts/standards/rule.ts +58 -0
- package/ts/standards/rules/barrel.element-index.ts +112 -0
- package/ts/standards/rules/barrel.no-demo-export.ts +30 -0
- package/ts/standards/rules/demo.fixture-not-exported.ts +30 -0
- package/ts/standards/rules/demo.groups.ts +74 -0
- package/ts/standards/rules/demo.required.ts +49 -0
- package/ts/standards/rules/demo.separate-file.ts +40 -0
- package/ts/standards/rules/demo.shape.ts +42 -0
- package/ts/standards/rules/docs.component-index.ts +88 -0
- package/ts/standards/rules/element.exported.ts +35 -0
- package/ts/standards/rules/element.literal-tag.ts +30 -0
- package/ts/standards/rules/element.reachable.ts +49 -0
- package/ts/standards/rules/element.tag-map.ts +87 -0
- package/ts/standards/rules/i18n.literals.ts +58 -0
- package/ts/standards/rules/index.ts +87 -0
- package/ts/standards/rules/layout.element-folder.ts +49 -0
- package/ts/standards/rules/layout.entry-file-name.ts +73 -0
- package/ts/standards/rules/layout.entry.ts +40 -0
- package/ts/standards/rules/layout.group-folder.ts +23 -0
- package/ts/standards/rules/layout.shared-00.ts +37 -0
- package/ts/standards/rules/naming.class-matches-tag.ts +27 -0
- package/ts/standards/rules/naming.lowercase-files.ts +27 -0
- package/ts/standards/rules/naming.tag-prefix.ts +24 -0
- package/ts/standards/rules/props.accessor.ts +37 -0
- package/ts/standards/rules/props.object-no-attribute.ts +45 -0
- package/ts/standards/rules/props.reflect-primitive.ts +44 -0
- package/ts/standards/rules/props.typed.ts +70 -0
- package/ts/standards/rules/shared.ts +127 -0
- package/ts/standards/rules/style.bdtheme.ts +31 -0
- package/ts_interfaces/bridge.ts +95 -0
- package/ts_interfaces/catalog.ts +37 -0
- package/ts_interfaces/index.ts +4 -0
- package/ts_interfaces/plugins.ts +3 -0
- package/ts_interfaces/requests.ts +65 -0
- package/ts_interfaces/standard.ts +103 -0
- package/ts_shared/index.ts +1 -0
- package/ts_shared/plugins.ts +3 -0
- package/ts_shared/previewroute.ts +58 -0
- package/ts_shell/bundlestatus.ts +68 -0
- package/ts_shell/elements/wcc-contextmenu.ts +306 -0
- package/ts_shell/elements/wcc-preview-frame.ts +167 -0
- package/ts_shell/elements/wcc-properties.ts +998 -0
- package/ts_shell/elements/wcc-record-button.ts +108 -0
- package/ts_shell/elements/wcc-recording-panel.ts +1005 -0
- package/ts_shell/elements/wcc-shell.ts +485 -0
- package/ts_shell/elements/wcc-sidebar.ts +1419 -0
- package/ts_shell/index.html +21 -0
- package/ts_shell/index.ts +4 -0
- package/ts_shell/plugins.ts +12 -0
- package/ts_shell/previewconnection.ts +103 -0
- package/ts_shell/services/recorder.service.ts +451 -0
- package/ts_shell/types/dom-mediacapture-stub/index.d.ts +12 -0
- package/ts_shell/types/dom-mediacapture-stub/package.json +6 -0
- package/ts_shell/types/dom-webcodecs-stub/index.d.ts +2 -0
- package/ts_shell/types/dom-webcodecs-stub/package.json +6 -0
- package/ts_web/00_commitinfo_data.ts +1 -1
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import * as plugins from '../../plugins.js';
|
|
2
|
+
import * as ast from '../helpers.ast.js';
|
|
3
|
+
import { baseOf, dirOf, specifierFor } from '../helpers.paths.js';
|
|
4
|
+
import type { IStandardElement, IStandardProperty, StandardProject } from '../classes.standardproject.js';
|
|
5
|
+
import type { IFixBuilder } from '../rule.js';
|
|
6
|
+
|
|
7
|
+
const ts = plugins.typescript;
|
|
8
|
+
|
|
9
|
+
export const elementsDir = 'ts_web/elements';
|
|
10
|
+
|
|
11
|
+
/** `ts_web/elements/00group-<area>` or `ts_web/elements` itself. */
|
|
12
|
+
export const isElementParentDir = (dirArg: string): boolean =>
|
|
13
|
+
dirArg === elementsDir || /^ts_web\/elements\/00group-[^/]+$/.test(dirArg);
|
|
14
|
+
|
|
15
|
+
/** Names the HTML specification reserves; `customElements.define` rejects them. */
|
|
16
|
+
const reservedElementNames = ['annotation-xml', 'color-profile', 'font-face', 'font-face-src', 'font-face-uri', 'font-face-format', 'font-face-name', 'missing-glyph'];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A valid custom element name in the ASCII subset the standard allows: a lowercase letter first,
|
|
20
|
+
* then lowercase letters, digits, `-`, `.` and `_`, at least one `-`, and not a reserved name. Such
|
|
21
|
+
* a tag is also a safe file and folder name, so only these tags feed fixes that derive paths or code.
|
|
22
|
+
*/
|
|
23
|
+
export const isCustomElementName = (tagArg: string): boolean =>
|
|
24
|
+
/^[a-z][a-z0-9._-]*$/.test(tagArg) && tagArg.includes('-') && !reservedElementNames.includes(tagArg);
|
|
25
|
+
|
|
26
|
+
/** True when an element's entry file sits in its own element folder `…/<tag>/`. */
|
|
27
|
+
export const isInElementFolder = (elementArg: IStandardElement): boolean => {
|
|
28
|
+
const folder = dirOf(elementArg.file);
|
|
29
|
+
return !!elementArg.tag && baseOf(folder) === elementArg.tag && isElementParentDir(dirOf(folder));
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** The `<area>` of `ts_web/elements/00group-<area>/…`, or null. */
|
|
33
|
+
export const groupAreaOf = (fileArg: string): string | null => /^ts_web\/elements\/00group-([^/]+)\//.exec(fileArg)?.[1] ?? null;
|
|
34
|
+
|
|
35
|
+
/** Elements outside demo files: the catalog's own elements. */
|
|
36
|
+
export const catalogElements = (projectArg: StandardProject): IStandardElement[] =>
|
|
37
|
+
projectArg.elements.filter((elementArg) => !elementArg.inDemoFile);
|
|
38
|
+
|
|
39
|
+
/** Public `@property` members outside demo files. */
|
|
40
|
+
export const publicProperties = (projectArg: StandardProject): IStandardProperty[] =>
|
|
41
|
+
projectArg.properties.filter((propertyArg) => propertyArg.decorator === 'property' && propertyArg.isPublic && !propertyArg.inDemoFile);
|
|
42
|
+
|
|
43
|
+
export const elementKey = (elementArg: IStandardElement): string => `${elementArg.file}#${elementArg.className ?? elementArg.tag ?? '?'}`;
|
|
44
|
+
|
|
45
|
+
export const propertyKey = (propertyArg: IStandardProperty): string => `${propertyArg.file}#${propertyArg.name}`;
|
|
46
|
+
|
|
47
|
+
/** The type annotation of a property member without `undefined` and `null` union members. */
|
|
48
|
+
export const coreTypeOf = (propertyArg: IStandardProperty): ast.TTypeNode | null => {
|
|
49
|
+
const member = propertyArg.member;
|
|
50
|
+
const typeNode = ts.isPropertyDeclaration(member) ? member.type : undefined;
|
|
51
|
+
if (!typeNode) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
if (ts.isUnionTypeNode(typeNode)) {
|
|
55
|
+
const members = typeNode.types.filter((typeArg) =>
|
|
56
|
+
typeArg.kind !== ts.SyntaxKind.UndefinedKeyword
|
|
57
|
+
&& !(ts.isLiteralTypeNode(typeArg) && typeArg.literal.kind === ts.SyntaxKind.NullKeyword));
|
|
58
|
+
if (members.length === 1) {
|
|
59
|
+
return members[0];
|
|
60
|
+
}
|
|
61
|
+
return typeNode;
|
|
62
|
+
}
|
|
63
|
+
return typeNode;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const isArrayTypeNode = (typeArg: ast.TTypeNode): boolean => {
|
|
67
|
+
if (ts.isArrayTypeNode(typeArg)) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
if (ts.isTypeOperatorNode(typeArg) && typeArg.operator === ts.SyntaxKind.ReadonlyKeyword) {
|
|
71
|
+
return ts.isArrayTypeNode(typeArg.type);
|
|
72
|
+
}
|
|
73
|
+
return ts.isTypeReferenceNode(typeArg) && ts.isIdentifier(typeArg.typeName) && ['Array', 'ReadonlyArray'].includes(typeArg.typeName.text);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/** The position at the start of the line after the last `export … from` statement, or at the end of the file. */
|
|
77
|
+
export const exportInsertionPoint = (sourceFileArg: ast.TSourceFile): { position: number; prefix: string } => {
|
|
78
|
+
let lastEnd = -1;
|
|
79
|
+
for (const statement of sourceFileArg.statements) {
|
|
80
|
+
if (ts.isExportDeclaration(statement)) {
|
|
81
|
+
lastEnd = statement.end;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const text = sourceFileArg.text;
|
|
85
|
+
if (lastEnd === -1) {
|
|
86
|
+
return { position: text.length, prefix: text.length > 0 && !text.endsWith('\n') ? '\n' : '' };
|
|
87
|
+
}
|
|
88
|
+
const newline = text.indexOf('\n', lastEnd);
|
|
89
|
+
return newline === -1 ? { position: text.length, prefix: '\n' } : { position: newline + 1, prefix: '' };
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/** Adds `export * from '<target>';` to a barrel. */
|
|
93
|
+
export const addReexport = (builderArg: IFixBuilder, projectArg: StandardProject, barrelArg: string, targetArg: string): void => {
|
|
94
|
+
const point = exportInsertionPoint(projectArg.sourceFile(barrelArg));
|
|
95
|
+
builderArg.edit(barrelArg, point.position, point.position, `${point.prefix}export * from '${specifierFor(barrelArg, targetArg, 'js')}';\n`);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/** Removes a whole statement including its line break; from the line start when only indentation precedes it. */
|
|
99
|
+
export const removeStatement = (builderArg: IFixBuilder, fileArg: string, statementArg: ast.TNode): void => {
|
|
100
|
+
const text = statementArg.getSourceFile().text;
|
|
101
|
+
let start = statementArg.getStart();
|
|
102
|
+
const lineStart = text.lastIndexOf('\n', start - 1) + 1;
|
|
103
|
+
if (/^[ \t]*$/.test(text.slice(lineStart, start))) {
|
|
104
|
+
start = lineStart;
|
|
105
|
+
}
|
|
106
|
+
let end = statementArg.end;
|
|
107
|
+
const rest = /^[ \t]*\r?\n/.exec(text.slice(end));
|
|
108
|
+
if (rest) {
|
|
109
|
+
end += rest[0].length;
|
|
110
|
+
}
|
|
111
|
+
builderArg.edit(fileArg, start, end, '');
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/** The identifier a `static demo` value refers to at its root, e.g. `demoFunc` or `demos` in `demos.main`. */
|
|
115
|
+
export const rootIdentifier = (expressionArg: ast.TExpression): string | null => {
|
|
116
|
+
let current: ast.TExpression = expressionArg;
|
|
117
|
+
while (ts.isPropertyAccessExpression(current)) {
|
|
118
|
+
current = current.expression;
|
|
119
|
+
}
|
|
120
|
+
return ts.isIdentifier(current) ? current.text : null;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/** The start of the line following the line a position is on. */
|
|
124
|
+
export const nextLineStart = (textArg: string, positionArg: number): number => {
|
|
125
|
+
const newline = textArg.indexOf('\n', positionArg);
|
|
126
|
+
return newline === -1 ? textArg.length : newline + 1;
|
|
127
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as plugins from '../../plugins.js';
|
|
2
|
+
import * as ast from '../helpers.ast.js';
|
|
3
|
+
import type { IRuleFinding, IStandardRule } from '../rule.js';
|
|
4
|
+
|
|
5
|
+
const ts = plugins.typescript;
|
|
6
|
+
|
|
7
|
+
/** The one module that may call `bdTheme()`: the token bridge. */
|
|
8
|
+
export const bdThemeBridge = 'ts_web/elements/00theme.ts';
|
|
9
|
+
|
|
10
|
+
/** dees: no new `cssManager.bdTheme()` call outside `ts_web/elements/00theme.ts`. A ratchet: baselines only. */
|
|
11
|
+
export const styleBdThemeRule: IStandardRule = {
|
|
12
|
+
id: 'style/bdtheme',
|
|
13
|
+
severity: { dees: 'error' },
|
|
14
|
+
fixMode: 'none',
|
|
15
|
+
detect: ({ project }) => {
|
|
16
|
+
const findings: IRuleFinding[] = [];
|
|
17
|
+
for (const file of project.webFiles) {
|
|
18
|
+
if (file === bdThemeBridge) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const visit = (nodeArg: ast.TNode): void => {
|
|
22
|
+
if (ts.isCallExpression(nodeArg) && ast.calleeName(nodeArg.expression) === 'bdTheme') {
|
|
23
|
+
findings.push({ file, position: nodeArg.getStart(), key: file, message: 'bdTheme() call; use --dees-* tokens' });
|
|
24
|
+
}
|
|
25
|
+
ts.forEachChild(nodeArg, visit);
|
|
26
|
+
};
|
|
27
|
+
visit(project.sourceFile(file));
|
|
28
|
+
}
|
|
29
|
+
return findings;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { IWccCatalogManifest } from './catalog.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The bridge between the shell and the preview document. The preview runtime installs it as
|
|
5
|
+
* `window.wccPreview` in the preview document; the shell reaches it through the same-origin
|
|
6
|
+
* iframe. Every argument and result is plain, structured-cloneable data: values never carry
|
|
7
|
+
* objects of the other document's realm.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export type TWccTheme = 'dark' | 'bright';
|
|
11
|
+
|
|
12
|
+
/** One demo (or page) of the catalog. */
|
|
13
|
+
export interface IWccSelection {
|
|
14
|
+
sectionName: string;
|
|
15
|
+
itemName: string;
|
|
16
|
+
/** 0-based; always 0 for a page. */
|
|
17
|
+
demoIndex: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** What the preview shows instead of a demo. */
|
|
21
|
+
export interface IWccEmptyState {
|
|
22
|
+
title: string;
|
|
23
|
+
detail: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type TWccEmptyReason =
|
|
27
|
+
| 'nothing-selected'
|
|
28
|
+
| 'no-demo'
|
|
29
|
+
| 'ignored'
|
|
30
|
+
| 'missing'
|
|
31
|
+
| 'no-such-demo'
|
|
32
|
+
| 'failed';
|
|
33
|
+
|
|
34
|
+
export type TWccRenderOutcome =
|
|
35
|
+
| { kind: 'rendered'; type: 'element' | 'page' }
|
|
36
|
+
| { kind: 'empty'; reason: TWccEmptyReason; emptyState: IWccEmptyState };
|
|
37
|
+
|
|
38
|
+
export type TWccPropertyKind = 'String' | 'Number' | 'Boolean' | 'Enum' | 'Object' | 'Array';
|
|
39
|
+
|
|
40
|
+
/** A scalar property value the properties panel can show and set directly. */
|
|
41
|
+
export type TWccPropertyScalar = string | number | boolean | null;
|
|
42
|
+
|
|
43
|
+
export interface IWccPropertyDescriptor {
|
|
44
|
+
name: string;
|
|
45
|
+
kind: TWccPropertyKind;
|
|
46
|
+
/** The values of an `Enum` property. */
|
|
47
|
+
enumValues?: string[];
|
|
48
|
+
/** The current value of a String, Number, Boolean or Enum property. */
|
|
49
|
+
value?: TWccPropertyScalar;
|
|
50
|
+
/** The current value of an Object or Array property, as formatted JSON. */
|
|
51
|
+
json?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type TWccPropertyListing =
|
|
55
|
+
| { kind: 'properties'; elementName: string; properties: IWccPropertyDescriptor[] }
|
|
56
|
+
| { kind: 'unavailable'; reason: string };
|
|
57
|
+
|
|
58
|
+
export type TWccPropertyEditResult = { ok: true } | { ok: false; error: string };
|
|
59
|
+
|
|
60
|
+
export interface IWccRenderedEvent {
|
|
61
|
+
type: 'rendered';
|
|
62
|
+
selection: IWccSelection | null;
|
|
63
|
+
outcome: TWccRenderOutcome;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type TWccPreviewEvent = IWccRenderedEvent;
|
|
67
|
+
|
|
68
|
+
export interface IWccPreviewBridge {
|
|
69
|
+
getManifest(): IWccCatalogManifest;
|
|
70
|
+
/** The selection rendered last, or null before the first render. */
|
|
71
|
+
getSelection(): IWccSelection | null;
|
|
72
|
+
getTheme(): TWccTheme;
|
|
73
|
+
/** Render a demo or page into the preview document, without reloading it. */
|
|
74
|
+
render(selectionArg: IWccSelection): Promise<TWccRenderOutcome>;
|
|
75
|
+
setTheme(themeArg: TWccTheme): Promise<void>;
|
|
76
|
+
/** The editable properties of the selected element's rendered instance, once it has rendered. */
|
|
77
|
+
getProperties(): Promise<TWccPropertyListing>;
|
|
78
|
+
setProperty(nameArg: string, valueArg: TWccPropertyScalar): TWccPropertyEditResult;
|
|
79
|
+
/** Parse JSON in the preview document and assign it to an Object or Array property. */
|
|
80
|
+
setPropertyJson(nameArg: string, jsonArg: string): TWccPropertyEditResult;
|
|
81
|
+
/** The rendered instance of the selected element, for same-origin tooling. */
|
|
82
|
+
findRenderedInstance(): HTMLElement | null;
|
|
83
|
+
subscribe(listenerArg: (eventArg: TWccPreviewEvent) => void): () => void;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The message a preview document posts to its parent once its bridge is installed. */
|
|
87
|
+
export interface IWccPreviewReadyMessage {
|
|
88
|
+
type: 'wcctools-preview-ready';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
declare global {
|
|
92
|
+
interface Window {
|
|
93
|
+
wccPreview?: IWccPreviewBridge;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The data-only description of a catalog that the preview runtime hands to the shell.
|
|
3
|
+
* Element classes and template factories stay in the preview document.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** How the entries of a section are rendered: element demos or page factories. */
|
|
7
|
+
export type TWccSectionType = 'elements' | 'pages';
|
|
8
|
+
|
|
9
|
+
/** A navigable catalog entry. */
|
|
10
|
+
export interface IWccManifestEntry {
|
|
11
|
+
name: string;
|
|
12
|
+
/** The registered tag of an element; null for pages and unregistered element classes. */
|
|
13
|
+
tagName: string | null;
|
|
14
|
+
/** Number of demos (always 1 for a page). */
|
|
15
|
+
demoCount: number;
|
|
16
|
+
demoGroups: string[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** A registered element without a usable demo; listed, never navigable. */
|
|
20
|
+
export interface IWccManifestEntryWithoutDemo {
|
|
21
|
+
name: string;
|
|
22
|
+
tagName: string | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface IWccManifestSection {
|
|
26
|
+
name: string;
|
|
27
|
+
type: TWccSectionType;
|
|
28
|
+
icon?: string;
|
|
29
|
+
collapsed?: boolean;
|
|
30
|
+
/** Classified, filtered and sorted as the section configures it. */
|
|
31
|
+
entries: IWccManifestEntry[];
|
|
32
|
+
entriesWithoutDemo: IWccManifestEntryWithoutDemo[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface IWccCatalogManifest {
|
|
36
|
+
sections: IWccManifestSection[];
|
|
37
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Typed requests the shell sends to the `wcctools dev` server on `/wcctools/typedrequest`.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface IWccDevServerInfo {
|
|
8
|
+
/** Version of the wcctools package that serves the shell. */
|
|
9
|
+
wcctoolsVersion: string;
|
|
10
|
+
/** Name of the served project's package. */
|
|
11
|
+
projectName: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface IReq_GetDevServerInfo
|
|
15
|
+
extends plugins.typedrequestInterfaces.implementsTR<
|
|
16
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
17
|
+
IReq_GetDevServerInfo
|
|
18
|
+
> {
|
|
19
|
+
method: 'getDevServerInfo';
|
|
20
|
+
request: {};
|
|
21
|
+
response: IWccDevServerInfo;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The state of a catalog bundle: its latest run started, finished or failed. */
|
|
25
|
+
export type TWccBundleState = 'started' | 'finished' | 'failed';
|
|
26
|
+
|
|
27
|
+
/** The status of one catalog bundle the dev server builds with tswatch. */
|
|
28
|
+
export interface IWccBundleStatus {
|
|
29
|
+
/** The bundle's name in the tswatch configuration. */
|
|
30
|
+
name: string;
|
|
31
|
+
/** The latest run: `started` while it runs, then `finished` or `failed`. */
|
|
32
|
+
state: TWccBundleState;
|
|
33
|
+
/** Milliseconds the latest completed run took; absent before a run completed. */
|
|
34
|
+
durationMs?: number;
|
|
35
|
+
/**
|
|
36
|
+
* The bundler's error message when the latest completed run failed. It stays while the next
|
|
37
|
+
* run is in progress, so a failure is reported until a run finishes.
|
|
38
|
+
*/
|
|
39
|
+
errorMessage?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The status of every catalog bundle, at a revision that changes with every bundle event. */
|
|
43
|
+
export interface IWccBundleStatusSnapshot {
|
|
44
|
+
revision: number;
|
|
45
|
+
bundles: IWccBundleStatus[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Reads the bundle status. With `afterRevision`, the server answers once the status differs from
|
|
50
|
+
* that revision, or with the unchanged status after its wait limit, so a client follows the
|
|
51
|
+
* status with one request at a time. While the server is not serving (it is stopping), the request
|
|
52
|
+
* is refused with a typed error.
|
|
53
|
+
*/
|
|
54
|
+
export interface IReq_GetBundleStatus
|
|
55
|
+
extends plugins.typedrequestInterfaces.implementsTR<
|
|
56
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
57
|
+
IReq_GetBundleStatus
|
|
58
|
+
> {
|
|
59
|
+
method: 'getBundleStatus';
|
|
60
|
+
request: {
|
|
61
|
+
/** The revision the client knows; omitted: answer at once. */
|
|
62
|
+
afterRevision?: number;
|
|
63
|
+
};
|
|
64
|
+
response: IWccBundleStatusSnapshot;
|
|
65
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wcctools component standard (docs/standard.md): its configuration in `.smartconfig.json`
|
|
3
|
+
* and the reports `wcctools check` and `wcctools fix` produce.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Rule set a repository adopts. */
|
|
7
|
+
export type TStandardProfile = 'base' | 'dees';
|
|
8
|
+
|
|
9
|
+
/** A rule id of the form `<area>/<name>`, e.g. `props/reflect-primitive`. */
|
|
10
|
+
export type TStandardRuleId = string;
|
|
11
|
+
|
|
12
|
+
export type TStandardSeverity = 'error' | 'warn' | 'info';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* What `wcctools fix` does for a rule:
|
|
16
|
+
* - `auto`: fixes it on every run;
|
|
17
|
+
* - `opt-in`: fixes it only when the rule is named with `--rule`;
|
|
18
|
+
* - `none`: reports only.
|
|
19
|
+
*/
|
|
20
|
+
export type TStandardFixMode = 'auto' | 'opt-in' | 'none';
|
|
21
|
+
|
|
22
|
+
/** `.smartconfig.json` → `@design.estate/wcctools` → `standard`. */
|
|
23
|
+
export interface IStandardConfig {
|
|
24
|
+
/** Rule set; 'base' when absent. */
|
|
25
|
+
profile?: TStandardProfile;
|
|
26
|
+
/** Tag prefix without the trailing hyphen, e.g. 'dees'. */
|
|
27
|
+
tagPrefix: string;
|
|
28
|
+
/** dees profile: display name per group area, e.g. { harness: 'Agent Chat' }. */
|
|
29
|
+
groupNames?: Record<string, string>;
|
|
30
|
+
/** Exact exceptions: rule id → '<file>#<member>' → '<category>: <reason>'. */
|
|
31
|
+
allowlist?: Record<TStandardRuleId, Record<string, string>>;
|
|
32
|
+
/** Accepted counts of error findings: rule id → file → count. Only shrinks. */
|
|
33
|
+
baselines?: Record<TStandardRuleId, Record<string, number>>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** `.smartconfig.json` → `@design.estate/wcctools`. */
|
|
37
|
+
export interface IWccToolsConfig {
|
|
38
|
+
standard?: IStandardConfig;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface IStandardFinding {
|
|
42
|
+
ruleId: TStandardRuleId;
|
|
43
|
+
severity: TStandardSeverity;
|
|
44
|
+
/** Path relative to the repository root, '/' separators. */
|
|
45
|
+
file: string;
|
|
46
|
+
/** 1-based. */
|
|
47
|
+
line: number;
|
|
48
|
+
/** 1-based. */
|
|
49
|
+
column: number;
|
|
50
|
+
message: string;
|
|
51
|
+
/** True when `wcctools fix` resolves this finding (for opt-in rules: with --rule). */
|
|
52
|
+
fixable: boolean;
|
|
53
|
+
/** Set when the finding is covered by the allowlist or a baseline and does not fail check. */
|
|
54
|
+
covered?: 'allowlist' | 'baseline';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** A file whose finding count is below its baseline: a candidate for lowering the baseline. */
|
|
58
|
+
export interface IStandardBaselineSlack {
|
|
59
|
+
ruleId: TStandardRuleId;
|
|
60
|
+
file: string;
|
|
61
|
+
baseline: number;
|
|
62
|
+
current: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface IStandardReport {
|
|
66
|
+
profile: TStandardProfile;
|
|
67
|
+
findings: IStandardFinding[];
|
|
68
|
+
/** Files whose count is below their baseline: candidates for --update-baseline. */
|
|
69
|
+
baselineSlack: IStandardBaselineSlack[];
|
|
70
|
+
/** True when no error finding remains outside the allowlist and baselines. */
|
|
71
|
+
ok: boolean;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** A rule as it applies in one profile. */
|
|
75
|
+
export interface IStandardRuleInfo {
|
|
76
|
+
id: TStandardRuleId;
|
|
77
|
+
severity: TStandardSeverity;
|
|
78
|
+
fixMode: TStandardFixMode;
|
|
79
|
+
/** Categories an allowlist entry for this rule may use; empty when the rule takes no allowlist. */
|
|
80
|
+
allowlistCategories: string[];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface IStandardFileMove {
|
|
84
|
+
from: string;
|
|
85
|
+
to: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The changes a `wcctools fix` run makes (or, with --dry-run, would make). */
|
|
89
|
+
export interface IStandardFixPlan {
|
|
90
|
+
/** `git mv` operations, from the original path to the final path. */
|
|
91
|
+
moves: IStandardFileMove[];
|
|
92
|
+
/** New files, by final path. */
|
|
93
|
+
created: string[];
|
|
94
|
+
/** Changed existing files, by final path, with the rules that changed them. */
|
|
95
|
+
edited: Array<{ file: string; ruleIds: TStandardRuleId[] }>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface IStandardFixResult {
|
|
99
|
+
dryRun: boolean;
|
|
100
|
+
plan: IStandardFixPlan;
|
|
101
|
+
/** The check after the fix (with --dry-run: as the fix would leave the repository). */
|
|
102
|
+
remaining: IStandardReport;
|
|
103
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './previewroute.js';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The address of a preview document: the path the `wcctools dev` server serves it on, and
|
|
5
|
+
* the query that names what it renders. The shell loads it into its iframe; headless tools
|
|
6
|
+
* load it directly to render one demo alone.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** The path `wcctools dev` serves the preview document on. */
|
|
10
|
+
export const previewRoutePath = '/wcctools-preview';
|
|
11
|
+
|
|
12
|
+
export interface IWccPreviewRoute {
|
|
13
|
+
selection: plugins.interfaces.IWccSelection | null;
|
|
14
|
+
theme: plugins.interfaces.TWccTheme;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const queryKeys = {
|
|
18
|
+
section: 'section',
|
|
19
|
+
item: 'item',
|
|
20
|
+
demo: 'demo',
|
|
21
|
+
theme: 'theme',
|
|
22
|
+
} as const;
|
|
23
|
+
|
|
24
|
+
/** The query string (with leading `?`) of a preview route. */
|
|
25
|
+
export const formatPreviewQuery = (routeArg: IWccPreviewRoute): string => {
|
|
26
|
+
const params = new URLSearchParams();
|
|
27
|
+
if (routeArg.selection) {
|
|
28
|
+
params.set(queryKeys.section, routeArg.selection.sectionName);
|
|
29
|
+
params.set(queryKeys.item, routeArg.selection.itemName);
|
|
30
|
+
params.set(queryKeys.demo, String(routeArg.selection.demoIndex));
|
|
31
|
+
}
|
|
32
|
+
params.set(queryKeys.theme, routeArg.theme);
|
|
33
|
+
return `?${params.toString()}`;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** Read a preview route from a query string. Missing or invalid parts read as no selection and the dark theme. */
|
|
37
|
+
export const parsePreviewQuery = (searchArg: string): IWccPreviewRoute => {
|
|
38
|
+
const params = new URLSearchParams(searchArg);
|
|
39
|
+
const theme: plugins.interfaces.TWccTheme = params.get(queryKeys.theme) === 'bright' ? 'bright' : 'dark';
|
|
40
|
+
const sectionName = params.get(queryKeys.section);
|
|
41
|
+
const itemName = params.get(queryKeys.item);
|
|
42
|
+
if (!sectionName || !itemName) {
|
|
43
|
+
return { selection: null, theme };
|
|
44
|
+
}
|
|
45
|
+
const demoIndex = Number.parseInt(params.get(queryKeys.demo) ?? '0', 10);
|
|
46
|
+
return {
|
|
47
|
+
selection: { sectionName, itemName, demoIndex: Number.isInteger(demoIndex) && demoIndex >= 0 ? demoIndex : 0 },
|
|
48
|
+
theme,
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const previewReadyMessage: plugins.interfaces.IWccPreviewReadyMessage = { type: 'wcctools-preview-ready' };
|
|
53
|
+
|
|
54
|
+
export const isPreviewReadyMessage = (dataArg: unknown): dataArg is plugins.interfaces.IWccPreviewReadyMessage => {
|
|
55
|
+
return typeof dataArg === 'object'
|
|
56
|
+
&& dataArg !== null
|
|
57
|
+
&& (dataArg as { type?: unknown }).type === previewReadyMessage.type;
|
|
58
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
|
|
3
|
+
/** The first and the longest pause before a failed status request is sent again. */
|
|
4
|
+
const retryDelayMinMs = 1_000;
|
|
5
|
+
const retryDelayMaxMs = 10_000;
|
|
6
|
+
|
|
7
|
+
/** Resolves after `msArg`, or at once when the signal aborts. */
|
|
8
|
+
const pause = (msArg: number, signalArg: AbortSignal): Promise<void> =>
|
|
9
|
+
new Promise((resolve) => {
|
|
10
|
+
const done = () => {
|
|
11
|
+
clearTimeout(timer);
|
|
12
|
+
signalArg.removeEventListener('abort', done);
|
|
13
|
+
resolve();
|
|
14
|
+
};
|
|
15
|
+
const timer = setTimeout(done, msArg);
|
|
16
|
+
signalArg.addEventListener('abort', done, { once: true });
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Follows the dev server's bundle status: one `getBundleStatus` request at a time, each answered
|
|
21
|
+
* when the status changes. A failed request (the server restarting, for example) is sent again
|
|
22
|
+
* after a growing pause. `dispose()` aborts the request in flight and ends the loop.
|
|
23
|
+
*/
|
|
24
|
+
export class WccBundleStatusClient {
|
|
25
|
+
private abortController: AbortController | null = null;
|
|
26
|
+
|
|
27
|
+
constructor(
|
|
28
|
+
private readonly apiPath: string,
|
|
29
|
+
private readonly onStatus: (snapshotArg: plugins.interfaces.IWccBundleStatusSnapshot) => void,
|
|
30
|
+
) {}
|
|
31
|
+
|
|
32
|
+
public start() {
|
|
33
|
+
if (this.abortController) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const abortController = new AbortController();
|
|
37
|
+
this.abortController = abortController;
|
|
38
|
+
void this.follow(abortController.signal);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public dispose() {
|
|
42
|
+
this.abortController?.abort();
|
|
43
|
+
this.abortController = null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private async follow(signalArg: AbortSignal) {
|
|
47
|
+
const request = new plugins.typedrequest.TypedRequest<plugins.interfaces.IReq_GetBundleStatus>(this.apiPath, 'getBundleStatus');
|
|
48
|
+
let revision: number | undefined;
|
|
49
|
+
let retryDelay = retryDelayMinMs;
|
|
50
|
+
while (!signalArg.aborted) {
|
|
51
|
+
try {
|
|
52
|
+
const snapshot = await request.fire({ afterRevision: revision }, { abortSignal: signalArg });
|
|
53
|
+
retryDelay = retryDelayMinMs;
|
|
54
|
+
if (!signalArg.aborted && snapshot.revision !== revision) {
|
|
55
|
+
revision = snapshot.revision;
|
|
56
|
+
this.onStatus(snapshot);
|
|
57
|
+
}
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (signalArg.aborted) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
console.warn('wcctools: reading the bundle status failed; retrying', error);
|
|
63
|
+
await pause(retryDelay, signalArg);
|
|
64
|
+
retryDelay = Math.min(retryDelay * 2, retryDelayMaxMs);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|