@cratis/components 2.8.0 → 2.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/dist/cjs/CommandForm/AutoCommandForm.js +49 -0
- package/dist/cjs/CommandForm/AutoCommandForm.js.map +1 -0
- package/dist/cjs/CommandForm/defaultFieldTypeProviders.js +24 -0
- package/dist/cjs/CommandForm/defaultFieldTypeProviders.js.map +1 -0
- package/dist/cjs/CommandForm/fieldTypeProviderRegistry.js +36 -0
- package/dist/cjs/CommandForm/fieldTypeProviderRegistry.js.map +1 -0
- package/dist/cjs/CommandForm/index.js +6 -0
- package/dist/cjs/CommandForm/index.js.map +1 -1
- package/dist/esm/CommandForm/AutoCommandForm.d.ts +8 -0
- package/dist/esm/CommandForm/AutoCommandForm.d.ts.map +1 -0
- package/dist/esm/CommandForm/AutoCommandForm.js +47 -0
- package/dist/esm/CommandForm/AutoCommandForm.js.map +1 -0
- package/dist/esm/CommandForm/FieldTypeProvider.d.ts +7 -0
- package/dist/esm/CommandForm/FieldTypeProvider.d.ts.map +1 -0
- package/dist/esm/CommandForm/FieldTypeProvider.js +2 -0
- package/dist/esm/CommandForm/FieldTypeProvider.js.map +1 -0
- package/dist/esm/CommandForm/defaultFieldTypeProviders.d.ts +2 -0
- package/dist/esm/CommandForm/defaultFieldTypeProviders.d.ts.map +1 -0
- package/dist/esm/CommandForm/defaultFieldTypeProviders.js +22 -0
- package/dist/esm/CommandForm/defaultFieldTypeProviders.js.map +1 -0
- package/dist/esm/CommandForm/fieldTypeProviderRegistry.d.ts +6 -0
- package/dist/esm/CommandForm/fieldTypeProviderRegistry.d.ts.map +1 -0
- package/dist/esm/CommandForm/fieldTypeProviderRegistry.js +32 -0
- package/dist/esm/CommandForm/fieldTypeProviderRegistry.js.map +1 -0
- package/dist/esm/CommandForm/index.d.ts +3 -0
- package/dist/esm/CommandForm/index.d.ts.map +1 -1
- package/dist/esm/CommandForm/index.js +2 -0
- package/dist/esm/CommandForm/index.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var commands = require('@cratis/arc.react/commands');
|
|
6
|
+
var fieldTypeProviderRegistry = require('./fieldTypeProviderRegistry.js');
|
|
7
|
+
require('./defaultFieldTypeProviders.js');
|
|
8
|
+
|
|
9
|
+
function formatTitle(propertyName) {
|
|
10
|
+
return propertyName
|
|
11
|
+
.replace(/([A-Z])/g, ' $1')
|
|
12
|
+
.replace(/^./, character => character.toUpperCase())
|
|
13
|
+
.trim();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A `CommandForm` that generates its field list from the command's own properties, choosing each
|
|
17
|
+
* field's component by the property's type through the {@link FieldTypeProvider} registry -
|
|
18
|
+
* `registerFieldTypeProvider` for a type the built-in defaults (`string`, `number`, `boolean`,
|
|
19
|
+
* `Date`) don't cover, or to override one of them.
|
|
20
|
+
*
|
|
21
|
+
* A property whose type no registered provider handles is left out of the generated list -
|
|
22
|
+
* `exclude` it explicitly for clarity, or add a `CommandForm` child by hand alongside this
|
|
23
|
+
* component for that one property.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* <AutoCommandForm command={RegisterInvoice} exclude={['invoiceId']} />
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function AutoCommandForm(props) {
|
|
31
|
+
const { exclude, ...commandFormProps } = props;
|
|
32
|
+
const propertyDescriptors = React.useMemo(() => new props.command().propertyDescriptors, [props.command]);
|
|
33
|
+
const excluded = React.useMemo(() => new Set((exclude ?? [])), [exclude]);
|
|
34
|
+
const fields = propertyDescriptors
|
|
35
|
+
.filter(descriptor => !excluded.has(descriptor.name))
|
|
36
|
+
.map(descriptor => {
|
|
37
|
+
const provider = fieldTypeProviderRegistry.resolveFieldTypeProvider(descriptor);
|
|
38
|
+
if (!provider) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const Field = provider.component;
|
|
42
|
+
return (jsxRuntime.jsx(Field, { value: (instance) => instance[descriptor.name], title: formatTitle(descriptor.name) }, descriptor.name));
|
|
43
|
+
})
|
|
44
|
+
.filter((field) => field !== null);
|
|
45
|
+
return jsxRuntime.jsx(commands.CommandForm, { ...commandFormProps, children: fields });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
exports.AutoCommandForm = AutoCommandForm;
|
|
49
|
+
//# sourceMappingURL=AutoCommandForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutoCommandForm.js","sources":["../../../CommandForm/AutoCommandForm.tsx"],"sourcesContent":[null],"names":["useMemo","resolveFieldTypeProvider","_jsx","CommandForm"],"mappings":";;;;;;;;AAqBA,SAAS,WAAW,CAAC,YAAoB,EAAA;AACrC,IAAA,OAAO;AACF,SAAA,OAAO,CAAC,UAAU,EAAE,KAAK;SACzB,OAAO,CAAC,IAAI,EAAE,SAAS,IAAI,SAAS,CAAC,WAAW,EAAE;AAClD,SAAA,IAAI,EAAE;AACf;AAEA;;;;;;;;;;;;;;AAcG;AACG,SAAU,eAAe,CAC3B,KAAgD,EAAA;IAEhD,MAAM,EAAE,OAAO,EAAE,GAAG,gBAAgB,EAAE,GAAG,KAAK;IAC9C,MAAM,mBAAmB,GAAGA,aAAO,CAAC,MAAO,IAAI,KAAK,CAAC,OAAO,EAAyB,CAAC,mBAAmB,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3H,MAAM,QAAQ,GAAGA,aAAO,CAAC,MAAM,IAAI,GAAG,EAAU,OAAO,IAAI,EAAE,EAAc,EAAE,CAAC,OAAO,CAAC,CAAC;IAEvF,MAAM,MAAM,GAAG;AACV,SAAA,MAAM,CAAC,UAAU,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC;SACnD,GAAG,CAAC,UAAU,IAAG;AACd,QAAA,MAAM,QAAQ,GAAGC,kDAAwB,CAAC,UAAU,CAAC;QACrD,IAAI,CAAC,QAAQ,EAAE;AACX,YAAA,OAAO,IAAI;QACf;AAEA,QAAA,MAAM,KAAK,GAAG,QAAQ,CAAC,SAAS;AAChC,QAAA,QACIC,cAAA,CAAC,KAAK,EAAA,EAEF,KAAK,EAAE,CAAC,QAAkB,KAAM,QAA+C,CAAC,UAAU,CAAC,IAAI,CAAC,EAChG,KAAK,EAAE,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,EAAA,EAF9B,UAAU,CAAC,IAAI,CAGtB;AAEV,IAAA,CAAC;SACA,MAAM,CAAC,CAAC,KAAK,KAAkC,KAAK,KAAK,IAAI,CAAC;AAEnE,IAAA,OAAOA,eAACC,oBAAW,EAAA,EAAA,GAAK,gBAAgB,EAAA,QAAA,EAAG,MAAM,GAAe;AACpE;;;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fieldTypeProviderRegistry = require('./fieldTypeProviderRegistry.js');
|
|
4
|
+
var InputTextField = require('./fields/InputTextField.js');
|
|
5
|
+
var NumberField = require('./fields/NumberField.js');
|
|
6
|
+
var CheckboxField = require('./fields/CheckboxField.js');
|
|
7
|
+
var CalendarField = require('./fields/CalendarField.js');
|
|
8
|
+
|
|
9
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
10
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
11
|
+
/**
|
|
12
|
+
* Registers the built-in {@link FieldTypeProvider}s {@link AutoCommandForm} falls back to for the
|
|
13
|
+
* JavaScript primitive types a command property can have. Registered once, on module load.
|
|
14
|
+
*/
|
|
15
|
+
function registerDefaultFieldTypeProviders() {
|
|
16
|
+
fieldTypeProviderRegistry.registerFieldTypeProvider({ canHandle: descriptor => descriptor.type === String, component: InputTextField.InputTextField });
|
|
17
|
+
fieldTypeProviderRegistry.registerFieldTypeProvider({ canHandle: descriptor => descriptor.type === Number, component: NumberField.NumberField });
|
|
18
|
+
fieldTypeProviderRegistry.registerFieldTypeProvider({ canHandle: descriptor => descriptor.type === Boolean, component: CheckboxField.CheckboxField });
|
|
19
|
+
fieldTypeProviderRegistry.registerFieldTypeProvider({ canHandle: descriptor => descriptor.type === Date, component: CalendarField.CalendarField });
|
|
20
|
+
}
|
|
21
|
+
registerDefaultFieldTypeProviders();
|
|
22
|
+
|
|
23
|
+
exports.registerDefaultFieldTypeProviders = registerDefaultFieldTypeProviders;
|
|
24
|
+
//# sourceMappingURL=defaultFieldTypeProviders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultFieldTypeProviders.js","sources":["../../../CommandForm/defaultFieldTypeProviders.ts"],"sourcesContent":[null],"names":["registerFieldTypeProvider","InputTextField","NumberField","CheckboxField","CalendarField"],"mappings":";;;;;;;;AAAA;AACA;AAQA;;;AAGG;SACa,iCAAiC,GAAA;AAC7C,IAAAA,mDAAyB,CAAC,EAAE,SAAS,EAAE,UAAU,IAAI,UAAU,CAAC,IAAI,KAAK,MAAM,EAAE,SAAS,EAAEC,6BAAc,EAAE,CAAC;AAC7G,IAAAD,mDAAyB,CAAC,EAAE,SAAS,EAAE,UAAU,IAAI,UAAU,CAAC,IAAI,KAAK,MAAM,EAAE,SAAS,EAAEE,uBAAW,EAAE,CAAC;AAC1G,IAAAF,mDAAyB,CAAC,EAAE,SAAS,EAAE,UAAU,IAAI,UAAU,CAAC,IAAI,KAAK,OAAO,EAAE,SAAS,EAAEG,2BAAa,EAAE,CAAC;AAC7G,IAAAH,mDAAyB,CAAC,EAAE,SAAS,EAAE,UAAU,IAAI,UAAU,CAAC,IAAI,KAAK,IAAI,EAAE,SAAS,EAAEI,2BAAa,EAAE,CAAC;AAC9G;AAEA,iCAAiC,EAAE;;;;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
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 providers = [];
|
|
6
|
+
/**
|
|
7
|
+
* Registers a {@link FieldTypeProvider} that {@link AutoCommandForm} consults when choosing which
|
|
8
|
+
* field component to render for a command property.
|
|
9
|
+
*
|
|
10
|
+
* Providers are consulted most-recently-registered first, so a provider registered by consuming
|
|
11
|
+
* application code overrides one of the built-in defaults for the same property type.
|
|
12
|
+
* @param provider The provider to register.
|
|
13
|
+
*/
|
|
14
|
+
function registerFieldTypeProvider(provider) {
|
|
15
|
+
providers.unshift(provider);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Finds the first registered {@link FieldTypeProvider} that handles the given property.
|
|
19
|
+
* @param propertyDescriptor The property to resolve a provider for.
|
|
20
|
+
* @returns The matching provider, or undefined if none handles this property's type.
|
|
21
|
+
*/
|
|
22
|
+
function resolveFieldTypeProvider(propertyDescriptor) {
|
|
23
|
+
return providers.find(provider => provider.canHandle(propertyDescriptor));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Clears every registered provider, including the built-in defaults. Exposed for specs; a
|
|
27
|
+
* consuming application should not normally call this.
|
|
28
|
+
*/
|
|
29
|
+
function clearFieldTypeProviders() {
|
|
30
|
+
providers.length = 0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
exports.clearFieldTypeProviders = clearFieldTypeProviders;
|
|
34
|
+
exports.registerFieldTypeProvider = registerFieldTypeProvider;
|
|
35
|
+
exports.resolveFieldTypeProvider = resolveFieldTypeProvider;
|
|
36
|
+
//# sourceMappingURL=fieldTypeProviderRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fieldTypeProviderRegistry.js","sources":["../../../CommandForm/fieldTypeProviderRegistry.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;AACA;AAKA,MAAM,SAAS,GAAwB,EAAE;AAEzC;;;;;;;AAOG;AACG,SAAU,yBAAyB,CAAC,QAA2B,EAAA;AACjE,IAAA,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC;AAC/B;AAEA;;;;AAIG;AACG,SAAU,wBAAwB,CAAC,kBAAsC,EAAA;AAC3E,IAAA,OAAO,SAAS,CAAC,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;AAC7E;AAEA;;;AAGG;SACa,uBAAuB,GAAA;AACnC,IAAA,SAAS,CAAC,MAAM,GAAG,CAAC;AACxB;;;;;;"}
|
|
@@ -12,6 +12,8 @@ var MultiSelectField = require('./fields/MultiSelectField.js');
|
|
|
12
12
|
var ChipsField = require('./fields/ChipsField.js');
|
|
13
13
|
var RadioButtonField = require('./fields/RadioButtonField.js');
|
|
14
14
|
var RadioGroupField = require('./fields/RadioGroupField.js');
|
|
15
|
+
var fieldTypeProviderRegistry = require('./fieldTypeProviderRegistry.js');
|
|
16
|
+
var AutoCommandForm = require('./AutoCommandForm.js');
|
|
15
17
|
|
|
16
18
|
// Copyright (c) Cratis. All rights reserved.
|
|
17
19
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
@@ -28,4 +30,8 @@ exports.MultiSelectField = MultiSelectField.MultiSelectField;
|
|
|
28
30
|
exports.ChipsField = ChipsField.ChipsField;
|
|
29
31
|
exports.RadioButtonField = RadioButtonField.RadioButtonField;
|
|
30
32
|
exports.RadioGroupField = RadioGroupField.RadioGroupField;
|
|
33
|
+
exports.clearFieldTypeProviders = fieldTypeProviderRegistry.clearFieldTypeProviders;
|
|
34
|
+
exports.registerFieldTypeProvider = fieldTypeProviderRegistry.registerFieldTypeProvider;
|
|
35
|
+
exports.resolveFieldTypeProvider = fieldTypeProviderRegistry.resolveFieldTypeProvider;
|
|
36
|
+
exports.AutoCommandForm = AutoCommandForm.AutoCommandForm;
|
|
31
37
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../CommandForm/index.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../CommandForm/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA;AACA;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CommandFormProps } from '@cratis/arc.react/commands';
|
|
3
|
+
import './defaultFieldTypeProviders';
|
|
4
|
+
export interface AutoCommandFormProps<TCommand extends object, TResponse = object> extends Omit<CommandFormProps<TCommand, TResponse>, 'children'> {
|
|
5
|
+
exclude?: (keyof TCommand)[];
|
|
6
|
+
}
|
|
7
|
+
export declare function AutoCommandForm<TCommand extends object = object, TResponse = object>(props: AutoCommandFormProps<TCommand, TResponse>): React.ReactElement;
|
|
8
|
+
//# sourceMappingURL=AutoCommandForm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutoCommandForm.d.ts","sourceRoot":"","sources":["../../../CommandForm/AutoCommandForm.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAe,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE3E,OAAO,6BAA6B,CAAC;AAMrC,MAAM,WAAW,oBAAoB,CAAC,QAAQ,SAAS,MAAM,EAAE,SAAS,GAAG,MAAM,CAAE,SAAQ,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,UAAU,CAAC;IAK9I,OAAO,CAAC,EAAE,CAAC,MAAM,QAAQ,CAAC,EAAE,CAAC;CAChC;AAwBD,wBAAgB,eAAe,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,EAAE,SAAS,GAAG,MAAM,EAChF,KAAK,EAAE,oBAAoB,CAAC,QAAQ,EAAE,SAAS,CAAC,GACjD,KAAK,CAAC,YAAY,CAyBpB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { CommandForm } from '@cratis/arc.react/commands';
|
|
4
|
+
import { resolveFieldTypeProvider } from './fieldTypeProviderRegistry.js';
|
|
5
|
+
import './defaultFieldTypeProviders.js';
|
|
6
|
+
|
|
7
|
+
function formatTitle(propertyName) {
|
|
8
|
+
return propertyName
|
|
9
|
+
.replace(/([A-Z])/g, ' $1')
|
|
10
|
+
.replace(/^./, character => character.toUpperCase())
|
|
11
|
+
.trim();
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A `CommandForm` that generates its field list from the command's own properties, choosing each
|
|
15
|
+
* field's component by the property's type through the {@link FieldTypeProvider} registry -
|
|
16
|
+
* `registerFieldTypeProvider` for a type the built-in defaults (`string`, `number`, `boolean`,
|
|
17
|
+
* `Date`) don't cover, or to override one of them.
|
|
18
|
+
*
|
|
19
|
+
* A property whose type no registered provider handles is left out of the generated list -
|
|
20
|
+
* `exclude` it explicitly for clarity, or add a `CommandForm` child by hand alongside this
|
|
21
|
+
* component for that one property.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* <AutoCommandForm command={RegisterInvoice} exclude={['invoiceId']} />
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
function AutoCommandForm(props) {
|
|
29
|
+
const { exclude, ...commandFormProps } = props;
|
|
30
|
+
const propertyDescriptors = useMemo(() => new props.command().propertyDescriptors, [props.command]);
|
|
31
|
+
const excluded = useMemo(() => new Set((exclude ?? [])), [exclude]);
|
|
32
|
+
const fields = propertyDescriptors
|
|
33
|
+
.filter(descriptor => !excluded.has(descriptor.name))
|
|
34
|
+
.map(descriptor => {
|
|
35
|
+
const provider = resolveFieldTypeProvider(descriptor);
|
|
36
|
+
if (!provider) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const Field = provider.component;
|
|
40
|
+
return (jsx(Field, { value: (instance) => instance[descriptor.name], title: formatTitle(descriptor.name) }, descriptor.name));
|
|
41
|
+
})
|
|
42
|
+
.filter((field) => field !== null);
|
|
43
|
+
return jsx(CommandForm, { ...commandFormProps, children: fields });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { AutoCommandForm };
|
|
47
|
+
//# sourceMappingURL=AutoCommandForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutoCommandForm.js","sources":["../../../CommandForm/AutoCommandForm.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":";;;;;;AAqBA,SAAS,WAAW,CAAC,YAAoB,EAAA;AACrC,IAAA,OAAO;AACF,SAAA,OAAO,CAAC,UAAU,EAAE,KAAK;SACzB,OAAO,CAAC,IAAI,EAAE,SAAS,IAAI,SAAS,CAAC,WAAW,EAAE;AAClD,SAAA,IAAI,EAAE;AACf;AAEA;;;;;;;;;;;;;;AAcG;AACG,SAAU,eAAe,CAC3B,KAAgD,EAAA;IAEhD,MAAM,EAAE,OAAO,EAAE,GAAG,gBAAgB,EAAE,GAAG,KAAK;IAC9C,MAAM,mBAAmB,GAAG,OAAO,CAAC,MAAO,IAAI,KAAK,CAAC,OAAO,EAAyB,CAAC,mBAAmB,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3H,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,IAAI,GAAG,EAAU,OAAO,IAAI,EAAE,EAAc,EAAE,CAAC,OAAO,CAAC,CAAC;IAEvF,MAAM,MAAM,GAAG;AACV,SAAA,MAAM,CAAC,UAAU,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC;SACnD,GAAG,CAAC,UAAU,IAAG;AACd,QAAA,MAAM,QAAQ,GAAG,wBAAwB,CAAC,UAAU,CAAC;QACrD,IAAI,CAAC,QAAQ,EAAE;AACX,YAAA,OAAO,IAAI;QACf;AAEA,QAAA,MAAM,KAAK,GAAG,QAAQ,CAAC,SAAS;AAChC,QAAA,QACIA,GAAA,CAAC,KAAK,EAAA,EAEF,KAAK,EAAE,CAAC,QAAkB,KAAM,QAA+C,CAAC,UAAU,CAAC,IAAI,CAAC,EAChG,KAAK,EAAE,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,EAAA,EAF9B,UAAU,CAAC,IAAI,CAGtB;AAEV,IAAA,CAAC;SACA,MAAM,CAAC,CAAC,KAAK,KAAkC,KAAK,KAAK,IAAI,CAAC;AAEnE,IAAA,OAAOA,IAAC,WAAW,EAAA,EAAA,GAAK,gBAAgB,EAAA,QAAA,EAAG,MAAM,GAAe;AACpE;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PropertyDescriptor } from '@cratis/arc/reflection';
|
|
2
|
+
import { ComponentType } from 'react';
|
|
3
|
+
export interface FieldTypeProvider {
|
|
4
|
+
canHandle(propertyDescriptor: PropertyDescriptor): boolean;
|
|
5
|
+
component: ComponentType<any>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=FieldTypeProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FieldTypeProvider.d.ts","sourceRoot":"","sources":["../../../CommandForm/FieldTypeProvider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAMtC,MAAM,WAAW,iBAAiB;IAM9B,SAAS,CAAC,kBAAkB,EAAE,kBAAkB,GAAG,OAAO,CAAC;IAO3D,SAAS,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;CACjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FieldTypeProvider.js","sourceRoot":"","sources":["../../../CommandForm/FieldTypeProvider.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultFieldTypeProviders.d.ts","sourceRoot":"","sources":["../../../CommandForm/defaultFieldTypeProviders.ts"],"names":[],"mappings":"AAaA,wBAAgB,iCAAiC,IAAI,IAAI,CAKxD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { registerFieldTypeProvider } from './fieldTypeProviderRegistry.js';
|
|
2
|
+
import { InputTextField } from './fields/InputTextField.js';
|
|
3
|
+
import { NumberField } from './fields/NumberField.js';
|
|
4
|
+
import { CheckboxField } from './fields/CheckboxField.js';
|
|
5
|
+
import { CalendarField } from './fields/CalendarField.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
|
+
* Registers the built-in {@link FieldTypeProvider}s {@link AutoCommandForm} falls back to for the
|
|
11
|
+
* JavaScript primitive types a command property can have. Registered once, on module load.
|
|
12
|
+
*/
|
|
13
|
+
function registerDefaultFieldTypeProviders() {
|
|
14
|
+
registerFieldTypeProvider({ canHandle: descriptor => descriptor.type === String, component: InputTextField });
|
|
15
|
+
registerFieldTypeProvider({ canHandle: descriptor => descriptor.type === Number, component: NumberField });
|
|
16
|
+
registerFieldTypeProvider({ canHandle: descriptor => descriptor.type === Boolean, component: CheckboxField });
|
|
17
|
+
registerFieldTypeProvider({ canHandle: descriptor => descriptor.type === Date, component: CalendarField });
|
|
18
|
+
}
|
|
19
|
+
registerDefaultFieldTypeProviders();
|
|
20
|
+
|
|
21
|
+
export { registerDefaultFieldTypeProviders };
|
|
22
|
+
//# sourceMappingURL=defaultFieldTypeProviders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultFieldTypeProviders.js","sources":["../../../CommandForm/defaultFieldTypeProviders.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AAAA;AACA;AAQA;;;AAGG;SACa,iCAAiC,GAAA;AAC7C,IAAA,yBAAyB,CAAC,EAAE,SAAS,EAAE,UAAU,IAAI,UAAU,CAAC,IAAI,KAAK,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC;AAC7G,IAAA,yBAAyB,CAAC,EAAE,SAAS,EAAE,UAAU,IAAI,UAAU,CAAC,IAAI,KAAK,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;AAC1G,IAAA,yBAAyB,CAAC,EAAE,SAAS,EAAE,UAAU,IAAI,UAAU,CAAC,IAAI,KAAK,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC;AAC7G,IAAA,yBAAyB,CAAC,EAAE,SAAS,EAAE,UAAU,IAAI,UAAU,CAAC,IAAI,KAAK,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC;AAC9G;AAEA,iCAAiC,EAAE;;;;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PropertyDescriptor } from '@cratis/arc/reflection';
|
|
2
|
+
import { FieldTypeProvider } from './FieldTypeProvider';
|
|
3
|
+
export declare function registerFieldTypeProvider(provider: FieldTypeProvider): void;
|
|
4
|
+
export declare function resolveFieldTypeProvider(propertyDescriptor: PropertyDescriptor): FieldTypeProvider | undefined;
|
|
5
|
+
export declare function clearFieldTypeProviders(): void;
|
|
6
|
+
//# sourceMappingURL=fieldTypeProviderRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fieldTypeProviderRegistry.d.ts","sourceRoot":"","sources":["../../../CommandForm/fieldTypeProviderRegistry.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAYxD,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAE3E;AAOD,wBAAgB,wBAAwB,CAAC,kBAAkB,EAAE,kBAAkB,GAAG,iBAAiB,GAAG,SAAS,CAE9G;AAMD,wBAAgB,uBAAuB,IAAI,IAAI,CAE9C"}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
const providers = [];
|
|
4
|
+
/**
|
|
5
|
+
* Registers a {@link FieldTypeProvider} that {@link AutoCommandForm} consults when choosing which
|
|
6
|
+
* field component to render for a command property.
|
|
7
|
+
*
|
|
8
|
+
* Providers are consulted most-recently-registered first, so a provider registered by consuming
|
|
9
|
+
* application code overrides one of the built-in defaults for the same property type.
|
|
10
|
+
* @param provider The provider to register.
|
|
11
|
+
*/
|
|
12
|
+
function registerFieldTypeProvider(provider) {
|
|
13
|
+
providers.unshift(provider);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Finds the first registered {@link FieldTypeProvider} that handles the given property.
|
|
17
|
+
* @param propertyDescriptor The property to resolve a provider for.
|
|
18
|
+
* @returns The matching provider, or undefined if none handles this property's type.
|
|
19
|
+
*/
|
|
20
|
+
function resolveFieldTypeProvider(propertyDescriptor) {
|
|
21
|
+
return providers.find(provider => provider.canHandle(propertyDescriptor));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Clears every registered provider, including the built-in defaults. Exposed for specs; a
|
|
25
|
+
* consuming application should not normally call this.
|
|
26
|
+
*/
|
|
27
|
+
function clearFieldTypeProviders() {
|
|
28
|
+
providers.length = 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { clearFieldTypeProviders, registerFieldTypeProvider, resolveFieldTypeProvider };
|
|
32
|
+
//# sourceMappingURL=fieldTypeProviderRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fieldTypeProviderRegistry.js","sources":["../../../CommandForm/fieldTypeProviderRegistry.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AAKA,MAAM,SAAS,GAAwB,EAAE;AAEzC;;;;;;;AAOG;AACG,SAAU,yBAAyB,CAAC,QAA2B,EAAA;AACjE,IAAA,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC;AAC/B;AAEA;;;;AAIG;AACG,SAAU,wBAAwB,CAAC,kBAAsC,EAAA;AAC3E,IAAA,OAAO,SAAS,CAAC,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;AAC7E;AAEA;;;AAGG;SACa,uBAAuB,GAAA;AACnC,IAAA,SAAS,CAAC,MAAM,GAAG,CAAC;AACxB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../CommandForm/index.ts"],"names":[],"mappings":"AAGA,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../CommandForm/index.ts"],"names":[],"mappings":"AAGA,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mBAAmB,CAAC"}
|
|
@@ -10,6 +10,8 @@ export { MultiSelectField } from './fields/MultiSelectField.js';
|
|
|
10
10
|
export { ChipsField } from './fields/ChipsField.js';
|
|
11
11
|
export { RadioButtonField } from './fields/RadioButtonField.js';
|
|
12
12
|
export { RadioGroupField } from './fields/RadioGroupField.js';
|
|
13
|
+
export { clearFieldTypeProviders, registerFieldTypeProvider, resolveFieldTypeProvider } from './fieldTypeProviderRegistry.js';
|
|
14
|
+
export { AutoCommandForm } from './AutoCommandForm.js';
|
|
13
15
|
|
|
14
16
|
// Copyright (c) Cratis. All rights reserved.
|
|
15
17
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../CommandForm/index.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../CommandForm/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;AACA"}
|