@entropic-bond/crud-panel 4.0.4 → 4.1.1

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/package.json CHANGED
@@ -1,6 +1,21 @@
1
1
  {
2
2
  "name": "@entropic-bond/crud-panel",
3
- "version": "4.0.4",
3
+ "type": "module",
4
+ "version": "4.1.1",
5
+ "description": "Crud panel for React",
6
+ "main": "lib/entropic-bond-crud-panel.umd.cjs",
7
+ "module": "lib/entropic-bond-crud-panel.js",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./lib/entropic-bond-crud-panel.js",
11
+ "require": "./lib/entropic-bond-crud-panel.umd.cjs",
12
+ "types": "./lib/index.d.ts"
13
+ }
14
+ },
15
+ "types": "./lib/index.d.ts",
16
+ "files": [
17
+ "lib"
18
+ ],
4
19
  "publishConfig": {
5
20
  "access": "public",
6
21
  "branches": [
@@ -16,18 +31,10 @@
16
31
  "@semantic-release/github"
17
32
  ]
18
33
  },
19
- "description": "Crud panel for React",
20
- "main": "lib/index.js",
21
- "types": "lib/index.d.ts",
22
- "files": [
23
- "lib"
24
- ],
25
34
  "scripts": {
26
35
  "test": "vitest",
27
- "build": "npm run build-cjs",
28
- "prepare": "npm run build",
29
- "build-ts": "cp -r ./src/ ./lib",
30
- "build-cjs": "tsc -p tsconfig-cjs.json"
36
+ "build": "tsc -p tsconfig-build.json && vite build",
37
+ "prepare": "npm run build"
31
38
  },
32
39
  "repository": {
33
40
  "type": "git",
@@ -46,20 +53,22 @@
46
53
  "devDependencies": {
47
54
  "@semantic-release/changelog": "^6.0.3",
48
55
  "@semantic-release/git": "^10.0.1",
49
- "@testing-library/jest-dom": "^6.2.0",
50
- "@testing-library/react": "^14.1.2",
56
+ "@testing-library/jest-dom": "^6.4.2",
57
+ "@testing-library/react": "^14.2.1",
51
58
  "@testing-library/user-event": "^14.5.2",
52
- "@types/react": "^18.2.47",
53
- "@types/react-dom": "^18.2.18",
59
+ "@types/node": "^20.11.17",
60
+ "@types/react": "^18.2.55",
61
+ "@types/react-dom": "^18.2.19",
54
62
  "fetch-mock": "^9.11.0",
55
63
  "git-branch-is": "^4.0.0",
56
- "happy-dom": "^12.10.3",
57
- "husky": "^8.0.3",
64
+ "happy-dom": "^13.3.8",
65
+ "husky": "^9.0.10",
58
66
  "react": "^18.2.0",
59
67
  "react-dom": "^18.2.0",
60
- "semantic-release": "^22.0.12",
68
+ "semantic-release": "^23.0.2",
61
69
  "typescript": "^5.3.3",
62
- "vitest": "^1.1.3"
70
+ "vite-plugin-dts": "^3.7.2",
71
+ "vitest": "^1.2.2"
63
72
  },
64
73
  "husky": {
65
74
  "hooks": {
@@ -67,6 +76,6 @@
67
76
  }
68
77
  },
69
78
  "dependencies": {
70
- "entropic-bond": "^1.48.1"
79
+ "entropic-bond": "^1.50.4"
71
80
  }
72
81
  }
@@ -1,249 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CrudController = void 0;
4
- const entropic_bond_1 = require("entropic-bond");
5
- const progress_controller_1 = require("./progress-controller");
6
- class CrudController {
7
- constructor(document) {
8
- this.progressController = new progress_controller_1.ProgressController();
9
- this.onChangeHdl = new entropic_bond_1.Observable();
10
- this.onErrorHdl = new entropic_bond_1.Observable();
11
- this.validator = {};
12
- this.setDocument(document || this.createDocument());
13
- }
14
- allRequiredPropertiesFilled() {
15
- return this.nonFilledRequiredProperties.length <= 0;
16
- }
17
- get nonFilledRequiredProperties() {
18
- return this.requiredProperties.filter(prop => this.validateProp(prop));
19
- }
20
- get requiredProperties() {
21
- if (!this.document)
22
- throw new Error(CrudController.errorMessages.missedDocument);
23
- return this.document.getPersistentProperties()
24
- .filter(prop => this.document.isRequired(prop.name))
25
- .map(prop => prop.name);
26
- }
27
- addValidator(prop, validatorFn, errorMessage) {
28
- this.validator[prop] = {
29
- func: validatorFn,
30
- errorMessage
31
- };
32
- }
33
- removeValidator(prop) {
34
- delete this.validator[prop];
35
- }
36
- failedValidationError(prop) {
37
- return this.validator[prop]?.errorMessage;
38
- }
39
- validateProp(prop) {
40
- if (!this.document)
41
- throw new Error(CrudController.errorMessages.missedDocument);
42
- const propVal = this.document[prop];
43
- if (this.validator[prop])
44
- return !this.validator[prop].func(propVal);
45
- return !this.document.isPropValueValid(prop);
46
- }
47
- storeDoc() {
48
- if (!this.document)
49
- throw new Error(CrudController.errorMessages.missedDocument);
50
- return this.model.save(this.document);
51
- }
52
- deleteDoc() {
53
- if (!this.document)
54
- throw new Error(CrudController.errorMessages.missedDocument);
55
- return this.model.delete(this.document.id);
56
- }
57
- /**
58
- * Override this method to customize the query used to retrieve the documents
59
- * in the documentCollection method. This is the default method used by
60
- * the documentCollection method. If the findDocs method is overridden and returns
61
- * non undefined value, then this queryDocs method will not be used.
62
- *
63
- * @param limit the maximum number of documents to retrieve
64
- * @returns a query to retrieve the documents
65
- * @see documentCollection
66
- * @see findDocs
67
- */
68
- queryDocs(limit) {
69
- let query = this.model.find();
70
- if (limit)
71
- query = query.limit(limit);
72
- return query;
73
- }
74
- /**
75
- * Override this method to customize the query used to retrieve the documents
76
- * in the documentCollection method. The default method called by the
77
- * documentCollection method is the queryDocs method. If this findDocs method
78
- * returns a non undefined value, then this method will be used instead of the
79
- * queryDocs method.
80
- *
81
- * @param limit the maximum number of documents to retrieve
82
- * @returns a query to retrieve the documents
83
- * @see documentCollection
84
- * @see queryDocs
85
- */
86
- findDocs(limit) {
87
- return undefined;
88
- }
89
- /**
90
- * Sets a filter function to filter in memory the documents returned by the `documentCollection` method.
91
- *
92
- * @param filter the filter function
93
- * @returns the controller itself
94
- */
95
- async setFilter(filter) {
96
- this._filter = filter;
97
- this.onChangeHdl.notify({ action: 'filterChange' });
98
- return this;
99
- }
100
- /**
101
- * Removes the filter function set by the `setFilter` method.
102
- * @returns the controller itself
103
- */
104
- resetFilter() {
105
- this._filter = undefined;
106
- this.onChangeHdl.notify({ action: 'filterChange' });
107
- return this;
108
- }
109
- onChange(observer) {
110
- return this.onChangeHdl.subscribe(observer);
111
- }
112
- /**
113
- * Notifies the observer of any error that occurs during the execution of the controller.
114
- * If there are no subscribers to this event, the error will be thrown.
115
- *
116
- * @param observer
117
- * @returns the unsubscriber function
118
- */
119
- onError(observer) {
120
- return this.onErrorHdl.subscribe(observer);
121
- }
122
- notifyChange(event) {
123
- this.onChangeHdl.notify(event);
124
- }
125
- newDocument() {
126
- return this.setDocument(this.createDocument());
127
- }
128
- async storeDocument() {
129
- const progressStage = 'Saving main document';
130
- try {
131
- this.progressController.notifyBusy(true, progressStage);
132
- await this.storeDoc();
133
- this.onChangeHdl.notify({
134
- documentCollection: await this.documentCollection(),
135
- action: 'saved'
136
- });
137
- }
138
- catch (error) {
139
- this.onChangeHdl.notify({ error: this.errorToError(error) });
140
- this.onErrorHdl.notify(this.errorToError(error));
141
- if (this.throwOnError)
142
- throw error;
143
- }
144
- finally {
145
- this.progressController.notifyBusy(false, progressStage);
146
- }
147
- }
148
- async deleteDocument() {
149
- const progressStage = 'Delete main document';
150
- try {
151
- this.progressController.notifyBusy(true, progressStage);
152
- await this.deleteDoc();
153
- this.onChangeHdl.notify({
154
- documentCollection: await this.documentCollection(),
155
- action: 'deleted'
156
- });
157
- }
158
- catch (error) {
159
- this.onChangeHdl.notify({ error: this.errorToError(error) });
160
- this.onErrorHdl.notify(this.errorToError(error));
161
- if (this.throwOnError)
162
- throw error;
163
- }
164
- finally {
165
- this.progressController.notifyBusy(false, progressStage);
166
- }
167
- }
168
- async documentCollection(limit) {
169
- const progressStage = 'Retrieving document collection';
170
- let found = [];
171
- try {
172
- this.progressController.notifyBusy(true, progressStage);
173
- const docPromise = this.findDocs(limit);
174
- if (docPromise)
175
- found = await docPromise;
176
- else
177
- found = await this.queryDocs(limit).get();
178
- }
179
- catch (error) {
180
- this.onChangeHdl.notify({ error: this.errorToError(error) });
181
- this.onErrorHdl.notify(this.errorToError(error));
182
- if (this.throwOnError)
183
- throw error;
184
- }
185
- finally {
186
- this.progressController.notifyBusy(false, progressStage);
187
- }
188
- return found;
189
- }
190
- filter(docs) {
191
- return docs.filter(doc => this._filter?.(doc) ?? true);
192
- }
193
- onProgress(observer) {
194
- return this.progressController.onProgress(observer);
195
- }
196
- get model() {
197
- return this._model || (this._model = this.getModel());
198
- }
199
- setDocument(value) {
200
- if (this._document !== value) {
201
- if (this.unsubscribeDocument)
202
- this.unsubscribeDocument();
203
- if (value) {
204
- this.unsubscribeDocument = value.onChange(e => this.onChangeHdl.notify({ documentProps: e }));
205
- }
206
- this._document = value;
207
- this.onChangeHdl.notify({ documentChanged: this._document });
208
- }
209
- return this;
210
- }
211
- set document(value) {
212
- this.setDocument(value);
213
- }
214
- get document() {
215
- return this._document;
216
- }
217
- /**
218
- * Use this method to throw an error in a controlled way.
219
- * It will notify the subscribers of the `onError` event and throw the error
220
- * if there are no subscribers to the `onError` event.
221
- *
222
- * @param error the error to throw
223
- */
224
- managedThrow(error) {
225
- /* deprecated */ this.onChangeHdl.notify({ error: this.errorToError(error) });
226
- this.onErrorHdl.notify(this.errorToError(error));
227
- if (this.throwOnError)
228
- throw this.errorToError(error);
229
- }
230
- errorToError(error) {
231
- if (error instanceof Error)
232
- return error;
233
- if (typeof error === 'string')
234
- return new Error(error);
235
- if ('code' in error)
236
- return new Error(error.code);
237
- if ('message' in error)
238
- return new Error(error.error);
239
- return new Error(JSON.stringify(error));
240
- }
241
- get throwOnError() {
242
- return this.onErrorHdl.subscribersCount === 0;
243
- }
244
- }
245
- exports.CrudController = CrudController;
246
- CrudController.errorMessages = {
247
- missedDocument: 'No document to save',
248
- };
249
- //# sourceMappingURL=crud-controller.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"crud-controller.js","sourceRoot":"","sources":["../src/crud-controller.ts"],"names":[],"mappings":";;;AAAA,iDAAoI;AACpI,+DAAyE;AAoBzE,MAAsB,cAAc;IAKnC,YAAa,QAAY;QAuQf,uBAAkB,GAAuB,IAAI,wCAAkB,EAAE,CAAA;QACjE,gBAAW,GAAuC,IAAI,0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,IAAI,CAAC,SAAS,CAAE,KAAK,CAAE,CAAE,CAAA;IAC5C,CAAC;IAED,IAAc,YAAY;QACzB,OAAO,IAAI,CAAC,UAAU,CAAC,gBAAgB,KAAK,CAAC,CAAA;IAC9C,CAAC;;AA1QF,wCAoRC;AAnRgB,4BAAa,GAAG;IAC/B,cAAc,EAAE,qBAAqB;CACrC,AAF4B,CAE5B"}
package/lib/crud-panel.js DELETED
@@ -1,168 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.CrudPanel = void 0;
27
- const entropic_bond_1 = require("entropic-bond");
28
- const react_1 = __importStar(require("react"));
29
- var Mode;
30
- (function (Mode) {
31
- Mode[Mode["normal"] = 0] = "normal";
32
- Mode[Mode["add"] = 1] = "add";
33
- Mode[Mode["edit"] = 2] = "edit";
34
- })(Mode || (Mode = {}));
35
- class CrudPanel extends react_1.Component {
36
- constructor(props) {
37
- super(props);
38
- this.unfilteredDocuments = [];
39
- this.state = {
40
- documents: [],
41
- mode: Mode.normal,
42
- };
43
- }
44
- async componentDidMount() {
45
- const { controller } = this.props;
46
- this.unsubscriber = controller.onChange(event => {
47
- if (event.documentCollection) {
48
- this.unfilteredDocuments = event.documentCollection;
49
- this.setState({
50
- documents: controller.filter(this.unfilteredDocuments)
51
- });
52
- }
53
- if (event.action === 'filterChange') {
54
- this.setState({
55
- documents: controller.filter(this.unfilteredDocuments)
56
- });
57
- }
58
- else
59
- this.setState({});
60
- });
61
- this.unfilteredDocuments = await controller.documentCollection();
62
- this.setState({
63
- documents: controller.filter(this.unfilteredDocuments)
64
- });
65
- }
66
- componentWillUnmount() {
67
- this.unsubscriber?.();
68
- }
69
- newDocument() {
70
- this.props.controller.newDocument();
71
- this.setState({
72
- mode: Mode.add,
73
- });
74
- }
75
- editDocument(document) {
76
- this.props.controller.setDocument(document);
77
- this.setState({
78
- mode: Mode.edit
79
- });
80
- }
81
- async storeDocument(document) {
82
- const { controller, layout } = this.props;
83
- controller.setDocument(document);
84
- await controller.storeDocument();
85
- if (layout === 'formAndItems') {
86
- this.newDocument();
87
- }
88
- else {
89
- this.setState({
90
- mode: Mode.normal,
91
- });
92
- }
93
- }
94
- invokeContentViewChild(labels) {
95
- const { children, layout, controller } = this.props;
96
- const { mode } = this.state;
97
- const closeOnCancel = layout !== 'formAndItems';
98
- if (!controller.document)
99
- return;
100
- const props = {
101
- controller: controller,
102
- submitButtonCaption: mode == Mode.edit ? labels?.updateButtonLabel : labels?.addButtonLabel,
103
- onSubmit: (document) => this.storeDocument(document),
104
- onCancel: closeOnCancel
105
- ? () => this.setState({ mode: Mode.normal })
106
- : () => this.newDocument(),
107
- };
108
- if (typeof children[0] === 'function') {
109
- return (0, react_1.cloneElement)(children[0](props), { key: controller.document.id });
110
- }
111
- else {
112
- return (0, react_1.cloneElement)(children[0], { key: controller.document.id, ...props });
113
- }
114
- }
115
- invokeDetailViewChild(document) {
116
- const { children, controller } = this.props;
117
- const props = {
118
- document,
119
- onSelect: (document) => this.editDocument(document),
120
- onDelete: (document) => controller.setDocument(document).deleteDocument()
121
- };
122
- if (typeof children[1] === 'function') {
123
- return (0, react_1.cloneElement)(children[1](props), { key: document.id });
124
- }
125
- else {
126
- return (0, react_1.cloneElement)(children[1], { key: document.id, ...props });
127
- }
128
- }
129
- render() {
130
- const { mode, documents } = this.state;
131
- const { className, cardAddButton, controller } = this.props;
132
- const docClassName = (0, entropic_bond_1.snakeCase)(controller.document?.className);
133
- let labels = this.props.labels || {};
134
- const layout = this.props.layout || 'itemsAlways';
135
- if (typeof labels === 'function')
136
- labels = labels(controller);
137
- const { addNewDocumentLabel, singularDocumentInCollectionCaption, documentsInCollectionCaption, noDocumentsFoundLabel } = labels;
138
- return (react_1.default.createElement("div", { className: `crud-panel ${docClassName} ${className || ''}` },
139
- mode === Mode.normal && layout !== 'formAndItems' && !cardAddButton &&
140
- react_1.default.createElement("div", { className: "header" }, this.props.header
141
- ? typeof this.props.header === 'function'
142
- ? this.props.header(controller, () => this.newDocument(), labels)
143
- : this.props.header
144
- : react_1.default.createElement("button", { onClick: () => this.newDocument() }, addNewDocumentLabel)),
145
- (layout === 'formAndItems' || mode === Mode.add || mode === Mode.edit) &&
146
- react_1.default.createElement("div", { className: "content-panel" }, this.invokeContentViewChild(labels)),
147
- (layout === 'itemsAlways' || layout === 'formAndItems' || mode === Mode.normal) &&
148
- react_1.default.createElement("div", { className: "collection-panel" },
149
- documents?.length > 0 &&
150
- react_1.default.createElement("h3", null, documents.length > 1
151
- ? documentsInCollectionCaption
152
- : singularDocumentInCollectionCaption || documentsInCollectionCaption),
153
- react_1.default.createElement("div", { className: "documents" },
154
- cardAddButton &&
155
- react_1.default.createElement("div", { className: "crud-card card-add-button clickable", onClick: () => this.newDocument() },
156
- react_1.default.createElement("div", { className: "button-element" }, cardAddButton),
157
- react_1.default.createElement("div", { className: "add-label" }, addNewDocumentLabel)),
158
- documents?.length
159
- ? documents.map((document) => this.invokeDetailViewChild(document))
160
- : react_1.default.createElement("p", null, noDocumentsFoundLabel))),
161
- react_1.default.createElement("div", { className: "footer" }, this.props.footer &&
162
- typeof this.props.footer === 'function'
163
- ? this.props.footer(controller, () => this.newDocument(), labels)
164
- : this.props.footer)));
165
- }
166
- }
167
- exports.CrudPanel = CrudPanel;
168
- //# sourceMappingURL=crud-panel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"crud-panel.js","sourceRoot":"","sources":["../src/crud-panel.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA0E;AAC1E,+CAAoE;AAGpE,IAAK,IAA0B;AAA/B,WAAK,IAAI;IAAG,mCAAM,CAAA;IAAE,6BAAG,CAAA;IAAE,+BAAI,CAAA;AAAC,CAAC,EAA1B,IAAI,KAAJ,IAAI,QAAsB;AA6C/B,MAAa,SAAuC,SAAQ,iBAA+C;IAE1G,YAAa,KAAwB;QACpC,KAAK,CAAE,KAAK,CAAE,CAAA;QA6LP,wBAAmB,GAAQ,EAAE,CAAA;QA3LpC,IAAI,CAAC,KAAK,GAAG;YACZ,SAAS,EAAE,EAAE;YACb,IAAI,EAAE,IAAI,CAAC,MAAM;SACjB,CAAA;IACF,CAAC;IAEQ,KAAK,CAAC,iBAAiB;QAC/B,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QAEjC,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,QAAQ,CAAE,KAAK,CAAC,EAAE;YAChD,IAAK,KAAK,CAAC,kBAAkB,EAAG,CAAC;gBAChC,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAC,kBAAkB,CAAA;gBACnD,IAAI,CAAC,QAAQ,CAAC;oBACb,SAAS,EAAE,UAAU,CAAC,MAAM,CAAE,IAAI,CAAC,mBAAmB,CAAE;iBACxD,CAAC,CAAA;YACH,CAAC;YACD,IAAK,KAAK,CAAC,MAAM,KAAK,cAAc,EAAG,CAAC;gBACvC,IAAI,CAAC,QAAQ,CAAC;oBACb,SAAS,EAAE,UA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K,SAAS,EAAC,WAAW,IAAG,mBAAmB,CAAQ,CACnD;wBAEL,SAAS,EAAE,MAAM;4BAClB,CAAC,CAAC,SAAS,CAAC,GAAG,CAAE,CAAC,QAAW,EAAE,EAAE,CAAC,IAAI,CAAC,qBAAqB,CAAE,QAAQ,CAAE,CAAE;4BAC1E,CAAC,CAAC,yCAAK,qBAAqB,CAAM,CAE9B,CACD;YAIP,uCAAK,SAAS,EAAC,QAAQ,IACpB,IAAI,CAAC,KAAK,CAAC,MAAM;gBAClB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,UAAU;gBACtC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAE,UAAU,EAAE,GAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,MAAM,CAAE;gBAClE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAEhB,CACD,CACN,CAAA;IACF,CAAC;CAID;AAjMD,8BAiMC"}
package/lib/index.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./crud-controller"), exports);
18
- __exportStar(require("./crud-panel"), exports);
19
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAiC;AACjC,+CAA4B"}
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ProgressController = void 0;
4
- const entropic_bond_1 = require("entropic-bond");
5
- class ProgressController {
6
- constructor() {
7
- this._stages = {};
8
- this._onProgress = new entropic_bond_1.Observable();
9
- }
10
- notifyBusy(busy, name) {
11
- this.pushStage({
12
- name: name ?? '', progress: busy ? 0 : 1, total: 1
13
- });
14
- }
15
- pushStage(stage) {
16
- this._stages[stage.name] = stage;
17
- const overallProgress = Object.values(this._stages).reduce((prev, stage, _i, arr) => {
18
- return prev + stage.progress / stage.total / arr.length;
19
- }, 0);
20
- this._onProgress.notify({
21
- busy: overallProgress < 1,
22
- overallProgress,
23
- stages: this._stages
24
- });
25
- if (overallProgress >= 1)
26
- this._stages = {};
27
- }
28
- onProgress(cb) {
29
- return this._onProgress.subscribe(cb);
30
- }
31
- }
32
- exports.ProgressController = ProgressController;
33
- //# sourceMappingURL=progress-controller.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"progress-controller.js","sourceRoot":"","sources":["../src/progress-controller.ts"],"names":[],"mappings":";;;AAAA,iDAAoD;AAkBpD,MAAa,kBAAkB;IAA/B;QA2BS,YAAO,GAA4B,EAAE,CAAA;QACrC,gBAAW,GAA8B,IAAI,0BAAU,EAAiB,CAAA;IACjF,CAAC;IA5BA,UAAU,CAAE,IAAa,EAAE,IAAa;QACvC,IAAI,CAAC,SAAS,CAAC;YACd,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;SACjD,CAAC,CAAA;IACH,CAAC;IAED,SAAS,CAAE,KAAoB;QAC9B,IAAI,CAAC,OAAO,CAAE,KAAK,CAAC,IAAI,CAAE,GAAG,KAAK,CAAA;QAElC,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAE,IAAI,CAAC,OAAO,CAAE,CAAC,MAAM,CAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE;YACtF,OAAO,IAAI,GAAG,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,MAAM,CAAA;QACxD,CAAC,EAAE,CAAC,CAAC,CAAA;QAEL,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;YACvB,IAAI,EAAE,eAAe,GAAG,CAAC;YACzB,eAAe;YACf,MAAM,EAAE,IAAI,CAAC,OAAO;SACpB,CAAC,CAAA;QAEF,IAAK,eAAe,IAAI,CAAC;YAAG,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;IAC9C,CAAC;IAED,UAAU,CAAE,EAA2B;QACtC,OAAO,IAAI,CAAC,WAAW,CAAC,SAAS,CAAE,EAAE,CAAE,CAAA;IACxC,CAAC;CAID;AA7BD,gDA6BC"}