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

Updating from BBC repo #2

Merged
merged 28 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6cfca7b
Develop (#175)
Aug 13, 2019
69f6b21
fixed vulernerabilities
Aug 13, 2019
be685c9
1.0.5
Aug 13, 2019
e301db1
fixed vulnerabilities + added webpack-cli as dev dependency
Aug 13, 2019
5657ecc
Fix: fonts
jamesdools Aug 14, 2019
639bc29
Refactor: tidy transcript-editor, remove repeated videoRef checks
jamesdools Aug 14, 2019
2f14de0
Task: Add sass-loader to webpack, pull in colours via scss
jamesdools Aug 14, 2019
c1172a4
fix should component update (#186)
Aug 16, 2019
430af3c
1.0.6
Aug 16, 2019
8500b11
Fixes bug where editor grabs focus on text-realigment even if editor …
murezzda Aug 16, 2019
b0a3c15
1.0.7
Aug 16, 2019
45c324d
Task: hide empty sidebar in storybook for now
jamesdools Aug 19, 2019
b1c2d38
Fix: tidy demo styling
jamesdools Aug 19, 2019
c3448e3
Feature: CSS hovers for buttons, refactoring css
jamesdools Aug 19, 2019
3aa42d6
Refactor: function cleanup
jamesdools Aug 19, 2019
9866f23
Task: Remove unused components
jamesdools Aug 19, 2019
9557faa
Task: Move to scss, update and optimise webpack
jamesdools Aug 20, 2019
0713129
storybook, npm, webpack setup - draft (#184)
Aug 21, 2019
c6de274
Feature: progress shades red on ProgressBar component
jamesdools Aug 22, 2019
6d2970a
Feature: progress shades red on ProgressBar component
jamesdools Aug 22, 2019
c62f410
simplifying package command with /bin/cp -rf (#191)
emettely Sep 16, 2019
1ba95a0
Merge
jamesdools Sep 18, 2019
8723a0b
Fix: demo font fallback & breakpoint
jamesdools Sep 18, 2019
b6f29c3
Task: Adding react-fast-compare to optimise renders
jamesdools Sep 18, 2019
0e7a988
Fix: prop type for progress bar
jamesdools Sep 18, 2019
c06416a
Merge pull request #183 from bbc/refactor-media-player
jamesdools Sep 18, 2019
d199690
Speechmatics adapter update (#190)
murezzda Sep 24, 2019
51d486e
Fix: npm audit
jamesdools Sep 24, 2019
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
5 changes: 3 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
],
"env": {
"browser": true,
"jest": true
"jest": true,
"node": true,
},
"rules": {
"prefer-const": 1,
Expand Down Expand Up @@ -43,7 +44,7 @@
"no-param-reassign": [ 1 ],
"no-shadow": [ 1 ],
"camelcase": [ 1 ],
"no-underscore-dangle" : [0, "always"],
"no-underscore-dangle": [0, "always"],
"keyword-spacing": ["error", { "before": true, "after": true }],
"key-spacing": ["error", { "afterColon": true }],
"newline-before-return": "error",
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion .storybook/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ addDecorator(withA11y);

addParameters({
options: {
panelPosition: 'right',
// showPanel: false,
panelPosition: 'bottom',
sidebarAnimations: true
},
});
Expand Down
13 changes: 11 additions & 2 deletions .storybook/styles/main.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
body * {
body {
font-family: ReithSerif, Fallback, sans-serif;
// font-family: ReithSans, Helvetica, sans-serif !important;

}

p, span {
font-family: ReithSans, Helvetica, sans-serif;

}

h1, h2, h3, h4, h5, h6, label * {
font-family: ReithSerif;
}
30 changes: 11 additions & 19 deletions .storybook/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,28 @@ module.exports = {
module: {
rules: [
{
test: /\.module.css$/,
test: /\.module.(sa|sc|c)ss$/,
use: [
"style-loader",
{
loader: "style-loader"
loader: "css-loader",
options: { modules: true }
},
{
loader: "css-loader",
options: {
modules: true
}
loader: "sass-loader",
options: { sourcemap: true }
}
]
},
{
test: /\.scss$/,
test: /\.s(a|c)ss$/,
exclude: /\.module.(s(a|c)ss)$/,
use: [
{
loader: "style-loader"
},
{
loader: "css-loader",
options: {
sourceMap: true
}
},
"style-loader",
"css-loader",
{
loader: "sass-loader",
options: {
sourcemap: true
}
options: { sourcemap: true }
}
]
}
Expand Down
77 changes: 43 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ _--> Work in progress <--_

<!-- _Screenshot of UI - optional_ -->

- [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)
- [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)
- [And you can see a list of features here](./docs/features-list.md).

## Development env
Expand Down Expand Up @@ -56,35 +56,33 @@ npm install @bbc/react-transcript-editor
```

```js
import TranscriptEditor from '@bbc/react-transcript-editor';
import TranscriptEditor from "@bbc/react-transcript-editor";
```

```js
<TranscriptEditor
transcriptData={ someJsonFile }
mediaUrl={'https://download.ted.com/talks/KateDarling_2018S-950k.mp4'}
isEditable={true}
spellCheck={false}
sttJsonType={ 'bbckaldi' }
handleAnalyticsEvents={ this.handleAnalyticsEvents }
fileName={'ted-talk.mp4'}
title={'Ted Talk'}
ref={ this.transcriptEditorRef }
/>
<TranscriptEditor
transcriptData={someJsonFile}
mediaUrl={"https://download.ted.com/talks/KateDarling_2018S-950k.mp4"}
isEditable={true}
spellCheck={false}
sttJsonType={"bbckaldi"}
handleAnalyticsEvents={this.handleAnalyticsEvents}
fileName={"ted-talk.mp4"}
title={"Ted Talk"}
ref={this.transcriptEditorRef}
/>
```


| Attributes | Description | required | type |
| :------------- | :---------- | :-----------: | :-----------: |
| transcriptData | Transcript json | yes | Json |
| mediaUrl | string url to media file - audio or video | yes | String |
| isEditable | set to true if you want to be able to edit the text | no | Boolean |
|spellCheck | set to true if you want the browser to spell check this transcript | no | Boolean |
| handleAnalyticsEvents | if you want to collect analytics events. | no | Function |
| fileName |used for saving and retrieving local storage blob files | no | String |
| title | defaults to empty string | no | String |
| 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 |

| Attributes | Description | required | type |
| :-------------------- | :---------------------------------------------------------------------------------------------------------------------- | :------: | :-------: |
| transcriptData | Transcript json | yes | Json |
| mediaUrl | string url to media file - audio or video | yes | String |
| isEditable | set to true if you want to be able to edit the text | no | Boolean |
| spellCheck | set to true if you want the browser to spell check this transcript | no | Boolean |
| handleAnalyticsEvents | if you want to collect analytics events. | no | Function |
| fileName | used for saving and retrieving local storage blob files | no | String |
| title | defaults to empty string | no | String |
| 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 |

See [`./demo/app.js` demo](./demo/app.js) as a more detailed example usage of the component.

Expand Down Expand Up @@ -119,10 +117,11 @@ You can also import some of the underlying React components directly.
To import the components you can do as follows

```js
import TimedTextEditor from '@bbc/react-transcript-editor/TimedTextEditor';
import TimedTextEditor from "@bbc/react-transcript-editor/TimedTextEditor";
```

```js
import { TimedTextEditor } from '@bbc/react-transcript-editor';
import { TimedTextEditor } from "@bbc/react-transcript-editor";
```

However 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)
Expand All @@ -132,23 +131,31 @@ See [the storybook](https://bbc.github.io/react-transcript-editor) for each comp
You can also use this node modules as standalone

```js
import exportAdapter from '@bbc/react-transcript-editor/exportAdapter'
import exportAdapter from "@bbc/react-transcript-editor/exportAdapter";
```

Converts from draftJs json format to other formats

```js
import sttJsonAdapter from '@bbc/react-transcript-editor/sttJsonAdapter'
import sttJsonAdapter from "@bbc/react-transcript-editor/sttJsonAdapter";
```

Converts various stt json formats to draftJs

```js
import { secondsToTimecode, timecodeToSeconds, shortTimecode} from '@bbc/react-transcript-editor/timecodeConverter'
import {
secondsToTimecode,
timecodeToSeconds,
shortTimecode
} from "@bbc/react-transcript-editor/timecodeConverter";
```

some modules to convert to and from timecodes

## System Architecture

<!-- _High level overview of system architecture_ -->

- 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.
- This uses [CSS Modules](https://github.com/css-modules/css-modules) to contain the scope of the css for this component.
- [`.storybook/webpack.config.js](./.storybook/webpack.config.js) enanches the storybook webpack config to add support for css modules.
Expand Down Expand Up @@ -187,14 +194,13 @@ npm run build:component

- **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)


http://localhost:6006


<!-- https://github.com/gitname/react-gh-pages
-->

## Build - storybook

To build the storybook as a static site

```
Expand Down Expand Up @@ -226,17 +232,18 @@ npm run build:storybook:serve
```

## Tests

<!-- _How to carry out tests_ -->

Test coverage using [`jest`](https://jestjs.io/), to run tests

```
```sh
npm run test
```

During development you can use

```
```sh
npm run test:watch
```

Expand All @@ -263,7 +270,9 @@ This runs `npm run build:component` and `npm publish --access public` under the
See [CONTRIBUTING.md](./CONTRIBUTING.md) guidelines and [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) guidelines.

## Licence

<!-- mention MIT Licence -->

See [LICENCE](./LICENCE.md)

## Legal Disclaimer
Expand Down
40 changes: 22 additions & 18 deletions demo/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import ExportFormatSelect from './select-export-format';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faGithub } from '@fortawesome/free-brands-svg-icons';

import demoTranscript from './sample-data/KateDarling-bbcKaldiTranscriptWithSpeakerSegments.json';
const demoMediaUrl = 'https://download.ted.com/talks/KateDarling_2018S-950k.mp4';
const demoTitle = 'Ted Talk - Kate Darling';
import DEMO_TRANSCRIPT from './sample-data/KateDarling-bbcKaldiTranscriptWithSpeakerSegments.json';
const DEMO_MEDIA_URL = 'https://download.ted.com/talks/KateDarling_2018S-950k.mp4';
const DEMO_TITLE = 'TED Talk | Kate Darling - Why we have an emotional connection to robots';

import style from './index.module.css';
import style from './index.module.scss';

class App extends React.Component {
constructor(props) {
Expand All @@ -32,9 +32,9 @@ class App extends React.Component {

loadDemo = () => {
this.setState({
transcriptData: demoTranscript,
mediaUrl: demoMediaUrl,
title: demoTitle,
transcriptData: DEMO_TRANSCRIPT,
mediaUrl: DEMO_MEDIA_URL,
title: DEMO_TITLE,
sttType: 'bbckaldi'
});
}
Expand All @@ -48,7 +48,7 @@ class App extends React.Component {
if (canPlay) {
const fileURL = URL.createObjectURL(file);
this.setState({
// transcriptData: demoTranscript,
// transcriptData: DEMO_TRANSCRIPT,
mediaUrl: fileURL,
fileName: file.name
});
Expand All @@ -61,7 +61,7 @@ class App extends React.Component {
const fileURL = prompt("Paste the URL you'd like to use here:");

this.setState({
// transcriptData: demoTranscript,
// transcriptData: DEMO_TRANSCRIPT,
mediaUrl: fileURL
});
}
Expand Down Expand Up @@ -116,7 +116,9 @@ class App extends React.Component {
if (ext === 'json') {
tmpData = JSON.stringify(data, null, 2);
}
this.download(tmpData, `${ this.state.mediaUrl }.${ ext }`);
if (ext !== 'docx') {
this.download(tmpData, `${ this.state.mediaUrl }.${ ext }`);
}
};

// https://stackoverflow.com/questions/2897619/using-html5-javascript-to-generate-and-save-a-file
Expand Down Expand Up @@ -172,19 +174,19 @@ class App extends React.Component {
</section>

<section className={ style.demoNavItem }>
<label className={ style.sectionLabel }>Custom Media</label>
<button onClick={ () => this.handleLoadMediaUrl() }>Load from URL</button>
<label className={ style.sectionLabel }>Load Media</label>
<button onClick={ () => this.handleLoadMediaUrl() }> From URL</button>
<input
type={ 'file' }
id={ 'mediaFile' }
onChange={ e => this.handleLoadMedia(e.target.files) }
/>
<label htmlFor="mediaFile" >Load local media</label>
<label htmlFor="mediaFile" >From Computer</label>
{this.state.fileName !== '' ? <label className={ style.fileNameLabel }>{this.state.fileName}</label> : null}
</section>

<section className={ style.demoNavItem }>
<label className={ style.sectionLabel }>Import Transcript</label>
<label className={ style.sectionLabel }>Load Transcript</label>
<SttTypeSelect
className={ style.dropdown }
name={ 'sttType' }
Expand All @@ -197,7 +199,7 @@ class App extends React.Component {
id={ 'transcriptFile' }
onChange={ e => this.handleLoadTranscriptJson(e.target.files) }
/>
<label htmlFor="transcriptFile" >Load Transcript</label>
<label htmlFor="transcriptFile" >From Computer</label>
{this.state.transcriptData !== null ? <label className={ style.fileNameLabel }>Transcript loaded.</label> : null}

</section>
Expand Down Expand Up @@ -248,7 +250,11 @@ class App extends React.Component {
/>
</div>

<button className={ style.warningButton } onClick={ () => this.clearLocalStorage() }>Clear Local Storage</button>
<button
className={ style.warningButton }
onClick={ () => this.clearLocalStorage() }>
Clear Local Storage
</button>
</section>
</div>

Expand All @@ -275,6 +281,4 @@ class App extends React.Component {
}
}

// render(<App />, document.getElementById('root'));

export default App;
Loading