@cratis/components 4.41.3 → 4.41.5

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.
@@ -68,7 +68,7 @@
68
68
  {
69
69
  "name": "@cratis/components",
70
70
  "role": "core",
71
- "version": "4.41.3",
71
+ "version": "4.41.5",
72
72
  "releaseMajorRange": ">=4 <5",
73
73
  "independentRelease": false,
74
74
  "private": false,
@@ -92,7 +92,7 @@
92
92
  {
93
93
  "name": "@cratis/eslint-plugin-components",
94
94
  "role": "eslint",
95
- "version": "4.41.3",
95
+ "version": "4.41.5",
96
96
  "releaseMajorRange": ">=4 <5",
97
97
  "independentRelease": false,
98
98
  "private": false,
@@ -105,7 +105,7 @@
105
105
  {
106
106
  "name": "@cratis/components.migrator",
107
107
  "role": "migrator",
108
- "version": "4.41.3",
108
+ "version": "4.41.5",
109
109
  "releaseMajorRange": ">=4 <5",
110
110
  "independentRelease": false,
111
111
  "private": false,
@@ -116,13 +116,13 @@
116
116
  {
117
117
  "name": "@cratis/components.conformance",
118
118
  "role": "conformance",
119
- "version": "4.41.3",
119
+ "version": "4.41.5",
120
120
  "releaseMajorRange": ">=4 <5",
121
121
  "independentRelease": false,
122
122
  "private": false,
123
123
  "packageAccess": "public",
124
124
  "peerDependencies": {
125
- "@cratis/components": "4.41.3",
125
+ "@cratis/components": "4.41.5",
126
126
  "react": "^19.0.0",
127
127
  "react-dom": "^19.0.0"
128
128
  },
@@ -132,13 +132,13 @@
132
132
  {
133
133
  "name": "@cratis/components.mui",
134
134
  "role": "renderer-adapter",
135
- "version": "4.41.3",
135
+ "version": "4.41.5",
136
136
  "releaseMajorRange": ">=4 <5",
137
137
  "independentRelease": false,
138
138
  "private": false,
139
139
  "packageAccess": "public",
140
140
  "peerDependencies": {
141
- "@cratis/components": "4.41.3",
141
+ "@cratis/components": "4.41.5",
142
142
  "@emotion/react": ">=11.5 <12",
143
143
  "@emotion/styled": ">=11.11 <12",
144
144
  "@mui/material": ">=9 <10",
@@ -188,13 +188,13 @@
188
188
  {
189
189
  "name": "@cratis/components.primereact",
190
190
  "role": "renderer-adapter",
191
- "version": "4.41.3",
191
+ "version": "4.41.5",
192
192
  "releaseMajorRange": ">=4 <5",
193
193
  "independentRelease": false,
194
194
  "private": false,
195
195
  "packageAccess": "public",
196
196
  "peerDependencies": {
197
- "@cratis/components": "4.41.3",
197
+ "@cratis/components": "4.41.5",
198
198
  "@primereact/core": ">=11 <12",
199
199
  "@primereact/ui": ">=11 <12",
200
200
  "@primeuix/themes": ">=3 <4",
@@ -256,13 +256,13 @@
256
256
  {
257
257
  "name": "@cratis/components.primereact10",
258
258
  "role": "renderer-adapter",
259
- "version": "4.41.3",
259
+ "version": "4.41.5",
260
260
  "releaseMajorRange": ">=4 <5",
261
261
  "independentRelease": false,
262
262
  "private": false,
263
263
  "packageAccess": "public",
264
264
  "peerDependencies": {
265
- "@cratis/components": "4.41.3",
265
+ "@cratis/components": "4.41.5",
266
266
  "primereact": ">=10.9.9 <11",
267
267
  "react": "^19.0.0",
268
268
  "react-dom": "^19.0.0"
@@ -1 +1 @@
1
- {"version":3,"file":"TagGroup.d.ts","sourceRoot":"","sources":["../../../Common/TagGroup.tsx"],"names":[],"mappings":"AAGA,OAAO,EAGH,KAAK,cAAc,EACnB,KAAK,mBAAmB,EAExB,KAAK,SAAS,EACjB,MAAM,OAAO,CAAC;AAYf,4GAA4G;AAC5G,MAAM,MAAM,sBAAsB,GAAG,IAAI,CACrC,cAAc,CAAC,WAAW,CAAC,EAC3B,WAAW,GAAG,OAAO,GAAG,OAAO,CAClC,GAAG;IACA,CAAC,aAAa,EAAE,QAAQ,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;CAC5E,CAAC;AAEF,gEAAgE;AAChE,MAAM,WAAW,aAAa;IAC1B,mDAAmD;IACnD,IAAI,CAAC,EAAE,sBAAsB,CAAC;IAC9B,oBAAoB;IACpB,IAAI,CAAC,EAAE,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C,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,yFAAyF;IACzF,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,6DAA6D;IAC7D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0FAA0F;IAC1F,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,4EAA4E;IAC5E,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IACxC;;;;OAIG;IACH,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wCAAwC;IACxC,EAAE,CAAC,EAAE,aAAa,CAAC;CACtB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,6OAiBlB,aAAa,gCAyFf,CAAC"}
@@ -4,12 +4,18 @@ import { TagGroup as TagGroup$1, TagList, Tag } from 'react-aria-components/TagG
4
4
  import { Button } from 'react-aria-components/Button';
5
5
  import { useCratisIcon } from '../configuration/useCratisIcon.js';
6
6
  import { classNames } from '../ClassNames/classNames.js';
7
+ import { useTagOccurrences } from './tagOccurrences.js';
7
8
 
8
9
  const TagGroup = ({ value, onChange, editable = true, placeholder, separators = [','], allowDuplicates = false, disabled = false, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, invalid = false, id, removeLabel, removeIcon, className, pt, }) => {
9
10
  const icon = useCratisIcon();
10
11
  const resolvedRemoveIcon = icon('remove', '×', removeIcon);
11
12
  const generatedId = useId();
12
13
  const inputId = id ?? `cratis-tag-group-${generatedId}`;
14
+ const { items, remove } = useTagOccurrences(value, onChange);
15
+ const entry = useTagGroupEntry({ value, onChange, separators, allowDuplicates }, () => remove(new Set([items[items.length - 1].id])));
16
+ return (jsxs("div", { ...pt?.root, className: classNames('cratis-tag-group', pt?.root?.className, className), "data-cratis-part": 'root', "data-cratis-component": 'TagGroup', "data-disabled": disabled || undefined, "data-invalid": invalid || undefined, children: [jsx(TagGroup$1, { className: 'cratis-tag-group__group', selectionMode: 'none', onRemove: remove, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, children: jsx(TagList, { ...pt?.list, items: items, dependencies: [disabled, removeLabel, resolvedRemoveIcon, pt], className: classNames('cratis-tag-group__list', pt?.list?.className), "data-cratis-part": 'list', children: (item) => (jsxs(Tag, { ...pt?.tag, id: item.id, textValue: item.label, isDisabled: disabled, className: classNames('cratis-tag-group__tag', pt?.tag?.className), "data-cratis-part": 'tag', "data-disabled": disabled || undefined, children: [jsx("span", { className: 'cratis-tag-group__tag-label', children: item.label }), !disabled && (jsx(Button, { ...pt?.remove, slot: 'remove', "aria-label": removeLabel?.(item.label), className: classNames('cratis-tag-group__remove', pt?.remove?.className), "data-cratis-part": 'remove', children: jsx("span", { "aria-hidden": 'true', children: resolvedRemoveIcon }) }))] })) }) }), editable && (jsx("input", { ...pt?.input, id: inputId, type: 'text', value: entry.draft, disabled: disabled, placeholder: placeholder, "aria-label": ariaLabelledBy ? undefined : ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-invalid": invalid || undefined, className: classNames('cratis-tag-group__input', pt?.input?.className), "data-cratis-part": 'input', "data-invalid": invalid || undefined, onChange: (event) => entry.setDraft(event.currentTarget.value), onKeyDown: entry.onKeyDown, onPaste: entry.onPaste, onBlur: entry.onBlur }))] }));
17
+ };
18
+ const useTagGroupEntry = ({ value, onChange, separators, allowDuplicates }, removeLast) => {
13
19
  const [draft, setDraft] = useState('');
14
20
  const add = (candidates) => {
15
21
  const next = [...value];
@@ -25,30 +31,27 @@ const TagGroup = ({ value, onChange, editable = true, placeholder, separators =
25
31
  onChange(next);
26
32
  setDraft('');
27
33
  };
28
- const remove = (keys) => onChange(value.filter((entry) => !keys.has(entry)));
29
- const splitOn = (text) => separators.length === 0
30
- ? [text]
31
- : text.split(new RegExp(`[${separators.map(escapeForClass).join('')}]`));
32
- return (jsxs("div", { ...pt?.root, className: classNames('cratis-tag-group', pt?.root?.className, className), "data-cratis-part": 'root', "data-cratis-component": 'TagGroup', "data-disabled": disabled || undefined, "data-invalid": invalid || undefined, children: [jsx(TagGroup$1, { className: 'cratis-tag-group__group', selectionMode: 'none', onRemove: remove, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, children: jsx(TagList, { ...pt?.list, items: value.map((entry) => ({ id: entry })), className: classNames('cratis-tag-group__list', pt?.list?.className), "data-cratis-part": 'list', children: (item) => (jsxs(Tag, { ...pt?.tag, id: item.id, textValue: item.id, isDisabled: disabled, className: classNames('cratis-tag-group__tag', pt?.tag?.className), "data-cratis-part": 'tag', "data-disabled": disabled || undefined, children: [jsx("span", { className: 'cratis-tag-group__tag-label', children: item.id }), !disabled && (jsx(Button, { ...pt?.remove, slot: 'remove', "aria-label": removeLabel?.(item.id), className: classNames('cratis-tag-group__remove', pt?.remove?.className), "data-cratis-part": 'remove', children: jsx("span", { "aria-hidden": 'true', children: resolvedRemoveIcon }) }))] })) }) }), editable && (jsx("input", { ...pt?.input, id: inputId, type: 'text', value: draft, disabled: disabled, placeholder: placeholder, "aria-label": ariaLabelledBy ? undefined : ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-invalid": invalid || undefined, className: classNames('cratis-tag-group__input', pt?.input?.className), "data-cratis-part": 'input', "data-invalid": invalid || undefined, onChange: (event) => setDraft(event.currentTarget.value), onKeyDown: (event) => {
33
- if (event.key === 'Enter' || separators.includes(event.key)) {
34
- event.preventDefault();
35
- add([draft]);
36
- }
37
- else if (event.key === 'Backspace' &&
38
- draft === '' &&
39
- value.length > 0) {
40
- onChange(value.slice(0, -1));
41
- }
42
- }, onPaste: (event) => {
43
- const text = event.clipboardData.getData('text');
44
- if (!separators.some((separator) => text.includes(separator)))
45
- return;
46
- event.preventDefault();
47
- add(splitOn(text));
48
- }, onBlur: () => {
49
- if (draft.trim())
50
- add([draft]);
51
- } }))] }));
34
+ const onKeyDown = (event) => {
35
+ if (event.key === 'Enter' || separators.includes(event.key)) {
36
+ event.preventDefault();
37
+ add([draft]);
38
+ }
39
+ else if (event.key === 'Backspace' && draft === '' && value.length > 0) {
40
+ removeLast();
41
+ }
42
+ };
43
+ const onPaste = (event) => {
44
+ const text = event.clipboardData.getData('text');
45
+ if (!separators.some((separator) => text.includes(separator)))
46
+ return;
47
+ event.preventDefault();
48
+ add(text.split(new RegExp(`[${separators.map(escapeForClass).join('')}]`)));
49
+ };
50
+ const onBlur = () => {
51
+ if (draft.trim())
52
+ add([draft]);
53
+ };
54
+ return { draft, setDraft, onKeyDown, onPaste, onBlur };
52
55
  };
53
56
  const escapeForClass = (separator) => separator.replace(/[\\\]^-]/gu, '\\$&');
54
57
 
@@ -1 +1 @@
1
- {"version":3,"file":"TagGroup.js","sources":["../../../Common/TagGroup.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 {\n useId,\n useState,\n type HTMLAttributes,\n type InputHTMLAttributes,\n type Key,\n type ReactNode,\n} from 'react';\nimport {\n Tag as AriaTag,\n TagGroup as AriaTagGroup,\n TagList as AriaTagList,\n} from 'react-aria-components/TagGroup';\nimport { Button as AriaButton } from 'react-aria-components/Button';\nimport { useCratisIcon } from '../configuration/useCratisIcon';\nimport type { ExactPartKeys } from '../types/ExactPartKeys';\nimport type { PartsOf } from '../types/parts';\nimport { classNames } from '../ClassNames/classNames';\n\n/** Attributes a consumer may hand to one {@link TagGroup} part: class, style, title and data attributes. */\nexport type TagGroupPartAttributes = Pick<\n HTMLAttributes<HTMLElement>,\n 'className' | 'style' | 'title'\n> & {\n [dataAttribute: `data-${string}`]: string | number | boolean | undefined;\n};\n\n/** Stable Cratis-owned parts for styling a {@link TagGroup}. */\nexport interface TagGroupParts {\n /** The element wrapping the tags and the entry. */\n root?: TagGroupPartAttributes;\n /** The tag list. */\n list?: TagGroupPartAttributes;\n /** One tag. */\n tag?: TagGroupPartAttributes;\n /** A tag's remove button. */\n remove?: TagGroupPartAttributes;\n /** The text entry that adds a value. */\n input?: InputHTMLAttributes<HTMLInputElement>;\n}\n\nconst tagGroupPartsMatchManifest: ExactPartKeys<TagGroupParts, PartsOf<'TagGroup'>> = true;\nvoid tagGroupPartsMatchManifest;\n\n/** Props for {@link TagGroup}. */\nexport interface TagGroupProps {\n /** Current values, in display order. */\n value: string[];\n /** Called with the next list whenever a value is added or removed. */\n onChange: (value: string[]) => void;\n /**\n * Whether a text entry is offered for adding values. A group without one is a read-only display\n * of removable tags.\n */\n editable?: boolean;\n /** Placeholder for the text entry. */\n placeholder?: string;\n /**\n * Characters that commit the typed value in addition to Enter. Defaults to a comma. A pasted\n * string is split on the same separators, so pasting a comma-separated list adds each value.\n */\n separators?: string[];\n /** Whether a duplicate of an existing value is accepted. Defaults to `false`. */\n allowDuplicates?: boolean;\n /** Whether the whole control is disabled. */\n disabled?: boolean;\n /** Accessible name for the group. */\n 'aria-label'?: string;\n /** Id of the element naming the group. */\n 'aria-labelledby'?: string;\n /** Id of the element describing the control — typically a field's error or hint text. */\n 'aria-describedby'?: string;\n /** Marks the text entry invalid for assistive technology. */\n invalid?: boolean;\n /** Id forwarded to the text entry so an external `<label htmlFor>` associates with it. */\n id?: string;\n /** Accessible label for a tag's remove button. Receives the tag's value. */\n removeLabel?: (value: string) => string;\n /**\n * Glyph inside a tag's remove button. Names this one tag group and wins over the provider's\n * `icons.remove`; defaults to a multiplication sign when neither is set. The button, its\n * accessible name and its keyboard behaviour are unaffected.\n */\n removeIcon?: ReactNode;\n /** Extra class name for the root element. */\n className?: string;\n /** Cratis-owned per-part attributes. */\n pt?: TagGroupParts;\n}\n\n/**\n * A group of removable values with an optional text entry — the control behind a tag or chips field.\n *\n * Every tag is reachable with the arrow keys and removable with Backspace or Delete, which is what\n * the `grid`/`row` semantics React Aria gives a tag group promise; a row of `<span>`s with a close\n * button cannot be operated from the keyboard at all. In the entry, Enter and each configured\n * separator commit the typed value, Backspace on an empty entry removes the last tag, and a pasted\n * string is split on the separators.\n */\nexport const TagGroup = ({\n value,\n onChange,\n editable = true,\n placeholder,\n separators = [','],\n allowDuplicates = false,\n disabled = false,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n invalid = false,\n id,\n removeLabel,\n removeIcon,\n className,\n pt,\n}: TagGroupProps) => {\n const icon = useCratisIcon();\n const resolvedRemoveIcon = icon('remove', '×', removeIcon);\n const generatedId = useId();\n const inputId = id ?? `cratis-tag-group-${generatedId}`;\n const [draft, setDraft] = useState('');\n\n const add = (candidates: string[]) => {\n const next = [...value];\n for (const candidate of candidates) {\n const trimmed = candidate.trim();\n if (!trimmed) continue;\n if (!allowDuplicates && next.includes(trimmed)) continue;\n next.push(trimmed);\n }\n if (next.length !== value.length) onChange(next);\n setDraft('');\n };\n\n const remove = (keys: Set<Key>) =>\n onChange(value.filter((entry) => !keys.has(entry)));\n\n const splitOn = (text: string) =>\n separators.length === 0\n ? [text]\n : text.split(new RegExp(`[${separators.map(escapeForClass).join('')}]`));\n\n return (\n <div\n {...pt?.root}\n className={classNames('cratis-tag-group', pt?.root?.className, className)}\n data-cratis-part='root'\n data-cratis-component='TagGroup'\n data-disabled={disabled || undefined}\n data-invalid={invalid || undefined}\n >\n <AriaTagGroup\n // React Aria renders a wrapper here. It generates a block box, which would trap the\n // tags in their own formatting context — the root's flex layout, and therefore the\n // gap between tags, would never reach them. It has no part on purpose: it is not a\n // styling surface, it just has to disappear from layout.\n className='cratis-tag-group__group'\n selectionMode='none'\n onRemove={remove}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n >\n <AriaTagList\n {...pt?.list}\n items={value.map((entry) => ({ id: entry }))}\n className={classNames('cratis-tag-group__list', pt?.list?.className)}\n data-cratis-part='list'\n >\n {(item: { id: string }) => (\n <AriaTag\n {...pt?.tag}\n id={item.id}\n textValue={item.id}\n isDisabled={disabled}\n className={classNames('cratis-tag-group__tag', pt?.tag?.className)}\n data-cratis-part='tag'\n data-disabled={disabled || undefined}\n >\n <span className='cratis-tag-group__tag-label'>{item.id}</span>\n {!disabled && (\n <AriaButton\n {...pt?.remove}\n slot='remove'\n aria-label={removeLabel?.(item.id)}\n className={classNames(\n 'cratis-tag-group__remove',\n pt?.remove?.className,\n )}\n data-cratis-part='remove'\n >\n <span aria-hidden='true'>{resolvedRemoveIcon}</span>\n </AriaButton>\n )}\n </AriaTag>\n )}\n </AriaTagList>\n </AriaTagGroup>\n {editable && (\n <input\n {...pt?.input}\n id={inputId}\n type='text'\n value={draft}\n disabled={disabled}\n placeholder={placeholder}\n aria-label={ariaLabelledBy ? undefined : ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-describedby={ariaDescribedBy}\n aria-invalid={invalid || undefined}\n className={classNames('cratis-tag-group__input', pt?.input?.className)}\n data-cratis-part='input'\n data-invalid={invalid || undefined}\n onChange={(event) => setDraft(event.currentTarget.value)}\n onKeyDown={(event) => {\n if (event.key === 'Enter' || separators.includes(event.key)) {\n event.preventDefault();\n add([draft]);\n } else if (\n event.key === 'Backspace' &&\n draft === '' &&\n value.length > 0\n ) {\n onChange(value.slice(0, -1));\n }\n }}\n onPaste={(event) => {\n const text = event.clipboardData.getData('text');\n if (!separators.some((separator) => text.includes(separator))) return;\n event.preventDefault();\n add(splitOn(text));\n }}\n onBlur={() => {\n if (draft.trim()) add([draft]);\n }}\n />\n )}\n </div>\n );\n};\n\n/** Escapes a separator for use inside a character class, so a `-` or `]` cannot reshape it. */\nconst escapeForClass = (separator: string) => separator.replace(/[\\\\\\]^-]/gu, '\\\\$&');\n"],"names":["_jsxs","_jsx","AriaTagGroup","AriaTagList","AriaTag","AriaButton"],"mappings":";;;;;;;AAsGO,MAAM,QAAQ,GAAG,CAAC,EACrB,KAAK,EACL,QAAQ,EACR,QAAQ,GAAG,IAAI,EACf,WAAW,EACX,UAAU,GAAG,CAAC,GAAG,CAAC,EAClB,eAAe,GAAG,KAAK,EACvB,QAA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,cAAc,EAAE;AACtB,wBAAA,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;oBAChB;AAAO,yBAAA,IACH,KAAK,CAAC,GAAG,KAAK,WAAW;AACzB,wBAAA,KAAK,KAAK,EAAE;AACZ,wBAAA,KAAK,CAAC,MAAM,GAAG,CAAC,EAClB;wBACE,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;oBAChC;AACJ,gBAAA,CAAC,EACD,OAAO,EAAE,CAAC,KAAK,KAAI;oBACf,MAAM,IAAI,GAAG,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC;AAChD,oBAAA,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,SAAS,KAAK,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;wBAAE;oBAC/D,KAAK,CAAC,cAAc,EAAE;AACtB,oBAAA,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACtB,gBAAA,CAAC,EACD,MAAM,EAAE,MAAK;oBACT,IAAI,KAAK,CAAC,IAAI,EAAE;AAAE,wBAAA,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;AAClC,gBAAA,CAAC,EAAA,CACH,CACL,CAAA,EAAA,CACC;AAEd;AAGA,MAAM,cAAc,GAAG,CAAC,SAAiB,KAAK,SAAS,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC;;"}
1
+ {"version":3,"file":"TagGroup.js","sources":["../../../Common/TagGroup.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 {\n useId,\n useState,\n type HTMLAttributes,\n type InputHTMLAttributes,\n type ReactNode,\n} from 'react';\nimport {\n Tag as AriaTag,\n TagGroup as AriaTagGroup,\n TagList as AriaTagList,\n} from 'react-aria-components/TagGroup';\nimport { Button as AriaButton } from 'react-aria-components/Button';\nimport { useCratisIcon } from '../configuration/useCratisIcon';\nimport type { ExactPartKeys } from '../types/ExactPartKeys';\nimport type { PartsOf } from '../types/parts';\nimport { classNames } from '../ClassNames/classNames';\nimport { useTagOccurrences } from './tagOccurrences';\n\n/** Attributes a consumer may hand to one {@link TagGroup} part: class, style, title and data attributes. */\nexport type TagGroupPartAttributes = Pick<\n HTMLAttributes<HTMLElement>,\n 'className' | 'style' | 'title'\n> & {\n [dataAttribute: `data-${string}`]: string | number | boolean | undefined;\n};\n\n/** Stable Cratis-owned parts for styling a {@link TagGroup}. */\nexport interface TagGroupParts {\n /** The element wrapping the tags and the entry. */\n root?: TagGroupPartAttributes;\n /** The tag list. */\n list?: TagGroupPartAttributes;\n /** One tag. */\n tag?: TagGroupPartAttributes;\n /** A tag's remove button. */\n remove?: TagGroupPartAttributes;\n /** The text entry that adds a value. */\n input?: InputHTMLAttributes<HTMLInputElement>;\n}\n\nconst tagGroupPartsMatchManifest: ExactPartKeys<TagGroupParts, PartsOf<'TagGroup'>> = true;\nvoid tagGroupPartsMatchManifest;\n\n/** Props for {@link TagGroup}. */\nexport interface TagGroupProps {\n /** Current values, in display order. */\n value: string[];\n /** Called with the next list whenever a value is added or removed. */\n onChange: (value: string[]) => void;\n /**\n * Whether a text entry is offered for adding values. A group without one is a read-only display\n * of removable tags.\n */\n editable?: boolean;\n /** Placeholder for the text entry. */\n placeholder?: string;\n /**\n * Characters that commit the typed value in addition to Enter. Defaults to a comma. A pasted\n * string is split on the same separators, so pasting a comma-separated list adds each value.\n */\n separators?: string[];\n /** Whether a duplicate of an existing value is accepted. Defaults to `false`. */\n allowDuplicates?: boolean;\n /** Whether the whole control is disabled. */\n disabled?: boolean;\n /** Accessible name for the group. */\n 'aria-label'?: string;\n /** Id of the element naming the group. */\n 'aria-labelledby'?: string;\n /** Id of the element describing the control — typically a field's error or hint text. */\n 'aria-describedby'?: string;\n /** Marks the text entry invalid for assistive technology. */\n invalid?: boolean;\n /** Id forwarded to the text entry so an external `<label htmlFor>` associates with it. */\n id?: string;\n /** Accessible label for a tag's remove button. Receives the tag's value. */\n removeLabel?: (value: string) => string;\n /**\n * Glyph inside a tag's remove button. Names this one tag group and wins over the provider's\n * `icons.remove`; defaults to a multiplication sign when neither is set. The button, its\n * accessible name and its keyboard behaviour are unaffected.\n */\n removeIcon?: ReactNode;\n /** Extra class name for the root element. */\n className?: string;\n /** Cratis-owned per-part attributes. */\n pt?: TagGroupParts;\n}\n\n/**\n * A group of removable values with an optional text entry — the control behind a tag or chips field.\n *\n * Every tag is reachable with the arrow keys and removable with Backspace or Delete, which is what\n * the `grid`/`row` semantics React Aria gives a tag group promise; a row of `<span>`s with a close\n * button cannot be operated from the keyboard at all. In the entry, Enter and each configured\n * separator commit the typed value, Backspace on an empty entry removes the last tag, and a pasted\n * string is split on the separators.\n */\nexport const TagGroup = ({\n value,\n onChange,\n editable = true,\n placeholder,\n separators = [','],\n allowDuplicates = false,\n disabled = false,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n invalid = false,\n id,\n removeLabel,\n removeIcon,\n className,\n pt,\n}: TagGroupProps) => {\n const icon = useCratisIcon();\n const resolvedRemoveIcon = icon('remove', '×', removeIcon);\n const generatedId = useId();\n const inputId = id ?? `cratis-tag-group-${generatedId}`;\n const { items, remove } = useTagOccurrences(value, onChange);\n const entry = useTagGroupEntry({ value, onChange, separators, allowDuplicates }, () =>\n remove(new Set([items[items.length - 1].id])));\n\n\n return (\n <div\n {...pt?.root}\n className={classNames('cratis-tag-group', pt?.root?.className, className)}\n data-cratis-part='root'\n data-cratis-component='TagGroup'\n data-disabled={disabled || undefined}\n data-invalid={invalid || undefined}\n >\n <AriaTagGroup\n // React Aria renders a wrapper here. It generates a block box, which would trap the\n // tags in their own formatting context — the root's flex layout, and therefore the\n // gap between tags, would never reach them. It has no part on purpose: it is not a\n // styling surface, it just has to disappear from layout.\n className='cratis-tag-group__group'\n selectionMode='none'\n onRemove={remove}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n >\n <AriaTagList\n {...pt?.list}\n items={items}\n dependencies={[disabled, removeLabel, resolvedRemoveIcon, pt]}\n className={classNames('cratis-tag-group__list', pt?.list?.className)}\n data-cratis-part='list'\n >\n {(item) => (\n <AriaTag\n {...pt?.tag}\n id={item.id}\n textValue={item.label}\n isDisabled={disabled}\n className={classNames('cratis-tag-group__tag', pt?.tag?.className)}\n data-cratis-part='tag'\n data-disabled={disabled || undefined}\n >\n <span className='cratis-tag-group__tag-label'>{item.label}</span>\n {!disabled && (\n <AriaButton\n {...pt?.remove}\n slot='remove'\n aria-label={removeLabel?.(item.label)}\n className={classNames(\n 'cratis-tag-group__remove',\n pt?.remove?.className,\n )}\n data-cratis-part='remove'\n >\n <span aria-hidden='true'>{resolvedRemoveIcon}</span>\n </AriaButton>\n )}\n </AriaTag>\n )}\n </AriaTagList>\n </AriaTagGroup>\n {editable && (\n <input\n {...pt?.input}\n id={inputId}\n type='text'\n value={entry.draft}\n disabled={disabled}\n placeholder={placeholder}\n aria-label={ariaLabelledBy ? undefined : ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-describedby={ariaDescribedBy}\n aria-invalid={invalid || undefined}\n className={classNames('cratis-tag-group__input', pt?.input?.className)}\n data-cratis-part='input'\n data-invalid={invalid || undefined}\n onChange={(event) => entry.setDraft(event.currentTarget.value)}\n onKeyDown={entry.onKeyDown}\n onPaste={entry.onPaste}\n onBlur={entry.onBlur}\n />\n )}\n </div>\n );\n};\n\nconst useTagGroupEntry = (\n { value, onChange, separators, allowDuplicates }: Required<Pick<TagGroupProps, 'value' | 'onChange' | 'separators' | 'allowDuplicates'>>,\n removeLast: () => void,\n) => {\n const [draft, setDraft] = useState('');\n const add = (candidates: string[]) => {\n const next = [...value];\n for (const candidate of candidates) {\n const trimmed = candidate.trim();\n if (!trimmed) continue;\n if (!allowDuplicates && next.includes(trimmed)) continue;\n next.push(trimmed);\n }\n if (next.length !== value.length) onChange(next);\n setDraft('');\n };\n const onKeyDown: InputHTMLAttributes<HTMLInputElement>['onKeyDown'] = (event) => {\n if (event.key === 'Enter' || separators.includes(event.key)) {\n event.preventDefault();\n add([draft]);\n } else if (event.key === 'Backspace' && draft === '' && value.length > 0) {\n removeLast();\n }\n };\n const onPaste: InputHTMLAttributes<HTMLInputElement>['onPaste'] = (event) => {\n const text = event.clipboardData.getData('text');\n if (!separators.some((separator) => text.includes(separator))) return;\n event.preventDefault();\n add(text.split(new RegExp(`[${separators.map(escapeForClass).join('')}]`)));\n };\n const onBlur = () => {\n if (draft.trim()) add([draft]);\n };\n return { draft, setDraft, onKeyDown, onPaste, onBlur };\n};\n\n/** Escapes a separator for use inside a character class, so a `-` or `]` cannot reshape it. */\nconst escapeForClass = (separator: string) => separator.replace(/[\\\\\\]^-]/gu, '\\\\$&');\n"],"names":["_jsxs","_jsx","AriaTagGroup","AriaTagList","AriaTag","AriaButton"],"mappings":";;;;;;;;AAsGO,MAAM,QAAQ,GAAG,CAAC,EACrB,KAAK,EACL,QAAQ,EACR,QAAQ,GAAG,IAAI,EACf,WAAW,EACX,UAAU,GAAG,CAAC,GAAG,CAAC,EAClB,eAAe,GAAG,KAAK,EACvB,QAAQ,GAAG,KAAK,EAChB,YAAY,EAAE,SAAS,EACvB,iBAAiB,EAAE,cAAc,EACjC,kBAAkB,EAAE,eAAe,EACnC,OAAO,GAAG,KAAK,EACf,EAAE,EACF,WAAW,EACX,UAAU,EACV,SAAS,EACT,EAAE,GACU,KAAI;AAChB,IAAA,MAAM,IAAI,GAAG,aAAa,EAAE;IAC5B,MAAM,kBAAkB,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,UAAU,CAAC;AAC1D,IAAA,MAAM,WAAW,GAAG,KAAK,EAAE;AAC3B,IAAA,MAAM,OAAO,GAAG,EAAE,IAAI,CAAA,iBAAA,EAAoB,WAAW,EAAE;AACvD,IAAA,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,iBAAiB,CAAC,KAAK,EAAE,QA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IAAI,GAAG,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC;AAChD,QAAA,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,SAAS,KAAK,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;YAAE;QAC/D,KAAK,CAAC,cAAc,EAAE;QACtB,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,CAAA,CAAA,EAAI,UAAU,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA,CAAA,CAAG,CAAC,CAAC,CAAC;AAC/E,IAAA,CAAC;IACD,MAAM,MAAM,GAAG,MAAK;QAChB,IAAI,KAAK,CAAC,IAAI,EAAE;AAAE,YAAA,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;AAClC,IAAA,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE;AAC1D,CAAC;AAGD,MAAM,cAAc,GAAG,CAAC,SAAiB,KAAK,SAAS,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC;;"}
@@ -0,0 +1,9 @@
1
+ import { type Key } from 'react';
2
+ export declare const useTagOccurrences: (value: string[], onChange: (value: string[]) => void) => {
3
+ items: {
4
+ id: string;
5
+ label: string;
6
+ }[];
7
+ remove: (keys: Set<Key>) => void;
8
+ };
9
+ //# sourceMappingURL=tagOccurrences.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tagOccurrences.d.ts","sourceRoot":"","sources":["../../../Common/tagOccurrences.ts"],"names":[],"mappings":"AAGA,OAAO,EAAmB,KAAK,GAAG,EAAE,MAAM,OAAO,CAAC;AAqBlD,eAAO,MAAM,iBAAiB,UAAW,MAAM,EAAE,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI;;;;;mBAY5D,GAAG,CAAC,GAAG,CAAC;CAOjC,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { useId, useState } from 'react';
2
+
3
+ const occurrence = (id, label) => ({ id, label });
4
+ const reconcile = (value, previous, prefix, nextId) => {
5
+ const available = new Map();
6
+ for (const item of previous) {
7
+ const queue = available.get(item.label) ?? { items: [], index: 0 };
8
+ queue.items.push(item);
9
+ available.set(item.label, queue);
10
+ }
11
+ const items = value.map((label) => {
12
+ const queue = available.get(label);
13
+ return queue?.items[queue.index++] ?? occurrence(`${prefix}-${nextId++}`, label);
14
+ });
15
+ return { value, items, nextId, pending: items };
16
+ };
17
+ const matches = (items, value) => items.length === value.length && items.every((item, index) => item.label === value[index]);
18
+ const useTagOccurrences = (value, onChange) => {
19
+ const prefix = useId();
20
+ const [stored, setStored] = useState(() => reconcile(value, [], prefix, 0));
21
+ let current = stored;
22
+ if (stored.value !== value || !matches(stored.items, value)) {
23
+ const previous = matches(stored.pending, value) ? stored.pending : stored.items;
24
+ current = reconcile(value, previous, prefix, stored.nextId);
25
+ setStored(current);
26
+ }
27
+ const remove = (keys) => {
28
+ const pending = current.items.filter((item) => !keys.has(item.id));
29
+ setStored({ ...current, pending });
30
+ onChange(pending.map((item) => item.label));
31
+ };
32
+ return { items: current.items, remove };
33
+ };
34
+
35
+ export { useTagOccurrences };
36
+ //# sourceMappingURL=tagOccurrences.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tagOccurrences.js","sources":["../../../Common/tagOccurrences.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 { useId, useState, type Key } from 'react';\n\nconst occurrence = (id: string, label: string) => ({ id, label });\n\nconst reconcile = (value: string[], previous: ReturnType<typeof occurrence>[], prefix: string, nextId: number) => {\n const available = new Map<string, { items: typeof previous; index: number }>();\n for (const item of previous) {\n const queue = available.get(item.label) ?? { items: [], index: 0 };\n queue.items.push(item);\n available.set(item.label, queue);\n }\n const items = value.map((label) => {\n const queue = available.get(label);\n return queue?.items[queue.index++] ?? occurrence(`${prefix}-${nextId++}`, label);\n });\n return { value, items, nextId, pending: items };\n};\n\nconst matches = (items: ReturnType<typeof occurrence>[], value: string[]) =>\n items.length === value.length && items.every((item, index) => item.label === value[index]);\n\nexport const useTagOccurrences = (value: string[], onChange: (value: string[]) => void) => {\n const prefix = useId();\n const [stored, setStored] = useState(() => reconcile(value, [], prefix, 0));\n let current = stored;\n if (stored.value !== value || !matches(stored.items, value)) {\n // Only an acknowledged local removal can disambiguate equal labels. Other replacements\n // match the nth new occurrence to the nth prior occurrence of the same label.\n const previous = matches(stored.pending, value) ? stored.pending : stored.items;\n current = reconcile(value, previous, prefix, stored.nextId);\n setStored(current);\n }\n\n const remove = (keys: Set<Key>) => {\n const pending = current.items.filter((item) => !keys.has(item.id));\n setStored({ ...current, pending });\n onChange(pending.map((item) => item.label));\n };\n\n return { items: current.items, remove };\n};\n"],"names":[],"mappings":";;AAKA,MAAM,UAAU,GAAG,CAAC,EAAU,EAAE,KAAa,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;AAEjE,MAAM,SAAS,GAAG,CAAC,KAAe,EAAE,QAAyC,EAAE,MAAc,EAAE,MAAc,KAAI;AAC7G,IAAA,MAAM,SAAS,GAAG,IAAI,GAAG,EAAqD;AAC9E,IAAA,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE;QACzB,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE;AAClE,QAAA,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;QACtB,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC;IACpC;IACA,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,KAAI;QAC9B,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC;QAClC,OAAO,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K,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAClE,SAAS,CAAC,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC;AAClC,QAAA,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC;AAC/C,IAAA,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE;AAC3C;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"PresentationPropertyEditor.d.ts","sourceRoot":"","sources":["../../../ComponentPicker/PresentationPropertyEditor.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iDAA8C,CAAC;AAEvF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAmB,CAAC;AAIzD,oDAAoD;AACpD,MAAM,WAAW,+BAA+B;IAC5C,qEAAqE;IACrE,MAAM,EAAE,eAAe,CAAC;IACxB,mHAAmH;IACnH,QAAQ,EAAE,CAAC,OAAO,EAAE,kBAAkB,EAAE,KAAK,IAAI,CAAC;IAClD;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAmED;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,6CAAsD,+BAA+B,gCA+C3H,CAAC"}
1
+ {"version":3,"file":"PresentationPropertyEditor.d.ts","sourceRoot":"","sources":["../../../ComponentPicker/PresentationPropertyEditor.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iDAA8C,CAAC;AAEvF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAmB,CAAC;AAIzD,oDAAoD;AACpD,MAAM,WAAW,+BAA+B;IAC5C,qEAAqE;IACrE,MAAM,EAAE,eAAe,CAAC;IACxB,mHAAmH;IACnH,QAAQ,EAAE,CAAC,OAAO,EAAE,kBAAkB,EAAE,KAAK,IAAI,CAAC;IAClD;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAoED;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,6CAAsD,+BAA+B,gCAmD3H,CAAC"}
@@ -4,6 +4,7 @@ import { previewPresentationChanges } from '../configuration/identity/componentI
4
4
  import { proposedChanges } from './proposedChanges.js';
5
5
 
6
6
  const unsetValue = '';
7
+ const emptyDraft = Object.freeze({});
7
8
  const field = (property, id, value, set) => {
8
9
  const common = { id, disabled: !property.editable, 'data-cratis-part': 'input' };
9
10
  switch (property.type) {
@@ -22,12 +23,13 @@ const field = (property, id, value, set) => {
22
23
  };
23
24
  const PresentationPropertyEditor = ({ picked, onChange, preview = false, className }) => {
24
25
  const prefix = useId();
25
- const [draft, setDraft] = useState({});
26
- const changes = useMemo(() => proposedChanges(picked, draft), [picked, draft]);
26
+ const [draft, setDraft] = useState({ picked, values: emptyDraft });
27
+ const values = draft.picked === picked ? draft.values : emptyDraft;
28
+ const changes = useMemo(() => proposedChanges(picked, values), [picked, values]);
27
29
  const reportChange = useRef(onChange);
28
30
  reportChange.current = onChange;
29
31
  useEffect(() => {
30
- setDraft({});
32
+ setDraft({ picked, values: emptyDraft });
31
33
  }, [picked]);
32
34
  useEffect(() => {
33
35
  reportChange.current(changes);
@@ -42,8 +44,11 @@ const PresentationPropertyEditor = ({ picked, onChange, preview = false, classNa
42
44
  }
43
45
  return (jsx("div", { "data-cratis-part": 'root', "data-cratis-component": 'PresentationPropertyEditor', className: className, children: picked.presentationProperties.map((property) => {
44
46
  const id = `${prefix}-${property.name}`;
45
- const value = property.name in draft ? draft[property.name] : property.value;
46
- return (jsxs("div", { "data-cratis-part": 'property', children: [jsx("label", { htmlFor: id, "data-cratis-part": 'label', children: property.label }), field(property, id, value, (next) => setDraft((current) => ({ ...current, [property.name]: next }))), property.description && jsx("small", { "data-cratis-part": 'description', children: property.description })] }, property.name));
47
+ const value = property.name in values ? values[property.name] : property.value;
48
+ return (jsxs("div", { "data-cratis-part": 'property', children: [jsx("label", { htmlFor: id, "data-cratis-part": 'label', children: property.label }), field(property, id, value, (next) => setDraft((current) => ({
49
+ picked,
50
+ values: { ...(current.picked === picked ? current.values : emptyDraft), [property.name]: next },
51
+ }))), property.description && jsx("small", { "data-cratis-part": 'description', children: property.description })] }, property.name));
47
52
  }) }));
48
53
  };
49
54
 
@@ -1 +1 @@
1
- {"version":3,"file":"PresentationPropertyEditor.js","sources":["../../../ComponentPicker/PresentationPropertyEditor.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 { useEffect, useId, useMemo, useRef, useState } from 'react';\nimport { previewPresentationChanges } from '../configuration/identity/componentInstances';\nimport type { PresentationChange } from '../configuration/identity/PresentationChange';\nimport type { PresentationPropertyValue } from '../configuration/identity/PresentationPropertyValue';\nimport type { PickedComponent } from './PickedComponent';\nimport type { PickedPresentationProperty } from './PickedPresentationProperty';\nimport { proposedChanges } from './proposedChanges';\n\n/** Props for {@link PresentationPropertyEditor}. */\nexport interface PresentationPropertyEditorProps {\n /** The picked component whose presentation properties are edited. */\n picked: PickedComponent;\n /** Called every time the proposed changes change, including with `[]` when nothing differs. Nothing is applied. */\n onChange: (changes: PresentationChange[]) => void;\n /**\n * Applies the proposed changes to the rendered component while editing, through the same\n * registry the picker reads. The component returns to how it was when the editor unmounts,\n * when this turns off, and when a change is edited back to its original value.\n */\n preview?: boolean;\n /** Extra class name for the editor root. */\n className?: string;\n}\n\nconst unsetValue = '';\n\nconst field = (\n property: PickedPresentationProperty,\n id: string,\n value: PresentationPropertyValue,\n set: (next: PresentationPropertyValue) => void,\n) => {\n const common = { id, disabled: !property.editable, 'data-cratis-part': 'input' } as const;\n switch (property.type) {\n case 'boolean':\n return (\n <input\n {...common}\n type='checkbox'\n checked={value === true}\n onChange={(event) => set(event.currentTarget.checked)}\n />\n );\n case 'number':\n return (\n <input\n {...common}\n className='cratis-text-input'\n type='number'\n value={typeof value === 'number' ? value : ''}\n onChange={(event) =>\n set(event.currentTarget.value === '' ? undefined : Number(event.currentTarget.value))\n }\n />\n );\n case 'enum':\n return (\n <select\n {...common}\n className='cratis-text-input'\n value={value === undefined ? unsetValue : String(value)}\n onChange={(event) => {\n const chosen = event.currentTarget.value;\n set(chosen === unsetValue ? undefined : property.values?.find((v) => String(v) === chosen));\n }}\n >\n <option value={unsetValue}>\n {property.defaultValue === undefined ? '(not set)' : `(default: ${String(property.defaultValue)})`}\n </option>\n {property.values?.map((option) => (\n <option key={String(option)} value={String(option)}>\n {String(option)}\n </option>\n ))}\n </select>\n );\n default:\n return (\n <input\n {...common}\n className='cratis-text-input'\n type='text'\n value={typeof value === 'string' ? value : ''}\n onChange={(event) => set(event.currentTarget.value)}\n />\n );\n }\n};\n\n/**\n * A form for the presentation properties of a {@link PickedComponent}: a text, toggle, select or\n * number input per property, built from the component's descriptor. It reports the proposed changes\n * as `{ property, from, to }` and never applies them to the app, except for the optional live\n * `preview`.\n */\nexport const PresentationPropertyEditor = ({ picked, onChange, preview = false, className }: PresentationPropertyEditorProps) => {\n const prefix = useId();\n const [draft, setDraft] = useState<Record<string, PresentationPropertyValue>>({});\n const changes = useMemo(() => proposedChanges(picked, draft), [picked, draft]);\n const reportChange = useRef(onChange);\n reportChange.current = onChange;\n\n useEffect(() => {\n setDraft({});\n }, [picked]);\n\n useEffect(() => {\n reportChange.current(changes);\n }, [changes]);\n\n useEffect(() => {\n if (!preview || changes.length === 0) return;\n return previewPresentationChanges(picked.element, changes);\n }, [preview, changes, picked.element]);\n\n if (picked.presentationProperties.length === 0) {\n return (\n <p data-cratis-part='empty' className={className}>\n {picked.component} has no properties that can be changed here.\n </p>\n );\n }\n\n return (\n <div data-cratis-part='root' data-cratis-component='PresentationPropertyEditor' className={className}>\n {picked.presentationProperties.map((property) => {\n const id = `${prefix}-${property.name}`;\n const value = property.name in draft ? draft[property.name] : property.value;\n return (\n <div key={property.name} data-cratis-part='property'>\n <label htmlFor={id} data-cratis-part='label'>\n {property.label}\n </label>\n {field(property, id, value, (next) =>\n setDraft((current) => ({ ...current, [property.name]: next })),\n )}\n {property.description && <small data-cratis-part='description'>{property.description}</small>}\n </div>\n );\n })}\n </div>\n );\n};\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;AA2BA,MAAM,UAAU,GAAG,EAAE;AAErB,MAAM,KAAK,GAAG,CACV,QAAoC,EACpC,EAAU,EACV,KAAgC,EAChC,GAA8C,KAC9C;AACA,IAAA,MAAM,MAAM,GAAG,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,EAAE,OAAO,EAAW;AACzF,IAAA,QAAQ,QAAQ,CAAC,IAAI;AACjB,QAAA,KAAK,SAAS;AACV,YAAA,QACIA,GAAA,CAAA,OAAA,EAAA,EAAA,GACQ,MAAM,EACV,IAAI,EAAC,UAAU,EACf,OAAO,EAAE,KAAK,KAAK,IAAI,EACvB,QAAQ,EAAE,CAAC,KAAK,KAAK,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,EAAA,CACvD;AAEV,QAAA,KAAK,QAAQ;AACT,YAAA,QACIA,GAAA,CAAA,OAAA,EAAA,EAAA,GACQ,MAAM,EACV,SAAS,EAAC,mBAAmB,EAC7B,IAAI,EAAC,QAAQ,EACb,KAAK,EAAE,OAAO,KAAK,KAAK,QAAQ,GAAG,KAAK,GAAG,EAAE,EAC7C,QAAQ,EAAE,CAAC,KAAK,KACZ,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,KAAK,EAAE,GAAG,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,EAAA,CAE3F;AAEV,QAAA,KAAK,MAAM;AACP,YAAA,QACIC,IAAA,CAAA,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AAQ,KAAI;YAC5C,MAAM,EAAE,GAAG,CAAA,EAAG,MAAM,IAAI,QAAQ,CAAC,IAAI,CAAA,CAAE;YACvC,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,IAAI,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,KAAK;AAC5E,YAAA,QACIC,IAAA,CAAA,KAAA,EAAA,EAAA,kBAAA,EAA0C,UAAU,EAAA,QAAA,EAAA,CAChDD,eAAO,OAAO,EAAE,EAAE,EAAA,kBAAA,EAAmB,OAAO,EAAA,QAAA,EACvC,QAAQ,CAAC,KAAK,EAAA,CACX,EACP,KAAK,CAAC,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,IAAI,KAC7B,QAAQ,CAAC,CAAC,OAAO,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,EAAE,CAAC,CAAC,CACjE,EACA,QAAQ,CAAC,WAAW,IAAIA,GAAA,CAAA,OAAA,EAAA,EAAA,kBAAA,EAAwB,aAAa,YAAE,QAAQ,CAAC,WAAW,EAAA,CAAS,KAPvF,QAAQ,CAAC,IAAI,CAQjB;QAEd,CAAC,CAAC,EAAA,CACA;AAEd;;"}
1
+ {"version":3,"file":"PresentationPropertyEditor.js","sources":["../../../ComponentPicker/PresentationPropertyEditor.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 { useEffect, useId, useMemo, useRef, useState } from 'react';\nimport { previewPresentationChanges } from '../configuration/identity/componentInstances';\nimport type { PresentationChange } from '../configuration/identity/PresentationChange';\nimport type { PresentationPropertyValue } from '../configuration/identity/PresentationPropertyValue';\nimport type { PickedComponent } from './PickedComponent';\nimport type { PickedPresentationProperty } from './PickedPresentationProperty';\nimport { proposedChanges } from './proposedChanges';\n\n/** Props for {@link PresentationPropertyEditor}. */\nexport interface PresentationPropertyEditorProps {\n /** The picked component whose presentation properties are edited. */\n picked: PickedComponent;\n /** Called every time the proposed changes change, including with `[]` when nothing differs. Nothing is applied. */\n onChange: (changes: PresentationChange[]) => void;\n /**\n * Applies the proposed changes to the rendered component while editing, through the same\n * registry the picker reads. The component returns to how it was when the editor unmounts,\n * when this turns off, and when a change is edited back to its original value.\n */\n preview?: boolean;\n /** Extra class name for the editor root. */\n className?: string;\n}\n\nconst unsetValue = '';\nconst emptyDraft: Readonly<Record<string, PresentationPropertyValue>> = Object.freeze({});\n\nconst field = (\n property: PickedPresentationProperty,\n id: string,\n value: PresentationPropertyValue,\n set: (next: PresentationPropertyValue) => void,\n) => {\n const common = { id, disabled: !property.editable, 'data-cratis-part': 'input' } as const;\n switch (property.type) {\n case 'boolean':\n return (\n <input\n {...common}\n type='checkbox'\n checked={value === true}\n onChange={(event) => set(event.currentTarget.checked)}\n />\n );\n case 'number':\n return (\n <input\n {...common}\n className='cratis-text-input'\n type='number'\n value={typeof value === 'number' ? value : ''}\n onChange={(event) =>\n set(event.currentTarget.value === '' ? undefined : Number(event.currentTarget.value))\n }\n />\n );\n case 'enum':\n return (\n <select\n {...common}\n className='cratis-text-input'\n value={value === undefined ? unsetValue : String(value)}\n onChange={(event) => {\n const chosen = event.currentTarget.value;\n set(chosen === unsetValue ? undefined : property.values?.find((v) => String(v) === chosen));\n }}\n >\n <option value={unsetValue}>\n {property.defaultValue === undefined ? '(not set)' : `(default: ${String(property.defaultValue)})`}\n </option>\n {property.values?.map((option) => (\n <option key={String(option)} value={String(option)}>\n {String(option)}\n </option>\n ))}\n </select>\n );\n default:\n return (\n <input\n {...common}\n className='cratis-text-input'\n type='text'\n value={typeof value === 'string' ? value : ''}\n onChange={(event) => set(event.currentTarget.value)}\n />\n );\n }\n};\n\n/**\n * A form for the presentation properties of a {@link PickedComponent}: a text, toggle, select or\n * number input per property, built from the component's descriptor. It reports the proposed changes\n * as `{ property, from, to }` and never applies them to the app, except for the optional live\n * `preview`.\n */\nexport const PresentationPropertyEditor = ({ picked, onChange, preview = false, className }: PresentationPropertyEditorProps) => {\n const prefix = useId();\n const [draft, setDraft] = useState({ picked, values: emptyDraft });\n const values = draft.picked === picked ? draft.values : emptyDraft;\n const changes = useMemo(() => proposedChanges(picked, values), [picked, values]);\n const reportChange = useRef(onChange);\n reportChange.current = onChange;\n\n useEffect(() => {\n setDraft({ picked, values: emptyDraft });\n }, [picked]);\n\n useEffect(() => {\n reportChange.current(changes);\n }, [changes]);\n\n useEffect(() => {\n if (!preview || changes.length === 0) return;\n return previewPresentationChanges(picked.element, changes);\n }, [preview, changes, picked.element]);\n\n if (picked.presentationProperties.length === 0) {\n return (\n <p data-cratis-part='empty' className={className}>\n {picked.component} has no properties that can be changed here.\n </p>\n );\n }\n\n return (\n <div data-cratis-part='root' data-cratis-component='PresentationPropertyEditor' className={className}>\n {picked.presentationProperties.map((property) => {\n const id = `${prefix}-${property.name}`;\n const value = property.name in values ? values[property.name] : property.value;\n return (\n <div key={property.name} data-cratis-part='property'>\n <label htmlFor={id} data-cratis-part='label'>\n {property.label}\n </label>\n {field(property, id, value, (next) =>\n setDraft((current) => ({\n picked,\n values: { ...(current.picked === picked ? current.values : emptyDraft), [property.name]: next },\n })),\n )}\n {property.description && <small data-cratis-part='description'>{property.description}</small>}\n </div>\n );\n })}\n </div>\n );\n};\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;AA2BA,MAAM,UAAU,GAAG,EAAE;AACrB,MAAM,UAAU,GAAwD,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;AAEzF,MAAM,KAAK,GAAG,CACV,QAAoC,EACpC,EAAU,EACV,KAAgC,EAChC,GAA8C,KAC9C;AACA,IAAA,MAAM,MAAM,GAAG,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,EAAE,OAAO,EAAW;AACzF,IAAA,QAAQ,QAAQ,CAAC,IAAI;AACjB,QAAA,KAAK,SAAS;AACV,YAAA,QACIA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KAAK,CAAC,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,IAAI,KAC7B,QAAQ,CAAC,CAAC,OAAO,MAAM;wBACnB,MAAM;AACN,wBAAA,MAAM,EAAE,EAAE,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,UAAU,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,EAAE;qBAClG,CAAC,CAAC,CACN,EACA,QAAQ,CAAC,WAAW,IAAIA,mCAAwB,aAAa,EAAA,QAAA,EAAE,QAAQ,CAAC,WAAW,GAAS,CAAA,EAAA,EAVvF,QAAQ,CAAC,IAAI,CAWjB;QAEd,CAAC,CAAC,EAAA,CACA;AAEd;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/components",
3
- "version": "4.41.3",
3
+ "version": "4.41.5",
4
4
  "description": "React components for CQRS and event-sourced apps — command dialogs, typed forms, and query-backed data tables for Cratis Arc",
5
5
  "keywords": [
6
6
  "react",