Jelajahi Sumber

Move type definition to separate file

JC Brand 3 bulan lalu
induk
melakukan
3a884f8f26

+ 1 - 1
.gitignore

@@ -49,8 +49,8 @@ develop-eggs
 pyvenv.cfg
 
 converse-logs/*.html
+community-plugins
 
-Backbone.Overview
 tags
 transpile
 

+ 6 - 23
src/headless/shared/api/public.js

@@ -7,7 +7,7 @@ import sizzle from 'sizzle';
 import { Stanza, Strophe, $build, $iq, $msg, $pres, stx } from 'strophe.js';
 import { Collection, Model } from "@converse/skeletor";
 import { filesize } from 'filesize';
-import { html } from 'lit';
+import { css, html, render } from 'lit';
 
 import api from './index.js';
 import _converse from '../_converse.js';
@@ -163,33 +163,14 @@ const converse = Object.assign(/** @type {ConversePrivateGlobal} */(window).conv
         }
 
     },
-    /**
-     * Utility methods and globals from bundled 3rd party libraries.
-     * @typedef ConverseEnv
-     * @property {Error} converse.env.TimeoutError
-     * @property {function} converse.env.$build    - Creates a Strophe.Builder, for creating stanza objects.
-     * @property {function} converse.env.$iq       - Creates a Strophe.Builder with an <iq/> element as the root.
-     * @property {function} converse.env.$msg      - Creates a Strophe.Builder with an <message/> element as the root.
-     * @property {function} converse.env.$pres     - Creates a Strophe.Builder with an <presence/> element as the root.
-     * @property {function} converse.env.Promise   - The Promise implementation used by Converse.
-     * @property {function} converse.env.Strophe   - The [Strophe](http://strophe.im/strophejs) XMPP library used by Converse.
-     * @property {function} converse.env.f         - And instance of Lodash with its methods wrapped to produce immutable auto-curried iteratee-first data-last methods.
-     * @property {function} converse.env.sizzle    - [Sizzle](https://sizzlejs.com) CSS selector engine.
-     * @property {function} converse.env.sprintf
-     * @property {object} converse.env._           - The instance of [lodash-es](http://lodash.com) used by Converse.
-     * @property {object} converse.env.dayjs       - [DayJS](https://github.com/iamkun/dayjs) date manipulation library.
-     * @property {Array<Error>} converse.env.errors
-     * @memberOf converse
-     */
-    'env': {
+    env: /** @type {import('./types').ConverseEnv} */({
         $build,
         $iq,
         $msg,
         $pres,
-        'utils': u,
+        utils: u,
         Collection,
         Model,
-        Promise,
         Stanza,
         Strophe,
         TimeoutError,
@@ -198,12 +179,14 @@ const converse = Object.assign(/** @type {ConversePrivateGlobal} */(window).conv
         errors,
         filesize,
         html,
+        css,
+        render,
         log,
         sizzle,
         sprintf,
         stx,
         u,
-    }
+    })
 });
 
 export default converse;

+ 27 - 0
src/headless/shared/api/types.ts

@@ -0,0 +1,27 @@
+import dayjs from "dayjs";
+import { $build, $iq, $msg, $pres, Strophe, Stanza } from "strophe.js";
+import { Model, Collection } from "@converse/skeletor";
+import { html, render } from "lit";
+import u from "../../utils/index.js";
+import sizzle from "sizzle";
+
+/**
+ * Utility methods and globals from bundled 3rd party libraries.
+ */
+export type ConverseEnv = {
+    $build: typeof $build;
+    $iq: typeof $iq;
+    $msg: typeof $msg;
+    $pres: typeof $pres;
+    Collection: typeof Collection;
+    Model: typeof Model;
+    Stanza: typeof Stanza;
+    Strophe: typeof Strophe;
+    TimeoutError: any;
+    dayjs: typeof dayjs;
+    html: typeof html;
+    render: typeof render;
+    sizzle: typeof sizzle;
+    sprintf: (...args: any[]) => string;
+    u: typeof u;
+};

+ 27 - 0
src/headless/types/shared/api/types.d.ts

@@ -0,0 +1,27 @@
+import dayjs from "dayjs";
+import { $build, $iq, $msg, $pres, Strophe, Stanza } from "strophe.js";
+import { Model, Collection } from "@converse/skeletor";
+import { html, render } from "lit";
+import u from "../../utils/index.js";
+import sizzle from "sizzle";
+/**
+ * Utility methods and globals from bundled 3rd party libraries.
+ */
+export type ConverseEnv = {
+    $build: typeof $build;
+    $iq: typeof $iq;
+    $msg: typeof $msg;
+    $pres: typeof $pres;
+    Collection: typeof Collection;
+    Model: typeof Model;
+    Stanza: typeof Stanza;
+    Strophe: typeof Strophe;
+    TimeoutError: any;
+    dayjs: typeof dayjs;
+    html: typeof html;
+    render: typeof render;
+    sizzle: typeof sizzle;
+    sprintf: (...args: any[]) => string;
+    u: typeof u;
+};
+//# sourceMappingURL=types.d.ts.map

+ 1 - 1
src/plugins/chatview/tests/corrections.js

@@ -1,5 +1,5 @@
 /*global mock, converse */
-const { Promise, Strophe, sizzle, u } = converse.env;
+const { Strophe, sizzle, u } = converse.env;
 
 describe("A Chat Message", function () {
 

+ 1 - 1
src/plugins/chatview/tests/emojis.js

@@ -1,6 +1,6 @@
 /*global mock, converse */
 
-const { Promise, $msg } = converse.env;
+const { $msg } = converse.env;
 const u = converse.env.utils;
 const original_timeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
 

+ 1 - 1
src/plugins/chatview/tests/messages.js

@@ -1,5 +1,5 @@
 /*global mock, converse */
-const { Promise, Strophe, $msg, dayjs, sizzle, stx, u } = converse.env;
+const { Strophe, $msg, dayjs, sizzle, stx, u } = converse.env;
 
 
 describe("A Chat Message", function () {

+ 1 - 1
src/plugins/chatview/tests/oob.js

@@ -1,5 +1,5 @@
 /*global mock, converse */
-const { Strophe, Promise, u } = converse.env;
+const { Strophe, u } = converse.env;
 
 describe("A Chat Message", function () {
     describe("which contains an OOB URL", function () {

+ 1 - 1
src/plugins/chatview/tests/receipts.js

@@ -1,6 +1,6 @@
 /*global mock, converse, _ */
 
-const { Promise, Strophe, $msg, sizzle } = converse.env;
+const { Strophe, $msg, sizzle } = converse.env;
 const u = converse.env.utils;
 
 

+ 1 - 2
src/plugins/modal/index.js

@@ -7,8 +7,6 @@ import Popover from "./popover.js";
 import modal_api from "./api.js";
 import { _converse, api, converse } from "@converse/headless";
 
-Object.assign(converse.env, { BaseModal, Popover });
-
 converse.plugins.add("converse-modal", {
     initialize() {
         api.listen.on("disconnect", () => {
@@ -20,6 +18,7 @@ converse.plugins.add("converse-modal", {
 
         api.listen.on("clearSession", () => api.modal.removeAll());
 
+        Object.assign(_converse.exports, { BaseModal, Popover });
         Object.assign(_converse.api, modal_api);
     },
 });

+ 3 - 3
src/plugins/muc-views/modals/templates/muc-config.js

@@ -1,8 +1,8 @@
-import 'shared/components/image-picker.js';
-import tplSpinner from 'templates/spinner.js';
-import { __ } from 'i18n';
 import { api, converse, parsers } from '@converse/headless';
 import { html } from 'lit';
+import tplSpinner from 'templates/spinner.js';
+import { __ } from 'i18n';
+import 'shared/components/image-picker.js';
 import '../styles/config.scss';
 
 const u = converse.env.utils;

+ 1 - 2
src/plugins/muc-views/tests/commands.js

@@ -1,6 +1,5 @@
 /*global mock, converse */
-
-const { Strophe, Promise, sizzle, stx, u }  = converse.env;
+const { Strophe, sizzle, stx, u }  = converse.env;
 
 describe("Groupchats", function () {
     beforeAll(() => jasmine.addMatchers({ toEqualStanza: jasmine.toEqualStanza }));

+ 1 - 1
src/plugins/muc-views/tests/muc-add-modal.js

@@ -1,5 +1,5 @@
 /*global mock, converse */
-const {  Promise, sizzle, u } = converse.env;
+const { sizzle, u } = converse.env;
 
 describe('The "Groupchats" Add modal', function () {
 

+ 1 - 1
src/plugins/muc-views/tests/muc-list-modal.js

@@ -1,6 +1,6 @@
 /*global mock, converse */
 
-const { Strophe, Promise, sizzle, u, stx } = converse.env;
+const { Strophe, sizzle, u, stx } = converse.env;
 
 describe('The "Groupchats" List modal', function () {
 

+ 1 - 2
src/plugins/muc-views/tests/muc-messages.js

@@ -1,6 +1,5 @@
 /*global mock, converse */
-
-const { Promise, Strophe, sizzle, u, stx } = converse.env;
+const { Strophe, sizzle, u, stx } = converse.env;
 const original_timeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
 
 describe("A Groupchat Message", function () {

+ 1 - 2
src/plugins/muc-views/tests/muc.js

@@ -1,6 +1,5 @@
 /*global mock, converse */
-
-const { $pres, Strophe, Promise, sizzle, stx, u }  = converse.env;
+const { $pres, Strophe, sizzle, stx, u }  = converse.env;
 
 describe("Groupchats", function () {
 

+ 1 - 2
src/plugins/muc-views/tests/mute.js

@@ -1,6 +1,5 @@
 /*global mock, converse */
-
-const { Strophe, Promise, stx, u }  = converse.env;
+const { Strophe, stx, u }  = converse.env;
 
 describe("Groupchats", function () {
     describe("A muted user", function () {