|
3 | 3 | ## DataSources |
4 | 4 |
|
5 | 5 | This module manages data sources within the editor. |
6 | | -You can initialize the module with the editor by passing an instance of `EditorModel`. |
| 6 | +Once the editor is instantiated, you can use the following API to manage data sources: |
7 | 7 |
|
8 | 8 | ```js |
9 | | -const editor = new EditorModel(); |
10 | | -const dsm = new DataSourceManager(editor); |
| 9 | +const editor = grapesjs.init({ ... }); |
| 10 | +const dsm = editor.DataSources; |
11 | 11 | ``` |
12 | 12 |
|
13 | | -Once the editor is instantiated, you can use the following API to manage data sources: |
| 13 | +## Available Events |
| 14 | +* `data:add` Added new data source. |
14 | 15 |
|
15 | | -```js |
16 | | -const dsm = editor.DataSources; |
| 16 | +```javascript |
| 17 | +editor.on('data:add', (dataSource) => { ... }); |
17 | 18 | ``` |
18 | 19 |
|
19 | | -* [add][1] - Add a new data source. |
20 | | -* [get][2] - Retrieve a data source by its ID. |
21 | | -* [getAll][3] - Retrieve all data sources. |
22 | | -* [remove][4] - Remove a data source by its ID. |
23 | | -* [clear][5] - Remove all data sources. |
| 20 | +* `data:remove` Data source removed. |
24 | 21 |
|
25 | | -Example of adding a data source: |
| 22 | +```javascript |
| 23 | +editor.on('data:remove', (dataSource) => { ... }); |
| 24 | +``` |
26 | 25 |
|
27 | | -```js |
28 | | -const ds = dsm.add({ |
29 | | - id: 'my_data_source_id', |
30 | | - records: [ |
31 | | - { id: 'id1', name: 'value1' }, |
32 | | - { id: 'id2', name: 'value2' } |
33 | | - ] |
| 26 | +* `data:update` Data source updated. |
| 27 | + |
| 28 | +```javascript |
| 29 | +editor.on('data:update', (dataSource, changes) => { ... }); |
| 30 | +``` |
| 31 | + |
| 32 | +* `data:path` Data record path update. |
| 33 | + |
| 34 | +```javascript |
| 35 | +editor.on('data:path:SOURCE_ID.RECORD_ID.PROP_NAME', ({ dataSource, dataRecord, path }) => { ... }); |
| 36 | +editor.on('data:path', ({ dataSource, dataRecord, path }) => { |
| 37 | + console.log('Path update in any data source') |
34 | 38 | }); |
35 | 39 | ``` |
36 | 40 |
|
37 | | -### Parameters |
| 41 | +* `data:pathSource` Data record path update per source. |
| 42 | + |
| 43 | +```javascript |
| 44 | +editor.on('data:pathSource:SOURCE_ID', ({ dataSource, dataRecord, path }) => { ... }); |
| 45 | +``` |
| 46 | + |
| 47 | +* `data` Catch-all event for all the events mentioned above. |
| 48 | + |
| 49 | +```javascript |
| 50 | +editor.on('data', ({ event, model, ... }) => { ... }); |
| 51 | +``` |
| 52 | + |
| 53 | +## Methods |
| 54 | + |
| 55 | +* [add][1] - Add a new data source. |
| 56 | +* [get][2] - Retrieve a data source by its ID. |
| 57 | +* [getAll][3] - Retrieve all data sources. |
| 58 | +* [remove][4] - Remove a data source by its ID. |
| 59 | +* [clear][5] - Remove all data sources. |
38 | 60 |
|
39 | | -* `em` **EditorModel** Editor model. |
| 61 | +[DataSource]: datasource.html |
40 | 62 |
|
41 | 63 | ## add |
42 | 64 |
|
|
0 commit comments