@constela/core 0.10.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -16,6 +16,10 @@ declare const STORAGE_TYPES: readonly ["local", "session"];
16
16
  type StorageType = (typeof STORAGE_TYPES)[number];
17
17
  declare const CLIPBOARD_OPERATIONS: readonly ["write", "read"];
18
18
  type ClipboardOperation = (typeof CLIPBOARD_OPERATIONS)[number];
19
+ declare const FOCUS_OPERATIONS: readonly ["focus", "blur", "select"];
20
+ type FocusOperation = (typeof FOCUS_OPERATIONS)[number];
21
+ declare const VALIDITY_PROPERTIES: readonly ["valid", "valueMissing", "typeMismatch", "patternMismatch", "tooLong", "tooShort", "rangeUnderflow", "rangeOverflow", "customError", "message"];
22
+ type ValidityProperty = (typeof VALIDITY_PROPERTIES)[number];
19
23
  declare const NAVIGATE_TARGETS: readonly ["_self", "_blank"];
20
24
  type NavigateTarget = (typeof NAVIGATE_TARGETS)[number];
21
25
  declare const PARAM_TYPES: readonly ["string", "number", "boolean", "json"];
@@ -142,7 +146,23 @@ interface ConcatExpr {
142
146
  expr: 'concat';
143
147
  items: Expression[];
144
148
  }
145
- type Expression = LitExpr | StateExpr | VarExpr | BinExpr | NotExpr | ParamExpr | CondExpr | GetExpr | RouteExpr | ImportExpr | DataExpr | RefExpr | IndexExpr | StyleExpr | ConcatExpr;
149
+ /**
150
+ * Validity expression - gets form element validation state
151
+ */
152
+ interface ValidityExpr {
153
+ expr: 'validity';
154
+ ref: string;
155
+ property?: ValidityProperty;
156
+ }
157
+ type Expression = LitExpr | StateExpr | VarExpr | BinExpr | NotExpr | ParamExpr | CondExpr | GetExpr | RouteExpr | ImportExpr | DataExpr | RefExpr | IndexExpr | StyleExpr | ConcatExpr | ValidityExpr;
158
+ /**
159
+ * Cookie expression for state initial value
160
+ */
161
+ interface CookieInitialExpr {
162
+ expr: 'cookie';
163
+ key: string;
164
+ default: string;
165
+ }
146
166
  /**
147
167
  * Number state field
148
168
  */
@@ -155,7 +175,7 @@ interface NumberField {
155
175
  */
156
176
  interface StringField {
157
177
  type: 'string';
158
- initial: string;
178
+ initial: string | CookieInitialExpr;
159
179
  }
160
180
  /**
161
181
  * List state field
@@ -340,8 +360,51 @@ interface CloseStep {
340
360
  do: 'close';
341
361
  connection: string;
342
362
  }
343
- type ActionStep = SetStep | UpdateStep | SetPathStep | FetchStep | StorageStep | ClipboardStep | NavigateStep | ImportStep | CallStep | SubscribeStep | DisposeStep | DomStep | SendStep | CloseStep;
363
+ /**
364
+ * Delay step - executes steps after a delay (setTimeout equivalent)
365
+ */
366
+ interface DelayStep {
367
+ do: 'delay';
368
+ ms: Expression;
369
+ then: ActionStep[];
370
+ result?: string;
371
+ }
372
+ /**
373
+ * Interval step - executes an action repeatedly (setInterval equivalent)
374
+ */
375
+ interface IntervalStep {
376
+ do: 'interval';
377
+ ms: Expression;
378
+ action: string;
379
+ result?: string;
380
+ }
381
+ /**
382
+ * ClearTimer step - clears a timer (clearTimeout/clearInterval equivalent)
383
+ */
384
+ interface ClearTimerStep {
385
+ do: 'clearTimer';
386
+ target: Expression;
387
+ }
388
+ /**
389
+ * Focus step - manages form element focus
390
+ */
391
+ interface FocusStep {
392
+ do: 'focus';
393
+ target: Expression;
394
+ operation: FocusOperation;
395
+ onSuccess?: ActionStep[];
396
+ onError?: ActionStep[];
397
+ }
398
+ type ActionStep = SetStep | UpdateStep | SetPathStep | FetchStep | StorageStep | ClipboardStep | NavigateStep | ImportStep | CallStep | SubscribeStep | DisposeStep | DomStep | SendStep | CloseStep | DelayStep | IntervalStep | ClearTimerStep | FocusStep;
344
399
  type LocalActionStep = SetStep | UpdateStep | SetPathStep;
400
+ /**
401
+ * Event handler options for special events like intersect
402
+ */
403
+ interface EventHandlerOptions {
404
+ threshold?: number;
405
+ rootMargin?: string;
406
+ once?: boolean;
407
+ }
345
408
  /**
346
409
  * Event handler - binds an event to an action
347
410
  */
@@ -349,6 +412,9 @@ interface EventHandler {
349
412
  event: string;
350
413
  action: string;
351
414
  payload?: Expression;
415
+ debounce?: number;
416
+ throttle?: number;
417
+ options?: EventHandlerOptions;
352
418
  }
353
419
  /**
354
420
  * Action definition - a named sequence of steps
@@ -434,7 +500,15 @@ interface CodeNode {
434
500
  language: Expression;
435
501
  content: Expression;
436
502
  }
437
- type ViewNode = ElementNode | TextNode | IfNode | EachNode | ComponentNode | SlotNode | MarkdownNode | CodeNode;
503
+ /**
504
+ * Portal node - renders children to a different DOM location
505
+ */
506
+ interface PortalNode {
507
+ kind: 'portal';
508
+ target: 'body' | 'head' | string;
509
+ children: ViewNode[];
510
+ }
511
+ type ViewNode = ElementNode | TextNode | IfNode | EachNode | ComponentNode | SlotNode | MarkdownNode | CodeNode | PortalNode;
438
512
  interface ComponentDef {
439
513
  params?: Record<string, ParamDef>;
440
514
  localState?: Record<string, StateField>;
@@ -633,6 +707,10 @@ declare function isStyleExpr(value: unknown): value is StyleExpr;
633
707
  * Checks if value is a concat expression
634
708
  */
635
709
  declare function isConcatExpr(value: unknown): value is ConcatExpr;
710
+ /**
711
+ * Checks if value is a validity expression
712
+ */
713
+ declare function isValidityExpr(value: unknown): value is ValidityExpr;
636
714
  /**
637
715
  * Checks if value is a data source
638
716
  */
@@ -681,6 +759,10 @@ declare function isMarkdownNode(value: unknown): value is MarkdownNode;
681
759
  * Checks if value is a code node
682
760
  */
683
761
  declare function isCodeNode(value: unknown): value is CodeNode;
762
+ /**
763
+ * Checks if value is a portal node
764
+ */
765
+ declare function isPortalNode(value: unknown): value is PortalNode;
684
766
  /**
685
767
  * Checks if value is any valid view node
686
768
  */
@@ -729,6 +811,10 @@ declare function isSubscribeStep(value: unknown): value is SubscribeStep;
729
811
  * Checks if value is a dispose step
730
812
  */
731
813
  declare function isDisposeStep(value: unknown): value is DisposeStep;
814
+ /**
815
+ * Checks if value is a focus step
816
+ */
817
+ declare function isFocusStep(value: unknown): value is FocusStep;
732
818
  /**
733
819
  * Checks if value is any valid action step
734
820
  */
@@ -746,6 +832,10 @@ declare function isLocalActionDefinition(value: unknown): value is LocalActionDe
746
832
  * Checks if value is a number field
747
833
  */
748
834
  declare function isNumberField(value: unknown): value is NumberField;
835
+ /**
836
+ * Checks if value is a cookie initial expression
837
+ */
838
+ declare function isCookieInitialExpr(value: unknown): value is CookieInitialExpr;
749
839
  /**
750
840
  * Checks if value is a string field
751
841
  */
@@ -1109,6 +1199,8 @@ declare const astSchema: {
1109
1199
  readonly $ref: "#/$defs/IndexExpr";
1110
1200
  }, {
1111
1201
  readonly $ref: "#/$defs/StyleExpr";
1202
+ }, {
1203
+ readonly $ref: "#/$defs/ValidityExpr";
1112
1204
  }];
1113
1205
  };
1114
1206
  readonly LitExpr: {
@@ -1295,6 +1387,24 @@ declare const astSchema: {
1295
1387
  };
1296
1388
  };
1297
1389
  };
1390
+ readonly ValidityExpr: {
1391
+ readonly type: "object";
1392
+ readonly required: readonly ["expr", "ref"];
1393
+ readonly additionalProperties: false;
1394
+ readonly properties: {
1395
+ readonly expr: {
1396
+ readonly type: "string";
1397
+ readonly const: "validity";
1398
+ };
1399
+ readonly ref: {
1400
+ readonly type: "string";
1401
+ };
1402
+ readonly property: {
1403
+ readonly type: "string";
1404
+ readonly enum: readonly ["valid", "valueMissing", "typeMismatch", "patternMismatch", "tooLong", "tooShort", "rangeUnderflow", "rangeOverflow", "customError", "message"];
1405
+ };
1406
+ };
1407
+ };
1298
1408
  readonly StylePreset: {
1299
1409
  readonly type: "object";
1300
1410
  readonly required: readonly ["base"];
@@ -1375,6 +1485,27 @@ declare const astSchema: {
1375
1485
  readonly const: "string";
1376
1486
  };
1377
1487
  readonly initial: {
1488
+ readonly oneOf: readonly [{
1489
+ readonly type: "string";
1490
+ }, {
1491
+ readonly $ref: "#/$defs/CookieInitialExpr";
1492
+ }];
1493
+ };
1494
+ };
1495
+ };
1496
+ readonly CookieInitialExpr: {
1497
+ readonly type: "object";
1498
+ readonly required: readonly ["expr", "key", "default"];
1499
+ readonly additionalProperties: false;
1500
+ readonly properties: {
1501
+ readonly expr: {
1502
+ readonly type: "string";
1503
+ readonly const: "cookie";
1504
+ };
1505
+ readonly key: {
1506
+ readonly type: "string";
1507
+ };
1508
+ readonly default: {
1378
1509
  readonly type: "string";
1379
1510
  };
1380
1511
  };
@@ -1428,6 +1559,14 @@ declare const astSchema: {
1428
1559
  readonly $ref: "#/$defs/UpdateStep";
1429
1560
  }, {
1430
1561
  readonly $ref: "#/$defs/FetchStep";
1562
+ }, {
1563
+ readonly $ref: "#/$defs/DelayStep";
1564
+ }, {
1565
+ readonly $ref: "#/$defs/IntervalStep";
1566
+ }, {
1567
+ readonly $ref: "#/$defs/ClearTimerStep";
1568
+ }, {
1569
+ readonly $ref: "#/$defs/FocusStep";
1431
1570
  }];
1432
1571
  };
1433
1572
  readonly SetStep: {
@@ -1510,6 +1649,93 @@ declare const astSchema: {
1510
1649
  };
1511
1650
  };
1512
1651
  };
1652
+ readonly DelayStep: {
1653
+ readonly type: "object";
1654
+ readonly required: readonly ["do", "ms", "then"];
1655
+ readonly additionalProperties: false;
1656
+ readonly properties: {
1657
+ readonly do: {
1658
+ readonly type: "string";
1659
+ readonly const: "delay";
1660
+ };
1661
+ readonly ms: {
1662
+ readonly $ref: "#/$defs/Expression";
1663
+ };
1664
+ readonly then: {
1665
+ readonly type: "array";
1666
+ readonly items: {
1667
+ readonly $ref: "#/$defs/ActionStep";
1668
+ };
1669
+ };
1670
+ readonly result: {
1671
+ readonly type: "string";
1672
+ };
1673
+ };
1674
+ };
1675
+ readonly IntervalStep: {
1676
+ readonly type: "object";
1677
+ readonly required: readonly ["do", "ms", "action"];
1678
+ readonly additionalProperties: false;
1679
+ readonly properties: {
1680
+ readonly do: {
1681
+ readonly type: "string";
1682
+ readonly const: "interval";
1683
+ };
1684
+ readonly ms: {
1685
+ readonly $ref: "#/$defs/Expression";
1686
+ };
1687
+ readonly action: {
1688
+ readonly type: "string";
1689
+ };
1690
+ readonly result: {
1691
+ readonly type: "string";
1692
+ };
1693
+ };
1694
+ };
1695
+ readonly ClearTimerStep: {
1696
+ readonly type: "object";
1697
+ readonly required: readonly ["do", "target"];
1698
+ readonly additionalProperties: false;
1699
+ readonly properties: {
1700
+ readonly do: {
1701
+ readonly type: "string";
1702
+ readonly const: "clearTimer";
1703
+ };
1704
+ readonly target: {
1705
+ readonly $ref: "#/$defs/Expression";
1706
+ };
1707
+ };
1708
+ };
1709
+ readonly FocusStep: {
1710
+ readonly type: "object";
1711
+ readonly required: readonly ["do", "target", "operation"];
1712
+ readonly additionalProperties: false;
1713
+ readonly properties: {
1714
+ readonly do: {
1715
+ readonly type: "string";
1716
+ readonly const: "focus";
1717
+ };
1718
+ readonly target: {
1719
+ readonly $ref: "#/$defs/Expression";
1720
+ };
1721
+ readonly operation: {
1722
+ readonly type: "string";
1723
+ readonly enum: readonly ["focus", "blur", "select"];
1724
+ };
1725
+ readonly onSuccess: {
1726
+ readonly type: "array";
1727
+ readonly items: {
1728
+ readonly $ref: "#/$defs/ActionStep";
1729
+ };
1730
+ };
1731
+ readonly onError: {
1732
+ readonly type: "array";
1733
+ readonly items: {
1734
+ readonly $ref: "#/$defs/ActionStep";
1735
+ };
1736
+ };
1737
+ };
1738
+ };
1513
1739
  readonly EventHandler: {
1514
1740
  readonly type: "object";
1515
1741
  readonly required: readonly ["event", "action"];
@@ -1524,6 +1750,30 @@ declare const astSchema: {
1524
1750
  readonly payload: {
1525
1751
  readonly $ref: "#/$defs/Expression";
1526
1752
  };
1753
+ readonly debounce: {
1754
+ readonly type: "number";
1755
+ };
1756
+ readonly throttle: {
1757
+ readonly type: "number";
1758
+ };
1759
+ readonly options: {
1760
+ readonly $ref: "#/$defs/EventHandlerOptions";
1761
+ };
1762
+ };
1763
+ };
1764
+ readonly EventHandlerOptions: {
1765
+ readonly type: "object";
1766
+ readonly additionalProperties: false;
1767
+ readonly properties: {
1768
+ readonly threshold: {
1769
+ readonly type: "number";
1770
+ };
1771
+ readonly rootMargin: {
1772
+ readonly type: "string";
1773
+ };
1774
+ readonly once: {
1775
+ readonly type: "boolean";
1776
+ };
1527
1777
  };
1528
1778
  };
1529
1779
  readonly ActionDefinition: {
@@ -1559,6 +1809,8 @@ declare const astSchema: {
1559
1809
  readonly $ref: "#/$defs/MarkdownNode";
1560
1810
  }, {
1561
1811
  readonly $ref: "#/$defs/CodeNode";
1812
+ }, {
1813
+ readonly $ref: "#/$defs/PortalNode";
1562
1814
  }];
1563
1815
  };
1564
1816
  readonly ElementNode: {
@@ -1719,6 +1971,26 @@ declare const astSchema: {
1719
1971
  };
1720
1972
  };
1721
1973
  };
1974
+ readonly PortalNode: {
1975
+ readonly type: "object";
1976
+ readonly required: readonly ["kind", "target", "children"];
1977
+ readonly additionalProperties: false;
1978
+ readonly properties: {
1979
+ readonly kind: {
1980
+ readonly type: "string";
1981
+ readonly const: "portal";
1982
+ };
1983
+ readonly target: {
1984
+ readonly type: "string";
1985
+ };
1986
+ readonly children: {
1987
+ readonly type: "array";
1988
+ readonly items: {
1989
+ readonly $ref: "#/$defs/ViewNode";
1990
+ };
1991
+ };
1992
+ };
1993
+ };
1722
1994
  readonly ParamDef: {
1723
1995
  readonly type: "object";
1724
1996
  readonly required: readonly ["type"];
@@ -1752,4 +2024,4 @@ declare const astSchema: {
1752
2024
  };
1753
2025
  };
1754
2026
 
1755
- export { type ActionDefinition, type ActionStep, BINARY_OPERATORS, type BinExpr, type BinaryOperator, type BooleanField, CLIPBOARD_OPERATIONS, type CallStep, type ClipboardOperation, type ClipboardStep, type CloseStep, type CodeNode, type ComponentDef, type ComponentNode, type ComponentsRef, type CompoundVariant, type ConcatExpr, type CondExpr, type ConstelaAst, ConstelaError, type ConstelaProgram, DATA_SOURCE_TYPES, DATA_TRANSFORMS, type DataExpr, type DataSource, type DataSourceType, type DataTransform, type DisposeStep, type DomStep, type EachNode, type ElementNode, type ErrorCode, type ErrorOptions, type EventHandler, type Expression, type FetchStep, type GetExpr, HTTP_METHODS, type HttpMethod, type IfNode, type ImportExpr, type ImportStep, type LayoutProgram, type LifecycleHooks, type ListField, type LitExpr, type LocalActionDefinition, type LocalActionStep, type MarkdownNode, NAVIGATE_TARGETS, type NavigateStep, type NavigateTarget, type NotExpr, type NumberField, type ObjectField, PARAM_TYPES, type ParamDef, type ParamExpr, type ParamType, type Program, type RefExpr, type RouteDefinition, type RouteExpr, STORAGE_OPERATIONS, STORAGE_TYPES, type SendStep, type SetPathStep, type SetStep, type SlotNode, type StateExpr, type StateField, type StaticPathsDefinition, type StorageOperation, type StorageStep, type StorageType, type StringField, type StyleExpr, type StylePreset, type SubscribeStep, type TextNode, UPDATE_OPERATIONS, type UpdateOperation, type UpdateStep, type ValidationFailure, type ValidationResult, type ValidationSuccess, type VarExpr, type ViewNode, astSchema, createClipboardWriteMissingValueError, createComponentCycleError, createComponentNotFoundError, createComponentPropMissingError, createComponentPropTypeError, createCondElseRequiredError, createDataNotDefinedError, createDuplicateActionError, createDuplicateDefaultSlotError, createDuplicateSlotNameError, createImportsNotDefinedError, createInvalidClipboardOperationError, createInvalidDataSourceError, createInvalidNavigateTargetError, createInvalidSlotNameError, createInvalidStorageOperationError, createInvalidStorageTypeError, createLayoutMissingSlotError, createLayoutNotFoundError, createLocalActionInvalidStepError, createOperationInvalidForTypeError, createOperationMissingFieldError, createOperationUnknownError, createRouteNotDefinedError, createSchemaError, createSlotInLoopError, createStorageSetMissingValueError, createUndefinedActionError, createUndefinedDataError, createUndefinedDataSourceError, createUndefinedImportError, createUndefinedLocalStateError, createUndefinedParamError, createUndefinedRefError, createUndefinedRouteParamError, createUndefinedStateError, createUndefinedStyleError, createUndefinedVarError, createUndefinedVariantError, createUnsupportedVersionError, findSimilarNames, isActionStep, isBinExpr, isBooleanField, isCallStep, isClipboardStep, isCodeNode, isComponentNode, isConcatExpr, isCondExpr, isConstelaError, isDataExpr, isDataSource, isDisposeStep, isEachNode, isElementNode, isEventHandler, isExpression, isFetchStep, isGetExpr, isIfNode, isImportExpr, isImportStep, isLayoutProgram, isLifecycleHooks, isListField, isLitExpr, isLocalActionDefinition, isLocalActionStep, isMarkdownNode, isNamedSlotNode, isNavigateStep, isNotExpr, isNumberField, isObjectField, isParamExpr, isRefExpr, isRouteDefinition, isRouteExpr, isSetPathStep, isSetStep, isSlotNode, isStateExpr, isStateField, isStaticPathsDefinition, isStorageStep, isStringField, isStyleExpr, isSubscribeStep, isTextNode, isUpdateStep, isVarExpr, isViewNode, validateAst };
2027
+ export { type ActionDefinition, type ActionStep, BINARY_OPERATORS, type BinExpr, type BinaryOperator, type BooleanField, CLIPBOARD_OPERATIONS, type CallStep, type ClearTimerStep, type ClipboardOperation, type ClipboardStep, type CloseStep, type CodeNode, type ComponentDef, type ComponentNode, type ComponentsRef, type CompoundVariant, type ConcatExpr, type CondExpr, type ConstelaAst, ConstelaError, type ConstelaProgram, type CookieInitialExpr, DATA_SOURCE_TYPES, DATA_TRANSFORMS, type DataExpr, type DataSource, type DataSourceType, type DataTransform, type DelayStep, type DisposeStep, type DomStep, type EachNode, type ElementNode, type ErrorCode, type ErrorOptions, type EventHandler, type EventHandlerOptions, type Expression, FOCUS_OPERATIONS, type FetchStep, type FocusOperation, type FocusStep, type GetExpr, HTTP_METHODS, type HttpMethod, type IfNode, type ImportExpr, type ImportStep, type IntervalStep, type LayoutProgram, type LifecycleHooks, type ListField, type LitExpr, type LocalActionDefinition, type LocalActionStep, type MarkdownNode, NAVIGATE_TARGETS, type NavigateStep, type NavigateTarget, type NotExpr, type NumberField, type ObjectField, PARAM_TYPES, type ParamDef, type ParamExpr, type ParamType, type PortalNode, type Program, type RefExpr, type RouteDefinition, type RouteExpr, STORAGE_OPERATIONS, STORAGE_TYPES, type SendStep, type SetPathStep, type SetStep, type SlotNode, type StateExpr, type StateField, type StaticPathsDefinition, type StorageOperation, type StorageStep, type StorageType, type StringField, type StyleExpr, type StylePreset, type SubscribeStep, type TextNode, UPDATE_OPERATIONS, type UpdateOperation, type UpdateStep, VALIDITY_PROPERTIES, type ValidationFailure, type ValidationResult, type ValidationSuccess, type ValidityExpr, type ValidityProperty, type VarExpr, type ViewNode, astSchema, createClipboardWriteMissingValueError, createComponentCycleError, createComponentNotFoundError, createComponentPropMissingError, createComponentPropTypeError, createCondElseRequiredError, createDataNotDefinedError, createDuplicateActionError, createDuplicateDefaultSlotError, createDuplicateSlotNameError, createImportsNotDefinedError, createInvalidClipboardOperationError, createInvalidDataSourceError, createInvalidNavigateTargetError, createInvalidSlotNameError, createInvalidStorageOperationError, createInvalidStorageTypeError, createLayoutMissingSlotError, createLayoutNotFoundError, createLocalActionInvalidStepError, createOperationInvalidForTypeError, createOperationMissingFieldError, createOperationUnknownError, createRouteNotDefinedError, createSchemaError, createSlotInLoopError, createStorageSetMissingValueError, createUndefinedActionError, createUndefinedDataError, createUndefinedDataSourceError, createUndefinedImportError, createUndefinedLocalStateError, createUndefinedParamError, createUndefinedRefError, createUndefinedRouteParamError, createUndefinedStateError, createUndefinedStyleError, createUndefinedVarError, createUndefinedVariantError, createUnsupportedVersionError, findSimilarNames, isActionStep, isBinExpr, isBooleanField, isCallStep, isClipboardStep, isCodeNode, isComponentNode, isConcatExpr, isCondExpr, isConstelaError, isCookieInitialExpr, isDataExpr, isDataSource, isDisposeStep, isEachNode, isElementNode, isEventHandler, isExpression, isFetchStep, isFocusStep, isGetExpr, isIfNode, isImportExpr, isImportStep, isLayoutProgram, isLifecycleHooks, isListField, isLitExpr, isLocalActionDefinition, isLocalActionStep, isMarkdownNode, isNamedSlotNode, isNavigateStep, isNotExpr, isNumberField, isObjectField, isParamExpr, isPortalNode, isRefExpr, isRouteDefinition, isRouteExpr, isSetPathStep, isSetStep, isSlotNode, isStateExpr, isStateField, isStaticPathsDefinition, isStorageStep, isStringField, isStyleExpr, isSubscribeStep, isTextNode, isUpdateStep, isValidityExpr, isVarExpr, isViewNode, validateAst };
package/dist/index.js CHANGED
@@ -29,6 +29,19 @@ var HTTP_METHODS = ["GET", "POST", "PUT", "DELETE"];
29
29
  var STORAGE_OPERATIONS = ["get", "set", "remove"];
30
30
  var STORAGE_TYPES = ["local", "session"];
31
31
  var CLIPBOARD_OPERATIONS = ["write", "read"];
32
+ var FOCUS_OPERATIONS = ["focus", "blur", "select"];
33
+ var VALIDITY_PROPERTIES = [
34
+ "valid",
35
+ "valueMissing",
36
+ "typeMismatch",
37
+ "patternMismatch",
38
+ "tooLong",
39
+ "tooShort",
40
+ "rangeUnderflow",
41
+ "rangeOverflow",
42
+ "customError",
43
+ "message"
44
+ ];
32
45
  var NAVIGATE_TARGETS = ["_self", "_blank"];
33
46
  var PARAM_TYPES = ["string", "number", "boolean", "json"];
34
47
  var DATA_TRANSFORMS = ["mdx", "yaml", "csv"];
@@ -142,6 +155,17 @@ function isStyleExpr(value) {
142
155
  function isConcatExpr(value) {
143
156
  return typeof value === "object" && value !== null && value.expr === "concat" && Array.isArray(value.items);
144
157
  }
158
+ function isValidityExpr(value) {
159
+ if (!isObject(value)) return false;
160
+ if (value["expr"] !== "validity") return false;
161
+ if (typeof value["ref"] !== "string") return false;
162
+ if ("property" in value && value["property"] !== void 0) {
163
+ if (!VALIDITY_PROPERTIES.includes(value["property"])) {
164
+ return false;
165
+ }
166
+ }
167
+ return true;
168
+ }
145
169
  function isDataSource(value) {
146
170
  if (!isObject(value)) return false;
147
171
  const type = value["type"];
@@ -178,7 +202,7 @@ function isRouteDefinition(value) {
178
202
  return true;
179
203
  }
180
204
  function isExpression(value) {
181
- return isLitExpr(value) || isStateExpr(value) || isVarExpr(value) || isBinExpr(value) || isNotExpr(value) || isParamExpr(value) || isCondExpr(value) || isGetExpr(value) || isRouteExpr(value) || isImportExpr(value) || isDataExpr(value) || isRefExpr(value) || isIndexExpr(value) || isStyleExpr(value) || isConcatExpr(value);
205
+ return isLitExpr(value) || isStateExpr(value) || isVarExpr(value) || isBinExpr(value) || isNotExpr(value) || isParamExpr(value) || isCondExpr(value) || isGetExpr(value) || isRouteExpr(value) || isImportExpr(value) || isDataExpr(value) || isRefExpr(value) || isIndexExpr(value) || isStyleExpr(value) || isConcatExpr(value) || isValidityExpr(value);
182
206
  }
183
207
  function isElementNode(value) {
184
208
  if (!isObject(value)) return false;
@@ -233,8 +257,15 @@ function isCodeNode(value) {
233
257
  if (!("content" in value) || !isObject(value["content"])) return false;
234
258
  return true;
235
259
  }
260
+ function isPortalNode(value) {
261
+ if (!isObject(value)) return false;
262
+ if (value["kind"] !== "portal") return false;
263
+ if (typeof value["target"] !== "string") return false;
264
+ if (!Array.isArray(value["children"])) return false;
265
+ return true;
266
+ }
236
267
  function isViewNode(value) {
237
- return isElementNode(value) || isTextNode(value) || isIfNode(value) || isEachNode(value) || isComponentNode(value) || isSlotNode(value) || isMarkdownNode(value) || isCodeNode(value);
268
+ return isElementNode(value) || isTextNode(value) || isIfNode(value) || isEachNode(value) || isComponentNode(value) || isSlotNode(value) || isMarkdownNode(value) || isCodeNode(value) || isPortalNode(value);
238
269
  }
239
270
  function isSetStep(value) {
240
271
  if (!isObject(value)) return false;
@@ -329,8 +360,37 @@ function isDisposeStep(value) {
329
360
  if (!isObject(value["target"])) return false;
330
361
  return true;
331
362
  }
363
+ function isDelayStep(value) {
364
+ if (!isObject(value)) return false;
365
+ if (value["do"] !== "delay") return false;
366
+ if (!isObject(value["ms"])) return false;
367
+ if (!Array.isArray(value["then"])) return false;
368
+ return true;
369
+ }
370
+ function isIntervalStep(value) {
371
+ if (!isObject(value)) return false;
372
+ if (value["do"] !== "interval") return false;
373
+ if (!isObject(value["ms"])) return false;
374
+ if (typeof value["action"] !== "string") return false;
375
+ return true;
376
+ }
377
+ function isClearTimerStep(value) {
378
+ if (!isObject(value)) return false;
379
+ if (value["do"] !== "clearTimer") return false;
380
+ if (!isObject(value["target"])) return false;
381
+ return true;
382
+ }
383
+ function isFocusStep(value) {
384
+ if (!isObject(value)) return false;
385
+ if (value["do"] !== "focus") return false;
386
+ if (!isObject(value["target"])) return false;
387
+ if (!FOCUS_OPERATIONS.includes(value["operation"])) {
388
+ return false;
389
+ }
390
+ return true;
391
+ }
332
392
  function isActionStep(value) {
333
- return isSetStep(value) || isUpdateStep(value) || isSetPathStep(value) || isFetchStep(value) || isStorageStep(value) || isClipboardStep(value) || isNavigateStep(value) || isImportStep(value) || isCallStep(value) || isSubscribeStep(value) || isDisposeStep(value);
393
+ return isSetStep(value) || isUpdateStep(value) || isSetPathStep(value) || isFetchStep(value) || isStorageStep(value) || isClipboardStep(value) || isNavigateStep(value) || isImportStep(value) || isCallStep(value) || isSubscribeStep(value) || isDisposeStep(value) || isDelayStep(value) || isIntervalStep(value) || isClearTimerStep(value) || isFocusStep(value);
334
394
  }
335
395
  function isLocalActionStep(value) {
336
396
  return isSetStep(value) || isUpdateStep(value) || isSetPathStep(value);
@@ -349,10 +409,13 @@ function isNumberField(value) {
349
409
  if (value["type"] !== "number") return false;
350
410
  return typeof value["initial"] === "number";
351
411
  }
412
+ function isCookieInitialExpr(value) {
413
+ return typeof value === "object" && value !== null && "expr" in value && value.expr === "cookie" && "key" in value && typeof value.key === "string" && "default" in value && typeof value.default === "string";
414
+ }
352
415
  function isStringField(value) {
353
416
  if (!isObject(value)) return false;
354
417
  if (value["type"] !== "string") return false;
355
- return typeof value["initial"] === "string";
418
+ return typeof value["initial"] === "string" || isCookieInitialExpr(value["initial"]);
356
419
  }
357
420
  function isListField(value) {
358
421
  if (!isObject(value)) return false;
@@ -1459,7 +1522,8 @@ var astSchema = {
1459
1522
  { $ref: "#/$defs/CondExpr" },
1460
1523
  { $ref: "#/$defs/GetExpr" },
1461
1524
  { $ref: "#/$defs/IndexExpr" },
1462
- { $ref: "#/$defs/StyleExpr" }
1525
+ { $ref: "#/$defs/StyleExpr" },
1526
+ { $ref: "#/$defs/ValidityExpr" }
1463
1527
  ]
1464
1528
  },
1465
1529
  LitExpr: {
@@ -1576,6 +1640,19 @@ var astSchema = {
1576
1640
  }
1577
1641
  }
1578
1642
  },
1643
+ ValidityExpr: {
1644
+ type: "object",
1645
+ required: ["expr", "ref"],
1646
+ additionalProperties: false,
1647
+ properties: {
1648
+ expr: { type: "string", const: "validity" },
1649
+ ref: { type: "string" },
1650
+ property: {
1651
+ type: "string",
1652
+ enum: ["valid", "valueMissing", "typeMismatch", "patternMismatch", "tooLong", "tooShort", "rangeUnderflow", "rangeOverflow", "customError", "message"]
1653
+ }
1654
+ }
1655
+ },
1579
1656
  // ==================== Style Presets ====================
1580
1657
  StylePreset: {
1581
1658
  type: "object",
@@ -1633,7 +1710,22 @@ var astSchema = {
1633
1710
  additionalProperties: false,
1634
1711
  properties: {
1635
1712
  type: { type: "string", const: "string" },
1636
- initial: { type: "string" }
1713
+ initial: {
1714
+ oneOf: [
1715
+ { type: "string" },
1716
+ { $ref: "#/$defs/CookieInitialExpr" }
1717
+ ]
1718
+ }
1719
+ }
1720
+ },
1721
+ CookieInitialExpr: {
1722
+ type: "object",
1723
+ required: ["expr", "key", "default"],
1724
+ additionalProperties: false,
1725
+ properties: {
1726
+ expr: { type: "string", const: "cookie" },
1727
+ key: { type: "string" },
1728
+ default: { type: "string" }
1637
1729
  }
1638
1730
  },
1639
1731
  ListField: {
@@ -1668,7 +1760,11 @@ var astSchema = {
1668
1760
  oneOf: [
1669
1761
  { $ref: "#/$defs/SetStep" },
1670
1762
  { $ref: "#/$defs/UpdateStep" },
1671
- { $ref: "#/$defs/FetchStep" }
1763
+ { $ref: "#/$defs/FetchStep" },
1764
+ { $ref: "#/$defs/DelayStep" },
1765
+ { $ref: "#/$defs/IntervalStep" },
1766
+ { $ref: "#/$defs/ClearTimerStep" },
1767
+ { $ref: "#/$defs/FocusStep" }
1672
1768
  ]
1673
1769
  },
1674
1770
  SetStep: {
@@ -1720,6 +1816,61 @@ var astSchema = {
1720
1816
  }
1721
1817
  }
1722
1818
  },
1819
+ DelayStep: {
1820
+ type: "object",
1821
+ required: ["do", "ms", "then"],
1822
+ additionalProperties: false,
1823
+ properties: {
1824
+ do: { type: "string", const: "delay" },
1825
+ ms: { $ref: "#/$defs/Expression" },
1826
+ then: {
1827
+ type: "array",
1828
+ items: { $ref: "#/$defs/ActionStep" }
1829
+ },
1830
+ result: { type: "string" }
1831
+ }
1832
+ },
1833
+ IntervalStep: {
1834
+ type: "object",
1835
+ required: ["do", "ms", "action"],
1836
+ additionalProperties: false,
1837
+ properties: {
1838
+ do: { type: "string", const: "interval" },
1839
+ ms: { $ref: "#/$defs/Expression" },
1840
+ action: { type: "string" },
1841
+ result: { type: "string" }
1842
+ }
1843
+ },
1844
+ ClearTimerStep: {
1845
+ type: "object",
1846
+ required: ["do", "target"],
1847
+ additionalProperties: false,
1848
+ properties: {
1849
+ do: { type: "string", const: "clearTimer" },
1850
+ target: { $ref: "#/$defs/Expression" }
1851
+ }
1852
+ },
1853
+ FocusStep: {
1854
+ type: "object",
1855
+ required: ["do", "target", "operation"],
1856
+ additionalProperties: false,
1857
+ properties: {
1858
+ do: { type: "string", const: "focus" },
1859
+ target: { $ref: "#/$defs/Expression" },
1860
+ operation: {
1861
+ type: "string",
1862
+ enum: ["focus", "blur", "select"]
1863
+ },
1864
+ onSuccess: {
1865
+ type: "array",
1866
+ items: { $ref: "#/$defs/ActionStep" }
1867
+ },
1868
+ onError: {
1869
+ type: "array",
1870
+ items: { $ref: "#/$defs/ActionStep" }
1871
+ }
1872
+ }
1873
+ },
1723
1874
  // ==================== Event Handler ====================
1724
1875
  EventHandler: {
1725
1876
  type: "object",
@@ -1728,7 +1879,19 @@ var astSchema = {
1728
1879
  properties: {
1729
1880
  event: { type: "string" },
1730
1881
  action: { type: "string" },
1731
- payload: { $ref: "#/$defs/Expression" }
1882
+ payload: { $ref: "#/$defs/Expression" },
1883
+ debounce: { type: "number" },
1884
+ throttle: { type: "number" },
1885
+ options: { $ref: "#/$defs/EventHandlerOptions" }
1886
+ }
1887
+ },
1888
+ EventHandlerOptions: {
1889
+ type: "object",
1890
+ additionalProperties: false,
1891
+ properties: {
1892
+ threshold: { type: "number" },
1893
+ rootMargin: { type: "string" },
1894
+ once: { type: "boolean" }
1732
1895
  }
1733
1896
  },
1734
1897
  // ==================== Action Definition ====================
@@ -1754,7 +1917,8 @@ var astSchema = {
1754
1917
  { $ref: "#/$defs/ComponentNode" },
1755
1918
  { $ref: "#/$defs/SlotNode" },
1756
1919
  { $ref: "#/$defs/MarkdownNode" },
1757
- { $ref: "#/$defs/CodeNode" }
1920
+ { $ref: "#/$defs/CodeNode" },
1921
+ { $ref: "#/$defs/PortalNode" }
1758
1922
  ]
1759
1923
  },
1760
1924
  ElementNode: {
@@ -1856,6 +2020,19 @@ var astSchema = {
1856
2020
  content: { $ref: "#/$defs/Expression" }
1857
2021
  }
1858
2022
  },
2023
+ PortalNode: {
2024
+ type: "object",
2025
+ required: ["kind", "target", "children"],
2026
+ additionalProperties: false,
2027
+ properties: {
2028
+ kind: { type: "string", const: "portal" },
2029
+ target: { type: "string" },
2030
+ children: {
2031
+ type: "array",
2032
+ items: { $ref: "#/$defs/ViewNode" }
2033
+ }
2034
+ }
2035
+ },
1859
2036
  // ==================== Component Definition ====================
1860
2037
  ParamDef: {
1861
2038
  type: "object",
@@ -1889,12 +2066,14 @@ export {
1889
2066
  ConstelaError,
1890
2067
  DATA_SOURCE_TYPES,
1891
2068
  DATA_TRANSFORMS,
2069
+ FOCUS_OPERATIONS,
1892
2070
  HTTP_METHODS,
1893
2071
  NAVIGATE_TARGETS,
1894
2072
  PARAM_TYPES,
1895
2073
  STORAGE_OPERATIONS,
1896
2074
  STORAGE_TYPES,
1897
2075
  UPDATE_OPERATIONS,
2076
+ VALIDITY_PROPERTIES,
1898
2077
  astSchema,
1899
2078
  createClipboardWriteMissingValueError,
1900
2079
  createComponentCycleError,
@@ -1947,6 +2126,7 @@ export {
1947
2126
  isConcatExpr,
1948
2127
  isCondExpr,
1949
2128
  isConstelaError,
2129
+ isCookieInitialExpr,
1950
2130
  isDataExpr,
1951
2131
  isDataSource,
1952
2132
  isDisposeStep,
@@ -1955,6 +2135,7 @@ export {
1955
2135
  isEventHandler,
1956
2136
  isExpression,
1957
2137
  isFetchStep,
2138
+ isFocusStep,
1958
2139
  isGetExpr,
1959
2140
  isIfNode,
1960
2141
  isImportExpr,
@@ -1972,6 +2153,7 @@ export {
1972
2153
  isNumberField,
1973
2154
  isObjectField,
1974
2155
  isParamExpr,
2156
+ isPortalNode,
1975
2157
  isRefExpr,
1976
2158
  isRouteDefinition,
1977
2159
  isRouteExpr,
@@ -1987,6 +2169,7 @@ export {
1987
2169
  isSubscribeStep,
1988
2170
  isTextNode,
1989
2171
  isUpdateStep,
2172
+ isValidityExpr,
1990
2173
  isVarExpr,
1991
2174
  isViewNode,
1992
2175
  validateAst
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constela/core",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "description": "Core types, schema, and validator for Constela UI framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",