matsuri-forms-sdk 0.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.
- package/MatsuriFormsQuestion.d.ts +3 -0
- package/MatsuriFormsQuestion.js +26 -0
- package/MatsuriFormsQuestion.js.map +1 -0
- package/MatsuriFormsQuestionProvider.d.ts +26 -0
- package/MatsuriFormsQuestionProvider.js +20 -0
- package/MatsuriFormsQuestionProvider.js.map +1 -0
- package/README.md +1 -0
- package/cjs/MatsuriFormsQuestion.js +33 -0
- package/cjs/MatsuriFormsQuestion.js.map +1 -0
- package/cjs/MatsuriFormsQuestionProvider.js +28 -0
- package/cjs/MatsuriFormsQuestionProvider.js.map +1 -0
- package/cjs/endpoints/index.js +34 -0
- package/cjs/endpoints/index.js.map +1 -0
- package/cjs/helpers/assetIsDefined.js +12 -0
- package/cjs/helpers/assetIsDefined.js.map +1 -0
- package/cjs/index.js +34 -0
- package/cjs/index.js.map +1 -0
- package/cjs/model/form.js +6 -0
- package/cjs/model/form.js.map +1 -0
- package/cjs/model/parsedQuestion.js +42 -0
- package/cjs/model/parsedQuestion.js.map +1 -0
- package/cjs/model/question.js +6 -0
- package/cjs/model/question.js.map +1 -0
- package/cjs/useMatsuriForms.js +114 -0
- package/cjs/useMatsuriForms.js.map +1 -0
- package/endpoints/index.d.ts +9 -0
- package/endpoints/index.js +26 -0
- package/endpoints/index.js.map +1 -0
- package/esm/MatsuriFormsQuestion.js +26 -0
- package/esm/MatsuriFormsQuestion.js.map +1 -0
- package/esm/MatsuriFormsQuestionProvider.js +20 -0
- package/esm/MatsuriFormsQuestionProvider.js.map +1 -0
- package/esm/endpoints/index.js +26 -0
- package/esm/endpoints/index.js.map +1 -0
- package/esm/helpers/assetIsDefined.js +6 -0
- package/esm/helpers/assetIsDefined.js.map +1 -0
- package/esm/index.js +5 -0
- package/esm/index.js.map +1 -0
- package/esm/model/form.js +2 -0
- package/esm/model/form.js.map +1 -0
- package/esm/model/parsedQuestion.js +40 -0
- package/esm/model/parsedQuestion.js.map +1 -0
- package/esm/model/question.js +2 -0
- package/esm/model/question.js.map +1 -0
- package/esm/useMatsuriForms.js +116 -0
- package/esm/useMatsuriForms.js.map +1 -0
- package/helpers/assetIsDefined.d.ts +1 -0
- package/helpers/assetIsDefined.js +6 -0
- package/helpers/assetIsDefined.js.map +1 -0
- package/index.d.ts +8 -0
- package/index.js +5 -0
- package/index.js.map +1 -0
- package/model/form.d.ts +24 -0
- package/model/form.js +2 -0
- package/model/form.js.map +1 -0
- package/model/parsedQuestion.d.ts +29 -0
- package/model/parsedQuestion.js +40 -0
- package/model/parsedQuestion.js.map +1 -0
- package/model/question.d.ts +42 -0
- package/model/question.js +2 -0
- package/model/question.js.map +1 -0
- package/package.json +48 -0
- package/types/MatsuriFormsQuestion.d.ts +3 -0
- package/types/MatsuriFormsQuestionProvider.d.ts +26 -0
- package/types/endpoints/index.d.ts +9 -0
- package/types/helpers/assetIsDefined.d.ts +1 -0
- package/types/index.d.ts +8 -0
- package/types/model/form.d.ts +24 -0
- package/types/model/parsedQuestion.d.ts +29 -0
- package/types/model/question.d.ts +42 -0
- package/types/useMatsuriForms.d.ts +18 -0
- package/useMatsuriForms.d.ts +18 -0
- package/useMatsuriForms.js +116 -0
- package/useMatsuriForms.js.map +1 -0
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { MatsuriFormsMultilineTextQuestionProps, MatsuriFormsSelectQuestionProps, MatsuriFormsTextQuestionProps } from "./MatsuriFormsQuestionProvider";
|
|
2
|
+
export type MatsuriFormsQuestionProps = MatsuriFormsTextQuestionProps | MatsuriFormsMultilineTextQuestionProps | MatsuriFormsSelectQuestionProps;
|
|
3
|
+
export declare const MatsuriFormsQuestion: (props: MatsuriFormsQuestionProps) => JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MatsuriFormsQuestionContext } from "./MatsuriFormsQuestionProvider";
|
|
2
|
+
import { assertIsDefined } from "./helpers/assetIsDefined";
|
|
3
|
+
import { useContext } from "react";
|
|
4
|
+
export var MatsuriFormsQuestion = props => {
|
|
5
|
+
var context = useContext(MatsuriFormsQuestionContext);
|
|
6
|
+
assertIsDefined(context);
|
|
7
|
+
switch (props.questionType) {
|
|
8
|
+
case "multilineText":
|
|
9
|
+
{
|
|
10
|
+
return context.renderMultilineText(props);
|
|
11
|
+
}
|
|
12
|
+
case "text":
|
|
13
|
+
{
|
|
14
|
+
return context.renderText(props);
|
|
15
|
+
}
|
|
16
|
+
case "select":
|
|
17
|
+
{
|
|
18
|
+
return context.renderSelect(props);
|
|
19
|
+
}
|
|
20
|
+
default:
|
|
21
|
+
{
|
|
22
|
+
throw new Error("Unknown question type");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=MatsuriFormsQuestion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MatsuriFormsQuestion.js","names":["MatsuriFormsQuestionContext","assertIsDefined","useContext","MatsuriFormsQuestion","props","context","questionType","renderMultilineText","renderText","renderSelect","Error"],"sources":["../../src/MatsuriFormsQuestion.tsx"],"sourcesContent":["import {\n MatsuriFormsMultilineTextQuestionProps,\n MatsuriFormsSelectQuestionProps,\n MatsuriFormsTextQuestionProps,\n} from \"./MatsuriFormsQuestionProvider\";\nimport { MatsuriFormsQuestionContext } from \"./MatsuriFormsQuestionProvider\";\nimport { assertIsDefined } from \"./helpers/assetIsDefined\";\nimport { useContext } from \"react\";\n\nexport type MatsuriFormsQuestionProps =\n | MatsuriFormsTextQuestionProps\n | MatsuriFormsMultilineTextQuestionProps\n | MatsuriFormsSelectQuestionProps;\n\nexport const MatsuriFormsQuestion = (props: MatsuriFormsQuestionProps) => {\n const context = useContext(MatsuriFormsQuestionContext);\n assertIsDefined(context);\n\n switch (props.questionType) {\n case \"multilineText\": {\n return context.renderMultilineText(props);\n }\n case \"text\": {\n return context.renderText(props);\n }\n case \"select\": {\n return context.renderSelect(props);\n }\n default: {\n throw new Error(\"Unknown question type\");\n }\n }\n};\n"],"mappings":"AAKA,SAASA,2BAA2B,QAAQ,gCAAgC;AAC5E,SAASC,eAAe,QAAQ,0BAA0B;AAC1D,SAASC,UAAU,QAAQ,OAAO;AAOlC,OAAO,IAAMC,oBAAoB,GAAIC,KAAgC,IAAK;EACxE,IAAMC,OAAO,GAAGH,UAAU,CAACF,2BAA2B,CAAC;EACvDC,eAAe,CAACI,OAAO,CAAC;EAExB,QAAQD,KAAK,CAACE,YAAY;IACxB,KAAK,eAAe;MAAE;QACpB,OAAOD,OAAO,CAACE,mBAAmB,CAACH,KAAK,CAAC;MAC3C;IACA,KAAK,MAAM;MAAE;QACX,OAAOC,OAAO,CAACG,UAAU,CAACJ,KAAK,CAAC;MAClC;IACA,KAAK,QAAQ;MAAE;QACb,OAAOC,OAAO,CAACI,YAAY,CAACL,KAAK,CAAC;MACpC;IACA;MAAS;QACP,MAAM,IAAIM,KAAK,CAAC,uBAAuB,CAAC;MAC1C;EAAC;AAEL,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ParsedMultilineTextQuestion, ParsedSelectQuestion, ParsedTextQuestion } from "./model/parsedQuestion";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export interface MatsuriFormsQuestionError {
|
|
4
|
+
code: "required" | "too_many";
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
export interface MatsuriFormsQuestionCommonProps {
|
|
8
|
+
error?: MatsuriFormsQuestionError;
|
|
9
|
+
}
|
|
10
|
+
export interface MatsuriFormsSelectQuestionProps extends ParsedSelectQuestion, MatsuriFormsQuestionCommonProps {
|
|
11
|
+
}
|
|
12
|
+
export interface MatsuriFormsTextQuestionProps extends ParsedTextQuestion, MatsuriFormsQuestionCommonProps {
|
|
13
|
+
}
|
|
14
|
+
export interface MatsuriFormsMultilineTextQuestionProps extends ParsedMultilineTextQuestion, MatsuriFormsQuestionCommonProps {
|
|
15
|
+
}
|
|
16
|
+
interface MatsuriFormsQuestionContextValue {
|
|
17
|
+
renderMultilineText: (props: MatsuriFormsMultilineTextQuestionProps) => JSX.Element;
|
|
18
|
+
renderText: (props: MatsuriFormsTextQuestionProps) => JSX.Element;
|
|
19
|
+
renderSelect: (props: MatsuriFormsSelectQuestionProps) => JSX.Element;
|
|
20
|
+
}
|
|
21
|
+
export declare const MatsuriFormsQuestionContext: React.Context<MatsuriFormsQuestionContextValue | null>;
|
|
22
|
+
interface MatsuriFormsQuestionProviderProps extends MatsuriFormsQuestionContextValue {
|
|
23
|
+
children?: React.ReactNode;
|
|
24
|
+
}
|
|
25
|
+
export declare const MatsuriFormsQuestionProvider: ({ children, renderText, renderMultilineText, renderSelect, }: MatsuriFormsQuestionProviderProps) => JSX.Element;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
export var MatsuriFormsQuestionContext = /*#__PURE__*/React.createContext(null);
|
|
4
|
+
export var MatsuriFormsQuestionProvider = _ref => {
|
|
5
|
+
var {
|
|
6
|
+
children,
|
|
7
|
+
renderText,
|
|
8
|
+
renderMultilineText,
|
|
9
|
+
renderSelect
|
|
10
|
+
} = _ref;
|
|
11
|
+
return /*#__PURE__*/_jsx(MatsuriFormsQuestionContext.Provider, {
|
|
12
|
+
value: {
|
|
13
|
+
renderText,
|
|
14
|
+
renderMultilineText,
|
|
15
|
+
renderSelect
|
|
16
|
+
},
|
|
17
|
+
children: children
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=MatsuriFormsQuestionProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MatsuriFormsQuestionProvider.js","names":["React","jsx","_jsx","MatsuriFormsQuestionContext","createContext","MatsuriFormsQuestionProvider","_ref","children","renderText","renderMultilineText","renderSelect","Provider","value"],"sources":["../../src/MatsuriFormsQuestionProvider.tsx"],"sourcesContent":["import {\n ParsedMultilineTextQuestion,\n ParsedSelectQuestion,\n ParsedTextQuestion,\n} from \"./model/parsedQuestion\";\nimport React from \"react\";\n\nexport interface MatsuriFormsQuestionError {\n code: \"required\" | \"too_many\";\n message: string;\n}\n\nexport interface MatsuriFormsQuestionCommonProps {\n error?: MatsuriFormsQuestionError;\n}\nexport interface MatsuriFormsSelectQuestionProps\n extends ParsedSelectQuestion,\n MatsuriFormsQuestionCommonProps {}\nexport interface MatsuriFormsTextQuestionProps\n extends ParsedTextQuestion,\n MatsuriFormsQuestionCommonProps {}\nexport interface MatsuriFormsMultilineTextQuestionProps\n extends ParsedMultilineTextQuestion,\n MatsuriFormsQuestionCommonProps {}\ninterface MatsuriFormsQuestionContextValue {\n renderMultilineText: (\n props: MatsuriFormsMultilineTextQuestionProps\n ) => JSX.Element;\n renderText: (props: MatsuriFormsTextQuestionProps) => JSX.Element;\n renderSelect: (props: MatsuriFormsSelectQuestionProps) => JSX.Element;\n}\nexport const MatsuriFormsQuestionContext =\n React.createContext<MatsuriFormsQuestionContextValue | null>(null);\ninterface MatsuriFormsQuestionProviderProps\n extends MatsuriFormsQuestionContextValue {\n children?: React.ReactNode;\n}\n\nexport const MatsuriFormsQuestionProvider = ({\n children,\n renderText,\n renderMultilineText,\n renderSelect,\n}: MatsuriFormsQuestionProviderProps) => {\n return (\n <MatsuriFormsQuestionContext.Provider\n value={{\n renderText,\n renderMultilineText,\n renderSelect,\n }}\n >\n {children}\n </MatsuriFormsQuestionContext.Provider>\n );\n};\n"],"mappings":"AAKA,OAAOA,KAAK,MAAM,OAAO;AAAC,SAAAC,GAAA,IAAAC,IAAA;AA0B1B,OAAO,IAAMC,2BAA2B,gBACtCH,KAAK,CAACI,aAAa,CAA0C,IAAI,CAAC;AAMpE,OAAO,IAAMC,4BAA4B,GAAGC,IAAA,IAKH;EAAA,IALI;IAC3CC,QAAQ;IACRC,UAAU;IACVC,mBAAmB;IACnBC;EACiC,CAAC,GAAAJ,IAAA;EAClC,oBACEJ,IAAA,CAACC,2BAA2B,CAACQ,QAAQ;IACnCC,KAAK,EAAE;MACLJ,UAAU;MACVC,mBAAmB;MACnBC;IACF,CAAE;IAAAH,QAAA,EAEDA;EAAQ,EAC4B;AAE3C,CAAC"}
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# matsuri-forms-sdk
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MatsuriFormsQuestion = void 0;
|
|
7
|
+
var _MatsuriFormsQuestionProvider = require("./MatsuriFormsQuestionProvider");
|
|
8
|
+
var _assetIsDefined = require("./helpers/assetIsDefined");
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
const MatsuriFormsQuestion = props => {
|
|
11
|
+
const context = (0, _react.useContext)(_MatsuriFormsQuestionProvider.MatsuriFormsQuestionContext);
|
|
12
|
+
(0, _assetIsDefined.assertIsDefined)(context);
|
|
13
|
+
switch (props.questionType) {
|
|
14
|
+
case "multilineText":
|
|
15
|
+
{
|
|
16
|
+
return context.renderMultilineText(props);
|
|
17
|
+
}
|
|
18
|
+
case "text":
|
|
19
|
+
{
|
|
20
|
+
return context.renderText(props);
|
|
21
|
+
}
|
|
22
|
+
case "select":
|
|
23
|
+
{
|
|
24
|
+
return context.renderSelect(props);
|
|
25
|
+
}
|
|
26
|
+
default:
|
|
27
|
+
{
|
|
28
|
+
throw new Error("Unknown question type");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
exports.MatsuriFormsQuestion = MatsuriFormsQuestion;
|
|
33
|
+
//# sourceMappingURL=MatsuriFormsQuestion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MatsuriFormsQuestion.js","names":["_MatsuriFormsQuestionProvider","require","_assetIsDefined","_react","MatsuriFormsQuestion","props","context","useContext","MatsuriFormsQuestionContext","assertIsDefined","questionType","renderMultilineText","renderText","renderSelect","Error","exports"],"sources":["../../src/MatsuriFormsQuestion.tsx"],"sourcesContent":["import {\n MatsuriFormsMultilineTextQuestionProps,\n MatsuriFormsSelectQuestionProps,\n MatsuriFormsTextQuestionProps,\n} from \"./MatsuriFormsQuestionProvider\";\nimport { MatsuriFormsQuestionContext } from \"./MatsuriFormsQuestionProvider\";\nimport { assertIsDefined } from \"./helpers/assetIsDefined\";\nimport { useContext } from \"react\";\n\nexport type MatsuriFormsQuestionProps =\n | MatsuriFormsTextQuestionProps\n | MatsuriFormsMultilineTextQuestionProps\n | MatsuriFormsSelectQuestionProps;\n\nexport const MatsuriFormsQuestion = (props: MatsuriFormsQuestionProps) => {\n const context = useContext(MatsuriFormsQuestionContext);\n assertIsDefined(context);\n\n switch (props.questionType) {\n case \"multilineText\": {\n return context.renderMultilineText(props);\n }\n case \"text\": {\n return context.renderText(props);\n }\n case \"select\": {\n return context.renderSelect(props);\n }\n default: {\n throw new Error(\"Unknown question type\");\n }\n }\n};\n"],"mappings":";;;;;;AAKA,IAAAA,6BAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAOO,MAAMG,oBAAoB,GAAIC,KAAgC,IAAK;EACxE,MAAMC,OAAO,GAAG,IAAAC,iBAAU,EAACC,yDAA2B,CAAC;EACvD,IAAAC,+BAAe,EAACH,OAAO,CAAC;EAExB,QAAQD,KAAK,CAACK,YAAY;IACxB,KAAK,eAAe;MAAE;QACpB,OAAOJ,OAAO,CAACK,mBAAmB,CAACN,KAAK,CAAC;MAC3C;IACA,KAAK,MAAM;MAAE;QACX,OAAOC,OAAO,CAACM,UAAU,CAACP,KAAK,CAAC;MAClC;IACA,KAAK,QAAQ;MAAE;QACb,OAAOC,OAAO,CAACO,YAAY,CAACR,KAAK,CAAC;MACpC;IACA;MAAS;QACP,MAAM,IAAIS,KAAK,CAAC,uBAAuB,CAAC;MAC1C;EAAC;AAEL,CAAC;AAACC,OAAA,CAAAX,oBAAA,GAAAA,oBAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MatsuriFormsQuestionProvider = exports.MatsuriFormsQuestionContext = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
const MatsuriFormsQuestionContext = /*#__PURE__*/_react.default.createContext(null);
|
|
11
|
+
exports.MatsuriFormsQuestionContext = MatsuriFormsQuestionContext;
|
|
12
|
+
const MatsuriFormsQuestionProvider = ({
|
|
13
|
+
children,
|
|
14
|
+
renderText,
|
|
15
|
+
renderMultilineText,
|
|
16
|
+
renderSelect
|
|
17
|
+
}) => {
|
|
18
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(MatsuriFormsQuestionContext.Provider, {
|
|
19
|
+
value: {
|
|
20
|
+
renderText,
|
|
21
|
+
renderMultilineText,
|
|
22
|
+
renderSelect
|
|
23
|
+
},
|
|
24
|
+
children: children
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
exports.MatsuriFormsQuestionProvider = MatsuriFormsQuestionProvider;
|
|
28
|
+
//# sourceMappingURL=MatsuriFormsQuestionProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MatsuriFormsQuestionProvider.js","names":["_react","_interopRequireDefault","require","_jsxRuntime","obj","__esModule","default","MatsuriFormsQuestionContext","React","createContext","exports","MatsuriFormsQuestionProvider","children","renderText","renderMultilineText","renderSelect","jsx","Provider","value"],"sources":["../../src/MatsuriFormsQuestionProvider.tsx"],"sourcesContent":["import {\n ParsedMultilineTextQuestion,\n ParsedSelectQuestion,\n ParsedTextQuestion,\n} from \"./model/parsedQuestion\";\nimport React from \"react\";\n\nexport interface MatsuriFormsQuestionError {\n code: \"required\" | \"too_many\";\n message: string;\n}\n\nexport interface MatsuriFormsQuestionCommonProps {\n error?: MatsuriFormsQuestionError;\n}\nexport interface MatsuriFormsSelectQuestionProps\n extends ParsedSelectQuestion,\n MatsuriFormsQuestionCommonProps {}\nexport interface MatsuriFormsTextQuestionProps\n extends ParsedTextQuestion,\n MatsuriFormsQuestionCommonProps {}\nexport interface MatsuriFormsMultilineTextQuestionProps\n extends ParsedMultilineTextQuestion,\n MatsuriFormsQuestionCommonProps {}\ninterface MatsuriFormsQuestionContextValue {\n renderMultilineText: (\n props: MatsuriFormsMultilineTextQuestionProps\n ) => JSX.Element;\n renderText: (props: MatsuriFormsTextQuestionProps) => JSX.Element;\n renderSelect: (props: MatsuriFormsSelectQuestionProps) => JSX.Element;\n}\nexport const MatsuriFormsQuestionContext =\n React.createContext<MatsuriFormsQuestionContextValue | null>(null);\ninterface MatsuriFormsQuestionProviderProps\n extends MatsuriFormsQuestionContextValue {\n children?: React.ReactNode;\n}\n\nexport const MatsuriFormsQuestionProvider = ({\n children,\n renderText,\n renderMultilineText,\n renderSelect,\n}: MatsuriFormsQuestionProviderProps) => {\n return (\n <MatsuriFormsQuestionContext.Provider\n value={{\n renderText,\n renderMultilineText,\n renderSelect,\n }}\n >\n {children}\n </MatsuriFormsQuestionContext.Provider>\n );\n};\n"],"mappings":";;;;;;AAKA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA0B,IAAAC,WAAA,GAAAD,OAAA;AAAA,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AA0BnB,MAAMG,2BAA2B,gBACtCC,cAAK,CAACC,aAAa,CAA0C,IAAI,CAAC;AAACC,OAAA,CAAAH,2BAAA,GAAAA,2BAAA;AAM9D,MAAMI,4BAA4B,GAAGA,CAAC;EAC3CC,QAAQ;EACRC,UAAU;EACVC,mBAAmB;EACnBC;AACiC,CAAC,KAAK;EACvC,oBACE,IAAAZ,WAAA,CAAAa,GAAA,EAACT,2BAA2B,CAACU,QAAQ;IACnCC,KAAK,EAAE;MACLL,UAAU;MACVC,mBAAmB;MACnBC;IACF,CAAE;IAAAH,QAAA,EAEDA;EAAQ,EAC4B;AAE3C,CAAC;AAACF,OAAA,CAAAC,4BAAA,GAAAA,4BAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.submissionCreate = exports.getForm = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* とりあえずendpoints-sdk-cliを使わずに実装する。
|
|
9
|
+
*
|
|
10
|
+
* このSDKを外部に公開する場合のことを考えると、ユーザーが開発環境にアクセスすることは想定されないため、
|
|
11
|
+
* 環境変数をユーザーに設定させるべきではなく、またproductionをデフォルトにする必要がある。
|
|
12
|
+
*
|
|
13
|
+
* 例えばmatsuri-forms用の環境変数を設置して、その環境変数があるときのみ開発環境にアクセスするようにして、
|
|
14
|
+
* ユーザーには秘匿するといった手もあるが、各サービスで各ライブラリ毎に環境変数が増えるといったことは許容したくない却下。
|
|
15
|
+
*/
|
|
16
|
+
const DEVELOPMENT_URL = "https://api-forms.dev.m2msystems.cloud";
|
|
17
|
+
const PRODUCTION_URL = "https://api-forms.m2msystems.cloud";
|
|
18
|
+
const root = env => {
|
|
19
|
+
/**
|
|
20
|
+
* 開発環境にユーザーがアクセスすることは想定されないため、ここのデフォルトはproductionであるべき。
|
|
21
|
+
*/
|
|
22
|
+
return env === "development" ? DEVELOPMENT_URL : PRODUCTION_URL;
|
|
23
|
+
};
|
|
24
|
+
const getForm = (id, env) => {
|
|
25
|
+
return `${root(env)}/forms/${id}`;
|
|
26
|
+
};
|
|
27
|
+
exports.getForm = getForm;
|
|
28
|
+
getForm.method = "GET";
|
|
29
|
+
const submissionCreate = env => {
|
|
30
|
+
return `${root(env)}/submissions`;
|
|
31
|
+
};
|
|
32
|
+
exports.submissionCreate = submissionCreate;
|
|
33
|
+
submissionCreate.method = "POST";
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["DEVELOPMENT_URL","PRODUCTION_URL","root","env","getForm","id","exports","method","submissionCreate"],"sources":["../../../src/endpoints/index.ts"],"sourcesContent":["/**\n * とりあえずendpoints-sdk-cliを使わずに実装する。\n *\n * このSDKを外部に公開する場合のことを考えると、ユーザーが開発環境にアクセスすることは想定されないため、\n * 環境変数をユーザーに設定させるべきではなく、またproductionをデフォルトにする必要がある。\n *\n * 例えばmatsuri-forms用の環境変数を設置して、その環境変数があるときのみ開発環境にアクセスするようにして、\n * ユーザーには秘匿するといった手もあるが、各サービスで各ライブラリ毎に環境変数が増えるといったことは許容したくない却下。\n */\nconst DEVELOPMENT_URL = \"https://api-forms.dev.m2msystems.cloud\";\nconst PRODUCTION_URL = \"https://api-forms.m2msystems.cloud\";\n\nexport type MatsuriFormsEndpointEnvironment = \"production\" | \"development\";\n\nconst root = (env?: MatsuriFormsEndpointEnvironment) => {\n /**\n * 開発環境にユーザーがアクセスすることは想定されないため、ここのデフォルトはproductionであるべき。\n */\n return env === \"development\" ? DEVELOPMENT_URL : PRODUCTION_URL;\n};\n\nexport const getForm = (id: string, env?: MatsuriFormsEndpointEnvironment) => {\n return `${root(env)}/forms/${id}`;\n};\n\ngetForm.method = \"GET\" as const;\n\nexport const submissionCreate = (env?: MatsuriFormsEndpointEnvironment) => {\n return `${root(env)}/submissions`;\n};\n\nsubmissionCreate.method = \"POST\" as const;\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,eAAe,GAAG,wCAAwC;AAChE,MAAMC,cAAc,GAAG,oCAAoC;AAI3D,MAAMC,IAAI,GAAIC,GAAqC,IAAK;EACtD;AACF;AACA;EACE,OAAOA,GAAG,KAAK,aAAa,GAAGH,eAAe,GAAGC,cAAc;AACjE,CAAC;AAEM,MAAMG,OAAO,GAAGA,CAACC,EAAU,EAAEF,GAAqC,KAAK;EAC5E,OAAQ,GAAED,IAAI,CAACC,GAAG,CAAE,UAASE,EAAG,EAAC;AACnC,CAAC;AAACC,OAAA,CAAAF,OAAA,GAAAA,OAAA;AAEFA,OAAO,CAACG,MAAM,GAAG,KAAc;AAExB,MAAMC,gBAAgB,GAAIL,GAAqC,IAAK;EACzE,OAAQ,GAAED,IAAI,CAACC,GAAG,CAAE,cAAa;AACnC,CAAC;AAACG,OAAA,CAAAE,gBAAA,GAAAA,gBAAA;AAEFA,gBAAgB,CAACD,MAAM,GAAG,MAAe"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.assertIsDefined = assertIsDefined;
|
|
7
|
+
function assertIsDefined(val) {
|
|
8
|
+
if (val === undefined || val === null) {
|
|
9
|
+
throw new Error(`Expected 'val' to be defined, but received ${val}`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=assetIsDefined.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assetIsDefined.js","names":["assertIsDefined","val","undefined","Error"],"sources":["../../../src/helpers/assetIsDefined.ts"],"sourcesContent":["export function assertIsDefined<T>(val: T): asserts val is NonNullable<T> {\n if (val === undefined || val === null) {\n throw new Error(`Expected 'val' to be defined, but received ${val}`);\n }\n}\n"],"mappings":";;;;;;AAAO,SAASA,eAAeA,CAAIC,GAAM,EAAiC;EACxE,IAAIA,GAAG,KAAKC,SAAS,IAAID,GAAG,KAAK,IAAI,EAAE;IACrC,MAAM,IAAIE,KAAK,CAAE,8CAA6CF,GAAI,EAAC,CAAC;EACtE;AACF"}
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "MatsuriFormsQuestion", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _MatsuriFormsQuestion.MatsuriFormsQuestion;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "MatsuriFormsQuestionProvider", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _MatsuriFormsQuestionProvider.MatsuriFormsQuestionProvider;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "parseQuestion", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _parsedQuestion.parseQuestion;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "useMatsuriForms", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _useMatsuriForms.useMatsuriForms;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
var _MatsuriFormsQuestion = require("./MatsuriFormsQuestion");
|
|
31
|
+
var _MatsuriFormsQuestionProvider = require("./MatsuriFormsQuestionProvider");
|
|
32
|
+
var _useMatsuriForms = require("./useMatsuriForms");
|
|
33
|
+
var _parsedQuestion = require("./model/parsedQuestion");
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
package/cjs/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["_MatsuriFormsQuestion","require","_MatsuriFormsQuestionProvider","_useMatsuriForms","_parsedQuestion"],"sources":["../../src/index.ts"],"sourcesContent":["export type { MatsuriFormsQuestionProps } from \"./MatsuriFormsQuestion\";\nexport { MatsuriFormsQuestion } from \"./MatsuriFormsQuestion\";\nexport type {\n MatsuriFormsTextQuestionProps,\n MatsuriFormsMultilineTextQuestionProps,\n MatsuriFormsSelectQuestionProps,\n} from \"./MatsuriFormsQuestionProvider\";\nexport { MatsuriFormsQuestionProvider } from \"./MatsuriFormsQuestionProvider\";\nexport { useMatsuriForms } from \"./useMatsuriForms\";\nexport type { Question } from \"./model/question\";\nexport type { ParsedQuestion } from \"./model/parsedQuestion\";\nexport { parseQuestion } from \"./model/parsedQuestion\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,qBAAA,GAAAC,OAAA;AAMA,IAAAC,6BAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AAGA,IAAAG,eAAA,GAAAH,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form.js","names":[],"sources":["../../../src/model/form.ts"],"sourcesContent":["import { Question } from \"./question\";\n\nexport interface Form {\n id: string;\n userId: string;\n draftRevision: string;\n publishStatus: \"private\" | \"public\";\n publishedRevision: string;\n title: string;\n isDeleted: boolean;\n createdAt: number;\n updatedAt: number;\n isSheetFeature: boolean;\n}\n\nexport interface FormContent {\n formId: string;\n revision: string;\n questions: Question[];\n createdAt: number;\n updatedAt: number;\n}\n\nexport interface FormDetail {\n form: Form;\n content: FormContent;\n}\n"],"mappings":""}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.parseQuestion = void 0;
|
|
7
|
+
const parseQuestion = question => {
|
|
8
|
+
const commonProps = {
|
|
9
|
+
id: question.id,
|
|
10
|
+
name: question.id,
|
|
11
|
+
required: question.required,
|
|
12
|
+
title: question.title,
|
|
13
|
+
description: question.description
|
|
14
|
+
};
|
|
15
|
+
if (question.value.multilineText) {
|
|
16
|
+
return {
|
|
17
|
+
questionType: "multilineText",
|
|
18
|
+
...commonProps,
|
|
19
|
+
maxLength: question.value.multilineText.maxLength
|
|
20
|
+
};
|
|
21
|
+
} else if (question.value.text) {
|
|
22
|
+
return {
|
|
23
|
+
questionType: "text",
|
|
24
|
+
...commonProps,
|
|
25
|
+
maxLength: question.value.text.maxLength,
|
|
26
|
+
type: question.value.text.inputType
|
|
27
|
+
};
|
|
28
|
+
} else if (question.value.select) {
|
|
29
|
+
return {
|
|
30
|
+
questionType: "select",
|
|
31
|
+
...commonProps,
|
|
32
|
+
options: question.value.select.options,
|
|
33
|
+
multiple: question.value.select.maxAnswer !== 1,
|
|
34
|
+
maxAnswer: question.value.select.maxAnswer,
|
|
35
|
+
hasOtherOption: question.value.select.otherOption
|
|
36
|
+
};
|
|
37
|
+
} else {
|
|
38
|
+
throw new Error("Unknown question type");
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.parseQuestion = parseQuestion;
|
|
42
|
+
//# sourceMappingURL=parsedQuestion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parsedQuestion.js","names":["parseQuestion","question","commonProps","id","name","required","title","description","value","multilineText","questionType","maxLength","text","type","inputType","select","options","multiple","maxAnswer","hasOtherOption","otherOption","Error","exports"],"sources":["../../../src/model/parsedQuestion.tsx"],"sourcesContent":["import { Question } from \"./question\";\n\nexport interface ParsedQuestionCommon {\n name: string;\n required?: boolean;\n title: string;\n id: string;\n description?: string;\n}\nexport interface ParsedMultilineTextQuestion extends ParsedQuestionCommon {\n questionType: \"multilineText\";\n maxLength?: number;\n}\n\nexport interface ParsedTextQuestion extends ParsedQuestionCommon {\n questionType: \"text\";\n type?: string;\n maxLength?: number;\n}\n\nexport interface ParsedSelectQuestion extends ParsedQuestionCommon {\n questionType: \"select\";\n options: { label: string; value: string }[];\n multiple?: boolean;\n maxAnswer?: number;\n hasOtherOption?: boolean;\n}\n\nexport type ParsedQuestion =\n | ParsedMultilineTextQuestion\n | ParsedTextQuestion\n | ParsedSelectQuestion;\n\nexport const parseQuestion = (question: Question): ParsedQuestion => {\n const commonProps: ParsedQuestionCommon = {\n id: question.id,\n name: question.id,\n required: question.required,\n title: question.title,\n description: question.description,\n };\n if (question.value.multilineText) {\n return {\n questionType: \"multilineText\",\n ...commonProps,\n maxLength: question.value.multilineText.maxLength,\n };\n } else if (question.value.text) {\n return {\n questionType: \"text\",\n ...commonProps,\n maxLength: question.value.text.maxLength,\n type: question.value.text.inputType,\n };\n } else if (question.value.select) {\n return {\n questionType: \"select\",\n ...commonProps,\n options: question.value.select.options,\n multiple: question.value.select.maxAnswer !== 1,\n maxAnswer: question.value.select.maxAnswer,\n hasOtherOption: question.value.select.otherOption,\n };\n } else {\n throw new Error(\"Unknown question type\");\n }\n};\n"],"mappings":";;;;;;AAiCO,MAAMA,aAAa,GAAIC,QAAkB,IAAqB;EACnE,MAAMC,WAAiC,GAAG;IACxCC,EAAE,EAAEF,QAAQ,CAACE,EAAE;IACfC,IAAI,EAAEH,QAAQ,CAACE,EAAE;IACjBE,QAAQ,EAAEJ,QAAQ,CAACI,QAAQ;IAC3BC,KAAK,EAAEL,QAAQ,CAACK,KAAK;IACrBC,WAAW,EAAEN,QAAQ,CAACM;EACxB,CAAC;EACD,IAAIN,QAAQ,CAACO,KAAK,CAACC,aAAa,EAAE;IAChC,OAAO;MACLC,YAAY,EAAE,eAAe;MAC7B,GAAGR,WAAW;MACdS,SAAS,EAAEV,QAAQ,CAACO,KAAK,CAACC,aAAa,CAACE;IAC1C,CAAC;EACH,CAAC,MAAM,IAAIV,QAAQ,CAACO,KAAK,CAACI,IAAI,EAAE;IAC9B,OAAO;MACLF,YAAY,EAAE,MAAM;MACpB,GAAGR,WAAW;MACdS,SAAS,EAAEV,QAAQ,CAACO,KAAK,CAACI,IAAI,CAACD,SAAS;MACxCE,IAAI,EAAEZ,QAAQ,CAACO,KAAK,CAACI,IAAI,CAACE;IAC5B,CAAC;EACH,CAAC,MAAM,IAAIb,QAAQ,CAACO,KAAK,CAACO,MAAM,EAAE;IAChC,OAAO;MACLL,YAAY,EAAE,QAAQ;MACtB,GAAGR,WAAW;MACdc,OAAO,EAAEf,QAAQ,CAACO,KAAK,CAACO,MAAM,CAACC,OAAO;MACtCC,QAAQ,EAAEhB,QAAQ,CAACO,KAAK,CAACO,MAAM,CAACG,SAAS,KAAK,CAAC;MAC/CA,SAAS,EAAEjB,QAAQ,CAACO,KAAK,CAACO,MAAM,CAACG,SAAS;MAC1CC,cAAc,EAAElB,QAAQ,CAACO,KAAK,CAACO,MAAM,CAACK;IACxC,CAAC;EACH,CAAC,MAAM;IACL,MAAM,IAAIC,KAAK,CAAC,uBAAuB,CAAC;EAC1C;AACF,CAAC;AAACC,OAAA,CAAAtB,aAAA,GAAAA,aAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"question.js","names":[],"sources":["../../../src/model/question.ts"],"sourcesContent":["export interface QuestionValueText {\n inputType: string;\n maxLength: number;\n}\n\nexport interface QuestionValueSelectOption {\n label: string;\n value: string;\n}\n\nexport interface QuestionValueSelect {\n options: QuestionValueSelectOption[];\n otherOption: boolean;\n // その他(自由入力)がvalueであるときにつけるprefix\n otherValuePrefix: string;\n maxAnswer: number;\n}\nexport interface QuestionValueMultilineText {\n maxLength: number;\n}\n\nexport type QuestionType = \"text\" | \"multilineText\" | \"select\";\n\nexport type QuestionValue =\n | {\n text: QuestionValueText;\n multilineText?: null;\n select?: null;\n }\n | {\n text?: null;\n multilineText: QuestionValueMultilineText;\n select?: null;\n }\n | {\n text?: null;\n multilineText?: null;\n select: QuestionValueSelect;\n }\n // このケースはありえないが、型の安全性を確保するために必要\n | {\n text?: null;\n multilineText?: null;\n select?: null;\n };\n\nexport interface Question {\n id: string;\n title: string;\n description: string;\n value: QuestionValue;\n required: boolean;\n}\n"],"mappings":""}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useMatsuriForms = void 0;
|
|
7
|
+
var _endpoints = require("./endpoints");
|
|
8
|
+
var _matsuriHooks = require("matsuri-hooks");
|
|
9
|
+
var _parsedQuestion = require("./model/parsedQuestion");
|
|
10
|
+
var _react = require("react");
|
|
11
|
+
const useMatsuriForms = (formId, options) => {
|
|
12
|
+
const {
|
|
13
|
+
data
|
|
14
|
+
} = (0, _matsuriHooks.useFetch)((0, _endpoints.getForm)(formId, options?.environment), {
|
|
15
|
+
method: _endpoints.getForm.method
|
|
16
|
+
});
|
|
17
|
+
const parsedQuestions = (0, _react.useMemo)(() => {
|
|
18
|
+
return data?.content.questions.map(question => {
|
|
19
|
+
return (0, _parsedQuestion.parseQuestion)(question);
|
|
20
|
+
}) ?? [];
|
|
21
|
+
}, [data?.content.questions]);
|
|
22
|
+
const getValues = (0, _react.useCallback)(form => {
|
|
23
|
+
const formData = new FormData(form);
|
|
24
|
+
const values = data?.content.questions.map(question => {
|
|
25
|
+
if (question.value.select) {
|
|
26
|
+
const {
|
|
27
|
+
otherOption,
|
|
28
|
+
options,
|
|
29
|
+
otherValuePrefix
|
|
30
|
+
} = question.value.select;
|
|
31
|
+
const values = formData.getAll(question.id);
|
|
32
|
+
return {
|
|
33
|
+
questionId: question.id,
|
|
34
|
+
value: otherOption ? values.map(value => {
|
|
35
|
+
if (options.find(option => option.value === value)) {
|
|
36
|
+
return value;
|
|
37
|
+
} else {
|
|
38
|
+
return [otherValuePrefix, value].join("");
|
|
39
|
+
}
|
|
40
|
+
}) : values
|
|
41
|
+
};
|
|
42
|
+
} else {
|
|
43
|
+
const value = formData.get(question.id) ?? "";
|
|
44
|
+
return {
|
|
45
|
+
questionId: question.id,
|
|
46
|
+
value
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return values;
|
|
51
|
+
}, [data?.content.questions]);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* event.preventDefault()
|
|
55
|
+
* const { error } = submit(event.currentTarget)
|
|
56
|
+
* // matsuri-uiの特定のコンポーネントには依存させない
|
|
57
|
+
* throwAlert(error, {...})
|
|
58
|
+
*/
|
|
59
|
+
const submit = (0, _react.useCallback)(async form => {
|
|
60
|
+
const values = getValues(form);
|
|
61
|
+
const {
|
|
62
|
+
error
|
|
63
|
+
} = await (0, _matsuriHooks.fetcher)((0, _endpoints.submissionCreate)(), {
|
|
64
|
+
method: _endpoints.submissionCreate.method,
|
|
65
|
+
body: JSON.stringify({
|
|
66
|
+
formId: data?.content.formId,
|
|
67
|
+
revision: data?.content.revision,
|
|
68
|
+
values
|
|
69
|
+
})
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
error
|
|
73
|
+
};
|
|
74
|
+
}, [data?.content.formId, data?.content.revision, getValues]);
|
|
75
|
+
const [errors, setErrors] = (0, _react.useState)({});
|
|
76
|
+
/**
|
|
77
|
+
* Form要素が責務を負えないmatsuri-forms由来のバリデーションを行う
|
|
78
|
+
*/
|
|
79
|
+
const validate = (0, _react.useCallback)(form => {
|
|
80
|
+
const formData = new FormData(form);
|
|
81
|
+
const errors = {};
|
|
82
|
+
data?.content.questions.forEach(question => {
|
|
83
|
+
if (question.value.select) {
|
|
84
|
+
const values = formData.getAll(question.id);
|
|
85
|
+
if (question.required && values.length === 0) {
|
|
86
|
+
errors[question.id] = {
|
|
87
|
+
code: "required",
|
|
88
|
+
message: "この質問は回答が必須です。"
|
|
89
|
+
};
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (question.value.select.maxAnswer < values.length) {
|
|
93
|
+
errors[question.id] = {
|
|
94
|
+
code: "too_many",
|
|
95
|
+
message: "この質問で選択できる回答数を超えています。"
|
|
96
|
+
};
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
setErrors(errors);
|
|
102
|
+
return {
|
|
103
|
+
errors: Object.keys(errors).length ? errors : undefined
|
|
104
|
+
};
|
|
105
|
+
}, [data?.content.questions]);
|
|
106
|
+
return {
|
|
107
|
+
questions: parsedQuestions,
|
|
108
|
+
submit,
|
|
109
|
+
validate,
|
|
110
|
+
errors
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
exports.useMatsuriForms = useMatsuriForms;
|
|
114
|
+
//# sourceMappingURL=useMatsuriForms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMatsuriForms.js","names":["_endpoints","require","_matsuriHooks","_parsedQuestion","_react","useMatsuriForms","formId","options","data","useFetch","getForm","environment","method","parsedQuestions","useMemo","content","questions","map","question","parseQuestion","getValues","useCallback","form","formData","FormData","values","value","select","otherOption","otherValuePrefix","getAll","id","questionId","find","option","join","get","submit","error","fetcher","submissionCreate","body","JSON","stringify","revision","errors","setErrors","useState","validate","forEach","required","length","code","message","maxAnswer","Object","keys","undefined","exports"],"sources":["../../src/useMatsuriForms.tsx"],"sourcesContent":["import { FormDetail } from \"./model/form\";\nimport {\n MatsuriFormsEndpointEnvironment,\n getForm,\n submissionCreate,\n} from \"./endpoints\";\nimport { MatsuriFormsQuestionError } from \"./MatsuriFormsQuestionProvider\";\nimport { fetcher, useFetch } from \"matsuri-hooks\";\nimport { parseQuestion } from \"./model/parsedQuestion\";\nimport { useCallback, useMemo, useState } from \"react\";\n\nexport interface MatsuriFormsQuestionErrorMap {\n [id: string]: MatsuriFormsQuestionError;\n}\n\nexport interface UseMatsuriFormsOptions {\n environment?: MatsuriFormsEndpointEnvironment;\n}\n\nexport const useMatsuriForms = (\n formId: string,\n options?: UseMatsuriFormsOptions\n) => {\n const { data } = useFetch<FormDetail>(getForm(formId, options?.environment), {\n method: getForm.method,\n });\n\n const parsedQuestions = useMemo(() => {\n return (\n data?.content.questions.map((question) => {\n return parseQuestion(question);\n }) ?? []\n );\n }, [data?.content.questions]);\n\n const getValues = useCallback(\n (form: HTMLFormElement) => {\n const formData = new FormData(form);\n\n const values = data?.content.questions.map((question) => {\n if (question.value.select) {\n const { otherOption, options, otherValuePrefix } =\n question.value.select;\n const values = formData.getAll(question.id);\n return {\n questionId: question.id,\n value: otherOption\n ? values.map((value) => {\n if (options.find((option) => option.value === value)) {\n return value;\n } else {\n return [otherValuePrefix, value].join(\"\");\n }\n })\n : values,\n };\n } else {\n const value = formData.get(question.id) ?? \"\";\n return {\n questionId: question.id,\n value,\n };\n }\n });\n return values;\n },\n [data?.content.questions]\n );\n\n /**\n * event.preventDefault()\n * const { error } = submit(event.currentTarget)\n * // matsuri-uiの特定のコンポーネントには依存させない\n * throwAlert(error, {...})\n */\n const submit = useCallback(\n async (form: HTMLFormElement) => {\n const values = getValues(form);\n\n const { error } = await fetcher(submissionCreate(), {\n method: submissionCreate.method,\n body: JSON.stringify({\n formId: data?.content.formId,\n revision: data?.content.revision,\n values,\n }),\n });\n return { error };\n },\n [data?.content.formId, data?.content.revision, getValues]\n );\n\n const [errors, setErrors] = useState<MatsuriFormsQuestionErrorMap>({});\n /**\n * Form要素が責務を負えないmatsuri-forms由来のバリデーションを行う\n */\n const validate = useCallback(\n (form: HTMLFormElement) => {\n const formData = new FormData(form);\n\n const errors: MatsuriFormsQuestionErrorMap = {};\n data?.content.questions.forEach((question) => {\n if (question.value.select) {\n const values = formData.getAll(question.id);\n if (question.required && values.length === 0) {\n errors[question.id] = {\n code: \"required\",\n message: \"この質問は回答が必須です。\",\n };\n return;\n }\n if (question.value.select.maxAnswer < values.length) {\n errors[question.id] = {\n code: \"too_many\",\n message: \"この質問で選択できる回答数を超えています。\",\n };\n return;\n }\n }\n });\n\n setErrors(errors);\n\n return {\n errors: Object.keys(errors).length ? errors : undefined,\n };\n },\n [data?.content.questions]\n );\n\n return {\n questions: parsedQuestions,\n submit,\n validate,\n errors,\n };\n};\n"],"mappings":"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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type MatsuriFormsEndpointEnvironment = "production" | "development";
|
|
2
|
+
export declare const getForm: {
|
|
3
|
+
(id: string, env?: MatsuriFormsEndpointEnvironment): string;
|
|
4
|
+
method: "GET";
|
|
5
|
+
};
|
|
6
|
+
export declare const submissionCreate: {
|
|
7
|
+
(env?: MatsuriFormsEndpointEnvironment): string;
|
|
8
|
+
method: "POST";
|
|
9
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* とりあえずendpoints-sdk-cliを使わずに実装する。
|
|
3
|
+
*
|
|
4
|
+
* このSDKを外部に公開する場合のことを考えると、ユーザーが開発環境にアクセスすることは想定されないため、
|
|
5
|
+
* 環境変数をユーザーに設定させるべきではなく、またproductionをデフォルトにする必要がある。
|
|
6
|
+
*
|
|
7
|
+
* 例えばmatsuri-forms用の環境変数を設置して、その環境変数があるときのみ開発環境にアクセスするようにして、
|
|
8
|
+
* ユーザーには秘匿するといった手もあるが、各サービスで各ライブラリ毎に環境変数が増えるといったことは許容したくない却下。
|
|
9
|
+
*/
|
|
10
|
+
var DEVELOPMENT_URL = "https://api-forms.dev.m2msystems.cloud";
|
|
11
|
+
var PRODUCTION_URL = "https://api-forms.m2msystems.cloud";
|
|
12
|
+
var root = env => {
|
|
13
|
+
/**
|
|
14
|
+
* 開発環境にユーザーがアクセスすることは想定されないため、ここのデフォルトはproductionであるべき。
|
|
15
|
+
*/
|
|
16
|
+
return env === "development" ? DEVELOPMENT_URL : PRODUCTION_URL;
|
|
17
|
+
};
|
|
18
|
+
export var getForm = (id, env) => {
|
|
19
|
+
return "".concat(root(env), "/forms/").concat(id);
|
|
20
|
+
};
|
|
21
|
+
getForm.method = "GET";
|
|
22
|
+
export var submissionCreate = env => {
|
|
23
|
+
return "".concat(root(env), "/submissions");
|
|
24
|
+
};
|
|
25
|
+
submissionCreate.method = "POST";
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["DEVELOPMENT_URL","PRODUCTION_URL","root","env","getForm","id","concat","method","submissionCreate"],"sources":["../../../src/endpoints/index.ts"],"sourcesContent":["/**\n * とりあえずendpoints-sdk-cliを使わずに実装する。\n *\n * このSDKを外部に公開する場合のことを考えると、ユーザーが開発環境にアクセスすることは想定されないため、\n * 環境変数をユーザーに設定させるべきではなく、またproductionをデフォルトにする必要がある。\n *\n * 例えばmatsuri-forms用の環境変数を設置して、その環境変数があるときのみ開発環境にアクセスするようにして、\n * ユーザーには秘匿するといった手もあるが、各サービスで各ライブラリ毎に環境変数が増えるといったことは許容したくない却下。\n */\nconst DEVELOPMENT_URL = \"https://api-forms.dev.m2msystems.cloud\";\nconst PRODUCTION_URL = \"https://api-forms.m2msystems.cloud\";\n\nexport type MatsuriFormsEndpointEnvironment = \"production\" | \"development\";\n\nconst root = (env?: MatsuriFormsEndpointEnvironment) => {\n /**\n * 開発環境にユーザーがアクセスすることは想定されないため、ここのデフォルトはproductionであるべき。\n */\n return env === \"development\" ? DEVELOPMENT_URL : PRODUCTION_URL;\n};\n\nexport const getForm = (id: string, env?: MatsuriFormsEndpointEnvironment) => {\n return `${root(env)}/forms/${id}`;\n};\n\ngetForm.method = \"GET\" as const;\n\nexport const submissionCreate = (env?: MatsuriFormsEndpointEnvironment) => {\n return `${root(env)}/submissions`;\n};\n\nsubmissionCreate.method = \"POST\" as const;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMA,eAAe,GAAG,wCAAwC;AAChE,IAAMC,cAAc,GAAG,oCAAoC;AAI3D,IAAMC,IAAI,GAAIC,GAAqC,IAAK;EACtD;AACF;AACA;EACE,OAAOA,GAAG,KAAK,aAAa,GAAGH,eAAe,GAAGC,cAAc;AACjE,CAAC;AAED,OAAO,IAAMG,OAAO,GAAGA,CAACC,EAAU,EAAEF,GAAqC,KAAK;EAC5E,UAAAG,MAAA,CAAUJ,IAAI,CAACC,GAAG,CAAC,aAAAG,MAAA,CAAUD,EAAE;AACjC,CAAC;AAEDD,OAAO,CAACG,MAAM,GAAG,KAAc;AAE/B,OAAO,IAAMC,gBAAgB,GAAIL,GAAqC,IAAK;EACzE,UAAAG,MAAA,CAAUJ,IAAI,CAACC,GAAG,CAAC;AACrB,CAAC;AAEDK,gBAAgB,CAACD,MAAM,GAAG,MAAe"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MatsuriFormsQuestionContext } from "./MatsuriFormsQuestionProvider";
|
|
2
|
+
import { assertIsDefined } from "./helpers/assetIsDefined";
|
|
3
|
+
import { useContext } from "react";
|
|
4
|
+
export var MatsuriFormsQuestion = props => {
|
|
5
|
+
var context = useContext(MatsuriFormsQuestionContext);
|
|
6
|
+
assertIsDefined(context);
|
|
7
|
+
switch (props.questionType) {
|
|
8
|
+
case "multilineText":
|
|
9
|
+
{
|
|
10
|
+
return context.renderMultilineText(props);
|
|
11
|
+
}
|
|
12
|
+
case "text":
|
|
13
|
+
{
|
|
14
|
+
return context.renderText(props);
|
|
15
|
+
}
|
|
16
|
+
case "select":
|
|
17
|
+
{
|
|
18
|
+
return context.renderSelect(props);
|
|
19
|
+
}
|
|
20
|
+
default:
|
|
21
|
+
{
|
|
22
|
+
throw new Error("Unknown question type");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=MatsuriFormsQuestion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MatsuriFormsQuestion.js","names":["MatsuriFormsQuestionContext","assertIsDefined","useContext","MatsuriFormsQuestion","props","context","questionType","renderMultilineText","renderText","renderSelect","Error"],"sources":["../../src/MatsuriFormsQuestion.tsx"],"sourcesContent":["import {\n MatsuriFormsMultilineTextQuestionProps,\n MatsuriFormsSelectQuestionProps,\n MatsuriFormsTextQuestionProps,\n} from \"./MatsuriFormsQuestionProvider\";\nimport { MatsuriFormsQuestionContext } from \"./MatsuriFormsQuestionProvider\";\nimport { assertIsDefined } from \"./helpers/assetIsDefined\";\nimport { useContext } from \"react\";\n\nexport type MatsuriFormsQuestionProps =\n | MatsuriFormsTextQuestionProps\n | MatsuriFormsMultilineTextQuestionProps\n | MatsuriFormsSelectQuestionProps;\n\nexport const MatsuriFormsQuestion = (props: MatsuriFormsQuestionProps) => {\n const context = useContext(MatsuriFormsQuestionContext);\n assertIsDefined(context);\n\n switch (props.questionType) {\n case \"multilineText\": {\n return context.renderMultilineText(props);\n }\n case \"text\": {\n return context.renderText(props);\n }\n case \"select\": {\n return context.renderSelect(props);\n }\n default: {\n throw new Error(\"Unknown question type\");\n }\n }\n};\n"],"mappings":"AAKA,SAASA,2BAA2B,QAAQ,gCAAgC;AAC5E,SAASC,eAAe,QAAQ,0BAA0B;AAC1D,SAASC,UAAU,QAAQ,OAAO;AAOlC,OAAO,IAAMC,oBAAoB,GAAIC,KAAgC,IAAK;EACxE,IAAMC,OAAO,GAAGH,UAAU,CAACF,2BAA2B,CAAC;EACvDC,eAAe,CAACI,OAAO,CAAC;EAExB,QAAQD,KAAK,CAACE,YAAY;IACxB,KAAK,eAAe;MAAE;QACpB,OAAOD,OAAO,CAACE,mBAAmB,CAACH,KAAK,CAAC;MAC3C;IACA,KAAK,MAAM;MAAE;QACX,OAAOC,OAAO,CAACG,UAAU,CAACJ,KAAK,CAAC;MAClC;IACA,KAAK,QAAQ;MAAE;QACb,OAAOC,OAAO,CAACI,YAAY,CAACL,KAAK,CAAC;MACpC;IACA;MAAS;QACP,MAAM,IAAIM,KAAK,CAAC,uBAAuB,CAAC;MAC1C;EAAC;AAEL,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
export var MatsuriFormsQuestionContext = /*#__PURE__*/React.createContext(null);
|
|
4
|
+
export var MatsuriFormsQuestionProvider = _ref => {
|
|
5
|
+
var {
|
|
6
|
+
children,
|
|
7
|
+
renderText,
|
|
8
|
+
renderMultilineText,
|
|
9
|
+
renderSelect
|
|
10
|
+
} = _ref;
|
|
11
|
+
return /*#__PURE__*/_jsx(MatsuriFormsQuestionContext.Provider, {
|
|
12
|
+
value: {
|
|
13
|
+
renderText,
|
|
14
|
+
renderMultilineText,
|
|
15
|
+
renderSelect
|
|
16
|
+
},
|
|
17
|
+
children: children
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=MatsuriFormsQuestionProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MatsuriFormsQuestionProvider.js","names":["React","jsx","_jsx","MatsuriFormsQuestionContext","createContext","MatsuriFormsQuestionProvider","_ref","children","renderText","renderMultilineText","renderSelect","Provider","value"],"sources":["../../src/MatsuriFormsQuestionProvider.tsx"],"sourcesContent":["import {\n ParsedMultilineTextQuestion,\n ParsedSelectQuestion,\n ParsedTextQuestion,\n} from \"./model/parsedQuestion\";\nimport React from \"react\";\n\nexport interface MatsuriFormsQuestionError {\n code: \"required\" | \"too_many\";\n message: string;\n}\n\nexport interface MatsuriFormsQuestionCommonProps {\n error?: MatsuriFormsQuestionError;\n}\nexport interface MatsuriFormsSelectQuestionProps\n extends ParsedSelectQuestion,\n MatsuriFormsQuestionCommonProps {}\nexport interface MatsuriFormsTextQuestionProps\n extends ParsedTextQuestion,\n MatsuriFormsQuestionCommonProps {}\nexport interface MatsuriFormsMultilineTextQuestionProps\n extends ParsedMultilineTextQuestion,\n MatsuriFormsQuestionCommonProps {}\ninterface MatsuriFormsQuestionContextValue {\n renderMultilineText: (\n props: MatsuriFormsMultilineTextQuestionProps\n ) => JSX.Element;\n renderText: (props: MatsuriFormsTextQuestionProps) => JSX.Element;\n renderSelect: (props: MatsuriFormsSelectQuestionProps) => JSX.Element;\n}\nexport const MatsuriFormsQuestionContext =\n React.createContext<MatsuriFormsQuestionContextValue | null>(null);\ninterface MatsuriFormsQuestionProviderProps\n extends MatsuriFormsQuestionContextValue {\n children?: React.ReactNode;\n}\n\nexport const MatsuriFormsQuestionProvider = ({\n children,\n renderText,\n renderMultilineText,\n renderSelect,\n}: MatsuriFormsQuestionProviderProps) => {\n return (\n <MatsuriFormsQuestionContext.Provider\n value={{\n renderText,\n renderMultilineText,\n renderSelect,\n }}\n >\n {children}\n </MatsuriFormsQuestionContext.Provider>\n );\n};\n"],"mappings":"AAKA,OAAOA,KAAK,MAAM,OAAO;AAAC,SAAAC,GAAA,IAAAC,IAAA;AA0B1B,OAAO,IAAMC,2BAA2B,gBACtCH,KAAK,CAACI,aAAa,CAA0C,IAAI,CAAC;AAMpE,OAAO,IAAMC,4BAA4B,GAAGC,IAAA,IAKH;EAAA,IALI;IAC3CC,QAAQ;IACRC,UAAU;IACVC,mBAAmB;IACnBC;EACiC,CAAC,GAAAJ,IAAA;EAClC,oBACEJ,IAAA,CAACC,2BAA2B,CAACQ,QAAQ;IACnCC,KAAK,EAAE;MACLJ,UAAU;MACVC,mBAAmB;MACnBC;IACF,CAAE;IAAAH,QAAA,EAEDA;EAAQ,EAC4B;AAE3C,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* とりあえずendpoints-sdk-cliを使わずに実装する。
|
|
3
|
+
*
|
|
4
|
+
* このSDKを外部に公開する場合のことを考えると、ユーザーが開発環境にアクセスすることは想定されないため、
|
|
5
|
+
* 環境変数をユーザーに設定させるべきではなく、またproductionをデフォルトにする必要がある。
|
|
6
|
+
*
|
|
7
|
+
* 例えばmatsuri-forms用の環境変数を設置して、その環境変数があるときのみ開発環境にアクセスするようにして、
|
|
8
|
+
* ユーザーには秘匿するといった手もあるが、各サービスで各ライブラリ毎に環境変数が増えるといったことは許容したくない却下。
|
|
9
|
+
*/
|
|
10
|
+
var DEVELOPMENT_URL = "https://api-forms.dev.m2msystems.cloud";
|
|
11
|
+
var PRODUCTION_URL = "https://api-forms.m2msystems.cloud";
|
|
12
|
+
var root = env => {
|
|
13
|
+
/**
|
|
14
|
+
* 開発環境にユーザーがアクセスすることは想定されないため、ここのデフォルトはproductionであるべき。
|
|
15
|
+
*/
|
|
16
|
+
return env === "development" ? DEVELOPMENT_URL : PRODUCTION_URL;
|
|
17
|
+
};
|
|
18
|
+
export var getForm = (id, env) => {
|
|
19
|
+
return "".concat(root(env), "/forms/").concat(id);
|
|
20
|
+
};
|
|
21
|
+
getForm.method = "GET";
|
|
22
|
+
export var submissionCreate = env => {
|
|
23
|
+
return "".concat(root(env), "/submissions");
|
|
24
|
+
};
|
|
25
|
+
submissionCreate.method = "POST";
|
|
26
|
+
//# sourceMappingURL=index.js.map
|