@process.co/ui 0.0.6 → 0.0.7

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.
@@ -255,11 +255,112 @@ type TemplateFieldChangeEvent = {
255
255
  inferredType?: string;
256
256
  };
257
257
  };
258
+ /**
259
+ * Context value for sharing inferred types between fields within an element.
260
+ * This enables type propagation via the $infer<...> syntax.
261
+ *
262
+ * ## Usage
263
+ *
264
+ * Publishing field (e.g., switchExpression):
265
+ * - Set expectedType to `$infer<string | number | boolean>`
266
+ * - The field will broadcast its inferred type to the context
267
+ *
268
+ * Subscribing field (e.g., caseExpression):
269
+ * - Set expectedType to `$infer<switchExpression>`
270
+ * - The field will use the inferred type from switchExpression
271
+ *
272
+ * @example
273
+ * ```tsx
274
+ * // In a custom control that needs to filter operators:
275
+ * const ctx = useInferredTypes();
276
+ * const switchType = ctx?.getInferredType('switchExpression') || 'any';
277
+ * const operators = getOperatorsForType(switchType);
278
+ * ```
279
+ */
280
+ interface InferredTypesContextValue {
281
+ /** Map of fieldName → inferred type */
282
+ inferredTypes: Record<string, string>;
283
+ /** Set the inferred type for a field (called by publisher fields) */
284
+ setInferredType: (fieldName: string, type: string) => void;
285
+ /** Get the inferred type for a field (called by subscriber fields) */
286
+ getInferredType: (fieldName: string) => string | undefined;
287
+ }
288
+ /**
289
+ * Context for inferred types.
290
+ * In production, this is provided by PropertiesRender.
291
+ */
292
+ declare const InferredTypesContext: React$1.Context<InferredTypesContextValue | null>;
293
+ /**
294
+ * Hook to access the inferred types context.
295
+ * Returns null when not inside an InferredTypesProvider (e.g., in mock/dev mode).
296
+ *
297
+ * @example
298
+ * ```tsx
299
+ * const ctx = useInferredTypes();
300
+ * const switchType = ctx?.getInferredType('switchExpression') || 'string';
301
+ * ```
302
+ */
303
+ declare function useInferredTypes(): InferredTypesContextValue | null;
304
+ /**
305
+ * Configuration parsed from the $infer<...> syntax.
306
+ */
307
+ interface InferConfig {
308
+ /** The mode of the field: 'publish', 'subscribe', or 'normal' */
309
+ mode: 'publish' | 'subscribe' | 'normal';
310
+ /** For publish mode: the allowed types (e.g., ['string', 'number', 'boolean']) */
311
+ allowedTypes?: string[];
312
+ /** For subscribe mode: the field name to subscribe to */
313
+ subscribeToField?: string;
314
+ }
315
+ /**
316
+ * Parse the $infer<...> syntax from an expectedType string.
317
+ *
318
+ * @example
319
+ * ```tsx
320
+ * parseInferSyntax('$infer<string | number>')
321
+ * // → { mode: 'publish', allowedTypes: ['string', 'number'] }
322
+ *
323
+ * parseInferSyntax('$infer<switchExpression>')
324
+ * // → { mode: 'subscribe', subscribeToField: 'switchExpression' }
325
+ *
326
+ * parseInferSyntax('string')
327
+ * // → { mode: 'normal' }
328
+ * ```
329
+ */
330
+ declare function parseInferSyntax(expectedType: string | undefined): InferConfig;
331
+ /**
332
+ * Standard operators grouped by compatible types.
333
+ * Use getOperatorsForType() to retrieve operators for a specific type.
334
+ */
335
+ declare const OPERATORS_BY_TYPE: Record<string, Array<{
336
+ value: string;
337
+ label: string;
338
+ }>>;
339
+ /**
340
+ * Get the appropriate operators for a given type.
341
+ * Falls back to 'any' operators for unrecognized types.
342
+ *
343
+ * @example
344
+ * ```tsx
345
+ * const ctx = useInferredTypes();
346
+ * const switchType = ctx?.getInferredType('switchExpression') || 'any';
347
+ * const operators = getOperatorsForType(switchType);
348
+ * // If switchType is 'number', returns numeric operators including <, >, etc.
349
+ * ```
350
+ */
351
+ declare function getOperatorsForType(type: string): Array<{
352
+ value: string;
353
+ label: string;
354
+ }>;
258
355
 
356
+ type index_InferConfig = InferConfig;
357
+ declare const index_InferredTypesContext: typeof InferredTypesContext;
358
+ type index_InferredTypesContextValue = InferredTypesContextValue;
259
359
  declare const index_Input: typeof Input;
260
360
  type index_InputProps = InputProps;
261
361
  declare const index_NestedFieldProvider: typeof NestedFieldProvider;
262
362
  type index_NestedFieldProviderProps = NestedFieldProviderProps;
363
+ declare const index_OPERATORS_BY_TYPE: typeof OPERATORS_BY_TYPE;
263
364
  declare const index_Select: typeof Select;
264
365
  type index_SelectOption = SelectOption;
265
366
  type index_SelectProps = SelectProps;
@@ -270,11 +371,14 @@ type index_TemplateFieldFocusContext = TemplateFieldFocusContext;
270
371
  declare const index_TemplateFieldProvider: typeof TemplateFieldProvider;
271
372
  type index_TemplateFieldProviderProps = TemplateFieldProviderProps;
272
373
  type index_TemplateFieldValidationError = TemplateFieldValidationError;
374
+ declare const index_getOperatorsForType: typeof getOperatorsForType;
375
+ declare const index_parseInferSyntax: typeof parseInferSyntax;
273
376
  declare const index_useFieldPath: typeof useFieldPath;
377
+ declare const index_useInferredTypes: typeof useInferredTypes;
274
378
  declare const index_useIsInTemplateFieldProvider: typeof useIsInTemplateFieldProvider;
275
379
  declare const index_useTemplateFieldContext: typeof useTemplateFieldContext;
276
380
  declare namespace index {
277
- export { index_Input as Input, type index_InputProps as InputProps, index_NestedFieldProvider as NestedFieldProvider, type index_NestedFieldProviderProps as NestedFieldProviderProps, 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_useFieldPath as useFieldPath, index_useIsInTemplateFieldProvider as useIsInTemplateFieldProvider, index_useTemplateFieldContext as useTemplateFieldContext };
381
+ export { type index_InferConfig as InferConfig, index_InferredTypesContext as InferredTypesContext, type index_InferredTypesContextValue as InferredTypesContextValue, index_Input as Input, type index_InputProps as InputProps, index_NestedFieldProvider as NestedFieldProvider, type index_NestedFieldProviderProps as NestedFieldProviderProps, index_OPERATORS_BY_TYPE as OPERATORS_BY_TYPE, 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_getOperatorsForType as getOperatorsForType, index_parseInferSyntax as parseInferSyntax, index_useFieldPath as useFieldPath, index_useInferredTypes as useInferredTypes, index_useIsInTemplateFieldProvider as useIsInTemplateFieldProvider, index_useTemplateFieldContext as useTemplateFieldContext };
278
382
  }
279
383
 
280
- export { Input as I, NestedFieldProvider as N, Select as S, type TemplateFieldContextValue as T, 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, type InputProps as j, type SelectProps as k, type SelectOption as l, type SelectRenderProps as m, useTemplateFieldContext as u };
384
+ export { type InferredTypesContextValue as I, NestedFieldProvider as N, OPERATORS_BY_TYPE as O, Select as S, type TemplateFieldContextValue as T, 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 InferConfig as l, getOperatorsForType as m, Input as n, type InputProps as o, parseInferSyntax as p, type SelectProps as q, type SelectOption as r, type SelectRenderProps as s, useTemplateFieldContext as u };
@@ -255,11 +255,112 @@ type TemplateFieldChangeEvent = {
255
255
  inferredType?: string;
256
256
  };
257
257
  };
258
+ /**
259
+ * Context value for sharing inferred types between fields within an element.
260
+ * This enables type propagation via the $infer<...> syntax.
261
+ *
262
+ * ## Usage
263
+ *
264
+ * Publishing field (e.g., switchExpression):
265
+ * - Set expectedType to `$infer<string | number | boolean>`
266
+ * - The field will broadcast its inferred type to the context
267
+ *
268
+ * Subscribing field (e.g., caseExpression):
269
+ * - Set expectedType to `$infer<switchExpression>`
270
+ * - The field will use the inferred type from switchExpression
271
+ *
272
+ * @example
273
+ * ```tsx
274
+ * // In a custom control that needs to filter operators:
275
+ * const ctx = useInferredTypes();
276
+ * const switchType = ctx?.getInferredType('switchExpression') || 'any';
277
+ * const operators = getOperatorsForType(switchType);
278
+ * ```
279
+ */
280
+ interface InferredTypesContextValue {
281
+ /** Map of fieldName → inferred type */
282
+ inferredTypes: Record<string, string>;
283
+ /** Set the inferred type for a field (called by publisher fields) */
284
+ setInferredType: (fieldName: string, type: string) => void;
285
+ /** Get the inferred type for a field (called by subscriber fields) */
286
+ getInferredType: (fieldName: string) => string | undefined;
287
+ }
288
+ /**
289
+ * Context for inferred types.
290
+ * In production, this is provided by PropertiesRender.
291
+ */
292
+ declare const InferredTypesContext: React$1.Context<InferredTypesContextValue | null>;
293
+ /**
294
+ * Hook to access the inferred types context.
295
+ * Returns null when not inside an InferredTypesProvider (e.g., in mock/dev mode).
296
+ *
297
+ * @example
298
+ * ```tsx
299
+ * const ctx = useInferredTypes();
300
+ * const switchType = ctx?.getInferredType('switchExpression') || 'string';
301
+ * ```
302
+ */
303
+ declare function useInferredTypes(): InferredTypesContextValue | null;
304
+ /**
305
+ * Configuration parsed from the $infer<...> syntax.
306
+ */
307
+ interface InferConfig {
308
+ /** The mode of the field: 'publish', 'subscribe', or 'normal' */
309
+ mode: 'publish' | 'subscribe' | 'normal';
310
+ /** For publish mode: the allowed types (e.g., ['string', 'number', 'boolean']) */
311
+ allowedTypes?: string[];
312
+ /** For subscribe mode: the field name to subscribe to */
313
+ subscribeToField?: string;
314
+ }
315
+ /**
316
+ * Parse the $infer<...> syntax from an expectedType string.
317
+ *
318
+ * @example
319
+ * ```tsx
320
+ * parseInferSyntax('$infer<string | number>')
321
+ * // → { mode: 'publish', allowedTypes: ['string', 'number'] }
322
+ *
323
+ * parseInferSyntax('$infer<switchExpression>')
324
+ * // → { mode: 'subscribe', subscribeToField: 'switchExpression' }
325
+ *
326
+ * parseInferSyntax('string')
327
+ * // → { mode: 'normal' }
328
+ * ```
329
+ */
330
+ declare function parseInferSyntax(expectedType: string | undefined): InferConfig;
331
+ /**
332
+ * Standard operators grouped by compatible types.
333
+ * Use getOperatorsForType() to retrieve operators for a specific type.
334
+ */
335
+ declare const OPERATORS_BY_TYPE: Record<string, Array<{
336
+ value: string;
337
+ label: string;
338
+ }>>;
339
+ /**
340
+ * Get the appropriate operators for a given type.
341
+ * Falls back to 'any' operators for unrecognized types.
342
+ *
343
+ * @example
344
+ * ```tsx
345
+ * const ctx = useInferredTypes();
346
+ * const switchType = ctx?.getInferredType('switchExpression') || 'any';
347
+ * const operators = getOperatorsForType(switchType);
348
+ * // If switchType is 'number', returns numeric operators including <, >, etc.
349
+ * ```
350
+ */
351
+ declare function getOperatorsForType(type: string): Array<{
352
+ value: string;
353
+ label: string;
354
+ }>;
258
355
 
356
+ type index_InferConfig = InferConfig;
357
+ declare const index_InferredTypesContext: typeof InferredTypesContext;
358
+ type index_InferredTypesContextValue = InferredTypesContextValue;
259
359
  declare const index_Input: typeof Input;
260
360
  type index_InputProps = InputProps;
261
361
  declare const index_NestedFieldProvider: typeof NestedFieldProvider;
262
362
  type index_NestedFieldProviderProps = NestedFieldProviderProps;
363
+ declare const index_OPERATORS_BY_TYPE: typeof OPERATORS_BY_TYPE;
263
364
  declare const index_Select: typeof Select;
264
365
  type index_SelectOption = SelectOption;
265
366
  type index_SelectProps = SelectProps;
@@ -270,11 +371,14 @@ type index_TemplateFieldFocusContext = TemplateFieldFocusContext;
270
371
  declare const index_TemplateFieldProvider: typeof TemplateFieldProvider;
271
372
  type index_TemplateFieldProviderProps = TemplateFieldProviderProps;
272
373
  type index_TemplateFieldValidationError = TemplateFieldValidationError;
374
+ declare const index_getOperatorsForType: typeof getOperatorsForType;
375
+ declare const index_parseInferSyntax: typeof parseInferSyntax;
273
376
  declare const index_useFieldPath: typeof useFieldPath;
377
+ declare const index_useInferredTypes: typeof useInferredTypes;
274
378
  declare const index_useIsInTemplateFieldProvider: typeof useIsInTemplateFieldProvider;
275
379
  declare const index_useTemplateFieldContext: typeof useTemplateFieldContext;
276
380
  declare namespace index {
277
- export { index_Input as Input, type index_InputProps as InputProps, index_NestedFieldProvider as NestedFieldProvider, type index_NestedFieldProviderProps as NestedFieldProviderProps, 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_useFieldPath as useFieldPath, index_useIsInTemplateFieldProvider as useIsInTemplateFieldProvider, index_useTemplateFieldContext as useTemplateFieldContext };
381
+ export { type index_InferConfig as InferConfig, index_InferredTypesContext as InferredTypesContext, type index_InferredTypesContextValue as InferredTypesContextValue, index_Input as Input, type index_InputProps as InputProps, index_NestedFieldProvider as NestedFieldProvider, type index_NestedFieldProviderProps as NestedFieldProviderProps, index_OPERATORS_BY_TYPE as OPERATORS_BY_TYPE, 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_getOperatorsForType as getOperatorsForType, index_parseInferSyntax as parseInferSyntax, index_useFieldPath as useFieldPath, index_useInferredTypes as useInferredTypes, index_useIsInTemplateFieldProvider as useIsInTemplateFieldProvider, index_useTemplateFieldContext as useTemplateFieldContext };
278
382
  }
279
383
 
280
- export { Input as I, NestedFieldProvider as N, Select as S, type TemplateFieldContextValue as T, 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, type InputProps as j, type SelectProps as k, type SelectOption as l, type SelectRenderProps as m, useTemplateFieldContext as u };
384
+ export { type InferredTypesContextValue as I, NestedFieldProvider as N, OPERATORS_BY_TYPE as O, Select as S, type TemplateFieldContextValue as T, 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 InferConfig as l, getOperatorsForType as m, Input as n, type InputProps as o, parseInferSyntax as p, type SelectProps as q, type SelectOption as r, type SelectRenderProps as s, useTemplateFieldContext as u };
package/dist/index.cjs CHANGED
@@ -4875,21 +4875,36 @@ function Button(_param) {
4875
4875
  // src/components/fields/index.tsx
4876
4876
  var fields_exports = {};
4877
4877
  __export(fields_exports, {
4878
+ InferredTypesContext: function() {
4879
+ return InferredTypesContext;
4880
+ },
4878
4881
  Input: function() {
4879
4882
  return Input;
4880
4883
  },
4881
4884
  NestedFieldProvider: function() {
4882
4885
  return NestedFieldProvider;
4883
4886
  },
4887
+ OPERATORS_BY_TYPE: function() {
4888
+ return OPERATORS_BY_TYPE;
4889
+ },
4884
4890
  Select: function() {
4885
4891
  return Select;
4886
4892
  },
4887
4893
  TemplateFieldProvider: function() {
4888
4894
  return TemplateFieldProvider;
4889
4895
  },
4896
+ getOperatorsForType: function() {
4897
+ return getOperatorsForType;
4898
+ },
4899
+ parseInferSyntax: function() {
4900
+ return parseInferSyntax;
4901
+ },
4890
4902
  useFieldPath: function() {
4891
4903
  return useFieldPath;
4892
4904
  },
4905
+ useInferredTypes: function() {
4906
+ return useInferredTypes;
4907
+ },
4893
4908
  useIsInTemplateFieldProvider: function() {
4894
4909
  return useIsInTemplateFieldProvider;
4895
4910
  },
@@ -5126,6 +5141,121 @@ function NestedFieldProvider(param) {
5126
5141
  var children = param.children;
5127
5142
  return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
5128
5143
  }
5144
+ var InferredTypesContext = React4.createContext(null);
5145
+ function useInferredTypes() {
5146
+ return React4.useContext(InferredTypesContext);
5147
+ }
5148
+ function parseInferSyntax(expectedType) {
5149
+ var _match_;
5150
+ if (!expectedType || !expectedType.startsWith("$infer<")) {
5151
+ return {
5152
+ mode: "normal"
5153
+ };
5154
+ }
5155
+ var match = expectedType.match(/^\$infer<(.+)>$/);
5156
+ if (!match) {
5157
+ return {
5158
+ mode: "normal"
5159
+ };
5160
+ }
5161
+ var content = ((_match_ = match[1]) === null || _match_ === void 0 ? void 0 : _match_.trim()) || "";
5162
+ if (!content.includes("|") && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(content)) {
5163
+ return {
5164
+ mode: "subscribe",
5165
+ subscribeToField: content
5166
+ };
5167
+ }
5168
+ var allowedTypes = content.split("|").map(function(t) {
5169
+ return t.trim();
5170
+ }).filter(Boolean);
5171
+ return {
5172
+ mode: "publish",
5173
+ allowedTypes: allowedTypes
5174
+ };
5175
+ }
5176
+ var OPERATORS_BY_TYPE = {
5177
+ string: [
5178
+ {
5179
+ value: "==",
5180
+ label: "equals (==)"
5181
+ },
5182
+ {
5183
+ value: "!=",
5184
+ label: "not equals (!=)"
5185
+ },
5186
+ {
5187
+ value: "contains",
5188
+ label: "contains"
5189
+ },
5190
+ {
5191
+ value: "startsWith",
5192
+ label: "starts with"
5193
+ },
5194
+ {
5195
+ value: "endsWith",
5196
+ label: "ends with"
5197
+ }
5198
+ ],
5199
+ number: [
5200
+ {
5201
+ value: "==",
5202
+ label: "equals (==)"
5203
+ },
5204
+ {
5205
+ value: "!=",
5206
+ label: "not equals (!=)"
5207
+ },
5208
+ {
5209
+ value: "<",
5210
+ label: "less than (<)"
5211
+ },
5212
+ {
5213
+ value: ">",
5214
+ label: "greater than (>)"
5215
+ },
5216
+ {
5217
+ value: "<=",
5218
+ label: "less than or equal (<=)"
5219
+ },
5220
+ {
5221
+ value: ">=",
5222
+ label: "greater than or equal (>=)"
5223
+ }
5224
+ ],
5225
+ boolean: [
5226
+ {
5227
+ value: "==",
5228
+ label: "equals (==)"
5229
+ },
5230
+ {
5231
+ value: "!=",
5232
+ label: "not equals (!=)"
5233
+ }
5234
+ ],
5235
+ any: [
5236
+ {
5237
+ value: "==",
5238
+ label: "equals (==)"
5239
+ },
5240
+ {
5241
+ value: "!=",
5242
+ label: "not equals (!=)"
5243
+ }
5244
+ ]
5245
+ };
5246
+ function getOperatorsForType(type) {
5247
+ var _OPERATORS_BY_TYPE_type, _ref;
5248
+ return (_ref = (_OPERATORS_BY_TYPE_type = OPERATORS_BY_TYPE[type]) !== null && _OPERATORS_BY_TYPE_type !== void 0 ? _OPERATORS_BY_TYPE_type : OPERATORS_BY_TYPE.any) !== null && _ref !== void 0 ? _ref : [
5249
+ {
5250
+ value: "==",
5251
+ label: "equals (==)"
5252
+ },
5253
+ {
5254
+ value: "!=",
5255
+ label: "not equals (!=)"
5256
+ }
5257
+ ];
5258
+ }
5129
5259
  exports.Button = Button;
5130
5260
  exports.buttonVariants = buttonVariants;
5131
5261
  exports.fields = fields_exports; //# sourceMappingURL=index.cjs.map