UNPKG

9.18 kBMarkdownView Raw
1# React Transcript Editor
2
3<!-- _One liner_ -->
4
5A React component to make transcribing audio and video easier and faster.
6
7[![install size](https://packagephobia.now.sh/badge?p=@bbc/react-transcript-editor)](https://packagephobia.now.sh/result?p=@bbc/react-transcript-editor)
8
9The project uses [this github project boards to organise and the co-ordinate development](https://github.com/bbc/react-transcript-editor/projects).
10
11_--> Work in progress <--_
12
13<!-- _Screenshot of UI - optional_ -->
14
15- [You can see a demo by clicking here ](https://bbc.github.io/react-transcript-editor/iframe.html?id=demo--default) (and then click the `load demo` button)
16- [And you can see a list of features here](./docs/features-list.md).
17
18## Development env
19
20 <!-- _How to run the development environment_ -->
21
22- npm > `6.1.0`
23- [Node 10 - dubnium](https://scotch.io/tutorials/whats-new-in-node-10-dubnium)
24
25Node version is set in node version manager [`.nvmrc`](https://github.com/creationix/nvm#nvmrc)
26
27<!-- _Coding style convention ref optional, eg which linter to use_ -->
28
29<!-- _Linting, github pre-push hook - optional_ -->
30
31## Setup
32
33<!-- _stack - optional_ -->
34<!-- _How to build and run the code/app_ -->
35
36Fork this repository + git clone + cd into folder
37
38## Usage - development
39
40Git clone this repository and cd into the folder.
41
42To start the storybook run
43
44```
45npm start
46```
47
48Visit [http://localhost:6006](http://localhost:6006)
49
50## Usage - production
51
52Available on [npm - `@bbc/react-transcript-editor`](https://www.npmjs.com/package/@bbc/react-transcript-editor)
53
54```
55npm install @bbc/react-transcript-editor
56```
57
58```js
59import TranscriptEditor from '@bbc/react-transcript-editor';
60```
61
62```js
63 <TranscriptEditor
64 transcriptData={ someJsonFile }
65 mediaUrl={'https://download.ted.com/talks/KateDarling_2018S-950k.mp4'}
66 isEditable={true}
67 spellCheck={false}
68 sttJsonType={ 'bbckaldi' }
69 handleAnalyticsEvents={ this.handleAnalyticsEvents }
70 fileName={'ted-talk.mp4'}
71 title={'Ted Talk'}
72 ref={ this.transcriptEditorRef }
73 />
74```
75
76
77| Attributes | Description | required | type |
78| :------------- | :---------- | :-----------: | :-----------: |
79| transcriptData | Transcript json | yes | Json |
80| mediaUrl | string url to media file - audio or video | yes | String |
81| isEditable | set to true if you want to be able to edit the text | no | Boolean |
82|spellCheck | set to true if you want the browser to spell check this transcript | no | Boolean |
83| handleAnalyticsEvents | if you want to collect analytics events. | no | Function |
84| fileName |used for saving and retrieving local storage blob files | no | String |
85| title | defaults to empty string | no | String |
86| ref | if you want to have access to internal functions such as retrieving content from the editor. eg to save to a server/db.| no | React ref |
87
88
89See [`./demo/app.js` demo](./demo/app.js) as a more detailed example usage of the component.
90
91_Note: `fileName` it is optional but it's needed if working with user uploaded local media in the browser, to be able to save and retrieve from local storage. For instance if you are passing a blob url to `mediaUrl` using `createObjectURL` this url is randomly re-generated on every page refresh so you wouldn't be able to restore a session, as `mediaUrl` is used as the local storage key. See demo app for more detail example of this[`./src/index.js`](./src/index.js)_
92
93### Typescript projects
94
95If using in a parent project where [typescript](https://www.typescriptlang.org/) is being used you might need to add `//@ts-ignore` before the import statment like this
96
97```js
98//@ts-ignore
99import { TranscriptEditor } from "@bbc/react-transcript-editor";
100```
101
102#### Internal components
103
104You can also import some of the underlying React components directly.
105
106- `TranscriptEditor`
107- `TimedTextEditor`
108- `MediaPlayer`
109- `VideoPlayer`
110- `Settings`
111- `KeyboardShortcuts`
112
113- `ProgressBar`
114- `PlaybackRate`
115- `PlayerControls`
116- `RollBack`
117- `Select`
118
119To import the components you can do as follows
120
121```js
122import TimedTextEditor from '@bbc/react-transcript-editor/TimedTextEditor';
123```
124```js
125import { TimedTextEditor } from '@bbc/react-transcript-editor';
126```
127
128However if you are not using `TranscriptEditor` it is recommended to follow the second option and import individual components like: `@bbc/react-transcript-editor/TimedTextEditor` rather than the entire library. Doing so pulls in only the specific components that you use, which can significantly reduce the amount of code you end up sending to the client. (Similarly to how [`react-bootstrap`](https://react-bootstrap.github.io/getting-started/introduction) works)
129
130See [the storybook](https://bbc.github.io/react-transcript-editor) for each component details on optional and required attributes.
131
132You can also use this node modules as standalone
133
134```js
135import exportAdapter from '@bbc/react-transcript-editor/exportAdapter'
136```
137Converts from draftJs json format to other formats
138
139```js
140import sttJsonAdapter from '@bbc/react-transcript-editor/sttJsonAdapter'
141```
142Converts various stt json formats to draftJs
143
144```js
145import { secondsToTimecode, timecodeToSeconds, shortTimecode} from '@bbc/react-transcript-editor/timecodeConverter'
146```
147some modules to convert to and from timecodes
148
149## System Architecture
150
151<!-- _High level overview of system architecture_ -->
152- uses [`storybook`](https://storybook.js.org) with the setup as [explained in their docs](https://storybook.js.org/docs/guides/guide-react/) to develop this React.
153- This uses [CSS Modules](https://github.com/css-modules/css-modules) to contain the scope of the css for this component.
154- [`.storybook/webpack.config.js](./.storybook/webpack.config.js) enanches the storybook webpack config to add support for css modules.
155- The parts of the component are inside [`./packages`](./packages)
156- [babel.config.js](./babel.config.js) provides root level system config for [babel 7](https://babeljs.io/docs/en/next/config-files#project-wide-configuration).
157
158<!-- - for build, packaging, and deployment of the npm module, we use webpack with babel 7 -->
159
160## Documentation
161
162There's a [docs](./docs) folder in this repository.
163
164[docs/notes](./docs/notes) contains dev notes on various aspects of the project.
165
166[docs/adr](./docs/adr) contains [Architecture Decision Record](https://github.com/joelparkerhenderson/architecture_decision_record).
167
168> An architectural decision record (ADR) is a document that captures an important architectural decision made along with its context and consequences.
169
170We are using [this template for ADR](https://gist.github.com/iaincollins/92923cc2c309c2751aea6f1b34b31d95)
171
172[There also QA testing docs](./docs/qa/README.md) to manual test the component before a major release, (QA testing does not require any technical knowledge).
173
174## Build
175
176<!-- _How to run build_ -->
177
178> To transpile `./packages` and create a build in the `./dist` folder, run:
179
180```
181npm run build:component
182```
183
184## Demo & storybook
185
186- **Storybook** can bew viewed at [https://bbc.github.io/react-transcript-editor/](https://bbc.github.io/react-transcript-editor/)
187
188- **Demo** can be viewed at [https://bbc.github.io/react-transcript-editor/iframe.html?id=demo--default](https://bbc.github.io/react-transcript-editor/iframe.html?id=demo--default)
189
190
191http://localhost:6006
192
193
194<!-- https://github.com/gitname/react-gh-pages
195-->
196
197## Build - storybook
198To build the storybook as a static site
199
200```
201npm run build:storybook
202```
203
204## Publish storybook & demo to github pages
205
206This github repository uses [github pages](https://pages.github.com/) to host the storybook and the demo of the component
207
208```
209npm run deploy:ghpages
210```
211
212add to git, and push to origin master to update
213
214<!-- https://help.github.com/articles/user-organization-and-project-pages/#project-pages-sites -->
215
216Alternatively If you simply want to build the demo locally in the `build` folder then just
217
218```
219npm run build:storybook
220```
221
222you can then run this command to serve the static site locally
223
224```
225npm run build:storybook:serve
226```
227
228## Tests
229<!-- _How to carry out tests_ -->
230
231Test coverage using [`jest`](https://jestjs.io/), to run tests
232
233```
234npm run test
235```
236
237During development you can use
238
239```
240npm run test:watch
241```
242
243## Travis CI
244
245On commit this repo uses the [.travis.yml](./.travis.yml) config tu run the automated test on [travis CI](https://travis-ci.org/bbc/react-transcript-editor).
246
247## Deployment
248
249<!-- _How to deploy the code/app into test/staging/production_ -->
250
251To push to [npm - `@bbc/react-transcript-editor`](https://www.npmjs.com/package/@bbc/react-transcript-editor)
252
253```
254npm publish:public
255```
256
257This runs `npm run build:component` and `npm publish --access public` under the hood
258
259> Note that only `README.md` and the `dist` folders are published to npm.
260
261## Contributing
262
263See [CONTRIBUTING.md](./CONTRIBUTING.md) guidelines and [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) guidelines.
264
265## Licence
266<!-- mention MIT Licence -->
267See [LICENCE](./LICENCE.md)
268
269## Legal Disclaimer
270
271_Despite using React and DraftJs, the BBC is not promoting any Facebook products or other commercial interest._