@conform-to/react 1.1.4 → 1.1.5
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/context.d.ts +187 -59
- package/context.js +3 -5
- package/context.mjs +4 -6
- package/experimental.d.ts +0 -0
- package/hooks.d.ts +53 -24
- package/index.d.ts +28 -4
- package/integrations.js +14 -1
- package/integrations.mjs +14 -1
- package/package.json +2 -2
- package/rollup.config.js +0 -102
package/context.d.ts
CHANGED
|
@@ -1,72 +1,200 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
type Constraint,
|
|
3
|
+
type Combine,
|
|
4
|
+
type FormId,
|
|
5
|
+
type FieldName,
|
|
6
|
+
type FormContext as BaseFormContext,
|
|
7
|
+
type FormValue,
|
|
8
|
+
type FormState,
|
|
9
|
+
type Intent,
|
|
10
|
+
type SubscriptionScope,
|
|
11
|
+
type SubscriptionSubject,
|
|
12
|
+
type FormOptions as BaseFormOptions,
|
|
13
|
+
} from '@conform-to/dom';
|
|
14
|
+
import {
|
|
15
|
+
type FormEvent,
|
|
16
|
+
type ReactElement,
|
|
17
|
+
type ReactNode,
|
|
18
|
+
type MutableRefObject,
|
|
19
|
+
} from 'react';
|
|
3
20
|
export type Pretty<T> = {
|
|
4
|
-
|
|
21
|
+
[K in keyof T]: T[K];
|
|
5
22
|
} & {};
|
|
6
|
-
export type Primitive =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
export type Primitive =
|
|
24
|
+
| string
|
|
25
|
+
| number
|
|
26
|
+
| bigint
|
|
27
|
+
| boolean
|
|
28
|
+
| Date
|
|
29
|
+
| File
|
|
30
|
+
| null
|
|
31
|
+
| undefined;
|
|
32
|
+
export type Metadata<
|
|
33
|
+
Schema,
|
|
34
|
+
FormSchema extends Record<string, unknown>,
|
|
35
|
+
FormError = string[],
|
|
36
|
+
> = {
|
|
37
|
+
key: string | undefined;
|
|
38
|
+
id: string;
|
|
39
|
+
errorId: string;
|
|
40
|
+
descriptionId: string;
|
|
41
|
+
name: FieldName<Schema, FormSchema, FormError>;
|
|
42
|
+
initialValue: FormValue<Schema>;
|
|
43
|
+
value: FormValue<Schema>;
|
|
44
|
+
errors: FormError | undefined;
|
|
45
|
+
allErrors: Record<string, FormError>;
|
|
46
|
+
valid: boolean;
|
|
47
|
+
dirty: boolean;
|
|
19
48
|
};
|
|
20
|
-
export type FormMetadata<
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
49
|
+
export type FormMetadata<
|
|
50
|
+
Schema extends Record<string, unknown> = Record<string, unknown>,
|
|
51
|
+
FormError = string[],
|
|
52
|
+
> = Omit<Metadata<Schema, Schema, FormError>, 'id'> &
|
|
53
|
+
Pick<FormContext<Schema, FormError>, Intent['type']> & {
|
|
54
|
+
id: FormId<Schema, FormError>;
|
|
55
|
+
context: Wrapped<FormContext<Schema, FormError>>;
|
|
56
|
+
status?: 'success' | 'error';
|
|
57
|
+
getFieldset: () => Required<{
|
|
58
|
+
[Key in keyof Combine<Schema>]: FieldMetadata<
|
|
59
|
+
Combine<Schema>[Key],
|
|
60
|
+
Schema,
|
|
61
|
+
FormError
|
|
62
|
+
>;
|
|
63
|
+
}>;
|
|
64
|
+
onSubmit: (event: React.FormEvent<HTMLFormElement>) => void;
|
|
65
|
+
noValidate: boolean;
|
|
66
|
+
};
|
|
67
|
+
type SubfieldMetadata<
|
|
68
|
+
Schema,
|
|
69
|
+
FormSchema extends Record<string, any>,
|
|
70
|
+
FormError,
|
|
71
|
+
> = [Schema] extends [Primitive]
|
|
72
|
+
? {}
|
|
73
|
+
: [Schema] extends [Array<infer Item> | null | undefined]
|
|
74
|
+
? {
|
|
75
|
+
getFieldList: () => Array<FieldMetadata<Item, FormSchema, FormError>>;
|
|
76
|
+
}
|
|
77
|
+
: [Schema] extends [Record<string, any> | null | undefined]
|
|
78
|
+
? {
|
|
79
|
+
getFieldset: () => Required<{
|
|
80
|
+
[Key in keyof Combine<Schema>]: FieldMetadata<
|
|
81
|
+
Combine<Schema>[Key],
|
|
82
|
+
FormSchema,
|
|
83
|
+
FormError
|
|
84
|
+
>;
|
|
85
|
+
}>;
|
|
86
|
+
}
|
|
87
|
+
: {};
|
|
88
|
+
export type FieldMetadata<
|
|
89
|
+
Schema = unknown,
|
|
90
|
+
FormSchema extends Record<string, any> = Record<string, unknown>,
|
|
91
|
+
FormError = string[],
|
|
92
|
+
> = Metadata<Schema, FormSchema, FormError> &
|
|
93
|
+
Constraint & {
|
|
94
|
+
formId: FormId<FormSchema, FormError>;
|
|
95
|
+
} & SubfieldMetadata<Schema, FormSchema, FormError>;
|
|
96
|
+
export declare const Form: import('react').Context<
|
|
97
|
+
FormContext<any, string[], any>[]
|
|
98
|
+
>;
|
|
41
99
|
declare const wrappedSymbol: unique symbol;
|
|
42
100
|
export type Wrapped<Type> = {
|
|
43
|
-
|
|
101
|
+
[wrappedSymbol]: Type;
|
|
44
102
|
};
|
|
45
|
-
export declare function getWrappedFormContext(
|
|
46
|
-
|
|
47
|
-
|
|
103
|
+
export declare function getWrappedFormContext(
|
|
104
|
+
context: Wrapped<FormContext>,
|
|
105
|
+
): FormContext;
|
|
106
|
+
export declare function useFormContext<
|
|
107
|
+
Schema extends Record<string, any>,
|
|
108
|
+
FormError,
|
|
109
|
+
>(formId?: FormId<Schema, FormError>): FormContext<Schema, FormError, unknown>;
|
|
110
|
+
export declare function useFormState<FormError>(
|
|
111
|
+
form: FormContext<any, FormError>,
|
|
112
|
+
subjectRef?: MutableRefObject<SubscriptionSubject>,
|
|
113
|
+
): FormState<FormError>;
|
|
48
114
|
export declare function FormProvider(props: {
|
|
49
|
-
|
|
50
|
-
|
|
115
|
+
context: Wrapped<FormContext<any, any>>;
|
|
116
|
+
children: ReactNode;
|
|
51
117
|
}): ReactElement;
|
|
52
118
|
export declare function FormStateInput(props: {
|
|
53
|
-
|
|
119
|
+
formId?: string;
|
|
54
120
|
}): React.ReactElement;
|
|
55
|
-
export declare function useSubjectRef(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
export declare function
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
121
|
+
export declare function useSubjectRef(
|
|
122
|
+
initialSubject?: SubscriptionSubject,
|
|
123
|
+
): MutableRefObject<SubscriptionSubject>;
|
|
124
|
+
export declare function updateSubjectRef(
|
|
125
|
+
ref: MutableRefObject<SubscriptionSubject>,
|
|
126
|
+
subject: 'status' | 'formId',
|
|
127
|
+
): void;
|
|
128
|
+
export declare function updateSubjectRef(
|
|
129
|
+
ref: MutableRefObject<SubscriptionSubject>,
|
|
130
|
+
subject: Exclude<keyof SubscriptionSubject, 'status' | 'formId'>,
|
|
131
|
+
scope: keyof SubscriptionScope,
|
|
132
|
+
name: string,
|
|
133
|
+
): void;
|
|
134
|
+
export declare function getMetadata<
|
|
135
|
+
Schema,
|
|
136
|
+
FormError,
|
|
137
|
+
FormSchema extends Record<string, any>,
|
|
138
|
+
>(
|
|
139
|
+
context: FormContext<FormSchema, FormError, any>,
|
|
140
|
+
subjectRef: MutableRefObject<SubscriptionSubject>,
|
|
141
|
+
stateSnapshot: FormState<FormError>,
|
|
142
|
+
name?: FieldName<Schema, FormSchema, FormError>,
|
|
143
|
+
): Metadata<Schema, FormSchema, FormError>;
|
|
144
|
+
export declare function getFieldMetadata<
|
|
145
|
+
Schema,
|
|
146
|
+
FormSchema extends Record<string, any>,
|
|
147
|
+
FormError,
|
|
148
|
+
>(
|
|
149
|
+
context: FormContext<FormSchema, FormError, any>,
|
|
150
|
+
subjectRef: MutableRefObject<SubscriptionSubject>,
|
|
151
|
+
stateSnapshot: FormState<FormError>,
|
|
152
|
+
prefix?: string,
|
|
153
|
+
key?: string | number,
|
|
154
|
+
): FieldMetadata<Schema, FormSchema, FormError>;
|
|
155
|
+
export declare function getFormMetadata<
|
|
156
|
+
Schema extends Record<string, any>,
|
|
157
|
+
FormError = string[],
|
|
158
|
+
FormValue = Schema,
|
|
159
|
+
>(
|
|
160
|
+
context: FormContext<Schema, FormError, FormValue>,
|
|
161
|
+
subjectRef: MutableRefObject<SubscriptionSubject>,
|
|
162
|
+
stateSnapshot: FormState<FormError>,
|
|
163
|
+
noValidate: boolean,
|
|
164
|
+
): FormMetadata<Schema, FormError>;
|
|
165
|
+
export type FormOptions<
|
|
166
|
+
Schema extends Record<string, any> = any,
|
|
167
|
+
FormError = string[],
|
|
168
|
+
FormValue = Schema,
|
|
169
|
+
> = BaseFormOptions<Schema, FormError, FormValue> & {
|
|
170
|
+
/**
|
|
171
|
+
* A function to be called before the form is submitted.
|
|
172
|
+
*/
|
|
173
|
+
onSubmit?: (
|
|
174
|
+
event: FormEvent<HTMLFormElement>,
|
|
175
|
+
context: ReturnType<
|
|
176
|
+
BaseFormContext<Schema, FormError, FormValue>['submit']
|
|
177
|
+
>,
|
|
178
|
+
) => void;
|
|
66
179
|
};
|
|
67
|
-
export type FormContext<
|
|
68
|
-
|
|
69
|
-
|
|
180
|
+
export type FormContext<
|
|
181
|
+
Schema extends Record<string, any> = any,
|
|
182
|
+
FormError = string[],
|
|
183
|
+
FormValue = Schema,
|
|
184
|
+
> = Omit<
|
|
185
|
+
BaseFormContext<Schema, FormError, FormValue>,
|
|
186
|
+
'submit' | 'onUpdate'
|
|
187
|
+
> & {
|
|
188
|
+
submit: (event: FormEvent<HTMLFormElement>) => void;
|
|
189
|
+
onUpdate: (
|
|
190
|
+
options: Partial<FormOptions<Schema, FormError, FormValue>>,
|
|
191
|
+
) => void;
|
|
70
192
|
};
|
|
71
|
-
export declare function createFormContext<
|
|
193
|
+
export declare function createFormContext<
|
|
194
|
+
Schema extends Record<string, any> = any,
|
|
195
|
+
FormError = string[],
|
|
196
|
+
FormValue = Schema,
|
|
197
|
+
>(
|
|
198
|
+
options: FormOptions<Schema, FormError, FormValue>,
|
|
199
|
+
): FormContext<Schema, FormError, FormValue>;
|
|
72
200
|
export {};
|
package/context.js
CHANGED
|
@@ -7,7 +7,6 @@ var dom = require('@conform-to/dom');
|
|
|
7
7
|
var react = require('react');
|
|
8
8
|
var jsxRuntime = require('react/jsx-runtime');
|
|
9
9
|
|
|
10
|
-
var _excluded = ["onSubmit"];
|
|
11
10
|
var Form = /*#__PURE__*/react.createContext([]);
|
|
12
11
|
|
|
13
12
|
// To hide the FormContext type from the public API
|
|
@@ -220,10 +219,9 @@ function getFormMetadata(context, subjectRef, stateSnapshot, noValidate) {
|
|
|
220
219
|
}
|
|
221
220
|
function createFormContext(options) {
|
|
222
221
|
var {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
var context = dom.unstable_createFormContext(rest);
|
|
222
|
+
onSubmit
|
|
223
|
+
} = options;
|
|
224
|
+
var context = dom.unstable_createFormContext(options);
|
|
227
225
|
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, context), {}, {
|
|
228
226
|
submit(event) {
|
|
229
227
|
var submitEvent = event.nativeEvent;
|
package/context.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
2
|
import { STATE, formatPaths, getPaths, unstable_createFormContext, INTENT, isPrefix } from '@conform-to/dom';
|
|
3
3
|
import { useContext, useMemo, createContext, useCallback, useSyncExternalStore, useRef } from 'react';
|
|
4
4
|
import { jsx } from 'react/jsx-runtime';
|
|
5
5
|
|
|
6
|
-
var _excluded = ["onSubmit"];
|
|
7
6
|
var Form = /*#__PURE__*/createContext([]);
|
|
8
7
|
|
|
9
8
|
// To hide the FormContext type from the public API
|
|
@@ -216,10 +215,9 @@ function getFormMetadata(context, subjectRef, stateSnapshot, noValidate) {
|
|
|
216
215
|
}
|
|
217
216
|
function createFormContext(options) {
|
|
218
217
|
var {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
var context = unstable_createFormContext(rest);
|
|
218
|
+
onSubmit
|
|
219
|
+
} = options;
|
|
220
|
+
var context = unstable_createFormContext(options);
|
|
223
221
|
return _objectSpread2(_objectSpread2({}, context), {}, {
|
|
224
222
|
submit(event) {
|
|
225
223
|
var submitEvent = event.nativeEvent;
|
|
File without changes
|
package/hooks.d.ts
CHANGED
|
@@ -1,34 +1,63 @@
|
|
|
1
1
|
import { type FormId, type FieldName } from '@conform-to/dom';
|
|
2
2
|
import { useEffect } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type FormMetadata,
|
|
5
|
+
type FieldMetadata,
|
|
6
|
+
type Pretty,
|
|
7
|
+
type FormOptions,
|
|
8
|
+
} from './context';
|
|
4
9
|
/**
|
|
5
10
|
* useLayoutEffect is client-only.
|
|
6
11
|
* This basically makes it a no-op on server
|
|
7
12
|
*/
|
|
8
13
|
export declare const useSafeLayoutEffect: typeof useEffect;
|
|
9
|
-
export declare function useFormId<
|
|
14
|
+
export declare function useFormId<
|
|
15
|
+
Schema extends Record<string, unknown>,
|
|
16
|
+
FormError,
|
|
17
|
+
>(preferredId?: string): FormId<Schema, FormError>;
|
|
10
18
|
export declare function useNoValidate(defaultNoValidate?: boolean): boolean;
|
|
11
|
-
export declare function useForm<
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
export declare function useForm<
|
|
20
|
+
Schema extends Record<string, any>,
|
|
21
|
+
FormValue = Schema,
|
|
22
|
+
FormError = string[],
|
|
23
|
+
>(
|
|
24
|
+
options: Pretty<
|
|
25
|
+
Omit<FormOptions<Schema, FormError, FormValue>, 'formId'> & {
|
|
26
|
+
/**
|
|
27
|
+
* The form id. If not provided, a random id will be generated.
|
|
28
|
+
*/
|
|
29
|
+
id?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Enable constraint validation before the dom is hydated.
|
|
32
|
+
*
|
|
33
|
+
* Default to `true`.
|
|
34
|
+
*/
|
|
35
|
+
defaultNoValidate?: boolean;
|
|
36
|
+
}
|
|
37
|
+
>,
|
|
38
|
+
): [
|
|
39
|
+
FormMetadata<Schema, FormError>,
|
|
40
|
+
ReturnType<FormMetadata<Schema, FormError>['getFieldset']>,
|
|
25
41
|
];
|
|
26
|
-
export declare function useFormMetadata<
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
42
|
+
export declare function useFormMetadata<
|
|
43
|
+
Schema extends Record<string, any>,
|
|
44
|
+
FormError = string[],
|
|
45
|
+
>(
|
|
46
|
+
formId?: FormId<Schema, FormError>,
|
|
47
|
+
options?: {
|
|
48
|
+
defaultNoValidate?: boolean;
|
|
49
|
+
},
|
|
50
|
+
): FormMetadata<Schema, FormError>;
|
|
51
|
+
export declare function useField<
|
|
52
|
+
FieldSchema,
|
|
53
|
+
FormSchema extends Record<string, unknown> = Record<string, unknown>,
|
|
54
|
+
FormError = string[],
|
|
55
|
+
>(
|
|
56
|
+
name: FieldName<FieldSchema, FormSchema, FormError>,
|
|
57
|
+
options?: {
|
|
58
|
+
formId?: FormId<FormSchema, FormError>;
|
|
59
|
+
},
|
|
60
|
+
): [
|
|
61
|
+
FieldMetadata<FieldSchema, FormSchema, FormError>,
|
|
62
|
+
FormMetadata<FormSchema, FormError>,
|
|
34
63
|
];
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
1
|
+
export {
|
|
2
|
+
type Submission,
|
|
3
|
+
type SubmissionResult,
|
|
4
|
+
type DefaultValue,
|
|
5
|
+
type Intent,
|
|
6
|
+
type FormId,
|
|
7
|
+
type FieldName,
|
|
8
|
+
parse,
|
|
9
|
+
} from '@conform-to/dom';
|
|
10
|
+
export {
|
|
11
|
+
type FieldMetadata,
|
|
12
|
+
type FormMetadata,
|
|
13
|
+
FormProvider,
|
|
14
|
+
FormStateInput,
|
|
15
|
+
} from './context';
|
|
3
16
|
export { useForm, useFormMetadata, useField } from './hooks';
|
|
4
|
-
export {
|
|
5
|
-
|
|
17
|
+
export {
|
|
18
|
+
Control as unstable_Control,
|
|
19
|
+
useControl as unstable_useControl,
|
|
20
|
+
useInputControl,
|
|
21
|
+
} from './integrations';
|
|
22
|
+
export {
|
|
23
|
+
getFormProps,
|
|
24
|
+
getFieldsetProps,
|
|
25
|
+
getInputProps,
|
|
26
|
+
getSelectProps,
|
|
27
|
+
getTextareaProps,
|
|
28
|
+
getCollectionProps,
|
|
29
|
+
} from './helpers';
|
package/integrations.js
CHANGED
|
@@ -216,8 +216,21 @@ function useControl(meta) {
|
|
|
216
216
|
setValue(value);
|
|
217
217
|
change(value);
|
|
218
218
|
};
|
|
219
|
+
var refCallback = element => {
|
|
220
|
+
var _meta$key;
|
|
221
|
+
register(element);
|
|
222
|
+
if (!element) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
var prevKey = element.dataset.conform;
|
|
226
|
+
var nextKey = "".concat((_meta$key = meta.key) !== null && _meta$key !== void 0 ? _meta$key : '');
|
|
227
|
+
if (prevKey !== nextKey) {
|
|
228
|
+
element.dataset.conform = nextKey;
|
|
229
|
+
updateFieldValue(element, value !== null && value !== void 0 ? value : '');
|
|
230
|
+
}
|
|
231
|
+
};
|
|
219
232
|
return {
|
|
220
|
-
register,
|
|
233
|
+
register: refCallback,
|
|
221
234
|
value,
|
|
222
235
|
change: handleChange,
|
|
223
236
|
focus,
|
package/integrations.mjs
CHANGED
|
@@ -212,8 +212,21 @@ function useControl(meta) {
|
|
|
212
212
|
setValue(value);
|
|
213
213
|
change(value);
|
|
214
214
|
};
|
|
215
|
+
var refCallback = element => {
|
|
216
|
+
var _meta$key;
|
|
217
|
+
register(element);
|
|
218
|
+
if (!element) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
var prevKey = element.dataset.conform;
|
|
222
|
+
var nextKey = "".concat((_meta$key = meta.key) !== null && _meta$key !== void 0 ? _meta$key : '');
|
|
223
|
+
if (prevKey !== nextKey) {
|
|
224
|
+
element.dataset.conform = nextKey;
|
|
225
|
+
updateFieldValue(element, value !== null && value !== void 0 ? value : '');
|
|
226
|
+
}
|
|
227
|
+
};
|
|
215
228
|
return {
|
|
216
|
-
register,
|
|
229
|
+
register: refCallback,
|
|
217
230
|
value,
|
|
218
231
|
change: handleChange,
|
|
219
232
|
focus,
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Conform view adapter for react",
|
|
4
4
|
"homepage": "https://conform.guide",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "1.1.
|
|
6
|
+
"version": "1.1.5",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"module": "index.mjs",
|
|
9
9
|
"types": "index.d.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"url": "https://github.com/edmundhung/conform/issues"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@conform-to/dom": "1.1.
|
|
33
|
+
"@conform-to/dom": "1.1.5"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@babel/core": "^7.17.8",
|
package/rollup.config.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import babel from '@rollup/plugin-babel';
|
|
3
|
-
import nodeResolve from '@rollup/plugin-node-resolve';
|
|
4
|
-
import copy from 'rollup-plugin-copy';
|
|
5
|
-
|
|
6
|
-
/** @returns {import("rollup").RollupOptions[]} */
|
|
7
|
-
function configurePackage() {
|
|
8
|
-
let sourceDir = '.';
|
|
9
|
-
let outputDir = sourceDir;
|
|
10
|
-
|
|
11
|
-
/** @type {import("rollup").RollupOptions} */
|
|
12
|
-
let ESM = {
|
|
13
|
-
external(id) {
|
|
14
|
-
return !id.startsWith('.') && !path.isAbsolute(id);
|
|
15
|
-
},
|
|
16
|
-
input: `${sourceDir}/index.ts`,
|
|
17
|
-
output: {
|
|
18
|
-
dir: outputDir,
|
|
19
|
-
format: 'esm',
|
|
20
|
-
preserveModules: true,
|
|
21
|
-
entryFileNames: '[name].mjs',
|
|
22
|
-
},
|
|
23
|
-
plugins: [
|
|
24
|
-
babel({
|
|
25
|
-
babelrc: false,
|
|
26
|
-
configFile: false,
|
|
27
|
-
presets: [
|
|
28
|
-
[
|
|
29
|
-
'@babel/preset-env',
|
|
30
|
-
{
|
|
31
|
-
targets: {
|
|
32
|
-
node: '16',
|
|
33
|
-
esmodules: true,
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
['@babel/preset-react', { runtime: 'automatic' }],
|
|
38
|
-
'@babel/preset-typescript',
|
|
39
|
-
],
|
|
40
|
-
plugins: [],
|
|
41
|
-
babelHelpers: 'bundled',
|
|
42
|
-
exclude: /node_modules/,
|
|
43
|
-
extensions: ['.ts', '.tsx'],
|
|
44
|
-
}),
|
|
45
|
-
nodeResolve({
|
|
46
|
-
extensions: ['.ts', '.tsx'],
|
|
47
|
-
}),
|
|
48
|
-
copy({
|
|
49
|
-
targets: [
|
|
50
|
-
{ src: `../../README`, dest: sourceDir },
|
|
51
|
-
{ src: `../../LICENSE`, dest: sourceDir },
|
|
52
|
-
],
|
|
53
|
-
}),
|
|
54
|
-
],
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/** @type {import("rollup").RollupOptions} */
|
|
58
|
-
let CJS = {
|
|
59
|
-
external(id) {
|
|
60
|
-
return !id.startsWith('.') && !path.isAbsolute(id);
|
|
61
|
-
},
|
|
62
|
-
input: `${sourceDir}/index.ts`,
|
|
63
|
-
output: {
|
|
64
|
-
dir: outputDir,
|
|
65
|
-
format: 'cjs',
|
|
66
|
-
preserveModules: true,
|
|
67
|
-
exports: 'auto',
|
|
68
|
-
},
|
|
69
|
-
plugins: [
|
|
70
|
-
babel({
|
|
71
|
-
babelrc: false,
|
|
72
|
-
configFile: false,
|
|
73
|
-
presets: [
|
|
74
|
-
[
|
|
75
|
-
'@babel/preset-env',
|
|
76
|
-
{
|
|
77
|
-
targets: {
|
|
78
|
-
node: '16',
|
|
79
|
-
esmodules: true,
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
['@babel/preset-react', { runtime: 'automatic' }],
|
|
84
|
-
'@babel/preset-typescript',
|
|
85
|
-
],
|
|
86
|
-
plugins: [],
|
|
87
|
-
babelHelpers: 'bundled',
|
|
88
|
-
exclude: /node_modules/,
|
|
89
|
-
extensions: ['.ts', '.tsx'],
|
|
90
|
-
}),
|
|
91
|
-
nodeResolve({
|
|
92
|
-
extensions: ['.ts', '.tsx'],
|
|
93
|
-
}),
|
|
94
|
-
],
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
return [ESM, CJS];
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export default function rollup() {
|
|
101
|
-
return configurePackage();
|
|
102
|
-
}
|