@cratis/components 4.25.2 → 4.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compat-manifest.json +11 -11
- package/dist/esm/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 +12 -0
- package/dist/esm/SchemaEditor/Tree/PropertyTypeBadge.js.map +1 -0
- package/dist/esm/SchemaEditor/Tree/PropertyTypeGlyph.d.ts +12 -0
- package/dist/esm/SchemaEditor/Tree/PropertyTypeGlyph.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/Tree/PropertyTypeGlyph.js +29 -0
- package/dist/esm/SchemaEditor/Tree/PropertyTypeGlyph.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 +38 -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 +20 -0
- package/dist/esm/SchemaEditor/Tree/propertyTypeDisplay.d.ts.map +1 -0
- package/dist/esm/SchemaEditor/Tree/propertyTypeDisplay.js +34 -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 +391 -0
- package/dist/esm/styles.css +391 -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 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaPropertyRow.js","sources":["../../../../SchemaEditor/Tree/SchemaPropertyRow.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, useId, useRef, useState, type KeyboardEvent, type MouseEvent } from 'react';\nimport { FaKey, FaLock, FaPlus, FaXmark } from 'react-icons/fa6';\nimport type { Property } from './Property';\nimport { PropertyNameProblem, findPropertyNameProblem } from './propertyNaming';\nimport { PropertyTypeBadge } from './PropertyTypeBadge';\nimport { PropertyTypeMenu } from './PropertyTypeMenu';\nimport { useSchemaEditorContext } from './SchemaEditorContext';\nimport type { SchemaPropertyContext } from './SchemaPropertyContext';\nimport { hasNestedProperties, propertyTypeName } from './propertyTypeDisplay';\n\n/** Props for one row of the editor, and everything nested under it. */\nexport interface SchemaPropertyRowProps {\n /** The property shown. */\n property: Property;\n\n /** The properties that share its parent, including itself. */\n siblings: Property[];\n\n /** How deeply the property is nested. */\n depth: number;\n}\n\nconst interactiveSelector = 'button, input, label, textarea, select, a, [role=\"menu\"]';\n\n/** One property: its row of controls, the host's details beneath it, and the properties nested under it. */\nexport const SchemaPropertyRow = ({ property, siblings, depth }: SchemaPropertyRowProps) => {\n const context = useSchemaEditorContext();\n const { labels, parts, operations, readOnly } = context;\n const messageId = useId();\n const nameInput = useRef<HTMLInputElement>(null);\n const [isEditing, setIsEditing] = useState(false);\n const [draftName, setDraftName] = useState(property.name);\n const [problem, setProblem] = useState<string | undefined>(undefined);\n\n const rowContext: SchemaPropertyContext = { depth, siblings, properties: context.properties, readOnly };\n const rowState = context.getRowState?.(property, rowContext);\n const details = context.renderDetails?.(property, rowContext);\n const isProtected = context.isProtected(property);\n const canRename = !readOnly && !isProtected && operations.rename !== undefined;\n const canRemove = !readOnly && !isProtected && operations.remove !== undefined;\n const canChangeType = !readOnly && operations.changeType !== undefined && rowState?.lockType !== true;\n const canSetRequired = context.isRequiredAllowed && operations.setRequired !== undefined;\n const canSetKey = !readOnly && operations.setKey !== undefined && context.isKeyAllowed(property, rowContext);\n const canAddChild = !readOnly && operations.addChild !== undefined && hasNestedProperties(property.type);\n const lockReason = rowState?.lockType === true ? rowState.lockTypeReason : undefined;\n const isSelected = context.selectedPropertyId === property.id;\n const typeName = propertyTypeName(property.type, labels);\n const nestedLabel = labels.nestedProperties(property.name);\n\n useEffect(() => {\n if (isEditing) nameInput.current?.select();\n }, [isEditing]);\n\n const startEditing = () => {\n if (!canRename) return;\n setDraftName(property.name);\n setProblem(undefined);\n setIsEditing(true);\n };\n\n const stopEditing = () => {\n setIsEditing(false);\n setProblem(undefined);\n };\n\n const describe = (name: string): string | undefined => {\n const found = findPropertyNameProblem(name, property.id, siblings);\n if (found === PropertyNameProblem.Empty) return labels.nameRequired;\n if (found === PropertyNameProblem.Reserved) return labels.nameReserved(name);\n if (found === PropertyNameProblem.Duplicate) return labels.nameDuplicate(name);\n return context.validateName?.(name, property, siblings);\n };\n\n const commit = (): boolean => {\n const name = draftName.trim();\n if (name === property.name) {\n stopEditing();\n return true;\n }\n const message = describe(name);\n if (message) {\n setProblem(message);\n return false;\n }\n stopEditing();\n operations.rename?.(property.id, name);\n return true;\n };\n\n const handleEditKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\n if (event.key === 'Enter') {\n event.preventDefault();\n commit();\n } else if (event.key === 'Escape') {\n event.stopPropagation();\n stopEditing();\n }\n };\n\n const handleRowClick = (event: MouseEvent<HTMLDivElement>) => {\n const target = event.target as HTMLElement;\n const optedIn = target.closest('[data-schema-row-select]');\n if (optedIn && event.currentTarget.contains(optedIn)) {\n context.onPropertyClick?.(property.id);\n return;\n }\n const interactive = target.closest(interactiveSelector);\n if (interactive && interactive.getAttribute('data-cratis-part') !== 'name') return;\n context.onPropertyClick?.(property.id);\n };\n\n const defaultBadge = <PropertyTypeBadge property={property} labels={labels} part={parts?.badge} lockReason={lockReason} />;\n const typeBadge = context.renderTypeBadge ? context.renderTypeBadge(property, rowContext, defaultBadge) : defaultBadge;\n const rowAttributes = rowState?.attributes ?? {};\n const isSelectable = context.onPropertyClick !== undefined;\n\n return (\n <li\n {...parts?.property}\n className={`cratis-schema-editor__property ${parts?.property?.className ?? ''}`}\n data-cratis-part='property'\n data-property-type={property.type}\n >\n <div\n {...parts?.row}\n {...rowAttributes}\n title={rowState?.title}\n className={`cratis-schema-editor__row ${rowState?.className ?? ''} ${parts?.row?.className ?? ''}`}\n data-cratis-part='row'\n data-selected={isSelected || undefined}\n onClick={handleRowClick}\n >\n {context.renderLeading && (\n <span {...parts?.leading} className={`cratis-schema-editor__leading ${parts?.leading?.className ?? ''}`} data-cratis-part='leading'>\n {context.renderLeading(property, rowContext)}\n </span>\n )}\n\n {isEditing ? (\n <span className='cratis-schema-editor__name-edit'>\n <input\n {...parts?.nameInput}\n ref={nameInput}\n type='text'\n value={draftName}\n aria-label={labels.propertyNameFor(property.name)}\n aria-invalid={problem !== undefined || undefined}\n aria-describedby={problem ? messageId : undefined}\n className={`cratis-schema-editor__name-input ${parts?.nameInput?.className ?? ''}`}\n data-cratis-part='nameInput'\n data-invalid={problem !== undefined || undefined}\n onChange={event => { setDraftName(event.target.value); setProblem(undefined); }}\n onBlur={() => { if (!commit()) stopEditing(); }}\n onKeyDown={handleEditKeyDown}\n />\n {problem && (\n <p\n {...parts?.message}\n id={messageId}\n role='alert'\n className={`cratis-schema-editor__message ${parts?.message?.className ?? ''}`}\n data-cratis-part='message'\n >\n {problem}\n </p>\n )}\n </span>\n ) : canRename || isSelectable ? (\n <button\n {...parts?.name}\n type='button'\n title={canRename ? labels.renameHint : undefined}\n aria-keyshortcuts={canRename ? 'F2' : undefined}\n className={`cratis-schema-editor__name ${parts?.name?.className ?? ''}`}\n data-cratis-part='name'\n onDoubleClick={startEditing}\n onKeyDown={event => { if (event.key === 'F2') { event.preventDefault(); startEditing(); } }}\n >\n {property.name}\n </button>\n ) : (\n <span className={`cratis-schema-editor__name cratis-schema-editor__name--static ${parts?.name?.className ?? ''}`} data-cratis-part='name'>\n {property.name}\n </span>\n )}\n\n {canChangeType ? (\n <PropertyTypeMenu\n labels={labels}\n concepts={context.concepts}\n triggerPart='typeButton'\n triggerLabel={labels.changeType(property.name, property.concept ?? typeName)}\n parts={parts}\n onSelect={(type, concept) => operations.changeType?.(property.id, type, concept)}\n >\n {typeBadge}\n </PropertyTypeMenu>\n ) : typeBadge}\n\n {canSetRequired && (\n <label\n {...parts?.required}\n title={labels.requiredHelp}\n className={`cratis-schema-editor__required ${parts?.required?.className ?? ''}`}\n data-cratis-part='required'\n >\n <input\n type='checkbox'\n checked={property.isRequired === true}\n disabled={readOnly}\n aria-label={labels.requiredProperty(property.name)}\n aria-description={labels.requiredHelp}\n onChange={event => operations.setRequired?.(property.id, event.target.checked)}\n />\n {labels.required}\n </label>\n )}\n\n {canSetKey && (\n <button\n {...parts?.key}\n type='button'\n aria-pressed={property.isKey === true}\n aria-label={labels.keyProperty(property.name)}\n title={property.isKey ? labels.isKey : labels.setAsKey}\n className={`cratis-schema-editor__key ${parts?.key?.className ?? ''}`}\n data-cratis-part='key'\n data-pressed={property.isKey === true || undefined}\n onClick={() => operations.setKey?.(property.id)}\n >\n <FaKey aria-hidden='true' />\n </button>\n )}\n\n {context.renderAccessory && (\n <span {...parts?.accessory} className={`cratis-schema-editor__accessory ${parts?.accessory?.className ?? ''}`} data-cratis-part='accessory'>\n {context.renderAccessory(property, rowContext)}\n </span>\n )}\n\n {isProtected ? (\n <span\n {...parts?.protected}\n role='img'\n aria-label={labels.protectedProperty}\n title={labels.protectedProperty}\n className={`cratis-schema-editor__protected ${parts?.protected?.className ?? ''}`}\n data-cratis-part='protected'\n >\n <FaLock aria-hidden='true' />\n </span>\n ) : canRemove && (\n <button\n {...parts?.remove}\n type='button'\n aria-label={labels.deletePropertyFor(property.name)}\n title={labels.deletePropertyFor(property.name)}\n className={`cratis-schema-editor__remove ${parts?.remove?.className ?? ''}`}\n data-cratis-part='remove'\n onClick={() => operations.remove?.(property.id)}\n >\n <FaXmark aria-hidden='true' />\n </button>\n )}\n </div>\n\n {details && (\n <div {...parts?.details} className={`cratis-schema-editor__details ${parts?.details?.className ?? ''}`} data-cratis-part='details'>\n {details}\n </div>\n )}\n\n {hasNestedProperties(property.type) && (\n <>\n {(property.children ?? []).length > 0 && (\n <ul\n {...parts?.list}\n aria-label={nestedLabel}\n className={`cratis-schema-editor__list cratis-schema-editor__list--nested ${parts?.list?.className ?? ''}`}\n data-cratis-part='list'\n >\n {(property.children ?? []).map(child => (\n <SchemaPropertyRow key={child.id} property={child} siblings={property.children ?? []} depth={depth + 1} />\n ))}\n </ul>\n )}\n {canAddChild && (\n <PropertyTypeMenu\n labels={labels}\n concepts={context.concepts}\n triggerPart='add'\n triggerLabel={labels.addPropertyTo(property.name)}\n parts={parts}\n onSelect={(type, concept) => operations.addChild?.(property.id, type, concept)}\n >\n <FaPlus aria-hidden='true' />\n {labels.addProperty}\n </PropertyTypeMenu>\n )}\n </>\n )}\n </li>\n );\n};\n"],"names":["_jsx","_jsxs","_Fragment"],"mappings":";;;;;;;;;AAyBA,MAAM,mBAAmB,GAAG,0DAA0D;AAG/E,MAAM,iBAAiB,GAAG,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAA0B,KAAI;AACvF,IAAA,MAAM,OAAO,GAAG,sBAAsB,EAAE;IACxC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,OAAO;AACvD,IAAA,MAAM,SAAS,GAAG,KAAK,EAAE;AACzB,IAAA,MAAM,SAAS,GAAG,MAAM,CAAmB,IAAI,CAAC;IAChD,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC;AACjD,IAAA,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC;IACzD,MAAM,CAAC,OAAO,EAAE,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CAAC,KACjCF,eACQ,KAAK,EAAE,IAAI,EAAA,YAAA,EACH,WAAW,EACvB,SAAS,EAAE,CAAA,8DAAA,EAAiE,KAAK,EAAE,IAAI,EAAE,SAAS,IAAI,EAAE,CAAA,CAAE,EAAA,kBAAA,EACzF,MAAM,YAEtB,CAAC,QAAQ,CAAC,QAAQ,IAAI,EAAE,EAAE,GAAG,CAAC,KAAK,KAChCA,GAAA,CAAC,iBAAiB,EAAA,EAAgB,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,EAAA,EAA9E,KAAK,CAAC,EAAE,CAA0E,CAC7G,CAAC,EAAA,CACD,CACR,EACA,WAAW,KACRC,IAAA,CAAC,gBAAgB,EAAA,EACb,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAC1B,WAAW,EAAC,KAAK,EACjB,YAAY,EAAE,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,EACjD,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,UAAU,CAAC,QAAQ,GAAG,QAAQ,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,aAE9ED,GAAA,CAAC,MAAM,EAAA,EAAA,aAAA,EAAa,MAAM,GAAG,EAC5B,MAAM,CAAC,WAAW,IACJ,CACtB,CAAA,EAAA,CACF,CACN,CAAA,EAAA,CACA;AAEb;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** What a host can say about the row of one property through `getPropertyRowState`. */
|
|
2
|
+
export interface SchemaPropertyRowState {
|
|
3
|
+
/** Extra class names for the row. */
|
|
4
|
+
className?: string;
|
|
5
|
+
/** Extra `data-*` attributes for the row, for example to mark it as a drop target. `undefined` values are left out. */
|
|
6
|
+
attributes?: {
|
|
7
|
+
[attribute: `data-${string}`]: string | undefined;
|
|
8
|
+
};
|
|
9
|
+
/** A tooltip for the row. */
|
|
10
|
+
title?: string;
|
|
11
|
+
/** When true the type of the property can no longer be changed, for example because something is bound to it. */
|
|
12
|
+
lockType?: boolean;
|
|
13
|
+
/** Why the type is locked. Shown as the tooltip of the locked type badge and exposed to assistive technology as its description. Only used with `lockType`. */
|
|
14
|
+
lockTypeReason?: string;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=SchemaPropertyRowState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaPropertyRowState.d.ts","sourceRoot":"","sources":["../../../../SchemaEditor/Tree/SchemaPropertyRowState.ts"],"names":[],"mappings":"AAGA,uFAAuF;AACvF,MAAM,WAAW,sBAAsB;IACnC,qCAAqC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,uHAAuH;IACvH,UAAU,CAAC,EAAE;QAAE,CAAC,SAAS,EAAE,QAAQ,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IAEnE,6BAA6B;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,iHAAiH;IACjH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,+JAA+J;IAC/J,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaPropertyRowState.js","sourceRoot":"","sources":["../../../../SchemaEditor/Tree/SchemaPropertyRowState.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG","sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/** What a host can say about the row of one property through `getPropertyRowState`. */\nexport interface SchemaPropertyRowState {\n /** Extra class names for the row. */\n className?: string;\n\n /** Extra `data-*` attributes for the row, for example to mark it as a drop target. `undefined` values are left out. */\n attributes?: { [attribute: `data-${string}`]: string | undefined };\n\n /** A tooltip for the row. */\n title?: string;\n\n /** When true the type of the property can no longer be changed, for example because something is bound to it. */\n lockType?: boolean;\n\n /** Why the type is locked. Shown as the tooltip of the locked type badge and exposed to assistive technology as its description. Only used with `lockType`. */\n lockTypeReason?: string;\n}\n"]}
|
|
@@ -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,K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IACrE,MAAM,CAAC,EAAE,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};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E,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,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,C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I,CAAC;QAAE,OAAO,mBAAmB,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,20 @@
|
|
|
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
|
+
/**
|
|
8
|
+
* The display name of a property type.
|
|
9
|
+
* @param type The type.
|
|
10
|
+
* @param labels The resolved labels.
|
|
11
|
+
* @returns The localized name.
|
|
12
|
+
*/
|
|
13
|
+
export declare function propertyTypeName(type: PropertyType, labels: Required<SchemaEditorLabels>): string;
|
|
14
|
+
/**
|
|
15
|
+
* Whether values of the type carry nested properties.
|
|
16
|
+
* @param type The type.
|
|
17
|
+
* @returns `true` for objects and lists of objects.
|
|
18
|
+
*/
|
|
19
|
+
export declare function hasNestedProperties(type: PropertyType): boolean;
|
|
20
|
+
//# 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;;;;;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,34 @@
|
|
|
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
|
+
function propertyTypeName(type, labels) {
|
|
17
|
+
switch (type) {
|
|
18
|
+
case PropertyType.Number: return labels.typeNumber;
|
|
19
|
+
case PropertyType.Boolean: return labels.typeBoolean;
|
|
20
|
+
case PropertyType.Date: return labels.typeDate;
|
|
21
|
+
case PropertyType.Time: return labels.typeTime;
|
|
22
|
+
case PropertyType.StringArray: return labels.typeStringArray;
|
|
23
|
+
case PropertyType.NumberArray: return labels.typeNumberArray;
|
|
24
|
+
case PropertyType.Object: return labels.typeObject;
|
|
25
|
+
case PropertyType.ObjectArray: return labels.typeObjectArray;
|
|
26
|
+
default: return labels.typeString;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function hasNestedProperties(type) {
|
|
30
|
+
return type === PropertyType.Object || type === PropertyType.ObjectArray;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { compositePropertyTypes, hasNestedProperties, primitivePropertyTypes, propertyTypeName };
|
|
34
|
+
//# 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/**\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;;AAStB,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;;"}
|