From 8e0e817b34988f06c4e2720ed4dcb3c43036108a Mon Sep 17 00:00:00 2001 From: cAttte <26514199+cAttte@users.noreply.github.com> Date: Thu, 4 Mar 2021 03:32:58 -0300 Subject: [PATCH 1/3] move html out of index, add class Raw and document --- mw/html.d.ts | 36 ++++++++++++++++++++++++++++++++++++ mw/index.d.ts | 6 ------ 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 mw/html.d.ts diff --git a/mw/html.d.ts b/mw/html.d.ts new file mode 100644 index 0000000..674d210 --- /dev/null +++ b/mw/html.d.ts @@ -0,0 +1,36 @@ +declare global { + namespace mw { + namespace html { + /** + * Escape a string for HTML. + * Converts special characters to HTML entities. + * @param {string} s The string to escape + * @returns {string} HTML + */ + function escape(s: string): string; + + /** + * Create an HTML element string, with safe escaping. + * @param {string} name The tag name + * @param {{ [key: string]: string }} attrs An object with members mapping element names to values + * @param {string | html.Raw} contents The contents of the element + * @returns {string} HTML + */ + function element( + name: string, + attrs?: Record, + contents?: string | mw.html.Raw + ): string; + + /** + * Wrapper object for raw HTML passed to mw.html.element(). + */ + class Raw { + constructor(value: V); + private value: V; + } + } + } +} + +export {}; diff --git a/mw/index.d.ts b/mw/index.d.ts index fa14918..563355c 100644 --- a/mw/index.d.ts +++ b/mw/index.d.ts @@ -84,12 +84,6 @@ declare global { wgWikibaseItemId: string; }>; - namespace html { - function escape(s: string): string; - - function element(name: string, attrs?: any, contents?: string): string; - } - namespace log { function deprecate( obj: any, From 9eabfc9a31c7dd8a34503eff7ad1bb73d4807ed9 Mon Sep 17 00:00:00 2001 From: cAttte <26514199+cAttte@users.noreply.github.com> Date: Thu, 4 Mar 2021 03:34:12 -0300 Subject: [PATCH 2/3] order imports --- mw/index.d.ts | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/mw/index.d.ts b/mw/index.d.ts index 563355c..319e9e0 100644 --- a/mw/index.d.ts +++ b/mw/index.d.ts @@ -1,15 +1,17 @@ import "./Api"; +import "./hook"; +import "./html"; import "./language"; -import "./util"; -import "./user"; import "./loader"; +import "./log"; import "./Map"; +import "./message"; +import "./notification"; +import "./storage"; import "./Title"; import "./Uri"; -import "./hook"; -import "./storage"; -import "./notification"; -import "./message"; +import "./user"; +import "./util"; declare global { /** @@ -84,20 +86,6 @@ declare global { wgWikibaseItemId: string; }>; - namespace log { - function deprecate( - obj: any, - key: string, - val: any, - msg?: string, - logName?: string - ): void; - - function error(...msg: any[]): void; - - function warn(...msg: string[]): void; - } - // types for mw.widgets are out of scope! const widgets: any; } From 77dc36ccfa268432bab90dbf32d0d21286b05368 Mon Sep 17 00:00:00 2001 From: cAttte <26514199+cAttte@users.noreply.github.com> Date: Thu, 4 Mar 2021 03:39:47 -0300 Subject: [PATCH 3/3] document mw.log --- mw/log.d.ts | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 mw/log.d.ts diff --git a/mw/log.d.ts b/mw/log.d.ts new file mode 100644 index 0000000..e51ed55 --- /dev/null +++ b/mw/log.d.ts @@ -0,0 +1,44 @@ +declare global { + namespace mw { + namespace log { + /** + * Create a property on a host object that, when accessed, will produce a deprecation warning in the console. + * @param {*} obj Host object of deprecated property + * @param {string} key Name of property to create in `obj` + * @param {*} val The value this property should return when accessed + * @param {string?} msg Optional text to include in the deprecation message + * @param {string?} logName Name for the feature for logging and tracking purposes. Except for properties of the window object, tracking is only enabled if logName is set + * @returns {void} + */ + function deprecate( + obj: any, + key: string, + val: any, + msg?: string, + logName?: string + ): void; + + /** + * Write a message to the browser console's error channel. + * + * Most browsers also print a stacktrace when calling this method if the argument is an Error object. + * + * This method is a no-op in browsers that don't implement the Console API. + * @param {Array<*>} msg Messages to output to console + * @returns {void} + */ + function error(...msg: any[]): void; + + /** + * Write a message to the browser console's warning channel. + * + * This method is a no-op in browsers that don't implement the Console API. + * @param msg Messages to output to console + * @returns {void} + */ + function warn(...msg: any[]): void; + } + } +} + +export {};