@formant/ava-react
Version:
React components of AVA.
125 lines (123 loc) • 4.7 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/NarrativeTextVis/NarrativeTextVis.tsx
var NarrativeTextVis_exports = {};
__export(NarrativeTextVis_exports, {
NarrativeTextVis: () => NarrativeTextVis
});
module.exports = __toCommonJS(NarrativeTextVis_exports);
var import_react = __toESM(require("react"));
var import_uuid = require("uuid");
var import_lodash = require("lodash");
var import_utils = require("../utils");
var import_constants = require("./constants");
var import_styled = require("./styled");
var import_paragraph = require("./paragraph");
var import_section = require("./section");
var import_plugin = require("./chore/plugin");
var import_exporter = require("./chore/exporter");
function NarrativeTextVis({
spec,
size = "normal",
theme = "dark",
palette,
pluginManager = import_plugin.presetPluginManager,
showCollapse = false,
copyNarrative,
...events
}) {
const narrativeDomRef = (0, import_react.useRef)(null);
const { headline, sections, styles, className } = spec;
const themeStyles = { theme, size, palette };
const {
onClickNarrative,
onMouseEnterNarrative,
onMouseLeaveNarrative,
onCopySuccess,
onCopyFailure,
...sectionEvents
} = events || {};
const onClick = () => {
onClickNarrative == null ? void 0 : onClickNarrative(spec);
};
const onMouseEnter = () => {
onMouseEnterNarrative == null ? void 0 : onMouseEnterNarrative(spec);
};
const onMouseLeave = () => {
onMouseLeaveNarrative == null ? void 0 : onMouseLeaveNarrative(spec);
};
(0, import_react.useEffect)(() => {
var _a;
const onCopy = async (event) => {
const { plainText, html } = await (0, import_exporter.getSelectionContentForCopy)();
if ((0, import_lodash.isFunction)(copyNarrative)) {
copyNarrative({ spec, plainText, html });
} else if ((0, import_lodash.isUndefined)(copyNarrative)) {
if (plainText) {
event.preventDefault();
(0, import_exporter.copyToClipboard)(html, plainText, onCopySuccess, onCopyFailure);
}
}
};
if (!(0, import_lodash.isNull)(copyNarrative)) {
(_a = narrativeDomRef.current) == null ? void 0 : _a.addEventListener("copy", onCopy);
}
return () => {
var _a2;
(_a2 = narrativeDomRef.current) == null ? void 0 : _a2.removeEventListener("copy", onCopy);
};
}, [copyNarrative]);
return /* @__PURE__ */ import_react.default.createElement(
import_styled.Container,
{
className: (0, import_utils.classnames)(className, `${import_constants.NTV_PREFIX_CLS}-container`),
style: styles,
...themeStyles,
onClick,
onMouseEnter,
onMouseLeave,
ref: narrativeDomRef
},
headline ? /* @__PURE__ */ import_react.default.createElement(import_paragraph.Headline, { spec: headline, pluginManager, ...themeStyles, ...sectionEvents }) : null,
sections ? sections == null ? void 0 : sections.map((section) => /* @__PURE__ */ import_react.default.createElement(
import_section.Section,
{
key: section.key || (0, import_uuid.v4)(),
spec: section,
pluginManager,
showCollapse,
...themeStyles,
...sectionEvents
}
)) : null
);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
NarrativeTextVis
});