@conform-to/dom 0.8.0 → 0.8.2
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/intent.d.ts +23 -17
- package/intent.js +5 -0
- package/intent.mjs +5 -0
- package/package.json +1 -1
package/intent.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import { type Pretty } from './types.js';
|
|
1
2
|
export interface IntentButtonProps {
|
|
2
3
|
name: typeof INTENT;
|
|
3
4
|
value: string;
|
|
4
5
|
formNoValidate?: boolean;
|
|
5
6
|
}
|
|
6
7
|
export type ListIntentPayload<Schema = unknown> = {
|
|
8
|
+
name: string;
|
|
9
|
+
operation: 'insert';
|
|
10
|
+
defaultValue?: Schema;
|
|
11
|
+
index?: number;
|
|
12
|
+
} | {
|
|
7
13
|
name: string;
|
|
8
14
|
operation: 'prepend';
|
|
9
15
|
defaultValue?: Schema;
|
|
@@ -26,29 +32,28 @@ export type ListIntentPayload<Schema = unknown> = {
|
|
|
26
32
|
from: number;
|
|
27
33
|
to: number;
|
|
28
34
|
};
|
|
35
|
+
type ExtractListIntentPayload<Operation, Schema = unknown> = Pretty<Omit<Extract<ListIntentPayload<Schema>, {
|
|
36
|
+
operation: Operation;
|
|
37
|
+
}>, 'name' | 'operation'>>;
|
|
38
|
+
type ListIntent<Operation> = {} extends ExtractListIntentPayload<Operation> ? <Schema>(name: string, payload?: ExtractListIntentPayload<Operation, Schema>) => IntentButtonProps : <Schema>(name: string, payload: ExtractListIntentPayload<Operation, Schema>) => IntentButtonProps;
|
|
29
39
|
/**
|
|
30
40
|
* Helpers to configure an intent button for modifying a list
|
|
31
41
|
*
|
|
32
42
|
* @see https://conform.guide/api/react#list
|
|
33
43
|
*/
|
|
34
44
|
export declare const list: {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
append: <
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
remove: <
|
|
46
|
-
|
|
47
|
-
}) => IntentButtonProps;
|
|
48
|
-
reorder: <Schema_4>(name: string, payload: {
|
|
49
|
-
from: number;
|
|
50
|
-
to: number;
|
|
51
|
-
}) => IntentButtonProps;
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated You can use `insert` without specifying an index instead
|
|
47
|
+
*/
|
|
48
|
+
append: ListIntent<'append'>;
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated You can use `insert` with zero index instead
|
|
51
|
+
*/
|
|
52
|
+
prepend: ListIntent<'prepend'>;
|
|
53
|
+
insert: ListIntent<'insert'>;
|
|
54
|
+
replace: ListIntent<'replace'>;
|
|
55
|
+
remove: ListIntent<'remove'>;
|
|
56
|
+
reorder: ListIntent<'reorder'>;
|
|
52
57
|
};
|
|
53
58
|
export declare const INTENT = "__intent__";
|
|
54
59
|
/**
|
|
@@ -74,3 +79,4 @@ export declare function parseIntent<Schema>(intent: string): {
|
|
|
74
79
|
payload: ListIntentPayload<Schema>;
|
|
75
80
|
} | null;
|
|
76
81
|
export declare function updateList<Schema>(list: Array<Schema>, payload: ListIntentPayload<Schema>): Array<Schema>;
|
|
82
|
+
export {};
|
package/intent.js
CHANGED
|
@@ -60,6 +60,7 @@ function validate(field) {
|
|
|
60
60
|
}
|
|
61
61
|
function requestIntent(form, buttonProps) {
|
|
62
62
|
if (!form) {
|
|
63
|
+
// eslint-disable-next-line no-console
|
|
63
64
|
console.warn('No form element is provided');
|
|
64
65
|
return;
|
|
65
66
|
}
|
|
@@ -100,6 +101,7 @@ function parseIntent(intent) {
|
|
|
100
101
|
return null;
|
|
101
102
|
}
|
|
102
103
|
function updateList(list, payload) {
|
|
104
|
+
var _payload$index;
|
|
103
105
|
switch (payload.operation) {
|
|
104
106
|
case 'prepend':
|
|
105
107
|
list.unshift(payload.defaultValue);
|
|
@@ -107,6 +109,9 @@ function updateList(list, payload) {
|
|
|
107
109
|
case 'append':
|
|
108
110
|
list.push(payload.defaultValue);
|
|
109
111
|
break;
|
|
112
|
+
case 'insert':
|
|
113
|
+
list.splice((_payload$index = payload.index) !== null && _payload$index !== void 0 ? _payload$index : list.length, 0, payload.defaultValue);
|
|
114
|
+
break;
|
|
110
115
|
case 'replace':
|
|
111
116
|
list.splice(payload.index, 1, payload.defaultValue);
|
|
112
117
|
break;
|
package/intent.mjs
CHANGED
|
@@ -56,6 +56,7 @@ function validate(field) {
|
|
|
56
56
|
}
|
|
57
57
|
function requestIntent(form, buttonProps) {
|
|
58
58
|
if (!form) {
|
|
59
|
+
// eslint-disable-next-line no-console
|
|
59
60
|
console.warn('No form element is provided');
|
|
60
61
|
return;
|
|
61
62
|
}
|
|
@@ -96,6 +97,7 @@ function parseIntent(intent) {
|
|
|
96
97
|
return null;
|
|
97
98
|
}
|
|
98
99
|
function updateList(list, payload) {
|
|
100
|
+
var _payload$index;
|
|
99
101
|
switch (payload.operation) {
|
|
100
102
|
case 'prepend':
|
|
101
103
|
list.unshift(payload.defaultValue);
|
|
@@ -103,6 +105,9 @@ function updateList(list, payload) {
|
|
|
103
105
|
case 'append':
|
|
104
106
|
list.push(payload.defaultValue);
|
|
105
107
|
break;
|
|
108
|
+
case 'insert':
|
|
109
|
+
list.splice((_payload$index = payload.index) !== null && _payload$index !== void 0 ? _payload$index : list.length, 0, payload.defaultValue);
|
|
110
|
+
break;
|
|
106
111
|
case 'replace':
|
|
107
112
|
list.splice(payload.index, 1, payload.defaultValue);
|
|
108
113
|
break;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "A set of opinionated helpers built on top of the Constraint Validation API",
|
|
4
4
|
"homepage": "https://conform.guide",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.8.
|
|
6
|
+
"version": "0.8.2",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"module": "index.mjs",
|
|
9
9
|
"types": "index.d.ts",
|