@exagone313/dsh-podman 1.7.0 → 1.8.1

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 (117) hide show
  1. package/cordis.patch.yml +3 -1
  2. package/dist/approval-reasons.d.ts +37 -0
  3. package/dist/approval-reasons.js +128 -0
  4. package/dist/approval-template-summary.d.ts +8 -0
  5. package/dist/approval-template-summary.js +163 -0
  6. package/dist/approval.d.ts +8 -4
  7. package/dist/approval.js +104 -10
  8. package/dist/client/ContainerCard.js +8 -2
  9. package/dist/client/container-card-controller.d.ts +13 -5
  10. package/dist/client/container-card-controller.js +60 -24
  11. package/dist/client/container-card-create-config.d.ts +23 -0
  12. package/dist/client/container-card-create-config.js +48 -0
  13. package/dist/client/container-card-create-modal.d.ts +9 -1
  14. package/dist/client/container-card-create-modal.js +37 -41
  15. package/dist/client/container-card-create-volume.d.ts +10 -0
  16. package/dist/client/container-card-create-volume.js +34 -0
  17. package/dist/client/container-card-dialog-styles.d.ts +4 -2
  18. package/dist/client/container-card-dialog-styles.js +47 -4
  19. package/dist/client/container-card-edit-modal.d.ts +5 -1
  20. package/dist/client/container-card-edit-modal.js +55 -19
  21. package/dist/client/container-card-editors.d.ts +9 -0
  22. package/dist/client/container-card-editors.js +300 -43
  23. package/dist/client/container-card-form.d.ts +2 -1
  24. package/dist/client/container-card-form.js +26 -8
  25. package/dist/client/container-card-images.js +9 -31
  26. package/dist/client/container-card-mount-actions.d.ts +12 -0
  27. package/dist/client/container-card-mount-actions.js +35 -0
  28. package/dist/client/container-card-mount-sources.d.ts +34 -0
  29. package/dist/client/container-card-mount-sources.js +180 -0
  30. package/dist/client/container-card-names.d.ts +2 -0
  31. package/dist/client/container-card-names.js +12 -0
  32. package/dist/client/container-card-row.d.ts +16 -1
  33. package/dist/client/container-card-row.js +69 -25
  34. package/dist/client/container-card-secrets.d.ts +2 -0
  35. package/dist/client/container-card-secrets.js +60 -17
  36. package/dist/client/container-card-shared.d.ts +17 -9
  37. package/dist/client/container-card-shared.js +122 -93
  38. package/dist/client/container-card-styles.d.ts +6 -0
  39. package/dist/client/container-card-styles.js +22 -0
  40. package/dist/client/container-card-table-styles.d.ts +2 -1
  41. package/dist/client/container-card-table-styles.js +14 -0
  42. package/dist/client/container-card-templates.d.ts +81 -0
  43. package/dist/client/container-card-templates.js +1004 -0
  44. package/dist/client/container-card-toast.js +1 -1
  45. package/dist/client/container-card-volumes.js +6 -20
  46. package/dist/client/container-card-workspace.d.ts +10 -2
  47. package/dist/client/container-card-workspace.js +98 -5
  48. package/dist/client/container-template-ui.d.ts +163 -0
  49. package/dist/client/container-template-ui.js +579 -0
  50. package/dist/client/download.d.ts +1 -0
  51. package/dist/client/download.js +23 -0
  52. package/dist/client/image-facts.d.ts +18 -0
  53. package/dist/client/image-facts.js +44 -0
  54. package/dist/client/index.js +13478 -3438
  55. package/dist/client/locales.d.ts +1 -1
  56. package/dist/client/locales.js +120 -0
  57. package/dist/client/podman-containers.js +47 -18
  58. package/dist/client/podman-terminal-guide.js +4 -2
  59. package/dist/client/podman-terminal.js +4 -2
  60. package/dist/client/template-client.d.ts +9 -0
  61. package/dist/client/template-client.js +52 -0
  62. package/dist/client/template-protocol.d.ts +60 -0
  63. package/dist/client/template-protocol.js +4 -0
  64. package/dist/client/terminal-errors.d.ts +11 -0
  65. package/dist/client/terminal-errors.js +26 -0
  66. package/dist/client/terminal-protocol.d.ts +5 -0
  67. package/dist/client/terminal-protocol.js +5 -0
  68. package/dist/client/terminal-styles.d.ts +2 -1
  69. package/dist/client/terminal-styles.js +9 -1
  70. package/dist/client/terminal-transport.d.ts +17 -2
  71. package/dist/client/terminal-transport.js +31 -8
  72. package/dist/client/tool-presentations.d.ts +32 -0
  73. package/dist/client/tool-presentations.js +33 -0
  74. package/dist/client/tool-views.js +17 -7
  75. package/dist/client/workspace-target.d.ts +54 -0
  76. package/dist/client/workspace-target.js +86 -0
  77. package/dist/container-template.d.ts +153 -0
  78. package/dist/container-template.js +1058 -0
  79. package/dist/generated/version.d.ts +2 -2
  80. package/dist/generated/version.js +2 -2
  81. package/dist/grpc/proto/dshguest/v1/guest.proto +11 -0
  82. package/dist/guest-rpc.d.ts +1 -0
  83. package/dist/guest-rpc.js +12 -0
  84. package/dist/index.js +7 -1
  85. package/dist/mount-enums.d.ts +2 -0
  86. package/dist/mount-enums.js +17 -0
  87. package/dist/mount-order.d.ts +14 -0
  88. package/dist/mount-order.js +49 -0
  89. package/dist/project-path.d.ts +14 -0
  90. package/dist/project-path.js +25 -0
  91. package/dist/template-apply.d.ts +21 -0
  92. package/dist/template-apply.js +102 -0
  93. package/dist/template-files.d.ts +23 -0
  94. package/dist/template-files.js +186 -0
  95. package/dist/template-image.d.ts +22 -0
  96. package/dist/template-image.js +80 -0
  97. package/dist/template-route.d.ts +9 -0
  98. package/dist/template-route.js +278 -0
  99. package/dist/terminal-route.js +49 -7
  100. package/dist/tool-defs.js +27 -1
  101. package/dist/tool-handlers.js +69 -1
  102. package/dist/tool-params.d.ts +38 -0
  103. package/dist/tool-params.js +30 -0
  104. package/docs/README.md +4 -3
  105. package/docs/architecture.md +42 -12
  106. package/docs/architecture.zh.md +22 -8
  107. package/docs/configuration.md +19 -20
  108. package/docs/configuration.zh.md +3 -4
  109. package/docs/development-prompt.md +49 -45
  110. package/docs/development-prompt.zh.md +47 -43
  111. package/docs/development.md +46 -28
  112. package/docs/development.zh.md +60 -46
  113. package/docs/uninstall.md +3 -3
  114. package/docs/uninstall.zh.md +2 -2
  115. package/docs/usage.md +155 -23
  116. package/docs/usage.zh.md +104 -14
  117. package/package.json +6 -5
@@ -0,0 +1,1004 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { EnvEditor, MountsEditor } from "./container-card-editors.js";
3
+ import { PathsEditor } from "./container-card-paths.js";
4
+ import { PortsEditor } from "./container-card-ports.js";
5
+ import { SecretEnvEditor, SecretModal } from "./container-card-secrets.js";
6
+ import { CreateVolumeModal } from "./container-card-create-volume.js";
7
+ import { DirectoryPickerModal } from "./container-card-directory.js";
8
+ import { TEMPLATE_DIALOG_CLASS, TEMPLATE_DIALOG_CONTENT_CLASS, } from "./container-card-dialog-styles.js";
9
+ import { ImageFacts } from "./image-facts.js";
10
+ import { Chip, DialogGroup, ImageRow } from "./container-card-shared.js";
11
+ import { ROW_LIST_CLASS } from "./container-card-table-styles.js";
12
+ import { templateBlockReason, templateChoiceActionable, templateConfigForEditor, templateDisplayName, templateDraftImageFacts, templateDraftMissingReferences, templateDraftReferences, templateImageAction, templateImageCandidates, templateProjectChecksEqual, templateProjectPathDecision, templateProjectPathError, templateSpecSummary, templateSummaryAccessibleLabel, templateSummaryLineText, templateSummarySegments, } from "./container-template-ui.js";
13
+ import { blockFields, businessAction, fieldGroup, fieldGroupLabel, hint, missingValue, rowMeta, rowName, templateAction, templateActionSelected, } from "./container-card-styles.js";
14
+ import { decideProjectPath, hostPathForProjectName, projectNameFromHostPath, } from "../project-path.js";
15
+ import { Button, IconCheckOutlineRegular, Input, Modal, SegmentedControl, } from "@deepseek-ai/dsh-client-ui-primitives";
16
+ import { useCallback, useEffect, useId, useMemo, useRef, useState, } from "react";
17
+ // The error line a popup shows for a failed read or build.
18
+ const errorText = {
19
+ margin: 0,
20
+ color: "var(--dsw-alias-state-error)",
21
+ };
22
+ // The column the details popup stacks its header, summary and sections in. The
23
+ // gap is what separates the blocks; each section paints its own surface.
24
+ const detailsBody = {
25
+ display: "flex",
26
+ flexDirection: "column",
27
+ gap: "12px",
28
+ };
29
+ // The details popup's header: the file name under the template name the Modal
30
+ // title already carries, then the destination choice at the top of the flow.
31
+ const detailsHeader = {
32
+ display: "flex",
33
+ flexDirection: "column",
34
+ gap: "10px",
35
+ };
36
+ // The template's file name: muted beneath its name, never a section title.
37
+ const detailsFile = {
38
+ ...rowMeta,
39
+ margin: 0,
40
+ };
41
+ // The destination choice and the line that explains where Continue will go.
42
+ const destinationBlock = {
43
+ display: "flex",
44
+ flexDirection: "column",
45
+ alignItems: "flex-start",
46
+ gap: "6px",
47
+ };
48
+ // The one line under the destination control: Create names the next step, and
49
+ // Replace's own list names the target.
50
+ const destinationHint = {
51
+ ...hint,
52
+ margin: 0,
53
+ };
54
+ // The details popup's footer: the reason slot on the left, the actions
55
+ // right-aligned. The slot is always rendered, so the actions keep their place
56
+ // whether or not a reason is present.
57
+ const footerRow = {
58
+ display: "flex",
59
+ alignItems: "center",
60
+ gap: "8px",
61
+ width: "100%",
62
+ };
63
+ // The details popup's reason slot: a blocking reason explains why Continue is
64
+ // disabled. It lives in the sticky footer, not in the scrolling body, so it
65
+ // stays visible while the sections scroll.
66
+ const footerReason = {
67
+ flex: "1 1 auto",
68
+ minHeight: "18px",
69
+ fontSize: "12px",
70
+ lineHeight: 1.4,
71
+ color: "var(--dsw-alias-label-tertiary)",
72
+ textAlign: "left",
73
+ };
74
+ // A blocking reason, in the harness's error colour — the one mount errors use.
75
+ const footerReasonError = {
76
+ ...footerReason,
77
+ color: "var(--dsw-alias-state-error-primary)",
78
+ };
79
+ const footerActions = {
80
+ display: "flex",
81
+ alignItems: "center",
82
+ gap: "8px",
83
+ flex: "none",
84
+ };
85
+ // The replace target's column: the filter above the bounded list of choices.
86
+ const replaceBlock = {
87
+ display: "flex",
88
+ flexDirection: "column",
89
+ gap: "6px",
90
+ width: "100%",
91
+ };
92
+ // The bounded list of containers a replace can target: a workspace with many
93
+ // containers scrolls this list instead of the whole dialog, and each row is the
94
+ // picker's full-width outlined control.
95
+ const replaceList = {
96
+ display: "flex",
97
+ flexDirection: "column",
98
+ gap: "8px",
99
+ maxHeight: "180px",
100
+ overflowY: "auto",
101
+ scrollbarGutter: "stable",
102
+ padding: "2px",
103
+ };
104
+ // The picker's choices: one column, each row a full-width control.
105
+ const choiceList = {
106
+ display: "flex",
107
+ flexDirection: "column",
108
+ gap: "8px",
109
+ };
110
+ // The text column of a picker row: the template's name over its one metadata
111
+ // line, both starting at the row's left edge.
112
+ const choiceText = {
113
+ display: "flex",
114
+ flexDirection: "column",
115
+ gap: "2px",
116
+ minWidth: 0,
117
+ flex: "1 1 auto",
118
+ };
119
+ // A picker row's name line.
120
+ const choiceName = {
121
+ ...rowName,
122
+ fontSize: "14px",
123
+ fontWeight: 500,
124
+ lineHeight: "20px",
125
+ color: "var(--dsw-alias-label-primary)",
126
+ };
127
+ // A picker row's name line when it also carries a chip: the name, then the
128
+ // badge that marks an uploaded file.
129
+ const choiceNameRow = {
130
+ display: "flex",
131
+ alignItems: "center",
132
+ gap: "6px",
133
+ minWidth: 0,
134
+ };
135
+ // A one-line secondary value that truncates rather than wrapping, so a replace
136
+ // option keeps the same two-line shape whatever image id it names.
137
+ const choiceMeta = {
138
+ ...rowMeta,
139
+ maxWidth: "100%",
140
+ overflow: "hidden",
141
+ textOverflow: "ellipsis",
142
+ whiteSpace: "nowrap",
143
+ lineHeight: "18px",
144
+ };
145
+ // A picker row's facts line: every category in one wrapping line. It never
146
+ // truncates or nowrap-clips a value; the button's own height grows with the
147
+ // lines the facts need, so long names stay whole and rows take their own height.
148
+ const choiceFacts = {
149
+ ...rowMeta,
150
+ lineHeight: "18px",
151
+ whiteSpace: "normal",
152
+ overflowWrap: "anywhere",
153
+ };
154
+ // The error block an invalid file shows in the metadata slot: the harness's
155
+ // error tone on a soft tint, wrapping over as many lines as the parser's reason
156
+ // needs so nothing the user can act on is hidden.
157
+ const choiceInvalid = {
158
+ alignSelf: "flex-start",
159
+ maxWidth: "100%",
160
+ padding: "0 8px",
161
+ borderRadius: "6px",
162
+ fontSize: "12px",
163
+ fontWeight: 500,
164
+ lineHeight: "20px",
165
+ color: "var(--dsw-alias-state-error-primary)",
166
+ background: "color-mix(in srgb, var(--dsw-alias-state-error-primary) 14%, transparent)",
167
+ whiteSpace: "pre-wrap",
168
+ overflowWrap: "anywhere",
169
+ };
170
+ // The metrics shared by every choice row in either popup: a full-width outlined
171
+ // control whose first line is top-aligned with the selection check, and whose
172
+ // whole box — not just the text — is what hover and focus outline.
173
+ const choiceMetrics = {
174
+ width: "100%",
175
+ height: "auto",
176
+ padding: "10px 12px",
177
+ alignItems: "flex-start",
178
+ justifyContent: "flex-start",
179
+ textAlign: "left",
180
+ whiteSpace: "normal",
181
+ };
182
+ // A picker row: the harness's outlined control, stretched to hold as many lines
183
+ // as its facts need, painted with the shared violet when it is the current
184
+ // choice.
185
+ function choiceStyle(selected) {
186
+ return {
187
+ ...choiceMetrics,
188
+ ...(selected ? templateActionSelected : {}),
189
+ };
190
+ }
191
+ // A replace row: the same outlined control, painted with the business blue when
192
+ // it is the chosen container, so the target reads like the Recreate action
193
+ // rather than the templates' violet accent.
194
+ function replaceChoiceStyle(selected) {
195
+ return {
196
+ ...choiceMetrics,
197
+ ...(selected ? businessAction : {}),
198
+ };
199
+ }
200
+ // The upload control under the picker's list: its label names the action and
201
+ // the native file input below it is what the browser draws.
202
+ const uploadField = {
203
+ ...fieldGroup,
204
+ ...fieldGroupLabel,
205
+ whiteSpace: "normal",
206
+ textAlign: "left",
207
+ cursor: "pointer",
208
+ };
209
+ // The description slot of one picker row, for a project template and an upload
210
+ // alike: the parsed template's labelled facts in full, or the parser's full
211
+ // reason in a wrapping error block when the file does not parse. There is no
212
+ // tooltip: nothing is hidden to repeat, and both lines wrap instead of
213
+ // truncating.
214
+ function PickerDescription(props) {
215
+ const { t, summary } = props;
216
+ if (summary === undefined)
217
+ return null;
218
+ if (!summary.valid) {
219
+ return _jsx("span", { style: choiceInvalid, children: summary.reason });
220
+ }
221
+ return (_jsx("span", { style: choiceFacts, children: templateSummaryLineText(templateSummarySegments(t, summary)) }));
222
+ }
223
+ // blockingReasonText is the one line that says why Continue is disabled. It
224
+ // never restates a state another part of the popup already carries: the loading
225
+ // hint and the image card (with a build failure's own message) report
226
+ // themselves. Every line it returns is a blocking reason, so the footer paints
227
+ // it in the error colour and announces it as an alert.
228
+ function blockingReasonText(t, block, building, missingReferences) {
229
+ switch (block) {
230
+ case "build":
231
+ return building ? undefined : t("templateBuildRequired");
232
+ case "image-missing":
233
+ return t("templateImageMissing");
234
+ case "checking":
235
+ return t("templateCheckingReferences");
236
+ case "missing-references":
237
+ return missingReferences === 1
238
+ ? t("templateReferenceMissingOne")
239
+ : t("templateReferenceMissingMany", { n: String(missingReferences) });
240
+ case "no-container":
241
+ return t("templateNoContainer");
242
+ default:
243
+ return undefined;
244
+ }
245
+ }
246
+ // TemplatePickerModal is the first popup: it lists the project's templates and
247
+ // offers an upload. Choosing one only changes this popup's selection; Next is
248
+ // the explicit step that opens the details popup, and nothing is inspected,
249
+ // built or created here.
250
+ function TemplatePickerModal(props) {
251
+ const { t, open, workspace, busy, actions, onClose, onChoose } = props;
252
+ const [entries, setEntries] = useState(null);
253
+ const [selected, setSelected] = useState("");
254
+ const [upload, setUpload] = useState(null);
255
+ const [error, setError] = useState("");
256
+ const actionsRef = useRef(actions);
257
+ actionsRef.current = actions;
258
+ // Opening lists the project's templates and resets the choice. It never
259
+ // preselects an entry: the user's own choice is the point of this step.
260
+ useEffect(() => {
261
+ if (!open)
262
+ return;
263
+ const controller = new AbortController();
264
+ setEntries(null);
265
+ setSelected("");
266
+ setUpload(null);
267
+ setError("");
268
+ void actionsRef.current.listTemplates(workspace.workspaceSlug, controller.signal).then((listed) => {
269
+ if (controller.signal.aborted)
270
+ return;
271
+ setEntries(listed);
272
+ }, (failure) => {
273
+ if (controller.signal.aborted)
274
+ return;
275
+ setEntries([]);
276
+ setError(failure instanceof Error ? failure.message : String(failure));
277
+ });
278
+ return () => controller.abort();
279
+ }, [open, workspace.workspaceSlug]);
280
+ const selectedEntry = entries?.find((entry) => entry.name === selected);
281
+ const choice = upload ?? selectedEntry;
282
+ // Each row's description, and the uploaded file's: what the parsed template
283
+ // does, never a guess at its image or a re-read of its file name. Parsing is
284
+ // local and read-only, so listing never calls the host more than once.
285
+ const summaries = useMemo(() => {
286
+ const map = new Map();
287
+ for (const entry of entries ?? []) {
288
+ map.set(entry.name, templateSpecSummary(entry.yaml));
289
+ }
290
+ return map;
291
+ }, [entries]);
292
+ const uploadSummary = useMemo(() => (upload === null ? undefined : templateSpecSummary(upload.yaml)), [upload]);
293
+ // The summary Next acts on: the upload's own parse when it is the choice, the
294
+ // selected project entry's otherwise. A choice without a summary stays
295
+ // disabled, so Next never opens details for a file the picker could not read.
296
+ const choiceSummary = upload !== null
297
+ ? uploadSummary
298
+ : selectedEntry === undefined
299
+ ? undefined
300
+ : summaries.get(selectedEntry.name);
301
+ const nextEnabled = templateChoiceActionable(choiceSummary, busy);
302
+ // The footer carries only the actions. The disabled Next's reason is the row's
303
+ // own wrapping error block — the one explanation — so it is never repeated
304
+ // here; no choice and a missing summary are defensively disabled silently.
305
+ const footer = (_jsxs("div", { style: footerActions, children: [_jsx(Button, { variant: "outline", size: "sm", onClick: onClose, children: t("cancel") }), _jsx(Button, { variant: "outline", size: "sm", style: templateAction, disabled: !nextEnabled, onClick: () => {
306
+ if (!templateChoiceActionable(choiceSummary, busy))
307
+ return;
308
+ if (choice === undefined)
309
+ return;
310
+ onChoose({
311
+ name: choice.name,
312
+ yaml: choice.yaml,
313
+ });
314
+ }, children: t("templateNext") })] }));
315
+ return (_jsx(Modal, { open: open, onClose: onClose, title: t("loadTemplate"), description: t("templatePickHint"), closeLabel: t("cancel"), className: TEMPLATE_DIALOG_CLASS, contentClassName: TEMPLATE_DIALOG_CONTENT_CLASS, footer: footer, children: _jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "16px" }, children: [error === "" ? null : (_jsx("p", { role: "alert", style: errorText, children: error })), entries === null
316
+ ? _jsx("p", { style: hint, role: "status", children: t("templateLoading") })
317
+ : entries.length === 0 && upload === null
318
+ ? _jsx("p", { style: hint, children: t("templateNone") })
319
+ : (_jsxs("div", { role: "group", "aria-label": t("templateChoose"), style: choiceList, children: [entries.map((entry) => {
320
+ const isSelected = upload === null && selected === entry.name;
321
+ return (_jsxs(Button, { variant: "outline", size: "md", title: entry.name, "aria-label": templateSummaryAccessibleLabel(t, templateDisplayName(entry.name), summaries.get(entry.name)), "aria-pressed": isSelected, style: choiceStyle(isSelected), onClick: () => {
322
+ setUpload(null);
323
+ setSelected(entry.name);
324
+ }, children: [_jsxs("span", { style: choiceText, children: [_jsx("span", { style: choiceName, children: templateDisplayName(entry.name) }), _jsx(PickerDescription, { t: t, summary: summaries.get(entry.name) })] }), isSelected ? _jsx(IconCheckOutlineRegular, { size: 16 }) : null] }, entry.name));
325
+ }), upload === null ? null : (_jsxs(Button, { variant: "outline", size: "md", title: upload.name, "aria-label": templateSummaryAccessibleLabel(t, templateDisplayName(upload.name), uploadSummary), "aria-pressed": true, style: choiceStyle(true), onClick: () => setSelected(""), children: [_jsxs("span", { style: choiceText, children: [_jsxs("span", { style: choiceNameRow, children: [_jsx("span", { style: choiceName, children: templateDisplayName(upload.name) }), _jsx(Chip, { t: t, label: t("templateUploadChip") })] }), _jsx(PickerDescription, { t: t, summary: uploadSummary })] }), _jsx(IconCheckOutlineRegular, { size: 16 })] }))] })), _jsxs("label", { style: uploadField, children: [t("templateUpload"), _jsx("input", { type: "file", accept: ".yml,.yaml,application/yaml,text/yaml", disabled: busy, style: { marginTop: "6px" }, onChange: (event) => {
326
+ const file = event.target.files?.[0];
327
+ event.target.value = "";
328
+ if (file === undefined)
329
+ return;
330
+ void file.text().then((yaml) => {
331
+ setSelected("");
332
+ setUpload({ name: file.name, yaml });
333
+ });
334
+ } })] })] }) }));
335
+ }
336
+ // TemplateDetailsModal is the second popup: it edits what the chosen template
337
+ // will stage, whether its image exists or needs building, and the destination
338
+ // choice. The draft is seeded from the template and every group is bound to it
339
+ // through the container editor's own components; Build is a deliberate action
340
+ // here, and Continue only opens the prefilled editor once the image is ready
341
+ // and every reference exists. Nothing is created from this popup.
342
+ function TemplateDetailsModal(props) {
343
+ const { t, locale, open, workspace, containers, images, volumes, secrets, defaultEnv, projectsRoot, directoryPicker, busy, writable, gatewayUnavailable, actions, onBuildImage, onRebuildImage, onRebuildBaseImage, onPullBaseImage, onCreateSecret, createVolume, onReload, selection, initialDraft, initialMode, initialReplaceTarget, initialReplaceFilter, onBack, onClose, onContinue, } = props;
344
+ const [inspection, setInspection] = useState(null);
345
+ // The draft every group edits and Continue hands on. It is seeded when a
346
+ // freshly inspected template arrives and reset when the popup reopens or the
347
+ // selection changes; a later re-read (a build's check) never overwrites it.
348
+ const [draft, setDraft] = useState(null);
349
+ const [error, setError] = useState("");
350
+ const [building, setBuilding] = useState(false);
351
+ const [buildFailed, setBuildFailed] = useState("");
352
+ const [mode, setMode] = useState("create");
353
+ const [replaceTarget, setReplaceTarget] = useState(containers[0]?.containerName ?? "");
354
+ // The replace list's filter; it is shown only when the workspace holds more
355
+ // containers than the list shows at once.
356
+ const [replaceFilter, setReplaceFilter] = useState("");
357
+ // The project path checks, keyed by the mount's index in the draft.
358
+ const [projectChecks, setProjectChecks] = useState({});
359
+ // The same map as a ref, so a re-check can tell an answer it already holds
360
+ // from one it still has to ask the host about.
361
+ const projectChecksRef = useRef(projectChecks);
362
+ projectChecksRef.current = projectChecks;
363
+ // The project values the host is listing right now, keyed by the mount's
364
+ // index. It is kept apart from the settled checks, so the answer a row already
365
+ // holds stays stored — and stays readable as its error — while a changed value
366
+ // is checked again.
367
+ const [projectChecksInFlight, setProjectChecksInFlight] = useState({});
368
+ // The storage dialogs the popup's Create volume / Create secret actions open,
369
+ // and the project row whose row-action Browse is open.
370
+ const [volumeCreateOpen, setVolumeCreateOpen] = useState(false);
371
+ const [secretCreateOpen, setSecretCreateOpen] = useState(false);
372
+ const [projectBrowse, setProjectBrowse] = useState(undefined);
373
+ const destinationId = useId();
374
+ // The popup's host callbacks and the container list arrive as props; a
375
+ // snapshot refresh re-renders the parent, and effect identities must not
376
+ // restart an inspection or reset a draft for that.
377
+ const actionsRef = useRef(actions);
378
+ actionsRef.current = actions;
379
+ const containersRef = useRef(containers);
380
+ containersRef.current = containers;
381
+ const selectionRef = useRef(selection);
382
+ selectionRef.current = selection;
383
+ const draftRef = useRef(draft);
384
+ draftRef.current = draft;
385
+ const defaultEnvRef = useRef(defaultEnv);
386
+ defaultEnvRef.current = defaultEnv;
387
+ const tRef = useRef(t);
388
+ tRef.current = t;
389
+ const pickerRef = useRef(directoryPicker);
390
+ pickerRef.current = directoryPicker;
391
+ const projectsRootRef = useRef(projectsRoot);
392
+ projectsRootRef.current = projectsRoot;
393
+ // A token that invalidates a project check once the draft, the popup or a
394
+ // newer check replaces it.
395
+ const checkToken = useRef(0);
396
+ // Opening on a newly chosen template starts from a clean plan, a clear draft
397
+ // and the Create destination; nothing from a previous choice survives. A
398
+ // resumed open takes the draft and destination the editor's Back came from
399
+ // instead, while the template is still inspected below. Closing also dismisses
400
+ // any storage dialog or directory browser opened on top of it.
401
+ useEffect(() => {
402
+ if (!open) {
403
+ setVolumeCreateOpen(false);
404
+ setSecretCreateOpen(false);
405
+ setProjectBrowse(undefined);
406
+ return;
407
+ }
408
+ checkToken.current += 1;
409
+ setInspection(null);
410
+ setDraft(initialDraft ?? null);
411
+ setError("");
412
+ setBuilding(false);
413
+ setBuildFailed("");
414
+ setMode(initialMode ?? "create");
415
+ setReplaceTarget(initialReplaceTarget ?? containersRef.current[0]?.containerName ?? "");
416
+ setReplaceFilter(initialReplaceFilter ?? "");
417
+ setProjectChecks({});
418
+ setProjectChecksInFlight({});
419
+ setVolumeCreateOpen(false);
420
+ setSecretCreateOpen(false);
421
+ setProjectBrowse(undefined);
422
+ }, [
423
+ open,
424
+ selection,
425
+ initialDraft,
426
+ initialMode,
427
+ initialReplaceTarget,
428
+ initialReplaceFilter,
429
+ ]);
430
+ // Inspecting only records the plan (image state, template and id). It never
431
+ // starts a build: that is the Build button's job below. The first plan seeds
432
+ // the draft; a re-read after a build leaves the user's edits alone. A resumed
433
+ // open already holds the draft the editor's Back came from, so the plan only
434
+ // refreshes the image state and never reseeds it.
435
+ useEffect(() => {
436
+ if (!open || selection === null)
437
+ return;
438
+ const controller = new AbortController();
439
+ setInspection(null);
440
+ setError("");
441
+ setBuildFailed("");
442
+ void actionsRef.current.inspectTemplate({
443
+ op: "inspect",
444
+ workspace: workspace.workspaceSlug,
445
+ name: selection.name,
446
+ yaml: selection.yaml,
447
+ }, controller.signal).then((inspected) => {
448
+ if (controller.signal.aborted)
449
+ return;
450
+ setInspection(inspected);
451
+ setDraft((previous) => previous ??
452
+ templateConfigForEditor(inspected.template, inspected.imageId, {
453
+ defaultEnv: defaultEnvRef.current,
454
+ }));
455
+ }, (failure) => {
456
+ if (controller.signal.aborted)
457
+ return;
458
+ setError(failure instanceof Error ? failure.message : String(failure));
459
+ });
460
+ return () => controller.abort();
461
+ }, [open, selection, workspace.workspaceSlug]);
462
+ // inspectNow re-reads the template's plan through the host route. The route
463
+ // lists the images when it runs, so the answer is the state at this moment:
464
+ // the popup never derives it from the card's cached image snapshot.
465
+ const inspectNow = async (signal) => {
466
+ const current = selectionRef.current;
467
+ if (current === null)
468
+ throw new Error("no template is selected");
469
+ return await actionsRef.current.inspectTemplate({
470
+ op: "inspect",
471
+ workspace: workspace.workspaceSlug,
472
+ name: current.name,
473
+ yaml: current.yaml,
474
+ }, signal);
475
+ };
476
+ // recheckAfterBuild reads the plan again once a build has finished, whatever
477
+ // its outcome. A failed build, or an image that was removed while the build
478
+ // ran, therefore shows as needing a build instead of leaving the popup on a
479
+ // plan cached when it opened. It never clears the failure message: a failed
480
+ // rebuild leaves the plan ready, and its failure must stay on screen until
481
+ // the user tries again. A re-check that fails itself changes nothing.
482
+ const recheckAfterBuild = async () => {
483
+ try {
484
+ setInspection(await inspectNow());
485
+ }
486
+ catch {
487
+ // Keep the build result (or its failure) when the re-check itself fails.
488
+ }
489
+ };
490
+ // The image card's one action. Progress is shown by the button's own busy
491
+ // label; a success replaces the plan with the built image, and a failure
492
+ // leaves its message under the card. `force` is the Rebuild action: it asks
493
+ // the host to rebuild an image the plan already considers current. Continue
494
+ // stays disabled by templateBlockReason while this runs and after a failure.
495
+ // The plan is read again before the busy state ends, so the button and the
496
+ // image state never describe an image that is no longer there.
497
+ const build = async (force) => {
498
+ if (selection === null || inspection === null || building)
499
+ return;
500
+ setBuilding(true);
501
+ setBuildFailed("");
502
+ try {
503
+ const built = await actionsRef.current.buildTemplate({
504
+ op: "build",
505
+ workspace: workspace.workspaceSlug,
506
+ name: selection.name,
507
+ yaml: selection.yaml,
508
+ ...(force ? { force: true } : {}),
509
+ });
510
+ setInspection(built);
511
+ onReload();
512
+ }
513
+ catch (failure) {
514
+ setBuildFailed(failure instanceof Error ? failure.message : String(failure));
515
+ }
516
+ finally {
517
+ await recheckAfterBuild();
518
+ setBuilding(false);
519
+ }
520
+ };
521
+ // runImageAction dispatches the image card's one button. The template's own
522
+ // image goes through the template build route, where a Rebuild is the same
523
+ // call with `force`; every other image runs exactly the command the Images
524
+ // tab's own row runs, and the snapshot is refreshed afterwards so the card
525
+ // and its action describe the image the command left behind. Nothing here
526
+ // writes a container: Continue is still the only way to the editor.
527
+ const runImageAction = (decision) => {
528
+ const current = draftRef.current;
529
+ if (current === null)
530
+ return;
531
+ const imageId = current.image;
532
+ switch (decision.command) {
533
+ case "template-build":
534
+ void build(false);
535
+ return;
536
+ case "template-rebuild":
537
+ void build(true);
538
+ return;
539
+ case "custom-build": {
540
+ const image = images.find((candidate) => candidate.imageId === imageId);
541
+ if (image === undefined)
542
+ return;
543
+ onBuildImage(image.imageId, image.parent, [...image.packages]);
544
+ break;
545
+ }
546
+ case "custom-rebuild":
547
+ onRebuildImage(imageId);
548
+ break;
549
+ case "base-build":
550
+ case "base-rebuild":
551
+ onRebuildBaseImage(imageId);
552
+ break;
553
+ case "base-pull":
554
+ onPullBaseImage(imageId);
555
+ break;
556
+ case "none":
557
+ return;
558
+ }
559
+ // The template route re-reads its own plan once the build returns; every
560
+ // other command only asks the card for a fresh snapshot.
561
+ onReload();
562
+ };
563
+ // checkProjects validates every project mount's path the way the mount editor
564
+ // does: lexically first, then by listing the directory through the host
565
+ // picker. It runs only when the popup opens or seeds a draft, when a project
566
+ // field loses focus, and once before Continue — never on a keystroke, so
567
+ // typing performs no host call. Every answer is keyed to the draft it was
568
+ // started for, so a stale listing never marks a newer draft. It reports
569
+ // whether every path is known to exist, which is what Continue waits for.
570
+ const checkProjects = useCallback(async (target) => {
571
+ const current = target ?? draftRef.current;
572
+ if (current === null)
573
+ return true;
574
+ const token = ++checkToken.current;
575
+ const picker = pickerRef.current;
576
+ const root = projectsRootRef.current;
577
+ const next = {};
578
+ // The value each row's host check is listing right now, so the row can say
579
+ // it is pending until that answer lands.
580
+ const inFlight = {};
581
+ const pending = [];
582
+ let lexicalOk = true;
583
+ current.mounts.forEach((mount, index) => {
584
+ if (mount.kind !== "project" || mount.project.trim() === "")
585
+ return;
586
+ const lexical = decideProjectPath({
587
+ origin: "typed",
588
+ project: mount.project,
589
+ directoryExists: true,
590
+ });
591
+ if (!lexical.ok) {
592
+ lexicalOk = false;
593
+ next[index] = {
594
+ state: "error",
595
+ project: mount.project,
596
+ error: templateProjectPathError(tRef.current, mount.project, lexical.reason),
597
+ };
598
+ return;
599
+ }
600
+ if (picker === undefined) {
601
+ next[index] = { state: "ok", project: mount.project };
602
+ return;
603
+ }
604
+ // The answer the row already holds stays stored while the re-check runs,
605
+ // so a row that failed keeps naming its failure — and keeps its error
606
+ // paragraph mounted — until this check resolves. The pending state is
607
+ // tracked beside the checks, never written over the stored answer.
608
+ const settled = projectChecksRef.current[index];
609
+ if (settled !== undefined && settled.state !== "pending") {
610
+ next[index] = settled;
611
+ }
612
+ inFlight[index] = mount.project;
613
+ pending.push(templateProjectPathDecision({
614
+ project: mount.project,
615
+ projectsRoot: root,
616
+ listDirectory: (path) => picker.list(path),
617
+ }).then((decision) => {
618
+ if (token !== checkToken.current)
619
+ return false;
620
+ const answer = decision.ok
621
+ ? { state: "ok", project: mount.project }
622
+ : {
623
+ state: "error",
624
+ project: mount.project,
625
+ error: templateProjectPathError(tRef.current, mount.project, decision.reason),
626
+ };
627
+ // An answer that repeats the stored one is not written back, so a
628
+ // re-check never renders the popup for no reason.
629
+ setProjectChecks((previous) => {
630
+ const updated = { ...previous, [index]: answer };
631
+ return templateProjectChecksEqual(previous, updated)
632
+ ? previous
633
+ : updated;
634
+ });
635
+ // This row is no longer pending: the answer above is the one the row
636
+ // and its error now report.
637
+ setProjectChecksInFlight((previous) => {
638
+ if (previous[index] !== mount.project)
639
+ return previous;
640
+ const updated = { ...previous };
641
+ delete updated[index];
642
+ return updated;
643
+ });
644
+ return decision.ok;
645
+ }));
646
+ });
647
+ setProjectChecks((previous) => templateProjectChecksEqual(previous, next) ? previous : next);
648
+ setProjectChecksInFlight(inFlight);
649
+ const results = await Promise.all(pending);
650
+ if (token !== checkToken.current)
651
+ return false;
652
+ return lexicalOk && results.every((ok) => ok);
653
+ }, []);
654
+ // A freshly seeded draft is checked once the moment it appears; later edits
655
+ // wait for the field's blur or Continue, so typing never asks the host. A
656
+ // resumed draft is seeded from the payload instead, so its own effect below
657
+ // is the one that checks it.
658
+ const draftSeeded = draft !== null;
659
+ useEffect(() => {
660
+ if (!open || !draftSeeded || initialDraft !== undefined)
661
+ return;
662
+ void checkProjects();
663
+ }, [open, draftSeeded, initialDraft, checkProjects]);
664
+ // A resumed draft is already non-null when the popup opens, so the effect
665
+ // above never sees the null-to-draft transition: its project paths are
666
+ // checked once here, exactly as a freshly seeded draft is checked on open.
667
+ useEffect(() => {
668
+ if (!open || initialDraft === undefined)
669
+ return;
670
+ void checkProjects(initialDraft);
671
+ }, [open, initialDraft, checkProjects]);
672
+ // projectCheck is the state the current draft's row shows. A check started
673
+ // for another value is not this row's answer, so the value's lexical decision
674
+ // stands instead; a changed value the host is listing right now reports
675
+ // pending. A mount added or removed before a row shifts its index, so a check
676
+ // stored for the same path under another index still answers it. A host
677
+ // failure already found on the row stays on screen while the user types — only
678
+ // a blur re-checks it — and the lexical check still reports an invalid shape
679
+ // immediately.
680
+ const projectCheck = (index, project) => {
681
+ const stored = projectChecks[index];
682
+ // The field's value changed and the host is listing it now: this row is
683
+ // pending, while the answer stored for it stays put and stays readable as
684
+ // the row's message until the check resolves.
685
+ if (projectChecksInFlight[index] === project &&
686
+ (stored === undefined || stored.project !== project)) {
687
+ return { state: "pending", project };
688
+ }
689
+ const checked = stored !== undefined && stored.project === project
690
+ ? stored
691
+ : Object.values(projectChecks).find((check) => check.project === project);
692
+ if (checked !== undefined)
693
+ return checked;
694
+ const lexical = decideProjectPath({
695
+ origin: "typed",
696
+ project,
697
+ directoryExists: true,
698
+ });
699
+ if (!lexical.ok) {
700
+ return {
701
+ state: "error",
702
+ project,
703
+ error: templateProjectPathError(t, project, lexical.reason),
704
+ };
705
+ }
706
+ // The row already failed on the value it had: keep that error on screen
707
+ // while the user types until a blur re-checks the new value.
708
+ if (stored !== undefined && stored.state === "error")
709
+ return stored;
710
+ // No check has started for this value at all — a mount the user has just
711
+ // added, whose path the Add-mount popup validated itself. Continue's own
712
+ // check still lists it before handing the draft on.
713
+ return { state: "ok", project };
714
+ };
715
+ // The draft's references and the ones that do not exist yet. A pending
716
+ // project check is not a known path, so it still counts as outstanding: the
717
+ // footer's number stays put while its re-check runs, and a missing reference
718
+ // outranks the checking state it may also be in.
719
+ const references = draft === null ? [] : templateDraftReferences(draft);
720
+ const projectReferences = references.filter((reference) => reference.kind === "project" && reference.mountIndex !== undefined);
721
+ const pendingProjects = projectReferences
722
+ .filter((reference) => projectCheck(reference.mountIndex, reference.name).state === "pending")
723
+ .map((reference) => reference.mountIndex);
724
+ const validProjects = projectReferences
725
+ .filter((reference) => projectCheck(reference.mountIndex, reference.name).state === "ok")
726
+ .map((reference) => reference.name);
727
+ const missingReferences = draft === null
728
+ ? []
729
+ : templateDraftMissingReferences(references, {
730
+ secrets,
731
+ volumes,
732
+ projects: validProjects,
733
+ });
734
+ const missingCount = missingReferences.length;
735
+ const block = templateBlockReason({
736
+ inspection,
737
+ draftImage: draft?.image ?? "",
738
+ images,
739
+ buildInProgress: building,
740
+ buildFailed,
741
+ pendingReferences: pendingProjects.length,
742
+ missingReferences: missingCount,
743
+ mode,
744
+ replaceTarget,
745
+ });
746
+ // The image card's one action: the template's own image keeps the template
747
+ // route, while another listed image offers the action the Images tab would
748
+ // give it. The command behind the action is what the button click runs.
749
+ const imageAction = templateImageAction({
750
+ plan: inspection === null ? null : inspection.image,
751
+ draftImage: draft?.image ?? "",
752
+ images,
753
+ building,
754
+ buildFailed,
755
+ });
756
+ // The button is disabled while the session is busy, while a build's own
757
+ // progress runs and in a read-only session. One label set serves every route:
758
+ // the action decides the wording, never the command behind it, and a running
759
+ // build or rebuild says so with the shared short words instead of the generic
760
+ // busy state.
761
+ const imageActionRunning = busy || imageAction.action === "building" ||
762
+ imageAction.action === "rebuilding";
763
+ const imageActionDisabled = !writable || imageActionRunning;
764
+ const imageActionRunningLabel = imageAction.action === "pull"
765
+ ? t("busy")
766
+ : imageAction.action === "rebuild" ||
767
+ imageAction.action === "rebuilding"
768
+ ? t("rebuilding")
769
+ : t("building");
770
+ const imageActionLabel = imageActionRunning
771
+ ? imageActionRunningLabel
772
+ : imageAction.action === "pull"
773
+ ? t("pullImage")
774
+ : imageAction.action === "rebuild"
775
+ ? t("rebuildImage")
776
+ : t("build");
777
+ // Everything the editors' own `enabled` gate covers: a busy session cannot
778
+ // edit the draft, matching the container editor.
779
+ const enabled = !busy;
780
+ const filteredContainers = useMemo(() => {
781
+ const filter = replaceFilter.trim().toLowerCase();
782
+ if (filter === "")
783
+ return containers;
784
+ return containers.filter((container) => container.containerName.toLowerCase().includes(filter));
785
+ }, [containers, replaceFilter]);
786
+ const canContinue = !busy && block === undefined && inspection !== null &&
787
+ draft !== null;
788
+ // The image group's facts for the draft's image: the template plan while the
789
+ // draft runs the derived id, another listed image's own facts otherwise.
790
+ const imageFacts = inspection === null || draft === null
791
+ ? undefined
792
+ : templateDraftImageFacts(inspection.image, draft.image, images);
793
+ // Every image the picker offers: the template's own image first, then the
794
+ // other base images, then the other custom images, each group sorted by image
795
+ // id, and never the reserved PTC image. The template's own image is kept even
796
+ // while the workspace list lacks it: a custom template's derived image only
797
+ // appears there once built, and the picker must be able to return to it after
798
+ // switching away.
799
+ const candidates = templateImageCandidates(inspection === null ? null : inspection.image, images);
800
+ // The one row a validation message belongs under: a project's check error, or
801
+ // a volume or secret mount whose source the workspace no longer holds. Every
802
+ // message names the offending value; an emptied field says what to choose.
803
+ const mountRowError = (mount, index) => {
804
+ if (mount.kind === "project") {
805
+ const check = projectCheck(index, mount.project);
806
+ // A failed answer stays the row's message while the changed value is
807
+ // checked, so the error paragraph is updated in place instead of being
808
+ // unmounted for the length of the host call.
809
+ if (check.state === "error")
810
+ return check.error;
811
+ if (check.state === "pending") {
812
+ const stored = projectChecks[index];
813
+ if (stored !== undefined && stored.state === "error") {
814
+ return stored.error;
815
+ }
816
+ }
817
+ return undefined;
818
+ }
819
+ if (mount.kind === "volume") {
820
+ if (mount.volume === "")
821
+ return t("templateChooseVolume");
822
+ return !volumes.some((volume) => volume.name === mount.volume)
823
+ ? t("templateVolumeMissing", { volume: mount.volume })
824
+ : undefined;
825
+ }
826
+ if (mount.kind === "secret") {
827
+ if (mount.secret === "")
828
+ return t("templateChooseSecret");
829
+ return !secrets.some((secret) => secret.name === mount.secret)
830
+ ? t("templateSecretMissing", { secret: mount.secret })
831
+ : undefined;
832
+ }
833
+ return undefined;
834
+ };
835
+ // The same message for a secret environment value.
836
+ const secretEnvRowError = (_name, secret) => {
837
+ if (secret === "")
838
+ return t("templateChooseSecret");
839
+ return !secrets.some((candidate) => candidate.name === secret)
840
+ ? t("templateSecretMissing", { secret })
841
+ : undefined;
842
+ };
843
+ const changeDraft = (patch) => {
844
+ if (draft === null)
845
+ return;
846
+ const next = { ...draft, ...patch };
847
+ // The host check reads the draft through its ref, so a change that starts
848
+ // one must be visible to it before the check runs.
849
+ draftRef.current = next;
850
+ setDraft(next);
851
+ };
852
+ // The one line that says why Continue is disabled, or nothing when the popup
853
+ // already states the reason elsewhere.
854
+ const blockText = blockingReasonText(t, block, building, missingCount);
855
+ // The popup's Create volume / Create secret actions: each is offered only
856
+ // while the draft mounts a storage of that kind, so a clean template shows
857
+ // just Add mount. Both open the same create forms the settings storage tab
858
+ // and the mount rows use.
859
+ const draftMounts = draft?.mounts ?? [];
860
+ const hasVolumeMount = draftMounts.some((mount) => mount.kind === "volume");
861
+ const hasSecretMount = draftMounts.some((mount) => mount.kind === "secret");
862
+ const mountActions = !hasVolumeMount && !hasSecretMount ? undefined : (_jsxs(_Fragment, { children: [hasVolumeMount
863
+ ? (_jsx(Button, { variant: "outline", size: "sm", disabled: !writable || busy, onClick: () => setVolumeCreateOpen(true), children: t("createVolume") }))
864
+ : null, hasSecretMount
865
+ ? (_jsx(Button, { variant: "outline", size: "sm", disabled: !writable || busy, onClick: () => setSecretCreateOpen(true), children: t("createSecret") }))
866
+ : null] }));
867
+ // The row's Browse opens the host directory picker on the row's current path;
868
+ // the pick fills the project field and then runs the same host check a blur
869
+ // would.
870
+ const browseProject = useCallback((index) => setProjectBrowse(index), []);
871
+ const chooseProject = (path) => {
872
+ const index = projectBrowse;
873
+ if (index === undefined || draft === null)
874
+ return;
875
+ const project = projectNameFromHostPath(projectsRoot, path) ?? path;
876
+ changeDraft({
877
+ mounts: draft.mounts.map((mount, at) => at === index ? { ...mount, project } : mount),
878
+ });
879
+ setProjectBrowse(undefined);
880
+ void checkProjects();
881
+ };
882
+ // Continue never creates or replaces anything here: it hands the edited
883
+ // draft to the create editor, or to the chosen container's edit editor. That
884
+ // editor's own Apply is the one path that saves. A workspace with no
885
+ // container yet gets its default editor, which creates the default container;
886
+ // otherwise the named editor opens with an empty name for the user to choose.
887
+ // The host check runs once here as well, so Continue never hands on a project
888
+ // path that was never listed; a path that fails keeps the popup open.
889
+ const continueToEditor = async () => {
890
+ if (inspection === null || draft === null || !canContinue)
891
+ return;
892
+ const projectsOk = await checkProjects();
893
+ if (!projectsOk)
894
+ return;
895
+ // The check awaited above may have been overtaken by an edit; hand over the
896
+ // draft as it now stands rather than the one captured at the click.
897
+ const currentDraft = draftRef.current;
898
+ if (currentDraft === null)
899
+ return;
900
+ // What the editor's Back returns to: the selection the popup was opened on,
901
+ // this draft and the destination choice as the popup now shows them, never
902
+ // the editor's own edits. The replace source is the inspection's canonical
903
+ // document, which the host publishes once the editor's Apply succeeded.
904
+ const source = { name: inspection.name, yaml: inspection.yaml };
905
+ const resume = {
906
+ selection: selection ?? source,
907
+ draft: currentDraft,
908
+ mode,
909
+ replaceTarget,
910
+ replaceFilter,
911
+ };
912
+ if (mode === "create") {
913
+ onContinue("create", containers.length === 0 ? "default" : "", currentDraft, undefined, resume);
914
+ return;
915
+ }
916
+ onContinue("replace", replaceTarget, currentDraft, source, resume);
917
+ };
918
+ const templateName = selection === null
919
+ ? t("templateDetails")
920
+ : templateDisplayName(selection.name);
921
+ const fileName = inspection?.name ?? selection?.name ?? "";
922
+ const footer = (_jsxs("div", { style: footerRow, children: [_jsx("span", { style: blockText === undefined ? footerReason : footerReasonError, role: blockText === undefined ? "status" : "alert", children: blockText ?? "" }), _jsxs("div", { style: footerActions, children: [_jsx(Button, { variant: "outline", size: "sm", onClick: onBack, children: t("templateBack") }), _jsx(Button, { variant: "outline", size: "sm", onClick: onClose, children: t("cancel") }), _jsx(Button, { variant: "outline", size: "sm", disabled: !canContinue, style: templateAction, onClick: () => void continueToEditor(), children: t("templateContinue") })] })] }));
923
+ return (_jsxs(_Fragment, { children: [_jsx(Modal, { open: open, onClose: onClose, title: templateName, closeLabel: t("cancel"), className: TEMPLATE_DIALOG_CLASS, contentClassName: TEMPLATE_DIALOG_CONTENT_CLASS, footer: footer, children: _jsxs("div", { style: detailsBody, children: [_jsxs("div", { style: detailsHeader, children: [_jsx("p", { style: detailsFile, children: fileName }), _jsxs("div", { style: destinationBlock, children: [_jsx(SegmentedControl, { id: destinationId, value: mode, options: [
924
+ { value: "create", label: t("templateCreate") },
925
+ {
926
+ value: "replace",
927
+ label: t("templateReplaceContainer"),
928
+ disabled: containers.length === 0,
929
+ },
930
+ ], onChange: (next) => {
931
+ setMode(next);
932
+ if (next === "replace" && replaceTarget === "") {
933
+ setReplaceTarget(containers[0]?.containerName ?? "");
934
+ }
935
+ }, label: t("templateDestination") }), mode === "create"
936
+ ? (_jsx("p", { style: destinationHint, children: containers.length === 0
937
+ ? t("templateCreateDefaultHint")
938
+ : t("templateCreateHint") }))
939
+ : (_jsxs("div", { style: replaceBlock, children: [containers.length > 5
940
+ ? (_jsx(Input, { type: "search", "aria-label": t("templateFilterTargets"), placeholder: t("templateFilterTargets"), value: replaceFilter, disabled: containers.length === 0, onChange: (event) => setReplaceFilter(event.target.value) }))
941
+ : null, _jsx("div", { role: "radiogroup", "aria-label": t("templateDestination"), style: replaceList, children: filteredContainers.length === 0
942
+ ? (_jsx("span", { style: missingValue, children: t("templateNoMatchingContainers") }))
943
+ : filteredContainers.map((container) => {
944
+ const isSelected = replaceTarget ===
945
+ container.containerName;
946
+ return (_jsxs(Button, { variant: "outline", size: "md", role: "radio", "aria-checked": isSelected, disabled: containers.length === 0, style: replaceChoiceStyle(isSelected), onClick: () => setReplaceTarget(container.containerName), children: [_jsxs("span", { style: choiceText, children: [_jsx("span", { style: choiceName, children: container.containerName }), _jsx("span", { style: choiceMeta, children: container.imageId })] }), isSelected
947
+ ? _jsx(IconCheckOutlineRegular, { size: 16 })
948
+ : null] }, container.containerName));
949
+ }) })] }))] })] }), error === "" ? null : (_jsx("p", { role: "alert", style: errorText, children: error })), inspection === null || draft === null
950
+ ? error === ""
951
+ ? _jsx("p", { style: hint, role: "status", children: t("templateLoading") })
952
+ : null
953
+ : (_jsxs(_Fragment, { children: [imageFacts === undefined
954
+ ? null
955
+ : (_jsx(DialogGroup, { title: t("image"), children: _jsxs("div", { className: ROW_LIST_CLASS, style: fieldGroup, children: [_jsx(ImageRow, { t: t, mode: "edit", image: draft.image, candidates: candidates, disabled: !enabled, onChange: (image) => changeDraft({ image }) }), _jsx(ImageFacts, { t: t, locale: locale, imageId: imageFacts.imageId, status: imageFacts.status, builtAt: imageFacts.builtAt, source: imageFacts.source, packages: imageFacts.packages, actions: imageAction.action === "none"
956
+ ? undefined
957
+ : (_jsx(Button, { variant: "outline", size: "sm", disabled: imageActionDisabled, "aria-busy": imageActionRunning, style: templateAction, onClick: () => runImageAction(imageAction), children: imageActionLabel })) }), buildFailed === "" ||
958
+ draft.image !== inspection.imageId
959
+ ? null
960
+ : (_jsx("p", { role: "alert", style: errorText, children: buildFailed }))] }) })), _jsxs("div", { style: blockFields, children: [_jsx(DialogGroup, { title: t("envTitle"), children: _jsx(EnvEditor, { t: t, env: draft.env, busy: busy, onChange: (env) => changeDraft({ env }) }) }), _jsx(DialogGroup, { title: t("mountsTitle"), children: _jsx(MountsEditor, { t: t, mounts: draft.mounts, volumes: volumes, secrets: secrets, busy: busy, enabled: enabled, writable: writable, projectsRoot: projectsRoot, directoryPicker: directoryPicker, mainProject: workspace.projectName, projectPathEditable: true, rowError: mountRowError, onProjectBlur: () => void checkProjects(), onProjectBrowse: directoryPicker === undefined
961
+ ? undefined
962
+ : browseProject, projectBrowseLabel: t("templateBrowse"), actions: mountActions, onCreateVolume: createVolume, onCreateSecret: onCreateSecret, onAdd: (mount) => changeDraft({ mounts: [...draft.mounts, mount] }), onRemove: (mount) => changeDraft({
963
+ mounts: draft.mounts.filter((item) => item !== mount),
964
+ }), onUpdate: (mount, index) => changeDraft({
965
+ mounts: draft.mounts.map((item, at) => at === index ? mount : item),
966
+ }) }) }), _jsx(DialogGroup, { title: t("pathsTitle"), children: _jsx(PathsEditor, { t: t, paths: draft.paths, busy: busy, enabled: enabled, onApply: (paths) => changeDraft({ paths }) }) }), _jsx(DialogGroup, { title: t("containerSecretsTitle"), children: _jsx(SecretEnvEditor, { t: t, secretEnv: draft.secretEnv, secrets: secrets, busy: busy, enabled: enabled, writable: writable, onCreateSecret: onCreateSecret, onChange: (secretEnv) => changeDraft({ secretEnv }), rowError: secretEnvRowError }) }), _jsx(DialogGroup, { title: t("portsTitle"), children: _jsx(PortsEditor, { t: t, ports: draft.ports, busy: busy, enabled: enabled, canPublish: enabled && !gatewayUnavailable, gatewayUnavailable: gatewayUnavailable, onChange: (ports) => changeDraft({ ports }) }) })] })] }))] }) }), _jsx(CreateVolumeModal, { t: t, open: volumeCreateOpen, busy: busy, writable: writable, onCreate: (name) => {
967
+ void createVolume(name);
968
+ }, onClose: () => setVolumeCreateOpen(false) }), _jsx(SecretModal, { t: t, mode: "create", open: secretCreateOpen, busy: busy, writable: writable, onCreate: (name, length, charset) => {
969
+ void onCreateSecret(name, length, charset);
970
+ }, onClose: () => setSecretCreateOpen(false) }), directoryPicker === undefined || projectBrowse === undefined ||
971
+ draft === null
972
+ ? null
973
+ : (_jsx(DirectoryPickerModal, { t: t, open: true, root: projectsRoot, start: hostPathForProjectName(projectsRoot, draft.mounts[projectBrowse]?.project ?? ""), picker: directoryPicker, onSelect: chooseProject, onClose: () => setProjectBrowse(undefined) }))] }));
974
+ }
975
+ export function LoadTemplateModal(props) {
976
+ const { t, locale, open, workspace, containers, images, volumes, secrets, defaultEnv, projectsRoot, directoryPicker, busy, writable, gatewayUnavailable, actions, onBuildImage, onRebuildImage, onRebuildBaseImage, onPullBaseImage, onCreateSecret, createVolume, onReload, resume, onClose, onContinue, } = props;
977
+ const [stage, setStage] = useState("pick");
978
+ const [selection, setSelection] = useState(null);
979
+ // Closing returns the flow to the picker, so reopening never resumes on a
980
+ // previously chosen template. Opening with a resume payload instead skips the
981
+ // picker and reopens the details step for that selection.
982
+ useEffect(() => {
983
+ if (!open) {
984
+ setStage("pick");
985
+ setSelection(null);
986
+ return;
987
+ }
988
+ if (resume === undefined || resume === null)
989
+ return;
990
+ setSelection(resume.selection);
991
+ setStage("details");
992
+ }, [open, resume]);
993
+ // The resume payload only seeds the selection it was recorded for: choosing
994
+ // another template starts that one from the template's own plan.
995
+ const resumeActive = resume !== undefined && resume !== null &&
996
+ selection !== null && selection.name === resume.selection.name &&
997
+ selection.yaml === resume.selection.yaml
998
+ ? resume
999
+ : undefined;
1000
+ return (_jsxs(_Fragment, { children: [_jsx(TemplatePickerModal, { t: t, open: open && stage === "pick", workspace: workspace, busy: busy, actions: actions, onClose: onClose, onChoose: (chosen) => {
1001
+ setSelection(chosen);
1002
+ setStage("details");
1003
+ } }), _jsx(TemplateDetailsModal, { t: t, locale: locale, open: open && stage === "details", workspace: workspace, containers: containers, images: images, volumes: volumes, secrets: secrets, defaultEnv: defaultEnv, projectsRoot: projectsRoot, directoryPicker: directoryPicker, busy: busy, writable: writable, gatewayUnavailable: gatewayUnavailable, actions: actions, onBuildImage: onBuildImage, onRebuildImage: onRebuildImage, onRebuildBaseImage: onRebuildBaseImage, onPullBaseImage: onPullBaseImage, onCreateSecret: onCreateSecret, createVolume: createVolume, onReload: onReload, selection: selection, initialDraft: resumeActive?.draft, initialMode: resumeActive?.mode, initialReplaceTarget: resumeActive?.replaceTarget, initialReplaceFilter: resumeActive?.replaceFilter, onBack: () => setStage("pick"), onClose: onClose, onContinue: onContinue })] }));
1004
+ }