@haklex/rich-renderer-codeblock 0.0.63 → 0.0.64

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.
@@ -3,10 +3,9 @@ interface CodeBlockCardProps {
3
3
  code: string;
4
4
  language: string;
5
5
  collapsible?: boolean;
6
- editable?: boolean;
7
- onLanguageChange?: (language: string) => void;
6
+ langSlot?: ReactNode;
8
7
  children: ReactNode;
9
8
  }
10
- export declare function CodeBlockCard({ code, language, collapsible, editable, onLanguageChange, children, }: CodeBlockCardProps): import("react/jsx-runtime").JSX.Element;
9
+ export declare function CodeBlockCard({ code, language, collapsible, langSlot, children, }: CodeBlockCardProps): import("react/jsx-runtime").JSX.Element;
11
10
  export {};
12
11
  //# 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,CAAA;AAerD,UAAU,kBAAkB;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;IAC7C,QAAQ,EAAE,SAAS,CAAA;CACpB;AAED,wBAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,QAAQ,EACR,WAAkB,EAClB,QAAgB,EAChB,gBAAgB,EAChB,QAAQ,GACT,EAAE,kBAAkB,2CAmIpB"}
1
+ {"version":3,"file":"CodeBlockCard.d.ts","sourceRoot":"","sources":["../src/CodeBlockCard.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,OAAO,CAAA;AAerD,UAAU,kBAAkB;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,QAAQ,EAAE,SAAS,CAAA;CACpB;AAED,wBAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,QAAQ,EACR,WAAkB,EAClB,QAAQ,EACR,QAAQ,GACT,EAAE,kBAAkB,2CAgHpB"}
@@ -1 +1 @@
1
- {"version":3,"file":"CodeBlockEditRenderer.d.ts","sourceRoot":"","sources":["../src/CodeBlockEditRenderer.tsx"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAEjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAa1C,eAAO,MAAM,qBAAqB,EAAE,aAAa,CAAC,sBAAsB,CA2QvE,CAAA"}
1
+ {"version":3,"file":"CodeBlockEditRenderer.d.ts","sourceRoot":"","sources":["../src/CodeBlockEditRenderer.tsx"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAEjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAc1C,eAAO,MAAM,qBAAqB,EAAE,aAAa,CAAC,sBAAsB,CAiRvE,CAAA"}
@@ -1,11 +1,10 @@
1
1
  import { jsxs, jsx } from "react/jsx-runtime";
2
- import { useVariant } from "@haklex/rich-editor";
3
2
  import { useState, useRef, useEffect, useCallback, useMemo } from "react";
4
3
  import { Check, Copy, ChevronDown } from "lucide-react";
5
4
  import { normalizeLanguage, getLanguageDisplayName, languageToColorMap } from "./constants.mjs";
6
5
  import "@iconify/utils";
7
6
  import "@iconify-json/material-icon-theme";
8
- import { e as card, s as semanticClassNames, f as lang, h as hasLanguageIcon, d as LanguageIcon, i as langInput, j as copyButton, k as bodyBackground, m as expandWrap, n as expandButton, o as scroll, p as scrollCollapsed, l as lined, a as linedWithNumbers } from "./language-DlgJtK5A.js";
7
+ import { i as card, s as semanticClassNames, l as lang, h as hasLanguageIcon, a as LanguageIcon, j as copyButton, k as bodyBackground, m as expandWrap, n as expandButton, o as scroll, p as scrollCollapsed, c as lined, d as linedWithNumbers } from "./language-CWZoNKWO.js";
9
8
  import { getHighlighterWithLang, SHIKI_DUAL_THEMES } from "./shiki.mjs";
10
9
  const CopyIcon = /* @__PURE__ */ jsx(Copy, { size: 16 });
11
10
  const CheckIcon = /* @__PURE__ */ jsx(Check, { size: 16 });
@@ -14,8 +13,7 @@ function CodeBlockCard({
14
13
  code,
15
14
  language,
16
15
  collapsible = true,
17
- editable = false,
18
- onLanguageChange,
16
+ langSlot,
19
17
  children
20
18
  }) {
21
19
  const normalizedLanguage = normalizeLanguage(language);
@@ -67,31 +65,14 @@ function CodeBlockCard({
67
65
  className: `${card} ${semanticClassNames.card}`,
68
66
  style: cardStyle,
69
67
  children: [
70
- editable ? /* @__PURE__ */ jsxs("div", { className: `${lang} ${semanticClassNames.lang}`, children: [
71
- hasLanguageIcon(normalizedLanguage) && /* @__PURE__ */ jsx(LanguageIcon, { language: normalizedLanguage, size: 14 }),
72
- /* @__PURE__ */ jsx(
73
- "input",
74
- {
75
- className: langInput,
76
- value: language,
77
- placeholder: "language",
78
- onChange: (e) => onLanguageChange?.(e.target.value),
79
- onKeyDown: (e) => {
80
- e.stopPropagation();
81
- if (e.key === "Escape" || e.key === "Enter") {
82
- e.currentTarget.blur();
83
- }
84
- }
85
- }
86
- )
87
- ] }) : normalizedLanguage !== "text" && /* @__PURE__ */ jsx(
68
+ langSlot ?? (normalizedLanguage !== "text" && /* @__PURE__ */ jsx(
88
69
  "div",
89
70
  {
90
71
  className: `${lang} ${semanticClassNames.lang}`,
91
72
  "aria-hidden": true,
92
73
  children: hasLanguageIcon(normalizedLanguage) ? /* @__PURE__ */ jsx(LanguageIcon, { language: normalizedLanguage, size: 14 }) : /* @__PURE__ */ jsx("span", { children: languageLabel })
93
74
  }
94
- ),
75
+ )),
95
76
  /* @__PURE__ */ jsx(
96
77
  "button",
97
78
  {
@@ -138,8 +119,7 @@ const CodeBlockRenderer = ({
138
119
  language,
139
120
  showLineNumbers: showLineNumbersProp
140
121
  }) => {
141
- const variant = useVariant();
142
- const showLineNumbers = showLineNumbersProp ?? variant !== "comment";
122
+ const showLineNumbers = showLineNumbersProp ?? false;
143
123
  const normalizedLanguage = normalizeLanguage(language);
144
124
  const [html, setHtml] = useState(null);
145
125
  useEffect(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"CodeBlockRenderer.d.ts","sourceRoot":"","sources":["../src/CodeBlockRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAEjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAQ1C,eAAO,MAAM,iBAAiB,EAAE,aAAa,CAAC,sBAAsB,CAiEnE,CAAA;AAED,eAAe,iBAAiB,CAAA"}
1
+ {"version":3,"file":"CodeBlockRenderer.d.ts","sourceRoot":"","sources":["../src/CodeBlockRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAQ1C,eAAO,MAAM,iBAAiB,EAAE,aAAa,CAAC,sBAAsB,CAgEnE,CAAA;AAED,eAAe,iBAAiB,CAAA"}
@@ -0,0 +1,7 @@
1
+ interface LanguageComboboxProps {
2
+ language: string;
3
+ onLanguageChange?: (language: string) => void;
4
+ }
5
+ export declare function LanguageCombobox({ language, onLanguageChange, }: LanguageComboboxProps): import("react/jsx-runtime").JSX.Element;
6
+ export {};
7
+ //# sourceMappingURL=LanguageCombobox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LanguageCombobox.d.ts","sourceRoot":"","sources":["../src/LanguageCombobox.tsx"],"names":[],"mappings":"AAoBA,UAAU,qBAAqB;IAC7B,QAAQ,EAAE,MAAM,CAAA;IAChB,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;CAC9C;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,gBAAgB,GACjB,EAAE,qBAAqB,2CAkDvB"}
@@ -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,CAAA;AAM/B,iEAAiE;AACjE,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA8C/C,CAAA;AAOD,2EAA2E;AAC3E,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAErD;AAED,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAiCA,CAAA"}
1
+ {"version":3,"file":"language.d.ts","sourceRoot":"","sources":["../../src/icons/language.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAM/B,iEAAiE;AACjE,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAoE/C,CAAA;AAOD,2EAA2E;AAC3E,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAErD;AAED,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAiCA,CAAA"}
package/dist/icons.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { useMemo } from "react";
3
- import { g as getMaterialIconSvg } from "./language-DlgJtK5A.js";
4
- import { L, d, h } from "./language-DlgJtK5A.js";
3
+ import { g as getMaterialIconSvg } from "./language-CWZoNKWO.js";
4
+ import { L, a, h } from "./language-CWZoNKWO.js";
5
5
  const EXT_TO_ICON = {
6
6
  ts: "typescript",
7
7
  tsx: "react-ts",
@@ -90,7 +90,7 @@ const FileIcon = ({
90
90
  export {
91
91
  FileIcon,
92
92
  L as LANG_TO_ICON,
93
- d as LanguageIcon,
93
+ a as LanguageIcon,
94
94
  getMaterialIconSvg,
95
95
  h as hasLanguageIcon
96
96
  };
package/dist/index.mjs CHANGED
@@ -4,11 +4,69 @@ import { Compartment, Prec, EditorState, EditorSelection } from "@codemirror/sta
4
4
  import { EditorView, keymap, lineNumbers } from "@codemirror/view";
5
5
  import { isOnFirstLine, isOnLastLine, getThemeExtensions, loadLanguageExtension } from "@haklex/cm-editor";
6
6
  import { useVariant, useColorScheme } from "@haklex/rich-editor";
7
- import { useState, useRef, useMemo, useEffect } from "react";
8
- import { a as CodeBlockCard } from "./CodeBlockRenderer-BAfW72ee.js";
9
- import { C } from "./CodeBlockRenderer-BAfW72ee.js";
7
+ import { useCallback, useMemo, useState, useRef, useEffect } from "react";
8
+ import { a as CodeBlockCard } from "./CodeBlockRenderer-DoVYgPoV.js";
9
+ import { C } from "./CodeBlockRenderer-DoVYgPoV.js";
10
10
  import { normalizeLanguage } from "./constants.mjs";
11
- import { l as lined, s as semanticClassNames, a as linedWithNumbers, b as body, c as bodyReadonly } from "./language-DlgJtK5A.js";
11
+ import { Combobox, ComboboxInput, ComboboxContent, ComboboxEmpty, ComboboxList, ComboboxItem } from "@haklex/rich-editor-ui";
12
+ import { bundledLanguagesInfo } from "shiki/bundle/web";
13
+ import "@iconify/utils";
14
+ import "@iconify-json/material-icon-theme";
15
+ import { l as lang, s as semanticClassNames, h as hasLanguageIcon, a as LanguageIcon, b as langInput, c as lined, d as linedWithNumbers, e as body, f as bodyReadonly } from "./language-CWZoNKWO.js";
16
+ const languageItems = bundledLanguagesInfo.map((info) => ({
17
+ id: info.id,
18
+ name: info.name
19
+ }));
20
+ function LanguageCombobox({
21
+ language,
22
+ onLanguageChange
23
+ }) {
24
+ const normalizedLanguage = normalizeLanguage(language);
25
+ const handleValueChange = useCallback(
26
+ (value) => {
27
+ if (value) {
28
+ onLanguageChange?.(value.id);
29
+ }
30
+ },
31
+ [onLanguageChange]
32
+ );
33
+ const selectedValue = useMemo(
34
+ () => languageItems.find((item) => item.id === normalizedLanguage) ?? null,
35
+ [normalizedLanguage]
36
+ );
37
+ return /* @__PURE__ */ jsxs("div", { className: `${lang} ${semanticClassNames.lang}`, children: [
38
+ hasLanguageIcon(normalizedLanguage) && /* @__PURE__ */ jsx(LanguageIcon, { language: normalizedLanguage, size: 14 }),
39
+ /* @__PURE__ */ jsxs(
40
+ Combobox,
41
+ {
42
+ value: selectedValue,
43
+ onValueChange: handleValueChange,
44
+ itemToStringValue: (item) => item.id,
45
+ itemToStringLabel: (item) => item.id,
46
+ items: languageItems,
47
+ children: [
48
+ /* @__PURE__ */ jsx(
49
+ ComboboxInput,
50
+ {
51
+ className: langInput,
52
+ placeholder: "language",
53
+ onKeyDown: (e) => {
54
+ e.stopPropagation();
55
+ }
56
+ }
57
+ ),
58
+ /* @__PURE__ */ jsxs(ComboboxContent, { side: "top", sideOffset: 8, align: "end", children: [
59
+ /* @__PURE__ */ jsx(ComboboxEmpty, { children: "No languages found." }),
60
+ /* @__PURE__ */ jsx(ComboboxList, { children: (item) => /* @__PURE__ */ jsxs(ComboboxItem, { value: item, children: [
61
+ /* @__PURE__ */ jsx(LanguageIcon, { language: item.id, size: 16 }),
62
+ item.name
63
+ ] }, item.id) })
64
+ ] })
65
+ ]
66
+ }
67
+ )
68
+ ] });
69
+ }
12
70
  function stopHandledEvent(event) {
13
71
  event.preventDefault();
14
72
  event.stopPropagation();
@@ -212,8 +270,13 @@ const CodeBlockEditRenderer = ({
212
270
  code,
213
271
  language,
214
272
  collapsible: !editable,
215
- editable,
216
- onLanguageChange,
273
+ langSlot: editable ? /* @__PURE__ */ jsx(
274
+ LanguageCombobox,
275
+ {
276
+ language,
277
+ onLanguageChange
278
+ }
279
+ ) : void 0,
217
280
  children: [
218
281
  !mounted && /* @__PURE__ */ jsx("pre", { className: fallbackClassName, children: /* @__PURE__ */ jsx("code", { children: fallbackLines.map((line, i) => /* @__PURE__ */ jsx("span", { className: "line", children: line }, `${line}-${i}`)) }) }),
219
282
  /* @__PURE__ */ jsx(
@@ -28,22 +28,30 @@ const LANG_TO_ICON = {
28
28
  js: "javascript",
29
29
  typescript: "typescript",
30
30
  ts: "typescript",
31
+ "angular-ts": "angular",
32
+ "angular-html": "angular",
31
33
  jsx: "react",
32
34
  tsx: "react",
33
- // TSX → React icon (same as JSX)
34
35
  html: "html",
36
+ "html-derivative": "html",
35
37
  css: "css",
36
38
  scss: "sass",
37
39
  sass: "sass",
38
40
  less: "sass",
41
+ postcss: "postcss",
42
+ stylus: "stylus",
39
43
  json: "json",
44
+ json5: "json",
40
45
  jsonc: "json",
46
+ jsonl: "json",
41
47
  markdown: "markdown",
42
48
  md: "markdown",
43
49
  mdx: "markdown",
50
+ mdc: "markdown",
44
51
  bash: "console",
45
52
  sh: "console",
46
53
  shell: "console",
54
+ shellscript: "console",
47
55
  zsh: "console",
48
56
  python: "python",
49
57
  py: "python",
@@ -61,15 +69,28 @@ const LANG_TO_ICON = {
61
69
  sql: "database",
62
70
  xml: "xml",
63
71
  vue: "vue",
72
+ "vue-html": "vue",
73
+ "vue-vine": "vue",
64
74
  svelte: "svelte",
75
+ astro: "astro",
65
76
  php: "php",
66
77
  rb: "ruby",
78
+ r: "r",
79
+ julia: "julia",
67
80
  lua: "lua",
68
81
  zig: "zig",
69
82
  toml: "toml",
70
83
  graphql: "graphql",
71
84
  gql: "graphql",
72
- dockerfile: "docker"
85
+ dockerfile: "docker",
86
+ coffee: "coffee",
87
+ pug: "pug",
88
+ haml: "haml",
89
+ handlebars: "handlebars",
90
+ marko: "markojs",
91
+ imba: "imba",
92
+ hurl: "hurl",
93
+ http: "http"
73
94
  };
74
95
  function getLanguageIconSvg(lang2) {
75
96
  const iconName = LANG_TO_ICON[lang2] ?? "code";
@@ -113,18 +134,18 @@ const LanguageIcon = ({
113
134
  };
114
135
  export {
115
136
  LANG_TO_ICON as L,
116
- linedWithNumbers as a,
117
- body as b,
118
- bodyReadonly as c,
119
- LanguageIcon as d,
120
- card as e,
121
- lang as f,
137
+ LanguageIcon as a,
138
+ langInput as b,
139
+ lined as c,
140
+ linedWithNumbers as d,
141
+ body as e,
142
+ bodyReadonly as f,
122
143
  getMaterialIconSvg as g,
123
144
  hasLanguageIcon as h,
124
- langInput as i,
145
+ card as i,
125
146
  copyButton as j,
126
147
  bodyBackground as k,
127
- lined as l,
148
+ lang as l,
128
149
  expandWrap as m,
129
150
  expandButton as n,
130
151
  scroll as o,
package/dist/static.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { C } from "./CodeBlockRenderer-BAfW72ee.js";
1
+ import { C } from "./CodeBlockRenderer-DoVYgPoV.js";
2
2
  export {
3
3
  C as CodeBlockRenderer
4
4
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@haklex/rich-renderer-codeblock",
3
3
  "type": "module",
4
- "version": "0.0.63",
4
+ "version": "0.0.64",
5
5
  "description": "Code block renderer with Shiki syntax highlighting",
6
6
  "license": "MIT",
7
7
  "exports": {
@@ -43,9 +43,10 @@
43
43
  "@iconify/utils": "^3.1.0",
44
44
  "lucide-react": "^0.577.0",
45
45
  "shiki": "^4.0.1",
46
- "@haklex/rich-editor": "0.0.63",
47
- "@haklex/rich-style-token": "0.0.63",
48
- "@haklex/cm-editor": "0.0.63"
46
+ "@haklex/cm-editor": "0.0.64",
47
+ "@haklex/rich-editor": "0.0.64",
48
+ "@haklex/rich-editor-ui": "0.0.64",
49
+ "@haklex/rich-style-token": "0.0.64"
49
50
  },
50
51
  "devDependencies": {
51
52
  "@types/react": "^19.2.14",