@cratis/components 4.42.0 → 4.42.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/compat-manifest.json +11 -11
  2. package/dist/esm/Canvas/Canvas.d.ts.map +1 -1
  3. package/dist/esm/Canvas/Canvas.js +16 -109
  4. package/dist/esm/Canvas/Canvas.js.map +1 -1
  5. package/dist/esm/Canvas/CanvasWorldLayers.d.ts +22 -0
  6. package/dist/esm/Canvas/CanvasWorldLayers.d.ts.map +1 -0
  7. package/dist/esm/Canvas/CanvasWorldLayers.js +27 -0
  8. package/dist/esm/Canvas/CanvasWorldLayers.js.map +1 -0
  9. package/dist/esm/Canvas/useCanvasSurface.d.ts +57 -0
  10. package/dist/esm/Canvas/useCanvasSurface.d.ts.map +1 -0
  11. package/dist/esm/Canvas/useCanvasSurface.js +112 -0
  12. package/dist/esm/Canvas/useCanvasSurface.js.map +1 -0
  13. package/dist/esm/Chat/ChatSidebar.d.ts +2 -2
  14. package/dist/esm/Chat/ChatSidebar.d.ts.map +1 -1
  15. package/dist/esm/Chat/ChatSidebar.js +21 -101
  16. package/dist/esm/Chat/ChatSidebar.js.map +1 -1
  17. package/dist/esm/Chat/ChatSidebarContent.d.ts +25 -0
  18. package/dist/esm/Chat/ChatSidebarContent.d.ts.map +1 -0
  19. package/dist/esm/Chat/ChatSidebarContent.js +12 -0
  20. package/dist/esm/Chat/ChatSidebarContent.js.map +1 -0
  21. package/dist/esm/Chat/ChatSidebarHeader.d.ts +16 -0
  22. package/dist/esm/Chat/ChatSidebarHeader.d.ts.map +1 -0
  23. package/dist/esm/Chat/ChatSidebarHeader.js +26 -0
  24. package/dist/esm/Chat/ChatSidebarHeader.js.map +1 -0
  25. package/dist/esm/Chat/ChatSidebarShells.d.ts +31 -0
  26. package/dist/esm/Chat/ChatSidebarShells.d.ts.map +1 -0
  27. package/dist/esm/Chat/ChatSidebarShells.js +43 -0
  28. package/dist/esm/Chat/ChatSidebarShells.js.map +1 -0
  29. package/dist/esm/Chat/useNonModalPhase.d.ts +16 -0
  30. package/dist/esm/Chat/useNonModalPhase.d.ts.map +1 -0
  31. package/dist/esm/Chat/useNonModalPhase.js +38 -0
  32. package/dist/esm/Chat/useNonModalPhase.js.map +1 -0
  33. package/dist/esm/Chat/useTopicSelection.d.ts +31 -0
  34. package/dist/esm/Chat/useTopicSelection.d.ts.map +1 -0
  35. package/dist/esm/Chat/useTopicSelection.js +45 -0
  36. package/dist/esm/Chat/useTopicSelection.js.map +1 -0
  37. package/dist/esm/CommandDialog/CommandStepperContent.d.ts.map +1 -1
  38. package/dist/esm/CommandDialog/CommandStepperContent.js +31 -119
  39. package/dist/esm/CommandDialog/CommandStepperContent.js.map +1 -1
  40. package/dist/esm/CommandDialog/CommandStepperList.d.ts +19 -0
  41. package/dist/esm/CommandDialog/CommandStepperList.d.ts.map +1 -0
  42. package/dist/esm/CommandDialog/CommandStepperList.js +20 -0
  43. package/dist/esm/CommandDialog/CommandStepperList.js.map +1 -0
  44. package/dist/esm/CommandDialog/CommandStepperNavigation.d.ts +20 -0
  45. package/dist/esm/CommandDialog/CommandStepperNavigation.d.ts.map +1 -0
  46. package/dist/esm/CommandDialog/CommandStepperNavigation.js +15 -0
  47. package/dist/esm/CommandDialog/CommandStepperNavigation.js.map +1 -0
  48. package/dist/esm/CommandDialog/CommandStepperPanels.d.ts +20 -0
  49. package/dist/esm/CommandDialog/CommandStepperPanels.d.ts.map +1 -0
  50. package/dist/esm/CommandDialog/CommandStepperPanels.js +9 -0
  51. package/dist/esm/CommandDialog/CommandStepperPanels.js.map +1 -0
  52. package/dist/esm/CommandDialog/CommandStepperStepParts.d.ts +23 -0
  53. package/dist/esm/CommandDialog/CommandStepperStepParts.d.ts.map +1 -0
  54. package/dist/esm/CommandDialog/CommandStepperStepParts.js +9 -0
  55. package/dist/esm/CommandDialog/CommandStepperStepParts.js.map +1 -0
  56. package/dist/esm/CommandDialog/commandStepperFields.d.ts +6 -0
  57. package/dist/esm/CommandDialog/commandStepperFields.d.ts.map +1 -0
  58. package/dist/esm/CommandDialog/commandStepperFields.js +54 -0
  59. package/dist/esm/CommandDialog/commandStepperFields.js.map +1 -0
  60. package/dist/esm/CommandDialog/joinClassNames.d.ts +3 -0
  61. package/dist/esm/CommandDialog/joinClassNames.d.ts.map +1 -0
  62. package/dist/esm/CommandDialog/joinClassNames.js +4 -0
  63. package/dist/esm/CommandDialog/joinClassNames.js.map +1 -0
  64. package/dist/esm/CommandDialog/resolveStepperLabels.d.ts +20 -0
  65. package/dist/esm/CommandDialog/resolveStepperLabels.d.ts.map +1 -0
  66. package/dist/esm/CommandDialog/resolveStepperLabels.js +8 -0
  67. package/dist/esm/CommandDialog/resolveStepperLabels.js.map +1 -0
  68. package/dist/esm/CommandDialog/useStepValidation.d.ts +7 -0
  69. package/dist/esm/CommandDialog/useStepValidation.d.ts.map +1 -0
  70. package/dist/esm/CommandDialog/useStepValidation.js +14 -0
  71. package/dist/esm/CommandDialog/useStepValidation.js.map +1 -0
  72. package/dist/esm/CommandDialog/useStepperState.d.ts +30 -0
  73. package/dist/esm/CommandDialog/useStepperState.d.ts.map +1 -0
  74. package/dist/esm/CommandDialog/useStepperState.js +37 -0
  75. package/dist/esm/CommandDialog/useStepperState.js.map +1 -0
  76. package/dist/esm/CommandForm/fields/ChipsField.d.ts +1 -1
  77. package/dist/esm/CommandForm/fields/ChipsField.d.ts.map +1 -1
  78. package/dist/esm/CommandForm/fields/ChipsField.js +7 -39
  79. package/dist/esm/CommandForm/fields/ChipsField.js.map +1 -1
  80. package/dist/esm/CommandForm/fields/ChipsInput.d.ts +18 -0
  81. package/dist/esm/CommandForm/fields/ChipsInput.d.ts.map +1 -0
  82. package/dist/esm/CommandForm/fields/ChipsInput.js +12 -0
  83. package/dist/esm/CommandForm/fields/ChipsInput.js.map +1 -0
  84. package/dist/esm/CommandForm/fields/ChipsItem.d.ts +14 -0
  85. package/dist/esm/CommandForm/fields/ChipsItem.d.ts.map +1 -0
  86. package/dist/esm/CommandForm/fields/ChipsItem.js +14 -0
  87. package/dist/esm/CommandForm/fields/ChipsItem.js.map +1 -0
  88. package/dist/esm/CommandForm/fields/useChipsDraft.d.ts +19 -0
  89. package/dist/esm/CommandForm/fields/useChipsDraft.d.ts.map +1 -0
  90. package/dist/esm/CommandForm/fields/useChipsDraft.js +19 -0
  91. package/dist/esm/CommandForm/fields/useChipsDraft.js.map +1 -0
  92. package/dist/esm/Common/CratisComponentsProvider.d.ts.map +1 -1
  93. package/dist/esm/Common/CratisComponentsProvider.js +1 -44
  94. package/dist/esm/Common/CratisComponentsProvider.js.map +1 -1
  95. package/dist/esm/Common/legacyLocaleMessages.d.ts +7 -0
  96. package/dist/esm/Common/legacyLocaleMessages.d.ts.map +1 -0
  97. package/dist/esm/Common/legacyLocaleMessages.js +43 -0
  98. package/dist/esm/Common/legacyLocaleMessages.js.map +1 -0
  99. package/dist/esm/DataTables/ColumnFilterActions.d.ts +11 -0
  100. package/dist/esm/DataTables/ColumnFilterActions.d.ts.map +1 -0
  101. package/dist/esm/DataTables/ColumnFilterActions.js +8 -0
  102. package/dist/esm/DataTables/ColumnFilterActions.js.map +1 -0
  103. package/dist/esm/DataTables/ColumnFilterMenu.d.ts +1 -1
  104. package/dist/esm/DataTables/ColumnFilterMenu.d.ts.map +1 -1
  105. package/dist/esm/DataTables/ColumnFilterMenu.js +16 -148
  106. package/dist/esm/DataTables/ColumnFilterMenu.js.map +1 -1
  107. package/dist/esm/DataTables/ColumnFilterTrigger.d.ts +12 -0
  108. package/dist/esm/DataTables/ColumnFilterTrigger.d.ts.map +1 -0
  109. package/dist/esm/DataTables/ColumnFilterTrigger.js +9 -0
  110. package/dist/esm/DataTables/ColumnFilterTrigger.js.map +1 -0
  111. package/dist/esm/DataTables/ColumnFilterValueInput.d.ts +24 -0
  112. package/dist/esm/DataTables/ColumnFilterValueInput.d.ts.map +1 -0
  113. package/dist/esm/DataTables/ColumnFilterValueInput.js +39 -0
  114. package/dist/esm/DataTables/ColumnFilterValueInput.js.map +1 -0
  115. package/dist/esm/DataTables/DataTableCore.d.ts +1 -1
  116. package/dist/esm/DataTables/DataTableCore.d.ts.map +1 -1
  117. package/dist/esm/DataTables/DataTableCore.js +12 -66
  118. package/dist/esm/DataTables/DataTableCore.js.map +1 -1
  119. package/dist/esm/DataTables/DataTableHead.d.ts +23 -0
  120. package/dist/esm/DataTables/DataTableHead.d.ts.map +1 -0
  121. package/dist/esm/DataTables/DataTableHead.js +12 -0
  122. package/dist/esm/DataTables/DataTableHead.js.map +1 -0
  123. package/dist/esm/DataTables/DataTableRows.d.ts +19 -0
  124. package/dist/esm/DataTables/DataTableRows.d.ts.map +1 -0
  125. package/dist/esm/DataTables/DataTableRows.js +7 -0
  126. package/dist/esm/DataTables/DataTableRows.js.map +1 -0
  127. package/dist/esm/DataTables/DataTableTable.d.ts +20 -0
  128. package/dist/esm/DataTables/DataTableTable.d.ts.map +1 -0
  129. package/dist/esm/DataTables/DataTableTable.js +10 -0
  130. package/dist/esm/DataTables/DataTableTable.js.map +1 -0
  131. package/dist/esm/DataTables/columnFilterMatchModes.d.ts +10 -0
  132. package/dist/esm/DataTables/columnFilterMatchModes.d.ts.map +1 -0
  133. package/dist/esm/DataTables/columnFilterMatchModes.js +52 -0
  134. package/dist/esm/DataTables/columnFilterMatchModes.js.map +1 -0
  135. package/dist/esm/DataTables/resolveColumnFilterLabels.d.ts +4 -0
  136. package/dist/esm/DataTables/resolveColumnFilterLabels.d.ts.map +1 -0
  137. package/dist/esm/DataTables/resolveColumnFilterLabels.js +20 -0
  138. package/dist/esm/DataTables/resolveColumnFilterLabels.js.map +1 -0
  139. package/dist/esm/DataTables/useColumnFilterDraft.d.ts +13 -0
  140. package/dist/esm/DataTables/useColumnFilterDraft.d.ts.map +1 -0
  141. package/dist/esm/DataTables/useColumnFilterDraft.js +24 -0
  142. package/dist/esm/DataTables/useColumnFilterDraft.js.map +1 -0
  143. package/dist/esm/DataTables/useDataTableRows.d.ts +40 -0
  144. package/dist/esm/DataTables/useDataTableRows.d.ts.map +1 -0
  145. package/dist/esm/DataTables/useDataTableRows.js +49 -0
  146. package/dist/esm/DataTables/useDataTableRows.js.map +1 -0
  147. package/dist/esm/DataTables/useRestoreFocusOnClose.d.ts +7 -0
  148. package/dist/esm/DataTables/useRestoreFocusOnClose.d.ts.map +1 -0
  149. package/dist/esm/DataTables/useRestoreFocusOnClose.js +30 -0
  150. package/dist/esm/DataTables/useRestoreFocusOnClose.js.map +1 -0
  151. package/dist/esm/Dialogs/DialogDocument.d.ts +22 -0
  152. package/dist/esm/Dialogs/DialogDocument.d.ts.map +1 -0
  153. package/dist/esm/Dialogs/DialogDocument.js +24 -0
  154. package/dist/esm/Dialogs/DialogDocument.js.map +1 -0
  155. package/dist/esm/Dialogs/DialogFooter.d.ts +24 -0
  156. package/dist/esm/Dialogs/DialogFooter.d.ts.map +1 -0
  157. package/dist/esm/Dialogs/DialogFooter.js +65 -0
  158. package/dist/esm/Dialogs/DialogFooter.js.map +1 -0
  159. package/dist/esm/Dialogs/DialogHeader.d.ts +31 -0
  160. package/dist/esm/Dialogs/DialogHeader.d.ts.map +1 -0
  161. package/dist/esm/Dialogs/DialogHeader.js +28 -0
  162. package/dist/esm/Dialogs/DialogHeader.js.map +1 -0
  163. package/dist/esm/Dialogs/DialogImplementation.d.ts +1 -2
  164. package/dist/esm/Dialogs/DialogImplementation.d.ts.map +1 -1
  165. package/dist/esm/Dialogs/DialogImplementation.js +88 -189
  166. package/dist/esm/Dialogs/DialogImplementation.js.map +1 -1
  167. package/dist/esm/Dialogs/DialogShells.d.ts +29 -0
  168. package/dist/esm/Dialogs/DialogShells.d.ts.map +1 -0
  169. package/dist/esm/Dialogs/DialogShells.js +36 -0
  170. package/dist/esm/Dialogs/DialogShells.js.map +1 -0
  171. package/dist/esm/Dialogs/dialogPartAttributes.d.ts +19 -0
  172. package/dist/esm/Dialogs/dialogPartAttributes.d.ts.map +1 -0
  173. package/dist/esm/Dialogs/dialogPartAttributes.js +10 -0
  174. package/dist/esm/Dialogs/dialogPartAttributes.js.map +1 -0
  175. package/dist/esm/Dialogs/resolveDialogLabels.d.ts +29 -0
  176. package/dist/esm/Dialogs/resolveDialogLabels.d.ts.map +1 -0
  177. package/dist/esm/Dialogs/resolveDialogLabels.js +11 -0
  178. package/dist/esm/Dialogs/resolveDialogLabels.js.map +1 -0
  179. package/dist/esm/Dialogs/useDialogClose.d.ts +13 -0
  180. package/dist/esm/Dialogs/useDialogClose.d.ts.map +1 -0
  181. package/dist/esm/Dialogs/useDialogClose.js +32 -0
  182. package/dist/esm/Dialogs/useDialogClose.js.map +1 -0
  183. package/dist/esm/Dialogs/useDialogFocus.d.ts +26 -0
  184. package/dist/esm/Dialogs/useDialogFocus.d.ts.map +1 -0
  185. package/dist/esm/Dialogs/useDialogFocus.js +56 -0
  186. package/dist/esm/Dialogs/useDialogFocus.js.map +1 -0
  187. package/dist/esm/Dialogs/useDialogZIndex.d.ts +9 -0
  188. package/dist/esm/Dialogs/useDialogZIndex.d.ts.map +1 -0
  189. package/dist/esm/Dialogs/useDialogZIndex.js +19 -0
  190. package/dist/esm/Dialogs/useDialogZIndex.js.map +1 -0
  191. package/dist/esm/SchemaEditor/ReadOnlyTypeCell.d.ts +6 -0
  192. package/dist/esm/SchemaEditor/ReadOnlyTypeCell.d.ts.map +1 -0
  193. package/dist/esm/SchemaEditor/ReadOnlyTypeCell.js +19 -0
  194. package/dist/esm/SchemaEditor/ReadOnlyTypeCell.js.map +1 -0
  195. package/dist/esm/SchemaEditor/SchemaEditor.d.ts.map +1 -1
  196. package/dist/esm/SchemaEditor/SchemaEditor.js +44 -514
  197. package/dist/esm/SchemaEditor/SchemaEditor.js.map +1 -1
  198. package/dist/esm/SchemaEditor/SchemaEditorNavigation.d.ts +13 -0
  199. package/dist/esm/SchemaEditor/SchemaEditorNavigation.d.ts.map +1 -0
  200. package/dist/esm/SchemaEditor/SchemaEditorNavigation.js +36 -0
  201. package/dist/esm/SchemaEditor/SchemaEditorNavigation.js.map +1 -0
  202. package/dist/esm/SchemaEditor/SchemaEditorTable.d.ts +34 -0
  203. package/dist/esm/SchemaEditor/SchemaEditorTable.d.ts.map +1 -0
  204. package/dist/esm/SchemaEditor/SchemaEditorTable.js +54 -0
  205. package/dist/esm/SchemaEditor/SchemaEditorTable.js.map +1 -0
  206. package/dist/esm/SchemaEditor/TypeCell.d.ts.map +1 -1
  207. package/dist/esm/SchemaEditor/TypeCell.js +14 -80
  208. package/dist/esm/SchemaEditor/TypeCell.js.map +1 -1
  209. package/dist/esm/SchemaEditor/TypeCellActions.d.ts +13 -0
  210. package/dist/esm/SchemaEditor/TypeCellActions.d.ts.map +1 -0
  211. package/dist/esm/SchemaEditor/TypeCellActions.js +19 -0
  212. package/dist/esm/SchemaEditor/TypeCellActions.js.map +1 -0
  213. package/dist/esm/SchemaEditor/resolveTypeChange.d.ts +12 -0
  214. package/dist/esm/SchemaEditor/resolveTypeChange.d.ts.map +1 -0
  215. package/dist/esm/SchemaEditor/resolveTypeChange.js +19 -0
  216. package/dist/esm/SchemaEditor/resolveTypeChange.js.map +1 -0
  217. package/dist/esm/SchemaEditor/schemaDocument.d.ts +20 -0
  218. package/dist/esm/SchemaEditor/schemaDocument.d.ts.map +1 -0
  219. package/dist/esm/SchemaEditor/schemaDocument.js +70 -0
  220. package/dist/esm/SchemaEditor/schemaDocument.js.map +1 -0
  221. package/dist/esm/SchemaEditor/schemaEditorMenu.d.ts +30 -0
  222. package/dist/esm/SchemaEditor/schemaEditorMenu.d.ts.map +1 -0
  223. package/dist/esm/SchemaEditor/schemaEditorMenu.js +51 -0
  224. package/dist/esm/SchemaEditor/schemaEditorMenu.js.map +1 -0
  225. package/dist/esm/SchemaEditor/schemaPropertyEdits.d.ts +33 -0
  226. package/dist/esm/SchemaEditor/schemaPropertyEdits.d.ts.map +1 -0
  227. package/dist/esm/SchemaEditor/schemaPropertyEdits.js +134 -0
  228. package/dist/esm/SchemaEditor/schemaPropertyEdits.js.map +1 -0
  229. package/dist/esm/SchemaEditor/typeOptions.d.ts +11 -0
  230. package/dist/esm/SchemaEditor/typeOptions.d.ts.map +1 -0
  231. package/dist/esm/SchemaEditor/typeOptions.js +20 -0
  232. package/dist/esm/SchemaEditor/typeOptions.js.map +1 -0
  233. package/dist/esm/SchemaEditor/useSchemaDocument.d.ts +26 -0
  234. package/dist/esm/SchemaEditor/useSchemaDocument.d.ts.map +1 -0
  235. package/dist/esm/SchemaEditor/useSchemaDocument.js +65 -0
  236. package/dist/esm/SchemaEditor/useSchemaDocument.js.map +1 -0
  237. package/dist/esm/SchemaEditor/useSchemaEdits.d.ts +29 -0
  238. package/dist/esm/SchemaEditor/useSchemaEdits.d.ts.map +1 -0
  239. package/dist/esm/SchemaEditor/useSchemaEdits.js +50 -0
  240. package/dist/esm/SchemaEditor/useSchemaEdits.js.map +1 -0
  241. package/dist/esm/SchemaEditor/useSchemaNavigation.d.ts +15 -0
  242. package/dist/esm/SchemaEditor/useSchemaNavigation.d.ts.map +1 -0
  243. package/dist/esm/SchemaEditor/useSchemaNavigation.js +24 -0
  244. package/dist/esm/SchemaEditor/useSchemaNavigation.js.map +1 -0
  245. package/dist/esm/SchemaEditor/useSchemaRows.d.ts +17 -0
  246. package/dist/esm/SchemaEditor/useSchemaRows.d.ts.map +1 -0
  247. package/dist/esm/SchemaEditor/useSchemaRows.js +49 -0
  248. package/dist/esm/SchemaEditor/useSchemaRows.js.map +1 -0
  249. package/package.json +1 -1
@@ -0,0 +1,19 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { Button } from '../Common/Button.js';
3
+ import { Tooltip } from '../Common/Tooltip.js';
4
+ import * as faIcons from 'react-icons/fa6';
5
+
6
+ const ActionButton = ({ label, icon, tone, onClick }) => (jsx(Tooltip, { content: label, position: 'top', children: jsx(Button, { variant: 'ghost', tone: tone, size: 'small', icon: icon, onClick: onClick, "aria-label": label }) }));
7
+ const navigatesToArrayItems = (rowData) => rowData.type === 'array' && rowData.items?.type === 'object';
8
+ const TypeCellActions = ({ rowData, canRemove, labels, onNavigateToProperty, onNavigateToArrayItems, onRemoveProperty, }) => {
9
+ const name = rowData.name;
10
+ return (jsxs("div", { style: {
11
+ marginLeft: 'auto',
12
+ display: 'flex',
13
+ alignItems: 'center',
14
+ gap: '0.5rem',
15
+ }, children: [name && navigatesToArrayItems(rowData) && (jsx(ActionButton, { label: labels.navigateToItemDefinition, icon: jsx(faIcons.FaArrowRight, {}), onClick: () => onNavigateToArrayItems(name) })), name && rowData.type === 'object' && (jsx(ActionButton, { label: labels.navigateToProperties, icon: jsx(faIcons.FaArrowRight, {}), onClick: () => onNavigateToProperty(name) })), name && canRemove && (jsx(ActionButton, { label: labels.deleteProperty, icon: jsx(faIcons.FaTrash, {}), tone: 'critical', onClick: () => onRemoveProperty(name) }))] }));
16
+ };
17
+
18
+ export { TypeCellActions };
19
+ //# sourceMappingURL=TypeCellActions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypeCellActions.js","sources":["../../../SchemaEditor/TypeCellActions.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Button } from '../Common/Button';\nimport { Tooltip } from '../Common/Tooltip';\nimport * as faIcons from 'react-icons/fa6';\nimport type { JsonSchemaProperty } from '../types/JsonSchema';\nimport type { SchemaEditorLabels } from './SchemaEditor';\n\nexport interface TypeCellActionsProps {\n rowData: JsonSchemaProperty;\n canRemove: boolean;\n labels: SchemaEditorLabels;\n onNavigateToProperty: (propertyName: string) => void;\n onNavigateToArrayItems: (propertyName: string) => void;\n onRemoveProperty: (propertyName: string) => void;\n}\n\ninterface ActionButtonProps {\n label: string;\n icon: React.ReactNode;\n tone?: 'critical';\n onClick: () => void;\n}\n\nconst ActionButton = ({ label, icon, tone, onClick }: ActionButtonProps) => (\n <Tooltip content={label} position='top'>\n <Button\n variant='ghost'\n tone={tone}\n size='small'\n icon={icon}\n onClick={onClick}\n aria-label={label}\n />\n </Tooltip>\n);\n\nconst navigatesToArrayItems = (rowData: JsonSchemaProperty) =>\n rowData.type === 'array' && rowData.items?.type === 'object';\n\n/** The navigate and delete buttons at the end of an editable type cell. */\nexport const TypeCellActions = ({\n rowData,\n canRemove,\n labels,\n onNavigateToProperty,\n onNavigateToArrayItems,\n onRemoveProperty,\n}: TypeCellActionsProps) => {\n const name = rowData.name;\n return (\n <div\n style={{\n marginLeft: 'auto',\n display: 'flex',\n alignItems: 'center',\n gap: '0.5rem',\n }}\n >\n {name && navigatesToArrayItems(rowData) && (\n <ActionButton\n label={labels.navigateToItemDefinition}\n icon={<faIcons.FaArrowRight />}\n onClick={() => onNavigateToArrayItems(name)}\n />\n )}\n {name && rowData.type === 'object' && (\n <ActionButton\n label={labels.navigateToProperties}\n icon={<faIcons.FaArrowRight />}\n onClick={() => onNavigateToProperty(name)}\n />\n )}\n {name && canRemove && (\n <ActionButton\n label={labels.deleteProperty}\n icon={<faIcons.FaTrash />}\n tone='critical'\n onClick={() => onRemoveProperty(name)}\n />\n )}\n </div>\n );\n};\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;AAyBA,MAAM,YAAY,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAqB,MACnEA,GAAA,CAAC,OAAO,EAAA,EAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAC,KAAK,EAAA,QAAA,EACnCA,IAAC,MAAM,EAAA,EACH,OAAO,EAAC,OAAO,EACf,IAAI,EAAE,IAAI,EACV,IAAI,EAAC,OAAO,EACZ,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,EAAA,YAAA,EACJ,KAAK,EAAA,CACnB,EAAA,CACI,CACb;AAED,MAAM,qBAAqB,GAAG,CAAC,OAA2B,KACtD,OAAO,CAAC,IAAI,KAAK,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,IAAI,KAAK,QAAQ;AAGzD,MAAM,eAAe,GAAG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: 'property';
7
+ type: string;
8
+ format: string | undefined;
9
+ };
10
+ /** Works out what choosing `value` in a type dropdown means for the property, or for its array items. */
11
+ export declare const resolveTypeChange: (value: string, typeFormats: TypeFormat[], isArrayItem: boolean) => TypeChange;
12
+ //# sourceMappingURL=resolveTypeChange.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveTypeChange.d.ts","sourceRoot":"","sources":["../../../SchemaEditor/resolveTypeChange.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAqB,CAAC;AAGtD,MAAM,MAAM,UAAU,GAChB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAkBrE,yGAAyG;AACzG,eAAO,MAAM,iBAAiB,UAAW,MAAM,eAAe,UAAU,EAAE,eAAe,OAAO,KAAG,UAGlG,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { CONTAINER_TYPES, effectiveFormat } from './typeOptions.js';
2
+
3
+ const resolveTypeAndFormat = (value, typeFormats) => {
4
+ if (CONTAINER_TYPES.some(container => container.value === value)) {
5
+ return { type: value, format: undefined };
6
+ }
7
+ const typeFormat = typeFormats.find(candidate => effectiveFormat(candidate) === value);
8
+ if (!typeFormat) {
9
+ return { type: value, format: undefined };
10
+ }
11
+ return { type: typeFormat.jsonType, format: typeFormat.format ? value : undefined };
12
+ };
13
+ const resolveTypeChange = (value, typeFormats, isArrayItem) => {
14
+ const { type, format } = resolveTypeAndFormat(value, typeFormats);
15
+ return isArrayItem ? { kind: 'arrayItem', type } : { kind: 'property', type, format };
16
+ };
17
+
18
+ export { resolveTypeChange };
19
+ //# sourceMappingURL=resolveTypeChange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveTypeChange.js","sources":["../../../SchemaEditor/resolveTypeChange.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport type { TypeFormat } from '../types/TypeFormat';\nimport { CONTAINER_TYPES, effectiveFormat } from './typeOptions';\n\nexport type TypeChange =\n | { kind: 'arrayItem'; type: string }\n | { kind: 'property'; type: string; format: string | undefined };\n\ninterface TypeAndFormat {\n type: string;\n format: string | undefined;\n}\n\nconst resolveTypeAndFormat = (value: string, typeFormats: TypeFormat[]): TypeAndFormat => {\n if (CONTAINER_TYPES.some(container => container.value === value)) {\n return { type: value, format: undefined };\n }\n const typeFormat = typeFormats.find(candidate => effectiveFormat(candidate) === value);\n if (!typeFormat) {\n return { type: value, format: undefined };\n }\n return { type: typeFormat.jsonType, format: typeFormat.format ? value : undefined };\n};\n\n/** Works out what choosing `value` in a type dropdown means for the property, or for its array items. */\nexport const resolveTypeChange = (value: string, typeFormats: TypeFormat[], isArrayItem: boolean): TypeChange => {\n const { type, format } = resolveTypeAndFormat(value, typeFormats);\n return isArrayItem ? { kind: 'arrayItem', type } : { kind: 'property', type, format };\n};\n"],"names":[],"mappings":";;AAeA,MAAM,oBAAoB,GAAG,CAAC,KAAa,EAAE,WAAyB,KAAmB;AACrF,IAAA,IAAI,eAAe,CAAC,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,KAAK,KAAK,KAAK,CAAC,EAAE;QAC9D,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE;IAC7C;AACA,IAAA,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,SAAS,IAAI,eAAe,CAAC,SAAS,CAAC,KAAK,KAAK,CAAC;IACtF,IAAI,CAAC,UAAU,EAAE;QACb,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE;IAC7C;IACA,OAAO,EAAE,IAAI,EAAE,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,GAAG,KAAK,GAAG,SAAS,EAAE;AACvF,CAAC;AAGM,MAAM,iBAAiB,GAAG,CAAC,KAAa,EAAE,WAAyB,EAAE,WAAoB,KAAgB;AAC5G,IAAA,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,oBAAoB,CAAC,KAAK,EAAE,WAAW,CAAC;IACjE,OAAO,WAAW,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE;AACzF;;"}
@@ -0,0 +1,20 @@
1
+ import type { JsonSchema, JsonSchemaProperty } from '../types/JsonSchema.js';
2
+ /**
3
+ * Deep-copies a schema through JSON and validates the copy.
4
+ * @param schema The schema to copy.
5
+ * @returns The copy, or undefined when the schema is not serializable or malformed.
6
+ */
7
+ export declare const cloneSchema: (schema: JsonSchema) => JsonSchema | undefined;
8
+ export declare const asJsonSchema: (property: JsonSchemaProperty) => JsonSchema;
9
+ export declare const asJsonSchemaProperty: (schema: JsonSchema) => JsonSchemaProperty;
10
+ /** Follows a drill-down path (property names and `$items`) to the schema it points at. */
11
+ export declare const findSchemaAtPath: (root: JsonSchema, path: string[]) => JsonSchema | undefined;
12
+ /**
13
+ * Applies an updater to the schema at a drill-down path of a schema copy.
14
+ * @param root A schema copy that may be mutated.
15
+ * @param path The drill-down path; empty for the root itself.
16
+ * @param updater Produces the replacement for the schema at the path.
17
+ * @returns The schema to use as the new root.
18
+ */
19
+ export declare const updateSchemaAtPath: (root: JsonSchema, path: string[], updater: (schema: JsonSchema) => JsonSchema) => JsonSchema;
20
+ //# sourceMappingURL=schemaDocument.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaDocument.d.ts","sourceRoot":"","sources":["../../../SchemaEditor/schemaDocument.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,wBAAqB,CAAC;AA6B1E;;;;GAIG;AACH,eAAO,MAAM,WAAW,WAAY,UAAU,KAAG,UAAU,GAAG,SAU7D,CAAC;AAEF,eAAO,MAAM,YAAY,aAAc,kBAAkB,KAAG,UAI3D,CAAC;AAEF,eAAO,MAAM,oBAAoB,WAAY,UAAU,KAAG,kBAGzD,CAAC;AAEF,0FAA0F;AAC1F,eAAO,MAAM,gBAAgB,SAAU,UAAU,QAAQ,MAAM,EAAE,KAAG,UAAU,GAAG,SAYhF,CAAC;AAsBF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,SACrB,UAAU,QACV,MAAM,EAAE,WACL,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU,KAC5C,UAMF,CAAC"}
@@ -0,0 +1,70 @@
1
+ const isPlainObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
2
+ const isStringArray = (value) => Array.isArray(value) && value.every((entry) => typeof entry === 'string');
3
+ const hasValidRequired = (node) => node.required === undefined || isStringArray(node.required);
4
+ const areNestedSchemasValid = (nestedSchemas) => nestedSchemas === undefined ||
5
+ (isPlainObject(nestedSchemas) && Object.values(nestedSchemas).every((nested) => isValidSchemaNode(nested)));
6
+ const isValidSchemaNode = (node) => isPlainObject(node) &&
7
+ hasValidRequired(node) &&
8
+ areNestedSchemasValid(node.properties) &&
9
+ areNestedSchemasValid(node.definitions) &&
10
+ (node.items === undefined || isValidSchemaNode(node.items));
11
+ const cloneSchema = (schema) => {
12
+ try {
13
+ const serializedSchema = JSON.stringify(schema);
14
+ if (serializedSchema === undefined)
15
+ return undefined;
16
+ const parsedSchema = JSON.parse(serializedSchema);
17
+ return isValidSchemaNode(parsedSchema) ? parsedSchema : undefined;
18
+ }
19
+ catch {
20
+ return undefined;
21
+ }
22
+ };
23
+ const asJsonSchema = (property) => {
24
+ return property;
25
+ };
26
+ const asJsonSchemaProperty = (schema) => {
27
+ return schema;
28
+ };
29
+ const findSchemaAtPath = (root, path) => {
30
+ let target = root;
31
+ for (const segment of path) {
32
+ if (target.type === 'array' && segment === '$items') {
33
+ target = target.items || {};
34
+ }
35
+ else if (target.properties?.[segment]) {
36
+ target = target.properties[segment];
37
+ }
38
+ else {
39
+ return undefined;
40
+ }
41
+ }
42
+ return target;
43
+ };
44
+ const stepInto = (target, segment) => {
45
+ if (target.type === 'array' && segment === '$items') {
46
+ target.items ??= { type: 'object', properties: {} };
47
+ return target.items;
48
+ }
49
+ const property = target.properties?.[segment];
50
+ return property ? asJsonSchema(property) : target;
51
+ };
52
+ const replaceLastSegment = (parent, segment, updater) => {
53
+ if (parent.type === 'array' && segment === '$items') {
54
+ parent.items = updater(parent.items || {});
55
+ return;
56
+ }
57
+ parent.properties ??= {};
58
+ const propertySchema = parent.properties[segment];
59
+ parent.properties[segment] = asJsonSchemaProperty(updater(propertySchema ? asJsonSchema(propertySchema) : {}));
60
+ };
61
+ const updateSchemaAtPath = (root, path, updater) => {
62
+ if (path.length === 0)
63
+ return updater(root);
64
+ const parent = path.slice(0, -1).reduce(stepInto, root);
65
+ replaceLastSegment(parent, path[path.length - 1], updater);
66
+ return root;
67
+ };
68
+
69
+ export { asJsonSchema, asJsonSchemaProperty, cloneSchema, findSchemaAtPath, updateSchemaAtPath };
70
+ //# sourceMappingURL=schemaDocument.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaDocument.js","sources":["../../../SchemaEditor/schemaDocument.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport type { JsonSchema, JsonSchemaProperty } from '../types/JsonSchema';\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst isStringArray = (value: unknown): boolean =>\n Array.isArray(value) && value.every((entry) => typeof entry === 'string');\n\nconst hasValidRequired = (node: Record<string, unknown>): boolean =>\n node.required === undefined || isStringArray(node.required);\n\nconst areNestedSchemasValid = (nestedSchemas: unknown): boolean =>\n nestedSchemas === undefined ||\n (isPlainObject(nestedSchemas) && Object.values(nestedSchemas).every((nested) => isValidSchemaNode(nested)));\n\n/**\n * Recursively validates that a parsed schema node, its required names, and every nested\n * `properties`, `definitions`, and `items` schema match the supported object shape. A JSON-valid\n * document can still contain malformed nested values (for example `properties.foo: null`,\n * `required: {}`, or `items: \"string\"`) that later code dereferences as schema data; those are\n * rejected here rather than crashing downstream.\n */\nconst isValidSchemaNode = (node: unknown): node is JsonSchema =>\n isPlainObject(node) &&\n hasValidRequired(node) &&\n areNestedSchemasValid(node.properties) &&\n areNestedSchemasValid(node.definitions) &&\n (node.items === undefined || isValidSchemaNode(node.items));\n\n/**\n * Deep-copies a schema through JSON and validates the copy.\n * @param schema The schema to copy.\n * @returns The copy, or undefined when the schema is not serializable or malformed.\n */\nexport const cloneSchema = (schema: JsonSchema): JsonSchema | undefined => {\n try {\n const serializedSchema = JSON.stringify(schema);\n if (serializedSchema === undefined) return undefined;\n\n const parsedSchema: unknown = JSON.parse(serializedSchema);\n return isValidSchemaNode(parsedSchema) ? parsedSchema : undefined;\n } catch {\n return undefined;\n }\n};\n\nexport const asJsonSchema = (property: JsonSchemaProperty): JsonSchema => {\n // SAFETY: A nested \"object\" property has the same editable shape as a schema —\n // `properties`, `items`, and `required` all mean the same thing on both types.\n return property as unknown as JsonSchema;\n};\n\nexport const asJsonSchemaProperty = (schema: JsonSchema): JsonSchemaProperty => {\n // SAFETY: The inverse of asJsonSchema; the shapes are structurally interchangeable.\n return schema as unknown as JsonSchemaProperty;\n};\n\n/** Follows a drill-down path (property names and `$items`) to the schema it points at. */\nexport const findSchemaAtPath = (root: JsonSchema, path: string[]): JsonSchema | undefined => {\n let target: JsonSchema | JsonSchemaProperty = root;\n for (const segment of path) {\n if (target.type === 'array' && segment === '$items') {\n target = target.items || {};\n } else if (target.properties?.[segment]) {\n target = target.properties[segment];\n } else {\n return undefined;\n }\n }\n return target as unknown as JsonSchema;\n};\n\n/** Steps one segment down, creating the array's item schema on the way; stays put on an unknown segment. */\nconst stepInto = (target: JsonSchema, segment: string): JsonSchema => {\n if (target.type === 'array' && segment === '$items') {\n target.items ??= { type: 'object', properties: {} };\n return target.items;\n }\n const property = target.properties?.[segment];\n return property ? asJsonSchema(property) : target;\n};\n\nconst replaceLastSegment = (parent: JsonSchema, segment: string, updater: (schema: JsonSchema) => JsonSchema) => {\n if (parent.type === 'array' && segment === '$items') {\n parent.items = updater(parent.items || {});\n return;\n }\n parent.properties ??= {};\n const propertySchema = parent.properties[segment];\n parent.properties[segment] = asJsonSchemaProperty(updater(propertySchema ? asJsonSchema(propertySchema) : {}));\n};\n\n/**\n * Applies an updater to the schema at a drill-down path of a schema copy.\n * @param root A schema copy that may be mutated.\n * @param path The drill-down path; empty for the root itself.\n * @param updater Produces the replacement for the schema at the path.\n * @returns The schema to use as the new root.\n */\nexport const updateSchemaAtPath = (\n root: JsonSchema,\n path: string[],\n updater: (schema: JsonSchema) => JsonSchema,\n): JsonSchema => {\n if (path.length === 0) return updater(root);\n\n const parent = path.slice(0, -1).reduce(stepInto, root);\n replaceLastSegment(parent, path[path.length - 1], updater);\n return root;\n};\n"],"names":[],"mappings":"AAKA,MAAM,aAAa,GAAG,CAAC,KAAc,KACjC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;AAExE,MAAM,aAAa,GAAG,CAAC,KAAc,KACjC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,KAAK,OAAO,KAAK,KAAK,QAAQ,CAAC;AAE7E,MAAM,gBAAgB,GAAG,CAAC,IAA6B,KACnD,IAAI,CAAC,QAAQ,KAAK,SAAS,IAAI,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC;AAE/D,MAAM,qBAAqB,GAAG,CAAC,aAAsB,KACjD,aAAa,KAAK,SAAS;KAC1B,aAAa,CAAC,aAAa,CAAC,IAAI,MAAM,CAAC,MAAM,C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CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC;AACvD,IAAA,kBAAkB,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC;AAC1D,IAAA,OAAO,IAAI;AACf;;"}
@@ -0,0 +1,30 @@
1
+ import type { ActionMenuItem } from '../Common/ActionMenubar.js';
2
+ import type { SchemaEditorLabels } from './SchemaEditorLabels.js';
3
+ /** What the action menu needs to decide which items to offer and how they behave. */
4
+ export interface SchemaEditorMenuState {
5
+ isEditMode: boolean;
6
+ canEdit: boolean;
7
+ canNotEditReason?: string;
8
+ schemaJsonIsInvalid: boolean;
9
+ hasValidationErrors: boolean;
10
+ saveDisabled: boolean;
11
+ cancelDisabled: boolean;
12
+ labels: Required<SchemaEditorLabels>;
13
+ onEdit: () => void;
14
+ onSave: () => void;
15
+ onCancel: () => void;
16
+ onAddProperty: () => void;
17
+ }
18
+ /**
19
+ * Builds the action menu of the table layout: Edit when viewing, Save, Cancel and Add property when editing.
20
+ * @param state The editor state and handlers the items depend on.
21
+ * @returns The menu items in display order.
22
+ */
23
+ export declare const buildSchemaEditorMenu: (state: SchemaEditorMenuState) => ActionMenuItem[];
24
+ /**
25
+ * The memoized action menu of the table layout.
26
+ * @param state The editor state and handlers the items depend on.
27
+ * @returns The menu items in display order.
28
+ */
29
+ export declare const useSchemaEditorMenu: (state: SchemaEditorMenuState) => ActionMenuItem[];
30
+ //# sourceMappingURL=schemaEditorMenu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaEditorMenu.d.ts","sourceRoot":"","sources":["../../../SchemaEditor/schemaEditorMenu.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAAyB,CAAC;AAE9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAsB,CAAC;AAE/D,qFAAqF;AACrF,MAAM,WAAW,qBAAqB;IAClC,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,YAAY,EAAE,OAAO,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC;IACxB,MAAM,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAC;IACrC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,aAAa,EAAE,MAAM,IAAI,CAAC;CAC7B;AA0DD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,UAAW,qBAAqB,KAAG,cAAc,EACpB,CAAC;AAEhE;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,UAAW,qBAAqB,KAAG,cAAc,EAEZ,CAAC"}
@@ -0,0 +1,51 @@
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import { useMemo } from 'react';
3
+ import * as faIcons from 'react-icons/fa6';
4
+ import { Tooltip } from '../Common/Tooltip.js';
5
+
6
+ const inertEditStyle = {
7
+ border: 0,
8
+ background: 'transparent',
9
+ color: 'inherit',
10
+ cursor: 'not-allowed',
11
+ opacity: 0.6,
12
+ display: 'inline-flex',
13
+ alignItems: 'center',
14
+ padding: '0.5rem 0.75rem',
15
+ };
16
+ const inertEditTemplate = (reason) => (item) => (jsx(Tooltip, { content: reason, position: 'bottom', children: jsxs("button", { type: 'button', "aria-disabled": 'true', style: inertEditStyle, children: [item.icon, jsx("span", { children: item.label })] }) }));
17
+ const editItem = (state) => ({
18
+ label: state.labels.edit,
19
+ icon: jsx(faIcons.FaPencil, { className: 'cratis:mr-2' }),
20
+ command: state.canEdit && !state.schemaJsonIsInvalid ? state.onEdit : undefined,
21
+ disabled: state.schemaJsonIsInvalid,
22
+ className: state.canEdit ? undefined : 'edit-disabled-with-reason',
23
+ template: !state.canEdit && state.canNotEditReason ? inertEditTemplate(state.canNotEditReason) : undefined,
24
+ });
25
+ const saveItem = (state) => ({
26
+ label: state.labels.save,
27
+ icon: jsx(faIcons.FaCheck, { className: 'cratis:mr-2' }),
28
+ command: state.hasValidationErrors ? undefined : state.onSave,
29
+ disabled: state.hasValidationErrors,
30
+ });
31
+ const cancelItem = (state) => ({
32
+ label: state.labels.cancel,
33
+ icon: jsx(faIcons.FaXmark, { className: 'cratis:mr-2' }),
34
+ command: state.onCancel,
35
+ });
36
+ const addPropertyItem = (state) => ({
37
+ label: state.labels.addProperty,
38
+ icon: jsx(faIcons.FaPlus, { className: 'cratis:mr-2' }),
39
+ command: state.schemaJsonIsInvalid ? undefined : state.onAddProperty,
40
+ disabled: state.schemaJsonIsInvalid,
41
+ });
42
+ const editModeItems = (state) => [
43
+ ...(state.saveDisabled ? [] : [saveItem(state)]),
44
+ ...(state.cancelDisabled ? [] : [cancelItem(state)]),
45
+ addPropertyItem(state),
46
+ ];
47
+ const buildSchemaEditorMenu = (state) => state.isEditMode ? editModeItems(state) : [editItem(state)];
48
+ const useSchemaEditorMenu = (state) => useMemo(() => buildSchemaEditorMenu(state), Object.values(state));
49
+
50
+ export { buildSchemaEditorMenu, useSchemaEditorMenu };
51
+ //# sourceMappingURL=schemaEditorMenu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaEditorMenu.js","sources":["../../../SchemaEditor/schemaEditorMenu.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { useMemo } from 'react';\nimport * as faIcons from 'react-icons/fa6';\nimport type { ActionMenuItem } from '../Common/ActionMenubar';\nimport { Tooltip } from '../Common/Tooltip';\nimport type { SchemaEditorLabels } from './SchemaEditorLabels';\n\n/** What the action menu needs to decide which items to offer and how they behave. */\nexport interface SchemaEditorMenuState {\n isEditMode: boolean;\n canEdit: boolean;\n canNotEditReason?: string;\n schemaJsonIsInvalid: boolean;\n hasValidationErrors: boolean;\n saveDisabled: boolean;\n cancelDisabled: boolean;\n labels: Required<SchemaEditorLabels>;\n onEdit: () => void;\n onSave: () => void;\n onCancel: () => void;\n onAddProperty: () => void;\n}\n\nconst inertEditStyle = {\n border: 0,\n background: 'transparent',\n color: 'inherit',\n cursor: 'not-allowed',\n opacity: 0.6,\n display: 'inline-flex',\n alignItems: 'center',\n padding: '0.5rem 0.75rem',\n} as const;\n\n/** The Edit item shown when editing is unavailable, explaining why in a tooltip. */\nconst inertEditTemplate = (reason: string) => (item: ActionMenuItem) => (\n <Tooltip content={reason} position='bottom'>\n <button type='button' aria-disabled='true' style={inertEditStyle}>\n {item.icon}\n <span>{item.label}</span>\n </button>\n </Tooltip>\n);\n\nconst editItem = (state: SchemaEditorMenuState): ActionMenuItem => ({\n label: state.labels.edit,\n icon: <faIcons.FaPencil className='cratis:mr-2' />,\n command: state.canEdit && !state.schemaJsonIsInvalid ? state.onEdit : undefined,\n disabled: state.schemaJsonIsInvalid,\n className: state.canEdit ? undefined : 'edit-disabled-with-reason',\n template: !state.canEdit && state.canNotEditReason ? inertEditTemplate(state.canNotEditReason) : undefined,\n});\n\nconst saveItem = (state: SchemaEditorMenuState): ActionMenuItem => ({\n label: state.labels.save,\n icon: <faIcons.FaCheck className='cratis:mr-2' />,\n command: state.hasValidationErrors ? undefined : state.onSave,\n disabled: state.hasValidationErrors,\n});\n\nconst cancelItem = (state: SchemaEditorMenuState): ActionMenuItem => ({\n label: state.labels.cancel,\n icon: <faIcons.FaXmark className='cratis:mr-2' />,\n command: state.onCancel,\n});\n\nconst addPropertyItem = (state: SchemaEditorMenuState): ActionMenuItem => ({\n label: state.labels.addProperty,\n icon: <faIcons.FaPlus className='cratis:mr-2' />,\n command: state.schemaJsonIsInvalid ? undefined : state.onAddProperty,\n disabled: state.schemaJsonIsInvalid,\n});\n\nconst editModeItems = (state: SchemaEditorMenuState): ActionMenuItem[] => [\n ...(state.saveDisabled ? [] : [saveItem(state)]),\n ...(state.cancelDisabled ? [] : [cancelItem(state)]),\n addPropertyItem(state),\n];\n\n/**\n * Builds the action menu of the table layout: Edit when viewing, Save, Cancel and Add property when editing.\n * @param state The editor state and handlers the items depend on.\n * @returns The menu items in display order.\n */\nexport const buildSchemaEditorMenu = (state: SchemaEditorMenuState): ActionMenuItem[] =>\n state.isEditMode ? editModeItems(state) : [editItem(state)];\n\n/**\n * The memoized action menu of the table layout.\n * @param state The editor state and handlers the items depend on.\n * @returns The menu items in display order.\n */\nexport const useSchemaEditorMenu = (state: SchemaEditorMenuState): ActionMenuItem[] =>\n // The state object is rebuilt every render, so its fields are the memo dependencies.\n useMemo(() => buildSchemaEditorMenu(state), Object.values(state));\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;AAyBA,MAAM,cAAc,GAAG;AACnB,IAAA,MAAM,EAAE,CAAC;AACT,IAAA,UAAU,EAAE,aAAa;AACzB,IAAA,KAAK,EAAE,SAAS;AAChB,IAAA,MAAM,EAAE,aAAa;AACrB,IAAA,OAAO,EAAE,GAAG;AACZ,IAAA,OAAO,EAAE,aAAa;AACtB,IAAA,UAAU,EAAE,QAAQ;AACpB,IAAA,OAAO,EAAE,gBAAgB;CACnB;AAGV,MAAM,iBAAiB,GAAG,CAAC,MAAc,KAAK,CAAC,IAAoB,MAC/DA,IAAC,OAAO,EAAA,EAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAC,QAAQ,YACvCC,IAAA,CAAA,QAAA,EAAA,EAAQ,IAAI,EAAC,QAAQ,EAAA,eAAA,EAAe,MAAM,EAAC,KAAK,EAAE,cAAc,EAAA,QAAA,EAAA,CAC3D,IAAI,CAAC,IAAI,EACVD,wBAAO,IAAI,CAAC,KAAK,EAAA,CAAQ,CAAA,EAAA,CACpB,EAAA,CACH,CACb;AAED,MAAM,QAAQ,GAAG,CAAC,KAA4B,MAAsB;AAChE,IAAA,KAAK,EAAE,KAAK,CAAC,MAA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,EAAE,KAAK,CAAC,mBAAmB,GAAG,SAAS,GAAG,KAAK,CAAC,aAAa;IACpE,QAAQ,EAAE,KAAK,CAAC,mBAAmB;AACtC,CAAA,CAAC;AAEF,MAAM,aAAa,GAAG,CAAC,KAA4B,KAAuB;AACtE,IAAA,IAAI,KAAK,CAAC,YAAY,GAAG,EAAE,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AAChD,IAAA,IAAI,KAAK,CAAC,cAAc,GAAG,EAAE,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IACpD,eAAe,CAAC,KAAK,CAAC;CACzB;AAOM,MAAM,qBAAqB,GAAG,CAAC,KAA4B,KAC9D,KAAK,CAAC,UAAU,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC;AAOvD,MAAM,mBAAmB,GAAG,CAAC,KAA4B,KAE5D,OAAO,CAAC,MAAM,qBAAqB,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;;"}
@@ -0,0 +1,33 @@
1
+ import type { JsonSchema, JsonSchemaProperty } from '../types/JsonSchema.js';
2
+ import type { Property } from './Tree/Property.js';
3
+ /** Adds a new string property with the first free `newProperty` name. */
4
+ export declare const addPropertyTo: (schema: JsonSchema) => JsonSchema;
5
+ /** Removes a property and drops it from the schema's own `required` array. */
6
+ export declare const removePropertyFrom: (schema: JsonSchema, propertyName: string) => JsonSchema;
7
+ /** Marks a property required or optional, removing the `required` array when it ends up empty. */
8
+ export declare const setRequiredIn: (schema: JsonSchema, propertyName: string, isRequired: boolean) => JsonSchema;
9
+ /** Makes the named property the key, clearing the key marker from every other property. */
10
+ export declare const setKeyIn: (schema: JsonSchema, propertyName: string) => JsonSchema;
11
+ /** Sets the item type of an array property, giving object and array items their own shape. */
12
+ export declare const setArrayItemType: (schema: JsonSchema, propertyName: string, itemType: string) => JsonSchema;
13
+ /** One edit of a property's name, type or format. */
14
+ export interface PropertyEdit {
15
+ field: keyof JsonSchemaProperty;
16
+ value: unknown;
17
+ additionalUpdates?: Partial<JsonSchemaProperty>;
18
+ }
19
+ /** The outcome of an edit: the new schema and, for a rename, the renamed property. */
20
+ export interface PropertyEditResult {
21
+ schema: JsonSchema;
22
+ renamed?: Property;
23
+ }
24
+ /**
25
+ * Applies a name, type or format edit to one property of a schema.
26
+ * @param schema The schema holding the property.
27
+ * @param oldName The property's current name.
28
+ * @param edit The edit to apply.
29
+ * @param isLocked Whether the property is protected from renaming.
30
+ * @returns The updated schema and, for a rename, the renamed property.
31
+ */
32
+ export declare const editProperty: (schema: JsonSchema, oldName: string, edit: PropertyEdit, isLocked: boolean) => PropertyEditResult;
33
+ //# sourceMappingURL=schemaPropertyEdits.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaPropertyEdits.d.ts","sourceRoot":"","sources":["../../../SchemaEditor/schemaPropertyEdits.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,wBAAqB,CAAC;AAE1E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAiB,CAAC;AAKhD,yEAAyE;AACzE,eAAO,MAAM,aAAa,WAAY,UAAU,KAAG,UASlD,CAAC;AAEF,8EAA8E;AAC9E,eAAO,MAAM,kBAAkB,WAAY,UAAU,gBAAgB,MAAM,KAAG,UAY7E,CAAC;AAEF,kGAAkG;AAClG,eAAO,MAAM,aAAa,WAAY,UAAU,gBAAgB,MAAM,cAAc,OAAO,KAAG,UAU7F,CAAC;AAEF,2FAA2F;AAC3F,eAAO,MAAM,QAAQ,WAAY,UAAU,gBAAgB,MAAM,KAAG,UAQnE,CAAC;AAEF,8FAA8F;AAC9F,eAAO,MAAM,gBAAgB,WAAY,UAAU,gBAAgB,MAAM,YAAY,MAAM,KAAG,UAc7F,CAAC;AAEF,qDAAqD;AACrD,MAAM,WAAW,YAAY;IACzB,KAAK,EAAE,MAAM,kBAAkB,CAAC;IAChC,KAAK,EAAE,OAAO,CAAC;IACf,iBAAiB,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;CACnD;AAED,sFAAsF;AACtF,MAAM,WAAW,kBAAkB;IAC/B,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,CAAC,EAAE,QAAQ,CAAC;CACtB;AAqED;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,WACb,UAAU,WACT,MAAM,QACT,YAAY,YACR,OAAO,KAClB,kBAaF,CAAC"}
@@ -0,0 +1,134 @@
1
+ import { dropInapplicableKeywords } from './schemaHelpers.js';
2
+ import { KEY_KEYWORD, jsonSchemaToProperties } from './Tree/schemaConversion.js';
3
+
4
+ const addPropertyTo = (schema) => {
5
+ const properties = { ...(schema.properties || {}) };
6
+ let name = 'newProperty';
7
+ let counter = 1;
8
+ while (properties[name]) {
9
+ name = `newProperty${counter++}`;
10
+ }
11
+ properties[name] = { type: 'string' };
12
+ return { ...schema, properties };
13
+ };
14
+ const removePropertyFrom = (schema, propertyName) => {
15
+ const properties = { ...(schema.properties || {}) };
16
+ delete properties[propertyName];
17
+ const updated = { ...schema, properties };
18
+ if (schema.required?.includes(propertyName)) {
19
+ updated.required = schema.required.filter((name) => name !== propertyName);
20
+ }
21
+ return updated;
22
+ };
23
+ const setRequiredIn = (schema, propertyName, isRequired) => {
24
+ const others = (schema.required ?? []).filter((name) => name !== propertyName);
25
+ const required = isRequired ? [...others, propertyName] : others;
26
+ const updated = { ...schema };
27
+ if (required.length > 0) {
28
+ updated.required = required;
29
+ }
30
+ else {
31
+ delete updated.required;
32
+ }
33
+ return updated;
34
+ };
35
+ const setKeyIn = (schema, propertyName) => {
36
+ const properties = {};
37
+ for (const [name, property] of Object.entries(schema.properties || {})) {
38
+ const { [KEY_KEYWORD]: previousKey, ...rest } = property;
39
+ const makeKey = name === propertyName && previousKey !== true;
40
+ properties[name] = (makeKey ? { ...rest, [KEY_KEYWORD]: true } : rest);
41
+ }
42
+ return { ...schema, properties };
43
+ };
44
+ const setArrayItemType = (schema, propertyName, itemType) => {
45
+ const properties = { ...(schema.properties || {}) };
46
+ const property = { ...(properties[propertyName] || {}) };
47
+ if (itemType === 'object') {
48
+ property.items = { type: 'object', properties: {} };
49
+ }
50
+ else if (itemType === 'array') {
51
+ property.items = { type: 'array', items: { type: 'string' } };
52
+ }
53
+ else {
54
+ property.items = { type: itemType };
55
+ }
56
+ properties[propertyName] = property;
57
+ return { ...schema, properties };
58
+ };
59
+ const reshapeForType = (property, type) => {
60
+ if (type === 'array') {
61
+ property.items = { type: 'string' };
62
+ delete property.format;
63
+ }
64
+ else if (type === 'object') {
65
+ property.properties = {};
66
+ delete property.format;
67
+ delete property.items;
68
+ }
69
+ else {
70
+ delete property.items;
71
+ delete property.properties;
72
+ }
73
+ delete property.required;
74
+ };
75
+ const applyFormatUpdate = (property, updates) => {
76
+ if (!updates || !('format' in updates))
77
+ return;
78
+ if (updates.format) {
79
+ property.format = updates.format;
80
+ }
81
+ else {
82
+ delete property.format;
83
+ }
84
+ };
85
+ const changeType = (property, type, updates) => {
86
+ const previousNode = { ...property };
87
+ property.type = type;
88
+ delete property['x-concept'];
89
+ reshapeForType(property, type);
90
+ applyFormatUpdate(property, updates);
91
+ dropInapplicableKeywords(property, previousNode);
92
+ };
93
+ const changeFormat = (property, format) => {
94
+ if (format && format !== 'none') {
95
+ property.format = format;
96
+ }
97
+ else {
98
+ delete property.format;
99
+ }
100
+ };
101
+ const renameRequired = (required, oldName, newName) => required?.includes(oldName) ? required.map((name) => (name === oldName ? newName : name)) : required;
102
+ const canRename = (properties, oldName, newName, isLocked) => !isLocked && newName !== oldName && !properties[newName];
103
+ const renameProperty = (schema, oldName, newName) => {
104
+ const property = schema.properties?.[oldName] || {};
105
+ const properties = { ...schema.properties, [newName]: property };
106
+ delete properties[oldName];
107
+ return {
108
+ schema: { ...schema, properties, required: renameRequired(schema.required, oldName, newName) },
109
+ renamed: jsonSchemaToProperties({ properties: { [newName]: property } })[0],
110
+ };
111
+ };
112
+ const reshapeProperty = (property, { field, value, additionalUpdates }) => {
113
+ if (field === 'type')
114
+ changeType(property, value, additionalUpdates);
115
+ if (field === 'format')
116
+ changeFormat(property, value);
117
+ };
118
+ const editProperty = (schema, oldName, edit, isLocked) => {
119
+ const properties = { ...(schema.properties || {}) };
120
+ if (edit.field === 'name') {
121
+ const newName = edit.value;
122
+ return canRename(properties, oldName, newName, isLocked)
123
+ ? renameProperty(schema, oldName, newName)
124
+ : { schema: { ...schema, properties } };
125
+ }
126
+ const property = { ...(properties[oldName] || {}) };
127
+ reshapeProperty(property, edit);
128
+ if (edit.field === 'type' || edit.field === 'format')
129
+ properties[oldName] = property;
130
+ return { schema: { ...schema, properties } };
131
+ };
132
+
133
+ export { addPropertyTo, editProperty, removePropertyFrom, setArrayItemType, setKeyIn, setRequiredIn };
134
+ //# sourceMappingURL=schemaPropertyEdits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaPropertyEdits.js","sources":["../../../SchemaEditor/schemaPropertyEdits.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport type { JsonSchema, JsonSchemaProperty } from '../types/JsonSchema';\nimport { dropInapplicableKeywords } from './schemaHelpers';\nimport type { Property } from './Tree/Property';\nimport { jsonSchemaToProperties, KEY_KEYWORD } from './Tree/schemaConversion';\n\ntype PropertyNode = JsonSchemaProperty & Record<string, unknown>;\n\n/** Adds a new string property with the first free `newProperty` name. */\nexport const addPropertyTo = (schema: JsonSchema): JsonSchema => {\n const properties = { ...(schema.properties || {}) };\n let name = 'newProperty';\n let counter = 1;\n while (properties[name]) {\n name = `newProperty${counter++}`;\n }\n properties[name] = { type: 'string' };\n return { ...schema, properties };\n};\n\n/** Removes a property and drops it from the schema's own `required` array. */\nexport const removePropertyFrom = (schema: JsonSchema, propertyName: string): JsonSchema => {\n const properties = { ...(schema.properties || {}) };\n delete properties[propertyName];\n\n // Deleting a property must also drop it from this schema's own\n // `required` array, or the array keeps naming a property that no\n // longer exists in `properties`.\n const updated: JsonSchema = { ...schema, properties };\n if (schema.required?.includes(propertyName)) {\n updated.required = schema.required.filter((name) => name !== propertyName);\n }\n return updated;\n};\n\n/** Marks a property required or optional, removing the `required` array when it ends up empty. */\nexport const setRequiredIn = (schema: JsonSchema, propertyName: string, isRequired: boolean): JsonSchema => {\n const others = (schema.required ?? []).filter((name) => name !== propertyName);\n const required = isRequired ? [...others, propertyName] : others;\n const updated: JsonSchema = { ...schema };\n if (required.length > 0) {\n updated.required = required;\n } else {\n delete updated.required;\n }\n return updated;\n};\n\n/** Makes the named property the key, clearing the key marker from every other property. */\nexport const setKeyIn = (schema: JsonSchema, propertyName: string): JsonSchema => {\n const properties: Record<string, JsonSchemaProperty> = {};\n for (const [name, property] of Object.entries(schema.properties || {})) {\n const { [KEY_KEYWORD]: previousKey, ...rest } = property as PropertyNode;\n const makeKey = name === propertyName && previousKey !== true;\n properties[name] = (makeKey ? { ...rest, [KEY_KEYWORD]: true } : rest) as JsonSchemaProperty;\n }\n return { ...schema, properties };\n};\n\n/** Sets the item type of an array property, giving object and array items their own shape. */\nexport const setArrayItemType = (schema: JsonSchema, propertyName: string, itemType: string): JsonSchema => {\n const properties = { ...(schema.properties || {}) };\n const property = { ...(properties[propertyName] || {}) };\n\n if (itemType === 'object') {\n property.items = { type: 'object', properties: {} };\n } else if (itemType === 'array') {\n property.items = { type: 'array', items: { type: 'string' } };\n } else {\n property.items = { type: itemType };\n }\n\n properties[propertyName] = property;\n return { ...schema, properties };\n};\n\n/** One edit of a property's name, type or format. */\nexport interface PropertyEdit {\n field: keyof JsonSchemaProperty;\n value: unknown;\n additionalUpdates?: Partial<JsonSchemaProperty>;\n}\n\n/** The outcome of an edit: the new schema and, for a rename, the renamed property. */\nexport interface PropertyEditResult {\n schema: JsonSchema;\n renamed?: Property;\n}\n\n// Only an \"object\" property has a meaningful `required` array of its own; a fresh `properties`\n// or an array's items make any prior one stale.\nconst reshapeForType = (property: JsonSchemaProperty, type: unknown) => {\n if (type === 'array') {\n property.items = { type: 'string' };\n delete property.format;\n } else if (type === 'object') {\n property.properties = {};\n delete property.format;\n delete property.items;\n } else {\n delete property.items;\n delete property.properties;\n }\n delete property.required;\n};\n\nconst applyFormatUpdate = (property: JsonSchemaProperty, updates: Partial<JsonSchemaProperty> | undefined) => {\n if (!updates || !('format' in updates)) return;\n if (updates.format) {\n property.format = updates.format;\n } else {\n delete property.format;\n }\n};\n\nconst changeType = (property: JsonSchemaProperty, type: unknown, updates: Partial<JsonSchemaProperty> | undefined) => {\n const previousNode = { ...property } as Record<string, unknown>;\n property.type = type as string;\n // A concept belongs to the type it was chosen for; the table offers no concepts.\n delete (property as Record<string, unknown>)['x-concept'];\n reshapeForType(property, type);\n applyFormatUpdate(property, updates);\n dropInapplicableKeywords(property as Record<string, unknown>, previousNode);\n};\n\nconst changeFormat = (property: JsonSchemaProperty, format: unknown) => {\n if (format && format !== 'none') {\n property.format = format as string;\n } else {\n delete property.format;\n }\n};\n\n// Renaming a required property must keep the `required` array pointing at the new name, or it goes\n// stale and silently references a property that no longer exists.\nconst renameRequired = (required: string[] | undefined, oldName: string, newName: string) =>\n required?.includes(oldName) ? required.map((name) => (name === oldName ? newName : name)) : required;\n\nconst canRename = (properties: Record<string, JsonSchemaProperty>, oldName: string, newName: string, isLocked: boolean) =>\n !isLocked && newName !== oldName && !properties[newName];\n\nconst renameProperty = (schema: JsonSchema, oldName: string, newName: string): PropertyEditResult => {\n const property = schema.properties?.[oldName] || {};\n const properties = { ...schema.properties, [newName]: property };\n delete properties[oldName];\n return {\n schema: { ...schema, properties, required: renameRequired(schema.required, oldName, newName) },\n renamed: jsonSchemaToProperties({ properties: { [newName]: property } })[0],\n };\n};\n\nconst reshapeProperty = (property: JsonSchemaProperty, { field, value, additionalUpdates }: PropertyEdit) => {\n if (field === 'type') changeType(property, value, additionalUpdates);\n if (field === 'format') changeFormat(property, value);\n};\n\n/**\n * Applies a name, type or format edit to one property of a schema.\n * @param schema The schema holding the property.\n * @param oldName The property's current name.\n * @param edit The edit to apply.\n * @param isLocked Whether the property is protected from renaming.\n * @returns The updated schema and, for a rename, the renamed property.\n */\nexport const editProperty = (\n schema: JsonSchema,\n oldName: string,\n edit: PropertyEdit,\n isLocked: boolean,\n): PropertyEditResult => {\n const properties = { ...(schema.properties || {}) };\n if (edit.field === 'name') {\n const newName = edit.value as string;\n return canRename(properties, oldName, newName, isLocked)\n ? renameProperty(schema, oldName, newName)\n : { schema: { ...schema, properties } };\n }\n\n const property = { ...(properties[oldName] || {}) };\n reshapeProperty(property, edit);\n if (edit.field === 'type' || edit.field === 'format') properties[oldName] = property;\n return { schema: { ...schema, properties } };\n};\n"],"names":[],"mappings":";;;AAWO,MAAM,aAAa,GAAG,CAAC,MAAkB,KAAgB;AAC5D,IAAA,MAAM,UAAU,GAAG,EAAE,IAAI,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE;IACnD,IAAI,IAAI,GAAG,aAAa;IACxB,IAAI,OAAO,GAAG,CAAC;AACf,IAAA,OAAO,UAAU,CAAC,IAAI,CAAC,EAAE;AACrB,QAAA,IAAI,GAAG,CAAA,WAAA,EAAc,OAAO,EAAE,EAAE;IACpC;IACA,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE;AACrC,IAAA,OAAO,EAAE,GAAG,MAAM,EAAE,UAAU,EAAE;AACpC;MAGa,kBAAkB,GAAG,CAAC,MAAkB,EAAE,YAAoB,KAAgB;AACvF,IAAA,MAAM,UAAU,GAAG,EAAE,IAAI,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE;AACnD,IAAA,OAAO,UAAU,CAAC,YAAY,CAAC;IAK/B,MAAM,OAAO,GAAe,EAAE,GAAG,MAAM,EAAE,UAAU,EAAE;IACrD,IAAI,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE;AACzC,QA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;cACvC,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,UAAU,EAAE,EAAE;IAC/C;AAEA,IAAA,MAAM,QAAQ,GAAG,EAAE,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE;AACnD,IAAA,eAAe,CAAC,QAAQ,EAAE,IAAI,CAAC;IAC/B,IAAI,IAAI,CAAC,KAAK,KAAK,MAAM,IAAI,IAAI,CAAC,KAAK,KAAK,QAAQ;AAAE,QAAA,UAAU,CAAC,OAAO,CAAC,GAAG,QAAQ;IACpF,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,UAAU,EAAE,EAAE;AAChD;;"}
@@ -0,0 +1,11 @@
1
+ import type { TypeFormat } from '../types/TypeFormat.js';
2
+ export interface TypeOption {
3
+ label: string;
4
+ value: string;
5
+ }
6
+ export declare const CONTAINER_TYPES: TypeOption[];
7
+ /** The value a type format is chosen by: its format, or its JSON type when it has no format. */
8
+ export declare const effectiveFormat: (typeFormat: TypeFormat) => string;
9
+ /** Every type a property can be changed to: the known type formats (or the defaults) plus array and object. */
10
+ export declare const buildTypeOptions: (typeFormats: TypeFormat[]) => TypeOption[];
11
+ //# sourceMappingURL=typeOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeOptions.d.ts","sourceRoot":"","sources":["../../../SchemaEditor/typeOptions.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAqB,CAAC;AAEtD,MAAM,WAAW,UAAU;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,eAAe,EAAE,UAAU,EAGvC,CAAC;AASF,gGAAgG;AAChG,eAAO,MAAM,eAAe,eAAgB,UAAU,KAAG,MACM,CAAC;AAEhE,+GAA+G;AAC/G,eAAO,MAAM,gBAAgB,gBAAiB,UAAU,EAAE,KAAG,UAAU,EAKtE,CAAC"}
@@ -0,0 +1,20 @@
1
+ const CONTAINER_TYPES = [
2
+ { label: 'array', value: 'array' },
3
+ { label: 'object', value: 'object' },
4
+ ];
5
+ const DEFAULT_TYPE_OPTIONS = [
6
+ { label: 'string', value: 'string' },
7
+ { label: 'integer', value: 'integer' },
8
+ { label: 'number', value: 'number' },
9
+ { label: 'boolean', value: 'boolean' },
10
+ ];
11
+ const effectiveFormat = (typeFormat) => typeFormat.format ? typeFormat.format : typeFormat.jsonType;
12
+ const buildTypeOptions = (typeFormats) => {
13
+ const formatOptions = typeFormats.length > 0
14
+ ? typeFormats.map(typeFormat => ({ label: effectiveFormat(typeFormat), value: effectiveFormat(typeFormat) }))
15
+ : DEFAULT_TYPE_OPTIONS;
16
+ return [...formatOptions, ...CONTAINER_TYPES];
17
+ };
18
+
19
+ export { CONTAINER_TYPES, buildTypeOptions, effectiveFormat };
20
+ //# sourceMappingURL=typeOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeOptions.js","sources":["../../../SchemaEditor/typeOptions.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport type { TypeFormat } from '../types/TypeFormat';\n\nexport interface TypeOption {\n label: string;\n value: string;\n}\n\nexport const CONTAINER_TYPES: TypeOption[] = [\n { label: 'array', value: 'array' },\n { label: 'object', value: 'object' },\n];\n\nconst DEFAULT_TYPE_OPTIONS: TypeOption[] = [\n { label: 'string', value: 'string' },\n { label: 'integer', value: 'integer' },\n { label: 'number', value: 'number' },\n { label: 'boolean', value: 'boolean' },\n];\n\n/** The value a type format is chosen by: its format, or its JSON type when it has no format. */\nexport const effectiveFormat = (typeFormat: TypeFormat): string =>\n typeFormat.format ? typeFormat.format : typeFormat.jsonType;\n\n/** Every type a property can be changed to: the known type formats (or the defaults) plus array and object. */\nexport const buildTypeOptions = (typeFormats: TypeFormat[]): TypeOption[] => {\n const formatOptions = typeFormats.length > 0\n ? typeFormats.map(typeFormat => ({ label: effectiveFormat(typeFormat), value: effectiveFormat(typeFormat) }))\n : DEFAULT_TYPE_OPTIONS;\n return [...formatOptions, ...CONTAINER_TYPES];\n};\n"],"names":[],"mappings":"AAUO,MAAM,eAAe,GAAiB;AACzC,IAAA,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE;AAClC,IAAA,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE;;AAGxC,MAAM,oBAAoB,GAAiB;AACvC,IAAA,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE;AACpC,IAAA,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE;AACtC,IAAA,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE;AACpC,IAAA,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE;CACzC;AAGM,MAAM,eAAe,GAAG,CAAC,UAAsB,KAClD,UAAU,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,GAAG,UAAU,CAAC;AAGhD,MAAM,gBAAgB,GAAG,CAAC,WAAyB,KAAkB;AACxE,IAAA,MAAM,aAAa,GAAG,WAAW,CAAC,MAAM,GAAG;UACrC,WAAW,CAAC,GAAG,CAAC,UAAU,KAAK,EAAE,KAAK,EAAE,eAAe,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC;UAC1G,oBAAoB;AAC1B,IAAA,OAAO,CAAC,GAAG,aAAa,EAAE,GAAG,eAAe,CAAC;AACjD;;"}
@@ -0,0 +1,26 @@
1
+ import type { ChangeHandler } from '../types/ChangeHandler.js';
2
+ import type { JsonSchema } from '../types/JsonSchema.js';
3
+ /** What the document hook reports back to the host. */
4
+ export interface SchemaDocumentOptions {
5
+ schema: JsonSchema;
6
+ editMode?: boolean;
7
+ onChange?: ChangeHandler<JsonSchema>;
8
+ onSave?: () => void;
9
+ onCancel?: () => void;
10
+ }
11
+ /**
12
+ * Holds the schema being edited and the Edit, Save and Cancel workflow around it.
13
+ * @param options The supplied schema, the initial edit mode and the host callbacks.
14
+ * @returns The working schema, whether it is invalid, the edit mode and the workflow actions.
15
+ */
16
+ export declare const useSchemaDocument: ({ schema, editMode, onChange, onSave, onCancel }: SchemaDocumentOptions) => {
17
+ currentSchema: JsonSchema;
18
+ setCurrentSchema: import("react").Dispatch<import("react").SetStateAction<JsonSchema>>;
19
+ schemaJsonIsInvalid: boolean;
20
+ setSchemaJsonIsInvalid: import("react").Dispatch<import("react").SetStateAction<boolean>>;
21
+ isEditMode: boolean;
22
+ handleEdit: () => void;
23
+ handleSave: () => void;
24
+ handleCancel: () => void;
25
+ };
26
+ //# sourceMappingURL=useSchemaDocument.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSchemaDocument.d.ts","sourceRoot":"","sources":["../../../SchemaEditor/useSchemaDocument.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAqB,CAAC;AAGtD,uDAAuD;AACvD,MAAM,WAAW,qBAAqB;IAClC,MAAM,EAAE,UAAU,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IACrC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACzB;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,qDAAsD,qBAAqB;;;;;;;;;CAkExG,CAAC"}