@cratis/components 4.27.0 → 4.29.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.
Files changed (81) hide show
  1. package/compat-manifest.json +11 -11
  2. package/dist/esm/SchemaEditor/SchemaEditor.d.ts +4 -1
  3. package/dist/esm/SchemaEditor/SchemaEditor.d.ts.map +1 -1
  4. package/dist/esm/SchemaEditor/SchemaEditor.js +3 -1
  5. package/dist/esm/SchemaEditor/SchemaEditor.js.map +1 -1
  6. package/dist/esm/SchemaEditor/SchemaEditorLabels.d.ts +6 -0
  7. package/dist/esm/SchemaEditor/SchemaEditorLabels.d.ts.map +1 -1
  8. package/dist/esm/SchemaEditor/SchemaEditorLabels.js.map +1 -1
  9. package/dist/esm/SchemaEditor/Tree/GeneratedToggle.d.ts +11 -0
  10. package/dist/esm/SchemaEditor/Tree/GeneratedToggle.d.ts.map +1 -0
  11. package/dist/esm/SchemaEditor/Tree/GeneratedToggle.js +24 -0
  12. package/dist/esm/SchemaEditor/Tree/GeneratedToggle.js.map +1 -0
  13. package/dist/esm/SchemaEditor/Tree/KeywordFamily.d.ts +14 -0
  14. package/dist/esm/SchemaEditor/Tree/KeywordFamily.d.ts.map +1 -0
  15. package/dist/esm/SchemaEditor/Tree/KeywordFamily.js +11 -0
  16. package/dist/esm/SchemaEditor/Tree/KeywordFamily.js.map +1 -0
  17. package/dist/esm/SchemaEditor/Tree/Property.d.ts +14 -0
  18. package/dist/esm/SchemaEditor/Tree/Property.d.ts.map +1 -1
  19. package/dist/esm/SchemaEditor/Tree/Property.js.map +1 -1
  20. package/dist/esm/SchemaEditor/Tree/SchemaEditorContext.d.ts +2 -0
  21. package/dist/esm/SchemaEditor/Tree/SchemaEditorContext.d.ts.map +1 -1
  22. package/dist/esm/SchemaEditor/Tree/SchemaEditorContext.js.map +1 -1
  23. package/dist/esm/SchemaEditor/Tree/SchemaEditorParts.d.ts +2 -0
  24. package/dist/esm/SchemaEditor/Tree/SchemaEditorParts.d.ts.map +1 -1
  25. package/dist/esm/SchemaEditor/Tree/SchemaEditorParts.js.map +1 -1
  26. package/dist/esm/SchemaEditor/Tree/SchemaOrderedProperty.d.ts +19 -0
  27. package/dist/esm/SchemaEditor/Tree/SchemaOrderedProperty.d.ts.map +1 -0
  28. package/dist/esm/SchemaEditor/Tree/SchemaOrderedProperty.js +15 -0
  29. package/dist/esm/SchemaEditor/Tree/SchemaOrderedProperty.js.map +1 -0
  30. package/dist/esm/SchemaEditor/Tree/SchemaOriginalShape.d.ts +21 -0
  31. package/dist/esm/SchemaEditor/Tree/SchemaOriginalShape.d.ts.map +1 -0
  32. package/dist/esm/SchemaEditor/Tree/SchemaOriginalShape.js +4 -0
  33. package/dist/esm/SchemaEditor/Tree/SchemaOriginalShape.js.map +1 -0
  34. package/dist/esm/SchemaEditor/Tree/SchemaPropertyRow.d.ts.map +1 -1
  35. package/dist/esm/SchemaEditor/Tree/SchemaPropertyRow.js +2 -2
  36. package/dist/esm/SchemaEditor/Tree/SchemaPropertyRow.js.map +1 -1
  37. package/dist/esm/SchemaEditor/Tree/TreeSchemaEditor.d.ts +8 -1
  38. package/dist/esm/SchemaEditor/Tree/TreeSchemaEditor.d.ts.map +1 -1
  39. package/dist/esm/SchemaEditor/Tree/TreeSchemaEditor.js +15 -11
  40. package/dist/esm/SchemaEditor/Tree/TreeSchemaEditor.js.map +1 -1
  41. package/dist/esm/SchemaEditor/Tree/keywordApplicability.d.ts +41 -0
  42. package/dist/esm/SchemaEditor/Tree/keywordApplicability.d.ts.map +1 -0
  43. package/dist/esm/SchemaEditor/Tree/keywordApplicability.js +56 -0
  44. package/dist/esm/SchemaEditor/Tree/keywordApplicability.js.map +1 -0
  45. package/dist/esm/SchemaEditor/Tree/originalShape.d.ts +30 -0
  46. package/dist/esm/SchemaEditor/Tree/originalShape.d.ts.map +1 -0
  47. package/dist/esm/SchemaEditor/Tree/originalShape.js +70 -0
  48. package/dist/esm/SchemaEditor/Tree/originalShape.js.map +1 -0
  49. package/dist/esm/SchemaEditor/Tree/schemaConversion.d.ts +17 -3
  50. package/dist/esm/SchemaEditor/Tree/schemaConversion.d.ts.map +1 -1
  51. package/dist/esm/SchemaEditor/Tree/schemaConversion.js +111 -55
  52. package/dist/esm/SchemaEditor/Tree/schemaConversion.js.map +1 -1
  53. package/dist/esm/SchemaEditor/Tree/schemaInOriginalOrder.d.ts +5 -0
  54. package/dist/esm/SchemaEditor/Tree/schemaInOriginalOrder.d.ts.map +1 -0
  55. package/dist/esm/SchemaEditor/Tree/schemaInOriginalOrder.js +10 -0
  56. package/dist/esm/SchemaEditor/Tree/schemaInOriginalOrder.js.map +1 -0
  57. package/dist/esm/SchemaEditor/Tree/schemaPropertyType.d.ts +11 -0
  58. package/dist/esm/SchemaEditor/Tree/schemaPropertyType.d.ts.map +1 -0
  59. package/dist/esm/SchemaEditor/Tree/schemaPropertyType.js +31 -0
  60. package/dist/esm/SchemaEditor/Tree/schemaPropertyType.js.map +1 -0
  61. package/dist/esm/SchemaEditor/Tree/standardKeywords.d.ts +18 -0
  62. package/dist/esm/SchemaEditor/Tree/standardKeywords.d.ts.map +1 -0
  63. package/dist/esm/SchemaEditor/Tree/standardKeywords.js +22 -0
  64. package/dist/esm/SchemaEditor/Tree/standardKeywords.js.map +1 -0
  65. package/dist/esm/SchemaEditor/defaultSchemaEditorLabels.d.ts.map +1 -1
  66. package/dist/esm/SchemaEditor/defaultSchemaEditorLabels.js +3 -0
  67. package/dist/esm/SchemaEditor/defaultSchemaEditorLabels.js.map +1 -1
  68. package/dist/esm/SchemaEditor/index.d.ts +1 -1
  69. package/dist/esm/SchemaEditor/index.d.ts.map +1 -1
  70. package/dist/esm/SchemaEditor/index.js +1 -1
  71. package/dist/esm/SchemaEditor/schemaHelpers.d.ts +9 -0
  72. package/dist/esm/SchemaEditor/schemaHelpers.d.ts.map +1 -1
  73. package/dist/esm/SchemaEditor/schemaHelpers.js +20 -1
  74. package/dist/esm/SchemaEditor/schemaHelpers.js.map +1 -1
  75. package/dist/esm/styles.SchemaEditor.css +7 -10
  76. package/dist/esm/styles.css +7 -10
  77. package/dist/esm/types/parts.d.ts +2 -1
  78. package/dist/esm/types/parts.d.ts.map +1 -1
  79. package/dist/esm/types/parts.js +2 -1
  80. package/dist/esm/types/parts.js.map +1 -1
  81. 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,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,EACvB,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,SAAS,EACvB,iBAAiB,EAAE,cAAc,EACjC,SAAS,EACT,EAAE,GACkB,KAAI;AACxB,IAAA,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,yBAAyB,CAAC,cAAc,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC;AACzF,IAAA,MAAM,gBAAgB,GAAG,2BAA2B,EAAE;AACtD,IAAA,MAAM,QAAQ,GAAG,gBAAgB,IAAI,gBAAgB;AACrD,IAAA,MAAM,YAAY,GAAG,oBAAoB,KAAK,SAAS;AACvD,IAAA,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,QAAQ,CAAa,MAAM,sBAAsB,CAAC,MAAM,CAA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EAAA,EAAK,SAAS,EAAC,+BAA+B,EAAA,QAAA,EAAA,CACzC,CAAC,QAAQ,IAAI,OAAO,KACjBA,KAAC,gBAAgB,EAAA,EACb,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAC,KAAK,EACjB,YAAY,EAAE,MAAM,CAAC,WAAW,EAChC,KAAK,EAAE,EAAE,EACT,QAAQ,EAAE,OAAO,EAAA,QAAA,EAAA,CAEjBD,GAAA,CAAC,MAAM,EAAA,EAAA,aAAA,EAAa,MAAM,EAAA,CAAG,EAC5B,MAAM,CAAC,WAAW,CAAA,EAAA,CACJ,CACtB,EACA,MAAM,KACHA,GAAA,CAAA,KAAA,EAAA,EAAA,GAAS,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,CAAA,6BAAA,EAAgC,EAAE,EAAE,MAAM,EAAE,SAAS,IAAI,EAAE,CAAA,CAAE,EAAA,kBAAA,EAAmB,QAAQ,EAAA,QAAA,EACnH,MAAM,EAAA,CACL,CACT,CAAA,EAAA,CACC,CACT,CAAA,EAAA,CACC,EAAA,CACqB;AAEvC;;"}
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 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,K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CACD,CACR,EAEA,CAAC,MAAM,KAAK,CAAC,QAAQ,IAAI,OAAO,CAAC,MAC9BC,IAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,+BAA+B,EAAA,QAAA,EAAA,CACzC,CAAC,QAAQ,IAAI,OAAO,KACjBA,KAAC,gBAAgB,EAAA,EACb,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAC,KAAK,EACjB,YAAY,EAAE,MAAM,CAAC,WAAW,EAChC,KAAK,EAAE,EAAE,EACT,QAAQ,EAAE,OAAO,EAAA,QAAA,EAAA,CAEjBD,GAAA,CAAC,MAAM,EAAA,EAAA,aAAA,EAAa,MAAM,EAAA,CAAG,EAC5B,MAAM,CAAC,WAAW,CAAA,EAAA,CACJ,CACtB,EACA,MAAM,KACHA,GAAA,CAAA,KAAA,EAAA,EAAA,GAAS,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,CAAA,6BAAA,EAAgC,EAAE,EAAE,MAAM,EAAE,SAAS,IAAI,EAAE,CAAA,CAAE,EAAA,kBAAA,EAAmB,QAAQ,EAAA,QAAA,EACnH,MAAM,EAAA,CACL,CACT,CAAA,EAAA,CACC,CACT,CAAA,EAAA,CACC,EAAA,CACqB;AAEvC;;"}
@@ -0,0 +1,41 @@
1
+ import { KeywordFamily } from './KeywordFamily.js';
2
+ import { PropertyType } from './PropertyType.js';
3
+ /**
4
+ * The keyword family of a property type.
5
+ * @param type The property type.
6
+ * @returns The family whose constraints apply to values of the type.
7
+ */
8
+ export declare function propertyTypeFamily(type: PropertyType): KeywordFamily;
9
+ /**
10
+ * The keyword family of a JSON Schema `type` value.
11
+ * @param type The `type` keyword of a schema node.
12
+ * @returns The family whose constraints apply to values of the type.
13
+ */
14
+ export declare function jsonTypeFamily(type: unknown): KeywordFamily;
15
+ /**
16
+ * Whether a standard keyword that the editor does not model still applies after the type changed.
17
+ * Annotations always apply and a family's constraints apply while the family stays the same; value
18
+ * keywords (default, enum, const, examples), type refinements and every other keyword do not. The modelled
19
+ * keywords (type, format, items, properties, required) and `x-` keywords are not decided here.
20
+ * @param keyword The keyword name.
21
+ * @param from The family of the type before the change.
22
+ * @param to The family of the type after the change.
23
+ * @returns True when the keyword applies to the new type.
24
+ */
25
+ export declare function isKeywordApplicable(keyword: string, from: KeywordFamily, to: KeywordFamily): boolean;
26
+ /**
27
+ * Keeps the keywords that still apply after the type changed.
28
+ * @param keywords The standard keywords the editor does not model.
29
+ * @param from The family of the type before the change.
30
+ * @param to The family of the type after the change.
31
+ * @returns The keywords that apply; empty when none do.
32
+ */
33
+ export declare function keywordsAfterTypeChange(keywords: Readonly<Record<string, unknown>>, from: KeywordFamily, to: KeywordFamily): Record<string, unknown>;
34
+ /**
35
+ * Whether a keyword survives a change between refinements of one type, such as integer and number: the
36
+ * constraints stay, but the value keywords and `multipleOf` described the old refinement.
37
+ * @param keyword The keyword name.
38
+ * @returns True when the keyword still applies.
39
+ */
40
+ export declare function isKeywordApplicableToRefinement(keyword: string): boolean;
41
+ //# sourceMappingURL=keywordApplicability.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keywordApplicability.d.ts","sourceRoot":"","sources":["../../../../SchemaEditor/Tree/keywordApplicability.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAgB,CAAC;AA6B9C;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,YAAY,GAAG,aAAa,CAEpE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,aAAa,CAc3D;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,EAAE,aAAa,GAAG,OAAO,CAEpG;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACnC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAC3C,IAAI,EAAE,aAAa,EACnB,EAAE,EAAE,aAAa,GAClB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzB;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAExE"}
@@ -0,0 +1,56 @@
1
+ import { KeywordFamily } from './KeywordFamily.js';
2
+ import { PropertyType } from './PropertyType.js';
3
+
4
+ const annotations = new Set(['title', 'description', '$comment', 'deprecated', 'readOnly', 'writeOnly']);
5
+ const refinementKeywords = new Set(['default', 'enum', 'const', 'examples', 'multipleOf']);
6
+ const familyKeywords = {
7
+ [KeywordFamily.None]: new Set(),
8
+ [KeywordFamily.String]: new Set(['minLength', 'maxLength', 'pattern', 'contentEncoding', 'contentMediaType']),
9
+ [KeywordFamily.Number]: new Set(['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum', 'multipleOf']),
10
+ [KeywordFamily.Array]: new Set(['minItems', 'maxItems', 'uniqueItems', 'contains', 'minContains', 'maxContains']),
11
+ [KeywordFamily.Object]: new Set([
12
+ 'minProperties', 'maxProperties', 'additionalProperties', 'patternProperties', 'propertyNames',
13
+ 'dependentRequired', 'dependentSchemas', 'unevaluatedProperties',
14
+ ]),
15
+ };
16
+ const typeFamilies = {
17
+ [PropertyType.String]: KeywordFamily.String,
18
+ [PropertyType.Date]: KeywordFamily.String,
19
+ [PropertyType.Time]: KeywordFamily.String,
20
+ [PropertyType.Number]: KeywordFamily.Number,
21
+ [PropertyType.Boolean]: KeywordFamily.None,
22
+ [PropertyType.Object]: KeywordFamily.Object,
23
+ [PropertyType.StringArray]: KeywordFamily.Array,
24
+ [PropertyType.NumberArray]: KeywordFamily.Array,
25
+ [PropertyType.ObjectArray]: KeywordFamily.Array,
26
+ };
27
+ function propertyTypeFamily(type) {
28
+ return typeFamilies[type];
29
+ }
30
+ function jsonTypeFamily(type) {
31
+ switch (type) {
32
+ case 'string':
33
+ return KeywordFamily.String;
34
+ case 'number':
35
+ case 'integer':
36
+ return KeywordFamily.Number;
37
+ case 'array':
38
+ return KeywordFamily.Array;
39
+ case 'object':
40
+ return KeywordFamily.Object;
41
+ default:
42
+ return KeywordFamily.None;
43
+ }
44
+ }
45
+ function isKeywordApplicable(keyword, from, to) {
46
+ return annotations.has(keyword) || (from === to && familyKeywords[to].has(keyword));
47
+ }
48
+ function keywordsAfterTypeChange(keywords, from, to) {
49
+ return Object.fromEntries(Object.entries(keywords).filter(([keyword]) => isKeywordApplicable(keyword, from, to)));
50
+ }
51
+ function isKeywordApplicableToRefinement(keyword) {
52
+ return !refinementKeywords.has(keyword);
53
+ }
54
+
55
+ export { isKeywordApplicable, isKeywordApplicableToRefinement, jsonTypeFamily, keywordsAfterTypeChange, propertyTypeFamily };
56
+ //# sourceMappingURL=keywordApplicability.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keywordApplicability.js","sources":["../../../../SchemaEditor/Tree/keywordApplicability.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 { KeywordFamily } from './KeywordFamily';\nimport { PropertyType } from './PropertyType';\n\nconst annotations: ReadonlySet<string> = new Set(['title', 'description', '$comment', 'deprecated', 'readOnly', 'writeOnly']);\n\nconst refinementKeywords: ReadonlySet<string> = new Set(['default', 'enum', 'const', 'examples', 'multipleOf']);\n\nconst familyKeywords: Readonly<Record<KeywordFamily, ReadonlySet<string>>> = {\n [KeywordFamily.None]: new Set(),\n [KeywordFamily.String]: new Set(['minLength', 'maxLength', 'pattern', 'contentEncoding', 'contentMediaType']),\n [KeywordFamily.Number]: new Set(['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum', 'multipleOf']),\n [KeywordFamily.Array]: new Set(['minItems', 'maxItems', 'uniqueItems', 'contains', 'minContains', 'maxContains']),\n [KeywordFamily.Object]: new Set([\n 'minProperties', 'maxProperties', 'additionalProperties', 'patternProperties', 'propertyNames',\n 'dependentRequired', 'dependentSchemas', 'unevaluatedProperties',\n ]),\n};\n\nconst typeFamilies: Readonly<Record<PropertyType, KeywordFamily>> = {\n [PropertyType.String]: KeywordFamily.String,\n [PropertyType.Date]: KeywordFamily.String,\n [PropertyType.Time]: KeywordFamily.String,\n [PropertyType.Number]: KeywordFamily.Number,\n [PropertyType.Boolean]: KeywordFamily.None,\n [PropertyType.Object]: KeywordFamily.Object,\n [PropertyType.StringArray]: KeywordFamily.Array,\n [PropertyType.NumberArray]: KeywordFamily.Array,\n [PropertyType.ObjectArray]: KeywordFamily.Array,\n};\n\n/**\n * The keyword family of a property type.\n * @param type The property type.\n * @returns The family whose constraints apply to values of the type.\n */\nexport function propertyTypeFamily(type: PropertyType): KeywordFamily {\n return typeFamilies[type];\n}\n\n/**\n * The keyword family of a JSON Schema `type` value.\n * @param type The `type` keyword of a schema node.\n * @returns The family whose constraints apply to values of the type.\n */\nexport function jsonTypeFamily(type: unknown): KeywordFamily {\n switch (type) {\n case 'string':\n return KeywordFamily.String;\n case 'number':\n case 'integer':\n return KeywordFamily.Number;\n case 'array':\n return KeywordFamily.Array;\n case 'object':\n return KeywordFamily.Object;\n default:\n return KeywordFamily.None;\n }\n}\n\n/**\n * Whether a standard keyword that the editor does not model still applies after the type changed.\n * Annotations always apply and a family's constraints apply while the family stays the same; value\n * keywords (default, enum, const, examples), type refinements and every other keyword do not. The modelled\n * keywords (type, format, items, properties, required) and `x-` keywords are not decided here.\n * @param keyword The keyword name.\n * @param from The family of the type before the change.\n * @param to The family of the type after the change.\n * @returns True when the keyword applies to the new type.\n */\nexport function isKeywordApplicable(keyword: string, from: KeywordFamily, to: KeywordFamily): boolean {\n return annotations.has(keyword) || (from === to && familyKeywords[to].has(keyword));\n}\n\n/**\n * Keeps the keywords that still apply after the type changed.\n * @param keywords The standard keywords the editor does not model.\n * @param from The family of the type before the change.\n * @param to The family of the type after the change.\n * @returns The keywords that apply; empty when none do.\n */\nexport function keywordsAfterTypeChange(\n keywords: Readonly<Record<string, unknown>>,\n from: KeywordFamily,\n to: KeywordFamily,\n): Record<string, unknown> {\n return Object.fromEntries(Object.entries(keywords).filter(([keyword]) => isKeywordApplicable(keyword, from, to)));\n}\n\n/**\n * Whether a keyword survives a change between refinements of one type, such as integer and number: the\n * constraints stay, but the value keywords and `multipleOf` described the old refinement.\n * @param keyword The keyword name.\n * @returns True when the keyword still applies.\n */\nexport function isKeywordApplicableToRefinement(keyword: string): boolean {\n return !refinementKeywords.has(keyword);\n}\n"],"names":[],"mappings":";;;AAMA,MAAM,WAAW,GAAwB,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;AAE7H,MAAM,kBAAkB,GAAwB,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC;AAE/G,MAAM,cAAc,GAAyD;AACzE,IAAA,CAAC,aAAa,CAAC,IAAI,GAAG,IAAI,GAAG,EAAE;AAC/B,IAAA,CAAC,aAAa,CAAC,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,iBAAiB,EAAE,kBAAkB,CAAC,CAAC;AAC7G,IAAA,CAAC,aAAa,CAAC,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,YAAY,CAAC,CAAC;IAC7G,CAAC,aAAa,CAAC,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC;AACjH,IAAA,CAAC,aAAa,CAAC,MAAM,GAAG,IAAI,GAAG,CAAC;AAC5B,QAAA,eAAe,EAAE,eAAe,EAAE,sBAAsB,EAAE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I,cAAc,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACvF;SASgB,uBAAuB,CACnC,QAA2C,EAC3C,IAAmB,EACnB,EAAiB,EAAA;AAEjB,IAAA,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,mBAAmB,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;AACrH;AAQM,SAAU,+BAA+B,CAAC,OAAe,EAAA;AAC3D,IAAA,OAAO,CAAC,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAAC;AAC3C;;"}
@@ -0,0 +1,30 @@
1
+ import { PropertyType } from './PropertyType.js';
2
+ import { type SchemaOrderedProperty } from './SchemaOrderedProperty.js';
3
+ import type { SchemaOriginalShape } from './SchemaOriginalShape.js';
4
+ type SchemaNode = Record<string, unknown>;
5
+ /** Whether a schema value is an object node rather than a boolean, an array or a scalar. */
6
+ export declare function isNode(value: unknown): value is SchemaNode;
7
+ /**
8
+ * Reads the `type` and `format` of a property node, and of its items node, exactly as they are written.
9
+ * @param node The property schema node.
10
+ * @param type The property type the node reads as.
11
+ * @returns The shape to restore while the property type is unchanged.
12
+ */
13
+ export declare function readOriginalShape(node: SchemaNode, type: PropertyType): SchemaOriginalShape;
14
+ /**
15
+ * Reads the order of the `required` names of an object, or of the items of an object list.
16
+ * @param node The property schema node.
17
+ * @param type The property type the node reads as.
18
+ * @returns The names in their original order, or undefined when there is no list.
19
+ */
20
+ export declare function readRequiredOrder(node: SchemaNode, type: PropertyType): readonly string[] | undefined;
21
+ /**
22
+ * Puts the original `type`, `format` and items of a property node back, while the property still has the
23
+ * type it was read with. A property whose type changed, or that was created in the editor, is returned as is.
24
+ * @param schema The node the editor would write.
25
+ * @param property The property the node is written for.
26
+ * @returns The node with its original shape.
27
+ */
28
+ export declare function restoreOriginalShape(schema: SchemaNode, property: SchemaOrderedProperty): SchemaNode;
29
+ export {};
30
+ //# sourceMappingURL=originalShape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"originalShape.d.ts","sourceRoot":"","sources":["../../../../SchemaEditor/Tree/originalShape.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAgB,CAAC;AAC9C,OAAO,EAAuB,KAAK,qBAAqB,EAAE,MAAM,4BAAyB,CAAC;AAC1F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAAuB,CAAC;AAEjE,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE1C,4FAA4F;AAC5F,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAE1D;AAgBD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,GAAG,mBAAmB,CAQ3F;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,CAGrG;AA4BD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,qBAAqB,GAAG,UAAU,CAKpG"}
@@ -0,0 +1,70 @@
1
+ import { KeywordFamily } from './KeywordFamily.js';
2
+ import { propertyTypeFamily } from './keywordApplicability.js';
3
+ import { PropertyType } from './PropertyType.js';
4
+ import { schemaOriginalShape } from './SchemaOrderedProperty.js';
5
+
6
+ function isNode(value) {
7
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
8
+ }
9
+ function present(node, names) {
10
+ return Object.fromEntries(names.filter(name => Object.hasOwn(node, name)).map(name => [name, node[name]]));
11
+ }
12
+ function itemsShape(node) {
13
+ if (node.type !== 'array' || !Object.hasOwn(node, 'items'))
14
+ return {};
15
+ return isNode(node.items) ? { item: present(node.items, ['type', 'format']) } : { rawItems: { value: node.items } };
16
+ }
17
+ function containerOf(node, type) {
18
+ if (type === PropertyType.Object)
19
+ return node;
20
+ return type === PropertyType.ObjectArray && isNode(node.items) ? node.items : undefined;
21
+ }
22
+ function readOriginalShape(node, type) {
23
+ const container = containerOf(node, type);
24
+ return {
25
+ propertyType: type,
26
+ node: present(node, ['type', 'format']),
27
+ ...itemsShape(node),
28
+ ...(container && !isNode(container.properties) ? { withoutProperties: true } : {}),
29
+ };
30
+ }
31
+ function readRequiredOrder(node, type) {
32
+ const required = containerOf(node, type)?.required;
33
+ return Array.isArray(required) ? required.filter((name) => typeof name === 'string') : undefined;
34
+ }
35
+ function restoreNode(node, original) {
36
+ const restored = { ...node };
37
+ delete restored.type;
38
+ delete restored.format;
39
+ return { ...restored, ...original };
40
+ }
41
+ function restoreItems(schema, shape) {
42
+ if (propertyTypeFamily(shape.propertyType) !== KeywordFamily.Array)
43
+ return schema;
44
+ const { items, ...rest } = schema;
45
+ if (shape.rawItems)
46
+ return { ...rest, items: shape.rawItems.value };
47
+ return shape.item ? { ...rest, items: restoreNode(items, shape.item) } : rest;
48
+ }
49
+ function withoutProperties(node) {
50
+ const copy = { ...node };
51
+ delete copy.properties;
52
+ return copy;
53
+ }
54
+ function restoreContainer(schema, shape, hasChildren) {
55
+ if (!shape.withoutProperties || hasChildren)
56
+ return schema;
57
+ if (shape.propertyType === PropertyType.ObjectArray)
58
+ return { ...schema, items: withoutProperties(schema.items) };
59
+ return withoutProperties(schema);
60
+ }
61
+ function restoreOriginalShape(schema, property) {
62
+ const shape = property[schemaOriginalShape];
63
+ if (!shape || shape.propertyType !== property.type)
64
+ return schema;
65
+ const restored = restoreItems(restoreNode(schema, shape.node), shape);
66
+ return restoreContainer(restored, shape, (property.children ?? []).length > 0);
67
+ }
68
+
69
+ export { isNode, readOriginalShape, readRequiredOrder, restoreOriginalShape };
70
+ //# sourceMappingURL=originalShape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"originalShape.js","sources":["../../../../SchemaEditor/Tree/originalShape.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 { KeywordFamily } from './KeywordFamily';\nimport { propertyTypeFamily } from './keywordApplicability';\nimport { PropertyType } from './PropertyType';\nimport { schemaOriginalShape, type SchemaOrderedProperty } from './SchemaOrderedProperty';\nimport type { SchemaOriginalShape } from './SchemaOriginalShape';\n\ntype SchemaNode = Record<string, unknown>;\n\n/** Whether a schema value is an object node rather than a boolean, an array or a scalar. */\nexport function isNode(value: unknown): value is SchemaNode {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction present(node: SchemaNode, names: readonly string[]): Record<string, unknown> {\n return Object.fromEntries(names.filter(name => Object.hasOwn(node, name)).map(name => [name, node[name]]));\n}\n\nfunction itemsShape(node: SchemaNode): Pick<SchemaOriginalShape, 'item' | 'rawItems'> {\n if (node.type !== 'array' || !Object.hasOwn(node, 'items')) return {};\n return isNode(node.items) ? { item: present(node.items, ['type', 'format']) } : { rawItems: { value: node.items } };\n}\n\nfunction containerOf(node: SchemaNode, type: PropertyType): SchemaNode | undefined {\n if (type === PropertyType.Object) return node;\n return type === PropertyType.ObjectArray && isNode(node.items) ? node.items : undefined;\n}\n\n/**\n * Reads the `type` and `format` of a property node, and of its items node, exactly as they are written.\n * @param node The property schema node.\n * @param type The property type the node reads as.\n * @returns The shape to restore while the property type is unchanged.\n */\nexport function readOriginalShape(node: SchemaNode, type: PropertyType): SchemaOriginalShape {\n const container = containerOf(node, type);\n return {\n propertyType: type,\n node: present(node, ['type', 'format']),\n ...itemsShape(node),\n ...(container && !isNode(container.properties) ? { withoutProperties: true } : {}),\n };\n}\n\n/**\n * Reads the order of the `required` names of an object, or of the items of an object list.\n * @param node The property schema node.\n * @param type The property type the node reads as.\n * @returns The names in their original order, or undefined when there is no list.\n */\nexport function readRequiredOrder(node: SchemaNode, type: PropertyType): readonly string[] | undefined {\n const required = containerOf(node, type)?.required;\n return Array.isArray(required) ? required.filter((name): name is string => typeof name === 'string') : undefined;\n}\n\nfunction restoreNode(node: SchemaNode, original: Readonly<Record<string, unknown>>): SchemaNode {\n const restored = { ...node };\n delete restored.type;\n delete restored.format;\n return { ...restored, ...original };\n}\n\nfunction restoreItems(schema: SchemaNode, shape: SchemaOriginalShape): SchemaNode {\n if (propertyTypeFamily(shape.propertyType) !== KeywordFamily.Array) return schema;\n const { items, ...rest } = schema;\n if (shape.rawItems) return { ...rest, items: shape.rawItems.value };\n return shape.item ? { ...rest, items: restoreNode(items as SchemaNode, shape.item) } : rest;\n}\n\nfunction withoutProperties(node: SchemaNode): SchemaNode {\n const copy = { ...node };\n delete copy.properties;\n return copy;\n}\n\nfunction restoreContainer(schema: SchemaNode, shape: SchemaOriginalShape, hasChildren: boolean): SchemaNode {\n if (!shape.withoutProperties || hasChildren) return schema;\n if (shape.propertyType === PropertyType.ObjectArray) return { ...schema, items: withoutProperties(schema.items as SchemaNode) };\n return withoutProperties(schema);\n}\n\n/**\n * Puts the original `type`, `format` and items of a property node back, while the property still has the\n * type it was read with. A property whose type changed, or that was created in the editor, is returned as is.\n * @param schema The node the editor would write.\n * @param property The property the node is written for.\n * @returns The node with its original shape.\n */\nexport function restoreOriginalShape(schema: SchemaNode, property: SchemaOrderedProperty): SchemaNode {\n const shape = property[schemaOriginalShape];\n if (!shape || shape.propertyType !== property.type) return schema;\n const restored = restoreItems(restoreNode(schema, shape.node), shape);\n return restoreContainer(restored, shape, (property.children ?? []).length > 0);\n}\n"],"names":[],"mappings":";;;;;AAYM,SAAU,MAAM,CAAC,KAAc,EAAA;AACjC,IAAA,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;AAC/E;AAEA,SAAS,OAAO,CAAC,IAAgB,EAAE,KAAwB,EAAA;AACvD,IAAA,OAAO,MA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,EAAE,WAAoB,EAAA;AAC1F,IAAA,IAAI,CAAC,KAAK,CAAC,iBAAiB,IAAI,WAAW;AAAE,QAAA,OAAO,MAAM;AAC1D,IAAA,IAAI,KAAK,CAAC,YAAY,KAAK,YAAY,CAAC,WAAW;AAAE,QAAA,OAAO,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,iBAAiB,CAAC,MAAM,CAAC,KAAmB,CAAC,EAAE;AAC/H,IAAA,OAAO,iBAAiB,CAAC,MAAM,CAAC;AACpC;AASM,SAAU,oBAAoB,CAAC,MAAkB,EAAE,QAA+B,EAAA;AACpF,IAAA,MAAM,KAAK,GAAG,QAAQ,CAAC,mBAAmB,CAAC;IAC3C,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,YAAY,KAAK,QAAQ,CAAC,IAAI;AAAE,QAAA,OAAO,MAAM;AACjE,IAAA,MAAM,QAAQ,GAAG,YAAY,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC;AACrE,IAAA,OAAO,gBAAgB,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,QAAQ,CAAC,QAAQ,IAAI,EAAE,EAAE,MAAM,GAAG,CAAC,CAAC;AAClF;;"}
@@ -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 and the
26
+ * standard keywords the editor does not model are 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,9 @@ 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 type keeps the annotations and the
69
+ * constraints of the same keyword family, and drops value keywords, the original type and format, item metadata
70
+ * and every other standard keyword that no longer applies. The same type keeps everything.
65
71
  * @param properties The root properties.
66
72
  * @param targetId The id of the property.
67
73
  * @param newType The new type.
@@ -84,6 +90,14 @@ export declare function toggleRequiredProperty(properties: Property[], targetId:
84
90
  * @returns The new tree.
85
91
  */
86
92
  export declare function setRequiredProperty(properties: Property[], targetId: string, isRequired: boolean): Property[];
93
+ /**
94
+ * Sets whether a property's value is generated. An explicit edit replaces any non-true x-generated value.
95
+ * @param properties The root properties.
96
+ * @param targetId The id of the property.
97
+ * @param isGenerated Whether the value is generated.
98
+ * @returns The new tree.
99
+ */
100
+ export declare function setGeneratedProperty(properties: Property[], targetId: string, isGenerated: boolean): Property[];
87
101
  /**
88
102
  * Makes a property the key of its parent object, moving the key when a sibling held it. Choosing the
89
103
  * 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,OA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