@cratis/scene.engine 4.14.0 → 4.16.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/QueryBindingState.ts +43 -0
- package/QueryBindingTicket.ts +8 -0
- package/dist/cjs/QueryBindingState.js +38 -0
- package/dist/cjs/QueryBindingState.js.map +1 -0
- package/dist/cjs/editing/resolveEffectiveConfiguration.js +11 -0
- package/dist/cjs/editing/resolveEffectiveConfiguration.js.map +1 -1
- package/dist/cjs/editing/validateValue.js +17 -1
- package/dist/cjs/editing/validateValue.js.map +1 -1
- package/dist/cjs/forms/CommandFormLayoutKey.js +14 -0
- package/dist/cjs/forms/CommandFormLayoutKey.js.map +1 -0
- package/dist/cjs/forms/applyCommandFormLayoutKey.js +72 -0
- package/dist/cjs/forms/applyCommandFormLayoutKey.js.map +1 -0
- package/dist/cjs/forms/stackCommandFormLayout.js +37 -0
- package/dist/cjs/forms/stackCommandFormLayout.js.map +1 -0
- package/dist/cjs/index.js +15 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/nestBindingScope.js +26 -0
- package/dist/cjs/nestBindingScope.js.map +1 -0
- package/dist/cjs/removeComponentOutputs.js +19 -0
- package/dist/cjs/removeComponentOutputs.js.map +1 -0
- package/dist/cjs/resolveArgumentSource.js +36 -0
- package/dist/cjs/resolveArgumentSource.js.map +1 -0
- package/dist/cjs/resolveBindingExpression.js +12 -8
- package/dist/cjs/resolveBindingExpression.js.map +1 -1
- package/dist/esm/QueryBindingState.d.ts +10 -0
- package/dist/esm/QueryBindingState.d.ts.map +1 -0
- package/dist/esm/QueryBindingState.js +36 -0
- package/dist/esm/QueryBindingState.js.map +1 -0
- package/dist/esm/QueryBindingTicket.d.ts +5 -0
- package/dist/esm/QueryBindingTicket.d.ts.map +1 -0
- package/dist/esm/QueryBindingTicket.js +2 -0
- package/dist/esm/QueryBindingTicket.js.map +1 -0
- package/dist/esm/editing/resolveEffectiveConfiguration.d.ts.map +1 -1
- package/dist/esm/editing/resolveEffectiveConfiguration.js +11 -0
- package/dist/esm/editing/resolveEffectiveConfiguration.js.map +1 -1
- package/dist/esm/editing/validateValue.d.ts.map +1 -1
- package/dist/esm/editing/validateValue.js +18 -2
- package/dist/esm/editing/validateValue.js.map +1 -1
- package/dist/esm/forms/CommandFormLayoutKey.d.ts +7 -0
- package/dist/esm/forms/CommandFormLayoutKey.d.ts.map +1 -0
- package/dist/esm/forms/CommandFormLayoutKey.js +12 -0
- package/dist/esm/forms/CommandFormLayoutKey.js.map +1 -0
- package/dist/esm/forms/applyCommandFormLayoutKey.d.ts +5 -0
- package/dist/esm/forms/applyCommandFormLayoutKey.d.ts.map +1 -0
- package/dist/esm/forms/applyCommandFormLayoutKey.js +70 -0
- package/dist/esm/forms/applyCommandFormLayoutKey.js.map +1 -0
- package/dist/esm/forms/index.d.ts +3 -0
- package/dist/esm/forms/index.d.ts.map +1 -1
- package/dist/esm/forms/index.js +3 -0
- package/dist/esm/forms/index.js.map +1 -1
- package/dist/esm/forms/stackCommandFormLayout.d.ts +3 -0
- package/dist/esm/forms/stackCommandFormLayout.d.ts.map +1 -0
- package/dist/esm/forms/stackCommandFormLayout.js +35 -0
- package/dist/esm/forms/stackCommandFormLayout.js.map +1 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/nestBindingScope.d.ts +3 -0
- package/dist/esm/nestBindingScope.d.ts.map +1 -0
- package/dist/esm/nestBindingScope.js +24 -0
- package/dist/esm/nestBindingScope.js.map +1 -0
- package/dist/esm/removeComponentOutputs.d.ts +3 -0
- package/dist/esm/removeComponentOutputs.d.ts.map +1 -0
- package/dist/esm/removeComponentOutputs.js +17 -0
- package/dist/esm/removeComponentOutputs.js.map +1 -0
- package/dist/esm/resolveArgumentSource.d.ts +4 -0
- package/dist/esm/resolveArgumentSource.d.ts.map +1 -0
- package/dist/esm/resolveArgumentSource.js +33 -0
- package/dist/esm/resolveArgumentSource.js.map +1 -0
- package/dist/esm/resolveBindingExpression.d.ts.map +1 -1
- package/dist/esm/resolveBindingExpression.js +12 -8
- package/dist/esm/resolveBindingExpression.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/editing/resolveEffectiveConfiguration.ts +11 -0
- package/editing/validateValue.ts +21 -1
- package/forms/CommandFormLayoutKey.ts +10 -0
- package/forms/applyCommandFormLayoutKey.ts +47 -0
- package/forms/index.ts +3 -0
- package/forms/stackCommandFormLayout.ts +22 -0
- package/index.ts +5 -0
- package/nestBindingScope.ts +19 -0
- package/package.json +3 -3
- package/removeComponentOutputs.ts +15 -0
- package/resolveArgumentSource.ts +33 -0
- package/resolveBindingExpression.ts +14 -7
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var scene_model = require('@cratis/scene.model');
|
|
4
|
+
var resolveBindingExpression = require('./resolveBindingExpression.js');
|
|
5
|
+
|
|
6
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
7
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
8
|
+
/** The prefix of an argument source that reads another element's output. */ const componentArgumentSourcePrefix = 'component.';
|
|
9
|
+
/**
|
|
10
|
+
* Resolves where a command argument comes from, as an action's argument mapping writes it.
|
|
11
|
+
*
|
|
12
|
+
* `component.<id>.<output>` reads an output another element publishes - an input's `value`, a table's
|
|
13
|
+
* `selectedItem.id` - from the same output scope a `componentProperty` binding reads. Element ids may contain
|
|
14
|
+
* dots, so the longest id with outputs in scope wins: `component.order.lines.value` reads `value` of
|
|
15
|
+
* `order.lines` when that element exists. Any other source is a path in the data context. An empty source,
|
|
16
|
+
* or an element with no outputs in scope, resolves as absent.
|
|
17
|
+
*
|
|
18
|
+
* The C# engine (`ArgumentSources.Resolve`) behaves identically; both run `argument-source-fixtures.json`.
|
|
19
|
+
*/ function resolveArgumentSource(source, scope) {
|
|
20
|
+
if (!source) return undefined;
|
|
21
|
+
if (!source.startsWith(componentArgumentSourcePrefix)) return resolveBindingExpression.resolveBindingExpression({
|
|
22
|
+
path: source
|
|
23
|
+
}, scope);
|
|
24
|
+
const reference = source.substring(componentArgumentSourcePrefix.length);
|
|
25
|
+
const componentId = Object.keys(scope.componentOutputs ?? {}).filter((id)=>reference === id || reference.startsWith(`${id}.`)).sort((left, right)=>right.length - left.length)[0];
|
|
26
|
+
if (componentId === undefined) return undefined;
|
|
27
|
+
return resolveBindingExpression.resolveBindingExpression({
|
|
28
|
+
kind: scene_model.BindingSourceKind.ComponentProperty,
|
|
29
|
+
componentId,
|
|
30
|
+
path: reference.substring(componentId.length + 1)
|
|
31
|
+
}, scope);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.componentArgumentSourcePrefix = componentArgumentSourcePrefix;
|
|
35
|
+
exports.resolveArgumentSource = resolveArgumentSource;
|
|
36
|
+
//# sourceMappingURL=resolveArgumentSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveArgumentSource.js","sources":["../../resolveArgumentSource.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { BindingSourceKind } from '@cratis/scene.model';\nimport { BindingScope } from './BindingScope';\nimport { resolveBindingExpression } from './resolveBindingExpression';\n\n/** The prefix of an argument source that reads another element's output. */\nexport const componentArgumentSourcePrefix = 'component.';\n\n/**\n * Resolves where a command argument comes from, as an action's argument mapping writes it.\n *\n * `component.<id>.<output>` reads an output another element publishes - an input's `value`, a table's\n * `selectedItem.id` - from the same output scope a `componentProperty` binding reads. Element ids may contain\n * dots, so the longest id with outputs in scope wins: `component.order.lines.value` reads `value` of\n * `order.lines` when that element exists. Any other source is a path in the data context. An empty source,\n * or an element with no outputs in scope, resolves as absent.\n *\n * The C# engine (`ArgumentSources.Resolve`) behaves identically; both run `argument-source-fixtures.json`.\n */\nexport function resolveArgumentSource(source: string, scope: BindingScope): unknown {\n if (!source) return undefined;\n if (!source.startsWith(componentArgumentSourcePrefix)) return resolveBindingExpression({ path: source }, scope);\n\n const reference = source.substring(componentArgumentSourcePrefix.length);\n const componentId = Object.keys(scope.componentOutputs ?? {})\n .filter(id => reference === id || reference.startsWith(`${id}.`))\n .sort((left, right) => right.length - left.length)[0];\n if (componentId === undefined) return undefined;\n\n return resolveBindingExpression({ kind: BindingSourceKind.ComponentProperty, componentId, path: reference.substring(componentId.length + 1) }, scope);\n}\n"],"names":["componentArgumentSourcePrefix","resolveArgumentSource","source","scope","undefined","startsWith","resolveBindingExpression","path","reference","substring","length","componentId","Object","keys","componentOutputs","filter","id","sort","left","right","kind","BindingSourceKind","ComponentProperty"],"mappings":";;;;;AAAA;AACA;AAMA,6EACO,MAAMA,6BAAAA,GAAgC;AAE7C;;;;;;;;;;AAUC,IACM,SAASC,qBAAAA,CAAsBC,MAAc,EAAEC,KAAmB,EAAA;IACrE,IAAI,CAACD,QAAQ,OAAOE,SAAAA;AACpB,IAAA,IAAI,CAACF,MAAAA,CAAOG,UAAU,CAACL,6BAAAA,CAAAA,EAAgC,OAAOM,iDAAAA,CAAyB;QAAEC,IAAAA,EAAML;KAAO,EAAGC,KAAAA,CAAAA;AAEzG,IAAA,MAAMK,SAAAA,GAAYN,MAAAA,CAAOO,SAAS,CAACT,8BAA8BU,MAAM,CAAA;AACvE,IAAA,MAAMC,WAAAA,GAAcC,MAAAA,CAAOC,IAAI,CAACV,MAAMW,gBAAgB,IAAI,EAAC,CAAA,CACtDC,MAAM,CAACC,CAAAA,EAAAA,GAAMR,SAAAA,KAAcQ,MAAMR,SAAAA,CAAUH,UAAU,CAAC,CAAA,EAAGW,GAAG,CAAC,CAAC,CAAA,CAAA,CAC9DC,IAAI,CAAC,CAACC,IAAAA,EAAMC,KAAAA,GAAUA,KAAAA,CAAMT,MAAM,GAAGQ,IAAAA,CAAKR,MAAM,CAAC,CAAC,CAAA,CAAE;IACzD,IAAIC,WAAAA,KAAgBP,WAAW,OAAOA,SAAAA;AAEtC,IAAA,OAAOE,iDAAAA,CAAyB;AAAEc,QAAAA,IAAAA,EAAMC,8BAAkBC,iBAAiB;AAAEX,QAAAA,WAAAA;AAAaJ,QAAAA,IAAAA,EAAMC,SAAAA,CAAUC,SAAS,CAACE,WAAAA,CAAYD,MAAM,GAAG,CAAA;KAAG,EAAGP,KAAAA,CAAAA;AACnJ;;;"}
|
|
@@ -8,9 +8,9 @@ var scene_model = require('@cratis/scene.model');
|
|
|
8
8
|
* Resolves a typed binding against the shared runtime binding scope.
|
|
9
9
|
*/ function resolveBindingExpression(binding, scope) {
|
|
10
10
|
const kind = binding.kind ?? scene_model.BindingSourceKind.DataContext;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const value = readPath(
|
|
11
|
+
// A literal without a value is absent, whether the author wrote `null` or nothing: the C# model cannot
|
|
12
|
+
// tell the two apart, and both engines must resolve the same document to the same value.
|
|
13
|
+
const value = kind === scene_model.BindingSourceKind.Literal ? binding.value ?? undefined : readPath(sourceValue(binding, scope, kind), sourcePath(binding, kind));
|
|
14
14
|
if (value !== null && value !== undefined) return value;
|
|
15
15
|
if (binding.nullBehavior === scene_model.BindingNullBehavior.Preserve) return undefined;
|
|
16
16
|
if (binding.nullBehavior === scene_model.BindingNullBehavior.Clear) return null;
|
|
@@ -24,7 +24,7 @@ var scene_model = require('@cratis/scene.model');
|
|
|
24
24
|
function sourceValue(binding, scope, kind) {
|
|
25
25
|
switch(kind){
|
|
26
26
|
case scene_model.BindingSourceKind.DataContext:
|
|
27
|
-
return scope.dataContext;
|
|
27
|
+
return scope.dataContext ?? undefined;
|
|
28
28
|
case scene_model.BindingSourceKind.QueryResult:
|
|
29
29
|
return binding.query ? scope.queryResults?.[binding.query] : undefined;
|
|
30
30
|
case scene_model.BindingSourceKind.ComponentProperty:
|
|
@@ -37,12 +37,16 @@ function sourcePath(binding, kind) {
|
|
|
37
37
|
if (kind === scene_model.BindingSourceKind.ComponentProperty) return binding.componentPropertyPath ?? binding.path;
|
|
38
38
|
return binding.path;
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Reads a dotted path. Only own properties and array indexes are read - never inherited members such as
|
|
42
|
+
* `constructor` - and anything that is not an object or array ends the walk, so the C# engine can follow
|
|
43
|
+
* exactly the same rule over JSON.
|
|
44
|
+
*/ function readPath(source, path) {
|
|
41
45
|
if (!path) return source;
|
|
42
46
|
return path.split('.').reduce((current, segment)=>{
|
|
43
|
-
if (current === null || current === undefined) return undefined;
|
|
44
|
-
if (
|
|
45
|
-
return current[segment];
|
|
47
|
+
if (current === null || current === undefined || typeof current !== 'object') return undefined;
|
|
48
|
+
if (Array.isArray(current)) return /^(0|[1-9][0-9]*)$/.test(segment) ? current[Number(segment)] : undefined;
|
|
49
|
+
return Object.hasOwn(current, segment) ? current[segment] : undefined;
|
|
46
50
|
}, source);
|
|
47
51
|
}
|
|
48
52
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveBindingExpression.js","sources":["../../resolveBindingExpression.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { BindingExpression, BindingNullBehavior, BindingSourceKind } from '@cratis/scene.model';\nimport { BindingScope } from './BindingScope';\n\n/**\n * Resolves a typed binding against the shared runtime binding scope.\n */\nexport function resolveBindingExpression(binding: BindingExpression, scope: BindingScope): unknown {\n const kind = binding.kind ?? BindingSourceKind.DataContext;\n
|
|
1
|
+
{"version":3,"file":"resolveBindingExpression.js","sources":["../../resolveBindingExpression.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { BindingExpression, BindingNullBehavior, BindingSourceKind } from '@cratis/scene.model';\nimport { BindingScope } from './BindingScope';\n\n/**\n * Resolves a typed binding against the shared runtime binding scope.\n */\nexport function resolveBindingExpression(binding: BindingExpression, scope: BindingScope): unknown {\n const kind = binding.kind ?? BindingSourceKind.DataContext;\n\n // A literal without a value is absent, whether the author wrote `null` or nothing: the C# model cannot\n // tell the two apart, and both engines must resolve the same document to the same value.\n const value = kind === BindingSourceKind.Literal\n ? binding.value ?? undefined\n : readPath(sourceValue(binding, scope, kind), sourcePath(binding, kind));\n if (value !== null && value !== undefined) return value;\n\n if (binding.nullBehavior === BindingNullBehavior.Preserve) return undefined;\n if (binding.nullBehavior === BindingNullBehavior.Clear) return null;\n return value;\n}\n\n/**\n * Creates a legacy resolver function from a binding scope.\n */\nexport function createBindingResolver(scope: BindingScope): (binding: BindingExpression) => unknown {\n return binding => resolveBindingExpression(binding, scope);\n}\n\nfunction sourceValue(binding: BindingExpression, scope: BindingScope, kind: BindingSourceKind): unknown {\n switch (kind) {\n case BindingSourceKind.DataContext:\n return scope.dataContext ?? undefined;\n case BindingSourceKind.QueryResult:\n return binding.query ? scope.queryResults?.[binding.query] : undefined;\n case BindingSourceKind.ComponentProperty:\n return binding.componentId ? scope.componentOutputs?.[binding.componentId] : undefined;\n case BindingSourceKind.Literal:\n return binding.value;\n }\n}\n\nfunction sourcePath(binding: BindingExpression, kind: BindingSourceKind): string {\n if (kind === BindingSourceKind.ComponentProperty) return binding.componentPropertyPath ?? binding.path;\n return binding.path;\n}\n\n/**\n * Reads a dotted path. Only own properties and array indexes are read - never inherited members such as\n * `constructor` - and anything that is not an object or array ends the walk, so the C# engine can follow\n * exactly the same rule over JSON.\n */\nfunction readPath(source: unknown, path: string): unknown {\n if (!path) return source;\n return path.split('.').reduce<unknown>((current, segment) => {\n if (current === null || current === undefined || typeof current !== 'object') return undefined;\n if (Array.isArray(current)) return /^(0|[1-9][0-9]*)$/.test(segment) ? current[Number(segment)] : undefined;\n return Object.hasOwn(current, segment) ? (current as Record<string, unknown>)[segment] : undefined;\n }, source);\n}\n"],"names":["resolveBindingExpression","binding","scope","kind","BindingSourceKind","DataContext","value","Literal","undefined","readPath","sourceValue","sourcePath","nullBehavior","BindingNullBehavior","Preserve","Clear","createBindingResolver","dataContext","QueryResult","query","queryResults","ComponentProperty","componentId","componentOutputs","componentPropertyPath","path","source","split","reduce","current","segment","Array","isArray","test","Number","Object","hasOwn"],"mappings":";;;;AAAA;AACA;AAKA;;AAEC,IACM,SAASA,wBAAAA,CAAyBC,OAA0B,EAAEC,KAAmB,EAAA;AACpF,IAAA,MAAMC,IAAAA,GAAOF,OAAAA,CAAQE,IAAI,IAAIC,8BAAkBC,WAAW;;;AAI1D,IAAA,MAAMC,KAAAA,GAAQH,IAAAA,KAASC,6BAAAA,CAAkBG,OAAO,GAC1CN,OAAAA,CAAQK,KAAK,IAAIE,SAAAA,GACjBC,SAASC,WAAAA,CAAYT,OAAAA,EAASC,KAAAA,EAAOC,IAAAA,CAAAA,EAAOQ,WAAWV,OAAAA,EAASE,IAAAA,CAAAA,CAAAA;AACtE,IAAA,IAAIG,KAAAA,KAAU,IAAA,IAAQA,KAAAA,KAAUE,SAAAA,EAAW,OAAOF,KAAAA;AAElD,IAAA,IAAIL,QAAQW,YAAY,KAAKC,+BAAAA,CAAoBC,QAAQ,EAAE,OAAON,SAAAA;AAClE,IAAA,IAAIP,QAAQW,YAAY,KAAKC,+BAAAA,CAAoBE,KAAK,EAAE,OAAO,IAAA;IAC/D,OAAOT,KAAAA;AACX;AAEA;;IAGO,SAASU,qBAAAA,CAAsBd,KAAmB,EAAA;IACrD,OAAOD,CAAAA,OAAAA,GAAWD,wBAAAA,CAAyBC,OAAAA,EAASC,KAAAA,CAAAA;AACxD;AAEA,SAASQ,WAAAA,CAAYT,OAA0B,EAAEC,KAAmB,EAAEC,IAAuB,EAAA;IACzF,OAAQA,IAAAA;AACJ,QAAA,KAAKC,8BAAkBC,WAAW;YAC9B,OAAOH,KAAAA,CAAMe,WAAW,IAAIT,SAAAA;AAChC,QAAA,KAAKJ,8BAAkBc,WAAW;YAC9B,OAAOjB,OAAAA,CAAQkB,KAAK,GAAGjB,KAAAA,CAAMkB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|
|
3
|
+
export declare class QueryBindingState {
|
|
4
|
+
#private;
|
|
5
|
+
begin(query: string): QueryBindingTicket;
|
|
6
|
+
complete(ticket: QueryBindingTicket, result: unknown): boolean;
|
|
7
|
+
clear(query: string): void;
|
|
8
|
+
get queryResults(): NonNullable<BindingScope['queryResults']>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=QueryBindingState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryBindingState.d.ts","sourceRoot":"","sources":["../../QueryBindingState.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAU1D,qBAAa,iBAAiB;;IAK1B,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,kBAAkB,CAIvC;IAGD,QAAQ,CAAC,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAI7D;IAGD,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAGzB;IAGD,IAAI,YAAY,IAAI,WAAW,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,CAE5D;CACJ"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
/**
|
|
4
|
+
* Keeps the results of bound queries as their arguments change. Every rebind starts a new generation; a
|
|
5
|
+
* result is accepted only for the latest generation of its query, so a slow answer for a previous
|
|
6
|
+
* selection is discarded instead of overwriting the current one. Clearing a query - its arguments became
|
|
7
|
+
* unavailable, or its element left the tree - removes the result and invalidates any run in flight.
|
|
8
|
+
*
|
|
9
|
+
* The C# engine (`QueryBindingState`) behaves identically; both run `binding-resolution-fixtures.json`.
|
|
10
|
+
*/ class QueryBindingState {
|
|
11
|
+
#generations = new Map();
|
|
12
|
+
#results = new Map();
|
|
13
|
+
/** Starts a run of a query with new arguments, invalidating every earlier run of that query. */ begin(query) {
|
|
14
|
+
const generation = (this.#generations.get(query) ?? 0) + 1;
|
|
15
|
+
this.#generations.set(query, generation);
|
|
16
|
+
return {
|
|
17
|
+
query,
|
|
18
|
+
generation
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** Records a run's result. Returns false, and keeps the current result, when the run is stale. */ complete(ticket, result) {
|
|
22
|
+
if (this.#generations.get(ticket.query) !== ticket.generation) return false;
|
|
23
|
+
this.#results.set(ticket.query, result);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
/** Removes a query's result and invalidates any run still in flight. */ clear(query) {
|
|
27
|
+
this.#generations.set(query, (this.#generations.get(query) ?? 0) + 1);
|
|
28
|
+
this.#results.delete(query);
|
|
29
|
+
}
|
|
30
|
+
/** The accepted results, as the query results of a binding scope. */ get queryResults() {
|
|
31
|
+
return Object.fromEntries(this.#results);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { QueryBindingState };
|
|
36
|
+
//# sourceMappingURL=QueryBindingState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryBindingState.js","sources":["../../QueryBindingState.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { BindingScope } from './BindingScope';\nimport { QueryBindingTicket } from './QueryBindingTicket';\n\n/**\n * Keeps the results of bound queries as their arguments change. Every rebind starts a new generation; a\n * result is accepted only for the latest generation of its query, so a slow answer for a previous\n * selection is discarded instead of overwriting the current one. Clearing a query - its arguments became\n * unavailable, or its element left the tree - removes the result and invalidates any run in flight.\n *\n * The C# engine (`QueryBindingState`) behaves identically; both run `binding-resolution-fixtures.json`.\n */\nexport class QueryBindingState {\n readonly #generations = new Map<string, number>();\n readonly #results = new Map<string, unknown>();\n\n /** Starts a run of a query with new arguments, invalidating every earlier run of that query. */\n begin(query: string): QueryBindingTicket {\n const generation = (this.#generations.get(query) ?? 0) + 1;\n this.#generations.set(query, generation);\n return { query, generation };\n }\n\n /** Records a run's result. Returns false, and keeps the current result, when the run is stale. */\n complete(ticket: QueryBindingTicket, result: unknown): boolean {\n if (this.#generations.get(ticket.query) !== ticket.generation) return false;\n this.#results.set(ticket.query, result);\n return true;\n }\n\n /** Removes a query's result and invalidates any run still in flight. */\n clear(query: string): void {\n this.#generations.set(query, (this.#generations.get(query) ?? 0) + 1);\n this.#results.delete(query);\n }\n\n /** The accepted results, as the query results of a binding scope. */\n get queryResults(): NonNullable<BindingScope['queryResults']> {\n return Object.fromEntries(this.#results);\n }\n}\n"],"names":["QueryBindingState","Map","begin","query","generation","get","set","complete","ticket","result","clear","delete","queryResults","Object","fromEntries"],"mappings":"AAAA;AACA;AAKA;;;;;;;AAOC,IACM,MAAMA,iBAAAA,CAAAA;IACA,YAAY,GAAG,IAAIC,GAAAA,EAAAA;IACnB,QAAQ,GAAG,IAAIA,GAAAA,EAAAA;qGAGxBC,KAAAA,CAAMC,KAAa,EAAsB;AACrC,QAAA,MAAMC,UAAAA,GAAc,CAAA,IAAI,CAAC,YAAY,CAACC,GAAG,CAACF,KAAAA,CAAAA,IAAU,CAAA,IAAK,CAAA;AACzD,QAAA,IAAI,CAAC,YAAY,CAACG,GAAG,CAACH,KAAAA,EAAOC,UAAAA,CAAAA;QAC7B,OAAO;AAAED,YAAAA,KAAAA;AAAOC,YAAAA;AAAW,SAAA;AAC/B,IAAA;AAEA,uGACAG,QAAAA,CAASC,MAA0B,EAAEC,MAAe,EAAW;AAC3D,QAAA,IAAI,IAAI,CAAC,YAAY,CAACJ,GAAG,CAACG,MAAAA,CAAOL,KAAK,CAAA,KAAMK,MAAAA,CAAOJ,UAAU,EAAE,OAAO,KAAA;QACtE,IAAI,CAAC,QAAQ,CAACE,GAAG,CAACE,MAAAA,CAAOL,KAAK,EAAEM,MAAAA,CAAAA;QAChC,OAAO,IAAA;AACX,IAAA;6EAGAC,KAAAA,CAAMP,KAAa,EAAQ;AACvB,QAAA,IAAI,CAAC,YAAY,CAACG,GAAG,CAACH,OAAO,CAAC,IAAI,CAAC,YAAY,CAACE,GAAG,CAACF,KAAAA,CAAAA,IAAU,CAAA,IAAK,CAAA,CAAA;AACnE,QAAA,IAAI,CAAC,QAAQ,CAACQ,MAAM,CAACR,KAAAA,CAAAA;AACzB,IAAA;0EAGA,IAAIS,YAAAA,GAA0D;AAC1D,QAAA,OAAOC,OAAOC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAA;AAC3C,IAAA;AACJ;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryBindingTicket.d.ts","sourceRoot":"","sources":["../../QueryBindingTicket.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,kBAAkB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryBindingTicket.js","sourceRoot":"","sources":["../../QueryBindingTicket.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveEffectiveConfiguration.d.ts","sourceRoot":"","sources":["../../../editing/resolveEffectiveConfiguration.ts"],"names":[],"mappings":"AAGA,OAAO,EAEH,sBAAsB,EAA0B,oBAAoB,EACvE,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAA2B,MAAM,qBAAqB,CAAC;AAIjF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAoGhD,wBAAgB,6BAA6B,CACzC,aAAa,EAAE,aAAa,EAC5B,qBAAqB,EAAE,oBAAoB,EAAE,EAC7C,OAAO,EAAE,iBAAiB,GAC3B,sBAAsB,
|
|
1
|
+
{"version":3,"file":"resolveEffectiveConfiguration.d.ts","sourceRoot":"","sources":["../../../editing/resolveEffectiveConfiguration.ts"],"names":[],"mappings":"AAGA,OAAO,EAEH,sBAAsB,EAA0B,oBAAoB,EACvE,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAA2B,MAAM,qBAAqB,CAAC;AAIjF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAoGhD,wBAAgB,6BAA6B,CACzC,aAAa,EAAE,aAAa,EAC5B,qBAAqB,EAAE,oBAAoB,EAAE,EAC7C,OAAO,EAAE,iBAAiB,GAC3B,sBAAsB,CAiGxB"}
|
|
@@ -156,6 +156,17 @@ function collectionValue(grant, matching, instance, items, diagnostics) {
|
|
|
156
156
|
scalarValue(effectiveGrant, matching, instance, current, diagnostics);
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
+
const maximumItems = grant.descriptor.constraints?.maximumItems;
|
|
160
|
+
if (isCollection && maximumItems !== undefined && items.length > maximumItems) {
|
|
161
|
+
// Saved items that no longer fit - the owner lowered the limit after they were added - are left out of
|
|
162
|
+
// the result in order and kept in the saved data, like any other saved value that no longer fits.
|
|
163
|
+
const dropped = items.splice(maximumItems);
|
|
164
|
+
diagnostics.push(errorDiagnostic(DiagnosticCode.ContributionTypeMismatch, `'${grant.path}' on '${grant.component}' allows at most ${maximumItems} items; ${dropped.map((item)=>`'${item.id}'`).join(', ')} ${dropped.length === 1 ? 'is' : 'are'} ignored and kept.`, {
|
|
165
|
+
instance: current.contributedBy ?? owner.instance,
|
|
166
|
+
component: grant.component,
|
|
167
|
+
path: grant.path
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
159
170
|
if (isCollection) {
|
|
160
171
|
current.items = items;
|
|
161
172
|
current.inheritedValue = baseItems.map(toFlatItem);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveEffectiveConfiguration.js","sources":["../../../editing/resolveEffectiveConfiguration.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport {\n CollectionOperation, DiagnosticCode, EffectiveCollectionItem, EffectiveComponentConfiguration,\n EffectiveConfiguration, EffectivePropertyValue, InstanceContribution, PropertyValueType, SceneDiagnostic, ValueSource,\n} from '@cratis/scene.model';\nimport { DescriptorCatalog, findComponentDescriptor } from './DescriptorCatalog';\nimport { errorDiagnostic } from './diagnostics';\nimport { computeExposureGrants, ExposureGrant, grantKey } from './exposureGrants';\nimport { cloneData, getValueAtPath, setValueAtPath } from './pathAccess';\nimport { TemplateChain } from './TemplateChain';\nimport { validateItemValues, validateValue } from './validateValue';\n\n/**\n * Splits a flat collection item as it is stored on an element - `{ id, label, ... }` - into its id and fields.\n */\nfunction toEffectiveItem(item: unknown, index: number): EffectiveCollectionItem {\n const { id, ...values } = (item !== null && typeof item === 'object' ? item : {}) as Record<string, unknown>;\n return { id: typeof id === 'string' && id.length > 0 ? id : `owner-${index}`, values, origin: 'owner', fixed: true };\n}\n\nfunction toFlatItem(item: EffectiveCollectionItem): Record<string, unknown> {\n return { id: item.id, ...item.values };\n}\n\nfunction scalarValue(grant: ExposureGrant, matching: InstanceContribution[], instance: string, current: EffectivePropertyValue, diagnostics: SceneDiagnostic[]): void {\n for (const contribution of matching) {\n const problem = contribution.value === undefined ? 'a value is required' : validateValue(grant.descriptor, contribution.value);\n if (problem) {\n diagnostics.push(errorDiagnostic(\n DiagnosticCode.ContributionTypeMismatch,\n `The saved value of '${grant.path}' set by '${instance}' is ignored: ${problem}. It is kept, and applies again when it fits.`,\n { instance, component: grant.component, path: grant.path }));\n continue;\n }\n\n current.value = contribution.value;\n current.source = ValueSource.Instance;\n current.contributedBy = instance;\n }\n}\n\nfunction collectionValue(grant: ExposureGrant, matching: InstanceContribution[], instance: string, items: EffectiveCollectionItem[], diagnostics: SceneDiagnostic[]): boolean {\n let contributed = false;\n\n for (const contribution of matching) {\n const context = { instance, component: grant.component, path: grant.path };\n if (contribution.items === undefined) {\n diagnostics.push(errorDiagnostic(DiagnosticCode.ContributionTypeMismatch, `The saved value of '${grant.path}' set by '${instance}' is ignored: a collection takes items.`, context));\n continue;\n }\n\n if (contribution.items.length > 0 && !grant.operations.includes(CollectionOperation.Add)) {\n diagnostics.push(errorDiagnostic(\n DiagnosticCode.ContributionOperationNotPermitted,\n `'${instance}' has items in '${grant.path}', but adding items is not exposed. They are ignored and kept.`,\n context));\n continue;\n }\n\n for (const item of contribution.items) {\n const itemContext = { ...context, itemId: item.id };\n if (items.some(existing => existing.id === item.id)) {\n diagnostics.push(errorDiagnostic(DiagnosticCode.DuplicateCollectionItem, `The item id '${item.id}' in '${grant.path}' is already used.`, itemContext));\n continue;\n }\n\n const values: Record<string, unknown> = {};\n for (const [field, value] of Object.entries(item.values)) {\n if (grant.editableFields !== undefined && !grant.editableFields.includes(field)) {\n diagnostics.push(errorDiagnostic(DiagnosticCode.ContributionOperationNotPermitted, `The field '${field}' of '${grant.path}' is not exposed for editing.`, itemContext));\n continue;\n }\n\n const problem = validateItemValues(grant.descriptor.item, { [field]: value }).find(candidate => candidate.field === field);\n if (problem) {\n diagnostics.push(errorDiagnostic(\n problem.problem.startsWith('is not a field') ? DiagnosticCode.UnknownCollectionField : DiagnosticCode.ContributionTypeMismatch,\n `The field '${field}' of an item in '${grant.path}' is ignored: ${problem.problem}.`,\n itemContext));\n continue;\n }\n\n values[field] = value;\n }\n\n items.push({ id: item.id, values, origin: instance, fixed: false });\n contributed = true;\n }\n }\n\n return contributed;\n}\n\n/**\n * Resolves what every configurable component in a template chain is worth: the owner's own values, with each\n * instance's contributions applied in nesting order.\n *\n * This is the one merge. The editor shows its result and the runtime renders from it, so what an author sees is\n * what Play renders. Order is fixed: the owner's value first, then each level from the outermost inwards, so a\n * later level wins a scalar and appends to a collection after the earlier ones.\n *\n * Nothing in the persisted data is changed. A contribution that cannot apply - the exposure was withdrawn, the\n * property's type changed, the component is gone - is reported in `diagnostics` and left out of the result, and\n * stays in `instanceContributions`, so restoring the exposure brings its value back.\n *\n * @param templateChain The nesting, from {@link resolveTemplateChain} or built by hand.\n * @param instanceContributions What each instance has set.\n * @param catalog The descriptors saying what each component supports.\n */\nexport function resolveEffectiveConfiguration(\n templateChain: TemplateChain,\n instanceContributions: InstanceContribution[],\n catalog: DescriptorCatalog,\n): EffectiveConfiguration {\n const grants = computeExposureGrants(templateChain, catalog);\n const diagnostics: SceneDiagnostic[] = [...templateChain.diagnostics, ...grants.diagnostics];\n const handled = new Set<InstanceContribution>();\n const components = new Map<string, EffectiveComponentConfiguration>();\n\n for (const grant of grants.exposed) {\n const owner = templateChain.levels[grant.ownerLevel];\n const element = owner.elements.find(candidate => candidate.id === grant.component)!;\n\n let configuration = components.get(grant.component);\n if (!configuration) {\n configuration = { component: grant.component, owner: owner.owner, properties: cloneData(element.properties), values: [] };\n components.set(grant.component, configuration);\n }\n\n const stored = getValueAtPath(element.properties, grant.path);\n const base = stored === undefined ? cloneData(grant.descriptor.default) : cloneData(stored);\n const isCollection = grant.descriptor.valueType === PropertyValueType.Collection;\n const baseItems = isCollection && Array.isArray(base) ? base.map(toEffectiveItem) : [];\n const items = [...baseItems];\n\n const current: EffectivePropertyValue = {\n path: grant.path,\n value: base,\n source: stored === undefined ? ValueSource.Default : ValueSource.Local,\n inheritedValue: base,\n };\n let contributed = false;\n\n for (let index = grant.ownerLevel + 1; index < templateChain.levels.length; index++) {\n const instance = templateChain.levels[index].instance;\n if (!grants.byInstance.get(instance)?.has(grantKey(grant.component, grant.path))) continue;\n\n const effectiveGrant = grants.byInstance.get(instance)!.get(grantKey(grant.component, grant.path))!;\n const matching = instanceContributions.filter(contribution =>\n contribution.instance === instance && contribution.component === grant.component && contribution.path === grant.path);\n for (const contribution of matching) handled.add(contribution);\n\n if (isCollection) {\n if (collectionValue(effectiveGrant, matching, instance, items, diagnostics)) {\n contributed = true;\n current.contributedBy = instance;\n }\n } else {\n scalarValue(effectiveGrant, matching, instance, current, diagnostics);\n }\n }\n\n if (isCollection) {\n current.items = items;\n current.inheritedValue = baseItems.map(toFlatItem);\n current.value = items.map(toFlatItem);\n if (contributed) current.source = ValueSource.Instance;\n }\n\n if (current.value !== undefined) setValueAtPath(configuration.properties, grant.path, current.value);\n configuration.values.push(current);\n }\n\n const levelOf = new Map(templateChain.levels.map((chainLevel, index) => [chainLevel.instance, index]));\n for (const contribution of instanceContributions) {\n const contributorLevel = levelOf.get(contribution.instance);\n if (contributorLevel === undefined || handled.has(contribution)) continue;\n\n const context = { instance: contribution.instance, component: contribution.component, path: contribution.path };\n const owner = templateChain.levels.slice(0, contributorLevel).find(chainLevel => chainLevel.elements.some(element => element.id === contribution.component));\n if (!owner) {\n diagnostics.push(errorDiagnostic(\n DiagnosticCode.ContributionTargetMissing,\n `'${contribution.instance}' has saved values for '${contribution.component}', which is not in any layout or template above it. They are kept.`,\n context));\n } else if (!findComponentDescriptor(catalog, owner.elements.find(element => element.id === contribution.component)!.componentName)) {\n diagnostics.push(errorDiagnostic(\n DiagnosticCode.MissingComponentDescriptor,\n `'${contribution.instance}' has saved values for '${contribution.component}', but nothing describes that component any more. They are kept.`,\n context));\n } else {\n diagnostics.push(errorDiagnostic(\n DiagnosticCode.ContributionNotExposed,\n `'${contribution.instance}' has a saved value for '${contribution.path}' on '${contribution.component}', which is not exposed to it. It is ignored and kept.`,\n context));\n }\n }\n\n return { components: [...components.values()], diagnostics };\n}\n"],"names":["toEffectiveItem","item","index","id","values","length","origin","fixed","toFlatItem","scalarValue","grant","matching","instance","current","diagnostics","contribution","problem","value","undefined","validateValue","descriptor","push","errorDiagnostic","DiagnosticCode","ContributionTypeMismatch","path","component","source","ValueSource","Instance","contributedBy","collectionValue","items","contributed","context","operations","includes","CollectionOperation","Add","ContributionOperationNotPermitted","itemContext","itemId","some","existing","DuplicateCollectionItem","field","Object","entries","editableFields","validateItemValues","find","candidate","startsWith","UnknownCollectionField","resolveEffectiveConfiguration","templateChain","instanceContributions","catalog","grants","computeExposureGrants","handled","Set","components","Map","exposed","owner","levels","ownerLevel","element","elements","configuration","get","properties","cloneData","set","stored","getValueAtPath","base","default","isCollection","valueType","PropertyValueType","Collection","baseItems","Array","isArray","map","Default","Local","inheritedValue","byInstance","has","grantKey","effectiveGrant","filter","add","setValueAtPath","levelOf","chainLevel","contributorLevel","slice","ContributionTargetMissing","findComponentDescriptor","componentName","MissingComponentDescriptor","ContributionNotExposed"],"mappings":";;;;;;;AAAA;AACA;AAaA;;AAEC,IACD,SAASA,eAAAA,CAAgBC,IAAa,EAAEC,KAAa,EAAA;AACjD,IAAA,MAAM,EAAEC,EAAE,EAAE,GAAGC,MAAAA,EAAQ,GAAIH,IAAAA,KAAS,IAAA,IAAQ,OAAOA,IAAAA,KAAS,QAAA,GAAWA,IAAAA,GAAO,EAAC;IAC/E,OAAO;QAAEE,EAAAA,EAAI,OAAOA,EAAAA,KAAO,QAAA,IAAYA,EAAAA,CAAGE,MAAM,GAAG,CAAA,GAAIF,EAAAA,GAAK,CAAC,MAAM,EAAED,KAAAA,CAAAA,CAAO;AAAEE,QAAAA,MAAAA;QAAQE,MAAAA,EAAQ,OAAA;QAASC,KAAAA,EAAO;AAAK,KAAA;AACvH;AAEA,SAASC,WAAWP,IAA6B,EAAA;IAC7C,OAAO;AAAEE,QAAAA,EAAAA,EAAIF,KAAKE,EAAE;AAAE,QAAA,GAAGF,KAAKG;AAAO,KAAA;AACzC;AAEA,SAASK,WAAAA,CAAYC,KAAoB,EAAEC,QAAgC,EAAEC,QAAgB,EAAEC,OAA+B,EAAEC,WAA8B,EAAA;IAC1J,KAAK,MAAMC,gBAAgBJ,QAAAA,CAAU;QACjC,MAAMK,OAAAA,GAAUD,YAAAA,CAAaE,KAAK,KAAKC,SAAAA,GAAY,qBAAA,GAAwBC,aAAAA,CAAcT,KAAAA,CAAMU,UAAU,EAAEL,YAAAA,CAAaE,KAAK,CAAA;AAC7H,QAAA,IAAID,OAAAA,EAAS;YACTF,WAAAA,CAAYO,IAAI,CAACC,eAAAA,CACbC,cAAAA,CAAeC,wBAAwB,EACvC,CAAC,oBAAoB,EAAEd,KAAAA,CAAMe,IAAI,CAA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EG,YAAAA,CAAaW,SAAS,CAAC,gEAAgE,CAAC,EAC5IQ,OAAAA,CAAAA,CAAAA;QACR,CAAA,MAAO;YACHpB,WAAAA,CAAYO,IAAI,CAACC,eAAAA,CACbC,cAAAA,CAAekF,sBAAsB,EACrC,CAAC,CAAC,EAAE1F,YAAAA,CAAaH,QAAQ,CAAC,yBAAyB,EAAEG,YAAAA,CAAaU,IAAI,CAAC,MAAM,EAAEV,aAAaW,SAAS,CAAC,sDAAsD,CAAC,EAC7JQ,OAAAA,CAAAA,CAAAA;AACR,QAAA;AACJ,IAAA;IAEA,OAAO;QAAE4B,UAAAA,EAAY;AAAIA,YAAAA,GAAAA,UAAAA,CAAW1D,MAAM;AAAG,SAAA;AAAEU,QAAAA;AAAY,KAAA;AAC/D;;"}
|
|
1
|
+
{"version":3,"file":"resolveEffectiveConfiguration.js","sources":["../../../editing/resolveEffectiveConfiguration.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport {\n CollectionOperation, DiagnosticCode, EffectiveCollectionItem, EffectiveComponentConfiguration,\n EffectiveConfiguration, EffectivePropertyValue, InstanceContribution, PropertyValueType, SceneDiagnostic, ValueSource,\n} from '@cratis/scene.model';\nimport { DescriptorCatalog, findComponentDescriptor } from './DescriptorCatalog';\nimport { errorDiagnostic } from './diagnostics';\nimport { computeExposureGrants, ExposureGrant, grantKey } from './exposureGrants';\nimport { cloneData, getValueAtPath, setValueAtPath } from './pathAccess';\nimport { TemplateChain } from './TemplateChain';\nimport { validateItemValues, validateValue } from './validateValue';\n\n/**\n * Splits a flat collection item as it is stored on an element - `{ id, label, ... }` - into its id and fields.\n */\nfunction toEffectiveItem(item: unknown, index: number): EffectiveCollectionItem {\n const { id, ...values } = (item !== null && typeof item === 'object' ? item : {}) as Record<string, unknown>;\n return { id: typeof id === 'string' && id.length > 0 ? id : `owner-${index}`, values, origin: 'owner', fixed: true };\n}\n\nfunction toFlatItem(item: EffectiveCollectionItem): Record<string, unknown> {\n return { id: item.id, ...item.values };\n}\n\nfunction scalarValue(grant: ExposureGrant, matching: InstanceContribution[], instance: string, current: EffectivePropertyValue, diagnostics: SceneDiagnostic[]): void {\n for (const contribution of matching) {\n const problem = contribution.value === undefined ? 'a value is required' : validateValue(grant.descriptor, contribution.value);\n if (problem) {\n diagnostics.push(errorDiagnostic(\n DiagnosticCode.ContributionTypeMismatch,\n `The saved value of '${grant.path}' set by '${instance}' is ignored: ${problem}. It is kept, and applies again when it fits.`,\n { instance, component: grant.component, path: grant.path }));\n continue;\n }\n\n current.value = contribution.value;\n current.source = ValueSource.Instance;\n current.contributedBy = instance;\n }\n}\n\nfunction collectionValue(grant: ExposureGrant, matching: InstanceContribution[], instance: string, items: EffectiveCollectionItem[], diagnostics: SceneDiagnostic[]): boolean {\n let contributed = false;\n\n for (const contribution of matching) {\n const context = { instance, component: grant.component, path: grant.path };\n if (contribution.items === undefined) {\n diagnostics.push(errorDiagnostic(DiagnosticCode.ContributionTypeMismatch, `The saved value of '${grant.path}' set by '${instance}' is ignored: a collection takes items.`, context));\n continue;\n }\n\n if (contribution.items.length > 0 && !grant.operations.includes(CollectionOperation.Add)) {\n diagnostics.push(errorDiagnostic(\n DiagnosticCode.ContributionOperationNotPermitted,\n `'${instance}' has items in '${grant.path}', but adding items is not exposed. They are ignored and kept.`,\n context));\n continue;\n }\n\n for (const item of contribution.items) {\n const itemContext = { ...context, itemId: item.id };\n if (items.some(existing => existing.id === item.id)) {\n diagnostics.push(errorDiagnostic(DiagnosticCode.DuplicateCollectionItem, `The item id '${item.id}' in '${grant.path}' is already used.`, itemContext));\n continue;\n }\n\n const values: Record<string, unknown> = {};\n for (const [field, value] of Object.entries(item.values)) {\n if (grant.editableFields !== undefined && !grant.editableFields.includes(field)) {\n diagnostics.push(errorDiagnostic(DiagnosticCode.ContributionOperationNotPermitted, `The field '${field}' of '${grant.path}' is not exposed for editing.`, itemContext));\n continue;\n }\n\n const problem = validateItemValues(grant.descriptor.item, { [field]: value }).find(candidate => candidate.field === field);\n if (problem) {\n diagnostics.push(errorDiagnostic(\n problem.problem.startsWith('is not a field') ? DiagnosticCode.UnknownCollectionField : DiagnosticCode.ContributionTypeMismatch,\n `The field '${field}' of an item in '${grant.path}' is ignored: ${problem.problem}.`,\n itemContext));\n continue;\n }\n\n values[field] = value;\n }\n\n items.push({ id: item.id, values, origin: instance, fixed: false });\n contributed = true;\n }\n }\n\n return contributed;\n}\n\n/**\n * Resolves what every configurable component in a template chain is worth: the owner's own values, with each\n * instance's contributions applied in nesting order.\n *\n * This is the one merge. The editor shows its result and the runtime renders from it, so what an author sees is\n * what Play renders. Order is fixed: the owner's value first, then each level from the outermost inwards, so a\n * later level wins a scalar and appends to a collection after the earlier ones.\n *\n * Nothing in the persisted data is changed. A contribution that cannot apply - the exposure was withdrawn, the\n * property's type changed, the component is gone - is reported in `diagnostics` and left out of the result, and\n * stays in `instanceContributions`, so restoring the exposure brings its value back.\n *\n * @param templateChain The nesting, from {@link resolveTemplateChain} or built by hand.\n * @param instanceContributions What each instance has set.\n * @param catalog The descriptors saying what each component supports.\n */\nexport function resolveEffectiveConfiguration(\n templateChain: TemplateChain,\n instanceContributions: InstanceContribution[],\n catalog: DescriptorCatalog,\n): EffectiveConfiguration {\n const grants = computeExposureGrants(templateChain, catalog);\n const diagnostics: SceneDiagnostic[] = [...templateChain.diagnostics, ...grants.diagnostics];\n const handled = new Set<InstanceContribution>();\n const components = new Map<string, EffectiveComponentConfiguration>();\n\n for (const grant of grants.exposed) {\n const owner = templateChain.levels[grant.ownerLevel];\n const element = owner.elements.find(candidate => candidate.id === grant.component)!;\n\n let configuration = components.get(grant.component);\n if (!configuration) {\n configuration = { component: grant.component, owner: owner.owner, properties: cloneData(element.properties), values: [] };\n components.set(grant.component, configuration);\n }\n\n const stored = getValueAtPath(element.properties, grant.path);\n const base = stored === undefined ? cloneData(grant.descriptor.default) : cloneData(stored);\n const isCollection = grant.descriptor.valueType === PropertyValueType.Collection;\n const baseItems = isCollection && Array.isArray(base) ? base.map(toEffectiveItem) : [];\n const items = [...baseItems];\n\n const current: EffectivePropertyValue = {\n path: grant.path,\n value: base,\n source: stored === undefined ? ValueSource.Default : ValueSource.Local,\n inheritedValue: base,\n };\n let contributed = false;\n\n for (let index = grant.ownerLevel + 1; index < templateChain.levels.length; index++) {\n const instance = templateChain.levels[index].instance;\n if (!grants.byInstance.get(instance)?.has(grantKey(grant.component, grant.path))) continue;\n\n const effectiveGrant = grants.byInstance.get(instance)!.get(grantKey(grant.component, grant.path))!;\n const matching = instanceContributions.filter(contribution =>\n contribution.instance === instance && contribution.component === grant.component && contribution.path === grant.path);\n for (const contribution of matching) handled.add(contribution);\n\n if (isCollection) {\n if (collectionValue(effectiveGrant, matching, instance, items, diagnostics)) {\n contributed = true;\n current.contributedBy = instance;\n }\n } else {\n scalarValue(effectiveGrant, matching, instance, current, diagnostics);\n }\n }\n\n const maximumItems = grant.descriptor.constraints?.maximumItems;\n if (isCollection && maximumItems !== undefined && items.length > maximumItems) {\n // Saved items that no longer fit - the owner lowered the limit after they were added - are left out of\n // the result in order and kept in the saved data, like any other saved value that no longer fits.\n const dropped = items.splice(maximumItems);\n diagnostics.push(errorDiagnostic(\n DiagnosticCode.ContributionTypeMismatch,\n `'${grant.path}' on '${grant.component}' allows at most ${maximumItems} items; ${dropped.map(item => `'${item.id}'`).join(', ')} ${dropped.length === 1 ? 'is' : 'are'} ignored and kept.`,\n { instance: current.contributedBy ?? owner.instance, component: grant.component, path: grant.path }));\n }\n\n if (isCollection) {\n current.items = items;\n current.inheritedValue = baseItems.map(toFlatItem);\n current.value = items.map(toFlatItem);\n if (contributed) current.source = ValueSource.Instance;\n }\n\n if (current.value !== undefined) setValueAtPath(configuration.properties, grant.path, current.value);\n configuration.values.push(current);\n }\n\n const levelOf = new Map(templateChain.levels.map((chainLevel, index) => [chainLevel.instance, index]));\n for (const contribution of instanceContributions) {\n const contributorLevel = levelOf.get(contribution.instance);\n if (contributorLevel === undefined || handled.has(contribution)) continue;\n\n const context = { instance: contribution.instance, component: contribution.component, path: contribution.path };\n const owner = templateChain.levels.slice(0, contributorLevel).find(chainLevel => chainLevel.elements.some(element => element.id === contribution.component));\n if (!owner) {\n diagnostics.push(errorDiagnostic(\n DiagnosticCode.ContributionTargetMissing,\n `'${contribution.instance}' has saved values for '${contribution.component}', which is not in any layout or template above it. They are kept.`,\n context));\n } else if (!findComponentDescriptor(catalog, owner.elements.find(element => element.id === contribution.component)!.componentName)) {\n diagnostics.push(errorDiagnostic(\n DiagnosticCode.MissingComponentDescriptor,\n `'${contribution.instance}' has saved values for '${contribution.component}', but nothing describes that component any more. They are kept.`,\n context));\n } else {\n diagnostics.push(errorDiagnostic(\n DiagnosticCode.ContributionNotExposed,\n `'${contribution.instance}' has a saved value for '${contribution.path}' on '${contribution.component}', which is not exposed to it. It is ignored and kept.`,\n context));\n }\n }\n\n return { components: [...components.values()], diagnostics };\n}\n"],"names":["toEffectiveItem","item","index","id","values","length","origin","fixed","toFlatItem","scalarValue","grant","matching","instance","current","diagnostics","contribution","problem","value","undefined","validateValue","descriptor","push","errorDiagnostic","DiagnosticCode","ContributionTypeMismatch","path","component","source","ValueSource","Instance","contributedBy","collectionValue","items","contributed","context","operations","includes","CollectionOperation","Add","ContributionOperationNotPermitted","itemContext","itemId","some","existing","DuplicateCollectionItem","field","Object","entries","editableFields","validateItemValues","find","candidate","startsWith","UnknownCollectionField","resolveEffectiveConfiguration","templateChain","instanceContributions","catalog","grants","computeExposureGrants","handled","Set","components","Map","exposed","owner","levels","ownerLevel","element","elements","configuration","get","properties","cloneData","set","stored","getValueAtPath","base","default","isCollection","valueType","PropertyValueType","Collection","baseItems","Array","isArray","map","Default","Local","inheritedValue","byInstance","has","grantKey","effectiveGrant","filter","add","maximumItems","constraints","dropped","splice","join","setValueAtPath","levelOf","chainLevel","contributorLevel","slice","ContributionTargetMissing","findComponentDescriptor","componentName","MissingComponentDescriptor","ContributionNotExposed"],"mapp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@@
|
|
|
1
|
-
{"version":3,"file":"validateValue.d.ts","sourceRoot":"","sources":["../../../editing/validateValue.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"validateValue.d.ts","sourceRoot":"","sources":["../../../editing/validateValue.ts"],"names":[],"mappings":"AAGA,OAAO,EAAqB,wBAAwB,EAAE,kBAAkB,EAAqB,MAAM,qBAAqB,CAAC;AAiBzH,wBAAgB,aAAa,CAAC,UAAU,EAAE,kBAAkB,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CA4DhG;AAgED,MAAM,WAAW,gBAAgB;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACnB;AASD,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,wBAAwB,GAAG,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,gBAAgB,EAAE,CAsB5I"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PropertyValueType } from '@cratis/scene.model';
|
|
1
|
+
import { BindingSourceKind, PropertyValueType } from '@cratis/scene.model';
|
|
2
2
|
|
|
3
3
|
// Copyright (c) Cratis. All rights reserved.
|
|
4
4
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
@@ -19,6 +19,10 @@ function isNonEmptyString(value) {
|
|
|
19
19
|
if (value === undefined || value === null) {
|
|
20
20
|
return constraints.required ? 'a value is required' : undefined;
|
|
21
21
|
}
|
|
22
|
+
const binding = bindingKindOf(value);
|
|
23
|
+
if (binding !== undefined && descriptor.acceptedBindingKinds !== undefined) {
|
|
24
|
+
return descriptor.acceptedBindingKinds.includes(binding.kind) ? undefined : `a ${binding.kind} binding is not accepted here; use ${descriptor.acceptedBindingKinds.join(' or ')}`;
|
|
25
|
+
}
|
|
22
26
|
switch(descriptor.valueType){
|
|
23
27
|
case PropertyValueType.String:
|
|
24
28
|
{
|
|
@@ -61,7 +65,19 @@ function isNonEmptyString(value) {
|
|
|
61
65
|
/**
|
|
62
66
|
* The deepest nesting a JSON value may have. Authored configuration (chart datasets, option lists) is shallow;
|
|
63
67
|
* the limit turns a runaway or hostile structure into a validation message instead of a stack overflow.
|
|
64
|
-
*/ const
|
|
68
|
+
*/ const bindingKinds = new Set(Object.values(BindingSourceKind));
|
|
69
|
+
/**
|
|
70
|
+
* The source kind of a value that is a typed binding expression - an object with a known `kind` and a
|
|
71
|
+
* string `path` - rather than a value of the property's own type. Only consulted for properties that declare
|
|
72
|
+
* `acceptedBindingKinds`, so a collection property such as a command form's `inputs` can be bound to a
|
|
73
|
+
* table's `selectedItem` instead of listing its items.
|
|
74
|
+
*/ function bindingKindOf(value) {
|
|
75
|
+
if (!isRecord(value) || typeof value.kind !== 'string' || !bindingKinds.has(value.kind) || typeof value.path !== 'string') return undefined;
|
|
76
|
+
return {
|
|
77
|
+
kind: value.kind
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const maximumJsonDepth = 64;
|
|
65
81
|
/**
|
|
66
82
|
* Whether a value is JSON: `null`, a string, a boolean, a finite number, or an array or plain object of those.
|
|
67
83
|
* The value is only inspected, never serialized, so what an editor stores is exactly what was passed in.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateValue.js","sources":["../../../editing/validateValue.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { CollectionItemDescriptor, PropertyDescriptor, PropertyValueType } from '@cratis/scene.model';\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === 'string' && value.length > 0;\n}\n\n/**\n * Checks a value against a property descriptor.\n *\n * @param descriptor The property the value is for.\n * @param value The value to check. `undefined` means \"not set\", which is fine unless the property is required.\n * @returns The reason the value is not acceptable, or `undefined` when it is.\n */\nexport function validateValue(descriptor: PropertyDescriptor, value: unknown): string | undefined {\n const constraints = descriptor.constraints ?? {};\n if (value === undefined || value === null) {\n return constraints.required ? 'a value is required' : undefined;\n }\n\n switch (descriptor.valueType) {\n case PropertyValueType.String: {\n if (typeof value !== 'string') return 'expected a string';\n if (constraints.minimumLength !== undefined && value.length < constraints.minimumLength) return `must be at least ${constraints.minimumLength} characters`;\n if (constraints.maximumLength !== undefined && value.length > constraints.maximumLength) return `must be at most ${constraints.maximumLength} characters`;\n if (constraints.pattern !== undefined && !new RegExp(`^(?:${constraints.pattern})$`).test(value)) return `must match ${constraints.pattern}`;\n return undefined;\n }\n\n case PropertyValueType.Number: {\n if (typeof value !== 'number' || !Number.isFinite(value)) return 'expected a number';\n if (constraints.integer && !Number.isInteger(value)) return 'expected a whole number';\n if (constraints.minimum !== undefined && value < constraints.minimum) return `must be at least ${constraints.minimum}`;\n if (constraints.maximum !== undefined && value > constraints.maximum) return `must be at most ${constraints.maximum}`;\n return undefined;\n }\n\n case PropertyValueType.Boolean:\n return typeof value === 'boolean' ? undefined : 'expected true or false';\n\n case PropertyValueType.Enum:\n return (descriptor.choices ?? []).some(choice => choice.value === value) ? undefined : 'not one of the allowed choices';\n\n case PropertyValueType.Icon:\n if (!isRecord(value) || !isNonEmptyString(value.library) || !isNonEmptyString(value.key)) return 'expected an icon reference with a library and a key';\n return value.variant === undefined || typeof value.variant === 'string' ? undefined : 'the icon variant must be a string';\n\n case PropertyValueType.Destination:\n if (!isRecord(value) || !isNonEmptyString(value.screen)) return 'expected a destination naming a screen';\n return value.routeParameterBindings === undefined || isRecord(value.routeParameterBindings)\n ? undefined\n : 'routeParameterBindings must be an object';\n\n case PropertyValueType.QueryReference:\n if (isNonEmptyString(value)) return undefined;\n if (!isRecord(value) || !isNonEmptyString(value.queryId) || !isNonEmptyString(value.query)) return 'expected a query name or a query binding';\n return Array.isArray(value.arguments) && Array.isArray(value.results) ? undefined : 'a query binding needs arguments and results lists';\n\n case PropertyValueType.Collection:\n return validateCollection(descriptor, value);\n\n case PropertyValueType.Json:\n return isJsonValue(value) ? undefined : 'expected a JSON value';\n\n default:\n return isRecord(value) || Array.isArray(value) ? undefined : 'expected a structured value';\n }\n}\n\n/**\n * The deepest nesting a JSON value may have. Authored configuration (chart datasets, option lists) is shallow;\n * the limit turns a runaway or hostile structure into a validation message instead of a stack overflow.\n */\nconst maximumJsonDepth = 64;\n\n/**\n * Whether a value is JSON: `null`, a string, a boolean, a finite number, or an array or plain object of those.\n * The value is only inspected, never serialized, so what an editor stores is exactly what was passed in.\n */\nfunction isJsonValue(value: unknown, parents = new Set<object>()): boolean {\n if (value === null || typeof value === 'string' || typeof value === 'boolean') return true;\n if (typeof value === 'number') return Number.isFinite(value);\n if (typeof value !== 'object' || parents.has(value) || parents.size >= maximumJsonDepth) return false;\n\n const isArray = Array.isArray(value);\n const prototype = Object.getPrototypeOf(value);\n if (isArray ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) return false;\n\n parents.add(value);\n const values = isArray ? Array.from({ length: value.length }, (_, index) => (index in value ? value[index] : undefined)) : Object.values(value);\n const valid = values.every(candidate => isJsonValue(candidate, parents));\n parents.delete(value);\n return valid;\n}\n\nfunction validateCollection(descriptor: PropertyDescriptor, value: unknown): string | undefined {\n if (!Array.isArray(value)) return 'expected a list';\n const constraints = descriptor.constraints ?? {};\n if (constraints.minimumItems !== undefined && value.length < constraints.minimumItems) return `needs at least ${constraints.minimumItems} items`;\n if (constraints.maximumItems !== undefined && value.length > constraints.maximumItems) return `allows at most ${constraints.maximumItems} items`;\n\n const identities = new Set<string>();\n for (const item of value) {\n if (!isRecord(item) || !isNonEmptyString(item.id)) return 'every item needs an id';\n if (identities.has(item.id)) return `the item id '${item.id}' is used twice`;\n identities.add(item.id);\n\n const { id: _identity, ...values } = item;\n const problem = validateItemValues(descriptor.item, values).at(0);\n if (problem) return `item '${item.id}': ${problem.field} ${problem.problem}`;\n }\n\n return undefined;\n}\n\n/**\n * One field of a collection item that does not fit its descriptor.\n */\nexport interface ItemFieldProblem {\n field: string;\n problem: string;\n}\n\n/**\n * Checks a collection item's field values against the collection's item descriptor.\n *\n * @param itemDescriptor What the items look like.\n * @param values The item's field values, keyed by field path.\n * @returns Every field that is unknown or has an unacceptable value.\n */\nexport function validateItemValues(itemDescriptor: CollectionItemDescriptor | undefined, values: Record<string, unknown>): ItemFieldProblem[] {\n const fields = itemDescriptor?.properties ?? [];\n const problems: ItemFieldProblem[] = [];\n\n for (const [field, fieldValue] of Object.entries(values)) {\n const fieldDescriptor = fields.find(candidate => candidate.path === field);\n if (!fieldDescriptor) {\n problems.push({ field, problem: 'is not a field of this collection\\'s items' });\n continue;\n }\n\n const problem = validateValue(fieldDescriptor, fieldValue);\n if (problem) problems.push({ field, problem });\n }\n\n for (const fieldDescriptor of fields) {\n if (fieldDescriptor.constraints?.required && values[fieldDescriptor.path] === undefined) {\n problems.push({ field: fieldDescriptor.path, problem: 'a value is required' });\n }\n }\n\n return problems;\n}\n"],"names":["isRecord","value","Array","isArray","isNonEmptyString","length","validateValue","descriptor","constraints","undefined","required","valueType","PropertyValueType","String","minimumLength","maximumLength","pattern","RegExp","test","Number","isFinite","integer","isInteger","minimum","maximum","Boolean","Enum","choices","some","choice","Icon","library","key","variant","Destination","screen","routeParameterBindings","QueryReference","queryId","query","arguments","results","Collection","validateCollection","Json","isJsonValue","maximumJsonDepth","parents","Set","has","size","prototype","Object","getPrototypeOf","add","values","from","_","index","valid","every","candidate","delete","minimumItems","maximumItems","identities","item","id","_identity","problem","validateItemValues","at","field","itemDescriptor","fields","properties","problems","fieldValue","entries","fieldDescriptor","find","path","push"],"mappings":";;AAAA;AACA;AAIA,SAASA,SAASC,KAAc,EAAA;IAC5B,OAAOA,KAAAA,KAAU,QAAQ,OAAOA,KAAAA,KAAU,YAAY,CAACC,KAAAA,CAAMC,OAAO,CAACF,KAAAA,CAAAA;AACzE;AAEA,SAASG,iBAAiBH,KAAc,EAAA;AACpC,IAAA,OAAO,OAAOA,KAAAA,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A+B,EAAE;IAEvC,KAAK,MAAM,CAACJ,KAAAA,EAAOK,UAAAA,CAAW,IAAIzB,MAAAA,CAAO0B,OAAO,CAACvB,MAAAA,CAAAA,CAAS;QACtD,MAAMwB,eAAAA,GAAkBL,OAAOM,IAAI,CAACnB,CAAAA,SAAAA,GAAaA,SAAAA,CAAUoB,IAAI,KAAKT,KAAAA,CAAAA;AACpE,QAAA,IAAI,CAACO,eAAAA,EAAiB;AAClBH,YAAAA,QAAAA,CAASM,IAAI,CAAC;AAAEV,gBAAAA,KAAAA;gBAAOH,OAAAA,EAAS;AAA6C,aAAA,CAAA;AAC7E,YAAA;AACJ,QAAA;QAEA,MAAMA,OAAAA,GAAU/D,cAAcyE,eAAAA,EAAiBF,UAAAA,CAAAA;QAC/C,IAAIR,OAAAA,EAASO,QAAAA,CAASM,IAAI,CAAC;AAAEV,YAAAA,KAAAA;AAAOH,YAAAA;AAAQ,SAAA,CAAA;AAChD,IAAA;IAEA,KAAK,MAAMU,mBAAmBL,MAAAA,CAAQ;QAClC,IAAIK,eAAAA,CAAgBvE,WAAW,EAAEE,QAAAA,IAAY6C,MAAM,CAACwB,eAAAA,CAAgBE,IAAI,CAAC,KAAKxE,SAAAA,EAAW;AACrFmE,YAAAA,QAAAA,CAASM,IAAI,CAAC;AAAEV,gBAAAA,KAAAA,EAAOO,gBAAgBE,IAAI;gBAAEZ,OAAAA,EAAS;AAAsB,aAAA,CAAA;AAChF,QAAA;AACJ,IAAA;IAEA,OAAOO,QAAAA;AACX;;"}
|
|
1
|
+
{"version":3,"file":"validateValue.js","sources":["../../../editing/validateValue.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { BindingSourceKind, CollectionItemDescriptor, PropertyDescriptor, PropertyValueType } from '@cratis/scene.model';\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === 'string' && value.length > 0;\n}\n\n/**\n * Checks a value against a property descriptor.\n *\n * @param descriptor The property the value is for.\n * @param value The value to check. `undefined` means \"not set\", which is fine unless the property is required.\n * @returns The reason the value is not acceptable, or `undefined` when it is.\n */\nexport function validateValue(descriptor: PropertyDescriptor, value: unknown): string | undefined {\n const constraints = descriptor.constraints ?? {};\n if (value === undefined || value === null) {\n return constraints.required ? 'a value is required' : undefined;\n }\n\n const binding = bindingKindOf(value);\n if (binding !== undefined && descriptor.acceptedBindingKinds !== undefined) {\n return descriptor.acceptedBindingKinds.includes(binding.kind)\n ? undefined\n : `a ${binding.kind} binding is not accepted here; use ${descriptor.acceptedBindingKinds.join(' or ')}`;\n }\n\n switch (descriptor.valueType) {\n case PropertyValueType.String: {\n if (typeof value !== 'string') return 'expected a string';\n if (constraints.minimumLength !== undefined && value.length < constraints.minimumLength) return `must be at least ${constraints.minimumLength} characters`;\n if (constraints.maximumLength !== undefined && value.length > constraints.maximumLength) return `must be at most ${constraints.maximumLength} characters`;\n if (constraints.pattern !== undefined && !new RegExp(`^(?:${constraints.pattern})$`).test(value)) return `must match ${constraints.pattern}`;\n return undefined;\n }\n\n case PropertyValueType.Number: {\n if (typeof value !== 'number' || !Number.isFinite(value)) return 'expected a number';\n if (constraints.integer && !Number.isInteger(value)) return 'expected a whole number';\n if (constraints.minimum !== undefined && value < constraints.minimum) return `must be at least ${constraints.minimum}`;\n if (constraints.maximum !== undefined && value > constraints.maximum) return `must be at most ${constraints.maximum}`;\n return undefined;\n }\n\n case PropertyValueType.Boolean:\n return typeof value === 'boolean' ? undefined : 'expected true or false';\n\n case PropertyValueType.Enum:\n return (descriptor.choices ?? []).some(choice => choice.value === value) ? undefined : 'not one of the allowed choices';\n\n case PropertyValueType.Icon:\n if (!isRecord(value) || !isNonEmptyString(value.library) || !isNonEmptyString(value.key)) return 'expected an icon reference with a library and a key';\n return value.variant === undefined || typeof value.variant === 'string' ? undefined : 'the icon variant must be a string';\n\n case PropertyValueType.Destination:\n if (!isRecord(value) || !isNonEmptyString(value.screen)) return 'expected a destination naming a screen';\n return value.routeParameterBindings === undefined || isRecord(value.routeParameterBindings)\n ? undefined\n : 'routeParameterBindings must be an object';\n\n case PropertyValueType.QueryReference:\n if (isNonEmptyString(value)) return undefined;\n if (!isRecord(value) || !isNonEmptyString(value.queryId) || !isNonEmptyString(value.query)) return 'expected a query name or a query binding';\n return Array.isArray(value.arguments) && Array.isArray(value.results) ? undefined : 'a query binding needs arguments and results lists';\n\n case PropertyValueType.Collection:\n return validateCollection(descriptor, value);\n\n case PropertyValueType.Json:\n return isJsonValue(value) ? undefined : 'expected a JSON value';\n\n default:\n return isRecord(value) || Array.isArray(value) ? undefined : 'expected a structured value';\n }\n}\n\n/**\n * The deepest nesting a JSON value may have. Authored configuration (chart datasets, option lists) is shallow;\n * the limit turns a runaway or hostile structure into a validation message instead of a stack overflow.\n */\nconst bindingKinds = new Set<string>(Object.values(BindingSourceKind));\n\n/**\n * The source kind of a value that is a typed binding expression - an object with a known `kind` and a\n * string `path` - rather than a value of the property's own type. Only consulted for properties that declare\n * `acceptedBindingKinds`, so a collection property such as a command form's `inputs` can be bound to a\n * table's `selectedItem` instead of listing its items.\n */\nfunction bindingKindOf(value: unknown): { kind: BindingSourceKind } | undefined {\n if (!isRecord(value) || typeof value.kind !== 'string' || !bindingKinds.has(value.kind) || typeof value.path !== 'string') return undefined;\n return { kind: value.kind as BindingSourceKind };\n}\n\nconst maximumJsonDepth = 64;\n\n/**\n * Whether a value is JSON: `null`, a string, a boolean, a finite number, or an array or plain object of those.\n * The value is only inspected, never serialized, so what an editor stores is exactly what was passed in.\n */\nfunction isJsonValue(value: unknown, parents = new Set<object>()): boolean {\n if (value === null || typeof value === 'string' || typeof value === 'boolean') return true;\n if (typeof value === 'number') return Number.isFinite(value);\n if (typeof value !== 'object' || parents.has(value) || parents.size >= maximumJsonDepth) return false;\n\n const isArray = Array.isArray(value);\n const prototype = Object.getPrototypeOf(value);\n if (isArray ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) return false;\n\n parents.add(value);\n const values = isArray ? Array.from({ length: value.length }, (_, index) => (index in value ? value[index] : undefined)) : Object.values(value);\n const valid = values.every(candidate => isJsonValue(candidate, parents));\n parents.delete(value);\n return valid;\n}\n\nfunction validateCollection(descriptor: PropertyDescriptor, value: unknown): string | undefined {\n if (!Array.isArray(value)) return 'expected a list';\n const constraints = descriptor.constraints ?? {};\n if (constraints.minimumItems !== undefined && value.length < constraints.minimumItems) return `needs at least ${constraints.minimumItems} items`;\n if (constraints.maximumItems !== undefined && value.length > constraints.maximumItems) return `allows at most ${constraints.maximumItems} items`;\n\n const identities = new Set<string>();\n for (const item of value) {\n if (!isRecord(item) || !isNonEmptyString(item.id)) return 'every item needs an id';\n if (identities.has(item.id)) return `the item id '${item.id}' is used twice`;\n identities.add(item.id);\n\n const { id: _identity, ...values } = item;\n const problem = validateItemValues(descriptor.item, values).at(0);\n if (problem) return `item '${item.id}': ${problem.field} ${problem.problem}`;\n }\n\n return undefined;\n}\n\n/**\n * One field of a collection item that does not fit its descriptor.\n */\nexport interface ItemFieldProblem {\n field: string;\n problem: string;\n}\n\n/**\n * Checks a collection item's field values against the collection's item descriptor.\n *\n * @param itemDescriptor What the items look like.\n * @param values The item's field values, keyed by field path.\n * @returns Every field that is unknown or has an unacceptable value.\n */\nexport function validateItemValues(itemDescriptor: CollectionItemDescriptor | undefined, values: Record<string, unknown>): ItemFieldProblem[] {\n const fields = itemDescriptor?.properties ?? [];\n const problems: ItemFieldProblem[] = [];\n\n for (const [field, fieldValue] of Object.entries(values)) {\n const fieldDescriptor = fields.find(candidate => candidate.path === field);\n if (!fieldDescriptor) {\n problems.push({ field, problem: 'is not a field of this collection\\'s items' });\n continue;\n }\n\n const problem = validateValue(fieldDescriptor, fieldValue);\n if (problem) problems.push({ field, problem });\n }\n\n for (const fieldDescriptor of fields) {\n if (fieldDescriptor.constraints?.required && values[fieldDescriptor.path] === undefined) {\n problems.push({ field: fieldDescriptor.path, problem: 'a value is required' });\n }\n }\n\n return problems;\n}\n"],"names":["isRecord","value","Array","isArray","isNonEmptyString","length","validateValue","descriptor","constraints","undefined","required","binding","bindingKindOf","acceptedBindingKinds","includes","kind","join","valueType","PropertyValueType","String","minimumLength","maximumLength","pattern","RegExp","test","Number","isFinite","integer","isInteger","minimum","maximum","Boolean","Enum","choices","some","choice","Icon","library","key","variant","Destination","screen","routeParameterBindings","QueryReference","queryId","query","arguments","results","Collection","validateCollection","Json","isJsonValue","bindingKinds","Set","Object","values","BindingSourceKind","has","path","maximumJsonDepth","parents","size","prototype","getPrototypeOf","add","from","_","index","valid","every","candidate","delete","minimumItems","maximumItems","identities","item","id","_identity","problem","validateItemValues","at","field","itemDescriptor","fields","properties","problems","fieldValue","entries","fieldDescriptor","find","push"],"mappings":";;AAAA;AACA;AAIA,SAASA,SAASC,KAAc,EAAA;IAC5B,OAAOA,KAAAA,KAAU,QAAQ,OAAOA,KAAAA,KAAU,YAAY,CAACC,KAAAA,CAAMC,OAAO,CAACF,KAAAA,CAAAA;AACzE;AAEA,SAASG,iBAAiBH,KAAc,EAAA;AACpC,IAAA,OAAO,OAAOA,KAAAA,KAAU,QAAA,IAAYA,KAAAA,CAAMI,MAAM,GAAG,CAAA;AACvD;AAEA;;;;;;AAMC,IACM,SAASC,aAAAA,CAAcC,UAA8B,EAAEN,KAAc,EAAA;AACxE,IAAA,MAAMO,WAAAA,GAAcD,UAAAA,CAAWC,WAAW,IAAI,EAAC;IAC/C,IAAIP,KAAAA,KAAUQ,SAAAA,IAAaR,KAAAA,KAAU,IAAA,EAAM;QACvC,OAAOO,WAAAA,CAAYE,QAAQ,GAAG,qBAAA,GAAwBD,SAAAA;AAC1D,IAAA;AAEA,IAAA,MAAME,UAAUC,aAAAA,CAAcX,KAAAA,CAAAA;AAC9B,IAAA,IAAIU,OAAAA,KAAYF,SAAAA,IAAaF,UAAAA,CAAWM,oBAAoB,KAAKJ,SAAAA,EAAW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OO,QAAAA;AACX;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandFormLayoutKey.d.ts","sourceRoot":"","sources":["../../../forms/CommandFormLayoutKey.ts"],"names":[],"mappings":"AAIA,oBAAY,oBAAoB;IAC5B,SAAS,cAAc;IACvB,UAAU,eAAe;IACzB,OAAO,YAAY;IACnB,SAAS,cAAc;CAC1B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
/** The keys a designer maps to layout moves and resizes. */ var CommandFormLayoutKey = /*#__PURE__*/ function(CommandFormLayoutKey) {
|
|
4
|
+
CommandFormLayoutKey["ArrowLeft"] = "ArrowLeft";
|
|
5
|
+
CommandFormLayoutKey["ArrowRight"] = "ArrowRight";
|
|
6
|
+
CommandFormLayoutKey["ArrowUp"] = "ArrowUp";
|
|
7
|
+
CommandFormLayoutKey["ArrowDown"] = "ArrowDown";
|
|
8
|
+
return CommandFormLayoutKey;
|
|
9
|
+
}({});
|
|
10
|
+
|
|
11
|
+
export { CommandFormLayoutKey };
|
|
12
|
+
//# sourceMappingURL=CommandFormLayoutKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandFormLayoutKey.js","sources":["../../../forms/CommandFormLayoutKey.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/** The keys a designer maps to layout moves and resizes. */\nexport enum CommandFormLayoutKey {\n ArrowLeft = 'ArrowLeft',\n ArrowRight = 'ArrowRight',\n ArrowUp = 'ArrowUp',\n ArrowDown = 'ArrowDown',\n}\n"],"names":["CommandFormLayoutKey"],"mappings":"AAAA;AACA;AAEA,6DACO,IAAKA,oBAAAA,iBAAAA,SAAAA,oBAAAA,EAAAA;;;;;AAAAA,IAAAA,OAAAA,oBAAAA;AAKX,CAAA,CAAA,EAAA;;"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CommandFormLayout } from '@cratis/scene.model';
|
|
2
|
+
import { CommandFormLayoutDraft } from './CommandFormLayoutDraft';
|
|
3
|
+
import { CommandFormLayoutKey } from './CommandFormLayoutKey';
|
|
4
|
+
export declare function applyCommandFormLayoutKey(committed: CommandFormLayout, field: string, key: CommandFormLayoutKey, resize?: boolean, fields?: readonly string[]): CommandFormLayoutDraft | undefined;
|
|
5
|
+
//# sourceMappingURL=applyCommandFormLayoutKey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyCommandFormLayoutKey.d.ts","sourceRoot":"","sources":["../../../forms/applyCommandFormLayoutKey.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAsB,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAW9D,wBAAgB,yBAAyB,CACrC,SAAS,EAAE,iBAAiB,EAC5B,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,oBAAoB,EACzB,MAAM,UAAQ,EACd,MAAM,GAAE,SAAS,MAAM,EAAO,GAC/B,sBAAsB,GAAG,SAAS,CAIpC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { CommandFormLayoutKey } from './CommandFormLayoutKey.js';
|
|
2
|
+
import { updateCommandFormFieldPlacement } from './updateCommandFormFieldPlacement.js';
|
|
3
|
+
|
|
4
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
5
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
6
|
+
/**
|
|
7
|
+
* Moves or resizes one field from the keyboard, so the layout can be arranged without a pointer.
|
|
8
|
+
*
|
|
9
|
+
* An arrow key moves the field one cell; with `resize`, Left and Right narrow and widen its column span and
|
|
10
|
+
* Up and Down shorten and lengthen its row span. Positions are one-based and never go below one, and spans never below one.
|
|
11
|
+
* The result is a draft validated like any other placement change, so a move or resize past the last
|
|
12
|
+
* column is reported in its diagnostics and the committed layout is kept. Returns undefined for a field that is not placed.
|
|
13
|
+
*/ function applyCommandFormLayoutKey(committed, field, key, resize = false, fields = []) {
|
|
14
|
+
const placement = committed.placements.find((candidate)=>candidate.field === field);
|
|
15
|
+
if (!placement) return undefined;
|
|
16
|
+
return updateCommandFormFieldPlacement(committed, resize ? resized(placement, key) : moved(placement, key), fields);
|
|
17
|
+
}
|
|
18
|
+
function moved(placement, key) {
|
|
19
|
+
switch(key){
|
|
20
|
+
case CommandFormLayoutKey.ArrowLeft:
|
|
21
|
+
return {
|
|
22
|
+
...placement,
|
|
23
|
+
column: Math.max(1, placement.column - 1)
|
|
24
|
+
};
|
|
25
|
+
case CommandFormLayoutKey.ArrowRight:
|
|
26
|
+
return {
|
|
27
|
+
...placement,
|
|
28
|
+
column: placement.column + 1
|
|
29
|
+
};
|
|
30
|
+
case CommandFormLayoutKey.ArrowUp:
|
|
31
|
+
return {
|
|
32
|
+
...placement,
|
|
33
|
+
row: Math.max(1, placement.row - 1)
|
|
34
|
+
};
|
|
35
|
+
case CommandFormLayoutKey.ArrowDown:
|
|
36
|
+
return {
|
|
37
|
+
...placement,
|
|
38
|
+
row: placement.row + 1
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function resized(placement, key) {
|
|
43
|
+
const columnSpan = placement.columnSpan ?? 1;
|
|
44
|
+
const rowSpan = placement.rowSpan ?? 1;
|
|
45
|
+
switch(key){
|
|
46
|
+
case CommandFormLayoutKey.ArrowLeft:
|
|
47
|
+
return {
|
|
48
|
+
...placement,
|
|
49
|
+
columnSpan: Math.max(1, columnSpan - 1)
|
|
50
|
+
};
|
|
51
|
+
case CommandFormLayoutKey.ArrowRight:
|
|
52
|
+
return {
|
|
53
|
+
...placement,
|
|
54
|
+
columnSpan: columnSpan + 1
|
|
55
|
+
};
|
|
56
|
+
case CommandFormLayoutKey.ArrowUp:
|
|
57
|
+
return {
|
|
58
|
+
...placement,
|
|
59
|
+
rowSpan: Math.max(1, rowSpan - 1)
|
|
60
|
+
};
|
|
61
|
+
case CommandFormLayoutKey.ArrowDown:
|
|
62
|
+
return {
|
|
63
|
+
...placement,
|
|
64
|
+
rowSpan: rowSpan + 1
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { applyCommandFormLayoutKey };
|
|
70
|
+
//# sourceMappingURL=applyCommandFormLayoutKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyCommandFormLayoutKey.js","sources":["../../../forms/applyCommandFormLayoutKey.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { CommandFormLayout, FormFieldPlacement } from '@cratis/scene.model';\nimport { CommandFormLayoutDraft } from './CommandFormLayoutDraft';\nimport { CommandFormLayoutKey } from './CommandFormLayoutKey';\nimport { updateCommandFormFieldPlacement } from './updateCommandFormFieldPlacement';\n\n/**\n * Moves or resizes one field from the keyboard, so the layout can be arranged without a pointer.\n *\n * An arrow key moves the field one cell; with `resize`, Left and Right narrow and widen its column span and\n * Up and Down shorten and lengthen its row span. Positions are one-based and never go below one, and spans never below one.\n * The result is a draft validated like any other placement change, so a move or resize past the last\n * column is reported in its diagnostics and the committed layout is kept. Returns undefined for a field that is not placed.\n */\nexport function applyCommandFormLayoutKey(\n committed: CommandFormLayout,\n field: string,\n key: CommandFormLayoutKey,\n resize = false,\n fields: readonly string[] = [],\n): CommandFormLayoutDraft | undefined {\n const placement = committed.placements.find(candidate => candidate.field === field);\n if (!placement) return undefined;\n return updateCommandFormFieldPlacement(committed, resize ? resized(placement, key) : moved(placement, key), fields);\n}\n\nfunction moved(placement: FormFieldPlacement, key: CommandFormLayoutKey): FormFieldPlacement {\n switch (key) {\n case CommandFormLayoutKey.ArrowLeft: return { ...placement, column: Math.max(1, placement.column - 1) };\n case CommandFormLayoutKey.ArrowRight: return { ...placement, column: placement.column + 1 };\n case CommandFormLayoutKey.ArrowUp: return { ...placement, row: Math.max(1, placement.row - 1) };\n case CommandFormLayoutKey.ArrowDown: return { ...placement, row: placement.row + 1 };\n }\n}\n\nfunction resized(placement: FormFieldPlacement, key: CommandFormLayoutKey): FormFieldPlacement {\n const columnSpan = placement.columnSpan ?? 1;\n const rowSpan = placement.rowSpan ?? 1;\n switch (key) {\n case CommandFormLayoutKey.ArrowLeft: return { ...placement, columnSpan: Math.max(1, columnSpan - 1) };\n case CommandFormLayoutKey.ArrowRight: return { ...placement, columnSpan: columnSpan + 1 };\n case CommandFormLayoutKey.ArrowUp: return { ...placement, rowSpan: Math.max(1, rowSpan - 1) };\n case CommandFormLayoutKey.ArrowDown: return { ...placement, rowSpan: rowSpan + 1 };\n }\n}\n"],"names":["applyCommandFormLayoutKey","committed","field","key","resize","fields","placement","placements","find","candidate","undefined","updateCommandFormFieldPlacement","resized","moved","CommandFormLayoutKey","ArrowLeft","column","Math","max","ArrowRight","ArrowUp","row","ArrowDown","columnSpan","rowSpan"],"mappings":";;;AAAA;AACA;AAOA;;;;;;;AAOC,IACM,SAASA,yBAAAA,CACZC,SAA4B,EAC5BC,KAAa,EACbC,GAAyB,EACzBC,MAAAA,GAAS,KAAK,EACdC,SAA4B,EAAE,EAAA;IAE9B,MAAMC,SAAAA,GAAYL,SAAAA,CAAUM,UAAU,CAACC,IAAI,CAACC,CAAAA,SAAAA,GAAaA,SAAAA,CAAUP,KAAK,KAAKA,KAAAA,CAAAA;IAC7E,IAAI,CAACI,WAAW,OAAOI,SAAAA;IACvB,OAAOC,+BAAAA,CAAgCV,WAAWG,MAAAA,GAASQ,OAAAA,CAAQN,WAAWH,GAAAA,CAAAA,GAAOU,KAAAA,CAAMP,WAAWH,GAAAA,CAAAA,EAAME,MAAAA,CAAAA;AAChH;AAEA,SAASQ,KAAAA,CAAMP,SAA6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