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
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Filename-safe slug: lowercase, ascii, hyphen-separated, capped at 120 chars.
3
+ *
4
+ * Shared runtime code (unlike protocol.ts, which is types-only): the client
5
+ * uses it to live-suggest a slug from the title, the server re-runs it as the
6
+ * authority before touching the filesystem. Keeping one implementation means
7
+ * the suggestion the user saw is exactly the filename the server creates.
8
+ */
9
+ export function slugify(raw: string): string {
10
+ return raw
11
+ .toLowerCase()
12
+ .normalize('NFKD')
13
+ .replace(/[\u0300-\u036f]/g, '')
14
+ .replace(/[^a-z0-9]+/g, '-')
15
+ .replace(/^-+|-+$/g, '')
16
+ .slice(0, 120);
17
+ }
@@ -0,0 +1,51 @@
1
+ import type { UnsplashImportWidth } from './protocol.ts';
2
+
3
+ /**
4
+ * The import widths an Unsplash photo may be fetched at — the safelist, plus
5
+ * the parsing both sides do.
6
+ *
7
+ * Shared runtime code, for the same reason `slug.ts` is (and unlike
8
+ * `protocol.ts`, which stays types-only): the picker renders the select from
9
+ * this list and sends the chosen width, and the server re-runs `coerceWidth` as
10
+ * the authority before it goes anywhere near the upstream URL. A width lands in
11
+ * a URL the dev server fetches, so a value that is not one of these is
12
+ * **refused, never clamped** — clamping a bad input would hide a client bug and
13
+ * silently import the wrong size.
14
+ *
15
+ * `'original'` means "send no `w` at all": the raw file at full resolution,
16
+ * bounded only by the import byte cap. `fit=max` never upscales, so every other
17
+ * entry only ever shrinks.
18
+ */
19
+ export const UNSPLASH_IMPORT_WIDTHS: readonly UnsplashImportWidth[] = [
20
+ 800,
21
+ 1600,
22
+ 2400,
23
+ 'original',
24
+ ];
25
+
26
+ /** The default when neither the config nor the settings file says otherwise —
27
+ * the width every import used before it was choosable, so behaviour is
28
+ * unchanged for a project that never touches the option. */
29
+ export const UNSPLASH_DEFAULT_IMPORT_WIDTH: UnsplashImportWidth = 2400;
30
+
31
+ /**
32
+ * The wire/settings form of a width: `'800'` … `'2400'`, `'original'`. The
33
+ * option is a `select`, whose values are strings, and the settings file is JSON
34
+ * a human may hand-edit — so a width is carried as text and parsed once, here.
35
+ */
36
+ export const UNSPLASH_IMPORT_WIDTH_CHOICES: readonly string[] =
37
+ UNSPLASH_IMPORT_WIDTHS.map(String);
38
+
39
+ /** Parse a width from anything — a wire field, a config value, a JSON string —
40
+ * returning `null` for everything not on the safelist. */
41
+ export function coerceImportWidth(raw: unknown): UnsplashImportWidth | null {
42
+ if (raw === 'original') return 'original';
43
+ const n = typeof raw === 'number' ? raw : typeof raw === 'string' ? Number(raw) : NaN;
44
+ if (!Number.isFinite(n)) return null;
45
+ return (UNSPLASH_IMPORT_WIDTHS.find((w) => w === n) as UnsplashImportWidth | undefined) ?? null;
46
+ }
47
+
48
+ /** How a width reads in the UI — `2400 px`, or `Original size`. */
49
+ export function importWidthLabel(width: UnsplashImportWidth): string {
50
+ return width === 'original' ? 'Original size' : `${width} px`;
51
+ }