@surveystudio/node-registery 1.0.0 → 1.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/README.md +16 -4
- package/dist/builder.d.mts +6 -13
- package/dist/builder.mjs +1 -60
- package/dist/coreTypes-D-1hYIe5.d.mts +85 -0
- package/dist/logic.d.mts +4 -3
- package/dist/logic.mjs +13 -6
- package/dist/runner.d.mts +4 -10
- package/dist/runner.mjs +1 -60
- package/dist/types-BpvjaHAP.d.mts +51 -0
- package/dist/types-D78Zx0gX.d.mts +18 -0
- package/dist/ui.d.mts +1724 -0
- package/dist/ui.mjs +32 -0
- package/package.json +7 -3
- package/dist/types-DJePy6HU.d.mts +0 -140
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @surveystudio/node-registery
|
|
2
2
|
|
|
3
3
|
Typed survey question node registry with separate entrypoints for pure logic, runner UI, and builder UI.
|
|
4
4
|
|
|
@@ -7,15 +7,27 @@ This package is currently in early migration. It exports the first migrated node
|
|
|
7
7
|
## Entrypoints
|
|
8
8
|
|
|
9
9
|
```ts
|
|
10
|
-
import { logicRegistry } from "@
|
|
11
|
-
import { runnerRegistry } from "@
|
|
12
|
-
import { builderRegistry } from "@
|
|
10
|
+
import { logicRegistry } from "@surveystudio/node-registery/logic";
|
|
11
|
+
import { runnerRegistry } from "@surveystudio/node-registery/runner";
|
|
12
|
+
import { builderRegistry } from "@surveystudio/node-registery/builder";
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
Use `/logic` for Worker, export, and server runtimes. It is intentionally React-free.
|
|
16
16
|
|
|
17
17
|
Use `/runner` and `/builder` only in React runtimes. React is a peer dependency and is not bundled.
|
|
18
18
|
|
|
19
|
+
## Logic Pipeline
|
|
20
|
+
|
|
21
|
+
Every node logic module should expose the same pure, Worker-safe pipeline:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
const value = logicRegistry.plainText.normalizeValue(rawAnswer, node.data, context);
|
|
25
|
+
const validation = logicRegistry.plainText.validate(value, node.data, context);
|
|
26
|
+
const columns = logicRegistry.plainText.extractValue(value, node.data, context);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Runner APIs should persist and queue normalized values. Export/projection APIs should read normalized values through `extractValue`.
|
|
30
|
+
|
|
19
31
|
## Current Status
|
|
20
32
|
|
|
21
33
|
Migrated nodes:
|
package/dist/builder.d.mts
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export { B as BuilderRegistry, c as CompleteBuilderRegistry, e as NodeBuilder, f as NodeBuilderProps, g as NodeCanvasProps, Q as QuestionNodeDefinition, h as defineBuilderRegistry, d as defineQuestionNode } from './types-BpvjaHAP.mjs';
|
|
2
|
+
import { J as JsonValue } from './coreTypes-D-1hYIe5.mjs';
|
|
3
|
+
export { f as NodeManifest, P as PropertyField, g as PropertyFieldType, S as SelectOption } from './coreTypes-D-1hYIe5.mjs';
|
|
4
|
+
import { P as PlainTextData } from './types-D78Zx0gX.mjs';
|
|
5
|
+
import 'react';
|
|
5
6
|
|
|
6
|
-
declare function PlainTextBuilderPreview({ data }: NodeCanvasProps<PlainTextData>): react.DetailedReactHTMLElement<{
|
|
7
|
-
style: CSSProperties;
|
|
8
|
-
}, HTMLElement>;
|
|
9
|
-
declare function PlainTextSettings(_props: NodeBuilderProps<PlainTextData>): null;
|
|
10
7
|
declare const plainTextBuilder: {
|
|
11
8
|
type: "plainText";
|
|
12
9
|
label: string;
|
|
13
|
-
SettingsComponent: typeof PlainTextSettings;
|
|
14
|
-
CanvasComponent: typeof PlainTextBuilderPreview;
|
|
15
10
|
};
|
|
16
11
|
|
|
17
12
|
declare const plainTextManifest: {
|
|
@@ -57,9 +52,7 @@ declare const builderRegistry: {
|
|
|
57
52
|
readonly plainText: {
|
|
58
53
|
type: "plainText";
|
|
59
54
|
label: string;
|
|
60
|
-
SettingsComponent: typeof PlainTextSettings;
|
|
61
|
-
CanvasComponent: typeof PlainTextBuilderPreview;
|
|
62
55
|
};
|
|
63
56
|
};
|
|
64
57
|
|
|
65
|
-
export {
|
|
58
|
+
export { builderRegistry, plainTextBuilder, plainTextManifest };
|
package/dist/builder.mjs
CHANGED
|
@@ -7,68 +7,9 @@ function defineBuilderRegistry(registry) {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
// src/nodes/plainText/builder.ts
|
|
10
|
-
import { createElement } from "react";
|
|
11
|
-
var shellStyle = {
|
|
12
|
-
display: "grid",
|
|
13
|
-
gap: "12px",
|
|
14
|
-
minWidth: "220px"
|
|
15
|
-
};
|
|
16
|
-
var titleStyle = {
|
|
17
|
-
color: "#111827",
|
|
18
|
-
fontSize: "14px",
|
|
19
|
-
fontWeight: 600,
|
|
20
|
-
lineHeight: 1.3,
|
|
21
|
-
margin: 0
|
|
22
|
-
};
|
|
23
|
-
var descriptionStyle = {
|
|
24
|
-
background: "#f3f4f6",
|
|
25
|
-
borderRadius: "6px",
|
|
26
|
-
color: "#4b5563",
|
|
27
|
-
fontSize: "12px",
|
|
28
|
-
lineHeight: 1.45,
|
|
29
|
-
margin: 0,
|
|
30
|
-
maxHeight: "96px",
|
|
31
|
-
overflow: "hidden",
|
|
32
|
-
padding: "8px",
|
|
33
|
-
whiteSpace: "pre-wrap"
|
|
34
|
-
};
|
|
35
|
-
var footerStyle = {
|
|
36
|
-
display: "flex",
|
|
37
|
-
justifyContent: "flex-end"
|
|
38
|
-
};
|
|
39
|
-
var buttonStyle = {
|
|
40
|
-
background: "#111827",
|
|
41
|
-
border: 0,
|
|
42
|
-
borderRadius: "6px",
|
|
43
|
-
color: "#ffffff",
|
|
44
|
-
fontSize: "12px",
|
|
45
|
-
fontWeight: 500,
|
|
46
|
-
padding: "4px 10px"
|
|
47
|
-
};
|
|
48
|
-
function PlainTextBuilderPreview({ data }) {
|
|
49
|
-
const label = data.label || "Info Screen";
|
|
50
|
-
const description = data.description || "No content provided...";
|
|
51
|
-
const buttonLabel = data.buttonLabel || "Continue";
|
|
52
|
-
return createElement(
|
|
53
|
-
"div",
|
|
54
|
-
{ style: shellStyle },
|
|
55
|
-
createElement("p", { style: titleStyle }, label),
|
|
56
|
-
createElement("p", { style: descriptionStyle }, description),
|
|
57
|
-
createElement(
|
|
58
|
-
"div",
|
|
59
|
-
{ style: footerStyle },
|
|
60
|
-
createElement("button", { disabled: true, style: buttonStyle, type: "button" }, buttonLabel)
|
|
61
|
-
)
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
function PlainTextSettings(_props) {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
10
|
var plainTextBuilder = {
|
|
68
11
|
type: "plainText",
|
|
69
|
-
label: "Info / Text"
|
|
70
|
-
SettingsComponent: PlainTextSettings,
|
|
71
|
-
CanvasComponent: PlainTextBuilderPreview
|
|
12
|
+
label: "Info / Text"
|
|
72
13
|
};
|
|
73
14
|
|
|
74
15
|
// src/nodes/plainText/manifest.ts
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
declare const QUESTION_NODE_TYPES: readonly ["textInput", "numberInput", "emailInput", "dateInput", "multiInput", "zipCodeInput", "singleChoice", "multipleChoice", "dropdown", "ranking", "cascadingChoice", "matrixChoice", "rating", "slider", "consent", "captcha", "image", "video", "audio", "plainText", "emojiRating"];
|
|
2
|
+
declare const FLOW_NODE_TYPES: readonly ["start", "end", "branch", "validation"];
|
|
3
|
+
type QuestionNodeType = (typeof QUESTION_NODE_TYPES)[number];
|
|
4
|
+
type FlowNodeType = (typeof FLOW_NODE_TYPES)[number];
|
|
5
|
+
type SurveyNodeType = QuestionNodeType | FlowNodeType;
|
|
6
|
+
type NodeCategory = "input" | "choice" | "logic" | "media" | "flow";
|
|
7
|
+
type PrimitiveValue = string | number | boolean | null;
|
|
8
|
+
type JsonValue = PrimitiveValue | JsonValue[] | {
|
|
9
|
+
[key: string]: JsonValue;
|
|
10
|
+
};
|
|
11
|
+
type NodeData = Record<string, JsonValue | undefined>;
|
|
12
|
+
type NodeValue = JsonValue | undefined;
|
|
13
|
+
type DataType = "text" | "number" | "boolean" | "option" | "array" | "object" | "none";
|
|
14
|
+
type PropertyFieldType = "text" | "textarea" | "number" | "switch" | "select" | "color" | "options" | "condition" | "stepBuilder" | "fileTextarea" | "file" | "files" | "emojiOptions";
|
|
15
|
+
interface SelectOption {
|
|
16
|
+
readonly label: string;
|
|
17
|
+
readonly value: string;
|
|
18
|
+
}
|
|
19
|
+
interface PropertyField<TData extends NodeData = NodeData> {
|
|
20
|
+
readonly name: keyof TData & string;
|
|
21
|
+
readonly label: string;
|
|
22
|
+
readonly type: PropertyFieldType;
|
|
23
|
+
readonly placeholder?: string;
|
|
24
|
+
readonly helperText?: string;
|
|
25
|
+
readonly defaultValue?: JsonValue;
|
|
26
|
+
readonly options?: readonly SelectOption[];
|
|
27
|
+
readonly visible?: (data: Readonly<TData>) => boolean;
|
|
28
|
+
readonly min?: number;
|
|
29
|
+
readonly max?: number;
|
|
30
|
+
}
|
|
31
|
+
interface NodeManifest<TType extends SurveyNodeType = SurveyNodeType, TData extends NodeData = NodeData> {
|
|
32
|
+
readonly type: TType;
|
|
33
|
+
readonly label: string;
|
|
34
|
+
readonly description: string;
|
|
35
|
+
readonly category: NodeCategory;
|
|
36
|
+
readonly dataType: DataType;
|
|
37
|
+
readonly defaultData: Readonly<TData>;
|
|
38
|
+
readonly properties: readonly PropertyField<TData>[];
|
|
39
|
+
}
|
|
40
|
+
interface ValidationResult {
|
|
41
|
+
readonly valid: boolean;
|
|
42
|
+
readonly error?: string;
|
|
43
|
+
}
|
|
44
|
+
interface NodeLogicContext<TType extends SurveyNodeType = SurveyNodeType> {
|
|
45
|
+
readonly nodeId: string;
|
|
46
|
+
readonly nodeType: TType;
|
|
47
|
+
readonly answerKey?: string;
|
|
48
|
+
}
|
|
49
|
+
interface ValidationContext<TType extends SurveyNodeType = SurveyNodeType> extends NodeLogicContext<TType> {
|
|
50
|
+
readonly mode?: "LIVE" | "TEST";
|
|
51
|
+
}
|
|
52
|
+
interface ExtractedValue {
|
|
53
|
+
readonly questionId?: string;
|
|
54
|
+
readonly columnKey?: string;
|
|
55
|
+
readonly columnLabel?: string;
|
|
56
|
+
readonly textValue?: string;
|
|
57
|
+
readonly numberValue?: number;
|
|
58
|
+
readonly booleanValue?: boolean;
|
|
59
|
+
readonly optionUuid?: string;
|
|
60
|
+
readonly optionText?: string;
|
|
61
|
+
readonly arrayValue?: readonly JsonValue[];
|
|
62
|
+
readonly objectValue?: Readonly<Record<string, JsonValue>>;
|
|
63
|
+
readonly metadata?: Readonly<Record<string, JsonValue>>;
|
|
64
|
+
}
|
|
65
|
+
interface ExtractionContext<TType extends SurveyNodeType = SurveyNodeType> extends NodeLogicContext<TType> {
|
|
66
|
+
readonly questionLabel?: string;
|
|
67
|
+
}
|
|
68
|
+
interface NodeLogic<TType extends SurveyNodeType = SurveyNodeType, TData extends NodeData = NodeData, TValue extends NodeValue = NodeValue> {
|
|
69
|
+
readonly type: TType;
|
|
70
|
+
readonly dataType: DataType;
|
|
71
|
+
readonly defaultData: Readonly<TData>;
|
|
72
|
+
readonly defaultValue?: TValue;
|
|
73
|
+
normalizeValue(rawValue: unknown, nodeData: Readonly<TData>, context: NodeLogicContext<TType>): TValue;
|
|
74
|
+
validate(value: TValue, nodeData: Readonly<TData>, context: ValidationContext<TType>): ValidationResult;
|
|
75
|
+
extractValue(value: TValue, nodeData: Readonly<TData>, context: ExtractionContext<TType>): readonly ExtractedValue[];
|
|
76
|
+
}
|
|
77
|
+
type CompleteLogicRegistry<TType extends QuestionNodeType = QuestionNodeType> = Readonly<Record<TType, NodeLogic<TType, NodeData, NodeValue>>>;
|
|
78
|
+
type LogicRegistry<TType extends SurveyNodeType = SurveyNodeType> = Readonly<Partial<{
|
|
79
|
+
[K in TType]: NodeLogic<K, NodeData, NodeValue>;
|
|
80
|
+
}>>;
|
|
81
|
+
type RegistryKeySet = Readonly<Partial<Record<SurveyNodeType, unknown>>>;
|
|
82
|
+
declare function defineLogicRegistry<const TRegistry extends RegistryKeySet>(registry: TRegistry): TRegistry;
|
|
83
|
+
declare function createInitialData<TData extends NodeData>(manifest: NodeManifest<SurveyNodeType, TData>): TData;
|
|
84
|
+
|
|
85
|
+
export { type CompleteLogicRegistry as C, type DataType as D, type ExtractedValue as E, type JsonValue as J, type LogicRegistry as L, type NodeLogic as N, type PropertyField as P, type QuestionNodeType as Q, type SelectOption as S, type ValidationContext as V, type ExtractionContext as a, type NodeLogicContext as b, type ValidationResult as c, createInitialData as d, defineLogicRegistry as e, type NodeManifest as f, type PropertyFieldType as g, type NodeData as h, type SurveyNodeType as i, type NodeValue as j };
|
package/dist/logic.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { P as PlainTextData, a as PlainTextValue } from './types-
|
|
2
|
-
export { C as CompleteLogicRegistry, D as DataType, E as ExtractedValue,
|
|
3
|
-
import 'react';
|
|
1
|
+
import { P as PlainTextData, a as PlainTextValue } from './types-D78Zx0gX.mjs';
|
|
2
|
+
export { C as CompleteLogicRegistry, D as DataType, E as ExtractedValue, a as ExtractionContext, L as LogicRegistry, N as NodeLogic, b as NodeLogicContext, V as ValidationContext, c as ValidationResult, d as createInitialData, e as defineLogicRegistry } from './coreTypes-D-1hYIe5.mjs';
|
|
4
3
|
|
|
5
4
|
declare const plainTextLogic: {
|
|
6
5
|
type: "plainText";
|
|
@@ -9,6 +8,7 @@ declare const plainTextLogic: {
|
|
|
9
8
|
defaultValue: {
|
|
10
9
|
viewed: false;
|
|
11
10
|
};
|
|
11
|
+
normalizeValue: (value: unknown) => PlainTextValue;
|
|
12
12
|
validate: () => {
|
|
13
13
|
valid: true;
|
|
14
14
|
};
|
|
@@ -27,6 +27,7 @@ declare const logicRegistry: {
|
|
|
27
27
|
defaultValue: {
|
|
28
28
|
viewed: false;
|
|
29
29
|
};
|
|
30
|
+
normalizeValue: (value: unknown) => PlainTextValue;
|
|
30
31
|
validate: () => {
|
|
31
32
|
valid: true;
|
|
32
33
|
};
|
package/dist/logic.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
function defineQuestionNode(definition) {
|
|
3
|
-
return definition;
|
|
4
|
-
}
|
|
1
|
+
// src/coreTypes.ts
|
|
5
2
|
function defineLogicRegistry(registry) {
|
|
6
3
|
return registry;
|
|
7
4
|
}
|
|
5
|
+
function createInitialData(manifest) {
|
|
6
|
+
return { ...manifest.defaultData };
|
|
7
|
+
}
|
|
8
8
|
|
|
9
9
|
// src/nodes/plainText/manifest.ts
|
|
10
10
|
var plainTextDefaultData = {
|
|
@@ -45,17 +45,24 @@ var plainTextManifest = {
|
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
// src/nodes/plainText/logic.ts
|
|
48
|
+
var normalizePlainTextValue = (value) => {
|
|
49
|
+
if (!value || typeof value !== "object") {
|
|
50
|
+
return { viewed: false };
|
|
51
|
+
}
|
|
52
|
+
return { viewed: Boolean(value.viewed) };
|
|
53
|
+
};
|
|
48
54
|
var plainTextLogic = {
|
|
49
55
|
type: "plainText",
|
|
50
56
|
dataType: "none",
|
|
51
57
|
defaultData: plainTextDefaultData,
|
|
52
58
|
defaultValue: { viewed: false },
|
|
59
|
+
normalizeValue: (value) => normalizePlainTextValue(value),
|
|
53
60
|
validate: () => ({ valid: true }),
|
|
54
61
|
extractValue: (value) => [
|
|
55
62
|
{
|
|
56
63
|
columnKey: "viewed",
|
|
57
64
|
columnLabel: "Viewed",
|
|
58
|
-
booleanValue: Boolean(value
|
|
65
|
+
booleanValue: Boolean(value.viewed)
|
|
59
66
|
}
|
|
60
67
|
]
|
|
61
68
|
};
|
|
@@ -65,8 +72,8 @@ var logicRegistry = defineLogicRegistry({
|
|
|
65
72
|
plainText: plainTextLogic
|
|
66
73
|
});
|
|
67
74
|
export {
|
|
75
|
+
createInitialData,
|
|
68
76
|
defineLogicRegistry,
|
|
69
|
-
defineQuestionNode,
|
|
70
77
|
logicRegistry,
|
|
71
78
|
plainTextLogic
|
|
72
79
|
};
|
package/dist/runner.d.mts
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
export { f as CompleteRunnerRegistry, g as NodeRunner, Q as QuestionNodeDefinition, R as RunnerRegistry, c as defineQuestionNode, h as defineRunnerRegistry } from './types-DJePy6HU.mjs';
|
|
1
|
+
export { C as CompleteRunnerRegistry, N as NodeRunner, a as NodeRunnerProps, Q as QuestionNodeDefinition, R as RunnerRegistry, d as defineQuestionNode, b as defineRunnerRegistry } from './types-BpvjaHAP.mjs';
|
|
2
|
+
import 'react';
|
|
3
|
+
import './coreTypes-D-1hYIe5.mjs';
|
|
5
4
|
|
|
6
|
-
declare function PlainTextRunnerView({ data, onChange, onNext, isActive, }: NodeRunnerProps<PlainTextData, PlainTextValue>): react.DetailedReactHTMLElement<{
|
|
7
|
-
style: CSSProperties;
|
|
8
|
-
}, HTMLElement>;
|
|
9
5
|
declare const plainTextRunner: {
|
|
10
6
|
type: "plainText";
|
|
11
|
-
Component: typeof PlainTextRunnerView;
|
|
12
7
|
};
|
|
13
8
|
|
|
14
9
|
declare const runnerRegistry: {
|
|
15
10
|
readonly plainText: {
|
|
16
11
|
type: "plainText";
|
|
17
|
-
Component: typeof PlainTextRunnerView;
|
|
18
12
|
};
|
|
19
13
|
};
|
|
20
14
|
|
|
21
|
-
export {
|
|
15
|
+
export { plainTextRunner, runnerRegistry };
|
package/dist/runner.mjs
CHANGED
|
@@ -7,67 +7,8 @@ function defineRunnerRegistry(registry) {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
// src/nodes/plainText/runner.ts
|
|
10
|
-
import { createElement } from "react";
|
|
11
|
-
var shellStyle = {
|
|
12
|
-
display: "grid",
|
|
13
|
-
gap: "24px",
|
|
14
|
-
maxWidth: "576px",
|
|
15
|
-
padding: "16px 0",
|
|
16
|
-
width: "100%"
|
|
17
|
-
};
|
|
18
|
-
var descriptionStyle = {
|
|
19
|
-
color: "#334155",
|
|
20
|
-
fontSize: "18px",
|
|
21
|
-
lineHeight: 1.65,
|
|
22
|
-
margin: 0,
|
|
23
|
-
whiteSpace: "pre-wrap"
|
|
24
|
-
};
|
|
25
|
-
var buttonStyle = {
|
|
26
|
-
alignItems: "center",
|
|
27
|
-
background: "#111827",
|
|
28
|
-
border: 0,
|
|
29
|
-
borderRadius: "999px",
|
|
30
|
-
color: "#ffffff",
|
|
31
|
-
cursor: "pointer",
|
|
32
|
-
display: "inline-flex",
|
|
33
|
-
fontSize: "15px",
|
|
34
|
-
fontWeight: 600,
|
|
35
|
-
gap: "8px",
|
|
36
|
-
justifySelf: "start",
|
|
37
|
-
padding: "12px 24px"
|
|
38
|
-
};
|
|
39
|
-
function PlainTextRunnerView({
|
|
40
|
-
data,
|
|
41
|
-
onChange,
|
|
42
|
-
onNext,
|
|
43
|
-
isActive
|
|
44
|
-
}) {
|
|
45
|
-
const description = data.description || "No description provided...";
|
|
46
|
-
const buttonLabel = data.buttonLabel || "Continue";
|
|
47
|
-
const children = [createElement("p", { key: "description", style: descriptionStyle }, description)];
|
|
48
|
-
if (isActive) {
|
|
49
|
-
children.push(
|
|
50
|
-
createElement(
|
|
51
|
-
"button",
|
|
52
|
-
{
|
|
53
|
-
key: "button",
|
|
54
|
-
onClick: () => {
|
|
55
|
-
onChange({ viewed: true });
|
|
56
|
-
onNext?.();
|
|
57
|
-
},
|
|
58
|
-
style: buttonStyle,
|
|
59
|
-
type: "button"
|
|
60
|
-
},
|
|
61
|
-
buttonLabel,
|
|
62
|
-
" ->"
|
|
63
|
-
)
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
return createElement("div", { style: shellStyle }, children);
|
|
67
|
-
}
|
|
68
10
|
var plainTextRunner = {
|
|
69
|
-
type: "plainText"
|
|
70
|
-
Component: PlainTextRunnerView
|
|
11
|
+
type: "plainText"
|
|
71
12
|
};
|
|
72
13
|
|
|
73
14
|
// src/runner/index.ts
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ComponentType, ReactNode } from 'react';
|
|
2
|
+
import { Q as QuestionNodeType, i as SurveyNodeType, h as NodeData, j as NodeValue, f as NodeManifest, N as NodeLogic } from './coreTypes-D-1hYIe5.mjs';
|
|
3
|
+
|
|
4
|
+
interface NodeRunnerProps<TData extends NodeData = NodeData, TValue extends NodeValue = NodeValue> {
|
|
5
|
+
readonly data: Readonly<TData>;
|
|
6
|
+
readonly value: TValue;
|
|
7
|
+
readonly onChange: (newValue: TValue) => void;
|
|
8
|
+
readonly onNext?: () => void;
|
|
9
|
+
readonly error?: string;
|
|
10
|
+
readonly isActive?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface NodeRunner<TType extends SurveyNodeType = SurveyNodeType, TData extends NodeData = NodeData, TValue extends NodeValue = NodeValue> {
|
|
13
|
+
readonly type: TType;
|
|
14
|
+
readonly Component?: ComponentType<NodeRunnerProps<TData, TValue>>;
|
|
15
|
+
}
|
|
16
|
+
interface NodeBuilderProps<TData extends NodeData = NodeData> {
|
|
17
|
+
readonly data: Readonly<TData>;
|
|
18
|
+
readonly onChange: (newData: TData) => void;
|
|
19
|
+
}
|
|
20
|
+
interface NodeCanvasProps<TData extends NodeData = NodeData> {
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly type: SurveyNodeType;
|
|
23
|
+
readonly data: Readonly<TData>;
|
|
24
|
+
readonly selected?: boolean;
|
|
25
|
+
}
|
|
26
|
+
interface NodeBuilder<TType extends SurveyNodeType = SurveyNodeType, TData extends NodeData = NodeData> {
|
|
27
|
+
readonly type: TType;
|
|
28
|
+
readonly label: string;
|
|
29
|
+
readonly icon?: ReactNode;
|
|
30
|
+
readonly SettingsComponent?: ComponentType<NodeBuilderProps<TData>>;
|
|
31
|
+
readonly CanvasComponent?: ComponentType<NodeCanvasProps<TData>>;
|
|
32
|
+
}
|
|
33
|
+
interface QuestionNodeDefinition<TType extends QuestionNodeType = QuestionNodeType, TData extends NodeData = NodeData, TValue extends NodeValue = NodeValue> {
|
|
34
|
+
readonly manifest: NodeManifest<TType, TData>;
|
|
35
|
+
readonly logic: NodeLogic<TType, TData, TValue>;
|
|
36
|
+
readonly builder: NodeBuilder<TType, TData>;
|
|
37
|
+
readonly runner: NodeRunner<TType, TData, TValue>;
|
|
38
|
+
}
|
|
39
|
+
type CompleteBuilderRegistry<TType extends QuestionNodeType = QuestionNodeType> = Readonly<Record<TType, NodeBuilder<TType, NodeData>>>;
|
|
40
|
+
type CompleteRunnerRegistry<TType extends QuestionNodeType = QuestionNodeType> = Readonly<Record<TType, NodeRunner<TType, NodeData, NodeValue>>>;
|
|
41
|
+
type BuilderRegistry<TType extends SurveyNodeType = SurveyNodeType> = Readonly<Partial<{
|
|
42
|
+
[K in TType]: NodeBuilder<K, NodeData>;
|
|
43
|
+
}>>;
|
|
44
|
+
type RunnerRegistry<TType extends SurveyNodeType = SurveyNodeType> = Readonly<Partial<{
|
|
45
|
+
[K in TType]: NodeRunner<K, NodeData, NodeValue>;
|
|
46
|
+
}>>;
|
|
47
|
+
declare function defineQuestionNode<const TType extends QuestionNodeType, TData extends NodeData, TValue extends NodeValue>(definition: QuestionNodeDefinition<TType, TData, TValue>): QuestionNodeDefinition<TType, TData, TValue>;
|
|
48
|
+
declare function defineBuilderRegistry<const TRegistry extends Readonly<Partial<Record<SurveyNodeType, unknown>>>>(registry: TRegistry): TRegistry;
|
|
49
|
+
declare function defineRunnerRegistry<const TRegistry extends Readonly<Partial<Record<SurveyNodeType, unknown>>>>(registry: TRegistry): TRegistry;
|
|
50
|
+
|
|
51
|
+
export { type BuilderRegistry as B, type CompleteRunnerRegistry as C, type NodeRunner as N, type QuestionNodeDefinition as Q, type RunnerRegistry as R, type NodeRunnerProps as a, defineRunnerRegistry as b, type CompleteBuilderRegistry as c, defineQuestionNode as d, type NodeBuilder as e, type NodeBuilderProps as f, type NodeCanvasProps as g, defineBuilderRegistry as h };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { h as NodeData, J as JsonValue } from './coreTypes-D-1hYIe5.mjs';
|
|
2
|
+
|
|
3
|
+
type PlainTextData = NodeData & {
|
|
4
|
+
label: string;
|
|
5
|
+
description: string;
|
|
6
|
+
buttonLabel: string;
|
|
7
|
+
condition: {
|
|
8
|
+
id: string;
|
|
9
|
+
type: "group";
|
|
10
|
+
logicType: "AND" | "OR";
|
|
11
|
+
children: JsonValue[];
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
type PlainTextValue = {
|
|
15
|
+
viewed: boolean;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type { PlainTextData as P, PlainTextValue as a };
|