@mittwald/flow-react-components 1.6.0-next.20 → 1.6.0-next.22

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.
Files changed (38) hide show
  1. package/dist/assets/component-index.json +1 -1
  2. package/dist/assets/doc-properties.json +1 -1
  3. package/dist/js/default.mjs +1 -1
  4. package/dist/js/packages/components/src/components/CodeEditor/CodeEditor.mjs +41 -12
  5. package/dist/js/packages/components/src/components/CodeEditor/CodeEditor.mjs.map +1 -1
  6. package/dist/js/packages/components/src/components/CodeEditor/hooks/useCodeEditorExtensions.mjs +29 -16
  7. package/dist/js/packages/components/src/components/CodeEditor/hooks/useCodeEditorExtensions.mjs.map +1 -1
  8. package/dist/js/packages/components/src/components/List/components/Items/Items.mjs +3 -0
  9. package/dist/js/packages/components/src/components/List/components/Items/Items.mjs.map +1 -1
  10. package/dist/js/packages/components/src/components/List/components/Items/components/Item/Item.mjs +1 -1
  11. package/dist/js/packages/components/src/components/List/components/Items/components/Item/Item.mjs.map +1 -1
  12. package/dist/js/packages/components/src/components/List/components/Items/components/Item/hooks/useGridItemProps.mjs +1 -2
  13. package/dist/js/packages/components/src/components/List/components/Items/components/Item/hooks/useGridItemProps.mjs.map +1 -1
  14. package/dist/js/packages/components/src/components/List/components/Table/Table.mjs +8 -12
  15. package/dist/js/packages/components/src/components/List/components/Table/Table.mjs.map +1 -1
  16. package/dist/js/packages/components/src/components/List/components/Table/components/Row.mjs +31 -0
  17. package/dist/js/packages/components/src/components/List/components/Table/components/Row.mjs.map +1 -0
  18. package/dist/js/packages/components/src/components/List/hooks/useLatestOnAction.mjs +21 -0
  19. package/dist/js/packages/components/src/components/List/hooks/useLatestOnAction.mjs.map +1 -0
  20. package/dist/js/packages/components/src/components/List/model/List.mjs +1 -0
  21. package/dist/js/packages/components/src/components/List/model/List.mjs.map +1 -1
  22. package/dist/js/packages/components/src/components/List/model/item/ItemView.mjs +20 -7
  23. package/dist/js/packages/components/src/components/List/model/item/ItemView.mjs.map +1 -1
  24. package/dist/js/packages/components/src/components/List/model/table/TableCell.mjs +1 -1
  25. package/dist/js/packages/components/src/components/List/model/table/TableCell.mjs.map +1 -1
  26. package/dist/js/packages/components/src/components/List/model/table/TableRow.mjs +28 -1
  27. package/dist/js/packages/components/src/components/List/model/table/TableRow.mjs.map +1 -1
  28. package/dist/js/packages/components/src/components/Markdown/Markdown.mjs +9 -5
  29. package/dist/js/packages/components/src/components/Markdown/Markdown.mjs.map +1 -1
  30. package/dist/types/components/List/components/Items/components/Item/Item.d.ts +2 -0
  31. package/dist/types/components/List/components/Items/components/Item/hooks/useGridItemProps.d.ts +1 -0
  32. package/dist/types/components/List/components/Table/components/Row.d.ts +13 -0
  33. package/dist/types/components/List/hooks/useLatestOnAction.d.ts +7 -0
  34. package/dist/types/components/List/model/item/ItemView.d.ts +34 -11
  35. package/dist/types/components/List/model/table/TableRow.d.ts +14 -0
  36. package/dist/types/components/List/model/table/types.d.ts +17 -1
  37. package/dist/types/components/List/typedList.d.ts +1 -0
  38. package/package.json +10 -10
@@ -299,8 +299,8 @@ import { Skeleton } from "./packages/components/src/components/Skeleton/Skeleton
299
299
  import { Table } from "./packages/components/src/components/Table/Table.mjs";
300
300
  import { TableHeader } from "./packages/components/src/components/Table/components/TableHeader/TableHeader.mjs";
301
301
  import { TableBody } from "./packages/components/src/components/Table/components/TableBody/TableBody.mjs";
302
- import { TableRow } from "./packages/components/src/components/Table/components/TableRow/TableRow.mjs";
303
302
  import { TableColumn } from "./packages/components/src/components/Table/components/TableColumn/TableColumn.mjs";
303
+ import { TableRow } from "./packages/components/src/components/Table/components/TableRow/TableRow.mjs";
304
304
  import { TableCell } from "./packages/components/src/components/Table/components/TableCell/TableCell.mjs";
305
305
  import { SettingsProvider } from "./packages/components/src/components/SettingsProvider/SettingsProvider.mjs";
306
306
  import { ListFilter, TypedListFilter } from "./packages/components/src/components/List/setupComponents/ListFilter.mjs";
@@ -12,7 +12,7 @@ import { defaultLightTheme } from "./themes/defaultEditorTheme.mjs";
12
12
  import { useCodeEditorExtensions } from "./hooks/useCodeEditorExtensions.mjs";
13
13
  import { CopyButton } from "../CopyButton/CopyButton.mjs";
14
14
  import clsx from "clsx";
15
- import { useCallback, useId, useState } from "react";
15
+ import { useCallback, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
16
16
  import { jsx, jsxs } from "react/jsx-runtime";
17
17
  import { useObjectRef } from "react-aria";
18
18
  import CodeMirror, { EditorView } from "@uiw/react-codemirror";
@@ -22,7 +22,7 @@ import CodeMirror, { EditorView } from "@uiw/react-codemirror";
22
22
  * @flowStatus new
23
23
  */
24
24
  var CodeEditor = flowComponent("CodeEditor", (props) => {
25
- const { ref, children, className, language, extensions, isReadOnly, isDisabled, isInvalid, isRequired, validationBehavior: _ignoredValidationBehavior, value, showLineNumbers = true, showCodeFolding = true, showCodeIndentationMakers = true, showLinterMarkers = true, showActiveLineMarker = true, copyable = true, height, minHeight, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, ...rest } = useControlledHostValueProps(props, "");
25
+ const { ref, children, className, language, extensions, isReadOnly, isDisabled, isInvalid, isRequired, validationBehavior: _ignoredValidationBehavior, value, onChange, onStatistics, showLineNumbers = true, showCodeFolding = true, showCodeIndentationMakers = true, showLinterMarkers = true, showActiveLineMarker = true, copyable = true, height, minHeight, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, ...rest } = useControlledHostValueProps(props, "");
26
26
  const { FieldErrorView, FieldErrorCaptureContext, wrapperProps, controlProps, fieldPropsContext } = useFieldComponent(props, "CodeEditor");
27
27
  const rootClassName = clsx(wrapperProps.className, CodeEditor_module_default.codeEditor, className);
28
28
  const labelId = useId();
@@ -83,14 +83,48 @@ var CodeEditor = flowComponent("CodeEditor", (props) => {
83
83
  */
84
84
  const labelledBy = joinIds(ariaLabelledBy, hasLabel && labelId);
85
85
  const describedBy = joinIds(hasDescription && descriptionId, controlProps["aria-describedby"]);
86
- const contentAttributes = EditorView.contentAttributes.of({
86
+ /**
87
+ * CodeMirror reconfigures the editor whenever `extensions`, `basicSetup` or
88
+ * `onChange` is a new object. All three are stable, so a render with
89
+ * unchanged props leaves the editor as it is.
90
+ */
91
+ const allExtensions = useMemo(() => [...enabledExtensions, EditorView.contentAttributes.of({
87
92
  ...labelledBy ? { "aria-labelledby": labelledBy } : {},
88
93
  ...ariaLabel ? { "aria-label": ariaLabel } : {},
89
94
  ...describedBy ? { "aria-describedby": describedBy } : {},
90
95
  ...isRequired ? { "aria-required": "true" } : {},
91
96
  ...isInvalid ? { "aria-invalid": "true" } : {},
92
97
  ...isDisabled ? { "aria-disabled": "true" } : {}
98
+ })], [
99
+ enabledExtensions,
100
+ labelledBy,
101
+ ariaLabel,
102
+ describedBy,
103
+ isRequired,
104
+ isInvalid,
105
+ isDisabled
106
+ ]);
107
+ const handlersRef = useRef({
108
+ onChange,
109
+ onStatistics
93
110
  });
111
+ useLayoutEffect(() => {
112
+ handlersRef.current = {
113
+ onChange,
114
+ onStatistics
115
+ };
116
+ });
117
+ const stableOnChange = useCallback((value) => handlersRef.current.onChange(value), []);
118
+ const stableOnStatistics = useCallback((statistics) => handlersRef.current.onStatistics?.(statistics), []);
119
+ const highlightActiveLine = showActiveLineMarker && !isDisabled;
120
+ const basicSetup = useMemo(() => ({
121
+ highlightActiveLine,
122
+ highlightActiveLineGutter: highlightActiveLine,
123
+ autocompletion: false,
124
+ lineNumbers: false,
125
+ foldGutter: false,
126
+ highlightSelectionMatches: false
127
+ }), [highlightActiveLine]);
94
128
  const localRef = useObjectRef(ref);
95
129
  useMakeFocusable(localRef);
96
130
  const isSkeleton = useSkeletonMode();
@@ -105,14 +139,9 @@ var CodeEditor = flowComponent("CodeEditor", (props) => {
105
139
  const editor = /* @__PURE__ */ jsxs(CodeMirror, {
106
140
  ...rest,
107
141
  value,
108
- basicSetup: {
109
- highlightActiveLine: showActiveLineMarker && !isDisabled,
110
- highlightActiveLineGutter: showActiveLineMarker && !isDisabled,
111
- autocompletion: false,
112
- lineNumbers: false,
113
- foldGutter: false,
114
- highlightSelectionMatches: false
115
- },
142
+ onChange: stableOnChange,
143
+ onStatistics: stableOnStatistics,
144
+ basicSetup,
116
145
  theme: defaultLightTheme,
117
146
  "data-invalid": isInvalid || void 0,
118
147
  "data-disabled": isDisabled || void 0,
@@ -122,7 +151,7 @@ var CodeEditor = flowComponent("CodeEditor", (props) => {
122
151
  ref: (codeMirrorRef) => {
123
152
  if (codeMirrorRef?.editor) localRef.current = codeMirrorRef.editor;
124
153
  },
125
- extensions: [...enabledExtensions, contentAttributes],
154
+ extensions: allExtensions,
126
155
  height: height ?? minHeight,
127
156
  children: [copyable && /* @__PURE__ */ jsx(CopyButton, {
128
157
  className: CodeEditor_module_default.copyButton,
@@ -1 +1 @@
1
- {"version":3,"file":"CodeEditor.mjs","names":["styles"],"sources":["../../../../../../../src/components/CodeEditor/CodeEditor.tsx"],"sourcesContent":["import type { ReactCodeMirrorProps } from \"@uiw/react-codemirror\";\nimport CodeMirror, { EditorView } from \"@uiw/react-codemirror\";\nimport { useCallback, useId, useState } from \"react\";\nimport {\n flowComponent,\n type FlowComponentProps,\n} from \"@/lib/componentFactory/flowComponent\";\nimport { useControlledHostValueProps } from \"@/lib/remote/useControlledHostValueProps\";\nimport { joinIds, useFieldComponent } from \"@/lib/hooks/useFieldComponent\";\nimport { type PropsContext, PropsContextProvider } from \"@/lib/propsContext\";\nimport clsx from \"clsx\";\nimport styles from \"./CodeEditor.module.scss\";\nimport { type CodeEditorLanguage } from \"@/components/CodeEditor/languages\";\nimport { useMakeFocusable } from \"@/lib/hooks/dom/useMakeFocusable\";\nimport { useObjectRef } from \"react-aria\";\nimport { defaultLightTheme } from \"@/components/CodeEditor/themes/defaultEditorTheme\";\nimport {\n type CodeEditorSetup,\n useCodeEditorExtensions,\n} from \"@/components/CodeEditor/hooks/useCodeEditorExtensions\";\nimport { CopyButton } from \"@/components/CopyButton\";\nimport { UiComponentTunnelExit } from \"@/components/UiComponentTunnel/UiComponentTunnelExit\";\nimport { useSkeletonMode } from \"@/components/SkeletonMode/skeletonModeContext\";\n\nexport interface CodeEditorProps\n extends\n Omit<ReactCodeMirrorProps, \"theme\" | \"lang\" | \"basicSetup\" | \"readOnly\">,\n CodeEditorSetup,\n FlowComponentProps {\n /** The initial code of an uncontrolled editor. */\n defaultValue?: string;\n /**\n * Whether the code can be read but not edited.\n *\n * @default false\n */\n isReadOnly?: boolean;\n /**\n * Whether the editor is disabled. The code can neither be edited, focused nor\n * copied.\n *\n * @default false\n */\n isDisabled?: boolean;\n /**\n * Whether the editor is displayed as invalid.\n *\n * @default false\n */\n isInvalid?: boolean;\n /** The elements class name. */\n className?: string;\n /**\n * The language the code is highlighted as. A language the editor does not\n * know is shown as plain text.\n */\n language?: CodeEditorLanguage | (string & {});\n /**\n * Whether a button to copy the code to the clipboard is shown.\n *\n * @default true\n */\n copyable?: boolean;\n /**\n * Whether the field must be filled in. Only marks the editor as required for\n * assistive technology — the editor does not validate itself.\n *\n * @default false\n */\n isRequired?: boolean;\n /**\n * @internal Set by `<Field />` on every form field. The editor has no\n * react-aria validation to forward it to and drops it.\n */\n validationBehavior?: unknown;\n}\n\n/**\n * @flr-generate all\n * @flowStatus new\n */\nexport const CodeEditor = flowComponent(\"CodeEditor\", (props) => {\n const {\n ref,\n children,\n className,\n language,\n extensions,\n isReadOnly,\n isDisabled,\n isInvalid,\n isRequired,\n validationBehavior: _ignoredValidationBehavior,\n value,\n showLineNumbers = true,\n showCodeFolding = true,\n showCodeIndentationMakers = true,\n showLinterMarkers = true,\n showActiveLineMarker = true,\n copyable = true,\n height,\n minHeight,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n ...rest\n } = useControlledHostValueProps(props, \"\");\n\n const {\n FieldErrorView,\n FieldErrorCaptureContext,\n wrapperProps,\n controlProps,\n fieldPropsContext,\n } = useFieldComponent(props, \"CodeEditor\");\n\n const rootClassName = clsx(\n wrapperProps.className,\n styles.codeEditor,\n className,\n );\n\n const labelId = useId();\n const descriptionId = useId();\n\n /**\n * Both are optional. Their refs tell whether they are rendered, so the editor\n * never references an element that does not exist – a dangling id fails HTML\n * validators and a11y checks. The callbacks are stable: a new one per render\n * would detach and re-attach on every render.\n */\n const [hasLabel, setHasLabel] = useState(false);\n const [hasDescription, setHasDescription] = useState(false);\n const labelRef = useCallback((element: Element | null) => {\n setHasLabel(!!element);\n }, []);\n const descriptionRef = useCallback((element: Element | null) => {\n setHasDescription(!!element);\n }, []);\n\n /**\n * The label and the field description are declared as children of the code\n * editor, but must be rendered outside of the editor itself. They are\n * tunneled out of the editor – just like the field error. Their ids are the\n * ones the editor references.\n */\n const propsContext: PropsContext = {\n ...fieldPropsContext,\n Label: {\n ...fieldPropsContext.Label,\n id: labelId,\n ref: labelRef,\n tunnel: { id: \"label\", component: \"CodeEditor\" },\n },\n FieldDescription: {\n ...fieldPropsContext.FieldDescription,\n id: descriptionId,\n ref: descriptionRef,\n tunnel: { id: \"fieldDescription\", component: \"CodeEditor\" },\n },\n };\n\n const enabledExtensions = useCodeEditorExtensions(language, extensions, {\n showLineNumbers: showLineNumbers,\n showCodeIndentationMakers: showCodeIndentationMakers,\n showCodeFolding: showCodeFolding,\n showLinterMarkers: showLinterMarkers,\n });\n\n /**\n * The editable element of CodeMirror is the `.cm-content` element – not the\n * root element the props are applied to. Its ARIA attributes are set through\n * the content attributes facet.\n *\n * Without a label, an `aria-label` names the editor instead.\n */\n const labelledBy = joinIds(ariaLabelledBy, hasLabel && labelId);\n const describedBy = joinIds(\n hasDescription && descriptionId,\n controlProps[\"aria-describedby\"],\n );\n\n const contentAttributes = EditorView.contentAttributes.of({\n ...(labelledBy ? { \"aria-labelledby\": labelledBy } : {}),\n ...(ariaLabel ? { \"aria-label\": ariaLabel } : {}),\n ...(describedBy ? { \"aria-describedby\": describedBy } : {}),\n ...(isRequired ? { \"aria-required\": \"true\" } : {}),\n ...(isInvalid ? { \"aria-invalid\": \"true\" } : {}),\n ...(isDisabled ? { \"aria-disabled\": \"true\" } : {}),\n });\n\n const localRef = useObjectRef(ref);\n\n useMakeFocusable(localRef);\n\n const isSkeleton = useSkeletonMode();\n\n /* No CodeMirror: one surface, as high as the code in the editor's line\n height. The children still render, so a label or a field description\n tunnels out and follows its own skeleton rule. */\n const skeleton = (\n <div\n className={clsx(\n styles.codeMirror,\n isReadOnly && styles.readonly,\n styles.skeleton,\n )}\n >\n <div\n className={styles.skeletonLines}\n style={{ height: height ?? minHeight }}\n >\n {(value ?? \"\").split(\"\\n\").map((line, index) => (\n <div key={index}>{line || \" \"}</div>\n ))}\n </div>\n {children}\n </div>\n );\n\n const editor = (\n <CodeMirror\n {...rest}\n value={value}\n basicSetup={{\n highlightActiveLine: showActiveLineMarker && !isDisabled,\n highlightActiveLineGutter: showActiveLineMarker && !isDisabled,\n autocompletion: false,\n lineNumbers: false,\n foldGutter: false,\n highlightSelectionMatches: false,\n }}\n theme={defaultLightTheme}\n data-invalid={isInvalid || undefined}\n data-disabled={isDisabled || undefined}\n readOnly={isReadOnly || isDisabled}\n editable={!isDisabled}\n className={clsx(styles.codeMirror, isReadOnly && styles.readonly)}\n ref={(codeMirrorRef) => {\n if (codeMirrorRef?.editor) {\n localRef.current = codeMirrorRef.editor;\n }\n }}\n extensions={[...enabledExtensions, contentAttributes]}\n height={height ?? minHeight}\n >\n {copyable && (\n <CopyButton\n className={styles.copyButton}\n size=\"s\"\n variant=\"soft\"\n text={value}\n isDisabled={isDisabled}\n />\n )}\n {children}\n </CodeMirror>\n );\n\n return (\n <div\n className={rootClassName}\n data-disabled={isDisabled || undefined}\n inert={isSkeleton || undefined}\n >\n <PropsContextProvider props={propsContext}>\n <UiComponentTunnelExit id=\"label\" component=\"CodeEditor\" />\n <FieldErrorCaptureContext>\n {isSkeleton ? skeleton : editor}\n </FieldErrorCaptureContext>\n <UiComponentTunnelExit id=\"fieldDescription\" component=\"CodeEditor\" />\n <FieldErrorView />\n </PropsContextProvider>\n </div>\n );\n});\n\nexport default CodeEdit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GACE,WAAWA,0BAAO;GAClB,MAAK;GACL,SAAQ;GACR,MAAM;GACM;EACb,CAAA,GAEF,QACS;;CAGd,OACE,oBAAC,OAAD;EACE,WAAW;EACX,iBAAe,cAAc,KAAA;EAC7B,OAAO,cAAc,KAAA;EAErB,UAAA,qBAAC,sBAAD;GAAsB,OAAO;GAA7B,UAAA;IACE,oBAAC,uBAAD;KAAuB,IAAG;KAAQ,WAAU;IAAc,CAAA;IAC1D,oBAAC,0BAAD,EAAA,UACG,aAAa,WAAW,OACD,CAAA;IAC1B,oBAAC,uBAAD;KAAuB,IAAG;KAAmB,WAAU;IAAc,CAAA;IACrE,oBAAC,gBAAD,CAAiB,CAAA;GACG;;CACnB,CAAA;AAET,CAAC"}
1
+ {"version":3,"file":"CodeEditor.mjs","names":["styles"],"sources":["../../../../../../../src/components/CodeEditor/CodeEditor.tsx"],"sourcesContent":["import type { ReactCodeMirrorProps, Statistics } from \"@uiw/react-codemirror\";\nimport CodeMirror, { EditorView } from \"@uiw/react-codemirror\";\nimport {\n useCallback,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n flowComponent,\n type FlowComponentProps,\n} from \"@/lib/componentFactory/flowComponent\";\nimport { useControlledHostValueProps } from \"@/lib/remote/useControlledHostValueProps\";\nimport { joinIds, useFieldComponent } from \"@/lib/hooks/useFieldComponent\";\nimport { type PropsContext, PropsContextProvider } from \"@/lib/propsContext\";\nimport clsx from \"clsx\";\nimport styles from \"./CodeEditor.module.scss\";\nimport { type CodeEditorLanguage } from \"@/components/CodeEditor/languages\";\nimport { useMakeFocusable } from \"@/lib/hooks/dom/useMakeFocusable\";\nimport { useObjectRef } from \"react-aria\";\nimport { defaultLightTheme } from \"@/components/CodeEditor/themes/defaultEditorTheme\";\nimport {\n type CodeEditorSetup,\n useCodeEditorExtensions,\n} from \"@/components/CodeEditor/hooks/useCodeEditorExtensions\";\nimport { CopyButton } from \"@/components/CopyButton\";\nimport { UiComponentTunnelExit } from \"@/components/UiComponentTunnel/UiComponentTunnelExit\";\nimport { useSkeletonMode } from \"@/components/SkeletonMode/skeletonModeContext\";\n\nexport interface CodeEditorProps\n extends\n Omit<ReactCodeMirrorProps, \"theme\" | \"lang\" | \"basicSetup\" | \"readOnly\">,\n CodeEditorSetup,\n FlowComponentProps {\n /** The initial code of an uncontrolled editor. */\n defaultValue?: string;\n /**\n * Whether the code can be read but not edited.\n *\n * @default false\n */\n isReadOnly?: boolean;\n /**\n * Whether the editor is disabled. The code can neither be edited, focused nor\n * copied.\n *\n * @default false\n */\n isDisabled?: boolean;\n /**\n * Whether the editor is displayed as invalid.\n *\n * @default false\n */\n isInvalid?: boolean;\n /** The elements class name. */\n className?: string;\n /**\n * The language the code is highlighted as. A language the editor does not\n * know is shown as plain text.\n */\n language?: CodeEditorLanguage | (string & {});\n /**\n * Whether a button to copy the code to the clipboard is shown.\n *\n * @default true\n */\n copyable?: boolean;\n /**\n * Whether the field must be filled in. Only marks the editor as required for\n * assistive technology — the editor does not validate itself.\n *\n * @default false\n */\n isRequired?: boolean;\n /**\n * @internal Set by `<Field />` on every form field. The editor has no\n * react-aria validation to forward it to and drops it.\n */\n validationBehavior?: unknown;\n}\n\n/**\n * @flr-generate all\n * @flowStatus new\n */\nexport const CodeEditor = flowComponent(\"CodeEditor\", (props) => {\n const {\n ref,\n children,\n className,\n language,\n extensions,\n isReadOnly,\n isDisabled,\n isInvalid,\n isRequired,\n validationBehavior: _ignoredValidationBehavior,\n value,\n onChange,\n onStatistics,\n showLineNumbers = true,\n showCodeFolding = true,\n showCodeIndentationMakers = true,\n showLinterMarkers = true,\n showActiveLineMarker = true,\n copyable = true,\n height,\n minHeight,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n ...rest\n } = useControlledHostValueProps(props, \"\");\n\n const {\n FieldErrorView,\n FieldErrorCaptureContext,\n wrapperProps,\n controlProps,\n fieldPropsContext,\n } = useFieldComponent(props, \"CodeEditor\");\n\n const rootClassName = clsx(\n wrapperProps.className,\n styles.codeEditor,\n className,\n );\n\n const labelId = useId();\n const descriptionId = useId();\n\n /**\n * Both are optional. Their refs tell whether they are rendered, so the editor\n * never references an element that does not exist – a dangling id fails HTML\n * validators and a11y checks. The callbacks are stable: a new one per render\n * would detach and re-attach on every render.\n */\n const [hasLabel, setHasLabel] = useState(false);\n const [hasDescription, setHasDescription] = useState(false);\n const labelRef = useCallback((element: Element | null) => {\n setHasLabel(!!element);\n }, []);\n const descriptionRef = useCallback((element: Element | null) => {\n setHasDescription(!!element);\n }, []);\n\n /**\n * The label and the field description are declared as children of the code\n * editor, but must be rendered outside of the editor itself. They are\n * tunneled out of the editor – just like the field error. Their ids are the\n * ones the editor references.\n */\n const propsContext: PropsContext = {\n ...fieldPropsContext,\n Label: {\n ...fieldPropsContext.Label,\n id: labelId,\n ref: labelRef,\n tunnel: { id: \"label\", component: \"CodeEditor\" },\n },\n FieldDescription: {\n ...fieldPropsContext.FieldDescription,\n id: descriptionId,\n ref: descriptionRef,\n tunnel: { id: \"fieldDescription\", component: \"CodeEditor\" },\n },\n };\n\n const enabledExtensions = useCodeEditorExtensions(language, extensions, {\n showLineNumbers: showLineNumbers,\n showCodeIndentationMakers: showCodeIndentationMakers,\n showCodeFolding: showCodeFolding,\n showLinterMarkers: showLinterMarkers,\n });\n\n /**\n * The editable element of CodeMirror is the `.cm-content` element – not the\n * root element the props are applied to. Its ARIA attributes are set through\n * the content attributes facet.\n *\n * Without a label, an `aria-label` names the editor instead.\n */\n const labelledBy = joinIds(ariaLabelledBy, hasLabel && labelId);\n const describedBy = joinIds(\n hasDescription && descriptionId,\n controlProps[\"aria-describedby\"],\n );\n\n /**\n * CodeMirror reconfigures the editor whenever `extensions`, `basicSetup` or\n * `onChange` is a new object. All three are stable, so a render with\n * unchanged props leaves the editor as it is.\n */\n const allExtensions = useMemo(\n () => [\n ...enabledExtensions,\n EditorView.contentAttributes.of({\n ...(labelledBy ? { \"aria-labelledby\": labelledBy } : {}),\n ...(ariaLabel ? { \"aria-label\": ariaLabel } : {}),\n ...(describedBy ? { \"aria-describedby\": describedBy } : {}),\n ...(isRequired ? { \"aria-required\": \"true\" } : {}),\n ...(isInvalid ? { \"aria-invalid\": \"true\" } : {}),\n ...(isDisabled ? { \"aria-disabled\": \"true\" } : {}),\n }),\n ],\n [\n enabledExtensions,\n labelledBy,\n ariaLabel,\n describedBy,\n isRequired,\n isInvalid,\n isDisabled,\n ],\n );\n\n /*\n * A new `onChange` on every render would reconfigure the editor as well.\n * CodeMirror's update listener captures `onStatistics` along with it, so both\n * call the latest handler through a ref.\n */\n const handlersRef = useRef({ onChange, onStatistics });\n useLayoutEffect(() => {\n handlersRef.current = { onChange, onStatistics };\n });\n const stableOnChange = useCallback(\n (value: string) => handlersRef.current.onChange(value),\n [],\n );\n const stableOnStatistics = useCallback(\n (statistics: Statistics) => handlersRef.current.onStatistics?.(statistics),\n [],\n );\n\n const highlightActiveLine = showActiveLineMarker && !isDisabled;\n const basicSetup = useMemo(\n () => ({\n highlightActiveLine,\n highlightActiveLineGutter: highlightActiveLine,\n autocompletion: false,\n lineNumbers: false,\n foldGutter: false,\n highlightSelectionMatches: false,\n }),\n [highlightActiveLine],\n );\n\n const localRef = useObjectRef(ref);\n\n useMakeFocusable(localRef);\n\n const isSkeleton = useSkeletonMode();\n\n /* No CodeMirror: one surface, as high as the code in the editor's line\n height. The children still render, so a label or a field description\n tunnels out and follows its own skeleton rule. */\n const skeleton = (\n <div\n className={clsx(\n styles.codeMirror,\n isReadOnly && styles.readonly,\n styles.skeleton,\n )}\n >\n <div\n className={styles.skeletonLines}\n style={{ height: height ?? minHeight }}\n >\n {(value ?? \"\").split(\"\\n\").map((line, index) => (\n <div key={index}>{line || \" \"}</div>\n ))}\n </div>\n {children}\n </div>\n );\n\n const editor = (\n <CodeMirror\n {...rest}\n value={value}\n onChange={stableOnChange}\n onStatistics={stableOnStatistics}\n basicSetup={basicSetup}\n theme={defaultLightTheme}\n data-invalid={isInvalid || undefined}\n data-disabled={isDisabled || undefined}\n readOnly={isReadOnly || isDisabled}\n editable={!isDisabled}\n className={clsx(styles.codeMirror, isReadOnly && styles.readonly)}\n ref={(codeMirrorRef) => {\n if (codeMirrorRef?.editor) {\n localRef.current = codeMirrorRef.editor;\n }\n }}\n extensions={allExtensions}\n height={height ?? minHeight}\n >\n {copyable && (\n <CopyButton\n className={styles.copyButton}\n size=\"s\"\n variant=\"soft\"\n text={value}\n isDisabled={isDisabled}\n />\n )}\n {children}\n </CodeMirror>\n );\n\n return (\n <div\n className={rootClassName}\n data-disabled={isDisabled || undefined}\n inert={isSkeleton || undefined}\n >\n <PropsContextProvider props={propsContext}>\n <UiComponentTunnelExit id=\"label\" component=\"CodeEditor\" />\n <FieldErrorCaptureContext>\n {isSkeleton ? skeleton : editor}\n </FieldErrorCaptureContext>\n <UiComponentTunnelExit id=\"fieldDescription\" component=\"CodeEditor\" />\n <FieldErrorView />\n </PropsContextProvider>\n </div>\n );\n});\n\nexport default CodeEditor;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAwFA,IAAa,aAAa,cAAc,eAAe,UAAU;CAC/D,MAAM,EACJ,KACA,UACA,WACA,UACA,YACA,YACA,YACA,WACA,YACA,oBAAoB,4BACpB,OACA,UACA,cACA,kBAAkB,MAClB,kBAAkB,MAClB,4BAA4B,MAC5B,oBAAoB,MACpB,uBAAuB,MACvB,WAAW,MACX,QACA,WACA,cAAc,WACd,mBAAmB,gBACnB,GAAG,SACD,4BAA4B,OAAO,EAAE;CAEzC,MAAM,EACJ,gBACA,0BACA,cACA,cACA,sBACE,kBAAkB,OAAO,YAAY;CAEzC,MAAM,gBAAgB,KACpB,aAAa,WACbA,0BAAO,YACP,SACF;CAEA,MAAM,UAAU,MAAM;CACtB,MAAM,gBAAgB,MAAM;;;;;;;CAQ5B,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAC9C,MAAM,CAAC,gBAAgB,qBAAqB,SAAS,KAAK;CAC1D,MAAM,W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BAAC,uBAAD;KAAuB,IAAG;KAAQ,WAAU;IAAc,CAAA;IAC1D,oBAAC,0BAAD,EAAA,UACG,aAAa,WAAW,OACD,CAAA;IAC1B,oBAAC,uBAAD;KAAuB,IAAG;KAAmB,WAAU;IAAc,CAAA;IACrE,oBAAC,gBAAD,CAAiB,CAAA;GACG;;CACnB,CAAA;AAET,CAAC"}
@@ -2,38 +2,51 @@
2
2
  /* */
3
3
  import supportedCodeEditorLanguages, { isCodeEditorLanguage } from "../languages/index.mjs";
4
4
  import { gutterSpacer } from "../extensions/gutterSpacer.mjs";
5
+ import { useMemo } from "react";
5
6
  import { lineNumbers } from "@uiw/react-codemirror";
6
7
  import { foldGutter } from "@codemirror/language";
7
8
  import { lintGutter } from "@codemirror/lint";
8
9
  import { indentationMarkers } from "@replit/codemirror-indentation-markers";
9
10
  //#region src/components/CodeEditor/hooks/useCodeEditorExtensions.tsx
10
11
  var markerColor = "var(--code-editor--indentation-marker-color)";
11
- var indentationMarkerColors = {
12
+ var codeIndentationMarkers = indentationMarkers({ colors: {
12
13
  light: markerColor,
13
14
  dark: markerColor,
14
15
  activeLight: markerColor,
15
16
  activeDark: markerColor
16
- };
17
+ } });
18
+ var noExtensions = [];
17
19
  /** @internal */
18
- var useCodeEditorExtensions = (language, extensions = [], options = {
20
+ var useCodeEditorExtensions = (language, extensions = noExtensions, options = {
19
21
  showCodeFolding: true,
20
22
  showCodeIndentationMakers: true,
21
23
  showLineNumbers: true,
22
24
  showLinterMarkers: true
23
25
  }) => {
24
- if (options.showLineNumbers) extensions.push(lineNumbers());
25
- if (options.showCodeFolding) extensions.push(foldGutter({ markerDOM: (open) => {
26
- const element = document.createElement("span");
27
- element.classList.add("cm-foldGutter");
28
- element.classList.add(open ? "cm-foldGutter-open" : "cm-foldGutter-closed");
29
- element.innerText = open ? "⌄" : "›";
30
- return element;
31
- } }));
32
- if (options.showLinterMarkers) extensions.push(lintGutter());
33
- if (options.showLineNumbers && (!options.showCodeFolding || !options.showLinterMarkers)) extensions.push(gutterSpacer());
34
- if (options.showCodeIndentationMakers) extensions.push(indentationMarkers({ colors: indentationMarkerColors }));
35
- if (language && isCodeEditorLanguage(language)) supportedCodeEditorLanguages[language]?.map((loader) => extensions.push(loader()));
36
- return extensions;
26
+ const { showCodeFolding, showCodeIndentationMakers, showLineNumbers, showLinterMarkers } = options;
27
+ return useMemo(() => {
28
+ const enabledExtensions = [...extensions];
29
+ if (showLineNumbers) enabledExtensions.push(lineNumbers());
30
+ if (showCodeFolding) enabledExtensions.push(foldGutter({ markerDOM: (open) => {
31
+ const element = document.createElement("span");
32
+ element.classList.add("cm-foldGutter");
33
+ element.classList.add(open ? "cm-foldGutter-open" : "cm-foldGutter-closed");
34
+ element.innerText = open ? "⌄" : "›";
35
+ return element;
36
+ } }));
37
+ if (showLinterMarkers) enabledExtensions.push(lintGutter());
38
+ if (showLineNumbers && (!showCodeFolding || !showLinterMarkers)) enabledExtensions.push(gutterSpacer());
39
+ if (showCodeIndentationMakers) enabledExtensions.push(codeIndentationMarkers);
40
+ if (language && isCodeEditorLanguage(language)) for (const loader of supportedCodeEditorLanguages[language] ?? []) enabledExtensions.push(loader());
41
+ return enabledExtensions;
42
+ }, [
43
+ language,
44
+ extensions,
45
+ showCodeFolding,
46
+ showCodeIndentationMakers,
47
+ showLineNumbers,
48
+ showLinterMarkers
49
+ ]);
37
50
  };
38
51
  //#endregion
39
52
  export { useCodeEditorExtensions };
@@ -1 +1 @@
1
- {"version":3,"file":"useCodeEditorExtensions.mjs","names":[],"sources":["../../../../../../../../src/components/CodeEditor/hooks/useCodeEditorExtensions.tsx"],"sourcesContent":["import { type Extension, lineNumbers } from \"@uiw/react-codemirror\";\nimport { lintGutter } from \"@codemirror/lint\";\nimport supportedCodeEditorLanguages, {\n isCodeEditorLanguage,\n} from \"@/components/CodeEditor/languages\";\nimport { indentationMarkers } from \"@replit/codemirror-indentation-markers\";\nimport { foldGutter } from \"@codemirror/language\";\nimport { gutterSpacer } from \"@/components/CodeEditor/extensions/gutterSpacer\";\n\n/*\n * Every slot gets the same color: the library picks between its light and dark\n * one by CodeMirror's dark theme flag, which Flow's theme never sets, and the\n * active block needs no color of its own.\n */\nconst markerColor = \"var(--code-editor--indentation-marker-color)\";\nconst indentationMarkerColors = {\n light: markerColor,\n dark: markerColor,\n activeLight: markerColor,\n activeDark: markerColor,\n};\n\nexport interface CodeEditorSetup {\n /**\n * Whether the line the cursor is on is highlighted.\n *\n * @default true\n */\n showActiveLineMarker?: boolean;\n /**\n * Whether the gutter offers controls to fold and unfold code blocks.\n *\n * @default true\n */\n showCodeFolding?: boolean;\n /**\n * Whether indentation levels are visualized with guide lines.\n *\n * @default true\n */\n showCodeIndentationMakers?: boolean;\n /**\n * Whether line numbers are shown in the gutter.\n *\n * @default true\n */\n showLineNumbers?: boolean;\n /**\n * Whether linter results are shown in the gutter.\n *\n * @default true\n */\n showLinterMarkers?: boolean;\n}\n\n/** @internal */\nexport const useCodeEditorExtensions = (\n language?: string,\n extensions: Extension[] = [],\n options: CodeEditorSetup = {\n showCodeFolding: true,\n showCodeIndentationMakers: true,\n showLineNumbers: true,\n showLinterMarkers: true,\n },\n) => {\n if (options.showLineNumbers) {\n extensions.push(lineNumbers());\n }\n\n if (options.showCodeFolding) {\n extensions.push(\n foldGutter({\n markerDOM: (open) => {\n const element = document.createElement(\"span\");\n element.classList.add(\"cm-foldGutter\");\n element.classList.add(\n open ? \"cm-foldGutter-open\" : \"cm-foldGutter-closed\",\n );\n element.innerText = open ? \"⌄\" : \"›\";\n return element;\n },\n }),\n );\n }\n\n if (options.showLinterMarkers) {\n extensions.push(lintGutter());\n }\n\n if (\n options.showLineNumbers &&\n (!options.showCodeFolding || !options.showLinterMarkers)\n ) {\n extensions.push(gutterSpacer());\n }\n\n if (options.showCodeIndentationMakers) {\n extensions.push(indentationMarkers({ colors: indentationMarkerColors }));\n }\n\n if (language && isCodeEditorLanguage(language)) {\n supportedCodeEditorLanguages[language]?.map((loader) =>\n extensions.push(loader()),\n );\n }\n\n return extensions;\n};\n"],"mappings":";;;;;;;;;AAcA,IAAM,cAAc;AACpB,IAAM,0BAA0B;CAC9B,OAAO;CACP,MAAM;CACN,aAAa;CACb,YAAY;AACd;;AAoCA,IAAa,2BACX,UACA,aAA0B,CAAC,GAC3B,UAA2B;CACzB,iBAAiB;CACjB,2BAA2B;CAC3B,iBAAiB;CACjB,mBAAmB;AACrB,MACG;CACH,IAAI,QAAQ,iBACV,WAAW,KAAK,YAAY,CAAC;CAG/B,IAAI,QAAQ,iBACV,WAAW,KACT,WAAW,EACT,YAAY,SAAS;EACnB,MAAM,UAAU,SAAS,cAAc,MAAM;EAC7C,QAAQ,UAAU,IAAI,eAAe;EACrC,QAAQ,UAAU,IAChB,OAAO,uBAAuB,sBAChC;EACA,QAAQ,YAAY,OAAO,MAAM;EACjC,OAAO;CACT,EACF,CAAC,CACH;CAGF,IAAI,QAAQ,mBACV,WAAW,KAAK,WAAW,CAAC;CAG9B,IACE,QAAQ,oBACP,CAAC,QAAQ,mBAAmB,CAAC,QAAQ,oBAEtC,WAAW,KAAK,aAAa,CAAC;CAGhC,IAAI,QAAQ,2BACV,WAAW,KAAK,mBAAmB,EAAE,QAAQ,wBAAwB,CAAC,CAAC;CAGzE,IAAI,YAAY,qBAAqB,QAAQ,GAC3C,6BAA6B,SAAS,EAAE,KAAK,WAC3C,WAAW,KAAK,OAAO,CAAC,CAC1B;CAGF,OAAO;AACT"}
1
+ {"version":3,"file":"useCodeEditorExtensions.mjs","names":[],"sources":["../../../../../../../../src/components/CodeEditor/hooks/useCodeEditorExtensions.tsx"],"sourcesContent":["import { type Extension, lineNumbers } from \"@uiw/react-codemirror\";\nimport { lintGutter } from \"@codemirror/lint\";\nimport supportedCodeEditorLanguages, {\n isCodeEditorLanguage,\n} from \"@/components/CodeEditor/languages\";\nimport { indentationMarkers } from \"@replit/codemirror-indentation-markers\";\nimport { foldGutter } from \"@codemirror/language\";\nimport { gutterSpacer } from \"@/components/CodeEditor/extensions/gutterSpacer\";\nimport { useMemo } from \"react\";\n\n/*\n * Every slot gets the same color: the library picks between its light and dark\n * one by CodeMirror's dark theme flag, which Flow's theme never sets, and the\n * active block needs no color of its own.\n */\nconst markerColor = \"var(--code-editor--indentation-marker-color)\";\n\n/*\n * Created once: every call brings a new style module along, and CodeMirror\n * never unmounts a style module – one per render grows the document's styles.\n */\nconst codeIndentationMarkers = indentationMarkers({\n colors: {\n light: markerColor,\n dark: markerColor,\n activeLight: markerColor,\n activeDark: markerColor,\n },\n});\n\nexport interface CodeEditorSetup {\n /**\n * Whether the line the cursor is on is highlighted.\n *\n * @default true\n */\n showActiveLineMarker?: boolean;\n /**\n * Whether the gutter offers controls to fold and unfold code blocks.\n *\n * @default true\n */\n showCodeFolding?: boolean;\n /**\n * Whether indentation levels are visualized with guide lines.\n *\n * @default true\n */\n showCodeIndentationMakers?: boolean;\n /**\n * Whether line numbers are shown in the gutter.\n *\n * @default true\n */\n showLineNumbers?: boolean;\n /**\n * Whether linter results are shown in the gutter.\n *\n * @default true\n */\n showLinterMarkers?: boolean;\n}\n\nconst noExtensions: Extension[] = [];\n\n/** @internal */\nexport const useCodeEditorExtensions = (\n language?: string,\n extensions: Extension[] = noExtensions,\n options: CodeEditorSetup = {\n showCodeFolding: true,\n showCodeIndentationMakers: true,\n showLineNumbers: true,\n showLinterMarkers: true,\n },\n): Extension[] => {\n const {\n showCodeFolding,\n showCodeIndentationMakers,\n showLineNumbers,\n showLinterMarkers,\n } = options;\n\n return useMemo(() => {\n const enabledExtensions = [...extensions];\n\n if (showLineNumbers) {\n enabledExtensions.push(lineNumbers());\n }\n\n if (showCodeFolding) {\n enabledExtensions.push(\n foldGutter({\n markerDOM: (open) => {\n const element = document.createElement(\"span\");\n element.classList.add(\"cm-foldGutter\");\n element.classList.add(\n open ? \"cm-foldGutter-open\" : \"cm-foldGutter-closed\",\n );\n element.innerText = open ? \"⌄\" : \"›\";\n return element;\n },\n }),\n );\n }\n\n if (showLinterMarkers) {\n enabledExtensions.push(lintGutter());\n }\n\n if (showLineNumbers && (!showCodeFolding || !showLinterMarkers)) {\n enabledExtensions.push(gutterSpacer());\n }\n\n if (showCodeIndentationMakers) {\n enabledExtensions.push(codeIndentationMarkers);\n }\n\n if (language && isCodeEditorLanguage(language)) {\n for (const loader of supportedCodeEditorLanguages[language] ?? []) {\n enabledExtensions.push(loader());\n }\n }\n\n return enabledExtensions;\n }, [\n language,\n extensions,\n showCodeFolding,\n showCodeIndentationMakers,\n showLineNumbers,\n showLinterMarkers,\n ]);\n};\n"],"mappings":";;;;;;;;;;AAeA,IAAM,cAAc;AAMpB,IAAM,yBAAyB,mBAAmB,EAChD,QAAQ;CACN,OAAO;CACP,MAAM;CACN,aAAa;CACb,YAAY;AACd,EACF,CAAC;AAmCD,IAAM,eAA4B,CAAC;;AAGnC,IAAa,2BACX,UACA,aAA0B,cAC1B,UAA2B;CACzB,iBAAiB;CACjB,2BAA2B;CAC3B,iBAAiB;CACjB,mBAAmB;AACrB,MACgB;CAChB,MAAM,EACJ,iBACA,2BACA,iBACA,sBACE;CAEJ,OAAO,cAAc;EACnB,MAAM,oBAAoB,CAAC,GAAG,UAAU;EAExC,IAAI,iBACF,kBAAkB,KAAK,YAAY,CAAC;EAGtC,IAAI,iBACF,kBAAkB,KAChB,WAAW,EACT,YAAY,SAAS;GACnB,MAAM,UAAU,SAAS,cAAc,MAAM;GAC7C,QAAQ,UAAU,IAAI,eAAe;GACrC,QAAQ,UAAU,IAChB,OAAO,uBAAuB,sBAChC;GACA,QAAQ,YAAY,OAAO,MAAM;GACjC,OAAO;EACT,EACF,CAAC,CACH;EAGF,IAAI,mBACF,kBAAkB,KAAK,WAAW,CAAC;EAGrC,IAAI,oBAAoB,CAAC,mBAAmB,CAAC,oBAC3C,kBAAkB,KAAK,aAAa,CAAC;EAGvC,IAAI,2BACF,kBAAkB,KAAK,sBAAsB;EAG/C,IAAI,YAAY,qBAAqB,QAAQ,GAC3C,KAAK,MAAM,UAAU,6BAA6B,aAAa,CAAC,GAC9D,kBAAkB,KAAK,OAAO,CAAC;EAInC,OAAO;CACT,GAAG;EACD;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;AACH"}
@@ -7,6 +7,7 @@ import { Item } from "./components/Item/Item.mjs";
7
7
  import ItemsGridListView from "../../../../views/ItemsGridListView.mjs";
8
8
  import { FallbackItems } from "./components/FallbackItems/FallbackItems.mjs";
9
9
  import { useInfiniteScrollTrigger } from "../../hooks/useInfiniteScrollTrigger.mjs";
10
+ import { useLatestOnAction } from "../../hooks/useLatestOnAction.mjs";
10
11
  import clsx from "clsx";
11
12
  import { jsx } from "react/jsx-runtime";
12
13
  //#region src/components/List/components/Items/Items.tsx
@@ -17,11 +18,13 @@ var Items = () => {
17
18
  const isInitiallyLoading = list.loader.useIsInitiallyLoading();
18
19
  const isLoadingMore = list.loader.useIsLoadingMore();
19
20
  const { triggerRef, triggerIndex } = useInfiniteScrollTrigger();
21
+ const onAction = useLatestOnAction(list);
20
22
  if (!list.itemView) return null;
21
23
  const items = list.items.entries.map((item, index) => /* @__PURE__ */ jsx(Item, {
22
24
  data: item.data,
23
25
  id: item.id,
24
26
  list,
27
+ onAction,
25
28
  isTile: tiles,
26
29
  triggerRef: index === triggerIndex ? triggerRef : void 0
27
30
  }, item.id));
@@ -1 +1 @@
1
- {"version":3,"file":"Items.mjs","names":["styles"],"sources":["../../../../../../../../../src/components/List/components/Items/Items.tsx"],"sourcesContent":["import Item from \"@/components/List/components/Items/components/Item/Item\";\nimport { useList } from \"@/components/List/hooks/useList\";\nimport DivView from \"@/views/DivView\";\nimport ItemsGridListView from \"@/views/ItemsGridListView\";\nimport clsx from \"clsx\";\nimport type { FC } from \"react\";\nimport styles from \"./Items.module.scss\";\nimport { FallbackItems } from \"./components/FallbackItems\";\nimport { useInfiniteScrollTrigger } from \"@/components/List/hooks/useInfiniteScrollTrigger\";\n\nexport const Items: FC = () => {\n const list = useList();\n const tiles = list.viewMode.isTiles;\n const isLoading = list.loader.useIsLoading();\n const isInitiallyLoading = list.loader.useIsInitiallyLoading();\n const isLoadingMore = list.loader.useIsLoadingMore();\n\n const { triggerRef, triggerIndex } = useInfiniteScrollTrigger();\n\n if (!list.itemView) {\n return null;\n }\n\n const items = list.items.entries.map((item, index) => (\n <Item\n key={item.id}\n data={item.data}\n id={item.id}\n list={list}\n isTile={tiles}\n triggerRef={index === triggerIndex ? triggerRef : undefined}\n />\n ));\n\n const rootClassName = clsx(\n styles.items,\n isLoading && !(list.infiniteScroll && isLoadingMore) && styles.isLoading,\n tiles && styles.tiles,\n );\n\n const {\n \"aria-labelledby\": ariaLabelledby,\n \"aria-label\": ariaLabel,\n ...rest\n } = list.componentProps;\n\n return (\n <DivView aria-hidden={isInitiallyLoading} aria-busy={isLoading}>\n <ItemsGridListView\n className={rootClassName}\n {...rest}\n aria-labelledby={ariaLabel ? undefined : ariaLabelledby}\n aria-label={ariaLabel}\n layout={tiles ? \"grid\" : \"stack\"}\n tileMaxWidth={list.itemView.tileMaxWidth}\n >\n {items.length === 0 && isInitiallyLoading ? <FallbackItems /> : items}\n </ItemsGridListView>\n </DivView>\n );\n};\n\nexport default Items;\n"],"mappings":";;;;;;;;;;;;AAUA,IAAa,cAAkB;CAC7B,MAAM,OAAO,QAAQ;CACrB,MAAM,QAAQ,KAAK,SAAS;CAC5B,MAAM,YAAY,KAAK,OAAO,aAAa;CAC3C,MAAM,qBAAqB,KAAK,OAAO,sBAAsB;CAC7D,MAAM,gBAAgB,KAAK,OAAO,iBAAiB;CAEnD,MAAM,EAAE,YAAY,iBAAiB,yBAAyB;CAE9D,IAAI,CAAC,KAAK,UACR,OAAO;CAGT,MAAM,QAAQ,KAAK,MAAM,QAAQ,KAAK,MAAM,UAC1C,oBAAC,MAAD;EAEE,MAAM,KAAK;EACX,IAAI,KAAK;EACH;EACN,QAAQ;EACR,YAAY,UAAU,eAAe,aAAa,KAAA;CACnD,GANM,KAAK,EAMX,CACF;CAED,MAAM,gBAAgB,KACpBA,qBAAO,OACP,aAAa,EAAE,KAAK,kBAAkB,kBAAkBA,qBAAO,WAC/D,SAASA,qBAAO,KAClB;CAEA,MAAM,EACJ,mBAAmB,gBACnB,cAAc,WACd,GAAG,SACD,KAAK;CAET,OACE,oBAAC,SAAD;EAAS,eAAa;EAAoB,aAAW;EACnD,UAAA,oBAAC,mBAAD;GACE,WAAW;GACX,GAAI;GACJ,mBAAiB,YAAY,KAAA,IAAY;GACzC,cAAY;GACZ,QAAQ,QAAQ,SAAS;GACzB,cAAc,KAAK,SAAS;GAE3B,UAAA,MAAM,WAAW,KAAK,qBAAqB,oBAAC,eAAD,CAAgB,CAAA,IAAI;EAC/C,CAAA;CACZ,CAAA;AAEb"}
1
+ {"version":3,"file":"Items.mjs","names":["styles"],"sources":["../../../../../../../../../src/components/List/components/Items/Items.tsx"],"sourcesContent":["import Item from \"@/components/List/components/Items/components/Item/Item\";\nimport { useList } from \"@/components/List/hooks/useList\";\nimport DivView from \"@/views/DivView\";\nimport ItemsGridListView from \"@/views/ItemsGridListView\";\nimport clsx from \"clsx\";\nimport type { FC } from \"react\";\nimport styles from \"./Items.module.scss\";\nimport { FallbackItems } from \"./components/FallbackItems\";\nimport { useInfiniteScrollTrigger } from \"@/components/List/hooks/useInfiniteScrollTrigger\";\nimport { useLatestOnAction } from \"@/components/List/hooks/useLatestOnAction\";\n\nexport const Items: FC = () => {\n const list = useList();\n const tiles = list.viewMode.isTiles;\n const isLoading = list.loader.useIsLoading();\n const isInitiallyLoading = list.loader.useIsInitiallyLoading();\n const isLoadingMore = list.loader.useIsLoadingMore();\n\n const { triggerRef, triggerIndex } = useInfiniteScrollTrigger();\n\n const onAction = useLatestOnAction(list);\n\n if (!list.itemView) {\n return null;\n }\n\n const items = list.items.entries.map((item, index) => (\n <Item\n key={item.id}\n data={item.data}\n id={item.id}\n list={list}\n onAction={onAction}\n isTile={tiles}\n triggerRef={index === triggerIndex ? triggerRef : undefined}\n />\n ));\n\n const rootClassName = clsx(\n styles.items,\n isLoading && !(list.infiniteScroll && isLoadingMore) && styles.isLoading,\n tiles && styles.tiles,\n );\n\n const {\n \"aria-labelledby\": ariaLabelledby,\n \"aria-label\": ariaLabel,\n ...rest\n } = list.componentProps;\n\n return (\n <DivView aria-hidden={isInitiallyLoading} aria-busy={isLoading}>\n <ItemsGridListView\n className={rootClassName}\n {...rest}\n aria-labelledby={ariaLabel ? undefined : ariaLabelledby}\n aria-label={ariaLabel}\n layout={tiles ? \"grid\" : \"stack\"}\n tileMaxWidth={list.itemView.tileMaxWidth}\n >\n {items.length === 0 && isInitiallyLoading ? <FallbackItems /> : items}\n </ItemsGridListView>\n </DivView>\n );\n};\n\nexport default Items;\n"],"mappings":";;;;;;;;;;;;;AAWA,IAAa,cAAkB;CAC7B,MAAM,OAAO,QAAQ;CACrB,MAAM,QAAQ,KAAK,SAAS;CAC5B,MAAM,YAAY,KAAK,OAAO,aAAa;CAC3C,MAAM,qBAAqB,KAAK,OAAO,sBAAsB;CAC7D,MAAM,gBAAgB,KAAK,OAAO,iBAAiB;CAEnD,MAAM,EAAE,YAAY,iBAAiB,yBAAyB;CAE9D,MAAM,WAAW,kBAAkB,IAAI;CAEvC,IAAI,CAAC,KAAK,UACR,OAAO;CAGT,MAAM,QAAQ,KAAK,MAAM,QAAQ,KAAK,MAAM,UAC1C,oBAAC,MAAD;EAEE,MAAM,KAAK;EACX,IAAI,KAAK;EACH;EACI;EACV,QAAQ;EACR,YAAY,UAAU,eAAe,aAAa,KAAA;CACnD,GAPM,KAAK,EAOX,CACF;CAED,MAAM,gBAAgB,KACpBA,qBAAO,OACP,aAAa,EAAE,KAAK,kBAAkB,kBAAkBA,qBAAO,WAC/D,SAASA,qBAAO,KAClB;CAEA,MAAM,EACJ,mBAAmB,gBACnB,cAAc,WACd,GAAG,SACD,KAAK;CAET,OACE,oBAAC,SAAD;EAAS,eAAa;EAAoB,aAAW;EACnD,UAAA,oBAAC,mBAAD;GACE,WAAW;GACX,GAAI;GACJ,mBAAiB,YAAY,KAAA,IAAY;GACzC,cAAY;GACZ,QAAQ,QAAQ,SAAS;GACzB,cAAc,KAAK,SAAS;GAE3B,UAAA,MAAM,WAAW,KAAK,qBAAqB,oBAAC,eAAD,CAAgB,CAAA,IAAI;EAC/C,CAAA;CACZ,CAAA;AAEb"}
@@ -36,7 +36,7 @@ var ItemImpl = (props) => {
36
36
  })
37
37
  });
38
38
  };
39
- var Item = memo(ItemImpl, (prev, next) => prev.id === next.id && prev.data === next.data && prev.triggerRef === next.triggerRef && prev.isTile === next.isTile && prev.list.onAction === next.list.onAction && prev.list.accordion === next.list.accordion && !!prev.list.itemView?.rendersSameAs(next.list.itemView));
39
+ var Item = memo(ItemImpl, (prev, next) => prev.id === next.id && prev.data === next.data && prev.triggerRef === next.triggerRef && prev.isTile === next.isTile && !!prev.onAction === !!next.onAction && prev.list.accordion === next.list.accordion && !!prev.list.itemView?.rendersSameFor(next.list.itemView, next.data));
40
40
  Item.displayName = "Item";
41
41
  var ItemContainer = (props) => {
42
42
  const list = useList();
@@ -1 +1 @@
1
- {"version":3,"file":"Item.mjs","names":["styles"],"sources":["../../../../../../../../../../../src/components/List/components/Items/components/Item/Item.tsx"],"sourcesContent":["import { useGridItemProps } from \"@/components/List/components/Items/components/Item/hooks/useGridItemProps\";\nimport { useList } from \"@/components/List/hooks/useList\";\nimport type ListModel from \"@/components/List/model/List\";\nimport ItemsGridListItemView from \"@/views/ItemsGridListItemView\";\nimport { mergeRefs } from \"@react-aria/utils\";\nimport type { FC, PropsWithChildren, Ref } from \"react\";\nimport { memo, Suspense } from \"react\";\nimport type { Key } from \"react-aria-components\";\nimport styles from \"./Item.module.scss\";\nimport { ItemLoadingView } from \"./components/ItemLoadingView/ItemLoadingView\";\n\ninterface Props extends PropsWithChildren {\n id: Key;\n data: never;\n triggerRef?: Ref<HTMLDivElement>;\n list: ListModel<never>;\n isTile: boolean;\n}\n\nconst ItemImpl = (props: Props) => {\n const { id, data, triggerRef, list, isTile } = props;\n\n const itemView = list.itemView;\n\n const { gridItemProps, children } = useGridItemProps(props, list);\n\n if (!itemView) {\n return null;\n }\n\n const textValue = itemView.textValue ? itemView.textValue(data) : undefined;\n const href = itemView.href ? itemView.href(data) : undefined;\n const hasAction = !!gridItemProps.onAction || !!href;\n\n const existingRef = \"ref\" in gridItemProps ? gridItemProps.ref : undefined;\n const gridItemPropsWithRef = triggerRef\n ? { ...gridItemProps, ref: mergeRefs(existingRef, triggerRef) }\n : gridItemProps;\n\n return (\n <ItemsGridListItemView\n id={id}\n textValue={textValue}\n href={href}\n target={itemView.target}\n hasAction={hasAction}\n isTile={isTile}\n {...gridItemPropsWithRef}\n >\n <Suspense fallback={<ItemLoadingView />}>{children}</Suspense>\n </ItemsGridListItemView>\n );\n};\n\n// The list model is rebuilt on every render, so it cannot be compared by\n// identity — but everything an item renders from it can. Those closures come\n// from the consumer's own JSX and only change when the consumer re-renders,\n// so loading more still skips the re-render while parent state no longer\n// leaves an item frozen on the values it first saw.\nexport const Item = memo(\n ItemImpl,\n (prev, next) =>\n prev.id === next.id &&\n prev.data === next.data &&\n prev.triggerRef === next.triggerRef &&\n prev.isTile === next.isTile &&\n prev.list.onAction === next.list.onAction &&\n prev.list.accordion === next.list.accordion &&\n !!prev.list.itemView?.rendersSameAs(next.list.itemView),\n);\nItem.displayName = \"Item\";\n\ninterface ItemContainerProps extends PropsWithChildren {\n id?: Key;\n data?: never;\n}\n\nexport const ItemContainer: FC<ItemContainerProps> = (props) => {\n const list = useList();\n return (\n <ItemsGridListItemView\n textValue=\"-\"\n className={styles.item}\n isTile={list.viewMode.isTiles}\n >\n {props.children}\n </ItemsGridListItemView>\n );\n};\n\nexport default Item;\n"],"mappings":";;;;;;;;;;;AAmBA,IAAM,YAAY,UAAiB;CACjC,MAAM,EAAE,IAAI,MAAM,YAAY,MAAM,WAAW;CAE/C,MAAM,WAAW,KAAK;CAEtB,MAAM,EAAE,eAAe,aAAa,iBAAiB,OAAO,IAAI;CAEhE,IAAI,CAAC,UACH,OAAO;CAGT,MAAM,YAAY,SAAS,YAAY,SAAS,UAAU,IAAI,IAAI,KAAA;CAClE,MAAM,OAAO,SAAS,OAAO,SAAS,KAAK,IAAI,IAAI,KAAA;CACnD,MAAM,YAAY,CAAC,CAAC,cAAc,YAAY,CAAC,CAAC;CAEhD,MAAM,cAAc,SAAS,gBAAgB,cAAc,MAAM,KAAA;CACjE,MAAM,uBAAuB,aACzB;EAAE,GAAG;EAAe,KAAK,UAAU,aAAa,UAAU;CAAE,IAC5D;CAEJ,OACE,oBAAC,uBAAD;EACM;EACO;EACL;EACN,QAAQ,SAAS;EACN;EACH;EACR,GAAI;EAEJ,UAAA,oBAAC,UAAD;GAAU,UAAU,oBAAC,iBAAD,CAAkB,CAAA;GAAI;EAAmB,CAAA;CACxC,CAAA;AAE3B;AAOA,IAAa,OAAO,KAClB,WACC,MAAM,SACL,KAAK,OAAO,KAAK,MACjB,KAAK,SAAS,KAAK,QACnB,KAAK,eAAe,KAAK,cACzB,KAAK,WAAW,KAAK,UACrB,KAAK,KAAK,aAAa,KAAK,KAAK,YACjC,KAAK,KAAK,cAAc,KAAK,KAAK,aAClC,CAAC,CAAC,KAAK,KAAK,UAAU,cAAc,KAAK,KAAK,QAAQ,CAC1D;AACA,KAAK,cAAc;AAOnB,IAAa,iBAAyC,UAAU;CAC9D,MAAM,OAAO,QAAQ;CACrB,OACE,oBAAC,uBAAD;EACE,WAAU;EACV,WAAWA,oBAAO;EAClB,QAAQ,KAAK,SAAS;EAErB,UAAA,MAAM;CACc,CAAA;AAE3B"}
1
+ {"version":3,"file":"Item.mjs","names":["styles"],"sources":["../../../../../../../../../../../src/components/List/components/Items/components/Item/Item.tsx"],"sourcesContent":["import { useGridItemProps } from \"@/components/List/components/Items/components/Item/hooks/useGridItemProps\";\nimport { useList } from \"@/components/List/hooks/useList\";\nimport type ListModel from \"@/components/List/model/List\";\nimport ItemsGridListItemView from \"@/views/ItemsGridListItemView\";\nimport { mergeRefs } from \"@react-aria/utils\";\nimport type { FC, PropsWithChildren, Ref } from \"react\";\nimport { memo, Suspense } from \"react\";\nimport type { Key } from \"react-aria-components\";\nimport styles from \"./Item.module.scss\";\nimport { ItemLoadingView } from \"./components/ItemLoadingView/ItemLoadingView\";\n\ninterface Props extends PropsWithChildren {\n id: Key;\n data: never;\n triggerRef?: Ref<HTMLDivElement>;\n list: ListModel<never>;\n isTile: boolean;\n /** Stable invoker of the list's latest `onAction` */\n onAction?: (data: never) => void;\n}\n\nconst ItemImpl = (props: Props) => {\n const { id, data, triggerRef, list, isTile } = props;\n\n const itemView = list.itemView;\n\n const { gridItemProps, children } = useGridItemProps(props, list);\n\n if (!itemView) {\n return null;\n }\n\n const textValue = itemView.textValue ? itemView.textValue(data) : undefined;\n const href = itemView.href ? itemView.href(data) : undefined;\n const hasAction = !!gridItemProps.onAction || !!href;\n\n const existingRef = \"ref\" in gridItemProps ? gridItemProps.ref : undefined;\n const gridItemPropsWithRef = triggerRef\n ? { ...gridItemProps, ref: mergeRefs(existingRef, triggerRef) }\n : gridItemProps;\n\n return (\n <ItemsGridListItemView\n id={id}\n textValue={textValue}\n href={href}\n target={itemView.target}\n hasAction={hasAction}\n isTile={isTile}\n {...gridItemPropsWithRef}\n >\n <Suspense fallback={<ItemLoadingView />}>{children}</Suspense>\n </ItemsGridListItemView>\n );\n};\n\n// The list model is rebuilt on every render, so it cannot be compared by\n// identity — but everything an item renders from it can. The render function\n// counts by its `renderDependencies`, or else by its identity: an inline one\n// changes whenever the consumer re-renders, so parent state no longer leaves\n// an item frozen on the values it first saw (#3065), while loading more still\n// skips the re-render. `onAction` arrives as a stable invoker of the latest\n// handler, and `textValue`/`href` count by their result.\nexport const Item = memo(\n ItemImpl,\n (prev, next) =>\n prev.id === next.id &&\n prev.data === next.data &&\n prev.triggerRef === next.triggerRef &&\n prev.isTile === next.isTile &&\n !!prev.onAction === !!next.onAction &&\n prev.list.accordion === next.list.accordion &&\n !!prev.list.itemView?.rendersSameFor(next.list.itemView, next.data),\n);\nItem.displayName = \"Item\";\n\ninterface ItemContainerProps extends PropsWithChildren {\n id?: Key;\n data?: never;\n}\n\nexport const ItemContainer: FC<ItemContainerProps> = (props) => {\n const list = useList();\n return (\n <ItemsGridListItemView\n textValue=\"-\"\n className={styles.item}\n isTile={list.viewMode.isTiles}\n >\n {props.children}\n </ItemsGridListItemView>\n );\n};\n\nexport default Item;\n"],"mappings":";;;;;;;;;;;AAqBA,IAAM,YAAY,UAAiB;CACjC,MAAM,EAAE,IAAI,MAAM,YAAY,MAAM,WAAW;CAE/C,MAAM,WAAW,KAAK;CAEtB,MAAM,EAAE,eAAe,aAAa,iBAAiB,OAAO,IAAI;CAEhE,IAAI,CAAC,UACH,OAAO;CAGT,MAAM,YAAY,SAAS,YAAY,SAAS,UAAU,IAAI,IAAI,KAAA;CAClE,MAAM,OAAO,SAAS,OAAO,SAAS,KAAK,IAAI,IAAI,KAAA;CACnD,MAAM,YAAY,CAAC,CAAC,cAAc,YAAY,CAAC,CAAC;CAEhD,MAAM,cAAc,SAAS,gBAAgB,cAAc,MAAM,KAAA;CACjE,MAAM,uBAAuB,aACzB;EAAE,GAAG;EAAe,KAAK,UAAU,aAAa,UAAU;CAAE,IAC5D;CAEJ,OACE,oBAAC,uBAAD;EACM;EACO;EACL;EACN,QAAQ,SAAS;EACN;EACH;EACR,GAAI;EAEJ,UAAA,oBAAC,UAAD;GAAU,UAAU,oBAAC,iBAAD,CAAkB,CAAA;GAAI;EAAmB,CAAA;CACxC,CAAA;AAE3B;AASA,IAAa,OAAO,KAClB,WACC,MAAM,SACL,KAAK,OAAO,KAAK,MACjB,KAAK,SAAS,KAAK,QACnB,KAAK,eAAe,KAAK,cACzB,KAAK,WAAW,KAAK,UACrB,CAAC,CAAC,KAAK,aAAa,CAAC,CAAC,KAAK,YAC3B,KAAK,KAAK,cAAc,KAAK,KAAK,aAClC,CAAC,CAAC,KAAK,KAAK,UAAU,eAAe,KAAK,KAAK,UAAU,KAAK,IAAI,CACtE;AACA,KAAK,cAAc;AAOnB,IAAa,iBAAyC,UAAU;CAC9D,MAAM,OAAO,QAAQ;CACrB,OACE,oBAAC,uBAAD;EACE,WAAU;EACV,WAAWA,oBAAO;EAClB,QAAQ,KAAK,SAAS;EAErB,UAAA,MAAM;CACc,CAAA;AAE3B"}
@@ -7,9 +7,8 @@ import { useEffect, useId, useRef, useState } from "react";
7
7
  import { jsx } from "react/jsx-runtime";
8
8
  //#region src/components/List/components/Items/components/Item/hooks/useGridItemProps.tsx
9
9
  var useGridItemProps = (props, list) => {
10
- const { data, children: childrenFromProps } = props;
10
+ const { data, onAction, children: childrenFromProps } = props;
11
11
  const itemView = list.itemView;
12
- const onAction = list.onAction;
13
12
  const [isExpanded, setIsExpanded] = useState(itemView?.defaultExpanded?.(data) ?? false);
14
13
  const contentElementId = useId();
15
14
  const itemRef = useRef(null);
@@ -1 +1 @@
1
- {"version":3,"file":"useGridItemProps.mjs","names":[],"sources":["../../../../../../../../../../../../src/components/List/components/Items/components/Item/hooks/useGridItemProps.tsx"],"sourcesContent":["import type { PropsWithChildren } from \"react\";\nimport { useEffect, useId, useRef, useState } from \"react\";\nimport type List from \"@/components/List/model/List\";\nimport type { PropsContext } from \"@/lib/propsContext\";\nimport { dynamic, PropsContextProvider } from \"@/lib/propsContext\";\nimport { AccordionButton } from \"@/components/List/components/Items/components/Item/components/AccordionButton\";\n\ninterface P extends PropsWithChildren {\n data: never;\n}\n\nexport const useGridItemProps = (props: P, list: List<never>) => {\n const { data, children: childrenFromProps } = props;\n const itemView = list.itemView;\n const onAction = list.onAction;\n\n const [isExpanded, setIsExpanded] = useState(\n itemView?.defaultExpanded?.(data) ?? false,\n );\n const contentElementId = useId();\n const itemRef = useRef<HTMLDivElement>(null);\n\n const accordion = list.accordion;\n const children = childrenFromProps ?? itemView?.render(data);\n\n useEffect(() => {\n if (accordion) {\n itemRef.current?.setAttribute(\"aria-expanded\", String(isExpanded));\n itemRef.current?.setAttribute(\"aria-controls\", contentElementId);\n }\n }, [isExpanded, contentElementId, itemRef.current, accordion]);\n\n if (!accordion) {\n return {\n gridItemProps: {\n onAction: onAction\n ? () => {\n onAction?.(data);\n }\n : undefined,\n },\n children,\n };\n }\n\n const toggleAccordion = () => {\n setIsExpanded((current) => !current);\n onAction?.(data);\n };\n\n const propsContext: PropsContext = {\n Content: {\n id: dynamic((p) => (p.slot === \"bottom\" ? contentElementId : undefined)),\n wrapWith: dynamic((p) =>\n p.slot === \"bottom\" ? (\n <AccordionButton\n contentElementId={contentElementId}\n toggle={toggleAccordion}\n isExpanded={isExpanded}\n />\n ) : undefined,\n ),\n },\n };\n\n return {\n gridItemProps: {\n ref: itemRef,\n onAction: toggleAccordion,\n },\n children: (\n <PropsContextProvider\n props={propsContext}\n dependencies={[contentElementId, isExpanded]}\n >\n {children}\n </PropsContextProvider>\n ),\n };\n};\n"],"mappings":";;;;;;;;AAWA,IAAa,oBAAoB,OAAU,SAAsB;CAC/D,MAAM,EAAE,MAAM,UAAU,sBAAsB;CAC9C,MAAM,WAAW,KAAK;CACtB,MAAM,WAAW,KAAK;CAEtB,MAAM,CAAC,YAAY,iBAAiB,SAClC,UAAU,kBAAkB,IAAI,KAAK,KACvC;CACA,MAAM,mBAAmB,MAAM;CAC/B,MAAM,UAAU,OAAuB,IAAI;CAE3C,MAAM,YAAY,KAAK;CACvB,MAAM,WAAW,qBAAqB,UAAU,OAAO,IAAI;CAE3D,gBAAgB;EACd,IAAI,WAAW;GACb,QAAQ,SAAS,aAAa,iBAAiB,OAAO,UAAU,CAAC;GACjE,QAAQ,SAAS,aAAa,iBAAiB,gBAAgB;EACjE;CACF,GAAG;EAAC;EAAY;EAAkB,QAAQ;EAAS;CAAS,CAAC;CAE7D,IAAI,CAAC,WACH,OAAO;EACL,eAAe,EACb,UAAU,iBACA;GACJ,WAAW,IAAI;EACjB,IACA,KAAA,EACN;EACA;CACF;CAGF,MAAM,wBAAwB;EAC5B,eAAe,YAAY,CAAC,OAAO;EACnC,WAAW,IAAI;CACjB;CAEA,MAAM,eAA6B,EACjC,SAAS;EACP,IAAI,SAAS,MAAO,EAAE,SAAS,WAAW,mBAAmB,KAAA,CAAU;EACvE,UAAU,SAAS,MACjB,EAAE,SAAS,WACT,oBAAC,iBAAD;GACoB;GAClB,QAAQ;GACI;EACb,CAAA,IACC,KAAA,CACN;CACF,EACF;CAEA,OAAO;EACL,eAAe;GACb,KAAK;GACL,UAAU;EACZ;EACA,UACE,oBAAC,sBAAD;GACE,OAAO;GACP,cAAc,CAAC,kBAAkB,UAAU;GAE1C;EACmB,CAAA;CAE1B;AACF"}
1
+ {"version":3,"file":"useGridItemProps.mjs","names":[],"sources":["../../../../../../../../../../../../src/components/List/components/Items/components/Item/hooks/useGridItemProps.tsx"],"sourcesContent":["import type { PropsWithChildren } from \"react\";\nimport { useEffect, useId, useRef, useState } from \"react\";\nimport type List from \"@/components/List/model/List\";\nimport type { PropsContext } from \"@/lib/propsContext\";\nimport { dynamic, PropsContextProvider } from \"@/lib/propsContext\";\nimport { AccordionButton } from \"@/components/List/components/Items/components/Item/components/AccordionButton\";\n\ninterface P extends PropsWithChildren {\n data: never;\n onAction?: (data: never) => void;\n}\n\nexport const useGridItemProps = (props: P, list: List<never>) => {\n const { data, onAction, children: childrenFromProps } = props;\n const itemView = list.itemView;\n\n const [isExpanded, setIsExpanded] = useState(\n itemView?.defaultExpanded?.(data) ?? false,\n );\n const contentElementId = useId();\n const itemRef = useRef<HTMLDivElement>(null);\n\n const accordion = list.accordion;\n const children = childrenFromProps ?? itemView?.render(data);\n\n useEffect(() => {\n if (accordion) {\n itemRef.current?.setAttribute(\"aria-expanded\", String(isExpanded));\n itemRef.current?.setAttribute(\"aria-controls\", contentElementId);\n }\n }, [isExpanded, contentElementId, itemRef.current, accordion]);\n\n if (!accordion) {\n return {\n gridItemProps: {\n onAction: onAction\n ? () => {\n onAction?.(data);\n }\n : undefined,\n },\n children,\n };\n }\n\n const toggleAccordion = () => {\n setIsExpanded((current) => !current);\n onAction?.(data);\n };\n\n const propsContext: PropsContext = {\n Content: {\n id: dynamic((p) => (p.slot === \"bottom\" ? contentElementId : undefined)),\n wrapWith: dynamic((p) =>\n p.slot === \"bottom\" ? (\n <AccordionButton\n contentElementId={contentElementId}\n toggle={toggleAccordion}\n isExpanded={isExpanded}\n />\n ) : undefined,\n ),\n },\n };\n\n return {\n gridItemProps: {\n ref: itemRef,\n onAction: toggleAccordion,\n },\n children: (\n <PropsContextProvider\n props={propsContext}\n dependencies={[contentElementId, isExpanded]}\n >\n {children}\n </PropsContextProvider>\n ),\n };\n};\n"],"mappings":";;;;;;;;AAYA,IAAa,oBAAoB,OAAU,SAAsB;CAC/D,MAAM,EAAE,MAAM,UAAU,UAAU,sBAAsB;CACxD,MAAM,WAAW,KAAK;CAEtB,MAAM,CAAC,YAAY,iBAAiB,SAClC,UAAU,kBAAkB,IAAI,KAAK,KACvC;CACA,MAAM,mBAAmB,MAAM;CAC/B,MAAM,UAAU,OAAuB,IAAI;CAE3C,MAAM,YAAY,KAAK;CACvB,MAAM,WAAW,qBAAqB,UAAU,OAAO,IAAI;CAE3D,gBAAgB;EACd,IAAI,WAAW;GACb,QAAQ,SAAS,aAAa,iBAAiB,OAAO,UAAU,CAAC;GACjE,QAAQ,SAAS,aAAa,iBAAiB,gBAAgB;EACjE;CACF,GAAG;EAAC;EAAY;EAAkB,QAAQ;EAAS;CAAS,CAAC;CAE7D,IAAI,CAAC,WACH,OAAO;EACL,eAAe,EACb,UAAU,iBACA;GACJ,WAAW,IAAI;EACjB,IACA,KAAA,EACN;EACA;CACF;CAGF,MAAM,wBAAwB;EAC5B,eAAe,YAAY,CAAC,OAAO;EACnC,WAAW,IAAI;CACjB;CAEA,MAAM,eAA6B,EACjC,SAAS;EACP,IAAI,SAAS,MAAO,EAAE,SAAS,WAAW,mBAAmB,KAAA,CAAU;EACvE,UAAU,SAAS,MACjB,EAAE,SAAS,WACT,oBAAC,iBAAD;GACoB;GAClB,QAAQ;GACI;EACb,CAAA,IACC,KAAA,CACN;CACF,EACF;CAEA,OAAO;EACL,eAAe;GACb,KAAK;GACL,UAAU;EACZ;EACA,UACE,oBAAC,sBAAD;GACE,OAAO;GACP,cAAc,CAAC,kBAAkB,UAAU;GAE1C;EACmB,CAAA;CAE1B;AACF"}
@@ -2,14 +2,14 @@
2
2
  /* */
3
3
  import { useList } from "../../hooks/useList.mjs";
4
4
  import { useInfiniteScrollTrigger } from "../../hooks/useInfiniteScrollTrigger.mjs";
5
+ import { useLatestOnAction } from "../../hooks/useLatestOnAction.mjs";
5
6
  import Table_module_default from "./Table.module.mjs";
6
7
  import TableView from "../../../../views/TableView.mjs";
7
8
  import TableHeaderView from "../../../../views/TableHeaderView.mjs";
8
9
  import TableBodyView from "../../../../views/TableBodyView.mjs";
9
- import TableRowView from "../../../../views/TableRowView.mjs";
10
- import TableCellView from "../../../../views/TableCellView.mjs";
11
10
  import TableColumnView from "../../../../views/TableColumnView.mjs";
12
11
  import { TableBodyLoadingView } from "./components/TableBodyLoadingView.mjs";
12
+ import { Row } from "./components/Row.mjs";
13
13
  import clsx from "clsx";
14
14
  import { jsx, jsxs } from "react/jsx-runtime";
15
15
  //#region src/components/List/components/Table/Table.tsx
@@ -21,19 +21,15 @@ var Table = () => {
21
21
  const isInitiallyLoading = list.loader.useIsInitiallyLoading();
22
22
  const isLoadingMore = list.loader.useIsLoadingMore();
23
23
  const { triggerRef, triggerIndex } = useInfiniteScrollTrigger();
24
+ const onAction = useLatestOnAction(list);
24
25
  if (!table || listIsEmpty) return null;
25
- const rowAction = table.list.onAction;
26
26
  const tableClassName = clsx(Table_module_default.table, isLoading && !(list.infiniteScroll && isLoadingMore) && Table_module_default.isLoading, table.componentProps.className);
27
- const rows = list.items.entries.map((item, index) => /* @__PURE__ */ jsx(TableRowView, {
28
- className: clsx(Table_module_default.row, rowAction && Table_module_default.hasAction, table.body.row.componentProps.className),
27
+ const rows = list.items.entries.map((item, index) => /* @__PURE__ */ jsx(Row, {
29
28
  id: item.id,
30
- onAction: rowAction ? () => rowAction(item.data) : void 0,
31
- ...table.body.row.componentProps,
32
- ...index === triggerIndex ? { ref: triggerRef } : {},
33
- children: table.body.row?.cells.map((cell, i) => /* @__PURE__ */ jsx(TableCellView, {
34
- ...cell.componentProps,
35
- children: cell.renderFn ? cell.renderFn(item.data, list) : void 0
36
- }, i))
29
+ data: item.data,
30
+ list,
31
+ onAction,
32
+ triggerRef: index === triggerIndex ? triggerRef : void 0
37
33
  }, item.id));
38
34
  return /* @__PURE__ */ jsxs(TableView, {
39
35
  ...list.componentProps,
@@ -1 +1 @@
1
- {"version":3,"file":"Table.mjs","names":["styles"],"sources":["../../../../../../../../../src/components/List/components/Table/Table.tsx"],"sourcesContent":["import type { FC } from \"react\";\nimport { useList } from \"@/components/List\";\nimport styles from \"./Table.module.scss\";\nimport clsx from \"clsx\";\nimport TableView from \"@/views/TableView\";\nimport TableHeaderView from \"@/views/TableHeaderView\";\nimport TableBodyView from \"@/views/TableBodyView\";\nimport TableRowView from \"@/views/TableRowView\";\nimport TableCellView from \"@/views/TableCellView\";\nimport TableColumnView from \"@/views/TableColumnView\";\nimport { TableBodyLoadingView } from \"@/components/List/components/Table/components/TableBodyLoadingView\";\nimport { useInfiniteScrollTrigger } from \"@/components/List/hooks/useInfiniteScrollTrigger\";\n\nexport const Table: FC = () => {\n const list = useList();\n const table = list.table;\n const listIsEmpty = list.useIsEmpty();\n\n const isLoading = list.loader.useIsLoading();\n const isInitiallyLoading = list.loader.useIsInitiallyLoading();\n const isLoadingMore = list.loader.useIsLoadingMore();\n\n const { triggerRef, triggerIndex } = useInfiniteScrollTrigger();\n\n if (!table || listIsEmpty) {\n return null;\n }\n\n const rowAction = table.list.onAction;\n\n const tableClassName = clsx(\n styles.table,\n isLoading && !(list.infiniteScroll && isLoadingMore) && styles.isLoading,\n table.componentProps.className,\n );\n\n const rows = list.items.entries.map((item, index) => (\n <TableRowView\n className={clsx(\n styles.row,\n rowAction && styles.hasAction,\n table.body.row.componentProps.className,\n )}\n key={item.id}\n id={item.id}\n onAction={rowAction ? () => rowAction(item.data) : undefined}\n {...table.body.row.componentProps}\n {...(index === triggerIndex ? { ref: triggerRef } : {})}\n >\n {table.body.row?.cells.map((cell, i) => (\n <TableCellView key={i} {...cell.componentProps}>\n {cell.renderFn ? cell.renderFn(item.data, list) : undefined}\n </TableCellView>\n ))}\n </TableRowView>\n ));\n\n return (\n <TableView\n {...list.componentProps}\n {...table.componentProps}\n className={tableClassName}\n aria-hidden={isInitiallyLoading}\n aria-busy={isLoading}\n >\n <TableHeaderView {...table.header.componentProps}>\n {table.header.columns.map((col, i) => (\n <TableColumnView key={i} {...col.componentProps} />\n ))}\n </TableHeaderView>\n <TableBodyView {...table.body.componentProps}>\n {isInitiallyLoading ? <TableBodyLoadingView /> : rows}\n </TableBodyView>\n </TableView>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;AAaA,IAAa,cAAkB;CAC7B,MAAM,OAAO,QAAQ;CACrB,MAAM,QAAQ,KAAK;CACnB,MAAM,cAAc,KAAK,WAAW;CAEpC,MAAM,YAAY,KAAK,OAAO,aAAa;CAC3C,MAAM,qBAAqB,KAAK,OAAO,sBAAsB;CAC7D,MAAM,gBAAgB,KAAK,OAAO,iBAAiB;CAEnD,MAAM,EAAE,YAAY,iBAAiB,yBAAyB;CAE9D,IAAI,CAAC,SAAS,aACZ,OAAO;CAGT,MAAM,YAAY,MAAM,KAAK;CAE7B,MAAM,iBAAiB,KACrBA,qBAAO,OACP,aAAa,EAAE,KAAK,kBAAkB,kBAAkBA,qBAAO,WAC/D,MAAM,eAAe,SACvB;CAEA,MAAM,OAAO,KAAK,MAAM,QAAQ,KAAK,MAAM,UACzC,oBAAC,cAAD;EACE,WAAW,KACTA,qBAAO,KACP,aAAaA,qBAAO,WACpB,MAAM,KAAK,IAAI,eAAe,SAChC;EAEA,IAAI,KAAK;EACT,UAAU,kBAAkB,UAAU,KAAK,IAAI,IAAI,KAAA;EACnD,GAAI,MAAM,KAAK,IAAI;EACnB,GAAK,UAAU,eAAe,EAAE,KAAK,WAAW,IAAI,CAAC;EAEpD,UAAA,MAAM,KAAK,KAAK,MAAM,KAAK,MAAM,MAChC,oBAAC,eAAD;GAAuB,GAAI,KAAK;GAC7B,UAAA,KAAK,WAAW,KAAK,SAAS,KAAK,MAAM,IAAI,IAAI,KAAA;EACrC,GAFK,CAEL,CAChB;CACW,GAXP,KAAK,EAWE,CACf;CAED,OACE,qBAAC,WAAD;EACE,GAAI,KAAK;EACT,GAAI,MAAM;EACV,WAAW;EACX,eAAa;EACb,aAAW;EALb,UAAA,CAOE,oBAAC,iBAAD;GAAiB,GAAI,MAAM,OAAO;GAC/B,UAAA,MAAM,OAAO,QAAQ,KAAK,KAAK,MAC9B,oBAAC,iBAAD,EAAyB,GAAI,IAAI,eAAiB,GAA5B,CAA4B,CACnD;EACc,CAAA,GACjB,oBAAC,eAAD;GAAe,GAAI,MAAM,KAAK;GAC3B,UAAA,qBAAqB,oBAAC,sBAAD,CAAuB,CAAA,IAAI;EACpC,CAAA,CACN;;AAEf"}
1
+ {"version":3,"file":"Table.mjs","names":["styles"],"sources":["../../../../../../../../../src/components/List/components/Table/Table.tsx"],"sourcesContent":["import type { FC } from \"react\";\nimport { useList } from \"@/components/List\";\nimport styles from \"./Table.module.scss\";\nimport clsx from \"clsx\";\nimport TableView from \"@/views/TableView\";\nimport TableHeaderView from \"@/views/TableHeaderView\";\nimport TableBodyView from \"@/views/TableBodyView\";\nimport TableColumnView from \"@/views/TableColumnView\";\nimport { TableBodyLoadingView } from \"@/components/List/components/Table/components/TableBodyLoadingView\";\nimport { useInfiniteScrollTrigger } from \"@/components/List/hooks/useInfiniteScrollTrigger\";\nimport { useLatestOnAction } from \"@/components/List/hooks/useLatestOnAction\";\nimport { Row } from \"@/components/List/components/Table/components/Row\";\n\nexport const Table: FC = () => {\n const list = useList();\n const table = list.table;\n const listIsEmpty = list.useIsEmpty();\n\n const isLoading = list.loader.useIsLoading();\n const isInitiallyLoading = list.loader.useIsInitiallyLoading();\n const isLoadingMore = list.loader.useIsLoadingMore();\n\n const { triggerRef, triggerIndex } = useInfiniteScrollTrigger();\n const onAction = useLatestOnAction(list);\n\n if (!table || listIsEmpty) {\n return null;\n }\n\n const tableClassName = clsx(\n styles.table,\n isLoading && !(list.infiniteScroll && isLoadingMore) && styles.isLoading,\n table.componentProps.className,\n );\n\n const rows = list.items.entries.map((item, index) => (\n <Row\n key={item.id}\n id={item.id}\n data={item.data}\n list={list}\n onAction={onAction}\n triggerRef={index === triggerIndex ? triggerRef : undefined}\n />\n ));\n\n return (\n <TableView\n {...list.componentProps}\n {...table.componentProps}\n className={tableClassName}\n aria-hidden={isInitiallyLoading}\n aria-busy={isLoading}\n >\n <TableHeaderView {...table.header.componentProps}>\n {table.header.columns.map((col, i) => (\n <TableColumnView key={i} {...col.componentProps} />\n ))}\n </TableHeaderView>\n <TableBodyView {...table.body.componentProps}>\n {isInitiallyLoading ? <TableBodyLoadingView /> : rows}\n </TableBodyView>\n </TableView>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;AAaA,IAAa,cAAkB;CAC7B,MAAM,OAAO,QAAQ;CACrB,MAAM,QAAQ,KAAK;CACnB,MAAM,cAAc,KAAK,WAAW;CAEpC,MAAM,YAAY,KAAK,OAAO,aAAa;CAC3C,MAAM,qBAAqB,KAAK,OAAO,sBAAsB;CAC7D,MAAM,gBAAgB,KAAK,OAAO,iBAAiB;CAEnD,MAAM,EAAE,YAAY,iBAAiB,yBAAyB;CAC9D,MAAM,WAAW,kBAAkB,IAAI;CAEvC,IAAI,CAAC,SAAS,aACZ,OAAO;CAGT,MAAM,iBAAiB,KACrBA,qBAAO,OACP,aAAa,EAAE,KAAK,kBAAkB,kBAAkBA,qBAAO,WAC/D,MAAM,eAAe,SACvB;CAEA,MAAM,OAAO,KAAK,MAAM,QAAQ,KAAK,MAAM,UACzC,oBAAC,KAAD;EAEE,IAAI,KAAK;EACT,MAAM,KAAK;EACL;EACI;EACV,YAAY,UAAU,eAAe,aAAa,KAAA;CACnD,GANM,KAAK,EAMX,CACF;CAED,OACE,qBAAC,WAAD;EACE,GAAI,KAAK;EACT,GAAI,MAAM;EACV,WAAW;EACX,eAAa;EACb,aAAW;EALb,UAAA,CAOE,oBAAC,iBAAD;GAAiB,GAAI,MAAM,OAAO;GAC/B,UAAA,MAAM,OAAO,QAAQ,KAAK,KAAK,MAC9B,oBAAC,iBAAD,EAAyB,GAAI,IAAI,eAAiB,GAA5B,CAA4B,CACnD;EACc,CAAA,GACjB,oBAAC,eAAD;GAAe,GAAI,MAAM,KAAK;GAC3B,UAAA,qBAAqB,oBAAC,sBAAD,CAAuB,CAAA,IAAI;EACpC,CAAA,CACN;;AAEf"}
@@ -0,0 +1,31 @@
1
+ "use client"
2
+ /* */
3
+ import Table_module_default from "../Table.module.mjs";
4
+ import TableRowView from "../../../../../views/TableRowView.mjs";
5
+ import TableCellView from "../../../../../views/TableCellView.mjs";
6
+ import clsx from "clsx";
7
+ import { memo } from "react";
8
+ import { jsx } from "react/jsx-runtime";
9
+ //#region src/components/List/components/Table/components/Row.tsx
10
+ var RowImpl = (props) => {
11
+ const { id, data, list, onAction, triggerRef } = props;
12
+ const row = list.table?.body.row;
13
+ if (!row) return null;
14
+ return /* @__PURE__ */ jsx(TableRowView, {
15
+ ...row.componentProps,
16
+ className: clsx(Table_module_default.row, onAction && Table_module_default.hasAction, row.componentProps.className),
17
+ id,
18
+ onAction: onAction ? () => onAction(data) : void 0,
19
+ ...triggerRef ? { ref: triggerRef } : {},
20
+ children: row.cells.map((cell, i) => /* @__PURE__ */ jsx(TableCellView, {
21
+ ...cell.componentProps,
22
+ children: cell.renderFn ? cell.renderFn(data, list) : void 0
23
+ }, i))
24
+ });
25
+ };
26
+ var Row = memo(RowImpl, (prev, next) => prev.id === next.id && prev.data === next.data && prev.triggerRef === next.triggerRef && !!prev.onAction === !!next.onAction && !!prev.list.table?.body.row.rendersSameAs(next.list.table?.body.row));
27
+ Row.displayName = "Row";
28
+ //#endregion
29
+ export { Row, Row as default };
30
+
31
+ //# sourceMappingURL=Row.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Row.mjs","names":["styles"],"sources":["../../../../../../../../../../src/components/List/components/Table/components/Row.tsx"],"sourcesContent":["import type { Ref } from \"react\";\nimport { memo } from \"react\";\nimport clsx from \"clsx\";\nimport type { Key } from \"react-aria-components\";\nimport type ListModel from \"@/components/List/model/List\";\nimport TableRowView from \"@/views/TableRowView\";\nimport TableCellView from \"@/views/TableCellView\";\nimport styles from \"../Table.module.scss\";\n\ninterface Props {\n id: Key;\n data: never;\n list: ListModel<never>;\n /** Stable invoker of the list's latest `onAction` */\n onAction?: (data: never) => void;\n triggerRef?: Ref<HTMLTableRowElement>;\n}\n\nconst RowImpl = (props: Props) => {\n const { id, data, list, onAction, triggerRef } = props;\n const row = list.table?.body.row;\n\n if (!row) {\n return null;\n }\n\n return (\n <TableRowView\n {...row.componentProps}\n className={clsx(\n styles.row,\n onAction && styles.hasAction,\n row.componentProps.className,\n )}\n id={id}\n onAction={onAction ? () => onAction(data) : undefined}\n {...(triggerRef ? { ref: triggerRef } : {})}\n >\n {row.cells.map((cell, i) => (\n <TableCellView key={i} {...cell.componentProps}>\n {cell.renderFn ? cell.renderFn(data, list) : undefined}\n </TableCellView>\n ))}\n </TableRowView>\n );\n};\n\n// The list model is rebuilt on every render, so it cannot be compared by\n// identity. A row that declares `renderDependencies` re-renders only when its data,\n// those dependencies or a cell's props change — the cells' render functions\n// count by the dependencies. Without them, rows re-render with the list.\nexport const Row = memo(\n RowImpl,\n (prev, next) =>\n prev.id === next.id &&\n prev.data === next.data &&\n prev.triggerRef === next.triggerRef &&\n !!prev.onAction === !!next.onAction &&\n !!prev.list.table?.body.row.rendersSameAs(next.list.table?.body.row),\n);\nRow.displayName = \"Row\";\n\nexport default Row;\n"],"mappings":";;;;;;;;;AAkBA,IAAM,WAAW,UAAiB;CAChC,MAAM,EAAE,IAAI,MAAM,MAAM,UAAU,eAAe;CACjD,MAAM,MAAM,KAAK,OAAO,KAAK;CAE7B,IAAI,CAAC,KACH,OAAO;CAGT,OACE,oBAAC,cAAD;EACE,GAAI,IAAI;EACR,WAAW,KACTA,qBAAO,KACP,YAAYA,qBAAO,WACnB,IAAI,eAAe,SACrB;EACI;EACJ,UAAU,iBAAiB,SAAS,IAAI,IAAI,KAAA;EAC5C,GAAK,aAAa,EAAE,KAAK,WAAW,IAAI,CAAC;EAExC,UAAA,IAAI,MAAM,KAAK,MAAM,MACpB,oBAAC,eAAD;GAAuB,GAAI,KAAK;GAC7B,UAAA,KAAK,WAAW,KAAK,SAAS,MAAM,IAAI,IAAI,KAAA;EAChC,GAFK,CAEL,CAChB;CACW,CAAA;AAElB;AAMA,IAAa,MAAM,KACjB,UACC,MAAM,SACL,KAAK,OAAO,KAAK,MACjB,KAAK,SAAS,KAAK,QACnB,KAAK,eAAe,KAAK,cACzB,CAAC,CAAC,KAAK,aAAa,CAAC,CAAC,KAAK,YAC3B,CAAC,CAAC,KAAK,KAAK,OAAO,KAAK,IAAI,cAAc,KAAK,KAAK,OAAO,KAAK,GAAG,CACvE;AACA,IAAI,cAAc"}
@@ -0,0 +1,21 @@
1
+ "use client"
2
+ /* */
3
+ import { useCallback, useLayoutEffect, useRef } from "react";
4
+ //#region src/components/List/hooks/useLatestOnAction.ts
5
+ /**
6
+ * A stable invoker of the list's latest `onAction`, or `undefined` without one.
7
+ * An event handler only ever needs to be the latest one, so items and rows do
8
+ * not re-render for an inline `onAction`.
9
+ */
10
+ var useLatestOnAction = (list) => {
11
+ const onActionRef = useRef(list.onAction);
12
+ useLayoutEffect(() => {
13
+ onActionRef.current = list.onAction;
14
+ });
15
+ const invokeOnAction = useCallback((data) => onActionRef.current?.(data), []);
16
+ return list.onAction ? invokeOnAction : void 0;
17
+ };
18
+ //#endregion
19
+ export { useLatestOnAction };
20
+
21
+ //# sourceMappingURL=useLatestOnAction.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLatestOnAction.mjs","names":[],"sources":["../../../../../../../../src/components/List/hooks/useLatestOnAction.ts"],"sourcesContent":["import { useCallback, useLayoutEffect, useRef } from \"react\";\nimport type List from \"@/components/List/model/List\";\n\n/**\n * A stable invoker of the list's latest `onAction`, or `undefined` without one.\n * An event handler only ever needs to be the latest one, so items and rows do\n * not re-render for an inline `onAction`.\n */\nexport const useLatestOnAction = (list: List<never>) => {\n const onActionRef = useRef(list.onAction);\n useLayoutEffect(() => {\n onActionRef.current = list.onAction;\n });\n const invokeOnAction = useCallback(\n (data: never) => onActionRef.current?.(data),\n [],\n );\n return list.onAction ? invokeOnAction : undefined;\n};\n"],"mappings":";;;;;;;;;AAQA,IAAa,qBAAqB,SAAsB;CACtD,MAAM,cAAc,OAAO,KAAK,QAAQ;CACxC,sBAAsB;EACpB,YAAY,UAAU,KAAK;CAC7B,CAAC;CACD,MAAM,iBAAiB,aACpB,SAAgB,YAAY,UAAU,IAAI,GAC3C,CAAC,CACH;CACA,OAAO,KAAK,WAAW,iBAAiB,KAAA;AAC1C"}
@@ -43,6 +43,7 @@ var List = class List {
43
43
  const { settingStorageKey, itemView, table, filters = [], sorting = [], batchesController, onChange, loader, search, onAction, getItemId, defaultViewMode, accordion = false, infiniteScroll = false, loadingItemsCount = 5, settingsStorageDefaults, emptyView, emptySearchResultView, ...componentProps } = shape;
44
44
  const warnDeprecation = useWarnDeprecation();
45
45
  if (itemView?.fallback !== void 0) warnDeprecation("The 'fallback' prop is deprecated and will be removed in a future release. Use 'loadingView' instead.");
46
+ if (itemView?.dependencies !== void 0) warnDeprecation("The 'dependencies' prop of 'List.Item' is deprecated and will be removed in a future release. Use 'renderDependencies' instead.");
46
47
  this.settingsStorageDefaults = settingsStorageDefaults;
47
48
  const generalSettingsStore = useSettings();
48
49
  this.settingsStorage = settingStorageKey && generalSettingsStore ? new ListSettingsStore(this, generalSettingsStore, { storageKey: settingStorageKey }) : void 0;
@@ -1 +1 @@
1
- {"version":3,"file":"List.mjs","names":["BatchesController"],"sources":["../../../../../../../../src/components/List/model/List.ts"],"sourcesContent":["import { ItemCollection } from \"@/components/List/model/item/ItemCollection\";\nimport { BatchesController } from \"@/components/List/model/pagination/BatchesController\";\nimport { Filter } from \"./filter/Filter\";\nimport { Sorting } from \"@/components/List/model/sorting/Sorting\";\nimport ReactTable from \"@/components/List/model/ReactTable\";\nimport type {\n EmptyViewType,\n GetItemId,\n ItemActionFn,\n ListSettingsStorageDefaults,\n ListShape,\n ListSupportedComponentProps,\n} from \"@/components/List/model/types\";\nimport { IncrementalLoader } from \"@/components/List/model/loading/IncrementalLoader\";\nimport invariant from \"invariant\";\nimport { Search } from \"@/components/List/model/search/Search\";\nimport { ItemView } from \"@/components/List/model/item/ItemView\";\nimport { Table } from \"@/components/List/model/table/Table\";\nimport { useEffect, type ReactNode } from \"react\";\nimport { ListSettingsStore } from \"./ListSettingsStore\";\nimport { ListViewMode } from \"./ListViewMode\";\nimport { useSettings } from \"@/components/SettingsProvider/SettingsProvider\";\nimport { DateRangeFilter } from \"@/components/List/model/filter/DateRangeFilter\";\nimport { useWarnDeprecation } from \"@/components/DeprecationWarningProvider\";\nimport type {\n ListModelContext,\n ListSettingsPort,\n} from \"@mittwald/flow-components-base\";\nimport type { Table as ReactTableInstance } from \"@tanstack/table-core\";\n\nexport class List<T = unknown, TMeta = unknown> implements ListModelContext<T> {\n public readonly filters: (\n Filter<T, never, never> | DateRangeFilter<T, never>\n )[];\n public readonly itemView?: ItemView<T>;\n public readonly table?: Table<T>;\n public readonly search?: Search<T>;\n public readonly sorting: Sorting<T>[];\n public readonly items: ItemCollection<T>;\n public readonly reactTable: ReactTable<T>;\n public readonly batches: BatchesController<T>;\n public readonly loader: IncrementalLoader<T>;\n public readonly onAction?: ItemActionFn<T>;\n public readonly accordion: boolean;\n public readonly infiniteScroll: boolean;\n public readonly getItemId?: GetItemId<T>;\n public readonly componentProps: ListSupportedComponentProps;\n public metadata?: TMeta;\n public readonly settingsStorage?: ListSettingsStore<T>;\n public readonly loadingItemsCount;\n public readonly viewMode: ListViewMode<T>;\n public readonly emptyView?: ReactNode;\n public readonly emptySearchResultView?: ReactNode;\n public readonly settingsStorageDefaults?: ListSettingsStorageDefaults;\n\n public constructor(shape: ListShape<T, TMeta>) {\n const {\n settingStorageKey,\n itemView,\n table,\n filters = [],\n sorting = [],\n batchesController,\n onChange,\n loader,\n search,\n onAction,\n getItemId,\n defaultViewMode,\n accordion = false,\n infiniteScroll = false,\n loadingItemsCount = 5,\n settingsStorageDefaults,\n emptyView,\n emptySearchResultView,\n ...componentProps\n } = shape;\n\n const warnDeprecation = useWarnDeprecation();\n if (itemView?.fallback !== undefined) {\n warnDeprecation(\n \"The 'fallback' prop is deprecated and will be removed in a future release. Use 'loadingView' instead.\",\n );\n }\n\n this.settingsStorageDefaults = settingsStorageDefaults;\n const generalSettingsStore = useSettings();\n\n this.settingsStorage =\n settingStorageKey && generalSettingsStore\n ? new ListSettingsStore(this, generalSettingsStore, {\n storageKey: settingStorageKey,\n })\n : undefined;\n\n this.items = new ItemCollection(this);\n this.filters = filters.map((shape) =>\n shape.mode === \"dateRange\"\n ? new DateRangeFilter(this, shape)\n : new Filter(this, shape),\n );\n this.sorting = sorting.map((shape) => new Sorting<T>(this, shape));\n this.search = search ? new Search(this, search) : undefined;\n this.itemView = itemView ? new ItemView(this, itemView) : undefined;\n this.accordion = accordion;\n this.infiniteScroll = infiniteScroll;\n this.table = table ? new Table(this, table) : undefined;\n this.batches = new BatchesController(this, batchesController);\n\n /*\n * The controller no longer subscribes itself: the filters and the search\n * are this list's, and handing a list of concrete filters to a shared\n * model is the `Table<never>` variance trap. `IncrementalLoader` still\n * subscribes in its own constructor, which runs right after this, so the\n * order of the two resets is unchanged.\n */\n this.filters.forEach((f) => f.onFilterUpdated(() => this.batches.reset()));\n this.search?.onUpdated(() => this.batches.reset());\n this.componentProps = componentProps;\n /*\n * Before the loader: its state takes `getItemId` over in its constructor,\n * and a loader built first would never deduplicate.\n */\n this.getItemId = getItemId;\n this.loader = IncrementalLoader.useNew<T>(this, loader);\n this.onAction = onAction;\n this.loadingItemsCount = loadingItemsCount;\n this.reactTable = ReactTable.useNew(this, onChange, {\n manualFiltering: this.loader.manualFiltering,\n manualPagination: this.loader.manualPagination,\n manualSorting: this.loader.manualSorting,\n });\n this.viewMode = ListViewMode.useNew(this, { defaultViewMode });\n this.emptyView = emptyView;\n this.emptySearchResultView = emptySearchResultView;\n\n useEffect(() => {\n this.filters.forEach((f) => f.deleteUnknownFilterValues());\n }, [this.filters]);\n }\n\n /*\n * `ListModelContext` — what the shared model in\n * `@mittwald/flow-components-base` reaches for, so `Sorting` and `Search` can\n * keep being handed the list itself. Getters, because the model is built\n * before the table is.\n */\n public get dataTable(): ReactTableInstance<T> {\n return this.reactTable.table;\n }\n\n public get settings(): ListSettingsPort | undefined {\n return this.settingsStorage;\n }\n\n public get settingsDefaults(): ListSettingsStorageDefaults | undefined {\n return this.settingsStorageDefaults;\n }\n\n public getEmptyViewType(): EmptyViewType {\n return this.hasActiveFilters || this.search?.isSet ? \"search\" : \"list\";\n }\n\n public get hasActiveFilters(): boolean {\n return this.filters.some((f) => f.isActive());\n }\n\n public get visibleSorting() {\n return this.sorting.filter((s) => s.initialEnabled !== \"hidden\");\n }\n\n public static useNew<T, TMeta = unknown>(\n shape: ListShape<T, TMeta>,\n ): List<T, TMeta> {\n return new List<T, TMeta>(shape);\n }\n\n public getSorting(id: string): Sorting<T> {\n const sorting = this.sorting.find((s) => s.id === id);\n invariant(!!sorting, `Could not get Sorting (ID: ${id})`);\n return sorting;\n }\n\n public clearSorting(): void {\n return this.sorting.forEach((s) => s.clear());\n }\n\n public resetFilters(): void {\n return this.filters.forEach((f) => f.resetValues());\n }\n\n public clearFilters(): void {\n return this.filters.forEach((f) => f.clear());\n }\n\n public useIsEmpty(): boolean {\n return !this.loader.useIsLoading() && this.items.entries.length === 0;\n }\n}\n\nexport default List;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA8BA,IAAa,OAAb,MAAa,KAAkE;CAC7E;CAGA;CACA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AAa,KAAK,KAAK,MAAM,QAAQ,WAAW;CACtE;AACF"}
1
+ {"version":3,"file":"List.mjs","names":["BatchesController"],"sources":["../../../../../../../../src/components/List/model/List.ts"],"sourcesContent":["import { ItemCollection } from \"@/components/List/model/item/ItemCollection\";\nimport { BatchesController } from \"@/components/List/model/pagination/BatchesController\";\nimport { Filter } from \"./filter/Filter\";\nimport { Sorting } from \"@/components/List/model/sorting/Sorting\";\nimport ReactTable from \"@/components/List/model/ReactTable\";\nimport type {\n EmptyViewType,\n GetItemId,\n ItemActionFn,\n ListSettingsStorageDefaults,\n ListShape,\n ListSupportedComponentProps,\n} from \"@/components/List/model/types\";\nimport { IncrementalLoader } from \"@/components/List/model/loading/IncrementalLoader\";\nimport invariant from \"invariant\";\nimport { Search } from \"@/components/List/model/search/Search\";\nimport { ItemView } from \"@/components/List/model/item/ItemView\";\nimport { Table } from \"@/components/List/model/table/Table\";\nimport { useEffect, type ReactNode } from \"react\";\nimport { ListSettingsStore } from \"./ListSettingsStore\";\nimport { ListViewMode } from \"./ListViewMode\";\nimport { useSettings } from \"@/components/SettingsProvider/SettingsProvider\";\nimport { DateRangeFilter } from \"@/components/List/model/filter/DateRangeFilter\";\nimport { useWarnDeprecation } from \"@/components/DeprecationWarningProvider\";\nimport type {\n ListModelContext,\n ListSettingsPort,\n} from \"@mittwald/flow-components-base\";\nimport type { Table as ReactTableInstance } from \"@tanstack/table-core\";\n\nexport class List<T = unknown, TMeta = unknown> implements ListModelContext<T> {\n public readonly filters: (\n Filter<T, never, never> | DateRangeFilter<T, never>\n )[];\n public readonly itemView?: ItemView<T>;\n public readonly table?: Table<T>;\n public readonly search?: Search<T>;\n public readonly sorting: Sorting<T>[];\n public readonly items: ItemCollection<T>;\n public readonly reactTable: ReactTable<T>;\n public readonly batches: BatchesController<T>;\n public readonly loader: IncrementalLoader<T>;\n public readonly onAction?: ItemActionFn<T>;\n public readonly accordion: boolean;\n public readonly infiniteScroll: boolean;\n public readonly getItemId?: GetItemId<T>;\n public readonly componentProps: ListSupportedComponentProps;\n public metadata?: TMeta;\n public readonly settingsStorage?: ListSettingsStore<T>;\n public readonly loadingItemsCount;\n public readonly viewMode: ListViewMode<T>;\n public readonly emptyView?: ReactNode;\n public readonly emptySearchResultView?: ReactNode;\n public readonly settingsStorageDefaults?: ListSettingsStorageDefaults;\n\n public constructor(shape: ListShape<T, TMeta>) {\n const {\n settingStorageKey,\n itemView,\n table,\n filters = [],\n sorting = [],\n batchesController,\n onChange,\n loader,\n search,\n onAction,\n getItemId,\n defaultViewMode,\n accordion = false,\n infiniteScroll = false,\n loadingItemsCount = 5,\n settingsStorageDefaults,\n emptyView,\n emptySearchResultView,\n ...componentProps\n } = shape;\n\n const warnDeprecation = useWarnDeprecation();\n if (itemView?.fallback !== undefined) {\n warnDeprecation(\n \"The 'fallback' prop is deprecated and will be removed in a future release. Use 'loadingView' instead.\",\n );\n }\n if (itemView?.dependencies !== undefined) {\n warnDeprecation(\n \"The 'dependencies' prop of 'List.Item' is deprecated and will be removed in a future release. Use 'renderDependencies' instead.\",\n );\n }\n\n this.settingsStorageDefaults = settingsStorageDefaults;\n const generalSettingsStore = useSettings();\n\n this.settingsStorage =\n settingStorageKey && generalSettingsStore\n ? new ListSettingsStore(this, generalSettingsStore, {\n storageKey: settingStorageKey,\n })\n : undefined;\n\n this.items = new ItemCollection(this);\n this.filters = filters.map((shape) =>\n shape.mode === \"dateRange\"\n ? new DateRangeFilter(this, shape)\n : new Filter(this, shape),\n );\n this.sorting = sorting.map((shape) => new Sorting<T>(this, shape));\n this.search = search ? new Search(this, search) : undefined;\n this.itemView = itemView ? new ItemView(this, itemView) : undefined;\n this.accordion = accordion;\n this.infiniteScroll = infiniteScroll;\n this.table = table ? new Table(this, table) : undefined;\n this.batches = new BatchesController(this, batchesController);\n\n /*\n * The controller no longer subscribes itself: the filters and the search\n * are this list's, and handing a list of concrete filters to a shared\n * model is the `Table<never>` variance trap. `IncrementalLoader` still\n * subscribes in its own constructor, which runs right after this, so the\n * order of the two resets is unchanged.\n */\n this.filters.forEach((f) => f.onFilterUpdated(() => this.batches.reset()));\n this.search?.onUpdated(() => this.batches.reset());\n this.componentProps = componentProps;\n /*\n * Before the loader: its state takes `getItemId` over in its constructor,\n * and a loader built first would never deduplicate.\n */\n this.getItemId = getItemId;\n this.loader = IncrementalLoader.useNew<T>(this, loader);\n this.onAction = onAction;\n this.loadingItemsCount = loadingItemsCount;\n this.reactTable = ReactTable.useNew(this, onChange, {\n manualFiltering: this.loader.manualFiltering,\n manualPagination: this.loader.manualPagination,\n manualSorting: this.loader.manualSorting,\n });\n this.viewMode = ListViewMode.useNew(this, { defaultViewMode });\n this.emptyView = emptyView;\n this.emptySearchResultView = emptySearchResultView;\n\n useEffect(() => {\n this.filters.forEach((f) => f.deleteUnknownFilterValues());\n }, [this.filters]);\n }\n\n /*\n * `ListModelContext` — what the shared model in\n * `@mittwald/flow-components-base` reaches for, so `Sorting` and `Search` can\n * keep being handed the list itself. Getters, because the model is built\n * before the table is.\n */\n public get dataTable(): ReactTableInstance<T> {\n return this.reactTable.table;\n }\n\n public get settings(): ListSettingsPort | undefined {\n return this.settingsStorage;\n }\n\n public get settingsDefaults(): ListSettingsStorageDefaults | undefined {\n return this.settingsStorageDefaults;\n }\n\n public getEmptyViewType(): EmptyViewType {\n return this.hasActiveFilters || this.search?.isSet ? \"search\" : \"list\";\n }\n\n public get hasActiveFilters(): boolean {\n return this.filters.some((f) => f.isActive());\n }\n\n public get visibleSorting() {\n return this.sorting.filter((s) => s.initialEnabled !== \"hidden\");\n }\n\n public static useNew<T, TMeta = unknown>(\n shape: ListShape<T, TMeta>,\n ): List<T, TMeta> {\n return new List<T, TMeta>(shape);\n }\n\n public getSorting(id: string): Sorting<T> {\n const sorting = this.sorting.find((s) => s.id === id);\n invariant(!!sorting, `Could not get Sorting (ID: ${id})`);\n return sorting;\n }\n\n public clearSorting(): void {\n return this.sorting.forEach((s) => s.clear());\n }\n\n public resetFilters(): void {\n return this.filters.forEach((f) => f.resetValues());\n }\n\n public clearFilters(): void {\n return this.filters.forEach((f) => f.clear());\n }\n\n public useIsEmpty(): boolean {\n return !this.loader.useIsLoading() && this.items.entries.length === 0;\n }\n}\n\nexport default List;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA8BA,IAAa,OAAb,MAAa,KAAkE;CAC7E;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,YAAmB,OAA4B;EAC7C,MAAM,EACJ,mBACA,UACA,OACA,UAAU,CAAC,GACX,UAAU,CAAC,GACX,mBACA,UACA,QACA,QACA,UACA,WACA,iBACA,YAAY,OACZ,iBAAiB,OACjB,oBAAoB,GACpB,yBACA,WACA,uBACA,GAAG,mBACD;EAEJ,MAAM,kBAAkB,mBAAmB;EAC3C,IAAI,UAAU,aAAa,KAAA,GACzB,gBACE,uGACF;EAEF,IAAI,UAAU,iBAAiB,KAAA,GAC7B,gBACE,iIACF;EAGF,KAAK,0BAA0B;EAC/B,MAAM,uBAAuB,YAAY;EAEzC,KAAK,kBACH,qBAAqB,uBACjB,IAAI,kBAAkB,MAAM,sBAAsB,EAChD,YAAY,kBACd,CAAC,IACD,KAAA;EAEN,KAAK,QAAQ,IAAI,eAAe,IAAI;EACpC,KAAK,UAAU,QAAQ,KAAK,UAC1B,MAAM,SAAS,cACX,IAAI,gBAAgB,MAAM,KAAK,IAC/B,IAAI,OAAO,MAAM,KAAK,CAC5B;EACA,KAAK,UAAU,QAAQ,KAAK,UAAU,IAAI,QAAW,MAAM,KAAK,CAAC;EACjE,KAAK,SAAS,SAAS,IAAI,OAAO,MAAM,MAAM,IAAI,KAAA;EAClD,KAAK,WAAW,WAAW,IAAI,SAAS,MAAM,QAAQ,IAAI,KAAA;EAC1D,KAAK,YAAY;EACjB,KAAK,iBAAiB;EACtB,KAAK,QAAQ,QAAQ,IAAI,MAAM,MAAM,KAAK,IAAI,KAAA;EAC9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