@vector-im/matrix-wysiwyg 2.40.0 → 2.42.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/constants.d.ts +2 -0
- package/dist/lib/conversion.d.ts +4 -0
- package/dist/lib/types.d.ts +36 -0
- package/dist/lib/useComposerModel.d.ts +11 -0
- package/dist/lib/useListeners/types.d.ts +27 -0
- package/dist/lib/useTestCases/types.d.ts +5 -0
- package/dist/lib/useWysiwyg.d.ts +26 -0
- package/dist/matrix-wysiwyg.js +814 -996
- package/dist/matrix-wysiwyg.umd.cjs +4 -11
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/package.json +7 -6
- package/package.json +22 -21
- package/dist/index.d.ts +0 -98
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/pkg/wysiwyg.d.ts +0 -265
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/pkg/wysiwyg_bg.cjs +0 -1838
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/pkg/wysiwyg_bg.js +0 -1849
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/pkg/wysiwyg_bg.wasm +0 -0
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/pkg/wysiwyg_bg.wasm.d.ts +0 -136
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const ACTION_TYPES: readonly ["bold", "italic", "strikeThrough", "underline", "undo", "redo", "orderedList", "unorderedList", "inlineCode", "clear", "link", "codeBlock", "quote", "indent", "unindent"];
|
|
2
|
+
export declare const SUGGESTIONS: readonly ["@", "#", "/", "", ":"];
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const markdownToPlain: (markdown: string) => string;
|
|
2
|
+
export declare function richToPlain(richText: string, inMessageFormat: boolean): Promise<string>;
|
|
3
|
+
export declare function plainToRich(plainText: string, inMessageFormat: boolean): Promise<string>;
|
|
4
|
+
export declare function plainTextInnerHtmlToMarkdown(innerHtml: string): string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ComposerUpdate } from '@vector-im/matrix-wysiwyg-wasm';
|
|
2
|
+
import { ACTION_TYPES, SUGGESTIONS } from './constants';
|
|
3
|
+
import { AllowedMentionAttributes, LinkEvent } from './useListeners/types';
|
|
4
|
+
export type BlockType = InputEvent['inputType'] | 'formatInlineCode' | 'clear';
|
|
5
|
+
export type WysiwygInputEvent = ClipboardEvent | LinkEvent | (InputEvent & {
|
|
6
|
+
inputType: BlockType;
|
|
7
|
+
data?: string | null;
|
|
8
|
+
});
|
|
9
|
+
export type WysiwygEvent = WysiwygInputEvent | KeyboardEvent;
|
|
10
|
+
export type ActionTypes = (typeof ACTION_TYPES)[number];
|
|
11
|
+
export type ActionState = 'enabled' | 'reversed' | 'disabled';
|
|
12
|
+
export type AllActionStates = Record<ActionTypes, ActionState>;
|
|
13
|
+
export type FormattingFunctions = Record<Exclude<ActionTypes, 'link'>, () => void> & {
|
|
14
|
+
insertText: (text: string) => void;
|
|
15
|
+
link: (url: string, text?: string) => void;
|
|
16
|
+
mention: (url: string, text: string, attributes: AllowedMentionAttributes) => void;
|
|
17
|
+
mentionAtRoom: (attributes: AllowedMentionAttributes) => void;
|
|
18
|
+
command: (text: string) => void;
|
|
19
|
+
emoji: (text: string) => void;
|
|
20
|
+
removeLinks: () => void;
|
|
21
|
+
getLink: () => string;
|
|
22
|
+
};
|
|
23
|
+
export type Wysiwyg = {
|
|
24
|
+
actions: FormattingFunctions;
|
|
25
|
+
content: () => string;
|
|
26
|
+
messageContent: () => string;
|
|
27
|
+
};
|
|
28
|
+
export type InputEventProcessor = (event: WysiwygEvent, wysiwyg: Wysiwyg, editor: HTMLElement) => WysiwygEvent | null;
|
|
29
|
+
export type SuggestionChar = (typeof SUGGESTIONS)[number] | '';
|
|
30
|
+
export type SuggestionType = 'mention' | 'command' | 'custom' | 'emoji' | 'unknown';
|
|
31
|
+
export type MappedSuggestion = {
|
|
32
|
+
keyChar: SuggestionChar;
|
|
33
|
+
text: string;
|
|
34
|
+
type: SuggestionType;
|
|
35
|
+
};
|
|
36
|
+
export type TraceAction = (update: ComposerUpdate | null, name: string, value1?: string | number, value2?: string | number) => ComposerUpdate | null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { ComposerModel } from '@vector-im/matrix-wysiwyg-wasm';
|
|
3
|
+
/**
|
|
4
|
+
* Initialise the WASM module, or do nothing if it is already initialised.
|
|
5
|
+
* Safe to call concurrently — all callers share the same underlying promise.
|
|
6
|
+
*/
|
|
7
|
+
export declare function initOnce(): Promise<void>;
|
|
8
|
+
export declare function useComposerModel(editorRef: RefObject<HTMLElement | null>, initialContent?: string, customSuggestionPatterns?: Array<string>): {
|
|
9
|
+
composerModel: ComposerModel | null;
|
|
10
|
+
onError: (initialContent?: string) => Promise<void>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BlockType } from '../types';
|
|
2
|
+
export type FormatBlockEvent = CustomEvent<{
|
|
3
|
+
blockType: BlockType;
|
|
4
|
+
data?: string;
|
|
5
|
+
}>;
|
|
6
|
+
export type LinkEvent = Omit<InputEvent, 'data'> & {
|
|
7
|
+
inputType: 'insertLink';
|
|
8
|
+
data: {
|
|
9
|
+
url: string;
|
|
10
|
+
text?: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export type AllowedMentionAttributes = Map<'style' | 'data-mention-type', string>;
|
|
14
|
+
export type SuggestionEvent = Omit<InputEvent, 'data'> & {
|
|
15
|
+
inputType: 'insertSuggestion';
|
|
16
|
+
data: {
|
|
17
|
+
url: string;
|
|
18
|
+
text: string;
|
|
19
|
+
attributes: AllowedMentionAttributes;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export type AtRoomSuggestionEvent = Omit<InputEvent, 'data'> & {
|
|
23
|
+
inputType: 'insertAtRoomSuggestion';
|
|
24
|
+
data: {
|
|
25
|
+
attributes: AllowedMentionAttributes;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { useTestCases } from './useTestCases';
|
|
2
|
+
export type TestUtilities = ReturnType<typeof useTestCases>['utilities'];
|
|
3
|
+
export type SelectTuple = ['select', number, number];
|
|
4
|
+
export type Tuple = SelectTuple | [string, (string | number)?, (string | number)?];
|
|
5
|
+
export type Actions = Array<Tuple>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { AllActionStates, FormattingFunctions, InputEventProcessor, MappedSuggestion, TraceAction } from './types.js';
|
|
3
|
+
export { richToPlain, plainToRich } from './conversion';
|
|
4
|
+
export type WysiwygProps = {
|
|
5
|
+
isAutoFocusEnabled?: boolean;
|
|
6
|
+
inputEventProcessor?: InputEventProcessor;
|
|
7
|
+
initialContent?: string;
|
|
8
|
+
emojiSuggestions?: Map<string, string>;
|
|
9
|
+
};
|
|
10
|
+
export type UseWysiwyg = {
|
|
11
|
+
ref: RefObject<HTMLDivElement | null>;
|
|
12
|
+
isWysiwygReady: boolean;
|
|
13
|
+
wysiwyg: FormattingFunctions;
|
|
14
|
+
content: string | null;
|
|
15
|
+
actionStates: AllActionStates;
|
|
16
|
+
debug: {
|
|
17
|
+
modelRef: RefObject<HTMLDivElement | null>;
|
|
18
|
+
testRef: RefObject<HTMLDivElement | null>;
|
|
19
|
+
resetTestCase: () => void | null;
|
|
20
|
+
traceAction: TraceAction;
|
|
21
|
+
};
|
|
22
|
+
suggestion: MappedSuggestion | null;
|
|
23
|
+
messageContent: string | null;
|
|
24
|
+
};
|
|
25
|
+
export declare function useWysiwyg(wysiwygProps?: WysiwygProps): UseWysiwyg;
|
|
26
|
+
export { initOnce } from './useComposerModel.js';
|