@ai-matrx/rich-content 0.2.48 → 0.2.50

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,22 @@
1
1
  # Changelog
2
2
 
3
+
4
+ ## 0.2.50
5
+
6
+ - `utils/client-lazy` re-exports `@ai-matrx/kit/client-lazy` (`clientLazy`, `useIsClient`) — one home
7
+ for the host-neutral lazy loader; chat's identical copy points there too (architecture step 3).
8
+
9
+ Consumer action: none. Needs `@ai-matrx/kit` ≥ 0.38.0.
10
+
11
+ ## 0.2.49
12
+
13
+ - The code block's HTML "Preview" button opens the `html` canvas kind with the source
14
+ (`{ type: "html", data, metadata: { title } }`) — the same frame every other "open HTML in
15
+ canvas" path uses — instead of publishing a page and opening the generic `iframe` web view.
16
+ It no longer needs a signed-in user or a page-service call.
17
+
18
+ Consumer action: none.
19
+
3
20
  ## 0.2.48
4
21
 
5
22
  - The copy commands and the document menu strip thinking with THE rule
@@ -8,17 +8,15 @@ import {
8
8
  isKindJsonText,
9
9
  valueCarriesKind
10
10
  } from "@ai-matrx/content-ir/surfaces";
11
- import { extractErrorMessage } from "../utils/lifted/errors.js";
12
11
  import { cn } from "@ai-matrx/design-system";
13
12
  import SmallCodeEditor from "./SmallCodeEditor.js";
14
13
  import CodeBlockHeader from "./CodeBlockHeader.js";
15
14
  import { useThemeMode } from "../host/app-bindings.js";
16
15
  import StickyButtons from "./StickyButtons.js";
17
16
  import { useIsMobile } from "@ai-matrx/kit/media-query";
18
- import { hostHtmlPageService, useHostUser } from "../host/app-bindings.js";
19
17
  import { isCompleteHtmlDocument } from "../utils/lifted/html-document.js";
20
18
  import { codeLanguageToExtension } from "../utils/lifted/code-language-extension.js";
21
- import { Globe, Loader2 } from "lucide-react";
19
+ import { Globe } from "lucide-react";
22
20
  import { useCanvas } from "../host/app-bindings.js";
23
21
  import { toast } from "../host/toast.js";
24
22
  import { ShikiCodeView } from "./highlight/ShikiCodeView.js";
@@ -91,7 +89,6 @@ const CodeBlockBody = ({
91
89
  const [minimapEnabled, setMinimapEnabled] = useState(false);
92
90
  const [isTopInView, setIsTopInView] = useState(false);
93
91
  const [isBottomInView, setIsBottomInView] = useState(false);
94
- const [isCreatingPage, setIsCreatingPage] = useState(false);
95
92
  const [formatTrigger, setFormatTrigger] = useState(0);
96
93
  const openSmartCodeEditorWindow = useOpenSmartCodeEditorWindow();
97
94
  const bottomRef = useRef(null);
@@ -101,37 +98,15 @@ const CodeBlockBody = ({
101
98
  const showStickyButtons = isBottomInView && !isTopInView && !isEditing;
102
99
  const mode = useThemeMode();
103
100
  const isMobile = useIsMobile();
104
- const user = useHostUser();
105
101
  const { open: openCanvas } = useCanvas();
106
102
  const code = editedCode ?? initialCode;
107
103
  const isCompleteHTMLDocument = (htmlCode) => viewLanguage === "html" && isCompleteHtmlDocument(htmlCode);
108
- const handleViewHTML = async () => {
109
- if (!user?.id) {
110
- toast.error("You must be logged in to view HTML pages");
111
- return;
112
- }
113
- setIsCreatingPage(true);
114
- try {
115
- const result = await hostHtmlPageService().createPage(
116
- code,
117
- "HTML Preview",
118
- "Generated from code block",
119
- user.id
120
- );
121
- openCanvas({
122
- type: "iframe",
123
- data: result.url,
124
- metadata: {
125
- title: "HTML Preview",
126
- htmlPageId: result.pageId
127
- }
128
- });
129
- } catch (error) {
130
- console.error("Failed to create HTML page:", error);
131
- toast.error(`Failed to create HTML page: ${extractErrorMessage(error)}`);
132
- } finally {
133
- setIsCreatingPage(false);
134
- }
104
+ const handleViewHTML = () => {
105
+ openCanvas({
106
+ type: "html",
107
+ data: code,
108
+ metadata: { title: "HTML Preview" }
109
+ });
135
110
  };
136
111
  useEffect(() => {
137
112
  const observerOptions = {
@@ -315,7 +290,6 @@ const CodeBlockBody = ({
315
290
  isMobile,
316
291
  isCompleteHTML: isCompleteHTMLDocument(code),
317
292
  handleViewHTML,
318
- isCreatingPage,
319
293
  showWrapLines,
320
294
  handleFormat,
321
295
  handleReset,
@@ -389,11 +363,10 @@ const CodeBlockBody = ({
389
363
  highlightLines: fence.highlightLines
390
364
  }
391
365
  ),
392
- isCompleteHTMLDocument(code) && !isCollapsed && /* @__PURE__ */ jsx(
366
+ isCompleteHTMLDocument(code) && !isCollapsed && /* @__PURE__ */ jsxs(
393
367
  "button",
394
368
  {
395
369
  onClick: handleViewHTML,
396
- disabled: isCreatingPage,
397
370
  className: cn(
398
371
  "absolute bottom-4 right-4 z-20",
399
372
  "flex items-center gap-2 px-4 py-2 rounded-full",
@@ -401,17 +374,13 @@ const CodeBlockBody = ({
401
374
  "text-white text-sm font-medium",
402
375
  "shadow-lg hover:shadow-xl",
403
376
  "transition-all duration-200 ease-in-out",
404
- "transform hover:scale-105",
405
- isCreatingPage && "opacity-50 cursor-not-allowed"
377
+ "transform hover:scale-105"
406
378
  ),
407
379
  title: "Open HTML Preview in Canvas",
408
- children: isCreatingPage ? /* @__PURE__ */ jsxs(Fragment, { children: [
409
- /* @__PURE__ */ jsx(Loader2, { className: "w-4 h-4 animate-spin" }),
410
- /* @__PURE__ */ jsx("span", { children: "Creating..." })
411
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
380
+ children: [
412
381
  /* @__PURE__ */ jsx(Globe, { className: "w-4 h-4" }),
413
382
  /* @__PURE__ */ jsx("span", { children: "Preview" })
414
- ] })
383
+ ]
415
384
  }
416
385
  )
417
386
  ]
@@ -1,13 +1 @@
1
- /**
2
- * `clientLazy` — the package's replacement for `next/dynamic(..., { ssr: false })`: a lazily
3
- * loaded component that renders only on the client. On the server and during hydration it
4
- * renders `loading` (hydration-safe through `useSyncExternalStore`); on the client it renders
5
- * the loaded component inside a Suspense boundary with the same `loading` as the fallback.
6
- */
7
- import { type ComponentType } from "react";
8
- export declare function useIsClient(): boolean;
9
- export declare function clientLazy<P extends object>(load: () => Promise<{
10
- default: ComponentType<P>;
11
- } | ComponentType<P>>, options?: {
12
- loading?: ComponentType;
13
- }): ComponentType<P>;
1
+ export { clientLazy, useIsClient } from "@ai-matrx/kit/client-lazy";
@@ -1,26 +1,5 @@
1
1
  "use client";
2
- import { createElement, lazy, Suspense, useSyncExternalStore } from "react";
3
- const subscribe = () => () => {
4
- };
5
- const onClient = () => true;
6
- const onServer = () => false;
7
- function useIsClient() {
8
- return useSyncExternalStore(subscribe, onClient, onServer);
9
- }
10
- function clientLazy(load, options = {}) {
11
- const Lazy = lazy(async () => {
12
- const m = await load();
13
- return typeof m === "function" || !("default" in m) ? { default: m } : m;
14
- });
15
- const Loading = options.loading;
16
- function ClientLazy(props) {
17
- const client = useIsClient();
18
- const fallback = Loading ? createElement(Loading) : null;
19
- if (!client) return fallback;
20
- return createElement(Suspense, { fallback }, createElement(Lazy, props));
21
- }
22
- return ClientLazy;
23
- }
2
+ import { clientLazy, useIsClient } from "@ai-matrx/kit/client-lazy";
24
3
  export {
25
4
  clientLazy,
26
5
  useIsClient
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-matrx/rich-content",
3
- "version": "0.2.48",
3
+ "version": "0.2.50",
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,21 +130,21 @@
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/content-ir": "latest",
133
+ "@ai-matrx/agents": "latest",
134
134
  "@ai-matrx/alchemy": "latest",
135
+ "@ai-matrx/content-ir": "latest",
135
136
  "@ai-matrx/content-ir-react": "latest",
136
- "@ai-matrx/agents": "latest",
137
137
  "@ai-matrx/data": "latest",
138
+ "@ai-matrx/design-system": "latest",
138
139
  "@ai-matrx/canvas": "latest",
139
- "@ai-matrx/diff": "latest",
140
140
  "@ai-matrx/icons": "latest",
141
141
  "@ai-matrx/kit": "latest",
142
- "@ai-matrx/records": "latest",
143
142
  "@ai-matrx/print": "latest",
144
- "@ai-matrx/records-ui": "latest",
143
+ "@ai-matrx/records": "latest",
145
144
  "@ai-matrx/media": "latest",
146
- "@ai-matrx/tap-target": "latest",
147
- "@ai-matrx/design-system": "latest"
145
+ "@ai-matrx/records-ui": "latest",
146
+ "@ai-matrx/diff": "latest",
147
+ "@ai-matrx/tap-target": "latest"
148
148
  },
149
149
  "peerDependencies": {
150
150
  "react": ">=19.0.0",