@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.
- package/compat-manifest.json +11 -11
- package/dist/esm/Canvas/Canvas.d.ts.map +1 -1
- package/dist/esm/Canvas/Canvas.js +16 -109
- package/dist/esm/Canvas/Canvas.js.map +1 -1
- package/dist/esm/Canvas/CanvasWorldLayers.d.ts +22 -0
- package/dist/esm/Canvas/CanvasWorldLayers.d.ts.map +1 -0
- package/dist/esm/Canvas/CanvasWorldLayers.js +27 -0
- package/dist/esm/Canvas/CanvasWorldLayers.js.map +1 -0
- package/dist/esm/Canvas/useCanvasSurface.d.ts +57 -0
- package/dist/esm/Canvas/useCanvasSurface.d.ts.map +1 -0
- package/dist/esm/Canvas/useCanvasSurface.js +112 -0
- package/dist/esm/Canvas/useCanvasSurface.js.map +1 -0
- package/dist/esm/Chat/ChatSidebar.d.ts +2 -2
- package/dist/esm/Chat/ChatSidebar.d.ts.map +1 -1
- package/dist/esm/Chat/ChatSidebar.js +21 -101
- package/dist/esm/Chat/ChatSidebar.js.map +1 -1
- package/dist/esm/Chat/ChatSidebarContent.d.ts +25 -0
- package/dist/esm/Chat/ChatSidebarContent.d.ts.map +1 -0
- package/dist/esm/Chat/ChatSidebarContent.js +12 -0
- package/dist/esm/Chat/ChatSidebarContent.js.map +1 -0
- package/dist/esm/Chat/ChatSidebarHeader.d.ts +16 -0
- package/dist/esm/Chat/ChatSidebarHeader.d.ts.map +1 -0
- package/dist/esm/Chat/ChatSidebarHeader.js +26 -0
- package/dist/esm/Chat/ChatSidebarHeader.js.map +1 -0
- package/dist/esm/Chat/ChatSidebarShells.d.ts +31 -0
- package/dist/esm/Chat/ChatSidebarShells.d.ts.map +1 -0
- package/dist/esm/Chat/ChatSidebarShells.js +43 -0
- package/dist/esm/Chat/ChatSidebarShells.js.map +1 -0
- package/dist/esm/Chat/useNonModalPhase.d.ts +16 -0
- package/dist/esm/Chat/useNonModalPhase.d.ts.map +1 -0
- package/dist/esm/Chat/useNonModalPhase.js +38 -0
- package/dist/esm/Chat/useNonModalPhase.js.map +1 -0
- package/dist/esm/Chat/useTopicSelection.d.ts +31 -0
- package/dist/esm/Chat/useTopicSelection.d.ts.map +1 -0
- package/dist/esm/Chat/useTopicSelection.js +45 -0
- package/dist/esm/Chat/useTopicSelection.js.map +1 -0
- package/dist/esm/CommandDialog/CommandStepperContent.d.ts.map +1 -1
- package/dist/esm/CommandDialog/CommandStepperContent.js +31 -119
- package/dist/esm/CommandDialog/CommandStepperContent.js.map +1 -1
- package/dist/esm/CommandDialog/CommandStepperList.d.ts +19 -0
- package/dist/esm/CommandDialog/CommandStepperList.d.ts.map +1 -0
- package/dist/esm/CommandDialog/CommandStepperList.js +20 -0
- package/dist/esm/CommandDialog/CommandStepperList.js.map +1 -0
- package/dist/esm/CommandDialog/CommandStepperNavigation.d.ts +20 -0
- package/dist/esm/CommandDialog/CommandStepperNavigation.d.ts.map +1 -0
- package/dist/esm/CommandDialog/CommandStepperNavigation.js +15 -0
- package/dist/esm/CommandDialog/CommandStepperNavigation.js.map +1 -0
- package/dist/esm/CommandDialog/CommandStepperPanels.d.ts +20 -0
- package/dist/esm/CommandDialog/CommandStepperPanels.d.ts.map +1 -0
- package/dist/esm/CommandDialog/CommandStepperPanels.js +9 -0
- package/dist/esm/CommandDialog/CommandStepperPanels.js.map +1 -0
- package/dist/esm/CommandDialog/CommandStepperStepParts.d.ts +23 -0
- package/dist/esm/CommandDialog/CommandStepperStepParts.d.ts.map +1 -0
- package/dist/esm/CommandDialog/CommandStepperStepParts.js +9 -0
- package/dist/esm/CommandDialog/CommandStepperStepParts.js.map +1 -0
- package/dist/esm/CommandDialog/commandStepperFields.d.ts +6 -0
- package/dist/esm/CommandDialog/commandStepperFields.d.ts.map +1 -0
- package/dist/esm/CommandDialog/commandStepperFields.js +54 -0
- package/dist/esm/CommandDialog/commandStepperFields.js.map +1 -0
- package/dist/esm/CommandDialog/joinClassNames.d.ts +3 -0
- package/dist/esm/CommandDialog/joinClassNames.d.ts.map +1 -0
- package/dist/esm/CommandDialog/joinClassNames.js +4 -0
- package/dist/esm/CommandDialog/joinClassNames.js.map +1 -0
- package/dist/esm/CommandDialog/resolveStepperLabels.d.ts +20 -0
- package/dist/esm/CommandDialog/resolveStepperLabels.d.ts.map +1 -0
- package/dist/esm/CommandDialog/resolveStepperLabels.js +8 -0
- package/dist/esm/CommandDialog/resolveStepperLabels.js.map +1 -0
- package/dist/esm/CommandDialog/useStepValidation.d.ts +7 -0
- package/dist/esm/CommandDialog/useStepValidation.d.ts.map +1 -0
- package/dist/esm/CommandDialog/useStepValidation.js +14 -0
- package/dist/esm/CommandDialog/useStepValidation.js.map +1 -0
- package/dist/esm/CommandDialog/useStepperState.d.ts +30 -0
- package/dist/esm/CommandDialog/useStepperState.d.ts.map +1 -0
- package/dist/esm/CommandDialog/useStepperState.js +37 -0
- package/dist/esm/CommandDialog/useStepperState.js.map +1 -0
- package/dist/esm/CommandForm/fields/ChipsField.d.ts +1 -1
- package/dist/esm/CommandForm/fields/ChipsField.d.ts.map +1 -1
- package/dist/esm/CommandForm/fields/ChipsField.js +7 -39
- package/dist/esm/CommandForm/fields/ChipsField.js.map +1 -1
- package/dist/esm/CommandForm/fields/ChipsInput.d.ts +18 -0
- package/dist/esm/CommandForm/fields/ChipsInput.d.ts.map +1 -0
- package/dist/esm/CommandForm/fields/ChipsInput.js +12 -0
- package/dist/esm/CommandForm/fields/ChipsInput.js.map +1 -0
- package/dist/esm/CommandForm/fields/ChipsItem.d.ts +14 -0
- package/dist/esm/CommandForm/fields/ChipsItem.d.ts.map +1 -0
- package/dist/esm/CommandForm/fields/ChipsItem.js +14 -0
- package/dist/esm/CommandForm/fields/ChipsItem.js.map +1 -0
- package/dist/esm/CommandForm/fields/useChipsDraft.d.ts +19 -0
- package/dist/esm/CommandForm/fields/useChipsDraft.d.ts.map +1 -0
- package/dist/esm/CommandForm/fields/useChipsDraft.js +19 -0
- package/dist/esm/CommandForm/fields/useChipsDraft.js.map +1 -0
- package/dist/esm/Common/CratisComponentsProvider.d.ts.map +1 -1
- package/dist/esm/Common/CratisComponentsProvider.js +1 -44
- package/dist/esm/Common/CratisComponentsProvider.js.map +1 -1
- package/dist/esm/Common/legacyLocaleMessages.d.ts +7 -0
- package/dist/esm/Common/legacyLocaleMessages.d.ts.map +1 -0
- package/dist/esm/Common/legacyLocaleMessages.js +43 -0
- package/dist/esm/Common/legacyLocaleMessages.js.map +1 -0
- package/dist/esm/DataTables/ColumnFilterActions.d.ts +11 -0
- package/dist/esm/DataTables/ColumnFilterActions.d.ts.map +1 -0
- package/dist/esm/DataTables/ColumnFilterActions.js +8 -0
- package/dist/esm/DataTables/ColumnFilterActions.js.map +1 -0
- package/dist/esm/DataTables/ColumnFilterMenu.d.ts +1 -1
- package/dist/esm/DataTables/ColumnFilterMenu.d.ts.map +1 -1
- package/dist/esm/DataTables/ColumnFilterMenu.js +16 -148
- package/dist/esm/DataTables/ColumnFilterMenu.js.map +1 -1
- package/dist/esm/DataTables/ColumnFilterTrigger.d.ts +12 -0
- package/dist/esm/DataTables/ColumnFilterTrigger.d.ts.map +1 -0
- package/dist/esm/DataTables/ColumnFilterTrigger.js +9 -0
- package/dist/esm/DataTables/ColumnFilterTrigger.js.map +1 -0
- package/dist/esm/DataTables/ColumnFilterValueInput.d.ts +24 -0
- package/dist/esm/DataTables/ColumnFilterValueInput.d.ts.map +1 -0
- package/dist/esm/DataTables/ColumnFilterValueInput.js +39 -0
- package/dist/esm/DataTables/ColumnFilterValueInput.js.map +1 -0
- package/dist/esm/DataTables/DataTableCore.d.ts +1 -1
- package/dist/esm/DataTables/DataTableCore.d.ts.map +1 -1
- package/dist/esm/DataTables/DataTableCore.js +12 -66
- package/dist/esm/DataTables/DataTableCore.js.map +1 -1
- package/dist/esm/DataTables/DataTableHead.d.ts +23 -0
- package/dist/esm/DataTables/DataTableHead.d.ts.map +1 -0
- package/dist/esm/DataTables/DataTableHead.js +12 -0
- package/dist/esm/DataTables/DataTableHead.js.map +1 -0
- package/dist/esm/DataTables/DataTableRows.d.ts +19 -0
- package/dist/esm/DataTables/DataTableRows.d.ts.map +1 -0
- package/dist/esm/DataTables/DataTableRows.js +7 -0
- package/dist/esm/DataTables/DataTableRows.js.map +1 -0
- package/dist/esm/DataTables/DataTableTable.d.ts +20 -0
- package/dist/esm/DataTables/DataTableTable.d.ts.map +1 -0
- package/dist/esm/DataTables/DataTableTable.js +10 -0
- package/dist/esm/DataTables/DataTableTable.js.map +1 -0
- package/dist/esm/DataTables/columnFilterMatchModes.d.ts +10 -0
- package/dist/esm/DataTables/columnFilterMatchModes.d.ts.map +1 -0
- package/dist/esm/DataTables/columnFilterMatchModes.js +52 -0
- package/dist/esm/DataTables/columnFilterMatchModes.js.map +1 -0
- package/dist/esm/DataTables/resolveColumnFilterLabels.d.ts +4 -0
- package/dist/esm/DataTables/resolveColumnFilterLabels.d.ts.map +1 -0
- package/dist/esm/DataTables/resolveColumnFilterLabels.js +20 -0
- package/dist/esm/DataTables/resolveColumnFilterLabels.js.map +1 -0
- package/dist/esm/DataTables/useColumnFilterDraft.d.ts +13 -0
- package/dist/esm/DataTables/useColumnFilterDraft.d.ts.map +1 -0
- package/dist/esm/DataTables/useColumnFilterDraft.js +24 -0
- package/dist/esm/DataTables/useColumnFilterDraft.js.map +1 -0
- package/dist/esm/DataTables/useDataTableRows.d.ts +40 -0
- package/dist/esm/DataTables/useDataTableRows.d.ts.map +1 -0
- package/dist/esm/DataTables/useDataTableRows.js +49 -0
- package/dist/esm/DataTables/useDataTableRows.js.map +1 -0
- package/dist/esm/DataTables/useRestoreFocusOnClose.d.ts +7 -0
- package/dist/esm/DataTables/useRestoreFocusOnClose.d.ts.map +1 -0
- package/dist/esm/DataTables/useRestoreFocusOnClose.js +30 -0
- package/dist/esm/DataTables/useRestoreFocusOnClose.js.map +1 -0
- package/dist/esm/Dialogs/DialogDocument.d.ts +22 -0
- package/dist/esm/Dialogs/DialogDocument.d.ts.map +1 -0
- package/dist/esm/Dialogs/DialogDocument.js +24 -0
- package/dist/esm/Dialogs/DialogDocument.js.map +1 -0
- package/dist/esm/Dialogs/DialogFooter.d.ts +24 -0
- package/dist/esm/Dialogs/DialogFooter.d.ts.map +1 -0
- package/dist/esm/Dialogs/DialogFooter.js +65 -0
- package/dist/esm/Dialogs/DialogFooter.js.map +1 -0
- package/dist/esm/Dialogs/DialogHeader.d.ts +31 -0
- package/dist/esm/Dialogs/DialogHeader.d.ts.map +1 -0
- package/dist/esm/Dialogs/DialogHeader.js +28 -0
- package/dist/esm/Dialogs/DialogHeader.js.map +1 -0
- package/dist/esm/Dialogs/DialogImplementation.d.ts +1 -2
- package/dist/esm/Dialogs/DialogImplementation.d.ts.map +1 -1
- package/dist/esm/Dialogs/DialogImplementation.js +88 -189
- package/dist/esm/Dialogs/DialogImplementation.js.map +1 -1
- package/dist/esm/Dialogs/DialogShells.d.ts +29 -0
- package/dist/esm/Dialogs/DialogShells.d.ts.map +1 -0
- package/dist/esm/Dialogs/DialogShells.js +36 -0
- package/dist/esm/Dialogs/DialogShells.js.map +1 -0
- package/dist/esm/Dialogs/dialogPartAttributes.d.ts +19 -0
- package/dist/esm/Dialogs/dialogPartAttributes.d.ts.map +1 -0
- package/dist/esm/Dialogs/dialogPartAttributes.js +10 -0
- package/dist/esm/Dialogs/dialogPartAttributes.js.map +1 -0
- package/dist/esm/Dialogs/resolveDialogLabels.d.ts +29 -0
- package/dist/esm/Dialogs/resolveDialogLabels.d.ts.map +1 -0
- package/dist/esm/Dialogs/resolveDialogLabels.js +11 -0
- package/dist/esm/Dialogs/resolveDialogLabels.js.map +1 -0
- package/dist/esm/Dialogs/useDialogClose.d.ts +13 -0
- package/dist/esm/Dialogs/useDialogClose.d.ts.map +1 -0
- package/dist/esm/Dialogs/useDialogClose.js +32 -0
- package/dist/esm/Dialogs/useDialogClose.js.map +1 -0
- package/dist/esm/Dialogs/useDialogFocus.d.ts +26 -0
- package/dist/esm/Dialogs/useDialogFocus.d.ts.map +1 -0
- package/dist/esm/Dialogs/useDialogFocus.js +56 -0
- package/dist/esm/Dialogs/useDialogFocus.js.map +1 -0
- package/dist/esm/Dialogs/useDialogZIndex.d.ts +9 -0
- package/dist/esm/Dialogs/useDialogZIndex.d.ts.map +1 -0
- package/dist/esm/Dialogs/useDialogZIndex.js +19 -0
- package/dist/esm/Dialogs/useDialogZIndex.js.map +1 -0
- package/dist/esm/SchemaEditor/ReadOnlyTypeCell.d.ts +6 -0
- package/dist/esm/SchemaEditor/ReadOnlyTypeCell.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/ReadOnlyTypeCell.js +19 -0
- package/dist/esm/SchemaEditor/ReadOnlyTypeCell.js.map +1 -0
- package/dist/esm/SchemaEditor/SchemaEditor.d.ts.map +1 -1
- package/dist/esm/SchemaEditor/SchemaEditor.js +44 -514
- package/dist/esm/SchemaEditor/SchemaEditor.js.map +1 -1
- package/dist/esm/SchemaEditor/SchemaEditorNavigation.d.ts +13 -0
- package/dist/esm/SchemaEditor/SchemaEditorNavigation.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/SchemaEditorNavigation.js +36 -0
- package/dist/esm/SchemaEditor/SchemaEditorNavigation.js.map +1 -0
- package/dist/esm/SchemaEditor/SchemaEditorTable.d.ts +34 -0
- package/dist/esm/SchemaEditor/SchemaEditorTable.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/SchemaEditorTable.js +54 -0
- package/dist/esm/SchemaEditor/SchemaEditorTable.js.map +1 -0
- package/dist/esm/SchemaEditor/TypeCell.d.ts.map +1 -1
- package/dist/esm/SchemaEditor/TypeCell.js +14 -80
- package/dist/esm/SchemaEditor/TypeCell.js.map +1 -1
- package/dist/esm/SchemaEditor/TypeCellActions.d.ts +13 -0
- package/dist/esm/SchemaEditor/TypeCellActions.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/TypeCellActions.js +19 -0
- package/dist/esm/SchemaEditor/TypeCellActions.js.map +1 -0
- package/dist/esm/SchemaEditor/resolveTypeChange.d.ts +12 -0
- package/dist/esm/SchemaEditor/resolveTypeChange.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/resolveTypeChange.js +19 -0
- package/dist/esm/SchemaEditor/resolveTypeChange.js.map +1 -0
- package/dist/esm/SchemaEditor/schemaDocument.d.ts +20 -0
- package/dist/esm/SchemaEditor/schemaDocument.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/schemaDocument.js +70 -0
- package/dist/esm/SchemaEditor/schemaDocument.js.map +1 -0
- package/dist/esm/SchemaEditor/schemaEditorMenu.d.ts +30 -0
- package/dist/esm/SchemaEditor/schemaEditorMenu.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/schemaEditorMenu.js +51 -0
- package/dist/esm/SchemaEditor/schemaEditorMenu.js.map +1 -0
- package/dist/esm/SchemaEditor/schemaPropertyEdits.d.ts +33 -0
- package/dist/esm/SchemaEditor/schemaPropertyEdits.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/schemaPropertyEdits.js +134 -0
- package/dist/esm/SchemaEditor/schemaPropertyEdits.js.map +1 -0
- package/dist/esm/SchemaEditor/typeOptions.d.ts +11 -0
- package/dist/esm/SchemaEditor/typeOptions.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/typeOptions.js +20 -0
- package/dist/esm/SchemaEditor/typeOptions.js.map +1 -0
- package/dist/esm/SchemaEditor/useSchemaDocument.d.ts +26 -0
- package/dist/esm/SchemaEditor/useSchemaDocument.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/useSchemaDocument.js +65 -0
- package/dist/esm/SchemaEditor/useSchemaDocument.js.map +1 -0
- package/dist/esm/SchemaEditor/useSchemaEdits.d.ts +29 -0
- package/dist/esm/SchemaEditor/useSchemaEdits.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/useSchemaEdits.js +50 -0
- package/dist/esm/SchemaEditor/useSchemaEdits.js.map +1 -0
- package/dist/esm/SchemaEditor/useSchemaNavigation.d.ts +15 -0
- package/dist/esm/SchemaEditor/useSchemaNavigation.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/useSchemaNavigation.js +24 -0
- package/dist/esm/SchemaEditor/useSchemaNavigation.js.map +1 -0
- package/dist/esm/SchemaEditor/useSchemaRows.d.ts +17 -0
- package/dist/esm/SchemaEditor/useSchemaRows.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/useSchemaRows.js +49 -0
- package/dist/esm/SchemaEditor/useSchemaRows.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,536 +1,66 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
-
import { useMemo,
|
|
3
|
-
import { Button } from '../Common/Button.js';
|
|
4
|
-
import { Checkbox } from '../Common/Checkbox.js';
|
|
5
|
-
import { DataTableCore } from '../DataTables/DataTableCore.js';
|
|
6
|
-
import { Column } from '../DataTables/Column.js';
|
|
2
|
+
import { useMemo, useCallback } from 'react';
|
|
7
3
|
import { ActionMenubar } from '../Common/ActionMenubar.js';
|
|
8
|
-
import { Tooltip } from '../Common/Tooltip.js';
|
|
9
4
|
import { Message } from '../Display/Message.js';
|
|
10
|
-
import * as faIcons from 'react-icons/fa6';
|
|
11
|
-
import { NameCell } from './NameCell.js';
|
|
12
|
-
import { TypeCell } from './TypeCell.js';
|
|
13
5
|
import { DEFAULT_TYPE_FORMATS } from '../types/TypeFormat.js';
|
|
14
|
-
import { validatePropertyName, dropInapplicableKeywords, buildBreadcrumbItems } from './schemaHelpers.js';
|
|
15
6
|
import { defaultSchemaEditorLabels } from './defaultSchemaEditorLabels.js';
|
|
16
|
-
import {
|
|
7
|
+
import { findSchemaAtPath } from './schemaDocument.js';
|
|
8
|
+
import { useSchemaDocument } from './useSchemaDocument.js';
|
|
9
|
+
import { useSchemaEdits } from './useSchemaEdits.js';
|
|
10
|
+
import { useSchemaNavigation } from './useSchemaNavigation.js';
|
|
11
|
+
import { useSchemaRows } from './useSchemaRows.js';
|
|
12
|
+
import { useSchemaEditorMenu } from './schemaEditorMenu.js';
|
|
13
|
+
import { SchemaEditorNavigation } from './SchemaEditorNavigation.js';
|
|
14
|
+
import { SchemaEditorTable } from './SchemaEditorTable.js';
|
|
17
15
|
import { TreeSchemaEditor } from './Tree/TreeSchemaEditor.js';
|
|
18
16
|
|
|
19
17
|
const emptySchema = {};
|
|
20
|
-
const isPlainObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
21
|
-
const isValidSchemaNode = (node) => {
|
|
22
|
-
if (!isPlainObject(node)) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
if (node.required !== undefined &&
|
|
26
|
-
(!Array.isArray(node.required) ||
|
|
27
|
-
!node.required.every((propertyName) => typeof propertyName === 'string'))) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
for (const nestedSchemas of [node.properties, node.definitions]) {
|
|
31
|
-
if (nestedSchemas === undefined)
|
|
32
|
-
continue;
|
|
33
|
-
if (!isPlainObject(nestedSchemas))
|
|
34
|
-
return false;
|
|
35
|
-
for (const nestedSchema of Object.values(nestedSchemas)) {
|
|
36
|
-
if (!isValidSchemaNode(nestedSchema))
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (node.items !== undefined && !isValidSchemaNode(node.items)) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
return true;
|
|
44
|
-
};
|
|
45
|
-
const cloneSchema = (schema) => {
|
|
46
|
-
try {
|
|
47
|
-
const serializedSchema = JSON.stringify(schema);
|
|
48
|
-
if (serializedSchema === undefined)
|
|
49
|
-
return undefined;
|
|
50
|
-
const parsedSchema = JSON.parse(serializedSchema);
|
|
51
|
-
if (!isValidSchemaNode(parsedSchema)) {
|
|
52
|
-
return undefined;
|
|
53
|
-
}
|
|
54
|
-
return parsedSchema;
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
57
|
-
return undefined;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
const findSchemaAtPath = (root, path) => {
|
|
61
|
-
let target = root;
|
|
62
|
-
for (const segment of path) {
|
|
63
|
-
if (target.type === 'array' && segment === '$items') {
|
|
64
|
-
target = target.items || {};
|
|
65
|
-
}
|
|
66
|
-
else if (target.properties && target.properties[segment]) {
|
|
67
|
-
target = target.properties[segment];
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return target;
|
|
74
|
-
};
|
|
75
|
-
const asJsonSchema = (property) => {
|
|
76
|
-
return property;
|
|
77
|
-
};
|
|
78
|
-
const asJsonSchemaProperty = (schema) => {
|
|
79
|
-
return schema;
|
|
80
|
-
};
|
|
81
18
|
const TableSchemaEditor = ({ schema: suppliedSchema, eventTypeName = '', canEdit = true, canNotEditReason, onChange, onSave, onCancel, editMode, saveDisabled = false, cancelDisabled = false, typeFormats = DEFAULT_TYPE_FORMATS, className, labels, allowKeyProperty, allowRequired, isPropertyProtected, validatePropertyName: validateCustomPropertyName, onPropertyRemoved, onPropertyRenamed, header, footer, }) => {
|
|
82
|
-
const schema = suppliedSchema ?? emptySchema;
|
|
83
19
|
const l = useMemo(() => ({ ...defaultSchemaEditorLabels, ...labels }), [labels]);
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
error = validateCustomPropertyName(property.name, property, level);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if (error) {
|
|
110
|
-
errors[prop.id] = error;
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
setValidationErrors(errors);
|
|
114
|
-
return Object.keys(errors).length === 0;
|
|
115
|
-
}, [validatePropertyName, validateCustomPropertyName]);
|
|
116
|
-
useEffect(() => {
|
|
117
|
-
const parsedSchema = cloneSchema(schema);
|
|
118
|
-
if (!parsedSchema) {
|
|
119
|
-
setSchemaJsonIsInvalid(true);
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
setSchemaJsonIsInvalid(false);
|
|
123
|
-
setCurrentSchema(parsedSchema);
|
|
124
|
-
setInitialSchema(parsedSchema);
|
|
125
|
-
}, [schema]);
|
|
126
|
-
useEffect(() => {
|
|
127
|
-
loadPropertiesForCurrentPath();
|
|
128
|
-
}, [currentPath, currentSchema, isEditMode]);
|
|
129
|
-
const loadPropertiesForCurrentPath = () => {
|
|
130
|
-
let targetSchema = currentSchema;
|
|
131
|
-
for (const segment of currentPath) {
|
|
132
|
-
if (targetSchema.type === 'array' && segment === '$items') {
|
|
133
|
-
targetSchema = targetSchema.items || {};
|
|
134
|
-
}
|
|
135
|
-
else if (targetSchema.properties && targetSchema.properties[segment]) {
|
|
136
|
-
targetSchema = targetSchema.properties[segment];
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
const schemaProps = [];
|
|
143
|
-
if (targetSchema.properties) {
|
|
144
|
-
let idCounter = 0;
|
|
145
|
-
for (const [name, property] of Object.entries(targetSchema.properties)) {
|
|
146
|
-
schemaProps.push({
|
|
147
|
-
id: `prop-${currentPath.join('-')}-${idCounter++}`,
|
|
148
|
-
name,
|
|
149
|
-
type: property.type || 'string',
|
|
150
|
-
format: property.format,
|
|
151
|
-
description: property.description,
|
|
152
|
-
items: property.items,
|
|
153
|
-
properties: property.properties,
|
|
154
|
-
required: property.required,
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
setProperties(schemaProps);
|
|
159
|
-
if (isEditMode) {
|
|
160
|
-
validateAllProperties(schemaProps, jsonSchemaToProperties(targetSchema));
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
const updateSchemaAtPath = useCallback((path, updater) => {
|
|
164
|
-
const newSchema = cloneSchema(currentSchema);
|
|
165
|
-
if (!newSchema) {
|
|
166
|
-
setSchemaJsonIsInvalid(true);
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
if (path.length === 0) {
|
|
170
|
-
const updated = updater(newSchema);
|
|
171
|
-
setCurrentSchema(updated);
|
|
172
|
-
onChange?.(updated, { source: 'user' });
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
let targetSchema = newSchema;
|
|
176
|
-
for (let i = 0; i < path.length - 1; i++) {
|
|
177
|
-
const segment = path[i];
|
|
178
|
-
if (targetSchema.type === 'array' && segment === '$items') {
|
|
179
|
-
if (!targetSchema.items) {
|
|
180
|
-
targetSchema.items = { type: 'object', properties: {} };
|
|
181
|
-
}
|
|
182
|
-
targetSchema = targetSchema.items;
|
|
183
|
-
}
|
|
184
|
-
else if (targetSchema.properties && targetSchema.properties[segment]) {
|
|
185
|
-
targetSchema = asJsonSchema(targetSchema.properties[segment]);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
const lastSegment = path[path.length - 1];
|
|
189
|
-
if (targetSchema.type === 'array' && lastSegment === '$items') {
|
|
190
|
-
targetSchema.items = updater(targetSchema.items || {});
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
if (!targetSchema.properties) {
|
|
194
|
-
targetSchema.properties = {};
|
|
195
|
-
}
|
|
196
|
-
const propertySchema = targetSchema.properties[lastSegment];
|
|
197
|
-
targetSchema.properties[lastSegment] = asJsonSchemaProperty(updater(propertySchema ? asJsonSchema(propertySchema) : {}));
|
|
198
|
-
}
|
|
199
|
-
setCurrentSchema(newSchema);
|
|
200
|
-
onChange?.(newSchema, { source: 'user' });
|
|
201
|
-
}, [currentSchema, onChange]);
|
|
202
|
-
const addProperty = useCallback(() => {
|
|
203
|
-
updateSchemaAtPath(currentPath, (schema) => {
|
|
204
|
-
const newProps = { ...(schema.properties || {}) };
|
|
205
|
-
let newName = 'newProperty';
|
|
206
|
-
let counter = 1;
|
|
207
|
-
while (newProps[newName]) {
|
|
208
|
-
newName = `newProperty${counter++}`;
|
|
209
|
-
}
|
|
210
|
-
newProps[newName] = { type: 'string' };
|
|
211
|
-
return { ...schema, properties: newProps };
|
|
212
|
-
});
|
|
213
|
-
}, [currentPath, updateSchemaAtPath]);
|
|
214
|
-
const getLevelProperties = useCallback(() => jsonSchemaToProperties(findSchemaAtPath(currentSchema, currentPath)), [currentSchema, currentPath]);
|
|
215
|
-
const isProtected = useCallback((propertyName) => {
|
|
216
|
-
if (!isPropertyProtected)
|
|
217
|
-
return false;
|
|
218
|
-
const property = getLevelProperties().find((candidate) => candidate.name === propertyName);
|
|
219
|
-
return property !== undefined && isPropertyProtected(property);
|
|
220
|
-
}, [isPropertyProtected, getLevelProperties]);
|
|
221
|
-
const removeProperty = useCallback((propertyName) => {
|
|
222
|
-
const removed = getLevelProperties().find((candidate) => candidate.name === propertyName);
|
|
223
|
-
if (removed && isPropertyProtected?.(removed))
|
|
224
|
-
return;
|
|
225
|
-
updateSchemaAtPath(currentPath, (schema) => {
|
|
226
|
-
const newProps = { ...(schema.properties || {}) };
|
|
227
|
-
delete newProps[propertyName];
|
|
228
|
-
const updated = { ...schema, properties: newProps };
|
|
229
|
-
if (schema.required?.includes(propertyName)) {
|
|
230
|
-
updated.required = schema.required.filter((name) => name !== propertyName);
|
|
231
|
-
}
|
|
232
|
-
return updated;
|
|
233
|
-
});
|
|
234
|
-
if (removed)
|
|
235
|
-
onPropertyRemoved?.(removed);
|
|
236
|
-
}, [currentPath, updateSchemaAtPath, getLevelProperties, isPropertyProtected, onPropertyRemoved]);
|
|
237
|
-
const setRequired = useCallback((propertyName, isRequired) => {
|
|
238
|
-
updateSchemaAtPath(currentPath, (schema) => {
|
|
239
|
-
const others = (schema.required ?? []).filter((name) => name !== propertyName);
|
|
240
|
-
const required = isRequired ? [...others, propertyName] : others;
|
|
241
|
-
const updated = { ...schema };
|
|
242
|
-
if (required.length > 0) {
|
|
243
|
-
updated.required = required;
|
|
244
|
-
}
|
|
245
|
-
else {
|
|
246
|
-
delete updated.required;
|
|
247
|
-
}
|
|
248
|
-
return updated;
|
|
249
|
-
});
|
|
250
|
-
}, [currentPath, updateSchemaAtPath]);
|
|
251
|
-
const setKey = useCallback((propertyName) => {
|
|
252
|
-
updateSchemaAtPath(currentPath, (schema) => {
|
|
253
|
-
const newProps = {};
|
|
254
|
-
for (const [name, property] of Object.entries(schema.properties || {})) {
|
|
255
|
-
const { [KEY_KEYWORD]: previousKey, ...rest } = property;
|
|
256
|
-
const makeKey = name === propertyName && previousKey !== true;
|
|
257
|
-
newProps[name] = (makeKey ? { ...rest, [KEY_KEYWORD]: true } : rest);
|
|
258
|
-
}
|
|
259
|
-
return { ...schema, properties: newProps };
|
|
260
|
-
});
|
|
261
|
-
}, [currentPath, updateSchemaAtPath]);
|
|
262
|
-
const updateProperty = useCallback((oldName, field, value, additionalUpdates) => {
|
|
263
|
-
let renamed;
|
|
264
|
-
updateSchemaAtPath(currentPath, (schema) => {
|
|
265
|
-
const newProps = { ...(schema.properties || {}) };
|
|
266
|
-
const prop = { ...(newProps[oldName] || {}) };
|
|
267
|
-
let newRequired = schema.required;
|
|
268
|
-
if (field === 'name') {
|
|
269
|
-
const newName = value;
|
|
270
|
-
if (newName !== oldName && !newProps[newName] && !isProtected(oldName)) {
|
|
271
|
-
renamed = jsonSchemaToProperties({ properties: { [newName]: prop } })[0];
|
|
272
|
-
newProps[newName] = prop;
|
|
273
|
-
delete newProps[oldName];
|
|
274
|
-
if (schema.required?.includes(oldName)) {
|
|
275
|
-
newRequired = schema.required.map((name) => name === oldName ? newName : name);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
else if (field === 'type') {
|
|
280
|
-
const previousNode = { ...prop };
|
|
281
|
-
prop.type = value;
|
|
282
|
-
delete prop['x-concept'];
|
|
283
|
-
if (value === 'array') {
|
|
284
|
-
prop.items = { type: 'string' };
|
|
285
|
-
delete prop.format;
|
|
286
|
-
delete prop.required;
|
|
287
|
-
}
|
|
288
|
-
else if (value === 'object') {
|
|
289
|
-
prop.properties = {};
|
|
290
|
-
delete prop.format;
|
|
291
|
-
delete prop.items;
|
|
292
|
-
delete prop.required;
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
295
|
-
delete prop.items;
|
|
296
|
-
delete prop.properties;
|
|
297
|
-
delete prop.required;
|
|
298
|
-
}
|
|
299
|
-
if (additionalUpdates) {
|
|
300
|
-
if ('format' in additionalUpdates) {
|
|
301
|
-
if (additionalUpdates.format) {
|
|
302
|
-
prop.format = additionalUpdates.format;
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
delete prop.format;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
dropInapplicableKeywords(prop, previousNode);
|
|
310
|
-
newProps[oldName] = prop;
|
|
311
|
-
}
|
|
312
|
-
else if (field === 'format') {
|
|
313
|
-
if (value && value !== 'none') {
|
|
314
|
-
prop.format = value;
|
|
315
|
-
}
|
|
316
|
-
else {
|
|
317
|
-
delete prop.format;
|
|
318
|
-
}
|
|
319
|
-
newProps[oldName] = prop;
|
|
320
|
-
}
|
|
321
|
-
return { ...schema, properties: newProps, required: newRequired };
|
|
322
|
-
});
|
|
323
|
-
if (renamed)
|
|
324
|
-
onPropertyRenamed?.(renamed, oldName);
|
|
325
|
-
}, [currentPath, updateSchemaAtPath, isProtected, onPropertyRenamed]);
|
|
326
|
-
const updateArrayItemType = useCallback((propertyName, itemType) => {
|
|
327
|
-
updateSchemaAtPath(currentPath, (schema) => {
|
|
328
|
-
const newProps = { ...(schema.properties || {}) };
|
|
329
|
-
const prop = { ...(newProps[propertyName] || {}) };
|
|
330
|
-
if (itemType === 'object') {
|
|
331
|
-
prop.items = { type: 'object', properties: {} };
|
|
332
|
-
}
|
|
333
|
-
else if (itemType === 'array') {
|
|
334
|
-
prop.items = { type: 'array', items: { type: 'string' } };
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
prop.items = { type: itemType };
|
|
338
|
-
}
|
|
339
|
-
newProps[propertyName] = prop;
|
|
340
|
-
return { ...schema, properties: newProps };
|
|
341
|
-
});
|
|
342
|
-
}, [currentPath, updateSchemaAtPath]);
|
|
343
|
-
const navigateToProperty = useCallback((propertyName) => {
|
|
344
|
-
setCurrentPath([...currentPath, propertyName]);
|
|
345
|
-
}, [currentPath]);
|
|
346
|
-
const navigateToArrayItems = useCallback((propertyName) => {
|
|
347
|
-
setCurrentPath([...currentPath, propertyName, '$items']);
|
|
348
|
-
}, [currentPath]);
|
|
349
|
-
const navigateBack = useCallback(() => {
|
|
350
|
-
if (currentPath.length > 0) {
|
|
351
|
-
setCurrentPath(currentPath.slice(0, -1));
|
|
352
|
-
}
|
|
353
|
-
}, [currentPath]);
|
|
354
|
-
const navigateToBreadcrumb = useCallback((index) => {
|
|
355
|
-
const items = getBreadcrumbItems();
|
|
356
|
-
setCurrentPath(items[index].path);
|
|
357
|
-
}, [currentPath, eventTypeName]);
|
|
358
|
-
const handleSave = useCallback(() => {
|
|
359
|
-
if (schemaJsonIsInvalid)
|
|
360
|
-
return;
|
|
361
|
-
onSave?.();
|
|
362
|
-
setIsEditMode(false);
|
|
363
|
-
}, [onSave, schemaJsonIsInvalid]);
|
|
364
|
-
const handleCancel = useCallback(() => {
|
|
365
|
-
const restoredSchema = cloneSchema(initialSchema);
|
|
366
|
-
const changedSchema = cloneSchema(initialSchema);
|
|
367
|
-
if (!restoredSchema || !changedSchema) {
|
|
368
|
-
setSchemaJsonIsInvalid(true);
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
|
-
const hasChanges = JSON.stringify(currentSchema) !== JSON.stringify(initialSchema);
|
|
372
|
-
setCurrentSchema(restoredSchema);
|
|
373
|
-
if (hasChanges) {
|
|
374
|
-
onChange?.(changedSchema, { source: 'reset' });
|
|
375
|
-
}
|
|
376
|
-
setIsEditMode(false);
|
|
377
|
-
onCancel?.();
|
|
378
|
-
}, [currentSchema, initialSchema, onChange, onCancel]);
|
|
379
|
-
const handleEdit = useCallback(() => {
|
|
380
|
-
if (schemaJsonIsInvalid)
|
|
381
|
-
return;
|
|
382
|
-
const parsedSchema = cloneSchema(currentSchema);
|
|
383
|
-
if (!parsedSchema) {
|
|
384
|
-
setSchemaJsonIsInvalid(true);
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
setInitialSchema(parsedSchema);
|
|
388
|
-
setIsEditMode(true);
|
|
389
|
-
}, [currentSchema, schemaJsonIsInvalid]);
|
|
390
|
-
const getBreadcrumbItems = () => buildBreadcrumbItems(eventTypeName, currentPath);
|
|
391
|
-
const getCurrentDescription = useCallback(() => {
|
|
392
|
-
let targetSchema = currentSchema;
|
|
393
|
-
for (const segment of currentPath) {
|
|
394
|
-
if (targetSchema.type === 'array' && segment === '$items') {
|
|
395
|
-
targetSchema = targetSchema.items || {};
|
|
396
|
-
}
|
|
397
|
-
else if (targetSchema.properties && targetSchema.properties[segment]) {
|
|
398
|
-
targetSchema = targetSchema.properties[segment];
|
|
399
|
-
}
|
|
400
|
-
else {
|
|
401
|
-
return undefined;
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
return targetSchema.description;
|
|
405
|
-
}, [currentSchema, currentPath]);
|
|
20
|
+
const document = useSchemaDocument({
|
|
21
|
+
schema: suppliedSchema ?? emptySchema,
|
|
22
|
+
editMode,
|
|
23
|
+
onChange,
|
|
24
|
+
onSave,
|
|
25
|
+
onCancel,
|
|
26
|
+
});
|
|
27
|
+
const { currentSchema, schemaJsonIsInvalid, isEditMode } = document;
|
|
28
|
+
const navigation = useSchemaNavigation(eventTypeName, isEditMode);
|
|
29
|
+
const { currentPath } = navigation;
|
|
30
|
+
const { properties, validationErrors } = useSchemaRows(currentSchema, currentPath, isEditMode, validateCustomPropertyName);
|
|
31
|
+
const markInvalid = useCallback(() => document.setSchemaJsonIsInvalid(true), [document.setSchemaJsonIsInvalid]);
|
|
32
|
+
const edits = useSchemaEdits({
|
|
33
|
+
currentSchema,
|
|
34
|
+
currentPath,
|
|
35
|
+
setCurrentSchema: document.setCurrentSchema,
|
|
36
|
+
markInvalid,
|
|
37
|
+
onChange,
|
|
38
|
+
isPropertyProtected,
|
|
39
|
+
onPropertyRemoved,
|
|
40
|
+
onPropertyRenamed,
|
|
41
|
+
});
|
|
406
42
|
const hasValidationErrors = schemaJsonIsInvalid || Object.keys(validationErrors).length > 0;
|
|
407
|
-
const menuItems =
|
|
408
|
-
...(isEditMode
|
|
409
|
-
? []
|
|
410
|
-
: [
|
|
411
|
-
{
|
|
412
|
-
label: l.edit,
|
|
413
|
-
icon: jsx(faIcons.FaPencil, { className: 'cratis:mr-2' }),
|
|
414
|
-
command: canEdit && !schemaJsonIsInvalid ? handleEdit : undefined,
|
|
415
|
-
disabled: schemaJsonIsInvalid,
|
|
416
|
-
className: canEdit ? undefined : 'edit-disabled-with-reason',
|
|
417
|
-
template: !canEdit && canNotEditReason
|
|
418
|
-
? (item) => (jsx(Tooltip, { content: canNotEditReason, position: 'bottom', children: jsxs("button", { type: 'button', "aria-disabled": 'true', style: {
|
|
419
|
-
border: 0,
|
|
420
|
-
background: 'transparent',
|
|
421
|
-
color: 'inherit',
|
|
422
|
-
cursor: 'not-allowed',
|
|
423
|
-
opacity: 0.6,
|
|
424
|
-
display: 'inline-flex',
|
|
425
|
-
alignItems: 'center',
|
|
426
|
-
padding: '0.5rem 0.75rem',
|
|
427
|
-
}, children: [item.icon, jsx("span", { children: item.label })] }) }))
|
|
428
|
-
: undefined,
|
|
429
|
-
},
|
|
430
|
-
]),
|
|
431
|
-
...(isEditMode
|
|
432
|
-
? [
|
|
433
|
-
...(saveDisabled
|
|
434
|
-
? []
|
|
435
|
-
: [
|
|
436
|
-
{
|
|
437
|
-
label: l.save,
|
|
438
|
-
icon: jsx(faIcons.FaCheck, { className: 'cratis:mr-2' }),
|
|
439
|
-
command: hasValidationErrors ? undefined : handleSave,
|
|
440
|
-
disabled: hasValidationErrors,
|
|
441
|
-
},
|
|
442
|
-
]),
|
|
443
|
-
...(cancelDisabled
|
|
444
|
-
? []
|
|
445
|
-
: [
|
|
446
|
-
{
|
|
447
|
-
label: l.cancel,
|
|
448
|
-
icon: jsx(faIcons.FaXmark, { className: 'cratis:mr-2' }),
|
|
449
|
-
command: handleCancel,
|
|
450
|
-
},
|
|
451
|
-
]),
|
|
452
|
-
{
|
|
453
|
-
label: l.addProperty,
|
|
454
|
-
icon: jsx(faIcons.FaPlus, { className: 'cratis:mr-2' }),
|
|
455
|
-
command: schemaJsonIsInvalid ? undefined : addProperty,
|
|
456
|
-
disabled: schemaJsonIsInvalid,
|
|
457
|
-
},
|
|
458
|
-
]
|
|
459
|
-
: []),
|
|
460
|
-
], [
|
|
43
|
+
const menuItems = useSchemaEditorMenu({
|
|
461
44
|
isEditMode,
|
|
462
|
-
handleSave,
|
|
463
|
-
handleCancel,
|
|
464
|
-
handleEdit,
|
|
465
|
-
addProperty,
|
|
466
45
|
canEdit,
|
|
467
46
|
canNotEditReason,
|
|
468
|
-
hasValidationErrors,
|
|
469
47
|
schemaJsonIsInvalid,
|
|
48
|
+
hasValidationErrors,
|
|
470
49
|
saveDisabled,
|
|
471
50
|
cancelDisabled,
|
|
472
|
-
l,
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
51
|
+
labels: l,
|
|
52
|
+
onEdit: document.handleEdit,
|
|
53
|
+
onSave: document.handleSave,
|
|
54
|
+
onCancel: document.handleCancel,
|
|
55
|
+
onAddProperty: edits.addProperty,
|
|
56
|
+
});
|
|
477
57
|
const currentLevel = findSchemaAtPath(currentSchema, currentPath);
|
|
478
|
-
return (jsxs("div", { className: className ? `schema-editor ${className}` : 'schema-editor', style: { display: 'flex', flexDirection: 'column', height: '100%' }, children: [header, jsxs("div", { className: 'cratis:px-4 cratis:py-4', children: [jsx("div", { className: 'schema-editor-menubar', children: jsx(ActionMenubar, { "aria-label": l.actions, model: menuItems }) }), schemaJsonIsInvalid &&
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
? 'location'
|
|
484
|
-
: undefined, style: {
|
|
485
|
-
padding: 0,
|
|
486
|
-
border: 0,
|
|
487
|
-
background: 'transparent',
|
|
488
|
-
color: 'inherit',
|
|
489
|
-
font: 'inherit',
|
|
490
|
-
cursor: 'pointer',
|
|
491
|
-
textDecoration: index < breadcrumbItems.length - 1
|
|
492
|
-
? 'underline'
|
|
493
|
-
: 'none',
|
|
494
|
-
}, children: item.name })] }, index))) })] }), currentDescription && (jsxs("div", { style: {
|
|
495
|
-
fontSize: '0.875rem',
|
|
496
|
-
color: 'var(--cratis-text-color-secondary)',
|
|
497
|
-
marginTop: '0.5rem',
|
|
498
|
-
marginLeft: '2.5rem',
|
|
499
|
-
fontStyle: 'italic',
|
|
500
|
-
display: 'flex',
|
|
501
|
-
alignItems: 'center',
|
|
502
|
-
gap: '0.5rem',
|
|
503
|
-
}, children: [jsx(faIcons.FaCircleInfo, {}), jsx("span", { children: currentDescription })] }))] }), jsx("div", { style: { flex: 1, overflow: 'auto', padding: '1rem' }, children: jsxs(DataTableCore, { data: properties, dataKey: 'id', emptyMessage: l.emptyMessage, rowClassName: (rowData) => {
|
|
504
|
-
if (!isEditMode &&
|
|
505
|
-
(rowData.type === 'object' ||
|
|
506
|
-
(rowData.type === 'array' &&
|
|
507
|
-
rowData.items?.type === 'object'))) {
|
|
508
|
-
return 'cratis-schema-editor-navigable-row';
|
|
509
|
-
}
|
|
510
|
-
return '';
|
|
511
|
-
}, onRowClick: (e) => {
|
|
512
|
-
if (!isEditMode) {
|
|
513
|
-
const rowData = e.data;
|
|
514
|
-
if (rowData.name) {
|
|
515
|
-
if (rowData.type === 'object') {
|
|
516
|
-
navigateToProperty(rowData.name);
|
|
517
|
-
}
|
|
518
|
-
else if (rowData.type === 'array' &&
|
|
519
|
-
rowData.items?.type === 'object') {
|
|
520
|
-
navigateToArrayItems(rowData.name);
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
}, pt: {
|
|
525
|
-
root: { style: { border: 'none' } },
|
|
526
|
-
body: {
|
|
527
|
-
style: {
|
|
528
|
-
borderTop: '1px solid var(--cratis-surface-border)',
|
|
529
|
-
},
|
|
530
|
-
},
|
|
531
|
-
}, children: [jsx(Column, { field: 'name', header: 'Property', body: (rowData) => (jsx(NameCell, { rowData: rowData, isEditMode: isEditMode, onUpdate: updateProperty, validationError: validationErrors[rowData.id], propertyNameLabel: l.propertyName, isLocked: isProtected(rowData.name ?? ''), lockedReason: l.protectedProperty })), style: { width: '30%' } }), showRequired && (jsx(Column, { header: l.requiredColumn, body: (rowData) => (jsx(Checkbox, { "aria-label": l.requiredProperty(rowData.name ?? ''), checked: Boolean(currentLevel?.required?.includes(rowData.name ?? '')), readOnly: !isEditMode, onChange: (checked) => setRequired(rowData.name ?? '', checked) })), style: { width: '6rem' } })), showKey && (jsx(Column, { header: l.keyColumn, body: (rowData) => (jsx(Checkbox, { "aria-label": l.keyProperty(rowData.name ?? ''), checked: isKeyProperty(currentLevel, rowData.name ?? ''), readOnly: !isEditMode, onChange: () => setKey(rowData.name ?? '') })), style: { width: '6rem' } })), jsx(Column, { header: 'Type', body: (rowData) => (jsx(TypeCell, { rowData: rowData, isEditMode: isEditMode, typeFormats: typeFormats, onUpdateProperty: updateProperty, onUpdateArrayItemType: updateArrayItemType, onNavigateToProperty: navigateToProperty, onNavigateToArrayItems: navigateToArrayItems, onRemoveProperty: removeProperty, canRemove: !isProtected(rowData.name ?? ''), labels: l })), style: { width: '70%' } })] }, `${isEditMode}-${currentPath.join('/')}`) }), footer] }));
|
|
58
|
+
return (jsxs("div", { className: className ? `schema-editor ${className}` : 'schema-editor', style: { display: 'flex', flexDirection: 'column', height: '100%' }, children: [header, jsxs("div", { className: 'cratis:px-4 cratis:py-4', children: [jsx("div", { className: 'schema-editor-menubar', children: jsx(ActionMenubar, { "aria-label": l.actions, model: menuItems }) }), schemaJsonIsInvalid && jsx(Message, { severity: 'error', text: l.invalidJson, className: 'cratis:mt-3' })] }), jsx(SchemaEditorNavigation, { items: navigation.breadcrumbItems, description: currentLevel?.description, isAtRoot: currentPath.length === 0, navigateBackLabel: l.navigateBack, onNavigateBack: navigation.navigateBack, onNavigateToBreadcrumb: navigation.navigateToBreadcrumb }), jsx("div", { style: { flex: 1, overflow: 'auto', padding: '1rem' }, children: jsx(SchemaEditorTable, { properties: properties, currentPath: currentPath, currentLevel: currentLevel, isEditMode: isEditMode, showRequired: allowRequired === true, showKey: allowKeyProperty !== undefined && allowKeyProperty !== false, validationErrors: validationErrors, typeFormats: typeFormats, labels: l, actions: {
|
|
59
|
+
...edits,
|
|
60
|
+
navigateToProperty: navigation.navigateToProperty,
|
|
61
|
+
navigateToArrayItems: navigation.navigateToArrayItems,
|
|
62
|
+
} }) }), footer] }));
|
|
532
63
|
};
|
|
533
|
-
const isKeyProperty = (level, propertyName) => level?.properties?.[propertyName]?.[KEY_KEYWORD] === true;
|
|
534
64
|
const SchemaEditor = (props) => props.layout === 'tree' ? jsx(TreeSchemaEditor, { ...props }) : jsx(TableSchemaEditor, { ...props });
|
|
535
65
|
|
|
536
66
|
export { SchemaEditor, defaultSchemaEditorLabels };
|