Skip to content

Commit

Permalink
Buncha stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
volstas committed Oct 16, 2024
1 parent 8e426e8 commit 454b48e
Show file tree
Hide file tree
Showing 12 changed files with 317 additions and 266 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ package-lock.json
/dist
/node_modules
/tmp
.yarn
147 changes: 76 additions & 71 deletions assets/index.html
Original file line number Diff line number Diff line change
@@ -1,82 +1,87 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Trix</title>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="csp-nonce" content="topsecret">
<link rel="icon" href="data:,">
<link rel="stylesheet" type="text/css" href="trix.css">
<style type="text/css">
* {
box-sizing: border-box;
}

main {
margin: 20px auto;
max-width: 700px;
}
<head>
<meta charset="UTF-8">
<title>Trix</title>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="csp-nonce" content="topsecret">
<link rel="icon" href="data:,">
<link rel="stylesheet" type="text/css" href="trix.css">
<style type="text/css">
* {
box-sizing: border-box;
}

#output {
margin: 1rem 0 0;
}
main {
margin: 20px auto;
max-width: 700px;
}

#output textarea {
width: 100%;
height: 6rem;
resize: vertical;
font-family: monospace;
border-radius: 5px;
border: solid 1px #444;
padding: 10px;
}
</style>
<script type="module" src="trix.esm.js"></script>
<script type="module" src="inspector.js"></script>
<script type="module">
Trix.config.attachments.preview.caption.name = true
Trix.config.attachments.preview.caption.size = false
#output {
margin: 1rem 0 0;
}

document.addEventListener("trix-initialize", function(event) {
Trix.Inspector.install(event.target);
});
#output textarea {
width: 100%;
height: 6rem;
resize: vertical;
font-family: monospace;
border-radius: 5px;
border: solid 1px #444;
padding: 10px;
}
</style>
<script type="module">
import TrixInitialize from './trix.esm/trix.js';
await TrixInitialize.init();
await import('./inspector.js');
Trix.config.attachments.preview.caption.name = true
Trix.config.attachments.preview.caption.size = false

document.addEventListener("trix-attachment-add", function(event) {
var attachment = event.attachment;
if (attachment.file) {
var xhr = new XMLHttpRequest;
xhr.open("POST", "/attachments", true);
document.addEventListener("trix-initialize", function (event) {
Trix.Inspector.install(event.target);
});

xhr.upload.onprogress = function(event) {
var progress = event.loaded / event.total * 100;
attachment.setUploadProgress(progress);
};
document.addEventListener("trix-attachment-add", function (event) {
var attachment = event.attachment;
if (attachment.file) {
var xhr = new XMLHttpRequest;
xhr.open("POST", "/attachments", true);

xhr.onload = function() {
if (xhr.status === 201) {
setTimeout(function() {
var url = xhr.responseText;
attachment.setAttributes({ url: url, href: url });
}, 30)
}
};
xhr.upload.onprogress = function (event) {
var progress = event.loaded / event.total * 100;
attachment.setUploadProgress(progress);
};

xhr.onload = function () {
if (xhr.status === 201) {
setTimeout(function () {
var url = xhr.responseText;
attachment.setAttributes({ url: url, href: url });
}, 30)
}
};

attachment.setUploadProgress(10);

setTimeout(function () {
xhr.send(attachment.file);
}, 30)
}
});
</script>
</head>

attachment.setUploadProgress(10);
<body>
<main>
<trix-toolbar id="my_toolbar"></trix-toolbar>
<trix-editor toolbar="my_toolbar" autofocus class="trix-content" input="input"></trix-editor>
<details id="output">
<summary>Output</summary>
<textarea readonly id="input"></textarea>
</details>
</main>
</body>

setTimeout(function() {
xhr.send(attachment.file);
}, 30)
}
});
</script>
</head>
<body>
<main>
<trix-editor autofocus class="trix-content" input="input"></trix-editor>
<details id="output">
<summary>Output</summary>
<textarea readonly id="input"></textarea>
</details>
</main>
</body>
</html>
</html>
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "trix",
"name": "@ernestasTheDev/trix-ssr",
"version": "2.1.6",
"description": "A rich text editor for everyday writing",
"main": "dist/trix.umd.min.js",
"module": "dist/trix.esm.min.js",
"main": "dist/trix.esm.min/trix.js",
"module": "dist/trix.esm.min/trix.js",
"style": "dist/trix.css",
"files": [
"dist/*.css",
Expand Down Expand Up @@ -61,12 +61,13 @@
"build": "yarn run build-js && yarn run build-css && yarn run build-assets",
"watch": "rollup -c -w",
"lint": "eslint .",
"pretest": "yarn run lint && yarn run build",
"pretest": "yarn run build",
"test": "karma start",
"prerelease": "yarn version && yarn test",
"release": "npm adduser && npm publish",
"postrelease": "git push && git push --tags",
"dev": "web-dev-server --app-index index.html --root-dir dist --node-resolve --open",
"start": "yarn build-assets && concurrently --kill-others --names js,css,dev-server 'yarn watch' 'yarn build-css --watch' 'yarn dev'"
}
},
"packageManager": "[email protected]"
}
26 changes: 7 additions & 19 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ const banner = `/*\nTrix ${version}\nCopyright © ${year} 37signals, LLC\n */`
const plugins = [
json(),
includePaths({
paths: [ "src" ],
extensions: [ ".js" ]
paths: ["src"],
extensions: [".js"]
}),
nodeResolve({ extensions: [ ".js" ] }),
nodeResolve({ extensions: [".js"] }),
commonjs({
extensions: [ ".js" ]
extensions: [".js"]
}),
babel({ babelHelpers: "bundled" }),
]
Expand Down Expand Up @@ -54,13 +54,7 @@ export default [
input: "src/trix/trix.js",
output: [
{
name: "Trix",
file: "dist/trix.umd.js",
format: "umd",
banner
},
{
file: "dist/trix.esm.js",
dir: "dist/trix.esm",
format: "es",
banner
}
Expand All @@ -71,14 +65,7 @@ export default [
input: "src/trix/trix.js",
output: [
{
name: "Trix",
file: "dist/trix.umd.min.js",
format: "umd",
banner,
sourcemap: true
},
{
file: "dist/trix.esm.min.js",
dir: "dist/trix.esm.min",
format: "es",
banner,
sourcemap: true
Expand All @@ -92,6 +79,7 @@ export default [
name: "TrixTests",
file: "dist/test.js",
format: "es",
inlineDynamicImports: true,
sourcemap: true,
banner
},
Expand Down
2 changes: 0 additions & 2 deletions src/test/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable
*/
import Trix from "trix/trix"

import "trix/core/helpers/global"
import "test/test_helper"

Expand Down
23 changes: 12 additions & 11 deletions src/test/test_helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Trix from "trix/trix"

import TrixInit from "trix/trix"
export * from "trix/core/helpers/functions"
export * from "trix/core/helpers/global"
export * from "./test_helpers/event_helpers"
Expand All @@ -14,20 +13,22 @@ export * from "./test_helpers/editor_helpers"
export * from "./test_helpers/toolbar_helpers"
export * from "./test_helpers/selection_helpers"

window.Trix = Trix
Trix.config.undo.interval = 0

QUnit.config.hidepassed = true
QUnit.config.testTimeout = 20000
(async () => {
await TrixInit.init();
Trix.config.undo.interval = 0
QUnit.config.hidepassed = true
QUnit.config.testTimeout = 20000

document.head.insertAdjacentHTML(
"beforeend",
`<style type="text/css">
document.head.insertAdjacentHTML(
"beforeend",
`<style type="text/css">
#trix-container { height: 150px; }
trix-toolbar { margin-bottom: 10px; }
trix-toolbar button { border: 1px solid #ccc; background: #fff; }
trix-toolbar button.active { background: #d3e6fd; }
trix-toolbar button:disabled { color: #ccc; }
#qunit { position: relative !important; }
</style>`
)
)
})();

Loading

0 comments on commit 454b48e

Please sign in to comment.