@devvit/shared-types 0.10.23-next-2024-06-24-3b95d192f.0 → 0.10.23-next-2024-06-25-2d3ae1206.0
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +4 -4
- package/useForm.d.ts +4 -0
- package/useForm.d.ts.map +1 -0
- package/useForm.js +18 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@devvit/shared-types",
|
3
|
-
"version": "0.10.23-next-2024-06-
|
3
|
+
"version": "0.10.23-next-2024-06-25-2d3ae1206.0",
|
4
4
|
"license": "BSD-3-Clause",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -23,12 +23,12 @@
|
|
23
23
|
},
|
24
24
|
"types": "./index.d.ts",
|
25
25
|
"dependencies": {
|
26
|
-
"@devvit/protos": "0.10.23-next-2024-06-
|
26
|
+
"@devvit/protos": "0.10.23-next-2024-06-25-2d3ae1206.0"
|
27
27
|
},
|
28
28
|
"devDependencies": {
|
29
29
|
"@devvit/eslint-config": "0.10.22",
|
30
30
|
"@devvit/repo-tools": "0.10.22",
|
31
|
-
"@devvit/tsconfig": "0.10.23-next-2024-06-
|
31
|
+
"@devvit/tsconfig": "0.10.23-next-2024-06-25-2d3ae1206.0",
|
32
32
|
"@types/redis-mock": "0.17.1",
|
33
33
|
"eslint": "8.9.0",
|
34
34
|
"lit": "2.2.8",
|
@@ -41,5 +41,5 @@
|
|
41
41
|
"directory": "dist"
|
42
42
|
},
|
43
43
|
"source": "./src/index.ts",
|
44
|
-
"gitHead": "
|
44
|
+
"gitHead": "1c77da0a8e5ff2a2e1e58740f0bd95ec131d9984"
|
45
45
|
}
|
package/useForm.d.ts
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
/** A unique key generated by `Devvit.createForm` or the `useForm` hook. */
|
2
|
+
export type FormKey = `form.${number}` | `form.hook.${string}.${number}`;
|
3
|
+
export declare function formKeyToHookId(formKey: string | FormKey): string | undefined;
|
4
|
+
//# sourceMappingURL=useForm.d.ts.map
|
package/useForm.d.ts.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../src/useForm.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,MAAM,MAAM,OAAO,GAAG,QAAQ,MAAM,EAAE,GAAG,aAAa,MAAM,IAAI,MAAM,EAAE,CAAC;AAEzE,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAqB7E"}
|
package/useForm.js
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
export function formKeyToHookId(formKey) {
|
2
|
+
// extract the hook id from the form key with a regex
|
3
|
+
const match = formKey.match(/form\.hook\.(.+)\.0/);
|
4
|
+
console.log('formKey', formKey, 'match', match);
|
5
|
+
/**
|
6
|
+
* It's tempting to throw here, but it will be RenderPost. All events for RenderPost flow to RenderPostContent
|
7
|
+
* lands in `Devvit.ts`. That means form ids flow through here and in the new world we've changed what a hook ID looks
|
8
|
+
* like. For now, we warn until the migration is complete and can later on turn this into a throw.
|
9
|
+
*/
|
10
|
+
if (!match?.[1]) {
|
11
|
+
// This shows on every form submit in RenderPost so just going to leave it out
|
12
|
+
// console.warn(
|
13
|
+
// `Could not parse a hook ref from form key '${formKey}'. Please make sure you are passing in a string that starts with 'form.hook.' and ends with '0'. If you are seeing this warning using RenderPost, it is safe to ignore.`
|
14
|
+
// );
|
15
|
+
return;
|
16
|
+
}
|
17
|
+
return match[1];
|
18
|
+
}
|