@jxsuite/studio 2.4.3 → 4.0.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 (208) hide show
  1. package/README.md +5 -5
  2. package/dist/chunks/Overlay.dev-723bv0df.js +23 -0
  3. package/dist/chunks/cf-settings-45fgyx8y.js +21 -0
  4. package/dist/chunks/{components-z6cnkyy1.js → components-zmx10t62.js} +6 -5
  5. package/dist/chunks/content-source-t88vb2dr.js +49 -0
  6. package/dist/chunks/{convert-to-repeater-k10dvcc7.js → convert-to-repeater-dhw1nrz9.js} +27 -18
  7. package/dist/chunks/entry-commands-6z6bhxg0.js +46 -0
  8. package/dist/chunks/{extension-sections-0ada0xcw.js → extension-sections-3ydgjbdy.js} +32 -23
  9. package/dist/chunks/file-ops-rskmhxyq.js +48 -0
  10. package/dist/chunks/files-0cratsr0.js +92 -0
  11. package/dist/chunks/{format-host-wewba4nq.js → format-host-tgcmfs4p.js} +3 -3
  12. package/dist/chunks/fs-events-hrrg328g.js +21 -0
  13. package/dist/chunks/{git-panel-2dh1aw50.js → git-panel-0yywyk76.js} +21 -15
  14. package/dist/chunks/{jx-validate-jj9rnt4n.js → jx-validate-8q2g05x1.js} +6 -4
  15. package/dist/chunks/layers-panel-z3tqe5cd.js +67 -0
  16. package/dist/chunks/layers-q75tj2mf.js +45 -0
  17. package/dist/chunks/lit-html-j055mkh8.js +22 -0
  18. package/dist/chunks/monaco-buffer-dqw0xxpx.js +25 -0
  19. package/dist/chunks/{monaco-setup-a5wkmbgh.js → monaco-setup-rws7k4br.js} +4 -4
  20. package/dist/chunks/notify-yjm79n4s.js +30 -0
  21. package/dist/chunks/parse-24d0gay3.js +19 -0
  22. package/dist/chunks/platform-ba1j1gbh.js +16 -0
  23. package/dist/chunks/publish-panel-54jvhskq.js +28 -0
  24. package/dist/chunks/quick-search-cgfmjwq5.js +65 -0
  25. package/dist/chunks/references-3qx8fkyp.js +29 -0
  26. package/dist/chunks/right-panel-cqp8bc4v.js +46 -0
  27. package/dist/chunks/sp-overlay.dev-yztmtrs1.js +18 -0
  28. package/dist/chunks/sp-popover.dev-n2etmqdp.js +9 -0
  29. package/dist/chunks/sp-progress-circle.dev-hryhj0es.js +15 -0
  30. package/dist/chunks/sp-tooltip.dev-xcvpnqr0.js +15 -0
  31. package/dist/chunks/{sp-tray.dev-64v4pxw8.js → sp-tray.dev-tkbscm06.js} +5 -5
  32. package/dist/chunks/{studio-f5yyvqxv.js → studio-1hbqnt19.js} +37 -31
  33. package/dist/chunks/studio-2zkz8evn.js +3163 -0
  34. package/dist/chunks/{studio-0b6fs05q.js → studio-4pqqxbrt.js} +23 -15
  35. package/dist/chunks/{studio-kvfx9z2c.js → studio-4rzyrtjz.js} +70 -31
  36. package/dist/chunks/{studio-ef8t53vc.js → studio-5q69gfag.js} +60 -56
  37. package/dist/chunks/{studio-v2c5pmjj.js → studio-5rywrkxz.js} +565 -133
  38. package/dist/chunks/{studio-6kv3apa9.js → studio-68n67094.js} +25 -9
  39. package/dist/chunks/{studio-0rqqhrdy.js → studio-7nte2hj4.js} +2 -2
  40. package/dist/chunks/{studio-hyn3vhwr.js → studio-8swrjbny.js} +31 -18
  41. package/dist/chunks/studio-92ab2jqe.js +282 -0
  42. package/dist/chunks/{studio-sas7mt3k.js → studio-9ab8gqsm.js} +2 -2
  43. package/dist/chunks/{studio-28xc8ws4.js → studio-9c4k4vhv.js} +14 -10
  44. package/dist/chunks/studio-9n4mrmnb.js +184 -0
  45. package/dist/chunks/{studio-tr20m8g8.js → studio-9r6j5ev1.js} +37 -2
  46. package/dist/chunks/{studio-aweyr4v1.js → studio-ahjfdy6e.js} +9 -7
  47. package/dist/chunks/{studio-s519zc99.js → studio-bgxt93ga.js} +3 -3
  48. package/dist/chunks/{studio-26sv44br.js → studio-cb12yz9w.js} +8543 -8784
  49. package/dist/chunks/studio-cft9r4r7.js +119 -0
  50. package/dist/chunks/{studio-rqemfhz6.js → studio-eenfkt4e.js} +6 -6
  51. package/dist/chunks/studio-eesa1myv.js +498 -0
  52. package/dist/chunks/{studio-ay8wcr2b.js → studio-eqq1w638.js} +7 -9
  53. package/dist/chunks/{studio-ke244pam.js → studio-ex8zyp98.js} +51 -25
  54. package/dist/chunks/studio-gv8vvshc.js +118 -0
  55. package/dist/chunks/studio-hbtp0eh1.js +1315 -0
  56. package/dist/chunks/{studio-cz2j1c0g.js → studio-htsf0w6m.js} +75 -123
  57. package/dist/chunks/{studio-pyrw8h0w.js → studio-kjjsjak4.js} +528 -212
  58. package/dist/chunks/{studio-5x5774ak.js → studio-kryvsw6j.js} +3 -3
  59. package/dist/chunks/studio-kyh9avvv.js +28 -0
  60. package/dist/chunks/{studio-jnakhg87.js → studio-kyk2v92a.js} +14 -14
  61. package/dist/chunks/{studio-twsafr1e.js → studio-m3hwn7y1.js} +3 -3
  62. package/dist/chunks/{studio-tzx3xmvx.js → studio-mmv72a27.js} +8 -8
  63. package/dist/chunks/{studio-vhk5fmfv.js → studio-n8b9wqwy.js} +5 -5
  64. package/dist/chunks/{studio-cjm7fdjf.js → studio-p4ngc046.js} +8 -104
  65. package/dist/chunks/{studio-sccge2wf.js → studio-p8j86wag.js} +2 -2
  66. package/dist/chunks/{studio-v1va0vhd.js → studio-pdfjntbk.js} +75 -139
  67. package/dist/chunks/studio-q43a5y9h.js +394 -0
  68. package/dist/chunks/studio-q7v10cg2.js +106 -0
  69. package/dist/chunks/{studio-2w11grav.js → studio-qq6jym04.js} +3 -3
  70. package/dist/chunks/studio-r1r7afxx.js +1066 -0
  71. package/dist/chunks/{studio-3fk1ac9z.js → studio-rdx8jcxy.js} +4 -4
  72. package/dist/chunks/{studio-4mqb9a0j.js → studio-rn9ta2mz.js} +4 -4
  73. package/dist/chunks/studio-sf7zjgv1.js +91 -0
  74. package/dist/chunks/studio-t7qb9db8.js +665 -0
  75. package/dist/chunks/studio-tmc5emrw.js +8 -0
  76. package/dist/chunks/{studio-wdt9y92a.js → studio-txwkm6p9.js} +2 -2
  77. package/dist/chunks/{studio-dgj7gq44.js → studio-v38hmvx1.js} +7 -7
  78. package/dist/chunks/{studio-7ejemhej.js → studio-vadzgkrz.js} +6 -6
  79. package/dist/chunks/studio-wcy8trfx.js +263 -0
  80. package/dist/chunks/{studio-hb7c46jy.js → studio-wx5609xd.js} +21 -15
  81. package/dist/chunks/studio-xrapxwwc.js +1539 -0
  82. package/dist/chunks/{studio-ws6ef6js.js → studio-yxrkyv8a.js} +41 -29
  83. package/dist/chunks/{studio-xm3dbxvn.js → studio-zczps70q.js} +2 -2
  84. package/dist/chunks/workspace-xpres40v.js +89 -0
  85. package/dist/iframe-entry.js +450 -48
  86. package/dist/studio.js +2455 -1761
  87. package/package.json +16 -15
  88. package/src/browse/library-layouts.ts +3 -3
  89. package/src/browse/library-pane.ts +59 -5
  90. package/src/browse/library-preview.ts +19 -3
  91. package/src/canvas/asset-refs.ts +119 -0
  92. package/src/canvas/asset-resolve.ts +256 -0
  93. package/src/canvas/canvas-live-render.ts +23 -15
  94. package/src/canvas/canvas-render.ts +23 -1
  95. package/src/canvas/iframe-entry.ts +1 -0
  96. package/src/canvas/iframe-host.ts +4 -0
  97. package/src/canvas/iframe-patch.ts +47 -21
  98. package/src/canvas/iframe-protocol.ts +9 -0
  99. package/src/canvas/iframe-render.ts +50 -16
  100. package/src/commands/app-commands.ts +4 -0
  101. package/src/commands/command-args.ts +29 -0
  102. package/src/commands/context.ts +15 -1
  103. package/src/commands/defaults.ts +29 -1
  104. package/src/commands/levels.ts +16 -0
  105. package/src/commands/live-context.ts +3 -0
  106. package/src/content/collection-match.ts +267 -0
  107. package/src/content/entry-commands.ts +38 -29
  108. package/src/content/entry-fields.ts +6 -0
  109. package/src/editor/file-drop-action.ts +2 -1
  110. package/src/editor/shortcuts.ts +5 -0
  111. package/src/files/file-ops.ts +10 -42
  112. package/src/files/files.ts +487 -61
  113. package/src/files/fs-events.ts +9 -0
  114. package/src/files/gitignore.ts +432 -0
  115. package/src/files/media-paths.ts +37 -14
  116. package/src/files/media-upload.ts +47 -6
  117. package/src/files/serialize-document.ts +60 -0
  118. package/src/format/convert-file.ts +511 -0
  119. package/src/format/format-choices.ts +199 -0
  120. package/src/grid/grid-idle.ts +45 -0
  121. package/src/grid/grid-view.ts +35 -0
  122. package/src/grid/schema-columns.ts +2 -1
  123. package/src/grid/sources/content-source.ts +24 -3
  124. package/src/media/media-open.ts +58 -0
  125. package/src/media/media-pane.ts +310 -0
  126. package/src/new-project/import-tab.ts +333 -160
  127. package/src/new-project/new-project-modal.ts +27 -34
  128. package/src/packages/ensure-deps.ts +14 -7
  129. package/src/packages/jxsuite-update.ts +11 -11
  130. package/src/page-params.ts +10 -46
  131. package/src/panels/activity-bar.ts +45 -16
  132. package/src/panels/ai-chat/attached-context.ts +6 -1
  133. package/src/panels/ai-chat/chat-view.ts +255 -13
  134. package/src/panels/ai-chat/composer.ts +21 -80
  135. package/src/panels/ai-panel.ts +116 -2
  136. package/src/panels/frontmatter-fields.ts +6 -2
  137. package/src/panels/navigator-panels.ts +7 -6
  138. package/src/panels/properties-panel.ts +8 -2
  139. package/src/panels/seo-modal.ts +5 -6
  140. package/src/panels/settings-menu.ts +799 -0
  141. package/src/panels/signals-panel.ts +2 -1
  142. package/src/panels/toolbar.ts +135 -15
  143. package/src/platforms/cloud.ts +34 -3
  144. package/src/platforms/devserver.ts +72 -34
  145. package/src/preview/preview-overlay.ts +226 -0
  146. package/src/services/ai-ask.ts +247 -0
  147. package/src/services/ai-import-tools.ts +494 -0
  148. package/src/services/ai-models.ts +101 -11
  149. package/src/services/ai-project-tools.ts +20 -26
  150. package/src/services/ai-settings.ts +69 -71
  151. package/src/services/ai-system-prompt.ts +88 -2
  152. package/src/services/ai-turn-signal.ts +70 -0
  153. package/src/services/cf-settings.ts +19 -37
  154. package/src/services/connection.ts +74 -0
  155. package/src/services/context-manager.ts +89 -0
  156. package/src/services/document-assistant.ts +49 -7
  157. package/src/services/idle.ts +6 -1
  158. package/src/services/import-client.ts +33 -6
  159. package/src/services/import-run.ts +158 -0
  160. package/src/services/import-seed.ts +120 -0
  161. package/src/services/jx-validate.ts +58 -6
  162. package/src/services/project-adoption.ts +71 -0
  163. package/src/services/references.ts +0 -0
  164. package/src/services/settings/definitions.ts +181 -0
  165. package/src/services/settings/kernel.ts +335 -0
  166. package/src/services/settings/write-queue.ts +116 -0
  167. package/src/services/tool-executor.ts +34 -2
  168. package/src/settings/contexts-section.ts +45 -3
  169. package/src/settings/dependencies-editor.ts +43 -23
  170. package/src/settings/general-settings.ts +30 -12
  171. package/src/settings/preferences-accounts.ts +6 -19
  172. package/src/settings/preferences-dialog.ts +18 -41
  173. package/src/settings/preferences-keymap.ts +8 -18
  174. package/src/settings/preferences-sections.ts +57 -0
  175. package/src/settings/schema-field-ui.ts +2 -2
  176. package/src/settings/settings-document.ts +65 -9
  177. package/src/shell.ts +6 -14
  178. package/src/studio.ts +65 -7
  179. package/src/tabs/transact.ts +42 -19
  180. package/src/types.ts +164 -8
  181. package/src/ui/ai-credentials-form.ts +52 -27
  182. package/src/ui/ai-model-picker.ts +162 -0
  183. package/src/ui/choice-field.ts +72 -0
  184. package/src/ui/layers.ts +83 -5
  185. package/src/ui/media-picker.ts +6 -11
  186. package/src/utils/studio-utils.ts +43 -31
  187. package/styles/forced-colors.css +7 -0
  188. package/styles/overlays.css +256 -0
  189. package/styles/panels.css +13 -1
  190. package/styles/shell.css +111 -0
  191. package/dist/chunks/Overlay.dev-d2ajy6sj.js +0 -23
  192. package/dist/chunks/cf-settings-g5fbf2zp.js +0 -17
  193. package/dist/chunks/content-source-k9724vcv.js +0 -39
  194. package/dist/chunks/files-yew27sn9.js +0 -69
  195. package/dist/chunks/layers-panel-qnsghwwd.js +0 -59
  196. package/dist/chunks/publish-panel-a0pdft5w.js +0 -21
  197. package/dist/chunks/quick-search-9avyc4pc.js +0 -54
  198. package/dist/chunks/right-panel-kcnhtc5j.js +0 -38
  199. package/dist/chunks/sp-overlay.dev-s18hymn9.js +0 -18
  200. package/dist/chunks/sp-popover.dev-dj9x7e7a.js +0 -9
  201. package/dist/chunks/sp-progress-circle.dev-0zxcyz3r.js +0 -15
  202. package/dist/chunks/sp-tooltip.dev-5c6d1kjz.js +0 -15
  203. package/dist/chunks/studio-a7pzveq1.js +0 -110
  204. package/dist/chunks/studio-c31yb4t6.js +0 -55
  205. package/dist/chunks/studio-ra7ar50f.js +0 -6682
  206. package/src/canvas/content-assets.ts +0 -263
  207. package/src/canvas/site-style-css.ts +0 -121
  208. package/src/services/settings-store.ts +0 -99
@@ -0,0 +1,1066 @@
1
+ import {
2
+ until
3
+ } from "./studio-eqq1w638.js";
4
+ import {
5
+ collectionOfPath,
6
+ entryCollection,
7
+ entryCollections,
8
+ missingRequired,
9
+ seedEntry
10
+ } from "./studio-sf7zjgv1.js";
11
+ import {
12
+ referenceTarget,
13
+ registerFormControl,
14
+ renderForm,
15
+ resolveContextPointer
16
+ } from "./studio-5q69gfag.js";
17
+ import {
18
+ DRAFT_FIELD,
19
+ DRAFT_MEANING,
20
+ hasDraftAxis,
21
+ isDraftEntry,
22
+ reloadDraftAwareGrids,
23
+ setIncludeDrafts
24
+ } from "./studio-eesa1myv.js";
25
+ import {
26
+ notePreviewOverlayEdit
27
+ } from "./studio-cb12yz9w.js";
28
+ import {
29
+ activeRegistry,
30
+ paneRegion
31
+ } from "./studio-t7qb9db8.js";
32
+ import {
33
+ errorMessage
34
+ } from "./studio-9n4mrmnb.js";
35
+ import {
36
+ LOCALE_PLACEHOLDER,
37
+ activateTab,
38
+ activeTab,
39
+ argsSchema,
40
+ booleanArg,
41
+ booleanProperty,
42
+ camelToLabel,
43
+ collectionForDirectory,
44
+ derivedEnumProperty,
45
+ enumArg,
46
+ mutateUpdateFrontmatter,
47
+ recordDocOp,
48
+ stringArg,
49
+ stringProperty,
50
+ toCamelCase,
51
+ transactDoc,
52
+ workspace
53
+ } from "./studio-2zkz8evn.js";
54
+ import {
55
+ effect,
56
+ effectScope,
57
+ notify
58
+ } from "./studio-xrapxwwc.js";
59
+ import {
60
+ live,
61
+ repeat
62
+ } from "./studio-4rzyrtjz.js";
63
+ import {
64
+ html,
65
+ nothing,
66
+ render
67
+ } from "./studio-kryvsw6j.js";
68
+ import {
69
+ cloneValue
70
+ } from "./studio-5ehhackm.js";
71
+ import {
72
+ projectState
73
+ } from "./studio-p4ngc046.js";
74
+ import {
75
+ defaultContentFormat,
76
+ formatByName,
77
+ formatForPath,
78
+ formatSerialize,
79
+ loadFormats
80
+ } from "./studio-eenfkt4e.js";
81
+ import {
82
+ __require
83
+ } from "./studio-a0tswy0w.js";
84
+
85
+ // src/settings/schema-field-ui.ts
86
+ var FIELD_TYPES = ["string", "number", "boolean", "array", "object", "reference"];
87
+ var FORMAT_OPTIONS = ["", "image", "date", "color"];
88
+ function detectFieldType(schema) {
89
+ if (schema.$ref) {
90
+ return "reference";
91
+ }
92
+ return schema.type || "string";
93
+ }
94
+ function detectFieldFormat(schema) {
95
+ if (schema.type === "array" && schema.items?.format) {
96
+ return schema.items.format;
97
+ }
98
+ return schema.format || "";
99
+ }
100
+ function fieldCardTpl(fieldName, fieldSchema, isRequired, handlers, contentTypeNames = []) {
101
+ const type = detectFieldType(fieldSchema);
102
+ const format = detectFieldFormat(fieldSchema);
103
+ const isNested = type === "object";
104
+ const isRef = type === "reference";
105
+ const nestedProps = fieldSchema.properties || {};
106
+ const nestedRequired = fieldSchema.required || [];
107
+ const refTarget = fieldSchema.$ref ? fieldSchema.$ref.replace(/^#\/[^/]+\//, "") : "";
108
+ return html`
109
+ <div class="schema-field-card">
110
+ <div class="schema-field-row">
111
+ <sp-field-label size="s" class="schema-field-label"
112
+ >${camelToLabel(fieldName)}</sp-field-label
113
+ >
114
+ <sp-textfield
115
+ size="s"
116
+ quiet
117
+ value=${fieldName}
118
+ class="schema-field-name-input"
119
+ @change=${(e) => {
120
+ const target = e.target;
121
+ const newName = target.value.trim();
122
+ if (newName && newName !== fieldName) {
123
+ handlers.onRename(fieldName, newName);
124
+ } else {
125
+ target.value = fieldName;
126
+ }
127
+ }}
128
+ @keydown=${(e) => {
129
+ const target = e.target;
130
+ if (e.key === "Enter") {
131
+ target.blur();
132
+ }
133
+ if (e.key === "Escape") {
134
+ target.value = fieldName;
135
+ target.blur();
136
+ }
137
+ }}
138
+ ></sp-textfield>
139
+ ${typePickerTpl(type, (newType) => handlers.onChangeType(fieldName, newType))}
140
+ ${type === "string" || type === "array" ? formatPickerTpl(format, (f) => {
141
+ if (handlers.onChangeFormat) {
142
+ handlers.onChangeFormat(fieldName, f);
143
+ }
144
+ }) : nothing}
145
+ <sp-switch
146
+ size="s"
147
+ ?checked=${isRequired}
148
+ @change=${() => handlers.onToggleRequired(fieldName)}
149
+ >
150
+ Req
151
+ </sp-switch>
152
+ <sp-action-button
153
+ size="xs"
154
+ quiet
155
+ title="Delete field"
156
+ @click=${() => handlers.onDelete(fieldName)}
157
+ >
158
+ <sp-icon-delete slot="icon"></sp-icon-delete>
159
+ </sp-action-button>
160
+ </div>
161
+ ${isRef && contentTypeNames.length > 0 ? html`
162
+ <div class="schema-field-ref-target">
163
+ <sp-picker
164
+ size="s"
165
+ label="Target"
166
+ value=${refTarget}
167
+ @change=${(e) => {
168
+ if (handlers.onChangeRefTarget) {
169
+ handlers.onChangeRefTarget(fieldName, e.target.value);
170
+ }
171
+ }}
172
+ >
173
+ ${contentTypeNames.map((n) => html`<sp-menu-item value=${n}>${n}</sp-menu-item>`)}
174
+ </sp-picker>
175
+ </div>
176
+ ` : nothing}
177
+ ${isNested ? html`
178
+ <div class="schema-field-nested">
179
+ ${Object.entries(nestedProps).map(([name, sub]) => nestedFieldCardTpl(fieldName, name, sub, nestedRequired.includes(name), handlers))}
180
+ ${nestedAddFieldTpl(fieldName, handlers)}
181
+ </div>
182
+ ` : nothing}
183
+ </div>
184
+ `;
185
+ }
186
+ function nestedFieldCardTpl(parentName, childName, childSchema, isRequired, handlers) {
187
+ const type = detectFieldType(childSchema);
188
+ const format = detectFieldFormat(childSchema);
189
+ return html`
190
+ <div class="schema-field-card schema-field-card--nested">
191
+ <div class="schema-field-row">
192
+ <sp-textfield
193
+ size="s"
194
+ quiet
195
+ value=${childName}
196
+ class="schema-field-name-input"
197
+ @change=${(e) => {
198
+ const target = e.target;
199
+ const newName = target.value.trim();
200
+ if (newName && newName !== childName && handlers.onRenameNested) {
201
+ handlers.onRenameNested(parentName, childName, newName);
202
+ } else {
203
+ target.value = childName;
204
+ }
205
+ }}
206
+ @keydown=${(e) => {
207
+ const target = e.target;
208
+ if (e.key === "Enter") {
209
+ target.blur();
210
+ }
211
+ if (e.key === "Escape") {
212
+ target.value = childName;
213
+ target.blur();
214
+ }
215
+ }}
216
+ ></sp-textfield>
217
+ ${typePickerTpl(type, (newType) => {
218
+ if (handlers.onChangeNestedType) {
219
+ handlers.onChangeNestedType(parentName, childName, newType);
220
+ }
221
+ })}
222
+ ${type === "string" || type === "array" ? formatPickerTpl(format, (f) => {
223
+ if (handlers.onChangeNestedFormat) {
224
+ handlers.onChangeNestedFormat(parentName, childName, f);
225
+ }
226
+ }) : nothing}
227
+ <sp-switch
228
+ size="s"
229
+ ?checked=${isRequired}
230
+ @change=${() => {
231
+ if (handlers.onToggleNestedRequired) {
232
+ handlers.onToggleNestedRequired(parentName, childName);
233
+ }
234
+ }}
235
+ >
236
+ Req
237
+ </sp-switch>
238
+ <sp-action-button
239
+ size="xs"
240
+ quiet
241
+ title="Delete field"
242
+ @click=${() => {
243
+ if (handlers.onDeleteNested) {
244
+ handlers.onDeleteNested(parentName, childName);
245
+ }
246
+ }}
247
+ >
248
+ <sp-icon-delete slot="icon"></sp-icon-delete>
249
+ </sp-action-button>
250
+ </div>
251
+ </div>
252
+ `;
253
+ }
254
+ function nestedAddFieldTpl(parentName, handlers) {
255
+ return html`
256
+ <div class="schema-nested-add">
257
+ <sp-textfield
258
+ size="s"
259
+ placeholder="field name"
260
+ class="schema-nested-add-name"
261
+ @keydown=${(e) => {
262
+ if (e.key === "Enter") {
263
+ const target = e.target;
264
+ const row = target.closest(".schema-nested-add");
265
+ const name = target.value.trim();
266
+ const typePicker = row?.querySelector("sp-picker");
267
+ const type = typePicker?.value || "string";
268
+ if (name && handlers.onAddNestedField) {
269
+ handlers.onAddNestedField(parentName, {
270
+ name,
271
+ required: false,
272
+ type
273
+ });
274
+ target.value = "";
275
+ }
276
+ }
277
+ }}
278
+ ></sp-textfield>
279
+ ${typePickerTpl("string", () => {})}
280
+ <sp-action-button
281
+ size="xs"
282
+ quiet
283
+ title="Add nested field"
284
+ @click=${(e) => {
285
+ const target = e.target;
286
+ const row = target.closest(".schema-nested-add");
287
+ const nameInput = row?.querySelector(".schema-nested-add-name");
288
+ const typePicker = row?.querySelector("sp-picker");
289
+ const name = nameInput?.value?.trim();
290
+ const type = typePicker?.value || "string";
291
+ if (name && handlers.onAddNestedField) {
292
+ handlers.onAddNestedField(parentName, {
293
+ name,
294
+ required: false,
295
+ type
296
+ });
297
+ if (nameInput) {
298
+ nameInput.value = "";
299
+ }
300
+ }
301
+ }}
302
+ >
303
+ <sp-icon-add slot="icon"></sp-icon-add>
304
+ </sp-action-button>
305
+ </div>
306
+ `;
307
+ }
308
+ function typePickerTpl(value, onChange) {
309
+ return html`
310
+ <sp-picker
311
+ size="s"
312
+ label="Type"
313
+ value=${value}
314
+ @change=${(e) => onChange(e.target.value)}
315
+ >
316
+ ${FIELD_TYPES.map((t) => html`<sp-menu-item value=${t}>${t}</sp-menu-item>`)}
317
+ </sp-picker>
318
+ `;
319
+ }
320
+ function formatPickerTpl(value, onChange) {
321
+ return html`
322
+ <sp-picker
323
+ size="s"
324
+ label="Format"
325
+ value=${value}
326
+ @change=${(e) => onChange(e.target.value)}
327
+ >
328
+ ${FORMAT_OPTIONS.map((f) => html`<sp-menu-item value=${f}>${f || "(none)"}</sp-menu-item>`)}
329
+ </sp-picker>
330
+ `;
331
+ }
332
+ function addFieldFormTpl(state, handlers) {
333
+ return html`
334
+ <div class="schema-add-field">
335
+ <sp-textfield
336
+ size="s"
337
+ placeholder="Field name"
338
+ .value=${state.name}
339
+ @input=${(e) => handlers.onInput("name", e.target.value)}
340
+ @keydown=${(e) => {
341
+ if (e.key === "Enter") {
342
+ handlers.onConfirm();
343
+ }
344
+ if (e.key === "Escape") {
345
+ handlers.onCancel();
346
+ }
347
+ }}
348
+ ></sp-textfield>
349
+ ${typePickerTpl(state.type, (t) => handlers.onInput("type", t))}
350
+ ${state.type === "string" || state.type === "array" ? formatPickerTpl(state.format || "", (f) => handlers.onInput("format", f)) : nothing}
351
+ <sp-switch
352
+ size="s"
353
+ ?checked=${state.required}
354
+ @change=${(e) => handlers.onInput("required", e.target.checked)}
355
+ >
356
+ Required
357
+ </sp-switch>
358
+ <sp-action-button size="s" @click=${handlers.onConfirm}>Add</sp-action-button>
359
+ <sp-action-button size="s" quiet @click=${handlers.onCancel}>Cancel</sp-action-button>
360
+ </div>
361
+ `;
362
+ }
363
+ function schemaForType(type, format) {
364
+ switch (type) {
365
+ case "number": {
366
+ return { type: "number" };
367
+ }
368
+ case "boolean": {
369
+ return { type: "boolean" };
370
+ }
371
+ case "array": {
372
+ return format ? { items: { format, type: "string" }, type: "array" } : { items: { type: "string" }, type: "array" };
373
+ }
374
+ case "object": {
375
+ return { properties: {}, required: [], type: "object" };
376
+ }
377
+ case "reference": {
378
+ return { $ref: "#/content/" };
379
+ }
380
+ default: {
381
+ return format ? { format, type: "string" } : { type: "string" };
382
+ }
383
+ }
384
+ }
385
+
386
+ // src/ui/form-controls.ts
387
+ var blankAddFieldState = () => ({
388
+ format: "",
389
+ name: "",
390
+ required: false,
391
+ type: "string"
392
+ });
393
+ var addFieldOpen = new Set;
394
+ var addFieldStates = new Map;
395
+ function cloneSchema(value) {
396
+ const base = value && typeof value === "object" && !Array.isArray(value) ? value : { properties: {}, required: [], type: "object" };
397
+ return JSON.parse(JSON.stringify(base));
398
+ }
399
+ function schemaBuilderControl({ key, value, onChange, ctx, rerender }) {
400
+ const schema = value && typeof value === "object" && !Array.isArray(value) ? value : { properties: {}, required: [], type: "object" };
401
+ const properties = schema.properties ?? {};
402
+ const required = schema.required ?? [];
403
+ const stateKey = `${ctx.fieldKeyPrefix ?? ""}.${key}`;
404
+ const update = (mutate) => {
405
+ const draft = cloneSchema(value);
406
+ draft.type ??= "object";
407
+ draft.properties ??= {};
408
+ draft.required ??= [];
409
+ mutate(draft);
410
+ onChange(draft);
411
+ rerender?.();
412
+ };
413
+ const contentTypesValue = ctx.resolvePointer("#/$context/content");
414
+ const contentTypeNames = contentTypesValue && typeof contentTypesValue === "object" ? Object.keys(contentTypesValue) : [];
415
+ const handlers = {
416
+ onAddNestedField: (parentName, fieldState) => update((draft) => {
417
+ const parent = draft.properties?.[parentName];
418
+ const name = toCamelCase(fieldState.name);
419
+ if (!parent || !name) {
420
+ return;
421
+ }
422
+ parent.properties ??= {};
423
+ parent.properties[name] = schemaForType(fieldState.type);
424
+ if (fieldState.required) {
425
+ parent.required ??= [];
426
+ if (!parent.required.includes(name)) {
427
+ parent.required.push(name);
428
+ }
429
+ }
430
+ }),
431
+ onChangeFormat: (name, format) => update((draft) => {
432
+ const prop = draft.properties?.[name];
433
+ if (!prop) {
434
+ return;
435
+ }
436
+ draft.properties[name] = schemaForType(prop.type || "string", format || undefined);
437
+ }),
438
+ onChangeNestedFormat: (parentName, childName, format) => update((draft) => {
439
+ const parent = draft.properties?.[parentName];
440
+ const prop = parent?.properties?.[childName];
441
+ if (!prop) {
442
+ return;
443
+ }
444
+ parent.properties[childName] = schemaForType(prop.type || "string", format || undefined);
445
+ }),
446
+ onChangeNestedType: (parentName, childName, newType) => update((draft) => {
447
+ const parent = draft.properties?.[parentName];
448
+ const prop = parent?.properties?.[childName];
449
+ if (!prop) {
450
+ return;
451
+ }
452
+ const oldFormat = newType === "string" || newType === "array" ? detectFieldFormat(prop) : undefined;
453
+ parent.properties[childName] = schemaForType(newType, oldFormat || undefined);
454
+ }),
455
+ onChangeRefTarget: (name, target) => update((draft) => {
456
+ if (!draft.properties?.[name]) {
457
+ return;
458
+ }
459
+ draft.properties[name] = { $ref: `#/content/${target}` };
460
+ }),
461
+ onChangeType: (name, newType) => update((draft) => {
462
+ const prop = draft.properties?.[name];
463
+ if (!prop) {
464
+ return;
465
+ }
466
+ const oldFormat = newType === "string" || newType === "array" ? detectFieldFormat(prop) : undefined;
467
+ draft.properties[name] = schemaForType(newType, oldFormat || undefined);
468
+ }),
469
+ onDelete: (name) => update((draft) => {
470
+ delete draft.properties?.[name];
471
+ draft.required = (draft.required ?? []).filter((r) => r !== name);
472
+ }),
473
+ onDeleteNested: (parentName, childName) => update((draft) => {
474
+ const parent = draft.properties?.[parentName];
475
+ if (!parent?.properties) {
476
+ return;
477
+ }
478
+ delete parent.properties[childName];
479
+ if (parent.required) {
480
+ parent.required = parent.required.filter((r) => r !== childName);
481
+ }
482
+ }),
483
+ onRename: (oldName, newName) => update((draft) => {
484
+ const normalized = toCamelCase(newName);
485
+ if (!draft.properties || !normalized || draft.properties[normalized]) {
486
+ return;
487
+ }
488
+ const next = {};
489
+ for (const [k, v] of Object.entries(draft.properties)) {
490
+ next[k === oldName ? normalized : k] = v;
491
+ }
492
+ draft.properties = next;
493
+ draft.required = (draft.required ?? []).map((r) => r === oldName ? normalized : r);
494
+ }),
495
+ onRenameNested: (parentName, oldChild, newChild) => update((draft) => {
496
+ const parent = draft.properties?.[parentName];
497
+ const normalized = toCamelCase(newChild);
498
+ if (!parent?.properties || !normalized || parent.properties[normalized]) {
499
+ return;
500
+ }
501
+ const next = {};
502
+ for (const [k, v] of Object.entries(parent.properties)) {
503
+ next[k === oldChild ? normalized : k] = v;
504
+ }
505
+ parent.properties = next;
506
+ if (parent.required) {
507
+ parent.required = parent.required.map((r) => r === oldChild ? normalized : r);
508
+ }
509
+ }),
510
+ onToggleNestedRequired: (parentName, childName) => update((draft) => {
511
+ const parent = draft.properties?.[parentName];
512
+ if (!parent) {
513
+ return;
514
+ }
515
+ parent.required ??= [];
516
+ const idx = parent.required.indexOf(childName);
517
+ if (idx === -1) {
518
+ parent.required.push(childName);
519
+ } else {
520
+ parent.required.splice(idx, 1);
521
+ }
522
+ }),
523
+ onToggleRequired: (name) => update((draft) => {
524
+ draft.required ??= [];
525
+ const idx = draft.required.indexOf(name);
526
+ if (idx === -1) {
527
+ draft.required.push(name);
528
+ } else {
529
+ draft.required.splice(idx, 1);
530
+ }
531
+ })
532
+ };
533
+ const fieldCards = repeat(Object.entries(properties), ([name]) => name, ([name, def]) => fieldCardTpl(name, def, required.includes(name), handlers, contentTypeNames));
534
+ const addFieldState = addFieldStates.get(stateKey) ?? blankAddFieldState();
535
+ return html`
536
+ <div class="schema-builder">
537
+ <div class="schema-field-list">${fieldCards}</div>
538
+ ${addFieldOpen.has(stateKey) ? addFieldFormTpl(addFieldState, {
539
+ onCancel: () => {
540
+ addFieldOpen.delete(stateKey);
541
+ addFieldStates.delete(stateKey);
542
+ rerender?.();
543
+ },
544
+ onConfirm: () => {
545
+ const raw = addFieldState.name.trim();
546
+ const name = toCamelCase(raw);
547
+ if (!name) {
548
+ return;
549
+ }
550
+ addFieldOpen.delete(stateKey);
551
+ addFieldStates.delete(stateKey);
552
+ update((draft) => {
553
+ draft.properties[name] = schemaForType(addFieldState.type, addFieldState.format || undefined);
554
+ if (addFieldState.required && !draft.required.includes(name)) {
555
+ draft.required.push(name);
556
+ }
557
+ });
558
+ },
559
+ onInput: (field, val) => {
560
+ addFieldStates.set(stateKey, { ...addFieldState, [field]: val });
561
+ rerender?.();
562
+ }
563
+ }) : html`
564
+ <sp-action-button
565
+ size="s"
566
+ quiet
567
+ @click=${() => {
568
+ addFieldOpen.add(stateKey);
569
+ addFieldStates.set(stateKey, blankAddFieldState());
570
+ rerender?.();
571
+ }}
572
+ >
573
+ <sp-icon-add slot="icon"></sp-icon-add> Add Field
574
+ </sp-action-button>
575
+ `}
576
+ </div>
577
+ `;
578
+ }
579
+ registerFormControl("schema-builder", schemaBuilderControl);
580
+ registerFormControl("secret", ({ key, value, onChange, ctx, rerender }) => {
581
+ const { commitSecret } = ctx;
582
+ const envName = typeof value === "string" && value ? value : null;
583
+ return html`<sp-textfield
584
+ size="s"
585
+ type="password"
586
+ class="secret-field"
587
+ placeholder=${envName ? `Stored as ${envName}` : "Not set"}
588
+ ?disabled=${!commitSecret}
589
+ @change=${async (e) => {
590
+ const target = e.target;
591
+ const secretValue = target.value;
592
+ if (!commitSecret || !secretValue) {
593
+ return;
594
+ }
595
+ const name = await commitSecret(key, secretValue);
596
+ target.value = "";
597
+ if (typeof name === "string" && name && name !== envName) {
598
+ onChange(name);
599
+ } else {
600
+ rerender?.();
601
+ }
602
+ }}
603
+ ></sp-textfield>`;
604
+ });
605
+ var entryIdCache = new Map;
606
+ var entryIdResult = new Map;
607
+ function invalidateReferenceEntries(collection) {
608
+ if (collection === undefined) {
609
+ entryIdCache.clear();
610
+ entryIdResult.clear();
611
+ } else {
612
+ entryIdCache.delete(collection);
613
+ entryIdResult.delete(collection);
614
+ }
615
+ }
616
+ function entryIdsFor(collection) {
617
+ const known = entryIdCache.get(collection);
618
+ if (known) {
619
+ return known;
620
+ }
621
+ const pending = import("./content-source-t88vb2dr.js").then((m) => m.listCollectionEntryIds(collection));
622
+ entryIdCache.set(collection, pending);
623
+ return pending;
624
+ }
625
+ function referenceTextField(current, onChange) {
626
+ return html`<sp-textfield
627
+ size="s"
628
+ class="reference-field"
629
+ .value=${current}
630
+ @change=${(e) => onChange(e.target.value.trim() || undefined)}
631
+ ></sp-textfield>`;
632
+ }
633
+ function referencePicker(collection, ids, current, onChange) {
634
+ const dangling = current !== "" && !ids.includes(current);
635
+ return html`
636
+ <sp-picker
637
+ size="s"
638
+ class="reference-field"
639
+ value=${current || "__none__"}
640
+ @change=${(e) => {
641
+ const chosen = e.target.value;
642
+ onChange(chosen === "__none__" ? undefined : chosen);
643
+ }}
644
+ >
645
+ <sp-menu-item value="__none__">—</sp-menu-item>
646
+ ${dangling ? html`<sp-menu-item class="reference-missing" value=${current}
647
+ >${current} — not found</sp-menu-item
648
+ >` : nothing}
649
+ ${ids.map((id) => html`<sp-menu-item value=${id}>${id}</sp-menu-item>`)}
650
+ </sp-picker>
651
+ ${ids.length === 0 ? html`<span class="reference-note">No ${collection} entries yet.</span>` : nothing}
652
+ `;
653
+ }
654
+ registerFormControl("reference", ({ schema, value, onChange, rerender }) => {
655
+ const collection = referenceTarget(schema);
656
+ const current = typeof value === "string" ? value : "";
657
+ if (collection === null) {
658
+ return html`<div class="reference-control">
659
+ ${referenceTextField(current, onChange)}
660
+ <span class="reference-note"
661
+ >No collection referenced — add <code>"$ref": "#/content/&lt;type&gt;"</code> to this
662
+ field.</span
663
+ >
664
+ </div>`;
665
+ }
666
+ const failedTpl = (error) => html`
667
+ ${referenceTextField(current, onChange)}
668
+ <span class="reference-note reference-note--failed"
669
+ >Could not list ${collection} entries — ${error}</span
670
+ >
671
+ ${rerender ? html`<sp-action-button
672
+ size="s"
673
+ quiet
674
+ @click=${() => {
675
+ invalidateReferenceEntries(collection);
676
+ rerender();
677
+ }}
678
+ >Retry</sp-action-button
679
+ >` : nothing}
680
+ `;
681
+ const done = entryIdResult.get(collection);
682
+ if (done) {
683
+ return html`<div class="reference-control">
684
+ ${"ids" in done ? referencePicker(collection, done.ids, current, onChange) : failedTpl(done.error)}
685
+ </div>`;
686
+ }
687
+ const resolved = entryIdsFor(collection).then((ids) => {
688
+ entryIdResult.set(collection, { ids });
689
+ return referencePicker(collection, ids, current, onChange);
690
+ }, (error) => {
691
+ const message = errorMessage(error);
692
+ entryIdResult.set(collection, { error: message });
693
+ return failedTpl(message);
694
+ });
695
+ return html`<div class="reference-control">
696
+ ${until(resolved, html`<sp-picker size="s" class="reference-field" disabled label="Loading…"></sp-picker>`)}
697
+ </div>`;
698
+ });
699
+
700
+ // src/content/entry-fields.ts
701
+ function fieldsAreDocument(tab) {
702
+ return tab.doc.sourceFormat == null && tab.doc.mode !== "content";
703
+ }
704
+ function entryFields(tab) {
705
+ return fieldsAreDocument(tab) ? tab.doc.document : tab.doc.content?.frontmatter ?? {};
706
+ }
707
+ function mutateDocumentField(tab, field, value) {
708
+ const doc = tab.doc.document;
709
+ const before = Object.hasOwn(doc, field) ? cloneValue(doc[field]) : undefined;
710
+ const deletes = value === undefined || value === null || value === "";
711
+ if (deletes) {
712
+ delete doc[field];
713
+ } else {
714
+ doc[field] = value;
715
+ }
716
+ const after = deletes ? undefined : cloneValue(value);
717
+ recordDocOp({
718
+ forward: { key: field, op: "set-key", path: [], value: after },
719
+ inverse: { key: field, op: "set-key", path: [], value: before }
720
+ });
721
+ tab.doc.dirty = true;
722
+ notePreviewOverlayEdit();
723
+ }
724
+ function mutateEntryField(tab, field, value) {
725
+ if (fieldsAreDocument(tab)) {
726
+ mutateDocumentField(tab, field, value);
727
+ } else {
728
+ mutateUpdateFrontmatter(tab, field, value);
729
+ }
730
+ }
731
+ function commitEntryFields(tab, patch) {
732
+ transactDoc(tab, (t) => {
733
+ for (const [field, value] of Object.entries(patch)) {
734
+ mutateEntryField(t, field, value);
735
+ }
736
+ });
737
+ }
738
+
739
+ // src/content/entry-editor.ts
740
+ var ENTRY_MODE = "entry";
741
+ var ENTRY_TAB_MODES = [ENTRY_MODE];
742
+ var _active = new Map;
743
+ function activeIn(paneId) {
744
+ return _active.get(paneId) ?? null;
745
+ }
746
+ function entryPaneMounted(paneId, tab) {
747
+ const panel = activeIn(paneId);
748
+ return panel !== null && panel.tabId === tab.id && panel.wrap.isConnected;
749
+ }
750
+ function detachEntryPane(paneId) {
751
+ const panel = _active.get(paneId);
752
+ if (!panel) {
753
+ return;
754
+ }
755
+ panel.scope.stop();
756
+ _active.delete(paneId);
757
+ }
758
+ function setEntryDraft(tab, draft) {
759
+ transactDoc(tab, (t) => mutateEntryField(t, DRAFT_FIELD, draft));
760
+ }
761
+ function entryDraftPill(tab) {
762
+ const collection = collectionOfPath(tab.documentPath);
763
+ const fields = entryFields(tab);
764
+ if (!collection || !hasDraftAxis(collection.schema, fields)) {
765
+ return nothing;
766
+ }
767
+ const draft = isDraftEntry(fields);
768
+ return html`<span
769
+ class=${draft ? "entry-pill entry-pill--draft" : "entry-pill"}
770
+ title=${draft ? DRAFT_MEANING : "Not marked a draft."}
771
+ >${draft ? "Draft" : "Published"}</span
772
+ >`;
773
+ }
774
+ function formContext(tab) {
775
+ return {
776
+ fieldKeyPrefix: `entry:${tab.id}`,
777
+ resolvePointer: (pointer, scope) => resolveContextPointer(pointer, {
778
+ projectConfig: projectState?.projectConfig ?? {},
779
+ scope
780
+ })
781
+ };
782
+ }
783
+ function absentRequiredErrors(collection, fields) {
784
+ const errors = {};
785
+ for (const field of missingRequired(collection.schema, fields)) {
786
+ errors[field] = "Required — this entry does not have one.";
787
+ }
788
+ return errors;
789
+ }
790
+ function headerTpl(tab, collection) {
791
+ const fields = entryFields(tab);
792
+ const draftAxis = hasDraftAxis(collection.schema, fields);
793
+ const draft = isDraftEntry(fields);
794
+ return html`
795
+ <div class="entry-editor-header">
796
+ <h3>${tab.documentPath?.split("/").pop() ?? "Untitled"}</h3>
797
+ <span class="entry-editor-collection">${collection.name}</span>
798
+ ${draftAxis ? html`
799
+ <sp-switch
800
+ size="s"
801
+ class="entry-draft-switch"
802
+ .checked=${live(draft)}
803
+ title=${DRAFT_MEANING}
804
+ @change=${(e) => setEntryDraft(tab, e.target.checked)}
805
+ >Draft</sp-switch
806
+ >
807
+ ` : nothing}
808
+ </div>
809
+ ${draft ? html`<p class="entry-editor-note">${DRAFT_MEANING}</p>` : nothing}
810
+ `;
811
+ }
812
+ function notAnEntryTpl(tab) {
813
+ return html`
814
+ <div class="entry-editor-empty">
815
+ <p>
816
+ ${tab.documentPath ?? "This document"} is not an entry of any content collection, so there
817
+ is no schema to draw a form from.
818
+ </p>
819
+ <p class="entry-editor-note">
820
+ A collection is a <code>content</code> entry in <code>project.json</code> whose
821
+ <code>source</code> directory contains this file and which declares a <code>schema</code>.
822
+ </p>
823
+ <sp-action-button
824
+ size="s"
825
+ @click=${() => {
826
+ activeRegistry()?.run("settings.open", { section: "content" });
827
+ }}
828
+ >Content types…</sp-action-button
829
+ >
830
+ </div>
831
+ `;
832
+ }
833
+ function renderEntryMode(surface, tab) {
834
+ const { paneId, wrap: canvasWrap } = surface;
835
+ if (entryPaneMounted(paneId, tab)) {
836
+ return;
837
+ }
838
+ detachEntryPane(paneId);
839
+ const scope = effectScope();
840
+ const panel = { paneId, scope, tabId: tab.id, wrap: canvasWrap };
841
+ _active.set(paneId, panel);
842
+ const rerender = () => {
843
+ if (activeIn(paneId) === panel) {
844
+ draw();
845
+ }
846
+ };
847
+ const draw = () => {
848
+ const collection = collectionOfPath(tab.documentPath);
849
+ if (!collection) {
850
+ render(html`<div class="entry-editor" data-jx-region=${paneRegion(paneId, "entry")}>
851
+ ${notAnEntryTpl(tab)}
852
+ </div>`, canvasWrap);
853
+ return;
854
+ }
855
+ const fields = entryFields(tab);
856
+ render(html`
857
+ <div class="entry-editor" data-jx-region=${paneRegion(paneId, "entry")}>
858
+ ${headerTpl(tab, collection)}
859
+ <div class="entry-editor-fields" data-jx-region=${paneRegion(paneId, "entry/fields")}>
860
+ ${renderForm(collection.schema, fields, {
861
+ context: formContext(tab),
862
+ errors: absentRequiredErrors(collection, fields),
863
+ onChange: (patch) => commitEntryFields(tab, patch),
864
+ rerender
865
+ })}
866
+ </div>
867
+ </div>
868
+ `, canvasWrap);
869
+ };
870
+ scope.run(() => {
871
+ effect(() => {
872
+ if (activeIn(paneId) !== panel) {
873
+ return;
874
+ }
875
+ tab.doc.document;
876
+ tab.doc.content?.frontmatter;
877
+ projectState?.projectConfig?.content;
878
+ draw();
879
+ });
880
+ });
881
+ }
882
+ async function openEntryEditor(path) {
883
+ const { openFileInTab } = await import("./files-0cratsr0.js");
884
+ await openFileInTab(path);
885
+ for (const [id, tab] of workspace.tabs.entries()) {
886
+ if (tab.documentPath !== path) {
887
+ continue;
888
+ }
889
+ for (const mode of ENTRY_TAB_MODES) {
890
+ if (!tab.capabilities.modes.includes(mode)) {
891
+ tab.capabilities.modes.unshift(mode);
892
+ }
893
+ }
894
+ tab.session.ui.canvasMode = ENTRY_MODE;
895
+ tab.session.ui.preview = false;
896
+ activateTab(id);
897
+ return tab;
898
+ }
899
+ return null;
900
+ }
901
+
902
+ // src/content/entry-commands.ts
903
+ function creatableCollections() {
904
+ return entryCollections().map((collection) => collection.name);
905
+ }
906
+ async function seedText(collection) {
907
+ const seed = seedEntry(collection.schema);
908
+ const formatName = (collection.def.format ? formatByName(collection.def.format)?.name : undefined) ?? formatForPath(`untitled${collection.ext}`)?.name ?? defaultContentFormat()?.name;
909
+ if (collection.ext === ".json" || formatName === undefined) {
910
+ return JSON.stringify(seed, null, 2);
911
+ }
912
+ return formatSerialize(formatName, { ...seed, children: [] }, { frontmatter: Object.keys(seed).length > 0, mode: "roundtrip" });
913
+ }
914
+ async function createEntry(collectionName, opts = {}) {
915
+ const collection = entryCollection(collectionName);
916
+ if (!collection) {
917
+ notify.error(`No content collection named "${collectionName}" to create an entry in.`, {
918
+ detail: "A collection needs a `content` entry in project.json whose `source` is a directory. A " + "collection whose source names a single file (a CSV catalogue) has rows, not entry files.",
919
+ source: "Content"
920
+ });
921
+ return null;
922
+ }
923
+ await loadFormats().catch(() => {});
924
+ let content;
925
+ try {
926
+ content = await seedText(collection);
927
+ } catch (error) {
928
+ notify.error(`Could not prepare a new ${collection.name} entry.`, {
929
+ detail: errorMessage(error),
930
+ path: collection.dir,
931
+ source: "Content"
932
+ });
933
+ return null;
934
+ }
935
+ const requested = opts.dir;
936
+ const destination = requested !== undefined && collectionForDirectory(requested)?.name === collection.name ? requested : collection.dir;
937
+ if (destination.includes(LOCALE_PLACEHOLDER)) {
938
+ notify.error(`"${collection.name}" is a localized collection.`, {
939
+ detail: `Its entries live in one directory per language (${collection.dir}). Open the folder for ` + "the language you are writing in and create the entry there.",
940
+ path: collection.dir,
941
+ source: "Content"
942
+ });
943
+ return null;
944
+ }
945
+ const { createFileIn } = await import("./files-0cratsr0.js");
946
+ const created = await createFileIn({
947
+ content,
948
+ dir: destination,
949
+ format: { ext: collection.ext, kind: "fixed" },
950
+ source: "Content",
951
+ suggestedName: "untitled",
952
+ title: `New ${collection.name} entry`
953
+ });
954
+ if (created === null) {
955
+ return null;
956
+ }
957
+ invalidateReferenceEntries(collection.name);
958
+ await openEntryEditor(created);
959
+ return created;
960
+ }
961
+ function activeEntryTab() {
962
+ const tab = activeTab.value;
963
+ return tab && collectionOfPath(tab.documentPath) ? tab : null;
964
+ }
965
+ function contentCommands() {
966
+ return [
967
+ {
968
+ args: argsSchema({
969
+ collection: derivedEnumProperty(creatableCollections, "The content collection the entry is created in.")
970
+ }),
971
+ category: "File",
972
+ id: "content.newEntry",
973
+ level: "project",
974
+ menus: ["palette"],
975
+ group: "1_file",
976
+ requires: "a project with a directory-backed content collection",
977
+ when: (ctx) => ctx.project.open,
978
+ enablement: () => creatableCollections().length > 0,
979
+ undo: "project",
980
+ aiTool: {
981
+ description: "Create a content entry in one of the project's collections, seeded from that collection's schema defaults, and open it in the entry form.",
982
+ name: "new_content_entry"
983
+ },
984
+ run: async (_ctx, args) => {
985
+ const names = creatableCollections();
986
+ await createEntry(enumArg("content.newEntry", args, "collection", names));
987
+ },
988
+ title: "New Entry"
989
+ },
990
+ {
991
+ args: argsSchema({
992
+ path: stringProperty("Project-relative path of the entry file to open.")
993
+ }),
994
+ category: "File",
995
+ id: "content.openEntry",
996
+ level: "project",
997
+ menus: ["context/file", "palette"],
998
+ group: "1_file",
999
+ requires: "an open project",
1000
+ when: (ctx) => ctx.project.open,
1001
+ aiTool: {
1002
+ description: "Open a content entry as a schema-driven form — its collection's fields, with a picker " + "for every reference to another collection.",
1003
+ name: "open_entry_form"
1004
+ },
1005
+ run: async (_ctx, args) => {
1006
+ await openEntryEditor(stringArg("content.openEntry", args, "path"));
1007
+ },
1008
+ title: "Open Entry Form"
1009
+ },
1010
+ {
1011
+ args: argsSchema({
1012
+ draft: booleanProperty("True marks the open entry a draft; false marks it published. Written as a `draft` field on the entry.")
1013
+ }),
1014
+ category: "Document",
1015
+ id: "content.setDraft",
1016
+ level: "document",
1017
+ menus: ["context/tab", "palette"],
1018
+ group: "3_document",
1019
+ requires: "a content entry open",
1020
+ when: (ctx) => ctx.document.open,
1021
+ enablement: () => activeEntryTab() !== null,
1022
+ undo: "document",
1023
+ aiTool: {
1024
+ description: "Mark the open content entry a draft, or published. Studio filters drafts out of its own lists; the build does not exclude them yet.",
1025
+ name: "set_entry_draft"
1026
+ },
1027
+ run: (_ctx, args) => {
1028
+ const tab = activeEntryTab();
1029
+ if (!tab) {
1030
+ throw new Error("content.setDraft: the active document is not a content entry");
1031
+ }
1032
+ setEntryDraft(tab, booleanArg("content.setDraft", args, "draft"));
1033
+ },
1034
+ title: "Set Draft"
1035
+ },
1036
+ {
1037
+ args: argsSchema({
1038
+ include: booleanProperty("True lists entries marked `draft: true` alongside the rest.")
1039
+ }),
1040
+ category: "View",
1041
+ id: "content.setIncludeDrafts",
1042
+ level: "project",
1043
+ menus: ["palette"],
1044
+ group: "2_view",
1045
+ requires: "an open project",
1046
+ when: (ctx) => ctx.project.open,
1047
+ aiTool: {
1048
+ description: "Choose whether draft entries appear in Studio's content listings.",
1049
+ name: "set_including_drafts"
1050
+ },
1051
+ run: async (_ctx, args) => {
1052
+ setIncludeDrafts(booleanArg("content.setIncludeDrafts", args, "include"));
1053
+ await reloadDraftAwareGrids();
1054
+ },
1055
+ title: "Include Drafts"
1056
+ }
1057
+ ];
1058
+ }
1059
+ function registerContentCommands(registry) {
1060
+ registry.registerAll(contentCommands());
1061
+ }
1062
+
1063
+ export { detectFieldFormat, fieldCardTpl, addFieldFormTpl, schemaForType, entryFields, entryPaneMounted, detachEntryPane, entryDraftPill, renderEntryMode, createEntry, contentCommands, registerContentCommands };
1064
+
1065
+ //# debugId=1103B912C500FD3E64756E2164756E21
1066
+ //# sourceMappingURL=studio-r1r7afxx.js.map