@acoustte-digital-services/digitalstore-controls-dev 0.8.1-dev.20260713051007 → 0.8.1-dev.20260713054521

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,199 @@
1
+ import {
2
+ Constants
3
+ } from "./chunk-DBHUCH4B.mjs";
4
+
5
+ // src/clients/OdataBuilder.tsx
6
+ var OdataBuilder = class {
7
+ constructor(url) {
8
+ this.baseUrl = url;
9
+ this.top = Constants.pagesize.toString();
10
+ this.skip = "0";
11
+ this.keyword = "";
12
+ this.filterBy = "";
13
+ this.orderBy = "";
14
+ }
15
+ // parseSearchParams(ReadonlyUrlSearchParams): DataQuery {
16
+ // this.top = top;
17
+ // return this;
18
+ // }
19
+ setQuery(odata) {
20
+ if (odata) {
21
+ for (const key in odata) {
22
+ if (odata[key] != null && odata[key] != "") {
23
+ if (key == "$skip") {
24
+ this.setSkip(odata[key]);
25
+ }
26
+ if (key == "$filter") {
27
+ this.setFilter(odata[key]);
28
+ }
29
+ if (key == "$top") {
30
+ this.setTop(odata[key]);
31
+ }
32
+ if (key == "$orderby") {
33
+ this.setOrderBy(odata[key]);
34
+ }
35
+ if (key == "searchTerm") {
36
+ this.searchTerm = odata[key];
37
+ }
38
+ if (key == "searchCols") {
39
+ this.searchCols = odata[key];
40
+ }
41
+ }
42
+ }
43
+ }
44
+ return this;
45
+ }
46
+ // parseKeyValuePairs(inputString: string): { [key: string]: string } {
47
+ // return inputString.split('$')
48
+ // .map((pair) => pair.split('='))
49
+ // .reduce((result: { [key: string]: string }, [key, value]) => {
50
+ // if (key && value) {
51
+ // result[key.trim()] = value.trim();
52
+ // }
53
+ // return result;
54
+ // }, {});
55
+ // }
56
+ static getOdataQueryString(obj, defaultOrder) {
57
+ let queryString = "";
58
+ let skip = (obj && obj["$skip"]) ?? "0";
59
+ let top = (obj && obj["$top"]) ?? Constants.pagesize.toString();
60
+ queryString = `$skip=${skip}&$top=${top}&$count=true`;
61
+ if (obj?.["searchTerm"] && obj["searchTerm"].trim() !== "") {
62
+ queryString += `&searchTerm=${encodeURIComponent(obj["searchTerm"])}`;
63
+ }
64
+ if (obj?.["searchCols"] && obj["searchCols"].trim() !== "") {
65
+ queryString += `&searchCols=${encodeURIComponent(obj["searchCols"])}`;
66
+ }
67
+ if (obj) {
68
+ if (obj["$filter"] && obj["$filter"] !== null && obj["$filter"] !== "") {
69
+ queryString = queryString + `&$filter=${encodeURIComponent(obj["$filter"])}`;
70
+ }
71
+ if (obj["$orderby"] && obj["$orderby"] !== null && obj["$orderby"] !== "") {
72
+ queryString = queryString + `&$orderby=${encodeURIComponent(obj["$orderby"])}`;
73
+ } else if (defaultOrder) {
74
+ queryString = queryString + `&$orderby=${encodeURIComponent(defaultOrder)}`;
75
+ }
76
+ } else {
77
+ if (defaultOrder) {
78
+ queryString = queryString + `&$orderby=${encodeURIComponent(defaultOrder)}`;
79
+ }
80
+ }
81
+ return queryString;
82
+ }
83
+ setTop(top) {
84
+ this.top = top;
85
+ return this;
86
+ }
87
+ setSkip(skip) {
88
+ this.skip = skip;
89
+ return this;
90
+ }
91
+ setKeyword(keyword) {
92
+ this.keyword = keyword;
93
+ return this;
94
+ }
95
+ setFilter(filterBy) {
96
+ this.filterBy = filterBy;
97
+ return this;
98
+ }
99
+ setOrderBy(orderBy) {
100
+ this.orderBy = orderBy;
101
+ return this;
102
+ }
103
+ getPageNumber(pageSize) {
104
+ let pageNumber = 1;
105
+ if (this.skip && this.top) {
106
+ const skip = parseInt(this.skip);
107
+ const top = parseInt(this.top);
108
+ if (!isNaN(skip) && !isNaN(top)) {
109
+ pageNumber = skip / pageSize + 1;
110
+ }
111
+ }
112
+ return pageNumber;
113
+ }
114
+ getUrl() {
115
+ let url = `${this.baseUrl}?$skip=${this.skip}&$top=${this.top}&$count=true`;
116
+ if (this.filterBy !== null && this.filterBy !== "") {
117
+ url = url + `&$filter=${encodeURIComponent(this.filterBy)}`;
118
+ }
119
+ if (this.orderBy !== null && this.orderBy !== "") {
120
+ url = url + `&$orderby=${encodeURIComponent(this.orderBy)}`;
121
+ }
122
+ if (this.searchTerm) {
123
+ url += `&searchTerm=${encodeURIComponent(this.searchTerm)}`;
124
+ }
125
+ if (this.searchCols) {
126
+ url += `&searchCols=${encodeURIComponent(this.searchCols)}`;
127
+ }
128
+ console.log(url);
129
+ return url;
130
+ }
131
+ getNewOrderByUrl(orderBy) {
132
+ let url = `${this.baseUrl}?$skip=${0}&$top=${this.top}&$count=true`;
133
+ if (this.filterBy !== null && this.filterBy !== "") {
134
+ url = url + `&$filter=${encodeURIComponent(this.filterBy)}`;
135
+ }
136
+ if (this.searchTerm) {
137
+ url += `&searchTerm=${encodeURIComponent(this.searchTerm)}`;
138
+ }
139
+ if (this.searchCols) {
140
+ url += `&searchCols=${encodeURIComponent(this.searchCols)}`;
141
+ }
142
+ url = url + `&$orderby=${encodeURIComponent(orderBy)}`;
143
+ return url;
144
+ }
145
+ getNewFilterUrl(filterBy) {
146
+ let url = `${this.baseUrl}?$skip=${0}&$top=${this.top}&$count=true`;
147
+ if (filterBy !== null && filterBy !== "") {
148
+ url = url + `&$filter=${encodeURIComponent(filterBy)}`;
149
+ }
150
+ if (this.orderBy !== null && this.orderBy !== "") {
151
+ url = url + `&$orderby=${encodeURIComponent(this.orderBy)}`;
152
+ }
153
+ if (this.searchTerm) {
154
+ url += `&searchTerm=${encodeURIComponent(this.searchTerm)}`;
155
+ }
156
+ if (this.searchCols) {
157
+ url += `&searchCols=${encodeURIComponent(this.searchCols)}`;
158
+ }
159
+ return url;
160
+ }
161
+ getNewPageUrl(page) {
162
+ let skip = page * Constants.pagesize - Constants.pagesize;
163
+ let url = `${this.baseUrl}?$skip=${skip}&$top=${this.top}&$count=true`;
164
+ if (this.filterBy !== null && this.filterBy !== "") {
165
+ url = url + `&$filter=${encodeURIComponent(this.filterBy)}`;
166
+ }
167
+ if (this.orderBy !== null && this.orderBy !== "") {
168
+ url = url + `&$orderby=${encodeURIComponent(this.orderBy)}`;
169
+ }
170
+ if (this.searchTerm) {
171
+ url += `&searchTerm=${encodeURIComponent(this.searchTerm)}`;
172
+ }
173
+ if (this.searchCols) {
174
+ url += `&searchCols=${encodeURIComponent(this.searchCols)}`;
175
+ }
176
+ return url;
177
+ }
178
+ getNewPageSizeUrl(pageSize) {
179
+ const currentPage = this.getPageNumber(
180
+ parseInt(this.top || Constants.pagesize.toString())
181
+ );
182
+ const skip = (currentPage - 1) * pageSize;
183
+ let url = `${this.baseUrl}?$skip=${skip}&$top=${pageSize}&$count=true`;
184
+ if (this.filterBy !== null && this.filterBy !== "") {
185
+ url = url + `&$filter=${encodeURIComponent(this.filterBy)}`;
186
+ }
187
+ if (this.orderBy !== null && this.orderBy !== "") {
188
+ url = url + `&$orderby=${encodeURIComponent(this.orderBy)}`;
189
+ }
190
+ return url;
191
+ }
192
+ getOrderBy() {
193
+ return this.orderBy;
194
+ }
195
+ };
196
+
197
+ export {
198
+ OdataBuilder
199
+ };
@@ -0,0 +1,212 @@
1
+ import {
2
+ buttonClasses,
3
+ progressClasses
4
+ } from "./chunk-56HSDML5.mjs";
5
+
6
+ // src/components/ToastService.tsx
7
+ var toastHandlersKey = "__digitalStoreToastHandlers";
8
+ var getToastHandlers = () => {
9
+ const globalScope = globalThis;
10
+ if (!globalScope[toastHandlersKey]) {
11
+ globalScope[toastHandlersKey] = {};
12
+ }
13
+ return globalScope[toastHandlersKey];
14
+ };
15
+ var ToastService = class {
16
+ static initialize(showToast, closeToast) {
17
+ const handlers = getToastHandlers();
18
+ handlers.showToast = showToast;
19
+ handlers.closeToast = closeToast;
20
+ }
21
+ static showError(message) {
22
+ const handlers = getToastHandlers();
23
+ if (handlers.showToast) {
24
+ handlers.showToast(message, "error");
25
+ }
26
+ }
27
+ static showInfo(message) {
28
+ const handlers = getToastHandlers();
29
+ if (handlers.showToast) {
30
+ handlers.showToast(message, "info");
31
+ }
32
+ }
33
+ static showWarning(message) {
34
+ const handlers = getToastHandlers();
35
+ if (handlers.showToast) {
36
+ handlers.showToast(message, "warning");
37
+ }
38
+ }
39
+ static showSuccess(message) {
40
+ const handlers = getToastHandlers();
41
+ if (handlers.showToast) {
42
+ handlers.showToast(message, "success");
43
+ }
44
+ }
45
+ static close() {
46
+ const handlers = getToastHandlers();
47
+ if (handlers.closeToast) {
48
+ handlers.closeToast();
49
+ }
50
+ }
51
+ };
52
+ var ToastService_default = ToastService;
53
+
54
+ // src/components/Button.tsx
55
+ import React3, { useState as useState2 } from "react";
56
+
57
+ // src/components/Confirm.tsx
58
+ import { useState } from "react";
59
+
60
+ // src/components/ClientButton.tsx
61
+ import React from "react";
62
+ import { jsx } from "react/jsx-runtime";
63
+ var ClientButton = (props) => {
64
+ const execute = async (event) => {
65
+ if (props.onClick !== void 0) {
66
+ props.onClick();
67
+ } else {
68
+ ToastService_default.showError("No action defined.");
69
+ }
70
+ };
71
+ let buttonClass = props.ButtonType ? buttonClasses.get(props.ButtonType) : buttonClasses.get("Primary" /* Solid */);
72
+ return /* @__PURE__ */ jsx(React.Fragment, { children: /* @__PURE__ */ jsx(
73
+ "button",
74
+ {
75
+ type: "button",
76
+ onClick: execute,
77
+ className: buttonClass + " " + props.className,
78
+ children: props.children
79
+ }
80
+ ) });
81
+ };
82
+ var ClientButton_default = ClientButton;
83
+
84
+ // src/components/Confirm.tsx
85
+ import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
86
+ var Confirm = ({ message, onConfirm, onCancel }) => {
87
+ const [showModal, setShowModal] = useState(true);
88
+ const handleConfirmAction = () => {
89
+ setShowModal(false);
90
+ if (onConfirm) {
91
+ onConfirm();
92
+ }
93
+ };
94
+ const handleCancelAction = () => {
95
+ setShowModal(false);
96
+ if (onCancel) {
97
+ onCancel();
98
+ }
99
+ };
100
+ return /* @__PURE__ */ jsx2(Fragment, { children: showModal && /* @__PURE__ */ jsxs("div", { className: "fixed inset-0 flex items-center justify-center z-50", children: [
101
+ /* @__PURE__ */ jsx2("div", { className: "absolute inset-0 bg-black opacity-70" }),
102
+ /* @__PURE__ */ jsxs("div", { className: "bg-white rounded-md p-6 w-2/6 shadow border z-50", children: [
103
+ /* @__PURE__ */ jsx2("p", { className: "text-xl font-medium mb-4", children: "Confirmation" }),
104
+ /* @__PURE__ */ jsx2("p", { className: "mb-4", children: message }),
105
+ /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-8", children: [
106
+ /* @__PURE__ */ jsx2(
107
+ ClientButton_default,
108
+ {
109
+ onClick: handleCancelAction,
110
+ ButtonType: "PrimaryHollow" /* Hollow */,
111
+ children: "Cancel"
112
+ }
113
+ ),
114
+ /* @__PURE__ */ jsx2(
115
+ ClientButton_default,
116
+ {
117
+ onClick: handleConfirmAction,
118
+ children: "Confirm"
119
+ }
120
+ )
121
+ ] })
122
+ ] })
123
+ ] }) });
124
+ };
125
+ var Confirm_default = Confirm;
126
+ {
127
+ }
128
+
129
+ // src/components/Button.tsx
130
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
131
+ var Button = (props) => {
132
+ const [inProgress, setInProgress] = useState2(false);
133
+ const [isActionPerformed, setIsActionPerformed] = useState2(false);
134
+ const [responseMessage, setResponseMessage] = useState2(null);
135
+ const [showModal, setShowModal] = useState2(null);
136
+ const execute = async (event) => {
137
+ event.preventDefault();
138
+ event.stopPropagation();
139
+ if (props.confirm) {
140
+ const confirmed = await showConfirmation("Are you sure you want to delete this item?");
141
+ setShowModal(null);
142
+ if (!confirmed) {
143
+ return;
144
+ }
145
+ }
146
+ if (props.oneTimeAction && isActionPerformed) {
147
+ return;
148
+ }
149
+ setInProgress(true);
150
+ let isValid = true;
151
+ if (props.onValidate !== void 0) {
152
+ isValid = await props.onValidate();
153
+ if (!isValid) {
154
+ setInProgress(false);
155
+ ToastService_default.showError("There are errors in the form. Please fix them before proceeding.");
156
+ return;
157
+ }
158
+ }
159
+ if (props.onClick !== void 0) {
160
+ let response = await props.onClick();
161
+ if (response.isSuccessful) {
162
+ setIsActionPerformed(true);
163
+ setResponseMessage(response.message);
164
+ if (props.showToast) {
165
+ ToastService_default.showInfo(response.message || "");
166
+ }
167
+ } else {
168
+ ToastService_default.showError(response.message || "");
169
+ }
170
+ } else {
171
+ ToastService_default.showError("No action defined.");
172
+ }
173
+ setInProgress(false);
174
+ };
175
+ const showConfirmation = (message) => {
176
+ return new Promise((resolve) => {
177
+ const onConfirm = () => resolve(true);
178
+ const onCancel = () => resolve(false);
179
+ setShowModal(/* @__PURE__ */ jsx3(Confirm_default, { message: props.confirmationMessage, onConfirm, onCancel }));
180
+ });
181
+ };
182
+ let buttonClass = props.ButtonType ? buttonClasses.get(props.ButtonType) : buttonClasses.get("Primary" /* Solid */);
183
+ let progressClass = props.ButtonType ? progressClasses.get(props.ButtonType) : progressClasses.get("Primary" /* Solid */);
184
+ const isDisabled = inProgress || isActionPerformed && props.oneTimeAction;
185
+ return /* @__PURE__ */ jsxs2(React3.Fragment, { children: [
186
+ /* @__PURE__ */ jsxs2(
187
+ "button",
188
+ {
189
+ type: "submit",
190
+ onClick: execute,
191
+ disabled: props.disabled,
192
+ title: isDisabled ? "The button is disabled to prevent any action" : "",
193
+ className: buttonClass + " relative " + props.className,
194
+ children: [
195
+ isActionPerformed && props.oneTimeAction && responseMessage ? responseMessage : props.children,
196
+ inProgress && /* @__PURE__ */ jsx3(React3.Fragment, { children: props.hideProgressIndicator === true ? /* @__PURE__ */ jsx3("div", { className: "absolute bottom-0 left-0 h-0.5 bg-gray-400 rounded animate-progress" }) : /* @__PURE__ */ jsxs2("svg", { className: "animate-spin ml-2 mr-3 h-5 w-5 " + progressClass, xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [
197
+ /* @__PURE__ */ jsx3("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
198
+ /* @__PURE__ */ jsx3("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })
199
+ ] }) })
200
+ ]
201
+ }
202
+ ),
203
+ showModal
204
+ ] });
205
+ };
206
+ var Button_default = Button;
207
+
208
+ export {
209
+ ToastService_default,
210
+ ClientButton_default,
211
+ Button_default
212
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acoustte-digital-services/digitalstore-controls-dev",
3
- "version": "0.8.1-dev.20260713051007",
3
+ "version": "0.8.1-dev.20260713054521",
4
4
  "description": "Reusable React components",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",