@aglyn/shared-ui-jsx-forms 1.20.1 → 1.20.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/shared-ui-jsx-forms",
3
- "version": "1.20.1",
3
+ "version": "1.20.3",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -25,13 +25,13 @@
25
25
  "./package.json": "./package.json"
26
26
  },
27
27
  "dependencies": {
28
- "@aglyn/shared-data-enums": "1.20.1",
29
- "@aglyn/shared-data-mdi": "1.20.1",
30
- "@aglyn/shared-ui-color-picker": "1.20.1",
31
- "@aglyn/shared-ui-jsx": "1.20.1",
32
- "@aglyn/shared-ui-theme": "1.20.1",
33
- "@aglyn/shared-util-tools": "1.20.1",
34
- "@aglyn/shared-util-vendor": "1.20.1",
28
+ "@aglyn/shared-data-enums": "1.20.3",
29
+ "@aglyn/shared-data-mdi": "1.20.3",
30
+ "@aglyn/shared-ui-color-picker": "1.20.3",
31
+ "@aglyn/shared-ui-jsx": "1.20.3",
32
+ "@aglyn/shared-ui-theme": "1.20.3",
33
+ "@aglyn/shared-util-tools": "1.20.3",
34
+ "@aglyn/shared-util-vendor": "1.20.3",
35
35
  "@data-driven-forms/common": "^4.2.0",
36
36
  "@data-driven-forms/react-form-renderer": "^4.2.0",
37
37
  "@swc/helpers": "0.5.23",
@@ -20,13 +20,21 @@ import { type FormTemplateRenderProps } from '../vendor/data-driven-forms';
20
20
  * A drawer rather than a dialog on purpose: creating is a drawer, picking is
21
21
  * a dialog (AGL-699). Editing is neither — it is the record's own page.
22
22
  */
23
+ /** What a create hands back: nothing, or the reason per field it refused. */
24
+ export type SubmitRefusal = void | undefined | Record<string, string>;
23
25
  export interface CreateArtifactDrawerProps {
24
26
  open: boolean;
25
27
  onClose: () => void;
26
28
  /** Drawer heading, e.g. "Create new component". */
27
29
  title: string;
28
- /** Receives the collected field values; closing is the caller's job. */
29
- onSubmit: (values: Record<string, any>) => void | Promise<void>;
30
+ /**
31
+ * Receives the collected field values; closing is the caller's job.
32
+ *
33
+ * A refusal that belongs to one field comes back as `{ [name]: reason }`,
34
+ * final-form's submission errors: the field says it beside itself and stops
35
+ * once its value changes, and every value stays as it was chosen.
36
+ */
37
+ onSubmit: (values: Record<string, any>) => SubmitRefusal | Promise<SubmitRefusal>;
30
38
  /** Extra fields appended after name and description. */
31
39
  extraFields?: any[];
32
40
  /** Rendered under the form when a submit fails. */
@@ -21,7 +21,8 @@ import { ICON_VARIANT_CLOSE } from "@aglyn/shared-data-enums";
21
21
  import { Container, MdiIcon, SrOnly } from "@aglyn/shared-ui-jsx";
22
22
  import { NavigationDrawerComponent } from "@aglyn/shared-ui-jsx/components/navigation-drawer.component";
23
23
  import { Box, Button, FormControl, Grid, IconButton, Typography } from "@mui/material";
24
- import { forwardRef } from "react";
24
+ import { isEqual } from "lodash-es";
25
+ import { forwardRef, useState } from "react";
25
26
  import { FormRenderer, FormSpy, useFormApi } from "../vendor/data-driven-forms.js";
26
27
  import { simpleComponentMapper } from "../constants/component-mappers.js";
27
28
  /**
@@ -79,11 +80,12 @@ ArtifactFormTemplate.displayName = 'ArtifactFormTemplate';
79
80
  ArtifactFormTemplate.aglyn = true;
80
81
  export function CreateArtifactDrawer(props) {
81
82
  const { open, onClose, title, onSubmit, extraFields, errorSlot, includeDescription = true, FormTemplate = ArtifactFormTemplate, submitLabel, componentMapper } = props;
83
+ const [initialValues] = useState(()=>new Map());
82
84
  const schema = _extends({
83
- fields: [
85
+ fields: keepInitialValues([
84
86
  ...includeDescription ? BASE_FIELDS : BASE_FIELDS.filter((field)=>field.name !== 'description'),
85
87
  ...extraFields != null ? extraFields : []
86
- ]
88
+ ], initialValues)
87
89
  }, submitLabel ? {
88
90
  submitLabel
89
91
  } : {});
@@ -146,6 +148,38 @@ export function CreateArtifactDrawer(props) {
146
148
  })
147
149
  });
148
150
  }
151
+ /**
152
+ * Each field's `initialValue`, kept as the same object for as long as it is
153
+ * equal to the one before (AGL-4047).
154
+ *
155
+ * Callers build their fields on every draw, so an object or array initial
156
+ * value is a new one each time the page around the drawer draws. The form
157
+ * library takes a new initial value as a new field: it lets the old one go
158
+ * and registers it again from that value, so a page drawing again, as it does
159
+ * to say why a create was refused, put the field back where it started — "All
160
+ * sites" with the ticked sites dropped, a second press creating what nobody
161
+ * chose. Keeping the reference keeps the field, and with it what was chosen.
162
+ * A value that really changes still comes through.
163
+ */ function keepInitialValues(fields, kept) {
164
+ return fields.map((field)=>{
165
+ if (!field || typeof field !== 'object') return field;
166
+ let next = field;
167
+ if (typeof field.name === 'string' && 'initialValue' in field) {
168
+ const before = kept.get(field.name);
169
+ if (before !== field.initialValue && kept.has(field.name) && isEqual(before, field.initialValue)) {
170
+ next = _extends({}, field, {
171
+ initialValue: before
172
+ });
173
+ } else {
174
+ kept.set(field.name, field.initialValue);
175
+ }
176
+ }
177
+ // A sub-form's own fields are registered the same way.
178
+ return Array.isArray(next.fields) ? _extends({}, next, {
179
+ fields: keepInitialValues(next.fields, kept)
180
+ }) : next;
181
+ });
182
+ }
149
183
  /**
150
184
  * Same shape and limits the layouts drawer has used since AGL-473, so the
151
185
  * creates across the console validate identically.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../libs/shared/ui/jsx-forms/src/lib/components/create-artifact-drawer.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport { ICON_VARIANT_CLOSE } from '@aglyn/shared-data-enums'\nimport { Container, MdiIcon, SrOnly } from '@aglyn/shared-ui-jsx'\nimport { NavigationDrawerComponent } from '@aglyn/shared-ui-jsx/components/navigation-drawer.component'\nimport {\n Box,\n Button,\n FormControl,\n Grid,\n IconButton,\n Typography,\n} from '@mui/material'\nimport { type ComponentType, forwardRef, type ReactNode } from 'react'\nimport {\n FormRenderer,\n FormSpy,\n type FormTemplateRenderProps,\n useFormApi,\n} from '../vendor/data-driven-forms'\nimport { simpleComponentMapper } from '../constants/component-mappers'\n\n/**\n * THE naming step in front of Create (AGL-700), shared by every console list\n * surface that creates a record.\n *\n * ## Why it lives in a library\n *\n * It began in `apps/console`, which put it out of reach of the console pages\n * that plugins ship — a plugin's console card cannot import from the app that\n * renders it. So a plugin adding a create button had two options, both bad:\n * an inline form stacked above its table, or a second drawer that looks\n * almost but not quite like this one. Both are how a console comes to have\n * three ways of creating a record.\n *\n * The console keeps a thin wrapper at its old path so its four existing call\n * sites are untouched; it passes its own auth form template through\n * {@link CreateArtifactDrawerProps.FormTemplate}.\n *\n * A drawer rather than a dialog on purpose: creating is a drawer, picking is\n * a dialog (AGL-699). Editing is neither — it is the record's own page.\n */\nexport interface CreateArtifactDrawerProps {\n open: boolean\n onClose: () => void\n /** Drawer heading, e.g. \"Create new component\". */\n title: string\n /** Receives the collected field values; closing is the caller's job. */\n onSubmit: (values: Record<string, any>) => void | Promise<void>\n /** Extra fields appended after name and description. */\n extraFields?: any[]\n /** Rendered under the form when a submit fails. */\n errorSlot?: ReactNode\n /**\n * Whether to offer the shared Description box (AGL-2498).\n *\n * True for every artifact whose document stores one. Content collections do\n * not: `/api/hosts/collections` filters `data` through a per-kind allowlist\n * of `displayName` + `slug`, so a description typed here would be dropped\n * without a word. A field the writer silently discards is worse than a field\n * that was never offered.\n */\n includeDescription?: boolean\n /**\n * The form's own chrome — the submit button and how the fields are laid out.\n *\n * Injectable because the console's version renders an auth-aware template\n * that lives in the app and depends on the console's session hook. Defaults\n * to {@link ArtifactFormTemplate}, which is the same layout without that\n * dependency.\n *\n * A template reads form state — `submitting`, `valid` — through a\n * `FormSpy`. The form does not draw its template again when that state\n * changes, so the `pristine` and `valid` on `useFormApi()` keep the values\n * they had when the drawer opened.\n */\n FormTemplate?: any\n /** Label on the submit button. */\n submitLabel?: string\n /**\n * Field components beyond the shared ones, by the `component` name an extra\n * field asks for. Merged over the drawer's own mapper, so a caller with one\n * field the library has no component for keeps the shared drawer.\n */\n componentMapper?: Record<string, ComponentType<any>>\n}\n\n/**\n * The default chrome: the fields in a grid and one submit button.\n *\n * No Cancel button of its own — the drawer's app bar already carries one, and\n * a second Cancel inside the form is the shape a reader has to think about.\n */\nexport const ArtifactFormTemplate = forwardRef<any, FormTemplateRenderProps>(\n (props, ref) => {\n const { formFields, schema, ...rest } = props\n const { handleSubmit } = useFormApi()\n return (\n <form ref={ref} onSubmit={handleSubmit} noValidate {...rest}>\n {schema.title}\n <Grid spacing={2} container>\n {formFields as any}\n </Grid>\n {/* `submitting` alone: it is all the button reads, and a spy with\n no subscription draws the button again on every keystroke. */}\n <FormSpy subscription={{ submitting: true }}>\n {({ submitting }) => (\n <Box sx={{ mt: 2 }}>\n <FormControl margin=\"normal\" fullWidth>\n <Button\n color=\"primary\"\n disabled={submitting}\n type=\"submit\"\n variant=\"contained\"\n fullWidth\n >\n {(schema as { submitLabel?: string }).submitLabel ?? 'Next'}\n </Button>\n </FormControl>\n </Box>\n )}\n </FormSpy>\n </form>\n )\n },\n)\nArtifactFormTemplate.displayName = 'ArtifactFormTemplate'\n;(ArtifactFormTemplate as any).aglyn = true\n\nexport function CreateArtifactDrawer(props: CreateArtifactDrawerProps) {\n const {\n open,\n onClose,\n title,\n onSubmit,\n extraFields,\n errorSlot,\n includeDescription = true,\n FormTemplate = ArtifactFormTemplate,\n submitLabel,\n componentMapper,\n } = props\n const schema = {\n fields: [\n ...(includeDescription\n ? BASE_FIELDS\n : BASE_FIELDS.filter((field) => field.name !== 'description')),\n ...(extraFields ?? []),\n ],\n ...(submitLabel ? { submitLabel } : {}),\n }\n return (\n <NavigationDrawerComponent\n open={open}\n anchor=\"right\"\n variant=\"temporary\"\n onClose={onClose}\n AppBarProps={{ color: 'surface' }}\n appBarLeft={\n <>\n <IconButton\n color=\"inherit\"\n edge=\"start\"\n onClick={onClose}\n sx={{ mr: 2 }}\n >\n <MdiIcon path={ICON_VARIANT_CLOSE.path} />\n <SrOnly>close drawer</SrOnly>\n </IconButton>\n <Typography variant=\"h6\" component=\"div\">\n {title}\n </Typography>\n </>\n }\n appBarRight={\n <Button variant=\"outlined\" color=\"inherit\" onClick={onClose}>\n {'Cancel'}\n </Button>\n }\n >\n <Container gutterY>\n {/*\n The form subscribes to nothing, so a keystroke draws the field it\n lands in and no other (AGL-3423). Each field reads its own state, a\n condition watches the fields it names, and the template's button\n watches `submitting` through its own FormSpy: nothing here is drawn\n from the form's state as a whole. The renderer's own defaults —\n pristine, submitting, valid — are switched off too: a change in any\n of them draws every field again, and the first letter of a required\n name changes two of them.\n */}\n <FormRenderer\n FormTemplate={FormTemplate}\n componentMapper={\n componentMapper\n ? { ...simpleComponentMapper, ...componentMapper }\n : simpleComponentMapper\n }\n onSubmit={onSubmit}\n schema={schema}\n subscription={{ pristine: false, submitting: false, valid: false }}\n clearOnUnmount\n />\n {errorSlot}\n </Container>\n </NavigationDrawerComponent>\n )\n}\n\n/**\n * Same shape and limits the layouts drawer has used since AGL-473, so the\n * creates across the console validate identically.\n */\nexport const BASE_FIELDS = [\n {\n component: 'text-field',\n name: 'displayName',\n helperText: 'Friendly name for internal reference',\n type: 'text',\n label: 'Display name',\n isRequired: true,\n validate: [\n { type: 'required', message: 'Provide a display name' },\n {\n type: 'max-length',\n threshold: 25,\n message: 'Must not exceed 25 characters',\n },\n ],\n },\n {\n component: 'textarea',\n name: 'description',\n label: 'Description',\n helperText: 'Brief description for internal reference',\n validate: [\n {\n type: 'max-length',\n threshold: 80,\n message: 'Must not exceed 80 characters',\n },\n ],\n },\n]\n\nCreateArtifactDrawer.displayName = 'CreateArtifactDrawer'\n\nexport default CreateArtifactDrawer\n"],"names":["ICON_VARIANT_CLOSE","Container","MdiIcon","SrOnly","NavigationDrawerComponent","Box","Button","FormControl","Grid","IconButton","Typography","forwardRef","FormRenderer","FormSpy","useFormApi","simpleComponentMapper","ArtifactFormTemplate","props","ref","formFields","schema","rest","handleSubmit","form","onSubmit","noValidate","title","spacing","container","subscription","submitting","sx","mt","margin","fullWidth","color","disabled","type","variant","submitLabel","displayName","aglyn","CreateArtifactDrawer","open","onClose","extraFields","errorSlot","includeDescription","FormTemplate","componentMapper","fields","BASE_FIELDS","filter","field","name","anchor","AppBarProps","appBarLeft","edge","onClick","mr","path","component","appBarRight","gutterY","pristine","valid","clearOnUnmount","helperText","label","isRequired","validate","message","threshold"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;;AAEA,SAASA,kBAAkB,QAAQ,2BAA0B;AAC7D,SAASC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ,uBAAsB;AACjE,SAASC,yBAAyB,QAAQ,8DAA6D;AACvG,SACEC,GAAG,EACHC,MAAM,EACNC,WAAW,EACXC,IAAI,EACJC,UAAU,EACVC,UAAU,QACL,gBAAe;AACtB,SAA6BC,UAAU,QAAwB,QAAO;AACtE,SACEC,YAAY,EACZC,OAAO,EAEPC,UAAU,QACL,iCAA6B;AACpC,SAASC,qBAAqB,QAAQ,oCAAgC;AAmEtE;;;;;CAKC,GACD,OAAO,MAAMC,qCAAuBL,WAClC,CAACM,OAAOC;IACN,MAAM,EAAEC,UAAU,EAAEC,MAAM,EAAW,GAAGH,OAATI,wCAASJ;;;;IACxC,MAAM,EAAEK,YAAY,EAAE,GAAGR;IACzB,qBACE,MAACS;QAAKL,KAAKA;QAAKM,UAAUF;QAAcG,UAAU;OAAKJ;;YACpDD,OAAOM,KAAK;0BACb,KAAClB;gBAAKmB,SAAS;gBAAGC,SAAS;0BACxBT;;0BAIH,KAACN;gBAAQgB,cAAc;oBAA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8BAWhB,KAACpD;oBACCoC,cAAcA;oBACdC,iBACEA,kBACI,aAAKlC,uBAA0BkC,mBAC/BlC;oBAENS,UAAUA;oBACVJ,QAAQA;oBACRS,cAAc;wBAAEoC,UAAU;wBAAOnC,YAAY;wBAAOoC,OAAO;oBAAM;oBACjEC,cAAc;;gBAEfrB;;;;AAIT;AAEA;;;CAGC,GACD,OAAO,MAAMK,cAAc;IACzB;QACEW,WAAW;QACXR,MAAM;QACNc,YAAY;QACZ/B,MAAM;QACNgC,OAAO;QACPC,YAAY;QACZC,UAAU;YACR;gBAAElC,MAAM;gBAAYmC,SAAS;YAAyB;YACtD;gBACEnC,MAAM;gBACNoC,WAAW;gBACXD,SAAS;YACX;SACD;IACH;IACA;QACEV,WAAW;QACXR,MAAM;QACNe,OAAO;QACPD,YAAY;QACZG,UAAU;YACR;gBACElC,MAAM;gBACNoC,WAAW;gBACXD,SAAS;YACX;SACD;IACH;CACD,CAAA;AAED9B,qBAAqBF,WAAW,GAAG;AAEnC,eAAeE,qBAAoB"}
1
+ {"version":3,"sources":["../../../../../../../../libs/shared/ui/jsx-forms/src/lib/components/create-artifact-drawer.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport { ICON_VARIANT_CLOSE } from '@aglyn/shared-data-enums'\nimport { Container, MdiIcon, SrOnly } from '@aglyn/shared-ui-jsx'\nimport { NavigationDrawerComponent } from '@aglyn/shared-ui-jsx/components/navigation-drawer.component'\nimport {\n Box,\n Button,\n FormControl,\n Grid,\n IconButton,\n Typography,\n} from '@mui/material'\nimport { isEqual } from 'lodash-es'\nimport { type ComponentType, forwardRef, type ReactNode, useState } from 'react'\nimport {\n FormRenderer,\n FormSpy,\n type FormTemplateRenderProps,\n useFormApi,\n} from '../vendor/data-driven-forms'\nimport { simpleComponentMapper } from '../constants/component-mappers'\n\n/**\n * THE naming step in front of Create (AGL-700), shared by every console list\n * surface that creates a record.\n *\n * ## Why it lives in a library\n *\n * It began in `apps/console`, which put it out of reach of the console pages\n * that plugins ship — a plugin's console card cannot import from the app that\n * renders it. So a plugin adding a create button had two options, both bad:\n * an inline form stacked above its table, or a second drawer that looks\n * almost but not quite like this one. Both are how a console comes to have\n * three ways of creating a record.\n *\n * The console keeps a thin wrapper at its old path so its four existing call\n * sites are untouched; it passes its own auth form template through\n * {@link CreateArtifactDrawerProps.FormTemplate}.\n *\n * A drawer rather than a dialog on purpose: creating is a drawer, picking is\n * a dialog (AGL-699). Editing is neither — it is the record's own page.\n */\n/** What a create hands back: nothing, or the reason per field it refused. */\nexport type SubmitRefusal = void | undefined | Record<string, string>\n\nexport interface CreateArtifactDrawerProps {\n open: boolean\n onClose: () => void\n /** Drawer heading, e.g. \"Create new component\". */\n title: string\n /**\n * Receives the collected field values; closing is the caller's job.\n *\n * A refusal that belongs to one field comes back as `{ [name]: reason }`,\n * final-form's submission errors: the field says it beside itself and stops\n * once its value changes, and every value stays as it was chosen.\n */\n onSubmit: (\n values: Record<string, any>,\n ) => SubmitRefusal | Promise<SubmitRefusal>\n /** Extra fields appended after name and description. */\n extraFields?: any[]\n /** Rendered under the form when a submit fails. */\n errorSlot?: ReactNode\n /**\n * Whether to offer the shared Description box (AGL-2498).\n *\n * True for every artifact whose document stores one. Content collections do\n * not: `/api/hosts/collections` filters `data` through a per-kind allowlist\n * of `displayName` + `slug`, so a description typed here would be dropped\n * without a word. A field the writer silently discards is worse than a field\n * that was never offered.\n */\n includeDescription?: boolean\n /**\n * The form's own chrome — the submit button and how the fields are laid out.\n *\n * Injectable because the console's version renders an auth-aware template\n * that lives in the app and depends on the console's session hook. Defaults\n * to {@link ArtifactFormTemplate}, which is the same layout without that\n * dependency.\n *\n * A template reads form state — `submitting`, `valid` — through a\n * `FormSpy`. The form does not draw its template again when that state\n * changes, so the `pristine` and `valid` on `useFormApi()` keep the values\n * they had when the drawer opened.\n */\n FormTemplate?: any\n /** Label on the submit button. */\n submitLabel?: string\n /**\n * Field components beyond the shared ones, by the `component` name an extra\n * field asks for. Merged over the drawer's own mapper, so a caller with one\n * field the library has no component for keeps the shared drawer.\n */\n componentMapper?: Record<string, ComponentType<any>>\n}\n\n/**\n * The default chrome: the fields in a grid and one submit button.\n *\n * No Cancel button of its own — the drawer's app bar already carries one, and\n * a second Cancel inside the form is the shape a reader has to think about.\n */\nexport const ArtifactFormTemplate = forwardRef<any, FormTemplateRenderProps>(\n (props, ref) => {\n const { formFields, schema, ...rest } = props\n const { handleSubmit } = useFormApi()\n return (\n <form ref={ref} onSubmit={handleSubmit} noValidate {...rest}>\n {schema.title}\n <Grid spacing={2} container>\n {formFields as any}\n </Grid>\n {/* `submitting` alone: it is all the button reads, and a spy with\n no subscription draws the button again on every keystroke. */}\n <FormSpy subscription={{ submitting: true }}>\n {({ submitting }) => (\n <Box sx={{ mt: 2 }}>\n <FormControl margin=\"normal\" fullWidth>\n <Button\n color=\"primary\"\n disabled={submitting}\n type=\"submit\"\n variant=\"contained\"\n fullWidth\n >\n {(schema as { submitLabel?: string }).submitLabel ?? 'Next'}\n </Button>\n </FormControl>\n </Box>\n )}\n </FormSpy>\n </form>\n )\n },\n)\nArtifactFormTemplate.displayName = 'ArtifactFormTemplate'\n;(ArtifactFormTemplate as any).aglyn = true\n\nexport function CreateArtifactDrawer(props: CreateArtifactDrawerProps) {\n const {\n open,\n onClose,\n title,\n onSubmit,\n extraFields,\n errorSlot,\n includeDescription = true,\n FormTemplate = ArtifactFormTemplate,\n submitLabel,\n componentMapper,\n } = props\n const [initialValues] = useState(() => new Map<string, unknown>())\n const schema = {\n fields: keepInitialValues(\n [\n ...(includeDescription\n ? BASE_FIELDS\n : BASE_FIELDS.filter((field) => field.name !== 'description')),\n ...(extraFields ?? []),\n ],\n initialValues,\n ),\n ...(submitLabel ? { submitLabel } : {}),\n }\n return (\n <NavigationDrawerComponent\n open={open}\n anchor=\"right\"\n variant=\"temporary\"\n onClose={onClose}\n AppBarProps={{ color: 'surface' }}\n appBarLeft={\n <>\n <IconButton\n color=\"inherit\"\n edge=\"start\"\n onClick={onClose}\n sx={{ mr: 2 }}\n >\n <MdiIcon path={ICON_VARIANT_CLOSE.path} />\n <SrOnly>close drawer</SrOnly>\n </IconButton>\n <Typography variant=\"h6\" component=\"div\">\n {title}\n </Typography>\n </>\n }\n appBarRight={\n <Button variant=\"outlined\" color=\"inherit\" onClick={onClose}>\n {'Cancel'}\n </Button>\n }\n >\n <Container gutterY>\n {/*\n The form subscribes to nothing, so a keystroke draws the field it\n lands in and no other (AGL-3423). Each field reads its own state, a\n condition watches the fields it names, and the template's button\n watches `submitting` through its own FormSpy: nothing here is drawn\n from the form's state as a whole. The renderer's own defaults —\n pristine, submitting, valid — are switched off too: a change in any\n of them draws every field again, and the first letter of a required\n name changes two of them.\n */}\n <FormRenderer\n FormTemplate={FormTemplate}\n componentMapper={\n componentMapper\n ? { ...simpleComponentMapper, ...componentMapper }\n : simpleComponentMapper\n }\n onSubmit={onSubmit}\n schema={schema}\n subscription={{ pristine: false, submitting: false, valid: false }}\n clearOnUnmount\n />\n {errorSlot}\n </Container>\n </NavigationDrawerComponent>\n )\n}\n\n/**\n * Each field's `initialValue`, kept as the same object for as long as it is\n * equal to the one before (AGL-4047).\n *\n * Callers build their fields on every draw, so an object or array initial\n * value is a new one each time the page around the drawer draws. The form\n * library takes a new initial value as a new field: it lets the old one go\n * and registers it again from that value, so a page drawing again, as it does\n * to say why a create was refused, put the field back where it started — \"All\n * sites\" with the ticked sites dropped, a second press creating what nobody\n * chose. Keeping the reference keeps the field, and with it what was chosen.\n * A value that really changes still comes through.\n */\nfunction keepInitialValues(fields: readonly any[], kept: Map<string, unknown>): any[] {\n return fields.map((field) => {\n if (!field || typeof field !== 'object') return field\n let next = field\n if (typeof field.name === 'string' && 'initialValue' in field) {\n const before = kept.get(field.name)\n if (before !== field.initialValue && kept.has(field.name) && isEqual(before, field.initialValue)) {\n next = { ...field, initialValue: before }\n } else {\n kept.set(field.name, field.initialValue)\n }\n }\n // A sub-form's own fields are registered the same way.\n return Array.isArray(next.fields) ? { ...next, fields: keepInitialValues(next.fields, kept) } : next\n })\n}\n\n/**\n * Same shape and limits the layouts drawer has used since AGL-473, so the\n * creates across the console validate identically.\n */\nexport const BASE_FIELDS = [\n {\n component: 'text-field',\n name: 'displayName',\n helperText: 'Friendly name for internal reference',\n type: 'text',\n label: 'Display name',\n isRequired: true,\n validate: [\n { type: 'required', message: 'Provide a display name' },\n {\n type: 'max-length',\n threshold: 25,\n message: 'Must not exceed 25 characters',\n },\n ],\n },\n {\n component: 'textarea',\n name: 'description',\n label: 'Description',\n helperText: 'Brief description for internal reference',\n validate: [\n {\n type: 'max-length',\n threshold: 80,\n message: 'Must not exceed 80 characters',\n },\n ],\n },\n]\n\nCreateArtifactDrawer.displayName = 'CreateArtifactDrawer'\n\nexport default CreateArtifactDrawer\n"],"names":["ICON_VARIANT_CLOSE","Container","MdiIcon","SrOnly","NavigationDrawerComponent","Box","Button","FormControl","Grid","IconButton","Typography","isEqual","forwardRef","useState","FormRenderer","FormSpy","useFormApi","simpleComponentMapper","ArtifactFormTemplate","props","ref","formFields","schema","rest","handleSubmit","form","onSubmit","noValidate","title","spacing","container","subscription","submitting","sx","mt","margin","fullWidth","color","disabled","type","variant","submitLabel","displayName","aglyn","CreateArtifactDrawer","open","onClose","extraFields","errorSlot","includeDescription","FormTemplate","componentMapper","initialValues","Map","fields","keepInitialValues","BASE_FIELDS","filter","field","name","anchor","AppBarProps","appBarLeft","edge","onClick","mr","path","component","appBarRight","gutterY","pristine","valid","clearOnUnmount","kept","map","next","before","get","initialValue","has","set","Array","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