@nivaro/react 0.2.53 → 0.2.55

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 (294) hide show
  1. package/dist/full.css +1 -1
  2. package/dist/hooks/useSessionRecorder.js +99 -98
  3. package/dist/index.d.ts +452 -4
  4. package/dist/index.js +644 -618
  5. package/dist/layout-editor.d.ts +252 -2
  6. package/dist/shared/components/BackgroundRunOffer.js +117 -0
  7. package/dist/shared/components/BroadcastView.js +214 -213
  8. package/dist/shared/components/CollectionBrowserView.js +2592 -2695
  9. package/dist/shared/components/FormWhatsNew.js +60 -0
  10. package/dist/shared/components/ItemEditForm.js +3968 -3618
  11. package/dist/shared/components/JobsTray.js +100 -55
  12. package/dist/shared/components/MyWorkView.js +91 -89
  13. package/dist/shared/components/NotificationBell.js +80 -79
  14. package/dist/shared/components/ProfileView.js +568 -520
  15. package/dist/shared/components/RecordCompare.js +254 -0
  16. package/dist/shared/components/RecordReadView.js +598 -543
  17. package/dist/shared/components/ReportView.js +578 -543
  18. package/dist/shared/components/RowPresence.js +91 -0
  19. package/dist/shared/components/TipLayer.js +27 -27
  20. package/dist/shared/components/WidgetSlot.js +474 -458
  21. package/dist/shared/components/ai/AiAnalyticsView.js +16 -6
  22. package/dist/shared/components/ai/AskPanel.js +139 -119
  23. package/dist/shared/components/ai/FirstWeekCard.js +126 -0
  24. package/dist/shared/components/bulk/BulkFieldUpdate.js +289 -0
  25. package/dist/shared/components/bulk/bulk-field-options.js +45 -0
  26. package/dist/shared/components/charts/CumulativeFlowChart.js +176 -0
  27. package/dist/shared/components/chat/ChannelArchive.js +326 -0
  28. package/dist/shared/components/chat/ChannelExtras.js +141 -121
  29. package/dist/shared/components/chat/ChatAnalyticsView.js +112 -110
  30. package/dist/shared/components/chat/ChatPanel.js +1695 -1733
  31. package/dist/shared/components/chat/Composer.js +357 -303
  32. package/dist/shared/components/chat/MessageActions.js +92 -0
  33. package/dist/shared/components/chat/MessageFormat.js +290 -264
  34. package/dist/shared/components/chat/OutboxBubbles.js +146 -0
  35. package/dist/shared/components/chat/RequestIdCard.js +135 -0
  36. package/dist/shared/components/chat/RoomHeaderMenu.js +202 -0
  37. package/dist/shared/components/chat/RoomParts.js +213 -274
  38. package/dist/shared/components/chat/ScreenClip.js +184 -0
  39. package/dist/shared/components/chat/chat-core.js +402 -483
  40. package/dist/shared/components/chat/chat-drafts.js +59 -0
  41. package/dist/shared/components/chat/chat-emoji.js +348 -0
  42. package/dist/shared/components/chat/chat-local-time.js +41 -0
  43. package/dist/shared/components/chat/chat-outbox.js +303 -0
  44. package/dist/shared/components/chat/chat-window.js +163 -0
  45. package/dist/shared/components/chat/huddle/HuddleControls.js +143 -0
  46. package/dist/shared/components/chat/huddle/HuddleStage.js +164 -0
  47. package/dist/shared/components/chat/huddle/huddle-store.js +342 -0
  48. package/dist/shared/components/chat/huddle/useHuddle.js +58 -0
  49. package/dist/shared/components/help-videos/api.js +80 -67
  50. package/dist/shared/components/help-videos/editor/DetailsTab.js +147 -130
  51. package/dist/shared/components/item-edit/CatalogPickerField.js +113 -112
  52. package/dist/shared/components/item-edit/ChangeReasonDialog.js +13 -13
  53. package/dist/shared/components/item-edit/FieldAffordances.js +9 -8
  54. package/dist/shared/components/item-edit/FieldRenderer.js +248 -245
  55. package/dist/shared/components/item-edit/FieldRow.js +382 -320
  56. package/dist/shared/components/item-edit/FormHelpVideoButton.js +59 -0
  57. package/dist/shared/components/item-edit/GroupSection.js +786 -639
  58. package/dist/shared/components/item-edit/HeaderTools.js +59 -56
  59. package/dist/shared/components/item-edit/InlineTableField.js +3 -1
  60. package/dist/shared/components/item-edit/LayoutContentBlock.js +47 -24
  61. package/dist/shared/components/item-edit/RelationCombobox.js +186 -176
  62. package/dist/shared/components/item-edit/entry/EntryStrip.js +54 -0
  63. package/dist/shared/components/item-edit/entry/entry-keys.js +27 -0
  64. package/dist/shared/components/item-edit/entry/useEntryKeyboard.js +70 -0
  65. package/dist/shared/components/item-edit/entry/useEntryMode.js +59 -0
  66. package/dist/shared/components/item-edit/form-structure-ui.js +105 -0
  67. package/dist/shared/components/item-edit/lazy-sections.js +36 -0
  68. package/dist/shared/components/item-edit/lock-why.js +94 -0
  69. package/dist/shared/components/item-edit/picker-miss.js +26 -0
  70. package/dist/shared/components/item-edit/placement-behaviour.js +196 -0
  71. package/dist/shared/components/item-edit/useFormUsageBeacon.js +65 -0
  72. package/dist/shared/components/layout-editor/AddPanel.js +226 -151
  73. package/dist/shared/components/layout-editor/ArrangeButton.js +34 -0
  74. package/dist/shared/components/layout-editor/AutoArrange.js +86 -0
  75. package/dist/shared/components/layout-editor/CanvasCompare.js +79 -0
  76. package/dist/shared/components/layout-editor/ChangeNote.js +147 -0
  77. package/dist/shared/components/layout-editor/CollabParts.js +175 -0
  78. package/dist/shared/components/layout-editor/DesignNode.js +311 -116
  79. package/dist/shared/components/layout-editor/EditorCanvas.js +30 -26
  80. package/dist/shared/components/layout-editor/EditorTopBar.js +463 -175
  81. package/dist/shared/components/layout-editor/FindReplace.js +188 -0
  82. package/dist/shared/components/layout-editor/FormMapButton.js +141 -0
  83. package/dist/shared/components/layout-editor/HistoryPanel.js +250 -109
  84. package/dist/shared/components/layout-editor/LayoutEditor.js +1196 -305
  85. package/dist/shared/components/layout-editor/LayoutsRail.js +94 -67
  86. package/dist/shared/components/layout-editor/NoteMarker.js +38 -0
  87. package/dist/shared/components/layout-editor/PlacementsTable.js +187 -0
  88. package/dist/shared/components/layout-editor/RestorePiece.js +143 -0
  89. package/dist/shared/components/layout-editor/ScheduleChange.js +106 -0
  90. package/dist/shared/components/layout-editor/SessionHistory.js +84 -0
  91. package/dist/shared/components/layout-editor/StagedChip.js +22 -0
  92. package/dist/shared/components/layout-editor/StructureMenu.js +464 -0
  93. package/dist/shared/components/layout-editor/UnsavedConfirm.js +103 -0
  94. package/dist/shared/components/layout-editor/ai/AiToolsButton.js +625 -0
  95. package/dist/shared/components/layout-editor/ai/ChangeCheck.js +153 -0
  96. package/dist/shared/components/layout-editor/ai/ai-tools-api.js +80 -0
  97. package/dist/shared/components/layout-editor/ai/assist-ops.js +38 -0
  98. package/dist/shared/components/layout-editor/ai/autofill-ops.js +73 -0
  99. package/dist/shared/components/layout-editor/ai/canvas-capture.js +41 -0
  100. package/dist/shared/components/layout-editor/ai-forms/AiComposer.js +271 -0
  101. package/dist/shared/components/layout-editor/ai-forms/AiFormsButton.js +182 -0
  102. package/dist/shared/components/layout-editor/ai-forms/MeaningSuggestions.js +109 -0
  103. package/dist/shared/components/layout-editor/ai-forms/SlimPanel.js +170 -0
  104. package/dist/shared/components/layout-editor/ai-forms/ai-forms-api.js +40 -0
  105. package/dist/shared/components/layout-editor/ai-forms/pending.js +25 -0
  106. package/dist/shared/components/layout-editor/ai-forms/plan.js +263 -0
  107. package/dist/shared/components/layout-editor/ai-rules/AiAskPopover.js +160 -0
  108. package/dist/shared/components/layout-editor/ai-rules/CascadeWriter.js +175 -0
  109. package/dist/shared/components/layout-editor/ai-rules/FieldRuleWriter.js +97 -0
  110. package/dist/shared/components/layout-editor/ai-rules/RuleWriter.js +94 -0
  111. package/dist/shared/components/layout-editor/ai-rules/ValidationSuggest.js +153 -0
  112. package/dist/shared/components/layout-editor/ai-rules/api.js +6 -0
  113. package/dist/shared/components/layout-editor/ai-text/AiTextTools.js +383 -0
  114. package/dist/shared/components/layout-editor/ai-text/text-ops.js +125 -0
  115. package/dist/shared/components/layout-editor/assist/AskPanel.js +278 -0
  116. package/dist/shared/components/layout-editor/assist/ExplainDiff.js +93 -0
  117. package/dist/shared/components/layout-editor/assist/ProposalsButton.js +150 -0
  118. package/dist/shared/components/layout-editor/assist/assist-api.js +63 -0
  119. package/dist/shared/components/layout-editor/assist/jump.js +142 -0
  120. package/dist/shared/components/layout-editor/assist/settings-index.js +118 -0
  121. package/dist/shared/components/layout-editor/auto-arrange.js +101 -0
  122. package/dist/shared/components/layout-editor/bulk/BulkChangesButton.js +221 -0
  123. package/dist/shared/components/layout-editor/bulk/BulkRun.js +237 -0
  124. package/dist/shared/components/layout-editor/bulk/MacrosPanel.js +230 -0
  125. package/dist/shared/components/layout-editor/bulk/bulk-api.js +65 -0
  126. package/dist/shared/components/layout-editor/bulk/field-labels.js +22 -0
  127. package/dist/shared/components/layout-editor/bulk/macro-record.js +142 -0
  128. package/dist/shared/components/layout-editor/bulk/useMacroRecorder.js +65 -0
  129. package/dist/shared/components/layout-editor/bundle-to-active.js +1 -0
  130. package/dist/shared/components/layout-editor/canvas-diff.js +157 -0
  131. package/dist/shared/components/layout-editor/collab/FormFollowShare.js +388 -0
  132. package/dist/shared/components/layout-editor/collab/collab-api.js +80 -0
  133. package/dist/shared/components/layout-editor/commands/CommandPalette.js +221 -0
  134. package/dist/shared/components/layout-editor/commands/intents.js +214 -0
  135. package/dist/shared/components/layout-editor/commands/parse.js +242 -0
  136. package/dist/shared/components/layout-editor/design-context.js +26 -6
  137. package/dist/shared/components/layout-editor/dnd/LayoutDndProvider.js +181 -164
  138. package/dist/shared/components/layout-editor/dnd/collision.js +25 -23
  139. package/dist/shared/components/layout-editor/dnd/node.js +69 -57
  140. package/dist/shared/components/layout-editor/dnd/rail-drop.js +56 -0
  141. package/dist/shared/components/layout-editor/draft-recovery.js +131 -0
  142. package/dist/shared/components/layout-editor/editor-notes.js +78 -0
  143. package/dist/shared/components/layout-editor/editors/swap-config.js +1 -0
  144. package/dist/shared/components/layout-editor/entry/PlacementPresets.js +149 -0
  145. package/dist/shared/components/layout-editor/entry/entry-editor-context.js +10 -0
  146. package/dist/shared/components/layout-editor/entry/presets.js +71 -0
  147. package/dist/shared/components/layout-editor/entry/tab-order.js +110 -0
  148. package/dist/shared/components/layout-editor/entry/theme-preview.js +37 -0
  149. package/dist/shared/components/layout-editor/explain/CanvasRules.js +142 -0
  150. package/dist/shared/components/layout-editor/explain/default-ghosts.js +81 -0
  151. package/dist/shared/components/layout-editor/explain/driver-hover.js +62 -0
  152. package/dist/shared/components/layout-editor/explain/field-sources.js +246 -0
  153. package/dist/shared/components/layout-editor/explain/rule-graph.js +215 -0
  154. package/dist/shared/components/layout-editor/explain/use-explain.js +132 -0
  155. package/dist/shared/components/layout-editor/field-zones.js +116 -0
  156. package/dist/shared/components/layout-editor/form-map.js +138 -0
  157. package/dist/shared/components/layout-editor/grid-guides.js +142 -0
  158. package/dist/shared/components/layout-editor/history-api.js +87 -0
  159. package/dist/shared/components/layout-editor/inheritance.js +55 -0
  160. package/dist/shared/components/layout-editor/inspect/inspect-api.js +66 -0
  161. package/dist/shared/components/layout-editor/inspect/picker-preview.js +48 -0
  162. package/dist/shared/components/layout-editor/inspect/width-fit.js +87 -0
  163. package/dist/shared/components/layout-editor/inspector/AiFillSetting.js +85 -0
  164. package/dist/shared/components/layout-editor/inspector/BehaviourSettings.js +402 -0
  165. package/dist/shared/components/layout-editor/inspector/Breadcrumb.js +36 -0
  166. package/dist/shared/components/layout-editor/inspector/BulkInspector.js +179 -0
  167. package/dist/shared/components/layout-editor/inspector/ColumnFit.js +112 -0
  168. package/dist/shared/components/layout-editor/inspector/GroupInspector.js +291 -141
  169. package/dist/shared/components/layout-editor/inspector/HelpTab.js +174 -0
  170. package/dist/shared/components/layout-editor/inspector/Inspector.js +282 -180
  171. package/dist/shared/components/layout-editor/inspector/LookTab.js +166 -109
  172. package/dist/shared/components/layout-editor/inspector/OverrideNotice.js +61 -0
  173. package/dist/shared/components/layout-editor/inspector/PickerMisses.js +129 -0
  174. package/dist/shared/components/layout-editor/inspector/PickerPreview.js +134 -0
  175. package/dist/shared/components/layout-editor/inspector/PickerTab.js +146 -118
  176. package/dist/shared/components/layout-editor/inspector/RulesTab.js +162 -111
  177. package/dist/shared/components/layout-editor/inspector/Translations.js +156 -0
  178. package/dist/shared/components/layout-editor/inspector/kit.js +71 -70
  179. package/dist/shared/components/layout-editor/inspector/tab-request.js +21 -0
  180. package/dist/shared/components/layout-editor/is-typing.js +9 -0
  181. package/dist/shared/components/layout-editor/keyboard-move.js +66 -0
  182. package/dist/shared/components/layout-editor/lint/LintPanel.js +190 -0
  183. package/dist/shared/components/layout-editor/lint/lint-api.js +52 -0
  184. package/dist/shared/components/layout-editor/load-error.js +37 -0
  185. package/dist/shared/components/layout-editor/matrix/FieldStateMatrix.js +305 -0
  186. package/dist/shared/components/layout-editor/matrix/MatrixGrid.js +181 -0
  187. package/dist/shared/components/layout-editor/matrix/RoleSectionMatrix.js +147 -0
  188. package/dist/shared/components/layout-editor/matrix/matrix-api.js +48 -0
  189. package/dist/shared/components/layout-editor/matrix/role-matrix.js +36 -0
  190. package/dist/shared/components/layout-editor/matrix/state-matrix.js +145 -0
  191. package/dist/shared/components/layout-editor/nav/FindPanel.js +109 -0
  192. package/dist/shared/components/layout-editor/nav/NavTools.js +114 -0
  193. package/dist/shared/components/layout-editor/nav/OutlinePanel.js +228 -0
  194. package/dist/shared/components/layout-editor/nav/ShortcutSheet.js +31 -0
  195. package/dist/shared/components/layout-editor/nav/find.js +20 -0
  196. package/dist/shared/components/layout-editor/nav/tree.js +142 -0
  197. package/dist/shared/components/layout-editor/nav/useEditorNav.js +101 -0
  198. package/dist/shared/components/layout-editor/nav/view-prefs.js +34 -0
  199. package/dist/shared/components/layout-editor/ops/ChangeRequestsPanel.js +143 -0
  200. package/dist/shared/components/layout-editor/ops/DependencyDiagram.js +179 -0
  201. package/dist/shared/components/layout-editor/ops/LayoutOpsBlocks.js +92 -0
  202. package/dist/shared/components/layout-editor/ops/PromotePanel.js +287 -0
  203. package/dist/shared/components/layout-editor/ops/ops-api.js +122 -0
  204. package/dist/shared/components/layout-editor/outputs/OutputsButton.js +254 -0
  205. package/dist/shared/components/layout-editor/outputs/help-sheet.js +154 -0
  206. package/dist/shared/components/layout-editor/outputs/output-api.js +61 -0
  207. package/dist/shared/components/layout-editor/overview/OverviewActions.js +15 -3
  208. package/dist/shared/components/layout-editor/overview/describe-conditions.js +24 -14
  209. package/dist/shared/components/layout-editor/overview/overview-api.js +105 -88
  210. package/dist/shared/components/layout-editor/overview/purpose.js +15 -13
  211. package/dist/shared/components/layout-editor/panel-style.js +8 -7
  212. package/dist/shared/components/layout-editor/parity-keys.json.js +4 -0
  213. package/dist/shared/components/layout-editor/pin.js +25 -0
  214. package/dist/shared/components/layout-editor/presence.js +111 -0
  215. package/dist/shared/components/layout-editor/preview/PreviewModes.js +224 -0
  216. package/dist/shared/components/layout-editor/preview/PreviewPanes.js +262 -0
  217. package/dist/shared/components/layout-editor/preview/preview-api.js +57 -0
  218. package/dist/shared/components/layout-editor/preview/preview-model.js +157 -0
  219. package/dist/shared/components/layout-editor/restore-piece.js +192 -0
  220. package/dist/shared/components/layout-editor/reuse/FieldMapStep.js +70 -0
  221. package/dist/shared/components/layout-editor/reuse/FormMoreMenu.js +127 -0
  222. package/dist/shared/components/layout-editor/reuse/LibraryRows.js +150 -0
  223. package/dist/shared/components/layout-editor/reuse/NewFormStart.js +20 -0
  224. package/dist/shared/components/layout-editor/reuse/SectionReuseActions.js +291 -0
  225. package/dist/shared/components/layout-editor/reuse/field-match.js +77 -0
  226. package/dist/shared/components/layout-editor/reuse/reuse-api.js +73 -0
  227. package/dist/shared/components/layout-editor/reuse/seed.js +13 -0
  228. package/dist/shared/components/layout-editor/reuse/useFormFromRecord.js +43 -0
  229. package/dist/shared/components/layout-editor/reuse/useRailCopy.js +34 -0
  230. package/dist/shared/components/layout-editor/section-structure.js +241 -0
  231. package/dist/shared/components/layout-editor/settings/EntrySection.js +296 -0
  232. package/dist/shared/components/layout-editor/settings/FormSettings.js +125 -103
  233. package/dist/shared/components/layout-editor/settings/InheritanceSection.js +1 -1
  234. package/dist/shared/components/layout-editor/settings/ResolveSettings.js +255 -0
  235. package/dist/shared/components/layout-editor/settings/ToolsSection.js +215 -105
  236. package/dist/shared/components/layout-editor/settings/WhoSection.js +139 -100
  237. package/dist/shared/components/layout-editor/settings/controls.js +8 -8
  238. package/dist/shared/components/layout-editor/settings/settings-registry.js +142 -21
  239. package/dist/shared/components/layout-editor/shortcuts.js +88 -0
  240. package/dist/shared/components/layout-editor/show-when.js +35 -0
  241. package/dist/shared/components/layout-editor/slot-names.js +4 -3
  242. package/dist/shared/components/layout-editor/staged-api.js +64 -0
  243. package/dist/shared/components/layout-editor/structure-ops.js +403 -0
  244. package/dist/shared/components/layout-editor/testing/CostLimitSetting.js +42 -0
  245. package/dist/shared/components/layout-editor/testing/TestingPanels.js +556 -0
  246. package/dist/shared/components/layout-editor/testing/testing-api.js +67 -0
  247. package/dist/shared/components/layout-editor/testing/testing-model.js +406 -0
  248. package/dist/shared/components/layout-editor/testing/use-record-check.js +44 -0
  249. package/dist/shared/components/layout-editor/toolbar-kit.js +242 -0
  250. package/dist/shared/components/layout-editor/unsaved-marks.js +72 -0
  251. package/dist/shared/components/layout-editor/usage/AbTestSection.js +355 -0
  252. package/dist/shared/components/layout-editor/usage/FillChip.js +27 -0
  253. package/dist/shared/components/layout-editor/usage/UsagePanel.js +232 -0
  254. package/dist/shared/components/layout-editor/usage/ab-api.js +86 -0
  255. package/dist/shared/components/layout-editor/usage/suggest-collapse.js +32 -0
  256. package/dist/shared/components/layout-editor/usage/suggest-sections.js +55 -0
  257. package/dist/shared/components/layout-editor/usage/usage-api.js +104 -0
  258. package/dist/shared/components/layout-editor/useLayoutDraft.js +573 -306
  259. package/dist/shared/components/notifications/NotificationAnalyticsView.js +148 -77
  260. package/dist/shared/components/panels/ErpFailureBanner.js +18 -17
  261. package/dist/shared/components/panels/ExternalRequestsChip.js +63 -62
  262. package/dist/shared/components/pipeline/PipelineEditorView.js +106 -104
  263. package/dist/shared/components/profile/AgentsPanel.js +479 -0
  264. package/dist/shared/components/queue/QueueWorklist.js +1026 -1040
  265. package/dist/shared/components/support/SuggestFormChange.js +143 -0
  266. package/dist/shared/components/support/SupportAnalytics.js +171 -0
  267. package/dist/shared/components/support/SupportView.js +75 -73
  268. package/dist/shared/lib/ai-fill.js +37 -0
  269. package/dist/shared/lib/background-runs.js +150 -0
  270. package/dist/shared/lib/delivery-ack.js +9 -0
  271. package/dist/shared/lib/entry-badge-style.js +13 -0
  272. package/dist/shared/lib/entry-config.js +71 -0
  273. package/dist/shared/lib/form-sections.js +64 -0
  274. package/dist/shared/lib/form-structure.js +99 -0
  275. package/dist/shared/lib/form-usage-beacon.js +133 -0
  276. package/dist/shared/lib/jobs-tray.js +25 -23
  277. package/dist/shared/lib/keyset-pager.js +37 -0
  278. package/dist/shared/lib/layout-i18n.js +66 -0
  279. package/dist/shared/lib/layout-lint.js +490 -0
  280. package/dist/shared/lib/layout-ops.js +116 -110
  281. package/dist/shared/lib/layout-resolve.js +113 -0
  282. package/dist/shared/lib/placement-behaviour.js +144 -0
  283. package/dist/shared/lib/prefetch.js +149 -0
  284. package/dist/shared/lib/presence-hooks.js +199 -0
  285. package/dist/shared/lib/record-outbox.js +82 -81
  286. package/dist/shared/lib/replay-socket.js +93 -0
  287. package/dist/shared/lib/request-gate.js +51 -50
  288. package/dist/shared/lib/room-gaps.js +96 -0
  289. package/dist/shared/lib/screenshot.js +54 -28
  290. package/dist/shared/lib/search-log.js +27 -0
  291. package/dist/shared/lib/socket-realtime.js +101 -80
  292. package/dist/shared/lib/visible-when.js +34 -0
  293. package/dist/shared/lib/worker-socket.js +200 -0
  294. package/package.json +1 -1
@@ -0,0 +1,150 @@
1
+ import { jsxs as i, Fragment as w, jsx as o } from "react/jsx-runtime";
2
+ import { BookMarked as C, X as R } from "lucide-react";
3
+ import { useState as u } from "react";
4
+ import { toast as p } from "sonner";
5
+ import { useNivaroClient as $ } from "../../../context.js";
6
+ import { cn as j } from "../../../lib/utils.js";
7
+ import { sectionOp as F } from "../add-target.js";
8
+ import { apiFailure as v } from "../overview/overview-api.js";
9
+ import { useFieldMapping as M, FieldMapStep as B } from "./FieldMapStep.js";
10
+ import { useTemplates as S, useRefreshTemplates as A, planBlock as T, leftOutWords as L, deleteTemplate as O } from "./reuse-api.js";
11
+ import { reusePrimary as E } from "./SectionReuseActions.js";
12
+ const I = "px-2 pb-1 pt-3 text-[11.5px] font-semibold text-slate-500 dark:text-muted-foreground";
13
+ function K(e, t) {
14
+ const r = F(e, t);
15
+ return r.op === "group_create" && r.parent_key === null ? r.index : void 0;
16
+ }
17
+ function P({ t: e, ...t }) {
18
+ const r = $(), n = A(), [f, c] = u(!1), [y, h] = u(!1), [s, x] = u(!1), m = !!e.source_collection && e.source_collection !== t.collection, a = M(m ? e.fields : [], e.source_collection, t.collection), b = async () => {
19
+ if (!s) {
20
+ if (m && !f && a.needed.length) {
21
+ c(!0);
22
+ return;
23
+ }
24
+ x(!0);
25
+ try {
26
+ const l = await T(r, {
27
+ source: { template_id: e.id },
28
+ target_collection: t.collection,
29
+ target_bundle: t.bundle,
30
+ field_map: m ? a.map : void 0,
31
+ index: K(t.bundle, t.selected)
32
+ });
33
+ if (!l.ops.length) throw new Error("Nothing to add");
34
+ t.apply(l.ops, { label: `Add ${e.name}` });
35
+ const d = l.ops.find((_) => _.op === "group_create");
36
+ (d == null ? void 0 : d.op) === "group_create" && t.onSelect({ kind: "group", key: d.key });
37
+ const g = L(l);
38
+ g && p(`${e.name} added: ${g}`), c(!1);
39
+ } catch (l) {
40
+ p.error(v(l, "Could not add the section").message);
41
+ } finally {
42
+ x(!1);
43
+ }
44
+ }
45
+ }, k = async () => {
46
+ try {
47
+ await O(r, e.id), n("section");
48
+ } catch (l) {
49
+ p.error(v(l, "Could not remove it").message);
50
+ }
51
+ }, N = [
52
+ `${e.fields.length} ${e.fields.length === 1 ? "field" : "fields"}`,
53
+ e.source_collection && e.source_collection !== t.collection ? `from ${e.source_collection}` : null,
54
+ e.description
55
+ ].filter(Boolean).join(" · ");
56
+ return /* @__PURE__ */ i("div", { "data-library-section": e.id, children: [
57
+ /* @__PURE__ */ i("div", { className: "group flex items-center gap-0.5", children: [
58
+ /* @__PURE__ */ i(
59
+ "button",
60
+ {
61
+ type: "button",
62
+ disabled: s || a.loading,
63
+ onClick: () => void b(),
64
+ className: "flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors hover:bg-muted disabled:opacity-60",
65
+ children: [
66
+ /* @__PURE__ */ i("span", { className: "flex min-w-0 flex-1 flex-col", children: [
67
+ /* @__PURE__ */ o("span", { className: "truncate text-[12.5px] font-medium text-slate-900 dark:text-foreground", children: e.name }),
68
+ /* @__PURE__ */ o("span", { className: "truncate text-[11.5px] text-slate-500 dark:text-muted-foreground", children: N })
69
+ ] }),
70
+ /* @__PURE__ */ o(C, { className: "h-3.5 w-3.5 shrink-0 text-slate-400" })
71
+ ]
72
+ }
73
+ ),
74
+ /* @__PURE__ */ o(
75
+ "button",
76
+ {
77
+ type: "button",
78
+ "aria-label": `Remove ${e.name} from the library`,
79
+ "data-tip": "Remove from the library",
80
+ onClick: () => h(!0),
81
+ className: "invisible inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-slate-400 transition-colors hover:bg-muted hover:text-slate-700 group-hover:visible focus-visible:visible dark:hover:text-foreground",
82
+ children: /* @__PURE__ */ o(R, { className: "h-3.5 w-3.5" })
83
+ }
84
+ )
85
+ ] }),
86
+ y && /* @__PURE__ */ i("div", { className: "mx-2 mb-1 flex items-center gap-2 text-[12px] text-slate-600 dark:text-muted-foreground", children: [
87
+ /* @__PURE__ */ o("span", { className: "flex-1", children: "Remove from the library? Forms keep their copies." }),
88
+ /* @__PURE__ */ o(
89
+ "button",
90
+ {
91
+ type: "button",
92
+ onClick: () => void k(),
93
+ className: "font-medium text-red-600 hover:underline dark:text-red-400",
94
+ children: "Remove"
95
+ }
96
+ ),
97
+ /* @__PURE__ */ o("button", { type: "button", onClick: () => h(!1), className: "hover:underline", children: "Keep" })
98
+ ] }),
99
+ f && /* @__PURE__ */ i(
100
+ "div",
101
+ {
102
+ className: j(
103
+ "mx-1 mb-2 rounded-md border border-slate-200 bg-slate-50 p-2 dark:border-border dark:bg-muted/40"
104
+ ),
105
+ children: [
106
+ /* @__PURE__ */ o(
107
+ B,
108
+ {
109
+ needed: a.needed,
110
+ map: a.map,
111
+ onChange: a.setMap,
112
+ targetCollection: t.collection
113
+ }
114
+ ),
115
+ /* @__PURE__ */ i("div", { className: "mt-2 flex justify-end gap-2", children: [
116
+ /* @__PURE__ */ o(
117
+ "button",
118
+ {
119
+ type: "button",
120
+ onClick: () => c(!1),
121
+ className: "text-[12px] text-slate-500 hover:underline dark:text-muted-foreground",
122
+ children: "Cancel"
123
+ }
124
+ ),
125
+ /* @__PURE__ */ o(
126
+ "button",
127
+ {
128
+ type: "button",
129
+ className: E,
130
+ disabled: s,
131
+ onClick: () => void b(),
132
+ children: s ? "Adding…" : "Add section"
133
+ }
134
+ )
135
+ ] })
136
+ ]
137
+ }
138
+ )
139
+ ] });
140
+ }
141
+ function Y(e) {
142
+ const { data: t = [] } = S("section"), r = t.filter((n) => e.matches(n.name, n.description, ...n.fields));
143
+ return r.length ? /* @__PURE__ */ i(w, { children: [
144
+ /* @__PURE__ */ o("p", { className: I, children: "Section library" }),
145
+ r.map((n) => /* @__PURE__ */ o(P, { t: n, ...e }, n.id))
146
+ ] }) : null;
147
+ }
148
+ export {
149
+ Y as LibraryRows
150
+ };
@@ -0,0 +1,20 @@
1
+ import "react/jsx-runtime";
2
+ import "lucide-react";
3
+ import "react";
4
+ import "sonner";
5
+ import { post as r } from "../../../lib/commands.js";
6
+ async function s(l, t) {
7
+ var i;
8
+ const o = await l.request(
9
+ r("/collection-layouts", {
10
+ collection: t.collection,
11
+ name: t.name,
12
+ layout_type: "grouped",
13
+ seed_fields: t.fields
14
+ })
15
+ ), e = (i = o == null ? void 0 : o.data) == null ? void 0 : i.id;
16
+ return e == null ? null : Number(e);
17
+ }
18
+ export {
19
+ s as createFormFromFields
20
+ };
@@ -0,0 +1,291 @@
1
+ import { jsxs as n, jsx as e, Fragment as $ } from "react/jsx-runtime";
2
+ import { useQuery as V } from "@tanstack/react-query";
3
+ import { Copy as X, ChevronLeft as Y, BookmarkPlus as Z } from "lucide-react";
4
+ import { useState as u, useMemo as ee } from "react";
5
+ import { toast as v } from "sonner";
6
+ import { useNivaroClient as F } from "../../../context.js";
7
+ import { get as te } from "../../../lib/commands.js";
8
+ import { titleCase as T, cn as ae } from "../../../lib/utils.js";
9
+ import { Popover as M, PopoverTrigger as W, PopoverContent as A } from "../../ui/popover.js";
10
+ import { useLayoutOverview as oe, useInvalidateLayouts as ne, apiFailure as D } from "../overview/overview-api.js";
11
+ import { useFieldMapping as re, FieldMapStep as se } from "./FieldMapStep.js";
12
+ import { useRefreshTemplates as le, copySection as ie, leftOutWords as ce, saveTemplate as de } from "./reuse-api.js";
13
+ const K = "inline-flex h-7 items-center gap-1.5 rounded-md border border-slate-200 bg-white px-2 text-[12px] font-medium text-slate-700 transition-colors hover:bg-slate-50 disabled:opacity-50 dark:border-border dark:bg-card dark:text-foreground dark:hover:bg-muted", Q = "inline-flex h-7 items-center gap-1.5 rounded-md bg-nvr-cyan px-2.5 text-[12px] font-semibold text-white transition-opacity hover:opacity-90 disabled:opacity-50", S = "h-8 w-full rounded-md border border-slate-200 bg-white px-2.5 text-[12.5px] text-slate-800 outline-none placeholder:text-slate-400 focus:border-nvr-cyan dark:border-border dark:bg-background dark:text-foreground dark:placeholder:text-muted-foreground", L = "mb-1 block text-[11.5px] font-semibold text-slate-600 dark:text-muted-foreground", q = "flex w-full items-center gap-2 truncate rounded px-2 py-1.5 text-left text-[12.5px] text-slate-700 hover:bg-muted dark:text-foreground";
14
+ function ue(s, r) {
15
+ const o = /* @__PURE__ */ new Set([r]);
16
+ for (let a = !0; a; ) {
17
+ a = !1;
18
+ for (const d of s.groups)
19
+ d.parent_key && o.has(d.parent_key) && !o.has(d.key) && (o.add(d.key), a = !0);
20
+ }
21
+ return [
22
+ ...new Set(
23
+ s.placements.filter((a) => a.group_key && o.has(a.group_key) && !a.field.startsWith("__")).map((a) => a.field)
24
+ )
25
+ ];
26
+ }
27
+ function me(s) {
28
+ const r = F();
29
+ return V({
30
+ queryKey: ["layout-editor", "collection-names"],
31
+ queryFn: () => r.request(
32
+ te("/collections")
33
+ ).then(
34
+ (o) => (o.data ?? []).filter((a) => !a.collection.startsWith("nivaro_")).map((a) => ({
35
+ collection: a.collection,
36
+ label: a.display_name || T(a.collection)
37
+ })).sort((a, d) => a.label.localeCompare(d.label))
38
+ ),
39
+ enabled: s,
40
+ staleTime: 5 * 6e4
41
+ });
42
+ }
43
+ function pe({
44
+ bundle: s,
45
+ collection: r,
46
+ group: o,
47
+ onCopied: a
48
+ }) {
49
+ const d = F(), [f, h] = u(!1), [i, y] = u(r), [b, m] = u(!1), [x, p] = u(""), [c, l] = u(null), [g, O] = u(!1), { data: N, isLoading: R } = oe(i), { data: E = [] } = me(f && b), z = ee(() => ue(s, o.key), [s, o.key]), k = re(z, r, i), G = ne(i), P = Number(s.layout.id), C = ((N == null ? void 0 : N.rows) ?? []).filter(
50
+ (t) => !(i === r && t.layout_id === P)
51
+ ), j = o.label || T(o.key), w = x.trim().toLowerCase(), B = () => {
52
+ y(r), m(!1), p(""), l(null);
53
+ }, H = async () => {
54
+ var t;
55
+ if (!(c == null || g)) {
56
+ O(!0);
57
+ try {
58
+ const _ = await ie(d, c, {
59
+ source_layout_id: P,
60
+ group_key: o.key,
61
+ source_bundle: s,
62
+ field_map: i === r ? void 0 : k.map
63
+ });
64
+ G();
65
+ const J = ((t = C.find((U) => U.layout_id === c)) == null ? void 0 : t.name) ?? "the form", I = ce(_);
66
+ v.success(`Copied ${j} to ${J}${I ? ` (${I})` : ""}`), a == null || a(c, i), h(!1), B();
67
+ } catch (_) {
68
+ v.error(D(_, "Could not copy the section").message);
69
+ } finally {
70
+ O(!1);
71
+ }
72
+ }
73
+ };
74
+ return /* @__PURE__ */ n(
75
+ M,
76
+ {
77
+ open: f,
78
+ onOpenChange: (t) => {
79
+ h(t), t || B();
80
+ },
81
+ children: [
82
+ /* @__PURE__ */ e(W, { asChild: !0, children: /* @__PURE__ */ n("button", { type: "button", className: K, "data-reuse-copy": "", children: [
83
+ /* @__PURE__ */ e(X, { className: "h-3.5 w-3.5" }),
84
+ "Copy to layout…"
85
+ ] }) }),
86
+ /* @__PURE__ */ n(A, { align: "start", className: "w-[340px] p-3", children: [
87
+ /* @__PURE__ */ n("p", { className: "mb-2 text-[12px] leading-snug text-slate-600 dark:text-muted-foreground", children: [
88
+ "Copy ",
89
+ /* @__PURE__ */ e("b", { className: "font-semibold text-slate-800 dark:text-foreground", children: j }),
90
+ " with its fields and settings. Tip: drag the section onto a form in the Forms list."
91
+ ] }),
92
+ b ? /* @__PURE__ */ n($, { children: [
93
+ /* @__PURE__ */ n(
94
+ "button",
95
+ {
96
+ type: "button",
97
+ onClick: () => m(!1),
98
+ className: "mb-1 inline-flex items-center gap-0.5 text-[12px] text-slate-500 hover:text-slate-800 dark:text-muted-foreground dark:hover:text-foreground",
99
+ children: [
100
+ /* @__PURE__ */ e(Y, { className: "h-3.5 w-3.5" }),
101
+ "Back"
102
+ ]
103
+ }
104
+ ),
105
+ /* @__PURE__ */ e(
106
+ "input",
107
+ {
108
+ value: x,
109
+ onChange: (t) => p(t.target.value),
110
+ placeholder: "Find a collection",
111
+ "aria-label": "Find a collection",
112
+ className: S
113
+ }
114
+ ),
115
+ /* @__PURE__ */ e("div", { className: "mt-1 max-h-[220px] overflow-y-auto overscroll-contain", children: E.filter(
116
+ (t) => !w || t.label.toLowerCase().includes(w) || t.collection.includes(w)
117
+ ).slice(0, 60).map((t) => /* @__PURE__ */ n(
118
+ "button",
119
+ {
120
+ type: "button",
121
+ className: q,
122
+ onClick: () => {
123
+ y(t.collection), l(null), m(!1), p("");
124
+ },
125
+ children: [
126
+ /* @__PURE__ */ e("span", { className: "truncate", children: t.label }),
127
+ /* @__PURE__ */ e("span", { className: "ml-auto shrink-0 font-mono text-[11px] text-slate-400", children: t.collection })
128
+ ]
129
+ },
130
+ t.collection
131
+ )) })
132
+ ] }) : /* @__PURE__ */ n($, { children: [
133
+ /* @__PURE__ */ n("div", { className: "flex items-center justify-between", children: [
134
+ /* @__PURE__ */ n("span", { className: L, children: [
135
+ "Layouts of ",
136
+ /* @__PURE__ */ e("span", { className: "font-mono font-normal", children: i })
137
+ ] }),
138
+ /* @__PURE__ */ e(
139
+ "button",
140
+ {
141
+ type: "button",
142
+ onClick: () => m(!0),
143
+ className: "mb-1 text-[11.5px] font-medium text-[#0089ad] hover:underline dark:text-nvr-cyan",
144
+ children: "Another collection…"
145
+ }
146
+ )
147
+ ] }),
148
+ /* @__PURE__ */ n(
149
+ "div",
150
+ {
151
+ role: "listbox",
152
+ "aria-label": "Copy to layout",
153
+ className: "max-h-[200px] overflow-y-auto overscroll-contain",
154
+ children: [
155
+ C.map((t) => /* @__PURE__ */ e(
156
+ "button",
157
+ {
158
+ type: "button",
159
+ role: "option",
160
+ "aria-selected": c === t.layout_id,
161
+ "data-reuse-target": t.layout_id,
162
+ onClick: () => l(t.layout_id),
163
+ className: ae(q, c === t.layout_id && "bg-accent hover:bg-accent"),
164
+ children: /* @__PURE__ */ e("span", { className: "truncate", children: t.name })
165
+ },
166
+ t.layout_id
167
+ )),
168
+ !R && C.length === 0 && /* @__PURE__ */ e("p", { className: "px-2 py-1.5 text-[12px] text-slate-500 dark:text-muted-foreground", children: "No other layout here yet." })
169
+ ]
170
+ }
171
+ ),
172
+ c != null && i !== r && /* @__PURE__ */ e("div", { className: "mt-2 border-t border-slate-200 pt-2 dark:border-border", children: /* @__PURE__ */ e(
173
+ se,
174
+ {
175
+ needed: k.needed,
176
+ map: k.map,
177
+ onChange: k.setMap,
178
+ targetCollection: i
179
+ }
180
+ ) }),
181
+ /* @__PURE__ */ e("div", { className: "mt-3 flex justify-end", children: /* @__PURE__ */ e(
182
+ "button",
183
+ {
184
+ type: "button",
185
+ className: Q,
186
+ disabled: c == null || g || k.loading,
187
+ onClick: () => void H(),
188
+ children: g ? "Copying…" : "Copy"
189
+ }
190
+ ) })
191
+ ] })
192
+ ] })
193
+ ]
194
+ }
195
+ );
196
+ }
197
+ function fe({ bundle: s, group: r }) {
198
+ const o = F(), a = le(), [d, f] = u(!1), [h, i] = u(""), [y, b] = u(""), [m, x] = u(!1), p = r.label || T(r.key), c = async () => {
199
+ const l = (h || p).trim();
200
+ if (!(!l || m)) {
201
+ x(!0);
202
+ try {
203
+ await de(o, {
204
+ kind: "section",
205
+ name: l,
206
+ description: y || null,
207
+ layout_id: Number(s.layout.id),
208
+ group_key: r.key,
209
+ bundle: s
210
+ }), a("section"), v.success(`Saved ${l} to the section library`), f(!1), i(""), b("");
211
+ } catch (g) {
212
+ v.error(D(g, "Could not save the section").message);
213
+ } finally {
214
+ x(!1);
215
+ }
216
+ }
217
+ };
218
+ return /* @__PURE__ */ n(M, { open: d, onOpenChange: f, children: [
219
+ /* @__PURE__ */ e(W, { asChild: !0, children: /* @__PURE__ */ n("button", { type: "button", className: K, "data-reuse-save-section": "", children: [
220
+ /* @__PURE__ */ e(Z, { className: "h-3.5 w-3.5" }),
221
+ "Save to library…"
222
+ ] }) }),
223
+ /* @__PURE__ */ n(A, { align: "start", className: "w-[320px] p-3", children: [
224
+ /* @__PURE__ */ e("p", { className: "mb-2 text-[12px] leading-snug text-slate-600 dark:text-muted-foreground", children: "Saved sections show under Add → Section library on every collection’s forms." }),
225
+ /* @__PURE__ */ n("label", { className: "block", children: [
226
+ /* @__PURE__ */ e("span", { className: L, children: "Name" }),
227
+ /* @__PURE__ */ e(
228
+ "input",
229
+ {
230
+ value: h,
231
+ placeholder: p,
232
+ onChange: (l) => i(l.target.value),
233
+ onKeyDown: (l) => {
234
+ l.key === "Enter" && c();
235
+ },
236
+ className: S
237
+ }
238
+ )
239
+ ] }),
240
+ /* @__PURE__ */ n("label", { className: "mt-2 block", children: [
241
+ /* @__PURE__ */ e("span", { className: L, children: "Description (optional)" }),
242
+ /* @__PURE__ */ e(
243
+ "input",
244
+ {
245
+ value: y,
246
+ onChange: (l) => b(l.target.value),
247
+ placeholder: "What it is for",
248
+ className: S
249
+ }
250
+ )
251
+ ] }),
252
+ /* @__PURE__ */ e("div", { className: "mt-3 flex justify-end", children: /* @__PURE__ */ e(
253
+ "button",
254
+ {
255
+ type: "button",
256
+ className: Q,
257
+ disabled: m,
258
+ onClick: () => void c(),
259
+ children: m ? "Saving…" : "Save"
260
+ }
261
+ ) })
262
+ ] })
263
+ ] });
264
+ }
265
+ function Le({
266
+ bundle: s,
267
+ collection: r,
268
+ group: o
269
+ }) {
270
+ return /* @__PURE__ */ n(
271
+ "div",
272
+ {
273
+ "data-reuse-actions": "",
274
+ className: "flex flex-wrap gap-1.5 border-t border-slate-200 pt-3 dark:border-border",
275
+ children: [
276
+ /* @__PURE__ */ e(pe, { bundle: s, collection: r, group: o }),
277
+ /* @__PURE__ */ e(fe, { bundle: s, group: o })
278
+ ]
279
+ }
280
+ );
281
+ }
282
+ export {
283
+ pe as CopyToLayout,
284
+ fe as SaveSectionToLibrary,
285
+ Le as SectionReuseActions,
286
+ K as reuseBtn,
287
+ S as reuseInput,
288
+ L as reuseLabel,
289
+ Q as reusePrimary,
290
+ ue as sectionFields
291
+ };
@@ -0,0 +1,77 @@
1
+ const w = (i) => i.toLowerCase().replace(/[^a-z0-9]/g, ""), M = (i) => i.replace(/([a-z0-9])([A-Z])/g, "$1 $2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
2
+ function j(i, l, c) {
3
+ if (Math.abs(i.length - l.length) > c) return c + 1;
4
+ let s = Array.from({ length: l.length + 1 }, (f, o) => o);
5
+ for (let f = 1; f <= i.length; f++) {
6
+ const o = [f];
7
+ let a = f;
8
+ for (let t = 1; t <= l.length; t++)
9
+ o[t] = Math.min(s[t] + 1, o[t - 1] + 1, s[t - 1] + (i[f - 1] === l[t - 1] ? 0 : 1)), a = Math.min(a, o[t]);
10
+ if (a > c) return c + 1;
11
+ s = o;
12
+ }
13
+ return s[l.length];
14
+ }
15
+ function v(i, l, c = []) {
16
+ const s = new Set(c), f = new Map(l.map((t) => [t.field, t])), o = [], a = (t, e, u) => {
17
+ e && s.add(e), o.push({ input: t, field: e, how: e ? u : null });
18
+ };
19
+ for (const t of i) {
20
+ const e = t.trim();
21
+ if (!e) continue;
22
+ const u = l.filter((n) => !s.has(n.field));
23
+ if (f.has(e) && !s.has(e)) {
24
+ a(e, e, "exact");
25
+ continue;
26
+ }
27
+ const r = w(e), m = u.find((n) => w(n.field) === r);
28
+ if (m) {
29
+ a(e, m.field, "same");
30
+ continue;
31
+ }
32
+ const p = u.find((n) => n.label && w(n.label) === r);
33
+ if (p) {
34
+ a(e, p.field, "label");
35
+ continue;
36
+ }
37
+ const b = r.length >= 8 ? 2 : r.length >= 4 ? 1 : 0;
38
+ let d = null;
39
+ for (const n of u)
40
+ for (const g of [n.field, n.label ?? ""]) {
41
+ if (!g) continue;
42
+ const h = j(r, w(g), b);
43
+ h <= b && (!d || h < d.d) && (d = { field: n.field, d: h });
44
+ }
45
+ if (!d) {
46
+ const n = M(e), g = n.length ? u.filter(
47
+ (h) => [h.field, h.label ?? ""].some((y) => {
48
+ const z = new Set(M(y));
49
+ return n.every((S) => z.has(S));
50
+ })
51
+ ) : [];
52
+ g.length === 1 && (d = { field: g[0].field, d: 0 });
53
+ }
54
+ a(e, (d == null ? void 0 : d.field) ?? null, d ? "close" : null);
55
+ }
56
+ return o;
57
+ }
58
+ function k(i, l) {
59
+ const c = new Set(l.map((e) => e.field)), s = i.map((e) => typeof e == "string" ? { field: e } : e), f = s.filter((e) => !c.has(e.field)), o = s.filter((e) => c.has(e.field)).map((e) => e.field), a = v(
60
+ f.map((e) => e.field),
61
+ l,
62
+ o
63
+ ), t = {};
64
+ return f.forEach((e, u) => {
65
+ var m, p;
66
+ let r = ((m = a[u]) == null ? void 0 : m.field) ?? null;
67
+ !r && e.label && (r = ((p = v([e.label], l, [
68
+ ...o,
69
+ ...Object.values(t).filter(Boolean)
70
+ ])[0]) == null ? void 0 : p.field) ?? null), t[e.field] = r;
71
+ }), t;
72
+ }
73
+ export {
74
+ v as matchNames,
75
+ w as squash,
76
+ k as suggestFieldMap
77
+ };
@@ -0,0 +1,73 @@
1
+ import { useQueryClient as m, useQuery as f } from "@tanstack/react-query";
2
+ import { useCallback as d } from "react";
3
+ import { useNivaroClient as y } from "../../../context.js";
4
+ import { post as s, get as h, del as g } from "../../../lib/commands.js";
5
+ const c = {
6
+ templates: (e) => ["layout-editor", "templates", e]
7
+ }, q = (e) => {
8
+ const t = (e == null ? void 0 : e.data) ?? e;
9
+ return Array.isArray(t) ? t : [];
10
+ };
11
+ function T(e, t = !0) {
12
+ const n = y();
13
+ return f({
14
+ queryKey: c.templates(e),
15
+ queryFn: () => n.request(h("/collection-layouts/templates", { kind: e })).then(q),
16
+ enabled: t,
17
+ staleTime: 3e4
18
+ });
19
+ }
20
+ function v() {
21
+ const e = m();
22
+ return d(
23
+ (t) => void e.invalidateQueries({ queryKey: c.templates(t) }),
24
+ [e]
25
+ );
26
+ }
27
+ const u = (e) => ({ groups: e.groups, placements: e.placements });
28
+ function C(e, t) {
29
+ const { bundle: n, ...l } = t;
30
+ return e.request(
31
+ s("/collection-layouts/templates", { ...l, ...n ? { bundle: u(n) } : {} })
32
+ );
33
+ }
34
+ function K(e, t) {
35
+ return e.request(g(`/collection-layouts/templates/${t}`));
36
+ }
37
+ function Q(e, t) {
38
+ const n = "bundle" in t.source && t.source.bundle ? { ...t.source, bundle: u(t.source.bundle) } : t.source;
39
+ return e.request(
40
+ s("/collection-layouts/blocks/plan", {
41
+ ...t,
42
+ source: n,
43
+ target_bundle: {
44
+ layout: { layout_type: t.target_bundle.layout.layout_type },
45
+ ...u(t.target_bundle)
46
+ }
47
+ })
48
+ );
49
+ }
50
+ function A(e, t, n) {
51
+ const { source_bundle: l, ...o } = n;
52
+ return e.request(
53
+ s(`/collection-layouts/${t}/copy-section`, {
54
+ ...o,
55
+ ...l ? { source_bundle: u(l) } : {}
56
+ })
57
+ );
58
+ }
59
+ function O(e) {
60
+ var l, o, r;
61
+ const t = [], n = (a, i, p) => `${a} ${a === 1 ? i : p}`;
62
+ return (l = e.already) != null && l.length && t.push(`${n(e.already.length, "field was", "fields were")} already on the form`), (o = e.unmapped) != null && o.length && t.push(`${n(e.unmapped.length, "field", "fields")} with no match left out`), (r = e.dropped) != null && r.length && t.push("conditions written for the other collection were left out"), t.join("; ");
63
+ }
64
+ export {
65
+ A as copySection,
66
+ K as deleteTemplate,
67
+ O as leftOutWords,
68
+ Q as planBlock,
69
+ c as reuseKeys,
70
+ C as saveTemplate,
71
+ v as useRefreshTemplates,
72
+ T as useTemplates
73
+ };
@@ -0,0 +1,13 @@
1
+ const d = /* @__PURE__ */ new Set(["id", "user_created", "user_updated", "date_created", "date_updated"]), r = (e) => /^(group-|presentation-)/.test(e ?? "");
2
+ function n(e) {
3
+ return e == null ? !1 : typeof e == "string" ? e.trim() !== "" : Array.isArray(e) ? e.length > 0 : typeof e == "object" ? Object.keys(e).length > 0 : !0;
4
+ }
5
+ function s(e, i) {
6
+ return i.filter(
7
+ (t) => t.field && !t.field.startsWith("__") && !d.has(t.field) && !t.hidden && !r(t.type) && !r(t.interface) && n(e[t.field])
8
+ ).map((t) => t.field);
9
+ }
10
+ export {
11
+ n as isFilled,
12
+ s as recordSeedFields
13
+ };
@@ -0,0 +1,43 @@
1
+ import { useState as y, useCallback as F } from "react";
2
+ import { toast as c } from "sonner";
3
+ import { useNivaroClient as $ } from "../../../context.js";
4
+ import { get as g } from "../../../lib/commands.js";
5
+ import { useCollectionMeta as C } from "../inspector/field-context.js";
6
+ import { useInvalidateLayouts as b, apiFailure as h } from "../overview/overview-api.js";
7
+ import { createFormFromFields as k } from "./NewFormStart.js";
8
+ import { recordSeedFields as v } from "./seed.js";
9
+ function x(e) {
10
+ const a = $(), { data: t } = C(e), l = b(e), [n, u] = y(!1);
11
+ return { make: F(
12
+ async (p, w) => {
13
+ if (n) return null;
14
+ u(!0);
15
+ try {
16
+ const r = await a.request(
17
+ g(`/items/${encodeURIComponent(e)}/${encodeURIComponent(String(p))}`)
18
+ );
19
+ if (!(r != null && r.data)) throw new Error("That record could not be read");
20
+ const s = v(r.data, (t == null ? void 0 : t.fields) ?? []);
21
+ if (!s.length) throw new Error("This record has nothing filled in yet");
22
+ const d = `Form from ${w}`.slice(0, 90);
23
+ let o = null, i = d;
24
+ for (let m = 2; o == null; m++)
25
+ try {
26
+ if (o = await k(a, { collection: e, name: i, fields: s }), o == null) throw new Error("No id came back");
27
+ } catch (f) {
28
+ if (h(f, "").status !== 409 || m > 6) throw f;
29
+ i = `${d} (${m})`;
30
+ }
31
+ return l(), c.success(`Made ${i} with ${s.length} fields`), o;
32
+ } catch (r) {
33
+ return c.error(h(r, "Could not make the form").message), null;
34
+ } finally {
35
+ u(!1);
36
+ }
37
+ },
38
+ [n, a, e, t, l]
39
+ ), busy: n, ready: !!t };
40
+ }
41
+ export {
42
+ x as useFormFromRecord
43
+ };