@pixerate/editor-react 0.170.0 → 0.172.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.
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import { insertSticker, type StickerInsertHost, type StickerProvider } from '@pixerate/editor/stickers';
3
+ export interface StickerInsertPanelProps {
4
+ provider: StickerProvider;
5
+ /** Where stickers go: `createVectorStickerHost`, `createImageStickerHost`, `createCanvasStickerHost` or your own. */
6
+ host: StickerInsertHost;
7
+ /** Called with what was inserted (its id, ref, size and licence). */
8
+ onInserted?: (result: Awaited<ReturnType<typeof insertSticker>>) => void;
9
+ className?: string;
10
+ }
11
+ /**
12
+ * Pick a sticker to insert it into an editor (one undo step), centred in the document at its
13
+ * natural size, with an optional tint for tintable stickers: the panel counterpart of
14
+ * `insert_sticker`.
15
+ */
16
+ export declare const StickerInsertPanel: React.FC<StickerInsertPanelProps>;
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import { insertSticker, type StickerInsertHost, type StickerProvider } from '@pixerate/editor/stickers';
3
+ export interface StickerInsertPanelProps {
4
+ provider: StickerProvider;
5
+ /** Where stickers go: `createVectorStickerHost`, `createImageStickerHost`, `createCanvasStickerHost` or your own. */
6
+ host: StickerInsertHost;
7
+ /** Called with what was inserted (its id, ref, size and licence). */
8
+ onInserted?: (result: Awaited<ReturnType<typeof insertSticker>>) => void;
9
+ className?: string;
10
+ }
11
+ /**
12
+ * Pick a sticker to insert it into an editor (one undo step), centred in the document at its
13
+ * natural size, with an optional tint for tintable stickers: the panel counterpart of
14
+ * `insert_sticker`.
15
+ */
16
+ export declare const StickerInsertPanel: React.FC<StickerInsertPanelProps>;
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import { type StickerBrowserItem, type StickerProvider } from '@pixerate/editor/stickers';
3
+ export interface StickerLibraryPickerProps {
4
+ /** The sticker library (e.g. `editorStickers()`, a host's, or `combineStickerProviders([...])`). */
5
+ provider: StickerProvider;
6
+ /** Refs shown as chosen. */
7
+ selected?: readonly string[];
8
+ /** Called with a sticker when it is clicked. */
9
+ onPick: (sticker: StickerBrowserItem) => void;
10
+ /** Accessible name of the sticker list (default "Stickers"). */
11
+ label?: string;
12
+ /** Shown under the list (e.g. load errors). */
13
+ footer?: React.ReactNode;
14
+ className?: string;
15
+ }
16
+ /**
17
+ * Stickers from a sticker library: searchable, by category and a page at a time, with each
18
+ * sticker's licence in its tooltip. Clicking one calls `onPick`. The same picker serves the paint
19
+ * editor's sticker brush and inserting stickers into the vector, image and canvas editors.
20
+ */
21
+ export declare const StickerLibraryPicker: React.FC<StickerLibraryPickerProps>;
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import { type StickerBrowserItem, type StickerProvider } from '@pixerate/editor/stickers';
3
+ export interface StickerLibraryPickerProps {
4
+ /** The sticker library (e.g. `editorStickers()`, a host's, or `combineStickerProviders([...])`). */
5
+ provider: StickerProvider;
6
+ /** Refs shown as chosen. */
7
+ selected?: readonly string[];
8
+ /** Called with a sticker when it is clicked. */
9
+ onPick: (sticker: StickerBrowserItem) => void;
10
+ /** Accessible name of the sticker list (default "Stickers"). */
11
+ label?: string;
12
+ /** Shown under the list (e.g. load errors). */
13
+ footer?: React.ReactNode;
14
+ className?: string;
15
+ }
16
+ /**
17
+ * Stickers from a sticker library: searchable, by category and a page at a time, with each
18
+ * sticker's licence in its tooltip. Clicking one calls `onPick`. The same picker serves the paint
19
+ * editor's sticker brush and inserting stickers into the vector, image and canvas editors.
20
+ */
21
+ export declare const StickerLibraryPicker: React.FC<StickerLibraryPickerProps>;
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/stickers/index.ts
21
+ var stickers_exports = {};
22
+ __export(stickers_exports, {
23
+ StickerInsertPanel: () => StickerInsertPanel,
24
+ StickerLibraryPicker: () => StickerLibraryPicker
25
+ });
26
+ module.exports = __toCommonJS(stickers_exports);
27
+
28
+ // src/stickers/StickerLibraryPicker.tsx
29
+ var import_react = require("react");
30
+ var import_stickers = require("@pixerate/editor/stickers");
31
+ var import_jsx_runtime = require("react/jsx-runtime");
32
+ var StickerLibraryPicker = ({ provider, selected = [], onPick, label = "Stickers", footer, className }) => {
33
+ const browser = (0, import_react.useMemo)(() => new import_stickers.StickerBrowser(() => provider), [provider]);
34
+ const [, setTick] = (0, import_react.useState)(0);
35
+ (0, import_react.useEffect)(() => {
36
+ const off = browser.subscribe(() => setTick((n) => n + 1));
37
+ void browser.refresh();
38
+ return off;
39
+ }, [browser]);
40
+ const s = browser.state;
41
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: `flex flex-col gap-1 ${className ?? ""}`, "data-testid": "sticker-picker", children: [
42
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center gap-1", children: [
43
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "search", "aria-label": `Search ${label.toLowerCase()}`, placeholder: `Search ${s.provider}`, value: s.query, onChange: (e) => void browser.setQuery(e.target.value), className: "min-w-0 flex-1 rounded bg-slate-800 px-1 py-0.5" }),
44
+ s.categories.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("select", { "aria-label": "Sticker category", value: s.category, onChange: (e) => void browser.setCategory(e.target.value), className: "rounded bg-slate-800 px-1 py-0.5", children: [
45
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "", children: "All" }),
46
+ s.categories.map((c) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: c.id, children: c.name }, c.id))
47
+ ] })
48
+ ] }),
49
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex max-h-32 flex-wrap gap-1 overflow-y-auto", role: "group", "aria-label": label, children: s.items.map((it) => {
50
+ const on = selected.includes(it.ref);
51
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
52
+ "button",
53
+ {
54
+ type: "button",
55
+ "aria-pressed": on,
56
+ title: `${it.name} (${it.ref}) \xB7 ${it.licence.name}${it.licence.attribution ? ` \xB7 ${it.licence.attribution}` : ""}`,
57
+ className: `flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] ${on ? "bg-indigo-600 text-white" : "bg-slate-800 text-slate-300"}`,
58
+ onClick: () => onPick(it),
59
+ children: [
60
+ it.thumbnail && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src: it.thumbnail, alt: "", className: "h-4 w-4" }),
61
+ it.name
62
+ ]
63
+ },
64
+ it.ref
65
+ );
66
+ }) }),
67
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center justify-between text-[10px] text-slate-500", children: [
68
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: s.loading ? "Loading\u2026" : `${s.items.length} of ${s.total}` }),
69
+ s.hasMore && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "text-indigo-300", onClick: () => void browser.more(), children: "More" })
70
+ ] }),
71
+ s.error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { role: "alert", className: "text-[11px] text-rose-400", children: s.error }),
72
+ footer
73
+ ] });
74
+ };
75
+
76
+ // src/stickers/StickerInsertPanel.tsx
77
+ var import_react2 = require("react");
78
+ var import_stickers2 = require("@pixerate/editor/stickers");
79
+ var import_jsx_runtime2 = require("react/jsx-runtime");
80
+ var StickerInsertPanel = ({ provider, host, onInserted, className }) => {
81
+ const [tint, setTint] = (0, import_react2.useState)(null);
82
+ const [error, setError] = (0, import_react2.useState)(null);
83
+ const [busy, setBusy] = (0, import_react2.useState)(false);
84
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: `flex flex-col gap-1.5 text-xs ${className ?? ""}`, "data-testid": "sticker-insert", children: [
85
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
86
+ StickerLibraryPicker,
87
+ {
88
+ provider,
89
+ label: "Insert sticker",
90
+ onPick: (it) => {
91
+ setBusy(true);
92
+ setError(null);
93
+ (0, import_stickers2.insertSticker)(provider, host, { ref: it.ref, ...tint && it.tintable ? { color: tint } : {} }).then((r) => onInserted?.(r)).catch((e) => setError(e instanceof Error ? e.message : String(e))).finally(() => setBusy(false));
94
+ }
95
+ }
96
+ ),
97
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { className: "flex items-center gap-2", children: [
98
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { type: "checkbox", "aria-label": "Tint stickers", checked: tint !== null, onChange: (e) => setTint(e.target.checked ? "#2563eb" : null) }),
99
+ " Tint",
100
+ tint !== null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { type: "color", "aria-label": "Sticker tint", value: tint, onChange: (e) => setTint(e.target.value) }),
101
+ busy && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-slate-500", children: "Inserting\u2026" })
102
+ ] }),
103
+ error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { role: "alert", className: "text-[11px] text-rose-400", children: error })
104
+ ] });
105
+ };
106
+ // Annotate the CommonJS export names for ESM import in node:
107
+ 0 && (module.exports = {
108
+ StickerInsertPanel,
109
+ StickerLibraryPicker
110
+ });
@@ -0,0 +1,2 @@
1
+ export * from './StickerLibraryPicker.cjs';
2
+ export * from './StickerInsertPanel.cjs';
@@ -0,0 +1,2 @@
1
+ export * from './StickerLibraryPicker.js';
2
+ export * from './StickerInsertPanel.js';
@@ -0,0 +1,38 @@
1
+ import {
2
+ StickerLibraryPicker
3
+ } from "../chunk-KYMDNWSX.js";
4
+
5
+ // src/stickers/StickerInsertPanel.tsx
6
+ import { useState } from "react";
7
+ import { insertSticker } from "@pixerate/editor/stickers";
8
+ import { jsx, jsxs } from "react/jsx-runtime";
9
+ var StickerInsertPanel = ({ provider, host, onInserted, className }) => {
10
+ const [tint, setTint] = useState(null);
11
+ const [error, setError] = useState(null);
12
+ const [busy, setBusy] = useState(false);
13
+ return /* @__PURE__ */ jsxs("div", { className: `flex flex-col gap-1.5 text-xs ${className ?? ""}`, "data-testid": "sticker-insert", children: [
14
+ /* @__PURE__ */ jsx(
15
+ StickerLibraryPicker,
16
+ {
17
+ provider,
18
+ label: "Insert sticker",
19
+ onPick: (it) => {
20
+ setBusy(true);
21
+ setError(null);
22
+ insertSticker(provider, host, { ref: it.ref, ...tint && it.tintable ? { color: tint } : {} }).then((r) => onInserted?.(r)).catch((e) => setError(e instanceof Error ? e.message : String(e))).finally(() => setBusy(false));
23
+ }
24
+ }
25
+ ),
26
+ /* @__PURE__ */ jsxs("label", { className: "flex items-center gap-2", children: [
27
+ /* @__PURE__ */ jsx("input", { type: "checkbox", "aria-label": "Tint stickers", checked: tint !== null, onChange: (e) => setTint(e.target.checked ? "#2563eb" : null) }),
28
+ " Tint",
29
+ tint !== null && /* @__PURE__ */ jsx("input", { type: "color", "aria-label": "Sticker tint", value: tint, onChange: (e) => setTint(e.target.value) }),
30
+ busy && /* @__PURE__ */ jsx("span", { className: "text-slate-500", children: "Inserting\u2026" })
31
+ ] }),
32
+ error && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-[11px] text-rose-400", children: error })
33
+ ] });
34
+ };
35
+ export {
36
+ StickerInsertPanel,
37
+ StickerLibraryPicker
38
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixerate/editor-react",
3
- "version": "0.170.0",
3
+ "version": "0.172.0",
4
4
  "description": "React bindings and prompt/rich-text components for @pixerate/editor",
5
5
  "author": "Pixerate",
6
6
  "license": "MIT",
@@ -34,6 +34,16 @@
34
34
  "default": "./dist/effects/index.cjs"
35
35
  }
36
36
  },
37
+ "./stickers": {
38
+ "import": {
39
+ "types": "./dist/stickers/index.d.ts",
40
+ "default": "./dist/stickers/index.js"
41
+ },
42
+ "require": {
43
+ "types": "./dist/stickers/index.d.cts",
44
+ "default": "./dist/stickers/index.cjs"
45
+ }
46
+ },
37
47
  "./spreadsheet": {
38
48
  "import": {
39
49
  "types": "./dist/spreadsheet/index.d.ts",
@@ -254,7 +264,7 @@
254
264
  "dependencies": {},
255
265
  "peerDependencies": {
256
266
  "@dagrejs/dagre": "^1.1.8",
257
- "@pixerate/editor": ">=0.249.0 <1.0.0-0",
267
+ "@pixerate/editor": ">=0.253.0 <1.0.0-0",
258
268
  "@tiptap/core": "^2.27.3",
259
269
  "@tiptap/extension-bubble-menu": "^2.27.3",
260
270
  "@tiptap/extension-placeholder": "^2.27.3",
@@ -305,7 +315,7 @@
305
315
  "tsup": "^9.0.0",
306
316
  "typescript": "^5.7.3",
307
317
  "vitest": "^5.0.5",
308
- "@pixerate/editor": "0.249.0"
318
+ "@pixerate/editor": "0.253.0"
309
319
  },
310
320
  "scripts": {
311
321
  "build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",