@uu-webtools/client 1.0.0
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.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +221 -0
- package/dist/index.mjs +180 -0
- package/dist/server.d.mts +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +70 -0
- package/dist/server.mjs +32 -0
- package/package.json +37 -0
package/dist/index.d.mts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __objRest = (source, exclude) => {
|
|
24
|
+
var target = {};
|
|
25
|
+
for (var prop in source)
|
|
26
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
27
|
+
target[prop] = source[prop];
|
|
28
|
+
if (source != null && __getOwnPropSymbols)
|
|
29
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
30
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
31
|
+
target[prop] = source[prop];
|
|
32
|
+
}
|
|
33
|
+
return target;
|
|
34
|
+
};
|
|
35
|
+
var __export = (target, all) => {
|
|
36
|
+
for (var name in all)
|
|
37
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
38
|
+
};
|
|
39
|
+
var __copyProps = (to, from, except, desc) => {
|
|
40
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
41
|
+
for (let key of __getOwnPropNames(from))
|
|
42
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
43
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
44
|
+
}
|
|
45
|
+
return to;
|
|
46
|
+
};
|
|
47
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
48
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
49
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
50
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
51
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
52
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
53
|
+
mod
|
|
54
|
+
));
|
|
55
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
56
|
+
|
|
57
|
+
// index.ts
|
|
58
|
+
var index_exports = {};
|
|
59
|
+
__export(index_exports, {
|
|
60
|
+
ErrorBoundary: () => ErrorBoundary,
|
|
61
|
+
ErrorProvider: () => ErrorProvider,
|
|
62
|
+
I18nProvider: () => I18nProvider,
|
|
63
|
+
NextErrorProvider: () => NextErrorProvider,
|
|
64
|
+
captureException: () => captureException,
|
|
65
|
+
initErrorClient: () => initErrorClient,
|
|
66
|
+
installGlobalHandlers: () => installGlobalHandlers,
|
|
67
|
+
useTranslation: () => useTranslation
|
|
68
|
+
});
|
|
69
|
+
module.exports = __toCommonJS(index_exports);
|
|
70
|
+
|
|
71
|
+
// ../@webtools:error-kit/NextErrorProvider.tsx
|
|
72
|
+
var import_react2 = require("react");
|
|
73
|
+
|
|
74
|
+
// ../@webtools:error-kit/ErrorBoundary.tsx
|
|
75
|
+
var import_react = __toESM(require("react"));
|
|
76
|
+
|
|
77
|
+
// ../@webtools:error-kit/client.ts
|
|
78
|
+
var _opts = null;
|
|
79
|
+
function initErrorClient(opts) {
|
|
80
|
+
_opts = opts;
|
|
81
|
+
}
|
|
82
|
+
function safeString(v) {
|
|
83
|
+
try {
|
|
84
|
+
return typeof v === "string" ? v : JSON.stringify(v);
|
|
85
|
+
} catch (e) {
|
|
86
|
+
return String(v);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function captureException(err, extras) {
|
|
90
|
+
if (!_opts) return;
|
|
91
|
+
const e = err instanceof Error ? err : new Error(safeString(err));
|
|
92
|
+
const payload = {
|
|
93
|
+
name: e.name,
|
|
94
|
+
message: e.message,
|
|
95
|
+
stack: e.stack,
|
|
96
|
+
url: typeof window !== "undefined" ? window.location.href : void 0,
|
|
97
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
98
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
99
|
+
projectToken: _opts.projectToken,
|
|
100
|
+
app: _opts.app,
|
|
101
|
+
env: _opts.env,
|
|
102
|
+
release: _opts.release,
|
|
103
|
+
tags: __spreadValues(__spreadValues({}, _opts.tags), extras == null ? void 0 : extras.tags),
|
|
104
|
+
extra: extras == null ? void 0 : extras.extra
|
|
105
|
+
};
|
|
106
|
+
try {
|
|
107
|
+
const headers = {
|
|
108
|
+
"Content-Type": "application/json"
|
|
109
|
+
};
|
|
110
|
+
if (_opts.projectToken) {
|
|
111
|
+
headers["X-Project-Token"] = _opts.projectToken;
|
|
112
|
+
}
|
|
113
|
+
await fetch(_opts.dsn, {
|
|
114
|
+
method: "POST",
|
|
115
|
+
headers,
|
|
116
|
+
body: JSON.stringify(payload),
|
|
117
|
+
keepalive: true
|
|
118
|
+
// important pro page unload
|
|
119
|
+
});
|
|
120
|
+
} catch (e2) {
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function installGlobalHandlers() {
|
|
124
|
+
if (typeof window === "undefined") return;
|
|
125
|
+
window.addEventListener("error", (event) => {
|
|
126
|
+
var _a;
|
|
127
|
+
captureException((_a = event.error) != null ? _a : new Error(event.message), {
|
|
128
|
+
extra: {
|
|
129
|
+
filename: event.filename,
|
|
130
|
+
lineno: event.lineno,
|
|
131
|
+
colno: event.colno
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
window.addEventListener("unhandledrejection", (event) => {
|
|
136
|
+
var _a;
|
|
137
|
+
captureException((_a = event.reason) != null ? _a : new Error("Unhandled promise rejection"));
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// ../@webtools:error-kit/ErrorBoundary.tsx
|
|
142
|
+
var ErrorBoundary = class extends import_react.default.Component {
|
|
143
|
+
constructor() {
|
|
144
|
+
super(...arguments);
|
|
145
|
+
this.state = { hasError: false };
|
|
146
|
+
}
|
|
147
|
+
static getDerivedStateFromError() {
|
|
148
|
+
return { hasError: true };
|
|
149
|
+
}
|
|
150
|
+
componentDidCatch(error, info) {
|
|
151
|
+
captureException(error, {
|
|
152
|
+
extra: { reactComponentStack: info.componentStack }
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
render() {
|
|
156
|
+
var _a;
|
|
157
|
+
if (this.state.hasError) {
|
|
158
|
+
return (_a = this.props.fallback) != null ? _a : null;
|
|
159
|
+
}
|
|
160
|
+
return this.props.children;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// ../@webtools:error-kit/NextErrorProvider.tsx
|
|
165
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
166
|
+
function NextErrorProvider(props) {
|
|
167
|
+
const _a = props, { children, fallback } = _a, opts = __objRest(_a, ["children", "fallback"]);
|
|
168
|
+
(0, import_react2.useEffect)(() => {
|
|
169
|
+
initErrorClient(opts);
|
|
170
|
+
installGlobalHandlers();
|
|
171
|
+
}, [opts.dsn, opts.projectToken, opts.app, opts.env, opts.release]);
|
|
172
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorBoundary, { fallback, children });
|
|
173
|
+
}
|
|
174
|
+
var ErrorProvider = NextErrorProvider;
|
|
175
|
+
|
|
176
|
+
// ../@webtools:i18n/context.tsx
|
|
177
|
+
var import_react3 = require("react");
|
|
178
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
179
|
+
var I18nContext = (0, import_react3.createContext)(null);
|
|
180
|
+
function I18nProvider({ locale, messages, children }) {
|
|
181
|
+
const value = (0, import_react3.useMemo)(() => ({ locale, messages }), [locale, messages]);
|
|
182
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(I18nContext.Provider, { value, children });
|
|
183
|
+
}
|
|
184
|
+
function resolve(obj, path) {
|
|
185
|
+
const keys = path.split(".");
|
|
186
|
+
let current = obj;
|
|
187
|
+
for (const key of keys) {
|
|
188
|
+
if (current === null || current === void 0 || typeof current !== "object") {
|
|
189
|
+
return path;
|
|
190
|
+
}
|
|
191
|
+
current = current[key];
|
|
192
|
+
}
|
|
193
|
+
if (typeof current === "string") return current;
|
|
194
|
+
if (typeof current === "number" || typeof current === "boolean") return String(current);
|
|
195
|
+
return path;
|
|
196
|
+
}
|
|
197
|
+
function useTranslation(prefix) {
|
|
198
|
+
const ctx = (0, import_react3.useContext)(I18nContext);
|
|
199
|
+
if (!ctx) {
|
|
200
|
+
throw new Error("useTranslation must be used within an <I18nProvider>");
|
|
201
|
+
}
|
|
202
|
+
const t = (0, import_react3.useCallback)(
|
|
203
|
+
(key) => {
|
|
204
|
+
const fullKey = prefix ? `${prefix}.${key}` : key;
|
|
205
|
+
return resolve(ctx.messages, fullKey);
|
|
206
|
+
},
|
|
207
|
+
[ctx.messages, prefix]
|
|
208
|
+
);
|
|
209
|
+
return t;
|
|
210
|
+
}
|
|
211
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
212
|
+
0 && (module.exports = {
|
|
213
|
+
ErrorBoundary,
|
|
214
|
+
ErrorProvider,
|
|
215
|
+
I18nProvider,
|
|
216
|
+
NextErrorProvider,
|
|
217
|
+
captureException,
|
|
218
|
+
initErrorClient,
|
|
219
|
+
installGlobalHandlers,
|
|
220
|
+
useTranslation
|
|
221
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __spreadValues = (a, b) => {
|
|
8
|
+
for (var prop in b || (b = {}))
|
|
9
|
+
if (__hasOwnProp.call(b, prop))
|
|
10
|
+
__defNormalProp(a, prop, b[prop]);
|
|
11
|
+
if (__getOwnPropSymbols)
|
|
12
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
13
|
+
if (__propIsEnum.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
}
|
|
16
|
+
return a;
|
|
17
|
+
};
|
|
18
|
+
var __objRest = (source, exclude) => {
|
|
19
|
+
var target = {};
|
|
20
|
+
for (var prop in source)
|
|
21
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
22
|
+
target[prop] = source[prop];
|
|
23
|
+
if (source != null && __getOwnPropSymbols)
|
|
24
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
25
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
26
|
+
target[prop] = source[prop];
|
|
27
|
+
}
|
|
28
|
+
return target;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// ../@webtools:error-kit/NextErrorProvider.tsx
|
|
32
|
+
import { useEffect } from "react";
|
|
33
|
+
|
|
34
|
+
// ../@webtools:error-kit/ErrorBoundary.tsx
|
|
35
|
+
import React from "react";
|
|
36
|
+
|
|
37
|
+
// ../@webtools:error-kit/client.ts
|
|
38
|
+
var _opts = null;
|
|
39
|
+
function initErrorClient(opts) {
|
|
40
|
+
_opts = opts;
|
|
41
|
+
}
|
|
42
|
+
function safeString(v) {
|
|
43
|
+
try {
|
|
44
|
+
return typeof v === "string" ? v : JSON.stringify(v);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
return String(v);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async function captureException(err, extras) {
|
|
50
|
+
if (!_opts) return;
|
|
51
|
+
const e = err instanceof Error ? err : new Error(safeString(err));
|
|
52
|
+
const payload = {
|
|
53
|
+
name: e.name,
|
|
54
|
+
message: e.message,
|
|
55
|
+
stack: e.stack,
|
|
56
|
+
url: typeof window !== "undefined" ? window.location.href : void 0,
|
|
57
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
58
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
59
|
+
projectToken: _opts.projectToken,
|
|
60
|
+
app: _opts.app,
|
|
61
|
+
env: _opts.env,
|
|
62
|
+
release: _opts.release,
|
|
63
|
+
tags: __spreadValues(__spreadValues({}, _opts.tags), extras == null ? void 0 : extras.tags),
|
|
64
|
+
extra: extras == null ? void 0 : extras.extra
|
|
65
|
+
};
|
|
66
|
+
try {
|
|
67
|
+
const headers = {
|
|
68
|
+
"Content-Type": "application/json"
|
|
69
|
+
};
|
|
70
|
+
if (_opts.projectToken) {
|
|
71
|
+
headers["X-Project-Token"] = _opts.projectToken;
|
|
72
|
+
}
|
|
73
|
+
await fetch(_opts.dsn, {
|
|
74
|
+
method: "POST",
|
|
75
|
+
headers,
|
|
76
|
+
body: JSON.stringify(payload),
|
|
77
|
+
keepalive: true
|
|
78
|
+
// important pro page unload
|
|
79
|
+
});
|
|
80
|
+
} catch (e2) {
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function installGlobalHandlers() {
|
|
84
|
+
if (typeof window === "undefined") return;
|
|
85
|
+
window.addEventListener("error", (event) => {
|
|
86
|
+
var _a;
|
|
87
|
+
captureException((_a = event.error) != null ? _a : new Error(event.message), {
|
|
88
|
+
extra: {
|
|
89
|
+
filename: event.filename,
|
|
90
|
+
lineno: event.lineno,
|
|
91
|
+
colno: event.colno
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
window.addEventListener("unhandledrejection", (event) => {
|
|
96
|
+
var _a;
|
|
97
|
+
captureException((_a = event.reason) != null ? _a : new Error("Unhandled promise rejection"));
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ../@webtools:error-kit/ErrorBoundary.tsx
|
|
102
|
+
var ErrorBoundary = class extends React.Component {
|
|
103
|
+
constructor() {
|
|
104
|
+
super(...arguments);
|
|
105
|
+
this.state = { hasError: false };
|
|
106
|
+
}
|
|
107
|
+
static getDerivedStateFromError() {
|
|
108
|
+
return { hasError: true };
|
|
109
|
+
}
|
|
110
|
+
componentDidCatch(error, info) {
|
|
111
|
+
captureException(error, {
|
|
112
|
+
extra: { reactComponentStack: info.componentStack }
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
render() {
|
|
116
|
+
var _a;
|
|
117
|
+
if (this.state.hasError) {
|
|
118
|
+
return (_a = this.props.fallback) != null ? _a : null;
|
|
119
|
+
}
|
|
120
|
+
return this.props.children;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// ../@webtools:error-kit/NextErrorProvider.tsx
|
|
125
|
+
import { jsx } from "react/jsx-runtime";
|
|
126
|
+
function NextErrorProvider(props) {
|
|
127
|
+
const _a = props, { children, fallback } = _a, opts = __objRest(_a, ["children", "fallback"]);
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
initErrorClient(opts);
|
|
130
|
+
installGlobalHandlers();
|
|
131
|
+
}, [opts.dsn, opts.projectToken, opts.app, opts.env, opts.release]);
|
|
132
|
+
return /* @__PURE__ */ jsx(ErrorBoundary, { fallback, children });
|
|
133
|
+
}
|
|
134
|
+
var ErrorProvider = NextErrorProvider;
|
|
135
|
+
|
|
136
|
+
// ../@webtools:i18n/context.tsx
|
|
137
|
+
import { createContext, useContext, useCallback, useMemo } from "react";
|
|
138
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
139
|
+
var I18nContext = createContext(null);
|
|
140
|
+
function I18nProvider({ locale, messages, children }) {
|
|
141
|
+
const value = useMemo(() => ({ locale, messages }), [locale, messages]);
|
|
142
|
+
return /* @__PURE__ */ jsx2(I18nContext.Provider, { value, children });
|
|
143
|
+
}
|
|
144
|
+
function resolve(obj, path) {
|
|
145
|
+
const keys = path.split(".");
|
|
146
|
+
let current = obj;
|
|
147
|
+
for (const key of keys) {
|
|
148
|
+
if (current === null || current === void 0 || typeof current !== "object") {
|
|
149
|
+
return path;
|
|
150
|
+
}
|
|
151
|
+
current = current[key];
|
|
152
|
+
}
|
|
153
|
+
if (typeof current === "string") return current;
|
|
154
|
+
if (typeof current === "number" || typeof current === "boolean") return String(current);
|
|
155
|
+
return path;
|
|
156
|
+
}
|
|
157
|
+
function useTranslation(prefix) {
|
|
158
|
+
const ctx = useContext(I18nContext);
|
|
159
|
+
if (!ctx) {
|
|
160
|
+
throw new Error("useTranslation must be used within an <I18nProvider>");
|
|
161
|
+
}
|
|
162
|
+
const t = useCallback(
|
|
163
|
+
(key) => {
|
|
164
|
+
const fullKey = prefix ? `${prefix}.${key}` : key;
|
|
165
|
+
return resolve(ctx.messages, fullKey);
|
|
166
|
+
},
|
|
167
|
+
[ctx.messages, prefix]
|
|
168
|
+
);
|
|
169
|
+
return t;
|
|
170
|
+
}
|
|
171
|
+
export {
|
|
172
|
+
ErrorBoundary,
|
|
173
|
+
ErrorProvider,
|
|
174
|
+
I18nProvider,
|
|
175
|
+
NextErrorProvider,
|
|
176
|
+
captureException,
|
|
177
|
+
initErrorClient,
|
|
178
|
+
installGlobalHandlers,
|
|
179
|
+
useTranslation
|
|
180
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { loadMessages, mergeModules } from '@webtools/i18n/server';
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { loadMessages, mergeModules } from '@webtools/i18n/server';
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// server.ts
|
|
31
|
+
var server_exports = {};
|
|
32
|
+
__export(server_exports, {
|
|
33
|
+
loadMessages: () => loadMessages,
|
|
34
|
+
mergeModules: () => mergeModules
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(server_exports);
|
|
37
|
+
|
|
38
|
+
// ../@webtools:i18n/loadMessages.ts
|
|
39
|
+
function mergeModules(modules) {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
const merged = {};
|
|
42
|
+
for (const [path, mod] of Object.entries(modules)) {
|
|
43
|
+
const file = (_a = path.split("/").pop()) != null ? _a : "";
|
|
44
|
+
const ns = file.replace(/\.\w+$/, "");
|
|
45
|
+
const data = (_b = mod.default) != null ? _b : mod;
|
|
46
|
+
merged[ns] = data;
|
|
47
|
+
}
|
|
48
|
+
return merged;
|
|
49
|
+
}
|
|
50
|
+
async function loadMessages(locale, messagesDir) {
|
|
51
|
+
const fs = await import("fs");
|
|
52
|
+
const path = await import("path");
|
|
53
|
+
const localeDir = path.join(messagesDir, locale);
|
|
54
|
+
if (!fs.existsSync(localeDir)) {
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
const files = fs.readdirSync(localeDir).filter((f) => f.endsWith(".json"));
|
|
58
|
+
const merged = {};
|
|
59
|
+
for (const file of files) {
|
|
60
|
+
const ns = file.replace(/\.json$/, "");
|
|
61
|
+
const content = fs.readFileSync(path.join(localeDir, file), "utf-8");
|
|
62
|
+
merged[ns] = JSON.parse(content);
|
|
63
|
+
}
|
|
64
|
+
return merged;
|
|
65
|
+
}
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
loadMessages,
|
|
69
|
+
mergeModules
|
|
70
|
+
});
|
package/dist/server.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// ../@webtools:i18n/loadMessages.ts
|
|
2
|
+
function mergeModules(modules) {
|
|
3
|
+
var _a, _b;
|
|
4
|
+
const merged = {};
|
|
5
|
+
for (const [path, mod] of Object.entries(modules)) {
|
|
6
|
+
const file = (_a = path.split("/").pop()) != null ? _a : "";
|
|
7
|
+
const ns = file.replace(/\.\w+$/, "");
|
|
8
|
+
const data = (_b = mod.default) != null ? _b : mod;
|
|
9
|
+
merged[ns] = data;
|
|
10
|
+
}
|
|
11
|
+
return merged;
|
|
12
|
+
}
|
|
13
|
+
async function loadMessages(locale, messagesDir) {
|
|
14
|
+
const fs = await import("fs");
|
|
15
|
+
const path = await import("path");
|
|
16
|
+
const localeDir = path.join(messagesDir, locale);
|
|
17
|
+
if (!fs.existsSync(localeDir)) {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
const files = fs.readdirSync(localeDir).filter((f) => f.endsWith(".json"));
|
|
21
|
+
const merged = {};
|
|
22
|
+
for (const file of files) {
|
|
23
|
+
const ns = file.replace(/\.json$/, "");
|
|
24
|
+
const content = fs.readFileSync(path.join(localeDir, file), "utf-8");
|
|
25
|
+
merged[ns] = JSON.parse(content);
|
|
26
|
+
}
|
|
27
|
+
return merged;
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
loadMessages,
|
|
31
|
+
mergeModules
|
|
32
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@uu-webtools/client",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "./dist/index.cjs",
|
|
5
|
+
"module": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
|
+
},
|
|
13
|
+
"./server": {
|
|
14
|
+
"types": "./dist/server.d.ts",
|
|
15
|
+
"import": "./dist/server.js",
|
|
16
|
+
"require": "./dist/server.cjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "./node_modules/.bin/tsup"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"react": ">=18.0.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^25.4.0",
|
|
30
|
+
"@types/react": "^19.0.0",
|
|
31
|
+
"@webtools/error-kit": "file:../@webtools:error-kit",
|
|
32
|
+
"@webtools/i18n": "file:../@webtools:i18n",
|
|
33
|
+
"react": "^19.0.0",
|
|
34
|
+
"tsup": "^8.5.1",
|
|
35
|
+
"typescript": "^5.9.3"
|
|
36
|
+
}
|
|
37
|
+
}
|