UNPKG

alinea

Version:

[![npm](https://img.shields.io/npm/v/alinea.svg)](https://npmjs.org/package/alinea) [![install size](https://packagephobia.com/badge?p=alinea)](https://packagephobia.com/result?p=alinea)

271 lines (266 loc) 10 kB
import { __commonJS, __toESM } from "../../chunks/chunk-U5RRZUYZ.js"; // node_modules/computed-style/dist/computedStyle.commonjs.js var require_computedStyle_commonjs = __commonJS({ "node_modules/computed-style/dist/computedStyle.commonjs.js"(exports, module) { var computedStyle = function(el, prop, getComputedStyle) { getComputedStyle = window.getComputedStyle; return ( // If we have getComputedStyle (getComputedStyle ? ( // Query it // TODO: From CSS-Query notes, we might need (node, null) for FF getComputedStyle(el) ) : ( // Otherwise, we are in IE and use currentStyle el.currentStyle ))[ // Switch to camelCase for CSSOM // DEV: Grabbed from jQuery // https://github.com/jquery/jquery/blob/1.9-stable/src/css.js#L191-L194 // https://github.com/jquery/jquery/blob/1.9-stable/src/core.js#L593-L597 prop.replace(/-(\w)/gi, function(word, letter) { return letter.toUpperCase(); }) ] ); }; module.exports = computedStyle; } }); // node_modules/line-height/lib/line-height.js var require_line_height = __commonJS({ "node_modules/line-height/lib/line-height.js"(exports, module) { var computedStyle = require_computedStyle_commonjs(); function lineHeight(node) { var lnHeightStr = computedStyle(node, "line-height"); var lnHeight = parseFloat(lnHeightStr, 10); if (lnHeightStr === lnHeight + "") { var _lnHeightStyle = node.style.lineHeight; node.style.lineHeight = lnHeightStr + "em"; lnHeightStr = computedStyle(node, "line-height"); lnHeight = parseFloat(lnHeightStr, 10); if (_lnHeightStyle) { node.style.lineHeight = _lnHeightStyle; } else { delete node.style.lineHeight; } } if (lnHeightStr.indexOf("pt") !== -1) { lnHeight *= 4; lnHeight /= 3; } else if (lnHeightStr.indexOf("mm") !== -1) { lnHeight *= 96; lnHeight /= 25.4; } else if (lnHeightStr.indexOf("cm") !== -1) { lnHeight *= 96; lnHeight /= 2.54; } else if (lnHeightStr.indexOf("in") !== -1) { lnHeight *= 96; } else if (lnHeightStr.indexOf("pc") !== -1) { lnHeight *= 16; } lnHeight = Math.round(lnHeight); if (lnHeightStr === "normal") { var nodeName = node.nodeName; var _node = document.createElement(nodeName); _node.innerHTML = "&nbsp;"; if (nodeName.toUpperCase() === "TEXTAREA") { _node.setAttribute("rows", "1"); } var fontSizeStr = computedStyle(node, "font-size"); _node.style.fontSize = fontSizeStr; _node.style.padding = "0px"; _node.style.border = "0px"; var body = document.body; body.appendChild(_node); var height = _node.offsetHeight; lnHeight = height; body.removeChild(_node); } return lnHeight; } module.exports = lineHeight; } }); // node_modules/autosize/dist/autosize.esm.js var e; var t; var n = "function" == typeof Map ? /* @__PURE__ */ new Map() : (e = [], t = [], { has: function(t2) { return e.indexOf(t2) > -1; }, get: function(n2) { return t[e.indexOf(n2)]; }, set: function(n2, o2) { -1 === e.indexOf(n2) && (e.push(n2), t.push(o2)); }, delete: function(n2) { var o2 = e.indexOf(n2); o2 > -1 && (e.splice(o2, 1), t.splice(o2, 1)); } }); var o = function(e2) { return new Event(e2, { bubbles: true }); }; try { new Event("test"); } catch (e2) { o = function(e3) { var t2 = document.createEvent("Event"); return t2.initEvent(e3, true, false), t2; }; } function r(e2) { var t2 = n.get(e2); t2 && t2.destroy(); } function i(e2) { var t2 = n.get(e2); t2 && t2.update(); } var l = null; "undefined" == typeof window || "function" != typeof window.getComputedStyle ? ((l = function(e2) { return e2; }).destroy = function(e2) { return e2; }, l.update = function(e2) { return e2; }) : ((l = function(e2, t2) { return e2 && Array.prototype.forEach.call(e2.length ? e2 : [e2], function(e3) { return function(e4) { if (e4 && e4.nodeName && "TEXTAREA" === e4.nodeName && !n.has(e4)) { var t3, r2 = null, i2 = null, l2 = null, d2 = function() { e4.clientWidth !== i2 && c(); }, a = function(t4) { window.removeEventListener("resize", d2, false), e4.removeEventListener("input", c, false), e4.removeEventListener("keyup", c, false), e4.removeEventListener("autosize:destroy", a, false), e4.removeEventListener("autosize:update", c, false), Object.keys(t4).forEach(function(n2) { e4.style[n2] = t4[n2]; }), n.delete(e4); }.bind(e4, { height: e4.style.height, resize: e4.style.resize, overflowY: e4.style.overflowY, overflowX: e4.style.overflowX, wordWrap: e4.style.wordWrap }); e4.addEventListener("autosize:destroy", a, false), "onpropertychange" in e4 && "oninput" in e4 && e4.addEventListener("keyup", c, false), window.addEventListener("resize", d2, false), e4.addEventListener("input", c, false), e4.addEventListener("autosize:update", c, false), e4.style.overflowX = "hidden", e4.style.wordWrap = "break-word", n.set(e4, { destroy: a, update: c }), "vertical" === (t3 = window.getComputedStyle(e4, null)).resize ? e4.style.resize = "none" : "both" === t3.resize && (e4.style.resize = "horizontal"), r2 = "content-box" === t3.boxSizing ? -(parseFloat(t3.paddingTop) + parseFloat(t3.paddingBottom)) : parseFloat(t3.borderTopWidth) + parseFloat(t3.borderBottomWidth), isNaN(r2) && (r2 = 0), c(); } function u(t4) { var n2 = e4.style.width; e4.style.width = "0px", e4.style.width = n2, e4.style.overflowY = t4; } function s() { if (0 !== e4.scrollHeight) { var t4 = function(e5) { for (var t5 = []; e5 && e5.parentNode && e5.parentNode instanceof Element; ) e5.parentNode.scrollTop && t5.push({ node: e5.parentNode, scrollTop: e5.parentNode.scrollTop }), e5 = e5.parentNode; return t5; }(e4), n2 = document.documentElement && document.documentElement.scrollTop; e4.style.height = "", e4.style.height = e4.scrollHeight + r2 + "px", i2 = e4.clientWidth, t4.forEach(function(e5) { e5.node.scrollTop = e5.scrollTop; }), n2 && (document.documentElement.scrollTop = n2); } } function c() { s(); var t4 = Math.round(parseFloat(e4.style.height)), n2 = window.getComputedStyle(e4, null), r3 = "content-box" === n2.boxSizing ? Math.round(parseFloat(n2.height)) : e4.offsetHeight; if (r3 < t4 ? "hidden" === n2.overflowY && (u("scroll"), s(), r3 = "content-box" === n2.boxSizing ? Math.round(parseFloat(window.getComputedStyle(e4, null).height)) : e4.offsetHeight) : "hidden" !== n2.overflowY && (u("hidden"), s(), r3 = "content-box" === n2.boxSizing ? Math.round(parseFloat(window.getComputedStyle(e4, null).height)) : e4.offsetHeight), l2 !== r3) { l2 = r3; var i3 = o("autosize:resized"); try { e4.dispatchEvent(i3); } catch (e5) { } } } }(e3); }), e2; }).destroy = function(e2) { return e2 && Array.prototype.forEach.call(e2.length ? e2 : [e2], r), e2; }, l.update = function(e2) { return e2 && Array.prototype.forEach.call(e2.length ? e2 : [e2], i), e2; }); var d = l; var autosize_esm_default = d; // src/ui/util/TextareaAutosize.tsx var import_line_height = __toESM(require_line_height(), 1); import React from "react"; import { jsx } from "react/jsx-runtime"; var getLineHeight = import_line_height.default; var RESIZED = "autosize:resized"; var TextareaAutosizeClass = class extends React.Component { static defaultProps = { rows: 1, async: false }; state = { lineHeight: null }; textarea = null; currentValue; onResize = (e2) => { if (this.props.onResize) { this.props.onResize(e2); } }; componentDidMount() { const { maxRows, async } = this.props; if (typeof maxRows === "number") { this.updateLineHeight(); } if (typeof maxRows === "number" || async) { setTimeout(() => this.textarea && autosize_esm_default(this.textarea)); } else { this.textarea && autosize_esm_default(this.textarea); } if (this.textarea) { this.textarea.addEventListener(RESIZED, this.onResize); } } componentWillUnmount() { if (this.textarea) { this.textarea.removeEventListener(RESIZED, this.onResize); autosize_esm_default.destroy(this.textarea); } } updateLineHeight = () => { if (this.textarea) { this.setState({ lineHeight: getLineHeight(this.textarea) }); } }; onChange = (e2) => { const { onChange } = this.props; this.currentValue = e2.currentTarget.value; onChange && onChange(e2); }; render() { const { props: { onResize, maxRows, onChange, style, innerRef, children, ...props }, state: { lineHeight } } = this; const maxHeight = maxRows && lineHeight ? lineHeight * maxRows : null; return /* @__PURE__ */ jsx( "textarea", { ...props, onChange: this.onChange, style: maxHeight ? { ...style, maxHeight } : style, ref: (element) => { this.textarea = element; if (typeof this.props.innerRef === "function") { this.props.innerRef(element); } else if (this.props.innerRef) { ; this.props.innerRef.current = element; } }, children } ); } componentDidUpdate() { this.textarea && autosize_esm_default.update(this.textarea); } }; var TextareaAutosize = React.forwardRef( (props, ref) => { return /* @__PURE__ */ jsx(TextareaAutosizeClass, { ...props, innerRef: ref }); } ); export { TextareaAutosize };