@esheet/renderer 0.0.4-0 → 0.0.4-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/dist/index.d.ts +8 -291
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5385 -4342
- package/dist/lib/EsheetRenderer.d.ts +129 -0
- package/dist/lib/EsheetRenderer.d.ts.map +1 -0
- package/dist/lib/components/FieldNode.d.ts +17 -0
- package/dist/lib/components/FieldNode.d.ts.map +1 -0
- package/dist/lib/components/RendererBody.d.ts +14 -0
- package/dist/lib/components/RendererBody.d.ts.map +1 -0
- package/dist/lib/components/index.d.ts +3 -0
- package/dist/lib/components/index.d.ts.map +1 -0
- package/dist/lib/hooks/index.d.ts +2 -0
- package/dist/lib/hooks/index.d.ts.map +1 -0
- package/dist/lib/hooks/useRendererInit.d.ts +12 -0
- package/dist/lib/hooks/useRendererInit.d.ts.map +1 -0
- package/dist/lib/mcp/index.d.ts +7 -0
- package/dist/lib/mcp/index.d.ts.map +1 -0
- package/dist/lib/mcp/system-prompt.d.ts +2 -0
- package/dist/lib/mcp/system-prompt.d.ts.map +1 -0
- package/dist/lib/mcp/tool-definitions.d.ts +10 -0
- package/dist/lib/mcp/tool-definitions.d.ts.map +1 -0
- package/dist/lib/mcp/tool-executor.d.ts +5 -0
- package/dist/lib/mcp/tool-executor.d.ts.map +1 -0
- package/dist/lib/mcp/useRendererToolBridge.d.ts +28 -0
- package/dist/lib/mcp/useRendererToolBridge.d.ts.map +1 -0
- package/dist/lib/register-defaults.d.ts +2 -0
- package/dist/lib/register-defaults.d.ts.map +1 -0
- package/dist/lib/renderer-tools.d.ts +56 -0
- package/dist/lib/renderer-tools.d.ts.map +1 -0
- package/dist/lib/renderer.d.ts +49 -0
- package/dist/lib/renderer.d.ts.map +1 -0
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,291 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import { ResponseExportOptions } from '@esheet/adapters';
|
|
10
|
-
import { UIStore } from '@esheet/core';
|
|
11
|
-
import { ValidationError } from '@esheet/core';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* EsheetRenderer - Read-only questionnaire form renderer
|
|
15
|
-
*
|
|
16
|
-
* Renders a form in fill-out mode with conditional visibility logic.
|
|
17
|
-
* Reuses all field components from @esheet/fields.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```tsx
|
|
21
|
-
* const rendererRef = useRef<EsheetRendererHandle>(null);
|
|
22
|
-
*
|
|
23
|
-
* <EsheetRenderer
|
|
24
|
-
* formData={myFormDefinition}
|
|
25
|
-
* initialResponses={{ field1: 'answer' }}
|
|
26
|
-
* ref={rendererRef}
|
|
27
|
-
* />
|
|
28
|
-
*
|
|
29
|
-
* // Later: get responses
|
|
30
|
-
* const responses = rendererRef.current?.getRawResponse();
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export declare const EsheetRenderer: default_2.ForwardRefExoticComponent<EsheetRendererProps & default_2.RefAttributes<EsheetRendererHandle>>;
|
|
34
|
-
|
|
35
|
-
export declare interface EsheetRendererHandle {
|
|
36
|
-
/** Get current form responses */
|
|
37
|
-
getRawResponse: () => FormResponse;
|
|
38
|
-
/**
|
|
39
|
-
* Get form responses in the specified format.
|
|
40
|
-
*
|
|
41
|
-
* @param options - Format and export options
|
|
42
|
-
* @returns Native FormResponse or FHIR QuestionnaireResponse
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```ts
|
|
46
|
-
* // Native format (default)
|
|
47
|
-
* const native = ref.current.getResponse();
|
|
48
|
-
*
|
|
49
|
-
* // FHIR QuestionnaireResponse
|
|
50
|
-
* const fhir = ref.current.getResponse({
|
|
51
|
-
* format: 'fhir',
|
|
52
|
-
* fhir: {
|
|
53
|
-
* questionnaireUrl: 'http://example.org/Questionnaire/my-form',
|
|
54
|
-
* status: 'completed',
|
|
55
|
-
* }
|
|
56
|
-
* });
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
getResponse: <T extends ResponseFormat = 'native'>(options?: GetResponseOptions & {
|
|
60
|
-
format?: T;
|
|
61
|
-
}) => GetResponseResult<T>;
|
|
62
|
-
/** Get form store instance */
|
|
63
|
-
getFormStore: () => FormStore;
|
|
64
|
-
/** Get UI store instance */
|
|
65
|
-
getUIStore: () => UIStore;
|
|
66
|
-
/** Get validated form responses (returns null if invalid) */
|
|
67
|
-
getValidResponse: () => {
|
|
68
|
-
response: FormResponse | null;
|
|
69
|
-
errors: ValidationError[];
|
|
70
|
-
};
|
|
71
|
-
/** Returns true if touch mode is currently enabled */
|
|
72
|
-
isTouchModeEnabled: () => boolean;
|
|
73
|
-
/** Toggle touch mode on/off. Only works when touchMode prop is 'auto' or undefined. Overrides auto-detection. */
|
|
74
|
-
setTouchMode: (enabled: boolean) => void;
|
|
75
|
-
/** Reset to auto-detection mode (clears manual override). Only works when touchMode='auto'. */
|
|
76
|
-
resetTouchMode: () => void;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export declare interface EsheetRendererProps {
|
|
80
|
-
/** Form definition — accepts FormDefinition, SurveyJS schema, MCP elicitation envelope,
|
|
81
|
-
* or any of the above as a JSON/YAML string. Auto-detected and converted internally.
|
|
82
|
-
* Set `strict` to disable auto-conversion and require a valid FormDefinition directly. */
|
|
83
|
-
formDataInput: unknown;
|
|
84
|
-
/** Additional CSS classes for root container */
|
|
85
|
-
className?: string;
|
|
86
|
-
/** Initial form responses (pre-fill data) */
|
|
87
|
-
initialResponses?: FormResponse;
|
|
88
|
-
/** When true, disables auto-detection of MCP/SurveyJS formats.
|
|
89
|
-
* Only accepts a valid eSheet FormDefinition (or JSON/YAML string thereof). */
|
|
90
|
-
strict?: boolean;
|
|
91
|
-
/** Called after the form definition has been parsed and loaded into the store. */
|
|
92
|
-
onReady?: () => void;
|
|
93
|
-
/**
|
|
94
|
-
* Called once after the renderer mounts, providing a narrow `RendererTools`
|
|
95
|
-
* facade for MCP / AI tool integrations.
|
|
96
|
-
*/
|
|
97
|
-
onRendererToolsReady?: (tools: RendererTools) => void;
|
|
98
|
-
/**
|
|
99
|
-
* Enable touch-optimized mode with larger touch targets.
|
|
100
|
-
* - `true`: Always enable touch mode
|
|
101
|
-
* - `false`: Never enable touch mode (CSS media query still applies)
|
|
102
|
-
* - `'auto'`: Enable based on viewport width (<980px) via JavaScript
|
|
103
|
-
* - `undefined`: Rely on CSS media query only (default)
|
|
104
|
-
*/
|
|
105
|
-
touchMode?: boolean | 'auto';
|
|
106
|
-
/**
|
|
107
|
-
* Called when touch mode changes (via auto-detection or programmatic toggle).
|
|
108
|
-
* Useful for syncing external UI with the renderer's touch state.
|
|
109
|
-
*/
|
|
110
|
-
onTouchModeChange?: (enabled: boolean) => void;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export declare function executeToolCall(toolName: string, args: ToolArgs, tools: RendererTools): string | Record<string, unknown>;
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* FieldNode - Renders a single field or section with recursive children
|
|
117
|
-
*
|
|
118
|
-
* Looks up the field component from the registry and passes field props.
|
|
119
|
-
* For sections, recursively renders visible children.
|
|
120
|
-
*/
|
|
121
|
-
export declare const FieldNode: default_2.NamedExoticComponent<FieldNodeProps>;
|
|
122
|
-
|
|
123
|
-
declare interface FieldNodeProps {
|
|
124
|
-
id: string;
|
|
125
|
-
form: FormStore;
|
|
126
|
-
ui: UIStore;
|
|
127
|
-
/** Nesting depth for visual styling (default: 0) */
|
|
128
|
-
depth?: number;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export { FormDefinition }
|
|
132
|
-
|
|
133
|
-
export { FormResponseEnvelope }
|
|
134
|
-
|
|
135
|
-
/** Options for getResponse() */
|
|
136
|
-
export declare interface GetResponseOptions {
|
|
137
|
-
/** Output format: 'native' (default) or 'fhir' (FHIR QuestionnaireResponse) */
|
|
138
|
-
format?: ResponseFormat;
|
|
139
|
-
/** FHIR export options (required when format is 'fhir') */
|
|
140
|
-
fhir?: Omit<ResponseExportOptions, 'questionnaireUrl'> & {
|
|
141
|
-
/** Canonical URL of the questionnaire. Falls back to form._sourceData metadata if available. */
|
|
142
|
-
questionnaireUrl?: string;
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/** Return type for getResponse() — varies by format */
|
|
147
|
-
export declare type GetResponseResult<T extends ResponseFormat = 'native'> = T extends 'fhir' ? FhirQuestionnaireResponse : FormResponse;
|
|
148
|
-
|
|
149
|
-
export declare const RENDERER_SYSTEM_PROMPT: string;
|
|
150
|
-
|
|
151
|
-
export declare const RENDERER_TOOL_DEFINITIONS: readonly ToolDefinition[];
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* RendererBody - Iterates over visible root fields and renders them
|
|
155
|
-
*
|
|
156
|
-
* Respects conditional visibility logic from form store.
|
|
157
|
-
* Only renders fields where isVisible() returns true.
|
|
158
|
-
* Sections recursively render their visible children.
|
|
159
|
-
*/
|
|
160
|
-
export declare function RendererBody({ form, ui }: RendererBodyProps): JSX.Element;
|
|
161
|
-
|
|
162
|
-
declare interface RendererBodyProps {
|
|
163
|
-
form: FormStore;
|
|
164
|
-
ui: UIStore;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/** Summary of a single field, suitable for AI context. */
|
|
168
|
-
declare interface RendererFieldSummary {
|
|
169
|
-
id: string;
|
|
170
|
-
fieldType: string;
|
|
171
|
-
/** For text fields: the HTML input type (e.g. 'date', 'datetime-local', 'month', 'time', 'email', 'number'). Use the correct format when filling this field. */
|
|
172
|
-
inputType?: string;
|
|
173
|
-
/** Required value format for structured input types. Use this exact format when calling fill_field. */
|
|
174
|
-
valueFormat?: string;
|
|
175
|
-
question: string | undefined;
|
|
176
|
-
required: boolean;
|
|
177
|
-
/** True if this field already has a response value. False means it is still empty and needs to be filled. */
|
|
178
|
-
hasValue: boolean;
|
|
179
|
-
/** Available option values for selection fields (radio, check, dropdown, etc.). Only present when the field has options. */
|
|
180
|
-
options?: string[];
|
|
181
|
-
/** Available row labels for matrix fields. Only present for singlematrix / multimatrix. */
|
|
182
|
-
rows?: string[];
|
|
183
|
-
/** Available column labels for matrix fields. Only present for singlematrix / multimatrix. */
|
|
184
|
-
columns?: string[];
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Narrow interface exposed to MCP / AI tools via `onRendererToolsReady`.
|
|
189
|
-
* Read-oriented: inspect responses, fill responses, and query the render tree.
|
|
190
|
-
*/
|
|
191
|
-
export declare interface RendererTools {
|
|
192
|
-
/** Currently visible, fillable fields with their available options. */
|
|
193
|
-
getForm: () => {
|
|
194
|
-
formId: string;
|
|
195
|
-
fieldCount: number;
|
|
196
|
-
fields: RendererFieldSummary[];
|
|
197
|
-
};
|
|
198
|
-
/** All fields in the form regardless of visibility, rules, or enabled state. */
|
|
199
|
-
getFormRaw: () => {
|
|
200
|
-
formId: string;
|
|
201
|
-
fieldCount: number;
|
|
202
|
-
fields: RendererFieldSummary[];
|
|
203
|
-
};
|
|
204
|
-
/** Get current raw responses keyed by field ID. */
|
|
205
|
-
getResponses: () => Record<string, unknown>;
|
|
206
|
-
/** Get validated responses — returns null if validation fails. */
|
|
207
|
-
getValidResponse: () => {
|
|
208
|
-
response: Record<string, unknown> | null;
|
|
209
|
-
errors: ValidationError[];
|
|
210
|
-
};
|
|
211
|
-
/** Set a response value for one visible field. Returns true on success, false if field not found/visible, or an error string if the value format is invalid. */
|
|
212
|
-
fillField: (fieldId: string, value: unknown) => boolean | string;
|
|
213
|
-
/** Clear all responses. */
|
|
214
|
-
clearResponses: () => void;
|
|
215
|
-
/** Full render tree with visibility/enabled/required per field. */
|
|
216
|
-
getFormTree: () => RenderFieldNode[];
|
|
217
|
-
/** Find a field ID by exact ID or partial question match. */
|
|
218
|
-
resolveFieldId: (fieldId?: string, fieldQuestion?: string) => string | undefined;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
declare interface RenderFieldNode {
|
|
222
|
-
/** Field identifier. */
|
|
223
|
-
id: string;
|
|
224
|
-
/** Field definition without nested children. */
|
|
225
|
-
definition: Omit<FieldDefinition, 'fields'>;
|
|
226
|
-
/** Computed visible state. */
|
|
227
|
-
visible: boolean;
|
|
228
|
-
/** Computed enabled state. */
|
|
229
|
-
enabled: boolean;
|
|
230
|
-
/** Computed required state. */
|
|
231
|
-
required: boolean;
|
|
232
|
-
/** Renderable child nodes (sections only). */
|
|
233
|
-
children: RenderFieldNode[];
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/** Response format options for getResponse() */
|
|
237
|
-
export declare type ResponseFormat = 'native' | 'fhir';
|
|
238
|
-
|
|
239
|
-
declare type ToolArgs = Record<string, unknown>;
|
|
240
|
-
|
|
241
|
-
export declare interface ToolDefinition {
|
|
242
|
-
type: string;
|
|
243
|
-
function: {
|
|
244
|
-
name: string;
|
|
245
|
-
description: string;
|
|
246
|
-
parameters: Record<string, unknown>;
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Initialize renderer with form definition.
|
|
252
|
-
*
|
|
253
|
-
* Auto-detects and converts the following input formats:
|
|
254
|
-
* - eSheet FormDefinition (object or JSON/YAML string)
|
|
255
|
-
* - FHIR R4 Questionnaire resource
|
|
256
|
-
* - MCP elicitation/create envelope
|
|
257
|
-
* - SurveyJS schema (has top-level `pages` or `elements` array)
|
|
258
|
-
*/
|
|
259
|
-
export declare function useRendererInit(form: FormStore, ui: UIStore, formData: unknown, initialResponses?: FormResponse, onValidationError?: (errors: string[]) => void, strict?: boolean, onReady?: () => void): void;
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Listens for AI tool-call events on a target element and dispatches them to
|
|
263
|
-
* the renderer's MCP tool executor. Returns the `onRendererToolsReady` callback
|
|
264
|
-
* to pass to `<EsheetRenderer>`.
|
|
265
|
-
*
|
|
266
|
-
* @example – default (listens on document)
|
|
267
|
-
* const onRendererToolsReady = useRendererMcpToolHandler({ eventName: 'ozwell-tool-call' });
|
|
268
|
-
* <EsheetRenderer onRendererToolsReady={onRendererToolsReady} ... />
|
|
269
|
-
*
|
|
270
|
-
* @example – scoped to a container element
|
|
271
|
-
* const ref = React.useRef<HTMLDivElement>(null);
|
|
272
|
-
* const onRendererToolsReady = useRendererMcpToolHandler({ target: ref.current ?? undefined, eventName: 'ozwell-tool-call' });
|
|
273
|
-
* <div ref={ref}><EsheetRenderer onRendererToolsReady={onRendererToolsReady} ... /></div>
|
|
274
|
-
*/
|
|
275
|
-
export declare function useRendererMcpToolHandler(options: UseRendererMcpToolHandlerOptions): (tools: RendererTools) => void;
|
|
276
|
-
|
|
277
|
-
export declare interface UseRendererMcpToolHandlerOptions {
|
|
278
|
-
/**
|
|
279
|
-
* The DOM element to listen on for tool-call events.
|
|
280
|
-
* Pass `document` to listen globally, or a specific element to scope it.
|
|
281
|
-
*/
|
|
282
|
-
target?: EventTarget;
|
|
283
|
-
/**
|
|
284
|
-
* The event name to listen for, e.g. `'ozwell-tool-call'`.
|
|
285
|
-
*/
|
|
286
|
-
eventName: string;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
export { ValidationError }
|
|
290
|
-
|
|
291
|
-
export { }
|
|
1
|
+
export { EsheetRenderer, type EsheetRendererProps, type EsheetRendererHandle, type GetResponseOptions, type GetResponseResult, type ResponseFormat, } from './lib/EsheetRenderer.js';
|
|
2
|
+
export { renderer, buildRenderTree, type RenderTreeOptions, } from './lib/renderer.js';
|
|
3
|
+
export type { FormDefinition, FormResponseEnvelope, ValidationError, } from '@esheet/core';
|
|
4
|
+
export { RendererBody, FieldNode } from './lib/components/index.js';
|
|
5
|
+
export { useRendererInit } from './lib/hooks/index.js';
|
|
6
|
+
export { executeToolCall, RENDERER_TOOL_DEFINITIONS, RENDERER_SYSTEM_PROMPT, useRendererMcpToolHandler, type ToolDefinition, type UseRendererMcpToolHandlerOptions, } from './lib/mcp/index.js';
|
|
7
|
+
export type { RendererTools } from './lib/renderer-tools.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAC;AAG5B,OAAO,EACL,cAAc,EACd,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,cAAc,GACpB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACL,QAAQ,EACR,eAAe,EACf,KAAK,iBAAiB,GACvB,MAAM,mBAAmB,CAAC;AAG3B,YAAY,EACV,cAAc,EACd,oBAAoB,EACpB,eAAe,GAChB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAGpE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,sBAAsB,EACtB,yBAAyB,EACzB,KAAK,cAAc,EACnB,KAAK,gCAAgC,GACtC,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC"}
|