@cratis/scene.components 4.8.0 → 4.9.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/cratisComponentsDescriptors.ts +53 -1
- package/cratisComponentsPackage.ts +15 -0
- package/dist/cjs/cratisComponentsDescriptors.js +150 -0
- package/dist/cjs/cratisComponentsDescriptors.js.map +1 -1
- package/dist/cjs/cratisComponentsPackage.js +32 -2
- package/dist/cjs/cratisComponentsPackage.js.map +1 -1
- package/dist/cjs/forms/CommandFormRuntime.js +11 -4
- package/dist/cjs/forms/CommandFormRuntime.js.map +1 -1
- package/dist/cjs/forms/ExplicitCommandField.js +13 -7
- package/dist/cjs/forms/ExplicitCommandField.js.map +1 -1
- package/dist/cjs/forms/SceneCommandForm.js +10 -3
- package/dist/cjs/forms/SceneCommandForm.js.map +1 -1
- package/dist/cjs/forms/commandInputs.js +8 -2
- package/dist/cjs/forms/commandInputs.js.map +1 -1
- package/dist/cjs/forms/generateCommandFieldsAction.js +58 -0
- package/dist/cjs/forms/generateCommandFieldsAction.js.map +1 -0
- package/dist/esm/cratisComponentsDescriptors.d.ts.map +1 -1
- package/dist/esm/cratisComponentsDescriptors.js +151 -1
- package/dist/esm/cratisComponentsDescriptors.js.map +1 -1
- package/dist/esm/cratisComponentsPackage.d.ts.map +1 -1
- package/dist/esm/cratisComponentsPackage.js +32 -2
- package/dist/esm/cratisComponentsPackage.js.map +1 -1
- package/dist/esm/forms/CommandFormRuntime.d.ts +2 -1
- package/dist/esm/forms/CommandFormRuntime.d.ts.map +1 -1
- package/dist/esm/forms/CommandFormRuntime.js +11 -4
- package/dist/esm/forms/CommandFormRuntime.js.map +1 -1
- package/dist/esm/forms/ExplicitCommandField.d.ts.map +1 -1
- package/dist/esm/forms/ExplicitCommandField.js +13 -7
- package/dist/esm/forms/ExplicitCommandField.js.map +1 -1
- package/dist/esm/forms/SceneCommandForm.d.ts.map +1 -1
- package/dist/esm/forms/SceneCommandForm.js +11 -4
- package/dist/esm/forms/SceneCommandForm.js.map +1 -1
- package/dist/esm/forms/commandInputs.d.ts +2 -0
- package/dist/esm/forms/commandInputs.d.ts.map +1 -1
- package/dist/esm/forms/commandInputs.js +9 -3
- package/dist/esm/forms/commandInputs.js.map +1 -1
- package/dist/esm/forms/generateCommandFieldsAction.d.ts +3 -0
- package/dist/esm/forms/generateCommandFieldsAction.d.ts.map +1 -0
- package/dist/esm/forms/generateCommandFieldsAction.js +56 -0
- package/dist/esm/forms/generateCommandFieldsAction.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/forms/CommandFormRuntime.tsx +5 -2
- package/forms/ExplicitCommandField.tsx +4 -2
- package/forms/SceneCommandForm.tsx +5 -3
- package/forms/commandInputs.ts +7 -3
- package/forms/generateCommandFieldsAction.ts +46 -0
- package/package.json +7 -7
|
@@ -4,7 +4,7 @@ import { BindingKind } from '../bindings/BindingKind.js';
|
|
|
4
4
|
import { resolveElementBinding } from '../bindings/resolveElementBinding.js';
|
|
5
5
|
import { MissingBinding } from '../bindings/MissingBinding.js';
|
|
6
6
|
import { ArcRuntimeBoundary } from '../bindings/ArcRuntimeBoundary.js';
|
|
7
|
-
import { stringProperty, stringArrayProperty } from '../properties.js';
|
|
7
|
+
import { unionProperty, numberProperty, stringProperty, stringArrayProperty } from '../properties.js';
|
|
8
8
|
import { commandInputs } from './commandInputs.js';
|
|
9
9
|
|
|
10
10
|
const CommandFormRuntime = /*#__PURE__*/ lazy(()=>import('./CommandFormRuntime.js'));
|
|
@@ -30,8 +30,12 @@ function commandKey(command) {
|
|
|
30
30
|
kind: BindingKind.Command,
|
|
31
31
|
name: name
|
|
32
32
|
});
|
|
33
|
-
const
|
|
34
|
-
|
|
33
|
+
const mode = unionProperty(element.properties, 'mode', [
|
|
34
|
+
'auto',
|
|
35
|
+
'manual'
|
|
36
|
+
]) ?? (Object.hasOwn(element.properties, 'inputs') ? 'manual' : 'auto');
|
|
37
|
+
const inputs = mode === 'manual' ? commandInputs(element.properties) : undefined;
|
|
38
|
+
if (mode === 'manual' && !inputs) return /*#__PURE__*/ jsx("div", {
|
|
35
39
|
role: "alert",
|
|
36
40
|
children: "Invalid command form inputs declaration"
|
|
37
41
|
});
|
|
@@ -40,7 +44,10 @@ function commandKey(command) {
|
|
|
40
44
|
command: target,
|
|
41
45
|
inputs: inputs,
|
|
42
46
|
exclude: stringArrayProperty(element.properties, 'exclude'),
|
|
43
|
-
submitLabel: stringProperty(element.properties, 'submitLabel') ?? 'Submit'
|
|
47
|
+
submitLabel: stringProperty(element.properties, 'submitLabel') ?? 'Submit',
|
|
48
|
+
...numberProperty(element.properties, 'columns') === undefined ? {} : {
|
|
49
|
+
columns: numberProperty(element.properties, 'columns')
|
|
50
|
+
}
|
|
44
51
|
}, commandKey(target))
|
|
45
52
|
});
|
|
46
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SceneCommandForm.js","sources":["../../../forms/SceneCommandForm.tsx"],"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 { lazy } from 'react';\nimport { RegisteredComponentProps } from '@cratis/scene.react';\nimport { ArcRuntimeBoundary, BindingKind, MissingBinding, resolveElementBinding } from '../bindings';\nimport type { BoundConstructor } from '../bindings';\nimport { stringArrayProperty, stringProperty } from '../properties';\nimport { commandInputs } from './commandInputs';\n\nconst CommandFormRuntime = lazy(() => import('./CommandFormRuntime'));\n\n// Arc's useCommand constructs the proxy only on mount. Key by the actual registered class,\n// not its Scene name (which may be re-registered with a different route or roles).\nconst commandKeys = new WeakMap<BoundConstructor, number>();\nlet nextCommandKey = 0;\nfunction commandKey(command: BoundConstructor): number {\n let key = commandKeys.get(command);\n if (key === undefined) {\n key = ++nextCommandKey;\n commandKeys.set(command, key);\n }\n return key;\n}\n\n/**\n * Auto mode follows supported native proxy descriptors; opt-in inputs bind exactly named fields\n * inside a single native Arc form. Neither mode consumes the content slot.\n */\nexport function SceneCommandForm({ element }: RegisteredComponentProps) {\n const { name, target } = resolveElementBinding(element, BindingKind.Command);\n if (!target) return <MissingBinding element={element} kind={BindingKind.Command} name={name} />;\n\n const
|
|
1
|
+
{"version":3,"file":"SceneCommandForm.js","sources":["../../../forms/SceneCommandForm.tsx"],"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 { lazy } from 'react';\nimport { RegisteredComponentProps } from '@cratis/scene.react';\nimport { ArcRuntimeBoundary, BindingKind, MissingBinding, resolveElementBinding } from '../bindings';\nimport type { BoundConstructor } from '../bindings';\nimport { numberProperty, stringArrayProperty, stringProperty, unionProperty } from '../properties';\nimport { commandInputs } from './commandInputs';\n\nconst CommandFormRuntime = lazy(() => import('./CommandFormRuntime'));\n\n// Arc's useCommand constructs the proxy only on mount. Key by the actual registered class,\n// not its Scene name (which may be re-registered with a different route or roles).\nconst commandKeys = new WeakMap<BoundConstructor, number>();\nlet nextCommandKey = 0;\nfunction commandKey(command: BoundConstructor): number {\n let key = commandKeys.get(command);\n if (key === undefined) {\n key = ++nextCommandKey;\n commandKeys.set(command, key);\n }\n return key;\n}\n\n/**\n * Auto mode follows supported native proxy descriptors; opt-in inputs bind exactly named fields\n * inside a single native Arc form. Neither mode consumes the content slot.\n */\nexport function SceneCommandForm({ element }: RegisteredComponentProps) {\n const { name, target } = resolveElementBinding(element, BindingKind.Command);\n if (!target) return <MissingBinding element={element} kind={BindingKind.Command} name={name} />;\n\n const mode = unionProperty(element.properties, 'mode', ['auto', 'manual'] as const) ?? (Object.hasOwn(element.properties, 'inputs') ? 'manual' : 'auto');\n const inputs = mode === 'manual' ? commandInputs(element.properties) : undefined;\n if (mode === 'manual' && !inputs) return <div role='alert'>Invalid command form inputs declaration</div>;\n\n return (\n <ArcRuntimeBoundary>\n <CommandFormRuntime\n key={commandKey(target)}\n command={target}\n inputs={inputs}\n exclude={stringArrayProperty(element.properties, 'exclude')}\n submitLabel={stringProperty(element.properties, 'submitLabel') ?? 'Submit'}\n {...(numberProperty(element.properties, 'columns') === undefined ? {} : { columns: numberProperty(element.properties, 'columns') })}\n />\n </ArcRuntimeBoundary>\n );\n}\n"],"names":["CommandFormRuntime","lazy","commandKeys","WeakMap","nextCommandKey","commandKey","command","key","get","undefined","set","SceneCommandForm","element","name","target","resolveElementBinding","BindingKind","Command","_jsx","MissingBinding","kind","mode","unionProperty","properties","Object","hasOwn","inputs","commandInputs","div","role","ArcRuntimeBoundary","exclude","stringArrayProperty","submitLabel","stringProperty","numberProperty","columns"],"mappings":";;;;;;;;;AAUA,MAAMA,kBAAAA,iBAAqBC,IAAAA,CAAK,IAAM,OAAO,yBAAA,CAAA,CAAA;AAE7C;AACA;AACA,MAAMC,cAAc,IAAIC,OAAAA,EAAAA;AACxB,IAAIC,cAAAA,GAAiB,CAAA;AACrB,SAASC,WAAWC,OAAyB,EAAA;IACzC,IAAIC,GAAAA,GAAML,WAAAA,CAAYM,GAAG,CAACF,OAAAA,CAAAA;AAC1B,IAAA,IAAIC,QAAQE,SAAAA,EAAW;AACnBF,QAAAA,GAAAA,GAAM,EAAEH,cAAAA;QACRF,WAAAA,CAAYQ,GAAG,CAACJ,OAAAA,EAASC,GAAAA,CAAAA;AAC7B,IAAA;IACA,OAAOA,GAAAA;AACX;AAEA;;;AAGC,IACM,SAASI,gBAAAA,CAAiB,EAAEC,OAAO,EAA4B,EAAA;IAClE,MAAM,EAAEC,IAAI,EAAEC,MAAM,EAAE,GAAGC,qBAAAA,CAAsBH,OAAAA,EAASI,WAAAA,CAAYC,OAAO,CAAA;IAC3E,IAAI,CAACH,MAAAA,EAAQ,qBAAOI,GAAA,CAACC,cAAAA,EAAAA;QAAeP,OAAAA,EAASA,OAAAA;AAASQ,QAAAA,IAAAA,EAAMJ,YAAYC,OAAO;QAAEJ,IAAAA,EAAMA;;AAEvF,IAAA,MAAMQ,IAAAA,GAAOC,aAAAA,CAAcV,OAAAA,CAAQW,UAAU,EAAE,MAAA,EAAQ;AAAC,QAAA,MAAA;AAAQ,QAAA;KAAS,CAAA,KAAeC,OAAOC,MAAM,CAACb,QAAQW,UAAU,EAAE,QAAA,CAAA,GAAY,QAAA,GAAW,MAAK,CAAA;AACtJ,IAAA,MAAMG,SAASL,IAAAA,KAAS,QAAA,GAAWM,aAAAA,CAAcf,OAAAA,CAAQW,UAAU,CAAA,GAAId,SAAAA;AACvE,IAAA,IAAIY,IAAAA,KAAS,QAAA,IAAY,CAACK,MAAAA,EAAQ,qBAAOR,GAAA,CAACU,KAAAA,EAAAA;QAAIC,IAAAA,EAAK,OAAA;AAAQ,QAAA,QAAA,EAAA;;AAE3D,IAAA,qBACIX,GAAA,CAACY,kBAAAA,EAAAA;AACG,QAAA,QAAA,gBAAAZ,GAAA,CAAClB,kBAAAA,EAAAA;YAEGM,OAAAA,EAASQ,MAAAA;YACTY,MAAAA,EAAQA,MAAAA;YACRK,OAAAA,EAASC,mBAAAA,CAAoBpB,OAAAA,CAAQW,UAAU,EAAE,SAAA,CAAA;AACjDU,YAAAA,WAAAA,EAAaC,cAAAA,CAAetB,OAAAA,CAAQW,UAAU,EAAE,aAAA,CAAA,IAAkB,QAAA;AACjE,YAAA,GAAIY,eAAevB,OAAAA,CAAQW,UAAU,EAAE,SAAA,CAAA,KAAed,SAAAA,GAAY,EAAC,GAAI;gBAAE2B,OAAAA,EAASD,cAAAA,CAAevB,OAAAA,CAAQW,UAAU,EAAE,SAAA;;WALjHlB,UAAAA,CAAWS,MAAAA,CAAAA;;AAShC;;"}
|
|
@@ -2,6 +2,8 @@ export interface CommandInput {
|
|
|
2
2
|
property: string;
|
|
3
3
|
type: 'string' | 'guid';
|
|
4
4
|
label: string;
|
|
5
|
+
column?: number;
|
|
6
|
+
width?: string;
|
|
5
7
|
}
|
|
6
8
|
export declare function commandInputs(properties: Record<string, unknown>): CommandInput[] | undefined;
|
|
7
9
|
//# sourceMappingURL=commandInputs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandInputs.d.ts","sourceRoot":"","sources":["../../../forms/commandInputs.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,YAAY;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,QAAQ,GAAG,MAAM,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"commandInputs.d.ts","sourceRoot":"","sources":["../../../forms/commandInputs.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,YAAY;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,QAAQ,GAAG,MAAM,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAGD,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY,EAAE,GAAG,SAAS,CAiB7F"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { arrayProperty, objectProperty, stringProperty } from '../properties.js';
|
|
1
|
+
import { arrayProperty, objectProperty, stringProperty, numberProperty } from '../properties.js';
|
|
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.
|
|
@@ -14,16 +14,22 @@ import { arrayProperty, objectProperty, stringProperty } from '../properties.js'
|
|
|
14
14
|
if (!input || Object.keys(input).some((key)=>![
|
|
15
15
|
'property',
|
|
16
16
|
'type',
|
|
17
|
-
'label'
|
|
17
|
+
'label',
|
|
18
|
+
'column',
|
|
19
|
+
'width'
|
|
18
20
|
].includes(key))) return undefined;
|
|
19
21
|
const property = stringProperty(input, 'property');
|
|
20
22
|
const label = stringProperty(input, 'label');
|
|
21
23
|
if (!property?.trim() || !label?.trim() || input.type !== 'string' && input.type !== 'guid' || seen.has(property)) return undefined;
|
|
22
24
|
seen.add(property);
|
|
25
|
+
const column = numberProperty(input, 'column');
|
|
26
|
+
const width = stringProperty(input, 'width');
|
|
23
27
|
inputs.push({
|
|
24
28
|
property,
|
|
25
29
|
type: input.type,
|
|
26
|
-
label
|
|
30
|
+
label,
|
|
31
|
+
column,
|
|
32
|
+
width
|
|
27
33
|
});
|
|
28
34
|
}
|
|
29
35
|
return inputs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandInputs.js","sources":["../../../forms/commandInputs.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 { arrayProperty, objectProperty, stringProperty } from '../properties';\n\n/** Exact, case-sensitive names from a generated command's propertyDescriptors. */\nexport interface CommandInput {\n property: string;\n type: 'string' | 'guid';\n label: string;\n}\n\n/** An absent declaration selects legacy auto mode; a present but invalid declaration never does. */\nexport function commandInputs(properties: Record<string, unknown>): CommandInput[] | undefined {\n const values = arrayProperty(properties, 'inputs');\n if (!values?.length) return undefined;\n const inputs: CommandInput[] = [];\n const seen = new Set<string>();\n for (const value of values) {\n const input = objectProperty({ value }, 'value');\n if (!input || Object.keys(input).some(key => !['property', 'type', 'label'].includes(key))) return undefined;\n const property = stringProperty(input, 'property');\n const label = stringProperty(input, 'label');\n if (!property?.trim() || !label?.trim() || (input.type !== 'string' && input.type !== 'guid') || seen.has(property)) return undefined;\n seen.add(property);\n inputs.push({ property, type: input.type, label });\n }\n return inputs;\n}\n"],"names":["commandInputs","properties","values","arrayProperty","length","undefined","inputs","seen","Set","value","input","objectProperty","Object","keys","some","key","includes","property","stringProperty","label","trim","type","has","add","push"],"mappings":";;AAAA;AACA;
|
|
1
|
+
{"version":3,"file":"commandInputs.js","sources":["../../../forms/commandInputs.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 { arrayProperty, numberProperty, objectProperty, stringProperty } from '../properties';\n\n/** Exact, case-sensitive names from a generated command's propertyDescriptors. */\nexport interface CommandInput {\n property: string;\n type: 'string' | 'guid';\n label: string;\n column?: number;\n width?: string;\n}\n\n/** An absent declaration selects legacy auto mode; a present but invalid declaration never does. */\nexport function commandInputs(properties: Record<string, unknown>): CommandInput[] | undefined {\n const values = arrayProperty(properties, 'inputs');\n if (!values?.length) return undefined;\n const inputs: CommandInput[] = [];\n const seen = new Set<string>();\n for (const value of values) {\n const input = objectProperty({ value }, 'value');\n if (!input || Object.keys(input).some(key => !['property', 'type', 'label', 'column', 'width'].includes(key))) return undefined;\n const property = stringProperty(input, 'property');\n const label = stringProperty(input, 'label');\n if (!property?.trim() || !label?.trim() || (input.type !== 'string' && input.type !== 'guid') || seen.has(property)) return undefined;\n seen.add(property);\n const column = numberProperty(input, 'column');\n const width = stringProperty(input, 'width');\n inputs.push({ property, type: input.type, label, column, width });\n }\n return inputs;\n}\n"],"names":["commandInputs","properties","values","arrayProperty","length","undefined","inputs","seen","Set","value","input","objectProperty","Object","keys","some","key","includes","property","stringProperty","label","trim","type","has","add","column","numberProperty","width","push"],"mappings":";;AAAA;AACA;AAaA,qGACO,SAASA,aAAAA,CAAcC,UAAmC,EAAA;IAC7D,MAAMC,MAAAA,GAASC,cAAcF,UAAAA,EAAY,QAAA,CAAA;IACzC,IAAI,CAACC,MAAAA,EAAQE,MAAAA,EAAQ,OAAOC,SAAAA;AAC5B,IAAA,MAAMC,SAAyB,EAAE;AACjC,IAAA,MAAMC,OAAO,IAAIC,GAAAA,EAAAA;IACjB,KAAK,MAAMC,SAASP,MAAAA,CAAQ;AACxB,QAAA,MAAMQ,QAAQC,cAAAA,CAAe;AAAEF,YAAAA;SAAM,EAAG,OAAA,CAAA;QACxC,IAAI,CAACC,KAAAA,IAASE,MAAAA,CAAOC,IAAI,CAACH,OAAOI,IAAI,CAACC,CAAAA,GAAAA,GAAO,CAAC;AAAC,gBAAA,UAAA;AAAY,gBAAA,MAAA;AAAQ,gBAAA,OAAA;AAAS,gBAAA,QAAA;AAAU,gBAAA;aAAQ,CAACC,QAAQ,CAACD,GAAAA,CAAAA,CAAAA,EAAO,OAAOV,SAAAA;QACtH,MAAMY,QAAAA,GAAWC,eAAeR,KAAAA,EAAO,UAAA,CAAA;QACvC,MAAMS,KAAAA,GAAQD,eAAeR,KAAAA,EAAO,OAAA,CAAA;AACpC,QAAA,IAAI,CAACO,QAAAA,EAAUG,IAAAA,EAAAA,IAAU,CAACD,KAAAA,EAAOC,IAAAA,EAAAA,IAAWV,MAAMW,IAAI,KAAK,QAAA,IAAYX,KAAAA,CAAMW,IAAI,KAAK,MAAA,IAAWd,KAAKe,GAAG,CAACL,WAAW,OAAOZ,SAAAA;AAC5HE,QAAAA,IAAAA,CAAKgB,GAAG,CAACN,QAAAA,CAAAA;QACT,MAAMO,MAAAA,GAASC,eAAef,KAAAA,EAAO,QAAA,CAAA;QACrC,MAAMgB,KAAAA,GAAQR,eAAeR,KAAAA,EAAO,OAAA,CAAA;AACpCJ,QAAAA,MAAAA,CAAOqB,IAAI,CAAC;AAAEV,YAAAA,QAAAA;AAAUI,YAAAA,IAAAA,EAAMX,MAAMW,IAAI;AAAEF,YAAAA,KAAAA;AAAOK,YAAAA,MAAAA;AAAQE,YAAAA;AAAM,SAAA,CAAA;AACnE,IAAA;IACA,OAAOpB,MAAAA;AACX;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateCommandFieldsAction.d.ts","sourceRoot":"","sources":["../../../forms/generateCommandFieldsAction.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAmD,MAAM,qBAAqB,CAAC;AAGxG,eAAO,MAAM,2BAA2B,EAAE,gBAWzC,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { DesignTimeActionPlacement, SceneEditKind } from '@cratis/scene.model';
|
|
2
|
+
|
|
3
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
4
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
5
|
+
const generateCommandFieldsAction = {
|
|
6
|
+
descriptor: {
|
|
7
|
+
id: 'Cratis.Components.commandForm.generateFields',
|
|
8
|
+
label: 'Generate fields',
|
|
9
|
+
placement: DesignTimeActionPlacement.Toolbar,
|
|
10
|
+
availability: 'commandForm.canGenerateFields',
|
|
11
|
+
description: 'Creates a deterministic editable field layout from the selected command metadata.'
|
|
12
|
+
},
|
|
13
|
+
isVisible: (context)=>context.element.componentName.endsWith(':commandForm'),
|
|
14
|
+
isEnabled: (context)=>Array.isArray(context.commandMetadata?.properties) && !Array.isArray(context.element.properties.inputs),
|
|
15
|
+
execute: (context)=>generateCommandFields(context)
|
|
16
|
+
};
|
|
17
|
+
function generateCommandFields(context) {
|
|
18
|
+
const properties = context.commandMetadata?.properties ?? [];
|
|
19
|
+
if (!properties.length) return {
|
|
20
|
+
edits: [],
|
|
21
|
+
diagnostics: [
|
|
22
|
+
'No command metadata was supplied.'
|
|
23
|
+
]
|
|
24
|
+
};
|
|
25
|
+
if (Array.isArray(context.element.properties.inputs)) {
|
|
26
|
+
return {
|
|
27
|
+
edits: [],
|
|
28
|
+
diagnostics: [
|
|
29
|
+
'The form already has authored fields; Generate fields will not overwrite them.'
|
|
30
|
+
]
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
diagnostics: [],
|
|
35
|
+
edits: [
|
|
36
|
+
{
|
|
37
|
+
kind: SceneEditKind.SetProperty,
|
|
38
|
+
nodeId: context.element.id,
|
|
39
|
+
path: 'inputs',
|
|
40
|
+
value: properties.map((property, index)=>({
|
|
41
|
+
property: property.name,
|
|
42
|
+
type: property.type === 'Guid' || property.type === 'guid' ? 'guid' : 'string',
|
|
43
|
+
label: property.label ?? humanize(property.name),
|
|
44
|
+
column: index % 2 + 1,
|
|
45
|
+
width: '1fr'
|
|
46
|
+
}))
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function humanize(name) {
|
|
52
|
+
return name.replace(/([a-z0-9])([A-Z])/g, '$1 $2').replace(/^./, (value)=>value.toUpperCase());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { generateCommandFieldsAction };
|
|
56
|
+
//# sourceMappingURL=generateCommandFieldsAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateCommandFieldsAction.js","sources":["../../../forms/generateCommandFieldsAction.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 { DesignTimeAction, DesignTimeActionContext, DesignTimeActionResult } from '@cratis/scene.react';\nimport { DesignTimeActionPlacement, SceneEditKind } from '@cratis/scene.model';\n\nexport const generateCommandFieldsAction: DesignTimeAction = {\n descriptor: {\n id: 'Cratis.Components.commandForm.generateFields',\n label: 'Generate fields',\n placement: DesignTimeActionPlacement.Toolbar,\n availability: 'commandForm.canGenerateFields',\n description: 'Creates a deterministic editable field layout from the selected command metadata.',\n },\n isVisible: context => context.element.componentName.endsWith(':commandForm'),\n isEnabled: context => Array.isArray(context.commandMetadata?.properties) && !Array.isArray(context.element.properties.inputs),\n execute: context => generateCommandFields(context),\n};\n\nfunction generateCommandFields(context: DesignTimeActionContext): DesignTimeActionResult {\n const properties = context.commandMetadata?.properties ?? [];\n if (!properties.length) return { edits: [], diagnostics: ['No command metadata was supplied.'] };\n if (Array.isArray(context.element.properties.inputs)) {\n return { edits: [], diagnostics: ['The form already has authored fields; Generate fields will not overwrite them.'] };\n }\n\n return {\n diagnostics: [],\n edits: [{\n kind: SceneEditKind.SetProperty,\n nodeId: context.element.id,\n path: 'inputs',\n value: properties.map((property, index) => ({\n property: property.name,\n type: property.type === 'Guid' || property.type === 'guid' ? 'guid' : 'string',\n label: property.label ?? humanize(property.name),\n column: (index % 2) + 1,\n width: '1fr',\n })),\n }],\n };\n}\n\nfunction humanize(name: string): string {\n return name.replace(/([a-z0-9])([A-Z])/g, '$1 $2').replace(/^./, value => value.toUpperCase());\n}\n"],"names":["generateCommandFieldsAction","descriptor","id","label","placement","DesignTimeActionPlacement","Toolbar","availability","description","isVisible","context","element","componentName","endsWith","isEnabled","Array","isArray","commandMetadata","properties","inputs","execute","generateCommandFields","length","edits","diagnostics","kind","SceneEditKind","SetProperty","nodeId","path","value","map","property","index","name","type","humanize","column","width","replace","toUpperCase"],"mappings":";;AAAA;AACA;MAKaA,2BAAAA,GAAgD;IACzDC,UAAAA,EAAY;QACRC,EAAAA,EAAI,8CAAA;QACJC,KAAAA,EAAO,iBAAA;AACPC,QAAAA,SAAAA,EAAWC,0BAA0BC,OAAO;QAC5CC,YAAAA,EAAc,+BAAA;QACdC,WAAAA,EAAa;AACjB,KAAA;IACAC,SAAAA,EAAWC,CAAAA,UAAWA,OAAAA,CAAQC,OAAO,CAACC,aAAa,CAACC,QAAQ,CAAC,cAAA,CAAA;AAC7DC,IAAAA,SAAAA,EAAWJ,CAAAA,OAAAA,GAAWK,KAAAA,CAAMC,OAAO,CAACN,OAAAA,CAAQO,eAAe,EAAEC,UAAAA,CAAAA,IAAe,CAACH,KAAAA,CAAMC,OAAO,CAACN,OAAAA,CAAQC,OAAO,CAACO,UAAU,CAACC,MAAM,CAAA;IAC5HC,OAAAA,EAASV,CAAAA,UAAWW,qBAAAA,CAAsBX,OAAAA;AAC9C;AAEA,SAASW,sBAAsBX,OAAgC,EAAA;AAC3D,IAAA,MAAMQ,UAAAA,GAAaR,OAAAA,CAAQO,eAAe,EAAEC,cAAc,EAAE;AAC5D,IAAA,IAAI,CAACA,UAAAA,CAAWI,MAAM,EAAE,OAAO;AAAEC,QAAAA,KAAAA,EAAO,EAAE;QAAEC,WAAAA,EAAa;AAAC,YAAA;AAAoC;AAAC,KAAA;IAC/F,IAAIT,KAAAA,CAAMC,OAAO,CAACN,OAAAA,CAAQC,OAAO,CAACO,UAAU,CAACC,MAAM,CAAA,EAAG;QAClD,OAAO;AAAEI,YAAAA,KAAAA,EAAO,EAAE;YAAEC,WAAAA,EAAa;AAAC,gBAAA;AAAiF;AAAC,SAAA;AACxH,IAAA;IAEA,OAAO;AACHA,QAAAA,WAAAA,EAAa,EAAE;QACfD,KAAAA,EAAO;AAAC,YAAA;AACJE,gBAAAA,IAAAA,EAAMC,cAAcC,WAAW;gBAC/BC,MAAAA,EAAQlB,OAAAA,CAAQC,OAAO,CAACT,EAAE;gBAC1B2B,IAAAA,EAAM,QAAA;AACNC,gBAAAA,KAAAA,EAAOZ,WAAWa,GAAG,CAAC,CAACC,QAAAA,EAAUC,SAAW;AACxCD,wBAAAA,QAAAA,EAAUA,SAASE,IAAI;wBACvBC,IAAAA,EAAMH,QAAAA,CAASG,IAAI,KAAK,MAAA,IAAUH,SAASG,IAAI,KAAK,SAAS,MAAA,GAAS,QAAA;AACtEhC,wBAAAA,KAAAA,EAAO6B,QAAAA,CAAS7B,KAAK,IAAIiC,QAAAA,CAASJ,SAASE,IAAI,CAAA;wBAC/CG,MAAAA,EAASJ,QAAQ,CAAA,GAAK,CAAA;wBACtBK,KAAAA,EAAO;qBACX,CAAA;AACJ;AAAE;AACN,KAAA;AACJ;AAEA,SAASF,SAASF,IAAY,EAAA;IAC1B,OAAOA,IAAAA,CAAKK,OAAO,CAAC,oBAAA,EAAsB,OAAA,CAAA,CAASA,OAAO,CAAC,IAAA,EAAMT,CAAAA,KAAAA,GAASA,KAAAA,CAAMU,WAAW,EAAA,CAAA;AAC/F;;"}
|