@builttocreate/engine-utils 2.0.1 → 2.2.0

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.
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var types = {
8
+ document: 'document',
9
+ template: 'template',
10
+ version: 'version'
11
+ };
12
+ var _default = types;
13
+ exports["default"] = _default;
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.getDefaultJoyDocPage = exports.getDefaultJoyDocFile = exports.getDefaultJoyDoc = exports.getCleanedJoyDocPages = exports.getCleanedJoyDoc = exports["default"] = void 0;
8
+ exports.getDocumentFromTemplate = exports.getDefaultTemplate = exports.getDefaultJoyDocPage = exports.getDefaultJoyDocFile = exports.getDefaultJoyDoc = exports.getDefaultDocument = exports.getCleanedJoyDocPages = exports.getCleanedJoyDoc = exports.duplicate = exports["default"] = void 0;
9
9
 
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
11
 
@@ -17,6 +17,8 @@ var _PageLayoutModes = _interopRequireDefault(require("./constants/PageLayoutMod
17
17
 
18
18
  var _FieldPresentationModes = _interopRequireDefault(require("./constants/FieldPresentationModes"));
19
19
 
20
+ var _DocumentTypes = _interopRequireDefault(require("./constants/DocumentTypes"));
21
+
20
22
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
21
23
 
22
24
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -199,13 +201,113 @@ var getCleanedJoyDocPages = function getCleanedJoyDocPages(pages) {
199
201
  return [getDefaultJoyDocPage()];
200
202
  }
201
203
  };
204
+ /**
205
+ * Get a properly formatted Document JoyDoc
206
+ *
207
+ * @returns {Object}
208
+ */
209
+
202
210
 
203
211
  exports.getCleanedJoyDocPages = getCleanedJoyDocPages;
212
+
213
+ var getDefaultDocument = function getDefaultDocument() {
214
+ var type = _DocumentTypes["default"].document;
215
+
216
+ var _id = (0, _generateObjectId["default"])();
217
+
218
+ var identifier = "doc_".concat(_id);
219
+ var name = 'New Doc';
220
+ return getDefaultJoyDoc({
221
+ type: type,
222
+ _id: _id,
223
+ identifier: identifier,
224
+ name: name
225
+ });
226
+ };
227
+ /**
228
+ * Get a properly formatted Template JoyDoc
229
+ *
230
+ * @returns {Object}
231
+ */
232
+
233
+
234
+ exports.getDefaultDocument = getDefaultDocument;
235
+
236
+ var getDefaultTemplate = function getDefaultTemplate() {
237
+ var type = _DocumentTypes["default"].template;
238
+
239
+ var _id = (0, _generateObjectId["default"])();
240
+
241
+ var identifier = "template_".concat(_id);
242
+ var name = 'New Template';
243
+ return getDefaultJoyDoc({
244
+ type: type,
245
+ _id: _id,
246
+ identifier: identifier,
247
+ name: name
248
+ });
249
+ };
250
+ /**
251
+ * Get a properly formatted duplicate of a Template or Document
252
+ *
253
+ * @returns {Object}
254
+ */
255
+
256
+
257
+ exports.getDefaultTemplate = getDefaultTemplate;
258
+
259
+ var duplicate = function duplicate(original, defaults) {
260
+ //Remove all references to original template object
261
+ var origin = JSON.parse(JSON.stringify(original));
262
+
263
+ var _id = (0, _generateObjectId["default"])();
264
+
265
+ var identifier = origin.type === _DocumentTypes["default"].template ? "template_".concat(_id) : "doc_".concat(_id);
266
+ return _objectSpread(_objectSpread({}, origin), {}, {
267
+ _id: _id,
268
+ identifier: identifier,
269
+ createdOn: new Date().getTime(),
270
+ source: origin.identifier
271
+ }, defaults);
272
+ };
273
+ /**
274
+ * Get a properly formatted Document JoyDoc from Template JoyDoc
275
+ *
276
+ * @param {Object} template
277
+ * @returns {Object}
278
+ */
279
+
280
+
281
+ exports.duplicate = duplicate;
282
+
283
+ var getDocumentFromTemplate = function getDocumentFromTemplate(template) {
284
+ var _id = (0, _generateObjectId["default"])();
285
+
286
+ var identifier = "doc_".concat(_id); //Remove all references to original template object
287
+
288
+ var temp = JSON.parse(JSON.stringify(template));
289
+ return {
290
+ _id: _id,
291
+ identifier: identifier,
292
+ type: _DocumentTypes["default"].document,
293
+ name: temp.name,
294
+ template: temp.identifier,
295
+ source: temp.identifier,
296
+ files: temp.files,
297
+ fields: temp.fields
298
+ };
299
+ };
300
+
301
+ exports.getDocumentFromTemplate = getDocumentFromTemplate;
204
302
  var _default = {
205
303
  getDefaultJoyDocPage: getDefaultJoyDocPage,
206
304
  getDefaultJoyDocFile: getDefaultJoyDocFile,
207
305
  getDefaultJoyDoc: getDefaultJoyDoc,
208
306
  getCleanedJoyDoc: getCleanedJoyDoc,
209
- getCleanedJoyDocPages: getCleanedJoyDocPages
307
+ getCleanedJoyDocPages: getCleanedJoyDocPages,
308
+ getDefaultDocument: getDefaultDocument,
309
+ getDefaultTemplate: getDefaultTemplate,
310
+ getDocumentFromTemplate: getDocumentFromTemplate,
311
+ duplicate: duplicate
210
312
  };
211
313
  exports["default"] = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builttocreate/engine-utils",
3
- "version": "2.0.1",
3
+ "version": "2.2.0",
4
4
  "description": "Utility library for common logic shared across web and mobile",
5
5
  "main": "dist/index.js",
6
6
  "files": [