@sveltia/ui 0.78.2 → 0.78.4
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/components/text-editor/core.d.ts +2 -0
- package/dist/components/text-editor/core.js +72 -7
- package/dist/components/text-editor/lexical-root.svelte +2 -2
- package/dist/components/text-editor/raw-markdown.d.ts +7 -7
- package/dist/components/text-editor/raw-markdown.js +32 -3
- package/dist/components/text-editor/shiki/version.d.ts +1 -1
- package/dist/components/text-editor/shiki/version.js +1 -1
- package/dist/components/text-editor/toolbar/insert-item-button.svelte +10 -8
- package/dist/components/text-editor/toolbar/insert-menu-button.svelte +10 -14
- package/dist/typedefs.d.ts +7 -0
- package/dist/typedefs.js +4 -0
- package/package.json +17 -17
- package/dist/components/text-editor/toolbar/component-editor.svelte +0 -96
- package/dist/components/text-editor/toolbar/component-editor.svelte.d.ts +0 -35
- package/dist/components/text-editor/toolbar/insert-component-dialog.svelte +0 -92
- package/dist/components/text-editor/toolbar/insert-component-dialog.svelte.d.ts +0 -30
|
@@ -5,6 +5,7 @@ export function isSafeLinkURL(url: string): boolean;
|
|
|
5
5
|
export function getSelectionTypes(): TextEditorSelectionState;
|
|
6
6
|
export function exportMarkdown(enabledTransformers: Transformer[]): string;
|
|
7
7
|
export function onEditorUpdate(editor: LexicalEditor, enabledTransformers: Transformer[], cachedValue?: string): string;
|
|
8
|
+
export function getComponentMarkdown({ node, createNode, transformer, createMarkdown }: TextEditorComponent): string;
|
|
8
9
|
export function initEditor({ enabledButtons, components, useMarkdownShortcuts, isCodeEditor, defaultLanguage, }: TextEditorConfig): InitEditorResult;
|
|
9
10
|
export function loadCodeHighlighter(lang: string): Promise<void>;
|
|
10
11
|
export function convertMarkdownToLexical(editor: LexicalEditor, value: string, enabledTransformers: Transformer[]): Promise<string>;
|
|
@@ -26,4 +27,5 @@ export type InitEditorResult = {
|
|
|
26
27
|
import type { LexicalEditor } from 'lexical';
|
|
27
28
|
import type { TextEditorSelectionState } from '../../typedefs';
|
|
28
29
|
import type { Transformer } from '@lexical/markdown';
|
|
30
|
+
import type { TextEditorComponent } from '../../typedefs';
|
|
29
31
|
import type { TextEditorConfig } from '../../typedefs';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
CodeExtension,
|
|
2
3
|
CodeHighlightNode,
|
|
3
4
|
CodeNode,
|
|
4
5
|
$createCodeNode as createCodeNode,
|
|
@@ -6,7 +7,7 @@ import {
|
|
|
6
7
|
$isCodeNode as isCodeNode,
|
|
7
8
|
} from '@lexical/code-core';
|
|
8
9
|
import { registerDragonSupport } from '@lexical/dragon';
|
|
9
|
-
import { HorizontalRuleNode } from '@lexical/extension';
|
|
10
|
+
import { buildEditorFromExtensions, HorizontalRuleNode } from '@lexical/extension';
|
|
10
11
|
import { createEmptyHistoryState, registerHistory } from '@lexical/history';
|
|
11
12
|
import {
|
|
12
13
|
$isLinkNode as isLinkNode,
|
|
@@ -41,6 +42,7 @@ import {
|
|
|
41
42
|
COMMAND_PRIORITY_LOW,
|
|
42
43
|
COMMAND_PRIORITY_NORMAL,
|
|
43
44
|
createEditor,
|
|
45
|
+
defineExtension,
|
|
44
46
|
DELETE_CHARACTER_COMMAND,
|
|
45
47
|
$createParagraphNode as createParagraphNode,
|
|
46
48
|
$createTextNode as createTextNode,
|
|
@@ -87,10 +89,11 @@ import { HR } from './transformers/hr.js';
|
|
|
87
89
|
import { TABLE } from './transformers/table.js';
|
|
88
90
|
|
|
89
91
|
/**
|
|
90
|
-
* @import {
|
|
92
|
+
* @import { LexicalEditor } from 'lexical';
|
|
91
93
|
* @import { Transformer } from '@lexical/markdown';
|
|
92
94
|
* @import {
|
|
93
95
|
* TextEditorBlockType,
|
|
96
|
+
* TextEditorComponent,
|
|
94
97
|
* TextEditorConfig,
|
|
95
98
|
* TextEditorInlineType,
|
|
96
99
|
* TextEditorNodeType,
|
|
@@ -479,6 +482,54 @@ export const onEditorUpdate = (editor, enabledTransformers, cachedValue) => {
|
|
|
479
482
|
return value;
|
|
480
483
|
};
|
|
481
484
|
|
|
485
|
+
/**
|
|
486
|
+
* Get the Markdown of a new instance of the given editor component, to insert it in the plain text
|
|
487
|
+
* mode. The component’s own `createMarkdown` function is used if any. Otherwise, a new node is
|
|
488
|
+
* created in a temporary editor and exported with the component’s transformer, just like the rich
|
|
489
|
+
* text editor does.
|
|
490
|
+
* @param {TextEditorComponent} component Editor component.
|
|
491
|
+
* @returns {string} Markdown. It can be empty, for example if the component’s output depends on a
|
|
492
|
+
* field value that is not set yet.
|
|
493
|
+
*/
|
|
494
|
+
export const getComponentMarkdown = ({ node, createNode, transformer, createMarkdown }) => {
|
|
495
|
+
if (createMarkdown) {
|
|
496
|
+
return createMarkdown().trim();
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const editor = createEditor({
|
|
500
|
+
namespace: 'component',
|
|
501
|
+
nodes: node ? [/** @type {any} */ (node)] : [],
|
|
502
|
+
/**
|
|
503
|
+
* Throw an error, so the export below fails as a whole.
|
|
504
|
+
* @param {Error} error Error.
|
|
505
|
+
* @throws {Error} Always.
|
|
506
|
+
*/
|
|
507
|
+
onError: (error) => {
|
|
508
|
+
throw error;
|
|
509
|
+
},
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
let markdown = '';
|
|
513
|
+
|
|
514
|
+
try {
|
|
515
|
+
editor.update(
|
|
516
|
+
() => {
|
|
517
|
+
const newNode = createNode();
|
|
518
|
+
|
|
519
|
+
// An inline node needs a paragraph to live in
|
|
520
|
+
getRoot().append(newNode.isInline() ? createParagraphNode().append(newNode) : newNode);
|
|
521
|
+
|
|
522
|
+
markdown = onEditorUpdate(editor, [transformer]);
|
|
523
|
+
},
|
|
524
|
+
{ discrete: true },
|
|
525
|
+
);
|
|
526
|
+
} catch {
|
|
527
|
+
// The component cannot be created or exported outside the rich text editor
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
return markdown.trim();
|
|
531
|
+
};
|
|
532
|
+
|
|
482
533
|
/**
|
|
483
534
|
* Initialize the Lexical editor.
|
|
484
535
|
* @param {TextEditorConfig} config Editor configuration.
|
|
@@ -491,9 +542,14 @@ export const initEditor = ({
|
|
|
491
542
|
isCodeEditor = false,
|
|
492
543
|
defaultLanguage = 'plain',
|
|
493
544
|
}) => {
|
|
494
|
-
|
|
495
|
-
|
|
545
|
+
const hasCodeBlock = enabledButtons.includes('code-block') || isCodeEditor;
|
|
546
|
+
|
|
547
|
+
const editorExtension = defineExtension({
|
|
548
|
+
name: '@sveltia/ui/editor',
|
|
496
549
|
namespace: 'editor',
|
|
550
|
+
// `CodeNode` expects the editor to be built with `CodeExtension`, which also registers the
|
|
551
|
+
// `CodeNode` and `CodeHighlightNode` nodes
|
|
552
|
+
dependencies: hasCodeBlock ? [CodeExtension] : [],
|
|
497
553
|
nodes: [
|
|
498
554
|
...components.map(({ node }) => node),
|
|
499
555
|
...new Set(
|
|
@@ -508,7 +564,15 @@ export const initEditor = ({
|
|
|
508
564
|
[HorizontalRuleNode, TableNode, TableCellNode, TableRowNode]),
|
|
509
565
|
],
|
|
510
566
|
theme: EDITOR_THEME,
|
|
511
|
-
|
|
567
|
+
/**
|
|
568
|
+
* Log an error like `createEditor` does by default, instead of throwing it.
|
|
569
|
+
* @param {Error} error Error.
|
|
570
|
+
*/
|
|
571
|
+
onError: (error) => {
|
|
572
|
+
// eslint-disable-next-line no-console
|
|
573
|
+
console.error(error);
|
|
574
|
+
},
|
|
575
|
+
});
|
|
512
576
|
|
|
513
577
|
/** @type {Transformer[]} */
|
|
514
578
|
const enabledTransformers = [
|
|
@@ -524,7 +588,7 @@ export const initEditor = ({
|
|
|
524
588
|
[HR, TABLE]),
|
|
525
589
|
];
|
|
526
590
|
|
|
527
|
-
const editor =
|
|
591
|
+
const editor = buildEditorFromExtensions(editorExtension);
|
|
528
592
|
/** @type {Array<() => void>} */
|
|
529
593
|
const unregisters = [];
|
|
530
594
|
|
|
@@ -612,7 +676,7 @@ export const initEditor = ({
|
|
|
612
676
|
addUnregister(registerMarkdownShortcuts(editor, enabledTransformers));
|
|
613
677
|
}
|
|
614
678
|
|
|
615
|
-
if (
|
|
679
|
+
if (hasCodeBlock) {
|
|
616
680
|
addUnregister(
|
|
617
681
|
registerCodeHighlighting(editor, {
|
|
618
682
|
...shikiTokenizer,
|
|
@@ -827,6 +891,7 @@ export const initEditor = ({
|
|
|
827
891
|
*/
|
|
828
892
|
dispose: () => {
|
|
829
893
|
unregisters.forEach((unregister) => unregister());
|
|
894
|
+
editor.dispose();
|
|
830
895
|
},
|
|
831
896
|
};
|
|
832
897
|
};
|
|
@@ -224,10 +224,10 @@
|
|
|
224
224
|
.lexical-root[aria-invalid=true] {
|
|
225
225
|
border-color: var(--sui-error-border-color);
|
|
226
226
|
}
|
|
227
|
-
.lexical-root :global(
|
|
227
|
+
.lexical-root :global(:not(.sui):first-child) {
|
|
228
228
|
margin-top: 0;
|
|
229
229
|
}
|
|
230
|
-
.lexical-root :global(
|
|
230
|
+
.lexical-root :global(:not(.sui):last-child) {
|
|
231
231
|
margin-bottom: 0;
|
|
232
232
|
}
|
|
233
233
|
.lexical-root :global(strong.italic) {
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @import { TextEditorBlockType, TextEditorFormatType } from '../../typedefs';
|
|
2
|
+
* @import {
|
|
3
|
+
* TextEditorBlockType,
|
|
4
|
+
* TextEditorComponent,
|
|
5
|
+
* TextEditorFormatType,
|
|
6
|
+
* } from '../../typedefs';
|
|
9
7
|
*/
|
|
10
8
|
/**
|
|
11
9
|
* Current value and selection of the `<textarea>`.
|
|
@@ -43,6 +41,7 @@ export function getRawTextState({ value, selectionStart, selectionEnd }: HTMLTex
|
|
|
43
41
|
export function focusTextArea(textArea: HTMLTextAreaElement): Promise<boolean>;
|
|
44
42
|
export function isRawTextEditable({ readOnly, disabled }: HTMLTextAreaElement): boolean;
|
|
45
43
|
export function applyRawTextEdit(textArea: HTMLTextAreaElement, { start, end, text, selectionStart, selectionEnd }: RawTextEdit): Promise<void>;
|
|
44
|
+
export function insertComponent(textArea: HTMLTextAreaElement, component: TextEditorComponent): Promise<void>;
|
|
46
45
|
/**
|
|
47
46
|
* Current value and selection of the `<textarea>`.
|
|
48
47
|
*/
|
|
@@ -88,3 +87,4 @@ export type RawTextEdit = {
|
|
|
88
87
|
};
|
|
89
88
|
import type { TextEditorFormatType } from '../../typedefs';
|
|
90
89
|
import type { TextEditorBlockType } from '../../typedefs';
|
|
90
|
+
import type { TextEditorComponent } from '../../typedefs';
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Markdown editing helpers for the plain text mode of the text editor, where the toolbar buttons
|
|
3
3
|
* edit the Markdown source in the `<textarea>` instead of Lexical nodes. Apart from
|
|
4
|
-
* {@link getRawTextState} and {@link
|
|
5
|
-
* the current value and selection, and returns the edit to apply.
|
|
4
|
+
* {@link getRawTextState}, {@link applyRawTextEdit} and {@link insertComponent}, everything here is
|
|
5
|
+
* pure: a function takes the current value and selection, and returns the edit to apply.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { getComponentMarkdown } from './core.js';
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
|
-
* @import {
|
|
11
|
+
* @import {
|
|
12
|
+
* TextEditorBlockType,
|
|
13
|
+
* TextEditorComponent,
|
|
14
|
+
* TextEditorFormatType,
|
|
15
|
+
* } from '../../typedefs';
|
|
10
16
|
*/
|
|
11
17
|
|
|
12
18
|
/**
|
|
@@ -469,3 +475,26 @@ export const applyRawTextEdit = async (
|
|
|
469
475
|
|
|
470
476
|
textArea.setSelectionRange(selectionStart, selectionEnd);
|
|
471
477
|
};
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Insert the Markdown of a new instance of the given editor component into the `<textarea>`. A
|
|
481
|
+
* component matched by a single-line pattern is inserted inline at the caret; anything else is
|
|
482
|
+
* inserted as a separate block. If the component has no Markdown to insert, the focus just moves
|
|
483
|
+
* back to the `<textarea>`.
|
|
484
|
+
* @param {HTMLTextAreaElement} textArea `<textarea>` element.
|
|
485
|
+
* @param {TextEditorComponent} component Editor component.
|
|
486
|
+
* @returns {Promise<void>} Nothing.
|
|
487
|
+
*/
|
|
488
|
+
export const insertComponent = async (textArea, component) => {
|
|
489
|
+
const markdown = getComponentMarkdown(component);
|
|
490
|
+
|
|
491
|
+
if (!markdown) {
|
|
492
|
+
textArea.focus();
|
|
493
|
+
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
const block = component.transformer?.type !== 'text-match';
|
|
498
|
+
|
|
499
|
+
await applyRawTextEdit(textArea, insertMarkdown(getRawTextState(textArea), markdown, { block }));
|
|
500
|
+
};
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { getContext } from 'svelte';
|
|
7
7
|
import Button from '../../button/button.svelte';
|
|
8
8
|
import Icon from '../../icon/icon.svelte';
|
|
9
|
-
import
|
|
9
|
+
import { insertComponent } from '../raw-markdown.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @import { TextEditorComponent, TextEditorStore } from '../../../typedefs';
|
|
@@ -28,8 +28,6 @@
|
|
|
28
28
|
const editorStore = getContext('editorStore');
|
|
29
29
|
|
|
30
30
|
const { label, icon, createNode } = $derived(component);
|
|
31
|
-
|
|
32
|
-
let openDialog = $state(false);
|
|
33
31
|
</script>
|
|
34
32
|
|
|
35
33
|
<Button
|
|
@@ -39,9 +37,15 @@
|
|
|
39
37
|
aria-label={label}
|
|
40
38
|
aria-controls={editorStore.controlId}
|
|
41
39
|
onclick={() => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
const { textArea, useRichText } = editorStore;
|
|
41
|
+
|
|
42
|
+
// Insert the component’s Markdown in the plain text mode
|
|
43
|
+
if (!useRichText) {
|
|
44
|
+
// The button is only enabled while the `<textarea>` is there
|
|
45
|
+
/* v8 ignore else */
|
|
46
|
+
if (textArea) {
|
|
47
|
+
insertComponent(textArea, component);
|
|
48
|
+
}
|
|
45
49
|
|
|
46
50
|
return;
|
|
47
51
|
}
|
|
@@ -58,5 +62,3 @@
|
|
|
58
62
|
{/if}
|
|
59
63
|
{/snippet}
|
|
60
64
|
</Button>
|
|
61
|
-
|
|
62
|
-
<InsertComponentDialog {component} bind:open={openDialog} />
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import MenuButton from '../../menu/menu-button.svelte';
|
|
10
10
|
import MenuItem from '../../menu/menu-item.svelte';
|
|
11
11
|
import Menu from '../../menu/menu.svelte';
|
|
12
|
-
import
|
|
12
|
+
import { insertComponent } from '../raw-markdown.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @import { TextEditorComponent, TextEditorStore } from '../../../typedefs';
|
|
@@ -29,13 +29,6 @@
|
|
|
29
29
|
|
|
30
30
|
/** @type {TextEditorStore} */
|
|
31
31
|
const editorStore = getContext('editorStore');
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Component to insert with the dialog in the plain text mode.
|
|
35
|
-
* @type {TextEditorComponent | undefined}
|
|
36
|
-
*/
|
|
37
|
-
let dialogComponent = $state();
|
|
38
|
-
let openDialog = $state(false);
|
|
39
32
|
</script>
|
|
40
33
|
|
|
41
34
|
<MenuButton label={_('_sui.insert')}>
|
|
@@ -49,10 +42,15 @@
|
|
|
49
42
|
<MenuItem
|
|
50
43
|
{label}
|
|
51
44
|
onclick={() => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
45
|
+
const { textArea, useRichText } = editorStore;
|
|
46
|
+
|
|
47
|
+
// Insert the component’s Markdown in the plain text mode
|
|
48
|
+
if (!useRichText) {
|
|
49
|
+
// The item is only clickable while the `<textarea>` is there
|
|
50
|
+
/* v8 ignore else */
|
|
51
|
+
if (textArea) {
|
|
52
|
+
insertComponent(textArea, component);
|
|
53
|
+
}
|
|
56
54
|
|
|
57
55
|
return;
|
|
58
56
|
}
|
|
@@ -73,5 +71,3 @@
|
|
|
73
71
|
</Menu>
|
|
74
72
|
{/snippet}
|
|
75
73
|
</MenuButton>
|
|
76
|
-
|
|
77
|
-
<InsertComponentDialog component={dialogComponent} bind:open={openDialog} />
|
package/dist/typedefs.d.ts
CHANGED
|
@@ -759,6 +759,13 @@ export type TextEditorComponent = {
|
|
|
759
759
|
* Node transformer.
|
|
760
760
|
*/
|
|
761
761
|
transformer: Transformer;
|
|
762
|
+
/**
|
|
763
|
+
* Function to create the Markdown inserted when the
|
|
764
|
+
* component is chosen in the plain text mode. By default, a new node created with `createNode` is
|
|
765
|
+
* exported with `transformer`, which may result in an empty string, for example if the output
|
|
766
|
+
* depends on a field value that is not set yet.
|
|
767
|
+
*/
|
|
768
|
+
createMarkdown?: (() => string) | undefined;
|
|
762
769
|
};
|
|
763
770
|
export type TextEditorConfig = {
|
|
764
771
|
/**
|
package/dist/typedefs.js
CHANGED
|
@@ -318,6 +318,10 @@
|
|
|
318
318
|
* @property {(props?: Record<string, any>) => LexicalNode} createNode Function to create a new node
|
|
319
319
|
* instance.
|
|
320
320
|
* @property {Transformer} transformer Node transformer.
|
|
321
|
+
* @property {() => string} [createMarkdown] Function to create the Markdown inserted when the
|
|
322
|
+
* component is chosen in the plain text mode. By default, a new node created with `createNode` is
|
|
323
|
+
* exported with `transformer`, which may result in an empty string, for example if the output
|
|
324
|
+
* depends on a field value that is not set yet.
|
|
321
325
|
*/
|
|
322
326
|
|
|
323
327
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltia/ui",
|
|
3
|
-
"version": "0.78.
|
|
3
|
+
"version": "0.78.4",
|
|
4
4
|
"description": "A collection of Svelte components and utilities for building user interfaces.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -43,22 +43,22 @@
|
|
|
43
43
|
"!dist/test-utils"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@lexical/code-core": "^0.
|
|
47
|
-
"@lexical/dragon": "^0.
|
|
48
|
-
"@lexical/extension": "^0.
|
|
49
|
-
"@lexical/history": "^0.
|
|
50
|
-
"@lexical/link": "^0.
|
|
51
|
-
"@lexical/list": "^0.
|
|
52
|
-
"@lexical/markdown": "^0.
|
|
53
|
-
"@lexical/rich-text": "^0.
|
|
54
|
-
"@lexical/selection": "^0.
|
|
55
|
-
"@lexical/table": "^0.
|
|
56
|
-
"@lexical/utils": "^0.
|
|
46
|
+
"@lexical/code-core": "^0.52.0",
|
|
47
|
+
"@lexical/dragon": "^0.52.0",
|
|
48
|
+
"@lexical/extension": "^0.52.0",
|
|
49
|
+
"@lexical/history": "^0.52.0",
|
|
50
|
+
"@lexical/link": "^0.52.0",
|
|
51
|
+
"@lexical/list": "^0.52.0",
|
|
52
|
+
"@lexical/markdown": "^0.52.0",
|
|
53
|
+
"@lexical/rich-text": "^0.52.0",
|
|
54
|
+
"@lexical/selection": "^0.52.0",
|
|
55
|
+
"@lexical/table": "^0.52.0",
|
|
56
|
+
"@lexical/utils": "^0.52.0",
|
|
57
57
|
"@shikijs/langs": "4.4.3",
|
|
58
58
|
"@shikijs/themes": "4.4.3",
|
|
59
59
|
"@sveltia/i18n": "^1.4.0",
|
|
60
60
|
"@sveltia/utils": "^0.12.2",
|
|
61
|
-
"lexical": "^0.
|
|
61
|
+
"lexical": "^0.52.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@fontsource-variable/material-symbols-outlined": "5.3.8",
|
|
@@ -71,17 +71,17 @@
|
|
|
71
71
|
"@sveltejs/vite-plugin-svelte": "^7.3.1",
|
|
72
72
|
"@vitest/browser-playwright": "^5.0.2",
|
|
73
73
|
"@vitest/coverage-v8": "^5.0.2",
|
|
74
|
-
"cspell": "^10.3.
|
|
74
|
+
"cspell": "^10.3.5",
|
|
75
75
|
"eslint": "^9.39.5",
|
|
76
76
|
"eslint-config-airbnb-extended": "^3.2.0",
|
|
77
77
|
"eslint-config-prettier": "^10.1.8",
|
|
78
78
|
"eslint-plugin-import": "^2.32.0",
|
|
79
|
-
"eslint-plugin-jsdoc": "^
|
|
80
|
-
"eslint-plugin-package-json": "^1.10.
|
|
79
|
+
"eslint-plugin-jsdoc": "^65.0.0",
|
|
80
|
+
"eslint-plugin-package-json": "^1.10.1",
|
|
81
81
|
"eslint-plugin-svelte": "^3.23.0",
|
|
82
82
|
"globals": "^17.12.0",
|
|
83
83
|
"happy-dom": "^20.14.5",
|
|
84
|
-
"oxlint": "^1.
|
|
84
|
+
"oxlint": "^1.86.0",
|
|
85
85
|
"playwright": "^1.63.0",
|
|
86
86
|
"postcss": "^8.5.28",
|
|
87
87
|
"postcss-html": "^2.0.0",
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
@component
|
|
3
|
-
A minimal rich text editor holding a single editor component, so it can be edited with its own
|
|
4
|
-
field UI outside the main editor, and exported to Markdown. Used to insert a component in the
|
|
5
|
-
plain text mode.
|
|
6
|
-
-->
|
|
7
|
-
<script>
|
|
8
|
-
import {
|
|
9
|
-
$createParagraphNode as createParagraphNode,
|
|
10
|
-
$getRoot as getRoot,
|
|
11
|
-
$insertNodes as insertNodes,
|
|
12
|
-
} from 'lexical';
|
|
13
|
-
import { getContext, setContext } from 'svelte';
|
|
14
|
-
import { onEditorUpdate } from '../core.js';
|
|
15
|
-
import LexicalRoot from '../lexical-root.svelte';
|
|
16
|
-
import { createEditorStore } from '../store.svelte.js';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @import { TextEditorComponent, TextEditorStore } from '../../../typedefs';
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @typedef {object} Props
|
|
24
|
-
* @property {TextEditorComponent} component Editor component to edit.
|
|
25
|
-
* @property {string} [markdown] Markdown output of the component.
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
/** @type {Props} */
|
|
29
|
-
let {
|
|
30
|
-
/* eslint-disable prefer-const */
|
|
31
|
-
component,
|
|
32
|
-
markdown = $bindable(''),
|
|
33
|
-
/* eslint-enable prefer-const */
|
|
34
|
-
} = $props();
|
|
35
|
-
|
|
36
|
-
/** @type {TextEditorStore} */
|
|
37
|
-
const parentStore = getContext('editorStore');
|
|
38
|
-
const editorStore = createEditorStore();
|
|
39
|
-
|
|
40
|
-
// svelte-ignore state_referenced_locally
|
|
41
|
-
editorStore.config = {
|
|
42
|
-
...parentStore.config,
|
|
43
|
-
modes: ['rich-text'],
|
|
44
|
-
components: [component],
|
|
45
|
-
useMarkdownShortcuts: false,
|
|
46
|
-
useEmojiAutocomplete: false,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
setContext('editorStore', editorStore);
|
|
50
|
-
|
|
51
|
-
let inserted = false;
|
|
52
|
-
|
|
53
|
-
$effect(() => {
|
|
54
|
-
const { editor, initialized } = editorStore;
|
|
55
|
-
|
|
56
|
-
if (!editor || !initialized || inserted) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
inserted = true;
|
|
61
|
-
|
|
62
|
-
editor.update(() => {
|
|
63
|
-
const paragraph = createParagraphNode();
|
|
64
|
-
|
|
65
|
-
getRoot().clear().append(paragraph);
|
|
66
|
-
paragraph.select();
|
|
67
|
-
insertNodes([component.createNode()]);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
$effect(() => {
|
|
72
|
-
markdown = editorStore.inputValue.trim();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Get the component’s Markdown right now. The bound `markdown` is only updated after a short
|
|
77
|
-
* delay, so it may not reflect a field that has just been changed.
|
|
78
|
-
* @returns {string} Markdown.
|
|
79
|
-
*/
|
|
80
|
-
export const getMarkdown = () => {
|
|
81
|
-
const { editor, enabledTransformers } = editorStore;
|
|
82
|
-
|
|
83
|
-
// The dialog can only be submitted once the editor is there
|
|
84
|
-
/* v8 ignore next 3 */
|
|
85
|
-
if (!editor) {
|
|
86
|
-
return markdown;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return editor
|
|
90
|
-
.getEditorState()
|
|
91
|
-
.read(() => onEditorUpdate(editor, enabledTransformers))
|
|
92
|
-
.trim();
|
|
93
|
-
};
|
|
94
|
-
</script>
|
|
95
|
-
|
|
96
|
-
<LexicalRoot aria-label={component.label} />
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export default ComponentEditor;
|
|
2
|
-
type ComponentEditor = {
|
|
3
|
-
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
-
$set?(props: Partial<Props>): void;
|
|
5
|
-
} & {
|
|
6
|
-
getMarkdown: () => string;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* A minimal rich text editor holding a single editor component, so it can be edited with its own
|
|
10
|
-
* field UI outside the main editor, and exported to Markdown. Used to insert a component in the
|
|
11
|
-
* plain text mode.
|
|
12
|
-
*/
|
|
13
|
-
declare const ComponentEditor: import("svelte").Component<{
|
|
14
|
-
/**
|
|
15
|
-
* Editor component to edit.
|
|
16
|
-
*/
|
|
17
|
-
component: TextEditorComponent;
|
|
18
|
-
/**
|
|
19
|
-
* Markdown output of the component.
|
|
20
|
-
*/
|
|
21
|
-
markdown?: string | undefined;
|
|
22
|
-
}, {
|
|
23
|
-
getMarkdown: () => string;
|
|
24
|
-
}, "markdown">;
|
|
25
|
-
type Props = {
|
|
26
|
-
/**
|
|
27
|
-
* Editor component to edit.
|
|
28
|
-
*/
|
|
29
|
-
component: TextEditorComponent;
|
|
30
|
-
/**
|
|
31
|
-
* Markdown output of the component.
|
|
32
|
-
*/
|
|
33
|
-
markdown?: string | undefined;
|
|
34
|
-
};
|
|
35
|
-
import type { TextEditorComponent } from '../../../typedefs';
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
@component
|
|
3
|
-
A dialog to insert an editor component in the plain text mode. The component is edited with its
|
|
4
|
-
own field UI in a minimal rich text editor, then inserted into the `<textarea>` as Markdown.
|
|
5
|
-
-->
|
|
6
|
-
<script>
|
|
7
|
-
import { _ } from '@sveltia/i18n';
|
|
8
|
-
import { getContext } from 'svelte';
|
|
9
|
-
import Dialog from '../../dialog/dialog.svelte';
|
|
10
|
-
import { applyRawTextEdit, getRawTextState, insertMarkdown } from '../raw-markdown.js';
|
|
11
|
-
import ComponentEditor from './component-editor.svelte';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @import { TextEditorComponent, TextEditorStore } from '../../../typedefs';
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @typedef {object} Props
|
|
19
|
-
* @property {TextEditorComponent | undefined} component Editor component to insert.
|
|
20
|
-
* @property {boolean} [open] Whether to open the dialog.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/** @type {Props} */
|
|
24
|
-
let {
|
|
25
|
-
/* eslint-disable prefer-const */
|
|
26
|
-
component,
|
|
27
|
-
open = $bindable(false),
|
|
28
|
-
/* eslint-enable prefer-const */
|
|
29
|
-
} = $props();
|
|
30
|
-
|
|
31
|
-
/** @type {TextEditorStore} */
|
|
32
|
-
const editorStore = getContext('editorStore');
|
|
33
|
-
|
|
34
|
-
let markdown = $state('');
|
|
35
|
-
/** @type {ComponentEditor | undefined} */
|
|
36
|
-
let componentEditor = $state();
|
|
37
|
-
/**
|
|
38
|
-
* Markdown taken from the editor as the dialog starts closing, while it’s still there.
|
|
39
|
-
* @type {string}
|
|
40
|
-
*/
|
|
41
|
-
let latestMarkdown = '';
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Insert the component’s Markdown into the `<textarea>`, or just bring the focus back there.
|
|
45
|
-
* @param {CustomEvent} event `close` event.
|
|
46
|
-
*/
|
|
47
|
-
const onClose = (event) => {
|
|
48
|
-
const { textArea } = editorStore;
|
|
49
|
-
|
|
50
|
-
// The dialog can only be opened from a button, which needs the `<textarea>`
|
|
51
|
-
/* v8 ignore next 3 */
|
|
52
|
-
if (!textArea) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (event.detail.returnValue !== 'cancel' && latestMarkdown) {
|
|
57
|
-
// A component matched by a single-line pattern is inline; anything else is a block
|
|
58
|
-
const block = component?.transformer?.type !== 'text-match';
|
|
59
|
-
|
|
60
|
-
applyRawTextEdit(
|
|
61
|
-
textArea,
|
|
62
|
-
insertMarkdown(getRawTextState(textArea), latestMarkdown, { block }),
|
|
63
|
-
);
|
|
64
|
-
} else {
|
|
65
|
-
textArea.focus();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
markdown = '';
|
|
69
|
-
latestMarkdown = '';
|
|
70
|
-
};
|
|
71
|
-
</script>
|
|
72
|
-
|
|
73
|
-
<Dialog
|
|
74
|
-
title={component?.label ?? ''}
|
|
75
|
-
size="large"
|
|
76
|
-
bind:open
|
|
77
|
-
okLabel={_('_sui.insert')}
|
|
78
|
-
okDisabled={!markdown}
|
|
79
|
-
restoreFocus={false}
|
|
80
|
-
onClosing={() => {
|
|
81
|
-
// Get the latest Markdown, as the bound value is updated with a delay
|
|
82
|
-
latestMarkdown = componentEditor?.getMarkdown() ?? markdown;
|
|
83
|
-
}}
|
|
84
|
-
onClose={(event) => {
|
|
85
|
-
onClose(event);
|
|
86
|
-
}}
|
|
87
|
-
>
|
|
88
|
-
<!-- The dialog unmounts its content once closed, so each opening gets a fresh editor -->
|
|
89
|
-
{#if component}
|
|
90
|
-
<ComponentEditor bind:this={componentEditor} {component} bind:markdown />
|
|
91
|
-
{/if}
|
|
92
|
-
</Dialog>
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export default InsertComponentDialog;
|
|
2
|
-
type InsertComponentDialog = {
|
|
3
|
-
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
-
$set?(props: Partial<Props>): void;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* A dialog to insert an editor component in the plain text mode. The component is edited with its
|
|
8
|
-
* own field UI in a minimal rich text editor, then inserted into the `<textarea>` as Markdown.
|
|
9
|
-
*/
|
|
10
|
-
declare const InsertComponentDialog: import("svelte").Component<{
|
|
11
|
-
/**
|
|
12
|
-
* Editor component to insert.
|
|
13
|
-
*/
|
|
14
|
-
component: TextEditorComponent | undefined;
|
|
15
|
-
/**
|
|
16
|
-
* Whether to open the dialog.
|
|
17
|
-
*/
|
|
18
|
-
open?: boolean | undefined;
|
|
19
|
-
}, {}, "open">;
|
|
20
|
-
type Props = {
|
|
21
|
-
/**
|
|
22
|
-
* Editor component to insert.
|
|
23
|
-
*/
|
|
24
|
-
component: TextEditorComponent | undefined;
|
|
25
|
-
/**
|
|
26
|
-
* Whether to open the dialog.
|
|
27
|
-
*/
|
|
28
|
-
open?: boolean | undefined;
|
|
29
|
-
};
|
|
30
|
-
import type { TextEditorComponent } from '../../../typedefs';
|