Skip to content

Commit

Permalink
Merge branch '24_2' of https://github.com/DevExpress/DevExtreme into …
Browse files Browse the repository at this point in the history
…24_2-htmleditor-aria-readonly
  • Loading branch information
nikkithelegendarypokemonster committed Sep 3, 2024
2 parents 395d0a7 + 536fcb8 commit cc9e95c
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 160 deletions.
25 changes: 25 additions & 0 deletions packages/devextreme-angular/src/ui/chat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
} from '@angular/core';


import { Store } from 'devextreme/data';
import DataSource, { Options as DataSourceOptions } from 'devextreme/data/data_source';
import { DisposingEvent, InitializedEvent, Message, MessageSendEvent, OptionChangedEvent, User } from 'devextreme/ui/chat';

import DxChat from 'devextreme/ui/chat';
Expand Down Expand Up @@ -88,6 +90,19 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges
}


/**
* [descr:dxChatOptions.dataSource]
*/
@Input()
get dataSource(): Store | DataSource | DataSourceOptions | null | string | Array<Message> {
return this._getOption('dataSource');
}
set dataSource(value: Store | DataSource | DataSourceOptions | null | string | Array<Message>) {
this._setOption('dataSource', value);
}


/**
* [descr:WidgetOptions.disabled]
Expand Down Expand Up @@ -276,6 +291,13 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges
*/
@Output() activeStateEnabledChange: EventEmitter<boolean>;

/**
* This member supports the internal infrastructure and is not intended to be used directly from your code.
*/
@Output() dataSourceChange: EventEmitter<Store | DataSource | DataSourceOptions | null | string | Array<Message>>;

/**
* This member supports the internal infrastructure and is not intended to be used directly from your code.
Expand Down Expand Up @@ -383,6 +405,7 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges
{ subscribe: 'optionChanged', emit: 'onOptionChanged' },
{ emit: 'accessKeyChange' },
{ emit: 'activeStateEnabledChange' },
{ emit: 'dataSourceChange' },
{ emit: 'disabledChange' },
{ emit: 'elementAttrChange' },
{ emit: 'focusStateEnabledChange' },
Expand Down Expand Up @@ -412,6 +435,7 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges

ngOnChanges(changes: SimpleChanges) {
super.ngOnChanges(changes);
this.setupChanges('dataSource', changes);
this.setupChanges('items', changes);
}

Expand All @@ -422,6 +446,7 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges
}

ngDoCheck() {
this._idh.doCheck('dataSource');
this._idh.doCheck('items');
this._watcherHelper.checkWatchers();
super.ngDoCheck();
Expand Down
86 changes: 35 additions & 51 deletions packages/devextreme-scss/scss/widgets/base/chat/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,48 @@ $chat-text-area-height: 40px;
padding: 24px 0;
}

.dx-chat-message-bubble-container {
display: flex;
flex-direction: column;
row-gap: 4px;
max-width: 90%;
}

.dx-chat-message-group-alignment-start {
justify-items: start;
grid-template-columns: 44px 1fr;
grid-column: 2;

.dx-chat-message-bubble {
border-bottom-left-radius: 0;
border-top-left-radius: 0;

&:first-child {
border-top-left-radius: $chat-bubble-border-radius;
}

&:last-child {
border-bottom-left-radius: $chat-bubble-border-radius;
}
}
}

.dx-chat-message-group-alignment-end {
justify-items: end;

.dx-chat-message-bubble {
background-color: $chat-bubble-background-color-primary;
border-bottom-right-radius: 0;
border-top-right-radius: 0;

&:first-child {
border-top-right-radius: $chat-bubble-border-radius;
}

&:last-child {
border-bottom-right-radius: $chat-bubble-border-radius;
}
}
}

.dx-chat-message-group-information {
Expand Down Expand Up @@ -84,61 +119,10 @@ $chat-text-area-height: 40px;

.dx-chat-message-bubble {
padding: 8px 12px;
max-width: 90%;
border-radius: $chat-bubble-border-radius;
background-color: $chat-bubble-background-color-secondary;
}

.dx-chat-message-group-alignment-start .dx-chat-message-bubble.dx-chat-message-bubble-first {
border-bottom-left-radius: 0;
}

.dx-chat-message-group-alignment-start .dx-chat-message-bubble.dx-chat-message-bubble-last {
border-top-left-radius: 0;
}

.dx-chat-message-group-alignment-start .dx-chat-message-bubble-first.dx-chat-message-bubble-last {
border-bottom-left-radius: $chat-bubble-border-radius;
border-top-left-radius: $chat-bubble-border-radius;
}

.dx-chat-message-group-alignment-start .dx-chat-message-bubble:not(
.dx-chat-message-bubble-first.dx-chat-message-bubble-last,
.dx-chat-message-bubble-first,
.dx-chat-message-bubble-last) {
border-bottom-left-radius: 0;
border-top-left-radius: 0;
}

.dx-chat-message-group-alignment-end .dx-chat-message-bubble.dx-chat-message-bubble-first {
border-bottom-right-radius: 0;
}

.dx-chat-message-group-alignment-end .dx-chat-message-bubble.dx-chat-message-bubble-last {
border-top-right-radius: 0;
}

.dx-chat-message-group-alignment-end .dx-chat-message-bubble-first.dx-chat-message-bubble-last {
border-bottom-right-radius: $chat-bubble-border-radius;
border-top-right-radius: $chat-bubble-border-radius;
}

.dx-chat-message-group-alignment-end .dx-chat-message-bubble:not(
.dx-chat-message-bubble-first.dx-chat-message-bubble-last,
.dx-chat-message-bubble-first,
.dx-chat-message-bubble-last) {
border-bottom-right-radius: 0;
border-top-right-radius: 0;
}

.dx-chat-message-group-alignment-start .dx-chat-message-bubble {
grid-column: 2;
}

.dx-chat-message-group-alignment-end .dx-chat-message-bubble {
background-color: $chat-bubble-background-color-primary;
}

.dx-chat-message-box {
display: flex;
align-items: center;
Expand Down
3 changes: 3 additions & 0 deletions packages/devextreme-vue/src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createConfigurationComponent } from "./core/index";
type AccessibleOptions = Pick<Properties,
"accessKey" |
"activeStateEnabled" |
"dataSource" |
"disabled" |
"elementAttr" |
"focusStateEnabled" |
Expand All @@ -29,6 +30,7 @@ const DxChat = createComponent({
props: {
accessKey: String,
activeStateEnabled: Boolean,
dataSource: {},
disabled: Boolean,
elementAttr: Object,
focusStateEnabled: Boolean,
Expand All @@ -50,6 +52,7 @@ const DxChat = createComponent({
"update:hoveredElement": null,
"update:accessKey": null,
"update:activeStateEnabled": null,
"update:dataSource": null,
"update:disabled": null,
"update:elementAttr": null,
"update:focusStateEnabled": null,
Expand Down
12 changes: 7 additions & 5 deletions packages/devextreme/js/__internal/ui/chat/chat.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ComponentFactory } from '@js/core/component_registrator';
import registerComponent from '@js/core/component_registrator';
import Guid from '@js/core/guid';
import type { dxElementWrapper } from '@js/core/renderer';
Expand Down Expand Up @@ -35,6 +36,7 @@ class Chat extends Widget<Properties & { title: Title }> {
hoverStateEnabled: true,
title: '',
items: [],
dataSource: null,
user: { id: new Guid().toString() },
onMessageSend: undefined,
};
Expand Down Expand Up @@ -138,7 +140,7 @@ class Chat extends Widget<Properties & { title: Title }> {
case 'activeStateEnabled':
case 'focusStateEnabled':
case 'hoverStateEnabled':
this._messageBox.option({ [name]: value });
this._messageBox.option(name, value as Properties[typeof name]);
break;
case 'title': {
if (value) {
Expand All @@ -154,10 +156,11 @@ class Chat extends Widget<Properties & { title: Title }> {
break;
}
case 'user':
this._messageList.option('currentUserId', (value as Properties['user'])?.id);
this._messageList.option('currentUserId', (value as Properties[typeof name])?.id);
break;
case 'items':
this._messageList.option('items', (value as Properties['items']) ?? []);
case 'dataSource':
this._messageList.option(name, value as Properties[typeof name]);
break;
case 'onMessageSend':
this._createMessageSendAction();
Expand All @@ -176,7 +179,6 @@ class Chat extends Widget<Properties & { title: Title }> {
}
}

// @ts-expect-error ts-error
registerComponent('dxChat', Chat);
registerComponent('dxChat', Chat as unknown as ComponentFactory<Chat>);

export default Chat;
41 changes: 13 additions & 28 deletions packages/devextreme/js/__internal/ui/chat/chat_message_group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ const CHAT_MESSAGE_GROUP_ALIGNMENT_END_CLASS = 'dx-chat-message-group-alignment-
const CHAT_MESSAGE_GROUP_INFORMATION_CLASS = 'dx-chat-message-group-information';
const CHAT_MESSAGE_TIME_CLASS = 'dx-chat-message-time';
const CHAT_MESSAGE_AUTHOR_NAME_CLASS = 'dx-chat-message-author-name';
const CHAT_MESSAGE_BUBBLE_CLASS = 'dx-chat-message-bubble';
const CHAT_MESSAGE_BUBBLE_FIRST_CLASS = 'dx-chat-message-bubble-first';
const CHAT_MESSAGE_BUBBLE_LAST_CLASS = 'dx-chat-message-bubble-last';
const CHAT_MESSAGE_BUBBLE_CONTAINER_CLASS = 'dx-chat-message-bubble-container';

export type MessageGroupAlignment = 'start' | 'end';

Expand All @@ -28,6 +26,8 @@ export interface MessageGroupOptions extends WidgetOptions<MessageGroup> {
class MessageGroup extends Widget<MessageGroupOptions> {
_avatar?: Avatar;

_$messageBubbleContainer!: dxElementWrapper;

_getDefaultOptions(): MessageGroupOptions {
return {
...super._getDefaultOptions(),
Expand Down Expand Up @@ -84,31 +84,24 @@ class MessageGroup extends Widget<MessageGroupOptions> {
});
}

_renderMessageBubble(message: Message, index: number, length: number): void {
_renderMessageBubble(message: Message): void {
const $bubble = $('<div>');

const isFirst = index === 0;
const isLast = index === length - 1;

if (isFirst) {
$bubble.addClass(CHAT_MESSAGE_BUBBLE_FIRST_CLASS);
}

if (isLast) {
$bubble.addClass(CHAT_MESSAGE_BUBBLE_LAST_CLASS);
}

$bubble.appendTo(this.element());

this._createComponent($bubble, MessageBubble, {
text: message.text,
});

this._$messageBubbleContainer.append($bubble);
}

_renderMessageBubbles(items: Message[]): void {
items.forEach((message, index) => {
this._renderMessageBubble(message, index, items.length);
this._$messageBubbleContainer = $('<div>').addClass(CHAT_MESSAGE_BUBBLE_CONTAINER_CLASS);

items.forEach((message) => {
this._renderMessageBubble(message);
});

this._$messageBubbleContainer.appendTo(this.element());
}

_renderName(name: string, $element: dxElementWrapper): void {
Expand Down Expand Up @@ -147,13 +140,6 @@ class MessageGroup extends Widget<MessageGroupOptions> {
$information.appendTo(this.element());
}

_updateLastBubbleClasses(): void {
const $bubbles = $(this.element()).find(`.${CHAT_MESSAGE_BUBBLE_CLASS}`);
const $lastBubble = $bubbles.eq($bubbles.length - 1);

$lastBubble.removeClass(CHAT_MESSAGE_BUBBLE_LAST_CLASS);
}

_optionChanged(args: Record<string, unknown>): void {
const { name } = args;

Expand All @@ -174,8 +160,7 @@ class MessageGroup extends Widget<MessageGroupOptions> {

this._setOptionWithoutOptionChange('items', newItems);

this._updateLastBubbleClasses();
this._renderMessageBubble(message, newItems.length - 1, newItems.length);
this._renderMessageBubble(message);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/devextreme/js/core/component_registrator.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import DOMComponent from './dom_component';
import { UserDefinedElement } from './element';

type ComponentFactory<TComponent> = {
export type ComponentFactory<TComponent> = {
new(element: UserDefinedElement, options?: Record<string, unknown>): TComponent;
getInstance(element: UserDefinedElement): TComponent;
};
Expand Down
12 changes: 11 additions & 1 deletion packages/devextreme/js/ui/chat.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
InitializedEventInfo,
ChangedOptionInfo,
} from '../events/index';
import DataSource, { DataSourceLike } from '../data/data_source';

/**
* @docid _ui_chat_DisposingEvent
Expand Down Expand Up @@ -138,6 +139,13 @@ export interface dxChatOptions extends WidgetOptions<dxChat> {
* @public
*/
items?: Array<Message>;
/**
* @docid
* @type string | Array<Message> | Store | DataSource | DataSourceOptions | null
* @default null
* @public
*/
dataSource?: DataSourceLike<Message> | null;
/**
* @docid
* @default null
Expand All @@ -150,7 +158,7 @@ export interface dxChatOptions extends WidgetOptions<dxChat> {

/**
* @docid
* @inherits Widget
* @inherits Widget, DataHelperMixin
* @namespace DevExpress.ui
* @public
*/
Expand All @@ -161,6 +169,8 @@ export default class dxChat extends Widget<Properties> {
* @public
*/
renderMessage(message: Message): void;

getDataSource(): DataSource<Message>;
}

/** @public */
Expand Down
Loading

0 comments on commit cc9e95c

Please sign in to comment.