@rulab/adminjs-components 0.0.13 → 0.1.0-alpha.2

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.
Files changed (71) hide show
  1. package/LICENSE +21 -21
  2. package/dist/index.cjs +10 -762
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.cts +10 -21
  5. package/dist/index.d.ts +10 -21
  6. package/dist/index.js +3 -754
  7. package/dist/index.js.map +1 -0
  8. package/package.json +12 -8
  9. package/src/components/ColorStatus/ColorStatusEdit.tsx +94 -94
  10. package/src/components/ColorStatus/ColorStatusList.tsx +20 -20
  11. package/src/components/ColorStatus/ColorStatusShow.tsx +23 -23
  12. package/src/components/ColorStatus/index.ts +3 -3
  13. package/src/components/ColorStatus/styles.ts +30 -30
  14. package/src/components/ColorStatus/types.ts +5 -5
  15. package/src/components/Editor/Editor.jsx +49 -49
  16. package/src/components/Editor/EditorList.jsx +22 -22
  17. package/src/components/Editor/EditorShow.jsx +24 -24
  18. package/src/components/Editor/config.ts +35 -35
  19. package/src/components/Editor/index.ts +3 -3
  20. package/src/components/Editor/styles.ts +151 -151
  21. package/src/components/{CustomSlug/CustomSlug.tsx → Slug/SlugEdit.tsx} +68 -68
  22. package/src/components/Slug/SlugFeature.ts +30 -0
  23. package/src/components/Slug/index.ts +1 -0
  24. package/src/components/{CustomSlug → Slug}/styles.ts +24 -24
  25. package/src/components/StringList/SortableList/SortableList.tsx +98 -98
  26. package/src/components/StringList/SortableList/components/SortableItem/DragHandle.tsx +20 -20
  27. package/src/components/StringList/SortableList/components/SortableItem/SortableItem.tsx +59 -59
  28. package/src/components/StringList/SortableList/components/SortableItem/styles.ts +22 -22
  29. package/src/components/StringList/SortableList/components/SortableItem/types.ts +7 -7
  30. package/src/components/StringList/SortableList/components/index.ts +2 -2
  31. package/src/components/StringList/SortableList/index.ts +1 -1
  32. package/src/components/StringList/SortableList/styles.ts +9 -9
  33. package/src/components/StringList/StringList.tsx +136 -136
  34. package/src/components/StringList/StringListShow.tsx +37 -37
  35. package/src/components/StringList/constants.ts +1 -1
  36. package/src/components/StringList/index.ts +2 -2
  37. package/src/components/StringList/styles.ts +41 -41
  38. package/src/components/index.ts +10 -9
  39. package/dist/bundle.js +0 -8
  40. package/dist/components/CustomSlug/CustomSlug.jsx +0 -29
  41. package/dist/components/CustomSlug/index.js +0 -1
  42. package/dist/components/CustomSlug/styles.js +0 -15
  43. package/dist/components/Editor/config.js +0 -11
  44. package/dist/components/Editor/index.js +0 -1
  45. package/dist/components/Editor/styles.js +0 -64
  46. package/dist/components/StringList/SortableList/SortableList.jsx +0 -43
  47. package/dist/components/StringList/SortableList/components/SortableItem/DragHandle.jsx +0 -10
  48. package/dist/components/StringList/SortableList/components/SortableItem/SortableItem.jsx +0 -32
  49. package/dist/components/StringList/SortableList/components/SortableItem/styles.js +0 -20
  50. package/dist/components/StringList/SortableList/components/SortableItem/types.js +0 -1
  51. package/dist/components/StringList/SortableList/components/index.js +0 -2
  52. package/dist/components/StringList/SortableList/index.js +0 -1
  53. package/dist/components/StringList/SortableList/styles.js +0 -8
  54. package/dist/components/StringList/StringList.jsx +0 -67
  55. package/dist/components/StringList/index.js +0 -1
  56. package/dist/components/StringList/styles.js +0 -16
  57. package/dist/components/index.js +0 -3
  58. package/dist/editorFeature.js +0 -16
  59. package/dist/index.d.mts +0 -8
  60. package/dist/index.mjs +0 -37
  61. package/dist/utils/index.js +0 -1
  62. package/dist/utils/slugifyImport.js +0 -3
  63. package/dist/utils/slugifyTitle.js +0 -10
  64. package/src/components/CustomSlug/index.ts +0 -1
  65. package/src/index.ts +0 -2
  66. package/src/types.d.ts +0 -3
  67. package/src/utils/index.ts +0 -3
  68. package/src/utils/parseHtml.ts +0 -56
  69. package/src/utils/slugifyImport.ts +0 -4
  70. package/src/utils/slugifyTitle.ts +0 -11
  71. package/tsconfig.json +0 -17
@@ -1,32 +0,0 @@
1
- import React, { createContext, useMemo } from 'react';
2
- import { useSortable } from '@dnd-kit/sortable';
3
- import { Button, Icon } from '@adminjs/design-system';
4
- import { DragHandle } from './DragHandle.js';
5
- import { StyledListItem } from './styles.js';
6
- const SortableItemContext = createContext({
7
- attributes: {},
8
- listeners: undefined,
9
- ref() { },
10
- });
11
- export function SortableItem({ children, id, onDelete, }) {
12
- const { attributes, isDragging, listeners, setNodeRef, setActivatorNodeRef } = useSortable({ id });
13
- const context = useMemo(() => ({
14
- attributes,
15
- listeners,
16
- ref: setActivatorNodeRef,
17
- }), [attributes, listeners, setActivatorNodeRef]);
18
- const style = {
19
- opacity: isDragging ? 0.4 : undefined,
20
- };
21
- return (<SortableItemContext.Provider value={context}>
22
- <StyledListItem ref={setNodeRef} style={style}>
23
- <div>
24
- <DragHandle context={SortableItemContext}/>
25
- {children}
26
- </div>
27
- <Button variant="outlined" color="danger" size="icon" onClick={(e) => onDelete(e, id)}>
28
- <Icon icon="X" color="red"/>
29
- </Button>
30
- </StyledListItem>
31
- </SortableItemContext.Provider>);
32
- }
@@ -1,20 +0,0 @@
1
- import { styled } from '@adminjs/design-system/styled-components';
2
- export const StyledListItem = styled.li `
3
- display: flex;
4
- justify-content: space-between;
5
- align-items: center;
6
- background-color: #fff;
7
- padding: 10px 20px 10px 15px;
8
- box-shadow:
9
- 0 0 0 calc(1px / var(--scale-x, 1)) rgba(63, 63, 68, 0.05),
10
- 0 1px calc(3px / var(--scale-x, 1)) 0 rgba(34, 33, 81, 0.15);
11
- border-radius: 5px;
12
- list-style: none;
13
- `;
14
- export const DragButton = styled.button `
15
- padding: 3px;
16
- margin-right: 15px;
17
- cursor: move;
18
- background: none;
19
- border: none;
20
- `;
@@ -1,2 +0,0 @@
1
- export { SortableItem } from './SortableItem/SortableItem.js';
2
- export { DragHandle } from './SortableItem/DragHandle.js';
@@ -1 +0,0 @@
1
- export { SortableList } from './SortableList.js';
@@ -1,8 +0,0 @@
1
- import { styled } from '@adminjs/design-system/styled-components';
2
- export const StyledListWrapper = styled.ul `
3
- display: flex;
4
- flex-direction: column;
5
- gap: 12px;
6
- padding: 0;
7
- list-style: none;
8
- `;
@@ -1,67 +0,0 @@
1
- import React, { useState, useEffect, } from "react";
2
- import { ThemeProvider } from "styled-components";
3
- import { theme, Button, Input, Label } from "@adminjs/design-system";
4
- import { StyledWrapper, StyledCustomInput, StyledListWrapper, StyledInputWrapper, } from "./styles.js";
5
- import { SortableList } from "./SortableList/SortableList.js";
6
- const StringList = ({ record, onChange, property }) => {
7
- const stringListValue = record.params?.[property.path] ?? property.props.value ?? "";
8
- const initialList = stringListValue
9
- ? prepareDataForList(stringListValue)
10
- : [];
11
- const [inputValue, setInputValue] = useState("");
12
- const [list, setList] = useState(initialList);
13
- const serializedData = prepareDataForDatabase(list);
14
- useEffect(() => {
15
- onChange(property.path, serializedData);
16
- }, [serializedData]);
17
- return (<ThemeProvider theme={theme}>
18
- <Label htmlFor="custom">String List</Label>
19
- <StyledWrapper>
20
- <StyledListWrapper>
21
- <SortableList items={list} onChange={setList} renderItem={(item) => (<SortableList.Item id={item.id} onDelete={handleDeleteButton}>
22
- {item.value}
23
- </SortableList.Item>)}/>
24
- </StyledListWrapper>
25
- <StyledInputWrapper>
26
- <Input id="stringList" name={property.path} value={serializedData} hidden/>
27
- <StyledCustomInput id="custom" name="customInput" value={inputValue} onChange={handleInput} onKeyPress={handleEnterPress}/>
28
- <Button variant="outlined" onClick={handleAddButton}>
29
- Add
30
- </Button>
31
- </StyledInputWrapper>
32
- </StyledWrapper>
33
- </ThemeProvider>);
34
- function handleInput(e) {
35
- setInputValue(e.target.value);
36
- }
37
- function handleEnterPress(e) {
38
- if (e.key === "Enter") {
39
- handleAddButton(e);
40
- }
41
- }
42
- function handleAddButton(e) {
43
- e.preventDefault();
44
- if (Boolean(inputValue)) {
45
- setList([...list, createListObject(inputValue)]);
46
- setInputValue("");
47
- }
48
- }
49
- function handleDeleteButton(e, id) {
50
- e.preventDefault();
51
- const newData = list.filter((item) => item.id !== id);
52
- setList(newData);
53
- }
54
- function prepareDataForDatabase(list) {
55
- return list.map(({ value }) => value).join("|");
56
- }
57
- function prepareDataForList(str) {
58
- return str.split("|").map((item) => createListObject(item));
59
- }
60
- function createListObject(value) {
61
- return {
62
- id: `${Date.now()}-${Math.floor(Math.random() * 1000)}`,
63
- value: value,
64
- };
65
- }
66
- };
67
- export default StringList;
@@ -1 +0,0 @@
1
- export { default } from "./StringList.js";
@@ -1,16 +0,0 @@
1
- import { styled } from "@adminjs/design-system/styled-components";
2
- import { Box, Input } from "@adminjs/design-system";
3
- export const StyledWrapper = styled(Box) `
4
- display: flex;
5
- flex-direction: column;
6
- `;
7
- export const StyledCustomInput = styled(Input) `
8
- width: 100%;
9
- margin-right: 10px;
10
- `;
11
- export const StyledInputWrapper = styled(Box) `
12
- display: flex;
13
- `;
14
- export const StyledListWrapper = styled(Box) `
15
- margin-bottom: 15px;
16
- `;
@@ -1,3 +0,0 @@
1
- export { default as CustomSlug } from "./CustomSlug/CustomSlug.js";
2
- export { default as StringList } from "./StringList/StringList.js";
3
- export { default as Editor } from "./Editor";
@@ -1,16 +0,0 @@
1
- import { buildFeature, } from "adminjs";
2
- import bundleComponent from "./bundle.js";
3
- const editorFeature = (options) => {
4
- const { componentLoader, name } = options;
5
- const editComponent = bundleComponent(componentLoader, "Editor");
6
- return buildFeature({
7
- properties: {
8
- [name]: {
9
- components: {
10
- edit: editComponent,
11
- },
12
- },
13
- },
14
- });
15
- };
16
- export default editorFeature;
package/dist/index.d.mts DELETED
@@ -1,8 +0,0 @@
1
- import { FeatureType, ComponentLoader } from 'adminjs';
2
-
3
- type EditorOptions = {
4
- componentLoader: ComponentLoader;
5
- };
6
- declare const editorFeature: (options: EditorOptions) => FeatureType;
7
-
8
- export { editorFeature as default, editorFeature };
package/dist/index.mjs DELETED
@@ -1,37 +0,0 @@
1
- // src/features/editorFeature.ts
2
- import {
3
- buildFeature
4
- } from "adminjs";
5
-
6
- // src/bundle.ts
7
- import path from "path";
8
- import * as url from "url";
9
- var __dirname = url.fileURLToPath(new URL(".", import.meta.url));
10
- var bundle = (loader, componentName) => {
11
- const componentPath = path.join(__dirname, `./components/${componentName}`);
12
- return loader.add(componentName, componentPath);
13
- };
14
- var bundle_default = bundle;
15
-
16
- // src/features/editorFeature.ts
17
- var editorFeature = (options) => {
18
- const { componentLoader } = options;
19
- const editComponent = bundle_default(componentLoader, "Editor");
20
- return buildFeature({
21
- properties: {
22
- editor: {
23
- components: {
24
- edit: editComponent
25
- }
26
- }
27
- }
28
- });
29
- };
30
- var editorFeature_default = editorFeature;
31
-
32
- // src/index.ts
33
- var src_default = editorFeature_default;
34
- export {
35
- src_default as default,
36
- editorFeature_default as editorFeature
37
- };
@@ -1 +0,0 @@
1
- export { slugifyTitle } from "./slugifyTitle.js";
@@ -1,3 +0,0 @@
1
- // This is a fix of typescript module import error
2
- import * as slugify from "slugify";
3
- export default slugify;
@@ -1,10 +0,0 @@
1
- import * as slugify from "slugify";
2
- export const slugifyTitle = (title) => {
3
- return slugify.default(title, {
4
- replacement: "-",
5
- remove: undefined,
6
- lower: true,
7
- locale: "vi",
8
- trim: true,
9
- });
10
- };
@@ -1 +0,0 @@
1
- export { default } from "./CustomSlug.js";
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./components/index.js";
2
- export { parseHtml } from "./utils/parseHtml.js";
package/src/types.d.ts DELETED
@@ -1,3 +0,0 @@
1
- declare module "@editorjs/header";
2
- declare module "@editorjs/paragraph";
3
- declare module "@editorjs/list";
@@ -1,3 +0,0 @@
1
- export { parseHtml } from "./parseHtml.js";
2
- export { slugifyTitle } from "./slugifyTitle.js";
3
-
@@ -1,56 +0,0 @@
1
- import edjsHTML from "editorjs-html";
2
-
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
- });
49
-
50
- try {
51
- const data = edjsParser.parse(JSON.parse(jsonData));
52
- return String(data).replace(/>,</g, "><");
53
- } catch (e) {
54
- console.log("error", e);
55
- }
56
- };
@@ -1,4 +0,0 @@
1
- // This is a fix of typescript module import error
2
- import slugify from "slugify";
3
-
4
- export default slugify as unknown as typeof slugify.default;
@@ -1,11 +0,0 @@
1
- import slugify from "./slugifyImport.js";
2
-
3
- export const slugifyTitle = (title: string) => {
4
- return slugify(title, {
5
- replacement: "-",
6
- remove: /[*+~.()'"!:@]/g,
7
- lower: true,
8
- locale: "vi",
9
- trim: true,
10
- });
11
- };
package/tsconfig.json DELETED
@@ -1,17 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "esModuleInterop": true,
4
- "skipLibCheck": true,
5
- "target": "es2022",
6
- "allowJs": true,
7
- "resolveJsonModule": true,
8
- "moduleDetection": "force",
9
- "strict": true,
10
- "noUncheckedIndexedAccess": true,
11
- "moduleResolution": "Bundler",
12
- "module": "ESNext",
13
- "lib": ["es2022", "dom", "dom.iterable"],
14
- "jsx": "react",
15
- "noEmit": true
16
- }
17
- }