@cratis/components 4.25.1 → 4.26.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/Canvas/canvasZoomListeners.d.ts +30 -0
- package/dist/esm/Canvas/canvasZoomListeners.d.ts.map +1 -0
- package/dist/esm/Canvas/canvasZoomListeners.js +121 -0
- package/dist/esm/Canvas/canvasZoomListeners.js.map +1 -0
- package/dist/esm/Canvas/useCanvasWheelZoom.d.ts +2 -1
- package/dist/esm/Canvas/useCanvasWheelZoom.d.ts.map +1 -1
- package/dist/esm/Canvas/useCanvasWheelZoom.js +24 -132
- package/dist/esm/Canvas/useCanvasWheelZoom.js.map +1 -1
- package/dist/esm/SchemaEditor/NameCell.d.ts +5 -1
- package/dist/esm/SchemaEditor/NameCell.d.ts.map +1 -1
- package/dist/esm/SchemaEditor/NameCell.js +2 -2
- package/dist/esm/SchemaEditor/NameCell.js.map +1 -1
- package/dist/esm/SchemaEditor/SchemaEditor.d.ts +63 -48
- package/dist/esm/SchemaEditor/SchemaEditor.d.ts.map +1 -1
- package/dist/esm/SchemaEditor/SchemaEditor.js +83 -25
- package/dist/esm/SchemaEditor/SchemaEditor.js.map +1 -1
- package/dist/esm/SchemaEditor/SchemaEditorLabels.d.ts +98 -0
- package/dist/esm/SchemaEditor/SchemaEditorLabels.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/SchemaEditorLabels.js +4 -0
- package/dist/esm/SchemaEditor/SchemaEditorLabels.js.map +1 -0
- package/dist/esm/SchemaEditor/SchemaEditorLayout.d.ts +6 -0
- package/dist/esm/SchemaEditor/SchemaEditorLayout.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/SchemaEditorLayout.js +4 -0
- package/dist/esm/SchemaEditor/SchemaEditorLayout.js.map +1 -0
- package/dist/esm/SchemaEditor/Tree/Property.d.ts +30 -0
- package/dist/esm/SchemaEditor/Tree/Property.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/Tree/Property.js +4 -0
- package/dist/esm/SchemaEditor/Tree/Property.js.map +1 -0
- package/dist/esm/SchemaEditor/Tree/PropertyConcept.d.ts +15 -0
- package/dist/esm/SchemaEditor/Tree/PropertyConcept.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/Tree/PropertyConcept.js +4 -0
- package/dist/esm/SchemaEditor/Tree/PropertyConcept.js.map +1 -0
- package/dist/esm/SchemaEditor/Tree/PropertyConceptsContext.d.ts +22 -0
- package/dist/esm/SchemaEditor/Tree/PropertyConceptsContext.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/Tree/PropertyConceptsContext.js +10 -0
- package/dist/esm/SchemaEditor/Tree/PropertyConceptsContext.js.map +1 -0
- package/dist/esm/SchemaEditor/Tree/PropertyType.d.ts +22 -0
- package/dist/esm/SchemaEditor/Tree/PropertyType.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/Tree/PropertyType.js +15 -0
- package/dist/esm/SchemaEditor/Tree/PropertyType.js.map +1 -0
- package/dist/esm/SchemaEditor/Tree/PropertyTypeBadge.d.ts +20 -0
- package/dist/esm/SchemaEditor/Tree/PropertyTypeBadge.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/Tree/PropertyTypeBadge.js +11 -0
- package/dist/esm/SchemaEditor/Tree/PropertyTypeBadge.js.map +1 -0
- package/dist/esm/SchemaEditor/Tree/PropertyTypeMenu.d.ts +28 -0
- package/dist/esm/SchemaEditor/Tree/PropertyTypeMenu.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/Tree/PropertyTypeMenu.js +37 -0
- package/dist/esm/SchemaEditor/Tree/PropertyTypeMenu.js.map +1 -0
- package/dist/esm/SchemaEditor/Tree/SchemaEditorContext.d.ts +42 -0
- package/dist/esm/SchemaEditor/Tree/SchemaEditorContext.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/Tree/SchemaEditorContext.js +12 -0
- package/dist/esm/SchemaEditor/Tree/SchemaEditorContext.js.map +1 -0
- package/dist/esm/SchemaEditor/Tree/SchemaEditorParts.d.ts +60 -0
- package/dist/esm/SchemaEditor/Tree/SchemaEditorParts.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/Tree/SchemaEditorParts.js +4 -0
- package/dist/esm/SchemaEditor/Tree/SchemaEditorParts.js.map +1 -0
- package/dist/esm/SchemaEditor/Tree/SchemaPropertyContext.d.ts +13 -0
- package/dist/esm/SchemaEditor/Tree/SchemaPropertyContext.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/Tree/SchemaPropertyContext.js +4 -0
- package/dist/esm/SchemaEditor/Tree/SchemaPropertyContext.js.map +1 -0
- package/dist/esm/SchemaEditor/Tree/SchemaPropertyRow.d.ts +13 -0
- package/dist/esm/SchemaEditor/Tree/SchemaPropertyRow.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/Tree/SchemaPropertyRow.js +107 -0
- package/dist/esm/SchemaEditor/Tree/SchemaPropertyRow.js.map +1 -0
- package/dist/esm/SchemaEditor/Tree/SchemaPropertyRowState.d.ts +16 -0
- package/dist/esm/SchemaEditor/Tree/SchemaPropertyRowState.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/Tree/SchemaPropertyRowState.js +4 -0
- package/dist/esm/SchemaEditor/Tree/SchemaPropertyRowState.js.map +1 -0
- package/dist/esm/SchemaEditor/Tree/TreeSchemaEditor.d.ts +116 -0
- package/dist/esm/SchemaEditor/Tree/TreeSchemaEditor.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/Tree/TreeSchemaEditor.js +96 -0
- package/dist/esm/SchemaEditor/Tree/TreeSchemaEditor.js.map +1 -0
- package/dist/esm/SchemaEditor/Tree/propertyNaming.d.ts +35 -0
- package/dist/esm/SchemaEditor/Tree/propertyNaming.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/Tree/propertyNaming.js +34 -0
- package/dist/esm/SchemaEditor/Tree/propertyNaming.js.map +1 -0
- package/dist/esm/SchemaEditor/Tree/propertyTree.d.ts +30 -0
- package/dist/esm/SchemaEditor/Tree/propertyTree.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/Tree/propertyTree.js +36 -0
- package/dist/esm/SchemaEditor/Tree/propertyTree.js.map +1 -0
- package/dist/esm/SchemaEditor/Tree/propertyTypeDisplay.d.ts +22 -0
- package/dist/esm/SchemaEditor/Tree/propertyTypeDisplay.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/Tree/propertyTypeDisplay.js +45 -0
- package/dist/esm/SchemaEditor/Tree/propertyTypeDisplay.js.map +1 -0
- package/dist/esm/SchemaEditor/Tree/schemaConversion.d.ts +95 -0
- package/dist/esm/SchemaEditor/Tree/schemaConversion.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/Tree/schemaConversion.js +171 -0
- package/dist/esm/SchemaEditor/Tree/schemaConversion.js.map +1 -0
- package/dist/esm/SchemaEditor/TypeCell.d.ts +3 -1
- package/dist/esm/SchemaEditor/TypeCell.d.ts.map +1 -1
- package/dist/esm/SchemaEditor/TypeCell.js +2 -2
- package/dist/esm/SchemaEditor/TypeCell.js.map +1 -1
- package/dist/esm/SchemaEditor/defaultSchemaEditorLabels.d.ts +9 -0
- package/dist/esm/SchemaEditor/defaultSchemaEditorLabels.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/defaultSchemaEditorLabels.js +51 -0
- package/dist/esm/SchemaEditor/defaultSchemaEditorLabels.js.map +1 -0
- package/dist/esm/SchemaEditor/index.d.ts +12 -0
- package/dist/esm/SchemaEditor/index.d.ts.map +1 -1
- package/dist/esm/SchemaEditor/index.js +7 -1
- package/dist/esm/SchemaEditor/index.js.map +1 -1
- package/dist/esm/SchemaEditor/resolveSchemaEditorLabels.d.ts +4 -0
- package/dist/esm/SchemaEditor/resolveSchemaEditorLabels.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/resolveSchemaEditorLabels.js +13 -0
- package/dist/esm/SchemaEditor/resolveSchemaEditorLabels.js.map +1 -0
- package/dist/esm/styles.SchemaEditor.css +346 -0
- package/dist/esm/styles.css +346 -0
- package/dist/esm/types/parts.d.ts +25 -0
- package/dist/esm/types/parts.d.ts.map +1 -1
- package/dist/esm/types/parts.js +25 -0
- package/dist/esm/types/parts.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { ChangeHandler } from '../../types/ChangeHandler.js';
|
|
3
|
+
import type { JsonSchema } from '../../types/JsonSchema.js';
|
|
4
|
+
import type { Property } from './Property.js';
|
|
5
|
+
import type { PropertyConcept } from './PropertyConcept.js';
|
|
6
|
+
import { PropertyType } from './PropertyType.js';
|
|
7
|
+
import type { SchemaEditorLabels } from '../SchemaEditorLabels.js';
|
|
8
|
+
import type { SchemaEditorParts } from './SchemaEditorParts.js';
|
|
9
|
+
import type { SchemaPropertyContext } from './SchemaPropertyContext.js';
|
|
10
|
+
import type { SchemaPropertyRowState } from './SchemaPropertyRowState.js';
|
|
11
|
+
/** The props of the tree layout of the {@link SchemaEditor}. */
|
|
12
|
+
export interface TreeSchemaEditorProps {
|
|
13
|
+
/**
|
|
14
|
+
* The JSON Schema to edit. The editor converts it, keeps the edited property tree itself and reports every
|
|
15
|
+
* edit through {@link TreeSchemaEditorProps.onChange}. Passing the reported schema back, or the same schema
|
|
16
|
+
* again, changes nothing; passing a schema that differs from both replaces the tree and its property ids.
|
|
17
|
+
* Ignored when `properties` is given.
|
|
18
|
+
*/
|
|
19
|
+
schema?: JsonSchema;
|
|
20
|
+
/** Called with the complete schema after every edit. Only used when the editor owns the property tree. */
|
|
21
|
+
onChange?: ChangeHandler<JsonSchema>;
|
|
22
|
+
/** Called with the property tree after every edit, so a host can follow the ids. Only used when the editor owns the property tree. */
|
|
23
|
+
onPropertiesChange?: (properties: Property[]) => void;
|
|
24
|
+
/** Called after a property was removed, with the property and everything nested under it. Only used when the editor owns the property tree. */
|
|
25
|
+
onPropertyRemoved?: (property: Property) => void;
|
|
26
|
+
/** Called after a property was renamed, with the renamed property and the name it had. Only used when the editor owns the property tree. */
|
|
27
|
+
onPropertyRenamed?: (property: Property, previousName: string) => void;
|
|
28
|
+
/**
|
|
29
|
+
* The property tree to show. When given, the editor is controlled: it changes nothing itself and each edit
|
|
30
|
+
* is offered through the matching `onAddProperty`, `onDeleteProperty`… callback, which the host applies.
|
|
31
|
+
* An edit without a callback is not offered.
|
|
32
|
+
*/
|
|
33
|
+
properties?: Property[];
|
|
34
|
+
/** Controlled mode: add a property to the root. */
|
|
35
|
+
onAddProperty?: (type: PropertyType, concept?: string) => void;
|
|
36
|
+
/** Controlled mode: add a property to a nested object. */
|
|
37
|
+
onAddChildProperty?: (parentId: string, type: PropertyType, concept?: string) => void;
|
|
38
|
+
/** Controlled mode: remove a property. */
|
|
39
|
+
onDeleteProperty?: (propertyId: string) => void;
|
|
40
|
+
/** Controlled mode: rename a property. The name is already checked. */
|
|
41
|
+
onRenameProperty?: (propertyId: string, name: string) => void;
|
|
42
|
+
/** Controlled mode: change the type of a property. */
|
|
43
|
+
onChangePropertyType?: (propertyId: string, type: PropertyType, concept?: string) => void;
|
|
44
|
+
/** Controlled mode: make a property the key of its object, or clear it when it already is. */
|
|
45
|
+
onSetKeyProperty?: (propertyId: string) => void;
|
|
46
|
+
/** Controlled mode: set whether a property must be present. */
|
|
47
|
+
onSetRequiredProperty?: (propertyId: string, isRequired: boolean) => void;
|
|
48
|
+
/**
|
|
49
|
+
* The concepts a property can be typed as, offered after the primitive types. Takes precedence over the
|
|
50
|
+
* concepts of a surrounding {@link PropertyConceptsProvider}.
|
|
51
|
+
*/
|
|
52
|
+
concepts?: PropertyConcept[];
|
|
53
|
+
/**
|
|
54
|
+
* Offers the key toggle. `true` offers it on every property; a function decides per property, for example
|
|
55
|
+
* `(property, context) => context.depth > 0` to leave the root properties out. Off by default, except in
|
|
56
|
+
* controlled mode, where supplying `onSetKeyProperty` implies `true` unless this is explicitly `false`.
|
|
57
|
+
*/
|
|
58
|
+
allowKeyProperty?: boolean | ((property: Property, context: SchemaPropertyContext) => boolean);
|
|
59
|
+
/**
|
|
60
|
+
* Offers the toggle for whether a property must be present (the `required` list). Off by default, except in
|
|
61
|
+
* controlled mode, where supplying `onSetRequiredProperty` implies `true` unless this is explicitly `false`.
|
|
62
|
+
*/
|
|
63
|
+
allowRequired?: boolean;
|
|
64
|
+
/** Offers no edits at all: the tree is shown, and only selection and the host's slots remain. */
|
|
65
|
+
readOnly?: boolean;
|
|
66
|
+
/** Decides which properties can be neither renamed nor removed. By default none. */
|
|
67
|
+
isPropertyProtected?: (property: Property) => boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Extra check of a new name, after the editor has rejected blank, reserved and duplicate names.
|
|
70
|
+
* Return the message to show, or `undefined` to accept the name.
|
|
71
|
+
*/
|
|
72
|
+
validatePropertyName?: (name: string, property: Property, siblings: Property[]) => string | undefined;
|
|
73
|
+
/** The id of the property to mark as selected. */
|
|
74
|
+
selectedPropertyId?: string | null;
|
|
75
|
+
/** Called when a property's row is clicked, or its name is activated from the keyboard. */
|
|
76
|
+
onPropertyClick?: (propertyId: string) => void;
|
|
77
|
+
/** 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. */
|
|
78
|
+
header?: ReactNode;
|
|
79
|
+
/** Content beside the add button, for example further actions. */
|
|
80
|
+
footer?: ReactNode;
|
|
81
|
+
/** Content at the start of every row, before the name; for example a connector to drag from or onto. */
|
|
82
|
+
renderPropertyLeading?: (property: Property, context: SchemaPropertyContext) => ReactNode;
|
|
83
|
+
/** Content at the end of every row, before the remove button; for example a button that opens rules. */
|
|
84
|
+
renderPropertyAccessory?: (property: Property, context: SchemaPropertyContext) => ReactNode;
|
|
85
|
+
/** Content under every row, above its nested properties; for example the rules of the property. Nothing is rendered for `null`, `undefined` and `false`. */
|
|
86
|
+
renderPropertyDetails?: (property: Property, context: SchemaPropertyContext) => ReactNode;
|
|
87
|
+
/** Styles and marks the row of a property: extra class names, `data-*` attributes, a tooltip, and whether its type is locked. */
|
|
88
|
+
getPropertyRowState?: (property: Property, context: SchemaPropertyContext) => SchemaPropertyRowState | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* Replaces or wraps the badge that shows a property's type. Receives the badge the editor would render, so a
|
|
91
|
+
* host can return it unchanged, wrap it, or render something else. The badge carries `data-property-type`
|
|
92
|
+
* for styling per type.
|
|
93
|
+
*/
|
|
94
|
+
renderPropertyTypeBadge?: (property: Property, context: SchemaPropertyContext, defaultBadge: ReactNode) => ReactNode;
|
|
95
|
+
/** Replaces any of the editor's strings. Unset ones stay English. */
|
|
96
|
+
labels?: Partial<SchemaEditorLabels>;
|
|
97
|
+
/** Accessible name of the editor. Defaults to the `schema` label. */
|
|
98
|
+
'aria-label'?: string;
|
|
99
|
+
/** Id of the element that names the editor. */
|
|
100
|
+
'aria-labelledby'?: string;
|
|
101
|
+
/** Extra class name for the root. */
|
|
102
|
+
className?: string;
|
|
103
|
+
/** Attributes for the stable parts of the editor. */
|
|
104
|
+
pt?: SchemaEditorParts;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* 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
|
|
108
|
+
* optionally concepts, the key, and whether a property is required.
|
|
109
|
+
*
|
|
110
|
+
* Pass a `schema` and the editor keeps the tree and reports the resulting schema, or pass `properties` and
|
|
111
|
+
* handle each edit yourself. Everything specific to a product — rules, mapping connectors, its own chrome — is
|
|
112
|
+
* attached through the slots (`header`, `footer`, `renderPropertyLeading`, `renderPropertyAccessory`,
|
|
113
|
+
* `renderPropertyDetails`, `renderPropertyTypeBadge`) and `getPropertyRowState`.
|
|
114
|
+
*/
|
|
115
|
+
export declare const TreeSchemaEditor: ({ schema, onChange, onPropertiesChange, onPropertyRemoved, onPropertyRenamed, properties: controlledProperties, onAddProperty, onAddChildProperty, onDeleteProperty, onRenameProperty, onChangePropertyType, onSetKeyProperty, onSetRequiredProperty, concepts: suppliedConcepts, allowKeyProperty, allowRequired, readOnly, isPropertyProtected, validatePropertyName, selectedPropertyId, onPropertyClick, header, footer, renderPropertyLeading, renderPropertyAccessory, renderPropertyDetails, getPropertyRowState, renderPropertyTypeBadge, labels: suppliedLabels, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, className, pt, }: TreeSchemaEditorProps) => import("react").JSX.Element;
|
|
116
|
+
//# sourceMappingURL=TreeSchemaEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeSchemaEditor.d.ts","sourceRoot":"","sources":["../../../../SchemaEditor/Tree/TreeSchemaEditor.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAwC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE7E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAmB,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAgB,CAAC;AAe9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAqB,CAAC;AAE7D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAAyB,CAAC;AACrE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA0B,CAAC;AAIvE,gEAAgE;AAChE,MAAM,WAAW,qBAAqB;IAClC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,UAAU,CAAC;IAEpB,0GAA0G;IAC1G,QAAQ,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IAErC,sIAAsI;IACtI,kBAAkB,CAAC,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,KAAK,IAAI,CAAC;IAEtD,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OAAO,CAAC,kBAAkB,CAAC,CAAC;IAErC,qEAAqE;IACrE,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,+CAA+C;IAC/C,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B,qCAAqC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,qDAAqD;IACrD,EAAE,CAAC,EAAE,iBAAiB,CAAC;CAC1B;AAID;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,2nBAkC1B,qBAAqB,gCAiJvB,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { useMemo, useState, useRef, useEffect } from 'react';
|
|
3
|
+
import { FaPlus } from 'react-icons/fa6';
|
|
4
|
+
import { useOptionalPropertyConcepts } from './PropertyConceptsContext.js';
|
|
5
|
+
import { findPropertyById, totalPropertyCount } from './propertyTree.js';
|
|
6
|
+
import { PropertyTypeMenu } from './PropertyTypeMenu.js';
|
|
7
|
+
import { jsonSchemaToProperties, propertiesToJsonSchema, setRequiredProperty, setKeyProperty, changePropertyType, renameProperty, removeProperty, addChildProperty, addProperty } from './schemaConversion.js';
|
|
8
|
+
import { SchemaEditorContext } from './SchemaEditorContext.js';
|
|
9
|
+
import { resolveSchemaEditorLabels } from '../resolveSchemaEditorLabels.js';
|
|
10
|
+
import { SchemaPropertyRow } from './SchemaPropertyRow.js';
|
|
11
|
+
|
|
12
|
+
const never = () => false;
|
|
13
|
+
const TreeSchemaEditor = ({ schema, onChange, onPropertiesChange, onPropertyRemoved, onPropertyRenamed, properties: controlledProperties, onAddProperty, onAddChildProperty, onDeleteProperty, onRenameProperty, onChangePropertyType, onSetKeyProperty, onSetRequiredProperty, concepts: suppliedConcepts, allowKeyProperty, allowRequired, readOnly = false, isPropertyProtected, validatePropertyName, selectedPropertyId, onPropertyClick, header, footer, renderPropertyLeading, renderPropertyAccessory, renderPropertyDetails, getPropertyRowState, renderPropertyTypeBadge, labels: suppliedLabels, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, className, pt, }) => {
|
|
14
|
+
const labels = useMemo(() => resolveSchemaEditorLabels(suppliedLabels), [suppliedLabels]);
|
|
15
|
+
const providedConcepts = useOptionalPropertyConcepts();
|
|
16
|
+
const concepts = suppliedConcepts ?? providedConcepts;
|
|
17
|
+
const isControlled = controlledProperties !== undefined;
|
|
18
|
+
const [ownedProperties, setOwnedProperties] = useState(() => jsonSchemaToProperties(schema));
|
|
19
|
+
const latest = useRef(ownedProperties);
|
|
20
|
+
useEffect(() => { latest.current = ownedProperties; }, [ownedProperties]);
|
|
21
|
+
const properties = isControlled ? controlledProperties : ownedProperties;
|
|
22
|
+
const incomingSchema = schema === undefined ? undefined : JSON.stringify(schema);
|
|
23
|
+
const [seenSchema, setSeenSchema] = useState(incomingSchema);
|
|
24
|
+
if (!isControlled && incomingSchema !== seenSchema) {
|
|
25
|
+
setSeenSchema(incomingSchema);
|
|
26
|
+
if (schema !== undefined && incomingSchema !== JSON.stringify(propertiesToJsonSchema(ownedProperties))) {
|
|
27
|
+
setOwnedProperties(jsonSchemaToProperties(schema));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const apply = (next) => {
|
|
31
|
+
latest.current = next;
|
|
32
|
+
setOwnedProperties(next);
|
|
33
|
+
onChange?.(propertiesToJsonSchema(next), { source: 'user' });
|
|
34
|
+
onPropertiesChange?.(next);
|
|
35
|
+
};
|
|
36
|
+
const ownedOperations = {
|
|
37
|
+
addChild: (parentId, type, concept) => apply(addChildProperty(latest.current, parentId, type, totalPropertyCount(latest.current), concept)),
|
|
38
|
+
remove: propertyId => {
|
|
39
|
+
const removed = findPropertyById(latest.current, propertyId);
|
|
40
|
+
apply(removeProperty(latest.current, propertyId));
|
|
41
|
+
if (removed)
|
|
42
|
+
onPropertyRemoved?.(removed);
|
|
43
|
+
},
|
|
44
|
+
rename: (propertyId, name) => {
|
|
45
|
+
const previousName = findPropertyById(latest.current, propertyId)?.name;
|
|
46
|
+
const next = renameProperty(latest.current, propertyId, name);
|
|
47
|
+
apply(next);
|
|
48
|
+
const renamed = findPropertyById(next, propertyId);
|
|
49
|
+
if (renamed && previousName !== undefined)
|
|
50
|
+
onPropertyRenamed?.(renamed, previousName);
|
|
51
|
+
},
|
|
52
|
+
changeType: (propertyId, type, concept) => apply(changePropertyType(latest.current, propertyId, type, concept)),
|
|
53
|
+
setKey: propertyId => apply(setKeyProperty(latest.current, propertyId)),
|
|
54
|
+
setRequired: (propertyId, isRequired) => apply(setRequiredProperty(latest.current, propertyId, isRequired)),
|
|
55
|
+
};
|
|
56
|
+
const controlledOperations = {
|
|
57
|
+
addChild: onAddChildProperty,
|
|
58
|
+
remove: onDeleteProperty,
|
|
59
|
+
rename: onRenameProperty,
|
|
60
|
+
changeType: onChangePropertyType,
|
|
61
|
+
setKey: onSetKeyProperty,
|
|
62
|
+
setRequired: onSetRequiredProperty,
|
|
63
|
+
};
|
|
64
|
+
const operations = isControlled ? controlledOperations : ownedOperations;
|
|
65
|
+
const addRoot = isControlled
|
|
66
|
+
? onAddProperty
|
|
67
|
+
: (type, concept) => apply(addProperty(latest.current, type, totalPropertyCount(latest.current), concept));
|
|
68
|
+
const keyAllowance = allowKeyProperty ?? (isControlled && onSetKeyProperty !== undefined);
|
|
69
|
+
const isKeyAllowed = typeof keyAllowance === 'function'
|
|
70
|
+
? keyAllowance
|
|
71
|
+
: keyAllowance ? () => true : never;
|
|
72
|
+
const isRequiredAllowed = allowRequired ?? (isControlled && onSetRequiredProperty !== undefined);
|
|
73
|
+
const contextValue = {
|
|
74
|
+
labels,
|
|
75
|
+
parts: pt,
|
|
76
|
+
properties,
|
|
77
|
+
concepts,
|
|
78
|
+
readOnly,
|
|
79
|
+
operations,
|
|
80
|
+
selectedPropertyId,
|
|
81
|
+
onPropertyClick,
|
|
82
|
+
isKeyAllowed,
|
|
83
|
+
isRequiredAllowed,
|
|
84
|
+
isProtected: isPropertyProtected ?? never,
|
|
85
|
+
validateName: validatePropertyName,
|
|
86
|
+
getRowState: getPropertyRowState,
|
|
87
|
+
renderLeading: renderPropertyLeading,
|
|
88
|
+
renderAccessory: renderPropertyAccessory,
|
|
89
|
+
renderDetails: renderPropertyDetails,
|
|
90
|
+
renderTypeBadge: renderPropertyTypeBadge,
|
|
91
|
+
};
|
|
92
|
+
return (jsx(SchemaEditorContext.Provider, { value: contextValue, children: jsxs("div", { ...pt?.root, role: 'group', "aria-label": ariaLabelledBy ? undefined : ariaLabel ?? labels.schema, "aria-labelledby": ariaLabelledBy, className: ['cratis-schema-editor', pt?.root?.className, className].filter(Boolean).join(' '), "data-cratis-part": 'root', "data-readonly": readOnly || undefined, children: [header && (jsx("div", { ...pt?.header, className: `cratis-schema-editor__header ${pt?.header?.className ?? ''}`, "data-cratis-part": 'header', children: header })), properties.length === 0 ? (jsx("p", { ...pt?.empty, className: `cratis-schema-editor__empty ${pt?.empty?.className ?? ''}`, "data-cratis-part": 'empty', children: labels.emptyMessage })) : (jsx("ul", { ...pt?.list, className: `cratis-schema-editor__list ${pt?.list?.className ?? ''}`, "data-cratis-part": 'list', children: properties.map(property => (jsx(SchemaPropertyRow, { property: property, siblings: properties, depth: 0 }, property.id))) })), (footer || (!readOnly && addRoot)) && (jsxs("div", { className: 'cratis-schema-editor__actions', children: [!readOnly && addRoot && (jsxs(PropertyTypeMenu, { labels: labels, concepts: concepts, triggerPart: 'add', triggerLabel: labels.addProperty, parts: pt, onSelect: addRoot, children: [jsx(FaPlus, { "aria-hidden": 'true' }), labels.addProperty] })), footer && (jsx("div", { ...pt?.footer, className: `cratis-schema-editor__footer ${pt?.footer?.className ?? ''}`, "data-cratis-part": 'footer', children: footer }))] }))] }) }));
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export { TreeSchemaEditor };
|
|
96
|
+
//# sourceMappingURL=TreeSchemaEditor.js.map
|
|
@@ -0,0 +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"],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E,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,35 @@
|
|
|
1
|
+
import type { Property } from './Property.js';
|
|
2
|
+
/** Why a property name cannot be used. */
|
|
3
|
+
export declare enum PropertyNameProblem {
|
|
4
|
+
/** The name is empty or only whitespace. */
|
|
5
|
+
Empty = "empty",
|
|
6
|
+
/** The name would shadow a member every JavaScript object inherits. */
|
|
7
|
+
Reserved = "reserved",
|
|
8
|
+
/** A sibling already carries the name. */
|
|
9
|
+
Duplicate = "duplicate"
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Derives the default name for a property typed as a concept — the concept name with a lower-cased first
|
|
13
|
+
* letter, so picking the `CustomerId` concept gives a `customerId` property rather than `property3`.
|
|
14
|
+
* @param concept The name of the concept.
|
|
15
|
+
* @returns The property name to start from.
|
|
16
|
+
*/
|
|
17
|
+
export declare function conceptPropertyName(concept: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Resolves a property name that no sibling already uses. Sibling names become the keys of the JSON Schema
|
|
20
|
+
* object, so two properties sharing a name would silently collapse into one.
|
|
21
|
+
* @param siblings The properties the new property will sit alongside.
|
|
22
|
+
* @param candidate The name to use when it is free.
|
|
23
|
+
* @returns The candidate, or the candidate with the lowest free number appended.
|
|
24
|
+
*/
|
|
25
|
+
export declare function uniquePropertyName(siblings: Property[], candidate: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Checks that a name can be used for a property without losing data: names become JSON Schema keys, so an
|
|
28
|
+
* empty, prototype-shadowing or duplicated name would corrupt or collapse the schema.
|
|
29
|
+
* @param name The proposed name.
|
|
30
|
+
* @param propertyId The id of the property being named, so it is not compared with itself.
|
|
31
|
+
* @param siblings The properties that share the parent, including the one being named.
|
|
32
|
+
* @returns What is wrong with the name, or `undefined` when it can be used.
|
|
33
|
+
*/
|
|
34
|
+
export declare function findPropertyNameProblem(name: string, propertyId: string, siblings: Property[]): PropertyNameProblem | undefined;
|
|
35
|
+
//# sourceMappingURL=propertyNaming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propertyNaming.d.ts","sourceRoot":"","sources":["../../../../SchemaEditor/Tree/propertyNaming.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAY,CAAC;AAE3C,0CAA0C;AAC1C,oBAAY,mBAAmB;IAC3B,4CAA4C;IAC5C,KAAK,UAAU;IACf,uEAAuE;IACvE,QAAQ,aAAa;IACrB,0CAA0C;IAC1C,SAAS,cAAc;CAC1B;AAID;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAG3D;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAWlF;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACnC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,QAAQ,EAAE,GACrB,mBAAmB,GAAG,SAAS,CAKjC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var PropertyNameProblem;
|
|
2
|
+
(function (PropertyNameProblem) {
|
|
3
|
+
PropertyNameProblem["Empty"] = "empty";
|
|
4
|
+
PropertyNameProblem["Reserved"] = "reserved";
|
|
5
|
+
PropertyNameProblem["Duplicate"] = "duplicate";
|
|
6
|
+
})(PropertyNameProblem || (PropertyNameProblem = {}));
|
|
7
|
+
const reservedPrototypeKeys = new Set(['__proto__', 'constructor', 'prototype']);
|
|
8
|
+
function conceptPropertyName(concept) {
|
|
9
|
+
const trimmed = concept.trim();
|
|
10
|
+
return trimmed.length === 0 ? '' : trimmed.charAt(0).toLowerCase() + trimmed.slice(1);
|
|
11
|
+
}
|
|
12
|
+
function uniquePropertyName(siblings, candidate) {
|
|
13
|
+
const taken = new Set(siblings.map(sibling => sibling.name));
|
|
14
|
+
if (!taken.has(candidate)) {
|
|
15
|
+
return candidate;
|
|
16
|
+
}
|
|
17
|
+
let suffix = 2;
|
|
18
|
+
while (taken.has(`${candidate}${suffix}`)) {
|
|
19
|
+
suffix++;
|
|
20
|
+
}
|
|
21
|
+
return `${candidate}${suffix}`;
|
|
22
|
+
}
|
|
23
|
+
function findPropertyNameProblem(name, propertyId, siblings) {
|
|
24
|
+
if (name.trim() === '')
|
|
25
|
+
return PropertyNameProblem.Empty;
|
|
26
|
+
if (reservedPrototypeKeys.has(name))
|
|
27
|
+
return PropertyNameProblem.Reserved;
|
|
28
|
+
if (siblings.some(sibling => sibling.name === name && sibling.id !== propertyId))
|
|
29
|
+
return PropertyNameProblem.Duplicate;
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { PropertyNameProblem, conceptPropertyName, findPropertyNameProblem, uniquePropertyName };
|
|
34
|
+
//# sourceMappingURL=propertyNaming.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propertyNaming.js","sources":["../../../../SchemaEditor/Tree/propertyNaming.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 { Property } from './Property';\n\n/** Why a property name cannot be used. */\nexport enum PropertyNameProblem {\n /** The name is empty or only whitespace. */\n Empty = 'empty',\n /** The name would shadow a member every JavaScript object inherits. */\n Reserved = 'reserved',\n /** A sibling already carries the name. */\n Duplicate = 'duplicate',\n}\n\nconst reservedPrototypeKeys = new Set(['__proto__', 'constructor', 'prototype']);\n\n/**\n * Derives the default name for a property typed as a concept — the concept name with a lower-cased first\n * letter, so picking the `CustomerId` concept gives a `customerId` property rather than `property3`.\n * @param concept The name of the concept.\n * @returns The property name to start from.\n */\nexport function conceptPropertyName(concept: string): string {\n const trimmed = concept.trim();\n return trimmed.length === 0 ? '' : trimmed.charAt(0).toLowerCase() + trimmed.slice(1);\n}\n\n/**\n * Resolves a property name that no sibling already uses. Sibling names become the keys of the JSON Schema\n * object, so two properties sharing a name would silently collapse into one.\n * @param siblings The properties the new property will sit alongside.\n * @param candidate The name to use when it is free.\n * @returns The candidate, or the candidate with the lowest free number appended.\n */\nexport function uniquePropertyName(siblings: Property[], candidate: string): string {\n const taken = new Set(siblings.map(sibling => sibling.name));\n if (!taken.has(candidate)) {\n return candidate;\n }\n\n let suffix = 2;\n while (taken.has(`${candidate}${suffix}`)) {\n suffix++;\n }\n return `${candidate}${suffix}`;\n}\n\n/**\n * Checks that a name can be used for a property without losing data: names become JSON Schema keys, so an\n * empty, prototype-shadowing or duplicated name would corrupt or collapse the schema.\n * @param name The proposed name.\n * @param propertyId The id of the property being named, so it is not compared with itself.\n * @param siblings The properties that share the parent, including the one being named.\n * @returns What is wrong with the name, or `undefined` when it can be used.\n */\nexport function findPropertyNameProblem(\n name: string,\n propertyId: string,\n siblings: Property[],\n): PropertyNameProblem | undefined {\n if (name.trim() === '') return PropertyNameProblem.Empty;\n if (reservedPrototypeKeys.has(name)) return PropertyNameProblem.Reserved;\n if (siblings.some(sibling => sibling.name === name && sibling.id !== propertyId)) return PropertyNameProblem.Duplicate;\n return undefined;\n}\n"],"names":[],"mappings":"IAMY;AAAZ,CAAA,UAAY,mBAAmB,EAAA;AAE3B,IAAA,mBAAA,CAAA,OAAA,CAAA,GAAA,O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AmB,CAAC,QAAQ;AACxE,IAAA,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,KAAK,IAAI,IAAI,OAAO,CAAC,EAAE,KAAK,UAAU,CAAC;QAAE,OAAO,mBAAmB,CAAC,SAAS;AACtH,IAAA,OAAO,SAAS;AACpB;;"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Property } from './Property.js';
|
|
2
|
+
/**
|
|
3
|
+
* Finds a property anywhere in the tree by its id.
|
|
4
|
+
* @param properties The root properties to search.
|
|
5
|
+
* @param id The id of the property.
|
|
6
|
+
* @returns The property, or `undefined` when no property has the id.
|
|
7
|
+
*/
|
|
8
|
+
export declare function findPropertyById(properties: Property[], id: string): Property | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Finds the first property with a name, searching depth first. Names are only unique among siblings, so this
|
|
11
|
+
* is for callers that key by name — for example to rebind state saved by name to the freshly generated ids.
|
|
12
|
+
* @param properties The root properties to search.
|
|
13
|
+
* @param name The name of the property.
|
|
14
|
+
* @returns The property, or `undefined` when no property has the name.
|
|
15
|
+
*/
|
|
16
|
+
export declare function findPropertyByName(properties: Property[], name: string): Property | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Finds the properties that share a parent with a property, including the property itself.
|
|
19
|
+
* @param properties The root properties to search.
|
|
20
|
+
* @param id The id of the property.
|
|
21
|
+
* @returns The sibling group, or `undefined` when no property has the id.
|
|
22
|
+
*/
|
|
23
|
+
export declare function findSiblingProperties(properties: Property[], id: string): Property[] | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Counts every property in the tree, nested ones included. Used to generate unique default names.
|
|
26
|
+
* @param properties The root properties.
|
|
27
|
+
* @returns The total number of properties.
|
|
28
|
+
*/
|
|
29
|
+
export declare function totalPropertyCount(properties: Property[]): number;
|
|
30
|
+
//# sourceMappingURL=propertyTree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propertyTree.d.ts","sourceRoot":"","sources":["../../../../SchemaEditor/Tree/propertyTree.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAY,CAAC;AAE3C;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAOzF;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAO7F;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,MAAM,GAAG,QAAQ,EAAE,GAAG,SAAS,CAOhG;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,QAAQ,EAAE,GAAG,MAAM,CAEjE"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
function findPropertyById(properties, id) {
|
|
2
|
+
for (const property of properties) {
|
|
3
|
+
if (property.id === id)
|
|
4
|
+
return property;
|
|
5
|
+
const found = property.children ? findPropertyById(property.children, id) : undefined;
|
|
6
|
+
if (found)
|
|
7
|
+
return found;
|
|
8
|
+
}
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
function findPropertyByName(properties, name) {
|
|
12
|
+
for (const property of properties) {
|
|
13
|
+
if (property.name === name)
|
|
14
|
+
return property;
|
|
15
|
+
const found = property.children ? findPropertyByName(property.children, name) : undefined;
|
|
16
|
+
if (found)
|
|
17
|
+
return found;
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
function findSiblingProperties(properties, id) {
|
|
22
|
+
if (properties.some(property => property.id === id))
|
|
23
|
+
return properties;
|
|
24
|
+
for (const property of properties) {
|
|
25
|
+
const found = property.children ? findSiblingProperties(property.children, id) : undefined;
|
|
26
|
+
if (found)
|
|
27
|
+
return found;
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
function totalPropertyCount(properties) {
|
|
32
|
+
return properties.reduce((sum, property) => sum + 1 + totalPropertyCount(property.children ?? []), 0);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { findPropertyById, findPropertyByName, findSiblingProperties, totalPropertyCount };
|
|
36
|
+
//# sourceMappingURL=propertyTree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propertyTree.js","sources":["../../../../SchemaEditor/Tree/propertyTree.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 { Property } from './Property';\n\n/**\n * Finds a property anywhere in the tree by its id.\n * @param properties The root properties to search.\n * @param id The id of the property.\n * @returns The property, or `undefined` when no property has the id.\n */\nexport function findPropertyById(properties: Property[], id: string): Property | undefined {\n for (const property of properties) {\n if (property.id === id) return property;\n const found = property.children ? findPropertyById(property.children, id) : undefined;\n if (found) return found;\n }\n return undefined;\n}\n\n/**\n * Finds the first property with a name, searching depth first. Names are only unique among siblings, so this\n * is for callers that key by name — for example to rebind state saved by name to the freshly generated ids.\n * @param properties The root properties to search.\n * @param name The name of the property.\n * @returns The property, or `undefined` when no property has the name.\n */\nexport function findPropertyByName(properties: Property[], name: string): Property | undefined {\n for (const property of properties) {\n if (property.name === name) return property;\n const found = property.children ? findPropertyByName(property.children, name) : undefined;\n if (found) return found;\n }\n return undefined;\n}\n\n/**\n * Finds the properties that share a parent with a property, including the property itself.\n * @param properties The root properties to search.\n * @param id The id of the property.\n * @returns The sibling group, or `undefined` when no property has the id.\n */\nexport function findSiblingProperties(properties: Property[], id: string): Property[] | undefined {\n if (properties.some(property => property.id === id)) return properties;\n for (const property of properties) {\n const found = property.children ? findSiblingProperties(property.children, id) : undefined;\n if (found) return found;\n }\n return undefined;\n}\n\n/**\n * Counts every property in the tree, nested ones included. Used to generate unique default names.\n * @param properties The root properties.\n * @returns The total number of properties.\n */\nexport function totalPropertyCount(properties: Property[]): number {\n return properties.reduce((sum, property) => sum + 1 + totalPropertyCount(property.children ?? []), 0);\n}\n"],"names":[],"mappings":"AAWM,SAAU,gBAAgB,CAAC,UAAsB,EAAE,EAAU,EAAA;AAC/D,IAAA,KAAK,MAAM,QAAQ,IAAI,UAAU,EAAE;AAC/B,QAAA,IAAI,QAAQ,CAAC,EAAE,KAAK,EAAE;AAAE,YAAA,OAAO,QAAQ;QACvC,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,GAAG,gBAAgB,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,GAAG,SAAS;AACrF,QAAA,IAAI,KAAK;AAAE,YAAA,OAAO,KAAK;IAC3B;AACA,IAAA,OAAO,SAAS;AACpB;AASM,SAAU,kBAAkB,CAAC,UAAsB,EAAE,IAAY,EAAA;AACnE,IAAA,KAAK,MAAM,QAAQ,IAAI,UAAU,EAAE;AAC/B,QAAA,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI;AAAE,YAAA,OAAO,QAAQ;QAC3C,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,GAAG,kBAAkB,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,SAAS;AACzF,QAAA,IAAI,KAAK;AAAE,YAAA,OAAO,KAAK;IAC3B;AACA,IAAA,OAAO,SAAS;AACpB;AAQM,SAAU,qBAAqB,CAAC,UAAsB,EAAE,EAAU,EAAA;AACpE,IAAA,IAAI,UAAU,CAAC,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC;AAAE,QAAA,OAAO,UAAU;AACtE,IAAA,KAAK,MAAM,QAAQ,IAAI,UAAU,EAAE;QAC/B,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,GAAG,qBAAqB,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,GAAG,SAAS;AAC1F,QAAA,IAAI,KAAK;AAAE,YAAA,OAAO,KAAK;IAC3B;AACA,IAAA,OAAO,SAAS;AACpB;AAOM,SAAU,kBAAkB,CAAC,UAAsB,EAAA;IACrD,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,QAAQ,KAAK,GAAG,GAAG,CAAC,GAAG,kBAAkB,CAAC,QAAQ,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;AACzG;;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PropertyType } from './PropertyType.js';
|
|
2
|
+
import type { SchemaEditorLabels } from '../SchemaEditorLabels.js';
|
|
3
|
+
/** The types the menu offers first, in order. Concepts follow them. */
|
|
4
|
+
export declare const primitivePropertyTypes: readonly PropertyType[];
|
|
5
|
+
/** The types the menu offers after the concepts, in order. */
|
|
6
|
+
export declare const compositePropertyTypes: readonly PropertyType[];
|
|
7
|
+
/** Short text shown in a type badge; decorative, because the badge also carries the type's name. */
|
|
8
|
+
export declare const propertyTypeGlyph: Record<PropertyType, string>;
|
|
9
|
+
/**
|
|
10
|
+
* The display name of a property type.
|
|
11
|
+
* @param type The type.
|
|
12
|
+
* @param labels The resolved labels.
|
|
13
|
+
* @returns The localized name.
|
|
14
|
+
*/
|
|
15
|
+
export declare function propertyTypeName(type: PropertyType, labels: Required<SchemaEditorLabels>): string;
|
|
16
|
+
/**
|
|
17
|
+
* Whether values of the type carry nested properties.
|
|
18
|
+
* @param type The type.
|
|
19
|
+
* @returns `true` for objects and lists of objects.
|
|
20
|
+
*/
|
|
21
|
+
export declare function hasNestedProperties(type: PropertyType): boolean;
|
|
22
|
+
//# sourceMappingURL=propertyTypeDisplay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propertyTypeDisplay.d.ts","sourceRoot":"","sources":["../../../../SchemaEditor/Tree/propertyTypeDisplay.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAAuB,CAAC;AAEhE,uEAAuE;AACvE,eAAO,MAAM,sBAAsB,EAAE,SAAS,YAAY,EAMzD,CAAC;AAEF,8DAA8D;AAC9D,eAAO,MAAM,sBAAsB,EAAE,SAAS,YAAY,EAKzD,CAAC;AAEF,oGAAoG;AACpG,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAU1D,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,CAAC,kBAAkB,CAAC,GAAG,MAAM,CAYjG;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAE/D"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { PropertyType } from './PropertyType.js';
|
|
2
|
+
|
|
3
|
+
const primitivePropertyTypes = [
|
|
4
|
+
PropertyType.String,
|
|
5
|
+
PropertyType.Number,
|
|
6
|
+
PropertyType.Boolean,
|
|
7
|
+
PropertyType.Date,
|
|
8
|
+
PropertyType.Time,
|
|
9
|
+
];
|
|
10
|
+
const compositePropertyTypes = [
|
|
11
|
+
PropertyType.StringArray,
|
|
12
|
+
PropertyType.NumberArray,
|
|
13
|
+
PropertyType.Object,
|
|
14
|
+
PropertyType.ObjectArray,
|
|
15
|
+
];
|
|
16
|
+
const propertyTypeGlyph = {
|
|
17
|
+
[PropertyType.String]: 'Aa',
|
|
18
|
+
[PropertyType.Number]: '123',
|
|
19
|
+
[PropertyType.Boolean]: 'T/F',
|
|
20
|
+
[PropertyType.Date]: 'Date',
|
|
21
|
+
[PropertyType.Time]: 'Time',
|
|
22
|
+
[PropertyType.Object]: '{ }',
|
|
23
|
+
[PropertyType.StringArray]: '[Aa]',
|
|
24
|
+
[PropertyType.NumberArray]: '[123]',
|
|
25
|
+
[PropertyType.ObjectArray]: '[{ }]',
|
|
26
|
+
};
|
|
27
|
+
function propertyTypeName(type, labels) {
|
|
28
|
+
switch (type) {
|
|
29
|
+
case PropertyType.Number: return labels.typeNumber;
|
|
30
|
+
case PropertyType.Boolean: return labels.typeBoolean;
|
|
31
|
+
case PropertyType.Date: return labels.typeDate;
|
|
32
|
+
case PropertyType.Time: return labels.typeTime;
|
|
33
|
+
case PropertyType.StringArray: return labels.typeStringArray;
|
|
34
|
+
case PropertyType.NumberArray: return labels.typeNumberArray;
|
|
35
|
+
case PropertyType.Object: return labels.typeObject;
|
|
36
|
+
case PropertyType.ObjectArray: return labels.typeObjectArray;
|
|
37
|
+
default: return labels.typeString;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function hasNestedProperties(type) {
|
|
41
|
+
return type === PropertyType.Object || type === PropertyType.ObjectArray;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { compositePropertyTypes, hasNestedProperties, primitivePropertyTypes, propertyTypeGlyph, propertyTypeName };
|
|
45
|
+
//# sourceMappingURL=propertyTypeDisplay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propertyTypeDisplay.js","sources":["../../../../SchemaEditor/Tree/propertyTypeDisplay.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 { PropertyType } from './PropertyType';\nimport type { SchemaEditorLabels } from '../SchemaEditorLabels';\n\n/** The types the menu offers first, in order. Concepts follow them. */\nexport const primitivePropertyTypes: readonly PropertyType[] = [\n PropertyType.String,\n PropertyType.Number,\n PropertyType.Boolean,\n PropertyType.Date,\n PropertyType.Time,\n];\n\n/** The types the menu offers after the concepts, in order. */\nexport const compositePropertyTypes: readonly PropertyType[] = [\n PropertyType.StringArray,\n PropertyType.NumberArray,\n PropertyType.Object,\n PropertyType.ObjectArray,\n];\n\n/** Short text shown in a type badge; decorative, because the badge also carries the type's name. */\nexport const propertyTypeGlyph: Record<PropertyType, string> = {\n [PropertyType.String]: 'Aa',\n [PropertyType.Number]: '123',\n [PropertyType.Boolean]: 'T/F',\n [PropertyType.Date]: 'Date',\n [PropertyType.Time]: 'Time',\n [PropertyType.Object]: '{ }',\n [PropertyType.StringArray]: '[Aa]',\n [PropertyType.NumberArray]: '[123]',\n [PropertyType.ObjectArray]: '[{ }]',\n};\n\n/**\n * The display name of a property type.\n * @param type The type.\n * @param labels The resolved labels.\n * @returns The localized name.\n */\nexport function propertyTypeName(type: PropertyType, labels: Required<SchemaEditorLabels>): string {\n switch (type) {\n case PropertyType.Number: return labels.typeNumber;\n case PropertyType.Boolean: return labels.typeBoolean;\n case PropertyType.Date: return labels.typeDate;\n case PropertyType.Time: return labels.typeTime;\n case PropertyType.StringArray: return labels.typeStringArray;\n case PropertyType.NumberArray: return labels.typeNumberArray;\n case PropertyType.Object: return labels.typeObject;\n case PropertyType.ObjectArray: return labels.typeObjectArray;\n default: return labels.typeString;\n }\n}\n\n/**\n * Whether values of the type carry nested properties.\n * @param type The type.\n * @returns `true` for objects and lists of objects.\n */\nexport function hasNestedProperties(type: PropertyType): boolean {\n return type === PropertyType.Object || type === PropertyType.ObjectArray;\n}\n"],"names":[],"mappings":";;AAOO,MAAM,sBAAsB,GAA4B;AAC3D,IAAA,YAAY,CAAC,MAAM;AACnB,IAAA,YAAY,CAAC,MAAM;AACnB,IAAA,YAAY,CAAC,OAAO;AACpB,IAAA,YAAY,CAAC,IAAI;AACjB,IAAA,YAAY,CAAC,IAAI;;AAId,MAAM,sBAAsB,GAA4B;AAC3D,IAAA,YAAY,CAAC,WAAW;AACxB,IAAA,YAAY,CAAC,WAAW;AACxB,IAAA,YAAY,CAAC,MAAM;AACnB,IAAA,YAAY,CAAC,WAAW;;AAIrB,MAAM,iBAAiB,GAAiC;AAC3D,IAAA,CAAC,YAAY,CAAC,MAAM,GAAG,IAAI;AAC3B,IAAA,CAAC,YAAY,CAAC,MAAM,GAAG,KAAK;AAC5B,IAAA,CAAC,YAAY,CAAC,OAAO,GAAG,KAAK;AAC7B,IAAA,CAAC,YAAY,CAAC,IAAI,GAAG,MAAM;AAC3B,IAAA,CAAC,YAAY,CAAC,IAAI,GAAG,MAAM;AAC3B,IAAA,CAAC,YAAY,CAAC,MAAM,GAAG,KAAK;AAC5B,IAAA,CAAC,YAAY,CAAC,WAAW,GAAG,MAAM;AAClC,IAAA,CAAC,YAAY,CAAC,WAAW,GAAG,OAAO;AACnC,IAAA,CAAC,YAAY,CAAC,WAAW,GAAG,OAAO;;AASjC,SAAU,gBAAgB,CAAC,IAAkB,EAAE,MAAoC,EAAA;IACrF,QAAQ,IAAI;QACR,KAAK,YAAY,CAAC,MAAM,EAAE,OAAO,MAAM,CAAC,UAAU;QAClD,KAAK,YAAY,CAAC,OAAO,EAAE,OAAO,MAAM,CAAC,WAAW;QACpD,KAAK,YAAY,CAAC,IAAI,EAAE,OAAO,MAAM,CAAC,QAAQ;QAC9C,KAAK,YAAY,CAAC,IAAI,EAAE,OAAO,MAAM,CAAC,QAAQ;QAC9C,KAAK,YAAY,CAAC,WAAW,EAAE,OAAO,MAAM,CAAC,eAAe;QAC5D,KAAK,YAAY,CAAC,WAAW,EAAE,OAAO,MAAM,CAAC,eAAe;QAC5D,KAAK,YAAY,CAAC,MAAM,EAAE,OAAO,MAAM,CAAC,UAAU;QAClD,KAAK,YAAY,CAAC,WAAW,EAAE,OAAO,MAAM,CAAC,eAAe;AAC5D,QAAA,SAAS,OAAO,MAAM,CAAC,UAAU;;AAEzC;AAOM,SAAU,mBAAmB,CAAC,IAAkB,EAAA;IAClD,OAAO,IAAI,KAAK,YAAY,CAAC,MAAM,IAAI,IAAI,KAAK,YAAY,CAAC,WAAW;AAC5E;;"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { JsonSchema } from '../../types/JsonSchema.js';
|
|
2
|
+
import type { Property } from './Property.js';
|
|
3
|
+
import { PropertyType } from './PropertyType.js';
|
|
4
|
+
/**
|
|
5
|
+
* The JSON Schema keyword carrying the concept a property is typed as. It annotates the primitive node the
|
|
6
|
+
* concept wraps rather than replacing it, so anything that does not know about concepts — code generation,
|
|
7
|
+
* an export, another tool — still reads a valid schema of the underlying primitive.
|
|
8
|
+
*/
|
|
9
|
+
export declare const CONCEPT_KEYWORD = "x-concept";
|
|
10
|
+
/**
|
|
11
|
+
* The JSON Schema keyword marking the property that identifies its parent object. Written as `true` on the
|
|
12
|
+
* property; at most one property of an object carries it.
|
|
13
|
+
*/
|
|
14
|
+
export declare const KEY_KEYWORD = "x-key";
|
|
15
|
+
/**
|
|
16
|
+
* Converts a JSON Schema object into a property tree. Generates a new id for every property.
|
|
17
|
+
* @param schema The schema to read; `undefined` and schemas without properties give an empty tree.
|
|
18
|
+
* @returns The root properties.
|
|
19
|
+
*/
|
|
20
|
+
export declare function jsonSchemaToProperties(schema: JsonSchema | undefined): Property[];
|
|
21
|
+
/**
|
|
22
|
+
* 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.
|
|
24
|
+
* @param properties The root properties.
|
|
25
|
+
* @returns The schema.
|
|
26
|
+
*/
|
|
27
|
+
export declare function propertiesToJsonSchema(properties: Property[]): JsonSchema;
|
|
28
|
+
/**
|
|
29
|
+
* Appends a property to the root.
|
|
30
|
+
* @param properties The root properties.
|
|
31
|
+
* @param type The type of the new property.
|
|
32
|
+
* @param existingCount The number of properties already in the tree, used to generate the default name; see {@link totalPropertyCount}.
|
|
33
|
+
* @param concept The concept the property is typed as. When given the property is named after it.
|
|
34
|
+
* @returns The new tree.
|
|
35
|
+
*/
|
|
36
|
+
export declare function addProperty(properties: Property[], type: PropertyType, existingCount: number, concept?: string): Property[];
|
|
37
|
+
/**
|
|
38
|
+
* Appends a property to a nested object or object list.
|
|
39
|
+
* @param properties The root properties.
|
|
40
|
+
* @param parentId The id of the parent property.
|
|
41
|
+
* @param type The type of the new property.
|
|
42
|
+
* @param existingCount The number of properties already in the tree, used to generate the default name.
|
|
43
|
+
* @param concept The concept the property is typed as.
|
|
44
|
+
* @returns The new tree.
|
|
45
|
+
*/
|
|
46
|
+
export declare function addChildProperty(properties: Property[], parentId: string, type: PropertyType, existingCount: number, concept?: string): Property[];
|
|
47
|
+
/**
|
|
48
|
+
* Removes a property, and everything nested under it.
|
|
49
|
+
* @param properties The root properties.
|
|
50
|
+
* @param targetId The id of the property to remove.
|
|
51
|
+
* @returns The new tree.
|
|
52
|
+
*/
|
|
53
|
+
export declare function removeProperty(properties: Property[], targetId: string): Property[];
|
|
54
|
+
/**
|
|
55
|
+
* Renames a property. Its requiredness travels with it, because both are stored against the property.
|
|
56
|
+
* @param properties The root properties.
|
|
57
|
+
* @param targetId The id of the property to rename.
|
|
58
|
+
* @param newName The new name.
|
|
59
|
+
* @returns The new tree.
|
|
60
|
+
*/
|
|
61
|
+
export declare function renameProperty(properties: Property[], targetId: string, newName: string): Property[];
|
|
62
|
+
/**
|
|
63
|
+
* 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.
|
|
65
|
+
* @param properties The root properties.
|
|
66
|
+
* @param targetId The id of the property.
|
|
67
|
+
* @param newType The new type.
|
|
68
|
+
* @param concept The concept the property is now typed as, if any.
|
|
69
|
+
* @returns The new tree.
|
|
70
|
+
*/
|
|
71
|
+
export declare function changePropertyType(properties: Property[], targetId: string, newType: PropertyType, concept?: string): Property[];
|
|
72
|
+
/**
|
|
73
|
+
* Flips whether a property is required.
|
|
74
|
+
* @param properties The root properties.
|
|
75
|
+
* @param targetId The id of the property.
|
|
76
|
+
* @returns The new tree.
|
|
77
|
+
*/
|
|
78
|
+
export declare function toggleRequiredProperty(properties: Property[], targetId: string): Property[];
|
|
79
|
+
/**
|
|
80
|
+
* Sets whether a property is required. Requiring a nested property does not require its parent.
|
|
81
|
+
* @param properties The root properties.
|
|
82
|
+
* @param targetId The id of the property.
|
|
83
|
+
* @param isRequired Whether the property must be present.
|
|
84
|
+
* @returns The new tree.
|
|
85
|
+
*/
|
|
86
|
+
export declare function setRequiredProperty(properties: Property[], targetId: string, isRequired: boolean): Property[];
|
|
87
|
+
/**
|
|
88
|
+
* Makes a property the key of its parent object, moving the key when a sibling held it. Choosing the
|
|
89
|
+
* property that already is the key clears it, so an object can also have no key.
|
|
90
|
+
* @param properties The root properties.
|
|
91
|
+
* @param targetId The id of the property.
|
|
92
|
+
* @returns The new tree.
|
|
93
|
+
*/
|
|
94
|
+
export declare function setKeyProperty(properties: Property[], targetId: string): Property[];
|
|
95
|
+
//# sourceMappingURL=schemaConversion.d.ts.map
|