@haklex/rich-renderer-codeblock 0.68.0 → 0.69.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.
@@ -1,4 +1,4 @@
1
- import { ReactNode } from 'react';
1
+ import type { ReactNode } from 'react';
2
2
  interface CodeBlockCardProps {
3
3
  children: ReactNode;
4
4
  code: string;
@@ -8,6 +8,6 @@ interface CodeBlockCardProps {
8
8
  /** Use bodyBackgroundStatic (with paddingBlock) when true. Set by static CodeBlockRenderer. */
9
9
  static?: boolean;
10
10
  }
11
- export declare function CodeBlockCard({ code, language, collapsible, langSlot, children, static: staticMode, }: CodeBlockCardProps): import('react').JSX.Element;
11
+ export declare function CodeBlockCard({ code, language, collapsible, langSlot, children, static: staticMode, }: CodeBlockCardProps): import("react").JSX.Element;
12
12
  export {};
13
13
  //# sourceMappingURL=CodeBlockCard.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeBlockCard.d.ts","sourceRoot":"","sources":["../src/CodeBlockCard.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,OAAO,CAAC;AAWtD,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,SAAS,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,+FAA+F;IAC/F,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,QAAQ,EACR,WAAkB,EAClB,QAAQ,EACR,QAAQ,EACR,MAAM,EAAE,UAAkB,GAC3B,EAAE,kBAAkB,+BAqHpB"}
1
+ {"version":3,"file":"CodeBlockCard.d.ts","sources":["../src/CodeBlockCard.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,OAAO,CAAC;AAWtD,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,SAAS,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,+FAA+F;IAC/F,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,QAAQ,EACR,WAAkB,EAClB,QAAQ,EACR,QAAQ,EACR,MAAM,EAAE,UAAkB,GAC3B,EAAE,kBAAkB,+BAsHpB"}
@@ -1,4 +1,4 @@
1
- import { CodeBlockRendererProps } from '@haklex/rich-editor/renderers';
2
- import { ComponentType } from 'react';
1
+ import type { CodeBlockRendererProps } from '@haklex/rich-editor/renderers';
2
+ import type { ComponentType } from 'react';
3
3
  export declare const CodeBlockEditRenderer: ComponentType<CodeBlockRendererProps>;
4
4
  //# sourceMappingURL=CodeBlockEditRenderer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeBlockEditRenderer.d.ts","sourceRoot":"","sources":["../src/CodeBlockEditRenderer.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAE5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAc3C,eAAO,MAAM,qBAAqB,EAAE,aAAa,CAAC,sBAAsB,CAgQvE,CAAC"}
1
+ {"version":3,"file":"CodeBlockEditRenderer.d.ts","sources":["../src/CodeBlockEditRenderer.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAE5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAc3C,eAAO,MAAM,qBAAqB,EAAE,aAAa,CAAC,sBAAsB,CAqQvE,CAAC"}
@@ -2,6 +2,6 @@ interface LanguageComboboxProps {
2
2
  language: string;
3
3
  onLanguageChange?: (language: string) => void;
4
4
  }
5
- export declare function LanguageCombobox({ language, onLanguageChange }: LanguageComboboxProps): import('react').JSX.Element;
5
+ export declare function LanguageCombobox({ language, onLanguageChange }: LanguageComboboxProps): import("react").JSX.Element;
6
6
  export {};
7
7
  //# sourceMappingURL=LanguageCombobox.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"LanguageCombobox.d.ts","sourceRoot":"","sources":["../src/LanguageCombobox.tsx"],"names":[],"mappings":"AAiBA,UAAU,qBAAqB;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/C;AAED,wBAAgB,gBAAgB,CAAC,EAAE,QAAQ,EAAE,gBAAgB,EAAE,EAAE,qBAAqB,+BAiErF"}
1
+ {"version":3,"file":"LanguageCombobox.d.ts","sources":["../src/LanguageCombobox.tsx"],"names":[],"mappings":"AAiBA,UAAU,qBAAqB;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/C;AAED,wBAAgB,gBAAgB,CAAC,EAAE,QAAQ,EAAE,gBAAgB,EAAE,EAAE,qBAAqB,+BAiErF"}
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA8BpD,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA8BrD,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAGlE;AAyBD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG3D"}
1
+ {"version":3,"file":"constants.d.ts","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA8BpD,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA8BrD,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAGlE;AAyBD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG3D"}
@@ -0,0 +1,4 @@
1
+ /** Maps file extension to material-icon-theme icon name. */
2
+ export declare const EXT_TO_ICON: Record<string, string>;
3
+ export declare function getFileIconSvg(filename: string): string | null;
4
+ //# sourceMappingURL=file-icon-map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-icon-map.d.ts","sources":["../../src/icons/file-icon-map.ts"],"names":[],"mappings":"AAEA,4DAA4D;AAC5D,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAkD9C,CAAC;AAEF,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAI9D"}
@@ -1,6 +1,4 @@
1
- import { FC, ReactNode } from 'react';
2
- /** Maps file extension to material-icon-theme icon name. */
3
- export declare const EXT_TO_ICON: Record<string, string>;
1
+ import type { FC, ReactNode } from 'react';
4
2
  export interface FileIconProps {
5
3
  /** Optional class for the wrapper (e.g. consumer styles). */
6
4
  className?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/icons/file.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAK3C,4DAA4D;AAC5D,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAkD9C,CAAC;AAQF,MAAM,WAAW,aAAa;IAC5B,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mDAAmD;IACnD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,aAAa,CA4BtC,CAAC"}
1
+ {"version":3,"file":"file.d.ts","sources":["../../src/icons/file.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAK3C,MAAM,WAAW,aAAa;IAC5B,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mDAAmD;IACnD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,aAAa,CA4BtC,CAAC"}
@@ -1,5 +1,6 @@
1
1
  export type { FileIconProps } from './file';
2
2
  export { FileIcon } from './file';
3
- export { hasLanguageIcon, LANG_TO_ICON, LanguageIcon } from './language';
3
+ export { LanguageIcon } from './language';
4
+ export { hasLanguageIcon, LANG_TO_ICON } from './language-icon-map';
4
5
  export { getMaterialIconSvg } from './material-icon';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/icons/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AACjC,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sources":["../../src/icons/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,6 @@
1
+ /** Maps normalized language to material-icon-theme icon name. */
2
+ export declare const LANG_TO_ICON: Record<string, string>;
3
+ export declare function getLanguageIconSvg(lang: string): string | null;
4
+ /** Returns whether a Material icon is available for the given language. */
5
+ export declare function hasLanguageIcon(lang: string): boolean;
6
+ //# sourceMappingURL=language-icon-map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"language-icon-map.d.ts","sources":["../../src/icons/language-icon-map.ts"],"names":[],"mappings":"AAEA,iEAAiE;AACjE,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAoE/C,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG9D;AAED,2EAA2E;AAC3E,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAErD"}
@@ -1,8 +1,4 @@
1
- import { FC } from 'react';
2
- /** Maps normalized language to material-icon-theme icon name. */
3
- export declare const LANG_TO_ICON: Record<string, string>;
4
- /** Returns whether a Material icon is available for the given language. */
5
- export declare function hasLanguageIcon(lang: string): boolean;
1
+ import type { FC } from 'react';
6
2
  export declare const LanguageIcon: FC<{
7
3
  language: string;
8
4
  size?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"language.d.ts","sourceRoot":"","sources":["../../src/icons/language.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAMhC,iEAAiE;AACjE,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAoE/C,CAAC;AAOF,2EAA2E;AAC3E,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAErD;AAED,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAiCA,CAAC"}
1
+ {"version":3,"file":"language.d.ts","sources":["../../src/icons/language.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAMhC,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAiCA,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"material-icon.d.ts","sourceRoot":"","sources":["../../src/icons/material-icon.ts"],"names":[],"mappings":"AAGA,wFAAwF;AACxF,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKlE"}
1
+ {"version":3,"file":"material-icon.d.ts","sources":["../../src/icons/material-icon.ts"],"names":[],"mappings":"AAGA,wFAAwF;AACxF,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKlE"}
@@ -11,7 +11,7 @@ function getMaterialIconSvg(iconName) {
11
11
  return iconToHTML(svg.body, svg.attributes);
12
12
  }
13
13
  //#endregion
14
- //#region src/icons/file.tsx
14
+ //#region src/icons/file-icon-map.ts
15
15
  /** Maps file extension to material-icon-theme icon name. */
16
16
  var EXT_TO_ICON = {
17
17
  ts: "typescript",
@@ -67,6 +67,8 @@ var EXT_TO_ICON = {
67
67
  function getFileIconSvg(filename) {
68
68
  return getMaterialIconSvg(EXT_TO_ICON[filename.split(".").pop()?.toLowerCase() ?? ""] ?? "file");
69
69
  }
70
+ //#endregion
71
+ //#region src/icons/file.tsx
70
72
  var FileIcon = ({ filename, size = 16, className, fallback = "F" }) => {
71
73
  const html = useMemo(() => getFileIconSvg(filename), [filename]);
72
74
  const wrapperStyle = {
@@ -128,7 +130,7 @@ var expandButton = "_1pn9r4qe";
128
130
  var lined = "_1pn9r4qf";
129
131
  var linedWithNumbers = "_1pn9r4qg";
130
132
  //#endregion
131
- //#region src/icons/language.tsx
133
+ //#region src/icons/language-icon-map.ts
132
134
  /** Maps normalized language to material-icon-theme icon name. */
133
135
  var LANG_TO_ICON = {
134
136
  "javascript": "javascript",
@@ -206,6 +208,8 @@ function getLanguageIconSvg(lang) {
206
208
  function hasLanguageIcon(lang) {
207
209
  return getLanguageIconSvg(lang) !== null;
208
210
  }
211
+ //#endregion
212
+ //#region src/icons/language.tsx
209
213
  var LanguageIcon = ({ language, size = 14, className = `${langIcon} ${semanticClassNames.langIcon}` }) => {
210
214
  const html = useMemo(() => getLanguageIconSvg(language), [language]);
211
215
  if (!html) return /* @__PURE__ */ jsx("span", {
@@ -231,4 +235,4 @@ var LanguageIcon = ({ language, size = 14, className = `${langIcon} ${semanticCl
231
235
  });
232
236
  };
233
237
  //#endregion
234
- export { getMaterialIconSvg as S, linedWithNumbers as _, bodyBackground as a, semanticClassNames as b, card as c, expandWrap as d, header as f, lined as g, langMark as h, body as i, copyButton as l, langInput as m, LanguageIcon as n, bodyBackgroundStatic as o, lang as p, hasLanguageIcon as r, bodyReadonly as s, LANG_TO_ICON as t, expandButton as u, scroll as v, FileIcon as x, scrollCollapsed as y };
238
+ export { getMaterialIconSvg as S, linedWithNumbers as _, bodyBackground as a, semanticClassNames as b, card as c, expandWrap as d, header as f, lined as g, langMark as h, body as i, copyButton as l, langInput as m, LANG_TO_ICON as n, bodyBackgroundStatic as o, lang as p, hasLanguageIcon as r, bodyReadonly as s, LanguageIcon as t, expandButton as u, scroll as v, FileIcon as x, scrollCollapsed as y };
package/dist/icons.mjs CHANGED
@@ -1 +1 @@
1
- export { x as FileIcon, t as LANG_TO_ICON, n as LanguageIcon, S as getMaterialIconSvg, r as hasLanguageIcon } from "./icons-C6NXwMKM.js";
1
+ export { x as FileIcon, n as LANG_TO_ICON, t as LanguageIcon, S as getMaterialIconSvg, r as hasLanguageIcon } from "./icons-CeZaBHVw.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA"}
package/dist/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  import { getLanguageDisplayName, languageToColorMap, normalizeLanguage } from "./constants.mjs";
2
- import { a as bodyBackground, b as semanticClassNames, c as card, f as header, i as body, l as copyButton, m as langInput, n as LanguageIcon, o as bodyBackgroundStatic, p as lang, r as hasLanguageIcon, v as scroll } from "./icons-C6NXwMKM.js";
2
+ import { a as bodyBackground, b as semanticClassNames, c as card, f as header, i as body, l as copyButton, m as langInput, o as bodyBackgroundStatic, p as lang, r as hasLanguageIcon, t as LanguageIcon, v as scroll } from "./icons-CeZaBHVw.js";
3
3
  import { CodeBlockRenderer } from "./static.mjs";
4
4
  import { defaultKeymap, history, historyKeymap, indentWithTab } from "@codemirror/commands";
5
5
  import { Compartment, EditorSelection, EditorState, Prec } from "@codemirror/state";
6
6
  import { EditorView, keymap, lineNumbers } from "@codemirror/view";
7
7
  import { getThemeExtensions, isOnFirstLine, isOnLastLine, loadLanguageExtension } from "@haklex/cm-editor";
8
8
  import { useColorScheme, useVariant } from "@haklex/rich-editor/static";
9
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
9
+ import { useCallback, useEffect, useEffectEvent, useLayoutEffect, useMemo, useRef, useState } from "react";
10
10
  import { Check, ChevronDown, Copy } from "lucide-react";
11
11
  import { jsx, jsxs } from "react/jsx-runtime";
12
12
  import { Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList, codeLanguages } from "@haklex/rich-editor-ui";
@@ -23,11 +23,9 @@ function CodeBlockCard({ code, language, collapsible = true, langSlot, children,
23
23
  const scrollRef = useRef(null);
24
24
  const lineCount = useMemo(() => code.split("\n").length, [code]);
25
25
  const gutterStyle = useMemo(() => ({ "--rc-ln-digits": Math.max(2, String(lineCount).length) }), [lineCount]);
26
+ if (!collapsible && isOverflow) setIsOverflow(false);
26
27
  useEffect(() => {
27
- if (!collapsible) {
28
- setIsOverflow(false);
29
- return;
30
- }
28
+ if (!collapsible) return;
31
29
  const el = scrollRef.current;
32
30
  if (!el) return;
33
31
  const check = () => {
@@ -182,72 +180,70 @@ var CodeBlockEditRenderer = ({ code, language, showLineNumbers: showLineNumbersP
182
180
  const editorRef = useRef(null);
183
181
  const suppressChangeRef = useRef(false);
184
182
  const editableRef = useRef(editable);
185
- editableRef.current = editable;
186
183
  const onCodeChangeRef = useRef(onCodeChange);
187
- onCodeChangeRef.current = onCodeChange;
188
184
  const onDeleteRef = useRef(onDelete);
189
- onDeleteRef.current = onDelete;
190
185
  const onExitBlockRef = useRef(onExitBlock);
191
- onExitBlockRef.current = onExitBlock;
192
- const languageCompartmentRef = useRef(null);
193
- const editableCompartmentRef = useRef(null);
194
- const lineNumbersCompartmentRef = useRef(null);
195
- const themeCompartmentRef = useRef(null);
196
- if (!languageCompartmentRef.current) languageCompartmentRef.current = new Compartment();
197
- if (!editableCompartmentRef.current) editableCompartmentRef.current = new Compartment();
198
- if (!lineNumbersCompartmentRef.current) lineNumbersCompartmentRef.current = new Compartment();
199
- if (!themeCompartmentRef.current) themeCompartmentRef.current = new Compartment();
200
- const keyboardBoundaryHandler = useMemo(() => Prec.high(EditorView.domEventHandlers({ keydown: (event, view) => {
201
- if (!editableRef.current) return false;
202
- event.stopPropagation();
203
- if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
204
- stopHandledEvent(event);
205
- onExitBlockRef.current?.("after");
206
- return true;
207
- }
208
- if (event.key === "Backspace" && view.state.doc.length === 0) {
209
- stopHandledEvent(event);
210
- onDeleteRef.current?.();
211
- return true;
212
- }
213
- if (event.key === "ArrowUp" && isOnFirstLine(view)) {
214
- stopHandledEvent(event);
215
- onExitBlockRef.current?.("before");
216
- return true;
217
- }
218
- if (event.key === "ArrowDown" && isOnLastLine(view)) {
219
- stopHandledEvent(event);
220
- onExitBlockRef.current?.("after");
221
- return true;
222
- }
223
- return false;
224
- } })), []);
186
+ useLayoutEffect(() => {
187
+ editableRef.current = editable;
188
+ onCodeChangeRef.current = onCodeChange;
189
+ onDeleteRef.current = onDelete;
190
+ onExitBlockRef.current = onExitBlock;
191
+ });
192
+ const [languageCompartment] = useState(() => new Compartment());
193
+ const [editableCompartment] = useState(() => new Compartment());
194
+ const [lineNumbersCompartment] = useState(() => new Compartment());
195
+ const [themeCompartment] = useState(() => new Compartment());
196
+ const createEditor = useEffectEvent((container) => new EditorView({
197
+ parent: container,
198
+ state: EditorState.create({
199
+ doc: code,
200
+ extensions: [
201
+ history(),
202
+ keymap.of([
203
+ ...defaultKeymap,
204
+ ...historyKeymap,
205
+ indentWithTab
206
+ ]),
207
+ EditorView.updateListener.of((update) => {
208
+ if (!update.docChanged || suppressChangeRef.current) return;
209
+ onCodeChangeRef.current?.(update.state.doc.toString());
210
+ }),
211
+ Prec.high(EditorView.domEventHandlers({ keydown: (event, view) => {
212
+ if (!editableRef.current) return false;
213
+ event.stopPropagation();
214
+ if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
215
+ stopHandledEvent(event);
216
+ onExitBlockRef.current?.("after");
217
+ return true;
218
+ }
219
+ if (event.key === "Backspace" && view.state.doc.length === 0) {
220
+ stopHandledEvent(event);
221
+ onDeleteRef.current?.();
222
+ return true;
223
+ }
224
+ if (event.key === "ArrowUp" && isOnFirstLine(view)) {
225
+ stopHandledEvent(event);
226
+ onExitBlockRef.current?.("before");
227
+ return true;
228
+ }
229
+ if (event.key === "ArrowDown" && isOnLastLine(view)) {
230
+ stopHandledEvent(event);
231
+ onExitBlockRef.current?.("after");
232
+ return true;
233
+ }
234
+ return false;
235
+ } })),
236
+ editableCompartment.of([EditorView.editable.of(editable), EditorState.readOnly.of(!editable)]),
237
+ lineNumbersCompartment.of(showLineNumbers ? lineNumbers() : []),
238
+ themeCompartment.of(getThemeExtensions(colorScheme)),
239
+ languageCompartment.of([])
240
+ ]
241
+ })
242
+ }));
225
243
  useEffect(() => {
226
244
  const container = containerRef.current;
227
245
  if (!container) return;
228
- const editor = new EditorView({
229
- parent: container,
230
- state: EditorState.create({
231
- doc: code,
232
- extensions: [
233
- history(),
234
- keymap.of([
235
- ...defaultKeymap,
236
- ...historyKeymap,
237
- indentWithTab
238
- ]),
239
- EditorView.updateListener.of((update) => {
240
- if (!update.docChanged || suppressChangeRef.current) return;
241
- onCodeChangeRef.current?.(update.state.doc.toString());
242
- }),
243
- keyboardBoundaryHandler,
244
- editableCompartmentRef.current.of([EditorView.editable.of(editable), EditorState.readOnly.of(!editable)]),
245
- lineNumbersCompartmentRef.current.of(showLineNumbers ? lineNumbers() : []),
246
- themeCompartmentRef.current.of(getThemeExtensions(colorScheme)),
247
- languageCompartmentRef.current.of([])
248
- ]
249
- })
250
- });
246
+ const editor = createEditor(container);
251
247
  editorRef.current = editor;
252
248
  setMounted(true);
253
249
  return () => {
@@ -259,18 +255,18 @@ var CodeBlockEditRenderer = ({ code, language, showLineNumbers: showLineNumbersP
259
255
  useEffect(() => {
260
256
  const editor = editorRef.current;
261
257
  if (!editor) return;
262
- editor.dispatch({ effects: editableCompartmentRef.current.reconfigure([EditorView.editable.of(editable), EditorState.readOnly.of(!editable)]) });
263
- }, [editable]);
258
+ editor.dispatch({ effects: editableCompartment.reconfigure([EditorView.editable.of(editable), EditorState.readOnly.of(!editable)]) });
259
+ }, [editable, editableCompartment]);
264
260
  useEffect(() => {
265
261
  const editor = editorRef.current;
266
262
  if (!editor) return;
267
- editor.dispatch({ effects: lineNumbersCompartmentRef.current.reconfigure(showLineNumbers ? lineNumbers() : []) });
268
- }, [showLineNumbers]);
263
+ editor.dispatch({ effects: lineNumbersCompartment.reconfigure(showLineNumbers ? lineNumbers() : []) });
264
+ }, [lineNumbersCompartment, showLineNumbers]);
269
265
  useEffect(() => {
270
266
  const editor = editorRef.current;
271
267
  if (!editor) return;
272
- editor.dispatch({ effects: themeCompartmentRef.current.reconfigure(getThemeExtensions(colorScheme)) });
273
- }, [colorScheme]);
268
+ editor.dispatch({ effects: themeCompartment.reconfigure(getThemeExtensions(colorScheme)) });
269
+ }, [colorScheme, themeCompartment]);
274
270
  useEffect(() => {
275
271
  const editor = editorRef.current;
276
272
  if (!editor) return;
@@ -291,12 +287,12 @@ var CodeBlockEditRenderer = ({ code, language, showLineNumbers: showLineNumbersP
291
287
  (async () => {
292
288
  const extension = await loadLanguageExtension(normalizedLanguage);
293
289
  if (cancelled) return;
294
- editor.dispatch({ effects: languageCompartmentRef.current.reconfigure(extension) });
290
+ editor.dispatch({ effects: languageCompartment.reconfigure(extension) });
295
291
  })();
296
292
  return () => {
297
293
  cancelled = true;
298
294
  };
299
- }, [normalizedLanguage]);
295
+ }, [languageCompartment, normalizedLanguage]);
300
296
  useEffect(() => {
301
297
  if (!editable || !selected) return;
302
298
  const editor = editorRef.current;
@@ -317,7 +313,17 @@ var CodeBlockEditRenderer = ({ code, language, showLineNumbers: showLineNumbersP
317
313
  mounted,
318
314
  selected
319
315
  ]);
320
- const fallbackLines = useMemo(() => code.split("\n"), [code]);
316
+ const fallbackLines = useMemo(() => {
317
+ const occurrences = /* @__PURE__ */ new Map();
318
+ return code.split("\n").map((line) => {
319
+ const occurrence = occurrences.get(line) ?? 0;
320
+ occurrences.set(line, occurrence + 1);
321
+ return {
322
+ key: `${occurrence}:${line}`,
323
+ line
324
+ };
325
+ });
326
+ }, [code]);
321
327
  const fallbackClassName = [
322
328
  showLineNumbers && "_1pn9r4qf",
323
329
  showLineNumbers && semanticClassNames.lined,
@@ -340,10 +346,10 @@ var CodeBlockEditRenderer = ({ code, language, showLineNumbers: showLineNumbersP
340
346
  }) : void 0,
341
347
  children: [!mounted && /* @__PURE__ */ jsx("pre", {
342
348
  className: fallbackClassName,
343
- children: /* @__PURE__ */ jsx("code", { children: fallbackLines.map((line, i) => /* @__PURE__ */ jsx("span", {
349
+ children: /* @__PURE__ */ jsx("code", { children: fallbackLines.map(({ key, line }) => /* @__PURE__ */ jsx("span", {
344
350
  className: "line",
345
351
  children: line
346
- }, `${line}-${i}`)) })
352
+ }, key)) })
347
353
  }), /* @__PURE__ */ jsx("div", {
348
354
  className: bodyClassName,
349
355
  ref: containerRef,
package/dist/static.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CodeBlockRendererProps } from '@haklex/rich-editor/renderers';
2
- import { ComponentType } from 'react';
1
+ import type { CodeBlockRendererProps } from '@haklex/rich-editor/renderers';
2
+ import type { ComponentType } from 'react';
3
3
  export declare const CodeBlockRenderer: ComponentType<CodeBlockRendererProps>;
4
4
  //# sourceMappingURL=static.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../src/static.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAG5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,eAAO,MAAM,iBAAiB,EAAE,aAAa,CAAC,sBAAsB,CAUnE,CAAC"}
1
+ {"version":3,"file":"static.d.ts","sources":["../src/static.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAG5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,eAAO,MAAM,iBAAiB,EAAE,aAAa,CAAC,sBAAsB,CAUnE,CAAC"}
@@ -1,18 +1,18 @@
1
1
  export declare const semanticClassNames: {
2
- readonly card: "rr-code-card";
3
- readonly header: "rr-code-header";
4
- readonly lang: "rr-code-lang";
5
- readonly langIcon: "rr-code-lang-icon";
6
- readonly copyButton: "rr-code-copy";
7
- readonly bodyBackground: "rr-code-bg";
8
- readonly scroll: "rr-code-scroll";
9
- readonly scrollCollapsed: "rr-code-scroll-collapsed";
10
- readonly body: "rr-code-body";
11
- readonly bodyReadonly: "rr-code-readonly";
12
- readonly expandWrap: "rr-code-expand-wrap";
13
- readonly expandButton: "rr-code-expand";
14
- readonly lined: "rr-code-lined";
15
- readonly linedWithNumbers: "rr-code-lined-ln";
2
+ readonly card: 'rr-code-card';
3
+ readonly header: 'rr-code-header';
4
+ readonly lang: 'rr-code-lang';
5
+ readonly langIcon: 'rr-code-lang-icon';
6
+ readonly copyButton: 'rr-code-copy';
7
+ readonly bodyBackground: 'rr-code-bg';
8
+ readonly scroll: 'rr-code-scroll';
9
+ readonly scrollCollapsed: 'rr-code-scroll-collapsed';
10
+ readonly body: 'rr-code-body';
11
+ readonly bodyReadonly: 'rr-code-readonly';
12
+ readonly expandWrap: 'rr-code-expand-wrap';
13
+ readonly expandButton: 'rr-code-expand';
14
+ readonly lined: 'rr-code-lined';
15
+ readonly linedWithNumbers: 'rr-code-lined-ln';
16
16
  };
17
17
  export declare const card: string;
18
18
  export declare const header: string;
@@ -32,11 +32,11 @@ export declare const expandButton: string;
32
32
  export declare const lined: string;
33
33
  export declare const linedWithNumbers: string;
34
34
  export declare const contentSemanticClassNames: {
35
- readonly root: "rich-code-block";
36
- readonly header: "rich-code-block-header";
37
- readonly lang: "rich-code-block-lang";
38
- readonly copyButton: "rich-code-block-copy";
39
- readonly numbered: "rich-code-block-numbered";
35
+ readonly root: 'rich-code-block';
36
+ readonly header: 'rich-code-block-header';
37
+ readonly lang: 'rich-code-block-lang';
38
+ readonly copyButton: 'rich-code-block-copy';
39
+ readonly numbered: 'rich-code-block-numbered';
40
40
  };
41
41
  export declare const contentRoot: string;
42
42
  export declare const contentHeader: string;
@@ -1 +1 @@
1
- {"version":3,"file":"styles.css.d.ts","sourceRoot":"","sources":["../src/styles.css.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;CAerB,CAAC;AAGX,eAAO,MAAM,IAAI,QAaf,CAAC;AAEH,eAAO,MAAM,MAAM,QAcjB,CAAC;AAGH,eAAO,MAAM,SAAS,QAepB,CAAC;AAEH,eAAO,MAAM,IAAI,QAMf,CAAC;AAEH,eAAO,MAAM,QAAQ,QAKnB,CAAC;AAEH,eAAO,MAAM,QAAQ,QAGnB,CAAC;AAOH,eAAO,MAAM,UAAU,QAiBrB,CAAC;AAGH,eAAO,MAAM,cAAc,QAGzB,CAAC;AAEH,eAAO,MAAM,oBAAoB,QAK/B,CAAC;AAGH,eAAO,MAAM,MAAM,QAMjB,CAAC;AAEH,eAAO,MAAM,eAAe,QAG1B,CAAC;AAGH,eAAO,MAAM,IAAI,QASf,CAAC;AAEH,eAAO,MAAM,YAAY,QAAY,CAAC;AA4CtC,eAAO,MAAM,UAAU,QAQrB,CAAC;AAEH,eAAO,MAAM,YAAY,QAkBvB,CAAC;AAgGH,eAAO,MAAM,KAAK,QAEhB,CAAC;AAiBH,eAAO,MAAM,gBAAgB,QAAY,CAAC;AA8B1C,eAAO,MAAM,yBAAyB;;;;;;CAM5B,CAAC;AAmFX,eAAO,MAAM,WAAW,QAA2B,CAAC;AACpD,eAAO,MAAM,aAAa,QAA6B,CAAC;AACxD,eAAO,MAAM,WAAW,QAA2B,CAAC;AACpD,eAAO,MAAM,iBAAiB,QAAiC,CAAC"}
1
+ {"version":3,"file":"styles.css.d.ts","sources":["../src/styles.css.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB;aAC7B,IAAI,EAAE,cAAc;aACpB,MAAM,EAAE,gBAAgB;aACxB,IAAI,EAAE,cAAc;aACpB,QAAQ,EAAE,mBAAmB;aAC7B,UAAU,EAAE,cAAc;aAC1B,cAAc,EAAE,YAAY;aAC5B,MAAM,EAAE,gBAAgB;aACxB,eAAe,EAAE,0BAA0B;aAC3C,IAAI,EAAE,cAAc;aACpB,YAAY,EAAE,kBAAkB;aAChC,UAAU,EAAE,qBAAqB;aACjC,YAAY,EAAE,gBAAgB;aAC9B,KAAK,EAAE,eAAe;aACtB,gBAAgB,EAAE,kBAAkB;CAC5B,CAAC;AAGX,eAAO,MAAM,IAAI,QAaf,CAAC;AAEH,eAAO,MAAM,MAAM,QAcjB,CAAC;AAGH,eAAO,MAAM,SAAS,QAepB,CAAC;AAEH,eAAO,MAAM,IAAI,QAMf,CAAC;AAEH,eAAO,MAAM,QAAQ,QAKnB,CAAC;AAEH,eAAO,MAAM,QAAQ,QAGnB,CAAC;AAOH,eAAO,MAAM,UAAU,QAiBrB,CAAC;AAGH,eAAO,MAAM,cAAc,QAGzB,CAAC;AAEH,eAAO,MAAM,oBAAoB,QAK/B,CAAC;AAGH,eAAO,MAAM,MAAM,QAMjB,CAAC;AAEH,eAAO,MAAM,eAAe,QAG1B,CAAC;AAGH,eAAO,MAAM,IAAI,QASf,CAAC;AAEH,eAAO,MAAM,YAAY,QAAY,CAAC;AA4CtC,eAAO,MAAM,UAAU,QAQrB,CAAC;AAEH,eAAO,MAAM,YAAY,QAkBvB,CAAC;AAgGH,eAAO,MAAM,KAAK,QAEhB,CAAC;AAiBH,eAAO,MAAM,gBAAgB,QAAY,CAAC;AA8B1C,eAAO,MAAM,yBAAyB;aACpC,IAAI,EAAE,iBAAiB;aACvB,MAAM,EAAE,wBAAwB;aAChC,IAAI,EAAE,sBAAsB;aAC5B,UAAU,EAAE,sBAAsB;aAClC,QAAQ,EAAE,0BAA0B;CAC5B,CAAC;AAmFX,eAAO,MAAM,WAAW,QAA2B,CAAC;AACpD,eAAO,MAAM,aAAa,QAA6B,CAAC;AACxD,eAAO,MAAM,WAAW,QAA2B,CAAC;AACpD,eAAO,MAAM,iBAAiB,QAAiC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haklex/rich-renderer-codeblock",
3
- "version": "0.68.0",
3
+ "version": "0.69.1",
4
4
  "description": "Code block renderer with Shiki syntax highlighting",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,7 +25,7 @@
25
25
  "./style.css": "./dist/rich-renderer-codeblock.css",
26
26
  "./icons": {
27
27
  "import": "./dist/icons.mjs",
28
- "types": "./dist/icons.d.ts"
28
+ "types": "./dist/icons/index.d.ts"
29
29
  }
30
30
  },
31
31
  "main": "./dist/index.mjs",
@@ -36,7 +36,7 @@
36
36
  "@codemirror/commands": "^6.11.1",
37
37
  "@codemirror/state": "^6.7.6",
38
38
  "@codemirror/view": "^6.43.15",
39
- "@haklex/cm-editor": "0.68.0",
39
+ "@haklex/cm-editor": "0.69.1",
40
40
  "@iconify-json/material-icon-theme": "^1.2.75",
41
41
  "@iconify/utils": "^3.1.7"
42
42
  },
@@ -49,14 +49,12 @@
49
49
  "lexical": "^0.53.0",
50
50
  "react": "^19.3.1",
51
51
  "react-dom": "^19.3.1",
52
- "typescript": "^7.0.2",
53
- "unplugin-dts": "^1.1.2",
54
52
  "vite": "^8.3.5"
55
53
  },
56
54
  "peerDependencies": {
57
- "@haklex/rich-editor": "^0.68.0",
58
- "@haklex/rich-editor-ui": "^0.68.0",
59
- "@haklex/rich-style-token": "^0.68.0",
55
+ "@haklex/rich-editor": "^0.69.1",
56
+ "@haklex/rich-editor-ui": "^0.69.1",
57
+ "@haklex/rich-style-token": "^0.69.1",
60
58
  "lucide-react": "^1.0.0",
61
59
  "react": ">=19",
62
60
  "react-dom": ">=19"