@json-layout/vocabulary
Advanced tools
Comparing version 0.9.1 to 0.10.0
{ | ||
"name": "@json-layout/vocabulary", | ||
"version": "0.9.1", | ||
"version": "0.10.0", | ||
"description": "Main JSON Layout vocabulary as JSON schemas and Typescript types. Also contains some small utility functions to validate and normalize annotations.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -212,6 +212,7 @@ import { validateLayoutKeyword, isComponentName, isPartialCompObject, isPartialChildren, isPartialSwitch, isPartialGetItemsExpr, isPartialGetItemsObj, isPartialSlotMarkdown, isPartialGetItemsFetch } from './layout-keyword/index.js' | ||
* @param {(text: string) => string} markdown | ||
* @param {string[]} optionsKeys | ||
* @param {'oneOf'} [arrayChild] | ||
* @returns {{normalized: CompObject, errors: string[]}} | ||
*/ | ||
function getCompObject (layoutKeyword, schemaFragment, schemaPath, markdown, arrayChild) { | ||
function getCompObject (layoutKeyword, schemaFragment, schemaPath, markdown, optionsKeys, arrayChild) { | ||
/** @type {string[]} */ | ||
@@ -247,10 +248,10 @@ const errors = [] | ||
if (compositeCompNames.includes(partial.comp)) { | ||
partial.title = partial.title ?? schemaFragment.title ?? null | ||
if (!('title' in partial)) partial.title = schemaFragment.title ?? null | ||
partial.children = getChildren(getDefaultChildren(schemaFragment), partial.children) | ||
} else if (partial.comp === 'list') { | ||
partial.title = partial.title ?? schemaFragment.title ?? key | ||
if (!('title' in partial)) partial.title = schemaFragment.title ?? key | ||
partial.listEditMode = partial.listEditMode ?? (schemaFragment.items.type === 'object' ? 'inline-single' : 'inline') | ||
partial.listActions = partial.listActions ?? ['add', 'edit', 'delete', 'duplicate', 'sort'] | ||
} else { | ||
partial.label = partial.label ?? schemaFragment.title ?? key | ||
if (!('label' in partial)) partial.label = schemaFragment.title ?? key | ||
} | ||
@@ -303,2 +304,16 @@ | ||
// options can be set directly in layout and normalized in layout.options | ||
// TODO: fetch this list from the schema ? | ||
for (const optionKey of optionsKeys) { | ||
if (optionKey in partial) { | ||
partial.options = partial.options ?? {} | ||
partial.options[optionKey] = partial[optionKey] | ||
delete partial[optionKey] | ||
} | ||
} | ||
if (schemaFragment.readOnly) { | ||
partial.options = partial.options ?? {} | ||
if (!('readOnly' in partial.options)) partial.options.readOnly = true | ||
} | ||
if (partial.getOptions !== undefined) partial.getOptions = normalizeExpression(partial.getOptions) | ||
@@ -377,6 +392,7 @@ if (partial.getDefaultData !== undefined) partial.getDefaultData = normalizeExpression(partial.getDefaultData) | ||
* @param {(text: string) => string} markdown | ||
* @param {string[]} optionsKeys | ||
* @param {'oneOf'} [arrayChild] | ||
* @returns {{normalized: NormalizedLayout, errors: string[]}} | ||
*/ | ||
function getNormalizedLayout (layoutKeyword, schemaFragment, schemaPath, markdown, arrayChild) { | ||
function getNormalizedLayout (layoutKeyword, schemaFragment, schemaPath, markdown, optionsKeys, arrayChild) { | ||
if (isPartialSwitch(layoutKeyword)) { | ||
@@ -392,3 +408,3 @@ /** @type {CompObject[]} */ | ||
const switchCase = switchCases[i] | ||
const compObjectResult = getCompObject(switchCase, schemaFragment, schemaPath, markdown, arrayChild) | ||
const compObjectResult = getCompObject(switchCase, schemaFragment, schemaPath, markdown, optionsKeys, arrayChild) | ||
normalizedSwitchCases.push(compObjectResult.normalized) | ||
@@ -399,3 +415,3 @@ for (const error of compObjectResult.errors) errors.push(`switch ${i} - ${error}`) | ||
} else { | ||
return getCompObject(layoutKeyword, schemaFragment, schemaPath, markdown, arrayChild) | ||
return getCompObject(layoutKeyword, schemaFragment, schemaPath, markdown, optionsKeys, arrayChild) | ||
} | ||
@@ -432,2 +448,4 @@ } | ||
const defaultOptionsKeys = ['readOnly', 'summary', 'titleDepth', 'density', 'removeAdditional', 'validateOn', 'initialValidation', 'defaultOn', 'readOnlyPropertiesMode'] | ||
/** | ||
@@ -437,6 +455,8 @@ * @param {SchemaFragment} schemaFragment | ||
* @param {(text: string) => string} markdown | ||
* @param {string[]} [optionsKeys] | ||
* @param {'oneOf'} [arrayChild] | ||
* @returns {{layout: NormalizedLayout, errors: string[]}} | ||
*/ | ||
export function normalizeLayoutFragment (schemaFragment, schemaPath, markdown = (src) => src, arrayChild) { | ||
export function normalizeLayoutFragment (schemaFragment, schemaPath, markdown = (src) => src, optionsKeys, arrayChild) { | ||
optionsKeys = optionsKeys ? optionsKeys.concat(defaultOptionsKeys) : defaultOptionsKeys | ||
let layoutKeyword | ||
@@ -451,11 +471,11 @@ if (arrayChild === 'oneOf') { | ||
return { | ||
layout: getNormalizedLayout({}, schemaFragment, schemaPath, markdown, arrayChild).normalized, | ||
layout: getNormalizedLayout({}, schemaFragment, schemaPath, markdown, optionsKeys, arrayChild).normalized, | ||
errors: lighterValidationErrors(validateLayoutKeyword.errors) | ||
} | ||
} | ||
const normalizedLayout = getNormalizedLayout(layoutKeyword, schemaFragment, schemaPath, markdown, arrayChild) | ||
const normalizedLayout = getNormalizedLayout(layoutKeyword, schemaFragment, schemaPath, markdown, optionsKeys, arrayChild) | ||
if (!validateNormalizedLayout(normalizedLayout.normalized)) { | ||
console.error(`normalized layout validation errors at path ${schemaPath}`, normalizedLayout, validateNormalizedLayout.errors) | ||
return { | ||
layout: getNormalizedLayout({}, schemaFragment, schemaPath, markdown, arrayChild).normalized, | ||
layout: getNormalizedLayout({}, schemaFragment, schemaPath, markdown, optionsKeys, arrayChild).normalized, | ||
errors: lighterValidationErrors(validateNormalizedLayout.errors) | ||
@@ -462,0 +482,0 @@ } |
@@ -1036,3 +1036,61 @@ | ||
"compact" | ||
], | ||
"default": "default" | ||
}, | ||
"removeAdditional": { | ||
"description": "true is the same as 'unknown', false is the same as 'none'", | ||
"default": "error", | ||
"oneOf": [ | ||
{ | ||
"type": "boolean" | ||
}, | ||
{ | ||
"type": "string", | ||
"enum": [ | ||
"unknown", | ||
"error", | ||
"none" | ||
] | ||
} | ||
] | ||
}, | ||
"validateOn": { | ||
"type": "string", | ||
"enum": [ | ||
"input", | ||
"blur", | ||
"submit" | ||
], | ||
"default": "input" | ||
}, | ||
"initialValidation": { | ||
"type": "string", | ||
"enum": [ | ||
"never", | ||
"always", | ||
"withData" | ||
], | ||
"default": "withData" | ||
}, | ||
"defaultOn": { | ||
"type": "string", | ||
"enum": [ | ||
"missing", | ||
"empty", | ||
"never" | ||
], | ||
"default": "empty" | ||
}, | ||
"autofocus": { | ||
"type": "boolean", | ||
"default": false | ||
}, | ||
"readOnlyPropertiesMode": { | ||
"type": "string", | ||
"enum": [ | ||
"remove", | ||
"hide", | ||
"show" | ||
], | ||
"default": "show" | ||
} | ||
@@ -1039,0 +1097,0 @@ } |
@@ -490,3 +490,35 @@ { | ||
"titleDepth": {"type": "integer", "minimum": 1, "maximum": 6, "default": 2}, | ||
"density": {"type": "string", "enum": ["default", "comfortable", "compact"]} | ||
"density": {"type": "string", "enum": ["default", "comfortable", "compact"], "default": "default"}, | ||
"removeAdditional": { | ||
"description": "true is the same as 'unknown', false is the same as 'none'", | ||
"default": "error", | ||
"oneOf": [ | ||
{"type": "boolean"}, | ||
{ | ||
"type": "string", | ||
"enum": ["unknown", "error", "none"] | ||
} | ||
] | ||
}, | ||
"validateOn": { | ||
"type": "string", | ||
"enum": ["input", "blur", "submit"], | ||
"default": "input" | ||
}, | ||
"initialValidation": { | ||
"type": "string", | ||
"enum": ["never", "always", "withData"], | ||
"default": "withData" | ||
}, | ||
"defaultOn": { | ||
"type": "string", | ||
"enum": ["missing", "empty", "never"], | ||
"default": "empty" | ||
}, | ||
"autofocus": {"type": "boolean", "default": false}, | ||
"readOnlyPropertiesMode": { | ||
"type": "string", | ||
"enum": ["remove", "hide", "show"], | ||
"default": "show" | ||
} | ||
} | ||
@@ -493,0 +525,0 @@ } |
@@ -54,2 +54,11 @@ export type NormalizedLayout = SwitchStruct | CompObject; | ||
density?: "default" | "comfortable" | "compact"; | ||
/** | ||
* true is the same as 'unknown', false is the same as 'none' | ||
*/ | ||
removeAdditional?: boolean | ("unknown" | "error" | "none"); | ||
validateOn?: "input" | "blur" | "submit"; | ||
initialValidation?: "never" | "always" | "withData"; | ||
defaultOn?: "missing" | "empty" | "never"; | ||
autofocus?: boolean; | ||
readOnlyPropertiesMode?: "remove" | "hide" | "show"; | ||
[k: string]: unknown; | ||
@@ -56,0 +65,0 @@ }; |
@@ -21,2 +21,3 @@ import { type LayoutKeyword } from './layout-keyword/types.js' | ||
formatMaximum?: string | ||
readOnly?: boolean | ||
} |
@@ -5,6 +5,7 @@ /** | ||
* @param {(text: string) => string} markdown | ||
* @param {string[]} [optionsKeys] | ||
* @param {'oneOf'} [arrayChild] | ||
* @returns {{layout: NormalizedLayout, errors: string[]}} | ||
*/ | ||
export function normalizeLayoutFragment(schemaFragment: SchemaFragment, schemaPath: string, markdown?: (text: string) => string, arrayChild?: "oneOf" | undefined): { | ||
export function normalizeLayoutFragment(schemaFragment: SchemaFragment, schemaPath: string, markdown?: (text: string) => string, optionsKeys?: string[] | undefined, arrayChild?: "oneOf" | undefined): { | ||
layout: NormalizedLayout; | ||
@@ -11,0 +12,0 @@ errors: string[]; |
@@ -788,3 +788,39 @@ declare namespace _default { | ||
enum: string[]; | ||
default: string; | ||
}; | ||
removeAdditional: { | ||
description: string; | ||
default: string; | ||
oneOf: ({ | ||
type: string; | ||
enum?: undefined; | ||
} | { | ||
type: string; | ||
enum: string[]; | ||
})[]; | ||
}; | ||
validateOn: { | ||
type: string; | ||
enum: string[]; | ||
default: string; | ||
}; | ||
initialValidation: { | ||
type: string; | ||
enum: string[]; | ||
default: string; | ||
}; | ||
defaultOn: { | ||
type: string; | ||
enum: string[]; | ||
default: string; | ||
}; | ||
autofocus: { | ||
type: string; | ||
default: boolean; | ||
}; | ||
readOnlyPropertiesMode: { | ||
type: string; | ||
enum: string[]; | ||
default: string; | ||
}; | ||
}; | ||
@@ -791,0 +827,0 @@ $ref?: undefined; |
@@ -29,2 +29,11 @@ export type NormalizedLayout = SwitchStruct | CompObject; | ||
density?: "default" | "comfortable" | "compact"; | ||
/** | ||
* true is the same as 'unknown', false is the same as 'none' | ||
*/ | ||
removeAdditional?: boolean | ("unknown" | "error" | "none"); | ||
validateOn?: "input" | "blur" | "submit"; | ||
initialValidation?: "never" | "always" | "withData"; | ||
defaultOn?: "missing" | "empty" | "never"; | ||
autofocus?: boolean; | ||
readOnlyPropertiesMode?: "remove" | "hide" | "show"; | ||
[k: string]: unknown; | ||
@@ -31,0 +40,0 @@ }; |
@@ -20,3 +20,4 @@ import { type LayoutKeyword } from './layout-keyword/types.js'; | ||
formatMaximum?: string; | ||
readOnly?: boolean; | ||
} | ||
//# sourceMappingURL=types.d.ts.map |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
424724
5204