2021-01-28 23:25:10 +01:00
|
|
|
/*
|
|
|
|
|
Copyright (c) Microsoft Corporation.
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import './recorder.css';
|
|
|
|
|
import * as React from 'react';
|
|
|
|
|
import { Toolbar } from '../components/toolbar';
|
|
|
|
|
import { ToolbarButton } from '../components/toolbarButton';
|
|
|
|
|
import { Source } from '../components/source';
|
|
|
|
|
|
2021-02-01 01:37:13 +01:00
|
|
|
declare global {
|
|
|
|
|
interface Window {
|
2021-02-04 01:01:51 +01:00
|
|
|
_playwrightClear(): Promise<void>
|
|
|
|
|
_playwrightSetSource: (params: { text: string, language: string }) => void
|
2021-02-01 01:37:13 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-28 23:25:10 +01:00
|
|
|
export interface RecorderProps {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const Recorder: React.FC<RecorderProps> = ({
|
|
|
|
|
}) => {
|
2021-02-01 01:37:13 +01:00
|
|
|
const [source, setSource] = React.useState({ language: 'javascript', text: '' });
|
2021-02-04 01:01:51 +01:00
|
|
|
window._playwrightSetSource = setSource;
|
2021-02-01 01:37:13 +01:00
|
|
|
|
2021-01-28 23:25:10 +01:00
|
|
|
return <div className="recorder">
|
|
|
|
|
<Toolbar>
|
2021-02-01 01:37:13 +01:00
|
|
|
<ToolbarButton icon="clone" title="Copy" onClick={() => {
|
|
|
|
|
copy(source.text);
|
|
|
|
|
}}></ToolbarButton>
|
|
|
|
|
<ToolbarButton icon="trashcan" title="Clear" onClick={() => {
|
2021-02-04 01:01:51 +01:00
|
|
|
window._playwrightClear().catch(e => console.error(e));
|
2021-02-01 01:37:13 +01:00
|
|
|
}}></ToolbarButton>
|
2021-01-28 23:25:10 +01:00
|
|
|
<div style={{flex: "auto"}}></div>
|
|
|
|
|
</Toolbar>
|
2021-02-01 01:37:13 +01:00
|
|
|
<Source text={source.text} language={source.language}></Source>
|
2021-01-28 23:25:10 +01:00
|
|
|
</div>;
|
|
|
|
|
};
|
2021-02-01 01:37:13 +01:00
|
|
|
|
|
|
|
|
function copy(text: string) {
|
|
|
|
|
const textArea = document.createElement('textarea');
|
|
|
|
|
textArea.style.position = 'absolute';
|
|
|
|
|
textArea.style.zIndex = '-1000';
|
|
|
|
|
textArea.value = text;
|
|
|
|
|
document.body.appendChild(textArea);
|
|
|
|
|
textArea.select();
|
|
|
|
|
document.execCommand('copy');
|
|
|
|
|
textArea.remove();
|
|
|
|
|
}
|