@velocity-astro/cms-astro 0.1.0-beta.3 → 0.1.0-beta.5

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 (58) hide show
  1. package/dist/admin-files.d.ts +2 -2
  2. package/dist/admin-files.d.ts.map +1 -1
  3. package/dist/admin-files.js +13 -7
  4. package/dist/admin-files.js.map +1 -1
  5. package/dist/challenge.d.ts +35 -0
  6. package/dist/challenge.d.ts.map +1 -0
  7. package/dist/challenge.js +84 -0
  8. package/dist/challenge.js.map +1 -0
  9. package/dist/connection.d.ts.map +1 -1
  10. package/dist/connection.js +22 -11
  11. package/dist/connection.js.map +1 -1
  12. package/dist/editor.d.ts +2 -0
  13. package/dist/editor.d.ts.map +1 -1
  14. package/dist/editor.js +9 -1
  15. package/dist/editor.js.map +1 -1
  16. package/dist/form-post.d.ts +9 -1
  17. package/dist/form-post.d.ts.map +1 -1
  18. package/dist/form-post.js +10 -3
  19. package/dist/form-post.js.map +1 -1
  20. package/dist/index.d.ts +8 -3
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +8 -3
  23. package/dist/index.js.map +1 -1
  24. package/dist/media-store.d.ts +9 -0
  25. package/dist/media-store.d.ts.map +1 -1
  26. package/dist/media-store.js +17 -1
  27. package/dist/media-store.js.map +1 -1
  28. package/dist/page-marks.d.ts +34 -0
  29. package/dist/page-marks.d.ts.map +1 -0
  30. package/dist/page-marks.js +68 -0
  31. package/dist/page-marks.js.map +1 -0
  32. package/dist/resend-mailer.d.ts +18 -1
  33. package/dist/resend-mailer.d.ts.map +1 -1
  34. package/dist/resend-mailer.js +24 -3
  35. package/dist/resend-mailer.js.map +1 -1
  36. package/dist/site-editor.d.ts +1 -1
  37. package/dist/site-editor.d.ts.map +1 -1
  38. package/dist/site-editor.js +28 -6
  39. package/dist/site-editor.js.map +1 -1
  40. package/dist/site-forms.d.ts +11 -0
  41. package/dist/site-forms.d.ts.map +1 -1
  42. package/dist/site-forms.js +29 -16
  43. package/dist/site-forms.js.map +1 -1
  44. package/dist/site-mail.d.ts +45 -0
  45. package/dist/site-mail.d.ts.map +1 -0
  46. package/dist/site-mail.js +84 -0
  47. package/dist/site-mail.js.map +1 -0
  48. package/dist/site-name.d.ts +9 -0
  49. package/dist/site-name.d.ts.map +1 -0
  50. package/dist/site-name.js +21 -0
  51. package/dist/site-name.js.map +1 -0
  52. package/dist/site-storage.d.ts +34 -0
  53. package/dist/site-storage.d.ts.map +1 -0
  54. package/dist/site-storage.js +118 -0
  55. package/dist/site-storage.js.map +1 -0
  56. package/package.json +7 -7
  57. package/routes/form-client.js.ts +68 -0
  58. package/routes/preview-client.js.ts +4 -56
@@ -1,63 +1,11 @@
1
1
  import type { APIRoute } from 'astro';
2
+ import { PREVIEW_BRIDGE_SCRIPT } from '@velocity-astro/cms-astro';
2
3
 
3
4
  export const prerender = false;
4
5
 
5
6
  /**
6
- * What the page beside the editor's form runs. The preview adds it to that page only, and it
7
- * does nothing unless the page is in a frame of the same site.
8
- *
9
- * It tells the editor which section was clicked, shows the section the editor asks for, and
10
- * keeps the page where it was scrolled to when it is drawn again. It marks a section by setting
11
- * its style from script, which a page's content rules allow where a style written into the page
12
- * would not be.
7
+ * What the page beside the editor's form runs (`src/preview-bridge.ts`). The preview adds it to
8
+ * that page only, and it does nothing unless the page is in a frame of the same site.
13
9
  */
14
- const SCRIPT = `
15
- if (window.parent !== window) {
16
- const origin = location.origin;
17
- const say = (message) => window.parent.postMessage({ source: 'velocity-cms', ...message }, origin);
18
- const sectionOf = (target) => (target instanceof Element ? target.closest('[data-cms-section]') : null);
19
-
20
- let marked = null;
21
- const mark = (section) => {
22
- if (marked === section) return;
23
- if (marked) marked.style.outline = marked.style.outlineOffset = marked.style.cursor = '';
24
- marked = section;
25
- if (!section) return;
26
- section.style.outline = '2px solid Highlight';
27
- section.style.outlineOffset = '-2px';
28
- section.style.cursor = 'pointer';
29
- };
30
- document.addEventListener('mouseover', (event) => mark(sectionOf(event.target)));
31
- document.documentElement.addEventListener('mouseleave', () => mark(null));
32
-
33
- // Nothing on the page goes anywhere: a click chooses the section it is in.
34
- document.addEventListener('click', (event) => {
35
- event.preventDefault();
36
- const section = sectionOf(event.target);
37
- if (section) say({ type: 'section', id: section.dataset.cmsSection });
38
- }, true);
39
- document.addEventListener('submit', (event) => event.preventDefault(), true);
40
-
41
- addEventListener('message', (event) => {
42
- if (event.origin !== origin || event.source !== window.parent || event.data?.source !== 'velocity-cms') return;
43
- if (event.data.type !== 'show') return;
44
- const section = [...document.querySelectorAll('[data-cms-section]')].find((candidate) => candidate.dataset.cmsSection === event.data.id);
45
- if (!section) return;
46
- // Room for a header that stays at the top of the page.
47
- section.style.scrollMarginTop = '6rem';
48
- section.scrollIntoView({ block: 'start' });
49
- });
50
-
51
- const key = 'velocity-cms:scroll:' + location.pathname;
52
- try {
53
- const kept = Number(sessionStorage.getItem(key));
54
- if (kept > 0) scrollTo({ top: kept, behavior: 'instant' });
55
- addEventListener('pagehide', () => sessionStorage.setItem(key, String(scrollY)));
56
- } catch {}
57
-
58
- say({ type: 'ready' });
59
- }
60
- `;
61
-
62
10
  export const GET: APIRoute = () =>
63
- new Response(SCRIPT, { headers: { 'Content-Type': 'text/javascript; charset=utf-8', 'Cache-Control': 'public, max-age=3600' } });
11
+ new Response(PREVIEW_BRIDGE_SCRIPT, { headers: { 'Content-Type': 'text/javascript; charset=utf-8', 'Cache-Control': 'public, max-age=3600' } });