@antv/t8
Version:
T8 is a text visualization solution for unstructured data within the AntV technology stack, and it is a declarative T8 markdown syntax that can be used to describe the content of data interpretation reports.
45 lines (41 loc) • 2.09 kB
JavaScript
;
var tslib = require('tslib');
var cloneDeep = require('../utils/cloneDeep.js');
var createPhraseFactory = require('./createPhraseFactory.js');
var getMergedDescriptor = require('./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.createPhraseFactory(true);
// Start with a deep copy of the default descriptor to avoid mutations.
var entityDescriptor = cloneDeep.cloneDeep(defaultDescriptor);
// Apply customizations if provided.
// TODO: how to process merge & overwrite
if (customDescriptor) {
entityDescriptor =
mode === 'overwrite' ? customDescriptor : getMergedDescriptor.getMergedDescriptor(defaultDescriptor, customDescriptor);
}
// Create the final phrase descriptor with the processed configuration.
return entityFactory(tslib.__assign({ key: key }, entityDescriptor));
};
};
exports.createEntityPhraseFactory = createEntityPhraseFactory;
//# sourceMappingURL=createEntityPhraseFactory.js.map