@process.co/ui 0.0.8 → 0.0.10
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 +349 -284
- package/css/ui.css +142 -7
- package/dist/components/fields/index.cjs +387 -21
- package/dist/components/fields/index.cjs.map +1 -1
- package/dist/components/fields/index.d.cts +1 -1
- package/dist/components/fields/index.d.ts +1 -1
- package/dist/components/fields/index.js +373 -22
- package/dist/components/fields/index.js.map +1 -1
- package/dist/index-DGN9LJqq.d.cts +711 -0
- package/dist/index-DGN9LJqq.d.ts +711 -0
- package/dist/index.cjs +428 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +426 -79
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/index-yubVl0hX.d.cts +0 -403
- package/dist/index-yubVl0hX.d.ts +0 -403
|
@@ -0,0 +1,711 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import React__default from 'react';
|
|
3
|
+
|
|
4
|
+
interface InputProps {
|
|
5
|
+
/**
|
|
6
|
+
* Field name/key.
|
|
7
|
+
* Used for Yjs field path and validation error tracking.
|
|
8
|
+
* When nested inside NestedFieldProvider, the parent path is auto-prepended.
|
|
9
|
+
*/
|
|
10
|
+
fieldName: string;
|
|
11
|
+
/** Display label for the field */
|
|
12
|
+
label: string;
|
|
13
|
+
/** Current value */
|
|
14
|
+
value: string | {
|
|
15
|
+
expression: string;
|
|
16
|
+
type: 'expression';
|
|
17
|
+
value?: string;
|
|
18
|
+
};
|
|
19
|
+
/** Called when value changes */
|
|
20
|
+
onChange: (value: string | {
|
|
21
|
+
expression: string;
|
|
22
|
+
type: 'expression';
|
|
23
|
+
}, metadata?: any) => void;
|
|
24
|
+
/** Whether the field is disabled */
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
/** Placeholder text */
|
|
27
|
+
placeholder?: string;
|
|
28
|
+
/** Expected return type for validation */
|
|
29
|
+
expectedType?: string;
|
|
30
|
+
/** Whether this is a required field */
|
|
31
|
+
required?: boolean;
|
|
32
|
+
/** Whether this field has a required property error (missing value) */
|
|
33
|
+
hasRequiredError?: boolean;
|
|
34
|
+
/** Custom className for the wrapper */
|
|
35
|
+
className?: string;
|
|
36
|
+
/** Custom className for the editor container */
|
|
37
|
+
editorClassName?: string;
|
|
38
|
+
/** Property definition (for richer context) */
|
|
39
|
+
propertyDefinition?: any;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Mock Input component for development/design mode.
|
|
43
|
+
*
|
|
44
|
+
* This is a simplified version that renders a basic input field.
|
|
45
|
+
* In production, this is replaced with the real Input from packages/ui
|
|
46
|
+
* which includes collaboration, type inference, and expression support.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```tsx
|
|
50
|
+
* <Input
|
|
51
|
+
* fieldName="firstName"
|
|
52
|
+
* label="First Name"
|
|
53
|
+
* value={value}
|
|
54
|
+
* onChange={setValue}
|
|
55
|
+
* />
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare function Input({ fieldName, label, value, onChange, disabled, placeholder, expectedType, required, hasRequiredError, className, editorClassName, }: InputProps): React.JSX.Element;
|
|
59
|
+
|
|
60
|
+
interface SelectOption {
|
|
61
|
+
node?: React.ReactNode;
|
|
62
|
+
value: string;
|
|
63
|
+
label: string;
|
|
64
|
+
}
|
|
65
|
+
interface SelectProps {
|
|
66
|
+
/**
|
|
67
|
+
* Field name/key.
|
|
68
|
+
* Used for Yjs field path and validation error tracking.
|
|
69
|
+
* When nested inside NestedFieldProvider, the parent path is auto-prepended.
|
|
70
|
+
*/
|
|
71
|
+
fieldName: string;
|
|
72
|
+
/** Display label for the field */
|
|
73
|
+
label: string;
|
|
74
|
+
/** Current value */
|
|
75
|
+
value: string | {
|
|
76
|
+
expression: string;
|
|
77
|
+
type: 'expression';
|
|
78
|
+
value?: string;
|
|
79
|
+
};
|
|
80
|
+
/** Called when value changes */
|
|
81
|
+
onChange: (value: string | {
|
|
82
|
+
expression: string;
|
|
83
|
+
type: 'expression';
|
|
84
|
+
}, metadata?: any) => void;
|
|
85
|
+
/** Available options */
|
|
86
|
+
options: SelectOption[] | string[];
|
|
87
|
+
/** Whether the field is disabled */
|
|
88
|
+
disabled?: boolean;
|
|
89
|
+
/** Placeholder text */
|
|
90
|
+
placeholder?: string;
|
|
91
|
+
/** Expected return type for validation */
|
|
92
|
+
expectedType?: string;
|
|
93
|
+
/** Whether this is a required field */
|
|
94
|
+
required?: boolean;
|
|
95
|
+
/** Whether this field has a required property error (missing value) */
|
|
96
|
+
hasRequiredError?: boolean;
|
|
97
|
+
/** Custom className for the wrapper */
|
|
98
|
+
className?: string;
|
|
99
|
+
/** Property definition (for richer context) */
|
|
100
|
+
propertyDefinition?: any;
|
|
101
|
+
/**
|
|
102
|
+
* Render prop for custom select UI.
|
|
103
|
+
* If not provided, uses a basic HTML select.
|
|
104
|
+
*/
|
|
105
|
+
children?: (props: SelectRenderProps) => React.ReactNode;
|
|
106
|
+
}
|
|
107
|
+
interface SelectRenderProps {
|
|
108
|
+
value: string;
|
|
109
|
+
onChange: (value: string) => void;
|
|
110
|
+
onFocus?: () => void;
|
|
111
|
+
onBlur?: () => void;
|
|
112
|
+
onExpressionClick: () => void;
|
|
113
|
+
options: SelectOption[];
|
|
114
|
+
localInput: string;
|
|
115
|
+
setLocalInput: (value: string) => void;
|
|
116
|
+
expressionMode: {
|
|
117
|
+
current: 'value' | 'expression';
|
|
118
|
+
isExpressionMode: boolean;
|
|
119
|
+
isEditorMode: boolean;
|
|
120
|
+
isEditing: boolean;
|
|
121
|
+
isFullScreen: boolean;
|
|
122
|
+
expression: string;
|
|
123
|
+
switchToValue: () => void;
|
|
124
|
+
switchToExpression: () => void;
|
|
125
|
+
switchToEditor: () => void;
|
|
126
|
+
clear: () => void;
|
|
127
|
+
};
|
|
128
|
+
inferredType?: string;
|
|
129
|
+
hasTypeMismatch?: boolean;
|
|
130
|
+
hasError?: boolean;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Mock Select component for development/design mode.
|
|
134
|
+
*
|
|
135
|
+
* This is a simplified version that renders a basic select field.
|
|
136
|
+
* In production, this is replaced with the real Select from packages/ui
|
|
137
|
+
* which includes collaboration, type inference, and expression support.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```tsx
|
|
141
|
+
* <Select
|
|
142
|
+
* fieldName="status"
|
|
143
|
+
* label="Status"
|
|
144
|
+
* value={value}
|
|
145
|
+
* onChange={setValue}
|
|
146
|
+
* options={['draft', 'published', 'archived']}
|
|
147
|
+
* />
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
declare function Select({ fieldName, label, value, onChange, options: rawOptions, disabled, placeholder, expectedType, required, hasRequiredError, className, children, }: SelectProps): React.JSX.Element;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Shared Operator Type Definitions and Utilities
|
|
154
|
+
*
|
|
155
|
+
* This module provides reusable types and utilities for building
|
|
156
|
+
* query builders with type-aware operators (Switch, IfThenElse, etc.)
|
|
157
|
+
*/
|
|
158
|
+
/**
|
|
159
|
+
* Standard operator types for condition builders.
|
|
160
|
+
* Custom UIs can extend this with their own operators.
|
|
161
|
+
*/
|
|
162
|
+
type BaseOperatorType = 'exists' | 'not_exists' | 'string_equals' | 'string_not_equals' | 'string_is_blank' | 'string_is_not_blank' | 'string_starts_with' | 'string_contains' | 'string_not_contains' | 'string_ends_with' | 'number_equals' | 'number_not_equals' | 'number_gt' | 'number_gte' | 'number_lt' | 'number_lte' | 'boolean_equals' | 'is_null' | 'is_not_null' | 'is_string' | 'is_not_string' | 'is_number' | 'is_not_number' | 'is_true' | 'is_false' | 'is_boolean' | 'is_not_boolean';
|
|
163
|
+
/**
|
|
164
|
+
* Generic operator definition that can be extended with custom operators.
|
|
165
|
+
*
|
|
166
|
+
* @template T - Additional operator types to include (defaults to never)
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* // Using base operators only
|
|
170
|
+
* const operators: OperatorDef[] = [...];
|
|
171
|
+
*
|
|
172
|
+
* // Extending with custom operators
|
|
173
|
+
* type MyOperator = 'expression' | 'custom_op';
|
|
174
|
+
* const operators: OperatorDef<MyOperator>[] = [...];
|
|
175
|
+
*/
|
|
176
|
+
type OperatorDef<T = never> = {
|
|
177
|
+
/** The operator value/key */
|
|
178
|
+
value: BaseOperatorType | T;
|
|
179
|
+
/** Which inferred types this applies to ('any' = always shown) */
|
|
180
|
+
types: string[];
|
|
181
|
+
/** Human-readable label for the operator */
|
|
182
|
+
label: string;
|
|
183
|
+
/** Short label for compact display (optional) */
|
|
184
|
+
shortLabel?: string;
|
|
185
|
+
/** Whether to show the value Input */
|
|
186
|
+
needsValue: boolean;
|
|
187
|
+
/** Type to register for narrowing ('never' = no narrowing) */
|
|
188
|
+
narrowsTo: string;
|
|
189
|
+
/** If true, union narrowed type with base type (e.g., narrowed | string) */
|
|
190
|
+
extendsWithBase?: boolean;
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Result of parsing an inferred type string.
|
|
194
|
+
*/
|
|
195
|
+
type ParsedTypes = {
|
|
196
|
+
/** Deduplicated base types (string, number, boolean, any, etc.) */
|
|
197
|
+
baseTypes: string[];
|
|
198
|
+
/** Extracted string literal constants */
|
|
199
|
+
stringConstants: string[];
|
|
200
|
+
/** Extracted number literal constants */
|
|
201
|
+
numberConstants: number[];
|
|
202
|
+
/** Whether any literal constants were found */
|
|
203
|
+
hasConstants: boolean;
|
|
204
|
+
/** Original type strings for union building */
|
|
205
|
+
rawTypes: string[];
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Parse an inferred type string into base types and extract any literal constants.
|
|
209
|
+
*
|
|
210
|
+
* Handles:
|
|
211
|
+
* - Base types: string, number, boolean
|
|
212
|
+
* - Union types: string | number
|
|
213
|
+
* - String literals: "Hans" | "Karl" | "Eddie" | "Theo" | "Fritz" -> treated as string type
|
|
214
|
+
* - Number literals: 1 | 2 | 3 -> treated as number type
|
|
215
|
+
* - Boolean literals: true | false -> treated as boolean type
|
|
216
|
+
*
|
|
217
|
+
* @param typeStr - The inferred type string to parse
|
|
218
|
+
* @returns Parsed type information
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* parseInferredTypes('"Hans" | "Karl" | "Eddie" | "Theo" | "Fritz" | string')
|
|
222
|
+
* // Returns:
|
|
223
|
+
* // {
|
|
224
|
+
* // baseTypes: ['string'],
|
|
225
|
+
* // stringConstants: ['Hans', 'Karl', 'Eddie', 'Theo', 'Fritz'],
|
|
226
|
+
* // numberConstants: [],
|
|
227
|
+
* // hasConstants: true,
|
|
228
|
+
* // rawTypes: ['"Hans"', '"Karl"', '"Eddie"', '"Theo"', '"Fritz"', 'string']
|
|
229
|
+
* // }
|
|
230
|
+
*/
|
|
231
|
+
declare function parseInferredTypes(typeStr: string): ParsedTypes;
|
|
232
|
+
/**
|
|
233
|
+
* Compute the expected type for a value input based on the operator.
|
|
234
|
+
*
|
|
235
|
+
* If `extendsWithBase` is true, the result includes both:
|
|
236
|
+
* - The matching literal types from the inferred type
|
|
237
|
+
* - The base type (to allow arbitrary input)
|
|
238
|
+
*
|
|
239
|
+
* This enables scenarios like:
|
|
240
|
+
* - `string_equals` on `"Hans" | "Karl" | "Eddie" | "Theo" | "Fritz" | string"` → expects `"Hans" | "Karl" | "Eddie" | "Theo" | "Fritz" | string"` (exact match)
|
|
241
|
+
* - `string_starts_with` on `"Hans" | "Karl" | "Eddie" | "Theo" | "Fritz" | string"` → expects `"Hans" | "Karl" | "Eddie" | "Theo" | "Fritz" | string"` (allows partial match)
|
|
242
|
+
*
|
|
243
|
+
* @param inferredType - The inferred type string from the statement
|
|
244
|
+
* @param opDef - The operator definition
|
|
245
|
+
* @returns The computed expected type string
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* const opDef = { narrowsTo: 'string', extendsWithBase: true, ... };
|
|
249
|
+
* computeExtendedType('"Hans" | "Karl" | "Eddie" | "Theo" | "Fritz" | string', opDef);
|
|
250
|
+
* // Returns: '"Hans" | "Karl" | "Eddie" | "Theo" | "Fritz" | string'
|
|
251
|
+
*/
|
|
252
|
+
declare function computeExtendedType<T = never>(inferredType: string, opDef: OperatorDef<T>): string;
|
|
253
|
+
/**
|
|
254
|
+
* Filter operators based on an inferred type.
|
|
255
|
+
* Returns only operators whose `types` include a matching base type.
|
|
256
|
+
*
|
|
257
|
+
* @param operators - Array of operator definitions
|
|
258
|
+
* @param inferredType - The inferred type string to filter by
|
|
259
|
+
* @returns Filtered array of operators
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* const filtered = filterOperatorsByType(OPERATORS, '"Hans" | "Karl" | "Eddie" | "Theo" | "Fritz" | string');
|
|
263
|
+
* // Returns operators with types: ['any'] or types: ['string']
|
|
264
|
+
*/
|
|
265
|
+
declare function filterOperatorsByType<T = never>(operators: OperatorDef<T>[], inferredType: string): OperatorDef<T>[];
|
|
266
|
+
/**
|
|
267
|
+
* Get string constants from an inferred type.
|
|
268
|
+
* Useful for showing constant-based autocomplete options.
|
|
269
|
+
*
|
|
270
|
+
* @param inferredType - The inferred type string
|
|
271
|
+
* @returns Array of string constants
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* getStringConstants('"Hans" | "Karl" | "Eddie" | "Theo" | "Fritz" | string');
|
|
275
|
+
* // Returns: ['Hans', 'Karl', 'Eddie', 'Theo', 'Fritz']
|
|
276
|
+
*/
|
|
277
|
+
declare function getStringConstants(inferredType: string): string[];
|
|
278
|
+
/**
|
|
279
|
+
* Get number constants from an inferred type.
|
|
280
|
+
*
|
|
281
|
+
* @param inferredType - The inferred type string
|
|
282
|
+
* @returns Array of number constants
|
|
283
|
+
*/
|
|
284
|
+
declare function getNumberConstants(inferredType: string): number[];
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Simplified Field Components (Mock/Development Version)
|
|
288
|
+
*
|
|
289
|
+
* These are mock implementations of the simplified field components
|
|
290
|
+
* for use during development and design. In production, these are
|
|
291
|
+
* replaced with the real implementations from packages/ui that include
|
|
292
|
+
* collaboration, type inference, and expression support.
|
|
293
|
+
*
|
|
294
|
+
* ## API
|
|
295
|
+
*
|
|
296
|
+
* The API matches the production components exactly, so developers
|
|
297
|
+
* can build and test their UIs without needing the full infrastructure.
|
|
298
|
+
*
|
|
299
|
+
* ## Example
|
|
300
|
+
*
|
|
301
|
+
* ```tsx
|
|
302
|
+
* import { Input, Select } from '@process.co/ui';
|
|
303
|
+
*
|
|
304
|
+
* function CustomUserForm({ value, onChange }) {
|
|
305
|
+
* return (
|
|
306
|
+
* <div>
|
|
307
|
+
* <Input
|
|
308
|
+
* fieldName="firstName"
|
|
309
|
+
* label="First Name"
|
|
310
|
+
* value={value.firstName}
|
|
311
|
+
* onChange={(v) => onChange({ ...value, firstName: v })}
|
|
312
|
+
* />
|
|
313
|
+
* <Select
|
|
314
|
+
* fieldName="role"
|
|
315
|
+
* label="Role"
|
|
316
|
+
* value={value.role}
|
|
317
|
+
* onChange={(v) => onChange({ ...value, role: v })}
|
|
318
|
+
* options={['admin', 'user', 'guest']}
|
|
319
|
+
* />
|
|
320
|
+
* </div>
|
|
321
|
+
* );
|
|
322
|
+
* }
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Mock context value (always returns defaults).
|
|
328
|
+
* In production, this is replaced with the real context from packages/ui.
|
|
329
|
+
*/
|
|
330
|
+
interface TemplateFieldContextValue {
|
|
331
|
+
yDoc: null;
|
|
332
|
+
collabUser: null;
|
|
333
|
+
awareness: null;
|
|
334
|
+
availableNodes: any;
|
|
335
|
+
myInterface: any;
|
|
336
|
+
typeDeclarations: string;
|
|
337
|
+
element: any;
|
|
338
|
+
nodeId: string;
|
|
339
|
+
onControlFocus: (context: any) => void;
|
|
340
|
+
onControlBlur: () => void;
|
|
341
|
+
onRecordChange: (change: any) => void;
|
|
342
|
+
onValidationChange: (fieldName: string, error: any) => void;
|
|
343
|
+
parentFieldPath: string | null;
|
|
344
|
+
disabled: boolean;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Mock hook - returns empty context values.
|
|
348
|
+
* Components work as basic inputs in development mode.
|
|
349
|
+
*/
|
|
350
|
+
declare function useTemplateFieldContext(): TemplateFieldContextValue;
|
|
351
|
+
/**
|
|
352
|
+
* Mock hook - always returns false in development mode.
|
|
353
|
+
*/
|
|
354
|
+
declare function useIsInTemplateFieldProvider(): boolean;
|
|
355
|
+
/**
|
|
356
|
+
* Mock hook - returns the fieldName as-is (no parent path in dev mode).
|
|
357
|
+
*/
|
|
358
|
+
declare function useFieldPath(fieldName: string): string;
|
|
359
|
+
/**
|
|
360
|
+
* Mock provider - just renders children without context.
|
|
361
|
+
*/
|
|
362
|
+
declare function TemplateFieldProvider({ children }: {
|
|
363
|
+
children: React__default.ReactNode;
|
|
364
|
+
}): React__default.JSX.Element;
|
|
365
|
+
/**
|
|
366
|
+
* Mock provider - just renders children without nesting context.
|
|
367
|
+
*/
|
|
368
|
+
declare function NestedFieldProvider({ children }: {
|
|
369
|
+
children: React__default.ReactNode;
|
|
370
|
+
fieldName: string;
|
|
371
|
+
}): React__default.JSX.Element;
|
|
372
|
+
type TemplateFieldProviderProps = {
|
|
373
|
+
children: React__default.ReactNode;
|
|
374
|
+
nodeId?: string;
|
|
375
|
+
yDoc?: any;
|
|
376
|
+
collabUser?: any;
|
|
377
|
+
awareness?: any;
|
|
378
|
+
availableNodes?: any;
|
|
379
|
+
myInterface?: any;
|
|
380
|
+
typeDeclarations?: string;
|
|
381
|
+
element?: any;
|
|
382
|
+
onControlFocus?: (context: any) => void;
|
|
383
|
+
onControlBlur?: () => void;
|
|
384
|
+
onRecordChange?: (change: any) => void;
|
|
385
|
+
onValidationChange?: (fieldName: string, error: any) => void;
|
|
386
|
+
parentFieldPath?: string | null;
|
|
387
|
+
disabled?: boolean;
|
|
388
|
+
};
|
|
389
|
+
type NestedFieldProviderProps = {
|
|
390
|
+
children: React__default.ReactNode;
|
|
391
|
+
fieldName: string;
|
|
392
|
+
};
|
|
393
|
+
type TemplateFieldValidationError = {
|
|
394
|
+
hasError: boolean;
|
|
395
|
+
hasSyntaxError: boolean;
|
|
396
|
+
hasTypeMismatch: boolean;
|
|
397
|
+
expectedType?: string;
|
|
398
|
+
inferredType?: string;
|
|
399
|
+
errorMessage?: string;
|
|
400
|
+
willCoerce?: boolean;
|
|
401
|
+
};
|
|
402
|
+
type TemplateFieldFocusContext = {
|
|
403
|
+
nodeId: string;
|
|
404
|
+
fieldName: string;
|
|
405
|
+
propertyPath: string;
|
|
406
|
+
label: string;
|
|
407
|
+
expectedType: string;
|
|
408
|
+
currentValue: any;
|
|
409
|
+
isExpression: boolean;
|
|
410
|
+
editorFormat: string;
|
|
411
|
+
inferredType?: string;
|
|
412
|
+
errors?: any;
|
|
413
|
+
selectedNodeId?: string;
|
|
414
|
+
selectedNodeName?: string;
|
|
415
|
+
elementContext?: any;
|
|
416
|
+
userContext?: any;
|
|
417
|
+
propertyDefinition?: any;
|
|
418
|
+
};
|
|
419
|
+
type TemplateFieldChangeEvent = {
|
|
420
|
+
type: 'value_change' | 'mode_switch' | 'format_change' | 'field_focus' | 'panel_open' | 'panel_close';
|
|
421
|
+
details: {
|
|
422
|
+
oldValue?: string;
|
|
423
|
+
newValue?: string;
|
|
424
|
+
oldMode?: string;
|
|
425
|
+
newMode?: string;
|
|
426
|
+
description?: string;
|
|
427
|
+
hasError?: boolean;
|
|
428
|
+
hasTypeMismatch?: boolean;
|
|
429
|
+
willCoerce?: boolean;
|
|
430
|
+
expectedType?: string;
|
|
431
|
+
inferredType?: string;
|
|
432
|
+
};
|
|
433
|
+
};
|
|
434
|
+
/**
|
|
435
|
+
* Context value for sharing inferred types between fields within an element.
|
|
436
|
+
* This enables type propagation via the $infer<...> syntax.
|
|
437
|
+
*
|
|
438
|
+
* ## Usage
|
|
439
|
+
*
|
|
440
|
+
* Publishing field (e.g., switchExpression):
|
|
441
|
+
* - Set expectedType to `$infer<string | number | boolean>`
|
|
442
|
+
* - The field will broadcast its inferred type to the context
|
|
443
|
+
*
|
|
444
|
+
* Subscribing field (e.g., caseExpression):
|
|
445
|
+
* - Set expectedType to `$infer<switchExpression>`
|
|
446
|
+
* - The field will use the inferred type from switchExpression
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* ```tsx
|
|
450
|
+
* // In a custom control that needs to filter operators:
|
|
451
|
+
* const ctx = useInferredTypes();
|
|
452
|
+
* const switchType = ctx?.getInferredType('switchExpression') || 'any';
|
|
453
|
+
* const operators = getOperatorsForType(switchType);
|
|
454
|
+
* ```
|
|
455
|
+
*/
|
|
456
|
+
interface InferredTypesContextValue {
|
|
457
|
+
/** Map of fieldName → inferred type */
|
|
458
|
+
inferredTypes: Record<string, string>;
|
|
459
|
+
/** Set the inferred type for a field (called by publisher fields) */
|
|
460
|
+
setInferredType: (fieldName: string, type: string) => void;
|
|
461
|
+
/** Get the inferred type for a field (called by subscriber fields) */
|
|
462
|
+
getInferredType: (fieldName: string) => string | undefined;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Context for inferred types.
|
|
466
|
+
* In production, this is provided by PropertiesRender.
|
|
467
|
+
*/
|
|
468
|
+
declare const InferredTypesContext: React__default.Context<InferredTypesContextValue | null>;
|
|
469
|
+
/**
|
|
470
|
+
* Hook to access the inferred types context.
|
|
471
|
+
* Returns null when not inside an InferredTypesProvider (e.g., in mock/dev mode).
|
|
472
|
+
*
|
|
473
|
+
* @example
|
|
474
|
+
* ```tsx
|
|
475
|
+
* const ctx = useInferredTypes();
|
|
476
|
+
* const switchType = ctx?.getInferredType('switchExpression') || 'string';
|
|
477
|
+
* ```
|
|
478
|
+
*/
|
|
479
|
+
declare function useInferredTypes(): InferredTypesContextValue | null;
|
|
480
|
+
/**
|
|
481
|
+
* Props for InferredTypesProvider
|
|
482
|
+
*/
|
|
483
|
+
interface InferredTypesProviderProps {
|
|
484
|
+
children: React__default.ReactNode;
|
|
485
|
+
/**
|
|
486
|
+
* Optional Yjs document for collaborative sync (ignored in mock mode).
|
|
487
|
+
* When provided in production, inferred types are synced via Yjs.
|
|
488
|
+
*/
|
|
489
|
+
yDoc?: unknown;
|
|
490
|
+
/**
|
|
491
|
+
* Optional key prefix for the Yjs map (ignored in mock mode).
|
|
492
|
+
*/
|
|
493
|
+
mapKey?: string;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Mock provider for inferred types context.
|
|
497
|
+
* In development mode, this is a no-op - just renders children.
|
|
498
|
+
* In production, the real implementation from @repo/ui provides actual type propagation.
|
|
499
|
+
*/
|
|
500
|
+
declare function InferredTypesProvider({ children }: InferredTypesProviderProps): React__default.JSX.Element;
|
|
501
|
+
/**
|
|
502
|
+
* Compute the intersection of multiple types.
|
|
503
|
+
* Used when subscribing to multiple fields to narrow the expected type.
|
|
504
|
+
*
|
|
505
|
+
* @example
|
|
506
|
+
* intersectTypes(['string | number', 'number']) → 'number'
|
|
507
|
+
*/
|
|
508
|
+
declare function intersectTypes(types: (string | undefined)[]): string;
|
|
509
|
+
/**
|
|
510
|
+
* Configuration parsed from the $infer<...> syntax.
|
|
511
|
+
*/
|
|
512
|
+
interface InferConfig {
|
|
513
|
+
/** The mode of the field: 'publish', 'subscribe', or 'normal' */
|
|
514
|
+
mode: 'publish' | 'subscribe' | 'normal';
|
|
515
|
+
/** For publish mode: the allowed types (e.g., ['string', 'number', 'boolean']) */
|
|
516
|
+
allowedTypes?: string[];
|
|
517
|
+
/** For subscribe mode: the field name to subscribe to */
|
|
518
|
+
subscribeToField?: string;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Parse the $infer<...> syntax from an expectedType string.
|
|
522
|
+
*
|
|
523
|
+
* @example
|
|
524
|
+
* ```tsx
|
|
525
|
+
* parseInferSyntax('$infer<string | number>')
|
|
526
|
+
* // → { mode: 'publish', allowedTypes: ['string', 'number'] }
|
|
527
|
+
*
|
|
528
|
+
* parseInferSyntax('$infer<switchExpression>')
|
|
529
|
+
* // → { mode: 'subscribe', subscribeToField: 'switchExpression' }
|
|
530
|
+
*
|
|
531
|
+
* parseInferSyntax('string')
|
|
532
|
+
* // → { mode: 'normal' }
|
|
533
|
+
* ```
|
|
534
|
+
*/
|
|
535
|
+
declare function parseInferSyntax(expectedType: string | undefined): InferConfig;
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Standard operators grouped by compatible types.
|
|
539
|
+
* Use getOperatorsForType() to retrieve operators for a specific type.
|
|
540
|
+
*
|
|
541
|
+
* @deprecated Use OperatorDef<T> and filterOperatorsByType() for more flexibility
|
|
542
|
+
*/
|
|
543
|
+
declare const OPERATORS_BY_TYPE: Record<string, Array<{
|
|
544
|
+
value: string;
|
|
545
|
+
label: string;
|
|
546
|
+
}>>;
|
|
547
|
+
/**
|
|
548
|
+
* Get the appropriate operators for a given type.
|
|
549
|
+
* Falls back to 'any' operators for unrecognized types.
|
|
550
|
+
*
|
|
551
|
+
* @deprecated Use OperatorDef<T> and filterOperatorsByType() for more flexibility
|
|
552
|
+
*
|
|
553
|
+
* @example
|
|
554
|
+
* ```tsx
|
|
555
|
+
* const ctx = useInferredTypes();
|
|
556
|
+
* const switchType = ctx?.getInferredType('switchExpression') || 'any';
|
|
557
|
+
* const operators = getOperatorsForType(switchType);
|
|
558
|
+
* // If switchType is 'number', returns numeric operators including <, >, etc.
|
|
559
|
+
* ```
|
|
560
|
+
*/
|
|
561
|
+
declare function getOperatorsForType(type: string): Array<{
|
|
562
|
+
value: string;
|
|
563
|
+
label: string;
|
|
564
|
+
}>;
|
|
565
|
+
/**
|
|
566
|
+
* Props for NodePropertyProvider
|
|
567
|
+
*/
|
|
568
|
+
interface NodePropertyProviderProps {
|
|
569
|
+
children: React__default.ReactNode;
|
|
570
|
+
/** The node ID this provider manages */
|
|
571
|
+
nodeId: string;
|
|
572
|
+
/** Yjs document for collaborative sync (ignored in mock mode) */
|
|
573
|
+
yDoc?: unknown;
|
|
574
|
+
/** Initial property data from the node */
|
|
575
|
+
initialData?: Record<string, any>;
|
|
576
|
+
/** Callback when a single property changes */
|
|
577
|
+
onPropertyChange?: (key: string, value: any, metadata?: any) => void;
|
|
578
|
+
/** Callback when multiple properties change */
|
|
579
|
+
onPropertiesChange?: (updates: Record<string, any>, metadata?: Record<string, any>) => void;
|
|
580
|
+
/** Client ID for conflict resolution */
|
|
581
|
+
clientId?: string;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Mock provider for node properties.
|
|
585
|
+
* In development mode, this is a no-op - just renders children.
|
|
586
|
+
* In production, the real implementation from @repo/ui provides actual store.
|
|
587
|
+
*/
|
|
588
|
+
declare function NodePropertyProvider({ children }: NodePropertyProviderProps): React__default.ReactElement;
|
|
589
|
+
/**
|
|
590
|
+
* Mock hook - always returns false in development mode.
|
|
591
|
+
* In production, returns true when inside a NodePropertyProvider.
|
|
592
|
+
*/
|
|
593
|
+
declare function useIsInNodePropertyProvider(): boolean;
|
|
594
|
+
/**
|
|
595
|
+
* Mock hook - returns [undefined, no-op] in development mode.
|
|
596
|
+
* In production, subscribes to a single property from the store.
|
|
597
|
+
*
|
|
598
|
+
* @example
|
|
599
|
+
* ```tsx
|
|
600
|
+
* const [operator, setOperator] = useNodeProperty<string>('operator');
|
|
601
|
+
* // In mock mode: operator is undefined, setOperator is a no-op
|
|
602
|
+
* ```
|
|
603
|
+
*/
|
|
604
|
+
declare function useNodeProperty<T = any>(key: string): [T | undefined, (value: T, metadata?: any) => void];
|
|
605
|
+
/**
|
|
606
|
+
* Mock hook - returns [{}, no-op] in development mode.
|
|
607
|
+
* In production, subscribes to all properties from the store.
|
|
608
|
+
*/
|
|
609
|
+
declare function useNodeProperties(): [
|
|
610
|
+
Record<string, any>,
|
|
611
|
+
(updates: Record<string, any>, metadata?: Record<string, any>) => void
|
|
612
|
+
];
|
|
613
|
+
/**
|
|
614
|
+
* Mock hook - returns undefined in development mode.
|
|
615
|
+
* In production, subscribes to an inferred type by field name.
|
|
616
|
+
*/
|
|
617
|
+
declare function useInferredType(fieldName: string): string | undefined;
|
|
618
|
+
/**
|
|
619
|
+
* Mock hook - returns no-op in development mode.
|
|
620
|
+
* In production, returns a setter for inferred types.
|
|
621
|
+
*/
|
|
622
|
+
declare function useSetInferredType(): (fieldName: string, type: string) => void;
|
|
623
|
+
/**
|
|
624
|
+
* Mock hook - returns {} in development mode.
|
|
625
|
+
* In production, subscribes to all inferred types.
|
|
626
|
+
*/
|
|
627
|
+
declare function useAllInferredTypes(): Record<string, string>;
|
|
628
|
+
/**
|
|
629
|
+
* Mock hook - returns no-op in development mode.
|
|
630
|
+
* In production, returns a setter for individual properties.
|
|
631
|
+
*/
|
|
632
|
+
declare function useSetProperty(): <T = any>(key: string, value: T, metadata?: any) => void;
|
|
633
|
+
/**
|
|
634
|
+
* Validation rule for a field.
|
|
635
|
+
*/
|
|
636
|
+
interface FieldValidationRule {
|
|
637
|
+
required?: boolean;
|
|
638
|
+
requiredIf?: (properties: Record<string, any>) => boolean;
|
|
639
|
+
customValidation?: (value: any, properties: Record<string, any>) => string | null;
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Mock hook - returns no-ops in development mode.
|
|
643
|
+
* In production, allows custom controls to set validation rules.
|
|
644
|
+
*
|
|
645
|
+
* @example
|
|
646
|
+
* ```tsx
|
|
647
|
+
* const { setFieldRequired, setFieldRequiredIf } = useFieldValidation();
|
|
648
|
+
* setFieldRequired('expression', true);
|
|
649
|
+
* setFieldRequiredIf('expression', (props) => props.operator?.needsValue);
|
|
650
|
+
* ```
|
|
651
|
+
*/
|
|
652
|
+
declare function useFieldValidation(): {
|
|
653
|
+
setFieldRequired: (fieldName: string, required: boolean) => void;
|
|
654
|
+
setFieldRequiredIf: (fieldName: string, requiredIf: (properties: Record<string, any>) => boolean) => void;
|
|
655
|
+
setFieldValidation: (fieldName: string, customValidation: (value: any, properties: Record<string, any>) => string | null) => void;
|
|
656
|
+
clearFieldValidation: (fieldName: string) => void;
|
|
657
|
+
isFieldRequired: (fieldName: string) => boolean;
|
|
658
|
+
validateField: (fieldName: string) => string | null;
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
type index_BaseOperatorType = BaseOperatorType;
|
|
662
|
+
type index_FieldValidationRule = FieldValidationRule;
|
|
663
|
+
type index_InferConfig = InferConfig;
|
|
664
|
+
declare const index_InferredTypesContext: typeof InferredTypesContext;
|
|
665
|
+
type index_InferredTypesContextValue = InferredTypesContextValue;
|
|
666
|
+
declare const index_InferredTypesProvider: typeof InferredTypesProvider;
|
|
667
|
+
type index_InferredTypesProviderProps = InferredTypesProviderProps;
|
|
668
|
+
declare const index_Input: typeof Input;
|
|
669
|
+
type index_InputProps = InputProps;
|
|
670
|
+
declare const index_NestedFieldProvider: typeof NestedFieldProvider;
|
|
671
|
+
type index_NestedFieldProviderProps = NestedFieldProviderProps;
|
|
672
|
+
declare const index_NodePropertyProvider: typeof NodePropertyProvider;
|
|
673
|
+
type index_NodePropertyProviderProps = NodePropertyProviderProps;
|
|
674
|
+
declare const index_OPERATORS_BY_TYPE: typeof OPERATORS_BY_TYPE;
|
|
675
|
+
type index_OperatorDef<T = never> = OperatorDef<T>;
|
|
676
|
+
type index_ParsedTypes = ParsedTypes;
|
|
677
|
+
declare const index_Select: typeof Select;
|
|
678
|
+
type index_SelectOption = SelectOption;
|
|
679
|
+
type index_SelectProps = SelectProps;
|
|
680
|
+
type index_SelectRenderProps = SelectRenderProps;
|
|
681
|
+
type index_TemplateFieldChangeEvent = TemplateFieldChangeEvent;
|
|
682
|
+
type index_TemplateFieldContextValue = TemplateFieldContextValue;
|
|
683
|
+
type index_TemplateFieldFocusContext = TemplateFieldFocusContext;
|
|
684
|
+
declare const index_TemplateFieldProvider: typeof TemplateFieldProvider;
|
|
685
|
+
type index_TemplateFieldProviderProps = TemplateFieldProviderProps;
|
|
686
|
+
type index_TemplateFieldValidationError = TemplateFieldValidationError;
|
|
687
|
+
declare const index_computeExtendedType: typeof computeExtendedType;
|
|
688
|
+
declare const index_filterOperatorsByType: typeof filterOperatorsByType;
|
|
689
|
+
declare const index_getNumberConstants: typeof getNumberConstants;
|
|
690
|
+
declare const index_getOperatorsForType: typeof getOperatorsForType;
|
|
691
|
+
declare const index_getStringConstants: typeof getStringConstants;
|
|
692
|
+
declare const index_intersectTypes: typeof intersectTypes;
|
|
693
|
+
declare const index_parseInferSyntax: typeof parseInferSyntax;
|
|
694
|
+
declare const index_parseInferredTypes: typeof parseInferredTypes;
|
|
695
|
+
declare const index_useAllInferredTypes: typeof useAllInferredTypes;
|
|
696
|
+
declare const index_useFieldPath: typeof useFieldPath;
|
|
697
|
+
declare const index_useFieldValidation: typeof useFieldValidation;
|
|
698
|
+
declare const index_useInferredType: typeof useInferredType;
|
|
699
|
+
declare const index_useInferredTypes: typeof useInferredTypes;
|
|
700
|
+
declare const index_useIsInNodePropertyProvider: typeof useIsInNodePropertyProvider;
|
|
701
|
+
declare const index_useIsInTemplateFieldProvider: typeof useIsInTemplateFieldProvider;
|
|
702
|
+
declare const index_useNodeProperties: typeof useNodeProperties;
|
|
703
|
+
declare const index_useNodeProperty: typeof useNodeProperty;
|
|
704
|
+
declare const index_useSetInferredType: typeof useSetInferredType;
|
|
705
|
+
declare const index_useSetProperty: typeof useSetProperty;
|
|
706
|
+
declare const index_useTemplateFieldContext: typeof useTemplateFieldContext;
|
|
707
|
+
declare namespace index {
|
|
708
|
+
export { type index_BaseOperatorType as BaseOperatorType, type index_FieldValidationRule as FieldValidationRule, type index_InferConfig as InferConfig, index_InferredTypesContext as InferredTypesContext, type index_InferredTypesContextValue as InferredTypesContextValue, index_InferredTypesProvider as InferredTypesProvider, type index_InferredTypesProviderProps as InferredTypesProviderProps, index_Input as Input, type index_InputProps as InputProps, index_NestedFieldProvider as NestedFieldProvider, type index_NestedFieldProviderProps as NestedFieldProviderProps, index_NodePropertyProvider as NodePropertyProvider, type index_NodePropertyProviderProps as NodePropertyProviderProps, index_OPERATORS_BY_TYPE as OPERATORS_BY_TYPE, type index_OperatorDef as OperatorDef, type index_ParsedTypes as ParsedTypes, index_Select as Select, type index_SelectOption as SelectOption, type index_SelectProps as SelectProps, type index_SelectRenderProps as SelectRenderProps, type index_TemplateFieldChangeEvent as TemplateFieldChangeEvent, type index_TemplateFieldContextValue as TemplateFieldContextValue, type index_TemplateFieldFocusContext as TemplateFieldFocusContext, index_TemplateFieldProvider as TemplateFieldProvider, type index_TemplateFieldProviderProps as TemplateFieldProviderProps, type index_TemplateFieldValidationError as TemplateFieldValidationError, index_computeExtendedType as computeExtendedType, index_filterOperatorsByType as filterOperatorsByType, index_getNumberConstants as getNumberConstants, index_getOperatorsForType as getOperatorsForType, index_getStringConstants as getStringConstants, index_intersectTypes as intersectTypes, index_parseInferSyntax as parseInferSyntax, index_parseInferredTypes as parseInferredTypes, index_useAllInferredTypes as useAllInferredTypes, index_useFieldPath as useFieldPath, index_useFieldValidation as useFieldValidation, index_useInferredType as useInferredType, index_useInferredTypes as useInferredTypes, index_useIsInNodePropertyProvider as useIsInNodePropertyProvider, index_useIsInTemplateFieldProvider as useIsInTemplateFieldProvider, index_useNodeProperties as useNodeProperties, index_useNodeProperty as useNodeProperty, index_useSetInferredType as useSetInferredType, index_useSetProperty as useSetProperty, index_useTemplateFieldContext as useTemplateFieldContext };
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
export { useSetProperty as A, useFieldValidation as B, Input as C, type InputProps as D, type SelectProps as E, type FieldValidationRule as F, type SelectOption as G, type SelectRenderProps as H, type InferredTypesContextValue as I, parseInferredTypes as J, computeExtendedType as K, filterOperatorsByType as L, getStringConstants as M, NestedFieldProvider as N, OPERATORS_BY_TYPE as O, getNumberConstants as P, type BaseOperatorType as Q, type OperatorDef as R, Select as S, type TemplateFieldContextValue as T, type ParsedTypes as U, useIsInTemplateFieldProvider as a, useFieldPath as b, TemplateFieldProvider as c, type TemplateFieldProviderProps as d, type NestedFieldProviderProps as e, type TemplateFieldValidationError as f, type TemplateFieldFocusContext as g, type TemplateFieldChangeEvent as h, index as i, InferredTypesContext as j, useInferredTypes as k, type InferredTypesProviderProps as l, InferredTypesProvider as m, intersectTypes as n, type InferConfig as o, parseInferSyntax as p, getOperatorsForType as q, type NodePropertyProviderProps as r, NodePropertyProvider as s, useIsInNodePropertyProvider as t, useTemplateFieldContext as u, useNodeProperty as v, useNodeProperties as w, useInferredType as x, useSetInferredType as y, useAllInferredTypes as z };
|