@dnb/eufemia 10.48.0 → 10.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/cjs/components/height-animation/HeightAnimationInstance.d.ts +1 -0
  3. package/cjs/components/height-animation/HeightAnimationInstance.js +13 -6
  4. package/cjs/components/height-animation/HeightAnimationInstance.js.map +1 -1
  5. package/cjs/extensions/forms/DataContext/Context.d.ts +6 -4
  6. package/cjs/extensions/forms/DataContext/Context.js +1 -2
  7. package/cjs/extensions/forms/DataContext/Context.js.map +1 -1
  8. package/cjs/extensions/forms/DataContext/FieldBoundary/FieldBoundaryContext.d.ts +4 -0
  9. package/cjs/extensions/forms/DataContext/FieldBoundary/FieldBoundaryContext.js.map +1 -1
  10. package/cjs/extensions/forms/DataContext/FieldBoundary/FieldBoundaryProvider.js +13 -4
  11. package/cjs/extensions/forms/DataContext/FieldBoundary/FieldBoundaryProvider.js.map +1 -1
  12. package/cjs/extensions/forms/DataContext/Provider/Provider.d.ts +0 -4
  13. package/cjs/extensions/forms/DataContext/Provider/Provider.js +27 -28
  14. package/cjs/extensions/forms/DataContext/Provider/Provider.js.map +1 -1
  15. package/cjs/extensions/forms/Form/Isolation/Isolation.js +5 -4
  16. package/cjs/extensions/forms/Form/Isolation/Isolation.js.map +1 -1
  17. package/cjs/extensions/forms/Iterate/Array/Array.js +12 -6
  18. package/cjs/extensions/forms/Iterate/Array/Array.js.map +1 -1
  19. package/cjs/extensions/forms/Iterate/Array/ArrayDocs.js +6 -1
  20. package/cjs/extensions/forms/Iterate/Array/ArrayDocs.js.map +1 -1
  21. package/cjs/extensions/forms/Iterate/Array/ArrayItemArea.d.ts +1 -1
  22. package/cjs/extensions/forms/Iterate/Array/ArrayItemArea.js.map +1 -1
  23. package/cjs/extensions/forms/Iterate/Array/types.d.ts +1 -0
  24. package/cjs/extensions/forms/Iterate/Array/types.js.map +1 -1
  25. package/cjs/extensions/forms/Iterate/EditContainer/DoneButton.js +0 -1
  26. package/cjs/extensions/forms/Iterate/EditContainer/DoneButton.js.map +1 -1
  27. package/cjs/extensions/forms/Iterate/PushButton/PushButton.js +19 -7
  28. package/cjs/extensions/forms/Iterate/PushButton/PushButton.js.map +1 -1
  29. package/cjs/extensions/forms/Iterate/PushContainer/OpenButton.js +18 -2
  30. package/cjs/extensions/forms/Iterate/PushContainer/OpenButton.js.map +1 -1
  31. package/cjs/extensions/forms/Iterate/PushContainer/PushContainer.d.ts +2 -1
  32. package/cjs/extensions/forms/Iterate/PushContainer/PushContainer.js.map +1 -1
  33. package/cjs/extensions/forms/Iterate/PushContainer/PushContainerDocs.js +5 -0
  34. package/cjs/extensions/forms/Iterate/PushContainer/PushContainerDocs.js.map +1 -1
  35. package/cjs/extensions/forms/Iterate/RemoveButton/RemoveButton.js +3 -5
  36. package/cjs/extensions/forms/Iterate/RemoveButton/RemoveButton.js.map +1 -1
  37. package/cjs/extensions/forms/Wizard/Step/Step.d.ts +1 -1
  38. package/cjs/extensions/forms/Wizard/Step/Step.js.map +1 -1
  39. package/cjs/extensions/forms/hooks/useFieldProps.js +20 -14
  40. package/cjs/extensions/forms/hooks/useFieldProps.js.map +1 -1
  41. package/cjs/shared/Eufemia.d.ts +1 -1
  42. package/cjs/shared/Eufemia.js +2 -2
  43. package/cjs/shared/Eufemia.js.map +1 -1
  44. package/cjs/style/core/scopes.scss +1 -1
  45. package/cjs/style/dnb-ui-basis.css +1 -1
  46. package/cjs/style/dnb-ui-basis.min.css +1 -1
  47. package/cjs/style/dnb-ui-body.css +1 -1
  48. package/cjs/style/dnb-ui-body.min.css +1 -1
  49. package/cjs/style/dnb-ui-core.css +1 -1
  50. package/cjs/style/dnb-ui-core.min.css +1 -1
  51. package/components/height-animation/HeightAnimationInstance.d.ts +1 -0
  52. package/components/height-animation/HeightAnimationInstance.js +13 -6
  53. package/components/height-animation/HeightAnimationInstance.js.map +1 -1
  54. package/es/components/height-animation/HeightAnimationInstance.d.ts +1 -0
  55. package/es/components/height-animation/HeightAnimationInstance.js +13 -6
  56. package/es/components/height-animation/HeightAnimationInstance.js.map +1 -1
  57. package/es/extensions/forms/DataContext/Context.d.ts +6 -4
  58. package/es/extensions/forms/DataContext/Context.js +1 -2
  59. package/es/extensions/forms/DataContext/Context.js.map +1 -1
  60. package/es/extensions/forms/DataContext/FieldBoundary/FieldBoundaryContext.d.ts +4 -0
  61. package/es/extensions/forms/DataContext/FieldBoundary/FieldBoundaryContext.js.map +1 -1
  62. package/es/extensions/forms/DataContext/FieldBoundary/FieldBoundaryProvider.js +13 -4
  63. package/es/extensions/forms/DataContext/FieldBoundary/FieldBoundaryProvider.js.map +1 -1
  64. package/es/extensions/forms/DataContext/Provider/Provider.d.ts +0 -4
  65. package/es/extensions/forms/DataContext/Provider/Provider.js +27 -26
  66. package/es/extensions/forms/DataContext/Provider/Provider.js.map +1 -1
  67. package/es/extensions/forms/Form/Isolation/Isolation.js +5 -4
  68. package/es/extensions/forms/Form/Isolation/Isolation.js.map +1 -1
  69. package/es/extensions/forms/Iterate/Array/Array.js +14 -8
  70. package/es/extensions/forms/Iterate/Array/Array.js.map +1 -1
  71. package/es/extensions/forms/Iterate/Array/ArrayDocs.js +6 -1
  72. package/es/extensions/forms/Iterate/Array/ArrayDocs.js.map +1 -1
  73. package/es/extensions/forms/Iterate/Array/ArrayItemArea.d.ts +1 -1
  74. package/es/extensions/forms/Iterate/Array/ArrayItemArea.js.map +1 -1
  75. package/es/extensions/forms/Iterate/Array/types.d.ts +1 -0
  76. package/es/extensions/forms/Iterate/Array/types.js.map +1 -1
  77. package/es/extensions/forms/Iterate/EditContainer/DoneButton.js +0 -1
  78. package/es/extensions/forms/Iterate/EditContainer/DoneButton.js.map +1 -1
  79. package/es/extensions/forms/Iterate/PushButton/PushButton.js +20 -8
  80. package/es/extensions/forms/Iterate/PushButton/PushButton.js.map +1 -1
  81. package/es/extensions/forms/Iterate/PushContainer/OpenButton.js +19 -3
  82. package/es/extensions/forms/Iterate/PushContainer/OpenButton.js.map +1 -1
  83. package/es/extensions/forms/Iterate/PushContainer/PushContainer.d.ts +2 -1
  84. package/es/extensions/forms/Iterate/PushContainer/PushContainer.js.map +1 -1
  85. package/es/extensions/forms/Iterate/PushContainer/PushContainerDocs.js +5 -0
  86. package/es/extensions/forms/Iterate/PushContainer/PushContainerDocs.js.map +1 -1
  87. package/es/extensions/forms/Iterate/RemoveButton/RemoveButton.js +4 -6
  88. package/es/extensions/forms/Iterate/RemoveButton/RemoveButton.js.map +1 -1
  89. package/es/extensions/forms/Wizard/Step/Step.d.ts +1 -1
  90. package/es/extensions/forms/Wizard/Step/Step.js.map +1 -1
  91. package/es/extensions/forms/hooks/useFieldProps.js +20 -14
  92. package/es/extensions/forms/hooks/useFieldProps.js.map +1 -1
  93. package/es/shared/Eufemia.d.ts +1 -1
  94. package/es/shared/Eufemia.js +2 -2
  95. package/es/shared/Eufemia.js.map +1 -1
  96. package/es/style/core/scopes.scss +1 -1
  97. package/es/style/dnb-ui-basis.css +1 -1
  98. package/es/style/dnb-ui-basis.min.css +1 -1
  99. package/es/style/dnb-ui-body.css +1 -1
  100. package/es/style/dnb-ui-body.min.css +1 -1
  101. package/es/style/dnb-ui-core.css +1 -1
  102. package/es/style/dnb-ui-core.min.css +1 -1
  103. package/esm/dnb-ui-basis.min.mjs +1 -1
  104. package/esm/dnb-ui-components.min.mjs +1 -1
  105. package/esm/dnb-ui-elements.min.mjs +1 -1
  106. package/esm/dnb-ui-extensions.min.mjs +2 -2
  107. package/esm/dnb-ui-lib.min.mjs +1 -1
  108. package/extensions/forms/DataContext/Context.d.ts +6 -4
  109. package/extensions/forms/DataContext/Context.js +1 -2
  110. package/extensions/forms/DataContext/Context.js.map +1 -1
  111. package/extensions/forms/DataContext/FieldBoundary/FieldBoundaryContext.d.ts +4 -0
  112. package/extensions/forms/DataContext/FieldBoundary/FieldBoundaryContext.js.map +1 -1
  113. package/extensions/forms/DataContext/FieldBoundary/FieldBoundaryProvider.js +13 -4
  114. package/extensions/forms/DataContext/FieldBoundary/FieldBoundaryProvider.js.map +1 -1
  115. package/extensions/forms/DataContext/Provider/Provider.d.ts +0 -4
  116. package/extensions/forms/DataContext/Provider/Provider.js +27 -26
  117. package/extensions/forms/DataContext/Provider/Provider.js.map +1 -1
  118. package/extensions/forms/Form/Isolation/Isolation.js +5 -4
  119. package/extensions/forms/Form/Isolation/Isolation.js.map +1 -1
  120. package/extensions/forms/Iterate/Array/Array.js +14 -8
  121. package/extensions/forms/Iterate/Array/Array.js.map +1 -1
  122. package/extensions/forms/Iterate/Array/ArrayDocs.js +6 -1
  123. package/extensions/forms/Iterate/Array/ArrayDocs.js.map +1 -1
  124. package/extensions/forms/Iterate/Array/ArrayItemArea.d.ts +1 -1
  125. package/extensions/forms/Iterate/Array/ArrayItemArea.js.map +1 -1
  126. package/extensions/forms/Iterate/Array/types.d.ts +1 -0
  127. package/extensions/forms/Iterate/Array/types.js.map +1 -1
  128. package/extensions/forms/Iterate/EditContainer/DoneButton.js +0 -1
  129. package/extensions/forms/Iterate/EditContainer/DoneButton.js.map +1 -1
  130. package/extensions/forms/Iterate/PushButton/PushButton.js +20 -8
  131. package/extensions/forms/Iterate/PushButton/PushButton.js.map +1 -1
  132. package/extensions/forms/Iterate/PushContainer/OpenButton.js +19 -3
  133. package/extensions/forms/Iterate/PushContainer/OpenButton.js.map +1 -1
  134. package/extensions/forms/Iterate/PushContainer/PushContainer.d.ts +2 -1
  135. package/extensions/forms/Iterate/PushContainer/PushContainer.js.map +1 -1
  136. package/extensions/forms/Iterate/PushContainer/PushContainerDocs.js +5 -0
  137. package/extensions/forms/Iterate/PushContainer/PushContainerDocs.js.map +1 -1
  138. package/extensions/forms/Iterate/RemoveButton/RemoveButton.js +4 -6
  139. package/extensions/forms/Iterate/RemoveButton/RemoveButton.js.map +1 -1
  140. package/extensions/forms/Wizard/Step/Step.d.ts +1 -1
  141. package/extensions/forms/Wizard/Step/Step.js.map +1 -1
  142. package/extensions/forms/hooks/useFieldProps.js +20 -14
  143. package/extensions/forms/hooks/useFieldProps.js.map +1 -1
  144. package/package.json +1 -1
  145. package/shared/Eufemia.d.ts +1 -1
  146. package/shared/Eufemia.js +2 -2
  147. package/shared/Eufemia.js.map +1 -1
  148. package/style/core/scopes.scss +1 -1
  149. package/style/dnb-ui-basis.css +1 -1
  150. package/style/dnb-ui-basis.min.css +1 -1
  151. package/style/dnb-ui-body.css +1 -1
  152. package/style/dnb-ui-body.min.css +1 -1
  153. package/style/dnb-ui-core.css +1 -1
  154. package/style/dnb-ui-core.min.css +1 -1
  155. package/umd/dnb-ui-basis.min.js +1 -1
  156. package/umd/dnb-ui-components.min.js +1 -1
  157. package/umd/dnb-ui-elements.min.js +1 -1
  158. package/umd/dnb-ui-extensions.min.js +2 -2
  159. package/umd/dnb-ui-lib.min.js +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"Isolation.js","names":["React","useCallback","useContext","useEffect","useMemo","useReducer","useRef","pointer","extendDeep","useDataValue","Context","Provider","SectionContext","IsolationCommitButton","clearedData","structuredClone","IsolationProvider","props","children","onPathChange","onCommit","onCommitProp","onClear","onClearProp","transformOnCommit","transformOnCommitProp","commitHandleRef","data","defaultData","forceUpdate","internalDataRef","localDataRef","dataContextRef","outerContext","path","pathSection","handlePathChange","handlePathChangeOuter","dataOuter","moveValueToPath","onPathChangeHandler","value","current","set","replace","removeSectionPath","has","get","getMountedData","_dataContextRef$curre","mounterData","mountedFieldPathsRef","forEach","localData","Object","assign","additionalArgs","_props$path","mountedData","outerData","isolatedData","Array","isArray","providerProps","_objectSpread","isolate","createElement","Consumer","dataContext","handleSubmit","CommitButton","_supportsSpacingProps","undefined"],"sources":["../../../../../../src/extensions/forms/Form/Isolation/Isolation.tsx"],"sourcesContent":["import React, {\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useReducer,\n useRef,\n} from 'react'\nimport pointer, { JsonObject } from 'json-pointer'\nimport { extendDeep } from '../../../../shared/component-helper'\nimport useDataValue from '../../hooks/useDataValue'\nimport { Context, ContextState, Provider } from '../../DataContext'\nimport SectionContext from '../Section/SectionContext'\nimport IsolationCommitButton from './IsolationCommitButton'\nimport {\n clearedData,\n type Props as ProviderProps,\n} from '../../DataContext/Provider'\nimport type { OnCommit, Path } from '../../types'\n\n/**\n * Deprecated, as it is supported by all major browsers and Node.js >=v18\n * So its a question of time, when we will remove this polyfill\n */\nimport structuredClone from '@ungap/structured-clone'\n\nexport type IsolationProviderProps<Data> = {\n /**\n * Form.Isolation: Will be called when the isolated context is committed.\n */\n onCommit?: OnCommit<Data>\n /**\n * Form.Isolation: Will be called when the form is cleared via Form.clearData\n */\n onClear?: () => void\n /**\n * Form.Isolation: A function that will be called when the isolated context is committed.\n * It will receive the data from the isolated context and the data from the outer context.\n * You can use this to transform the data before it is committed.\n */\n transformOnCommit?: (isolatedData: Data, handlerData: Data) => Data\n /**\n * Used internally by the Form.Isolation component\n */\n path?: Path\n /**\n * Used internally by the Form.Isolation component\n */\n isolate?: boolean\n}\n\nexport type IsolationProps<Data> = Omit<\n ProviderProps<Data>,\n | 'onSubmit'\n | 'onSubmitRequest'\n | 'onSubmitComplete'\n | 'minimumAsyncBehaviorTime'\n | 'asyncSubmitTimeout'\n | 'scrollTopOnSubmit'\n | 'sessionStorageId'\n | 'globalStatusId'\n> & {\n /**\n * A ref (function) that you can call in order to commit the data programmatically to the outer context.\n */\n commitHandleRef?: React.MutableRefObject<() => void>\n}\n\nfunction IsolationProvider<Data extends JsonObject>(\n props: IsolationProps<Data>\n) {\n const {\n children,\n onPathChange,\n onCommit: onCommitProp,\n onClear: onClearProp,\n transformOnCommit: transformOnCommitProp,\n commitHandleRef,\n data,\n defaultData,\n } = props\n\n const [, forceUpdate] = useReducer(() => ({}), {})\n const internalDataRef = useRef<Data>()\n const localDataRef = useRef<Partial<Data>>({})\n const dataContextRef = useRef<ContextState>(null)\n const outerContext = useContext(Context)\n const { path: pathSection } = useContext(SectionContext) || {}\n const { handlePathChange: handlePathChangeOuter, data: dataOuter } =\n outerContext || {}\n const { moveValueToPath } = useDataValue()\n\n const onPathChangeHandler = useCallback(\n async (path: Path, value: unknown) => {\n if (localDataRef.current === clearedData) {\n localDataRef.current = {}\n }\n\n pointer.set(localDataRef.current, path, value)\n\n if (pathSection) {\n path = path.replace(pathSection, '')\n }\n\n return await onPathChange?.(path, value)\n },\n [onPathChange, pathSection]\n )\n\n const removeSectionPath = useCallback(\n (data: Data) => {\n return pathSection && pointer.has(data, pathSection)\n ? pointer.get(data, pathSection)\n : data\n },\n [pathSection]\n )\n\n const getMountedData = useCallback((data: Data) => {\n const mounterData = {} as Data\n dataContextRef.current?.mountedFieldPathsRef.current.forEach(\n (path) => {\n if (pointer.has(data, path)) {\n pointer.set(mounterData, path, pointer.get(data, path))\n }\n }\n )\n return mounterData\n }, [])\n\n useEffect(() => {\n localDataRef.current = getMountedData(internalDataRef.current)\n }, [getMountedData])\n\n // Update the isolated data with the outside context data\n useMemo(() => {\n if (localDataRef.current === clearedData) {\n return // stop here\n }\n\n let localData = data ?? defaultData\n\n if (\n localData &&\n pathSection &&\n !pointer.has(localDataRef.current, pathSection)\n ) {\n localData = moveValueToPath<Data>(pathSection, localData)\n }\n\n internalDataRef.current = Object.assign(\n {},\n localData || dataOuter || {},\n localDataRef.current\n )\n }, [data, defaultData, pathSection, dataOuter, moveValueToPath])\n\n const onCommit: IsolationProps<Data>['onCommit'] = useCallback(\n async (data: Data, additionalArgs) => {\n const mountedData = getMountedData(data)\n const path = props.path ?? '/'\n const outerData =\n props.path && pointer.has(dataOuter, path)\n ? pointer.get(dataOuter, path)\n : dataOuter\n\n localDataRef.current = mountedData\n let isolatedData = structuredClone(mountedData) as Data\n\n if (typeof transformOnCommitProp === 'function') {\n isolatedData = transformOnCommitProp(isolatedData, outerData)\n }\n\n // Commit the internal data to the nested context data\n handlePathChangeOuter?.(\n path,\n Array.isArray(isolatedData)\n ? isolatedData\n : extendDeep({}, outerData, isolatedData)\n )\n\n return await onCommitProp?.(\n removeSectionPath(isolatedData),\n additionalArgs\n )\n },\n [\n getMountedData,\n props.path,\n dataOuter,\n transformOnCommitProp,\n handlePathChangeOuter,\n onCommitProp,\n removeSectionPath,\n ]\n )\n\n const onClear = useCallback(() => {\n localDataRef.current = clearedData\n internalDataRef.current = clearedData as Data\n forceUpdate()\n onClearProp?.()\n }, [onClearProp])\n\n const providerProps: IsolationProps<Data> = {\n ...props,\n [defaultData ? 'defaultData' : 'data']: internalDataRef.current,\n onPathChange: onPathChangeHandler,\n onCommit,\n onClear,\n isolate: true,\n }\n\n return (\n <Provider {...providerProps}>\n <Context.Consumer>\n {(dataContext) => {\n dataContextRef.current = dataContext\n\n if (commitHandleRef) {\n commitHandleRef.current = dataContext?.handleSubmit\n }\n\n return children\n }}\n </Context.Consumer>\n </Provider>\n )\n}\n\nIsolationProvider.CommitButton = IsolationCommitButton\nIsolationProvider._supportsSpacingProps = undefined\n\nexport default IsolationProvider\n"],"mappings":";;;;;AAAA,OAAOA,KAAK,IACVC,WAAW,EACXC,UAAU,EACVC,SAAS,EACTC,OAAO,EACPC,UAAU,EACVC,MAAM,QACD,OAAO;AACd,OAAOC,OAAO,MAAsB,cAAc;AAClD,SAASC,UAAU,QAAQ,qCAAqC;AAChE,OAAOC,YAAY,MAAM,0BAA0B;AACnD,SAASC,OAAO,EAAgBC,QAAQ,QAAQ,mBAAmB;AACnE,OAAOC,cAAc,MAAM,2BAA2B;AACtD,OAAOC,qBAAqB,MAAM,yBAAyB;AAC3D,SACEC,WAAW,QAEN,4BAA4B;AAOnC,OAAOC,eAAe,MAAM,yBAAyB;AA4CrD,SAASC,iBAAiBA,CACxBC,KAA2B,EAC3B;EACA,MAAM;IACJC,QAAQ;IACRC,YAAY;IACZC,QAAQ,EAAEC,YAAY;IACtBC,OAAO,EAAEC,WAAW;IACpBC,iBAAiB,EAAEC,qBAAqB;IACxCC,eAAe;IACfC,IAAI;IACJC;EACF,CAAC,GAAGX,KAAK;EAET,MAAM,G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MAAM;IAChC8B,YAAY,CAACW,OAAO,GAAG5B,WAAW;IAClCgB,eAAe,CAACY,OAAO,GAAG5B,WAAmB;IAC7Ce,WAAW,CAAC,CAAC;IACbN,WAAW,aAAXA,WAAW,uBAAXA,WAAW,CAAG,CAAC;EACjB,CAAC,EAAE,CAACA,WAAW,CAAC,CAAC;EAEjB,MAAMwC,aAAmC,GAAAC,aAAA,CAAAA,aAAA,KACpC/C,KAAK;IACR,CAACW,WAAW,GAAG,aAAa,GAAG,MAAM,GAAGE,eAAe,CAACY,OAAO;IAC/DvB,YAAY,EAAEqB,mBAAmB;IACjCpB,QAAQ;IACRE,OAAO;IACP2C,OAAO,EAAE;EAAI,EACd;EAED,OACEjE,KAAA,CAAAkE,aAAA,CAACvD,QAAQ,EAAKoD,aAAa,EACzB/D,KAAA,CAAAkE,aAAA,CAACxD,OAAO,CAACyD,QAAQ,QACbC,WAAW,IAAK;IAChBpC,cAAc,CAACU,OAAO,GAAG0B,WAAW;IAEpC,IAAI1C,eAAe,EAAE;MACnBA,eAAe,CAACgB,OAAO,GAAG0B,WAAW,aAAXA,WAAW,uBAAXA,WAAW,CAAEC,YAAY;IACrD;IAEA,OAAOnD,QAAQ;EACjB,CACgB,CACV,CAAC;AAEf;AAEAF,iBAAiB,CAACsD,YAAY,GAAGzD,qBAAqB;AACtDG,iBAAiB,CAACuD,qBAAqB,GAAGC,SAAS;AAEnD,eAAexD,iBAAiB"}
1
+ {"version":3,"file":"Isolation.js","names":["React","useCallback","useContext","useEffect","useMemo","useReducer","useRef","pointer","extendDeep","useDataValue","Context","Provider","SectionContext","IsolationCommitButton","clearedData","structuredClone","IsolationProvider","props","children","onPathChange","onCommit","onCommitProp","onClear","onClearProp","transformOnCommit","transformOnCommitProp","commitHandleRef","data","defaultData","forceUpdate","internalDataRef","localDataRef","dataContextRef","outerContext","path","pathSection","handlePathChange","handlePathChangeOuter","dataOuter","moveValueToPath","onPathChangeHandler","value","current","set","replace","removeSectionPath","has","get","getMountedData","mounterData","_dataContextRef$curre","mountedFieldsRef","field","isMounted","localData","Object","assign","additionalArgs","_props$path","mountedData","outerData","isolatedData","Array","isArray","providerProps","_objectSpread","isolate","createElement","Consumer","dataContext","handleSubmit","CommitButton","_supportsSpacingProps","undefined"],"sources":["../../../../../../src/extensions/forms/Form/Isolation/Isolation.tsx"],"sourcesContent":["import React, {\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useReducer,\n useRef,\n} from 'react'\nimport pointer, { JsonObject } from 'json-pointer'\nimport { extendDeep } from '../../../../shared/component-helper'\nimport useDataValue from '../../hooks/useDataValue'\nimport { Context, ContextState, Provider } from '../../DataContext'\nimport SectionContext from '../Section/SectionContext'\nimport IsolationCommitButton from './IsolationCommitButton'\nimport {\n clearedData,\n type Props as ProviderProps,\n} from '../../DataContext/Provider'\nimport type { OnCommit, Path } from '../../types'\n\n/**\n * Deprecated, as it is supported by all major browsers and Node.js >=v18\n * So its a question of time, when we will remove this polyfill\n */\nimport structuredClone from '@ungap/structured-clone'\n\nexport type IsolationProviderProps<Data> = {\n /**\n * Form.Isolation: Will be called when the isolated context is committed.\n */\n onCommit?: OnCommit<Data>\n /**\n * Form.Isolation: Will be called when the form is cleared via Form.clearData\n */\n onClear?: () => void\n /**\n * Form.Isolation: A function that will be called when the isolated context is committed.\n * It will receive the data from the isolated context and the data from the outer context.\n * You can use this to transform the data before it is committed.\n */\n transformOnCommit?: (isolatedData: Data, handlerData: Data) => Data\n /**\n * Used internally by the Form.Isolation component\n */\n path?: Path\n /**\n * Used internally by the Form.Isolation component\n */\n isolate?: boolean\n}\n\nexport type IsolationProps<Data> = Omit<\n ProviderProps<Data>,\n | 'onSubmit'\n | 'onSubmitRequest'\n | 'onSubmitComplete'\n | 'minimumAsyncBehaviorTime'\n | 'asyncSubmitTimeout'\n | 'scrollTopOnSubmit'\n | 'sessionStorageId'\n | 'globalStatusId'\n> & {\n /**\n * A ref (function) that you can call in order to commit the data programmatically to the outer context.\n */\n commitHandleRef?: React.MutableRefObject<() => void>\n}\n\nfunction IsolationProvider<Data extends JsonObject>(\n props: IsolationProps<Data>\n) {\n const {\n children,\n onPathChange,\n onCommit: onCommitProp,\n onClear: onClearProp,\n transformOnCommit: transformOnCommitProp,\n commitHandleRef,\n data,\n defaultData,\n } = props\n\n const [, forceUpdate] = useReducer(() => ({}), {})\n const internalDataRef = useRef<Data>()\n const localDataRef = useRef<Partial<Data>>({})\n const dataContextRef = useRef<ContextState>(null)\n const outerContext = useContext(Context)\n const { path: pathSection } = useContext(SectionContext) || {}\n const { handlePathChange: handlePathChangeOuter, data: dataOuter } =\n outerContext || {}\n const { moveValueToPath } = useDataValue()\n\n const onPathChangeHandler = useCallback(\n async (path: Path, value: unknown) => {\n if (localDataRef.current === clearedData) {\n localDataRef.current = {}\n }\n\n pointer.set(localDataRef.current, path, value)\n\n if (pathSection) {\n path = path.replace(pathSection, '')\n }\n\n return await onPathChange?.(path, value)\n },\n [onPathChange, pathSection]\n )\n\n const removeSectionPath = useCallback(\n (data: Data) => {\n return pathSection && pointer.has(data, pathSection)\n ? pointer.get(data, pathSection)\n : data\n },\n [pathSection]\n )\n\n const getMountedData = useCallback((data: Data) => {\n const mounterData = {} as Data\n for (const path in dataContextRef.current?.mountedFieldsRef.current) {\n const field = dataContextRef.current.mountedFieldsRef.current[path]\n if (field.isMounted && pointer.has(data, path)) {\n pointer.set(mounterData, path, pointer.get(data, path))\n }\n }\n return mounterData\n }, [])\n\n useEffect(() => {\n localDataRef.current = getMountedData(internalDataRef.current)\n }, [getMountedData])\n\n // Update the isolated data with the outside context data\n useMemo(() => {\n if (localDataRef.current === clearedData) {\n return // stop here\n }\n\n let localData = data ?? defaultData\n\n if (\n localData &&\n pathSection &&\n !pointer.has(localDataRef.current, pathSection)\n ) {\n localData = moveValueToPath<Data>(pathSection, localData)\n }\n\n internalDataRef.current = Object.assign(\n {},\n localData || dataOuter || {},\n localDataRef.current\n )\n }, [data, defaultData, pathSection, dataOuter, moveValueToPath])\n\n const onCommit: IsolationProps<Data>['onCommit'] = useCallback(\n async (data: Data, additionalArgs) => {\n const mountedData = getMountedData(data)\n const path = props.path ?? '/'\n const outerData =\n props.path && pointer.has(dataOuter, path)\n ? pointer.get(dataOuter, path)\n : dataOuter\n\n localDataRef.current = mountedData\n let isolatedData = structuredClone(mountedData) as Data\n\n if (typeof transformOnCommitProp === 'function') {\n isolatedData = transformOnCommitProp(isolatedData, outerData)\n }\n\n // Commit the internal data to the nested context data\n handlePathChangeOuter?.(\n path,\n Array.isArray(isolatedData)\n ? isolatedData\n : extendDeep({}, outerData, isolatedData)\n )\n\n return await onCommitProp?.(\n removeSectionPath(isolatedData),\n additionalArgs\n )\n },\n [\n getMountedData,\n props.path,\n dataOuter,\n transformOnCommitProp,\n handlePathChangeOuter,\n onCommitProp,\n removeSectionPath,\n ]\n )\n\n const onClear = useCallback(() => {\n localDataRef.current = clearedData\n internalDataRef.current = clearedData as Data\n forceUpdate()\n onClearProp?.()\n }, [onClearProp])\n\n const providerProps: IsolationProps<Data> = {\n ...props,\n [defaultData ? 'defaultData' : 'data']: internalDataRef.current,\n onPathChange: onPathChangeHandler,\n onCommit,\n onClear,\n isolate: true,\n }\n\n return (\n <Provider {...providerProps}>\n <Context.Consumer>\n {(dataContext) => {\n dataContextRef.current = dataContext\n\n if (commitHandleRef) {\n commitHandleRef.current = dataContext?.handleSubmit\n }\n\n return children\n }}\n </Context.Consumer>\n </Provider>\n )\n}\n\nIsolationProvider.CommitButton = IsolationCommitButton\nIsolationProvider._supportsSpacingProps = undefined\n\nexport default IsolationProvider\n"],"mappings":";;;;;AAAA,OAAOA,KAAK,IACVC,WAAW,EACXC,UAAU,EACVC,SAAS,EACTC,OAAO,EACPC,UAAU,EACVC,MAAM,QACD,OAAO;AACd,OAAOC,OAAO,MAAsB,cAAc;AAClD,SAASC,UAAU,QAAQ,qCAAqC;AAChE,OAAOC,YAAY,MAAM,0BAA0B;AACnD,SAASC,OAAO,EAAgBC,QAAQ,QAAQ,mBAAmB;A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,CAAC;AAEf;AAEAF,iBAAiB,CAACuD,YAAY,GAAG1D,qBAAqB;AACtDG,iBAAiB,CAACwD,qBAAqB,GAAGC,SAAS;AAEnD,eAAezD,iBAAiB"}
@@ -3,12 +3,12 @@
3
3
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
4
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
5
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
- import React, { useMemo, useRef, useEffect, useReducer, createRef, useContext, Fragment } from 'react';
6
+ import React, { useMemo, useRef, useEffect, useReducer, createRef, useContext } from 'react';
7
7
  import classnames from 'classnames';
8
8
  import pointer from 'json-pointer';
9
9
  import { useFieldProps } from '../../hooks';
10
10
  import { makeUniqueId } from '../../../../shared/component-helper';
11
- import { Flex, FormStatus } from '../../../../components';
11
+ import { Flex, FormStatus, HeightAnimation } from '../../../../components';
12
12
  import { pickSpacingProps } from '../../../../components/flex/utils';
13
13
  import useMountEffect from '../../../../shared/helpers/useMountEffect';
14
14
  import { pickFlexContainerProps } from '../../../../components/flex/Container';
@@ -54,12 +54,16 @@ function ArrayComponent(props) {
54
54
  index: i
55
55
  }));
56
56
  }
57
- return _objectSpread(_objectSpread({}, props), {}, {
57
+ return _objectSpread(_objectSpread({
58
+ required: false
59
+ }, props), {}, {
58
60
  value: newValue
59
61
  });
60
62
  }
61
63
  }
62
- return props;
64
+ return _objectSpread({
65
+ required: false
66
+ }, props);
63
67
  }, [getValueByPath, props]);
64
68
  const {
65
69
  path,
@@ -70,6 +74,7 @@ function ArrayComponent(props) {
70
74
  emptyValue,
71
75
  placeholder,
72
76
  containerMode,
77
+ animate,
73
78
  handleChange,
74
79
  setChanged,
75
80
  onChange,
@@ -191,8 +196,7 @@ function ArrayComponent(props) {
191
196
  }, pickFlexContainerProps(props)), pickSpacingProps(props)), {}, {
192
197
  innerRef: containerRef
193
198
  });
194
- const WrapperElement = omitFlex ? Fragment : Flex.Stack;
195
- return React.createElement(React.Fragment, null, React.createElement(WrapperElement, omitFlex ? null : flexProps, arrayValue === emptyValue || (props === null || props === void 0 ? void 0 : (_props$value = props.value) === null || _props$value === void 0 ? void 0 : _props$value.length) === 0 ? placeholder : arrayItems.map(itemProps => {
199
+ const arrayElements = arrayValue === emptyValue || (props === null || props === void 0 ? void 0 : (_props$value = props.value) === null || _props$value === void 0 ? void 0 : _props$value.length) === 0 ? placeholder : arrayItems.map(itemProps => {
196
200
  const {
197
201
  id,
198
202
  value,
@@ -220,7 +224,9 @@ function ArrayComponent(props) {
220
224
  }, React.createElement(IterateItemContext.Provider, {
221
225
  value: contextValue
222
226
  }, React.createElement(FieldBoundaryProvider, null, content)));
223
- })), React.createElement(FormStatus, {
227
+ });
228
+ const content = omitFlex ? arrayElements : React.createElement(Flex.Stack, flexProps, arrayElements);
229
+ return React.createElement(React.Fragment, null, animate ? React.createElement(HeightAnimation, null, content) : content, React.createElement(FormStatus, {
224
230
  top: 0,
225
231
  bottom: 0,
226
232
  show: Boolean(error),
@@ -233,6 +239,6 @@ function ArrayComponent(props) {
233
239
  content: error
234
240
  })));
235
241
  }
236
- ArrayComponent._supportsSpacingProps = false;
242
+ ArrayComponent._supportsSpacingProps = true;
237
243
  export default ArrayComponent;
238
244
  //# sourceMappingURL=Array.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Array.js","names":["React","useMemo","useRef","useEffect","useReducer","createRef","useContext","Fragment","classnames","pointer","useFieldProps","makeUniqueId","Flex","FormStatus","pickSpacingProps","useMountEffect","pickFlexContainerProps","IterateItemContext","SummaryListContext","ValueBlockContext","FieldBoundaryProvider","DataContext","useDataValue","useSwitchContainerMode","getMessage","structuredClone","ArrayComponent","props","_props$value","salt","forceUpdate","summaryListContext","valueBlockContext","getValueByPath","preparedProps","path","countPath","countPathLimit","Infinity","countPathTransform","arrayValue","countValue","parseFloat","length","newValue","i","l","value","push","index","_objectSpread","error","defaultValue","withoutFlex","emptyValue","placeholder","containerMode","handleChange","setChanged","onChange","children","idsRef","isNewRef","modesRef","valueWhileClosingRef","valueCountRef","containerRef","hadPushRef","innerRefs","omitFlex","handlePathChange","current","getNextContainerMode","arrayItems","list","map","_valueCountRef$curren","_modesRef$current$id","id","hasNewItems","isNew","_getNextContainerMode","itemContext","previousContainerMode","previous","initialContainerMode","modeOptions","options","switchContainerMode","mode","_isNewRef$current","newArrayValue","set","handlePush","element","handleRemove","keepItems","splice","fulfillRemove","_modesRef$current","_isNewRef$current2","findIndex","indexOf","restoreOriginalValue","last","flexProps","className","innerRef","WrapperElement","Stack","createElement","itemProps","elementRef","renderChildren","elementChild","contextValue","content","Array","isArray","child","Provider","key","Item","tabIndex","top","bottom","show","Boolean","no_animation","shellSpace","_supportsSpacingProps"],"sources":["../../../../../../src/extensions/forms/Iterate/Array/Array.tsx"],"sourcesContent":["import React, {\n useMemo,\n useRef,\n useEffect,\n useReducer,\n createRef,\n useContext,\n Fragment,\n} from 'react'\nimport classnames from 'classnames'\nimport pointer from 'json-pointer'\nimport { useFieldProps } from '../../hooks'\nimport { makeUniqueId } from '../../../../shared/component-helper'\nimport { Flex, FormStatus } from '../../../../components'\nimport { pickSpacingProps } from '../../../../components/flex/utils'\nimport useMountEffect from '../../../../shared/helpers/useMountEffect'\nimport {\n BasicProps as FlexContainerProps,\n Props as FlexContainerAllProps,\n pickFlexContainerProps,\n} from '../../../../components/flex/Container'\nimport IterateItemContext, {\n IterateItemContextState,\n} from '../IterateItemContext'\nimport SummaryListContext from '../../Value/SummaryList/SummaryListContext'\nimport ValueBlockContext from '../../ValueBlock/ValueBlockContext'\nimport FieldBoundaryProvider from '../../DataContext/FieldBoundary/FieldBoundaryProvider'\nimport DataContext from '../../DataContext/Context'\nimport useDataValue from '../../hooks/useDataValue'\nimport { useSwitchContainerMode } from '../hooks'\nimport { getMessage } from '../../FieldBlock'\n\nimport type { ContainerMode, ElementChild, Props, Value } from './types'\nimport type { Identifier } from '../../types'\n\n/**\n * Deprecated, as it is supported by all major browsers and Node.js >=v18\n * So its a question of time, when we will remove this polyfill\n */\nimport structuredClone from '@ungap/structured-clone'\n\nexport type * from './types'\n\nfunction ArrayComponent(props: Props) {\n const [salt, forceUpdate] = useReducer(() => ({}), {})\n\n const summaryListContext = useContext(SummaryListContext)\n const valueBlockContext = useContext(ValueBlockContext)\n\n const { getValueByPath } = useDataValue()\n const preparedProps = useMemo(() => {\n const {\n path,\n countPath,\n countPathLimit = Infinity,\n countPathTransform,\n } = props\n\n if (countPath) {\n const arrayValue = getValueByPath(path)\n let countValue = parseFloat(getValueByPath(countPath))\n if (!(countValue >= 0)) {\n countValue = 0\n }\n if (countValue > countPathLimit) {\n countValue = countPathLimit\n }\n if (arrayValue?.length !== countValue) {\n const newValue = []\n for (let i = 0, l = countValue; i < l; i++) {\n const value = arrayValue?.[i]\n newValue.push(countPathTransform?.({ value, index: i }))\n }\n\n return {\n ...props,\n value: newValue,\n }\n }\n }\n\n return props\n }, [getValueByPath, props])\n\n const {\n path,\n value: arrayValue,\n error,\n defaultValue,\n withoutFlex,\n emptyValue,\n placeholder,\n containerMode,\n handleChange,\n setChanged,\n onChange,\n children,\n } = useFieldProps(preparedProps)\n\n useMountEffect(() => {\n // To ensure the validator is called when a new item is added\n setChanged(true)\n })\n\n const idsRef = useRef<Array<Identifier>>([])\n const isNewRef = useRef<Record<string, boolean>>({})\n const modesRef = useRef<\n Record<\n Identifier,\n {\n current: ContainerMode\n previous?: ContainerMode\n options?: { omitFocusManagement?: boolean }\n }\n >\n >({})\n const valueWhileClosingRef = useRef<Value>()\n const valueCountRef = useRef(arrayValue)\n const containerRef = useRef<HTMLDivElement>()\n const hadPushRef = useRef<boolean>()\n const innerRefs = useRef<\n Record<string, React.RefObject<HTMLDivElement>>\n >({})\n\n const omitFlex = withoutFlex ?? (summaryListContext || valueBlockContext)\n\n // To support React.StrictMode, we inject the defaultValue into the data context this way.\n // The routine inside useFieldProps where updateDataValueDataContext is called, does not support React.StrictMode\n const { handlePathChange } = useContext(DataContext) || {}\n useMountEffect(() => {\n if (defaultValue) {\n handlePathChange?.(path, defaultValue)\n }\n })\n\n useEffect(() => {\n // Update inside the useEffect, to support React.StrictMode\n valueCountRef.current = arrayValue || []\n }, [arrayValue])\n\n const { getNextContainerMode } = useSwitchContainerMode()\n\n const arrayItems = useMemo(() => {\n const list = valueWhileClosingRef.current || arrayValue\n return (list ?? []).map((value, index) => {\n const id = idsRef.current[index] || makeUniqueId()\n\n const hasNewItems =\n arrayValue?.length > valueCountRef.current?.length\n\n if (!idsRef.current[index]) {\n isNewRef.current[id] = hasNewItems\n idsRef.current.push(id)\n }\n\n const isNew = isNewRef.current[id] || false\n if (!modesRef.current[id]?.current) {\n modesRef.current[id] = {\n current:\n containerMode ??\n (isNew ? getNextContainerMode() ?? 'edit' : 'auto'),\n }\n }\n\n const itemContext: IterateItemContextState = {\n id,\n path,\n value,\n index,\n arrayValue,\n containerRef,\n isNew,\n containerMode: modesRef.current[id].current,\n previousContainerMode: modesRef.current[id].previous,\n initialContainerMode: containerMode || 'auto',\n modeOptions: modesRef.current[id].options,\n switchContainerMode: (mode, options = {}) => {\n modesRef.current[id].previous = modesRef.current[id].current\n modesRef.current[id].current = mode\n modesRef.current[id].options = options\n delete isNewRef.current?.[id]\n forceUpdate()\n },\n handleChange: (path, value) => {\n const newArrayValue = structuredClone(arrayValue)\n\n // Make sure we have a new object reference,\n // else two new objects will be the same\n newArrayValue[index] = { ...newArrayValue[index] }\n\n pointer.set(newArrayValue, path, value)\n handleChange(newArrayValue)\n },\n handlePush: (element) => {\n hadPushRef.current = true\n handleChange([...(arrayValue || []), element])\n },\n handleRemove: ({ keepItems = false } = {}) => {\n if (keepItems) {\n // Add a backup as the array value while animating\n valueWhileClosingRef.current = arrayValue\n }\n\n const newArrayValue = structuredClone(arrayValue)\n newArrayValue.splice(index, 1)\n handleChange(newArrayValue)\n },\n\n // - Called after animation end\n fulfillRemove: () => {\n valueWhileClosingRef.current = null\n delete modesRef.current?.[id]\n delete isNewRef.current?.[id]\n const findIndex = idsRef.current.indexOf(id)\n idsRef.current.splice(findIndex, 1)\n forceUpdate()\n },\n\n // - Called when cancel button press\n restoreOriginalValue: (value) => {\n if (value) {\n const newArrayValue = structuredClone(arrayValue)\n newArrayValue[index] = value\n handleChange(newArrayValue)\n }\n },\n }\n\n return itemContext\n })\n\n // In order to update \"valueWhileClosingRef\" we need to have \"salt\" in the deps array\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [salt, arrayValue, path, handleChange])\n\n // - Call the onChange callback when a new element is added without calling \"handlePush\"\n useMemo(() => {\n const last = arrayItems?.[arrayItems.length - 1]\n if (last?.isNew && !hadPushRef.current) {\n onChange?.(arrayValue)\n } else {\n hadPushRef.current = false\n }\n }, [arrayValue, arrayItems, onChange])\n\n const flexProps: FlexContainerProps & {\n innerRef: FlexContainerAllProps['innerRef']\n } = {\n className: classnames(\n 'dnb-forms-iterate',\n 'dnb-forms-section',\n props?.className\n ),\n ...pickFlexContainerProps(props as FlexContainerProps),\n ...pickSpacingProps(props),\n innerRef: containerRef,\n }\n\n const WrapperElement = omitFlex ? Fragment : Flex.Stack\n\n return (\n <>\n <WrapperElement {...(omitFlex ? null : flexProps)}>\n {arrayValue === emptyValue || props?.value?.length === 0\n ? placeholder\n : arrayItems.map((itemProps) => {\n const { id, value, index } = itemProps\n const elementRef = (innerRefs.current[id] =\n innerRefs.current[id] || createRef<HTMLDivElement>())\n\n const renderChildren = (elementChild: ElementChild) => {\n return typeof elementChild === 'function'\n ? elementChild(value, index)\n : elementChild\n }\n\n const contextValue = {\n ...itemProps,\n elementRef,\n }\n\n const content = Array.isArray(children)\n ? children.map((child) => renderChildren(child))\n : renderChildren(children)\n\n if (omitFlex) {\n return (\n <IterateItemContext.Provider\n key={`element-${id}`}\n value={contextValue}\n >\n <FieldBoundaryProvider>\n {content}\n </FieldBoundaryProvider>\n </IterateItemContext.Provider>\n )\n }\n\n return (\n <Flex.Item\n className=\"dnb-forms-iterate__element\"\n tabIndex={-1}\n innerRef={elementRef}\n key={`element-${id}`}\n >\n <IterateItemContext.Provider value={contextValue}>\n <FieldBoundaryProvider>\n {content}\n </FieldBoundaryProvider>\n </IterateItemContext.Provider>\n </Flex.Item>\n )\n })}\n </WrapperElement>\n\n <FormStatus\n top={0}\n bottom={0}\n show={Boolean(error)}\n no_animation={false}\n shellSpace={{ top: true, bottom: true }}\n >\n {getMessage({ content: error })}\n </FormStatus>\n </>\n )\n}\n\nArrayComponent._supportsSpacingProps = false // disable flex support to avoid rerender, which could result in flickering\nexport default ArrayComponent\n"],"mappings":";;;;;AAAA,OAAOA,KAAK,IACVC,OAAO,EACPC,MAAM,EACNC,SAAS,EACTC,UAAU,EACVC,SAAS,EACTC,UAAU,EACVC,QAAQ,QACH,OAAO;AACd,OAAOC,UAAU,MAAM,YAAY;AACnC,OAAOC,OAAO,MAAM,cAAc;AAClC,SAASC,aAAa,QAAQ,aAAa;AAC3C,SAASC,YAAY,QAAQ,qCAAqC;AAClE,SAASC,IAAI,EAAEC,UAAU,QAAQ,wBAAwB;AACzD,SAASC,gBAAgB,QAAQ,mCAAmC;AACpE,OAAOC,cAAc,MAAM,2CAA2C;AACtE,SAGEC,sBAAsB,QACjB,uCAAuC;AAC9C,OAAOC,kBAAkB,MAElB,uBAAuB;AAC9B,OAAOC,kBAAkB,MAAM,4CAA4C;AAC3E,OAAOC,iBAAiB,MAAM,oCAAoC;AAClE,OAAOC,qBAAqB,MA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EAAE,CAAC,CAAE;MACbhB,QAAQ,EAAEK,UAAW;MACrBS,GAAG,EAAG,WAAU3C,EAAG;IAAE,GAErB9E,KAAA,CAAA8G,aAAA,CAAC7F,kBAAkB,CAACuG,QAAQ;MAACzE,KAAK,EAAEoE;IAAa,GAC/CnH,KAAA,CAAA8G,aAAA,CAAC1F,qBAAqB,QACnBgG,OACoB,CACI,CACpB,CAAC;EAEhB,CAAC,CACS,CAAC,EAEjBpH,KAAA,CAAA8G,aAAA,CAACjG,UAAU;IACT+G,GAAG,EAAE,CAAE;IACPC,MAAM,EAAE,CAAE;IACVC,IAAI,EAAEC,OAAO,CAAC5E,KAAK,CAAE;IACrB6E,YAAY,EAAE,KAAM;IACpBC,UAAU,EAAE;MAAEL,GAAG,EAAE,IAAI;MAAEC,MAAM,EAAE;IAAK;EAAE,GAEvCrG,UAAU,CAAC;IAAE4F,OAAO,EAAEjE;EAAM,CAAC,CACpB,CACZ,CAAC;AAEP;AAEAzB,cAAc,CAACwG,qBAAqB,GAAG,KAAK;AAC5C,eAAexG,cAAc"}
1
+ {"version":3,"file":"Array.js","names":["React","useMemo","useRef","useEffect","useReducer","createRef","useContext","classnames","pointer","useFieldProps","makeUniqueId","Flex","FormStatus","HeightAnimation","pickSpacingProps","useMountEffect","pickFlexContainerProps","IterateItemContext","SummaryListContext","ValueBlockContext","FieldBoundaryProvider","DataContext","useDataValue","useSwitchContainerMode","getMessage","structuredClone","ArrayComponent","props","_props$value","salt","forceUpdate","summaryListContext","valueBlockContext","getValueByPath","preparedProps","path","countPath","countPathLimit","Infinity","countPathTransform","arrayValue","countValue","parseFloat","length","newValue","i","l","value","push","index","_objectSpread","required","error","defaultValue","withoutFlex","emptyValue","placeholder","containerMode","animate","handleChange","setChanged","onChange","children","idsRef","isNewRef","modesRef","valueWhileClosingRef","valueCountRef","containerRef","hadPushRef","innerRefs","omitFlex","handlePathChange","current","getNextContainerMode","arrayItems","list","map","_valueCountRef$curren","_modesRef$current$id","id","hasNewItems","isNew","_getNextContainerMode","itemContext","previousContainerMode","previous","initialContainerMode","modeOptions","options","switchContainerMode","mode","_isNewRef$current","newArrayValue","set","handlePush","element","handleRemove","keepItems","splice","fulfillRemove","_modesRef$current","_isNewRef$current2","findIndex","indexOf","restoreOriginalValue","last","flexProps","className","innerRef","arrayElements","itemProps","elementRef","renderChildren","elementChild","contextValue","content","Array","isArray","child","createElement","Provider","key","Item","tabIndex","Stack","Fragment","top","bottom","show","Boolean","no_animation","shellSpace","_supportsSpacingProps"],"sources":["../../../../../../src/extensions/forms/Iterate/Array/Array.tsx"],"sourcesContent":["import React, {\n useMemo,\n useRef,\n useEffect,\n useReducer,\n createRef,\n useContext,\n} from 'react'\nimport classnames from 'classnames'\nimport pointer from 'json-pointer'\nimport { useFieldProps } from '../../hooks'\nimport { makeUniqueId } from '../../../../shared/component-helper'\nimport { Flex, FormStatus, HeightAnimation } from '../../../../components'\nimport { pickSpacingProps } from '../../../../components/flex/utils'\nimport useMountEffect from '../../../../shared/helpers/useMountEffect'\nimport {\n BasicProps as FlexContainerProps,\n Props as FlexContainerAllProps,\n pickFlexContainerProps,\n} from '../../../../components/flex/Container'\nimport IterateItemContext, {\n IterateItemContextState,\n} from '../IterateItemContext'\nimport SummaryListContext from '../../Value/SummaryList/SummaryListContext'\nimport ValueBlockContext from '../../ValueBlock/ValueBlockContext'\nimport FieldBoundaryProvider from '../../DataContext/FieldBoundary/FieldBoundaryProvider'\nimport DataContext from '../../DataContext/Context'\nimport useDataValue from '../../hooks/useDataValue'\nimport { useSwitchContainerMode } from '../hooks'\nimport { getMessage } from '../../FieldBlock'\n\nimport type { ContainerMode, ElementChild, Props, Value } from './types'\nimport type { Identifier } from '../../types'\n\n/**\n * Deprecated, as it is supported by all major browsers and Node.js >=v18\n * So its a question of time, when we will remove this polyfill\n */\nimport structuredClone from '@ungap/structured-clone'\n\nexport type * from './types'\n\nfunction ArrayComponent(props: Props) {\n const [salt, forceUpdate] = useReducer(() => ({}), {})\n\n const summaryListContext = useContext(SummaryListContext)\n const valueBlockContext = useContext(ValueBlockContext)\n\n const { getValueByPath } = useDataValue()\n const preparedProps = useMemo(() => {\n const {\n path,\n countPath,\n countPathLimit = Infinity,\n countPathTransform,\n } = props\n\n if (countPath) {\n const arrayValue = getValueByPath(path)\n let countValue = parseFloat(getValueByPath(countPath))\n if (!(countValue >= 0)) {\n countValue = 0\n }\n if (countValue > countPathLimit) {\n countValue = countPathLimit\n }\n if (arrayValue?.length !== countValue) {\n const newValue = []\n for (let i = 0, l = countValue; i < l; i++) {\n const value = arrayValue?.[i]\n newValue.push(countPathTransform?.({ value, index: i }))\n }\n\n return {\n required: false,\n ...props,\n value: newValue,\n }\n }\n }\n\n return { required: false, ...props }\n }, [getValueByPath, props])\n\n const {\n path,\n value: arrayValue,\n error,\n defaultValue,\n withoutFlex,\n emptyValue,\n placeholder,\n containerMode,\n animate,\n handleChange,\n setChanged,\n onChange,\n children,\n } = useFieldProps(preparedProps)\n\n useMountEffect(() => {\n // To ensure the validator is called when a new item is added\n setChanged(true)\n })\n\n const idsRef = useRef<Array<Identifier>>([])\n const isNewRef = useRef<Record<string, boolean>>({})\n const modesRef = useRef<\n Record<\n Identifier,\n {\n current: ContainerMode\n previous?: ContainerMode\n options?: { omitFocusManagement?: boolean }\n }\n >\n >({})\n const valueWhileClosingRef = useRef<Value>()\n const valueCountRef = useRef(arrayValue)\n const containerRef = useRef<HTMLDivElement>()\n const hadPushRef = useRef<boolean>()\n const innerRefs = useRef<\n Record<string, React.RefObject<HTMLDivElement>>\n >({})\n\n const omitFlex = withoutFlex ?? (summaryListContext || valueBlockContext)\n\n // To support React.StrictMode, we inject the defaultValue into the data context this way.\n // The routine inside useFieldProps where updateDataValueDataContext is called, does not support React.StrictMode\n const { handlePathChange } = useContext(DataContext) || {}\n useMountEffect(() => {\n if (defaultValue) {\n handlePathChange?.(path, defaultValue)\n }\n })\n\n useEffect(() => {\n // Update inside the useEffect, to support React.StrictMode\n valueCountRef.current = arrayValue || []\n }, [arrayValue])\n\n const { getNextContainerMode } = useSwitchContainerMode()\n\n const arrayItems = useMemo(() => {\n const list = valueWhileClosingRef.current || arrayValue\n return (list ?? []).map((value, index) => {\n const id = idsRef.current[index] || makeUniqueId()\n\n const hasNewItems =\n arrayValue?.length > valueCountRef.current?.length\n\n if (!idsRef.current[index]) {\n isNewRef.current[id] = hasNewItems\n idsRef.current.push(id)\n }\n\n const isNew = isNewRef.current[id] || false\n if (!modesRef.current[id]?.current) {\n modesRef.current[id] = {\n current:\n containerMode ??\n (isNew ? getNextContainerMode() ?? 'edit' : 'auto'),\n }\n }\n\n const itemContext: IterateItemContextState = {\n id,\n path,\n value,\n index,\n arrayValue,\n containerRef,\n isNew,\n containerMode: modesRef.current[id].current,\n previousContainerMode: modesRef.current[id].previous,\n initialContainerMode: containerMode || 'auto',\n modeOptions: modesRef.current[id].options,\n switchContainerMode: (mode, options = {}) => {\n modesRef.current[id].previous = modesRef.current[id].current\n modesRef.current[id].current = mode\n modesRef.current[id].options = options\n delete isNewRef.current?.[id]\n forceUpdate()\n },\n handleChange: (path, value) => {\n const newArrayValue = structuredClone(arrayValue)\n\n // Make sure we have a new object reference,\n // else two new objects will be the same\n newArrayValue[index] = { ...newArrayValue[index] }\n\n pointer.set(newArrayValue, path, value)\n handleChange(newArrayValue)\n },\n handlePush: (element) => {\n hadPushRef.current = true\n handleChange([...(arrayValue || []), element])\n },\n handleRemove: ({ keepItems = false } = {}) => {\n if (keepItems) {\n // Add a backup as the array value while animating\n valueWhileClosingRef.current = arrayValue\n }\n\n const newArrayValue = structuredClone(arrayValue)\n newArrayValue.splice(index, 1)\n handleChange(newArrayValue)\n },\n\n // - Called after animation end\n fulfillRemove: () => {\n valueWhileClosingRef.current = null\n delete modesRef.current?.[id]\n delete isNewRef.current?.[id]\n const findIndex = idsRef.current.indexOf(id)\n idsRef.current.splice(findIndex, 1)\n forceUpdate()\n },\n\n // - Called when cancel button press\n restoreOriginalValue: (value) => {\n if (value) {\n const newArrayValue = structuredClone(arrayValue)\n newArrayValue[index] = value\n handleChange(newArrayValue)\n }\n },\n }\n\n return itemContext\n })\n\n // In order to update \"valueWhileClosingRef\" we need to have \"salt\" in the deps array\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [salt, arrayValue, path, handleChange])\n\n // - Call the onChange callback when a new element is added without calling \"handlePush\"\n useMemo(() => {\n const last = arrayItems?.[arrayItems.length - 1]\n if (last?.isNew && !hadPushRef.current) {\n onChange?.(arrayValue)\n } else {\n hadPushRef.current = false\n }\n }, [arrayValue, arrayItems, onChange])\n\n const flexProps: FlexContainerProps & {\n innerRef: FlexContainerAllProps['innerRef']\n } = {\n className: classnames(\n 'dnb-forms-iterate',\n 'dnb-forms-section',\n props?.className\n ),\n ...pickFlexContainerProps(props as FlexContainerProps),\n ...pickSpacingProps(props),\n innerRef: containerRef,\n }\n\n const arrayElements =\n arrayValue === emptyValue || props?.value?.length === 0\n ? placeholder\n : arrayItems.map((itemProps) => {\n const { id, value, index } = itemProps\n const elementRef = (innerRefs.current[id] =\n innerRefs.current[id] || createRef<HTMLDivElement>())\n\n const renderChildren = (elementChild: ElementChild) => {\n return typeof elementChild === 'function'\n ? elementChild(value, index)\n : elementChild\n }\n\n const contextValue = {\n ...itemProps,\n elementRef,\n }\n\n const content = Array.isArray(children)\n ? children.map((child) => renderChildren(child))\n : renderChildren(children)\n\n if (omitFlex) {\n return (\n <IterateItemContext.Provider\n key={`element-${id}`}\n value={contextValue}\n >\n <FieldBoundaryProvider>{content}</FieldBoundaryProvider>\n </IterateItemContext.Provider>\n )\n }\n\n return (\n <Flex.Item\n className=\"dnb-forms-iterate__element\"\n tabIndex={-1}\n innerRef={elementRef}\n key={`element-${id}`}\n >\n <IterateItemContext.Provider value={contextValue}>\n <FieldBoundaryProvider>{content}</FieldBoundaryProvider>\n </IterateItemContext.Provider>\n </Flex.Item>\n )\n })\n\n const content = omitFlex ? (\n arrayElements\n ) : (\n <Flex.Stack {...flexProps}>{arrayElements}</Flex.Stack>\n )\n\n return (\n <>\n {animate ? <HeightAnimation>{content}</HeightAnimation> : content}\n\n <FormStatus\n top={0}\n bottom={0}\n show={Boolean(error)}\n no_animation={false}\n shellSpace={{ top: true, bottom: true }}\n >\n {getMessage({ content: error })}\n </FormStatus>\n </>\n )\n}\n\nArrayComponent._supportsSpacingProps = true\nexport default ArrayComponent\n"],"mappings":";;;;;AAAA,OAAOA,KAAK,IACVC,OAAO,EACPC,MAAM,EACNC,SAAS,EACTC,UAAU,EACVC,SAAS,EACTC,UAAU,QACL,OAAO;AACd,OAAOC,UAAU,MAAM,YAAY;AACnC,OAAOC,OAAO,MAAM,cAAc;AAClC,SAASC,aAAa,QAAQ,aAAa;AAC3C,SAASC,YAAY,QAAQ,qCAAqC;AAClE,SAASC,IAAI,EAAEC,UAAU,EAAEC,eAAe,QAAQ,wBAAwB;AAC1E,SAASC,gBAAgB,QAAQ,mCAAmC;AACpE,OAAOC,cAAc,MAAM,2CAA2C;AACtE,SAGEC,sBAAsB,QACjB,uCAAuC;AAC9C,OAAOC,kBAAkB,MAElB,uBAAuB;AAC9B,OAAOC,kBAAkB,MAAM,4CAA4C;AAC3E,OAAOC,iBAAiB,MAAM,oCAAoC;AAClE,OAAOC,qBAAqB,MAAM,uDAAuD;AACzF,OAAOC,WAAW,MAAM,2BAA2B;AACnD,OAAOC,YAAY,MAAM,0BAA0B;AACnD,SAASC,sBAAsB,QAAQ,UAAU;AACjD,SAASC,UAAU,QAAQ,kBAAkB;AAS7C,OAAOC,eAAe,MAAM,yBAAyB;AAIrD,SAASC,cAAcA,CAACC,KAAY,EAAE;EAAA,IAAAC,YAAA;EACpC,MAAM,CAACC,IAAI,EAAEC,WAAW,CAAC,GAAG1B,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;EAEtD,MAAM2B,kBAAkB,GAAGzB,UAAU,CAACY,kBAAkB,CAAC;EACzD,MAAMc,iBAAiB,GAAG1B,UAAU,CAACa,iBAAiB,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,aAAA,CAAC5G,UAAU;IACTmH,GAAG,EAAE,CAAE;IACPC,MAAM,EAAE,CAAE;IACVC,IAAI,EAAEC,OAAO,CAAC9E,KAAK,CAAE;IACrB+E,YAAY,EAAE,KAAM;IACpBC,UAAU,EAAE;MAAEL,GAAG,EAAE,IAAI;MAAEC,MAAM,EAAE;IAAK;EAAE,GAEvCxG,UAAU,CAAC;IAAE4F,OAAO,EAAEhE;EAAM,CAAC,CACpB,CACZ,CAAC;AAEP;AAEA1B,cAAc,CAAC2G,qBAAqB,GAAG,IAAI;AAC3C,eAAe3G,cAAc"}
@@ -30,6 +30,11 @@ export const ArrayProperties = {
30
30
  type: 'boolean',
31
31
  status: 'optional'
32
32
  },
33
+ animate: {
34
+ doc: 'When `true` it will animate the height of the items.',
35
+ type: 'boolean',
36
+ status: 'optional'
37
+ },
33
38
  placeholder: {
34
39
  doc: 'Will be shown if the value or data context value is empty.',
35
40
  type: 'React.Node',
@@ -50,7 +55,7 @@ export const ArrayProperties = {
50
55
  },
51
56
  children: {
52
57
  doc: 'React.Node or a function so you can get the current value and index.',
53
- type: 'boolean',
58
+ type: ['React.ReactNode', 'function'],
54
59
  status: 'optional'
55
60
  },
56
61
  '[Flex.Stack](/uilib/layout/flex/stack/)': {
@@ -1 +1 @@
1
- {"version":3,"file":"ArrayDocs.js","names":["dataValueProperties","ArrayProperties","value","doc","type","status","path","countPath","countPathTransform","countPathLimit","withoutFlex","placeholder","emptyValue","validator","validateInitially","continuousValidation","containerMode","children","ArrayEvents","onChange"],"sources":["../../../../../../src/extensions/forms/Iterate/Array/ArrayDocs.ts"],"sourcesContent":["import { PropertiesTableProps } from '../../../../shared/types'\nimport { dataValueProperties } from '../../hooks/DataValueDocs'\n\nexport const ArrayProperties: PropertiesTableProps = {\n value: {\n doc: 'The data to iterate over. Alternative you can use the `path` prop.',\n type: 'array',\n status: 'optional',\n },\n path: {\n doc: 'A path (JSON Pointer) to the array to iterate over.',\n type: 'string',\n status: 'optional',\n },\n countPath: {\n doc: 'A path (JSON Pointer) to the array length.',\n type: 'string',\n status: 'optional',\n },\n countPathTransform: {\n doc: 'Will transform the current value before it is displayed.',\n type: 'function',\n status: 'optional',\n },\n countPathLimit: {\n doc: 'Will limit the iterate amount by given \"countPathLimit\" value.',\n type: 'number',\n status: 'optional',\n },\n withoutFlex: {\n doc: 'When `true` it will omit the Flex.Stack wrapper so it can be used for tables and lists.',\n type: 'boolean',\n status: 'optional',\n },\n placeholder: {\n doc: 'Will be shown if the value or data context value is empty.',\n type: 'React.Node',\n status: 'optional',\n },\n emptyValue: {\n doc: 'Will be used to compare the value in order to show the placeholder.',\n type: 'unknown',\n status: 'optional',\n },\n validator: dataValueProperties.validator,\n validateInitially: dataValueProperties.validateInitially,\n continuousValidation: dataValueProperties.continuousValidation,\n containerMode: {\n doc: 'Defines the container mode for all nested containers. Can be `view`, `edit` or `auto`. When using `auto`, it will automatically open if there is an error in the container. When a new item is added, the item before it will change to `view` mode, if it had no validation errors. Defaults to `auto`.',\n type: 'string',\n status: 'optional',\n },\n children: {\n doc: 'React.Node or a function so you can get the current value and index.',\n type: 'boolean',\n status: 'optional',\n },\n '[Flex.Stack](/uilib/layout/flex/stack/)': {\n doc: 'All Flex.Stack properties.',\n type: 'Various',\n status: 'optional',\n },\n}\n\nexport const ArrayEvents: PropertiesTableProps = {\n onChange: {\n doc: 'Will be called when a value of a field was changed by the user, with the data set (including the changed value) as argument.',\n type: 'function',\n status: 'optional',\n },\n}\n"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,2BAA2B;AAE/D,OAAO,MAAMC,eAAqC,GAAG;EACnDC,KAAK,EAAE;IACLC,GAAG,EAAE,oEAAoE;IACzEC,IAAI,EAAE,OAAO;IACbC,MAAM,EAAE;EACV,CAAC;EACDC,IAAI,EAAE;IACJH,GAAG,EAAE,qDAAqD;IAC1DC,IAAI,EAAE,QAAQ;IACdC,MAAM,EAAE;EACV,CAAC;EACDE,SAAS,EAAE;IACTJ,GAAG,EAAE,4CAA4C;IACjDC,IAAI,EAAE,QAAQ;IACdC,MAAM,EAAE;EACV,CAAC;EACDG,kBAAkB,EAAE;IAClBL,GAAG,EAAE,0DAA0D;IAC/DC,IAAI,EAAE,UAAU;IAChBC,MAAM,EAAE;EACV,CAAC;EACDI,cAAc,EAAE;IACdN,GAAG,EAAE,gEAAgE;IACrEC,IAAI,EAAE,QAAQ;IACdC,MAAM,EAAE;EACV,CAAC;EACDK,WAAW,EAAE;IACXP,GAAG,EAAE,yFAAyF;IAC9FC,IAAI,EAAE,SAAS;IACfC,MAAM,EAAE;EACV,CAAC;EACDM,WAAW,EAAE;IACXR,GAAG,EAAE,4DAA4D;IACjEC,IAAI,EAAE,YAAY;IAClBC,MAAM,EAAE;EACV,CAAC;EACDO,UAAU,EAAE;IACVT,GAAG,EAAE,qEAAqE;IAC1EC,IAAI,EAAE,SAAS;IACfC,MAAM,EAAE;EACV,CAAC;EACDQ,SAAS,EAAEb,mBAAmB,CAACa,SAAS;EACxCC,iBAAiB,EAAEd,mBAAmB,CAACc,iBAAiB;EACxDC,oBAAoB,EAAEf,mBAAmB,CAACe,oBAAoB;EAC9DC,aAAa,EAAE;IACbb,GAAG,EAAE,0SAA0S;IAC/SC,IAAI,EAAE,QAAQ;IACdC,MAAM,EAAE;EACV,CAAC;EACDY,QAAQ,EAAE;IACRd,GAAG,EAAE,sEAAsE;IAC3EC,IAAI,EAAE,SAAS;IACfC,MAAM,EAAE;EACV,CAAC;EACD,yCAAyC,EAAE;IACzCF,GAAG,EAAE,4BAA4B;IACjCC,IAAI,EAAE,SAAS;IACfC,MAAM,EAAE;EACV;AACF,CAAC;AAED,OAAO,MAAMa,WAAiC,GAAG;EAC/CC,QAAQ,EAAE;IACRhB,GAAG,EAAE,8HAA8H;IACnIC,IAAI,EAAE,UAAU;IAChBC,MAAM,EAAE;EACV;AACF,CAAC"}
1
+ {"version":3,"file":"ArrayDocs.js","names":["dataValueProperties","ArrayProperties","value","doc","type","status","path","countPath","countPathTransform","countPathLimit","withoutFlex","animate","placeholder","emptyValue","validator","validateInitially","continuousValidation","containerMode","children","ArrayEvents","onChange"],"sources":["../../../../../../src/extensions/forms/Iterate/Array/ArrayDocs.ts"],"sourcesContent":["import { PropertiesTableProps } from '../../../../shared/types'\nimport { dataValueProperties } from '../../hooks/DataValueDocs'\n\nexport const ArrayProperties: PropertiesTableProps = {\n value: {\n doc: 'The data to iterate over. Alternative you can use the `path` prop.',\n type: 'array',\n status: 'optional',\n },\n path: {\n doc: 'A path (JSON Pointer) to the array to iterate over.',\n type: 'string',\n status: 'optional',\n },\n countPath: {\n doc: 'A path (JSON Pointer) to the array length.',\n type: 'string',\n status: 'optional',\n },\n countPathTransform: {\n doc: 'Will transform the current value before it is displayed.',\n type: 'function',\n status: 'optional',\n },\n countPathLimit: {\n doc: 'Will limit the iterate amount by given \"countPathLimit\" value.',\n type: 'number',\n status: 'optional',\n },\n withoutFlex: {\n doc: 'When `true` it will omit the Flex.Stack wrapper so it can be used for tables and lists.',\n type: 'boolean',\n status: 'optional',\n },\n animate: {\n doc: 'When `true` it will animate the height of the items.',\n type: 'boolean',\n status: 'optional',\n },\n placeholder: {\n doc: 'Will be shown if the value or data context value is empty.',\n type: 'React.Node',\n status: 'optional',\n },\n emptyValue: {\n doc: 'Will be used to compare the value in order to show the placeholder.',\n type: 'unknown',\n status: 'optional',\n },\n validator: dataValueProperties.validator,\n validateInitially: dataValueProperties.validateInitially,\n continuousValidation: dataValueProperties.continuousValidation,\n containerMode: {\n doc: 'Defines the container mode for all nested containers. Can be `view`, `edit` or `auto`. When using `auto`, it will automatically open if there is an error in the container. When a new item is added, the item before it will change to `view` mode, if it had no validation errors. Defaults to `auto`.',\n type: 'string',\n status: 'optional',\n },\n children: {\n doc: 'React.Node or a function so you can get the current value and index.',\n type: ['React.ReactNode', 'function'],\n status: 'optional',\n },\n '[Flex.Stack](/uilib/layout/flex/stack/)': {\n doc: 'All Flex.Stack properties.',\n type: 'Various',\n status: 'optional',\n },\n}\n\nexport const ArrayEvents: PropertiesTableProps = {\n onChange: {\n doc: 'Will be called when a value of a field was changed by the user, with the data set (including the changed value) as argument.',\n type: 'function',\n status: 'optional',\n },\n}\n"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,2BAA2B;AAE/D,OAAO,MAAMC,eAAqC,GAAG;EACnDC,KAAK,EAAE;IACLC,GAAG,EAAE,oEAAoE;IACzEC,IAAI,EAAE,OAAO;IACbC,MAAM,EAAE;EACV,CAAC;EACDC,IAAI,EAAE;IACJH,GAAG,EAAE,qDAAqD;IAC1DC,IAAI,EAAE,QAAQ;IACdC,MAAM,EAAE;EACV,CAAC;EACDE,SAAS,EAAE;IACTJ,GAAG,EAAE,4CAA4C;IACjDC,IAAI,EAAE,QAAQ;IACdC,MAAM,EAAE;EACV,CAAC;EACDG,kBAAkB,EAAE;IAClBL,GAAG,EAAE,0DAA0D;IAC/DC,IAAI,EAAE,UAAU;IAChBC,MAAM,EAAE;EACV,CAAC;EACDI,cAAc,EAAE;IACdN,GAAG,EAAE,gEAAgE;IACrEC,IAAI,EAAE,QAAQ;IACdC,MAAM,EAAE;EACV,CAAC;EACDK,WAAW,EAAE;IACXP,GAAG,EAAE,yFAAyF;IAC9FC,IAAI,EAAE,SAAS;IACfC,MAAM,EAAE;EACV,CAAC;EACDM,OAAO,EAAE;IACPR,GAAG,EAAE,sDAAsD;IAC3DC,IAAI,EAAE,SAAS;IACfC,MAAM,EAAE;EACV,CAAC;EACDO,WAAW,EAAE;IACXT,GAAG,EAAE,4DAA4D;IACjEC,IAAI,EAAE,YAAY;IAClBC,MAAM,EAAE;EACV,CAAC;EACDQ,UAAU,EAAE;IACVV,GAAG,EAAE,qEAAqE;IAC1EC,IAAI,EAAE,SAAS;IACfC,MAAM,EAAE;EACV,CAAC;EACDS,SAAS,EAAEd,mBAAmB,CAACc,SAAS;EACxCC,iBAAiB,EAAEf,mBAAmB,CAACe,iBAAiB;EACxDC,oBAAoB,EAAEhB,mBAAmB,CAACgB,oBAAoB;EAC9DC,aAAa,EAAE;IACbd,GAAG,EAAE,0SAA0S;IAC/SC,IAAI,EAAE,QAAQ;IACdC,MAAM,EAAE;EACV,CAAC;EACDa,QAAQ,EAAE;IACRf,GAAG,EAAE,sEAAsE;IAC3EC,IAAI,EAAE,CAAC,iBAAiB,EAAE,UAAU,CAAC;IACrCC,MAAM,EAAE;EACV,CAAC;EACD,yCAAyC,EAAE;IACzCF,GAAG,EAAE,4BAA4B;IACjCC,IAAI,EAAE,SAAS;IACfC,MAAM,EAAE;EACV;AACF,CAAC;AAED,OAAO,MAAMc,WAAiC,GAAG;EAC/CC,QAAQ,EAAE;IACRjB,GAAG,EAAE,8HAA8H;IACnIC,IAAI,EAAE,UAAU;IAChBC,MAAM,EAAE;EACV;AACF,CAAC"}
@@ -2,7 +2,7 @@ import { Props as FlexContainerProps } from '../../../../components/flex/Contain
2
2
  import { ContainerMode } from './types';
3
3
  export type ArrayItemAreaProps = {
4
4
  /**
5
- * Defines the variant of the ViewContainer or EditContainer. Can be `outline`.
5
+ * Defines the variant of the ViewContainer, EditContainer or PushContainer. Can be `outline` or `basic`.
6
6
  * Defaults to `outline`.
7
7
  */
8
8
  variant?: 'outline' | 'basic';
@@ -1 +1 @@
1
- {"version":3,"file":"ArrayItemArea.js","names":["React","useCallback","useContext","useEffect","useReducer","useRef","classnames","Flex","HeightAnimation","IterateItemContext","ArrayItemAreaContext","FieldBoundaryContext","ArrayItemArea","props","forceUpdate","mode","open","ariaLabel","onAnimationEnd","className","children","openDelay","variant","restProps","_objectWithoutProperties","_excluded","localContextRef","hasError","hasSubmitError","current","nextFocusElementRef","isNew","value","containerMode","determineMode","initialContainerMode","switchContainerMode","omitFocusManagement","handleRemove","index","previousContainerMode","openRef","isRemoving","setOpenState","setTimeout","setFocus","state","_localContextRef$curr","modeOptions","_localContextRef$curr2","_localContextRef$curr3","_localContextRef$curr4","elementRef","focus","call","_nextFocusElementRef$","_nextFocusElementRef$2","handleAnimationEnd","_localContextRef$curr5","_localContextRef$curr6","fulfillRemove","handleRemoveItem","Array","from","parentElement","childNodes","at","e","keepItems","createElement","Provider","duration","keepInDOM","Stack","_extends","element","_supportsSpacingProps"],"sources":["../../../../../../src/extensions/forms/Iterate/Array/ArrayItemArea.tsx"],"sourcesContent":["import React, {\n useCallback,\n useContext,\n useEffect,\n useReducer,\n useRef,\n} from 'react'\nimport classnames from 'classnames'\nimport { Flex, HeightAnimation } from '../../../../components'\nimport IterateItemContext, {\n IterateItemContextState,\n} from '../IterateItemContext'\nimport ArrayItemAreaContext from './ArrayItemAreaContext'\nimport FieldBoundaryContext from '../../DataContext/FieldBoundary/FieldBoundaryContext'\nimport { Props as FlexContainerProps } from '../../../../components/flex/Container'\nimport { ContainerMode } from './types'\n\nexport type ArrayItemAreaProps = {\n /**\n * Defines the variant of the ViewContainer or EditContainer. Can be `outline`.\n * Defaults to `outline`.\n */\n variant?: 'outline' | 'basic'\n}\n\nexport type Props = {\n mode: ContainerMode\n open?: boolean | undefined\n ariaLabel?: string\n openDelay?: number\n} & ArrayItemAreaProps\n\nfunction ArrayItemArea(props: Props & FlexContainerProps) {\n const [, forceUpdate] = useReducer(() => ({}), {})\n\n const {\n mode,\n open,\n ariaLabel,\n onAnimationEnd,\n className,\n children,\n openDelay = 100,\n variant = 'outline',\n ...restProps\n } = props\n\n const localContextRef = useRef<IterateItemContextState>()\n const { hasError, hasSubmitError } =\n useContext(FieldBoundaryContext) || {}\n localContextRef.current = useContext(IterateItemContext) || {}\n const nextFocusElementRef = useRef<HTMLElement>()\n const { isNew, value } = localContextRef.current\n if (hasSubmitError || !value) {\n localContextRef.current.containerMode = 'edit'\n }\n if (localContextRef.current.containerMode === 'auto') {\n localContextRef.current.containerMode = 'view'\n }\n\n const determineMode = useCallback(() => {\n const { initialContainerMode, switchContainerMode } =\n localContextRef.current\n if (\n mode === 'edit' &&\n !hasSubmitError &&\n initialContainerMode === 'auto'\n ) {\n // - Set the container mode to \"edit\" if we have an error\n if (hasError && !isNew) {\n switchContainerMode('edit', { omitFocusManagement: true })\n }\n }\n }, [hasError, hasSubmitError, isNew, mode])\n\n useEffect(() => {\n determineMode()\n }, [determineMode])\n\n const { handleRemove, index, previousContainerMode, containerMode } =\n localContextRef.current\n\n const openRef = useRef(open ?? (containerMode === mode && !isNew))\n const isRemoving = useRef(false)\n\n const setOpenState = useCallback((open: boolean) => {\n openRef.current = open\n forceUpdate()\n }, [])\n\n useEffect(() => {\n if (!isRemoving.current) {\n // - Set the open state, if it's controlled\n if (typeof open !== 'undefined') {\n setOpenState(open)\n } else {\n // - Open the block with animation, if it's in the right mode\n if (openRef.current !== (containerMode === mode)) {\n if (isNew) {\n setTimeout(() => {\n setOpenState(containerMode === mode)\n }, openDelay) // in order to apply the animation\n } else {\n setOpenState(containerMode === mode)\n }\n }\n }\n }\n }, [containerMode, isNew, mode, open, openDelay, setOpenState])\n\n const setFocus = useCallback(\n (state) => {\n if (\n localContextRef.current.modeOptions?.omitFocusManagement !==\n true &&\n !hasSubmitError &&\n containerMode === mode && // ensure we match the correct mode\n containerMode !== previousContainerMode // ensure we have a new mode\n ) {\n if (state === 'opened') {\n localContextRef.current.elementRef?.current?.focus?.()\n } else if (state === 'closed') {\n nextFocusElementRef.current?.focus?.()\n }\n }\n },\n [containerMode, hasSubmitError, mode, previousContainerMode]\n )\n\n // - Remove the block with animation, if it's in the right mode\n const handleAnimationEnd = useCallback(\n (state) => {\n if (!openRef.current && isRemoving.current) {\n isRemoving.current = false\n localContextRef.current.fulfillRemove?.()\n }\n\n setFocus(state)\n onAnimationEnd?.(state)\n },\n [onAnimationEnd, setFocus]\n )\n\n const handleRemoveItem = useCallback(() => {\n try {\n // Because \"previousElementSibling\" did not work in Jest/JSDOM\n nextFocusElementRef.current = Array.from(\n localContextRef.current.elementRef.current.parentElement.childNodes\n ).at(index - 1) as HTMLElement\n } catch (e) {\n //\n }\n isRemoving.current = true\n handleRemove?.({ keepItems: true })\n setOpenState(false)\n }, [handleRemove, index, setOpenState])\n\n return (\n <ArrayItemAreaContext.Provider value={{ handleRemoveItem }}>\n <HeightAnimation\n className={classnames(\n 'dnb-forms-section-block',\n variant && `dnb-forms-section-block--variant-${variant}`,\n isNew && 'dnb-forms-section-block--new',\n hasSubmitError && 'dnb-forms-section-block--error',\n className\n )}\n open={openRef.current}\n onAnimationEnd={handleAnimationEnd}\n duration={450}\n keepInDOM // Ensure fields get mounted so they will sync with the data context\n >\n <Flex.Stack\n className=\"dnb-forms-section-block__inner\"\n {...restProps}\n element=\"section\"\n aria-label={ariaLabel}\n >\n {children}\n </Flex.Stack>\n </HeightAnimation>\n </ArrayItemAreaContext.Provider>\n )\n}\n\nArrayItemArea._supportsSpacingProps = true\nexport default ArrayItemArea\n"],"mappings":";;;;;AAAA,OAAOA,KAAK,IACVC,WAAW,EACXC,UAAU,EACVC,SAAS,EACTC,UAAU,EACVC,MAAM,QACD,OAAO;AACd,OAAOC,UAAU,MAAM,YAAY;AACnC,SAASC,IAAI,EAAEC,eAAe,QAAQ,wBAAwB;AAC9D,OAAOC,kBAAkB,MAElB,uBAAuB;AAC9B,OAAOC,oBAAoB,MAAM,wBAAwB;AACzD,OAAOC,oBAAoB,MAAM,sDAAsD;AAmBvF,SAASC,aAAaA,CAACC,KAAiC,EAAE;EACxD,MAAM,GAAGC,WAAW,CAAC,GAAGV,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;EAElD,MAAM;MACJW,IAAI;MACJC,IAAI;MACJC,SAAS;MACTC,cAAc;MACdC,SAAS;MACTC,QAAQ;MACRC,SAAS,GAAG,GAAG;MACfC,OAAO,GAAG;IAEZ,CAAC,GAAGT,KAAK;IADJU,SAAS,GAAAC,wBAAA,CACVX,KAAK,EAAAY,SAAA;EAET,MAAMC,eAAe,GAAGrB,MAAM,CAA0B,CAAC;EACzD,MAAM;IAAEsB,QAAQ;IAAEC;EAAe,CAAC,GAChC1B,UAAU,CAACS,oBAAoB,CAAC,IAAI,CAAC,CAAC;EACxCe,eAA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AO,GAAG,IAAI;IACzBS,YAAY,aAAZA,YAAY,uBAAZA,YAAY,CAAG;MAAE8B,SAAS,EAAE;IAAK,CAAC,CAAC;IACnCzB,YAAY,CAAC,KAAK,CAAC;EACrB,CAAC,EAAE,CAACL,YAAY,EAAEC,KAAK,EAAEI,YAAY,CAAC,CAAC;EAEvC,OACE3C,KAAA,CAAAqE,aAAA,CAAC3D,oBAAoB,CAAC4D,QAAQ;IAACtC,KAAK,EAAE;MAAE6B;IAAiB;EAAE,GACzD7D,KAAA,CAAAqE,aAAA,CAAC7D,eAAe;IACdW,SAAS,EAAEb,UAAU,CACnB,yBAAyB,EAIzBa,SAAS,EAHTG,OAAO,IAAK,oCAAmCA,OAAQ,EAAC,EACxDS,KAAK,IAAI,8BAA8B,EACvCH,cAAc,IAAI,gCAEpB,CAAE;IACFZ,IAAI,EAAEyB,OAAO,CAACZ,OAAQ;IACtBX,cAAc,EAAEuC,kBAAmB;IACnCc,QAAQ,EAAE,GAAI;IACdC,SAAS;EAAA,GAETxE,KAAA,CAAAqE,aAAA,CAAC9D,IAAI,CAACkE,KAAK,EAAAC,QAAA;IACTvD,SAAS,EAAC;EAAgC,GACtCI,SAAS;IACboD,OAAO,EAAC,SAAS;IACjB,cAAY1D;EAAU,IAErBG,QACS,CACG,CACY,CAAC;AAEpC;AAEAR,aAAa,CAACgE,qBAAqB,GAAG,IAAI;AAC1C,eAAehE,aAAa"}
1
+ {"version":3,"file":"ArrayItemArea.js","names":["React","useCallback","useContext","useEffect","useReducer","useRef","classnames","Flex","HeightAnimation","IterateItemContext","ArrayItemAreaContext","FieldBoundaryContext","ArrayItemArea","props","forceUpdate","mode","open","ariaLabel","onAnimationEnd","className","children","openDelay","variant","restProps","_objectWithoutProperties","_excluded","localContextRef","hasError","hasSubmitError","current","nextFocusElementRef","isNew","value","containerMode","determineMode","initialContainerMode","switchContainerMode","omitFocusManagement","handleRemove","index","previousContainerMode","openRef","isRemoving","setOpenState","setTimeout","setFocus","state","_localContextRef$curr","modeOptions","_localContextRef$curr2","_localContextRef$curr3","_localContextRef$curr4","elementRef","focus","call","_nextFocusElementRef$","_nextFocusElementRef$2","handleAnimationEnd","_localContextRef$curr5","_localContextRef$curr6","fulfillRemove","handleRemoveItem","Array","from","parentElement","childNodes","at","e","keepItems","createElement","Provider","duration","keepInDOM","Stack","_extends","element","_supportsSpacingProps"],"sources":["../../../../../../src/extensions/forms/Iterate/Array/ArrayItemArea.tsx"],"sourcesContent":["import React, {\n useCallback,\n useContext,\n useEffect,\n useReducer,\n useRef,\n} from 'react'\nimport classnames from 'classnames'\nimport { Flex, HeightAnimation } from '../../../../components'\nimport IterateItemContext, {\n IterateItemContextState,\n} from '../IterateItemContext'\nimport ArrayItemAreaContext from './ArrayItemAreaContext'\nimport FieldBoundaryContext from '../../DataContext/FieldBoundary/FieldBoundaryContext'\nimport { Props as FlexContainerProps } from '../../../../components/flex/Container'\nimport { ContainerMode } from './types'\n\nexport type ArrayItemAreaProps = {\n /**\n * Defines the variant of the ViewContainer, EditContainer or PushContainer. Can be `outline` or `basic`.\n * Defaults to `outline`.\n */\n variant?: 'outline' | 'basic'\n}\n\nexport type Props = {\n mode: ContainerMode\n open?: boolean | undefined\n ariaLabel?: string\n openDelay?: number\n} & ArrayItemAreaProps\n\nfunction ArrayItemArea(props: Props & FlexContainerProps) {\n const [, forceUpdate] = useReducer(() => ({}), {})\n\n const {\n mode,\n open,\n ariaLabel,\n onAnimationEnd,\n className,\n children,\n openDelay = 100,\n variant = 'outline',\n ...restProps\n } = props\n\n const localContextRef = useRef<IterateItemContextState>()\n const { hasError, hasSubmitError } =\n useContext(FieldBoundaryContext) || {}\n localContextRef.current = useContext(IterateItemContext) || {}\n const nextFocusElementRef = useRef<HTMLElement>()\n const { isNew, value } = localContextRef.current\n if (hasSubmitError || !value) {\n localContextRef.current.containerMode = 'edit'\n }\n if (localContextRef.current.containerMode === 'auto') {\n localContextRef.current.containerMode = 'view'\n }\n\n const determineMode = useCallback(() => {\n const { initialContainerMode, switchContainerMode } =\n localContextRef.current\n if (\n mode === 'edit' &&\n !hasSubmitError &&\n initialContainerMode === 'auto'\n ) {\n // - Set the container mode to \"edit\" if we have an error\n if (hasError && !isNew) {\n switchContainerMode('edit', { omitFocusManagement: true })\n }\n }\n }, [hasError, hasSubmitError, isNew, mode])\n\n useEffect(() => {\n determineMode()\n }, [determineMode])\n\n const { handleRemove, index, previousContainerMode, containerMode } =\n localContextRef.current\n\n const openRef = useRef(open ?? (containerMode === mode && !isNew))\n const isRemoving = useRef(false)\n\n const setOpenState = useCallback((open: boolean) => {\n openRef.current = open\n forceUpdate()\n }, [])\n\n useEffect(() => {\n if (!isRemoving.current) {\n // - Set the open state, if it's controlled\n if (typeof open !== 'undefined') {\n setOpenState(open)\n } else {\n // - Open the block with animation, if it's in the right mode\n if (openRef.current !== (containerMode === mode)) {\n if (isNew) {\n setTimeout(() => {\n setOpenState(containerMode === mode)\n }, openDelay) // in order to apply the animation\n } else {\n setOpenState(containerMode === mode)\n }\n }\n }\n }\n }, [containerMode, isNew, mode, open, openDelay, setOpenState])\n\n const setFocus = useCallback(\n (state) => {\n if (\n localContextRef.current.modeOptions?.omitFocusManagement !==\n true &&\n !hasSubmitError &&\n containerMode === mode && // ensure we match the correct mode\n containerMode !== previousContainerMode // ensure we have a new mode\n ) {\n if (state === 'opened') {\n localContextRef.current.elementRef?.current?.focus?.()\n } else if (state === 'closed') {\n nextFocusElementRef.current?.focus?.()\n }\n }\n },\n [containerMode, hasSubmitError, mode, previousContainerMode]\n )\n\n // - Remove the block with animation, if it's in the right mode\n const handleAnimationEnd = useCallback(\n (state) => {\n if (!openRef.current && isRemoving.current) {\n isRemoving.current = false\n localContextRef.current.fulfillRemove?.()\n }\n\n setFocus(state)\n onAnimationEnd?.(state)\n },\n [onAnimationEnd, setFocus]\n )\n\n const handleRemoveItem = useCallback(() => {\n try {\n // Because \"previousElementSibling\" did not work in Jest/JSDOM\n nextFocusElementRef.current = Array.from(\n localContextRef.current.elementRef.current.parentElement.childNodes\n ).at(index - 1) as HTMLElement\n } catch (e) {\n //\n }\n isRemoving.current = true\n handleRemove?.({ keepItems: true })\n setOpenState(false)\n }, [handleRemove, index, setOpenState])\n\n return (\n <ArrayItemAreaContext.Provider value={{ handleRemoveItem }}>\n <HeightAnimation\n className={classnames(\n 'dnb-forms-section-block',\n variant && `dnb-forms-section-block--variant-${variant}`,\n isNew && 'dnb-forms-section-block--new',\n hasSubmitError && 'dnb-forms-section-block--error',\n className\n )}\n open={openRef.current}\n onAnimationEnd={handleAnimationEnd}\n duration={450}\n keepInDOM // Ensure fields get mounted so they will sync with the data context\n >\n <Flex.Stack\n className=\"dnb-forms-section-block__inner\"\n {...restProps}\n element=\"section\"\n aria-label={ariaLabel}\n >\n {children}\n </Flex.Stack>\n </HeightAnimation>\n </ArrayItemAreaContext.Provider>\n )\n}\n\nArrayItemArea._supportsSpacingProps = true\nexport default ArrayItemArea\n"],"mappings":";;;;;AAAA,OAAOA,KAAK,IACVC,WAAW,EACXC,UAAU,EACVC,SAAS,EACTC,UAAU,EACVC,MAAM,QACD,OAAO;AACd,OAAOC,UAAU,MAAM,YAAY;AACnC,SAASC,IAAI,EAAEC,eAAe,QAAQ,wBAAwB;AAC9D,OAAOC,kBAAkB,MAElB,uBAAuB;AAC9B,OAAOC,oBAAoB,MAAM,wBAAwB;AACzD,OAAOC,oBAAoB,MAAM,sDAAsD;AAmBvF,SAASC,aAAaA,CAACC,KAAiC,EAAE;EACxD,MAAM,GAAGC,WAAW,CAAC,GAAGV,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;EAElD,MAAM;MACJW,IAAI;MACJC,IAAI;MACJC,SAAS;MACTC,cAAc;MACdC,SAAS;MACTC,QAAQ;MACRC,SAAS,GAAG,GAAG;MACfC,OAAO,GAAG;IAEZ,CAAC,GAAGT,KAAK;IADJU,SAAS,GAAAC,wBAAA,CACVX,KAAK,EAAAY,SAAA;EAET,MAAMC,eAAe,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aAAa,CAACC,UAC3D,CAAC,CAACC,EAAE,CAAC3B,KAAK,GAAG,CAAC,CAAgB;IAChC,CAAC,CAAC,OAAO4B,CAAC,EAAE,CAEZ;IACAzB,UAAU,CAACb,OAAO,GAAG,IAAI;IACzBS,YAAY,aAAZA,YAAY,uBAAZA,YAAY,CAAG;MAAE8B,SAAS,EAAE;IAAK,CAAC,CAAC;IACnCzB,YAAY,CAAC,KAAK,CAAC;EACrB,CAAC,EAAE,CAACL,YAAY,EAAEC,KAAK,EAAEI,YAAY,CAAC,CAAC;EAEvC,OACE3C,KAAA,CAAAqE,aAAA,CAAC3D,oBAAoB,CAAC4D,QAAQ;IAACtC,KAAK,EAAE;MAAE6B;IAAiB;EAAE,GACzD7D,KAAA,CAAAqE,aAAA,CAAC7D,eAAe;IACdW,SAAS,EAAEb,UAAU,CACnB,yBAAyB,EAIzBa,SAAS,EAHTG,OAAO,IAAK,oCAAmCA,OAAQ,EAAC,EACxDS,KAAK,IAAI,8BAA8B,EACvCH,cAAc,IAAI,gCAEpB,CAAE;IACFZ,IAAI,EAAEyB,OAAO,CAACZ,OAAQ;IACtBX,cAAc,EAAEuC,kBAAmB;IACnCc,QAAQ,EAAE,GAAI;IACdC,SAAS;EAAA,GAETxE,KAAA,CAAAqE,aAAA,CAAC9D,IAAI,CAACkE,KAAK,EAAAC,QAAA;IACTvD,SAAS,EAAC;EAAgC,GACtCI,SAAS;IACboD,OAAO,EAAC,SAAS;IACjB,cAAY1D;EAAU,IAErBG,QACS,CACG,CACY,CAAC;AAEpC;AAEAR,aAAa,CAACgE,qBAAqB,GAAG,IAAI;AAC1C,eAAehE,aAAa"}
@@ -11,6 +11,7 @@ export type Props = Omit<FlexContainerProps, keyof Omit<React.HTMLAttributes<HTM
11
11
  countPathLimit?: number;
12
12
  validator?: Validator<Value>;
13
13
  withoutFlex?: boolean;
14
+ animate?: boolean;
14
15
  placeholder?: React.ReactNode;
15
16
  containerMode?: ContainerMode;
16
17
  countPathTransform?: (params: {
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../../../../src/extensions/forms/Iterate/Array/types.ts"],"sourcesContent":["import { Path, UseFieldProps, Validator } from '../../types'\nimport { Props as FlexContainerProps } from '../../../../components/flex/Container'\n\nexport type ContainerMode = 'view' | 'edit' | 'auto'\nexport type Value = Array<unknown | Record<string, unknown>>\nexport type ElementChild =\n | React.ReactNode\n | ((value: any, index: number) => React.ReactNode)\nexport type Props = Omit<\n FlexContainerProps,\n keyof Omit<React.HTMLAttributes<HTMLDivElement>, 'className'>\n> &\n Pick<\n UseFieldProps<Value, undefined | Value>,\n | 'value'\n | 'defaultValue'\n | 'emptyValue'\n | 'onChange'\n | 'validateInitially'\n | 'continuousValidation'\n > & {\n children: ElementChild | Array<ElementChild>\n path?: Path\n countPath?: Path\n countPathLimit?: number\n validator?: Validator<Value>\n withoutFlex?: boolean\n placeholder?: React.ReactNode\n containerMode?: ContainerMode\n countPathTransform?: (params: { value: any; index: number }) => any\n }\n"],"mappings":""}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../../../../src/extensions/forms/Iterate/Array/types.ts"],"sourcesContent":["import { Path, UseFieldProps, Validator } from '../../types'\nimport { Props as FlexContainerProps } from '../../../../components/flex/Container'\n\nexport type ContainerMode = 'view' | 'edit' | 'auto'\nexport type Value = Array<unknown | Record<string, unknown>>\nexport type ElementChild =\n | React.ReactNode\n | ((value: any, index: number) => React.ReactNode)\nexport type Props = Omit<\n FlexContainerProps,\n keyof Omit<React.HTMLAttributes<HTMLDivElement>, 'className'>\n> &\n Pick<\n UseFieldProps<Value, undefined | Value>,\n | 'value'\n | 'defaultValue'\n | 'emptyValue'\n | 'onChange'\n | 'validateInitially'\n | 'continuousValidation'\n > & {\n children: ElementChild | Array<ElementChild>\n path?: Path\n countPath?: Path\n countPathLimit?: number\n validator?: Validator<Value>\n withoutFlex?: boolean\n animate?: boolean\n placeholder?: React.ReactNode\n containerMode?: ContainerMode\n countPathTransform?: (params: { value: any; index: number }) => any\n }\n"],"mappings":""}
@@ -24,7 +24,6 @@ export default function DoneButton(props) {
24
24
  const {
25
25
  commitHandleRef
26
26
  } = useContext(PushContainerContext) || {};
27
- useContext(FieldBoundaryContext) || {};
28
27
  const {
29
28
  setShowError
30
29
  } = useContext(ToolbarContext) || {};
@@ -1 +1 @@
1
- {"version":3,"file":"DoneButton.js","names":["React","useCallback","useContext","useEffect","useRef","Button","useTranslation","IterateItemContext","ToolbarContext","FieldBoundaryContext","PushContainerContext","check","DoneButton","props","switchContainerMode","containerMode","arrayValue","index","hasError","hasVisibleError","setShowBoundaryErrors","commitHandleRef","setShowError","doneButton","IterateEditContainer","valueBackupRef","current","doneHandler","_commitHandleRef$curr","call","createElement","_extends","variant","icon","icon_position","on_click"],"sources":["../../../../../../src/extensions/forms/Iterate/EditContainer/DoneButton.tsx"],"sourcesContent":["import React, { useCallback, useContext, useEffect, useRef } from 'react'\nimport { Button } from '../../../../components'\nimport useTranslation from '../../hooks/useTranslation'\nimport IterateItemContext from '../IterateItemContext'\nimport ToolbarContext from '../Toolbar/ToolbarContext'\nimport FieldBoundaryContext from '../../DataContext/FieldBoundary/FieldBoundaryContext'\nimport PushContainerContext from '../PushContainer/PushContainerContext'\nimport { check } from '../../../../icons'\nimport { ButtonProps } from '../../../../components/Button'\n\ntype Props = ButtonProps\n\nexport default function DoneButton(props: Props) {\n const { switchContainerMode, containerMode, arrayValue, index } =\n useContext(IterateItemContext) || {}\n const { hasError, hasVisibleError, setShowBoundaryErrors } =\n useContext(FieldBoundaryContext) || {}\n const { commitHandleRef } = useContext(PushContainerContext) || {}\n useContext(FieldBoundaryContext) || {}\n const { setShowError } = useContext(ToolbarContext) || {}\n\n const { doneButton } = useTranslation().IterateEditContainer\n const valueBackupRef = useRef<unknown>()\n\n useEffect(() => {\n if (containerMode === 'edit' && !valueBackupRef.current) {\n valueBackupRef.current = arrayValue?.[index]\n }\n if (containerMode === 'view') {\n valueBackupRef.current = null\n }\n }, [arrayValue, containerMode, index])\n\n const doneHandler = useCallback(() => {\n if (hasError) {\n setShowBoundaryErrors?.(true)\n if (hasVisibleError) {\n setShowError(true)\n }\n } else {\n setShowBoundaryErrors?.(false)\n setShowError(false)\n if (commitHandleRef) {\n commitHandleRef.current?.()\n } else {\n switchContainerMode?.('view')\n }\n }\n }, [\n commitHandleRef,\n hasError,\n hasVisibleError,\n setShowBoundaryErrors,\n setShowError,\n switchContainerMode,\n ])\n\n return (\n <Button\n variant=\"tertiary\"\n icon={check}\n icon_position=\"left\"\n on_click={doneHandler}\n {...props}\n >\n {doneButton}\n </Button>\n )\n}\n"],"mappings":";;;AAAA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AACzE,SAASC,MAAM,QAAQ,wBAAwB;AAC/C,OAAOC,cAAc,MAAM,4BAA4B;AACvD,OAAOC,kBAAkB,MAAM,uBAAuB;AACtD,OAAOC,cAAc,MAAM,2BAA2B;AACtD,OAAOC,oBAAoB,MAAM,sDAAsD;AACvF,OAAOC,oBAAoB,MAAM,uCAAuC;AACxE,SAASC,KAAK,QAAQ,mBAAmB;AAKzC,eAAe,SAASC,UAAUA,CAACC,KAAY,EAAE;EAC/C,MAAM;IAAEC,mBAAmB;IAAEC,aAAa;IAAEC,UAAU;IAAEC;EAAM,CAAC,GAC7Df,UAAU,CAACK,kBAAkB,CAAC,IAAI,CAAC,CAAC;EACtC,MAAM;IAAEW,QAAQ;IAAEC,eAAe;IAAEC;EAAsB,CAAC,GACxDlB,UAAU,CAACO,oBAAoB,CAAC,IAAI,CAAC,CAAC;EACxC,MAAM;IAAEY;EAAgB,CAAC,GAAGnB,UAAU,CAACQ,oBAAoB,CAAC,IAAI,CAAC,CAAC;EAClER,UAAU,CAACO,oBAAoB,CAAC,IAAI,CAAC,CAAC;EACtC,MAAM;IAAEa;EAAa,CAAC,GAAGpB,UAAU,CAACM,cAAc,CAAC,IAAI,CAAC,CAAC;EAEzD,MAAM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IACZuB,aAAa,EAAC,MAAM;IACpBC,QAAQ,EAAER;EAAY,GAClBd,KAAK,GAERU,UACK,CAAC;AAEb"}
1
+ {"version":3,"file":"DoneButton.js","names":["React","useCallback","useContext","useEffect","useRef","Button","useTranslation","IterateItemContext","ToolbarContext","FieldBoundaryContext","PushContainerContext","check","DoneButton","props","switchContainerMode","containerMode","arrayValue","index","hasError","hasVisibleError","setShowBoundaryErrors","commitHandleRef","setShowError","doneButton","IterateEditContainer","valueBackupRef","current","doneHandler","_commitHandleRef$curr","call","createElement","_extends","variant","icon","icon_position","on_click"],"sources":["../../../../../../src/extensions/forms/Iterate/EditContainer/DoneButton.tsx"],"sourcesContent":["import React, { useCallback, useContext, useEffect, useRef } from 'react'\nimport { Button } from '../../../../components'\nimport useTranslation from '../../hooks/useTranslation'\nimport IterateItemContext from '../IterateItemContext'\nimport ToolbarContext from '../Toolbar/ToolbarContext'\nimport FieldBoundaryContext from '../../DataContext/FieldBoundary/FieldBoundaryContext'\nimport PushContainerContext from '../PushContainer/PushContainerContext'\nimport { check } from '../../../../icons'\nimport { ButtonProps } from '../../../../components/Button'\n\ntype Props = ButtonProps\n\nexport default function DoneButton(props: Props) {\n const { switchContainerMode, containerMode, arrayValue, index } =\n useContext(IterateItemContext) || {}\n const { hasError, hasVisibleError, setShowBoundaryErrors } =\n useContext(FieldBoundaryContext) || {}\n const { commitHandleRef } = useContext(PushContainerContext) || {}\n const { setShowError } = useContext(ToolbarContext) || {}\n\n const { doneButton } = useTranslation().IterateEditContainer\n const valueBackupRef = useRef<unknown>()\n\n useEffect(() => {\n if (containerMode === 'edit' && !valueBackupRef.current) {\n valueBackupRef.current = arrayValue?.[index]\n }\n if (containerMode === 'view') {\n valueBackupRef.current = null\n }\n }, [arrayValue, containerMode, index])\n\n const doneHandler = useCallback(() => {\n if (hasError) {\n setShowBoundaryErrors?.(true)\n if (hasVisibleError) {\n setShowError(true)\n }\n } else {\n setShowBoundaryErrors?.(false)\n setShowError(false)\n if (commitHandleRef) {\n commitHandleRef.current?.()\n } else {\n switchContainerMode?.('view')\n }\n }\n }, [\n commitHandleRef,\n hasError,\n hasVisibleError,\n setShowBoundaryErrors,\n setShowError,\n switchContainerMode,\n ])\n\n return (\n <Button\n variant=\"tertiary\"\n icon={check}\n icon_position=\"left\"\n on_click={doneHandler}\n {...props}\n >\n {doneButton}\n </Button>\n )\n}\n"],"mappings":";;;AAAA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AACzE,SAASC,MAAM,QAAQ,wBAAwB;AAC/C,OAAOC,cAAc,MAAM,4BAA4B;AACvD,OAAOC,kBAAkB,MAAM,uBAAuB;AACtD,OAAOC,cAAc,MAAM,2BAA2B;AACtD,OAAOC,oBAAoB,MAAM,sDAAsD;AACvF,OAAOC,oBAAoB,MAAM,uCAAuC;AACxE,SAASC,KAAK,QAAQ,mBAAmB;AAKzC,eAAe,SAASC,UAAUA,CAACC,KAAY,EAAE;EAC/C,MAAM;IAAEC,mBAAmB;IAAEC,aAAa;IAAEC,UAAU;IAAEC;EAAM,CAAC,GAC7Df,UAAU,CAACK,kBAAkB,CAAC,IAAI,CAAC,CAAC;EACtC,MAAM;IAAEW,QAAQ;IAAEC,eAAe;IAAEC;EAAsB,CAAC,GACxDlB,UAAU,CAACO,oBAAoB,CAAC,IAAI,CAAC,CAAC;EACxC,MAAM;IAAEY;EAAgB,CAAC,GAAGnB,UAAU,CAACQ,oBAAoB,CAAC,IAAI,CAAC,CAAC;EAClE,MAAM;IAAEY;EAAa,CAAC,GAAGpB,UAAU,CAACM,cAAc,CAAC,IAAI,CAAC,CAAC;EAEzD,MAAM;IAAEe;EAAW,CAAC,GAAGjB,cAAc,CAAC,CAAC,CAACkB,oBAAoB;EAC5D,MAAMC,cAAc,GAAGrB,MAAM,CAAU,CAAC;EAExCD,SAAS,CAAC,MAAM;IACd,IAAIY,aAAa,KAAK,MAAM,IAAI,CAACU,cAAc,CAACC,OAAO,EAAE;MACvDD,cAAc,CAACC,OAAO,GAAGV,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAGC,KAAK,CAAC;IAC9C;IACA,IAAIF,aAAa,KAAK,MAAM,EAAE;MAC5BU,cAAc,CAACC,OAAO,GAAG,IAAI;IAC/B;EACF,CAAC,EAAE,CAACV,UAAU,EAAED,aAAa,EAAEE,KAAK,CAAC,CAAC;EAEtC,MAAMU,WAAW,GAAG1B,WAAW,CAAC,MAAM;IACpC,IAAIiB,QAAQ,EAAE;MACZE,qBAAqB,aAArBA,qBAAqB,uBAArBA,qBAAqB,CAAG,IAAI,CAAC;MAC7B,IAAID,eAAe,EAAE;QACnBG,YAAY,CAAC,IAAI,CAAC;MACpB;IACF,CAAC,MAAM;MACLF,qBAAqB,aAArBA,qBAAqB,uBAArBA,qBAAqB,CAAG,KAAK,CAAC;MAC9BE,YAAY,CAAC,KAAK,CAAC;MACnB,IAAID,eAAe,EAAE;QAAA,IAAAO,qBAAA;QACnB,CAAAA,qBAAA,GAAAP,eAAe,CAACK,OAAO,cAAAE,qBAAA,uBAAvBA,qBAAA,CAAAC,IAAA,CAAAR,eAA0B,CAAC;MAC7B,CAAC,MAAM;QACLP,mBAAmB,aAAnBA,mBAAmB,uBAAnBA,mBAAmB,CAAG,MAAM,CAAC;MAC/B;IACF;EACF,CAAC,EAAE,CACDO,eAAe,EACfH,QAAQ,EACRC,eAAe,EACfC,qBAAqB,EACrBE,YAAY,EACZR,mBAAmB,CACpB,CAAC;EAEF,OACEd,KAAA,CAAA8B,aAAA,CAACzB,MAAM,EAAA0B,QAAA;IACLC,OAAO,EAAC,UAAU;IAClBC,IAAI,EAAEtB,KAAM;IACZuB,aAAa,EAAC,MAAM;IACpBC,QAAQ,EAAER;EAAY,GAClBd,KAAK,GAERU,UACK,CAAC;AAEb"}
@@ -2,8 +2,8 @@
2
2
 
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
- const _excluded = ["pushValue", "className", "path", "children"];
6
- import React, { useCallback, useContext } from 'react';
5
+ const _excluded = ["pushValue", "className", "path", "text", "children"];
6
+ import React, { useCallback, useContext, useMemo } from 'react';
7
7
  import classnames from 'classnames';
8
8
  import { Button } from '../../../../components';
9
9
  import IterateItemContext from '../IterateItemContext';
@@ -12,6 +12,7 @@ import { omitDataValueReadWriteProps } from '../../types';
12
12
  import { add } from '../../../../icons';
13
13
  import DataContext from '../../DataContext/Context';
14
14
  import useDataValue from '../../hooks/useDataValue';
15
+ import { convertJsxToString } from '../../../../shared/component-helper';
15
16
  function PushButton(props) {
16
17
  const {
17
18
  handlePathChange
@@ -24,12 +25,13 @@ function PushButton(props) {
24
25
  pushValue,
25
26
  className,
26
27
  path,
28
+ text,
27
29
  children
28
30
  } = props,
29
31
  restProps = _objectWithoutProperties(props, _excluded);
30
32
  const buttonProps = omitDataValueReadWriteProps(restProps);
31
- const value = useDataValue().getValueByPath(path);
32
- if (value !== undefined && !Array.isArray(value)) {
33
+ const arrayValue = useDataValue().getValueByPath(path);
34
+ if (arrayValue !== undefined && !Array.isArray(arrayValue)) {
33
35
  throw new Error('PushButton received a non-array value');
34
36
  }
35
37
  const {
@@ -38,23 +40,33 @@ function PushButton(props) {
38
40
  path
39
41
  });
40
42
  const handleClick = useCallback(async () => {
41
- const newValue = typeof pushValue === 'function' ? pushValue(value) : pushValue;
43
+ const newValue = typeof pushValue === 'function' ? pushValue(arrayValue) : pushValue;
42
44
  if (handlePush) {
43
45
  handlePush(newValue);
44
46
  } else {
45
- await (handlePathChange === null || handlePathChange === void 0 ? void 0 : handlePathChange(path, [...(value !== null && value !== void 0 ? value : []), newValue]));
47
+ await (handlePathChange === null || handlePathChange === void 0 ? void 0 : handlePathChange(path, [...(arrayValue !== null && arrayValue !== void 0 ? arrayValue : []), newValue]));
46
48
  }
47
49
  setTimeout(() => {
48
50
  setLastItemContainerMode('view');
49
51
  }, 100);
50
- }, [handlePathChange, handlePush, path, pushValue, setLastItemContainerMode, value]);
52
+ }, [handlePathChange, handlePush, path, pushValue, setLastItemContainerMode, arrayValue]);
53
+ const content = useMemo(() => {
54
+ if (children || text) {
55
+ const str = convertJsxToString(children || text);
56
+ if (str.includes('{nextItemNo}')) {
57
+ const nextItemNo = ((arrayValue === null || arrayValue === void 0 ? void 0 : arrayValue.length) || 0) + 1;
58
+ return str.replace('{nextItemNo}', String(nextItemNo));
59
+ }
60
+ }
61
+ return children || text;
62
+ }, [arrayValue === null || arrayValue === void 0 ? void 0 : arrayValue.length, children, text]);
51
63
  return React.createElement(Button, _extends({
52
64
  className: classnames('dnb-forms-iterate-push-button', className),
53
65
  variant: "secondary",
54
66
  icon: add,
55
67
  icon_position: "left",
56
68
  on_click: handleClick
57
- }, buttonProps), children);
69
+ }, buttonProps), content);
58
70
  }
59
71
  PushButton._supportsSpacingProps = true;
60
72
  export default PushButton;
@@ -1 +1 @@
1
- {"version":3,"file":"PushButton.js","names":["React","useCallback","useContext","classnames","Button","IterateItemContext","useSwitchContainerMode","omitDataValueReadWriteProps","add","DataContext","useDataValue","PushButton","props","handlePathChange","iterateItemContext","handlePush","pushValue","className","path","children","restProps","_objectWithoutProperties","_excluded","buttonProps","value","getValueByPath","undefined","Array","isArray","Error","setLastItemContainerMode","handleClick","newValue","setTimeout","createElement","_extends","variant","icon","icon_position","on_click","_supportsSpacingProps"],"sources":["../../../../../../src/extensions/forms/Iterate/PushButton/PushButton.tsx"],"sourcesContent":["import React, { useCallback, useContext } from 'react'\nimport classnames from 'classnames'\nimport { Button } from '../../../../components'\nimport { ButtonProps } from '../../../../components/Button'\nimport IterateItemContext from '../IterateItemContext'\nimport { useSwitchContainerMode } from '../hooks'\nimport { omitDataValueReadWriteProps, Path } from '../../types'\nimport { add } from '../../../../icons'\nimport DataContext from '../../DataContext/Context'\nimport useDataValue from '../../hooks/useDataValue'\n\nexport type Props = ButtonProps & {\n path?: Path\n pushValue: unknown | ((value: unknown) => void)\n\n /**\n * Used internally\n */\n value?: unknown\n}\n\nfunction PushButton(props: Props) {\n const { handlePathChange } = useContext(DataContext) || {}\n const iterateItemContext = useContext(IterateItemContext)\n const { handlePush } = iterateItemContext ?? {}\n\n const { pushValue, className, path, children, ...restProps } = props\n const buttonProps = omitDataValueReadWriteProps(restProps)\n const value = useDataValue().getValueByPath(path)\n\n if (value !== undefined && !Array.isArray(value)) {\n throw new Error('PushButton received a non-array value')\n }\n\n const { setLastItemContainerMode } = useSwitchContainerMode({\n path,\n })\n\n const handleClick = useCallback(async () => {\n const newValue =\n typeof pushValue === 'function' ? pushValue(value) : pushValue\n\n if (handlePush) {\n // Inside an Iterate element - make the change through the Iterate component\n handlePush(newValue)\n } else {\n // If not inside an iterate, it could still manipulate a source data set through useFieldProps\n await handlePathChange?.(path, [...(value ?? []), newValue])\n }\n\n setTimeout(() => {\n setLastItemContainerMode('view')\n }, 100) // UX improvement because of the \"openDelay\"\n }, [\n handlePathChange,\n handlePush,\n path,\n pushValue,\n setLastItemContainerMode,\n value,\n ])\n\n return (\n <Button\n className={classnames('dnb-forms-iterate-push-button', className)}\n variant=\"secondary\"\n icon={add}\n icon_position=\"left\"\n on_click={handleClick}\n {...buttonProps}\n >\n {children}\n </Button>\n )\n}\n\nPushButton._supportsSpacingProps = true\nexport default PushButton\n"],"mappings":";;;;;AAAA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,UAAU,QAAQ,OAAO;AACtD,OAAOC,UAAU,MAAM,YAAY;AACnC,SAASC,MAAM,QAAQ,wBAAwB;AAE/C,OAAOC,kBAAkB,MAAM,uBAAuB;AACtD,SAASC,sBAAsB,QAAQ,UAAU;AACjD,SAASC,2BAA2B,QAAc,aAAa;AAC/D,SAASC,GAAG,QAAQ,mBAAmB;AACvC,OAAOC,WAAW,MAAM,2BAA2B;AACnD,OAAOC,YAAY,MAAM,0BAA0B;AAYnD,SAASC,UAAUA,CAACC,KAAY,EAAE;EAChC,MAAM;IAAEC;EAAiB,CAAC,GAAGX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IAAI,EACJF,SAAS,EACTc,wBAAwB,EACxBN,KAAK,CACN,CAAC;EAEF,OACExB,KAAA,CAAAkC,aAAA,CAAC9B,MAAM,EAAA+B,QAAA;IACLlB,SAAS,EAAEd,UAAU,CAAC,+BAA+B,EAAEc,SAAS,CAAE;IAClEmB,OAAO,EAAC,WAAW;IACnBC,IAAI,EAAE7B,GAAI;IACV8B,aAAa,EAAC,MAAM;IACpBC,QAAQ,EAAER;EAAY,GAClBR,WAAW,GAEdJ,QACK,CAAC;AAEb;AAEAR,UAAU,CAAC6B,qBAAqB,GAAG,IAAI;AACvC,eAAe7B,UAAU"}
1
+ {"version":3,"file":"PushButton.js","names":["React","useCallback","useContext","useMemo","classnames","Button","IterateItemContext","useSwitchContainerMode","omitDataValueReadWriteProps","add","DataContext","useDataValue","convertJsxToString","PushButton","props","handlePathChange","iterateItemContext","handlePush","pushValue","className","path","text","children","restProps","_objectWithoutProperties","_excluded","buttonProps","arrayValue","getValueByPath","undefined","Array","isArray","Error","setLastItemContainerMode","handleClick","newValue","setTimeout","content","str","includes","nextItemNo","length","replace","String","createElement","_extends","variant","icon","icon_position","on_click","_supportsSpacingProps"],"sources":["../../../../../../src/extensions/forms/Iterate/PushButton/PushButton.tsx"],"sourcesContent":["import React, { useCallback, useContext, useMemo } from 'react'\nimport classnames from 'classnames'\nimport { Button } from '../../../../components'\nimport { ButtonProps } from '../../../../components/Button'\nimport IterateItemContext from '../IterateItemContext'\nimport { useSwitchContainerMode } from '../hooks'\nimport { omitDataValueReadWriteProps, Path } from '../../types'\nimport { add } from '../../../../icons'\nimport DataContext from '../../DataContext/Context'\nimport useDataValue from '../../hooks/useDataValue'\nimport { convertJsxToString } from '../../../../shared/component-helper'\n\nexport type Props = ButtonProps & {\n path?: Path\n pushValue: unknown | ((value: unknown) => void)\n\n /**\n * Used internally\n */\n value?: unknown\n}\n\nfunction PushButton(props: Props) {\n const { handlePathChange } = useContext(DataContext) || {}\n const iterateItemContext = useContext(IterateItemContext)\n const { handlePush } = iterateItemContext ?? {}\n\n const { pushValue, className, path, text, children, ...restProps } =\n props\n const buttonProps = omitDataValueReadWriteProps(restProps)\n const arrayValue = useDataValue().getValueByPath(path)\n\n if (arrayValue !== undefined && !Array.isArray(arrayValue)) {\n throw new Error('PushButton received a non-array value')\n }\n\n const { setLastItemContainerMode } = useSwitchContainerMode({\n path,\n })\n\n const handleClick = useCallback(async () => {\n const newValue =\n typeof pushValue === 'function' ? pushValue(arrayValue) : pushValue\n\n if (handlePush) {\n // Inside an Iterate element - make the change through the Iterate component\n handlePush(newValue)\n } else {\n // If not inside an iterate, it could still manipulate a source data set through useFieldProps\n await handlePathChange?.(path, [...(arrayValue ?? []), newValue])\n }\n\n setTimeout(() => {\n setLastItemContainerMode('view')\n }, 100) // UX improvement because of the \"openDelay\"\n }, [\n handlePathChange,\n handlePush,\n path,\n pushValue,\n setLastItemContainerMode,\n arrayValue,\n ])\n\n const content = useMemo(() => {\n if (children || text) {\n const str = convertJsxToString(children || text)\n\n if (str.includes('{nextItemNo}')) {\n const nextItemNo = (arrayValue?.length || 0) + 1\n return str.replace('{nextItemNo}', String(nextItemNo))\n }\n }\n\n return children || text\n }, [arrayValue?.length, children, text])\n\n return (\n <Button\n className={classnames('dnb-forms-iterate-push-button', className)}\n variant=\"secondary\"\n icon={add}\n icon_position=\"left\"\n on_click={handleClick}\n {...buttonProps}\n >\n {content}\n </Button>\n )\n}\n\nPushButton._supportsSpacingProps = true\nexport default PushButton\n"],"mappings":";;;;;AAAA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,UAAU,EAAEC,OAAO,QAAQ,OAAO;AAC/D,OAAOC,UAAU,MAAM,YAAY;AACnC,SAASC,MAAM,QAAQ,wBAAwB;AAE/C,OAAOC,kBAAkB,MAAM,uBAAuB;AACtD,SAASC,sBAAsB,QAAQ,UAAU;AACjD,SAASC,2BAA2B,QAAc,aAAa;AAC/D,SAASC,GAAG,QAAQ,mBAAmB;AACvC,OAAOC,WAAW,MAAM,2B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QAAQ,CAAC,CAAC;IACnE;IAEAC,UAAU,CAAC,MAAM;MACfH,wBAAwB,CAAC,MAAM,CAAC;IAClC,CAAC,EAAE,GAAG,CAAC;EACT,CAAC,EAAE,CACDlB,gBAAgB,EAChBE,UAAU,EACVG,IAAI,EACJF,SAAS,EACTe,wBAAwB,EACxBN,UAAU,CACX,CAAC;EAEF,MAAMU,OAAO,GAAGlC,OAAO,CAAC,MAAM;IAC5B,IAAImB,QAAQ,IAAID,IAAI,EAAE;MACpB,MAAMiB,GAAG,GAAG1B,kBAAkB,CAACU,QAAQ,IAAID,IAAI,CAAC;MAEhD,IAAIiB,GAAG,CAACC,QAAQ,CAAC,cAAc,CAAC,EAAE;QAChC,MAAMC,UAAU,GAAG,CAAC,CAAAb,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEc,MAAM,KAAI,CAAC,IAAI,CAAC;QAChD,OAAOH,GAAG,CAACI,OAAO,CAAC,cAAc,EAAEC,MAAM,CAACH,UAAU,CAAC,CAAC;MACxD;IACF;IAEA,OAAOlB,QAAQ,IAAID,IAAI;EACzB,CAAC,EAAE,CAACM,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEc,MAAM,EAAEnB,QAAQ,EAAED,IAAI,CAAC,CAAC;EAExC,OACErB,KAAA,CAAA4C,aAAA,CAACvC,MAAM,EAAAwC,QAAA;IACL1B,SAAS,EAAEf,UAAU,CAAC,+BAA+B,EAAEe,SAAS,CAAE;IAClE2B,OAAO,EAAC,WAAW;IACnBC,IAAI,EAAEtC,GAAI;IACVuC,aAAa,EAAC,MAAM;IACpBC,QAAQ,EAAEf;EAAY,GAClBR,WAAW,GAEdW,OACK,CAAC;AAEb;AAEAxB,UAAU,CAACqC,qBAAqB,GAAG,IAAI;AACvC,eAAerC,UAAU"}
@@ -2,31 +2,47 @@
2
2
 
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
- const _excluded = ["className", "children"];
6
- import React, { useCallback, useContext } from 'react';
5
+ const _excluded = ["className", "text", "children"];
6
+ import React, { useCallback, useContext, useMemo } from 'react';
7
7
  import classnames from 'classnames';
8
8
  import Button from '../../../../components/Button';
9
9
  import { add } from '../../../../icons';
10
10
  import IterateItemContext from '../IterateItemContext';
11
+ import PushContainerContext from './PushContainerContext';
12
+ import { convertJsxToString } from '../../../../shared/component-helper';
11
13
  function OpenButton(props) {
12
14
  const {
13
15
  className,
16
+ text,
14
17
  children
15
18
  } = props,
16
19
  restProps = _objectWithoutProperties(props, _excluded);
17
20
  const {
18
21
  switchContainerMode
19
22
  } = useContext(IterateItemContext) || {};
23
+ const {
24
+ entries
25
+ } = useContext(PushContainerContext) || {};
20
26
  const handleClick = useCallback(() => {
21
27
  switchContainerMode === null || switchContainerMode === void 0 ? void 0 : switchContainerMode('edit');
22
28
  }, [switchContainerMode]);
29
+ const content = useMemo(() => {
30
+ if (children || text) {
31
+ const str = convertJsxToString(children || text);
32
+ if (str.includes('{nextItemNo}')) {
33
+ const nextItemNo = ((entries === null || entries === void 0 ? void 0 : entries.length) || 0) + 1;
34
+ return str.replace('{nextItemNo}', String(nextItemNo));
35
+ }
36
+ }
37
+ return children || text;
38
+ }, [entries === null || entries === void 0 ? void 0 : entries.length, children, text]);
23
39
  return React.createElement(Button, _extends({
24
40
  className: classnames('dnb-forms-iterate-open-button', className),
25
41
  variant: "secondary",
26
42
  icon: add,
27
43
  icon_position: "left",
28
44
  on_click: handleClick
29
- }, restProps), children);
45
+ }, restProps), content);
30
46
  }
31
47
  export default OpenButton;
32
48
  //# sourceMappingURL=OpenButton.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"OpenButton.js","names":["React","useCallback","useContext","classnames","Button","add","IterateItemContext","OpenButton","props","className","children","restProps","_objectWithoutProperties","_excluded","switchContainerMode","handleClick","createElement","_extends","variant","icon","icon_position","on_click"],"sources":["../../../../../../src/extensions/forms/Iterate/PushContainer/OpenButton.tsx"],"sourcesContent":["import React, { useCallback, useContext } from 'react'\nimport classnames from 'classnames'\nimport Button, { ButtonProps } from '../../../../components/Button'\nimport { add } from '../../../../icons'\nimport IterateItemContext from '../IterateItemContext'\n\ntype Props = ButtonProps\n\nfunction OpenButton(props: Props) {\n const { className, children, ...restProps } = props\n const { switchContainerMode } = useContext(IterateItemContext) || {}\n\n const handleClick = useCallback(() => {\n switchContainerMode?.('edit')\n }, [switchContainerMode])\n\n return (\n <Button\n className={classnames('dnb-forms-iterate-open-button', className)}\n variant=\"secondary\"\n icon={add}\n icon_position=\"left\"\n on_click={handleClick}\n {...restProps}\n >\n {children}\n </Button>\n )\n}\n\nexport default OpenButton\n"],"mappings":";;;;;AAAA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,UAAU,QAAQ,OAAO;AACtD,OAAOC,UAAU,MAAM,YAAY;AACnC,OAAOC,MAAM,MAAuB,+BAA+B;AACnE,SAASC,GAAG,QAAQ,mBAAmB;AACvC,OAAOC,kBAAkB,MAAM,uBAAuB;AAItD,SAASC,UAAUA,CAACC,KAAY,EAAE;EAChC,MAAM;MAAEC,SAAS;MAAEC;IAAuB,CAAC,GAAGF,KAAK;IAAnBG,SAAS,GAAAC,wBAAA,CAAKJ,KAAK,EAAAK,SAAA;EACnD,MAAM;IAAEC;EAAoB,CAAC,GAAGZ,UAAU,CAACI,kBAAkB,CAAC,IAAI,CAAC,CAAC;EAEpE,MAAMS,WAAW,GAAGd,WAAW,CAAC,MAAM;IACpCa,mBAAmB,aAAnBA,mBAAmB,uBAAnBA,mBAAmB,CAAG,MAAM,CAAC;EAC/B,CAAC,EAAE,CAACA,mBAAmB,CAAC,CAAC;EAEzB,OACEd,KAAA,CAAAgB,aAAA,CAACZ,MAAM,EAAAa,QAAA;IACLR,SAAS,EAAEN,UAAU,CAAC,+BAA+B,EAAEM,SAAS,CAAE;IAClES,OAAO,EAAC,WAAW;IACnBC,IAAI,EAAEd,GAAI;IACVe,aAAa,EAAC,MAAM;IACpBC,QAAQ,EAAEN;EAAY,GAClBJ,SAAS,GAEZD,QACK,CAAC;AAEb;AAEA,eAAeH,UAAU"}
1
+ {"version":3,"file":"OpenButton.js","names":["React","useCallback","useContext","useMemo","classnames","Button","add","IterateItemContext","PushContainerContext","convertJsxToString","OpenButton","props","className","text","children","restProps","_objectWithoutProperties","_excluded","switchContainerMode","entries","handleClick","content","str","includes","nextItemNo","length","replace","String","createElement","_extends","variant","icon","icon_position","on_click"],"sources":["../../../../../../src/extensions/forms/Iterate/PushContainer/OpenButton.tsx"],"sourcesContent":["import React, { useCallback, useContext, useMemo } from 'react'\nimport classnames from 'classnames'\nimport Button, { ButtonProps } from '../../../../components/Button'\nimport { add } from '../../../../icons'\nimport IterateItemContext from '../IterateItemContext'\nimport PushContainerContext from './PushContainerContext'\nimport { convertJsxToString } from '../../../../shared/component-helper'\n\ntype Props = ButtonProps\n\nfunction OpenButton(props: Props) {\n const { className, text, children, ...restProps } = props\n const { switchContainerMode } = useContext(IterateItemContext) || {}\n const { entries } = useContext(PushContainerContext) || {}\n\n const handleClick = useCallback(() => {\n switchContainerMode?.('edit')\n }, [switchContainerMode])\n\n const content = useMemo(() => {\n if (children || text) {\n const str = convertJsxToString(children || text)\n\n if (str.includes('{nextItemNo}')) {\n const nextItemNo = (entries?.length || 0) + 1\n return str.replace('{nextItemNo}', String(nextItemNo))\n }\n }\n\n return children || text\n }, [entries?.length, children, text])\n\n return (\n <Button\n className={classnames('dnb-forms-iterate-open-button', className)}\n variant=\"secondary\"\n icon={add}\n icon_position=\"left\"\n on_click={handleClick}\n {...restProps}\n >\n {content}\n </Button>\n )\n}\n\nexport default OpenButton\n"],"mappings":";;;;;AAAA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,UAAU,EAAEC,OAAO,QAAQ,OAAO;AAC/D,OAAOC,UAAU,MAAM,YAAY;AACnC,OAAOC,MAAM,MAAuB,+BAA+B;AACnE,SAASC,GAAG,QAAQ,mBAAmB;AACvC,OAAOC,kBAAkB,MAAM,uBAAu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