ywana-core8 0.0.197 → 0.0.198

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.
@@ -1018,6 +1018,234 @@ var DropDown = function DropDown(props) {
1018
1018
  }) : null, renderOptions());
1019
1019
  };
1020
1020
 
1021
+ /**
1022
+ * TYPES
1023
+ */
1024
+ var TYPES = {
1025
+ STRING: 'String',
1026
+ NUMBER: 'Number',
1027
+ BOOLEAN: 'Boolean',
1028
+ ARRAY: 'Array',
1029
+ ENTITY: 'Object',
1030
+ FUNCTION: 'Function'
1031
+ };
1032
+ /**
1033
+ * FORMATS
1034
+ */
1035
+
1036
+ var FORMATS = {
1037
+ NONE: '',
1038
+ DATE: 'date',
1039
+ EMAIL: 'email',
1040
+ HTML: 'HTML',
1041
+ URL: 'URL'
1042
+ };
1043
+ /**
1044
+ * CHECK
1045
+ */
1046
+
1047
+ var CHECK = Object.values(TYPES).reduce(function (obj, name) {
1048
+ obj['is' + name] = function (x) {
1049
+ return toString.call(x) == '[object ' + name + ']';
1050
+ };
1051
+
1052
+ return obj;
1053
+ }, {});
1054
+ /**
1055
+ * Content Type
1056
+ */
1057
+
1058
+ var ContentType = /*#__PURE__*/function () {
1059
+ function ContentType(schema) {
1060
+ this._schema = schema;
1061
+ }
1062
+
1063
+ var _proto = ContentType.prototype;
1064
+
1065
+ _proto.checkType = function checkType(_ref, data) {
1066
+ var type = _ref.type,
1067
+ item = _ref.item;
1068
+ var valid = true;
1069
+ var validChildren = true;
1070
+
1071
+ if (item) {
1072
+ var child = new ContentType(item);
1073
+
1074
+ switch (type) {
1075
+ case TYPES.ARRAY:
1076
+ valid = CHECK['is' + type](data);
1077
+ validChildren = data.every(function (element) {
1078
+ return child.validate(element);
1079
+ });
1080
+ break;
1081
+
1082
+ case TYPES.ENTITY:
1083
+ valid = CHECK['is' + type](data);
1084
+ validChildren = child.validate(data);
1085
+ break;
1086
+
1087
+ case TYPES.NUMBER:
1088
+ valid = CHECK['is' + type](data.value);
1089
+ validChildren = true;
1090
+ break;
1091
+
1092
+ default:
1093
+ valid = true;
1094
+ validChildren = true;
1095
+ }
1096
+ }
1097
+
1098
+ return valid && validChildren;
1099
+ }
1100
+ /**
1101
+ * Validate entity data
1102
+ * - Inspect required attributes only
1103
+ * - Check attributes type
1104
+ */
1105
+ ;
1106
+
1107
+ _proto.validate = function validate(data) {
1108
+ var _this = this;
1109
+
1110
+ var attributes = Object.entries(this._schema);
1111
+ return attributes.filter(function (_ref2) {
1112
+ var attr = _ref2[1];
1113
+ return attr.required === true;
1114
+ }).every(function (_ref3) {
1115
+ var name = _ref3[0],
1116
+ attr = _ref3[1];
1117
+ return data[name] !== undefined ? _this.checkType(attr, data[name]) : false;
1118
+ });
1119
+ }
1120
+ /**
1121
+ * Content Type Form
1122
+ */
1123
+ ;
1124
+
1125
+ _proto.form = function form(data) {
1126
+ var entries = Object.entries(this._schema);
1127
+ var form = entries.reduce(function (form, _ref4) {
1128
+ var id = _ref4[0],
1129
+ field = _ref4[1];
1130
+ form[id] = Object.assign({}, field, {
1131
+ value: data[id]
1132
+ });
1133
+ return form;
1134
+ }, {});
1135
+ return form;
1136
+ }
1137
+ /**
1138
+ * Content Type Sections
1139
+ */
1140
+ ;
1141
+
1142
+ _proto.sections = function sections(data) {
1143
+ var form = this.form(data);
1144
+ var fields = Object.values(form);
1145
+ var sections = fields.reduce(function (sections, field) {
1146
+ var section = field.section;
1147
+ var title = section ? section : '';
1148
+ if (!sections.hasOwnProperty(title)) sections[title] = {
1149
+ title: title,
1150
+ fields: []
1151
+ };
1152
+ sections[title].fields.push(field);
1153
+ return sections;
1154
+ }, {});
1155
+ return Object.values(sections);
1156
+ }
1157
+ /**
1158
+ * value
1159
+ */
1160
+ ;
1161
+
1162
+ _proto.value = function value(data) {
1163
+ var fields = Object.entries(this._schema);
1164
+ var next = fields.reduce(function (next, _ref5) {
1165
+ var name = _ref5[0],
1166
+ field = _ref5[1];
1167
+ var type = field.type,
1168
+ item = field.item;
1169
+ var entryData = data ? data[name] : null;
1170
+
1171
+ switch (type) {
1172
+ case TYPES.STRING:
1173
+ next[name] = entryData || field["default"];
1174
+ break;
1175
+
1176
+ case TYPES.NUMBER:
1177
+ next[name] = entryData || field["default"];
1178
+ break;
1179
+
1180
+ case TYPES.BOOLEAN:
1181
+ next[name] = entryData || field["default"];
1182
+ break;
1183
+
1184
+ case TYPES.ENTITY:
1185
+ var child1 = new ContentType(item);
1186
+ next[name] = child1.value(entryData);
1187
+ break;
1188
+
1189
+ case TYPES.ARRAY:
1190
+ if (item === TYPES.STRING) {
1191
+ next[name] = entryData ? entryData : [];
1192
+ } else {
1193
+ var child2 = new ContentType(item);
1194
+ next[name] = entryData ? entryData.map(function (data2) {
1195
+ return child2.value(data2);
1196
+ }) : [];
1197
+ }
1198
+
1199
+ break;
1200
+
1201
+ default:
1202
+ next[name] = field;
1203
+ break;
1204
+ }
1205
+
1206
+ return next;
1207
+ }, {});
1208
+ return next;
1209
+ };
1210
+
1211
+ return ContentType;
1212
+ }();
1213
+ /**
1214
+ * Content
1215
+ */
1216
+
1217
+ var Content = /*#__PURE__*/function () {
1218
+ function Content(type, value) {
1219
+ this.type = type;
1220
+ this._type = new ContentType(type);
1221
+ this._value = value;
1222
+ }
1223
+
1224
+ var _proto2 = Content.prototype;
1225
+
1226
+ _proto2.isValid = function isValid() {
1227
+ return this._type.validate(this._value);
1228
+ };
1229
+
1230
+ _proto2.value = function value() {
1231
+ return this._type.value(this._value);
1232
+ };
1233
+
1234
+ _proto2.form = function form() {
1235
+ return this._type.form(this._value);
1236
+ };
1237
+
1238
+ _proto2.sections = function sections() {
1239
+ return this._type.sections(this._value);
1240
+ };
1241
+
1242
+ _proto2.update = function update(value) {
1243
+ this._value = value;
1244
+ };
1245
+
1246
+ return Content;
1247
+ }();
1248
+
1021
1249
  var isFunction$1 = function isFunction(value) {
1022
1250
  return value && (Object.prototype.toString.call(value) === "[object Function]" || "function" === typeof value || value instanceof Function);
1023
1251
  };
@@ -1181,6 +1409,7 @@ var DataTableCell = function DataTableCell(_ref2) {
1181
1409
  min = column.min,
1182
1410
  max = column.max,
1183
1411
  _onChange = column.onChange,
1412
+ format = column.format,
1184
1413
  options = column.options;
1185
1414
 
1186
1415
  if (id === "checked") {
@@ -1300,6 +1529,7 @@ var DataTableCell = function DataTableCell(_ref2) {
1300
1529
  return /*#__PURE__*/React.createElement(StringCellViewer, {
1301
1530
  id: id,
1302
1531
  value: cell,
1532
+ format: format,
1303
1533
  options: options
1304
1534
  });
1305
1535
 
@@ -1334,11 +1564,19 @@ var BooleanCellViewer = function BooleanCellViewer(_ref3) {
1334
1564
 
1335
1565
  var StringCellViewer = function StringCellViewer(_ref4) {
1336
1566
  var value = _ref4.value,
1567
+ format = _ref4.format,
1337
1568
  options = _ref4.options;
1338
1569
  var option = options ? options.find(function (o) {
1339
1570
  return o.value === value;
1340
1571
  }) : null;
1341
1572
  var text = option ? option.label : value;
1573
+
1574
+ switch (format) {
1575
+ case FORMATS.DATE:
1576
+ text = new Date(text).toLocaleDateString();
1577
+ break;
1578
+ }
1579
+
1342
1580
  return /*#__PURE__*/React.createElement("div", {
1343
1581
  className: "field-editor string-viewer"
1344
1582
  }, text);
@@ -2263,234 +2501,6 @@ var Dialog = function Dialog(props) {
2263
2501
  }) : null, /*#__PURE__*/React.createElement(Text, null, title)), /*#__PURE__*/React.createElement("main", null, children), /*#__PURE__*/React.createElement("footer", null, actions))));
2264
2502
  };
2265
2503
 
2266
- /**
2267
- * TYPES
2268
- */
2269
- var TYPES = {
2270
- STRING: 'String',
2271
- NUMBER: 'Number',
2272
- BOOLEAN: 'Boolean',
2273
- ARRAY: 'Array',
2274
- ENTITY: 'Object',
2275
- FUNCTION: 'Function'
2276
- };
2277
- /**
2278
- * FORMATS
2279
- */
2280
-
2281
- var FORMATS = {
2282
- NONE: '',
2283
- DATE: 'date',
2284
- EMAIL: 'email',
2285
- HTML: 'HTML',
2286
- URL: 'URL'
2287
- };
2288
- /**
2289
- * CHECK
2290
- */
2291
-
2292
- var CHECK = Object.values(TYPES).reduce(function (obj, name) {
2293
- obj['is' + name] = function (x) {
2294
- return toString.call(x) == '[object ' + name + ']';
2295
- };
2296
-
2297
- return obj;
2298
- }, {});
2299
- /**
2300
- * Content Type
2301
- */
2302
-
2303
- var ContentType = /*#__PURE__*/function () {
2304
- function ContentType(schema) {
2305
- this._schema = schema;
2306
- }
2307
-
2308
- var _proto = ContentType.prototype;
2309
-
2310
- _proto.checkType = function checkType(_ref, data) {
2311
- var type = _ref.type,
2312
- item = _ref.item;
2313
- var valid = true;
2314
- var validChildren = true;
2315
-
2316
- if (item) {
2317
- var child = new ContentType(item);
2318
-
2319
- switch (type) {
2320
- case TYPES.ARRAY:
2321
- valid = CHECK['is' + type](data);
2322
- validChildren = data.every(function (element) {
2323
- return child.validate(element);
2324
- });
2325
- break;
2326
-
2327
- case TYPES.ENTITY:
2328
- valid = CHECK['is' + type](data);
2329
- validChildren = child.validate(data);
2330
- break;
2331
-
2332
- case TYPES.NUMBER:
2333
- valid = CHECK['is' + type](data.value);
2334
- validChildren = true;
2335
- break;
2336
-
2337
- default:
2338
- valid = true;
2339
- validChildren = true;
2340
- }
2341
- }
2342
-
2343
- return valid && validChildren;
2344
- }
2345
- /**
2346
- * Validate entity data
2347
- * - Inspect required attributes only
2348
- * - Check attributes type
2349
- */
2350
- ;
2351
-
2352
- _proto.validate = function validate(data) {
2353
- var _this = this;
2354
-
2355
- var attributes = Object.entries(this._schema);
2356
- return attributes.filter(function (_ref2) {
2357
- var attr = _ref2[1];
2358
- return attr.required === true;
2359
- }).every(function (_ref3) {
2360
- var name = _ref3[0],
2361
- attr = _ref3[1];
2362
- return data[name] !== undefined ? _this.checkType(attr, data[name]) : false;
2363
- });
2364
- }
2365
- /**
2366
- * Content Type Form
2367
- */
2368
- ;
2369
-
2370
- _proto.form = function form(data) {
2371
- var entries = Object.entries(this._schema);
2372
- var form = entries.reduce(function (form, _ref4) {
2373
- var id = _ref4[0],
2374
- field = _ref4[1];
2375
- form[id] = Object.assign({}, field, {
2376
- value: data[id]
2377
- });
2378
- return form;
2379
- }, {});
2380
- return form;
2381
- }
2382
- /**
2383
- * Content Type Sections
2384
- */
2385
- ;
2386
-
2387
- _proto.sections = function sections(data) {
2388
- var form = this.form(data);
2389
- var fields = Object.values(form);
2390
- var sections = fields.reduce(function (sections, field) {
2391
- var section = field.section;
2392
- var title = section ? section : '';
2393
- if (!sections.hasOwnProperty(title)) sections[title] = {
2394
- title: title,
2395
- fields: []
2396
- };
2397
- sections[title].fields.push(field);
2398
- return sections;
2399
- }, {});
2400
- return Object.values(sections);
2401
- }
2402
- /**
2403
- * value
2404
- */
2405
- ;
2406
-
2407
- _proto.value = function value(data) {
2408
- var fields = Object.entries(this._schema);
2409
- var next = fields.reduce(function (next, _ref5) {
2410
- var name = _ref5[0],
2411
- field = _ref5[1];
2412
- var type = field.type,
2413
- item = field.item;
2414
- var entryData = data ? data[name] : null;
2415
-
2416
- switch (type) {
2417
- case TYPES.STRING:
2418
- next[name] = entryData || field["default"];
2419
- break;
2420
-
2421
- case TYPES.NUMBER:
2422
- next[name] = entryData || field["default"];
2423
- break;
2424
-
2425
- case TYPES.BOOLEAN:
2426
- next[name] = entryData || field["default"];
2427
- break;
2428
-
2429
- case TYPES.ENTITY:
2430
- var child1 = new ContentType(item);
2431
- next[name] = child1.value(entryData);
2432
- break;
2433
-
2434
- case TYPES.ARRAY:
2435
- if (item === TYPES.STRING) {
2436
- next[name] = entryData ? entryData : [];
2437
- } else {
2438
- var child2 = new ContentType(item);
2439
- next[name] = entryData ? entryData.map(function (data2) {
2440
- return child2.value(data2);
2441
- }) : [];
2442
- }
2443
-
2444
- break;
2445
-
2446
- default:
2447
- next[name] = field;
2448
- break;
2449
- }
2450
-
2451
- return next;
2452
- }, {});
2453
- return next;
2454
- };
2455
-
2456
- return ContentType;
2457
- }();
2458
- /**
2459
- * Content
2460
- */
2461
-
2462
- var Content = /*#__PURE__*/function () {
2463
- function Content(type, value) {
2464
- this.type = type;
2465
- this._type = new ContentType(type);
2466
- this._value = value;
2467
- }
2468
-
2469
- var _proto2 = Content.prototype;
2470
-
2471
- _proto2.isValid = function isValid() {
2472
- return this._type.validate(this._value);
2473
- };
2474
-
2475
- _proto2.value = function value() {
2476
- return this._type.value(this._value);
2477
- };
2478
-
2479
- _proto2.form = function form() {
2480
- return this._type.form(this._value);
2481
- };
2482
-
2483
- _proto2.sections = function sections() {
2484
- return this._type.sections(this._value);
2485
- };
2486
-
2487
- _proto2.update = function update(value) {
2488
- this._value = value;
2489
- };
2490
-
2491
- return Content;
2492
- }();
2493
-
2494
2504
  /**
2495
2505
  * Content Form
2496
2506
  */
@@ -2938,7 +2948,7 @@ var EntityEditor = function EntityEditor(_ref5) {
2938
2948
  });
2939
2949
  return /*#__PURE__*/React.createElement("div", {
2940
2950
  className: "entity-editor"
2941
- }, /*#__PURE__*/React.createElement("header", null, "\u2202", /*#__PURE__*/React.createElement(Text, {
2951
+ }, /*#__PURE__*/React.createElement("header", null, /*#__PURE__*/React.createElement(Text, {
2942
2952
  use: "caption"
2943
2953
  }, label)), /*#__PURE__*/React.createElement("main", null, fields.map(function (field) {
2944
2954
  return /*#__PURE__*/React.createElement(FieldEditor, {
@@ -4672,6 +4682,7 @@ var TableEditor = function TableEditor(props) {
4672
4682
  id: field.id,
4673
4683
  label: field.label,
4674
4684
  type: field.type,
4685
+ format: field.format,
4675
4686
  onChange: field.id === "checked" ? checkOne : field.editable ? change : null,
4676
4687
 
4677
4688
  /* checked has it´s own handler */