@estiva-app/ui 0.35.1 → 0.36.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/dist/eslint/escape.d.ts +23 -6
- package/dist/eslint/escape.d.ts.map +1 -1
- package/dist/eslint/index.js +70 -9
- package/dist/eslint/index.js.map +2 -2
- package/dist/eslint/no-raw-element.d.ts +7 -0
- package/dist/eslint/no-raw-element.d.ts.map +1 -1
- package/dist/eslint/no-restyled-part.d.ts +8 -0
- package/dist/eslint/no-restyled-part.d.ts.map +1 -1
- package/dist/gates/app-checks.d.ts.map +1 -1
- package/dist/gates/{chunk-DRIHHXQK.js → chunk-CC6L4B5U.js} +23 -17
- package/dist/gates/chunk-CC6L4B5U.js.map +7 -0
- package/dist/gates/chunk-SYVKGOWM.js +1131 -0
- package/dist/gates/chunk-SYVKGOWM.js.map +7 -0
- package/dist/gates/ci.d.ts +18 -0
- package/dist/gates/ci.d.ts.map +1 -0
- package/dist/gates/cli.js +20 -3
- package/dist/gates/cli.js.map +2 -2
- package/dist/gates/create-app.d.ts.map +1 -1
- package/dist/gates/create-app.js +1 -1
- package/dist/gates/escapes.d.ts +23 -0
- package/dist/gates/escapes.d.ts.map +1 -0
- package/dist/gates/gate-config.d.ts.map +1 -1
- package/dist/gates/hook.d.ts +2 -0
- package/dist/gates/hook.d.ts.map +1 -1
- package/dist/gates/index.d.ts +5 -1
- package/dist/gates/index.d.ts.map +1 -1
- package/dist/gates/index.js +41 -185
- package/dist/gates/index.js.map +4 -4
- package/dist/gates/name-escapes.d.ts +14 -0
- package/dist/gates/name-escapes.d.ts.map +1 -0
- package/dist/gates/status.d.ts +3 -1
- package/dist/gates/status.d.ts.map +1 -1
- package/dist/gates/token-lint.d.ts.map +1 -1
- package/dist/gates/token-style.d.ts +21 -0
- package/dist/gates/token-style.d.ts.map +1 -0
- package/dist/index.js +13 -13
- package/dist/index.js.map +1 -1
- package/dist/registry/{app-3ALZE6XO.js → app-YMABQII6.js} +3 -3
- package/dist/registry/app.d.ts.map +1 -1
- package/dist/registry/behaviours.d.ts +71 -0
- package/dist/registry/behaviours.d.ts.map +1 -0
- package/dist/registry/{build-NDXMVFQ5.js → build-3EANARLQ.js} +2 -2
- package/dist/registry/build.d.ts.map +1 -1
- package/dist/registry/{chunk-3WJ7ZZ7Z.js → chunk-EVJW26UR.js} +51 -4
- package/dist/registry/chunk-EVJW26UR.js.map +7 -0
- package/dist/registry/{chunk-XVII7P6G.js → chunk-SIB44CES.js} +276 -90
- package/dist/registry/chunk-SIB44CES.js.map +7 -0
- package/dist/registry/{chunk-KMZIMB3G.js → chunk-XK747STJ.js} +46 -3
- package/dist/registry/chunk-XK747STJ.js.map +7 -0
- package/dist/registry/cli.js +93 -34
- package/dist/registry/cli.js.map +3 -3
- package/dist/registry/contract.d.ts +27 -1
- package/dist/registry/contract.d.ts.map +1 -1
- package/dist/registry/index.d.ts +1 -1
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/index.js +11 -5
- package/dist/registry/siblings.d.ts +9 -0
- package/dist/registry/siblings.d.ts.map +1 -1
- package/dist/registry/storymap.d.ts +19 -5
- package/dist/registry/storymap.d.ts.map +1 -1
- package/package.json +4 -1
- package/registry.json +293 -17
- package/skill/estiva-ui.md +2 -1
- package/src/AppShell.mdx +2 -1
- package/src/AttachmentCard.tsx +7 -7
- package/src/Button.tsx +1 -1
- package/src/Card.tsx +2 -2
- package/src/ChipInput.mdx +2 -0
- package/src/ChipInput.tsx +1 -1
- package/src/CommandPalette.tsx +3 -3
- package/src/DialogShell.tsx +1 -1
- package/src/EmptyState.mdx +4 -3
- package/src/Lightbox.tsx +1 -1
- package/src/NavItem.tsx +1 -1
- package/src/PersonTrigger.tsx +1 -1
- package/src/Reaction.tsx +1 -1
- package/src/ScrollArea.mdx +4 -0
- package/src/Select.tsx +1 -1
- package/src/TopBar.mdx +1 -1
- package/src/eslint/escape.ts +43 -14
- package/src/eslint/has-a-page-and-a-story.test.ts +1 -1
- package/src/eslint/index.test.ts +2 -2
- package/src/eslint/no-copied-look.test.ts +1 -1
- package/src/eslint/no-hand-rolled-behaviour.test.ts +3 -3
- package/src/eslint/no-handmade-empty-state.test.ts +2 -2
- package/src/eslint/no-handmade-header.test.ts +2 -2
- package/src/eslint/no-native-title.test.ts +2 -2
- package/src/eslint/no-raw-element.test.ts +47 -15
- package/src/eslint/no-raw-element.ts +53 -3
- package/src/eslint/no-rebuilt-behaviour.test.ts +9 -9
- package/src/eslint/no-restyled-part.test.ts +21 -2
- package/src/eslint/no-restyled-part.ts +30 -0
- package/src/eslint/raw-element-outside-a-wrapper.test.ts +3 -3
- package/src/gates/app-checks.ts +4 -3
- package/src/gates/ci.ts +152 -0
- package/src/gates/cli.ts +19 -3
- package/src/gates/count.ts +1 -1
- package/src/gates/create-app.test.ts +2 -2
- package/src/gates/create-app.ts +22 -16
- package/src/gates/escapes.ts +111 -0
- package/src/gates/gate-config.ts +6 -2
- package/src/gates/gates.test.ts +93 -1
- package/src/gates/hook.ts +44 -6
- package/src/gates/index.ts +5 -1
- package/src/gates/name-escapes.ts +77 -0
- package/src/gates/status.ts +45 -2
- package/src/gates/token-lint.ts +11 -4
- package/src/gates/token-style.ts +79 -0
- package/src/how.test.ts +282 -0
- package/src/pages.test.ts +17 -0
- package/src/registry/app.test.ts +34 -0
- package/src/registry/app.ts +52 -2
- package/src/registry/behaviours.ts +223 -0
- package/src/registry/build.ts +36 -0
- package/src/registry/cli.ts +37 -18
- package/src/registry/contract.test.ts +63 -3
- package/src/registry/contract.ts +75 -2
- package/src/registry/index.ts +1 -1
- package/src/registry/registry.test.ts +14 -0
- package/src/registry/siblings.test.ts +24 -1
- package/src/registry/siblings.ts +23 -0
- package/src/registry/storymap.test.ts +52 -31
- package/src/registry/storymap.ts +76 -37
- package/stories/Choosing.mdx +8 -2
- package/dist/gates/chunk-DRIHHXQK.js.map +0 -7
- package/dist/gates/chunk-GI6M4P7H.js +0 -606
- package/dist/gates/chunk-GI6M4P7H.js.map +0 -7
- package/dist/registry/chunk-3WJ7ZZ7Z.js.map +0 -7
- package/dist/registry/chunk-KMZIMB3G.js.map +0 -7
- package/dist/registry/chunk-XVII7P6G.js.map +0 -7
- /package/dist/registry/{app-3ALZE6XO.js.map → app-YMABQII6.js.map} +0 -0
- /package/dist/registry/{build-NDXMVFQ5.js.map → build-3EANARLQ.js.map} +0 -0
|
@@ -6,13 +6,162 @@ import {
|
|
|
6
6
|
// src/registry/build.ts
|
|
7
7
|
import { readFileSync as readFileSync2, readdirSync } from "node:fs";
|
|
8
8
|
import { join as join2 } from "node:path";
|
|
9
|
-
import
|
|
9
|
+
import ts3 from "typescript";
|
|
10
|
+
import { OWNED_BEHAVIOURS as OWNED_BEHAVIOURS2 } from "../eslint/index.js";
|
|
11
|
+
|
|
12
|
+
// src/registry/behaviours.ts
|
|
13
|
+
import ts from "typescript";
|
|
10
14
|
import { OWNED_BEHAVIOURS } from "../eslint/index.js";
|
|
15
|
+
var isBaseUi = (specifier) => /^@base-ui(?:-components)?\/react(?:\/|$)/.test(specifier);
|
|
16
|
+
function baseUiBehaviours(part, piece) {
|
|
17
|
+
const whole = !piece || piece === "Root" || piece === "Provider";
|
|
18
|
+
return OWNED_BEHAVIOURS.filter((owned) => owned.id === "base-ui" || owned.baseUi.includes(part) && (whole || owned.id === "role")).map((owned) => owned.id);
|
|
19
|
+
}
|
|
20
|
+
var HANDED_ON = /* @__PURE__ */ new Set(["portal", "press-outside", "page-keys", "focus", "scroll-lock", "follow", "scroll"]);
|
|
21
|
+
var HINTS = /* @__PURE__ */ new Set(["Tooltip", "WithTooltip", "TooltipProvider", "PreviewCard"]);
|
|
22
|
+
var handedOn = (name, owned) => HINTS.has(name) ? [] : [...owned].filter((id) => HANDED_ON.has(id));
|
|
23
|
+
function asBehaviours(ids) {
|
|
24
|
+
const held = new Set(ids);
|
|
25
|
+
return OWNED_BEHAVIOURS.filter((owned) => held.has(owned.id)).map((owned) => ({ id: owned.id, behaviour: owned.behaviour }));
|
|
26
|
+
}
|
|
27
|
+
function tagText(tag) {
|
|
28
|
+
if (ts.isIdentifier(tag)) return tag.text;
|
|
29
|
+
if (ts.isPropertyAccessExpression(tag)) {
|
|
30
|
+
const inner = tagText(tag.expression);
|
|
31
|
+
return inner && `${inner}.${tag.name.text}`;
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
var splitTag = (tag) => {
|
|
36
|
+
const [root, piece] = tag.split(".");
|
|
37
|
+
return [root, piece];
|
|
38
|
+
};
|
|
39
|
+
function tagsUnder(node) {
|
|
40
|
+
const found = /* @__PURE__ */ new Set();
|
|
41
|
+
const visit = (n) => {
|
|
42
|
+
if (ts.isJsxOpeningElement(n) || ts.isJsxSelfClosingElement(n)) {
|
|
43
|
+
const tag = tagText(n.tagName);
|
|
44
|
+
if (tag && /^[A-Z]/.test(tag)) found.add(tag);
|
|
45
|
+
}
|
|
46
|
+
ts.forEachChild(n, visit);
|
|
47
|
+
};
|
|
48
|
+
visit(node);
|
|
49
|
+
return found;
|
|
50
|
+
}
|
|
51
|
+
function drawnIn(sf) {
|
|
52
|
+
const direct = /* @__PURE__ */ new Map();
|
|
53
|
+
for (const statement of sf.statements) {
|
|
54
|
+
if ((ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement)) && statement.name) direct.set(statement.name.text, tagsUnder(statement));
|
|
55
|
+
else if (ts.isVariableStatement(statement)) {
|
|
56
|
+
for (const d of statement.declarationList.declarations) if (ts.isIdentifier(d.name) && d.initializer) direct.set(d.name.text, tagsUnder(d.initializer));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const closed = /* @__PURE__ */ new Map();
|
|
60
|
+
for (const name of direct.keys()) {
|
|
61
|
+
const out = /* @__PURE__ */ new Set();
|
|
62
|
+
const seen = /* @__PURE__ */ new Set([name]);
|
|
63
|
+
const stack = [name];
|
|
64
|
+
while (stack.length) {
|
|
65
|
+
for (const tag of direct.get(stack.pop()) ?? []) {
|
|
66
|
+
out.add(tag);
|
|
67
|
+
if (direct.has(tag) && !seen.has(tag)) {
|
|
68
|
+
seen.add(tag);
|
|
69
|
+
stack.push(tag);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
closed.set(name, out);
|
|
74
|
+
}
|
|
75
|
+
return closed;
|
|
76
|
+
}
|
|
77
|
+
function rootsOfExpression(e, out) {
|
|
78
|
+
if (!e) return;
|
|
79
|
+
if (ts.isParenthesizedExpression(e) || ts.isAsExpression(e) || ts.isSatisfiesExpression(e) || ts.isNonNullExpression(e)) return rootsOfExpression(e.expression, out);
|
|
80
|
+
if (ts.isConditionalExpression(e)) {
|
|
81
|
+
rootsOfExpression(e.whenTrue, out);
|
|
82
|
+
rootsOfExpression(e.whenFalse, out);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (ts.isBinaryExpression(e)) {
|
|
86
|
+
if (e.operatorToken.kind !== ts.SyntaxKind.AmpersandAmpersandToken) rootsOfExpression(e.left, out);
|
|
87
|
+
rootsOfExpression(e.right, out);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (ts.isJsxFragment(e)) return;
|
|
91
|
+
const tag = ts.isJsxElement(e) ? tagText(e.openingElement.tagName) : ts.isJsxSelfClosingElement(e) ? tagText(e.tagName) : null;
|
|
92
|
+
if (tag && /^[A-Z]/.test(tag)) out.add(tag);
|
|
93
|
+
}
|
|
94
|
+
function rootsOfFunction(fn) {
|
|
95
|
+
const out = /* @__PURE__ */ new Set();
|
|
96
|
+
if (ts.isArrowFunction(fn) && !ts.isBlock(fn.body)) rootsOfExpression(fn.body, out);
|
|
97
|
+
const visit = (n) => {
|
|
98
|
+
if (n !== fn && (ts.isFunctionLike(n) || ts.isClassLike(n))) return;
|
|
99
|
+
if (ts.isReturnStatement(n)) rootsOfExpression(n.expression, out);
|
|
100
|
+
ts.forEachChild(n, visit);
|
|
101
|
+
};
|
|
102
|
+
visit(fn);
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
function functionOf(node) {
|
|
106
|
+
if (!node) return void 0;
|
|
107
|
+
if (ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node)) return node;
|
|
108
|
+
if (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isSatisfiesExpression(node)) return functionOf(node.expression);
|
|
109
|
+
if (ts.isCallExpression(node)) for (const argument of node.arguments) {
|
|
110
|
+
const fn = functionOf(argument);
|
|
111
|
+
if (fn) return fn;
|
|
112
|
+
}
|
|
113
|
+
return void 0;
|
|
114
|
+
}
|
|
115
|
+
function rootsIn(sf) {
|
|
116
|
+
const direct = /* @__PURE__ */ new Map();
|
|
117
|
+
for (const statement of sf.statements) {
|
|
118
|
+
if (ts.isFunctionDeclaration(statement) && statement.name) direct.set(statement.name.text, rootsOfFunction(statement));
|
|
119
|
+
else if (ts.isVariableStatement(statement)) {
|
|
120
|
+
for (const d of statement.declarationList.declarations) {
|
|
121
|
+
const fn = functionOf(d.initializer);
|
|
122
|
+
if (ts.isIdentifier(d.name) && fn) direct.set(d.name.text, rootsOfFunction(fn));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const closed = /* @__PURE__ */ new Map();
|
|
127
|
+
for (const name of direct.keys()) {
|
|
128
|
+
const out = /* @__PURE__ */ new Set();
|
|
129
|
+
const seen = /* @__PURE__ */ new Set([name]);
|
|
130
|
+
const stack = [name];
|
|
131
|
+
while (stack.length) {
|
|
132
|
+
for (const tag of direct.get(stack.pop()) ?? []) {
|
|
133
|
+
if (direct.has(tag)) {
|
|
134
|
+
if (!seen.has(tag)) {
|
|
135
|
+
seen.add(tag);
|
|
136
|
+
stack.push(tag);
|
|
137
|
+
}
|
|
138
|
+
} else out.add(tag);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
closed.set(name, out);
|
|
142
|
+
}
|
|
143
|
+
return closed;
|
|
144
|
+
}
|
|
145
|
+
function importsOf(sf) {
|
|
146
|
+
const out = /* @__PURE__ */ new Map();
|
|
147
|
+
for (const statement of sf.statements) {
|
|
148
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) continue;
|
|
149
|
+
const clause = statement.importClause;
|
|
150
|
+
if (!clause || clause.isTypeOnly) continue;
|
|
151
|
+
const specifier = statement.moduleSpecifier.text;
|
|
152
|
+
if (clause.name) out.set(clause.name.text, { specifier, imported: "default" });
|
|
153
|
+
const bindings = clause.namedBindings;
|
|
154
|
+
if (bindings && ts.isNamedImports(bindings)) {
|
|
155
|
+
for (const e of bindings.elements) if (!e.isTypeOnly) out.set(e.name.text, { specifier, imported: (e.propertyName ?? e.name).text });
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
11
160
|
|
|
12
161
|
// src/eslint/looks-of.ts
|
|
13
162
|
import { existsSync, readFileSync } from "node:fs";
|
|
14
163
|
import { dirname, join, resolve as resolvePath } from "node:path";
|
|
15
|
-
import
|
|
164
|
+
import ts2 from "typescript";
|
|
16
165
|
var PLACEMENT = [
|
|
17
166
|
/^m[xytrblse]?-/,
|
|
18
167
|
/^p[xytrblse]?-/,
|
|
@@ -37,10 +186,10 @@ var CAP = 24;
|
|
|
37
186
|
function classUnits(source, follow) {
|
|
38
187
|
const consts = /* @__PURE__ */ new Map();
|
|
39
188
|
const collect = (node) => {
|
|
40
|
-
if (
|
|
189
|
+
if (ts2.isVariableDeclaration(node) && ts2.isIdentifier(node.name) && node.initializer && ts2.isVariableDeclarationList(node.parent) && node.parent.flags & ts2.NodeFlags.Const) {
|
|
41
190
|
consts.set(node.name.text, node.initializer);
|
|
42
191
|
}
|
|
43
|
-
|
|
192
|
+
ts2.forEachChild(node, collect);
|
|
44
193
|
};
|
|
45
194
|
collect(source);
|
|
46
195
|
const product = (lists) => {
|
|
@@ -54,30 +203,30 @@ function classUnits(source, follow) {
|
|
|
54
203
|
};
|
|
55
204
|
const resolve = (node, depth = 0) => {
|
|
56
205
|
if (!node || depth > 8) return [[]];
|
|
57
|
-
if (
|
|
58
|
-
if (
|
|
59
|
-
if (
|
|
60
|
-
if (
|
|
61
|
-
if (
|
|
62
|
-
if (
|
|
63
|
-
if (
|
|
64
|
-
if (node.operatorToken.kind ===
|
|
65
|
-
if (node.operatorToken.kind ===
|
|
206
|
+
if (ts2.isStringLiteral(node) || ts2.isNoSubstitutionTemplateLiteral(node)) return [words(node.text)];
|
|
207
|
+
if (ts2.isTemplateExpression(node)) return product([[words(node.head.text)], ...node.templateSpans.flatMap((span) => [resolve(span.expression, depth + 1), [words(span.literal.text)]])]);
|
|
208
|
+
if (ts2.isParenthesizedExpression(node) || ts2.isAsExpression(node) || ts2.isSatisfiesExpression(node) || ts2.isNonNullExpression(node)) return resolve(node.expression, depth + 1);
|
|
209
|
+
if (ts2.isJsxExpression(node)) return resolve(node.expression, depth + 1);
|
|
210
|
+
if (ts2.isCallExpression(node)) return ts2.isIdentifier(node.expression) && CLASS_FUNCTIONS.has(node.expression.text) ? product(node.arguments.map((a) => resolve(a, depth + 1))) : [[]];
|
|
211
|
+
if (ts2.isConditionalExpression(node)) return [...resolve(node.whenTrue, depth + 1), ...resolve(node.whenFalse, depth + 1)].slice(0, CAP);
|
|
212
|
+
if (ts2.isBinaryExpression(node)) {
|
|
213
|
+
if (node.operatorToken.kind === ts2.SyntaxKind.AmpersandAmpersandToken) return [[], ...resolve(node.right, depth + 1)];
|
|
214
|
+
if (node.operatorToken.kind === ts2.SyntaxKind.BarBarToken || node.operatorToken.kind === ts2.SyntaxKind.QuestionQuestionToken) return [...resolve(node.left, depth + 1), ...resolve(node.right, depth + 1)].slice(0, CAP);
|
|
66
215
|
return [[]];
|
|
67
216
|
}
|
|
68
|
-
if (
|
|
69
|
-
if (
|
|
70
|
-
if (
|
|
217
|
+
if (ts2.isArrayLiteralExpression(node)) return product(node.elements.map((e) => resolve(e, depth + 1)));
|
|
218
|
+
if (ts2.isObjectLiteralExpression(node)) return [[], node.properties.flatMap((p) => p.name && (ts2.isIdentifier(p.name) || ts2.isStringLiteral(p.name)) ? words(p.name.text) : [])];
|
|
219
|
+
if (ts2.isIdentifier(node)) {
|
|
71
220
|
const init = consts.get(node.text) ?? follow?.(node.text);
|
|
72
221
|
return init ? resolve(init, depth + 1) : [[]];
|
|
73
222
|
}
|
|
74
|
-
if (
|
|
223
|
+
if (ts2.isPropertyAccessExpression(node) || ts2.isElementAccessExpression(node)) {
|
|
75
224
|
let target = node.expression;
|
|
76
|
-
if (
|
|
77
|
-
while (target && (
|
|
78
|
-
if (!target || !
|
|
79
|
-
const key =
|
|
80
|
-
return target.properties.filter((p) =>
|
|
225
|
+
if (ts2.isIdentifier(target)) target = consts.get(target.text) ?? follow?.(target.text);
|
|
226
|
+
while (target && (ts2.isAsExpression(target) || ts2.isSatisfiesExpression(target) || ts2.isParenthesizedExpression(target))) target = target.expression;
|
|
227
|
+
if (!target || !ts2.isObjectLiteralExpression(target)) return [[]];
|
|
228
|
+
const key = ts2.isPropertyAccessExpression(node) ? node.name.text : ts2.isStringLiteral(node.argumentExpression) ? node.argumentExpression.text : null;
|
|
229
|
+
return target.properties.filter((p) => ts2.isPropertyAssignment(p) && (key === null || !!p.name && (ts2.isIdentifier(p.name) || ts2.isStringLiteral(p.name)) && p.name.text === key)).flatMap((p) => resolve(p.initializer, depth + 1)).slice(0, CAP);
|
|
81
230
|
}
|
|
82
231
|
return [[]];
|
|
83
232
|
};
|
|
@@ -85,14 +234,14 @@ function classUnits(source, follow) {
|
|
|
85
234
|
const seen = /* @__PURE__ */ new Set();
|
|
86
235
|
const sharedAt = (node) => {
|
|
87
236
|
for (let at = node; at; at = at.parent) {
|
|
88
|
-
if (
|
|
237
|
+
if (ts2.isVariableDeclaration(at)) return ts2.isIdentifier(at.name) && /_CLASSES$/.test(at.name.text) && !!at.parent?.parent && ts2.isVariableStatement(at.parent.parent) && !!at.parent.parent.modifiers?.some((m) => m.kind === ts2.SyntaxKind.ExportKeyword);
|
|
89
238
|
}
|
|
90
239
|
return false;
|
|
91
240
|
};
|
|
92
241
|
const lineStart = (node) => {
|
|
93
242
|
const line = source.getLineAndCharacterOfPosition(node.getStart(source)).line;
|
|
94
243
|
let at = node;
|
|
95
|
-
while (at.parent && !
|
|
244
|
+
while (at.parent && !ts2.isSourceFile(at.parent) && source.getLineAndCharacterOfPosition(at.parent.getStart(source)).line === line) at = at.parent;
|
|
96
245
|
return at.getStart(source);
|
|
97
246
|
};
|
|
98
247
|
const add = (tokens, node, via, anchor = via === "literal" ? lineStart(node) : node.getStart(source)) => {
|
|
@@ -105,12 +254,12 @@ function classUnits(source, follow) {
|
|
|
105
254
|
units.push({ tokens: list, look, start: node.getStart(source), end: node.getEnd(), via, anchor, shared: via === "literal" && sharedAt(node) });
|
|
106
255
|
};
|
|
107
256
|
const visit = (node) => {
|
|
108
|
-
if (
|
|
257
|
+
if (ts2.isJsxAttribute(node) && ts2.isIdentifier(node.name) && CLASS_PROP.test(node.name.text) && node.initializer) {
|
|
109
258
|
const element = node.parent.parent;
|
|
110
259
|
for (const alternative of resolve(node.initializer)) add(alternative, node, "attribute", element.getStart(source));
|
|
111
260
|
}
|
|
112
|
-
if ((
|
|
113
|
-
|
|
261
|
+
if ((ts2.isStringLiteral(node) || ts2.isNoSubstitutionTemplateLiteral(node)) && isClassList(node.text)) add(words(node.text), node, "literal");
|
|
262
|
+
ts2.forEachChild(node, visit);
|
|
114
263
|
};
|
|
115
264
|
visit(source);
|
|
116
265
|
return units;
|
|
@@ -119,15 +268,15 @@ function componentsOf(source) {
|
|
|
119
268
|
const found = /* @__PURE__ */ new Map();
|
|
120
269
|
const fn = (node) => {
|
|
121
270
|
let current = node;
|
|
122
|
-
while (current &&
|
|
123
|
-
return current && (
|
|
271
|
+
while (current && ts2.isCallExpression(current) && current.arguments.length) current = current.arguments[0];
|
|
272
|
+
return current && (ts2.isArrowFunction(current) || ts2.isFunctionExpression(current)) ? current : void 0;
|
|
124
273
|
};
|
|
125
274
|
for (const statement of source.statements) {
|
|
126
|
-
if (
|
|
127
|
-
if (
|
|
275
|
+
if (ts2.isFunctionDeclaration(statement) && statement.name && /^[A-Z]/.test(statement.name.text)) found.set(statement.name.text, { start: statement.getStart(source), end: statement.getEnd() });
|
|
276
|
+
if (ts2.isVariableStatement(statement)) {
|
|
128
277
|
for (const declaration of statement.declarationList.declarations) {
|
|
129
278
|
const body = fn(declaration.initializer);
|
|
130
|
-
if (
|
|
279
|
+
if (ts2.isIdentifier(declaration.name) && /^[A-Z]/.test(declaration.name.text) && body) found.set(declaration.name.text, { start: body.getStart(source), end: body.getEnd() });
|
|
131
280
|
}
|
|
132
281
|
}
|
|
133
282
|
}
|
|
@@ -147,7 +296,7 @@ function looksOf(source, names) {
|
|
|
147
296
|
return out;
|
|
148
297
|
}
|
|
149
298
|
function parseForLooks(fileName, text) {
|
|
150
|
-
return
|
|
299
|
+
return ts2.createSourceFile(fileName, text, ts2.ScriptTarget.Latest, true, fileName.endsWith("x") ? ts2.ScriptKind.TSX : ts2.ScriptKind.TS);
|
|
151
300
|
}
|
|
152
301
|
function importTarget(fromFile, specifier) {
|
|
153
302
|
let base;
|
|
@@ -167,8 +316,8 @@ function constantsOf(file) {
|
|
|
167
316
|
const found = /* @__PURE__ */ new Map();
|
|
168
317
|
const source = parseForLooks(file, readFileSync(file, "utf8"));
|
|
169
318
|
for (const statement of source.statements) {
|
|
170
|
-
if (!
|
|
171
|
-
for (const d of statement.declarationList.declarations) if (
|
|
319
|
+
if (!ts2.isVariableStatement(statement)) continue;
|
|
320
|
+
for (const d of statement.declarationList.declarations) if (ts2.isIdentifier(d.name) && d.initializer) found.set(d.name.text, d.initializer);
|
|
172
321
|
}
|
|
173
322
|
constantsCache.set(file, found);
|
|
174
323
|
return found;
|
|
@@ -176,9 +325,9 @@ function constantsOf(file) {
|
|
|
176
325
|
function importedConstants(source) {
|
|
177
326
|
const imported = /* @__PURE__ */ new Map();
|
|
178
327
|
for (const statement of source.statements) {
|
|
179
|
-
if (!
|
|
328
|
+
if (!ts2.isImportDeclaration(statement) || !ts2.isStringLiteral(statement.moduleSpecifier)) continue;
|
|
180
329
|
const bindings = statement.importClause?.namedBindings;
|
|
181
|
-
if (!bindings || !
|
|
330
|
+
if (!bindings || !ts2.isNamedImports(bindings)) continue;
|
|
182
331
|
const target = importTarget(source.fileName, statement.moduleSpecifier.text);
|
|
183
332
|
if (!target) continue;
|
|
184
333
|
for (const element of bindings.elements) {
|
|
@@ -207,13 +356,13 @@ function storyNameFromExport(key) {
|
|
|
207
356
|
}
|
|
208
357
|
var toId = (title, name) => `${sanitize(title)}--${sanitize(storyNameFromExport(name))}`;
|
|
209
358
|
function readIndexExports(source) {
|
|
210
|
-
const file =
|
|
359
|
+
const file = ts3.createSourceFile("index.ts", source, ts3.ScriptTarget.Latest, true);
|
|
211
360
|
const found = [];
|
|
212
361
|
for (const statement of file.statements) {
|
|
213
|
-
if (!
|
|
362
|
+
if (!ts3.isExportDeclaration(statement)) continue;
|
|
214
363
|
const from = statement.moduleSpecifier;
|
|
215
364
|
const clause = statement.exportClause;
|
|
216
|
-
if (!from || !
|
|
365
|
+
if (!from || !ts3.isStringLiteral(from) || !clause || !ts3.isNamedExports(clause)) continue;
|
|
217
366
|
for (const element of clause.elements) {
|
|
218
367
|
found.push({ name: element.name.text, module: from.text.replace(/^\.\//, ""), isType: statement.isTypeOnly || element.isTypeOnly });
|
|
219
368
|
}
|
|
@@ -221,7 +370,7 @@ function readIndexExports(source) {
|
|
|
221
370
|
return found;
|
|
222
371
|
}
|
|
223
372
|
function docAbove(source, node, headerPos = null) {
|
|
224
|
-
const ranges =
|
|
373
|
+
const ranges = ts3.getLeadingCommentRanges(source, node.getFullStart()) ?? [];
|
|
225
374
|
const jsdoc = ranges.filter((range) => source.slice(range.pos, range.pos + 3) === "/**").pop();
|
|
226
375
|
if (!jsdoc) return "";
|
|
227
376
|
if (headerPos !== null && jsdoc.pos === headerPos) return "";
|
|
@@ -254,23 +403,23 @@ function pageOpening(mdx) {
|
|
|
254
403
|
}
|
|
255
404
|
function propName(member) {
|
|
256
405
|
if (!member.name) return null;
|
|
257
|
-
if (
|
|
406
|
+
if (ts3.isIdentifier(member.name) || ts3.isStringLiteral(member.name)) return member.name.text;
|
|
258
407
|
return null;
|
|
259
408
|
}
|
|
260
409
|
function literalUnion(type, aliases, seen = /* @__PURE__ */ new Set()) {
|
|
261
410
|
if (!type) return null;
|
|
262
|
-
if (
|
|
411
|
+
if (ts3.isTypeReferenceNode(type) && ts3.isIdentifier(type.typeName)) {
|
|
263
412
|
const name = type.typeName.text;
|
|
264
413
|
if (seen.has(name)) return null;
|
|
265
414
|
seen.add(name);
|
|
266
415
|
const alias = aliases.get(name);
|
|
267
416
|
return alias ? literalUnion(alias, aliases, seen) : null;
|
|
268
417
|
}
|
|
269
|
-
if (
|
|
270
|
-
if (!
|
|
418
|
+
if (ts3.isLiteralTypeNode(type) && ts3.isStringLiteral(type.literal)) return [type.literal.text];
|
|
419
|
+
if (!ts3.isUnionTypeNode(type)) return null;
|
|
271
420
|
const values = [];
|
|
272
421
|
for (const member of type.types) {
|
|
273
|
-
if (member.kind ===
|
|
422
|
+
if (member.kind === ts3.SyntaxKind.UndefinedKeyword || member.kind === ts3.SyntaxKind.NullKeyword) continue;
|
|
274
423
|
const inner = literalUnion(member, aliases, seen);
|
|
275
424
|
if (!inner) return null;
|
|
276
425
|
values.push(...inner);
|
|
@@ -278,7 +427,7 @@ function literalUnion(type, aliases, seen = /* @__PURE__ */ new Set()) {
|
|
|
278
427
|
return values.length > 1 ? values : null;
|
|
279
428
|
}
|
|
280
429
|
function readModule(source, sibling = () => void 0, { lendFirstComment = true } = {}) {
|
|
281
|
-
const file =
|
|
430
|
+
const file = ts3.createSourceFile("module.tsx", source, ts3.ScriptTarget.Latest, true);
|
|
282
431
|
const declarations = /* @__PURE__ */ new Map();
|
|
283
432
|
const aliases = /* @__PURE__ */ new Map();
|
|
284
433
|
const shapes = /* @__PURE__ */ new Map();
|
|
@@ -287,60 +436,60 @@ function readModule(source, sibling = () => void 0, { lendFirstComment = true }
|
|
|
287
436
|
const propsTypeOf = (parameters) => parameters[0]?.type;
|
|
288
437
|
const propsOfInitializer = (initializer) => {
|
|
289
438
|
if (!initializer) return void 0;
|
|
290
|
-
if (
|
|
291
|
-
if (
|
|
292
|
-
const callee =
|
|
439
|
+
if (ts3.isArrowFunction(initializer) || ts3.isFunctionExpression(initializer)) return propsTypeOf(initializer.parameters);
|
|
440
|
+
if (ts3.isCallExpression(initializer)) {
|
|
441
|
+
const callee = ts3.isPropertyAccessExpression(initializer.expression) ? initializer.expression.name.text : ts3.isIdentifier(initializer.expression) ? initializer.expression.text : "";
|
|
293
442
|
if (callee === "forwardRef" && initializer.typeArguments?.[1]) return initializer.typeArguments[1];
|
|
294
|
-
const wrapped = initializer.arguments.find((argument) =>
|
|
443
|
+
const wrapped = initializer.arguments.find((argument) => ts3.isArrowFunction(argument) || ts3.isFunctionExpression(argument));
|
|
295
444
|
if (wrapped) return propsTypeOf(wrapped.parameters);
|
|
296
445
|
}
|
|
297
446
|
return void 0;
|
|
298
447
|
};
|
|
299
448
|
const propsOfAnnotation = (type) => {
|
|
300
|
-
if (!type || !
|
|
301
|
-
const named =
|
|
449
|
+
if (!type || !ts3.isTypeReferenceNode(type)) return void 0;
|
|
450
|
+
const named = ts3.isIdentifier(type.typeName) ? type.typeName.text : type.typeName.right.text;
|
|
302
451
|
return named === "FC" || named === "FunctionComponent" ? type.typeArguments?.[0] : void 0;
|
|
303
452
|
};
|
|
304
|
-
const opening = file.statements.find((statement) => !
|
|
305
|
-
const headerPos = opening ? (
|
|
306
|
-
const topPos = file.statements[0] ? (
|
|
307
|
-
const aboveImports = !!file.statements[0] &&
|
|
453
|
+
const opening = file.statements.find((statement) => !ts3.isImportDeclaration(statement));
|
|
454
|
+
const headerPos = opening ? (ts3.getLeadingCommentRanges(source, opening.getFullStart()) ?? []).find((range) => source.slice(range.pos, range.pos + 3) === "/**")?.pos ?? null : null;
|
|
455
|
+
const topPos = file.statements[0] ? (ts3.getLeadingCommentRanges(source, file.statements[0].getFullStart()) ?? []).find((range) => source.slice(range.pos, range.pos + 3) === "/**")?.pos ?? null : null;
|
|
456
|
+
const aboveImports = !!file.statements[0] && ts3.isImportDeclaration(file.statements[0]);
|
|
308
457
|
const refused = lendFirstComment ? topPos ?? headerPos : aboveImports ? topPos : null;
|
|
309
458
|
for (const statement of file.statements) {
|
|
310
|
-
if (
|
|
459
|
+
if (ts3.isImportDeclaration(statement) && ts3.isStringLiteral(statement.moduleSpecifier)) {
|
|
311
460
|
const bindings = statement.importClause?.namedBindings;
|
|
312
|
-
if (bindings &&
|
|
461
|
+
if (bindings && ts3.isNamedImports(bindings)) {
|
|
313
462
|
for (const element of bindings.elements) importedFrom.set(element.name.text, { specifier: statement.moduleSpecifier.text, imported: (element.propertyName ?? element.name).text });
|
|
314
463
|
}
|
|
315
464
|
}
|
|
316
|
-
if (
|
|
465
|
+
if (ts3.isExportDeclaration(statement) && statement.moduleSpecifier && ts3.isStringLiteral(statement.moduleSpecifier) && statement.exportClause && ts3.isNamedExports(statement.exportClause)) {
|
|
317
466
|
for (const element of statement.exportClause.elements) importedFrom.set(element.name.text, { specifier: statement.moduleSpecifier.text, imported: (element.propertyName ?? element.name).text });
|
|
318
467
|
}
|
|
319
|
-
if (
|
|
320
|
-
if (
|
|
468
|
+
if (ts3.isTypeAliasDeclaration(statement)) aliases.set(statement.name.text, statement.type);
|
|
469
|
+
if (ts3.isInterfaceDeclaration(statement)) {
|
|
321
470
|
shapes.set(statement.name.text, [...statement.members]);
|
|
322
471
|
const extended = (statement.heritageClauses ?? []).flatMap((clause) => [...clause.types]);
|
|
323
472
|
if (extended.length) bases.set(statement.name.text, extended);
|
|
324
473
|
}
|
|
325
|
-
if (
|
|
326
|
-
if (
|
|
327
|
-
const base = (statement.heritageClauses ?? []).find((clause) => clause.token ===
|
|
328
|
-
const name = statement.name?.text ?? (
|
|
474
|
+
if (ts3.isTypeAliasDeclaration(statement) && ts3.isTypeLiteralNode(statement.type)) shapes.set(statement.name.text, [...statement.type.members]);
|
|
475
|
+
if (ts3.isClassDeclaration(statement)) {
|
|
476
|
+
const base = (statement.heritageClauses ?? []).find((clause) => clause.token === ts3.SyntaxKind.ExtendsKeyword)?.types[0];
|
|
477
|
+
const name = statement.name?.text ?? (ts3.getModifiers(statement)?.some((m) => m.kind === ts3.SyntaxKind.DefaultKeyword) ? "default" : null);
|
|
329
478
|
if (name) declarations.set(name, { doc: docAbove(source, statement, refused), deprecated: false, propsType: base?.typeArguments?.[0] });
|
|
330
479
|
continue;
|
|
331
480
|
}
|
|
332
|
-
if (
|
|
481
|
+
if (ts3.isExportAssignment(statement) && !statement.isExportEquals && !ts3.isIdentifier(statement.expression)) {
|
|
333
482
|
declarations.set("default", { doc: docAbove(source, statement, refused), deprecated: false, propsType: propsOfInitializer(statement.expression) });
|
|
334
483
|
continue;
|
|
335
484
|
}
|
|
336
|
-
if (
|
|
485
|
+
if (ts3.isFunctionDeclaration(statement) && !statement.name && ts3.getModifiers(statement)?.some((m) => m.kind === ts3.SyntaxKind.DefaultKeyword)) {
|
|
337
486
|
declarations.set("default", { doc: docAbove(source, statement, refused), deprecated: false, propsType: propsTypeOf(statement.parameters) });
|
|
338
487
|
continue;
|
|
339
488
|
}
|
|
340
|
-
if (!
|
|
489
|
+
if (!ts3.isFunctionDeclaration(statement) && !ts3.isVariableStatement(statement)) continue;
|
|
341
490
|
const doc = docAbove(source, statement, refused);
|
|
342
491
|
const deprecated = /(^|\n)@deprecated\b/.test(doc) || /\*\s*@deprecated\b/.test(source.slice(Math.max(0, statement.getFullStart()), statement.getStart()));
|
|
343
|
-
if (
|
|
492
|
+
if (ts3.isFunctionDeclaration(statement) && statement.name) {
|
|
344
493
|
const held = declarations.get(statement.name.text);
|
|
345
494
|
if (held) {
|
|
346
495
|
if (!held.doc && doc) held.doc = doc;
|
|
@@ -349,9 +498,9 @@ function readModule(source, sibling = () => void 0, { lendFirstComment = true }
|
|
|
349
498
|
declarations.set(statement.name.text, { doc, deprecated, propsType: propsTypeOf(statement.parameters) });
|
|
350
499
|
continue;
|
|
351
500
|
}
|
|
352
|
-
if (
|
|
501
|
+
if (ts3.isVariableStatement(statement)) {
|
|
353
502
|
for (const declaration of statement.declarationList.declarations) {
|
|
354
|
-
if (!
|
|
503
|
+
if (!ts3.isIdentifier(declaration.name)) continue;
|
|
355
504
|
declarations.set(declaration.name.text, { doc, deprecated, propsType: propsOfInitializer(declaration.initializer) ?? propsOfAnnotation(declaration.type) });
|
|
356
505
|
}
|
|
357
506
|
}
|
|
@@ -359,11 +508,11 @@ function readModule(source, sibling = () => void 0, { lendFirstComment = true }
|
|
|
359
508
|
const EMPTY = { props: [], variants: [] };
|
|
360
509
|
const keysOf = (type) => {
|
|
361
510
|
if (!type) return null;
|
|
362
|
-
if (
|
|
363
|
-
if (!
|
|
511
|
+
if (ts3.isLiteralTypeNode(type) && ts3.isStringLiteral(type.literal)) return [type.literal.text];
|
|
512
|
+
if (!ts3.isUnionTypeNode(type)) return null;
|
|
364
513
|
const keys = [];
|
|
365
514
|
for (const member of type.types) {
|
|
366
|
-
if (!
|
|
515
|
+
if (!ts3.isLiteralTypeNode(member) || !ts3.isStringLiteral(member.literal)) return null;
|
|
367
516
|
keys.push(member.literal.text);
|
|
368
517
|
}
|
|
369
518
|
return keys;
|
|
@@ -401,7 +550,7 @@ function readModule(source, sibling = () => void 0, { lendFirstComment = true }
|
|
|
401
550
|
const variants = [];
|
|
402
551
|
for (const member of members) {
|
|
403
552
|
const name = propName(member);
|
|
404
|
-
if (name === null || !
|
|
553
|
+
if (name === null || !ts3.isPropertySignature(member)) continue;
|
|
405
554
|
const values = literalUnion(member.type, aliases);
|
|
406
555
|
const note = firstSentence(docAbove(source, member));
|
|
407
556
|
props.push({ name, takes: takes(member.type, values), required: !member.questionToken, note: note || null });
|
|
@@ -411,9 +560,9 @@ function readModule(source, sibling = () => void 0, { lendFirstComment = true }
|
|
|
411
560
|
};
|
|
412
561
|
const resolveNode = (type, seen) => {
|
|
413
562
|
if (!type || seen.size > 12) return EMPTY;
|
|
414
|
-
if (
|
|
415
|
-
if (
|
|
416
|
-
if (
|
|
563
|
+
if (ts3.isTypeLiteralNode(type)) return fromMembers(type.members);
|
|
564
|
+
if (ts3.isIntersectionTypeNode(type)) return merge(type.types.map((side) => resolveNode(side, seen)));
|
|
565
|
+
if (ts3.isTypeReferenceNode(type) && ts3.isIdentifier(type.typeName)) {
|
|
417
566
|
const named = type.typeName.text;
|
|
418
567
|
if (named === "Omit" || named === "Pick") {
|
|
419
568
|
return narrow(resolveNode(type.typeArguments?.[0], seen), named, keysOf(type.typeArguments?.[1]));
|
|
@@ -423,7 +572,7 @@ function readModule(source, sibling = () => void 0, { lendFirstComment = true }
|
|
|
423
572
|
return EMPTY;
|
|
424
573
|
};
|
|
425
574
|
const resolveBase = (base, seen) => {
|
|
426
|
-
if (!
|
|
575
|
+
if (!ts3.isIdentifier(base.expression)) return EMPTY;
|
|
427
576
|
const named = base.expression.text;
|
|
428
577
|
if (named === "Omit" || named === "Pick") {
|
|
429
578
|
return narrow(resolveNode(base.typeArguments?.[0], seen), named, keysOf(base.typeArguments?.[1]));
|
|
@@ -444,7 +593,7 @@ function readModule(source, sibling = () => void 0, { lendFirstComment = true }
|
|
|
444
593
|
return (from ? sibling(from.specifier, from.imported) : void 0) ?? EMPTY;
|
|
445
594
|
}
|
|
446
595
|
const resolve = (propsType) => resolveNode(propsType, /* @__PURE__ */ new Set());
|
|
447
|
-
const jsdocAt = (node) => node ? (
|
|
596
|
+
const jsdocAt = (node) => node ? (ts3.getLeadingCommentRanges(source, node.getFullStart()) ?? []).find((range) => source.slice(range.pos, range.pos + 3) === "/**") : void 0;
|
|
448
597
|
const headerRange = jsdocAt(file.statements[0]) ?? jsdocAt(opening);
|
|
449
598
|
return { declarations, headerDoc: headerRange ? headerComment(source, headerRange) : "", resolve, resolveName: (name) => resolveName(name, /* @__PURE__ */ new Set()) };
|
|
450
599
|
}
|
|
@@ -452,23 +601,23 @@ function headerComment(source, range) {
|
|
|
452
601
|
return source.slice(range.pos, range.end).split(/\r?\n/).map((line) => line.trim().replace(/^\/\*\*/, "").replace(/\*\/$/, "").replace(/^\*/, "").trim()).join("\n").trim();
|
|
453
602
|
}
|
|
454
603
|
function readStories(source) {
|
|
455
|
-
const file =
|
|
604
|
+
const file = ts3.createSourceFile("x.stories.tsx", source, ts3.ScriptTarget.Latest, true);
|
|
456
605
|
let title = null;
|
|
457
606
|
const stories = [];
|
|
458
607
|
for (const statement of file.statements) {
|
|
459
|
-
if (
|
|
608
|
+
if (ts3.isVariableStatement(statement)) {
|
|
460
609
|
for (const declaration of statement.declarationList.declarations) {
|
|
461
|
-
if (!
|
|
610
|
+
if (!ts3.isIdentifier(declaration.name)) continue;
|
|
462
611
|
const initializer = declaration.initializer;
|
|
463
|
-
const object = initializer &&
|
|
464
|
-
if (declaration.name.text === "meta" && object &&
|
|
612
|
+
const object = initializer && ts3.isSatisfiesExpression(initializer) ? initializer.expression : initializer;
|
|
613
|
+
if (declaration.name.text === "meta" && object && ts3.isObjectLiteralExpression(object)) {
|
|
465
614
|
for (const property of object.properties) {
|
|
466
|
-
if (
|
|
615
|
+
if (ts3.isPropertyAssignment(property) && ts3.isIdentifier(property.name) && property.name.text === "title" && ts3.isStringLiteral(property.initializer)) {
|
|
467
616
|
title = property.initializer.text;
|
|
468
617
|
}
|
|
469
618
|
}
|
|
470
619
|
}
|
|
471
|
-
const exported =
|
|
620
|
+
const exported = ts3.getModifiers(statement)?.some((m) => m.kind === ts3.SyntaxKind.ExportKeyword);
|
|
472
621
|
if (exported && declaration.name.text !== "meta") stories.push(declaration.name.text);
|
|
473
622
|
}
|
|
474
623
|
}
|
|
@@ -481,7 +630,7 @@ function kindOf(name) {
|
|
|
481
630
|
return /^[A-Z]/.test(name) && !isAllCaps(name) ? "component" : "helper";
|
|
482
631
|
}
|
|
483
632
|
function behavioursOf(name) {
|
|
484
|
-
return
|
|
633
|
+
return OWNED_BEHAVIOURS2.filter((owned) => owned.owners.includes(name)).map((owned) => ({ id: owned.id, behaviour: owned.behaviour }));
|
|
485
634
|
}
|
|
486
635
|
function buildRegistry({ root = process.cwd(), repo = "estiva-ui" } = {}) {
|
|
487
636
|
const src = join2(root, "src");
|
|
@@ -548,6 +697,36 @@ function buildRegistry({ root = process.cwd(), repo = "estiva-ui" } = {}) {
|
|
|
548
697
|
}
|
|
549
698
|
if (problems.length) throw new Error(`the registry cannot be built:
|
|
550
699
|
${problems.join("\n ")}`);
|
|
700
|
+
const moduleByName = new Map(values.map((v) => [v.name, v.module]));
|
|
701
|
+
const drawing = /* @__PURE__ */ new Map();
|
|
702
|
+
const drawingOf = (moduleName) => {
|
|
703
|
+
if (!drawing.has(moduleName)) {
|
|
704
|
+
const file = moduleOf(moduleName).file;
|
|
705
|
+
const sf = ts3.createSourceFile(file, readFileSync2(join2(root, file), "utf8"), ts3.ScriptTarget.Latest, true, file.endsWith("x") ? ts3.ScriptKind.TSX : ts3.ScriptKind.TS);
|
|
706
|
+
drawing.set(moduleName, { drawn: drawnIn(sf), roots: rootsIn(sf), imports: importsOf(sf) });
|
|
707
|
+
}
|
|
708
|
+
return drawing.get(moduleName);
|
|
709
|
+
};
|
|
710
|
+
const owns = (name, seen) => {
|
|
711
|
+
const out = new Set(behavioursOf(name).map((b) => b.id));
|
|
712
|
+
const moduleName = moduleByName.get(name);
|
|
713
|
+
if (!moduleName || seen.has(name)) return out;
|
|
714
|
+
seen.add(name);
|
|
715
|
+
const { drawn, roots, imports } = drawingOf(moduleName);
|
|
716
|
+
for (const tag of drawn.get(name) ?? []) {
|
|
717
|
+
const [local, piece] = splitTag(tag);
|
|
718
|
+
const from = imports.get(local);
|
|
719
|
+
if (from && isBaseUi(from.specifier)) for (const id of baseUiBehaviours(from.imported, piece)) out.add(id);
|
|
720
|
+
}
|
|
721
|
+
for (const tag of roots.get(name) ?? []) {
|
|
722
|
+
const [local] = splitTag(tag);
|
|
723
|
+
const from = imports.get(local);
|
|
724
|
+
const part = from?.specifier.startsWith("./") ? from.imported : !from && local !== name ? local : void 0;
|
|
725
|
+
if (part && moduleByName.has(part)) for (const id of handedOn(part, owns(part, seen))) out.add(id);
|
|
726
|
+
}
|
|
727
|
+
return out;
|
|
728
|
+
};
|
|
729
|
+
for (const entry of entries) if (entry.kind === "component") entry.ownsBehaviours = asBehaviours(owns(entry.name, /* @__PURE__ */ new Set()));
|
|
551
730
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
552
731
|
return {
|
|
553
732
|
schemaVersion: SCHEMA_VERSION,
|
|
@@ -579,6 +758,13 @@ function serializeRegistry(registry) {
|
|
|
579
758
|
}
|
|
580
759
|
|
|
581
760
|
export {
|
|
761
|
+
isBaseUi,
|
|
762
|
+
baseUiBehaviours,
|
|
763
|
+
handedOn,
|
|
764
|
+
asBehaviours,
|
|
765
|
+
splitTag,
|
|
766
|
+
drawnIn,
|
|
767
|
+
rootsIn,
|
|
582
768
|
looksOf,
|
|
583
769
|
parseForLooks,
|
|
584
770
|
PACKAGE_IMPORT,
|
|
@@ -592,4 +778,4 @@ export {
|
|
|
592
778
|
buildRegistry,
|
|
593
779
|
serializeRegistry
|
|
594
780
|
};
|
|
595
|
-
//# sourceMappingURL=chunk-
|
|
781
|
+
//# sourceMappingURL=chunk-SIB44CES.js.map
|