Skip to content

Commit 6da3a7d

Browse files
committed
Add build output to repo
1 parent bdeb92a commit 6da3a7d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1689
-1
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Custom
22
.idea/
3-
lib/
43
.npmrc
54

65
# Logs

lib/ModuleApi.d.ts

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import React from "react";
2+
import { PlainSubstitution, TranslationStringsObject } from "./types/translations";
3+
import { DialogContent, DialogProps } from "./components/DialogContent";
4+
import { AccountAuthInfo } from "./types/AccountAuthInfo";
5+
import { ModuleUiDialogOptions } from "./types/ModuleUiDialogOptions";
6+
import { App } from "./types/App";
7+
import { Container } from "./types/Container";
8+
/**
9+
* A module API surface for the react-sdk. Provides a stable API for modules to
10+
* interact with the internals of the react-sdk without having to update themselves
11+
* for refactorings or code changes within the react-sdk.
12+
*
13+
* An instance of a ModuleApi is provided to all modules at runtime.
14+
*/
15+
export interface ModuleApi {
16+
/**
17+
* Register strings with the translation engine. This supports overriding strings which
18+
* the system is already aware of.
19+
* @param translations The translations to load.
20+
*/
21+
registerTranslations(translations: TranslationStringsObject): void;
22+
/**
23+
* Runs a string through the translation engine. If variables are needed, use %(varName)s
24+
* as a placeholder for varName in the variables object.
25+
* @param s The string. Should already be known to the engine.
26+
* @param variables The variables to replace, if any.
27+
* @returns The translated string.
28+
*/
29+
translateString(s: string, variables?: Record<string, PlainSubstitution>): string;
30+
/**
31+
* Opens a dialog in the client.
32+
* @param initialTitleOrOptions Initial options for the dialog. Can be the title of the dialog, or a
33+
* configuration object. Note that the dialog implementation may later
34+
* modify its own options via the {@link DialogProps.setOptions} callback.
35+
* @param body The function which creates a body component for the dialog.
36+
* @param props Optional props to provide to {@link body}, in addition to the common set in {@link DialogProps}.
37+
* @returns Whether the user submitted the dialog or closed it, and the model returned by the
38+
* dialog component if submitted.
39+
*/
40+
openDialog<M extends object, P extends DialogProps = DialogProps, C extends DialogContent<P> = DialogContent<P>>(initialTitleOrOptions: string | ModuleUiDialogOptions, body: (props: P, ref: React.RefObject<C>) => React.ReactNode, props?: Omit<P, keyof DialogProps>): Promise<{
41+
didOkOrSubmit: boolean;
42+
model: M;
43+
}>;
44+
/**
45+
* Registers for an account on the currently connected homeserver. This requires that the homeserver
46+
* offer a password-only flow without other flows. This means it is not traditionally compatible with
47+
* homeservers like matrix.org which also generally require a combination of reCAPTCHA, email address,
48+
* terms of service acceptance, etc.
49+
* @param username The username to register.
50+
* @param password The password to register.
51+
* @param displayName Optional display name to set.
52+
* @returns Resolves to the authentication info for the created account.
53+
*/
54+
registerSimpleAccount(username: string, password: string, displayName?: string): Promise<AccountAuthInfo>;
55+
/**
56+
* Switches the user's currently logged-in account to the one specified. The user will not
57+
* be warned.
58+
* @param accountAuthInfo The authentication info to log in with.
59+
* @returns Resolves when complete.
60+
*/
61+
overwriteAccountAuth(accountAuthInfo: AccountAuthInfo): Promise<void>;
62+
/**
63+
* Switches the user's current view to look at the given permalink. If the permalink is
64+
* a room, it can optionally be joined automatically if required.
65+
*
66+
* Permalink must be a matrix.to permalink at this time.
67+
* @param uri The URI to navigate to.
68+
* @param andJoin True to also join the room if needed. Does nothing if the link isn't to
69+
* a room.
70+
* @returns Resolves when complete.
71+
*/
72+
navigatePermalink(uri: string, andJoin?: boolean): Promise<void>;
73+
/**
74+
* Gets a value verbatim from the config. The returned value will be of the type specified
75+
* by the user - it is not verified against a schema. If the value does not exist in the
76+
* config then this will return undefined;
77+
*
78+
* The caller should provide a namespace which it owns to retrieve settings from. During
79+
* read, the `key` will be treated as a sub-key of the namespace on the overall configuration
80+
* object. For example:
81+
*
82+
* ```json
83+
* {
84+
* "inaccessible_root_level_config": "hello world",
85+
* "org.example.my_module_namespace": {
86+
* "my_key": 42
87+
* }
88+
* }
89+
* ```
90+
*
91+
* The caller would use `getConfigValue<number>("org.example.my_module_namespace", "my_key")`
92+
* to get the targeted config value.
93+
*
94+
* There is no root namespace, thus root-level config values cannot be read.
95+
* @param namespace The module's namespace.
96+
* @param key The key to look up.
97+
* @returns The config value verbatim.
98+
*/
99+
getConfigValue<T>(namespace: string, key: string): T | undefined;
100+
/**
101+
* Gets the apps for a given room.
102+
*
103+
* @param roomId The room ID to get the apps for.
104+
* @returns The apps for the given room.
105+
*/
106+
getApps(roomId: string): Array<App>;
107+
/**
108+
* Gets the avatar URL for an app.
109+
*
110+
* @param app The app to get the avatar URL for.
111+
* @param width The width of the avatar.
112+
* @param height The height of the avatar.
113+
* @param resizeMethod The resize method to use, either "crop" or "scale".
114+
*/
115+
getAppAvatarUrl(app: App, width?: number, height?: number, resizeMethod?: string): string | null;
116+
/**
117+
* Checks if an app is in a container for a given room.
118+
*
119+
* @param app The app to check.
120+
* @param container The container to check.
121+
* @param roomId The room ID to check.
122+
*/
123+
isAppInContainer(app: App, container: Container, roomId: string): boolean;
124+
/**
125+
* Moves apps to containers for a given room.
126+
*
127+
* @param app The app to move.
128+
* @param container The container to move the app to.
129+
* @param roomId The room ID to move the app in.
130+
*/
131+
moveAppToContainer(app: App, container: Container, roomId: string): void;
132+
}

lib/ModuleApi.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});

lib/RuntimeModule.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// <reference types="node" />
2+
import { EventEmitter } from "events";
3+
import { ModuleApi } from "./ModuleApi";
4+
import { PlainSubstitution } from "./types/translations";
5+
import { AllExtensions } from "./types/extensions";
6+
/**
7+
* Represents a module which is loaded at runtime. Modules which implement this class
8+
* will be provided information about the application state and can react to it.
9+
*/
10+
export declare abstract class RuntimeModule extends EventEmitter {
11+
protected readonly moduleApi: ModuleApi;
12+
extensions?: AllExtensions;
13+
moduleName: string;
14+
protected constructor(moduleApi: ModuleApi);
15+
/**
16+
* Run a string through the translation engine. Shortcut to ModuleApi#translateString().
17+
* @param s The string.
18+
* @param variables The variables, if any.
19+
* @returns The translated string.
20+
* @protected
21+
*/
22+
protected t(s: string, variables?: Record<string, PlainSubstitution>): string;
23+
}

lib/RuntimeModule.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"use strict";
2+
3+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4+
5+
Object.defineProperty(exports, "__esModule", {
6+
value: true
7+
});
8+
exports.RuntimeModule = void 0;
9+
10+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11+
12+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13+
14+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
15+
16+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
17+
18+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
19+
20+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
21+
22+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
23+
24+
var _events = require("events");
25+
26+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
27+
28+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
29+
30+
// TODO: Type the event emitter with AnyLifecycle (extract TypedEventEmitter from js-sdk somehow?)
31+
// See https://github.com/matrix-org/matrix-react-sdk-module-api/issues/4
32+
33+
/**
34+
* Represents a module which is loaded at runtime. Modules which implement this class
35+
* will be provided information about the application state and can react to it.
36+
*/
37+
var RuntimeModule = /*#__PURE__*/function (_EventEmitter) {
38+
(0, _inherits2["default"])(RuntimeModule, _EventEmitter);
39+
40+
var _super = _createSuper(RuntimeModule);
41+
42+
function RuntimeModule(moduleApi) {
43+
var _this;
44+
45+
(0, _classCallCheck2["default"])(this, RuntimeModule);
46+
_this = _super.call(this);
47+
_this.moduleApi = moduleApi;
48+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "extensions", void 0);
49+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "moduleName", RuntimeModule.name);
50+
return _this;
51+
}
52+
/**
53+
* Run a string through the translation engine. Shortcut to ModuleApi#translateString().
54+
* @param s The string.
55+
* @param variables The variables, if any.
56+
* @returns The translated string.
57+
* @protected
58+
*/
59+
60+
61+
(0, _createClass2["default"])(RuntimeModule, [{
62+
key: "t",
63+
value: function t(s, variables) {
64+
return this.moduleApi.translateString(s, variables);
65+
}
66+
}]);
67+
return RuntimeModule;
68+
}(_events.EventEmitter);
69+
70+
exports.RuntimeModule = RuntimeModule;

lib/components/DialogContent.d.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import * as React from "react";
2+
import { ModuleApi } from "../ModuleApi";
3+
import { PlainSubstitution } from "../types/translations";
4+
import { ModuleUiDialogOptions } from "../types/ModuleUiDialogOptions";
5+
/** React properties for dialog content implementations based on {@link DialogContent} */
6+
export interface DialogProps {
7+
/**
8+
* A reference to the active Module API.
9+
*/
10+
moduleApi: ModuleApi;
11+
/**
12+
* Callback to update the dialog options.
13+
*
14+
* Dialog content implementations can call this to update any of the options that were
15+
* originally set via {@link ModuleApi.openDialog}.
16+
*
17+
* @param options - The updates that should be applied to the dialog options. Any properties
18+
* not set in the {@link options} are left unchanged.
19+
*/
20+
setOptions(options: Partial<ModuleUiDialogOptions>): void;
21+
/**
22+
* Cancel the dialog programmatically.
23+
*/
24+
cancel(): void;
25+
}
26+
/** State of {@link DialogContent} */
27+
export interface DialogState {
28+
busy: boolean;
29+
error?: string;
30+
}
31+
/**
32+
* Base class for the content of a Dialog.
33+
*
34+
* The `body` callback passed to {@link ModuleApi.openDialog} should return an instance of a
35+
* class based on this.
36+
*/
37+
export declare abstract class DialogContent<P extends DialogProps = DialogProps, S extends DialogState = DialogState, M extends object = {}> extends React.PureComponent<P, S> {
38+
protected constructor(props: P, state?: S);
39+
/**
40+
* Run a string through the translation engine. Shortcut to ModuleApi#translateString().
41+
* @param s The string.
42+
* @param variables The variables, if any.
43+
* @returns The translated string.
44+
* @protected
45+
*/
46+
protected t(s: string, variables?: Record<string, PlainSubstitution>): string;
47+
/**
48+
* Called when the dialog is submitted. Note that calling this will not submit the
49+
* dialog by default - this component will be wrapped in a form which handles keyboard
50+
* submission and buttons on its own.
51+
*
52+
* If the returned promise resolves then the dialog will be closed, otherwise the dialog
53+
* will stay open.
54+
*/
55+
abstract trySubmit(): Promise<M>;
56+
}

lib/components/DialogContent.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
"use strict";
2+
3+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4+
5+
var _typeof = require("@babel/runtime/helpers/typeof");
6+
7+
Object.defineProperty(exports, "__esModule", {
8+
value: true
9+
});
10+
exports.DialogContent = void 0;
11+
12+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13+
14+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15+
16+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17+
18+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
19+
20+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
21+
22+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
23+
24+
var React = _interopRequireWildcard(require("react"));
25+
26+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27+
28+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29+
30+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
31+
32+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
33+
34+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
35+
36+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
37+
38+
/**
39+
* Base class for the content of a Dialog.
40+
*
41+
* The `body` callback passed to {@link ModuleApi.openDialog} should return an instance of a
42+
* class based on this.
43+
*/
44+
var DialogContent = /*#__PURE__*/function (_React$PureComponent) {
45+
(0, _inherits2["default"])(DialogContent, _React$PureComponent);
46+
47+
var _super = _createSuper(DialogContent);
48+
49+
function DialogContent(props, state) {
50+
var _this;
51+
52+
(0, _classCallCheck2["default"])(this, DialogContent);
53+
_this = _super.call(this, props);
54+
_this.state = _objectSpread({
55+
busy: false
56+
}, state);
57+
return _this;
58+
}
59+
/**
60+
* Run a string through the translation engine. Shortcut to ModuleApi#translateString().
61+
* @param s The string.
62+
* @param variables The variables, if any.
63+
* @returns The translated string.
64+
* @protected
65+
*/
66+
67+
68+
(0, _createClass2["default"])(DialogContent, [{
69+
key: "t",
70+
value: function t(s, variables) {
71+
return this.props.moduleApi.translateString(s, variables);
72+
}
73+
/**
74+
* Called when the dialog is submitted. Note that calling this will not submit the
75+
* dialog by default - this component will be wrapped in a form which handles keyboard
76+
* submission and buttons on its own.
77+
*
78+
* If the returned promise resolves then the dialog will be closed, otherwise the dialog
79+
* will stay open.
80+
*/
81+
82+
}]);
83+
return DialogContent;
84+
}(React.PureComponent);
85+
86+
exports.DialogContent = DialogContent;

lib/components/Spinner.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as React from "react";
2+
export declare class Spinner extends React.PureComponent {
3+
/**
4+
* The factory this component uses to render itself. Set to a different value to override.
5+
* @returns The component, rendered.
6+
*/
7+
static renderFactory: () => React.ReactNode;
8+
render(): React.ReactNode;
9+
}

0 commit comments

Comments
 (0)