UNPKG

contentful-management

Version:
49 lines (46 loc) 1.66 kB
import copy from 'fast-copy'; import { toPlainObject, freezeSys } from 'contentful-sdk-core'; import enhanceWithMethods from '../enhance-with-methods.js'; import { wrapCollection } from '../common-utils.js'; /** * @internal */ function createEditorInterfaceApi(makeRequest) { return { update: function () { const self = this; const raw = self.toPlainObject(); return makeRequest({ entityType: 'EditorInterface', action: 'update', params: { spaceId: self.sys.space.sys.id, environmentId: self.sys.environment.sys.id, contentTypeId: self.sys.contentType.sys.id, }, payload: raw, }).then((response) => wrapEditorInterface(makeRequest, response)); }, getControlForField: function (fieldId) { const self = this; const result = (self.controls || []).filter((control) => { return control.fieldId === fieldId; }); return result && result.length > 0 ? result[0] : null; }, }; } /** * @internal */ function wrapEditorInterface(makeRequest, data) { const editorInterface = toPlainObject(copy(data)); const editorInterfaceWithMethods = enhanceWithMethods(editorInterface, createEditorInterfaceApi(makeRequest)); return freezeSys(editorInterfaceWithMethods); } /** * @internal */ const wrapEditorInterfaceCollection = wrapCollection(wrapEditorInterface); export { wrapEditorInterface, wrapEditorInterfaceCollection }; //# sourceMappingURL=editor-interface.js.map