Skip to content

Commit

Permalink
feat: prettier workflow for js files
Browse files Browse the repository at this point in the history
Signed-off-by: Royal Simpson Pinto <[email protected]>

feat: prettier workflow modification

Signed-off-by: Royal Simpson Pinto <[email protected]>
  • Loading branch information
royalpinto007 committed Aug 12, 2024
1 parent 2fc751c commit f5de03b
Show file tree
Hide file tree
Showing 7 changed files with 6,675 additions and 692 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Prettier Code Formatter

on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop

jobs:
prettier:
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install dependencies
run: npm install
- name: Run Prettier on JS files
run: npx prettier --write 'js/**/*.js'
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Plugin } from 'ckeditor5/src/core';
import createButtonView from './buttonView';
import { Plugin } from "ckeditor5/src/core";
import createButtonView from "./buttonView";

export default class TextToTextGeneration extends Plugin {
init() {
const editor = this.editor;
editor.ui.componentFactory.add('textToTextGeneration', locale => {
const view = createButtonView(locale, editor);
return view;
});
}
init() {
const editor = this.editor;
editor.ui.componentFactory.add("textToTextGeneration", (locale) => {
const view = createButtonView(locale, editor);
return view;
});
}
}
37 changes: 19 additions & 18 deletions js/ckeditor5_plugins/text2text_generation/src/api.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import axios from 'axios';
import axios from "axios";

export function generateText(inputText, editor) {
axios.post('/generate-text', JSON.stringify({ text: inputText }), {
headers: {
'Content-Type': 'application/json'
}
axios
.post("/generate-text", JSON.stringify({ text: inputText }), {
headers: {
"Content-Type": "application/json",
},
})
.then(response => {
console.log('Received response:', response.data);
const generatedText = response.data.generated_text;
const textarea = document.getElementById('inputText');
if (textarea) {
textarea.value = generatedText;
}
.then((response) => {
console.log("Received response:", response.data);
const generatedText = response.data.generated_text;
const textarea = document.getElementById("inputText");
if (textarea) {
textarea.value = generatedText;
}
})
.catch(error => {
console.error('Error generating text:', error.response.data);
const textarea = document.getElementById('inputText');
if (textarea) {
textarea.value = 'Error generating text, please try again.';
}
.catch((error) => {
console.error("Error generating text:", error.response.data);
const textarea = document.getElementById("inputText");
if (textarea) {
textarea.value = "Error generating text, please try again.";
}
});
}
145 changes: 75 additions & 70 deletions js/ckeditor5_plugins/text2text_generation/src/buttonView.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ButtonView } from 'ckeditor5/src/ui';
import { generateText } from './api';
import icon from '../../../../icons/text_generation.svg';
import { ButtonView } from "ckeditor5/src/ui";
import { generateText } from "./api";
import icon from "../../../../icons/text_generation.svg";

export default function createButtonView(locale, editor) {
const view = new ButtonView(locale);
const view = new ButtonView(locale);

const css = `
const css = `
.ck-button-generate-text {
background-color: #0074bd;
color: white;
Expand Down Expand Up @@ -56,85 +56,90 @@ export default function createButtonView(locale, editor) {
font-size: 16px;
}
`;
const styleSheet = document.createElement('style');
styleSheet.type = 'text/css';
styleSheet.innerText = css;
document.head.appendChild(styleSheet);

view.set({
label: 'Generate Text',
icon,
tooltip: true,
class: 'ck-button ck-button-generate-text'
});

view.on('execute', () => {
const dialogElement = document.createElement('div');
dialogElement.className = 'ck-text-generator-dialog';
dialogElement.innerHTML = `
const styleSheet = document.createElement("style");
styleSheet.type = "text/css";
styleSheet.innerText = css;
document.head.appendChild(styleSheet);

view.set({
label: "Generate Text",
icon,
tooltip: true,
class: "ck-button ck-button-generate-text",
});

view.on("execute", () => {
const dialogElement = document.createElement("div");
dialogElement.className = "ck-text-generator-dialog";
dialogElement.innerHTML = `
<button class="ck-close-button">✖</button>
<div class="ck-dialog-body">
<textarea id="inputText" class="ck-input-text" rows="4" cols="40"></textarea>
<button id="submitText" class="ck-submit-button">Generate</button>
</div>
`;

document.body.appendChild(dialogElement);
enableDrag(dialogElement);
document.body.appendChild(dialogElement);
enableDrag(dialogElement);

// Calculate and set initial position with slight space below the icon
const buttonRect = view.element.getBoundingClientRect();
dialogElement.style.position = 'absolute';
dialogElement.style.top = `${buttonRect.bottom + 5}px`; // position slightly below the button with 5px gap
dialogElement.style.left = `${buttonRect.left}px`; // align with the button
// Calculate and set initial position with slight space below the icon
const buttonRect = view.element.getBoundingClientRect();
dialogElement.style.position = "absolute";
dialogElement.style.top = `${buttonRect.bottom + 5}px`; // position slightly below the button with 5px gap
dialogElement.style.left = `${buttonRect.left}px`; // align with the button

document.getElementById('inputText').focus();
document.getElementById("inputText").focus();

document.getElementById('submitText').addEventListener('click', () => {
const inputText = document.getElementById('inputText').value;
generateText(inputText, editor).then(generatedText => {
document.getElementById('inputText').value = generatedText;
});
});
document.getElementById("submitText").addEventListener("click", () => {
const inputText = document.getElementById("inputText").value;
generateText(inputText, editor).then((generatedText) => {
document.getElementById("inputText").value = generatedText;
});
});

document.querySelector('.ck-close-button').addEventListener('click', () => {
dialogElement.remove();
});
document.querySelector(".ck-close-button").addEventListener("click", () => {
dialogElement.remove();
});
});

return view;
return view;
}

function enableDrag(element) {
let pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
if (document.querySelector(element.className + " .ck-close-button")) {
document.querySelector(element.className + " .ck-close-button").onmousedown = dragMouseDown;
} else {
element.onmousedown = dragMouseDown;
}

function dragMouseDown(e) {
e = e || window.event;
e.preventDefault();
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
document.onmousemove = elementDrag;
}

function elementDrag(e) {
e = e || window.event;
e.preventDefault();
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
element.style.top = (element.offsetTop - pos2) + "px";
element.style.left = (element.offsetLeft - pos1) + "px";
}

function closeDragElement() {
document.onmouseup = null;
document.onmousemove = null;
}
let pos1 = 0,
pos2 = 0,
pos3 = 0,
pos4 = 0;
if (document.querySelector(element.className + " .ck-close-button")) {
document.querySelector(
element.className + " .ck-close-button",
).onmousedown = dragMouseDown;
} else {
element.onmousedown = dragMouseDown;
}

function dragMouseDown(e) {
e = e || window.event;
e.preventDefault();
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
document.onmousemove = elementDrag;
}

function elementDrag(e) {
e = e || window.event;
e.preventDefault();
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
element.style.top = element.offsetTop - pos2 + "px";
element.style.left = element.offsetLeft - pos1 + "px";
}

function closeDragElement() {
document.onmouseup = null;
document.onmousemove = null;
}
}
Loading

0 comments on commit f5de03b

Please sign in to comment.