@cratis/scene.engine 4.27.0 → 4.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +15 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/structure/ApplicationStructureIndex.js +10 -0
- package/dist/cjs/structure/ApplicationStructureIndex.js.map +1 -1
- package/dist/cjs/toolbar/SliceDialogSource.js +14 -0
- package/dist/cjs/toolbar/SliceDialogSource.js.map +1 -0
- package/dist/cjs/toolbar/ToolbarDiagnosticCode.js +16 -0
- package/dist/cjs/toolbar/ToolbarDiagnosticCode.js.map +1 -0
- package/dist/cjs/toolbar/ToolbarDiagnosticSeverity.js +14 -0
- package/dist/cjs/toolbar/ToolbarDiagnosticSeverity.js.map +1 -0
- package/dist/cjs/toolbar/sliceDialogFor.js +38 -0
- package/dist/cjs/toolbar/sliceDialogFor.js.map +1 -0
- package/dist/cjs/toolbar/toolbarButtons.js +93 -0
- package/dist/cjs/toolbar/toolbarButtons.js.map +1 -0
- package/dist/cjs/toolbar/validateToolbarButtons.js +59 -0
- package/dist/cjs/toolbar/validateToolbarButtons.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/structure/ApplicationStructureIndex.d.ts +1 -0
- package/dist/esm/structure/ApplicationStructureIndex.d.ts.map +1 -1
- package/dist/esm/structure/ApplicationStructureIndex.js +10 -0
- package/dist/esm/structure/ApplicationStructureIndex.js.map +1 -1
- package/dist/esm/toolbar/ResolvedToolbarButton.d.ts +13 -0
- package/dist/esm/toolbar/ResolvedToolbarButton.d.ts.map +1 -0
- package/dist/esm/toolbar/ResolvedToolbarButton.js +2 -0
- package/dist/esm/toolbar/ResolvedToolbarButton.js.map +1 -0
- package/dist/esm/toolbar/SliceDialog.d.ts +8 -0
- package/dist/esm/toolbar/SliceDialog.d.ts.map +1 -0
- package/dist/esm/toolbar/SliceDialog.js +2 -0
- package/dist/esm/toolbar/SliceDialog.js.map +1 -0
- package/dist/esm/toolbar/SliceDialogSource.d.ts +5 -0
- package/dist/esm/toolbar/SliceDialogSource.d.ts.map +1 -0
- package/dist/esm/toolbar/SliceDialogSource.js +12 -0
- package/dist/esm/toolbar/SliceDialogSource.js.map +1 -0
- package/dist/esm/toolbar/ToolbarDiagnostic.d.ts +9 -0
- package/dist/esm/toolbar/ToolbarDiagnostic.d.ts.map +1 -0
- package/dist/esm/toolbar/ToolbarDiagnostic.js +2 -0
- package/dist/esm/toolbar/ToolbarDiagnostic.js.map +1 -0
- package/dist/esm/toolbar/ToolbarDiagnosticCode.d.ts +6 -0
- package/dist/esm/toolbar/ToolbarDiagnosticCode.d.ts.map +1 -0
- package/dist/esm/toolbar/ToolbarDiagnosticCode.js +14 -0
- package/dist/esm/toolbar/ToolbarDiagnosticCode.js.map +1 -0
- package/dist/esm/toolbar/ToolbarDiagnosticSeverity.d.ts +5 -0
- package/dist/esm/toolbar/ToolbarDiagnosticSeverity.d.ts.map +1 -0
- package/dist/esm/toolbar/ToolbarDiagnosticSeverity.js +12 -0
- package/dist/esm/toolbar/ToolbarDiagnosticSeverity.js.map +1 -0
- package/dist/esm/toolbar/index.d.ts +10 -0
- package/dist/esm/toolbar/index.d.ts.map +1 -0
- package/dist/esm/toolbar/index.js +10 -0
- package/dist/esm/toolbar/index.js.map +1 -0
- package/dist/esm/toolbar/sliceDialogFor.d.ts +5 -0
- package/dist/esm/toolbar/sliceDialogFor.d.ts.map +1 -0
- package/dist/esm/toolbar/sliceDialogFor.js +35 -0
- package/dist/esm/toolbar/sliceDialogFor.js.map +1 -0
- package/dist/esm/toolbar/toolbarButtons.d.ts +10 -0
- package/dist/esm/toolbar/toolbarButtons.d.ts.map +1 -0
- package/dist/esm/toolbar/toolbarButtons.js +89 -0
- package/dist/esm/toolbar/toolbarButtons.js.map +1 -0
- package/dist/esm/toolbar/validateToolbarButtons.d.ts +5 -0
- package/dist/esm/toolbar/validateToolbarButtons.d.ts.map +1 -0
- package/dist/esm/toolbar/validateToolbarButtons.js +57 -0
- package/dist/esm/toolbar/validateToolbarButtons.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/index.ts +1 -0
- package/package.json +3 -3
- package/structure/ApplicationStructureIndex.ts +11 -0
- package/toolbar/ResolvedToolbarButton.ts +34 -0
- package/toolbar/SliceDialog.ts +21 -0
- package/toolbar/SliceDialogSource.ts +13 -0
- package/toolbar/ToolbarDiagnostic.ts +22 -0
- package/toolbar/ToolbarDiagnosticCode.ts +17 -0
- package/toolbar/ToolbarDiagnosticSeverity.ts +13 -0
- package/toolbar/index.ts +12 -0
- package/toolbar/sliceDialogFor.ts +31 -0
- package/toolbar/toolbarButtons.ts +83 -0
- package/toolbar/validateToolbarButtons.ts +61 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SliceDialogSource.d.ts","sourceRoot":"","sources":["../../../toolbar/SliceDialogSource.ts"],"names":[],"mappings":"AAMA,oBAAY,iBAAiB;IAEzB,KAAK,UAAU;IAGf,OAAO,YAAY;CACtB"}
|
|
@@ -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
|
+
/**
|
|
4
|
+
* Where a slice's dialog template comes from.
|
|
5
|
+
*/ var SliceDialogSource = /*#__PURE__*/ function(SliceDialogSource) {
|
|
6
|
+
/** The slice names its own dialog template. */ SliceDialogSource["Slice"] = "slice";
|
|
7
|
+
/** The slice names none, so the default form dialog is used. */ SliceDialogSource["Default"] = "default";
|
|
8
|
+
return SliceDialogSource;
|
|
9
|
+
}({});
|
|
10
|
+
|
|
11
|
+
export { SliceDialogSource };
|
|
12
|
+
//# sourceMappingURL=SliceDialogSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SliceDialogSource.js","sources":["../../../toolbar/SliceDialogSource.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/**\n * Where a slice's dialog template comes from.\n */\nexport enum SliceDialogSource {\n /** The slice names its own dialog template. */\n Slice = 'slice',\n\n /** The slice names none, so the default form dialog is used. */\n Default = 'default',\n}\n"],"names":["SliceDialogSource"],"mappings":"AAAA;AACA;AAEA;;IAGO,IAAKA,iBAAAA,iBAAAA,SAAAA,iBAAAA,EAAAA;oDACqC,iBAAA,CAAA,OAAA,CAAA,GAAA,OAAA;qEAGiB,iBAAA,CAAA,SAAA,CAAA,GAAA,SAAA;AAJtDA,IAAAA,OAAAA,iBAAAA;AAMX,CAAA,CAAA,EAAA;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ToolbarDiagnosticCode } from './ToolbarDiagnosticCode';
|
|
2
|
+
import { ToolbarDiagnosticSeverity } from './ToolbarDiagnosticSeverity';
|
|
3
|
+
export interface ToolbarDiagnostic {
|
|
4
|
+
code: ToolbarDiagnosticCode;
|
|
5
|
+
severity: ToolbarDiagnosticSeverity;
|
|
6
|
+
message: string;
|
|
7
|
+
button: string;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=ToolbarDiagnostic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolbarDiagnostic.d.ts","sourceRoot":"","sources":["../../../toolbar/ToolbarDiagnostic.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAKxE,MAAM,WAAW,iBAAiB;IAE9B,IAAI,EAAE,qBAAqB,CAAC;IAG5B,QAAQ,EAAE,yBAAyB,CAAC;IAGpC,OAAO,EAAE,MAAM,CAAC;IAGhB,MAAM,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolbarDiagnostic.js","sourceRoot":"","sources":["../../../toolbar/ToolbarDiagnostic.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare enum ToolbarDiagnosticCode {
|
|
2
|
+
ToolbarButtonSliceNotFound = "toolbarButtonSliceNotFound",
|
|
3
|
+
ToolbarButtonSliceNotStateChange = "toolbarButtonSliceNotStateChange",
|
|
4
|
+
ToolbarButtonSliceEmpty = "toolbarButtonSliceEmpty"
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=ToolbarDiagnosticCode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolbarDiagnosticCode.d.ts","sourceRoot":"","sources":["../../../toolbar/ToolbarDiagnosticCode.ts"],"names":[],"mappings":"AAOA,oBAAY,qBAAqB;IAE7B,0BAA0B,+BAA+B;IAGzD,gCAAgC,qCAAqC;IAGrE,uBAAuB,4BAA4B;CACtD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
* What is wrong with a toolbar button. The values are shared with the C# engine so both report the same code for
|
|
5
|
+
* the same toolbar.
|
|
6
|
+
*/ var ToolbarDiagnosticCode = /*#__PURE__*/ function(ToolbarDiagnosticCode) {
|
|
7
|
+
/** A button invokes a slice the application structure does not have. */ ToolbarDiagnosticCode["ToolbarButtonSliceNotFound"] = "toolbarButtonSliceNotFound";
|
|
8
|
+
/** A button invokes a slice that is not a state change; state views and automations never take user input. */ ToolbarDiagnosticCode["ToolbarButtonSliceNotStateChange"] = "toolbarButtonSliceNotStateChange";
|
|
9
|
+
/** A button has no slice yet. It is allowed while designing, and flagged. */ ToolbarDiagnosticCode["ToolbarButtonSliceEmpty"] = "toolbarButtonSliceEmpty";
|
|
10
|
+
return ToolbarDiagnosticCode;
|
|
11
|
+
}({});
|
|
12
|
+
|
|
13
|
+
export { ToolbarDiagnosticCode };
|
|
14
|
+
//# sourceMappingURL=ToolbarDiagnosticCode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolbarDiagnosticCode.js","sources":["../../../toolbar/ToolbarDiagnosticCode.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/**\n * What is wrong with a toolbar button. The values are shared with the C# engine so both report the same code for\n * the same toolbar.\n */\nexport enum ToolbarDiagnosticCode {\n /** A button invokes a slice the application structure does not have. */\n ToolbarButtonSliceNotFound = 'toolbarButtonSliceNotFound',\n\n /** A button invokes a slice that is not a state change; state views and automations never take user input. */\n ToolbarButtonSliceNotStateChange = 'toolbarButtonSliceNotStateChange',\n\n /** A button has no slice yet. It is allowed while designing, and flagged. */\n ToolbarButtonSliceEmpty = 'toolbarButtonSliceEmpty',\n}\n"],"names":["ToolbarDiagnosticCode"],"mappings":"AAAA;AACA;AAEA;;;IAIO,IAAKA,qBAAAA,iBAAAA,SAAAA,qBAAAA,EAAAA;6EAC8D,qBAAA,CAAA,4BAAA,CAAA,GAAA,4BAAA;mHAGsC,qBAAA,CAAA,kCAAA,CAAA,GAAA,kCAAA;kFAGjC,qBAAA,CAAA,yBAAA,CAAA,GAAA,yBAAA;AAPnEA,IAAAA,OAAAA,qBAAAA;AASX,CAAA,CAAA,EAAA;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolbarDiagnosticSeverity.d.ts","sourceRoot":"","sources":["../../../toolbar/ToolbarDiagnosticSeverity.ts"],"names":[],"mappings":"AAMA,oBAAY,yBAAyB;IAEjC,KAAK,UAAU;IAGf,OAAO,YAAY;CACtB"}
|
|
@@ -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
|
+
/**
|
|
4
|
+
* How serious a toolbar diagnostic is.
|
|
5
|
+
*/ var ToolbarDiagnosticSeverity = /*#__PURE__*/ function(ToolbarDiagnosticSeverity) {
|
|
6
|
+
/** The button cannot work. */ ToolbarDiagnosticSeverity["Error"] = "error";
|
|
7
|
+
/** The button is allowed but incomplete. */ ToolbarDiagnosticSeverity["Warning"] = "warning";
|
|
8
|
+
return ToolbarDiagnosticSeverity;
|
|
9
|
+
}({});
|
|
10
|
+
|
|
11
|
+
export { ToolbarDiagnosticSeverity };
|
|
12
|
+
//# sourceMappingURL=ToolbarDiagnosticSeverity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolbarDiagnosticSeverity.js","sources":["../../../toolbar/ToolbarDiagnosticSeverity.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/**\n * How serious a toolbar diagnostic is.\n */\nexport enum ToolbarDiagnosticSeverity {\n /** The button cannot work. */\n Error = 'error',\n\n /** The button is allowed but incomplete. */\n Warning = 'warning',\n}\n"],"names":["ToolbarDiagnosticSeverity"],"mappings":"AAAA;AACA;AAEA;;IAGO,IAAKA,yBAAAA,iBAAAA,SAAAA,yBAAAA,EAAAA;mCACoB,yBAAA,CAAA,OAAA,CAAA,GAAA,OAAA;iDAGc,yBAAA,CAAA,SAAA,CAAA,GAAA,SAAA;AAJlCA,IAAAA,OAAAA,yBAAAA;AAMX,CAAA,CAAA,EAAA;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './ToolbarDiagnosticCode';
|
|
2
|
+
export * from './ToolbarDiagnosticSeverity';
|
|
3
|
+
export * from './ToolbarDiagnostic';
|
|
4
|
+
export * from './SliceDialogSource';
|
|
5
|
+
export * from './SliceDialog';
|
|
6
|
+
export * from './ResolvedToolbarButton';
|
|
7
|
+
export * from './sliceDialogFor';
|
|
8
|
+
export * from './toolbarButtons';
|
|
9
|
+
export * from './validateToolbarButtons';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../toolbar/index.ts"],"names":[],"mappings":"AAGA,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './ToolbarDiagnosticCode';
|
|
2
|
+
export * from './ToolbarDiagnosticSeverity';
|
|
3
|
+
export * from './ToolbarDiagnostic';
|
|
4
|
+
export * from './SliceDialogSource';
|
|
5
|
+
export * from './SliceDialog';
|
|
6
|
+
export * from './ResolvedToolbarButton';
|
|
7
|
+
export * from './sliceDialogFor';
|
|
8
|
+
export * from './toolbarButtons';
|
|
9
|
+
export * from './validateToolbarButtons';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../toolbar/index.ts"],"names":[],"mappings":"AAGA,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ApplicationStructureIndex } from '../structure';
|
|
2
|
+
import { SliceDialog } from './SliceDialog';
|
|
3
|
+
export declare const defaultSliceDialogTemplate = "FormDialog";
|
|
4
|
+
export declare function sliceDialogFor(index: ApplicationStructureIndex, sliceId: string, defaultTemplate?: string): SliceDialog | undefined;
|
|
5
|
+
//# sourceMappingURL=sliceDialogFor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sliceDialogFor.d.ts","sourceRoot":"","sources":["../../../toolbar/sliceDialogFor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAI5C,eAAO,MAAM,0BAA0B,eAAe,CAAC;AAavD,wBAAgB,cAAc,CAAC,KAAK,EAAE,yBAAyB,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAQnI"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { SliceKind } from '@cratis/scene.model';
|
|
2
|
+
import { SliceDialogSource } from './SliceDialogSource.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
|
+
/** The dialog template used when a slice names none. */ const defaultSliceDialogTemplate = 'FormDialog';
|
|
7
|
+
/**
|
|
8
|
+
* Works out the task dialog a state change slice opens, once, so no host decides it again (TB4): the slice's own
|
|
9
|
+
* dialog template when it names one, else the default form dialog.
|
|
10
|
+
*
|
|
11
|
+
* The C# engine (`SliceDialogs.For`) resolves the same dialog; both are asserted against `toolbar-slice-fixtures.json`.
|
|
12
|
+
*
|
|
13
|
+
* @param index The modules, features and slices of the application.
|
|
14
|
+
* @param sliceId The slice's qualified id.
|
|
15
|
+
* @param defaultTemplate The template used when the slice names none; {@link defaultSliceDialogTemplate} when absent.
|
|
16
|
+
* @returns The dialog, or undefined when there is no such slice or it is not a state change.
|
|
17
|
+
*/ function sliceDialogFor(index, sliceId, defaultTemplate) {
|
|
18
|
+
const slice = index.findSlice(sliceId);
|
|
19
|
+
if (slice?.kind !== SliceKind.StateChange) return undefined;
|
|
20
|
+
const command = slice.command ?? slice.id;
|
|
21
|
+
return slice.dialogTemplate ? {
|
|
22
|
+
slice: sliceId,
|
|
23
|
+
command,
|
|
24
|
+
template: slice.dialogTemplate,
|
|
25
|
+
source: SliceDialogSource.Slice
|
|
26
|
+
} : {
|
|
27
|
+
slice: sliceId,
|
|
28
|
+
command,
|
|
29
|
+
template: defaultTemplate ?? defaultSliceDialogTemplate,
|
|
30
|
+
source: SliceDialogSource.Default
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { defaultSliceDialogTemplate, sliceDialogFor };
|
|
35
|
+
//# sourceMappingURL=sliceDialogFor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sliceDialogFor.js","sources":["../../../toolbar/sliceDialogFor.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 { SliceKind } from '@cratis/scene.model';\nimport { ApplicationStructureIndex } from '../structure';\nimport { SliceDialog } from './SliceDialog';\nimport { SliceDialogSource } from './SliceDialogSource';\n\n/** The dialog template used when a slice names none. */\nexport const defaultSliceDialogTemplate = 'FormDialog';\n\n/**\n * Works out the task dialog a state change slice opens, once, so no host decides it again (TB4): the slice's own\n * dialog template when it names one, else the default form dialog.\n *\n * The C# engine (`SliceDialogs.For`) resolves the same dialog; both are asserted against `toolbar-slice-fixtures.json`.\n *\n * @param index The modules, features and slices of the application.\n * @param sliceId The slice's qualified id.\n * @param defaultTemplate The template used when the slice names none; {@link defaultSliceDialogTemplate} when absent.\n * @returns The dialog, or undefined when there is no such slice or it is not a state change.\n */\nexport function sliceDialogFor(index: ApplicationStructureIndex, sliceId: string, defaultTemplate?: string): SliceDialog | undefined {\n const slice = index.findSlice(sliceId);\n if (slice?.kind !== SliceKind.StateChange) return undefined;\n\n const command = slice.command ?? slice.id;\n return slice.dialogTemplate\n ? { slice: sliceId, command, template: slice.dialogTemplate, source: SliceDialogSource.Slice }\n : { slice: sliceId, command, template: defaultTemplate ?? defaultSliceDialogTemplate, source: SliceDialogSource.Default };\n}\n"],"names":["defaultSliceDialogTemplate","sliceDialogFor","index","sliceId","defaultTemplate","slice","findSlice","kind","SliceKind","StateChange","undefined","command","id","dialogTemplate","template","source","SliceDialogSource","Slice","Default"],"mappings":";;;AAAA;AACA;AAOA,yDACO,MAAMA,0BAAAA,GAA6B;AAE1C;;;;;;;;;;AAUC,IACM,SAASC,cAAAA,CAAeC,KAAgC,EAAEC,OAAe,EAAEC,eAAwB,EAAA;IACtG,MAAMC,KAAAA,GAAQH,KAAAA,CAAMI,SAAS,CAACH,OAAAA,CAAAA;AAC9B,IAAA,IAAIE,KAAAA,EAAOE,IAAAA,KAASC,SAAAA,CAAUC,WAAW,EAAE,OAAOC,SAAAA;AAElD,IAAA,MAAMC,OAAAA,GAAUN,KAAAA,CAAMM,OAAO,IAAIN,MAAMO,EAAE;IACzC,OAAOP,KAAAA,CAAMQ,cAAc,GACrB;QAAER,KAAAA,EAAOF,OAAAA;AAASQ,QAAAA,OAAAA;AAASG,QAAAA,QAAAA,EAAUT,MAAMQ,cAAc;AAAEE,QAAAA,MAAAA,EAAQC,kBAAkBC;KAAM,GAC3F;QAAEZ,KAAAA,EAAOF,OAAAA;AAASQ,QAAAA,OAAAA;AAASG,QAAAA,QAAAA,EAAUV,eAAAA,IAAmBJ,0BAAAA;AAA4Be,QAAAA,MAAAA,EAAQC,kBAAkBE;AAAQ,KAAA;AAChI;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ToolbarButton } from '@cratis/scene.model';
|
|
2
|
+
import { ApplicationStructureIndex } from '../structure';
|
|
3
|
+
import { ResolvedToolbarButton } from './ResolvedToolbarButton';
|
|
4
|
+
export declare function toolbarButtonFromItem(id: string, properties: Record<string, unknown>): ToolbarButton | undefined;
|
|
5
|
+
export declare function normalizeToolbarButton(index: ApplicationStructureIndex, button: ToolbarButton): {
|
|
6
|
+
button: ToolbarButton;
|
|
7
|
+
converted: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare function resolveToolbarButton(index: ApplicationStructureIndex, button: ToolbarButton, defaultDialogTemplate?: string): ResolvedToolbarButton;
|
|
10
|
+
//# sourceMappingURL=toolbarButtons.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolbarButtons.d.ts","sourceRoot":"","sources":["../../../toolbar/toolbarButtons.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAmB,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAkBhE,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,GAAG,SAAS,CAiBhH;AASD,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,yBAAyB,EAAE,MAAM,EAAE,aAAa,GAAG;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAS7I;AAYD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,EAAE,MAAM,EAAE,aAAa,EAAE,qBAAqB,CAAC,EAAE,MAAM,GAAG,qBAAqB,CAYnJ"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { ToolbarEmphasis } from '@cratis/scene.model';
|
|
2
|
+
import { sliceDialogFor } from './sliceDialogFor.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
|
+
function text(properties, name) {
|
|
7
|
+
const value = properties[name];
|
|
8
|
+
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Reads a button from the properties of a `core:toolbarItem` element: `label` (or `name`), `kind`, `slice`,
|
|
12
|
+
* `emphasis`, `icon` and `target`.
|
|
13
|
+
*
|
|
14
|
+
* The C# engine (`ToolbarButtons.FromItem`) reads the same; both are asserted against `toolbar-slice-fixtures.json`.
|
|
15
|
+
*
|
|
16
|
+
* @param id The element id.
|
|
17
|
+
* @param properties The element properties.
|
|
18
|
+
* @returns The button, or undefined when the item does not invoke a command or slice - a navigate or dialog item.
|
|
19
|
+
*/ function toolbarButtonFromItem(id, properties) {
|
|
20
|
+
const slice = text(properties, 'slice');
|
|
21
|
+
const action = text(properties, 'kind')?.toLowerCase() === 'action';
|
|
22
|
+
if (slice === undefined && !action) return undefined;
|
|
23
|
+
const button = {
|
|
24
|
+
id,
|
|
25
|
+
title: text(properties, 'label') ?? text(properties, 'name') ?? id
|
|
26
|
+
};
|
|
27
|
+
if (slice !== undefined) button.slice = slice;
|
|
28
|
+
const emphasis = text(properties, 'emphasis')?.toLowerCase();
|
|
29
|
+
if (emphasis === ToolbarEmphasis.Primary || emphasis === ToolbarEmphasis.Secondary || emphasis === ToolbarEmphasis.Quiet) button.emphasis = emphasis;
|
|
30
|
+
const icon = text(properties, 'icon');
|
|
31
|
+
if (icon !== undefined) button.icon = icon;
|
|
32
|
+
const target = text(properties, 'target');
|
|
33
|
+
if (target !== undefined) button.target = target;
|
|
34
|
+
return button;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Converts a hand-authored button to a slice-backed one: a button with no slice whose command is accepted by exactly
|
|
38
|
+
* one state change slice names that slice instead.
|
|
39
|
+
* @param index The modules, features and slices of the application.
|
|
40
|
+
* @param button The button.
|
|
41
|
+
* @returns The button to use, and whether it was converted. A button that cannot be converted is returned as it is.
|
|
42
|
+
*/ function normalizeToolbarButton(index, button) {
|
|
43
|
+
if (button.slice || !button.target) return {
|
|
44
|
+
button,
|
|
45
|
+
converted: false
|
|
46
|
+
};
|
|
47
|
+
const matches = index.findSlicesByCommand(button.target);
|
|
48
|
+
if (matches.length !== 1) return {
|
|
49
|
+
button,
|
|
50
|
+
converted: false
|
|
51
|
+
};
|
|
52
|
+
const { target, ...rest } = button;
|
|
53
|
+
return {
|
|
54
|
+
button: {
|
|
55
|
+
...rest,
|
|
56
|
+
slice: matches[0]
|
|
57
|
+
},
|
|
58
|
+
converted: true
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Resolves a button: its slice, command and task dialog, without any rendering. This is what a renderer, Stage and the
|
|
63
|
+
* Studio preview call.
|
|
64
|
+
*
|
|
65
|
+
* The C# engine (`ToolbarButtons.Resolve`) resolves the same; both are asserted against `toolbar-slice-fixtures.json`.
|
|
66
|
+
*
|
|
67
|
+
* @param index The modules, features and slices of the application.
|
|
68
|
+
* @param button The button.
|
|
69
|
+
* @param defaultDialogTemplate The dialog template used when a slice names none.
|
|
70
|
+
*/ function resolveToolbarButton(index, button, defaultDialogTemplate) {
|
|
71
|
+
const { button: normalized, converted } = normalizeToolbarButton(index, button);
|
|
72
|
+
const dialog = normalized.slice ? sliceDialogFor(index, normalized.slice, defaultDialogTemplate) : undefined;
|
|
73
|
+
const resolved = {
|
|
74
|
+
id: normalized.id,
|
|
75
|
+
title: normalized.title,
|
|
76
|
+
emphasis: normalized.emphasis ?? ToolbarEmphasis.Secondary,
|
|
77
|
+
converted
|
|
78
|
+
};
|
|
79
|
+
if (normalized.icon !== undefined) resolved.icon = normalized.icon;
|
|
80
|
+
if (normalized.slice) resolved.slice = normalized.slice;
|
|
81
|
+
if (dialog) {
|
|
82
|
+
resolved.command = dialog.command;
|
|
83
|
+
resolved.dialog = dialog;
|
|
84
|
+
}
|
|
85
|
+
return resolved;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { normalizeToolbarButton, resolveToolbarButton, toolbarButtonFromItem };
|
|
89
|
+
//# sourceMappingURL=toolbarButtons.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolbarButtons.js","sources":["../../../toolbar/toolbarButtons.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 { ToolbarButton, ToolbarEmphasis } from '@cratis/scene.model';\nimport { ApplicationStructureIndex } from '../structure';\nimport { ResolvedToolbarButton } from './ResolvedToolbarButton';\nimport { sliceDialogFor } from './sliceDialogFor';\n\nfunction text(properties: Record<string, unknown>, name: string): string | undefined {\n const value = properties[name];\n return typeof value === 'string' && value.length > 0 ? value : undefined;\n}\n\n/**\n * Reads a button from the properties of a `core:toolbarItem` element: `label` (or `name`), `kind`, `slice`,\n * `emphasis`, `icon` and `target`.\n *\n * The C# engine (`ToolbarButtons.FromItem`) reads the same; both are asserted against `toolbar-slice-fixtures.json`.\n *\n * @param id The element id.\n * @param properties The element properties.\n * @returns The button, or undefined when the item does not invoke a command or slice - a navigate or dialog item.\n */\nexport function toolbarButtonFromItem(id: string, properties: Record<string, unknown>): ToolbarButton | undefined {\n const slice = text(properties, 'slice');\n const action = text(properties, 'kind')?.toLowerCase() === 'action';\n if (slice === undefined && !action) return undefined;\n\n const button: ToolbarButton = { id, title: text(properties, 'label') ?? text(properties, 'name') ?? id };\n if (slice !== undefined) button.slice = slice;\n\n const emphasis = text(properties, 'emphasis')?.toLowerCase();\n if (emphasis === ToolbarEmphasis.Primary || emphasis === ToolbarEmphasis.Secondary || emphasis === ToolbarEmphasis.Quiet) button.emphasis = emphasis;\n\n const icon = text(properties, 'icon');\n if (icon !== undefined) button.icon = icon;\n\n const target = text(properties, 'target');\n if (target !== undefined) button.target = target;\n return button;\n}\n\n/**\n * Converts a hand-authored button to a slice-backed one: a button with no slice whose command is accepted by exactly\n * one state change slice names that slice instead.\n * @param index The modules, features and slices of the application.\n * @param button The button.\n * @returns The button to use, and whether it was converted. A button that cannot be converted is returned as it is.\n */\nexport function normalizeToolbarButton(index: ApplicationStructureIndex, button: ToolbarButton): { button: ToolbarButton; converted: boolean } {\n if (button.slice || !button.target) return { button, converted: false };\n\n const matches = index.findSlicesByCommand(button.target);\n if (matches.length !== 1) return { button, converted: false };\n\n const { target, ...rest } = button;\n void target;\n return { button: { ...rest, slice: matches[0] }, converted: true };\n}\n\n/**\n * Resolves a button: its slice, command and task dialog, without any rendering. This is what a renderer, Stage and the\n * Studio preview call.\n *\n * The C# engine (`ToolbarButtons.Resolve`) resolves the same; both are asserted against `toolbar-slice-fixtures.json`.\n *\n * @param index The modules, features and slices of the application.\n * @param button The button.\n * @param defaultDialogTemplate The dialog template used when a slice names none.\n */\nexport function resolveToolbarButton(index: ApplicationStructureIndex, button: ToolbarButton, defaultDialogTemplate?: string): ResolvedToolbarButton {\n const { button: normalized, converted } = normalizeToolbarButton(index, button);\n const dialog = normalized.slice ? sliceDialogFor(index, normalized.slice, defaultDialogTemplate) : undefined;\n const resolved: ResolvedToolbarButton = { id: normalized.id, title: normalized.title, emphasis: normalized.emphasis ?? ToolbarEmphasis.Secondary, converted };\n if (normalized.icon !== undefined) resolved.icon = normalized.icon;\n if (normalized.slice) resolved.slice = normalized.slice;\n if (dialog) {\n resolved.command = dialog.command;\n resolved.dialog = dialog;\n }\n\n return resolved;\n}\n"],"names":["text","properties","name","value","length","undefined","toolbarButtonFromItem","id","slice","action","toLowerCase","button","title","emphasis","ToolbarEmphasis","Primary","Secondary","Quiet","icon","target","normalizeToolbarButton","index","converted","matches","findSlicesByCommand","rest","resolveToolbarButton","defaultDialogTemplate","normalized","dialog","sliceDialogFor","resolved","command"],"mappings":";;;AAAA;AACA;AAOA,SAASA,IAAAA,CAAKC,UAAmC,EAAEC,IAAY,EAAA;IAC3D,MAAMC,KAAAA,GAAQF,UAAU,CAACC,IAAAA,CAAK;AAC9B,IAAA,OAAO,OAAOC,KAAAA,KAAU,QAAA,IAAYA,MAAMC,MAAM,GAAG,IAAID,KAAAA,GAAQE,SAAAA;AACnE;AAEA;;;;;;;;;AASC,IACM,SAASC,qBAAAA,C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B,KAAK,GAAGoB,WAAWpB,KAAK;AACvD,IAAA,IAAIqB,MAAAA,EAAQ;QACRE,QAAAA,CAASC,OAAO,GAAGH,MAAAA,CAAOG,OAAO;AACjCD,QAAAA,QAAAA,CAASF,MAAM,GAAGA,MAAAA;AACtB,IAAA;IAEA,OAAOE,QAAAA;AACX;;"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ApplicationStructure, Toolbar } from '@cratis/scene.model';
|
|
2
|
+
import { ApplicationStructureIndex } from '../structure';
|
|
3
|
+
import { ToolbarDiagnostic } from './ToolbarDiagnostic';
|
|
4
|
+
export declare function validateToolbarButtons(structure: ApplicationStructure | ApplicationStructureIndex, toolbar: Toolbar): ToolbarDiagnostic[];
|
|
5
|
+
//# sourceMappingURL=validateToolbarButtons.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateToolbarButtons.d.ts","sourceRoot":"","sources":["../../../toolbar/validateToolbarButtons.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAa,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAiBxD,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,oBAAoB,GAAG,yBAAyB,EAAE,OAAO,EAAE,OAAO,GAAG,iBAAiB,EAAE,CAsCzI"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { SliceKind } from '@cratis/scene.model';
|
|
2
|
+
import { ApplicationStructureIndex } from '../structure/ApplicationStructureIndex.js';
|
|
3
|
+
import { ToolbarDiagnosticCode } from './ToolbarDiagnosticCode.js';
|
|
4
|
+
import { ToolbarDiagnosticSeverity } from './ToolbarDiagnosticSeverity.js';
|
|
5
|
+
import { normalizeToolbarButton } from './toolbarButtons.js';
|
|
6
|
+
|
|
7
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
8
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
9
|
+
/**
|
|
10
|
+
* Validates the buttons of a toolbar against the application structure: a button must invoke a state change slice
|
|
11
|
+
* (TB3), and a button without a slice is allowed but flagged (TB5). A hand-authored button that names a command is
|
|
12
|
+
* converted first, and a button whose command no single slice accepts is a legacy button that still validates.
|
|
13
|
+
*
|
|
14
|
+
* The C# engine (`ToolbarButtonValidation.Validate`) reports the same codes, severities and messages in the same
|
|
15
|
+
* order; both are asserted against `toolbar-slice-fixtures.json`.
|
|
16
|
+
*
|
|
17
|
+
* @param structure The modules, features and slices of the application.
|
|
18
|
+
* @param toolbar The toolbar.
|
|
19
|
+
* @returns The problems found, in button order.
|
|
20
|
+
*/ function validateToolbarButtons(structure, toolbar) {
|
|
21
|
+
const index = structure instanceof ApplicationStructureIndex ? structure : new ApplicationStructureIndex(structure);
|
|
22
|
+
const diagnostics = [];
|
|
23
|
+
for (const authored of toolbar.buttons){
|
|
24
|
+
const { button } = normalizeToolbarButton(index, authored);
|
|
25
|
+
if (!button.slice) {
|
|
26
|
+
if (!button.target) {
|
|
27
|
+
diagnostics.push({
|
|
28
|
+
code: ToolbarDiagnosticCode.ToolbarButtonSliceEmpty,
|
|
29
|
+
severity: ToolbarDiagnosticSeverity.Warning,
|
|
30
|
+
message: `Toolbar button '${button.id}' has no slice to invoke.`,
|
|
31
|
+
button: button.id
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const slice = index.findSlice(button.slice);
|
|
37
|
+
if (!slice) {
|
|
38
|
+
diagnostics.push({
|
|
39
|
+
code: ToolbarDiagnosticCode.ToolbarButtonSliceNotFound,
|
|
40
|
+
severity: ToolbarDiagnosticSeverity.Error,
|
|
41
|
+
message: `Toolbar button '${button.id}' invokes slice '${button.slice}', which does not exist.`,
|
|
42
|
+
button: button.id
|
|
43
|
+
});
|
|
44
|
+
} else if (slice.kind !== SliceKind.StateChange) {
|
|
45
|
+
diagnostics.push({
|
|
46
|
+
code: ToolbarDiagnosticCode.ToolbarButtonSliceNotStateChange,
|
|
47
|
+
severity: ToolbarDiagnosticSeverity.Error,
|
|
48
|
+
message: `Toolbar button '${button.id}' invokes slice '${button.slice}', which is ${slice.kind === SliceKind.StateView ? 'a state view' : 'an automation'}; only a state change can be invoked from a toolbar.`,
|
|
49
|
+
button: button.id
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return diagnostics;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { validateToolbarButtons };
|
|
57
|
+
//# sourceMappingURL=validateToolbarButtons.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateToolbarButtons.js","sources":["../../../toolbar/validateToolbarButtons.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 { ApplicationStructure, SliceKind, Toolbar } from '@cratis/scene.model';\nimport { ApplicationStructureIndex } from '../structure';\nimport { ToolbarDiagnostic } from './ToolbarDiagnostic';\nimport { ToolbarDiagnosticCode } from './ToolbarDiagnosticCode';\nimport { ToolbarDiagnosticSeverity } from './ToolbarDiagnosticSeverity';\nimport { normalizeToolbarButton } from './toolbarButtons';\n\n/**\n * Validates the buttons of a toolbar against the application structure: a button must invoke a state change slice\n * (TB3), and a button without a slice is allowed but flagged (TB5). A hand-authored button that names a command is\n * converted first, and a button whose command no single slice accepts is a legacy button that still validates.\n *\n * The C# engine (`ToolbarButtonValidation.Validate`) reports the same codes, severities and messages in the same\n * order; both are asserted against `toolbar-slice-fixtures.json`.\n *\n * @param structure The modules, features and slices of the application.\n * @param toolbar The toolbar.\n * @returns The problems found, in button order.\n */\nexport function validateToolbarButtons(structure: ApplicationStructure | ApplicationStructureIndex, toolbar: Toolbar): ToolbarDiagnostic[] {\n const index = structure instanceof ApplicationStructureIndex ? structure : new ApplicationStructureIndex(structure);\n const diagnostics: ToolbarDiagnostic[] = [];\n\n for (const authored of toolbar.buttons) {\n const { button } = normalizeToolbarButton(index, authored);\n if (!button.slice) {\n if (!button.target) {\n diagnostics.push({\n code: ToolbarDiagnosticCode.ToolbarButtonSliceEmpty,\n severity: ToolbarDiagnosticSeverity.Warning,\n message: `Toolbar button '${button.id}' has no slice to invoke.`,\n button: button.id,\n });\n }\n\n continue;\n }\n\n const slice = index.findSlice(button.slice);\n if (!slice) {\n diagnostics.push({\n code: ToolbarDiagnosticCode.ToolbarButtonSliceNotFound,\n severity: ToolbarDiagnosticSeverity.Error,\n message: `Toolbar button '${button.id}' invokes slice '${button.slice}', which does not exist.`,\n button: button.id,\n });\n } else if (slice.kind !== SliceKind.StateChange) {\n diagnostics.push({\n code: ToolbarDiagnosticCode.ToolbarButtonSliceNotStateChange,\n severity: ToolbarDiagnosticSeverity.Error,\n message: `Toolbar button '${button.id}' invokes slice '${button.slice}', which is ${slice.kind === SliceKind.StateView ? 'a state view' : 'an automation'}; only a state change can be invoked from a toolbar.`,\n button: button.id,\n });\n }\n }\n\n return diagnostics;\n}\n"],"names":["validateToolbarButtons","structure","toolbar","index","ApplicationStructureIndex","diagnostics","authored","buttons","button","normalizeToolbarButton","slice","target","push","code","ToolbarDiagnosticCode","ToolbarButtonSliceEmpty","severity","ToolbarDiagnosticSeverity","Warning","message","id","findSlice","ToolbarButtonSliceNotFound","Error","kind","SliceKind","StateChange","ToolbarButtonSliceNotStateChange","StateView"],"mappings":";;;;;;AAAA;AACA;AASA;;;;;;;;;;;AAWC,IACM,SAASA,sBAAAA,CAAuBC,SAA2D,EAAEC,OAAgB,EAAA;AAChH,IAAA,MAAMC,KAAAA,GAAQF,SAAAA,YAAqBG,yBAAAA,GAA4BH,SAAAA,GAAY,IAAIG,yBAAAA,CAA0BH,SAAAA,CAAAA;AACzG,IAAA,MAAMI,cAAmC,EAAE;AAE3C,IAAA,KAAK,MAAMC,QAAAA,IAAYJ,OAAAA,CAAQK,OAAO,CA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