Skip to content

Commit 2ce135a

Browse files
Bashamegasaschanaz
andauthored
Migrate HTMLInputElement (#2338)
Co-authored-by: saschanaz <saschanaz@users.noreply.github.com>
1 parent 5535d0a commit 2ce135a

File tree

9 files changed

+44
-62
lines changed

9 files changed

+44
-62
lines changed

baselines/dom.generated.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17341,7 +17341,7 @@ interface HTMLInputElement extends HTMLElement, PopoverTargetAttributes {
1734117341
*
1734217342
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLInputElement/selectionDirection)
1734317343
*/
17344-
selectionDirection: "forward" | "backward" | "none" | null;
17344+
selectionDirection: SelectionDirection | null;
1734517345
/**
1734617346
* The **`selectionEnd`** property of the HTMLInputElement interface is a number that represents the end index of the selected text. That is, it represents the index of the character immediately following the selection. Likewise, when there is no selection, this returns the offset of the character immediately following the current text input cursor position.
1734717347
*
@@ -17470,7 +17470,7 @@ interface HTMLInputElement extends HTMLElement, PopoverTargetAttributes {
1747017470
*
1747117471
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLInputElement/setSelectionRange)
1747217472
*/
17473-
setSelectionRange(start: number | null, end: number | null, direction?: "forward" | "backward" | "none"): void;
17473+
setSelectionRange(start: number | null, end: number | null, direction?: SelectionDirection): void;
1747417474
/**
1747517475
* The **`HTMLInputElement.showPicker()`** method displays the browser picker for an input element.
1747617476
*
@@ -42478,6 +42478,7 @@ type ReadableStreamReader<T> = ReadableStreamDefaultReader<T> | ReadableStreamBY
4247842478
type RenderingContext = CanvasRenderingContext2D | ImageBitmapRenderingContext | WebGLRenderingContext | WebGL2RenderingContext;
4247942479
type ReportList = Report[];
4248042480
type RequestInfo = Request | string;
42481+
type SelectionDirection = "forward" | "backward" | "none";
4248142482
type TexImageSource = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas | VideoFrame;
4248242483
type TimerHandler = string | Function;
4248342484
type Transferable = OffscreenCanvas | ImageBitmap | MessagePort | MediaSourceHandle | ReadableStream | WritableStream | TransformStream | AudioData | VideoFrame | RTCDataChannel | ArrayBuffer;

baselines/ts5.5/dom.generated.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17323,7 +17323,7 @@ interface HTMLInputElement extends HTMLElement, PopoverTargetAttributes {
1732317323
*
1732417324
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLInputElement/selectionDirection)
1732517325
*/
17326-
selectionDirection: "forward" | "backward" | "none" | null;
17326+
selectionDirection: SelectionDirection | null;
1732717327
/**
1732817328
* The **`selectionEnd`** property of the HTMLInputElement interface is a number that represents the end index of the selected text. That is, it represents the index of the character immediately following the selection. Likewise, when there is no selection, this returns the offset of the character immediately following the current text input cursor position.
1732917329
*
@@ -17452,7 +17452,7 @@ interface HTMLInputElement extends HTMLElement, PopoverTargetAttributes {
1745217452
*
1745317453
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLInputElement/setSelectionRange)
1745417454
*/
17455-
setSelectionRange(start: number | null, end: number | null, direction?: "forward" | "backward" | "none"): void;
17455+
setSelectionRange(start: number | null, end: number | null, direction?: SelectionDirection): void;
1745617456
/**
1745717457
* The **`HTMLInputElement.showPicker()`** method displays the browser picker for an input element.
1745817458
*
@@ -42452,6 +42452,7 @@ type ReadableStreamReader<T> = ReadableStreamDefaultReader<T> | ReadableStreamBY
4245242452
type RenderingContext = CanvasRenderingContext2D | ImageBitmapRenderingContext | WebGLRenderingContext | WebGL2RenderingContext;
4245342453
type ReportList = Report[];
4245442454
type RequestInfo = Request | string;
42455+
type SelectionDirection = "forward" | "backward" | "none";
4245542456
type TexImageSource = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas | VideoFrame;
4245642457
type TimerHandler = string | Function;
4245742458
type Transferable = OffscreenCanvas | ImageBitmap | MessagePort | MediaSourceHandle | ReadableStream | WritableStream | TransformStream | AudioData | VideoFrame | RTCDataChannel | ArrayBuffer;

baselines/ts5.6/dom.generated.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17338,7 +17338,7 @@ interface HTMLInputElement extends HTMLElement, PopoverTargetAttributes {
1733817338
*
1733917339
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLInputElement/selectionDirection)
1734017340
*/
17341-
selectionDirection: "forward" | "backward" | "none" | null;
17341+
selectionDirection: SelectionDirection | null;
1734217342
/**
1734317343
* The **`selectionEnd`** property of the HTMLInputElement interface is a number that represents the end index of the selected text. That is, it represents the index of the character immediately following the selection. Likewise, when there is no selection, this returns the offset of the character immediately following the current text input cursor position.
1734417344
*
@@ -17467,7 +17467,7 @@ interface HTMLInputElement extends HTMLElement, PopoverTargetAttributes {
1746717467
*
1746817468
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLInputElement/setSelectionRange)
1746917469
*/
17470-
setSelectionRange(start: number | null, end: number | null, direction?: "forward" | "backward" | "none"): void;
17470+
setSelectionRange(start: number | null, end: number | null, direction?: SelectionDirection): void;
1747117471
/**
1747217472
* The **`HTMLInputElement.showPicker()`** method displays the browser picker for an input element.
1747317473
*
@@ -42475,6 +42475,7 @@ type ReadableStreamReader<T> = ReadableStreamDefaultReader<T> | ReadableStreamBY
4247542475
type RenderingContext = CanvasRenderingContext2D | ImageBitmapRenderingContext | WebGLRenderingContext | WebGL2RenderingContext;
4247642476
type ReportList = Report[];
4247742477
type RequestInfo = Request | string;
42478+
type SelectionDirection = "forward" | "backward" | "none";
4247842479
type TexImageSource = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas | VideoFrame;
4247942480
type TimerHandler = string | Function;
4248042481
type Transferable = OffscreenCanvas | ImageBitmap | MessagePort | MediaSourceHandle | ReadableStream | WritableStream | TransformStream | AudioData | VideoFrame | RTCDataChannel | ArrayBuffer;

baselines/ts5.9/dom.generated.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17338,7 +17338,7 @@ interface HTMLInputElement extends HTMLElement, PopoverTargetAttributes {
1733817338
*
1733917339
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLInputElement/selectionDirection)
1734017340
*/
17341-
selectionDirection: "forward" | "backward" | "none" | null;
17341+
selectionDirection: SelectionDirection | null;
1734217342
/**
1734317343
* The **`selectionEnd`** property of the HTMLInputElement interface is a number that represents the end index of the selected text. That is, it represents the index of the character immediately following the selection. Likewise, when there is no selection, this returns the offset of the character immediately following the current text input cursor position.
1734417344
*
@@ -17467,7 +17467,7 @@ interface HTMLInputElement extends HTMLElement, PopoverTargetAttributes {
1746717467
*
1746817468
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLInputElement/setSelectionRange)
1746917469
*/
17470-
setSelectionRange(start: number | null, end: number | null, direction?: "forward" | "backward" | "none"): void;
17470+
setSelectionRange(start: number | null, end: number | null, direction?: SelectionDirection): void;
1747117471
/**
1747217472
* The **`HTMLInputElement.showPicker()`** method displays the browser picker for an input element.
1747317473
*
@@ -42475,6 +42475,7 @@ type ReadableStreamReader<T> = ReadableStreamDefaultReader<T> | ReadableStreamBY
4247542475
type RenderingContext = CanvasRenderingContext2D | ImageBitmapRenderingContext | WebGLRenderingContext | WebGL2RenderingContext;
4247642476
type ReportList = Report[];
4247742477
type RequestInfo = Request | string;
42478+
type SelectionDirection = "forward" | "backward" | "none";
4247842479
type TexImageSource = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas | VideoFrame;
4247942480
type TimerHandler = string | Function;
4248042481
type Transferable = OffscreenCanvas | ImageBitmap | MessagePort | MediaSourceHandle | ReadableStream | WritableStream | TransformStream | AudioData | VideoFrame | RTCDataChannel | ArrayBuffer;

inputfiles/addedTypes.jsonc

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,6 @@
301301
}
302302
}
303303
},
304-
"HTMLInputElement": {
305-
"properties": {
306-
"property": {
307-
"labels": {
308-
"overrideType": "NodeListOf<HTMLLabelElement>"
309-
}
310-
}
311-
}
312-
},
313304
"RuntimeError": {
314305
"name": "RuntimeError",
315306
"extends": "Error",

inputfiles/knownTypes.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"AutoFillContactField",
1515
"AutoFillField",
1616
"AutoFillCredentialField",
17-
"AutoFill",
1817
"BigInteger",
1918
"ClientQueryOptions",
2019
"ClientTypes",

inputfiles/overridingTypes.jsonc

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,48 +1445,6 @@
14451445
}
14461446
}
14471447
},
1448-
"HTMLInputElement": {
1449-
"properties": {
1450-
"property": {
1451-
"autocomplete": {
1452-
"name": "autocomplete",
1453-
"overrideType": "AutoFill"
1454-
},
1455-
"selectionDirection": {
1456-
"name": "selectionDirection",
1457-
"overrideType": "\"forward\" | \"backward\" | \"none\""
1458-
},
1459-
"valueAsDate": {
1460-
"name": "valueAsDate",
1461-
"overrideType": "Date"
1462-
}
1463-
}
1464-
},
1465-
"methods": {
1466-
"method": {
1467-
"setSelectionRange": {
1468-
"signature": {
1469-
"0": {
1470-
"param": [
1471-
{
1472-
"name": "start",
1473-
"nullable": true
1474-
},
1475-
{
1476-
"name": "end",
1477-
"nullable": true
1478-
},
1479-
{
1480-
"name": "direction",
1481-
"overrideType": "\"forward\" | \"backward\" | \"none\""
1482-
}
1483-
]
1484-
}
1485-
}
1486-
}
1487-
}
1488-
}
1489-
},
14901448
"MouseEvent": {
14911449
"methods": {
14921450
"method": {

inputfiles/patches/html.kdl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,30 @@ interface HTMLImageElement {
4747
property loading overrideType=#""eager" | "lazy""#
4848
}
4949

50+
interface HTMLInputElement {
51+
property labels {
52+
type NodeListOf {
53+
type HTMLLabelElement
54+
}
55+
}
56+
property autocomplete type=AutoFill
57+
property valueAsDate type=Date
58+
property selectionDirection type=SelectionDirection
59+
method setSelectionRange signatureIndex=0 {
60+
// nullable types because we want to allow passing selectionStart/End properties, which are nullable.
61+
// See also https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/878.
62+
param start {
63+
type nullable=#true
64+
}
65+
param end {
66+
type nullable=#true
67+
}
68+
param direction type=SelectionDirection
69+
}
70+
}
71+
72+
typedef SelectionDirection overrideType=#""forward" | "backward" | "none""#
73+
5074
dictionary StructuredSerializeOptions {
5175
member transfer {
5276
type {

src/build/patches.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ function handleProperty(child: Node): DeepPartial<Property> {
307307
function handleParam(node: Node) {
308308
const name = string(node.values[0]);
309309
let additionalTypes: string[] | undefined;
310+
const typeNodes: Node[] = [];
310311

311312
for (const child of node.children) {
312313
switch (child.name) {
@@ -317,14 +318,18 @@ function handleParam(node: Node) {
317318
additionalTypes = child.values.map(string);
318319
break;
319320
}
321+
case "type": {
322+
typeNodes.push(child);
323+
break;
324+
}
320325
default:
321326
throw new Error(`Unexpected child "${child.name}" in param "${name}"`);
322327
}
323328
}
324329

325330
return {
326331
name,
327-
...optionalMember("type", "string", node.properties?.type),
332+
...handleTyped(typeNodes, node.properties?.type),
328333
...optionalMember("overrideType", "string", node.properties?.overrideType),
329334
additionalTypes,
330335
};
@@ -343,7 +348,7 @@ function handleMethodAndConstructor(
343348

344349
// Collect all type nodes into an array
345350
const typeNodes: Node[] = [];
346-
const params: Partial<Param>[] = [];
351+
const params: DeepPartial<Param>[] = [];
347352

348353
for (const c of child.children) {
349354
switch (c.name) {
@@ -452,6 +457,7 @@ function handleTypedef(node: Node): DeepPartial<TypeDef> {
452457
"string",
453458
node.properties?.legacyNamespace,
454459
),
460+
...optionalMember("overrideType", "string", node.properties?.overrideType),
455461
};
456462
}
457463

0 commit comments

Comments
 (0)