UNPKG

@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.

60 lines (56 loc) 2.63 kB
'use strict'; var jsxRuntime = require('preact/jsx-runtime'); var uuid = require('uuid'); require('../../schema/paragraph.js'); require('../../schema/phrase.js'); var isSpecType = require('../../schema/utils/isSpecType.js'); var functionalize = require('../../utils/functionalize.js'); var getPrefixCls = require('../../utils/getPrefixCls.js'); var classnames = require('../../utils/classnames.js'); require('clarinet'); require('../styled/bullet.js'); var container = require('../styled/container.js'); require('../styled/entity.js'); require('../styled/heading.js'); require('../styled/marks.js'); require('../styled/paragraph.js'); var index = require('../paragraph/index.js'); require('../context/hooks/theme.js'); var plugin = require('../context/hooks/plugin.js'); var event = require('../context/hooks/event.js'); require('../../plugin/index.js'); require('tslib'); require('../../theme/seed/index.js'); var hooks = require('preact/hooks'); function Section(_a) { var spec = _a.spec; var onEvent = event.useEvent().onEvent; var pluginManager = plugin.usePluginManager(); var onClick = function () { onEvent === null || onEvent === void 0 ? void 0 : onEvent('section:click', spec); }; var onMouseEnter = function () { onEvent === null || onEvent === void 0 ? void 0 : onEvent('section:mouseenter', spec); }; var onMouseLeave = function () { onEvent === null || onEvent === void 0 ? void 0 : onEvent('section:mouseleave', spec); }; var renderCustomSection = function () { if (isSpecType.isCustomSection(spec)) { var descriptor = pluginManager.getBlockDescriptor(spec.customType); if (descriptor) { return functionalize.functionalize(descriptor.render, null)(spec); } } return null; }; var sectionContent = hooks.useMemo(function () { if (isSpecType.isCustomSection(spec)) { return renderCustomSection(); } return null; }, [spec]); return (jsxRuntime.jsxs(container.Container, { as: "section", className: classnames.classnames(getPrefixCls.getPrefixCls('section'), spec.className), style: spec.styles, onClick: onClick, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, children: [sectionContent && jsxRuntime.jsx(container.Container, { dangerouslySetInnerHTML: { __html: sectionContent.outerHTML } }), isSpecType.isStandardSection(spec) && spec.paragraphs.map(function (p) { return jsxRuntime.jsx(index.Paragraph, { spec: p }, p.key || uuid.v4()); })] })); } exports.Section = Section; //# sourceMappingURL=index.js.map