ywana-core8 0.0.195 → 0.0.199

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/dist/index.cjs CHANGED
@@ -1025,6 +1025,234 @@ var DropDown = function DropDown(props) {
1025
1025
  }) : null, renderOptions());
1026
1026
  };
1027
1027
 
1028
+ /**
1029
+ * TYPES
1030
+ */
1031
+ var TYPES = {
1032
+ STRING: 'String',
1033
+ NUMBER: 'Number',
1034
+ BOOLEAN: 'Boolean',
1035
+ ARRAY: 'Array',
1036
+ ENTITY: 'Object',
1037
+ FUNCTION: 'Function'
1038
+ };
1039
+ /**
1040
+ * FORMATS
1041
+ */
1042
+
1043
+ var FORMATS = {
1044
+ NONE: '',
1045
+ DATE: 'date',
1046
+ EMAIL: 'email',
1047
+ HTML: 'HTML',
1048
+ URL: 'URL'
1049
+ };
1050
+ /**
1051
+ * CHECK
1052
+ */
1053
+
1054
+ var CHECK = Object.values(TYPES).reduce(function (obj, name) {
1055
+ obj['is' + name] = function (x) {
1056
+ return toString.call(x) == '[object ' + name + ']';
1057
+ };
1058
+
1059
+ return obj;
1060
+ }, {});
1061
+ /**
1062
+ * Content Type
1063
+ */
1064
+
1065
+ var ContentType = /*#__PURE__*/function () {
1066
+ function ContentType(schema) {
1067
+ this._schema = schema;
1068
+ }
1069
+
1070
+ var _proto = ContentType.prototype;
1071
+
1072
+ _proto.checkType = function checkType(_ref, data) {
1073
+ var type = _ref.type,
1074
+ item = _ref.item;
1075
+ var valid = true;
1076
+ var validChildren = true;
1077
+
1078
+ if (item) {
1079
+ var child = new ContentType(item);
1080
+
1081
+ switch (type) {
1082
+ case TYPES.ARRAY:
1083
+ valid = CHECK['is' + type](data);
1084
+ validChildren = data.every(function (element) {
1085
+ return child.validate(element);
1086
+ });
1087
+ break;
1088
+
1089
+ case TYPES.ENTITY:
1090
+ valid = CHECK['is' + type](data);
1091
+ validChildren = child.validate(data);
1092
+ break;
1093
+
1094
+ case TYPES.NUMBER:
1095
+ valid = CHECK['is' + type](data.value);
1096
+ validChildren = true;
1097
+ break;
1098
+
1099
+ default:
1100
+ valid = true;
1101
+ validChildren = true;
1102
+ }
1103
+ }
1104
+
1105
+ return valid && validChildren;
1106
+ }
1107
+ /**
1108
+ * Validate entity data
1109
+ * - Inspect required attributes only
1110
+ * - Check attributes type
1111
+ */
1112
+ ;
1113
+
1114
+ _proto.validate = function validate(data) {
1115
+ var _this = this;
1116
+
1117
+ var attributes = Object.entries(this._schema);
1118
+ return attributes.filter(function (_ref2) {
1119
+ var attr = _ref2[1];
1120
+ return attr.required === true;
1121
+ }).every(function (_ref3) {
1122
+ var name = _ref3[0],
1123
+ attr = _ref3[1];
1124
+ return data[name] !== undefined ? _this.checkType(attr, data[name]) : false;
1125
+ });
1126
+ }
1127
+ /**
1128
+ * Content Type Form
1129
+ */
1130
+ ;
1131
+
1132
+ _proto.form = function form(data) {
1133
+ var entries = Object.entries(this._schema);
1134
+ var form = entries.reduce(function (form, _ref4) {
1135
+ var id = _ref4[0],
1136
+ field = _ref4[1];
1137
+ form[id] = Object.assign({}, field, {
1138
+ value: data[id]
1139
+ });
1140
+ return form;
1141
+ }, {});
1142
+ return form;
1143
+ }
1144
+ /**
1145
+ * Content Type Sections
1146
+ */
1147
+ ;
1148
+
1149
+ _proto.sections = function sections(data) {
1150
+ var form = this.form(data);
1151
+ var fields = Object.values(form);
1152
+ var sections = fields.reduce(function (sections, field) {
1153
+ var section = field.section;
1154
+ var title = section ? section : '';
1155
+ if (!sections.hasOwnProperty(title)) sections[title] = {
1156
+ title: title,
1157
+ fields: []
1158
+ };
1159
+ sections[title].fields.push(field);
1160
+ return sections;
1161
+ }, {});
1162
+ return Object.values(sections);
1163
+ }
1164
+ /**
1165
+ * value
1166
+ */
1167
+ ;
1168
+
1169
+ _proto.value = function value(data) {
1170
+ var fields = Object.entries(this._schema);
1171
+ var next = fields.reduce(function (next, _ref5) {
1172
+ var name = _ref5[0],
1173
+ field = _ref5[1];
1174
+ var type = field.type,
1175
+ item = field.item;
1176
+ var entryData = data ? data[name] : null;
1177
+
1178
+ switch (type) {
1179
+ case TYPES.STRING:
1180
+ next[name] = entryData || field["default"];
1181
+ break;
1182
+
1183
+ case TYPES.NUMBER:
1184
+ next[name] = entryData || field["default"];
1185
+ break;
1186
+
1187
+ case TYPES.BOOLEAN:
1188
+ next[name] = entryData || field["default"];
1189
+ break;
1190
+
1191
+ case TYPES.ENTITY:
1192
+ var child1 = new ContentType(item);
1193
+ next[name] = child1.value(entryData);
1194
+ break;
1195
+
1196
+ case TYPES.ARRAY:
1197
+ if (item === TYPES.STRING) {
1198
+ next[name] = entryData ? entryData : [];
1199
+ } else {
1200
+ var child2 = new ContentType(item);
1201
+ next[name] = entryData ? entryData.map(function (data2) {
1202
+ return child2.value(data2);
1203
+ }) : [];
1204
+ }
1205
+
1206
+ break;
1207
+
1208
+ default:
1209
+ next[name] = field;
1210
+ break;
1211
+ }
1212
+
1213
+ return next;
1214
+ }, {});
1215
+ return next;
1216
+ };
1217
+
1218
+ return ContentType;
1219
+ }();
1220
+ /**
1221
+ * Content
1222
+ */
1223
+
1224
+ var Content = /*#__PURE__*/function () {
1225
+ function Content(type, value) {
1226
+ this.type = type;
1227
+ this._type = new ContentType(type);
1228
+ this._value = value;
1229
+ }
1230
+
1231
+ var _proto2 = Content.prototype;
1232
+
1233
+ _proto2.isValid = function isValid() {
1234
+ return this._type.validate(this._value);
1235
+ };
1236
+
1237
+ _proto2.value = function value() {
1238
+ return this._type.value(this._value);
1239
+ };
1240
+
1241
+ _proto2.form = function form() {
1242
+ return this._type.form(this._value);
1243
+ };
1244
+
1245
+ _proto2.sections = function sections() {
1246
+ return this._type.sections(this._value);
1247
+ };
1248
+
1249
+ _proto2.update = function update(value) {
1250
+ this._value = value;
1251
+ };
1252
+
1253
+ return Content;
1254
+ }();
1255
+
1028
1256
  var isFunction$1 = function isFunction(value) {
1029
1257
  return value && (Object.prototype.toString.call(value) === "[object Function]" || "function" === typeof value || value instanceof Function);
1030
1258
  };
@@ -1188,6 +1416,7 @@ var DataTableCell = function DataTableCell(_ref2) {
1188
1416
  min = column.min,
1189
1417
  max = column.max,
1190
1418
  _onChange = column.onChange,
1419
+ format = column.format,
1191
1420
  options = column.options;
1192
1421
 
1193
1422
  if (id === "checked") {
@@ -1307,6 +1536,7 @@ var DataTableCell = function DataTableCell(_ref2) {
1307
1536
  return /*#__PURE__*/React__default["default"].createElement(StringCellViewer, {
1308
1537
  id: id,
1309
1538
  value: cell,
1539
+ format: format,
1310
1540
  options: options
1311
1541
  });
1312
1542
 
@@ -1341,11 +1571,19 @@ var BooleanCellViewer = function BooleanCellViewer(_ref3) {
1341
1571
 
1342
1572
  var StringCellViewer = function StringCellViewer(_ref4) {
1343
1573
  var value = _ref4.value,
1574
+ format = _ref4.format,
1344
1575
  options = _ref4.options;
1345
1576
  var option = options ? options.find(function (o) {
1346
1577
  return o.value === value;
1347
1578
  }) : null;
1348
1579
  var text = option ? option.label : value;
1580
+
1581
+ switch (format) {
1582
+ case FORMATS.DATE:
1583
+ text = new Date(text).toLocaleString();
1584
+ break;
1585
+ }
1586
+
1349
1587
  return /*#__PURE__*/React__default["default"].createElement("div", {
1350
1588
  className: "field-editor string-viewer"
1351
1589
  }, text);
@@ -2270,234 +2508,6 @@ var Dialog = function Dialog(props) {
2270
2508
  }) : null, /*#__PURE__*/React__default["default"].createElement(Text, null, title)), /*#__PURE__*/React__default["default"].createElement("main", null, children), /*#__PURE__*/React__default["default"].createElement("footer", null, actions))));
2271
2509
  };
2272
2510
 
2273
- /**
2274
- * TYPES
2275
- */
2276
- var TYPES = {
2277
- STRING: 'String',
2278
- NUMBER: 'Number',
2279
- BOOLEAN: 'Boolean',
2280
- ARRAY: 'Array',
2281
- ENTITY: 'Object',
2282
- FUNCTION: 'Function'
2283
- };
2284
- /**
2285
- * FORMATS
2286
- */
2287
-
2288
- var FORMATS = {
2289
- NONE: '',
2290
- DATE: 'date',
2291
- EMAIL: 'email',
2292
- HTML: 'HTML',
2293
- URL: 'URL'
2294
- };
2295
- /**
2296
- * CHECK
2297
- */
2298
-
2299
- var CHECK = Object.values(TYPES).reduce(function (obj, name) {
2300
- obj['is' + name] = function (x) {
2301
- return toString.call(x) == '[object ' + name + ']';
2302
- };
2303
-
2304
- return obj;
2305
- }, {});
2306
- /**
2307
- * Content Type
2308
- */
2309
-
2310
- var ContentType = /*#__PURE__*/function () {
2311
- function ContentType(schema) {
2312
- this._schema = schema;
2313
- }
2314
-
2315
- var _proto = ContentType.prototype;
2316
-
2317
- _proto.checkType = function checkType(_ref, data) {
2318
- var type = _ref.type,
2319
- item = _ref.item;
2320
- var valid = true;
2321
- var validChildren = true;
2322
-
2323
- if (item) {
2324
- var child = new ContentType(item);
2325
-
2326
- switch (type) {
2327
- case TYPES.ARRAY:
2328
- valid = CHECK['is' + type](data);
2329
- validChildren = data.every(function (element) {
2330
- return child.validate(element);
2331
- });
2332
- break;
2333
-
2334
- case TYPES.ENTITY:
2335
- valid = CHECK['is' + type](data);
2336
- validChildren = child.validate(data);
2337
- break;
2338
-
2339
- case TYPES.NUMBER:
2340
- valid = CHECK['is' + type](data.value);
2341
- validChildren = true;
2342
- break;
2343
-
2344
- default:
2345
- valid = true;
2346
- validChildren = true;
2347
- }
2348
- }
2349
-
2350
- return valid && validChildren;
2351
- }
2352
- /**
2353
- * Validate entity data
2354
- * - Inspect required attributes only
2355
- * - Check attributes type
2356
- */
2357
- ;
2358
-
2359
- _proto.validate = function validate(data) {
2360
- var _this = this;
2361
-
2362
- var attributes = Object.entries(this._schema);
2363
- return attributes.filter(function (_ref2) {
2364
- var attr = _ref2[1];
2365
- return attr.required === true;
2366
- }).every(function (_ref3) {
2367
- var name = _ref3[0],
2368
- attr = _ref3[1];
2369
- return data[name] !== undefined ? _this.checkType(attr, data[name]) : false;
2370
- });
2371
- }
2372
- /**
2373
- * Content Type Form
2374
- */
2375
- ;
2376
-
2377
- _proto.form = function form(data) {
2378
- var entries = Object.entries(this._schema);
2379
- var form = entries.reduce(function (form, _ref4) {
2380
- var id = _ref4[0],
2381
- field = _ref4[1];
2382
- form[id] = Object.assign({}, field, {
2383
- value: data[id]
2384
- });
2385
- return form;
2386
- }, {});
2387
- return form;
2388
- }
2389
- /**
2390
- * Content Type Sections
2391
- */
2392
- ;
2393
-
2394
- _proto.sections = function sections(data) {
2395
- var form = this.form(data);
2396
- var fields = Object.values(form);
2397
- var sections = fields.reduce(function (sections, field) {
2398
- var section = field.section;
2399
- var title = section ? section : '';
2400
- if (!sections.hasOwnProperty(title)) sections[title] = {
2401
- title: title,
2402
- fields: []
2403
- };
2404
- sections[title].fields.push(field);
2405
- return sections;
2406
- }, {});
2407
- return Object.values(sections);
2408
- }
2409
- /**
2410
- * value
2411
- */
2412
- ;
2413
-
2414
- _proto.value = function value(data) {
2415
- var fields = Object.entries(this._schema);
2416
- var next = fields.reduce(function (next, _ref5) {
2417
- var name = _ref5[0],
2418
- field = _ref5[1];
2419
- var type = field.type,
2420
- item = field.item;
2421
- var entryData = data ? data[name] : null;
2422
-
2423
- switch (type) {
2424
- case TYPES.STRING:
2425
- next[name] = entryData || field["default"];
2426
- break;
2427
-
2428
- case TYPES.NUMBER:
2429
- next[name] = entryData || field["default"];
2430
- break;
2431
-
2432
- case TYPES.BOOLEAN:
2433
- next[name] = entryData || field["default"];
2434
- break;
2435
-
2436
- case TYPES.ENTITY:
2437
- var child1 = new ContentType(item);
2438
- next[name] = child1.value(entryData);
2439
- break;
2440
-
2441
- case TYPES.ARRAY:
2442
- if (item === TYPES.STRING) {
2443
- next[name] = entryData ? entryData : [];
2444
- } else {
2445
- var child2 = new ContentType(item);
2446
- next[name] = entryData ? entryData.map(function (data2) {
2447
- return child2.value(data2);
2448
- }) : [];
2449
- }
2450
-
2451
- break;
2452
-
2453
- default:
2454
- next[name] = field;
2455
- break;
2456
- }
2457
-
2458
- return next;
2459
- }, {});
2460
- return next;
2461
- };
2462
-
2463
- return ContentType;
2464
- }();
2465
- /**
2466
- * Content
2467
- */
2468
-
2469
- var Content$1 = /*#__PURE__*/function () {
2470
- function Content(type, value) {
2471
- this.type = type;
2472
- this._type = new ContentType(type);
2473
- this._value = value;
2474
- }
2475
-
2476
- var _proto2 = Content.prototype;
2477
-
2478
- _proto2.isValid = function isValid() {
2479
- return this._type.validate(this._value);
2480
- };
2481
-
2482
- _proto2.value = function value() {
2483
- return this._type.value(this._value);
2484
- };
2485
-
2486
- _proto2.form = function form() {
2487
- return this._type.form(this._value);
2488
- };
2489
-
2490
- _proto2.sections = function sections() {
2491
- return this._type.sections(this._value);
2492
- };
2493
-
2494
- _proto2.update = function update(value) {
2495
- this._value = value;
2496
- };
2497
-
2498
- return Content;
2499
- }();
2500
-
2501
2511
  /**
2502
2512
  * Content Form
2503
2513
  */
@@ -2780,7 +2790,7 @@ var TreededContentEditor = function TreededContentEditor(_ref3) {
2780
2790
  setSelected = _useState2[1];
2781
2791
 
2782
2792
  function select(index, field, node) {
2783
- var item = new Content$1(node.item, field);
2793
+ var item = new Content(node.item, field);
2784
2794
  setSelected({
2785
2795
  index: index,
2786
2796
  item: item,
@@ -2930,7 +2940,7 @@ var EntityEditor = function EntityEditor(_ref5) {
2930
2940
  var id = field.id,
2931
2941
  item = field.item,
2932
2942
  label = field.label;
2933
- var content = new Content$1(item, value);
2943
+ var content = new Content(item, value);
2934
2944
 
2935
2945
  function change(fid, value) {
2936
2946
  var _Object$assign4;
@@ -2945,7 +2955,7 @@ var EntityEditor = function EntityEditor(_ref5) {
2945
2955
  });
2946
2956
  return /*#__PURE__*/React__default["default"].createElement("div", {
2947
2957
  className: "entity-editor"
2948
- }, /*#__PURE__*/React__default["default"].createElement("header", null, "\u2202", /*#__PURE__*/React__default["default"].createElement(Text, {
2958
+ }, /*#__PURE__*/React__default["default"].createElement("header", null, /*#__PURE__*/React__default["default"].createElement(Text, {
2949
2959
  use: "caption"
2950
2960
  }, label)), /*#__PURE__*/React__default["default"].createElement("main", null, fields.map(function (field) {
2951
2961
  return /*#__PURE__*/React__default["default"].createElement(FieldEditor, {
@@ -3356,7 +3366,7 @@ var CreateContentDialog$1 = function CreateContentDialog(_ref) {
3356
3366
  var title = /*#__PURE__*/React__default["default"].createElement(Text, {
3357
3367
  use: "headline6"
3358
3368
  }, label);
3359
- var content = new Content$1(type, form);
3369
+ var content = new Content(type, form);
3360
3370
  return /*#__PURE__*/React__default["default"].createElement(Dialog, {
3361
3371
  title: title,
3362
3372
  open: true,
@@ -3445,7 +3455,7 @@ var EditContentDialog = function EditContentDialog(_ref) {
3445
3455
  var title = /*#__PURE__*/React__default["default"].createElement(Text, {
3446
3456
  use: "headline6"
3447
3457
  }, label);
3448
- var content = new Content$1(type, form);
3458
+ var content = new Content(type, form);
3449
3459
  return /*#__PURE__*/React__default["default"].createElement(Dialog, {
3450
3460
  title: title,
3451
3461
  open: true,
@@ -3538,7 +3548,7 @@ var CreateContentDialog = function CreateContentDialog(_ref) {
3538
3548
  var title = /*#__PURE__*/React__default["default"].createElement(Text, {
3539
3549
  use: "headline6"
3540
3550
  }, label);
3541
- var content = new Content$1(type, form);
3551
+ var content = new Content(type, form);
3542
3552
  return /*#__PURE__*/React__default["default"].createElement(Dialog, {
3543
3553
  title: title,
3544
3554
  open: true,
@@ -3871,7 +3881,7 @@ var CollectionEditor = function CollectionEditor(props) {
3871
3881
  }
3872
3882
 
3873
3883
  function renderEditor() {
3874
- var content = new Content$1(schema, form);
3884
+ var content = new Content(schema, form);
3875
3885
 
3876
3886
  switch (layout) {
3877
3887
  case 'TABBED':
@@ -4103,6 +4113,7 @@ var ContentViewer = function ContentViewer(props) {
4103
4113
  };
4104
4114
  /**
4105
4115
  * Field Viewer
4116
+ *
4106
4117
  * @param {} props
4107
4118
  * @returns
4108
4119
  */
@@ -4337,7 +4348,7 @@ var TablePage = function TablePage(props) {
4337
4348
  return /*#__PURE__*/React__default["default"].createElement("aside", {
4338
4349
  className: "table-page"
4339
4350
  }, rowSelected ? /*#__PURE__*/React__default["default"].createElement(TableRowEditor, {
4340
- content: new Content$1(schema, form),
4351
+ content: new Content(schema, form),
4341
4352
  filter: editorFilter,
4342
4353
  onChange: change,
4343
4354
  onClose: closeAside,
@@ -4535,7 +4546,7 @@ var TableFilters = function TableFilters(props) {
4535
4546
  change({});
4536
4547
  }
4537
4548
 
4538
- var content = new Content$1(filterSchema, form);
4549
+ var content = new Content(filterSchema, form);
4539
4550
  return /*#__PURE__*/React__default["default"].createElement(React.Fragment, null, /*#__PURE__*/React__default["default"].createElement(Header, {
4540
4551
  className: "table-filters",
4541
4552
  title: /*#__PURE__*/React__default["default"].createElement(Text, null, "Filters")
@@ -4678,6 +4689,7 @@ var TableEditor = function TableEditor(props) {
4678
4689
  id: field.id,
4679
4690
  label: field.label,
4680
4691
  type: field.type,
4692
+ format: field.format,
4681
4693
  onChange: field.id === "checked" ? checkOne : field.editable ? change : null,
4682
4694
 
4683
4695
  /* checked has it´s own handler */
@@ -5249,7 +5261,7 @@ exports.CircularProgress = CircularProgress;
5249
5261
  exports.CollectionContext = CollectionContext;
5250
5262
  exports.CollectionEditor = CollectionEditor$1;
5251
5263
  exports.CollectionPage = CollectionPage;
5252
- exports.Content = Content$1;
5264
+ exports.Content = Content;
5253
5265
  exports.ContentEditor = ContentEditor;
5254
5266
  exports.ContentForm = ContentForm;
5255
5267
  exports.CreateContentDialog = CreateContentDialog$1;