Skip to content
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

Feature/data sources #6018

Merged
merged 86 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 85 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
888a008
Start DataSourceManager
artf Feb 24, 2024
88a1f7f
Start data variable component
artf Feb 24, 2024
903d6cf
Up DataSourceManager
artf Feb 24, 2024
3e58fbe
Up data sources
artf Feb 24, 2024
9eec8b8
Update DataRecord update
artf Feb 27, 2024
b507f68
Up triggerChange
artf Feb 27, 2024
3b3b1f4
Init tests for dataSources
artf Feb 27, 2024
22edded
Refactor
artf Feb 28, 2024
970990e
Improve data variable listeners
artf Feb 28, 2024
6f52e50
Update data variable listener
artf Mar 1, 2024
98fb63c
Add remove to dataSources
artf Mar 1, 2024
9d64fe2
Add getRecord to DataSource
artf Mar 1, 2024
9137f4b
Add removeRecord
artf Mar 1, 2024
1fb6597
Up data record changes tests
artf Mar 1, 2024
32a22b9
Up
artf Mar 1, 2024
ef2d3b2
Up tests
artf Mar 1, 2024
bf04d7d
Up listenToData
artf Mar 2, 2024
7abb437
Add getInnerHTML to ComponentDataVariable
artf Mar 2, 2024
5b2b60d
Up
artf Mar 2, 2024
5f8c188
Merge branch 'dev' into feature/data-sources
danstarns Aug 2, 2024
415d81d
refactor: move dir to _ path pattern & give types to getters
danstarns Aug 2, 2024
e1dae2d
test: refactor to _ data_sources
danstarns Aug 3, 2024
121b839
feat: init datasources into style
danstarns Aug 4, 2024
d371b25
feat: data watchers
danstarns Aug 4, 2024
b8858dc
refactor: *
danstarns Aug 4, 2024
d9154c6
test: add default style var coverage
danstarns Aug 4, 2024
704c587
Merge branch 'dev' into feature/data-sources
danstarns Aug 6, 2024
1b4e092
init: DataSourceTransformers
danstarns Aug 7, 2024
597b207
Merge branch 'dev' into feature/data-sources
danstarns Aug 7, 2024
9088f92
refactor: remove type conflict
danstarns Aug 7, 2024
40c48b4
feat: add onRecordSet methoda
danstarns Aug 8, 2024
ea3ec6a
feat: add onRecordRead datasource
danstarns Aug 8, 2024
c31ef1a
feat: add onRecordDelete data source
danstarns Aug 8, 2024
21930e8
init: add traits
danstarns Aug 14, 2024
adb0544
test: add traint input update coverage
danstarns Aug 14, 2024
f117a96
Merge branch 'dev' into feature/data-sources
danstarns Aug 14, 2024
ecf07e0
refactor: use base data var class and move code into data_sources dire
danstarns Aug 14, 2024
4c24860
test: split data sources into seperate test files around topics
danstarns Aug 14, 2024
b2c9f3f
refactor: remove unused mixins
danstarns Aug 15, 2024
ac08703
test: name changes
danstarns Aug 15, 2024
18e0271
fix: add optional check for model
danstarns Aug 15, 2024
13bf741
test: add placeholder test for trait var
danstarns Aug 15, 2024
b911c08
test: add checkbox datasources trait coverage
danstarns Aug 16, 2024
69c6395
test: add image trait datasource coverage
danstarns Aug 16, 2024
a77af21
test: add link traits data sources coverage
danstarns Aug 16, 2024
4f6139a
docs: init DataSources
danstarns Aug 16, 2024
acb44a5
docs: hook datasources into sidebar
danstarns Aug 17, 2024
17eafe1
test: add datasources init Serialization
danstarns Aug 17, 2024
b53ce12
Merge 'dev' into feature/data-sources
danstarns Aug 20, 2024
592ea79
format: *
danstarns Aug 20, 2024
7ce74dc
Merge branch 'dev' into feature/data-sources
danstarns Aug 21, 2024
80f67e5
feat: working DataVariable with .getProjectData method
danstarns Aug 22, 2024
0f840ff
refactor
danstarns Aug 22, 2024
3be94a9
feat: make DataSources work with .loadProjectData
danstarns Aug 22, 2024
77cdb34
docs: init for datasources
danstarns Aug 22, 2024
2de091a
import fix
danstarns Aug 22, 2024
891f61f
up
danstarns Aug 22, 2024
7ff69fb
refactor: remove unused code
danstarns Aug 22, 2024
a058436
Merge branch 'dev' into feature/data-sources
danstarns Aug 23, 2024
02596a4
refactor: remove logs
danstarns Aug 23, 2024
305d0a8
Merge branch 'dev' into feature/data-sources
artf Aug 25, 2024
987874b
Merge branch 'dev' into feature/data-sources
danstarns Aug 26, 2024
31eb7b8
Merge branch 'dev' into feature/data-sources
danstarns Aug 27, 2024
ed0b0b7
Merge branch 'feature/data-sources' of github.com:GrapesJS/grapesjs i…
danstarns Aug 27, 2024
bceb3a2
docs: *
danstarns Aug 27, 2024
b781f9d
format
danstarns Aug 27, 2024
5d6c479
refactor: move DataSourceProps to types file
danstarns Aug 27, 2024
63b377e
fix: type import in tests
danstarns Aug 27, 2024
1d6d48a
refactor: remove redundant initialize method
danstarns Aug 27, 2024
fdd79e6
test: add component attribute checks alongside model traits
danstarns Aug 27, 2024
fa40cc0
docs: add issue pr link
danstarns Aug 28, 2024
29d2a03
refactor: simplify set logic
danstarns Aug 28, 2024
da44545
refactor: bring back getValye, getContext and fromPath, add nested tests
danstarns Aug 28, 2024
85fbea2
fix: more usage of fromPath for nested items
danstarns Aug 28, 2024
5dc734b
feat: changeProp usage
danstarns Aug 29, 2024
733656f
feat: add setRecords back
danstarns Aug 29, 2024
c0c79dd
refactor: change data var to defaultValue
danstarns Aug 29, 2024
0655954
feat: add default value record removal check and proper listeners
danstarns Aug 29, 2024
843492f
feat: reuse data listeners for style and traits
danstarns Aug 29, 2024
e01d4af
test: remove repeated test
danstarns Aug 29, 2024
7f22ab8
feat: support key value for set with transformers
danstarns Aug 30, 2024
74085e8
feat: reuse DataVariableListenerManager on ComponentDataVar
danstarns Aug 30, 2024
f4cb333
refactor: change to onRecordSetValue
danstarns Aug 30, 2024
d9e1bf5
refactor: remove not needed transformers
danstarns Aug 30, 2024
63e3e19
Merge branch 'dev' into feature/data-sources
danstarns Aug 30, 2024
575da3d
Merge branch 'dev' into feature/data-sources
artf Aug 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ module.exports = {
['/api/keymaps', 'Keymaps'],
['/api/undo_manager', 'Undo Manager'],
['/api/parser', 'Parser'],
['/api/data_source_manager', 'Data Source Manager'],
['/api/datasource', `${subDivider}DataSource`],
['/api/datarecord', `${subDivider}DataRecord`],
],
'/': [
'',
Expand All @@ -126,6 +129,7 @@ module.exports = {
['/modules/Storage', 'Storage Manager'],
['/modules/Modal', 'Modal'],
['/modules/Plugins', 'Plugins'],
['/modules/DataSources', 'Data Sources'],
],
},
{
Expand Down
3 changes: 3 additions & 0 deletions docs/api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ async function generateDocs() {
['pages/index.ts', 'pages.md'],
['pages/model/Page.ts', 'page.md'],
['parser/index.ts', 'parser.md'],
['data_sources/index.ts', 'data_source_manager.md'],
['data_sources/model/DataSource.ts', 'datasource.md'],
['data_sources/model/DataRecord.ts', 'datarecord.md'],
].map(async (file) => {
const filePath = `${srcRoot}/${file[0]}`;

Expand Down
141 changes: 141 additions & 0 deletions docs/api/data_source_manager.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

## DataSources

This module manages data sources within the editor.
You can initialize the module with the editor by passing an instance of `EditorModel`.

```js
const editor = new EditorModel();
const dsm = new DataSourceManager(editor);
```

Once the editor is instantiated, you can use the following API to manage data sources:

```js
const dsm = editor.DataSources;
```

* [add][1] - Add a new data source.
* [get][2] - Retrieve a data source by its ID.
* [getAll][3] - Retrieve all data sources.
* [remove][4] - Remove a data source by its ID.
* [clear][5] - Remove all data sources.

Example of adding a data source:

```js
const ds = dsm.add({
id: 'my_data_source_id',
records: [
{ id: 'id1', name: 'value1' },
{ id: 'id2', name: 'value2' }
]
});
```

### Parameters

* `em` **EditorModel** Editor model.

## add

Add new data source.

### Parameters

* `props` **[Object][6]** Data source properties.
* `opts` **AddOptions** (optional, default `{}`)

### Examples

```javascript
const ds = dsm.add({
id: 'my_data_source_id',
records: [
{ id: 'id1', name: 'value1' },
{ id: 'id2', name: 'value2' }
]
});
```

Returns **[DataSource]** Added data source.

## get

Get data source.

### Parameters

* `id` **[String][7]** Data source id.

### Examples

```javascript
const ds = dsm.get('my_data_source_id');
```

Returns **[DataSource]** Data source.

## getValue

Get value from data sources by key

### Parameters

* `key` **[String][7]** Path to value.
* `defValue` **any**&#x20;

Returns **any** const value = dsm.getValue('ds\_id.record\_id.propName', 'defaultValue');

## remove

Remove data source.

### Parameters

* `id` **([String][7] | [DataSource])** Id of the data source.
* `opts` **RemoveOptions?**&#x20;

### Examples

```javascript
const removed = dsm.remove('DS_ID');
```

Returns **[DataSource]** Removed data source.

## fromPath

Retrieve a data source, data record, and optional property path based on a string path.
This method parses a string path to identify and retrieve the corresponding data source
and data record. If a property path is included in the input, it will also be returned.
The method is useful for accessing nested data within data sources.

### Parameters

* `path` **[String][7]** The string path in the format 'dataSourceId.recordId.property'.

### Examples

```javascript
const [dataSource, dataRecord, propPath] = dsm.fromPath('my_data_source_id.record_id.myProp');
// e.g., [DataSource, DataRecord, 'myProp']
```

Returns **[DataSource?, DataRecord?, [String][7]?]** An array containing the data source,
data record, and optional property path.

[1]: #add

[2]: #get

[3]: #getall

[4]: #remove

[5]: #clear

[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object

[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
115 changes: 115 additions & 0 deletions docs/api/datarecord.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

## DataRecord

The `DataRecord` class represents a single record within a data source.
It extends the base `Model` class and provides additional methods and properties specific to data records.
Each `DataRecord` is associated with a `DataSource` and can trigger events when its properties change.

### DataRecord API

* [getPath][1]
* [getPaths][2]
* [set][3]

### Example of Usage

```js
const record = new DataRecord({ id: 'record1', name: 'value1' }, { collection: dataRecords });
const path = record.getPath(); // e.g., 'SOURCE_ID.record1'
record.set('name', 'newValue');
```

### Parameters

* `props` **DataRecordProps** Properties to initialize the data record.
* `opts` **[Object][4]** Options for initializing the data record.

## getPath

Get the path of the record.
The path is a string that represents the location of the record within the data source.
Optionally, include a property name to create a more specific path.

### Parameters

* `prop` **[String][5]?** Optional property name to include in the path.
* `opts` **[Object][4]?** Options for path generation.

* `opts.useIndex` **[Boolean][6]?** Whether to use the index of the record in the path.

### Examples

```javascript
const pathRecord = record.getPath();
// e.g., 'SOURCE_ID.record1'
const pathRecord2 = record.getPath('myProp');
// e.g., 'SOURCE_ID.record1.myProp'
```

Returns **[String][5]** The path of the record.

## getPaths

Get both ID-based and index-based paths of the record.
Returns an array containing the paths using both ID and index.

### Parameters

* `prop` **[String][5]?** Optional property name to include in the paths.

### Examples

```javascript
const paths = record.getPaths();
// e.g., ['SOURCE_ID.record1', 'SOURCE_ID.0']
```

Returns **[Array][7]<[String][5]>** An array of paths.

## triggerChange

Trigger a change event for the record.
Optionally, include a property name to trigger a change event for a specific property.

### Parameters

* `prop` **[String][5]?** Optional property name to trigger a change event for a specific property.

## set

Set a property on the record, optionally using transformers.
If transformers are defined for the record, they will be applied to the value before setting it.

### Parameters

* `attributeName` **([String][5] | [Object][4])** The name of the attribute to set, or an object of key-value pairs.
* `value` **any?** The value to set for the attribute.
* `options` **[Object][4]?** Options to apply when setting the attribute.

* `options.avoidTransformers` **[Boolean][6]?** If true, transformers will not be applied.

### Examples

```javascript
record.set('name', 'newValue');
// Sets 'name' property to 'newValue'
```

Returns **[DataRecord][8]** The instance of the DataRecord.

[1]: #getpath

[2]: #getpaths

[3]: #set

[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object

[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean

[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array

[8]: #datarecord
Loading