@rulab/adminjs-components 0.0.10 → 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/dist/index.cjs CHANGED
@@ -38,7 +38,8 @@ __export(src_exports, {
38
38
  EditorList: () => EditorList_default,
39
39
  EditorShow: () => EditorShow_default,
40
40
  StringList: () => StringList_default,
41
- StringListShow: () => StringListShow_default
41
+ StringListShow: () => StringListShow_default,
42
+ parseHtml: () => parseHtml
42
43
  });
43
44
  module.exports = __toCommonJS(src_exports);
44
45
 
@@ -150,8 +151,6 @@ var ColorStatusList = ({ property, record }) => {
150
151
  const currentOption = property.availableValues?.find(
151
152
  (item) => item.value === record.params[property.path]
152
153
  );
153
- console.log(record, "record");
154
- console.log(record.params[property.path], "record.params[property.path]");
155
154
  return /* @__PURE__ */ import_react3.default.createElement(ColorStatusBadge, { color: currentOption.color }, record.params[property.path]);
156
155
  };
157
156
  var ColorStatusList_default = ColorStatusList;
@@ -176,6 +175,42 @@ var slugifyTitle = (title) => {
176
175
  });
177
176
  };
178
177
 
178
+ // src/utils/parseHtml.ts
179
+ var import_editorjs_html = __toESM(require("editorjs-html"), 1);
180
+ var parseHtml = (jsonData) => {
181
+ function tableParser(block) {
182
+ const rows = block.data.content.map((row, index) => {
183
+ const tableHtml = [];
184
+ if (block.data.withHeadings && index === 0) {
185
+ tableHtml.push(`<tr>${row.map((cell) => `<th>${cell}</th>`)}</tr>`);
186
+ } else {
187
+ tableHtml.push(`<tr>${row.map((cell) => `<td>${cell}</td>`)}</tr>`);
188
+ }
189
+ return tableHtml;
190
+ });
191
+ if (block.data.withHeadings) {
192
+ const heading = rows[0];
193
+ const [, ...content] = rows;
194
+ return `<table><thead>${heading.join("")}</thead><tbody>${content.join("")}</tbody></table>`;
195
+ } else {
196
+ return `<table><tbody>${rows.join("")}</tbody></table>`;
197
+ }
198
+ }
199
+ const audioPlayerParser = (block) => {
200
+ return `<audio controls src={${block.data.src}} />`;
201
+ };
202
+ const edjsParser = (0, import_editorjs_html.default)({
203
+ table: tableParser,
204
+ audioPlayer: audioPlayerParser
205
+ });
206
+ try {
207
+ const data = edjsParser.parse(JSON.parse(jsonData));
208
+ return String(data).replace(/>,</g, "><");
209
+ } catch (e) {
210
+ console.log("error", e);
211
+ }
212
+ };
213
+
179
214
  // src/components/CustomSlug/styles.ts
180
215
  var import_styled_components2 = require("@adminjs/design-system/styled-components");
181
216
  var import_design_system = require("@adminjs/design-system");
@@ -284,16 +319,50 @@ var StyledEditorViewWrapper = (0, import_styled_components4.styled)(import_desig
284
319
  ul {
285
320
  list-style: inherit;
286
321
  }
322
+
323
+ table,
324
+ audio {
325
+ margin: 16px 0;
326
+ }
327
+
328
+ table,
329
+ th,
330
+ td {
331
+ border: 1px solid;
332
+ }
333
+
334
+ th {
335
+ font-weight: bold;
336
+ }
337
+
338
+ th,
339
+ td {
340
+ padding: 4px;
341
+ }
342
+
343
+ blockquote {
344
+ display: block;
345
+ padding: 5px 8px;
346
+ width: fit-content;
347
+ border-radius: 10px;
348
+ background-color: #e6e6e6;
349
+ }
287
350
  `;
288
351
  var StyledEditorShowWrapper = (0, import_styled_components4.styled)(StyledEditorViewWrapper)`
289
352
  margin-bottom: 24px;
290
353
  `;
291
354
  var StyledEditor = import_styled_components4.styled.div`
355
+ audio,
292
356
  .cdx-block,
293
357
  .ce-header {
294
358
  padding-left: 58px;
295
359
  }
296
360
 
361
+ input {
362
+ margin-left: 58px;
363
+ width: auto;
364
+ }
365
+
297
366
  .cdx-list {
298
367
  padding-left: 85px;
299
368
  }
@@ -347,13 +416,26 @@ var StyledEditor = import_styled_components4.styled.div`
347
416
  var import_header = __toESM(require("@editorjs/header"), 1);
348
417
  var import_paragraph = __toESM(require("@editorjs/paragraph"), 1);
349
418
  var import_list = __toESM(require("@editorjs/list"), 1);
419
+ var import_table = __toESM(require("@editorjs/table"), 1);
420
+ var import_quote = __toESM(require("@editorjs/quote"), 1);
421
+ var import_editorjs_audio_player = __toESM(require("editorjs-audio-player"), 1);
350
422
  var EDITOR_TOOLS = {
351
423
  paragraph: {
352
424
  class: import_paragraph.default,
353
425
  inlineToolbar: true
354
426
  },
355
427
  list: import_list.default,
356
- header: import_header.default
428
+ header: {
429
+ class: import_header.default,
430
+ config: {
431
+ placeholder: "Enter a header",
432
+ levels: [2, 3, 4],
433
+ defaultLevel: 2
434
+ }
435
+ },
436
+ table: import_table.default,
437
+ quote: import_quote.default,
438
+ audioPlayer: import_editorjs_audio_player.default
357
439
  };
358
440
 
359
441
  // src/components/Editor/Editor.jsx
@@ -386,23 +468,9 @@ var Editor = ({ property, record, onChangeAdmin, editorId }) => {
386
468
  var Editor_default = Editor;
387
469
 
388
470
  // src/components/Editor/EditorList.jsx
471
+ var import_design_system5 = require("@adminjs/design-system");
389
472
  var import_react6 = __toESM(require("react"), 1);
390
473
  var import_styled_components6 = require("styled-components");
391
- var import_design_system5 = require("@adminjs/design-system");
392
-
393
- // src/utils/parseHtml.ts
394
- var import_editorjs_html = __toESM(require("editorjs-html"), 1);
395
- var parseHtml = (jsonData) => {
396
- const edjsParser = (0, import_editorjs_html.default)();
397
- try {
398
- const data = edjsParser.parse(JSON.parse(String(jsonData)));
399
- return String(data).replace(/>,</g, "><");
400
- } catch (e) {
401
- return;
402
- }
403
- };
404
-
405
- // src/components/Editor/EditorList.jsx
406
474
  var EditorList = ({ property, record }) => {
407
475
  const htmlContent = parseHtml(record.params[property.path]);
408
476
  return /* @__PURE__ */ import_react6.default.createElement(import_styled_components6.ThemeProvider, { theme: import_design_system5.theme }, /* @__PURE__ */ import_react6.default.createElement(StyledEditorViewWrapper, null, htmlContent && /* @__PURE__ */ import_react6.default.createElement("div", { dangerouslySetInnerHTML: { __html: htmlContent } })));
@@ -697,5 +765,6 @@ var StringListShow_default = StringListShow;
697
765
  EditorList,
698
766
  EditorShow,
699
767
  StringList,
700
- StringListShow
768
+ StringListShow,
769
+ parseHtml
701
770
  });
package/dist/index.d.cts CHANGED
@@ -39,4 +39,6 @@ interface StringListShowPropsType extends ShowPropertyProps {
39
39
  }
40
40
  declare const StringListShow: FC<StringListShowPropsType>;
41
41
 
42
- export { ColorStatus as ColorStatusEdit, ColorStatusList, ColorStatusShow, CustomSlug, Editor, EditorList, EditorShow, StringList, StringListShow };
42
+ declare const parseHtml: (jsonData: string) => string | undefined;
43
+
44
+ export { ColorStatus as ColorStatusEdit, ColorStatusList, ColorStatusShow, CustomSlug, Editor, EditorList, EditorShow, StringList, StringListShow, parseHtml };
package/dist/index.d.ts CHANGED
@@ -39,4 +39,6 @@ interface StringListShowPropsType extends ShowPropertyProps {
39
39
  }
40
40
  declare const StringListShow: FC<StringListShowPropsType>;
41
41
 
42
- export { ColorStatus as ColorStatusEdit, ColorStatusList, ColorStatusShow, CustomSlug, Editor, EditorList, EditorShow, StringList, StringListShow };
42
+ declare const parseHtml: (jsonData: string) => string | undefined;
43
+
44
+ export { ColorStatus as ColorStatusEdit, ColorStatusList, ColorStatusShow, CustomSlug, Editor, EditorList, EditorShow, StringList, StringListShow, parseHtml };
package/dist/index.js CHANGED
@@ -106,8 +106,6 @@ var ColorStatusList = ({ property, record }) => {
106
106
  const currentOption = property.availableValues?.find(
107
107
  (item) => item.value === record.params[property.path]
108
108
  );
109
- console.log(record, "record");
110
- console.log(record.params[property.path], "record.params[property.path]");
111
109
  return /* @__PURE__ */ React3.createElement(ColorStatusBadge, { color: currentOption.color }, record.params[property.path]);
112
110
  };
113
111
  var ColorStatusList_default = ColorStatusList;
@@ -135,6 +133,42 @@ var slugifyTitle = (title) => {
135
133
  });
136
134
  };
137
135
 
136
+ // src/utils/parseHtml.ts
137
+ import edjsHTML from "editorjs-html";
138
+ var parseHtml = (jsonData) => {
139
+ function tableParser(block) {
140
+ const rows = block.data.content.map((row, index) => {
141
+ const tableHtml = [];
142
+ if (block.data.withHeadings && index === 0) {
143
+ tableHtml.push(`<tr>${row.map((cell) => `<th>${cell}</th>`)}</tr>`);
144
+ } else {
145
+ tableHtml.push(`<tr>${row.map((cell) => `<td>${cell}</td>`)}</tr>`);
146
+ }
147
+ return tableHtml;
148
+ });
149
+ if (block.data.withHeadings) {
150
+ const heading = rows[0];
151
+ const [, ...content] = rows;
152
+ return `<table><thead>${heading.join("")}</thead><tbody>${content.join("")}</tbody></table>`;
153
+ } else {
154
+ return `<table><tbody>${rows.join("")}</tbody></table>`;
155
+ }
156
+ }
157
+ const audioPlayerParser = (block) => {
158
+ return `<audio controls src={${block.data.src}} />`;
159
+ };
160
+ const edjsParser = edjsHTML({
161
+ table: tableParser,
162
+ audioPlayer: audioPlayerParser
163
+ });
164
+ try {
165
+ const data = edjsParser.parse(JSON.parse(jsonData));
166
+ return String(data).replace(/>,</g, "><");
167
+ } catch (e) {
168
+ console.log("error", e);
169
+ }
170
+ };
171
+
138
172
  // src/components/CustomSlug/styles.ts
139
173
  import { styled as styled2 } from "@adminjs/design-system/styled-components";
140
174
  import { Box, Button, Input } from "@adminjs/design-system";
@@ -243,16 +277,50 @@ var StyledEditorViewWrapper = styled3(Box2)`
243
277
  ul {
244
278
  list-style: inherit;
245
279
  }
280
+
281
+ table,
282
+ audio {
283
+ margin: 16px 0;
284
+ }
285
+
286
+ table,
287
+ th,
288
+ td {
289
+ border: 1px solid;
290
+ }
291
+
292
+ th {
293
+ font-weight: bold;
294
+ }
295
+
296
+ th,
297
+ td {
298
+ padding: 4px;
299
+ }
300
+
301
+ blockquote {
302
+ display: block;
303
+ padding: 5px 8px;
304
+ width: fit-content;
305
+ border-radius: 10px;
306
+ background-color: #e6e6e6;
307
+ }
246
308
  `;
247
309
  var StyledEditorShowWrapper = styled3(StyledEditorViewWrapper)`
248
310
  margin-bottom: 24px;
249
311
  `;
250
312
  var StyledEditor = styled3.div`
313
+ audio,
251
314
  .cdx-block,
252
315
  .ce-header {
253
316
  padding-left: 58px;
254
317
  }
255
318
 
319
+ input {
320
+ margin-left: 58px;
321
+ width: auto;
322
+ }
323
+
256
324
  .cdx-list {
257
325
  padding-left: 85px;
258
326
  }
@@ -306,13 +374,26 @@ var StyledEditor = styled3.div`
306
374
  import Header from "@editorjs/header";
307
375
  import Paragraph from "@editorjs/paragraph";
308
376
  import List from "@editorjs/list";
377
+ import Table from "@editorjs/table";
378
+ import Quote from "@editorjs/quote";
379
+ import AudioPlayer from "editorjs-audio-player";
309
380
  var EDITOR_TOOLS = {
310
381
  paragraph: {
311
382
  class: Paragraph,
312
383
  inlineToolbar: true
313
384
  },
314
385
  list: List,
315
- header: Header
386
+ header: {
387
+ class: Header,
388
+ config: {
389
+ placeholder: "Enter a header",
390
+ levels: [2, 3, 4],
391
+ defaultLevel: 2
392
+ }
393
+ },
394
+ table: Table,
395
+ quote: Quote,
396
+ audioPlayer: AudioPlayer
316
397
  };
317
398
 
318
399
  // src/components/Editor/Editor.jsx
@@ -345,23 +426,9 @@ var Editor = ({ property, record, onChangeAdmin, editorId }) => {
345
426
  var Editor_default = Editor;
346
427
 
347
428
  // src/components/Editor/EditorList.jsx
429
+ import { theme as theme3 } from "@adminjs/design-system";
348
430
  import React6 from "react";
349
431
  import { ThemeProvider as ThemeProvider3 } from "styled-components";
350
- import { theme as theme3 } from "@adminjs/design-system";
351
-
352
- // src/utils/parseHtml.ts
353
- import edjsHTML from "editorjs-html";
354
- var parseHtml = (jsonData) => {
355
- const edjsParser = edjsHTML();
356
- try {
357
- const data = edjsParser.parse(JSON.parse(String(jsonData)));
358
- return String(data).replace(/>,</g, "><");
359
- } catch (e) {
360
- return;
361
- }
362
- };
363
-
364
- // src/components/Editor/EditorList.jsx
365
432
  var EditorList = ({ property, record }) => {
366
433
  const htmlContent = parseHtml(record.params[property.path]);
367
434
  return /* @__PURE__ */ React6.createElement(ThemeProvider3, { theme: theme3 }, /* @__PURE__ */ React6.createElement(StyledEditorViewWrapper, null, htmlContent && /* @__PURE__ */ React6.createElement("div", { dangerouslySetInnerHTML: { __html: htmlContent } })));
@@ -671,5 +738,6 @@ export {
671
738
  EditorList_default as EditorList,
672
739
  EditorShow_default as EditorShow,
673
740
  StringList_default as StringList,
674
- StringListShow_default as StringListShow
741
+ StringListShow_default as StringListShow,
742
+ parseHtml
675
743
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulab/adminjs-components",
3
- "version": "0.0.10",
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",
@@ -19,9 +19,14 @@ import {
19
19
  StyledLabel,
20
20
  } from "./styles.js";
21
21
 
22
- type CustomSlugTypes = Omit<EditPropertyProps, "where" | "resource">;
22
+ type CustomSlugTypes = Omit<EditPropertyProps, "where">;
23
23
 
24
- const CustomSlug: FC<CustomSlugTypes> = ({ property, record, onChange }) => {
24
+ const CustomSlug: FC<CustomSlugTypes> = ({
25
+ property,
26
+ record,
27
+ resource,
28
+ onChange,
29
+ }) => {
25
30
  const [inputValue, setInputValue] = useState(record.params.slug);
26
31
 
27
32
  useEffect(() => {
@@ -51,9 +56,11 @@ const CustomSlug: FC<CustomSlugTypes> = ({ property, record, onChange }) => {
51
56
 
52
57
  function generateSlug(e: SyntheticEvent<HTMLInputElement>) {
53
58
  e.preventDefault();
54
- const title = record.params.title;
55
- if (title) {
56
- setInputValue(slugifyTitle(title));
59
+ const slugSource =
60
+ record.params[property.props.sourceField ?? resource.titleProperty.name];
61
+
62
+ if (slugSource) {
63
+ setInputValue(slugifyTitle(slugSource));
57
64
  }
58
65
  }
59
66
  };
@@ -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
  };