@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.
- package/CHANGELOG.md +19 -0
- package/cjs/components/height-animation/HeightAnimationInstance.d.ts +1 -0
- package/cjs/components/height-animation/HeightAnimationInstance.js +13 -6
- package/cjs/components/height-animation/HeightAnimationInstance.js.map +1 -1
- package/cjs/extensions/forms/DataContext/Context.d.ts +6 -4
- package/cjs/extensions/forms/DataContext/Context.js +1 -2
- package/cjs/extensions/forms/DataContext/Context.js.map +1 -1
- package/cjs/extensions/forms/DataContext/FieldBoundary/FieldBoundaryContext.d.ts +4 -0
- package/cjs/extensions/forms/DataContext/FieldBoundary/FieldBoundaryContext.js.map +1 -1
- package/cjs/extensions/forms/DataContext/FieldBoundary/FieldBoundaryProvider.js +13 -4
- package/cjs/extensions/forms/DataContext/FieldBoundary/FieldBoundaryProvider.js.map +1 -1
- package/cjs/extensions/forms/DataContext/Provider/Provider.d.ts +0 -4
- package/cjs/extensions/forms/DataContext/Provider/Provider.js +27 -28
- package/cjs/extensions/forms/DataContext/Provider/Provider.js.map +1 -1
- package/cjs/extensions/forms/Form/Isolation/Isolation.js +5 -4
- package/cjs/extensions/forms/Form/Isolation/Isolation.js.map +1 -1
- package/cjs/extensions/forms/Iterate/Array/Array.js +12 -6
- package/cjs/extensions/forms/Iterate/Array/Array.js.map +1 -1
- package/cjs/extensions/forms/Iterate/Array/ArrayDocs.js +6 -1
- package/cjs/extensions/forms/Iterate/Array/ArrayDocs.js.map +1 -1
- package/cjs/extensions/forms/Iterate/Array/ArrayItemArea.d.ts +1 -1
- package/cjs/extensions/forms/Iterate/Array/ArrayItemArea.js.map +1 -1
- package/cjs/extensions/forms/Iterate/Array/types.d.ts +1 -0
- package/cjs/extensions/forms/Iterate/Array/types.js.map +1 -1
- package/cjs/extensions/forms/Iterate/EditContainer/DoneButton.js +0 -1
- package/cjs/extensions/forms/Iterate/EditContainer/DoneButton.js.map +1 -1
- package/cjs/extensions/forms/Iterate/PushButton/PushButton.js +19 -7
- package/cjs/extensions/forms/Iterate/PushButton/PushButton.js.map +1 -1
- package/cjs/extensions/forms/Iterate/PushContainer/OpenButton.js +18 -2
- package/cjs/extensions/forms/Iterate/PushContainer/OpenButton.js.map +1 -1
- package/cjs/extensions/forms/Iterate/PushContainer/PushContainer.d.ts +2 -1
- package/cjs/extensions/forms/Iterate/PushContainer/PushContainer.js.map +1 -1
- package/cjs/extensions/forms/Iterate/PushContainer/PushContainerDocs.js +5 -0
- package/cjs/extensions/forms/Iterate/PushContainer/PushContainerDocs.js.map +1 -1
- package/cjs/extensions/forms/Iterate/RemoveButton/RemoveButton.js +3 -5
- package/cjs/extensions/forms/Iterate/RemoveButton/RemoveButton.js.map +1 -1
- package/cjs/extensions/forms/Wizard/Step/Step.d.ts +1 -1
- package/cjs/extensions/forms/Wizard/Step/Step.js.map +1 -1
- package/cjs/extensions/forms/hooks/useFieldProps.js +20 -14
- package/cjs/extensions/forms/hooks/useFieldProps.js.map +1 -1
- package/cjs/shared/Eufemia.d.ts +1 -1
- package/cjs/shared/Eufemia.js +2 -2
- package/cjs/shared/Eufemia.js.map +1 -1
- package/cjs/style/core/scopes.scss +1 -1
- package/cjs/style/dnb-ui-basis.css +1 -1
- package/cjs/style/dnb-ui-basis.min.css +1 -1
- package/cjs/style/dnb-ui-body.css +1 -1
- package/cjs/style/dnb-ui-body.min.css +1 -1
- package/cjs/style/dnb-ui-core.css +1 -1
- package/cjs/style/dnb-ui-core.min.css +1 -1
- package/components/height-animation/HeightAnimationInstance.d.ts +1 -0
- package/components/height-animation/HeightAnimationInstance.js +13 -6
- package/components/height-animation/HeightAnimationInstance.js.map +1 -1
- package/es/components/height-animation/HeightAnimationInstance.d.ts +1 -0
- package/es/components/height-animation/HeightAnimationInstance.js +13 -6
- package/es/components/height-animation/HeightAnimationInstance.js.map +1 -1
- package/es/extensions/forms/DataContext/Context.d.ts +6 -4
- package/es/extensions/forms/DataContext/Context.js +1 -2
- package/es/extensions/forms/DataContext/Context.js.map +1 -1
- package/es/extensions/forms/DataContext/FieldBoundary/FieldBoundaryContext.d.ts +4 -0
- package/es/extensions/forms/DataContext/FieldBoundary/FieldBoundaryContext.js.map +1 -1
- package/es/extensions/forms/DataContext/FieldBoundary/FieldBoundaryProvider.js +13 -4
- package/es/extensions/forms/DataContext/FieldBoundary/FieldBoundaryProvider.js.map +1 -1
- package/es/extensions/forms/DataContext/Provider/Provider.d.ts +0 -4
- package/es/extensions/forms/DataContext/Provider/Provider.js +27 -26
- package/es/extensions/forms/DataContext/Provider/Provider.js.map +1 -1
- package/es/extensions/forms/Form/Isolation/Isolation.js +5 -4
- package/es/extensions/forms/Form/Isolation/Isolation.js.map +1 -1
- package/es/extensions/forms/Iterate/Array/Array.js +14 -8
- package/es/extensions/forms/Iterate/Array/Array.js.map +1 -1
- package/es/extensions/forms/Iterate/Array/ArrayDocs.js +6 -1
- package/es/extensions/forms/Iterate/Array/ArrayDocs.js.map +1 -1
- package/es/extensions/forms/Iterate/Array/ArrayItemArea.d.ts +1 -1
- package/es/extensions/forms/Iterate/Array/ArrayItemArea.js.map +1 -1
- package/es/extensions/forms/Iterate/Array/types.d.ts +1 -0
- package/es/extensions/forms/Iterate/Array/types.js.map +1 -1
- package/es/extensions/forms/Iterate/EditContainer/DoneButton.js +0 -1
- package/es/extensions/forms/Iterate/EditContainer/DoneButton.js.map +1 -1
- package/es/extensions/forms/Iterate/PushButton/PushButton.js +20 -8
- package/es/extensions/forms/Iterate/PushButton/PushButton.js.map +1 -1
- package/es/extensions/forms/Iterate/PushContainer/OpenButton.js +19 -3
- package/es/extensions/forms/Iterate/PushContainer/OpenButton.js.map +1 -1
- package/es/extensions/forms/Iterate/PushContainer/PushContainer.d.ts +2 -1
- package/es/extensions/forms/Iterate/PushContainer/PushContainer.js.map +1 -1
- package/es/extensions/forms/Iterate/PushContainer/PushContainerDocs.js +5 -0
- package/es/extensions/forms/Iterate/PushContainer/PushContainerDocs.js.map +1 -1
- package/es/extensions/forms/Iterate/RemoveButton/RemoveButton.js +4 -6
- package/es/extensions/forms/Iterate/RemoveButton/RemoveButton.js.map +1 -1
- package/es/extensions/forms/Wizard/Step/Step.d.ts +1 -1
- package/es/extensions/forms/Wizard/Step/Step.js.map +1 -1
- package/es/extensions/forms/hooks/useFieldProps.js +20 -14
- package/es/extensions/forms/hooks/useFieldProps.js.map +1 -1
- package/es/shared/Eufemia.d.ts +1 -1
- package/es/shared/Eufemia.js +2 -2
- package/es/shared/Eufemia.js.map +1 -1
- package/es/style/core/scopes.scss +1 -1
- package/es/style/dnb-ui-basis.css +1 -1
- package/es/style/dnb-ui-basis.min.css +1 -1
- package/es/style/dnb-ui-body.css +1 -1
- package/es/style/dnb-ui-body.min.css +1 -1
- package/es/style/dnb-ui-core.css +1 -1
- package/es/style/dnb-ui-core.min.css +1 -1
- package/esm/dnb-ui-basis.min.mjs +1 -1
- package/esm/dnb-ui-components.min.mjs +1 -1
- package/esm/dnb-ui-elements.min.mjs +1 -1
- package/esm/dnb-ui-extensions.min.mjs +2 -2
- package/esm/dnb-ui-lib.min.mjs +1 -1
- package/extensions/forms/DataContext/Context.d.ts +6 -4
- package/extensions/forms/DataContext/Context.js +1 -2
- package/extensions/forms/DataContext/Context.js.map +1 -1
- package/extensions/forms/DataContext/FieldBoundary/FieldBoundaryContext.d.ts +4 -0
- package/extensions/forms/DataContext/FieldBoundary/FieldBoundaryContext.js.map +1 -1
- package/extensions/forms/DataContext/FieldBoundary/FieldBoundaryProvider.js +13 -4
- package/extensions/forms/DataContext/FieldBoundary/FieldBoundaryProvider.js.map +1 -1
- package/extensions/forms/DataContext/Provider/Provider.d.ts +0 -4
- package/extensions/forms/DataContext/Provider/Provider.js +27 -26
- package/extensions/forms/DataContext/Provider/Provider.js.map +1 -1
- package/extensions/forms/Form/Isolation/Isolation.js +5 -4
- package/extensions/forms/Form/Isolation/Isolation.js.map +1 -1
- package/extensions/forms/Iterate/Array/Array.js +14 -8
- package/extensions/forms/Iterate/Array/Array.js.map +1 -1
- package/extensions/forms/Iterate/Array/ArrayDocs.js +6 -1
- package/extensions/forms/Iterate/Array/ArrayDocs.js.map +1 -1
- package/extensions/forms/Iterate/Array/ArrayItemArea.d.ts +1 -1
- package/extensions/forms/Iterate/Array/ArrayItemArea.js.map +1 -1
- package/extensions/forms/Iterate/Array/types.d.ts +1 -0
- package/extensions/forms/Iterate/Array/types.js.map +1 -1
- package/extensions/forms/Iterate/EditContainer/DoneButton.js +0 -1
- package/extensions/forms/Iterate/EditContainer/DoneButton.js.map +1 -1
- package/extensions/forms/Iterate/PushButton/PushButton.js +20 -8
- package/extensions/forms/Iterate/PushButton/PushButton.js.map +1 -1
- package/extensions/forms/Iterate/PushContainer/OpenButton.js +19 -3
- package/extensions/forms/Iterate/PushContainer/OpenButton.js.map +1 -1
- package/extensions/forms/Iterate/PushContainer/PushContainer.d.ts +2 -1
- package/extensions/forms/Iterate/PushContainer/PushContainer.js.map +1 -1
- package/extensions/forms/Iterate/PushContainer/PushContainerDocs.js +5 -0
- package/extensions/forms/Iterate/PushContainer/PushContainerDocs.js.map +1 -1
- package/extensions/forms/Iterate/RemoveButton/RemoveButton.js +4 -6
- package/extensions/forms/Iterate/RemoveButton/RemoveButton.js.map +1 -1
- package/extensions/forms/Wizard/Step/Step.d.ts +1 -1
- package/extensions/forms/Wizard/Step/Step.js.map +1 -1
- package/extensions/forms/hooks/useFieldProps.js +20 -14
- package/extensions/forms/hooks/useFieldProps.js.map +1 -1
- package/package.json +1 -1
- package/shared/Eufemia.d.ts +1 -1
- package/shared/Eufemia.js +2 -2
- package/shared/Eufemia.js.map +1 -1
- package/style/core/scopes.scss +1 -1
- package/style/dnb-ui-basis.css +1 -1
- package/style/dnb-ui-basis.min.css +1 -1
- package/style/dnb-ui-body.css +1 -1
- package/style/dnb-ui-body.min.css +1 -1
- package/style/dnb-ui-core.css +1 -1
- package/style/dnb-ui-core.min.css +1 -1
- package/umd/dnb-ui-basis.min.js +1 -1
- package/umd/dnb-ui-components.min.js +1 -1
- package/umd/dnb-ui-elements.min.js +1 -1
- package/umd/dnb-ui-extensions.min.js +2 -2
- package/umd/dnb-ui-lib.min.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
All notable changes to @dnb/eufemia will be documented in this file. See
|
|
4
4
|
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [10.49.0](https://github.com/dnbexperience/eufemia/compare/v10.48.0...v10.49.0) (2024-09-16)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### :sparkles: Features
|
|
10
|
+
|
|
11
|
+
* **Forms:** add `{nextItemNo}` support to Iterate.PushButton ([#3936](https://github.com/dnbexperience/eufemia/issues/3936)) ([c1445a3](https://github.com/dnbexperience/eufemia/commit/c1445a3db8b4ddd343d4093510e2b70ac94dddf7))
|
|
12
|
+
* **Forms:** add `{nextItemNo}` support to Iterate.PushContainer open button ([#3937](https://github.com/dnbexperience/eufemia/issues/3937)) ([84e8281](https://github.com/dnbexperience/eufemia/commit/84e82817637bdd2392841d484a4c564e6f670618))
|
|
13
|
+
* **Forms:** add `animate` prop to Iterate.Array ([#3928](https://github.com/dnbexperience/eufemia/issues/3928)) ([1d9f3e4](https://github.com/dnbexperience/eufemia/commit/1d9f3e43e98faf5ba3663129eb6b7fa0ac73df8b))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### :bug: Bug Fixes
|
|
17
|
+
|
|
18
|
+
* **ChildrenWithAge:** fixes spacing issue above 1st child ([#3942](https://github.com/dnbexperience/eufemia/issues/3942)) ([0f9dff3](https://github.com/dnbexperience/eufemia/commit/0f9dff3c90a3e8d0b4f002fdb30d2e076f1e323e))
|
|
19
|
+
* **Forms:** enhance container boundary error handling ([#3939](https://github.com/dnbexperience/eufemia/issues/3939)) ([e4691a0](https://github.com/dnbexperience/eufemia/commit/e4691a0e5361c801e9551d3073fad551428acb0d))
|
|
20
|
+
* **Forms:** remove unwanted Iterate.EditContainer error confirmation when using required on Form.Handler ([#3938](https://github.com/dnbexperience/eufemia/issues/3938)) ([4523e35](https://github.com/dnbexperience/eufemia/commit/4523e350f01536bf909a13d737fa0b6423405510))
|
|
21
|
+
* **Forms:** Wizard.Step JSX component TypeScript fix ([#3935](https://github.com/dnbexperience/eufemia/issues/3935)) ([5556182](https://github.com/dnbexperience/eufemia/commit/5556182a0983a11fe952cba9fb34f188d22b60dc))
|
|
22
|
+
* **HeightAnimation:** enhance adjusting the height to 0 ([#3929](https://github.com/dnbexperience/eufemia/issues/3929)) ([a1f6129](https://github.com/dnbexperience/eufemia/commit/a1f6129d0342d8870db7bd07ddab0556cf926c09))
|
|
23
|
+
* **PushContainer:** Add missing variant type ([#3931](https://github.com/dnbexperience/eufemia/issues/3931)) ([32d41b9](https://github.com/dnbexperience/eufemia/commit/32d41b93c4f7f4a65e4bcde4c56e4d335aa65a1f))
|
|
24
|
+
|
|
6
25
|
## [10.48.0](https://github.com/dnbexperience/eufemia/compare/v10.47.0...v10.48.0) (2024-09-12)
|
|
7
26
|
|
|
8
27
|
|
|
@@ -51,6 +51,7 @@ export default class HeightAnimation {
|
|
|
51
51
|
setAsClosed(): void;
|
|
52
52
|
getHeight(): number;
|
|
53
53
|
getUnknownHeight(): number;
|
|
54
|
+
withFallback(elem: HTMLElement, key: 'clientHeight' | 'clientWidth', fallback?: 'data-height' | 'data-width'): number;
|
|
54
55
|
onStart(fn: HeightAnimationOnStartCallback): void;
|
|
55
56
|
onEnd(fn: HeightAnimationOnEndCallback): void;
|
|
56
57
|
start(fromHeight: HeightAnimationFromHeight, toHeight: HeightAnimationToHeight): void;
|
|
@@ -137,11 +137,11 @@ class HeightAnimation {
|
|
|
137
137
|
this.callAnimationEnd();
|
|
138
138
|
}
|
|
139
139
|
getHeight() {
|
|
140
|
-
var _this$
|
|
141
|
-
return
|
|
140
|
+
var _this$withFallback;
|
|
141
|
+
return (_this$withFallback = this.withFallback(this.elem, 'clientHeight')) !== null && _this$withFallback !== void 0 ? _this$withFallback : null;
|
|
142
142
|
}
|
|
143
143
|
getUnknownHeight() {
|
|
144
|
-
var _this$elem$parentNode, _clonedElem$parentNod;
|
|
144
|
+
var _this$elem$parentNode, _this$withFallback2, _this$withFallback3, _clonedElem$parentNod;
|
|
145
145
|
if (!this.elem) {
|
|
146
146
|
return null;
|
|
147
147
|
}
|
|
@@ -160,17 +160,24 @@ class HeightAnimation {
|
|
|
160
160
|
clonedElem.style.position = 'absolute';
|
|
161
161
|
(_this$elem$parentNode = this.elem.parentNode) === null || _this$elem$parentNode === void 0 ? void 0 : _this$elem$parentNode.insertBefore(clonedElem, this.elem.nextSibling);
|
|
162
162
|
const elemWidth = this.elem.clientWidth;
|
|
163
|
-
const clonedWidth =
|
|
163
|
+
const clonedWidth = (_this$withFallback2 = this.withFallback(clonedElem, 'clientWidth', 'data-width')) !== null && _this$withFallback2 !== void 0 ? _this$withFallback2 : 0;
|
|
164
164
|
if (clonedWidth > elemWidth) {
|
|
165
165
|
clonedElem.style.width = `${elemWidth}px`;
|
|
166
166
|
}
|
|
167
|
-
const height =
|
|
167
|
+
const height = (_this$withFallback3 = this.withFallback(this.elem, 'clientHeight', 'data-height')) !== null && _this$withFallback3 !== void 0 ? _this$withFallback3 : null;
|
|
168
168
|
(_clonedElem$parentNod = clonedElem.parentNode) === null || _clonedElem$parentNod === void 0 ? void 0 : _clonedElem$parentNod.removeChild(clonedElem);
|
|
169
169
|
if (height) {
|
|
170
170
|
this.__currentHeight = height;
|
|
171
171
|
}
|
|
172
172
|
return height;
|
|
173
173
|
}
|
|
174
|
+
withFallback(elem, key, fallback) {
|
|
175
|
+
const val = fallback && elem.hasAttribute(fallback) ? parseFloat(elem.getAttribute(fallback)) : elem === null || elem === void 0 ? void 0 : elem[key];
|
|
176
|
+
if (isNaN(val)) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
return val;
|
|
180
|
+
}
|
|
174
181
|
onStart(fn) {
|
|
175
182
|
this.onStartStack.push(fn);
|
|
176
183
|
}
|
|
@@ -254,7 +261,7 @@ class HeightAnimation {
|
|
|
254
261
|
if (!this.elem || opts.animate === false || this.state === 'opening' || this.state === 'closing') {
|
|
255
262
|
return;
|
|
256
263
|
}
|
|
257
|
-
if (fromHeight ===
|
|
264
|
+
if (fromHeight === null) {
|
|
258
265
|
fromHeight = this.getHeight();
|
|
259
266
|
}
|
|
260
267
|
if (toHeight === null) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HeightAnimationInstance.js","names":["HeightAnimation","constructor","opts","arguments","length","undefined","_defineProperty","animate","visibility","opacity","height","isInBrowser","window","setState","setOptions","callAnimationStart","startTime","Date","now","firstTime","onStartStack","forEach","fn","state","callAnimationEnd","isAnimating","__currentHeight","removeEndEvents","onEndStack","addEndEvent","listener","_this$elem","_this$elem$addEventLi","handleTransitionEnd","e","canFinish","delay","duration","timeouts","push","setTimeout","events","elem","addEventListener","call","_this$elem2","_this$elem2$removeEve","removeEventListener","setElement","_this$elem3","_globalThis$animation","document","createElement","String","nodeName","toLowerCase","parentElement","globalThis","animationDuration","parseFloat","getComputedStyle","transitionDuration","Object","freeze","_objectSpread","getOptions","remove","stop","setAsOpen","setAsClosed","getHeight","_this$elem4","clientHeight","getUnknownHeight","_this$elem$parentNode","_clonedElem$parentNod","clonedElem","cloneNode","inputs","querySelectorAll","input","removeAttribute","key","firstPaintStyle","style","position","parentNode","insertBefore","nextSibling","elemWidth","clientWidth","clonedWidth","getAttribute","width","removeChild","onStart","onEnd","start","fromHeight","toHeight","requestAnimationFrame","reqId1","reqId2","id","clearTimeout","cancelAnimationFrame","open","shouldBypassAnimation","target","currentTarget","overflowY","readjust","close","adjustTo","endHeight","newHeight","_globalThis$animation2","Boolean","_globalThis$bypassTim","IS_TEST","bypassTime","exports","default"],"sources":["../../../../src/components/height-animation/HeightAnimationInstance.ts"],"sourcesContent":["export type HeightAnimationOnStartStates =\n | 'opening'\n | 'closing'\n | 'adjusting'\nexport type HeightAnimationOnEndStates = 'opened' | 'closed' | 'adjusted'\nexport type HeightAnimationStates =\n | HeightAnimationOnStartStates\n | HeightAnimationOnEndStates\n | 'init'\nexport type HeightAnimationOptions = {\n animate?: boolean\n}\nexport type HeightAnimationOnStartCallback = (\n state: HeightAnimationStates\n) => void\nexport type HeightAnimationOnEndCallback = (\n state: HeightAnimationStates\n) => void\nexport type HeightAnimationOnStartStack =\n Array<HeightAnimationOnStartCallback>\nexport type HeightAnimationOnEndStack = Array<HeightAnimationOnEndCallback>\nexport type HeightAnimationEventListener = (e: Event) => void\nexport type HeightAnimationEvents = Array<HeightAnimationEventListener>\nexport type HeightAnimationElement = HTMLElement\nexport type HeightAnimationContainer = HTMLElement\nexport type HeightAnimationFromHeight = number\nexport type HeightAnimationToHeight = number\n\nexport default class HeightAnimation {\n private state: Readonly<HeightAnimationStates>\n isInBrowser: boolean\n onStartStack: HeightAnimationOnStartStack = []\n onEndStack: HeightAnimationOnEndStack = []\n events: HeightAnimationEvents = []\n opts: HeightAnimationOptions = { animate: true }\n elem: HeightAnimationElement\n reqId1: number\n reqId2: number\n resizeTimeout: NodeJS.Timeout\n timeouts: NodeJS.Timeout[] = []\n firstTime?: number = 0\n startTime?: number = 0\n duration?: number = 0\n isAnimating: boolean\n __currentHeight: number\n\n firstPaintStyle = {\n visibility: 'hidden',\n opacity: '0', // prevents before/after elements to be visible\n height: 'auto',\n } as const\n\n constructor(opts: HeightAnimationOptions = {}) {\n this.isInBrowser = typeof window !== 'undefined'\n this.setState('init')\n this.setOptions(opts)\n }\n\n callAnimationStart() {\n this.startTime = Date.now()\n if (!this.firstTime) {\n this.firstTime = this.startTime\n }\n if (this.onStartStack) {\n this.onStartStack.forEach((fn) => {\n if (typeof fn === 'function') {\n fn(this.state)\n }\n })\n }\n }\n callAnimationEnd() {\n this.isAnimating = false\n\n if (this.state !== 'opened') {\n delete this.__currentHeight\n }\n\n this.removeEndEvents()\n\n if (this.onEndStack) {\n this.onEndStack.forEach((fn) => {\n if (typeof fn === 'function') {\n fn(this.state)\n }\n })\n }\n }\n addEndEvent(listener: HeightAnimationEventListener) {\n this.removeEndEvents() // also, remove events on every open (but not on close!)\n\n const handleTransitionEnd = (e) => {\n if (this.canFinish()) {\n listener(e)\n } else {\n const delay = this.duration - (Date.now() - this.startTime)\n\n if (delay === -1) {\n listener(e)\n } else {\n this.timeouts.push(setTimeout(() => listener(e), delay))\n }\n }\n }\n\n this.events.push(handleTransitionEnd)\n this.elem?.addEventListener?.('transitionend', handleTransitionEnd)\n }\n removeEndEvents() {\n this.events.forEach((listener) => {\n this.elem?.removeEventListener?.('transitionend', listener)\n })\n this.events = []\n }\n\n // Public methods\n setElement(elem: HeightAnimationElement) {\n this.elem =\n elem ||\n (typeof document !== 'undefined' && document.createElement('div'))\n\n // TODO: remove when responsive tables are supported\n if (String(this.elem?.nodeName).toLowerCase() === 'td') {\n this.elem = this.elem.parentElement\n }\n\n this.duration =\n globalThis.animationDuration ??\n (parseFloat(window.getComputedStyle(this.elem).transitionDuration) *\n 1000 ||\n 400) // The default duration\n }\n setState(state: HeightAnimationStates) {\n this.state = Object.freeze(state)\n }\n setOptions(opts: HeightAnimationOptions) {\n this.opts = Object.freeze({ ...this.opts, ...opts })\n }\n getOptions() {\n return this.opts\n }\n remove() {\n this.stop()\n this.removeEndEvents()\n this.setState('init')\n this.isAnimating = false\n this.onEndStack = []\n this.onStartStack = []\n this.__currentHeight = undefined\n this.elem = undefined\n }\n setAsOpen() {\n if (this.state === 'opened') {\n return\n }\n this.setState('opening')\n this.callAnimationStart()\n this.setState('opened')\n this.callAnimationEnd()\n }\n setAsClosed() {\n if (this.state === 'closed') {\n return\n }\n this.setState('closing')\n this.callAnimationStart()\n this.setState('closed')\n this.callAnimationEnd()\n }\n getHeight() {\n return parseFloat(String(this.elem?.clientHeight)) || null\n }\n getUnknownHeight() {\n if (!this.elem) {\n return null\n }\n\n if (this.isAnimating && typeof this.__currentHeight !== 'undefined') {\n return this.__currentHeight\n }\n\n const clonedElem = this.elem.cloneNode(true) as HTMLElement\n const inputs = clonedElem.querySelectorAll('input')\n inputs.forEach((input) => {\n input.removeAttribute('name') // because type=\"radio\" will be else effected negatively\n input.removeAttribute('id') // don't put IDs twice in the DOM\n })\n\n // Hide the cloned element\n for (const key in this.firstPaintStyle) {\n clonedElem.style[key] = this.firstPaintStyle[key]\n }\n clonedElem.style.position = 'absolute' // not a part of the \"firstPaintStyle\"\n\n this.elem.parentNode?.insertBefore(clonedElem, this.elem.nextSibling)\n\n // When text is wrapped, we get different widths,\n // so we need to set the width to the original width\n const elemWidth = this.elem.clientWidth\n const clonedWidth =\n clonedElem.clientWidth ||\n // data-width is used for mockup testing with \"mockHeight\"\n parseFloat(clonedElem.getAttribute('data-width')) ||\n 0\n\n if (clonedWidth > elemWidth) {\n clonedElem.style.width = `${elemWidth}px`\n }\n\n const height =\n clonedElem.clientHeight ||\n // data-height is used for mockup testing with \"mockHeight\"\n parseFloat(clonedElem.getAttribute('data-height')) ||\n null\n\n clonedElem.parentNode?.removeChild(clonedElem)\n\n if (height) {\n this.__currentHeight = height\n }\n\n return height\n }\n onStart(fn: HeightAnimationOnStartCallback) {\n this.onStartStack.push(fn)\n }\n onEnd(fn: HeightAnimationOnEndCallback) {\n this.onEndStack.push(fn)\n }\n start(\n fromHeight: HeightAnimationFromHeight,\n toHeight: HeightAnimationToHeight\n ) {\n if (\n !this.elem ||\n !(\n this.isInBrowser &&\n typeof window.requestAnimationFrame === 'function'\n )\n ) {\n return\n }\n\n const opts = this.getOptions()\n if (opts.animate === false) {\n return\n }\n\n this.stop()\n this.isAnimating = true\n\n // make the animation\n this.reqId1 = window.requestAnimationFrame(() => {\n if (!this.elem) {\n return\n }\n\n this.elem.style.height = `${fromHeight}px`\n\n this.reqId2 = window.requestAnimationFrame(() => {\n if (!this.elem) {\n return\n }\n\n this.elem.style.height = `${toHeight}px`\n })\n })\n }\n stop() {\n this.timeouts.forEach((id) => clearTimeout(id))\n this.timeouts = []\n\n if (\n this.isInBrowser &&\n typeof window.requestAnimationFrame === 'function'\n ) {\n window.cancelAnimationFrame(this.reqId1)\n window.cancelAnimationFrame(this.reqId2)\n }\n }\n open() {\n if (\n this.state === 'opened' ||\n this.state === 'opening' ||\n this.shouldBypassAnimation()\n ) {\n this.setAsOpen()\n return\n }\n\n this.setState('opening')\n this.callAnimationStart()\n\n const toHeight = this.getUnknownHeight()\n\n this.addEndEvent((e) => {\n if (e.target === e.currentTarget || !e.currentTarget) {\n if (this.elem) {\n this.elem.style.overflowY = ''\n }\n this.setState('opened')\n this.readjust()\n }\n })\n\n this.start(0, toHeight)\n }\n close() {\n if (\n this.state === 'closed' ||\n this.state === 'closing' ||\n this.shouldBypassAnimation()\n ) {\n this.setAsClosed()\n return\n }\n\n this.setState('closing')\n this.callAnimationStart()\n\n const fromHeight = this.getHeight()\n\n this.addEndEvent((e) => {\n if (e.target === e.currentTarget || !e.currentTarget) {\n if (this.elem) {\n this.elem.style.visibility = 'hidden'\n this.elem.style.overflowY = 'clip'\n }\n this.setState('closed')\n this.callAnimationEnd()\n }\n })\n\n this.start(fromHeight, 0)\n }\n adjustTo(\n fromHeight: HeightAnimationFromHeight = null,\n toHeight: HeightAnimationToHeight = null\n ) {\n const opts = this.getOptions()\n\n if (\n !this.elem ||\n opts.animate === false ||\n this.state === 'opening' ||\n this.state === 'closing'\n ) {\n return\n }\n\n if (fromHeight === 0 || fromHeight === null) {\n fromHeight = this.getHeight()\n }\n if (toHeight === null) {\n toHeight = this.getUnknownHeight()\n }\n\n if (fromHeight === toHeight) {\n this.setState('adjusted')\n return\n }\n\n this.setState('adjusting')\n this.callAnimationStart()\n\n this.addEndEvent((e) => {\n if (\n this.state === 'adjusting' &&\n (e.target === e.currentTarget || !e.currentTarget)\n ) {\n if (this.elem) {\n this.elem.style.height = 'auto'\n }\n this.setState('adjusted')\n this.callAnimationEnd()\n }\n })\n\n this.start(fromHeight, toHeight)\n }\n readjust() {\n const endHeight = this.getHeight()\n\n if (this.elem) {\n this.elem.style.height = 'auto'\n }\n\n this.__currentHeight = undefined\n const newHeight = this.getUnknownHeight()\n\n // If the height has changed during the animation, we need to adjust it\n if (endHeight !== newHeight) {\n this.adjustTo(endHeight, newHeight)\n } else {\n this.callAnimationEnd()\n }\n }\n /**\n * Determines whether the animation can finish.\n * Check for certain states and if the time passed is too short.\n * With a so short first state change, we do not call animation end.\n */\n canFinish() {\n return Boolean(\n this.startTime &&\n Date.now() - this.startTime >\n (globalThis.animationDuration ?? this.duration)\n )\n }\n /**\n * Determines whether the animation should be bypassed.\n * Check for certain states and if the time passed is too short to be correct.\n * With a very short first state change, we skip animation.\n */\n shouldBypassAnimation() {\n const opts = this.getOptions()\n\n if (!this.elem || opts.animate === false) {\n return true\n }\n\n if (\n this.isInBrowser &&\n (globalThis.IS_TEST || globalThis.bypassTime === -1)\n ) {\n return false\n }\n\n return Boolean(\n this.firstTime &&\n Date.now() - this.firstTime < (globalThis.bypassTime ?? 100)\n )\n }\n}\n"],"mappings":";;;;;;;;;;;AA4Be,MAAMA,eAAe,CAAC;EAwBnCC,WAAWA,CAAA,EAAoC;IAAA,IAAnCC,IAA4B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAAAG,eAAA;IAAAA,eAAA;IAAAA,eAAA,uBArBD,EAAE;IAAAA,eAAA,qBACN,EAAE;IAAAA,eAAA,iBACV,EAAE;IAAAA,eAAA,eACH;MAAEC,OAAO,EAAE;IAAK,CAAC;IAAAD,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA,mBAKnB,EAAE;IAAAA,eAAA,oBACV,CAAC;IAAAA,eAAA,oBACD,CAAC;IAAAA,eAAA,mBACF,CAAC;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA,0BAIH;MAChBE,UAAU,EAAE,QAAQ;MACpBC,OAAO,EAAE,GAAG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K;IACd;IAEA,OAAOH,OAAO,CACZ,IAAI,CAAClG,SAAS,IACZF,IAAI,CAACC,GAAG,CAAC,CAAC,GAAG,IAAI,CAACC,SAAS,KAAAmG,qBAAA,GAAI7D,UAAU,CAAC+D,UAAU,cAAAF,qBAAA,cAAAA,qBAAA,GAAI,GAAG,CAC/D,CAAC;EACH;AACF;AAACG,OAAA,CAAAC,OAAA,GAAA1H,eAAA"}
|
|
1
|
+
{"version":3,"file":"HeightAnimationInstance.js","names":["HeightAnimation","constructor","opts","arguments","length","undefined","_defineProperty","animate","visibility","opacity","height","isInBrowser","window","setState","setOptions","callAnimationStart","startTime","Date","now","firstTime","onStartStack","forEach","fn","state","callAnimationEnd","isAnimating","__currentHeight","removeEndEvents","onEndStack","addEndEvent","listener","_this$elem","_this$elem$addEventLi","handleTransitionEnd","e","canFinish","delay","duration","timeouts","push","setTimeout","events","elem","addEventListener","call","_this$elem2","_this$elem2$removeEve","removeEventListener","setElement","_this$elem3","_globalThis$animation","document","createElement","String","nodeName","toLowerCase","parentElement","globalThis","animationDuration","parseFloat","getComputedStyle","transitionDuration","Object","freeze","_objectSpread","getOptions","remove","stop","setAsOpen","setAsClosed","getHeight","_this$withFallback","withFallback","getUnknownHeight","_this$elem$parentNode","_this$withFallback2","_this$withFallback3","_clonedElem$parentNod","clonedElem","cloneNode","inputs","querySelectorAll","input","removeAttribute","key","firstPaintStyle","style","position","parentNode","insertBefore","nextSibling","elemWidth","clientWidth","clonedWidth","width","removeChild","fallback","val","hasAttribute","getAttribute","isNaN","onStart","onEnd","start","fromHeight","toHeight","requestAnimationFrame","reqId1","reqId2","id","clearTimeout","cancelAnimationFrame","open","shouldBypassAnimation","target","currentTarget","overflowY","readjust","close","adjustTo","endHeight","newHeight","_globalThis$animation2","Boolean","_globalThis$bypassTim","IS_TEST","bypassTime","exports","default"],"sources":["../../../../src/components/height-animation/HeightAnimationInstance.ts"],"sourcesContent":["export type HeightAnimationOnStartStates =\n | 'opening'\n | 'closing'\n | 'adjusting'\nexport type HeightAnimationOnEndStates = 'opened' | 'closed' | 'adjusted'\nexport type HeightAnimationStates =\n | HeightAnimationOnStartStates\n | HeightAnimationOnEndStates\n | 'init'\nexport type HeightAnimationOptions = {\n animate?: boolean\n}\nexport type HeightAnimationOnStartCallback = (\n state: HeightAnimationStates\n) => void\nexport type HeightAnimationOnEndCallback = (\n state: HeightAnimationStates\n) => void\nexport type HeightAnimationOnStartStack =\n Array<HeightAnimationOnStartCallback>\nexport type HeightAnimationOnEndStack = Array<HeightAnimationOnEndCallback>\nexport type HeightAnimationEventListener = (e: Event) => void\nexport type HeightAnimationEvents = Array<HeightAnimationEventListener>\nexport type HeightAnimationElement = HTMLElement\nexport type HeightAnimationContainer = HTMLElement\nexport type HeightAnimationFromHeight = number\nexport type HeightAnimationToHeight = number\n\nexport default class HeightAnimation {\n private state: Readonly<HeightAnimationStates>\n isInBrowser: boolean\n onStartStack: HeightAnimationOnStartStack = []\n onEndStack: HeightAnimationOnEndStack = []\n events: HeightAnimationEvents = []\n opts: HeightAnimationOptions = { animate: true }\n elem: HeightAnimationElement\n reqId1: number\n reqId2: number\n resizeTimeout: NodeJS.Timeout\n timeouts: NodeJS.Timeout[] = []\n firstTime?: number = 0\n startTime?: number = 0\n duration?: number = 0\n isAnimating: boolean\n __currentHeight: number\n\n firstPaintStyle = {\n visibility: 'hidden',\n opacity: '0', // prevents before/after elements to be visible\n height: 'auto',\n } as const\n\n constructor(opts: HeightAnimationOptions = {}) {\n this.isInBrowser = typeof window !== 'undefined'\n this.setState('init')\n this.setOptions(opts)\n }\n\n callAnimationStart() {\n this.startTime = Date.now()\n if (!this.firstTime) {\n this.firstTime = this.startTime\n }\n if (this.onStartStack) {\n this.onStartStack.forEach((fn) => {\n if (typeof fn === 'function') {\n fn(this.state)\n }\n })\n }\n }\n callAnimationEnd() {\n this.isAnimating = false\n\n if (this.state !== 'opened') {\n delete this.__currentHeight\n }\n\n this.removeEndEvents()\n\n if (this.onEndStack) {\n this.onEndStack.forEach((fn) => {\n if (typeof fn === 'function') {\n fn(this.state)\n }\n })\n }\n }\n addEndEvent(listener: HeightAnimationEventListener) {\n this.removeEndEvents() // also, remove events on every open (but not on close!)\n\n const handleTransitionEnd = (e) => {\n if (this.canFinish()) {\n listener(e)\n } else {\n const delay = this.duration - (Date.now() - this.startTime)\n\n if (delay === -1) {\n listener(e)\n } else {\n this.timeouts.push(setTimeout(() => listener(e), delay))\n }\n }\n }\n\n this.events.push(handleTransitionEnd)\n this.elem?.addEventListener?.('transitionend', handleTransitionEnd)\n }\n removeEndEvents() {\n this.events.forEach((listener) => {\n this.elem?.removeEventListener?.('transitionend', listener)\n })\n this.events = []\n }\n\n // Public methods\n setElement(elem: HeightAnimationElement) {\n this.elem =\n elem ||\n (typeof document !== 'undefined' && document.createElement('div'))\n\n // TODO: remove when responsive tables are supported\n if (String(this.elem?.nodeName).toLowerCase() === 'td') {\n this.elem = this.elem.parentElement\n }\n\n this.duration =\n globalThis.animationDuration ??\n (parseFloat(window.getComputedStyle(this.elem).transitionDuration) *\n 1000 ||\n 400) // The default duration\n }\n setState(state: HeightAnimationStates) {\n this.state = Object.freeze(state)\n }\n setOptions(opts: HeightAnimationOptions) {\n this.opts = Object.freeze({ ...this.opts, ...opts })\n }\n getOptions() {\n return this.opts\n }\n remove() {\n this.stop()\n this.removeEndEvents()\n this.setState('init')\n this.isAnimating = false\n this.onEndStack = []\n this.onStartStack = []\n this.__currentHeight = undefined\n this.elem = undefined\n }\n setAsOpen() {\n if (this.state === 'opened') {\n return\n }\n this.setState('opening')\n this.callAnimationStart()\n this.setState('opened')\n this.callAnimationEnd()\n }\n setAsClosed() {\n if (this.state === 'closed') {\n return\n }\n this.setState('closing')\n this.callAnimationStart()\n this.setState('closed')\n this.callAnimationEnd()\n }\n getHeight() {\n return this.withFallback(this.elem, 'clientHeight') ?? null\n }\n getUnknownHeight() {\n if (!this.elem) {\n return null\n }\n\n if (this.isAnimating && typeof this.__currentHeight !== 'undefined') {\n return this.__currentHeight\n }\n\n const clonedElem = this.elem.cloneNode(true) as HTMLElement\n const inputs = clonedElem.querySelectorAll('input')\n inputs.forEach((input) => {\n input.removeAttribute('name') // because type=\"radio\" will be else effected negatively\n input.removeAttribute('id') // don't put IDs twice in the DOM\n })\n\n // Hide the cloned element\n for (const key in this.firstPaintStyle) {\n clonedElem.style[key] = this.firstPaintStyle[key]\n }\n clonedElem.style.position = 'absolute' // not a part of the \"firstPaintStyle\"\n\n this.elem.parentNode?.insertBefore(clonedElem, this.elem.nextSibling)\n\n // When text is wrapped, we get different widths,\n // so we need to set the width to the original width\n const elemWidth = this.elem.clientWidth\n const clonedWidth =\n this.withFallback(clonedElem, 'clientWidth', 'data-width') ?? 0\n\n if (clonedWidth > elemWidth) {\n clonedElem.style.width = `${elemWidth}px`\n }\n\n const height =\n // data-height is used for mockup testing with \"mockHeight\"\n this.withFallback(this.elem, 'clientHeight', 'data-height') ?? null\n\n clonedElem.parentNode?.removeChild(clonedElem)\n\n if (height) {\n this.__currentHeight = height\n }\n\n return height\n }\n withFallback(\n elem: HTMLElement,\n key: 'clientHeight' | 'clientWidth',\n fallback?: 'data-height' | 'data-width'\n ) {\n const val =\n fallback && elem.hasAttribute(fallback)\n ? parseFloat(elem.getAttribute(fallback))\n : elem?.[key]\n\n if (isNaN(val)) {\n return null\n }\n\n return val\n }\n onStart(fn: HeightAnimationOnStartCallback) {\n this.onStartStack.push(fn)\n }\n onEnd(fn: HeightAnimationOnEndCallback) {\n this.onEndStack.push(fn)\n }\n start(\n fromHeight: HeightAnimationFromHeight,\n toHeight: HeightAnimationToHeight\n ) {\n if (\n !this.elem ||\n !(\n this.isInBrowser &&\n typeof window.requestAnimationFrame === 'function'\n )\n ) {\n return\n }\n\n const opts = this.getOptions()\n if (opts.animate === false) {\n return\n }\n\n this.stop()\n this.isAnimating = true\n\n // make the animation\n this.reqId1 = window.requestAnimationFrame(() => {\n if (!this.elem) {\n return\n }\n\n this.elem.style.height = `${fromHeight}px`\n\n this.reqId2 = window.requestAnimationFrame(() => {\n if (!this.elem) {\n return\n }\n\n this.elem.style.height = `${toHeight}px`\n })\n })\n }\n stop() {\n this.timeouts.forEach((id) => clearTimeout(id))\n this.timeouts = []\n\n if (\n this.isInBrowser &&\n typeof window.requestAnimationFrame === 'function'\n ) {\n window.cancelAnimationFrame(this.reqId1)\n window.cancelAnimationFrame(this.reqId2)\n }\n }\n open() {\n if (\n this.state === 'opened' ||\n this.state === 'opening' ||\n this.shouldBypassAnimation()\n ) {\n this.setAsOpen()\n return\n }\n\n this.setState('opening')\n this.callAnimationStart()\n\n const toHeight = this.getUnknownHeight()\n\n this.addEndEvent((e) => {\n if (e.target === e.currentTarget || !e.currentTarget) {\n if (this.elem) {\n this.elem.style.overflowY = ''\n }\n this.setState('opened')\n this.readjust()\n }\n })\n\n this.start(0, toHeight)\n }\n close() {\n if (\n this.state === 'closed' ||\n this.state === 'closing' ||\n this.shouldBypassAnimation()\n ) {\n this.setAsClosed()\n return\n }\n\n this.setState('closing')\n this.callAnimationStart()\n\n const fromHeight = this.getHeight()\n\n this.addEndEvent((e) => {\n if (e.target === e.currentTarget || !e.currentTarget) {\n if (this.elem) {\n this.elem.style.visibility = 'hidden'\n this.elem.style.overflowY = 'clip'\n }\n this.setState('closed')\n this.callAnimationEnd()\n }\n })\n\n this.start(fromHeight, 0)\n }\n adjustTo(\n fromHeight: HeightAnimationFromHeight = null,\n toHeight: HeightAnimationToHeight = null\n ) {\n const opts = this.getOptions()\n\n if (\n !this.elem ||\n opts.animate === false ||\n this.state === 'opening' ||\n this.state === 'closing'\n ) {\n return\n }\n\n if (fromHeight === null) {\n fromHeight = this.getHeight()\n }\n if (toHeight === null) {\n toHeight = this.getUnknownHeight()\n }\n\n if (fromHeight === toHeight) {\n this.setState('adjusted')\n return\n }\n\n this.setState('adjusting')\n this.callAnimationStart()\n\n this.addEndEvent((e) => {\n if (\n this.state === 'adjusting' &&\n (e.target === e.currentTarget || !e.currentTarget)\n ) {\n if (this.elem) {\n this.elem.style.height = 'auto'\n }\n this.setState('adjusted')\n this.callAnimationEnd()\n }\n })\n\n this.start(fromHeight, toHeight)\n }\n readjust() {\n const endHeight = this.getHeight()\n\n if (this.elem) {\n this.elem.style.height = 'auto'\n }\n\n this.__currentHeight = undefined\n const newHeight = this.getUnknownHeight()\n\n // If the height has changed during the animation, we need to adjust it\n if (endHeight !== newHeight) {\n this.adjustTo(endHeight, newHeight)\n } else {\n this.callAnimationEnd()\n }\n }\n /**\n * Determines whether the animation can finish.\n * Check for certain states and if the time passed is too short.\n * With a so short first state change, we do not call animation end.\n */\n canFinish() {\n return Boolean(\n this.startTime &&\n Date.now() - this.startTime >\n (globalThis.animationDuration ?? this.duration)\n )\n }\n /**\n * Determines whether the animation should be bypassed.\n * Check for certain states and if the time passed is too short to be correct.\n * With a very short first state change, we skip animation.\n */\n shouldBypassAnimation() {\n const opts = this.getOptions()\n\n if (!this.elem || opts.animate === false) {\n return true\n }\n\n if (\n this.isInBrowser &&\n (globalThis.IS_TEST || globalThis.bypassTime === -1)\n ) {\n return false\n }\n\n return Boolean(\n this.firstTime &&\n Date.now() - this.firstTime < (globalThis.bypassTime ?? 100)\n )\n }\n}\n"],"mappings":";;;;;;;;;;;AA4Be,MAAMA,eAAe,CAAC;EAwBnCC,WAAWA,CAAA,EAAoC;IAAA,IAAnCC,IAA4B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAAAG,eAAA;IAAAA,eAAA;IAAAA,eAAA,uBArBD,EAAE;IAAAA,eAAA,qBACN,EAAE;IAAAA,eAAA,iBACV,EAAE;IAAAA,eAAA,eACH;MAAEC,OAAO,EAAE;IAAK,CAAC;IAAAD,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA,mBAKnB,EAAE;IAAAA,eAAA,oBACV,CAAC;IAAAA,eAAA,oBACD,CAAC;IAAAA,eAAA,mBACF,CAAC;I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C,CAAC,GAAG,IAAI,CAACF,SAAS,KAAA0G,sBAAA,GACxBjE,UAAU,CAACC,iBAAiB,cAAAgE,sBAAA,cAAAA,sBAAA,GAAI,IAAI,CAACrF,QAAQ,CACpD,CAAC;EACH;EAMA4E,qBAAqBA,CAAA,EAAG;IAAA,IAAAW,qBAAA;IACtB,MAAM1H,IAAI,GAAG,IAAI,CAAC+D,UAAU,CAAC,CAAC;IAE9B,IAAI,CAAC,IAAI,CAACvB,IAAI,IAAIxC,IAAI,CAACK,OAAO,KAAK,KAAK,EAAE;MACxC,OAAO,IAAI;IACb;IAEA,IACE,IAAI,CAACI,WAAW,KACf8C,UAAU,CAACoE,OAAO,IAAIpE,UAAU,CAACqE,UAAU,KAAK,CAAC,CAAC,CAAC,EACpD;MACA,OAAO,KAAK;IACd;IAEA,OAAOH,OAAO,CACZ,IAAI,CAACxG,SAAS,IACZF,IAAI,CAACC,GAAG,CAAC,CAAC,GAAG,IAAI,CAACC,SAAS,KAAAyG,qBAAA,GAAInE,UAAU,CAACqE,UAAU,cAAAF,qBAAA,cAAAA,qBAAA,GAAI,GAAG,CAC/D,CAAC;EACH;AACF;AAACG,OAAA,CAAAC,OAAA,GAAAhI,eAAA"}
|
|
@@ -5,6 +5,9 @@ import { Props as ProviderProps } from './Provider';
|
|
|
5
5
|
type HandleSubmitProps = {
|
|
6
6
|
formElement?: HTMLFormElement;
|
|
7
7
|
};
|
|
8
|
+
export type MountOptions = {
|
|
9
|
+
isMounted?: boolean;
|
|
10
|
+
};
|
|
8
11
|
export type EventListenerCall = {
|
|
9
12
|
path?: Path;
|
|
10
13
|
type?: 'onSubmit' | 'onPathChange';
|
|
@@ -58,8 +61,7 @@ export interface ContextState {
|
|
|
58
61
|
hasFieldError: (path: Path) => boolean;
|
|
59
62
|
setFieldState: (path: Path, fieldState: SubmitState) => void;
|
|
60
63
|
setFieldError: (path: Path, error: Error | FormError) => void;
|
|
61
|
-
|
|
62
|
-
handleUnMountField: (path: Path) => void;
|
|
64
|
+
setMountedFieldState: (path: Path, options: MountOptions) => void;
|
|
63
65
|
setFormState?: (state: SubmitState) => void;
|
|
64
66
|
setSubmitState?: (state: EventStateObject) => void;
|
|
65
67
|
addOnChangeHandler?: (callback: OnChange) => void;
|
|
@@ -70,13 +72,13 @@ export interface ContextState {
|
|
|
70
72
|
skipErrorCheck?: boolean;
|
|
71
73
|
}) => void;
|
|
72
74
|
setFieldEventListener?: (path: EventListenerCall['path'], type: EventListenerCall['type'], callback: EventListenerCall['callback']) => void;
|
|
73
|
-
|
|
75
|
+
setVisibleError?: (path: Path, hasError: boolean) => void;
|
|
74
76
|
setFieldProps?: (path: Path, props: unknown) => void;
|
|
75
77
|
setValueProps?: (path: Path, props: unknown) => void;
|
|
76
78
|
setHandleSubmit?: (callback: HandleSubmitCallback) => void;
|
|
77
79
|
fieldPropsRef?: React.MutableRefObject<Record<string, FieldProps>>;
|
|
78
80
|
valuePropsRef?: React.MutableRefObject<Record<string, ValueProps>>;
|
|
79
|
-
|
|
81
|
+
mountedFieldsRef?: React.MutableRefObject<Record<Path, MountOptions>>;
|
|
80
82
|
showAllErrors: boolean;
|
|
81
83
|
hasVisibleError: boolean;
|
|
82
84
|
formState: SubmitState;
|
|
@@ -26,8 +26,7 @@ const defaultContextState = {
|
|
|
26
26
|
setSubmitState: () => null,
|
|
27
27
|
handleSubmitCall: () => null,
|
|
28
28
|
setShowAllErrors: () => null,
|
|
29
|
-
|
|
30
|
-
handleUnMountField: () => null,
|
|
29
|
+
setMountedFieldState: () => null,
|
|
31
30
|
hasErrors: () => false,
|
|
32
31
|
hasFieldState: () => false,
|
|
33
32
|
hasFieldError: () => false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Context.js","names":["_react","_interopRequireDefault","require","_ajv","obj","__esModule","default","defaultContextState","hasContext","data","undefined","schema","submitState","handlePathChange","handlePathChangeUnvalidated","updateDataValue","setData","validateData","handleSubmit","scrollToTop","showAllErrors","hasVisibleError","formState","setFormState","setSubmitState","handleSubmitCall","setShowAllErrors","
|
|
1
|
+
{"version":3,"file":"Context.js","names":["_react","_interopRequireDefault","require","_ajv","obj","__esModule","default","defaultContextState","hasContext","data","undefined","schema","submitState","handlePathChange","handlePathChangeUnvalidated","updateDataValue","setData","validateData","handleSubmit","scrollToTop","showAllErrors","hasVisibleError","formState","setFormState","setSubmitState","handleSubmitCall","setShowAllErrors","setMountedFieldState","hasErrors","hasFieldState","hasFieldError","setFieldState","setFieldError","ajvInstance","makeAjvInstance","contextErrorMessages","isInsideFormElement","props","exports","Context","React","createContext","_default"],"sources":["../../../../../src/extensions/forms/DataContext/Context.ts"],"sourcesContent":["import React from 'react'\nimport { Ajv, makeAjvInstance } from '../utils/ajv'\nimport {\n AllJSONSchemaVersions,\n CustomErrorMessagesWithPaths,\n SubmitState,\n Path,\n EventStateObject,\n EventReturnWithStateObject,\n Identifier,\n FieldProps,\n FormError,\n ValueProps,\n OnChange,\n} from '../types'\nimport { Props as ProviderProps } from './Provider'\n\ntype HandleSubmitProps = {\n formElement?: HTMLFormElement\n}\n\nexport type MountOptions = {\n isMounted?: boolean\n}\n\nexport type EventListenerCall = {\n path?: Path\n type?: 'onSubmit' | 'onPathChange'\n callback: (params?: { value: unknown }) => void | Promise<void | Error>\n}\n\nexport type FilterDataHandler<Data> = (\n data: Data,\n filter: FilterData\n) => Partial<Data>\nexport type FilterDataHandlerCallback<R> = (\n parameters: FilterDataHandlerParameters\n) => R\nexport type FilterDataHandlerParameters =\n FilterDataPathConditionParameters & {\n path: Path\n }\nexport type FilterDataPathCondition<Data = unknown> = (\n parameters: FilterDataPathConditionParameters<Data>\n) => boolean | undefined\nexport type FilterDataPathConditionParameters<Data = unknown> = {\n value: unknown\n props: FieldProps\n data: Data\n internal: {\n error: Error | undefined\n }\n}\nexport type FilterDataPathObject<Data> = Record<\n Path,\n FilterDataPathCondition<Data> | boolean | undefined\n>\nexport type FilterData<Data = unknown> =\n | FilterDataPathObject<Data>\n | FilterDataHandlerCallback<boolean | undefined>\nexport type TransformData = FilterDataHandlerCallback<unknown>\nexport type HandleSubmitCallback = ({\n preventSubmit,\n}: {\n preventSubmit: () => void\n}) => void\n\nexport interface ContextState {\n id?: Identifier\n hasContext: boolean\n /** The dataset for the form / form wizard */\n data: any\n internalDataRef?: React.MutableRefObject<any>\n /** Should the form validate data before submitting? */\n errors?: Record<string, Error>\n /** Will set autoComplete=\"on\" on each nested Field.String and Field.Number */\n autoComplete?: boolean\n handlePathChange: (\n path: Path,\n value?: any\n ) =>\n | EventReturnWithStateObject\n | unknown\n | Promise<EventReturnWithStateObject | unknown>\n handlePathChangeUnvalidated: (path: Path, value: any) => void\n updateDataValue: (path: Path, value: any) => void\n setData: (data: any) => void\n clearData?: () => void\n mutateDataHandler?: (data: any, mutate: TransformData) => any\n filterDataHandler?: (data: any, filter: FilterData) => any\n validateData: () => void\n handleSubmit: (props?: HandleSubmitProps) => any\n scrollToTop: () => void\n setShowAllErrors: (showAllErrors: boolean) => void\n hasErrors: () => boolean\n hasFieldState: (state: SubmitState) => boolean\n hasFieldError: (path: Path) => boolean\n setFieldState: (path: Path, fieldState: SubmitState) => void\n setFieldError: (path: Path, error: Error | FormError) => void\n setMountedFieldState: (path: Path, options: MountOptions) => void\n setFormState?: (state: SubmitState) => void\n setSubmitState?: (state: EventStateObject) => void\n addOnChangeHandler?: (callback: OnChange) => void\n handleSubmitCall: ({\n onSubmit,\n enableAsyncBehavior,\n skipFieldValidation,\n skipErrorCheck,\n }: {\n onSubmit: () =>\n | EventReturnWithStateObject\n | void\n | Promise<EventReturnWithStateObject | void>\n enableAsyncBehavior: boolean\n skipFieldValidation?: boolean\n skipErrorCheck?: boolean\n }) => void\n setFieldEventListener?: (\n path: EventListenerCall['path'],\n type: EventListenerCall['type'],\n callback: EventListenerCall['callback']\n ) => void\n setVisibleError?: (path: Path, hasError: boolean) => void\n setFieldProps?: (path: Path, props: unknown) => void\n setValueProps?: (path: Path, props: unknown) => void\n setHandleSubmit?: (callback: HandleSubmitCallback) => void\n fieldPropsRef?: React.MutableRefObject<Record<string, FieldProps>>\n valuePropsRef?: React.MutableRefObject<Record<string, ValueProps>>\n mountedFieldsRef?: React.MutableRefObject<Record<Path, MountOptions>>\n showAllErrors: boolean\n hasVisibleError: boolean\n formState: SubmitState\n ajvInstance: Ajv\n contextErrorMessages: CustomErrorMessagesWithPaths\n schema: AllJSONSchemaVersions\n path?: Path\n disabled?: boolean\n required?: boolean\n submitState: Partial<EventStateObject>\n isInsideFormElement?: boolean\n prerenderFieldProps?: boolean\n props: ProviderProps<unknown>\n}\n\nexport const defaultContextState: ContextState = {\n hasContext: false,\n data: undefined,\n schema: undefined,\n submitState: undefined,\n handlePathChange: () => null,\n handlePathChangeUnvalidated: () => null,\n updateDataValue: () => null,\n setData: () => null,\n validateData: () => null,\n handleSubmit: () => null,\n scrollToTop: () => null,\n showAllErrors: false,\n hasVisibleError: false,\n formState: undefined,\n setFormState: () => null,\n setSubmitState: () => null,\n handleSubmitCall: () => null,\n setShowAllErrors: () => null,\n setMountedFieldState: () => null,\n hasErrors: () => false,\n hasFieldState: () => false,\n hasFieldError: () => false,\n setFieldState: () => null,\n setFieldError: () => null,\n ajvInstance: makeAjvInstance(),\n contextErrorMessages: undefined,\n isInsideFormElement: false,\n props: null,\n}\n\nconst Context = React.createContext<ContextState>(defaultContextState)\n\nexport default Context\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AAAmD,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AA+I5C,MAAMG,mBAAiC,GAAG;EAC/CC,UAAU,EAAE,KAAK;EACjBC,IAAI,EAAEC,SAAS;EACfC,MAAM,EAAED,SAAS;EACjBE,WAAW,EAAEF,SAAS;EACtBG,gBAAgB,EAAEA,CAAA,KAAM,IAAI;EAC5BC,2BAA2B,EAAEA,CAAA,KAAM,IAAI;EACvCC,eAAe,EAAEA,CAAA,KAAM,IAAI;EAC3BC,OAAO,EAAEA,CAAA,KAAM,IAAI;EACnBC,YAAY,EAAEA,CAAA,KAAM,IAAI;EACxBC,YAAY,EAAEA,CAAA,KAAM,IAAI;EACxBC,WAAW,EAAEA,CAAA,KAAM,IAAI;EACvBC,aAAa,EAAE,KAAK;EACpBC,eAAe,EAAE,KAAK;EACtBC,SAAS,EAAEZ,SAAS;EACpBa,YAAY,EAAEA,CAAA,KAAM,IAAI;EACxBC,cAAc,EAAEA,CAAA,KAAM,IAAI;EAC1BC,gBAAgB,EAAEA,CAAA,KAAM,IAAI;EAC5BC,gBAAgB,EAAEA,CAAA,KAAM,IAAI;EAC5BC,oBAAoB,EAAEA,CAAA,KAAM,IAAI;EAChCC,SAAS,EAAEA,CAAA,KAAM,KAAK;EACtBC,aAAa,EAAEA,CAAA,KAAM,KAAK;EAC1BC,aAAa,EAAEA,CAAA,KAAM,KAAK;EAC1BC,aAAa,EAAEA,CAAA,KAAM,IAAI;EACzBC,aAAa,EAAEA,CAAA,KAAM,IAAI;EACzBC,WAAW,EAAE,IAAAC,oBAAe,EAAC,CAAC;EAC9BC,oBAAoB,EAAEzB,SAAS;EAC/B0B,mBAAmB,EAAE,KAAK;EAC1BC,KAAK,EAAE;AACT,CAAC;AAAAC,OAAA,CAAA/B,mBAAA,GAAAA,mBAAA;AAED,MAAMgC,OAAO,GAAGC,cAAK,CAACC,aAAa,CAAelC,mBAAmB,CAAC;AAAA,IAAAmC,QAAA,GAEvDH,OAAO;AAAAD,OAAA,CAAAhC,OAAA,GAAAoC,QAAA"}
|
|
@@ -30,6 +30,10 @@ export interface FieldBoundaryContextState {
|
|
|
30
30
|
* To set the local error state.
|
|
31
31
|
*/
|
|
32
32
|
setFieldError?: (path: Path, error: Error) => void;
|
|
33
|
+
/**
|
|
34
|
+
* To set the local visible error state.
|
|
35
|
+
*/
|
|
36
|
+
setVisibleError?: (path: Path, hasError: boolean) => void;
|
|
33
37
|
}
|
|
34
38
|
declare const FieldBoundaryContext: React.Context<FieldBoundaryContextState>;
|
|
35
39
|
export default FieldBoundaryContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldBoundaryContext.js","names":["_react","_interopRequireDefault","require","obj","__esModule","default","FieldBoundaryContext","React","createContext","undefined","_default","exports"],"sources":["../../../../../../src/extensions/forms/DataContext/FieldBoundary/FieldBoundaryContext.ts"],"sourcesContent":["import React from 'react'\nimport { Path } from '../../types'\n\nexport interface FieldBoundaryContextState {\n /**\n * Will be set to true when one or more nested fields are in error state.\n */\n hasError?: boolean\n\n /**\n * Will be set to true when the inherited data context has submit errors and the `hasError` has errors as well.\n */\n hasSubmitError?: boolean\n\n /**\n * Will be set to true when a nested field contains a visible error.\n */\n hasVisibleError?: boolean\n\n /**\n * Contains the nested field errors.\n */\n errorsRef?: React.RefObject<unknown>\n\n /**\n * Will be set to true when the boundary context error state should be shown.\n * Support a number to ensure we can renew hooks each time we get a new value.\n */\n showBoundaryErrors?: boolean | number\n\n /**\n * To set the boundary context error state.\n */\n setShowBoundaryErrors?: (\n showBoundaryErrors: FieldBoundaryContextState['showBoundaryErrors']\n ) => void\n\n /**\n * To set the local error state.\n */\n setFieldError?: (path: Path, error: Error) => void\n}\n\nconst FieldBoundaryContext = React.createContext<\n FieldBoundaryContextState | undefined\n>(undefined)\n\nexport default FieldBoundaryContext\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAyB,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;
|
|
1
|
+
{"version":3,"file":"FieldBoundaryContext.js","names":["_react","_interopRequireDefault","require","obj","__esModule","default","FieldBoundaryContext","React","createContext","undefined","_default","exports"],"sources":["../../../../../../src/extensions/forms/DataContext/FieldBoundary/FieldBoundaryContext.ts"],"sourcesContent":["import React from 'react'\nimport { Path } from '../../types'\n\nexport interface FieldBoundaryContextState {\n /**\n * Will be set to true when one or more nested fields are in error state.\n */\n hasError?: boolean\n\n /**\n * Will be set to true when the inherited data context has submit errors and the `hasError` has errors as well.\n */\n hasSubmitError?: boolean\n\n /**\n * Will be set to true when a nested field contains a visible error.\n */\n hasVisibleError?: boolean\n\n /**\n * Contains the nested field errors.\n */\n errorsRef?: React.RefObject<unknown>\n\n /**\n * Will be set to true when the boundary context error state should be shown.\n * Support a number to ensure we can renew hooks each time we get a new value.\n */\n showBoundaryErrors?: boolean | number\n\n /**\n * To set the boundary context error state.\n */\n setShowBoundaryErrors?: (\n showBoundaryErrors: FieldBoundaryContextState['showBoundaryErrors']\n ) => void\n\n /**\n * To set the local error state.\n */\n setFieldError?: (path: Path, error: Error) => void\n\n /**\n * To set the local visible error state.\n */\n setVisibleError?: (path: Path, hasError: boolean) => void\n}\n\nconst FieldBoundaryContext = React.createContext<\n FieldBoundaryContextState | undefined\n>(undefined)\n\nexport default FieldBoundaryContext\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAyB,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAgDzB,MAAMG,oBAAoB,GAAGC,cAAK,CAACC,aAAa,CAE9CC,SAAS,CAAC;AAAA,IAAAC,QAAA,GAEGJ,oBAAoB;AAAAK,OAAA,CAAAN,OAAA,GAAAK,QAAA"}
|
|
@@ -19,8 +19,7 @@ function FieldBoundaryProvider(props) {
|
|
|
19
19
|
} = props;
|
|
20
20
|
const [, forceUpdate] = (0, _react.useReducer)(() => ({}), {});
|
|
21
21
|
const {
|
|
22
|
-
showAllErrors
|
|
23
|
-
hasVisibleError
|
|
22
|
+
showAllErrors
|
|
24
23
|
} = (0, _react.useContext)(_Context.default);
|
|
25
24
|
const onPathErrorRef = (0, _react.useRef)(onPathError);
|
|
26
25
|
onPathErrorRef.current = onPathError;
|
|
@@ -39,6 +38,15 @@ function FieldBoundaryProvider(props) {
|
|
|
39
38
|
forceUpdate();
|
|
40
39
|
(_onPathErrorRef$curre = onPathErrorRef.current) === null || _onPathErrorRef$curre === void 0 ? void 0 : _onPathErrorRef$curre.call(onPathErrorRef, path, error);
|
|
41
40
|
}, []);
|
|
41
|
+
const hasVisibleErrorRef = (0, _react.useRef)({});
|
|
42
|
+
const setVisibleError = (0, _react.useCallback)((path, hasError) => {
|
|
43
|
+
if (hasError) {
|
|
44
|
+
hasVisibleErrorRef.current[path] = hasError;
|
|
45
|
+
} else {
|
|
46
|
+
delete hasVisibleErrorRef.current[path];
|
|
47
|
+
}
|
|
48
|
+
forceUpdate();
|
|
49
|
+
}, []);
|
|
42
50
|
const setShowBoundaryErrors = (0, _react.useCallback)(showBoundaryErrors => {
|
|
43
51
|
showBoundaryErrorsRef.current = showBoundaryErrors;
|
|
44
52
|
forceUpdate();
|
|
@@ -46,11 +54,12 @@ function FieldBoundaryProvider(props) {
|
|
|
46
54
|
const context = {
|
|
47
55
|
hasError,
|
|
48
56
|
hasSubmitError,
|
|
49
|
-
hasVisibleError,
|
|
57
|
+
hasVisibleError: Object.keys(hasVisibleErrorRef.current).length > 0,
|
|
50
58
|
errorsRef,
|
|
51
59
|
showBoundaryErrors: showBoundaryErrorsRef.current,
|
|
52
60
|
setShowBoundaryErrors,
|
|
53
|
-
setFieldError
|
|
61
|
+
setFieldError,
|
|
62
|
+
setVisibleError
|
|
54
63
|
};
|
|
55
64
|
return _react.default.createElement(_FieldBoundaryContext.default.Provider, {
|
|
56
65
|
value: context
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldBoundaryProvider.js","names":["_react","_interopRequireWildcard","require","_FieldBoundaryContext","_interopRequireDefault","_Context","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","FieldBoundaryProvider","props","showErrors","onPathError","children","forceUpdate","useReducer","showAllErrors","
|
|
1
|
+
{"version":3,"file":"FieldBoundaryProvider.js","names":["_react","_interopRequireWildcard","require","_FieldBoundaryContext","_interopRequireDefault","_Context","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","FieldBoundaryProvider","props","showErrors","onPathError","children","forceUpdate","useReducer","showAllErrors","useContext","DataContext","onPathErrorRef","useRef","current","errorsRef","showBoundaryErrorsRef","hasError","keys","length","hasSubmitError","setFieldError","useCallback","path","error","_onPathErrorRef$curre","_errorsRef$current","hasVisibleErrorRef","setVisibleError","setShowBoundaryErrors","showBoundaryErrors","context","hasVisibleError","createElement","Provider","value"],"sources":["../../../../../../src/extensions/forms/DataContext/FieldBoundary/FieldBoundaryProvider.tsx"],"sourcesContent":["import React, { useCallback, useContext, useReducer, useRef } from 'react'\nimport FieldBoundaryContext, {\n FieldBoundaryContextState,\n} from './FieldBoundaryContext'\nimport DataContext from '../Context'\nimport { Path } from '../../types'\n\nexport type Props = {\n showErrors?: boolean\n onPathError?: (path: Path, error: Error) => void\n children: React.ReactNode\n}\n\nexport default function FieldBoundaryProvider(props: Props) {\n const { showErrors = false, onPathError = null, children } = props\n const [, forceUpdate] = useReducer(() => ({}), {})\n const { showAllErrors } = useContext(DataContext)\n\n const onPathErrorRef = useRef(onPathError)\n onPathErrorRef.current = onPathError\n const errorsRef = useRef<Record<Path, boolean>>({})\n const showBoundaryErrorsRef =\n useRef<FieldBoundaryContextState['showBoundaryErrors']>(showErrors)\n const hasError = Object.keys(errorsRef.current).length > 0\n const hasSubmitError = showAllErrors && hasError\n\n const setFieldError = useCallback((path: Path, error: Error) => {\n if (error) {\n errorsRef.current[path] = !!error\n } else {\n delete errorsRef.current?.[path]\n }\n forceUpdate()\n onPathErrorRef.current?.(path, error)\n }, [])\n\n const hasVisibleErrorRef = useRef<Record<Path, boolean>>({})\n const setVisibleError = useCallback((path: Path, hasError: boolean) => {\n if (hasError) {\n hasVisibleErrorRef.current[path] = hasError\n } else {\n delete hasVisibleErrorRef.current[path]\n }\n forceUpdate()\n }, [])\n\n const setShowBoundaryErrors: FieldBoundaryContextState['setShowBoundaryErrors'] =\n useCallback((showBoundaryErrors) => {\n showBoundaryErrorsRef.current = showBoundaryErrors\n forceUpdate()\n }, [])\n\n const context: FieldBoundaryContextState = {\n hasError,\n hasSubmitError,\n hasVisibleError: Object.keys(hasVisibleErrorRef.current).length > 0,\n errorsRef,\n showBoundaryErrors: showBoundaryErrorsRef.current,\n setShowBoundaryErrors,\n setFieldError,\n setVisibleError,\n }\n\n return (\n <FieldBoundaryContext.Provider value={context}>\n {children}\n </FieldBoundaryContext.Provider>\n )\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,qBAAA,GAAAC,sBAAA,CAAAF,OAAA;AAGA,IAAAG,QAAA,GAAAD,sBAAA,CAAAF,OAAA;AAAoC,SAAAE,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAT,wBAAAK,GAAA,EAAAI,WAAA,SAAAA,WAAA,IAAAJ,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAA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CAAC,EAAE,EAAE,CAAC;EAER,MAAMwB,OAAkC,GAAG;IACzCd,QAAQ;IACRG,cAAc;IACdY,eAAe,EAAEvC,MAAM,CAACyB,IAAI,CAACS,kBAAkB,CAACb,OAAO,CAAC,CAACK,MAAM,GAAG,CAAC;IACnEJ,SAAS;IACTe,kBAAkB,EAAEd,qBAAqB,CAACF,OAAO;IACjDe,qBAAqB;IACrBR,aAAa;IACbO;EACF,CAAC;EAED,OACEtD,MAAA,CAAAQ,OAAA,CAAAmD,aAAA,CAACxD,qBAAA,CAAAK,OAAoB,CAACoD,QAAQ;IAACC,KAAK,EAAEJ;EAAQ,GAC3CzB,QAC4B,CAAC;AAEpC"}
|
|
@@ -110,8 +110,4 @@ export interface Props<Data extends JsonObject> extends IsolationProviderProps<D
|
|
|
110
110
|
children: React.ReactNode;
|
|
111
111
|
}
|
|
112
112
|
export default function Provider<Data extends JsonObject>(props: Props<Data>): import("react/jsx-runtime").JSX.Element;
|
|
113
|
-
type PathList = string[];
|
|
114
|
-
export declare function addListPath(paths: PathList, path: Path): PathList;
|
|
115
|
-
export declare function removeListPath(paths: PathList, path: Path): PathList;
|
|
116
113
|
export declare const clearedData: Readonly<{}>;
|
|
117
|
-
export {};
|
|
@@ -4,10 +4,8 @@
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.addListPath = addListPath;
|
|
8
7
|
exports.clearedData = void 0;
|
|
9
8
|
exports.default = Provider;
|
|
10
|
-
exports.removeListPath = removeListPath;
|
|
11
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
12
10
|
var _jsonPointer = _interopRequireDefault(require("json-pointer"));
|
|
13
11
|
var _ajv = require("../../utils/ajv");
|
|
@@ -76,7 +74,7 @@ function Provider(props) {
|
|
|
76
74
|
}
|
|
77
75
|
const translation = (0, _useTranslation.default)().Field;
|
|
78
76
|
const ajvRef = (0, _react.useRef)((0, _ajv.makeAjvInstance)(ajvInstance));
|
|
79
|
-
const
|
|
77
|
+
const mountedFieldsRef = (0, _react.useRef)({});
|
|
80
78
|
const hasVisibleErrorRef = (0, _react.useRef)({});
|
|
81
79
|
const errorsRef = (0, _react.useRef)();
|
|
82
80
|
const showAllErrorsRef = (0, _react.useRef)(false);
|
|
@@ -84,7 +82,7 @@ function Provider(props) {
|
|
|
84
82
|
showAllErrorsRef.current = showAllErrors;
|
|
85
83
|
forceUpdate();
|
|
86
84
|
}, []);
|
|
87
|
-
const
|
|
85
|
+
const setVisibleError = (0, _react.useCallback)((path, hasError) => {
|
|
88
86
|
if (hasError) {
|
|
89
87
|
hasVisibleErrorRef.current[path] = hasError;
|
|
90
88
|
} else {
|
|
@@ -139,14 +137,20 @@ function Provider(props) {
|
|
|
139
137
|
return Boolean(state === 'error' ? ((_errorsRef$current = errorsRef.current) === null || _errorsRef$current === void 0 ? void 0 : _errorsRef$current[path]) instanceof Error || fieldErrorRef.current[path] instanceof Error : fieldStateRef.current[path] === state);
|
|
140
138
|
}, []);
|
|
141
139
|
const hasFieldState = (0, _react.useCallback)(state => {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
140
|
+
for (const path in mountedFieldsRef.current) {
|
|
141
|
+
if (checkFieldStateFor(path, state)) {
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return false;
|
|
145
146
|
}, [checkFieldStateFor]);
|
|
146
147
|
const hasFieldError = (0, _react.useCallback)(path => {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
for (const p in mountedFieldsRef.current) {
|
|
149
|
+
if (p === path && checkFieldStateFor(path, 'error')) {
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return false;
|
|
150
154
|
}, [checkFieldStateFor]);
|
|
151
155
|
const hasErrors = (0, _react.useCallback)(() => {
|
|
152
156
|
return hasFieldState('error');
|
|
@@ -275,7 +279,8 @@ function Provider(props) {
|
|
|
275
279
|
}, []);
|
|
276
280
|
const hasFieldWithAsyncValidator = (0, _react.useCallback)(() => {
|
|
277
281
|
for (const path in fieldPropsRef.current) {
|
|
278
|
-
|
|
282
|
+
var _mountedFieldsRef$cur;
|
|
283
|
+
if ((_mountedFieldsRef$cur = mountedFieldsRef.current[path]) !== null && _mountedFieldsRef$cur !== void 0 && _mountedFieldsRef$cur.isMounted) {
|
|
279
284
|
const props = fieldPropsRef.current[path];
|
|
280
285
|
if ((0, _isAsync.isAsync)(props.validator) || (0, _isAsync.isAsync)(props.onBlurValidator)) {
|
|
281
286
|
return true;
|
|
@@ -454,11 +459,12 @@ function Provider(props) {
|
|
|
454
459
|
changeHandlerStackRef.current.push(callback);
|
|
455
460
|
}
|
|
456
461
|
}, []);
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
+
const setMountedFieldState = (0, _react.useCallback)((path, options) => {
|
|
463
|
+
if (!mountedFieldsRef.current[path]) {
|
|
464
|
+
mountedFieldsRef.current[path] = _objectSpread({}, options);
|
|
465
|
+
} else {
|
|
466
|
+
Object.assign(mountedFieldsRef.current[path], options);
|
|
467
|
+
}
|
|
462
468
|
}, []);
|
|
463
469
|
const scrollToTop = (0, _react.useCallback)(() => {
|
|
464
470
|
if (typeof window !== 'undefined') {
|
|
@@ -494,12 +500,13 @@ function Provider(props) {
|
|
|
494
500
|
}
|
|
495
501
|
if (!skipFieldValidation) {
|
|
496
502
|
for (const item of fieldEventListenersRef.current) {
|
|
503
|
+
var _mountedFieldsRef$cur2;
|
|
497
504
|
const {
|
|
498
505
|
path,
|
|
499
506
|
type,
|
|
500
507
|
callback
|
|
501
508
|
} = item;
|
|
502
|
-
if (type === 'onSubmit' &&
|
|
509
|
+
if (type === 'onSubmit' && (_mountedFieldsRef$cur2 = mountedFieldsRef.current[path]) !== null && _mountedFieldsRef$cur2 !== void 0 && _mountedFieldsRef$cur2.isMounted) {
|
|
503
510
|
if (asyncBehaviorIsEnabled) {
|
|
504
511
|
await callback();
|
|
505
512
|
} else {
|
|
@@ -554,7 +561,6 @@ function Provider(props) {
|
|
|
554
561
|
onSubmitRequest === null || onSubmitRequest === void 0 ? void 0 : onSubmitRequest();
|
|
555
562
|
setShowAllErrors(true);
|
|
556
563
|
}
|
|
557
|
-
return internalDataRef.current;
|
|
558
564
|
}, [clearData, hasErrors, hasFieldState, hasFieldWithAsyncValidator, isolate, onCommit, onSubmitRequest, setFormState, setShowAllErrors, setSubmitState]);
|
|
559
565
|
const handleSubmitListenersRef = (0, _react.useRef)([]);
|
|
560
566
|
const setHandleSubmit = (0, _react.useCallback)(callback => {
|
|
@@ -678,13 +684,12 @@ function Provider(props) {
|
|
|
678
684
|
handlePathChange,
|
|
679
685
|
handlePathChangeUnvalidated,
|
|
680
686
|
handleSubmit,
|
|
681
|
-
|
|
682
|
-
handleUnMountField,
|
|
687
|
+
setMountedFieldState,
|
|
683
688
|
handleSubmitCall,
|
|
684
689
|
setFormState,
|
|
685
690
|
setSubmitState,
|
|
686
691
|
setShowAllErrors,
|
|
687
|
-
|
|
692
|
+
setVisibleError,
|
|
688
693
|
setFieldEventListener,
|
|
689
694
|
setFieldState,
|
|
690
695
|
setFieldError,
|
|
@@ -713,7 +718,7 @@ function Provider(props) {
|
|
|
713
718
|
hasVisibleError: Object.keys(hasVisibleErrorRef.current).length > 0,
|
|
714
719
|
fieldPropsRef,
|
|
715
720
|
valuePropsRef,
|
|
716
|
-
|
|
721
|
+
mountedFieldsRef,
|
|
717
722
|
ajvInstance: ajvRef.current,
|
|
718
723
|
id,
|
|
719
724
|
data: internalDataRef.current,
|
|
@@ -735,12 +740,6 @@ function Provider(props) {
|
|
|
735
740
|
translations: translations ? translations : undefined
|
|
736
741
|
}, children));
|
|
737
742
|
}
|
|
738
|
-
function addListPath(paths, path) {
|
|
739
|
-
return paths.includes(path) ? paths : paths.concat(path);
|
|
740
|
-
}
|
|
741
|
-
function removeListPath(paths, path) {
|
|
742
|
-
return paths.filter(thisPath => thisPath !== path);
|
|
743
|
-
}
|
|
744
743
|
function useFormStatusBuffer(props) {
|
|
745
744
|
const {
|
|
746
745
|
formState,
|