@caretcms/core 0.1.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 (249) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +191 -0
  3. package/dist/browser-runtime.d.ts +12 -0
  4. package/dist/browser-runtime.d.ts.map +1 -0
  5. package/dist/browser-runtime.js +298 -0
  6. package/dist/browser-runtime.js.map +1 -0
  7. package/dist/index.d.ts +81 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +343 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/loader.d.ts +61 -0
  12. package/dist/loader.d.ts.map +1 -0
  13. package/dist/loader.js +80 -0
  14. package/dist/loader.js.map +1 -0
  15. package/dist/providers/storage/filesystem.d.ts +7 -0
  16. package/dist/providers/storage/filesystem.d.ts.map +1 -0
  17. package/dist/providers/storage/filesystem.js +6 -0
  18. package/dist/providers/storage/filesystem.js.map +1 -0
  19. package/dist/providers/uploads/local.d.ts +6 -0
  20. package/dist/providers/uploads/local.d.ts.map +1 -0
  21. package/dist/providers/uploads/local.js +6 -0
  22. package/dist/providers/uploads/local.js.map +1 -0
  23. package/dist/runtime/auth/cookie-utils.d.ts +3 -0
  24. package/dist/runtime/auth/cookie-utils.d.ts.map +1 -0
  25. package/dist/runtime/auth/cookie-utils.js +33 -0
  26. package/dist/runtime/auth/cookie-utils.js.map +1 -0
  27. package/dist/runtime/auth/demo-session.d.ts +24 -0
  28. package/dist/runtime/auth/demo-session.d.ts.map +1 -0
  29. package/dist/runtime/auth/demo-session.js +42 -0
  30. package/dist/runtime/auth/demo-session.js.map +1 -0
  31. package/dist/runtime/auth/rate-limiter.d.ts +26 -0
  32. package/dist/runtime/auth/rate-limiter.d.ts.map +1 -0
  33. package/dist/runtime/auth/rate-limiter.js +65 -0
  34. package/dist/runtime/auth/rate-limiter.js.map +1 -0
  35. package/dist/runtime/auth/session.d.ts +14 -0
  36. package/dist/runtime/auth/session.d.ts.map +1 -0
  37. package/dist/runtime/auth/session.js +128 -0
  38. package/dist/runtime/auth/session.js.map +1 -0
  39. package/dist/runtime/bind.d.ts +14 -0
  40. package/dist/runtime/bind.d.ts.map +1 -0
  41. package/dist/runtime/bind.js +19 -0
  42. package/dist/runtime/bind.js.map +1 -0
  43. package/dist/runtime/config.d.ts +20 -0
  44. package/dist/runtime/config.d.ts.map +1 -0
  45. package/dist/runtime/config.js +40 -0
  46. package/dist/runtime/config.js.map +1 -0
  47. package/dist/runtime/content.d.ts +28 -0
  48. package/dist/runtime/content.d.ts.map +1 -0
  49. package/dist/runtime/content.js +37 -0
  50. package/dist/runtime/content.js.map +1 -0
  51. package/dist/runtime/index.d.ts +14 -0
  52. package/dist/runtime/index.d.ts.map +1 -0
  53. package/dist/runtime/index.js +16 -0
  54. package/dist/runtime/index.js.map +1 -0
  55. package/dist/runtime/middleware.d.ts +14 -0
  56. package/dist/runtime/middleware.d.ts.map +1 -0
  57. package/dist/runtime/middleware.js +80 -0
  58. package/dist/runtime/middleware.js.map +1 -0
  59. package/dist/runtime/mutations/contracts.d.ts +91 -0
  60. package/dist/runtime/mutations/contracts.d.ts.map +1 -0
  61. package/dist/runtime/mutations/contracts.js +320 -0
  62. package/dist/runtime/mutations/contracts.js.map +1 -0
  63. package/dist/runtime/mutations/engine.d.ts +23 -0
  64. package/dist/runtime/mutations/engine.d.ts.map +1 -0
  65. package/dist/runtime/mutations/engine.js +255 -0
  66. package/dist/runtime/mutations/engine.js.map +1 -0
  67. package/dist/runtime/providers.d.ts +9 -0
  68. package/dist/runtime/providers.d.ts.map +1 -0
  69. package/dist/runtime/providers.js +44 -0
  70. package/dist/runtime/providers.js.map +1 -0
  71. package/dist/runtime/request-context.d.ts +11 -0
  72. package/dist/runtime/request-context.d.ts.map +1 -0
  73. package/dist/runtime/request-context.js +16 -0
  74. package/dist/runtime/request-context.js.map +1 -0
  75. package/dist/runtime/rewrite.d.ts +13 -0
  76. package/dist/runtime/rewrite.d.ts.map +1 -0
  77. package/dist/runtime/rewrite.js +253 -0
  78. package/dist/runtime/rewrite.js.map +1 -0
  79. package/dist/runtime/routes/_helpers.d.ts +17 -0
  80. package/dist/runtime/routes/_helpers.d.ts.map +1 -0
  81. package/dist/runtime/routes/_helpers.js +38 -0
  82. package/dist/runtime/routes/_helpers.js.map +1 -0
  83. package/dist/runtime/routes/admin-entry.d.ts +3 -0
  84. package/dist/runtime/routes/admin-entry.d.ts.map +1 -0
  85. package/dist/runtime/routes/admin-entry.js +170 -0
  86. package/dist/runtime/routes/admin-entry.js.map +1 -0
  87. package/dist/runtime/routes/admin.d.ts +3 -0
  88. package/dist/runtime/routes/admin.d.ts.map +1 -0
  89. package/dist/runtime/routes/admin.js +189 -0
  90. package/dist/runtime/routes/admin.js.map +1 -0
  91. package/dist/runtime/routes/auth-login.d.ts +4 -0
  92. package/dist/runtime/routes/auth-login.d.ts.map +1 -0
  93. package/dist/runtime/routes/auth-login.js +71 -0
  94. package/dist/runtime/routes/auth-login.js.map +1 -0
  95. package/dist/runtime/routes/auth-logout.d.ts +4 -0
  96. package/dist/runtime/routes/auth-logout.d.ts.map +1 -0
  97. package/dist/runtime/routes/auth-logout.js +47 -0
  98. package/dist/runtime/routes/auth-logout.js.map +1 -0
  99. package/dist/runtime/routes/auth-session.d.ts +3 -0
  100. package/dist/runtime/routes/auth-session.d.ts.map +1 -0
  101. package/dist/runtime/routes/auth-session.js +8 -0
  102. package/dist/runtime/routes/auth-session.js.map +1 -0
  103. package/dist/runtime/routes/collection-list.d.ts +3 -0
  104. package/dist/runtime/routes/collection-list.d.ts.map +1 -0
  105. package/dist/runtime/routes/collection-list.js +420 -0
  106. package/dist/runtime/routes/collection-list.js.map +1 -0
  107. package/dist/runtime/routes/collections-metadata.d.ts +3 -0
  108. package/dist/runtime/routes/collections-metadata.d.ts.map +1 -0
  109. package/dist/runtime/routes/collections-metadata.js +17 -0
  110. package/dist/runtime/routes/collections-metadata.js.map +1 -0
  111. package/dist/runtime/routes/editor-assets.d.ts +3 -0
  112. package/dist/runtime/routes/editor-assets.d.ts.map +1 -0
  113. package/dist/runtime/routes/editor-assets.js +73 -0
  114. package/dist/runtime/routes/editor-assets.js.map +1 -0
  115. package/dist/runtime/routes/entries.d.ts +3 -0
  116. package/dist/runtime/routes/entries.d.ts.map +1 -0
  117. package/dist/runtime/routes/entries.js +96 -0
  118. package/dist/runtime/routes/entries.js.map +1 -0
  119. package/dist/runtime/routes/history.d.ts +4 -0
  120. package/dist/runtime/routes/history.d.ts.map +1 -0
  121. package/dist/runtime/routes/history.js +54 -0
  122. package/dist/runtime/routes/history.js.map +1 -0
  123. package/dist/runtime/routes/mutate.d.ts +4 -0
  124. package/dist/runtime/routes/mutate.d.ts.map +1 -0
  125. package/dist/runtime/routes/mutate.js +38 -0
  126. package/dist/runtime/routes/mutate.js.map +1 -0
  127. package/dist/runtime/routes/schema.d.ts +3 -0
  128. package/dist/runtime/routes/schema.d.ts.map +1 -0
  129. package/dist/runtime/routes/schema.js +58 -0
  130. package/dist/runtime/routes/schema.js.map +1 -0
  131. package/dist/runtime/routes/studio-home.d.ts +3 -0
  132. package/dist/runtime/routes/studio-home.d.ts.map +1 -0
  133. package/dist/runtime/routes/studio-home.js +99 -0
  134. package/dist/runtime/routes/studio-home.js.map +1 -0
  135. package/dist/runtime/routes/theme-stylesheet.d.ts +3 -0
  136. package/dist/runtime/routes/theme-stylesheet.d.ts.map +1 -0
  137. package/dist/runtime/routes/theme-stylesheet.js +32 -0
  138. package/dist/runtime/routes/theme-stylesheet.js.map +1 -0
  139. package/dist/runtime/routes/upload.d.ts +3 -0
  140. package/dist/runtime/routes/upload.d.ts.map +1 -0
  141. package/dist/runtime/routes/upload.js +33 -0
  142. package/dist/runtime/routes/upload.js.map +1 -0
  143. package/dist/runtime/sanitize-html.d.ts +8 -0
  144. package/dist/runtime/sanitize-html.d.ts.map +1 -0
  145. package/dist/runtime/sanitize-html.js +86 -0
  146. package/dist/runtime/sanitize-html.js.map +1 -0
  147. package/dist/runtime/schema/template.d.ts +15 -0
  148. package/dist/runtime/schema/template.d.ts.map +1 -0
  149. package/dist/runtime/schema/template.js +38 -0
  150. package/dist/runtime/schema/template.js.map +1 -0
  151. package/dist/runtime/schema-registry.d.ts +17 -0
  152. package/dist/runtime/schema-registry.d.ts.map +1 -0
  153. package/dist/runtime/schema-registry.js +16 -0
  154. package/dist/runtime/schema-registry.js.map +1 -0
  155. package/dist/runtime/storage/filesystem-adapter.d.ts +36 -0
  156. package/dist/runtime/storage/filesystem-adapter.d.ts.map +1 -0
  157. package/dist/runtime/storage/filesystem-adapter.js +291 -0
  158. package/dist/runtime/storage/filesystem-adapter.js.map +1 -0
  159. package/dist/runtime/storage/filesystem-upload-handler.d.ts +11 -0
  160. package/dist/runtime/storage/filesystem-upload-handler.d.ts.map +1 -0
  161. package/dist/runtime/storage/filesystem-upload-handler.js +20 -0
  162. package/dist/runtime/storage/filesystem-upload-handler.js.map +1 -0
  163. package/dist/runtime/storage/image-validation.d.ts +28 -0
  164. package/dist/runtime/storage/image-validation.d.ts.map +1 -0
  165. package/dist/runtime/storage/image-validation.js +94 -0
  166. package/dist/runtime/storage/image-validation.js.map +1 -0
  167. package/dist/runtime/storage/in-memory-adapter.d.ts +29 -0
  168. package/dist/runtime/storage/in-memory-adapter.d.ts.map +1 -0
  169. package/dist/runtime/storage/in-memory-adapter.js +110 -0
  170. package/dist/runtime/storage/in-memory-adapter.js.map +1 -0
  171. package/dist/runtime/storage/quota-upload-handler.d.ts +27 -0
  172. package/dist/runtime/storage/quota-upload-handler.d.ts.map +1 -0
  173. package/dist/runtime/storage/quota-upload-handler.js +34 -0
  174. package/dist/runtime/storage/quota-upload-handler.js.map +1 -0
  175. package/dist/runtime/storage/session-overlay-adapter.d.ts +33 -0
  176. package/dist/runtime/storage/session-overlay-adapter.d.ts.map +1 -0
  177. package/dist/runtime/storage/session-overlay-adapter.js +121 -0
  178. package/dist/runtime/storage/session-overlay-adapter.js.map +1 -0
  179. package/dist/runtime/themes/preset-tokens.d.ts +17 -0
  180. package/dist/runtime/themes/preset-tokens.d.ts.map +1 -0
  181. package/dist/runtime/themes/preset-tokens.js +47 -0
  182. package/dist/runtime/themes/preset-tokens.js.map +1 -0
  183. package/dist/runtime/utils.d.ts +6 -0
  184. package/dist/runtime/utils.d.ts.map +1 -0
  185. package/dist/runtime/utils.js +29 -0
  186. package/dist/runtime/utils.js.map +1 -0
  187. package/dist/runtime/views/studio-layout.d.ts +25 -0
  188. package/dist/runtime/views/studio-layout.d.ts.map +1 -0
  189. package/dist/runtime/views/studio-layout.js +108 -0
  190. package/dist/runtime/views/studio-layout.js.map +1 -0
  191. package/dist/schema-utils.d.ts +16 -0
  192. package/dist/schema-utils.d.ts.map +1 -0
  193. package/dist/schema-utils.js +62 -0
  194. package/dist/schema-utils.js.map +1 -0
  195. package/dist/types.d.ts +76 -0
  196. package/dist/types.d.ts.map +1 -0
  197. package/dist/types.js +2 -0
  198. package/dist/types.js.map +1 -0
  199. package/editor-runtime.d.ts +6 -0
  200. package/editor-runtime.js +2 -0
  201. package/package.json +88 -0
  202. package/static/cms/admin-entry.css +207 -0
  203. package/static/cms/admin-entry.js +1083 -0
  204. package/static/cms/editor/config.js +118 -0
  205. package/static/cms/editor/content-map.css +141 -0
  206. package/static/cms/editor/content-map.js +172 -0
  207. package/static/cms/editor/guards.js +72 -0
  208. package/static/cms/editor/helpers.js +51 -0
  209. package/static/cms/editor/image-edit.js +151 -0
  210. package/static/cms/editor/image-utils.js +84 -0
  211. package/static/cms/editor/image.css +133 -0
  212. package/static/cms/editor/link-follow.js +144 -0
  213. package/static/cms/editor/link-ui.css +199 -0
  214. package/static/cms/editor/linkify.js +55 -0
  215. package/static/cms/editor/panel.css +91 -0
  216. package/static/cms/editor/panel.js +70 -0
  217. package/static/cms/editor/rich-toolbar.css +67 -0
  218. package/static/cms/editor/rich-toolbar.js +200 -0
  219. package/static/cms/editor/sanitize.js +89 -0
  220. package/static/cms/editor/save-queue.js +166 -0
  221. package/static/cms/editor/section-controls/activation.js +10 -0
  222. package/static/cms/editor/section-controls/api.js +87 -0
  223. package/static/cms/editor/section-controls/constants.js +24 -0
  224. package/static/cms/editor/section-controls/index.js +622 -0
  225. package/static/cms/editor/section-controls/model.js +76 -0
  226. package/static/cms/editor/section-controls/mutations.js +112 -0
  227. package/static/cms/editor/section-controls/page-context.js +34 -0
  228. package/static/cms/editor/section-controls/pickers.js +196 -0
  229. package/static/cms/editor/section-controls/reorder.js +92 -0
  230. package/static/cms/editor/section-controls/selection.js +54 -0
  231. package/static/cms/editor/section-controls/spacing-drag.js +83 -0
  232. package/static/cms/editor/section-controls/ui-elements.js +54 -0
  233. package/static/cms/editor/section-controls/utils.js +35 -0
  234. package/static/cms/editor/section-controls.css +349 -0
  235. package/static/cms/editor/section-controls.js +1 -0
  236. package/static/cms/editor/security.js +48 -0
  237. package/static/cms/editor/sync.js +72 -0
  238. package/static/cms/editor/text-edit.js +151 -0
  239. package/static/cms/editor/text-link-interactions.js +254 -0
  240. package/static/cms/editor/toast.css +50 -0
  241. package/static/cms/editor/toast.js +29 -0
  242. package/static/cms/editor/tokens-and-text.css +93 -0
  243. package/static/cms/editor/toolbar.css +249 -0
  244. package/static/cms/editor/toolbar.js +117 -0
  245. package/static/cms/editor.css +12 -0
  246. package/static/cms/editor.js +116 -0
  247. package/static/cms/studio-login.css +300 -0
  248. package/static/cms/studio-tokens.css +85 -0
  249. package/static/cms/studio.css +437 -0
@@ -0,0 +1,254 @@
1
+ import { escapeHtml } from './linkify.js';
2
+
3
+ export function createTextLinkInteractions({
4
+ state,
5
+ clientLinkify,
6
+ showToast,
7
+ snapshots,
8
+ }) {
9
+ let activePopover = null;
10
+ let activeLinkHint = null;
11
+
12
+ function removeLinkHint() {
13
+ if (activeLinkHint) {
14
+ activeLinkHint.remove();
15
+ activeLinkHint = null;
16
+ }
17
+ }
18
+
19
+ function dismissLinkPopup() {
20
+ if (activePopover) {
21
+ activePopover.remove();
22
+ activePopover = null;
23
+ }
24
+ state.linkPopupEl = null;
25
+ }
26
+
27
+ function showLinkPopup(rect, initialUrl, onApply) {
28
+ dismissLinkPopup();
29
+
30
+ const popover = document.createElement('div');
31
+ popover.className = 'cms-link-popover';
32
+ popover.innerHTML = `
33
+ <div class="cms-link-popover-row">
34
+ <svg class="cms-link-popover-icon" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
35
+ <path d="M10 13a5 5 0 007.54.54l3-3a5 5 0 00-7.07-7.07l-1.72 1.71"/>
36
+ <path d="M14 11a5 5 0 00-7.54-.54l-3 3a5 5 0 007.07 7.07l1.71-1.71"/>
37
+ </svg>
38
+ <input type="text" class="cms-link-popover-input" placeholder="Paste URL or path (e.g. /contact)" value="${escapeHtml(initialUrl)}" />
39
+ </div>
40
+ <div class="cms-link-popover-actions">
41
+ <span class="cms-link-popover-hint">${navigator.platform.includes('Mac') ? '\u2318' : 'Ctrl'}+K</span>
42
+ <div class="cms-link-popover-btns">
43
+ <button type="button" class="cms-link-popover-cancel">Cancel</button>
44
+ <button type="button" class="cms-link-popover-apply">Apply</button>
45
+ </div>
46
+ </div>
47
+ `;
48
+
49
+ document.body.appendChild(popover);
50
+ activePopover = popover;
51
+
52
+ const popW = 340;
53
+ let left = rect.left + rect.width / 2 - popW / 2;
54
+ left = Math.max(8, Math.min(left, window.innerWidth - popW - 8));
55
+ let top = rect.bottom + 8;
56
+ if (top + 120 > window.innerHeight) {
57
+ top = rect.top - 120;
58
+ }
59
+ popover.style.left = `${left}px`;
60
+ popover.style.top = `${top}px`;
61
+
62
+ const input = popover.querySelector('.cms-link-popover-input');
63
+ const applyBtn = popover.querySelector('.cms-link-popover-apply');
64
+ const cancelBtn = popover.querySelector('.cms-link-popover-cancel');
65
+
66
+ requestAnimationFrame(() => input.focus());
67
+ if (initialUrl) input.select();
68
+
69
+ function apply() {
70
+ const url = input.value.trim();
71
+ dismissLinkPopup();
72
+ onApply(url);
73
+ }
74
+
75
+ function cancel() {
76
+ dismissLinkPopup();
77
+ onApply(null);
78
+ }
79
+
80
+ applyBtn.addEventListener('click', apply);
81
+ cancelBtn.addEventListener('click', cancel);
82
+
83
+ input.addEventListener('keydown', (e) => {
84
+ if (e.key === 'Enter') {
85
+ e.preventDefault();
86
+ apply();
87
+ }
88
+ if (e.key === 'Escape') {
89
+ e.preventDefault();
90
+ cancel();
91
+ }
92
+ });
93
+
94
+ setTimeout(() => {
95
+ function onDocClick(e) {
96
+ if (!popover.contains(e.target)) {
97
+ document.removeEventListener('click', onDocClick, true);
98
+ cancel();
99
+ }
100
+ }
101
+ document.addEventListener('click', onDocClick, true);
102
+ }, 0);
103
+ }
104
+
105
+ function showLinkHint(el) {
106
+ removeLinkHint();
107
+ const hint = document.createElement('div');
108
+ hint.className = 'cms-link-hint';
109
+ hint.textContent = `${navigator.platform.includes('Mac') ? '\u2318' : 'Ctrl'}+K to link`;
110
+ document.body.appendChild(hint);
111
+ activeLinkHint = hint;
112
+
113
+ const rect = el.getBoundingClientRect();
114
+ hint.style.top = `${rect.top - 28}px`;
115
+ hint.style.left = `${rect.right - hint.offsetWidth}px`;
116
+ }
117
+
118
+ function onKeydown(e) {
119
+ const focused = document.activeElement;
120
+
121
+ // Ctrl+S / Cmd+S — save focused element by triggering blur save
122
+ if ((e.ctrlKey || e.metaKey) && e.key === 's') {
123
+ e.preventDefault();
124
+ if (focused && focused.matches('[data-caret]')) {
125
+ focused.blur();
126
+ }
127
+ return;
128
+ }
129
+
130
+ // Ctrl+K / Cmd+K — insert link in a rich or linkable field
131
+ if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
132
+ if (focused && focused.matches('[data-caret]') && focused.hasAttribute('data-caret-rich')) {
133
+ // Rich text mode — use execCommand('createLink')
134
+ e.preventDefault();
135
+ const sel = window.getSelection();
136
+ if (!sel || sel.isCollapsed) return;
137
+
138
+ const selectedText = sel.toString();
139
+ if (!selectedText.trim()) return;
140
+
141
+ const range = sel.getRangeAt(0).cloneRange();
142
+ const selRect = range.getBoundingClientRect();
143
+
144
+ // Check if selection is already a link
145
+ const anchorNode = sel.anchorNode;
146
+ const existingLink = anchorNode?.nodeType === Node.TEXT_NODE
147
+ ? anchorNode.parentElement?.closest('a')
148
+ : anchorNode instanceof Element ? anchorNode.closest('a') : null;
149
+ const initialUrl = existingLink?.getAttribute('href') || '';
150
+
151
+ state.linkPopupEl = focused;
152
+
153
+ showLinkPopup(selRect, initialUrl, (url) => {
154
+ focused.focus();
155
+
156
+ if (url) {
157
+ const newSel = window.getSelection();
158
+ newSel.removeAllRanges();
159
+ newSel.addRange(range);
160
+
161
+ if (existingLink) {
162
+ existingLink.setAttribute('href', url);
163
+ } else {
164
+ document.execCommand('createLink', false, url);
165
+ }
166
+
167
+ // Set security attrs on external links
168
+ const freshSel = window.getSelection();
169
+ if (freshSel && freshSel.anchorNode) {
170
+ const textNode = freshSel.anchorNode;
171
+ const newLink = textNode.nodeType === Node.TEXT_NODE
172
+ ? textNode.parentElement?.closest('a')
173
+ : textNode instanceof Element ? textNode.closest('a') : null;
174
+ if (newLink && /^https?:/i.test(url)) {
175
+ newLink.setAttribute('target', '_blank');
176
+ newLink.setAttribute('rel', 'noopener noreferrer');
177
+ }
178
+ }
179
+
180
+ state.dirtyEl = focused;
181
+ } else if (url === '' && existingLink) {
182
+ document.execCommand('unlink', false, null);
183
+ state.dirtyEl = focused;
184
+ }
185
+
186
+ state.linkPopupEl = null;
187
+ });
188
+ return;
189
+ }
190
+
191
+ if (focused && focused.matches('[data-caret]') && focused.hasAttribute('data-caret-raw')) {
192
+ e.preventDefault();
193
+ const sel = window.getSelection();
194
+ if (!sel || sel.isCollapsed) return;
195
+
196
+ const selectedText = sel.toString();
197
+ if (!selectedText.trim()) return;
198
+
199
+ const range = sel.getRangeAt(0).cloneRange();
200
+ const selRect = range.getBoundingClientRect();
201
+ state.linkPopupEl = focused;
202
+
203
+ showLinkPopup(selRect, '', (url) => {
204
+ focused.focus();
205
+
206
+ if (url) {
207
+ const newSel = window.getSelection();
208
+ newSel.removeAllRanges();
209
+ newSel.addRange(range);
210
+ document.execCommand('insertText', false, `[${selectedText}](${url})`);
211
+ state.dirtyEl = focused;
212
+ }
213
+
214
+ state.linkPopupEl = null;
215
+ });
216
+ }
217
+ return;
218
+ }
219
+
220
+ // Escape — revert to snapshot and blur without saving
221
+ if (e.key === 'Escape') {
222
+ if (activePopover) return;
223
+
224
+ if (focused && focused.matches('[data-caret]')) {
225
+ e.preventDefault();
226
+ const snapshot = snapshots.get(focused);
227
+ if (snapshot !== undefined) {
228
+ const isRich = focused.hasAttribute('data-caret-rich');
229
+ const isLinkable = focused.hasAttribute('data-caret-raw');
230
+ if (isRich) {
231
+ focused.innerHTML = snapshot;
232
+ } else if (isLinkable) {
233
+ focused.innerHTML = clientLinkify(snapshot);
234
+ focused.setAttribute('data-caret-raw', snapshot);
235
+ } else {
236
+ focused.textContent = snapshot;
237
+ }
238
+ state.dirtyEl = null;
239
+ }
240
+ focused._caretSkipSave = true;
241
+ focused.blur();
242
+ removeLinkHint();
243
+ showToast('Edit cancelled', 'success');
244
+ }
245
+ }
246
+ }
247
+
248
+ return {
249
+ onKeydown,
250
+ showLinkHint,
251
+ removeLinkHint,
252
+ showLinkPopup,
253
+ };
254
+ }
@@ -0,0 +1,50 @@
1
+ /* ---------------------------------------------------------------------------
2
+ Toast notifications
3
+ --------------------------------------------------------------------------- */
4
+
5
+ .cms-toast {
6
+ position: fixed;
7
+ bottom: 62px;
8
+ right: 24px;
9
+ z-index: 100000;
10
+ display: flex;
11
+ align-items: center;
12
+ gap: 10px;
13
+ padding: 12px 20px;
14
+ background: var(--cms-surface);
15
+ border: 1px solid rgba(255, 255, 255, 0.06);
16
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
17
+ font-family: var(--cms-font);
18
+ font-size: 12px;
19
+ color: rgba(255, 255, 255, 0.8);
20
+ border-radius: 2px;
21
+ opacity: 0;
22
+ transform: translateY(8px) scale(0.98);
23
+ animation: cms-toast-in 0.3s ease forwards;
24
+ pointer-events: none;
25
+ }
26
+
27
+ .cms-toast.cms-toast-out {
28
+ animation: cms-toast-out 0.3s ease forwards;
29
+ }
30
+
31
+ .cms-toast-icon {
32
+ width: 16px;
33
+ height: 16px;
34
+ flex-shrink: 0;
35
+ }
36
+
37
+ .cms-toast-success { border-left: 3px solid var(--cms-green); }
38
+ .cms-toast-success .cms-toast-icon { color: var(--cms-green); }
39
+
40
+ .cms-toast-error { border-left: 3px solid var(--cms-red); }
41
+ .cms-toast-error .cms-toast-icon { color: var(--cms-red); }
42
+
43
+ @keyframes cms-toast-in {
44
+ to { opacity: 1; transform: translateY(0) scale(1); }
45
+ }
46
+
47
+ @keyframes cms-toast-out {
48
+ to { opacity: 0; transform: translateY(12px) scale(0.98); }
49
+ }
50
+
@@ -0,0 +1,29 @@
1
+ export function createToast() {
2
+ let activeToast = null;
3
+
4
+ return function showToast(message, type) {
5
+ if (activeToast) {
6
+ activeToast.remove();
7
+ }
8
+
9
+ const toast = document.createElement('div');
10
+ toast.className = `cms-toast cms-toast-${type}`;
11
+
12
+ const iconSvg =
13
+ type === 'success'
14
+ ? '<svg class="cms-toast-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6L9 17l-5-5"/></svg>'
15
+ : '<svg class="cms-toast-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>';
16
+
17
+ toast.innerHTML = iconSvg + `<span>${message}</span>`;
18
+ document.body.appendChild(toast);
19
+ activeToast = toast;
20
+
21
+ setTimeout(() => {
22
+ toast.classList.add('cms-toast-out');
23
+ setTimeout(() => {
24
+ toast.remove();
25
+ if (activeToast === toast) activeToast = null;
26
+ }, 300);
27
+ }, 2500);
28
+ };
29
+ }
@@ -0,0 +1,93 @@
1
+ /* ========================================================================
2
+ CMS Editor Styles — only loaded when isEditor = true
3
+ ======================================================================== */
4
+
5
+ /* ---------------------------------------------------------------------------
6
+ CSS Custom Properties
7
+ --------------------------------------------------------------------------- */
8
+
9
+ :root {
10
+ --cms-blue: rgba(59, 130, 246, 0.8);
11
+ --cms-blue-dim: rgba(59, 130, 246, 0.1);
12
+ --cms-blue-hover: rgba(59, 130, 246, 0.4);
13
+ --cms-surface: #14171c;
14
+ --cms-accent: #3b82f6;
15
+ --cms-accent-soft: rgba(59, 130, 246, 0.15);
16
+ --cms-green: #22c55e;
17
+ --cms-red: #ef4444;
18
+ --cms-yellow: #eab308;
19
+ --cms-font: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
20
+ }
21
+
22
+ /* ---------------------------------------------------------------------------
23
+ Text editing affordances — simple blue outline
24
+ --------------------------------------------------------------------------- */
25
+
26
+ [data-caret].cms-editable {
27
+ cursor: text;
28
+ transition: outline 0.2s, box-shadow 0.2s;
29
+ outline: 2px dashed transparent;
30
+ outline-offset: 4px;
31
+ border-radius: 2px;
32
+ }
33
+
34
+ [data-caret].cms-editable:hover {
35
+ outline-color: var(--cms-blue-hover);
36
+ }
37
+
38
+ [data-caret].cms-editable:focus {
39
+ outline: 2px solid var(--cms-blue);
40
+ outline-offset: 4px;
41
+ box-shadow: 0 0 0 4px var(--cms-blue-dim);
42
+ }
43
+
44
+ /* ---------------------------------------------------------------------------
45
+ Link/button click prevention in editor mode
46
+ --------------------------------------------------------------------------- */
47
+
48
+ .cms-edit-mode a[data-caret],
49
+ .cms-edit-mode button[data-caret],
50
+ .cms-edit-mode [data-caret] a,
51
+ .cms-edit-mode [data-caret] button {
52
+ pointer-events: auto;
53
+ }
54
+
55
+ /* CMS-editable links get text cursor; non-CMS links keep pointer for navigation */
56
+ .cms-edit-mode a[data-caret],
57
+ .cms-edit-mode a:has([data-caret]) {
58
+ cursor: text;
59
+ }
60
+
61
+ /* ---------------------------------------------------------------------------
62
+ Save / error feedback
63
+ --------------------------------------------------------------------------- */
64
+
65
+ .cms-saving {
66
+ outline-color: var(--cms-yellow) !important;
67
+ }
68
+
69
+ .cms-saved {
70
+ animation: cms-flash-green 1.5s ease-out;
71
+ }
72
+
73
+ .cms-error {
74
+ animation: cms-flash-red 1.5s ease-out;
75
+ }
76
+
77
+ @keyframes cms-flash-green {
78
+ 0% { outline: 2px solid var(--cms-green); outline-offset: 4px; }
79
+ 100% { outline: 2px solid transparent; outline-offset: 4px; }
80
+ }
81
+
82
+ @keyframes cms-flash-red {
83
+ 0% { outline: 2px solid var(--cms-red); outline-offset: 4px; }
84
+ 100% { outline: 2px solid transparent; outline-offset: 4px; }
85
+ }
86
+
87
+ /* ---------------------------------------------------------------------------
88
+ Invisible overlays — prevent hover-state duplicates from blocking editing
89
+ --------------------------------------------------------------------------- */
90
+
91
+ .cms-edit-mode .opacity-0 {
92
+ pointer-events: none !important;
93
+ }
@@ -0,0 +1,249 @@
1
+ /* ---------------------------------------------------------------------------
2
+ Toolbar — fixed bottom bar
3
+ --------------------------------------------------------------------------- */
4
+
5
+ .cms-toolbar {
6
+ position: fixed;
7
+ bottom: 0;
8
+ left: 0;
9
+ right: 0;
10
+ z-index: 99999;
11
+ font-family: var(--cms-font);
12
+ font-size: 12px;
13
+ opacity: 0;
14
+ transform: translateY(100%);
15
+ animation: cms-toolbar-enter 0.5s cubic-bezier(0.16, 1, 0.3, 1) 0.3s forwards;
16
+ }
17
+
18
+ /* Insulate the toolbar from consumer page resets: every descendant uses
19
+ border-box so padding doesn't expand widths, and inherits our font stack so
20
+ user-agent defaults on <button> can't bleed through. */
21
+ .cms-toolbar,
22
+ .cms-toolbar *,
23
+ .cms-toolbar *::before,
24
+ .cms-toolbar *::after {
25
+ box-sizing: border-box;
26
+ }
27
+
28
+ .cms-toolbar-inner {
29
+ display: flex;
30
+ align-items: center;
31
+ justify-content: space-between;
32
+ background: var(--cms-surface);
33
+ border-top: 1px solid rgba(59, 130, 246, 0.15);
34
+ box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.3);
35
+ max-width: 100%;
36
+ padding: 0 24px;
37
+ height: 48px;
38
+ }
39
+
40
+ .cms-toolbar-left {
41
+ display: flex;
42
+ align-items: center;
43
+ gap: 12px;
44
+ }
45
+
46
+ .cms-toolbar-badge {
47
+ display: flex;
48
+ align-items: center;
49
+ gap: 8px;
50
+ padding: 5px 14px;
51
+ background: var(--cms-accent-soft);
52
+ border: 1px solid rgba(59, 130, 246, 0.2);
53
+ border-radius: 2px;
54
+ }
55
+
56
+ .cms-toolbar-badge svg {
57
+ width: 14px;
58
+ height: 14px;
59
+ color: var(--cms-accent);
60
+ }
61
+
62
+ .cms-toolbar-badge-text {
63
+ color: var(--cms-accent);
64
+ font-size: 10px;
65
+ font-weight: 600;
66
+ letter-spacing: 0.15em;
67
+ text-transform: uppercase;
68
+ }
69
+
70
+ .cms-toolbar-divider {
71
+ width: 1px;
72
+ height: 20px;
73
+ background: rgba(255, 255, 255, 0.08);
74
+ margin: 0 4px;
75
+ }
76
+
77
+ .cms-toolbar-right {
78
+ display: flex;
79
+ align-items: center;
80
+ gap: 12px;
81
+ }
82
+
83
+ /* Shared base for every toolbar button so they can't drift visually. Individual
84
+ button classes below only override colors/borders. */
85
+ .cms-toolbar button {
86
+ display: inline-flex;
87
+ align-items: center;
88
+ gap: 6px;
89
+ padding: 6px 14px;
90
+ font-family: var(--cms-font);
91
+ font-size: 10px;
92
+ font-weight: 500;
93
+ line-height: 1.2;
94
+ letter-spacing: 0.12em;
95
+ text-transform: uppercase;
96
+ background: transparent;
97
+ color: rgba(255, 255, 255, 0.5);
98
+ border: 1px solid rgba(255, 255, 255, 0.1);
99
+ border-radius: 2px;
100
+ cursor: pointer;
101
+ transition: background 0.2s, border-color 0.2s, color 0.2s;
102
+ white-space: nowrap;
103
+ }
104
+
105
+ .cms-toolbar button:hover {
106
+ background: rgba(59, 130, 246, 0.08);
107
+ border-color: rgba(59, 130, 246, 0.3);
108
+ color: rgba(255, 255, 255, 0.85);
109
+ }
110
+
111
+ .cms-toolbar button svg {
112
+ width: 12px;
113
+ height: 12px;
114
+ flex-shrink: 0;
115
+ }
116
+
117
+ /* Status indicator */
118
+ .cms-status-group {
119
+ display: flex;
120
+ align-items: center;
121
+ gap: 8px;
122
+ }
123
+
124
+ .cms-status-dot {
125
+ width: 7px;
126
+ height: 7px;
127
+ border-radius: 50%;
128
+ transition: background-color 0.3s, box-shadow 0.3s;
129
+ }
130
+
131
+ .cms-status-idle {
132
+ background-color: var(--cms-green);
133
+ box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
134
+ }
135
+
136
+ .cms-status-saving {
137
+ background-color: var(--cms-yellow);
138
+ box-shadow: 0 0 6px rgba(234, 179, 8, 0.4);
139
+ animation: cms-dot-pulse 1s ease-in-out infinite;
140
+ }
141
+
142
+ .cms-status-error {
143
+ background-color: var(--cms-red);
144
+ box-shadow: 0 0 6px rgba(239, 68, 68, 0.4);
145
+ }
146
+
147
+ @keyframes cms-dot-pulse {
148
+ 0%, 100% { opacity: 1; }
149
+ 50% { opacity: 0.3; }
150
+ }
151
+
152
+ .cms-status-text {
153
+ color: rgba(255, 255, 255, 0.5);
154
+ font-size: 11px;
155
+ font-weight: 400;
156
+ }
157
+
158
+ /* Content Studio toggle — accent-colored */
159
+ .cms-toolbar button.cms-studio-btn {
160
+ background: var(--cms-accent-soft);
161
+ color: var(--cms-accent);
162
+ border-color: rgba(59, 130, 246, 0.2);
163
+ }
164
+
165
+ .cms-toolbar button.cms-studio-btn:hover {
166
+ background: rgba(59, 130, 246, 0.25);
167
+ border-color: rgba(59, 130, 246, 0.4);
168
+ color: var(--cms-accent);
169
+ }
170
+
171
+ /* Highlight-all active state */
172
+ .cms-toolbar button.cms-highlight-btn-active {
173
+ background: rgba(59, 130, 246, 0.12);
174
+ border-color: rgba(59, 130, 246, 0.4);
175
+ color: rgba(59, 130, 246, 0.9);
176
+ }
177
+
178
+ /* Highlight all mode — show every editable region */
179
+ .cms-highlight-all [data-caret].cms-editable {
180
+ outline-color: var(--cms-blue-hover);
181
+ background: rgba(59, 130, 246, 0.04);
182
+ }
183
+
184
+ .cms-highlight-all img[data-caret] {
185
+ outline: 2px dashed rgba(59, 130, 246, 0.4);
186
+ outline-offset: 4px;
187
+ }
188
+
189
+ /* ---------------------------------------------------------------------------
190
+ Toolbar — page navigation links
191
+ --------------------------------------------------------------------------- */
192
+
193
+ .cms-toolbar-nav {
194
+ display: none;
195
+ align-items: center;
196
+ gap: 2px;
197
+ }
198
+
199
+ @media (min-width: 768px) {
200
+ .cms-toolbar-nav {
201
+ display: flex;
202
+ }
203
+ }
204
+
205
+ .cms-nav-link {
206
+ padding: 5px 14px;
207
+ font-size: 10px;
208
+ letter-spacing: 0.1em;
209
+ text-transform: uppercase;
210
+ text-decoration: none;
211
+ color: rgba(255, 255, 255, 0.35);
212
+ transition: color 0.15s, background 0.15s;
213
+ border-radius: 2px;
214
+ white-space: nowrap;
215
+ }
216
+
217
+ .cms-nav-link:hover {
218
+ color: rgba(255, 255, 255, 0.7);
219
+ background: rgba(255, 255, 255, 0.04);
220
+ }
221
+
222
+ .cms-nav-link.active {
223
+ color: var(--cms-accent);
224
+ background: var(--cms-accent-soft);
225
+ }
226
+
227
+ /* Exit — red on hover */
228
+ .cms-toolbar button.cms-exit-btn:hover {
229
+ background: rgba(248, 113, 113, 0.08);
230
+ border-color: rgba(248, 113, 113, 0.3);
231
+ color: var(--cms-red);
232
+ }
233
+
234
+ /* Account for toolbar height */
235
+ body:has(.cms-toolbar) {
236
+ padding-bottom: 48px;
237
+ }
238
+
239
+ /* Shift back-to-top button above toolbar */
240
+ body:has(.cms-toolbar) #back-to-top {
241
+ bottom: 60px;
242
+ }
243
+
244
+ @keyframes cms-toolbar-enter {
245
+ to {
246
+ opacity: 1;
247
+ transform: translateY(0);
248
+ }
249
+ }