A .gitignore => .gitignore +1 -0
@@ 0,0 1,1 @@
+*.autosave
A public/404 => public/404 +21 -0
A public/404.css => public/404.css +3 -0
@@ 0,0 1,3 @@
+body {
+ color: black
+}<
\ No newline at end of file
A public/404.html => public/404.html +3 -0
@@ 0,0 1,3 @@
+asdf
+
+boo yesss<
\ No newline at end of file
A public/asldfn => public/asldfn +1 -0
@@ 0,0 1,1 @@
+aaaa<
\ No newline at end of file
A public/asldfn.html => public/asldfn.html +1 -0
@@ 0,0 1,1 @@
+aaaaa<
\ No newline at end of file
M public/editor.bundle.js => public/editor.bundle.js +16 -5
@@ 17867,15 17867,15 @@ import('https://esm.sh/fast-equals@2.0.4').then(({ deepEqual })=>equal = deepEq
const editors = {
};
const autosave = upload.bind(null, 'autosave');
-const save1 = upload.bind(null, 'save');
+const publish = upload.bind(null, 'save');
function createEditor(selector, flags = {
}) {
const $ = tag(selector);
mount1($, flags);
- onSave($, flags);
onAutosave($, {
every: 5
});
+ onPublish($, flags);
}
const config1 = {
extensions: [
@@ 17889,6 17889,16 @@ function mount1($, flags) {
$.mount((target)=>{
$.ready(()=>{
if (editors[target.id]) return;
+ target.innerHTML = `
+ <nav class="action-bar">
+ <button data-reset data-id="${target.id}">
+ Reset
+ </button>
+ <button data-publish data-id="${target.id}">
+ Publish
+ </button>
+ </nav>
+ `;
const initialState = $.read();
const copy = initialState[target.id] || {
};
@@ 17916,9 17926,10 @@ function onAutosave($, { every }) {
})
, every * 1000);
}
-function onSave($, _flags) {
- $.on('click', '[data-save]', (event)=>{
- save1(event.target.id, $);
+function onPublish($, _flags) {
+ $.on('click', '[data-publish]', (event)=>{
+ const { id } = event.target.dataset;
+ publish(id, $);
});
}
async function upload(mode, pathname, $) {
M public/editor.js => public/editor.js +18 -6
@@ 18,14 18,14 @@ import tag
const editors = {}
const autosave = upload.bind(null, 'autosave')
-const save = upload.bind(null, 'save')
+const publish = upload.bind(null, 'save')
export default function createEditor(selector, flags = {}) {
const $ = tag(selector)
mount($, flags)
- onSave($, flags)
onAutosave($, { every: 5 })
+ onPublish($, flags)
}
const config = {
@@ 40,9 40,20 @@ const config = {
function mount($, flags) {
$.mount(target => {
$.ready(() => {
- // not ready or already initialized, quit
+ // already initialized, quit
if(editors[target.id]) return
+ target.innerHTML = `
+ <nav class="action-bar">
+ <button data-reset data-id="${target.id}">
+ Reset
+ </button>
+ <button data-publish data-id="${target.id}">
+ Publish
+ </button>
+ </nav>
+ `
+
const initialState = $.read()
const copy = initialState[target.id] || {}
@@ 73,9 84,10 @@ function onAutosave($, { every }) {
}), every * 1000)
}
-function onSave($, _flags) {
- $.on('click', '[data-save]', (event) => {
- save(event.target.id, $)
+function onPublish($, _flags) {
+ $.on('click', '[data-publish]', (event) => {
+ const { id } = event.target.dataset
+ publish(id, $)
})
}
M server.js => server.js +1 -5
@@ 12,7 12,6 @@ const modes = {
async function autosave(pathname, params) {
const { value } = params
-console.log('why')
await Deno.writeTextFile(`./public${pathname}.autosave`, value)
return editor(request)
}
@@ 71,10 70,7 @@ function editor(request) {
id="${pathname}"
></main>
<script type="module">
- import createEditor
- from '/public/editor.bundle.js'
-
- console.log({ createEditor })
+ import createEditor from '/public/editor.bundle.js'
createEditor('.source-code')
</script>