@atlaskit/embedded-document 0.7.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +978 -0
- package/LICENSE +13 -0
- package/build/tsconfig.json +17 -0
- package/dist/cjs/components/document.js +157 -0
- package/dist/cjs/components/toolbar.js +89 -0
- package/dist/cjs/consumers/consumer.js +102 -0
- package/dist/cjs/consumers/document-body.js +95 -0
- package/dist/cjs/consumers/with-document-actions.js +139 -0
- package/dist/cjs/context/context.js +71 -0
- package/dist/cjs/context/embedded-document.js +396 -0
- package/dist/cjs/index.js +47 -0
- package/dist/cjs/model/index.js +5 -0
- package/dist/cjs/provider/index.js +35 -0
- package/dist/cjs/provider/provider.js +5 -0
- package/dist/cjs/provider/service-provider.js +240 -0
- package/dist/cjs/version.json +5 -0
- package/dist/es2019/components/document.js +107 -0
- package/dist/es2019/components/toolbar.js +45 -0
- package/dist/es2019/consumers/consumer.js +62 -0
- package/dist/es2019/consumers/document-body.js +49 -0
- package/dist/es2019/consumers/with-document-actions.js +35 -0
- package/dist/es2019/context/context.js +19 -0
- package/dist/es2019/context/embedded-document.js +216 -0
- package/dist/es2019/index.js +5 -0
- package/dist/es2019/model/index.js +1 -0
- package/dist/es2019/provider/index.js +18 -0
- package/dist/es2019/provider/provider.js +1 -0
- package/dist/es2019/provider/service-provider.js +101 -0
- package/dist/es2019/version.json +5 -0
- package/dist/esm/components/document.js +136 -0
- package/dist/esm/components/toolbar.js +70 -0
- package/dist/esm/consumers/consumer.js +84 -0
- package/dist/esm/consumers/document-body.js +77 -0
- package/dist/esm/consumers/with-document-actions.js +119 -0
- package/dist/esm/context/context.js +59 -0
- package/dist/esm/context/embedded-document.js +375 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/model/index.js +1 -0
- package/dist/esm/provider/index.js +18 -0
- package/dist/esm/provider/provider.js +1 -0
- package/dist/esm/provider/service-provider.js +229 -0
- package/dist/esm/version.json +5 -0
- package/dist/types/components/document.d.ts +20 -0
- package/dist/types/components/toolbar.d.ts +6 -0
- package/dist/types/consumers/consumer.d.ts +23 -0
- package/dist/types/consumers/document-body.d.ts +13 -0
- package/dist/types/consumers/with-document-actions.d.ts +16 -0
- package/dist/types/context/context.d.ts +22 -0
- package/dist/types/context/embedded-document.d.ts +41 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/model/index.d.ts +19 -0
- package/dist/types/provider/index.d.ts +9 -0
- package/dist/types/provider/provider.d.ts +7 -0
- package/dist/types/provider/service-provider.d.ts +13 -0
- package/package.json +44 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
5
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
6
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
7
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
8
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
9
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
10
|
+
|
|
11
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
12
|
+
|
|
13
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
14
|
+
|
|
15
|
+
import React from 'react';
|
|
16
|
+
import { PureComponent } from 'react';
|
|
17
|
+
import { Consumer } from '../consumers/consumer';
|
|
18
|
+
|
|
19
|
+
var WithDocumentActions = /*#__PURE__*/function (_PureComponent) {
|
|
20
|
+
_inherits(WithDocumentActions, _PureComponent);
|
|
21
|
+
|
|
22
|
+
var _super = _createSuper(WithDocumentActions);
|
|
23
|
+
|
|
24
|
+
function WithDocumentActions() {
|
|
25
|
+
var _this;
|
|
26
|
+
|
|
27
|
+
_classCallCheck(this, WithDocumentActions);
|
|
28
|
+
|
|
29
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
30
|
+
args[_key] = arguments[_key];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
34
|
+
|
|
35
|
+
_defineProperty(_assertThisInitialized(_this), "actionsMapper", function (actions) {
|
|
36
|
+
return {
|
|
37
|
+
createDocument: function createDocument(value) {
|
|
38
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
39
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
40
|
+
while (1) {
|
|
41
|
+
switch (_context.prev = _context.next) {
|
|
42
|
+
case 0:
|
|
43
|
+
return _context.abrupt("return", actions.createDocument(value));
|
|
44
|
+
|
|
45
|
+
case 1:
|
|
46
|
+
case "end":
|
|
47
|
+
return _context.stop();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}, _callee);
|
|
51
|
+
}))();
|
|
52
|
+
},
|
|
53
|
+
editDocument: function editDocument() {
|
|
54
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
55
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
56
|
+
while (1) {
|
|
57
|
+
switch (_context2.prev = _context2.next) {
|
|
58
|
+
case 0:
|
|
59
|
+
actions.setDocumentMode('edit');
|
|
60
|
+
|
|
61
|
+
case 1:
|
|
62
|
+
case "end":
|
|
63
|
+
return _context2.stop();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}, _callee2);
|
|
67
|
+
}))();
|
|
68
|
+
},
|
|
69
|
+
updateDocument: function updateDocument(value) {
|
|
70
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
71
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
72
|
+
while (1) {
|
|
73
|
+
switch (_context3.prev = _context3.next) {
|
|
74
|
+
case 0:
|
|
75
|
+
return _context3.abrupt("return", actions.updateDocument(value));
|
|
76
|
+
|
|
77
|
+
case 1:
|
|
78
|
+
case "end":
|
|
79
|
+
return _context3.stop();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}, _callee3);
|
|
83
|
+
}))();
|
|
84
|
+
},
|
|
85
|
+
cancelEdit: function cancelEdit() {
|
|
86
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
|
87
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
88
|
+
while (1) {
|
|
89
|
+
switch (_context4.prev = _context4.next) {
|
|
90
|
+
case 0:
|
|
91
|
+
actions.setDocumentMode('view');
|
|
92
|
+
|
|
93
|
+
case 1:
|
|
94
|
+
case "end":
|
|
95
|
+
return _context4.stop();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}, _callee4);
|
|
99
|
+
}))();
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return _this;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
_createClass(WithDocumentActions, [{
|
|
108
|
+
key: "render",
|
|
109
|
+
value: function render() {
|
|
110
|
+
return /*#__PURE__*/React.createElement(Consumer, {
|
|
111
|
+
actionsMapper: this.actionsMapper
|
|
112
|
+
}, this.props.render);
|
|
113
|
+
}
|
|
114
|
+
}]);
|
|
115
|
+
|
|
116
|
+
return WithDocumentActions;
|
|
117
|
+
}(PureComponent);
|
|
118
|
+
|
|
119
|
+
export { WithDocumentActions as default };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import { createContext } from 'react';
|
|
4
|
+
|
|
5
|
+
var noop = function noop() {};
|
|
6
|
+
|
|
7
|
+
export var Context = /*#__PURE__*/createContext({
|
|
8
|
+
value: {},
|
|
9
|
+
actions: {
|
|
10
|
+
getDocument: noop,
|
|
11
|
+
getDocumentByObjectId: noop,
|
|
12
|
+
setDocumentMode: noop,
|
|
13
|
+
updateDocument: function () {
|
|
14
|
+
var _updateDocument = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
15
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
16
|
+
while (1) {
|
|
17
|
+
switch (_context.prev = _context.next) {
|
|
18
|
+
case 0:
|
|
19
|
+
throw new Error('Not implemented.');
|
|
20
|
+
|
|
21
|
+
case 1:
|
|
22
|
+
case "end":
|
|
23
|
+
return _context.stop();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}, _callee);
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
function updateDocument() {
|
|
30
|
+
return _updateDocument.apply(this, arguments);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return updateDocument;
|
|
34
|
+
}(),
|
|
35
|
+
createDocument: function () {
|
|
36
|
+
var _createDocument = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
37
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
38
|
+
while (1) {
|
|
39
|
+
switch (_context2.prev = _context2.next) {
|
|
40
|
+
case 0:
|
|
41
|
+
throw new Error('Not implemented.');
|
|
42
|
+
|
|
43
|
+
case 1:
|
|
44
|
+
case "end":
|
|
45
|
+
return _context2.stop();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}, _callee2);
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
function createDocument() {
|
|
52
|
+
return _createDocument.apply(this, arguments);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return createDocument;
|
|
56
|
+
}()
|
|
57
|
+
},
|
|
58
|
+
renderProps: {}
|
|
59
|
+
});
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
5
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
6
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
7
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
8
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
9
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
10
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
|
|
11
|
+
|
|
12
|
+
var _templateObject;
|
|
13
|
+
|
|
14
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
15
|
+
|
|
16
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
17
|
+
|
|
18
|
+
import React from 'react';
|
|
19
|
+
import { Component } from 'react';
|
|
20
|
+
import styled from 'styled-components';
|
|
21
|
+
import { Context } from './context';
|
|
22
|
+
import { getProvider } from '../provider';
|
|
23
|
+
import { akEditorGutterPadding } from '@atlaskit/editor-shared-styles';
|
|
24
|
+
export var akEditorFullPageMaxWidth = 680;
|
|
25
|
+
var Content = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n line-height: 24px;\n height: 100%;\n width: 100%;\n max-width: ", "px;\n padding-top: 50px;\n margin: 0 auto;\n display: flex;\n flex-direction: column;\n flex-grow: 1;\n padding-bottom: 55px;\n\n & > * {\n padding: 0 32px;\n }\n"])), akEditorFullPageMaxWidth + akEditorGutterPadding * 2);
|
|
26
|
+
|
|
27
|
+
var EmbeddedDocument = /*#__PURE__*/function (_Component) {
|
|
28
|
+
_inherits(EmbeddedDocument, _Component);
|
|
29
|
+
|
|
30
|
+
var _super = _createSuper(EmbeddedDocument);
|
|
31
|
+
|
|
32
|
+
function EmbeddedDocument(props) {
|
|
33
|
+
var _this;
|
|
34
|
+
|
|
35
|
+
_classCallCheck(this, EmbeddedDocument);
|
|
36
|
+
|
|
37
|
+
_this = _super.call(this, props);
|
|
38
|
+
|
|
39
|
+
_defineProperty(_assertThisInitialized(_this), "getDocumentByObjectId", /*#__PURE__*/function () {
|
|
40
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(objectId, language) {
|
|
41
|
+
var doc;
|
|
42
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
43
|
+
while (1) {
|
|
44
|
+
switch (_context.prev = _context.next) {
|
|
45
|
+
case 0:
|
|
46
|
+
_this.setState({
|
|
47
|
+
isLoading: true
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
_context.next = 3;
|
|
51
|
+
return _this.provider.getDocumentByObjectId(objectId, language);
|
|
52
|
+
|
|
53
|
+
case 3:
|
|
54
|
+
doc = _context.sent;
|
|
55
|
+
|
|
56
|
+
_this.setDocumentState(doc);
|
|
57
|
+
|
|
58
|
+
case 5:
|
|
59
|
+
case "end":
|
|
60
|
+
return _context.stop();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}, _callee);
|
|
64
|
+
}));
|
|
65
|
+
|
|
66
|
+
return function (_x, _x2) {
|
|
67
|
+
return _ref.apply(this, arguments);
|
|
68
|
+
};
|
|
69
|
+
}());
|
|
70
|
+
|
|
71
|
+
_defineProperty(_assertThisInitialized(_this), "getDocument", /*#__PURE__*/function () {
|
|
72
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(documentId, language) {
|
|
73
|
+
var doc;
|
|
74
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
75
|
+
while (1) {
|
|
76
|
+
switch (_context2.prev = _context2.next) {
|
|
77
|
+
case 0:
|
|
78
|
+
_this.setState({
|
|
79
|
+
isLoading: true
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
_context2.next = 3;
|
|
83
|
+
return _this.provider.getDocument(documentId, language);
|
|
84
|
+
|
|
85
|
+
case 3:
|
|
86
|
+
doc = _context2.sent;
|
|
87
|
+
|
|
88
|
+
_this.setDocumentState(doc);
|
|
89
|
+
|
|
90
|
+
case 5:
|
|
91
|
+
case "end":
|
|
92
|
+
return _context2.stop();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}, _callee2);
|
|
96
|
+
}));
|
|
97
|
+
|
|
98
|
+
return function (_x3, _x4) {
|
|
99
|
+
return _ref2.apply(this, arguments);
|
|
100
|
+
};
|
|
101
|
+
}());
|
|
102
|
+
|
|
103
|
+
_defineProperty(_assertThisInitialized(_this), "setDocumentMode", /*#__PURE__*/function () {
|
|
104
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(mode) {
|
|
105
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
106
|
+
while (1) {
|
|
107
|
+
switch (_context3.prev = _context3.next) {
|
|
108
|
+
case 0:
|
|
109
|
+
_this.setState({
|
|
110
|
+
mode: mode
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
case 1:
|
|
114
|
+
case "end":
|
|
115
|
+
return _context3.stop();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}, _callee3);
|
|
119
|
+
}));
|
|
120
|
+
|
|
121
|
+
return function (_x5) {
|
|
122
|
+
return _ref3.apply(this, arguments);
|
|
123
|
+
};
|
|
124
|
+
}());
|
|
125
|
+
|
|
126
|
+
_defineProperty(_assertThisInitialized(_this), "updateDocument", /*#__PURE__*/function () {
|
|
127
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(body) {
|
|
128
|
+
var _ref5, documentId, objectId, language, doc;
|
|
129
|
+
|
|
130
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
131
|
+
while (1) {
|
|
132
|
+
switch (_context4.prev = _context4.next) {
|
|
133
|
+
case 0:
|
|
134
|
+
_ref5 = _this.state.doc || _this.props, documentId = _ref5.documentId, objectId = _ref5.objectId, language = _ref5.language;
|
|
135
|
+
|
|
136
|
+
if (documentId) {
|
|
137
|
+
_context4.next = 3;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return _context4.abrupt("return", _this.createDocument(body));
|
|
142
|
+
|
|
143
|
+
case 3:
|
|
144
|
+
_context4.next = 5;
|
|
145
|
+
return _this.provider.updateDocument(documentId, JSON.stringify(body), objectId, '', language);
|
|
146
|
+
|
|
147
|
+
case 5:
|
|
148
|
+
doc = _context4.sent;
|
|
149
|
+
|
|
150
|
+
if (!doc) {
|
|
151
|
+
_context4.next = 11;
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
_this.setState({
|
|
156
|
+
doc: doc,
|
|
157
|
+
mode: 'view'
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
return _context4.abrupt("return", doc);
|
|
161
|
+
|
|
162
|
+
case 11:
|
|
163
|
+
_this.setState({
|
|
164
|
+
hasError: true,
|
|
165
|
+
mode: 'view'
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
throw new Error('Failed to update document');
|
|
169
|
+
|
|
170
|
+
case 13:
|
|
171
|
+
case "end":
|
|
172
|
+
return _context4.stop();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}, _callee4);
|
|
176
|
+
}));
|
|
177
|
+
|
|
178
|
+
return function (_x6) {
|
|
179
|
+
return _ref4.apply(this, arguments);
|
|
180
|
+
};
|
|
181
|
+
}());
|
|
182
|
+
|
|
183
|
+
_defineProperty(_assertThisInitialized(_this), "createDocument", /*#__PURE__*/function () {
|
|
184
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(body) {
|
|
185
|
+
var _this$props, objectId, language, doc;
|
|
186
|
+
|
|
187
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
188
|
+
while (1) {
|
|
189
|
+
switch (_context5.prev = _context5.next) {
|
|
190
|
+
case 0:
|
|
191
|
+
_this$props = _this.props, objectId = _this$props.objectId, language = _this$props.language;
|
|
192
|
+
_context5.next = 3;
|
|
193
|
+
return _this.provider.createDocument(JSON.stringify(body), objectId, '', language);
|
|
194
|
+
|
|
195
|
+
case 3:
|
|
196
|
+
doc = _context5.sent;
|
|
197
|
+
|
|
198
|
+
if (!doc) {
|
|
199
|
+
_context5.next = 9;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
_this.setState({
|
|
204
|
+
doc: doc,
|
|
205
|
+
mode: 'view'
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
return _context5.abrupt("return", doc);
|
|
209
|
+
|
|
210
|
+
case 9:
|
|
211
|
+
_this.setState({
|
|
212
|
+
hasError: true,
|
|
213
|
+
mode: 'view'
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
throw new Error('Failed to create document');
|
|
217
|
+
|
|
218
|
+
case 11:
|
|
219
|
+
case "end":
|
|
220
|
+
return _context5.stop();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}, _callee5);
|
|
224
|
+
}));
|
|
225
|
+
|
|
226
|
+
return function (_x7) {
|
|
227
|
+
return _ref6.apply(this, arguments);
|
|
228
|
+
};
|
|
229
|
+
}());
|
|
230
|
+
|
|
231
|
+
_defineProperty(_assertThisInitialized(_this), "setDocumentState", function (doc) {
|
|
232
|
+
if (doc) {
|
|
233
|
+
_this.setState({
|
|
234
|
+
isLoading: false,
|
|
235
|
+
doc: doc
|
|
236
|
+
});
|
|
237
|
+
} else {
|
|
238
|
+
_this.setState({
|
|
239
|
+
isLoading: false,
|
|
240
|
+
mode: 'edit'
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
_this.actions = {
|
|
246
|
+
getDocument: _this.getDocument,
|
|
247
|
+
setDocumentMode: _this.setDocumentMode,
|
|
248
|
+
updateDocument: _this.updateDocument,
|
|
249
|
+
createDocument: _this.createDocument,
|
|
250
|
+
getDocumentByObjectId: _this.getDocumentByObjectId
|
|
251
|
+
};
|
|
252
|
+
_this.provider = getProvider(props);
|
|
253
|
+
_this.state = {
|
|
254
|
+
mode: props.mode || 'view',
|
|
255
|
+
isLoading: true
|
|
256
|
+
};
|
|
257
|
+
return _this;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
_createClass(EmbeddedDocument, [{
|
|
261
|
+
key: "componentDidMount",
|
|
262
|
+
value: function () {
|
|
263
|
+
var _componentDidMount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
|
|
264
|
+
var _this$props2, documentId, language, objectId;
|
|
265
|
+
|
|
266
|
+
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
267
|
+
while (1) {
|
|
268
|
+
switch (_context6.prev = _context6.next) {
|
|
269
|
+
case 0:
|
|
270
|
+
_this$props2 = this.props, documentId = _this$props2.documentId, language = _this$props2.language, objectId = _this$props2.objectId;
|
|
271
|
+
|
|
272
|
+
if (!documentId) {
|
|
273
|
+
_context6.next = 6;
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
_context6.next = 4;
|
|
278
|
+
return this.getDocument(documentId, language);
|
|
279
|
+
|
|
280
|
+
case 4:
|
|
281
|
+
_context6.next = 8;
|
|
282
|
+
break;
|
|
283
|
+
|
|
284
|
+
case 6:
|
|
285
|
+
_context6.next = 8;
|
|
286
|
+
return this.getDocumentByObjectId(objectId, language);
|
|
287
|
+
|
|
288
|
+
case 8:
|
|
289
|
+
case "end":
|
|
290
|
+
return _context6.stop();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}, _callee6, this);
|
|
294
|
+
}));
|
|
295
|
+
|
|
296
|
+
function componentDidMount() {
|
|
297
|
+
return _componentDidMount.apply(this, arguments);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return componentDidMount;
|
|
301
|
+
}()
|
|
302
|
+
}, {
|
|
303
|
+
key: "renderToolbar",
|
|
304
|
+
value:
|
|
305
|
+
/**
|
|
306
|
+
* Toolbar will only be rendered here if we're in "view"-mode.
|
|
307
|
+
*
|
|
308
|
+
* In all other modes, the toolbar rendering will be triggered
|
|
309
|
+
* by the Document-component.
|
|
310
|
+
*/
|
|
311
|
+
function renderToolbar() {
|
|
312
|
+
var mode = this.state.mode;
|
|
313
|
+
var renderToolbar = this.props.renderToolbar;
|
|
314
|
+
|
|
315
|
+
if (mode !== 'view' || !renderToolbar) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return renderToolbar(mode);
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Title will only be rendered here if we're in "view"-mode.
|
|
323
|
+
*
|
|
324
|
+
* In all other modes, the title rendering will be triggered
|
|
325
|
+
* by the Document-component.
|
|
326
|
+
*/
|
|
327
|
+
|
|
328
|
+
}, {
|
|
329
|
+
key: "renderTitle",
|
|
330
|
+
value: function renderTitle() {
|
|
331
|
+
var _this$state = this.state,
|
|
332
|
+
mode = _this$state.mode,
|
|
333
|
+
doc = _this$state.doc;
|
|
334
|
+
var renderTitle = this.props.renderTitle;
|
|
335
|
+
|
|
336
|
+
if (mode !== 'view' || !renderTitle) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return renderTitle(mode, doc);
|
|
341
|
+
}
|
|
342
|
+
}, {
|
|
343
|
+
key: "renderContent",
|
|
344
|
+
value: function renderContent() {
|
|
345
|
+
var mode = this.state.mode;
|
|
346
|
+
|
|
347
|
+
if (mode === 'view') {
|
|
348
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, this.renderToolbar(), /*#__PURE__*/React.createElement(Content, null, this.renderTitle(), this.props.children));
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return this.props.children;
|
|
352
|
+
}
|
|
353
|
+
}, {
|
|
354
|
+
key: "render",
|
|
355
|
+
value: function render() {
|
|
356
|
+
var _this$props3 = this.props,
|
|
357
|
+
renderTitle = _this$props3.renderTitle,
|
|
358
|
+
renderToolbar = _this$props3.renderToolbar;
|
|
359
|
+
return /*#__PURE__*/React.createElement(Context.Provider, {
|
|
360
|
+
value: {
|
|
361
|
+
value: this.state,
|
|
362
|
+
actions: this.actions,
|
|
363
|
+
renderProps: {
|
|
364
|
+
renderTitle: renderTitle,
|
|
365
|
+
renderToolbar: renderToolbar
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}, this.renderContent());
|
|
369
|
+
}
|
|
370
|
+
}]);
|
|
371
|
+
|
|
372
|
+
return EmbeddedDocument;
|
|
373
|
+
}(Component);
|
|
374
|
+
|
|
375
|
+
export { EmbeddedDocument as default };
|