UNPKG

10.7 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
62Minimal data needed for initialization
63
64```js
65<TranscriptEditor
66 transcriptData={someJsonFile}
67 mediaUrl={"https://download.ted.com/talks/KateDarling_2018S-950k.mp4"}
68/>
69```
70
71With more attributes
72```js
73<TranscriptEditor
74 transcriptData={someJsonFile}
75 mediaUrl={"https://download.ted.com/talks/KateDarling_2018S-950k.mp4"}
76 handleAutoSaveChanges={this.handleAutoSaveChanges}
77 autoSaveContentType={'digitalpaperedit'}
78 isEditable={true}
79 spellCheck={false}
80 sttJsonType={"bbckaldi"}
81 handleAnalyticsEvents={this.handleAnalyticsEvents}
82 fileName={"ted-talk.mp4"}
83 title={"Ted Talk"}
84 ref={this.transcriptEditorRef}
85
86/>
87```
88
89| Attributes | Description | required | type |
90| :-------------------- | :---------------------------------------------------------------------------------------------------------------------- | :------: | :-------: |
91| transcriptData | Transcript json | yes | Json |
92| mediaUrl | string url to media file - audio or video | yes | String |
93|`handleAutoSaveChanges`| returns content of transcription after a change | no | Function |
94| autoSaveContentType | specify the file format for data returned by `handleAutoSaveChanges`,falls back on `sttJsonType`. or `draftjs` | no | string |
95| isEditable | set to true if you want to be able to edit the text | no | Boolean |
96| spellCheck | set to true if you want the browser to spell check this transcript | no | Boolean |
97|`handleAnalyticsEvents`| if you want to collect analytics events. | no | Function |
98| fileName | used for saving and retrieving local storage blob files | no | String |
99| title | defaults to empty string | no | String |
100| 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 |
101
102See [`./demo/app.js` demo](./demo/app.js) as a more detailed example usage of the component.
103
104_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)_
105
106### Typescript projects
107
108If 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
109
110```js
111//@ts-ignore
112import { TranscriptEditor } from "@bbc/react-transcript-editor";
113```
114
115#### Internal components
116
117You can also import some of the underlying React components directly.
118
119- `TranscriptEditor`
120- `TimedTextEditor`
121- `MediaPlayer`
122- `VideoPlayer`
123- `Settings`
124- `KeyboardShortcuts`
125
126- `ProgressBar`
127- `PlaybackRate`
128- `PlayerControls`
129- `RollBack`
130- `Select`
131
132To import the components you can do as follows
133
134```js
135import TimedTextEditor from "@bbc/react-transcript-editor/TimedTextEditor";
136```
137
138```js
139import { TimedTextEditor } from "@bbc/react-transcript-editor";
140```
141
142However 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)
143
144See [the storybook](https://bbc.github.io/react-transcript-editor) for each component details on optional and required attributes.
145
146You can also use this node modules as standalone
147
148```js
149import exportAdapter from "@bbc/react-transcript-editor/exportAdapter";
150```
151
152Converts from draftJs json format to other formats
153
154```js
155import sttJsonAdapter from "@bbc/react-transcript-editor/sttJsonAdapter";
156```
157
158Converts various stt json formats to draftJs
159
160```js
161import {
162 secondsToTimecode,
163 timecodeToSeconds,
164 shortTimecode
165} from "@bbc/react-transcript-editor/timecodeConverter";
166```
167
168some modules to convert to and from timecodes
169
170## System Architecture
171
172<!-- _High level overview of system architecture_ -->
173
174- 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.
175- This uses [CSS Modules](https://github.com/css-modules/css-modules) to contain the scope of the css for this component.
176- [`.storybook/webpack.config.js](./.storybook/webpack.config.js) enanches the storybook webpack config to add support for css modules.
177- The parts of the component are inside [`./packages`](./packages)
178- [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).
179
180<!-- - for build, packaging, and deployment of the npm module, we use webpack with babel 7 -->
181
182## Documentation
183
184There's a [docs](./docs) folder in this repository.
185
186[docs/notes](./docs/notes) contains dev notes on various aspects of the project.
187
188[docs/adr](./docs/adr) contains [Architecture Decision Record](https://github.com/joelparkerhenderson/architecture_decision_record).
189
190> An architectural decision record (ADR) is a document that captures an important architectural decision made along with its context and consequences.
191
192We are using [this template for ADR](https://gist.github.com/iaincollins/92923cc2c309c2751aea6f1b34b31d95)
193
194[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).
195
196## Build
197
198<!-- _How to run build_ -->
199
200> To transpile `./packages` and create a build in the `./dist` folder, run:
201
202```
203npm run build:component
204```
205
206## Demo & storybook
207
208- **Storybook** can bew viewed at [https://bbc.github.io/react-transcript-editor/](https://bbc.github.io/react-transcript-editor/)
209
210- **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)
211
212http://localhost:6006
213
214<!-- https://github.com/gitname/react-gh-pages
215-->
216
217## Build - storybook
218
219To build the storybook as a static site
220
221```
222npm run build:storybook
223```
224
225## Publish storybook & demo to github pages
226
227This github repository uses [github pages](https://pages.github.com/) to host the storybook and the demo of the component
228
229```
230npm run deploy:ghpages
231```
232
233add to git, and push to origin master to update
234
235<!-- https://help.github.com/articles/user-organization-and-project-pages/#project-pages-sites -->
236
237Alternatively If you simply want to build the demo locally in the `build` folder then just
238
239```
240npm run build:storybook
241```
242
243you can then run this command to serve the static site locally
244
245```
246npm run build:storybook:serve
247```
248
249## Tests
250
251<!-- _How to carry out tests_ -->
252
253Test coverage using [`jest`](https://jestjs.io/), to run tests
254
255```sh
256npm run test
257```
258
259During development you can use
260
261```sh
262npm run test:watch
263```
264
265## Travis CI
266
267On 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).
268
269## Deployment
270
271<!-- _How to deploy the code/app into test/staging/production_ -->
272
273To push to [npm - `@bbc/react-transcript-editor`](https://www.npmjs.com/package/@bbc/react-transcript-editor)
274
275```
276npm publish:public
277```
278
279This runs `npm run build:component` and `npm publish --access public` under the hood
280
281> Note that only `README.md` and the `dist` folders are published to npm.
282
283## Contributing
284
285See [CONTRIBUTING.md](./CONTRIBUTING.md) guidelines and [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) guidelines.
286
287## Licence
288
289<!-- mention MIT Licence -->
290
291See [LICENCE](./LICENCE.md)
292
293## Legal Disclaimer
294
295_Despite using React and DraftJs, the BBC is not promoting any Facebook products or other commercial interest._