@rulab/adminjs-components 0.0.1 → 0.0.3
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 +119 -0
- package/dist/index.d.cts +9 -2
- package/dist/index.d.ts +9 -2
- package/dist/index.js +118 -0
- package/package.json +8 -2
- package/src/components/Editor/Editor.jsx +48 -0
- package/src/components/Editor/config.ts +12 -0
- package/src/components/Editor/index.ts +1 -0
- package/src/components/Editor/styles.ts +67 -0
- package/src/components/index.ts +1 -0
- package/src/types.d.ts +3 -0
package/dist/index.cjs
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
CustomSlug: () => CustomSlug_default,
|
|
34
|
+
Editor: () => Editor_default,
|
|
34
35
|
StringList: () => StringList_default
|
|
35
36
|
});
|
|
36
37
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -326,8 +327,126 @@ var StringList = ({ record, onChange, property }) => {
|
|
|
326
327
|
}
|
|
327
328
|
};
|
|
328
329
|
var StringList_default = StringList;
|
|
330
|
+
|
|
331
|
+
// src/components/Editor/Editor.jsx
|
|
332
|
+
var import_react6 = __toESM(require("react"), 1);
|
|
333
|
+
var import_styled_components8 = require("styled-components");
|
|
334
|
+
var import_editorjs = __toESM(require("@editorjs/editorjs"), 1);
|
|
335
|
+
var import_design_system7 = require("@adminjs/design-system");
|
|
336
|
+
|
|
337
|
+
// src/components/Editor/styles.ts
|
|
338
|
+
var import_design_system6 = require("@adminjs/design-system");
|
|
339
|
+
var import_styled_components7 = require("@adminjs/design-system/styled-components");
|
|
340
|
+
var Label3 = import_styled_components7.styled.div`
|
|
341
|
+
font-size: 12px;
|
|
342
|
+
margin-bottom: 8px;
|
|
343
|
+
`;
|
|
344
|
+
var EditorWrapper = (0, import_styled_components7.styled)(import_design_system6.Box)`
|
|
345
|
+
padding: 12px;
|
|
346
|
+
border: 1px solid rgb(187, 195, 203);
|
|
347
|
+
`;
|
|
348
|
+
var StyledEditor = import_styled_components7.styled.div`
|
|
349
|
+
.cdx-block,
|
|
350
|
+
.ce-header {
|
|
351
|
+
padding-left: 58px;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
.cdx-list {
|
|
355
|
+
padding-left: 85px;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
.ce-block__content {
|
|
359
|
+
width: 100%;
|
|
360
|
+
max-width: none;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
.ce-toolbar__content {
|
|
364
|
+
max-width: none;
|
|
365
|
+
left: 0;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
.ce-toolbar__actions {
|
|
369
|
+
left: 0;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
h1.ce-header {
|
|
373
|
+
font-size: 22px;
|
|
374
|
+
font-weight: bold;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
h2.ce-header {
|
|
378
|
+
font-size: 20px;
|
|
379
|
+
font-weight: bold;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
h3.ce-header {
|
|
383
|
+
font-size: 18px;
|
|
384
|
+
font-weight: bold;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
h4.ce-header {
|
|
388
|
+
font-size: 16px;
|
|
389
|
+
font-weight: bold;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
h5.ce-header {
|
|
393
|
+
font-size: 15px;
|
|
394
|
+
font-weight: bold;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
h6.ce-header {
|
|
398
|
+
font-size: 14px;
|
|
399
|
+
font-weight: bold;
|
|
400
|
+
}
|
|
401
|
+
`;
|
|
402
|
+
|
|
403
|
+
// src/components/Editor/config.ts
|
|
404
|
+
var import_header = __toESM(require("@editorjs/header"), 1);
|
|
405
|
+
var import_paragraph = __toESM(require("@editorjs/paragraph"), 1);
|
|
406
|
+
var import_list = __toESM(require("@editorjs/list"), 1);
|
|
407
|
+
var EDITOR_TOOLS = {
|
|
408
|
+
paragraph: {
|
|
409
|
+
class: import_paragraph.default,
|
|
410
|
+
inlineToolbar: true
|
|
411
|
+
},
|
|
412
|
+
list: import_list.default,
|
|
413
|
+
header: import_header.default
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
// src/components/Editor/Editor.jsx
|
|
417
|
+
var Editor = ({ property, record, onChangeAdmin, editorId }) => {
|
|
418
|
+
const [jsonData, setJsonData] = (0, import_react6.useState)();
|
|
419
|
+
console.log(
|
|
420
|
+
record.params[property.path],
|
|
421
|
+
"record.params[property.path].path"
|
|
422
|
+
);
|
|
423
|
+
const ref = (0, import_react6.useRef)();
|
|
424
|
+
(0, import_react6.useEffect)(() => {
|
|
425
|
+
onChangeAdmin(property.path, jsonData);
|
|
426
|
+
}, [jsonData]);
|
|
427
|
+
(0, import_react6.useEffect)(() => {
|
|
428
|
+
if (!ref.current) {
|
|
429
|
+
const editor = new import_editorjs.default({
|
|
430
|
+
holder: editorId,
|
|
431
|
+
tools: EDITOR_TOOLS,
|
|
432
|
+
data: JSON.parse(record.params[property.path]),
|
|
433
|
+
async onChange(api, event) {
|
|
434
|
+
const data = await api.saver.save();
|
|
435
|
+
setJsonData(JSON.stringify(data));
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
ref.current = editor;
|
|
439
|
+
}
|
|
440
|
+
return () => {
|
|
441
|
+
ref?.current?.destroy?.();
|
|
442
|
+
};
|
|
443
|
+
}, []);
|
|
444
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_styled_components8.ThemeProvider, { theme: import_design_system7.theme }, /* @__PURE__ */ import_react6.default.createElement(Label3, null, "Text"), /* @__PURE__ */ import_react6.default.createElement(EditorWrapper, null, /* @__PURE__ */ import_react6.default.createElement(StyledEditor, { id: editorId })));
|
|
445
|
+
};
|
|
446
|
+
var Editor_default = Editor;
|
|
329
447
|
// Annotate the CommonJS export names for ESM import in node:
|
|
330
448
|
0 && (module.exports = {
|
|
331
449
|
CustomSlug,
|
|
450
|
+
Editor,
|
|
332
451
|
StringList
|
|
333
452
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
2
|
import { EditPropertyProps } from 'adminjs';
|
|
3
3
|
|
|
4
4
|
type CustomSlugTypes = Omit<EditPropertyProps, "where" | "resource">;
|
|
@@ -7,4 +7,11 @@ declare const CustomSlug: FC<CustomSlugTypes>;
|
|
|
7
7
|
type StringListTypes = Omit<EditPropertyProps, "where" | "resource">;
|
|
8
8
|
declare const StringList: FC<StringListTypes>;
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
declare function Editor({ property, record, onChangeAdmin, editorId }: {
|
|
11
|
+
property: any;
|
|
12
|
+
record: any;
|
|
13
|
+
onChangeAdmin: any;
|
|
14
|
+
editorId: any;
|
|
15
|
+
}): React.JSX.Element;
|
|
16
|
+
|
|
17
|
+
export { CustomSlug, Editor, StringList };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
2
|
import { EditPropertyProps } from 'adminjs';
|
|
3
3
|
|
|
4
4
|
type CustomSlugTypes = Omit<EditPropertyProps, "where" | "resource">;
|
|
@@ -7,4 +7,11 @@ declare const CustomSlug: FC<CustomSlugTypes>;
|
|
|
7
7
|
type StringListTypes = Omit<EditPropertyProps, "where" | "resource">;
|
|
8
8
|
declare const StringList: FC<StringListTypes>;
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
declare function Editor({ property, record, onChangeAdmin, editorId }: {
|
|
11
|
+
property: any;
|
|
12
|
+
record: any;
|
|
13
|
+
onChangeAdmin: any;
|
|
14
|
+
editorId: any;
|
|
15
|
+
}): React.JSX.Element;
|
|
16
|
+
|
|
17
|
+
export { CustomSlug, Editor, StringList };
|
package/dist/index.js
CHANGED
|
@@ -308,7 +308,125 @@ var StringList = ({ record, onChange, property }) => {
|
|
|
308
308
|
}
|
|
309
309
|
};
|
|
310
310
|
var StringList_default = StringList;
|
|
311
|
+
|
|
312
|
+
// src/components/Editor/Editor.jsx
|
|
313
|
+
import React6, { memo, useState as useState4, useEffect as useEffect3, useRef } from "react";
|
|
314
|
+
import { ThemeProvider as ThemeProvider3 } from "styled-components";
|
|
315
|
+
import EditorJS from "@editorjs/editorjs";
|
|
316
|
+
import { theme as theme3 } from "@adminjs/design-system";
|
|
317
|
+
|
|
318
|
+
// src/components/Editor/styles.ts
|
|
319
|
+
import { Box as Box3 } from "@adminjs/design-system";
|
|
320
|
+
import { styled as styled5 } from "@adminjs/design-system/styled-components";
|
|
321
|
+
var Label3 = styled5.div`
|
|
322
|
+
font-size: 12px;
|
|
323
|
+
margin-bottom: 8px;
|
|
324
|
+
`;
|
|
325
|
+
var EditorWrapper = styled5(Box3)`
|
|
326
|
+
padding: 12px;
|
|
327
|
+
border: 1px solid rgb(187, 195, 203);
|
|
328
|
+
`;
|
|
329
|
+
var StyledEditor = styled5.div`
|
|
330
|
+
.cdx-block,
|
|
331
|
+
.ce-header {
|
|
332
|
+
padding-left: 58px;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
.cdx-list {
|
|
336
|
+
padding-left: 85px;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
.ce-block__content {
|
|
340
|
+
width: 100%;
|
|
341
|
+
max-width: none;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
.ce-toolbar__content {
|
|
345
|
+
max-width: none;
|
|
346
|
+
left: 0;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
.ce-toolbar__actions {
|
|
350
|
+
left: 0;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
h1.ce-header {
|
|
354
|
+
font-size: 22px;
|
|
355
|
+
font-weight: bold;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
h2.ce-header {
|
|
359
|
+
font-size: 20px;
|
|
360
|
+
font-weight: bold;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
h3.ce-header {
|
|
364
|
+
font-size: 18px;
|
|
365
|
+
font-weight: bold;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
h4.ce-header {
|
|
369
|
+
font-size: 16px;
|
|
370
|
+
font-weight: bold;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
h5.ce-header {
|
|
374
|
+
font-size: 15px;
|
|
375
|
+
font-weight: bold;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
h6.ce-header {
|
|
379
|
+
font-size: 14px;
|
|
380
|
+
font-weight: bold;
|
|
381
|
+
}
|
|
382
|
+
`;
|
|
383
|
+
|
|
384
|
+
// src/components/Editor/config.ts
|
|
385
|
+
import Header from "@editorjs/header";
|
|
386
|
+
import Paragraph from "@editorjs/paragraph";
|
|
387
|
+
import List from "@editorjs/list";
|
|
388
|
+
var EDITOR_TOOLS = {
|
|
389
|
+
paragraph: {
|
|
390
|
+
class: Paragraph,
|
|
391
|
+
inlineToolbar: true
|
|
392
|
+
},
|
|
393
|
+
list: List,
|
|
394
|
+
header: Header
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
// src/components/Editor/Editor.jsx
|
|
398
|
+
var Editor = ({ property, record, onChangeAdmin, editorId }) => {
|
|
399
|
+
const [jsonData, setJsonData] = useState4();
|
|
400
|
+
console.log(
|
|
401
|
+
record.params[property.path],
|
|
402
|
+
"record.params[property.path].path"
|
|
403
|
+
);
|
|
404
|
+
const ref = useRef();
|
|
405
|
+
useEffect3(() => {
|
|
406
|
+
onChangeAdmin(property.path, jsonData);
|
|
407
|
+
}, [jsonData]);
|
|
408
|
+
useEffect3(() => {
|
|
409
|
+
if (!ref.current) {
|
|
410
|
+
const editor = new EditorJS({
|
|
411
|
+
holder: editorId,
|
|
412
|
+
tools: EDITOR_TOOLS,
|
|
413
|
+
data: JSON.parse(record.params[property.path]),
|
|
414
|
+
async onChange(api, event) {
|
|
415
|
+
const data = await api.saver.save();
|
|
416
|
+
setJsonData(JSON.stringify(data));
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
ref.current = editor;
|
|
420
|
+
}
|
|
421
|
+
return () => {
|
|
422
|
+
ref?.current?.destroy?.();
|
|
423
|
+
};
|
|
424
|
+
}, []);
|
|
425
|
+
return /* @__PURE__ */ React6.createElement(ThemeProvider3, { theme: theme3 }, /* @__PURE__ */ React6.createElement(Label3, null, "Text"), /* @__PURE__ */ React6.createElement(EditorWrapper, null, /* @__PURE__ */ React6.createElement(StyledEditor, { id: editorId })));
|
|
426
|
+
};
|
|
427
|
+
var Editor_default = Editor;
|
|
311
428
|
export {
|
|
312
429
|
CustomSlug_default as CustomSlug,
|
|
430
|
+
Editor_default as Editor,
|
|
313
431
|
StringList_default as StringList
|
|
314
432
|
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulab/adminjs-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"private": false,
|
|
8
8
|
"type": "module",
|
|
9
|
-
"keywords": [
|
|
9
|
+
"keywords": [
|
|
10
|
+
"adminjs"
|
|
11
|
+
],
|
|
10
12
|
"repository": {
|
|
11
13
|
"url": "https://github.com/rulab/adminjs-components"
|
|
12
14
|
},
|
|
@@ -18,6 +20,10 @@
|
|
|
18
20
|
"@adminjs/design-system": "^4.1.1",
|
|
19
21
|
"@dnd-kit/core": "^6.1.0",
|
|
20
22
|
"@dnd-kit/sortable": "^8.0.0",
|
|
23
|
+
"@editorjs/editorjs": "^2.30.2",
|
|
24
|
+
"@editorjs/header": "^2.8.7",
|
|
25
|
+
"@editorjs/list": "^1.9.0",
|
|
26
|
+
"@editorjs/paragraph": "^2.11.6",
|
|
21
27
|
"adminjs": "^7.8.1",
|
|
22
28
|
"react": "^18.2.0",
|
|
23
29
|
"slugify": "^1.6.6",
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React, { memo, useState, useEffect, useRef } from "react";
|
|
2
|
+
import { ThemeProvider } from "styled-components";
|
|
3
|
+
import EditorJS from "@editorjs/editorjs";
|
|
4
|
+
import { theme } from "@adminjs/design-system";
|
|
5
|
+
|
|
6
|
+
import { Label, StyledEditor, EditorWrapper } from "./styles";
|
|
7
|
+
|
|
8
|
+
import { EDITOR_TOOLS } from "./config";
|
|
9
|
+
|
|
10
|
+
const Editor = ({ property, record, onChangeAdmin, editorId }) => {
|
|
11
|
+
const [jsonData, setJsonData] = useState();
|
|
12
|
+
|
|
13
|
+
const ref = useRef();
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
onChangeAdmin(property.path, jsonData);
|
|
17
|
+
}, [jsonData]);
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!ref.current) {
|
|
21
|
+
const editor = new EditorJS({
|
|
22
|
+
holder: editorId,
|
|
23
|
+
tools: EDITOR_TOOLS,
|
|
24
|
+
data: JSON.parse(record.params[property.path]),
|
|
25
|
+
async onChange(api, event) {
|
|
26
|
+
const data = await api.saver.save();
|
|
27
|
+
setJsonData(JSON.stringify(data));
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
ref.current = editor;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return () => {
|
|
34
|
+
ref?.current?.destroy?.();
|
|
35
|
+
};
|
|
36
|
+
}, []);
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<ThemeProvider theme={theme}>
|
|
40
|
+
<Label>Text</Label>
|
|
41
|
+
<EditorWrapper>
|
|
42
|
+
<StyledEditor id={editorId} />
|
|
43
|
+
</EditorWrapper>
|
|
44
|
+
</ThemeProvider>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default Editor;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Header from "@editorjs/header";
|
|
2
|
+
import Paragraph from "@editorjs/paragraph";
|
|
3
|
+
import List from "@editorjs/list";
|
|
4
|
+
|
|
5
|
+
export const EDITOR_TOOLS = {
|
|
6
|
+
paragraph: {
|
|
7
|
+
class: Paragraph,
|
|
8
|
+
inlineToolbar: true,
|
|
9
|
+
},
|
|
10
|
+
list: List,
|
|
11
|
+
header: Header,
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Editor.jsx";
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Box } from "@adminjs/design-system";
|
|
2
|
+
import { styled } from "@adminjs/design-system/styled-components";
|
|
3
|
+
|
|
4
|
+
export const Label = styled.div`
|
|
5
|
+
font-size: 12px;
|
|
6
|
+
margin-bottom: 8px;
|
|
7
|
+
`;
|
|
8
|
+
|
|
9
|
+
export const EditorWrapper = styled(Box)`
|
|
10
|
+
padding: 12px;
|
|
11
|
+
border: 1px solid rgb(187, 195, 203);
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
export const StyledEditor = styled.div`
|
|
15
|
+
.cdx-block,
|
|
16
|
+
.ce-header {
|
|
17
|
+
padding-left: 58px;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.cdx-list {
|
|
21
|
+
padding-left: 85px;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.ce-block__content {
|
|
25
|
+
width: 100%;
|
|
26
|
+
max-width: none;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.ce-toolbar__content {
|
|
30
|
+
max-width: none;
|
|
31
|
+
left: 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.ce-toolbar__actions {
|
|
35
|
+
left: 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
h1.ce-header {
|
|
39
|
+
font-size: 22px;
|
|
40
|
+
font-weight: bold;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
h2.ce-header {
|
|
44
|
+
font-size: 20px;
|
|
45
|
+
font-weight: bold;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
h3.ce-header {
|
|
49
|
+
font-size: 18px;
|
|
50
|
+
font-weight: bold;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
h4.ce-header {
|
|
54
|
+
font-size: 16px;
|
|
55
|
+
font-weight: bold;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
h5.ce-header {
|
|
59
|
+
font-size: 15px;
|
|
60
|
+
font-weight: bold;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
h6.ce-header {
|
|
64
|
+
font-size: 14px;
|
|
65
|
+
font-weight: bold;
|
|
66
|
+
}
|
|
67
|
+
`;
|
package/src/components/index.ts
CHANGED
package/src/types.d.ts
ADDED