forked from silverstripe/silverstripe-elemental
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entwine.js
45 lines (39 loc) · 1.14 KB
/
entwine.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* global window */
import jQuery from 'jquery';
import React from 'react';
import ReactDOM from 'react-dom';
import { loadComponent } from 'lib/Injector';
/**
* Uses entwine to inject the HistoryViewer React component into the DOM, when used
* outside of a React context e.g. in the CMS
*/
jQuery.entwine('ss', ($) => {
$('.js-injector-boot .element-editor__container').entwine({
onmatch() {
const context = {};
const ElementEditorComponent = loadComponent('ElementEditor', context);
const schemaData = this.data('schema');
const props = {
fieldName: this.attr('name'),
pageId: schemaData['page-id'],
elementTypes: schemaData['element-types'],
baseAddHref: schemaData['base-add-href']
};
ReactDOM.render(
<ElementEditorComponent {...props} />,
this[0]
);
},
onunmatch() {
ReactDOM.unmountComponentAtNode(this[0]);
},
/**
* Make sure the editor has flushed all it's buffers before the form is submitted.
*/
'from .cms-edit-form': {
onaftersubmitform() {
window.ss.apolloClient.resetStore();
}
},
});
});