@cratis/components 4.26.4 → 4.28.0
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/Common/CratisComponentsProvider.d.ts +4 -0
- package/dist/esm/Common/CratisComponentsProvider.d.ts.map +1 -1
- package/dist/esm/Common/CratisComponentsProvider.js +1 -0
- package/dist/esm/Common/CratisComponentsProvider.js.map +1 -1
- package/dist/esm/DataPage/DataPage.d.ts +2 -0
- package/dist/esm/DataPage/DataPage.d.ts.map +1 -1
- package/dist/esm/DataPage/DataPage.js.map +1 -1
- package/dist/esm/DataTables/DataTableForObservableQuery.d.ts +2 -0
- package/dist/esm/DataTables/DataTableForObservableQuery.d.ts.map +1 -1
- package/dist/esm/DataTables/DataTableForObservableQuery.js +1 -1
- package/dist/esm/DataTables/DataTableForObservableQuery.js.map +1 -1
- package/dist/esm/DataTables/DataTableForQuery.d.ts +2 -0
- package/dist/esm/DataTables/DataTableForQuery.d.ts.map +1 -1
- package/dist/esm/DataTables/DataTableForQuery.js +1 -1
- package/dist/esm/DataTables/DataTableForQuery.js.map +1 -1
- package/dist/esm/DataTables/PaginatorPageItem.d.ts +13 -0
- package/dist/esm/DataTables/PaginatorPageItem.d.ts.map +1 -0
- package/dist/esm/DataTables/PaginatorPageItem.js +4 -0
- package/dist/esm/DataTables/PaginatorPageItem.js.map +1 -0
- package/dist/esm/DataTables/TablePaginator.d.ts +22 -2
- package/dist/esm/DataTables/TablePaginator.d.ts.map +1 -1
- package/dist/esm/DataTables/TablePaginator.js.map +1 -1
- package/dist/esm/DataTables/TablePaginatorImplementation.d.ts +1 -1
- package/dist/esm/DataTables/TablePaginatorImplementation.d.ts.map +1 -1
- package/dist/esm/DataTables/TablePaginatorImplementation.js +8 -3
- package/dist/esm/DataTables/TablePaginatorImplementation.js.map +1 -1
- package/dist/esm/DataTables/TablePaginatorPages.d.ts +9 -0
- package/dist/esm/DataTables/TablePaginatorPages.d.ts.map +1 -0
- package/dist/esm/DataTables/TablePaginatorPages.js +20 -0
- package/dist/esm/DataTables/TablePaginatorPages.js.map +1 -0
- package/dist/esm/DataTables/index.d.ts +2 -0
- package/dist/esm/DataTables/index.d.ts.map +1 -1
- package/dist/esm/DataTables/index.js +1 -0
- package/dist/esm/DataTables/index.js.map +1 -1
- package/dist/esm/DataTables/paginatorPages.d.ts +15 -0
- package/dist/esm/DataTables/paginatorPages.d.ts.map +1 -0
- package/dist/esm/DataTables/paginatorPages.js +40 -0
- package/dist/esm/DataTables/paginatorPages.js.map +1 -0
- package/dist/esm/Filter/FilterGroup.d.ts +23 -0
- package/dist/esm/Filter/FilterGroup.d.ts.map +1 -0
- package/dist/esm/Filter/FilterGroup.js +51 -0
- package/dist/esm/Filter/FilterGroup.js.map +1 -0
- package/dist/esm/Filter/FilterPanel.d.ts.map +1 -1
- package/dist/esm/Filter/FilterPanel.js +24 -257
- package/dist/esm/Filter/FilterPanel.js.map +1 -1
- package/dist/esm/Filter/FilterSearchBox.d.ts +10 -0
- package/dist/esm/Filter/FilterSearchBox.d.ts.map +1 -0
- package/dist/esm/Filter/FilterSearchBox.js +10 -0
- package/dist/esm/Filter/FilterSearchBox.js.map +1 -0
- package/dist/esm/Filter/measurePanelPlacement.d.ts +31 -0
- package/dist/esm/Filter/measurePanelPlacement.d.ts.map +1 -0
- package/dist/esm/Filter/measurePanelPlacement.js +132 -0
- package/dist/esm/Filter/measurePanelPlacement.js.map +1 -0
- package/dist/esm/Filter/usePanelDismissal.d.ts +32 -0
- package/dist/esm/Filter/usePanelDismissal.d.ts.map +1 -0
- package/dist/esm/Filter/usePanelDismissal.js +63 -0
- package/dist/esm/Filter/usePanelDismissal.js.map +1 -0
- package/dist/esm/Filter/usePanelPosition.d.ts +24 -0
- package/dist/esm/Filter/usePanelPosition.d.ts.map +1 -0
- package/dist/esm/Filter/usePanelPosition.js +85 -0
- package/dist/esm/Filter/usePanelPosition.js.map +1 -0
- package/dist/esm/Filter/useResolvedAnchor.d.ts +17 -0
- package/dist/esm/Filter/useResolvedAnchor.d.ts.map +1 -0
- package/dist/esm/Filter/useResolvedAnchor.js +16 -0
- package/dist/esm/Filter/useResolvedAnchor.js.map +1 -0
- package/dist/esm/PivotViewer/PivotViewer.d.ts.map +1 -1
- package/dist/esm/PivotViewer/PivotViewer.js +47 -207
- package/dist/esm/PivotViewer/PivotViewer.js.map +1 -1
- package/dist/esm/PivotViewer/components/pivot/visibility.d.ts +1 -1
- package/dist/esm/PivotViewer/components/pivot/visibility.d.ts.map +1 -1
- package/dist/esm/PivotViewer/components/pivot/visibility.js +24 -222
- package/dist/esm/PivotViewer/components/pivot/visibility.js.map +1 -1
- package/dist/esm/PivotViewer/components/pivot/visibilityHelpers.d.ts +114 -0
- package/dist/esm/PivotViewer/components/pivot/visibilityHelpers.d.ts.map +1 -0
- package/dist/esm/PivotViewer/components/pivot/visibilityHelpers.js +306 -0
- package/dist/esm/PivotViewer/components/pivot/visibilityHelpers.js.map +1 -0
- package/dist/esm/PivotViewer/hooks/useColorCssVariables.d.ts +9 -0
- package/dist/esm/PivotViewer/hooks/useColorCssVariables.d.ts.map +1 -0
- package/dist/esm/PivotViewer/hooks/useColorCssVariables.js +32 -0
- package/dist/esm/PivotViewer/hooks/useColorCssVariables.js.map +1 -0
- package/dist/esm/PivotViewer/hooks/usePivotViewerGrouping.d.ts +27 -0
- package/dist/esm/PivotViewer/hooks/usePivotViewerGrouping.d.ts.map +1 -0
- package/dist/esm/PivotViewer/hooks/usePivotViewerGrouping.js +40 -0
- package/dist/esm/PivotViewer/hooks/usePivotViewerGrouping.js.map +1 -0
- package/dist/esm/PivotViewer/hooks/usePivotViewerInteractions.d.ts +27 -0
- package/dist/esm/PivotViewer/hooks/usePivotViewerInteractions.d.ts.map +1 -0
- package/dist/esm/PivotViewer/hooks/usePivotViewerInteractions.js +46 -0
- package/dist/esm/PivotViewer/hooks/usePivotViewerInteractions.js.map +1 -0
- package/dist/esm/PivotViewer/hooks/useRawGrouping.d.ts +22 -0
- package/dist/esm/PivotViewer/hooks/useRawGrouping.d.ts.map +1 -0
- package/dist/esm/PivotViewer/hooks/useRawGrouping.js +56 -0
- package/dist/esm/PivotViewer/hooks/useRawGrouping.js.map +1 -0
- package/dist/esm/PivotViewer/hooks/useScrollPositionTracking.d.ts +12 -0
- package/dist/esm/PivotViewer/hooks/useScrollPositionTracking.d.ts.map +1 -0
- package/dist/esm/PivotViewer/hooks/useScrollPositionTracking.js +20 -0
- package/dist/esm/PivotViewer/hooks/useScrollPositionTracking.js.map +1 -0
- package/dist/esm/PivotViewer/hooks/useViewerLayout.d.ts +16 -0
- package/dist/esm/PivotViewer/hooks/useViewerLayout.d.ts.map +1 -0
- package/dist/esm/PivotViewer/hooks/useViewerLayout.js +29 -0
- package/dist/esm/PivotViewer/hooks/useViewerLayout.js.map +1 -0
- package/dist/esm/PivotViewer/hooks/useVisibleIds.d.ts +21 -0
- package/dist/esm/PivotViewer/hooks/useVisibleIds.d.ts.map +1 -0
- package/dist/esm/PivotViewer/hooks/useVisibleIds.js +34 -0
- package/dist/esm/PivotViewer/hooks/useVisibleIds.js.map +1 -0
- package/dist/esm/SchemaEditor/SchemaEditor.d.ts +4 -1
- package/dist/esm/SchemaEditor/SchemaEditor.d.ts.map +1 -1
- package/dist/esm/SchemaEditor/SchemaEditor.js.map +1 -1
- package/dist/esm/SchemaEditor/SchemaEditorLabels.d.ts +6 -0
- package/dist/esm/SchemaEditor/SchemaEditorLabels.d.ts.map +1 -1
- package/dist/esm/SchemaEditor/SchemaEditorLabels.js.map +1 -1
- package/dist/esm/SchemaEditor/Tree/GeneratedToggle.d.ts +11 -0
- package/dist/esm/SchemaEditor/Tree/GeneratedToggle.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/Tree/GeneratedToggle.js +24 -0
- package/dist/esm/SchemaEditor/Tree/GeneratedToggle.js.map +1 -0
- package/dist/esm/SchemaEditor/Tree/Property.d.ts +6 -0
- package/dist/esm/SchemaEditor/Tree/Property.d.ts.map +1 -1
- package/dist/esm/SchemaEditor/Tree/Property.js.map +1 -1
- package/dist/esm/SchemaEditor/Tree/SchemaEditorContext.d.ts +2 -0
- package/dist/esm/SchemaEditor/Tree/SchemaEditorContext.d.ts.map +1 -1
- package/dist/esm/SchemaEditor/Tree/SchemaEditorContext.js.map +1 -1
- package/dist/esm/SchemaEditor/Tree/SchemaEditorParts.d.ts +2 -0
- package/dist/esm/SchemaEditor/Tree/SchemaEditorParts.d.ts.map +1 -1
- package/dist/esm/SchemaEditor/Tree/SchemaEditorParts.js.map +1 -1
- package/dist/esm/SchemaEditor/Tree/SchemaOrderedProperty.d.ts +12 -0
- package/dist/esm/SchemaEditor/Tree/SchemaOrderedProperty.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/Tree/SchemaOrderedProperty.js +13 -0
- package/dist/esm/SchemaEditor/Tree/SchemaOrderedProperty.js.map +1 -0
- package/dist/esm/SchemaEditor/Tree/SchemaPropertyRow.d.ts.map +1 -1
- package/dist/esm/SchemaEditor/Tree/SchemaPropertyRow.js +2 -2
- package/dist/esm/SchemaEditor/Tree/SchemaPropertyRow.js.map +1 -1
- package/dist/esm/SchemaEditor/Tree/TreeSchemaEditor.d.ts +8 -1
- package/dist/esm/SchemaEditor/Tree/TreeSchemaEditor.d.ts.map +1 -1
- package/dist/esm/SchemaEditor/Tree/TreeSchemaEditor.js +15 -11
- package/dist/esm/SchemaEditor/Tree/TreeSchemaEditor.js.map +1 -1
- package/dist/esm/SchemaEditor/Tree/schemaConversion.d.ts +15 -3
- package/dist/esm/SchemaEditor/Tree/schemaConversion.d.ts.map +1 -1
- package/dist/esm/SchemaEditor/Tree/schemaConversion.js +83 -27
- package/dist/esm/SchemaEditor/Tree/schemaConversion.js.map +1 -1
- package/dist/esm/SchemaEditor/Tree/schemaInOriginalOrder.d.ts +3 -0
- package/dist/esm/SchemaEditor/Tree/schemaInOriginalOrder.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/Tree/schemaInOriginalOrder.js +7 -0
- package/dist/esm/SchemaEditor/Tree/schemaInOriginalOrder.js.map +1 -0
- package/dist/esm/SchemaEditor/defaultSchemaEditorLabels.d.ts.map +1 -1
- package/dist/esm/SchemaEditor/defaultSchemaEditorLabels.js +3 -0
- package/dist/esm/SchemaEditor/defaultSchemaEditorLabels.js.map +1 -1
- package/dist/esm/SchemaEditor/index.d.ts +1 -1
- package/dist/esm/SchemaEditor/index.d.ts.map +1 -1
- package/dist/esm/SchemaEditor/index.js +1 -1
- package/dist/esm/configuration/CratisComponentsDefaults.d.ts.map +1 -1
- package/dist/esm/configuration/CratisComponentsDefaults.js +2 -0
- package/dist/esm/configuration/CratisComponentsDefaults.js.map +1 -1
- package/dist/esm/styles.DataPage.css +51 -6
- package/dist/esm/styles.DataTables.css +51 -6
- package/dist/esm/styles.SchemaEditor.css +58 -16
- package/dist/esm/styles.css +58 -16
- package/dist/esm/styles.renderer.builtin.css +51 -6
- package/dist/esm/types/parts.d.ts +6 -2
- package/dist/esm/types/parts.d.ts.map +1 -1
- package/dist/esm/types/parts.js +6 -2
- package/dist/esm/types/parts.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeSchemaEditor.js","sources":["../../../../SchemaEditor/Tree/TreeSchemaEditor.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 { useEffect, useMemo, useRef, useState, type ReactNode } from 'react';\nimport { FaPlus } from 'react-icons/fa6';\nimport type { ChangeHandler } from '../../types/ChangeHandler';\nimport type { JsonSchema } from '../../types/JsonSchema';\nimport type { Property } from './Property';\nimport type { PropertyConcept } from './PropertyConcept';\nimport { useOptionalPropertyConcepts } from './PropertyConceptsContext';\nimport { PropertyType } from './PropertyType';\nimport { findPropertyById } from './propertyTree';\nimport { PropertyTypeMenu } from './PropertyTypeMenu';\nimport {\n addChildProperty,\n addProperty,\n changePropertyType,\n jsonSchemaToProperties,\n propertiesToJsonSchema,\n removeProperty,\n renameProperty,\n setKeyProperty,\n setRequiredProperty,\n} from './schemaConversion';\nimport { SchemaEditorContext, type SchemaEditorContextValue, type SchemaEditorOperations } from './SchemaEditorContext';\nimport type { SchemaEditorLabels } from '../SchemaEditorLabels';\nimport type { SchemaEditorParts } from './SchemaEditorParts';\nimport { resolveSchemaEditorLabels } from '../resolveSchemaEditorLabels';\nimport type { SchemaPropertyContext } from './SchemaPropertyContext';\nimport type { SchemaPropertyRowState } from './SchemaPropertyRowState';\nimport { SchemaPropertyRow } from './SchemaPropertyRow';\nimport { totalPropertyCount } from './propertyTree';\n\n/** The props of the tree layout of the {@link SchemaEditor}. */\nexport interface TreeSchemaEditorProps {\n /**\n * The JSON Schema to edit. The editor converts it, keeps the edited property tree itself and reports every\n * edit through {@link TreeSchemaEditorProps.onChange}. Passing the reported schema back, or the same schema\n * again, changes nothing; passing a schema that differs from both replaces the tree and its property ids.\n * Ignored when `properties` is given.\n */\n schema?: JsonSchema;\n\n /** Called with the complete schema after every edit. Only used when the editor owns the property tree. */\n onChange?: ChangeHandler<JsonSchema>;\n\n /** Called with the property tree after every edit, so a host can follow the ids. Only used when the editor owns the property tree. */\n onPropertiesChange?: (properties: Property[]) => void;\n\n /** Called after a property was removed, with the property and everything nested under it. Only used when the editor owns the property tree. */\n onPropertyRemoved?: (property: Property) => void;\n\n /** Called after a property was renamed, with the renamed property and the name it had. Only used when the editor owns the property tree. */\n onPropertyRenamed?: (property: Property, previousName: string) => void;\n\n /**\n * The property tree to show. When given, the editor is controlled: it changes nothing itself and each edit\n * is offered through the matching `onAddProperty`, `onDeleteProperty`… callback, which the host applies.\n * An edit without a callback is not offered.\n */\n properties?: Property[];\n\n /** Controlled mode: add a property to the root. */\n onAddProperty?: (type: PropertyType, concept?: string) => void;\n\n /** Controlled mode: add a property to a nested object. */\n onAddChildProperty?: (parentId: string, type: PropertyType, concept?: string) => void;\n\n /** Controlled mode: remove a property. */\n onDeleteProperty?: (propertyId: string) => void;\n\n /** Controlled mode: rename a property. The name is already checked. */\n onRenameProperty?: (propertyId: string, name: string) => void;\n\n /** Controlled mode: change the type of a property. */\n onChangePropertyType?: (propertyId: string, type: PropertyType, concept?: string) => void;\n\n /** Controlled mode: make a property the key of its object, or clear it when it already is. */\n onSetKeyProperty?: (propertyId: string) => void;\n\n /** Controlled mode: set whether a property must be present. */\n onSetRequiredProperty?: (propertyId: string, isRequired: boolean) => void;\n\n /**\n * The concepts a property can be typed as, offered after the primitive types. Takes precedence over the\n * concepts of a surrounding {@link PropertyConceptsProvider}.\n */\n concepts?: PropertyConcept[];\n\n /**\n * Offers the key toggle. `true` offers it on every property; a function decides per property, for example\n * `(property, context) => context.depth > 0` to leave the root properties out. Off by default, except in\n * controlled mode, where supplying `onSetKeyProperty` implies `true` unless this is explicitly `false`.\n */\n allowKeyProperty?: boolean | ((property: Property, context: SchemaPropertyContext) => boolean);\n\n /**\n * Offers the toggle for whether a property must be present (the `required` list). Off by default, except in\n * controlled mode, where supplying `onSetRequiredProperty` implies `true` unless this is explicitly `false`.\n */\n allowRequired?: boolean;\n\n /** Offers no edits at all: the tree is shown, and only selection and the host's slots remain. */\n readOnly?: boolean;\n\n /** Decides which properties can be neither renamed nor removed. By default none. */\n isPropertyProtected?: (property: Property) => boolean;\n\n /**\n * Extra check of a new name, after the editor has rejected blank, reserved and duplicate names.\n * Return the message to show, or `undefined` to accept the name.\n */\n validatePropertyName?: (name: string, property: Property, siblings: Property[]) => string | undefined;\n\n /** The id of the property to mark as selected. */\n selectedPropertyId?: string | null;\n\n /** Called when a property's row is clicked, or its name is activated from the keyboard. */\n onPropertyClick?: (propertyId: string) => void;\n\n /** Content above the properties, for example the title of the schema. Rendered inside the editor's root, so a host that needs a full-bleed header places its own outside the editor. */\n header?: ReactNode;\n\n /** Content beside the add button, for example further actions. */\n footer?: ReactNode;\n\n /** Content at the start of every row, before the name; for example a connector to drag from or onto. */\n renderPropertyLeading?: (property: Property, context: SchemaPropertyContext) => ReactNode;\n\n /** Content at the end of every row, before the remove button; for example a button that opens rules. */\n renderPropertyAccessory?: (property: Property, context: SchemaPropertyContext) => ReactNode;\n\n /** Content under every row, above its nested properties; for example the rules of the property. Nothing is rendered for `null`, `undefined` and `false`. */\n renderPropertyDetails?: (property: Property, context: SchemaPropertyContext) => ReactNode;\n\n /** Styles and marks the row of a property: extra class names, `data-*` attributes, a tooltip, and whether its type is locked. */\n getPropertyRowState?: (property: Property, context: SchemaPropertyContext) => SchemaPropertyRowState | undefined;\n\n /**\n * Replaces or wraps the badge that shows a property's type. Receives the badge the editor would render, so a\n * host can return it unchanged, wrap it, or render something else. The badge carries `data-property-type`\n * for styling per type.\n */\n renderPropertyTypeBadge?: (property: Property, context: SchemaPropertyContext, defaultBadge: ReactNode) => ReactNode;\n\n /** Replaces any of the editor's strings. Unset ones stay English. */\n labels?: Partial<SchemaEditorLabels>;\n\n /** Accessible name of the editor. Defaults to the `schema` label. */\n 'aria-label'?: string;\n\n /** Id of the element that names the editor. */\n 'aria-labelledby'?: string;\n\n /** Extra class name for the root. */\n className?: string;\n\n /** Attributes for the stable parts of the editor. */\n pt?: SchemaEditorParts;\n}\n\nconst never = () => false;\n\n/**\n * The tree layout of the {@link SchemaEditor} (`layout='tree'`). Edits the properties of a JSON Schema as a tree: names, types, nested objects and lists of objects, and\n * optionally concepts, the key, and whether a property is required.\n *\n * Pass a `schema` and the editor keeps the tree and reports the resulting schema, or pass `properties` and\n * handle each edit yourself. Everything specific to a product — rules, mapping connectors, its own chrome — is\n * attached through the slots (`header`, `footer`, `renderPropertyLeading`, `renderPropertyAccessory`,\n * `renderPropertyDetails`, `renderPropertyTypeBadge`) and `getPropertyRowState`.\n */\nexport const TreeSchemaEditor = ({\n schema,\n onChange,\n onPropertiesChange,\n onPropertyRemoved,\n onPropertyRenamed,\n properties: controlledProperties,\n onAddProperty,\n onAddChildProperty,\n onDeleteProperty,\n onRenameProperty,\n onChangePropertyType,\n onSetKeyProperty,\n onSetRequiredProperty,\n concepts: suppliedConcepts,\n allowKeyProperty,\n allowRequired,\n readOnly = false,\n isPropertyProtected,\n validatePropertyName,\n selectedPropertyId,\n onPropertyClick,\n header,\n footer,\n renderPropertyLeading,\n renderPropertyAccessory,\n renderPropertyDetails,\n getPropertyRowState,\n renderPropertyTypeBadge,\n labels: suppliedLabels,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n className,\n pt,\n}: TreeSchemaEditorProps) => {\n const labels = useMemo(() => resolveSchemaEditorLabels(suppliedLabels), [suppliedLabels]);\n const providedConcepts = useOptionalPropertyConcepts();\n const concepts = suppliedConcepts ?? providedConcepts;\n const isControlled = controlledProperties !== undefined;\n const [ownedProperties, setOwnedProperties] = useState<Property[]>(() => jsonSchemaToProperties(schema));\n // The latest tree, kept synchronously so two edits in one event apply one after the other.\n const latest = useRef(ownedProperties);\n useEffect(() => { latest.current = ownedProperties; }, [ownedProperties]);\n const properties = isControlled ? controlledProperties : ownedProperties;\n\n // A schema from outside replaces the tree only when it says something the editor does not already show:\n // handing back what was reported, or the same schema again, must not throw away the property ids.\n const incomingSchema = schema === undefined ? undefined : JSON.stringify(schema);\n const [seenSchema, setSeenSchema] = useState(incomingSchema);\n if (!isControlled && incomingSchema !== seenSchema) {\n setSeenSchema(incomingSchema);\n if (schema !== undefined && incomingSchema !== JSON.stringify(propertiesToJsonSchema(ownedProperties))) {\n setOwnedProperties(jsonSchemaToProperties(schema));\n }\n }\n\n const apply = (next: Property[]) => {\n latest.current = next;\n setOwnedProperties(next);\n onChange?.(propertiesToJsonSchema(next), { source: 'user' });\n onPropertiesChange?.(next);\n };\n\n const ownedOperations: SchemaEditorOperations = {\n addChild: (parentId, type, concept) =>\n apply(addChildProperty(latest.current, parentId, type, totalPropertyCount(latest.current), concept)),\n remove: propertyId => {\n const removed = findPropertyById(latest.current, propertyId);\n apply(removeProperty(latest.current, propertyId));\n if (removed) onPropertyRemoved?.(removed);\n },\n rename: (propertyId, name) => {\n const previousName = findPropertyById(latest.current, propertyId)?.name;\n const next = renameProperty(latest.current, propertyId, name);\n apply(next);\n const renamed = findPropertyById(next, propertyId);\n if (renamed && previousName !== undefined) onPropertyRenamed?.(renamed, previousName);\n },\n changeType: (propertyId, type, concept) => apply(changePropertyType(latest.current, propertyId, type, concept)),\n setKey: propertyId => apply(setKeyProperty(latest.current, propertyId)),\n setRequired: (propertyId, isRequired) => apply(setRequiredProperty(latest.current, propertyId, isRequired)),\n };\n\n const controlledOperations: SchemaEditorOperations = {\n addChild: onAddChildProperty,\n remove: onDeleteProperty,\n rename: onRenameProperty,\n changeType: onChangePropertyType,\n setKey: onSetKeyProperty,\n setRequired: onSetRequiredProperty,\n };\n\n const operations = isControlled ? controlledOperations : ownedOperations;\n const addRoot = isControlled\n ? onAddProperty\n : (type: PropertyType, concept?: string) =>\n apply(addProperty(latest.current, type, totalPropertyCount(latest.current), concept));\n\n // In controlled mode a toggle callback implies its allow flag, unless the host set the flag to false.\n const keyAllowance = allowKeyProperty ?? (isControlled && onSetKeyProperty !== undefined);\n const isKeyAllowed = typeof keyAllowance === 'function'\n ? keyAllowance\n : keyAllowance ? () => true : never;\n const isRequiredAllowed = allowRequired ?? (isControlled && onSetRequiredProperty !== undefined);\n\n const contextValue: SchemaEditorContextValue = {\n labels,\n parts: pt,\n properties,\n concepts,\n readOnly,\n operations,\n selectedPropertyId,\n onPropertyClick,\n isKeyAllowed,\n isRequiredAllowed,\n isProtected: isPropertyProtected ?? never,\n validateName: validatePropertyName,\n getRowState: getPropertyRowState,\n renderLeading: renderPropertyLeading,\n renderAccessory: renderPropertyAccessory,\n renderDetails: renderPropertyDetails,\n renderTypeBadge: renderPropertyTypeBadge,\n };\n\n return (\n <SchemaEditorContext.Provider value={contextValue}>\n <div\n {...pt?.root}\n role='group'\n aria-label={ariaLabelledBy ? undefined : ariaLabel ?? labels.schema}\n aria-labelledby={ariaLabelledBy}\n className={['cratis-schema-editor', pt?.root?.className, className].filter(Boolean).join(' ')}\n data-cratis-part='root'\n data-readonly={readOnly || undefined}\n >\n {header && (\n <div {...pt?.header} className={`cratis-schema-editor__header ${pt?.header?.className ?? ''}`} data-cratis-part='header'>\n {header}\n </div>\n )}\n\n {properties.length === 0 ? (\n <p {...pt?.empty} className={`cratis-schema-editor__empty ${pt?.empty?.className ?? ''}`} data-cratis-part='empty'>\n {labels.emptyMessage}\n </p>\n ) : (\n <ul {...pt?.list} className={`cratis-schema-editor__list ${pt?.list?.className ?? ''}`} data-cratis-part='list'>\n {properties.map(property => (\n <SchemaPropertyRow key={property.id} property={property} siblings={properties} depth={0} />\n ))}\n </ul>\n )}\n\n {(footer || (!readOnly && addRoot)) && (\n <div className='cratis-schema-editor__actions'>\n {!readOnly && addRoot && (\n <PropertyTypeMenu\n labels={labels}\n concepts={concepts}\n triggerPart='add'\n triggerLabel={labels.addProperty}\n parts={pt}\n onSelect={addRoot}\n >\n <FaPlus aria-hidden='true' />\n {labels.addProperty}\n </PropertyTypeMenu>\n )}\n {footer && (\n <div {...pt?.footer} className={`cratis-schema-editor__footer ${pt?.footer?.className ?? ''}`} data-cratis-part='footer'>\n {footer}\n </div>\n )}\n </div>\n )}\n </div>\n </SchemaEditorContext.Provider>\n );\n};\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;;;;;;AAiKA,MAAM,KAAK,GAAG,MAAM,KAAK;AAWlB,MAAM,gBAAgB,GAAG,CAAC,EAC7B,MAAM,EACN,QAAQ,EACR,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EAAE,oBAAoB,EAChC,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,EACrB,QAAQ,EAAE,gBAAgB,EAC1B,gBAAgB,EAChB,aAAa,EACb,QAAQ,GAAG,KAAK,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EACf,MAAM,EACN,MAAM,EACN,qBAAqB,EACrB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,"file":"TreeSchemaEditor.js","sources":["../../../../SchemaEditor/Tree/TreeSchemaEditor.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 { useEffect, useMemo, useRef, useState, type ReactNode } from 'react';\nimport { FaPlus } from 'react-icons/fa6';\nimport type { ChangeHandler } from '../../types/ChangeHandler';\nimport type { JsonSchema } from '../../types/JsonSchema';\nimport type { Property } from './Property';\nimport type { PropertyConcept } from './PropertyConcept';\nimport { useOptionalPropertyConcepts } from './PropertyConceptsContext';\nimport { PropertyType } from './PropertyType';\nimport { findPropertyById } from './propertyTree';\nimport { PropertyTypeMenu } from './PropertyTypeMenu';\nimport {\n addChildProperty,\n addProperty,\n changePropertyType,\n jsonSchemaToProperties,\n propertiesToJsonSchema,\n removeProperty,\n renameProperty,\n setKeyProperty,\n setGeneratedProperty,\n setRequiredProperty,\n} from './schemaConversion';\nimport { SchemaEditorContext, type SchemaEditorContextValue, type SchemaEditorOperations } from './SchemaEditorContext';\nimport type { SchemaEditorLabels } from '../SchemaEditorLabels';\nimport type { SchemaEditorParts } from './SchemaEditorParts';\nimport { resolveSchemaEditorLabels } from '../resolveSchemaEditorLabels';\nimport type { SchemaPropertyContext } from './SchemaPropertyContext';\nimport type { SchemaPropertyRowState } from './SchemaPropertyRowState';\nimport { SchemaPropertyRow } from './SchemaPropertyRow';\nimport { totalPropertyCount } from './propertyTree';\n\n/** The props of the tree layout of the {@link SchemaEditor}. */\nexport interface TreeSchemaEditorProps {\n /**\n * The JSON Schema to edit. The editor converts it, keeps the edited property tree itself and reports every\n * edit through {@link TreeSchemaEditorProps.onChange}. Passing the reported schema back, or the same schema\n * again, changes nothing; passing a schema that differs from both replaces the tree and its property ids.\n * Ignored when `properties` is given.\n */\n schema?: JsonSchema;\n\n /** Called with the complete schema after every edit. Only used when the editor owns the property tree. */\n onChange?: ChangeHandler<JsonSchema>;\n\n /** Called with the property tree after every edit, so a host can follow the ids. Only used when the editor owns the property tree. */\n onPropertiesChange?: (properties: Property[]) => void;\n\n /** Called after a property was removed, with the property and everything nested under it. Only used when the editor owns the property tree. */\n onPropertyRemoved?: (property: Property) => void;\n\n /** Called after a property was renamed, with the renamed property and the name it had. Only used when the editor owns the property tree. */\n onPropertyRenamed?: (property: Property, previousName: string) => void;\n\n /**\n * The property tree to show. When given, the editor is controlled: it changes nothing itself and each edit\n * is offered through the matching `onAddProperty`, `onDeleteProperty`… callback, which the host applies.\n * An edit without a callback is not offered.\n */\n properties?: Property[];\n\n /** Controlled mode: add a property to the root. */\n onAddProperty?: (type: PropertyType, concept?: string) => void;\n\n /** Controlled mode: add a property to a nested object. */\n onAddChildProperty?: (parentId: string, type: PropertyType, concept?: string) => void;\n\n /** Controlled mode: remove a property. */\n onDeleteProperty?: (propertyId: string) => void;\n\n /** Controlled mode: rename a property. The name is already checked. */\n onRenameProperty?: (propertyId: string, name: string) => void;\n\n /** Controlled mode: change the type of a property. */\n onChangePropertyType?: (propertyId: string, type: PropertyType, concept?: string) => void;\n\n /** Controlled mode: make a property the key of its object, or clear it when it already is. */\n onSetKeyProperty?: (propertyId: string) => void;\n\n /** Controlled mode: set whether a property's value is generated. Implies allowGeneratedProperty unless explicitly false. */\n onSetGeneratedProperty?: (propertyId: string, isGenerated: boolean) => void;\n\n /** Controlled mode: set whether a property must be present. */\n onSetRequiredProperty?: (propertyId: string, isRequired: boolean) => void;\n\n /**\n * The concepts a property can be typed as, offered after the primitive types. Takes precedence over the\n * concepts of a surrounding {@link PropertyConceptsProvider}.\n */\n concepts?: PropertyConcept[];\n\n /**\n * Offers the key toggle. `true` offers it on every property; a function decides per property, for example\n * `(property, context) => context.depth > 0` to leave the root properties out. Off by default, except in\n * controlled mode, where supplying `onSetKeyProperty` implies `true` unless this is explicitly `false`.\n */\n allowKeyProperty?: boolean | ((property: Property, context: SchemaPropertyContext) => boolean);\n\n /**\n * Offers the Generated toggle on every property, or on properties accepted by the predicate. Off by default;\n * a controlled onSetGeneratedProperty callback implies true unless explicitly false. The table layout ignores it.\n */\n allowGeneratedProperty?: boolean | ((property: Property, context: SchemaPropertyContext) => boolean);\n\n /**\n * Offers the toggle for whether a property must be present (the `required` list). Off by default, except in\n * controlled mode, where supplying `onSetRequiredProperty` implies `true` unless this is explicitly `false`.\n */\n allowRequired?: boolean;\n\n /** Offers no edits at all: the tree is shown, and only selection and the host's slots remain. */\n readOnly?: boolean;\n\n /** Decides which properties can be neither renamed nor removed. By default none. */\n isPropertyProtected?: (property: Property) => boolean;\n\n /**\n * Extra check of a new name, after the editor has rejected blank, reserved and duplicate names.\n * Return the message to show, or `undefined` to accept the name.\n */\n validatePropertyName?: (name: string, property: Property, siblings: Property[]) => string | undefined;\n\n /** The id of the property to mark as selected. */\n selectedPropertyId?: string | null;\n\n /** Called when a property's row is clicked, or its name is activated from the keyboard. */\n onPropertyClick?: (propertyId: string) => void;\n\n /** Content above the properties, for example the title of the schema. Rendered inside the editor's root, so a host that needs a full-bleed header places its own outside the editor. */\n header?: ReactNode;\n\n /** Content beside the add button, for example further actions. */\n footer?: ReactNode;\n\n /** Content at the start of every row, before the name; for example a connector to drag from or onto. */\n renderPropertyLeading?: (property: Property, context: SchemaPropertyContext) => ReactNode;\n\n /** Content at the end of every row, before the remove button; for example a button that opens rules. */\n renderPropertyAccessory?: (property: Property, context: SchemaPropertyContext) => ReactNode;\n\n /** Content under every row, above its nested properties; for example the rules of the property. Nothing is rendered for `null`, `undefined` and `false`. */\n renderPropertyDetails?: (property: Property, context: SchemaPropertyContext) => ReactNode;\n\n /** Styles and marks the row of a property: extra class names, `data-*` attributes, a tooltip, and whether its type is locked. */\n getPropertyRowState?: (property: Property, context: SchemaPropertyContext) => SchemaPropertyRowState | undefined;\n\n /**\n * Replaces or wraps the badge that shows a property's type. Receives the badge the editor would render, so a\n * host can return it unchanged, wrap it, or render something else. The badge carries `data-property-type`\n * for styling per type.\n */\n renderPropertyTypeBadge?: (property: Property, context: SchemaPropertyContext, defaultBadge: ReactNode) => ReactNode;\n\n /** Replaces any of the editor's strings. Unset ones stay English. */\n labels?: Partial<SchemaEditorLabels>;\n\n /** Accessible name of the editor. Defaults to the `schema` label. */\n 'aria-label'?: string;\n\n /** Id of the element that names the editor. */\n 'aria-labelledby'?: string;\n\n /** Extra class name for the root. */\n className?: string;\n\n /** Attributes for the stable parts of the editor. */\n pt?: SchemaEditorParts;\n}\n\nconst never = () => false;\n\nfunction allowance(flag: TreeSchemaEditorProps['allowKeyProperty'], callback: unknown, isControlled: boolean) {\n const allowed = flag ?? (isControlled && callback !== undefined);\n if (typeof allowed === 'function') return allowed;\n return allowed ? () => true : never;\n}\n\n/**\n * The tree layout of the {@link SchemaEditor} (`layout='tree'`). Edits the properties of a JSON Schema as a tree: names, types, nested objects and lists of objects, and\n * optionally concepts, the key, and whether a property is required.\n *\n * Pass a `schema` and the editor keeps the tree and reports the resulting schema, or pass `properties` and\n * handle each edit yourself. Everything specific to a product — rules, mapping connectors, its own chrome — is\n * attached through the slots (`header`, `footer`, `renderPropertyLeading`, `renderPropertyAccessory`,\n * `renderPropertyDetails`, `renderPropertyTypeBadge`) and `getPropertyRowState`.\n */\nexport const TreeSchemaEditor = ({\n schema,\n onChange,\n onPropertiesChange,\n onPropertyRemoved,\n onPropertyRenamed,\n properties: controlledProperties,\n onAddProperty,\n onAddChildProperty,\n onDeleteProperty,\n onRenameProperty,\n onChangePropertyType,\n onSetKeyProperty,\n onSetGeneratedProperty,\n onSetRequiredProperty,\n concepts: suppliedConcepts,\n allowKeyProperty,\n allowGeneratedProperty,\n allowRequired,\n readOnly = false,\n isPropertyProtected,\n validatePropertyName,\n selectedPropertyId,\n onPropertyClick,\n header,\n footer,\n renderPropertyLeading,\n renderPropertyAccessory,\n renderPropertyDetails,\n getPropertyRowState,\n renderPropertyTypeBadge,\n labels: suppliedLabels,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n className,\n pt,\n}: TreeSchemaEditorProps) => {\n const labels = useMemo(() => resolveSchemaEditorLabels(suppliedLabels), [suppliedLabels]);\n const providedConcepts = useOptionalPropertyConcepts();\n const concepts = suppliedConcepts ?? providedConcepts;\n const isControlled = controlledProperties !== undefined;\n const [ownedProperties, setOwnedProperties] = useState<Property[]>(() => jsonSchemaToProperties(schema));\n // The latest tree, kept synchronously so two edits in one event apply one after the other.\n const latest = useRef(ownedProperties);\n useEffect(() => { latest.current = ownedProperties; }, [ownedProperties]);\n const properties = isControlled ? controlledProperties : ownedProperties;\n\n // A schema from outside replaces the tree only when it says something the editor does not already show:\n // handing back what was reported, or the same schema again, must not throw away the property ids.\n const incomingSchema = schema === undefined ? undefined : JSON.stringify(schema);\n const [seenSchema, setSeenSchema] = useState(incomingSchema);\n if (!isControlled && incomingSchema !== seenSchema) {\n setSeenSchema(incomingSchema);\n if (schema !== undefined && incomingSchema !== JSON.stringify(propertiesToJsonSchema(ownedProperties, schema))) {\n setOwnedProperties(jsonSchemaToProperties(schema));\n }\n }\n\n const apply = (next: Property[]) => {\n latest.current = next;\n setOwnedProperties(next);\n onChange?.(propertiesToJsonSchema(next, schema), { source: 'user' });\n onPropertiesChange?.(next);\n };\n\n const ownedOperations: SchemaEditorOperations = {\n addChild: (parentId, type, concept) =>\n apply(addChildProperty(latest.current, parentId, type, totalPropertyCount(latest.current), concept)),\n remove: propertyId => {\n const removed = findPropertyById(latest.current, propertyId);\n apply(removeProperty(latest.current, propertyId));\n if (removed) onPropertyRemoved?.(removed);\n },\n rename: (propertyId, name) => {\n const previousName = findPropertyById(latest.current, propertyId)?.name;\n const next = renameProperty(latest.current, propertyId, name);\n apply(next);\n const renamed = findPropertyById(next, propertyId);\n if (renamed && previousName !== undefined) onPropertyRenamed?.(renamed, previousName);\n },\n changeType: (propertyId, type, concept) => apply(changePropertyType(latest.current, propertyId, type, concept)),\n setKey: propertyId => apply(setKeyProperty(latest.current, propertyId)),\n setGenerated: (propertyId, isGenerated) => apply(setGeneratedProperty(latest.current, propertyId, isGenerated)),\n setRequired: (propertyId, isRequired) => apply(setRequiredProperty(latest.current, propertyId, isRequired)),\n };\n\n const controlledOperations: SchemaEditorOperations = {\n addChild: onAddChildProperty,\n remove: onDeleteProperty,\n rename: onRenameProperty,\n changeType: onChangePropertyType,\n setKey: onSetKeyProperty,\n setGenerated: onSetGeneratedProperty,\n setRequired: onSetRequiredProperty,\n };\n\n const operations = isControlled ? controlledOperations : ownedOperations;\n const addRoot = isControlled\n ? onAddProperty\n : (type: PropertyType, concept?: string) =>\n apply(addProperty(latest.current, type, totalPropertyCount(latest.current), concept));\n\n const contextValue: SchemaEditorContextValue = {\n labels,\n parts: pt,\n properties,\n concepts,\n readOnly,\n operations,\n selectedPropertyId,\n onPropertyClick,\n isKeyAllowed: allowance(allowKeyProperty, onSetKeyProperty, isControlled),\n isGeneratedAllowed: allowance(allowGeneratedProperty, onSetGeneratedProperty, isControlled),\n isRequiredAllowed: allowRequired ?? (isControlled && onSetRequiredProperty !== undefined),\n isProtected: isPropertyProtected ?? never,\n validateName: validatePropertyName,\n getRowState: getPropertyRowState,\n renderLeading: renderPropertyLeading,\n renderAccessory: renderPropertyAccessory,\n renderDetails: renderPropertyDetails,\n renderTypeBadge: renderPropertyTypeBadge,\n };\n\n return (\n <SchemaEditorContext.Provider value={contextValue}>\n <div\n {...pt?.root}\n role='group'\n aria-label={ariaLabelledBy ? undefined : ariaLabel ?? labels.schema}\n aria-labelledby={ariaLabelledBy}\n className={['cratis-schema-editor', pt?.root?.className, className].filter(Boolean).join(' ')}\n data-cratis-part='root'\n data-readonly={readOnly || undefined}\n >\n {header && (\n <div {...pt?.header} className={`cratis-schema-editor__header ${pt?.header?.className ?? ''}`} data-cratis-part='header'>\n {header}\n </div>\n )}\n\n {properties.length === 0 ? (\n <p {...pt?.empty} className={`cratis-schema-editor__empty ${pt?.empty?.className ?? ''}`} data-cratis-part='empty'>\n {labels.emptyMessage}\n </p>\n ) : (\n <ul {...pt?.list} className={`cratis-schema-editor__list ${pt?.list?.className ?? ''}`} data-cratis-part='list'>\n {properties.map(property => (\n <SchemaPropertyRow key={property.id} property={property} siblings={properties} depth={0} />\n ))}\n </ul>\n )}\n\n {(footer || (!readOnly && addRoot)) && (\n <div className='cratis-schema-editor__actions'>\n {!readOnly && addRoot && (\n <PropertyTypeMenu\n labels={labels}\n concepts={concepts}\n triggerPart='add'\n triggerLabel={labels.addProperty}\n parts={pt}\n onSelect={addRoot}\n >\n <FaPlus aria-hidden='true' />\n {labels.addProperty}\n </PropertyTypeMenu>\n )}\n {footer && (\n <div {...pt?.footer} className={`cratis-schema-editor__footer ${pt?.footer?.className ?? ''}`} data-cratis-part='footer'>\n {footer}\n </div>\n )}\n </div>\n )}\n </div>\n </SchemaEditorContext.Provider>\n );\n};\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;;;;;;AA2KA,MAAM,KAAK,GAAG,MAAM,KAAK;AAEzB,SAAS,SAAS,CAAC,IAA+C,EAAE,QAAiB,EAAE,YAAqB,EAAA;IACxG,MAAM,OAAO,GAAG,IAAI,KAAK,YAAY,IAAI,QAAQ,KAAK,SAAS,CAAC;IAChE,IAAI,OAAO,OAAO,KAAK,UAAU;AAAE,QAAA,OAAO,OAAO;AACjD,IAAA,OAAO,OAAO,GAAG,MAAM,IAAI,GAAG,KAAK;AACvC;AAWO,MAAM,gBAAgB,GAAG,CAAC,EAC7B,MAAM,EACN,QAAQ,EACR,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EAAE,oBAAoB,EAChC,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,EACrB,QAAQ,EAAE,gBAAgB,EAC1B,gBAAgB,EAChB,sBAAsB,EACtB,aAAa,EACb,QAAQ,GAAG,KAAK,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EACf,MAAM,EACN,MAAM,EACN,qBAAqB,EACrB,uBAAuB,EACvB,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M,EAAA,CACL,CACT,CAAA,EAAA,CACC,CACT,CAAA,EAAA,CACC,EAAA,CACqB;AAEvC;;"}
|
|
@@ -12,6 +12,8 @@ export declare const CONCEPT_KEYWORD = "x-concept";
|
|
|
12
12
|
* property; at most one property of an object carries it.
|
|
13
13
|
*/
|
|
14
14
|
export declare const KEY_KEYWORD = "x-key";
|
|
15
|
+
/** The JSON Schema keyword marking a value generated when the command runs rather than entered. */
|
|
16
|
+
export declare const GENERATED_KEYWORD = "x-generated";
|
|
15
17
|
/**
|
|
16
18
|
* Converts a JSON Schema object into a property tree. Generates a new id for every property.
|
|
17
19
|
* @param schema The schema to read; `undefined` and schemas without properties give an empty tree.
|
|
@@ -20,11 +22,13 @@ export declare const KEY_KEYWORD = "x-key";
|
|
|
20
22
|
export declare function jsonSchemaToProperties(schema: JsonSchema | undefined): Property[];
|
|
21
23
|
/**
|
|
22
24
|
* Converts a property tree into a JSON Schema object. Empty `required` lists are omitted, and a property
|
|
23
|
-
* typed as a concept or marked as the key carries the `x-concept` and `x-key` keywords.
|
|
25
|
+
* typed as a concept or marked as the key carries the `x-concept` and `x-key` keywords. Vendor keywords are
|
|
26
|
+
* preserved on properties and array items; generated values carry `x-generated: true`.
|
|
24
27
|
* @param properties The root properties.
|
|
28
|
+
* @param base The incoming schema. Root keys other than type, properties and required are preserved.
|
|
25
29
|
* @returns The schema.
|
|
26
30
|
*/
|
|
27
|
-
export declare function propertiesToJsonSchema(properties: Property[]): JsonSchema;
|
|
31
|
+
export declare function propertiesToJsonSchema(properties: Property[], base?: JsonSchema): JsonSchema;
|
|
28
32
|
/**
|
|
29
33
|
* Appends a property to the root.
|
|
30
34
|
* @param properties The root properties.
|
|
@@ -61,7 +65,7 @@ export declare function removeProperty(properties: Property[], targetId: string)
|
|
|
61
65
|
export declare function renameProperty(properties: Property[], targetId: string, newName: string): Property[];
|
|
62
66
|
/**
|
|
63
67
|
* Changes the type of a property. Choosing a plain primitive drops the concept; choosing an object or
|
|
64
|
-
* object list keeps the children, and any other type drops them.
|
|
68
|
+
* object list keeps the children, and any other type drops them. A different item kind clears item metadata.
|
|
65
69
|
* @param properties The root properties.
|
|
66
70
|
* @param targetId The id of the property.
|
|
67
71
|
* @param newType The new type.
|
|
@@ -84,6 +88,14 @@ export declare function toggleRequiredProperty(properties: Property[], targetId:
|
|
|
84
88
|
* @returns The new tree.
|
|
85
89
|
*/
|
|
86
90
|
export declare function setRequiredProperty(properties: Property[], targetId: string, isRequired: boolean): Property[];
|
|
91
|
+
/**
|
|
92
|
+
* Sets whether a property's value is generated. An explicit edit replaces any non-true x-generated value.
|
|
93
|
+
* @param properties The root properties.
|
|
94
|
+
* @param targetId The id of the property.
|
|
95
|
+
* @param isGenerated Whether the value is generated.
|
|
96
|
+
* @returns The new tree.
|
|
97
|
+
*/
|
|
98
|
+
export declare function setGeneratedProperty(properties: Property[], targetId: string, isGenerated: boolean): Property[];
|
|
87
99
|
/**
|
|
88
100
|
* Makes a property the key of its parent object, moving the key when a sibling held it. Choosing the
|
|
89
101
|
* property that already is the key clears it, so an object can also have no key.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaConversion.d.ts","sourceRoot":"","sources":["../../../../SchemaEditor/Tree/schemaConversion.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAsB,MAAM,2BAAwB,CAAC;AAC7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAY,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"schemaConversion.d.ts","sourceRoot":"","sources":["../../../../SchemaEditor/Tree/schemaConversion.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAsB,MAAM,2BAAwB,CAAC;AAC7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAY,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAgB,CAAC;AAM9C;;;;GA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,EAAE,QAAQ,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,QAAQ,EAAE,CAE3F;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,QAAQ,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,GAAG,QAAQ,EAAE,CAE7G;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,QAAQ,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,GAAG,QAAQ,EAAE,CAQ/G;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,QAAQ,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,QAAQ,EAAE,CAOnF"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { PropertyType } from './PropertyType.js';
|
|
2
2
|
import { uniquePropertyName, conceptPropertyName } from './propertyNaming.js';
|
|
3
3
|
import { findPropertyById } from './propertyTree.js';
|
|
4
|
+
import { copySchemaKeywordOrder, schemaKeywordOrder, itemSchemaKeywordOrder } from './SchemaOrderedProperty.js';
|
|
5
|
+
import { schemaInOriginalOrder } from './schemaInOriginalOrder.js';
|
|
4
6
|
|
|
5
7
|
const CONCEPT_KEYWORD = 'x-concept';
|
|
6
8
|
const KEY_KEYWORD = 'x-key';
|
|
9
|
+
const GENERATED_KEYWORD = 'x-generated';
|
|
7
10
|
const isComplex = (type) => type === PropertyType.Object || type === PropertyType.ObjectArray;
|
|
8
11
|
const identifier = () => Math.random().toString(36).slice(2, 10) + Math.random().toString(36).slice(2, 6);
|
|
9
12
|
function schemaPropertyType(value) {
|
|
@@ -32,32 +35,57 @@ function schemaPropertyType(value) {
|
|
|
32
35
|
return PropertyType.String;
|
|
33
36
|
}
|
|
34
37
|
}
|
|
38
|
+
function vendorKeywords(node, isProperty) {
|
|
39
|
+
const entries = Object.entries(node).filter(([name, value]) => {
|
|
40
|
+
if (!name.startsWith('x-'))
|
|
41
|
+
return false;
|
|
42
|
+
if (!isProperty)
|
|
43
|
+
return true;
|
|
44
|
+
return name !== CONCEPT_KEYWORD && name !== KEY_KEYWORD && !(name === GENERATED_KEYWORD && value === true);
|
|
45
|
+
});
|
|
46
|
+
return entries.length > 0 ? Object.fromEntries(entries) : undefined;
|
|
47
|
+
}
|
|
48
|
+
function readItemKeywords(node) {
|
|
49
|
+
if (node.type !== 'array' || typeof node.items !== 'object' || node.items === null)
|
|
50
|
+
return {};
|
|
51
|
+
const items = node.items;
|
|
52
|
+
const keywords = vendorKeywords(items, false);
|
|
53
|
+
return { [itemSchemaKeywordOrder]: Object.keys(items), ...(keywords ? { itemVendorKeywords: keywords } : {}) };
|
|
54
|
+
}
|
|
55
|
+
function readFlags(node, isRequired) {
|
|
56
|
+
const keywords = vendorKeywords(node, true);
|
|
57
|
+
return {
|
|
58
|
+
[schemaKeywordOrder]: Object.keys(node),
|
|
59
|
+
...readItemKeywords(node),
|
|
60
|
+
...(keywords ? { vendorKeywords: keywords } : {}),
|
|
61
|
+
...(node[GENERATED_KEYWORD] === true ? { isGenerated: true } : {}),
|
|
62
|
+
...(isRequired ? { isRequired: true } : {}),
|
|
63
|
+
...(node[KEY_KEYWORD] === true ? { isKey: true } : {}),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
35
66
|
function schemaPropertyToProperty(name, value, required) {
|
|
36
67
|
const node = value;
|
|
37
68
|
const type = schemaPropertyType(node);
|
|
38
69
|
const concept = node[CONCEPT_KEYWORD];
|
|
39
|
-
const flags =
|
|
40
|
-
...(required.has(name) ? { isRequired: true } : {}),
|
|
41
|
-
...(node[KEY_KEYWORD] === true ? { isKey: true } : {}),
|
|
42
|
-
};
|
|
70
|
+
const flags = readFlags(node, required.has(name));
|
|
43
71
|
const container = (type === PropertyType.Object ? node : type === PropertyType.ObjectArray ? node.items : undefined);
|
|
44
72
|
if (container?.properties) {
|
|
45
73
|
const childRequired = new Set(container.required ?? []);
|
|
46
|
-
return {
|
|
74
|
+
return copySchemaKeywordOrder(flags, {
|
|
47
75
|
id: identifier(),
|
|
48
76
|
name,
|
|
49
77
|
type,
|
|
50
78
|
...flags,
|
|
51
79
|
children: Object.entries(container.properties).map(([childName, child]) => schemaPropertyToProperty(childName, child, childRequired)),
|
|
52
|
-
};
|
|
80
|
+
});
|
|
53
81
|
}
|
|
54
|
-
return {
|
|
82
|
+
return copySchemaKeywordOrder(flags, {
|
|
55
83
|
id: identifier(),
|
|
56
84
|
name,
|
|
57
85
|
type,
|
|
58
86
|
...flags,
|
|
59
87
|
...(typeof concept === 'string' && concept.length > 0 ? { concept } : {}),
|
|
60
|
-
};
|
|
88
|
+
});
|
|
61
89
|
}
|
|
62
90
|
function jsonSchemaToProperties(schema) {
|
|
63
91
|
if (!schema?.properties)
|
|
@@ -78,22 +106,32 @@ function primitiveSchema(property) {
|
|
|
78
106
|
case PropertyType.Object:
|
|
79
107
|
return { type: 'object', ...objectSchema(property.children ?? []) };
|
|
80
108
|
case PropertyType.StringArray:
|
|
81
|
-
return { type: 'array', items: { type: 'string' } };
|
|
109
|
+
return { type: 'array', items: { type: 'string', ...property.itemVendorKeywords } };
|
|
82
110
|
case PropertyType.NumberArray:
|
|
83
|
-
return { type: 'array', items: { type: 'number' } };
|
|
111
|
+
return { type: 'array', items: { type: 'number', ...property.itemVendorKeywords } };
|
|
84
112
|
case PropertyType.ObjectArray:
|
|
85
|
-
return { type: 'array', items: { type: 'object', ...objectSchema(property.children ?? []) } };
|
|
113
|
+
return { type: 'array', items: { type: 'object', ...objectSchema(property.children ?? []), ...property.itemVendorKeywords } };
|
|
86
114
|
default:
|
|
87
115
|
return { type: 'string' };
|
|
88
116
|
}
|
|
89
117
|
}
|
|
90
|
-
function
|
|
118
|
+
function orderedPrimitiveSchema(property) {
|
|
119
|
+
const schema = primitiveSchema(property);
|
|
120
|
+
if (schema.items)
|
|
121
|
+
schema.items = schemaInOriginalOrder(schema.items, property[itemSchemaKeywordOrder]);
|
|
122
|
+
return schema;
|
|
123
|
+
}
|
|
124
|
+
function propertyAnnotations(property) {
|
|
91
125
|
return {
|
|
92
|
-
...
|
|
126
|
+
...property.vendorKeywords,
|
|
127
|
+
...(property.isGenerated === true ? { [GENERATED_KEYWORD]: true } : {}),
|
|
93
128
|
...(property.concept ? { [CONCEPT_KEYWORD]: property.concept } : {}),
|
|
94
129
|
...(property.isKey === true ? { [KEY_KEYWORD]: true } : {}),
|
|
95
130
|
};
|
|
96
131
|
}
|
|
132
|
+
function propertySchema(property) {
|
|
133
|
+
return schemaInOriginalOrder({ ...orderedPrimitiveSchema(property), ...propertyAnnotations(property) }, property[schemaKeywordOrder]);
|
|
134
|
+
}
|
|
97
135
|
function objectSchema(properties) {
|
|
98
136
|
const schemaProperties = {};
|
|
99
137
|
for (const property of properties) {
|
|
@@ -102,8 +140,9 @@ function objectSchema(properties) {
|
|
|
102
140
|
const required = properties.filter(property => property.isRequired === true).map(property => property.name);
|
|
103
141
|
return { properties: schemaProperties, ...(required.length > 0 ? { required } : {}) };
|
|
104
142
|
}
|
|
105
|
-
function propertiesToJsonSchema(properties) {
|
|
106
|
-
|
|
143
|
+
function propertiesToJsonSchema(properties, base = {}) {
|
|
144
|
+
const root = Object.fromEntries(Object.entries(base).filter(([name]) => !['properties', 'required'].includes(name)));
|
|
145
|
+
return schemaInOriginalOrder({ ...root, type: 'object', ...objectSchema(properties) }, Object.keys(base));
|
|
107
146
|
}
|
|
108
147
|
function newProperty(siblings, type, existingCount, concept) {
|
|
109
148
|
const base = isComplex(type) ? 'nested' : 'property';
|
|
@@ -124,48 +163,65 @@ function addChildProperty(properties, parentId, type, existingCount, concept) {
|
|
|
124
163
|
const child = newProperty(siblings, type, existingCount, concept);
|
|
125
164
|
const insert = (level) => level.map(property => {
|
|
126
165
|
if (property.id === parentId)
|
|
127
|
-
return { ...property, children: [...(property.children ?? []), child] };
|
|
128
|
-
return property.children ? { ...property, children: insert(property.children) } : property;
|
|
166
|
+
return copySchemaKeywordOrder(property, { ...property, children: [...(property.children ?? []), child] });
|
|
167
|
+
return property.children ? copySchemaKeywordOrder(property, { ...property, children: insert(property.children) }) : property;
|
|
129
168
|
});
|
|
130
169
|
return insert(properties);
|
|
131
170
|
}
|
|
132
171
|
function removeProperty(properties, targetId) {
|
|
133
172
|
return properties
|
|
134
173
|
.filter(property => property.id !== targetId)
|
|
135
|
-
.map(property => property.children ? { ...property, children: removeProperty(property.children, targetId) } : property);
|
|
174
|
+
.map(property => property.children ? copySchemaKeywordOrder(property, { ...property, children: removeProperty(property.children, targetId) }) : property);
|
|
136
175
|
}
|
|
137
176
|
function updateProperty(properties, targetId, update) {
|
|
138
177
|
return properties.map(property => {
|
|
139
178
|
if (property.id === targetId)
|
|
140
179
|
return update(property);
|
|
141
|
-
return property.children ? { ...property, children: updateProperty(property.children, targetId, update) } : property;
|
|
180
|
+
return property.children ? copySchemaKeywordOrder(property, { ...property, children: updateProperty(property.children, targetId, update) }) : property;
|
|
142
181
|
});
|
|
143
182
|
}
|
|
144
183
|
function renameProperty(properties, targetId, newName) {
|
|
145
|
-
return updateProperty(properties, targetId, property => ({ ...property, name: newName }));
|
|
184
|
+
return updateProperty(properties, targetId, property => copySchemaKeywordOrder(property, { ...property, name: newName }));
|
|
146
185
|
}
|
|
147
|
-
function
|
|
148
|
-
|
|
186
|
+
function retypedProperty(property, newType, concept) {
|
|
187
|
+
const next = copySchemaKeywordOrder(property, {
|
|
149
188
|
...property,
|
|
150
189
|
type: newType,
|
|
151
190
|
concept,
|
|
152
191
|
children: isComplex(newType) ? (property.children ?? []) : undefined,
|
|
153
|
-
})
|
|
192
|
+
});
|
|
193
|
+
if (property.type !== newType) {
|
|
194
|
+
delete next.itemVendorKeywords;
|
|
195
|
+
delete next[itemSchemaKeywordOrder];
|
|
196
|
+
}
|
|
197
|
+
return next;
|
|
198
|
+
}
|
|
199
|
+
function changePropertyType(properties, targetId, newType, concept) {
|
|
200
|
+
return updateProperty(properties, targetId, property => retypedProperty(property, newType, concept));
|
|
154
201
|
}
|
|
155
202
|
function toggleRequiredProperty(properties, targetId) {
|
|
156
|
-
return updateProperty(properties, targetId, property => ({ ...property, isRequired: !property.isRequired || undefined }));
|
|
203
|
+
return updateProperty(properties, targetId, property => copySchemaKeywordOrder(property, { ...property, isRequired: !property.isRequired || undefined }));
|
|
157
204
|
}
|
|
158
205
|
function setRequiredProperty(properties, targetId, isRequired) {
|
|
159
|
-
return updateProperty(properties, targetId, property => ({ ...property, isRequired }));
|
|
206
|
+
return updateProperty(properties, targetId, property => copySchemaKeywordOrder(property, { ...property, isRequired }));
|
|
207
|
+
}
|
|
208
|
+
function setGeneratedProperty(properties, targetId, isGenerated) {
|
|
209
|
+
return updateProperty(properties, targetId, property => {
|
|
210
|
+
const keywords = Object.fromEntries(Object.entries(property.vendorKeywords ?? {}).filter(([name]) => name !== GENERATED_KEYWORD));
|
|
211
|
+
const next = { ...property };
|
|
212
|
+
delete next.isGenerated;
|
|
213
|
+
delete next.vendorKeywords;
|
|
214
|
+
return copySchemaKeywordOrder(property, { ...next, ...(isGenerated ? { isGenerated: true } : {}), ...(Object.keys(keywords).length > 0 ? { vendorKeywords: keywords } : {}) });
|
|
215
|
+
});
|
|
160
216
|
}
|
|
161
217
|
function setKeyProperty(properties, targetId) {
|
|
162
218
|
const target = properties.find(property => property.id === targetId);
|
|
163
|
-
return properties.map(property => ({
|
|
219
|
+
return properties.map(property => copySchemaKeywordOrder(property, {
|
|
164
220
|
...property,
|
|
165
221
|
...(target ? { isKey: property.id === targetId && target.isKey !== true ? true : undefined } : {}),
|
|
166
222
|
...(property.children ? { children: setKeyProperty(property.children, targetId) } : {}),
|
|
167
223
|
}));
|
|
168
224
|
}
|
|
169
225
|
|
|
170
|
-
export { CONCEPT_KEYWORD, KEY_KEYWORD, addChildProperty, addProperty, changePropertyType, jsonSchemaToProperties, propertiesToJsonSchema, removeProperty, renameProperty, setKeyProperty, setRequiredProperty, toggleRequiredProperty };
|
|
226
|
+
export { CONCEPT_KEYWORD, GENERATED_KEYWORD, KEY_KEYWORD, addChildProperty, addProperty, changePropertyType, jsonSchemaToProperties, propertiesToJsonSchema, removeProperty, renameProperty, setGeneratedProperty, setKeyProperty, setRequiredProperty, toggleRequiredProperty };
|
|
171
227
|
//# sourceMappingURL=schemaConversion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaConversion.js","sources":["../../../../SchemaEditor/Tree/schemaConversion.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 type { Property } from './Property';\nimport { PropertyType } from './PropertyType';\nimport { conceptPropertyName, uniquePropertyName } from './propertyNaming';\nimport { findPropertyById } from './propertyTree';\n\n/**\n * The JSON Schema keyword carrying the concept a property is typed as. It annotates the primitive node the\n * concept wraps rather than replacing it, so anything that does not know about concepts — code generation,\n * an export, another tool — still reads a valid schema of the underlying primitive.\n */\nexport const CONCEPT_KEYWORD = 'x-concept';\n\n/**\n * The JSON Schema keyword marking the property that identifies its parent object. Written as `true` on the\n * property; at most one property of an object carries it.\n */\nexport const KEY_KEYWORD = 'x-key';\n\ntype SchemaNode = Record<string, unknown>;\n\nconst isComplex = (type: PropertyType): boolean => type === PropertyType.Object || type === PropertyType.ObjectArray;\n\nconst identifier = (): string => Math.random().toString(36).slice(2, 10) + Math.random().toString(36).slice(2, 6);\n\n// ── JsonSchema → Property[] ─────────────────────────────────────────\n\nfunction schemaPropertyType(value: SchemaNode): PropertyType {\n const items = value.items as { type?: string } | undefined;\n\n switch (value.type) {\n case 'string':\n if (value.format === 'date') return PropertyType.Date;\n if (value.format === 'time') return PropertyType.Time;\n return PropertyType.String;\n case 'number':\n case 'integer':\n return PropertyType.Number;\n case 'boolean':\n return PropertyType.Boolean;\n case 'object':\n return PropertyType.Object;\n case 'array':\n if (items?.type === 'number' || items?.type === 'integer') return PropertyType.NumberArray;\n if (items?.type === 'object') return PropertyType.ObjectArray;\n return PropertyType.StringArray;\n default:\n return PropertyType.String;\n }\n}\n\nfunction schemaPropertyToProperty(name: string, value: JsonSchemaProperty, required: ReadonlySet<string>): Property {\n const node = value as unknown as SchemaNode;\n const type = schemaPropertyType(node);\n const concept = node[CONCEPT_KEYWORD];\n const flags = {\n ...(required.has(name) ? { isRequired: true } : {}),\n ...(node[KEY_KEYWORD] === true ? { isKey: true } : {}),\n };\n\n const container = (type === PropertyType.Object ? node : type === PropertyType.ObjectArray ? node.items : undefined) as\n | { properties?: Record<string, JsonSchemaProperty>; required?: string[] }\n | undefined;\n\n if (container?.properties) {\n const childRequired = new Set(container.required ?? []);\n return {\n id: identifier(),\n name,\n type,\n ...flags,\n children: Object.entries(container.properties).map(([childName, child]) =>\n schemaPropertyToProperty(childName, child, childRequired)),\n };\n }\n\n return {\n id: identifier(),\n name,\n type,\n ...flags,\n ...(typeof concept === 'string' && concept.length > 0 ? { concept } : {}),\n };\n}\n\n/**\n * Converts a JSON Schema object into a property tree. Generates a new id for every property.\n * @param schema The schema to read; `undefined` and schemas without properties give an empty tree.\n * @returns The root properties.\n */\nexport function jsonSchemaToProperties(schema: JsonSchema | undefined): Property[] {\n if (!schema?.properties) return [];\n const required = new Set(schema.required ?? []);\n return Object.entries(schema.properties).map(([name, value]) => schemaPropertyToProperty(name, value, required));\n}\n\n// ── Property[] → JsonSchema ─────────────────────────────────────────\n\nfunction primitiveSchema(property: Property): SchemaNode {\n switch (property.type) {\n case PropertyType.Number:\n return { type: 'number' };\n case PropertyType.Boolean:\n return { type: 'boolean' };\n case PropertyType.Date:\n return { type: 'string', format: 'date' };\n case PropertyType.Time:\n return { type: 'string', format: 'time' };\n case PropertyType.Object:\n return { type: 'object', ...objectSchema(property.children ?? []) };\n case PropertyType.StringArray:\n return { type: 'array', items: { type: 'string' } };\n case PropertyType.NumberArray:\n return { type: 'array', items: { type: 'number' } };\n case PropertyType.ObjectArray:\n return { type: 'array', items: { type: 'object', ...objectSchema(property.children ?? []) } };\n default:\n return { type: 'string' };\n }\n}\n\nfunction propertySchema(property: Property): JsonSchemaProperty {\n return {\n ...primitiveSchema(property),\n ...(property.concept ? { [CONCEPT_KEYWORD]: property.concept } : {}),\n ...(property.isKey === true ? { [KEY_KEYWORD]: true } : {}),\n } as unknown as JsonSchemaProperty;\n}\n\nfunction objectSchema(properties: Property[]): { properties: Record<string, JsonSchemaProperty>; required?: string[] } {\n const schemaProperties: Record<string, JsonSchemaProperty> = {};\n for (const property of properties) {\n schemaProperties[property.name] = propertySchema(property);\n }\n const required = properties.filter(property => property.isRequired === true).map(property => property.name);\n return { properties: schemaProperties, ...(required.length > 0 ? { required } : {}) };\n}\n\n/**\n * Converts a property tree into a JSON Schema object. Empty `required` lists are omitted, and a property\n * typed as a concept or marked as the key carries the `x-concept` and `x-key` keywords.\n * @param properties The root properties.\n * @returns The schema.\n */\nexport function propertiesToJsonSchema(properties: Property[]): JsonSchema {\n return { type: 'object', ...objectSchema(properties) } as JsonSchema;\n}\n\n// ── Pure tree edits ─────────────────────────────────────────────────\n\nfunction newProperty(siblings: Property[], type: PropertyType, existingCount: number, concept?: string): Property {\n const base = isComplex(type) ? 'nested' : 'property';\n const name = concept ? uniquePropertyName(siblings, conceptPropertyName(concept)) : `${base}${existingCount + 1}`;\n\n return {\n id: identifier(),\n name,\n type,\n ...(concept ? { concept } : {}),\n ...(isComplex(type) ? { children: [] } : {}),\n };\n}\n\n/**\n * Appends a property to the root.\n * @param properties The root properties.\n * @param type The type of the new property.\n * @param existingCount The number of properties already in the tree, used to generate the default name; see {@link totalPropertyCount}.\n * @param concept The concept the property is typed as. When given the property is named after it.\n * @returns The new tree.\n */\nexport function addProperty(properties: Property[], type: PropertyType, existingCount: number, concept?: string): Property[] {\n return [...properties, newProperty(properties, type, existingCount, concept)];\n}\n\n/**\n * Appends a property to a nested object or object list.\n * @param properties The root properties.\n * @param parentId The id of the parent property.\n * @param type The type of the new property.\n * @param existingCount The number of properties already in the tree, used to generate the default name.\n * @param concept The concept the property is typed as.\n * @returns The new tree.\n */\nexport function addChildProperty(\n properties: Property[],\n parentId: string,\n type: PropertyType,\n existingCount: number,\n concept?: string,\n): Property[] {\n const siblings = findPropertyById(properties, parentId)?.children ?? [];\n const child = newProperty(siblings, type, existingCount, concept);\n const insert = (level: Property[]): Property[] => level.map(property => {\n if (property.id === parentId) return { ...property, children: [...(property.children ?? []), child] };\n return property.children ? { ...property, children: insert(property.children) } : property;\n });\n return insert(properties);\n}\n\n/**\n * Removes a property, and everything nested under it.\n * @param properties The root properties.\n * @param targetId The id of the property to remove.\n * @returns The new tree.\n */\nexport function removeProperty(properties: Property[], targetId: string): Property[] {\n return properties\n .filter(property => property.id !== targetId)\n .map(property => property.children ? { ...property, children: removeProperty(property.children, targetId) } : property);\n}\n\nfunction updateProperty(properties: Property[], targetId: string, update: (property: Property) => Property): Property[] {\n return properties.map(property => {\n if (property.id === targetId) return update(property);\n return property.children ? { ...property, children: updateProperty(property.children, targetId, update) } : property;\n });\n}\n\n/**\n * Renames a property. Its requiredness travels with it, because both are stored against the property.\n * @param properties The root properties.\n * @param targetId The id of the property to rename.\n * @param newName The new name.\n * @returns The new tree.\n */\nexport function renameProperty(properties: Property[], targetId: string, newName: string): Property[] {\n return updateProperty(properties, targetId, property => ({ ...property, name: newName }));\n}\n\n/**\n * Changes the type of a property. Choosing a plain primitive drops the concept; choosing an object or\n * object list keeps the children, and any other type drops them.\n * @param properties The root properties.\n * @param targetId The id of the property.\n * @param newType The new type.\n * @param concept The concept the property is now typed as, if any.\n * @returns The new tree.\n */\nexport function changePropertyType(properties: Property[], targetId: string, newType: PropertyType, concept?: string): Property[] {\n return updateProperty(properties, targetId, property => ({\n ...property,\n type: newType,\n concept,\n children: isComplex(newType) ? (property.children ?? []) : undefined,\n }));\n}\n\n/**\n * Flips whether a property is required.\n * @param properties The root properties.\n * @param targetId The id of the property.\n * @returns The new tree.\n */\nexport function toggleRequiredProperty(properties: Property[], targetId: string): Property[] {\n return updateProperty(properties, targetId, property => ({ ...property, isRequired: !property.isRequired || undefined }));\n}\n\n/**\n * Sets whether a property is required. Requiring a nested property does not require its parent.\n * @param properties The root properties.\n * @param targetId The id of the property.\n * @param isRequired Whether the property must be present.\n * @returns The new tree.\n */\nexport function setRequiredProperty(properties: Property[], targetId: string, isRequired: boolean): Property[] {\n return updateProperty(properties, targetId, property => ({ ...property, isRequired }));\n}\n\n/**\n * Makes a property the key of its parent object, moving the key when a sibling held it. Choosing the\n * property that already is the key clears it, so an object can also have no key.\n * @param properties The root properties.\n * @param targetId The id of the property.\n * @returns The new tree.\n */\nexport function setKeyProperty(properties: Property[], targetId: string): Property[] {\n const target = properties.find(property => property.id === targetId);\n return properties.map(property => ({\n ...property,\n ...(target ? { isKey: property.id === targetId && target.isKey !== true ? true : undefined } : {}),\n ...(property.children ? { children: setKeyProperty(property.children, targetId) } : {}),\n }));\n}\n"],"names":[],"mappings":";;;;AAcO,MAAM,eAAe,GAAG;AAMxB,MAAM,WAAW,GAAG;AAI3B,MAAM,SAAS,GAAG,CAAC,IAAkB,KAAc,IAAI,KAAK,YAAY,CAAC,MAAM,IAAI,IAAI,KAAK,YAAY,CAAC,WAAW;AAEpH,MAAM,UAAU,GAAG,MAAc,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;AAIjH,SAAS,kBAAkB,CAAC,KAAiB,EAAA;AACzC,IAAA,MAAM,KAAK,GAAG,KAAK,CAAC,KAAsC;AAE1D,IAAA,QAAQ,KAAK,CAAC,IAAI;AACd,QAAA,KAAK,QAAQ;AACT,YAAA,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM;gBAAE,OAAO,YAAY,CAAC,IAAI;AACrD,YAAA,IAAI,KAAK,CAAC,M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,EAAA;AACnE,IAAA,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,EAAE,KAAK,QAAQ,CAAC;IACpE,OAAO,UAAU,CAAC,GAAG,CAAC,QAAQ,KAAK;AAC/B,QAAA,GAAG,QAAQ;AACX,QAAA,IAAI,MAAM,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,KAAK,QAAQ,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI,GAAG,IAAI,GAAG,SAAS,EAAE,GAAG,EAAE,CAAC;QAClG,IAAI,QAAQ,CAAC,QAAQ,GAAG,EAAE,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;AAC1F,KAAA,CAAC,CAAC;AACP;;"}
|
|
1
|
+
{"version":3,"file":"schemaConversion.js","sources":["../../../../SchemaEditor/Tree/schemaConversion.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 type { Property } from './Property';\nimport { PropertyType } from './PropertyType';\nimport { conceptPropertyName, uniquePropertyName } from './propertyNaming';\nimport { findPropertyById } from './propertyTree';\nimport { copySchemaKeywordOrder, itemSchemaKeywordOrder, schemaKeywordOrder, type SchemaOrderedProperty } from './SchemaOrderedProperty';\nimport { schemaInOriginalOrder } from './schemaInOriginalOrder';\n\n/**\n * The JSON Schema keyword carrying the concept a property is typed as. It annotates the primitive node the\n * concept wraps rather than replacing it, so anything that does not know about concepts — code generation,\n * an export, another tool — still reads a valid schema of the underlying primitive.\n */\nexport const CONCEPT_KEYWORD = 'x-concept';\n\n/**\n * The JSON Schema keyword marking the property that identifies its parent object. Written as `true` on the\n * property; at most one property of an object carries it.\n */\nexport const KEY_KEYWORD = 'x-key';\n\n/** The JSON Schema keyword marking a value generated when the command runs rather than entered. */\nexport const GENERATED_KEYWORD = 'x-generated';\n\ntype SchemaNode = Record<string, unknown>;\n\nconst isComplex = (type: PropertyType): boolean => type === PropertyType.Object || type === PropertyType.ObjectArray;\n\nconst identifier = (): string => Math.random().toString(36).slice(2, 10) + Math.random().toString(36).slice(2, 6);\n\n// ── JsonSchema → Property[] ─────────────────────────────────────────\n\nfunction schemaPropertyType(value: SchemaNode): PropertyType {\n const items = value.items as { type?: string } | undefined;\n\n switch (value.type) {\n case 'string':\n if (value.format === 'date') return PropertyType.Date;\n if (value.format === 'time') return PropertyType.Time;\n return PropertyType.String;\n case 'number':\n case 'integer':\n return PropertyType.Number;\n case 'boolean':\n return PropertyType.Boolean;\n case 'object':\n return PropertyType.Object;\n case 'array':\n if (items?.type === 'number' || items?.type === 'integer') return PropertyType.NumberArray;\n if (items?.type === 'object') return PropertyType.ObjectArray;\n return PropertyType.StringArray;\n default:\n return PropertyType.String;\n }\n}\n\nfunction vendorKeywords(node: SchemaNode, isProperty: boolean): Readonly<Record<string, unknown>> | undefined {\n const entries = Object.entries(node).filter(([name, value]) => {\n if (!name.startsWith('x-')) return false;\n if (!isProperty) return true;\n return name !== CONCEPT_KEYWORD && name !== KEY_KEYWORD && !(name === GENERATED_KEYWORD && value === true);\n });\n return entries.length > 0 ? Object.fromEntries(entries) : undefined;\n}\n\nfunction readItemKeywords(node: SchemaNode): Partial<SchemaOrderedProperty> {\n if (node.type !== 'array' || typeof node.items !== 'object' || node.items === null) return {};\n const items = node.items as SchemaNode;\n const keywords = vendorKeywords(items, false);\n return { [itemSchemaKeywordOrder]: Object.keys(items), ...(keywords ? { itemVendorKeywords: keywords } : {}) };\n}\n\nfunction readFlags(node: SchemaNode, isRequired: boolean): Partial<SchemaOrderedProperty> {\n const keywords = vendorKeywords(node, true);\n return {\n [schemaKeywordOrder]: Object.keys(node),\n ...readItemKeywords(node),\n ...(keywords ? { vendorKeywords: keywords } : {}),\n ...(node[GENERATED_KEYWORD] === true ? { isGenerated: true } : {}),\n ...(isRequired ? { isRequired: true } : {}),\n ...(node[KEY_KEYWORD] === true ? { isKey: true } : {}),\n };\n}\n\nfunction schemaPropertyToProperty(name: string, value: JsonSchemaProperty, required: ReadonlySet<string>): Property {\n const node = value as unknown as SchemaNode;\n const type = schemaPropertyType(node);\n const concept = node[CONCEPT_KEYWORD];\n const flags = readFlags(node, required.has(name));\n\n const container = (type === PropertyType.Object ? node : type === PropertyType.ObjectArray ? node.items : undefined) as\n | { properties?: Record<string, JsonSchemaProperty>; required?: string[] }\n | undefined;\n\n if (container?.properties) {\n const childRequired = new Set(container.required ?? []);\n return copySchemaKeywordOrder(flags, {\n id: identifier(),\n name,\n type,\n ...flags,\n children: Object.entries(container.properties).map(([childName, child]) =>\n schemaPropertyToProperty(childName, child, childRequired)),\n });\n }\n\n return copySchemaKeywordOrder(flags, {\n id: identifier(),\n name,\n type,\n ...flags,\n ...(typeof concept === 'string' && concept.length > 0 ? { concept } : {}),\n });\n}\n\n/**\n * Converts a JSON Schema object into a property tree. Generates a new id for every property.\n * @param schema The schema to read; `undefined` and schemas without properties give an empty tree.\n * @returns The root properties.\n */\nexport function jsonSchemaToProperties(schema: JsonSchema | undefined): Property[] {\n if (!schema?.properties) return [];\n const required = new Set(schema.required ?? []);\n return Object.entries(schema.properties).map(([name, value]) => schemaPropertyToProperty(name, value, required));\n}\n\n// ── Property[] → JsonSchema ─────────────────────────────────────────\n\nfunction primitiveSchema(property: Property): SchemaNode {\n switch (property.type) {\n case PropertyType.Number:\n return { type: 'number' };\n case PropertyType.Boolean:\n return { type: 'boolean' };\n case PropertyType.Date:\n return { type: 'string', format: 'date' };\n case PropertyType.Time:\n return { type: 'string', format: 'time' };\n case PropertyType.Object:\n return { type: 'object', ...objectSchema(property.children ?? []) };\n case PropertyType.StringArray:\n return { type: 'array', items: { type: 'string', ...property.itemVendorKeywords } };\n case PropertyType.NumberArray:\n return { type: 'array', items: { type: 'number', ...property.itemVendorKeywords } };\n case PropertyType.ObjectArray:\n return { type: 'array', items: { type: 'object', ...objectSchema(property.children ?? []), ...property.itemVendorKeywords } };\n default:\n return { type: 'string' };\n }\n}\n\nfunction orderedPrimitiveSchema(property: SchemaOrderedProperty): SchemaNode {\n const schema = primitiveSchema(property);\n if (schema.items) schema.items = schemaInOriginalOrder(schema.items as SchemaNode, property[itemSchemaKeywordOrder]);\n return schema;\n}\n\nfunction propertyAnnotations(property: Property): SchemaNode {\n return {\n ...property.vendorKeywords,\n ...(property.isGenerated === true ? { [GENERATED_KEYWORD]: true } : {}),\n ...(property.concept ? { [CONCEPT_KEYWORD]: property.concept } : {}),\n ...(property.isKey === true ? { [KEY_KEYWORD]: true } : {}),\n };\n}\n\nfunction propertySchema(property: SchemaOrderedProperty): JsonSchemaProperty {\n return schemaInOriginalOrder({ ...orderedPrimitiveSchema(property), ...propertyAnnotations(property) }, property[schemaKeywordOrder]) as unknown as JsonSchemaProperty;\n}\n\nfunction objectSchema(properties: Property[]): { properties: Record<string, JsonSchemaProperty>; required?: string[] } {\n const schemaProperties: Record<string, JsonSchemaProperty> = {};\n for (const property of properties) {\n schemaProperties[property.name] = propertySchema(property);\n }\n const required = properties.filter(property => property.isRequired === true).map(property => property.name);\n return { properties: schemaProperties, ...(required.length > 0 ? { required } : {}) };\n}\n\n/**\n * Converts a property tree into a JSON Schema object. Empty `required` lists are omitted, and a property\n * typed as a concept or marked as the key carries the `x-concept` and `x-key` keywords. Vendor keywords are\n * preserved on properties and array items; generated values carry `x-generated: true`.\n * @param properties The root properties.\n * @param base The incoming schema. Root keys other than type, properties and required are preserved.\n * @returns The schema.\n */\nexport function propertiesToJsonSchema(properties: Property[], base: JsonSchema = {}): JsonSchema {\n const root = Object.fromEntries(Object.entries(base).filter(([name]) => !['properties', 'required'].includes(name)));\n return schemaInOriginalOrder({ ...root, type: 'object', ...objectSchema(properties) }, Object.keys(base)) as JsonSchema;\n}\n\n// ── Pure tree edits ─────────────────────────────────────────────────\n\nfunction newProperty(siblings: Property[], type: PropertyType, existingCount: number, concept?: string): Property {\n const base = isComplex(type) ? 'nested' : 'property';\n const name = concept ? uniquePropertyName(siblings, conceptPropertyName(concept)) : `${base}${existingCount + 1}`;\n\n return {\n id: identifier(),\n name,\n type,\n ...(concept ? { concept } : {}),\n ...(isComplex(type) ? { children: [] } : {}),\n };\n}\n\n/**\n * Appends a property to the root.\n * @param properties The root properties.\n * @param type The type of the new property.\n * @param existingCount The number of properties already in the tree, used to generate the default name; see {@link totalPropertyCount}.\n * @param concept The concept the property is typed as. When given the property is named after it.\n * @returns The new tree.\n */\nexport function addProperty(properties: Property[], type: PropertyType, existingCount: number, concept?: string): Property[] {\n return [...properties, newProperty(properties, type, existingCount, concept)];\n}\n\n/**\n * Appends a property to a nested object or object list.\n * @param properties The root properties.\n * @param parentId The id of the parent property.\n * @param type The type of the new property.\n * @param existingCount The number of properties already in the tree, used to generate the default name.\n * @param concept The concept the property is typed as.\n * @returns The new tree.\n */\nexport function addChildProperty(\n properties: Property[],\n parentId: string,\n type: PropertyType,\n existingCount: number,\n concept?: string,\n): Property[] {\n const siblings = findPropertyById(properties, parentId)?.children ?? [];\n const child = newProperty(siblings, type, existingCount, concept);\n const insert = (level: Property[]): Property[] => level.map(property => {\n if (property.id === parentId) return copySchemaKeywordOrder(property, { ...property, children: [...(property.children ?? []), child] });\n return property.children ? copySchemaKeywordOrder(property, { ...property, children: insert(property.children) }) : property;\n });\n return insert(properties);\n}\n\n/**\n * Removes a property, and everything nested under it.\n * @param properties The root properties.\n * @param targetId The id of the property to remove.\n * @returns The new tree.\n */\nexport function removeProperty(properties: Property[], targetId: string): Property[] {\n return properties\n .filter(property => property.id !== targetId)\n .map(property => property.children ? copySchemaKeywordOrder(property, { ...property, children: removeProperty(property.children, targetId) }) : property);\n}\n\nfunction updateProperty(properties: Property[], targetId: string, update: (property: Property) => Property): Property[] {\n return properties.map(property => {\n if (property.id === targetId) return update(property);\n return property.children ? copySchemaKeywordOrder(property, { ...property, children: updateProperty(property.children, targetId, update) }) : property;\n });\n}\n\n/**\n * Renames a property. Its requiredness travels with it, because both are stored against the property.\n * @param properties The root properties.\n * @param targetId The id of the property to rename.\n * @param newName The new name.\n * @returns The new tree.\n */\nexport function renameProperty(properties: Property[], targetId: string, newName: string): Property[] {\n return updateProperty(properties, targetId, property => copySchemaKeywordOrder(property, { ...property, name: newName }));\n}\n\nfunction retypedProperty(property: Property, newType: PropertyType, concept?: string): Property {\n const next: SchemaOrderedProperty = copySchemaKeywordOrder(property, {\n ...property,\n type: newType,\n concept,\n children: isComplex(newType) ? (property.children ?? []) : undefined,\n });\n if (property.type !== newType) {\n delete next.itemVendorKeywords;\n delete next[itemSchemaKeywordOrder];\n }\n return next;\n}\n\n/**\n * Changes the type of a property. Choosing a plain primitive drops the concept; choosing an object or\n * object list keeps the children, and any other type drops them. A different item kind clears item metadata.\n * @param properties The root properties.\n * @param targetId The id of the property.\n * @param newType The new type.\n * @param concept The concept the property is now typed as, if any.\n * @returns The new tree.\n */\nexport function changePropertyType(properties: Property[], targetId: string, newType: PropertyType, concept?: string): Property[] {\n return updateProperty(properties, targetId, property => retypedProperty(property, newType, concept));\n}\n\n/**\n * Flips whether a property is required.\n * @param properties The root properties.\n * @param targetId The id of the property.\n * @returns The new tree.\n */\nexport function toggleRequiredProperty(properties: Property[], targetId: string): Property[] {\n return updateProperty(properties, targetId, property => copySchemaKeywordOrder(property, { ...property, isRequired: !property.isRequired || undefined }));\n}\n\n/**\n * Sets whether a property is required. Requiring a nested property does not require its parent.\n * @param properties The root properties.\n * @param targetId The id of the property.\n * @param isRequired Whether the property must be present.\n * @returns The new tree.\n */\nexport function setRequiredProperty(properties: Property[], targetId: string, isRequired: boolean): Property[] {\n return updateProperty(properties, targetId, property => copySchemaKeywordOrder(property, { ...property, isRequired }));\n}\n\n/**\n * Sets whether a property's value is generated. An explicit edit replaces any non-true x-generated value.\n * @param properties The root properties.\n * @param targetId The id of the property.\n * @param isGenerated Whether the value is generated.\n * @returns The new tree.\n */\nexport function setGeneratedProperty(properties: Property[], targetId: string, isGenerated: boolean): Property[] {\n return updateProperty(properties, targetId, property => {\n const keywords = Object.fromEntries(Object.entries(property.vendorKeywords ?? {}).filter(([name]) => name !== GENERATED_KEYWORD));\n const next = { ...property };\n delete next.isGenerated;\n delete next.vendorKeywords;\n return copySchemaKeywordOrder(property, { ...next, ...(isGenerated ? { isGenerated: true } : {}), ...(Object.keys(keywords).length > 0 ? { vendorKeywords: keywords } : {}) });\n });\n}\n\n/**\n * Makes a property the key of its parent object, moving the key when a sibling held it. Choosing the\n * property that already is the key clears it, so an object can also have no key.\n * @param properties The root properties.\n * @param targetId The id of the property.\n * @returns The new tree.\n */\nexport function setKeyProperty(properties: Property[], targetId: string): Property[] {\n const target = properties.find(property => property.id === targetId);\n return properties.map(property => copySchemaKeywordOrder(property, {\n ...property,\n ...(target ? { isKey: property.id === targetId && target.isKey !== true ? true : undefined } : {}),\n ...(property.children ? { children: setKeyProperty(property.children, targetId) } : {}),\n }));\n}\n"],"names":[],"mappings":";;;;;;AAgBO,MAAM,eAAe,GAAG;AAMxB,MAAM,WAAW,GAAG;AAGpB,MAAM,iBAAiB,GAAG;AAIjC,MAAM,SAAS,GAAG,CAAC,IAAkB,KAAc,IAAI,KAAK,YAAY,CAAC,MAAM,IAAI,IAAI,KAAK,YAAY,CAAC,WAAW;AAEpH,MAAM,UAAU,GAAG,MAAc,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;AAIjH,SAAS,kBAAkB,CAAC,KAAiB,EAAA;AACzC,IAAA,MAAM,KAAK,GAAG,KAAK,CAAC,KAAsC;AAE1D,IAAA,QAAQ,KAAK,CAAC,IAAI;AACd,QAAA,KAAK,QAAQ;AACT,YAAA,IAAI,KAAK,CAAC,MAAM,KAAK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,WAAW,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,GAAG,CAAC,GAAG,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;AAClL,IAAA,CAAC,CAAC;AACN;AASM,SAAU,cAAc,CAAC,UAAsB,EAAE,QAAgB,EAAA;AACnE,IAAA,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,EAAE,KAAK,QAAQ,CAAC;IACpE,OAAO,UAAU,CAAC,GAAG,CAAC,QAAQ,IAAI,sBAAsB,CAAC,QAAQ,EAAE;AAC/D,QAAA,GAAG,QAAQ;AACX,QAAA,IAAI,MAAM,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,KAAK,QAAQ,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI,GAAG,IAAI,GAAG,SAAS,EAAE,GAAG,EAAE,CAAC;QAClG,IAAI,QAAQ,CAAC,QAAQ,GAAG,EAAE,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;AAC1F,KAAA,CAAC,CAAC;AACP;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaInOriginalOrder.d.ts","sourceRoot":"","sources":["../../../../SchemaEditor/Tree/schemaInOriginalOrder.ts"],"names":[],"mappings":"AAGA,mFAAmF;AACnF,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,GAAE,SAAS,MAAM,EAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAG7H"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
function schemaInOriginalOrder(schema, order = []) {
|
|
2
|
+
const names = new Set([...order, ...Object.keys(schema)]);
|
|
3
|
+
return Object.fromEntries([...names].filter(name => Object.hasOwn(schema, name)).map(name => [name, schema[name]]));
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export { schemaInOriginalOrder };
|
|
7
|
+
//# sourceMappingURL=schemaInOriginalOrder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaInOriginalOrder.js","sources":["../../../../SchemaEditor/Tree/schemaInOriginalOrder.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\n/** Retains the positions of surviving schema keywords and appends new keywords. */\nexport function schemaInOriginalOrder(schema: Record<string, unknown>, order: readonly string[] = []): Record<string, unknown> {\n const names = new Set([...order, ...Object.keys(schema)]);\n return Object.fromEntries([...names].filter(name => Object.hasOwn(schema, name)).map(name => [name, schema[name]]));\n}\n"],"names":[],"mappings":"SAIgB,qBAAqB,CAAC,MAA+B,EAAE,QAA2B,EAAE,EAAA;AAChG,IAAA,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AACzD,IAAA,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACvH;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultSchemaEditorLabels.d.ts","sourceRoot":"","sources":["../../../SchemaEditor/defaultSchemaEditorLabels.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAsB,CAAC;AAE/D,2FAA2F;AAC3F,eAAO,MAAM,0BAA0B,EAAE,QAAQ,CAAC,kBAAkB,
|
|
1
|
+
{"version":3,"file":"defaultSchemaEditorLabels.d.ts","sourceRoot":"","sources":["../../../SchemaEditor/defaultSchemaEditorLabels.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAsB,CAAC;AAE/D,2FAA2F;AAC3F,eAAO,MAAM,0BAA0B,EAAE,QAAQ,CAAC,kBAAkB,CAiDnE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,yBAAyB,EAAE,kBAA+C,CAAC"}
|
|
@@ -29,6 +29,9 @@ const completeSchemaEditorLabels = {
|
|
|
29
29
|
keyProperty: (propertyName) => `Use ${propertyName} as the key property`,
|
|
30
30
|
setAsKey: 'Use as the key that identifies the object',
|
|
31
31
|
isKey: 'This is the key that identifies the object. Select it again to clear it.',
|
|
32
|
+
generatedProperty: (propertyName) => `Generated: ${propertyName}`,
|
|
33
|
+
setAsGenerated: 'Mark as generated: the value is created when the command runs, not entered',
|
|
34
|
+
isGenerated: 'The value is generated. Select it again to mark it as entered.',
|
|
32
35
|
keyColumn: 'Key',
|
|
33
36
|
requiredColumn: 'Required',
|
|
34
37
|
protectedProperty: 'This property cannot be renamed or removed.',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultSchemaEditorLabels.js","sources":["../../../SchemaEditor/defaultSchemaEditorLabels.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 { SchemaEditorLabels } from './SchemaEditorLabels';\n\n/** Every label with its English default, so the editor never has to guard an unset one. */\nexport const completeSchemaEditorLabels: Required<SchemaEditorLabels> = {\n edit: 'Edit',\n save: 'Save',\n cancel: 'Cancel',\n addProperty: 'Add Property',\n actions: 'Actions',\n navigateBack: 'Navigate back',\n emptyMessage: 'No properties defined',\n navigateToItemDefinition: 'Navigate to item definition',\n navigateToProperties: 'Navigate to object properties',\n propertyName: 'Property name',\n propertyType: 'Property type',\n arrayItemType: 'Array item type',\n deleteProperty: 'Delete property',\n invalidJson: 'The schema must contain valid JSON before it can be edited.',\n schema: 'Schema properties',\n addPropertyTo: (propertyName) => `Add property to ${propertyName}`,\n nestedProperties: (propertyName) => `Properties of ${propertyName}`,\n propertyNameFor: (propertyName) => `Name of ${propertyName}`,\n renameHint: 'Double-click or press F2 to rename',\n deletePropertyFor: (propertyName) => `Delete ${propertyName}`,\n changeType: (propertyName, typeName) => `Change type of ${propertyName}, currently ${typeName}`,\n propertyTypes: 'Property types',\n concepts: 'Concepts',\n noConcepts: 'No concepts defined',\n required: 'Required',\n requiredProperty: (propertyName) => `Required in schema: ${propertyName}`,\n requiredHelp: 'The property must be present in the object. An empty value still counts as present.',\n keyProperty: (propertyName) => `Use ${propertyName} as the key property`,\n setAsKey: 'Use as the key that identifies the object',\n isKey: 'This is the key that identifies the object. Select it again to clear it.',\n keyColumn: 'Key',\n requiredColumn: 'Required',\n protectedProperty: 'This property cannot be renamed or removed.',\n nameRequired: 'Enter a name.',\n nameReserved: (name) => `${name} is reserved and cannot be used as a name.`,\n nameDuplicate: (name) => `Another property is already named ${name}.`,\n typeString: 'Text',\n typeNumber: 'Number',\n typeBoolean: 'Yes or no',\n typeDate: 'Date',\n typeTime: 'Time',\n typeStringArray: 'List of text',\n typeNumberArray: 'List of numbers',\n typeObject: 'Object',\n typeObjectArray: 'List of objects',\n};\n\n/**\n * English defaults for {@link SchemaEditorLabels}. The labels added for the tree layout and the capabilities are\n * optional on the type, and are present here with their English text.\n */\nexport const defaultSchemaEditorLabels: SchemaEditorLabels = completeSchemaEditorLabels;\n"],"names":[],"mappings":"AAMO,MAAM,0BAA0B,GAAiC;AACpE,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,WAAW,EAAE,cAAc;AAC3B,IAAA,OAAO,EAAE,SAAS;AAClB,IAAA,YAAY,EAAE,eAAe;AAC7B,IA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ratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport type { SchemaEditorLabels } from './SchemaEditorLabels';\n\n/** Every label with its English default, so the editor never has to guard an unset one. */\nexport const completeSchemaEditorLabels: Required<SchemaEditorLabels> = {\n edit: 'Edit',\n save: 'Save',\n cancel: 'Cancel',\n addProperty: 'Add Property',\n actions: 'Actions',\n navigateBack: 'Navigate back',\n emptyMessage: 'No properties defined',\n navigateToItemDefinition: 'Navigate to item definition',\n navigateToProperties: 'Navigate to object properties',\n propertyName: 'Property name',\n propertyType: 'Property type',\n arrayItemType: 'Array item type',\n deleteProperty: 'Delete property',\n invalidJson: 'The schema must contain valid JSON before it can be edited.',\n schema: 'Schema properties',\n addPropertyTo: (propertyName) => `Add property to ${propertyName}`,\n nestedProperties: (propertyName) => `Properties of ${propertyName}`,\n propertyNameFor: (propertyName) => `Name of ${propertyName}`,\n renameHint: 'Double-click or press F2 to rename',\n deletePropertyFor: (propertyName) => `Delete ${propertyName}`,\n changeType: (propertyName, typeName) => `Change type of ${propertyName}, currently ${typeName}`,\n propertyTypes: 'Property types',\n concepts: 'Concepts',\n noConcepts: 'No concepts defined',\n required: 'Required',\n requiredProperty: (propertyName) => `Required in schema: ${propertyName}`,\n requiredHelp: 'The property must be present in the object. An empty value still counts as present.',\n keyProperty: (propertyName) => `Use ${propertyName} as the key property`,\n setAsKey: 'Use as the key that identifies the object',\n isKey: 'This is the key that identifies the object. Select it again to clear it.',\n generatedProperty: (propertyName) => `Generated: ${propertyName}`,\n setAsGenerated: 'Mark as generated: the value is created when the command runs, not entered',\n isGenerated: 'The value is generated. Select it again to mark it as entered.',\n keyColumn: 'Key',\n requiredColumn: 'Required',\n protectedProperty: 'This property cannot be renamed or removed.',\n nameRequired: 'Enter a name.',\n nameReserved: (name) => `${name} is reserved and cannot be used as a name.`,\n nameDuplicate: (name) => `Another property is already named ${name}.`,\n typeString: 'Text',\n typeNumber: 'Number',\n typeBoolean: 'Yes or no',\n typeDate: 'Date',\n typeTime: 'Time',\n typeStringArray: 'List of text',\n typeNumberArray: 'List of numbers',\n typeObject: 'Object',\n typeObjectArray: 'List of objects',\n};\n\n/**\n * English defaults for {@link SchemaEditorLabels}. The labels added for the tree layout and the capabilities are\n * optional on the type, and are present here with their English text.\n */\nexport const defaultSchemaEditorLabels: SchemaEditorLabels = completeSchemaEditorLabels;\n"],"names":[],"mappings":"AAMO,MAAM,0BAA0B,GAAiC;AACpE,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,WAAW,EAAE,cAAc;AAC3B,IAAA,OAAO,EAAE,SAAS;AAClB,IAAA,YAAY,EAAE,eAAe;AAC7B,IAAA,YAAY,EAAE,uBAAuB;AACrC,IAAA,wBAAwB,EAAE,6BAA6B;AACvD,IAAA,oBAAoB,EAAE,+BAA+B;AACrD,IAAA,YAAY,EAAE,eAAe;AAC7B,IAAA,YAAY,EAAE,eAAe;AAC7B,IAAA,aAAa,EAAE,iBAAiB;AAChC,IAAA,cAAc,EAAE,iBAAiB;AACjC,IAAA,WAAW,EAAE,6DAA6D;AAC1E,IAAA,MAAM,EAAE,mBAAmB;IAC3B,aAAa,EAAE,CAAC,YAAY,KAAK,CAAA,gBAAA,EAAmB,YAAY,CAAA,CAAE;IAClE,gBAAgB,EAAE,CAAC,YAAY,KAAK,CAAA,cAAA,EAAiB,YAAY,CAAA,CAAE;IACnE,eAAe,EAAE,CAAC,YAAY,KAAK,CAAA,QAAA,EAAW,YAAY,CAAA,CAAE;AAC5D,IAAA,UAAU,EAAE,oCAAoC;IAChD,iBAAiB,EAAE,CAAC,YAAY,KAAK,CAAA,OAAA,EAAU,YAAY,CAAA,CAAE;AAC7D,IAAA,UAAU,EAAE,CAAC,YAAY,EAAE,QAAQ,KAAK,CAAA,eAAA,EAAkB,YAAY,CAAA,YAAA,EAAe,QAAQ,CAAA,CAAE;AAC/F,IAAA,aAAa,EAAE,gBAAgB;AAC/B,IAAA,QAAQ,EAAE,UAAU;AACpB,IAAA,UAAU,EAAE,qBAAqB;AACjC,IAAA,QAAQ,EAAE,UAAU;IACpB,gBAAgB,EAAE,CAAC,YAAY,KAAK,CAAA,oBAAA,EAAuB,YAAY,CAAA,CAAE;AACzE,IAAA,YAAY,EAAE,qFAAqF;IACnG,WAAW,EAAE,CAAC,YAAY,KAAK,CAAA,IAAA,EAAO,YAAY,CAAA,oBAAA,CAAsB;AACxE,IAAA,QAAQ,EAAE,2CAA2C;AACrD,IAAA,KAAK,EAAE,0EAA0E;IACjF,iBAAiB,EAAE,CAAC,YAAY,KAAK,CAAA,WAAA,EAAc,YAAY,CAAA,CAAE;AACjE,IAAA,cAAc,EAAE,4EAA4E;AAC5F,IAAA,WAAW,EAAE,gEAAgE;AAC7E,IAAA,SAAS,EAAE,KAAK;AAChB,IAAA,cAAc,EAAE,UAAU;AAC1B,IAAA,iBAAiB,EAAE,6CAA6C;AAChE,IAAA,YAAY,EAAE,eAAe;IAC7B,YAAY,EAAE,CAAC,IAAI,KAAK,CAAA,EAAG,IAAI,CAAA,0CAAA,CAA4C;IAC3E,aAAa,EAAE,CAAC,IAAI,KAAK,CAAA,kCAAA,EAAqC,IAAI,CAAA,CAAA,CAAG;AACrE,IAAA,UAAU,EAAE,MAAM;AAClB,IAAA,UAAU,EAAE,QAAQ;AACpB,IAAA,WAAW,EAAE,WAAW;AACxB,IAAA,QAAQ,EAAE,MAAM;AAChB,IAAA,QAAQ,EAAE,MAAM;AAChB,IAAA,eAAe,EAAE,cAAc;AAC/B,IAAA,eAAe,EAAE,iBAAiB;AAClC,IAAA,UAAU,EAAE,QAAQ;AACpB,IAAA,eAAe,EAAE,iBAAiB;;AAO/B,MAAM,yBAAyB,GAAuB;;"}
|
|
@@ -10,7 +10,7 @@ export { PropertyType } from './Tree/PropertyType.js';
|
|
|
10
10
|
export type { PropertyConcept } from './Tree/PropertyConcept.js';
|
|
11
11
|
export { PropertyNameProblem, conceptPropertyName, findPropertyNameProblem, uniquePropertyName, } from './Tree/propertyNaming.js';
|
|
12
12
|
export { findPropertyById, findPropertyByName, findSiblingProperties, totalPropertyCount } from './Tree/propertyTree.js';
|
|
13
|
-
export { CONCEPT_KEYWORD, KEY_KEYWORD, addChildProperty, addProperty, changePropertyType, jsonSchemaToProperties, propertiesToJsonSchema, removeProperty, renameProperty, setKeyProperty, setRequiredProperty, toggleRequiredProperty, } from './Tree/schemaConversion.js';
|
|
13
|
+
export { CONCEPT_KEYWORD, KEY_KEYWORD, GENERATED_KEYWORD, addChildProperty, addProperty, changePropertyType, jsonSchemaToProperties, propertiesToJsonSchema, removeProperty, renameProperty, setKeyProperty, setGeneratedProperty, setRequiredProperty, toggleRequiredProperty, } from './Tree/schemaConversion.js';
|
|
14
14
|
export * from '../types/JsonSchema.js';
|
|
15
15
|
export * from '../types/TypeFormat.js';
|
|
16
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../SchemaEditor/index.ts"],"names":[],"mappings":"AAGA,cAAc,mBAAgB,CAAC;AAC/B,YAAY,EAAE,kBAAkB,EAAE,MAAM,yBAAsB,CAAC;AAC/D,YAAY,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,8BAA8B,EAAE,MAAM,6BAA0B,CAAC;AAC9H,YAAY,EAAE,qBAAqB,EAAE,MAAM,iCAA8B,CAAC;AAC1E,YAAY,EAAE,sBAAsB,EAAE,MAAM,kCAA+B,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,mCAAgC,CAAC;AAC/F,YAAY,EAAE,6BAA6B,EAAE,MAAM,mCAAgC,CAAC;AACpF,YAAY,EAAE,QAAQ,EAAE,MAAM,oBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAqB,CAAC;AACnD,YAAY,EAAE,eAAe,EAAE,MAAM,2BAAwB,CAA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AkB,EAAE,MAAM,wBAAqB,CAAC;AACtH,OAAO,EACH,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,cAAc,EACd,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,GACzB,MAAM,4BAAyB,CAAC;AACjC,cAAc,wBAAqB,CAAC;AACpC,cAAc,wBAAqB,CAAC"}
|
|
@@ -3,7 +3,7 @@ export { PropertyConceptsProvider, usePropertyConcepts } from './Tree/PropertyCo
|
|
|
3
3
|
export { PropertyType } from './Tree/PropertyType.js';
|
|
4
4
|
export { PropertyNameProblem, conceptPropertyName, findPropertyNameProblem, uniquePropertyName } from './Tree/propertyNaming.js';
|
|
5
5
|
export { findPropertyById, findPropertyByName, findSiblingProperties, totalPropertyCount } from './Tree/propertyTree.js';
|
|
6
|
-
export { CONCEPT_KEYWORD, KEY_KEYWORD, addChildProperty, addProperty, changePropertyType, jsonSchemaToProperties, propertiesToJsonSchema, removeProperty, renameProperty, setKeyProperty, setRequiredProperty, toggleRequiredProperty } from './Tree/schemaConversion.js';
|
|
6
|
+
export { CONCEPT_KEYWORD, GENERATED_KEYWORD, KEY_KEYWORD, addChildProperty, addProperty, changePropertyType, jsonSchemaToProperties, propertiesToJsonSchema, removeProperty, renameProperty, setGeneratedProperty, setKeyProperty, setRequiredProperty, toggleRequiredProperty } from './Tree/schemaConversion.js';
|
|
7
7
|
export { DEFAULT_TYPE_FORMATS } from '../types/TypeFormat.js';
|
|
8
8
|
export { defaultSchemaEditorLabels } from './defaultSchemaEditorLabels.js';
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CratisComponentsDefaults.d.ts","sourceRoot":"","sources":["../../../configuration/CratisComponentsDefaults.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uCAAoC,CAAC;AAEjF,sDAAsD;AACtD,eAAO,MAAM,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"CratisComponentsDefaults.d.ts","sourceRoot":"","sources":["../../../configuration/CratisComponentsDefaults.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uCAAoC,CAAC;AAEjF,sDAAsD;AACtD,eAAO,MAAM,cAAc,EAAE,sBAiE5B,CAAC"}
|