astro-dev-edit 0.11.0

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.
Files changed (81) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +125 -0
  3. package/package.json +52 -0
  4. package/src/client/admin-bar.ts +622 -0
  5. package/src/client/api.ts +370 -0
  6. package/src/client/classify-cache.ts +61 -0
  7. package/src/client/css-inspect.ts +345 -0
  8. package/src/client/editors/asset-picker.ts +155 -0
  9. package/src/client/editors/body-editor.ts +419 -0
  10. package/src/client/editors/collections-panel.ts +1532 -0
  11. package/src/client/editors/copy-panel.ts +73 -0
  12. package/src/client/editors/drawer.ts +95 -0
  13. package/src/client/editors/entry.ts +433 -0
  14. package/src/client/editors/expression.ts +77 -0
  15. package/src/client/editors/fields.ts +309 -0
  16. package/src/client/editors/image.ts +268 -0
  17. package/src/client/editors/markup-insert.ts +73 -0
  18. package/src/client/editors/markup.ts +125 -0
  19. package/src/client/editors/media-grid.ts +326 -0
  20. package/src/client/editors/media-modal.ts +588 -0
  21. package/src/client/editors/notice.ts +160 -0
  22. package/src/client/editors/peek.ts +135 -0
  23. package/src/client/editors/settings-panel.ts +457 -0
  24. package/src/client/editors/source-popup.ts +166 -0
  25. package/src/client/editors/text.ts +105 -0
  26. package/src/client/editors/unsplash-pane.ts +317 -0
  27. package/src/client/element-context.ts +308 -0
  28. package/src/client/features.ts +81 -0
  29. package/src/client/focus.ts +166 -0
  30. package/src/client/group.ts +186 -0
  31. package/src/client/highlight.ts +146 -0
  32. package/src/client/hover.ts +485 -0
  33. package/src/client/icons.ts +160 -0
  34. package/src/client/markdown.ts +319 -0
  35. package/src/client/overlay.ts +466 -0
  36. package/src/client/page-source.ts +143 -0
  37. package/src/client/router.ts +198 -0
  38. package/src/client/shadow.ts +111 -0
  39. package/src/client/source-map.ts +150 -0
  40. package/src/client/state.ts +153 -0
  41. package/src/client/styles.ts +3485 -0
  42. package/src/client/tree-model.ts +45 -0
  43. package/src/client/tree.ts +366 -0
  44. package/src/client/ui.ts +987 -0
  45. package/src/client/unsplash-search.ts +250 -0
  46. package/src/index.ts +299 -0
  47. package/src/patcher/astro.ts +792 -0
  48. package/src/patcher/content-config.ts +1035 -0
  49. package/src/patcher/dotenv.ts +121 -0
  50. package/src/patcher/expression-trace.ts +326 -0
  51. package/src/patcher/frontmatter.ts +249 -0
  52. package/src/patcher/registry.ts +11 -0
  53. package/src/patcher/types.ts +32 -0
  54. package/src/server/annotate.ts +173 -0
  55. package/src/server/assets.ts +167 -0
  56. package/src/server/collection-entries.ts +91 -0
  57. package/src/server/content-config.ts +210 -0
  58. package/src/server/editor.ts +15 -0
  59. package/src/server/entry-detect.ts +110 -0
  60. package/src/server/entry-resolve-routes.ts +218 -0
  61. package/src/server/entry-routes.ts +304 -0
  62. package/src/server/inspect-locate.ts +81 -0
  63. package/src/server/inspect-routes.ts +94 -0
  64. package/src/server/middleware.ts +480 -0
  65. package/src/server/options.ts +778 -0
  66. package/src/server/page-source-routes.ts +71 -0
  67. package/src/server/paths.ts +219 -0
  68. package/src/server/private-files.ts +116 -0
  69. package/src/server/route-manifest.ts +200 -0
  70. package/src/server/router.ts +94 -0
  71. package/src/server/schema-introspect.ts +233 -0
  72. package/src/server/schema-routes.ts +808 -0
  73. package/src/server/settings-routes.ts +246 -0
  74. package/src/server/settings.ts +382 -0
  75. package/src/server/text-writes.ts +105 -0
  76. package/src/server/unsplash-routes.ts +515 -0
  77. package/src/server/zod-adapt.ts +239 -0
  78. package/src/shared/asset-path.ts +132 -0
  79. package/src/shared/protocol.ts +935 -0
  80. package/src/shared/slug.ts +17 -0
  81. package/src/shared/unsplash.ts +51 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 janjcwebtech
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,125 @@
1
+ <div align="center">
2
+
3
+ <img src="https://raw.githubusercontent.com/janjcwebtech/astro-dev-edit/main/documentation/images/banner.webp" alt="VS Code with the playground site in the editor pane: the hover pill reads index.astro:22:13 editable, with open and copy buttons, above a heading selected for inline editing, and the matching h1 highlighted in the source on the right" width="820">
4
+
5
+ # astro-dev-edit
6
+
7
+ ### Click the text on the page, edit it, and the change lands in your source file.
8
+
9
+ [![version](https://img.shields.io/github/v/tag/janjcwebtech/astro-dev-edit?color=6144d7&label=version)](https://github.com/janjcwebtech/astro-dev-edit/releases) ![status: beta](https://img.shields.io/badge/status-beta-f59e0b) [![Astro 5, 6 and 7](https://img.shields.io/badge/astro-5%20%C2%B7%206%20%C2%B7%207-6144d7)](https://github.com/withastro/astro) ![Dev server only](https://img.shields.io/badge/scope-dev%20server%20only-444) [![MIT license](https://img.shields.io/github/license/janjcwebtech/astro-dev-edit?color=444)](https://github.com/janjcwebtech/astro-dev-edit/blob/main/LICENSE)
10
+
11
+ [**Watch the demo**](https://youtu.be/sa0TdkoybAk) · [Why I built it](https://jcweb.tech/visual-editing-for-astro-development/) · [Docs](https://github.com/janjcwebtech/astro-dev-edit/blob/main/documentation/EDITING.md) · [Changelog](https://github.com/janjcwebtech/astro-dev-edit/blob/main/CHANGELOG.md)
12
+
13
+ </div>
14
+
15
+ [https://github.com/user-attachments/assets/ac4a1864-daec-4ab6-b7e5-5ee0839f5356](https://github.com/user-attachments/assets/ac4a1864-daec-4ab6-b7e5-5ee0839f5356)
16
+
17
+ `astro-dev-edit` is an **in-browser visual content editor** for Astro websites running on a local dev server. Turn on the edit mode, click a piece of text or an image on the rendered page, change it, and the change is written into the source file it came from.
18
+
19
+ For bigger changes it **points you to the right place in the source code**.
20
+ There is also a **quick source preview** for HTML and CSS and allows you to give the exact **context to your AI** agent.
21
+
22
+ **Tip:** Hold Ctrl (Option on macOS) and links work as usual, so you can move around the site without leaving edit mode.
23
+
24
+ ## Install
25
+
26
+ Not on npm yet. While it is in beta, install it from GitHub:
27
+
28
+ ```bash
29
+ npm install --save-dev github:janjcwebtech/astro-dev-edit
30
+ ```
31
+
32
+ ```js
33
+ // astro.config.mjs
34
+ import { defineConfig } from "astro/config";
35
+ import devEdit from "astro-dev-edit";
36
+
37
+ export default defineConfig({
38
+ integrations: [devEdit()],
39
+ });
40
+ ```
41
+
42
+ Run `npm run dev` and click **Edit page** in the admin bar.
43
+
44
+ Works on Astro 5, 6 and 7. The per-version setup, and the one flag Astro 5 and 6 need, are in [Astro versions and source annotations](https://github.com/janjcwebtech/astro-dev-edit/blob/main/documentation/CONFIGURATION.md#astro-versions-and-source-annotations).
45
+
46
+ ## What you can edit
47
+
48
+ - **Literal text in a template.** Click it and type. The pill above the element names the file and the line the change will land in. Enter saves, escape cancels.
49
+ - **Strings that arrive through an expression.** A value pulled from the frontmatter is followed back to the string that produced it, and you edit that string, with the trace of where it came from.
50
+ - **Text carrying inline markup.** A heading broken by a `<br>`, or a sentence with a `<strong>` in it, opens over the raw source with a row of insertable tags: `br`, `strong`, `em`, `b`, `i`, `u`, `a`, `span`, `code`, `small`, `sup`, `sub`.
51
+ - **Images.** Click one and you get a preview, the file name and size, the alt text, and the six images most recently added to the project. The full picker lists everything in your asset directories, with a filter, an upload button and an Unsplash tab if you add an access key.
52
+ - **Markdown and MDX entries.** Switch a collection on in the **Collections** drawer and its pages get **Edit entry**: a drawer of typed form fields generated from your own zod schema, and the body as rich text or as raw markdown. It looks like a small CMS panel, but it reads and writes the entry file directly. The tool finds the backing entry from the URL, so there is nothing to add to your templates. You can create and delete entries from here too.
53
+ - **Collection schemas.** The designer lists every collection you declare and lets you add a field, retype one, remove one, or build a collection from scratch. Those edits patch your `content.config.ts`.
54
+
55
+ ## Other features
56
+
57
+ - **CSS peek**
58
+ - **Code peek**
59
+ - **Structure tree view**
60
+ - **Links to the source code across the UI**
61
+ - **Copy element's context for AI**
62
+
63
+ ## Screenshots
64
+
65
+ ![A heading in edit mode with the hover pill above it naming the file and line](https://raw.githubusercontent.com/janjcwebtech/astro-dev-edit/main/documentation/images/edit-text.png)
66
+
67
+ _Editing a heading in place. The pill names the file, the line and the column, and it stays there while you type._
68
+
69
+ ![The body field of the entry drawer showing a formatting toolbar above rendered headings, paragraphs and a code block](https://raw.githubusercontent.com/janjcwebtech/astro-dev-edit/main/documentation/images/body-editor.png)
70
+
71
+ _The body of a markdown entry in the rich text editor. The toolbar covers headings, emphasis, lists, quotes, code, links, images and horizontal rules, and you can switch to the raw markdown at any point._
72
+
73
+ ![The Unsplash tab of the picker showing search results for mountains, each tile credited to its photographer, with shape and size selects](https://raw.githubusercontent.com/janjcwebtech/astro-dev-edit/main/documentation/images/unsplash.jpg)
74
+
75
+ _With an Unsplash access key, a second tab in the picker searches Unsplash from inside your own site and imports the photo you pick at the width you choose._
76
+
77
+ ![The hover pill showing class chips for btn and btn-primary, with a popup listing the CSS rules applied by btn-primary and the file they are written in](https://raw.githubusercontent.com/janjcwebtech/astro-dev-edit/main/documentation/images/css-inspector.png)
78
+
79
+ _The class chips on the pill show which CSS rules apply to the element and which file they are written in, so adjusting a transition is one click rather than a search._
80
+
81
+ ![The pill's copy button, next to a Claude Code prompt filled with the element context: source location, page URL, DOM path and applied CSS](https://raw.githubusercontent.com/janjcwebtech/astro-dev-edit/main/documentation/images/copy-context.png)
82
+
83
+ _**Copy Context** puts the whole context of the element on your clipboard: the source location, the page URL, the DOM path, the rendered HTML and the CSS rules that apply to it. Your AI agent starts at the change instead of spending turns working all of that out._
84
+
85
+ ## Configuration
86
+
87
+ Everything is optional. Pass what you want to `devEdit({ … })`, or set it from the **Settings** drawer, which saves your choices in `.astro-dev-edit.json` and applies them to the next request without a restart. Anything you set in `astro.config.mjs` wins over that file and renders read-only in the drawer, with a note saying where the value came from.
88
+
89
+ Your Unsplash key goes somewhere else: the drawer writes it to `.env.local` at `0600`. Gitignore that and `.astro-dev-edit.json` — the drawer names either one your ignore rules miss.
90
+
91
+ Every option, with its default and what it does: [Configuration reference](https://github.com/janjcwebtech/astro-dev-edit/blob/main/documentation/CONFIGURATION.md).
92
+
93
+ ## Limits
94
+
95
+ - No undo and no edit history. Every save writes the file immediately, so your git tree is the safety net: start from a clean tree, review with `git diff`, discard with `git checkout <file>`. Writes are atomic and verified against what the page showed, so a stale click fails rather than corrupting the file.
96
+ - Content, never structure. Inline edited text is escaped so it cannot introduce a tag, an expression or an entity. The markup popup lets tags through, but only the inline safelist, only with presentational attributes, and only well nested.
97
+ - The rich body editor covers a markdown subset. Anything past it, so tables, raw HTML or MDX, footnotes and nested lists, stays editable as markdown source.
98
+ - The collection designer reads only the schema shapes it can prove: `schema: z.object({ … })` and `schema: ({ image }) => z.object({ … })` with a plain field list. Anything else is reported as unreadable, with _Open source_ offered instead.
99
+ - Unsplash is free tier only, and a photo is importable only while the dev server that searched for it is still running.
100
+
101
+ ## Documentation
102
+
103
+ | Doc | What's in it |
104
+ | ------------------------------------ | ------------------------------------------------------------ |
105
+ | Editing reference | Everything the overlay can edit, and every surface it draws |
106
+ | Entry editor and collection designer | The CMS drawer, switching it on per collection, schema editing |
107
+ | Media picker and Unsplash | Choosing, uploading and importing images |
108
+ | Configuration reference | Every option, the Settings drawer, and which source wins |
109
+ | Styling reference | The --atx-\* properties and ::part() names you can theme |
110
+ | Architecture | How the layers fit together, and where a new capability goes |
111
+ | Changelog | What changed, release by release |
112
+
113
+ **Disclaimer:** The author is not responsible for any data loss. Back up your work regularly using git best practices.
114
+
115
+ ## Credits
116
+
117
+ The technique of snapshotting Astro's `data-astro-source-*` attributes into a private JS property the instant they appear, before the dev toolbar runtime strips them from the live DOM, is borrowed from [`astro-click-to-source`](https://www.npmjs.com/package/astro-click-to-source) by **invisible1988** (MIT). If source navigation is all you want, that is the lighter tool for the job.
118
+
119
+ ## Contributing
120
+
121
+ Bug reports and pull requests are welcome. Everything is reviewed and merged by me, and commits need a `Signed-off-by` line (`git commit -s`). [Contributing guide](https://github.com/janjcwebtech/astro-dev-edit/blob/main/CONTRIBUTING.md) · [Security policy](https://github.com/janjcwebtech/astro-dev-edit/blob/main/SECURITY.md).
122
+
123
+ ## License
124
+
125
+ MIT
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "astro-dev-edit",
3
+ "version": "0.11.0",
4
+ "description": "In-browser visual content editing for the Astro dev server — click text or images in the rendered page, writes straight to source. Dev-only.",
5
+ "type": "module",
6
+ "author": "Jan Cerny (https://github.com/janjcwebtech)",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/janjcwebtech/astro-dev-edit.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/janjcwebtech/astro-dev-edit/issues"
13
+ },
14
+ "homepage": "https://github.com/janjcwebtech/astro-dev-edit#readme",
15
+ "exports": {
16
+ ".": "./src/index.ts"
17
+ },
18
+ "files": [
19
+ "src",
20
+ "README.md",
21
+ "LICENSE"
22
+ ],
23
+ "keywords": [
24
+ "astro",
25
+ "astro-integration",
26
+ "astro-component",
27
+ "cms",
28
+ "visual-editing",
29
+ "dev-tools",
30
+ "withastro"
31
+ ],
32
+ "license": "MIT",
33
+ "scripts": {
34
+ "typecheck": "tsc --noEmit -p tsconfig.json",
35
+ "test": "vitest run",
36
+ "test:watch": "vitest"
37
+ },
38
+ "peerDependencies": {
39
+ "astro": ">=5.0.0 <8"
40
+ },
41
+ "dependencies": {
42
+ "@astrojs/compiler": "^2.13.1",
43
+ "launch-editor": "^2.14.1",
44
+ "yaml": "^2.9.0"
45
+ },
46
+ "devDependencies": {
47
+ "@types/node": "^22.20.1",
48
+ "typescript": "^5.6.0",
49
+ "vitest": "^4.1.10",
50
+ "zod": "^3.25.76"
51
+ }
52
+ }