-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3af232e
commit ad35cab
Showing
32 changed files
with
364 additions
and
655 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"printWidth": 100, | ||
"printWidth": 120, | ||
"tabWidth": 2, | ||
"trailingComma": "es5", | ||
"singleQuote": true, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
.../core/src/core/useRegle/useStateProperties/collections/createReactiveCollectionElement.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import type { Ref } from 'vue'; | ||
import { toRef } from 'vue'; | ||
import type { | ||
$InternalFormPropertyTypes, | ||
$InternalRegleErrors, | ||
$InternalRegleStatusType, | ||
RegleCollectionRuleDeclKeyProperty, | ||
} from '../../../../types'; | ||
import { randomId } from '../../../../utils'; | ||
import type { CommonResolverOptions, StateWithId } from '../common/common-types'; | ||
import { createReactiveChildrenStatus } from './../createReactiveNestedStatus'; | ||
|
||
interface CreateCollectionElementArgs extends CommonResolverOptions { | ||
$id: string; | ||
index: number; | ||
stateValue: Ref<StateWithId>; | ||
rules: $InternalFormPropertyTypes & RegleCollectionRuleDeclKeyProperty; | ||
externalErrors: Ref<$InternalRegleErrors[] | undefined> | undefined; | ||
initialState: any[] | undefined; | ||
} | ||
|
||
export function createCollectionElement({ | ||
$id, | ||
path, | ||
index, | ||
options, | ||
storage, | ||
stateValue, | ||
customMessages, | ||
rules, | ||
externalErrors, | ||
initialState, | ||
shortcuts, | ||
fieldName, | ||
}: CreateCollectionElementArgs): $InternalRegleStatusType | null { | ||
const $fieldId = rules.$key ? rules.$key : randomId(); | ||
let $path = `${path}.${String($fieldId)}`; | ||
|
||
if (typeof stateValue.value === 'object' && stateValue.value != null) { | ||
if (!stateValue.value.$id) { | ||
Object.defineProperties(stateValue.value, { | ||
$id: { | ||
value: $fieldId, | ||
enumerable: false, | ||
configurable: false, | ||
writable: false, | ||
}, | ||
}); | ||
} else { | ||
$path = `${path}.${stateValue.value.$id}`; | ||
} | ||
} | ||
|
||
const $status = createReactiveChildrenStatus({ | ||
state: stateValue, | ||
rulesDef: toRef(() => rules), | ||
customMessages, | ||
path: $path, | ||
storage, | ||
options, | ||
externalErrors: toRef(externalErrors?.value ?? [], index), | ||
initialState: initialState?.[index], | ||
shortcuts, | ||
fieldName, | ||
}); | ||
|
||
if ($status) { | ||
const valueId = stateValue.value?.$id; | ||
$status.$id = valueId ?? String($fieldId); | ||
storage.addArrayStatus($id, $status.$id, $status); | ||
} | ||
|
||
return $status; | ||
} |
Oops, something went wrong.