-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: conditionals operations for dialog objects (#86)
* feat: add conditional functions to dialog * feat: add conditions implementation * fix: missing tabs schema * fix: types for component function * feat: type conditions operations * refactor: move utils to types folder * refactor: move types to new files * feat: add new conditional operators Signed-off-by: Francisco Madeira <francisco.madeira@diconium.com> * chore: setup paths test * chore: deprecate rollup plugin * chore: add alias to vitecondig * fix: add correct type to select * chore: add changesets for publish * fix: add all node paths to Operators field Signed-off-by: Francisco Madeira <francisco.madeira@diconium.com> --------- Signed-off-by: Francisco Madeira <francisco.madeira@diconium.com>
- Loading branch information
Showing
41 changed files
with
5,487 additions
and
4,102 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Changesets | ||
|
||
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works | ||
with multi-package repos, or single-package repos to help you version and publish your code. You can | ||
find the full documentation for it [in our repository](https://github.com/changesets/changesets) | ||
|
||
We have a quick list of common questions to get you started engaging with this project in | ||
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) |
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,11 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/config@3.0.3/schema.json", | ||
"changelog": "@changesets/cli/changelog", | ||
"commit": false, | ||
"fixed": [], | ||
"linked": [], | ||
"access": "restricted", | ||
"baseBranch": "main", | ||
"updateInternalDependencies": "patch", | ||
"ignore": [] | ||
} |
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,6 @@ | ||
--- | ||
'@ethereal-nexus/vite-plugin-ethereal-nexus': minor | ||
'@ethereal-nexus/core': minor | ||
--- | ||
|
||
Updated libraries to support the conditionals behavior for dialogs. |
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,5 @@ | ||
--- | ||
'@ethereal-nexus/core': patch | ||
--- | ||
|
||
fix type inference for select schema |
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
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,50 @@ | ||
import { NestedPaths } from '../../types'; | ||
import { ConditionFn, ConditionOperators, Conditions, Field } from './types'; | ||
import { ObjectEntries } from '../../types/object'; | ||
|
||
function addConditionToField(fields: Field[], path: string, condition: Conditions): void { | ||
const keys = path.split('.'); | ||
let currentFields = fields; | ||
|
||
for (let i = 0; i < keys.length; i++) { | ||
const key = keys[i]; | ||
const field = currentFields.find(f => f.id === key); | ||
|
||
if (!field) { | ||
throw new Error(`Field with id "${key}" not found`); | ||
} | ||
|
||
if (i === keys.length - 1) { | ||
field.condition = condition; | ||
} else { | ||
if (!field.children) { | ||
throw new Error(`Field with id "${key}" has no children`); | ||
} | ||
currentFields = field.children; | ||
} | ||
} | ||
} | ||
|
||
export class Condition<TEntries extends ObjectEntries> { | ||
private conditions = new Map<string, Conditions>(); | ||
|
||
addCondition(field: NestedPaths<TEntries>, condition: ConditionFn<TEntries>) { | ||
const operators: ConditionOperators<TEntries> = { | ||
eq: (field, value) => ({ operator: 'eq', field, value }), | ||
neq: (field, value) => ({ operator: 'neq', field, value }), | ||
exists: (field) => ({ operator: 'exists', field }), | ||
and: (...operations) => ({ operator: 'and', value: operations }), | ||
or: (...operations) => ({ operator: 'or', value: operations }) | ||
}; | ||
|
||
this.conditions.set(field, condition(operators)); | ||
} | ||
|
||
parse(entries: Field[]) { | ||
for (let [key, value] of this.conditions) { | ||
addConditionToField(entries, key, value) | ||
} | ||
|
||
return entries; | ||
} | ||
} |
Oops, something went wrong.