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
48 changes: 47 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Contributing to RoValra

# PRs are very likely not gonna get merged or reviewed until Roblox is fully done migrating their site to next.js.
Expand All @@ -17,7 +17,15 @@
Don't rush me and don't expect it to get accepted instantly.\
If the PR has remained stale with no review for a few weeks then feel free to ask about it.

Every PR needs a clear description of what it does. Depending on the type of PR, please also include the following:
When opening a PR, please:

* Include a clear description of what it does
* Make sure it builds
* Make sure it works properly, without significant issues
* If Artificial Intelligence was utilised in the generation or authoring of the PR, please very clearly disclose/specify what AI did, what it was used for, and whether you tested its code
* If Artificial Intelligence was utilised in the generation or authoring of the PR, please manually review and test all code generated by the AI before opening the PR

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combine with 23

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lines start exactly the same, why not combine them?


Depending on the type of PR, please also include the following:

### New features

Expand All @@ -38,6 +46,44 @@

PRs without screenshots for new features, or without a proper description for bug fixes, may take longer to review or be closed.

## Making UI with TSX

If you need to make UI, you can use JSX/TSX in the extension via PReact (not to be confused with React). Keep in mind that you do **not** need the `.jsx`/`.tsx` file extension.

The PReact API is very similar to the React API. The documentation can be found here: <https://preactjs.com/>.

### Creating an element

You can create an element in two ways.

The first way automatically gives it a parent:

```js
import { renderElement } from './core/ui/react.ts';
const renderedElement = renderElement(element, parent);
```

The second way lets you create an HTMLElement without adding it to the webpage:

```js
import { renderElement } from './core/ui/react.ts';
const renderedElement = renderElement(element);
```

Of course, standard `render()` is still available, and is used by `renderElement()`.

You can define HTML elements like this:

```js
<div
className="rovalra-overlay-content"
role="dialog"
/>
```

> [!NOTE]
> Use `className` instead of `class`, and dont forget to call `renderElement(el)` before adding it to the webpage, or just call `renderElement(el, parent)` or `render(el, parent)`!

## Adding Translations

RoValra uses [i18next](https://www.i18next.com/) for translations. All translations are community made.
Expand Down
10 changes: 10 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
let sass = null;
try {
sass = require('sass');
} catch (e) {

Check warning on line 8 in build.js

View workflow job for this annotation

GitHub Actions / eslint

'e' is defined but never used
console.warn('Sass not found, skipping SCSS compilation.');
}
const dracoPath = path.join(
Expand Down Expand Up @@ -54,6 +54,7 @@
);
process.exit(1);
}

//E why the hell did i make this comment?
const bannerText = `/*!
* ${pkg.name} v${pkg.version}
Expand All @@ -79,6 +80,13 @@
js: bannerText,
css: bannerText,
},

loader: {
'.js': 'jsx'
},

jsx: 'automatic',
jsxImportSource: 'preact',
};

function compileScssFile(inputFile, outputFile) {
Expand All @@ -102,6 +110,7 @@
entryPoints: [backgroundEntryPath],
outfile: 'dist/background.js',
bundle: true,
inject: ['./src/shared/preact-inject.js'],
})
.catch(() => process.exit(1));

Expand Down Expand Up @@ -192,6 +201,7 @@
banner: {
js: bannerText + '\n' + dracoSource,
},
inject: ['./src/shared/preact-inject.js'],
})
.catch(() => process.exit(1));
if (fs.existsSync(cssDir)) {
Expand Down
37 changes: 37 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"lint:firefox": "web-ext lint --source-dir dist-firefox",
"package:firefox": "web-ext build --source-dir dist-firefox --artifacts-dir build --overwrite-dest",
"start:firefox": "web-ext run --source-dir dist-firefox --start-url https://www.roblox.com",
"lint": "eslint ."
"lint": "eslint .",
"types": "tsc --noEmit"
},
"devDependencies": {
"@types/chrome": "^0.3.6",
Expand All @@ -34,7 +35,8 @@
"fzstd": "^0.1.1",
"i18next": "26.5.5",
"marked": "^18.1.1",
"roavatar-renderer": "^1.10.3",
"preact": "^11.2.0",
"roavatar-renderer": "^1.10.3",
"roblox-bat": "0.6.5"
},
"overrides": {
Expand Down
3 changes: 3 additions & 0 deletions public/Assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,9 @@
"madeFr": "Helped make the French locale",
"madeZh": "Helped make the Chinese locale",
"madeVi": "Helped make the Vietnamese locale"
},
"ui": {
"addedPreact": "Added Preact support for easier UI creation"
}
},
"ui": {
Expand Down
6 changes: 6 additions & 0 deletions src/content/core/configs/otherContributions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class Contribution {
userId: string;
contributionDescription: string;
Expand Down Expand Up @@ -83,6 +83,12 @@
new Contribution(650766686, "displayAppThemeUserProfile.addedToWebsite", "https://github.com/NotValra/RoValra-Website/pull/7"), // @auggeeo
]
},
UI: {
label: "User Interfaces",
contributors: [
new Contribution(1564574922, "ui.addedPreact", "https://github.com/NotValra/RoValra/pull/419"), // @BossBoss2021
]
},
Locales: {
label: "RoValra Languages",
contributors: [
Expand Down
11 changes: 8 additions & 3 deletions src/content/core/ui/overlay.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Creates roblox overlay
import { render } from 'preact';
import { createCloseButton } from './closeButton.js';
import { createAssetIcon } from './general/toast.js';
import DOMPurify from 'dompurify';
import { renderElement } from './react.js';

export function createOverlay({
title,
Expand All @@ -18,13 +20,16 @@ export function createOverlay({
const overlay = document.createElement('div');
overlay.className = 'rovalra-global-overlay';

const content = document.createElement('div');
content.className = 'rovalra-overlay-content';
content.setAttribute('role', 'dialog');
const content = renderElement(<div
className="rovalra-overlay-content"
role="dialog"
/>);

content.style.maxWidth = maxWidth;
content.style.maxHeight = maxHeight;
content.style.display = 'flex';
content.style.flexDirection = 'column';

if (overflowVisible) {
content.style.overflow = 'visible';
} else {
Expand Down
20 changes: 20 additions & 0 deletions src/content/core/ui/react.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { render, ComponentChild, ContainerNode, createRef, isValidElement, cloneElement } from "preact";

export function renderElement(element: ComponentChild, parent?: ContainerNode): HTMLElement {
if (!isValidElement(element)) {
throw new Error();
}

const ref = createRef<HTMLElement>();
const container = document.createElement('div');

render(cloneElement(element, { ref: ref }), container);

if (!ref.current)
throw new Error("Failed to create PReact element.");

if (parent)
parent.appendChild(ref.current!);

return ref.current;
}
2 changes: 2 additions & 0 deletions src/shared/preact-inject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { render } from 'preact';
export { useState, useEffect, useRef, useMemo } from 'preact/hooks';
17 changes: 17 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact",

"allowJs": true,
"checkJs": false,

"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"lib": ["DOM", "DOM.Iterable", "ES2022"],
"esModuleInterop": true,
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
Loading