@haklex/rich-ext-code-snippet 0.0.9 → 0.0.11

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
@@ -5,4 +5,5 @@ export { codeSnippetEditNodes, codeSnippetNodes } from './nodes';
5
5
  export { $createCodeSnippetEditNode, $isCodeSnippetEditNode, CodeSnippetEditNode, } from './nodes/CodeSnippetEditNode';
6
6
  export type { SerializedCodeSnippetNode } from './nodes/CodeSnippetNode';
7
7
  export { $createCodeSnippetNode, $isCodeSnippetNode, CodeSnippetNode, } from './nodes/CodeSnippetNode';
8
+ export { CODE_SNIPPET_BLOCK_TRANSFORMER } from './transformer';
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAA;AAErB,YAAY,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAA;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAChE,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,6BAA6B,CAAA;AACpC,YAAY,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAA;AACxE,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,eAAe,GAChB,MAAM,yBAAyB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAA;AAErB,YAAY,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAA;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAChE,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,6BAA6B,CAAA;AACpC,YAAY,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAA;AACxE,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,eAAe,GAChB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,8BAA8B,EAAE,MAAM,eAAe,CAAA"}
package/dist/index.mjs CHANGED
@@ -928,11 +928,47 @@ function $isCodeSnippetEditNode(node) {
928
928
  }
929
929
  const codeSnippetNodes = [CodeSnippetNode];
930
930
  const codeSnippetEditNodes = [CodeSnippetEditNode];
931
+ const NEVER_MATCH = /a^/;
932
+ function quoteAttr(value) {
933
+ return value.replaceAll('"', '\\"');
934
+ }
935
+ function pickFence(content) {
936
+ const matches = content.match(/`+/g);
937
+ const maxLen = matches?.reduce((max, run) => Math.max(max, run.length), 0) ?? 0;
938
+ return "`".repeat(Math.max(3, maxLen + 1));
939
+ }
940
+ const CODE_SNIPPET_BLOCK_TRANSFORMER = {
941
+ dependencies: [CodeSnippetNode],
942
+ export: (node) => {
943
+ if (!$isCodeSnippetNode(node)) return null;
944
+ const snippet = node.exportJSON();
945
+ const body = snippet.files.map((file) => {
946
+ const fence = pickFence(file.code || "");
947
+ const lang = file.language || "";
948
+ const filename = quoteAttr(file.filename || "untitled");
949
+ return [
950
+ `::: file{name="${filename}" lang="${lang}"}`,
951
+ `${fence}${lang}`,
952
+ file.code || "",
953
+ fence,
954
+ ":::"
955
+ ].join("\n");
956
+ }).join("\n");
957
+ return `::: code-snippet
958
+ ${body}
959
+ :::`;
960
+ },
961
+ regExp: NEVER_MATCH,
962
+ replace: () => {
963
+ },
964
+ type: "element"
965
+ };
931
966
  export {
932
967
  $createCodeSnippetEditNode,
933
968
  $createCodeSnippetNode,
934
969
  $isCodeSnippetEditNode,
935
970
  $isCodeSnippetNode,
971
+ CODE_SNIPPET_BLOCK_TRANSFORMER,
936
972
  CodeSnippetEditNode,
937
973
  CodeSnippetEditRenderer,
938
974
  CodeSnippetNode,
@@ -0,0 +1,10 @@
1
+ import { LexicalNode } from 'lexical';
2
+ import { CodeSnippetNode } from './nodes/CodeSnippetNode';
3
+ export declare const CODE_SNIPPET_BLOCK_TRANSFORMER: {
4
+ dependencies: (typeof CodeSnippetNode)[];
5
+ export: (node: LexicalNode) => string | null;
6
+ regExp: RegExp;
7
+ replace: () => void;
8
+ type: "element";
9
+ };
10
+ //# sourceMappingURL=transformer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../src/transformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C,OAAO,EAEL,eAAe,EAEhB,MAAM,yBAAyB,CAAA;AAehC,eAAO,MAAM,8BAA8B;;mBAE1B,WAAW;;;;CAwB3B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haklex/rich-ext-code-snippet",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Multi-file code snippet extension",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -21,10 +21,10 @@
21
21
  "@dnd-kit/utilities": "^3.2.2",
22
22
  "lucide-react": "^0.574.0",
23
23
  "shikicode": "*",
24
- "@haklex/rich-editor": "0.0.9",
25
- "@haklex/rich-editor-ui": "0.0.9",
26
- "@haklex/rich-renderer-codeblock": "0.0.9",
27
- "@haklex/rich-style-token": "0.0.9"
24
+ "@haklex/rich-editor": "0.0.11",
25
+ "@haklex/rich-renderer-codeblock": "0.0.11",
26
+ "@haklex/rich-style-token": "0.0.11",
27
+ "@haklex/rich-editor-ui": "0.0.11"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@lexical/react": "^0.40.0",