Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
},
"dependencies": {
"@codemirror/basic-setup": "^0.19.1",
"@codemirror/commands": "^0.19.8",
"@codemirror/lang-java": "^0.19.1",
"@codemirror/lang-json": "^0.19.2",
"@codemirror/theme-one-dark": "^0.19.1",
"@codemirror/view": "^0.19.42",
"@stencil/core": "^2.13.0",
"axios": "^0.26.0"
"axios": "^0.26.0",
"sweetalert2": "^11.4.6"
},
"devDependencies": {
"@types/jest": "^27.0.3",
Expand Down
92 changes: 64 additions & 28 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export namespace Components {
"name": string;
}
interface CodeEditor {
"isEditable": 'true' | 'false';
"language": 'java' | 'json';
"doc": any;
"url": string;
}
interface CustomTable {
"clearSearch": any;
Expand All @@ -29,6 +29,11 @@ export namespace Components {
"tableHeader": object[];
"toggleSortMethod": any;
}
interface DataTable {
"doc": any;
}
interface DialogComponent {
}
interface DropDown {
"alias": string;
"clearSearch": any;
Expand Down Expand Up @@ -68,24 +73,28 @@ export namespace Components {
"align": 'vertical' | 'horizontal';
"name": string;
}
interface SignIn {
interface ResEditor {
"doc": any;
"responseLabel": 'result' | 'error';
}
interface TabComponent {
"doc": any;
"responseLabel": any;
}
interface TableWrapper {
"api": any;
"autocompute": boolean;
"headerList": object[];
"rowPerPage": number[];
}
interface TestCom {
}
interface TextField {
"addClass": string;
"eye": boolean;
"name": string;
"onChange": any;
"onClick": any;
"placeholder": string;
"type": 'email' | 'password' | 'text' | 'search';
"width": 'full' | 'auto';
}
interface TextFieldArea {
"addClass": string;
Expand All @@ -111,6 +120,18 @@ declare global {
prototype: HTMLCustomTableElement;
new (): HTMLCustomTableElement;
};
interface HTMLDataTableElement extends Components.DataTable, HTMLStencilElement {
}
var HTMLDataTableElement: {
prototype: HTMLDataTableElement;
new (): HTMLDataTableElement;
};
interface HTMLDialogComponentElement extends Components.DialogComponent, HTMLStencilElement {
}
var HTMLDialogComponentElement: {
prototype: HTMLDialogComponentElement;
new (): HTMLDialogComponentElement;
};
interface HTMLDropDownElement extends Components.DropDown, HTMLStencilElement {
}
var HTMLDropDownElement: {
Expand Down Expand Up @@ -171,24 +192,24 @@ declare global {
prototype: HTMLRadioButtonElement;
new (): HTMLRadioButtonElement;
};
interface HTMLSignInElement extends Components.SignIn, HTMLStencilElement {
interface HTMLResEditorElement extends Components.ResEditor, HTMLStencilElement {
}
var HTMLSignInElement: {
prototype: HTMLSignInElement;
new (): HTMLSignInElement;
var HTMLResEditorElement: {
prototype: HTMLResEditorElement;
new (): HTMLResEditorElement;
};
interface HTMLTabComponentElement extends Components.TabComponent, HTMLStencilElement {
}
var HTMLTabComponentElement: {
prototype: HTMLTabComponentElement;
new (): HTMLTabComponentElement;
};
interface HTMLTableWrapperElement extends Components.TableWrapper, HTMLStencilElement {
}
var HTMLTableWrapperElement: {
prototype: HTMLTableWrapperElement;
new (): HTMLTableWrapperElement;
};
interface HTMLTestComElement extends Components.TestCom, HTMLStencilElement {
}
var HTMLTestComElement: {
prototype: HTMLTestComElement;
new (): HTMLTestComElement;
};
interface HTMLTextFieldElement extends Components.TextField, HTMLStencilElement {
}
var HTMLTextFieldElement: {
Expand All @@ -205,6 +226,8 @@ declare global {
"check-box": HTMLCheckBoxElement;
"code-editor": HTMLCodeEditorElement;
"custom-table": HTMLCustomTableElement;
"data-table": HTMLDataTableElement;
"dialog-component": HTMLDialogComponentElement;
"drop-down": HTMLDropDownElement;
"fluid-container": HTMLFluidContainerElement;
"icon-button": HTMLIconButtonElement;
Expand All @@ -215,9 +238,9 @@ declare global {
"nav-bar": HTMLNavBarElement;
"plain-button": HTMLPlainButtonElement;
"radio-button": HTMLRadioButtonElement;
"sign-in": HTMLSignInElement;
"res-editor": HTMLResEditorElement;
"tab-component": HTMLTabComponentElement;
"table-wrapper": HTMLTableWrapperElement;
"test-com": HTMLTestComElement;
"text-field": HTMLTextFieldElement;
"text-field-area": HTMLTextFieldAreaElement;
}
Expand All @@ -227,8 +250,8 @@ declare namespace LocalJSX {
"name"?: string;
}
interface CodeEditor {
"isEditable"?: 'true' | 'false';
"language"?: 'java' | 'json';
"doc"?: any;
"url"?: string;
}
interface CustomTable {
"clearSearch"?: any;
Expand All @@ -246,6 +269,11 @@ declare namespace LocalJSX {
"tableHeader"?: object[];
"toggleSortMethod"?: any;
}
interface DataTable {
"doc"?: any;
}
interface DialogComponent {
}
interface DropDown {
"alias"?: string;
"clearSearch"?: any;
Expand Down Expand Up @@ -285,24 +313,28 @@ declare namespace LocalJSX {
"align"?: 'vertical' | 'horizontal';
"name"?: string;
}
interface SignIn {
interface ResEditor {
"doc"?: any;
"responseLabel"?: 'result' | 'error';
}
interface TabComponent {
"doc"?: any;
"responseLabel"?: any;
}
interface TableWrapper {
"api"?: any;
"autocompute"?: boolean;
"headerList"?: object[];
"rowPerPage"?: number[];
}
interface TestCom {
}
interface TextField {
"addClass"?: string;
"eye"?: boolean;
"name"?: string;
"onChange"?: any;
"onClick"?: any;
"placeholder"?: string;
"type"?: 'email' | 'password' | 'text' | 'search';
"width"?: 'full' | 'auto';
}
interface TextFieldArea {
"addClass"?: string;
Expand All @@ -312,6 +344,8 @@ declare namespace LocalJSX {
"check-box": CheckBox;
"code-editor": CodeEditor;
"custom-table": CustomTable;
"data-table": DataTable;
"dialog-component": DialogComponent;
"drop-down": DropDown;
"fluid-container": FluidContainer;
"icon-button": IconButton;
Expand All @@ -322,9 +356,9 @@ declare namespace LocalJSX {
"nav-bar": NavBar;
"plain-button": PlainButton;
"radio-button": RadioButton;
"sign-in": SignIn;
"res-editor": ResEditor;
"tab-component": TabComponent;
"table-wrapper": TableWrapper;
"test-com": TestCom;
"text-field": TextField;
"text-field-area": TextFieldArea;
}
Expand All @@ -336,6 +370,8 @@ declare module "@stencil/core" {
"check-box": LocalJSX.CheckBox & JSXBase.HTMLAttributes<HTMLCheckBoxElement>;
"code-editor": LocalJSX.CodeEditor & JSXBase.HTMLAttributes<HTMLCodeEditorElement>;
"custom-table": LocalJSX.CustomTable & JSXBase.HTMLAttributes<HTMLCustomTableElement>;
"data-table": LocalJSX.DataTable & JSXBase.HTMLAttributes<HTMLDataTableElement>;
"dialog-component": LocalJSX.DialogComponent & JSXBase.HTMLAttributes<HTMLDialogComponentElement>;
"drop-down": LocalJSX.DropDown & JSXBase.HTMLAttributes<HTMLDropDownElement>;
"fluid-container": LocalJSX.FluidContainer & JSXBase.HTMLAttributes<HTMLFluidContainerElement>;
"icon-button": LocalJSX.IconButton & JSXBase.HTMLAttributes<HTMLIconButtonElement>;
Expand All @@ -346,9 +382,9 @@ declare module "@stencil/core" {
"nav-bar": LocalJSX.NavBar & JSXBase.HTMLAttributes<HTMLNavBarElement>;
"plain-button": LocalJSX.PlainButton & JSXBase.HTMLAttributes<HTMLPlainButtonElement>;
"radio-button": LocalJSX.RadioButton & JSXBase.HTMLAttributes<HTMLRadioButtonElement>;
"sign-in": LocalJSX.SignIn & JSXBase.HTMLAttributes<HTMLSignInElement>;
"res-editor": LocalJSX.ResEditor & JSXBase.HTMLAttributes<HTMLResEditorElement>;
"tab-component": LocalJSX.TabComponent & JSXBase.HTMLAttributes<HTMLTabComponentElement>;
"table-wrapper": LocalJSX.TableWrapper & JSXBase.HTMLAttributes<HTMLTableWrapperElement>;
"test-com": LocalJSX.TestCom & JSXBase.HTMLAttributes<HTMLTestComElement>;
"text-field": LocalJSX.TextField & JSXBase.HTMLAttributes<HTMLTextFieldElement>;
"text-field-area": LocalJSX.TextFieldArea & JSXBase.HTMLAttributes<HTMLTextFieldAreaElement>;
}
Expand Down
95 changes: 77 additions & 18 deletions src/components/code-editor/code-editor.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,99 @@
import { Component, h, Element, State, Prop } from '@stencil/core';
import { Component, h, Element, State, Prop, Host } from '@stencil/core';
import { EditorState, basicSetup } from '@codemirror/basic-setup';
import { EditorView } from '@codemirror/view';
import { EditorView, keymap } from '@codemirror/view';
// import { defaultKeymap } from '@codemirror/commands';
import { java } from '@codemirror/lang-java';
import { json } from '@codemirror/lang-json';
// import { oneDarkTheme } from '@codemirror/theme-one-dark';

import axios from 'axios';
@Component({
tag: 'code-editor',
scoped: true,
})
export class CodeEditor {
@Prop() isEditable: 'true' | 'false' = 'true';
@Prop() language: 'java' | 'json' = 'java';
@Element() element: HTMLElement;
@Prop() url: string;
@Prop() doc: any = '\n\n\n';
@State() response: any;
@State() responseLabel: any;
@State() view: EditorView;
@State() state: EditorState;
@State() isLoading = false;
@Element() element: HTMLElement;

componentWillLoad() {
componentDidLoad() {
this.state = EditorState.create({
doc: 'console.log("hi")\n\n\n\n',
extensions: [basicSetup, EditorView.editable.of(this.parseToBoolean(this.isEditable)), this.language === 'java' ? java() : json()],
doc: this.doc,
extensions: [
basicSetup,
java(),
// keymap.of(defaultKeymap),
this.dummyKeymap(),
],
});

this.view = new EditorView({ state: this.state, parent: this.element });
this.view = new EditorView({
state: this.state,
parent: this.element.querySelector('#editor'),
});
}

disconnectedCallback() {
this.view.destroy();
clickHandler() {
this.isLoading = true;
let transaction = this.view.state.update();
const query = transaction.state.doc.toString().trim();
this.view.dispatch(transaction);

//axios call
axios
.post(this.url, {
query,
apiKey: 'VD695S0-471MNBN-Q253RNQ-TZ2G9PT',
})
.then((res: any) => {
this.response = Object.values(res.data)[0];
this.responseLabel = Object.keys(res.data)[0];
this.isLoading = false;
})
.catch(err => console.log(err));
}

parseToBoolean(str) {
if (str === 'true') return true;
return false;
dummyKeymap() {
let self = this;
return keymap.of([
{
key: 'Ctrl-Shift-Enter',
run() {
self.clickHandler();
return true;
},
},
]);
}

render() {
return <div></div>;
return (
<Host>
<div class="border border-gray-300 shadow-gray-300 p-3 space-y-2">
<div id="editor" class="border border-gray-300"></div>
<button
title="Ctrl+Shift+Enter to run"
onClick={() => this.clickHandler()}
class="flex text-sm gap-2 items-center justify-center text-gray-600 border border-gray-300 px-3 py-2 hover:bg-gray-200 hover:text-gray-800"
>
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM9.555 7.168A1 1 0 008 8v4a1 1 0 001.555.832l3-2a1 1 0 000-1.664l-3-2z" clip-rule="evenodd" />
</svg>
Run
</button>
</div>

{this.isLoading && (
<div>
<p class="text-gray-400 pt-8 pb-12">Output :</p>
<loader-component></loader-component>
</div>
)}
{this.response && !this.isLoading && <tab-component responseLabel={this.responseLabel} doc={this.response}></tab-component>}
{/* {this.response && !this.isLoading && <res-editor responseLabel={this.responseLabel} doc={JSON.stringify(this.response, null, 2)}></res-editor>} */}
</Host>
);
}
}
Loading