@wix/zero-config-implementation 1.106.0 → 1.109.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/index.d.ts +11 -17
- package/dist/index.js +12172 -12042
- package/package.json +3 -3
- package/src/converters/data-item-builder.ts +44 -10
- package/src/converters/function-signature-builder.test.ts +257 -0
- package/src/converters/function-signature-builder.ts +144 -0
- package/src/converters/to-editor-component.test.ts +0 -85
- package/src/converters/to-editor-component.ts +0 -39
- package/src/information-extractors/css/parse.ts +0 -16
- package/src/information-extractors/css/types.ts +0 -17
- package/src/information-extractors/ts/types.ts +6 -0
- package/src/information-extractors/ts/utils/semantic-type-resolver.ts +93 -2
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
CssCustomPropertyItem,
|
|
3
|
-
CssNumber,
|
|
4
3
|
CssPropertyItem,
|
|
5
4
|
CustomPropertyEnum,
|
|
6
5
|
DataItem,
|
|
@@ -387,7 +386,6 @@ function buildNearestCommonAncestorCustomProps(
|
|
|
387
386
|
? registration.cssPropertyType
|
|
388
387
|
: getVarPropertyTypeFromCssInfos(varName, valueForTypeInference, component.css)
|
|
389
388
|
const customEnum = buildCustomEnum(registration)
|
|
390
|
-
const numberLimits = buildCssNumber(registration, cssPropertyType)
|
|
391
389
|
const cleanVarName = varName.startsWith('--') ? varName.slice(2) : varName
|
|
392
390
|
|
|
393
391
|
const existingProps = nearestCommonAncestorCustomProps.get(nearestCommonAncestorTraceId) ?? {}
|
|
@@ -397,7 +395,6 @@ function buildNearestCommonAncestorCustomProps(
|
|
|
397
395
|
...(statesDefaultValues && { statesDefaultValues }),
|
|
398
396
|
...(cssPropertyType !== undefined && { cssPropertyType }),
|
|
399
397
|
...(customEnum && { customEnum }),
|
|
400
|
-
...(numberLimits && { number: numberLimits }),
|
|
401
398
|
}
|
|
402
399
|
nearestCommonAncestorCustomProps.set(nearestCommonAncestorTraceId, existingProps)
|
|
403
400
|
}
|
|
@@ -493,42 +490,6 @@ function buildCustomEnum(registration: RegisteredCustomProperty | undefined): Cu
|
|
|
493
490
|
}
|
|
494
491
|
}
|
|
495
492
|
|
|
496
|
-
function parseFiniteDescriptor(rawValue: string | undefined): number | undefined {
|
|
497
|
-
const trimmed = rawValue?.trim()
|
|
498
|
-
if (!trimmed) return undefined
|
|
499
|
-
const parsed = Number(trimmed)
|
|
500
|
-
return Number.isFinite(parsed) ? parsed : undefined
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
/**
|
|
504
|
-
* Builds the clamp the panel's number control applies, from an @property's range
|
|
505
|
-
* descriptors. Anything unusable is dropped rather than passed through.
|
|
506
|
-
*/
|
|
507
|
-
function buildCssNumber(
|
|
508
|
-
registration: RegisteredCustomProperty | undefined,
|
|
509
|
-
cssPropertyType: CssCustomPropertyItem['cssPropertyType'],
|
|
510
|
-
): CssNumber | undefined {
|
|
511
|
-
if (!registration?.range || cssPropertyType !== CSS_PROPERTIES.CSS_DATA_TYPE.number) return undefined
|
|
512
|
-
|
|
513
|
-
let min = parseFiniteDescriptor(registration.range.min)
|
|
514
|
-
let max = parseFiniteDescriptor(registration.range.max)
|
|
515
|
-
if (min !== undefined && max !== undefined && min >= max) {
|
|
516
|
-
min = undefined
|
|
517
|
-
max = undefined
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
const step = parseFiniteDescriptor(registration.range.step)
|
|
521
|
-
const multiplier = step !== undefined && step > 0 ? step : undefined
|
|
522
|
-
|
|
523
|
-
if (min === undefined && max === undefined && multiplier === undefined) return undefined
|
|
524
|
-
|
|
525
|
-
return {
|
|
526
|
-
...(min !== undefined && { min: String(min) }),
|
|
527
|
-
...(max !== undefined && { max: String(max) }),
|
|
528
|
-
...(multiplier !== undefined && { multiplier: String(multiplier) }),
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
493
|
function getVarPropertyTypeFromCssInfos(
|
|
533
494
|
varName: string,
|
|
534
495
|
defaultValue: string,
|
|
@@ -9,7 +9,6 @@ import type {
|
|
|
9
9
|
CssDataType,
|
|
10
10
|
NativePseudoClass,
|
|
11
11
|
RegisteredCustomProperty,
|
|
12
|
-
RegisteredPropertyRange,
|
|
13
12
|
SelectorStateScope,
|
|
14
13
|
StateClassRule,
|
|
15
14
|
} from './types'
|
|
@@ -537,19 +536,6 @@ function extractAtruleDescriptors(block: CssNode): Map<string, string> {
|
|
|
537
536
|
return descriptors
|
|
538
537
|
}
|
|
539
538
|
|
|
540
|
-
/** Picks the range descriptors out of the block; css-tree collects them like any other declaration. */
|
|
541
|
-
function extractRangeDescriptors(descriptors: Map<string, string>): RegisteredPropertyRange | undefined {
|
|
542
|
-
const min = descriptors.get('--min')
|
|
543
|
-
const max = descriptors.get('--max')
|
|
544
|
-
const step = descriptors.get('--step')
|
|
545
|
-
if (min === undefined && max === undefined && step === undefined) return undefined
|
|
546
|
-
return {
|
|
547
|
-
...(min !== undefined && { min }),
|
|
548
|
-
...(max !== undefined && { max }),
|
|
549
|
-
...(step !== undefined && { step }),
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
|
|
553
539
|
/**
|
|
554
540
|
* Walks the stylesheet for `@property` at-rules and builds a map of registered custom
|
|
555
541
|
* properties keyed by the `--`-prefixed variable name.
|
|
@@ -577,13 +563,11 @@ function parseRegisteredProperties(cssString: string): Map<string, RegisteredCus
|
|
|
577
563
|
if (!resolved) return
|
|
578
564
|
const { cssPropertyType, enumOptions } = resolved
|
|
579
565
|
const initialValue = descriptors.get('initial-value')
|
|
580
|
-
const range = extractRangeDescriptors(descriptors)
|
|
581
566
|
|
|
582
567
|
registered.set(varName, {
|
|
583
568
|
cssPropertyType,
|
|
584
569
|
...(enumOptions && { enumOptions }),
|
|
585
570
|
...(initialValue !== undefined && { defaultValue: initialValue }),
|
|
586
|
-
...(range && { range }),
|
|
587
571
|
})
|
|
588
572
|
},
|
|
589
573
|
})
|
|
@@ -69,23 +69,6 @@ export interface RegisteredCustomProperty {
|
|
|
69
69
|
* (`a | b | c`). Present only when `cssPropertyType` is `customEnum`.
|
|
70
70
|
*/
|
|
71
71
|
enumOptions?: string[]
|
|
72
|
-
/**
|
|
73
|
-
* The numeric range for the control, as raw descriptor strings. Validated at
|
|
74
|
-
* conversion time. Meaningful only when `cssPropertyType` is `number`.
|
|
75
|
-
*/
|
|
76
|
-
range?: RegisteredPropertyRange
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* `--min` / `--max` / `--step` descriptors an importer may emit inside an `@property`
|
|
81
|
-
* block. The `--` prefix keeps them in the author namespace: browsers ignore descriptors
|
|
82
|
-
* they don't know, so the CSS stays valid and CSS can't standardise these names out from
|
|
83
|
-
* under us.
|
|
84
|
-
*/
|
|
85
|
-
export interface RegisteredPropertyRange {
|
|
86
|
-
min?: string
|
|
87
|
-
max?: string
|
|
88
|
-
step?: string
|
|
89
72
|
}
|
|
90
73
|
|
|
91
74
|
export type NativePseudoClass = 'hover' | 'focus' | 'disabled' | 'invalid'
|
|
@@ -21,6 +21,12 @@ export interface ResolvedType {
|
|
|
21
21
|
properties?: Record<string, PropInfo>
|
|
22
22
|
elementType?: ResolvedType
|
|
23
23
|
types?: ResolvedType[] // For unions and intersections
|
|
24
|
+
functionSignature?: {
|
|
25
|
+
parameters: { name: string; type: ResolvedType; optional: boolean; rest: boolean }[]
|
|
26
|
+
returnType: ResolvedType
|
|
27
|
+
async: boolean
|
|
28
|
+
overloaded: boolean
|
|
29
|
+
}
|
|
24
30
|
}
|
|
25
31
|
|
|
26
32
|
/**
|
|
@@ -214,7 +214,7 @@ function resolveTypeBody({
|
|
|
214
214
|
() => resolveUnionType(type, checker, depth, seenTypes),
|
|
215
215
|
() => resolveArrayType(type, checker, depth, seenTypes),
|
|
216
216
|
() => resolveIntersectionType(type, checker, depth, seenTypes),
|
|
217
|
-
() => resolveFunctionType(type, checker),
|
|
217
|
+
() => resolveFunctionType(type, checker, depth, seenTypes),
|
|
218
218
|
() => resolveObjectType(type, checker, depth, seenTypes),
|
|
219
219
|
]
|
|
220
220
|
|
|
@@ -367,7 +367,58 @@ function getArrayElementType(type: ts.Type, checker: ts.TypeChecker): ts.Type |
|
|
|
367
367
|
return checker.getIndexTypeOfType(type, ts.IndexKind.Number)
|
|
368
368
|
}
|
|
369
369
|
|
|
370
|
-
|
|
370
|
+
const REACT_EVENT_TYPES = new Set([
|
|
371
|
+
'ChangeEvent',
|
|
372
|
+
'MouseEvent',
|
|
373
|
+
'PointerEvent',
|
|
374
|
+
'FocusEvent',
|
|
375
|
+
'KeyboardEvent',
|
|
376
|
+
'FormEvent',
|
|
377
|
+
])
|
|
378
|
+
|
|
379
|
+
function resolveCallbackType(
|
|
380
|
+
type: ts.Type,
|
|
381
|
+
checker: ts.TypeChecker,
|
|
382
|
+
depth: number,
|
|
383
|
+
seenTypes: Set<ts.Type>,
|
|
384
|
+
typeNode?: ts.TypeNode,
|
|
385
|
+
): ResolvedType {
|
|
386
|
+
const declaredSemanticType = resolveDeclaredCallbackSemanticType(typeNode, checker)
|
|
387
|
+
if (declaredSemanticType) return declaredSemanticType
|
|
388
|
+
const symbol = type.getSymbol()
|
|
389
|
+
if (symbol && REACT_EVENT_TYPES.has(symbol.getName())) {
|
|
390
|
+
const source = getSymbolPackage(symbol, checker)
|
|
391
|
+
if (source === '@types/react' || source === 'react') {
|
|
392
|
+
return { kind: 'semantic', value: symbol.getName(), source }
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return resolveType({ type, checker, depth: depth + 1, seenTypes })
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function resolveDeclaredCallbackSemanticType(
|
|
399
|
+
typeNode: ts.TypeNode | undefined,
|
|
400
|
+
checker: ts.TypeChecker,
|
|
401
|
+
seenSymbols = new Set<ts.Symbol>(),
|
|
402
|
+
): ResolvedType | undefined {
|
|
403
|
+
if (!typeNode || !ts.isTypeReferenceNode(typeNode)) return undefined
|
|
404
|
+
let symbol = checker.getSymbolAtLocation(typeNode.typeName)
|
|
405
|
+
if (!symbol) return undefined
|
|
406
|
+
if ((symbol.flags & ts.SymbolFlags.Alias) !== 0) symbol = checker.getAliasedSymbol(symbol)
|
|
407
|
+
if (seenSymbols.has(symbol)) return undefined
|
|
408
|
+
seenSymbols.add(symbol)
|
|
409
|
+
if (getSymbolPackage(symbol, checker) === '@wix/editor-react-types' && isValidWixSemanticType(symbol.getName())) {
|
|
410
|
+
return { kind: 'semantic', value: symbol.getName(), source: '@wix/editor-react-types' }
|
|
411
|
+
}
|
|
412
|
+
const declaration = symbol.getDeclarations()?.find(ts.isTypeAliasDeclaration)
|
|
413
|
+
return declaration ? resolveDeclaredCallbackSemanticType(declaration.type, checker, seenSymbols) : undefined
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function resolveFunctionType(
|
|
417
|
+
type: ts.Type,
|
|
418
|
+
checker: ts.TypeChecker,
|
|
419
|
+
depth: number,
|
|
420
|
+
seenTypes: Set<ts.Type>,
|
|
421
|
+
): ResolvedType | undefined {
|
|
371
422
|
const callSignatures = type.getCallSignatures()
|
|
372
423
|
if (callSignatures.length > 0) {
|
|
373
424
|
const signature = callSignatures[0]
|
|
@@ -379,6 +430,13 @@ function resolveFunctionType(type: ts.Type, checker: ts.TypeChecker): ResolvedTy
|
|
|
379
430
|
}
|
|
380
431
|
})
|
|
381
432
|
const returnType = signature.getReturnType()
|
|
433
|
+
const isAsync = returnType.getSymbol()?.getName() === 'Promise'
|
|
434
|
+
const resolvedReturnType = isAsync ? checker.getTypeArguments(returnType as ts.TypeReference)[0] : returnType
|
|
435
|
+
const declaredReturnType = signature.getDeclaration()?.type
|
|
436
|
+
const returnTypeNode =
|
|
437
|
+
isAsync && declaredReturnType && ts.isTypeReferenceNode(declaredReturnType)
|
|
438
|
+
? declaredReturnType.typeArguments?.[0]
|
|
439
|
+
: declaredReturnType
|
|
382
440
|
|
|
383
441
|
return {
|
|
384
442
|
kind: 'function',
|
|
@@ -386,6 +444,39 @@ function resolveFunctionType(type: ts.Type, checker: ts.TypeChecker): ResolvedTy
|
|
|
386
444
|
parameters,
|
|
387
445
|
returnType: checker.typeToString(returnType),
|
|
388
446
|
},
|
|
447
|
+
functionSignature: {
|
|
448
|
+
parameters: signature.getParameters().map((parameter) => {
|
|
449
|
+
const declaration = parameter.valueDeclaration
|
|
450
|
+
const parameterTypeNode = declaration && ts.isParameter(declaration) ? declaration.type : undefined
|
|
451
|
+
const parameterType = checker.getTypeOfSymbol(parameter)
|
|
452
|
+
const optional =
|
|
453
|
+
(parameter.flags & ts.SymbolFlags.Optional) !== 0 ||
|
|
454
|
+
(declaration &&
|
|
455
|
+
ts.isParameter(declaration) &&
|
|
456
|
+
Boolean(declaration.questionToken || declaration.initializer))
|
|
457
|
+
const definedType =
|
|
458
|
+
optional && parameterType.isUnion()
|
|
459
|
+
? parameterType.types.filter((member) => !(member.flags & ts.TypeFlags.Undefined))
|
|
460
|
+
: [parameterType]
|
|
461
|
+
return {
|
|
462
|
+
name: parameter.getName(),
|
|
463
|
+
type:
|
|
464
|
+
definedType.length === 1
|
|
465
|
+
? resolveCallbackType(definedType[0], checker, depth, seenTypes, parameterTypeNode)
|
|
466
|
+
: {
|
|
467
|
+
kind: 'union',
|
|
468
|
+
types: definedType.map((member) =>
|
|
469
|
+
resolveCallbackType(member, checker, depth, seenTypes, parameterTypeNode),
|
|
470
|
+
),
|
|
471
|
+
},
|
|
472
|
+
optional: Boolean(optional),
|
|
473
|
+
rest: Boolean(declaration && ts.isParameter(declaration) && declaration.dotDotDotToken),
|
|
474
|
+
}
|
|
475
|
+
}),
|
|
476
|
+
returnType: resolveCallbackType(resolvedReturnType ?? returnType, checker, depth, seenTypes, returnTypeNode),
|
|
477
|
+
async: isAsync,
|
|
478
|
+
overloaded: callSignatures.length > 1,
|
|
479
|
+
},
|
|
389
480
|
}
|
|
390
481
|
}
|
|
391
482
|
return undefined
|