@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.
@@ -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
- const [inputValue, setInputValue] = useState(record.params.slug);
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 { ComponentLoader, FeatureType } from "adminjs";
2
- type SlugOptions = {
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 slugFeature = () => {
7
- const editComponent = bundleComponent(componentLoader, COMPONENT_NAME, 'SlugEdit.js');
8
- return buildFeature({
9
- properties: {
10
- [key]: {
11
- isVisible: { show: false, edit: true, list: false, filter: false },
12
- components: {
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,7 @@
1
+ import { ComponentLoader } from "adminjs";
2
+ type SlugOptions = {
3
+ componentLoader: ComponentLoader;
4
+ source: string;
5
+ key: string;
6
+ };
7
+ export default SlugOptions;
@@ -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(componentName, componentPath);
7
+ return loader.add(componentFile, componentPath);
8
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulab/adminjs-components",
3
- "version": "0.1.0-alpha.10",
3
+ "version": "0.1.0-alpha.12",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -1,4 +1,4 @@
1
- import { EditPropertyProps } from "adminjs";
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.js";
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
- const [inputValue, setInputValue] = useState(record.params.slug);
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
- const slugFeature = () => {
14
- const editComponent = bundleComponent(componentLoader, COMPONENT_NAME, 'SlugEdit.js')
15
- return buildFeature({
16
- properties: {
17
- [key]: {
18
- isVisible: { show: false, edit: true, list: false, filter: false },
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
@@ -0,0 +1,9 @@
1
+ import {ComponentLoader} from "adminjs";
2
+
3
+ type SlugOptions = {
4
+ componentLoader: ComponentLoader
5
+ source: string
6
+ key: string
7
+ }
8
+
9
+ export default SlugOptions