tempo-sdk 0.0.18 → 0.0.20
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 +32 -2
- package/dist/assets/editor.d.ts +79 -0
- package/dist/assets/editor.js +571 -0
- package/dist/assets/editor.js.map +1 -0
- package/dist/assets/index.d.ts +83 -0
- package/dist/assets/index.js +26 -0
- package/dist/assets/index.js.map +1 -0
- package/dist/assets/parser.d.ts +78 -0
- package/dist/assets/parser.js +29 -0
- package/dist/assets/parser.js.map +1 -0
- package/dist/canvas/editor.js +1 -1
- package/dist/canvas/index.d.ts +99 -16
- package/dist/canvas/index.js +1427 -661
- package/dist/canvas/index.js.map +1 -1
- package/dist/canvas/interact-projection.d.ts +8 -0
- package/dist/canvas/interact-projection.js +2848 -0
- package/dist/canvas/interact-projection.js.map +1 -0
- package/dist/canvas/parser.d.ts +25 -1
- package/dist/canvas/parser.js +3 -1
- package/dist/{chunk-6Q4I3RFN.js → chunk-GBKYTBEE.js} +242 -33
- package/dist/chunk-GBKYTBEE.js.map +1 -0
- package/dist/chunk-IWULHYPW.js +650 -0
- package/dist/chunk-IWULHYPW.js.map +1 -0
- package/dist/chunk-QXB32HG4.js +11 -0
- package/dist/chunk-QXB32HG4.js.map +1 -0
- package/dist/index.d.ts +8 -3
- package/dist/index.js +601 -20
- package/dist/index.js.map +1 -1
- package/dist/types-B-dRoF2T.d.ts +102 -0
- package/package.json +19 -2
- package/dist/chunk-6Q4I3RFN.js.map +0 -1
package/dist/canvas/parser.d.ts
CHANGED
|
@@ -5,6 +5,11 @@ type CanvasSourceSpan = {
|
|
|
5
5
|
type CanvasParseError = {
|
|
6
6
|
message: string;
|
|
7
7
|
span?: CanvasSourceSpan;
|
|
8
|
+
/** "structural": the file's storyboard identity/structure cannot be
|
|
9
|
+
* trusted — readers must fail closed. "degraded": a single storyboard
|
|
10
|
+
* (or the canvas display name) is not statically readable/editable but
|
|
11
|
+
* identity is intact — readers keep working with fallback values. */
|
|
12
|
+
kind: "structural" | "degraded";
|
|
8
13
|
};
|
|
9
14
|
type ParsedCanvasImport = {
|
|
10
15
|
localName: string;
|
|
@@ -19,6 +24,23 @@ type ParsedCanvasImport = {
|
|
|
19
24
|
hasDefaultSpecifier: boolean;
|
|
20
25
|
hasNamespaceSpecifier: boolean;
|
|
21
26
|
};
|
|
27
|
+
/** An import statement that names Tempo SDK canvas components but uses the
|
|
28
|
+
* wrong tempo-sdk specifier (e.g. `import { Canvas } from "tempo-sdk"`).
|
|
29
|
+
* Neither the main entry nor the other subpaths export the components, so
|
|
30
|
+
* the file both fails at runtime and is invisible to this parser's <Canvas>
|
|
31
|
+
* detection — migrate-on-read uses these records to repair the specifier. */
|
|
32
|
+
type MisimportedSdkCanvasImport = {
|
|
33
|
+
/** Import source exactly as written, e.g. "tempo-sdk". */
|
|
34
|
+
source: string;
|
|
35
|
+
/** Span of the source string literal INCLUDING its quote characters. */
|
|
36
|
+
sourceSpan: CanvasSourceSpan;
|
|
37
|
+
/** Imported names of every value specifier on the statement. */
|
|
38
|
+
importedNames: string[];
|
|
39
|
+
/** True when every value specifier on the statement is a named import of a
|
|
40
|
+
* value actually exported by "tempo-sdk/canvas" — rewriting the source
|
|
41
|
+
* string to "tempo-sdk/canvas" provably fixes the statement. */
|
|
42
|
+
rewritable: boolean;
|
|
43
|
+
};
|
|
22
44
|
type ParsedCanvasLayout = {
|
|
23
45
|
x: number;
|
|
24
46
|
y: number;
|
|
@@ -98,11 +120,13 @@ type ParsedCanvasFile = {
|
|
|
98
120
|
backgroundColorSpan?: CanvasSourceSpan;
|
|
99
121
|
backgroundColorAttributeSpan?: CanvasSourceSpan;
|
|
100
122
|
imports: ParsedCanvasImport[];
|
|
123
|
+
misimportedSdkCanvasImports: MisimportedSdkCanvasImport[];
|
|
101
124
|
storyboards: ParsedCanvasStoryboard[];
|
|
102
125
|
errors: CanvasParseError[];
|
|
103
126
|
};
|
|
104
127
|
declare function parseCanvasFile(filePath: string, source: string): ParsedCanvasFile;
|
|
128
|
+
declare function misimportedSdkCanvasImportMessage(entry: MisimportedSdkCanvasImport): string;
|
|
105
129
|
declare function unwrapTsExpression(node: any): any;
|
|
106
130
|
declare function fallbackPageName(filePath: string): string;
|
|
107
131
|
|
|
108
|
-
export { type CanvasParseError, type CanvasSourceSpan, type ParsedCanvasComponentReference, type ParsedCanvasExpressionReference, type ParsedCanvasFile, type ParsedCanvasImport, type ParsedCanvasLayout, type ParsedCanvasLayoutSpans, type ParsedCanvasStoryboard, fallbackPageName, parseCanvasFile, unwrapTsExpression };
|
|
132
|
+
export { type CanvasParseError, type CanvasSourceSpan, type MisimportedSdkCanvasImport, type ParsedCanvasComponentReference, type ParsedCanvasExpressionReference, type ParsedCanvasFile, type ParsedCanvasImport, type ParsedCanvasLayout, type ParsedCanvasLayoutSpans, type ParsedCanvasStoryboard, fallbackPageName, misimportedSdkCanvasImportMessage, parseCanvasFile, unwrapTsExpression };
|
package/dist/canvas/parser.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
fallbackPageName,
|
|
3
|
+
misimportedSdkCanvasImportMessage,
|
|
3
4
|
parseCanvasFile,
|
|
4
5
|
unwrapTsExpression
|
|
5
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-GBKYTBEE.js";
|
|
6
7
|
export {
|
|
7
8
|
fallbackPageName,
|
|
9
|
+
misimportedSdkCanvasImportMessage,
|
|
8
10
|
parseCanvasFile,
|
|
9
11
|
unwrapTsExpression
|
|
10
12
|
};
|
|
@@ -8,6 +8,29 @@ var SDK_COMPONENTS = /* @__PURE__ */ new Set([
|
|
|
8
8
|
"RouteStoryboard",
|
|
9
9
|
"HtmlStoryboard"
|
|
10
10
|
]);
|
|
11
|
+
var SDK_CANVAS_VALUE_EXPORTS = /* @__PURE__ */ new Set([
|
|
12
|
+
"Canvas",
|
|
13
|
+
"CanvasContext",
|
|
14
|
+
"getCanvasStoryboardRenderId",
|
|
15
|
+
"CanvasHost",
|
|
16
|
+
"buildRenderContentFiberSelector",
|
|
17
|
+
"buildRenderContentSelector",
|
|
18
|
+
"buildRenderSelector",
|
|
19
|
+
"captureStoryboardCombined",
|
|
20
|
+
"captureStoryboardHtml",
|
|
21
|
+
"captureStoryboardImage",
|
|
22
|
+
"stripRenderContentWrapperAttributes",
|
|
23
|
+
"stripRenderContentWrapperFromCombinedCapture",
|
|
24
|
+
"watchStoryboardCombined",
|
|
25
|
+
"getCanvasHostRuntime",
|
|
26
|
+
"getOptionalCanvasHostRuntime",
|
|
27
|
+
"useActiveState",
|
|
28
|
+
"HtmlStoryboard",
|
|
29
|
+
"LegacyStoryboardV1",
|
|
30
|
+
"RouteStoryboard",
|
|
31
|
+
"Storyboard",
|
|
32
|
+
"StoryboardSlot"
|
|
33
|
+
]);
|
|
11
34
|
var DEFAULT_LAYOUT = {
|
|
12
35
|
x: 0,
|
|
13
36
|
y: 0,
|
|
@@ -23,7 +46,8 @@ function parseCanvasFile(filePath, source) {
|
|
|
23
46
|
for (const error of result.errors ?? []) {
|
|
24
47
|
errors.push({
|
|
25
48
|
message: error.message ?? "Unable to parse canvas source",
|
|
26
|
-
span: toSpan(error) ?? toSpan(error?.labels?.[0])
|
|
49
|
+
span: toSpan(error) ?? toSpan(error?.labels?.[0]),
|
|
50
|
+
kind: "structural"
|
|
27
51
|
});
|
|
28
52
|
}
|
|
29
53
|
} catch (error) {
|
|
@@ -31,33 +55,86 @@ function parseCanvasFile(filePath, source) {
|
|
|
31
55
|
filePath,
|
|
32
56
|
pageName: fallbackPageName(filePath),
|
|
33
57
|
imports: [],
|
|
58
|
+
misimportedSdkCanvasImports: [],
|
|
34
59
|
storyboards: [],
|
|
35
60
|
errors: [
|
|
36
61
|
{
|
|
37
|
-
message: error instanceof Error ? error.message : "Unable to parse canvas source"
|
|
62
|
+
message: error instanceof Error ? error.message : "Unable to parse canvas source",
|
|
63
|
+
kind: "structural"
|
|
38
64
|
}
|
|
39
65
|
]
|
|
40
66
|
};
|
|
41
67
|
}
|
|
42
68
|
const imports = readImports(program);
|
|
69
|
+
const misimportedSdkCanvasImports = readMisimportedSdkCanvasImports(program);
|
|
43
70
|
const { legacyObjects, stringBindings: objectStringBindings } = readObjectExpressionBindings(program, imports, source);
|
|
44
|
-
const storyboards = [];
|
|
45
71
|
let canvasElement = null;
|
|
72
|
+
const allStoryboardElements = [];
|
|
46
73
|
walk(program, (node) => {
|
|
47
74
|
if (node.type !== "JSXElement") return;
|
|
48
75
|
const component = resolveSdkComponent(node.openingElement?.name, imports);
|
|
49
|
-
|
|
50
|
-
|
|
76
|
+
const namespaceMisimport = resolveMisimportedNamespaceSdkComponent(
|
|
77
|
+
node.openingElement?.name,
|
|
78
|
+
imports,
|
|
79
|
+
misimportedSdkCanvasImports
|
|
80
|
+
);
|
|
81
|
+
if (namespaceMisimport) {
|
|
82
|
+
misimportedSdkCanvasImports.add(namespaceMisimport);
|
|
83
|
+
}
|
|
84
|
+
if (component === "Canvas") {
|
|
85
|
+
if (!canvasElement) {
|
|
86
|
+
canvasElement = node;
|
|
87
|
+
} else {
|
|
88
|
+
errors.push({
|
|
89
|
+
message: "Canvas file must declare exactly one <Canvas> element",
|
|
90
|
+
span: toSpan(node),
|
|
91
|
+
kind: "structural"
|
|
92
|
+
});
|
|
93
|
+
}
|
|
51
94
|
return;
|
|
52
95
|
}
|
|
53
|
-
if (component
|
|
54
|
-
|
|
55
|
-
readStoryboard(node, component, imports, legacyObjects, source, errors)
|
|
56
|
-
);
|
|
96
|
+
if (isStoryboardSdkComponent(component)) {
|
|
97
|
+
allStoryboardElements.push({ element: node, component });
|
|
57
98
|
}
|
|
58
99
|
});
|
|
100
|
+
const directStoryboardElements = canvasElement ? readDirectCanvasStoryboardElements(canvasElement, imports) : [];
|
|
101
|
+
const directStoryboardElementSet = new Set(
|
|
102
|
+
directStoryboardElements.map((item) => item.element)
|
|
103
|
+
);
|
|
104
|
+
const storyboards = directStoryboardElements.map(
|
|
105
|
+
(item) => readStoryboard(
|
|
106
|
+
item.element,
|
|
107
|
+
item.component,
|
|
108
|
+
imports,
|
|
109
|
+
legacyObjects,
|
|
110
|
+
source,
|
|
111
|
+
errors
|
|
112
|
+
)
|
|
113
|
+
);
|
|
114
|
+
for (const item of allStoryboardElements) {
|
|
115
|
+
if (directStoryboardElementSet.has(item.element)) continue;
|
|
116
|
+
errors.push({
|
|
117
|
+
message: `<${item.component}> declarations must be direct children of the <Canvas> element`,
|
|
118
|
+
span: toSpan(item.element),
|
|
119
|
+
kind: "structural"
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
reportDuplicateStoryboardIds(storyboards, errors);
|
|
59
123
|
if (!canvasElement) {
|
|
60
|
-
|
|
124
|
+
if (misimportedSdkCanvasImports.all.length > 0) {
|
|
125
|
+
for (const entry of misimportedSdkCanvasImports.all) {
|
|
126
|
+
errors.push({
|
|
127
|
+
message: misimportedSdkCanvasImportMessage(entry),
|
|
128
|
+
span: entry.sourceSpan,
|
|
129
|
+
kind: "structural"
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
errors.push({
|
|
134
|
+
message: "No <Canvas> declaration found in canvas file",
|
|
135
|
+
kind: "structural"
|
|
136
|
+
});
|
|
137
|
+
}
|
|
61
138
|
} else {
|
|
62
139
|
errors.push(...validateCanvasChildren(canvasElement, imports));
|
|
63
140
|
}
|
|
@@ -80,7 +157,8 @@ function parseCanvasFile(filePath, source) {
|
|
|
80
157
|
if (openingElement && !name) {
|
|
81
158
|
errors.push({
|
|
82
159
|
message: '<Canvas> must include a literal "name" prop',
|
|
83
|
-
span: toSpan(openingElement)
|
|
160
|
+
span: toSpan(openingElement),
|
|
161
|
+
kind: "degraded"
|
|
84
162
|
});
|
|
85
163
|
}
|
|
86
164
|
return {
|
|
@@ -98,10 +176,59 @@ function parseCanvasFile(filePath, source) {
|
|
|
98
176
|
backgroundColorSpan: backgroundColor?.valueSpan,
|
|
99
177
|
backgroundColorAttributeSpan: backgroundColor?.attributeSpan,
|
|
100
178
|
imports: imports.all,
|
|
179
|
+
misimportedSdkCanvasImports: misimportedSdkCanvasImports.all,
|
|
101
180
|
storyboards,
|
|
102
181
|
errors
|
|
103
182
|
};
|
|
104
183
|
}
|
|
184
|
+
function misimportedSdkCanvasImportMessage(entry) {
|
|
185
|
+
return `Tempo canvas components must be imported from "tempo-sdk/canvas" \u2014 found import of ${entry.importedNames.join(", ")} from "${entry.source}"`;
|
|
186
|
+
}
|
|
187
|
+
function readMisimportedSdkCanvasImports(program) {
|
|
188
|
+
const all = [];
|
|
189
|
+
const byDeclarationKey = /* @__PURE__ */ new Map();
|
|
190
|
+
const namespaceCandidatesByLocalName = /* @__PURE__ */ new Map();
|
|
191
|
+
const add = (entry) => {
|
|
192
|
+
const key = spanKey(entry.sourceSpan);
|
|
193
|
+
if (byDeclarationKey.has(key)) return;
|
|
194
|
+
byDeclarationKey.set(key, entry);
|
|
195
|
+
all.push(entry);
|
|
196
|
+
};
|
|
197
|
+
for (const statement of program?.body ?? []) {
|
|
198
|
+
if (statement?.type !== "ImportDeclaration" || typeof statement.source?.value !== "string" || !isWrongTempoSdkCanvasImportSource(statement.source.value) || statement.importKind === "type") {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
const source = statement.source.value;
|
|
202
|
+
const sourceSpan = toSpan(statement.source);
|
|
203
|
+
if (!sourceSpan) continue;
|
|
204
|
+
const valueSpecifiers = (statement.specifiers ?? []).filter(
|
|
205
|
+
(specifier) => specifier?.importKind !== "type"
|
|
206
|
+
);
|
|
207
|
+
const importedNames = valueSpecifiers.map(readImportedName);
|
|
208
|
+
const entry = {
|
|
209
|
+
source,
|
|
210
|
+
sourceSpan,
|
|
211
|
+
importedNames,
|
|
212
|
+
rewritable: valueSpecifiers.length > 0 && valueSpecifiers.every(
|
|
213
|
+
(specifier) => specifier?.type === "ImportSpecifier" && SDK_CANVAS_VALUE_EXPORTS.has(readImportedName(specifier))
|
|
214
|
+
)
|
|
215
|
+
};
|
|
216
|
+
const hasMisimportedNamedSdkComponent = valueSpecifiers.some(
|
|
217
|
+
(specifier) => specifier?.type === "ImportSpecifier" && SDK_COMPONENTS.has(readImportedName(specifier))
|
|
218
|
+
);
|
|
219
|
+
if (hasMisimportedNamedSdkComponent) {
|
|
220
|
+
add(entry);
|
|
221
|
+
}
|
|
222
|
+
for (const specifier of valueSpecifiers) {
|
|
223
|
+
if (specifier?.type !== "ImportNamespaceSpecifier") continue;
|
|
224
|
+
const localName = specifier.local?.name;
|
|
225
|
+
if (typeof localName === "string") {
|
|
226
|
+
namespaceCandidatesByLocalName.set(localName, entry);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return { all, byDeclarationKey, namespaceCandidatesByLocalName, add };
|
|
231
|
+
}
|
|
105
232
|
function readImports(program) {
|
|
106
233
|
const all = [];
|
|
107
234
|
const byLocalName = /* @__PURE__ */ new Map();
|
|
@@ -153,24 +280,38 @@ function readImports(program) {
|
|
|
153
280
|
function readObjectExpressionBindings(program, imports, source) {
|
|
154
281
|
const legacyObjects = /* @__PURE__ */ new Map();
|
|
155
282
|
const stringBindings = /* @__PURE__ */ new Map();
|
|
156
|
-
|
|
157
|
-
if (node
|
|
158
|
-
|
|
283
|
+
for (const node of readTopLevelVariableDeclarators(program)) {
|
|
284
|
+
if (node.id?.type !== "Identifier") {
|
|
285
|
+
continue;
|
|
159
286
|
}
|
|
160
287
|
const objectExpression = unwrapTsExpression(node.init);
|
|
161
|
-
if (objectExpression?.type !== "ObjectExpression")
|
|
288
|
+
if (objectExpression?.type !== "ObjectExpression") continue;
|
|
162
289
|
const bindingName = node.id.name;
|
|
163
290
|
legacyObjects.set(
|
|
164
291
|
bindingName,
|
|
165
|
-
readLegacyStoryboardObject(
|
|
292
|
+
readLegacyStoryboardObject(
|
|
293
|
+
bindingName,
|
|
294
|
+
objectExpression,
|
|
295
|
+
imports,
|
|
296
|
+
source
|
|
297
|
+
)
|
|
166
298
|
);
|
|
167
299
|
const stringProperties = readObjectStringProperties(objectExpression);
|
|
168
300
|
if (stringProperties.size > 0) {
|
|
169
301
|
stringBindings.set(bindingName, stringProperties);
|
|
170
302
|
}
|
|
171
|
-
}
|
|
303
|
+
}
|
|
172
304
|
return { legacyObjects, stringBindings };
|
|
173
305
|
}
|
|
306
|
+
function readTopLevelVariableDeclarators(program) {
|
|
307
|
+
const declarators = [];
|
|
308
|
+
for (const statement of program?.body ?? []) {
|
|
309
|
+
const declaration = statement?.type === "VariableDeclaration" ? statement : statement?.type === "ExportNamedDeclaration" && statement.declaration?.type === "VariableDeclaration" ? statement.declaration : null;
|
|
310
|
+
if (!declaration) continue;
|
|
311
|
+
declarators.push(...declaration.declarations ?? []);
|
|
312
|
+
}
|
|
313
|
+
return declarators;
|
|
314
|
+
}
|
|
174
315
|
function readLegacyStoryboardObject(bindingName, objectExpression, imports, source) {
|
|
175
316
|
const errors = [];
|
|
176
317
|
const nameProperty = getObjectProperty(objectExpression, "name");
|
|
@@ -181,7 +322,8 @@ function readLegacyStoryboardObject(bindingName, objectExpression, imports, sour
|
|
|
181
322
|
errors: [
|
|
182
323
|
{
|
|
183
324
|
message: '<LegacyStoryboardV1> storyboard object must include a literal "layout" object',
|
|
184
|
-
span: toSpan(objectExpression)
|
|
325
|
+
span: toSpan(objectExpression),
|
|
326
|
+
kind: "degraded"
|
|
185
327
|
}
|
|
186
328
|
]
|
|
187
329
|
};
|
|
@@ -194,7 +336,8 @@ function readLegacyStoryboardObject(bindingName, objectExpression, imports, sour
|
|
|
194
336
|
if (nameProperty && !name) {
|
|
195
337
|
errors.push({
|
|
196
338
|
message: "<LegacyStoryboardV1> storyboard.name must be a string literal when set",
|
|
197
|
-
span: toSpan(nameProperty)
|
|
339
|
+
span: toSpan(nameProperty),
|
|
340
|
+
kind: "degraded"
|
|
198
341
|
});
|
|
199
342
|
}
|
|
200
343
|
errors.push(...layout.errors);
|
|
@@ -237,12 +380,14 @@ function readStoryboard(element, component, imports, legacyObjects, source, glob
|
|
|
237
380
|
errors: legacyObject?.errors ?? (legacyReference ? [
|
|
238
381
|
{
|
|
239
382
|
message: "<LegacyStoryboardV1> storyboard prop must reference a same-file object literal",
|
|
240
|
-
span: legacyReference.span
|
|
383
|
+
span: legacyReference.span,
|
|
384
|
+
kind: "degraded"
|
|
241
385
|
}
|
|
242
386
|
] : [
|
|
243
387
|
{
|
|
244
388
|
message: '<LegacyStoryboardV1> must include a "storyboard" expression prop',
|
|
245
|
-
span: toSpan(openingElement)
|
|
389
|
+
span: toSpan(openingElement),
|
|
390
|
+
kind: "degraded"
|
|
246
391
|
}
|
|
247
392
|
])
|
|
248
393
|
} : readLayout(openingElement, component);
|
|
@@ -250,7 +395,8 @@ function readStoryboard(element, component, imports, legacyObjects, source, glob
|
|
|
250
395
|
if (!id) {
|
|
251
396
|
errors.push({
|
|
252
397
|
message: `<${component}> must include a literal "id" prop`,
|
|
253
|
-
span: toSpan(openingElement)
|
|
398
|
+
span: toSpan(openingElement),
|
|
399
|
+
kind: "structural"
|
|
254
400
|
});
|
|
255
401
|
}
|
|
256
402
|
if (layout.errors.length > 0) {
|
|
@@ -293,7 +439,8 @@ function readStoryboard(element, component, imports, legacyObjects, source, glob
|
|
|
293
439
|
} else {
|
|
294
440
|
errors.push({
|
|
295
441
|
message: '<Storyboard> must include a "component" expression prop',
|
|
296
|
-
span: toSpan(openingElement)
|
|
442
|
+
span: toSpan(openingElement),
|
|
443
|
+
kind: "degraded"
|
|
297
444
|
});
|
|
298
445
|
}
|
|
299
446
|
}
|
|
@@ -306,7 +453,8 @@ function readStoryboard(element, component, imports, legacyObjects, source, glob
|
|
|
306
453
|
} else {
|
|
307
454
|
errors.push({
|
|
308
455
|
message: '<RouteStoryboard> must include a literal "route" prop',
|
|
309
|
-
span: toSpan(openingElement)
|
|
456
|
+
span: toSpan(openingElement),
|
|
457
|
+
kind: "degraded"
|
|
310
458
|
});
|
|
311
459
|
}
|
|
312
460
|
}
|
|
@@ -322,13 +470,45 @@ function readStoryboard(element, component, imports, legacyObjects, source, glob
|
|
|
322
470
|
if (!filepath && !src) {
|
|
323
471
|
errors.push({
|
|
324
472
|
message: '<HtmlStoryboard> must include a literal "filepath" or "src" prop',
|
|
325
|
-
span: toSpan(openingElement)
|
|
473
|
+
span: toSpan(openingElement),
|
|
474
|
+
kind: "degraded"
|
|
326
475
|
});
|
|
327
476
|
}
|
|
328
477
|
}
|
|
329
478
|
globalErrors.push(...errors);
|
|
330
479
|
return storyboard;
|
|
331
480
|
}
|
|
481
|
+
function readDirectCanvasStoryboardElements(canvasElement, imports) {
|
|
482
|
+
const elements = [];
|
|
483
|
+
for (const child of canvasElement.children ?? []) {
|
|
484
|
+
if (child?.type !== "JSXElement") continue;
|
|
485
|
+
const component = resolveSdkComponent(child.openingElement?.name, imports);
|
|
486
|
+
if (isStoryboardSdkComponent(component)) {
|
|
487
|
+
elements.push({ element: child, component });
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
return elements;
|
|
491
|
+
}
|
|
492
|
+
function reportDuplicateStoryboardIds(storyboards, errors) {
|
|
493
|
+
const byId = /* @__PURE__ */ new Map();
|
|
494
|
+
for (const storyboard of storyboards) {
|
|
495
|
+
if (!storyboard.storyboardKey) continue;
|
|
496
|
+
const matching = byId.get(storyboard.storyboardKey);
|
|
497
|
+
if (matching) {
|
|
498
|
+
matching.push(storyboard);
|
|
499
|
+
} else {
|
|
500
|
+
byId.set(storyboard.storyboardKey, [storyboard]);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
for (const [storyboardKey, matching] of byId) {
|
|
504
|
+
if (matching.length < 2) continue;
|
|
505
|
+
errors.push({
|
|
506
|
+
message: `Duplicate storyboard id "${storyboardKey}" (${matching.length} declarations) \u2014 storyboard ids must be unique`,
|
|
507
|
+
span: matching[1]?.jsxElementSpan,
|
|
508
|
+
kind: "structural"
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
}
|
|
332
512
|
function validateCanvasChildren(canvasElement, imports) {
|
|
333
513
|
const errors = [];
|
|
334
514
|
for (const child of canvasElement.children ?? []) {
|
|
@@ -344,7 +524,8 @@ function validateCanvasChildren(canvasElement, imports) {
|
|
|
344
524
|
}
|
|
345
525
|
errors.push({
|
|
346
526
|
message: "<Canvas> children must be static storyboard declarations, not expressions",
|
|
347
|
-
span: toSpan(child)
|
|
527
|
+
span: toSpan(child),
|
|
528
|
+
kind: "structural"
|
|
348
529
|
});
|
|
349
530
|
continue;
|
|
350
531
|
}
|
|
@@ -359,7 +540,8 @@ function validateCanvasChildren(canvasElement, imports) {
|
|
|
359
540
|
}
|
|
360
541
|
errors.push({
|
|
361
542
|
message: "<Canvas> children must be <Storyboard>, <RouteStoryboard>, <HtmlStoryboard>, or <LegacyStoryboardV1> declarations",
|
|
362
|
-
span: toSpan(child)
|
|
543
|
+
span: toSpan(child),
|
|
544
|
+
kind: "structural"
|
|
363
545
|
});
|
|
364
546
|
}
|
|
365
547
|
return errors;
|
|
@@ -418,7 +600,8 @@ function readLayout(openingElement, componentName) {
|
|
|
418
600
|
errors: [
|
|
419
601
|
{
|
|
420
602
|
message: `<${componentName}> must include a literal "layout" object prop`,
|
|
421
|
-
span: toSpan(openingElement)
|
|
603
|
+
span: toSpan(openingElement),
|
|
604
|
+
kind: "degraded"
|
|
422
605
|
}
|
|
423
606
|
]
|
|
424
607
|
};
|
|
@@ -438,7 +621,8 @@ function readLayoutExpression(expression, componentName) {
|
|
|
438
621
|
errors: [
|
|
439
622
|
{
|
|
440
623
|
message: `<${componentName}> layout must be an object literal`,
|
|
441
|
-
span: toSpan(expression)
|
|
624
|
+
span: toSpan(expression),
|
|
625
|
+
kind: "degraded"
|
|
442
626
|
}
|
|
443
627
|
]
|
|
444
628
|
};
|
|
@@ -456,7 +640,8 @@ function readLayoutExpression(expression, componentName) {
|
|
|
456
640
|
} else {
|
|
457
641
|
errors.push({
|
|
458
642
|
message: `<${componentName}> layout.${key} must be a number literal`,
|
|
459
|
-
span: toSpan(property ?? expression)
|
|
643
|
+
span: toSpan(property ?? expression),
|
|
644
|
+
kind: "degraded"
|
|
460
645
|
});
|
|
461
646
|
}
|
|
462
647
|
}
|
|
@@ -469,7 +654,8 @@ function readLayoutExpression(expression, componentName) {
|
|
|
469
654
|
} else {
|
|
470
655
|
errors.push({
|
|
471
656
|
message: `<${componentName}> layout.zIndex must be a number literal`,
|
|
472
|
-
span: toSpan(zIndex)
|
|
657
|
+
span: toSpan(zIndex),
|
|
658
|
+
kind: "degraded"
|
|
473
659
|
});
|
|
474
660
|
}
|
|
475
661
|
}
|
|
@@ -481,7 +667,8 @@ function readLayoutExpression(expression, componentName) {
|
|
|
481
667
|
} else {
|
|
482
668
|
errors.push({
|
|
483
669
|
message: `<${componentName}> layout.intrinsicSizing must be "root-element" when set`,
|
|
484
|
-
span: toSpan(intrinsicSizing)
|
|
670
|
+
span: toSpan(intrinsicSizing),
|
|
671
|
+
kind: "degraded"
|
|
485
672
|
});
|
|
486
673
|
}
|
|
487
674
|
}
|
|
@@ -592,6 +779,21 @@ function resolveSdkComponent(nameNode, imports) {
|
|
|
592
779
|
}
|
|
593
780
|
return null;
|
|
594
781
|
}
|
|
782
|
+
function resolveMisimportedNamespaceSdkComponent(nameNode, imports, misimportedSdkCanvasImports) {
|
|
783
|
+
if (nameNode?.type !== "JSXMemberExpression" || nameNode.object?.type !== "JSXIdentifier" || nameNode.property?.type !== "JSXIdentifier" || !SDK_COMPONENTS.has(nameNode.property.name)) {
|
|
784
|
+
return null;
|
|
785
|
+
}
|
|
786
|
+
const imported = imports.byLocalName.get(nameNode.object.name);
|
|
787
|
+
if (imported?.kind !== "namespace" || !isWrongTempoSdkCanvasImportSource(imported.source)) {
|
|
788
|
+
return null;
|
|
789
|
+
}
|
|
790
|
+
return misimportedSdkCanvasImports.namespaceCandidatesByLocalName.get(
|
|
791
|
+
nameNode.object.name
|
|
792
|
+
) ?? null;
|
|
793
|
+
}
|
|
794
|
+
function isStoryboardSdkComponent(component) {
|
|
795
|
+
return component === "Storyboard" || component === "LegacyStoryboardV1" || component === "RouteStoryboard" || component === "HtmlStoryboard";
|
|
796
|
+
}
|
|
595
797
|
function readImportedName(specifier) {
|
|
596
798
|
if (specifier.type === "ImportDefaultSpecifier") return "default";
|
|
597
799
|
if (specifier.type === "ImportNamespaceSpecifier") return "*";
|
|
@@ -605,6 +807,12 @@ function readImportKind(specifier) {
|
|
|
605
807
|
function isSdkImportSource(source) {
|
|
606
808
|
return SDK_IMPORT_SOURCES.has(source) || source.endsWith("/tempo-sdk/canvas");
|
|
607
809
|
}
|
|
810
|
+
function isWrongTempoSdkCanvasImportSource(source) {
|
|
811
|
+
return (source === "tempo-sdk" || source.startsWith("tempo-sdk/")) && !isSdkImportSource(source);
|
|
812
|
+
}
|
|
813
|
+
function spanKey(span) {
|
|
814
|
+
return `${span.start}:${span.end}`;
|
|
815
|
+
}
|
|
608
816
|
function readLayoutClose(node) {
|
|
609
817
|
return typeof node?.end === "number" && Number.isFinite(node.end) ? node.end - 1 : void 0;
|
|
610
818
|
}
|
|
@@ -637,7 +845,8 @@ function walk(node, visitor, seen = /* @__PURE__ */ new Set()) {
|
|
|
637
845
|
|
|
638
846
|
export {
|
|
639
847
|
parseCanvasFile,
|
|
848
|
+
misimportedSdkCanvasImportMessage,
|
|
640
849
|
unwrapTsExpression,
|
|
641
850
|
fallbackPageName
|
|
642
851
|
};
|
|
643
|
-
//# sourceMappingURL=chunk-
|
|
852
|
+
//# sourceMappingURL=chunk-GBKYTBEE.js.map
|