@headless-adminapp/fluent 1.2.0 → 1.2.1

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.
@@ -18,6 +18,7 @@ const DateTimeControl_1 = require("../form/controls/DateTimeControl");
18
18
  const DecimalControl_1 = require("../form/controls/DecimalControl");
19
19
  const DurationControl_1 = require("../form/controls/DurationControl");
20
20
  const EmailControl_1 = require("../form/controls/EmailControl");
21
+ const IdControl_1 = require("../form/controls/IdControl");
21
22
  const IntegerControl_1 = require("../form/controls/IntegerControl");
22
23
  const LookupControl_1 = require("../form/controls/LookupControl");
23
24
  const MultiSelectControl_1 = __importDefault(require("../form/controls/MultiSelectControl"));
@@ -56,6 +57,21 @@ const StandardControl = (props) => {
56
57
  const { schemaStore, experienceStore } = (0, hooks_1.useMetadata)();
57
58
  // const { openQuickCreate } = useQuickCreateForm();
58
59
  switch (attribute.type) {
60
+ case 'id': {
61
+ const controlProps = {
62
+ name,
63
+ placeholder,
64
+ value,
65
+ onChange,
66
+ onBlur,
67
+ error: isError,
68
+ disabled: readOnly,
69
+ readOnly,
70
+ };
71
+ const Control = componentStore_1.componentStore.getComponent('Form.IdControl') ??
72
+ IdControl_1.IdControl;
73
+ return (0, jsx_runtime_1.jsx)(Control, { ...controlProps, idTypes: attribute });
74
+ }
59
75
  case 'string': {
60
76
  const controlProps = {
61
77
  name,
@@ -0,0 +1,7 @@
1
+ import { Id } from '@headless-adminapp/core';
2
+ import { IdTypes } from '@headless-adminapp/core/attributes/IdAttribute';
3
+ import { ControlProps } from './types';
4
+ export interface IdControlProps extends ControlProps<Id> {
5
+ idTypes: IdTypes;
6
+ }
7
+ export declare function IdControl({ idTypes, ...props }: Readonly<IdControlProps>): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IdControl = IdControl;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const IntegerControl_1 = require("./IntegerControl");
6
+ const TextControl_1 = require("./TextControl");
7
+ function formatGuid(value) {
8
+ if (!value) {
9
+ return '';
10
+ }
11
+ value = value.replace(/[^0-9a-fA-F]/g, '');
12
+ const part1 = value.substring(0, 8);
13
+ const part2 = value.substring(8, 12);
14
+ const part3 = value.substring(12, 16);
15
+ const part4 = value.substring(16, 20);
16
+ const part5 = value.substring(20, 32);
17
+ let formattedValue = '';
18
+ formattedValue += part1;
19
+ if (part2) {
20
+ formattedValue += `-${part2}`;
21
+ }
22
+ if (part3) {
23
+ formattedValue += `-${part3}`;
24
+ }
25
+ if (part4) {
26
+ formattedValue += `-${part4}`;
27
+ }
28
+ if (part5) {
29
+ formattedValue += `-${part5}`;
30
+ }
31
+ return formattedValue.toLowerCase();
32
+ }
33
+ function formatObjectId(value) {
34
+ if (!value) {
35
+ return '';
36
+ }
37
+ value = value.replace(/[^0-9a-fA-F]/g, '');
38
+ return value.substring(0, 24).toLowerCase();
39
+ }
40
+ function IdControl({ idTypes, ...props }) {
41
+ if ('string' in idTypes && idTypes.string) {
42
+ return (0, jsx_runtime_1.jsx)(TextControl_1.TextControl, { ...props, value: props.value });
43
+ }
44
+ else if ('number' in idTypes && idTypes.number) {
45
+ return (0, jsx_runtime_1.jsx)(IntegerControl_1.IntegerControl, { ...props, value: props.value });
46
+ }
47
+ else if ('guid' in idTypes && idTypes.guid) {
48
+ return ((0, jsx_runtime_1.jsx)(TextControl_1.TextControl, { ...props, maxLength: 36, value: formatGuid(props.value), onChange: (value) => {
49
+ if (!value) {
50
+ props.onChange?.(null);
51
+ }
52
+ else {
53
+ props.onChange?.(formatGuid(value));
54
+ }
55
+ } }));
56
+ }
57
+ else if ('objectId' in idTypes && idTypes.objectId) {
58
+ return ((0, jsx_runtime_1.jsx)(TextControl_1.TextControl, { ...props, maxLength: 24, value: props.value, onChange: (value) => {
59
+ if (!value) {
60
+ props.onChange?.(null);
61
+ }
62
+ else {
63
+ props.onChange?.(formatObjectId(value));
64
+ }
65
+ } }));
66
+ }
67
+ return ((0, jsx_runtime_1.jsx)(TextControl_1.TextControl, { ...props, value: props.value ? String(props.value) : null, onChange: () => { }, placeholder: "Unsupported ID type", disabled: true }));
68
+ }
@@ -6,5 +6,6 @@ export interface TextControlProps extends ControlProps<string> {
6
6
  autoCorrect?: string;
7
7
  textTransform?: 'capitalize' | 'uppercase' | 'lowercase' | 'none';
8
8
  appearance?: InputProps['appearance'];
9
+ maxLength?: number;
9
10
  }
10
- export declare function TextControl({ value, onChange, id, name, onBlur, onFocus, placeholder, disabled, autoComplete, autoFocus, autoCapitalize, autoCorrect, textTransform, readOnly, appearance, }: TextControlProps): import("react/jsx-runtime").JSX.Element;
11
+ export declare function TextControl({ value, onChange, id, name, onBlur, onFocus, placeholder, disabled, autoComplete, autoFocus, autoCapitalize, autoCorrect, textTransform, readOnly, appearance, maxLength, }: TextControlProps): import("react/jsx-runtime").JSX.Element;
@@ -7,7 +7,7 @@ function TextControl({ value, onChange, id, name, onBlur, onFocus,
7
7
  // error,
8
8
  placeholder, disabled, autoComplete, autoFocus, autoCapitalize, autoCorrect, textTransform,
9
9
  // borderOnFocusOnly,
10
- readOnly, appearance = 'filled-darker', }) {
10
+ readOnly, appearance = 'filled-darker', maxLength, }) {
11
11
  const readonly = disabled || readOnly;
12
12
  return ((0, jsx_runtime_1.jsx)(react_components_1.Input, { placeholder: placeholder, id: id, name: name, autoFocus: autoFocus, appearance: appearance, value: value || '', onChange: (e) => {
13
13
  textTransform === 'uppercase'
@@ -20,5 +20,5 @@ readOnly, appearance = 'filled-darker', }) {
20
20
  // readOnly={readOnly || disabled}
21
21
  readOnly: readonly, autoComplete: autoComplete, autoCorrect: autoCorrect, autoCapitalize: autoCapitalize, className: (0, react_components_1.mergeClasses)(readonly && 'TextControl_readonly'), style: {
22
22
  width: '100%',
23
- } }));
23
+ }, maxLength: maxLength }));
24
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@headless-adminapp/fluent",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -50,5 +50,5 @@
50
50
  "uuid": "11.0.3",
51
51
  "yup": "^1.4.0"
52
52
  },
53
- "gitHead": "3c59cbbf000e71e39b81c9440a71363b729e6e3c"
53
+ "gitHead": "1cf9322dda84c1898cc90f1e92278b79ed9f2902"
54
54
  }