]> BookStack Code Mirror - bookstack/blob - resources/js/wysiwyg/ui/defaults/form-definitions.ts
Lexical: Created core modal functionality
[bookstack] / resources / js / wysiwyg / ui / defaults / form-definitions.ts
1 import {EditorFormDefinition, EditorSelectFormFieldDefinition} from "../framework/forms";
2 import {EditorUiContext} from "../framework/core";
3 import {$createLinkNode} from "@lexical/link";
4 import {$createTextNode, $getSelection} from "lexical";
5
6
7 export const link: EditorFormDefinition = {
8     submitText: 'Apply',
9     action(formData, context: EditorUiContext) {
10         context.editor.update(() => {
11
12             const selection = $getSelection();
13
14             const linkNode = $createLinkNode(formData.get('url')?.toString() || '', {
15                 title: formData.get('title')?.toString() || '',
16                 target: formData.get('target')?.toString() || '',
17             });
18             linkNode.append($createTextNode(formData.get('text')?.toString() || ''));
19
20             selection?.insertNodes([linkNode]);
21         });
22         return true;
23     },
24     fields: [
25         {
26             label: 'URL',
27             name: 'url',
28             type: 'text',
29         },
30         {
31             label: 'Text to display',
32             name: 'text',
33             type: 'text',
34         },
35         {
36             label: 'Title',
37             name: 'title',
38             type: 'text',
39         },
40         {
41             label: 'Open link in...',
42             name: 'target',
43             type: 'select',
44             valuesByLabel: {
45                 'Current window': '',
46                 'New window': '_blank',
47             }
48         } as EditorSelectFormFieldDefinition,
49     ],
50 };