@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,35 @@
1
+ import { SPACING_Y_VALUES } from './constants.js';
2
+
3
+ export function humanizeSectionKey(key) {
4
+ const short = key.startsWith('home.') ? key.slice('home.'.length) : key;
5
+ return short.replace(/_/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase());
6
+ }
7
+
8
+ export function normalizeSpacingY(value) {
9
+ if (typeof value !== 'string') return undefined;
10
+ return SPACING_Y_VALUES.includes(value) && value !== 'default' ? value : undefined;
11
+ }
12
+
13
+ export function spacingToken(value) {
14
+ return normalizeSpacingY(value) || 'default';
15
+ }
16
+
17
+ export function spacingIndex(value) {
18
+ const idx = SPACING_Y_VALUES.indexOf(spacingToken(value));
19
+ return idx === -1 ? 0 : idx;
20
+ }
21
+
22
+ export function spacingButtonLabel(value) {
23
+ const token = spacingToken(value);
24
+ return token === 'default' ? 'Space' : `Space:${token}`;
25
+ }
26
+
27
+ export function isRecord(value) {
28
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
29
+ }
30
+
31
+ export function generateSectionId(key) {
32
+ return `sec-${key.replace(/\./g, '-')}-${Date.now().toString(36)}-${Math.random()
33
+ .toString(36)
34
+ .slice(2, 6)}`;
35
+ }
@@ -0,0 +1,349 @@
1
+ /* ---------------------------------------------------------------------------
2
+ Section controls (on-canvas layout actions)
3
+ --------------------------------------------------------------------------- */
4
+
5
+ .cms-section-editable {
6
+ outline: 2px dashed transparent;
7
+ outline-offset: 2px;
8
+ transition: outline-color 0.2s ease, box-shadow 0.2s ease;
9
+ }
10
+
11
+ .cms-section-editable:hover {
12
+ outline-color: rgba(59, 130, 246, 0.45);
13
+ }
14
+
15
+ .cms-section-editable.cms-section-active {
16
+ outline-color: rgba(59, 130, 246, 0.85);
17
+ box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.28);
18
+ }
19
+
20
+ .cms-section-editable.cms-section-disabled-preview {
21
+ opacity: 0.58;
22
+ }
23
+
24
+ .cms-section-editable.cms-section-disabled-preview .cms-section-controls,
25
+ .cms-section-editable.cms-section-disabled-preview .cms-section-chip {
26
+ opacity: 1;
27
+ transform: translateY(0);
28
+ pointer-events: auto;
29
+ }
30
+
31
+ .cms-highlight-all .cms-section-editable {
32
+ outline-color: rgba(59, 130, 246, 0.35);
33
+ }
34
+
35
+ .cms-section-controls {
36
+ position: absolute;
37
+ top: 12px;
38
+ right: 12px;
39
+ z-index: 1200;
40
+ display: flex;
41
+ align-items: center;
42
+ gap: 10px;
43
+ padding: 6px 8px;
44
+ border-radius: 6px;
45
+ background: rgba(20, 23, 28, 0.9);
46
+ border: 1px solid rgba(59, 130, 246, 0.22);
47
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
48
+ backdrop-filter: blur(4px);
49
+ opacity: 0;
50
+ transform: translateY(-4px);
51
+ transition: opacity 0.18s ease, transform 0.18s ease;
52
+ pointer-events: none;
53
+ }
54
+
55
+ .cms-section-editable:hover .cms-section-controls,
56
+ .cms-section-editable.cms-section-active .cms-section-controls,
57
+ .cms-section-controls:focus-within {
58
+ opacity: 1;
59
+ transform: translateY(0);
60
+ pointer-events: auto;
61
+ }
62
+
63
+ .cms-section-chip {
64
+ position: absolute;
65
+ top: 12px;
66
+ left: 12px;
67
+ z-index: 1198;
68
+ padding: 4px 8px;
69
+ border-radius: 999px;
70
+ font-family: var(--cms-font);
71
+ font-size: 9px;
72
+ font-weight: 700;
73
+ letter-spacing: 0.08em;
74
+ text-transform: uppercase;
75
+ border: 1px solid rgba(59, 130, 246, 0.28);
76
+ background: rgba(12, 14, 18, 0.88);
77
+ color: rgba(255, 255, 255, 0.75);
78
+ opacity: 0;
79
+ transform: translateY(-4px);
80
+ transition: opacity 0.16s ease, transform 0.16s ease, border-color 0.16s ease;
81
+ pointer-events: none;
82
+ }
83
+
84
+ .cms-section-editable:hover .cms-section-chip,
85
+ .cms-section-editable.cms-section-active .cms-section-chip,
86
+ .cms-highlight-all .cms-section-chip {
87
+ opacity: 1;
88
+ transform: translateY(0);
89
+ }
90
+
91
+ .cms-section-editable.cms-section-active .cms-section-chip {
92
+ border-color: rgba(59, 130, 246, 0.65);
93
+ color: var(--cms-accent);
94
+ }
95
+
96
+ .cms-section-controls-actions {
97
+ display: flex;
98
+ align-items: center;
99
+ gap: 4px;
100
+ }
101
+
102
+ .cms-section-btn {
103
+ border: 1px solid rgba(255, 255, 255, 0.15);
104
+ background: rgba(255, 255, 255, 0.03);
105
+ color: rgba(255, 255, 255, 0.76);
106
+ font-family: var(--cms-font);
107
+ font-size: 9px;
108
+ font-weight: 600;
109
+ letter-spacing: 0.08em;
110
+ text-transform: uppercase;
111
+ border-radius: 4px;
112
+ padding: 5px 7px;
113
+ cursor: pointer;
114
+ transition: all 0.16s ease;
115
+ }
116
+
117
+ .cms-section-btn:hover {
118
+ border-color: rgba(59, 130, 246, 0.55);
119
+ color: var(--cms-accent);
120
+ background: rgba(59, 130, 246, 0.1);
121
+ }
122
+
123
+ .cms-section-btn-drag {
124
+ cursor: grab;
125
+ }
126
+
127
+ .cms-section-btn-drag:active {
128
+ cursor: grabbing;
129
+ }
130
+
131
+ .cms-section-btn:disabled {
132
+ opacity: 0.4;
133
+ cursor: wait;
134
+ }
135
+
136
+ .cms-section-drag-source {
137
+ outline-color: rgba(59, 130, 246, 0.6) !important;
138
+ box-shadow: inset 0 0 0 2px rgba(59, 130, 246, 0.25);
139
+ }
140
+
141
+ .cms-section-drop-target {
142
+ outline-color: rgba(59, 130, 246, 0.75) !important;
143
+ }
144
+
145
+ .cms-section-drop-before {
146
+ box-shadow: inset 0 4px 0 0 rgba(59, 130, 246, 0.8);
147
+ }
148
+
149
+ .cms-section-drop-after {
150
+ box-shadow: inset 0 -4px 0 0 rgba(59, 130, 246, 0.8);
151
+ }
152
+
153
+ body.cms-section-dragging .cms-section-controls {
154
+ opacity: 1;
155
+ pointer-events: none;
156
+ }
157
+
158
+ .cms-section-boundary-actions {
159
+ position: absolute;
160
+ left: 50%;
161
+ bottom: -15px;
162
+ transform: translateX(-50%);
163
+ z-index: 1190;
164
+ display: flex;
165
+ align-items: center;
166
+ gap: 6px;
167
+ opacity: 0;
168
+ pointer-events: none;
169
+ transition: opacity 0.16s ease;
170
+ }
171
+
172
+ .cms-section-editable:hover .cms-section-boundary-actions,
173
+ .cms-section-editable.cms-section-active .cms-section-boundary-actions,
174
+ body.cms-spacing-dragging .cms-section-boundary-actions {
175
+ opacity: 1;
176
+ pointer-events: auto;
177
+ }
178
+
179
+ .cms-section-insert-handle {
180
+ width: 28px;
181
+ height: 28px;
182
+ border-radius: 999px;
183
+ border: 1px solid rgba(59, 130, 246, 0.5);
184
+ background: rgba(12, 14, 18, 0.96);
185
+ color: var(--cms-accent);
186
+ display: inline-flex;
187
+ align-items: center;
188
+ justify-content: center;
189
+ cursor: pointer;
190
+ box-shadow: 0 8px 18px rgba(0, 0, 0, 0.26);
191
+ transition: border-color 0.16s ease, transform 0.16s ease, background 0.16s ease;
192
+ }
193
+
194
+ .cms-section-insert-plus {
195
+ font-family: var(--cms-font);
196
+ font-size: 18px;
197
+ font-weight: 700;
198
+ line-height: 1;
199
+ transform: translateY(-1px);
200
+ }
201
+
202
+ .cms-section-insert-handle:hover {
203
+ border-color: rgba(59, 130, 246, 0.9);
204
+ background: rgba(59, 130, 246, 0.15);
205
+ transform: translateY(-1px);
206
+ }
207
+
208
+ .cms-section-gap-handle {
209
+ height: 22px;
210
+ min-width: 64px;
211
+ padding: 0 8px;
212
+ border: 1px solid rgba(59, 130, 246, 0.38);
213
+ border-radius: 999px;
214
+ background: rgba(12, 14, 18, 0.92);
215
+ color: rgba(255, 255, 255, 0.82);
216
+ display: inline-flex;
217
+ align-items: center;
218
+ justify-content: center;
219
+ gap: 6px;
220
+ font-family: var(--cms-font);
221
+ font-size: 9px;
222
+ letter-spacing: 0.08em;
223
+ text-transform: uppercase;
224
+ cursor: ns-resize;
225
+ box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
226
+ transition: border-color 0.16s ease, color 0.16s ease, background 0.16s ease;
227
+ }
228
+
229
+ .cms-section-gap-grip {
230
+ width: 10px;
231
+ height: 10px;
232
+ border-radius: 999px;
233
+ background:
234
+ radial-gradient(circle at 2px 2px, rgba(59, 130, 246, 0.9) 1.5px, transparent 1.7px),
235
+ radial-gradient(circle at 8px 2px, rgba(59, 130, 246, 0.9) 1.5px, transparent 1.7px),
236
+ radial-gradient(circle at 2px 8px, rgba(59, 130, 246, 0.9) 1.5px, transparent 1.7px),
237
+ radial-gradient(circle at 8px 8px, rgba(59, 130, 246, 0.9) 1.5px, transparent 1.7px);
238
+ }
239
+
240
+ .cms-section-gap-handle:hover,
241
+ .cms-section-gap-handle.is-dragging {
242
+ border-color: rgba(59, 130, 246, 0.75);
243
+ color: var(--cms-accent);
244
+ background: rgba(59, 130, 246, 0.1);
245
+ }
246
+
247
+ body.cms-spacing-dragging {
248
+ cursor: ns-resize;
249
+ }
250
+
251
+ body.cms-spacing-dragging * {
252
+ user-select: none !important;
253
+ }
254
+
255
+ .cms-section-add-picker {
256
+ position: fixed;
257
+ z-index: 1400;
258
+ width: 220px;
259
+ border-radius: 8px;
260
+ background: rgba(12, 14, 18, 0.97);
261
+ border: 1px solid rgba(59, 130, 246, 0.26);
262
+ box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
263
+ backdrop-filter: blur(6px);
264
+ transform: translateY(-4px);
265
+ opacity: 0;
266
+ pointer-events: none;
267
+ transition: opacity 0.16s ease, transform 0.16s ease;
268
+ }
269
+
270
+ .cms-section-add-picker.open {
271
+ opacity: 1;
272
+ transform: translateY(0);
273
+ pointer-events: auto;
274
+ }
275
+
276
+ .cms-section-add-picker-head {
277
+ padding: 10px 10px 8px;
278
+ font-size: 10px;
279
+ letter-spacing: 0.1em;
280
+ text-transform: uppercase;
281
+ color: rgba(255, 255, 255, 0.62);
282
+ border-bottom: 1px solid rgba(255, 255, 255, 0.08);
283
+ }
284
+
285
+ .cms-section-add-picker-list {
286
+ padding: 6px;
287
+ display: flex;
288
+ flex-direction: column;
289
+ gap: 4px;
290
+ }
291
+
292
+ .cms-section-add-option {
293
+ border: 1px solid rgba(255, 255, 255, 0.1);
294
+ background: rgba(255, 255, 255, 0.02);
295
+ color: rgba(255, 255, 255, 0.83);
296
+ font-family: var(--cms-font);
297
+ font-size: 10px;
298
+ text-align: left;
299
+ padding: 7px 8px;
300
+ border-radius: 5px;
301
+ cursor: pointer;
302
+ transition: all 0.15s ease;
303
+ }
304
+
305
+ .cms-section-add-option:hover {
306
+ border-color: rgba(59, 130, 246, 0.45);
307
+ color: var(--cms-accent);
308
+ background: rgba(59, 130, 246, 0.08);
309
+ }
310
+
311
+ .cms-section-add-option.active {
312
+ border-color: rgba(59, 130, 246, 0.55);
313
+ color: var(--cms-accent);
314
+ background: rgba(59, 130, 246, 0.14);
315
+ }
316
+
317
+ .cms-section-add-option:disabled {
318
+ opacity: 0.45;
319
+ cursor: wait;
320
+ }
321
+
322
+ @media (max-width: 960px) {
323
+ .cms-section-controls {
324
+ left: 10px;
325
+ right: 10px;
326
+ top: 10px;
327
+ flex-direction: column;
328
+ align-items: stretch;
329
+ gap: 6px;
330
+ }
331
+
332
+ .cms-section-controls-actions {
333
+ flex-wrap: wrap;
334
+ }
335
+
336
+ .cms-section-chip {
337
+ top: 8px;
338
+ left: 8px;
339
+ }
340
+
341
+ .cms-section-boundary-actions {
342
+ bottom: -18px;
343
+ }
344
+
345
+ .cms-section-add-picker {
346
+ width: calc(100vw - 24px);
347
+ max-width: 360px;
348
+ }
349
+ }
@@ -0,0 +1 @@
1
+ export { mountSectionControls } from './section-controls/index.js';
@@ -0,0 +1,48 @@
1
+ import { CLOUD, getCloudSessionToken, isCloudMode } from './config.js';
2
+
3
+ async function getTurnstileToken(action) {
4
+ if (typeof window.cmsGetTurnstileToken !== 'function') return null;
5
+ try {
6
+ return await window.cmsGetTurnstileToken(action);
7
+ } catch {
8
+ return null;
9
+ }
10
+ }
11
+
12
+ export async function mutateHeaders() {
13
+ const headers = { 'Content-Type': 'application/json', 'x-caret-request': '1' };
14
+ if (isCloudMode()) {
15
+ if (CLOUD?.publicToken) headers['x-caret-token'] = CLOUD.publicToken;
16
+ const sessionToken = getCloudSessionToken();
17
+ if (sessionToken) headers.Authorization = `Bearer ${sessionToken}`;
18
+ }
19
+ const token = await getTurnstileToken('cms_mutate');
20
+ if (token) {
21
+ headers['x-cms-turnstile-token'] = token;
22
+ }
23
+ return headers;
24
+ }
25
+
26
+ export function readHeaders() {
27
+ const headers = {};
28
+ if (isCloudMode()) {
29
+ if (CLOUD?.publicToken) headers['x-caret-token'] = CLOUD.publicToken;
30
+ const sessionToken = getCloudSessionToken();
31
+ if (sessionToken) headers.Authorization = `Bearer ${sessionToken}`;
32
+ }
33
+ return Object.keys(headers).length > 0 ? headers : undefined;
34
+ }
35
+
36
+ export async function uploadHeaders() {
37
+ const headers = { 'x-caret-request': '1' };
38
+ if (isCloudMode()) {
39
+ if (CLOUD?.publicToken) headers['x-caret-token'] = CLOUD.publicToken;
40
+ const sessionToken = getCloudSessionToken();
41
+ if (sessionToken) headers.Authorization = `Bearer ${sessionToken}`;
42
+ }
43
+ const token = await getTurnstileToken('cms_upload');
44
+ if (token) {
45
+ headers['x-cms-turnstile-token'] = token;
46
+ }
47
+ return headers;
48
+ }
@@ -0,0 +1,72 @@
1
+ import { sanitizeHtml } from './sanitize.js';
2
+
3
+ export function mountStudioSync({ studioIframe, state, showToast, clientLinkify }) {
4
+ if (!studioIframe) return;
5
+
6
+ window.addEventListener('message', (e) => {
7
+ // Only accept messages from our iframe
8
+ if (e.source !== studioIframe.contentWindow) return;
9
+ const msg = e.data;
10
+ if (!msg || typeof msg.type !== 'string') return;
11
+
12
+ if (msg.type === 'cms:saved') {
13
+ const { collection, id, data } = msg;
14
+ if (!data || typeof data !== 'object') return;
15
+
16
+ let updated = 0;
17
+
18
+ function walkData(obj, prefix) {
19
+ for (const [key, value] of Object.entries(obj)) {
20
+ const path = prefix ? `${prefix}.${key}` : key;
21
+ const selector = `${collection}::${id}::${path}`;
22
+
23
+ if (typeof value === 'string') {
24
+ // Text and image fields — unified under [data-caret]
25
+ const els = document.querySelectorAll(`[data-caret="${selector}"]`);
26
+ els.forEach((el) => {
27
+ // Skip elements being actively edited to prevent overwriting unsaved work
28
+ if (el === state.dirtyEl || el === document.activeElement) return;
29
+
30
+ if (el instanceof HTMLImageElement) {
31
+ // Image element
32
+ if (el.src !== value && el.getAttribute('src') !== value) {
33
+ el.src = value;
34
+ updated++;
35
+ }
36
+ } else if (el.hasAttribute('data-caret-rich')) {
37
+ const sanitized = sanitizeHtml(value);
38
+ if (el.innerHTML !== sanitized) {
39
+ el.innerHTML = sanitized;
40
+ updated++;
41
+ }
42
+ } else if (el.hasAttribute('data-caret-raw')) {
43
+ if (el.getAttribute('data-caret-raw') !== value) {
44
+ el.setAttribute('data-caret-raw', value);
45
+ el.innerHTML = clientLinkify(value);
46
+ updated++;
47
+ }
48
+ } else if (el.textContent !== value) {
49
+ el.textContent = value;
50
+ updated++;
51
+ }
52
+ });
53
+ } else if (typeof value === 'object' && value !== null) {
54
+ walkData(value, path);
55
+ }
56
+ }
57
+ }
58
+
59
+ walkData(data, '');
60
+
61
+ if (updated > 0) {
62
+ showToast(`Updated ${updated} element${updated > 1 ? 's' : ''} on page`, 'success');
63
+ } else {
64
+ showToast('Saved — refresh to see changes', 'success');
65
+ }
66
+ }
67
+
68
+ if (msg.type === 'cms:created') {
69
+ showToast('New entry created — refresh to see changes', 'success');
70
+ }
71
+ });
72
+ }
@@ -0,0 +1,151 @@
1
+ import { createTextLinkInteractions } from './text-link-interactions.js';
2
+ import { resolveBinding } from './helpers.js';
3
+ import { sanitizeHtml } from './sanitize.js';
4
+
5
+ const snapshots = new WeakMap();
6
+ let keydownBound = false;
7
+
8
+ export function mountTextEditors({
9
+ state,
10
+ parseCaretAttr,
11
+ clientLinkify,
12
+ saveField,
13
+ flash,
14
+ showToast,
15
+ }) {
16
+ const applyTextValue = (target, value) => {
17
+ if (target.hasAttribute('data-caret-rich')) {
18
+ target.innerHTML = sanitizeHtml(value);
19
+ } else if (target.hasAttribute('data-caret-raw')) {
20
+ target.setAttribute('data-caret-raw', value);
21
+ target.innerHTML = clientLinkify(value);
22
+ } else {
23
+ target.textContent = value;
24
+ }
25
+ };
26
+ const syncBoundText = (attr, value) => {
27
+ document.querySelectorAll('[data-caret]').forEach((node) => {
28
+ if (!(node instanceof HTMLElement)) return;
29
+ if (node.getAttribute('data-caret') !== attr) return;
30
+ if (node instanceof HTMLImageElement) return;
31
+ applyTextValue(node, value);
32
+ });
33
+ };
34
+ const { onKeydown, showLinkHint, removeLinkHint, showLinkPopup } = createTextLinkInteractions({
35
+ state,
36
+ clientLinkify,
37
+ showToast,
38
+ snapshots,
39
+ });
40
+
41
+ if (!keydownBound) {
42
+ document.addEventListener('keydown', onKeydown);
43
+ keydownBound = true;
44
+ }
45
+
46
+ document.querySelectorAll('[data-caret]').forEach((el) => {
47
+ if (el instanceof HTMLImageElement) return;
48
+ if (el.dataset.caretTextMounted === 'true') return;
49
+ el.dataset.caretTextMounted = 'true';
50
+
51
+ const attr = el.getAttribute('data-caret');
52
+ const isRich = el.hasAttribute('data-caret-rich');
53
+ const isLinkable = !isRich && el.hasAttribute('data-caret-raw');
54
+
55
+ el.setAttribute('contenteditable', isRich ? 'true' : 'plaintext-only');
56
+ el.classList.add('cms-editable');
57
+ if (isRich) el.classList.add('cms-rich');
58
+ if (isLinkable) el.classList.add('cms-linkable');
59
+
60
+ el.addEventListener('focus', () => {
61
+ if (isRich) {
62
+ snapshots.set(el, el.innerHTML);
63
+ } else if (isLinkable) {
64
+ const raw = el.getAttribute('data-caret-raw') || '';
65
+ snapshots.set(el, raw);
66
+ el.textContent = raw;
67
+ showLinkHint(el);
68
+ } else {
69
+ snapshots.set(el, el.textContent || '');
70
+ }
71
+ });
72
+
73
+ el.addEventListener('input', () => {
74
+ const snapshot = snapshots.get(el);
75
+ const current = isRich ? el.innerHTML : (el.textContent || '');
76
+ state.dirtyEl = current !== snapshot ? el : null;
77
+ });
78
+
79
+ el.addEventListener('blur', async () => {
80
+ removeLinkHint();
81
+
82
+ // If link popup is active for this element, defer the save
83
+ if (state.linkPopupEl === el) return;
84
+
85
+ // Skip save if Escape was pressed
86
+ if (el._caretSkipSave) {
87
+ el._caretSkipSave = false;
88
+ state.dirtyEl = null;
89
+ if (isRich) {
90
+ el.innerHTML = snapshots.get(el) || '';
91
+ } else if (isLinkable) {
92
+ const raw = el.getAttribute('data-caret-raw') || '';
93
+ el.innerHTML = clientLinkify(raw);
94
+ }
95
+ return;
96
+ }
97
+
98
+ const snapshot = snapshots.get(el) ?? '';
99
+ let current;
100
+ if (isRich) {
101
+ current = sanitizeHtml(el.innerHTML);
102
+ el.innerHTML = current; // normalize
103
+ } else {
104
+ current = el.textContent || '';
105
+ }
106
+
107
+ if (current === snapshot) {
108
+ if (isLinkable) {
109
+ el.innerHTML = clientLinkify(current);
110
+ }
111
+ return;
112
+ }
113
+
114
+ const parsed = parseCaretAttr(el.getAttribute('data-caret') || '');
115
+ const resolved = resolveBinding(el, parsed);
116
+ if (!resolved) return;
117
+
118
+ // Update raw attribute and re-render before saving
119
+ if (isLinkable) {
120
+ el.setAttribute('data-caret-raw', current);
121
+ el.innerHTML = clientLinkify(current);
122
+ }
123
+
124
+ el.classList.add('cms-saving');
125
+ const result = await saveField(resolved.collection, resolved.id, resolved.field, current);
126
+ el.classList.remove('cms-saving');
127
+ flash(el, result.ok);
128
+ state.dirtyEl = null;
129
+
130
+ // Sync all duplicated text bindings
131
+ if (result.ok) {
132
+ syncBoundText(attr, current);
133
+ showToast('Content saved', 'success');
134
+ } else {
135
+ const rollbackValue =
136
+ result.reason === 'conflict' && typeof result.latestValue === 'string'
137
+ ? result.latestValue
138
+ : snapshot;
139
+ syncBoundText(attr, rollbackValue);
140
+
141
+ if (result.reason === 'conflict') {
142
+ showToast('Content changed elsewhere. Loaded latest value.', 'error');
143
+ } else if (result.reason !== 'unauthorized') {
144
+ showToast('Failed to save. Changes reverted.', 'error');
145
+ }
146
+ }
147
+ });
148
+ });
149
+
150
+ return { showLinkPopup };
151
+ }