Use globalThis and React.JSX in the browser code. [skip build]
This commit is contained in:
@@ -24,7 +24,7 @@ export function AngleSelector({
|
|||||||
onChange,
|
onChange,
|
||||||
size = 80,
|
size = 80,
|
||||||
disabled = false,
|
disabled = false,
|
||||||
}: AngleSelectorProps): JSX.Element {
|
}: AngleSelectorProps): React.JSX.Element {
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const [isDragging, setIsDragging] = useState(false);
|
const [isDragging, setIsDragging] = useState(false);
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ import {
|
|||||||
import { MessageLayout, MessageSpacing } from '../../../state/settings';
|
import { MessageLayout, MessageSpacing } from '../../../state/settings';
|
||||||
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
||||||
import { useEmojiUsage } from '../../../hooks/useEmojiUsage';
|
import { useEmojiUsage } from '../../../hooks/useEmojiUsage';
|
||||||
import { emojis } from '../../../plugins/emoji';
|
import { IEmoji, emojis } from '../../../plugins/emoji';
|
||||||
import * as css from './styles.css';
|
import * as css from './styles.css';
|
||||||
import { EventReaders } from '../../../components/event-readers';
|
import { EventReaders } from '../../../components/event-readers';
|
||||||
import { TextViewer } from '../../../components/text-viewer';
|
import { TextViewer } from '../../../components/text-viewer';
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ export const renderMatrixMention = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const factoryRenderLinkifyWithMention = (
|
export const factoryRenderLinkifyWithMention = (
|
||||||
mentionRender: (href: string) => JSX.Element | undefined,
|
mentionRender: (href: string) => React.JSX.Element | undefined,
|
||||||
): OptFn<(ir: IntermediateRepresentation) => any> => {
|
): OptFn<(ir: IntermediateRepresentation) => any> => {
|
||||||
const render: OptFn<(ir: IntermediateRepresentation) => any> = ({
|
const render: OptFn<(ir: IntermediateRepresentation) => any> = ({
|
||||||
tagName,
|
tagName,
|
||||||
@@ -205,7 +205,7 @@ export const factoryRenderLinkifyWithMention = (
|
|||||||
return render;
|
return render;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const scaleSystemEmoji = (text: string): (string | JSX.Element)[] =>
|
export const scaleSystemEmoji = (text: string): (string | React.JSX.Element)[] =>
|
||||||
findAndReplace(
|
findAndReplace(
|
||||||
text,
|
text,
|
||||||
EMOJI_REG_G,
|
EMOJI_REG_G,
|
||||||
@@ -231,8 +231,8 @@ export const makeHighlightRegex = (highlights: string[]): RegExp | undefined =>
|
|||||||
|
|
||||||
export const highlightText = (
|
export const highlightText = (
|
||||||
regex: RegExp,
|
regex: RegExp,
|
||||||
data: (string | JSX.Element)[],
|
data: (string | React.JSX.Element)[],
|
||||||
): (string | JSX.Element)[] =>
|
): (string | React.JSX.Element)[] =>
|
||||||
data.flatMap((text) => {
|
data.flatMap((text) => {
|
||||||
if (typeof text !== 'string') return text;
|
if (typeof text !== 'string') return text;
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ let handlingKeyConflict = false;
|
|||||||
|
|
||||||
const deleteIndexedDB = (dbName: string): Promise<void> =>
|
const deleteIndexedDB = (dbName: string): Promise<void> =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
const request = global.indexedDB.deleteDatabase(dbName);
|
const request = globalThis.indexedDB.deleteDatabase(dbName);
|
||||||
request.onsuccess = () => {
|
request.onsuccess = () => {
|
||||||
console.log(`[initMatrix] Deleted IndexedDB database: ${dbName}`);
|
console.log(`[initMatrix] Deleted IndexedDB database: ${dbName}`);
|
||||||
resolve();
|
resolve();
|
||||||
@@ -108,7 +108,7 @@ const deleteIndexedDB = (dbName: string): Promise<void> =>
|
|||||||
|
|
||||||
const getAllIndexedDBNames = async (): Promise<string[]> => {
|
const getAllIndexedDBNames = async (): Promise<string[]> => {
|
||||||
try {
|
try {
|
||||||
if ('databases' in global.indexedDB) {
|
if ('databases' in globalThis.indexedDB) {
|
||||||
// Add timeout to prevent hanging
|
// Add timeout to prevent hanging
|
||||||
const timeoutPromise = new Promise<string[]>((resolve) => {
|
const timeoutPromise = new Promise<string[]>((resolve) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -117,7 +117,7 @@ const getAllIndexedDBNames = async (): Promise<string[]> => {
|
|||||||
}, 2000);
|
}, 2000);
|
||||||
});
|
});
|
||||||
|
|
||||||
const databasesPromise = (global.indexedDB as any)
|
const databasesPromise = (globalThis.indexedDB as any)
|
||||||
.databases()
|
.databases()
|
||||||
.then((dbs: any[]) => dbs.map((db: any) => db.name).filter(Boolean));
|
.then((dbs: any[]) => dbs.map((db: any) => db.name).filter(Boolean));
|
||||||
|
|
||||||
@@ -300,12 +300,12 @@ export const initClient = async (session: Session): Promise<MatrixClient> => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const indexedDBStore = new IndexedDBStore({
|
const indexedDBStore = new IndexedDBStore({
|
||||||
indexedDB: global.indexedDB,
|
indexedDB: globalThis.indexedDB,
|
||||||
localStorage: global.localStorage,
|
localStorage: globalThis.localStorage,
|
||||||
dbName: storeName.sync,
|
dbName: storeName.sync,
|
||||||
});
|
});
|
||||||
|
|
||||||
const legacyCryptoStore = new IndexedDBCryptoStore(global.indexedDB, storeName.crypto);
|
const legacyCryptoStore = new IndexedDBCryptoStore(globalThis.indexedDB, storeName.crypto);
|
||||||
|
|
||||||
const mx = createClient({
|
const mx = createClient({
|
||||||
baseUrl: session.baseUrl,
|
baseUrl: session.baseUrl,
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ function fetchConfig(token?: string): RequestInit | undefined {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.addEventListener('activate', (event: ExtendableEvent) => {
|
self.addEventListener('activate', (event: ExtendableEvent) => {
|
||||||
event.waitUntil(clients.claim());
|
event.waitUntil(self.clients.claim());
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener('fetch', (event: FetchEvent) => {
|
self.addEventListener('fetch', (event: FetchEvent) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user