UNPKG

tldraw

Version:

A tiny little drawing editor.

137 lines (136 loc) • 7.65 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 DoubleDropdownPicker_exports = {}; __export(DoubleDropdownPicker_exports, { DoubleDropdownPicker: () => DoubleDropdownPicker }); module.exports = __toCommonJS(DoubleDropdownPicker_exports); var import_jsx_runtime = require("react/jsx-runtime"); var import_editor = require("@tldraw/editor"); var React = __toESM(require("react")); var import_useTranslation = require("../../hooks/useTranslation/useTranslation"); var import_TldrawUiButtonIcon = require("../primitives/Button/TldrawUiButtonIcon"); var import_TldrawUiPopover = require("../primitives/TldrawUiPopover"); var import_TldrawUiToolbar = require("../primitives/TldrawUiToolbar"); var import_TldrawUiMenuContext = require("../primitives/menus/TldrawUiMenuContext"); function DoubleDropdownPickerInner({ label, uiTypeA, uiTypeB, labelA, labelB, itemsA, itemsB, styleA, styleB, valueA, valueB, onValueChange }) { const editor = (0, import_editor.useEditor)(); const msg = (0, import_useTranslation.useTranslation)(); const [isOpenA, setIsOpenA] = React.useState(false); const [isOpenB, setIsOpenB] = React.useState(false); const iconA = React.useMemo( () => itemsA.find((item) => valueA.type === "shared" && valueA.value === item.value)?.icon ?? "mixed", [itemsA, valueA] ); const iconB = React.useMemo( () => itemsB.find((item) => valueB.type === "shared" && valueB.value === item.value)?.icon ?? "mixed", [itemsB, valueB] ); if (valueA === void 0 && valueB === void 0) return null; const idA = `style panel ${uiTypeA} A`; const idB = `style panel ${uiTypeB} B`; return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "tlui-style-panel__double-select-picker", children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { title: msg(label), className: "tlui-style-panel__double-select-picker-label", children: msg(label) }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_TldrawUiToolbar.TldrawUiToolbar, { label: msg(label), className: "tlui-buttons__horizontal", children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_TldrawUiPopover.TldrawUiPopover, { id: idA, open: isOpenA, onOpenChange: setIsOpenA, children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiPopover.TldrawUiPopoverTrigger, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_TldrawUiToolbar.TldrawUiToolbarButton, { type: "icon", "data-testid": `style.${uiTypeA}`, title: msg(labelA) + " \u2014 " + (valueA === null || valueA.type === "mixed" ? msg("style-panel.mixed") : msg(`${uiTypeA}-style.${valueA.value}`)), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiButtonIcon.TldrawUiButtonIcon, { icon: iconA, small: true, invertIcon: true }) } ) }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiPopover.TldrawUiPopoverContent, { side: "left", align: "center", sideOffset: 80, alignOffset: 0, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiToolbar.TldrawUiToolbar, { label: msg(labelA), className: "tlui-buttons__grid", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiMenuContext.TldrawUiMenuContextProvider, { type: "icons", sourceId: "style-panel", children: itemsA.map((item) => { return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_TldrawUiToolbar.TldrawUiToolbarButton, { "data-testid": `style.${uiTypeA}.${item.value}`, type: "icon", onClick: () => { onValueChange(styleA, item.value); import_editor.tlmenus.deleteOpenMenu(idA, editor.contextId); setIsOpenA(false); }, title: `${msg(labelA)} \u2014 ${msg(`${uiTypeA}-style.${item.value}`)}`, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiButtonIcon.TldrawUiButtonIcon, { icon: item.icon, invertIcon: true }) }, item.value ); }) }) }) }) ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_TldrawUiPopover.TldrawUiPopover, { id: idB, open: isOpenB, onOpenChange: setIsOpenB, children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiPopover.TldrawUiPopoverTrigger, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_TldrawUiToolbar.TldrawUiToolbarButton, { type: "icon", "data-testid": `style.${uiTypeB}`, title: msg(labelB) + " \u2014 " + (valueB === null || valueB.type === "mixed" ? msg("style-panel.mixed") : msg(`${uiTypeB}-style.${valueB.value}`)), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiButtonIcon.TldrawUiButtonIcon, { icon: iconB, small: true }) } ) }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiPopover.TldrawUiPopoverContent, { side: "left", align: "center", sideOffset: 116, alignOffset: 0, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiToolbar.TldrawUiToolbar, { label: msg(labelB), className: "tlui-buttons__grid", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiMenuContext.TldrawUiMenuContextProvider, { type: "icons", sourceId: "style-panel", children: itemsB.map((item) => { return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_TldrawUiToolbar.TldrawUiToolbarButton, { type: "icon", title: `${msg(labelB)} \u2014 ${msg(`${uiTypeB}-style.${item.value}`)}`, "data-testid": `style.${uiTypeB}.${item.value}`, onClick: () => { onValueChange(styleB, item.value); import_editor.tlmenus.deleteOpenMenu(idB, editor.contextId); setIsOpenB(false); }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiButtonIcon.TldrawUiButtonIcon, { icon: item.icon }) }, item.value ); }) }) }) }) ] }) ] }) ] }); } const DoubleDropdownPicker = React.memo( DoubleDropdownPickerInner ); //# sourceMappingURL=DoubleDropdownPicker.js.map