@ai-react-markdown/mantine 1.8.0 → 2.0.1

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/dist/index.d.ts CHANGED
@@ -1,48 +1,39 @@
1
1
  import * as react from 'react';
2
- import * as _ai_react_markdown_core from '@ai-react-markdown/core';
3
- import { AIMarkdownMetadata, AIMarkdownRenderConfig, AIMarkdownProps, AIMarkdownTypographyProps, AIMarkdownExtraStylesComponent } from '@ai-react-markdown/core';
2
+ import { AIMarkdownMetadata, AIMarkdownProps, AIMarkdownTypographyProps, AIMarkdownExtraStylesComponent, AIMarkdownBehaviorProps } from '@ai-react-markdown/core';
4
3
 
5
4
  /**
6
- * Mantine-specific type definitions and default configuration.
7
- *
8
- * Extends the core {@link AIMarkdownRenderConfig} and {@link AIMarkdownMetadata}
9
- * with Mantine-themed options such as uniform heading sizes and code block behavior.
5
+ * Mantine-specific type definitions and defaults: the `codeBlock` behavior
6
+ * group and the metadata extension point.
10
7
  *
11
8
  * @module defs
12
9
  */
13
10
 
14
11
  /**
15
- * Extended render configuration for the Mantine integration.
12
+ * Code block rendering options (the mantine `codeBlock` behavior group).
16
13
  *
17
- * Inherits all core config fields (extra syntax, display optimizations) and adds
18
- * Mantine-specific options for typography sizing and code block behavior.
14
+ * v2 transport: passed as the flat `codeBlock` prop on `MantineAIMarkdown`
15
+ * (group value replaces atomically) and read through
16
+ * `useMantineCodeBlockOptions()`, which applies the defaults below inside
17
+ * the hook — the single place defaults live at read time.
19
18
  */
20
- interface MantineAIMarkdownRenderConfig extends AIMarkdownRenderConfig {
21
- /** Code block rendering options. */
22
- codeBlock: {
23
- /**
24
- * Whether code blocks start in their expanded state.
25
- * When `false`, long code blocks are collapsed with an expand button.
26
- *
27
- * @default true
28
- */
29
- defaultExpanded: boolean;
30
- /**
31
- * When `true`, uses `highlight.js` auto-detection to determine the language
32
- * of code blocks that lack an explicit language annotation.
33
- *
34
- * @default false
35
- */
36
- autoDetectUnknownLanguage: boolean;
37
- };
19
+ interface MantineCodeBlockOptions {
20
+ /**
21
+ * Whether code blocks start in their expanded state.
22
+ * When `false`, long code blocks are collapsed with an expand button.
23
+ *
24
+ * @default true
25
+ */
26
+ defaultExpanded: boolean;
27
+ /**
28
+ * When `true`, uses `highlight.js` auto-detection to determine the language
29
+ * of code blocks that lack an explicit language annotation.
30
+ *
31
+ * @default false
32
+ */
33
+ autoDetectUnknownLanguage: boolean;
38
34
  }
39
- /**
40
- * Default Mantine render configuration.
41
- *
42
- * Extends {@link defaultAIMarkdownRenderConfig} with Mantine-specific defaults.
43
- * Frozen to prevent accidental mutation.
44
- */
45
- declare const defaultMantineAIMarkdownRenderConfig: MantineAIMarkdownRenderConfig;
35
+ /** Shipped defaults for the `codeBlock` behavior group. */
36
+ declare const defaultMantineCodeBlockOptions: Readonly<MantineCodeBlockOptions>;
46
37
  /**
47
38
  * Metadata type for the Mantine integration.
48
39
  *
@@ -56,13 +47,19 @@ interface MantineAIMarkdownMetadata extends AIMarkdownMetadata {
56
47
  /**
57
48
  * Props for the {@link MantineAIMarkdown} component.
58
49
  *
59
- * Extends {@link AIMarkdownProps} with Mantine-specific config and metadata generics.
60
- * All core props (`content`, `streaming`, `fontSize`, `config`, etc.) are inherited.
50
+ * Extends {@link AIMarkdownProps} with the mantine behavior groups.
51
+ * All core props (`content`, `streaming`, `fontSize`, `enginePlugins`, etc.)
52
+ * are inherited.
61
53
  *
62
- * @typeParam TConfig - Render configuration type, defaults to {@link MantineAIMarkdownRenderConfig}.
63
- * @typeParam TRenderData - Metadata type, defaults to {@link MantineAIMarkdownMetadata}.
54
+ * @typeParam TMetadata - Metadata type, defaults to {@link MantineAIMarkdownMetadata}.
64
55
  */
65
- interface MantineAIMarkdownProps<TConfig extends MantineAIMarkdownRenderConfig = MantineAIMarkdownRenderConfig, TRenderData extends MantineAIMarkdownMetadata = MantineAIMarkdownMetadata> extends AIMarkdownProps<TConfig, TRenderData> {
56
+ interface MantineAIMarkdownProps<TMetadata extends MantineAIMarkdownMetadata = MantineAIMarkdownMetadata> extends AIMarkdownProps<TMetadata> {
57
+ /**
58
+ * Code-block behavior group (Behaviors system). The group value replaces
59
+ * atomically; omitted fields resolve to the shipped defaults inside
60
+ * `useMantineCodeBlockOptions()`. `null` counts as absent.
61
+ */
62
+ codeBlock?: Partial<MantineCodeBlockOptions>;
66
63
  }
67
64
  /**
68
65
  * Inner (non-memoized) implementation of the Mantine AI markdown component.
@@ -71,10 +68,9 @@ interface MantineAIMarkdownProps<TConfig extends MantineAIMarkdownRenderConfig =
71
68
  * overrides take precedence). Automatically resolves the color scheme from Mantine's
72
69
  * `useComputedColorScheme` when no explicit `colorScheme` prop is provided.
73
70
  *
74
- * @typeParam TConfig - Render configuration type.
75
- * @typeParam TRenderData - Metadata type.
71
+ * @typeParam TMetadata - Metadata type.
76
72
  */
77
- declare const MantineAIMarkdownComponent: <TConfig extends MantineAIMarkdownRenderConfig = MantineAIMarkdownRenderConfig, TRenderData extends MantineAIMarkdownMetadata = MantineAIMarkdownMetadata>({ Typography, ExtraStyles, defaultConfig, customComponents, colorScheme, ...props }: MantineAIMarkdownProps<TConfig, TRenderData>) => react.JSX.Element;
73
+ declare const MantineAIMarkdownComponent: <TMetadata extends MantineAIMarkdownMetadata = MantineAIMarkdownMetadata>({ Typography, ExtraStyles, customComponents, colorScheme, codeBlock, ...props }: MantineAIMarkdownProps<TMetadata>) => react.JSX.Element;
78
74
  declare const _default: typeof MantineAIMarkdownComponent;
79
75
 
80
76
  /**
@@ -105,29 +101,48 @@ declare const MantineAIMarkdownTypography: react.MemoExoticComponent<({ children
105
101
  declare const MantineAIMDefaultExtraStyles: AIMarkdownExtraStylesComponent;
106
102
 
107
103
  /**
108
- * Typed wrapper around the core {@link useAIMarkdownRenderState} hook.
104
+ * Narrow hook for the mantine `codeBlock` behavior group.
109
105
  *
110
- * Returns the current {@link AIMarkdownRenderState} defaulting to
111
- * {@link MantineAIMarkdownRenderConfig}. Accepts an optional generic parameter
112
- * for further extension, giving consumers direct access to Mantine-specific
113
- * config fields (`codeBlock`, etc.) without manual annotation.
106
+ * This is THE single type-assertion site for the group (the pattern that
107
+ * retires the public caller-asserted `TConfig` generic): the opaque
108
+ * extension record from `useAIMarkdownBehaviors()` is narrowed here, and
109
+ * group defaults are applied here read sites must consume this hook and
110
+ * never re-apply defaults with bare `??` (multiple read sites duplicating
111
+ * defaults will drift).
114
112
  *
115
- * Must be called inside a component rendered within the `<MantineAIMarkdown>` tree.
116
- * Throws if called outside the provider boundary.
113
+ * @module hooks/useMantineCodeBlockOptions
114
+ */
115
+
116
+ /**
117
+ * Read the resolved code-block options from the behaviors context.
117
118
  *
118
- * @typeParam TConfig - Config type (defaults to {@link MantineAIMarkdownRenderConfig}).
119
- * @returns The current render state typed with `TConfig`.
119
+ * Group values replace atomically at the transport layer; defaults are
120
+ * filled in here, so a partial group (e.g. `codeBlock={{ defaultExpanded:
121
+ * false }}`) resolves the omitted fields to the shipped defaults.
120
122
  *
121
- * @example
122
- * ```tsx
123
- * function MyComponent() {
124
- * const { config, streaming, colorScheme } = useMantineAIMarkdownRenderState();
125
- * const isExpanded = config.codeBlock.defaultExpanded;
126
- * // ...
127
- * }
128
- * ```
123
+ * Must be called inside a `<MantineAIMarkdown>` (or any `<AIMarkdown>`
124
+ * wrapped in the mantine Provider stack) — throws outside, same contract
125
+ * as the core narrow hooks.
129
126
  */
130
- declare const useMantineAIMarkdownRenderState: <TConfig extends MantineAIMarkdownRenderConfig = MantineAIMarkdownRenderConfig>() => _ai_react_markdown_core.AIMarkdownRenderState<TConfig>;
127
+ declare function useMantineCodeBlockOptions(): Required<MantineCodeBlockOptions>;
128
+
129
+ /**
130
+ * Widened `define*` factory for the mantine wrapper (EXECUTION-PLAN §4
131
+ * item 8): identity + mantine prop types + freeze, zero logic. Core
132
+ * factories accept core fields only — passing `codeBlock` to core's
133
+ * `defineBehaviors` is a TS error; this widened factory is the wrapper's
134
+ * one-line obligation.
135
+ *
136
+ * @module define
137
+ */
138
+
139
+ /** Behavior-system props packagable at integration time, mantine-widened. */
140
+ interface MantineBehaviorProps extends AIMarkdownBehaviorProps {
141
+ /** The mantine `codeBlock` behavior group (atomic replacement; defaults applied at read time). */
142
+ codeBlock?: Partial<MantineCodeBlockOptions>;
143
+ }
144
+ /** Freeze a mantine behaviors fragment. Identity + types + freeze; zero logic. */
145
+ declare function defineMantineBehaviors(values: MantineBehaviorProps): Readonly<MantineBehaviorProps>;
131
146
 
132
147
  /**
133
148
  * Typed wrapper around the core {@link useAIMarkdownMetadata} hook.
@@ -154,4 +169,4 @@ declare const useMantineAIMarkdownRenderState: <TConfig extends MantineAIMarkdow
154
169
  */
155
170
  declare const useMantineAIMarkdownMetadata: <TMetadata extends MantineAIMarkdownMetadata = MantineAIMarkdownMetadata>() => TMetadata | undefined;
156
171
 
157
- export { MantineAIMDefaultExtraStyles, type MantineAIMarkdownMetadata, type MantineAIMarkdownProps, type MantineAIMarkdownRenderConfig, MantineAIMarkdownTypography, _default as default, defaultMantineAIMarkdownRenderConfig, useMantineAIMarkdownMetadata, useMantineAIMarkdownRenderState };
172
+ export { MantineAIMDefaultExtraStyles, type MantineAIMarkdownMetadata, type MantineAIMarkdownProps, MantineAIMarkdownTypography, type MantineBehaviorProps, type MantineCodeBlockOptions, _default as default, defaultMantineCodeBlockOptions, defineMantineBehaviors, useMantineAIMarkdownMetadata, useMantineCodeBlockOptions };
package/dist/index.js CHANGED
@@ -1,7 +1,12 @@
1
1
  // src/MantineAIMarkdown.tsx
2
- import { memo as memo4, useMemo as useMemo2 } from "react";
2
+ import { memo as memo4, useMemo as useMemo3 } from "react";
3
3
  import AIMarkdown from "@ai-react-markdown/core";
4
- import { useStableValue } from "@ai-react-markdown/core";
4
+ import {
5
+ AIMarkdownBehaviorsProvider,
6
+ AIMarkdownStabilityPolicy,
7
+ useStableRecord,
8
+ useStableValue
9
+ } from "@ai-react-markdown/core";
5
10
 
6
11
  // src/components/typography/MantineTypography.tsx
7
12
  import { memo } from "react";
@@ -18,33 +23,36 @@ var MantineAIMDefaultExtraStyles = ({ children }) => {
18
23
  };
19
24
  var DefaultExtraStyles_default = MantineAIMDefaultExtraStyles;
20
25
 
21
- // src/defs.tsx
22
- import { defaultAIMarkdownRenderConfig } from "@ai-react-markdown/core";
23
- var defaultMantineAIMarkdownRenderConfig = Object.freeze({
24
- ...defaultAIMarkdownRenderConfig,
25
- codeBlock: Object.freeze({
26
- defaultExpanded: true,
27
- autoDetectUnknownLanguage: false
28
- })
29
- });
30
-
31
26
  // src/components/customized/PreCode.tsx
32
- import { memo as memo3, useMemo } from "react";
27
+ import { memo as memo3, useMemo as useMemo2 } from "react";
33
28
  import { CodeHighlight, CodeHighlightTabs as CodeHighlightTabs2 } from "@mantine/code-highlight";
34
29
  import { deepParseJson } from "deep-parse-json";
35
30
  import hljs from "highlight.js";
31
+ import { useAIMarkdownTheme as useAIMarkdownTheme2 } from "@ai-react-markdown/core";
36
32
 
37
- // src/hooks/useMantineAIMarkdownRenderState.ts
38
- import { useAIMarkdownRenderState } from "@ai-react-markdown/core";
39
- var useMantineAIMarkdownRenderState = () => {
40
- return useAIMarkdownRenderState();
41
- };
33
+ // src/hooks/useMantineCodeBlockOptions.ts
34
+ import { useMemo } from "react";
35
+ import { useAIMarkdownBehaviors } from "@ai-react-markdown/core";
36
+
37
+ // src/defs.tsx
38
+ var defaultMantineCodeBlockOptions = Object.freeze({
39
+ defaultExpanded: true,
40
+ autoDetectUnknownLanguage: false
41
+ });
42
+
43
+ // src/hooks/useMantineCodeBlockOptions.ts
44
+ function useMantineCodeBlockOptions() {
45
+ const behaviors = useAIMarkdownBehaviors();
46
+ const group = behaviors.codeBlock;
47
+ return useMemo(() => ({ ...defaultMantineCodeBlockOptions, ...group }), [group]);
48
+ }
42
49
 
43
50
  // src/components/customized/MermaidCode/index.tsx
44
51
  import { memo as memo2, useEffect, useRef, useState, useCallback } from "react";
45
52
  import { CodeHighlightControl, CodeHighlightTabs } from "@mantine/code-highlight";
46
53
  import { ActionIcon, CopyButton, Flex, Tooltip } from "@mantine/core";
47
54
  import mermaid from "mermaid";
55
+ import { useAIMarkdownState, useAIMarkdownTheme } from "@ai-react-markdown/core";
48
56
  import { Fragment, jsx as jsx3, jsxs } from "react/jsx-runtime";
49
57
  var PRE_STYLE = { cursor: "pointer", overflow: "auto", width: "100%", padding: "0.5rem" };
50
58
  var sameView = (a, b) => a.kind === "diagram" && b.kind === "diagram" ? a.chartType === b.chartType : a.kind === b.kind;
@@ -82,9 +90,10 @@ var handleViewSVGInNewWindow = (svgElement, isDark) => {
82
90
  }
83
91
  };
84
92
  var MantineAIMMermaidCode = memo2((props) => {
85
- const renderState = useMantineAIMarkdownRenderState();
86
- const isDark = renderState.colorScheme === "dark";
87
- const streaming = renderState.streaming;
93
+ const { colorScheme, fontSize } = useAIMarkdownTheme();
94
+ const { streaming } = useAIMarkdownState();
95
+ const { defaultExpanded } = useMantineCodeBlockOptions();
96
+ const isDark = colorScheme === "dark";
88
97
  const ref = useRef(null);
89
98
  const renderVersionRef = useRef(0);
90
99
  const viewRef = useRef({ kind: "source" });
@@ -169,7 +178,7 @@ var MantineAIMMermaidCode = memo2((props) => {
169
178
  CodeHighlightTabs,
170
179
  {
171
180
  mb: 15,
172
- fz: renderState.fontSize,
181
+ fz: fontSize,
173
182
  w: "100%",
174
183
  code: [
175
184
  {
@@ -178,7 +187,7 @@ var MantineAIMMermaidCode = memo2((props) => {
178
187
  language: "mermaid"
179
188
  }
180
189
  ],
181
- defaultExpanded: renderState.config.codeBlock.defaultExpanded,
190
+ defaultExpanded,
182
191
  maxCollapsedHeight: "320px",
183
192
  styles: {
184
193
  filesScrollarea: {
@@ -273,15 +282,16 @@ var SpecialCodeLanguage = /* @__PURE__ */ ((SpecialCodeLanguage2) => {
273
282
  var SPECIAL_LANGUAGES = new Set(Object.values(SpecialCodeLanguage));
274
283
  var MantineAIMPreCode = memo3(
275
284
  (props) => {
276
- const renderState = useMantineAIMarkdownRenderState();
277
- const codeLanguage = useMemo(() => {
285
+ const { fontSize } = useAIMarkdownTheme2();
286
+ const { autoDetectUnknownLanguage, defaultExpanded } = useMantineCodeBlockOptions();
287
+ const codeLanguage = useMemo2(() => {
278
288
  if (props.existLanguage) return props.existLanguage;
279
- if (renderState.config.codeBlock.autoDetectUnknownLanguage) {
289
+ if (autoDetectUnknownLanguage) {
280
290
  return hljs.highlightAuto(props.codeText).language || "";
281
291
  }
282
292
  return "";
283
- }, [props.existLanguage, props.codeText, renderState.config.codeBlock.autoDetectUnknownLanguage]);
284
- const [usedCodeLanguage, usedFileName] = useMemo(() => {
293
+ }, [props.existLanguage, props.codeText, autoDetectUnknownLanguage]);
294
+ const [usedCodeLanguage, usedFileName] = useMemo2(() => {
285
295
  if (!codeLanguage) return ["plaintext", "unknown"];
286
296
  if (!hljs.getLanguage(codeLanguage)) {
287
297
  return ["plaintext", codeLanguage];
@@ -289,7 +299,7 @@ var MantineAIMPreCode = memo3(
289
299
  return [codeLanguage, codeLanguage];
290
300
  }, [codeLanguage]);
291
301
  const isSpecialCodeBlock = SPECIAL_LANGUAGES.has(codeLanguage);
292
- const normalCodeBlockContent = useMemo(() => {
302
+ const normalCodeBlockContent = useMemo2(() => {
293
303
  if (isSpecialCodeBlock) return null;
294
304
  let usedCodeStr = props.codeText;
295
305
  if (usedCodeStr && usedCodeLanguage.toLowerCase() === "json") {
@@ -300,19 +310,19 @@ var MantineAIMPreCode = memo3(
300
310
  CodeHighlight,
301
311
  {
302
312
  mb: 15,
303
- fz: renderState.fontSize,
313
+ fz: fontSize,
304
314
  w: "100%",
305
315
  code: usedCodeStr,
306
316
  withBorder: true,
307
317
  withExpandButton: true,
308
- defaultExpanded: renderState.config.codeBlock.defaultExpanded,
318
+ defaultExpanded,
309
319
  maxCollapsedHeight: "320px"
310
320
  }
311
321
  ) : /* @__PURE__ */ jsx4(
312
322
  CodeHighlightTabs2,
313
323
  {
314
324
  mb: 15,
315
- fz: renderState.fontSize,
325
+ fz: fontSize,
316
326
  w: "100%",
317
327
  code: [
318
328
  {
@@ -323,19 +333,12 @@ var MantineAIMPreCode = memo3(
323
333
  ],
324
334
  withBorder: true,
325
335
  withExpandButton: true,
326
- defaultExpanded: renderState.config.codeBlock.defaultExpanded,
336
+ defaultExpanded,
327
337
  maxCollapsedHeight: "320px"
328
338
  }
329
339
  );
330
- }, [
331
- isSpecialCodeBlock,
332
- props.codeText,
333
- usedCodeLanguage,
334
- usedFileName,
335
- renderState.fontSize,
336
- renderState.config.codeBlock.defaultExpanded
337
- ]);
338
- const specialCodeBlockContent = useMemo(() => {
340
+ }, [isSpecialCodeBlock, props.codeText, usedCodeLanguage, usedFileName, fontSize, defaultExpanded]);
341
+ const specialCodeBlockContent = useMemo2(() => {
339
342
  switch (codeLanguage) {
340
343
  case "mermaid" /* Mermaid */:
341
344
  return /* @__PURE__ */ jsx4(MermaidCode_default, { code: props.codeText });
@@ -352,6 +355,10 @@ var PreCode_default = MantineAIMPreCode;
352
355
  // src/MantineAIMarkdown.tsx
353
356
  import { useComputedColorScheme } from "@mantine/core";
354
357
  import { jsx as jsx5 } from "react/jsx-runtime";
358
+ var EMPTY_CODE_BLOCK = Object.freeze({});
359
+ var MANTINE_STABILITY_TABLE = {
360
+ codeBlock: AIMarkdownStabilityPolicy.DEEP_EQUAL
361
+ };
355
362
  var DefaultCustomComponents = {
356
363
  pre: ({ node, ...usefulProps }) => {
357
364
  const code = node?.children[0];
@@ -367,32 +374,38 @@ var DefaultCustomComponents = {
367
374
  var MantineAIMarkdownComponent = ({
368
375
  Typography: Typography2 = MantineTypography_default,
369
376
  ExtraStyles = DefaultExtraStyles_default,
370
- defaultConfig = defaultMantineAIMarkdownRenderConfig,
371
377
  customComponents,
372
378
  colorScheme,
379
+ codeBlock,
373
380
  ...props
374
381
  }) => {
375
382
  const stableCustomComponents = useStableValue(customComponents);
376
- const usedComponents = useMemo2(() => {
383
+ const usedComponents = useMemo3(() => {
377
384
  return stableCustomComponents ? { ...DefaultCustomComponents, ...stableCustomComponents } : DefaultCustomComponents;
378
385
  }, [stableCustomComponents]);
379
386
  const computedColorScheme = useComputedColorScheme("light");
380
- return /* @__PURE__ */ jsx5(
387
+ const stable = useStableRecord({ codeBlock }, MANTINE_STABILITY_TABLE);
388
+ const behaviorGroups = useMemo3(() => ({ codeBlock: stable.codeBlock ?? EMPTY_CODE_BLOCK }), [stable.codeBlock]);
389
+ return /* @__PURE__ */ jsx5(AIMarkdownBehaviorsProvider, { value: behaviorGroups, children: /* @__PURE__ */ jsx5(
381
390
  AIMarkdown,
382
391
  {
383
392
  Typography: Typography2,
384
393
  ExtraStyles,
385
- defaultConfig,
386
394
  customComponents: usedComponents,
387
395
  colorScheme: colorScheme ?? computedColorScheme,
388
396
  ...props
389
397
  }
390
- );
398
+ ) });
391
399
  };
392
400
  var MantineAIMarkdown = memo4(MantineAIMarkdownComponent);
393
401
  MantineAIMarkdown.displayName = "MantineAIMarkdown";
394
402
  var MantineAIMarkdown_default = MantineAIMarkdown;
395
403
 
404
+ // src/define.ts
405
+ function defineMantineBehaviors(values) {
406
+ return Object.freeze(values);
407
+ }
408
+
396
409
  // src/hooks/useMantineAIMarkdownMetadata.ts
397
410
  import { useAIMarkdownMetadata } from "@ai-react-markdown/core";
398
411
  var useMantineAIMarkdownMetadata = () => {
@@ -402,8 +415,9 @@ export {
402
415
  DefaultExtraStyles_default as MantineAIMDefaultExtraStyles,
403
416
  MantineTypography_default as MantineAIMarkdownTypography,
404
417
  MantineAIMarkdown_default as default,
405
- defaultMantineAIMarkdownRenderConfig,
418
+ defaultMantineCodeBlockOptions,
419
+ defineMantineBehaviors,
406
420
  useMantineAIMarkdownMetadata,
407
- useMantineAIMarkdownRenderState
421
+ useMantineCodeBlockOptions
408
422
  };
409
423
  //# sourceMappingURL=index.js.map