@object-ui/core 17.5.0 → 17.7.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.
Files changed (157) hide show
  1. package/CHANGELOG.md +7404 -0
  2. package/README.md +127 -26
  3. package/dist/actions/ActionEngine.d.ts +5 -3
  4. package/dist/actions/ActionEngine.js +14 -10
  5. package/dist/actions/ActionRunner.d.ts +363 -30
  6. package/dist/actions/ActionRunner.js +544 -58
  7. package/dist/actions/TransactionManager.d.ts +7 -2
  8. package/dist/actions/actionKeys.d.ts +75 -13
  9. package/dist/actions/actionKeys.js +131 -16
  10. package/dist/actions/actionResponse.js +3 -3
  11. package/dist/actions/index.d.ts +2 -0
  12. package/dist/actions/index.js +2 -0
  13. package/dist/actions/recordDelete.d.ts +118 -0
  14. package/dist/actions/recordDelete.js +112 -0
  15. package/dist/actions/recordIdParam.d.ts +77 -0
  16. package/dist/actions/recordIdParam.js +37 -0
  17. package/dist/actions/serverActionHandler.d.ts +1 -1
  18. package/dist/actions/serverActionHandler.js +1 -1
  19. package/dist/adapters/ValueDataSource.d.ts +6 -1
  20. package/dist/adapters/ValueDataSource.js +1090 -98
  21. package/dist/adapters/batchTransaction.d.ts +1 -1
  22. package/dist/adapters/batchTransaction.js +1 -1
  23. package/dist/builder/schema-builder.d.ts +38 -81
  24. package/dist/builder/schema-builder.js +33 -152
  25. package/dist/data-scope/ViewDataProvider.d.ts +1 -1
  26. package/dist/data-scope/ViewDataProvider.js +21 -1
  27. package/dist/data-scope/element-data-source.d.ts +261 -7
  28. package/dist/data-scope/element-data-source.js +342 -52
  29. package/dist/data-scope/index.d.ts +9 -4
  30. package/dist/data-scope/index.js +9 -4
  31. package/dist/evaluator/ExpressionEvaluator.d.ts +128 -1
  32. package/dist/evaluator/ExpressionEvaluator.js +226 -13
  33. package/dist/evaluator/FormulaFunctions.d.ts +0 -10
  34. package/dist/evaluator/FormulaFunctions.js +166 -27
  35. package/dist/evaluator/SafeExpressionParser.js +0 -4
  36. package/dist/evaluator/declaredPredicate.d.ts +93 -9
  37. package/dist/evaluator/declaredPredicate.js +118 -17
  38. package/dist/evaluator/fieldRules.d.ts +107 -4
  39. package/dist/evaluator/fieldRules.js +231 -35
  40. package/dist/evaluator/index.d.ts +2 -0
  41. package/dist/evaluator/index.js +2 -0
  42. package/dist/evaluator/listConditional.d.ts +125 -9
  43. package/dist/evaluator/listConditional.js +167 -26
  44. package/dist/evaluator/optionRules.d.ts +126 -0
  45. package/dist/evaluator/optionRules.js +141 -4
  46. package/dist/evaluator/predicateInput.d.ts +15 -4
  47. package/dist/evaluator/predicateInput.js +35 -2
  48. package/dist/evaluator/rowPredicateCanon.d.ts +56 -0
  49. package/dist/evaluator/rowPredicateCanon.js +158 -0
  50. package/dist/evaluator/subjectPermissions.d.ts +76 -0
  51. package/dist/evaluator/subjectPermissions.js +44 -0
  52. package/dist/evaluator/unevaluablePredicate.d.ts +57 -0
  53. package/dist/evaluator/unevaluablePredicate.js +70 -0
  54. package/dist/index.d.ts +18 -0
  55. package/dist/index.js +97 -2
  56. package/dist/protocols/index.d.ts +0 -1
  57. package/dist/protocols/index.js +9 -1
  58. package/dist/registry/Registry.d.ts +397 -48
  59. package/dist/registry/Registry.js +263 -11
  60. package/dist/registry/WidgetRegistry.js +7 -3
  61. package/dist/registry/html-tier-intrinsics.d.ts +90 -0
  62. package/dist/registry/html-tier-intrinsics.js +110 -0
  63. package/dist/registry/public-blocks.d.ts +8 -0
  64. package/dist/registry/public-blocks.js +57 -0
  65. package/dist/theme/ThemeEngine.js +1 -1
  66. package/dist/theme/index.d.ts +1 -1
  67. package/dist/theme/index.js +1 -1
  68. package/dist/types/index.d.ts +92 -13
  69. package/dist/utils/chart-category-key.d.ts +82 -0
  70. package/dist/utils/chart-category-key.js +84 -0
  71. package/dist/utils/chart-measure-key.d.ts +64 -0
  72. package/dist/utils/chart-measure-key.js +65 -0
  73. package/dist/utils/chart-presentation.d.ts +188 -0
  74. package/dist/utils/chart-presentation.js +345 -0
  75. package/dist/utils/chart-series.d.ts +271 -31
  76. package/dist/utils/chart-series.js +478 -55
  77. package/dist/utils/column-identity.d.ts +43 -0
  78. package/dist/utils/column-identity.js +47 -1
  79. package/dist/utils/column-sortability.d.ts +157 -0
  80. package/dist/utils/column-sortability.js +217 -0
  81. package/dist/utils/dashboard-filters.d.ts +38 -6
  82. package/dist/utils/dashboard-filters.js +107 -61
  83. package/dist/utils/dataset-format.d.ts +211 -30
  84. package/dist/utils/dataset-format.js +407 -52
  85. package/dist/utils/date-display.d.ts +354 -0
  86. package/dist/utils/date-display.js +463 -0
  87. package/dist/utils/date-macros.js +7 -0
  88. package/dist/utils/debug.js +7 -0
  89. package/dist/utils/drill-down.d.ts +78 -0
  90. package/dist/utils/drill-down.js +93 -0
  91. package/dist/utils/emptiness.d.ts +96 -0
  92. package/dist/utils/emptiness.js +101 -0
  93. package/dist/utils/expand-fields.d.ts +171 -11
  94. package/dist/utils/expand-fields.js +171 -11
  95. package/dist/utils/extract-records.d.ts +65 -5
  96. package/dist/utils/extract-records.js +65 -8
  97. package/dist/utils/filter-converter.d.ts +152 -4
  98. package/dist/utils/filter-converter.js +1092 -22
  99. package/dist/utils/filter-tokens.d.ts +49 -5
  100. package/dist/utils/filter-tokens.js +105 -34
  101. package/dist/utils/freeze-schema.d.ts +38 -1
  102. package/dist/utils/freeze-schema.js +10 -0
  103. package/dist/utils/grouping-fields.d.ts +61 -0
  104. package/dist/utils/grouping-fields.js +84 -0
  105. package/dist/utils/humanize-label.d.ts +60 -0
  106. package/dist/utils/humanize-label.js +62 -0
  107. package/dist/utils/managedBy.d.ts +30 -5
  108. package/dist/utils/managedBy.js +5 -5
  109. package/dist/utils/native-date-value.d.ts +48 -0
  110. package/dist/utils/native-date-value.js +167 -0
  111. package/dist/utils/non-grid-row-ceiling.d.ts +143 -0
  112. package/dist/utils/non-grid-row-ceiling.js +141 -0
  113. package/dist/utils/normalize-list-view.d.ts +131 -1
  114. package/dist/utils/normalize-list-view.js +248 -6
  115. package/dist/utils/number-display.d.ts +70 -17
  116. package/dist/utils/number-display.js +34 -12
  117. package/dist/utils/object-aggregate-query.d.ts +113 -0
  118. package/dist/utils/object-aggregate-query.js +50 -0
  119. package/dist/utils/parent-scope.d.ts +123 -0
  120. package/dist/utils/parent-scope.js +140 -0
  121. package/dist/utils/predicate-fields.d.ts +62 -4
  122. package/dist/utils/predicate-fields.js +169 -4
  123. package/dist/utils/record-color.d.ts +75 -0
  124. package/dist/utils/record-color.js +65 -0
  125. package/dist/utils/record-source.d.ts +298 -0
  126. package/dist/utils/record-source.js +331 -0
  127. package/dist/utils/record-title.d.ts +148 -8
  128. package/dist/utils/record-title.js +220 -26
  129. package/dist/utils/reference-keys.d.ts +21 -22
  130. package/dist/utils/reference-keys.js +532 -29
  131. package/dist/utils/retired-field-types.d.ts +90 -0
  132. package/dist/utils/retired-field-types.js +124 -0
  133. package/dist/utils/sort-query.d.ts +128 -26
  134. package/dist/utils/sort-query.js +240 -13
  135. package/dist/utils/text-comparand.d.ts +92 -0
  136. package/dist/utils/text-comparand.js +99 -0
  137. package/dist/utils/unmaterialized-fields.d.ts +52 -0
  138. package/dist/utils/unmaterialized-fields.js +57 -0
  139. package/dist/utils/without-denied-fields.d.ts +49 -0
  140. package/dist/utils/without-denied-fields.js +52 -0
  141. package/dist/validation/index.d.ts +9 -4
  142. package/dist/validation/index.js +9 -4
  143. package/dist/validation/schema-validator.d.ts +1 -1
  144. package/dist/validation/schema-validator.js +305 -82
  145. package/dist/validation/server-owned-value.d.ts +62 -0
  146. package/dist/validation/server-owned-value.js +99 -0
  147. package/dist/validation/validators/object-validation-engine.d.ts +1 -1
  148. package/dist/validation/validators/object-validation-engine.js +14 -5
  149. package/package.json +8 -9
  150. package/dist/__benchmarks__/core.bench.d.ts +0 -8
  151. package/dist/__benchmarks__/core.bench.js +0 -53
  152. package/dist/data-scope/DataScopeManager.d.ts +0 -127
  153. package/dist/data-scope/DataScopeManager.js +0 -229
  154. package/dist/protocols/ResponsiveProtocol.d.ts +0 -73
  155. package/dist/protocols/ResponsiveProtocol.js +0 -158
  156. package/dist/validation/validation-engine.d.ts +0 -88
  157. package/dist/validation/validation-engine.js +0 -434
@@ -0,0 +1,99 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ /**
9
+ * The ONE client-side answer to "is this field's value the PRODUCER's to
10
+ * supply?" — the other half of {@link isMissingForRequired}.
11
+ *
12
+ * A `required` verdict is a question about two facts: is the value absent
13
+ * (`required-presence.ts`), and was the client ever supposed to provide it.
14
+ * This module owns the second one. Both live here in `@object-ui/core` because
15
+ * every layer that decides required-ness reads them: the form renderer
16
+ * (`resolveFieldRuleState`), the wizard's cross-step gate, and the
17
+ * create-form field builders in `@object-ui/plugin-form`.
18
+ *
19
+ * ## What makes a value server-owned
20
+ *
21
+ * A `defaultValue` may be a literal, or an *instruction* the server resolves
22
+ * per insert:
23
+ *
24
+ * - a runtime token — `'NOW()'` / `'current_user'`, the whole
25
+ * `DEFAULT_VALUE_TOKENS` family from `@objectstack/spec/data`
26
+ * - a CEL Expression envelope — `{ dialect: 'cel', source: 'today()' }`
27
+ *
28
+ * A CREATE form deliberately leaves such a control EMPTY and omits the key
29
+ * from the payload, because `ObjectQL.applyFieldDefaults` resolves a declared
30
+ * default only for a field that arrives absent or null (#4047 / #4068). The
31
+ * field is therefore not "missing" on that submit — it is server-owned, and
32
+ * nothing the client evaluates may declare it required (#4069 / #4085).
33
+ *
34
+ * ## Create only
35
+ *
36
+ * On an EDIT form the token was already resolved at insert. The control shows
37
+ * a persisted value, so blanking it is a real removal and `required` (static
38
+ * or conditional) enforces normally.
39
+ */
40
+ import { isRuntimeDefaultToken } from '@objectstack/spec/data';
41
+ /**
42
+ * Is `v` a CEL/template Expression envelope rather than a literal value?
43
+ *
44
+ * Same shape test the engine applies before handing a default to
45
+ * `ExpressionEngine` (`{ dialect, source }`), kept structural on purpose: the
46
+ * point is "the server evaluates this", which is true for every dialect.
47
+ */
48
+ function isExpressionEnvelope(v) {
49
+ return (typeof v === 'object' &&
50
+ v !== null &&
51
+ typeof v.dialect === 'string' &&
52
+ typeof v.source === 'string');
53
+ }
54
+ /**
55
+ * Is this declared `defaultValue` a RUNTIME INSTRUCTION the server resolves per
56
+ * insert, rather than a literal value?
57
+ *
58
+ * True for the `DEFAULT_VALUE_TOKENS` family (`'NOW()'` / `'current_user'`) and
59
+ * for CEL/template Expression envelopes. This is THE classifier for "the
60
+ * producer owns this field's create value", and every consumer reads THIS one
61
+ * — a second copy would be free to disagree about, say, a CEL envelope, and
62
+ * then a form would seed a field it also refuses to submit. Today's consumers:
63
+ *
64
+ * 1. seeding (#4047 / #4068) — such a default is not seeded, because putting
65
+ * the literal text `NOW()` into a datetime input and submitting it
66
+ * suppresses the very resolution the declaration asked for;
67
+ * 2. the create-mode static `required` rule (#4069) —
68
+ * `isRequiredInForm` in `@object-ui/plugin-form`;
69
+ * 3. the create-mode `requiredWhen` rule (#4085) —
70
+ * {@link isServerOwnedValue}, read by `resolveFieldRuleState`.
71
+ */
72
+ export function isRuntimeDefault(v) {
73
+ return isRuntimeDefaultToken(v) || isExpressionEnvelope(v);
74
+ }
75
+ /**
76
+ * Does the PRODUCER supply this field's value for the submit this form is
77
+ * about to make? (#4085)
78
+ *
79
+ * The single derivation of that fact, so the three call sites that feed
80
+ * `resolveFieldRuleState` cannot each answer "where does the declared default
81
+ * live" differently. It reads the runtime FormField's `field` slot — the
82
+ * resolved object-field metadata the object-bound builders stash there
83
+ * (`ObjectForm`, `sectionFields`, and the containers' no-sections paths), and
84
+ * the only spelling of a declared `defaultValue` that reaches the renderer.
85
+ * A hand-authored FormField carries no object metadata, so it is never
86
+ * server-owned and its rules are untouched.
87
+ *
88
+ * `isCreateForm` is the CALLER's fact, never inferred here: the form renderer
89
+ * reads it off `FormSchema.previousValues` (whose absence *is* the declared
90
+ * "this is an insert" signal, objectui#3484), while the wizard's step gate
91
+ * reads its own `mode`. An evaluator guessing from a `previous` argument would
92
+ * call an edit-mode caller that simply passes no `previous` a create form, and
93
+ * silently drop a `requiredWhen` the author meant to enforce.
94
+ */
95
+ export function isServerOwnedValue(field, isCreateForm) {
96
+ if (!isCreateForm)
97
+ return false;
98
+ return isRuntimeDefault(field?.field?.defaultValue);
99
+ }
@@ -186,7 +186,7 @@ export declare class ObjectValidationEngine {
186
186
  * - no `initialStates` declared → allow (legacy no-op)
187
187
  * - field absent from the write → allow (requiredness is not our job)
188
188
  * - value empty → allow (ditto)
189
- * - value ∉ initialStates → reject (the FSM entry point, #3165)
189
+ * - value ∉ initialStates → reject (the FSM entry point, objectstack-ai/objectstack#3165)
190
190
  *
191
191
  * UPDATE
192
192
  * - field absent from the write → allow (no transition to police)
@@ -53,7 +53,15 @@ function priorityOf(rule) {
53
53
  * Simple expression evaluator using a simple parser (no dynamic code execution)
54
54
  *
55
55
  * SECURITY: This implementation parses expressions into an AST and evaluates them
56
- * without using eval() or new Function(). It supports:
56
+ * without using eval() or new Function(). That is a remediation, not a style
57
+ * preference: an earlier revision compiled the predicate with
58
+ * `new Function(...contextKeys, "'use strict'; return (" + expression + ")")`,
59
+ * and CodeQL flagged it as "Unsafe code constructed from library input" —
60
+ * expressions reach this class from validation metadata, so that shape is a
61
+ * code-injection vector in any consumer that renders metadata it does not
62
+ * control. Never reintroduce eval(), new Function() or any other dynamic-code
63
+ * path here to buy expressiveness or speed; extend the parser, or inject a
64
+ * richer evaluator through the constructor (see NOT CEL below). Supports:
57
65
  * - Comparison operators: ==, !=, >, <, >=, <=
58
66
  * - Logical operators: &&, ||, !
59
67
  * - Property access: record.field, record['field']
@@ -72,7 +80,10 @@ function priorityOf(rule) {
72
80
  * pre-check agree with the server on richer predicates, pass a CEL-backed
73
81
  * `ValidationExpressionEvaluator` to the constructor.
74
82
  *
75
- * @see https://github.com/objectstack-ai/objectui/blob/main/SECURITY_FIX_SUMMARY.md
83
+ * The write-up this block used to link to (`SECURITY_FIX_SUMMARY.md`) was
84
+ * deleted with no successor; its load-bearing reasoning is inline above, and
85
+ * the original text remains readable at
86
+ * `git show ea72f1886^:SECURITY_FIX_SUMMARY.md`.
76
87
  */
77
88
  class SimpleExpressionEvaluator {
78
89
  evaluate(expression, context) {
@@ -129,13 +140,11 @@ class SimpleExpressionEvaluator {
129
140
  return leftVal === rightVal;
130
141
  case '==':
131
142
  // Use loose equality for backward compatibility with existing expressions
132
- // eslint-disable-next-line eqeqeq
133
143
  return leftVal == rightVal;
134
144
  case '!==':
135
145
  return leftVal !== rightVal;
136
146
  case '!=':
137
147
  // Use loose inequality for backward compatibility with existing expressions
138
- // eslint-disable-next-line eqeqeq
139
148
  return leftVal != rightVal;
140
149
  case '>': return leftVal > rightVal;
141
150
  case '<': return leftVal < rightVal;
@@ -386,7 +395,7 @@ export class ObjectValidationEngine {
386
395
  * - no `initialStates` declared → allow (legacy no-op)
387
396
  * - field absent from the write → allow (requiredness is not our job)
388
397
  * - value empty → allow (ditto)
389
- * - value ∉ initialStates → reject (the FSM entry point, #3165)
398
+ * - value ∉ initialStates → reject (the FSM entry point, objectstack-ai/objectstack#3165)
390
399
  *
391
400
  * UPDATE
392
401
  * - field absent from the write → allow (no transition to police)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@object-ui/core",
3
- "version": "17.5.0",
3
+ "version": "17.7.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "license": "MIT",
@@ -25,15 +25,14 @@
25
25
  }
26
26
  },
27
27
  "dependencies": {
28
- "@objectstack/formula": "^17.0.0-rc.6",
29
- "@objectstack/spec": "^17.0.0-rc.6",
30
- "lodash": "^4.18.1",
31
- "zod": "^4.4.3",
32
- "@object-ui/types": "17.5.0"
28
+ "@objectstack/formula": "^17.5.0",
29
+ "@objectstack/spec": "^17.6.0",
30
+ "@object-ui/types": "17.7.0"
33
31
  },
34
32
  "devDependencies": {
35
33
  "typescript": "^6.0.3",
36
- "vitest": "^4.1.10"
34
+ "vitest": "^4.1.10",
35
+ "@object-ui/test-support": "17.4.0"
37
36
  },
38
37
  "keywords": [
39
38
  "objectui",
@@ -60,8 +59,8 @@
60
59
  "LICENSE"
61
60
  ],
62
61
  "scripts": {
63
- "build": "tsc",
64
- "test": "vitest run",
62
+ "build": "tsc && node ../../scripts/check-dist-completeness.mjs",
63
+ "test": "vitest run --root ../.. packages/core/",
65
64
  "type-check": "tsc --noEmit && tsc -p tsconfig.test.json",
66
65
  "lint": "eslint ."
67
66
  }
@@ -1,8 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- export {};
@@ -1,53 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- /**
9
- * Performance benchmark suite for @object-ui/core.
10
- *
11
- * Part of Q1 2026 roadmap §1.4 Test Coverage Improvement.
12
- *
13
- * Run with: npx vitest bench packages/core/src/__benchmarks__/
14
- */
15
- import { bench, describe } from 'vitest';
16
- import { ExpressionEvaluator } from '@object-ui/core';
17
- import { ComponentRegistry } from '@object-ui/core';
18
- import { contrastRatio, meetsContrastLevel, hexToHSL } from '@object-ui/core';
19
- describe('ExpressionEvaluator performance', () => {
20
- const evaluator = new ExpressionEvaluator({ data: { name: 'Alice', age: 30, active: true } });
21
- bench('evaluate simple string', () => {
22
- evaluator.evaluate('Hello ${data.name}');
23
- });
24
- bench('evaluate 100 expressions', () => {
25
- for (let i = 0; i < 100; i++) {
26
- evaluator.evaluate('Hello ${data.name}');
27
- }
28
- });
29
- });
30
- describe('ComponentRegistry performance', () => {
31
- bench('get registered component', () => {
32
- ComponentRegistry.get('button');
33
- });
34
- bench('has check', () => {
35
- ComponentRegistry.has('button');
36
- });
37
- });
38
- describe('Theme utilities performance', () => {
39
- bench('hexToHSL conversion', () => {
40
- hexToHSL('#336699');
41
- });
42
- bench('contrastRatio calculation', () => {
43
- contrastRatio('#000000', '#ffffff');
44
- });
45
- bench('meetsContrastLevel check', () => {
46
- meetsContrastLevel('#000000', '#ffffff', 'AA');
47
- });
48
- bench('100 contrast checks', () => {
49
- for (let i = 0; i < 100; i++) {
50
- meetsContrastLevel('#336699', '#ffffff', 'AA');
51
- }
52
- });
53
- });
@@ -1,127 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- /**
9
- * @object-ui/core - DataScope Manager
10
- *
11
- * Runtime implementation of the DataContext interface for managing
12
- * named data scopes. Provides row-level data access control and
13
- * reactive data state management within the UI component tree.
14
- *
15
- * @module data-scope
16
- * @packageDocumentation
17
- */
18
- import type { DataScope, DataContext, DataSource } from '@object-ui/types';
19
- /**
20
- * Row-level filter for restricting data access within a scope
21
- */
22
- export interface RowLevelFilter {
23
- /** Field to filter on */
24
- field: string;
25
- /** Filter operator */
26
- operator: 'eq' | 'ne' | 'gt' | 'lt' | 'gte' | 'lte' | 'in' | 'nin' | 'contains';
27
- /** Filter value */
28
- value: any;
29
- }
30
- /**
31
- * Configuration for creating a data scope
32
- */
33
- export interface DataScopeConfig {
34
- /** Data source instance */
35
- dataSource?: DataSource;
36
- /** Initial data */
37
- data?: any;
38
- /** Row-level filters to apply */
39
- filters?: RowLevelFilter[];
40
- /** Whether this scope is read-only */
41
- readOnly?: boolean;
42
- }
43
- /**
44
- * DataScopeManager — Runtime implementation of DataContext.
45
- *
46
- * Manages named data scopes for the component tree, providing:
47
- * - Scope registration and lookup
48
- * - Row-level security via filters
49
- * - Data state management (data, loading, error)
50
- *
51
- * @example
52
- * ```ts
53
- * const manager = new DataScopeManager();
54
- * manager.registerScope('contacts', {
55
- * dataSource: myDataSource,
56
- * data: [],
57
- * });
58
- * const scope = manager.getScope('contacts');
59
- * ```
60
- */
61
- export declare class DataScopeManager implements DataContext {
62
- scopes: Record<string, DataScope>;
63
- private filters;
64
- private readOnlyScopes;
65
- private listeners;
66
- /**
67
- * Register a data scope
68
- */
69
- registerScope(name: string, scope: DataScope): void;
70
- /**
71
- * Register a data scope with configuration
72
- */
73
- registerScopeWithConfig(name: string, config: DataScopeConfig): void;
74
- /**
75
- * Get a data scope by name
76
- */
77
- getScope(name: string): DataScope | undefined;
78
- /**
79
- * Remove a data scope
80
- */
81
- removeScope(name: string): void;
82
- /**
83
- * Check if a scope is read-only
84
- */
85
- isReadOnly(name: string): boolean;
86
- /**
87
- * Get row-level filters for a scope
88
- */
89
- getFilters(name: string): RowLevelFilter[];
90
- /**
91
- * Set row-level filters for a scope
92
- */
93
- setFilters(name: string, filters: RowLevelFilter[]): void;
94
- /**
95
- * Apply row-level filters to a dataset
96
- */
97
- applyFilters(name: string, data: any[]): any[];
98
- /**
99
- * Update data in a scope
100
- */
101
- updateScopeData(name: string, data: any): void;
102
- /**
103
- * Update loading state for a scope
104
- */
105
- updateScopeLoading(name: string, loading: boolean): void;
106
- /**
107
- * Update error state for a scope
108
- */
109
- updateScopeError(name: string, error: Error | string | null): void;
110
- /**
111
- * Subscribe to scope changes
112
- */
113
- onScopeChange(name: string, listener: (scope: DataScope) => void): () => void;
114
- /**
115
- * Get all registered scope names
116
- */
117
- getScopeNames(): string[];
118
- /**
119
- * Clear all scopes
120
- */
121
- clear(): void;
122
- private notifyListeners;
123
- }
124
- /**
125
- * Default DataScopeManager instance
126
- */
127
- export declare const defaultDataScopeManager: DataScopeManager;
@@ -1,229 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- /**
9
- * DataScopeManager — Runtime implementation of DataContext.
10
- *
11
- * Manages named data scopes for the component tree, providing:
12
- * - Scope registration and lookup
13
- * - Row-level security via filters
14
- * - Data state management (data, loading, error)
15
- *
16
- * @example
17
- * ```ts
18
- * const manager = new DataScopeManager();
19
- * manager.registerScope('contacts', {
20
- * dataSource: myDataSource,
21
- * data: [],
22
- * });
23
- * const scope = manager.getScope('contacts');
24
- * ```
25
- */
26
- export class DataScopeManager {
27
- constructor() {
28
- Object.defineProperty(this, "scopes", {
29
- enumerable: true,
30
- configurable: true,
31
- writable: true,
32
- value: {}
33
- });
34
- Object.defineProperty(this, "filters", {
35
- enumerable: true,
36
- configurable: true,
37
- writable: true,
38
- value: {}
39
- });
40
- Object.defineProperty(this, "readOnlyScopes", {
41
- enumerable: true,
42
- configurable: true,
43
- writable: true,
44
- value: new Set()
45
- });
46
- Object.defineProperty(this, "listeners", {
47
- enumerable: true,
48
- configurable: true,
49
- writable: true,
50
- value: new Map()
51
- });
52
- }
53
- /**
54
- * Register a data scope
55
- */
56
- registerScope(name, scope) {
57
- this.scopes[name] = scope;
58
- this.notifyListeners(name, scope);
59
- }
60
- /**
61
- * Register a data scope with configuration
62
- */
63
- registerScopeWithConfig(name, config) {
64
- const scope = {
65
- dataSource: config.dataSource,
66
- data: config.data,
67
- loading: false,
68
- error: null,
69
- };
70
- if (config.filters) {
71
- this.filters[name] = config.filters;
72
- }
73
- if (config.readOnly) {
74
- this.readOnlyScopes.add(name);
75
- }
76
- this.scopes[name] = scope;
77
- this.notifyListeners(name, scope);
78
- }
79
- /**
80
- * Get a data scope by name
81
- */
82
- getScope(name) {
83
- return this.scopes[name];
84
- }
85
- /**
86
- * Remove a data scope
87
- */
88
- removeScope(name) {
89
- delete this.scopes[name];
90
- delete this.filters[name];
91
- this.readOnlyScopes.delete(name);
92
- this.listeners.delete(name);
93
- }
94
- /**
95
- * Check if a scope is read-only
96
- */
97
- isReadOnly(name) {
98
- return this.readOnlyScopes.has(name);
99
- }
100
- /**
101
- * Get row-level filters for a scope
102
- */
103
- getFilters(name) {
104
- return this.filters[name] || [];
105
- }
106
- /**
107
- * Set row-level filters for a scope
108
- */
109
- setFilters(name, filters) {
110
- this.filters[name] = filters;
111
- }
112
- /**
113
- * Apply row-level filters to a dataset
114
- */
115
- applyFilters(name, data) {
116
- const scopeFilters = this.filters[name];
117
- if (!scopeFilters || scopeFilters.length === 0) {
118
- return data;
119
- }
120
- return data.filter(row => {
121
- return scopeFilters.every(filter => {
122
- const fieldValue = row[filter.field];
123
- return evaluateFilter(fieldValue, filter.operator, filter.value);
124
- });
125
- });
126
- }
127
- /**
128
- * Update data in a scope
129
- */
130
- updateScopeData(name, data) {
131
- const scope = this.scopes[name];
132
- if (!scope)
133
- return;
134
- if (this.readOnlyScopes.has(name)) {
135
- throw new Error(`Cannot update read-only scope: ${name}`);
136
- }
137
- scope.data = data;
138
- this.notifyListeners(name, scope);
139
- }
140
- /**
141
- * Update loading state for a scope
142
- */
143
- updateScopeLoading(name, loading) {
144
- const scope = this.scopes[name];
145
- if (!scope)
146
- return;
147
- scope.loading = loading;
148
- this.notifyListeners(name, scope);
149
- }
150
- /**
151
- * Update error state for a scope
152
- */
153
- updateScopeError(name, error) {
154
- const scope = this.scopes[name];
155
- if (!scope)
156
- return;
157
- scope.error = error;
158
- this.notifyListeners(name, scope);
159
- }
160
- /**
161
- * Subscribe to scope changes
162
- */
163
- onScopeChange(name, listener) {
164
- if (!this.listeners.has(name)) {
165
- this.listeners.set(name, []);
166
- }
167
- this.listeners.get(name).push(listener);
168
- return () => {
169
- const arr = this.listeners.get(name);
170
- if (arr) {
171
- const idx = arr.indexOf(listener);
172
- if (idx >= 0)
173
- arr.splice(idx, 1);
174
- }
175
- };
176
- }
177
- /**
178
- * Get all registered scope names
179
- */
180
- getScopeNames() {
181
- return Object.keys(this.scopes);
182
- }
183
- /**
184
- * Clear all scopes
185
- */
186
- clear() {
187
- this.scopes = {};
188
- this.filters = {};
189
- this.readOnlyScopes.clear();
190
- this.listeners.clear();
191
- }
192
- notifyListeners(name, scope) {
193
- const arr = this.listeners.get(name);
194
- if (arr) {
195
- arr.forEach(listener => listener(scope));
196
- }
197
- }
198
- }
199
- /**
200
- * Evaluate a single filter condition against a field value
201
- */
202
- function evaluateFilter(fieldValue, operator, filterValue) {
203
- switch (operator) {
204
- case 'eq':
205
- return fieldValue === filterValue;
206
- case 'ne':
207
- return fieldValue !== filterValue;
208
- case 'gt':
209
- return fieldValue > filterValue;
210
- case 'lt':
211
- return fieldValue < filterValue;
212
- case 'gte':
213
- return fieldValue >= filterValue;
214
- case 'lte':
215
- return fieldValue <= filterValue;
216
- case 'in':
217
- return Array.isArray(filterValue) && filterValue.includes(fieldValue);
218
- case 'nin':
219
- return Array.isArray(filterValue) && !filterValue.includes(fieldValue);
220
- case 'contains':
221
- return typeof fieldValue === 'string' && fieldValue.includes(String(filterValue));
222
- default:
223
- return true;
224
- }
225
- }
226
- /**
227
- * Default DataScopeManager instance
228
- */
229
- export const defaultDataScopeManager = new DataScopeManager();
@@ -1,73 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- /**
9
- * @object-ui/core - Responsive Protocol Bridge
10
- *
11
- * Converts spec-aligned ResponsiveConfig schemas into Tailwind CSS
12
- * utility classes for visibility, grid columns, and ordering across
13
- * breakpoints. Also provides runtime width-based visibility checks.
14
- *
15
- * @module protocols/ResponsiveProtocol
16
- * @packageDocumentation
17
- */
18
- import type { SpecResponsiveConfig } from '@object-ui/types';
19
- /** Breakpoint name type matching Tailwind defaults. */
20
- export type BreakpointKey = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';
21
- /** Breakpoint minimum pixel widths aligned with Tailwind CSS defaults. */
22
- export declare const BREAKPOINT_VALUES: Record<BreakpointKey, number>;
23
- /** Fully resolved responsive configuration. */
24
- export interface ResolvedResponsiveConfig {
25
- breakpoint?: BreakpointKey;
26
- hiddenOn: BreakpointKey[];
27
- columns: Partial<Record<BreakpointKey, number>>;
28
- order: Partial<Record<BreakpointKey, number>>;
29
- }
30
- /**
31
- * Resolve a responsive configuration by applying defaults.
32
- *
33
- * @param config - SpecResponsiveConfig from the spec
34
- * @returns Fully resolved responsive configuration
35
- */
36
- export declare function resolveResponsiveConfig(config: SpecResponsiveConfig): ResolvedResponsiveConfig;
37
- /**
38
- * Generate Tailwind CSS classes for responsive visibility.
39
- *
40
- * If `breakpoint` is set, the element is hidden below that breakpoint
41
- * (e.g. breakpoint "md" → `['hidden', 'md:block']`).
42
- *
43
- * If `hiddenOn` contains breakpoints, the element is hidden at those
44
- * specific sizes (e.g. hiddenOn: ["sm", "lg"] → `['sm:hidden', 'md:block', 'lg:hidden', 'xl:block']`).
45
- *
46
- * @param config - SpecResponsiveConfig from the spec
47
- * @returns Array of Tailwind CSS class strings
48
- */
49
- export declare function getVisibilityClasses(config: SpecResponsiveConfig): string[];
50
- /**
51
- * Generate Tailwind grid-cols classes for responsive column layouts.
52
- *
53
- * @param config - SpecResponsiveConfig from the spec
54
- * @returns Array of Tailwind CSS grid column class strings
55
- */
56
- export declare function getColumnClasses(config: SpecResponsiveConfig): string[];
57
- /**
58
- * Generate Tailwind order utility classes for responsive ordering.
59
- *
60
- * @param config - SpecResponsiveConfig from the spec
61
- * @returns Array of Tailwind CSS order class strings
62
- */
63
- export declare function getOrderClasses(config: SpecResponsiveConfig): string[];
64
- /**
65
- * Determine whether a component should be hidden at a given viewport width.
66
- *
67
- * Checks both the minimum `breakpoint` threshold and the `hiddenOn` list.
68
- *
69
- * @param config - SpecResponsiveConfig from the spec
70
- * @param width - Current viewport width in pixels
71
- * @returns `true` if the component should be hidden at the given width
72
- */
73
- export declare function shouldHideAtBreakpoint(config: SpecResponsiveConfig, width: number): boolean;