@pixerate/editor-react 0.181.0 → 0.183.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1272,11 +1272,11 @@ var PaintSlider = ({ control, value, onChange, onCommit }) => {
1272
1272
  var ErrorLine = ({ error }) => error ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { role: "alert", className: "text-[11px] text-rose-400", children: error }) : null;
1273
1273
 
1274
1274
  // src/brushes/BrushEditor.tsx
1275
- var import_react9 = require("react");
1275
+ var import_react9 = __toESM(require("react"), 1);
1276
1276
  var import_brushes2 = require("@pixerate/editor/brushes");
1277
1277
  var import_jsx_runtime8 = require("react/jsx-runtime");
1278
- var BrushEditor = ({ brush, profile = import_brushes2.PAINT_PROFILE, onChange, preview, previewBackground, onSave, saveLabel = "Save", onSaveAs, renderExtra, className }) => {
1279
- const sections = (0, import_react9.useMemo)(() => (0, import_brushes2.brushEditorSections)(brush, profile), [brush, profile]);
1278
+ var BrushEditor = ({ brush, profile = import_brushes2.PAINT_PROFILE, onChange, preview, previewBackground, onSave, saveLabel = "Save", onSaveAs, renderExtra, sources, onAddSource, className }) => {
1279
+ const sections = (0, import_react9.useMemo)(() => (0, import_brushes2.brushEditorSections)(brush, profile, { sources }), [brush, profile, sources]);
1280
1280
  const scope = (0, import_react9.useMemo)(() => (0, import_brushes2.brushEditorScope)(brush, profile), [brush, profile]);
1281
1281
  const [problems, setProblems] = (0, import_react9.useState)(null);
1282
1282
  const [name, setName] = (0, import_react9.useState)("");
@@ -1294,12 +1294,24 @@ var BrushEditor = ({ brush, profile = import_brushes2.PAINT_PROFILE, onChange, p
1294
1294
  setProblems(r.problems.length ? r.problems.join(" ") : null);
1295
1295
  if (r.brush !== brush) onChange(r.brush);
1296
1296
  };
1297
+ const addSource = onAddSource ? async (file, as) => {
1298
+ try {
1299
+ const r = (0, import_brushes2.withBrushSource)(brush, await onAddSource(file), as);
1300
+ setProblems(r.problems.length ? r.problems.join(" ") : null);
1301
+ onChange(r.brush);
1302
+ } catch (e) {
1303
+ setProblems(e.message);
1304
+ }
1305
+ } : void 0;
1297
1306
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: `flex flex-col gap-2 ${className ?? ""}`, "data-testid": "brush-editor", children: [
1298
1307
  typeof preview === "string" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("img", { src: preview, alt: "Brush preview", className: "rounded object-contain", style: { width: "100%", aspectRatio: "4 / 1", ...previewBackground ? { background: previewBackground } : {} } }) : preview !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(PixelCanvas, { pixels: preview, label: "Brush preview", className: "rounded", style: { width: "100%", aspectRatio: preview ? `${preview.width} / ${preview.height}` : "4 / 1" } }),
1299
1308
  scope.note && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "text-[10px] text-amber-400", "data-testid": "brush-editor-scope", title: `${profile.name} shows only what it can use; these are kept unchanged when you save.`, children: scope.note }),
1300
1309
  sections.map((s) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("section", { className: "flex flex-col gap-1.5", "data-section": s.id, ...s.id === "behaviour" ? { "data-testid": "brush-engine" } : {}, children: [
1301
1310
  /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "font-medium text-slate-300", children: s.title }),
1302
- s.controls.map((c) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(EditorControl, { control: c, onSet: set }, c.path)),
1311
+ s.controls.map((c) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_react9.default.Fragment, { children: [
1312
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(EditorControl, { control: c, onSet: set }),
1313
+ addSource && (c.path === "tip.stamps" || c.path === "tip.grain.source") && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AddImage, { label: c.path === "tip.stamps" ? "Add image tip\u2026" : "Add grain image\u2026", onFile: (f) => addSource(f, c.path === "tip.stamps" ? "tip" : "grain") })
1314
+ ] }, c.path)),
1303
1315
  renderExtra?.(s.id)
1304
1316
  ] }, s.id)),
1305
1317
  (onSave || onSaveAs) && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex flex-wrap items-center gap-1", children: [
@@ -1312,6 +1324,23 @@ var BrushEditor = ({ brush, profile = import_brushes2.PAINT_PROFILE, onChange, p
1312
1324
  /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ErrorLine, { error: problems })
1313
1325
  ] });
1314
1326
  };
1327
+ var AddImage = ({ label, onFile }) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("label", { className: `${button} cursor-pointer self-start`, children: [
1328
+ label,
1329
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1330
+ "input",
1331
+ {
1332
+ type: "file",
1333
+ accept: "image/*",
1334
+ "aria-label": label,
1335
+ className: "sr-only",
1336
+ onChange: (e) => {
1337
+ const file = e.target.files?.[0];
1338
+ e.target.value = "";
1339
+ if (file) onFile(file);
1340
+ }
1341
+ }
1342
+ )
1343
+ ] });
1315
1344
  var EditorControl = ({ control: c, onSet }) => {
1316
1345
  const note = c.note ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "text-[10px] text-amber-400", children: c.note }) : null;
1317
1346
  switch (c.kind) {
@@ -1389,6 +1418,17 @@ var BrushLibraryEditor = ({ library, brushId, profile, renderPreview, previewPap
1389
1418
  const [draft, setDraft] = (0, import_react10.useState)(null);
1390
1419
  const [status, setStatus] = (0, import_react10.useState)(null);
1391
1420
  const [preview, setPreview] = (0, import_react10.useState)(null);
1421
+ const [sources, setSources] = (0, import_react10.useState)([]);
1422
+ (0, import_react10.useEffect)(() => {
1423
+ let live = true;
1424
+ const read = () => void library.listSources().then((list) => live && setSources(list), () => void 0);
1425
+ read();
1426
+ const off = library.subscribe(read);
1427
+ return () => {
1428
+ live = false;
1429
+ off();
1430
+ };
1431
+ }, [library]);
1392
1432
  (0, import_react10.useEffect)(() => {
1393
1433
  let live = true;
1394
1434
  setStatus(null);
@@ -1460,7 +1500,9 @@ var BrushLibraryEditor = ({ library, brushId, profile, renderPreview, previewPap
1460
1500
  },
1461
1501
  onSave: original ? () => save() : void 0,
1462
1502
  saveLabel: builtin ? "Save a copy" : "Save",
1463
- onSaveAs: (name) => save(name)
1503
+ onSaveAs: (name) => save(name),
1504
+ sources,
1505
+ onAddSource: async (file) => (await (0, import_brushes3.addBrushSourceFromFile)(library, file)).ref
1464
1506
  }
1465
1507
  ),
1466
1508
  errors.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("ul", { className: "text-[11px] text-rose-400", "data-testid": "brush-library-editor-issues", children: errors.map((i) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("li", { children: [
@@ -1665,7 +1707,12 @@ function VectorAppearancePanel({ controller, renderBrushPreview, className }) {
1665
1707
  ),
1666
1708
  kind === "stroke" && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", className: buttonClass2, title: "Add a brushstroke (a natural-media brush along the path)", "aria-label": "Add brushstroke", "data-vector-add-brushstroke": "", disabled: !ids.length, onClick: () => controller.addBrushstroke({ brushId: controller.listBrushstrokeBrushes()[0].id, seed: (0, import_vector5.randomVectorBrushstrokeSeed)() }, { ids }), children: "\u270E+" })
1667
1709
  ] }),
1668
- [...layers].reverse().map((l) => layerRow(l, layers.length))
1710
+ [...layers].reverse().map((l) => layerRow(l, layers.length)),
1711
+ kind === "stroke" && layers.some((l) => l.brushstroke) && // Editor state: brushstrokes added or rebrushed from now on keep their colour.
1712
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("label", { className: "flex items-center gap-1 text-[11px] text-muted-foreground", title: "Choosing a brush keeps the stroke's colour instead of taking the brush's default colour", children: [
1713
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("input", { type: "checkbox", "aria-label": "Keep my colour", "data-vector-keep-colour": "", checked: state.colorLocked, onChange: (e) => controller.setColorLocked(e.target.checked) }),
1714
+ " Keep my colour when choosing a brush"
1715
+ ] })
1669
1716
  ] });
1670
1717
  const filterNode = panel.filterNodeId;
1671
1718
  const setFilter = (f, key, value, merge) => {
@@ -15,10 +15,10 @@ import {
15
15
  import {
16
16
  BrushLibraryEditor,
17
17
  useBrushLibrary
18
- } from "../chunk-THMOZMEE.js";
18
+ } from "../chunk-2QXGKOVK.js";
19
19
  import {
20
20
  BrushLibraryBrowser
21
- } from "../chunk-XORL5PGL.js";
21
+ } from "../chunk-GUBRH2OO.js";
22
22
 
23
23
  // src/vector/useVectorEditor.ts
24
24
  import { useEffect, useMemo, useRef, useSyncExternalStore } from "react";
@@ -1237,7 +1237,12 @@ function VectorAppearancePanel({ controller, renderBrushPreview, className }) {
1237
1237
  ),
1238
1238
  kind === "stroke" && /* @__PURE__ */ jsx4("button", { type: "button", className: buttonClass2, title: "Add a brushstroke (a natural-media brush along the path)", "aria-label": "Add brushstroke", "data-vector-add-brushstroke": "", disabled: !ids.length, onClick: () => controller.addBrushstroke({ brushId: controller.listBrushstrokeBrushes()[0].id, seed: randomVectorBrushstrokeSeed() }, { ids }), children: "\u270E+" })
1239
1239
  ] }),
1240
- [...layers].reverse().map((l) => layerRow(l, layers.length))
1240
+ [...layers].reverse().map((l) => layerRow(l, layers.length)),
1241
+ kind === "stroke" && layers.some((l) => l.brushstroke) && // Editor state: brushstrokes added or rebrushed from now on keep their colour.
1242
+ /* @__PURE__ */ jsxs4("label", { className: "flex items-center gap-1 text-[11px] text-muted-foreground", title: "Choosing a brush keeps the stroke's colour instead of taking the brush's default colour", children: [
1243
+ /* @__PURE__ */ jsx4("input", { type: "checkbox", "aria-label": "Keep my colour", "data-vector-keep-colour": "", checked: state.colorLocked, onChange: (e) => controller.setColorLocked(e.target.checked) }),
1244
+ " Keep my colour when choosing a brush"
1245
+ ] })
1241
1246
  ] });
1242
1247
  const filterNode = panel.filterNodeId;
1243
1248
  const setFilter = (f, key, value, merge) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixerate/editor-react",
3
- "version": "0.181.0",
3
+ "version": "0.183.0",
4
4
  "description": "React bindings and prompt/rich-text components for @pixerate/editor",
5
5
  "author": "Pixerate",
6
6
  "license": "MIT",
@@ -277,7 +277,7 @@
277
277
  "dependencies": {},
278
278
  "peerDependencies": {
279
279
  "@dagrejs/dagre": "^1.1.8",
280
- "@pixerate/editor": ">=0.265.0 <1.0.0-0",
280
+ "@pixerate/editor": ">=0.268.0 <1.0.0-0",
281
281
  "@tiptap/core": "^2.27.3",
282
282
  "@tiptap/extension-bubble-menu": "^2.27.3",
283
283
  "@tiptap/extension-placeholder": "^2.27.3",
@@ -328,7 +328,7 @@
328
328
  "tsup": "^9.0.0",
329
329
  "typescript": "^5.7.3",
330
330
  "vitest": "^5.0.5",
331
- "@pixerate/editor": "0.265.0"
331
+ "@pixerate/editor": "0.268.0"
332
332
  },
333
333
  "scripts": {
334
334
  "build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",