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

[DRAFT] Move Adaptive Cards from component to bundle #1304

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions packages/bundle/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"plugins": [
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread",
"babel-plugin-version-transform"
],
Expand Down
51 changes: 44 additions & 7 deletions packages/bundle/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/bundle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"devDependencies": {
"@babel/cli": "^7.1.2",
"@babel/core": "^7.1.2",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.1.0",
"@babel/preset-env": "^7.1.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/bundle/src/FullReactWebChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import * as adaptiveCards from 'adaptivecards';
import memoize from 'memoize-one';
import React from 'react';

import BasicWebChat, { createAdaptiveCardsAttachmentMiddleware, concatMiddleware } from 'botframework-webchat-component';
import BasicWebChat, { concatMiddleware } from 'botframework-webchat-component';

import createAdaptiveCardsAttachmentMiddleware from './adaptiveCards/createAdaptiveCardMiddleware';
import renderMarkdown from './renderMarkdown';

// Add additional props to <WebChat>, so it support additional features
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { AdaptiveCard } from 'adaptivecards';
import memoize from 'memoize-one';
import React from 'react';

import AdaptiveCardRenderer from './AdaptiveCardRenderer';

import { AdaptiveCard } from 'adaptivecards';

function stripSubmitAction(card) {
if (!card.actions) {
return card;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { HostConfig } from 'adaptivecards';
import React from 'react';

import { localize } from '../Localization/Localize';
import connectToWebChat from '../connectToWebChat';
import ErrorBox from '../ErrorBox';
import getTabIndex from '../Utils/TypeFocusSink/getTabIndex';
import {
Components,
connectToWebChat,
getTabIndex,
localize
} from 'botframework-webchat-component';

const { ErrorBox } = Components;

function isPlainObject(obj) {
return obj.__proto__ === Object.prototype;
}

class AdaptiveCardRenderer extends React.PureComponent {
constructor(props) {
Expand Down Expand Up @@ -90,9 +99,12 @@ class AdaptiveCardRenderer extends React.PureComponent {
// Because there could be timing difference between .parse and .render, we could be using wrong Markdown engine

adaptiveCard.constructor.processMarkdown = renderMarkdown || (text => text);
adaptiveCard.hostConfig = adaptiveCardHostConfig;
adaptiveCard.onExecuteAction = this.handleExecuteAction;

if (adaptiveCardHostConfig) {
adaptiveCard.hostConfig = isPlainObject(adaptiveCardHostConfig) ? new HostConfig(adaptiveCardHostConfig) : adaptiveCardHostConfig;
}

const errors = adaptiveCard.validate();

if (errors.length) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import memoize from 'memoize-one';
import React from 'react';

import { AdaptiveCardBuilder } from '../Utils/AdaptiveCardBuilder';
import { Components, connectToWebChat } from 'botframework-webchat-component';

import { AdaptiveCardBuilder } from '../AdaptiveCardBuilder';
import CommonCard from './CommonCard';
import connectToWebChat from '../connectToWebChat';
import ImageContent from './ImageContent';
import VideoContent from './VideoContent';

const { ImageContent, VideoContent } = Components;

class AnimationCardAttachment extends React.Component {
constructor(props) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from 'react';

import AudioContent from './AudioContent';
import { Components, connectToWebChat } from 'botframework-webchat-component';

import CommonCard from './CommonCard';
import connectToWebChat from '../connectToWebChat';

const { AudioContent } = Components;

export default connectToWebChat(
({ styleSet }) => ({ styleSet })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import memoize from 'memoize-one';
import React from 'react';

import { AdaptiveCardBuilder } from '../Utils/AdaptiveCardBuilder';
import { AdaptiveCardBuilder } from '../AdaptiveCardBuilder';
import AdaptiveCardRenderer from './AdaptiveCardRenderer';

export default class extends React.Component {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import memoize from 'memoize-one';
import React from 'react';

import { AdaptiveCardBuilder } from '../Utils/AdaptiveCardBuilder';
import { AdaptiveCardBuilder } from '../AdaptiveCardBuilder';
import AdaptiveCardRenderer from './AdaptiveCardRenderer';

export default class extends React.Component {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import memoize from 'memoize-one';
import React from 'react';

import { AdaptiveCardBuilder } from '../Utils/AdaptiveCardBuilder';
import { AdaptiveCardBuilder } from '../AdaptiveCardBuilder';
import AdaptiveCardRenderer from './AdaptiveCardRenderer';

export default class extends React.Component {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import memoize from 'memoize-one';
import React from 'react';

import { AdaptiveCardBuilder } from '../Utils/AdaptiveCardBuilder';
import { localize } from '../Localization/Localize';
import { connectToWebChat, localize } from 'botframework-webchat-component';

import { AdaptiveCardBuilder } from '../AdaptiveCardBuilder';
import AdaptiveCardRenderer from './AdaptiveCardRenderer';
import connectToWebChat from '../connectToWebChat';

function nullOrUndefined(obj) {
return obj === null || typeof obj === 'undefined';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';

import { connectToWebChat } from 'botframework-webchat-component';

import CommonCard from './CommonCard';
import connectToWebChat from '../connectToWebChat';

export default connectToWebChat(
({ styleSet }) => ({ styleSet })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import memoize from 'memoize-one';
import React from 'react';

import { AdaptiveCardBuilder } from '../Utils/AdaptiveCardBuilder';
import { AdaptiveCardBuilder } from '../AdaptiveCardBuilder';
import AdaptiveCardRenderer from './AdaptiveCardRenderer';

export default class extends React.Component {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from 'react';

import { Components, connectToWebChat } from 'botframework-webchat-component';

import CommonCard from './CommonCard';
import connectToWebChat from '../connectToWebChat';
import VideoContent from './VideoContent';

const { VideoContent } = Components;

export default connectToWebChat(
({ styleSet }) => ({ styleSet })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';

import AdaptiveCardAttachment from '../../Attachment/AdaptiveCardAttachment';
import AnimationCardAttachment from '../../Attachment/AnimationCardAttachment';
import AudioCardAttachment from '../../Attachment/AudioCardAttachment';
import HeroCardAttachment from '../../Attachment/HeroCardAttachment';
import OAuthCardAttachment from '../../Attachment/OAuthCardAttachment';
import ReceiptCardAttachment from '../../Attachment/ReceiptCardAttachment';
import SignInCardAttachment from '../../Attachment/SignInCardAttachment';
import ThumbnailCardAttachment from '../../Attachment/ThumbnailCardAttachment';
import VideoCardAttachment from '../../Attachment/VideoCardAttachment';
import AdaptiveCardAttachment from './Attachment/AdaptiveCardAttachment';
import AnimationCardAttachment from './Attachment/AnimationCardAttachment';
import AudioCardAttachment from './Attachment/AudioCardAttachment';
import HeroCardAttachment from './Attachment/HeroCardAttachment';
import OAuthCardAttachment from './Attachment/OAuthCardAttachment';
import ReceiptCardAttachment from './Attachment/ReceiptCardAttachment';
import SignInCardAttachment from './Attachment/SignInCardAttachment';
import ThumbnailCardAttachment from './Attachment/ThumbnailCardAttachment';
import VideoCardAttachment from './Attachment/VideoCardAttachment';

// TODO: [P4] Rename this file or the whole middleware, it looks either too simple or too comprehensive now
export default function (props) {
Expand Down
1 change: 0 additions & 1 deletion packages/component/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"plugins": [
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread",
"babel-plugin-version-transform"
],
Expand Down
Loading