@antv/t8
Version:
T8 is a text visualization solution for unstructured data within the AntV technology stack, and it is a declarative JSON Schema syntax that can be used to describe the content of data interpretation reports.
44 lines (41 loc) • 2.02 kB
JavaScript
import { __assign } from 'tslib';
import { cloneDeep } from '../utils/cloneDeep.js';
import 'clarinet';
import { createPhraseFactory } from './createPhraseFactory.js';
import { getMergedDescriptor } from './utils/getMergedDescriptor.js';
/**
* Factory function creator for entity phrase descriptors.
*
* This higher-order function creates a factory function that generates entity phrase descriptors.
* It allows customization of entity descriptors while maintaining default behaviors through
* merging or overwriting strategies.
*
* @param key - The entity type identifier for the phrase.
* @param defaultDescriptor - The base descriptor providing default behavior and styling.
* @returns A factory function that creates customized phrase descriptors.
*/
var createEntityPhraseFactory = function (key, defaultDescriptor) {
return function (
/**
* @param customDescriptor - Optional descriptor to customize the entity phrase.
* @param mode - Strategy for applying customizations: 'merge' combines with defaults, 'overwrite' replaces defaults.
* @returns A fully configured phrase descriptor for the entity type.
*/
customDescriptor, mode) {
if (mode === void 0) { mode = 'merge'; }
// Get the base phrase factory for entities.
var entityFactory = createPhraseFactory(true);
// Start with a deep copy of the default descriptor to avoid mutations.
var entityDescriptor = cloneDeep(defaultDescriptor);
// Apply customizations if provided.
// TODO: how to process merge & overwrite
if (customDescriptor) {
entityDescriptor =
mode === 'overwrite' ? customDescriptor : getMergedDescriptor(defaultDescriptor, customDescriptor);
}
// Create the final phrase descriptor with the processed configuration.
return entityFactory(__assign({ key: key }, entityDescriptor));
};
};
export { createEntityPhraseFactory };
//# sourceMappingURL=createEntityPhraseFactory.js.map