@rulab/adminjs-components 0.0.11 → 0.0.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulab/adminjs-components",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -24,8 +24,11 @@
24
24
  "@editorjs/header": "^2.8.7",
25
25
  "@editorjs/list": "^1.9.0",
26
26
  "@editorjs/paragraph": "^2.11.6",
27
+ "@editorjs/quote": "^2.7.2",
28
+ "@editorjs/table": "^2.4.1",
27
29
  "adminjs": "^7.8.1",
28
30
  "chroma-js": "^3.0.0",
31
+ "editorjs-audio-player": "^0.0.3",
29
32
  "editorjs-html": "^3.4.3",
30
33
  "react": "^18.2.0",
31
34
  "react-select": "^5.8.0",
@@ -1,9 +1,8 @@
1
1
  import React from "react";
2
- import { ThemeProvider } from "styled-components";
3
- import { theme } from "@adminjs/design-system";
4
2
 
3
+ import { theme } from "@adminjs/design-system";
4
+ import { ThemeProvider } from "styled-components";
5
5
  import { parseHtml } from "../../utils/parseHtml";
6
-
7
6
  import { StyledEditorViewWrapper } from "./styles";
8
7
 
9
8
  const EditorList = ({ property, record }) => {
@@ -1,6 +1,10 @@
1
1
  import Header from "@editorjs/header";
2
- import Paragraph from "@editorjs/paragraph";
3
2
  import List from "@editorjs/list";
3
+ import Paragraph from "@editorjs/paragraph";
4
+ import Quote from "@editorjs/quote";
5
+ import Table from "@editorjs/table";
6
+ // @ts-ignore
7
+ import AudioPlayer from "editorjs-audio-player";
4
8
 
5
9
  export const EDITOR_TOOLS = {
6
10
  paragraph: {
@@ -8,5 +12,15 @@ export const EDITOR_TOOLS = {
8
12
  inlineToolbar: true,
9
13
  },
10
14
  list: List,
11
- header: Header,
15
+ header: {
16
+ class: Header,
17
+ config: {
18
+ placeholder: "Enter a header",
19
+ levels: [2, 3, 4],
20
+ defaultLevel: 2,
21
+ },
22
+ },
23
+ table: Table,
24
+ quote: Quote,
25
+ audioPlayer: AudioPlayer,
12
26
  };
@@ -55,6 +55,34 @@ export const StyledEditorViewWrapper = styled(Box)`
55
55
  ul {
56
56
  list-style: inherit;
57
57
  }
58
+
59
+ table,
60
+ audio {
61
+ margin: 16px 0;
62
+ }
63
+
64
+ table,
65
+ th,
66
+ td {
67
+ border: 1px solid;
68
+ }
69
+
70
+ th {
71
+ font-weight: bold;
72
+ }
73
+
74
+ th,
75
+ td {
76
+ padding: 4px;
77
+ }
78
+
79
+ blockquote {
80
+ display: block;
81
+ padding: 5px 8px;
82
+ width: fit-content;
83
+ border-radius: 4px;
84
+ background-color: #e6e6e6;
85
+ }
58
86
  `;
59
87
 
60
88
  export const StyledEditorShowWrapper = styled(StyledEditorViewWrapper)`
@@ -62,11 +90,17 @@ export const StyledEditorShowWrapper = styled(StyledEditorViewWrapper)`
62
90
  `;
63
91
 
64
92
  export const StyledEditor = styled.div`
93
+ audio,
65
94
  .cdx-block,
66
95
  .ce-header {
67
96
  padding-left: 58px;
68
97
  }
69
98
 
99
+ input {
100
+ margin-left: 58px;
101
+ width: auto;
102
+ }
103
+
70
104
  .cdx-list {
71
105
  padding-left: 85px;
72
106
  }
package/src/index.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from "./components/index.js";
2
+ export { parseHtml } from "./utils/parseHtml.js";
@@ -1 +1,3 @@
1
+ export { parseHtml } from "./parseHtml.js";
1
2
  export { slugifyTitle } from "./slugifyTitle.js";
3
+
@@ -1,12 +1,56 @@
1
1
  import edjsHTML from "editorjs-html";
2
2
 
3
- export const parseHtml = (jsonData?: string) => {
4
- const edjsParser = edjsHTML();
3
+ type TableBlockType = {
4
+ type: "table";
5
+ data: {
6
+ content: string[][];
7
+ withHeadings: boolean;
8
+ };
9
+ };
10
+
11
+ type AudioPlayerBlockType = {
12
+ type: "audioPlayer";
13
+ data: {
14
+ src: string;
15
+ };
16
+ };
17
+
18
+ const tableParser = (block: TableBlockType) => {
19
+ const rows = block.data.content.map((row, index) => {
20
+ const tableHtml = [];
21
+ if (block.data.withHeadings && index === 0) {
22
+ tableHtml.push(`<tr>${row.map((cell) => `<th>${cell}</th>`)}</tr>`);
23
+ } else {
24
+ tableHtml.push(`<tr>${row.map((cell) => `<td>${cell}</td>`)}</tr>`);
25
+ }
26
+
27
+ return tableHtml;
28
+ });
29
+
30
+ if (block.data.withHeadings) {
31
+ const heading = rows[0] as string[];
32
+ const [, ...content] = rows;
33
+
34
+ return `<table><thead>${heading.join("")}</thead><tbody>${content.join("")}</tbody></table>`;
35
+ } else {
36
+ return `<table><tbody>${rows.join("")}</tbody></table>`;
37
+ }
38
+ };
39
+
40
+ const audioPlayerParser = (block: AudioPlayerBlockType) => {
41
+ return `<audio controls src={${block.data.src}} />`;
42
+ };
43
+
44
+ export const parseHtml = (jsonData: string) => {
45
+ const edjsParser = edjsHTML({
46
+ table: tableParser,
47
+ audioPlayer: audioPlayerParser,
48
+ });
5
49
 
6
50
  try {
7
- const data = edjsParser.parse(JSON.parse(String(jsonData)));
51
+ const data = edjsParser.parse(JSON.parse(jsonData));
8
52
  return String(data).replace(/>,</g, "><");
9
53
  } catch (e) {
10
- return;
54
+ console.log("error", e);
11
55
  }
12
56
  };