imean-service-engine-htmx-plugin 2.1.1 → 2.3.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
@@ -2,6 +2,7 @@ import { Context } from 'hono';
2
2
  import { z } from 'zod';
3
3
  import { Plugin, PluginPriority, Microservice } from 'imean-service-engine';
4
4
  import * as hono_jsx_jsx_dev_runtime from 'hono/jsx/jsx-dev-runtime';
5
+ import * as hono_utils_html from 'hono/utils/html';
5
6
 
6
7
  /**
7
8
  * HtmxAdminPlugin 核心类型定义
@@ -39,11 +40,17 @@ interface ActionButton {
39
40
  onClick?: string;
40
41
  /** 自定义类名 */
41
42
  className?: string;
43
+ /** 链接目标(如 "_blank" 表示新窗口打开) */
44
+ target?: string;
42
45
  }
43
46
  /**
44
47
  * 对话框大小类型
45
48
  */
46
49
  type DialogSize = "sm" | "md" | "lg" | "xl" | "full";
50
+ /**
51
+ * 打开方式类型
52
+ */
53
+ type OpenMode = "dialog" | "page" | "newWindow";
47
54
  /**
48
55
  * 页面元数据配置
49
56
  */
@@ -105,9 +112,20 @@ interface ModelField {
105
112
  value: string | number;
106
113
  label: string;
107
114
  }>;
115
+ /** HTML input step 属性(用于 number 类型,支持小数) */
116
+ step?: string | number;
108
117
  /** 原始 Zod Schema(用于验证等) */
109
118
  schema: any;
110
119
  }
120
+ /**
121
+ * 字段分组配置
122
+ */
123
+ interface FieldGroup {
124
+ /** 分组标签 */
125
+ label: string;
126
+ /** 该分组包含的字段名列表 */
127
+ fields: string[];
128
+ }
111
129
  /**
112
130
  * Feature 类型
113
131
  */
@@ -316,6 +334,21 @@ interface FormField {
316
334
  value: string | number;
317
335
  label: string;
318
336
  }>;
337
+ /** HTML input step 属性(用于 number 类型,支持小数) */
338
+ step?: string | number;
339
+ }
340
+ /**
341
+ * 表单字段渲染器属性
342
+ */
343
+ interface FormFieldRendererProps<T = any> {
344
+ /** 字段定义 */
345
+ field: FormField;
346
+ /** 当前值(已解析的对象/数组,不是 JSON 字符串) */
347
+ value: any;
348
+ /** 完整的初始数据 */
349
+ initialData?: Partial<T>;
350
+ /** 字段名(用于更新隐藏字段) */
351
+ fieldName: string;
319
352
  }
320
353
 
321
354
  /**
@@ -458,11 +491,6 @@ declare abstract class BaseFeature implements Feature {
458
491
  render?(context: FeatureContext): Promise<any>;
459
492
  }
460
493
 
461
- /**
462
- * 表单 Feature 基类
463
- * 提供创建和编辑 Feature 的公共逻辑
464
- */
465
-
466
494
  /**
467
495
  * 表单操作类型
468
496
  */
@@ -478,6 +506,8 @@ declare abstract class BaseFormFeature<T extends {
478
506
  protected descriptionGetter?: (context: FeatureContext, item?: T) => string | Promise<string> | undefined;
479
507
  /** 当前请求的表单 ID(用于在 render 和 getActions 之间共享) */
480
508
  private currentFormId?;
509
+ /** 自定义表单字段渲染器 */
510
+ protected formFieldRenderers?: Record<string, (props: FormFieldRendererProps<T>) => any>;
481
511
  /**
482
512
  * 获取或生成表单 ID(确保在同一个请求中保持一致)
483
513
  */
@@ -533,6 +563,7 @@ declare abstract class BaseFormFeature<T extends {
533
563
  */
534
564
  handle(context: FeatureContext): Promise<any>;
535
565
  protected formFieldNames?: string[];
566
+ protected groups?: FieldGroup[];
536
567
  /**
537
568
  * 渲染表单页面
538
569
  */
@@ -583,10 +614,6 @@ declare class CustomFeature extends BaseFeature {
583
614
  render(context: FeatureContext): Promise<any>;
584
615
  }
585
616
 
586
- /**
587
- * 默认创建 Feature
588
- */
589
-
590
617
  /**
591
618
  * 默认创建 Feature
592
619
  * 类型通过 schema 的 z.infer 推断
@@ -609,6 +636,10 @@ declare class DefaultCreateFeature<T extends {
609
636
  getDescription?: (context: FeatureContext) => string | Promise<string> | undefined;
610
637
  /** 表单字段名(可选,不提供则显示 schema 中的所有字段) */
611
638
  formFieldNames?: string[];
639
+ /** 字段分组配置(可选,用于将字段分组展示为 Tab) */
640
+ groups?: FieldGroup[];
641
+ /** 自定义表单字段渲染器 */
642
+ formFieldRenderers?: Record<string, (props: FormFieldRendererProps<T>) => any>;
612
643
  });
613
644
  getFormAction(): "create";
614
645
  getRoutes(): ({
@@ -665,6 +696,8 @@ declare class DefaultDetailFeature<T extends {
665
696
  private titleGetter?;
666
697
  private descriptionGetter?;
667
698
  private detailFieldNames?;
699
+ private fieldRenderers?;
700
+ private groups?;
668
701
  constructor(options: {
669
702
  /** 详情数据的 Schema(用于字段推断和显示) */
670
703
  schema: z.ZodObject<any>;
@@ -680,6 +713,10 @@ declare class DefaultDetailFeature<T extends {
680
713
  getDescription?: (item: T, context: FeatureContext) => string | Promise<string> | undefined;
681
714
  /** 详情显示字段名(可选,不提供则显示 schema 中的所有字段) */
682
715
  detailFieldNames?: string[];
716
+ /** 自定义字段渲染函数(可选,key 为字段名,value 为渲染函数) */
717
+ fieldRenderers?: Record<string, (value: any, item: T) => any>;
718
+ /** 字段分组配置(可选,用于将字段分组展示为卡片) */
719
+ groups?: FieldGroup[];
683
720
  });
684
721
  getTitle(context: FeatureContext): Promise<string>;
685
722
  getDescription(context: FeatureContext): Promise<string | undefined>;
@@ -691,10 +728,6 @@ declare class DefaultDetailFeature<T extends {
691
728
  getActions(context: FeatureContext): Promise<ActionButton[]>;
692
729
  }
693
730
 
694
- /**
695
- * 默认编辑 Feature
696
- */
697
-
698
731
  /**
699
732
  * 默认编辑 Feature
700
733
  * 类型通过 schema 的 z.infer 推断
@@ -719,6 +752,10 @@ declare class DefaultEditFeature<T extends {
719
752
  getDescription?: (item: T, context: FeatureContext) => string | Promise<string> | undefined;
720
753
  /** 表单字段名(可选,不提供则显示 schema 中的所有字段) */
721
754
  formFieldNames?: string[];
755
+ /** 字段分组配置(可选,用于将字段分组展示为 Tab) */
756
+ groups?: FieldGroup[];
757
+ /** 自定义表单字段渲染器 */
758
+ formFieldRenderers?: Record<string, (props: FormFieldRendererProps<T>) => any>;
722
759
  });
723
760
  getFormAction(): "edit";
724
761
  getRoutes(): ({
@@ -755,6 +792,7 @@ declare class DefaultListFeature<T extends {
755
792
  private listFieldNames?;
756
793
  private filterSchema?;
757
794
  private columnRenderers?;
795
+ private openMode?;
758
796
  constructor(options: {
759
797
  /** 列表数据的 Schema(用于字段推断和显示) */
760
798
  schema: z.ZodObject<any>;
@@ -776,6 +814,16 @@ declare class DefaultListFeature<T extends {
776
814
  filterSchema?: z.ZodObject<any>;
777
815
  /** 自定义列渲染函数(可选,key 为字段名,value 为渲染函数) */
778
816
  columnRenderers?: Record<string, (value: any, item: T) => any>;
817
+ /** 打开方式配置(可选,默认为 dialog)
818
+ * - create: 新建按钮的打开方式(默认 "dialog")
819
+ * - detail: 查看按钮的打开方式(默认 "dialog")
820
+ * - edit: 编辑按钮的打开方式(默认 "dialog")
821
+ */
822
+ openMode?: {
823
+ create?: OpenMode;
824
+ detail?: OpenMode;
825
+ edit?: OpenMode;
826
+ };
779
827
  });
780
828
  getRoutes(): {
781
829
  method: "get";
@@ -875,6 +923,8 @@ interface DialogProps {
875
923
  closeOnBackdropClick?: boolean;
876
924
  /** 操作按钮(在 Footer 中显示,固定在底部) */
877
925
  actions?: ActionButton[];
926
+ /** 是否固定内容区域高度(用于表单等需要固定高度的场景,避免切换 Tab 时高度变化) */
927
+ fixedContentHeight?: boolean;
878
928
  }
879
929
  declare function Dialog(props: DialogProps): hono_jsx_jsx_dev_runtime.JSX.Element;
880
930
 
@@ -908,4 +958,39 @@ declare function ErrorAlert(props: ErrorAlertProps): hono_jsx_jsx_dev_runtime.JS
908
958
  */
909
959
  declare function LoadingBar(): hono_jsx_jsx_dev_runtime.JSX.Element;
910
960
 
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 };
961
+ interface ObjectEditorProps {
962
+ /** 字段定义 */
963
+ field: any;
964
+ /** 当前值(对象,已解析) */
965
+ value: Record<string, any> | null;
966
+ /** 完整的初始数据 */
967
+ initialData?: any;
968
+ /** 字段名(用于更新隐藏字段) */
969
+ fieldName: string;
970
+ /** 对象的 Zod schema(用于自动渲染结构) */
971
+ objectSchema?: z.ZodObject<any>;
972
+ }
973
+ declare function ObjectEditor(props: ObjectEditorProps): hono_jsx_jsx_dev_runtime.JSX.Element;
974
+
975
+ /**
976
+ * 字符串数组编辑器组件
977
+ * 支持增加、删除和拖放排序功能
978
+ * 使用 Alpine.js 管理状态,通过隐藏字段与表单系统同步数据
979
+ */
980
+ interface StringArrayEditorProps {
981
+ /** 字段定义 */
982
+ field: any;
983
+ /** 当前值(字符串数组,已解析) */
984
+ value: string[] | null;
985
+ /** 完整的初始数据 */
986
+ initialData?: any;
987
+ /** 字段名(用于更新隐藏字段) */
988
+ fieldName: string;
989
+ /** 占位符文本(可选) */
990
+ placeholder?: string;
991
+ /** 是否允许空值(默认 false) */
992
+ allowEmpty?: boolean;
993
+ }
994
+ declare function StringArrayEditor(props: StringArrayEditorProps): hono_utils_html.HtmlEscapedString | Promise<hono_utils_html.HtmlEscapedString>;
995
+
996
+ 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, ObjectEditor, type ObjectEditorProps, type PageMetadata, PageModel, type PermissionResult, StringArrayEditor, type StringArrayEditorProps, type UserInfo, checkUserPermission, getUserInfo, modelNameToPath, parseListParams };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import { Context } from 'hono';
2
2
  import { z } from 'zod';
3
3
  import { Plugin, PluginPriority, Microservice } from 'imean-service-engine';
4
4
  import * as hono_jsx_jsx_dev_runtime from 'hono/jsx/jsx-dev-runtime';
5
+ import * as hono_utils_html from 'hono/utils/html';
5
6
 
6
7
  /**
7
8
  * HtmxAdminPlugin 核心类型定义
@@ -39,11 +40,17 @@ interface ActionButton {
39
40
  onClick?: string;
40
41
  /** 自定义类名 */
41
42
  className?: string;
43
+ /** 链接目标(如 "_blank" 表示新窗口打开) */
44
+ target?: string;
42
45
  }
43
46
  /**
44
47
  * 对话框大小类型
45
48
  */
46
49
  type DialogSize = "sm" | "md" | "lg" | "xl" | "full";
50
+ /**
51
+ * 打开方式类型
52
+ */
53
+ type OpenMode = "dialog" | "page" | "newWindow";
47
54
  /**
48
55
  * 页面元数据配置
49
56
  */
@@ -105,9 +112,20 @@ interface ModelField {
105
112
  value: string | number;
106
113
  label: string;
107
114
  }>;
115
+ /** HTML input step 属性(用于 number 类型,支持小数) */
116
+ step?: string | number;
108
117
  /** 原始 Zod Schema(用于验证等) */
109
118
  schema: any;
110
119
  }
120
+ /**
121
+ * 字段分组配置
122
+ */
123
+ interface FieldGroup {
124
+ /** 分组标签 */
125
+ label: string;
126
+ /** 该分组包含的字段名列表 */
127
+ fields: string[];
128
+ }
111
129
  /**
112
130
  * Feature 类型
113
131
  */
@@ -316,6 +334,21 @@ interface FormField {
316
334
  value: string | number;
317
335
  label: string;
318
336
  }>;
337
+ /** HTML input step 属性(用于 number 类型,支持小数) */
338
+ step?: string | number;
339
+ }
340
+ /**
341
+ * 表单字段渲染器属性
342
+ */
343
+ interface FormFieldRendererProps<T = any> {
344
+ /** 字段定义 */
345
+ field: FormField;
346
+ /** 当前值(已解析的对象/数组,不是 JSON 字符串) */
347
+ value: any;
348
+ /** 完整的初始数据 */
349
+ initialData?: Partial<T>;
350
+ /** 字段名(用于更新隐藏字段) */
351
+ fieldName: string;
319
352
  }
320
353
 
321
354
  /**
@@ -458,11 +491,6 @@ declare abstract class BaseFeature implements Feature {
458
491
  render?(context: FeatureContext): Promise<any>;
459
492
  }
460
493
 
461
- /**
462
- * 表单 Feature 基类
463
- * 提供创建和编辑 Feature 的公共逻辑
464
- */
465
-
466
494
  /**
467
495
  * 表单操作类型
468
496
  */
@@ -478,6 +506,8 @@ declare abstract class BaseFormFeature<T extends {
478
506
  protected descriptionGetter?: (context: FeatureContext, item?: T) => string | Promise<string> | undefined;
479
507
  /** 当前请求的表单 ID(用于在 render 和 getActions 之间共享) */
480
508
  private currentFormId?;
509
+ /** 自定义表单字段渲染器 */
510
+ protected formFieldRenderers?: Record<string, (props: FormFieldRendererProps<T>) => any>;
481
511
  /**
482
512
  * 获取或生成表单 ID(确保在同一个请求中保持一致)
483
513
  */
@@ -533,6 +563,7 @@ declare abstract class BaseFormFeature<T extends {
533
563
  */
534
564
  handle(context: FeatureContext): Promise<any>;
535
565
  protected formFieldNames?: string[];
566
+ protected groups?: FieldGroup[];
536
567
  /**
537
568
  * 渲染表单页面
538
569
  */
@@ -583,10 +614,6 @@ declare class CustomFeature extends BaseFeature {
583
614
  render(context: FeatureContext): Promise<any>;
584
615
  }
585
616
 
586
- /**
587
- * 默认创建 Feature
588
- */
589
-
590
617
  /**
591
618
  * 默认创建 Feature
592
619
  * 类型通过 schema 的 z.infer 推断
@@ -609,6 +636,10 @@ declare class DefaultCreateFeature<T extends {
609
636
  getDescription?: (context: FeatureContext) => string | Promise<string> | undefined;
610
637
  /** 表单字段名(可选,不提供则显示 schema 中的所有字段) */
611
638
  formFieldNames?: string[];
639
+ /** 字段分组配置(可选,用于将字段分组展示为 Tab) */
640
+ groups?: FieldGroup[];
641
+ /** 自定义表单字段渲染器 */
642
+ formFieldRenderers?: Record<string, (props: FormFieldRendererProps<T>) => any>;
612
643
  });
613
644
  getFormAction(): "create";
614
645
  getRoutes(): ({
@@ -665,6 +696,8 @@ declare class DefaultDetailFeature<T extends {
665
696
  private titleGetter?;
666
697
  private descriptionGetter?;
667
698
  private detailFieldNames?;
699
+ private fieldRenderers?;
700
+ private groups?;
668
701
  constructor(options: {
669
702
  /** 详情数据的 Schema(用于字段推断和显示) */
670
703
  schema: z.ZodObject<any>;
@@ -680,6 +713,10 @@ declare class DefaultDetailFeature<T extends {
680
713
  getDescription?: (item: T, context: FeatureContext) => string | Promise<string> | undefined;
681
714
  /** 详情显示字段名(可选,不提供则显示 schema 中的所有字段) */
682
715
  detailFieldNames?: string[];
716
+ /** 自定义字段渲染函数(可选,key 为字段名,value 为渲染函数) */
717
+ fieldRenderers?: Record<string, (value: any, item: T) => any>;
718
+ /** 字段分组配置(可选,用于将字段分组展示为卡片) */
719
+ groups?: FieldGroup[];
683
720
  });
684
721
  getTitle(context: FeatureContext): Promise<string>;
685
722
  getDescription(context: FeatureContext): Promise<string | undefined>;
@@ -691,10 +728,6 @@ declare class DefaultDetailFeature<T extends {
691
728
  getActions(context: FeatureContext): Promise<ActionButton[]>;
692
729
  }
693
730
 
694
- /**
695
- * 默认编辑 Feature
696
- */
697
-
698
731
  /**
699
732
  * 默认编辑 Feature
700
733
  * 类型通过 schema 的 z.infer 推断
@@ -719,6 +752,10 @@ declare class DefaultEditFeature<T extends {
719
752
  getDescription?: (item: T, context: FeatureContext) => string | Promise<string> | undefined;
720
753
  /** 表单字段名(可选,不提供则显示 schema 中的所有字段) */
721
754
  formFieldNames?: string[];
755
+ /** 字段分组配置(可选,用于将字段分组展示为 Tab) */
756
+ groups?: FieldGroup[];
757
+ /** 自定义表单字段渲染器 */
758
+ formFieldRenderers?: Record<string, (props: FormFieldRendererProps<T>) => any>;
722
759
  });
723
760
  getFormAction(): "edit";
724
761
  getRoutes(): ({
@@ -755,6 +792,7 @@ declare class DefaultListFeature<T extends {
755
792
  private listFieldNames?;
756
793
  private filterSchema?;
757
794
  private columnRenderers?;
795
+ private openMode?;
758
796
  constructor(options: {
759
797
  /** 列表数据的 Schema(用于字段推断和显示) */
760
798
  schema: z.ZodObject<any>;
@@ -776,6 +814,16 @@ declare class DefaultListFeature<T extends {
776
814
  filterSchema?: z.ZodObject<any>;
777
815
  /** 自定义列渲染函数(可选,key 为字段名,value 为渲染函数) */
778
816
  columnRenderers?: Record<string, (value: any, item: T) => any>;
817
+ /** 打开方式配置(可选,默认为 dialog)
818
+ * - create: 新建按钮的打开方式(默认 "dialog")
819
+ * - detail: 查看按钮的打开方式(默认 "dialog")
820
+ * - edit: 编辑按钮的打开方式(默认 "dialog")
821
+ */
822
+ openMode?: {
823
+ create?: OpenMode;
824
+ detail?: OpenMode;
825
+ edit?: OpenMode;
826
+ };
779
827
  });
780
828
  getRoutes(): {
781
829
  method: "get";
@@ -875,6 +923,8 @@ interface DialogProps {
875
923
  closeOnBackdropClick?: boolean;
876
924
  /** 操作按钮(在 Footer 中显示,固定在底部) */
877
925
  actions?: ActionButton[];
926
+ /** 是否固定内容区域高度(用于表单等需要固定高度的场景,避免切换 Tab 时高度变化) */
927
+ fixedContentHeight?: boolean;
878
928
  }
879
929
  declare function Dialog(props: DialogProps): hono_jsx_jsx_dev_runtime.JSX.Element;
880
930
 
@@ -908,4 +958,39 @@ declare function ErrorAlert(props: ErrorAlertProps): hono_jsx_jsx_dev_runtime.JS
908
958
  */
909
959
  declare function LoadingBar(): hono_jsx_jsx_dev_runtime.JSX.Element;
910
960
 
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 };
961
+ interface ObjectEditorProps {
962
+ /** 字段定义 */
963
+ field: any;
964
+ /** 当前值(对象,已解析) */
965
+ value: Record<string, any> | null;
966
+ /** 完整的初始数据 */
967
+ initialData?: any;
968
+ /** 字段名(用于更新隐藏字段) */
969
+ fieldName: string;
970
+ /** 对象的 Zod schema(用于自动渲染结构) */
971
+ objectSchema?: z.ZodObject<any>;
972
+ }
973
+ declare function ObjectEditor(props: ObjectEditorProps): hono_jsx_jsx_dev_runtime.JSX.Element;
974
+
975
+ /**
976
+ * 字符串数组编辑器组件
977
+ * 支持增加、删除和拖放排序功能
978
+ * 使用 Alpine.js 管理状态,通过隐藏字段与表单系统同步数据
979
+ */
980
+ interface StringArrayEditorProps {
981
+ /** 字段定义 */
982
+ field: any;
983
+ /** 当前值(字符串数组,已解析) */
984
+ value: string[] | null;
985
+ /** 完整的初始数据 */
986
+ initialData?: any;
987
+ /** 字段名(用于更新隐藏字段) */
988
+ fieldName: string;
989
+ /** 占位符文本(可选) */
990
+ placeholder?: string;
991
+ /** 是否允许空值(默认 false) */
992
+ allowEmpty?: boolean;
993
+ }
994
+ declare function StringArrayEditor(props: StringArrayEditorProps): hono_utils_html.HtmlEscapedString | Promise<hono_utils_html.HtmlEscapedString>;
995
+
996
+ 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, ObjectEditor, type ObjectEditorProps, type PageMetadata, PageModel, type PermissionResult, StringArrayEditor, type StringArrayEditorProps, type UserInfo, checkUserPermission, getUserInfo, modelNameToPath, parseListParams };