@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.
58 lines (55 loc) • 2.48 kB
JavaScript
import { jsxs, jsx } from 'preact/jsx-runtime';
import { v4 } from 'uuid';
import '../../schema/paragraph.js';
import '../../schema/phrase.js';
import { isCustomSection, isStandardSection } from '../../schema/utils/isSpecType.js';
import { functionalize } from '../../utils/functionalize.js';
import { getPrefixCls } from '../../utils/getPrefixCls.js';
import { classnames } from '../../utils/classnames.js';
import 'clarinet';
import '../styled/bullet.js';
import { Container } from '../styled/container.js';
import '../styled/entity.js';
import '../styled/heading.js';
import '../styled/marks.js';
import '../styled/paragraph.js';
import { Paragraph } from '../paragraph/index.js';
import '../context/hooks/theme.js';
import { usePluginManager } from '../context/hooks/plugin.js';
import { useEvent } from '../context/hooks/event.js';
import '../../plugin/index.js';
import 'tslib';
import '../../theme/seed/index.js';
import { useMemo } from 'preact/hooks';
function Section(_a) {
var spec = _a.spec;
var onEvent = useEvent().onEvent;
var pluginManager = 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 (isCustomSection(spec)) {
var descriptor = pluginManager.getBlockDescriptor(spec.customType);
if (descriptor) {
return functionalize(descriptor.render, null)(spec);
}
}
return null;
};
var sectionContent = useMemo(function () {
if (isCustomSection(spec)) {
return renderCustomSection();
}
return null;
}, [spec]);
return (jsxs(Container, { as: "section", className: classnames(getPrefixCls('section'), spec.className), style: spec.styles, onClick: onClick, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, children: [sectionContent && jsx(Container, { dangerouslySetInnerHTML: { __html: sectionContent.outerHTML } }), isStandardSection(spec) && spec.paragraphs.map(function (p) { return jsx(Paragraph, { spec: p }, p.key || v4()); })] }));
}
export { Section };
//# sourceMappingURL=index.js.map