Convert `Ui/Redactor/Article` to TypeScript
authorAlexander Ebert <ebert@woltlab.com>
Tue, 3 Nov 2020 19:21:12 +0000 (20:21 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 3 Nov 2020 19:21:12 +0000 (20:21 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Article.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Editor.js [new file with mode: 0644]
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Article.js [deleted file]
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Article.ts [new file with mode: 0644]
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Editor.ts [new file with mode: 0644]

index 1c5bf68f0ac7af885139be3e49d2f1728fce4147..3aa1327aff8481446b599733bd15dcc85f08b4a4 100644 (file)
@@ -2,35 +2,28 @@
  * Converts `<woltlab-metacode>` into the bbcode representation.
  *
  * @author      Alexander Ebert
- * @copyright  2001-2019 WoltLab GmbH
+ * @copyright  2001-2019 WoltLab GmbH
  * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @module      WoltLabSuite/Core/Ui/Redactor/Article
  */
-define(['WoltLabSuite/Core/Ui/Article/Search'], function (UiArticleSearch) {
+define(["require", "exports", "tslib", "../../Core", "../Article/Search"], function (require, exports, tslib_1, Core, UiArticleSearch) {
     "use strict";
-    if (!COMPILER_TARGET_DEFAULT) {
-        var Fake = function () { };
-        Fake.prototype = {
-            init: function () { },
-            _click: function () { },
-            _insert: function () { }
-        };
-        return Fake;
-    }
-    function UiRedactorArticle(editor, button) { this.init(editor, button); }
-    UiRedactorArticle.prototype = {
-        init: function (editor, button) {
+    Core = tslib_1.__importStar(Core);
+    UiArticleSearch = tslib_1.__importStar(UiArticleSearch);
+    class UiRedactorArticle {
+        constructor(editor, button) {
             this._editor = editor;
-            button.addEventListener('click', this._click.bind(this));
-        },
-        _click: function (event) {
+            button.addEventListener("click", (ev) => this._click(ev));
+        }
+        _click(event) {
             event.preventDefault();
-            UiArticleSearch.open(this._insert.bind(this));
-        },
-        _insert: function (articleId) {
+            UiArticleSearch.open((articleId) => this._insert(articleId));
+        }
+        _insert(articleId) {
             this._editor.buffer.set();
-            this._editor.insert.text("[wsa='" + articleId + "'][/wsa]");
+            this._editor.insert.text(`[wsa='${articleId}'][/wsa]`);
         }
-    };
+    }
+    Core.enableLegacyInheritance(UiRedactorArticle);
     return UiRedactorArticle;
 });
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Editor.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Editor.js
new file mode 100644 (file)
index 0000000..2ae92b6
--- /dev/null
@@ -0,0 +1,4 @@
+define(["require", "exports"], function (require, exports) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", { value: true });
+});
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Article.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Article.js
deleted file mode 100644 (file)
index 133ae42..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * Converts `<woltlab-metacode>` into the bbcode representation.
- * 
- * @author      Alexander Ebert
- * @copyright  2001-2019 WoltLab GmbH
- * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module      WoltLabSuite/Core/Ui/Redactor/Article
- */
-define(['WoltLabSuite/Core/Ui/Article/Search'], function(UiArticleSearch) {
-       "use strict";
-       
-       if (!COMPILER_TARGET_DEFAULT) {
-               var Fake = function() {};
-               Fake.prototype = {
-                       init: function() {},
-                       _click: function() {},
-                       _insert: function() {}
-               };
-               return Fake;
-       }
-       
-       function UiRedactorArticle(editor, button) { this.init(editor, button); }
-       UiRedactorArticle.prototype = {
-               init: function (editor, button) {
-                       this._editor = editor;
-                       
-                       button.addEventListener('click', this._click.bind(this));
-               },
-               
-               _click: function (event) {
-                       event.preventDefault();
-                       
-                       UiArticleSearch.open(this._insert.bind(this));
-               },
-               
-               _insert: function (articleId) {
-                       this._editor.buffer.set();
-                       
-                       this._editor.insert.text("[wsa='" + articleId + "'][/wsa]");
-               }
-       };
-       
-       return UiRedactorArticle;
-});
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Article.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Article.ts
new file mode 100644 (file)
index 0000000..f245141
--- /dev/null
@@ -0,0 +1,38 @@
+/**
+ * Converts `<woltlab-metacode>` into the bbcode representation.
+ *
+ * @author      Alexander Ebert
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module      WoltLabSuite/Core/Ui/Redactor/Article
+ */
+
+import * as Core from "../../Core";
+import * as UiArticleSearch from "../Article/Search";
+import { RedactorEditor } from "./Editor";
+
+class UiRedactorArticle {
+  protected readonly _editor: RedactorEditor;
+
+  constructor(editor: RedactorEditor, button: HTMLAnchorElement) {
+    this._editor = editor;
+
+    button.addEventListener("click", (ev) => this._click(ev));
+  }
+
+  protected _click(event: MouseEvent): void {
+    event.preventDefault();
+
+    UiArticleSearch.open((articleId) => this._insert(articleId));
+  }
+
+  protected _insert(articleId: number): void {
+    this._editor.buffer.set();
+
+    this._editor.insert.text(`[wsa='${articleId}'][/wsa]`);
+  }
+}
+
+Core.enableLegacyInheritance(UiRedactorArticle);
+
+export = UiRedactorArticle;
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Editor.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Editor.ts
new file mode 100644 (file)
index 0000000..e0f968c
--- /dev/null
@@ -0,0 +1,8 @@
+export interface RedactorEditor {
+  buffer: {
+    set: () => void;
+  };
+  insert: {
+    text: (text: string) => void;
+  };
+}