@json-layout/core
Advanced tools
Comparing version 0.23.0 to 0.24.0
{ | ||
"name": "@json-layout/core", | ||
"version": "0.23.0", | ||
"version": "0.24.0", | ||
"description": "Compilation and state management utilities for JSON Layout.", | ||
@@ -71,4 +71,3 @@ "type": "module", | ||
"magicast": "^0.3.3", | ||
"markdown-it": "^13.0.2", | ||
"mitt": "^3.0.1" | ||
"markdown-it": "^13.0.2" | ||
}, | ||
@@ -75,0 +74,0 @@ "devDependencies": { |
// eslint-disable-next-line import/no-named-default | ||
import mittModule from 'mitt' | ||
import debug from 'debug' | ||
@@ -17,3 +16,2 @@ import { produce } from 'immer' | ||
* @typedef {import('./types.js').StatefulLayoutOptions} StatefulLayoutOptions | ||
* @typedef {import('./types.js').StatefulLayoutEvents} StatefulLayoutEvents | ||
* @typedef {import('./types.js').CreateStateTreeContext} CreateStateTreeContext | ||
@@ -55,6 +53,2 @@ * @typedef {import('./types.js').TextFieldNode} TextFieldNode | ||
// ugly fix of modules whose default export were wrongly declared | ||
// @ts-ignore | ||
const mitt = /** @type {typeof mittModule.default} */ (mittModule) | ||
/** | ||
@@ -83,2 +77,5 @@ * @param {Partial<StatefulLayoutOptions>} partialOptions | ||
readOnlyPropertiesMode: 'show', | ||
onAutofocus: () => {}, | ||
onUpdate: () => {}, | ||
onData: () => {}, | ||
...partialOptions, | ||
@@ -91,8 +88,2 @@ messages | ||
/** | ||
* @readonly | ||
* @type {import('mitt').Emitter<StatefulLayoutEvents>} | ||
*/ | ||
events | ||
/** | ||
* @private | ||
@@ -228,4 +219,2 @@ * @readonly | ||
this.skeletonTree = skeletonTree | ||
/** @type {import('mitt').Emitter<StatefulLayoutEvents>} */ | ||
this.events = mitt() | ||
this.prepareOptions(options) | ||
@@ -282,3 +271,3 @@ this._autofocusTarget = this.options.autofocus ? '' : null | ||
logDataBinding('emit update event', this._data, this._stateTree) | ||
this.events.emit('update', this) | ||
this.options.onUpdate(this) | ||
this.emitData() | ||
@@ -294,3 +283,3 @@ } | ||
logDataBinding('emit data event', this._data) | ||
this.events.emit('data', this._data) | ||
this.options.onData(this._data) | ||
this._previousData = this._data | ||
@@ -616,6 +605,8 @@ } | ||
const item = {} | ||
/** @type {import('@json-layout/vocabulary').ItemsBasedCompObject} */ | ||
const layout = node.layout | ||
if (typeof rawItem === 'object') { | ||
item.value = node.layout.getItems?.itemValue ? this.evalNodeExpression(node, node.layout.getItems.itemValue, rawItem) : (node.layout.getItems?.returnObjects ? rawItem : rawItem.value) | ||
item.key = node.layout.getItems?.itemKey ? this.evalNodeExpression(node, node.layout.getItems.itemKey, rawItem) : rawItem.key | ||
item.title = node.layout.getItems?.itemTitle ? this.evalNodeExpression(node, node.layout.getItems.itemTitle, rawItem) : rawItem.title | ||
item.value = layout.getItems?.itemValue ? this.evalNodeExpression(node, layout.getItems.itemValue, rawItem) : (layout.getItems?.returnObjects ? rawItem : rawItem.value) | ||
item.key = layout.getItems?.itemKey ? this.evalNodeExpression(node, layout.getItems.itemKey, rawItem) : rawItem.key | ||
item.title = layout.getItems?.itemTitle ? this.evalNodeExpression(node, layout.getItems.itemTitle, rawItem) : rawItem.title | ||
item.value = item.value ?? item.key | ||
@@ -626,7 +617,7 @@ item.key = item.key ?? item.value + '' | ||
} else { | ||
item.value = node.layout.getItems?.itemValue ? this.evalNodeExpression(node, node.layout.getItems.itemValue, rawItem) : rawItem | ||
item.key = node.layout.getItems?.itemKey ? this.evalNodeExpression(node, node.layout.getItems.itemKey, rawItem) : item.value | ||
item.title = node.layout.getItems?.itemTitle ? this.evalNodeExpression(node, node.layout.getItems.itemTitle, rawItem) : item.value | ||
item.value = layout.getItems?.itemValue ? this.evalNodeExpression(node, layout.getItems.itemValue, rawItem) : rawItem | ||
item.key = layout.getItems?.itemKey ? this.evalNodeExpression(node, layout.getItems.itemKey, rawItem) : item.value | ||
item.title = layout.getItems?.itemTitle ? this.evalNodeExpression(node, layout.getItems.itemTitle, rawItem) : item.value | ||
} | ||
if (node.layout.getItems?.itemIcon) item.icon = this.evalNodeExpression(node, node.layout.getItems?.itemIcon, rawItem) | ||
if (layout.getItems?.itemIcon) item.icon = this.evalNodeExpression(node, layout.getItems?.itemIcon, rawItem) | ||
return /** @type {import('@json-layout/vocabulary').SelectItem} */(item) | ||
@@ -674,3 +665,3 @@ } | ||
logDataBinding('emit autofocus event', autofocusTarget) | ||
this.events.emit('autofocus', autofocusTarget) | ||
this.options.onAutofocus(autofocusTarget) | ||
}) | ||
@@ -677,0 +668,0 @@ } |
@@ -99,9 +99,2 @@ import { type ErrorObject } from 'ajv/dist/2019.js' | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export type StatefulLayoutEvents = { | ||
data: any | ||
update: StatefulLayout | ||
autofocus: string | ||
} | ||
// StateNodeOptionsBase come from the vocabulary and should contain all node options that can be set in the layout | ||
@@ -111,2 +104,5 @@ export type StateNodeOptions = Required<StateNodeOptionsBase & { | ||
messages: LocaleMessages | ||
onData: (data: any) => void | ||
onUpdate: (statefulLayout: StatefulLayout) => void | ||
onAutofocus: (key: string) => void | ||
}> | ||
@@ -113,0 +109,0 @@ |
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
10
103438
22
2673
- Removedmitt@^3.0.1
- Removedmitt@3.0.1(transitive)