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

dotCMS/core#26912 [UI] AI actions menu selection is not working as should. #26995

Merged
merged 8 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
Expand Up @@ -278,6 +278,17 @@
}
}
}

.ai-loading {
display: flex;
justify-content: center;
align-items: center;
min-width: 100%;
padding: $spacing-1;
border-radius: $spacing-1;
border: 1px solid $color-palette-gray-400;
color: $color-palette-primary;
}
}

.video-container {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,13 @@
padding: $spacing-1;
margin-left: $spacing-8;

li {
.p-listbox-list .p-listbox-item {
padding: $spacing-2 $spacing-3;
border-bottom: 1px solid $color-palette-gray-300;
background-color: $white;

// accept option
&:first-child {
background-color: $color-palette-primary-200;
}

// regenerate option
&:nth-child(2) {
padding: $spacing-3;
background-color: $white;
}

// delete option
&:last-child {
border-top: 1px solid $color-palette-gray-300;
background-color: $white;
border-bottom: none;
}

&:hover {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
[attr.disabled]="vm.status === 'loading' || null"
(keyup.escape)="handleScape($event)"
(keydown.escape)="$event.stopPropagation()"
autofocus
formControlName="textPrompt"
pInputText
placeholder="{{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,13 @@ export class AIContentPromptView {
* template in ai-content-prompt.component.html
*/

this.componentStore.status$
.pipe(
skip(1),
takeUntil(this.destroy$),
filter((status) => status === 'exit')
)
.subscribe(() => {
this.componentStore.status$.pipe(skip(1), takeUntil(this.destroy$)).subscribe((status) => {
if (status === 'exit') {
hmoreras marked this conversation as resolved.
Show resolved Hide resolved
this.tippy?.hide();
});
} else if (status === 'loading') {
hmoreras marked this conversation as resolved.
Show resolved Hide resolved
this.editor.commands.setLoadingAIContentNode(true);
}
});

/**
* Subscription to delete AI_CONTENT node.
Expand Down Expand Up @@ -169,8 +167,6 @@ export class AIContentPromptView {
const prev = prevState ? this.pluginKey?.getState(prevState) : { open: false };

if (next?.open === prev?.open) {
this.tippy?.popperInstance?.forceUpdate();

return;
}

Expand Down Expand Up @@ -231,6 +227,7 @@ export class AIContentPromptView {
* @param notifyStore
*/
hide(notifyStore = true) {
this.tippy?.hide();
this.editor.setEditable(true);

this.editor.view.focus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@ declare module '@tiptap/core' {
interface Commands<ReturnType> {
AIContentNode: {
insertAINode: (content?: string) => ReturnType;
setLoadingAIContentNode: (loading: boolean) => ReturnType;
};
}
}

const AI_LOADING_CLASS = 'ai-loading';
export const AIContentNode = Node.create({
name: 'aiContent',

addAttributes() {
return {
content: {
default: ''
},
loading: {
default: false
}
};
},
Expand Down Expand Up @@ -70,7 +75,8 @@ export const AIContentNode = Node.create({
// If an AI_CONTENT node is found, replace its content.
if (nodeInformation) {
tr.setNodeMarkup(nodeInformation.from, undefined, {
content: content
content: content,
loading: false
});
// Set the node selection to the beginning of the replaced content.
commands.setNodeSelection(nodeInformation.from);
Expand All @@ -83,6 +89,20 @@ export const AIContentNode = Node.create({
type: this.name,
attrs: { content: content }
});
},
setLoadingAIContentNode:
(loading: boolean) =>
({ tr, editor }) => {
const nodeInformation = findNodeByType(editor, NodeTypes.AI_CONTENT);
// Set the loading attribute to the specified value.
if (nodeInformation) {
tr.setNodeMarkup(nodeInformation.from, undefined, {
...nodeInformation.node.attrs,
loading: loading
});
}

return true;
}
};
},
Expand All @@ -96,13 +116,18 @@ export const AIContentNode = Node.create({
const dom = document.createElement('div');
const div = document.createElement('div');

div.innerHTML = node.attrs.content || '';
div.innerHTML = node.attrs.loading
? `<span class="pi pi-spin pi-spinner"></span>`
: node.attrs.content;

dom.contentEditable = 'true';
dom.classList.add('ai-content-container');
dom.className = `ai-content-container ${node.attrs.loading ? AI_LOADING_CLASS : ''}`;

dom.append(div);

return { dom };
return {
dom
};
};
}
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ResolvedPos } from 'prosemirror-model';
import { ResolvedPos, Node } from 'prosemirror-model';
import { SelectionRange, TextSelection } from 'prosemirror-state';
import { EditorView } from 'prosemirror-view';

Expand Down
2 changes: 1 addition & 1 deletion dotCMS/src/main/webapp/html/dotcms-block-editor.js

Large diffs are not rendered by default.

Loading