mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-04-03 12:55:39 +00:00
Stop declaring typescript JSX config as global. (#455)
This commit is contained in:
@@ -8,7 +8,7 @@ import { BaseFunction, defineInterfaceCommand } from '../../commands/interface-m
|
||||
import { findPresentationType, parameters } from '../../commands/interface-manager/ParameterParsing';
|
||||
import { AppserviceBaseExecutor } from './AppserviceCommandHandler';
|
||||
import { tickCrossRenderer } from '../../commands/interface-manager/MatrixHelpRenderer';
|
||||
import { JSXFactory } from '../../commands/interface-manager/JSXFactory';
|
||||
import { DeadDocumentJSX } from '../../commands/interface-manager/JSXFactory';
|
||||
import { renderMatrixAndSend } from '../../commands/interface-manager/DeadDocumentMatrix';
|
||||
import { ActionError, ActionResult, isError, Ok, UserID } from 'matrix-protection-suite';
|
||||
import { MatrixSendClient } from 'matrix-protection-suite-for-matrix-bot-sdk';
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
import { ActionError, ActionException, ActionResult, DescriptionMeta, MatrixRoomReference, ResultForUsersInRoom, RoomSetResult, StringRoomID, StringUserID, isOk } from "matrix-protection-suite";
|
||||
import { DocumentNode } from "../commands/interface-manager/DeadDocument";
|
||||
import { JSXFactory } from "../commands/interface-manager/JSXFactory";
|
||||
import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory";
|
||||
import { renderMentionPill, renderRoomPill } from "../commands/interface-manager/MatrixHelpRenderer";
|
||||
|
||||
export function renderElaborationTrail(error: ActionError): DocumentNode {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { RendererMessage, RendererMessageCollector } from "./RendererMessageColl
|
||||
import { DescriptionMeta, StringRoomID, Task } from "matrix-protection-suite";
|
||||
import { DocumentNode } from "../commands/interface-manager/DeadDocument";
|
||||
import { renderMatrixAndSend } from "../commands/interface-manager/DeadDocumentMatrix";
|
||||
import { JSXFactory } from "../commands/interface-manager/JSXFactory";
|
||||
import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory";
|
||||
|
||||
export class DraupnirRendererMessageCollector implements RendererMessageCollector {
|
||||
constructor(
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
import { ActionResult, Capability, DescriptionMeta, Ok, Permalinks, PolicyListRevision, RoomSetResult, ServerACLConsequencesContext, ServerConsequences, StringRoomID, describeCapabilityContextGlue, describeCapabilityRenderer, isError } from "matrix-protection-suite";
|
||||
import { RendererMessageCollector } from "./RendererMessageCollector";
|
||||
import { renderFailedSingularConsequence, renderRoomSetResult } from "./CommonRenderers";
|
||||
import { JSXFactory } from "../commands/interface-manager/JSXFactory";
|
||||
import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory";
|
||||
import { Draupnir } from "../Draupnir";
|
||||
|
||||
class StandardServerConsequencesRenderer implements ServerConsequences {
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
import { ActionResult, Capability, DescriptionMeta, EventConsequences, Permalinks, RoomEventRedacter, StringEventID, StringRoomID, describeCapabilityContextGlue, describeCapabilityRenderer, isError } from "matrix-protection-suite";
|
||||
import { RendererMessageCollector } from "./RendererMessageCollector";
|
||||
import { renderFailedSingularConsequence } from "./CommonRenderers";
|
||||
import { JSXFactory } from "../commands/interface-manager/JSXFactory";
|
||||
import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory";
|
||||
import { Draupnir } from "../Draupnir";
|
||||
|
||||
class StandardEventConsequencesRenderer implements EventConsequences {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
// https://github.com/matrix-org/mjolnir
|
||||
// </text>
|
||||
|
||||
import { JSXFactory } from "../commands/interface-manager/JSXFactory";
|
||||
import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory";
|
||||
import { ActionResult, Capability, DescriptionMeta, MatrixRoomReference, Ok, Permalinks, PolicyListRevision, ResultForUsersInRoom, ResultForUsersInSet, RoomSetResult, StandardUserConsequencesContext, StringRoomID, StringUserID, UserConsequences, describeCapabilityContextGlue, describeCapabilityRenderer, isError } from "matrix-protection-suite";
|
||||
import { RendererMessageCollector } from "./RendererMessageCollector";
|
||||
import { renderFailedSingularConsequence, renderOutcome, renderResultForUsersInRoom, renderRoomSetResult } from "./CommonRenderers";
|
||||
|
||||
@@ -28,7 +28,7 @@ limitations under the License.
|
||||
import { DocumentNode } from "./interface-manager/DeadDocument";
|
||||
import { CommandTable, defineInterfaceCommand, findCommandTable, findTableCommand } from "./interface-manager/InterfaceCommand";
|
||||
import { renderCommandSummary } from "./interface-manager/MatrixHelpRenderer";
|
||||
import { JSXFactory } from "./interface-manager/JSXFactory";
|
||||
import { DeadDocumentJSX } from "./interface-manager/JSXFactory";
|
||||
import { findPresentationType, parameters, RestDescription } from "./interface-manager/ParameterParsing";
|
||||
import { defineMatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfaceAdaptor";
|
||||
import { renderMatrixAndSend } from "./interface-manager/DeadDocumentMatrix";
|
||||
|
||||
@@ -31,7 +31,7 @@ import { ActionError, ActionResult, MatrixRoomReference, Ok, StringRoomID, Strin
|
||||
import { KeywordsDescription, ParsedKeywords, findPresentationType, parameters } from "./interface-manager/ParameterParsing";
|
||||
import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk";
|
||||
import { DocumentNode } from "./interface-manager/DeadDocument";
|
||||
import { JSXFactory } from "./interface-manager/JSXFactory";
|
||||
import { DeadDocumentJSX } from "./interface-manager/JSXFactory";
|
||||
import { defineInterfaceCommand, findTableCommand } from "./interface-manager/InterfaceCommand";
|
||||
import { defineMatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfaceAdaptor";
|
||||
import { renderMatrixAndSend } from "./interface-manager/DeadDocumentMatrix";
|
||||
|
||||
@@ -33,7 +33,7 @@ import { defineMatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfac
|
||||
import { tickCrossRenderer } from "./interface-manager/MatrixHelpRenderer";
|
||||
import { Draupnir } from "../Draupnir";
|
||||
import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk";
|
||||
import { JSXFactory } from "./interface-manager/JSXFactory";
|
||||
import { DeadDocumentJSX } from "./interface-manager/JSXFactory";
|
||||
import { DocumentNode } from "./interface-manager/DeadDocument";
|
||||
import { renderMatrixAndSend } from "./interface-manager/DeadDocumentMatrix";
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import { ParsedKeywords, findPresentationType, parameters } from "./interface-ma
|
||||
import { defineMatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfaceAdaptor";
|
||||
import { renderRoomPill, tickCrossRenderer } from "./interface-manager/MatrixHelpRenderer";
|
||||
import { renderMatrixAndSend } from "./interface-manager/DeadDocumentMatrix";
|
||||
import { JSXFactory } from "./interface-manager/JSXFactory";
|
||||
import { DeadDocumentJSX } from "./interface-manager/JSXFactory";
|
||||
|
||||
async function resolveAliasCommand(
|
||||
this: DraupnirContext,
|
||||
|
||||
@@ -31,7 +31,7 @@ import { DraupnirContext } from "./CommandHandler";
|
||||
import { defineMatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfaceAdaptor";
|
||||
import { tickCrossRenderer } from "./interface-manager/MatrixHelpRenderer";
|
||||
import { DocumentNode } from "./interface-manager/DeadDocument";
|
||||
import { JSXFactory } from "./interface-manager/JSXFactory";
|
||||
import { DeadDocumentJSX } from "./interface-manager/JSXFactory";
|
||||
import { renderMatrixAndSend } from "./interface-manager/DeadDocumentMatrix";
|
||||
import { ActionException, ActionExceptionKind, ActionResult, MatrixRoomID, MatrixRoomReference, Ok, isError } from "matrix-protection-suite";
|
||||
import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk";
|
||||
|
||||
@@ -29,7 +29,7 @@ import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk";
|
||||
import { DraupnirContext } from "./CommandHandler";
|
||||
import { renderMatrixAndSend } from "./interface-manager/DeadDocumentMatrix";
|
||||
import { defineInterfaceCommand, findTableCommand } from "./interface-manager/InterfaceCommand";
|
||||
import { JSXFactory } from "./interface-manager/JSXFactory";
|
||||
import { DeadDocumentJSX } from "./interface-manager/JSXFactory";
|
||||
import { tickCrossRenderer } from "./interface-manager/MatrixHelpRenderer";
|
||||
import { defineMatrixInterfaceAdaptor, MatrixContext, MatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfaceAdaptor";
|
||||
import { findPresentationType, parameters, union } from "./interface-manager/ParameterParsing";
|
||||
|
||||
@@ -30,7 +30,7 @@ import { defineInterfaceCommand, findTableCommand } from "./interface-manager/In
|
||||
import { parameters } from "./interface-manager/ParameterParsing";
|
||||
import { DraupnirContext } from "./CommandHandler";
|
||||
import { defineMatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfaceAdaptor";
|
||||
import { JSXFactory } from "./interface-manager/JSXFactory";
|
||||
import { DeadDocumentJSX } from "./interface-manager/JSXFactory";
|
||||
import { tickCrossRenderer } from "./interface-manager/MatrixHelpRenderer";
|
||||
import { renderMatrixAndSend } from "./interface-manager/DeadDocumentMatrix";
|
||||
import { ActionResult, Ok, PolicyRoomRevision, PolicyRoomWatchProfile, PolicyRuleType, isError } from "matrix-protection-suite";
|
||||
|
||||
@@ -7,36 +7,6 @@ import { DocumentNode, LeafNode, makeDocumentNode, makeLeafNode, NodeTag, TextNo
|
||||
import { DeadDocumentPresentationMirror } from "./DeadDocumentPresentation";
|
||||
|
||||
type JSXChild = DocumentNode|LeafNode|string|number|JSXChild[];
|
||||
|
||||
export function JSXFactory(tag: NodeTag, properties: unknown, ...rawChildren: (DocumentNode|LeafNode|string)[]) {
|
||||
const node = makeDocumentNode(tag);
|
||||
if (properties) {
|
||||
for (const [key, value] of Object.entries(properties)) {
|
||||
node.attributeMap.set(key, value);
|
||||
}
|
||||
}
|
||||
const ensureChild = (rawChild: JSXChild) => {
|
||||
if (typeof rawChild === 'string') {
|
||||
makeLeafNode<TextNode>(NodeTag.TextNode, node, rawChild);
|
||||
} else if (typeof rawChild === 'number') {
|
||||
makeLeafNode<TextNode>(NodeTag.TextNode, node, (rawChild as number).toString());
|
||||
} else if (Array.isArray(rawChild)) {
|
||||
rawChild.forEach(ensureChild);
|
||||
// Then it's a DocumentNode|LeafNode
|
||||
} else if (typeof rawChild.leafNode === 'boolean') {
|
||||
if (rawChild.tag === NodeTag.Fragment) {
|
||||
(rawChild as DocumentNode).getChildren().forEach(node.addChild, node);
|
||||
} else {
|
||||
node.addChild(rawChild);
|
||||
}
|
||||
} else {
|
||||
node.addChild(DeadDocumentPresentationMirror.present(rawChild));
|
||||
}
|
||||
}
|
||||
rawChildren.forEach(ensureChild);
|
||||
return node;
|
||||
}
|
||||
|
||||
// TODO: For `children?` to work without allowing people to accidentally use
|
||||
// `{undefined}` then we need to enable:
|
||||
// https://www.typescriptlang.org/tsconfig/#exactOptionalPropertyTypes
|
||||
@@ -47,12 +17,35 @@ export function JSXFactory(tag: NodeTag, properties: unknown, ...rawChildren: (D
|
||||
type NodeProperties = { children?: JSXChild[]|JSXChild };
|
||||
type LeafNodeProperties = { children?: never[] };
|
||||
|
||||
/**
|
||||
* Has to be global for some reason or VSCodium explodes.
|
||||
* https://www.typescriptlang.org/docs/handbook/declaration-merging.html
|
||||
* https://www.typescriptlang.org/tsconfig#jsxFactory
|
||||
*/
|
||||
declare global {
|
||||
export namespace DeadDocumentJSX {
|
||||
export function JSXFactory(tag: NodeTag, properties: unknown, ...rawChildren: (DocumentNode|LeafNode|string)[]) {
|
||||
const node = makeDocumentNode(tag);
|
||||
if (properties) {
|
||||
for (const [key, value] of Object.entries(properties)) {
|
||||
node.attributeMap.set(key, value);
|
||||
}
|
||||
}
|
||||
const ensureChild = (rawChild: JSXChild) => {
|
||||
if (typeof rawChild === 'string') {
|
||||
makeLeafNode<TextNode>(NodeTag.TextNode, node, rawChild);
|
||||
} else if (typeof rawChild === 'number') {
|
||||
makeLeafNode<TextNode>(NodeTag.TextNode, node, (rawChild as number).toString());
|
||||
} else if (Array.isArray(rawChild)) {
|
||||
rawChild.forEach(ensureChild);
|
||||
// Then it's a DocumentNode|LeafNode
|
||||
} else if (typeof rawChild.leafNode === 'boolean') {
|
||||
if (rawChild.tag === NodeTag.Fragment) {
|
||||
(rawChild as DocumentNode).getChildren().forEach(node.addChild, node);
|
||||
} else {
|
||||
node.addChild(rawChild);
|
||||
}
|
||||
} else {
|
||||
node.addChild(DeadDocumentPresentationMirror.present(rawChild));
|
||||
}
|
||||
}
|
||||
rawChildren.forEach(ensureChild);
|
||||
return node;
|
||||
}
|
||||
export namespace JSX {
|
||||
export interface IntrinsicElements {
|
||||
a: NodeProperties & { href?: string, name?: string, target?: string },
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { BaseFunction, CommandTable, InterfaceCommand } from "./InterfaceCommand";
|
||||
import { MatrixContext, MatrixInterfaceAdaptor, RendererSignature } from "./MatrixInterfaceAdaptor";
|
||||
import { ArgumentParseError, ParameterDescription, RestDescription } from "./ParameterParsing";
|
||||
import { JSXFactory } from "./JSXFactory";
|
||||
import { DeadDocumentJSX } from "./JSXFactory";
|
||||
import { DocumentNode } from "./DeadDocument";
|
||||
import { renderMatrixAndSend } from "./DeadDocumentMatrix";
|
||||
import { LogService } from "matrix-bot-sdk";
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import { ReadItem } from "./CommandReader";
|
||||
import { findPresentationType, makePresentationType, simpleTypeValidator } from "./ParameterParsing";
|
||||
import { definePresentationRenderer } from "./DeadDocumentPresentation";
|
||||
import { JSXFactory } from "./JSXFactory";
|
||||
import { DeadDocumentJSX } from "./JSXFactory";
|
||||
import { DocumentNode } from "./DeadDocument";
|
||||
import { MatrixEventViaAlias, MatrixEventViaRoomID, MatrixRoomAlias, MatrixRoomID, MatrixRoomReference, UserID } from "matrix-protection-suite";
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import { ClientPlatform, Logger, RoomEvent, StringRoomID, Task, Value, isError } from "matrix-protection-suite";
|
||||
import { renderMatrixAndSend } from "./DeadDocumentMatrix";
|
||||
import { BaseFunction, CommandTable, InterfaceCommand } from "./InterfaceCommand";
|
||||
import { JSXFactory } from "./JSXFactory";
|
||||
import { DeadDocumentJSX } from "./JSXFactory";
|
||||
import { MatrixContext, findMatrixInterfaceAdaptor } from "./MatrixInterfaceAdaptor";
|
||||
import { ArgumentStream, ParameterDescription } from "./ParameterParsing";
|
||||
import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk";
|
||||
|
||||
@@ -27,7 +27,7 @@ limitations under the License.
|
||||
|
||||
import { DocumentNode } from "../commands/interface-manager/DeadDocument";
|
||||
import { renderMatrixAndSend } from "../commands/interface-manager/DeadDocumentMatrix";
|
||||
import { JSXFactory } from "../commands/interface-manager/JSXFactory";
|
||||
import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory";
|
||||
import { ActionException, ActionExceptionKind, ActionResult, Ok, RoomUpdateError, StringRoomID } from "matrix-protection-suite";
|
||||
import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk";
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ limitations under the License.
|
||||
* a Mjolnir PR that was originally created by Gergő Fándly https://github.com/matrix-org/mjolnir/pull/223
|
||||
*/
|
||||
|
||||
import { JSXFactory } from "../commands/interface-manager/JSXFactory";
|
||||
import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory";
|
||||
import { renderMatrixAndSend } from "../commands/interface-manager/DeadDocumentMatrix";
|
||||
import { renderMentionPill, renderRoomPill } from "../commands/interface-manager/MatrixHelpRenderer";
|
||||
import { ListMatches, renderListRules } from "../commands/Rules";
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { HandleMissingProtectionPermissions, MatrixRoomReference, ProtectionPermissionsChange, StringRoomID, Task } from "matrix-protection-suite";
|
||||
import { renderMatrixAndSend } from "../commands/interface-manager/DeadDocumentMatrix";
|
||||
import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk";
|
||||
import { JSXFactory } from "../commands/interface-manager/JSXFactory";
|
||||
import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory";
|
||||
import { DocumentNode } from "../commands/interface-manager/DeadDocument";
|
||||
import { renderRoomPill } from "../commands/interface-manager/MatrixHelpRenderer";
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import { AbstractProtection, ActionResult, Logger, MatrixRoomReference, Ok, Poli
|
||||
import { DraupnirProtection } from "./Protection";
|
||||
import { Draupnir } from "../Draupnir";
|
||||
import { DocumentNode } from "../commands/interface-manager/DeadDocument";
|
||||
import { JSXFactory } from "../commands/interface-manager/JSXFactory";
|
||||
import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory";
|
||||
import { renderMentionPill, renderRoomPill } from "../commands/interface-manager/MatrixHelpRenderer";
|
||||
import { renderMatrixAndSend } from "../commands/interface-manager/DeadDocumentMatrix";
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
import { ActionError, ProtectionDescription, StringRoomID } from "matrix-protection-suite";
|
||||
import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk";
|
||||
import { renderMatrixAndSend } from "../commands/interface-manager/DeadDocumentMatrix";
|
||||
import { JSXFactory } from "../commands/interface-manager/JSXFactory";
|
||||
import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory";
|
||||
|
||||
export async function renderProtectionFailedToStart(
|
||||
client: MatrixSendClient,
|
||||
|
||||
@@ -14,7 +14,7 @@ import { DraupnirProtection } from "../Protection";
|
||||
import { isInvitationForUser, isSenderJoinedInRevision } from "./inviteCore";
|
||||
import { renderMatrixAndSend } from "../../commands/interface-manager/DeadDocumentMatrix";
|
||||
import { DocumentNode } from "../../commands/interface-manager/DeadDocument";
|
||||
import { JSXFactory } from "../../commands/interface-manager/JSXFactory";
|
||||
import { DeadDocumentJSX } from "../../commands/interface-manager/JSXFactory";
|
||||
import { renderMentionPill, renderRoomPill } from "../../commands/interface-manager/MatrixHelpRenderer";
|
||||
import { renderFailedSingularConsequence } from "../../capabilities/CommonRenderers";
|
||||
import { ProtectroomsOnInvite } from "./ProtectRoomsOnInvite";
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
import { Logger, MatrixRoomID, MembershipEvent, Ok, Permalink, ProtectedRoomsSet, RoomEvent, Task, Value, isError } from "matrix-protection-suite";
|
||||
import { DocumentNode } from "../../commands/interface-manager/DeadDocument";
|
||||
import { renderActionResultToEvent, renderMentionPill, renderRoomPill } from "../../commands/interface-manager/MatrixHelpRenderer";
|
||||
import { JSXFactory } from "../../commands/interface-manager/JSXFactory";
|
||||
import { DeadDocumentJSX } from "../../commands/interface-manager/JSXFactory";
|
||||
import { renderMatrixAndSend } from "../../commands/interface-manager/DeadDocumentMatrix";
|
||||
import { StaticDecode, Type } from "@sinclair/typebox";
|
||||
import { Draupnir } from "../../Draupnir";
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
import { ALL_RULE_TYPES, Logger, MJOLNIR_SHORTCODE_EVENT_TYPE, MatrixRoomID, MembershipEvent, Ok, Permalink, ProtectedRoomsSet, RoomEvent, RoomStateRevision, Task, Value, isError } from "matrix-protection-suite";
|
||||
import { Draupnir } from "../../Draupnir";
|
||||
import { DocumentNode } from "../../commands/interface-manager/DeadDocument";
|
||||
import { JSXFactory } from "../../commands/interface-manager/JSXFactory";
|
||||
import { DeadDocumentJSX } from "../../commands/interface-manager/JSXFactory";
|
||||
import { renderActionResultToEvent, renderMentionPill, renderRoomPill } from "../../commands/interface-manager/MatrixHelpRenderer";
|
||||
import { renderMatrixAndSend } from "../../commands/interface-manager/DeadDocumentMatrix";
|
||||
import { StaticDecode, Type } from "@sinclair/typebox";
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
"mocha"
|
||||
],
|
||||
"jsx": "react",
|
||||
"jsxFactory": "JSXFactory"
|
||||
"jsxFactory": "DeadDocumentJSX.JSXFactory"
|
||||
},
|
||||
"include": [
|
||||
"./src/**/*"
|
||||
|
||||
Reference in New Issue
Block a user