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 & viewer | Support for absolute link #1496

Merged
merged 77 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
1c0e577
restructure folder changes
vivinkrishna-ni Aug 31, 2023
fa86b5a
Fix component import in angular
vivinkrishna-ni Aug 31, 2023
c7f895d
Fixing build issue in angular viewer module
vivinkrishna-ni Aug 31, 2023
01afe47
Updated the markdown serializer class
vivinkrishna-ni Aug 31, 2023
bafbe48
Renaming the initialization markdown serializer method
vivinkrishna-ni Aug 31, 2023
91bb520
Fix lint errors
vivinkrishna-ni Aug 31, 2023
3a70156
Change files
vivinkrishna-ni Aug 31, 2023
d37e001
Update change file description
vivinkrishna-ni Aug 31, 2023
d9d06de
Merge branch 'main' into users/vivin/revamp-rich-text-components
vivinkrishna-ni Sep 1, 2023
2c2d5ac
Resolve merge conflicts
vivinkrishna-ni Sep 1, 2023
b7fe9d8
Update editor component paths for rich text editor
vivinkrishna-ni Sep 1, 2023
b819d0e
Updating pageobject paths for angular files
vivinkrishna-ni Sep 1, 2023
4acdff3
Resolve merge conflicts
vivinkrishna-ni Sep 1, 2023
ee47b00
Merge branch 'main' into users/vivin/revamp-rich-text-components
vivinkrishna-ni Sep 1, 2023
fdc3cf7
Updated serialize method name
vivinkrishna-ni Sep 1, 2023
65acbd7
Moved the parser initialization in viewer component just like the edi…
vivinkrishna-ni Sep 1, 2023
efa562a
Merge branch 'main' into users/vivin/revamp-rich-text-components
vivinkrishna-ni Sep 1, 2023
b38df31
Resolve PR comments
vivinkrishna-ni Sep 4, 2023
719e0b7
Merge branch 'users/vivin/revamp-rich-text-components' of https://git…
vivinkrishna-ni Sep 4, 2023
b485046
Merge branch 'main' into users/vivin/revamp-rich-text-components
vivinkrishna-ni Sep 4, 2023
163de0e
Moved the specs folder to common rich-text folder
vivinkrishna-ni Sep 4, 2023
f3c7c13
Merge branch 'main' into users/vivin/revamp-rich-text-components
vivinkrishna-ni Sep 5, 2023
ea5b737
Merge branch 'main' into users/vivin/revamp-rich-text-components
vivinkrishna-ni Sep 5, 2023
c2c6367
Resolving PR comments
vivinkrishna-ni Sep 6, 2023
6c9de89
Minor import order in viewer spec
vivinkrishna-ni Sep 6, 2023
42eaa06
Merge branch 'main' into users/vivin/revamp-rich-text-components
vivinkrishna-ni Sep 6, 2023
7454fa1
Merge branch 'main' into users/vivin/revamp-rich-text-components
vivinkrishna-ni Sep 6, 2023
0657434
Update paths for label spec file
vivinkrishna-ni Sep 6, 2023
92df4e9
Added markdown model files
vivinkrishna-ni Sep 6, 2023
46126aa
refactor: migrate markdown parser tests from text editor and viewer c…
saikrishnan-ni Sep 6, 2023
219941a
chore: run format
saikrishnan-ni Sep 6, 2023
5d80878
Added spec file for serializer and updated static classes for model f…
vivinkrishna-ni Sep 6, 2023
15b6608
Merge branch 'main' into users/sai/markdown-model-refactors
vivinkrishna-ni Sep 7, 2023
3a67d52
Fix lint
vivinkrishna-ni Sep 7, 2023
5beb940
Removed previous branch change files
vivinkrishna-ni Sep 7, 2023
a6490b9
Change files
saikrishnan-ni Sep 7, 2023
7664716
refactor: update email id in change file
saikrishnan-ni Sep 7, 2023
f674ddf
refactor: remove redundant eslint disable
saikrishnan-ni Sep 7, 2023
6109d1f
refactor: add in review suggestion test cases
saikrishnan-ni Sep 7, 2023
81e348a
chore: run format
saikrishnan-ni Sep 7, 2023
1a6e97f
refactor: add in review changes
saikrishnan-ni Sep 7, 2023
86ba4a0
Merge branch 'main' into users/sai/markdown-model-refactors
saikrishnan-ni Sep 7, 2023
7bedc9c
absolute link support in editor
vivinkrishna-ni Sep 7, 2023
5338d07
Merge branch 'users/sai/markdown-model-refactors' into users/vivin/li…
vivinkrishna-ni Sep 7, 2023
fd65fdb
Minor comment description
vivinkrishna-ni Sep 7, 2023
e1ed701
Updated the comment description about link behavior
vivinkrishna-ni Sep 8, 2023
b3ba37d
refactor: add parser utils for reusable functions
saikrishnan-ni Sep 8, 2023
f6d27d8
refactor:remove unwanted type conversion and update function naming
saikrishnan-ni Sep 8, 2023
9969270
Removed mixable configuration from the serializer for link mark
vivinkrishna-ni Sep 8, 2023
647e05d
Merge branch 'users/sai/markdown-model-refactors' into users/vivin/li…
vivinkrishna-ni Sep 8, 2023
3c4f72d
Merge branch 'main' into users/vivin/link-support
vivinkrishna-ni Sep 9, 2023
78a9f4b
Change files
vivinkrishna-ni Sep 9, 2023
2ffd1fb
Resolving comments partially
vivinkrishna-ni Sep 11, 2023
946b418
Fix lint
vivinkrishna-ni Sep 11, 2023
42c7b68
Rendering "a" tag in place of "nimble-anchor" in editor.
vivinkrishna-ni Sep 11, 2023
8d3d81e
Fix lint
vivinkrishna-ni Sep 11, 2023
b625927
Updates to linking styles
vivinkrishna-ni Sep 12, 2023
1c3cbb4
removing heights from the storybook docs
vivinkrishna-ni Sep 12, 2023
676e4ac
Normalization of link texts to render encoded and non-ascii character…
vivinkrishna-ni Sep 12, 2023
282f22b
Added few more link tests
vivinkrishna-ni Sep 12, 2023
2eba73d
Minor code changes
vivinkrishna-ni Sep 12, 2023
597de3c
Fix lint
vivinkrishna-ni Sep 12, 2023
38739e3
Fix test case fail in editor
vivinkrishna-ni Sep 12, 2023
19463de
Merge branch 'main' into users/vivin/link-support
vivinkrishna-ni Sep 12, 2023
7169a06
Update the code comment to explain the rationale for the same.
vivinkrishna-ni Sep 13, 2023
c96a601
Merge branch 'main' into users/vivin/link-support
vivinkrishna-ni Sep 13, 2023
8de8361
Resolve PR comments
vivinkrishna-ni Sep 14, 2023
3a35a26
Minor comment error change
vivinkrishna-ni Sep 14, 2023
9b04787
Minor test case update
vivinkrishna-ni Sep 14, 2023
f425b5c
Removed forward slash in emoji test case
vivinkrishna-ni Sep 14, 2023
14d74dd
Merge branch 'main' into users/vivin/link-support
vivinkrishna-ni Sep 14, 2023
b0beadc
Merge branch 'main' into users/vivin/link-support
vivinkrishna-ni Sep 14, 2023
5335091
Added matrix test for long link in mobile width
vivinkrishna-ni Sep 14, 2023
5ba52df
Merge branch 'users/vivin/link-support' of https://github.com/ni/nimb…
vivinkrishna-ni Sep 14, 2023
23b8fdd
Updated the comment of parseHTML in editor
vivinkrishna-ni Sep 14, 2023
4897b24
Merge branch 'main' into users/vivin/link-support
vivinkrishna-ni Sep 14, 2023
2008979
Merge branch 'main' into users/vivin/link-support
vivinkrishna-ni Sep 14, 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": "Support for absolute links in rich text components",
"packageName": "@ni/nimble-components",
"email": "[email protected]",
"dependentChangeType": "patch"
}
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/nimble-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"@tiptap/extension-document": "^2.1.6",
"@tiptap/extension-history": "^2.1.6",
"@tiptap/extension-italic": "^2.1.6",
"@tiptap/extension-link": "^2.1.6",
"@tiptap/extension-list-item": "^2.1.6",
"@tiptap/extension-ordered-list": "^2.1.6",
"@tiptap/extension-paragraph": "^2.1.6",
Expand Down
44 changes: 43 additions & 1 deletion packages/nimble-components/src/rich-text/editor/index.ts
vivinkrishna-ni marked this conversation as resolved.
Show resolved Hide resolved
vivinkrishna-ni marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import {
findParentNode,
isList,
AnyExtension,
Extension
Extension,
Mark
} from '@tiptap/core';
import Bold from '@tiptap/extension-bold';
import BulletList from '@tiptap/extension-bullet-list';
import Document from '@tiptap/extension-document';
import History from '@tiptap/extension-history';
import Italic from '@tiptap/extension-italic';
import Link, { LinkOptions } from '@tiptap/extension-link';
import ListItem from '@tiptap/extension-list-item';
import OrderedList from '@tiptap/extension-ordered-list';
import Paragraph from '@tiptap/extension-paragraph';
Expand All @@ -31,6 +33,7 @@ import { TipTapNodeName } from './types';
import type { ErrorPattern } from '../../patterns/error/types';
import { RichTextMarkdownParser } from '../models/markdown-parser';
import { RichTextMarkdownSerializer } from '../models/markdown-serializer';
import { anchorTag } from '../../anchor';

declare global {
interface HTMLElementTagNameMap {
Expand Down Expand Up @@ -330,6 +333,8 @@ export class RichTextEditor extends FoundationElement implements ErrorPattern {
}

private createTiptapEditor(): Editor {
const customLink = this.getCustomLinkExtension();

/**
* For more information on the extensions for the supported formatting options, refer to the links below.
* Tiptap marks: https://tiptap.dev/api/marks
Expand All @@ -350,11 +355,48 @@ export class RichTextEditor extends FoundationElement implements ErrorPattern {
Placeholder.configure({
placeholder: '',
showOnlyWhenEditable: false
}),
customLink.configure({
// HTMLAttribute cannot be in camelCase as we want to match it with the name in Tiptap
// eslint-disable-next-line @typescript-eslint/naming-convention
HTMLAttributes: {
rel: 'noopener noreferrer',
target: null
},
autolink: true,
openOnClick: false,
linkOnPaste: false,
vivinkrishna-ni marked this conversation as resolved.
Show resolved Hide resolved
validate: href => /^https?:\/\//i.test(href)
})
]
});
}

/**
* Extending the default link mark schema defined in the TipTap.
*
* "excludes": https://prosemirror.net/docs/ref/#model.MarkSpec.excludes
* "inclusive": https://prosemirror.net/docs/ref/#model.MarkSpec.inclusive
* "parseHTML": https://tiptap.dev/guide/custom-extensions#parse-html
* "renderHTML": https://tiptap.dev/guide/custom-extensions/#render-html
*/
private getCustomLinkExtension(): Mark<LinkOptions> {
return Link.extend({
excludes: '_',
vivinkrishna-ni marked this conversation as resolved.
Show resolved Hide resolved
vivinkrishna-ni marked this conversation as resolved.
Show resolved Hide resolved
inclusive: false,
vivinkrishna-ni marked this conversation as resolved.
Show resolved Hide resolved
parseHTML() {
return [{ tag: anchorTag }];
vivinkrishna-ni marked this conversation as resolved.
Show resolved Hide resolved
},
// HTMLAttribute cannot be in camelCase as we want to match it with the name in Tiptap
// eslint-disable-next-line @typescript-eslint/naming-convention
renderHTML({ HTMLAttributes }) {
// The below 'a' tag should be replaced with 'nimble-anchor' once the below issue is fixed.
// https://github.com/ni/nimble/issues/1516
return ['a', HTMLAttributes];
}
});
}

/**
* This function takes the Fragment from parseMarkdownToDOM function and return the serialized string using XMLSerializer
*/
Expand Down
23 changes: 22 additions & 1 deletion packages/nimble-components/src/rich-text/editor/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
failColor,
iconSize,
smallDelay,
standardPadding
standardPadding,
linkFontColor
} from '../../theme-provider/design-tokens';
import { styles as errorStyles } from '../../patterns/error/styles';

Expand Down Expand Up @@ -188,6 +189,26 @@ export const styles = css`
color: ${controlLabelDisabledFontColor};
}

.ProseMirror a {
vivinkrishna-ni marked this conversation as resolved.
Show resolved Hide resolved
vivinkrishna-ni marked this conversation as resolved.
Show resolved Hide resolved
color: ${linkFontColor};
white-space: normal;
${
/**
* Setting 'pointer-events: none;' to restrict the user from opening a link using the right-click context menu: If the user manually edits
* the link's text content, the 'href' attribute of the anchor tag will not be updated. If they attempt to open it using
* the right-click context menu with 'Open in new tab/window,' it will still navigate to the link specified
* in the 'href' attribute, which may create unnecessary confusion while trying to open the link.
vivinkrishna-ni marked this conversation as resolved.
Show resolved Hide resolved
*/ ''
vivinkrishna-ni marked this conversation as resolved.
Show resolved Hide resolved
}
pointer-events: none;
}

:host([disabled]) .ProseMirror a {
color: ${bodyDisabledFontColor};
fill: currentcolor;
cursor: default;
}

.footer-section {
display: flex;
justify-content: space-between;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import type { ToggleButton } from '../../../toggle-button';
import type { ToolbarButton } from './types';
import {
getTagsFromElement,
getLeafContentsFromElement
getLeafContentsFromElement,
getLastChildElement,
getLastChildElementAttribute
} from '../../models/testing/markdown-parser-utils';

/**
Expand Down Expand Up @@ -109,15 +111,18 @@ export class RichTextEditorPageObject {
}

public async setEditorTextContent(value: string): Promise<void> {
let lastElement = this.getTiptapEditor()?.lastElementChild;

while (lastElement?.lastElementChild) {
lastElement = lastElement?.lastElementChild;
}
lastElement!.parentElement!.textContent = value;
const lastElement = this.getEditorLastChildElement();
lastElement.parentElement!.textContent = value;
await waitForUpdatesAsync();
}

public getEditorLastChildAttribute(attribute: string): string {
return getLastChildElementAttribute(
attribute,
this.getTiptapEditor() as HTMLElement
);
}

public getEditorFirstChildTagName(): string {
return this.getTiptapEditor()?.firstElementChild?.tagName ?? '';
}
Expand All @@ -136,6 +141,28 @@ export class RichTextEditorPageObject {
);
}

public getEditorTagNamesWithClosingTags(): string[] {
const tagNames: string[] = [];
const tiptapEditor = this.getTiptapEditor();

const processNode = (node: Node): void => {
if (node.nodeType === Node.ELEMENT_NODE) {
const el = node as Element;
tagNames.push(el.tagName);

el.childNodes.forEach(processNode);

tagNames.push(`/${el.tagName}`);
}
};

if (tiptapEditor) {
processNode(tiptapEditor);
}

return tagNames.slice(1, -1);
}

public getFormattingButtonTextContent(
toolbarButton: ToolbarButton
): string {
Expand Down Expand Up @@ -217,4 +244,8 @@ export class RichTextEditorPageObject {
);
return buttons[button];
}

private getEditorLastChildElement(): Element {
return getLastChildElement(this.getTiptapEditor() as HTMLElement)!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const metadata: Meta = {
}
};

const richTextMarkdownString = '1. **Bold*Italics***';
const richTextMarkdownString = '1. <https://nimble.ni.dev>\n2. **Bold*Italics***';

export default metadata;

Expand Down
Loading
Loading