diff --git a/types/activex-dao/activex-dao-tests.ts b/types/activex-dao/activex-dao-tests.ts index 412bea60b5..7e8c2bef22 100644 --- a/types/activex-dao/activex-dao-tests.ts +++ b/types/activex-dao/activex-dao-tests.ts @@ -1,27 +1,48 @@ -let engine = new ActiveXObject('DAO.DBEngine.120'); +const collectionToArray = (col: { Item(key: any): T }): T[] => { + const results: T[] = []; + const enumerator = new Enumerator(col); + enumerator.moveFirst(); + while (!enumerator.atEnd()) { + results.push(enumerator.item()); + enumerator.moveNext(); + } + return results; +}; + +const dbOpenSnapshot = DAO.RecordsetTypeEnum.dbOpenSnapshot; + +let engine = new ActiveXObject('DAO.DBEngine'); let dbsNorthwind = engine.OpenDatabase('c:\\path\\to\\northwind.mdb'); -// adding a record to a recordset -- https://msdn.microsoft.com/VBA/Access-VBA/articles/add-a-record-to-a-dao-recordset -let rstShippers = dbsNorthwind.OpenRecordset('Shippers'); -rstShippers.AddNew(); -rstShippers.Fields.Item('CompanyName').Value = 'Global Parcel Service'; -// Set remaining fields -rstShippers.Update(); -rstShippers.Close(); +// https://msdn.microsoft.com/VBA/Access-VBA/articles/add-a-record-to-a-dao-recordset +{ + // adding a record to a recordset + const rstShippers = dbsNorthwind.OpenRecordset('Shippers'); + rstShippers.AddNew(); + rstShippers('CompanyName').Value = 'Global Parcel Service'; + // Set remaining fields + rstShippers.Update(); + rstShippers.Close(); +} -// create a QueryDef with the given SQL -- https://msdn.microsoft.com/VBA/Access-VBA/articles/build-sql-statements-that-include-variables-and-controls -let sql = 'SELECT * FROM Orders WHERE OrderDate > #3-31-2006#'; -let qdf = dbsNorthwind.CreateQueryDef('Second quarter', sql); -// using parameters -sql = ` - PARAMETERS QuarterStart DATETIME - SELECT * - FROM Orders - WHERE OrderDate > QuarterStart -`; -qdf = dbsNorthwind.CreateQueryDef('Second quarter (parameters)', sql); +// https://msdn.microsoft.com/VBA/Access-VBA/articles/build-sql-statements-that-include-variables-and-controls +{ + // create a QueryDef with the given SQL + let sql = 'SELECT * FROM Orders WHERE OrderDate > #3-31-2006#'; + let qdf = dbsNorthwind.CreateQueryDef('Second quarter', sql); + // using parameters + sql = ` + PARAMETERS QuarterStart DATETIME + SELECT * + FROM Orders + WHERE OrderDate > QuarterStart + `; + qdf = dbsNorthwind.CreateQueryDef('Second quarter (parameters)', sql); + WScript.Echo(`Field names: ${collectionToArray(qdf.Fields).map(fld => fld.Name).join(', ')}`); +} -// count the number of records in a Recordset -- https://msdn.microsoft.com/VBA/Access-VBA/articles/count-the-number-of-records-in-a-dao-recordset +// https://msdn.microsoft.com/VBA/Access-VBA/articles/count-the-number-of-records-in-a-dao-recordset +/** Count the number of records in a Recordset */ const findRecordCount = (dbs: DAO.Database, sql: string) => { let count = 0; const rstRecords = dbs.OpenRecordset(sql); @@ -33,113 +54,119 @@ const findRecordCount = (dbs: DAO.Database, sql: string) => { return count; }; -// delete records from a Recordset -- https://msdn.microsoft.com/VBA/Access-VBA/articles/delete-a-record-from-a-dao-recordset -rstShippers = dbsNorthwind.OpenRecordset('SELECT * FROM Shippers ORDER BY CompanyName, ShipperID', DAO.RecordsetTypeEnum.dbOpenDynaset); -if (!rstShippers.EOF) { - let name = rstShippers.Fields.Item('CompanyName').Value; - rstShippers.MoveNext(); - while (!rstShippers.EOF) { - const recordName: string = rstShippers.Fields.Item('CompanyName').Value; - if (recordName === name) { - rstShippers.Delete(); - } else { - name = recordName; - } +// https://msdn.microsoft.com/VBA/Access-VBA/articles/delete-a-record-from-a-dao-recordset +{ + // delete records from a Recordset + const rstShippers = dbsNorthwind.OpenRecordset('SELECT * FROM Shippers ORDER BY CompanyName, ShipperID', DAO.RecordsetTypeEnum.dbOpenDynaset); + if (!rstShippers.EOF) { + let name = rstShippers('CompanyName').Value; rstShippers.MoveNext(); + while (!rstShippers.EOF) { + const recordName: string = rstShippers('CompanyName').Value; + if (recordName === name) { + rstShippers.Delete(); + } else { + name = recordName; + } + rstShippers.MoveNext(); + } } + rstShippers.Close(); } -rstShippers.Close(); -// copy entire records to an array -- https://msdn.microsoft.com/VBA/Access-VBA/articles/extract-data-from-a-record-in-a-dao-recordset -let rstEmployees = dbsNorthwind.OpenRecordset('SELECT FirstName, LastName, Title FROM Employees', DAO.RecordsetTypeEnum.dbOpenSnapshot); -let records = new VBArray(rstEmployees.GetRows(3)); -let recordCount = records.ubound(2) + 1; -let columnCount = records.ubound(1) + 1; -for (let row = 0; row < recordCount; row += 1) { - for (let column = 0; column < columnCount; column += 1) { - WScript.Echo(records.getItem(column, row)); +// https://msdn.microsoft.com/VBA/Access-VBA/articles/extract-data-from-a-record-in-a-dao-recordset +{ + // copy entire records to an array + const rstEmployees = dbsNorthwind.OpenRecordset('SELECT FirstName, LastName, Title FROM Employees', dbOpenSnapshot); + const records = new VBArray(rstEmployees.GetRows(3)); + const recordCount = records.ubound(2) + 1; + const columnCount = records.ubound(1) + 1; + for (let row = 0; row < recordCount; row += 1) { + for (let column = 0; column < columnCount; column += 1) { + WScript.Echo(records.getItem(column, row)); + } } + if (rstEmployees.EOF) { WScript.Echo('At end of recordset'); } + rstEmployees.Close(); } -if (rstEmployees.EOF) { WScript.Echo('At end of recordset'); } -rstEmployees.Close(); // find a record in a dynaset-type or snapshot-type DAO Recordset -- https://msdn.microsoft.com/en-us/vba/access-vba/articles/find-a-record-in-a-dynaset-type-or-snapshot-type-dao-recordset -const findOrdersWithoutDetails = () => { +{ const orders: number[] = []; - const rstOrders = dbsNorthwind.OpenRecordset('SELECT * FROM Orders ORDER BY OrderID', DAO.RecordsetTypeEnum.dbOpenSnapshot); - const rstOrderDetails = dbsNorthwind.OpenRecordset('SELECT * FROM [Order Details] ORDER BY OrderID', DAO.RecordsetTypeEnum.dbOpenSnapshot); + const rstOrders = dbsNorthwind.OpenRecordset('SELECT * FROM Orders ORDER BY OrderID', dbOpenSnapshot); + const rstOrderDetails = dbsNorthwind.OpenRecordset('SELECT * FROM [Order Details] ORDER BY OrderID', dbOpenSnapshot); - const closeRecordsets = () => { - rstOrders.Close(); - rstOrderDetails.Close(); - }; - if (rstOrders.EOF || rstOrderDetails.EOF) { - closeRecordsets(); - return; - } - - while (!rstOrders.EOF) { - const orderID = rstOrders.Fields.Item('OrderID').Value; - rstOrderDetails.FindFirst(`OrderID=${orderID}`); - if (rstOrderDetails.NoMatch) { - orders.push(orderID); + if (!rstOrders.EOF && !rstOrderDetails.EOF) { + while (!rstOrders.EOF) { + const orderID = rstOrders('OrderID').Value; + rstOrderDetails.FindFirst(`OrderID=${orderID}`); + if (rstOrderDetails.NoMatch) { + orders.push(orderID); + } + rstOrders.MoveNext(); } - rstOrders.MoveNext(); } - closeRecordsets(); - return orders; -}; -// find a record in a table-type DAO Recordset -- https://msdn.microsoft.com/VBA/Access-VBA/articles/find-a-record-in-a-table-type-dao-recordset + rstOrders.Close(); + rstOrderDetails.Close(); + + WScript.Echo(orders.join('\n')); +} + +// https://msdn.microsoft.com/VBA/Access-VBA/articles/find-a-record-in-a-table-type-dao-recordset +/** Find a record in a table-type DAO Recordset */ const getHireDate = (employeeID: number) => { let hireDate: Date | undefined; const rstEmployees = dbsNorthwind.OpenRecordset('Employees'); rstEmployees.Index = 'PrimaryKey'; rstEmployees.Seek('=', employeeID); if (!rstEmployees.NoMatch) { - hireDate = new Date(rstEmployees.Fields.Item('HireDate').Value as VarDate); + hireDate = new Date(rstEmployees('HireDate').Value as VarDate); } return hireDate; }; -// manipulate multiple fields with DAO -- https://msdn.microsoft.com/VBA/Access-VBA/articles/manipulate-multivalued-fields-with-dao -const browseMultiValueField = () => { +// https://msdn.microsoft.com/VBA/Access-VBA/articles/manipulate-multivalued-fields-with-dao +{ + // manipulate multiple fields with DAO const rs = dbsNorthwind.OpenRecordset('Tasks'); rs.MoveFirst(); while (!rs.EOF) { - WScript.Echo(rs.Fields.Item('TaskName').Value); - const childRs = rs.Fields.Item('AssignedTo').Value as DAO.Recordset; + WScript.Echo(rs('TaskName').Value); + const childRs = rs('AssignedTo').Value as DAO.Recordset; if (childRs.EOF) { continue; } childRs.MoveFirst(); while (!childRs.EOF) { - WScript.Echo('\t' + childRs.Fields.Item('Value').Value); + WScript.Echo('\t' + childRs('Value').Value); } } -}; +} -// modifying an existing record in a DAO Recordset -- https://msdn.microsoft.com/VBA/Access-VBA/articles/modify-an-existing-record-in-a-dao-recordset -const changeTitleWithoutTransaction = () => { - rstEmployees = dbsNorthwind.OpenRecordset('Employees'); +// https://msdn.microsoft.com/VBA/Access-VBA/articles/modify-an-existing-record-in-a-dao-recordset +{ + // modifying an existing record in a DAO Recordset + const rstEmployees = dbsNorthwind.OpenRecordset('Employees'); while (!rstEmployees.EOF) { - if (rstEmployees.Fields.Item('Title').Value === 'Sales Representative') { + if (rstEmployees('Title').Value === 'Sales Representative') { rstEmployees.Edit(); - rstEmployees.Fields.Item('Title').Value = 'Account Executive'; + rstEmployees('Title').Value = 'Account Executive'; rstEmployees.Update(); } rstEmployees.MoveNext(); } rstEmployees.Close(); -}; +} -// using transactions in a DAO Recordset -- https://msdn.microsoft.com/VBA/Access-VBA/articles/use-transactions-in-a-dao-recordset +// https://msdn.microsoft.com/VBA/Access-VBA/articles/use-transactions-in-a-dao-recordset +/** using transactions in a DAO Recordset */ const changeTitleWithTransaction = (commitTransaction: boolean) => { - const currentWorkspace = engine.Workspaces.Item(0); - rstEmployees = dbsNorthwind.OpenRecordset('Employees'); + const currentWorkspace = engine.Workspaces(0); + const rstEmployees = dbsNorthwind.OpenRecordset('Employees'); currentWorkspace.BeginTrans(); while (!rstEmployees.EOF) { - if (rstEmployees.Fields.Item('Title').Value === 'Sales Representative') { + if (rstEmployees('Title').Value === 'Sales Representative') { rstEmployees.Edit(); - rstEmployees.Fields.Item('Title').Value = 'Account Executive'; + rstEmployees('Title').Value = 'Account Executive'; rstEmployees.Update(); } rstEmployees.MoveNext(); diff --git a/types/activex-dao/index.d.ts b/types/activex-dao/index.d.ts index 6db3e0bd0d..a2a159e324 100644 --- a/types/activex-dao/index.d.ts +++ b/types/activex-dao/index.d.ts @@ -1,8 +1,8 @@ -// Type definitions for Microsoft Office 14.0 Access Database Engine Object Library - DAO 14.0 +// Type definitions for Microsoft Office 16.0 Access Database Engine Object Library - DAO 16.0 // Project: https://msdn.microsoft.com/en-us/library/dn124645.aspx // Definitions by: Zev Spitz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.4 +// TypeScript Version: 2.6 declare namespace DAO { const enum _DAOSuppHelp { @@ -56,12 +56,15 @@ declare namespace DAO { } const enum DatabaseTypeEnum { + /** @deprecated */ dbDecrypt = 4, + /** @deprecated */ dbEncrypt = 2, dbVersion10 = 1, dbVersion11 = 8, dbVersion120 = 128, dbVersion140 = 256, + dbVersion150 = 512, dbVersion20 = 16, dbVersion30 = 32, dbVersion40 = 64, @@ -128,6 +131,15 @@ declare namespace DAO { dbRefreshCache = 8, } + const enum ISAMStatsEnum { + DiskReads = 0, + DiskWrites = 1, + LocksPlaced = 4, + LocksReleased = 5, + ReadsFromCache = 2, + ReadsFromReadAheadCache = 3, + } + const enum LanguageConstants { dbLangArabic = ';LANGID=0x0401;CP=1256;COUNTRY=0', dbLangChineseSimplified = ';LANGID=0x0804;CP=936;COUNTRY=0', @@ -308,18 +320,26 @@ declare namespace DAO { dbUseODBC = 1, } + type Bookmark = SafeArray; + + class ComplexType { + private 'DAO.ComplexType_typekey': ComplexType; + private constructor(); + readonly Fields: Fields; + } + class Connection { private 'DAO.Connection_typekey': Connection; private constructor(); Cancel(): void; Close(): void; readonly Connect: string; - CreateQueryDef(Name?: any, SQLText?: any): QueryDef; + CreateQueryDef(Name?: string, SQLText?: string): QueryDef; readonly Database: Database; - Execute(Query: string, Options?: any): void; + Execute(Query: string, Options?: RecordsetOptionEnum): void; readonly hDbc: number; readonly Name: string; - OpenRecordset(Name: string, Type?: any, Options?: any, LockEdit?: any): Recordset; + OpenRecordset(Name: string, Type?: RecordsetTypeEnum, Options?: RecordsetOptionEnum, LockEdit?: LockTypeEnum): Recordset; readonly QueryDefs: QueryDefs; QueryTimeout: number; readonly RecordsAffected: number; @@ -329,12 +349,11 @@ declare namespace DAO { readonly Updatable: boolean; } - class Connections { - private 'DAO.Connections_typekey': Connections; - private constructor(); + interface Connections { readonly Count: number; - Item(Item: any): Connection; + Item(Item: number | string): Connection; Refresh(): void; + (Item: number | string): Connection; } class Container { @@ -350,12 +369,11 @@ declare namespace DAO { UserName: string; } - class Containers { - private 'DAO.Containers_typekey': Containers; - private constructor(); + interface Containers { readonly Count: number; - Item(Item: any): Container; + Item(Item: number | string): Container; Refresh(): void; + (Item: number | string): Container; } class Database { @@ -366,16 +384,16 @@ declare namespace DAO { Connect: string; readonly Connection: Connection; readonly Containers: Containers; - CreateProperty(Name?: any, Type?: any, Value?: any, DDL?: any): Property; - CreateQueryDef(Name?: any, SQLText?: any): QueryDef; - CreateRelation(Name?: any, Table?: any, ForeignTable?: any, Attributes?: any): Relation; - CreateTableDef(Name?: any, Attributes?: any, SourceTableName?: any, Connect?: any): TableDef; + CreateProperty(Name?: string, Type?: DataTypeEnum, Value?: any, DDL?: boolean): Property; + CreateQueryDef(Name?: string, SQLText?: string): QueryDef; + CreateRelation(Name?: string, Table?: string, ForeignTable?: string, Attributes?: RelationAttributeEnum): Relation; + CreateTableDef(Name?: string, Attributes?: TableDefAttributeEnum, SourceTableName?: string, Connect?: string): TableDef; DesignMasterID: string; - Execute(Query: string, Options?: any): void; - MakeReplica(PathName: string, Description: string, Options?: any): void; + Execute(Query: string, Options?: RecordsetOptionEnum): void; + MakeReplica(PathName: string, Description: string, Options?: ReplicaTypeEnum): void; readonly Name: string; NewPassword(bstrOld: string, bstrNew: string): void; - OpenRecordset(Name: string, Type?: any, Options?: any, LockEdit?: any): Recordset; + OpenRecordset(Name: string, Type?: RecordsetTypeEnum, Options?: RecordsetOptionEnum, LockEdit?: LockTypeEnum): Recordset; PopulatePartial(DbPathName: string): void; readonly Properties: Properties; readonly QueryDefs: QueryDefs; @@ -384,19 +402,18 @@ declare namespace DAO { readonly Recordsets: Recordsets; readonly Relations: Relations; readonly ReplicaID: string; - Synchronize(DbPathName: string, ExchangeType?: any): void; + Synchronize(DbPathName: string, ExchangeType?: SynchronizeTypeEnum): void; readonly TableDefs: TableDefs; readonly Transactions: boolean; readonly Updatable: boolean; readonly Version: string; } - class Databases { - private 'DAO.Databases_typekey': Databases; - private constructor(); + interface Databases { readonly Count: number; - Item(Item: any): Database; + Item(Item: number | string): Database; Refresh(): void; + (Item: number | string): Database; } class DBEngine { @@ -404,26 +421,51 @@ declare namespace DAO { private constructor(); BeginTrans(): void; - /** @param number [Option=0] */ + /** @param Option [Option=0] */ CommitTrans(Option?: number): void; - CompactDatabase(SrcName: string, DstName: string, DstLocale?: any, Options?: any, SrcLocale?: any): void; - CreateDatabase(Name: string, Locale: string, Option?: any): Database; - CreateWorkspace(Name: string, UserName: string, Password: string, UseType?: any): Workspace; + + /** + * Compact a closed database + * + * @param DstLocale Specify one of the following: + * * the locale, using one of the language constants + * * the password, in the form `;pwd=MyNewPassword'` + * * both the constant and a password, e.g. `dbLangGreek + ';pwd=MyNewPassword'` + * + * @param Options `dbEncrypt` and `dbDecrypt` are deprecated, and unsupported for ACCDB + * @param password Deprecated, and unsupported for ACCDB + */ + CompactDatabase(SrcName: string, DstName: string, DstLocale?: LanguageConstants | string, Options?: DatabaseTypeEnum, password?: string): void; + + /** + * @param Locale Specify one of the following: + * * the locale, using one of the language constants + * * the password, in the form `;pwd=MyNewPassword'` + * * both the constant and a password, e.g. `dbLangGreek + ';pwd=MyNewPassword'` + */ + CreateDatabase(Name: string, Locale: LanguageConstants | string, Option?: DatabaseTypeEnum): Database; + CreateWorkspace(Name: string, UserName: string, Password: string, UseType?: WorkspaceTypeEnum): Workspace; readonly DefaultPassword: string; DefaultType: number; readonly DefaultUser: string; readonly Errors: Errors; - Idle(Action?: any): void; + Idle(Action?: IdleEnum): void; IniPath: string; - ISAMStats(StatNum: number, Reset?: any): number; + + /** Returns various statistics from the Jet engine */ + ISAMStats(StatNum: ISAMStatsEnum, Reset?: boolean): number; LoginTimeout: number; - OpenConnection(Name: string, Options?: any, ReadOnly?: any, Connect?: any): Connection; - OpenDatabase(Name: string, Options?: any, ReadOnly?: any, Connect?: any): Database; + + /** + * @param Connect ODBC connection string; prepend with `ODBC;` + */ + OpenConnection(Name: string, Options?: DriverPromptEnum | RecordsetOptionEnum.dbRunAsync, ReadOnly?: boolean, Connect?: string): Connection; + OpenDatabase(Name: string, Exclusive?: boolean, ReadOnly?: boolean, Connect?: string): Database; readonly Properties: Properties; RegisterDatabase(Dsn: string, Driver: string, Silent: boolean, Attributes: string): void; RepairDatabase(Name: string): void; Rollback(): void; - SetOption(Option: number, Value: any): void; + SetOption(Option: SetOptionEnum, Value: any): void; SystemDB: string; readonly Version: string; readonly Workspaces: Workspaces; @@ -434,9 +476,9 @@ declare namespace DAO { private constructor(); readonly AllPermissions: number; readonly Container: string; - CreateProperty(Name?: any, Type?: any, Value?: any, DDL?: any): Property; - readonly DateCreated: any; - readonly LastUpdated: any; + CreateProperty(Name?: string, Type?: DataTypeEnum, Value?: any, DDL?: boolean): Property; + readonly DateCreated: VarDate; + readonly LastUpdated: VarDate; readonly Name: string; Owner: string; Permissions: number; @@ -444,12 +486,11 @@ declare namespace DAO { UserName: string; } - class Documents { - private 'DAO.Documents_typekey': Documents; - private constructor(); + interface Documents { readonly Count: number; - Item(Item: any): Document; + Item(Item: number | string): Document; Refresh(): void; + (Item: number | string): Document; } class Error { @@ -462,33 +503,38 @@ declare namespace DAO { readonly Source: string; } - class Errors { - private 'DAO.Errors_typekey': Errors; - private constructor(); + interface Errors { readonly Count: number; Item(Item: any): Error; Refresh(): void; + (Item: any): Error; } class Field { - private 'DAO.Field_typekey': Field; private constructor(); + private 'DAO.Field2_typekey': Field; AllowZeroLength: boolean; AppendChunk(Val: any): void; + AppendOnly: boolean; Attributes: number; readonly CollatingOrder: number; readonly CollectionIndex: number; - CreateProperty(Name?: any, Type?: any, Value?: any, DDL?: any): Property; + readonly ComplexType: ComplexType; + CreateProperty(Name?: string, Type?: DataTypeEnum, Value?: any, DDL?: boolean): Property; readonly DataUpdatable: boolean; DefaultValue: any; + Expression: string; readonly FieldSize: number; ForeignName: string; GetChunk(Offset: number, Bytes: number): any; + readonly IsComplex: boolean; + LoadFromFile(FileName: string): void; Name: string; OrdinalPosition: number; readonly OriginalValue: any; readonly Properties: Properties; Required: boolean; + SaveToFile(FileName: string): void; Size: number; readonly SourceField: string; readonly SourceTable: string; @@ -500,44 +546,42 @@ declare namespace DAO { readonly VisibleValue: any; } - class Fields { - private 'DAO.Fields_typekey': Fields; - private constructor(); - Append(Object: any): void; + interface Fields { + Append(Field: Field): void; readonly Count: number; Delete(Name: string): void; - Item(Item: any): Field; + Item(Item: number | string): Field; Refresh(): void; + (Item: number | string): Field; } class Group { private 'DAO.Group_typekey': Group; private constructor(); - CreateUser(Name?: any, PID?: any, Password?: any): User; + CreateUser(Name?: string, PID?: string, Password?: string): User; Name: string; readonly PID: string; readonly Properties: Properties; readonly Users: Users; } - class Groups { - private 'DAO.Groups_typekey': Groups; - private constructor(); - Append(Object: any): void; + interface Groups { + Append(Group: Group): void; readonly Count: number; Delete(Name: string): void; - Item(Item: any): Group; + Item(Item: number | string): Group; Refresh(): void; + (Item: number | string): Group; } class Index { private 'DAO.Index_typekey': Index; private constructor(); Clustered: boolean; - CreateField(Name?: any, Type?: any, Size?: any): Field; - CreateProperty(Name?: any, Type?: any, Value?: any, DDL?: any): Property; + CreateField(Name?: string): Field; + CreateProperty(Name?: string, Type?: DataTypeEnum, Value?: any, DDL?: boolean): Property; readonly DistinctCount: number; - Fields: any; + Fields: Fields; readonly Foreign: boolean; IgnoreNulls: boolean; Name: string; @@ -547,14 +591,14 @@ declare namespace DAO { Unique: boolean; } - class Indexes { - private 'DAO.Indexes_typekey': Indexes; - private constructor(); - Append(Object: any): void; + // tslint:disable-next-line:interface-name + interface Indexes { + Append(Index: Index): void; readonly Count: number; Delete(Name: string): void; - Item(Item: any): Index; + Item(Item: number | string): Index; Refresh(): void; + (Item: number | string): Index; } class Parameter { @@ -567,53 +611,20 @@ declare namespace DAO { Value: any; } - class Parameters { - private 'DAO.Parameters_typekey': Parameters; - private constructor(); + interface Parameters { readonly Count: number; - Item(Item: any): Parameter; + Item(Item: number | string): Parameter; Refresh(): void; + (Item: number | string): Parameter; } - /** DAO 3.0 DBEngine (private) */ - class PrivDBEngine { - private 'DAO.PrivDBEngine_typekey': PrivDBEngine; - private constructor(); - BeginTrans(): void; - - /** @param number [Option=0] */ - CommitTrans(Option?: number): void; - CompactDatabase(SrcName: string, DstName: string, DstLocale?: any, Options?: any, SrcLocale?: any): void; - CreateDatabase(Name: string, Locale: string, Option?: any): Database; - CreateWorkspace(Name: string, UserName: string, Password: string, UseType?: any): Workspace; - readonly DefaultPassword: string; - DefaultType: number; - readonly DefaultUser: string; - readonly Errors: Errors; - Idle(Action?: any): void; - IniPath: string; - ISAMStats(StatNum: number, Reset?: any): number; - LoginTimeout: number; - OpenConnection(Name: string, Options?: any, ReadOnly?: any, Connect?: any): Connection; - OpenDatabase(Name: string, Options?: any, ReadOnly?: any, Connect?: any): Database; - readonly Properties: Properties; - RegisterDatabase(Dsn: string, Driver: string, Silent: boolean, Attributes: string): void; - RepairDatabase(Name: string): void; - Rollback(): void; - SetOption(Option: number, Value: any): void; - SystemDB: string; - readonly Version: string; - readonly Workspaces: Workspaces; - } - - class Properties { - private 'DAO.Properties_typekey': Properties; - private constructor(); - Append(Object: any): void; + interface Properties { + Append(Property: Property): void; readonly Count: number; Delete(Name: string): void; - Item(Item: any): Property; + Item(Item: number | string): Property; Refresh(): void; + (Item: number | string): Property; } class Property { @@ -633,81 +644,78 @@ declare namespace DAO { Cancel(): void; Close(): void; Connect: string; - CreateProperty(Name?: any, Type?: any, Value?: any, DDL?: any): Property; - readonly DateCreated: any; - Execute(Options?: any): void; + CreateProperty(Name?: string, Type?: DataTypeEnum, Value?: any, DDL?: boolean): Property; + readonly DateCreated: VarDate; + Execute(Options?: RecordsetOptionEnum): void; readonly Fields: Fields; readonly hStmt: number; - readonly LastUpdated: any; + readonly LastUpdated: VarDate; MaxRecords: number; Name: string; ODBCTimeout: number; - OpenRecordset(Type?: any, Options?: any, LockEdit?: any): Recordset; + OpenRecordset(Type?: RecordsetTypeEnum, Options?: RecordsetOptionEnum, LockEdit?: LockTypeEnum): Recordset; readonly Parameters: Parameters; - Prepare: any; + Prepare: QueryDefStateEnum; readonly Properties: Properties; readonly RecordsAffected: number; ReturnsRecords: boolean; SQL: string; readonly StillExecuting: boolean; - readonly Type: number; + readonly Type: QueryDefTypeEnum; readonly Updatable: boolean; } - class QueryDefs { - private 'DAO.QueryDefs_typekey': QueryDefs; - private constructor(); - Append(Object: any): void; + interface QueryDefs { + Append(QueryDef: QueryDef): void; readonly Count: number; Delete(Name: string): void; - Item(Item: any): QueryDef; + Item(Item: number | string): QueryDef; Refresh(): void; + (Item: number | string): QueryDef; } - class Recordset { - private 'DAO.Recordset_typekey': Recordset; - private constructor(); + interface Recordset { AbsolutePosition: number; AddNew(): void; readonly BatchCollisionCount: number; - readonly BatchCollisions: any; + readonly BatchCollisions: SafeArray; BatchSize: number; readonly BOF: boolean; - Bookmark: SafeArray; + Bookmark: Bookmark; readonly Bookmarkable: boolean; CacheSize: number; - CacheStart: SafeArray; + CacheStart: Bookmark; Cancel(): void; - /** @param number [UpdateType=1] */ + /** @param UpdateType [UpdateType=1] */ CancelUpdate(UpdateType?: number): void; Clone(): Recordset; Close(): void; Collect(Item: any): any; Connection: Connection; CopyQueryDef(): QueryDef; - readonly DateCreated: any; + readonly DateCreated: VarDate; Delete(): void; Edit(): void; - readonly EditMode: number; + readonly EditMode: EditModeEnum; readonly EOF: boolean; readonly Fields: Fields; - FillCache(Rows?: any, StartBookmark?: any): void; + FillCache(Rows?: number, StartBookmark?: string): void; Filter: string; FindFirst(Criteria: string): void; FindLast(Criteria: string): void; FindNext(Criteria: string): void; FindPrevious(Criteria: string): void; - GetRows(NumRows?: any): any; + GetRows(NumRows?: number): any; readonly hStmt: number; Index: string; - readonly LastModified: SafeArray; - readonly LastUpdated: any; + readonly LastModified: Bookmark; + readonly LastUpdated: VarDate; LockEdits: boolean; - Move(Rows: number, StartBookmark?: any): void; + Move(Rows: number, StartBookmark?: Bookmark): void; MoveFirst(): void; - /** @param number [Options=0] */ + /** @param Options [Options=0] */ MoveLast(Options?: number): void; MoveNext(): void; MovePrevious(): void; @@ -716,45 +724,44 @@ declare namespace DAO { readonly NoMatch: boolean; readonly ODBCFetchCount: number; readonly ODBCFetchDelay: number; - OpenRecordset(Type?: any, Options?: any): Recordset; + OpenRecordset(Type?: RecordsetTypeEnum, Options?: RecordsetOptionEnum): Recordset; readonly Parent: Database; PercentPosition: number; readonly Properties: Properties; readonly RecordCount: number; readonly RecordStatus: number; - Requery(NewQueryDef?: any): void; + Requery(NewQueryDef?: QueryDef): void; readonly Restartable: boolean; - Seek( - Comparison: string, Key1: any, Key2?: any, Key3?: any, Key4?: any, Key5?: any, Key6?: any, Key7?: any, Key8?: any, Key9?: any, Key10?: any, Key11?: any, Key12?: any, Key13?: any): void; + Seek(Comparison: string, Key1: any, Key2?: any, Key3?: any, Key4?: any, Key5?: any, Key6?: any, Key7?: any, Key8?: any, Key9?: any, Key10?: any, Key11?: any, Key12?: any, Key13?: any): void; Sort: string; readonly StillExecuting: boolean; readonly Transactions: boolean; - readonly Type: number; + readonly Type: RecordsetTypeEnum; readonly Updatable: boolean; /** - * @param number [UpdateType=1] - * @param boolean [Force=false] + * @param UpdateType [UpdateType=1] + * @param Force [Force=false] */ - Update(UpdateType?: number, Force?: boolean): void; - UpdateOptions: number; + Update(UpdateType?: UpdateTypeEnum, Force?: boolean): void; + UpdateOptions: UpdateCriteriaEnum; readonly ValidationRule: string; readonly ValidationText: string; + (FieldIndex: number | string): Field; } - class Recordsets { - private 'DAO.Recordsets_typekey': Recordsets; - private constructor(); + interface Recordsets { readonly Count: number; - Item(Item: any): Recordset; + Item(Item: number | string): Recordset; Refresh(): void; + (Item: number | string): Recordset; } class Relation { private 'DAO.Relation_typekey': Relation; private constructor(); - Attributes: number; - CreateField(Name?: any, Type?: any, Size?: any): Field; + Attributes: RelationAttributeEnum; + CreateField(Name?: string): Field; readonly Fields: Fields; ForeignTable: string; Name: string; @@ -763,55 +770,53 @@ declare namespace DAO { Table: string; } - class Relations { - private 'DAO.Relations_typekey': Relations; - private constructor(); - Append(Object: any): void; + interface Relations { + Append(Relation: Relation): void; readonly Count: number; Delete(Name: string): void; - Item(Item: any): Relation; + Item(Item: number | string): Relation; Refresh(): void; + (Item: number | string): Relation; } class TableDef { private 'DAO.TableDef_typekey': TableDef; private constructor(); - Attributes: number; + Attributes: TableDefAttributeEnum; readonly ConflictTable: string; Connect: string; - CreateField(Name?: any, Type?: any, Size?: any): Field; - CreateIndex(Name?: any): Index; - CreateProperty(Name?: any, Type?: any, Value?: any, DDL?: any): Property; - readonly DateCreated: any; + CreateField(Name?: string, Type?: DataTypeEnum, Size?: number): Field; + CreateIndex(Name?: string): Index; + CreateProperty(Name?: string, Type?: DataTypeEnum, Value?: any, DDL?: boolean): Property; + readonly DateCreated: VarDate; readonly Fields: Fields; readonly Indexes: Indexes; - readonly LastUpdated: any; + readonly LastUpdated: VarDate; Name: string; - OpenRecordset(Type?: any, Options?: any): Recordset; + OpenRecordset(Type?: RecordsetTypeEnum, Options?: RecordsetOptionEnum): Recordset; readonly Properties: Properties; readonly RecordCount: number; RefreshLink(): void; - ReplicaFilter: any; + ReplicaFilter: string | boolean; SourceTableName: string; readonly Updatable: boolean; ValidationRule: string; ValidationText: string; } - class TableDefs { - private 'DAO.TableDefs_typekey': TableDefs; - private constructor(); - Append(Object: any): void; + interface TableDefs { + Append(TableDef: TableDef): void; readonly Count: number; Delete(Name: string): void; - Item(Item: any): TableDef; + Item(Item: number | string): TableDef; Refresh(): void; + (Item: number | string): TableDef; } class User { private 'DAO.User_typekey': User; private constructor(); - CreateGroup(Name?: any, PID?: any): Group; + CreateGroup(Name?: string, PID?: string): Group; readonly Groups: Groups; Name: string; NewPassword(bstrOld: string, bstrNew: string): void; @@ -820,14 +825,13 @@ declare namespace DAO { readonly Properties: Properties; } - class Users { - private 'DAO.Users_typekey': Users; - private constructor(); - Append(Object: any): void; + interface Users { + Append(User: User): void; readonly Count: number; Delete(Name: string): void; - Item(Item: any): User; + Item(Item: number | string): User; Refresh(): void; + (Item: number | string): User; } class Workspace { @@ -836,12 +840,19 @@ declare namespace DAO { BeginTrans(): void; Close(): void; - /** @param number [Options=0] */ + /** @param Options [Options=0] */ CommitTrans(Options?: number): void; readonly Connections: Connections; - CreateDatabase(Name: string, Connect: string, Option?: any): Database; - CreateGroup(Name?: any, PID?: any): Group; - CreateUser(Name?: any, PID?: any, Password?: any): User; + + /** + * @param Connect Specify one of the following: + * * the locale, using one of the language constants + * * the password, in the form `;pwd=MyNewPassword'` + * * both the constant and a password, e.g. `dbLangGreek + ';pwd=MyNewPassword'` + */ + CreateDatabase(Name: string, Connect: string, Option?: DatabaseTypeEnum): Database; + CreateGroup(Name?: string, PID?: string): Group; + CreateUser(Name?: string, PID?: string, Password?: string): User; readonly Databases: Databases; DefaultCursorDriver: number; readonly Groups: Groups; @@ -849,8 +860,12 @@ declare namespace DAO { IsolateODBCTrans: number; LoginTimeout: number; Name: string; - OpenConnection(Name: string, Options?: any, ReadOnly?: any, Connect?: any): Connection; - OpenDatabase(Name: string, Options?: any, ReadOnly?: any, Connect?: any): Database; + + /** + * @param Connect ODBC connection string; prepend with `ODBC;` + */ + OpenConnection(Name: string, Options?: DriverPromptEnum | RecordsetOptionEnum.dbRunAsync, ReadOnly?: boolean, Connect?: string): Connection; + OpenDatabase(Name: string, Exclusive?: boolean, ReadOnly?: boolean, Connect?: string): Database; readonly Properties: Properties; Rollback(): void; readonly Type: number; @@ -858,14 +873,13 @@ declare namespace DAO { readonly Users: Users; } - class Workspaces { - private 'DAO.Workspaces_typekey': Workspaces; - private constructor(); - Append(Object: any): void; + interface Workspaces { + Append(Workspace: Workspace): void; readonly Count: number; Delete(Name: string): void; - Item(Item: any): Workspace; + Item(Item: number | string): Workspace; Refresh(): void; + (Item: number | string): Workspace; } } @@ -875,36 +889,12 @@ interface ActiveXObject { interface ActiveXObjectNameMap { 'DAO.DBEngine': DAO.DBEngine; - 'DAO.DBEngine.120': DAO.DBEngine; 'DAO.Field': DAO.Field; 'DAO.Group': DAO.Group; 'DAO.Index': DAO.Index; - 'DAO.PrivateDBEngine': DAO.PrivDBEngine; + 'DAO.PrivateDBEngine': DAO.DBEngine; 'DAO.QueryDef': DAO.QueryDef; 'DAO.Relation': DAO.Relation; 'DAO.TableDef': DAO.TableDef; 'DAO.User': DAO.User; } - -interface EnumeratorConstructor { - new(col: DAO.Connections): Enumerator; - new(col: DAO.Containers): Enumerator; - new(col: DAO.Databases): Enumerator; - new(col: DAO.Documents): Enumerator; - new(col: DAO.Errors): Enumerator; - new(col: DAO.Fields): Enumerator; - new(col: DAO.Groups): Enumerator; - new(col: DAO.Indexes): Enumerator; - new(col: DAO.Parameters): Enumerator; - new(col: DAO.Properties): Enumerator; - new(col: DAO.QueryDefs): Enumerator; - new(col: DAO.Recordsets): Enumerator; - new(col: DAO.Relations): Enumerator; - new(col: DAO.TableDefs): Enumerator; - new(col: DAO.Users): Enumerator; - new(col: DAO.Workspaces): Enumerator; -} - -interface SafeArray { - _brand: SafeArray; -} diff --git a/types/aws-lambda-mock-context/index.d.ts b/types/aws-lambda-mock-context/index.d.ts index 6fc5fda67a..b5a3768f2d 100644 --- a/types/aws-lambda-mock-context/index.d.ts +++ b/types/aws-lambda-mock-context/index.d.ts @@ -26,10 +26,10 @@ interface Context { } interface Options { - region: string; - account: string; - functionName: string; - functionVersion: string; - memoryLimitInMB: string; + region?: string; + account?: string; + functionName?: string; + functionVersion?: string; + memoryLimitInMB?: string; alias?: string; } diff --git a/types/chai/chai-tests.ts b/types/chai/chai-tests.ts index 57b7d127ac..f19514fe71 100644 --- a/types/chai/chai-tests.ts +++ b/types/chai/chai-tests.ts @@ -191,6 +191,18 @@ function within() { expect(10).to.be.within(50, 100, 'blah'); (10).should.be.within(50, 100, 'blah'); + expect(new Date('December 17, 1995 03:24:30')).to.not.be.within(new Date('December 17, 1995 03:24:20'), new Date('December 17, 1995 03:24:40')); + new Date('December 17, 1995 03:24:30').should.not.be.within(new Date('December 17, 1995 03:24:20'), new Date('December 17, 1995 03:24:40')); + + expect(new Date('December 17, 1995 03:24:30')).to.be.within(new Date('December 17, 1995 03:24:20'), new Date('December 17, 1995 03:24:40')); + new Date('December 17, 1995 03:24:30').should.be.within(new Date('December 17, 1995 03:24:20'), new Date('December 17, 1995 03:24:40')); + + expect(new Date('December 17, 1995 03:24:30')).to.not.be.within(new Date('December 17, 1995 03:24:20'), new Date('December 17, 1995 03:24:40'), 'blah'); + new Date('December 17, 1995 03:24:30').should.not.be.within(new Date('December 17, 1995 03:24:20'), new Date('December 17, 1995 03:24:40'), 'blah'); + + expect(new Date('December 17, 1995 03:24:30')).to.be.within(new Date('December 17, 1995 03:24:20'), new Date('December 17, 1995 03:24:40'), 'blah'); + new Date('December 17, 1995 03:24:30').should.be.within(new Date('December 17, 1995 03:24:20'), new Date('December 17, 1995 03:24:40'), 'blah'); + expect('foo').to.have.length.within(5, 7, 'blah'); 'foo'.should.have.length.within(5, 7, 'blah'); @@ -218,6 +230,18 @@ function above() { expect(10).to.not.be.above(6, 'blah'); (10).should.not.be.above(6, 'blah'); + expect(new Date('December 17, 1995 03:24:30')).to.not.be.above(new Date('December 17, 1995 03:24:20')); + new Date('December 17, 1995 03:24:30').should.not.be.above(new Date('December 17, 1995 03:24:20')); + + expect(new Date('December 17, 1995 03:24:30')).to.be.above(new Date('December 17, 1995 03:24:20')); + new Date('December 17, 1995 03:24:30').should.be.above(new Date('December 17, 1995 03:24:20')); + + expect(new Date('December 17, 1995 03:24:30')).to.not.be.above(new Date('December 17, 1995 03:24:20'), 'blah'); + new Date('December 17, 1995 03:24:30').should.not.be.above(new Date('December 17, 1995 03:24:20'), 'blah'); + + expect(new Date('December 17, 1995 03:24:30')).to.be.above(new Date('December 17, 1995 03:24:20'), 'blah'); + new Date('December 17, 1995 03:24:30').should.be.above(new Date('December 17, 1995 03:24:20'), 'blah'); + expect('foo').to.have.length.above(4, 'blah'); 'foo'.should.have.length.above(4, 'blah'); @@ -243,6 +267,18 @@ function least() { expect(10).to.not.be.at.least(6, 'blah'); (10).should.not.be.at.least(6, 'blah'); + expect(new Date('December 17, 1995 03:24:30')).to.not.be.least(new Date('December 17, 1995 03:24:20')); + new Date('December 17, 1995 03:24:30').should.not.be.least(new Date('December 17, 1995 03:24:20')); + + expect(new Date('December 17, 1995 03:24:30')).to.be.least(new Date('December 17, 1995 03:24:20')); + new Date('December 17, 1995 03:24:30').should.be.least(new Date('December 17, 1995 03:24:20')); + + expect(new Date('December 17, 1995 03:24:30')).to.not.be.least(new Date('December 17, 1995 03:24:20'), 'blah'); + new Date('December 17, 1995 03:24:30').should.not.be.least(new Date('December 17, 1995 03:24:20'), 'blah'); + + expect(new Date('December 17, 1995 03:24:30')).to.be.least(new Date('December 17, 1995 03:24:20'), 'blah'); + new Date('December 17, 1995 03:24:30').should.be.least(new Date('December 17, 1995 03:24:20'), 'blah'); + expect('foo').to.have.length.of.at.least(4, 'blah'); 'foo'.should.have.length.of.at.least(4, 'blah'); @@ -273,6 +309,18 @@ function below() { expect(6).to.not.be.below(10, 'blah'); (6).should.not.be.below(10, 'blah'); + expect(new Date('December 17, 1995 03:24:30')).to.not.be.below(new Date('December 17, 1995 03:24:20')); + new Date('December 17, 1995 03:24:30').should.not.be.below(new Date('December 17, 1995 03:24:20')); + + expect(new Date('December 17, 1995 03:24:30')).to.be.below(new Date('December 17, 1995 03:24:20')); + new Date('December 17, 1995 03:24:30').should.be.below(new Date('December 17, 1995 03:24:20')); + + expect(new Date('December 17, 1995 03:24:30')).to.not.be.below(new Date('December 17, 1995 03:24:20'), 'blah'); + new Date('December 17, 1995 03:24:30').should.not.be.below(new Date('December 17, 1995 03:24:20'), 'blah'); + + expect(new Date('December 17, 1995 03:24:30')).to.be.below(new Date('December 17, 1995 03:24:20'), 'blah'); + new Date('December 17, 1995 03:24:30').should.be.below(new Date('December 17, 1995 03:24:20'), 'blah'); + expect('foo').to.have.length.below(2, 'blah'); 'foo'.should.have.length.below(2, 'blah'); @@ -300,6 +348,18 @@ function most() { expect(6).to.not.be.at.most(10, 'blah'); (6).should.not.be.at.most(10, 'blah'); + expect(new Date('December 17, 1995 03:24:30')).to.not.be.most(new Date('December 17, 1995 03:24:20')); + new Date('December 17, 1995 03:24:30').should.not.be.most(new Date('December 17, 1995 03:24:20')); + + expect(new Date('December 17, 1995 03:24:30')).to.be.most(new Date('December 17, 1995 03:24:20')); + new Date('December 17, 1995 03:24:30').should.be.most(new Date('December 17, 1995 03:24:20')); + + expect(new Date('December 17, 1995 03:24:30')).to.not.be.most(new Date('December 17, 1995 03:24:20'), 'blah'); + new Date('December 17, 1995 03:24:30').should.not.be.most(new Date('December 17, 1995 03:24:20'), 'blah'); + + expect(new Date('December 17, 1995 03:24:30')).to.be.most(new Date('December 17, 1995 03:24:20'), 'blah'); + new Date('December 17, 1995 03:24:30').should.be.most(new Date('December 17, 1995 03:24:20'), 'blah'); + expect('foo').to.have.length.of.at.most(2, 'blah'); 'foo'.should.have.length.of.at.most(2, 'blah'); diff --git a/types/chai/index.d.ts b/types/chai/index.d.ts index 02bca8909f..d0f5ab099c 100644 --- a/types/chai/index.d.ts +++ b/types/chai/index.d.ts @@ -9,6 +9,7 @@ // Shaun Luttin // Gintautas Miselis // Satana Charuwichitratana +// Erik Schierboom // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace Chai { @@ -150,10 +151,11 @@ declare namespace Chai { most: NumberComparer; lte: NumberComparer; within(start: number, finish: number, message?: string): Assertion; + within(start: Date, finish: Date, message?: string): Assertion; } interface NumberComparer { - (value: number, message?: string): Assertion; + (value: number | Date, message?: string): Assertion; } interface TypeComparison { diff --git a/types/node-common-errors/node-common-errors-tests.ts b/types/common-errors/common-errors-tests.ts similarity index 98% rename from types/node-common-errors/node-common-errors-tests.ts rename to types/common-errors/common-errors-tests.ts index 9554c31dff..ed2c1cdf15 100644 --- a/types/node-common-errors/node-common-errors-tests.ts +++ b/types/common-errors/common-errors-tests.ts @@ -1,4 +1,4 @@ -import * as errors from 'node-common-errors'; +import * as errors from 'common-errors'; errors.log(new Error()); // $ExpectType Error errors.log(new Error(), ''); // $ExpectType Error diff --git a/types/node-common-errors/index.d.ts b/types/common-errors/index.d.ts similarity index 99% rename from types/node-common-errors/index.d.ts rename to types/common-errors/index.d.ts index 06bcb9e754..da0230b084 100644 --- a/types/node-common-errors/index.d.ts +++ b/types/common-errors/index.d.ts @@ -1,5 +1,5 @@ -// Type definitions for node-common-errors 0.4 -// Project: https://github.com/shutterstock/node-errors +// Type definitions for common-errors 1.0 +// Project: https://github.com/shutterstock/node-common-errors // Definitions by: Ian Copp // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 diff --git a/types/node-common-errors/tsconfig.json b/types/common-errors/tsconfig.json similarity index 92% rename from types/node-common-errors/tsconfig.json rename to types/common-errors/tsconfig.json index a862893b87..a4c4800e39 100644 --- a/types/node-common-errors/tsconfig.json +++ b/types/common-errors/tsconfig.json @@ -18,6 +18,6 @@ }, "files": [ "index.d.ts", - "node-common-errors-tests.ts" + "common-errors-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/node-common-errors/tslint.json b/types/common-errors/tslint.json similarity index 100% rename from types/node-common-errors/tslint.json rename to types/common-errors/tslint.json diff --git a/types/ember-data/index.d.ts b/types/ember-data/index.d.ts index 5e4fa4eb60..a5918f9375 100644 --- a/types/ember-data/index.d.ts +++ b/types/ember-data/index.d.ts @@ -43,7 +43,7 @@ declare module 'ember-data' { isRelationship: true; } - namespace DS { + export namespace DS { /** * Convert an hash of errors into an array with errors in JSON-API format. */ diff --git a/types/eventsource/eventsource-tests.ts b/types/eventsource/eventsource-tests.ts index d081e87e42..62f867926f 100644 --- a/types/eventsource/eventsource-tests.ts +++ b/types/eventsource/eventsource-tests.ts @@ -4,6 +4,7 @@ const eventSource = new EventSource("http://foobar"); eventSource.onmessage = (x: any) => {}; eventSource.onerror = (x: any) => {}; eventSource.onopen = (x: any) => {}; +eventSource.addEventListener = (type: string, x: any) => {}; eventSource.close(); import EventSourcePolyfill = require("eventsource/lib/eventsource-polyfill"); @@ -12,4 +13,5 @@ const eventSourcePolyfill = new EventSourcePolyfill("http://foobar"); eventSourcePolyfill.onmessage = (x: any) => {}; eventSourcePolyfill.onerror = (x: any) => {}; eventSourcePolyfill.onopen = (x: any) => {}; +eventSourcePolyfill.addEventListener = (type: string, x: any) => {}; eventSourcePolyfill.close(); diff --git a/types/eventsource/index.d.ts b/types/eventsource/index.d.ts index 3620b6116f..62859d037b 100644 --- a/types/eventsource/index.d.ts +++ b/types/eventsource/index.d.ts @@ -16,6 +16,7 @@ declare class EventSource { onopen: EventListener; onmessage: EventListener; onerror: EventListener; + addEventListener(type: string, listener: EventListener): void; close(): void; } diff --git a/types/eventsource/lib/eventsource-polyfill/index.d.ts b/types/eventsource/lib/eventsource-polyfill/index.d.ts index 6246355dfe..3e4ad378e4 100644 --- a/types/eventsource/lib/eventsource-polyfill/index.d.ts +++ b/types/eventsource/lib/eventsource-polyfill/index.d.ts @@ -10,6 +10,7 @@ declare class EventSource { onopen: EventListener; onmessage: EventListener; onerror: EventListener; + addEventListener(type: string, listener: EventListener): void; close(): void; } diff --git a/types/gulp-mustache/gulp-mustache-tests.ts b/types/gulp-mustache/gulp-mustache-tests.ts index d8285370e7..d7fb994a58 100644 --- a/types/gulp-mustache/gulp-mustache-tests.ts +++ b/types/gulp-mustache/gulp-mustache-tests.ts @@ -4,6 +4,33 @@ import { Transform } from "stream"; mustache({ // $ExpectType Transform msg: "Hello Gulp!" }); +mustache({ + name: "Chris", + value: 10000, + taxed_value: 10000 - (10000 * 0.4), + in_ca: true +}); +mustache({ + repo: [ + { name: "resque" }, + { name: "hub" }, + { name: "rip" } + ] +}); +mustache({ + name: "Willy", + wrapped: () => { + return (text: string, render: (arg: string) => string) => { + return `${render(text)}`; + }; + } +}); +mustache({ + "person?": { name: "Jon" } +}); +mustache({ + repo: [] +}); mustache({ // $ExpectType Transform msg: "Hello Gulp!", diff --git a/types/gulp-mustache/index.d.ts b/types/gulp-mustache/index.d.ts index 13e0198558..ba6b22df9d 100644 --- a/types/gulp-mustache/index.d.ts +++ b/types/gulp-mustache/index.d.ts @@ -11,7 +11,7 @@ declare namespace GulpMustache { type View = Hash | string | undefined; interface Hash { - [key: string]: string; + [key: string]: any; } interface Options { diff --git a/types/joi/v10/index.d.ts b/types/joi/v10/index.d.ts index 9270c411aa..e21edda875 100644 --- a/types/joi/v10/index.d.ts +++ b/types/joi/v10/index.d.ts @@ -8,6 +8,7 @@ // Rytis Alekna // Pavel Ivanov // Youngrok Kim +// Conan Lai // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.4 @@ -142,6 +143,17 @@ export interface WhenOptions { otherwise?: SchemaLike; } +export interface WhenSchemaOptions { + /** + * the alternative schema type if the condition is true. Required if otherwise is missing. + */ + then?: SchemaLike; + /** + * the alternative schema type if the condition is false. Required if then is missing + */ + otherwise?: SchemaLike; +} + export interface ReferenceOptions { separator?: string; contextPrefix?: string; @@ -327,6 +339,7 @@ export interface AnySchema extends JoiObject { */ when(ref: string, options: WhenOptions): AlternativesSchema; when(ref: Reference, options: WhenOptions): AlternativesSchema; + when(ref: Schema, options: WhenSchemaOptions): AlternativesSchema; /** * Overrides the key name in error messages. @@ -878,6 +891,7 @@ export interface AlternativesSchema extends AnySchema { try(...types: SchemaLike[]): this; when(ref: string, options: WhenOptions): this; when(ref: Reference, options: WhenOptions): this; + when(ref: Schema, options: WhenSchemaOptions): this; } export interface LazySchema extends AnySchema { @@ -1160,6 +1174,7 @@ export function concat(schema: T): T; */ export function when(ref: string, options: WhenOptions): AlternativesSchema; export function when(ref: Reference, options: WhenOptions): AlternativesSchema; +export function when(ref: Schema, options: WhenSchemaOptions): AlternativesSchema; /** * Overrides the key name in error messages. diff --git a/types/joi/v10/joi-tests.ts b/types/joi/v10/joi-tests.ts index bfc6268ef7..b1f125a6ea 100644 --- a/types/joi/v10/joi-tests.ts +++ b/types/joi/v10/joi-tests.ts @@ -122,6 +122,14 @@ whenOpts = { is: schemaLike, then: schemaLike, otherwise: schemaLike }; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- +var whenSchemaOpts: Joi.WhenSchemaOptions = null; + +whenSchemaOpts = { then: schema }; +whenSchemaOpts = { otherwise: schema }; +whenSchemaOpts = { then: schemaLike, otherwise: schemaLike }; + +// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- + var refOpts: Joi.ReferenceOptions = null; refOpts = { separator: str }; @@ -263,6 +271,7 @@ namespace common { altSchema = anySchema.when(str, whenOpts); altSchema = anySchema.when(ref, whenOpts); + altSchema = anySchema.when(schema, whenSchemaOpts); anySchema = anySchema.label(str); anySchema = anySchema.raw(); @@ -350,6 +359,7 @@ namespace common_copy_paste { altSchema = arrSchema.when(str, whenOpts); altSchema = arrSchema.when(ref, whenOpts); + altSchema = arrSchema.when(schema, whenSchemaOpts); } // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- @@ -420,6 +430,7 @@ namespace common_copy_paste { altSchema = boolSchema.when(str, whenOpts); altSchema = boolSchema.when(ref, whenOpts); + altSchema = boolSchema.when(schema, whenSchemaOpts); } // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- @@ -476,6 +487,7 @@ namespace common { altSchema = binSchema.when(str, whenOpts); altSchema = binSchema.when(ref, whenOpts); + altSchema = binSchema.when(schema, whenSchemaOpts); } // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- @@ -548,6 +560,7 @@ namespace common { altSchema = dateSchema.when(str, whenOpts); altSchema = dateSchema.when(ref, whenOpts); + altSchema = dateSchema.when(schema, whenSchemaOpts); } // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- @@ -622,6 +635,7 @@ namespace common { altSchema = numSchema.when(str, whenOpts); altSchema = numSchema.when(ref, whenOpts); + altSchema = numSchema.when(schema, whenSchemaOpts); } // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- @@ -732,6 +746,7 @@ namespace common { altSchema = objSchema.when(str, whenOpts); altSchema = objSchema.when(ref, whenOpts); + altSchema = objSchema.when(schema, whenSchemaOpts); } // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- @@ -823,6 +838,7 @@ namespace common { altSchema = strSchema.when(str, whenOpts); altSchema = strSchema.when(ref, whenOpts); + altSchema = strSchema.when(schema, whenSchemaOpts); } // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- @@ -1007,6 +1023,7 @@ schema = Joi.concat(x); schema = Joi.when(str, whenOpts); schema = Joi.when(ref, whenOpts); +schema = Joi.when(schema, whenSchemaOpts); schema = Joi.label(str); schema = Joi.raw(); diff --git a/types/jpegtran-bin/index.d.ts b/types/jpegtran-bin/index.d.ts new file mode 100644 index 0000000000..b946d056b7 --- /dev/null +++ b/types/jpegtran-bin/index.d.ts @@ -0,0 +1,9 @@ +// Type definitions for jpegtran-bin 3.2 +// Project: https://github.com/imagemin/jpegtran-bin#readme +// Definitions by: Hirotaka Ikoma +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare const jpegtran: string; +export = jpegtran; diff --git a/types/jpegtran-bin/jpegtran-bin-tests.ts b/types/jpegtran-bin/jpegtran-bin-tests.ts new file mode 100644 index 0000000000..9f3e8318fd --- /dev/null +++ b/types/jpegtran-bin/jpegtran-bin-tests.ts @@ -0,0 +1,6 @@ +import { execFile } from "child_process"; +import * as jpegtran from "jpegtran-bin"; + +execFile(jpegtran, ["-outfile", "output.jpg", "input.jpg"], { encoding: "utf-8" }, (err: Error | null) => { + console.log("Image minified!"); +}); diff --git a/types/jpegtran-bin/tsconfig.json b/types/jpegtran-bin/tsconfig.json new file mode 100644 index 0000000000..5f260cfaed --- /dev/null +++ b/types/jpegtran-bin/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "jpegtran-bin-tests.ts" + ] +} diff --git a/types/jpegtran-bin/tslint.json b/types/jpegtran-bin/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/jpegtran-bin/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/mapbox-gl/index.d.ts b/types/mapbox-gl/index.d.ts index b6a63ef9dd..f878e2b2bd 100644 --- a/types/mapbox-gl/index.d.ts +++ b/types/mapbox-gl/index.d.ts @@ -873,6 +873,7 @@ declare namespace mapboxgl { speed?: number; screenSpeed?: number; easing?: Function; + maxDuration?: number; } export interface FitBoundsOptions extends mapboxgl.FlyToOptions { diff --git a/types/mapbox-gl/mapbox-gl-tests.ts b/types/mapbox-gl/mapbox-gl-tests.ts index ce10a26564..fa62007088 100644 --- a/types/mapbox-gl/mapbox-gl-tests.ts +++ b/types/mapbox-gl/mapbox-gl-tests.ts @@ -150,7 +150,8 @@ map.flyTo({ screenSpeed: 1, easing: function(t: any) { return t; - } + }, + maxDuration: 1 }); /** diff --git a/types/mozjpeg/index.d.ts b/types/mozjpeg/index.d.ts new file mode 100644 index 0000000000..064d7b16e3 --- /dev/null +++ b/types/mozjpeg/index.d.ts @@ -0,0 +1,9 @@ +// Type definitions for mozjpeg 5.0 +// Project: https://github.com/imagemin/mozjpeg-bin#readme +// Definitions by: Hirotaka Ikoma +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare const mozjpeg: string; +export = mozjpeg; diff --git a/types/mozjpeg/mozjpeg-tests.ts b/types/mozjpeg/mozjpeg-tests.ts new file mode 100644 index 0000000000..6915acf946 --- /dev/null +++ b/types/mozjpeg/mozjpeg-tests.ts @@ -0,0 +1,6 @@ +import { execFile } from "child_process"; +import * as mozjpeg from "mozjpeg"; + +execFile(mozjpeg, ["-outfile", "output.jpg", "input.jpg"], {encoding: "utf-8"}, (err: Error | null) => { + console.log("Image minified!"); +}); diff --git a/types/mozjpeg/tsconfig.json b/types/mozjpeg/tsconfig.json new file mode 100644 index 0000000000..caea469f46 --- /dev/null +++ b/types/mozjpeg/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "mozjpeg-tests.ts" + ] +} diff --git a/types/mozjpeg/tslint.json b/types/mozjpeg/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/mozjpeg/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/pngquant-bin/index.d.ts b/types/pngquant-bin/index.d.ts new file mode 100644 index 0000000000..928ef83333 --- /dev/null +++ b/types/pngquant-bin/index.d.ts @@ -0,0 +1,9 @@ +// Type definitions for pngquant-bin 4.0 +// Project: https://github.com/imagemin/pngquant-bin#readme +// Definitions by: Hirotaka Ikoma +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare const pngquant: string; +export = pngquant; diff --git a/types/pngquant-bin/pngquant-bin-tests.ts b/types/pngquant-bin/pngquant-bin-tests.ts new file mode 100644 index 0000000000..40f79d1371 --- /dev/null +++ b/types/pngquant-bin/pngquant-bin-tests.ts @@ -0,0 +1,6 @@ +import { execFile } from "child_process"; +import * as pngquant from "pngquant-bin"; + +execFile(pngquant, ["-o", "output.png", "input.png"], { encoding: "utf-8" }, (err: Error | null) => { + console.log("Image minified!"); +}); diff --git a/types/pngquant-bin/tsconfig.json b/types/pngquant-bin/tsconfig.json new file mode 100644 index 0000000000..770ff62c3f --- /dev/null +++ b/types/pngquant-bin/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "pngquant-bin-tests.ts" + ] +} diff --git a/types/pngquant-bin/tslint.json b/types/pngquant-bin/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/pngquant-bin/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/prosemirror-collab/index.d.ts b/types/prosemirror-collab/index.d.ts index 4b84101159..cb4949bcba 100644 --- a/types/prosemirror-collab/index.d.ts +++ b/types/prosemirror-collab/index.d.ts @@ -3,13 +3,11 @@ // Definitions by: Bradley Ayers // David Hahn // Tim Baumann +// Patrick Simmelbauer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 - -// IMPORTANT -// This file was generated by https://github.com/bradleyayers/getdocs2ts. Please do not edit manually. -// When you find an error in these declarations, fix the getdocs comment upstream or 'getdocs2ts', then regenerate. +// TypeScript Version: 2.3 +import { Schema } from 'prosemirror-model'; import { EditorState, Plugin, Transaction } from 'prosemirror-state'; import { Step } from 'prosemirror-transform'; @@ -17,13 +15,20 @@ import { Step } from 'prosemirror-transform'; * Creates a plugin that enables the collaborative editing framework * for the editor. */ -export function collab(config?: { version?: number | null, clientID?: number | string | null }): Plugin; +export function collab(config?: { + version?: number | null; + clientID?: number | string | null; +}): Plugin; /** * Create a transaction that represents a set of new steps received from * the authority. Applying this transaction moves the state forward to * adjust to the authority's view of the document. */ -export function receiveTransaction(state: EditorState, steps: Step[], clientIDs: Array): Transaction; +export function receiveTransaction( + state: EditorState, + steps: Array>, + clientIDs: Array +): Transaction; /** * Provides data describing the editor's unconfirmed steps, which need * to be sent to the central authority. Returns null when there is @@ -35,7 +40,14 @@ export function receiveTransaction(state: EditorState, steps: Step[], clientIDs: * rebased, whereas the origin transactions are still the old, * unchanged objects. */ -export function sendableSteps(state: EditorState): { version: number, steps: Step[], clientID: number | string, origins: Transaction[] } | null | void; +export function sendableSteps( + state: EditorState +): { + version: number; + steps: Array>; + clientID: number | string; + origins: Array>; +} | null | void; /** * Get the version up to which the collab plugin has synced with the * central authority. diff --git a/types/prosemirror-commands/index.d.ts b/types/prosemirror-commands/index.d.ts index 5f8cb75946..1f6fbee7b3 100644 --- a/types/prosemirror-commands/index.d.ts +++ b/types/prosemirror-commands/index.d.ts @@ -3,21 +3,21 @@ // Definitions by: Bradley Ayers // David Hahn // Tim Baumann +// Patrick Simmelbauer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 +// TypeScript Version: 2.3 -// IMPORTANT -// This file was generated by https://github.com/bradleyayers/getdocs2ts. Please do not edit manually. -// When you find an error in these declarations, fix the getdocs comment upstream or 'getdocs2ts', then regenerate. - -import { MarkType, Node as ProsemirrorNode, NodeType } from 'prosemirror-model'; +import { MarkType, Node as ProsemirrorNode, NodeType, Schema } from 'prosemirror-model'; import { EditorState, Transaction } from 'prosemirror-state'; import { EditorView } from 'prosemirror-view'; /** * Delete the selection, if there is one. */ -export function deleteSelection(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function deleteSelection( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; /** * If the selection is empty and at the start of a textblock, try to * reduce the distance between that block and the one before it—if @@ -27,7 +27,11 @@ export function deleteSelection(state: EditorState, dispatch?: (tr: Transaction) * into a parent of the previous block. Will use the view for accurate * (bidi-aware) start-of-textblock detection if given. */ -export function joinBackward(state: EditorState, dispatch?: (tr: Transaction) => void, view?: EditorView): boolean; +export function joinBackward( + state: EditorState, + dispatch?: (tr: Transaction) => void, + view?: EditorView +): boolean; /** * When the selection is empty and at the start of a textblock, select * the node before that textblock, if possible. This is intended to be @@ -36,7 +40,11 @@ export function joinBackward(state: EditorState, dispatch?: (tr: Transaction) => * commands, as a fall-back behavior when the schema doesn't allow * deletion at the selected point. */ -export function selectNodeBackward(state: EditorState, dispatch?: (tr: Transaction) => void, view?: EditorView): boolean; +export function selectNodeBackward( + state: EditorState, + dispatch?: (tr: Transaction) => void, + view?: EditorView +): boolean; /** * If the selection is empty and the cursor is at the end of a * textblock, try to reduce or remove the boundary between that block @@ -44,7 +52,11 @@ export function selectNodeBackward(state: EditorState, dispatch?: (tr: Transacti * block closer to this one in the tree structure. Will use the view * for accurate start-of-textblock detection if given. */ -export function joinForward(state: EditorState, dispatch?: (tr: Transaction) => void, view?: EditorView): boolean; +export function joinForward( + state: EditorState, + dispatch?: (tr: Transaction) => void, + view?: EditorView +): boolean; /** * When the selection is empty and at the end of a textblock, select * the node coming after that textblock, if possible. This is intended @@ -53,74 +65,117 @@ export function joinForward(state: EditorState, dispatch?: (tr: Transaction) => * commands, to provide a fall-back behavior when the schema doesn't * allow deletion at the selected point. */ -export function selectNodeForward(state: EditorState, dispatch?: (tr: Transaction) => void, view?: EditorView): boolean; +export function selectNodeForward( + state: EditorState, + dispatch?: (tr: Transaction) => void, + view?: EditorView +): boolean; /** * Join the selected block or, if there is a text selection, the * closest ancestor block of the selection that can be joined, with * the sibling above it. */ -export function joinUp(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function joinUp( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; /** * Join the selected block, or the closest ancestor of the selection * that can be joined, with the sibling after it. */ -export function joinDown(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function joinDown( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; /** * Lift the selected block, or the closest ancestor block of the * selection that can be lifted, out of its parent node. */ -export function lift(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function lift( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; /** * If the selection is in a node whose type has a truthy * [`code`](#model.NodeSpec.code) property in its spec, replace the * selection with a newline character. */ -export function newlineInCode(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function newlineInCode( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; /** * When the selection is in a node with a truthy * [`code`](#model.NodeSpec.code) property in its spec, create a * default block after the code block, and move the cursor there. */ -export function exitCode(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function exitCode( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; /** * If a block node is selected, create an empty paragraph before (if * it is its parent's first child) or after it. */ -export function createParagraphNear(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function createParagraphNear( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; /** * If the cursor is in an empty textblock that can be lifted, lift the * block. */ -export function liftEmptyBlock(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function liftEmptyBlock( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; /** * Split the parent block of the selection. If the selection is a text * selection, also delete its content. */ -export function splitBlock(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function splitBlock( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; /** * Acts like [`splitBlock`](#commands.splitBlock), but without * resetting the set of active marks at the cursor. */ -export function splitBlockKeepMarks(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function splitBlockKeepMarks( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; /** * Move the selection to the node wrapping the current selection, if * any. (Will not select the document node.) */ -export function selectParentNode(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function selectParentNode( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; /** * Select the whole document. */ -export function selectAll(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function selectAll( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; /** * Wrap the selection in a node of the given type with the given * attributes. */ -export function wrapIn(nodeType: NodeType, attrs?: { [key: string]: any }): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean; +export function wrapIn( + nodeType: NodeType, + attrs?: { [key: string]: any } +): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean; /** * Returns a command that tries to set the textblock around the * selection to the given node type with the given attributes. */ -export function setBlockType(nodeType: NodeType, attrs?: { [key: string]: any }): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean; +export function setBlockType( + nodeType: NodeType, + attrs?: { [key: string]: any } +): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean; /** * Create a command function that toggles the given mark with the * given attributes. Will return `false` when the current selection @@ -130,7 +185,10 @@ export function setBlockType(nodeType: NodeType, attrs?: { [key: string]: any }) * marks](#state.EditorState.storedMarks) instead of a range of the * document. */ -export function toggleMark(markType: MarkType, attrs?: { [key: string]: any }): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean; +export function toggleMark( + markType: MarkType, + attrs?: { [key: string]: any } +): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean; /** * Wrap a command so that, when it produces a transform that causes * two joinable nodes to end up next to each other, those are joined. @@ -139,17 +197,19 @@ export function toggleMark(markType: MarkType, attrs?: { [key: string]: any }): * array of strings was passed, if their node type name is in that * array. */ -export function autoJoin( - command: (state: EditorState, p1?: (tr: Transaction) => void) => boolean, - isJoinable: ((before: ProsemirrorNode, after: ProsemirrorNode) => boolean) | string[] -): (state: EditorState, p1?: (tr: Transaction) => void) => boolean; +export function autoJoin( + command: (state: EditorState, p1?: (tr: Transaction) => void) => boolean, + isJoinable: ((before: ProsemirrorNode, after: ProsemirrorNode) => boolean) | string[] +): (state: EditorState, p1?: (tr: Transaction) => void) => boolean; /** * Combine a number of command functions into a single function (which * calls them one by one until one returns true). */ -export function chainCommands( - ...commands: Array<(p1: EditorState, p2?: (tr: Transaction) => void, p3?: EditorView) => boolean> -): (p1: EditorState, p2?: (tr: Transaction) => void, p3?: EditorView) => boolean; +export function chainCommands( + ...commands: Array< + (p1: EditorState, p2?: (tr: Transaction) => void, p3?: EditorView) => boolean + > +): (p1: EditorState, p2?: (tr: Transaction) => void, p3?: EditorView) => boolean; /** * A basic keymap containing bindings not specific to any schema. * Binds the following keys (when multiple commands are listed, they diff --git a/types/prosemirror-gapcursor/index.d.ts b/types/prosemirror-gapcursor/index.d.ts index 41edf50e3f..c1fe56425d 100644 --- a/types/prosemirror-gapcursor/index.d.ts +++ b/types/prosemirror-gapcursor/index.d.ts @@ -3,12 +3,9 @@ // Definitions by: Bradley Ayers // David Hahn // Tim Baumann +// Patrick Simmelbauer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 - -// IMPORTANT -// This file was generated by https://github.com/bradleyayers/getdocs2ts. Please do not edit manually. -// When you find an error in these declarations, fix the getdocs comment upstream or 'getdocs2ts', then regenerate. +// TypeScript Version: 2.3 import { Plugin, Selection } from 'prosemirror-state'; @@ -16,8 +13,7 @@ import { Plugin, Selection } from 'prosemirror-state'; * Gap cursor selections are represented using this class. Its * `$anchor` and `$head` properties both point at the cursor position. */ -export class GapCursor extends Selection { -} +export class GapCursor extends Selection { } /** * Create a gap cursor plugin. When enabled, this will capture clicks * near and arrow-key-motion past places that don't have a normally diff --git a/types/prosemirror-history/index.d.ts b/types/prosemirror-history/index.d.ts index 4fbb59ecb9..5d62c9267c 100644 --- a/types/prosemirror-history/index.d.ts +++ b/types/prosemirror-history/index.d.ts @@ -3,13 +3,11 @@ // Definitions by: Bradley Ayers // David Hahn // Tim Baumann +// Patrick Simmelbauer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 - -// IMPORTANT -// This file was generated by https://github.com/bradleyayers/getdocs2ts. Please do not edit manually. -// When you find an error in these declarations, fix the getdocs comment upstream or 'getdocs2ts', then regenerate. +// TypeScript Version: 2.3 +import { Schema } from 'prosemirror-model'; import { EditorState, Plugin, Transaction } from 'prosemirror-state'; /** @@ -17,7 +15,7 @@ import { EditorState, Plugin, Transaction } from 'prosemirror-state'; * from being appended to an existing history event (so that they * require a separate undo command to undo). */ -export function closeHistory(tr: Transaction): Transaction; +export function closeHistory(tr: Transaction): Transaction; /** * Returns a plugin that enables the undo history for an editor. The * plugin will track undo and redo stacks, which can be used with the @@ -27,15 +25,21 @@ export function closeHistory(tr: Transaction): Transaction; * property](#state.Transaction.setMeta) of `false` on a transaction * to prevent it from being rolled back by undo. */ -export function history(config?: { depth?: number | null, newGroupDelay?: number | null }): Plugin; +export function history(config?: { depth?: number | null; newGroupDelay?: number | null }): Plugin; /** * A command function that undoes the last change, if any. */ -export function undo(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function undo( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; /** * A command function that redoes the last undone change, if any. */ -export function redo(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function redo( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; /** * The amount of undoable events available in a given state. */ diff --git a/types/prosemirror-inputrules/index.d.ts b/types/prosemirror-inputrules/index.d.ts index a75dc9cff5..7c405530e0 100644 --- a/types/prosemirror-inputrules/index.d.ts +++ b/types/prosemirror-inputrules/index.d.ts @@ -3,14 +3,11 @@ // Definitions by: Bradley Ayers // David Hahn // Tim Baumann +// Patrick Simmelbauer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 +// TypeScript Version: 2.3 -// IMPORTANT -// This file was generated by https://github.com/bradleyayers/getdocs2ts. Please do not edit manually. -// When you find an error in these declarations, fix the getdocs comment upstream or 'getdocs2ts', then regenerate. - -import { Node as ProsemirrorNode, NodeType } from 'prosemirror-model'; +import { Node as ProsemirrorNode, NodeType, Schema } from 'prosemirror-model'; import { EditorState, Plugin, Transaction } from 'prosemirror-state'; /** @@ -19,7 +16,7 @@ import { EditorState, Plugin, Transaction } from 'prosemirror-state'; * changing two dashes into an emdash, wrapping a paragraph starting * with `"> "` into a blockquote, or something entirely different. */ -export class InputRule { +export class InputRule { /** * Create an input rule. The rule applies when the user typed * something and the text directly in front of the cursor matches @@ -36,19 +33,34 @@ export class InputRule { * return a [transaction](#state.Transaction) that describes the * rule's effect, or null to indicate the input was not handled. */ - constructor(match: RegExp, handler: string | ((state: EditorState, match: string[], start: number, end: number) => Transaction | null | void)); + constructor( + match: RegExp, + handler: + | string + | (( + state: EditorState, + match: string[], + start: number, + end: number + ) => Transaction | null | void) + ); } /** * Create an input rules plugin. When enabled, it will cause text * input that matches any of the given rules to trigger the rule's * action. */ -export function inputRules(config: { rules: InputRule[] }): Plugin; +export function inputRules(config: { + rules: Array>; +}): Plugin; /** * This is a command that will undo an input rule, if applying such a * rule was the last thing that the user did. */ -export function undoInputRule(state: EditorState, dispatch?: (p: Transaction) => void): boolean; +export function undoInputRule( + state: EditorState, + dispatch?: (p: Transaction) => void +): boolean; /** * Build an input rule for automatically wrapping a textblock when a * given string is typed. The `regexp` argument is @@ -66,12 +78,12 @@ export function undoInputRule(state: EditorState, dispatch?: (p: Transaction) => * expression match and the node before the wrapped node, and can * return a boolean to indicate whether a join should happen. */ -export function wrappingInputRule( +export function wrappingInputRule( regexp: RegExp, - nodeType: NodeType, + nodeType: NodeType, getAttrs?: { [key: string]: any } | ((p: string[]) => { [key: string]: any } | null | void), - joinPredicate?: (p1: string[], p2: ProsemirrorNode) => boolean -): InputRule; + joinPredicate?: (p1: string[], p2: ProsemirrorNode) => boolean +): InputRule; /** * Build an input rule that changes the type of a textblock when the * matched text is typed into it. You'll usually want to start your @@ -80,7 +92,11 @@ export function wrappingInputRule( * the new node's attributes, and works the same as in the * `wrappingInputRule` function. */ -export function textblockTypeInputRule(regexp: RegExp, nodeType: NodeType, getAttrs?: { [key: string]: any } | ((p: string[]) => { [key: string]: any } | null | void)): InputRule; +export function textblockTypeInputRule( + regexp: RegExp, + nodeType: NodeType, + getAttrs?: { [key: string]: any } | ((p: string[]) => { [key: string]: any } | null | void) +): InputRule; /** * Converts double dashes to an emdash. */ diff --git a/types/prosemirror-keymap/index.d.ts b/types/prosemirror-keymap/index.d.ts index 2e049948d5..8b418b08f5 100644 --- a/types/prosemirror-keymap/index.d.ts +++ b/types/prosemirror-keymap/index.d.ts @@ -3,12 +3,9 @@ // Definitions by: Bradley Ayers // David Hahn // Tim Baumann +// Patrick Simmelbauer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 - -// IMPORTANT -// This file was generated by https://github.com/bradleyayers/getdocs2ts. Please do not edit manually. -// When you find an error in these declarations, fix the getdocs comment upstream or 'getdocs2ts', then regenerate. +// TypeScript Version: 2.3 import { Plugin } from 'prosemirror-state'; import { EditorView } from 'prosemirror-view'; @@ -50,4 +47,6 @@ export function keymap(bindings: { [key: string]: any }): Plugin; * [`keymap`](#keymap.keymap), return a [keydown * handler](#view.EditorProps.handleKeyDown) handles them. */ -export function keydownHandler(bindings: { [key: string]: any }): (view: EditorView, event: Event) => boolean; +export function keydownHandler(bindings: { + [key: string]: any; +}): (view: EditorView, event: Event) => boolean; diff --git a/types/prosemirror-markdown/index.d.ts b/types/prosemirror-markdown/index.d.ts index 6617166c6e..7af366c04e 100644 --- a/types/prosemirror-markdown/index.d.ts +++ b/types/prosemirror-markdown/index.d.ts @@ -3,12 +3,9 @@ // Definitions by: Bradley Ayers // David Hahn // Tim Baumann +// Patrick Simmelbauer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 - -// IMPORTANT -// This file was generated by https://github.com/bradleyayers/getdocs2ts. Please do not edit manually. -// When you find an error in these declarations, fix the getdocs comment upstream or 'getdocs2ts', then regenerate. +// TypeScript Version: 2.3 import { MarkdownIt } from 'markdown-it'; import { Node as ProsemirrorNode, Schema } from 'prosemirror-model'; @@ -19,7 +16,7 @@ import { Node as ProsemirrorNode, Schema } from 'prosemirror-model'; * tokenize a file, and then runs the custom rules it is given over * the tokens to create a ProseMirror document tree. */ -export class MarkdownParser { +export class MarkdownParser { /** * Create a parser with the given configuration. You can configure * the markdown-it parser to parse the dialect you want, and provide @@ -58,7 +55,7 @@ export class MarkdownParser { * **`ignore`**`: ?bool` * : When true, ignore content for the matched token. */ - constructor(schema: Schema, tokenizer: MarkdownIt, tokens: { [key: string]: any }); + constructor(schema: S, tokenizer: MarkdownIt, tokens: { [key: string]: any }); /** * The value of the `tokens` object used to construct * this parser. Can be useful to copy and modify to base other @@ -70,7 +67,7 @@ export class MarkdownParser { * and create a ProseMirror document as prescribed by this parser's * rules. */ - parse(text: string): ProsemirrorNode; + parse(text: string): ProsemirrorNode; } /** * A parser parsing unextended [CommonMark](http://commonmark.org/), @@ -81,13 +78,23 @@ export let defaultMarkdownParser: MarkdownParser; * A specification for serializing a ProseMirror document as * Markdown/CommonMark text. */ -export class MarkdownSerializer { - constructor(nodes: { [name: string]: (state: MarkdownSerializerState, node: ProsemirrorNode, parent: ProsemirrorNode, index: number) => void }, marks: { [key: string]: any }); +export class MarkdownSerializer { + constructor( + nodes: { + [name: string]: ( + state: MarkdownSerializerState, + node: ProsemirrorNode, + parent: ProsemirrorNode, + index: number + ) => void; + }, + marks: { [key: string]: any } + ); /** * The node serializer * functions for this serializer. */ - nodes: { [name: string]: (p1: MarkdownSerializerState, p2: ProsemirrorNode) => void }; + nodes: { [name: string]: (p1: MarkdownSerializerState, p2: ProsemirrorNode) => void }; /** * The mark serializer info. */ @@ -96,7 +103,7 @@ export class MarkdownSerializer { * Serialize the content of the given node to * [CommonMark](http://commonmark.org/). */ - serialize(content: ProsemirrorNode, options?: { [key: string]: any }): string; + serialize(content: ProsemirrorNode, options?: { [key: string]: any }): string; } /** * A serializer for the [basic schema](#schema). @@ -107,7 +114,7 @@ export let defaultMarkdownSerializer: MarkdownSerializer; * methods related to markdown serialization. Instances are passed to * node and mark serialization methods (see `toMarkdown`). */ -export class MarkdownSerializerState { +export class MarkdownSerializerState { /** * The options passed to the serializer. */ @@ -118,7 +125,12 @@ export class MarkdownSerializerState { * the end of the block, and `f` is a function that renders the * content of the block. */ - wrapBlock(delim: string, firstDelim: string | undefined, node: ProsemirrorNode, f: () => void): void; + wrapBlock( + delim: string, + firstDelim: string | undefined, + node: ProsemirrorNode, + f: () => void + ): void; /** * Ensure the current content ends with a newline. */ @@ -132,7 +144,7 @@ export class MarkdownSerializerState { /** * Close the block for the given node. */ - closeBlock(node: ProsemirrorNode): void; + closeBlock(node: ProsemirrorNode): void; /** * Add the given text to the document. When escape is not `false`, * it will be escaped. @@ -141,22 +153,22 @@ export class MarkdownSerializerState { /** * Render the given node as a block. */ - render(node: ProsemirrorNode): void; + render(node: ProsemirrorNode): void; /** * Render the contents of `parent` as block nodes. */ - renderContent(parent: ProsemirrorNode): void; + renderContent(parent: ProsemirrorNode): void; /** * Render the contents of `parent` as inline content. */ - renderInline(parent: ProsemirrorNode): void; + renderInline(parent: ProsemirrorNode): void; /** * Render a node's content as a list. `delim` should be the extra * indentation added to all lines except the first in an item, * `firstDelim` is a function going from an item index to a * delimiter for the first line of the item. */ - renderList(node: ProsemirrorNode, delim: string, firstDelim: (p: number) => string): void; + renderList(node: ProsemirrorNode, delim: string, firstDelim: (p: number) => string): void; /** * Escape the given string so that it can safely appear in Markdown * content. If `startOfLine` is true, also escape characters that @@ -172,5 +184,5 @@ export class MarkdownSerializerState { * leading or trailing property of the return object will be undefined * if there is no match. */ - getEnclosingWhitespace(text: string): { leading?: string | null, trailing?: string | null }; + getEnclosingWhitespace(text: string): { leading?: string | null; trailing?: string | null }; } diff --git a/types/prosemirror-menu/index.d.ts b/types/prosemirror-menu/index.d.ts index 898fdffd20..75cc56966d 100644 --- a/types/prosemirror-menu/index.d.ts +++ b/types/prosemirror-menu/index.d.ts @@ -3,14 +3,11 @@ // Definitions by: Bradley Ayers // David Hahn // Tim Baumann +// Patrick Simmelbauer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 +// TypeScript Version: 2.3 -// IMPORTANT -// This file was generated by https://github.com/bradleyayers/getdocs2ts. Please do not edit manually. -// When you find an error in these declarations, fix the getdocs comment upstream or 'getdocs2ts', then regenerate. - -import { NodeType } from 'prosemirror-model'; +import { NodeType, Schema } from 'prosemirror-model'; import { EditorState, Plugin, Transaction } from 'prosemirror-state'; import { EditorView } from 'prosemirror-view'; @@ -19,61 +16,61 @@ import { EditorView } from 'prosemirror-view'; * display in your menu. Anything that conforms to this interface can * be put into a menu structure. */ -export interface MenuElement { +export interface MenuElement { /** * Render the element for display in the menu. Must return a DOM * element and a function that can be used to update the element to * a new state. The `update` function will return false if the * update hid the entire element. */ - render(pm: EditorView): { dom: Node, update(p: EditorState): boolean }; + render(pm: EditorView): { dom: Node; update(p: EditorState): boolean }; } /** * An icon or label that, when clicked, executes a command. */ -export class MenuItem { - constructor(spec: MenuItemSpec); +export class MenuItem { + constructor(spec: MenuItemSpec); /** * The spec used to create the menu item. */ - spec: MenuItemSpec; + spec: MenuItemSpec; /** * Renders the icon according to its [display * spec](#menu.MenuItemSpec.display), and adds an event handler which * executes the command when the representation is clicked. */ - render(view: EditorView): { dom: Node, update(p: EditorState): boolean }; + render(view: EditorView): { dom: Node; update(p: EditorState): boolean }; } /** * The configuration object passed to the `MenuItem` constructor. */ -export interface MenuItemSpec { +export interface MenuItemSpec { /** * The function to execute when the menu item is activated. */ - run(p1: EditorState, p2: (p: Transaction) => void, p3: EditorView, p4: Event): void; + run(p1: EditorState, p2: (p: Transaction) => void, p3: EditorView, p4: Event): void; /** * Optional function that is used to determine whether the item is * appropriate at the moment. Deselected items will be hidden. */ - select?: ((p: EditorState) => boolean) | null; + select?: ((p: EditorState) => boolean) | null; /** * Function that is used to determine if the item is enabled. If * given and returning false, the item will be given a disabled * styling. */ - enable?: ((p: EditorState) => boolean) | null; + enable?: ((p: EditorState) => boolean) | null; /** * A predicate function to determine whether the item is 'active' (for * example, the item for toggling the strong mark might be active then * the cursor is in strong text). */ - active?: ((p: EditorState) => boolean) | null; + active?: ((p: EditorState) => boolean) | null; /** * A function that renders the item. You must provide either this, * [`icon`](#menu.MenuItemSpec.icon), or [`label`](#MenuItemSpec.label). */ - render?: ((p: EditorView) => Node) | null; + render?: ((p: EditorView) => Node) | null; /** * Describes an icon to show for this item. The object may specify * an SVG icon, in which case its `path` property should be an [SVG @@ -95,7 +92,7 @@ export interface MenuItemSpec { /** * Defines DOM title (mouseover) text for the item. */ - title?: string | ((p: EditorState) => string) | null; + title?: string | ((p: EditorState) => string) | null; /** * Optionally adds a CSS class to the item's DOM representation. */ @@ -115,7 +112,7 @@ export interface MenuItemSpec { * A drop-down menu, displayed as a label with a downwards-pointing * triangle to the right of it. */ -export class Dropdown { +export class Dropdown { /** * Create a dropdown wrapping the elements. Options may include * the following properties: @@ -134,17 +131,17 @@ export class Dropdown { * **`css`**`: string` * : When given, adds an extra set of CSS styles to the menu control. */ - constructor(content: MenuElement[], options?: { [key: string]: any }); + constructor(content: Array>, options?: { [key: string]: any }); /** * Render the dropdown menu and sub-items. */ - render(view: EditorView): { dom: Node, update(p: EditorState): void }; + render(view: EditorView): { dom: Node; update(p: EditorState): void }; } /** * Represents a submenu wrapping a group of elements that start * hidden and expand to the right when hovered over or tapped. */ -export class DropdownSubmenu { +export class DropdownSubmenu { /** * Creates a submenu for the given group of menu elements. The * following options are recognized: @@ -152,11 +149,11 @@ export class DropdownSubmenu { * **`label`**`: string` * : The label to show on the submenu. */ - constructor(content: MenuElement[], options?: { [key: string]: any }); + constructor(content: Array>, options?: { [key: string]: any }); /** * Renders the submenu. */ - render(view: EditorView): { dom: Node, update(p: EditorState): boolean }; + render(view: EditorView): { dom: Node; update(p: EditorState): boolean }; } /** * Render the given, possibly nested, array of menu elements into a @@ -164,7 +161,10 @@ export class DropdownSubmenu { * superfluous separators appear when some of the groups turn out to * be empty). */ -export function renderGrouped(view: EditorView, content: Array): { dom?: DocumentFragment | null, update(p: EditorState): boolean }; +export function renderGrouped( + view: EditorView, + content: Array | Array>> +): { dom?: DocumentFragment | null; update(p: EditorState): boolean }; /** * A set of basic editor-related icons. Contains the properties * `join`, `lift`, `selectParentNode`, `undo`, `redo`, `strong`, `em`, @@ -199,16 +199,25 @@ export function redoItem(p: { [key: string]: any }): MenuItem; * `options`. `options.attrs` may be an object or a function, as in * `toggleMarkItem`. */ -export function wrapItem(nodeType: NodeType, options: { [key: string]: any }): MenuItem; +export function wrapItem( + nodeType: NodeType, + options: { [key: string]: any } +): MenuItem; /** * Build a menu item for changing the type of the textblock around the * selection to the given type. Provides `run`, `active`, and `select` * properties. Others must be given in `options`. `options.attrs` may * be an object to provide the attributes for the textblock node. */ -export function blockTypeItem(nodeType: NodeType, options: { [key: string]: any }): MenuItem; +export function blockTypeItem( + nodeType: NodeType, + options: { [key: string]: any } +): MenuItem; /** * A plugin that will place a menu bar above the editor. Note that * this involves wrapping the editor in an additional `
`. */ -export function menuBar(options: { content: MenuElement[][], floating?: boolean | null }): Plugin; +export function menuBar(options: { + content: Array>>; + floating?: boolean | null; +}): Plugin; diff --git a/types/prosemirror-model/index.d.ts b/types/prosemirror-model/index.d.ts index 153358e3c6..adb8a6141c 100644 --- a/types/prosemirror-model/index.d.ts +++ b/types/prosemirror-model/index.d.ts @@ -1,15 +1,12 @@ -// Type definitions for prosemirror-model 1.1 +// Type definitions for prosemirror-model 1.4 // Project: https://github.com/ProseMirror/prosemirror-model // Definitions by: Bradley Ayers // David Hahn // Tim Baumann // Malte Blanken +// Patrick Simmelbauer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 - -// IMPORTANT -// This file was generated by https://github.com/bradleyayers/getdocs2ts. Please do not edit manually. -// When you find an error in these declarations, fix the getdocs comment upstream or 'getdocs2ts', then regenerate. +// TypeScript Version: 2.3 import OrderedMap = require('orderedmap'); @@ -19,7 +16,17 @@ import OrderedMap = require('orderedmap'); * used to find out whether further content matches here, and whether * a given position is a valid end of the node. */ -export class ContentMatch { +export class ContentMatch { + /** + * Get the first matching node type at this match position that can + * be generated. + */ + defaultType?: NodeType; + /** + * The number of outgoing edges this node has in the finite automaton + * that describes the content expression. + */ + edgeCount: number; /** * True when this match state represents a valid end of the node. */ @@ -28,12 +35,12 @@ export class ContentMatch { * Match a node type and marks, returning a match after that node * if successful. */ - matchType(type: NodeType): ContentMatch | null | void; + matchType(type: NodeType): ContentMatch | null | void; /** * Try to match a fragment. Returns the resulting match when * successful. */ - matchFragment(frag: Fragment, start?: number, end?: number): ContentMatch | null | void; + matchFragment(frag: Fragment, start?: number, end?: number): ContentMatch | null | void; /** * Try to match the given fragment, and if that fails, see if it can * be made to match by inserting nodes in front of it. When @@ -42,14 +49,19 @@ export class ContentMatch { * return a fragment if the resulting match goes to the end of the * content expression. */ - fillBefore(after: Fragment, toEnd?: boolean, startIndex?: number): Fragment | null | void; + fillBefore(after: Fragment, toEnd?: boolean, startIndex?: number): Fragment | null | void; /** * Find a set of wrapping node types that would allow a node of the * given type to appear at this position. The result may be empty * (when it fits directly) and will be null when no such wrapping * exists. */ - findWrapping(target: NodeType): NodeType[] | null | void; + findWrapping(target: NodeType): Array> | null | void; + /** + * Get the _n_th outgoing edge from this node in the finite automaton + * that describes the content expression. + */ + edge(n: number): { type: NodeType; next: ContentMatch }; } /** * A fragment represents a node's collection of child nodes. @@ -58,7 +70,7 @@ export class ContentMatch { * should not mutate them or their content. Rather, you create new * instances whenever needed. The API tries to make this easy. */ -export class Fragment { +export class Fragment { /** * The size of the fragment, which is the total of the size of its * content nodes. @@ -69,38 +81,54 @@ export class Fragment { * positions (relative to start of this fragment). Doesn't descend * into a node when the callback returns `false`. */ - nodesBetween(from: number, to: number, f: (node: ProsemirrorNode, start: number, parent: ProsemirrorNode, index: number) => boolean | null | void): void; + nodesBetween( + from: number, + to: number, + f: ( + node: ProsemirrorNode, + start: number, + parent: ProsemirrorNode, + index: number + ) => boolean | null | void, + startPos?: number + ): void; /** * Call the given callback for every descendant node. The callback * may return `false` to prevent traversal of a given node's children. */ - descendants(f: (node: ProsemirrorNode, pos: number, parent: ProsemirrorNode) => boolean | null | void): void; + descendants( + f: ( + node: ProsemirrorNode, + pos: number, + parent: ProsemirrorNode + ) => boolean | null | void + ): void; /** * Create a new fragment containing the combined content of this * fragment and the other. */ - append(other: Fragment): Fragment; + append(other: Fragment): Fragment; /** * Cut out the sub-fragment between the two given positions. */ - cut(from: number, to?: number): Fragment; + cut(from: number, to?: number): Fragment; /** * Create a new fragment in which the node at the given index is * replaced by the given node. */ - replaceChild(index: number, node: ProsemirrorNode): Fragment; + replaceChild(index: number, node: ProsemirrorNode): Fragment; /** * Compare this fragment to another one. */ - eq(other: Fragment): boolean; + eq(other: Fragment): boolean; /** * The first child of the fragment, or `null` if it is empty. */ - firstChild?: ProsemirrorNode | null; + firstChild?: ProsemirrorNode | null; /** * The last child of the fragment, or `null` if it is empty. */ - lastChild?: ProsemirrorNode | null; + lastChild?: ProsemirrorNode | null; /** * The number of child nodes in this fragment. */ @@ -109,28 +137,28 @@ export class Fragment { * Get the child node at the given index. Raise an error when the * index is out of range. */ - child(index: number): ProsemirrorNode; + child(index: number): ProsemirrorNode; /** * Get the child node at the given index, if it exists. */ - maybeChild(index: number): ProsemirrorNode | null | void; + maybeChild(index: number): ProsemirrorNode | null | void; /** * Call `f` for every child node, passing the node, its offset * into this parent node, and its index. */ - forEach(f: (node: ProsemirrorNode, offset: number, index: number) => void): void; + forEach(f: (node: ProsemirrorNode, offset: number, index: number) => void): void; /** * Find the first position at which this fragment and another * fragment differ, or `null` if they are the same. */ - findDiffStart(other: Fragment): number | null | void; + findDiffStart(other: Fragment): number | null | void; /** * Find the first position, searching from the end, at which this * fragment and the given fragment differ, or `null` if they are the * same. Since this position will not be the same in both nodes, an * object with two separate positions is returned. */ - findDiffEnd(other: ProsemirrorNode): { a: number, b: number } | null | void; + findDiffEnd(other: ProsemirrorNode): { a: number; b: number } | null | void; /** * Return a debugging string that describes this fragment. */ @@ -142,19 +170,24 @@ export class Fragment { /** * Deserialize a fragment from its JSON representation. */ - static fromJSON(schema: Schema, value?: { [key: string]: any }): Fragment; + static fromJSON( + schema: S, + value?: { [key: string]: any } + ): Fragment; /** * Build a fragment from an array of nodes. Ensures that adjacent * text nodes with the same marks are joined together. */ - static fromArray(array: ProsemirrorNode[]): Fragment; + static fromArray(array: Array>): Fragment; /** * Create a fragment from something that can be interpreted as a set * of nodes. For `null`, it returns the empty fragment. For a * fragment, the fragment itself. For a node or array of nodes, a * fragment containing those nodes. */ - static from(nodes?: Fragment | ProsemirrorNode | ProsemirrorNode[]): Fragment; + static from( + nodes?: Fragment | ProsemirrorNode | Array> + ): Fragment; /** * An empty fragment. Intended to be reused whenever a node doesn't * contain anything (rather than allocating a new empty fragment for @@ -167,13 +200,13 @@ export class Fragment { * [`parse`](#model.DOMParser.parse) and * [`parseSlice`](#model.DOMParser.parseSlice) methods. */ -export interface ParseOptions { +export interface ParseOptions { /** * By default, whitespace is collapsed as per HTML's rules. Pass * `true` to preserve whitespace, but normalize newlines to * spaces, and `"full"` to preserve whitespace entirely. */ - preserveWhitespace?: boolean | "full" | null; + preserveWhitespace?: boolean | 'full' | null; /** * When given, the parser will, beside parsing the content, * record the document positions of the given DOM positions. It @@ -181,7 +214,7 @@ export interface ParseOptions { * that holds the document position. DOM positions that are not * in the parsed content will not be written to. */ - findPositions?: Array<{ node: Node, offset: number }> | null; + findPositions?: Array<{ node: Node; offset: number }> | null; /** * The child node index to start parsing from. */ @@ -196,7 +229,7 @@ export interface ParseOptions { * option to use the type and attributes from a different node * as the top container. */ - topNode?: ProsemirrorNode | null; + topNode?: ProsemirrorNode | null; /** * Provide the starting content match that content parsed into the * top node is matched against. @@ -207,13 +240,13 @@ export interface ParseOptions { * [context](#model.ParseRule.context) when parsing, above the * given [top node](#model.ParseOptions.topNode). */ - context?: ResolvedPos | null; + context?: ResolvedPos | null; } /** * A value that describes how to parse a given DOM node or inline * style as a ProseMirror node or mark. */ -export interface ParseRule { +export interface ParseRule { /** * A CSS selector describing the kind of DOM elements to match. A * single rule should have _either_ a `tag` or a `style` property. @@ -308,7 +341,7 @@ export interface ParseRule { * present, instead of parsing the node's child nodes, the result of * this function is used. */ - getContent?: ((p: Node) => Fragment) | null; + getContent?: ((p: Node) => Fragment) | null; /** * Controls whether whitespace should be preserved when parsing the * content inside the matched element. `false` means whitespace may @@ -316,32 +349,32 @@ export interface ParseRule { * but newlines normalized to spaces, and `"full"` means that * newlines should also be preserved. */ - preserveWhitespace?: boolean | "full" | null; + preserveWhitespace?: boolean | 'full' | null; } /** * A DOM parser represents a strategy for parsing DOM content into * a ProseMirror document conforming to a given schema. Its behavior * is defined by an array of [rules](#model.ParseRule). */ -export class DOMParser { +export class DOMParser { /** * Create a parser that targets the given schema, using the given * parsing rules. */ - constructor(schema: Schema, rules: ParseRule[]); + constructor(schema: S, rules: Array>); /** * The schema into which the parser parses. */ - schema: Schema; + schema: S; /** * The set of [parse rules](#model.ParseRule) that the parser * uses, in order of precedence. */ - rules: ParseRule[]; + rules: Array>; /** * Parse a document from the content of a DOM node. */ - parse(dom: Node, options?: ParseOptions): ProsemirrorNode; + parse(dom: Node, options?: ParseOptions): ProsemirrorNode; /** * Parses the content of the given DOM node, like * [`parse`](#model.DOMParser.parse), and takes the same set of @@ -350,13 +383,13 @@ export class DOMParser { * the schema constraints aren't applied to the start of nodes to * the left of the input and the end of nodes at the end. */ - parseSlice(dom: Node, options?: ParseOptions): Slice; + parseSlice(dom: Node, options?: ParseOptions): Slice; /** * Construct a DOM parser using the parsing rules listed in a * schema's [node specs](#model.NodeSpec.parseDOM), reordered by * [priority](#model.ParseRule.priority). */ - static fromSchema(schema: Schema): DOMParser; + static fromSchema(schema: S): DOMParser; } /** * A mark is a piece of information that can be attached to a node, @@ -366,11 +399,11 @@ export class DOMParser { * `Schema`, which controls which types exist and which * attributes they have. */ -export class Mark { +export class Mark { /** * The type of this mark. */ - type: MarkType; + type: MarkType; /** * The attributes associated with this mark. */ @@ -382,35 +415,35 @@ export class Mark { * [exclusive](#model.MarkSpec.excludes) with this mark are present, * those are replaced by this one. */ - addToSet(set: Mark[]): Mark[]; + addToSet(set: Array>): Array>; /** * Remove this mark from the given set, returning a new set. If this * mark is not in the set, the set itself is returned. */ - removeFromSet(set: Mark[]): Mark[]; + removeFromSet(set: Array>): Array>; /** * Test whether this mark is in the given set of marks. */ - isInSet(set: Mark[]): boolean; + isInSet(set: Array>): boolean; /** * Test whether this mark has the same type and attributes as * another mark. */ - eq(other: Mark): boolean; + eq(other: Mark): boolean; /** * Convert this mark to a JSON-serializeable representation. */ toJSON(): { [key: string]: any }; - static fromJSON(schema: Schema, json: { [key: string]: any }): Mark; + static fromJSON(schema: S, json: { [key: string]: any }): Mark; /** * Test whether two sets of marks are identical. */ - static sameSet(a: Mark[], b: Mark[]): boolean; + static sameSet(a: Array>, b: Array>): boolean; /** * Create a properly sorted mark set from null, a single mark, or an * unsorted array of marks. */ - static setFrom(marks?: Mark | Mark[]): Mark[]; + static setFrom(marks?: Mark | Array>): Array>; /** * The empty set of marks. */ @@ -430,11 +463,11 @@ export class Mark { * **Do not** directly mutate the properties of a `Node` object. See * [the guide](/docs/guide/#doc) for more information. */ -declare class ProsemirrorNode { +declare class ProsemirrorNode { /** * The type of node that this is. */ - type: NodeType; + type: NodeType; /** * An object mapping attribute names to values. The kind of * attributes allowed and required are @@ -444,12 +477,12 @@ declare class ProsemirrorNode { /** * A container holding the node's children. */ - content: Fragment; + content: Fragment; /** * The marks (things like whether it is emphasized or part of a * link) applied to this node. */ - marks: Mark[]; + marks: Array>; /** * For text nodes, this contains the node's text content. */ @@ -470,16 +503,16 @@ declare class ProsemirrorNode { * Get the child node at the given index. Raises an error when the * index is out of range. */ - child(index: number): ProsemirrorNode; + child(index: number): ProsemirrorNode; /** * Get the child node at the given index, if it exists. */ - maybeChild(index: number): ProsemirrorNode | null | void; + maybeChild(index: number): ProsemirrorNode | null | void; /** * Call `f` for every child node, passing the node, its offset * into this parent node, and its index. */ - forEach(f: (node: ProsemirrorNode, offset: number, index: number) => void): void; + forEach(f: (node: ProsemirrorNode, offset: number, index: number) => void): void; /** * Invoke a callback for all descendant nodes recursively between * the given two positions that are relative to start of this node's @@ -488,12 +521,28 @@ declare class ProsemirrorNode { * When the callback returns false for a given node, that node's * children will not be recursed over. */ - nodesBetween(from: number, to: number, f: (node: ProsemirrorNode, pos: number, parent: ProsemirrorNode, index: number) => boolean | null | void): void; + nodesBetween( + from: number, + to: number, + f: ( + node: ProsemirrorNode, + pos: number, + parent: ProsemirrorNode, + index: number + ) => boolean | null | void, + startPos?: number + ): void; /** * Call the given callback for every descendant node. Doesn't * descend into a node when the callback returns `false`. */ - descendants(f: (node: ProsemirrorNode, pos: number, parent: ProsemirrorNode) => boolean | null | void): void; + descendants( + f: ( + node: ProsemirrorNode, + pos: number, + parent: ProsemirrorNode + ) => boolean | null | void + ): void; /** * Concatenates all the text nodes found in this fragment and its * children. @@ -510,47 +559,47 @@ declare class ProsemirrorNode { * Returns this node's first child, or `null` if there are no * children. */ - firstChild?: ProsemirrorNode | null; + firstChild?: ProsemirrorNode | null; /** * Returns this node's last child, or `null` if there are no * children. */ - lastChild?: ProsemirrorNode | null; + lastChild?: ProsemirrorNode | null; /** * Test whether two nodes represent the same piece of document. */ - eq(other: ProsemirrorNode): boolean; + eq(other: ProsemirrorNode): boolean; /** * Compare the markup (type, attributes, and marks) of this node to * those of another. Returns `true` if both have the same markup. */ - sameMarkup(other: ProsemirrorNode): boolean; + sameMarkup(other: ProsemirrorNode): boolean; /** * Check whether this node's markup correspond to the given type, * attributes, and marks. */ - hasMarkup(type: NodeType, attrs?: { [key: string]: any }, marks?: Mark[]): boolean; + hasMarkup(type: NodeType, attrs?: { [key: string]: any }, marks?: Array>): boolean; /** * Create a new node with the same markup as this node, containing * the given content (or empty, if no content is given). */ - copy(content?: Fragment): ProsemirrorNode; + copy(content?: Fragment): ProsemirrorNode; /** * Create a copy of this node, with the given set of marks instead * of the node's own marks. */ - mark(marks: Mark[]): ProsemirrorNode; + mark(marks: Array>): ProsemirrorNode; /** * Create a copy of this node with only the content between the * given positions. If `to` is not given, it defaults to the end of * the node. */ - cut(from: number, to?: number): ProsemirrorNode; + cut(from: number, to?: number): ProsemirrorNode; /** * Cut out the part of the document between the given positions, and * return it as a `Slice` object. */ - slice(from: number, to?: number): Slice; + slice(from: number, to?: number): Slice; /** * Replace the part of the document between the given positions with * the given slice. The slice must 'fit', meaning its open sides @@ -559,33 +608,33 @@ declare class ProsemirrorNode { * into. If any of this is violated, an error of type * [`ReplaceError`](#model.ReplaceError) is thrown. */ - replace(from: number, to: number, slice: Slice): ProsemirrorNode; + replace(from: number, to: number, slice: Slice): ProsemirrorNode; /** * Find the node starting at the given position. */ - nodeAt(pos: number): ProsemirrorNode | null | void; + nodeAt(pos: number): ProsemirrorNode | null | void; /** * Find the (direct) child node after the given offset, if any, * and return it along with its index and offset relative to this * node. */ - childAfter(pos: number): { node?: ProsemirrorNode | null, index: number, offset: number }; + childAfter(pos: number): { node?: ProsemirrorNode | null; index: number; offset: number }; /** * Find the (direct) child node before the given offset, if any, * and return it along with its index and offset relative to this * node. */ - childBefore(pos: number): { node?: ProsemirrorNode | null, index: number, offset: number }; + childBefore(pos: number): { node?: ProsemirrorNode | null; index: number; offset: number }; /** * Resolve the given position in the document, returning an * [object](#model.ResolvedPos) with information about its context. */ - resolve(pos: number): ResolvedPos; + resolve(pos: number): ResolvedPos; /** * Test whether a mark of the given type occurs in this document * between the two given positions. */ - rangeHasMark(from: number, to: number, type: MarkType): boolean; + rangeHasMark(from: number, to: number, type: MarkType): boolean; /** * True when this is a block (non-inline node) */ @@ -628,7 +677,7 @@ declare class ProsemirrorNode { /** * Get the content match in this node at the given index. */ - contentMatchAt(index: number): ContentMatch; + contentMatchAt(index: number): ContentMatch; /** * Test whether replacing the range between `from` and `to` (by * child index) with the given replacement fragment (which defaults @@ -636,19 +685,25 @@ declare class ProsemirrorNode { * can optionally pass `start` and `end` indices into the * replacement fragment. */ - canReplace(from: number, to: number, replacement?: Fragment, start?: number, end?: number): boolean; + canReplace( + from: number, + to: number, + replacement?: Fragment, + start?: number, + end?: number + ): boolean; /** * Test whether replacing the range `from` to `to` (by index) with a * node of the given type. */ - canReplaceWith(from: number, to: number, type: NodeType, marks?: Mark[]): boolean; + canReplaceWith(from: number, to: number, type: NodeType, marks?: Array>): boolean; /** * Test whether the given node's content could be appended to this * node. If that node is empty, this will only return true if there * is at least one node type that can appear in both nodes (to avoid * merging completely incompatible nodes). */ - canAppend(other: ProsemirrorNode): boolean; + canAppend(other: ProsemirrorNode): boolean; /** * Check whether this node and its descendants conform to the * schema, and raise error when they do not. @@ -661,21 +716,23 @@ declare class ProsemirrorNode { /** * Deserialize a node from its JSON representation. */ - static fromJSON(schema: Schema, json: { [key: string]: any }): ProsemirrorNode; + static fromJSON( + schema: S, + json: { [key: string]: any } + ): ProsemirrorNode; } export { ProsemirrorNode as Node }; /** * Error type raised by [`Node.replace`](#model.Node.replace) when * given an invalid replacement. */ -export class ReplaceError extends Error { -} +export class ReplaceError extends Error { } /** * A slice represents a piece cut out of a larger document. It * stores not only a fragment, but also the depth up to which nodes on * both side are ‘open’ (cut through). */ -export class Slice { +export class Slice { /** * Create a slice. When specifying a non-zero open depth, you must * make sure that there are nodes of at least that depth at the @@ -688,11 +745,11 @@ export class Slice { * start/end/middle for such a node, depending on which sides are * open. */ - constructor(content: Fragment, openStart: number, openEnd: number); + constructor(content: Fragment, openStart: number, openEnd: number); /** * The slice's content. */ - content: Fragment; + content: Fragment; /** * The open depth at the start. */ @@ -708,7 +765,7 @@ export class Slice { /** * Tests whether this slice is equal to another slice. */ - eq(other: Slice): boolean; + eq(other: Slice): boolean; /** * Convert a slice to a JSON-serializable representation. */ @@ -716,12 +773,15 @@ export class Slice { /** * Deserialize a slice from its JSON representation. */ - static fromJSON(schema: Schema, json?: { [key: string]: any }): Slice; + static fromJSON(schema: S, json?: { [key: string]: any }): Slice; /** * Create a slice from a fragment by taking the maximum possible * open value on both side of the fragment. */ - static maxOpen(fragment: Fragment, openIsolating?: boolean): Slice; + static maxOpen( + fragment: Fragment, + openIsolating?: boolean + ): Slice; /** * The empty slice. */ @@ -737,7 +797,7 @@ export class Slice { * parameter will interpret undefined as `this.depth` and negative * numbers as `this.depth + value`. */ -export class ResolvedPos { +export class ResolvedPos { /** * The position that was resolved. */ @@ -757,16 +817,16 @@ export class ResolvedPos { * a position points into a text node, that node is not considered * the parent—text nodes are ‘flat’ in this model, and have no content. */ - parent: ProsemirrorNode; + parent: ProsemirrorNode; /** * The root node in which the position was resolved. */ - doc: ProsemirrorNode; + doc: ProsemirrorNode; /** * The ancestor node at the given level. `p.node(p.depth)` is the * same as `p.parent`. */ - node(depth?: number): ProsemirrorNode; + node(depth?: number): ProsemirrorNode; /** * The index into the ancestor at the given level. If this points at * the 3rd node in the 2nd paragraph on the top level, for example, @@ -810,20 +870,20 @@ export class ResolvedPos { * points into a text node, only the part of that node after the * position is returned. */ - nodeAfter?: ProsemirrorNode | null; + nodeAfter?: ProsemirrorNode | null; /** * Get the node directly before the position, if any. If the * position points into a text node, only the part of that node * before the position is returned. */ - nodeBefore?: ProsemirrorNode | null; + nodeBefore?: ProsemirrorNode | null; /** * Get the marks at this position, factoring in the surrounding * marks' [`inclusive`](#model.MarkSpec.inclusive) property. If the * position is at the start of a non-empty node, the marks of the * node after it (if any) are returned. */ - marks(): Mark[]; + marks(): Array>; /** * Get the marks after the current position, if any, except those * that are non-inclusive and not present at position `$end`. This @@ -832,7 +892,7 @@ export class ResolvedPos { * its parent node or its parent node isn't a textblock (in which * case no marks should be preserved). */ - marksAcross($end: ResolvedPos): Mark[] | null | void; + marksAcross($end: ResolvedPos): Array> | null | void; /** * The depth up to which this position and the given (non-resolved) * position share the same parent nodes. @@ -847,31 +907,34 @@ export class ResolvedPos { * pass in an optional predicate that will be called with a parent * node to see if a range into that parent is acceptable. */ - blockRange(other?: ResolvedPos, pred?: (p: ProsemirrorNode) => boolean): NodeRange | null | void; + blockRange( + other?: ResolvedPos, + pred?: (p: ProsemirrorNode) => boolean + ): NodeRange | null | void; /** * Query whether the given position shares the same parent node. */ - sameParent(other: ResolvedPos): boolean; + sameParent(other: ResolvedPos): boolean; /** * Return the greater of this and the given position. */ - max(other: ResolvedPos): ResolvedPos; + max(other: ResolvedPos): ResolvedPos; /** * Return the smaller of this and the given position. */ - min(other: ResolvedPos): ResolvedPos; + min(other: ResolvedPos): ResolvedPos; } /** * Represents a flat range of content, i.e. one that starts and * ends in the same node. */ -export class NodeRange { +export class NodeRange { /** * Construct a node range. `$from` and `$to` should point into the * same node until at least the given `depth`, since a node range * denotes an adjacent set of nodes in a single parent node. */ - constructor($from: ResolvedPos, $to: ResolvedPos, depth: number); + constructor($from: ResolvedPos, $to: ResolvedPos, depth: number); /** * A resolved position along the start of the * content. May have a `depth` greater than this object's `depth` @@ -879,12 +942,12 @@ export class NodeRange { * compute the range, not re-resolved positions directly at its * boundaries. */ - $from: ResolvedPos; + $from: ResolvedPos; /** * A position along the end of the content. See * caveat for [`$from`](#model.NodeRange.$from). */ - $to: ResolvedPos; + $to: ResolvedPos; /** * The depth of the node that this range points into. */ @@ -900,7 +963,7 @@ export class NodeRange { /** * The parent node that the range points into. */ - parent: ProsemirrorNode; + parent: ProsemirrorNode; /** * The start index of the range in the parent node. */ @@ -916,7 +979,7 @@ export class NodeRange { * about the node type, such as its name and what kind of node it * represents. */ -export class NodeType { +export class NodeType { /** * The name the node type has in this schema. */ @@ -924,7 +987,7 @@ export class NodeType { /** * A link back to the `Schema` the node type belongs to. */ - schema: Schema; + schema: S; /** * The spec that this type is based on */ @@ -932,7 +995,7 @@ export class NodeType { /** * The starting match of the node type's content expression. */ - contentMatch: ContentMatch; + contentMatch: ContentMatch; /** * True if this node type has inline content. */ @@ -971,13 +1034,21 @@ export class NodeType { * `null`. Similarly `marks` may be `null` to default to the empty * set of marks. */ - create(attrs?: { [key: string]: any }, content?: Fragment | ProsemirrorNode | ProsemirrorNode[], marks?: Mark[]): ProsemirrorNode; + create( + attrs?: { [key: string]: any }, + content?: Fragment | ProsemirrorNode | Array>, + marks?: Array> + ): ProsemirrorNode; /** * Like [`create`](#model.NodeType.create), but check the given content * against the node type's content restrictions, and throw an error * if it doesn't match. */ - createChecked(attrs?: { [key: string]: any }, content?: Fragment | ProsemirrorNode | ProsemirrorNode[], marks?: Mark[]): ProsemirrorNode; + createChecked( + attrs?: { [key: string]: any }, + content?: Fragment | ProsemirrorNode | Array>, + marks?: Array> + ): ProsemirrorNode; /** * Like [`create`](#model.NodeType.create), but see if it is necessary to * add nodes to the start or end of the given fragment to make it @@ -986,24 +1057,28 @@ export class NodeType { * created, this will always succeed if you pass null or * `Fragment.empty` as content. */ - createAndFill(attrs?: { [key: string]: any }, content?: Fragment | ProsemirrorNode | ProsemirrorNode[], marks?: Mark[]): ProsemirrorNode | null | void; + createAndFill( + attrs?: { [key: string]: any }, + content?: Fragment | ProsemirrorNode | Array>, + marks?: Array> + ): ProsemirrorNode | null | void; /** * Returns true if the given fragment is valid content for this node * type with the given attributes. */ - validContent(content: Fragment): boolean; + validContent(content: Fragment): boolean; /** * Check whether the given mark type is allowed in this node. */ - allowsMarkType(markType: MarkType): boolean; + allowsMarkType(markType: MarkType): boolean; /** * Test whether the given set of marks are allowed in this node. */ - allowsMarks(marks: Mark[]): boolean; + allowsMarks(marks: Array>): boolean; /** * Removes the marks that are not allowed in this node from the given set. */ - allowedMarks(marks: Mark[]): Mark[]; + allowedMarks(marks: Array>): Array>; } /** * Like nodes, marks (which are associated with nodes to signify @@ -1011,7 +1086,7 @@ export class NodeType { * [tagged](#model.Mark.type) with type objects, which are * instantiated once per `Schema`. */ -export class MarkType { +export class MarkType { /** * The name of the mark type. */ @@ -1019,7 +1094,7 @@ export class MarkType { /** * The schema that this mark type instance is part of. */ - schema: Schema; + schema: S; /** * The spec on which the type is based. */ @@ -1029,27 +1104,27 @@ export class MarkType { * containing only some of the mark's attributes. The others, if * they have defaults, will be added. */ - create(attrs?: { [key: string]: any }): Mark; + create(attrs?: { [key: string]: any }): Mark; /** * When there is a mark of this type in the given set, a new set * without it is returned. Otherwise, the input set is returned. */ - removeFromSet(set: Mark[]): Mark[]; + removeFromSet(set: Array>): Array>; /** * Tests whether there is a mark of this type in the given set. */ - isInSet(set: Mark[]): Mark | null | void; + isInSet(set: Array>): Mark | null | void; /** * Queries whether a given mark type is * [excluded](#model.MarkSpec.excludes) by this one. */ - excludes(other: MarkType): boolean; + excludes(other: MarkType): boolean; } /** * An object describing a schema, as passed to the [`Schema`](#model.Schema) * constructor. */ -export interface SchemaSpec { +export interface SchemaSpec { /** * The node types in this schema. Maps names to * [`NodeSpec`](#model.NodeSpec) objects that describe the node type @@ -1058,14 +1133,14 @@ export interface SchemaSpec { * precedence by default, and which nodes come first in a given * [group](#model.NodeSpec.group). */ - nodes: { [name: string]: NodeSpec } | OrderedMap; + nodes: { [name in N]: NodeSpec } | OrderedMap; /** * The mark types that exist in this schema. The order in which they * are provided determines the order in which [mark * sets](#model.Mark.addToSet) are sorted and in which [parse * rules](#model.MarkSpec.parseDOM) are tried. */ - marks?: { [name: string]: MarkSpec } | OrderedMap | null; + marks?: { [name in M]: MarkSpec } | OrderedMap | null; /** * The name of the default top-level node for the schema. Defaults * to `"doc"`. @@ -1228,11 +1303,11 @@ export interface AttributeSpec { * occur in conforming documents, and provides functionality for * creating and deserializing such documents. */ -export class Schema { +export class Schema { /** * Construct a schema from a schema [specification](#model.SchemaSpec). */ - constructor(spec: SchemaSpec); + constructor(spec: SchemaSpec); /** * The [spec](#model.SchemaSpec) on which the schema is based, * with the added guarantee that its `nodes` and `marks` @@ -1240,20 +1315,20 @@ export class Schema { * [`OrderedMap`](https://github.com/marijnh/orderedmap) instances * (not raw objects). */ - spec: SchemaSpec; + spec: SchemaSpec; /** * An object mapping the schema's node names to node type objects. */ - nodes: { [name: string]: NodeType }; + nodes: { [name in N]: NodeType> } & { [key: string]: NodeType> }; /** * A map from mark names to mark type objects. */ - marks: { [name: string]: MarkType }; + marks: { [name in M]: MarkType> } & { [key: string]: NodeType> }; /** * The type of the [default top node](#model.SchemaSpec.topNode) * for this schema. */ - topNodeType: NodeType; + topNodeType: NodeType>; /** * An object for storing whatever values modules may want to * compute and cache per schema. (If you want to store something @@ -1266,26 +1341,34 @@ export class Schema { * with defaults, `content` may be a `Fragment`, * `null`, a `Node`, or an array of nodes. */ - node(type: string | NodeType, attrs?: { [key: string]: any }, content?: Fragment | ProsemirrorNode | ProsemirrorNode[], marks?: Mark[]): ProsemirrorNode; + node( + type: string | NodeType>, + attrs?: { [key: string]: any }, + content?: + | Fragment> + | ProsemirrorNode> + | Array>>, + marks?: Array>> + ): ProsemirrorNode>; /** * Create a text node in the schema. Empty text nodes are not * allowed. */ - text(text: string, marks?: Mark[]): ProsemirrorNode; + text(text: string, marks?: Array>>): ProsemirrorNode>; /** * Create a mark with the given type and attributes. */ - mark(type: string | MarkType, attrs?: { [key: string]: any }): Mark; + mark(type: string | MarkType>, attrs?: { [key: string]: any }): Mark>; /** * Deserialize a node from its JSON representation. This method is * bound. */ - nodeFromJSON(json: { [key: string]: any }): ProsemirrorNode; + nodeFromJSON(json: { [key: string]: any }): ProsemirrorNode>; /** * Deserialize a mark from its JSON representation. This method is * bound. */ - markFromJSON(json: { [key: string]: any }): Mark; + markFromJSON(json: { [key: string]: any }): Mark>; } export interface DOMOutputSpecArray { 0: string; @@ -1299,15 +1382,12 @@ export interface DOMOutputSpecArray { 8?: DOMOutputSpec | 0; 9?: DOMOutputSpec | 0; } -export type DOMOutputSpec - = string - | Node - | DOMOutputSpecArray; +export type DOMOutputSpec = string | Node | DOMOutputSpecArray; /** * A DOM serializer knows how to convert ProseMirror nodes and * marks of various types to DOM nodes. */ -export class DOMSerializer { +export class DOMSerializer { /** * Create a serializer. `nodes` should map node names to functions * that take a node and return a description of the corresponding @@ -1317,22 +1397,25 @@ export class DOMSerializer { * serializer may be `null` to indicate that marks of that type * should not be serialized. */ - constructor(nodes: { [name: string]: (node: ProsemirrorNode) => DOMOutputSpec }, marks: { [name: string]: (mark: Mark, inline: boolean) => DOMOutputSpec }); + constructor( + nodes: { [name: string]: (node: ProsemirrorNode) => DOMOutputSpec }, + marks: { [name: string]: (mark: Mark, inline: boolean) => DOMOutputSpec } + ); /** * The node serialization functions. */ - nodes: { [name: string]: (node: ProsemirrorNode) => DOMOutputSpec }; + nodes: { [name: string]: (node: ProsemirrorNode) => DOMOutputSpec }; /** * The mark serialization functions. */ - marks: { [name: string]: (mark: Mark, inline: boolean) => DOMOutputSpec }; + marks: { [name: string]: (mark: Mark, inline: boolean) => DOMOutputSpec }; /** * Serialize the content of this fragment to a DOM fragment. When * not in the browser, the `document` option, containing a DOM * document, should be passed so that the serializer can create * nodes. */ - serializeFragment(fragment: Fragment, options?: { [key: string]: any }): DocumentFragment; + serializeFragment(fragment: Fragment, options?: { [key: string]: any }): DocumentFragment; /** * Serialize this node to a DOM node. This can be useful when you * need to serialize a part of a document, as opposed to the whole @@ -1340,16 +1423,19 @@ export class DOMSerializer { * [`serializeFragment`](#model.DOMSerializer.serializeFragment) on * its [content](#model.Node.content). */ - serializeNode(node: ProsemirrorNode, options?: { [key: string]: any }): Node; + serializeNode(node: ProsemirrorNode, options?: { [key: string]: any }): Node; /** * Render an [output spec](#model.DOMOutputSpec) to a DOM node. If * the spec has a hole (zero) in it, `contentDOM` will point at the * node with the hole. */ - static renderSpec(doc: Document, structure: DOMOutputSpec): { dom: Node, contentDOM?: Node | null }; + static renderSpec( + doc: Document, + structure: DOMOutputSpec + ): { dom: Node; contentDOM?: Node | null }; /** * Build a serializer using the [`toDOM`](#model.NodeSpec.toDOM) * properties in a schema's node and mark specs. */ - static fromSchema(schema: Schema): DOMSerializer; + static fromSchema(schema: S): DOMSerializer; } diff --git a/types/prosemirror-model/prosemirror-model-tests.ts b/types/prosemirror-model/prosemirror-model-tests.ts index d6ac1c2a5f..98460d4313 100644 --- a/types/prosemirror-model/prosemirror-model-tests.ts +++ b/types/prosemirror-model/prosemirror-model-tests.ts @@ -13,26 +13,28 @@ domOutputSpec = ['div', ['div', { class: 'foo' }]]; domOutputSpec = ['div', ['div', { class: 'foo' }, 0]]; export const nodeSpec: model.NodeSpec = { - attrs: { - name: { default: '' }, - }, - parseDOM: [{ - tag: 'span[data-name]', - getAttrs(dom) { - if (dom instanceof HTMLElement) { - return { - name: dom.getAttribute('data-name')! + attrs: { + name: { default: '' } + }, + parseDOM: [ + { + tag: 'span[data-name]', + getAttrs(dom) { + if (dom instanceof HTMLElement) { + return { + name: dom.getAttribute('data-name')! + }; + } + } + } + ], + toDOM(node) { + const { name } = node.attrs; + const attrs = { + 'data-emoji-name': name }; - } + return ['span', attrs, 0]; } - }], - toDOM(node) { - const { name } = node.attrs; - const attrs = { - 'data-emoji-name': name, - }; - return ['span', attrs, 0]; - } }; const node = new model.Node(); diff --git a/types/prosemirror-schema-basic/index.d.ts b/types/prosemirror-schema-basic/index.d.ts index 0e7a6f7846..49c9d29851 100644 --- a/types/prosemirror-schema-basic/index.d.ts +++ b/types/prosemirror-schema-basic/index.d.ts @@ -3,12 +3,9 @@ // Definitions by: Bradley Ayers // David Hahn // Tim Baumann +// Patrick Simmelbauer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 - -// IMPORTANT -// This file was generated by https://github.com/bradleyayers/getdocs2ts. Please do not edit manually. -// When you find an error in these declarations, fix the getdocs comment upstream or 'getdocs2ts', then regenerate. +// TypeScript Version: 2.3 import { MarkSpec, NodeSpec, Schema } from 'prosemirror-model'; @@ -16,20 +13,25 @@ import { MarkSpec, NodeSpec, Schema } from 'prosemirror-model'; * [Specs](#model.NodeSpec) for the nodes defined in this schema. */ export let nodes: { - doc: NodeSpec, - paragraph: NodeSpec, - blockquote: NodeSpec, - horizontal_rule: NodeSpec, - heading: NodeSpec, - code_block: NodeSpec, - text: NodeSpec, - image: NodeSpec, - hard_break: NodeSpec + doc: NodeSpec; + paragraph: NodeSpec; + blockquote: NodeSpec; + horizontal_rule: NodeSpec; + heading: NodeSpec; + code_block: NodeSpec; + text: NodeSpec; + image: NodeSpec; + hard_break: NodeSpec; }; /** * [Specs](#model.MarkSpec) for the marks in the schema. */ -export let marks: { link: MarkSpec, em: MarkSpec, strong: MarkSpec, code: MarkSpec }; +export let marks: { + link: MarkSpec; + em: MarkSpec; + strong: MarkSpec; + code: MarkSpec; +}; /** * This schema rougly corresponds to the document schema used by * [CommonMark](http://commonmark.org/), minus the list elements, @@ -39,4 +41,4 @@ export let marks: { link: MarkSpec, em: MarkSpec, strong: MarkSpec, code: MarkSp * To reuse elements from this schema, extend or read from its * `spec.nodes` and `spec.marks` [properties](#model.Schema.spec). */ -export let schema: Schema; +export let schema: Schema; diff --git a/types/prosemirror-schema-list/index.d.ts b/types/prosemirror-schema-list/index.d.ts index 01053b06cd..9c97c3fcdb 100644 --- a/types/prosemirror-schema-list/index.d.ts +++ b/types/prosemirror-schema-list/index.d.ts @@ -3,15 +3,12 @@ // Definitions by: Bradley Ayers // David Hahn // Tim Baumann +// Patrick Simmelbauer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 - -// IMPORTANT -// This file was generated by https://github.com/bradleyayers/getdocs2ts. Please do not edit manually. -// When you find an error in these declarations, fix the getdocs comment upstream or 'getdocs2ts', then regenerate. +// TypeScript Version: 2.3 import OrderedMap = require('orderedmap'); -import { NodeSpec, NodeType } from 'prosemirror-model'; +import { NodeSpec, NodeType, Schema } from 'prosemirror-model'; import { EditorState, Transaction } from 'prosemirror-state'; /** @@ -43,26 +40,39 @@ export let listItem: NodeSpec; * given to assign a group name to the list node types, for example * `"block"`. */ -export function addListNodes(nodes: OrderedMap, itemContent: string, listGroup?: string): OrderedMap; +export function addListNodes( + nodes: OrderedMap, + itemContent: string, + listGroup?: string +): OrderedMap; /** * Returns a command function that wraps the selection in a list with * the given type an attributes. If `dispatch` is null, only return a * value to indicate whether this is possible, but don't actually * perform the change. */ -export function wrapInList(listType: NodeType, attrs?: { [key: string]: any }): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean; +export function wrapInList( + listType: NodeType, + attrs?: { [key: string]: any } +): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean; /** * Build a command that splits a non-empty textblock at the top level * of a list item by also splitting that list item. */ -export function splitListItem(itemType: NodeType): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean; +export function splitListItem( + itemType: NodeType +): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean; /** * Create a command to lift the list item around the selection up into * a wrapping list. */ -export function liftListItem(itemType: NodeType): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean; +export function liftListItem( + itemType: NodeType +): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean; /** * Create a command to sink the list item around the selection down * into an inner list. */ -export function sinkListItem(itemType: NodeType): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean; +export function sinkListItem( + itemType: NodeType +): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean; diff --git a/types/prosemirror-state/index.d.ts b/types/prosemirror-state/index.d.ts index 781a1459e9..6b210a73e1 100644 --- a/types/prosemirror-state/index.d.ts +++ b/types/prosemirror-state/index.d.ts @@ -1,16 +1,20 @@ -// Type definitions for prosemirror-state 1.0 +// Type definitions for prosemirror-state 1.1 // Project: https://github.com/ProseMirror/prosemirror-state // Definitions by: Bradley Ayers // David Hahn // Tim Baumann +// Patrick Simmelbauer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 +// TypeScript Version: 2.3 -// IMPORTANT -// This file was generated by https://github.com/bradleyayers/getdocs2ts. Please do not edit manually. -// When you find an error in these declarations, fix the getdocs comment upstream or 'getdocs2ts', then regenerate. - -import { Mark, MarkType, Node as ProsemirrorNode, ResolvedPos, Schema, Slice } from 'prosemirror-model'; +import { + Mark, + MarkType, + Node as ProsemirrorNode, + ResolvedPos, + Schema, + Slice +} from 'prosemirror-model'; import { Mappable, Mapping, Transform } from 'prosemirror-transform'; import { EditorProps, EditorView } from 'prosemirror-view'; @@ -18,13 +22,13 @@ import { EditorProps, EditorView } from 'prosemirror-view'; * This is the type passed to the [`Plugin`](#state.Plugin) * constructor. It provides a definition for a plugin. */ -export interface PluginSpec { +export interface PluginSpec { /** * The [view props](#view.EditorProps) added by this plugin. Props * that are functions will be bound to have the plugin instance as * their `this` binding. */ - props?: EditorProps | null; + props?: EditorProps | null; /** * Allows a plugin to define a [state field](#state.StateField), an * extra slot in the state object in which it can keep its own data. @@ -36,20 +40,27 @@ export interface PluginSpec { * access the plugin's configuration and state through the key, * without having access to the plugin instance object. */ - key?: PluginKey | null; + key?: PluginKey | null; /** * When the plugin needs to interact with the editor view, or * set something up in the DOM, use this field. The function * will be called when the plugin's state is associated with an * editor view. */ - view?: ((p: EditorView) => { update?: ((view: EditorView, prevState: EditorState) => void) | null, destroy?: (() => void) | null }) | null; + view?: + | (( + p: EditorView + ) => { + update?: ((view: EditorView, prevState: EditorState) => void) | null; + destroy?: (() => void) | null; + }) + | null; /** * When present, this will be called before a transaction is * applied by the state, allowing the plugin to cancel it (by * returning false). */ - filterTransaction?: ((p1: Transaction, p2: EditorState) => boolean) | null; + filterTransaction?: ((p1: Transaction, p2: EditorState) => boolean) | null; /** * Allows the plugin to append another transaction to be applied * after the given array of transactions. When another plugin @@ -58,22 +69,28 @@ export interface PluginSpec { * transactions, i.e. it won't be passed transactions that it * already saw. */ - appendTransaction?: ((transactions: Transaction[], oldState: EditorState, newState: EditorState) => Transaction | null | void) | null; + appendTransaction?: + | (( + transactions: Transaction[], + oldState: EditorState, + newState: EditorState + ) => Transaction | null | void) + | null; } /** * Plugins bundle functionality that can be added to an editor. * They are part of the [editor state](#state.EditorState) and * may influence that state and the view that contains it. */ -export class Plugin { +export class Plugin { /** * Create a plugin. */ - constructor(spec: PluginSpec); + constructor(spec: PluginSpec); /** * The [props](#view.EditorProps) exported by this plugin. */ - props: EditorProps; + props: EditorProps; /** * The plugin's [spec object](#state.PluginSpec). */ @@ -81,7 +98,7 @@ export class Plugin { /** * Extract the plugin's state field from an editor state. */ - getState(state: EditorState): any; + getState(state: EditorState): any; } /** * A plugin spec may provide a state field (under its @@ -89,21 +106,21 @@ export class Plugin { * describes the state it wants to keep. Functions provided here are * always called with the plugin instance as their `this` binding. */ -export interface StateField { +export interface StateField { /** * Initialize the value of the field. `config` will be the object * passed to [`EditorState.create`](#state.EditorState^create). Note * that `instance` is a half-initialized state instance, and will * not have values for plugin fields initialized after this one. */ - init(config: { [key: string]: any }, instance: EditorState): T; + init(config: { [key: string]: any }, instance: EditorState): T; /** * Apply the given transaction to this state field, producing a new * field value. Note that the `newState` argument is again a partially * constructed state does not yet contain the state from plugins * coming after this one. */ - apply(tr: Transaction, value: T, oldState: EditorState, newState: EditorState): T; + apply(tr: Transaction, value: T, oldState: EditorState, newState: EditorState): T; /** * Convert this field to JSON. Optional, can be left off to disable * JSON serialization for the field. @@ -113,7 +130,7 @@ export interface StateField { * Deserialize the JSON representation of this field. Note that the * `state` argument is again a half-initialized state. */ - fromJSON?: ((config: { [key: string]: any }, value: any, state: EditorState) => T) | null; + fromJSON?: ((config: { [key: string]: any }, value: any, state: EditorState) => T) | null; } /** * A key is used to [tag](#state.PluginSpec.key) @@ -121,7 +138,7 @@ export interface StateField { * editor state. Assigning a key does mean only one plugin of that * type can be active in a state. */ -export class PluginKey { +export class PluginKey { /** * Create a plugin key. */ @@ -130,37 +147,37 @@ export class PluginKey { * Get the active plugin with this key, if any, from an editor * state. */ - get(state: EditorState): Plugin | null | void; + get(state: EditorState): Plugin | null | void; /** * Get the plugin's state from an editor state. */ - getState(state: EditorState): any | null | void; + getState(state: EditorState): any | null | void; } /** * Superclass for editor selections. Every selection type should * extend this. Should not be instantiated directly. */ -export class Selection { +export class Selection { /** * Initialize a selection with the head and anchor and ranges. If no * ranges are given, constructs a single range across `$anchor` and * `$head`. */ - constructor($anchor: ResolvedPos, $head: ResolvedPos, ranges?: SelectionRange[]); + constructor($anchor: ResolvedPos, $head: ResolvedPos, ranges?: Array>); /** * The ranges covered by the selection. */ - ranges: SelectionRange[]; + ranges: Array>; /** * The resolved anchor of the selection (the side that stays in * place when the selection is modified). */ - $anchor: ResolvedPos; + $anchor: ResolvedPos; /** * The resolved head of the selection (the side that moves when * the selection is modified). */ - $head: ResolvedPos; + $head: ResolvedPos; /** * The selection's anchor, as an unresolved position. */ @@ -180,11 +197,11 @@ export class Selection { /** * The resolved lower bound of the selection's main range. */ - $from: ResolvedPos; + $from: ResolvedPos; /** * The resolved upper bound of the selection's main range. */ - $to: ResolvedPos; + $to: ResolvedPos; /** * Indicates whether the selection contains any content. */ @@ -192,26 +209,26 @@ export class Selection { /** * Test whether the selection is the same as another selection. */ - eq(p: Selection): boolean; + eq(p: Selection): boolean; /** * Map this selection through a [mappable](#transform.Mappable) thing. `doc` * should be the new document to which we are mapping. */ - map(doc: ProsemirrorNode, mapping: Mappable): Selection; + map(doc: ProsemirrorNode, mapping: Mappable): Selection; /** * Get the content of this selection as a slice. */ - content(): Slice; + content(): Slice; /** * Replace the selection with a slice or, if no slice is given, * delete the selection. Will append to the given transaction. */ - replace(tr: Transaction, content?: Slice): void; + replace(tr: Transaction, content?: Slice): void; /** * Replace the selection with the given node, appending the changes * to the given transaction. */ - replaceWith(tr: Transaction, node: ProsemirrorNode): void; + replaceWith(tr: Transaction, node: ProsemirrorNode): void; /** * Convert the selection to a JSON representation. When implementing * this for a custom selection class, make sure to give the object a @@ -228,7 +245,7 @@ export class Selection { * this method just converts the selection to a text selection and * returns the bookmark for that. */ - getBookmark(): SelectionBookmark; + getBookmark(): SelectionBookmark; /** * Controls whether, when a selection of this type is active in the * browser, the selected range should be visible to the user. Defaults @@ -242,30 +259,37 @@ export class Selection { * selections. Will return null when no valid selection position is * found. */ - static findFrom($pos: ResolvedPos, dir: number, textOnly?: boolean): Selection | null | void; + static findFrom( + $pos: ResolvedPos, + dir: number, + textOnly?: boolean + ): Selection | null | void; /** * Find a valid cursor or leaf node selection near the given * position. Searches forward first by default, but if `bias` is * negative, it will search backwards first. */ - static near($pos: ResolvedPos, bias?: number): Selection; + static near($pos: ResolvedPos, bias?: number): Selection; /** * Find the cursor or leaf node selection closest to the start of * the given document. Will return an * [`AllSelection`](#state.AllSelection) if no valid position * exists. */ - static atStart(doc: ProsemirrorNode): Selection; + static atStart(doc: ProsemirrorNode): Selection; /** * Find the cursor or leaf node selection closest to the end of the * given document. */ - static atEnd(doc: ProsemirrorNode): Selection; + static atEnd(doc: ProsemirrorNode): Selection; /** * Deserialize the JSON representation of a selection. Must be * implemented for custom classes (as a static class method). */ - static fromJSON(doc: ProsemirrorNode, json: { [key: string]: any }): Selection; + static fromJSON( + doc: ProsemirrorNode, + json: { [key: string]: any } + ): Selection; /** * To be able to deserialize selections from JSON, custom selection * classes must register themselves with an ID string, so that they @@ -279,32 +303,32 @@ export class Selection { * You can define a custom bookmark type for a custom selection class * to make the history handle it well. */ -export interface SelectionBookmark { +export interface SelectionBookmark { /** * Map the bookmark through a set of changes. */ - map(mapping: Mapping): SelectionBookmark; + map(mapping: Mapping): SelectionBookmark; /** * Resolve the bookmark to a real selection again. This may need to * do some error checking and may fall back to a default (usually * [`TextSelection.between`](#state.TextSelection^between)) if * mapping made the bookmark invalid. */ - resolve(doc: ProsemirrorNode): Selection; + resolve(doc: ProsemirrorNode): Selection; } /** * Represents a selected range in a document. */ -export class SelectionRange { - constructor($from: ResolvedPos, $to: ResolvedPos); +export class SelectionRange { + constructor($from: ResolvedPos, $to: ResolvedPos); /** * The lower bound of the range. */ - $from: ResolvedPos; + $from: ResolvedPos; /** * The upper bound of the range. */ - $to: ResolvedPos; + $to: ResolvedPos; } /** * A text selection represents a classical editor selection, with @@ -312,20 +336,24 @@ export class SelectionRange { * point into textblock nodes. It can be empty (a regular cursor * position). */ -export class TextSelection extends Selection { +export class TextSelection extends Selection { /** * Construct a text selection between the given points. */ - constructor($anchor: ResolvedPos, $head?: ResolvedPos); + constructor($anchor: ResolvedPos, $head?: ResolvedPos); /** * Returns a resolved position if this is a cursor selection (an * empty text selection), and null otherwise. */ - $cursor?: ResolvedPos | null; + $cursor?: ResolvedPos | null; /** * Create a text selection from non-resolved positions. */ - static create(doc: ProsemirrorNode, anchor: number, head?: number): TextSelection; + static create( + doc: ProsemirrorNode, + anchor: number, + head?: number + ): TextSelection; /** * Return a text selection that spans the given positions or, if * they aren't text positions, find a text selection near them. @@ -334,7 +362,11 @@ export class TextSelection extends Selection { * [`Selection.near`](#state.Selection^near) when the document * doesn't contain a valid text position. */ - static between($anchor: ResolvedPos, $head: ResolvedPos, bias?: number): Selection; + static between( + $anchor: ResolvedPos, + $head: ResolvedPos, + bias?: number + ): Selection; } /** * A node selection is a selection that points at a single node. @@ -343,20 +375,23 @@ export class TextSelection extends Selection { * `to` point directly before and after the selected node, `anchor` * equals `from`, and `head` equals `to`.. */ -export class NodeSelection extends Selection { +export class NodeSelection extends Selection { /** * Create a node selection. Does not verify the validity of its * argument. */ - constructor($pos: ResolvedPos); + constructor($pos: ResolvedPos); /** * The selected node. */ - node: ProsemirrorNode; + node: ProsemirrorNode; /** * Create a node selection from non-resolved positions. */ - static create(doc: ProsemirrorNode, from: number): NodeSelection; + static create( + doc: ProsemirrorNode, + from: number + ): NodeSelection; /** * Determines whether the given node may be selected as a node * selection. @@ -369,11 +404,11 @@ export class NodeSelection extends Selection { * there are for example leaf block nodes at the start or end of the * document). */ -export class AllSelection extends Selection { +export class AllSelection extends Selection { /** * Create an all-selection over the given document. */ - constructor(doc: ProsemirrorNode); + constructor(doc: ProsemirrorNode); } /** * The state of a ProseMirror editor is represented by an object @@ -384,32 +419,32 @@ export class AllSelection extends Selection { * A state holds a number of built-in fields, and plugins can * [define](#state.PluginSpec.state) additional fields. */ -export class EditorState { +export class EditorState { /** * The current document. */ - doc: ProsemirrorNode; + doc: ProsemirrorNode; /** * The selection. */ - selection: Selection; + selection: Selection; /** * A set of marks to apply to the next input. Will be null when * no explicit marks have been set. */ - storedMarks?: Mark[] | null; + storedMarks?: Array> | null; /** * The schema of the state's document. */ - schema: Schema; + schema: S; /** * The plugins that are active in this state. */ - plugins: Plugin[]; + plugins: Array>; /** * Apply the given transaction to produce a new state. */ - apply(tr: Transaction): EditorState; + apply(tr: Transaction): EditorState; /** * Verbose variant of [`apply`](#state.EditorState.apply) that * returns the precise transactions that were applied (which might @@ -417,7 +452,7 @@ export class EditorState { * hooks](#state.PluginSpec.filterTransaction) of * plugins) along with the new state. */ - applyTransaction(tr: Transaction): { state: EditorState, transactions: Transaction[] }; + applyTransaction(tr: Transaction): { state: EditorState; transactions: Transaction[] }; /** * Start a [transaction](#state.Transaction) from this state. */ @@ -430,17 +465,22 @@ export class EditorState { * [`init`](#state.StateField.init) method, passing in the new * configuration object.. */ - reconfigure(config: { schema?: Schema | null, plugins?: Plugin[] | null }): EditorState; + reconfigure(config: { schema?: S | null; plugins?: Array> | null }): EditorState; /** * Serialize this state to JSON. If you want to serialize the state * of plugins, pass an object mapping property names to use in the * resulting JSON object to plugin objects. */ - toJSON(pluginFields?: { [name: string]: Plugin }): { [key: string]: any }; + toJSON(pluginFields?: { [name: string]: Plugin } | string | number): { [key: string]: any }; /** * Create a new state. */ - static create(config: { schema?: Schema | null, doc?: ProsemirrorNode | null, selection?: Selection | null, plugins?: Plugin[] | null }): EditorState; + static create(config: { + schema?: S | null; + doc?: ProsemirrorNode | null; + selection?: Selection | null; + plugins?: Array> | null; + }): EditorState; /** * Deserialize a JSON representation of a state. `config` should * have at least a `schema` field, and should contain array of @@ -448,7 +488,11 @@ export class EditorState { * to deserialize the state of plugins, by associating plugin * instances with the property names they use in the JSON object. */ - static fromJSON(config: { schema: Schema, plugins?: Plugin[] | null }, json: { [key: string]: any }, pluginFields?: { [name: string]: Plugin }): EditorState; + static fromJSON( + config: { schema: S; plugins?: Array> | null }, + json: { [key: string]: any }, + pluginFields?: { [name: string]: Plugin } + ): EditorState; } /** * An editor state transaction, which can be applied to a state to @@ -469,7 +513,7 @@ export class EditorState { * selection transactions directly caused by mouse or touch input, and * a `"paste"` property of true to transactions caused by a paste.. */ -export class Transaction extends Transform { +export class Transaction extends Transform { /** * The timestamp associated with this transaction, in the same * format as `Date.now()`. diff --git a/types/prosemirror-tables/index.d.ts b/types/prosemirror-tables/index.d.ts index 53df9fc220..9ae723910b 100644 --- a/types/prosemirror-tables/index.d.ts +++ b/types/prosemirror-tables/index.d.ts @@ -2,10 +2,12 @@ // Project: https://github.com/ProseMirror/prosemirror-tables // Definitions by: Oscar Wallhult // Eduard Shvedai +// Patrick Simmelbauer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 + import { EditorState, Plugin, SelectionRange, Transaction, PluginKey } from 'prosemirror-state'; -import { Node as ProsemirrorNode, NodeSpec, Slice, ResolvedPos } from 'prosemirror-model'; +import { Node as ProsemirrorNode, NodeSpec, Slice, ResolvedPos, Schema } from 'prosemirror-model'; import { NodeView } from 'prosemirror-view'; export interface TableNodesOptions { @@ -38,37 +40,50 @@ export interface CellSelectionJSON { head: number; } -export class CellSelection { - constructor($anchorCell: ResolvedPos, $headCell?: ResolvedPos); +export class CellSelection { + constructor($anchorCell: ResolvedPos, $headCell?: ResolvedPos); from: number; to: number; - $from: ResolvedPos; - $to: ResolvedPos; + $from: ResolvedPos; + $to: ResolvedPos; anchor: number; head: number; - $anchor: ResolvedPos; - $head: ResolvedPos; - $anchorCell: ResolvedPos; - $headCell: ResolvedPos; + $anchor: ResolvedPos; + $head: ResolvedPos; + $anchorCell: ResolvedPos; + $headCell: ResolvedPos; empty: boolean; - ranges: SelectionRange[]; + ranges: Array>; - map(doc: ProsemirrorNode, mapping: any): any; - content(): Slice; - replace(tr: Transaction, content: Slice): void; - replaceWith(tr: Transaction, node: ProsemirrorNode): void; - forEachCell(f: (node: ProsemirrorNode, pos: number) => void): void; + map(doc: ProsemirrorNode, mapping: any): any; + content(): Slice; + replace(tr: Transaction, content: Slice): void; + replaceWith(tr: Transaction, node: ProsemirrorNode): void; + forEachCell(f: (node: ProsemirrorNode, pos: number) => void): void; isRowSelection(): boolean; isColSelection(): boolean; eq(other: any): boolean; toJSON(): CellSelectionJSON; - getBookmark(): {anchor: number, head: number}; + getBookmark(): { anchor: number; head: number }; - static colSelection(anchorCell: ResolvedPos, headCell?: ResolvedPos): CellSelection; - static rowSelection(anchorCell: ResolvedPos, headCell?: ResolvedPos): CellSelection; - static create(doc: ProsemirrorNode, anchorCell: number, headCell?: number): CellSelection; - static fromJSON(doc: ProsemirrorNode, json: CellSelectionJSON): CellSelection; + static colSelection( + anchorCell: ResolvedPos, + headCell?: ResolvedPos + ): CellSelection; + static rowSelection( + anchorCell: ResolvedPos, + headCell?: ResolvedPos + ): CellSelection; + static create( + doc: ProsemirrorNode, + anchorCell: number, + headCell?: number + ): CellSelection; + static fromJSON( + doc: ProsemirrorNode, + json: CellSelectionJSON + ): CellSelection; } export interface Rect { @@ -96,52 +111,115 @@ export class TableMap { export function tableEditing(): Plugin; -export function deleteTable(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function deleteTable( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; -export function goToNextCell(direction: number): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean; +export function goToNextCell( + direction: number +): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean; -export function toggleHeaderCell(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function toggleHeaderCell( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; -export function toggleHeaderColumn(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function toggleHeaderColumn( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; -export function toggleHeaderRow(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function toggleHeaderRow( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; -export function setCellAttr(name: string, value: any): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean; +export function setCellAttr( + name: string, + value: any +): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean; -export function splitCell(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function splitCell( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; -export function mergeCells(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function mergeCells( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; -export function deleteRow(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function deleteRow( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; -export function addRowAfter(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function addRowAfter( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; -export function addRowBefore(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function addRowBefore( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; -export function deleteColumn(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function deleteColumn( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; -export function addColumnAfter(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function addColumnAfter( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; -export function addColumnBefore(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; +export function addColumnBefore( + state: EditorState, + dispatch?: (tr: Transaction) => void +): boolean; -export function columnResizing(props: { handleWidth?: number, cellMinWidth?: number, View?: NodeView }): Plugin; +export function columnResizing(props: { + handleWidth?: number; + cellMinWidth?: number; + View?: NodeView; +}): Plugin; export const columnResizingPluginKey: PluginKey; -export function updateColumnsOnResize(node: ProsemirrorNode, colgroup: Element, table: Element, cellMinWidth: number, overrideCol?: number, overrideValue?: number): void; +export function updateColumnsOnResize( + node: ProsemirrorNode, + colgroup: Element, + table: Element, + cellMinWidth: number, + overrideCol?: number, + overrideValue?: number +): void; -export function cellAround(pos: ResolvedPos): ResolvedPos | null; +export function cellAround(pos: ResolvedPos): ResolvedPos | null; export function isInTable(state: EditorState): boolean; -export function selectionCell(state: EditorState): ResolvedPos | null | undefined; +export function selectionCell( + state: EditorState +): ResolvedPos | null | undefined; -export function moveCellForward(pos: ResolvedPos): ResolvedPos; +export function moveCellForward(pos: ResolvedPos): ResolvedPos; -export function inSameTable($a: ResolvedPos, $b: ResolvedPos): boolean; +export function inSameTable( + $a: ResolvedPos, + $b: ResolvedPos +): boolean; -export function findCell(pos: ResolvedPos): {top: number, left: number, right: number, buttom: number}; +export function findCell( + pos: ResolvedPos +): { top: number; left: number; right: number; buttom: number }; export function colCount(pos: ResolvedPos): number; -export function nextCell(pos: ResolvedPos, axis: string, dir: number): null | ResolvedPos; +export function nextCell( + pos: ResolvedPos, + axis: string, + dir: number +): null | ResolvedPos; diff --git a/types/prosemirror-transform/index.d.ts b/types/prosemirror-transform/index.d.ts index 8f386b4bd3..c0b63136f4 100644 --- a/types/prosemirror-transform/index.d.ts +++ b/types/prosemirror-transform/index.d.ts @@ -3,14 +3,21 @@ // Definitions by: Bradley Ayers // David Hahn // Tim Baumann +// Patrick Simmelbauer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 +// TypeScript Version: 2.3 -// IMPORTANT -// This file was generated by https://github.com/bradleyayers/getdocs2ts. Please do not edit manually. -// When you find an error in these declarations, fix the getdocs comment upstream or 'getdocs2ts', then regenerate. - -import { ContentMatch, Fragment, Mark, MarkType, Node as ProsemirrorNode, NodeRange, NodeType, Schema, Slice } from 'prosemirror-model'; +import { + ContentMatch, + Fragment, + Mark, + MarkType, + Node as ProsemirrorNode, + NodeRange, + NodeType, + Schema, + Slice +} from 'prosemirror-model'; /** * There are several things that positions can be mapped through. @@ -160,14 +167,14 @@ export class Mapping implements Mappable { /** * Add a mark to all inline content between two positions. */ -export class AddMarkStep extends Step { - constructor(from: number, to: number, mark: Mark); +export class AddMarkStep extends Step { + constructor(from: number, to: number, mark: Mark); } /** * Remove a mark from all inline content between two positions. */ -export class RemoveMarkStep extends Step { - constructor(from: number, to: number, mark: Mark); +export class RemoveMarkStep extends Step { + constructor(from: number, to: number, mark: Mark); } /** * Abstraction to build up and track an array of @@ -176,39 +183,43 @@ export class RemoveMarkStep extends Step { * Most transforming methods return the `Transform` object itself, so * that they can be chained. */ -export class Transform { +export class Transform { /** * Create a transform that starts with the given document. */ - constructor(doc: ProsemirrorNode); + constructor(doc: ProsemirrorNode); /** * Add the given mark to the inline content between `from` and `to`. */ - addMark(from: number, to: number, mark: Mark): this; + addMark(from: number, to: number, mark: Mark): this; /** * Remove marks from inline nodes between `from` and `to`. When `mark` * is a single mark, remove precisely that mark. When it is a mark type, * remove all marks of that type. When it is null, remove all marks of * any type. */ - removeMark(from: number, to: number, mark?: Mark | MarkType): this; + removeMark(from: number, to: number, mark?: Mark | MarkType): this; /** * Removes all marks and nodes from the content of the node at `pos` * that don't match the given new parent node type. Accepts an * optional starting [content match](#model.ContentMatch) as third * argument. */ - clearIncompatible(pos: number, parentType: NodeType, match?: ContentMatch): this; + clearIncompatible(pos: number, parentType: NodeType, match?: ContentMatch): this; /** * Replace the part of the document between `from` and `to` with the * given `slice`. */ - replace(from: number, to?: number, slice?: Slice): this; + replace(from: number, to?: number, slice?: Slice): this; /** * Replace the given range with the given content, which may be a * fragment, node, or array of nodes. */ - replaceWith(from: number, to: number, content: Fragment | ProsemirrorNode | ProsemirrorNode[]): this; + replaceWith( + from: number, + to: number, + content: Fragment | ProsemirrorNode | Array> + ): this; /** * Delete the content between the given positions. */ @@ -216,7 +227,10 @@ export class Transform { /** * Insert the given content at the given position. */ - insert(pos: number, content: Fragment | ProsemirrorNode | ProsemirrorNode[]): this; + insert( + pos: number, + content: Fragment | ProsemirrorNode | Array> + ): this; /** * Replace a range of the document with a given slice, using `from`, * `to`, and the slice's [`openStart`](#model.Slice.openStart) property @@ -234,7 +248,7 @@ export class Transform { * range, and is useful in situations where you need more precise * control over what happens. */ - replaceRange(from: number, to: number, slice: Slice): this; + replaceRange(from: number, to: number, slice: Slice): this; /** * Replace the given range with a node, but use `from` and `to` as * hints, rather than precise positions. When from and to are the same @@ -244,7 +258,7 @@ export class Transform { * completely covers a parent node, this method may completely replace * that parent node. */ - replaceRangeWith(from: number, to: number, node: ProsemirrorNode): this; + replaceRangeWith(from: number, to: number, node: ProsemirrorNode): this; /** * Delete the given range, expanding it to cover fully covered * parent nodes until a valid replace is found. @@ -257,23 +271,36 @@ export class Transform { * [`liftTarget`](#transform.liftTarget) to compute `target`, to make * sure the lift is valid. */ - lift(range: NodeRange, target: number): this; + lift(range: NodeRange, target: number): this; /** * Wrap the given [range](#model.NodeRange) in the given set of wrappers. * The wrappers are assumed to be valid in this position, and should * probably be computed with [`findWrapping`](#transform.findWrapping). */ - wrap(range: NodeRange, wrappers: Array<{ type: NodeType, attrs?: { [key: string]: any } | null }>): this; + wrap( + range: NodeRange, + wrappers: Array<{ type: NodeType; attrs?: { [key: string]: any } | null }> + ): this; /** * Set the type of all textblocks (partly) between `from` and `to` to * the given node type with the given attributes. */ - setBlockType(from: number, to: number | undefined, type: NodeType, attrs?: { [key: string]: any }): this; + setBlockType( + from: number, + to: number | undefined, + type: NodeType, + attrs?: { [key: string]: any } + ): this; /** * Change the type, attributes, and/or marks of the node at `pos`. * When `nodeType` is null, the existing node type is preserved, */ - setNodeMarkup(pos: number, type?: NodeType, attrs?: { [key: string]: any }, marks?: Mark[]): this; + setNodeMarkup( + pos: number, + type?: NodeType, + attrs?: { [key: string]: any }, + marks?: Array> + ): this; /** * Split the node at the given position, and optionally, if `depth` is * greater than one, any number of nodes above that. By default, the @@ -281,7 +308,11 @@ export class Transform { * This can be changed by passing an array of types and attributes to * use after the split. */ - split(pos: number, depth?: number, typesAfter?: Array<{ type: NodeType, attrs?: { [key: string]: any } | null }>): this; + split( + pos: number, + depth?: number, + typesAfter?: Array<{ type: NodeType; attrs?: { [key: string]: any } | null }> + ): this; /** * Join the blocks around the given position. If depth is 2, their * last and first siblings are also joined, and so on. @@ -291,15 +322,15 @@ export class Transform { * The current document (the result of applying the steps in the * transform). */ - doc: ProsemirrorNode; + doc: ProsemirrorNode; /** * The steps in this transform. */ - steps: Step[]; + steps: Array>; /** * The documents before each of the steps. */ - docs: ProsemirrorNode[]; + docs: Array>; /** * A mapping with the maps for each of the steps in this transform. */ @@ -307,17 +338,17 @@ export class Transform { /** * The starting document. */ - before: ProsemirrorNode; + before: ProsemirrorNode; /** * Apply a new step in this transform, saving the result. Throws an * error when the step fails. */ - step(step: Step): this; + step(step: Step): this; /** * Try to apply a step in this transformation, ignoring it if it * fails. Returns the step result. */ - maybeStep(step: Step): StepResult; + maybeStep(step: Step): StepResult; /** * True when the document has been changed (when there are any * steps). @@ -327,7 +358,7 @@ export class Transform { /** * Replace a part of the document with a slice of new content. */ -export class ReplaceStep extends Step { +export class ReplaceStep extends Step { /** * The given `slice` should fit the 'gap' between `from` and * `to`—the depths must line up, and the surrounding nodes must be @@ -337,21 +368,29 @@ export class ReplaceStep extends Step { * tokens (this is to guard against rebased replace steps * overwriting something they weren't supposed to). */ - constructor(from: number, to: number, slice: Slice, structure?: boolean); + constructor(from: number, to: number, slice: Slice, structure?: boolean); } /** * Replace a part of the document with a slice of content, but * preserve a range of the replaced content by moving it into the * slice. */ -export class ReplaceAroundStep extends Step { +export class ReplaceAroundStep extends Step { /** * Create a replace-around step with the given range and gap. * `insert` should be the point in the slice into which the content * of the gap should be moved. `structure` has the same meaning as * it has in the [`ReplaceStep`](#transform.ReplaceStep) class. */ - constructor(from: number, to: number, gapFrom: number, gapTo: number, slice: Slice, insert: number, structure?: boolean); + constructor( + from: number, + to: number, + gapFrom: number, + gapTo: number, + slice: Slice, + insert: number, + structure?: boolean + ); } /** * ‘Fit’ a slice into a given position in the document, producing a @@ -359,7 +398,12 @@ export class ReplaceAroundStep extends Step { * there's no meaningful way to insert the slice here, or inserting it * would be a no-op (an empty slice over an empty range). */ -export function replaceStep(doc: ProsemirrorNode, from: number, to?: number, slice?: Slice): Step | null | void; +export function replaceStep( + doc: ProsemirrorNode, + from: number, + to?: number, + slice?: Slice +): Step | null | void; /** * A step object represents an atomic change. It generally applies * only to the document it was created for, since the positions @@ -371,14 +415,14 @@ export function replaceStep(doc: ProsemirrorNode, from: number, to?: number, sli * JSON-serialization identifier using * [`Step.jsonID`](#transform.Step^jsonID). */ -export class Step { +export class Step { /** * Applies this step to the given document, returning a result * object that either indicates failure, if the step can not be * applied to this document, or indicates success by containing a * transformed document. */ - apply(doc: ProsemirrorNode): StepResult; + apply(doc: ProsemirrorNode): StepResult; /** * Get the step map that represents the changes made by this step, * and which can be used to transform between positions in the old @@ -389,19 +433,19 @@ export class Step { * Create an inverted version of this step. Needs the document as it * was before the step as argument. */ - invert(doc: ProsemirrorNode): Step; + invert(doc: ProsemirrorNode): Step; /** * Map this step through a mappable thing, returning either a * version of that step with its positions adjusted, or `null` if * the step was entirely deleted by the mapping. */ - map(mapping: Mappable): Step | null | void; + map(mapping: Mappable): Step | null | void; /** * Try to merge this step with another one, to be applied directly * after it. Returns the merged step when possible, null if the * steps can't be merged. */ - merge(other: Step): Step | null | void; + merge(other: Step): Step | null | void; /** * Create a JSON-serializeable representation of this step. When * defining this for a custom subclass, make sure the result object @@ -413,7 +457,7 @@ export class Step { * Deserialize a step from its JSON representation. Will call * through to the step class' own implementation of this method. */ - static fromJSON(schema: Schema, json: { [key: string]: any }): Step; + static fromJSON(schema: S, json: { [key: string]: any }): Step; /** * To be able to serialize steps to JSON, each step needs a string * ID to attach to its JSON representation. Use this method to @@ -426,11 +470,11 @@ export class Step { * The result of [applying](#transform.Step.apply) a step. Contains either a * new document or a failure value. */ -export class StepResult { +export class StepResult { /** * The transformed document. */ - doc?: ProsemirrorNode | null; + doc?: ProsemirrorNode | null; /** * Text providing information about a failed step. */ @@ -438,7 +482,7 @@ export class StepResult { /** * Create a successful step result. */ - static ok(doc: ProsemirrorNode): StepResult; + static ok(doc: ProsemirrorNode): StepResult; /** * Create a failed step result. */ @@ -448,7 +492,12 @@ export class StepResult { * arguments. Create a successful result if it succeeds, and a * failed one if it throws a `ReplaceError`. */ - static fromReplace(doc: ProsemirrorNode, from: number, to: number, slice: Slice): StepResult; + static fromReplace( + doc: ProsemirrorNode, + from: number, + to: number, + slice: Slice + ): StepResult; } /** * Try to find a target depth to which the content in the given range @@ -462,11 +511,20 @@ export function liftTarget(range: NodeRange): number | null | void; * the wrapper node, if necessary. Returns null if no valid wrapping * could be found. */ -export function findWrapping(range: NodeRange, nodeType: NodeType, attrs?: { [key: string]: any }): Array<{ type: NodeType, attrs?: { [key: string]: any } | null }> | null | void; +export function findWrapping( + range: NodeRange, + nodeType: NodeType, + attrs?: { [key: string]: any } +): Array<{ type: NodeType; attrs?: { [key: string]: any } | null }> | null | void; /** * Check whether splitting at the given position is allowed. */ -export function canSplit(doc: ProsemirrorNode, pos: number, depth?: number, typesAfter?: Array<{ type: NodeType, attrs?: { [key: string]: any } | null }>): boolean; +export function canSplit( + doc: ProsemirrorNode, + pos: number, + depth?: number, + typesAfter?: Array<{ type: NodeType; attrs?: { [key: string]: any } | null }> +): boolean; /** * Test whether the blocks before and after a given position can be * joined. @@ -484,4 +542,8 @@ export function joinPoint(doc: ProsemirrorNode, pos: number, dir?: number): numb * isn't a valid place but is at the start or end of a node. Return * null if no position was found. */ -export function insertPoint(doc: ProsemirrorNode, pos: number, nodeType: NodeType): number | null | void; +export function insertPoint( + doc: ProsemirrorNode, + pos: number, + nodeType: NodeType +): number | null | void; diff --git a/types/prosemirror-transform/tsconfig.json b/types/prosemirror-transform/tsconfig.json index c5799c88a6..31a3452e16 100644 --- a/types/prosemirror-transform/tsconfig.json +++ b/types/prosemirror-transform/tsconfig.json @@ -1,24 +1,16 @@ { "compilerOptions": { "module": "commonjs", - "lib": [ - "es6", - "dom" - ], + "lib": ["es6", "dom"], "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", - "typeRoots": [ - "../" - ], + "typeRoots": ["../"], "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true }, - "files": [ - "index.d.ts", - "prosemirror-transform-tests.ts" - ] -} \ No newline at end of file + "files": ["index.d.ts", "prosemirror-transform-tests.ts"] +} diff --git a/types/prosemirror-view/index.d.ts b/types/prosemirror-view/index.d.ts index 0ce2e37794..f24a5270d1 100644 --- a/types/prosemirror-view/index.d.ts +++ b/types/prosemirror-view/index.d.ts @@ -1,16 +1,21 @@ -// Type definitions for prosemirror-view 1.0 +// Type definitions for prosemirror-view 1.2 // Project: https://github.com/ProseMirror/prosemirror-view // Definitions by: Bradley Ayers // David Hahn // Tim Baumann +// Patrick Simmelbauer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 +// TypeScript Version: 2.3 -// IMPORTANT -// This file was generated by https://github.com/bradleyayers/getdocs2ts. Please do not edit manually. -// When you find an error in these declarations, fix the getdocs comment upstream or 'getdocs2ts', then regenerate. - -import { DOMParser, DOMSerializer, Node as ProsemirrorNode, ResolvedPos, Slice } from 'prosemirror-model'; +import { + DOMParser, + DOMSerializer, + Node as ProsemirrorNode, + ResolvedPos, + Slice, + Schema, + Mark +} from 'prosemirror-model'; import { EditorState, Selection, Transaction } from 'prosemirror-state'; import { Mapping } from 'prosemirror-transform'; @@ -38,18 +43,37 @@ export class Decoration { * Creates a widget decoration, which is a DOM node that's shown in * the document at the given position. */ - static widget(pos: number, dom: Node, spec?: { side?: number | null, stopEvent?: ((event: Event) => boolean) | null, key?: string | null }): Decoration; + static widget( + pos: number, + dom: Node, + spec?: { + side?: number | null; + marks?: Mark[]; + stopEvent?: ((event: Event) => boolean) | null; + key?: string | null; + } + ): Decoration; /** * Creates an inline decoration, which adds the given attributes to * each inline node between `from` and `to`. */ - static inline(from: number, to: number, attrs: DecorationAttrs, spec?: { inclusiveStart?: boolean | null, inclusiveEnd?: boolean | null }): Decoration; + static inline( + from: number, + to: number, + attrs: DecorationAttrs, + spec?: { inclusiveStart?: boolean | null; inclusiveEnd?: boolean | null } + ): Decoration; /** * Creates a node decoration. `from` and `to` should point precisely * before and after a node in the document. That node, and only that * node, will receive the given attributes. */ - static node(from: number, to: number, attrs: DecorationAttrs, spec?: { [key: string]: any }): Decoration; + static node( + from: number, + to: number, + attrs: DecorationAttrs, + spec?: { [key: string]: any } + ): Decoration; } /** * A set of attributes to add to a decorated node. Most properties @@ -78,7 +102,7 @@ export interface DecorationAttrs { * compare them. This is a persistent data structure—it is not * modified, updates create a new value. */ -export class DecorationSet { +export class DecorationSet { /** * Find all decorations in this set which touch the given range * (including decorations that start or end directly at the @@ -87,28 +111,39 @@ export class DecorationSet { * considered. When `predicate` isn't given, all decorations are * asssumed to match. */ - find(start?: number, end?: number, predicate?: (spec: { [key: string]: any }) => boolean): Decoration[]; + find( + start?: number, + end?: number, + predicate?: (spec: { [key: string]: any }) => boolean + ): Decoration[]; /** * Map the set of decorations in response to a change in the * document. */ - map(mapping: Mapping, doc: ProsemirrorNode, options?: { onRemove?: ((decorationSpec: { [key: string]: any }) => void) | null }): DecorationSet; + map( + mapping: Mapping, + doc: ProsemirrorNode, + options?: { onRemove?: ((decorationSpec: { [key: string]: any }) => void) | null } + ): DecorationSet; /** * Add the given array of decorations to the ones in the set, * producing a new set. Needs access to the current document to * create the appropriate tree structure. */ - add(doc: ProsemirrorNode, decorations: Decoration[]): DecorationSet; + add(doc: ProsemirrorNode, decorations: Decoration[]): DecorationSet; /** * Create a new set that contains the decorations in this set, minus * the ones in the given array. */ - remove(decorations: Decoration[]): DecorationSet; + remove(decorations: Decoration[]): DecorationSet; /** * Create a set of decorations, using the structure of the given * document. */ - static create(doc: ProsemirrorNode, decorations: Decoration[]): DecorationSet; + static create( + doc: ProsemirrorNode, + decorations: Decoration[] + ): DecorationSet; /** * The empty set of decorations. */ @@ -119,7 +154,7 @@ export class DecorationSet { * editable document. Its state and behavior are determined by its * [props](#view.DirectEditorProps). */ -export class EditorView { +export class EditorView { /** * Create a view. `place` may be a DOM node that the editor should * be appended to, a function that will place it into the document, @@ -127,11 +162,14 @@ export class EditorView { * document container. If it is `null`, the editor will not be added * to the document. */ - constructor(place: Node | ((p: Node) => void) | { mount: Node } | undefined, props: DirectEditorProps); + constructor( + place: Node | ((p: Node) => void) | { mount: Node } | undefined, + props: DirectEditorProps + ); /** * The view's current [state](#state.EditorState). */ - state: EditorState; + state: EditorState; /** * An editable DOM node containing the document. (You probably * should not directly interfere with its content.) @@ -142,27 +180,27 @@ export class EditorView { * information about the dragged slice and whether it is being * copied or moved. At any other time, it is null. */ - dragging?: { slice: Slice, move: boolean } | null; + dragging?: { slice: Slice; move: boolean } | null; /** * The view's current [props](#view.EditorProps). */ - props: DirectEditorProps; + props: DirectEditorProps; /** * Update the view's props. Will immediately cause an update to * the DOM. */ - update(props: DirectEditorProps): void; + update(props: DirectEditorProps): void; /** * Update the view by updating existing props object with the object * given as argument. Equivalent to `view.update(Object.assign({}, * view.props, props))`. */ - setProps(props: DirectEditorProps): void; + setProps(props: DirectEditorProps): void; /** * Update the editor's `state` prop, without touching any of the * other props. */ - updateState(state: EditorState): void; + updateState(state: EditorState): void; /** * Goes over the values of a prop, first those provided directly, * then those from plugins (in order), and calls `f` every time a @@ -196,20 +234,23 @@ export class EditorView { * inner node that the position falls inside of, or -1 if it is at * the top level, not in any node. */ - posAtCoords(coords: { left: number, top: number }): { pos: number, inside: number } | null | void; + posAtCoords(coords: { + left: number; + top: number; + }): { pos: number; inside: number } | null | void; /** * Returns the viewport rectangle at a given document position. `left` * and `right` will be the same number, as this returns a flat * cursor-ish rectangle. */ - coordsAtPos(pos: number): { left: number, right: number, top: number, bottom: number }; + coordsAtPos(pos: number): { left: number; right: number; top: number; bottom: number }; /** * Find the DOM position that corresponds to the given document * position. Note that you should **not** mutate the editor's * internal DOM, only inspect it (and even that is usually not * necessary). */ - domAtPos(pos: number): { node: Node, offset: number }; + domAtPos(pos: number): { node: Node; offset: number }; /** * Find out whether the selection is at the end of a textblock when * moving in a given direction. When, for example, given `"left"`, @@ -218,7 +259,10 @@ export class EditorView { * to the view's current state by default, but it is possible to * pass a different state. */ - endOfTextblock(dir: "up" | "down" | "left" | "right" | "forward" | "backward", state?: EditorState): boolean; + endOfTextblock( + dir: 'up' | 'down' | 'left' | 'right' | 'forward' | 'backward', + state?: EditorState + ): boolean; /** * Removes the editor from the DOM and destroys all [node * views](#view.NodeView). @@ -233,7 +277,7 @@ export class EditorView { * This method is bound to the view instance, so that it can be * easily passed around. */ - dispatch(tr: Transaction): void; + dispatch(tr: Transaction): void; } /** * Props are configuration values that can be passed to an editor view @@ -250,7 +294,7 @@ export class EditorView { * them returns true. For some props, the first plugin that yields a * value gets precedence. */ -export interface EditorProps { +export interface EditorProps { /** * Can be an object mapping DOM event type names to functions that * handle them. Such functions will be called before any handling @@ -260,78 +304,115 @@ export interface EditorProps { * `preventDefault` yourself (or not, if you want to allow the * default behavior). */ - handleDOMEvents?: { [name: string]: (view: EditorView, event: Event) => boolean } | null; + handleDOMEvents?: { [name: string]: (view: EditorView, event: Event) => boolean } | null; /** * Called when the editor receives a `keydown` event. */ - handleKeyDown?: ((view: EditorView, event: KeyboardEvent) => boolean) | null; + handleKeyDown?: ((view: EditorView, event: KeyboardEvent) => boolean) | null; /** * Handler for `keypress` events. */ - handleKeyPress?: ((view: EditorView, event: KeyboardEvent) => boolean) | null; + handleKeyPress?: ((view: EditorView, event: KeyboardEvent) => boolean) | null; /** * Whenever the user directly input text, this handler is called * before the input is applied. If it returns `true`, the default * behavior of actually inserting the text is suppressed. */ - handleTextInput?: ((view: EditorView, from: number, to: number, text: string) => boolean) | null; + handleTextInput?: + | ((view: EditorView, from: number, to: number, text: string) => boolean) + | null; /** * Called for each node around a click, from the inside out. The * `direct` flag will be true for the inner node. */ - handleClickOn?: ((view: EditorView, pos: number, node: ProsemirrorNode, nodePos: number, event: MouseEvent, direct: boolean) => boolean) | null; + handleClickOn?: + | (( + view: EditorView, + pos: number, + node: ProsemirrorNode, + nodePos: number, + event: MouseEvent, + direct: boolean + ) => boolean) + | null; /** * Called when the editor is clicked, after `handleClickOn` handlers * have been called. */ - handleClick?: ((view: EditorView, pos: number, event: MouseEvent) => boolean) | null; + handleClick?: ((view: EditorView, pos: number, event: MouseEvent) => boolean) | null; /** * Called for each node around a double click. */ - handleDoubleClickOn?: ((view: EditorView, pos: number, node: ProsemirrorNode, nodePos: number, event: MouseEvent, direct: boolean) => boolean) | null; + handleDoubleClickOn?: + | (( + view: EditorView, + pos: number, + node: ProsemirrorNode, + nodePos: number, + event: MouseEvent, + direct: boolean + ) => boolean) + | null; /** * Called when the editor is double-clicked, after `handleDoubleClickOn`. */ - handleDoubleClick?: ((view: EditorView, pos: number, event: MouseEvent) => boolean) | null; + handleDoubleClick?: ((view: EditorView, pos: number, event: MouseEvent) => boolean) | null; /** * Called for each node around a triple click. */ - handleTripleClickOn?: ((view: EditorView, pos: number, node: ProsemirrorNode, nodePos: number, event: MouseEvent, direct: boolean) => boolean) | null; + handleTripleClickOn?: + | (( + view: EditorView, + pos: number, + node: ProsemirrorNode, + nodePos: number, + event: MouseEvent, + direct: boolean + ) => boolean) + | null; /** * Called when the editor is triple-clicked, after `handleTripleClickOn`. */ - handleTripleClick?: ((view: EditorView, pos: number, event: MouseEvent) => boolean) | null; + handleTripleClick?: ((view: EditorView, pos: number, event: MouseEvent) => boolean) | null; /** * Can be used to override the behavior of pasting. `slice` is the * pasted content parsed by the editor, but you can directly access * the event to get at the raw content. */ - handlePaste?: ((view: EditorView, event: Event, slice: Slice) => boolean) | null; + handlePaste?: ((view: EditorView, event: Event, slice: Slice) => boolean) | null; /** * Called when something is dropped on the editor. `moved` will be * true if this drop moves from the current selection (which should * thus be deleted). */ - handleDrop?: ((view: EditorView, event: Event, slice: Slice, moved: boolean) => boolean) | null; + handleDrop?: + | ((view: EditorView, event: Event, slice: Slice, moved: boolean) => boolean) + | null; /** * Called when the view, after updating its state, tries to scroll * the selection into view. A handler function may return false to * indicate that it did not handle the scrolling and further * handlers or the default behavior should be tried. */ - handleScrollToSelection?: ((view: EditorView) => boolean) | null; + handleScrollToSelection?: ((view: EditorView) => boolean) | null; /** * Can be used to override the way a selection is created when * reading a DOM selection between the given anchor and head. */ - createSelectionBetween?: ((view: EditorView, anchor: ResolvedPos, head: ResolvedPos) => Selection | null | void) | null; + createSelectionBetween?: + | (( + view: EditorView, + anchor: ResolvedPos, + head: ResolvedPos + ) => Selection | null | void) + | null; /** * The [parser](#model.DOMParser) to use when reading editor changes * from the DOM. Defaults to calling * [`DOMParser.fromSchema`](#model.DOMParser^fromSchema) on the * editor's schema. */ - domParser?: DOMParser | null; + domParser?: DOMParser | null; /** * Can be used to transform pasted HTML text, _before_ it is parsed, * for example to clean it up. @@ -342,7 +423,7 @@ export interface EditorProps { * the clipboard. When not given, the value of the * [`domParser`](#view.EditorProps.domParser) prop is used. */ - clipboardParser?: DOMParser | null; + clipboardParser?: DOMParser | null; /** * Transform pasted plain text. */ @@ -355,12 +436,12 @@ export interface EditorProps { * in `

` tags, and call * [`clipboardParser`](#view.EditorProps.clipboardParser) on it. */ - clipboardTextParser?: ((text: string, $context: ResolvedPos) => Slice) | null; + clipboardTextParser?: ((text: string, $context: ResolvedPos) => Slice) | null; /** * Can be used to transform pasted content before it is applied to * the document. */ - transformPasted?: ((p: Slice) => Slice) | null; + transformPasted?: ((p: Slice) => Slice) | null; /** * Allows you to pass custom rendering and behavior logic for nodes * and marks. Should map node and mark names to constructor @@ -375,31 +456,38 @@ export interface EditorProps { * they can also be used as a way to provide context information to * the node view without adding it to the document itself. */ - nodeViews?: { [name: string]: (node: ProsemirrorNode, view: EditorView, getPos: () => number, decorations: Decoration[]) => NodeView } | null; + nodeViews?: { + [name: string]: ( + node: ProsemirrorNode, + view: EditorView, + getPos: () => number, + decorations: Decoration[] + ) => NodeView; + } | null; /** * The DOM serializer to use when putting content onto the * clipboard. If not given, the result of * [`DOMSerializer.fromSchema`](#model.DOMSerializer^fromSchema) * will be used. */ - clipboardSerializer?: DOMSerializer | null; + clipboardSerializer?: DOMSerializer | null; /** * A function that will be called to get the text for the current * selection when copying text to the clipboard. By default, the * editor will use [`textBetween`](#model.Node.textBetween) on the * selected range. */ - clipboardTextSerializer?: ((p: Slice) => string) | null; + clipboardTextSerializer?: ((p: Slice) => string) | null; /** * A set of [document decorations](#view.Decoration) to show in the * view. */ - decorations?: ((state: EditorState) => DecorationSet | null | void) | null; + decorations?: ((state: EditorState) => DecorationSet | null | void) | null; /** * When this returns false, the content of the view is not directly * editable. */ - editable?: ((state: EditorState) => boolean) | null; + editable?: ((state: EditorState) => boolean) | null; /** * Control the DOM attributes of the editable element. May be either * an object or a function going from an editor state to an object. @@ -410,7 +498,10 @@ export interface EditorProps { * the value provided first (as in * [`someProp`](#view.EditorView.someProp)) will be used. */ - attributes?: { [name: string]: string } | ((p: EditorState) => { [name: string]: string } | null | void) | null; + attributes?: + | { [name: string]: string } + | ((p: EditorState) => { [name: string]: string } | null | void) + | null; /** * Determines the distance (in pixels) between the cursor and the * end of the visible viewport at which point, when scrolling the @@ -427,11 +518,11 @@ export interface EditorProps { * The props object given directly to the editor view supports two * fields that can't be used in plugins: */ -export interface DirectEditorProps extends EditorProps { +export interface DirectEditorProps extends EditorProps { /** * The current state of the editor. */ - state: EditorState; + state: EditorState; /** * The callback over which to send transactions (state updates) * produced by the view. If you specify this, you probably want to @@ -440,7 +531,7 @@ export interface DirectEditorProps extends EditorProps { * state that has the transaction * [applied](#state.EditorState.apply). */ - dispatchTransaction?: ((tr: Transaction) => void) | null; + dispatchTransaction?: ((tr: Transaction) => void) | null; } /** * By default, document nodes are rendered using the result of the @@ -452,7 +543,7 @@ export interface DirectEditorProps extends EditorProps { * * Objects returned as node views must conform to this interface. */ -export interface NodeView { +export interface NodeView { /** * The outer DOM node that represents the document node. When not * given, the default strategy is used to create a DOM node. @@ -477,7 +568,7 @@ export interface NodeView { * no `dom` property), updating its child nodes will be handled by * ProseMirror. */ - update?: ((node: ProsemirrorNode, decorations: Decoration[]) => boolean) | null; + update?: ((node: ProsemirrorNode, decorations: Decoration[]) => boolean) | null; /** * Can be used to override the way the node's selected status (as a * node selection) is displayed. diff --git a/types/ramda/index.d.ts b/types/ramda/index.d.ts index 70200aae41..69acb41dc6 100644 --- a/types/ramda/index.d.ts +++ b/types/ramda/index.d.ts @@ -17,6 +17,7 @@ // Ethan Resnick // Jack Leigh // Keagan McClelland +// Tomas Szabo // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.6 @@ -1027,6 +1028,13 @@ declare namespace R { */ memoize(fn: (...a: any[]) => T): (...a: any[]) => T; + /** + * A customisable version of R.memoize. memoizeWith takes an additional function that will be applied to a given + * argument set and used to create the cache key under which the results of the function to be memoized will be stored. + * Care must be taken when implementing key generation to avoid clashes that may overwrite previous entries erroneously. + */ + memoizeWith any>(keyFn: (...v: any[]) => string, fn: T): T; + /** * Create a new object with the own properties of a * merged with the own properties of object b. diff --git a/types/ramda/ramda-tests.ts b/types/ramda/ramda-tests.ts index dbb697e658..81eb438535 100644 --- a/types/ramda/ramda-tests.ts +++ b/types/ramda/ramda-tests.ts @@ -309,6 +309,36 @@ R.times(i, 5); const isLong = memoStringLength('short') > 10; // false })(); +(() => { + interface Vector { + x: number; + y: number; + } + + let numberOfCalls = 0; + + function vectorSum(a: Vector, b: Vector): Vector { + numberOfCalls += 1; + return { + x: a.x + b.x, + y: a.y + b.y + }; + } + + const memoVectorSum = R.memoizeWith(JSON.stringify, vectorSum); + + memoVectorSum({ x: 1, y: 1 }, { x: 2, y: 2 }); // => { x: 3, y: 3 } + numberOfCalls; // => 1 + memoVectorSum({ x: 1, y: 1 }, { x: 2, y: 2 }); // => { x: 3, y: 3 } + numberOfCalls; // => 1 + memoVectorSum({ x: 1, y: 2 }, { x: 2, y: 3 }); // => { x: 3, y: 5 } + numberOfCalls; // => 2 + + // Note that argument order matters + memoVectorSum({ x: 2, y: 3 }, { x: 1, y: 2 }); // => { x: 3, y: 5 } + numberOfCalls; // => 3 +})(); + (() => { const addOneOnce = R.once((x: number) => x + 1); addOneOnce(10); // => 11 diff --git a/types/raven/index.d.ts b/types/raven/index.d.ts index 5d478a496b..81a36ee8f1 100644 --- a/types/raven/index.d.ts +++ b/types/raven/index.d.ts @@ -158,4 +158,6 @@ export namespace transports { } class HTTPSTransport extends HTTPTransport { } + const https: HTTPSTransport; + const http: HTTPTransport; } diff --git a/types/raven/raven-tests.ts b/types/raven/raven-tests.ts index 6191f8f89d..fc89d88589 100644 --- a/types/raven/raven-tests.ts +++ b/types/raven/raven-tests.ts @@ -16,6 +16,11 @@ Raven.config({ release: 'foobar', transport }); + +Raven.config({ + transport: Raven.transports.https +}); + client.setContext({}); client.on('logged', () => { }); client.process({}); diff --git a/types/react-is/index.d.ts b/types/react-is/index.d.ts new file mode 100644 index 0000000000..f088b1bcc9 --- /dev/null +++ b/types/react-is/index.d.ts @@ -0,0 +1,26 @@ +// Type definitions for react-is 16.3 +// Project: https://reactjs.org/ +// Definitions by: Avi Vahl +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.6 + +export as namespace ReactIs; + +import { ReactElement, ReactType } from 'react'; + +export function typeOf(value: any): symbol | undefined; +export function isValidElementType(value: any): value is ReactType; + +export function isContextConsumer(value: any): value is ReactElement; +export function isContextProvider(value: any): value is ReactElement; +export function isElement(value: any): value is ReactElement; +export function isFragment(value: any): value is ReactElement; +export function isPortal(value: any): value is ReactElement; +export function isStrictMode(value: any): value is ReactElement; + +export const ContextProvider: symbol; +export const ContextConsumer: symbol; +export const Element: symbol; +export const Fragment: symbol; +export const Portal: symbol; +export const StrictMode: symbol; diff --git a/types/react-is/react-is-tests.tsx b/types/react-is/react-is-tests.tsx new file mode 100644 index 0000000000..a03ad7b534 --- /dev/null +++ b/types/react-is/react-is-tests.tsx @@ -0,0 +1,74 @@ +import * as React from 'react'; +import * as ReactDOM from 'react-dom'; +import * as ReactIs from 'react-is'; + +// Below is taken from README of react-is +// Determining if a Component is Valid + +interface CompProps { + forwardedRef?: React.Ref; + children?: React.ReactNode; +} + +class ClassComponent extends React.Component { + render() { + return React.createElement('div'); + } +} + +const StatelessComponent = () => React.createElement('div'); + +const ForwardRefComponent = React.forwardRef((props, ref) => + React.createElement(ClassComponent, { forwardedRef: ref, ...props }) +); + +const Context = React.createContext(false); + +ReactIs.isValidElementType('div'); // true +ReactIs.isValidElementType(ClassComponent); // true +ReactIs.isValidElementType(StatelessComponent); // true +ReactIs.isValidElementType(ForwardRefComponent); // true +ReactIs.isValidElementType(Context.Provider); // true +ReactIs.isValidElementType(Context.Consumer); // true +ReactIs.isValidElementType(React.createFactory('div')); // true + +// Determining an Element's Type + +// AsyncMode - unstable_AsyncMode is not implemented in @types/react yet +// ReactIs.isAsyncMode(); // true +// ReactIs.typeOf() === ReactIs.AsyncMode; // true + +// Context +const ThemeContext = React.createContext('blue'); + +ReactIs.isContextConsumer(); // true +ReactIs.isContextProvider(); // true +ReactIs.typeOf() === ReactIs.ContextConsumer; // true +ReactIs.typeOf() === ReactIs.ContextProvider; // true + +// Element +ReactIs.isElement(

); // true +ReactIs.typeOf(
) === ReactIs.Element; // true + +// Fragment +ReactIs.isFragment(<>); // true +ReactIs.typeOf(<>) === ReactIs.Fragment; // true + +// Portal +const div = document.createElement('div'); +const portal = ReactDOM.createPortal(
, div); + +ReactIs.isPortal(portal); // true +ReactIs.typeOf(portal) === ReactIs.Portal; // true + +// StrictMode +ReactIs.isStrictMode(); // true +ReactIs.typeOf() === ReactIs.StrictMode; // true + +// Verify typeOf accepts any type of value (taken from tests of react-is) +ReactIs.typeOf('abc') === undefined; +ReactIs.typeOf(true) === undefined; +ReactIs.typeOf(123) === undefined; +ReactIs.typeOf({}) === undefined; +ReactIs.typeOf(null) === undefined; +ReactIs.typeOf(undefined) === undefined; diff --git a/types/react-is/tsconfig.json b/types/react-is/tsconfig.json new file mode 100644 index 0000000000..9ef6f3da96 --- /dev/null +++ b/types/react-is/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "strictFunctionTypes": false, + "jsx": "preserve" + }, + "files": [ + "index.d.ts", + "react-is-tests.tsx" + ] +} diff --git a/types/react-is/tslint.json b/types/react-is/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-is/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/react-owl-carousel/index.d.ts b/types/react-owl-carousel/index.d.ts new file mode 100644 index 0000000000..bcd9af38b5 --- /dev/null +++ b/types/react-owl-carousel/index.d.ts @@ -0,0 +1,414 @@ +// Type definitions for react-owl-carousel 2.2 +// Project: https://github.com/seal789ie/react-owl-carousel +// Definitions by: T Bounsiar , Ismael Gorissen , Kenneth Ceyer +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.6 + +import * as React from "react"; + +export type HandlerCallback = (...args: any[]) => void; + +export interface Options { + // OPTIONS + /** + * Default: + * Adding a -striped className to OwlCarousel. + */ + className?: string; + /** + * Default: 3 + * The number of items you want to see on the screen. + */ + items?: number; + /** + * Default: 0 + * margin-right(px) on item. + */ + margin?: number; + /** + * Default: false + * Infinity loop. Duplicate last and first items to get loop illusion. + */ + loop?: boolean; + /** + * Default: false + * Center item. Works well with even an odd number of items. + */ + center?: boolean; + /** + * Default: true + * Mouse drag enabled. + */ + mouseDrag?: boolean; + /** + * Default: true + * Touch drag enabled. + */ + touchDrag?: boolean; + /** + * Default: true + * Stage pull to edge. + */ + pullDrag?: boolean; + /** + * Default: false + * Item pull to edge. + */ + freeDrag?: boolean; + /** + * Default: 0 + * Padding left and right on stage (can see neighbours). + */ + stagePadding?: number; + /** + * Default: false + * Merge items. Looking for data-merge='{number}' inside item. + */ + merge?: boolean; + /** + * Default: true + * Fit merged items if screen is smaller than items value. + */ + mergeFit?: boolean; + /** + * Default: false + * Set non grid content. Try using width style on divs. + */ + autoWidth?: boolean; + /** + * Default: 0 + * Start position or URL Hash string like '#id'. + */ + startPosition?: number | string; + /** + * Default: false + * Listen to url hash changes. data-hash on items is required. + */ + URLhashListener?: boolean; + /** + * Default: false + * Show next/prev buttons. + */ + nav?: boolean; + /** + * Default: true + * Go backwards when the boundary has reached. + */ + rewind?: boolean; + /** + * Default: ['next','prev'] + * HTML allowed. + */ + navText?: string[]; + /** + * Default: div + * DOM element type for a single directional navigation link. + */ + navElement?: string; + /** + * Default: 1 + * Navigation slide by x. 'page' string can be set to slide by page. + */ + slideBy?: number | string; + /** + * Default: true + * Show dots navigation. + */ + dots?: boolean; + /** + * Default: false + * Show dots each x item. + */ + dotsEach?: number | boolean; + /** + * Default: false + * Used by data-dot content. + */ + dotData?: boolean; + /** + * Default: false + * Lazy load images. data-src and data-src-retina for highres. + * Also load images into background inline style if element is not . + */ + lazyLoad?: boolean; + /** + * Default: false + * lazyContent was introduced during beta tests but i removed it from the final release due to bad implementation. + * It is a nice options so i will work on it in the nearest feature. + */ + lazyContent?: boolean; + /** + * Default: false + * Autoplay. + */ + autoplay?: boolean; + /** + * Default: 5000 + * Autoplay interval timeout. + */ + autoplayTimeout?: number; + /** + * Default: false + * Pause on mouse hover. + */ + autoplayHoverPause?: boolean; + /** + * Default: 250 + * Speed Calculate. More info to come.. + */ + smartSpeed?: number | boolean; + /** + * Default: Number + * Speed Calculate. More info to come.. + */ + fluidSpeed?: number | boolean; + /** + * Default: false + * autoplay speed. + */ + autoplaySpeed?: number | boolean; + /** + * Default: false + * Navigation speed. + */ + navSpeed?: number | boolean; + /** + * Default: Number/Boolean + * Pagination speed. + */ + dotsSpeed?: number | boolean; + /** + * Default: false + * Drag end speed. + */ + dragEndSpeed?: number | boolean; + /** + * Default: true + * Enable callback events. + */ + callbacks?: boolean; + /** + * Default: empty object + * Object containing responsive options. Can be set to false to remove responsive capabilities.. + */ + responsive?: { [breakpoint: string]: Options }; + /** + * Default: 200 + * Responsive refresh rate. + */ + responsiveRefreshRate?: number; + /** + * Default: window + * Set on any DOM element. + * If you care about non responsive browser (like ie8) then use it on main wrapper. This will prevent from crazy resizing. + */ + responsiveBaseElement?: Element; + /** + * Default: false + * Enable fetching YouTube/Vimeo/Vzaar videos. + */ + video?: boolean; + /** + * Default: false + * Set height for videos. + */ + videoHeight?: number | boolean; + /** + * Default: false + * Set width for videos. + */ + videoWidth?: number | boolean; + /** + * Default: false + * Class for CSS3 animation out. + */ + animateOut?: string | boolean; + /** + * Default: false + * Class for CSS3 animation in. + */ + animateIn?: string | boolean; + /** + * Default: swing + * Easing for CSS2 $.animate. + */ + fallbackEasing?: string; + /** + * Default: false + * Callback to retrieve basic information (current item/pages/widths). + * Info function second parameter is Owl DOM object reference. + */ + info?: HandlerCallback; + /** + * Default: false + * Use it if owl items are deep nested inside some generated content. E.g 'youritem'. Dont use dot before class name. + */ + nestedItemSelector?: string; + /** + * Default: div + * DOM element type for owl-item. + */ + itemElement?: string; + /** + * Default: div + * DOM element type for owl-stage. + */ + stageElement?: string; + /** + * Default: false + * Set your own container for nav. + */ + navContainer?: string | boolean; + /** + * Default: false + * Set your own container for nav. + */ + dotsContainer?: string | boolean; + + // CLASSES + /** + * Default: owl-refresh + * Class during refresh. + */ + refreshClass?: string; + /** + * Default: owl-loading + * Class during load. + */ + loadingClass?: string; + /** + * Default: owl-loaded + * Class after load. + */ + loadedClass?: string; + /** + * Default: owl-rtl + * Class for right to left mode. + */ + rtlClass?: string; + /** + * Default: owl-drag + * Class for mouse drag mode. + */ + dragClass?: string; + /** + * Default: owl-grab + * Class during mouse drag. + */ + grabClass?: string; + /** + * Default: owl-stage + * Stage class. + */ + stageClass?: string; + /** + * Default: owl-stage-outer + * Stage outer class. + */ + stageOuterClass?: string; + /** + * Default: owl-nav + * Navigation container class. + */ + navContainerClass?: string; + /** + * Default: ['owl-prev','owl-next'] + * Navigation buttons classes. + */ + navClass?: string[]; + /** + * Default: owl-controls + * Controls container class - wrapper for navs and dots. + */ + controlsClass?: string; + /** + * Default: owl-dot + * Dot Class. + */ + dotClass?: string; + /** + * Default: owl-dots + * Dots container class. + */ + dotsClass?: string; + /** + * Default: owl-height + * Auto height class. + */ + autoHeightClass?: string; + /** + * Default: false + * Optional helper class. + * Add '-' class to main element. Can be used to stylize content on given breakpoint. + */ + responsiveClass?: string | boolean; + + // EVENTS + /** + * When the plugin initializes. + */ + onInitialize?: HandlerCallback; + /** + * When the plugin has initialized. + */ + onInitialized?: HandlerCallback; + /** + * When the plugin gets resized. + */ + onResize?: HandlerCallback; + /** + * When the plugin has resized. + */ + onResized?: HandlerCallback; + /** + * When the internal state of the plugin needs update. + */ + onRefresh?: HandlerCallback; + /** + * When the internal state of the plugin has updated. + */ + onRefreshed?: HandlerCallback; + /** + * When the dragging of an item is started. + */ + onDrag?: HandlerCallback; + /** + * When the dragging of an item has finished. + */ + onDragged?: HandlerCallback; + /** + * When the translation of the stage starts. + */ + onTranslate?: HandlerCallback; + /** + * When the translation of the stage has finished. + */ + onTranslated?: HandlerCallback; + /** + * When a property is going to change its value. + */ + onChange?: HandlerCallback; + /** + * When a property has changed its value. + */ + onChanged?: HandlerCallback; + /** + * When lazy image loads. + */ + onLoadLazy?: HandlerCallback; + /** + * When lazy image has loaded. + */ + onLoadedLazy?: HandlerCallback; + /** + * When video has unloaded. + */ + onStopVideo?: HandlerCallback; + /** + * When video has loaded. + */ + onPlayVideo?: HandlerCallback; +} + +export default class OwlCarousel extends React.Component { +} diff --git a/types/react-owl-carousel/react-owl-carousel-tests.tsx b/types/react-owl-carousel/react-owl-carousel-tests.tsx new file mode 100644 index 0000000000..ba65ca9557 --- /dev/null +++ b/types/react-owl-carousel/react-owl-carousel-tests.tsx @@ -0,0 +1,30 @@ +import * as React from "react"; +import * as ReactDOM from 'react-dom'; + +// Import React Owl Carousel +import OwlCarousel from "react-owl-carousel"; + +export class ReactOwlCarouselTest extends React.Component { + render() { + return ( +
+ +

1

+

2

+

3

+

4

+

5

+

6

+

7

+

8

+

9

+

10

+

11

+

12

+
+
+ ); + } +} + +ReactDOM.render(, document.getElementById("root")); diff --git a/types/react-owl-carousel/tsconfig.json b/types/react-owl-carousel/tsconfig.json new file mode 100644 index 0000000000..3733b428c9 --- /dev/null +++ b/types/react-owl-carousel/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "jsx": "react", + "strictNullChecks": true, + "strictFunctionTypes": true, + "noImplicitAny": true, + "noImplicitThis": true, + "forceConsistentCasingInFileNames": true, + "noEmit": true, + "experimentalDecorators": true + }, + "files": [ + "index.d.ts", + "react-owl-carousel-tests.tsx" + ] +} diff --git a/types/react-owl-carousel/tslint.json b/types/react-owl-carousel/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/react-owl-carousel/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} diff --git a/types/react-popover/index.d.ts b/types/react-popover/index.d.ts new file mode 100644 index 0000000000..20958f3040 --- /dev/null +++ b/types/react-popover/index.d.ts @@ -0,0 +1,35 @@ +// Type definitions for react-popover 0.5 +// Project: https://github.com/littlebits/react-popover +// Definitions by: Jakub Řičař +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.6 + +import * as React from 'react'; + +export type PopoverPlace = + | 'above' + | 'right' + | 'below' + | 'left' + | 'row' + | 'column' + | 'start' + | 'end'; + +export interface PopoverProps { + body: React.ReactNode; + isOpen?: boolean; + preferPlace?: PopoverPlace; + place?: PopoverPlace; + onOuterAction?: (event: Event) => void; + refreshIntervalMs?: number; + enterExitTransitionDurationMs?: number; + tipSize?: number; + className?: string; + style?: React.CSSProperties; + target?: React.ReactElement; + appendTarget?: Element; +} + +declare class Popover extends React.Component {} +export default Popover; diff --git a/types/react-popover/react-popover-tests.tsx b/types/react-popover/react-popover-tests.tsx new file mode 100644 index 0000000000..39cb256c73 --- /dev/null +++ b/types/react-popover/react-popover-tests.tsx @@ -0,0 +1,23 @@ +import * as React from 'react'; +import Popover from 'react-popover'; + +class Test extends React.Component { + render() { + return ( + body
} + isOpen + preferPlace="above" + place="below" + onOuterAction={event => console.log(event)} + refreshIntervalMs={10} + enterExitTransitionDurationMs={10} + tipSize={10} + className="xxx" + style={{ display: 'block' }} + target={
target
} + appendTarget={document.createElement('div')} + /> + ); + } +} diff --git a/types/react-popover/tsconfig.json b/types/react-popover/tsconfig.json new file mode 100644 index 0000000000..723d670093 --- /dev/null +++ b/types/react-popover/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react" + }, + "files": [ + "index.d.ts", + "react-popover-tests.tsx" + ] +} diff --git a/types/react-popover/tslint.json b/types/react-popover/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-popover/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/react-stripe-elements/index.d.ts b/types/react-stripe-elements/index.d.ts index 0ef90dc839..d7cea98728 100644 --- a/types/react-stripe-elements/index.d.ts +++ b/types/react-stripe-elements/index.d.ts @@ -16,6 +16,8 @@ export namespace ReactStripeElements { import ElementsOptions = stripe.elements.ElementsOptions; import TokenOptions = stripe.TokenOptions; import TokenResponse = stripe.TokenResponse; + import SourceResponse = stripe.SourceResponse; + import SourceOptions = stripe.SourceOptions; /** * There's a bug in @types/stripe which defines the property as @@ -28,8 +30,7 @@ export namespace ReactStripeElements { type StripeProviderProps = { apiKey: string; stripe?: never; } | { apiKey?: never; stripe: StripeProps | null; }; interface StripeProps { - // I'm not sure what the definition for this is - createSource(): void; + createSource(sourceData?: SourceOptions): Promise; createToken(options?: TokenOptions): Promise; } diff --git a/types/storybook__addon-info/index.d.ts b/types/storybook__addon-info/index.d.ts index f694ad3eb4..c616933b8f 100644 --- a/types/storybook__addon-info/index.d.ts +++ b/types/storybook__addon-info/index.d.ts @@ -29,6 +29,6 @@ export interface Options { maxPropStringLength?: number; } -export function withInfo(textOrOptions: string | Options): (storyFn: RenderFunction) => () => React.ReactElement; +export function withInfo(textOrOptions: string | Options): (storyFn: RenderFunction) => (context?: object) => React.ReactElement; export function setDefaults(newDefaults: Options): Options; diff --git a/types/three/three-core.d.ts b/types/three/three-core.d.ts index d3bd6fadcc..f97768d34f 100644 --- a/types/three/three-core.d.ts +++ b/types/three/three-core.d.ts @@ -1833,19 +1833,66 @@ export interface RaycasterParameters { } export class Raycaster { + /** + * This creates a new raycaster object. + * @param origin The origin vector where the ray casts from. + * @param direction The direction vector that gives direction to the ray. Should be normalized. + * @param near All results returned are further away than near. Near can't be negative. Default value is 0. + * @param far All results returned are closer then far. Far can't be lower then near . Default value is Infinity. + */ constructor(origin?: Vector3, direction?: Vector3, near?: number, far?: number); + /** The Ray used for the raycasting. */ ray: Ray; + + /** + * The near factor of the raycaster. This value indicates which objects can be discarded based on the + * distance. This value shouldn't be negative and should be smaller than the far property. + */ near: number; + + /** + * The far factor of the raycaster. This value indicates which objects can be discarded based on the + * distance. This value shouldn't be negative and should be larger than the near property. + */ far: number; + params: RaycasterParameters; - precision: number; + + /** + * The precision factor of the raycaster when intersecting Line objects. + */ linePrecision: number; + /** + * Updates the ray with a new origin and direction. + * @param origin The origin vector where the ray casts from. + * @param direction The normalized direction vector that gives direction to the ray. + */ set(origin: Vector3, direction: Vector3): void; + + /** + * Updates the ray with a new origin and direction. + * @param coords 2D coordinates of the mouse, in normalized device coordinates (NDC)---X and Y components should be between -1 and 1. + * @param camera camera from which the ray should originate + */ setFromCamera(coords: { x: number; y: number; }, camera: Camera ): void; - intersectObject(object: Object3D, recursive?: boolean): Intersection[]; - intersectObjects(objects: Object3D[], recursive?: boolean): Intersection[]; + + /** + * Checks all intersection between the ray and the object with or without the descendants. Intersections are returned sorted by distance, closest first. + * @param object The object to check for intersection with the ray. + * @param recursive If true, it also checks all descendants. Otherwise it only checks intersecton with the object. Default is false. + * @param optionalTarget (optional) target to set the result. Otherwise a new Array is instantiated. If set, you must clear this array prior to each call (i.e., array.length = 0;). + */ + intersectObject(object: Object3D, recursive?: boolean, optionalTarget?: Intersection[]): Intersection[]; + + /** + * Checks all intersection between the ray and the objects with or without the descendants. Intersections are returned sorted by distance, closest first. Intersections are of the same form as those returned by .intersectObject. + * @param objects The objects to check for intersection with the ray. + * @param recursive If true, it also checks all descendants of the objects. Otherwise it only checks intersecton with the objects. Default is false. + * @param optionalTarget (optional) target to set the result. Otherwise a new Array is instantiated. If set, you must clear this array prior to each call (i.e., array.length = 0;). + */ + intersectObjects(objects: Object3D[], recursive?: boolean, optionalTarget?: Intersection[]): Intersection[]; } export class Layers { diff --git a/types/zopflipng-bin/index.d.ts b/types/zopflipng-bin/index.d.ts new file mode 100644 index 0000000000..8fc2242b98 --- /dev/null +++ b/types/zopflipng-bin/index.d.ts @@ -0,0 +1,8 @@ +// Type definitions for zopflipng-bin 4.1 +// Project: https://github.com/imagemin/zopflipng-bin#readme +// Definitions by: Hirotaka Ikoma +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +declare const zopflipng: string; +export = zopflipng; diff --git a/types/zopflipng-bin/tsconfig.json b/types/zopflipng-bin/tsconfig.json new file mode 100644 index 0000000000..5a929c6d3a --- /dev/null +++ b/types/zopflipng-bin/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "zopflipng-bin-tests.ts" + ] +} diff --git a/types/zopflipng-bin/tslint.json b/types/zopflipng-bin/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/zopflipng-bin/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/zopflipng-bin/zopflipng-bin-tests.ts b/types/zopflipng-bin/zopflipng-bin-tests.ts new file mode 100644 index 0000000000..28c3fe491f --- /dev/null +++ b/types/zopflipng-bin/zopflipng-bin-tests.ts @@ -0,0 +1,6 @@ +import { execFile } from "child_process"; +import * as zopflipng from "zopflipng-bin"; + +execFile(zopflipng, ["-m", "--lossy_8bit", "input.png", "outout.png"], { encoding: "utf-8" }, (err: Error | null) => { + console.log("Image minified!"); +});