@rulab/adminjs-components 0.1.0-alpha.10 → 0.1.0-alpha.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/components/Slug/SlugEdit.js +7 -1
- package/dist/components/Slug/SlugFeature.d.ts +2 -5
- package/dist/components/Slug/SlugFeature.js +11 -13
- package/dist/components/Slug/SlugOptions.type.d.ts +7 -0
- package/dist/components/Slug/SlugOptions.type.js +1 -0
- package/dist/utils/bundle-component.js +1 -1
- package/package.json +1 -1
- package/src/components/Slug/SlugEdit.tsx +15 -3
- package/src/components/Slug/SlugFeature.ts +13 -17
- package/src/components/Slug/SlugOptions.type.ts +9 -0
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
import { flat } from "adminjs";
|
|
1
2
|
import React, { useEffect, useState, } from "react";
|
|
2
3
|
import { ThemeProvider } from "styled-components";
|
|
3
4
|
import { theme } from "@adminjs/design-system";
|
|
4
5
|
import { slugifyTitle } from "../../utils/index.js";
|
|
5
6
|
import { StyledCustomInput, StyledGenerateButton, StyledInputWrapper, StyledLabel, } from "./styles.js";
|
|
6
7
|
const SlugEdit = ({ property, record, resource, onChange, }) => {
|
|
7
|
-
|
|
8
|
+
console.log("✅ SlugEdit loaded", { property });
|
|
9
|
+
const { params } = record;
|
|
10
|
+
const { custom } = property;
|
|
11
|
+
const source = flat.get(params, custom.source);
|
|
12
|
+
const key = flat.get(params, custom.key);
|
|
13
|
+
const [inputValue, setInputValue] = useState(key);
|
|
8
14
|
useEffect(() => {
|
|
9
15
|
onChange(property.path, inputValue);
|
|
10
16
|
}, [inputValue]);
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
componentLoader: ComponentLoader;
|
|
4
|
-
key: string;
|
|
5
|
-
};
|
|
1
|
+
import { FeatureType } from "adminjs";
|
|
2
|
+
import SlugOptions from "./SlugOptions.type";
|
|
6
3
|
declare const SlugFeature: (config: SlugOptions) => FeatureType;
|
|
7
4
|
export default SlugFeature;
|
|
@@ -2,20 +2,18 @@ import { buildFeature } from "adminjs";
|
|
|
2
2
|
import { bundleComponent } from "../../utils/bundle-component.js";
|
|
3
3
|
const COMPONENT_NAME = 'Slug';
|
|
4
4
|
const SlugFeature = (config) => {
|
|
5
|
-
const { componentLoader, key } = config;
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
edit: editComponent,
|
|
14
|
-
},
|
|
5
|
+
const { componentLoader, source, key } = config;
|
|
6
|
+
const editComponent = bundleComponent(componentLoader, COMPONENT_NAME, 'SlugEdit');
|
|
7
|
+
return buildFeature({
|
|
8
|
+
properties: {
|
|
9
|
+
[key]: {
|
|
10
|
+
isVisible: { filter: true, show: true, edit: true, list: true },
|
|
11
|
+
components: {
|
|
12
|
+
edit: editComponent,
|
|
15
13
|
},
|
|
14
|
+
custom: { source, key }
|
|
16
15
|
},
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
return slugFeature();
|
|
16
|
+
},
|
|
17
|
+
});
|
|
20
18
|
};
|
|
21
19
|
export default SlugFeature;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -4,5 +4,5 @@ const dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
|
4
4
|
export const bundleComponent = (loader, componentName, componentFile) => {
|
|
5
5
|
const componentPath = path.join(dirname, '../components', componentName, componentFile);
|
|
6
6
|
console.log('[bundleComponent] Registering:', componentPath);
|
|
7
|
-
return loader.add(
|
|
7
|
+
return loader.add(componentFile, componentPath);
|
|
8
8
|
};
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {EditPropertyProps, flat} from "adminjs";
|
|
2
2
|
import React, {
|
|
3
3
|
ChangeEvent,
|
|
4
4
|
FC,
|
|
@@ -17,7 +17,8 @@ import {
|
|
|
17
17
|
StyledGenerateButton,
|
|
18
18
|
StyledInputWrapper,
|
|
19
19
|
StyledLabel,
|
|
20
|
-
} from "./styles
|
|
20
|
+
} from "./styles";
|
|
21
|
+
import SlugOptions from "./SlugOptions.type";
|
|
21
22
|
|
|
22
23
|
type CustomSlugTypes = Omit<EditPropertyProps, "where">;
|
|
23
24
|
|
|
@@ -27,7 +28,18 @@ const SlugEdit: FC<CustomSlugTypes> = ({
|
|
|
27
28
|
resource,
|
|
28
29
|
onChange,
|
|
29
30
|
}) => {
|
|
30
|
-
|
|
31
|
+
console.log("✅ SlugEdit loaded", { property });
|
|
32
|
+
type SlugCustomProperty = {
|
|
33
|
+
source: string,
|
|
34
|
+
key: string
|
|
35
|
+
}
|
|
36
|
+
const { params } = record
|
|
37
|
+
const { custom } = property as unknown as { custom: SlugCustomProperty }
|
|
38
|
+
|
|
39
|
+
const source = flat.get(params, custom.source)
|
|
40
|
+
const key = flat.get(params, custom.key)
|
|
41
|
+
|
|
42
|
+
const [inputValue, setInputValue] = useState(key);
|
|
31
43
|
|
|
32
44
|
useEffect(() => {
|
|
33
45
|
onChange(property.path, inputValue);
|
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
import {buildFeature, ComponentLoader, FeatureType} from "adminjs";
|
|
2
2
|
import {bundleComponent} from "../../utils/bundle-component";
|
|
3
|
+
import SlugOptions from "./SlugOptions.type";
|
|
3
4
|
|
|
4
5
|
const COMPONENT_NAME = 'Slug'
|
|
5
6
|
|
|
6
|
-
type SlugOptions = {
|
|
7
|
-
componentLoader: ComponentLoader
|
|
8
|
-
key: string
|
|
9
|
-
}
|
|
10
7
|
const SlugFeature = (config: SlugOptions): FeatureType => {
|
|
11
|
-
const {componentLoader,key} = config
|
|
8
|
+
const {componentLoader,source,key} = config
|
|
9
|
+
|
|
10
|
+
const editComponent = bundleComponent(componentLoader, COMPONENT_NAME, 'SlugEdit')
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
components: {
|
|
20
|
-
edit: editComponent,
|
|
21
|
-
},
|
|
12
|
+
return buildFeature({
|
|
13
|
+
properties: {
|
|
14
|
+
[key]: {
|
|
15
|
+
isVisible: { filter: true, show: true, edit: true, list: true },
|
|
16
|
+
components: {
|
|
17
|
+
edit: editComponent,
|
|
22
18
|
},
|
|
19
|
+
custom: {source,key}
|
|
23
20
|
},
|
|
24
|
-
}
|
|
25
|
-
}
|
|
21
|
+
},
|
|
22
|
+
})
|
|
26
23
|
|
|
27
|
-
return slugFeature()
|
|
28
24
|
}
|
|
29
25
|
|
|
30
26
|
export default SlugFeature
|