UNPKG

tldraw

Version:

A tiny little drawing editor.

130 lines (129 loc) 5.02 kB
"use strict"; 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); var PlainTextLabel_exports = {}; __export(PlainTextLabel_exports, { PlainTextLabel: () => PlainTextLabel }); module.exports = __toCommonJS(PlainTextLabel_exports); var import_jsx_runtime = require("react/jsx-runtime"); var import_classnames = __toESM(require("classnames"), 1); var import_react = __toESM(require("react"), 1); var import_PlainTextArea = require("../text/PlainTextArea"); var import_TextHelpers = require("./TextHelpers"); var import_legacyProps = require("./legacyProps"); var import_useEditablePlainText = require("./useEditablePlainText"); const PlainTextLabel = import_react.default.memo(function PlainTextLabel2({ shapeId, type, text: plaintext, labelColor, font, fontSize, lineHeight, align, verticalAlign, wrap, isSelected, padding = 0, onKeyDown: handleKeyDownCustom, classNamePrefix, style, textWidth, textHeight, showTextOutline = true }) { const { rInput, isEmpty, isEditing, isReadyForEditing, ...editableTextRest } = (0, import_useEditablePlainText.useEditablePlainText)(shapeId, type, plaintext); const finalPlainText = import_TextHelpers.TextHelpers.normalizeTextForDom(plaintext || ""); const hasText = finalPlainText.length > 0; const legacyAlign = (0, import_legacyProps.isLegacyAlign)(align); if (!isEditing && !hasText) { return null; } const cssPrefix = classNamePrefix || "tl-text"; return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "div", { className: `${cssPrefix}-label tl-text-wrapper tl-plain-text-wrapper`, "aria-hidden": !isEditing, "data-font": font, "data-align": align, "data-hastext": !isEmpty, "data-isediting": isEditing, "data-is-ready-for-editing": isReadyForEditing, "data-textwrap": !!wrap, "data-isselected": isSelected, style: { justifyContent: align === "middle" || legacyAlign ? "center" : align, alignItems: verticalAlign === "middle" ? "center" : verticalAlign, padding, ...style }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( "div", { className: `${cssPrefix}-label__inner tl-text-content__wrapper`, style: { fontSize, lineHeight: lineHeight.toString(), minHeight: Math.floor(fontSize * lineHeight) + "px", minWidth: Math.ceil(textWidth || 0), color: labelColor, width: textWidth ? Math.ceil(textWidth) : void 0, height: textHeight ? Math.ceil(textHeight) : void 0 }, children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "div", { className: (0, import_classnames.default)( `${cssPrefix} tl-text tl-text-content`, showTextOutline ? "tl-text__outline" : "tl-text__no-outline" ), dir: "auto", children: finalPlainText.split("\n").map((lineOfText, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { dir: "auto", children: lineOfText }, index)) } ), (isReadyForEditing || isSelected) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_PlainTextArea.PlainTextArea, { ref: rInput, text: plaintext, isEditing, shapeId, ...editableTextRest, handleKeyDown: handleKeyDownCustom ?? editableTextRest.handleKeyDown } ) ] } ) } ); }); //# sourceMappingURL=PlainTextLabel.js.map