imean-service-engine-htmx-plugin 2.1.1 → 2.2.0

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.d.mts CHANGED
@@ -105,9 +105,20 @@ interface ModelField {
105
105
  value: string | number;
106
106
  label: string;
107
107
  }>;
108
+ /** HTML input step 属性(用于 number 类型,支持小数) */
109
+ step?: string | number;
108
110
  /** 原始 Zod Schema(用于验证等) */
109
111
  schema: any;
110
112
  }
113
+ /**
114
+ * 字段分组配置
115
+ */
116
+ interface FieldGroup {
117
+ /** 分组标签 */
118
+ label: string;
119
+ /** 该分组包含的字段名列表 */
120
+ fields: string[];
121
+ }
111
122
  /**
112
123
  * Feature 类型
113
124
  */
@@ -316,6 +327,21 @@ interface FormField {
316
327
  value: string | number;
317
328
  label: string;
318
329
  }>;
330
+ /** HTML input step 属性(用于 number 类型,支持小数) */
331
+ step?: string | number;
332
+ }
333
+ /**
334
+ * 表单字段渲染器属性
335
+ */
336
+ interface FormFieldRendererProps<T = any> {
337
+ /** 字段定义 */
338
+ field: FormField;
339
+ /** 当前值(已解析的对象/数组,不是 JSON 字符串) */
340
+ value: any;
341
+ /** 完整的初始数据 */
342
+ initialData?: Partial<T>;
343
+ /** 字段名(用于更新隐藏字段) */
344
+ fieldName: string;
319
345
  }
320
346
 
321
347
  /**
@@ -458,11 +484,6 @@ declare abstract class BaseFeature implements Feature {
458
484
  render?(context: FeatureContext): Promise<any>;
459
485
  }
460
486
 
461
- /**
462
- * 表单 Feature 基类
463
- * 提供创建和编辑 Feature 的公共逻辑
464
- */
465
-
466
487
  /**
467
488
  * 表单操作类型
468
489
  */
@@ -478,6 +499,8 @@ declare abstract class BaseFormFeature<T extends {
478
499
  protected descriptionGetter?: (context: FeatureContext, item?: T) => string | Promise<string> | undefined;
479
500
  /** 当前请求的表单 ID(用于在 render 和 getActions 之间共享) */
480
501
  private currentFormId?;
502
+ /** 自定义表单字段渲染器 */
503
+ protected formFieldRenderers?: Record<string, (props: FormFieldRendererProps<T>) => any>;
481
504
  /**
482
505
  * 获取或生成表单 ID(确保在同一个请求中保持一致)
483
506
  */
@@ -533,6 +556,7 @@ declare abstract class BaseFormFeature<T extends {
533
556
  */
534
557
  handle(context: FeatureContext): Promise<any>;
535
558
  protected formFieldNames?: string[];
559
+ protected groups?: FieldGroup[];
536
560
  /**
537
561
  * 渲染表单页面
538
562
  */
@@ -583,10 +607,6 @@ declare class CustomFeature extends BaseFeature {
583
607
  render(context: FeatureContext): Promise<any>;
584
608
  }
585
609
 
586
- /**
587
- * 默认创建 Feature
588
- */
589
-
590
610
  /**
591
611
  * 默认创建 Feature
592
612
  * 类型通过 schema 的 z.infer 推断
@@ -609,6 +629,10 @@ declare class DefaultCreateFeature<T extends {
609
629
  getDescription?: (context: FeatureContext) => string | Promise<string> | undefined;
610
630
  /** 表单字段名(可选,不提供则显示 schema 中的所有字段) */
611
631
  formFieldNames?: string[];
632
+ /** 字段分组配置(可选,用于将字段分组展示为 Tab) */
633
+ groups?: FieldGroup[];
634
+ /** 自定义表单字段渲染器 */
635
+ formFieldRenderers?: Record<string, (props: FormFieldRendererProps<T>) => any>;
612
636
  });
613
637
  getFormAction(): "create";
614
638
  getRoutes(): ({
@@ -665,6 +689,8 @@ declare class DefaultDetailFeature<T extends {
665
689
  private titleGetter?;
666
690
  private descriptionGetter?;
667
691
  private detailFieldNames?;
692
+ private fieldRenderers?;
693
+ private groups?;
668
694
  constructor(options: {
669
695
  /** 详情数据的 Schema(用于字段推断和显示) */
670
696
  schema: z.ZodObject<any>;
@@ -680,6 +706,10 @@ declare class DefaultDetailFeature<T extends {
680
706
  getDescription?: (item: T, context: FeatureContext) => string | Promise<string> | undefined;
681
707
  /** 详情显示字段名(可选,不提供则显示 schema 中的所有字段) */
682
708
  detailFieldNames?: string[];
709
+ /** 自定义字段渲染函数(可选,key 为字段名,value 为渲染函数) */
710
+ fieldRenderers?: Record<string, (value: any, item: T) => any>;
711
+ /** 字段分组配置(可选,用于将字段分组展示为卡片) */
712
+ groups?: FieldGroup[];
683
713
  });
684
714
  getTitle(context: FeatureContext): Promise<string>;
685
715
  getDescription(context: FeatureContext): Promise<string | undefined>;
@@ -691,10 +721,6 @@ declare class DefaultDetailFeature<T extends {
691
721
  getActions(context: FeatureContext): Promise<ActionButton[]>;
692
722
  }
693
723
 
694
- /**
695
- * 默认编辑 Feature
696
- */
697
-
698
724
  /**
699
725
  * 默认编辑 Feature
700
726
  * 类型通过 schema 的 z.infer 推断
@@ -719,6 +745,10 @@ declare class DefaultEditFeature<T extends {
719
745
  getDescription?: (item: T, context: FeatureContext) => string | Promise<string> | undefined;
720
746
  /** 表单字段名(可选,不提供则显示 schema 中的所有字段) */
721
747
  formFieldNames?: string[];
748
+ /** 字段分组配置(可选,用于将字段分组展示为 Tab) */
749
+ groups?: FieldGroup[];
750
+ /** 自定义表单字段渲染器 */
751
+ formFieldRenderers?: Record<string, (props: FormFieldRendererProps<T>) => any>;
722
752
  });
723
753
  getFormAction(): "edit";
724
754
  getRoutes(): ({
@@ -829,6 +859,70 @@ declare class HtmxAdminPlugin implements Plugin {
829
859
  */
830
860
  declare function getUserInfo(ctx: Context, authProvider?: AuthProvider): Promise<UserInfo | null>;
831
861
 
862
+ /**
863
+ * 表单字段渲染器的 Alpine.js x-data 工具函数
864
+ * 提供统一的模式,简化自定义表单字段渲染器的开发
865
+ */
866
+ interface FormFieldXDataOptions {
867
+ /** 字段名(用于更新隐藏字段) */
868
+ fieldName: string;
869
+ /** 数据对象的键名(如 'banners', 'items' 等) */
870
+ dataKey: string;
871
+ /** 默认值(如 [] 或 {}) */
872
+ defaultValue?: any;
873
+ /** 额外的数据属性 */
874
+ customData?: Record<string, any>;
875
+ /** 自定义方法(方法名 -> 方法体字符串) */
876
+ customMethods?: Record<string, string>;
877
+ /** 是否使用 x-effect 自动同步(默认 false,需要在方法中手动调用 updateHiddenField) */
878
+ autoSync?: boolean;
879
+ }
880
+ /**
881
+ * 创建表单字段的 Alpine.js x-data 字符串
882
+ *
883
+ * @example
884
+ * ```tsx
885
+ * const xData = createFormFieldXData({
886
+ * fieldName: 'banners',
887
+ * dataKey: 'banners',
888
+ * defaultValue: [],
889
+ * customMethods: {
890
+ * addBanner() {
891
+ * this.banners.push({ url: '', alt: '', order: this.banners.length });
892
+ * this.updateHiddenField();
893
+ * },
894
+ * removeBanner(index) {
895
+ * this.banners.splice(index, 1);
896
+ * this.updateHiddenField();
897
+ * }
898
+ * }
899
+ * });
900
+ * ```
901
+ */
902
+ declare function createFormFieldXData(options: FormFieldXDataOptions): string;
903
+ /**
904
+ * 表单字段渲染器包装器组件的属性
905
+ */
906
+ interface FormFieldWrapperProps {
907
+ /** 字段名 */
908
+ fieldName: string;
909
+ /** 初始值(会被序列化为 JSON) */
910
+ initialValue: any;
911
+ /** x-data 字符串 */
912
+ xData: string;
913
+ /** 是否使用 x-effect 自动同步 */
914
+ autoSync?: boolean;
915
+ /** 子元素(组件 UI) */
916
+ children: any;
917
+ /** 额外的 className */
918
+ className?: string;
919
+ }
920
+ /**
921
+ * 表单字段渲染器包装器组件
922
+ * 自动处理隐藏字段、x-data、data-initial-value 等固定模式
923
+ */
924
+ declare function FormFieldWrapper(props: FormFieldWrapperProps): hono_jsx_jsx_dev_runtime.JSX.Element;
925
+
832
926
  /**
833
927
  * 参数解析工具函数
834
928
  */
@@ -875,6 +969,8 @@ interface DialogProps {
875
969
  closeOnBackdropClick?: boolean;
876
970
  /** 操作按钮(在 Footer 中显示,固定在底部) */
877
971
  actions?: ActionButton[];
972
+ /** 是否固定内容区域高度(用于表单等需要固定高度的场景,避免切换 Tab 时高度变化) */
973
+ fixedContentHeight?: boolean;
878
974
  }
879
975
  declare function Dialog(props: DialogProps): hono_jsx_jsx_dev_runtime.JSX.Element;
880
976
 
@@ -908,4 +1004,4 @@ declare function ErrorAlert(props: ErrorAlertProps): hono_jsx_jsx_dev_runtime.JS
908
1004
  */
909
1005
  declare function LoadingBar(): hono_jsx_jsx_dev_runtime.JSX.Element;
910
1006
 
911
- export { type AuthProvider, BaseFeature, CustomFeature, DefaultCreateFeature, DefaultDeleteFeature, DefaultDetailFeature, DefaultEditFeature, DefaultListFeature, Dialog, type DialogProps, type DialogSize, ErrorAlert, type ErrorAlertProps, type Feature, type FeatureContext, type FeatureType, type FieldMetadata, HtmxAdminPlugin, type HtmxAdminPluginOptions, type ListParams, type ListResult, LoadingBar, type NavItemConfig, type Notification, type NotificationType$1 as NotificationType, type PageMetadata, PageModel, type PermissionResult, type UserInfo, checkUserPermission, getUserInfo, modelNameToPath, parseListParams };
1007
+ export { type AuthProvider, BaseFeature, CustomFeature, DefaultCreateFeature, DefaultDeleteFeature, DefaultDetailFeature, DefaultEditFeature, DefaultListFeature, Dialog, type DialogProps, type DialogSize, ErrorAlert, type ErrorAlertProps, type Feature, type FeatureContext, type FeatureType, type FieldMetadata, FormFieldWrapper, HtmxAdminPlugin, type HtmxAdminPluginOptions, type ListParams, type ListResult, LoadingBar, type NavItemConfig, type Notification, type NotificationType$1 as NotificationType, type PageMetadata, PageModel, type PermissionResult, type UserInfo, checkUserPermission, createFormFieldXData, getUserInfo, modelNameToPath, parseListParams };
package/dist/index.d.ts CHANGED
@@ -105,9 +105,20 @@ interface ModelField {
105
105
  value: string | number;
106
106
  label: string;
107
107
  }>;
108
+ /** HTML input step 属性(用于 number 类型,支持小数) */
109
+ step?: string | number;
108
110
  /** 原始 Zod Schema(用于验证等) */
109
111
  schema: any;
110
112
  }
113
+ /**
114
+ * 字段分组配置
115
+ */
116
+ interface FieldGroup {
117
+ /** 分组标签 */
118
+ label: string;
119
+ /** 该分组包含的字段名列表 */
120
+ fields: string[];
121
+ }
111
122
  /**
112
123
  * Feature 类型
113
124
  */
@@ -316,6 +327,21 @@ interface FormField {
316
327
  value: string | number;
317
328
  label: string;
318
329
  }>;
330
+ /** HTML input step 属性(用于 number 类型,支持小数) */
331
+ step?: string | number;
332
+ }
333
+ /**
334
+ * 表单字段渲染器属性
335
+ */
336
+ interface FormFieldRendererProps<T = any> {
337
+ /** 字段定义 */
338
+ field: FormField;
339
+ /** 当前值(已解析的对象/数组,不是 JSON 字符串) */
340
+ value: any;
341
+ /** 完整的初始数据 */
342
+ initialData?: Partial<T>;
343
+ /** 字段名(用于更新隐藏字段) */
344
+ fieldName: string;
319
345
  }
320
346
 
321
347
  /**
@@ -458,11 +484,6 @@ declare abstract class BaseFeature implements Feature {
458
484
  render?(context: FeatureContext): Promise<any>;
459
485
  }
460
486
 
461
- /**
462
- * 表单 Feature 基类
463
- * 提供创建和编辑 Feature 的公共逻辑
464
- */
465
-
466
487
  /**
467
488
  * 表单操作类型
468
489
  */
@@ -478,6 +499,8 @@ declare abstract class BaseFormFeature<T extends {
478
499
  protected descriptionGetter?: (context: FeatureContext, item?: T) => string | Promise<string> | undefined;
479
500
  /** 当前请求的表单 ID(用于在 render 和 getActions 之间共享) */
480
501
  private currentFormId?;
502
+ /** 自定义表单字段渲染器 */
503
+ protected formFieldRenderers?: Record<string, (props: FormFieldRendererProps<T>) => any>;
481
504
  /**
482
505
  * 获取或生成表单 ID(确保在同一个请求中保持一致)
483
506
  */
@@ -533,6 +556,7 @@ declare abstract class BaseFormFeature<T extends {
533
556
  */
534
557
  handle(context: FeatureContext): Promise<any>;
535
558
  protected formFieldNames?: string[];
559
+ protected groups?: FieldGroup[];
536
560
  /**
537
561
  * 渲染表单页面
538
562
  */
@@ -583,10 +607,6 @@ declare class CustomFeature extends BaseFeature {
583
607
  render(context: FeatureContext): Promise<any>;
584
608
  }
585
609
 
586
- /**
587
- * 默认创建 Feature
588
- */
589
-
590
610
  /**
591
611
  * 默认创建 Feature
592
612
  * 类型通过 schema 的 z.infer 推断
@@ -609,6 +629,10 @@ declare class DefaultCreateFeature<T extends {
609
629
  getDescription?: (context: FeatureContext) => string | Promise<string> | undefined;
610
630
  /** 表单字段名(可选,不提供则显示 schema 中的所有字段) */
611
631
  formFieldNames?: string[];
632
+ /** 字段分组配置(可选,用于将字段分组展示为 Tab) */
633
+ groups?: FieldGroup[];
634
+ /** 自定义表单字段渲染器 */
635
+ formFieldRenderers?: Record<string, (props: FormFieldRendererProps<T>) => any>;
612
636
  });
613
637
  getFormAction(): "create";
614
638
  getRoutes(): ({
@@ -665,6 +689,8 @@ declare class DefaultDetailFeature<T extends {
665
689
  private titleGetter?;
666
690
  private descriptionGetter?;
667
691
  private detailFieldNames?;
692
+ private fieldRenderers?;
693
+ private groups?;
668
694
  constructor(options: {
669
695
  /** 详情数据的 Schema(用于字段推断和显示) */
670
696
  schema: z.ZodObject<any>;
@@ -680,6 +706,10 @@ declare class DefaultDetailFeature<T extends {
680
706
  getDescription?: (item: T, context: FeatureContext) => string | Promise<string> | undefined;
681
707
  /** 详情显示字段名(可选,不提供则显示 schema 中的所有字段) */
682
708
  detailFieldNames?: string[];
709
+ /** 自定义字段渲染函数(可选,key 为字段名,value 为渲染函数) */
710
+ fieldRenderers?: Record<string, (value: any, item: T) => any>;
711
+ /** 字段分组配置(可选,用于将字段分组展示为卡片) */
712
+ groups?: FieldGroup[];
683
713
  });
684
714
  getTitle(context: FeatureContext): Promise<string>;
685
715
  getDescription(context: FeatureContext): Promise<string | undefined>;
@@ -691,10 +721,6 @@ declare class DefaultDetailFeature<T extends {
691
721
  getActions(context: FeatureContext): Promise<ActionButton[]>;
692
722
  }
693
723
 
694
- /**
695
- * 默认编辑 Feature
696
- */
697
-
698
724
  /**
699
725
  * 默认编辑 Feature
700
726
  * 类型通过 schema 的 z.infer 推断
@@ -719,6 +745,10 @@ declare class DefaultEditFeature<T extends {
719
745
  getDescription?: (item: T, context: FeatureContext) => string | Promise<string> | undefined;
720
746
  /** 表单字段名(可选,不提供则显示 schema 中的所有字段) */
721
747
  formFieldNames?: string[];
748
+ /** 字段分组配置(可选,用于将字段分组展示为 Tab) */
749
+ groups?: FieldGroup[];
750
+ /** 自定义表单字段渲染器 */
751
+ formFieldRenderers?: Record<string, (props: FormFieldRendererProps<T>) => any>;
722
752
  });
723
753
  getFormAction(): "edit";
724
754
  getRoutes(): ({
@@ -829,6 +859,70 @@ declare class HtmxAdminPlugin implements Plugin {
829
859
  */
830
860
  declare function getUserInfo(ctx: Context, authProvider?: AuthProvider): Promise<UserInfo | null>;
831
861
 
862
+ /**
863
+ * 表单字段渲染器的 Alpine.js x-data 工具函数
864
+ * 提供统一的模式,简化自定义表单字段渲染器的开发
865
+ */
866
+ interface FormFieldXDataOptions {
867
+ /** 字段名(用于更新隐藏字段) */
868
+ fieldName: string;
869
+ /** 数据对象的键名(如 'banners', 'items' 等) */
870
+ dataKey: string;
871
+ /** 默认值(如 [] 或 {}) */
872
+ defaultValue?: any;
873
+ /** 额外的数据属性 */
874
+ customData?: Record<string, any>;
875
+ /** 自定义方法(方法名 -> 方法体字符串) */
876
+ customMethods?: Record<string, string>;
877
+ /** 是否使用 x-effect 自动同步(默认 false,需要在方法中手动调用 updateHiddenField) */
878
+ autoSync?: boolean;
879
+ }
880
+ /**
881
+ * 创建表单字段的 Alpine.js x-data 字符串
882
+ *
883
+ * @example
884
+ * ```tsx
885
+ * const xData = createFormFieldXData({
886
+ * fieldName: 'banners',
887
+ * dataKey: 'banners',
888
+ * defaultValue: [],
889
+ * customMethods: {
890
+ * addBanner() {
891
+ * this.banners.push({ url: '', alt: '', order: this.banners.length });
892
+ * this.updateHiddenField();
893
+ * },
894
+ * removeBanner(index) {
895
+ * this.banners.splice(index, 1);
896
+ * this.updateHiddenField();
897
+ * }
898
+ * }
899
+ * });
900
+ * ```
901
+ */
902
+ declare function createFormFieldXData(options: FormFieldXDataOptions): string;
903
+ /**
904
+ * 表单字段渲染器包装器组件的属性
905
+ */
906
+ interface FormFieldWrapperProps {
907
+ /** 字段名 */
908
+ fieldName: string;
909
+ /** 初始值(会被序列化为 JSON) */
910
+ initialValue: any;
911
+ /** x-data 字符串 */
912
+ xData: string;
913
+ /** 是否使用 x-effect 自动同步 */
914
+ autoSync?: boolean;
915
+ /** 子元素(组件 UI) */
916
+ children: any;
917
+ /** 额外的 className */
918
+ className?: string;
919
+ }
920
+ /**
921
+ * 表单字段渲染器包装器组件
922
+ * 自动处理隐藏字段、x-data、data-initial-value 等固定模式
923
+ */
924
+ declare function FormFieldWrapper(props: FormFieldWrapperProps): hono_jsx_jsx_dev_runtime.JSX.Element;
925
+
832
926
  /**
833
927
  * 参数解析工具函数
834
928
  */
@@ -875,6 +969,8 @@ interface DialogProps {
875
969
  closeOnBackdropClick?: boolean;
876
970
  /** 操作按钮(在 Footer 中显示,固定在底部) */
877
971
  actions?: ActionButton[];
972
+ /** 是否固定内容区域高度(用于表单等需要固定高度的场景,避免切换 Tab 时高度变化) */
973
+ fixedContentHeight?: boolean;
878
974
  }
879
975
  declare function Dialog(props: DialogProps): hono_jsx_jsx_dev_runtime.JSX.Element;
880
976
 
@@ -908,4 +1004,4 @@ declare function ErrorAlert(props: ErrorAlertProps): hono_jsx_jsx_dev_runtime.JS
908
1004
  */
909
1005
  declare function LoadingBar(): hono_jsx_jsx_dev_runtime.JSX.Element;
910
1006
 
911
- export { type AuthProvider, BaseFeature, CustomFeature, DefaultCreateFeature, DefaultDeleteFeature, DefaultDetailFeature, DefaultEditFeature, DefaultListFeature, Dialog, type DialogProps, type DialogSize, ErrorAlert, type ErrorAlertProps, type Feature, type FeatureContext, type FeatureType, type FieldMetadata, HtmxAdminPlugin, type HtmxAdminPluginOptions, type ListParams, type ListResult, LoadingBar, type NavItemConfig, type Notification, type NotificationType$1 as NotificationType, type PageMetadata, PageModel, type PermissionResult, type UserInfo, checkUserPermission, getUserInfo, modelNameToPath, parseListParams };
1007
+ export { type AuthProvider, BaseFeature, CustomFeature, DefaultCreateFeature, DefaultDeleteFeature, DefaultDetailFeature, DefaultEditFeature, DefaultListFeature, Dialog, type DialogProps, type DialogSize, ErrorAlert, type ErrorAlertProps, type Feature, type FeatureContext, type FeatureType, type FieldMetadata, FormFieldWrapper, HtmxAdminPlugin, type HtmxAdminPluginOptions, type ListParams, type ListResult, LoadingBar, type NavItemConfig, type Notification, type NotificationType$1 as NotificationType, type PageMetadata, PageModel, type PermissionResult, type UserInfo, checkUserPermission, createFormFieldXData, getUserInfo, modelNameToPath, parseListParams };