@cratis/components 4.42.0 → 4.42.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compat-manifest.json +11 -11
- 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/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/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/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
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
2
|
+
import { cloneSchema } from './schemaDocument.js';
|
|
3
|
+
|
|
4
|
+
const useSchemaDocument = ({ schema, editMode, onChange, onSave, onCancel }) => {
|
|
5
|
+
const [initialParsedSchema] = useState(() => cloneSchema(schema));
|
|
6
|
+
const [currentSchema, setCurrentSchema] = useState(initialParsedSchema ?? {});
|
|
7
|
+
const [isEditMode, setIsEditMode] = useState(editMode ?? false);
|
|
8
|
+
const [initialSchema, setInitialSchema] = useState(initialParsedSchema ?? {});
|
|
9
|
+
const [schemaJsonIsInvalid, setSchemaJsonIsInvalid] = useState(initialParsedSchema === undefined);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const parsedSchema = cloneSchema(schema);
|
|
12
|
+
if (!parsedSchema) {
|
|
13
|
+
setSchemaJsonIsInvalid(true);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
setSchemaJsonIsInvalid(false);
|
|
17
|
+
setCurrentSchema(parsedSchema);
|
|
18
|
+
setInitialSchema(parsedSchema);
|
|
19
|
+
}, [schema]);
|
|
20
|
+
const handleSave = useCallback(() => {
|
|
21
|
+
if (schemaJsonIsInvalid)
|
|
22
|
+
return;
|
|
23
|
+
onSave?.();
|
|
24
|
+
setIsEditMode(false);
|
|
25
|
+
}, [onSave, schemaJsonIsInvalid]);
|
|
26
|
+
const handleCancel = useCallback(() => {
|
|
27
|
+
const restoredSchema = cloneSchema(initialSchema);
|
|
28
|
+
const changedSchema = cloneSchema(initialSchema);
|
|
29
|
+
if (!restoredSchema || !changedSchema) {
|
|
30
|
+
setSchemaJsonIsInvalid(true);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const hasChanges = JSON.stringify(currentSchema) !== JSON.stringify(initialSchema);
|
|
34
|
+
setCurrentSchema(restoredSchema);
|
|
35
|
+
if (hasChanges) {
|
|
36
|
+
onChange?.(changedSchema, { source: 'reset' });
|
|
37
|
+
}
|
|
38
|
+
setIsEditMode(false);
|
|
39
|
+
onCancel?.();
|
|
40
|
+
}, [currentSchema, initialSchema, onChange, onCancel]);
|
|
41
|
+
const handleEdit = useCallback(() => {
|
|
42
|
+
if (schemaJsonIsInvalid)
|
|
43
|
+
return;
|
|
44
|
+
const parsedSchema = cloneSchema(currentSchema);
|
|
45
|
+
if (!parsedSchema) {
|
|
46
|
+
setSchemaJsonIsInvalid(true);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
setInitialSchema(parsedSchema);
|
|
50
|
+
setIsEditMode(true);
|
|
51
|
+
}, [currentSchema, schemaJsonIsInvalid]);
|
|
52
|
+
return {
|
|
53
|
+
currentSchema,
|
|
54
|
+
setCurrentSchema,
|
|
55
|
+
schemaJsonIsInvalid,
|
|
56
|
+
setSchemaJsonIsInvalid,
|
|
57
|
+
isEditMode,
|
|
58
|
+
handleEdit,
|
|
59
|
+
handleSave,
|
|
60
|
+
handleCancel,
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export { useSchemaDocument };
|
|
65
|
+
//# sourceMappingURL=useSchemaDocument.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSchemaDocument.js","sources":["../../../SchemaEditor/useSchemaDocument.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 { useCallback, useEffect, useState } from 'react';\nimport type { ChangeHandler } from '../types/ChangeHandler';\nimport type { JsonSchema } from '../types/JsonSchema';\nimport { cloneSchema } from './schemaDocument';\n\n/** What the document hook reports back to the host. */\nexport interface SchemaDocumentOptions {\n schema: JsonSchema;\n editMode?: boolean;\n onChange?: ChangeHandler<JsonSchema>;\n onSave?: () => void;\n onCancel?: () => void;\n}\n\n/**\n * Holds the schema being edited and the Edit, Save and Cancel workflow around it.\n * @param options The supplied schema, the initial edit mode and the host callbacks.\n * @returns The working schema, whether it is invalid, the edit mode and the workflow actions.\n */\nexport const useSchemaDocument = ({ schema, editMode, onChange, onSave, onCancel }: SchemaDocumentOptions) => {\n const [initialParsedSchema] = useState<JsonSchema | undefined>(() => cloneSchema(schema));\n const [currentSchema, setCurrentSchema] = useState<JsonSchema>(initialParsedSchema ?? {});\n const [isEditMode, setIsEditMode] = useState(editMode ?? false);\n const [initialSchema, setInitialSchema] = useState<JsonSchema>(initialParsedSchema ?? {});\n const [schemaJsonIsInvalid, setSchemaJsonIsInvalid] = useState(initialParsedSchema === undefined);\n\n useEffect(() => {\n const parsedSchema = cloneSchema(schema);\n if (!parsedSchema) {\n setSchemaJsonIsInvalid(true);\n return;\n }\n\n setSchemaJsonIsInvalid(false);\n setCurrentSchema(parsedSchema);\n setInitialSchema(parsedSchema);\n }, [schema]);\n\n const handleSave = useCallback(() => {\n if (schemaJsonIsInvalid) return;\n\n onSave?.();\n setIsEditMode(false);\n }, [onSave, schemaJsonIsInvalid]);\n\n const handleCancel = useCallback(() => {\n const restoredSchema = cloneSchema(initialSchema);\n const changedSchema = cloneSchema(initialSchema);\n if (!restoredSchema || !changedSchema) {\n setSchemaJsonIsInvalid(true);\n return;\n }\n\n const hasChanges = JSON.stringify(currentSchema) !== JSON.stringify(initialSchema);\n setCurrentSchema(restoredSchema);\n if (hasChanges) {\n onChange?.(changedSchema, { source: 'reset' });\n }\n setIsEditMode(false);\n onCancel?.();\n }, [currentSchema, initialSchema, onChange, onCancel]);\n\n const handleEdit = useCallback(() => {\n if (schemaJsonIsInvalid) return;\n\n const parsedSchema = cloneSchema(currentSchema);\n if (!parsedSchema) {\n setSchemaJsonIsInvalid(true);\n return;\n }\n\n setInitialSchema(parsedSchema);\n setIsEditMode(true);\n }, [currentSchema, schemaJsonIsInvalid]);\n\n return {\n currentSchema,\n setCurrentSchema,\n schemaJsonIsInvalid,\n setSchemaJsonIsInvalid,\n isEditMode,\n handleEdit,\n handleSave,\n handleCancel,\n };\n};\n"],"names":[],"mappings":";;;AAsBO,MAAM,iBAAiB,GAAG,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAyB,KAAI;AACzG,IAAA,MAAM,CAAC,mBAAmB,CAAC,GAAG,QAAQ,CAAyB,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;AACzF,IAAA,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAa,mBAAmB,IAAI,EAAE,CAAC;AACzF,IAAA,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,QAAQ,IAAI,KAAK,CAAC;AAC/D,IAAA,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAa,mBAAmB,IAAI,EAAE,CAAC;AACzF,IAAA,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GAAG,QAAQ,CAAC,mBAAmB,KAAK,SAAS,CAAC;IAEjG,SAAS,CAAC,MAAK;AACX,QAAA,MAAM,YAAY,GAAG,WAAW,CAAC,MAAM,CAAC;QACxC,IAAI,CAAC,YAAY,EAAE;YACf,sBAAsB,CAAC,IAAI,CAAC;YAC5B;QACJ;QAEA,sBAAsB,CAAC,KAAK,CAAC;QAC7B,gBAAgB,CAAC,YAAY,CAAC;QAC9B,gBAAgB,CAAC,YAAY,CAAC;AAClC,IAAA,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;AAEZ,IAAA,MAAM,UAAU,GAAG,WAAW,CAAC,MAAK;AAChC,Q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-0,0 +1,29 @@
|
|
|
1
|
+
import type { ChangeHandler } from '../types/ChangeHandler.js';
|
|
2
|
+
import type { JsonSchema, JsonSchemaProperty } from '../types/JsonSchema.js';
|
|
3
|
+
import type { Property } from './Tree/Property.js';
|
|
4
|
+
/** The working document and the host hooks the edits report to. */
|
|
5
|
+
export interface SchemaEditsOptions {
|
|
6
|
+
currentSchema: JsonSchema;
|
|
7
|
+
currentPath: string[];
|
|
8
|
+
setCurrentSchema: (schema: JsonSchema) => void;
|
|
9
|
+
markInvalid: () => void;
|
|
10
|
+
onChange?: ChangeHandler<JsonSchema>;
|
|
11
|
+
isPropertyProtected?: (property: Property) => boolean;
|
|
12
|
+
onPropertyRemoved?: (property: Property) => void;
|
|
13
|
+
onPropertyRenamed?: (property: Property, previousName: string) => void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The edits the table layout applies to the schema level at the current path.
|
|
17
|
+
* @param options The working document and the host hooks.
|
|
18
|
+
* @returns The edit actions and the protected check.
|
|
19
|
+
*/
|
|
20
|
+
export declare const useSchemaEdits: ({ currentSchema, currentPath, setCurrentSchema, markInvalid, onChange, isPropertyProtected, onPropertyRemoved, onPropertyRenamed, }: SchemaEditsOptions) => {
|
|
21
|
+
addProperty: () => void;
|
|
22
|
+
removeProperty: (propertyName: string) => void;
|
|
23
|
+
setRequired: (propertyName: string, isRequired: boolean) => void;
|
|
24
|
+
setKey: (propertyName: string) => void;
|
|
25
|
+
updateProperty: (oldName: string, field: keyof JsonSchemaProperty, value: unknown, additionalUpdates?: Partial<JsonSchemaProperty>) => void;
|
|
26
|
+
updateArrayItemType: (propertyName: string, itemType: string) => void;
|
|
27
|
+
isProtected: (propertyName: string) => boolean;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=useSchemaEdits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSchemaEdits.d.ts","sourceRoot":"","sources":["../../../SchemaEditor/useSchemaEdits.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,wBAAqB,CAAC;AAU1E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAiB,CAAC;AAGhD,mEAAmE;AACnE,MAAM,WAAW,kBAAkB;IAC/B,aAAa,EAAE,UAAU,CAAC;IAC1B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,gBAAgB,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IAC/C,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,QAAQ,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IACrC,mBAAmB,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC;IACtD,iBAAiB,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;IACjD,iBAAiB,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,KAAK,IAAI,CAAC;CAC1E;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,wIASxB,kBAAkB;;mCAkCE,MAAM;gCAUN,MAAM,cAAc,OAAO;2BAKJ,MAAM;8BAI/B,MAAM,SACR,MAAM,kBAAkB,SACxB,OAAO,sBACM,OAAO,CAAC,kBAAkB,CAAC;wCAcpC,MAAM,YAAY,MAAM;gCA/CxB,MAAM;CAqD5B,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { cloneSchema, updateSchemaAtPath, findSchemaAtPath } from './schemaDocument.js';
|
|
3
|
+
import { addPropertyTo, removePropertyFrom, setRequiredIn, setKeyIn, editProperty, setArrayItemType } from './schemaPropertyEdits.js';
|
|
4
|
+
import { jsonSchemaToProperties } from './Tree/schemaConversion.js';
|
|
5
|
+
|
|
6
|
+
const useSchemaEdits = ({ currentSchema, currentPath, setCurrentSchema, markInvalid, onChange, isPropertyProtected, onPropertyRemoved, onPropertyRenamed, }) => {
|
|
7
|
+
const applyEdit = useCallback((updater) => {
|
|
8
|
+
const copy = cloneSchema(currentSchema);
|
|
9
|
+
if (!copy) {
|
|
10
|
+
markInvalid();
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const updated = updateSchemaAtPath(copy, currentPath, updater);
|
|
14
|
+
setCurrentSchema(updated);
|
|
15
|
+
onChange?.(updated, { source: 'user' });
|
|
16
|
+
}, [currentSchema, currentPath, onChange, setCurrentSchema, markInvalid]);
|
|
17
|
+
const getLevelProperties = useCallback(() => jsonSchemaToProperties(findSchemaAtPath(currentSchema, currentPath)), [currentSchema, currentPath]);
|
|
18
|
+
const isProtected = useCallback((propertyName) => {
|
|
19
|
+
if (!isPropertyProtected)
|
|
20
|
+
return false;
|
|
21
|
+
const property = getLevelProperties().find((candidate) => candidate.name === propertyName);
|
|
22
|
+
return property !== undefined && isPropertyProtected(property);
|
|
23
|
+
}, [isPropertyProtected, getLevelProperties]);
|
|
24
|
+
const addProperty = useCallback(() => applyEdit(addPropertyTo), [applyEdit]);
|
|
25
|
+
const removeProperty = useCallback((propertyName) => {
|
|
26
|
+
const removed = getLevelProperties().find((candidate) => candidate.name === propertyName);
|
|
27
|
+
if (removed && isPropertyProtected?.(removed))
|
|
28
|
+
return;
|
|
29
|
+
applyEdit((level) => removePropertyFrom(level, propertyName));
|
|
30
|
+
if (removed)
|
|
31
|
+
onPropertyRemoved?.(removed);
|
|
32
|
+
}, [applyEdit, getLevelProperties, isPropertyProtected, onPropertyRemoved]);
|
|
33
|
+
const setRequired = useCallback((propertyName, isRequired) => applyEdit((level) => setRequiredIn(level, propertyName, isRequired)), [applyEdit]);
|
|
34
|
+
const setKey = useCallback((propertyName) => applyEdit((level) => setKeyIn(level, propertyName)), [applyEdit]);
|
|
35
|
+
const updateProperty = useCallback((oldName, field, value, additionalUpdates) => {
|
|
36
|
+
let renamed;
|
|
37
|
+
applyEdit((level) => {
|
|
38
|
+
const result = editProperty(level, oldName, { field, value, additionalUpdates }, isProtected(oldName));
|
|
39
|
+
renamed = result.renamed;
|
|
40
|
+
return result.schema;
|
|
41
|
+
});
|
|
42
|
+
if (renamed)
|
|
43
|
+
onPropertyRenamed?.(renamed, oldName);
|
|
44
|
+
}, [applyEdit, isProtected, onPropertyRenamed]);
|
|
45
|
+
const updateArrayItemType = useCallback((propertyName, itemType) => applyEdit((level) => setArrayItemType(level, propertyName, itemType)), [applyEdit]);
|
|
46
|
+
return { addProperty, removeProperty, setRequired, setKey, updateProperty, updateArrayItemType, isProtected };
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export { useSchemaEdits };
|
|
50
|
+
//# sourceMappingURL=useSchemaEdits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSchemaEdits.js","sources":["../../../SchemaEditor/useSchemaEdits.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 { useCallback } from 'react';\nimport type { ChangeHandler } from '../types/ChangeHandler';\nimport type { JsonSchema, JsonSchemaProperty } from '../types/JsonSchema';\nimport { cloneSchema, findSchemaAtPath, updateSchemaAtPath } from './schemaDocument';\nimport {\n addPropertyTo,\n editProperty,\n removePropertyFrom,\n setArrayItemType,\n setKeyIn,\n setRequiredIn,\n} from './schemaPropertyEdits';\nimport type { Property } from './Tree/Property';\nimport { jsonSchemaToProperties } from './Tree/schemaConversion';\n\n/** The working document and the host hooks the edits report to. */\nexport interface SchemaEditsOptions {\n currentSchema: JsonSchema;\n currentPath: string[];\n setCurrentSchema: (schema: JsonSchema) => void;\n markInvalid: () => void;\n onChange?: ChangeHandler<JsonSchema>;\n isPropertyProtected?: (property: Property) => boolean;\n onPropertyRemoved?: (property: Property) => void;\n onPropertyRenamed?: (property: Property, previousName: string) => void;\n}\n\n/**\n * The edits the table layout applies to the schema level at the current path.\n * @param options The working document and the host hooks.\n * @returns The edit actions and the protected check.\n */\nexport const useSchemaEdits = ({\n currentSchema,\n currentPath,\n setCurrentSchema,\n markInvalid,\n onChange,\n isPropertyProtected,\n onPropertyRemoved,\n onPropertyRenamed,\n}: SchemaEditsOptions) => {\n const applyEdit = useCallback(\n (updater: (level: JsonSchema) => JsonSchema) => {\n const copy = cloneSchema(currentSchema);\n if (!copy) {\n markInvalid();\n return;\n }\n\n const updated = updateSchemaAtPath(copy, currentPath, updater);\n setCurrentSchema(updated);\n onChange?.(updated, { source: 'user' });\n },\n [currentSchema, currentPath, onChange, setCurrentSchema, markInvalid],\n );\n\n /** The editable view of the properties at the current path, for the host callbacks. */\n const getLevelProperties = useCallback(\n () => jsonSchemaToProperties(findSchemaAtPath(currentSchema, currentPath)),\n [currentSchema, currentPath],\n );\n\n const isProtected = useCallback(\n (propertyName: string) => {\n if (!isPropertyProtected) return false;\n const property = getLevelProperties().find((candidate) => candidate.name === propertyName);\n return property !== undefined && isPropertyProtected(property);\n },\n [isPropertyProtected, getLevelProperties],\n );\n\n const addProperty = useCallback(() => applyEdit(addPropertyTo), [applyEdit]);\n\n const removeProperty = useCallback(\n (propertyName: string) => {\n const removed = getLevelProperties().find((candidate) => candidate.name === propertyName);\n if (removed && isPropertyProtected?.(removed)) return;\n applyEdit((level) => removePropertyFrom(level, propertyName));\n if (removed) onPropertyRemoved?.(removed);\n },\n [applyEdit, getLevelProperties, isPropertyProtected, onPropertyRemoved],\n );\n\n const setRequired = useCallback(\n (propertyName: string, isRequired: boolean) =>\n applyEdit((level) => setRequiredIn(level, propertyName, isRequired)),\n [applyEdit],\n );\n\n const setKey = useCallback((propertyName: string) => applyEdit((level) => setKeyIn(level, propertyName)), [applyEdit]);\n\n const updateProperty = useCallback(\n (\n oldName: string,\n field: keyof JsonSchemaProperty,\n value: unknown,\n additionalUpdates?: Partial<JsonSchemaProperty>,\n ) => {\n let renamed: Property | undefined;\n applyEdit((level) => {\n const result = editProperty(level, oldName, { field, value, additionalUpdates }, isProtected(oldName));\n renamed = result.renamed;\n return result.schema;\n });\n if (renamed) onPropertyRenamed?.(renamed, oldName);\n },\n [applyEdit, isProtected, onPropertyRenamed],\n );\n\n const updateArrayItemType = useCallback(\n (propertyName: string, itemType: string) =>\n applyEdit((level) => setArrayItemType(level, propertyName, itemType)),\n [applyEdit],\n );\n\n return { addProperty, removeProperty, setRequired, setKey, updateProperty, updateArrayItemType, isProtected };\n};\n"],"names":[],"mappings":";;;;;MAmCa,cAAc,GAAG,CAAC,EAC3B,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,GACA,KAAI;AACrB,IAAA,MAAM,SAAS,GAAG,WAAW,CACzB,CAAC,OAA0C,KAAI;AAC3C,QAAA,MAAM,IAAI,GAAG,WAAW,CAAC,aAAa,CAAC;QACvC,IAAI,CAAC,IAAI,EAAE;AACP,YAAA,WAAW,EAAE;YACb;QACJ;QAEA,MAAM,OAAO,GAAG,kBAAkB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC;QAC9D,gBAAgB,CAAC,OAAO,CAAC;QACzB,QAAQ,GAAG,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAC3C,IAAA,CAAC,EACD,CAAC,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,gBAAgB,EAAE,WAAW,CAAC,CACxE;IAGD,MAAM,kBAAkB,GAAG,WAAW,CAClC,MAAM,sBAAsB,CAAC,gBAAgB,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC,EAC1E,CAAC,aAAa,EAAE,WAAW,CAAC,CAC/B;AAED,IAAA,MAAM,WAAW,GAAG,WAAW,CAC3B,CAAC,YAAoB,KAAI;AACrB,QAAA,IAAI,CAAC,mBAAmB;AAAE,YAAA,OAAO,KAAK;AACtC,QAAA,MAAM,QAAQ,GAAG,kBAAkB,EAAE,CAAC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;AACA,QAAA,IAAI,OAA6B;AACjC,QAAA,SAAS,CAAC,CAAC,KAAK,KAAI;YAChB,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;AACtG,YAAA,OAAO,GAAG,MAAM,CAAC,OAAO;YACxB,OAAO,MAAM,CAAC,MAAM;AACxB,QAAA,CAAC,CAAC;AACF,QAAA,IAAI,OAAO;AAAE,YAAA,iBAAiB,GAAG,OAAO,EAAE,OAAO,CAAC;IACtD,CAAC,EACD,CAAC,SAAS,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAC9C;AAED,IAAA,MAAM,mBAAmB,GAAG,WAAW,CACnC,CAAC,YAAoB,EAAE,QAAgB,KACnC,SAAS,CAAC,CAAC,KAAK,KAAK,gBAAgB,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAC,EACzE,CAAC,SAAS,CAAC,CACd;AAED,IAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,mBAAmB,EAAE,WAAW,EAAE;AACjH;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tracks the drill-down path of the table layout; leaving edit mode returns to the root.
|
|
3
|
+
* @param eventTypeName The label of the root breadcrumb.
|
|
4
|
+
* @param isEditMode Whether the editor is editing.
|
|
5
|
+
* @returns The path, the breadcrumb and the navigation actions.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useSchemaNavigation: (eventTypeName: string, isEditMode: boolean) => {
|
|
8
|
+
currentPath: string[];
|
|
9
|
+
breadcrumbItems: import("./index.js").NavigationItem[];
|
|
10
|
+
navigateToProperty: (propertyName: string) => void;
|
|
11
|
+
navigateToArrayItems: (propertyName: string) => void;
|
|
12
|
+
navigateBack: () => void;
|
|
13
|
+
navigateToBreadcrumb: (index: number) => void;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=useSchemaNavigation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSchemaNavigation.d.ts","sourceRoot":"","sources":["../../../SchemaEditor/useSchemaNavigation.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,kBAAmB,MAAM,cAAc,OAAO;;;uCAYvD,MAAM;yCAKN,MAAM;;kCAWb,MAAM;CAKrB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useState, useEffect, useMemo, useCallback } from 'react';
|
|
2
|
+
import { buildBreadcrumbItems } from './schemaHelpers.js';
|
|
3
|
+
|
|
4
|
+
const useSchemaNavigation = (eventTypeName, isEditMode) => {
|
|
5
|
+
const [currentPath, setCurrentPath] = useState([]);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (!isEditMode) {
|
|
8
|
+
setCurrentPath([]);
|
|
9
|
+
}
|
|
10
|
+
}, [isEditMode]);
|
|
11
|
+
const breadcrumbItems = useMemo(() => buildBreadcrumbItems(eventTypeName, currentPath), [eventTypeName, currentPath]);
|
|
12
|
+
const navigateToProperty = useCallback((propertyName) => setCurrentPath([...currentPath, propertyName]), [currentPath]);
|
|
13
|
+
const navigateToArrayItems = useCallback((propertyName) => setCurrentPath([...currentPath, propertyName, '$items']), [currentPath]);
|
|
14
|
+
const navigateBack = useCallback(() => {
|
|
15
|
+
if (currentPath.length > 0) {
|
|
16
|
+
setCurrentPath(currentPath.slice(0, -1));
|
|
17
|
+
}
|
|
18
|
+
}, [currentPath]);
|
|
19
|
+
const navigateToBreadcrumb = useCallback((index) => setCurrentPath(breadcrumbItems[index].path), [breadcrumbItems]);
|
|
20
|
+
return { currentPath, breadcrumbItems, navigateToProperty, navigateToArrayItems, navigateBack, navigateToBreadcrumb };
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { useSchemaNavigation };
|
|
24
|
+
//# sourceMappingURL=useSchemaNavigation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSchemaNavigation.js","sources":["../../../SchemaEditor/useSchemaNavigation.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 { useCallback, useEffect, useMemo, useState } from 'react';\nimport { buildBreadcrumbItems } from './schemaHelpers';\n\n/**\n * Tracks the drill-down path of the table layout; leaving edit mode returns to the root.\n * @param eventTypeName The label of the root breadcrumb.\n * @param isEditMode Whether the editor is editing.\n * @returns The path, the breadcrumb and the navigation actions.\n */\nexport const useSchemaNavigation = (eventTypeName: string, isEditMode: boolean) => {\n const [currentPath, setCurrentPath] = useState<string[]>([]);\n\n useEffect(() => {\n if (!isEditMode) {\n setCurrentPath([]);\n }\n }, [isEditMode]);\n\n const breadcrumbItems = useMemo(() => buildBreadcrumbItems(eventTypeName, currentPath), [eventTypeName, currentPath]);\n\n const navigateToProperty = useCallback(\n (propertyName: string) => setCurrentPath([...currentPath, propertyName]),\n [currentPath],\n );\n\n const navigateToArrayItems = useCallback(\n (propertyName: string) => setCurrentPath([...currentPath, propertyName, '$items']),\n [currentPath],\n );\n\n const navigateBack = useCallback(() => {\n if (currentPath.length > 0) {\n setCurrentPath(currentPath.slice(0, -1));\n }\n }, [currentPath]);\n\n const navigateToBreadcrumb = useCallback(\n (index: number) => setCurrentPath(breadcrumbItems[index].path),\n [breadcrumbItems],\n );\n\n return { currentPath, breadcrumbItems, navigateToProperty, navigateToArrayItems, navigateBack, navigateToBreadcrumb };\n};\n"],"names":[],"mappings":";;;MAYa,mBAAmB,GAAG,CAAC,aAAqB,EAAE,UAAmB,KAAI;IAC9E,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAW,EAAE,CAAC;IAE5D,SAAS,CAAC,MAAK;QACX,IAAI,CAAC,UAAU,EAAE;YACb,cAAc,CAAC,EAAE,CAAC;QACtB;AACJ,IAAA,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;IAEhB,MAAM,eAAe,GAAG,OAAO,CAAC,MAAM,oBAAoB,CAAC,aAAa,EAAE,WAAW,CAAC,EAAE,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;IAErH,MAAM,kBAAkB,GAAG,WAAW,CAClC,CAAC,YAAoB,KAAK,cAAc,CAAC,CAAC,GAAG,WAAW,EAAE,YAAY,CAAC,CAAC,EACxE,CAAC,WAAW,CAAC,CAChB;IAED,MAAM,oBAAoB,GAAG,WAAW,CACpC,CAAC,YAAoB,KAAK,cAAc,CAAC,CAAC,GAAG,WAAW,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAC,EAClF,CAAC,WAAW,CAAC,CAChB;AAED,IAAA,MAAM,YAAY,GAAG,WAAW,CAAC,MAAK;AAClC,QAAA,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;YACxB,cAAc,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC5C;AACJ,IAAA,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC;IAEjB,MAAM,oBAAoB,GAAG,WAAW,CACpC,CAAC,KAAa,KAAK,cAAc,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,EAC9D,CAAC,eAAe,CAAC,CACpB;AAED,IAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,YAAY,EAAE,oBAAoB,EAAE;AACzH;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { JsonSchema, JsonSchemaProperty } from '../types/JsonSchema.js';
|
|
2
|
+
import type { Property } from './Tree/Property.js';
|
|
3
|
+
type CustomNameValidator = (name: string, property: Property, siblings: Property[]) => string | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* Derives the rows of the current schema level and, in edit mode, their name validation errors.
|
|
6
|
+
* @param currentSchema The working schema.
|
|
7
|
+
* @param currentPath The drill-down path.
|
|
8
|
+
* @param isEditMode Whether the editor is editing.
|
|
9
|
+
* @param customValidator The host's extra property name check.
|
|
10
|
+
* @returns The rows and the validation error per row id.
|
|
11
|
+
*/
|
|
12
|
+
export declare const useSchemaRows: (currentSchema: JsonSchema, currentPath: string[], isEditMode: boolean, customValidator?: CustomNameValidator) => {
|
|
13
|
+
properties: JsonSchemaProperty[];
|
|
14
|
+
validationErrors: Record<string, string>;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=useSchemaRows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSchemaRows.d.ts","sourceRoot":"","sources":["../../../SchemaEditor/useSchemaRows.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,wBAAqB,CAAC;AAG1E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAiB,CAAC;AAGhD,KAAK,mBAAmB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,MAAM,GAAG,SAAS,CAAC;AAyB1G;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,kBACP,UAAU,eACZ,MAAM,EAAE,cACT,OAAO,oBACD,mBAAmB;;;CA6BxC,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
2
|
+
import { validatePropertyName } from './schemaHelpers.js';
|
|
3
|
+
import { findSchemaAtPath } from './schemaDocument.js';
|
|
4
|
+
import { jsonSchemaToProperties } from './Tree/schemaConversion.js';
|
|
5
|
+
|
|
6
|
+
const toPropertyRows = (level, path) => Object.entries(level.properties ?? {}).map(([name, property], index) => ({
|
|
7
|
+
id: `prop-${path.join('-')}-${index}`,
|
|
8
|
+
name,
|
|
9
|
+
type: property.type || 'string',
|
|
10
|
+
format: property.format,
|
|
11
|
+
description: property.description,
|
|
12
|
+
items: property.items,
|
|
13
|
+
properties: property.properties,
|
|
14
|
+
required: property.required,
|
|
15
|
+
}));
|
|
16
|
+
const rowError = (row, rows, level, custom) => {
|
|
17
|
+
const error = validatePropertyName(row.name ?? '', row.id, rows);
|
|
18
|
+
if (error || !custom)
|
|
19
|
+
return error;
|
|
20
|
+
const property = level.find((candidate) => candidate.name === row.name);
|
|
21
|
+
return property ? custom(property.name, property, level) : undefined;
|
|
22
|
+
};
|
|
23
|
+
const useSchemaRows = (currentSchema, currentPath, isEditMode, customValidator) => {
|
|
24
|
+
const [properties, setProperties] = useState([]);
|
|
25
|
+
const [validationErrors, setValidationErrors] = useState({});
|
|
26
|
+
const validate = useCallback((rows, level) => {
|
|
27
|
+
const errors = {};
|
|
28
|
+
rows.forEach((row) => {
|
|
29
|
+
const error = rowError(row, rows, level, customValidator);
|
|
30
|
+
if (error)
|
|
31
|
+
errors[row.id] = error;
|
|
32
|
+
});
|
|
33
|
+
setValidationErrors(errors);
|
|
34
|
+
}, [customValidator]);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
const level = findSchemaAtPath(currentSchema, currentPath);
|
|
37
|
+
if (!level)
|
|
38
|
+
return;
|
|
39
|
+
const rows = toPropertyRows(level, currentPath);
|
|
40
|
+
setProperties(rows);
|
|
41
|
+
if (isEditMode) {
|
|
42
|
+
validate(rows, jsonSchemaToProperties(level));
|
|
43
|
+
}
|
|
44
|
+
}, [currentPath, currentSchema, isEditMode]);
|
|
45
|
+
return { properties, validationErrors };
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export { useSchemaRows };
|
|
49
|
+
//# sourceMappingURL=useSchemaRows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSchemaRows.js","sources":["../../../SchemaEditor/useSchemaRows.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 { useCallback, useEffect, useState } from 'react';\nimport type { JsonSchema, JsonSchemaProperty } from '../types/JsonSchema';\nimport { validatePropertyName } from './schemaHelpers';\nimport { findSchemaAtPath } from './schemaDocument';\nimport type { Property } from './Tree/Property';\nimport { jsonSchemaToProperties } from './Tree/schemaConversion';\n\ntype CustomNameValidator = (name: string, property: Property, siblings: Property[]) => string | undefined;\n\nconst toPropertyRows = (level: JsonSchema, path: string[]): JsonSchemaProperty[] =>\n Object.entries(level.properties ?? {}).map(([name, property], index) => ({\n id: `prop-${path.join('-')}-${index}`,\n name,\n type: property.type || 'string',\n format: property.format,\n description: property.description,\n items: property.items,\n properties: property.properties,\n // A property's own `required` array (populated when its `type` is \"object\") lists which of *its*\n // properties are required. It is scoped to this property alone — never to the parent schema's\n // `required` array — and is carried through verbatim so navigating into it sees it intact.\n required: property.required,\n }));\n\nconst rowError = (row: JsonSchemaProperty, rows: JsonSchemaProperty[], level: Property[], custom?: CustomNameValidator) => {\n const error = validatePropertyName(row.name ?? '', row.id!, rows);\n if (error || !custom) return error;\n\n const property = level.find((candidate) => candidate.name === row.name);\n return property ? custom(property.name, property, level) : undefined;\n};\n\n/**\n * Derives the rows of the current schema level and, in edit mode, their name validation errors.\n * @param currentSchema The working schema.\n * @param currentPath The drill-down path.\n * @param isEditMode Whether the editor is editing.\n * @param customValidator The host's extra property name check.\n * @returns The rows and the validation error per row id.\n */\nexport const useSchemaRows = (\n currentSchema: JsonSchema,\n currentPath: string[],\n isEditMode: boolean,\n customValidator?: CustomNameValidator,\n) => {\n const [properties, setProperties] = useState<JsonSchemaProperty[]>([]);\n const [validationErrors, setValidationErrors] = useState<Record<string, string>>({});\n\n const validate = useCallback(\n (rows: JsonSchemaProperty[], level: Property[]) => {\n const errors: Record<string, string> = {};\n rows.forEach((row) => {\n const error = rowError(row, rows, level, customValidator);\n if (error) errors[row.id!] = error;\n });\n setValidationErrors(errors);\n },\n [customValidator],\n );\n\n useEffect(() => {\n const level = findSchemaAtPath(currentSchema, currentPath);\n if (!level) return;\n\n const rows = toPropertyRows(level, currentPath);\n setProperties(rows);\n if (isEditMode) {\n validate(rows, jsonSchemaToProperties(level));\n }\n }, [currentPath, currentSchema, isEditMode]);\n\n return { properties, validationErrors };\n};\n"],"names":[],"mappings":";;;;;AAYA,MAAM,cAAc,GAAG,CAAC,KAAiB,EAAE,IAAc,KACrD,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,KAAK,MAAM;IACrE,EAAE,EAAE,CAAA,KAAA,EAAQ,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA,CAAA,EAAI,KAAK,CAAA,CAAE;IACrC,IAAI;AACJ,IAAA,IAAI,EAAE,QAAQ,CAAC,IAAI,IAAI,QAAQ;IAC/B,MAAM,EAAE,QAAQ,CAAC,MAAM;IACvB,WAAW,EAAE,QAAQ,CAAC,WAAW;IACjC,KAAK,EAAE,QAAQ,CAAC,KAAK;IACrB,UAAU,EAAE,QAAQ,CAAC,UAAU;IAI/B,QAAQ,EAAE,QAAQ,CAAC,QAAQ;AAC9B,CAAA,CAAC,CAAC;AAEP,MAAM,QAAQ,GAAG,CAAC,GAAuB,EAAE,IAA0B,EAAE,KAAiB,EAAE,MAA4B,KAAI;AACtH,IAAA,MAAM,KAAK,GAAG,oBAAoB,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,EAAE,GAAG,CAAC,EAAG,EAAE,IAAI,CAAC;IACjE,IAAI,KAAK,IAAI,CAAC,MAAM;AAAE,QAAA,OAAO,KAAK;AAElC,IAAA,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,SAAS,KAAK,SAAS,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,CAAC;AACvE,IAAA,OAAO,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,CAAC,GAAG,SAAS;AACxE,C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