ywana-core8 0.0.16 → 0.0.20
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 +705 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +29 -0
- package/dist/index.css.map +1 -1
- package/dist/index.modern.js +704 -44
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +705 -44
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/publish.sh +1 -0
- package/src/domain/CollectionPage.js +2 -2
- package/src/domain/CreateContentDialog.js +26 -30
- package/src/domain/CreateContentDialog_old.js +59 -0
- package/src/domain/TablePage.js +9 -5
- package/src/domain/index.js +1 -0
- package/src/css/fonts.css +0 -162
- package/src/fonts/Assistant-Bold.ttf +0 -0
- package/src/fonts/Assistant-ExtraBold.ttf +0 -0
- package/src/fonts/Assistant-ExtraLight.ttf +0 -0
- package/src/fonts/Assistant-Light.ttf +0 -0
- package/src/fonts/Assistant-Medium.ttf +0 -0
- package/src/fonts/Assistant-Regular.ttf +0 -0
- package/src/fonts/Assistant-SemiBold.ttf +0 -0
- package/src/fonts/Assistant-VariableFont_wght.ttf +0 -0
package/dist/index.modern.js
CHANGED
@@ -3,7 +3,7 @@ import React, { useContext, useState, useEffect, Fragment, useRef, Children, use
|
|
3
3
|
import equal from 'deep-equal';
|
4
4
|
import ResumableJS from 'resumablejs';
|
5
5
|
|
6
|
-
function _catch$
|
6
|
+
function _catch$2(body, recover) {
|
7
7
|
try {
|
8
8
|
var result = body();
|
9
9
|
} catch (e) {
|
@@ -34,7 +34,7 @@ var fetchAsync = function fetchAsync(method, URL, body, token) {
|
|
34
34
|
},
|
35
35
|
body: body
|
36
36
|
};
|
37
|
-
return Promise.resolve(_catch$
|
37
|
+
return Promise.resolve(_catch$2(function () {
|
38
38
|
return Promise.resolve(fetch(URL, request)).then(function (response) {
|
39
39
|
var _exit;
|
40
40
|
|
@@ -3128,16 +3128,16 @@ var CollectionAdder = function CollectionAdder(_ref11) {
|
|
3128
3128
|
* Create Content Dialog
|
3129
3129
|
*/
|
3130
3130
|
|
3131
|
-
var CreateContentDialog = function CreateContentDialog(_ref) {
|
3131
|
+
var CreateContentDialog$1 = function CreateContentDialog(_ref) {
|
3132
3132
|
var label = _ref.label,
|
3133
3133
|
type = _ref.type,
|
3134
|
+
_ref$value = _ref.value,
|
3135
|
+
value = _ref$value === void 0 ? {} : _ref$value,
|
3134
3136
|
validator = _ref.validator,
|
3135
|
-
onOK = _ref.onOK
|
3136
|
-
_ref$onActionClose = _ref.onActionClose,
|
3137
|
-
onActionClose = _ref$onActionClose === void 0 ? true : _ref$onActionClose;
|
3137
|
+
onOK = _ref.onOK;
|
3138
3138
|
var site = useContext(SiteContext);
|
3139
3139
|
|
3140
|
-
var _useState = useState(
|
3140
|
+
var _useState = useState(value),
|
3141
3141
|
form = _useState[0],
|
3142
3142
|
setForm = _useState[1];
|
3143
3143
|
|
@@ -3149,7 +3149,7 @@ var CreateContentDialog = function CreateContentDialog(_ref) {
|
|
3149
3149
|
errors = _useState3[0],
|
3150
3150
|
setErrors = _useState3[1];
|
3151
3151
|
|
3152
|
-
function change(form
|
3152
|
+
function change(form) {
|
3153
3153
|
setForm(form);
|
3154
3154
|
|
3155
3155
|
if (validator) {
|
@@ -3158,28 +3158,20 @@ var CreateContentDialog = function CreateContentDialog(_ref) {
|
|
3158
3158
|
_validator$errors = _validator.errors,
|
3159
3159
|
_errors = _validator$errors === void 0 ? [] : _validator$errors;
|
3160
3160
|
|
3161
|
-
setValid(
|
3161
|
+
setValid(validation);
|
3162
3162
|
setErrors(_errors);
|
3163
3163
|
} else {
|
3164
|
-
setValid(
|
3164
|
+
setValid(true);
|
3165
3165
|
}
|
3166
3166
|
}
|
3167
3167
|
|
3168
3168
|
function onAction(action) {
|
3169
|
-
if (action === 'OK' && onOK) onOK(form);
|
3170
|
-
|
3171
|
-
}
|
3172
|
-
|
3173
|
-
function isRequired(field) {
|
3174
|
-
var _field$required = field.required,
|
3175
|
-
required = _field$required === void 0 ? false : _field$required;
|
3176
|
-
return required;
|
3169
|
+
if (action === 'OK' && onOK) onOK(Object.assign({}, value, form));
|
3170
|
+
site.closeDialog();
|
3177
3171
|
}
|
3178
3172
|
|
3179
|
-
function
|
3180
|
-
|
3181
|
-
creation = _field$creation === void 0 ? false : _field$creation;
|
3182
|
-
return creation;
|
3173
|
+
function createFilter(field, content) {
|
3174
|
+
return field.required === true || field.optional === true; // TODO: execute props.filter
|
3183
3175
|
}
|
3184
3176
|
|
3185
3177
|
var actions = /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Button, {
|
@@ -3187,6 +3179,8 @@ var CreateContentDialog = function CreateContentDialog(_ref) {
|
|
3187
3179
|
action: function action() {
|
3188
3180
|
return onAction("CLOSE");
|
3189
3181
|
}
|
3182
|
+
}), /*#__PURE__*/React.createElement("div", {
|
3183
|
+
className: "expand"
|
3190
3184
|
}), /*#__PURE__*/React.createElement(Button, {
|
3191
3185
|
label: "OK",
|
3192
3186
|
action: function action() {
|
@@ -3204,12 +3198,10 @@ var CreateContentDialog = function CreateContentDialog(_ref) {
|
|
3204
3198
|
open: true,
|
3205
3199
|
onAction: onAction,
|
3206
3200
|
actions: actions
|
3207
|
-
}, /*#__PURE__*/React.createElement(
|
3201
|
+
}, /*#__PURE__*/React.createElement(ContentEditor, {
|
3208
3202
|
content: content,
|
3209
|
-
|
3210
|
-
|
3211
|
-
},
|
3212
|
-
onChange: change
|
3203
|
+
onChange: change,
|
3204
|
+
filter: createFilter
|
3213
3205
|
}), errors.map(function (error) {
|
3214
3206
|
return /*#__PURE__*/React.createElement(Text, {
|
3215
3207
|
use: "overline",
|
@@ -3303,7 +3295,102 @@ var EditContentDialog = function EditContentDialog(_ref) {
|
|
3303
3295
|
}));
|
3304
3296
|
};
|
3305
3297
|
|
3306
|
-
|
3298
|
+
/**
|
3299
|
+
* Create Content Dialog
|
3300
|
+
*/
|
3301
|
+
|
3302
|
+
var CreateContentDialog = function CreateContentDialog(_ref) {
|
3303
|
+
var label = _ref.label,
|
3304
|
+
type = _ref.type,
|
3305
|
+
validator = _ref.validator,
|
3306
|
+
onOK = _ref.onOK,
|
3307
|
+
_ref$onActionClose = _ref.onActionClose,
|
3308
|
+
onActionClose = _ref$onActionClose === void 0 ? true : _ref$onActionClose;
|
3309
|
+
var site = useContext(SiteContext);
|
3310
|
+
|
3311
|
+
var _useState = useState({}),
|
3312
|
+
form = _useState[0],
|
3313
|
+
setForm = _useState[1];
|
3314
|
+
|
3315
|
+
var _useState2 = useState(false),
|
3316
|
+
isValid = _useState2[0],
|
3317
|
+
setValid = _useState2[1];
|
3318
|
+
|
3319
|
+
var _useState3 = useState([]),
|
3320
|
+
errors = _useState3[0],
|
3321
|
+
setErrors = _useState3[1];
|
3322
|
+
|
3323
|
+
function change(form, validForm) {
|
3324
|
+
setForm(form);
|
3325
|
+
|
3326
|
+
if (validator) {
|
3327
|
+
var _validator = validator(form),
|
3328
|
+
validation = _validator.validation,
|
3329
|
+
_validator$errors = _validator.errors,
|
3330
|
+
_errors = _validator$errors === void 0 ? [] : _validator$errors;
|
3331
|
+
|
3332
|
+
setValid(validForm && validation);
|
3333
|
+
setErrors(_errors);
|
3334
|
+
} else {
|
3335
|
+
setValid(validForm);
|
3336
|
+
}
|
3337
|
+
}
|
3338
|
+
|
3339
|
+
function onAction(action) {
|
3340
|
+
if (action === 'OK' && onOK) onOK(form);
|
3341
|
+
if (action === 'CLOSE' || onActionClose === true) site.closeDialog();
|
3342
|
+
}
|
3343
|
+
|
3344
|
+
function isRequired(field) {
|
3345
|
+
var _field$required = field.required,
|
3346
|
+
required = _field$required === void 0 ? false : _field$required;
|
3347
|
+
return required;
|
3348
|
+
}
|
3349
|
+
|
3350
|
+
function isOptional(field) {
|
3351
|
+
var _field$creation = field.creation,
|
3352
|
+
creation = _field$creation === void 0 ? false : _field$creation;
|
3353
|
+
return creation;
|
3354
|
+
}
|
3355
|
+
|
3356
|
+
var actions = /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Button, {
|
3357
|
+
label: "CLOSE",
|
3358
|
+
action: function action() {
|
3359
|
+
return onAction("CLOSE");
|
3360
|
+
}
|
3361
|
+
}), /*#__PURE__*/React.createElement(Button, {
|
3362
|
+
label: "OK",
|
3363
|
+
action: function action() {
|
3364
|
+
return onAction("OK");
|
3365
|
+
},
|
3366
|
+
disabled: !isValid,
|
3367
|
+
raised: true
|
3368
|
+
}));
|
3369
|
+
var title = /*#__PURE__*/React.createElement(Text, {
|
3370
|
+
use: "headline6"
|
3371
|
+
}, label);
|
3372
|
+
var content = new Content(type, form);
|
3373
|
+
return /*#__PURE__*/React.createElement(Dialog, {
|
3374
|
+
title: title,
|
3375
|
+
open: true,
|
3376
|
+
onAction: onAction,
|
3377
|
+
actions: actions
|
3378
|
+
}, /*#__PURE__*/React.createElement(ContentForm, {
|
3379
|
+
content: content,
|
3380
|
+
filter: function filter(field) {
|
3381
|
+
return isRequired(field) || isOptional(field);
|
3382
|
+
},
|
3383
|
+
onChange: change
|
3384
|
+
}), errors.map(function (error) {
|
3385
|
+
return /*#__PURE__*/React.createElement(Text, {
|
3386
|
+
use: "overline",
|
3387
|
+
tag: "div",
|
3388
|
+
className: "error"
|
3389
|
+
}, error);
|
3390
|
+
}));
|
3391
|
+
};
|
3392
|
+
|
3393
|
+
function _catch$1(body, recover) {
|
3307
3394
|
try {
|
3308
3395
|
var result = body();
|
3309
3396
|
} catch (e) {
|
@@ -3317,7 +3404,7 @@ function _catch(body, recover) {
|
|
3317
3404
|
return result;
|
3318
3405
|
}
|
3319
3406
|
|
3320
|
-
var http = HTTPClient(window.API || process.env.REACT_APP_API, Session);
|
3407
|
+
var http$1 = HTTPClient(window.API || process.env.REACT_APP_API, Session);
|
3321
3408
|
/**
|
3322
3409
|
* Collection Page
|
3323
3410
|
*/
|
@@ -3378,8 +3465,8 @@ var CollectionPage = function CollectionPage(props) {
|
|
3378
3465
|
}
|
3379
3466
|
};
|
3380
3467
|
|
3381
|
-
site.openDialog( /*#__PURE__*/React.createElement(
|
3382
|
-
label: "
|
3468
|
+
site.openDialog( /*#__PURE__*/React.createElement(CreateContentDialog, {
|
3469
|
+
label: "" + name,
|
3383
3470
|
type: schema,
|
3384
3471
|
onOK: onOK
|
3385
3472
|
}));
|
@@ -3672,7 +3759,7 @@ var CollectionContext = function CollectionContext(url, field) {
|
|
3672
3759
|
try {
|
3673
3760
|
var _this2 = this;
|
3674
3761
|
|
3675
|
-
var _temp2 = _catch(function () {
|
3762
|
+
var _temp2 = _catch$1(function () {
|
3676
3763
|
return Promise.resolve(API.all()).then(function (data) {
|
3677
3764
|
_this2.all = field ? data[field] : data;
|
3678
3765
|
});
|
@@ -3698,7 +3785,7 @@ var CollectionContext = function CollectionContext(url, field) {
|
|
3698
3785
|
try {
|
3699
3786
|
var _this4 = this;
|
3700
3787
|
|
3701
|
-
var _temp4 = _catch(function () {
|
3788
|
+
var _temp4 = _catch$1(function () {
|
3702
3789
|
return Promise.resolve(API.create(form)).then(function () {
|
3703
3790
|
return Promise.resolve(_this4.load()).then(function () {});
|
3704
3791
|
});
|
@@ -3715,7 +3802,7 @@ var CollectionContext = function CollectionContext(url, field) {
|
|
3715
3802
|
try {
|
3716
3803
|
var _this6 = this;
|
3717
3804
|
|
3718
|
-
var _temp6 = _catch(function () {
|
3805
|
+
var _temp6 = _catch$1(function () {
|
3719
3806
|
return Promise.resolve(API.update(form)).then(function () {
|
3720
3807
|
return Promise.resolve(_this6.load()).then(function () {});
|
3721
3808
|
});
|
@@ -3732,7 +3819,7 @@ var CollectionContext = function CollectionContext(url, field) {
|
|
3732
3819
|
try {
|
3733
3820
|
var _this8 = this;
|
3734
3821
|
|
3735
|
-
var _temp8 = _catch(function () {
|
3822
|
+
var _temp8 = _catch$1(function () {
|
3736
3823
|
return Promise.resolve(API.patch(id, form)).then(function () {
|
3737
3824
|
return Promise.resolve(_this8.load()).then(function () {});
|
3738
3825
|
});
|
@@ -3749,7 +3836,7 @@ var CollectionContext = function CollectionContext(url, field) {
|
|
3749
3836
|
try {
|
3750
3837
|
var _this10 = this;
|
3751
3838
|
|
3752
|
-
var _temp10 = _catch(function () {
|
3839
|
+
var _temp10 = _catch$1(function () {
|
3753
3840
|
return Promise.resolve(API.updateProperty(id, propertyName, form)).then(function () {
|
3754
3841
|
return Promise.resolve(_this10.load()).then(function () {});
|
3755
3842
|
});
|
@@ -3766,7 +3853,7 @@ var CollectionContext = function CollectionContext(url, field) {
|
|
3766
3853
|
try {
|
3767
3854
|
var _this12 = this;
|
3768
3855
|
|
3769
|
-
var _temp12 = _catch(function () {
|
3856
|
+
var _temp12 = _catch$1(function () {
|
3770
3857
|
return Promise.resolve(API.remove(id)).then(function () {
|
3771
3858
|
return Promise.resolve(_this12.load()).then(function () {});
|
3772
3859
|
});
|
@@ -3788,26 +3875,599 @@ var CollectionContext = function CollectionContext(url, field) {
|
|
3788
3875
|
var CollectionAPI = function CollectionAPI(url) {
|
3789
3876
|
return {
|
3790
3877
|
all: function all() {
|
3791
|
-
return http.GET(url);
|
3878
|
+
return http$1.GET(url);
|
3792
3879
|
},
|
3793
3880
|
find: function find(id) {
|
3794
|
-
return http.GET(url + "/" + id);
|
3881
|
+
return http$1.GET(url + "/" + id);
|
3795
3882
|
},
|
3796
3883
|
create: function create(form) {
|
3797
3884
|
var body = JSON.stringify(form);
|
3798
|
-
return http.POST(url, body);
|
3885
|
+
return http$1.POST(url, body);
|
3799
3886
|
},
|
3800
3887
|
update: function update(form) {
|
3801
3888
|
var body = JSON.stringify(form);
|
3802
|
-
return http.PUT(url + "/" + form.id, body);
|
3889
|
+
return http$1.PUT(url + "/" + form.id, body);
|
3803
3890
|
},
|
3804
3891
|
patch: function patch(id, form) {
|
3805
3892
|
var body = JSON.stringify(form);
|
3806
|
-
return http.PATCH(url + "/" + id, body);
|
3893
|
+
return http$1.PATCH(url + "/" + id, body);
|
3807
3894
|
},
|
3808
3895
|
updateProperty: function updateProperty(id, propertyName, form) {
|
3809
3896
|
var body = JSON.stringify(form);
|
3810
|
-
return http.PUT(url + "/" + id + "/" + propertyName, body);
|
3897
|
+
return http$1.PUT(url + "/" + id + "/" + propertyName, body);
|
3898
|
+
},
|
3899
|
+
remove: function remove(id) {
|
3900
|
+
return http$1.DELETE(url + "/" + id);
|
3901
|
+
}
|
3902
|
+
};
|
3903
|
+
};
|
3904
|
+
|
3905
|
+
function _catch(body, recover) {
|
3906
|
+
try {
|
3907
|
+
var result = body();
|
3908
|
+
} catch (e) {
|
3909
|
+
return recover(e);
|
3910
|
+
}
|
3911
|
+
|
3912
|
+
if (result && result.then) {
|
3913
|
+
return result.then(void 0, recover);
|
3914
|
+
}
|
3915
|
+
|
3916
|
+
return result;
|
3917
|
+
}
|
3918
|
+
|
3919
|
+
var http = HTTPClient(window.API || process.env.REACT_APP_API, Session);
|
3920
|
+
/**
|
3921
|
+
* Table Page
|
3922
|
+
*/
|
3923
|
+
|
3924
|
+
var TablePage = function TablePage(props) {
|
3925
|
+
var playScenario = function playScenario() {
|
3926
|
+
try {
|
3927
|
+
var promises1 = pageContext.all.map(function (item) {
|
3928
|
+
try {
|
3929
|
+
return Promise.resolve(pageContext.remove(item.id));
|
3930
|
+
} catch (e) {
|
3931
|
+
return Promise.reject(e);
|
3932
|
+
}
|
3933
|
+
});
|
3934
|
+
Promise.all(promises1).then(function () {
|
3935
|
+
try {
|
3936
|
+
var promises2 = scenario.map(function (item) {
|
3937
|
+
try {
|
3938
|
+
return Promise.resolve(pageContext.create(item));
|
3939
|
+
} catch (e) {
|
3940
|
+
return Promise.reject(e);
|
3941
|
+
}
|
3942
|
+
});
|
3943
|
+
Promise.all(promises2).then(function () {
|
3944
|
+
try {
|
3945
|
+
return Promise.resolve(pageContext.load()).then(function () {
|
3946
|
+
setPageContext(Object.assign({}, pageContext));
|
3947
|
+
});
|
3948
|
+
} catch (e) {
|
3949
|
+
return Promise.reject(e);
|
3950
|
+
}
|
3951
|
+
});
|
3952
|
+
return Promise.resolve();
|
3953
|
+
} catch (e) {
|
3954
|
+
return Promise.reject(e);
|
3955
|
+
}
|
3956
|
+
});
|
3957
|
+
return Promise.resolve();
|
3958
|
+
} catch (e) {
|
3959
|
+
return Promise.reject(e);
|
3960
|
+
}
|
3961
|
+
};
|
3962
|
+
|
3963
|
+
var save = function save() {
|
3964
|
+
try {
|
3965
|
+
console.log('saving.....');
|
3966
|
+
return Promise.resolve(pageContext.update(form)).then(function () {
|
3967
|
+
setPageContext(Object.assign({}, pageContext));
|
3968
|
+
});
|
3969
|
+
} catch (e) {
|
3970
|
+
return Promise.reject(e);
|
3971
|
+
}
|
3972
|
+
};
|
3973
|
+
|
3974
|
+
var site = useContext(SiteContext);
|
3975
|
+
var _props$id = props.id,
|
3976
|
+
id = _props$id === void 0 ? "table" : _props$id,
|
3977
|
+
icon = props.icon,
|
3978
|
+
title = props.title,
|
3979
|
+
_props$name = props.name,
|
3980
|
+
name = _props$name === void 0 ? "table 1" : _props$name,
|
3981
|
+
schema = props.schema,
|
3982
|
+
url = props.url,
|
3983
|
+
field = props.field,
|
3984
|
+
_props$delay = props.delay,
|
3985
|
+
delay = _props$delay === void 0 ? 1000 : _props$delay,
|
3986
|
+
actions = props.actions,
|
3987
|
+
editable = props.editable,
|
3988
|
+
_props$canAdd = props.canAdd,
|
3989
|
+
canAdd = _props$canAdd === void 0 ? true : _props$canAdd,
|
3990
|
+
_props$dev = props.dev,
|
3991
|
+
dev = _props$dev === void 0 ? false : _props$dev,
|
3992
|
+
_props$autosave = props.autosave,
|
3993
|
+
autosave = _props$autosave === void 0 ? true : _props$autosave,
|
3994
|
+
groupBy = props.groupBy,
|
3995
|
+
validator = props.validator,
|
3996
|
+
scenario = props.scenario;
|
3997
|
+
|
3998
|
+
var _useContext = useContext(PageContext),
|
3999
|
+
pageContext = _useContext[0],
|
4000
|
+
setPageContext = _useContext[1];
|
4001
|
+
|
4002
|
+
var selected = pageContext.selected;
|
4003
|
+
var timer = useRef(null);
|
4004
|
+
|
4005
|
+
var _useState = useState(selected),
|
4006
|
+
form = _useState[0],
|
4007
|
+
setForm = _useState[1];
|
4008
|
+
|
4009
|
+
useEffect(function () {
|
4010
|
+
setForm(selected);
|
4011
|
+
}, [selected]);
|
4012
|
+
useEffect(function () {
|
4013
|
+
if (autosave) {
|
4014
|
+
clearTimeout(timer.current);
|
4015
|
+
timer.current = setTimeout(function () {
|
4016
|
+
if (canSave()) save();
|
4017
|
+
}, delay);
|
4018
|
+
}
|
4019
|
+
}, [form]);
|
4020
|
+
useEffect(function () {
|
4021
|
+
try {
|
4022
|
+
var context = TableContext(url, field);
|
4023
|
+
return Promise.resolve(context.load()).then(function () {
|
4024
|
+
setPageContext(context);
|
4025
|
+
});
|
4026
|
+
} catch (e) {
|
4027
|
+
return Promise.reject(e);
|
4028
|
+
}
|
4029
|
+
}, []);
|
4030
|
+
|
4031
|
+
function add() {
|
4032
|
+
var onOK = function onOK(form) {
|
4033
|
+
try {
|
4034
|
+
return Promise.resolve(pageContext.create(form)).then(function () {
|
4035
|
+
setPageContext(Object.assign({}, pageContext));
|
4036
|
+
});
|
4037
|
+
} catch (e) {
|
4038
|
+
return Promise.reject(e);
|
4039
|
+
}
|
4040
|
+
};
|
4041
|
+
|
4042
|
+
site.openDialog( /*#__PURE__*/React.createElement(EditContentDialog, {
|
4043
|
+
label: "Crear " + name,
|
4044
|
+
type: schema,
|
4045
|
+
onOK: onOK,
|
4046
|
+
validator: validator
|
4047
|
+
}));
|
4048
|
+
}
|
4049
|
+
|
4050
|
+
function change(next) {
|
4051
|
+
setForm(next);
|
4052
|
+
}
|
4053
|
+
|
4054
|
+
function canSave() {
|
4055
|
+
var can = !equal(form, selected);
|
4056
|
+
return can;
|
4057
|
+
}
|
4058
|
+
|
4059
|
+
function closeAside() {
|
4060
|
+
pageContext.select(null);
|
4061
|
+
setPageContext(Object.assign({}, pageContext));
|
4062
|
+
}
|
4063
|
+
|
4064
|
+
function renderAside() {
|
4065
|
+
if (selected && form) {
|
4066
|
+
var content = new Content(schema, form);
|
4067
|
+
return /*#__PURE__*/React.createElement("aside", {
|
4068
|
+
className: "table-page"
|
4069
|
+
}, /*#__PURE__*/React.createElement(Header, {
|
4070
|
+
icon: "local_offer",
|
4071
|
+
title: selected.name || "Propiedades"
|
4072
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
4073
|
+
icon: "close",
|
4074
|
+
clickable: true,
|
4075
|
+
action: closeAside
|
4076
|
+
})), /*#__PURE__*/React.createElement(ContentEditor, {
|
4077
|
+
content: content,
|
4078
|
+
onChange: change
|
4079
|
+
}));
|
4080
|
+
}
|
4081
|
+
|
4082
|
+
return null;
|
4083
|
+
}
|
4084
|
+
|
4085
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Header, {
|
4086
|
+
className: "table-page",
|
4087
|
+
title: /*#__PURE__*/React.createElement(Text, null, title)
|
4088
|
+
}, canAdd ? /*#__PURE__*/React.createElement(Button, {
|
4089
|
+
icon: "add",
|
4090
|
+
label: "A\xF1adir",
|
4091
|
+
action: add,
|
4092
|
+
raised: true
|
4093
|
+
}) : null, dev ? /*#__PURE__*/React.createElement(MenuIcon, {
|
4094
|
+
align: "alignRight"
|
4095
|
+
}, /*#__PURE__*/React.createElement(MenuItem, {
|
4096
|
+
label: "Cargar Escenario 1",
|
4097
|
+
onSelect: playScenario
|
4098
|
+
})) : null, actions), /*#__PURE__*/React.createElement("menu", {
|
4099
|
+
className: "table-page"
|
4100
|
+
}, /*#__PURE__*/React.createElement(TableFilters, {
|
4101
|
+
schema: schema
|
4102
|
+
})), /*#__PURE__*/React.createElement("main", {
|
4103
|
+
key: id,
|
4104
|
+
className: "table-page"
|
4105
|
+
}, /*#__PURE__*/React.createElement(TableEditor, {
|
4106
|
+
icon: icon,
|
4107
|
+
title: name,
|
4108
|
+
schema: schema,
|
4109
|
+
delay: delay,
|
4110
|
+
editable: editable,
|
4111
|
+
groupBy: groupBy
|
4112
|
+
})), renderAside());
|
4113
|
+
};
|
4114
|
+
/**
|
4115
|
+
* Table Filters
|
4116
|
+
*/
|
4117
|
+
|
4118
|
+
var TableFilters = function TableFilters(props) {
|
4119
|
+
var change = function change(next) {
|
4120
|
+
try {
|
4121
|
+
setForm(next);
|
4122
|
+
return Promise.resolve(pageContext.load(next)).then(function () {
|
4123
|
+
setPageContext(Object.assign({}, pageContext));
|
4124
|
+
});
|
4125
|
+
} catch (e) {
|
4126
|
+
return Promise.reject(e);
|
4127
|
+
}
|
4128
|
+
};
|
4129
|
+
|
4130
|
+
var _useContext2 = useContext(PageContext),
|
4131
|
+
pageContext = _useContext2[0],
|
4132
|
+
setPageContext = _useContext2[1];
|
4133
|
+
|
4134
|
+
var schema = props.schema;
|
4135
|
+
|
4136
|
+
var _useState2 = useState({}),
|
4137
|
+
form = _useState2[0],
|
4138
|
+
setForm = _useState2[1];
|
4139
|
+
|
4140
|
+
var filterSchema = useMemo(function () {
|
4141
|
+
var filterSchema = Object.assign({}, schema);
|
4142
|
+
Object.values(filterSchema).forEach(function (field) {
|
4143
|
+
return field.section = null;
|
4144
|
+
});
|
4145
|
+
delete filterSchema.flows;
|
4146
|
+
return filterSchema;
|
4147
|
+
}, [schema]);
|
4148
|
+
|
4149
|
+
function clear() {
|
4150
|
+
setForm({});
|
4151
|
+
}
|
4152
|
+
|
4153
|
+
var content = new Content(filterSchema, form);
|
4154
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Header, {
|
4155
|
+
title: /*#__PURE__*/React.createElement(Text, null, "Filtros")
|
4156
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
4157
|
+
icon: "filter_list_off",
|
4158
|
+
label: "Limpiar",
|
4159
|
+
action: clear
|
4160
|
+
})), /*#__PURE__*/React.createElement("main", null, /*#__PURE__*/React.createElement(ContentEditor, {
|
4161
|
+
content: content,
|
4162
|
+
onChange: change
|
4163
|
+
})));
|
4164
|
+
};
|
4165
|
+
/**
|
4166
|
+
* Table Editor
|
4167
|
+
*/
|
4168
|
+
|
4169
|
+
|
4170
|
+
var TableEditor = function TableEditor(props) {
|
4171
|
+
var select = function select(row, event) {
|
4172
|
+
try {
|
4173
|
+
clear();
|
4174
|
+
return Promise.resolve(pageContext.select(row.id)).then(function () {
|
4175
|
+
setPageContext(Object.assign({}, pageContext));
|
4176
|
+
});
|
4177
|
+
} catch (e) {
|
4178
|
+
return Promise.reject(e);
|
4179
|
+
}
|
4180
|
+
};
|
4181
|
+
|
4182
|
+
var remove = function remove(id) {
|
4183
|
+
try {
|
4184
|
+
return Promise.resolve(pageContext.remove(id)).then(function () {
|
4185
|
+
pageContext.clear();
|
4186
|
+
setPageContext(Object.assign({}, pageContext));
|
4187
|
+
});
|
4188
|
+
} catch (e) {
|
4189
|
+
return Promise.reject(e);
|
4190
|
+
}
|
4191
|
+
};
|
4192
|
+
|
4193
|
+
var _useContext3 = useContext(PageContext),
|
4194
|
+
pageContext = _useContext3[0],
|
4195
|
+
setPageContext = _useContext3[1];
|
4196
|
+
|
4197
|
+
var _pageContext$all = pageContext.all,
|
4198
|
+
all = _pageContext$all === void 0 ? [] : _pageContext$all;
|
4199
|
+
var icon = props.icon,
|
4200
|
+
title = props.title,
|
4201
|
+
schema = props.schema,
|
4202
|
+
editable = props.editable;
|
4203
|
+
|
4204
|
+
var _useState3 = useState(props.groupBy),
|
4205
|
+
groupBy = _useState3[0],
|
4206
|
+
setGroupBy = _useState3[1];
|
4207
|
+
|
4208
|
+
function changeGroup(id, value) {
|
4209
|
+
setGroupBy(value);
|
4210
|
+
}
|
4211
|
+
|
4212
|
+
function change(rowID, cellID, value) {
|
4213
|
+
var _Object$assign;
|
4214
|
+
|
4215
|
+
var row = all.find(function (r) {
|
4216
|
+
return r.id === rowID;
|
4217
|
+
});
|
4218
|
+
var next = Object.assign({}, row, (_Object$assign = {}, _Object$assign[cellID] = value, _Object$assign));
|
4219
|
+
delete next.actions;
|
4220
|
+
pageContext.update(next);
|
4221
|
+
setPageContext(Object.assign({}, pageContext));
|
4222
|
+
}
|
4223
|
+
|
4224
|
+
function clear() {
|
4225
|
+
pageContext.clear();
|
4226
|
+
setPageContext(Object.assign({}, pageContext));
|
4227
|
+
}
|
4228
|
+
|
4229
|
+
function renderGroups() {
|
4230
|
+
var groups = all.reduce(function (groups, filter) {
|
4231
|
+
var groupName = filter[groupBy];
|
4232
|
+
var group = groups[groupName];
|
4233
|
+
if (!group) groups[groupName] = [];
|
4234
|
+
groups[groupName].push(filter);
|
4235
|
+
return groups;
|
4236
|
+
}, {});
|
4237
|
+
return Object.keys(groups).map(function (groupName) {
|
4238
|
+
var table = {
|
4239
|
+
columns: Object.values(schema).filter(function (field) {
|
4240
|
+
return field.column === true;
|
4241
|
+
}).map(function (field) {
|
4242
|
+
var options = field.options;
|
4243
|
+
|
4244
|
+
if (options && typeof options == 'function') {
|
4245
|
+
options = options();
|
4246
|
+
}
|
4247
|
+
|
4248
|
+
return {
|
4249
|
+
id: field.id,
|
4250
|
+
label: field.label,
|
4251
|
+
type: field.type,
|
4252
|
+
onChange: field.editable ? change : null,
|
4253
|
+
options: options
|
4254
|
+
};
|
4255
|
+
}),
|
4256
|
+
rows: groups[groupName].map(function (item) {
|
4257
|
+
item.actions = [/*#__PURE__*/React.createElement(Icon, {
|
4258
|
+
icon: "delete",
|
4259
|
+
size: "small",
|
4260
|
+
clickable: true,
|
4261
|
+
action: function action() {
|
4262
|
+
return remove(item.id);
|
4263
|
+
}
|
4264
|
+
})];
|
4265
|
+
return item;
|
4266
|
+
})
|
4267
|
+
};
|
4268
|
+
table.columns.push({
|
4269
|
+
id: "actions"
|
4270
|
+
});
|
4271
|
+
return /*#__PURE__*/React.createElement(Fragment, {
|
4272
|
+
key: groupName
|
4273
|
+
}, /*#__PURE__*/React.createElement(Header, {
|
4274
|
+
title: groupName
|
4275
|
+
}), /*#__PURE__*/React.createElement(DataTable, _extends({}, table, {
|
4276
|
+
onRowSelection: select,
|
4277
|
+
editable: editable
|
4278
|
+
})));
|
4279
|
+
});
|
4280
|
+
}
|
4281
|
+
|
4282
|
+
var table = {
|
4283
|
+
columns: Object.values(schema).filter(function (field) {
|
4284
|
+
return field.column === true;
|
4285
|
+
}).map(function (field) {
|
4286
|
+
var options = field.options;
|
4287
|
+
|
4288
|
+
if (options && typeof options == 'function') {
|
4289
|
+
options = options();
|
4290
|
+
}
|
4291
|
+
|
4292
|
+
return {
|
4293
|
+
id: field.id,
|
4294
|
+
label: field.label,
|
4295
|
+
type: field.type,
|
4296
|
+
onChange: field.editable ? change : null,
|
4297
|
+
options: options
|
4298
|
+
};
|
4299
|
+
}),
|
4300
|
+
rows: all.map(function (item) {
|
4301
|
+
item.actions = [/*#__PURE__*/React.createElement(Icon, {
|
4302
|
+
icon: "delete",
|
4303
|
+
size: "small",
|
4304
|
+
clickable: true,
|
4305
|
+
action: function action() {
|
4306
|
+
return remove(item.id);
|
4307
|
+
}
|
4308
|
+
})];
|
4309
|
+
return item;
|
4310
|
+
})
|
4311
|
+
};
|
4312
|
+
table.columns.push({
|
4313
|
+
id: "actions"
|
4314
|
+
});
|
4315
|
+
|
4316
|
+
function buildGroupOptions(schema) {
|
4317
|
+
return Object.values(schema).filter(function (field) {
|
4318
|
+
return field.grouper === true;
|
4319
|
+
}).map(function (field) {
|
4320
|
+
return {
|
4321
|
+
label: field.label,
|
4322
|
+
value: field.id
|
4323
|
+
};
|
4324
|
+
});
|
4325
|
+
}
|
4326
|
+
|
4327
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Header, {
|
4328
|
+
icon: icon,
|
4329
|
+
title: /*#__PURE__*/React.createElement(Text, null, title)
|
4330
|
+
}, /*#__PURE__*/React.createElement(DropDown, {
|
4331
|
+
id: "groupBy",
|
4332
|
+
label: "Agrupar Por",
|
4333
|
+
value: groupBy,
|
4334
|
+
options: buildGroupOptions(schema),
|
4335
|
+
onChange: changeGroup
|
4336
|
+
})), /*#__PURE__*/React.createElement("main", {
|
4337
|
+
className: "table-editor"
|
4338
|
+
}, renderGroups()));
|
4339
|
+
};
|
4340
|
+
/**
|
4341
|
+
* table Context
|
4342
|
+
*/
|
4343
|
+
|
4344
|
+
|
4345
|
+
var TableContext = function TableContext(url, field) {
|
4346
|
+
var API = TableAPI(url);
|
4347
|
+
return {
|
4348
|
+
all: [],
|
4349
|
+
selected: null,
|
4350
|
+
filters: {},
|
4351
|
+
load: function load(filter) {
|
4352
|
+
try {
|
4353
|
+
var _this2 = this;
|
4354
|
+
|
4355
|
+
var _temp2 = _catch(function () {
|
4356
|
+
var filters = filter ? Object.keys(filter).reduce(function (filters, key) {
|
4357
|
+
var field = filter[key];
|
4358
|
+
if (field) filters[key] = field;
|
4359
|
+
return filters;
|
4360
|
+
}, {}) : [];
|
4361
|
+
return Promise.resolve(API.all(filters)).then(function (data) {
|
4362
|
+
_this2.all = field ? data[field] : data;
|
4363
|
+
});
|
4364
|
+
}, function (error) {
|
4365
|
+
console.log(error);
|
4366
|
+
});
|
4367
|
+
|
4368
|
+
return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0);
|
4369
|
+
} catch (e) {
|
4370
|
+
return Promise.reject(e);
|
4371
|
+
}
|
4372
|
+
},
|
4373
|
+
select: function select(id) {
|
4374
|
+
var result = this.all.find(function (item) {
|
4375
|
+
return item.id === id;
|
4376
|
+
});
|
4377
|
+
this.selected = result;
|
4378
|
+
},
|
4379
|
+
clear: function clear() {
|
4380
|
+
this.selected = null;
|
4381
|
+
},
|
4382
|
+
create: function create(form) {
|
4383
|
+
try {
|
4384
|
+
var _this4 = this;
|
4385
|
+
|
4386
|
+
var _temp4 = _catch(function () {
|
4387
|
+
return Promise.resolve(API.create(form)).then(function () {
|
4388
|
+
return Promise.resolve(_this4.load()).then(function () {});
|
4389
|
+
});
|
4390
|
+
}, function (error) {
|
4391
|
+
console.log(error);
|
4392
|
+
});
|
4393
|
+
|
4394
|
+
return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(function () {}) : void 0);
|
4395
|
+
} catch (e) {
|
4396
|
+
return Promise.reject(e);
|
4397
|
+
}
|
4398
|
+
},
|
4399
|
+
update: function update(form) {
|
4400
|
+
try {
|
4401
|
+
var _this6 = this;
|
4402
|
+
|
4403
|
+
var _temp6 = _catch(function () {
|
4404
|
+
return Promise.resolve(API.update(form)).then(function () {
|
4405
|
+
return Promise.resolve(_this6.load()).then(function () {});
|
4406
|
+
});
|
4407
|
+
}, function (error) {
|
4408
|
+
console.log(error);
|
4409
|
+
});
|
4410
|
+
|
4411
|
+
return Promise.resolve(_temp6 && _temp6.then ? _temp6.then(function () {}) : void 0);
|
4412
|
+
} catch (e) {
|
4413
|
+
return Promise.reject(e);
|
4414
|
+
}
|
4415
|
+
},
|
4416
|
+
remove: function remove(id) {
|
4417
|
+
try {
|
4418
|
+
var _this8 = this;
|
4419
|
+
|
4420
|
+
var _temp8 = _catch(function () {
|
4421
|
+
return Promise.resolve(API.remove(id)).then(function () {
|
4422
|
+
return Promise.resolve(_this8.load()).then(function () {});
|
4423
|
+
});
|
4424
|
+
}, function (error) {
|
4425
|
+
console.log(error);
|
4426
|
+
});
|
4427
|
+
|
4428
|
+
return Promise.resolve(_temp8 && _temp8.then ? _temp8.then(function () {}) : void 0);
|
4429
|
+
} catch (e) {
|
4430
|
+
return Promise.reject(e);
|
4431
|
+
}
|
4432
|
+
},
|
4433
|
+
changeFilters: function changeFilters(filters) {
|
4434
|
+
this.filters = filters;
|
4435
|
+
}
|
4436
|
+
};
|
4437
|
+
};
|
4438
|
+
/**
|
4439
|
+
* table API
|
4440
|
+
*/
|
4441
|
+
|
4442
|
+
|
4443
|
+
var TableAPI = function TableAPI(url) {
|
4444
|
+
return {
|
4445
|
+
all: function all(filters) {
|
4446
|
+
var queryParams = "?";
|
4447
|
+
|
4448
|
+
if (filters) {
|
4449
|
+
var filterQuery = Object.keys(filters).reduce(function (query, key) {
|
4450
|
+
if (typeof filters[key] === 'boolean') {
|
4451
|
+
return query.concat(key + "=" + filters[key] + "&");
|
4452
|
+
} else {
|
4453
|
+
return query.concat(key + "=%" + filters[key] + "%&");
|
4454
|
+
}
|
4455
|
+
}, "");
|
4456
|
+
queryParams = queryParams.concat(filterQuery);
|
4457
|
+
}
|
4458
|
+
|
4459
|
+
return http.GET(url + queryParams);
|
4460
|
+
},
|
4461
|
+
find: function find(id) {
|
4462
|
+
return http.GET(url + "/" + id);
|
4463
|
+
},
|
4464
|
+
create: function create(form) {
|
4465
|
+
var body = JSON.stringify(form);
|
4466
|
+
return http.POST(url, body);
|
4467
|
+
},
|
4468
|
+
update: function update(form) {
|
4469
|
+
var body = JSON.stringify(form);
|
4470
|
+
return http.PUT(url + "/" + form.id, body);
|
3811
4471
|
},
|
3812
4472
|
remove: function remove(id) {
|
3813
4473
|
return http.DELETE(url + "/" + id);
|
@@ -4083,5 +4743,5 @@ var isFunction = function isFunction(value) {
|
|
4083
4743
|
return value && (Object.prototype.toString.call(value) === "[object Function]" || "function" === typeof value || value instanceof Function);
|
4084
4744
|
};
|
4085
4745
|
|
4086
|
-
export { Button, CheckBox, Chip, Chips, CircularProgress, CollectionContext, CollectionEditor$1 as CollectionEditor, CollectionPage, Content, ContentEditor, ContentForm, CreateContentDialog, DataTable, Dialog, DropDown, EditContentDialog, FieldEditor, Form, HTTPClient, Header, Icon, Kanban, KanbanCard, KanbanColumn, LinearProgress, List, ListEditor, LoginBox, Menu, MenuIcon, MenuItem, MenuSeparator, Page, PageContext, PageProvider, Property, RadioButton, ResetPasswordBox, Section, Session, Site, SiteContext, SiteProvider, Stack, TYPES, Tab, TabbedContentEditor, Tabs, Text, TextField, TokenField, Tree, TreeItem, TreeNode, TreededContentEditor, UploadArea, UploadDialog, UploadFile, Uploader, Viewer, isFunction };
|
4746
|
+
export { Button, CheckBox, Chip, Chips, CircularProgress, CollectionContext, CollectionEditor$1 as CollectionEditor, CollectionPage, Content, ContentEditor, ContentForm, CreateContentDialog$1 as CreateContentDialog, DataTable, Dialog, DropDown, EditContentDialog, FieldEditor, Form, HTTPClient, Header, Icon, Kanban, KanbanCard, KanbanColumn, LinearProgress, List, ListEditor, LoginBox, Menu, MenuIcon, MenuItem, MenuSeparator, Page, PageContext, PageProvider, Property, RadioButton, ResetPasswordBox, Section, Session, Site, SiteContext, SiteProvider, Stack, TYPES, Tab, TabbedContentEditor, TablePage, Tabs, Text, TextField, TokenField, Tree, TreeItem, TreeNode, TreededContentEditor, UploadArea, UploadDialog, UploadFile, Uploader, Viewer, isFunction };
|
4087
4747
|
//# sourceMappingURL=index.modern.js.map
|