conditional-selection 1.0.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.
@@ -0,0 +1,53 @@
1
+ import type { ReactNode } from 'react';
2
+
3
+ export enum EConditionalSelectionFramework {
4
+ /** 内容组 */
5
+ GROUP = 'group',
6
+ /** 内容 */
7
+ INDIVIDUAL = 'individual',
8
+ }
9
+
10
+ export enum EConditionalSelectionLink {
11
+ AND = 'and',
12
+ OR = 'or',
13
+ }
14
+
15
+ export type TConditionalSelection<T = any> = {
16
+ _id: string;
17
+ /** 结构标识 */
18
+ framework: EConditionalSelectionFramework;
19
+ /** 内容关系 */
20
+ link?: EConditionalSelectionLink;
21
+ group?: TConditionalSelection<T>[];
22
+ individual?: Record<string, any>;
23
+ level: number;
24
+ }
25
+
26
+ export type TConditionalSelectionDisabledProps = {
27
+ addItem?: boolean;
28
+ delItem?: boolean;
29
+ linkChange?: boolean;
30
+ };
31
+
32
+ export type TConditionalSelectionProps = {
33
+ /** 数据内容 */
34
+ conditionalRules?: TConditionalSelection | null;
35
+ /** deep 层级限制,需大于0,默认1 */
36
+ maxLevel?: number;
37
+ /** 最外层子项数量限制,需大于1,默认不限 */
38
+ zeroLevelMaxLength?: number;
39
+ /** 是否禁用新增、删除、关系变更 */
40
+ disabled?: boolean | TConditionalSelectionDisabledProps;
41
+ /** 数据变更回调 */
42
+ onChange?: (value: TConditionalSelection | undefined) => void;
43
+ /** 渲染条件行内容的插槽,参数为当前 INDIVIDUAL 节点和变更 handler */
44
+ renderConditionRules?: (
45
+ conditionRulesData: TConditionalSelection,
46
+ change: (data: Record<string, any>) => void
47
+ ) => ReactNode;
48
+ /** 渲染创建条件按钮插槽(createCondition) */
49
+ renderCreateCondition?: (params: {
50
+ createRules: (ruleData: TConditionalSelection) => void;
51
+ rulesData: TConditionalSelection;
52
+ }) => ReactNode;
53
+ };
@@ -0,0 +1 @@
1
+ export * from './ConditionalSelection'
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "allowSyntheticDefaultImports": true,
7
+ "jsx": "preserve",
8
+ "jsxImportSource": "react",
9
+ "strict": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true
12
+ },
13
+ "include": ["packages/**/*"],
14
+ "references": [{ "path": "./tsconfig.node.json" }]
15
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "allowSyntheticDefaultImports": true,
7
+ "allowImportingTsExtensions": true,
8
+ "strict": true,
9
+ "skipLibCheck": true,
10
+ "emitDeclarationOnly": true,
11
+ "types": ["node"],
12
+ "composite": true
13
+ },
14
+ "include": ["vite.config.ts"]
15
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { defineConfig } from 'vite';
2
+ import react from '@vitejs/plugin-react-swc'
3
+ import path from 'node:path'
4
+ import dts from 'vite-plugin-dts'
5
+ export default defineConfig(({ command }) => {
6
+ const isDev = command === 'serve'
7
+ return {
8
+ plugins: [react(), dts({
9
+ outDir: 'dist/types',
10
+ insertTypesEntry: true, //这是dts插件的配置,用于生成类型文件
11
+ include: ['packages/**/*.ts', 'packages/**/*.tsx'],
12
+ rollupTypes: true
13
+ })],
14
+ root: isDev ? path.resolve(__dirname, 'example') : undefined,
15
+ server: {
16
+ port: 3000,
17
+ open: true,
18
+ },
19
+ build: {
20
+ outDir: path.resolve(__dirname, 'dist'),
21
+ lib: {
22
+ entry: path.resolve(__dirname, 'packages/index.ts'),
23
+ name: 'ui',
24
+ formats: ['es', 'umd', 'cjs', 'iife'],
25
+ fileName: (format) => `ui.${format}.js`,
26
+ },
27
+ emptyOutDir: false,
28
+ rollupOptions: {
29
+ external: ['react', 'react-dom'],
30
+ output: {
31
+ globals: {
32
+ react: 'React',
33
+ 'react-dom': 'ReactDOM',
34
+ },
35
+ },
36
+ },
37
+ },
38
+ }
39
+ });