@dwidge/json-forms-expo 0.0.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/LICENSE +23 -0
- package/README.md +30 -0
- package/dist/cjs/FileAttachment/AttachmentEdit.js +14 -0
- package/dist/cjs/FileAttachment/AttachmentEdit.js.map +1 -0
- package/dist/cjs/FileAttachment/AttachmentListEdit.js +21 -0
- package/dist/cjs/FileAttachment/AttachmentListEdit.js.map +1 -0
- package/dist/cjs/FileAttachment/AttachmentListView.js +13 -0
- package/dist/cjs/FileAttachment/AttachmentListView.js.map +1 -0
- package/dist/cjs/FileAttachment/AttachmentScreen.js +14 -0
- package/dist/cjs/FileAttachment/AttachmentScreen.js.map +1 -0
- package/dist/cjs/FileAttachment/AttachmentView.js +14 -0
- package/dist/cjs/FileAttachment/AttachmentView.js.map +1 -0
- package/dist/cjs/FileAttachment/index.js +24 -0
- package/dist/cjs/FileAttachment/index.js.map +1 -0
- package/dist/cjs/FileAttachment/useFileAttachmentUrl.js +12 -0
- package/dist/cjs/FileAttachment/useFileAttachmentUrl.js.map +1 -0
- package/dist/cjs/FileAttachment/useFileUrl.js +11 -0
- package/dist/cjs/FileAttachment/useFileUrl.js.map +1 -0
- package/dist/cjs/Form/EditFormAttachmentScreen.js +61 -0
- package/dist/cjs/Form/EditFormAttachmentScreen.js.map +1 -0
- package/dist/cjs/Form/FormEdit.js +12 -0
- package/dist/cjs/Form/FormEdit.js.map +1 -0
- package/dist/cjs/Form/FormEditScreen.js +29 -0
- package/dist/cjs/Form/FormEditScreen.js.map +1 -0
- package/dist/cjs/Form/FormListEdit.js +22 -0
- package/dist/cjs/Form/FormListEdit.js.map +1 -0
- package/dist/cjs/Form/FormListScreen.js +28 -0
- package/dist/cjs/Form/FormListScreen.js.map +1 -0
- package/dist/cjs/Form/FormListView.js +18 -0
- package/dist/cjs/Form/FormListView.js.map +1 -0
- package/dist/cjs/Form/FormSelectScreen.js +21 -0
- package/dist/cjs/Form/FormSelectScreen.js.map +1 -0
- package/dist/cjs/Form/FormSelectView.js +16 -0
- package/dist/cjs/Form/FormSelectView.js.map +1 -0
- package/dist/cjs/Form/FormView.js +12 -0
- package/dist/cjs/Form/FormView.js.map +1 -0
- package/dist/cjs/Form/index.js +26 -0
- package/dist/cjs/Form/index.js.map +1 -0
- package/dist/cjs/FormAttachment/FormAttachmentEdit.js +30 -0
- package/dist/cjs/FormAttachment/FormAttachmentEdit.js.map +1 -0
- package/dist/cjs/FormAttachment/FormAttachmentEditScreen.js +15 -0
- package/dist/cjs/FormAttachment/FormAttachmentEditScreen.js.map +1 -0
- package/dist/cjs/FormAttachment/FormAttachmentListEdit.js +27 -0
- package/dist/cjs/FormAttachment/FormAttachmentListEdit.js.map +1 -0
- package/dist/cjs/FormAttachment/FormAttachmentListScreen.js +31 -0
- package/dist/cjs/FormAttachment/FormAttachmentListScreen.js.map +1 -0
- package/dist/cjs/FormAttachment/FormAttachmentListView.js +21 -0
- package/dist/cjs/FormAttachment/FormAttachmentListView.js.map +1 -0
- package/dist/cjs/FormAttachment/FormAttachmentView.js +15 -0
- package/dist/cjs/FormAttachment/FormAttachmentView.js.map +1 -0
- package/dist/cjs/FormAttachment/index.js +23 -0
- package/dist/cjs/FormAttachment/index.js.map +1 -0
- package/dist/cjs/hooks/FileApi.js +15 -0
- package/dist/cjs/hooks/FileApi.js.map +1 -0
- package/dist/cjs/hooks/FileAttachmentApi.js +13 -0
- package/dist/cjs/hooks/FileAttachmentApi.js.map +1 -0
- package/dist/cjs/hooks/FormApi.js +13 -0
- package/dist/cjs/hooks/FormApi.js.map +1 -0
- package/dist/cjs/hooks/FormAttachmentApi.js +12 -0
- package/dist/cjs/hooks/FormAttachmentApi.js.map +1 -0
- package/dist/cjs/hooks/FormsContext.js +30 -0
- package/dist/cjs/hooks/FormsContext.js.map +1 -0
- package/dist/cjs/hooks/createApi.js +40 -0
- package/dist/cjs/hooks/createApi.js.map +1 -0
- package/dist/cjs/hooks/index.js +27 -0
- package/dist/cjs/hooks/index.js.map +1 -0
- package/dist/cjs/hooks/useCreateBlankAttachment.js +21 -0
- package/dist/cjs/hooks/useCreateBlankAttachment.js.map +1 -0
- package/dist/cjs/hooks/useCreateBlankForm.js +12 -0
- package/dist/cjs/hooks/useCreateBlankForm.js.map +1 -0
- package/dist/cjs/hooks/useCreateBlankFormAttachment.js +14 -0
- package/dist/cjs/hooks/useCreateBlankFormAttachment.js.map +1 -0
- package/dist/cjs/hooks/useParams.js +8 -0
- package/dist/cjs/hooks/useParams.js.map +1 -0
- package/dist/cjs/index.js +22 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/types/File2.js +3 -0
- package/dist/cjs/types/File2.js.map +1 -0
- package/dist/cjs/types/FileAttachment.js +3 -0
- package/dist/cjs/types/FileAttachment.js.map +1 -0
- package/dist/cjs/types/Form1.js +3 -0
- package/dist/cjs/types/Form1.js.map +1 -0
- package/dist/cjs/types/FormAttachment.js +3 -0
- package/dist/cjs/types/FormAttachment.js.map +1 -0
- package/dist/cjs/types/index.js +21 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/esm/FileAttachment/AttachmentEdit.js +10 -0
- package/dist/esm/FileAttachment/AttachmentEdit.js.map +1 -0
- package/dist/esm/FileAttachment/AttachmentListEdit.js +14 -0
- package/dist/esm/FileAttachment/AttachmentListEdit.js.map +1 -0
- package/dist/esm/FileAttachment/AttachmentListView.js +9 -0
- package/dist/esm/FileAttachment/AttachmentListView.js.map +1 -0
- package/dist/esm/FileAttachment/AttachmentScreen.js +10 -0
- package/dist/esm/FileAttachment/AttachmentScreen.js.map +1 -0
- package/dist/esm/FileAttachment/AttachmentView.js +10 -0
- package/dist/esm/FileAttachment/AttachmentView.js.map +1 -0
- package/dist/esm/FileAttachment/index.js +8 -0
- package/dist/esm/FileAttachment/index.js.map +1 -0
- package/dist/esm/FileAttachment/useFileAttachmentUrl.js +8 -0
- package/dist/esm/FileAttachment/useFileAttachmentUrl.js.map +1 -0
- package/dist/esm/FileAttachment/useFileUrl.js +7 -0
- package/dist/esm/FileAttachment/useFileUrl.js.map +1 -0
- package/dist/esm/Form/EditFormAttachmentScreen.js +57 -0
- package/dist/esm/Form/EditFormAttachmentScreen.js.map +1 -0
- package/dist/esm/Form/FormEdit.js +8 -0
- package/dist/esm/Form/FormEdit.js.map +1 -0
- package/dist/esm/Form/FormEditScreen.js +25 -0
- package/dist/esm/Form/FormEditScreen.js.map +1 -0
- package/dist/esm/Form/FormListEdit.js +15 -0
- package/dist/esm/Form/FormListEdit.js.map +1 -0
- package/dist/esm/Form/FormListScreen.js +24 -0
- package/dist/esm/Form/FormListScreen.js.map +1 -0
- package/dist/esm/Form/FormListView.js +11 -0
- package/dist/esm/Form/FormListView.js.map +1 -0
- package/dist/esm/Form/FormSelectScreen.js +17 -0
- package/dist/esm/Form/FormSelectScreen.js.map +1 -0
- package/dist/esm/Form/FormSelectView.js +12 -0
- package/dist/esm/Form/FormSelectView.js.map +1 -0
- package/dist/esm/Form/FormView.js +8 -0
- package/dist/esm/Form/FormView.js.map +1 -0
- package/dist/esm/Form/index.js +10 -0
- package/dist/esm/Form/index.js.map +1 -0
- package/dist/esm/FormAttachment/FormAttachmentEdit.js +26 -0
- package/dist/esm/FormAttachment/FormAttachmentEdit.js.map +1 -0
- package/dist/esm/FormAttachment/FormAttachmentEditScreen.js +11 -0
- package/dist/esm/FormAttachment/FormAttachmentEditScreen.js.map +1 -0
- package/dist/esm/FormAttachment/FormAttachmentListEdit.js +20 -0
- package/dist/esm/FormAttachment/FormAttachmentListEdit.js.map +1 -0
- package/dist/esm/FormAttachment/FormAttachmentListScreen.js +27 -0
- package/dist/esm/FormAttachment/FormAttachmentListScreen.js.map +1 -0
- package/dist/esm/FormAttachment/FormAttachmentListView.js +14 -0
- package/dist/esm/FormAttachment/FormAttachmentListView.js.map +1 -0
- package/dist/esm/FormAttachment/FormAttachmentView.js +11 -0
- package/dist/esm/FormAttachment/FormAttachmentView.js.map +1 -0
- package/dist/esm/FormAttachment/index.js +7 -0
- package/dist/esm/FormAttachment/index.js.map +1 -0
- package/dist/esm/hooks/FileApi.js +12 -0
- package/dist/esm/hooks/FileApi.js.map +1 -0
- package/dist/esm/hooks/FileAttachmentApi.js +10 -0
- package/dist/esm/hooks/FileAttachmentApi.js.map +1 -0
- package/dist/esm/hooks/FormApi.js +10 -0
- package/dist/esm/hooks/FormApi.js.map +1 -0
- package/dist/esm/hooks/FormAttachmentApi.js +9 -0
- package/dist/esm/hooks/FormAttachmentApi.js.map +1 -0
- package/dist/esm/hooks/FormsContext.js +26 -0
- package/dist/esm/hooks/FormsContext.js.map +1 -0
- package/dist/esm/hooks/createApi.js +36 -0
- package/dist/esm/hooks/createApi.js.map +1 -0
- package/dist/esm/hooks/index.js +11 -0
- package/dist/esm/hooks/index.js.map +1 -0
- package/dist/esm/hooks/useCreateBlankAttachment.js +14 -0
- package/dist/esm/hooks/useCreateBlankAttachment.js.map +1 -0
- package/dist/esm/hooks/useCreateBlankForm.js +8 -0
- package/dist/esm/hooks/useCreateBlankForm.js.map +1 -0
- package/dist/esm/hooks/useCreateBlankFormAttachment.js +10 -0
- package/dist/esm/hooks/useCreateBlankFormAttachment.js.map +1 -0
- package/dist/esm/hooks/useParams.js +4 -0
- package/dist/esm/hooks/useParams.js.map +1 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/types/File2.js +2 -0
- package/dist/esm/types/File2.js.map +1 -0
- package/dist/esm/types/FileAttachment.js +2 -0
- package/dist/esm/types/FileAttachment.js.map +1 -0
- package/dist/esm/types/Form1.js +2 -0
- package/dist/esm/types/Form1.js.map +1 -0
- package/dist/esm/types/FormAttachment.js +2 -0
- package/dist/esm/types/FormAttachment.js.map +1 -0
- package/dist/esm/types/index.js +5 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/FileAttachment/AttachmentEdit.d.ts +6 -0
- package/dist/types/FileAttachment/AttachmentEdit.d.ts.map +1 -0
- package/dist/types/FileAttachment/AttachmentListEdit.d.ts +9 -0
- package/dist/types/FileAttachment/AttachmentListEdit.d.ts.map +1 -0
- package/dist/types/FileAttachment/AttachmentListView.d.ts +9 -0
- package/dist/types/FileAttachment/AttachmentListView.d.ts.map +1 -0
- package/dist/types/FileAttachment/AttachmentScreen.d.ts +8 -0
- package/dist/types/FileAttachment/AttachmentScreen.d.ts.map +1 -0
- package/dist/types/FileAttachment/AttachmentView.d.ts +6 -0
- package/dist/types/FileAttachment/AttachmentView.d.ts.map +1 -0
- package/dist/types/FileAttachment/index.d.ts +8 -0
- package/dist/types/FileAttachment/index.d.ts.map +1 -0
- package/dist/types/FileAttachment/useFileAttachmentUrl.d.ts +2 -0
- package/dist/types/FileAttachment/useFileAttachmentUrl.d.ts.map +1 -0
- package/dist/types/FileAttachment/useFileUrl.d.ts +2 -0
- package/dist/types/FileAttachment/useFileUrl.d.ts.map +1 -0
- package/dist/types/Form/EditFormAttachmentScreen.d.ts +40 -0
- package/dist/types/Form/EditFormAttachmentScreen.d.ts.map +1 -0
- package/dist/types/Form/FormEdit.d.ts +4 -0
- package/dist/types/Form/FormEdit.d.ts.map +1 -0
- package/dist/types/Form/FormEditScreen.d.ts +4 -0
- package/dist/types/Form/FormEditScreen.d.ts.map +1 -0
- package/dist/types/Form/FormListEdit.d.ts +6 -0
- package/dist/types/Form/FormListEdit.d.ts.map +1 -0
- package/dist/types/Form/FormListScreen.d.ts +8 -0
- package/dist/types/Form/FormListScreen.d.ts.map +1 -0
- package/dist/types/Form/FormListView.d.ts +5 -0
- package/dist/types/Form/FormListView.d.ts.map +1 -0
- package/dist/types/Form/FormSelectScreen.d.ts +6 -0
- package/dist/types/Form/FormSelectScreen.d.ts.map +1 -0
- package/dist/types/Form/FormSelectView.d.ts +8 -0
- package/dist/types/Form/FormSelectView.d.ts.map +1 -0
- package/dist/types/Form/FormView.d.ts +5 -0
- package/dist/types/Form/FormView.d.ts.map +1 -0
- package/dist/types/Form/index.d.ts +10 -0
- package/dist/types/Form/index.d.ts.map +1 -0
- package/dist/types/FormAttachment/FormAttachmentEdit.d.ts +9 -0
- package/dist/types/FormAttachment/FormAttachmentEdit.d.ts.map +1 -0
- package/dist/types/FormAttachment/FormAttachmentEditScreen.d.ts +5 -0
- package/dist/types/FormAttachment/FormAttachmentEditScreen.d.ts.map +1 -0
- package/dist/types/FormAttachment/FormAttachmentListEdit.d.ts +11 -0
- package/dist/types/FormAttachment/FormAttachmentListEdit.d.ts.map +1 -0
- package/dist/types/FormAttachment/FormAttachmentListScreen.d.ts +7 -0
- package/dist/types/FormAttachment/FormAttachmentListScreen.d.ts.map +1 -0
- package/dist/types/FormAttachment/FormAttachmentListView.d.ts +5 -0
- package/dist/types/FormAttachment/FormAttachmentListView.d.ts.map +1 -0
- package/dist/types/FormAttachment/FormAttachmentView.d.ts +6 -0
- package/dist/types/FormAttachment/FormAttachmentView.d.ts.map +1 -0
- package/dist/types/FormAttachment/index.d.ts +7 -0
- package/dist/types/FormAttachment/index.d.ts.map +1 -0
- package/dist/types/hooks/FileApi.d.ts +35 -0
- package/dist/types/hooks/FileApi.d.ts.map +1 -0
- package/dist/types/hooks/FileAttachmentApi.d.ts +35 -0
- package/dist/types/hooks/FileAttachmentApi.d.ts.map +1 -0
- package/dist/types/hooks/FormApi.d.ts +35 -0
- package/dist/types/hooks/FormApi.d.ts.map +1 -0
- package/dist/types/hooks/FormAttachmentApi.d.ts +35 -0
- package/dist/types/hooks/FormAttachmentApi.d.ts.map +1 -0
- package/dist/types/hooks/FormsContext.d.ts +20 -0
- package/dist/types/hooks/FormsContext.d.ts.map +1 -0
- package/dist/types/hooks/createApi.d.ts +36 -0
- package/dist/types/hooks/createApi.d.ts.map +1 -0
- package/dist/types/hooks/index.d.ts +11 -0
- package/dist/types/hooks/index.d.ts.map +1 -0
- package/dist/types/hooks/useCreateBlankAttachment.d.ts +10 -0
- package/dist/types/hooks/useCreateBlankAttachment.d.ts.map +1 -0
- package/dist/types/hooks/useCreateBlankForm.d.ts +6 -0
- package/dist/types/hooks/useCreateBlankForm.d.ts.map +1 -0
- package/dist/types/hooks/useCreateBlankFormAttachment.d.ts +13 -0
- package/dist/types/hooks/useCreateBlankFormAttachment.d.ts.map +1 -0
- package/dist/types/hooks/useParams.d.ts +7 -0
- package/dist/types/hooks/useParams.d.ts.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/types/File2.d.ts +16 -0
- package/dist/types/types/File2.d.ts.map +1 -0
- package/dist/types/types/FileAttachment.d.ts +10 -0
- package/dist/types/types/FileAttachment.d.ts.map +1 -0
- package/dist/types/types/Form1.d.ts +14 -0
- package/dist/types/types/Form1.d.ts.map +1 -0
- package/dist/types/types/FormAttachment.d.ts +13 -0
- package/dist/types/types/FormAttachment.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +5 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/package.json +73 -0
- package/src/FileAttachment/AttachmentEdit.tsx +14 -0
- package/src/FileAttachment/AttachmentListEdit.tsx +45 -0
- package/src/FileAttachment/AttachmentListView.tsx +12 -0
- package/src/FileAttachment/AttachmentScreen.tsx +21 -0
- package/src/FileAttachment/AttachmentView.tsx +14 -0
- package/src/FileAttachment/index.ts +7 -0
- package/src/FileAttachment/useFileAttachmentUrl.ts +15 -0
- package/src/FileAttachment/useFileUrl.ts +12 -0
- package/src/Form/EditFormAttachmentScreen.tsx +101 -0
- package/src/Form/FormEdit.tsx +15 -0
- package/src/Form/FormEditScreen.tsx +54 -0
- package/src/Form/FormListEdit.tsx +32 -0
- package/src/Form/FormListScreen.tsx +54 -0
- package/src/Form/FormListView.tsx +23 -0
- package/src/Form/FormSelectScreen.tsx +49 -0
- package/src/Form/FormSelectView.tsx +31 -0
- package/src/Form/FormView.tsx +11 -0
- package/src/Form/index.ts +9 -0
- package/src/FormAttachment/FormAttachmentEdit.tsx +72 -0
- package/src/FormAttachment/FormAttachmentEditScreen.tsx +21 -0
- package/src/FormAttachment/FormAttachmentListEdit.tsx +40 -0
- package/src/FormAttachment/FormAttachmentListScreen.tsx +62 -0
- package/src/FormAttachment/FormAttachmentListView.tsx +30 -0
- package/src/FormAttachment/FormAttachmentView.tsx +25 -0
- package/src/FormAttachment/index.ts +6 -0
- package/src/hooks/FileApi.ts +13 -0
- package/src/hooks/FileAttachmentApi.ts +11 -0
- package/src/hooks/FormApi.ts +11 -0
- package/src/hooks/FormAttachmentApi.ts +10 -0
- package/src/hooks/FormsContext.ts +29 -0
- package/src/hooks/createApi.ts +65 -0
- package/src/hooks/index.ts +10 -0
- package/src/hooks/useCreateBlankAttachment.ts +24 -0
- package/src/hooks/useCreateBlankForm.ts +12 -0
- package/src/hooks/useCreateBlankFormAttachment.ts +20 -0
- package/src/hooks/useParams.ts +9 -0
- package/src/index.ts +5 -0
- package/src/types/File2.ts +19 -0
- package/src/types/FileAttachment.ts +9 -0
- package/src/types/Form1.ts +17 -0
- package/src/types/FormAttachment.ts +19 -0
- package/src/types/index.ts +4 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright DWJ 2024.
|
|
2
|
+
// Distributed under the Boost Software License, Version 1.0.
|
|
3
|
+
// https://www.boost.org/LICENSE_1_0.txt
|
|
4
|
+
|
|
5
|
+
import { UnstyledList, viewStyles } from "@dwidge/components-rnw";
|
|
6
|
+
import assert from "assert";
|
|
7
|
+
import { useState } from "react";
|
|
8
|
+
import { FormApi } from "../hooks/FormApi";
|
|
9
|
+
import { FormView } from "./FormView";
|
|
10
|
+
|
|
11
|
+
export const FormListView = ({
|
|
12
|
+
elements = FormApi.useGetList(),
|
|
13
|
+
selection: [selection, setSelection] = useState<string[]>([]),
|
|
14
|
+
}) => (
|
|
15
|
+
<UnstyledList
|
|
16
|
+
items={elements}
|
|
17
|
+
keyExtractor={(item) => (assert(item.id), item.id)}
|
|
18
|
+
selection={[selection, setSelection]}
|
|
19
|
+
render={(item) => <FormView form={item} />}
|
|
20
|
+
selectStyle={viewStyles.select}
|
|
21
|
+
style={viewStyles.unselect}
|
|
22
|
+
/>
|
|
23
|
+
);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Copyright DWJ 2024.
|
|
2
|
+
// Distributed under the Boost Software License, Version 1.0.
|
|
3
|
+
// https://www.boost.org/LICENSE_1_0.txt
|
|
4
|
+
|
|
5
|
+
import React, { useState } from "react";
|
|
6
|
+
import {
|
|
7
|
+
ScreenView,
|
|
8
|
+
ScrollView,
|
|
9
|
+
StyledText,
|
|
10
|
+
StyledView,
|
|
11
|
+
} from "@dwidge/components-rnw";
|
|
12
|
+
import { useNavAction2 } from "@dwidge/hooks-expo";
|
|
13
|
+
import { StyledButton } from "@dwidge/components-rnw";
|
|
14
|
+
import { FormSelectView } from "./FormSelectView";
|
|
15
|
+
import { useNavRoutes } from "../hooks/FormsContext";
|
|
16
|
+
import { StyledHeader } from "@dwidge/components-expo";
|
|
17
|
+
import { useCreateBlankFormAttachment } from "../hooks/useCreateBlankFormAttachment";
|
|
18
|
+
|
|
19
|
+
const useOnSelectForm = () =>
|
|
20
|
+
useNavAction2(
|
|
21
|
+
useNavRoutes().FORM_ATTACHMENT_EDIT_SCREEN,
|
|
22
|
+
useCreateBlankFormAttachment({}),
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export const FormSelectScreen = ({
|
|
26
|
+
onSelectForm = useOnSelectForm(),
|
|
27
|
+
selected: [selected, setSelected] = useState<string[]>([]),
|
|
28
|
+
}) => (
|
|
29
|
+
<ScreenView>
|
|
30
|
+
<StyledHeader title="Select Form" />
|
|
31
|
+
<ScrollView gap pad>
|
|
32
|
+
<StyledView>
|
|
33
|
+
<StyledText center>
|
|
34
|
+
Select from the list of forms below, or use the search option above.
|
|
35
|
+
</StyledText>
|
|
36
|
+
</StyledView>
|
|
37
|
+
<FormSelectView selected={[selected, setSelected]} />
|
|
38
|
+
<StyledButton
|
|
39
|
+
onPress={
|
|
40
|
+
selected.length > 0 && onSelectForm
|
|
41
|
+
? () => onSelectForm(selected.map((id) => ({ id })))
|
|
42
|
+
: undefined
|
|
43
|
+
}
|
|
44
|
+
>
|
|
45
|
+
Select Form
|
|
46
|
+
</StyledButton>
|
|
47
|
+
</ScrollView>
|
|
48
|
+
</ScreenView>
|
|
49
|
+
);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Copyright DWJ 2024.
|
|
2
|
+
// Distributed under the Boost Software License, Version 1.0.
|
|
3
|
+
// https://www.boost.org/LICENSE_1_0.txt
|
|
4
|
+
|
|
5
|
+
import { StyledButton } from "@dwidge/components-rnw";
|
|
6
|
+
import { ReactNode, useState } from "react";
|
|
7
|
+
import { FormApi } from "../hooks/FormApi";
|
|
8
|
+
import { FormListView } from "./FormListView";
|
|
9
|
+
|
|
10
|
+
export const FormSelectView = ({
|
|
11
|
+
formList = FormApi.useGetList(),
|
|
12
|
+
selected: [selected, setSelected] = useState<string[]>([]),
|
|
13
|
+
searchValue: [searchValue, setSearchValue] = useState(""),
|
|
14
|
+
createFormList = FormApi.useCreateList(),
|
|
15
|
+
}): ReactNode => (
|
|
16
|
+
<>
|
|
17
|
+
<FormListView
|
|
18
|
+
elements={
|
|
19
|
+
searchValue
|
|
20
|
+
? formList?.filter((form) =>
|
|
21
|
+
form.name?.toLowerCase().includes(searchValue.toLowerCase()),
|
|
22
|
+
)
|
|
23
|
+
: formList
|
|
24
|
+
}
|
|
25
|
+
selection={[selected, setSelected]}
|
|
26
|
+
/>
|
|
27
|
+
<StyledButton onPress={createFormList && (() => createFormList([{}]))}>
|
|
28
|
+
Create New Form
|
|
29
|
+
</StyledButton>
|
|
30
|
+
</>
|
|
31
|
+
);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright DWJ 2024.
|
|
2
|
+
// Distributed under the Boost Software License, Version 1.0.
|
|
3
|
+
// https://www.boost.org/LICENSE_1_0.txt
|
|
4
|
+
|
|
5
|
+
import { StyledText } from "@dwidge/components-rnw";
|
|
6
|
+
import { FormApi } from "../hooks/FormApi";
|
|
7
|
+
|
|
8
|
+
export const FormView = ({
|
|
9
|
+
form = FormApi.useGetItem(),
|
|
10
|
+
onPress = () => {},
|
|
11
|
+
}) => <StyledText>{form?.name || "untitled"}</StyledText>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./EditFormAttachmentScreen";
|
|
2
|
+
export * from "./FormEdit";
|
|
3
|
+
export * from "./FormEditScreen";
|
|
4
|
+
export * from "./FormListEdit";
|
|
5
|
+
export * from "./FormListScreen";
|
|
6
|
+
export * from "./FormListView";
|
|
7
|
+
export * from "./FormSelectScreen";
|
|
8
|
+
export * from "./FormSelectView";
|
|
9
|
+
export * from "./FormView";
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Copyright DWJ 2024.
|
|
2
|
+
// Distributed under the Boost Software License, Version 1.0.
|
|
3
|
+
// https://www.boost.org/LICENSE_1_0.txt
|
|
4
|
+
|
|
5
|
+
import { StyledButton, StyledLoader, StyledText } from "@dwidge/components-rnw";
|
|
6
|
+
import { useNavAction2 } from "@dwidge/hooks-expo";
|
|
7
|
+
import {
|
|
8
|
+
defaultFormSchemaString,
|
|
9
|
+
defaultJsonFormDataString,
|
|
10
|
+
FormSubmit,
|
|
11
|
+
} from "@dwidge/json-forms-designer";
|
|
12
|
+
import { useContext } from "react";
|
|
13
|
+
import { AttachmentListEdit } from "../FileAttachment/AttachmentListEdit";
|
|
14
|
+
import { FormApi } from "../hooks/FormApi";
|
|
15
|
+
import { FormAttachmentApi } from "../hooks/FormAttachmentApi";
|
|
16
|
+
import { FormsContext } from "../hooks/FormsContext";
|
|
17
|
+
import { useParams } from "../hooks/useParams";
|
|
18
|
+
import { FormAttachment1 } from "../types/FormAttachment";
|
|
19
|
+
|
|
20
|
+
type T = FormAttachment1 | null | undefined;
|
|
21
|
+
export const FormAttachmentEdit = ({
|
|
22
|
+
id = useParams().FormAttachmentId,
|
|
23
|
+
formAttachment: [
|
|
24
|
+
formAttachment,
|
|
25
|
+
setFormAttachment,
|
|
26
|
+
] = FormAttachmentApi.useItem(id),
|
|
27
|
+
form = FormApi.useGetItem(formAttachment?.FormId),
|
|
28
|
+
onEditForm = useNavAction2(
|
|
29
|
+
useContext(FormsContext).routes.FORM_EDIT_SCREEN,
|
|
30
|
+
async (key: string) => ({
|
|
31
|
+
FormId: key,
|
|
32
|
+
}),
|
|
33
|
+
),
|
|
34
|
+
onSaveForm = useNavAction2(
|
|
35
|
+
useContext(FormsContext).routes.FORM_ATTACHMENT_LIST_SCREEN,
|
|
36
|
+
async () => ({}),
|
|
37
|
+
),
|
|
38
|
+
}) =>
|
|
39
|
+
formAttachment === undefined || form === undefined ? (
|
|
40
|
+
<StyledLoader />
|
|
41
|
+
) : formAttachment === null || form === null ? (
|
|
42
|
+
<StyledText>No form</StyledText>
|
|
43
|
+
) : form.schema ? (
|
|
44
|
+
<>
|
|
45
|
+
<FormSubmit
|
|
46
|
+
dataString={[
|
|
47
|
+
formAttachment.data ?? defaultJsonFormDataString,
|
|
48
|
+
setFormAttachment &&
|
|
49
|
+
((data) =>
|
|
50
|
+
setFormAttachment((prev) => ({
|
|
51
|
+
...prev,
|
|
52
|
+
data:
|
|
53
|
+
typeof data === "function"
|
|
54
|
+
? data(prev?.data ?? defaultJsonFormDataString)
|
|
55
|
+
: data,
|
|
56
|
+
}))),
|
|
57
|
+
]}
|
|
58
|
+
schemaString={[form.schema ?? defaultFormSchemaString]}
|
|
59
|
+
/>
|
|
60
|
+
<AttachmentListEdit ids={{ FormAttachmentId: formAttachment.id }} />
|
|
61
|
+
<StyledButton onPress={onSaveForm}>Save</StyledButton>
|
|
62
|
+
</>
|
|
63
|
+
) : (
|
|
64
|
+
<>
|
|
65
|
+
<StyledText>This form has not been created yet.</StyledText>
|
|
66
|
+
{onEditForm && (
|
|
67
|
+
<StyledButton onPress={() => onEditForm(form.id!)}>
|
|
68
|
+
Edit Form
|
|
69
|
+
</StyledButton>
|
|
70
|
+
)}
|
|
71
|
+
</>
|
|
72
|
+
);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright DWJ 2024.
|
|
2
|
+
// Distributed under the Boost Software License, Version 1.0.
|
|
3
|
+
// https://www.boost.org/LICENSE_1_0.txt
|
|
4
|
+
|
|
5
|
+
import { StyledHeader } from "@dwidge/components-expo";
|
|
6
|
+
import { ScreenView, ScrollView } from "@dwidge/components-rnw";
|
|
7
|
+
import { FormApi } from "../hooks/FormApi";
|
|
8
|
+
import { FormAttachmentApi } from "../hooks/FormAttachmentApi";
|
|
9
|
+
import { FormAttachmentEdit } from "./FormAttachmentEdit";
|
|
10
|
+
|
|
11
|
+
export const FormAttachmentEditScreen = ({
|
|
12
|
+
formAttachment = FormAttachmentApi.useGetItem(),
|
|
13
|
+
form = FormApi.useGetItem(formAttachment?.FormId),
|
|
14
|
+
}) => (
|
|
15
|
+
<ScreenView>
|
|
16
|
+
<StyledHeader title={["Form", form?.name].filter(Boolean).join(" - ")} />
|
|
17
|
+
<ScrollView flex gap pad>
|
|
18
|
+
<FormAttachmentEdit />
|
|
19
|
+
</ScrollView>
|
|
20
|
+
</ScreenView>
|
|
21
|
+
);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Copyright DWJ 2024.
|
|
2
|
+
// Distributed under the Boost Software License, Version 1.0.
|
|
3
|
+
// https://www.boost.org/LICENSE_1_0.txt
|
|
4
|
+
|
|
5
|
+
import { StyledView, UnstyledList, viewStyles } from "@dwidge/components-rnw";
|
|
6
|
+
import { useNavAction2 } from "@dwidge/hooks-expo";
|
|
7
|
+
import { useMemoState } from "@dwidge/hooks-react";
|
|
8
|
+
import assert from "assert";
|
|
9
|
+
import { useParams } from "../hooks";
|
|
10
|
+
import { FormAttachmentApi } from "../hooks/FormAttachmentApi";
|
|
11
|
+
import { useNavRoutes } from "../hooks/FormsContext";
|
|
12
|
+
import { FormAttachmentView } from "./FormAttachmentView";
|
|
13
|
+
|
|
14
|
+
export const FormAttachmentListEdit = ({
|
|
15
|
+
ids = useParams(),
|
|
16
|
+
elements = FormAttachmentApi.useGetList({
|
|
17
|
+
id: undefined,
|
|
18
|
+
data: undefined,
|
|
19
|
+
...ids,
|
|
20
|
+
}),
|
|
21
|
+
selection: [selection, setSelection] = useMemoState<string[]>([]),
|
|
22
|
+
onPress = useNavAction2(
|
|
23
|
+
useNavRoutes().FORM_ATTACHMENT_EDIT_SCREEN,
|
|
24
|
+
async (id: string) => ({
|
|
25
|
+
FormAttachmentId: id,
|
|
26
|
+
}),
|
|
27
|
+
),
|
|
28
|
+
}) => (
|
|
29
|
+
<StyledView column>
|
|
30
|
+
<UnstyledList
|
|
31
|
+
items={elements}
|
|
32
|
+
keyExtractor={(item) => (assert(item.id), item.id)}
|
|
33
|
+
selection={[selection, setSelection]}
|
|
34
|
+
render={(item) => <FormAttachmentView id={item.id} />}
|
|
35
|
+
selectStyle={viewStyles.select}
|
|
36
|
+
style={viewStyles.unselect}
|
|
37
|
+
onPress={onPress}
|
|
38
|
+
/>
|
|
39
|
+
</StyledView>
|
|
40
|
+
);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Copyright DWJ 2024.
|
|
2
|
+
// Distributed under the Boost Software License, Version 1.0.
|
|
3
|
+
// https://www.boost.org/LICENSE_1_0.txt
|
|
4
|
+
|
|
5
|
+
import { StyledHeader } from "@dwidge/components-expo";
|
|
6
|
+
import {
|
|
7
|
+
CenterView,
|
|
8
|
+
ScreenView,
|
|
9
|
+
ScrollView,
|
|
10
|
+
StyledFontAwesome,
|
|
11
|
+
} from "@dwidge/components-rnw";
|
|
12
|
+
import { useNavAction2 } from "@dwidge/hooks-expo";
|
|
13
|
+
import { useMemoState } from "@dwidge/hooks-react";
|
|
14
|
+
import { TouchableOpacity } from "react-native";
|
|
15
|
+
import { FormAttachmentApi } from "../hooks/FormAttachmentApi";
|
|
16
|
+
import { useNavRoutes } from "../hooks/FormsContext";
|
|
17
|
+
import { FormAttachmentListEdit } from "./FormAttachmentListEdit";
|
|
18
|
+
|
|
19
|
+
export const FormAttachmentListScreen = ({
|
|
20
|
+
onCreateAttachment = useNavAction2(
|
|
21
|
+
useNavRoutes().FORM_SELECT_SCREEN,
|
|
22
|
+
async () => ({}),
|
|
23
|
+
),
|
|
24
|
+
onEditAttachment = useNavAction2(
|
|
25
|
+
useNavRoutes().FORM_ATTACHMENT_EDIT_SCREEN,
|
|
26
|
+
async (key: string) => ({
|
|
27
|
+
FormAttachmentId: key,
|
|
28
|
+
}),
|
|
29
|
+
),
|
|
30
|
+
onDeleteAttachmentList = FormAttachmentApi.useDeleteList(),
|
|
31
|
+
selection = useMemoState<string[]>([]),
|
|
32
|
+
}) => (
|
|
33
|
+
<ScreenView>
|
|
34
|
+
<StyledHeader
|
|
35
|
+
title="Manage Forms"
|
|
36
|
+
actions={[
|
|
37
|
+
{
|
|
38
|
+
icon: "remove-circle",
|
|
39
|
+
onPress:
|
|
40
|
+
onDeleteAttachmentList && selection[0].length
|
|
41
|
+
? () => onDeleteAttachmentList(selection[0].map((id) => ({ id })))
|
|
42
|
+
: undefined,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
icon: "add-circle",
|
|
46
|
+
onPress: onCreateAttachment,
|
|
47
|
+
},
|
|
48
|
+
]}
|
|
49
|
+
/>
|
|
50
|
+
<ScrollView gap>
|
|
51
|
+
<FormAttachmentListEdit
|
|
52
|
+
selection={selection}
|
|
53
|
+
onPress={onEditAttachment}
|
|
54
|
+
/>
|
|
55
|
+
<TouchableOpacity style={{ flex: 1 }} onPress={onCreateAttachment}>
|
|
56
|
+
<CenterView row gap>
|
|
57
|
+
<StyledFontAwesome name="plus" size={30} />
|
|
58
|
+
</CenterView>
|
|
59
|
+
</TouchableOpacity>
|
|
60
|
+
</ScrollView>
|
|
61
|
+
</ScreenView>
|
|
62
|
+
);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright DWJ 2024.
|
|
2
|
+
// Distributed under the Boost Software License, Version 1.0.
|
|
3
|
+
// https://www.boost.org/LICENSE_1_0.txt
|
|
4
|
+
|
|
5
|
+
import { UnstyledList, viewStyles } from "@dwidge/components-rnw";
|
|
6
|
+
import { useNavAction2 } from "@dwidge/hooks-expo";
|
|
7
|
+
import assert from "assert";
|
|
8
|
+
import { FormAttachmentApi } from "../hooks/FormAttachmentApi";
|
|
9
|
+
import { useNavRoutes } from "../hooks/FormsContext";
|
|
10
|
+
import { FormAttachmentView } from "./FormAttachmentView";
|
|
11
|
+
|
|
12
|
+
export const FormAttachmentListView = ({
|
|
13
|
+
attachments = FormAttachmentApi.useGetList({}),
|
|
14
|
+
onPressItem = useNavAction2(
|
|
15
|
+
useNavRoutes().FORM_ATTACHMENT_EDIT_SCREEN,
|
|
16
|
+
async (id: string) => ({
|
|
17
|
+
FormAttachmentId: id,
|
|
18
|
+
}),
|
|
19
|
+
),
|
|
20
|
+
}) => (
|
|
21
|
+
<UnstyledList
|
|
22
|
+
items={attachments}
|
|
23
|
+
keyExtractor={(item) => (assert(item.id), item.id)}
|
|
24
|
+
selection={[[], () => {}]}
|
|
25
|
+
render={(item) => <FormAttachmentView id={item.id} />}
|
|
26
|
+
selectStyle={viewStyles.select}
|
|
27
|
+
style={viewStyles.unselect}
|
|
28
|
+
onPress={onPressItem}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright DWJ 2024.
|
|
2
|
+
// Distributed under the Boost Software License, Version 1.0.
|
|
3
|
+
// https://www.boost.org/LICENSE_1_0.txt
|
|
4
|
+
|
|
5
|
+
import { StyledDate } from "@dwidge/components-expo";
|
|
6
|
+
import { StyledLoader, StyledText, StyledView } from "@dwidge/components-rnw";
|
|
7
|
+
import { FormApi } from "../hooks/FormApi";
|
|
8
|
+
import { FormAttachmentApi } from "../hooks/FormAttachmentApi";
|
|
9
|
+
import { useParams } from "../hooks/useParams";
|
|
10
|
+
|
|
11
|
+
export const FormAttachmentView = ({
|
|
12
|
+
id = useParams().FormAttachmentId,
|
|
13
|
+
attachment: [attachment, setAttachment] = FormAttachmentApi.useItem(id),
|
|
14
|
+
form = FormApi.useGetItem(attachment?.FormId),
|
|
15
|
+
}) =>
|
|
16
|
+
attachment && form ? (
|
|
17
|
+
<StyledView space outline gap pad flex>
|
|
18
|
+
<StyledText>{form.name || "untitled"}</StyledText>
|
|
19
|
+
{attachment.createdAt && (
|
|
20
|
+
<StyledDate>{attachment.createdAt * 1000}</StyledDate>
|
|
21
|
+
)}
|
|
22
|
+
</StyledView>
|
|
23
|
+
) : (
|
|
24
|
+
<StyledLoader />
|
|
25
|
+
);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { File2 } from "../types/File2.js";
|
|
2
|
+
import { createApi } from "./createApi.js";
|
|
3
|
+
|
|
4
|
+
export const FileApi = createApi<File2>({
|
|
5
|
+
id: undefined,
|
|
6
|
+
createdAt: undefined,
|
|
7
|
+
createdBy: undefined,
|
|
8
|
+
size: undefined,
|
|
9
|
+
mime: undefined,
|
|
10
|
+
sha256: undefined,
|
|
11
|
+
putUrl: undefined,
|
|
12
|
+
getUrl: undefined,
|
|
13
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FileAttachment } from "../types/FileAttachment.js";
|
|
2
|
+
import { createApi } from "./createApi.js";
|
|
3
|
+
|
|
4
|
+
export const FileAttachmentApi = createApi<FileAttachment>({
|
|
5
|
+
id: undefined,
|
|
6
|
+
createdAt: undefined,
|
|
7
|
+
createdBy: undefined,
|
|
8
|
+
FileId: undefined,
|
|
9
|
+
FormId: undefined,
|
|
10
|
+
FormAttachmentId: undefined,
|
|
11
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Form1 } from "../types/Form1.js";
|
|
2
|
+
import { createApi } from "./createApi.js";
|
|
3
|
+
|
|
4
|
+
export const FormApi = createApi<Form1>({
|
|
5
|
+
id: undefined,
|
|
6
|
+
createdAt: undefined,
|
|
7
|
+
createdBy: undefined,
|
|
8
|
+
name: undefined,
|
|
9
|
+
type: undefined,
|
|
10
|
+
schema: undefined,
|
|
11
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FormAttachment1 } from "../types/FormAttachment.js";
|
|
2
|
+
import { createApi } from "./createApi.js";
|
|
3
|
+
|
|
4
|
+
export const FormAttachmentApi = createApi<FormAttachment1>({
|
|
5
|
+
id: undefined,
|
|
6
|
+
createdAt: undefined,
|
|
7
|
+
createdBy: undefined,
|
|
8
|
+
FormId: undefined,
|
|
9
|
+
data: undefined,
|
|
10
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright DWJ 2024.
|
|
2
|
+
// Distributed under the Boost Software License, Version 1.0.
|
|
3
|
+
// https://www.boost.org/LICENSE_1_0.txt
|
|
4
|
+
|
|
5
|
+
import { useLocalSearchParams } from "expo-router";
|
|
6
|
+
import { createContext, useContext } from "react";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
|
|
9
|
+
export const FormsContext = createContext({
|
|
10
|
+
routes: {
|
|
11
|
+
FORM_ATTACHMENT_LIST_SCREEN: "",
|
|
12
|
+
FORM_ATTACHMENT_EDIT_SCREEN: "",
|
|
13
|
+
FORM_EDIT_SCREEN: "",
|
|
14
|
+
FORM_SELECT_SCREEN: "",
|
|
15
|
+
},
|
|
16
|
+
useParams: () =>
|
|
17
|
+
z
|
|
18
|
+
.object({
|
|
19
|
+
FormId: z.coerce.string().nullable(),
|
|
20
|
+
FormAttachmentId: z.coerce.string().nullable(),
|
|
21
|
+
AttachmentId: z.coerce.string().nullable(),
|
|
22
|
+
})
|
|
23
|
+
.partial()
|
|
24
|
+
.parse({
|
|
25
|
+
...useLocalSearchParams(),
|
|
26
|
+
}) satisfies Record<string, string | number | null>,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export const useNavRoutes = () => useContext(FormsContext).routes;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { AsyncState, useAsyncSaveState } from "@dwidge/hooks-react";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
import { useParams } from "./useParams";
|
|
4
|
+
|
|
5
|
+
export type ApiItem = Record<string, string | number | boolean | null>;
|
|
6
|
+
|
|
7
|
+
export const createApi = <T extends ApiItem>(
|
|
8
|
+
defaultFilter: Partial<T> = {},
|
|
9
|
+
) => {
|
|
10
|
+
type Get = Partial<T>;
|
|
11
|
+
type Set = Omit<Get, "createdAt" | "createdBy">;
|
|
12
|
+
type Key = Pick<Get, "id">;
|
|
13
|
+
type Filter = Get;
|
|
14
|
+
|
|
15
|
+
getList: (filter?: Filter) => Promise<Get[]>;
|
|
16
|
+
setList: (list: Set[]) => Promise<(Key | null)[]>;
|
|
17
|
+
createList: (list: Set[]) => Promise<(Key | null)[]>;
|
|
18
|
+
updateList: (list: Set[]) => Promise<(Key | null)[]>;
|
|
19
|
+
deleteList: (list: Key[]) => Promise<(Key | null)[]>;
|
|
20
|
+
getItem: (item: Filter & Key) => Promise<Get | null>;
|
|
21
|
+
updateItem: (item: Set) => Promise<Key | null>;
|
|
22
|
+
deleteItem: (item: Key) => Promise<Key | null>;
|
|
23
|
+
|
|
24
|
+
const message =
|
|
25
|
+
"createApiW1: Please wrap App with <Context.Provider value={{}}></Context.Provider>";
|
|
26
|
+
|
|
27
|
+
const Context = createContext<{
|
|
28
|
+
useGetList: (filter?: Filter) => undefined | Get[];
|
|
29
|
+
useCreateList: () => ((list: Set[]) => Promise<(Get | null)[]>) | undefined;
|
|
30
|
+
useDeleteList: () => ((list: Key[]) => Promise<(Get | null)[]>) | undefined;
|
|
31
|
+
useGetItem: (key?: Filter & Key) => undefined | Get | null;
|
|
32
|
+
useItem: (key?: Get) => AsyncState<Get | null>;
|
|
33
|
+
}>({
|
|
34
|
+
useGetList: () => (console.warn(message), undefined),
|
|
35
|
+
useCreateList: () => (console.warn(message), undefined),
|
|
36
|
+
useDeleteList: () => (console.warn(message), undefined),
|
|
37
|
+
useGetItem: () => (console.warn(message), undefined),
|
|
38
|
+
useItem: () => (console.warn(message), []),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const useGetList = (filter: Filter = {}, ids = useParams()) =>
|
|
42
|
+
useContext(Context).useGetList({ ...ids, ...defaultFilter, ...filter });
|
|
43
|
+
const useCreateList = () => useContext(Context).useCreateList();
|
|
44
|
+
const useDeleteList = () => useContext(Context).useDeleteList();
|
|
45
|
+
const useGetItem = (id?: Key["id"] | null, ids = useParams()) =>
|
|
46
|
+
useContext(Context).useGetItem(
|
|
47
|
+
id ? { ...ids, ...defaultFilter, id } : undefined,
|
|
48
|
+
);
|
|
49
|
+
const useItem = (id?: Key["id"] | null, ids = useParams()) =>
|
|
50
|
+
useAsyncSaveState(
|
|
51
|
+
useContext(Context).useItem(
|
|
52
|
+
id ? { ...ids, ...defaultFilter, id } : undefined,
|
|
53
|
+
),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
Context,
|
|
58
|
+
Provider: Context.Provider,
|
|
59
|
+
useGetList,
|
|
60
|
+
useGetItem,
|
|
61
|
+
useItem,
|
|
62
|
+
useCreateList,
|
|
63
|
+
useDeleteList,
|
|
64
|
+
};
|
|
65
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./FileApi";
|
|
2
|
+
export * from "./FileAttachmentApi";
|
|
3
|
+
export * from "./FormApi";
|
|
4
|
+
export * from "./FormAttachmentApi";
|
|
5
|
+
export * from "./FormsContext";
|
|
6
|
+
export * from "./createApi";
|
|
7
|
+
export * from "./useCreateBlankAttachment";
|
|
8
|
+
export * from "./useCreateBlankForm";
|
|
9
|
+
export * from "./useCreateBlankFormAttachment";
|
|
10
|
+
export * from "./useParams";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import { useParams } from "./useParams";
|
|
3
|
+
import { FileApi } from "./FileApi";
|
|
4
|
+
import { FileAttachmentApi } from "./FileAttachmentApi";
|
|
5
|
+
|
|
6
|
+
export const useCreateBlankAttachment = ({
|
|
7
|
+
createAttachmentList = FileAttachmentApi.useCreateList(),
|
|
8
|
+
createFileList = FileApi.useCreateList(),
|
|
9
|
+
AttachIds = useParams(),
|
|
10
|
+
} = {}) =>
|
|
11
|
+
createAttachmentList && createFileList
|
|
12
|
+
? () =>
|
|
13
|
+
createFileList([{}]).then(
|
|
14
|
+
([file]) => (
|
|
15
|
+
assert(file),
|
|
16
|
+
createAttachmentList([
|
|
17
|
+
{
|
|
18
|
+
FileId: file.id,
|
|
19
|
+
...AttachIds,
|
|
20
|
+
},
|
|
21
|
+
]).then(([r]) => r)
|
|
22
|
+
),
|
|
23
|
+
)
|
|
24
|
+
: undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright DWJ 2024.
|
|
2
|
+
// Distributed under the Boost Software License, Version 1.0.
|
|
3
|
+
// https://www.boost.org/LICENSE_1_0.txt
|
|
4
|
+
|
|
5
|
+
import { FormApi } from "./FormApi";
|
|
6
|
+
|
|
7
|
+
export const useCreateBlankForm = ({
|
|
8
|
+
createFormList = FormApi.useCreateList(),
|
|
9
|
+
} = {}) =>
|
|
10
|
+
createFormList
|
|
11
|
+
? () => createFormList([{}]).then(([form]) => ({ FormId: form?.id }))
|
|
12
|
+
: () => undefined;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Copyright DWJ 2024.
|
|
2
|
+
// Distributed under the Boost Software License, Version 1.0.
|
|
3
|
+
// https://www.boost.org/LICENSE_1_0.txt
|
|
4
|
+
|
|
5
|
+
import { Form1Key } from "../types/Form1";
|
|
6
|
+
import { FormApi } from "./FormApi";
|
|
7
|
+
import { FormAttachmentApi } from "./FormAttachmentApi";
|
|
8
|
+
import { useParams } from "./useParams";
|
|
9
|
+
|
|
10
|
+
export const useCreateBlankFormAttachment = ({
|
|
11
|
+
createFormList = FormApi.useCreateList(),
|
|
12
|
+
createAttachmentList = FormAttachmentApi.useCreateList(),
|
|
13
|
+
AttachmentIds = useParams(),
|
|
14
|
+
} = {}) =>
|
|
15
|
+
createFormList && createAttachmentList
|
|
16
|
+
? async (forms: Form1Key[]) =>
|
|
17
|
+
createAttachmentList(
|
|
18
|
+
forms.map((form) => ({ ...AttachmentIds, FormId: form.id })),
|
|
19
|
+
).then(([r]) => ({ FormAttachmentId: r?.id }))
|
|
20
|
+
: async () => undefined;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { FormsContext } from "./FormsContext";
|
|
3
|
+
|
|
4
|
+
export type Params = Record<string, string | number | null | undefined>;
|
|
5
|
+
export const useParams = (): Params & {
|
|
6
|
+
AttachmentId?: string | null | undefined;
|
|
7
|
+
FormId?: string | null | undefined;
|
|
8
|
+
FormAttachmentId?: string | null | undefined;
|
|
9
|
+
} => useContext(FormsContext).useParams();
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type File2 = {
|
|
2
|
+
id: string;
|
|
3
|
+
created: boolean;
|
|
4
|
+
createdAt: number;
|
|
5
|
+
createdBy: number | null;
|
|
6
|
+
size: number | null;
|
|
7
|
+
mime: string | null;
|
|
8
|
+
sha256: string | null;
|
|
9
|
+
getUrl: string | null;
|
|
10
|
+
putUrl: string | null;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type File2Get = Partial<File2>;
|
|
14
|
+
|
|
15
|
+
export type File2Set = Omit<File2Get, "createdAt" | "createdBy">;
|
|
16
|
+
|
|
17
|
+
export type File2Key = Pick<File2Get, "id">;
|
|
18
|
+
|
|
19
|
+
export type File2Filter = File2Get;
|