mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 17:11:17 -08:00
Migrate to oxlint and oxfmt (#696)
<!-- Please read https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before submitting your pull request --> ### Description Migrates from eslint and prettier to oxlint and oxfmt + some rule hardening and - some rules that don't exist in oxlint, but I decided it probably wasn't worth running both in parallel just for a few rules. Notably, got rid of many "as any"s and swapped to .toSorted() for safer stuff and "type" in imports. Added comments to all the existing lint issues (console logging and the alert for app updates) and the few places "as any" was justified (test cases) and some message object whatnots. Also notably, fmt now takes a second or two, and linting now takes no more than a few seconds. Yay! Recommended vscode plugins, workflows, and configs should all be updated assuming I didn't miss anything. <!-- Please include a summary of the change. Please also include relevant motivation and context. List any dependencies that are required for this change. --> #### Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [x] Breaking change - breaking I guess since not all rules exist? I don't really know exactly what I uh... didn't include. - [ ] This change requires a documentation update ### Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings ### AI disclosure: - [x] Partially AI assisted (clarify which code was AI assisted and briefly explain what it does). - [ ] Fully AI generated (explain what all the generated code does in moderate detail). <!-- Write any explanation required here, but do not generate the explanation using AI!! You must prove you understand what the code in this PR does. --> I deployed a swarm of silly AIs to fix many of the simpler as any casts and subsequent typechecks because there were hundreds and I'm not doing that manually :p. I did review it, mostly just seamless swapping to the correct cast type instead of as any, nothing particularly complicated.
This commit is contained in:
616 files changed
+5536
-5874
No files matched your search
@@ -1,8 +0,0 @@
|
||||
dist
|
||||
node_modules
|
||||
package.json
|
||||
pnpm-lock.yaml
|
||||
LICENSE
|
||||
README.md
|
||||
CHANGELOG.md
|
||||
./changeset
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"printWidth": 100,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "es5"
|
||||
}
|
||||
Vendored
+1
-1
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "webpro.vscode-knip"]
|
||||
"recommendations": ["webpro.vscode-knip", "oxc.oxc-vscode"]
|
||||
}
|
||||
Vendored
+8
-3
@@ -1,11 +1,16 @@
|
||||
{
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.oxc": "always"
|
||||
},
|
||||
"editor.formatOnSave": true,
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.defaultFormatter": "oxc.oxc-vscode",
|
||||
"oxc.fmt.configPath": "oxfmt.config.ts",
|
||||
"oxc.typeAware": true,
|
||||
"typescript.tsdk": "node_modules/typescript/lib",
|
||||
"[jsonc]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
"editor.defaultFormatter": "oxc.oxc-vscode"
|
||||
},
|
||||
"[json]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
"editor.defaultFormatter": "oxc.oxc-vscode"
|
||||
}
|
||||
}
|
||||
@@ -1,143 +0,0 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import { includeIgnoreFile } from '@eslint/compat';
|
||||
import js from '@eslint/js';
|
||||
import { defineConfig } from 'eslint/config';
|
||||
import { configs, helpers, plugins } from 'eslint-config-airbnb-extended';
|
||||
import { rules as prettierConfigRules } from 'eslint-config-prettier';
|
||||
import prettierPlugin from 'eslint-plugin-prettier';
|
||||
import reactPlugin from 'eslint-plugin-react';
|
||||
import globals from 'globals';
|
||||
|
||||
const gitignorePath = path.resolve('.', '.gitignore');
|
||||
const { jsFiles, tsFiles } = helpers.extensions;
|
||||
|
||||
const jsConfig = defineConfig([
|
||||
// ESLint recommended config
|
||||
{
|
||||
name: 'js/config',
|
||||
...js.configs.recommended,
|
||||
},
|
||||
// Stylistic plugin
|
||||
plugins.stylistic,
|
||||
// Import X plugin
|
||||
plugins.importX,
|
||||
// Airbnb base recommended config
|
||||
...configs.base.recommended,
|
||||
]);
|
||||
|
||||
const reactConfig = defineConfig([
|
||||
// React plugin
|
||||
plugins.react,
|
||||
// React hooks plugin
|
||||
plugins.reactHooks,
|
||||
// React JSX A11y plugin
|
||||
plugins.reactA11y,
|
||||
// Airbnb React recommended config
|
||||
...configs.react.recommended,
|
||||
// React 17+ automatic JSX runtime
|
||||
reactPlugin.configs.flat['jsx-runtime'],
|
||||
]);
|
||||
|
||||
const typescriptConfig = defineConfig([
|
||||
// TypeScript ESLint plugin
|
||||
plugins.typescriptEslint,
|
||||
// Airbnb base TypeScript config
|
||||
...configs.base.typescript,
|
||||
// Airbnb React TypeScript config
|
||||
...configs.react.typescript,
|
||||
]);
|
||||
|
||||
const prettierConfig = defineConfig([
|
||||
// Prettier plugin
|
||||
{
|
||||
name: 'prettier/plugin/config',
|
||||
plugins: {
|
||||
prettier: prettierPlugin,
|
||||
},
|
||||
},
|
||||
// Prettier config
|
||||
{
|
||||
name: 'prettier/config',
|
||||
rules: {
|
||||
...prettierConfigRules,
|
||||
'prettier/prettier': 'error',
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
const projectOverrides = defineConfig([
|
||||
{
|
||||
name: 'project/rule-overrides',
|
||||
files: [...jsFiles, ...tsFiles],
|
||||
languageOptions: {
|
||||
globals: {
|
||||
JSX: 'readonly',
|
||||
...globals.browser,
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
'linebreak-style': 'off',
|
||||
'no-underscore-dangle': 'off',
|
||||
'no-shadow': 'off',
|
||||
'import-x/prefer-default-export': 'off',
|
||||
'import-x/extensions': 'off',
|
||||
'import-x/no-unresolved': 'off',
|
||||
'import-x/no-extraneous-dependencies': [
|
||||
'error',
|
||||
{
|
||||
devDependencies: true,
|
||||
optionalDependencies: false,
|
||||
peerDependencies: true,
|
||||
bundledDependencies: true,
|
||||
},
|
||||
],
|
||||
'react/no-unstable-nested-components': ['error', { allowAsProps: true }],
|
||||
'react/jsx-filename-extension': [
|
||||
'error',
|
||||
{
|
||||
extensions: ['.tsx', '.jsx'],
|
||||
},
|
||||
],
|
||||
// obsolete in a React 19
|
||||
'react/prop-types': 'off',
|
||||
'react/require-default-props': 'off',
|
||||
'react/jsx-props-no-spreading': 'off',
|
||||
'react-hooks/rules-of-hooks': 'error',
|
||||
'react-hooks/exhaustive-deps': 'error',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'project/typescript-rule-overrides',
|
||||
files: tsFiles,
|
||||
rules: {
|
||||
// disabled for now to get eslint to pass
|
||||
'@typescript-eslint/consistent-type-definitions': 'off',
|
||||
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
|
||||
'@typescript-eslint/only-throw-error': 'off',
|
||||
'@typescript-eslint/array-type': 'off',
|
||||
'@typescript-eslint/no-unused-vars': [
|
||||
'error',
|
||||
{
|
||||
args: 'after-used',
|
||||
enableAutofixRemoval: {
|
||||
imports: true,
|
||||
},
|
||||
ignoreRestSiblings: true,
|
||||
vars: 'all',
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/no-shadow': 'error',
|
||||
'no-undef': 'off',
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
export default defineConfig([
|
||||
includeIgnoreFile(gitignorePath),
|
||||
...jsConfig,
|
||||
...reactConfig,
|
||||
...typescriptConfig,
|
||||
...prettierConfig,
|
||||
...projectOverrides,
|
||||
]);
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"$schema": "https://unpkg.com/knip@5/schema.json",
|
||||
"entry": ["src/sw.ts", "scripts/normalize-imports.js"],
|
||||
"ignore": ["oxlint.config.ts", "oxfmt.config.ts"],
|
||||
"ignoreExportsUsedInFile": {
|
||||
"interface": true,
|
||||
"type": true
|
||||
@@ -8,8 +9,7 @@
|
||||
"ignoreDependencies": [
|
||||
"buffer",
|
||||
"@sableclient/sable-call-embedded",
|
||||
"@matrix-org/matrix-sdk-crypto-wasm",
|
||||
"@testing-library/user-event"
|
||||
"@matrix-org/matrix-sdk-crypto-wasm"
|
||||
],
|
||||
"ignoreBinaries": ["knope"],
|
||||
"rules": {
|
||||
|
||||
+8
-4
@@ -2,8 +2,12 @@
|
||||
versioned_files = ["package.json"]
|
||||
changelog = "CHANGELOG.md"
|
||||
extra_changelog_sections = [
|
||||
{ name = "Documentation", types = ["docs"] },
|
||||
{ name = "Notes", types = ["note"] },
|
||||
{ name = "Documentation", types = [
|
||||
"docs",
|
||||
] },
|
||||
{ name = "Notes", types = [
|
||||
"note",
|
||||
] },
|
||||
]
|
||||
# assets = "marker" // TODO: add this later once we have assets
|
||||
|
||||
@@ -64,6 +68,6 @@ repo = "Sable"
|
||||
[release_notes]
|
||||
# The <!-- commit:$commit_hash --> marker is used by prepare-release.yml
|
||||
change_templates = [
|
||||
"### $summary <!-- commit:$commit_hash -->\n\n$details",
|
||||
"* $summary <!-- commit:$commit_hash -->",
|
||||
"### $summary <!-- commit:$commit_hash -->\n\n$details",
|
||||
"* $summary <!-- commit:$commit_hash -->",
|
||||
]
|
||||
@@ -0,0 +1,18 @@
|
||||
import { defineConfig } from 'oxfmt';
|
||||
|
||||
export default defineConfig({
|
||||
printWidth: 100,
|
||||
tabWidth: 2,
|
||||
singleQuote: true,
|
||||
trailingComma: 'es5',
|
||||
ignorePatterns: [
|
||||
'dist',
|
||||
'node_modules',
|
||||
'package.json',
|
||||
'pnpm-lock.yaml',
|
||||
'LICENSE',
|
||||
'README.md',
|
||||
'CHANGELOG.md',
|
||||
'./changeset',
|
||||
],
|
||||
});
|
||||
@@ -0,0 +1,62 @@
|
||||
import { defineConfig } from 'oxlint';
|
||||
|
||||
export default defineConfig({
|
||||
options: {
|
||||
typeAware: true,
|
||||
},
|
||||
plugins: ['react', 'jsx-a11y', 'typescript', 'import', 'unicorn', 'oxc', 'vitest', 'promise'],
|
||||
categories: {
|
||||
correctness: 'error',
|
||||
suspicious: 'warn',
|
||||
perf: 'warn',
|
||||
style: 'off',
|
||||
},
|
||||
env: {
|
||||
browser: true,
|
||||
builtin: true,
|
||||
},
|
||||
rules: {
|
||||
'import/no-unassigned-import': 'off',
|
||||
'import/no-named-as-default': 'off',
|
||||
'import/no-named-as-default-member': 'off',
|
||||
'no-console': ['error', { allow: ['warn', 'error'] }],
|
||||
'react/react-in-jsx-scope': 'off',
|
||||
'react/jsx-filename-extension': ['error', { extensions: ['.tsx', '.jsx'] }],
|
||||
'react/rules-of-hooks': 'error',
|
||||
'react/exhaustive-deps': 'error',
|
||||
'react/iframe-missing-sandbox': 'off',
|
||||
'jsx-a11y/no-autofocus': 'off',
|
||||
'jsx-a11y/prefer-tag-over-role': 'off',
|
||||
'typescript/no-explicit-any': 'error',
|
||||
'typescript/consistent-type-imports': 'error',
|
||||
'typescript/only-throw-error': 'error',
|
||||
'typescript/no-unsafe-type-assertion': 'off',
|
||||
'typescript/no-floating-promises': 'off',
|
||||
'typescript/no-unnecessary-type-arguments': 'off',
|
||||
'oxc/no-map-spread': 'off',
|
||||
'promise/always-return': 'off',
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: ['**/*.ts', '**/*.tsx', '**/*.cts', '**/*.mts'],
|
||||
rules: {
|
||||
'typescript/no-unused-vars': [
|
||||
'error',
|
||||
{
|
||||
args: 'after-used',
|
||||
ignoreRestSiblings: true,
|
||||
vars: 'all',
|
||||
},
|
||||
],
|
||||
'typescript/no-shadow': 'error',
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['**/*.test.ts', '**/*.test.tsx'],
|
||||
rules: {
|
||||
'typescript/unbound-method': 'off',
|
||||
'typescript/no-unsafe-enum-comparison': 'off',
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
+7
-13
@@ -12,10 +12,10 @@
|
||||
"dev": "vite dev",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "eslint . --fix",
|
||||
"fmt": "prettier --write .",
|
||||
"fmt:check": "prettier --check .",
|
||||
"lint": "oxlint .",
|
||||
"lint:fix": "oxlint . --fix && oxfmt .",
|
||||
"fmt": "oxfmt .",
|
||||
"fmt:check": "oxfmt --check .",
|
||||
"typecheck": "tsc",
|
||||
"test": "vitest",
|
||||
"test:ui": "vitest --ui",
|
||||
@@ -57,7 +57,6 @@
|
||||
"dompurify": "^3.3.3",
|
||||
"emojibase": "^15.3.1",
|
||||
"emojibase-data": "^15.3.2",
|
||||
"eslint-plugin-react": "7.37.5",
|
||||
"eventemitter3": "^5.0.4",
|
||||
"file-saver": "^2.0.5",
|
||||
"focus-trap-react": "^10.3.1",
|
||||
@@ -96,8 +95,6 @@
|
||||
"devDependencies": {
|
||||
"@cloudflare/vite-plugin": "^1.26.0",
|
||||
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
|
||||
"@eslint/compat": "2.0.2",
|
||||
"@eslint/js": "9.39.3",
|
||||
"@rollup/plugin-inject": "^5.0.5",
|
||||
"@rollup/plugin-wasm": "^6.2.2",
|
||||
"@sableclient/sable-call-embedded": "v1.1.4",
|
||||
@@ -118,14 +115,11 @@
|
||||
"@vitest/ui": "^4.1.0",
|
||||
"buffer": "^6.0.3",
|
||||
"cloudflared": "^0.7.1",
|
||||
"eslint": "9.39.3",
|
||||
"eslint-config-airbnb-extended": "3.0.1",
|
||||
"eslint-config-prettier": "10.1.8",
|
||||
"eslint-plugin-prettier": "5.5.5",
|
||||
"globals": "17.3.0",
|
||||
"jsdom": "^29.0.0",
|
||||
"knip": "5.85.0",
|
||||
"prettier": "3.8.1",
|
||||
"oxfmt": "^0.45.0",
|
||||
"oxlint": "^1.60.0",
|
||||
"oxlint-tsgolint": "^0.21.0",
|
||||
"typescript": "^5.9.3",
|
||||
"vite": "^7.3.1",
|
||||
"vite-plugin-compression2": "2.5.0",
|
||||
|
||||
Generated
+496
-1676
File diff suppressed because it is too large.
Load diff
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
/* eslint-disable no-console */
|
||||
/* oxlint-disable no-console */
|
||||
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
@@ -212,7 +212,7 @@ function rewriteFileImports(filePath, sourceCode, aliases, projectRoot) {
|
||||
|
||||
const uniqueReplacements = Array.from(
|
||||
new Map(replacements.map((r) => [`${r.start}:${r.end}`, r])).values()
|
||||
).sort((a, b) => b.start - a.start);
|
||||
).toSorted((a, b) => b.start - a.start);
|
||||
|
||||
const updatedCode = uniqueReplacements.reduce(
|
||||
(code, replacement) =>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* eslint-disable no-console */
|
||||
/* oxlint-disable no-console */
|
||||
import process from 'node:process';
|
||||
|
||||
export const ANSI = {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { FormEventHandler, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import type { FormEventHandler } from 'react';
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Text,
|
||||
@@ -14,7 +15,7 @@ import {
|
||||
Scroll,
|
||||
config,
|
||||
} from 'folds';
|
||||
import { MatrixError } from '$types/matrix-sdk';
|
||||
import type { MatrixError } from '$types/matrix-sdk';
|
||||
import { Cursor } from '$plugins/text-area';
|
||||
import { syntaxErrorPosition } from '$utils/dom';
|
||||
import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ReactNode } from 'react';
|
||||
import { AuthDict, AuthType, IAuthData, UIAFlow } from '$types/matrix-sdk';
|
||||
import type { ReactNode } from 'react';
|
||||
import type { AuthDict, IAuthData, UIAFlow } from '$types/matrix-sdk';
|
||||
import { AuthType } from '$types/matrix-sdk';
|
||||
import { getUIAFlowForStages } from '$utils/matrix-uia';
|
||||
import { useSupportedUIAFlows, useUIACompleted, useUIAFlow } from '$hooks/useUIAFlows';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
@@ -34,7 +35,7 @@ export function ActionUIA({ authData, ongoingFlow, action, onCancel }: ActionUIA
|
||||
stepCount={ongoingFlow.stages.length}
|
||||
onCancel={onCancel}
|
||||
>
|
||||
{stageToComplete.type === AuthType.Password && (
|
||||
{stageToComplete.type === (AuthType.Password as string) && (
|
||||
<PasswordStage
|
||||
userId={mx.getUserId()!}
|
||||
stageData={stageToComplete}
|
||||
@@ -42,7 +43,7 @@ export function ActionUIA({ authData, ongoingFlow, action, onCancel }: ActionUIA
|
||||
submitAuthDict={action}
|
||||
/>
|
||||
)}
|
||||
{stageToComplete.type === AuthType.Sso && stageToComplete.session && (
|
||||
{stageToComplete.type === (AuthType.Sso as string) && stageToComplete.session && (
|
||||
<SSOStage
|
||||
ssoRedirectURL={mx.getFallbackAuthUrl(AuthType.Sso, stageToComplete.session)}
|
||||
stageData={stageToComplete}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import { ReactNode, useCallback, useEffect, useMemo } from 'react';
|
||||
import { MatrixError, createClient } from '$types/matrix-sdk';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useCallback, useEffect, useMemo } from 'react';
|
||||
import type { MatrixError } from '$types/matrix-sdk';
|
||||
import { createClient } from '$types/matrix-sdk';
|
||||
import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
|
||||
import { useAutoDiscoveryInfo } from '$hooks/useAutoDiscoveryInfo';
|
||||
import { promiseFulfilledResult, promiseRejectedResult } from '$utils/common';
|
||||
import {
|
||||
AuthFlows,
|
||||
RegisterFlowStatus,
|
||||
RegisterFlowsResponse,
|
||||
parseRegisterErrResp,
|
||||
} from '$hooks/useAuthFlows';
|
||||
import type { AuthFlows, RegisterFlowsResponse } from '$hooks/useAuthFlows';
|
||||
import { RegisterFlowStatus, parseRegisterErrResp } from '$hooks/useAuthFlows';
|
||||
|
||||
type AuthFlowsLoaderProps = {
|
||||
fallback?: () => ReactNode;
|
||||
@@ -26,7 +24,9 @@ export function AuthFlowsLoader({ fallback, error, children }: AuthFlowsLoaderPr
|
||||
const result = await Promise.allSettled([mx.loginFlows(), mx.registerRequest({})]);
|
||||
const loginFlows = promiseFulfilledResult(result[0]);
|
||||
const registerResp = promiseRejectedResult(result[1]) as MatrixError | undefined;
|
||||
let registerFlows: RegisterFlowsResponse = { status: RegisterFlowStatus.InvalidRequest };
|
||||
let registerFlows: RegisterFlowsResponse = {
|
||||
status: RegisterFlowStatus.InvalidRequest,
|
||||
};
|
||||
|
||||
if (typeof registerResp === 'object' && registerResp.httpStatus) {
|
||||
registerFlows = parseRegisterErrResp(registerResp);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ReactNode, useCallback } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useCallback } from 'react';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { matchPath, useLocation, useNavigate } from 'react-router-dom';
|
||||
import {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { MouseEventHandler, useCallback, useState } from 'react';
|
||||
import type { MouseEventHandler } from 'react';
|
||||
import { useCallback, useState } from 'react';
|
||||
import { useAtom } from 'jotai';
|
||||
import { CryptoApi, KeyBackupInfo } from '$types/matrix-sdk';
|
||||
import type { CryptoApi, KeyBackupInfo } from '$types/matrix-sdk';
|
||||
import type { RectCords } from 'folds';
|
||||
import {
|
||||
Badge,
|
||||
Box,
|
||||
@@ -14,7 +16,6 @@ import {
|
||||
percent,
|
||||
PopOut,
|
||||
ProgressBar,
|
||||
RectCords,
|
||||
Spinner,
|
||||
Text,
|
||||
} from 'folds';
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ReactNode, useCallback, useRef } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useCallback, useRef } from 'react';
|
||||
import { useAtomValue, useSetAtom } from 'jotai';
|
||||
import { useAutoJoinCall } from '$hooks/useAutoJoinCall';
|
||||
import {
|
||||
@@ -9,7 +10,8 @@ import {
|
||||
useCallThemeSync,
|
||||
useCallMemberSoundSync,
|
||||
} from '$hooks/useCallEmbed';
|
||||
import { CallEmbed, useClientWidgetApiEvent, ElementWidgetActions } from '$plugins/call';
|
||||
import type { CallEmbed } from '$plugins/call';
|
||||
import { useClientWidgetApiEvent, ElementWidgetActions } from '$plugins/call';
|
||||
import { callChatAtom, callEmbedAtom } from '$state/callEmbed';
|
||||
import { useSelectedRoom } from '$hooks/router/useSelectedRoom';
|
||||
import { ScreenSize, useScreenSizeContext } from '$hooks/useScreenSize';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ReactNode, useCallback, useEffect, useState } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
|
||||
import { ClientConfig } from '$hooks/useClientConfig';
|
||||
import type { ClientConfig } from '$hooks/useClientConfig';
|
||||
import { trimTrailingSlash } from '$utils/common';
|
||||
|
||||
const getClientConfig = async (): Promise<ClientConfig> => {
|
||||
|
||||
@@ -18,7 +18,7 @@ export function ClientSideHoverFreeze({
|
||||
img.crossOrigin = 'anonymous';
|
||||
img.src = src;
|
||||
|
||||
img.onload = () => {
|
||||
const handleLoad = () => {
|
||||
if (isMounted && canvasRef.current) {
|
||||
canvasRef.current.width = img.naturalWidth || img.width;
|
||||
canvasRef.current.height = img.naturalHeight || img.height;
|
||||
@@ -27,8 +27,10 @@ export function ClientSideHoverFreeze({
|
||||
setIsCanvasReady(true);
|
||||
}
|
||||
};
|
||||
img.addEventListener('load', handleLoad);
|
||||
return () => {
|
||||
isMounted = false;
|
||||
img.removeEventListener('load', handleLoad);
|
||||
};
|
||||
}, [src]);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ReactNode, RefObject, useCallback, useRef, useState } from 'react';
|
||||
import type { ReactNode, RefObject } from 'react';
|
||||
import { useCallback, useRef, useState } from 'react';
|
||||
import { useDebounce } from '$hooks/useDebounce';
|
||||
|
||||
type ConfirmPasswordMatchProps = {
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import {
|
||||
ShowSasCallbacks,
|
||||
VerificationPhase,
|
||||
VerificationRequest,
|
||||
Verifier,
|
||||
VerificationMethod,
|
||||
} from '$types/matrix-sdk';
|
||||
import { CSSProperties, useCallback, useEffect, useState } from 'react';
|
||||
import type { ShowSasCallbacks, VerificationRequest, Verifier } from '$types/matrix-sdk';
|
||||
import { VerificationPhase, VerificationMethod } from '$types/matrix-sdk';
|
||||
import type { CSSProperties } from 'react';
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
@@ -119,6 +115,15 @@ function AutoVerificationStart({ onStart }: VerificationStartProps) {
|
||||
|
||||
function CompareEmoji({ sasData }: { sasData: ShowSasCallbacks }) {
|
||||
const [confirmState, confirm] = useAsyncCallback(useCallback(() => sasData.confirm(), [sasData]));
|
||||
const emojiEntries = useMemo<{ id: string; emoji: string; name: string }[]>(
|
||||
() =>
|
||||
(sasData.sas.emoji ?? []).map(([emoji, name], index) => ({
|
||||
id: `emoji-${index}`,
|
||||
emoji,
|
||||
name,
|
||||
})),
|
||||
[sasData]
|
||||
);
|
||||
|
||||
const confirming =
|
||||
confirmState.status === AsyncStatus.Loading || confirmState.status === AsyncStatus.Success;
|
||||
@@ -136,15 +141,8 @@ function CompareEmoji({ sasData }: { sasData: ShowSasCallbacks }) {
|
||||
wrap="Wrap"
|
||||
justifyContent="Center"
|
||||
>
|
||||
{sasData.sas.emoji?.map(([emoji, name], index) => (
|
||||
<Box
|
||||
// eslint-disable-next-line react/no-array-index-key
|
||||
key={`${emoji}${name}${index}`}
|
||||
direction="Column"
|
||||
gap="100"
|
||||
justifyContent="Center"
|
||||
alignItems="Center"
|
||||
>
|
||||
{emojiEntries.map(({ id, emoji, name }) => (
|
||||
<Box key={id} direction="Column" gap="100" justifyContent="Center" alignItems="Center">
|
||||
<Text size="H1">{emoji}</Text>
|
||||
<Text size="T200">{name}</Text>
|
||||
</Box>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { FormEventHandler, forwardRef, useCallback, useState } from 'react';
|
||||
import type { FormEventHandler } from 'react';
|
||||
import { forwardRef, useCallback, useState } from 'react';
|
||||
import {
|
||||
Dialog,
|
||||
Header,
|
||||
@@ -15,7 +16,8 @@ import {
|
||||
} from 'folds';
|
||||
import FileSaver from 'file-saver';
|
||||
import to from 'await-to-js';
|
||||
import { AuthDict, IAuthData, MatrixError, UIAuthCallback } from '$types/matrix-sdk';
|
||||
import type { AuthDict, IAuthData, UIAuthCallback } from '$types/matrix-sdk';
|
||||
import { MatrixError } from '$types/matrix-sdk';
|
||||
import { clearSecretStorageKeys } from '$client/secretStorageKeys';
|
||||
import { ContainerColor } from '$styles/ContainerColor.css';
|
||||
import { copyToClipboard } from '$utils/dom';
|
||||
@@ -42,7 +44,7 @@ function makeUIAAction<T>(
|
||||
authData: IAuthData,
|
||||
performAction: PerformAction<T>,
|
||||
resolve: (data: T) => void,
|
||||
reject: (error?: any) => void
|
||||
reject: (error?: unknown) => void
|
||||
): UIAAction<T> {
|
||||
const action: UIAAction<T> = {
|
||||
authData,
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { ReactNode } from 'react';
|
||||
import { CryptoApi } from '$types/matrix-sdk';
|
||||
import {
|
||||
useDeviceVerificationStatus,
|
||||
VerificationStatus,
|
||||
} from '$hooks/useDeviceVerificationStatus';
|
||||
import type { ReactNode } from 'react';
|
||||
import type { CryptoApi } from '$types/matrix-sdk';
|
||||
import type { VerificationStatus } from '$hooks/useDeviceVerificationStatus';
|
||||
import { useDeviceVerificationStatus } from '$hooks/useDeviceVerificationStatus';
|
||||
|
||||
type DeviceVerificationStatusProps = {
|
||||
crypto?: CryptoApi;
|
||||
|
||||
@@ -21,7 +21,7 @@ import { HOME_ROOM_PATH, DIRECT_ROOM_PATH, SPACE_ROOM_PATH } from '$pages/paths'
|
||||
import { getCanonicalAliasOrRoomId } from '$utils/matrix';
|
||||
import { announce } from '$utils/announce';
|
||||
import { roomIdToReplyDraftAtomFamily } from '$state/room/roomInputDrafts';
|
||||
import { Room } from 'matrix-js-sdk';
|
||||
import type { Room } from '$types/matrix-sdk';
|
||||
|
||||
export function GlobalKeyboardShortcuts() {
|
||||
const navigate = useNavigate();
|
||||
@@ -63,6 +63,10 @@ export function GlobalKeyboardShortcuts() {
|
||||
const parents = roomToParents.get(roomId);
|
||||
if (parents && parents.size > 0) {
|
||||
const spaceId = Array.from(parents)[0];
|
||||
if (!spaceId) {
|
||||
navigate(getHomeRoomPath(roomIdOrAliasToNav));
|
||||
return;
|
||||
}
|
||||
const spaceIdOrAlias = getCanonicalAliasOrRoomId(mx, spaceId);
|
||||
navigate(getSpaceRoomPath(spaceIdOrAlias, roomIdOrAliasToNav));
|
||||
} else {
|
||||
@@ -82,11 +86,11 @@ export function GlobalKeyboardShortcuts() {
|
||||
if (!isKeyHotkey('alt+n', evt)) return;
|
||||
const unreadEntries = Array.from(roomToUnread.entries())
|
||||
.filter(([id, u]) => u.total > 0 && id !== currentRoom?.roomId)
|
||||
.sort((a, b) => b[1].highlight - a[1].highlight || b[1].total - a[1].total);
|
||||
.toSorted((a, b) => b[1].highlight - a[1].highlight || b[1].total - a[1].total);
|
||||
if (unreadEntries.length === 0) return;
|
||||
evt.preventDefault();
|
||||
unreadIndexRef.current = 0;
|
||||
const [roomId] = unreadEntries[0];
|
||||
const [roomId] = unreadEntries[0]!;
|
||||
navigateToRoom(roomId, unreadEntries.length - 1);
|
||||
},
|
||||
[roomToUnread, currentRoom?.roomId, navigateToRoom]
|
||||
@@ -100,7 +104,7 @@ export function GlobalKeyboardShortcuts() {
|
||||
if (!isDown && !isUp) return;
|
||||
const unreadEntries = Array.from(roomToUnread.entries())
|
||||
.filter(([, u]) => u.total > 0)
|
||||
.sort((a, b) => b[1].highlight - a[1].highlight || b[1].total - a[1].total);
|
||||
.toSorted((a, b) => b[1].highlight - a[1].highlight || b[1].total - a[1].total);
|
||||
if (unreadEntries.length === 0) return;
|
||||
evt.preventDefault();
|
||||
if (isDown) {
|
||||
@@ -109,7 +113,9 @@ export function GlobalKeyboardShortcuts() {
|
||||
unreadIndexRef.current =
|
||||
(unreadIndexRef.current - 1 + unreadEntries.length) % unreadEntries.length;
|
||||
}
|
||||
const [roomId] = unreadEntries[unreadIndexRef.current];
|
||||
const currentEntry = unreadEntries[unreadIndexRef.current];
|
||||
if (!currentEntry) return;
|
||||
const [roomId] = currentEntry;
|
||||
navigateToRoom(roomId, unreadEntries.length - 1);
|
||||
},
|
||||
[roomToUnread, navigateToRoom]
|
||||
@@ -137,6 +143,7 @@ export function GlobalKeyboardShortcuts() {
|
||||
const currentReplyIndex = events.findIndex((e) => e.event.event_id === replyDraft.eventId);
|
||||
if (currentReplyIndex === events.length - 1 && isDown) return; // you cant go further down than that idiot
|
||||
const newTargetEvent = isUp ? events[currentReplyIndex - 1] : events[currentReplyIndex + 1];
|
||||
if (!newTargetEvent) return;
|
||||
const eventId = newTargetEvent.event.event_id;
|
||||
if (eventId === undefined) return;
|
||||
setReplyDraft({ userId: currentRoom.myUserId, eventId, body: '' });
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { Box, Button, config, Menu, PopOut, RectCords, Text } from 'folds';
|
||||
import { MouseEventHandler, ReactNode, useState } from 'react';
|
||||
import type { RectCords } from 'folds';
|
||||
import { Box, Button, config, Menu, PopOut, Text } from 'folds';
|
||||
import type { MouseEventHandler, ReactNode } from 'react';
|
||||
import { useState } from 'react';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
|
||||
type HexColorPickerPopOutProps = {
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
OverlayCenter,
|
||||
OverlayBackdrop,
|
||||
} from 'folds';
|
||||
import type { Room } from '$types/matrix-sdk';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { useRoomName } from '$hooks/useRoomMeta';
|
||||
import { getRoomAvatarUrl } from '$utils/room';
|
||||
@@ -32,7 +33,7 @@ import { RoomAvatar } from './room-avatar';
|
||||
const debugLog = createDebugLogger('IncomingCall');
|
||||
|
||||
type IncomingCallInternalProps = {
|
||||
room: any;
|
||||
room: Room;
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,18 +1,7 @@
|
||||
import { MouseEventHandler, useCallback, useMemo, useState } from 'react';
|
||||
import {
|
||||
config,
|
||||
Box,
|
||||
MenuItem,
|
||||
Text,
|
||||
Icon,
|
||||
Icons,
|
||||
IconSrc,
|
||||
RectCords,
|
||||
PopOut,
|
||||
Menu,
|
||||
Button,
|
||||
Spinner,
|
||||
} from 'folds';
|
||||
import type { MouseEventHandler } from 'react';
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
import type { IconSrc, RectCords } from 'folds';
|
||||
import { config, Box, MenuItem, Text, Icon, Icons, PopOut, Menu, Button, Spinner } from 'folds';
|
||||
import { JoinRule } from '$types/matrix-sdk';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
|
||||
@@ -1,19 +1,9 @@
|
||||
import { MouseEventHandler, ReactNode, useCallback, useState } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Text,
|
||||
Chip,
|
||||
Icon,
|
||||
Icons,
|
||||
RectCords,
|
||||
PopOut,
|
||||
Menu,
|
||||
config,
|
||||
MenuItem,
|
||||
color,
|
||||
} from 'folds';
|
||||
import type { MouseEventHandler, ReactNode } from 'react';
|
||||
import { useCallback, useState } from 'react';
|
||||
import type { RectCords } from 'folds';
|
||||
import { Box, Text, Chip, Icon, Icons, PopOut, Menu, config, MenuItem, color } from 'folds';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { SecretStorageKeyContent } from '$types/matrix/accountData';
|
||||
import type { SecretStorageKeyContent } from '$types/matrix/accountData';
|
||||
import { storePrivateKey } from '$client/secretStorageKeys';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
|
||||
@@ -6,7 +6,7 @@ describe('Modal500', () => {
|
||||
it('does not throw when rendered without tabbable children', () => {
|
||||
expect(() =>
|
||||
render(
|
||||
<Modal500 requestClose={vi.fn()}>
|
||||
<Modal500 requestClose={vi.fn<() => void>()}>
|
||||
<div>Empty modal content</div>
|
||||
</Modal500>
|
||||
)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ReactNode, useRef } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useRef } from 'react';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { Modal, Overlay, OverlayBackdrop, OverlayCenter } from 'folds';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable no-param-reassign */
|
||||
|
||||
import { FormEventHandler, MouseEventHandler, useEffect, useRef, useState } from 'react';
|
||||
import type { FormEventHandler, MouseEventHandler } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import type { RectCords } from 'folds';
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
@@ -13,7 +13,6 @@ import {
|
||||
Input,
|
||||
Menu,
|
||||
PopOut,
|
||||
RectCords,
|
||||
Scroll,
|
||||
Spinner,
|
||||
Text,
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { memo, useMemo, useCallback } from 'react';
|
||||
import { IPreviewUrlResponse, MsgType } from '$types/matrix-sdk';
|
||||
import type { IPreviewUrlResponse } from '$types/matrix-sdk';
|
||||
import { MsgType } from '$types/matrix-sdk';
|
||||
import { parseSettingsLink } from '$features/settings/settingsLink';
|
||||
import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl';
|
||||
import { testMatrixTo } from '$plugins/matrix-to';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
import { settingsAtom, CaptionPosition } from '$state/settings';
|
||||
import { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import { Opts } from 'linkifyjs';
|
||||
import type { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import type { Opts } from 'linkifyjs';
|
||||
import { Box, config } from 'folds';
|
||||
import {
|
||||
AudioContent,
|
||||
@@ -42,7 +43,7 @@ type RenderMessageContentProps = {
|
||||
msgType: string;
|
||||
ts: number;
|
||||
edited?: boolean;
|
||||
getContent: <T>() => T;
|
||||
getContent: () => unknown;
|
||||
mediaAutoLoad?: boolean;
|
||||
bundledPreview?: boolean;
|
||||
urlPreview?: boolean;
|
||||
@@ -80,7 +81,7 @@ function RenderMessageContentInternal({
|
||||
outlineAttachment,
|
||||
hideCaption,
|
||||
}: RenderMessageContentProps) {
|
||||
const content = useMemo(() => getContent<any>(), [getContent]);
|
||||
const content = useMemo(() => getContent() as Record<string, unknown>, [getContent]);
|
||||
|
||||
const [autoplayGifs] = useSetting(settingsAtom, 'autoplayGifs');
|
||||
const [captionPosition] = useSetting(settingsAtom, 'captionPosition');
|
||||
@@ -95,9 +96,10 @@ function RenderMessageContentInternal({
|
||||
const attachmentDirection = captionPositionMap[captionPosition];
|
||||
|
||||
const renderBody = useCallback(
|
||||
(props: any) => (
|
||||
(props: Record<string, unknown>) => (
|
||||
<RenderBody
|
||||
{...props}
|
||||
body={props.body as string}
|
||||
highlightRegex={highlightRegex}
|
||||
htmlReactParserOptions={htmlReactParserOptions}
|
||||
linkifyOpts={linkifyOpts}
|
||||
@@ -117,16 +119,18 @@ function RenderMessageContentInternal({
|
||||
url,
|
||||
type: getMediaType(url),
|
||||
}));
|
||||
|
||||
const toRender = multiplePreviews ? analyzed : [analyzed[0]];
|
||||
const mediaLinks = analyzed.filter((item) => item.type !== null);
|
||||
const previewCandidates = mediaLinks.length > 0 ? mediaLinks : analyzed;
|
||||
const toRender = multiplePreviews ? previewCandidates : [previewCandidates[0]!];
|
||||
return (
|
||||
<UrlPreviewHolder>
|
||||
{toRender.map(({ url, type }) => {
|
||||
{toRender.map((item) => {
|
||||
const { url, type } = item;
|
||||
if (type) {
|
||||
return <UrlPreviewCard urlPreview key={url} url={url} ts={ts} mediaType={type} />;
|
||||
}
|
||||
if (clientUrlPreview && youtubeUrl(url)) {
|
||||
return <ClientPreview url={url} />;
|
||||
return <ClientPreview key={url} url={url} />;
|
||||
}
|
||||
if (urlPreview) {
|
||||
return <UrlPreviewCard urlPreview key={url} url={url} ts={ts} mediaType={type} />;
|
||||
@@ -157,9 +161,13 @@ function RenderMessageContentInternal({
|
||||
const messageBundlePreview = bundledPreview ? renderBundledPreviews : undefined;
|
||||
|
||||
const renderCaption = () => {
|
||||
const hasCaption = content.body && content.body.trim().length > 0;
|
||||
const hasCaption = content.body && (content.body as string).trim().length > 0;
|
||||
if (captionPosition === CaptionPosition.Hidden || hideCaption) return null;
|
||||
if (hasCaption && content.filename && content.filename !== content.body) {
|
||||
if (
|
||||
hasCaption &&
|
||||
(content as { filename?: string }).filename &&
|
||||
(content as { filename?: string }).filename !== content.body
|
||||
) {
|
||||
if (captionPosition !== CaptionPosition.Inline)
|
||||
return (
|
||||
<MText
|
||||
@@ -213,7 +221,7 @@ function RenderMessageContentInternal({
|
||||
const renderFile = () =>
|
||||
renderCaptionedAttachment(
|
||||
<MFile
|
||||
content={content}
|
||||
content={content as Record<string, never> & { msgtype: MsgType.File }}
|
||||
renderFileContent={({ body, mimeType, info, encInfo, url }) => (
|
||||
<FileContent
|
||||
body={body}
|
||||
@@ -244,7 +252,7 @@ function RenderMessageContentInternal({
|
||||
/>
|
||||
);
|
||||
|
||||
if (msgType === MsgType.Text) {
|
||||
if (msgType === (MsgType.Text as string)) {
|
||||
return (
|
||||
<MText
|
||||
edited={edited}
|
||||
@@ -256,13 +264,15 @@ function RenderMessageContentInternal({
|
||||
);
|
||||
}
|
||||
|
||||
if (msgType === MsgType.Emote) {
|
||||
if (content['fyi.cisnt.headpat']) {
|
||||
if (msgType === (MsgType.Emote as string)) {
|
||||
if ((content as { 'fyi.cisnt.headpat'?: boolean })['fyi.cisnt.headpat']) {
|
||||
return (
|
||||
<MCuteEvent
|
||||
content={content}
|
||||
content={(content as { body?: string }).body}
|
||||
type={CuteEventType.Headpat}
|
||||
mentionedUserIds={content?.['m.mentions']?.user_ids}
|
||||
mentionedUserIds={
|
||||
(content as { 'm.mentions'?: { user_ids?: string[] } })['m.mentions']?.user_ids
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -278,7 +288,7 @@ function RenderMessageContentInternal({
|
||||
);
|
||||
}
|
||||
|
||||
if (msgType === MsgType.Notice) {
|
||||
if (msgType === (MsgType.Notice as string)) {
|
||||
return (
|
||||
<MNotice
|
||||
edited={edited}
|
||||
@@ -290,17 +300,19 @@ function RenderMessageContentInternal({
|
||||
);
|
||||
}
|
||||
|
||||
if (msgType === MsgType.Image) {
|
||||
if (msgType === (MsgType.Image as string)) {
|
||||
const info = (content as { info?: { mimetype?: string } }).info;
|
||||
const isGif =
|
||||
content.info?.mimetype === 'image/gif' ||
|
||||
content.info?.mimetype === 'image/webp' ||
|
||||
content.body?.toLowerCase().endsWith('.gif') ||
|
||||
content.body?.toLowerCase().endsWith('.webp') ||
|
||||
(typeof content.url === 'string' && content.url.toLowerCase().includes('gif'));
|
||||
info?.mimetype === 'image/gif' ||
|
||||
info?.mimetype === 'image/webp' ||
|
||||
(content.body as string)?.toLowerCase().endsWith('.gif') ||
|
||||
(content.body as string)?.toLowerCase().endsWith('.webp') ||
|
||||
(typeof (content as { url?: string }).url === 'string' &&
|
||||
(content as { url?: string }).url?.toLowerCase().includes('gif'));
|
||||
|
||||
return renderCaptionedAttachment(
|
||||
<MImage
|
||||
content={content}
|
||||
content={content as Record<string, never> & { msgtype: MsgType.Image }}
|
||||
renderImageContent={(imageProps) => (
|
||||
<ImageContent
|
||||
{...imageProps}
|
||||
@@ -323,10 +335,10 @@ function RenderMessageContentInternal({
|
||||
);
|
||||
}
|
||||
|
||||
if (msgType === MsgType.Video) {
|
||||
if (msgType === (MsgType.Video as string)) {
|
||||
return renderCaptionedAttachment(
|
||||
<MVideo
|
||||
content={content}
|
||||
content={content as Record<string, never> & { msgtype: MsgType.Video }}
|
||||
renderAsFile={renderFile}
|
||||
renderVideoContent={({ body, info, ...videoProps }) => (
|
||||
<VideoContent
|
||||
@@ -353,10 +365,10 @@ function RenderMessageContentInternal({
|
||||
);
|
||||
}
|
||||
|
||||
if (msgType === MsgType.Audio) {
|
||||
if (msgType === (MsgType.Audio as string)) {
|
||||
return renderCaptionedAttachment(
|
||||
<MAudio
|
||||
content={content}
|
||||
content={content as Record<string, never> & { msgtype: MsgType.Audio }}
|
||||
renderAsFile={renderFile}
|
||||
renderAudioContent={(audioProps) => (
|
||||
<AudioContent {...audioProps} renderMediaControl={(p) => <MediaControl {...p} />} />
|
||||
@@ -366,29 +378,33 @@ function RenderMessageContentInternal({
|
||||
);
|
||||
}
|
||||
|
||||
if (msgType === MsgType.File) return renderFile();
|
||||
if (msgType === MsgType.Location) return <MLocation content={content} />;
|
||||
if (msgType === (MsgType.File as string)) return renderFile();
|
||||
if (msgType === (MsgType.Location as string)) return <MLocation content={content} />;
|
||||
if (msgType === 'm.bad.encrypted') return <MBadEncrypted />;
|
||||
|
||||
// cute events
|
||||
if (msgType === 'im.fluffychat.cute_event')
|
||||
return (
|
||||
<MCuteEvent
|
||||
content={content}
|
||||
type={content?.cute_type}
|
||||
mentionedUserIds={content?.['m.mentions']?.user_ids}
|
||||
content={(content as { body?: string }).body}
|
||||
type={(content as { cute_type: CuteEventType }).cute_type ?? CuteEventType.Hug}
|
||||
mentionedUserIds={
|
||||
(content as { 'm.mentions'?: { user_ids?: string[] } })['m.mentions']?.user_ids
|
||||
}
|
||||
/>
|
||||
);
|
||||
// as fallback to render older events where msgtype was set instead of m.emote with a custom property
|
||||
if (msgType === 'fyi.cisnt.headpat')
|
||||
return (
|
||||
<MCuteEvent
|
||||
content={content}
|
||||
content={(content as { body?: string }).body}
|
||||
type={CuteEventType.Headpat}
|
||||
mentionedUserIds={content?.['m.mentions']?.user_ids}
|
||||
mentionedUserIds={
|
||||
(content as { 'm.mentions'?: { user_ids?: string[] } })['m.mentions']?.user_ids
|
||||
}
|
||||
/>
|
||||
);
|
||||
return <UnsupportedContent body={content?.body} />;
|
||||
return <UnsupportedContent body={(content as { body?: string }).body ?? ''} />;
|
||||
}
|
||||
|
||||
export const RenderMessageContent = memo(RenderMessageContentInternal);
|
||||
@@ -1,17 +1,18 @@
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import type * as RoomsNotificationPreferencesModule from '$hooks/useRoomsNotificationPreferences';
|
||||
|
||||
import { RoomNotificationMode } from '$hooks/useRoomsNotificationPreferences';
|
||||
|
||||
import { RoomNotificationModeSwitcher } from './RoomNotificationSwitcher';
|
||||
|
||||
const { mockSetMode, modeStateStatus } = vi.hoisted(() => ({
|
||||
mockSetMode: vi.fn(),
|
||||
mockSetMode: vi.fn<(mode: RoomNotificationMode, current: RoomNotificationMode) => void>(),
|
||||
modeStateStatus: { current: 'idle' as 'idle' | 'loading' },
|
||||
}));
|
||||
|
||||
vi.mock('$hooks/useRoomsNotificationPreferences', async () => {
|
||||
const actual = await vi.importActual<typeof import('$hooks/useRoomsNotificationPreferences')>(
|
||||
const actual = await vi.importActual<typeof RoomsNotificationPreferencesModule>(
|
||||
'$hooks/useRoomsNotificationPreferences'
|
||||
);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Box, Icon, Text } from 'folds';
|
||||
import { type MouseEventHandler, ReactNode } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { type MouseEventHandler } from 'react';
|
||||
import { SettingMenuSelector, type SettingMenuOption } from '$components/setting-menu-selector';
|
||||
import {
|
||||
getRoomNotificationModeIcon,
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { ReactNode, useCallback, useState } from 'react';
|
||||
import { MatrixClient, Room, IHierarchyRoom } from '$types/matrix-sdk';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useCallback, useState } from 'react';
|
||||
import type { MatrixClient, Room, IHierarchyRoom } from '$types/matrix-sdk';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { LocalRoomSummary, useLocalRoomSummary } from '$hooks/useLocalRoomSummary';
|
||||
import { AsyncState, AsyncStatus } from '$hooks/useAsyncCallback';
|
||||
import type { LocalRoomSummary } from '$hooks/useLocalRoomSummary';
|
||||
import { useLocalRoomSummary } from '$hooks/useLocalRoomSummary';
|
||||
import type { AsyncState } from '$hooks/useAsyncCallback';
|
||||
import { AsyncStatus } from '$hooks/useAsyncCallback';
|
||||
|
||||
export type IRoomSummary = Awaited<ReturnType<MatrixClient['getRoomSummary']>>;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ReactElement } from 'react';
|
||||
import { Unread } from '$types/matrix/room';
|
||||
import type { ReactElement } from 'react';
|
||||
import type { Unread } from '$types/matrix/room';
|
||||
import { useRoomUnread, useRoomsUnread } from '$state/hooks/unread';
|
||||
import { roomToUnreadAtom } from '$state/room/roomToUnread';
|
||||
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { FormEventHandler, useCallback } from 'react';
|
||||
import type { FormEventHandler } from 'react';
|
||||
import { useCallback } from 'react';
|
||||
import { Box, Text, Button, Spinner, color } from 'folds';
|
||||
import { decodeRecoveryKey, deriveRecoveryKeyFromPassphrase } from '$types/matrix-sdk';
|
||||
import { SecretStorageKeyContent, SecretStoragePassphraseContent } from '$types/matrix/accountData';
|
||||
import type {
|
||||
SecretStorageKeyContent,
|
||||
SecretStoragePassphraseContent,
|
||||
} from '$types/matrix/accountData';
|
||||
import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { useAlive } from '$hooks/useAlive';
|
||||
@@ -36,7 +40,7 @@ export function SecretStorageRecoveryPassphrase({
|
||||
bits
|
||||
);
|
||||
|
||||
const match = await mx.secretStorage.checkKey(decodedRecoveryKey, keyContent as any);
|
||||
const match = await mx.secretStorage.checkKey(decodedRecoveryKey, keyContent as never);
|
||||
|
||||
if (!match) {
|
||||
throw new Error('Invalid recovery passphrase.');
|
||||
@@ -128,7 +132,7 @@ export function SecretStorageRecoveryKey({
|
||||
async (recoveryKey) => {
|
||||
const decodedRecoveryKey = decodeRecoveryKey(recoveryKey);
|
||||
|
||||
const match = await mx.secretStorage.checkKey(decodedRecoveryKey, keyContent as any);
|
||||
const match = await mx.secretStorage.checkKey(decodedRecoveryKey, keyContent as never);
|
||||
|
||||
if (!match) {
|
||||
throw new Error('Invalid recovery key.');
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { ReactNode, useCallback, useMemo } from 'react';
|
||||
import { Capabilities, validateAuthMetadata, ValidatedAuthMetadata } from '$types/matrix-sdk';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import type { Capabilities, ValidatedAuthMetadata } from '$types/matrix-sdk';
|
||||
import { validateAuthMetadata } from '$types/matrix-sdk';
|
||||
import { AsyncStatus, useAsyncCallbackValue } from '$hooks/useAsyncCallback';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { MediaConfig } from '$hooks/useMediaConfig';
|
||||
import type { MediaConfig } from '$hooks/useMediaConfig';
|
||||
import { promiseFulfilledResult } from '$utils/common';
|
||||
import { createLogger } from '$utils/debug';
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { ReactNode, useCallback, useEffect, useState } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
|
||||
import { SpecVersions, specVersions } from '../cs-api';
|
||||
import type { SpecVersions } from '../cs-api';
|
||||
import { specVersions } from '../cs-api';
|
||||
|
||||
type SpecVersionsLoaderProps = {
|
||||
baseUrl: string;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ReactNode } from 'react';
|
||||
import { UIAFlow } from '$types/matrix-sdk';
|
||||
import type { ReactNode } from 'react';
|
||||
import type { UIAFlow } from '$types/matrix-sdk';
|
||||
import { useSupportedUIAFlows } from '$hooks/useUIAFlows';
|
||||
|
||||
export function SupportedUIAFlowsLoader({
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ReactNode } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { motion, useMotionValue, useSpring } from 'framer-motion';
|
||||
import { useDrag } from '@use-gesture/react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useMotionValue, useSpring, useTransform, motion } from 'framer-motion';
|
||||
import { useDrag } from '@use-gesture/react';
|
||||
import { ReactNode, useMemo, useState } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { config, Icon, Icons } from 'folds';
|
||||
import { mobileOrTablet } from '$utils/user-agent';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ReactNode } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { motion, useMotionValue, useSpring } from 'framer-motion';
|
||||
import { useDrag } from '@use-gesture/react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ReactNode } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import {
|
||||
Overlay,
|
||||
OverlayBackdrop,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Dispatch, ReactElement, SetStateAction, useState } from 'react';
|
||||
import type { Dispatch, ReactElement, SetStateAction } from 'react';
|
||||
import { useState } from 'react';
|
||||
|
||||
type UseStateProviderProps<T> = {
|
||||
initial: T | (() => T);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Menu, PopOut, toRem } from 'folds';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { useCloseUserRoomProfile, useUserRoomProfileState } from '$state/hooks/userRoomProfile';
|
||||
import { UserRoomProfileState } from '$state/userRoomProfile';
|
||||
import type { UserRoomProfileState } from '$state/userRoomProfile';
|
||||
import { useAllJoinedRoomsSet, useGetRoom } from '$hooks/useGetRoom';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import { SpaceProvider } from '$hooks/useSpace';
|
||||
|
||||
@@ -6,8 +6,9 @@ import { CodeHighlightRenderer } from '.';
|
||||
import * as css from './CodeHighlightRenderer.css';
|
||||
|
||||
const { highlightCode, useArboriumThemeStatus } = vi.hoisted(() => ({
|
||||
highlightCode: vi.fn(),
|
||||
useArboriumThemeStatus: vi.fn(),
|
||||
highlightCode:
|
||||
vi.fn<() => Promise<{ mode: 'highlighted' | 'plain'; html: string; language: string }>>(),
|
||||
useArboriumThemeStatus: vi.fn<() => { ready: boolean }>(),
|
||||
}));
|
||||
|
||||
vi.mock('$plugins/arborium', () => ({
|
||||
|
||||
@@ -74,7 +74,6 @@ export function CodeHighlightRenderer({
|
||||
}
|
||||
|
||||
return (
|
||||
// eslint-disable-next-line react/no-danger
|
||||
<code className={codeClassName} dangerouslySetInnerHTML={{ __html: currentResult.html }} />
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { RectCords } from 'folds';
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
@@ -10,25 +11,20 @@ import {
|
||||
Menu,
|
||||
MenuItem,
|
||||
PopOut,
|
||||
RectCords,
|
||||
Scroll,
|
||||
Text,
|
||||
toRem,
|
||||
} from 'folds';
|
||||
import { isKeyHotkey } from 'is-hotkey';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import {
|
||||
ChangeEventHandler,
|
||||
KeyboardEventHandler,
|
||||
MouseEventHandler,
|
||||
useMemo,
|
||||
useState,
|
||||
} from 'react';
|
||||
import type { ChangeEventHandler, KeyboardEventHandler, MouseEventHandler } from 'react';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { getMxIdLocalPart, getMxIdServer, isUserId } from '$utils/matrix';
|
||||
import { useDirectUsers } from '$hooks/useDirectUsers';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import { useAsyncSearch, UseAsyncSearchOptions } from '$hooks/useAsyncSearch';
|
||||
import type { UseAsyncSearchOptions } from '$hooks/useAsyncSearch';
|
||||
import { useAsyncSearch } from '$hooks/useAsyncSearch';
|
||||
import { highlightText, makeHighlightRegex } from '$plugins/react-custom-html-parser';
|
||||
import { SettingTile } from '$components/setting-tile';
|
||||
|
||||
@@ -101,7 +97,7 @@ export function AdditionalCreatorInput({
|
||||
|
||||
const suggestionUsers = result
|
||||
? result.items
|
||||
: filteredUsers.sort((a, b) => (a.toLocaleLowerCase() >= b.toLocaleLowerCase() ? 1 : -1));
|
||||
: filteredUsers.toSorted((a, b) => (a.toLocaleLowerCase() >= b.toLocaleLowerCase() ? 1 : -1));
|
||||
|
||||
const handleOpenMenu: MouseEventHandler<HTMLButtonElement> = (evt) => {
|
||||
setMenuCords(evt.currentTarget.getBoundingClientRect());
|
||||
@@ -224,7 +220,10 @@ export function AdditionalCreatorInput({
|
||||
grow="Yes"
|
||||
direction="Column"
|
||||
gap="100"
|
||||
style={{ padding: config.space.S200, paddingRight: 0 }}
|
||||
style={{
|
||||
padding: config.space.S200,
|
||||
paddingRight: 0,
|
||||
}}
|
||||
>
|
||||
{suggestionUsers.map((userId) => (
|
||||
<MenuItem
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Box, Text, Icon, Icons, config, IconSrc } from 'folds';
|
||||
import type { IconSrc } from 'folds';
|
||||
import { Box, Text, Icon, Icons, config } from 'folds';
|
||||
import { SequenceCard } from '$components/sequence-card';
|
||||
import { SettingTile } from '$components/setting-tile';
|
||||
import { CreateRoomAccess } from './types';
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
import {
|
||||
FormEventHandler,
|
||||
KeyboardEventHandler,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import type { FormEventHandler, KeyboardEventHandler } from 'react';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { MatrixError } from '$types/matrix-sdk';
|
||||
import { Box, color, Icon, Icons, Input, Spinner, Text, toRem } from 'folds';
|
||||
import { isKeyHotkey } from 'is-hotkey';
|
||||
import { getMxIdServer } from '$utils/matrix';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { replaceSpaceWithDash } from '$utils/common';
|
||||
import { AsyncState, AsyncStatus, useAsync } from '$hooks/useAsyncCallback';
|
||||
import type { AsyncState } from '$hooks/useAsyncCallback';
|
||||
import { AsyncStatus, useAsync } from '$hooks/useAsyncCallback';
|
||||
import { useDebounce } from '$hooks/useDebounce';
|
||||
|
||||
export function CreateRoomAliasInput({ disabled }: { disabled?: boolean }) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Box, Text, Icon, Icons, config, IconSrc } from 'folds';
|
||||
import type { IconSrc } from 'folds';
|
||||
import { Box, Text, Icon, Icons, config } from 'folds';
|
||||
import { SequenceCard } from '$components/sequence-card';
|
||||
import { SettingTile } from '$components/setting-tile';
|
||||
import { BetaNoticeBadge } from '$components/BetaNoticeBadge';
|
||||
|
||||
@@ -1,17 +1,7 @@
|
||||
import { MouseEventHandler, useState } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
Chip,
|
||||
config,
|
||||
Icon,
|
||||
Icons,
|
||||
Menu,
|
||||
PopOut,
|
||||
RectCords,
|
||||
Text,
|
||||
toRem,
|
||||
} from 'folds';
|
||||
import type { MouseEventHandler } from 'react';
|
||||
import { useState } from 'react';
|
||||
import type { RectCords } from 'folds';
|
||||
import { Box, Button, Chip, config, Icon, Icons, Menu, PopOut, Text, toRem } from 'folds';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import { SettingTile } from '$components/setting-tile';
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import {
|
||||
import type {
|
||||
ICreateRoomOpts,
|
||||
ICreateRoomStateEvent,
|
||||
JoinRule,
|
||||
MatrixClient,
|
||||
RestrictedAllowType,
|
||||
Room,
|
||||
RoomJoinRulesEventContent,
|
||||
} from '$types/matrix-sdk';
|
||||
import { RoomType, StateEvent } from '$types/matrix/room';
|
||||
import { JoinRule, RestrictedAllowType, EventType, RoomType } from '$types/matrix-sdk';
|
||||
|
||||
import type { StateEvents } from '$types/matrix-sdk';
|
||||
import { getViaServers } from '$plugins/via-servers';
|
||||
import { getMxIdServer } from '$utils/matrix';
|
||||
import { CreateRoomAccess } from './types';
|
||||
@@ -17,11 +17,11 @@ export const createRoomCreationContent = (
|
||||
allowFederation: boolean,
|
||||
additionalCreators: string[] | undefined
|
||||
): object => {
|
||||
const content: Record<string, any> = {};
|
||||
const content: Record<string, unknown> = {};
|
||||
if (typeof type === 'string') {
|
||||
content.type = type;
|
||||
}
|
||||
if (allowFederation === false) {
|
||||
if (!allowFederation) {
|
||||
content['m.federate'] = false;
|
||||
}
|
||||
if (Array.isArray(additionalCreators)) {
|
||||
@@ -59,14 +59,14 @@ export const createRoomJoinRulesState = (
|
||||
}
|
||||
|
||||
return {
|
||||
type: StateEvent.RoomJoinRules,
|
||||
type: EventType.RoomJoinRules,
|
||||
state_key: '',
|
||||
content,
|
||||
};
|
||||
};
|
||||
|
||||
export const createRoomParentState = (parent: Room) => ({
|
||||
type: StateEvent.SpaceParent,
|
||||
type: EventType.SpaceParent,
|
||||
state_key: parent.roomId,
|
||||
content: {
|
||||
canonical: true,
|
||||
@@ -94,7 +94,7 @@ export const createRoomCallState = () => ({
|
||||
|
||||
export const createVoiceRoomPowerLevelsOverride = () => ({
|
||||
events: {
|
||||
[StateEvent.GroupCallMemberPrefix]: 0,
|
||||
[EventType.GroupCallMemberPrefix]: 0,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -122,7 +122,7 @@ export const createRoom = async (mx: MatrixClient, data: CreateRoomData): Promis
|
||||
initialState.push(createRoomParentState(data.parent));
|
||||
}
|
||||
|
||||
if (data.type === RoomType.Call) {
|
||||
if (data.type === RoomType.UnstableCall) {
|
||||
initialState.push(createRoomCallState());
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ export const createRoom = async (mx: MatrixClient, data: CreateRoomData): Promis
|
||||
data.additionalCreators
|
||||
),
|
||||
power_level_content_override:
|
||||
data.type === RoomType.Call ? createVoiceRoomPowerLevelsOverride() : undefined,
|
||||
data.type === RoomType.UnstableCall ? createVoiceRoomPowerLevelsOverride() : undefined,
|
||||
initial_state: initialState,
|
||||
};
|
||||
|
||||
@@ -152,12 +152,12 @@ export const createRoom = async (mx: MatrixClient, data: CreateRoomData): Promis
|
||||
if (data.parent) {
|
||||
await mx.sendStateEvent(
|
||||
data.parent.roomId,
|
||||
StateEvent.SpaceChild as any,
|
||||
EventType.SpaceChild as keyof StateEvents,
|
||||
{
|
||||
auto_join: false,
|
||||
suggested: false,
|
||||
via: [getMxIdServer(mx.getUserId() ?? '') ?? ''],
|
||||
},
|
||||
} as StateEvents[keyof StateEvents],
|
||||
result.room_id
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { as, ContainerColor as TContainerColor } from 'folds';
|
||||
import type { ContainerColor as TContainerColor } from 'folds';
|
||||
import { as } from 'folds';
|
||||
import classNames from 'classnames';
|
||||
import { ContainerColor } from '$styles/ContainerColor.css';
|
||||
import * as css from './CutoutCard.css';
|
||||
|
||||
@@ -1,31 +1,15 @@
|
||||
/* eslint-disable no-param-reassign */
|
||||
import {
|
||||
ClipboardEventHandler,
|
||||
KeyboardEventHandler,
|
||||
ReactNode,
|
||||
forwardRef,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useLayoutEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import type { ClipboardEventHandler, KeyboardEventHandler, ReactNode } from 'react';
|
||||
import { forwardRef, useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
||||
import { Box, Scroll, Text } from 'folds';
|
||||
import { Descendant, Editor, Node, createEditor } from 'slate';
|
||||
import {
|
||||
Slate,
|
||||
Editable,
|
||||
withReact,
|
||||
RenderLeafProps,
|
||||
RenderElementProps,
|
||||
RenderPlaceholderProps,
|
||||
ReactEditor,
|
||||
} from 'slate-react';
|
||||
import type { Descendant, Editor } from 'slate';
|
||||
import { Node, createEditor } from 'slate';
|
||||
import type { RenderLeafProps, RenderElementProps, RenderPlaceholderProps } from 'slate-react';
|
||||
import { Slate, Editable, withReact, ReactEditor } from 'slate-react';
|
||||
import { withHistory } from 'slate-history';
|
||||
import { mobileOrTablet } from '$utils/user-agent';
|
||||
import { BlockType } from './types';
|
||||
import { RenderElement, RenderLeaf } from './Elements';
|
||||
import { CustomElement } from './slate';
|
||||
import type { CustomElement } from './slate';
|
||||
import * as css from './Editor.css';
|
||||
import { toggleKeyboardShortcut } from './keyboard';
|
||||
|
||||
@@ -436,7 +420,9 @@ export const CustomEditor = forwardRef<HTMLDivElement, CustomEditorProps>(
|
||||
<Scroll
|
||||
className={`${css.EditorTextareaScroll} ${layoutIsMultiline ? css.EditorTextareaScrollMultiline : ''}`}
|
||||
variant={variant}
|
||||
style={{ maxHeight: showResponsiveAfterInFooter ? undefined : maxHeight }}
|
||||
style={{
|
||||
maxHeight: showResponsiveAfterInFooter ? undefined : maxHeight,
|
||||
}}
|
||||
size="300"
|
||||
visibility="Always"
|
||||
hideTrack
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import { Scroll, Text } from 'folds';
|
||||
import {
|
||||
RenderElementProps,
|
||||
RenderLeafProps,
|
||||
useFocused,
|
||||
useSelected,
|
||||
useSlate,
|
||||
} from 'slate-react';
|
||||
import type { RenderElementProps, RenderLeafProps } from 'slate-react';
|
||||
import { useFocused, useSelected, useSlate } from 'slate-react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
|
||||
import * as css from '$styles/CustomHtml.css';
|
||||
@@ -15,7 +10,7 @@ import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { nicknamesAtom } from '$state/nicknames';
|
||||
import { BlockType } from './types';
|
||||
import { getBeginCommand } from './utils';
|
||||
import { CommandElement, EmoticonElement, LinkElement, MentionElement } from './slate';
|
||||
import type { CommandElement, EmoticonElement, LinkElement, MentionElement } from './slate';
|
||||
|
||||
// Put this at the start and end of an inline component to work around this Chromium bug:
|
||||
// https://bugs.chromium.org/p/chromium/issues/detail?id=1249405
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import type { IconSrc, RectCords } from 'folds';
|
||||
import {
|
||||
Badge,
|
||||
Box,
|
||||
@@ -6,18 +7,17 @@ import {
|
||||
Icon,
|
||||
IconButton,
|
||||
Icons,
|
||||
IconSrc,
|
||||
Line,
|
||||
Menu,
|
||||
PopOut,
|
||||
RectCords,
|
||||
Scroll,
|
||||
Text,
|
||||
Tooltip,
|
||||
TooltipProvider,
|
||||
toRem,
|
||||
} from 'folds';
|
||||
import { MouseEventHandler, ReactNode, useState } from 'react';
|
||||
import type { MouseEventHandler, ReactNode } from 'react';
|
||||
import { useState } from 'react';
|
||||
import { ReactEditor, useSlate } from 'slate-react';
|
||||
import { isMacOS } from '$utils/user-agent';
|
||||
import { KeySymbol } from '$utils/key-symbol';
|
||||
@@ -25,7 +25,7 @@ import { useSetting } from '$state/hooks/settings';
|
||||
import { settingsAtom } from '$state/settings';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import { floatingToolbar } from '$styles/overrides/Composer.css';
|
||||
import { HeadingLevel } from './slate';
|
||||
import type { HeadingLevel } from './slate';
|
||||
import { BlockType, MarkType } from './types';
|
||||
import * as css from './Editor.css';
|
||||
import {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { ReactNode, useEffect, useRef, useState } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { isKeyHotkey } from 'is-hotkey';
|
||||
import { Header, Menu, Scroll, config } from 'folds';
|
||||
|
||||
import { preventScrollWithArrowKey, stopPropagation } from '$utils/keyboard';
|
||||
import { useAlive } from '$hooks/useAlive';
|
||||
import { Editor } from 'slate';
|
||||
import type { Editor } from 'slate';
|
||||
import { ReactEditor } from 'slate-react';
|
||||
import * as css from './AutocompleteMenu.css';
|
||||
import { BaseAutocompleteMenu } from './BaseAutocompleteMenu';
|
||||
@@ -33,7 +34,7 @@ export function AutocompleteMenu({
|
||||
};
|
||||
const [isActive, setIsActive] = useState(true);
|
||||
useEffect(() => ReactEditor.focus(editor), [editor, isActive]);
|
||||
function handleInput(evt: any) {
|
||||
function handleInput(evt: KeyboardEvent) {
|
||||
if (!evt) return;
|
||||
if (
|
||||
isKeyHotkey('arrowdown', evt) ||
|
||||
@@ -61,7 +62,10 @@ export function AutocompleteMenu({
|
||||
escapeDeactivates: stopPropagation,
|
||||
}}
|
||||
>
|
||||
<Menu className={css.AutocompleteMenu} onKeyDown={(evt) => handleInput(evt)}>
|
||||
<Menu
|
||||
className={css.AutocompleteMenu}
|
||||
onKeyDown={(evt) => handleInput(evt as unknown as KeyboardEvent)}
|
||||
>
|
||||
<Header className={css.AutocompleteMenuHeader} size="400">
|
||||
{headerContent}
|
||||
</Header>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ReactNode } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { Header, Menu } from 'folds';
|
||||
import { BaseAutocompleteMenu } from './BaseAutocompleteMenu';
|
||||
import * as css from './AutocompleteMenu.css';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ReactNode } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import * as css from './AutocompleteMenu.css';
|
||||
|
||||
type BaseAutocompleteMenuProps = {
|
||||
|
||||
@@ -1,25 +1,29 @@
|
||||
import { KeyboardEvent as ReactKeyboardEvent, useEffect, useMemo } from 'react';
|
||||
import { Editor } from 'slate';
|
||||
import type { KeyboardEvent as ReactKeyboardEvent } from 'react';
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import type { Editor } from 'slate';
|
||||
import { ReactEditor } from 'slate-react';
|
||||
import { Box, MenuItem, Text, toRem } from 'folds';
|
||||
import { Room } from '$types/matrix-sdk';
|
||||
import type { Room } from '$types/matrix-sdk';
|
||||
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { UseAsyncSearchOptions, useAsyncSearch } from '$hooks/useAsyncSearch';
|
||||
import type { UseAsyncSearchOptions } from '$hooks/useAsyncSearch';
|
||||
import { useAsyncSearch } from '$hooks/useAsyncSearch';
|
||||
import { onTabPress } from '$utils/keyboard';
|
||||
import { useRecentEmoji } from '$hooks/useRecentEmoji';
|
||||
import { useRelevantImagePacks } from '$hooks/useImagePacks';
|
||||
import { IEmoji, emojis } from '$plugins/emoji';
|
||||
import type { IEmoji } from '$plugins/emoji';
|
||||
import { emojis } from '$plugins/emoji';
|
||||
import { useKeyDown } from '$hooks/useKeyDown';
|
||||
import { mxcUrlToHttp } from '$utils/matrix';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { ImageUsage, PackImageReader } from '$plugins/custom-emoji';
|
||||
import type { PackImageReader } from '$plugins/custom-emoji';
|
||||
import { ImageUsage } from '$plugins/custom-emoji';
|
||||
import { getEmoticonSearchStr } from '$plugins/utils';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
import { settingsAtom } from '$state/settings';
|
||||
import { createEmoticonElement, moveCursor, replaceWithElement } from '$components/editor/utils';
|
||||
import { AutocompleteMenu } from './AutocompleteMenu';
|
||||
import { AutocompleteQuery } from './autocompleteQuery';
|
||||
import type { AutocompleteQuery } from './autocompleteQuery';
|
||||
|
||||
type EmoticonCompleteHandler = (key: string, shortcode: string) => void;
|
||||
|
||||
@@ -96,7 +100,7 @@ export function EmoticonAutocomplete({
|
||||
useKeyDown(window, (evt: KeyboardEvent) => {
|
||||
onTabPress(evt, () => {
|
||||
if (autoCompleteEmoticon.length === 0) return;
|
||||
const emoticon = autoCompleteEmoticon[0];
|
||||
const emoticon = autoCompleteEmoticon[0]!;
|
||||
const key = 'url' in emoticon ? emoticon.url : emoticon.unicode;
|
||||
handleAutocomplete(key, emoticon.shortcode);
|
||||
});
|
||||
@@ -129,7 +133,11 @@ export function EmoticonAutocomplete({
|
||||
as="img"
|
||||
src={customEmojiUrl}
|
||||
alt={emoticon.shortcode}
|
||||
style={{ width: toRem(24), height: toRem(24), objectFit: 'contain' }}
|
||||
style={{
|
||||
width: toRem(24),
|
||||
height: toRem(24),
|
||||
objectFit: 'contain',
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<Box
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import { KeyboardEvent as ReactKeyboardEvent, useCallback, useEffect } from 'react';
|
||||
import { Editor } from 'slate';
|
||||
import type { KeyboardEvent as ReactKeyboardEvent } from 'react';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import type { Editor } from 'slate';
|
||||
import { ReactEditor } from 'slate-react';
|
||||
import { Avatar, Icon, Icons, MenuItem, Text } from 'folds';
|
||||
import { JoinRule, MatrixClient } from '$types/matrix-sdk';
|
||||
import type { MatrixClient } from '$types/matrix-sdk';
|
||||
import { JoinRule } from '$types/matrix-sdk';
|
||||
import { useAtomValue } from 'jotai';
|
||||
|
||||
import { getDirectRoomAvatarUrl } from '$utils/room';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { getMxIdServer, isRoomAlias } from '$utils/matrix';
|
||||
import { UseAsyncSearchOptions, useAsyncSearch } from '$hooks/useAsyncSearch';
|
||||
import type { UseAsyncSearchOptions } from '$hooks/useAsyncSearch';
|
||||
import { useAsyncSearch } from '$hooks/useAsyncSearch';
|
||||
import { onTabPress } from '$utils/keyboard';
|
||||
import { useKeyDown } from '$hooks/useKeyDown';
|
||||
import { mDirectAtom } from '$state/mDirectList';
|
||||
@@ -18,7 +21,7 @@ import { RoomAvatar, RoomIcon } from '$components/room-avatar';
|
||||
import { getViaServers } from '$plugins/via-servers';
|
||||
import { createMentionElement, moveCursor, replaceWithElement } from '$components/editor/utils';
|
||||
import { AutocompleteMenu } from './AutocompleteMenu';
|
||||
import { AutocompleteQuery } from './autocompleteQuery';
|
||||
import type { AutocompleteQuery } from './autocompleteQuery';
|
||||
|
||||
type MentionAutoCompleteHandler = (roomAliasOrId: string, name: string) => void;
|
||||
|
||||
@@ -80,7 +83,7 @@ export function RoomMentionAutocomplete({
|
||||
const mx = useMatrixClient();
|
||||
const mDirects = useAtomValue(mDirectAtom);
|
||||
|
||||
const allRooms = useAtomValue(allRoomsAtom).sort(factoryRoomIdByActivity(mx));
|
||||
const allRooms = useAtomValue(allRoomsAtom).toSorted(factoryRoomIdByActivity(mx));
|
||||
|
||||
const [result, search, resetSearch] = useAsyncSearch(
|
||||
allRooms,
|
||||
@@ -130,7 +133,7 @@ export function RoomMentionAutocomplete({
|
||||
const rId = autoCompleteRoomIds[0];
|
||||
const r = mx.getRoom(rId);
|
||||
const name = r?.name ?? rId;
|
||||
handleAutocomplete(r?.getCanonicalAlias() ?? rId, name);
|
||||
handleAutocomplete(r?.getCanonicalAlias() ?? rId ?? '', name as string);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,24 +1,27 @@
|
||||
import { useEffect, KeyboardEvent as ReactKeyboardEvent } from 'react';
|
||||
import { Editor } from 'slate';
|
||||
import type { KeyboardEvent as ReactKeyboardEvent } from 'react';
|
||||
import { useEffect } from 'react';
|
||||
import type { Editor } from 'slate';
|
||||
import { ReactEditor } from 'slate-react';
|
||||
import { Avatar, Icon, Icons, MenuItem, Text } from 'folds';
|
||||
import { MatrixClient, Room, RoomMember } from '$types/matrix-sdk';
|
||||
import type { MatrixClient, Room, RoomMember } from '$types/matrix-sdk';
|
||||
|
||||
import { useRoomMembers } from '$hooks/useRoomMembers';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { SearchItemStrGetter, UseAsyncSearchOptions, useAsyncSearch } from '$hooks/useAsyncSearch';
|
||||
import type { SearchItemStrGetter, UseAsyncSearchOptions } from '$hooks/useAsyncSearch';
|
||||
import { useAsyncSearch } from '$hooks/useAsyncSearch';
|
||||
import { onTabPress } from '$utils/keyboard';
|
||||
import { useKeyDown } from '$hooks/useKeyDown';
|
||||
import { getMxIdLocalPart, getMxIdServer, isUserId } from '$utils/matrix';
|
||||
import { getMemberDisplayName, getMemberSearchStr } from '$utils/room';
|
||||
import { UserAvatar } from '$components/user-avatar';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { Membership } from '$types/matrix/room';
|
||||
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { nicknamesAtom } from '$state/nicknames';
|
||||
import { createMentionElement, moveCursor, replaceWithElement } from '$components/editor/utils';
|
||||
import { AutocompleteMenu } from './AutocompleteMenu';
|
||||
import { AutocompleteQuery } from './autocompleteQuery';
|
||||
import type { AutocompleteQuery } from './autocompleteQuery';
|
||||
import { KnownMembership } from '$types/matrix-sdk';
|
||||
|
||||
type MentionAutoCompleteHandler = (userId: string, name: string) => void;
|
||||
|
||||
@@ -68,9 +71,9 @@ type UserMentionAutocompleteProps = {
|
||||
};
|
||||
|
||||
const withAllowedMembership = (member: RoomMember): boolean =>
|
||||
member.membership === Membership.Join ||
|
||||
member.membership === Membership.Invite ||
|
||||
member.membership === Membership.Knock;
|
||||
member.membership === KnownMembership.Join ||
|
||||
member.membership === KnownMembership.Invite ||
|
||||
member.membership === KnownMembership.Knock;
|
||||
|
||||
const SEARCH_OPTIONS: UseAsyncSearchOptions = {
|
||||
limit: 1000,
|
||||
@@ -137,7 +140,7 @@ export function UserMentionAutocomplete({
|
||||
handleAutocomplete(userId, userId);
|
||||
return;
|
||||
}
|
||||
const roomMember = autoCompleteMembers[0];
|
||||
const roomMember = autoCompleteMembers[0]!;
|
||||
handleAutocomplete(roomMember.userId, getName(roomMember));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { BaseRange, Editor } from 'slate';
|
||||
import type { BaseRange } from 'slate';
|
||||
import { Editor } from 'slate';
|
||||
|
||||
export enum AutocompletePrefix {
|
||||
RoomMention = '#',
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { Descendant, Text } from 'slate';
|
||||
import type { Descendant } from 'slate';
|
||||
import { Text } from 'slate';
|
||||
import parse from 'html-dom-parser';
|
||||
import { ChildNode, Element, isText, isTag } from 'domhandler';
|
||||
import type { ChildNode, Element } from 'domhandler';
|
||||
import { isText, isTag } from 'domhandler';
|
||||
|
||||
import { sanitizeCustomHtml } from '$utils/sanitize';
|
||||
import {
|
||||
@@ -11,7 +13,7 @@ import {
|
||||
} from '$plugins/matrix-to';
|
||||
import { escapeMarkdownInlineSequences, escapeMarkdownBlockSequences } from '$plugins/markdown';
|
||||
import { BlockType, MarkType } from './types';
|
||||
import {
|
||||
import type {
|
||||
BlockQuoteElement,
|
||||
CodeBlockElement,
|
||||
CodeLineElement,
|
||||
@@ -83,7 +85,12 @@ const getInlineMarkElement = (
|
||||
children.push({ text: mdSequence });
|
||||
return children;
|
||||
}
|
||||
return children.map((child) => (Text.isText(child) ? { ...child, [markType]: true } : child));
|
||||
return children.map((child) => {
|
||||
if (Text.isText(child)) {
|
||||
return { ...child, [markType]: true };
|
||||
}
|
||||
return child;
|
||||
});
|
||||
};
|
||||
|
||||
const getInlineNonMarkElement = (node: Element): MentionElement | EmoticonElement | undefined => {
|
||||
@@ -220,7 +227,7 @@ const parseCodeBlockNode = (node: Element): CodeBlockElement[] | ParagraphElemen
|
||||
type: BlockType.Paragraph,
|
||||
children: [{ text }],
|
||||
}));
|
||||
const childCode = node.children[0];
|
||||
const childCode = node.children[0]!;
|
||||
const className =
|
||||
isTag(childCode) && childCode.tagName === 'code' ? (childCode.attribs.class ?? '') : '';
|
||||
const prefix = { text: `${mdSequence}${className.replace('language-', '')}` };
|
||||
@@ -322,7 +329,7 @@ const parseHeadingNode = (
|
||||
|
||||
const headingMatch = node.name.match(/^h([123456])$/);
|
||||
const [, g1AsLevel] = headingMatch ?? ['h3', '3'];
|
||||
const level = Number.parseInt(g1AsLevel, 10);
|
||||
const level = Number.parseInt(g1AsLevel!, 10);
|
||||
|
||||
const mdSequence = node.attribs['data-md'];
|
||||
if (mdSequence !== undefined) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { isKeyHotkey } from 'is-hotkey';
|
||||
import { KeyboardEvent } from 'react';
|
||||
import type { KeyboardEvent } from 'react';
|
||||
import { Editor, Element as SlateElement, Range, Transforms } from 'slate';
|
||||
import { isAnyMarkActive, isBlockActive, removeAllMark, toggleBlock, toggleMark } from './utils';
|
||||
import { BlockType, MarkType } from './types';
|
||||
@@ -83,7 +83,7 @@ export const toggleKeyboardShortcut = (editor: Editor, event: KeyboardEvent): bo
|
||||
const blockToggled = BLOCK_KEYS.find((hotkey) => {
|
||||
if (isKeyHotkey(hotkey, event)) {
|
||||
event.preventDefault();
|
||||
toggleBlock(editor, BLOCK_HOTKEYS[hotkey]);
|
||||
toggleBlock(editor, BLOCK_HOTKEYS[hotkey]!);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -107,7 +107,7 @@ export const toggleKeyboardShortcut = (editor: Editor, event: KeyboardEvent): bo
|
||||
: INLINE_KEYS.find((hotkey) => {
|
||||
if (isKeyHotkey(hotkey, event)) {
|
||||
event.preventDefault();
|
||||
toggleMark(editor, INLINE_HOTKEYS[hotkey]);
|
||||
toggleMark(editor, INLINE_HOTKEYS[hotkey]!);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Descendant, Editor, Text } from 'slate';
|
||||
import { MatrixClient } from '$types/matrix-sdk';
|
||||
import type { Descendant, Editor } from 'slate';
|
||||
import { Text } from 'slate';
|
||||
import type { MatrixClient } from '$types/matrix-sdk';
|
||||
import { sanitizeText } from '$utils/sanitize';
|
||||
import {
|
||||
parseBlockMD,
|
||||
@@ -10,7 +11,7 @@ import {
|
||||
import { findAndReplace } from '$utils/findAndReplace';
|
||||
import { sanitizeForRegex } from '$utils/regex';
|
||||
import { isUserId } from '$utils/matrix';
|
||||
import { CustomElement } from './slate';
|
||||
import type { CustomElement } from './slate';
|
||||
import { BlockType } from './types';
|
||||
|
||||
export type OutputOptions = {
|
||||
|
||||
Vendored
+4
-4
@@ -1,7 +1,7 @@
|
||||
import { BaseEditor } from 'slate';
|
||||
import { ReactEditor } from 'slate-react';
|
||||
import { HistoryEditor } from 'slate-history';
|
||||
import { BlockType } from './types';
|
||||
import type { BaseEditor } from 'slate';
|
||||
import type { ReactEditor } from 'slate-react';
|
||||
import type { HistoryEditor } from 'slate-history';
|
||||
import type { BlockType } from './types';
|
||||
|
||||
export type HeadingLevel = 1 | 2 | 3;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { BasePoint, BaseRange, Editor, Element, Point, Range, Text, Transforms } from 'slate';
|
||||
import type { BasePoint, BaseRange } from 'slate';
|
||||
import { Editor, Element, Point, Range, Text, Transforms } from 'slate';
|
||||
import { BlockType, MarkType } from './types';
|
||||
import {
|
||||
import type {
|
||||
CommandElement,
|
||||
EmoticonElement,
|
||||
FormattedText,
|
||||
@@ -63,12 +64,12 @@ export const headingLevel = (editor: Editor): HeadingLevel | undefined => {
|
||||
};
|
||||
|
||||
type BlockOption = { level: HeadingLevel };
|
||||
const NESTED_BLOCK = [
|
||||
const NESTED_BLOCK = new Set([
|
||||
BlockType.OrderedList,
|
||||
BlockType.UnorderedList,
|
||||
BlockType.BlockQuote,
|
||||
BlockType.CodeBlock,
|
||||
];
|
||||
]);
|
||||
|
||||
export const toggleBlock = (editor: Editor, format: BlockType, option?: BlockOption) => {
|
||||
Transforms.collapse(editor, {
|
||||
@@ -77,7 +78,7 @@ export const toggleBlock = (editor: Editor, format: BlockType, option?: BlockOpt
|
||||
const isActive = isBlockActive(editor, format);
|
||||
|
||||
Transforms.unwrapNodes(editor, {
|
||||
match: (node) => Element.isElement(node) && NESTED_BLOCK.includes(node.type),
|
||||
match: (node) => Element.isElement(node) && NESTED_BLOCK.has(node.type),
|
||||
split: true,
|
||||
});
|
||||
|
||||
@@ -161,7 +162,6 @@ export const resetEditor = (editor: Editor) => {
|
||||
};
|
||||
|
||||
export const resetEditorHistory = (editor: Editor) => {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
editor.history = {
|
||||
undos: [],
|
||||
redos: [],
|
||||
@@ -242,7 +242,6 @@ export const getPointUntilChar = (
|
||||
reverse: options.reverse,
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const point of pointItr) {
|
||||
if (!Point.equals(point, cursorPoint) && prevPoint) {
|
||||
char = Editor.string(editor, { anchor: point, focus: prevPoint });
|
||||
|
||||
@@ -1,39 +1,41 @@
|
||||
import {
|
||||
import type {
|
||||
ChangeEventHandler,
|
||||
FocusEventHandler,
|
||||
MouseEventHandler,
|
||||
ReactNode,
|
||||
RefObject,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
} from 'react';
|
||||
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
||||
import { Box, config, Icons, Scroll } from 'folds';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { isKeyHotkey } from 'is-hotkey';
|
||||
import { Room } from '$types/matrix-sdk';
|
||||
import { atom, PrimitiveAtom, useAtom, useSetAtom } from 'jotai';
|
||||
import type { Room } from '$types/matrix-sdk';
|
||||
import type { PrimitiveAtom } from 'jotai';
|
||||
import { atom, useAtom, useSetAtom } from 'jotai';
|
||||
import { useVirtualizer } from '@tanstack/react-virtual';
|
||||
import { IEmoji, emojiGroups, emojis } from '$plugins/emoji';
|
||||
import type { IEmoji } from '$plugins/emoji';
|
||||
import { emojiGroups, emojis } from '$plugins/emoji';
|
||||
import { preventScrollWithArrowKey, stopPropagation } from '$utils/keyboard';
|
||||
import { useRelevantImagePacks } from '$hooks/useImagePacks';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { useRecentEmoji } from '$hooks/useRecentEmoji';
|
||||
import { isUserId, mxcUrlToHttp } from '$utils/matrix';
|
||||
import { editableActiveElement, targetFromEvent } from '$utils/dom';
|
||||
import { useAsyncSearch, UseAsyncSearchOptions } from '$hooks/useAsyncSearch';
|
||||
import type { UseAsyncSearchOptions } from '$hooks/useAsyncSearch';
|
||||
import { useAsyncSearch } from '$hooks/useAsyncSearch';
|
||||
import { useDebounce } from '$hooks/useDebounce';
|
||||
import { useThrottle } from '$hooks/useThrottle';
|
||||
import { addRecentEmoji } from '$plugins/recent-emoji';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { ImagePack, ImageUsage, PackImageReader } from '$plugins/custom-emoji';
|
||||
import type { ImagePack, PackImageReader } from '$plugins/custom-emoji';
|
||||
import { ImageUsage } from '$plugins/custom-emoji';
|
||||
import { getEmoticonSearchStr } from '$plugins/utils';
|
||||
import { VirtualTile } from '$components/virtualizer';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
import { settingsAtom } from '$state/settings';
|
||||
import { useEmojiGroupIcons } from './useEmojiGroupIcons';
|
||||
import { useEmojiGroupLabels } from './useEmojiGroupLabels';
|
||||
import type { PreviewData } from './components';
|
||||
import {
|
||||
SearchInput,
|
||||
EmojiBoardTabs,
|
||||
@@ -43,7 +45,6 @@ import {
|
||||
NoStickerPacks,
|
||||
createPreviewDataAtom,
|
||||
Preview,
|
||||
PreviewData,
|
||||
EmojiItem,
|
||||
StickerItem,
|
||||
CustomEmojiItem,
|
||||
@@ -97,7 +98,7 @@ const useGroups = (
|
||||
name: label ?? 'Unknown',
|
||||
items: pack
|
||||
.getImages(ImageUsage.Emoticon)
|
||||
.sort((a, b) => a.shortcode.localeCompare(b.shortcode)),
|
||||
.toSorted((a, b) => a.shortcode.localeCompare(b.shortcode)),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -125,7 +126,7 @@ const useGroups = (
|
||||
name: label ?? 'Unknown',
|
||||
items: pack
|
||||
.getImages(ImageUsage.Sticker)
|
||||
.sort((a, b) => a.shortcode.localeCompare(b.shortcode)),
|
||||
.toSorted((a, b) => a.shortcode.localeCompare(b.shortcode)),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -600,7 +601,7 @@ export function EmojiBoard({
|
||||
}}
|
||||
>
|
||||
{vItems.map((vItem) => {
|
||||
const group = groups[vItem.index];
|
||||
const group = groups[vItem.index]!;
|
||||
|
||||
return (
|
||||
<VirtualTile
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { as, Box, Text } from 'folds';
|
||||
import { ReactNode } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import * as css from './styles.css';
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { Box } from 'folds';
|
||||
import { MatrixClient } from '$types/matrix-sdk';
|
||||
import { PackImageReader } from '$plugins/custom-emoji';
|
||||
import { IEmoji } from '$plugins/emoji';
|
||||
import type { MatrixClient } from '$types/matrix-sdk';
|
||||
import type { PackImageReader } from '$plugins/custom-emoji';
|
||||
import type { IEmoji } from '$plugins/emoji';
|
||||
import { mxcUrlToHttp } from '$utils/matrix';
|
||||
import { EmojiItemInfo, EmojiType } from '$components/emoji-board/types';
|
||||
import type { EmojiItemInfo } from '$components/emoji-board/types';
|
||||
import { EmojiType } from '$components/emoji-board/types';
|
||||
import * as css from './styles.css';
|
||||
|
||||
const ANIMATED_MIME_TYPES = new Set(['image/gif', 'image/apng']);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { as, Box, Line } from 'folds';
|
||||
import { ReactNode } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import * as css from './styles.css';
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Box, Text } from 'folds';
|
||||
import { Atom, atom, useAtomValue } from 'jotai';
|
||||
import type { Atom } from 'jotai';
|
||||
import { atom, useAtomValue } from 'jotai';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { mxcUrlToHttp } from '$utils/matrix';
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ChangeEventHandler, useRef } from 'react';
|
||||
import type { ChangeEventHandler } from 'react';
|
||||
import { useRef } from 'react';
|
||||
import { Input, Chip, Icon, Icons, Text } from 'folds';
|
||||
import { mobileOrTablet } from '$utils/user-agent';
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ReactNode } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import type { IconSrc } from 'folds';
|
||||
import {
|
||||
Box,
|
||||
Scroll,
|
||||
@@ -9,7 +10,6 @@ import {
|
||||
Text,
|
||||
IconButton,
|
||||
Icon,
|
||||
IconSrc,
|
||||
Icons,
|
||||
} from 'folds';
|
||||
import classNames from 'classnames';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CSSProperties } from 'react';
|
||||
import type { CSSProperties } from 'react';
|
||||
import { Badge, Box, Text } from 'folds';
|
||||
import { EmojiBoardTab } from '$components/emoji-board/types';
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useMemo } from 'react';
|
||||
import { IconSrc, Icons } from 'folds';
|
||||
import type { IconSrc } from 'folds';
|
||||
import { Icons } from 'folds';
|
||||
|
||||
import { EmojiGroupId } from '$plugins/emoji';
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
color,
|
||||
config,
|
||||
} from 'folds';
|
||||
import { IContent, MatrixEvent, Room } from '$types/matrix-sdk';
|
||||
import type { IContent, MatrixEvent, Room } from '$types/matrix-sdk';
|
||||
import { getMemberDisplayName } from '$utils/room';
|
||||
import { getMxIdLocalPart } from '$utils/matrix';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
@@ -30,17 +30,18 @@ import { useSetting } from '$state/hooks/settings';
|
||||
import { settingsAtom } from '$state/settings';
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
import { getReactCustomHtmlParser, LINKIFY_OPTS } from '$plugins/react-custom-html-parser';
|
||||
import { Opts as LinkifyOpts } from 'linkifyjs';
|
||||
import { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import type { Opts as LinkifyOpts } from 'linkifyjs';
|
||||
import type { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import { useSpoilerClickHandler } from '$hooks/useSpoilerClickHandler';
|
||||
import { modalAtom, ModalType } from '$state/modal';
|
||||
import { roomIdToReplyDraftAtomFamily } from '$state/room/roomInputDrafts';
|
||||
import { useRoomPermissions } from '$hooks/useRoomPermissions';
|
||||
import { useRoomCreators } from '$hooks/useRoomCreators';
|
||||
import { usePowerLevelsContext } from '$hooks/usePowerLevels';
|
||||
import { MessageEvent } from '$types/matrix/room';
|
||||
|
||||
import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl';
|
||||
import * as css from './EventHistory.css';
|
||||
import { EventType } from '$types/matrix-sdk';
|
||||
|
||||
export type EventHistoryProps = {
|
||||
room: Room;
|
||||
@@ -59,7 +60,7 @@ export const EventHistory = as<'div', EventHistoryProps>(
|
||||
const getName = (userId: string) =>
|
||||
getMemberDisplayName(room, userId, nicknames) ?? getMxIdLocalPart(userId) ?? userId;
|
||||
|
||||
const readerId = mEvents[0].event.sender ?? '';
|
||||
const readerId = mEvents[0]?.event.sender ?? '';
|
||||
const name = getName(readerId ?? '');
|
||||
const avatarMxcUrl = room.getMember(readerId ?? '')?.getMxcAvatarUrl();
|
||||
const avatarUrl = avatarMxcUrl
|
||||
@@ -73,7 +74,7 @@ export const EventHistory = as<'div', EventHistoryProps>(
|
||||
const spoilerClickHandler = useSpoilerClickHandler();
|
||||
const htmlReactParserOptions = useMemo<HTMLReactParserOptions>(
|
||||
() =>
|
||||
getReactCustomHtmlParser(mx, mEvents[0].getRoomId(), {
|
||||
getReactCustomHtmlParser(mx, mEvents[0]!.getRoomId(), {
|
||||
settingsLinkBaseUrl,
|
||||
linkifyOpts,
|
||||
useAuthentication,
|
||||
@@ -85,8 +86,8 @@ export const EventHistory = as<'div', EventHistoryProps>(
|
||||
const creators = useRoomCreators(room);
|
||||
const permissions = useRoomPermissions(creators, powerLevels);
|
||||
const canRedact = permissions.action('redact', mx.getSafeUserId());
|
||||
const canDeleteOwn = permissions.event(MessageEvent.RoomRedaction, mx.getSafeUserId());
|
||||
const canDelete = canRedact || (canDeleteOwn && mEvents[0].getSender() === mx.getUserId());
|
||||
const canDeleteOwn = permissions.event(EventType.RoomRedaction, mx.getSafeUserId());
|
||||
const canDelete = canRedact || (canDeleteOwn && mEvents[0]?.getSender() === mx.getUserId());
|
||||
|
||||
const setReplyDraft = useSetAtom(roomIdToReplyDraftAtomFamily(room.roomId));
|
||||
const triggerReply = useCallback(
|
||||
@@ -269,11 +270,16 @@ export const EventHistory = as<'div', EventHistoryProps>(
|
||||
<Scroll visibility="Hover">
|
||||
<Box className={css.Content} direction="Column">
|
||||
{mEvents.map((mEvent) => {
|
||||
if (!mEvent.event.sender) return <div />;
|
||||
if (!mEvent.event.sender) return <div key={mEvent.event.event_id} />;
|
||||
const EventContent = mEvent.getOriginalContent();
|
||||
return (
|
||||
<>
|
||||
<hr style={{ width: '100%', color: color.Surface.ContainerLine }} />
|
||||
<hr
|
||||
style={{
|
||||
width: '100%',
|
||||
color: color.Surface.ContainerLine,
|
||||
}}
|
||||
/>
|
||||
<EventItem mEvent={mEvent} EventContent={EventContent} />
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
as,
|
||||
config,
|
||||
} from 'folds';
|
||||
import { Room } from '$types/matrix-sdk';
|
||||
import type { Room } from '$types/matrix-sdk';
|
||||
import { useRoomEventReaders } from '$hooks/useRoomEventReaders';
|
||||
import { getMemberDisplayName } from '$utils/room';
|
||||
import { getMxIdLocalPart } from '$utils/matrix';
|
||||
|
||||
@@ -8,12 +8,12 @@ export type ImageEditorProps = {
|
||||
requestClose: () => void;
|
||||
};
|
||||
|
||||
const handleApply = () => {
|
||||
//
|
||||
};
|
||||
|
||||
export const ImageEditor = as<'div', ImageEditorProps>(
|
||||
({ className, name, url, requestClose, ...props }, ref) => {
|
||||
const handleApply = () => {
|
||||
//
|
||||
};
|
||||
|
||||
return (
|
||||
<Box
|
||||
className={classNames(css.ImageEditor, className)}
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { as, Box, Text, config, Button, Menu, Spinner } from 'folds';
|
||||
import {
|
||||
ImagePack,
|
||||
ImageUsage,
|
||||
PackContent,
|
||||
PackImage,
|
||||
PackImageReader,
|
||||
packMetaEqual,
|
||||
PackMetaReader,
|
||||
} from '$plugins/custom-emoji';
|
||||
import type { ImagePack, ImageUsage, PackContent, PackImage } from '$plugins/custom-emoji';
|
||||
import { PackImageReader, packMetaEqual, PackMetaReader } from '$plugins/custom-emoji';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { useFilePicker } from '$hooks/useFilePicker';
|
||||
import { UploadSuccess } from '$state/upload';
|
||||
import { getImageInfo, TUploadContent } from '$utils/matrix';
|
||||
import type { UploadSuccess } from '$state/upload';
|
||||
import type { TUploadContent } from '$utils/matrix';
|
||||
import { getImageInfo } from '$utils/matrix';
|
||||
import { getImageFileUrl, loadImageElement, renameFile } from '$utils/dom';
|
||||
import { replaceSpaceWithDash, suffixRename } from '$utils/common';
|
||||
import { getFileNameWithoutExt } from '$utils/mimeTypes';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Box, IconButton, Text, Icon, Icons, Scroll, Chip } from 'folds';
|
||||
import { PackAddress } from '$plugins/custom-emoji';
|
||||
import type { PackAddress } from '$plugins/custom-emoji';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { Page, PageHeader, PageContent } from '$components/page';
|
||||
import { RoomImagePack } from './RoomImagePack';
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { FormEventHandler, ReactNode, useMemo, useState } from 'react';
|
||||
import type { FormEventHandler, ReactNode } from 'react';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { Badge, Box, Button, Chip, Icon, Icons, Input, Text } from 'folds';
|
||||
import { mxcUrlToHttp } from '$utils/matrix';
|
||||
import { ImageUsage, imageUsageEqual, PackImageReader } from '$plugins/custom-emoji';
|
||||
import type { ImageUsage } from '$plugins/custom-emoji';
|
||||
import { imageUsageEqual, PackImageReader } from '$plugins/custom-emoji';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { useObjectURL } from '$hooks/useObjectURL';
|
||||
import { createUploadAtom, TUploadAtom } from '$state/upload';
|
||||
import type { TUploadAtom } from '$state/upload';
|
||||
import { createUploadAtom } from '$state/upload';
|
||||
import { replaceSpaceWithDash } from '$utils/common';
|
||||
import { SettingTile } from '$components/setting-tile';
|
||||
import * as css from './style.css';
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { FormEventHandler, useCallback, useMemo, useState } from 'react';
|
||||
import type { FormEventHandler } from 'react';
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Text,
|
||||
@@ -21,7 +22,8 @@ import { LINKIFY_OPTS } from '$plugins/react-custom-html-parser';
|
||||
import { ContainerColor } from '$styles/ContainerColor.css';
|
||||
import { useFilePicker } from '$hooks/useFilePicker';
|
||||
import { useObjectURL } from '$hooks/useObjectURL';
|
||||
import { createUploadAtom, UploadSuccess } from '$state/upload';
|
||||
import type { UploadSuccess } from '$state/upload';
|
||||
import { createUploadAtom } from '$state/upload';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { PackMetaReader } from '$plugins/custom-emoji';
|
||||
import { CompactUploadCardRenderer } from '$components/upload-card';
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { Room } from '$types/matrix-sdk';
|
||||
import type { Room } from '$types/matrix-sdk';
|
||||
import { usePowerLevels } from '$hooks/usePowerLevels';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { ImagePack, PackContent } from '$plugins/custom-emoji';
|
||||
import { StateEvent } from '$types/matrix/room';
|
||||
import type { PackContent } from '$plugins/custom-emoji';
|
||||
import { ImagePack } from '$plugins/custom-emoji';
|
||||
|
||||
import { useRoomImagePack } from '$hooks/useImagePacks';
|
||||
import { randomStr } from '$utils/common';
|
||||
import { useRoomPermissions } from '$hooks/useRoomPermissions';
|
||||
import { useRoomCreators } from '$hooks/useRoomCreators';
|
||||
import { ImagePackContent } from './ImagePackContent';
|
||||
import { CustomStateEvent } from '$types/matrix/room';
|
||||
|
||||
type RoomImagePackProps = {
|
||||
room: Room;
|
||||
@@ -22,7 +24,7 @@ export function RoomImagePack({ room, stateKey }: RoomImagePackProps) {
|
||||
const creators = useRoomCreators(room);
|
||||
|
||||
const permissions = useRoomPermissions(creators, powerLevels);
|
||||
const canEditImagePack = permissions.stateEvent(StateEvent.PoniesRoomEmotes, userId);
|
||||
const canEditImagePack = permissions.stateEvent(CustomStateEvent.PoniesRoomEmotes, userId);
|
||||
|
||||
const fallbackPack = useMemo(() => {
|
||||
const fakePackId = randomStr(4);
|
||||
@@ -44,7 +46,7 @@ export function RoomImagePack({ room, stateKey }: RoomImagePackProps) {
|
||||
|
||||
await mx.sendStateEvent(
|
||||
address.roomId,
|
||||
StateEvent.PoniesRoomEmotes,
|
||||
CustomStateEvent.PoniesRoomEmotes,
|
||||
packContent,
|
||||
address.stateKey
|
||||
);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { MouseEventHandler, useMemo, useState } from 'react';
|
||||
import { Box, Button, config, Icon, Icons, Menu, MenuItem, PopOut, RectCords, Text } from 'folds';
|
||||
import type { MouseEventHandler } from 'react';
|
||||
import { useMemo, useState } from 'react';
|
||||
import type { RectCords } from 'folds';
|
||||
import { Box, Button, config, Icon, Icons, Menu, MenuItem, PopOut, Text } from 'folds';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { ImageUsage } from '$plugins/custom-emoji';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { ImagePack, PackContent } from '$plugins/custom-emoji';
|
||||
import type { PackContent } from '$plugins/custom-emoji';
|
||||
import { ImagePack } from '$plugins/custom-emoji';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { AccountDataEvent } from '$types/matrix/accountData';
|
||||
|
||||
import { useUserImagePack } from '$hooks/useImagePacks';
|
||||
import { ImagePackContent } from './ImagePackContent';
|
||||
import { CustomAccountDataEvent } from '$types/matrix/accountData';
|
||||
|
||||
export function UserImagePack() {
|
||||
const mx = useMatrixClient();
|
||||
@@ -13,7 +15,7 @@ export function UserImagePack() {
|
||||
|
||||
const handleUpdate = useCallback(
|
||||
async (packContent: PackContent) => {
|
||||
await mx.setAccountData(AccountDataEvent.PoniesUserEmotes, packContent);
|
||||
await mx.setAccountData(CustomAccountDataEvent.PoniesUserEmotes, packContent);
|
||||
},
|
||||
[mx]
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Box, ContainerColor, Text } from 'folds';
|
||||
import { ReactNode } from 'react';
|
||||
import type { ContainerColor } from 'folds';
|
||||
import { Box, Text } from 'folds';
|
||||
import type { ReactNode } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { BreakWord } from '$styles/Text.css';
|
||||
import { ContainerColor as ContainerClr } from '$styles/ContainerColor.css';
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
import {
|
||||
ChangeEventHandler,
|
||||
FormEventHandler,
|
||||
KeyboardEventHandler,
|
||||
useCallback,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import type { ChangeEventHandler, FormEventHandler, KeyboardEventHandler } from 'react';
|
||||
import { useCallback, useMemo, useRef, useState } from 'react';
|
||||
import {
|
||||
Overlay,
|
||||
OverlayBackdrop,
|
||||
@@ -29,19 +22,21 @@ import {
|
||||
Scroll,
|
||||
MenuItem,
|
||||
} from 'folds';
|
||||
import { Room } from '$types/matrix-sdk';
|
||||
import type { Room } from '$types/matrix-sdk';
|
||||
import { isKeyHotkey } from 'is-hotkey';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import { useDirectUsers } from '$hooks/useDirectUsers';
|
||||
import { getMxIdLocalPart, getMxIdServer, isUserId } from '$utils/matrix';
|
||||
import { Membership } from '$types/matrix/room';
|
||||
import { useAsyncSearch, UseAsyncSearchOptions } from '$hooks/useAsyncSearch';
|
||||
|
||||
import type { UseAsyncSearchOptions } from '$hooks/useAsyncSearch';
|
||||
import { useAsyncSearch } from '$hooks/useAsyncSearch';
|
||||
import { highlightText, makeHighlightRegex } from '$plugins/react-custom-html-parser';
|
||||
import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { BreakWord } from '$styles/Text.css';
|
||||
import { useAlive } from '$hooks/useAlive';
|
||||
import { KnownMembership } from '$types/matrix-sdk';
|
||||
|
||||
const SEARCH_OPTIONS: UseAsyncSearchOptions = {
|
||||
limit: 1000,
|
||||
@@ -67,7 +62,7 @@ export function InviteUserPrompt({ room, requestClose }: InviteUserProps) {
|
||||
() =>
|
||||
directUsers.filter((userId) => {
|
||||
const membership = room.getMember(userId)?.membership;
|
||||
return membership !== Membership.Join;
|
||||
return membership !== KnownMembership.Join;
|
||||
}),
|
||||
[directUsers, room]
|
||||
);
|
||||
@@ -146,6 +141,7 @@ export function InviteUserPrompt({ room, requestClose }: InviteUserProps) {
|
||||
if (isKeyHotkey('tab', evt) && result && result.items.length > 0) {
|
||||
evt.preventDefault();
|
||||
const userId = result.items[0];
|
||||
if (!userId) return;
|
||||
handleUserId(userId);
|
||||
}
|
||||
};
|
||||
@@ -215,9 +211,20 @@ export function InviteUserPrompt({ room, requestClose }: InviteUserProps) {
|
||||
}}
|
||||
>
|
||||
<Box style={{ position: 'relative' }}>
|
||||
<Menu style={{ position: 'absolute', top: 0, zIndex: 1, width: '100%' }}>
|
||||
<Menu
|
||||
style={{
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
zIndex: 1,
|
||||
width: '100%',
|
||||
}}
|
||||
>
|
||||
<Scroll size="300" style={{ maxHeight: toRem(100) }}>
|
||||
<div style={{ padding: config.space.S100 }}>
|
||||
<div
|
||||
style={{
|
||||
padding: config.space.S100,
|
||||
}}
|
||||
>
|
||||
{result.items.map((userId) => {
|
||||
const username = `${getMxIdLocalPart(userId)}`;
|
||||
const userServer = getMxIdServer(userId);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { FormEventHandler, useState } from 'react';
|
||||
import type { FormEventHandler } from 'react';
|
||||
import { useState } from 'react';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import {
|
||||
Dialog,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useCallback, useEffect, FormEventHandler } from 'react';
|
||||
import type { FormEventHandler } from 'react';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import {
|
||||
Dialog,
|
||||
@@ -17,7 +18,7 @@ import {
|
||||
Button,
|
||||
Spinner,
|
||||
} from 'folds';
|
||||
import { MatrixError } from '$types/matrix-sdk';
|
||||
import type { MatrixError } from '$types/matrix-sdk';
|
||||
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
Button,
|
||||
Spinner,
|
||||
} from 'folds';
|
||||
import { MatrixError } from '$types/matrix-sdk';
|
||||
import type { MatrixError } from '$types/matrix-sdk';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
Button,
|
||||
Spinner,
|
||||
} from 'folds';
|
||||
import { MatrixError } from '$types/matrix-sdk';
|
||||
import type { MatrixError } from '$types/matrix-sdk';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ImgHTMLAttributes, forwardRef } from 'react';
|
||||
import type { ImgHTMLAttributes } from 'react';
|
||||
import { forwardRef } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import * as css from './media.css';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ReactNode } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { Box, as } from 'folds';
|
||||
|
||||
export type MediaControlProps = {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { VideoHTMLAttributes, forwardRef, useEffect, useRef } from 'react';
|
||||
import type { VideoHTMLAttributes } from 'react';
|
||||
import { forwardRef, useEffect, useRef } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import * as css from './media.css';
|
||||
|
||||
export const Video = forwardRef<HTMLVideoElement, VideoHTMLAttributes<HTMLVideoElement>>(
|
||||
({ className, ...props }, ref) => (
|
||||
// eslint-disable-next-line jsx-a11y/media-has-caption
|
||||
// oxlint-disable-next-line jsx-a11y/media-has-caption
|
||||
<video className={classNames(css.Video, className)} {...props} ref={ref} />
|
||||
)
|
||||
);
|
||||
|
||||
Loaded 100 of 616 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user