@rulab/adminjs-components 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.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
 
@@ -109,7 +110,7 @@ var colorStyles = {
109
110
  var ColorStatus = ({ property, record, onChange }) => {
110
111
  const availableValues = property.availableValues;
111
112
  const currentOption = availableValues.find(
112
- (item) => item.value === record.params.colorStatus
113
+ (item) => item.value === record.params[property.path]
113
114
  );
114
115
  const [selectOption, setCurrentOption] = (0, import_react.useState)(currentOption);
115
116
  const handleSelectChange = (option) => {
@@ -138,9 +139,9 @@ var ColorStatusEdit_default = ColorStatus;
138
139
  var import_react2 = __toESM(require("react"), 1);
139
140
  var ColorStatusShow = ({ property, record }) => {
140
141
  const currentOption = property.availableValues?.find(
141
- (item) => item.value === record.params.colorStatus
142
+ (item) => item.value === record.params[property.path]
142
143
  );
143
- return /* @__PURE__ */ import_react2.default.createElement(ColorStatusBadgeWrapper, null, /* @__PURE__ */ import_react2.default.createElement(ShowLabel, null, property.path), /* @__PURE__ */ import_react2.default.createElement(ColorStatusBadge, { color: currentOption.color }, record.params.colorStatus));
144
+ return /* @__PURE__ */ import_react2.default.createElement(ColorStatusBadgeWrapper, null, /* @__PURE__ */ import_react2.default.createElement(ShowLabel, null, property.path), /* @__PURE__ */ import_react2.default.createElement(ColorStatusBadge, { color: currentOption.color }, record.params[property.path]));
144
145
  };
145
146
  var ColorStatusShow_default = ColorStatusShow;
146
147
 
@@ -148,9 +149,9 @@ var ColorStatusShow_default = ColorStatusShow;
148
149
  var import_react3 = __toESM(require("react"), 1);
149
150
  var ColorStatusList = ({ property, record }) => {
150
151
  const currentOption = property.availableValues?.find(
151
- (item) => item.value === record.params.colorStatus
152
+ (item) => item.value === record.params[property.path]
152
153
  );
153
- return /* @__PURE__ */ import_react3.default.createElement(ColorStatusBadge, { color: currentOption.color }, record.params.colorStatus);
154
+ return /* @__PURE__ */ import_react3.default.createElement(ColorStatusBadge, { color: currentOption.color }, record.params[property.path]);
154
155
  };
155
156
  var ColorStatusList_default = ColorStatusList;
156
157
 
@@ -174,6 +175,42 @@ var slugifyTitle = (title) => {
174
175
  });
175
176
  };
176
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
+
177
214
  // src/components/CustomSlug/styles.ts
178
215
  var import_styled_components2 = require("@adminjs/design-system/styled-components");
179
216
  var import_design_system = require("@adminjs/design-system");
@@ -282,16 +319,50 @@ var StyledEditorViewWrapper = (0, import_styled_components4.styled)(import_desig
282
319
  ul {
283
320
  list-style: inherit;
284
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
+ }
285
350
  `;
286
351
  var StyledEditorShowWrapper = (0, import_styled_components4.styled)(StyledEditorViewWrapper)`
287
352
  margin-bottom: 24px;
288
353
  `;
289
354
  var StyledEditor = import_styled_components4.styled.div`
355
+ audio,
290
356
  .cdx-block,
291
357
  .ce-header {
292
358
  padding-left: 58px;
293
359
  }
294
360
 
361
+ input {
362
+ margin-left: 58px;
363
+ width: auto;
364
+ }
365
+
295
366
  .cdx-list {
296
367
  padding-left: 85px;
297
368
  }
@@ -345,13 +416,26 @@ var StyledEditor = import_styled_components4.styled.div`
345
416
  var import_header = __toESM(require("@editorjs/header"), 1);
346
417
  var import_paragraph = __toESM(require("@editorjs/paragraph"), 1);
347
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);
348
422
  var EDITOR_TOOLS = {
349
423
  paragraph: {
350
424
  class: import_paragraph.default,
351
425
  inlineToolbar: true
352
426
  },
353
427
  list: import_list.default,
354
- 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
355
439
  };
356
440
 
357
441
  // src/components/Editor/Editor.jsx
@@ -384,23 +468,9 @@ var Editor = ({ property, record, onChangeAdmin, editorId }) => {
384
468
  var Editor_default = Editor;
385
469
 
386
470
  // src/components/Editor/EditorList.jsx
471
+ var import_design_system5 = require("@adminjs/design-system");
387
472
  var import_react6 = __toESM(require("react"), 1);
388
473
  var import_styled_components6 = require("styled-components");
389
- var import_design_system5 = require("@adminjs/design-system");
390
-
391
- // src/utils/parseHtml.ts
392
- var import_editorjs_html = __toESM(require("editorjs-html"), 1);
393
- var parseHtml = (jsonData) => {
394
- const edjsParser = (0, import_editorjs_html.default)();
395
- try {
396
- const data = edjsParser.parse(JSON.parse(String(jsonData)));
397
- return String(data).replace(/>,</g, "><");
398
- } catch (e) {
399
- return;
400
- }
401
- };
402
-
403
- // src/components/Editor/EditorList.jsx
404
474
  var EditorList = ({ property, record }) => {
405
475
  const htmlContent = parseHtml(record.params[property.path]);
406
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 } })));
@@ -695,5 +765,6 @@ var StringListShow_default = StringListShow;
695
765
  EditorList,
696
766
  EditorShow,
697
767
  StringList,
698
- StringListShow
768
+ StringListShow,
769
+ parseHtml
699
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
@@ -65,7 +65,7 @@ var colorStyles = {
65
65
  var ColorStatus = ({ property, record, onChange }) => {
66
66
  const availableValues = property.availableValues;
67
67
  const currentOption = availableValues.find(
68
- (item) => item.value === record.params.colorStatus
68
+ (item) => item.value === record.params[property.path]
69
69
  );
70
70
  const [selectOption, setCurrentOption] = useState(currentOption);
71
71
  const handleSelectChange = (option) => {
@@ -94,9 +94,9 @@ var ColorStatusEdit_default = ColorStatus;
94
94
  import React2 from "react";
95
95
  var ColorStatusShow = ({ property, record }) => {
96
96
  const currentOption = property.availableValues?.find(
97
- (item) => item.value === record.params.colorStatus
97
+ (item) => item.value === record.params[property.path]
98
98
  );
99
- return /* @__PURE__ */ React2.createElement(ColorStatusBadgeWrapper, null, /* @__PURE__ */ React2.createElement(ShowLabel, null, property.path), /* @__PURE__ */ React2.createElement(ColorStatusBadge, { color: currentOption.color }, record.params.colorStatus));
99
+ return /* @__PURE__ */ React2.createElement(ColorStatusBadgeWrapper, null, /* @__PURE__ */ React2.createElement(ShowLabel, null, property.path), /* @__PURE__ */ React2.createElement(ColorStatusBadge, { color: currentOption.color }, record.params[property.path]));
100
100
  };
101
101
  var ColorStatusShow_default = ColorStatusShow;
102
102
 
@@ -104,9 +104,9 @@ var ColorStatusShow_default = ColorStatusShow;
104
104
  import React3 from "react";
105
105
  var ColorStatusList = ({ property, record }) => {
106
106
  const currentOption = property.availableValues?.find(
107
- (item) => item.value === record.params.colorStatus
107
+ (item) => item.value === record.params[property.path]
108
108
  );
109
- return /* @__PURE__ */ React3.createElement(ColorStatusBadge, { color: currentOption.color }, record.params.colorStatus);
109
+ return /* @__PURE__ */ React3.createElement(ColorStatusBadge, { color: currentOption.color }, record.params[property.path]);
110
110
  };
111
111
  var ColorStatusList_default = ColorStatusList;
112
112
 
@@ -133,6 +133,42 @@ var slugifyTitle = (title) => {
133
133
  });
134
134
  };
135
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
+
136
172
  // src/components/CustomSlug/styles.ts
137
173
  import { styled as styled2 } from "@adminjs/design-system/styled-components";
138
174
  import { Box, Button, Input } from "@adminjs/design-system";
@@ -241,16 +277,50 @@ var StyledEditorViewWrapper = styled3(Box2)`
241
277
  ul {
242
278
  list-style: inherit;
243
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
+ }
244
308
  `;
245
309
  var StyledEditorShowWrapper = styled3(StyledEditorViewWrapper)`
246
310
  margin-bottom: 24px;
247
311
  `;
248
312
  var StyledEditor = styled3.div`
313
+ audio,
249
314
  .cdx-block,
250
315
  .ce-header {
251
316
  padding-left: 58px;
252
317
  }
253
318
 
319
+ input {
320
+ margin-left: 58px;
321
+ width: auto;
322
+ }
323
+
254
324
  .cdx-list {
255
325
  padding-left: 85px;
256
326
  }
@@ -304,13 +374,26 @@ var StyledEditor = styled3.div`
304
374
  import Header from "@editorjs/header";
305
375
  import Paragraph from "@editorjs/paragraph";
306
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";
307
380
  var EDITOR_TOOLS = {
308
381
  paragraph: {
309
382
  class: Paragraph,
310
383
  inlineToolbar: true
311
384
  },
312
385
  list: List,
313
- 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
314
397
  };
315
398
 
316
399
  // src/components/Editor/Editor.jsx
@@ -343,23 +426,9 @@ var Editor = ({ property, record, onChangeAdmin, editorId }) => {
343
426
  var Editor_default = Editor;
344
427
 
345
428
  // src/components/Editor/EditorList.jsx
429
+ import { theme as theme3 } from "@adminjs/design-system";
346
430
  import React6 from "react";
347
431
  import { ThemeProvider as ThemeProvider3 } from "styled-components";
348
- import { theme as theme3 } from "@adminjs/design-system";
349
-
350
- // src/utils/parseHtml.ts
351
- import edjsHTML from "editorjs-html";
352
- var parseHtml = (jsonData) => {
353
- const edjsParser = edjsHTML();
354
- try {
355
- const data = edjsParser.parse(JSON.parse(String(jsonData)));
356
- return String(data).replace(/>,</g, "><");
357
- } catch (e) {
358
- return;
359
- }
360
- };
361
-
362
- // src/components/Editor/EditorList.jsx
363
432
  var EditorList = ({ property, record }) => {
364
433
  const htmlContent = parseHtml(record.params[property.path]);
365
434
  return /* @__PURE__ */ React6.createElement(ThemeProvider3, { theme: theme3 }, /* @__PURE__ */ React6.createElement(StyledEditorViewWrapper, null, htmlContent && /* @__PURE__ */ React6.createElement("div", { dangerouslySetInnerHTML: { __html: htmlContent } })));
@@ -669,5 +738,6 @@ export {
669
738
  EditorList_default as EditorList,
670
739
  EditorShow_default as EditorShow,
671
740
  StringList_default as StringList,
672
- StringListShow_default as StringListShow
741
+ StringListShow_default as StringListShow,
742
+ parseHtml
673
743
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulab/adminjs-components",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -57,7 +57,7 @@ const ColorStatus: FC<ColorStatusTypes> = ({ property, record, onChange }) => {
57
57
  const availableValues = property.availableValues as AvailableValueType[];
58
58
 
59
59
  const currentOption = availableValues.find(
60
- (item) => item.value === record.params.colorStatus,
60
+ (item) => item.value === record.params[property.path],
61
61
  ) as AvailableValueType;
62
62
 
63
63
  const [selectOption, setCurrentOption] = useState<
@@ -7,12 +7,12 @@ import type { AvailableValueType } from "./types";
7
7
 
8
8
  const ColorStatusList: FC<ShowPropertyProps> = ({ property, record }) => {
9
9
  const currentOption = property.availableValues?.find(
10
- (item) => item.value === record.params.colorStatus,
10
+ (item) => item.value === record.params[property.path],
11
11
  ) as AvailableValueType;
12
12
 
13
13
  return (
14
14
  <ColorStatusBadge color={currentOption.color}>
15
- {record.params.colorStatus}
15
+ {record.params[property.path]}
16
16
  </ColorStatusBadge>
17
17
  );
18
18
  };
@@ -7,14 +7,14 @@ import type { AvailableValueType } from "./types";
7
7
 
8
8
  const ColorStatusShow: FC<ShowPropertyProps> = ({ property, record }) => {
9
9
  const currentOption = property.availableValues?.find(
10
- (item) => item.value === record.params.colorStatus,
10
+ (item) => item.value === record.params[property.path],
11
11
  ) as AvailableValueType;
12
12
 
13
13
  return (
14
14
  <ColorStatusBadgeWrapper>
15
15
  <ShowLabel>{property.path}</ShowLabel>
16
16
  <ColorStatusBadge color={currentOption.color}>
17
- {record.params.colorStatus}
17
+ {record.params[property.path]}
18
18
  </ColorStatusBadge>
19
19
  </ColorStatusBadgeWrapper>
20
20
  );
@@ -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
  };