ソースを参照

Expose constants via the `_converse` object.

Fixes #3440.
JC Brand 1 年間 前
コミット
46313ad92c

+ 2 - 0
src/headless/index.js

@@ -43,6 +43,8 @@ export { VCard, VCards } from './plugins/vcard/index.js'; // XEP-0054 VCard-temp
 import * as muc_constants from './plugins/muc/constants.js';
 const constants = Object.assign({}, shared_constants, muc_constants);
 
+Object.assign(_converse.constants, constants);
+
 export { api, converse, _converse, i18n, log, u, constants, parsers };
 
 export default converse;

+ 6 - 0
src/headless/shared/_converse.js

@@ -121,6 +121,12 @@ class ConversePrivateGlobal extends EventEmitter(Object) {
          */
         this.exports = /** @type {Record<string, Object>} */({});
 
+        /**
+         * Provides a way for 3rd party plugins to access constants used by
+         * Converse.
+         */
+        this.constants = /** @type {Record<string, string|Object>} */({});
+
         /**
          * Namespace for storing the state, as represented by instances of
          * Models and Collections.

+ 5 - 0
src/headless/types/shared/_converse.d.ts

@@ -60,6 +60,11 @@ declare class ConversePrivateGlobal extends ConversePrivateGlobal_base {
      * converse.js as a dependency.
      */
     exports: Record<string, any>;
+    /**
+     * Provides a way for 3rd party plugins to access constants used by
+     * Converse.
+     */
+    constants: Record<string, any>;
     /**
      * Namespace for storing the state, as represented by instances of
      * Models and Collections.

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

@@ -17,6 +17,7 @@ export type _converse = {
     api: any;
     labels: Record<string, string | Record<string, string>>;
     exports: Record<string, any>;
+    constants: Record<string, any>;
     state: any;
     initSession(): void;
     session: import("@converse/skeletor").Model;