Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rich Text Editor | Add setMarkdown() and getMarkdown() methods to set and get content from Tip Tap editor #1424

Merged
merged 112 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
ca4ccec
Initial pass for editor component. This is a intermediate commit and …
vivinkrishna-ni Jul 6, 2023
6e15794
Overrides semver version to be >=7.5.2
AagashRaaj Jul 7, 2023
a163b55
Removed the tiptap packages
vivinkrishna-ni Jul 11, 2023
6df5ef1
Reverted the package-lock.json to main branch changes
vivinkrishna-ni Jul 11, 2023
38be4dd
Added tiptap packages and necessary packages for tiptap
vivinkrishna-ni Jul 11, 2023
b159f86
Component and angular skeleton code bring up for rich-text-editor
vivinkrishna-ni Jul 11, 2023
37e1062
Merge branch 'users/vivin/initial-code-for-rich-text-editor' into use…
vivinkrishna-ni Jul 11, 2023
0d1de1a
Resolved linting errors
vivinkrishna-ni Jul 11, 2023
91362df
Merge branch 'users/vivin/initial-code-for-rich-text-editor' into use…
vivinkrishna-ni Jul 11, 2023
70a5c2d
Removed angular code from this branch and will be added as separate PR
vivinkrishna-ni Jul 11, 2023
0a68e83
Removed constant file file for rich-text-content
vivinkrishna-ni Jul 11, 2023
6bdd0d7
Change files
vivinkrishna-ni Jul 11, 2023
5851a8b
Merge branch 'users/vivin/initial-code-for-rich-text-editor' into use…
vivinkrishna-ni Jul 11, 2023
391ecbc
Updated the description for editor storybook
vivinkrishna-ni Jul 11, 2023
288aa3e
Merge branch 'users/vivin/initial-code-for-rich-text-editor' into use…
vivinkrishna-ni Jul 11, 2023
43330c2
Merge branch 'main' into users/vivin/initial-code-for-rich-text-editor
vivinkrishna-ni Jul 13, 2023
f21a11e
Merge branch 'users/vivin/initial-code-for-rich-text-editor' into use…
vivinkrishna-ni Jul 13, 2023
4c94bd4
Initial bring up of titptap editor with basic template enabled
vivinkrishna-ni Jul 14, 2023
6cc6209
Merge branch 'main' into users/vivin/integrate-tiptap-editor
vivinkrishna-ni Jul 18, 2023
560ecd5
Intermediate commit to add functionalities to the buttons and modifie…
vivinkrishna-ni Jul 19, 2023
a32ade0
Added placeholder and link extensions
vivinkrishna-ni Jul 20, 2023
dc8152d
Added placeholder support rich-text-editor
vivinkrishna-ni Jul 20, 2023
00571c1
Updates on the link configurations
vivinkrishna-ni Jul 21, 2023
0468ba5
Intermediate changes for maxlength and disabled state
vivinkrishna-ni Jul 25, 2023
9ec89cf
Updated for footer hidden attribute
vivinkrishna-ni Jul 26, 2023
d56355b
Added some additional APIs to this branch, might be removed and split…
vivinkrishna-ni Jul 31, 2023
33cb3c7
Merge branch 'main' into users/vivin/integrate-tiptap-editor
vivinkrishna-ni Jul 31, 2023
efe79e0
Update package lock json
vivinkrishna-ni Jul 31, 2023
ca2bf70
Changes with only basic editor and footer actions
vivinkrishna-ni Jul 31, 2023
1c39203
Updated few code changes to re-confirm pipeline passes
vivinkrishna-ni Aug 1, 2023
390df6a
Removed markdown-it from dev dependency
vivinkrishna-ni Aug 1, 2023
92ddd09
Updated test case, style and implementation to integrate tiptap edito…
vivinkrishna-ni Aug 2, 2023
e0e20eb
Update desc in change file and formatting in template
vivinkrishna-ni Aug 3, 2023
3df5015
Merge branch 'main' into users/vivin/integrate-tiptap-editor
vivinkrishna-ni Aug 3, 2023
fe4b926
resolve linting errors
vivinkrishna-ni Aug 3, 2023
bd29abb
Changed the name of the private function and minor style change
vivinkrishna-ni Aug 3, 2023
15b3fa4
Added model class for editor button events
vivinkrishna-ni Aug 3, 2023
9dc2e1a
returning void for base class methods
vivinkrishna-ni Aug 3, 2023
e67d478
resolve linting errors
vivinkrishna-ni Aug 3, 2023
40633b8
Merge branch 'main' into users/vivin/integrate-tiptap-editor
vivinkrishna-ni Aug 4, 2023
4d3e099
Resolved PR comments
vivinkrishna-ni Aug 7, 2023
ad024ef
Added internal comment for public variables
vivinkrishna-ni Aug 7, 2023
bbe0c26
Resolve PR comments
vivinkrishna-ni Aug 7, 2023
6dddc0a
Update minor function name change
vivinkrishna-ni Aug 7, 2023
94cafd0
resolve linting errors
vivinkrishna-ni Aug 7, 2023
c1a0ca8
Merge branch 'main' into users/vivin/integrate-tiptap-editor
vivinkrishna-ni Aug 8, 2023
0b16f24
Updated package-lock.json
vivinkrishna-ni Aug 9, 2023
9eb96e3
Merge branch 'main' into users/vivin/integrate-tiptap-editor
vivinkrishna-ni Aug 9, 2023
21abec6
Resolving PR comments
vivinkrishna-ni Aug 9, 2023
efa3f1e
Updated the name for button properties and resolve linting errors
vivinkrishna-ni Aug 9, 2023
101ebb5
Added test cases for aria attributes
vivinkrishna-ni Aug 9, 2023
2602635
Removed fdescribe
vivinkrishna-ni Aug 9, 2023
393f42b
Added comments to specify the return value for key handler
vivinkrishna-ni Aug 9, 2023
462d929
added readonly for base class properties
vivinkrishna-ni Aug 9, 2023
8e33326
Removed model classes and moved it to a template file
vivinkrishna-ni Aug 10, 2023
eeaec8e
Add setMarkdown and getmarkdown method in rich-text-editor
AagashRaaj Aug 10, 2023
2755e60
Added labels for each buttons
vivinkrishna-ni Aug 10, 2023
0a8955d
Update story book
AagashRaaj Aug 10, 2023
c4db560
Fix lint
AagashRaaj Aug 10, 2023
924fd8b
Minor fix
AagashRaaj Aug 10, 2023
bfb5c23
safari workaround
AagashRaaj Aug 10, 2023
d0bfce2
Merge branch 'main' into users/vivin/integrate-tiptap-editor
vivinkrishna-ni Aug 11, 2023
367491e
Resolving PR comments
vivinkrishna-ni Aug 11, 2023
2b01fff
Minor code changes
vivinkrishna-ni Aug 11, 2023
1ece855
Updated comment in the code
vivinkrishna-ni Aug 11, 2023
54cfba0
updated the comment in the styles
vivinkrishna-ni Aug 11, 2023
65bd029
resolve linting errors
vivinkrishna-ni Aug 11, 2023
ba0f36b
Address PR Comments
AagashRaaj Aug 11, 2023
04db1a8
Added test cases for the change event propagation and part for footer…
vivinkrishna-ni Aug 11, 2023
d8c239e
Minor correction in the comment added
vivinkrishna-ni Aug 11, 2023
2497365
Remove focus on setMarkdown()
AagashRaaj Aug 11, 2023
5dc0216
Merge branch 'users/vivin/integrate-tiptap-editor' of https://github.…
AagashRaaj Aug 11, 2023
9d21139
Added test cases for nested lists in editor and viewer
vivinkrishna-ni Aug 14, 2023
fc592a3
Removed skipping escape func while serializing
AagashRaaj Aug 14, 2023
7c5c95e
Merge branch 'main' into users/vivin/integrate-tiptap-editor
vivinkrishna-ni Aug 14, 2023
47e92d7
Merge branch 'main' into users/vivin/integrate-tiptap-editor
vivinkrishna-ni Aug 14, 2023
9f27b34
Merge branch 'main' into users/vivin/integrate-tiptap-editor
vivinkrishna-ni Aug 14, 2023
cd43757
Minor test case name update
vivinkrishna-ni Aug 15, 2023
1daf767
Merge branch 'main' into users/vivin/integrate-tiptap-editor
vivinkrishna-ni Aug 15, 2023
84e56dc
Address PR comments
AagashRaaj Aug 16, 2023
748c780
Remove types.ts file
AagashRaaj Aug 16, 2023
b845367
Fix linting
AagashRaaj Aug 16, 2023
aa4045c
Refactored page object and updated the test cases accordingly
vivinkrishna-ni Aug 16, 2023
567fd0c
Updated the nested list test cases in viewer component
vivinkrishna-ni Aug 16, 2023
ef70cda
Resolving PR comments
vivinkrishna-ni Aug 17, 2023
dfb9cd8
Merge branch 'main' into users/vivin/integrate-tiptap-editor
vivinkrishna-ni Aug 17, 2023
f211efc
Updated the default height of the container for sizing tests
vivinkrishna-ni Aug 17, 2023
afe3cdf
Merge branch 'users/vivin/integrate-tiptap-editor' of https://github.…
vivinkrishna-ni Aug 17, 2023
c49bcba
Address PR comments
AagashRaaj Aug 17, 2023
c3e7f8f
Minor fix
AagashRaaj Aug 17, 2023
f6188f2
Fix lint
AagashRaaj Aug 17, 2023
12dd3f0
Merge branch 'users/vivin/integrate-tiptap-editor' of https://github.…
AagashRaaj Aug 17, 2023
9f5b675
Updated the aria-multiline value by using setAttribute
vivinkrishna-ni Aug 18, 2023
43f52ac
Typo correction for aria-multiline attribute
vivinkrishna-ni Aug 18, 2023
31cac04
Added titles for buttons and moved enum to a type file
vivinkrishna-ni Aug 18, 2023
8db2b7f
Added spec file for types
vivinkrishna-ni Aug 18, 2023
0b58903
Merge branch 'main' into users/vivin/integrate-tiptap-editor
vivinkrishna-ni Aug 18, 2023
afe4eca
Merge branch 'users/vivin/integrate-tiptap-editor' into users/aagash/…
vivinkrishna-ni Aug 18, 2023
fe8de41
Merge branch 'users/aagash/markdown-parser-serializer-editor' of http…
vivinkrishna-ni Aug 18, 2023
da25204
Merge branch 'main' into users/aagash/markdown-parser-serializer-editor
vivinkrishna-ni Aug 18, 2023
9d32990
Removed change file
vivinkrishna-ni Aug 18, 2023
60ee9c7
Merge branch 'users/aagash/markdown-parser-serializer-editor' of http…
vivinkrishna-ni Aug 18, 2023
0823fe3
Fix linting
vivinkrishna-ni Aug 18, 2023
14bb516
Passed enum types to the methods in page objects instead of number type
vivinkrishna-ni Aug 18, 2023
d1b0955
Change files
jattasNI Aug 18, 2023
bfa0f2e
typo
jattasNI Aug 18, 2023
7252c97
Update Comments
AagashRaaj Aug 21, 2023
33611bd
Merge branch 'main' into users/aagash/markdown-parser-serializer-editor
vivinkrishna-ni Aug 21, 2023
8460c85
Add testcase for editor Before DOM Connection
AagashRaaj Aug 21, 2023
e9a4548
Minor renaming
AagashRaaj Aug 21, 2023
65a4b96
Check getMarkdown() before dom initialization
AagashRaaj Aug 21, 2023
fb9595c
Merge branch 'main' into users/aagash/markdown-parser-serializer-editor
aagash-ni Aug 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Add setMarkdown and getMarkdown methods in rich-text-editor",
"packageName": "@ni/nimble-components",
"email": "[email protected]",
"dependentChangeType": "patch"
}
135 changes: 133 additions & 2 deletions packages/nimble-components/src/rich-text-editor/index.ts
aagash-ni marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import { observable } from '@microsoft/fast-element';
import { DesignSystem, FoundationElement } from '@microsoft/fast-foundation';
import { keyEnter, keySpace } from '@microsoft/fast-web-utilities';
jattasNI marked this conversation as resolved.
Show resolved Hide resolved
import { Editor } from '@tiptap/core';
import {
schema,
defaultMarkdownParser,
MarkdownParser,
MarkdownSerializer,
defaultMarkdownSerializer,
MarkdownSerializerState
} from 'prosemirror-markdown';
import { DOMSerializer, Node } from 'prosemirror-model';
import Bold from '@tiptap/extension-bold';
import BulletList from '@tiptap/extension-bullet-list';
import Document from '@tiptap/extension-document';
Expand Down Expand Up @@ -52,16 +61,29 @@ export class RichTextEditor extends FoundationElement {
/**
* @internal
*/
public editor!: HTMLDivElement;
public editorContainer!: HTMLDivElement;

private tiptapEditor!: Editor;
private editor!: HTMLDivElement;

private readonly markdownParser = this.initializeMarkdownParser();
private readonly markdownSerializer = this.initializeMarkdownSerializer();
private readonly domSerializer = DOMSerializer.fromSchema(schema);
private readonly xmlSerializer = new XMLSerializer();

public constructor() {
super();
this.initializeEditor();
}

/**
* @internal
*/
public override connectedCallback(): void {
super.connectedCallback();
this.initializeEditor();
if (!this.editor.isConnected) {
this.editorContainer.append(this.editor);
}
this.bindEditorTransactionEvent();
}

Expand Down Expand Up @@ -153,6 +175,26 @@ export class RichTextEditor extends FoundationElement {
return true;
}

/**
* This function load tip tap editor with provided markdown content by parsing into html
* @public
*/
public setMarkdown(markdown: string): void {
const html = this.getHtmlContent(markdown);
this.tiptapEditor.commands.setContent(html);
}

/**
* This function returns markdown string by serializing tiptap editor document using prosemirror MarkdownSerializer
* @public
*/
public getMarkdown(): string {
const markdownContent = this.markdownSerializer.serialize(
this.tiptapEditor.state.doc
);
return markdownContent;
}

/**
* @internal
*/
Expand All @@ -163,7 +205,96 @@ export class RichTextEditor extends FoundationElement {
return false;
}

/**
* This function takes the Fragment from parseMarkdownToDOM function and return the serialized string using XMLSerializer
*/
private getHtmlContent(markdown: string): string {
const documentFragment = this.parseMarkdownToDOM(markdown);
return this.xmlSerializer.serializeToString(documentFragment);
}

private initializeMarkdownParser(): MarkdownParser {
aagash-ni marked this conversation as resolved.
Show resolved Hide resolved
/**
* It configures the tokenizer of the default Markdown parser with the 'zero' preset.
* The 'zero' preset is a configuration with no rules enabled by default to selectively enable specific rules.
* https://github.com/markdown-it/markdown-it/blob/2b6cac25823af011ff3bc7628bc9b06e483c5a08/lib/presets/zero.js#L1
*
*/
const zeroTokenizerConfiguration = defaultMarkdownParser.tokenizer.configure('zero');

// The detailed information of the supported rules were provided in the below CommonMark spec document.
// https://spec.commonmark.org/0.30/
const supportedTokenizerRules = zeroTokenizerConfiguration.enable([
'emphasis',
'list'
]);

return new MarkdownParser(
schema,
supportedTokenizerRules,
defaultMarkdownParser.tokens
);
}

private initializeMarkdownSerializer(): MarkdownSerializer {
/**
* orderedList Node is getting 'order' attribute which it is not present in the
* tip-tap orderedList Node and having start instead of order, Changed it to start (nodes.attrs.start)
* Assigned updated node in place of orderedList node from defaultMarkdownSerializer
* https://github.com/ProseMirror/prosemirror-markdown/blob/b7c1fd2fb74c7564bfe5428c7c8141ded7ebdd9f/src/to_markdown.ts#L94C2-L101C7
*/
const orderedListNode = function orderedList(
state: MarkdownSerializerState,
node: Node
): void {
const start = (node.attrs.start as number) || 1;
const maxW = String(start + node.childCount - 1).length;
const space = state.repeat(' ', maxW + 2);
state.renderList(node, space, i => {
const nStr = String(start + i);
return `${state.repeat(' ', maxW - nStr.length) + nStr}. `;
});
};
aagash-ni marked this conversation as resolved.
Show resolved Hide resolved

/**
* Internally Tiptap editor creates it own schema ( Nodes AND Marks ) based on the extensions ( Here Starter Kit is used for Bold, italic, orderedList and
* bulletList extensions) and defaultMarkdownSerializer uses schema from prosemirror-markdown to serialize the markdown.
* So, there is variations in the nodes and marks name (Eg. 'ordered_list' in prosemirror-markdown schema whereas 'orderedList' in tip tap editor schema),
* To fix up this reassigned the respective nodes and marks with tip-tap editor schema.
*/
const nodes = {
bulletList: defaultMarkdownSerializer.nodes.bullet_list!,
listItem: defaultMarkdownSerializer.nodes.list_item!,
orderedList: orderedListNode,
doc: defaultMarkdownSerializer.nodes.doc!,
paragraph: defaultMarkdownSerializer.nodes.paragraph!,
text: defaultMarkdownSerializer.nodes.text!
};
const marks = {
italic: defaultMarkdownSerializer.marks.em!,
bold: defaultMarkdownSerializer.marks.strong!
};
return new MarkdownSerializer(nodes, marks);
}

private parseMarkdownToDOM(value: string): HTMLElement | DocumentFragment {
const parsedMarkdownContent = this.markdownParser.parse(value);
if (parsedMarkdownContent === null) {
return document.createDocumentFragment();
}

return this.domSerializer.serializeFragment(
parsedMarkdownContent.content
);
}

private initializeEditor(): void {
// Create div from the constructor because the TipTap editor requires its host element before the template is instantiated.
this.editor = document.createElement('div');
aagash-ni marked this conversation as resolved.
Show resolved Hide resolved
this.editor.className = 'editor';
this.editor.setAttribute('aria-multiline', 'true');
this.editor.setAttribute('role', 'textbox');

/**
* For more information on the extensions for the supported formatting options, refer to the links below.
* Tiptap marks: https://tiptap.dev/api/marks
Expand Down
4 changes: 4 additions & 0 deletions packages/nimble-components/src/rich-text-editor/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export const styles = css`
overflow: auto;
}

.editor-container {
display: contents;
}

.ProseMirror {
${
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import { iconNumberListTag } from '../icons/number-list';
export const template = html<RichTextEditor>`
<template>
<div class="container">
<section
${ref('editor')}
class="editor"
role="textbox"
aria-multiline="true">
<section ${ref('editorContainer')} class="editor-container">
</section>
<section class="footer-section" part="footer-section">
<${toolbarTag}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { keySpace, keyEnter, keyTab } from '@microsoft/fast-web-utilities';
import type { RichTextEditor } from '..';
import { waitForUpdatesAsync } from '../../testing/async-helpers';
import type { ToggleButton } from '../../toggle-button';
import type { ToolbarButton } from './types';

/**
* Page object for the `nimble-rich-text-editor` component.
Expand Down Expand Up @@ -73,54 +74,54 @@ export class RichTextEditorPageObject {

/**
* To click a formatting button in the footer section, pass its position value as an index (starting from '0')
* @param buttonIndex can be imported from an enum for each button using the `ButtonIndex`.
* @param button can be imported from an enum for each button using the `ButtonIndex`.
*/
public async clickFooterButton(buttonIndex: number): Promise<void> {
const button = this.getFormattingButton(buttonIndex);
button!.click();
public async clickFooterButton(button: ToolbarButton): Promise<void> {
const toggleButton = this.getFormattingButton(button);
toggleButton!.click();
await waitForUpdatesAsync();
}

/**
* To retrieve the checked state of the button, provide its position value as an index (starting from '0')
* @param buttonIndex can be imported from an enum for each button using the `ButtonIndex`.
* @param button can be imported from an enum for each button using the `ButtonIndex`.
*/
public getButtonCheckedState(buttonIndex: number): boolean {
const button = this.getFormattingButton(buttonIndex);
return button!.checked;
public getButtonCheckedState(button: ToolbarButton): boolean {
const toggleButton = this.getFormattingButton(button);
return toggleButton!.checked;
}

/**
* To retrieve the tab index of the button, provide its position value as an index (starting from '0')
* @param buttonIndex can be imported from an enum for each button using the `ButtonIndex`.
* @param button can be imported from an enum for each button using the `ButtonIndex`.
*/
public getButtonTabIndex(buttonIndex: number): number {
const button = this.getFormattingButton(buttonIndex);
return button!.tabIndex;
public getButtonTabIndex(button: ToolbarButton): number {
const toggleButton = this.getFormattingButton(button);
return toggleButton!.tabIndex;
}

/**
* To trigger a space key press for the button, provide its position value as an index (starting from '0')
* @param buttonIndex can be imported from an enum for each button using the `ButtonIndex`.
* @param button can be imported from an enum for each button using the `ButtonIndex`.
*/
public spaceKeyActivatesButton(buttonIndex: number): void {
const button = this.getFormattingButton(buttonIndex)!;
public spaceKeyActivatesButton(button: ToolbarButton): void {
const toggleButton = this.getFormattingButton(button)!;
const event = new KeyboardEvent('keypress', {
key: keySpace
} as KeyboardEventInit);
button.control.dispatchEvent(event);
toggleButton.control.dispatchEvent(event);
}

/**
* To trigger a enter key press for the button, provide its position value as an index (starting from '0')
* @param buttonIndex can be imported from an enum for each button using the `ButtonIndex`.
* @param button can be imported from an enum for each button using the `ButtonIndex`.
*/
public enterKeyActivatesButton(buttonIndex: number): void {
const button = this.getFormattingButton(buttonIndex)!;
public enterKeyActivatesButton(button: ToolbarButton): void {
const toggleButton = this.getFormattingButton(button)!;
const event = new KeyboardEvent('keypress', {
key: keyEnter
} as KeyboardEventInit);
button.control.dispatchEvent(event);
toggleButton.control.dispatchEvent(event);
}

public async setEditorTextContent(value: string): Promise<void> {
Expand Down Expand Up @@ -166,7 +167,7 @@ export class RichTextEditorPageObject {
}

private getFormattingButton(
index: number
index: ToolbarButton
): ToggleButton | null | undefined {
const buttons: NodeListOf<ToggleButton> = this.richTextEditorElement.shadowRoot!.querySelectorAll(
'nimble-toggle-button'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
tokenNames
} from '../../theme-provider/design-token-names';
import { buttonTag } from '../../button';
import { loremIpsum } from '../../utilities/tests/lorem-ipsum';

const metadata: Meta = {
title: 'Tests/Rich Text Editor',
Expand All @@ -23,13 +24,20 @@ const metadata: Meta = {
}
};

const richTextMarkdownString = '1. **Bold*Italics***';

export default metadata;

// prettier-ignore
const component = (): ViewTemplate => html`
<${richTextEditorTag}></${richTextEditorTag}>
`;

const playFunction = (): void => {
const editorNodeList = document.querySelectorAll('nimble-rich-text-editor');
editorNodeList.forEach(element => element.setMarkdown(richTextMarkdownString));
};

const editorSizingTestCase = (
[widthLabel, widthStyle]: [string, string],
[heightLabel, heightStyle]: [string, string]
Expand All @@ -49,6 +57,8 @@ export const richTextEditorThemeMatrix: StoryFn = createMatrixThemeStory(
createMatrix(component)
);

richTextEditorThemeMatrix.play = playFunction;

export const richTextEditorSizing: StoryFn = createStory(html`
${createMatrix(editorSizingTestCase, [
[
Expand All @@ -64,6 +74,47 @@ export const richTextEditorSizing: StoryFn = createStory(html`
])}
`);

const mobileWidthComponent = html`
<${richTextEditorTag} style="padding: 20px; width: 300px;">
<${buttonTag} slot="footer-actions" appearance="ghost">Cancel</${buttonTag}>
<${buttonTag} slot="footer-actions" appearance="outline">Ok</${buttonTag}>
</${richTextEditorTag}>
`;

export const plainTextContentInMobileWidth: StoryFn = createStory(mobileWidthComponent);

plainTextContentInMobileWidth.play = (): void => {
document.querySelector('nimble-rich-text-editor')!.setMarkdown(loremIpsum);
};

const multipleSubPointsContent = `
1. Sub point 1
1. Sub point 2
1. Sub point 3
1. Sub point 4
1. Sub point 5
1. Sub point 6
1. Sub point 7
1. Sub point 8
1. Sub point 9`;

export const multipleSubPointsContentInMobileWidth: StoryFn = createStory(mobileWidthComponent);

multipleSubPointsContentInMobileWidth.play = (): void => {
document
.querySelector('nimble-rich-text-editor')!
.setMarkdown(multipleSubPointsContent);
};

export const longWordContentInMobileWidth: StoryFn = createStory(mobileWidthComponent);

longWordContentInMobileWidth.play = (): void => {
aagash-ni marked this conversation as resolved.
Show resolved Hide resolved
document
.querySelector('nimble-rich-text-editor')!
.setMarkdown(
'ThisIsALongWordWithoutSpaceToTestLongWordInSmallWidthThisIsALongWordWithoutSpaceToTestLongWordInSmallWidth'
);
};
export const hiddenRichTextEditor: StoryFn = createStory(
hiddenWrapper(html`<${richTextEditorTag} hidden></${richTextEditorTag}>`)
);
Loading