@ai-matrx/rich-content 0.2.54 → 0.2.55
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.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.55
|
|
4
|
+
|
|
5
|
+
- Transform works on the rich-document bar (chat answers, notes). `ExportPaletteAnchor` kept ONE opener per key, and two bars for one document share `instanceKey("alchemy")`: the newest overwrote the rest and, on unmount, deleted the key while the bar on screen still needed it. The registry now keeps every anchor per key (newest on-screen wins, on `globalThis`), and `openerRef` hands each host its own anchor — the bar's Transform opens its own palette. Guard: `copy/__tests__/export-palette-anchor.test.tsx`.
|
|
6
|
+
- `ContentActionMenuRows` — the set's rows (Plain, the five exports, Print, Transform) for a host whose phone bar already has a ⋯ sheet; the set's own "…" renders the same rows.
|
|
7
|
+
- Plain's tooltip reads "Show source text" (it shows the exact source — a JSON answer shows its JSON).
|
|
8
|
+
|
|
9
|
+
Consumer action: none.
|
|
10
|
+
|
|
3
11
|
## 0.2.54
|
|
4
12
|
|
|
5
13
|
- `RemoteImageGate` (every image the core draws, `DurableMarkdownImg` included) waits for the app's lazy host (`RichContentHostGate`) before it reads the knob hooks. Rendered before the host landed — Write's image island after a reload, whose node view sits outside any gate — it ran the bare defaults, then the app's hooks on the next render: React refused ("Rendered more hooks") and the image vanished.
|
|
@@ -30,6 +30,18 @@ export interface ContentActionsProps {
|
|
|
30
30
|
className?: string;
|
|
31
31
|
}
|
|
32
32
|
export declare function ContentActions({ content, title, copy, viewKey, onTransform, exporters, onPrint, label, size, preserveSelection, disabled, className, }: ContentActionsProps): React.ReactElement;
|
|
33
|
+
export interface ContentActionMenuRowsProps extends Pick<ContentActionsProps, "content" | "title" | "viewKey" | "onTransform" | "exporters" | "onPrint"> {
|
|
34
|
+
/** Close the host's menu / sheet (called before the action runs). */
|
|
35
|
+
onDone?: () => void;
|
|
36
|
+
/** Row class (a bottom sheet wants 44px rows). */
|
|
37
|
+
rowClassName?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The set's rows — Plain, PDF · Word · HTML · Markdown file · Text file, Print, Transform — each ONE tap.
|
|
41
|
+
* The set's own phone "…" renders them; a host whose phone bar already has a ⋯ sheet (the note dock)
|
|
42
|
+
* renders them there instead of a second "…".
|
|
43
|
+
*/
|
|
44
|
+
export declare function ContentActionMenuRows({ content, title, viewKey, onTransform, exporters, onPrint, onDone, rowClassName, }: ContentActionMenuRowsProps): React.ReactElement;
|
|
33
45
|
/** The exact source, shown in place of the render: monospace, wrapped, selectable. */
|
|
34
46
|
export declare function PlainTextView({ text, className }: {
|
|
35
47
|
text: string;
|
|
@@ -42,7 +42,7 @@ function ContentActions({
|
|
|
42
42
|
void (own ? own() : exportContent(read(), format, title));
|
|
43
43
|
};
|
|
44
44
|
const runPrint = () => void (onPrint ? onPrint() : printContent(read(), title));
|
|
45
|
-
const plainName = plain ? "Show formatted" : "Show
|
|
45
|
+
const plainName = plain ? "Show formatted" : "Show source text";
|
|
46
46
|
const PlainIcon = plain ? BookOpen : Code2;
|
|
47
47
|
const exportRows = (close) => CONTENT_EXPORT_FORMATS.map(({ format, label: rowLabel }) => /* @__PURE__ */ jsxs(
|
|
48
48
|
"button",
|
|
@@ -140,65 +140,95 @@ function ContentActions({
|
|
|
140
140
|
children: /* @__PURE__ */ jsx(MoreHorizontal, { className: iconSize })
|
|
141
141
|
}
|
|
142
142
|
) }),
|
|
143
|
-
/* @__PURE__ */ jsx(PopoverContent, { align: "start", className: "w-auto min-w-52 p-1", "data-content-actions-sheet": "", children: /* @__PURE__ */
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
children: [
|
|
156
|
-
/* @__PURE__ */ jsx(PlainIcon, { className: "h-4 w-4 shrink-0 text-muted-foreground" }),
|
|
157
|
-
/* @__PURE__ */ jsx("span", { className: "flex-1", children: plainName })
|
|
158
|
-
]
|
|
159
|
-
}
|
|
160
|
-
) : null,
|
|
161
|
-
exportRows(() => setMoreOpen(false)),
|
|
162
|
-
/* @__PURE__ */ jsxs(
|
|
163
|
-
"button",
|
|
164
|
-
{
|
|
165
|
-
type: "button",
|
|
166
|
-
role: "menuitem",
|
|
167
|
-
"data-content-print": "",
|
|
168
|
-
onClick: () => {
|
|
169
|
-
setMoreOpen(false);
|
|
170
|
-
runPrint();
|
|
171
|
-
},
|
|
172
|
-
className: menuRow,
|
|
173
|
-
children: [
|
|
174
|
-
/* @__PURE__ */ jsx(Printer, { className: "h-4 w-4 shrink-0 text-muted-foreground" }),
|
|
175
|
-
/* @__PURE__ */ jsx("span", { className: "flex-1", children: "Print" })
|
|
176
|
-
]
|
|
177
|
-
}
|
|
178
|
-
),
|
|
179
|
-
onTransform ? /* @__PURE__ */ jsxs(
|
|
180
|
-
"button",
|
|
181
|
-
{
|
|
182
|
-
type: "button",
|
|
183
|
-
role: "menuitem",
|
|
184
|
-
"data-content-transform": "",
|
|
185
|
-
onClick: () => {
|
|
186
|
-
setMoreOpen(false);
|
|
187
|
-
onTransform();
|
|
188
|
-
},
|
|
189
|
-
className: menuRow,
|
|
190
|
-
children: [
|
|
191
|
-
/* @__PURE__ */ jsx(WandSparkles, { className: "h-4 w-4 shrink-0 text-muted-foreground" }),
|
|
192
|
-
/* @__PURE__ */ jsx("span", { className: "flex-1", children: "Transform" })
|
|
193
|
-
]
|
|
194
|
-
}
|
|
195
|
-
) : null
|
|
196
|
-
] }) })
|
|
143
|
+
/* @__PURE__ */ jsx(PopoverContent, { align: "start", className: "w-auto min-w-52 p-1", "data-content-actions-sheet": "", children: /* @__PURE__ */ jsx("div", { role: "menu", "aria-label": "Content actions", children: /* @__PURE__ */ jsx(
|
|
144
|
+
ContentActionMenuRows,
|
|
145
|
+
{
|
|
146
|
+
content: read,
|
|
147
|
+
title,
|
|
148
|
+
viewKey,
|
|
149
|
+
onTransform,
|
|
150
|
+
exporters,
|
|
151
|
+
onPrint,
|
|
152
|
+
onDone: () => setMoreOpen(false)
|
|
153
|
+
}
|
|
154
|
+
) }) })
|
|
197
155
|
] })
|
|
198
156
|
]
|
|
199
157
|
}
|
|
200
158
|
);
|
|
201
159
|
}
|
|
160
|
+
function ContentActionMenuRows({
|
|
161
|
+
content,
|
|
162
|
+
title,
|
|
163
|
+
viewKey,
|
|
164
|
+
onTransform,
|
|
165
|
+
exporters,
|
|
166
|
+
onPrint,
|
|
167
|
+
onDone,
|
|
168
|
+
rowClassName
|
|
169
|
+
}) {
|
|
170
|
+
const read = () => typeof content === "function" ? content() : content;
|
|
171
|
+
const plain = usePlainView(viewKey);
|
|
172
|
+
const plainName = plain ? "Show formatted" : "Show source text";
|
|
173
|
+
const PlainIcon = plain ? BookOpen : Code2;
|
|
174
|
+
const row = cn(menuRow, rowClassName);
|
|
175
|
+
const run = (action) => () => {
|
|
176
|
+
onDone?.();
|
|
177
|
+
void action();
|
|
178
|
+
};
|
|
179
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
180
|
+
viewKey ? /* @__PURE__ */ jsxs(
|
|
181
|
+
"button",
|
|
182
|
+
{
|
|
183
|
+
type: "button",
|
|
184
|
+
role: "menuitem",
|
|
185
|
+
"data-content-plain-toggle": plain ? "plain" : "formatted",
|
|
186
|
+
onClick: run(() => togglePlainView(viewKey)),
|
|
187
|
+
className: row,
|
|
188
|
+
children: [
|
|
189
|
+
/* @__PURE__ */ jsx(PlainIcon, { className: "h-4 w-4 shrink-0 text-muted-foreground" }),
|
|
190
|
+
/* @__PURE__ */ jsx("span", { className: "flex-1", children: plainName })
|
|
191
|
+
]
|
|
192
|
+
}
|
|
193
|
+
) : null,
|
|
194
|
+
CONTENT_EXPORT_FORMATS.map(({ format, label: rowLabel }) => /* @__PURE__ */ jsxs(
|
|
195
|
+
"button",
|
|
196
|
+
{
|
|
197
|
+
type: "button",
|
|
198
|
+
role: "menuitem",
|
|
199
|
+
"data-content-export": format,
|
|
200
|
+
onClick: run(() => {
|
|
201
|
+
const own = exporters?.[format];
|
|
202
|
+
return own ? own() : exportContent(read(), format, title);
|
|
203
|
+
}),
|
|
204
|
+
className: row,
|
|
205
|
+
children: [
|
|
206
|
+
/* @__PURE__ */ jsx(Download, { className: "h-4 w-4 shrink-0 text-muted-foreground" }),
|
|
207
|
+
/* @__PURE__ */ jsx("span", { className: "flex-1", children: rowLabel })
|
|
208
|
+
]
|
|
209
|
+
},
|
|
210
|
+
format
|
|
211
|
+
)),
|
|
212
|
+
/* @__PURE__ */ jsxs(
|
|
213
|
+
"button",
|
|
214
|
+
{
|
|
215
|
+
type: "button",
|
|
216
|
+
role: "menuitem",
|
|
217
|
+
"data-content-print": "",
|
|
218
|
+
onClick: run(() => onPrint ? onPrint() : printContent(read(), title)),
|
|
219
|
+
className: row,
|
|
220
|
+
children: [
|
|
221
|
+
/* @__PURE__ */ jsx(Printer, { className: "h-4 w-4 shrink-0 text-muted-foreground" }),
|
|
222
|
+
/* @__PURE__ */ jsx("span", { className: "flex-1", children: "Print" })
|
|
223
|
+
]
|
|
224
|
+
}
|
|
225
|
+
),
|
|
226
|
+
onTransform ? /* @__PURE__ */ jsxs("button", { type: "button", role: "menuitem", "data-content-transform": "", onClick: run(onTransform), className: row, children: [
|
|
227
|
+
/* @__PURE__ */ jsx(WandSparkles, { className: "h-4 w-4 shrink-0 text-muted-foreground" }),
|
|
228
|
+
/* @__PURE__ */ jsx("span", { className: "flex-1", children: "Transform" })
|
|
229
|
+
] }) : null
|
|
230
|
+
] });
|
|
231
|
+
}
|
|
202
232
|
function PlainTextView({ text, className }) {
|
|
203
233
|
return /* @__PURE__ */ jsx(
|
|
204
234
|
"pre",
|
|
@@ -224,6 +254,7 @@ function ContentView({
|
|
|
224
254
|
}
|
|
225
255
|
var ContentActions_default = ContentActions;
|
|
226
256
|
export {
|
|
257
|
+
ContentActionMenuRows,
|
|
227
258
|
ContentActions,
|
|
228
259
|
ContentView,
|
|
229
260
|
PlainTextView,
|
|
@@ -2,16 +2,21 @@ import * as React from "react";
|
|
|
2
2
|
import type { ContentTransferController } from "@ai-matrx/alchemy/react/workspace";
|
|
3
3
|
/** Is an export palette mounted for this key (a ⋯ "Export…" row shows only then)? */
|
|
4
4
|
export declare function hasExportPalette(key: string): boolean;
|
|
5
|
-
/** Open the export palette mounted under `key
|
|
5
|
+
/** Open the export palette mounted under `key` (the newest one on screen). False when nothing is mounted there. */
|
|
6
6
|
export declare function openExportPalette(key: string): boolean;
|
|
7
7
|
export interface ExportPaletteAnchorProps {
|
|
8
8
|
/** The key a ⋯ "Export…" row opens this palette by (the document's `instanceKey("alchemy")`). */
|
|
9
9
|
exportKey?: string;
|
|
10
10
|
/** The host's hidden ContentTransferMenu — the palette that mounts here. */
|
|
11
11
|
controllerRef: React.RefObject<ContentTransferController | null>;
|
|
12
|
+
/**
|
|
13
|
+
* Receives THIS anchor's opener. A host's own Transform calls it so it always opens its own
|
|
14
|
+
* palette, never another anchor that shares the key.
|
|
15
|
+
*/
|
|
16
|
+
openerRef?: React.MutableRefObject<(() => void) | null>;
|
|
12
17
|
className?: string;
|
|
13
18
|
}
|
|
14
|
-
export declare function ExportPaletteAnchor({ exportKey, controllerRef, className, }: ExportPaletteAnchorProps): React.ReactElement;
|
|
19
|
+
export declare function ExportPaletteAnchor({ exportKey, controllerRef, openerRef, className, }: ExportPaletteAnchorProps): React.ReactElement;
|
|
15
20
|
/** A key for a host that opens its own anchor (the split Copy's "Export…" row). */
|
|
16
21
|
export declare function useExportPaletteKey(): string;
|
|
17
22
|
export default ExportPaletteAnchor;
|
|
@@ -2,35 +2,46 @@
|
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { Popover, PopoverAnchor, PopoverContent, cn } from "@ai-matrx/design-system";
|
|
5
|
-
const hosts = /* @__PURE__ */ new Map();
|
|
5
|
+
const hosts = globalThis[/* @__PURE__ */ Symbol.for("ai-matrx.rich-content.export-palette-hosts")] ??= /* @__PURE__ */ new Map();
|
|
6
|
+
function onScreen(element) {
|
|
7
|
+
return Boolean(element?.isConnected && element.getClientRects().length > 0);
|
|
8
|
+
}
|
|
6
9
|
function hasExportPalette(key) {
|
|
7
|
-
return hosts.
|
|
10
|
+
return (hosts.get(key)?.length ?? 0) > 0;
|
|
8
11
|
}
|
|
9
12
|
function openExportPalette(key) {
|
|
10
|
-
const
|
|
11
|
-
if (!
|
|
12
|
-
|
|
13
|
+
const list = hosts.get(key);
|
|
14
|
+
if (!list?.length) return false;
|
|
15
|
+
const visible = [...list].reverse().find((entry) => onScreen(entry.anchor()));
|
|
16
|
+
(visible ?? list[list.length - 1]).open();
|
|
13
17
|
return true;
|
|
14
18
|
}
|
|
15
19
|
function ExportPaletteAnchor({
|
|
16
20
|
exportKey,
|
|
17
21
|
controllerRef,
|
|
22
|
+
openerRef,
|
|
18
23
|
className
|
|
19
24
|
}) {
|
|
20
25
|
const [open, setOpen] = React.useState(false);
|
|
26
|
+
const anchorRef = React.useRef(null);
|
|
21
27
|
React.useEffect(() => {
|
|
22
|
-
if (!exportKey) return;
|
|
23
28
|
const opener = () => {
|
|
24
29
|
window.setTimeout(() => setOpen(true), 0);
|
|
25
30
|
};
|
|
26
|
-
|
|
31
|
+
if (openerRef) openerRef.current = opener;
|
|
32
|
+
const entry = { open: opener, anchor: () => anchorRef.current };
|
|
33
|
+
if (exportKey) hosts.set(exportKey, [...hosts.get(exportKey) ?? [], entry]);
|
|
27
34
|
return () => {
|
|
28
|
-
if (
|
|
35
|
+
if (openerRef?.current === opener) openerRef.current = null;
|
|
36
|
+
if (!exportKey) return;
|
|
37
|
+
const rest = (hosts.get(exportKey) ?? []).filter((other) => other !== entry);
|
|
38
|
+
if (rest.length) hosts.set(exportKey, rest);
|
|
39
|
+
else hosts.delete(exportKey);
|
|
29
40
|
};
|
|
30
|
-
}, [exportKey]);
|
|
41
|
+
}, [exportKey, openerRef]);
|
|
31
42
|
const close = React.useCallback(() => setOpen(false), []);
|
|
32
43
|
return /* @__PURE__ */ jsxs(Popover, { open, onOpenChange: setOpen, children: [
|
|
33
|
-
/* @__PURE__ */ jsx(PopoverAnchor, { asChild: true, children: /* @__PURE__ */ jsx("span", { "aria-hidden": true, "data-export-palette-anchor": "", className: cn("inline-block h-0 w-0", className) }) }),
|
|
44
|
+
/* @__PURE__ */ jsx(PopoverAnchor, { asChild: true, children: /* @__PURE__ */ jsx("span", { ref: anchorRef, "aria-hidden": true, "data-export-palette-anchor": "", className: cn("inline-block h-0 w-0", className) }) }),
|
|
34
45
|
/* @__PURE__ */ jsx(
|
|
35
46
|
PopoverContent,
|
|
36
47
|
{
|
|
@@ -33,6 +33,7 @@ function ActionBar(props) {
|
|
|
33
33
|
const oneMenu = useOneMenuFor(getCtx().source);
|
|
34
34
|
const hasCopy = actions.some((action) => action.category === "copy");
|
|
35
35
|
const palette = React.useRef(null);
|
|
36
|
+
const openOwnPalette = React.useRef(null);
|
|
36
37
|
const copy = React.useCallback((flavor) => runDocumentCopy(actions, getCtx, flavor), [actions, getCtx]);
|
|
37
38
|
const exporters = React.useMemo(() => {
|
|
38
39
|
const out = {};
|
|
@@ -67,7 +68,7 @@ function ActionBar(props) {
|
|
|
67
68
|
viewKey: sourceId,
|
|
68
69
|
exporters,
|
|
69
70
|
onPrint: printAction ? () => printAction.run(getCtx()) : void 0,
|
|
70
|
-
onTransform: () => void openExportPalette(sourceId)
|
|
71
|
+
onTransform: () => openOwnPalette.current ? openOwnPalette.current() : void openExportPalette(sourceId)
|
|
71
72
|
}
|
|
72
73
|
) : null,
|
|
73
74
|
/* @__PURE__ */ jsx(
|
|
@@ -93,7 +94,7 @@ function ActionBar(props) {
|
|
|
93
94
|
hideOverflow: true
|
|
94
95
|
}
|
|
95
96
|
),
|
|
96
|
-
hasCopy ? /* @__PURE__ */ jsx(ExportPaletteAnchor, { exportKey: sourceId, controllerRef: palette }) : null,
|
|
97
|
+
hasCopy ? /* @__PURE__ */ jsx(ExportPaletteAnchor, { exportKey: sourceId, controllerRef: palette, openerRef: openOwnPalette }) : null,
|
|
97
98
|
hideOverflow ? null : oneMenu ? /* @__PURE__ */ jsx(OpenOneMenuButton, { source: getCtx().source }) : /* @__PURE__ */ jsx(StandaloneOneMenu, { getCtx, target })
|
|
98
99
|
]
|
|
99
100
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-matrx/rich-content",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.55",
|
|
4
4
|
"description": "The AI Matrx formatted-text engine: the one markdown renderer, streaming markdown, the block splitter and renderer, the generic blocks, <RichContent> levels, the rich-document action registry and menus, copy, and the selection toolbar — as portable React.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -130,14 +130,14 @@
|
|
|
130
130
|
"unist-util-visit": "^5.1.0",
|
|
131
131
|
"unist-util-visit-parents": "^6.0.2",
|
|
132
132
|
"yaml": "^2.9.1",
|
|
133
|
+
"@ai-matrx/agents": "latest",
|
|
133
134
|
"@ai-matrx/alchemy": "latest",
|
|
134
135
|
"@ai-matrx/canvas": "latest",
|
|
135
|
-
"@ai-matrx/agents": "latest",
|
|
136
136
|
"@ai-matrx/content-ir": "latest",
|
|
137
137
|
"@ai-matrx/content-ir-react": "latest",
|
|
138
138
|
"@ai-matrx/data": "latest",
|
|
139
|
-
"@ai-matrx/diff": "latest",
|
|
140
139
|
"@ai-matrx/design-system": "latest",
|
|
140
|
+
"@ai-matrx/diff": "latest",
|
|
141
141
|
"@ai-matrx/icons": "latest",
|
|
142
142
|
"@ai-matrx/kit": "latest",
|
|
143
143
|
"@ai-matrx/media": "latest",
|