Skip to content

Commit 0c340ab

Browse files
authored
fix #160: add standalone output, update dependencies, reformat (#162)
also fixes an error when using renderChat without configuring local storage
1 parent 009bf76 commit 0c340ab

File tree

25 files changed

+2659
-7632
lines changed

25 files changed

+2659
-7632
lines changed

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ module.exports = {
1515
extends: [
1616
'plugin:react/recommended', // Uses the recommended rules from @eslint-plugin-react
1717
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
18-
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
1918
'plugin:storybook/recommended',
2019
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
2120
],

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yarn lint

README.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,14 @@ The toolkit is currently used in production by various conversational assistants
4141

4242
## Quick Start
4343

44-
Include `react`, `react-dom`, `@emotion-core`, `@emotion-styled`, `emotion-theming` and `tock-react-kit` in an HTML page.
45-
_React must be at least version 16.8 (must have hooks)_
44+
If you do not use a package manager, you can include the standalone bundle for the `tock-react-kit` in an HTML page.
45+
Note that this bundle includes its own copy of React - if you have an existing React application,
46+
please refer to the [module instructions below](#use-as-a-module).
4647

4748
```html
48-
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
49-
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
50-
<script crossorigin src="https://unpkg.com/@emotion/core@10/dist/core.umd.min.js"></script>
51-
<script crossorigin src="https://unpkg.com/@emotion/styled@10/dist/styled.umd.min.js"></script>
52-
<script crossorigin src="https://unpkg.com/emotion-theming@10/dist/emotion-theming.umd.min.js"></script>
5349
<script
5450
crossorigin
55-
src="https://unpkg.com/tock-react-kit@latest/build/tock-react-kit.umd.js"
51+
src="https://unpkg.com/tock-react-kit@latest/build/tock-react-kit-standalone.umd.js"
5652
></script>
5753
```
5854

@@ -69,14 +65,15 @@ Render your app in an element:
6965

7066
## Use as a module
7167

72-
You can also use it as a module (i.e [Create React App](https://github.com/facebook/create-react-app)) and bundle it:
68+
You can install this package alongside its peer dependencies using the package manager of your choice,
69+
and then bundle it with the rest of your web application. For example with NPM:
7370

7471
```
75-
npm i tock-react-kit
76-
npm i @emotion/react@11
77-
npm i @emotion/styled@11
72+
npm i react@18 react-dom@18 @emotion/react@11 @emotion/styled@11 tock-react-kit
7873
```
7974

75+
Your bundler must support ESM modules, which is the case for Webpack, Rollup and Vite among others.
76+
8077
### Use in a React app
8178

8279
```jsx
@@ -104,6 +101,8 @@ Therefore, in apps where the `Chat` component is susceptible to being unmounted
104101

105102
### Use in a non-React app
106103

104+
When working in a non-React app, you can once again use `renderChat` to render the app in an existing element:
105+
107106
```js
108107
import { renderChat } from 'tock-react-kit';
109108

@@ -510,7 +509,7 @@ This is typically used to pass tokens or custom values to the Bot backend.
510509

511510
Tock web connector can send custom messages :
512511

513-
```json
512+
```json5
514513
{
515514
data: {
516515
departure: 'Paris',

package.json

Lines changed: 40 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
"build/tock-react-kit.d.ts",
1616
"build/tock-react-kit.esm.js",
1717
"build/tock-react-kit.esm.js.map",
18-
"build/tock-react-kit.umd.js"
18+
"build/tock-react-kit.umd.js",
19+
"build/tock-react-kit-standalone.umd.js",
20+
"build/tock-react-kit-standalone.esm.js"
1921
],
2022
"scripts": {
2123
"storybook": "storybook dev -p 6006",
@@ -29,11 +31,6 @@
2931
"test-release": "np --preview",
3032
"release": "np"
3133
},
32-
"husky": {
33-
"hooks": {
34-
"pre-commit": "npm run lint"
35-
}
36-
},
3734
"dependencies": {
3835
"deepmerge": "^4.2.2",
3936
"linkifyjs": "^2.1.9",
@@ -47,85 +44,54 @@
4744
"@babel/preset-react": "^7.22.15",
4845
"@babel/preset-typescript": "^7.22.15",
4946
"@emotion/eslint-plugin": "^11.11.0",
50-
"@emotion/react": "^11.11.1",
51-
"@emotion/styled": "^11.0.0",
52-
"@storybook/addon-essentials": "^7.4.0",
53-
"@storybook/addon-interactions": "^7.4.0",
54-
"@storybook/addon-links": "^7.4.0",
55-
"@storybook/addons": "^7.4.0",
56-
"@storybook/blocks": "^7.4.0",
57-
"@storybook/builder-webpack5": "^7.4.0",
58-
"@storybook/react": "^7.4.0",
59-
"@storybook/react-webpack5": "^7.4.0",
47+
"@emotion/react": "^11.11.3",
48+
"@emotion/styled": "^11.11.0",
49+
"@rollup/plugin-commonjs": "^25.0.7",
50+
"@rollup/plugin-node-resolve": "^15.2.3",
51+
"@rollup/plugin-replace": "^5.0.5",
52+
"@rollup/plugin-terser": "^0.4.4",
53+
"@rollup/plugin-typescript": "^11.1.6",
54+
"@storybook/addon-essentials": "^7.6.17",
55+
"@storybook/addon-interactions": "^7.6.17",
56+
"@storybook/addon-links": "^7.6.17",
57+
"@storybook/addons": "^7.6.17",
58+
"@storybook/blocks": "^7.6.17",
59+
"@storybook/builder-webpack5": "^7.6.17",
60+
"@storybook/react": "^7.6.17",
61+
"@storybook/react-webpack5": "^7.6.17",
6062
"@storybook/testing-library": "^0.2.0",
61-
"@types/node": "^14.0.26",
62-
"@types/react-color": "^3.0.4",
63-
"@types/react-dom": "^18.2.8",
64-
"@types/storybook__react": "^5.2.1",
65-
"@typescript-eslint/eslint-plugin": "^3.9.1",
66-
"@typescript-eslint/parser": "^3.9.1",
63+
"@types/node": "^20.11.20",
64+
"@types/react-dom": "^18.2.19",
65+
"@typescript-eslint/eslint-plugin": "^7.0.2",
66+
"@typescript-eslint/parser": "^7.0.2",
6767
"auto-changelog": "^2.4.0",
6868
"babel-loader": "^9.1.3",
69-
"eslint": "^7.7.0",
70-
"eslint-config-prettier": "^6.11.0",
71-
"eslint-plugin-prettier": "^3.1.4",
72-
"eslint-plugin-react": "^7.20.6",
73-
"eslint-plugin-storybook": "^0.6.13",
74-
"husky": "^4.2.5",
75-
"np": "^8.0.4",
76-
"prettier": "^2.0.5",
69+
"eslint": "^8.56.0",
70+
"eslint-config-prettier": "^9.1.0",
71+
"eslint-plugin-prettier": "^5.1.3",
72+
"eslint-plugin-react": "^7.33.2",
73+
"eslint-plugin-storybook": "^0.8.0",
74+
"husky": "^9.0.11",
75+
"np": "^9.2.0",
76+
"prettier": "^3.2.5",
7777
"react": "^18.2.0",
7878
"react-dom": "^18.2.0",
79-
"rollup": "^3.29.0",
80-
"rollup-plugin-commonjs": "^10.1.0",
81-
"rollup-plugin-dts": "^6.0.2",
82-
"rollup-plugin-node-resolve": "^5.2.0",
83-
"rollup-plugin-replace": "^2.2.0",
84-
"rollup-plugin-typescript": "^1.0.1",
85-
"storybook": "^7.4.0",
86-
"type-fest": "^4.3.1",
87-
"typescript": "^4.9.5"
79+
"rollup": "^4.12.0",
80+
"rollup-plugin-dts": "^6.1.0",
81+
"rollup-plugin-sourcemaps": "^0.6.3",
82+
"storybook": "^7.6.17",
83+
"type-fest": "^4.10.3",
84+
"typescript": "^5.3.3"
8885
},
8986
"peerDependencies": {
9087
"@emotion/react": "^11.0.0",
9188
"@emotion/styled": "^11.0.0",
92-
"react": ">=16.13",
93-
"react-dom": ">=16.13"
89+
"react": ">=17.0",
90+
"react-dom": ">=17.0"
9491
},
9592
"resolutions": {
96-
"immer": "9.0.6",
97-
"y18n": "5.0.8",
98-
"lodash": "4.17.21",
99-
"lodash-es": "4.17.21",
100-
"set-value": "4.0.1",
101-
"trim-newlines": "3.0.1",
102-
"glob-parent": "5.1.2",
103-
"normalize-url": "4.5.1",
104-
"ssri": "8.0.1",
105-
"react-dev-utils": "11.0.4",
106-
"hosted-git-info": "3.0.8",
107-
"browserslist": "4.17.1",
108-
"merge-deep": "3.0.3",
109-
"tar": "6.1.9",
110-
"prismjs": "1.27.0",
111-
"ini": "1.3.6",
112-
"semver-regex": "3.1.4",
113-
"nth-check": "2.0.1",
114-
"elliptic": "6.5.4",
115-
"highlight.js": "10.7.3",
116-
"path-parse": "1.0.7",
117-
"handlebars": "4.7.7",
118-
"shelljs": "0.8.5",
119-
"ansi-html": "0.0.8",
120-
"postcss": "7.0.36",
121-
"node-fetch": "2.6.7",
122-
"ansi-regex": "5.0.1",
123-
"trim": "0.0.3",
124-
"minimist": "1.2.6",
125-
"shell-quote": "1.7.3",
126-
"got": "11.8.5",
127-
"ejs": "3.1.7",
128-
"terser": "5.14.2"
93+
"jackspeak": "2.1.1",
94+
"string-width": "^4"
12995
},
13096
"auto-changelog": {
13197
"includeBranch": [

rollup.config.mjs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import commonjs from 'rollup-plugin-commonjs';
1+
import commonjs from '@rollup/plugin-commonjs';
2+
import resolve from '@rollup/plugin-node-resolve';
3+
import replace from '@rollup/plugin-replace';
24
import dts from 'rollup-plugin-dts';
3-
import resolve from 'rollup-plugin-node-resolve';
4-
import replace from 'rollup-plugin-replace';
5-
import typescript from 'rollup-plugin-typescript';
5+
import terser from "@rollup/plugin-terser";
6+
import typescript from '@rollup/plugin-typescript';
67

78
export default [
89
{
910
input: 'src/index.ts',
1011
external: ['react', 'react-dom', '@emotion/react', '@emotion/styled'],
1112
output: [
1213
{
14+
// TODO deprecated build output, remove in 24.x
1315
file: 'build/tock-react-kit.umd.js',
1416
format: 'umd',
1517
name: 'TockReact',
@@ -35,6 +37,31 @@ export default [
3537
}),
3638
],
3739
},
40+
{
41+
input: 'src/index.ts',
42+
output: [
43+
{
44+
file: 'build/tock-react-kit-standalone.umd.js',
45+
format: 'umd',
46+
name: 'TockReact',
47+
sourcemap: true,
48+
},
49+
{
50+
file: 'build/tock-react-kit-standalone.esm.js',
51+
format: 'esm',
52+
sourcemap: true,
53+
},
54+
],
55+
plugins: [
56+
resolve(),
57+
commonjs(),
58+
typescript(),
59+
replace({
60+
'process.env.NODE_ENV': JSON.stringify('production'),
61+
}),
62+
terser(),
63+
],
64+
},
3865
{
3966
// path to your declaration files root
4067
input: 'src/index.ts',

src/TockContext.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@ import { retrieveUserId } from './utils';
1313
import { QuickReply } from './model/buttons';
1414
import { Message } from './model/messages';
1515

16-
export const TockSettingsContext: Context<
17-
TockSettings | undefined
18-
> = createContext<TockSettings | undefined>(undefined);
16+
export const TockSettingsContext: Context<TockSettings | undefined> =
17+
createContext<TockSettings | undefined>(undefined);
1918

2019
export const TockStateContext: Context<TockState | undefined> = createContext<
2120
TockState | undefined
2221
>(undefined);
23-
export const TockStateDispatch: Context<
24-
Dispatch<TockAction> | undefined
25-
> = createContext<Dispatch<TockAction> | undefined>(undefined);
22+
export const TockStateDispatch: Context<Dispatch<TockAction> | undefined> =
23+
createContext<Dispatch<TockAction> | undefined>(undefined);
2624

2725
export const useTockSettings: () => TockSettings = () => {
2826
const settings = useContext(TockSettingsContext);
@@ -41,9 +39,8 @@ export const useTockState: () => TockState = () => {
4139
};
4240

4341
export const useTockDispatch: () => Dispatch<TockAction> = () => {
44-
const dispatch: Dispatch<TockAction> | undefined = useContext(
45-
TockStateDispatch,
46-
);
42+
const dispatch: Dispatch<TockAction> | undefined =
43+
useContext(TockStateDispatch);
4744
if (!dispatch) {
4845
throw new Error('useTockDispatch must be used in a TockContext');
4946
}

src/components/Card/Card.tsx

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,17 @@ import UrlButton from '../buttons/UrlButton';
1212
import PostBackButton from '../buttons/PostBackButton';
1313
import { css, Theme } from '@emotion/react';
1414

15-
export const CardOuter: StyledComponent<DetailedHTMLProps<
16-
HTMLAttributes<HTMLLIElement>,
17-
HTMLLIElement
18-
>> = styled.li`
15+
export const CardOuter: StyledComponent<
16+
DetailedHTMLProps<HTMLAttributes<HTMLLIElement>, HTMLLIElement>
17+
> = styled.li`
1918
max-width: ${theme('sizing.conversation.width')};
2019
margin: 0.5em auto;
2120
list-style: none;
2221
`;
2322

24-
export const CardContainer: StyledComponent<DetailedHTMLProps<
25-
HTMLAttributes<HTMLDivElement>,
26-
HTMLDivElement
27-
>> = styled.div`
23+
export const CardContainer: StyledComponent<
24+
DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
25+
> = styled.div`
2826
padding: 0.5em;
2927
background: ${theme('palette.background.card')};
3028
color: ${theme('palette.text.card')};
@@ -35,10 +33,9 @@ export const CardContainer: StyledComponent<DetailedHTMLProps<
3533
${theme('overrides.card.cardContainer')};
3634
`;
3735

38-
const CardTitle: StyledComponent<DetailedHTMLProps<
39-
HTMLAttributes<HTMLSpanElement>,
40-
HTMLSpanElement
41-
>> = styled.span`
36+
const CardTitle: StyledComponent<
37+
DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>
38+
> = styled.span`
4239
margin: 0.5em 0;
4340
font-size: 1.5em;
4441
font-weight: bold;
@@ -47,10 +44,9 @@ const CardTitle: StyledComponent<DetailedHTMLProps<
4744
${theme('overrides.card.cardTitle')};
4845
`;
4946

50-
const CardSubTitle: StyledComponent<DetailedHTMLProps<
51-
HTMLAttributes<HTMLSpanElement>,
52-
HTMLSpanElement
53-
>> = styled.span`
47+
const CardSubTitle: StyledComponent<
48+
DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>
49+
> = styled.span`
5450
margin: 0.5em 0;
5551
font-size: 1em;
5652
font-weight: bold;
@@ -59,20 +55,18 @@ const CardSubTitle: StyledComponent<DetailedHTMLProps<
5955
${theme('overrides.card.cardSubTitle')};
6056
`;
6157

62-
const CardImage: StyledComponent<DetailedHTMLProps<
63-
ImgHTMLAttributes<HTMLImageElement>,
64-
HTMLImageElement
65-
>> = styled.img`
58+
const CardImage: StyledComponent<
59+
DetailedHTMLProps<ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>
60+
> = styled.img`
6661
max-width: 100%;
6762
max-height: 100%;
6863
6964
${theme('overrides.card.cardImage')};
7065
`;
7166

72-
const ButtonList: StyledComponent<DetailedHTMLProps<
73-
HTMLAttributes<HTMLUListElement>,
74-
HTMLUListElement
75-
>> = styled.ul`
67+
const ButtonList: StyledComponent<
68+
DetailedHTMLProps<HTMLAttributes<HTMLUListElement>, HTMLUListElement>
69+
> = styled.ul`
7670
margin: 0.5em 0;
7771
list-style: none;
7872
padding: 0.5em 0;
@@ -168,8 +162,8 @@ const Card = React.forwardRef<HTMLLIElement, CardProps>(function cardRender(
168162
ref == undefined
169163
? undefined
170164
: roleDescription
171-
? roleDescription
172-
: 'Slide'
165+
? roleDescription
166+
: 'Slide'
173167
}
174168
>
175169
<CardContainer aria-hidden={isHidden}>

0 commit comments

Comments
 (0)