-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Dynamic values improvements #6451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
72 commits
Select commit
Hold shift + click to select a range
a5e8994
Avoid throwing errors if no condition is passed to a DataCondition
mohamedsalem401 b207f28
Refactor Condition class
mohamedsalem401 9a05a4b
Remove expecting errors for conditions tests
mohamedsalem401 265d7fb
Extend and refactor BaseOperator
mohamedsalem401 ebb99a6
Rename and refactor GenericOperator
mohamedsalem401 847ce26
Rename and refactor logicalOperator to BooleanOperator
mohamedsalem401 5420643
Refactor StringOperator
mohamedsalem401 72ca51b
Refactor NumberOperator
mohamedsalem401 2e80660
Refactor and fix DataResolverListener
mohamedsalem401 8a225b2
Update tests for condition Operators
mohamedsalem401 ed58822
Rename Condition class to ConditionEvaluator
mohamedsalem401 4049620
Add missing types file
mohamedsalem401 62c0684
Update and refactor DataCondition
mohamedsalem401 a951dd4
Update utils
mohamedsalem401 85abba3
Refactor StyleableModel class
mohamedsalem401 4f4d68d
Update ComponentDataCondition
mohamedsalem401 2aaf427
Refactor ComponentResolverWatcher
mohamedsalem401 b00ac0d
Fix conditional styles
mohamedsalem401 929ab42
Rename LogicalGroupStatement to LogicalGroupEvaluator
mohamedsalem401 761bdbf
Fix tests for DataCondition
mohamedsalem401 8a5d45d
Add setter methods for component data variable
mohamedsalem401 7e7e797
Add setters and getter to ComponentDataCondition
mohamedsalem401 c98b78b
Add getters to ComponentDataVariable
mohamedsalem401 d5e1f96
Rename test file
mohamedsalem401 6e266a2
Merge branch 'dev' of https://github.com/GrapesJS/grapesjs into dynam…
mohamedsalem401 deb5a74
Make dynamic components undroppable
mohamedsalem401 b93153d
Fix collection types
mohamedsalem401 af5a0c5
Update collections ( add setters and getter, first item editable, syn…
mohamedsalem401 ec81416
Update data collection tests
mohamedsalem401 ac8c576
Format tests
mohamedsalem401 04f72fb
Fix some ComponentData collection bugs
mohamedsalem401 1428d88
Refactor setStartIndex and setEndIndex
mohamedsalem401 9aae95c
Fix getComponentDef test
mohamedsalem401 a643411
Fix bug with end index = 0
mohamedsalem401 80237cd
fix test for setDataSource
mohamedsalem401 72f4d81
fix test for HTML updates
mohamedsalem401 e5fcba3
Format
mohamedsalem401 bee0643
Merge branch 'dev' of https://github.com/GrapesJS/grapesjs into dynam…
mohamedsalem401 215ade0
Add tests for the new option in getDataValue for conditions ( skipDyn…
mohamedsalem401 174b11b
rename Operation to DataConditionOperation
mohamedsalem401 dcfb273
Run __onStyleChange after style changes as before
mohamedsalem401 ef13f27
Format
mohamedsalem401 99fff68
Up BooleanOperator
artf 9c6cb0c
Merge branch 'dev' of https://github.com/artf/grapesjs into dynamic-v…
artf 6c8783a
Merge branch 'dev' of https://github.com/GrapesJS/grapesjs into dynam…
mohamedsalem401 154cbc9
Avoid raising errors for wrong dynamic value types
mohamedsalem401 1a90a53
Refactor DataCondition
mohamedsalem401 53b5006
Format
mohamedsalem401 3a6505a
Refactor how component data variable works internally
mohamedsalem401 4f7f1b6
Symbols fix
mohamedsalem401 a0ba9da
Add docs
mohamedsalem401 55b16d9
Refactor componentDatacondition
mohamedsalem401 1bb179d
Add types for Datacondition output ( result ) types
mohamedsalem401 13dacb3
Refactor DataCondition
mohamedsalem401 41e5887
Refactor ComponentDataCollection
mohamedsalem401 fbb5616
Refactor styleableModel
mohamedsalem401 63cefe9
Add missing files and utils
mohamedsalem401 a5a1dde
Up tests for ComponentDataCondition
mohamedsalem401 14bd129
Add new tests for component data condition
mohamedsalem401 3e2faf2
Fix quality check
mohamedsalem401 bb0650d
Merge branch 'dev' into dynamic-values-improvements
artf bca58dd
Move ComponentDataVariable path and default value to dataResolver pro…
mohamedsalem401 c893319
Update component data condition structure
mohamedsalem401 e33551d
Refactor data condition
mohamedsalem401 8dd768d
Merge branch 'dev' of https://github.com/GrapesJS/grapesjs into dynam…
mohamedsalem401 a14c4af
Fix ifTrue and ifFalse position in ComponentDataCondition
mohamedsalem401 5dcad3d
Fix typescript
mohamedsalem401 2af7785
Change setIfTrueContent to be setIfTrueComponents
mohamedsalem401 6cbca33
Fix memory leak for binding to this.postRender
mohamedsalem401 4e34882
Cleanup ComponentDataConditionView
mohamedsalem401 18309f0
Up tests
mohamedsalem401 e5479e0
Merge branch 'dev' into dynamic-values-improvements
mohamedsalem401 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
124 changes: 93 additions & 31 deletions
124
packages/core/src/data_sources/model/conditional_variables/ComponentDataCondition.ts
This file contains hidden or 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,61 +1,123 @@ | ||
| import Component from '../../../dom_components/model/Component'; | ||
| import { ComponentDefinition, ComponentOptions } from '../../../dom_components/model/types'; | ||
| import { | ||
| ComponentDefinition as ComponentProperties, | ||
| ComponentDefinitionDefined, | ||
| ComponentOptions, | ||
| ToHTMLOptions, | ||
| ComponentAddType, | ||
| } from '../../../dom_components/model/types'; | ||
| import { toLowerCase } from '../../../utils/mixins'; | ||
| import { DataCondition, DataConditionProps, DataConditionType } from './DataCondition'; | ||
| import { DataCondition, DataConditionOutputChangedEvent, DataConditionProps, DataConditionType } from './DataCondition'; | ||
| import { ConditionProps } from './DataConditionEvaluator'; | ||
| import { StringOperation } from './operators/StringOperator'; | ||
| import { ObjectAny } from '../../../common'; | ||
| import { DataConditionIfTrueType, DataConditionIfFalseType } from './constants'; | ||
|
|
||
| export type DataConditionDisplayType = typeof DataConditionIfTrueType | typeof DataConditionIfFalseType; | ||
|
|
||
| export interface ComponentDataConditionProps extends ComponentProperties { | ||
| type: typeof DataConditionType; | ||
| dataResolver: DataConditionProps; | ||
| } | ||
|
|
||
| export default class ComponentDataCondition extends Component { | ||
| dataResolver: DataCondition; | ||
|
|
||
| constructor(props: DataConditionProps, opt: ComponentOptions) { | ||
| const dataConditionInstance = new DataCondition(props, { em: opt.em }); | ||
|
|
||
| super( | ||
| { | ||
| ...props, | ||
| type: DataConditionType, | ||
| components: dataConditionInstance.getDataValue(), | ||
| droppable: false, | ||
| get defaults(): ComponentDefinitionDefined { | ||
| return { | ||
| // @ts-ignore | ||
| ...super.defaults, | ||
| droppable: false, | ||
| type: DataConditionType, | ||
| dataResolver: { | ||
| condition: { | ||
| left: '', | ||
| operator: StringOperation.equalsIgnoreCase, | ||
| right: '', | ||
| }, | ||
| }, | ||
| opt, | ||
| ); | ||
| this.dataResolver = dataConditionInstance; | ||
| this.dataResolver.onValueChange = this.handleConditionChange.bind(this); | ||
| components: [ | ||
| { | ||
| type: DataConditionIfTrueType, | ||
| }, | ||
| { | ||
| type: DataConditionIfFalseType, | ||
| }, | ||
| ], | ||
| }; | ||
| } | ||
|
|
||
| getCondition() { | ||
| return this.dataResolver.getCondition(); | ||
| constructor(props: ComponentDataConditionProps, opt: ComponentOptions) { | ||
| // @ts-ignore | ||
| super(props, opt); | ||
|
|
||
| const { condition } = props.dataResolver; | ||
| this.dataResolver = new DataCondition({ condition }, { em: opt.em }); | ||
|
|
||
| this.listenToPropsChange(); | ||
| } | ||
|
|
||
| getIfTrue() { | ||
| return this.dataResolver.getIfTrue(); | ||
| isTrue() { | ||
| return this.dataResolver.isTrue(); | ||
| } | ||
|
|
||
| getIfFalse() { | ||
| return this.dataResolver.getIfFalse(); | ||
| getCondition() { | ||
| return this.dataResolver.getCondition(); | ||
| } | ||
|
|
||
| private handleConditionChange() { | ||
| this.components(this.dataResolver.getDataValue()); | ||
| getIfTrueContent(): Component | undefined { | ||
| return this.components().at(0); | ||
| } | ||
|
|
||
| static isComponent(el: HTMLElement) { | ||
| return toLowerCase(el.tagName) === DataConditionType; | ||
| getIfFalseContent(): Component | undefined { | ||
| return this.components().at(1); | ||
| } | ||
|
|
||
| getOutputContent(): Component | undefined { | ||
| return this.isTrue() ? this.getIfTrueContent() : this.getIfFalseContent(); | ||
| } | ||
|
|
||
| setCondition(newCondition: ConditionProps) { | ||
| this.dataResolver.setCondition(newCondition); | ||
| } | ||
|
|
||
| setIfTrue(newIfTrue: any) { | ||
| this.dataResolver.setIfTrue(newIfTrue); | ||
| setIfTrueComponents(content: ComponentAddType) { | ||
| this.setComponentsAtIndex(0, content); | ||
| } | ||
|
|
||
| setIfFalseComponents(content: ComponentAddType) { | ||
| this.setComponentsAtIndex(1, content); | ||
| } | ||
|
|
||
| getInnerHTML(opts?: ToHTMLOptions): string { | ||
| return this.getOutputContent()?.getInnerHTML(opts) ?? ''; | ||
| } | ||
|
|
||
| private setComponentsAtIndex(index: number, newContent: ComponentAddType) { | ||
| const component = this.components().at(index); | ||
| component?.components(newContent); | ||
| } | ||
|
|
||
| private listenToPropsChange() { | ||
| this.on('change:dataResolver', () => { | ||
| this.dataResolver.set(this.get('dataResolver')); | ||
| }); | ||
| } | ||
|
|
||
| setIfFalse(newIfFalse: any) { | ||
| this.dataResolver.setIfFalse(newIfFalse); | ||
| toJSON(opts?: ObjectAny): ComponentProperties { | ||
| const json = super.toJSON(opts); | ||
| const dataResolver = this.dataResolver.toJSON(); | ||
| delete dataResolver.type; | ||
| delete dataResolver.ifTrue; | ||
| delete dataResolver.ifFalse; | ||
artf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return { | ||
| ...json, | ||
| dataResolver, | ||
| }; | ||
| } | ||
|
|
||
| toJSON(): ComponentDefinition { | ||
| return this.dataResolver.toJSON(); | ||
| static isComponent(el: HTMLElement) { | ||
| return toLowerCase(el.tagName) === DataConditionType; | ||
| } | ||
| } | ||
19 changes: 19 additions & 0 deletions
19
packages/core/src/data_sources/model/conditional_variables/ConditionalOutputBase.ts
This file contains hidden or 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,19 @@ | ||
| import Component from '../../../dom_components/model/Component'; | ||
| import { ComponentDefinitionDefined, ToHTMLOptions } from '../../../dom_components/model/types'; | ||
| import { toLowerCase } from '../../../utils/mixins'; | ||
| import { isDataConditionDisplayType } from '../../utils'; | ||
|
|
||
| export default class ConditionalOutputBase extends Component { | ||
| get defaults(): ComponentDefinitionDefined { | ||
| return { | ||
| // @ts-ignore | ||
| ...super.defaults, | ||
| removable: false, | ||
| draggable: false, | ||
| }; | ||
| } | ||
|
|
||
| static isComponent(el: HTMLElement) { | ||
| return isDataConditionDisplayType(toLowerCase(el.tagName)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.