@cratis/scene.components 4.70.0 → 4.70.2
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/forms/CommandFieldPropertyEditor.js +2 -1
- package/dist/cjs/forms/CommandFieldPropertyEditor.js.map +1 -1
- package/dist/cjs/forms/CommandFormLayoutEditor.js +1 -1
- package/dist/cjs/forms/CommandFormLayoutEditor.js.map +1 -1
- package/dist/cjs/forms/generateCommandFieldsAction.js +4 -1
- package/dist/cjs/forms/generateCommandFieldsAction.js.map +1 -1
- package/dist/esm/forms/CommandFieldPropertyEditor.d.ts.map +1 -1
- package/dist/esm/forms/CommandFieldPropertyEditor.js +2 -1
- package/dist/esm/forms/CommandFieldPropertyEditor.js.map +1 -1
- package/dist/esm/forms/CommandFormLayoutEditor.js +2 -2
- package/dist/esm/forms/CommandFormLayoutEditor.js.map +1 -1
- package/dist/esm/forms/generateCommandFieldsAction.d.ts.map +1 -1
- package/dist/esm/forms/generateCommandFieldsAction.js +4 -1
- package/dist/esm/forms/generateCommandFieldsAction.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/forms/CommandFieldPropertyEditor.tsx +2 -1
- package/forms/CommandFormLayoutEditor.tsx +2 -2
- package/forms/generateCommandFieldsAction.ts +4 -1
- package/package.json +7 -7
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var scene_engine = require('@cratis/scene.engine');
|
|
4
5
|
var scene_model = require('@cratis/scene.model');
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -15,7 +16,7 @@ var scene_model = require('@cratis/scene.model');
|
|
|
15
16
|
context.submitEdits([
|
|
16
17
|
{
|
|
17
18
|
kind: scene_model.SceneEditKind.SetProperty,
|
|
18
|
-
nodeId: context.element.id,
|
|
19
|
+
nodeId: scene_engine.elementNodeId(context.element.id),
|
|
19
20
|
path: property.path,
|
|
20
21
|
value: next
|
|
21
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandFieldPropertyEditor.js","sources":["../../../forms/CommandFieldPropertyEditor.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 { SceneEditKind } from '@cratis/scene.model';\nimport { DesignTimePropertyEditorProps } from '@cratis/scene.react';\n\n/**\n * Package-side editor for a command form property. It writes through the generic Scene edit boundary.\n */\nexport function CommandFieldPropertyEditor({ context, property, value, setValue }: DesignTimePropertyEditorProps) {\n return <input aria-label={property.label} value={typeof value === 'string' ? value : ''} onChange={event => {\n const next = event.currentTarget.value;\n setValue(next);\n context.submitEdits([{ kind: SceneEditKind.SetProperty, nodeId: context.element.id, path: property.path, value: next }]);\n }} />;\n}\n"],"names":["CommandFieldPropertyEditor","context","property","value","setValue","_jsx","input","aria-label","label","onChange","event","next","currentTarget","submitEdits","kind","SceneEditKind","SetProperty","nodeId","element","id","path"],"mappings":"
|
|
1
|
+
{"version":3,"file":"CommandFieldPropertyEditor.js","sources":["../../../forms/CommandFieldPropertyEditor.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 { elementNodeId } from '@cratis/scene.engine';\nimport { SceneEditKind } from '@cratis/scene.model';\nimport { DesignTimePropertyEditorProps } from '@cratis/scene.react';\n\n/**\n * Package-side editor for a command form property. It writes through the generic Scene edit boundary.\n */\nexport function CommandFieldPropertyEditor({ context, property, value, setValue }: DesignTimePropertyEditorProps) {\n return <input aria-label={property.label} value={typeof value === 'string' ? value : ''} onChange={event => {\n const next = event.currentTarget.value;\n setValue(next);\n context.submitEdits([{ kind: SceneEditKind.SetProperty, nodeId: elementNodeId(context.element.id), path: property.path, value: next }]);\n }} />;\n}\n"],"names":["CommandFieldPropertyEditor","context","property","value","setValue","_jsx","input","aria-label","label","onChange","event","next","currentTarget","submitEdits","kind","SceneEditKind","SetProperty","nodeId","elementNodeId","element","id","path"],"mappings":";;;;;;AAOA;;IAGO,SAASA,0BAAAA,CAA2B,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,QAAQ,EAAiC,EAAA;AAC5G,IAAA,qBAAOC,cAAA,CAACC,OAAAA,EAAAA;AAAMC,QAAAA,YAAAA,EAAYL,SAASM,KAAK;QAAEL,KAAAA,EAAO,OAAOA,KAAAA,KAAU,QAAA,GAAWA,KAAAA,GAAQ,EAAA;AAAIM,QAAAA,QAAAA,EAAUC,CAAAA,KAAAA,GAAAA;AAC/F,YAAA,MAAMC,IAAAA,GAAOD,KAAAA,CAAME,aAAa,CAACT,KAAK;YACtCC,QAAAA,CAASO,IAAAA,CAAAA;AACTV,YAAAA,OAAAA,CAAQY,WAAW,CAAC;AAAC,gBAAA;AAAEC,oBAAAA,IAAAA,EAAMC,0BAAcC,WAAW;AAAEC,oBAAAA,MAAAA,EAAQC,0BAAAA,CAAcjB,OAAAA,CAAQkB,OAAO,CAACC,EAAE,CAAA;AAAGC,oBAAAA,IAAAA,EAAMnB,SAASmB,IAAI;oBAAElB,KAAAA,EAAOQ;AAAK;AAAE,aAAA,CAAA;AAC1I,QAAA;;AACJ;;"}
|
|
@@ -40,7 +40,7 @@ const layoutKeys = new Set(Object.values(scene_engine.CommandFormLayoutKey));
|
|
|
40
40
|
context.submitEdits([
|
|
41
41
|
{
|
|
42
42
|
kind: scene_model.SceneEditKind.SetProperty,
|
|
43
|
-
nodeId: context.element.id,
|
|
43
|
+
nodeId: scene_engine.elementNodeId(context.element.id),
|
|
44
44
|
path: property.path,
|
|
45
45
|
value: next
|
|
46
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandFormLayoutEditor.js","sources":["../../../forms/CommandFormLayoutEditor.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 { KeyboardEvent, useState } from 'react';\nimport { CommandFormLayout, SceneEditKind } from '@cratis/scene.model';\nimport { CommandFormLayoutKey, applyCommandFormLayoutKey } from '@cratis/scene.engine';\nimport { DesignTimePropertyEditorProps } from '@cratis/scene.react';\nimport { commandFormLayout } from './commandFormLayout';\n\nconst layoutKeys = new Set<string>(Object.values(CommandFormLayoutKey));\n\n/**\n * Arranges a command form's fields from the keyboard. Each placed field is a focusable cell: the arrow keys\n * move it one cell, and Shift with an arrow key resizes it. A valid change is submitted as one canonical\n * edit of the `layout` property; an invalid one is announced and the committed layout is kept.\n */\nexport function CommandFormLayoutEditor({ context, property, value, setValue }: DesignTimePropertyEditorProps) {\n const layout = commandFormLayout({ layout: value });\n const [problem, setProblem] = useState<string>();\n if (!layout) return <p role='note'>{property.label}: no layout is authored yet.</p>;\n\n const onKeyDown = (field: string) => (event: KeyboardEvent<HTMLButtonElement>) => {\n if (!layoutKeys.has(event.key)) return;\n event.preventDefault();\n const draft = applyCommandFormLayoutKey(layout, field, event.key as CommandFormLayoutKey, event.shiftKey, layout.placements.map(placement => placement.field));\n if (!draft) return;\n if (!draft.isValid) {\n setProblem(draft.diagnostics[0].message);\n return;\n }\n\n setProblem(undefined);\n commit(draft.draft);\n };\n\n const commit = (next: CommandFormLayout) => {\n setValue(next);\n context.submitEdits([{ kind: SceneEditKind.SetProperty, nodeId: context.element.id, path: property.path, value: next }]);\n };\n\n return <div role='group' aria-label={property.label} aria-describedby={`${context.element.id}-layout-help`}>\n <p id={`${context.element.id}-layout-help`}>Arrow keys move a field. Shift and an arrow key resize it.</p>\n {layout.placements.map(placement => <button key={placement.field} type='button' onKeyDown={onKeyDown(placement.field)}\n aria-label={`${placement.field}: row ${placement.row}, column ${placement.column}, spans ${placement.columnSpan ?? 1} column(s) and ${placement.rowSpan ?? 1} row(s)`}>\n {placement.field}\n </button>)}\n {problem && <p role='alert'>{problem}</p>}\n </div>;\n}\n"],"names":["layoutKeys","Set","Object","values","CommandFormLayoutKey","CommandFormLayoutEditor","context","property","value","setValue","layout","commandFormLayout","problem","setProblem","useState","_jsxs","p","role","label","onKeyDown","field","event","has","key","preventDefault","draft","applyCommandFormLayoutKey","shiftKey","placements","map","placement","isValid","diagnostics","message","undefined","commit","next","submitEdits","kind","SceneEditKind","SetProperty","nodeId","element","id","path","div","aria-label","aria-describedby","_jsx","button","type","row","column","columnSpan","rowSpan"],"mappings":";;;;;;;;AASA,MAAMA,UAAAA,GAAa,IAAIC,GAAAA,CAAYC,MAAAA,CAAOC,MAAM,CAACC,iCAAAA,CAAAA,CAAAA;AAEjD;;;;IAKO,SAASC,uBAAAA,CAAwB,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,QAAQ,EAAiC,EAAA;AACzG,IAAA,MAAMC,SAASC,mCAAAA,CAAkB;QAAED,MAAAA,EAAQF;AAAM,KAAA,CAAA;IACjD,MAAM,CAACI,OAAAA,EAASC,UAAAA,CAAW,GAAGC,cAAAA,EAAAA;IAC9B,IAAI,CAACJ,MAAAA,EAAQ,qBAAOK,eAAA,CAACC,GAAAA,EAAAA;QAAEC,IAAAA,EAAK,MAAA;;AAAQV,YAAAA,QAAAA,CAASW,KAAK;AAAC,YAAA;;;IAEnD,MAAMC,SAAAA,GAAY,CAACC,KAAAA,GAAkB,CAACC,KAAAA,GAAAA;AAClC,YAAA,IAAI,CAACrB,UAAAA,CAAWsB,GAAG,CAACD,KAAAA,CAAME,GAAG,CAAA,EAAG;AAChCF,YAAAA,KAAAA,CAAMG,cAAc,EAAA;AACpB,YAAA,MAAMC,QAAQC,sCAAAA,CAA0BhB,MAAAA,EAAQU,OAAOC,KAAAA,CAAME,GAAG,EAA0BF,KAAAA,CAAMM,QAAQ,EAAEjB,MAAAA,CAAOkB,UAAU,CAACC,GAAG,CAACC,CAAAA,SAAAA,GAAaA,UAAUV,KAAK,CAAA,CAAA;AAC5J,YAAA,IAAI,CAACK,KAAAA,EAAO;YACZ,IAAI,CAACA,KAAAA,CAAMM,OAAO,EAAE;AAChBlB,gBAAAA,UAAAA,CAAWY,KAAAA,CAAMO,WAAW,CAAC,CAAA,CAAE,CAACC,OAAO,CAAA;AACvC,gBAAA;AACJ,YAAA;YAEApB,UAAAA,CAAWqB,SAAAA,CAAAA;AACXC,YAAAA,MAAAA,CAAOV,MAAMA,KAAK,CAAA;AACtB,QAAA,CAAA;AAEA,IAAA,MAAMU,SAAS,CAACC,IAAAA,GAAAA;QACZ3B,QAAAA,CAAS2B,IAAAA,CAAAA;AACT9B,QAAAA,OAAAA,CAAQ+B,WAAW,CAAC;AAAC,YAAA;AAAEC,gBAAAA,IAAAA,EAAMC,0BAAcC,WAAW;
|
|
1
|
+
{"version":3,"file":"CommandFormLayoutEditor.js","sources":["../../../forms/CommandFormLayoutEditor.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 { KeyboardEvent, useState } from 'react';\nimport { CommandFormLayout, SceneEditKind } from '@cratis/scene.model';\nimport { CommandFormLayoutKey, applyCommandFormLayoutKey, elementNodeId } from '@cratis/scene.engine';\nimport { DesignTimePropertyEditorProps } from '@cratis/scene.react';\nimport { commandFormLayout } from './commandFormLayout';\n\nconst layoutKeys = new Set<string>(Object.values(CommandFormLayoutKey));\n\n/**\n * Arranges a command form's fields from the keyboard. Each placed field is a focusable cell: the arrow keys\n * move it one cell, and Shift with an arrow key resizes it. A valid change is submitted as one canonical\n * edit of the `layout` property; an invalid one is announced and the committed layout is kept.\n */\nexport function CommandFormLayoutEditor({ context, property, value, setValue }: DesignTimePropertyEditorProps) {\n const layout = commandFormLayout({ layout: value });\n const [problem, setProblem] = useState<string>();\n if (!layout) return <p role='note'>{property.label}: no layout is authored yet.</p>;\n\n const onKeyDown = (field: string) => (event: KeyboardEvent<HTMLButtonElement>) => {\n if (!layoutKeys.has(event.key)) return;\n event.preventDefault();\n const draft = applyCommandFormLayoutKey(layout, field, event.key as CommandFormLayoutKey, event.shiftKey, layout.placements.map(placement => placement.field));\n if (!draft) return;\n if (!draft.isValid) {\n setProblem(draft.diagnostics[0].message);\n return;\n }\n\n setProblem(undefined);\n commit(draft.draft);\n };\n\n const commit = (next: CommandFormLayout) => {\n setValue(next);\n context.submitEdits([{ kind: SceneEditKind.SetProperty, nodeId: elementNodeId(context.element.id), path: property.path, value: next }]);\n };\n\n return <div role='group' aria-label={property.label} aria-describedby={`${context.element.id}-layout-help`}>\n <p id={`${context.element.id}-layout-help`}>Arrow keys move a field. Shift and an arrow key resize it.</p>\n {layout.placements.map(placement => <button key={placement.field} type='button' onKeyDown={onKeyDown(placement.field)}\n aria-label={`${placement.field}: row ${placement.row}, column ${placement.column}, spans ${placement.columnSpan ?? 1} column(s) and ${placement.rowSpan ?? 1} row(s)`}>\n {placement.field}\n </button>)}\n {problem && <p role='alert'>{problem}</p>}\n </div>;\n}\n"],"names":["layoutKeys","Set","Object","values","CommandFormLayoutKey","CommandFormLayoutEditor","context","property","value","setValue","layout","commandFormLayout","problem","setProblem","useState","_jsxs","p","role","label","onKeyDown","field","event","has","key","preventDefault","draft","applyCommandFormLayoutKey","shiftKey","placements","map","placement","isValid","diagnostics","message","undefined","commit","next","submitEdits","kind","SceneEditKind","SetProperty","nodeId","elementNodeId","element","id","path","div","aria-label","aria-describedby","_jsx","button","type","row","column","columnSpan","rowSpan"],"mappings":";;;;;;;;AASA,MAAMA,UAAAA,GAAa,IAAIC,GAAAA,CAAYC,MAAAA,CAAOC,MAAM,CAACC,iCAAAA,CAAAA,CAAAA;AAEjD;;;;IAKO,SAASC,uBAAAA,CAAwB,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,QAAQ,EAAiC,EAAA;AACzG,IAAA,MAAMC,SAASC,mCAAAA,CAAkB;QAAED,MAAAA,EAAQF;AAAM,KAAA,CAAA;IACjD,MAAM,CAACI,OAAAA,EAASC,UAAAA,CAAW,GAAGC,cAAAA,EAAAA;IAC9B,IAAI,CAACJ,MAAAA,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AAC+B,KAAAA,EAAAA;QAAI7B,IAAAA,EAAK,OAAA;AAAQ8B,QAAAA,YAAAA,EAAYxC,SAASW,KAAK;AAAE8B,QAAAA,kBAAAA,EAAkB,GAAG1C,OAAAA,CAAQqC,OAAO,CAACC,EAAE,CAAC,YAAY,CAAC;;0BACtGK,cAAA,CAACjC,GAAAA,EAAAA;AAAE4B,gBAAAA,EAAAA,EAAI,GAAGtC,OAAAA,CAAQqC,OAAO,CAACC,EAAE,CAAC,YAAY,CAAC;AAAE,gBAAA,QAAA,EAAA;;AAC3ClC,YAAAA,MAAAA,CAAOkB,UAAU,CAACC,GAAG,CAACC,CAAAA,0BAAamB,cAAA,CAACC,QAAAA,EAAAA;oBAA6BC,IAAAA,EAAK,QAAA;oBAAShC,SAAAA,EAAWA,SAAAA,CAAUW,UAAUV,KAAK,CAAA;oBAChH2B,YAAAA,EAAY,CAAA,EAAGjB,SAAAA,CAAUV,KAAK,CAAC,MAAM,EAAEU,SAAAA,CAAUsB,GAAG,CAAC,SAAS,EAAEtB,SAAAA,CAAUuB,MAAM,CAAC,QAAQ,EAAEvB,SAAAA,CAAUwB,UAAU,IAAI,CAAA,CAAE,eAAe,EAAExB,SAAAA,CAAUyB,OAAO,IAAI,CAAA,CAAE,OAAO,CAAC;AACpKzB,oBAAAA,QAAAA,EAAAA,SAAAA,CAAUV;AAFkCU,iBAAAA,EAAAA,SAAAA,CAAUV,KAAK,CAAA,CAAA;AAI/DR,YAAAA,OAAAA,kBAAWqC,cAAA,CAACjC,GAAAA,EAAAA;gBAAEC,IAAAA,EAAK,OAAA;AAASL,gBAAAA,QAAAA,EAAAA;;;;AAErC;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var scene_engine = require('@cratis/scene.engine');
|
|
3
4
|
var scene_model = require('@cratis/scene.model');
|
|
4
5
|
|
|
5
6
|
// Copyright (c) Cratis. All rights reserved.
|
|
@@ -46,9 +47,11 @@ function generateCommandFields(context) {
|
|
|
46
47
|
edits: [
|
|
47
48
|
{
|
|
48
49
|
kind: scene_model.SceneEditKind.SetProperty,
|
|
49
|
-
nodeId: context.element.id,
|
|
50
|
+
nodeId: scene_engine.elementNodeId(context.element.id),
|
|
50
51
|
path: 'inputs',
|
|
52
|
+
// A collection item is addressed by its id, so an item without one is refused by the editing engine and nothing is generated.
|
|
51
53
|
value: properties.map((property, index)=>({
|
|
54
|
+
id: property.name,
|
|
52
55
|
property: property.name,
|
|
53
56
|
type: property.type === 'Guid' || property.type === 'guid' ? 'guid' : 'string',
|
|
54
57
|
label: property.label ?? humanize(property.name),
|
|
@@ -1 +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) && context.element.properties.inputs === undefined,\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 // Authored fields, or a binding that supplies them, are never overwritten.\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 if (context.element.properties.inputs !== undefined) {\n return { edits: [], diagnostics: ['The form\\'s fields come from a binding; Generate fields will not overwrite it.'] };\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","undefined","execute","generateCommandFields","length","edits","diagnostics","kind","SceneEditKind","SetProperty","nodeId","path","value","map","property","index","name","type","humanize","column","width","replace","toUpperCase"],"mappings":"
|
|
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 { elementNodeId } from '@cratis/scene.engine';\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) && context.element.properties.inputs === undefined,\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 // Authored fields, or a binding that supplies them, are never overwritten.\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 if (context.element.properties.inputs !== undefined) {\n return { edits: [], diagnostics: ['The form\\'s fields come from a binding; Generate fields will not overwrite it.'] };\n }\n\n return {\n diagnostics: [],\n edits: [{\n kind: SceneEditKind.SetProperty,\n nodeId: elementNodeId(context.element.id),\n path: 'inputs',\n // A collection item is addressed by its id, so an item without one is refused by the editing engine and nothing is generated.\n value: properties.map((property, index) => ({\n id: property.name,\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","undefined","execute","generateCommandFields","length","edits","diagnostics","kind","SceneEditKind","SetProperty","nodeId","elementNodeId","path","value","map","property","index","name","type","humanize","column","width","replace","toUpperCase"],"mappings":";;;;;AAAA;AACA;MAMaA,2BAAAA,GAAgD;IACzDC,UAAAA,EAAY;QACRC,EAAAA,EAAI,8CAAA;QACJC,KAAAA,EAAO,iBAAA;AACPC,QAAAA,SAAAA,EAAWC,sCAA0BC,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,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QAAAA,CAASG,IAAI,KAAK,MAAA,IAAUH,SAASG,IAAI,KAAK,SAAS,MAAA,GAAS,QAAA;AACtElC,wBAAAA,KAAAA,EAAO+B,QAAAA,CAAS/B,KAAK,IAAImC,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;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandFieldPropertyEditor.d.ts","sourceRoot":"","sources":["../../../forms/CommandFieldPropertyEditor.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CommandFieldPropertyEditor.d.ts","sourceRoot":"","sources":["../../../forms/CommandFieldPropertyEditor.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AAKpE,wBAAgB,0BAA0B,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,6BAA6B,+BAM/G"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { elementNodeId } from '@cratis/scene.engine';
|
|
2
3
|
import { SceneEditKind } from '@cratis/scene.model';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -13,7 +14,7 @@ import { SceneEditKind } from '@cratis/scene.model';
|
|
|
13
14
|
context.submitEdits([
|
|
14
15
|
{
|
|
15
16
|
kind: SceneEditKind.SetProperty,
|
|
16
|
-
nodeId: context.element.id,
|
|
17
|
+
nodeId: elementNodeId(context.element.id),
|
|
17
18
|
path: property.path,
|
|
18
19
|
value: next
|
|
19
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandFieldPropertyEditor.js","sources":["../../../forms/CommandFieldPropertyEditor.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 { SceneEditKind } from '@cratis/scene.model';\nimport { DesignTimePropertyEditorProps } from '@cratis/scene.react';\n\n/**\n * Package-side editor for a command form property. It writes through the generic Scene edit boundary.\n */\nexport function CommandFieldPropertyEditor({ context, property, value, setValue }: DesignTimePropertyEditorProps) {\n return <input aria-label={property.label} value={typeof value === 'string' ? value : ''} onChange={event => {\n const next = event.currentTarget.value;\n setValue(next);\n context.submitEdits([{ kind: SceneEditKind.SetProperty, nodeId: context.element.id, path: property.path, value: next }]);\n }} />;\n}\n"],"names":["CommandFieldPropertyEditor","context","property","value","setValue","_jsx","input","aria-label","label","onChange","event","next","currentTarget","submitEdits","kind","SceneEditKind","SetProperty","nodeId","element","id","path"],"mappings":"
|
|
1
|
+
{"version":3,"file":"CommandFieldPropertyEditor.js","sources":["../../../forms/CommandFieldPropertyEditor.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 { elementNodeId } from '@cratis/scene.engine';\nimport { SceneEditKind } from '@cratis/scene.model';\nimport { DesignTimePropertyEditorProps } from '@cratis/scene.react';\n\n/**\n * Package-side editor for a command form property. It writes through the generic Scene edit boundary.\n */\nexport function CommandFieldPropertyEditor({ context, property, value, setValue }: DesignTimePropertyEditorProps) {\n return <input aria-label={property.label} value={typeof value === 'string' ? value : ''} onChange={event => {\n const next = event.currentTarget.value;\n setValue(next);\n context.submitEdits([{ kind: SceneEditKind.SetProperty, nodeId: elementNodeId(context.element.id), path: property.path, value: next }]);\n }} />;\n}\n"],"names":["CommandFieldPropertyEditor","context","property","value","setValue","_jsx","input","aria-label","label","onChange","event","next","currentTarget","submitEdits","kind","SceneEditKind","SetProperty","nodeId","elementNodeId","element","id","path"],"mappings":";;;;AAOA;;IAGO,SAASA,0BAAAA,CAA2B,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,QAAQ,EAAiC,EAAA;AAC5G,IAAA,qBAAOC,GAAA,CAACC,OAAAA,EAAAA;AAAMC,QAAAA,YAAAA,EAAYL,SAASM,KAAK;QAAEL,KAAAA,EAAO,OAAOA,KAAAA,KAAU,QAAA,GAAWA,KAAAA,GAAQ,EAAA;AAAIM,QAAAA,QAAAA,EAAUC,CAAAA,KAAAA,GAAAA;AAC/F,YAAA,MAAMC,IAAAA,GAAOD,KAAAA,CAAME,aAAa,CAACT,KAAK;YACtCC,QAAAA,CAASO,IAAAA,CAAAA;AACTV,YAAAA,OAAAA,CAAQY,WAAW,CAAC;AAAC,gBAAA;AAAEC,oBAAAA,IAAAA,EAAMC,cAAcC,WAAW;AAAEC,oBAAAA,MAAAA,EAAQC,aAAAA,CAAcjB,OAAAA,CAAQkB,OAAO,CAACC,EAAE,CAAA;AAAGC,oBAAAA,IAAAA,EAAMnB,SAASmB,IAAI;oBAAElB,KAAAA,EAAOQ;AAAK;AAAE,aAAA,CAAA;AAC1I,QAAA;;AACJ;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { useState } from 'react';
|
|
3
3
|
import { SceneEditKind } from '@cratis/scene.model';
|
|
4
|
-
import { CommandFormLayoutKey, applyCommandFormLayoutKey } from '@cratis/scene.engine';
|
|
4
|
+
import { CommandFormLayoutKey, applyCommandFormLayoutKey, elementNodeId } from '@cratis/scene.engine';
|
|
5
5
|
import { commandFormLayout } from './commandFormLayout.js';
|
|
6
6
|
|
|
7
7
|
const layoutKeys = new Set(Object.values(CommandFormLayoutKey));
|
|
@@ -38,7 +38,7 @@ const layoutKeys = new Set(Object.values(CommandFormLayoutKey));
|
|
|
38
38
|
context.submitEdits([
|
|
39
39
|
{
|
|
40
40
|
kind: SceneEditKind.SetProperty,
|
|
41
|
-
nodeId: context.element.id,
|
|
41
|
+
nodeId: elementNodeId(context.element.id),
|
|
42
42
|
path: property.path,
|
|
43
43
|
value: next
|
|
44
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandFormLayoutEditor.js","sources":["../../../forms/CommandFormLayoutEditor.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 { KeyboardEvent, useState } from 'react';\nimport { CommandFormLayout, SceneEditKind } from '@cratis/scene.model';\nimport { CommandFormLayoutKey, applyCommandFormLayoutKey } from '@cratis/scene.engine';\nimport { DesignTimePropertyEditorProps } from '@cratis/scene.react';\nimport { commandFormLayout } from './commandFormLayout';\n\nconst layoutKeys = new Set<string>(Object.values(CommandFormLayoutKey));\n\n/**\n * Arranges a command form's fields from the keyboard. Each placed field is a focusable cell: the arrow keys\n * move it one cell, and Shift with an arrow key resizes it. A valid change is submitted as one canonical\n * edit of the `layout` property; an invalid one is announced and the committed layout is kept.\n */\nexport function CommandFormLayoutEditor({ context, property, value, setValue }: DesignTimePropertyEditorProps) {\n const layout = commandFormLayout({ layout: value });\n const [problem, setProblem] = useState<string>();\n if (!layout) return <p role='note'>{property.label}: no layout is authored yet.</p>;\n\n const onKeyDown = (field: string) => (event: KeyboardEvent<HTMLButtonElement>) => {\n if (!layoutKeys.has(event.key)) return;\n event.preventDefault();\n const draft = applyCommandFormLayoutKey(layout, field, event.key as CommandFormLayoutKey, event.shiftKey, layout.placements.map(placement => placement.field));\n if (!draft) return;\n if (!draft.isValid) {\n setProblem(draft.diagnostics[0].message);\n return;\n }\n\n setProblem(undefined);\n commit(draft.draft);\n };\n\n const commit = (next: CommandFormLayout) => {\n setValue(next);\n context.submitEdits([{ kind: SceneEditKind.SetProperty, nodeId: context.element.id, path: property.path, value: next }]);\n };\n\n return <div role='group' aria-label={property.label} aria-describedby={`${context.element.id}-layout-help`}>\n <p id={`${context.element.id}-layout-help`}>Arrow keys move a field. Shift and an arrow key resize it.</p>\n {layout.placements.map(placement => <button key={placement.field} type='button' onKeyDown={onKeyDown(placement.field)}\n aria-label={`${placement.field}: row ${placement.row}, column ${placement.column}, spans ${placement.columnSpan ?? 1} column(s) and ${placement.rowSpan ?? 1} row(s)`}>\n {placement.field}\n </button>)}\n {problem && <p role='alert'>{problem}</p>}\n </div>;\n}\n"],"names":["layoutKeys","Set","Object","values","CommandFormLayoutKey","CommandFormLayoutEditor","context","property","value","setValue","layout","commandFormLayout","problem","setProblem","useState","_jsxs","p","role","label","onKeyDown","field","event","has","key","preventDefault","draft","applyCommandFormLayoutKey","shiftKey","placements","map","placement","isValid","diagnostics","message","undefined","commit","next","submitEdits","kind","SceneEditKind","SetProperty","nodeId","element","id","path","div","aria-label","aria-describedby","_jsx","button","type","row","column","columnSpan","rowSpan"],"mappings":";;;;;;AASA,MAAMA,UAAAA,GAAa,IAAIC,GAAAA,CAAYC,MAAAA,CAAOC,MAAM,CAACC,oBAAAA,CAAAA,CAAAA;AAEjD;;;;IAKO,SAASC,uBAAAA,CAAwB,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,QAAQ,EAAiC,EAAA;AACzG,IAAA,MAAMC,SAASC,iBAAAA,CAAkB;QAAED,MAAAA,EAAQF;AAAM,KAAA,CAAA;IACjD,MAAM,CAACI,OAAAA,EAASC,UAAAA,CAAW,GAAGC,QAAAA,EAAAA;IAC9B,IAAI,CAACJ,MAAAA,EAAQ,qBAAOK,IAAA,CAACC,GAAAA,EAAAA;QAAEC,IAAAA,EAAK,MAAA;;AAAQV,YAAAA,QAAAA,CAASW,KAAK;AAAC,YAAA;;;IAEnD,MAAMC,SAAAA,GAAY,CAACC,KAAAA,GAAkB,CAACC,KAAAA,GAAAA;AAClC,YAAA,IAAI,CAACrB,UAAAA,CAAWsB,GAAG,CAACD,KAAAA,CAAME,GAAG,CAAA,EAAG;AAChCF,YAAAA,KAAAA,CAAMG,cAAc,EAAA;AACpB,YAAA,MAAMC,QAAQC,yBAAAA,CAA0BhB,MAAAA,EAAQU,OAAOC,KAAAA,CAAME,GAAG,EAA0BF,KAAAA,CAAMM,QAAQ,EAAEjB,MAAAA,CAAOkB,UAAU,CAACC,GAAG,CAACC,CAAAA,SAAAA,GAAaA,UAAUV,KAAK,CAAA,CAAA;AAC5J,YAAA,IAAI,CAACK,KAAAA,EAAO;YACZ,IAAI,CAACA,KAAAA,CAAMM,OAAO,EAAE;AAChBlB,gBAAAA,UAAAA,CAAWY,KAAAA,CAAMO,WAAW,CAAC,CAAA,CAAE,CAACC,OAAO,CAAA;AACvC,gBAAA;AACJ,YAAA;YAEApB,UAAAA,CAAWqB,SAAAA,CAAAA;AACXC,YAAAA,MAAAA,CAAOV,MAAMA,KAAK,CAAA;AACtB,QAAA,CAAA;AAEA,IAAA,MAAMU,SAAS,CAACC,IAAAA,GAAAA;QACZ3B,QAAAA,CAAS2B,IAAAA,CAAAA;AACT9B,QAAAA,OAAAA,CAAQ+B,WAAW,CAAC;AAAC,YAAA;AAAEC,gBAAAA,IAAAA,EAAMC,cAAcC,WAAW;
|
|
1
|
+
{"version":3,"file":"CommandFormLayoutEditor.js","sources":["../../../forms/CommandFormLayoutEditor.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 { KeyboardEvent, useState } from 'react';\nimport { CommandFormLayout, SceneEditKind } from '@cratis/scene.model';\nimport { CommandFormLayoutKey, applyCommandFormLayoutKey, elementNodeId } from '@cratis/scene.engine';\nimport { DesignTimePropertyEditorProps } from '@cratis/scene.react';\nimport { commandFormLayout } from './commandFormLayout';\n\nconst layoutKeys = new Set<string>(Object.values(CommandFormLayoutKey));\n\n/**\n * Arranges a command form's fields from the keyboard. Each placed field is a focusable cell: the arrow keys\n * move it one cell, and Shift with an arrow key resizes it. A valid change is submitted as one canonical\n * edit of the `layout` property; an invalid one is announced and the committed layout is kept.\n */\nexport function CommandFormLayoutEditor({ context, property, value, setValue }: DesignTimePropertyEditorProps) {\n const layout = commandFormLayout({ layout: value });\n const [problem, setProblem] = useState<string>();\n if (!layout) return <p role='note'>{property.label}: no layout is authored yet.</p>;\n\n const onKeyDown = (field: string) => (event: KeyboardEvent<HTMLButtonElement>) => {\n if (!layoutKeys.has(event.key)) return;\n event.preventDefault();\n const draft = applyCommandFormLayoutKey(layout, field, event.key as CommandFormLayoutKey, event.shiftKey, layout.placements.map(placement => placement.field));\n if (!draft) return;\n if (!draft.isValid) {\n setProblem(draft.diagnostics[0].message);\n return;\n }\n\n setProblem(undefined);\n commit(draft.draft);\n };\n\n const commit = (next: CommandFormLayout) => {\n setValue(next);\n context.submitEdits([{ kind: SceneEditKind.SetProperty, nodeId: elementNodeId(context.element.id), path: property.path, value: next }]);\n };\n\n return <div role='group' aria-label={property.label} aria-describedby={`${context.element.id}-layout-help`}>\n <p id={`${context.element.id}-layout-help`}>Arrow keys move a field. Shift and an arrow key resize it.</p>\n {layout.placements.map(placement => <button key={placement.field} type='button' onKeyDown={onKeyDown(placement.field)}\n aria-label={`${placement.field}: row ${placement.row}, column ${placement.column}, spans ${placement.columnSpan ?? 1} column(s) and ${placement.rowSpan ?? 1} row(s)`}>\n {placement.field}\n </button>)}\n {problem && <p role='alert'>{problem}</p>}\n </div>;\n}\n"],"names":["layoutKeys","Set","Object","values","CommandFormLayoutKey","CommandFormLayoutEditor","context","property","value","setValue","layout","commandFormLayout","problem","setProblem","useState","_jsxs","p","role","label","onKeyDown","field","event","has","key","preventDefault","draft","applyCommandFormLayoutKey","shiftKey","placements","map","placement","isValid","diagnostics","message","undefined","commit","next","submitEdits","kind","SceneEditKind","SetProperty","nodeId","elementNodeId","element","id","path","div","aria-label","aria-describedby","_jsx","button","type","row","column","columnSpan","rowSpan"],"mappings":";;;;;;AASA,MAAMA,UAAAA,GAAa,IAA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CAAA;AAI/DR,YAAAA,OAAAA,kBAAWqC,GAAA,CAACjC,GAAAA,EAAAA;gBAAEC,IAAAA,EAAK,OAAA;AAASL,gBAAAA,QAAAA,EAAAA;;;;AAErC;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateCommandFieldsAction.d.ts","sourceRoot":"","sources":["../../../forms/generateCommandFieldsAction.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generateCommandFieldsAction.d.ts","sourceRoot":"","sources":["../../../forms/generateCommandFieldsAction.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAmD,MAAM,qBAAqB,CAAC;AAGxG,eAAO,MAAM,2BAA2B,EAAE,gBAWzC,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { elementNodeId } from '@cratis/scene.engine';
|
|
1
2
|
import { DesignTimeActionPlacement, SceneEditKind } from '@cratis/scene.model';
|
|
2
3
|
|
|
3
4
|
// Copyright (c) Cratis. All rights reserved.
|
|
@@ -44,9 +45,11 @@ function generateCommandFields(context) {
|
|
|
44
45
|
edits: [
|
|
45
46
|
{
|
|
46
47
|
kind: SceneEditKind.SetProperty,
|
|
47
|
-
nodeId: context.element.id,
|
|
48
|
+
nodeId: elementNodeId(context.element.id),
|
|
48
49
|
path: 'inputs',
|
|
50
|
+
// A collection item is addressed by its id, so an item without one is refused by the editing engine and nothing is generated.
|
|
49
51
|
value: properties.map((property, index)=>({
|
|
52
|
+
id: property.name,
|
|
50
53
|
property: property.name,
|
|
51
54
|
type: property.type === 'Guid' || property.type === 'guid' ? 'guid' : 'string',
|
|
52
55
|
label: property.label ?? humanize(property.name),
|
|
@@ -1 +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) && context.element.properties.inputs === undefined,\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 // Authored fields, or a binding that supplies them, are never overwritten.\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 if (context.element.properties.inputs !== undefined) {\n return { edits: [], diagnostics: ['The form\\'s fields come from a binding; Generate fields will not overwrite it.'] };\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","undefined","execute","generateCommandFields","length","edits","diagnostics","kind","SceneEditKind","SetProperty","nodeId","path","value","map","property","index","name","type","humanize","column","width","replace","toUpperCase"],"mappings":"
|
|
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 { elementNodeId } from '@cratis/scene.engine';\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) && context.element.properties.inputs === undefined,\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 // Authored fields, or a binding that supplies them, are never overwritten.\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 if (context.element.properties.inputs !== undefined) {\n return { edits: [], diagnostics: ['The form\\'s fields come from a binding; Generate fields will not overwrite it.'] };\n }\n\n return {\n diagnostics: [],\n edits: [{\n kind: SceneEditKind.SetProperty,\n nodeId: elementNodeId(context.element.id),\n path: 'inputs',\n // A collection item is addressed by its id, so an item without one is refused by the editing engine and nothing is generated.\n value: properties.map((property, index) => ({\n id: property.name,\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","undefined","execute","generateCommandFields","length","edits","diagnostics","kind","SceneEditKind","SetProperty","nodeId","elementNodeId","path","value","map","property","index","name","type","humanize","column","width","replace","toUpperCase"],"mappings":";;;AAAA;AACA;MAMaA,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,IAAeR,QAAQC,OAAO,CAACO,UAAU,CAACC,MAAM,KAAKC,SAAAA;IAClHC,OAAAA,EAASX,CAAAA,UAAWY,qBAAAA,CAAsBZ,OAAAA;AAC9C;AAEA,SAASY,sBAAsBZ,OAAgC,EAAA;AAC3D,IAAA,MAAMQ,UAAAA,GAAaR,OAAAA,CAAQO,eAAe,EAAEC,cAAc,EAAE;AAC5D,IAAA,IAAI,CAACA,UAAAA,CAAWK,MAAM,EAAE,OAAO;AAAEC,QAAAA,KAAAA,EAAO,EAAE;QAAEC,WAAAA,EAAa;AAAC,YAAA;AAAoC;AAAC,KAAA;;IAE/F,IAAIV,KAAAA,CAAMC,OAAO,CAACN,OAAAA,CAAQC,OAAO,CAACO,UAAU,CAACC,MAAM,CAAA,EAAG;QAClD,OAAO;AAAEK,YAAAA,KAAAA,EAAO,EAAE;YAAEC,WAAAA,EAAa;AA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