@pirateandfox/pagestack 0.1.0-beta.14 → 0.1.0-beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -6
- package/package.json +1 -1
- package/src/client/editor.ts +4 -2
- package/src/client/state.ts +11 -2
package/README.md
CHANGED
|
@@ -171,7 +171,7 @@ export const schemas = {
|
|
|
171
171
|
heading: {
|
|
172
172
|
label: 'Heading',
|
|
173
173
|
fields: {
|
|
174
|
-
text: { type: 'text', label: 'Text', inline: true, default: 'Heading' },
|
|
174
|
+
text: { type: 'text', label: 'Text', inline: true, marks: true, default: 'Heading' }, // marks: bold + italic
|
|
175
175
|
tag: { type: 'select', label: 'HTML tag', options: [...], default: 'h2', group: 'advanced' },
|
|
176
176
|
color: { type: 'color', label: 'Text colour', group: 'style' },
|
|
177
177
|
},
|
|
@@ -189,7 +189,8 @@ export const presets: Preset[] = [
|
|
|
189
189
|
|
|
190
190
|
Field types: `text`, `richtext`, `image`, `link`, `color`, `select`, `number`, `boolean`,
|
|
191
191
|
`textarea`, `code`, `svg`. `inline: true` on `text` / `richtext` / `image` makes the field
|
|
192
|
-
editable by clicking it in the preview.
|
|
192
|
+
editable by clicking it in the preview. `marks: true` on a `text` field allows bold and italic in it
|
|
193
|
+
(see [Bold and italic in headings](#bold-and-italic-in-headings)). The schema drives the sidebar form, validation on save,
|
|
193
194
|
the add-block menus and the tree labels. **Presets are the section library.**
|
|
194
195
|
|
|
195
196
|
### 3. Components that mark what they render
|
|
@@ -217,12 +218,37 @@ A few things worth knowing while you set up the schema:
|
|
|
217
218
|
(`src/sections/components.ts`) so the schema stays plain data.
|
|
218
219
|
- **List View names a block after its first non-empty inline text field**, so put the field people
|
|
219
220
|
recognise (the title) first.
|
|
220
|
-
- **`text` fields are plain text, unless you add `marks: true
|
|
221
|
-
|
|
222
|
-
page or in the sidebar. The value is then HTML holding only `<strong>` and `<em>` (everything else
|
|
223
|
-
is removed on save), so render it with `set:html`. The bakery's section titles use it.
|
|
221
|
+
- **`text` fields are plain text, unless you add `marks: true`**, which allows bold and italic as
|
|
222
|
+
in a WordPress heading. See [Bold and italic in headings](#bold-and-italic-in-headings).
|
|
224
223
|
- **The home page is `src/content/pages/index.json`**, edited at `/edit/index`.
|
|
225
224
|
|
|
225
|
+
### Bold and italic in headings
|
|
226
|
+
|
|
227
|
+
Text fields are plain text by default. Add `marks: true` to one and it behaves like a WordPress
|
|
228
|
+
heading: editors select words and press **B** or **I** in the small bar that appears, or `⌘B` / `⌘I`;
|
|
229
|
+
the sidebar shows the same field as one line with the two buttons. Pasting keeps bold and italic and
|
|
230
|
+
drops all other formatting.
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
title: { type: 'text', label: 'Title', inline: true, marks: true, default: 'Bread worth getting up <em>early</em> for' },
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
```astro
|
|
237
|
+
<h2 {...fieldAttrs(edit, 'title', 'text')} set:html={s.title} />
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
- The value is HTML holding only `<strong>` and `<em>`. Saving cleans it to exactly that (`<b>` and
|
|
241
|
+
`<i>` become `<strong>` and `<em>`; line breaks, links, spans and attributes are removed), so it is
|
|
242
|
+
safe with `set:html`.
|
|
243
|
+
- Render it with `set:html`. Rendered as `{s.title}`, the tags show up as text.
|
|
244
|
+
- Where the same value is used as plain text (a `<title>`, `alt`, `aria-label`, a breadcrumb, a
|
|
245
|
+
URL), strip the tags first: `s.title.replace(/<[^>]*>/g, '')`. Leave `marks` off fields that only
|
|
246
|
+
ever end up in places like that.
|
|
247
|
+
- Switching it on for an existing field is safe: plain values stay as they are. Values that held
|
|
248
|
+
other markup lose it the next time the page is saved, so check for that first.
|
|
249
|
+
- Headings inside a Markdown body (collections) need nothing: they are edited with the full rich
|
|
250
|
+
text toolbar already, and `**bold**` / `*italic*` is written back to the Markdown.
|
|
251
|
+
|
|
226
252
|
## Editing
|
|
227
253
|
|
|
228
254
|
Coming from the WordPress block editor:
|
|
@@ -235,6 +261,7 @@ Coming from the WordPress block editor:
|
|
|
235
261
|
| Block toolbar, ⋮ menu | Move, parent, add, duplicate, delete, copy, save as pattern |
|
|
236
262
|
| Settings sidebar, Page / Block tabs | Same, generated from the schema |
|
|
237
263
|
| Rich text toolbar, links | Same; `⌘B`, `⌘I`, `⌘K`, and an HTML view |
|
|
264
|
+
| Bold / italic in a heading | Same, on `text` fields with `marks: true`: a **B** / **I** bar, `⌘B`, `⌘I` |
|
|
238
265
|
| Status (Draft / Published), Publish, Preview | A **Ready to publish** switch (**Published** without `github.live`) that saves when flipped; Publish is **Publish changes** in the top bar with `github.live`; Preview opens the unsaved draft in a new tab |
|
|
239
266
|
| Revisions | The page's git history |
|
|
240
267
|
| Permalink | Change URL, which also adds a redirect |
|
|
@@ -249,6 +276,7 @@ Coming from the WordPress block editor:
|
|
|
249
276
|
- **Preview**: the page renders in a frame at real device widths, scaled to fit. Every change POSTs
|
|
250
277
|
the draft to `/edit/preview/<slug>`; the server renders it and only changed sections are swapped.
|
|
251
278
|
- **Inline**: click text to edit it in place; click an image to open the picker (alt text required).
|
|
279
|
+
Enter (in a one-line field) or clicking away keeps the edit; Escape cancels it.
|
|
252
280
|
- **Drafts** are kept in `localStorage` until saved; undo/redo is per session.
|
|
253
281
|
- **Save** sanitises rich text, validates the document, and writes the file (local) or commits
|
|
254
282
|
(github). A hash of what you loaded is sent along; if someone saved first you get a 409 and a
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pirateandfox/pagestack",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.15",
|
|
4
4
|
"description": "A block editor for Astro sites. Content stays in your repo, saves are git commits, the public site stays static, sign-in is passkeys.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/client/editor.ts
CHANGED
|
@@ -128,9 +128,11 @@ const inline = new InlineEditor({
|
|
|
128
128
|
onInput: (path, value) => { state.apply(setAt(state.doc, path, value), 'inline', false); refreshButtons(); },
|
|
129
129
|
onCommit: (path, value, changed) => {
|
|
130
130
|
idoc().body.removeAttribute('data-ps-typing');
|
|
131
|
-
|
|
131
|
+
// Not changed: clicked in and out, or Escape. Live updates already reached the doc, so go back.
|
|
132
|
+
let reverted = false;
|
|
133
|
+
if (changed) state.apply(setAt(state.doc, path, value), 'inline', false); else reverted = state.dropSnapshot(true);
|
|
132
134
|
refreshChrome();
|
|
133
|
-
if (changed || renderQueued) scheduleRender(0);
|
|
135
|
+
if (changed || reverted || renderQueued) scheduleRender(0);
|
|
134
136
|
renderQueued = false;
|
|
135
137
|
},
|
|
136
138
|
});
|
package/src/client/state.ts
CHANGED
|
@@ -38,8 +38,17 @@ export class EditorState extends EventTarget {
|
|
|
38
38
|
if (this.past.length > 200) this.past.shift();
|
|
39
39
|
this.future = [];
|
|
40
40
|
}
|
|
41
|
-
/**
|
|
42
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Take back a `snapshot` that turned out to have no change after it. With `restore`, also go back
|
|
43
|
+
* to the document it holds (an inline edit cancelled with Escape after live updates). True when that changed the doc.
|
|
44
|
+
*/
|
|
45
|
+
dropSnapshot(restore = false): boolean {
|
|
46
|
+
const prev = this.past.pop();
|
|
47
|
+
if (!restore || prev === undefined || prev === JSON.stringify(this.doc)) return false;
|
|
48
|
+
this.doc = JSON.parse(prev);
|
|
49
|
+
this.persist();
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
43
52
|
undo() {
|
|
44
53
|
const prev = this.past.pop();
|
|
45
54
|
if (prev === undefined) return;
|